src/java.base/macosx/native/libjli/java_md_macosx.m
changeset 53941 f9302cf718c9
parent 52788 241b8151b6b6
child 57220 6a80fd1912ef
child 58280 ef8c8cf9256a
equal deleted inserted replaced
53940:f8b2179a55d0 53941:f9302cf718c9
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   715         hSplashLib = NULL;
   715         hSplashLib = NULL;
   716     }
   716     }
   717 }
   717 }
   718 
   718 
   719 /*
   719 /*
   720  * Block current thread and continue execution in a new thread
   720  * Signature adapter for pthread_create().
       
   721  */
       
   722 static void* ThreadJavaMain(void* args) {
       
   723     return (void*)(intptr_t)JavaMain(args);
       
   724 }
       
   725 
       
   726 /*
       
   727  * Block current thread and continue execution in a new thread.
   721  */
   728  */
   722 int
   729 int
   723 ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
   730 CallJavaMainInNewThread(jlong stack_size, void* args) {
   724     int rslt;
   731     int rslt;
   725     pthread_t tid;
   732     pthread_t tid;
   726     pthread_attr_t attr;
   733     pthread_attr_t attr;
   727     pthread_attr_init(&attr);
   734     pthread_attr_init(&attr);
   728     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
   735     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
   729 
   736 
   730     if (stack_size > 0) {
   737     if (stack_size > 0) {
   731       pthread_attr_setstacksize(&attr, stack_size);
   738         pthread_attr_setstacksize(&attr, stack_size);
   732     }
   739     }
   733     pthread_attr_setguardsize(&attr, 0); // no pthread guard page on java threads
   740     pthread_attr_setguardsize(&attr, 0); // no pthread guard page on java threads
   734 
   741 
   735     if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) {
   742     if (pthread_create(&tid, &attr, ThreadJavaMain, args) == 0) {
   736       void * tmp;
   743         void* tmp;
   737       pthread_join(tid, &tmp);
   744         pthread_join(tid, &tmp);
   738       rslt = (int)(intptr_t)tmp;
   745         rslt = (int)(intptr_t)tmp;
   739     } else {
   746     } else {
   740      /*
   747        /*
   741       * Continue execution in current thread if for some reason (e.g. out of
   748         * Continue execution in current thread if for some reason (e.g. out of
   742       * memory/LWP)  a new thread can't be created. This will likely fail
   749         * memory/LWP)  a new thread can't be created. This will likely fail
   743       * later in continuation as JNI_CreateJavaVM needs to create quite a
   750         * later in JavaMain as JNI_CreateJavaVM needs to create quite a
   744       * few new threads, anyway, just give it a try..
   751         * few new threads, anyway, just give it a try..
   745       */
   752         */
   746       rslt = continuation(args);
   753         rslt = JavaMain(args);
   747     }
   754     }
   748 
   755 
   749     pthread_attr_destroy(&attr);
   756     pthread_attr_destroy(&attr);
   750     return rslt;
   757     return rslt;
   751 }
   758 }