< prev index next >

test/jdk/java/lang/reflect/exeCallerAccessTest/exeCallerAccessTest.c

Print this page
rev 55510 : 8226863: jdk/java/lang/reflect/exeCallerAccessTest cannot launch on primordial thread
Reviewed-by:

*** 24,44 **** #include <stdio.h> #include <stdlib.h> #include "jni.h" #include "assert.h" static jclass classClass; static jclass iaeClass; static jmethodID mid_Class_forName; static jmethodID mid_Class_getField; static jmethodID mid_Field_get; int getField(JNIEnv *env, char* declaringClass_name, char* field_name); int checkAndClearIllegalAccessExceptionThrown(JNIEnv *env); ! int main(int argc, char** args) { JavaVM *jvm; JNIEnv *env; JavaVMInitArgs vm_args; JavaVMOption options[1]; jint rc; --- 24,47 ---- #include <stdio.h> #include <stdlib.h> #include "jni.h" #include "assert.h" + #ifndef WIN32 + #include "pthread.h" + #endif static jclass classClass; static jclass iaeClass; static jmethodID mid_Class_forName; static jmethodID mid_Class_getField; static jmethodID mid_Field_get; int getField(JNIEnv *env, char* declaringClass_name, char* field_name); int checkAndClearIllegalAccessExceptionThrown(JNIEnv *env); ! static int main_inner(int argc, char** args) { JavaVM *jvm; JNIEnv *env; JavaVMInitArgs vm_args; JavaVMOption options[1]; jint rc;
*** 125,129 **** --- 128,188 ---- return 3; } return 0; } + /* On AIX, unfortunately, we are not able to invoke the libjvm on the primordial thread. */ + + #ifdef _AIX + #define DEFAULT_SPAWN_IN_NEW_THREAD + #else + #undef DEFAULT_SPAWN_IN_NEW_THREAD + #endif + + struct args_t { + int argc; char** argv; + }; + + #define STACK_SIZE 0x200000 + + #ifdef _WIN32 + + #error Not implemented on Windows. + + #else + + 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); + } + } + + #endif /* ! WIN32 */ + + int main(int argc, char** args) { + #ifdef DEFAULT_SPAWN_IN_NEW_THREAD + struct args_t a; + a.argc = argc; + a.argv = args; + run_in_new_thread(&a); + #else + main_inner(argc, args); + #endif + }
< prev index next >