File tree 3 files changed +26
-8
lines changed
src/java.desktop/macosx/native
3 files changed +26
-8
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright (c) 2011, 2018 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2011, 2024 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -117,12 +117,20 @@ + (ApplicationDelegate *)sharedDelegate {
117
117
// don't install the EAWT delegate if another kind of NSApplication is installed, like say, Safari
118
118
BOOL shouldInstall = NO ;
119
119
BOOL overrideDelegate = (getenv (" AWT_OVERRIDE_NSDELEGATE" ) != NULL );
120
+ BOOL isApplicationOwner = NO ;
120
121
if (NSApp != nil ) {
121
122
if ([NSApp isMemberOfClass: [NSApplication class ]] && overrideDelegate) shouldInstall = YES ;
122
- if ([NSApp isKindOfClass: [NSApplicationAWT class ]]) shouldInstall = YES ;
123
+ if ([NSApp isKindOfClass: [NSApplicationAWT class ]]) {
124
+ shouldInstall = YES ;
125
+ isApplicationOwner = YES ;
126
+ }
123
127
}
124
128
checked = YES ;
125
- if (!shouldInstall) return nil ;
129
+ if (!shouldInstall) {
130
+ [ThreadUtilities setApplicationOwner: NO ];
131
+ return nil ;
132
+ }
133
+ [ThreadUtilities setApplicationOwner: isApplicationOwner];
126
134
127
135
sApplicationDelegate = [[ApplicationDelegate alloc ] init ];
128
136
return sApplicationDelegate ;
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright (c) 2011, 2013 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2011, 2024 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -131,6 +131,7 @@ __attribute__((visibility("default")))
131
131
+ (JNIEnv*)getJNIEnvUncached;
132
132
+ (void )detachCurrentThread;
133
133
+ (void )setAppkitThreadGroup:(jobject)group;
134
+ + (void )setApplicationOwner:(BOOL )owner;
134
135
135
136
+ (void )performOnMainThreadWaiting:(BOOL )wait block:(void (^)())block;
136
137
+ (void )performOnMainThread:(SEL )aSelector on:(id )target withObject:(id )arg waitUntilDone:(BOOL )wait;
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright (c) 2011, 2013 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2011, 2024 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
31
31
32
32
// The following must be named "jvm", as there are extern references to it in AWT
33
33
JavaVM *jvm = NULL ;
34
+ static BOOL isNSApplicationOwner = NO ;
34
35
static JNIEnv *appKitEnv = NULL ;
35
36
static jobject appkitThreadGroup = NULL ;
36
37
static NSString * JavaRunLoopMode = @" AWTRunLoopMode" ;
@@ -59,12 +60,20 @@ + (void)initialize {
59
60
nil ];
60
61
}
61
62
63
+ + (void )setApplicationOwner : (BOOL )owner {
64
+ isNSApplicationOwner = owner;
65
+ }
66
+
62
67
+ (JNIEnv*)getJNIEnv {
63
68
AWT_ASSERT_APPKIT_THREAD;
64
- if (appKitEnv == NULL ) {
65
- attachCurrentThread ((void **)&appKitEnv);
69
+ if (isNSApplicationOwner) {
70
+ if (appKitEnv == NULL ) {
71
+ attachCurrentThread ((void **)&appKitEnv);
72
+ }
73
+ return appKitEnv;
74
+ } else {
75
+ return [ThreadUtilities getJNIEnvUncached ];
66
76
}
67
- return appKitEnv;
68
77
}
69
78
70
79
+ (JNIEnv*)getJNIEnvUncached {
You can’t perform that action at this time.
0 commit comments