Skip to content

Commit

Permalink
8259869: [macOS] Remove desktop module dependencies on JNF Reference …
Browse files Browse the repository at this point in the history
…APIs

Reviewed-by: serb
  • Loading branch information
prrace committed Jan 22, 2021
1 parent a7c2ebc commit 92c2f08
Show file tree
Hide file tree
Showing 21 changed files with 146 additions and 134 deletions.
11 changes: 4 additions & 7 deletions src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ - (void) dealloc {
{
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];

JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
(*env)->DeleteGlobalRef(env, fInputMethodLOCKABLE);
fInputMethodLOCKABLE = NULL;
}

Expand Down Expand Up @@ -1359,14 +1359,10 @@ - (void)setInputMethod:(jobject)inputMethod

// Get rid of the old one
if (fInputMethodLOCKABLE) {
JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
(*env)->DeleteGlobalRef(env, fInputMethodLOCKABLE);
}

// Save a global ref to the new input method.
if (inputMethod != NULL)
fInputMethodLOCKABLE = JNFNewGlobalRef(env, inputMethod);
else
fInputMethodLOCKABLE = NULL;
fInputMethodLOCKABLE = inputMethod; // input method arg must be a GlobalRef

NSTextInputContext *curContxt = [NSTextInputContext currentInputContext];
kbdLayout = curContxt.selectedKeyboardInputSource;
Expand Down Expand Up @@ -1408,6 +1404,7 @@ - (void)abandonInput

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

[ThreadUtilities performOnMainThreadWaiting:YES block:^(){

Expand Down
7 changes: 3 additions & 4 deletions src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@
#import "LWCToolkit.h"

@class AWTView;
@class JNFWeakJObjectWrapper;

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

@property (nonatomic, retain) JNFWeakJObjectWrapper *javaPlatformWindow;
@property (nonatomic) jobject javaPlatformWindow;
@property (nonatomic, retain) CMenuBar *javaMenuBar;
@property (nonatomic, retain) AWTWindow *ownerWindow;
@property (nonatomic) NSSize javaMinSize;
Expand All @@ -65,7 +64,7 @@
@property (nonatomic) BOOL isMinimizing;
@property (nonatomic) BOOL keyNotificationRecd;

- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)javaPlatformWindow
- (id) initWithPlatformWindow:(jobject)javaPlatformWindow
ownerWindow:owner
styleBits:(jint)styleBits
frameRect:(NSRect)frameRect
Expand Down
46 changes: 23 additions & 23 deletions src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ - (void)postGesture:(NSEvent *)event as:(jint)type a:(jdouble)a b:(jdouble)b {
AWT_ASSERT_APPKIT_THREAD;

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

- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)platformWindow
- (id) initWithPlatformWindow:(jobject)platformWindow
ownerWindow:owner
styleBits:(jint)bits
frameRect:(NSRect)rect
Expand Down Expand Up @@ -482,7 +482,7 @@ - (void) dealloc {
AWT_ASSERT_APPKIT_THREAD;

JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
[self.javaPlatformWindow setJObject:nil withEnv:env];
(*env)->DeleteWeakGlobalRef(env, self.javaPlatformWindow);
self.javaPlatformWindow = nil;
self.nsWindow = nil;
self.ownerWindow = nil;
Expand All @@ -494,7 +494,7 @@ - (BOOL) isBlocked {
BOOL isBlocked = NO;

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

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

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

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

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

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_windowWillMiniaturize, jc_CPlatformWindow, "windowWillMiniaturize", "()V");
Expand Down Expand Up @@ -757,9 +757,9 @@ - (void)windowDidDeminiaturize:(NSNotification *)notification {
- (void) _deliverWindowFocusEvent:(BOOL)focused oppositeWindow:(AWTWindow *)opposite {
//AWT_ASSERT_APPKIT_THREAD;
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
jobject oppositeWindow = [opposite.javaPlatformWindow jObjectWithEnv:env];
jobject oppositeWindow = (*env)->NewLocalRef(env, opposite.javaPlatformWindow);
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(ZLsun/lwawt/macosx/CPlatformWindow;)V");
(*env)->CallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused, oppositeWindow);
Expand Down Expand Up @@ -788,7 +788,7 @@ - (void) windowDidBecomeMain: (NSNotification *) notification {
}

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_windowDidBecomeMain, jc_CPlatformWindow, "windowDidBecomeMain", "()V");
Expand Down Expand Up @@ -904,7 +904,7 @@ - (BOOL)windowShouldClose:(id)sender {
AWT_ASSERT_APPKIT_THREAD;
[AWTToolkit eventCountPlusPlus];
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS_RETURN(NO);
DECLARE_METHOD_RETURN(jm_deliverWindowClosingEvent, jc_CPlatformWindow, "deliverWindowClosingEvent", "()V", NO);
Expand All @@ -922,7 +922,7 @@ - (void)_notifyFullScreenOp:(jint)op withEnv:(JNIEnv *)env {
"handleFullScreenEventFromNative", "(Ljava/awt/Window;I)V");
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_FIELD(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;");
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
jobject awtWindow = (*env)->GetObjectField(env, platformWindow, jf_target);
if (awtWindow != NULL) {
Expand All @@ -939,7 +939,7 @@ - (void)windowWillEnterFullScreen:(NSNotification *)notification {
JNIEnv *env = [ThreadUtilities getJNIEnv];
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_windowWillEnterFullScreen, jc_CPlatformWindow, "windowWillEnterFullScreen", "()V");
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
(*env)->CallVoidMethod(env, platformWindow, jm_windowWillEnterFullScreen);
CHECK_EXCEPTION();
Expand All @@ -952,7 +952,7 @@ - (void)windowDidEnterFullScreen:(NSNotification *)notification {
JNIEnv *env = [ThreadUtilities getJNIEnv];
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_windowDidEnterFullScreen, jc_CPlatformWindow, "windowDidEnterFullScreen", "()V");
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
(*env)->CallVoidMethod(env, platformWindow, jm_windowDidEnterFullScreen);
CHECK_EXCEPTION();
Expand All @@ -971,7 +971,7 @@ - (void)windowWillExitFullScreen:(NSNotification *)notification {
jm_windowWillExitFullScreen = (*env)->GetMethodID(env, jc_CPlatformWindow, "windowWillExitFullScreen", "()V");
}
CHECK_NULL(jm_windowWillExitFullScreen);
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
(*env)->CallVoidMethod(env, platformWindow, jm_windowWillExitFullScreen);
CHECK_EXCEPTION();
Expand All @@ -982,7 +982,7 @@ - (void)windowWillExitFullScreen:(NSNotification *)notification {

- (void)windowDidExitFullScreen:(NSNotification *)notification {
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_windowDidExitFullScreen, jc_CPlatformWindow, "windowDidExitFullScreen", "()V");
Expand All @@ -1001,7 +1001,7 @@ - (void)sendEvent:(NSEvent *)event {
// in front of its nearest parent.
if (self.ownerWindow != nil) {
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_orderAboveSiblings, jc_CPlatformWindow, "orderAboveSiblings", "()V");
Expand All @@ -1020,7 +1020,7 @@ - (void)sendEvent:(NSEvent *)event {
// Check if the click happened in the non-client area (title bar)
if (p.y >= (frame.origin.y + contentRect.size.height)) {
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
// Currently, no need to deliver the whole NSEvent.
GET_CPLATFORM_WINDOW_CLASS();
Expand Down Expand Up @@ -1103,7 +1103,7 @@ + (AWTWindow *) lastKeyWindow {

JNI_COCOA_ENTER(env);

JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env];
jobject platformWindow = (*env)->NewWeakGlobalRef(env, obj);
NSView *contentView = OBJC(contentViewPtr);
NSRect frameRect = NSMakeRect(x, y, w, h);
AWTWindow *owner = [OBJC(ownerPtr) delegate];
Expand Down Expand Up @@ -1544,7 +1544,7 @@ + (AWTWindow *) lastKeyWindow {
[ThreadUtilities performOnMainThreadWaiting:YES block:^{
AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse];
if (awtWindow != nil) {
topmostWindowUnderMouse = [awtWindow.javaPlatformWindow jObject];
topmostWindowUnderMouse = awtWindow.javaPlatformWindow;
}
}];

Expand Down
6 changes: 3 additions & 3 deletions src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ - (void)declareTypes:(NSArray*)types withOwner:(jobject)owner jniEnv:(JNIEnv*)en
@synchronized(self) {
if (owner != NULL) {
if (self.clipboardOwner != NULL) {
JNFDeleteGlobalRef(env, self.clipboardOwner);
(*env)->DeleteGlobalRef(env, self.clipboardOwner);
}
self.clipboardOwner = JNFNewGlobalRef(env, owner);
self.clipboardOwner = (*env)->NewGlobalRef(env, owner);
}
}
[ThreadUtilities performOnMainThreadWaiting:YES block:^() {
Expand Down Expand Up @@ -101,7 +101,7 @@ - (void)checkPasteboard:(id)sender {
if (self.clipboardOwner) {
(*env)->CallVoidMethod(env, self.clipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event)
CHECK_EXCEPTION();
JNFDeleteGlobalRef(env, self.clipboardOwner);
(*env)->DeleteGlobalRef(env, self.clipboardOwner);
self.clipboardOwner = NULL;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -169,32 +169,32 @@ - (void)removeFromView:(JNIEnv *)env

// Clean up JNI refs
if (fComponent != NULL) {
JNFDeleteGlobalRef(env, fComponent);
(*env)->DeleteGlobalRef(env, fComponent);
fComponent = NULL;
}

if (fDragSourceContextPeer != NULL) {
JNFDeleteGlobalRef(env, fDragSourceContextPeer);
(*env)->DeleteGlobalRef(env, fDragSourceContextPeer);
fDragSourceContextPeer = NULL;
}

if (fTransferable != NULL) {
JNFDeleteGlobalRef(env, fTransferable);
(*env)->DeleteGlobalRef(env, fTransferable);
fTransferable = NULL;
}

if (fTriggerEvent != NULL) {
JNFDeleteGlobalRef(env, fTriggerEvent);
(*env)->DeleteGlobalRef(env, fTriggerEvent);
fTriggerEvent = NULL;
}

if (fFormats != NULL) {
JNFDeleteGlobalRef(env, fFormats);
(*env)->DeleteGlobalRef(env, fFormats);
fFormats = NULL;
}

if (fFormatMap != NULL) {
JNFDeleteGlobalRef(env, fFormatMap);
(*env)->DeleteGlobalRef(env, fFormatMap);
fFormatMap = NULL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
JNI_COCOA_ENTER(env);

// Global references are disposed when the DragSource is removed
jobject gComponent = JNFNewGlobalRef(env, jcomponent);
jobject gDragSourceContextPeer = JNFNewGlobalRef(env, jthis);
jobject gTransferable = JNFNewGlobalRef(env, jtransferable);
jobject gTriggerEvent = JNFNewGlobalRef(env, jtrigger);
jlongArray gFormats = JNFNewGlobalRef(env, jformats);
jobject gFormatMap = JNFNewGlobalRef(env, jformatmap);
jobject gComponent = (*env)->NewGlobalRef(env, jcomponent);
jobject gDragSourceContextPeer = (*env)->NewGlobalRef(env, jthis);
jobject gTransferable = (*env)->NewGlobalRef(env, jtransferable);
jobject gTriggerEvent = (*env)->NewGlobalRef(env, jtrigger);
jlongArray gFormats = (*env)->NewGlobalRef(env, jformats);
jobject gFormatMap = (*env)->NewGlobalRef(env, jformatmap);

[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
dragSource = [[CDragSource alloc] init:gDragSourceContextPeer
Expand Down
Loading

1 comment on commit 92c2f08

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.