提交 263559a1 编写于 作者: D dcubed

Merge

/* /*
* Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
#define JVM_ERROR1 "Error: Could not create the Java Virtual Machine.\n" GEN_ERROR #define JVM_ERROR1 "Error: Could not create the Java Virtual Machine.\n" GEN_ERROR
#define JVM_ERROR2 "Error: Could not detach main thread.\n" JNI_ERROR #define JVM_ERROR2 "Error: Could not detach main thread.\n" JNI_ERROR
#define JVM_ERROR3 "Error: SPARC V8 processor detected; Server compiler requires V9 or better.\nUse Client compiler on V8 processors.\nCould not create the Java virtual machine." #define JVM_ERROR3 "Error: SPARC V8 processor detected; Required V9 processors or better.\nUse JDK5 client compiler for V8 processors.\n" JVM_ERROR1
#define JAR_ERROR1 "Error: Failed to load Main-Class manifest attribute from\n%s\n%s" #define JAR_ERROR1 "Error: Failed to load Main-Class manifest attribute from\n%s\n%s"
#define JAR_ERROR2 "Error: Unable to access jarfile %s" #define JAR_ERROR2 "Error: Unable to access jarfile %s"
...@@ -69,7 +69,8 @@ ...@@ -69,7 +69,8 @@
#define CFG_ERROR5 "Error: Could not determine application home." #define CFG_ERROR5 "Error: Could not determine application home."
#define CFG_ERROR6 "Error: could not open `%s'" #define CFG_ERROR6 "Error: could not open `%s'"
#define CFG_ERROR7 "Error: no known VMs. (check for corrupt jvm.cfg file)" #define CFG_ERROR7 "Error: no known VMs. (check for corrupt jvm.cfg file)"
#define CFG_ERROR8 "Error: no `%s' JVM at `%s'." #define CFG_ERROR8 "Error: missing `%s' JVM at `%s'.\nPlease install or use the JRE or JDK that contains these missing components."
#define CFG_ERROR9 "Error: could not determine JVM type."
#define SPC_ERROR1 "Error: Syntax error in version specification \"%s\"" #define SPC_ERROR1 "Error: Syntax error in version specification \"%s\""
......
/* /*
* Copyright (c) 1995, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -192,8 +192,8 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */ ...@@ -192,8 +192,8 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */
int ret; int ret;
InvocationFunctions ifn; InvocationFunctions ifn;
jlong start, end; jlong start, end;
char jrepath[MAXPATHLEN], jvmpath[MAXPATHLEN]; char jvmpath[MAXPATHLEN];
char ** original_argv = argv; char jrepath[MAXPATHLEN];
_fVersion = fullversion; _fVersion = fullversion;
_dVersion = dotversion; _dVersion = dotversion;
...@@ -225,14 +225,17 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */ ...@@ -225,14 +225,17 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */
*/ */
SelectVersion(argc, argv, &main_class); SelectVersion(argc, argv, &main_class);
/* copy original argv */ if (JLI_IsTraceLauncher()) {
JLI_TraceLauncher("Command line Args:\n"); int i;
original_argv = (JLI_CopyArgs(argc, (const char**)argv)); printf("Command line args:\n");
for (i = 0; i < argc ; i++) {
printf("argv[%d] = %s\n", i, argv[i]);
}
}
CreateExecutionEnvironment(&argc, &argv, CreateExecutionEnvironment(&argc, &argv,
jrepath, sizeof(jrepath), jrepath, sizeof(jrepath),
jvmpath, sizeof(jvmpath), jvmpath, sizeof(jvmpath));
original_argv);
ifn.CreateJavaVM = 0; ifn.CreateJavaVM = 0;
ifn.GetDefaultJavaVMInitArgs = 0; ifn.GetDefaultJavaVMInitArgs = 0;
...@@ -301,22 +304,43 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */ ...@@ -301,22 +304,43 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */
return ContinueInNewThread(&ifn, argc, argv, jarfile, classname, ret); return ContinueInNewThread(&ifn, argc, argv, jarfile, classname, ret);
} }
/*
* Always detach the main thread so that it appears to have ended when
* the application's main method exits. This will invoke the
* uncaught exception handler machinery if main threw an
* exception. An uncaught exception handler cannot change the
* launcher's return code except by calling System.exit.
*
* Wait for all non-daemon threads to end, then destroy the VM.
* This will actually create a trivial new Java waiter thread
* named "DestroyJavaVM", but this will be seen as a different
* thread from the one that executed main, even though they are
* the same C thread. This allows mainThread.join() and
* mainThread.isAlive() to work as expected.
*/
#define LEAVE() \
if ((*vm)->DetachCurrentThread(vm) != 0) { \
JLI_ReportErrorMessage(JVM_ERROR2); \
ret = 1; \
} \
(*vm)->DestroyJavaVM(vm); \
return ret \
#define CHECK_EXCEPTION_NULL_LEAVE(e) \ #define CHECK_EXCEPTION_NULL_LEAVE(e) \
if ((*env)->ExceptionOccurred(env)) { \ if ((*env)->ExceptionOccurred(env)) { \
JLI_ReportExceptionDescription(env); \ JLI_ReportExceptionDescription(env); \
goto leave; \ LEAVE(); \
} \ } \
if ((e) == NULL) { \ if ((e) == NULL) { \
JLI_ReportErrorMessage(JNI_ERROR); \ JLI_ReportErrorMessage(JNI_ERROR); \
goto leave; \ LEAVE(); \
} }
#define CHECK_EXCEPTION_LEAVE(rv) \ #define CHECK_EXCEPTION_LEAVE(rv) \
if ((*env)->ExceptionOccurred(env)) { \ if ((*env)->ExceptionOccurred(env)) { \
JLI_ReportExceptionDescription(env); \ JLI_ReportExceptionDescription(env); \
ret = (rv); \ ret = (rv); \
goto leave; \ LEAVE(); \
} }
int JNICALL int JNICALL
...@@ -349,8 +373,7 @@ JavaMain(void * _args) ...@@ -349,8 +373,7 @@ JavaMain(void * _args)
PrintJavaVersion(env, showVersion); PrintJavaVersion(env, showVersion);
CHECK_EXCEPTION_LEAVE(0); CHECK_EXCEPTION_LEAVE(0);
if (printVersion) { if (printVersion) {
ret = 0; LEAVE();
goto leave;
} }
} }
...@@ -358,7 +381,7 @@ JavaMain(void * _args) ...@@ -358,7 +381,7 @@ JavaMain(void * _args)
if (printXUsage || printUsage || (jarfile == 0 && classname == 0)) { if (printXUsage || printUsage || (jarfile == 0 && classname == 0)) {
PrintUsage(env, printXUsage); PrintUsage(env, printXUsage);
CHECK_EXCEPTION_LEAVE(1); CHECK_EXCEPTION_LEAVE(1);
goto leave; LEAVE();
} }
FreeKnownVMs(); /* after last possible PrintUsage() */ FreeKnownVMs(); /* after last possible PrintUsage() */
...@@ -430,30 +453,7 @@ JavaMain(void * _args) ...@@ -430,30 +453,7 @@ JavaMain(void * _args)
* System.exit) will be non-zero if main threw an exception. * System.exit) will be non-zero if main threw an exception.
*/ */
ret = (*env)->ExceptionOccurred(env) == NULL ? 0 : 1; ret = (*env)->ExceptionOccurred(env) == NULL ? 0 : 1;
LEAVE();
leave:
/*
* Always detach the main thread so that it appears to have ended when
* the application's main method exits. This will invoke the
* uncaught exception handler machinery if main threw an
* exception. An uncaught exception handler cannot change the
* launcher's return code except by calling System.exit.
*/
if ((*vm)->DetachCurrentThread(vm) != 0) {
JLI_ReportErrorMessage(JVM_ERROR2);
ret = 1;
}
/*
* Wait for all non-daemon threads to end, then destroy the VM.
* This will actually create a trivial new Java waiter thread
* named "DestroyJavaVM", but this will be seen as a different
* thread from the one that executed main, even though they are
* the same C thread. This allows mainThread.join() and
* mainThread.isAlive() to work as expected.
*/
(*vm)->DestroyJavaVM(vm);
return ret;
} }
/* /*
...@@ -1076,15 +1076,17 @@ ParseArguments(int *pargc, char ***pargv, char **pjarfile, ...@@ -1076,15 +1076,17 @@ ParseArguments(int *pargc, char ***pargv, char **pjarfile,
if (--argc >= 0) { if (--argc >= 0) {
if (jarflag) { if (jarflag) {
*pjarfile = *argv++; *pjarfile = *argv++;
*pclassname = 0; *pclassname = NULL;
} else { } else {
*pjarfile = 0; *pjarfile = NULL;
*pclassname = *argv++; *pclassname = *argv++;
} }
*pargc = argc; *pargc = argc;
*pargv = argv; *pargv = argv;
} }
if (*pjarfile == NULL && *pclassname == NULL) {
*pret = 1;
}
return JNI_TRUE; return JNI_TRUE;
} }
......
/* /*
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -114,13 +114,19 @@ GetApplicationHome(char *buf, jint bufsize); ...@@ -114,13 +114,19 @@ GetApplicationHome(char *buf, jint bufsize);
#define GetArch() GetArchPath(CURRENT_DATA_MODEL) #define GetArch() GetArchPath(CURRENT_DATA_MODEL)
void CreateExecutionEnvironment(int *_argc, /*
char ***_argv, * Different platforms will implement this, here
char jrepath[], * pargc is a pointer to the original argc,
jint so_jrepath, * pargv is a pointer to the original argv,
char jvmpath[], * jrepath is an accessible path to the jre as determined by the call
jint so_jvmpath, * so_jrepath is the length of the buffer jrepath
char **original_argv); * jvmpath is an accessible path to the jvm as determined by the call
* so_jvmpath is the length of the buffer jvmpath
*/
void CreateExecutionEnvironment(int *argc, char ***argv,
char *jrepath, jint so_jrepath,
char *jvmpath, jint so_jvmpath);
/* Reports an error message to stderr or a window as appropriate. */ /* Reports an error message to stderr or a window as appropriate. */
void JLI_ReportErrorMessage(const char * message, ...); void JLI_ReportErrorMessage(const char * message, ...);
......
/* /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -84,23 +84,6 @@ JLI_MemFree(void *ptr) ...@@ -84,23 +84,6 @@ JLI_MemFree(void *ptr)
free(ptr); free(ptr);
} }
/*
* Makes a copy of arguments
*/
char**
JLI_CopyArgs(int argc, const char **iargv)
{
int i;
char** oargv = (char**)JLI_MemAlloc(sizeof(char*)*(argc+1));
for (i = 0 ; i < argc+1 ; i++) {
oargv[i] = (iargv[i] == NULL) ? NULL : JLI_StringDup(iargv[i]);
if (iargv[i] != NULL && JLI_IsTraceLauncher() == JNI_TRUE) {
printf("\targv[%d] = '%s'\n",i,iargv[i]);
}
}
return oargv;
}
/* /*
* debug helpers we use * debug helpers we use
*/ */
......
/* /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,7 +33,6 @@ void *JLI_MemAlloc(size_t size); ...@@ -33,7 +33,6 @@ void *JLI_MemAlloc(size_t size);
void *JLI_MemRealloc(void *ptr, size_t size); void *JLI_MemRealloc(void *ptr, size_t size);
char *JLI_StringDup(const char *s1); char *JLI_StringDup(const char *s1);
void JLI_MemFree(void *ptr); void JLI_MemFree(void *ptr);
char **JLI_CopyArgs(int argc, const char **iargv);
int JLI_StrCCmp(const char *s1, const char* s2); int JLI_StrCCmp(const char *s1, const char* s2);
...@@ -56,10 +55,12 @@ int JLI_StrCCmp(const char *s1, const char* s2); ...@@ -56,10 +55,12 @@ int JLI_StrCCmp(const char *s1, const char* s2);
#include <io.h> #include <io.h>
#define JLI_StrCaseCmp(p1, p2) stricmp((p1), (p2)) #define JLI_StrCaseCmp(p1, p2) stricmp((p1), (p2))
#define JLI_StrNCaseCmp(p1, p2, p3) strnicmp((p1), (p2), (p3)) #define JLI_StrNCaseCmp(p1, p2, p3) strnicmp((p1), (p2), (p3))
#define JLI_Snprintf _snprintf
#else #else
#include <unistd.h> #include <unistd.h>
#define JLI_StrCaseCmp(p1, p2) strcasecmp((p1), (p2)) #define JLI_StrCaseCmp(p1, p2) strcasecmp((p1), (p2))
#define JLI_StrNCaseCmp(p1, p2, p3) strncasecmp((p1), (p2), (p3)) #define JLI_StrNCaseCmp(p1, p2, p3) strncasecmp((p1), (p2), (p3))
#define JLI_Snprintf snprintf
#endif /* _WIN32 */ #endif /* _WIN32 */
/* /*
......
/* /*
* Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -183,13 +183,9 @@ GetArchPath(int nbits) ...@@ -183,13 +183,9 @@ GetArchPath(int nbits)
} }
void void
CreateExecutionEnvironment(int *_argcp, CreateExecutionEnvironment(int *pargc, char ***pargv,
char ***_argvp, char jrepath[], jint so_jrepath,
char jrepath[], char jvmpath[], jint so_jvmpath) {
jint so_jrepath,
char jvmpath[],
jint so_jvmpath,
char **original_argv) {
/* /*
* First, determine if we are running the desired data model. If we * First, determine if we are running the desired data model. If we
* are running the desired data model, all the error messages * are running the desired data model, all the error messages
...@@ -200,18 +196,17 @@ CreateExecutionEnvironment(int *_argcp, ...@@ -200,18 +196,17 @@ CreateExecutionEnvironment(int *_argcp,
* os/processor combination has dual mode capabilities. * os/processor combination has dual mode capabilities.
*/ */
int original_argc = *_argcp;
jboolean jvmpathExists; jboolean jvmpathExists;
/* Compute/set the name of the executable */ /* Compute/set the name of the executable */
SetExecname(*_argvp); SetExecname(*pargv);
/* Check data model flags, and exec process, if needed */ /* Check data model flags, and exec process, if needed */
{ {
char *arch = (char *)GetArch(); /* like sparc or sparcv9 */ char *arch = (char *)GetArch(); /* like sparc or sparcv9 */
char * jvmtype = NULL; char * jvmtype = NULL;
int argc = *_argcp; int argc = *pargc;
char **argv = original_argv; char **argv = *pargv;
int running = CURRENT_DATA_MODEL; int running = CURRENT_DATA_MODEL;
...@@ -233,7 +228,7 @@ CreateExecutionEnvironment(int *_argcp, ...@@ -233,7 +228,7 @@ CreateExecutionEnvironment(int *_argcp,
{ /* open new scope to declare local variables */ { /* open new scope to declare local variables */
int i; int i;
newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(*newargv)); newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(char*));
newargv[newargc++] = argv[0]; newargv[newargc++] = argv[0];
/* scan for data model arguments and remove from argument list; /* scan for data model arguments and remove from argument list;
...@@ -293,7 +288,11 @@ CreateExecutionEnvironment(int *_argcp, ...@@ -293,7 +288,11 @@ CreateExecutionEnvironment(int *_argcp,
} }
jvmpath[0] = '\0'; jvmpath[0] = '\0';
jvmtype = CheckJvmType(_argcp, _argvp, JNI_FALSE); jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE);
if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
JLI_ReportErrorMessage(CFG_ERROR9);
exit(4);
}
if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch )) { if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch )) {
JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath); JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
...@@ -309,7 +308,9 @@ CreateExecutionEnvironment(int *_argcp, ...@@ -309,7 +308,9 @@ CreateExecutionEnvironment(int *_argcp,
if (running != wanted) { if (running != wanted) {
/* Find out where the JRE is that we will be using. */ /* Find out where the JRE is that we will be using. */
if (!GetJREPath(jrepath, so_jrepath, GetArchPath(wanted), JNI_TRUE)) { if (!GetJREPath(jrepath, so_jrepath, GetArchPath(wanted), JNI_TRUE)) {
goto EndDataModelSpeculate; /* give up and let other code report error message */
JLI_ReportErrorMessage(JRE_ERROR2, wanted);
exit(1);
} }
/* /*
...@@ -317,16 +318,21 @@ CreateExecutionEnvironment(int *_argcp, ...@@ -317,16 +318,21 @@ CreateExecutionEnvironment(int *_argcp,
* selection options. * selection options.
*/ */
if (ReadKnownVMs(jrepath, GetArchPath(wanted), JNI_TRUE) < 1) { if (ReadKnownVMs(jrepath, GetArchPath(wanted), JNI_TRUE) < 1) {
goto EndDataModelSpeculate; /* give up and let other code report error message */
JLI_ReportErrorMessage(JRE_ERROR2, wanted);
exit(1);
} }
jvmpath[0] = '\0'; jvmpath[0] = '\0';
jvmtype = CheckJvmType(_argcp, _argvp, JNI_TRUE); jvmtype = CheckJvmType(pargc, pargv, JNI_TRUE);
if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
JLI_ReportErrorMessage(CFG_ERROR9);
exit(4);
}
/* exec child can do error checking on the existence of the path */ /* exec child can do error checking on the existence of the path */
jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, GetArchPath(wanted)); jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, GetArchPath(wanted));
} }
EndDataModelSpeculate: /* give up and let other code report error message */
;
#else #else
JLI_ReportErrorMessage(JRE_ERROR2, wanted); JLI_ReportErrorMessage(JRE_ERROR2, wanted);
exit(1); exit(1);
...@@ -398,9 +404,9 @@ GetJVMPath(const char *jrepath, const char *jvmtype, ...@@ -398,9 +404,9 @@ GetJVMPath(const char *jrepath, const char *jvmtype,
struct stat s; struct stat s;
if (JLI_StrChr(jvmtype, '/')) { if (JLI_StrChr(jvmtype, '/')) {
sprintf(jvmpath, "%s/" JVM_DLL, jvmtype); JLI_Snprintf(jvmpath, jvmpathsize, "%s/" JVM_DLL, jvmtype);
} else { } else {
sprintf(jvmpath, "%s/lib/%s/%s/" JVM_DLL, jrepath, arch, jvmtype); JLI_Snprintf(jvmpath, jvmpathsize, "%s/lib/%s/%s/" JVM_DLL, jrepath, arch, jvmtype);
} }
JLI_TraceLauncher("Does `%s' exist ... ", jvmpath); JLI_TraceLauncher("Does `%s' exist ... ", jvmpath);
...@@ -424,26 +430,24 @@ GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative) ...@@ -424,26 +430,24 @@ GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative)
if (GetApplicationHome(path, pathsize)) { if (GetApplicationHome(path, pathsize)) {
/* Is JRE co-located with the application? */ /* Is JRE co-located with the application? */
sprintf(libjava, "%s/lib/%s/" JAVA_DLL, path, arch); JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/%s/" JAVA_DLL, path, arch);
if (access(libjava, F_OK) == 0) { if (access(libjava, F_OK) == 0) {
goto found; JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
} }
/* Does the app ship a private JRE in <apphome>/jre directory? */ /* Does the app ship a private JRE in <apphome>/jre directory? */
sprintf(libjava, "%s/jre/lib/%s/" JAVA_DLL, path, arch); JLI_Snprintf(libjava, sizeof(libjava), "%s/jre/lib/%s/" JAVA_DLL, path, arch);
if (access(libjava, F_OK) == 0) { if (access(libjava, F_OK) == 0) {
JLI_StrCat(path, "/jre"); JLI_StrCat(path, "/jre");
goto found; JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
} }
} }
if (!speculative) if (!speculative)
JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL); JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
return JNI_FALSE; return JNI_FALSE;
found:
JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
} }
jboolean jboolean
...@@ -463,14 +467,18 @@ LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn) ...@@ -463,14 +467,18 @@ LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)
int location; int location;
fp = fopen(jvmpath, "r"); fp = fopen(jvmpath, "r");
if(fp == NULL) if (fp == NULL) {
goto error; JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
return JNI_FALSE;
}
/* read in elf header */ /* read in elf header */
count = fread((void*)(&elf_head), sizeof(Elf32_Ehdr), 1, fp); count = fread((void*)(&elf_head), sizeof(Elf32_Ehdr), 1, fp);
fclose(fp); fclose(fp);
if(count < 1) if (count < 1) {
goto error; JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
return JNI_FALSE;
}
/* /*
* Check for running a server vm (compiled with -xarch=v8plus) * Check for running a server vm (compiled with -xarch=v8plus)
...@@ -481,41 +489,42 @@ LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn) ...@@ -481,41 +489,42 @@ LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)
* does not have to be checked for in binaries with an LP64 data * does not have to be checked for in binaries with an LP64 data
* model. * model.
*/ */
if(elf_head.e_machine == EM_SPARC32PLUS) { if (elf_head.e_machine == EM_SPARC32PLUS) {
char buf[257]; /* recommended buffer size from sysinfo man char buf[257]; /* recommended buffer size from sysinfo man
page */ page */
long length; long length;
char* location; char* location;
length = sysinfo(SI_ISALIST, buf, 257); length = sysinfo(SI_ISALIST, buf, 257);
if(length > 0) { if (length > 0) {
location = JLI_StrStr(buf, "sparcv8plus "); location = JLI_StrStr(buf, "sparcv8plus ");
if(location == NULL) { if (location == NULL) {
JLI_ReportErrorMessage(JVM_ERROR3); JLI_ReportErrorMessage(JVM_ERROR3);
return JNI_FALSE; return JNI_FALSE;
} }
} }
} }
#endif #endif
JLI_ReportErrorMessage(DLL_ERROR1, __LINE__); JLI_ReportErrorMessage(DLL_ERROR1, __LINE__);
goto error; JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
return JNI_FALSE;
} }
ifn->CreateJavaVM = (CreateJavaVM_t) ifn->CreateJavaVM = (CreateJavaVM_t)
dlsym(libjvm, "JNI_CreateJavaVM"); dlsym(libjvm, "JNI_CreateJavaVM");
if (ifn->CreateJavaVM == NULL) if (ifn->CreateJavaVM == NULL) {
goto error; JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
return JNI_FALSE;
}
ifn->GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t) ifn->GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t)
dlsym(libjvm, "JNI_GetDefaultJavaVMInitArgs"); dlsym(libjvm, "JNI_GetDefaultJavaVMInitArgs");
if (ifn->GetDefaultJavaVMInitArgs == NULL) if (ifn->GetDefaultJavaVMInitArgs == NULL) {
goto error; JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
return JNI_FALSE;
}
return JNI_TRUE; return JNI_TRUE;
error:
JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
return JNI_FALSE;
} }
/* /*
...@@ -575,7 +584,7 @@ Resolve(char *indir, char *cmd) ...@@ -575,7 +584,7 @@ Resolve(char *indir, char *cmd)
char name[PATH_MAX + 2], *real; char name[PATH_MAX + 2], *real;
if ((JLI_StrLen(indir) + JLI_StrLen(cmd) + 1) > PATH_MAX) return 0; if ((JLI_StrLen(indir) + JLI_StrLen(cmd) + 1) > PATH_MAX) return 0;
sprintf(name, "%s%c%s", indir, FILE_SEPARATOR, cmd); JLI_Snprintf(name, sizeof(name), "%s%c%s", indir, FILE_SEPARATOR, cmd);
if (!ProgramExists(name)) return 0; if (!ProgramExists(name)) return 0;
real = JLI_MemAlloc(PATH_MAX + 2); real = JLI_MemAlloc(PATH_MAX + 2);
if (!realpath(name, real)) if (!realpath(name, real))
...@@ -622,7 +631,7 @@ FindExecName(char *program) ...@@ -622,7 +631,7 @@ FindExecName(char *program)
else { else {
/* relative path element */ /* relative path element */
char dir[2*PATH_MAX]; char dir[2*PATH_MAX];
sprintf(dir, "%s%c%s", getcwd(cwdbuf, sizeof(cwdbuf)), JLI_Snprintf(dir, sizeof(dir), "%s%c%s", getcwd(cwdbuf, sizeof(cwdbuf)),
FILE_SEPARATOR, s); FILE_SEPARATOR, s);
result = Resolve(dir, program); result = Resolve(dir, program);
} }
...@@ -746,7 +755,7 @@ CheckSanity(char *path, char *dir) ...@@ -746,7 +755,7 @@ CheckSanity(char *path, char *dir)
if (JLI_StrLen(path) + JLI_StrLen(dir) + 11 > PATH_MAX) if (JLI_StrLen(path) + JLI_StrLen(dir) + 11 > PATH_MAX)
return (0); /* Silently reject "impossibly" long paths */ return (0); /* Silently reject "impossibly" long paths */
sprintf(buffer, "%s/%s/bin/java", path, dir); JLI_Snprintf(buffer, sizeof(buffer), "%s/%s/bin/java", path, dir);
return ((access(buffer, X_OK) == 0) ? 1 : 0); return ((access(buffer, X_OK) == 0) ? 1 : 0);
} }
......
/* /*
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -80,26 +80,22 @@ GetArchPath(int nbits) ...@@ -80,26 +80,22 @@ GetArchPath(int nbits)
* *
*/ */
void void
CreateExecutionEnvironment(int *_argc, CreateExecutionEnvironment(int *pargc, char ***pargv,
char ***_argv, char *jrepath, jint so_jrepath,
char jrepath[], char *jvmpath, jint so_jvmpath) {
jint so_jrepath,
char jvmpath[],
jint so_jvmpath,
char **original_argv) {
char * jvmtype; char * jvmtype;
int i = 0; int i = 0;
char** pargv = *_argv;
int running = CURRENT_DATA_MODEL; int running = CURRENT_DATA_MODEL;
int wanted = running; int wanted = running;
for (i = 0; i < *_argc ; i++) { char** argv = *pargv;
if (JLI_StrCmp(pargv[i], "-J-d64") == 0 || JLI_StrCmp(pargv[i], "-d64") == 0) { for (i = 0; i < *pargc ; i++) {
if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) {
wanted = 64; wanted = 64;
continue; continue;
} }
if (JLI_StrCmp(pargv[i], "-J-d32") == 0 || JLI_StrCmp(pargv[i], "-d32") == 0) { if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) {
wanted = 32; wanted = 32;
continue; continue;
} }
...@@ -123,7 +119,12 @@ CreateExecutionEnvironment(int *_argc, ...@@ -123,7 +119,12 @@ CreateExecutionEnvironment(int *_argc,
JLI_ReportErrorMessage(CFG_ERROR7); JLI_ReportErrorMessage(CFG_ERROR7);
exit(1); exit(1);
} }
jvmtype = CheckJvmType(_argc, _argv, JNI_FALSE);
jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE);
if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
JLI_ReportErrorMessage(CFG_ERROR9);
exit(4);
}
jvmpath[0] = '\0'; jvmpath[0] = '\0';
if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) { if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) {
...@@ -131,7 +132,6 @@ CreateExecutionEnvironment(int *_argc, ...@@ -131,7 +132,6 @@ CreateExecutionEnvironment(int *_argc,
exit(4); exit(4);
} }
/* If we got here, jvmpath has been correctly initialized. */ /* If we got here, jvmpath has been correctly initialized. */
} }
...@@ -203,19 +203,21 @@ EnsureJreInstallation(const char* jrepath) ...@@ -203,19 +203,21 @@ EnsureJreInstallation(const char* jrepath)
PREJVMSTART PreJVMStart; PREJVMSTART PreJVMStart;
struct stat s; struct stat s;
/* Make sure the jrepath contains something */
if (jrepath[0] == NULL) {
return;
}
/* 32 bit windows only please */ /* 32 bit windows only please */
if (strcmp(GetArch(), "i386") != 0 ) { if (JLI_StrCmp(GetArch(), "i386") != 0 ) {
return; return;
} }
/* Does our bundle directory exist ? */ /* Does our bundle directory exist ? */
strcpy(tmpbuf, jrepath); JLI_Snprintf(tmpbuf, sizeof(tmpbuf), "%s\\lib\\bundles", jrepath);
strcat(tmpbuf, "\\lib\\bundles");
if (stat(tmpbuf, &s) != 0) { if (stat(tmpbuf, &s) != 0) {
return; return;
} }
/* Does our jkernel dll exist ? */ /* Does our jkernel dll exist ? */
strcpy(tmpbuf, jrepath); JLI_Snprintf(tmpbuf, sizeof(tmpbuf), "%s\\bin\\jkernel.dll", jrepath);
strcat(tmpbuf, "\\bin\\jkernel.dll");
if (stat(tmpbuf, &s) != 0) { if (stat(tmpbuf, &s) != 0) {
return; return;
} }
...@@ -249,30 +251,30 @@ GetJREPath(char *path, jint pathsize) ...@@ -249,30 +251,30 @@ GetJREPath(char *path, jint pathsize)
if (GetApplicationHome(path, pathsize)) { if (GetApplicationHome(path, pathsize)) {
/* Is JRE co-located with the application? */ /* Is JRE co-located with the application? */
sprintf(javadll, "%s\\bin\\" JAVA_DLL, path); JLI_Snprintf(javadll, sizeof(javadll), "%s\\bin\\" JAVA_DLL, path);
if (stat(javadll, &s) == 0) { if (stat(javadll, &s) == 0) {
goto found; JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
} }
/* Does this app ship a private JRE in <apphome>\jre directory? */ /* Does this app ship a private JRE in <apphome>\jre directory? */
sprintf(javadll, "%s\\jre\\bin\\" JAVA_DLL, path); JLI_Snprintf(javadll, sizeof (javadll), "%s\\jre\\bin\\" JAVA_DLL, path);
if (stat(javadll, &s) == 0) { if (stat(javadll, &s) == 0) {
JLI_StrCat(path, "\\jre"); JLI_StrCat(path, "\\jre");
goto found; JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
} }
} }
/* Look for a public JRE on this machine. */ /* Look for a public JRE on this machine. */
if (GetPublicJREHome(path, pathsize)) { if (GetPublicJREHome(path, pathsize)) {
goto found; JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
} }
JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL); JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
return JNI_FALSE; return JNI_FALSE;
found:
JLI_TraceLauncher("JRE path is %s\n", path);
return JNI_TRUE;
} }
/* /*
...@@ -286,9 +288,9 @@ GetJVMPath(const char *jrepath, const char *jvmtype, ...@@ -286,9 +288,9 @@ GetJVMPath(const char *jrepath, const char *jvmtype,
{ {
struct stat s; struct stat s;
if (JLI_StrChr(jvmtype, '/') || JLI_StrChr(jvmtype, '\\')) { if (JLI_StrChr(jvmtype, '/') || JLI_StrChr(jvmtype, '\\')) {
sprintf(jvmpath, "%s\\" JVM_DLL, jvmtype); JLI_Snprintf(jvmpath, jvmpathsize, "%s\\" JVM_DLL, jvmtype);
} else { } else {
sprintf(jvmpath, "%s\\bin\\%s\\" JVM_DLL, jrepath, jvmtype); JLI_Snprintf(jvmpath, jvmpathsize, "%s\\bin\\%s\\" JVM_DLL, jrepath, jvmtype);
} }
if (stat(jvmpath, &s) == 0) { if (stat(jvmpath, &s) == 0) {
return JNI_TRUE; return JNI_TRUE;
......
/* /*
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/** /**
* @test * @test
* @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 * @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 6753938
* @summary Argument parsing validation. * @summary Argument parsing validation.
* @compile -XDignore.symbol.file Arrrghs.java TestHelper.java * @compile -XDignore.symbol.file Arrrghs.java TestHelper.java
* @run main Arrrghs * @run main Arrrghs
...@@ -223,6 +223,20 @@ public class Arrrghs { ...@@ -223,6 +223,20 @@ public class Arrrghs {
tr.checkPositive(); tr.checkPositive();
tr.isNotZeroOutput(); tr.isNotZeroOutput();
System.out.println(tr); System.out.println(tr);
// 6753938, test for non-negative exit value for an incorrectly formed
// command line, '% java'
tr = TestHelper.doExec(TestHelper.javaCmd);
tr.checkNegative();
tr.isNotZeroOutput();
System.out.println(tr);
// 6753938, test for non-negative exit value for an incorrectly formed
// command line, '% java -Xcomp'
tr = TestHelper.doExec(TestHelper.javaCmd, "-Xcomp");
tr.checkNegative();
tr.isNotZeroOutput();
System.out.println(tr);
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册