From df2818b97b0b7cb721ad214dd530591c4e934602 Mon Sep 17 00:00:00 2001 From: Vladimir Kempik Date: Thu, 8 Apr 2021 12:21:23 +0000 Subject: [PATCH] 8259869: [macOS] Remove desktop module dependencies on JNF Reference APIs Backport-of: 92c2f084a2d1eb4475ebce6c9c08312e5c4aea5e --- .../macosx/native/libawt_lwawt/awt/AWTView.m | 11 ++--- .../native/libawt_lwawt/awt/AWTWindow.h | 7 ++- .../native/libawt_lwawt/awt/AWTWindow.m | 46 +++++++++---------- .../native/libawt_lwawt/awt/CClipboard.m | 6 +-- .../native/libawt_lwawt/awt/CDragSource.m | 12 ++--- .../libawt_lwawt/awt/CDragSourceContextPeer.m | 12 ++--- .../native/libawt_lwawt/awt/CDropTarget.m | 20 ++++---- .../libawt_lwawt/awt/CDropTargetContextPeer.m | 2 +- .../native/libawt_lwawt/awt/CFileDialog.m | 4 +- .../native/libawt_lwawt/awt/CGraphicsEnv.m | 19 ++++---- .../native/libawt_lwawt/awt/CInputMethod.m | 12 ++--- .../native/libawt_lwawt/awt/CMenuComponent.m | 2 +- .../native/libawt_lwawt/awt/CPopupMenu.m | 2 +- .../native/libawt_lwawt/awt/CTrayIcon.m | 4 +- .../libawt_lwawt/awt/ImageSurfaceData.m | 12 ++--- .../awt/JavaAccessibilityAction.m | 29 ++++++++---- .../awt/JavaComponentAccessibility.m | 8 ++-- .../native/libawt_lwawt/awt/PrinterView.m | 24 +++++----- .../libawt_lwawt/java2d/opengl/CGLLayer.h | 6 +-- .../libawt_lwawt/java2d/opengl/CGLLayer.m | 8 ++-- .../macosx/native/libosxui/ScreenMenu.m | 34 +++++++------- 21 files changed, 146 insertions(+), 134 deletions(-) diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m index 299f10bfd57..61c9ea46794 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m @@ -121,7 +121,7 @@ - (void) dealloc { { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; - JNFDeleteGlobalRef(env, fInputMethodLOCKABLE); + (*env)->DeleteGlobalRef(env, fInputMethodLOCKABLE); fInputMethodLOCKABLE = NULL; } @@ -1363,14 +1363,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; @@ -1412,6 +1408,7 @@ - (void)abandonInput NSRect rect = NSMakeRect(originX, originY, width, height); jobject cPlatformView = (*env)->NewWeakGlobalRef(env, obj); + CHECK_EXCEPTION(); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.h b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.h index 18251d8da41..7d6fb4f3ebc 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.h @@ -32,11 +32,10 @@ #import "LWCToolkit.h" @class AWTView; -@class JNFWeakJObjectWrapper; @interface AWTWindow : NSObject { @private - JNFWeakJObjectWrapper *javaPlatformWindow; + jobject javaPlatformWindow; /* This is a weak ref. Always copy to a local ref before using */ CMenuBar *javaMenuBar; NSSize javaMinSize; NSSize javaMaxSize; @@ -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; @@ -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 diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m index 0bdff7bc86b..bc682ed7ef6 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m @@ -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(); @@ -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 @@ -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; @@ -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); @@ -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); @@ -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) @@ -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); @@ -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 } @@ -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"); @@ -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"); @@ -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); @@ -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"); @@ -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); @@ -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) { @@ -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(); @@ -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(); @@ -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(); @@ -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"); @@ -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"); @@ -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(); @@ -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]; @@ -1544,7 +1544,7 @@ + (AWTWindow *) lastKeyWindow { [ThreadUtilities performOnMainThreadWaiting:YES block:^{ AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse]; if (awtWindow != nil) { - topmostWindowUnderMouse = [awtWindow.javaPlatformWindow jObject]; + topmostWindowUnderMouse = awtWindow.javaPlatformWindow; } }]; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m index 8e7cba9b11e..3a6d573579c 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m @@ -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:^() { @@ -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; } } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m index d9df2e2bd1b..fc9d855e086 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m @@ -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; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m index b57b64f280b..4b86ec6818d 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m @@ -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 diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m index f2fbcf1a5b0..a5540406411 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m @@ -84,8 +84,8 @@ - (id)init:(jobject)jdropTarget component:(jobject)jcomponent control:(id)contro if (control != nil) { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; - fComponent = JNFNewGlobalRef(env, jcomponent); - fDropTarget = JNFNewGlobalRef(env, jdropTarget); + fComponent = (*env)->NewGlobalRef(env, jcomponent); + fDropTarget = (*env)->NewGlobalRef(env, jdropTarget); fView = [((AWTView *) control) retain]; [fView setDropTarget:self]; @@ -148,7 +148,7 @@ - (void)releaseDraggingData if (sDraggingFormats != NULL) { JNIEnv *env = [ThreadUtilities getJNIEnv]; - JNFDeleteGlobalRef(env, sDraggingFormats); + (*env)->DeleteGlobalRef(env, sDraggingFormats); sDraggingFormats = NULL; } @@ -165,15 +165,15 @@ - (void)removeFromView:(JNIEnv *)env // Clean up JNI refs if (fComponent != NULL) { - JNFDeleteGlobalRef(env, fComponent); + (*env)->DeleteGlobalRef(env, fComponent); fComponent = NULL; } if (fDropTarget != NULL) { - JNFDeleteGlobalRef(env, fDropTarget); + (*env)->DeleteGlobalRef(env, fDropTarget); fDropTarget = NULL; } if (fDropTargetContextPeer != NULL) { - JNFDeleteGlobalRef(env, fDropTargetContextPeer); + (*env)->DeleteGlobalRef(env, fDropTargetContextPeer); fDropTargetContextPeer = NULL; } @@ -239,7 +239,7 @@ - (BOOL)copyDraggingTypes:(id)sender if (formats == nil) return FALSE; - sDraggingFormats = (jlongArray) JNFNewGlobalRef(env, formats); + sDraggingFormats = (jlongArray) (*env)->NewGlobalRef(env, formats); (*env)->DeleteLocalRef(env, formats); if (sDraggingFormats == nil) return FALSE; @@ -356,7 +356,7 @@ - (jobject) copyDraggingDataForFormat:(jlong)format jbyteArray lbyteArray = (*env)->NewByteArray(env, dataLength); if (lbyteArray == nil) return nil; - jbyteArray gbyteArray = (jbyteArray) JNFNewGlobalRef(env, lbyteArray); + jbyteArray gbyteArray = (jbyteArray) (*env)->NewGlobalRef(env, lbyteArray); (*env)->DeleteLocalRef(env, lbyteArray); if (gbyteArray == nil) return nil; @@ -459,7 +459,7 @@ - (NSDragOperation)draggingEntered:(id)sender // Delete any drop target context peer left over from a previous drag: if (fDropTargetContextPeer != NULL) { - JNFDeleteGlobalRef(env, fDropTargetContextPeer); + (*env)->DeleteGlobalRef(env, fDropTargetContextPeer); fDropTargetContextPeer = NULL; } @@ -473,7 +473,7 @@ - (NSDragOperation)draggingEntered:(id)sender CHECK_EXCEPTION(); if (dropTargetContextPeer != nil) { - fDropTargetContextPeer = JNFNewGlobalRef(env, dropTargetContextPeer); + fDropTargetContextPeer = (*env)->NewGlobalRef(env, dropTargetContextPeer); (*env)->DeleteLocalRef(env, dropTargetContextPeer); } } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m index b1ac2a9e866..8020706ae3b 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m @@ -106,7 +106,7 @@ static void TransferFailed(JNIEnv *env, jobject jthis, jlong jdroptarget, jlong (*env)->CallVoidMethod(env, jthis, newDataMethod, jformat, jdropdata); // AWT_THREADING Safe (!appKit) } @catch (NSException *ex) { DLog2(@"[CDropTargetContextPeer startTransfer]: exception in newData() for %d.\n", (NSInteger) jdroptarget); - JNFDeleteGlobalRef(env, jdropdata); + (*env)->DeleteGlobalRef(env, jdropdata); TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat); return result; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m index 33141c1095c..4b09d07114b 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m @@ -49,7 +49,7 @@ - (id)initWithFilter:(jboolean)inHasFilter { if (self = [super init]) { fHasFileFilter = inHasFilter; - fFileDialog = JNFNewGlobalRef(env, inDialog); + fFileDialog = (*env)->NewGlobalRef(env, inDialog); fDirectory = inPath; [fDirectory retain]; fFile = inFile; @@ -69,7 +69,7 @@ - (id)initWithFilter:(jboolean)inHasFilter -(void) disposer { if (fFileDialog != NULL) { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; - JNFDeleteGlobalRef(env, fFileDialog); + (*env)->DeleteGlobalRef(env, fFileDialog); fFileDialog = NULL; } } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m index 7c36bb6e407..76dc31fa101 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m @@ -115,9 +115,9 @@ [ThreadUtilities performOnMainThreadWaiting:NO block:^() { JNFPerformEnvBlock(JNFThreadDetachImmediately, ^(JNIEnv *env) { - JNFWeakJObjectWrapper *wrapper = (JNFWeakJObjectWrapper *)userInfo; + jobject cgeRef = (jobject)userInfo; - jobject graphicsEnv = [wrapper jObjectWithEnv:env]; + jobject graphicsEnv = (*env)->NewLocalRef(env, cgeRef); if (graphicsEnv == NULL) return; // ref already GC'd DECLARE_CLASS(jc_CGraphicsEnvironment, "sun/awt/CGraphicsEnvironment"); DECLARE_METHOD(jm_displayReconfiguration, @@ -143,15 +143,15 @@ JNI_COCOA_ENTER(env); - JNFWeakJObjectWrapper *wrapper = [[JNFWeakJObjectWrapper wrapperWithJObject:this withEnv:env] retain]; + jobject cgeRef = (*env)->NewWeakGlobalRef(env, this); /* Register the callback */ - if (CGDisplayRegisterReconfigurationCallback(&displaycb_handle, wrapper) != kCGErrorSuccess) { + if (CGDisplayRegisterReconfigurationCallback(&displaycb_handle, cgeRef) != kCGErrorSuccess) { JNU_ThrowInternalError(env, "CGDisplayRegisterReconfigurationCallback() failed"); return 0L; } - ret = ptr_to_jlong(wrapper); + ret = ptr_to_jlong(cgeRef); JNI_COCOA_EXIT(env); @@ -169,17 +169,16 @@ { JNI_COCOA_ENTER(env); - JNFWeakJObjectWrapper *wrapper = (JNFWeakJObjectWrapper *)jlong_to_ptr(p); - if (!wrapper) return; + jobject cgeRef = (jobject)jlong_to_ptr(p); + if (!cgeRef) return; /* Remove the registration */ - if (CGDisplayRemoveReconfigurationCallback(&displaycb_handle, wrapper) != kCGErrorSuccess) { + if (CGDisplayRemoveReconfigurationCallback(&displaycb_handle, cgeRef) != kCGErrorSuccess) { JNU_ThrowInternalError(env, "CGDisplayRemoveReconfigurationCallback() failed, leaking the callback context!"); return; } - [wrapper setJObject:NULL withEnv:env]; // more efficient to pre-clear - [wrapper release]; + (*env)->DeleteWeakGlobalRef(env, cgeRef); JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m index 08c12870166..3c5b18c5269 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m @@ -112,13 +112,13 @@ + (void) setKeyboardLayout:(NSString *)theLocale [inputMethodController performSelector:@selector(setCurrentInputMethodForLocale) withObject:theLocale]; } -+ (void) _nativeNotifyPeerWithView:(AWTView *)view inputMethod:(JNFJObjectWrapper *) inputMethod { ++ (void) _nativeNotifyPeerWithView:(AWTView *)view inputMethod:(jobject) inputMethod { AWT_ASSERT_APPKIT_THREAD; if (!view) return; if (!inputMethod) return; - [view setInputMethod:[inputMethod jObject]]; + [view setInputMethod:inputMethod]; // inputMethod is a GlobalRef } + (void) _nativeEndComposition:(AWTView *)view { @@ -177,9 +177,9 @@ + (void) _nativeEndComposition:(AWTView *)view { { JNI_COCOA_ENTER(env); AWTView *view = (AWTView *)jlong_to_ptr(nativePeer); - JNFJObjectWrapper *inputMethodWrapper = [[JNFJObjectWrapper alloc] initWithJObject:inputMethod withEnv:env]; + jobject inputMethodRef = (*env)->NewGlobalRef(env, inputMethod); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ - [CInputMethod _nativeNotifyPeerWithView:view inputMethod:inputMethodWrapper]; + [CInputMethod _nativeNotifyPeerWithView:view inputMethod:inputMethodRef]; }]; JNI_COCOA_EXIT(env); @@ -234,11 +234,11 @@ + (void) _nativeEndComposition:(AWTView *)view { [isoAbbreviation release]; if (sLastKeyboardLocaleObj) { - JNFDeleteGlobalRef(env, sLastKeyboardLocaleObj); + (*env)->DeleteGlobalRef(env, sLastKeyboardLocaleObj); sLastKeyboardLocaleObj = NULL; } if (localObj != NULL) { - sLastKeyboardLocaleObj = JNFNewGlobalRef(env, localObj); + sLastKeyboardLocaleObj = (*env)->NewGlobalRef(env, localObj); (*env)->DeleteLocalRef(env, localObj); } } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuComponent.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuComponent.m index cf093cd650c..d49edec879e 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuComponent.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuComponent.m @@ -43,7 +43,7 @@ -(id) initWithPeer:(jobject)peer { - (void)dealloc { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; - JNFDeleteGlobalRef(env, fPeer); + (*env)->DeleteGlobalRef(env, fPeer); fPeer = NULL; [super dealloc]; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPopupMenu.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPopupMenu.m index bd4b6af381d..b77756dfaa4 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPopupMenu.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPopupMenu.m @@ -62,7 +62,7 @@ - (NSString *)description { JNI_COCOA_ENTER(env); - jobject cPeerObjGlobal = JNFNewGlobalRef(env, peer); + jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ aCPopupMenu = [[CPopupMenu alloc] initWithPeer:cPeerObjGlobal]; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m index e613981c187..95ff4c3ec45 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m @@ -75,7 +75,7 @@ - (id) initWithPeer:(jobject)thePeer { -(void) dealloc { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; - JNFDeleteGlobalRef(env, peer); + (*env)->DeleteGlobalRef(env, peer); [[NSStatusBar systemStatusBar] removeStatusItem: theItem]; @@ -335,7 +335,7 @@ - (void) otherMouseDragged:(NSEvent *)event { JNI_COCOA_ENTER(env); - jobject thePeer = JNFNewGlobalRef(env, peer); + jobject thePeer = (*env)->NewGlobalRef(env, peer); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ trayIcon = [[AWTTrayIcon alloc] initWithPeer:thePeer]; }]; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m index 488a2a4f9f2..bac3fbfa78e 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m @@ -1452,7 +1452,7 @@ static void ImageSD_dispose(JNIEnv *env, SurfaceDataOps *ops) qsdo->graphicsStateInfo.batchedLines = NULL; } - JNFDeleteGlobalRef(env, qsdo->javaGraphicsStatesObjects); + (*env)->DeleteGlobalRef(env, qsdo->javaGraphicsStatesObjects); if (qsdo->cgRef != NULL) { @@ -1484,12 +1484,12 @@ static void ImageSD_dispose(JNIEnv *env, SurfaceDataOps *ops) } if (isdo->array != NULL) { - JNFDeleteGlobalRef(env, isdo->array); + (*env)->DeleteGlobalRef(env, isdo->array); isdo->array = NULL; } if (isdo->icm != NULL) { - JNFDeleteGlobalRef(env, isdo->icm); + (*env)->DeleteGlobalRef(env, isdo->icm); isdo->icm = NULL; } @@ -1848,13 +1848,13 @@ JNIEXPORT void JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_initRaster(JNIEnv // parameters specifying this image given to us from Java isdo->javaImageInfo = (jint*)((*env)->GetDirectBufferAddress(env, jImageInfo)); - isdo->array = (array != NULL) ? JNFNewGlobalRef(env, array) : NULL; + isdo->array = (array != NULL) ? (*env)->NewGlobalRef(env, array) : NULL; isdo->offset = offset; isdo->width = width; isdo->height = height; isdo->javaPixelBytes = pixelStride; isdo->javaPixelsBytesPerRow = scanStride; - isdo->icm = (icm != NULL) ? JNFNewGlobalRef(env, icm) : NULL; + isdo->icm = (icm != NULL) ? (*env)->NewGlobalRef(env, icm) : NULL; isdo->type = type; if ((isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kImageStolenIndex] == 1) || @@ -1962,7 +1962,7 @@ JNIEXPORT void JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_initRaster(JNIEnv qsdo->FinishSurface = ImageSD_finishCGContext; qsdo->javaGraphicsStates = (jint*)((*env)->GetDirectBufferAddress(env, jGraphicsState)); - qsdo->javaGraphicsStatesObjects = JNFNewGlobalRef(env, jGraphicsStateObject); + qsdo->javaGraphicsStatesObjects = (*env)->NewGlobalRef(env, jGraphicsStateObject); qsdo->graphicsStateInfo.batchedLines = NULL; qsdo->graphicsStateInfo.batchedLinesCount = 0; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m index fd2ab6339b7..feb49b0ed71 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m @@ -36,9 +36,11 @@ - (id)initWithEnv:(JNIEnv *)env withAccessibleAction:(jobject)accessibleAction w { self = [super init]; if (self) { - fAccessibleAction = JNFNewWeakGlobalRef(env, accessibleAction); + fAccessibleAction = (*env)->NewWeakGlobalRef(env, accessibleAction); + CHECK_EXCEPTION(); fIndex = index; - fComponent = JNFNewWeakGlobalRef(env, component); + fComponent = (*env)->NewWeakGlobalRef(env, component); + CHECK_EXCEPTION(); } return self; } @@ -47,10 +49,10 @@ - (void)dealloc { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; - JNFDeleteWeakGlobalRef(env, fAccessibleAction); + (*env)->DeleteWeakGlobalRef(env, fAccessibleAction); fAccessibleAction = NULL; - JNFDeleteWeakGlobalRef(env, fComponent); + (*env)->DeleteWeakGlobalRef(env, fComponent); fComponent = NULL; [super dealloc]; @@ -63,14 +65,20 @@ - (NSString *)getDescription DECLARE_METHOD_RETURN(jm_getAccessibleActionDescription, sjc_CAccessibility, "getAccessibleActionDescription", "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)Ljava/lang/String;", nil); + /* WeakGlobalRefs can be cleared at any time, so first get strong local refs and use those */ jobject fCompLocal = (*env)->NewLocalRef(env, fComponent); if ((*env)->IsSameObject(env, fCompLocal, NULL)) { return nil; } + jobject fAccessibleActionLocal = (*env)->NewLocalRef(env, fAccessibleAction); + if ((*env)->IsSameObject(env, fAccessibleActionLocal, NULL)) { + (*env)->DeleteLocalRef(env, fCompLocal); + return nil; + } NSString *str = nil; jstring jstr = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibleActionDescription, - fAccessibleAction, + fAccessibleActionLocal, fIndex, fCompLocal ); CHECK_EXCEPTION(); @@ -79,6 +87,7 @@ - (NSString *)getDescription (*env)->DeleteLocalRef(env, jstr); } (*env)->DeleteLocalRef(env, fCompLocal); + (*env)->DeleteLocalRef(env, fAccessibleActionLocal); return str; } @@ -103,9 +112,11 @@ - (id)initWithEnv:(JNIEnv *)env withTabGroup:(jobject)tabGroup withIndex:(jint)i { self = [super init]; if (self) { - fTabGroup = JNFNewWeakGlobalRef(env, tabGroup); + fTabGroup = (*env)->NewWeakGlobalRef(env, tabGroup); + CHECK_EXCEPTION(); fIndex = index; - fComponent = JNFNewWeakGlobalRef(env, component); + fComponent = (*env)->NewWeakGlobalRef(env, component); + CHECK_EXCEPTION(); } return self; } @@ -114,10 +125,10 @@ - (void)dealloc { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; - JNFDeleteWeakGlobalRef(env, fTabGroup); + (*env)->DeleteWeakGlobalRef(env, fTabGroup); fTabGroup = NULL; - JNFDeleteWeakGlobalRef(env, fComponent); + (*env)->DeleteWeakGlobalRef(env, fComponent); fComponent = NULL; [super dealloc]; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m index 3b252d846b9..084656dc184 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m @@ -1833,7 +1833,8 @@ - (id)initWithParent:(NSObject *)parent withEnv:(JNIEnv *)env withAccessible:(jo self = [super initWithParent:parent withEnv:env withAccessible:accessible withIndex:index withView:view withJavaRole:javaRole]; if (self) { if (tabGroup != NULL) { - fTabGroupAxContext = JNFNewWeakGlobalRef(env, tabGroup); + fTabGroupAxContext = (*env)->NewWeakGlobalRef(env, tabGroup); + CHECK_EXCEPTION(); } else { fTabGroupAxContext = NULL; } @@ -1846,7 +1847,7 @@ - (void)dealloc JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; if (fTabGroupAxContext != NULL) { - JNFDeleteWeakGlobalRef(env, fTabGroupAxContext); + (*env)->DeleteWeakGlobalRef(env, fTabGroupAxContext); fTabGroupAxContext = NULL; } @@ -1879,7 +1880,8 @@ - (jobject)tabGroup if (fTabGroupAxContext == NULL) { JNIEnv* env = [ThreadUtilities getJNIEnv]; jobject tabGroupAxContext = [(JavaComponentAccessibility *)[self parent] axContextWithEnv:env]; - fTabGroupAxContext = JNFNewWeakGlobalRef(env, tabGroupAxContext); + fTabGroupAxContext = (*env)->NewWeakGlobalRef(env, tabGroupAxContext); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, tabGroupAxContext); } return fTabGroupAxContext; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m index 5b059897cda..a64fba4eac3 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m @@ -45,7 +45,7 @@ - (id)initWithFrame:(NSRect)aRect withEnv:(JNIEnv*)env withPrinterJob:(jobject)p self = [super initWithFrame:aRect]; if (self) { - fPrinterJob = JNFNewGlobalRef(env, printerJob); + fPrinterJob = (*env)->NewGlobalRef(env, printerJob); fCurPageFormat = NULL; fCurPainter = NULL; fCurPeekGraphics = NULL; @@ -57,17 +57,17 @@ - (void)releaseReferences:(JNIEnv*)env { if (fCurPageFormat != NULL) { - JNFDeleteGlobalRef(env, fCurPageFormat); + (*env)->DeleteGlobalRef(env, fCurPageFormat); fCurPageFormat = NULL; } if (fCurPainter != NULL) { - JNFDeleteGlobalRef(env, fCurPainter); + (*env)->DeleteGlobalRef(env, fCurPainter); fCurPainter = NULL; } if (fCurPeekGraphics != NULL) { - JNFDeleteGlobalRef(env, fCurPeekGraphics); + (*env)->DeleteGlobalRef(env, fCurPeekGraphics); fCurPeekGraphics = NULL; } } @@ -166,7 +166,7 @@ - (NSRect)rectForPage:(NSInteger)pageNumber DECLARE_CLASS_RETURN(sjc_PageFormat, "java/awt/print/PageFormat", NSZeroRect); DECLARE_METHOD_RETURN(jm_getOrientation, sjc_PageFormat, "getOrientation", "()I", NSZeroRect); - // Assertions removed, and corresponding JNFDeleteGlobalRefs added, for radr://3962543 + // Assertions removed, and corresponding DeleteGlobalRefs added, for radr://3962543 // Actual fix that will keep these assertions from being true is radr://3205462 , // which will hopefully be fixed by the blocking AppKit bug radr://3056694 //assert(fCurPageFormat == NULL); @@ -174,13 +174,13 @@ - (NSRect)rectForPage:(NSInteger)pageNumber //assert(fCurPeekGraphics == NULL); if(fCurPageFormat != NULL) { - JNFDeleteGlobalRef(env, fCurPageFormat); + (*env)->DeleteGlobalRef(env, fCurPageFormat); } if(fCurPainter != NULL) { - JNFDeleteGlobalRef(env, fCurPainter); + (*env)->DeleteGlobalRef(env, fCurPainter); } if(fCurPeekGraphics != NULL) { - JNFDeleteGlobalRef(env, fCurPeekGraphics); + (*env)->DeleteGlobalRef(env, fCurPeekGraphics); } //+++gdb Check the pageNumber for validity (PageAttrs) @@ -201,15 +201,15 @@ - (NSRect)rectForPage:(NSInteger)pageNumber // Get references to the return objects -> PageFormat, Printable, PeekGraphics // Cheat - we know we either got NULL or a 3 element array jobject pageFormat = (*env)->GetObjectArrayElement(env, objectArray, 0); - fCurPageFormat = JNFNewGlobalRef(env, pageFormat); + fCurPageFormat = (*env)->NewGlobalRef(env, pageFormat); (*env)->DeleteLocalRef(env, pageFormat); jobject painter = (*env)->GetObjectArrayElement(env, objectArray, 1); - fCurPainter = JNFNewGlobalRef(env, painter); + fCurPainter = (*env)->NewGlobalRef(env, painter); (*env)->DeleteLocalRef(env, painter); jobject peekGraphics = (*env)->GetObjectArrayElement(env, objectArray, 2); - fCurPeekGraphics = JNFNewGlobalRef(env, peekGraphics); + fCurPeekGraphics = (*env)->NewGlobalRef(env, peekGraphics); (*env)->DeleteLocalRef(env, peekGraphics); // Actually print and get the PageFormatArea @@ -280,7 +280,7 @@ - (void)complete:(JNIEnv*)env [self releaseReferences:env]; if (fPrinterJob != NULL) { - JNFDeleteGlobalRef(env, fPrinterJob); + (*env)->DeleteGlobalRef(env, fPrinterJob); fPrinterJob = NULL; } } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.h b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.h index dd1acdd30c8..b5428a7ff1f 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.h @@ -31,7 +31,7 @@ @interface CGLLayer : CAOpenGLLayer { @private - JNFWeakJObjectWrapper *javaLayer; + jobject javaLayer; // intermediate buffer, used the RQ lock to synchronize GLuint textureID; @@ -40,13 +40,13 @@ float textureHeight; } -@property (nonatomic, retain) JNFWeakJObjectWrapper *javaLayer; +@property (nonatomic) jobject javaLayer; @property (readwrite, assign) GLuint textureID; @property (readwrite, assign) GLenum target; @property (readwrite, assign) float textureWidth; @property (readwrite, assign) float textureHeight; -- (id) initWithJavaLayer:(JNFWeakJObjectWrapper *)javaLayer; +- (id) initWithJavaLayer:(jobject)javaLayer; - (void) blitTexture; @end diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.m index ec2b4e254f0..de083075250 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.m @@ -42,7 +42,7 @@ @implementation CGLLayer @synthesize textureWidth; @synthesize textureHeight; -- (id) initWithJavaLayer:(JNFWeakJObjectWrapper *)layer; +- (id) initWithJavaLayer:(jobject)layer; { AWT_ASSERT_APPKIT_THREAD; // Initialize ourselves @@ -79,6 +79,8 @@ - (id) initWithJavaLayer:(JNFWeakJObjectWrapper *)layer; } - (void) dealloc { + JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; + (*env)->DeleteWeakGlobalRef(env, self.javaLayer); self.javaLayer = nil; [super dealloc]; } @@ -133,7 +135,7 @@ -(void)drawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj) DECLARE_CLASS(jc_JavaLayer, "sun/java2d/opengl/CGLLayer"); DECLARE_METHOD(jm_drawInCGLContext, jc_JavaLayer, "drawInCGLContext", "()V"); - jobject javaLayerLocalRef = [self.javaLayer jObjectWithEnv:env]; + jobject javaLayerLocalRef = (*env)->NewLocalRef(env, self.javaLayer); if ((*env)->IsSameObject(env, javaLayerLocalRef, NULL)) { return; } @@ -172,7 +174,7 @@ -(void)drawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj) JNI_COCOA_ENTER(env); - JNFWeakJObjectWrapper *javaLayer = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env]; + jobject javaLayer = (*env)->NewWeakGlobalRef(env, obj); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ AWT_ASSERT_APPKIT_THREAD; diff --git a/src/java.desktop/macosx/native/libosxui/ScreenMenu.m b/src/java.desktop/macosx/native/libosxui/ScreenMenu.m index 169059b2f65..1a19f03fce5 100644 --- a/src/java.desktop/macosx/native/libosxui/ScreenMenu.m +++ b/src/java.desktop/macosx/native/libosxui/ScreenMenu.m @@ -65,13 +65,13 @@ @interface NativeToJavaDelegate : NSObject { @public NSMenu *nsmenu; - JNFJObjectWrapper *javaObjectWrapper; + jobject javaObject; } @property (nonatomic, retain) NSMenu *nsmenu; -@property (nonatomic, retain) JNFJObjectWrapper *javaObjectWrapper; +@property (nonatomic) jobject javaObject; -- (id)initFromMenu:(NSMenu *)menu javaObj:(JNFJObjectWrapper *)obj; +- (id)initFromMenu:(NSMenu *)menu javaObj:(jobject)obj; - (NSMenu*)menu; @end @@ -79,14 +79,14 @@ - (NSMenu*)menu; @implementation NativeToJavaDelegate @synthesize nsmenu; -@synthesize javaObjectWrapper; +@synthesize javaObject; -- (id)initFromMenu:(NSMenu *)aMenu javaObj:(JNFJObjectWrapper *)obj +- (id)initFromMenu:(NSMenu *)aMenu javaObj:(jobject)obj { self = [super init]; if (self) { self.nsmenu = aMenu; - self.javaObjectWrapper = obj; + self.javaObject = obj; } return self; } @@ -97,7 +97,7 @@ - (NSMenu *)menu { - (void)menuWillOpen:(NSMenu *)menu { - if (self.javaObjectWrapper == nil) { + if (self.javaObject == nil) { #ifdef DEBUG NSLog(@"_javaObject is NULL: (%s - %s : %d)", __FILE__, __FUNCTION__, __LINE__); #endif @@ -109,7 +109,7 @@ - (void)menuWillOpen:(NSMenu *)menu //NSLog(@"menuWillOpen %@", [menu title]); GET_SCREENMENU_CLASS(); DECLARE_METHOD(jm_ScreenMenu_invokeOpenLater, sjc_ScreenMenu, "invokeOpenLater", "()V"); - (*env)->CallVoidMethod(env, [self.javaObjectWrapper jObject], jm_ScreenMenu_invokeOpenLater); // AWT_THREADING Safe (AWTRunLoopMode) + (*env)->CallVoidMethod(env, self.javaObject, jm_ScreenMenu_invokeOpenLater); // AWT_THREADING Safe (AWTRunLoopMode) CHECK_EXCEPTION(); JNI_COCOA_EXIT(env); @@ -117,7 +117,7 @@ - (void)menuWillOpen:(NSMenu *)menu - (void)menuDidClose:(NSMenu *)menu { - if (self.javaObjectWrapper == nil) { + if (self.javaObject == nil) { #ifdef DEBUG NSLog(@"_javaObject is NULL: (%s - %s : %d)", __FILE__, __FUNCTION__, __LINE__); #endif @@ -129,7 +129,7 @@ - (void)menuDidClose:(NSMenu *)menu //NSLog(@"menuDidClose %@", [menu title]); GET_SCREENMENU_CLASS(); DECLARE_METHOD(jm_ScreenMenu_invokeMenuClosing, sjc_ScreenMenu, "invokeMenuClosing", "()V"); - (*env)->CallVoidMethod(env, [self.javaObjectWrapper jObject], jm_ScreenMenu_invokeMenuClosing); // AWT_THREADING Safe (AWTRunLoopMode) + (*env)->CallVoidMethod(env, self.javaObject, jm_ScreenMenu_invokeMenuClosing); // AWT_THREADING Safe (AWTRunLoopMode) CHECK_EXCEPTION(); JNI_COCOA_EXIT(env); } @@ -137,7 +137,7 @@ - (void)menuDidClose:(NSMenu *)menu - (void)handleJavaMenuItemTargetedAtIndex:(NSUInteger)menuIndex rect:(NSRect)rect { - if (self.javaObjectWrapper == nil) { + if (self.javaObject== nil) { #ifdef DEBUG NSLog(@"_javaObject is NULL: (%s - %s : %d)", __FILE__, __FUNCTION__, __LINE__); #endif @@ -149,7 +149,7 @@ - (void)handleJavaMenuItemTargetedAtIndex:(NSUInteger)menuIndex rect:(NSRect)rec // Send that to Java so we can test which item was hit. GET_SCREENMENU_CLASS(); DECLARE_METHOD(jm_ScreenMenu_updateSelectedItem, sjc_ScreenMenu, "handleItemTargeted", "(IIIII)V"); - (*env)->CallVoidMethod(env, [self.javaObjectWrapper jObject], jm_ScreenMenu_updateSelectedItem, menuIndex, + (*env)->CallVoidMethod(env, self.javaObject, jm_ScreenMenu_updateSelectedItem, menuIndex, NSMinY(rect), NSMinX(rect), NSMaxY(rect), NSMaxX(rect)); // AWT_THREADING Safe (AWTRunLoopMode) CHECK_EXCEPTION(); @@ -194,7 +194,7 @@ - (void)handleJavaMouseEvent:(NSEvent *)event JNI_COCOA_ENTER(env); GET_SCREENMENU_CLASS(); DECLARE_METHOD(jm_ScreenMenu_handleMouseEvent, sjc_ScreenMenu, "handleMouseEvent", "(IIIIJ)V"); - (*env)->CallVoidMethod(env, [self.javaObjectWrapper jObject], jm_ScreenMenu_handleMouseEvent, + (*env)->CallVoidMethod(env, self.javaObject, jm_ScreenMenu_handleMouseEvent, javaKind, javaX, javaY, javaModifiers, javaWhen); // AWT_THREADING Safe (AWTRunLoopMode) CHECK_EXCEPTION(); JNI_COCOA_EXIT(env); @@ -215,10 +215,10 @@ - (void)handleJavaMouseEvent:(NSEvent *)event JNI_COCOA_ENTER(env); - JNFJObjectWrapper *wrapper = [JNFJObjectWrapper wrapperWithJObject:listener withEnv:env]; + jobject listenerRef = (*env)->NewGlobalRef(env, listener); NSMenu *menu = jlong_to_ptr(nativeMenu); - delegate = [[[NativeToJavaDelegate alloc] initFromMenu:menu javaObj:wrapper] autorelease]; + delegate = [[[NativeToJavaDelegate alloc] initFromMenu:menu javaObj:listenerRef] autorelease]; CFRetain(delegate); // GC [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^{ @@ -253,9 +253,11 @@ - (void)handleJavaMouseEvent:(NSEvent *)event [menu setJavaMenuDelegate:nil]; [menu setDelegate:nil]; delegate.nsmenu = nil; - delegate.javaObjectWrapper = nil; }]; + (*env)->DeleteGlobalRef(env, delegate.javaObject); + delegate.javaObject = nil; + CFRelease(delegate); // GC JNI_COCOA_EXIT(env);