Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
/ jdk13u-dev Public archive

Commit ad45c98

Browse files
author
Vladimir Kempik
committedApr 8, 2021
8257853: Remove dependencies on JNF's JNI utility functions in AWT and 2D code
Reviewed-by: yan Backport-of: fa50877
1 parent 98baf88 commit ad45c98

35 files changed

+1401
-736
lines changed
 

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

+94-59
Large diffs are not rendered by default.

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

+96-49
Large diffs are not rendered by default.

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

+43-17
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#import "CMenuBar.h"
3939
#import "ThreadUtilities.h"
4040
#import "NSApplicationAWT.h"
41+
#import "JNIUtilities.h"
4142

4243
#pragma mark App Menu helpers
4344

@@ -243,9 +244,11 @@ - (id) init {
243244
BOOL prefsEnabled = (prefsAvailable && [self.fPreferencesMenu isEnabled] && ([self.fPreferencesMenu target] != nil));
244245

245246
JNIEnv *env = [ThreadUtilities getJNIEnv];
246-
static JNF_CLASS_CACHE(sjc_AppMenuBarHandler, "com/apple/eawt/_AppMenuBarHandler");
247-
static JNF_STATIC_MEMBER_CACHE(sjm_initMenuStates, sjc_AppMenuBarHandler, "initMenuStates", "(ZZZZ)V");
248-
JNFCallStaticVoidMethod(env, sjm_initMenuStates, aboutAvailable, aboutEnabled, prefsAvailable, prefsEnabled);
247+
DECLARE_CLASS_RETURN(sjc_AppMenuBarHandler, "com/apple/eawt/_AppMenuBarHandler", NULL);
248+
DECLARE_STATIC_METHOD_RETURN(sjm_initMenuStates, sjc_AppMenuBarHandler, "initMenuStates", "(ZZZZ)V", NULL);
249+
(*env)->CallStaticVoidMethod(env, sjc_AppMenuBarHandler, sjm_initMenuStates,
250+
aboutAvailable, aboutEnabled, prefsAvailable, prefsEnabled);
251+
CHECK_EXCEPTION();
249252

250253
// register for the finish launching and system power off notifications by default
251254
NSNotificationCenter *ctr = [NSNotificationCenter defaultCenter];
@@ -272,7 +275,12 @@ - (void)dealloc {
272275

273276
#pragma mark Callbacks from AppKit
274277

275-
static JNF_CLASS_CACHE(sjc_AppEventHandler, "com/apple/eawt/_AppEventHandler");
278+
static jclass sjc_AppEventHandler = NULL;
279+
#define GET_APPEVENTHANDLER_CLASS() \
280+
GET_CLASS(sjc_AppEventHandler, "com/apple/eawt/_AppEventHandler");
281+
282+
#define GET_APPEVENTHANDLER_CLASS_RETURN(ret) \
283+
GET_CLASS_RETURN(sjc_AppEventHandler, "com/apple/eawt/_AppEventHandler", ret);
276284

277285
- (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
278286
AWT_ASSERT_APPKIT_THREAD;
@@ -283,8 +291,10 @@ - (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEven
283291
//fprintf(stderr,"jm_handleOpenURL\n");
284292
JNIEnv *env = [ThreadUtilities getJNIEnv];
285293
jstring jURL = JNFNSToJavaString(env, url);
286-
static JNF_STATIC_MEMBER_CACHE(jm_handleOpenURI, sjc_AppEventHandler, "handleOpenURI", "(Ljava/lang/String;)V");
287-
JNFCallStaticVoidMethod(env, jm_handleOpenURI, jURL); // AWT_THREADING Safe (event)
294+
GET_APPEVENTHANDLER_CLASS();
295+
DECLARE_STATIC_METHOD(jm_handleOpenURI, sjc_AppEventHandler, "handleOpenURI", "(Ljava/lang/String;)V");
296+
(*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handleOpenURI, jURL); // AWT_THREADING Safe (event)
297+
CHECK_EXCEPTION();
288298
(*env)->DeleteLocalRef(env, jURL);
289299

290300
[replyEvent insertDescriptor:[NSAppleEventDescriptor nullDescriptor] atIndex:0];
@@ -293,14 +303,22 @@ - (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEven
293303
// Helper for both open file and print file methods
294304
// Creates a Java list of files from a native list of files
295305
- (jobject)_createFilePathArrayFrom:(NSArray *)filenames withEnv:(JNIEnv *)env {
296-
static JNF_CLASS_CACHE(sjc_ArrayList, "java/util/ArrayList");
297-
static JNF_CTOR_CACHE(jm_ArrayList_ctor, sjc_ArrayList, "(I)V");
298-
static JNF_MEMBER_CACHE(jm_ArrayList_add, sjc_ArrayList, "add", "(Ljava/lang/Object;)Z");
306+
static jclass sjc_ArrayList = NULL;
307+
if (sjc_ArrayList == NULL) {
308+
sjc_ArrayList = (*env)->FindClass(env, "java/util/ArrayList");
309+
if (sjc_ArrayList != NULL) sjc_ArrayList = (*env)->NewGlobalRef(env, sjc_ArrayList); \
310+
}
311+
CHECK_NULL_RETURN(sjc_ArrayList, NULL);
312+
DECLARE_METHOD_RETURN(jm_ArrayList_ctor, sjc_ArrayList, "<init>", "(I)V", NULL);
313+
DECLARE_METHOD_RETURN(jm_ArrayList_add, sjc_ArrayList, "add", "(Ljava/lang/Object;)Z", NULL);
314+
315+
jobject jFileNamesArray = (*env)->NewObject(env, sjc_ArrayList, jm_ArrayList_ctor, (jint)[filenames count]); // AWT_THREADING Safe (known object)
316+
CHECK_EXCEPTION_NULL_RETURN(jFileNamesArray, NULL);
299317

300-
jobject jFileNamesArray = JNFNewObject(env, jm_ArrayList_ctor, (jint)[filenames count]); // AWT_THREADING Safe (known object)
301318
for (NSString *filename in filenames) {
302319
jstring jFileName = JNFNormalizedJavaStringForPath(env, filename);
303-
JNFCallVoidMethod(env, jFileNamesArray, jm_ArrayList_add, jFileName);
320+
(*env)->CallVoidMethod(env, jFileNamesArray, jm_ArrayList_add, jFileName);
321+
CHECK_EXCEPTION();
304322
}
305323

306324
return jFileNamesArray;
@@ -325,8 +343,11 @@ - (void)application:(NSApplication *)theApplication openFiles:(NSArray *)fileNam
325343
// convert the file names array
326344
jobject jFileNamesArray = [self _createFilePathArrayFrom:fileNames withEnv:env];
327345

328-
static JNF_STATIC_MEMBER_CACHE(jm_handleOpenFiles, sjc_AppEventHandler, "handleOpenFiles", "(Ljava/util/List;Ljava/lang/String;)V");
329-
JNFCallStaticVoidMethod(env, jm_handleOpenFiles, jFileNamesArray, jSearchString);
346+
GET_APPEVENTHANDLER_CLASS();
347+
DECLARE_STATIC_METHOD(jm_handleOpenFiles, sjc_AppEventHandler,
348+
"handleOpenFiles", "(Ljava/util/List;Ljava/lang/String;)V");
349+
(*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handleOpenFiles, jFileNamesArray, jSearchString);
350+
CHECK_EXCEPTION();
330351
(*env)->DeleteLocalRef(env, jFileNamesArray);
331352
(*env)->DeleteLocalRef(env, jSearchString);
332353

@@ -341,8 +362,11 @@ - (NSApplicationPrintReply)application:(NSApplication *)application printFiles:(
341362
//fprintf(stderr,"jm_handlePrintFile\n");
342363
JNIEnv *env = [ThreadUtilities getJNIEnv];
343364
jobject jFileNamesArray = [self _createFilePathArrayFrom:fileNames withEnv:env];
344-
static JNF_STATIC_MEMBER_CACHE(jm_handlePrintFile, sjc_AppEventHandler, "handlePrintFiles", "(Ljava/util/List;)V");
345-
JNFCallStaticVoidMethod(env, jm_handlePrintFile, jFileNamesArray); // AWT_THREADING Safe (event)
365+
GET_APPEVENTHANDLER_CLASS_RETURN(NSPrintingCancelled);
366+
DECLARE_STATIC_METHOD_RETURN(jm_handlePrintFile, sjc_AppEventHandler,
367+
"handlePrintFiles", "(Ljava/util/List;)V", NSPrintingCancelled);
368+
(*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handlePrintFile, jFileNamesArray); // AWT_THREADING Safe (event)
369+
CHECK_EXCEPTION();
346370
(*env)->DeleteLocalRef(env, jFileNamesArray);
347371

348372
return NSPrintingSuccess;
@@ -354,8 +378,10 @@ + (void)_notifyJava:(jint)notificationType {
354378

355379
//fprintf(stderr,"jm_handleOpenApplication\n");
356380
JNIEnv *env = [ThreadUtilities getJNIEnv];
357-
static JNF_STATIC_MEMBER_CACHE(jm_handleNativeNotification, sjc_AppEventHandler, "handleNativeNotification", "(I)V");
358-
JNFCallStaticVoidMethod(env, jm_handleNativeNotification, notificationType); // AWT_THREADING Safe (event)
381+
GET_APPEVENTHANDLER_CLASS();
382+
DECLARE_STATIC_METHOD(jm_handleNativeNotification, sjc_AppEventHandler, "handleNativeNotification", "(I)V");
383+
(*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handleNativeNotification, notificationType); // AWT_THREADING Safe (event)
384+
CHECK_EXCEPTION();
359385
}
360386

361387
// About menu handler

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#import "CDataTransferer.h"
2727
#import "ThreadUtilities.h"
28-
#import "jni_util.h"
28+
#import "JNIUtilities.h"
2929
#import <Cocoa/Cocoa.h>
3030
#import <JavaNativeFoundation/JavaNativeFoundation.h>
3131

@@ -88,18 +88,19 @@ - (void)checkPasteboard:(id)sender {
8888
if (self.changeCount != newChangeCount) {
8989
self.changeCount = newChangeCount;
9090

91-
// Notify that the content might be changed
92-
static JNF_CLASS_CACHE(jc_CClipboard, "sun/lwawt/macosx/CClipboard");
93-
static JNF_STATIC_MEMBER_CACHE(jm_contentChanged, jc_CClipboard, "notifyChanged", "()V");
9491
JNIEnv *env = [ThreadUtilities getJNIEnv];
95-
JNFCallStaticVoidMethod(env, jm_contentChanged);
92+
// Notify that the content might be changed
93+
DECLARE_CLASS(jc_CClipboard, "sun/lwawt/macosx/CClipboard");
94+
DECLARE_STATIC_METHOD(jm_contentChanged, jc_CClipboard, "notifyChanged", "()V");
95+
(*env)->CallStaticVoidMethod(env, jc_CClipboard, jm_contentChanged);
96+
CHECK_EXCEPTION();
9697

9798
// If we have a Java pasteboard owner, tell it that it doesn't own the pasteboard anymore.
98-
static JNF_MEMBER_CACHE(jm_lostOwnership, jc_CClipboard, "notifyLostOwnership", "()V");
99+
DECLARE_METHOD(jm_lostOwnership, jc_CClipboard, "notifyLostOwnership", "()V");
99100
@synchronized(self) {
100101
if (self.clipboardOwner) {
101-
JNIEnv *env = [ThreadUtilities getJNIEnv];
102-
JNFCallVoidMethod(env, self.clipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event)
102+
(*env)->CallVoidMethod(env, self.clipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event)
103+
CHECK_EXCEPTION();
103104
JNFDeleteGlobalRef(env, self.clipboardOwner);
104105
self.clipboardOwner = NULL;
105106
}

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

+48-22
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#import "DnDUtilities.h"
3939
#import "ThreadUtilities.h"
4040
#import "LWCToolkit.h"
41+
#import "JNIUtilities.h"
4142

4243

4344
// When sIsJavaDragging is true Java drag gesture has been recognized and a drag is/has been initialized.
@@ -69,9 +70,17 @@ + (void)javaDraggingEnd
6970
}
7071
@end
7172

72-
JNF_CLASS_CACHE(DataTransfererClass, "sun/awt/datatransfer/DataTransferer");
73-
JNF_CLASS_CACHE(CDragSourceContextPeerClass, "sun/lwawt/macosx/CDragSourceContextPeer");
74-
JNF_CLASS_CACHE(CImageClass, "sun/lwawt/macosx/CImage");
73+
static jclass DataTransfererClass = NULL;
74+
static jclass CDragSourceContextPeerClass = NULL;
75+
76+
#define GET_DT_CLASS() \
77+
GET_CLASS(DataTransfererClass, "sun/awt/datatransfer/DataTransferer");
78+
79+
#define GET_DT_CLASS_RETURN(ret) \
80+
GET_CLASS_RETURN(DataTransfererClass, "sun/awt/datatransfer/DataTransferer", ret);
81+
82+
#define GET_DSCP_CLASS() \
83+
GET_CLASS(CDragSourceContextPeerClass, "sun/lwawt/macosx/CDragSourceContextPeer");
7584

7685
static NSDragOperation sDragOperation;
7786
static NSPoint sDraggingLocation;
@@ -212,8 +221,11 @@ - (void)dealloc
212221
//
213222
- (jobject)dataTransferer:(JNIEnv*)env
214223
{
215-
JNF_STATIC_MEMBER_CACHE(getInstanceMethod, DataTransfererClass, "getInstance", "()Lsun/awt/datatransfer/DataTransferer;");
216-
return JNFCallStaticObjectMethod(env, getInstanceMethod);
224+
GET_DT_CLASS_RETURN(NULL);
225+
DECLARE_STATIC_METHOD_RETURN(getInstanceMethod, DataTransfererClass, "getInstance", "()Lsun/awt/datatransfer/DataTransferer;", NULL);
226+
jobject o = (*env)->CallStaticObjectMethod(env, DataTransfererClass, getInstanceMethod);
227+
CHECK_EXCEPTION();
228+
return o;
217229
}
218230

219231
// Appropriated from Windows' awt_DataTransferer.cpp:
@@ -227,9 +239,11 @@ - (jbyteArray)convertData:(jlong)format
227239
jbyteArray data = nil;
228240

229241
if (transferer != NULL) {
230-
JNF_MEMBER_CACHE(convertDataMethod, DataTransfererClass, "convertData", "(Ljava/lang/Object;Ljava/awt/datatransfer/Transferable;JLjava/util/Map;Z)[B");
231-
data = JNFCallObjectMethod(env, transferer, convertDataMethod, fComponent, fTransferable, format, fFormatMap, (jboolean) TRUE);
242+
GET_DT_CLASS_RETURN(NULL);
243+
DECLARE_METHOD_RETURN(convertDataMethod, DataTransfererClass, "convertData", "(Ljava/lang/Object;Ljava/awt/datatransfer/Transferable;JLjava/util/Map;Z)[B", NULL);
244+
data = (*env)->CallObjectMethod(env, transferer, convertDataMethod, fComponent, fTransferable, format, fFormatMap, (jboolean) TRUE);
232245
}
246+
CHECK_EXCEPTION();
233247

234248
return data;
235249
}
@@ -555,11 +569,14 @@ - (void)doDrag
555569
}
556570

557571
// DragSourceContextPeer.dragDropFinished() should be called even if there was an error:
558-
JNF_MEMBER_CACHE(dragDropFinishedMethod, CDragSourceContextPeerClass, "dragDropFinished", "(ZIII)V");
572+
GET_DSCP_CLASS();
573+
DECLARE_METHOD(dragDropFinishedMethod, CDragSourceContextPeerClass, "dragDropFinished", "(ZIII)V");
559574
DLog3(@" -> posting dragDropFinished, point %f, %f", point.x, point.y);
560-
JNFCallVoidMethod(env, fDragSourceContextPeer, dragDropFinishedMethod, success, dragOp, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
561-
JNF_MEMBER_CACHE(resetHoveringMethod, CDragSourceContextPeerClass, "resetHovering", "()V");
562-
JNFCallVoidMethod(env, fDragSourceContextPeer, resetHoveringMethod); // Hust reset static variable
575+
(*env)->CallVoidMethod(env, fDragSourceContextPeer, dragDropFinishedMethod, success, dragOp, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
576+
CHECK_EXCEPTION();
577+
DECLARE_METHOD(resetHoveringMethod, CDragSourceContextPeerClass, "resetHovering", "()V");
578+
(*env)->CallVoidMethod(env, fDragSourceContextPeer, resetHoveringMethod); // Hust reset static variable
579+
CHECK_EXCEPTION();
563580
} @finally {
564581
sNeedsEnter = NO;
565582
AWTToolkit.inDoDragDropLoop = NO;
@@ -594,8 +611,10 @@ - (void)draggingOperationChanged:(NSDragOperation)dragOp {
594611
DLog3(@" -> posting operationChanged, point %f, %f", point.x, point.y);
595612
jint modifiedModifiers = fDragKeyModifiers | fDragMouseModifiers | [DnDUtilities javaKeyModifiersForNSDragOperation:dragOp];
596613

597-
JNF_MEMBER_CACHE(operationChangedMethod, CDragSourceContextPeerClass, "operationChanged", "(IIII)V");
598-
JNFCallVoidMethod(env, fDragSourceContextPeer, operationChangedMethod, targetActions, modifiedModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
614+
GET_DSCP_CLASS();
615+
DECLARE_METHOD(operationChangedMethod, CDragSourceContextPeerClass, "operationChanged", "(IIII)V");
616+
(*env)->CallVoidMethod(env, fDragSourceContextPeer, operationChangedMethod, targetActions, modifiedModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
617+
CHECK_EXCEPTION();
599618
}
600619

601620
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)localDrag {
@@ -667,12 +686,14 @@ - (void)draggedImage:(NSImage *)image movedTo:(NSPoint)screenPoint {
667686
DLog4(@"[CDragSource draggedImage moved]: (%f, %f) %@\n", screenPoint.x, screenPoint.y, self);
668687

669688
DLog3(@" -> posting dragMotion, point %f, %f", point.x, point.y);
670-
JNF_MEMBER_CACHE(dragMotionMethod, CDragSourceContextPeerClass, "dragMotion", "(IIII)V");
671-
JNFCallVoidMethod(env, fDragSourceContextPeer, dragMotionMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
672-
689+
GET_DSCP_CLASS();
690+
DECLARE_METHOD(dragMotionMethod, CDragSourceContextPeerClass, "dragMotion", "(IIII)V");
691+
(*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMotionMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
692+
CHECK_EXCEPTION();
673693
DLog3(@" -> posting dragMouseMoved, point %f, %f", point.x, point.y);
674-
JNF_MEMBER_CACHE(dragMouseMovedMethod, CDragSourceContextPeerClass, "dragMouseMoved", "(IIII)V");
675-
JNFCallVoidMethod(env, fDragSourceContextPeer, dragMouseMovedMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
694+
DECLARE_METHOD(dragMouseMovedMethod, CDragSourceContextPeerClass, "dragMouseMoved", "(IIII)V");
695+
(*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMouseMovedMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
696+
CHECK_EXCEPTION();
676697
}
677698
JNF_COCOA_EXIT(env);
678699
}
@@ -696,8 +717,10 @@ - (void) postDragEnter {
696717

697718
NSPoint point = [self mapNSScreenPointToJavaWithOffset:sDraggingLocation];
698719
DLog3(@" -> posting dragEnter, point %f, %f", point.x, point.y);
699-
JNF_MEMBER_CACHE(dragEnterMethod, CDragSourceContextPeerClass, "dragEnter", "(IIII)V");
700-
JNFCallVoidMethod(env, fDragSourceContextPeer, dragEnterMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
720+
GET_DSCP_CLASS();
721+
DECLARE_METHOD(dragEnterMethod, CDragSourceContextPeerClass, "dragEnter", "(IIII)V");
722+
(*env)->CallVoidMethod(env, fDragSourceContextPeer, dragEnterMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
723+
CHECK_EXCEPTION();
701724
}
702725

703726
- (void) postDragExit {
@@ -706,8 +729,11 @@ - (void) postDragExit {
706729

707730
NSPoint point = [self mapNSScreenPointToJavaWithOffset:sDraggingLocation];
708731
DLog3(@" -> posting dragExit, point %f, %f", point.x, point.y);
709-
JNF_MEMBER_CACHE(dragExitMethod, CDragSourceContextPeerClass, "dragExit", "(II)V");
710-
JNFCallVoidMethod(env, fDragSourceContextPeer, dragExitMethod, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
732+
GET_DSCP_CLASS();
733+
DECLARE_METHOD(dragExitMethod, CDragSourceContextPeerClass, "dragExit", "(II)V");
734+
(*env)->CallVoidMethod(env, fDragSourceContextPeer, dragExitMethod, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event)
735+
CHECK_EXCEPTION();
736+
711737
}
712738

713739

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Apr 8, 2021

@openjdk-notifier[bot]
This repository has been archived.