Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit 92c2f08

Browse files
committedJan 22, 2021
8259869: [macOS] Remove desktop module dependencies on JNF Reference APIs
Reviewed-by: serb
1 parent a7c2ebc commit 92c2f08

21 files changed

+146
-134
lines changed
 

‎src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m

+4-7
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ - (void) dealloc {
117117
{
118118
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
119119

120-
JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
120+
(*env)->DeleteGlobalRef(env, fInputMethodLOCKABLE);
121121
fInputMethodLOCKABLE = NULL;
122122
}
123123

@@ -1359,14 +1359,10 @@ - (void)setInputMethod:(jobject)inputMethod
13591359

13601360
// Get rid of the old one
13611361
if (fInputMethodLOCKABLE) {
1362-
JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
1362+
(*env)->DeleteGlobalRef(env, fInputMethodLOCKABLE);
13631363
}
13641364

1365-
// Save a global ref to the new input method.
1366-
if (inputMethod != NULL)
1367-
fInputMethodLOCKABLE = JNFNewGlobalRef(env, inputMethod);
1368-
else
1369-
fInputMethodLOCKABLE = NULL;
1365+
fInputMethodLOCKABLE = inputMethod; // input method arg must be a GlobalRef
13701366

13711367
NSTextInputContext *curContxt = [NSTextInputContext currentInputContext];
13721368
kbdLayout = curContxt.selectedKeyboardInputSource;
@@ -1408,6 +1404,7 @@ - (void)abandonInput
14081404

14091405
NSRect rect = NSMakeRect(originX, originY, width, height);
14101406
jobject cPlatformView = (*env)->NewWeakGlobalRef(env, obj);
1407+
CHECK_EXCEPTION();
14111408

14121409
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
14131410

‎src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@
3232
#import "LWCToolkit.h"
3333

3434
@class AWTView;
35-
@class JNFWeakJObjectWrapper;
3635

3736
@interface AWTWindow : NSObject <NSWindowDelegate> {
3837
@private
39-
JNFWeakJObjectWrapper *javaPlatformWindow;
38+
jobject javaPlatformWindow; /* This is a weak ref. Always copy to a local ref before using */
4039
CMenuBar *javaMenuBar;
4140
NSSize javaMinSize;
4241
NSSize javaMaxSize;
@@ -53,7 +52,7 @@
5352
// An instance of either AWTWindow_Normal or AWTWindow_Panel
5453
@property (nonatomic, retain) NSWindow *nsWindow;
5554

56-
@property (nonatomic, retain) JNFWeakJObjectWrapper *javaPlatformWindow;
55+
@property (nonatomic) jobject javaPlatformWindow;
5756
@property (nonatomic, retain) CMenuBar *javaMenuBar;
5857
@property (nonatomic, retain) AWTWindow *ownerWindow;
5958
@property (nonatomic) NSSize javaMinSize;
@@ -65,7 +64,7 @@
6564
@property (nonatomic) BOOL isMinimizing;
6665
@property (nonatomic) BOOL keyNotificationRecd;
6766

68-
- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)javaPlatformWindow
67+
- (id) initWithPlatformWindow:(jobject)javaPlatformWindow
6968
ownerWindow:owner
7069
styleBits:(jint)styleBits
7170
frameRect:(NSRect)frameRect

‎src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m

+23-23
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ - (void)postGesture:(NSEvent *)event as:(jint)type a:(jdouble)a b:(jdouble)b {
116116
AWT_ASSERT_APPKIT_THREAD;
117117

118118
JNIEnv *env = [ThreadUtilities getJNIEnv];
119-
jobject platformWindow = [((AWTWindow *)self.delegate).javaPlatformWindow jObjectWithEnv:env];
119+
jobject platformWindow = (*env)->NewLocalRef(env, ((AWTWindow *)self.delegate).javaPlatformWindow);
120120
if (platformWindow != NULL) {
121121
// extract the target AWT Window object out of the CPlatformWindow
122122
GET_CPLATFORM_WINDOW_CLASS();
@@ -281,7 +281,7 @@ - (void) setPropertiesForStyleBits:(jint)bits mask:(jint)mask {
281281
}
282282
}
283283

284-
- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)platformWindow
284+
- (id) initWithPlatformWindow:(jobject)platformWindow
285285
ownerWindow:owner
286286
styleBits:(jint)bits
287287
frameRect:(NSRect)rect
@@ -482,7 +482,7 @@ - (void) dealloc {
482482
AWT_ASSERT_APPKIT_THREAD;
483483

484484
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
485-
[self.javaPlatformWindow setJObject:nil withEnv:env];
485+
(*env)->DeleteWeakGlobalRef(env, self.javaPlatformWindow);
486486
self.javaPlatformWindow = nil;
487487
self.nsWindow = nil;
488488
self.ownerWindow = nil;
@@ -494,7 +494,7 @@ - (BOOL) isBlocked {
494494
BOOL isBlocked = NO;
495495

496496
JNIEnv *env = [ThreadUtilities getJNIEnv];
497-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
497+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
498498
if (platformWindow != NULL) {
499499
GET_CPLATFORM_WINDOW_CLASS_RETURN(isBlocked);
500500
DECLARE_METHOD_RETURN(jm_isBlocked, jc_CPlatformWindow, "isBlocked", "()Z", isBlocked);
@@ -511,7 +511,7 @@ - (BOOL) isSimpleWindowOwnedByEmbeddedFrame {
511511
BOOL isSimpleWindowOwnedByEmbeddedFrame = NO;
512512

513513
JNIEnv *env = [ThreadUtilities getJNIEnv];
514-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
514+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
515515
if (platformWindow != NULL) {
516516
GET_CPLATFORM_WINDOW_CLASS_RETURN(NO);
517517
DECLARE_METHOD_RETURN(jm_isBlocked, jc_CPlatformWindow, "isSimpleWindowOwnedByEmbeddedFrame", "()Z", NO);
@@ -532,7 +532,7 @@ + (BOOL) isJavaPlatformWindowVisible:(NSWindow *)window {
532532
[AWTToolkit eventCountPlusPlus];
533533

534534
JNIEnv *env = [ThreadUtilities getJNIEnv];
535-
jobject platformWindow = [awtWindow.javaPlatformWindow jObjectWithEnv:env];
535+
jobject platformWindow = (*env)->NewLocalRef(env, awtWindow.javaPlatformWindow);
536536
if (platformWindow != NULL) {
537537
GET_CPLATFORM_WINDOW_CLASS_RETURN(isVisible);
538538
DECLARE_METHOD_RETURN(jm_isVisible, jc_CPlatformWindow, "isVisible", "()Z", isVisible)
@@ -603,7 +603,7 @@ - (BOOL) canBecomeMainWindow {
603603
[AWTToolkit eventCountPlusPlus];
604604

605605
JNIEnv *env = [ThreadUtilities getJNIEnv];
606-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
606+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
607607
if (platformWindow != NULL) {
608608
GET_CPLATFORM_WINDOW_CLASS_RETURN(NO);
609609
DECLARE_METHOD_RETURN(jm_checkBlockingAndOrder, jc_CPlatformWindow, "checkBlockingAndOrder", "()Z", NO);
@@ -632,7 +632,7 @@ - (void) _deliverMoveResizeEvent {
632632
// the bounds of the window to avoid the Dock or remain on screen.
633633
[AWTToolkit eventCountPlusPlus];
634634
JNIEnv *env = [ThreadUtilities getJNIEnv];
635-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
635+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
636636
if (platformWindow == NULL) {
637637
// TODO: create generic AWT assert
638638
}
@@ -710,7 +710,7 @@ - (void) _deliverIconify:(BOOL)iconify {
710710

711711
[AWTToolkit eventCountPlusPlus];
712712
JNIEnv *env = [ThreadUtilities getJNIEnv];
713-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
713+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
714714
if (platformWindow != NULL) {
715715
GET_CPLATFORM_WINDOW_CLASS();
716716
DECLARE_METHOD(jm_deliverIconify, jc_CPlatformWindow, "deliverIconify", "(Z)V");
@@ -726,7 +726,7 @@ - (void)windowWillMiniaturize:(NSNotification *)notification {
726726
self.isMinimizing = YES;
727727

728728
JNIEnv *env = [ThreadUtilities getJNIEnv];
729-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
729+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
730730
if (platformWindow != NULL) {
731731
GET_CPLATFORM_WINDOW_CLASS();
732732
DECLARE_METHOD(jm_windowWillMiniaturize, jc_CPlatformWindow, "windowWillMiniaturize", "()V");
@@ -757,9 +757,9 @@ - (void)windowDidDeminiaturize:(NSNotification *)notification {
757757
- (void) _deliverWindowFocusEvent:(BOOL)focused oppositeWindow:(AWTWindow *)opposite {
758758
//AWT_ASSERT_APPKIT_THREAD;
759759
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
760-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
760+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
761761
if (platformWindow != NULL) {
762-
jobject oppositeWindow = [opposite.javaPlatformWindow jObjectWithEnv:env];
762+
jobject oppositeWindow = (*env)->NewLocalRef(env, opposite.javaPlatformWindow);
763763
GET_CPLATFORM_WINDOW_CLASS();
764764
DECLARE_METHOD(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(ZLsun/lwawt/macosx/CPlatformWindow;)V");
765765
(*env)->CallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused, oppositeWindow);
@@ -788,7 +788,7 @@ - (void) windowDidBecomeMain: (NSNotification *) notification {
788788
}
789789

790790
JNIEnv *env = [ThreadUtilities getJNIEnv];
791-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
791+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
792792
if (platformWindow != NULL) {
793793
GET_CPLATFORM_WINDOW_CLASS();
794794
DECLARE_METHOD(jm_windowDidBecomeMain, jc_CPlatformWindow, "windowDidBecomeMain", "()V");
@@ -904,7 +904,7 @@ - (BOOL)windowShouldClose:(id)sender {
904904
AWT_ASSERT_APPKIT_THREAD;
905905
[AWTToolkit eventCountPlusPlus];
906906
JNIEnv *env = [ThreadUtilities getJNIEnv];
907-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
907+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
908908
if (platformWindow != NULL) {
909909
GET_CPLATFORM_WINDOW_CLASS_RETURN(NO);
910910
DECLARE_METHOD_RETURN(jm_deliverWindowClosingEvent, jc_CPlatformWindow, "deliverWindowClosingEvent", "()V", NO);
@@ -922,7 +922,7 @@ - (void)_notifyFullScreenOp:(jint)op withEnv:(JNIEnv *)env {
922922
"handleFullScreenEventFromNative", "(Ljava/awt/Window;I)V");
923923
GET_CPLATFORM_WINDOW_CLASS();
924924
DECLARE_FIELD(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;");
925-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
925+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
926926
if (platformWindow != NULL) {
927927
jobject awtWindow = (*env)->GetObjectField(env, platformWindow, jf_target);
928928
if (awtWindow != NULL) {
@@ -939,7 +939,7 @@ - (void)windowWillEnterFullScreen:(NSNotification *)notification {
939939
JNIEnv *env = [ThreadUtilities getJNIEnv];
940940
GET_CPLATFORM_WINDOW_CLASS();
941941
DECLARE_METHOD(jm_windowWillEnterFullScreen, jc_CPlatformWindow, "windowWillEnterFullScreen", "()V");
942-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
942+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
943943
if (platformWindow != NULL) {
944944
(*env)->CallVoidMethod(env, platformWindow, jm_windowWillEnterFullScreen);
945945
CHECK_EXCEPTION();
@@ -952,7 +952,7 @@ - (void)windowDidEnterFullScreen:(NSNotification *)notification {
952952
JNIEnv *env = [ThreadUtilities getJNIEnv];
953953
GET_CPLATFORM_WINDOW_CLASS();
954954
DECLARE_METHOD(jm_windowDidEnterFullScreen, jc_CPlatformWindow, "windowDidEnterFullScreen", "()V");
955-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
955+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
956956
if (platformWindow != NULL) {
957957
(*env)->CallVoidMethod(env, platformWindow, jm_windowDidEnterFullScreen);
958958
CHECK_EXCEPTION();
@@ -971,7 +971,7 @@ - (void)windowWillExitFullScreen:(NSNotification *)notification {
971971
jm_windowWillExitFullScreen = (*env)->GetMethodID(env, jc_CPlatformWindow, "windowWillExitFullScreen", "()V");
972972
}
973973
CHECK_NULL(jm_windowWillExitFullScreen);
974-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
974+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
975975
if (platformWindow != NULL) {
976976
(*env)->CallVoidMethod(env, platformWindow, jm_windowWillExitFullScreen);
977977
CHECK_EXCEPTION();
@@ -982,7 +982,7 @@ - (void)windowWillExitFullScreen:(NSNotification *)notification {
982982

983983
- (void)windowDidExitFullScreen:(NSNotification *)notification {
984984
JNIEnv *env = [ThreadUtilities getJNIEnv];
985-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
985+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
986986
if (platformWindow != NULL) {
987987
GET_CPLATFORM_WINDOW_CLASS();
988988
DECLARE_METHOD(jm_windowDidExitFullScreen, jc_CPlatformWindow, "windowDidExitFullScreen", "()V");
@@ -1001,7 +1001,7 @@ - (void)sendEvent:(NSEvent *)event {
10011001
// in front of its nearest parent.
10021002
if (self.ownerWindow != nil) {
10031003
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
1004-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
1004+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
10051005
if (platformWindow != NULL) {
10061006
GET_CPLATFORM_WINDOW_CLASS();
10071007
DECLARE_METHOD(jm_orderAboveSiblings, jc_CPlatformWindow, "orderAboveSiblings", "()V");
@@ -1020,7 +1020,7 @@ - (void)sendEvent:(NSEvent *)event {
10201020
// Check if the click happened in the non-client area (title bar)
10211021
if (p.y >= (frame.origin.y + contentRect.size.height)) {
10221022
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
1023-
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
1023+
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
10241024
if (platformWindow != NULL) {
10251025
// Currently, no need to deliver the whole NSEvent.
10261026
GET_CPLATFORM_WINDOW_CLASS();
@@ -1103,7 +1103,7 @@ + (AWTWindow *) lastKeyWindow {
11031103

11041104
JNI_COCOA_ENTER(env);
11051105

1106-
JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env];
1106+
jobject platformWindow = (*env)->NewWeakGlobalRef(env, obj);
11071107
NSView *contentView = OBJC(contentViewPtr);
11081108
NSRect frameRect = NSMakeRect(x, y, w, h);
11091109
AWTWindow *owner = [OBJC(ownerPtr) delegate];
@@ -1544,7 +1544,7 @@ + (AWTWindow *) lastKeyWindow {
15441544
[ThreadUtilities performOnMainThreadWaiting:YES block:^{
15451545
AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse];
15461546
if (awtWindow != nil) {
1547-
topmostWindowUnderMouse = [awtWindow.javaPlatformWindow jObject];
1547+
topmostWindowUnderMouse = awtWindow.javaPlatformWindow;
15481548
}
15491549
}];
15501550

‎src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ - (void)declareTypes:(NSArray*)types withOwner:(jobject)owner jniEnv:(JNIEnv*)en
6666
@synchronized(self) {
6767
if (owner != NULL) {
6868
if (self.clipboardOwner != NULL) {
69-
JNFDeleteGlobalRef(env, self.clipboardOwner);
69+
(*env)->DeleteGlobalRef(env, self.clipboardOwner);
7070
}
71-
self.clipboardOwner = JNFNewGlobalRef(env, owner);
71+
self.clipboardOwner = (*env)->NewGlobalRef(env, owner);
7272
}
7373
}
7474
[ThreadUtilities performOnMainThreadWaiting:YES block:^() {
@@ -101,7 +101,7 @@ - (void)checkPasteboard:(id)sender {
101101
if (self.clipboardOwner) {
102102
(*env)->CallVoidMethod(env, self.clipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event)
103103
CHECK_EXCEPTION();
104-
JNFDeleteGlobalRef(env, self.clipboardOwner);
104+
(*env)->DeleteGlobalRef(env, self.clipboardOwner);
105105
self.clipboardOwner = NULL;
106106
}
107107
}

‎src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m

+6-6
Original file line numberDiff line numberDiff line change
@@ -169,32 +169,32 @@ - (void)removeFromView:(JNIEnv *)env
169169

170170
// Clean up JNI refs
171171
if (fComponent != NULL) {
172-
JNFDeleteGlobalRef(env, fComponent);
172+
(*env)->DeleteGlobalRef(env, fComponent);
173173
fComponent = NULL;
174174
}
175175

176176
if (fDragSourceContextPeer != NULL) {
177-
JNFDeleteGlobalRef(env, fDragSourceContextPeer);
177+
(*env)->DeleteGlobalRef(env, fDragSourceContextPeer);
178178
fDragSourceContextPeer = NULL;
179179
}
180180

181181
if (fTransferable != NULL) {
182-
JNFDeleteGlobalRef(env, fTransferable);
182+
(*env)->DeleteGlobalRef(env, fTransferable);
183183
fTransferable = NULL;
184184
}
185185

186186
if (fTriggerEvent != NULL) {
187-
JNFDeleteGlobalRef(env, fTriggerEvent);
187+
(*env)->DeleteGlobalRef(env, fTriggerEvent);
188188
fTriggerEvent = NULL;
189189
}
190190

191191
if (fFormats != NULL) {
192-
JNFDeleteGlobalRef(env, fFormats);
192+
(*env)->DeleteGlobalRef(env, fFormats);
193193
fFormats = NULL;
194194
}
195195

196196
if (fFormatMap != NULL) {
197-
JNFDeleteGlobalRef(env, fFormatMap);
197+
(*env)->DeleteGlobalRef(env, fFormatMap);
198198
fFormatMap = NULL;
199199
}
200200

‎src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@
5050
JNI_COCOA_ENTER(env);
5151

5252
// Global references are disposed when the DragSource is removed
53-
jobject gComponent = JNFNewGlobalRef(env, jcomponent);
54-
jobject gDragSourceContextPeer = JNFNewGlobalRef(env, jthis);
55-
jobject gTransferable = JNFNewGlobalRef(env, jtransferable);
56-
jobject gTriggerEvent = JNFNewGlobalRef(env, jtrigger);
57-
jlongArray gFormats = JNFNewGlobalRef(env, jformats);
58-
jobject gFormatMap = JNFNewGlobalRef(env, jformatmap);
53+
jobject gComponent = (*env)->NewGlobalRef(env, jcomponent);
54+
jobject gDragSourceContextPeer = (*env)->NewGlobalRef(env, jthis);
55+
jobject gTransferable = (*env)->NewGlobalRef(env, jtransferable);
56+
jobject gTriggerEvent = (*env)->NewGlobalRef(env, jtrigger);
57+
jlongArray gFormats = (*env)->NewGlobalRef(env, jformats);
58+
jobject gFormatMap = (*env)->NewGlobalRef(env, jformatmap);
5959

6060
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
6161
dragSource = [[CDragSource alloc] init:gDragSourceContextPeer

0 commit comments

Comments
 (0)
This repository has been archived.