8215009: GCC 8 compilation error in libjli

Reviewed-by: dholmes, mikael, rriggs
This commit is contained in:
Dmitry Chuyko 2019-02-27 13:13:15 +03:00
parent 7af48cfb45
commit b818234d2a
5 changed files with 86 additions and 63 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -717,10 +717,17 @@ void SplashFreeLibrary() {
} }
/* /*
* Block current thread and continue execution in a new thread * Signature adapter for pthread_create().
*/
static void* ThreadJavaMain(void* args) {
return (void*)(intptr_t)JavaMain(args);
}
/*
* Block current thread and continue execution in a new thread.
*/ */
int int
ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) { CallJavaMainInNewThread(jlong stack_size, void* args) {
int rslt; int rslt;
pthread_t tid; pthread_t tid;
pthread_attr_t attr; pthread_attr_t attr;
@ -728,22 +735,22 @@ ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
if (stack_size > 0) { if (stack_size > 0) {
pthread_attr_setstacksize(&attr, stack_size); pthread_attr_setstacksize(&attr, stack_size);
} }
pthread_attr_setguardsize(&attr, 0); // no pthread guard page on java threads pthread_attr_setguardsize(&attr, 0); // no pthread guard page on java threads
if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) { if (pthread_create(&tid, &attr, ThreadJavaMain, args) == 0) {
void * tmp; void* tmp;
pthread_join(tid, &tmp); pthread_join(tid, &tmp);
rslt = (int)(intptr_t)tmp; rslt = (int)(intptr_t)tmp;
} else { } else {
/* /*
* Continue execution in current thread if for some reason (e.g. out of * Continue execution in current thread if for some reason (e.g. out of
* memory/LWP) a new thread can't be created. This will likely fail * memory/LWP) a new thread can't be created. This will likely fail
* later in continuation as JNI_CreateJavaVM needs to create quite a * later in JavaMain as JNI_CreateJavaVM needs to create quite a
* few new threads, anyway, just give it a try.. * few new threads, anyway, just give it a try..
*/ */
rslt = continuation(args); rslt = JavaMain(args);
} }
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -388,8 +388,8 @@ JLI_Launch(int argc, char ** argv, /* main argc, argv */
} while (JNI_FALSE) } while (JNI_FALSE)
int JNICALL int
JavaMain(void * _args) JavaMain(void* _args)
{ {
JavaMainArgs *args = (JavaMainArgs *)_args; JavaMainArgs *args = (JavaMainArgs *)_args;
int argc = args->argc; int argc = args->argc;
@ -2348,7 +2348,7 @@ ContinueInNewThread(InvocationFunctions* ifn, jlong threadStackSize,
args.what = what; args.what = what;
args.ifn = *ifn; args.ifn = *ifn;
rslt = ContinueInNewThread0(JavaMain, threadStackSize, (void*)&args); rslt = CallJavaMainInNewThread(threadStackSize, (void*)&args);
/* If the caller has deemed there is an error we /* If the caller has deemed there is an error we
* simply return that, otherwise we return the value of * simply return that, otherwise we return the value of
* the callee * the callee

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -156,10 +156,9 @@ JLI_ReportExceptionDescription(JNIEnv * env);
void PrintMachineDependentOptions(); void PrintMachineDependentOptions();
/* /*
* Block current thread and continue execution in new thread * Block current thread and continue execution in new thread.
*/ */
int ContinueInNewThread0(int (JNICALL *continuation)(void *), int CallJavaMainInNewThread(jlong stack_size, void* args);
jlong stack_size, void * args);
/* sun.java.launcher.* platform properties. */ /* sun.java.launcher.* platform properties. */
void SetJavaLauncherPlatformProps(void); void SetJavaLauncherPlatformProps(void);
@ -224,7 +223,10 @@ jobjectArray CreateApplicationArgs(JNIEnv *env, char **strv, int argc);
jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc); jobjectArray NewPlatformStringArray(JNIEnv *env, char **strv, int strc);
jclass GetLauncherHelperClass(JNIEnv *env); jclass GetLauncherHelperClass(JNIEnv *env);
int JNICALL JavaMain(void * args); /* entry point */ /*
* Entry point.
*/
int JavaMain(void* args);
enum LaunchMode { // cf. sun.launcher.LauncherHelper enum LaunchMode { // cf. sun.launcher.LauncherHelper
LM_UNKNOWN = 0, LM_UNKNOWN = 0,

View File

@ -718,10 +718,17 @@ void SplashFreeLibrary() {
} }
/* /*
* Block current thread and continue execution in a new thread * Signature adapter for pthread_create() or thr_create().
*/
static void* ThreadJavaMain(void* args) {
return (void*)(intptr_t)JavaMain(args);
}
/*
* Block current thread and continue execution in a new thread.
*/ */
int int
ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) { CallJavaMainInNewThread(jlong stack_size, void* args) {
int rslt; int rslt;
#ifndef __solaris__ #ifndef __solaris__
pthread_t tid; pthread_t tid;
@ -730,35 +737,35 @@ ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
if (stack_size > 0) { if (stack_size > 0) {
pthread_attr_setstacksize(&attr, stack_size); pthread_attr_setstacksize(&attr, stack_size);
} }
pthread_attr_setguardsize(&attr, 0); // no pthread guard page on java threads pthread_attr_setguardsize(&attr, 0); // no pthread guard page on java threads
if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) { if (pthread_create(&tid, &attr, ThreadJavaMain, args) == 0) {
void * tmp; void* tmp;
pthread_join(tid, &tmp); pthread_join(tid, &tmp);
rslt = (int)(intptr_t)tmp; rslt = (int)(intptr_t)tmp;
} else { } else {
/* /*
* Continue execution in current thread if for some reason (e.g. out of * Continue execution in current thread if for some reason (e.g. out of
* memory/LWP) a new thread can't be created. This will likely fail * memory/LWP) a new thread can't be created. This will likely fail
* later in continuation as JNI_CreateJavaVM needs to create quite a * later in JavaMain as JNI_CreateJavaVM needs to create quite a
* few new threads, anyway, just give it a try.. * few new threads, anyway, just give it a try..
*/ */
rslt = continuation(args); rslt = JavaMain(args);
} }
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
#else /* __solaris__ */ #else /* __solaris__ */
thread_t tid; thread_t tid;
long flags = 0; long flags = 0;
if (thr_create(NULL, stack_size, (void *(*)(void *))continuation, args, flags, &tid) == 0) { if (thr_create(NULL, stack_size, ThreadJavaMain, args, flags, &tid) == 0) {
void * tmp; void* tmp;
thr_join(tid, NULL, &tmp); thr_join(tid, NULL, &tmp);
rslt = (int)(intptr_t)tmp; rslt = (int)(intptr_t)tmp;
} else { } else {
/* See above. Continue in current thread if thr_create() failed */ /* See above. Continue in current thread if thr_create() failed */
rslt = continuation(args); rslt = JavaMain(args);
} }
#endif /* !__solaris__ */ #endif /* !__solaris__ */
return rslt; return rslt;

View File

@ -704,10 +704,17 @@ void SplashFreeLibrary() {
} }
/* /*
* Block current thread and continue execution in a new thread * Signature adapter for _beginthreadex().
*/
static unsigned __stdcall ThreadJavaMain(void* args) {
return (unsigned)JavaMain(args);
}
/*
* Block current thread and continue execution in a new thread.
*/ */
int int
ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) { CallJavaMainInNewThread(jlong stack_size, void* args) {
int rslt = 0; int rslt = 0;
unsigned thread_id; unsigned thread_id;
@ -722,20 +729,20 @@ ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void
* source (os_win32.cpp) for details. * source (os_win32.cpp) for details.
*/ */
HANDLE thread_handle = HANDLE thread_handle =
(HANDLE)_beginthreadex(NULL, (HANDLE)_beginthreadex(NULL,
(unsigned)stack_size, (unsigned)stack_size,
continuation, ThreadJavaMain,
args, args,
STACK_SIZE_PARAM_IS_A_RESERVATION, STACK_SIZE_PARAM_IS_A_RESERVATION,
&thread_id); &thread_id);
if (thread_handle == NULL) { if (thread_handle == NULL) {
thread_handle = thread_handle =
(HANDLE)_beginthreadex(NULL, (HANDLE)_beginthreadex(NULL,
(unsigned)stack_size, (unsigned)stack_size,
continuation, ThreadJavaMain,
args, args,
0, 0,
&thread_id); &thread_id);
} }
/* AWT preloading (AFTER main thread start) */ /* AWT preloading (AFTER main thread start) */
@ -772,11 +779,11 @@ ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void
#endif /* ENABLE_AWT_PRELOAD */ #endif /* ENABLE_AWT_PRELOAD */
if (thread_handle) { if (thread_handle) {
WaitForSingleObject(thread_handle, INFINITE); WaitForSingleObject(thread_handle, INFINITE);
GetExitCodeThread(thread_handle, &rslt); GetExitCodeThread(thread_handle, &rslt);
CloseHandle(thread_handle); CloseHandle(thread_handle);
} else { } else {
rslt = continuation(args); rslt = JavaMain(args);
} }
#ifdef ENABLE_AWT_PRELOAD #ifdef ENABLE_AWT_PRELOAD