8190329: [macos] Swing InterOp Platform.exit() crash

Co-authored-by: Kevin Rushforth <kcr@openjdk.org>
Reviewed-by: kcr, azvegint
This commit is contained in:
Prasanta Sadhukhan 2024-09-04 05:05:20 +00:00
parent 5998f4b6f5
commit 9a1024dec6
3 changed files with 26 additions and 8 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -117,12 +117,20 @@ AWT_ASSERT_APPKIT_THREAD;
// don't install the EAWT delegate if another kind of NSApplication is installed, like say, Safari
BOOL shouldInstall = NO;
BOOL overrideDelegate = (getenv("AWT_OVERRIDE_NSDELEGATE") != NULL);
BOOL isApplicationOwner = NO;
if (NSApp != nil) {
if ([NSApp isMemberOfClass:[NSApplication class]] && overrideDelegate) shouldInstall = YES;
if ([NSApp isKindOfClass:[NSApplicationAWT class]]) shouldInstall = YES;
if ([NSApp isKindOfClass:[NSApplicationAWT class]]) {
shouldInstall = YES;
isApplicationOwner = YES;
}
}
checked = YES;
if (!shouldInstall) return nil;
if (!shouldInstall) {
[ThreadUtilities setApplicationOwner:NO];
return nil;
}
[ThreadUtilities setApplicationOwner:isApplicationOwner];
sApplicationDelegate = [[ApplicationDelegate alloc] init];
return sApplicationDelegate;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -131,6 +131,7 @@ __attribute__((visibility("default")))
+ (JNIEnv*)getJNIEnvUncached;
+ (void)detachCurrentThread;
+ (void)setAppkitThreadGroup:(jobject)group;
+ (void)setApplicationOwner:(BOOL)owner;
+ (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block;
+ (void)performOnMainThread:(SEL)aSelector on:(id)target withObject:(id)arg waitUntilDone:(BOOL)wait;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -31,6 +31,7 @@
// The following must be named "jvm", as there are extern references to it in AWT
JavaVM *jvm = NULL;
static BOOL isNSApplicationOwner = NO;
static JNIEnv *appKitEnv = NULL;
static jobject appkitThreadGroup = NULL;
static NSString* JavaRunLoopMode = @"AWTRunLoopMode";
@ -59,12 +60,20 @@ static inline void attachCurrentThread(void** env) {
nil];
}
+ (void)setApplicationOwner:(BOOL)owner {
isNSApplicationOwner = owner;
}
+ (JNIEnv*)getJNIEnv {
AWT_ASSERT_APPKIT_THREAD;
if (appKitEnv == NULL) {
attachCurrentThread((void **)&appKitEnv);
if (isNSApplicationOwner) {
if (appKitEnv == NULL) {
attachCurrentThread((void **)&appKitEnv);
}
return appKitEnv;
} else {
return [ThreadUtilities getJNIEnvUncached];
}
return appKitEnv;
}
+ (JNIEnv*)getJNIEnvUncached {