--- old/make/test/JtregNativeJdk.gmk 2019-07-01 11:37:06.675819002 +0200 +++ new/make/test/JtregNativeJdk.gmk 2019-07-01 11:37:06.479819631 +0200 @@ -73,7 +73,7 @@ BUILD_JDK_JTREG_LIBRARIES_LIBS_libInheritedChannel := -ljava -lsocket -lnsl endif BUILD_JDK_JTREG_EXECUTABLES_LIBS_exeJliLaunchTest := -ljli - BUILD_JDK_JTREG_EXECUTABLES_LIBS_exeCallerAccessTest := -ljvm + BUILD_JDK_JTREG_EXECUTABLES_LIBS_exeCallerAccessTest := -ljvm -lpthread endif ifeq ($(call isTargetOs, macosx), true) --- old/test/jdk/java/lang/reflect/exeCallerAccessTest/exeCallerAccessTest.c 2019-07-01 11:37:07.203817307 +0200 +++ new/test/jdk/java/lang/reflect/exeCallerAccessTest/exeCallerAccessTest.c 2019-07-01 11:37:07.007817937 +0200 @@ -21,12 +21,27 @@ * questions. */ +/* On AIX, unfortunately, we are not able to invoke the libjvm on the primordial thread. */ +#ifdef _AIX + #define CREATEVM_IN_NEW_THREAD +#else + #undef CREATEVM_IN_NEW_THREAD +#endif + #include #include #include "jni.h" #include "assert.h" +#ifdef CREATEVM_IN_NEW_THREAD + #ifdef WIN32 + #error Not on Windows. + #else + #include "pthread.h" + #endif +#endif + static jclass classClass; static jclass iaeClass; static jmethodID mid_Class_forName; @@ -36,7 +51,7 @@ int getField(JNIEnv *env, char* declaringClass_name, char* field_name); int checkAndClearIllegalAccessExceptionThrown(JNIEnv *env); -int main(int argc, char** args) { +static int main_inner(int argc, char** args) { JavaVM *jvm; JNIEnv *env; JavaVMInitArgs vm_args; @@ -127,3 +142,50 @@ return 0; } + +#ifdef CREATEVM_IN_NEW_THREAD + +struct args_t { + int argc; char** argv; +}; + +#define STACK_SIZE 0x200000 + +static void* thread_wrapper(void* p) { + const struct args_t* const p_args = (const struct args_t*) p; + main_inner(p_args->argc, p_args->argv); + return 0; +} + +static void run_in_new_thread(const struct args_t* args) { + pthread_t tid; + pthread_attr_t attr; + + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, STACK_SIZE); + + if (pthread_create(&tid, &attr, thread_wrapper, (void*)args) != 0) { + fprintf(stderr, "Failed to create main thread\n"); + exit(2); + } + + if (pthread_join(tid, NULL) != 0) { + fprintf(stderr, "Failed to join main thread\n"); + exit(2); + } +} + +int main(int argc, char** args) { + struct args_t a; + a.argc = argc; + a.argv = args; + run_in_new_thread(&a); +} + +#else + +int main(int argc, char** args) { + main_inner(argc, args); +} + +#endif /* CREATEVM_IN_NEW_THREAD */