diff --git a/runtime/exelib/common/libargs.c b/runtime/exelib/common/libargs.c index e0d01754533..4bc809b0e34 100644 --- a/runtime/exelib/common/libargs.c +++ b/runtime/exelib/common/libargs.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1991, 2017 IBM Corp. and others + * Copyright (c) 1991, 2018 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -23,7 +23,7 @@ /*------------------------------------------------------------------ * libargs. : handle VM init args *------------------------------------------------------------------*/ - + #include #include #include @@ -36,7 +36,7 @@ #include "util_api.h" /*------------------------------------------------------------------ - * + * *------------------------------------------------------------------*/ #if defined(LOGGING) #define LOG(x) printf x @@ -44,7 +44,7 @@ #define LOG(x) #endif /*------------------------------------------------------------------ - * + * *------------------------------------------------------------------*/ typedef struct J9LinkedString { @@ -55,46 +55,40 @@ typedef struct J9LinkedString { typedef struct { I_32 size; I_32 count; - JavaVMOption *vmOptions; + JavaVMOption *vmOptions; J9PortLibrary *portLib; J9LinkedString *strings; } J9VMOptionsTable; #define J9CMD_EXACT_MATCH 0 #define J9CMD_PARTIAL_MATCH 1 -typedef struct J9CmdLineAction{ +typedef struct J9CmdLineAction { char *cmdLineName; UDATA partialMatch; char *internalName; I_32 (*actionFunction)(J9PortLibrary *portLib, int *argc, char *argv[], void **vmOptionsTable, struct J9CmdLineAction *); } J9CmdLineAction; -I_32 vmOptionsTableAddExeName ( void **vmOptionsTable, char *argv0 ); -int vmOptionsTableGetCount ( void **vmOptionsTable ); -I_32 vmOptionsTableInit ( J9PortLibrary *portLib, void **vmOptionsTable, int initialCount ); -I_32 vmOptionsTableAddOptionWithCopy ( void **vmOptionsTable, char *optionString, void *extraInfo ); -I_32 vmOptionsTableAddOption ( void **vmOptionsTable, char *optionString, void *extraInfo ); -JavaVMOption *vmOptionsTableGetOptions ( void **vmOptionsTable ); -void vmOptionsTableDestroy ( void **vmOptionsTable ); - - - -static char* allocString (J9VMOptionsTable* table, UDATA size); -static I_32 cmdline_get_jcl ( J9PortLibrary *portLib, int *argc, char *argv[], void **vmOptionsTable, J9CmdLineAction *action ); -static I_32 copyTable ( J9PortLibrary *portLib, J9VMOptionsTable *table, J9VMOptionsTable *oldTable ); -static I_32 buildNewTable ( J9PortLibrary *portLib, int initialCount, J9VMOptionsTable *oldTable, J9VMOptionsTable **newTable ); +I_32 vmOptionsTableAddExeName(void **vmOptionsTable, char *argv0); +int vmOptionsTableGetCount(void **vmOptionsTable); +I_32 vmOptionsTableInit(J9PortLibrary *portLib, void **vmOptionsTable, int initialCount); +I_32 vmOptionsTableAddOptionWithCopy(void **vmOptionsTable, char *optionString, void *extraInfo); +I_32 vmOptionsTableAddOption(void **vmOptionsTable, char *optionString, void *extraInfo); +JavaVMOption *vmOptionsTableGetOptions(void **vmOptionsTable); +void vmOptionsTableDestroy(void **vmOptionsTable); +static char *allocString(J9VMOptionsTable *table, UDATA size); +static I_32 cmdline_get_jcl(J9PortLibrary *portLib, int *argc, char *argv[], void **vmOptionsTable, J9CmdLineAction *action); +static I_32 copyTable(J9PortLibrary *portLib, J9VMOptionsTable *table, J9VMOptionsTable *oldTable); +static I_32 buildNewTable(J9PortLibrary *portLib, int initialCount, J9VMOptionsTable *oldTable, J9VMOptionsTable **newTable); #define NO_DEFAULT_VALUE 0 #define PRIVATE_OPTION NULL - /*------------------------------------------------------------------ - * + * *------------------------------------------------------------------*/ - - #if defined(J9VM_INTERP_VERBOSE) static char *verboseOptions[] = { "\n -verbose[:{class", @@ -108,34 +102,29 @@ static char *verboseOptions[] = { }; #endif /* J9VM_INTERP_VERBOSE */ - /*------------------------------------------------------------------ * create a new table with specified size *------------------------------------------------------------------*/ -I_32 vmOptionsTableInit( - J9PortLibrary *portLib, - void **vmOptionsTable, - int initialCount - ) { - return buildNewTable(portLib,initialCount,NULL,(J9VMOptionsTable **)vmOptionsTable); +I_32 +vmOptionsTableInit(J9PortLibrary *portLib, void **vmOptionsTable, int initialCount) +{ + return buildNewTable(portLib, initialCount, NULL, (J9VMOptionsTable **)vmOptionsTable); } - /*------------------------------------------------------------------ - * destroy the table + * destroy the table *------------------------------------------------------------------*/ -void vmOptionsTableDestroy( - void **vmOptionsTable - ) { +void +vmOptionsTableDestroy(void **vmOptionsTable) +{ J9VMOptionsTable *table = *vmOptionsTable; - J9PortLibrary *portLib = table->portLib; - J9LinkedString *this, *next; + J9PortLibrary *portLib = table->portLib; + J9LinkedString *this = table->strings; PORT_ACCESS_FROM_PORT(portLib); /* free the linked list of strings */ - this = table->strings; - while (this) { - next = this->next; + while (NULL != this) { + J9LinkedString *next = this->next; j9mem_free_memory(this); this = next; } @@ -143,46 +132,42 @@ void vmOptionsTableDestroy( j9mem_free_memory(table); } - /*------------------------------------------------------------------ * get the number of options in the table *------------------------------------------------------------------*/ -int vmOptionsTableGetCount( - void **vmOptionsTable - ) { +int +vmOptionsTableGetCount(void **vmOptionsTable) +{ J9VMOptionsTable *table = *vmOptionsTable; return table->count; } - /*------------------------------------------------------------------ - * + * *------------------------------------------------------------------*/ -JavaVMOption *vmOptionsTableGetOptions( - void **vmOptionsTable - ) { +JavaVMOption * +vmOptionsTableGetOptions(void **vmOptionsTable) +{ J9VMOptionsTable *table = *vmOptionsTable; return table->vmOptions; } - /*------------------------------------------------------------------ - * + * *------------------------------------------------------------------*/ -I_32 vmOptionsTableAddOption( - void **vmOptionsTable, - char *optionString, - void *extraInfo - ) { +I_32 +vmOptionsTableAddOption(void **vmOptionsTable, char *optionString, void *extraInfo) +{ J9VMOptionsTable *table = *vmOptionsTable; - J9VMOptionsTable *newTable= NULL; - I_32 returnCode; + J9VMOptionsTable *newTable = NULL; if (table->count == table->size) { - returnCode = buildNewTable(table->portLib, table->size * 2, table, &newTable); - if (returnCode != J9CMDLINE_OK) return returnCode; + I_32 returnCode = buildNewTable(table->portLib, table->size * 2, table, &newTable); + if (J9CMDLINE_OK != returnCode) { + return returnCode; + } vmOptionsTableDestroy(vmOptionsTable); table = newTable; @@ -190,30 +175,30 @@ I_32 vmOptionsTableAddOption( } table->vmOptions[table->count].optionString = optionString; - table->vmOptions[table->count].extraInfo = extraInfo; + table->vmOptions[table->count].extraInfo = extraInfo; table->count++; return J9CMDLINE_OK; } - /*------------------------------------------------------------------ - * + * *------------------------------------------------------------------*/ -I_32 vmOptionsTableAddExeName( - void **vmOptionsTable, - char *argv0 - ) { +I_32 +vmOptionsTableAddExeName(void **vmOptionsTable, char *argv0) +{ J9VMOptionsTable *table = *vmOptionsTable; PORT_ACCESS_FROM_PORT(table->portLib); char *value = NULL; char *define = NULL; #define EXE_PROPERTY "-Dcom.ibm.oti.vm.exe=" - if (j9sysinfo_get_executable_name(argv0, &value)) return J9CMDLINE_GENERIC_ERROR; + if (j9sysinfo_get_executable_name(argv0, &value)) { + return J9CMDLINE_GENERIC_ERROR; + } - define = allocString(*vmOptionsTable, sizeof(EXE_PROPERTY) + strlen(value) ); /* sizeof() includes room for the terminating \0 */ - if (define == NULL) { + define = allocString(*vmOptionsTable, sizeof(EXE_PROPERTY) + strlen(value)); /* sizeof() includes room for the terminating \0 */ + if (NULL == define) { j9mem_free_memory(value); return J9CMDLINE_OUT_OF_MEMORY; } @@ -224,13 +209,15 @@ I_32 vmOptionsTableAddExeName( return vmOptionsTableAddOption(vmOptionsTable, define, NULL); } - - -static char* allocString(J9VMOptionsTable* table, UDATA size) { - +static char * +allocString(J9VMOptionsTable *table, UDATA size) +{ PORT_ACCESS_FROM_PORT(table->portLib); - J9LinkedString* node = j9mem_allocate_memory(size + sizeof(J9LinkedString*), OMRMEM_CATEGORY_VM); - if (node == NULL) return NULL; + J9LinkedString *node = j9mem_allocate_memory(size + sizeof(J9LinkedString *), OMRMEM_CATEGORY_VM); + + if (NULL == node) { + return NULL; + } node->next = table->strings; table->strings = node; @@ -238,63 +225,57 @@ static char* allocString(J9VMOptionsTable* table, UDATA size) { return node->data; } - /*------------------------------------------------------------------ * create a new table, copying from old if valid *------------------------------------------------------------------*/ -static I_32 buildNewTable( - J9PortLibrary *portLib, - int initialCount, - J9VMOptionsTable *oldTable, - J9VMOptionsTable **newTable - ) { - J9VMOptionsTable *table; - int mallocSize; - I_32 returnCode; +static I_32 +buildNewTable(J9PortLibrary *portLib, int initialCount, J9VMOptionsTable *oldTable, J9VMOptionsTable **newTable) +{ + J9VMOptionsTable *table = NULL; + int mallocSize = sizeof(J9VMOptionsTable) + (sizeof(JavaVMOption) * initialCount); + I_32 returnCode = 0; PORT_ACCESS_FROM_PORT(portLib); - LOG(("buildNewTable(%d,%p)\n",initialCount,oldTable)); - - mallocSize = - sizeof(J9VMOptionsTable) + - (sizeof(JavaVMOption) * initialCount); - LOG(("buildNewtable(): malloc size = %d\n",mallocSize)); + LOG(("buildNewTable(%d,%p)\n", initialCount, oldTable)); + LOG(("buildNewtable(): malloc size = %d\n", mallocSize)); table = j9mem_allocate_memory(mallocSize, OMRMEM_CATEGORY_VM); - if (!table) return J9CMDLINE_OUT_OF_MEMORY; + if (NULL == table) { + return J9CMDLINE_OUT_OF_MEMORY; + } *newTable = table; - table->size = initialCount; - table->count = 0; - table->portLib = portLib; + table->size = initialCount; + table->count = 0; + table->portLib = portLib; table->vmOptions = (JavaVMOption *) (((char *) table) + sizeof(J9VMOptionsTable)); - table->strings = NULL; + table->strings = NULL; LOG(("buildNewtable(): table: %#010X\n",table)); LOG(("buildNewtable(): options: %#010X\n",table->vmOptions)); - if (!oldTable) return J9CMDLINE_OK; + if (NULL == oldTable) { + return J9CMDLINE_OK; + } LOG(("buildNewtable(): copying table\n")); returnCode = copyTable(table->portLib, table, oldTable); - if (returnCode != J9CMDLINE_OK) return returnCode; - - LOG(("buildNewtable(): table->size = %d\n",table->size)); + if (J9CMDLINE_OK != returnCode) { + return returnCode; + } + + LOG(("buildNewtable(): table->size = %d\n",table->size)); return J9CMDLINE_OK; } - - /*------------------------------------------------------------------ * create a new table, copying from old if valid *------------------------------------------------------------------*/ -static I_32 copyTable( - J9PortLibrary *portLib, - J9VMOptionsTable *table, - J9VMOptionsTable *oldTable - ) { - int i; +static I_32 +copyTable(J9PortLibrary *portLib, J9VMOptionsTable *table, J9VMOptionsTable *oldTable) +{ + int i = 0; LOG(("copyTable(%p, %p, %d)\n", table, oldTable, copyCount)); @@ -302,9 +283,9 @@ static I_32 copyTable( oldTable->strings = NULL; table->count = oldTable->count; - for (i=0; icount; i++) { + for (i = 0; i < oldTable->count; i++) { table->vmOptions[i].optionString = oldTable->vmOptions[i].optionString; - table->vmOptions[i].extraInfo = oldTable->vmOptions[i].extraInfo; + table->vmOptions[i].extraInfo = oldTable->vmOptions[i].extraInfo; } LOG(("copyTable(): table->count = %d\n",table->count)); @@ -312,64 +293,87 @@ static I_32 copyTable( return J9CMDLINE_OK; } - - /*------------------------------------------------------------------ - * + * *------------------------------------------------------------------*/ -I_32 vmOptionsTableAddOptionWithCopy( - void **vmOptionsTable, - char *optionString, - void *extraInfo - ) { - char *copyOptionString; - copyOptionString = allocString(*vmOptionsTable, strlen(optionString)+1); - if (copyOptionString == NULL) return J9CMDLINE_OUT_OF_MEMORY; +I_32 +vmOptionsTableAddOptionWithCopy(void **vmOptionsTable, char *optionString, void *extraInfo) +{ + char *copyOptionString = allocString(*vmOptionsTable, strlen(optionString) + 1); + + if (NULL == copyOptionString) { + return J9CMDLINE_OUT_OF_MEMORY; + } strcpy(copyOptionString, optionString); return vmOptionsTableAddOption(vmOptionsTable, copyOptionString, extraInfo); } #if defined(WIN32) -#define J9JAVA_DIR_SEPARATOR "\\" -#else /* UNIX style */ -#define J9JAVA_DIR_SEPARATOR "/" -#endif + /* On Windows, the subdirectory containing the redirector hasn't changed with Java versions. */ + #define J9JAVA_REDIRECTOR_SUBDIR "\\bin\\j9vm\\" +#elif (JAVA_SPEC_VERSION >= 10) || ((JAVA_SPEC_VERSION == 9) && defined(OPENJ9_BUILD)) + /* On other platforms, the subdirectory containing the redirector is common in recent Java versions. */ + #define J9JAVA_REDIRECTOR_SUBDIR "/lib/j9vm/" +#else /* WIN32 */ + /* In Java 8 and early versions of Java 9, the path depends on the platform architecture. */ + #if defined(J9HAMMER) + #define JVM_ARCH_DIR "amd64" + #elif defined(J9ARM) + #define JVM_ARCH_DIR "arm" + #elif defined(J9X86) + #define JVM_ARCH_DIR "i386" + #elif defined(S39064) || defined(J9ZOS39064) + #define JVM_ARCH_DIR "s390x" + #elif defined(S390) || defined(J9ZOS390) + #define JVM_ARCH_DIR "s390" + #elif defined(RS6000) || defined(LINUXPPC) + #if !defined(PPC64) + #define JVM_ARCH_DIR "ppc" + #elif defined(J9VM_ENV_LITTLE_ENDIAN) + #define JVM_ARCH_DIR "ppc64le" + #else /* J9VM_ENV_LITTLE_ENDIAN */ + #define JVM_ARCH_DIR "ppc64" + #endif /* PPC64 */ + #else + #error "Must define an architecture" + #endif + #define J9JAVA_REDIRECTOR_SUBDIR "/lib/" JVM_ARCH_DIR "/j9vm/" +#endif /* WIN32 */ #define JAVAHOMEDIR "-Djava.home=" -#define JAVAHOMEDIR_LEN strlen(JAVAHOMEDIR) +#define JAVAHOMEDIR_LEN (sizeof(JAVAHOMEDIR) - 1) /** * This function scans for -Djava.home=xxx/jre. If found, it uses it to construct a path * to redirector jvm.dll and put it in the passed in char buffer: - * --> [java.home]/bin/j9vm/ + * --> [java.home]/bin/j9vm/ * This function is meant to be used by thrstatetest and shrtest so the test can be invoked * in a sdk shape independent way. */ BOOLEAN -cmdline_fetchRedirectorDllDir(struct j9cmdlineOptions *args, char *result) { +cmdline_fetchRedirectorDllDir(struct j9cmdlineOptions *args, char *result) +{ char *tmpresult = NULL; - const char * directorySep = J9JAVA_DIR_SEPARATOR; - char *javaHomeDir = NULL; - struct j9cmdlineOptions * arg = args; + struct j9cmdlineOptions *arg = args; int argc = arg->argc; char **argv = arg->argv; - int i; + int i = 0; - /*Find the last -Djava.home= in the args*/ + /* Find the last -Djava.home= in the args */ for (i = 0; i < argc; i++) { - javaHomeDir = strstr(argv[i], JAVAHOMEDIR); + char *javaHomeDir = strstr(argv[i], JAVAHOMEDIR); if (NULL != javaHomeDir) { tmpresult = javaHomeDir + JAVAHOMEDIR_LEN; } } - if (tmpresult == NULL) { + if (NULL == tmpresult) { printf("ERROR: -Djava.home was not specified on command line.\n"); return FALSE; } strcpy(result, tmpresult); - strcat(result, J9JAVA_DIR_SEPARATOR "bin" J9JAVA_DIR_SEPARATOR "j9vm" J9JAVA_DIR_SEPARATOR); + strcat(result, J9JAVA_REDIRECTOR_SUBDIR); return TRUE; } diff --git a/runtime/jniinv/main.c b/runtime/jniinv/main.c index cf11d2ba02e..997c79dedcc 100644 --- a/runtime/jniinv/main.c +++ b/runtime/jniinv/main.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1991, 2017 IBM Corp. and others + * Copyright (c) 1991, 2018 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -356,7 +356,7 @@ setupInvocationAPIMethods(struct j9cmdlineOptions* startupOptions) printf("libjvmPath is %s\n", libjvmPath); if (j9sl_open_shared_library(libjvmPath, &handle, J9PORT_SLOPEN_DECORATE)) { - j9tty_printf(PORTLIB, "Failed to open JVM DLL: %s (%s)\n", J9_VM_DLL_NAME, j9error_last_error_message()); + j9tty_printf(PORTLIB, "Failed to open JVM DLL: %s (%s)\n", libjvmPath, j9error_last_error_message()); rc = FAIL; goto cleanup; } diff --git a/runtime/tests/shared/main.c b/runtime/tests/shared/main.c index a95f6cb6e0c..eb9cce9fc65 100644 --- a/runtime/tests/shared/main.c +++ b/runtime/tests/shared/main.c @@ -1,4 +1,3 @@ - /******************************************************************************* * Copyright (c) 1991, 2018 IBM Corp. and others * @@ -148,7 +147,7 @@ createJavaVM(struct j9cmdlineOptions* startupOptions, J9JavaVM** vm_, BOOLEAN us strcat(libjvmPath, jvmLibName); if (j9sl_open_shared_library(libjvmPath, &handle, J9PORT_SLOPEN_DECORATE)) { - j9tty_printf(PORTLIB, "Failed to open JVM DLL: %s (%s)\n", J9_VM_DLL_NAME, + j9tty_printf(PORTLIB, "Failed to open JVM DLL: %s (%s)\n", libjvmPath, j9error_last_error_message()); rc = 1; goto cleanup; diff --git a/runtime/tests/thread/thrstate/runtest.c b/runtime/tests/thread/thrstate/runtest.c index 841cd34ebc9..dfdc56f76bf 100644 --- a/runtime/tests/thread/thrstate/runtest.c +++ b/runtime/tests/thread/thrstate/runtest.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2017 IBM Corp. and others + * Copyright (c) 2008, 2018 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -611,12 +611,11 @@ signalProtectedMain(struct J9PortLibrary *portLibrary, void *arg) strcat(libjvmPath, jvmLibName); if (j9sl_open_shared_library(libjvmPath, &handle, J9PORT_SLOPEN_DECORATE)) { - j9tty_printf(PORTLIB, "Failed to open JVM DLL: %s (%s)\n", J9_VM_DLL_NAME, + j9tty_printf(PORTLIB, "Failed to open JVM DLL: %s (%s)\n", libjvmPath, j9error_last_error_message()); return 1; } - if (createVMArgs(PORTLIB, argc, argv, handle, JNI_VERSION_1_6, JNI_FALSE, &vm_args, &CreateJavaVM)) { return 1; diff --git a/runtime/tests/vm_lifecycle/main.c b/runtime/tests/vm_lifecycle/main.c index 0f9e6611b66..94a1738ce20 100644 --- a/runtime/tests/vm_lifecycle/main.c +++ b/runtime/tests/vm_lifecycle/main.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1991, 2017 IBM Corp. and others + * Copyright (c) 1991, 2018 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -90,7 +90,7 @@ setupInvocationAPIMethods(struct j9cmdlineOptions* startupOptions) strcat(libjvmPath, jvmLibName); if (j9sl_open_shared_library(libjvmPath, &handle, J9PORT_SLOPEN_DECORATE)) { - j9tty_printf(PORTLIB, "Failed to open JVM DLL: %s (%s)\n", J9_VM_DLL_NAME, j9error_last_error_message()); + j9tty_printf(PORTLIB, "Failed to open JVM DLL: %s (%s)\n", libjvmPath, j9error_last_error_message()); rc = FAIL; goto cleanup; }