src/java.base/unix/native/libjli/java_md_solinux.c
changeset 53941 f9302cf718c9
parent 53346 61866ba87b31
child 54023 a764c49570c6
equal deleted inserted replaced
53940:f8b2179a55d0 53941:f9302cf718c9
   716         hSplashLib = NULL;
   716         hSplashLib = NULL;
   717     }
   717     }
   718 }
   718 }
   719 
   719 
   720 /*
   720 /*
   721  * Block current thread and continue execution in a new thread
   721  * Signature adapter for pthread_create() or thr_create().
       
   722  */
       
   723 static void* ThreadJavaMain(void* args) {
       
   724     return (void*)(intptr_t)JavaMain(args);
       
   725 }
       
   726 
       
   727 /*
       
   728  * Block current thread and continue execution in a new thread.
   722  */
   729  */
   723 int
   730 int
   724 ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
   731 CallJavaMainInNewThread(jlong stack_size, void* args) {
   725     int rslt;
   732     int rslt;
   726 #ifndef __solaris__
   733 #ifndef __solaris__
   727     pthread_t tid;
   734     pthread_t tid;
   728     pthread_attr_t attr;
   735     pthread_attr_t attr;
   729     pthread_attr_init(&attr);
   736     pthread_attr_init(&attr);
   730     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
   737     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
   731 
   738 
   732     if (stack_size > 0) {
   739     if (stack_size > 0) {
   733       pthread_attr_setstacksize(&attr, stack_size);
   740         pthread_attr_setstacksize(&attr, stack_size);
   734     }
   741     }
   735     pthread_attr_setguardsize(&attr, 0); // no pthread guard page on java threads
   742     pthread_attr_setguardsize(&attr, 0); // no pthread guard page on java threads
   736 
   743 
   737     if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) {
   744     if (pthread_create(&tid, &attr, ThreadJavaMain, args) == 0) {
   738       void * tmp;
   745         void* tmp;
   739       pthread_join(tid, &tmp);
   746         pthread_join(tid, &tmp);
   740       rslt = (int)(intptr_t)tmp;
   747         rslt = (int)(intptr_t)tmp;
   741     } else {
   748     } else {
   742      /*
   749        /*
   743       * Continue execution in current thread if for some reason (e.g. out of
   750         * Continue execution in current thread if for some reason (e.g. out of
   744       * memory/LWP)  a new thread can't be created. This will likely fail
   751         * memory/LWP)  a new thread can't be created. This will likely fail
   745       * later in continuation as JNI_CreateJavaVM needs to create quite a
   752         * later in JavaMain as JNI_CreateJavaVM needs to create quite a
   746       * few new threads, anyway, just give it a try..
   753         * few new threads, anyway, just give it a try..
   747       */
   754         */
   748       rslt = continuation(args);
   755         rslt = JavaMain(args);
   749     }
   756     }
   750 
   757 
   751     pthread_attr_destroy(&attr);
   758     pthread_attr_destroy(&attr);
   752 #else /* __solaris__ */
   759 #else /* __solaris__ */
   753     thread_t tid;
   760     thread_t tid;
   754     long flags = 0;
   761     long flags = 0;
   755     if (thr_create(NULL, stack_size, (void *(*)(void *))continuation, args, flags, &tid) == 0) {
   762     if (thr_create(NULL, stack_size, ThreadJavaMain, args, flags, &tid) == 0) {
   756       void * tmp;
   763         void* tmp;
   757       thr_join(tid, NULL, &tmp);
   764         thr_join(tid, NULL, &tmp);
   758       rslt = (int)(intptr_t)tmp;
   765         rslt = (int)(intptr_t)tmp;
   759     } else {
   766     } else {
   760       /* See above. Continue in current thread if thr_create() failed */
   767         /* See above. Continue in current thread if thr_create() failed */
   761       rslt = continuation(args);
   768         rslt = JavaMain(args);
   762     }
   769     }
   763 #endif /* !__solaris__ */
   770 #endif /* !__solaris__ */
   764     return rslt;
   771     return rslt;
   765 }
   772 }
   766 
   773