# HG changeset patch # User vkempik # Date 1617797753 0 # Wed Apr 07 12:15:53 2021 +0000 # Node ID 9ce80bd2884c6fc0e1a221ec46da98456f746ef5 # Parent 3c184f05cdf1df68ae2aa94f7b9ce706d2ed2dc7 8257858: [macOS]: Remove JNF dependency from libosxsecurity/KeystoreImpl.m 8257860: [macOS]: Remove JNF dependency from libosxkrb5/SCDynamicStoreConfig.m diff --git a/make/common/TestFilesCompilation.gmk b/make/common/TestFilesCompilation.gmk --- a/make/common/TestFilesCompilation.gmk +++ b/make/common/TestFilesCompilation.gmk @@ -75,7 +75,7 @@ # Locate all files with the matching prefix $1_FILE_LIST := \ - $$(call FindFiles, $$($1_SOURCE_DIRS), $$($1_PREFIX)*.c) + $$(call FindFiles, $$($1_SOURCE_DIRS), $$($1_PREFIX)*.c $$($1_PREFIX)*.m) $1_EXCLUDE_PATTERN := $$(addprefix %/, $$($1_EXCLUDE)) $1_FILTERED_FILE_LIST := $$(filter-out $$($1_EXCLUDE_PATTERN), $$($1_FILE_LIST)) diff --git a/make/lib/Lib-java.base.gmk b/make/lib/Lib-java.base.gmk --- a/make/lib/Lib-java.base.gmk +++ b/make/lib/Lib-java.base.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -110,9 +110,9 @@ $(call SET_SHARED_LIBRARY_ORIGIN), \ LIBS := \ -lobjc \ - -framework JavaNativeFoundation \ -framework CoreServices \ -framework Security \ + -framework Foundation \ $(JDKLIB_LIBS), \ )) diff --git a/make/lib/Lib-java.security.jgss.gmk b/make/lib/Lib-java.security.jgss.gmk --- a/make/lib/Lib-java.security.jgss.gmk +++ b/make/lib/Lib-java.security.jgss.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -78,8 +78,8 @@ DISABLED_WARNINGS_clang := deprecated-declarations, \ LDFLAGS := $(LDFLAGS_JDKLIB) \ $(call SET_SHARED_LIBRARY_ORIGIN), \ - LIBS := -framework JavaNativeFoundation -framework Cocoa \ - -framework SystemConfiguration -framework Kerberos, \ + LIBS := -framework Cocoa -framework SystemConfiguration \ + -framework Kerberos, \ )) TARGETS += $(BUILD_LIBOSXKRB5) diff --git a/make/test/JtregNativeJdk.gmk b/make/test/JtregNativeJdk.gmk --- a/make/test/JtregNativeJdk.gmk +++ b/make/test/JtregNativeJdk.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -76,11 +76,13 @@ endif ifeq ($(OPENJDK_TARGET_OS), macosx) - BUILD_JDK_JTREG_LIBRARIES_CFLAGS_libTestMainKeyWindow := -ObjC BUILD_JDK_JTREG_LIBRARIES_LIBS_libTestMainKeyWindow := \ -framework Cocoa -framework JavaNativeFoundation + BUILD_JDK_JTREG_LIBRARIES_LIBS_libTestDynamicStore := \ + -framework Cocoa -framework SystemConfiguration else - BUILD_JDK_JTREG_EXCLUDE += libTestMainKeyWindow.c + BUILD_JDK_JTREG_EXCLUDE += libTestMainKeyWindow.m + BUILD_JDK_JTREG_EXCLUDE += libTestDynamicStore.m endif $(eval $(call SetupTestFilesCompilation, BUILD_JDK_JTREG_LIBRARIES, \ diff --git a/src/java.base/macosx/classes/apple/security/KeychainStore.java b/src/java.base/macosx/classes/apple/security/KeychainStore.java --- a/src/java.base/macosx/classes/apple/security/KeychainStore.java +++ b/src/java.base/macosx/classes/apple/security/KeychainStore.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -826,8 +826,8 @@ * Callback method from _scanKeychain. If an identity is found, this method will be called to create Java certificate * and private key objects from the keychain data. */ - private void createKeyEntry(String alias, long creationDate, long secKeyRef, long[] secCertificateRefs, byte[][] rawCertData) - throws IOException, NoSuchAlgorithmException, UnrecoverableKeyException { + private void createKeyEntry(String alias, long creationDate, long secKeyRef, + long[] secCertificateRefs, byte[][] rawCertData) { KeyEntry ke = new KeyEntry(); // First, store off the private key information. This is the easy part. diff --git a/src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m b/src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m --- a/src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m +++ b/src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,16 +25,10 @@ #import "apple_security_KeychainStore.h" #import "jni_util.h" - #import #import #import // (for require() macros) -#import - - -static JNF_CLASS_CACHE(jc_KeychainStore, "apple/security/KeychainStore"); -static JNF_MEMBER_CACHE(jm_createTrustedCertEntry, jc_KeychainStore, "createTrustedCertEntry", "(Ljava/lang/String;JJ[B)V"); -static JNF_MEMBER_CACHE(jm_createKeyEntry, jc_KeychainStore, "createKeyEntry", "(Ljava/lang/String;JJ[J[[B)V"); +#import static jstring getLabelFromItem(JNIEnv *env, SecKeychainItemRef inItem) { @@ -290,6 +284,10 @@ SecIdentityRef theIdentity = NULL; OSErr searchResult = noErr; + jclass jc_KeychainStore = (*env)->FindClass(env, "apple/security/KeychainStore"); + CHECK_NULL(jc_KeychainStore); + jmethodID jm_createKeyEntry = (*env)->GetMethodID(env, jc_KeychainStore, "createKeyEntry", "(Ljava/lang/String;JJ[J[[B)V"); + CHECK_NULL(jm_createKeyEntry); do { searchResult = SecIdentitySearchCopyNext(identitySearch, &theIdentity); @@ -359,7 +357,8 @@ // Call back to the Java object to create Java objects corresponding to this security object. jlong nativeKeyRef = ptr_to_jlong(privateKeyRef); - JNFCallVoidMethod(env, keyStore, jm_createKeyEntry, alias, creationDate, nativeKeyRef, certRefArray, javaCertArray); + (*env)->CallVoidMethod(env, keyStore, jm_createKeyEntry, alias, creationDate, nativeKeyRef, certRefArray, javaCertArray); + JNU_CHECK_EXCEPTION(env); } } while (searchResult == noErr); @@ -377,6 +376,11 @@ SecKeychainItemRef theItem = NULL; OSErr searchResult = noErr; + jclass jc_KeychainStore = (*env)->FindClass(env, "apple/security/KeychainStore"); + CHECK_NULL(jc_KeychainStore); + jmethodID jm_createTrustedCertEntry = (*env)->GetMethodID( + env, jc_KeychainStore, "createTrustedCertEntry", "(Ljava/lang/String;JJ[B)V"); + CHECK_NULL(jm_createTrustedCertEntry); do { searchResult = SecKeychainSearchCopyNext(keychainItemSearch, &theItem); @@ -402,7 +406,8 @@ // Call back to the Java object to create Java objects corresponding to this security object. jlong nativeRef = ptr_to_jlong(certRef); - JNFCallVoidMethod(env, keyStore, jm_createTrustedCertEntry, alias, nativeRef, creationDate, certData); + (*env)->CallVoidMethod(env, keyStore, jm_createTrustedCertEntry, alias, nativeRef, creationDate, certData); + JNU_CHECK_EXCEPTION(env); } } while (searchResult == noErr); @@ -500,6 +505,20 @@ } +NSString* JavaStringToNSString(JNIEnv *env, jstring jstr) { + if (jstr == NULL) { + return NULL; + } + jsize len = (*env)->GetStringLength(env, jstr); + const jchar *chars = (*env)->GetStringChars(env, jstr, NULL); + if (chars == NULL) { + return NULL; + } + NSString *result = [NSString stringWithCharacters:(UniChar *)chars length:len]; + (*env)->ReleaseStringChars(env, jstr, chars); + return result; +} + /* * Class: apple_security_KeychainStore * Method: _addItemToKeychain @@ -511,95 +530,97 @@ OSStatus err; jlong returnValue = 0; -JNF_COCOA_ENTER(env); - - jsize dataSize = (*env)->GetArrayLength(env, rawDataObj); - jbyte *rawData = (*env)->GetByteArrayElements(env, rawDataObj, NULL); - if (rawData == NULL) { - goto errOut; - } + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \ + @try { + jsize dataSize = (*env)->GetArrayLength(env, rawDataObj); + jbyte *rawData = (*env)->GetByteArrayElements(env, rawDataObj, NULL); + if (rawData == NULL) { + goto errOut; + } - CFDataRef cfDataToImport = CFDataCreate(kCFAllocatorDefault, (UInt8 *)rawData, dataSize); - CFArrayRef createdItems = NULL; + CFDataRef cfDataToImport = CFDataCreate(kCFAllocatorDefault, (UInt8 *)rawData, dataSize); + CFArrayRef createdItems = NULL; - SecKeychainRef defaultKeychain = NULL; - SecKeychainCopyDefault(&defaultKeychain); + SecKeychainRef defaultKeychain = NULL; + SecKeychainCopyDefault(&defaultKeychain); - SecExternalFormat dataFormat = (isCertificate == JNI_TRUE ? kSecFormatX509Cert : kSecFormatWrappedPKCS8); + SecExternalFormat dataFormat = (isCertificate == JNI_TRUE ? kSecFormatX509Cert : kSecFormatWrappedPKCS8); - // Convert the password obj into a CFStringRef that the keychain importer can use for encryption. - SecKeyImportExportParameters paramBlock; - CFStringRef passwordStrRef = NULL; + // Convert the password obj into a CFStringRef that the keychain importer can use for encryption. + SecKeyImportExportParameters paramBlock; + CFStringRef passwordStrRef = NULL; - jsize passwordLen = 0; - jchar *passwordChars = NULL; + jsize passwordLen = 0; + jchar *passwordChars = NULL; - if (passwordObj) { - passwordLen = (*env)->GetArrayLength(env, passwordObj); + if (passwordObj) { + passwordLen = (*env)->GetArrayLength(env, passwordObj); - if (passwordLen > 0) { - passwordChars = (*env)->GetCharArrayElements(env, passwordObj, NULL); - if (passwordChars == NULL) { - goto errOut; - } + if (passwordLen > 0) { + passwordChars = (*env)->GetCharArrayElements(env, passwordObj, NULL); + if (passwordChars == NULL) { + goto errOut; + } - passwordStrRef = CFStringCreateWithCharactersNoCopy(NULL, passwordChars, passwordLen, kCFAllocatorNull); - if (passwordStrRef == NULL) { - goto errOut; + passwordStrRef = CFStringCreateWithCharactersNoCopy(NULL, passwordChars, passwordLen, kCFAllocatorNull); + if (passwordStrRef == NULL) { + goto errOut; + } } } - } - - paramBlock.version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION; - // Note that setting the flags field **requires** you to pass in a password of some kind. The keychain will not prompt you. - paramBlock.flags = 0; - paramBlock.passphrase = passwordStrRef; - paramBlock.alertTitle = NULL; - paramBlock.alertPrompt = NULL; - paramBlock.accessRef = NULL; - paramBlock.keyUsage = CSSM_KEYUSE_ANY; - paramBlock.keyAttributes = CSSM_KEYATTR_RETURN_DEFAULT; - err = SecKeychainItemImport(cfDataToImport, NULL, &dataFormat, NULL, - 0, ¶mBlock, defaultKeychain, &createdItems); - if (cfDataToImport != NULL) { - CFRelease(cfDataToImport); - } + paramBlock.version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION; + // Note that setting the flags field **requires** you to pass in a password of some kind. The keychain will not prompt you. + paramBlock.flags = 0; + paramBlock.passphrase = passwordStrRef; + paramBlock.alertTitle = NULL; + paramBlock.alertPrompt = NULL; + paramBlock.accessRef = NULL; + paramBlock.keyUsage = CSSM_KEYUSE_ANY; + paramBlock.keyAttributes = CSSM_KEYATTR_RETURN_DEFAULT; - if (err == noErr) { - SecKeychainItemRef anItem = (SecKeychainItemRef)CFArrayGetValueAtIndex(createdItems, 0); - - // Don't bother labeling keys. They become part of an identity, and are not an accessible part of the keychain. - if (CFGetTypeID(anItem) == SecCertificateGetTypeID()) { - setLabelForItem(JNFJavaToNSString(env, alias), anItem); + err = SecKeychainItemImport(cfDataToImport, NULL, &dataFormat, NULL, + 0, ¶mBlock, defaultKeychain, &createdItems); + if (cfDataToImport != NULL) { + CFRelease(cfDataToImport); } - // Retain the item, since it will be released once when the array holding it gets released. - CFRetain(anItem); - returnValue = ptr_to_jlong(anItem); - } else { - cssmPerror("_addItemToKeychain: SecKeychainItemImport", err); - } + if (err == noErr) { + SecKeychainItemRef anItem = (SecKeychainItemRef)CFArrayGetValueAtIndex(createdItems, 0); - if (createdItems != NULL) { - CFRelease(createdItems); - } + // Don't bother labeling keys. They become part of an identity, and are not an accessible part of the keychain. + if (CFGetTypeID(anItem) == SecCertificateGetTypeID()) { + setLabelForItem(JavaStringToNSString(env, alias), anItem); + } + + // Retain the item, since it will be released once when the array holding it gets released. + CFRetain(anItem); + returnValue = ptr_to_jlong(anItem); + } else { + cssmPerror("_addItemToKeychain: SecKeychainItemImport", err); + } -errOut: - if (rawData) { - (*env)->ReleaseByteArrayElements(env, rawDataObj, rawData, JNI_ABORT); - } + if (createdItems != NULL) { + CFRelease(createdItems); + } + + errOut: + if (rawData) { + (*env)->ReleaseByteArrayElements(env, rawDataObj, rawData, JNI_ABORT); + } - if (passwordStrRef) CFRelease(passwordStrRef); - if (passwordChars) { - // clear the password and release - memset(passwordChars, 0, passwordLen); - (*env)->ReleaseCharArrayElements(env, passwordObj, passwordChars, - JNI_ABORT); + if (passwordStrRef) CFRelease(passwordStrRef); + if (passwordChars) { + // clear the password and release + memset(passwordChars, 0, passwordLen); + (*env)->ReleaseCharArrayElements(env, passwordObj, passwordChars, + JNI_ABORT); + } + } @catch (NSException *e) { + NSLog(@"%@", [e callStackSymbols]); + } @finally { + [pool drain]; } - -JNF_COCOA_EXIT(env); - return returnValue; } diff --git a/src/java.security.jgss/macosx/native/libosxkrb5/SCDynamicStoreConfig.m b/src/java.security.jgss/macosx/native/libosxkrb5/SCDynamicStoreConfig.m --- a/src/java.security.jgss/macosx/native/libosxkrb5/SCDynamicStoreConfig.m +++ b/src/java.security.jgss/macosx/native/libosxkrb5/SCDynamicStoreConfig.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,110 +24,40 @@ */ #import -#import #import - - -@interface JNFVectorCoercion : NSObject { } -@end - -@implementation JNFVectorCoercion - -- (jobject) coerceNSObject:(id)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer { - static JNF_CLASS_CACHE(jc_Vector, "java/util/Vector"); - static JNF_CTOR_CACHE(jm_Vector_ctor, jc_Vector, "(I)V"); - static JNF_MEMBER_CACHE(jm_Vector_add, jc_Vector, "add", "(Ljava/lang/Object;)Z"); - - NSArray *nsArray = (NSArray *)obj; - jobject javaArray = JNFNewObject(env, jm_Vector_ctor, (jint)[nsArray count]); - - for (id obj in nsArray) { - jobject jobj = [coercer coerceNSObject:obj withEnv:env usingCoercer:coercer]; - JNFCallBooleanMethod(env, javaArray, jm_Vector_add, jobj); - if (jobj != NULL) (*env)->DeleteLocalRef(env, jobj); - } - - return javaArray; -} - -- (id) coerceJavaObject:(jobject)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer { - return nil; -} - -@end - - -@interface JNFHashtableCoercion : NSObject { } -@end - -@implementation JNFHashtableCoercion - -- (jobject) coerceNSObject:(id)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer { - static JNF_CLASS_CACHE(jc_Hashtable, "java/util/Hashtable"); - static JNF_CTOR_CACHE(jm_Hashtable_ctor, jc_Hashtable, "()V"); - static JNF_MEMBER_CACHE(jm_Hashtable_put, jc_Hashtable, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); - - NSDictionary *nsDict = (NSDictionary *)obj; - NSEnumerator *keyEnum = [nsDict keyEnumerator]; - - jobject jHashTable = JNFNewObject(env, jm_Hashtable_ctor); - - id key = nil; - while ((key = [keyEnum nextObject]) != nil) { - jobject jkey = [coercer coerceNSObject:key withEnv:env usingCoercer:coercer]; - - id value = [nsDict objectForKey:key]; - jobject jvalue = [coercer coerceNSObject:value withEnv:env usingCoercer:coercer]; - - JNFCallObjectMethod(env, jHashTable, jm_Hashtable_put, jkey, jvalue); - - if (jkey != NULL) (*env)->DeleteLocalRef(env, jkey); - if (jvalue != NULL) (*env)->DeleteLocalRef(env, jvalue); - } - - return jHashTable; -} - -- (id) coerceJavaObject:(jobject)obj withEnv:(JNIEnv *)env usingCoercer:(JNFTypeCoercion *)coercer { - return nil; -} - -@end - - - -NSDictionary *realmConfigsForRealms(SCDynamicStoreRef store, NSArray *realms) { - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; - - for (NSString *realm in realms) { - CFTypeRef realmInfo = SCDynamicStoreCopyValue(store, (CFStringRef) [NSString stringWithFormat:@"Kerberos:%@", realm]); - - if (realmInfo == NULL || CFGetTypeID(realmInfo) != CFDictionaryGetTypeID()) { - if (realmInfo) CFRelease(realmInfo); - return nil; - } - - [dict setObject:(NSArray *)realmInfo forKey:realm]; - CFRelease(realmInfo); - } - - return dict; -} - +#import "jni_util.h" #define KERBEROS_DEFAULT_REALMS @"Kerberos-Default-Realms" #define KERBEROS_DEFAULT_REALM_MAPPINGS @"Kerberos-Domain-Realm-Mappings" +#define KERBEROS_REALM_INFO @"Kerberos:%@" + +JavaVM *localVM; void _SCDynamicStoreCallBack(SCDynamicStoreRef store, CFArrayRef changedKeys, void *info) { - NSArray *keys = (NSArray *)changedKeys; + NSArray *keys = (NSArray *)changedKeys; if ([keys count] == 0) return; if (![keys containsObject:KERBEROS_DEFAULT_REALMS] && ![keys containsObject:KERBEROS_DEFAULT_REALM_MAPPINGS]) return; - JNFPerformEnvBlock(JNFThreadDetachOnThreadDeath | JNFThreadSetSystemClassLoaderOnAttach | JNFThreadAttachAsDaemon, ^(JNIEnv *env) { - static JNF_CLASS_CACHE(jc_Config, "sun/security/krb5/Config"); - static JNF_STATIC_MEMBER_CACHE(jm_Config_refresh, jc_Config, "refresh", "()V"); - JNFCallStaticVoidMethod(env, jm_Config_refresh); - }); + JNIEnv *env; + bool createdFromAttach = FALSE; + jint status = (*localVM)->GetEnv(localVM, (void**)&env, JNI_VERSION_1_2); + if (status == JNI_EDETACHED) { + status = (*localVM)->AttachCurrentThreadAsDaemon(localVM, (void**)&env, NULL); + createdFromAttach = TRUE; + } + if (status == 0) { + jclass jc_Config = (*env)->FindClass(env, "sun/security/krb5/Config"); + CHECK_NULL(jc_Config); + jmethodID jm_Config_refresh = (*env)->GetStaticMethodID(env, jc_Config, "refresh", "()V"); + CHECK_NULL(jm_Config_refresh); + (*env)->CallStaticVoidMethod(env, jc_Config, jm_Config_refresh); + if ((*env)->ExceptionOccurred(env) != NULL) { + (*env)->ExceptionClear(env); + } + if (createdFromAttach) { + (*localVM)->DetachCurrentThread(localVM); + } + } } /* @@ -135,89 +65,109 @@ * Method: installNotificationCallback */ JNIEXPORT void JNICALL Java_sun_security_krb5_SCDynamicStoreConfig_installNotificationCallback(JNIEnv *env, jclass klass) { - -JNF_COCOA_ENTER(env); + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \ + @try { + (*env)->GetJavaVM(env, &localVM); + SCDynamicStoreRef store = SCDynamicStoreCreate(NULL, CFSTR("java"), _SCDynamicStoreCallBack, NULL); + if (store == NULL) { + return; + } - SCDynamicStoreRef store = SCDynamicStoreCreate(NULL, CFSTR("java"), _SCDynamicStoreCallBack, NULL); - if (store == NULL) { - return; - } - - NSArray *keys = [NSArray arrayWithObjects:KERBEROS_DEFAULT_REALMS, KERBEROS_DEFAULT_REALM_MAPPINGS, nil]; - SCDynamicStoreSetNotificationKeys(store, (CFArrayRef) keys, NULL); + NSArray *keys = [NSArray arrayWithObjects:KERBEROS_DEFAULT_REALMS, KERBEROS_DEFAULT_REALM_MAPPINGS, nil]; + SCDynamicStoreSetNotificationKeys(store, (CFArrayRef) keys, NULL); - CFRunLoopSourceRef rls = SCDynamicStoreCreateRunLoopSource(NULL, store, 0); - if (rls != NULL) { - CFRunLoopAddSource(CFRunLoopGetMain(), rls, kCFRunLoopDefaultMode); - CFRelease(rls); - } + CFRunLoopSourceRef rls = SCDynamicStoreCreateRunLoopSource(NULL, store, 0); + if (rls != NULL) { + CFRunLoopAddSource(CFRunLoopGetMain(), rls, kCFRunLoopDefaultMode); + CFRelease(rls); + } - CFRelease(store); + CFRelease(store); + } @catch (NSException *e) { + NSLog(@"%@", [e callStackSymbols]); + } @finally { + [pool drain]; + } +} -JNF_COCOA_EXIT(env); +#define ADD(list, str) { \ + jobject localeObj = (*env)->NewStringUTF(env, [str UTF8String]); \ + (*env)->CallBooleanMethod(env, list, jm_listAdd, localeObj); \ + (*env)->DeleteLocalRef(env, localeObj); \ +} -} +#define ADDNULL(list) (*env)->CallBooleanMethod(env, list, jm_listAdd, NULL) /* * Class: sun_security_krb5_SCDynamicStoreConfig * Method: getKerberosConfig - * Signature: ()Ljava/util/Hashtable; + * Signature: ()Ljava/util/List; */ JNIEXPORT jobject JNICALL Java_sun_security_krb5_SCDynamicStoreConfig_getKerberosConfig(JNIEnv *env, jclass klass) { - jobject jHashTable = NULL; -JNF_COCOA_ENTER(env); + jobject newList = 0; - SCDynamicStoreRef store = SCDynamicStoreCreate(NULL, CFSTR("java-kerberos"), NULL, NULL); - if (store == NULL) { - return NULL; - } + SCDynamicStoreRef store = NULL; + CFTypeRef realms = NULL; + CFTypeRef realmMappings = NULL; + CFTypeRef realmInfo = NULL; + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \ + @try { + SCDynamicStoreRef store = SCDynamicStoreCreate(NULL, CFSTR("java-kerberos"), NULL, NULL); + if (store == NULL) { + return NULL; + } - CFTypeRef realms = SCDynamicStoreCopyValue(store, (CFStringRef) KERBEROS_DEFAULT_REALMS); - if (realms == NULL || CFGetTypeID(realms) != CFArrayGetTypeID()) { - if (realms) CFRelease(realms); - CFRelease(store); - return NULL; - } - - CFTypeRef realmMappings = SCDynamicStoreCopyValue(store, (CFStringRef) KERBEROS_DEFAULT_REALM_MAPPINGS); + CFTypeRef realms = SCDynamicStoreCopyValue(store, (CFStringRef) KERBEROS_DEFAULT_REALMS); + if (realms == NULL || CFGetTypeID(realms) != CFArrayGetTypeID()) { + return NULL; + } - if (realmMappings == NULL || CFGetTypeID(realmMappings) != CFArrayGetTypeID()) { - if (realmMappings) CFRelease(realmMappings); - CFRelease(realms); - CFRelease(store); - return NULL; - } - - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + // This methods returns a ArrayList: + // (realm kdc* null) null (mapping-domain mapping-realm)* + jclass jc_arrayListClass = (*env)->FindClass(env, "java/util/ArrayList"); + CHECK_NULL_RETURN(jc_arrayListClass, NULL); + jmethodID jm_arrayListCons = (*env)->GetMethodID(env, jc_arrayListClass, "", "()V"); + CHECK_NULL_RETURN(jm_arrayListCons, NULL); + jmethodID jm_listAdd = (*env)->GetMethodID(env, jc_arrayListClass, "add", "(Ljava/lang/Object;)Z"); + CHECK_NULL_RETURN(jm_listAdd, NULL); + newList = (*env)->NewObject(env, jc_arrayListClass, jm_arrayListCons); + CHECK_NULL_RETURN(newList, NULL); - if (CFArrayGetCount(realms) > 0) { - NSDictionary *defaultRealmsDict = [NSDictionary dictionaryWithObject:[(NSArray *)realms objectAtIndex:0] forKey:@"default_realm"]; - [dict setObject:defaultRealmsDict forKey:@"libdefaults"]; + for (NSString *realm in (NSArray*)realms) { + if (realmInfo) CFRelease(realmInfo); // for the previous realm + realmInfo = SCDynamicStoreCopyValue(store, (CFStringRef) [NSString stringWithFormat:KERBEROS_REALM_INFO, realm]); + if (realmInfo == NULL || CFGetTypeID(realmInfo) != CFDictionaryGetTypeID()) { + continue; + } - NSDictionary *realmConfigs = realmConfigsForRealms(store, (NSArray *)realms); - [dict setObject:realmConfigs forKey:@"realms"]; - } - CFRelease(realms); - CFRelease(store); - - if (CFArrayGetCount(realmMappings) > 0) { - [dict setObject:[(NSArray *)realmMappings objectAtIndex:0] forKey:@"domain_realm"]; - } - CFRelease(realmMappings); + ADD(newList, realm); + NSDictionary* ri = (NSDictionary*)realmInfo; + for (NSDictionary* k in (NSArray*)ri[@"kdc"]) { + ADD(newList, k[@"host"]); + } + ADDNULL(newList); + } + ADDNULL(newList); - - // create and load a coercer with all of the different coercions to convert each type of object - JNFTypeCoercer *coercer = [[[JNFTypeCoercer alloc] init] autorelease]; - [JNFDefaultCoercions addStringCoercionTo:coercer]; - [JNFDefaultCoercions addNumberCoercionTo:coercer]; - [coercer addCoercion:[[[JNFHashtableCoercion alloc] init] autorelease] forNSClass:[NSDictionary class] javaClass:@"java/util/Map"]; - [coercer addCoercion:[[[JNFVectorCoercion alloc] init] autorelease] forNSClass:[NSArray class] javaClass:@"java/util/List"]; - - // convert Cocoa graph to Java graph - jHashTable = [coercer coerceNSObject:dict withEnv:env]; - -JNF_COCOA_EXIT(env); - - return jHashTable; + CFTypeRef realmMappings = SCDynamicStoreCopyValue(store, (CFStringRef) KERBEROS_DEFAULT_REALM_MAPPINGS); + if (realmMappings != NULL && CFGetTypeID(realmMappings) == CFArrayGetTypeID()) { + for (NSDictionary* d in (NSArray *)realmMappings) { + for (NSString* s in d) { + ADD(newList, s); + ADD(newList, d[s]); + } + } + } + } @catch (NSException *e) { + NSLog(@"%@", [e callStackSymbols]); + } @finally { + [pool drain]; + if (realmInfo) CFRelease(realmInfo); + if (realmMappings) CFRelease(realmMappings); + if (realms) CFRelease(realms); + if (store) CFRelease(store); + } + return newList; } diff --git a/src/java.security.jgss/share/classes/sun/security/krb5/SCDynamicStoreConfig.java b/src/java.security.jgss/share/classes/sun/security/krb5/SCDynamicStoreConfig.java --- a/src/java.security.jgss/share/classes/sun/security/krb5/SCDynamicStoreConfig.java +++ b/src/java.security.jgss/share/classes/sun/security/krb5/SCDynamicStoreConfig.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,14 +26,20 @@ package sun.security.krb5; import java.io.IOException; -import java.util.Collection; import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; import java.util.Vector; public class SCDynamicStoreConfig { private static native void installNotificationCallback(); - private static native Hashtable getKerberosConfig(); + + /** + * Returns the dynamic store setting for kerberos in a string array. + * (realm kdc* null) null (mapping-domain mapping-realm)* + */ + private static native List getKerberosConfig(); private static boolean DEBUG = sun.security.krb5.internal.Krb5.DEBUG; static { @@ -51,49 +57,6 @@ if (isMac) installNotificationCallback(); } - private static Vector unwrapHost( - Collection> c) { - Vector vector = new Vector(); - for (Hashtable m : c) { - vector.add(m.get("host")); - } - return vector; - } - - /** - * convertRealmConfigs: Maps the Object graph that we get from JNI to the - * object graph that Config expects. Also the items inside the kdc array - * are wrapped inside Hashtables - */ - @SuppressWarnings("unchecked") - private static Hashtable - convertRealmConfigs(Hashtable configs) { - Hashtable realmsTable = new Hashtable(); - - for (String realm : configs.keySet()) { - // get the kdc - Hashtable> map = - (Hashtable>) configs.get(realm); - Hashtable> realmMap = - new Hashtable>(); - - // put the kdc into the realmMap - Collection> kdc = - (Collection>) map.get("kdc"); - if (kdc != null) realmMap.put("kdc", unwrapHost(kdc)); - - // put the admin server into the realmMap - Collection> kadmin = - (Collection>) map.get("kadmin"); - if (kadmin != null) realmMap.put("admin_server", unwrapHost(kadmin)); - - // add the full entry to the realmTable - realmsTable.put(realm, realmMap); - } - - return realmsTable; - } - /** * Calls down to JNI to get the raw Kerberos Config and maps the object * graph to the one that Kerberos Config in Java expects @@ -102,45 +65,64 @@ * @throws IOException */ public static Hashtable getConfig() throws IOException { - Hashtable stanzaTable = getKerberosConfig(); - if (stanzaTable == null) { + List list = getKerberosConfig(); + if (list == null) { throw new IOException( "Could not load configuration from SCDynamicStore"); } - if (DEBUG) System.out.println("Raw map from JNI: " + stanzaTable); - return convertNativeConfig(stanzaTable); + if (DEBUG) System.out.println("Raw map from JNI: " + list); + + Hashtable v = new Hashtable<>(); + Hashtable realms = new Hashtable<>(); + Iterator iterator = list.iterator(); + String defaultRealm = null; + + while (true) { + String nextRealm = iterator.next(); + if (nextRealm == null) { + break; + } + if (defaultRealm == null) { + defaultRealm = nextRealm; + Hashtable dr = new Hashtable<>(); + dr.put("default_realm", v1(defaultRealm)); + v.put("libdefaults", dr); + } + Vector kdcs = new Vector<>(); + while (true) { + String nextKdc = iterator.next(); + if (nextKdc == null) { + break; + } + kdcs.add(nextKdc); + } + if (!kdcs.isEmpty()) { + Hashtable ri = new Hashtable<>(); + ri.put("kdc", kdcs); + realms.put(nextRealm, ri); + } + } + if (!realms.isEmpty()) { + v.put("realms", realms); + } + Hashtable mapping = new Hashtable<>(); + while (true) { + if (!iterator.hasNext()) { + break; + } + mapping.put(iterator.next(), v1(iterator.next())); + } + if (!mapping.isEmpty()) { + v.put("domain_realm", mapping); + } + return v; } - @SuppressWarnings("unchecked") - private static Hashtable convertNativeConfig( - Hashtable stanzaTable) throws IOException { - // convert SCDynamicStore realm structure to Java realm structure - Hashtable realms = - (Hashtable) stanzaTable.get("realms"); - if (realms == null || realms.isEmpty()) { - throw new IOException( - "SCDynamicStore contains an empty Kerberos setting"); - } - stanzaTable.remove("realms"); - Hashtable realmsTable = convertRealmConfigs(realms); - stanzaTable.put("realms", realmsTable); - WrapAllStringInVector(stanzaTable); - if (DEBUG) System.out.println("stanzaTable : " + stanzaTable); - return stanzaTable; - } - - @SuppressWarnings("unchecked") - private static void WrapAllStringInVector( - Hashtable stanzaTable) { - for (String s: stanzaTable.keySet()) { - Object v = stanzaTable.get(s); - if (v instanceof Hashtable) { - WrapAllStringInVector((Hashtable)v); - } else if (v instanceof String) { - Vector vec = new Vector<>(); - vec.add((String)v); - stanzaTable.put(s, vec); - } - } + // Make a single value Vector. Config's stanzaTable always + // use Vector as end values. + private static Vector v1(String s) { + Vector out = new Vector<>(); + out.add(s); + return out; } } diff --git a/test/jdk/java/awt/Window/MainKeyWindowTest/libTestMainKeyWindow.c b/test/jdk/java/awt/Window/MainKeyWindowTest/libTestMainKeyWindow.m rename from test/jdk/java/awt/Window/MainKeyWindowTest/libTestMainKeyWindow.c rename to test/jdk/java/awt/Window/MainKeyWindowTest/libTestMainKeyWindow.m diff --git a/test/jdk/sun/security/krb5/config/SCDynamicConfigTest.java b/test/jdk/sun/security/krb5/config/SCDynamicConfigTest.java deleted file mode 100644 --- a/test/jdk/sun/security/krb5/config/SCDynamicConfigTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test - * @bug 7184246 - * @summary Simplify Config.get() of krb5 - * @modules java.security.jgss/sun.security.krb5:+open - */ -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.Hashtable; -import java.util.Vector; -import sun.security.krb5.Config; -import sun.security.krb5.SCDynamicStoreConfig; - -public class SCDynamicConfigTest { - - static Vector>hosts() { - Vector > result = new Vector<>(); - Hashtable pair = new Hashtable<>(); - pair.put("host", "127.0.0.1"); - result.add(pair); - pair = new Hashtable<>(); - pair.put("host", "127.0.0.2"); - result.add(pair); - return result; - } - - public static void main(String[] args) throws Exception { - // Reconstruct a typical SCDynamicConfig.getKerberosConfig() output - Hashtable conf = new Hashtable<>(); - - Hashtable libdefaults = new Hashtable<>(); - libdefaults.put("default_realm", "REALM.COM"); - conf.put("libdefaults", libdefaults); - - Hashtable realms = new Hashtable<>(); - Hashtable thisRealm = new Hashtable<>(); - realms.put("REALM.COM", thisRealm); - thisRealm.put("kpasswd", hosts()); - thisRealm.put("kadmin", hosts()); - thisRealm.put("kdc", hosts()); - conf.put("realms", realms); - - Hashtable domain_realm = new Hashtable<>(); - domain_realm.put(".realm.com", "REALM.COM"); - domain_realm.put("realm.com", "REALM.COM"); - conf.put("domain_realm", domain_realm); - - System.out.println("SCDynamicConfig:\n"); - System.out.println(conf); - - // Simulate SCDynamicConfig.getConfig() output - Method m = SCDynamicStoreConfig.class.getDeclaredMethod( - "convertNativeConfig", Hashtable.class); - m.setAccessible(true); - conf = (Hashtable)m.invoke(null, conf); - - System.out.println("\nkrb5.conf:\n"); - System.out.println(conf); - - // Feed it into a Config object - System.setProperty("java.security.krb5.conf", "not-a-file"); - Config cf = Config.getInstance(); - Field f = Config.class.getDeclaredField("stanzaTable"); - f.setAccessible(true); - f.set(cf, conf); - - System.out.println("\nConfig:\n"); - System.out.println(cf); - - if (!cf.getDefaultRealm().equals("REALM.COM")) { - throw new Exception(); - } - if (!cf.getKDCList("REALM.COM").equals("127.0.0.1 127.0.0.2")) { - throw new Exception(); - } - if (!cf.get("domain_realm", ".realm.com").equals("REALM.COM")) { - throw new Exception(); - } - } -} diff --git a/test/jdk/sun/security/krb5/config/native/TestDynamicStore.java b/test/jdk/sun/security/krb5/config/native/TestDynamicStore.java new file mode 100644 --- /dev/null +++ b/test/jdk/sun/security/krb5/config/native/TestDynamicStore.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8257860 + * @summary SCDynamicStoreConfig works + * @modules java.security.jgss/sun.security.krb5 + * @library /test/lib + * @run main/manual/native TestDynamicStore + * @requires (os.family == "mac") + */ + +import jdk.test.lib.Asserts; +import sun.security.krb5.Config; + +public class TestDynamicStore { + + native static int actionInternal(char what, char whom); + + // what: 'a' for add, 'r' for remove + // whom: 'a' for all, 'r' for realm, 'm' for mapping + static int action(char what, char whom) throws Exception { + int out = actionInternal(what, whom); + System.out.println("Run " + what + whom + " " + out); + Thread.sleep(1000); // wait for callback called + return out; + } + + public static void main(String[] args) throws Exception { + + System.loadLibrary("TestDynamicStore"); + + Config cfg = Config.getInstance(); + if (cfg.exists("libdefaults") || cfg.exists("realms")) { + System.out.println("Already have krb5 config. Will not touch"); + return; + } + + try { + System.out.println("Fill in dynamic store"); + action('a', 'a'); + Asserts.assertTrue(Config.getInstance().get("libdefaults", "default_realm").equals("A.COM")); + Asserts.assertTrue(Config.getInstance().exists("domain_realm")); + + System.out.println("Remove mapping"); + action('r', 'm'); + Asserts.assertTrue(!Config.getInstance().exists("domain_realm")); + + System.out.println("Re-add mapping"); + action('a', 'm'); + Asserts.assertTrue(Config.getInstance().exists("domain_realm")); + + System.out.println("Remove realm info"); + action('r', 'r'); + // Realm info is not watched, so no change detected + Asserts.assertTrue(Config.getInstance().get("libdefaults", "default_realm").equals("A.COM")); + + System.out.println("Remove mapping"); + action('r', 'm'); + // But mapping is watched, so realm info is not re-read + Asserts.assertTrue(Config.getInstance().get("libdefaults", "default_realm").equals("B.COM")); + } finally { + System.out.println("Remove everything"); + action('r', 'a'); + Asserts.assertTrue(!Config.getInstance().exists("libdefault")); + } + } +} diff --git a/test/jdk/sun/security/krb5/config/native/libTestDynamicStore.m b/test/jdk/sun/security/krb5/config/native/libTestDynamicStore.m new file mode 100644 --- /dev/null +++ b/test/jdk/sun/security/krb5/config/native/libTestDynamicStore.m @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#import +#import +#import + +#define KERBEROS_DEFAULT_REALMS @"Kerberos-Default-Realms" +#define KERBEROS_DEFAULT_REALM_MAPPINGS @"Kerberos-Domain-Realm-Mappings" +#define KERBEROS_REALM_INFO @"Kerberos:%@" + +int removeAll(SCDynamicStoreRef store) { + fprintf(stderr, "%d\n", SCDynamicStoreRemoveValue(store, (CFStringRef) KERBEROS_DEFAULT_REALMS)); + fprintf(stderr, "%d\n", SCDynamicStoreRemoveValue(store, (CFStringRef) [NSString stringWithFormat:KERBEROS_REALM_INFO, @"A.COM"])); + fprintf(stderr, "%d\n", SCDynamicStoreRemoveValue(store, (CFStringRef) [NSString stringWithFormat:KERBEROS_REALM_INFO, @"B.COM"])); + fprintf(stderr, "%d\n", SCDynamicStoreRemoveValue(store, (CFStringRef) KERBEROS_DEFAULT_REALM_MAPPINGS)); + return 1; +} + +int removeRealm(SCDynamicStoreRef store) { + fprintf(stderr, "%d\n", SCDynamicStoreRemoveValue(store, (CFStringRef) [NSString stringWithFormat:KERBEROS_REALM_INFO, @"A.COM"])); + return 1; +} + +int removeMapping(SCDynamicStoreRef store) { + fprintf(stderr, "%d\n", SCDynamicStoreRemoveValue(store, (CFStringRef) KERBEROS_DEFAULT_REALM_MAPPINGS)); + return 1; +} + +int addMapping(SCDynamicStoreRef store) { + NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: + @"a", @"A", + @"b", @"B", + @"c", @"C", + @"d", @"D", + nil]; + fprintf(stderr, "%d\n", SCDynamicStoreSetValue(store, (CFStringRef) KERBEROS_DEFAULT_REALM_MAPPINGS, [NSArray arrayWithObjects: dict, nil])); + return 1; +} + +int addAll(SCDynamicStoreRef store) { + NSArray *keys = [NSArray arrayWithObjects:@"A.COM", @"B.COM", nil]; + fprintf(stderr, "%d\n", SCDynamicStoreSetValue(store, (CFStringRef) KERBEROS_DEFAULT_REALMS, keys)); + + NSDictionary *k1 = [NSDictionary dictionaryWithObjectsAndKeys: + @"kdc1.a.com", @"host", nil]; + NSDictionary *k2 = [NSDictionary dictionaryWithObjectsAndKeys: + @"kdc2.a.com", @"host", nil]; + NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: + [NSArray arrayWithObjects: k1, k2, nil], @"kdc", + nil]; + fprintf(stderr, "%d\n", SCDynamicStoreSetValue(store, (CFStringRef) [NSString stringWithFormat:KERBEROS_REALM_INFO, @"A.COM"], dict)); + + k1 = [NSDictionary dictionaryWithObjectsAndKeys: + @"kdc1.b.com", @"host", nil]; + k2 = [NSDictionary dictionaryWithObjectsAndKeys: + @"kdc2.b.com", @"host", nil]; + dict = [NSDictionary dictionaryWithObjectsAndKeys: + [NSArray arrayWithObjects: k1, k2, nil], @"kdc", + nil]; + fprintf(stderr, "%d\n", SCDynamicStoreSetValue(store, (CFStringRef) [NSString stringWithFormat:KERBEROS_REALM_INFO, @"B.COM"], dict)); + addMapping(store); + return 1; +} + +JNIEXPORT jint JNICALL Java_TestDynamicStore_actionInternal(JNIEnv *env, jclass clazz, jchar what, jchar whom) { + SCDynamicStoreRef store = SCDynamicStoreCreate(NULL, CFSTR("java-kerberos"), NULL, NULL); + fprintf(stderr, ">>> action: %c %c\n", what, whom); + @try { + switch (what) { + case 'a': + switch (whom) { + case 'a': return addAll(store); + case 'm': return addMapping(store); + } + break; + case 'r': + switch (whom) { + case 'a': return removeAll(store); + case 'r': return removeRealm(store); + case 'm': return removeMapping(store); + } + break; + } + return 0; + } @finally { + CFRelease(store); + } +} # HG changeset patch # User vkempik # Date 1618479257 -10800 # Thu Apr 15 12:34:17 2021 +0300 # Node ID f40019cd312be6990a0e3022a09c43a78477c822 # Parent 9ce80bd2884c6fc0e1a221ec46da98456f746ef5 8257853: Remove dependencies on JNF's JNI utility functions in AWT and 2D code diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m @@ -33,6 +33,7 @@ #import "GeomUtilities.h" #import "OSVersion.h" #import "ThreadUtilities.h" +#import "JNIUtilities.h" #import #import @@ -418,9 +419,9 @@ deltaY = [event scrollingDeltaY] * 0.1; } - static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent"); - static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDDI)V"); - jobject jEvent = JNFNewObject(env, jctor_NSEvent, + DECLARE_CLASS(jc_NSEvent, "sun/lwawt/macosx/NSEvent"); + DECLARE_METHOD(jctor_NSEvent, jc_NSEvent, "", "(IIIIIIIIDDI)V"); + jobject jEvent = (*env)->NewObject(env, jc_NSEvent, jctor_NSEvent, [event type], [event modifierFlags], clickCount, @@ -432,11 +433,12 @@ [AWTToolkit scrollStateWithEvent: event]); CHECK_NULL(jEvent); - static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView"); - static JNF_MEMBER_CACHE(jm_deliverMouseEvent, jc_PlatformView, "deliverMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V"); + DECLARE_CLASS(jc_PlatformView, "sun/lwawt/macosx/CPlatformView"); + DECLARE_METHOD(jm_deliverMouseEvent, jc_PlatformView, "deliverMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V"); jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); if (!(*env)->IsSameObject(env, jlocal, NULL)) { - JNFCallVoidMethod(env, jlocal, jm_deliverMouseEvent, jEvent); + (*env)->CallVoidMethod(env, jlocal, jm_deliverMouseEvent, jEvent); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jlocal); } (*env)->DeleteLocalRef(env, jEvent); @@ -488,9 +490,9 @@ charactersIgnoringModifiers = JNFNSToJavaString(env, [event charactersIgnoringModifiers]); } - static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent"); - static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IISLjava/lang/String;Ljava/lang/String;)V"); - jobject jEvent = JNFNewObject(env, jctor_NSEvent, + DECLARE_CLASS(jc_NSEvent, "sun/lwawt/macosx/NSEvent"); + DECLARE_METHOD(jctor_NSEvent, jc_NSEvent, "", "(IISLjava/lang/String;Ljava/lang/String;)V"); + jobject jEvent = (*env)->NewObject(env, jc_NSEvent, jctor_NSEvent, [event type], [event modifierFlags], [event keyCode], @@ -498,12 +500,13 @@ charactersIgnoringModifiers); CHECK_NULL(jEvent); - static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView"); - static JNF_MEMBER_CACHE(jm_deliverKeyEvent, jc_PlatformView, + DECLARE_CLASS(jc_PlatformView, "sun/lwawt/macosx/CPlatformView"); + DECLARE_METHOD(jm_deliverKeyEvent, jc_PlatformView, "deliverKeyEvent", "(Lsun/lwawt/macosx/NSEvent;)V"); jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); if (!(*env)->IsSameObject(env, jlocal, NULL)) { - JNFCallVoidMethod(env, jlocal, jm_deliverKeyEvent, jEvent); + (*env)->CallVoidMethod(env, jlocal, jm_deliverKeyEvent, jEvent); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jlocal); } if (characters != NULL) { @@ -518,12 +521,13 @@ jint w = (jint) rect.size.width; jint h = (jint) rect.size.height; JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_CLASS_CACHE(jc_PlatformView, "sun/lwawt/macosx/CPlatformView"); - static JNF_MEMBER_CACHE(jm_deliverResize, jc_PlatformView, "deliverResize", "(IIII)V"); + DECLARE_CLASS(jc_PlatformView, "sun/lwawt/macosx/CPlatformView"); + DECLARE_METHOD(jm_deliverResize, jc_PlatformView, "deliverResize", "(IIII)V"); jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); if (!(*env)->IsSameObject(env, jlocal, NULL)) { - JNFCallVoidMethod(env, jlocal, jm_deliverResize, x,y,w,h); + (*env)->CallVoidMethod(env, jlocal, jm_deliverResize, x,y,w,h); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jlocal); } } @@ -552,11 +556,12 @@ } } else { */ - static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView"); - static JNF_MEMBER_CACHE(jm_deliverWindowDidExposeEvent, jc_CPlatformView, "deliverWindowDidExposeEvent", "()V"); + DECLARE_CLASS(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView"); + DECLARE_METHOD(jm_deliverWindowDidExposeEvent, jc_CPlatformView, "deliverWindowDidExposeEvent", "()V"); jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); if (!(*env)->IsSameObject(env, jlocal, NULL)) { - JNFCallVoidMethod(env, jlocal, jm_deliverWindowDidExposeEvent); + (*env)->CallVoidMethod(env, jlocal, jm_deliverWindowDidExposeEvent); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jlocal); } /* @@ -591,8 +596,8 @@ // NSAccessibility support - (jobject)awtComponent:(JNIEnv*)env { - static JNF_CLASS_CACHE(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView"); - static JNF_MEMBER_CACHE(jf_Peer, jc_CPlatformView, "peer", "Lsun/lwawt/LWWindowPeer;"); + DECLARE_CLASS_RETURN(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView", NULL); + DECLARE_FIELD_RETURN(jf_Peer, jc_CPlatformView, "peer", "Lsun/lwawt/LWWindowPeer;", NULL); if ((env == NULL) || (m_cPlatformView == NULL)) { NSLog(@"Apple AWT : Error AWTView:awtComponent given bad parameters."); if (env != NULL) @@ -605,26 +610,28 @@ jobject peer = NULL; jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); if (!(*env)->IsSameObject(env, jlocal, NULL)) { - peer = JNFGetObjectField(env, jlocal, jf_Peer); + peer = (*env)->GetObjectField(env, jlocal, jf_Peer); (*env)->DeleteLocalRef(env, jlocal); } - static JNF_CLASS_CACHE(jc_LWWindowPeer, "sun/lwawt/LWWindowPeer"); - static JNF_MEMBER_CACHE(jf_Target, jc_LWWindowPeer, "target", "Ljava/awt/Component;"); + DECLARE_CLASS_RETURN(jc_LWWindowPeer, "sun/lwawt/LWWindowPeer", NULL); + DECLARE_FIELD_RETURN(jf_Target, jc_LWWindowPeer, "target", "Ljava/awt/Component;", NULL); if (peer == NULL) { NSLog(@"Apple AWT : Error AWTView:awtComponent got null peer from CPlatformView"); JNFDumpJavaStack(env); return NULL; } - jobject comp = JNFGetObjectField(env, peer, jf_Target); + jobject comp = (*env)->GetObjectField(env, peer, jf_Target); (*env)->DeleteLocalRef(env, peer); return comp; } + (AWTView *) awtView:(JNIEnv*)env ofAccessible:(jobject)jaccessible { - static JNF_STATIC_MEMBER_CACHE(jm_getAWTView, sjc_CAccessibility, "getAWTView", "(Ljavax/accessibility/Accessible;)J"); + DECLARE_CLASS_RETURN(sjc_CAccessibility, "sun/lwawt/macosx/CAccessibility", NULL); + DECLARE_STATIC_METHOD_RETURN(jm_getAWTView, sjc_CAccessibility, "getAWTView", "(Ljavax/accessibility/Accessible;)J", NULL); - jlong jptr = JNFCallStaticLongMethod(env, jm_getAWTView, jaccessible); + jlong jptr = (*env)->CallStaticLongMethod(env, sjc_CAccessibility, jm_getAWTView, jaccessible); + CHECK_EXCEPTION(); if (jptr == 0) return nil; return (AWTView *)jlong_to_ptr(jptr); @@ -950,7 +957,13 @@ /******************************** BEGIN NSTextInputClient Protocol ********************************/ -JNF_CLASS_CACHE(jc_CInputMethod, "sun/lwawt/macosx/CInputMethod"); +static jclass jc_CInputMethod = NULL; + +#define GET_CIM_CLASS() \ + GET_CLASS(jc_CInputMethod, "sun/lwawt/macosx/CInputMethod"); + +#define GET_CIM_CLASS_RETURN(ret) \ + GET_CLASS_RETURN(jc_CInputMethod, "sun/lwawt/macosx/CInputMethod", ret); - (void) insertText:(id)aString replacementRange:(NSRange)replacementRange { @@ -991,16 +1004,19 @@ if ([self hasMarkedText] || !fProcessingKeystroke || aStringIsComplex) { JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V"); + GET_CIM_CLASS(); + DECLARE_METHOD(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V"); // We need to select the previous glyph so that it is overwritten. if (fPAHNeedsToSelect) { - JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph); + (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph); + CHECK_EXCEPTION(); fPAHNeedsToSelect = NO; } - static JNF_MEMBER_CACHE(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V"); + DECLARE_METHOD(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V"); jstring insertedText = JNFNSToJavaString(env, useString); - JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); // AWT_THREADING Safe (AWTRunLoopMode) + (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, insertedText); // The input method event will create psuedo-key events for each character in the committed string. @@ -1055,16 +1071,18 @@ #ifdef IM_DEBUG fprintf(stderr, "AWTView InputMethod Selector Called : [setMarkedText] \"%s\", loc=%lu, length=%lu\n", [incomingString UTF8String], (unsigned long)selectionRange.location, (unsigned long)selectionRange.length); #endif // IM_DEBUG - static JNF_MEMBER_CACHE(jm_startIMUpdate, jc_CInputMethod, "startIMUpdate", "(Ljava/lang/String;)V"); - static JNF_MEMBER_CACHE(jm_addAttribute, jc_CInputMethod, "addAttribute", "(ZZII)V"); - static JNF_MEMBER_CACHE(jm_dispatchText, jc_CInputMethod, "dispatchText", "(IIZ)V"); JNIEnv *env = [ThreadUtilities getJNIEnv]; + GET_CIM_CLASS(); + DECLARE_METHOD(jm_startIMUpdate, jc_CInputMethod, "startIMUpdate", "(Ljava/lang/String;)V"); + DECLARE_METHOD(jm_addAttribute, jc_CInputMethod, "addAttribute", "(ZZII)V"); + DECLARE_METHOD(jm_dispatchText, jc_CInputMethod, "dispatchText", "(IIZ)V"); // NSInputContext already did the analysis of the TSM event and created attributes indicating // the underlining and color that should be done to the string. We need to look at the underline // style and color to determine what kind of Java hilighting needs to be done. jstring inProcessText = JNFNSToJavaString(env, incomingString); - JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_startIMUpdate, inProcessText); // AWT_THREADING Safe (AWTRunLoopMode) + (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_startIMUpdate, inProcessText); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, inProcessText); if (isAttributedString) { @@ -1087,20 +1105,24 @@ (NSColor *)[attributes objectForKey:NSUnderlineColorAttributeName]; isGray = !([underlineColorObj isEqual:[NSColor blackColor]]); - JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_addAttribute, isThickUnderline, isGray, effectiveRange.location, effectiveRange.length); // AWT_THREADING Safe (AWTRunLoopMode) + (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_addAttribute, isThickUnderline, + isGray, effectiveRange.location, effectiveRange.length); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); } } } - static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V"); + DECLARE_METHOD(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V"); // We need to select the previous glyph so that it is overwritten. if (fPAHNeedsToSelect) { - JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph); + (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_selectPreviousGlyph); + CHECK_EXCEPTION(); fPAHNeedsToSelect = NO; } - JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_dispatchText, selectionRange.location, selectionRange.length, JNI_FALSE); // AWT_THREADING Safe (AWTRunLoopMode) - + (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_dispatchText, + selectionRange.location, selectionRange.length, JNI_FALSE); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); // If the marked text is being cleared (zero-length string) don't handle the key event. if ([incomingString length] == 0) { fKeyEventsNeeded = NO; @@ -1118,10 +1140,11 @@ } // unmarkText cancels any input in progress and commits it to the text field. - static JNF_MEMBER_CACHE(jm_unmarkText, jc_CInputMethod, "unmarkText", "()V"); JNIEnv *env = [ThreadUtilities getJNIEnv]; - JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText); // AWT_THREADING Safe (AWTRunLoopMode) - + GET_CIM_CLASS(); + DECLARE_METHOD(jm_unmarkText, jc_CInputMethod, "unmarkText", "()V"); + (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); } - (BOOL) hasMarkedText @@ -1134,12 +1157,15 @@ return NO; } - static JNF_MEMBER_CACHE(jf_fCurrentText, jc_CInputMethod, "fCurrentText", "Ljava/text/AttributedString;"); - static JNF_MEMBER_CACHE(jf_fCurrentTextLength, jc_CInputMethod, "fCurrentTextLength", "I"); JNIEnv *env = [ThreadUtilities getJNIEnv]; - jobject currentText = JNFGetObjectField(env, fInputMethodLOCKABLE, jf_fCurrentText); + GET_CIM_CLASS_RETURN(NO); + DECLARE_FIELD_RETURN(jf_fCurrentText, jc_CInputMethod, "fCurrentText", "Ljava/text/AttributedString;", NO); + DECLARE_FIELD_RETURN(jf_fCurrentTextLength, jc_CInputMethod, "fCurrentTextLength", "I", NO); + jobject currentText = (*env)->GetObjectField(env, fInputMethodLOCKABLE, jf_fCurrentText); + CHECK_EXCEPTION(); - jint currentTextLength = JNFGetIntField(env, fInputMethodLOCKABLE, jf_fCurrentTextLength); + jint currentTextLength = (*env)->GetIntField(env, fInputMethodLOCKABLE, jf_fCurrentTextLength); + CHECK_EXCEPTION(); BOOL hasMarkedText = (currentText != NULL && currentTextLength > 0); @@ -1168,9 +1194,10 @@ fprintf(stderr, "AWTView InputMethod Selector Called : [attributedSubstringFromRange] location=%lu, length=%lu\n", (unsigned long)theRange.location, (unsigned long)theRange.length); #endif // IM_DEBUG - static JNF_MEMBER_CACHE(jm_substringFromRange, jc_CInputMethod, "attributedSubstringFromRange", "(II)Ljava/lang/String;"); JNIEnv *env = [ThreadUtilities getJNIEnv]; - jobject theString = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_substringFromRange, theRange.location, theRange.length); // AWT_THREADING Safe (AWTRunLoopMode) + DECLARE_METHOD_RETURN(jm_substringFromRange, jc_CInputMethod, "attributedSubstringFromRange", "(II)Ljava/lang/String;", nil); + jobject theString = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_substringFromRange, theRange.location, theRange.length); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION_NULL_RETURN(theString, nil); id result = [[[NSAttributedString alloc] initWithString:JNFJavaToNSString(env, theString)] autorelease]; #ifdef IM_DEBUG @@ -1195,14 +1222,16 @@ return NSMakeRange(NSNotFound, 0); } - static JNF_MEMBER_CACHE(jm_markedRange, jc_CInputMethod, "markedRange", "()[I"); JNIEnv *env = [ThreadUtilities getJNIEnv]; jarray array; jboolean isCopy; jint *_array; NSRange range = NSMakeRange(NSNotFound, 0); + GET_CIM_CLASS_RETURN(range); + DECLARE_METHOD_RETURN(jm_markedRange, jc_CInputMethod, "markedRange", "()[I", range); - array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_markedRange); // AWT_THREADING Safe (AWTRunLoopMode) + array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_markedRange); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); if (array) { _array = (*env)->GetIntArrayElements(env, array, &isCopy); @@ -1230,18 +1259,20 @@ return NSMakeRange(NSNotFound, 0); } - static JNF_MEMBER_CACHE(jm_selectedRange, jc_CInputMethod, "selectedRange", "()[I"); JNIEnv *env = [ThreadUtilities getJNIEnv]; jarray array; jboolean isCopy; jint *_array; NSRange range = NSMakeRange(NSNotFound, 0); + GET_CIM_CLASS_RETURN(range); + DECLARE_METHOD_RETURN(jm_selectedRange, jc_CInputMethod, "selectedRange", "()[I", range); #ifdef IM_DEBUG fprintf(stderr, "AWTView InputMethod Selector Called : [selectedRange]\n"); #endif // IM_DEBUG - array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_selectedRange); // AWT_THREADING Safe (AWTRunLoopMode) + array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_selectedRange); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); if (array) { _array = (*env)->GetIntArrayElements(env, array, &isCopy); if (_array != NULL) { @@ -1263,9 +1294,10 @@ return NSZeroRect; } - static JNF_MEMBER_CACHE(jm_firstRectForCharacterRange, jc_CInputMethod, - "firstRectForCharacterRange", "(I)[I"); JNIEnv *env = [ThreadUtilities getJNIEnv]; + GET_CIM_CLASS_RETURN(NSZeroRect); + DECLARE_METHOD_RETURN(jm_firstRectForCharacterRange, jc_CInputMethod, + "firstRectForCharacterRange", "(I)[I", NSZeroRect); jarray array; jboolean isCopy; jint *_array; @@ -1277,7 +1309,7 @@ (unsigned long)theRange.location, (unsigned long)theRange.length); #endif // IM_DEBUG - array = JNFCallObjectMethod(env, fInputMethodLOCKABLE, jm_firstRectForCharacterRange, + array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_firstRectForCharacterRange, theRange.location); // AWT_THREADING Safe (AWTRunLoopMode) _array = (*env)->GetIntArrayElements(env, array, &isCopy); @@ -1306,9 +1338,10 @@ return NSNotFound; } - static JNF_MEMBER_CACHE(jm_characterIndexForPoint, jc_CInputMethod, - "characterIndexForPoint", "(II)I"); JNIEnv *env = [ThreadUtilities getJNIEnv]; + GET_CIM_CLASS_RETURN(NSNotFound); + DECLARE_METHOD_RETURN(jm_characterIndexForPoint, jc_CInputMethod, + "characterIndexForPoint", "(II)I", NSNotFound); NSPoint flippedLocation = ConvertNSScreenPoint(env, thePoint); @@ -1316,7 +1349,9 @@ fprintf(stderr, "AWTView InputMethod Selector Called : [characterIndexForPoint:(NSPoint)thePoint] x=%f, y=%f\n", flippedLocation.x, flippedLocation.y); #endif // IM_DEBUG - jint index = JNFCallIntMethod(env, fInputMethodLOCKABLE, jm_characterIndexForPoint, (jint)flippedLocation.x, (jint)flippedLocation.y); // AWT_THREADING Safe (AWTRunLoopMode) + jint index = (*env)->CallIntMethod(env, fInputMethodLOCKABLE, jm_characterIndexForPoint, + (jint)flippedLocation.x, (jint)flippedLocation.y); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); #ifdef IM_DEBUG fprintf(stderr, "characterIndexForPoint returning %d\n", index); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m @@ -35,6 +35,7 @@ #import "AWTView.h" #import "GeomUtilities.h" #import "ThreadUtilities.h" +#import "JNIUtilities.h" #define MASK(KEY) \ (sun_lwawt_macosx_CPlatformWindow_ ## KEY) @@ -45,7 +46,12 @@ #define SET(BITS, KEY, VALUE) \ BITS = VALUE ? BITS | MASK(KEY) : BITS & ~MASK(KEY) -static JNF_CLASS_CACHE(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow"); +static jclass jc_CPlatformWindow = NULL; +#define GET_CPLATFORM_WINDOW_CLASS() \ + GET_CLASS(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow"); + +#define GET_CPLATFORM_WINDOW_CLASS_RETURN(ret) \ + GET_CLASS_RETURN(jc_CPlatformWindow, "sun/lwawt/macosx/CPlatformWindow", ret); // Cocoa windowDidBecomeKey/windowDidResignKey notifications // doesn't provide information about "opposite" window, so we @@ -113,17 +119,21 @@ jobject platformWindow = [((AWTWindow *)self.delegate).javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { // extract the target AWT Window object out of the CPlatformWindow - static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;"); - jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target); + GET_CPLATFORM_WINDOW_CLASS(); + DECLARE_FIELD(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;"); + jobject awtWindow = (*env)->GetObjectField(env, platformWindow, jf_target); if (awtWindow != NULL) { // translate the point into Java coordinates NSPoint loc = [event locationInWindow]; loc.y = [self frame].size.height - loc.y; // send up to the GestureHandler to recursively dispatch on the AWT event thread - static JNF_CLASS_CACHE(jc_GestureHandler, "com/apple/eawt/event/GestureHandler"); - static JNF_STATIC_MEMBER_CACHE(sjm_handleGestureFromNative, jc_GestureHandler, "handleGestureFromNative", "(Ljava/awt/Window;IDDDD)V"); - JNFCallStaticVoidMethod(env, sjm_handleGestureFromNative, awtWindow, type, (jdouble)loc.x, (jdouble)loc.y, (jdouble)a, (jdouble)b); + DECLARE_CLASS(jc_GestureHandler, "com/apple/eawt/event/GestureHandler"); + DECLARE_METHOD(sjm_handleGestureFromNative, jc_GestureHandler, + "handleGestureFromNative", "(Ljava/awt/Window;IDDDD)V"); + (*env)->CallStaticVoidMethod(env, jc_GestureHandler, sjm_handleGestureFromNative, + awtWindow, type, (jdouble)loc.x, (jdouble)loc.y, (jdouble)a, (jdouble)b); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, awtWindow); } (*env)->DeleteLocalRef(env, platformWindow); @@ -474,8 +484,10 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { - static JNF_MEMBER_CACHE(jm_isBlocked, jc_CPlatformWindow, "isBlocked", "()Z"); - isBlocked = JNFCallBooleanMethod(env, platformWindow, jm_isBlocked) == JNI_TRUE ? YES : NO; + GET_CPLATFORM_WINDOW_CLASS_RETURN(isBlocked); + DECLARE_METHOD_RETURN(jm_isBlocked, jc_CPlatformWindow, "isBlocked", "()Z", isBlocked); + isBlocked = (*env)->CallBooleanMethod(env, platformWindow, jm_isBlocked) == JNI_TRUE ? YES : NO; + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, platformWindow); } @@ -489,8 +501,10 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { - static JNF_MEMBER_CACHE(jm_isBlocked, jc_CPlatformWindow, "isSimpleWindowOwnedByEmbeddedFrame", "()Z"); - isSimpleWindowOwnedByEmbeddedFrame = JNFCallBooleanMethod(env, platformWindow, jm_isBlocked) == JNI_TRUE ? YES : NO; + GET_CPLATFORM_WINDOW_CLASS_RETURN(NO); + DECLARE_METHOD_RETURN(jm_isBlocked, jc_CPlatformWindow, "isSimpleWindowOwnedByEmbeddedFrame", "()Z", NO); + isSimpleWindowOwnedByEmbeddedFrame = (*env)->CallBooleanMethod(env, platformWindow, jm_isBlocked) == JNI_TRUE ? YES : NO; + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, platformWindow); } @@ -508,8 +522,10 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; jobject platformWindow = [awtWindow.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { - static JNF_MEMBER_CACHE(jm_isVisible, jc_CPlatformWindow, "isVisible", "()Z"); - isVisible = JNFCallBooleanMethod(env, platformWindow, jm_isVisible) == JNI_TRUE ? YES : NO; + GET_CPLATFORM_WINDOW_CLASS_RETURN(isVisible); + DECLARE_METHOD_RETURN(jm_isVisible, jc_CPlatformWindow, "isVisible", "()Z", isVisible) + isVisible = (*env)->CallBooleanMethod(env, platformWindow, jm_isVisible) == JNI_TRUE ? YES : NO; + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, platformWindow); } @@ -577,9 +593,10 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { - static JNF_MEMBER_CACHE(jm_checkBlockingAndOrder, jc_CPlatformWindow, - "checkBlockingAndOrder", "()Z"); - JNFCallBooleanMethod(env, platformWindow, jm_checkBlockingAndOrder); + GET_CPLATFORM_WINDOW_CLASS_RETURN(NO); + DECLARE_METHOD_RETURN(jm_checkBlockingAndOrder, jc_CPlatformWindow, "checkBlockingAndOrder", "()Z", NO); + (*env)->CallBooleanMethod(env, platformWindow, jm_checkBlockingAndOrder); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, platformWindow); } } @@ -610,13 +627,15 @@ NSRect frame = ConvertNSScreenRect(env, [self.nsWindow frame]); - static JNF_MEMBER_CACHE(jm_deliverMoveResizeEvent, jc_CPlatformWindow, "deliverMoveResizeEvent", "(IIIIZ)V"); - JNFCallVoidMethod(env, platformWindow, jm_deliverMoveResizeEvent, + GET_CPLATFORM_WINDOW_CLASS(); + DECLARE_METHOD(jm_deliverMoveResizeEvent, jc_CPlatformWindow, "deliverMoveResizeEvent", "(IIIIZ)V"); + (*env)->CallVoidMethod(env, platformWindow, jm_deliverMoveResizeEvent, (jint)frame.origin.x, (jint)frame.origin.y, (jint)frame.size.width, (jint)frame.size.height, (jboolean)[self.nsWindow inLiveResize]); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, platformWindow); [AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows]; @@ -681,8 +700,10 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { - static JNF_MEMBER_CACHE(jm_deliverIconify, jc_CPlatformWindow, "deliverIconify", "(Z)V"); - JNFCallVoidMethod(env, platformWindow, jm_deliverIconify, iconify); + GET_CPLATFORM_WINDOW_CLASS(); + DECLARE_METHOD(jm_deliverIconify, jc_CPlatformWindow, "deliverIconify", "(Z)V"); + (*env)->CallVoidMethod(env, platformWindow, jm_deliverIconify, iconify); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, platformWindow); } } @@ -695,8 +716,10 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { - static JNF_MEMBER_CACHE(jm_windowWillMiniaturize, jc_CPlatformWindow, "windowWillMiniaturize", "()V"); - JNFCallVoidMethod(env, platformWindow, jm_windowWillMiniaturize); + GET_CPLATFORM_WINDOW_CLASS(); + DECLARE_METHOD(jm_windowWillMiniaturize, jc_CPlatformWindow, "windowWillMiniaturize", "()V"); + (*env)->CallVoidMethod(env, platformWindow, jm_windowWillMiniaturize); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, platformWindow); } // Explicitly make myself a key window to avoid possible @@ -725,9 +748,10 @@ jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { jobject oppositeWindow = [opposite.javaPlatformWindow jObjectWithEnv:env]; - - static JNF_MEMBER_CACHE(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(ZLsun/lwawt/macosx/CPlatformWindow;)V"); - JNFCallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused, oppositeWindow); + 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); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, platformWindow); (*env)->DeleteLocalRef(env, oppositeWindow); } @@ -747,8 +771,10 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { - static JNF_MEMBER_CACHE(jm_windowDidBecomeMain, jc_CPlatformWindow, "windowDidBecomeMain", "()V"); - JNFCallVoidMethod(env, platformWindow, jm_windowDidBecomeMain); + GET_CPLATFORM_WINDOW_CLASS(); + DECLARE_METHOD(jm_windowDidBecomeMain, jc_CPlatformWindow, "windowDidBecomeMain", "()V"); + (*env)->CallVoidMethod(env, platformWindow, jm_windowDidBecomeMain); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, platformWindow); } } @@ -855,24 +881,28 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { - static JNF_MEMBER_CACHE(jm_deliverWindowClosingEvent, jc_CPlatformWindow, "deliverWindowClosingEvent", "()V"); - JNFCallVoidMethod(env, platformWindow, jm_deliverWindowClosingEvent); + GET_CPLATFORM_WINDOW_CLASS_RETURN(NO); + DECLARE_METHOD_RETURN(jm_deliverWindowClosingEvent, jc_CPlatformWindow, "deliverWindowClosingEvent", "()V", NO); + (*env)->CallVoidMethod(env, platformWindow, jm_deliverWindowClosingEvent); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, platformWindow); } // The window will be closed (if allowed) as result of sending Java event return NO; } - - (void)_notifyFullScreenOp:(jint)op withEnv:(JNIEnv *)env { - static JNF_CLASS_CACHE(jc_FullScreenHandler, "com/apple/eawt/FullScreenHandler"); - static JNF_STATIC_MEMBER_CACHE(jm_notifyFullScreenOperation, jc_FullScreenHandler, "handleFullScreenEventFromNative", "(Ljava/awt/Window;I)V"); - static JNF_MEMBER_CACHE(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;"); + DECLARE_CLASS(jc_FullScreenHandler, "com/apple/eawt/FullScreenHandler"); + DECLARE_STATIC_METHOD(jm_notifyFullScreenOperation, jc_FullScreenHandler, + "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]; if (platformWindow != NULL) { - jobject awtWindow = JNFGetObjectField(env, platformWindow, jf_target); + jobject awtWindow = (*env)->GetObjectField(env, platformWindow, jf_target); if (awtWindow != NULL) { - JNFCallStaticVoidMethod(env, jm_notifyFullScreenOperation, awtWindow, op); + (*env)->CallStaticVoidMethod(env, jc_FullScreenHandler, jm_notifyFullScreenOperation, awtWindow, op); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, awtWindow); } (*env)->DeleteLocalRef(env, platformWindow); @@ -881,22 +911,26 @@ - (void)windowWillEnterFullScreen:(NSNotification *)notification { - static JNF_MEMBER_CACHE(jm_windowWillEnterFullScreen, jc_CPlatformWindow, "windowWillEnterFullScreen", "()V"); JNIEnv *env = [ThreadUtilities getJNIEnv]; + GET_CPLATFORM_WINDOW_CLASS(); + DECLARE_METHOD(jm_windowWillEnterFullScreen, jc_CPlatformWindow, "windowWillEnterFullScreen", "()V"); jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { - JNFCallVoidMethod(env, platformWindow, jm_windowWillEnterFullScreen); + (*env)->CallVoidMethod(env, platformWindow, jm_windowWillEnterFullScreen); + CHECK_EXCEPTION(); [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_ENTER withEnv:env]; (*env)->DeleteLocalRef(env, platformWindow); } } - (void)windowDidEnterFullScreen:(NSNotification *)notification { - static JNF_MEMBER_CACHE(jm_windowDidEnterFullScreen, jc_CPlatformWindow, "windowDidEnterFullScreen", "()V"); JNIEnv *env = [ThreadUtilities getJNIEnv]; + GET_CPLATFORM_WINDOW_CLASS(); + DECLARE_METHOD(jm_windowDidEnterFullScreen, jc_CPlatformWindow, "windowDidEnterFullScreen", "()V"); jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { - JNFCallVoidMethod(env, platformWindow, jm_windowDidEnterFullScreen); + (*env)->CallVoidMethod(env, platformWindow, jm_windowDidEnterFullScreen); + CHECK_EXCEPTION(); [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_ENTER withEnv:env]; (*env)->DeleteLocalRef(env, platformWindow); } @@ -904,22 +938,31 @@ } - (void)windowWillExitFullScreen:(NSNotification *)notification { - static JNF_MEMBER_CACHE(jm_windowWillExitFullScreen, jc_CPlatformWindow, "windowWillExitFullScreen", "()V"); JNIEnv *env = [ThreadUtilities getJNIEnv]; + GET_CPLATFORM_WINDOW_CLASS(); + DECLARE_METHOD(jm_windowWillExitFullScreen, jc_CPlatformWindow, "windowWillExitFullScreen", "()V"); + if (jm_windowWillExitFullScreen == NULL) { + GET_CPLATFORM_WINDOW_CLASS(); + jm_windowWillExitFullScreen = (*env)->GetMethodID(env, jc_CPlatformWindow, "windowWillExitFullScreen", "()V"); + } + CHECK_NULL(jm_windowWillExitFullScreen); jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { - JNFCallVoidMethod(env, platformWindow, jm_windowWillExitFullScreen); + (*env)->CallVoidMethod(env, platformWindow, jm_windowWillExitFullScreen); + CHECK_EXCEPTION(); [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_WILL_EXIT withEnv:env]; (*env)->DeleteLocalRef(env, platformWindow); } } - (void)windowDidExitFullScreen:(NSNotification *)notification { - static JNF_MEMBER_CACHE(jm_windowDidExitFullScreen, jc_CPlatformWindow, "windowDidExitFullScreen", "()V"); JNIEnv *env = [ThreadUtilities getJNIEnv]; jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { - JNFCallVoidMethod(env, platformWindow, jm_windowDidExitFullScreen); + GET_CPLATFORM_WINDOW_CLASS(); + DECLARE_METHOD(jm_windowDidExitFullScreen, jc_CPlatformWindow, "windowDidExitFullScreen", "()V"); + (*env)->CallVoidMethod(env, platformWindow, jm_windowDidExitFullScreen); + CHECK_EXCEPTION(); [self _notifyFullScreenOp:com_apple_eawt_FullScreenHandler_FULLSCREEN_DID_EXIT withEnv:env]; (*env)->DeleteLocalRef(env, platformWindow); } @@ -935,8 +978,10 @@ JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { - static JNF_MEMBER_CACHE(jm_orderAboveSiblings, jc_CPlatformWindow, "orderAboveSiblings", "()V"); - JNFCallVoidMethod(env,platformWindow, jm_orderAboveSiblings); + GET_CPLATFORM_WINDOW_CLASS(); + DECLARE_METHOD(jm_orderAboveSiblings, jc_CPlatformWindow, "orderAboveSiblings", "()V"); + (*env)->CallVoidMethod(env,platformWindow, jm_orderAboveSiblings); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, platformWindow); } } @@ -953,8 +998,10 @@ jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env]; if (platformWindow != NULL) { // Currently, no need to deliver the whole NSEvent. - static JNF_MEMBER_CACHE(jm_deliverNCMouseDown, jc_CPlatformWindow, "deliverNCMouseDown", "()V"); - JNFCallVoidMethod(env, platformWindow, jm_deliverNCMouseDown); + GET_CPLATFORM_WINDOW_CLASS(); + DECLARE_METHOD(jm_deliverNCMouseDown, jc_CPlatformWindow, "deliverNCMouseDown", "()V"); + (*env)->CallVoidMethod(env, platformWindow, jm_deliverNCMouseDown); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, platformWindow); } } @@ -1173,9 +1220,9 @@ jint bottom = (jint)(contentRect.origin.y - frame.origin.y); jint right = (jint)(frame.size.width - (contentRect.size.width + left)); - static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets"); - static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V"); - ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right); + DECLARE_CLASS_RETURN(jc_Insets, "java/awt/Insets", NULL); + DECLARE_METHOD_RETURN(jc_Insets_ctor, jc_Insets, "", "(IIII)V", NULL); + ret = (*env)->NewObject(env, jc_Insets, jc_Insets_ctor, top, left, bottom, right); JNF_COCOA_EXIT(env); return ret; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m @@ -37,6 +37,7 @@ #import "CPopupMenu.h" #import "ThreadUtilities.h" #import "NSApplicationAWT.h" +#import "JNIUtilities.h" #pragma mark App Menu helpers @@ -243,9 +244,11 @@ BOOL prefsEnabled = (prefsAvailable && [self.fPreferencesMenu isEnabled] && ([self.fPreferencesMenu target] != nil)); JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_CLASS_CACHE(sjc_AppMenuBarHandler, "com/apple/eawt/_AppMenuBarHandler"); - static JNF_STATIC_MEMBER_CACHE(sjm_initMenuStates, sjc_AppMenuBarHandler, "initMenuStates", "(ZZZZ)V"); - JNFCallStaticVoidMethod(env, sjm_initMenuStates, aboutAvailable, aboutEnabled, prefsAvailable, prefsEnabled); + DECLARE_CLASS_RETURN(sjc_AppMenuBarHandler, "com/apple/eawt/_AppMenuBarHandler", NULL); + DECLARE_STATIC_METHOD_RETURN(sjm_initMenuStates, sjc_AppMenuBarHandler, "initMenuStates", "(ZZZZ)V", NULL); + (*env)->CallStaticVoidMethod(env, sjc_AppMenuBarHandler, sjm_initMenuStates, + aboutAvailable, aboutEnabled, prefsAvailable, prefsEnabled); + CHECK_EXCEPTION(); // register for the finish launching and system power off notifications by default NSNotificationCenter *ctr = [NSNotificationCenter defaultCenter]; @@ -272,7 +275,12 @@ #pragma mark Callbacks from AppKit -static JNF_CLASS_CACHE(sjc_AppEventHandler, "com/apple/eawt/_AppEventHandler"); +static jclass sjc_AppEventHandler = NULL; +#define GET_APPEVENTHANDLER_CLASS() \ + GET_CLASS(sjc_AppEventHandler, "com/apple/eawt/_AppEventHandler"); + +#define GET_APPEVENTHANDLER_CLASS_RETURN(ret) \ + GET_CLASS_RETURN(sjc_AppEventHandler, "com/apple/eawt/_AppEventHandler", ret); - (void)_handleOpenURLEvent:(NSAppleEventDescriptor *)openURLEvent withReplyEvent:(NSAppleEventDescriptor *)replyEvent { AWT_ASSERT_APPKIT_THREAD; @@ -283,8 +291,10 @@ //fprintf(stderr,"jm_handleOpenURL\n"); JNIEnv *env = [ThreadUtilities getJNIEnv]; jstring jURL = JNFNSToJavaString(env, url); - static JNF_STATIC_MEMBER_CACHE(jm_handleOpenURI, sjc_AppEventHandler, "handleOpenURI", "(Ljava/lang/String;)V"); - JNFCallStaticVoidMethod(env, jm_handleOpenURI, jURL); // AWT_THREADING Safe (event) + GET_APPEVENTHANDLER_CLASS(); + DECLARE_STATIC_METHOD(jm_handleOpenURI, sjc_AppEventHandler, "handleOpenURI", "(Ljava/lang/String;)V"); + (*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handleOpenURI, jURL); // AWT_THREADING Safe (event) + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jURL); [replyEvent insertDescriptor:[NSAppleEventDescriptor nullDescriptor] atIndex:0]; @@ -293,14 +303,22 @@ // Helper for both open file and print file methods // Creates a Java list of files from a native list of files - (jobject)_createFilePathArrayFrom:(NSArray *)filenames withEnv:(JNIEnv *)env { - static JNF_CLASS_CACHE(sjc_ArrayList, "java/util/ArrayList"); - static JNF_CTOR_CACHE(jm_ArrayList_ctor, sjc_ArrayList, "(I)V"); - static JNF_MEMBER_CACHE(jm_ArrayList_add, sjc_ArrayList, "add", "(Ljava/lang/Object;)Z"); + static jclass sjc_ArrayList = NULL; + if (sjc_ArrayList == NULL) { + sjc_ArrayList = (*env)->FindClass(env, "java/util/ArrayList"); + if (sjc_ArrayList != NULL) sjc_ArrayList = (*env)->NewGlobalRef(env, sjc_ArrayList); \ + } + CHECK_NULL_RETURN(sjc_ArrayList, NULL); + DECLARE_METHOD_RETURN(jm_ArrayList_ctor, sjc_ArrayList, "", "(I)V", NULL); + DECLARE_METHOD_RETURN(jm_ArrayList_add, sjc_ArrayList, "add", "(Ljava/lang/Object;)Z", NULL); - jobject jFileNamesArray = JNFNewObject(env, jm_ArrayList_ctor, (jint)[filenames count]); // AWT_THREADING Safe (known object) + jobject jFileNamesArray = (*env)->NewObject(env, sjc_ArrayList, jm_ArrayList_ctor, (jint)[filenames count]); // AWT_THREADING Safe (known object) + CHECK_EXCEPTION_NULL_RETURN(jFileNamesArray, NULL); + for (NSString *filename in filenames) { jstring jFileName = JNFNormalizedJavaStringForPath(env, filename); - JNFCallVoidMethod(env, jFileNamesArray, jm_ArrayList_add, jFileName); + (*env)->CallVoidMethod(env, jFileNamesArray, jm_ArrayList_add, jFileName); + CHECK_EXCEPTION(); } return jFileNamesArray; @@ -325,8 +343,11 @@ // convert the file names array jobject jFileNamesArray = [self _createFilePathArrayFrom:fileNames withEnv:env]; - static JNF_STATIC_MEMBER_CACHE(jm_handleOpenFiles, sjc_AppEventHandler, "handleOpenFiles", "(Ljava/util/List;Ljava/lang/String;)V"); - JNFCallStaticVoidMethod(env, jm_handleOpenFiles, jFileNamesArray, jSearchString); + GET_APPEVENTHANDLER_CLASS(); + DECLARE_STATIC_METHOD(jm_handleOpenFiles, sjc_AppEventHandler, + "handleOpenFiles", "(Ljava/util/List;Ljava/lang/String;)V"); + (*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handleOpenFiles, jFileNamesArray, jSearchString); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jFileNamesArray); (*env)->DeleteLocalRef(env, jSearchString); @@ -341,8 +362,11 @@ //fprintf(stderr,"jm_handlePrintFile\n"); JNIEnv *env = [ThreadUtilities getJNIEnv]; jobject jFileNamesArray = [self _createFilePathArrayFrom:fileNames withEnv:env]; - static JNF_STATIC_MEMBER_CACHE(jm_handlePrintFile, sjc_AppEventHandler, "handlePrintFiles", "(Ljava/util/List;)V"); - JNFCallStaticVoidMethod(env, jm_handlePrintFile, jFileNamesArray); // AWT_THREADING Safe (event) + GET_APPEVENTHANDLER_CLASS_RETURN(NSPrintingCancelled); + DECLARE_STATIC_METHOD_RETURN(jm_handlePrintFile, sjc_AppEventHandler, + "handlePrintFiles", "(Ljava/util/List;)V", NSPrintingCancelled); + (*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handlePrintFile, jFileNamesArray); // AWT_THREADING Safe (event) + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jFileNamesArray); return NSPrintingSuccess; @@ -354,8 +378,10 @@ //fprintf(stderr,"jm_handleOpenApplication\n"); JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_STATIC_MEMBER_CACHE(jm_handleNativeNotification, sjc_AppEventHandler, "handleNativeNotification", "(I)V"); - JNFCallStaticVoidMethod(env, jm_handleNativeNotification, notificationType); // AWT_THREADING Safe (event) + GET_APPEVENTHANDLER_CLASS(); + DECLARE_STATIC_METHOD(jm_handleNativeNotification, sjc_AppEventHandler, "handleNativeNotification", "(I)V"); + (*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handleNativeNotification, notificationType); // AWT_THREADING Safe (event) + CHECK_EXCEPTION(); } // About menu handler diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m @@ -25,7 +25,7 @@ #import "CDataTransferer.h" #import "ThreadUtilities.h" -#import "jni_util.h" +#import "JNIUtilities.h" #import #import @@ -88,18 +88,19 @@ if (self.changeCount != newChangeCount) { self.changeCount = newChangeCount; + JNIEnv *env = [ThreadUtilities getJNIEnv]; // Notify that the content might be changed - static JNF_CLASS_CACHE(jc_CClipboard, "sun/lwawt/macosx/CClipboard"); - static JNF_STATIC_MEMBER_CACHE(jm_contentChanged, jc_CClipboard, "notifyChanged", "()V"); - JNIEnv *env = [ThreadUtilities getJNIEnv]; - JNFCallStaticVoidMethod(env, jm_contentChanged); + DECLARE_CLASS(jc_CClipboard, "sun/lwawt/macosx/CClipboard"); + DECLARE_STATIC_METHOD(jm_contentChanged, jc_CClipboard, "notifyChanged", "()V"); + (*env)->CallStaticVoidMethod(env, jc_CClipboard, jm_contentChanged); + CHECK_EXCEPTION(); // If we have a Java pasteboard owner, tell it that it doesn't own the pasteboard anymore. - static JNF_MEMBER_CACHE(jm_lostOwnership, jc_CClipboard, "notifyLostOwnership", "()V"); + DECLARE_METHOD(jm_lostOwnership, jc_CClipboard, "notifyLostOwnership", "()V"); @synchronized(self) { if (self.clipboardOwner) { - JNIEnv *env = [ThreadUtilities getJNIEnv]; - JNFCallVoidMethod(env, self.clipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event) + (*env)->CallVoidMethod(env, self.clipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event) + CHECK_EXCEPTION(); JNFDeleteGlobalRef(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 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m @@ -38,6 +38,7 @@ #import "DnDUtilities.h" #import "ThreadUtilities.h" #import "LWCToolkit.h" +#import "JNIUtilities.h" // When sIsJavaDragging is true Java drag gesture has been recognized and a drag is/has been initialized. @@ -69,9 +70,17 @@ } @end -JNF_CLASS_CACHE(DataTransfererClass, "sun/awt/datatransfer/DataTransferer"); -JNF_CLASS_CACHE(CDragSourceContextPeerClass, "sun/lwawt/macosx/CDragSourceContextPeer"); -JNF_CLASS_CACHE(CImageClass, "sun/lwawt/macosx/CImage"); +static jclass DataTransfererClass = NULL; +static jclass CDragSourceContextPeerClass = NULL; + +#define GET_DT_CLASS() \ + GET_CLASS(DataTransfererClass, "sun/awt/datatransfer/DataTransferer"); + +#define GET_DT_CLASS_RETURN(ret) \ + GET_CLASS_RETURN(DataTransfererClass, "sun/awt/datatransfer/DataTransferer", ret); + +#define GET_DSCP_CLASS() \ + GET_CLASS(CDragSourceContextPeerClass, "sun/lwawt/macosx/CDragSourceContextPeer"); static NSDragOperation sDragOperation; static NSPoint sDraggingLocation; @@ -212,8 +221,11 @@ // - (jobject)dataTransferer:(JNIEnv*)env { - JNF_STATIC_MEMBER_CACHE(getInstanceMethod, DataTransfererClass, "getInstance", "()Lsun/awt/datatransfer/DataTransferer;"); - return JNFCallStaticObjectMethod(env, getInstanceMethod); + GET_DT_CLASS_RETURN(NULL); + DECLARE_STATIC_METHOD_RETURN(getInstanceMethod, DataTransfererClass, "getInstance", "()Lsun/awt/datatransfer/DataTransferer;", NULL); + jobject o = (*env)->CallStaticObjectMethod(env, DataTransfererClass, getInstanceMethod); + CHECK_EXCEPTION(); + return o; } // Appropriated from Windows' awt_DataTransferer.cpp: @@ -227,9 +239,11 @@ jbyteArray data = nil; if (transferer != NULL) { - JNF_MEMBER_CACHE(convertDataMethod, DataTransfererClass, "convertData", "(Ljava/lang/Object;Ljava/awt/datatransfer/Transferable;JLjava/util/Map;Z)[B"); - data = JNFCallObjectMethod(env, transferer, convertDataMethod, fComponent, fTransferable, format, fFormatMap, (jboolean) TRUE); + GET_DT_CLASS_RETURN(NULL); + DECLARE_METHOD_RETURN(convertDataMethod, DataTransfererClass, "convertData", "(Ljava/lang/Object;Ljava/awt/datatransfer/Transferable;JLjava/util/Map;Z)[B", NULL); + data = (*env)->CallObjectMethod(env, transferer, convertDataMethod, fComponent, fTransferable, format, fFormatMap, (jboolean) TRUE); } + CHECK_EXCEPTION(); return data; } @@ -555,11 +569,14 @@ } // DragSourceContextPeer.dragDropFinished() should be called even if there was an error: - JNF_MEMBER_CACHE(dragDropFinishedMethod, CDragSourceContextPeerClass, "dragDropFinished", "(ZIII)V"); + GET_DSCP_CLASS(); + DECLARE_METHOD(dragDropFinishedMethod, CDragSourceContextPeerClass, "dragDropFinished", "(ZIII)V"); DLog3(@" -> posting dragDropFinished, point %f, %f", point.x, point.y); - JNFCallVoidMethod(env, fDragSourceContextPeer, dragDropFinishedMethod, success, dragOp, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) - JNF_MEMBER_CACHE(resetHoveringMethod, CDragSourceContextPeerClass, "resetHovering", "()V"); - JNFCallVoidMethod(env, fDragSourceContextPeer, resetHoveringMethod); // Hust reset static variable + (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragDropFinishedMethod, success, dragOp, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + CHECK_EXCEPTION(); + DECLARE_METHOD(resetHoveringMethod, CDragSourceContextPeerClass, "resetHovering", "()V"); + (*env)->CallVoidMethod(env, fDragSourceContextPeer, resetHoveringMethod); // Hust reset static variable + CHECK_EXCEPTION(); } @finally { sNeedsEnter = NO; AWTToolkit.inDoDragDropLoop = NO; @@ -594,8 +611,10 @@ DLog3(@" -> posting operationChanged, point %f, %f", point.x, point.y); jint modifiedModifiers = fDragKeyModifiers | fDragMouseModifiers | [DnDUtilities javaKeyModifiersForNSDragOperation:dragOp]; - JNF_MEMBER_CACHE(operationChangedMethod, CDragSourceContextPeerClass, "operationChanged", "(IIII)V"); - JNFCallVoidMethod(env, fDragSourceContextPeer, operationChangedMethod, targetActions, modifiedModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + GET_DSCP_CLASS(); + DECLARE_METHOD(operationChangedMethod, CDragSourceContextPeerClass, "operationChanged", "(IIII)V"); + (*env)->CallVoidMethod(env, fDragSourceContextPeer, operationChangedMethod, targetActions, modifiedModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + CHECK_EXCEPTION(); } - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)localDrag { @@ -667,12 +686,14 @@ DLog4(@"[CDragSource draggedImage moved]: (%f, %f) %@\n", screenPoint.x, screenPoint.y, self); DLog3(@" -> posting dragMotion, point %f, %f", point.x, point.y); - JNF_MEMBER_CACHE(dragMotionMethod, CDragSourceContextPeerClass, "dragMotion", "(IIII)V"); - JNFCallVoidMethod(env, fDragSourceContextPeer, dragMotionMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) - + GET_DSCP_CLASS(); + DECLARE_METHOD(dragMotionMethod, CDragSourceContextPeerClass, "dragMotion", "(IIII)V"); + (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMotionMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + CHECK_EXCEPTION(); DLog3(@" -> posting dragMouseMoved, point %f, %f", point.x, point.y); - JNF_MEMBER_CACHE(dragMouseMovedMethod, CDragSourceContextPeerClass, "dragMouseMoved", "(IIII)V"); - JNFCallVoidMethod(env, fDragSourceContextPeer, dragMouseMovedMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + DECLARE_METHOD(dragMouseMovedMethod, CDragSourceContextPeerClass, "dragMouseMoved", "(IIII)V"); + (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMouseMovedMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + CHECK_EXCEPTION(); } JNF_COCOA_EXIT(env); } @@ -696,8 +717,10 @@ NSPoint point = [self mapNSScreenPointToJavaWithOffset:sDraggingLocation]; DLog3(@" -> posting dragEnter, point %f, %f", point.x, point.y); - JNF_MEMBER_CACHE(dragEnterMethod, CDragSourceContextPeerClass, "dragEnter", "(IIII)V"); - JNFCallVoidMethod(env, fDragSourceContextPeer, dragEnterMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + GET_DSCP_CLASS(); + DECLARE_METHOD(dragEnterMethod, CDragSourceContextPeerClass, "dragEnter", "(IIII)V"); + (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragEnterMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + CHECK_EXCEPTION(); } - (void) postDragExit { @@ -706,8 +729,11 @@ NSPoint point = [self mapNSScreenPointToJavaWithOffset:sDraggingLocation]; DLog3(@" -> posting dragExit, point %f, %f", point.x, point.y); - JNF_MEMBER_CACHE(dragExitMethod, CDragSourceContextPeerClass, "dragExit", "(II)V"); - JNFCallVoidMethod(env, fDragSourceContextPeer, dragExitMethod, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + GET_DSCP_CLASS(); + DECLARE_METHOD(dragExitMethod, CDragSourceContextPeerClass, "dragExit", "(II)V"); + (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragExitMethod, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + CHECK_EXCEPTION(); + } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m @@ -40,6 +40,7 @@ #import "CDataTransferer.h" #import "DnDUtilities.h" #import "ThreadUtilities.h" +#import "JNIUtilities.h" static NSInteger sDraggingSequenceNumber = -1; @@ -57,7 +58,12 @@ static CDropTarget* sCurrentDropTarget; -extern JNFClassInfo jc_CDropTargetContextPeer; +extern jclass jc_CDropTargetContextPeer; +#define GET_DTCP_CLASS() \ + GET_CLASS(jc_CDropTargetContextPeer, "sun/lwawt/macosx/CDropTargetContextPeer"); + +#define GET_DTCP_CLASS_RETURN(ret) \ + GET_CLASS_RETURN(jc_CDropTargetContextPeer, "sun/lwawt/macosx/CDropTargetContextPeer", ret); @implementation CDropTarget @@ -458,10 +464,13 @@ } // Look up the CDropTargetContextPeer class: - JNF_STATIC_MEMBER_CACHE(getDropTargetContextPeerMethod, jc_CDropTargetContextPeer, "getDropTargetContextPeer", "()Lsun/lwawt/macosx/CDropTargetContextPeer;"); + GET_DTCP_CLASS_RETURN(dragOp); + DECLARE_STATIC_METHOD_RETURN(getDropTargetContextPeerMethod, jc_CDropTargetContextPeer, + "getDropTargetContextPeer", "()Lsun/lwawt/macosx/CDropTargetContextPeer;", dragOp) if (sDraggingError == FALSE) { // Create a new drop target context peer: - jobject dropTargetContextPeer = JNFCallStaticObjectMethod(env, getDropTargetContextPeerMethod); + jobject dropTargetContextPeer = (*env)->CallStaticObjectMethod(env, jc_CDropTargetContextPeer, getDropTargetContextPeerMethod); + CHECK_EXCEPTION(); if (dropTargetContextPeer != nil) { fDropTargetContextPeer = JNFNewGlobalRef(env, dropTargetContextPeer); @@ -493,13 +502,16 @@ jlongArray formats = sDraggingFormats; - JNF_MEMBER_CACHE(handleEnterMessageMethod, jc_CDropTargetContextPeer, "handleEnterMessage", "(Ljava/awt/Component;IIII[JJ)I"); + GET_DTCP_CLASS_RETURN(dragOp); + DECLARE_METHOD_RETURN(handleEnterMessageMethod, jc_CDropTargetContextPeer, + "handleEnterMessage", "(Ljava/awt/Component;IIII[JJ)I", dragOp); if (sDraggingError == FALSE) { // Double-casting self gets rid of 'different size' compiler warning: // AWT_THREADING Safe (CToolkitThreadBlockedHandler) - actions = JNFCallIntMethod(env, fDropTargetContextPeer, handleEnterMessageMethod, + actions = (*env)->CallIntMethod(env, fDropTargetContextPeer, handleEnterMessageMethod, fComponent, (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); + CHECK_EXCEPTION(); } if (sDraggingError == FALSE) { @@ -578,10 +590,13 @@ jlongArray formats = sDraggingFormats; - JNF_MEMBER_CACHE(handleMotionMessageMethod, jc_CDropTargetContextPeer, "handleMotionMessage", "(Ljava/awt/Component;IIII[JJ)I"); + GET_DTCP_CLASS_RETURN(dragOp); + DECLARE_METHOD_RETURN(handleMotionMessageMethod, jc_CDropTargetContextPeer, "handleMotionMessage", "(Ljava/awt/Component;IIII[JJ)I", dragOp); if (sDraggingError == FALSE) { DLog3(@" >> posting handleMotionMessage, point %f, %f", javaLocation.x, javaLocation.y); - userAction = JNFCallIntMethod(env, fDropTargetContextPeer, handleMotionMessageMethod, fComponent, (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); // AWT_THREADING Safe (CToolkitThreadBlockedHandler) + userAction = (*env)->CallIntMethod(env, fDropTargetContextPeer, handleMotionMessageMethod, fComponent, + (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); // AWT_THREADING Safe (CToolkitThreadBlockedHandler) + CHECK_EXCEPTION(); } if (sDraggingError == FALSE) { @@ -608,12 +623,14 @@ JNIEnv* env = [ThreadUtilities getJNIEnv]; if (sDraggingExited == FALSE && sDraggingError == FALSE) { - JNF_MEMBER_CACHE(handleExitMessageMethod, jc_CDropTargetContextPeer, "handleExitMessage", "(Ljava/awt/Component;J)V"); + GET_DTCP_CLASS(); + DECLARE_METHOD(handleExitMessageMethod, jc_CDropTargetContextPeer, "handleExitMessage", "(Ljava/awt/Component;J)V"); if (sDraggingError == FALSE) { DLog3(@" - dragExit: loc native %f, %f\n", sDraggingLocation.x, sDraggingLocation.y); // AWT_THREADING Safe (CToolkitThreadBlockedHandler) - JNFCallVoidMethod(env, fDropTargetContextPeer, + (*env)->CallVoidMethod(env, fDropTargetContextPeer, handleExitMessageMethod, fComponent, ptr_to_jlong(self)); + CHECK_EXCEPTION(); } // 5-27-03 Note: [Radar 3270455] @@ -658,10 +675,13 @@ jlongArray formats = sDraggingFormats; - JNF_MEMBER_CACHE(handleDropMessageMethod, jc_CDropTargetContextPeer, "handleDropMessage", "(Ljava/awt/Component;IIII[JJ)V"); + GET_DTCP_CLASS_RETURN(NO); + DECLARE_METHOD_RETURN(handleDropMessageMethod, jc_CDropTargetContextPeer, "handleDropMessage", "(Ljava/awt/Component;IIII[JJ)V", NO); if (sDraggingError == FALSE) { - JNFCallVoidMethod(env, fDropTargetContextPeer, handleDropMessageMethod, fComponent, (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); // AWT_THREADING Safe (event) + (*env)->CallVoidMethod(env, fDropTargetContextPeer, handleDropMessageMethod, fComponent, + (jint) javaLocation.x, (jint) javaLocation.y, dropAction, actions, formats, ptr_to_jlong(self)); // AWT_THREADING Safe (event) + CHECK_EXCEPTION(); } } else { // 8-19-03 Note: [Radar 3368754] diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m @@ -31,14 +31,22 @@ #import "CDropTarget.h" #import "DnDUtilities.h" #import "ThreadUtilities.h" +#import "JNIUtilities.h" -JNF_CLASS_CACHE(jc_CDropTargetContextPeer, "sun/lwawt/macosx/CDropTargetContextPeer"); +jclass jc_CDropTargetContextPeer = NULL; +#define GET_DTCP_CLASS() \ + GET_CLASS(jc_CDropTargetContextPeer, "sun/lwawt/macosx/CDropTargetContextPeer"); + +#define GET_DTCP_CLASS_RETURN(ret) \ + GET_CLASS_RETURN(jc_CDropTargetContextPeer, "sun/lwawt/macosx/CDropTargetContextPeer", ret); static void TransferFailed(JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jdroptransfer, jlong jformat) { AWT_ASSERT_NOT_APPKIT_THREAD; - JNF_MEMBER_CACHE(transferFailedMethod, jc_CDropTargetContextPeer, "transferFailed", "(J)V"); - JNFCallVoidMethod(env, jthis, transferFailedMethod, jformat); // AWT_THREADING Safe (!appKit) + GET_DTCP_CLASS(); + DECLARE_METHOD(transferFailedMethod, jc_CDropTargetContextPeer, "transferFailed", "(J)V"); + (*env)->CallVoidMethod(env, jthis, transferFailedMethod, jformat); // AWT_THREADING Safe (!appKit) + CHECK_EXCEPTION(); } static CDropTarget* GetCDropTarget(jlong jdroptarget) { @@ -77,7 +85,8 @@ return result; } - JNF_MEMBER_CACHE(newDataMethod, jc_CDropTargetContextPeer, "newData", "(J[B)V"); + GET_DTCP_CLASS_RETURN(result); + DECLARE_METHOD_RETURN(newDataMethod, jc_CDropTargetContextPeer, "newData", "(J[B)V", result); if ((*env)->ExceptionOccurred(env) || !newDataMethod) { DLog2(@"[CDropTargetContextPeer startTransfer]: couldn't get newData method for %d.\n", (NSInteger) jdroptarget); TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat); @@ -94,7 +103,7 @@ // Pass the data to drop target: @try { - JNFCallVoidMethod(env, jthis, newDataMethod, jformat, jdropdata); // AWT_THREADING Safe (!appKit) + (*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); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m @@ -29,6 +29,7 @@ #import "CFileDialog.h" #import "ThreadUtilities.h" +#import "JNIUtilities.h" #import "java_awt_FileDialog.h" #import "sun_lwawt_macosx_CFileDialog.h" @@ -144,9 +145,10 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; jstring jString = JNFNormalizedJavaStringForPath(env, filename); - static JNF_CLASS_CACHE(jc_CFileDialog, "sun/lwawt/macosx/CFileDialog"); - static JNF_MEMBER_CACHE(jm_queryFF, jc_CFileDialog, "queryFilenameFilter", "(Ljava/lang/String;)Z"); - BOOL returnValue = JNFCallBooleanMethod(env, fFileDialog, jm_queryFF, jString); // AWT_THREADING Safe (AWTRunLoopMode) + DECLARE_CLASS_RETURN(jc_CFileDialog, "sun/lwawt/macosx/CFileDialog", NO); + DECLARE_METHOD_RETURN(jm_queryFF, jc_CFileDialog, "queryFilenameFilter", "(Ljava/lang/String;)Z", NO); + BOOL returnValue = (*env)->CallBooleanMethod(env, fFileDialog, jm_queryFF, jString); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jString); return returnValue; @@ -222,8 +224,8 @@ NSArray *urls = [dialogDelegate URLs]; jsize count = [urls count]; - static JNF_CLASS_CACHE(jc_String, "java/lang/String"); - returnValue = JNFNewObjectArray(env, &jc_String, count); + DECLARE_CLASS_RETURN(jc_String, "java/lang/String", NULL); + returnValue = (*env)->NewObjectArray(env, count, jc_String, NULL); [urls enumerateObjectsUsingBlock:^(id url, NSUInteger index, BOOL *stop) { jstring filename = JNFNormalizedJavaStringForPath(env, [url path]); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m @@ -26,6 +26,7 @@ #import "LWCToolkit.h" #import "ThreadUtilities.h" #include "GeomUtilities.h" +#include "JNIUtilities.h" #import @@ -159,9 +160,10 @@ w = CGDisplayModeGetWidth(mode); CFRelease(currentBPP); } - static JNF_CLASS_CACHE(jc_DisplayMode, "java/awt/DisplayMode"); - static JNF_CTOR_CACHE(jc_DisplayMode_ctor, jc_DisplayMode, "(IIII)V"); - ret = JNFNewObject(env, jc_DisplayMode_ctor, w, h, bpp, refrate); + DECLARE_CLASS_RETURN(jc_DisplayMode, "java/awt/DisplayMode", ret); + DECLARE_METHOD_RETURN(jc_DisplayMode_ctor, jc_DisplayMode, "", "(IIII)V", ret); + ret = (*env)->NewObject(env, jc_DisplayMode, jc_DisplayMode_ctor, w, h, bpp, refrate); + CHECK_EXCEPTION(); JNF_COCOA_EXIT(env); return ret; } @@ -252,9 +254,9 @@ jint left = visibleFrame.origin.x - frame.origin.x; jint right = frame.size.width - visibleFrame.size.width - left; - static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets"); - static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V"); - ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right); + DECLARE_CLASS_RETURN(jc_Insets, "java/awt/Insets", ret); + DECLARE_METHOD_RETURN(jc_Insets_ctor, jc_Insets, "", "(IIII)V", ret); + ret = (*env)->NewObject(env, jc_Insets, jc_Insets_ctor, top, left, bottom, right); JNF_COCOA_EXIT(env); @@ -327,9 +329,9 @@ CFArrayRef allModes = getAllValidDisplayModes(displayID); CFIndex numModes = allModes ? CFArrayGetCount(allModes): 0; - static JNF_CLASS_CACHE(jc_DisplayMode, "java/awt/DisplayMode"); + DECLARE_CLASS_RETURN(jc_DisplayMode, "java/awt/DisplayMode", NULL); - jreturnArray = JNFNewObjectArray(env, &jc_DisplayMode, (jsize) numModes); + jreturnArray = (*env)->NewObjectArray(env, (jsize)numModes, jc_DisplayMode, NULL); if (!jreturnArray) { NSLog(@"CGraphicsDevice can't create java array of DisplayMode objects"); return nil; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m @@ -25,7 +25,7 @@ #import "AWT_debug.h" -#import "jni_util.h" +#import "JNIUtilities.h" #import "ThreadUtilities.h" #import @@ -74,7 +74,8 @@ } /* Allocate a java array for display identifiers */ - ret = JNFNewIntArray(env, displayActiveCount); + ret = (*env)->NewIntArray(env, displayActiveCount); + CHECK_NULL_RETURN(ret, NULL); /* Initialize and return the backing int array */ assert(sizeof(jint) >= sizeof(CGDirectDisplayID)); @@ -122,12 +123,13 @@ jobject graphicsEnv = [wrapper jObjectWithEnv:env]; if (graphicsEnv == NULL) return; // ref already GC'd - static JNF_CLASS_CACHE(jc_CGraphicsEnvironment, "sun/awt/CGraphicsEnvironment"); - static JNF_MEMBER_CACHE(jm_displayReconfiguration, + DECLARE_CLASS(jc_CGraphicsEnvironment, "sun/awt/CGraphicsEnvironment"); + DECLARE_METHOD(jm_displayReconfiguration, jc_CGraphicsEnvironment, "_displayReconfiguration","(IZ)V"); - JNFCallVoidMethod(env, graphicsEnv, jm_displayReconfiguration, + (*env)->CallVoidMethod(env, graphicsEnv, jm_displayReconfiguration, (jint) display, (jboolean) flags & kCGDisplayRemoveFlag); (*env)->DeleteLocalRef(env, graphicsEnv); + CHECK_EXCEPTION(); }); }]; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m @@ -405,8 +405,8 @@ } count = [sortedPixelSizes count]; - static JNF_CLASS_CACHE(jc_Dimension, "java/awt/Dimension"); - jreturnArray = JNFNewObjectArray(env, &jc_Dimension, count); + DECLARE_CLASS_RETURN(jc_Dimension, "java/awt/Dimension", jreturnArray); + jreturnArray = (*env)->NewObjectArray(env, count, jc_Dimension, NULL); CHECK_NULL_RETURN(jreturnArray, NULL); for(i = 0; i < count; i++){ diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m @@ -30,6 +30,7 @@ #import "sun_lwawt_macosx_CInputMethodDescriptor.h" #import "ThreadUtilities.h" #import "AWTView.h" +#import "JNIUtilities.h" #import #import @@ -37,20 +38,13 @@ #define JAVA_LIST @"JAVA_LIST" #define CURRENT_KB_DESCRIPTION @"CURRENT_KB_DESCRIPTION" -static JNF_CLASS_CACHE(jc_localeClass, "java/util/Locale"); -static JNF_CTOR_CACHE(jm_localeCons, jc_localeClass, "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); -static JNF_CLASS_CACHE(jc_arrayListClass, "java/util/ArrayList"); -static JNF_CTOR_CACHE(jm_arrayListCons, jc_arrayListClass, "()V"); -static JNF_MEMBER_CACHE(jm_listAdd, jc_arrayListClass, "add", "(Ljava/lang/Object;)Z"); -static JNF_MEMBER_CACHE(jm_listContains, jc_arrayListClass, "contains", "(Ljava/lang/Object;)Z"); - - - // // NOTE: This returns a JNI Local Ref. Any code that calls must call DeleteLocalRef with the return value. // static jobject CreateLocaleObjectFromNSString(JNIEnv *env, NSString *name) { + DECLARE_CLASS_RETURN(jc_localeClass, "java/util/Locale", NULL); + DECLARE_METHOD_RETURN(jm_localeCons, jc_localeClass, "", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", NULL); // Break apart the string into its components. // First, duplicate the NSString into a C string, since we're going to modify it. char * language = strdup([name UTF8String]); @@ -77,8 +71,9 @@ if(ctryObj != NULL) { jobject vrntObj = (*env)->NewStringUTF(env, variant); if (vrntObj != NULL) { - localeObj = JNFNewObject(env, jm_localeCons,langObj, ctryObj, + localeObj = (*env)->NewObject(env, jc_localeClass, jm_localeCons,langObj, ctryObj, vrntObj); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, vrntObj); } (*env)->DeleteLocalRef(env, ctryObj); @@ -295,6 +290,11 @@ JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CInputMethodDescriptor_nativeGetAvailableLocales (JNIEnv *env, jclass klass) { + DECLARE_CLASS_RETURN(jc_arrayListClass, "java/util/ArrayList", NULL); + DECLARE_METHOD_RETURN(jm_arrayListCons, jc_arrayListClass, "", "()V", NULL); + DECLARE_METHOD_RETURN(jm_listAdd, jc_arrayListClass, "add", "(Ljava/lang/Object;)Z", NULL); + DECLARE_METHOD_RETURN(jm_listContains, jc_arrayListClass, "contains", "(Ljava/lang/Object;)Z", NULL); + if (!inputMethodController) return NULL; jobject returnValue = 0; @@ -309,7 +309,8 @@ if (selectableArray == nil) return NULL; // Create an ArrayList to return back to the caller. - returnValue = JNFNewObject(env, jm_arrayListCons); + returnValue = (*env)->NewObject(env, jc_arrayListClass, jm_arrayListCons); + CHECK_EXCEPTION_NULL_RETURN(returnValue, NULL); for(NSString *locale in selectableArray) { jobject localeObj = CreateLocaleObjectFromNSString(env, locale); @@ -317,9 +318,11 @@ break; } - if (JNFCallBooleanMethod(env, returnValue, jm_listContains, localeObj) == JNI_FALSE) { - JNFCallBooleanMethod(env, returnValue, jm_listAdd, localeObj); + if ((*env)->CallBooleanMethod(env, returnValue, jm_listContains, localeObj) == JNI_FALSE) { + if ((*env)->ExceptionOccurred(env)) (*env)->ExceptionClear(env); + (*env)->CallBooleanMethod(env, returnValue, jm_listAdd, localeObj); } + if ((*env)->ExceptionOccurred(env)) (*env)->ExceptionClear(env); (*env)->DeleteLocalRef(env, localeObj); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuItem.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuItem.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuItem.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuItem.m @@ -30,6 +30,7 @@ #import "AWTEvent.h" #import "AWTWindow.h" #import "ThreadUtilities.h" +#import "JNIUtilities.h" #import "java_awt_Event.h" #import "java_awt_event_KeyEvent.h" @@ -82,14 +83,14 @@ // means we have to handle it here. NSEvent *currEvent = [[NSApplication sharedApplication] currentEvent]; if (fIsCheckbox) { - static JNF_CLASS_CACHE(jc_CCheckboxMenuItem, "sun/lwawt/macosx/CCheckboxMenuItem"); - static JNF_MEMBER_CACHE(jm_ckHandleAction, jc_CCheckboxMenuItem, "handleAction", "(Z)V"); + DECLARE_CLASS(jc_CCheckboxMenuItem, "sun/lwawt/macosx/CCheckboxMenuItem"); + DECLARE_METHOD(jm_ckHandleAction, jc_CCheckboxMenuItem, "handleAction", "(Z)V"); // Send the opposite of what's currently checked -- the action // indicates what state we're going to. NSInteger state = [sender state]; jboolean newState = (state == NSOnState ? JNI_FALSE : JNI_TRUE); - JNFCallVoidMethod(env, fPeer, jm_ckHandleAction, newState); + (*env)->CallVoidMethod(env, fPeer, jm_ckHandleAction, newState); } else { if ([currEvent type] == NSKeyDown) { @@ -120,14 +121,15 @@ } } - static JNF_CLASS_CACHE(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem"); - static JNF_MEMBER_CACHE(jm_handleAction, jc_CMenuItem, "handleAction", "(JI)V"); // AWT_THREADING Safe (event) + DECLARE_CLASS(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem"); + DECLARE_METHOD(jm_handleAction, jc_CMenuItem, "handleAction", "(JI)V"); // AWT_THREADING Safe (event) NSUInteger modifiers = [currEvent modifierFlags]; jint javaModifiers = NsKeyModifiersToJavaModifiers(modifiers, NO); - JNFCallVoidMethod(env, fPeer, jm_handleAction, UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event) + (*env)->CallVoidMethod(env, fPeer, jm_handleAction, UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event) } + CHECK_EXCEPTION(); JNF_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m @@ -36,13 +36,29 @@ #import "PrintModel.h" #import "ThreadUtilities.h" #import "GeomUtilities.h" +#import "JNIUtilities.h" -static JNF_CLASS_CACHE(sjc_Paper, "java/awt/print/Paper"); -static JNF_CLASS_CACHE(sjc_PageFormat, "java/awt/print/PageFormat"); -static JNF_CLASS_CACHE(sjc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob"); -static JNF_CLASS_CACHE(sjc_CPrinterDialog, "sun/lwawt/macosx/CPrinterDialog"); -static JNF_MEMBER_CACHE(sjm_getNSPrintInfo, sjc_CPrinterJob, "getNSPrintInfo", "()J"); -static JNF_MEMBER_CACHE(sjm_printerJob, sjc_CPrinterDialog, "fPrinterJob", "Lsun/lwawt/macosx/CPrinterJob;"); +static jclass sjc_Paper = NULL; +static jclass sjc_PageFormat = NULL; +static jclass sjc_CPrinterJob = NULL; +static jclass sjc_CPrinterDialog = NULL; +static jmethodID sjm_getNSPrintInfo = NULL; +static jmethodID sjm_printerJob = NULL; + +#define GET_PAPER_CLASS() GET_CLASS(sjc_Paper, "java/awt/print/Paper"); +#define GET_PAGEFORMAT_CLASS() GET_CLASS(sjc_PageFormat, "java/awt/print/PageFormat"); +#define GET_CPRINTERDIALOG_CLASS() GET_CLASS(sjc_CPrinterDialog, "sun/lwawt/macosx/CPrinterDialog"); +#define GET_CPRINTERDIALOG_CLASS_RETURN(ret) GET_CLASS_RETURN(sjc_CPrinterDialog, "sun/lwawt/macosx/CPrinterDialog", ret); +#define GET_CPRINTERJOB_CLASS() GET_CLASS(sjc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob"); +#define GET_CPRINTERJOB_CLASS_RETURN(ret) GET_CLASS_RETURN(sjc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob", ret); + +#define GET_NSPRINTINFO_METHOD_RETURN(ret) \ + GET_CPRINTERJOB_CLASS_RETURN(ret); \ + GET_METHOD_RETURN(sjm_getNSPrintInfo, sjc_CPrinterJob, "getNSPrintInfo", "()J", ret); + +#define GET_CPRINTERDIALOG_METHOD_RETURN(ret) \ + GET_CPRINTERDIALOG_CLASS_RETURN(ret); \ + GET_METHOD_RETURN(sjm_printerJob, sjc_CPrinterDialog, "fPrinterJob", "Lsun/lwawt/macosx/CPrinterJob;", ret); static NSPrintInfo* createDefaultNSPrintInfo(); @@ -140,8 +156,10 @@ static void nsPrintInfoToJavaPaper(JNIEnv* env, NSPrintInfo* src, jobject dst) { - static JNF_MEMBER_CACHE(jm_setSize, sjc_Paper, "setSize", "(DD)V"); - static JNF_MEMBER_CACHE(jm_setImageableArea, sjc_Paper, "setImageableArea", "(DDDD)V"); + GET_PAGEFORMAT_CLASS(); + GET_PAPER_CLASS(); + DECLARE_METHOD(jm_setSize, sjc_Paper, "setSize", "(DD)V"); + DECLARE_METHOD(jm_setImageableArea, sjc_Paper, "setImageableArea", "(DDDD)V"); jdouble jPaperW, jPaperH; @@ -167,7 +185,8 @@ break; } - JNFCallVoidMethod(env, dst, jm_setSize, jPaperW, jPaperH); // AWT_THREADING Safe (known object - always actual Paper) + (*env)->CallVoidMethod(env, dst, jm_setSize, jPaperW, jPaperH); // AWT_THREADING Safe (known object - always actual Paper) + CHECK_EXCEPTION(); // Set the imageable area from the margins CGFloat leftM = [src leftMargin]; @@ -180,35 +199,44 @@ jdouble jImageW = jPaperW - (leftM + rightM); jdouble jImageH = jPaperH - (topM + bottomM); - JNFCallVoidMethod(env, dst, jm_setImageableArea, jImageX, jImageY, jImageW, jImageH); // AWT_THREADING Safe (known object - always actual Paper) + (*env)->CallVoidMethod(env, dst, jm_setImageableArea, jImageX, jImageY, jImageW, jImageH); // AWT_THREADING Safe (known object - always actual Paper) + CHECK_EXCEPTION(); } static void javaPaperToNSPrintInfo(JNIEnv* env, jobject src, NSPrintInfo* dst) { AWT_ASSERT_NOT_APPKIT_THREAD; - static JNF_MEMBER_CACHE(jm_getWidth, sjc_Paper, "getWidth", "()D"); - static JNF_MEMBER_CACHE(jm_getHeight, sjc_Paper, "getHeight", "()D"); - static JNF_MEMBER_CACHE(jm_getImageableX, sjc_Paper, "getImageableX", "()D"); - static JNF_MEMBER_CACHE(jm_getImageableY, sjc_Paper, "getImageableY", "()D"); - static JNF_MEMBER_CACHE(jm_getImageableW, sjc_Paper, "getImageableWidth", "()D"); - static JNF_MEMBER_CACHE(jm_getImageableH, sjc_Paper, "getImageableHeight", "()D"); + GET_PAGEFORMAT_CLASS(); + GET_PAPER_CLASS(); + DECLARE_METHOD(jm_getWidth, sjc_Paper, "getWidth", "()D"); + DECLARE_METHOD(jm_getHeight, sjc_Paper, "getHeight", "()D"); + DECLARE_METHOD(jm_getImageableX, sjc_Paper, "getImageableX", "()D"); + DECLARE_METHOD(jm_getImageableY, sjc_Paper, "getImageableY", "()D"); + DECLARE_METHOD(jm_getImageableW, sjc_Paper, "getImageableWidth", "()D"); + DECLARE_METHOD(jm_getImageableH, sjc_Paper, "getImageableHeight", "()D"); // java Paper is always Portrait oriented. Set NSPrintInfo with this // rectangle, and it's orientation may change. If necessary, be sure to call // -[NSPrintInfo setOrientation] after this call, which will then // adjust the -[NSPrintInfo paperSize] as well. - jdouble jPhysicalWidth = JNFCallDoubleMethod(env, src, jm_getWidth); // AWT_THREADING Safe (!appKit) - jdouble jPhysicalHeight = JNFCallDoubleMethod(env, src, jm_getHeight); // AWT_THREADING Safe (!appKit) + jdouble jPhysicalWidth = (*env)->CallDoubleMethod(env, src, jm_getWidth); // AWT_THREADING Safe (!appKit) + CHECK_EXCEPTION(); + jdouble jPhysicalHeight = (*env)->CallDoubleMethod(env, src, jm_getHeight); // AWT_THREADING Safe (!appKit) + CHECK_EXCEPTION(); [dst setPaperSize:NSMakeSize(jPhysicalWidth, jPhysicalHeight)]; // Set the margins from the imageable area - jdouble jImageX = JNFCallDoubleMethod(env, src, jm_getImageableX); // AWT_THREADING Safe (!appKit) - jdouble jImageY = JNFCallDoubleMethod(env, src, jm_getImageableY); // AWT_THREADING Safe (!appKit) - jdouble jImageW = JNFCallDoubleMethod(env, src, jm_getImageableW); // AWT_THREADING Safe (!appKit) - jdouble jImageH = JNFCallDoubleMethod(env, src, jm_getImageableH); // AWT_THREADING Safe (!appKit) + jdouble jImageX = (*env)->CallDoubleMethod(env, src, jm_getImageableX); // AWT_THREADING Safe (!appKit) + CHECK_EXCEPTION(); + jdouble jImageY = (*env)->CallDoubleMethod(env, src, jm_getImageableY); // AWT_THREADING Safe (!appKit) + CHECK_EXCEPTION(); + jdouble jImageW = (*env)->CallDoubleMethod(env, src, jm_getImageableW); // AWT_THREADING Safe (!appKit) + CHECK_EXCEPTION(); + jdouble jImageH = (*env)->CallDoubleMethod(env, src, jm_getImageableH); // AWT_THREADING Safe (!appKit) + CHECK_EXCEPTION(); [dst setLeftMargin:(CGFloat)jImageX]; [dst setTopMargin:(CGFloat)jImageY]; @@ -220,9 +248,12 @@ { AWT_ASSERT_NOT_APPKIT_THREAD; - static JNF_MEMBER_CACHE(jm_setOrientation, sjc_PageFormat, "setOrientation", "(I)V"); - static JNF_MEMBER_CACHE(jm_setPaper, sjc_PageFormat, "setPaper", "(Ljava/awt/print/Paper;)V"); - static JNF_CTOR_CACHE(jm_Paper_ctor, sjc_Paper, "()V"); + GET_CPRINTERJOB_CLASS(); + GET_PAGEFORMAT_CLASS(); + GET_PAPER_CLASS(); + DECLARE_METHOD(jm_setOrientation, sjc_PageFormat, "setOrientation", "(I)V"); + DECLARE_METHOD(jm_setPaper, sjc_PageFormat, "setPaper", "(Ljava/awt/print/Paper;)V"); + DECLARE_METHOD(jm_Paper_ctor, sjc_Paper, "", "()V"); jint jOrientation; switch ([src orientation]) { @@ -246,15 +277,21 @@ break; } - JNFCallVoidMethod(env, dst, jm_setOrientation, jOrientation); // AWT_THREADING Safe (!appKit) + (*env)->CallVoidMethod(env, dst, jm_setOrientation, jOrientation); // AWT_THREADING Safe (!appKit) + CHECK_EXCEPTION(); // Create a new Paper - jobject paper = JNFNewObject(env, jm_Paper_ctor); // AWT_THREADING Safe (known object) + jobject paper = (*env)->NewObject(env, sjc_Paper, jm_Paper_ctor); // AWT_THREADING Safe (known object) + CHECK_EXCEPTION(); + if (paper == NULL) { + return; + } nsPrintInfoToJavaPaper(env, src, paper); // Set the Paper in the PageFormat - JNFCallVoidMethod(env, dst, jm_setPaper, paper); // AWT_THREADING Safe (!appKit) + (*env)->CallVoidMethod(env, dst, jm_setPaper, paper); // AWT_THREADING Safe (!appKit) + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, paper); } @@ -263,9 +300,12 @@ { AWT_ASSERT_NOT_APPKIT_THREAD; - static JNF_MEMBER_CACHE(jm_getOrientation, sjc_PageFormat, "getOrientation", "()I"); - static JNF_MEMBER_CACHE(jm_getPaper, sjc_PageFormat, "getPaper", "()Ljava/awt/print/Paper;"); - static JNF_MEMBER_CACHE(jm_getPrinterName, sjc_CPrinterJob, "getPrinterName", "()Ljava/lang/String;"); + GET_CPRINTERJOB_CLASS(); + GET_PAGEFORMAT_CLASS(); + GET_PAPER_CLASS(); + DECLARE_METHOD(jm_getOrientation, sjc_PageFormat, "getOrientation", "()I"); + DECLARE_METHOD(jm_getPaper, sjc_PageFormat, "getPaper", "()Ljava/awt/print/Paper;"); + DECLARE_METHOD(jm_getPrinterName, sjc_CPrinterJob, "getPrinterName", "()Ljava/lang/String;"); // When setting page information (orientation, size) in NSPrintInfo, set the // rectangle first. This is because setting the orientation will change the @@ -274,11 +314,12 @@ // Set up the paper. This will force Portrait since java Paper is // not oriented. Then setting the NSPrintInfo orientation below // will flip NSPrintInfo's info as necessary. - jobject paper = JNFCallObjectMethod(env, srcPageFormat, jm_getPaper); // AWT_THREADING Safe (!appKit) + jobject paper = (*env)->CallObjectMethod(env, srcPageFormat, jm_getPaper); // AWT_THREADING Safe (!appKit) + CHECK_EXCEPTION(); javaPaperToNSPrintInfo(env, paper, dstPrintInfo); (*env)->DeleteLocalRef(env, paper); - switch (JNFCallIntMethod(env, srcPageFormat, jm_getOrientation)) { // AWT_THREADING Safe (!appKit) + switch ((*env)->CallIntMethod(env, srcPageFormat, jm_getOrientation)) { // AWT_THREADING Safe (!appKit) case java_awt_print_PageFormat_PORTRAIT: [dstPrintInfo setOrientation:NS_PORTRAIT]; break; @@ -296,11 +337,13 @@ [dstPrintInfo setOrientation:NS_PORTRAIT]; break; } + CHECK_EXCEPTION(); // NSPrinterInfo is not correctly set to the selected printer // from the Java side of CPrinterJob. Has always assumed the default printer was the one we wanted. if (srcPrintJob == NULL) return; - jobject printerNameObj = JNFCallObjectMethod(env, srcPrintJob, jm_getPrinterName); + jobject printerNameObj = (*env)->CallObjectMethod(env, srcPrintJob, jm_getPrinterName); + CHECK_EXCEPTION(); if (printerNameObj == NULL) return; NSString *printerName = JNFJavaToNSString(env, printerNameObj); if (printerName == nil) return; @@ -311,29 +354,32 @@ static void nsPrintInfoToJavaPrinterJob(JNIEnv* env, NSPrintInfo* src, jobject dstPrinterJob, jobject dstPageable) { - static JNF_MEMBER_CACHE(jm_setService, sjc_CPrinterJob, "setPrinterServiceFromNative", "(Ljava/lang/String;)V"); - static JNF_MEMBER_CACHE(jm_setCopiesAttribute, sjc_CPrinterJob, "setCopiesAttribute", "(I)V"); - static JNF_MEMBER_CACHE(jm_setCollated, sjc_CPrinterJob, "setCollated", "(Z)V"); - static JNF_MEMBER_CACHE(jm_setPageRangeAttribute, sjc_CPrinterJob, "setPageRangeAttribute", "(IIZ)V"); + GET_CPRINTERJOB_CLASS(); + DECLARE_METHOD(jm_setService, sjc_CPrinterJob, "setPrinterServiceFromNative", "(Ljava/lang/String;)V"); + DECLARE_METHOD(jm_setCopiesAttribute, sjc_CPrinterJob, "setCopiesAttribute", "(I)V"); + DECLARE_METHOD(jm_setCollated, sjc_CPrinterJob, "setCollated", "(Z)V"); + DECLARE_METHOD(jm_setPageRangeAttribute, sjc_CPrinterJob, "setPageRangeAttribute", "(IIZ)V"); // get the selected printer's name, and set the appropriate PrintService on the Java side NSString *name = [[src printer] name]; jstring printerName = JNFNSToJavaString(env, name); - JNFCallVoidMethod(env, dstPrinterJob, jm_setService, printerName); - + (*env)->CallVoidMethod(env, dstPrinterJob, jm_setService, printerName); + CHECK_EXCEPTION(); NSMutableDictionary* printingDictionary = [src dictionary]; NSNumber* nsCopies = [printingDictionary objectForKey:NSPrintCopies]; if ([nsCopies respondsToSelector:@selector(integerValue)]) { - JNFCallVoidMethod(env, dstPrinterJob, jm_setCopiesAttribute, [nsCopies integerValue]); // AWT_THREADING Safe (known object) + (*env)->CallVoidMethod(env, dstPrinterJob, jm_setCopiesAttribute, [nsCopies integerValue]); // AWT_THREADING Safe (known object) + CHECK_EXCEPTION(); } NSNumber* nsCollated = [printingDictionary objectForKey:NSPrintMustCollate]; if ([nsCollated respondsToSelector:@selector(boolValue)]) { - JNFCallVoidMethod(env, dstPrinterJob, jm_setCollated, [nsCollated boolValue] ? JNI_TRUE : JNI_FALSE); // AWT_THREADING Safe (known object) + (*env)->CallVoidMethod(env, dstPrinterJob, jm_setCollated, [nsCollated boolValue] ? JNI_TRUE : JNI_FALSE); // AWT_THREADING Safe (known object) + CHECK_EXCEPTION(); } NSNumber* nsPrintAllPages = [printingDictionary objectForKey:NSPrintAllPages]; @@ -356,9 +402,9 @@ } isRangeSet = true; } - JNFCallVoidMethod(env, dstPrinterJob, jm_setPageRangeAttribute, - jFirstPage, jLastPage, isRangeSet); - // AWT_THREADING Safe (known object) + (*env)->CallVoidMethod(env, dstPrinterJob, jm_setPageRangeAttribute, + jFirstPage, jLastPage, isRangeSet); // AWT_THREADING Safe (known object) + CHECK_EXCEPTION(); } } @@ -367,27 +413,32 @@ { AWT_ASSERT_NOT_APPKIT_THREAD; - static JNF_CLASS_CACHE(jc_Pageable, "java/awt/print/Pageable"); - static JNF_MEMBER_CACHE(jm_getCopies, sjc_CPrinterJob, "getCopiesInt", "()I"); - static JNF_MEMBER_CACHE(jm_isCollated, sjc_CPrinterJob, "isCollated", "()Z"); - static JNF_MEMBER_CACHE(jm_getFromPage, sjc_CPrinterJob, "getFromPageAttrib", "()I"); - static JNF_MEMBER_CACHE(jm_getToPage, sjc_CPrinterJob, "getToPageAttrib", "()I"); - static JNF_MEMBER_CACHE(jm_getMinPage, sjc_CPrinterJob, "getMinPageAttrib", "()I"); - static JNF_MEMBER_CACHE(jm_getMaxPage, sjc_CPrinterJob, "getMaxPageAttrib", "()I"); - static JNF_MEMBER_CACHE(jm_getSelectAttrib, sjc_CPrinterJob, "getSelectAttrib", "()I"); - static JNF_MEMBER_CACHE(jm_getNumberOfPages, jc_Pageable, "getNumberOfPages", "()I"); - static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormatFromAttributes", "()Ljava/awt/print/PageFormat;"); + DECLARE_CLASS(jc_Pageable, "java/awt/print/Pageable"); + DECLARE_METHOD(jm_getCopies, sjc_CPrinterJob, "getCopiesInt", "()I"); + DECLARE_METHOD(jm_isCollated, sjc_CPrinterJob, "isCollated", "()Z"); + DECLARE_METHOD(jm_getFromPage, sjc_CPrinterJob, "getFromPageAttrib", "()I"); + DECLARE_METHOD(jm_getToPage, sjc_CPrinterJob, "getToPageAttrib", "()I"); + DECLARE_METHOD(jm_getMinPage, sjc_CPrinterJob, "getMinPageAttrib", "()I"); + DECLARE_METHOD(jm_getMaxPage, sjc_CPrinterJob, "getMaxPageAttrib", "()I"); + DECLARE_METHOD(jm_getSelectAttrib, sjc_CPrinterJob, "getSelectAttrib", "()I"); + DECLARE_METHOD(jm_getNumberOfPages, jc_Pageable, "getNumberOfPages", "()I"); + DECLARE_METHOD(jm_getPageFormat, sjc_CPrinterJob, "getPageFormatFromAttributes", "()Ljava/awt/print/PageFormat;"); NSMutableDictionary* printingDictionary = [dst dictionary]; - jint copies = JNFCallIntMethod(env, srcPrinterJob, jm_getCopies); // AWT_THREADING Safe (known object) + jint copies = (*env)->CallIntMethod(env, srcPrinterJob, jm_getCopies); // AWT_THREADING Safe (known object) + CHECK_EXCEPTION(); [printingDictionary setObject:[NSNumber numberWithInteger:copies] forKey:NSPrintCopies]; - jboolean collated = JNFCallBooleanMethod(env, srcPrinterJob, jm_isCollated); // AWT_THREADING Safe (known object) + jboolean collated = (*env)->CallBooleanMethod(env, srcPrinterJob, jm_isCollated); // AWT_THREADING Safe (known object) + CHECK_EXCEPTION(); [printingDictionary setObject:[NSNumber numberWithBool:collated ? YES : NO] forKey:NSPrintMustCollate]; - jint selectID = JNFCallIntMethod(env, srcPrinterJob, jm_getSelectAttrib); - jint fromPage = JNFCallIntMethod(env, srcPrinterJob, jm_getFromPage); - jint toPage = JNFCallIntMethod(env, srcPrinterJob, jm_getToPage); + jint selectID = (*env)->CallIntMethod(env, srcPrinterJob, jm_getSelectAttrib); + CHECK_EXCEPTION(); + jint fromPage = (*env)->CallIntMethod(env, srcPrinterJob, jm_getFromPage); + CHECK_EXCEPTION(); + jint toPage = (*env)->CallIntMethod(env, srcPrinterJob, jm_getToPage); + CHECK_EXCEPTION(); if (selectID ==0) { [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintAllPages]; } else if (selectID == 2) { @@ -396,8 +447,10 @@ [printingDictionary setObject:[NSNumber numberWithBool:NO] forKey:NSPrintAllPages]; [printingDictionary setObject:[NSNumber numberWithBool:YES] forKey:NSPrintSelectionOnly]; } else { - jint minPage = JNFCallIntMethod(env, srcPrinterJob, jm_getMinPage); - jint maxPage = JNFCallIntMethod(env, srcPrinterJob, jm_getMaxPage); + jint minPage = (*env)->CallIntMethod(env, srcPrinterJob, jm_getMinPage); + CHECK_EXCEPTION(); + jint maxPage = (*env)->CallIntMethod(env, srcPrinterJob, jm_getMaxPage); + CHECK_EXCEPTION(); // for PD_SELECTION or PD_NOSELECTION, check from/to page // to determine which radio button to select @@ -412,7 +465,8 @@ [printingDictionary setObject:[NSNumber numberWithInteger:fromPage] forKey:NSPrintFirstPage]; [printingDictionary setObject:[NSNumber numberWithInteger:toPage] forKey:NSPrintLastPage]; - jobject page = JNFCallObjectMethod(env, srcPrinterJob, jm_getPageFormat); + jobject page = (*env)->CallObjectMethod(env, srcPrinterJob, jm_getPageFormat); + CHECK_EXCEPTION(); if (page != NULL) { javaPageFormatToNSPrintInfo(env, NULL, page, dst); } @@ -461,6 +515,7 @@ { JNF_COCOA_ENTER(env); + NSPrintInfo* printInfo = createDefaultNSPrintInfo(env, NULL); javaPaperToNSPrintInfo(env, origpaper, printInfo); makeBestFit(printInfo); @@ -519,26 +574,32 @@ { AWT_ASSERT_NOT_APPKIT_THREAD; - static JNF_MEMBER_CACHE(jm_getPageFormat, sjc_CPrinterJob, "getPageFormat", "(I)Ljava/awt/print/PageFormat;"); - static JNF_MEMBER_CACHE(jm_getPageFormatArea, sjc_CPrinterJob, "getPageFormatArea", "(Ljava/awt/print/PageFormat;)Ljava/awt/geom/Rectangle2D;"); - static JNF_MEMBER_CACHE(jm_getPrinterName, sjc_CPrinterJob, "getPrinterName", "()Ljava/lang/String;"); - static JNF_MEMBER_CACHE(jm_getPageable, sjc_CPrinterJob, "getPageable", "()Ljava/awt/print/Pageable;"); - static JNF_MEMBER_CACHE(jm_getPrinterTray, sjc_CPrinterJob, "getPrinterTray", "()Ljava/lang/String;"); + GET_CPRINTERJOB_CLASS_RETURN(NO); + DECLARE_METHOD_RETURN(jm_getPageFormat, sjc_CPrinterJob, "getPageFormat", "(I)Ljava/awt/print/PageFormat;", NO); + DECLARE_METHOD_RETURN(jm_getPageFormatArea, sjc_CPrinterJob, "getPageFormatArea", "(Ljava/awt/print/PageFormat;)Ljava/awt/geom/Rectangle2D;", NO); + DECLARE_METHOD_RETURN(jm_getPrinterName, sjc_CPrinterJob, "getPrinterName", "()Ljava/lang/String;", NO); + DECLARE_METHOD_RETURN(jm_getPageable, sjc_CPrinterJob, "getPageable", "()Ljava/awt/print/Pageable;", NO); + DECLARE_METHOD_RETURN(jm_getPrinterTray, sjc_CPrinterJob, "getPrinterTray", "()Ljava/lang/String;", NO); jboolean retVal = JNI_FALSE; JNF_COCOA_ENTER(env); // Get the first page's PageFormat for setting things up (This introduces // and is a facet of the same problem in Radar 2818593/2708932). - jobject page = JNFCallObjectMethod(env, jthis, jm_getPageFormat, 0); // AWT_THREADING Safe (!appKit) + jobject page = (*env)->CallObjectMethod(env, jthis, jm_getPageFormat, 0); // AWT_THREADING Safe (!appKit) + CHECK_EXCEPTION(); if (page != NULL) { - jobject pageFormatArea = JNFCallObjectMethod(env, jthis, jm_getPageFormatArea, page); // AWT_THREADING Safe (!appKit) + jobject pageFormatArea = (*env)->CallObjectMethod(env, jthis, jm_getPageFormatArea, page); // AWT_THREADING Safe (!appKit) + CHECK_EXCEPTION(); PrinterView* printerView = [[PrinterView alloc] initWithFrame:JavaToNSRect(env, pageFormatArea) withEnv:env withPrinterJob:jthis]; [printerView setFirstPage:firstPage lastPage:lastPage]; - NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(JNFCallLongMethod(env, jthis, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object) - jobject printerTrayObj = JNFCallObjectMethod(env, jthis, jm_getPrinterTray); + GET_NSPRINTINFO_METHOD_RETURN(NO) + NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr((*env)->CallLongMethod(env, jthis, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object) + CHECK_EXCEPTION(); + jobject printerTrayObj = (*env)->CallObjectMethod(env, jthis, jm_getPrinterTray); + CHECK_EXCEPTION(); if (printerTrayObj != NULL) { NSString *printerTray = JNFJavaToNSString(env, printerTrayObj); if (printerTray != nil) { @@ -551,7 +612,8 @@ // NSPrinterInfo is not correctly set to the selected printer // from the Java side of CPrinterJob. Had always assumed the default printer was the one we wanted. - jobject printerNameObj = JNFCallObjectMethod(env, jthis, jm_getPrinterName); + jobject printerNameObj = (*env)->CallObjectMethod(env, jthis, jm_getPrinterName); + CHECK_EXCEPTION(); if (printerNameObj != NULL) { NSString *printerName = JNFJavaToNSString(env, printerNameObj); if (printerName != nil) { @@ -561,7 +623,7 @@ } // JTable.print attributes are ignored - jobject pageable = JNFCallObjectMethod(env, jthis, jm_getPageable); // AWT_THREADING Safe (!appKit) + jobject pageable = (*env)->CallObjectMethod(env, jthis, jm_getPageable); // AWT_THREADING Safe (!appKit) javaPrinterJobToNSPrintInfo(env, jthis, pageable, printInfo); PrintModel* printModel = [[PrintModel alloc] initWithPrintInfo:printInfo]; @@ -597,15 +659,20 @@ (JNIEnv *env, jobject jthis) { - static JNF_CLASS_CACHE(jc_CPrinterPageDialog, "sun/lwawt/macosx/CPrinterPageDialog"); - static JNF_MEMBER_CACHE(jm_page, jc_CPrinterPageDialog, "fPage", "Ljava/awt/print/PageFormat;"); + DECLARE_CLASS_RETURN(jc_CPrinterPageDialog, "sun/lwawt/macosx/CPrinterPageDialog", NO); + DECLARE_FIELD_RETURN(jm_page, jc_CPrinterPageDialog, "fPage", "Ljava/awt/print/PageFormat;", NO); jboolean result = JNI_FALSE; JNF_COCOA_ENTER(env); - jobject printerJob = JNFGetObjectField(env, jthis, sjm_printerJob); - NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(JNFCallLongMethod(env, printerJob, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object) + GET_CPRINTERDIALOG_METHOD_RETURN(NO); + GET_NSPRINTINFO_METHOD_RETURN(NO) + jobject printerJob = (*env)->GetObjectField(env, jthis, sjm_printerJob); + if (printerJob == NULL) return NO; + NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr((*env)->CallLongMethod(env, printerJob, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object) + if (printInfo == NULL) return result; - jobject page = JNFGetObjectField(env, jthis, jm_page); + jobject page = (*env)->GetObjectField(env, jthis, jm_page); + if (page == NULL) return NO; // passing NULL, because only a CPrinterJob has a real printer associated with it javaPageFormatToNSPrintInfo(env, NULL, page, printInfo); @@ -641,15 +708,19 @@ JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CPrinterJobDialog_showDialog (JNIEnv *env, jobject jthis) { - static JNF_CLASS_CACHE(jc_CPrinterJobDialog, "sun/lwawt/macosx/CPrinterJobDialog"); - static JNF_MEMBER_CACHE(jm_pageable, jc_CPrinterJobDialog, "fPageable", "Ljava/awt/print/Pageable;"); + DECLARE_CLASS_RETURN(jc_CPrinterJobDialog, "sun/lwawt/macosx/CPrinterJobDialog", NO); + DECLARE_FIELD_RETURN(jm_pageable, jc_CPrinterJobDialog, "fPageable", "Ljava/awt/print/Pageable;", NO); jboolean result = JNI_FALSE; JNF_COCOA_ENTER(env); - jobject printerJob = JNFGetObjectField(env, jthis, sjm_printerJob); - NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(JNFCallLongMethod(env, printerJob, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object) + GET_CPRINTERDIALOG_METHOD_RETURN(NO); + jobject printerJob = (*env)->GetObjectField(env, jthis, sjm_printerJob); + if (printerJob == NULL) return NO; + GET_NSPRINTINFO_METHOD_RETURN(NO) + NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr((*env)->CallLongMethod(env, printerJob, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object) - jobject pageable = JNFGetObjectField(env, jthis, jm_pageable); + jobject pageable = (*env)->GetObjectField(env, jthis, jm_pageable); + if (pageable == NULL) return NO; javaPrinterJobToNSPrintInfo(env, printerJob, pageable, printInfo); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m @@ -32,6 +32,7 @@ #import #import "ThreadUtilities.h" +#import "JNIUtilities.h" NSColor **sColors = nil; NSColor **appleColors = nil; @@ -46,8 +47,6 @@ JNF_COCOA_EXIT(env); } -static JNF_CLASS_CACHE(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit"); -static JNF_STATIC_MEMBER_CACHE(jm_systemColorsChanged, jc_LWCToolkit, "systemColorsChanged", "()V"); + (void)systemColorsDidChange:(NSNotification *)notification { AWT_ASSERT_APPKIT_THREAD; @@ -57,7 +56,11 @@ // Call LWCToolkit with the news. LWCToolkit makes certain to do its duties // from a new thread. JNIEnv* env = [ThreadUtilities getJNIEnv]; - JNFCallStaticVoidMethod(env, jm_systemColorsChanged); // AWT_THREADING Safe (event) + DECLARE_CLASS(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit"); + DECLARE_STATIC_METHOD(jm_systemColorsChanged, jc_LWCToolkit, "systemColorsChanged", "()V"); + (*env)->CallStaticVoidMethod(env, jc_LWCToolkit, jm_systemColorsChanged); // AWT_THREADING Safe (event) + CHECK_EXCEPTION(); + } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTextPipe.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTextPipe.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTextPipe.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTextPipe.m @@ -35,6 +35,7 @@ #import "CoreTextSupport.h" #import "QuartzSurfaceData.h" #include "AWTStrike.h" +#import "JNIUtilities.h" static const CGAffineTransform sInverseTX = { 1, 0, 0, -1, 0, 0 }; @@ -322,7 +323,8 @@ -----------------------------------*/ -static JNF_CLASS_CACHE(jc_StandardGlyphVector, "sun/font/StandardGlyphVector"); +static jclass jc_StandardGlyphVector = NULL; +#define GET_SGV_CLASS() GET_CLASS(jc_StandardGlyphVector, "sun/font/StandardGlyphVector"); // Checks the GlyphVector Java object for any transforms that were applied to individual characters. If none are present, // strike the glyphs immediately in Core Graphics. Otherwise, obtain the arrays, and defer to above. @@ -330,8 +332,9 @@ (JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, jobject gVector, BOOL useSubstituion, int *uniChars, CGGlyph *glyphs, CGSize *advances, size_t length) { // if we have no character substitution, and no per-glyph transformations - strike now! - static JNF_MEMBER_CACHE(jm_StandardGlyphVector_gti, jc_StandardGlyphVector, "gti", "Lsun/font/StandardGlyphVector$GlyphTransformInfo;"); - jobject gti = JNFGetObjectField(env, gVector, jm_StandardGlyphVector_gti); + GET_SGV_CLASS(); + DECLARE_FIELD(jm_StandardGlyphVector_gti, jc_StandardGlyphVector, "gti", "Lsun/font/StandardGlyphVector$GlyphTransformInfo;"); + jobject gti = (*env)->GetObjectField(env, gVector, jm_StandardGlyphVector_gti); if (gti == 0) { if (useSubstituion) @@ -347,9 +350,9 @@ return; } - static JNF_CLASS_CACHE(jc_StandardGlyphVector_GlyphTransformInfo, "sun/font/StandardGlyphVector$GlyphTransformInfo"); - static JNF_MEMBER_CACHE(jm_StandardGlyphVector_GlyphTransformInfo_transforms, jc_StandardGlyphVector_GlyphTransformInfo, "transforms", "[D"); - jdoubleArray g_gtiTransformsArray = JNFGetObjectField(env, gti, jm_StandardGlyphVector_GlyphTransformInfo_transforms); //(*env)->GetObjectField(env, gti, g_gtiTransforms); + DECLARE_CLASS(jc_StandardGlyphVector_GlyphTransformInfo, "sun/font/StandardGlyphVector$GlyphTransformInfo"); + DECLARE_FIELD(jm_StandardGlyphVector_GlyphTransformInfo_transforms, jc_StandardGlyphVector_GlyphTransformInfo, "transforms", "[D"); + jdoubleArray g_gtiTransformsArray = (*env)->GetObjectField(env, gti, jm_StandardGlyphVector_GlyphTransformInfo_transforms); //(*env)->GetObjectField(env, gti, g_gtiTransforms); if (g_gtiTransformsArray == NULL) { return; } @@ -359,8 +362,8 @@ return; } - static JNF_MEMBER_CACHE(jm_StandardGlyphVector_GlyphTransformInfo_indices, jc_StandardGlyphVector_GlyphTransformInfo, "indices", "[I"); - jintArray g_gtiTXIndicesArray = JNFGetObjectField(env, gti, jm_StandardGlyphVector_GlyphTransformInfo_indices); + DECLARE_FIELD(jm_StandardGlyphVector_GlyphTransformInfo_indices, jc_StandardGlyphVector_GlyphTransformInfo, "indices", "[I"); + jintArray g_gtiTXIndicesArray = (*env)->GetObjectField(env, gti, jm_StandardGlyphVector_GlyphTransformInfo_indices); jint *g_gvTXIndicesAsInts = (*env)->GetPrimitiveArrayCritical(env, g_gtiTXIndicesArray, NULL); if (g_gvTXIndicesAsInts == NULL) { (*env)->ReleasePrimitiveArrayCritical(env, g_gtiTransformsArray, g_gvTransformsAsDoubles, JNI_ABORT); @@ -437,8 +440,9 @@ (*env)->ReleasePrimitiveArrayCritical(env, glyphsArray, glyphsAsInts, JNI_ABORT); // fill the advance buffer - static JNF_MEMBER_CACHE(jm_StandardGlyphVector_positions, jc_StandardGlyphVector, "positions", "[F"); - jfloatArray posArray = JNFGetObjectField(env, gVector, jm_StandardGlyphVector_positions); + GET_SGV_CLASS(); + DECLARE_FIELD(jm_StandardGlyphVector_positions, jc_StandardGlyphVector, "positions", "[F"); + jfloatArray posArray = (*env)->GetObjectField(env, gVector, jm_StandardGlyphVector_positions); jfloat *positions = NULL; if (posArray != NULL) { // in this case, the positions have already been pre-calculated for us on the Java side @@ -497,8 +501,9 @@ static inline void doDrawGlyphsPipe_getGlyphVectorLengthAndAlloc (JNIEnv *env, QuartzSDOps *qsdo, const AWTStrike *strike, jobject gVector) { - static JNF_MEMBER_CACHE(jm_StandardGlyphVector_glyphs, jc_StandardGlyphVector, "glyphs", "[I"); - jintArray glyphsArray = JNFGetObjectField(env, gVector, jm_StandardGlyphVector_glyphs); + GET_SGV_CLASS(); + DECLARE_FIELD(jm_StandardGlyphVector_glyphs, jc_StandardGlyphVector, "glyphs", "[I"); + jintArray glyphsArray = (*env)->GetObjectField(env, gVector, jm_StandardGlyphVector_glyphs); jsize length = (*env)->GetArrayLength(env, glyphsArray); if (length == 0) diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m @@ -146,9 +146,9 @@ deltaY = [event scrollingDeltaY] * 0.1; } - static JNF_CLASS_CACHE(jc_NSEvent, "sun/lwawt/macosx/NSEvent"); - static JNF_CTOR_CACHE(jctor_NSEvent, jc_NSEvent, "(IIIIIIIIDDI)V"); - jobject jEvent = JNFNewObject(env, jctor_NSEvent, + DECLARE_CLASS(jc_NSEvent, "sun/lwawt/macosx/NSEvent"); + DECLARE_METHOD(jctor_NSEvent, jc_NSEvent, "", "(IIIIIIIIDDI)V"); + jobject jEvent = (*env)->NewObject(env, jc_NSEvent, jctor_NSEvent, [event type], [event modifierFlags], clickCount, @@ -160,9 +160,10 @@ [AWTToolkit scrollStateWithEvent: event]); CHECK_NULL(jEvent); - static JNF_CLASS_CACHE(jc_TrayIcon, "sun/lwawt/macosx/CTrayIcon"); - static JNF_MEMBER_CACHE(jm_handleMouseEvent, jc_TrayIcon, "handleMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V"); - JNFCallVoidMethod(env, peer, jm_handleMouseEvent, jEvent); + DECLARE_CLASS(jc_TrayIcon, "sun/lwawt/macosx/CTrayIcon"); + DECLARE_METHOD(jm_handleMouseEvent, jc_TrayIcon, "handleMouseEvent", "(Lsun/lwawt/macosx/NSEvent;)V"); + (*env)->CallVoidMethod(env, peer, jm_handleMouseEvent, jEvent); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jEvent); } @@ -268,9 +269,10 @@ if (([event modifierFlags] & NSControlKeyMask) == 0) { //find CTrayIcon.getPopupMenuModel method and call it to get popup menu ptr. JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_CLASS_CACHE(jc_CTrayIcon, "sun/lwawt/macosx/CTrayIcon"); - static JNF_MEMBER_CACHE(jm_getPopupMenuModel, jc_CTrayIcon, "getPopupMenuModel", "()J"); - jlong res = JNFCallLongMethod(env, trayIcon.peer, jm_getPopupMenuModel); + DECLARE_CLASS(jc_CTrayIcon, "sun/lwawt/macosx/CTrayIcon"); + DECLARE_METHOD(jm_getPopupMenuModel, jc_CTrayIcon, "getPopupMenuModel", "()J"); + jlong res = (*env)->CallLongMethod(env, trayIcon.peer, jm_getPopupMenuModel); + CHECK_EXCEPTION(); if (res != 0) { CPopupMenu *cmenu = jlong_to_ptr(res); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.h b/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.h --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.h @@ -24,10 +24,9 @@ */ #import -#include "jni.h" +#include "JNIUtilities.h" jobject CGToJavaRect(JNIEnv *env, CGRect rect); -CGRect JavaToCGRect(JNIEnv *env, jobject rect); jobject NSToJavaRect(JNIEnv *env, NSRect rect); NSRect JavaToNSRect(JNIEnv *env, jobject rect); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.m @@ -24,27 +24,13 @@ */ #import "GeomUtilities.h" -#import - -static JNF_CLASS_CACHE(sjc_Point2D, "java/awt/geom/Point2D"); -static JNF_MEMBER_CACHE(jm_pt_getX, sjc_Point2D, "getX", "()D"); -static JNF_MEMBER_CACHE(jm_pt_getY, sjc_Point2D, "getY", "()D"); - -static JNF_CLASS_CACHE(sjc_Dimension2D, "java/awt/geom/Dimension2D"); -static JNF_MEMBER_CACHE(jm_sz_getWidth, sjc_Dimension2D, "getWidth", "()D"); -static JNF_MEMBER_CACHE(jm_sz_getHeight, sjc_Dimension2D, "getHeight", "()D"); - -static JNF_CLASS_CACHE(sjc_Rectangle2D, "java/awt/geom/Rectangle2D"); -static JNF_MEMBER_CACHE(jm_rect_getX, sjc_Rectangle2D, "getX", "()D"); -static JNF_MEMBER_CACHE(jm_rect_getY, sjc_Rectangle2D, "getY", "()D"); -static JNF_MEMBER_CACHE(jm_rect_getWidth, sjc_Rectangle2D, "getWidth", "()D"); -static JNF_MEMBER_CACHE(jm_rect_getHeight, sjc_Rectangle2D, "getHeight", "()D"); - static jobject NewJavaRect(JNIEnv *env, jdouble x, jdouble y, jdouble w, jdouble h) { - static JNF_CLASS_CACHE(sjc_Rectangle2DDouble, "java/awt/geom/Rectangle2D$Double"); - static JNF_CTOR_CACHE(ctor_Rectangle2DDouble, sjc_Rectangle2DDouble, "(DDDD)V"); - return JNFNewObject(env, ctor_Rectangle2DDouble, x, y, w, h); + DECLARE_CLASS_RETURN(sjc_Rectangle2DDouble, "java/awt/geom/Rectangle2D$Double", NULL); + DECLARE_METHOD_RETURN(ctor_Rectangle2DDouble, sjc_Rectangle2DDouble, "", "(DDDD)V", NULL); + jobject o = (*env)->NewObject(env, sjc_Rectangle2DDouble, ctor_Rectangle2DDouble, x, y, w, h); + CHECK_EXCEPTION(); + return o; } jobject CGToJavaRect(JNIEnv *env, CGRect rect) { @@ -63,46 +49,55 @@ rect.size.height); } -CGRect JavaToCGRect(JNIEnv *env, jobject rect) { - return CGRectMake(JNFCallDoubleMethod(env, rect, jm_rect_getX), - JNFCallDoubleMethod(env, rect, jm_rect_getY), - JNFCallDoubleMethod(env, rect, jm_rect_getWidth), - JNFCallDoubleMethod(env, rect, jm_rect_getHeight)); -} - NSRect JavaToNSRect(JNIEnv *env, jobject rect) { - return NSMakeRect(JNFCallDoubleMethod(env, rect, jm_rect_getX), - JNFCallDoubleMethod(env, rect, jm_rect_getY), - JNFCallDoubleMethod(env, rect, jm_rect_getWidth), - JNFCallDoubleMethod(env, rect, jm_rect_getHeight)); + DECLARE_CLASS_RETURN(sjc_Rectangle2D, "java/awt/geom/Rectangle2D", NSZeroRect); + DECLARE_METHOD_RETURN(jm_rect_getX, sjc_Rectangle2D, "getX", "()D", NSZeroRect); + DECLARE_METHOD_RETURN(jm_rect_getY, sjc_Rectangle2D, "getY", "()D", NSZeroRect); + DECLARE_METHOD_RETURN(jm_rect_getWidth, sjc_Rectangle2D, "getWidth", "()D", NSZeroRect); + DECLARE_METHOD_RETURN(jm_rect_getHeight, sjc_Rectangle2D, "getHeight", "()D", NSZeroRect); + return NSMakeRect((*env)->CallDoubleMethod(env, rect, jm_rect_getX), + (*env)->CallDoubleMethod(env, rect, jm_rect_getY), + (*env)->CallDoubleMethod(env, rect, jm_rect_getWidth), + (*env)->CallDoubleMethod(env, rect, jm_rect_getHeight)); } jobject NSToJavaPoint(JNIEnv *env, NSPoint point) { - static JNF_CLASS_CACHE(sjc_Point2DDouble, "java/awt/geom/Point2D$Double"); - static JNF_CTOR_CACHE(ctor_Point2DDouble, sjc_Point2DDouble, "(DD)V"); - return JNFNewObject(env, ctor_Point2DDouble, (jdouble)point.x, (jdouble)point.y); + DECLARE_CLASS_RETURN(sjc_Point2DDouble, "java/awt/geom/Point2D$Double", NULL); + DECLARE_METHOD_RETURN(ctor_Point2DDouble, sjc_Point2DDouble, "", "(DD)V", NULL); + jobject o = (*env)->NewObject(env, sjc_Point2DDouble, ctor_Point2DDouble, (jdouble)point.x, (jdouble)point.y); + CHECK_EXCEPTION(); + return o; } NSPoint JavaToNSPoint(JNIEnv *env, jobject point) { - return NSMakePoint(JNFCallDoubleMethod(env, point, jm_pt_getX), - JNFCallDoubleMethod(env, point, jm_pt_getY)); + DECLARE_CLASS_RETURN(sjc_Point2D, "java/awt/geom/Point2D", NSZeroPoint); + DECLARE_METHOD_RETURN(jm_pt_getX, sjc_Point2D, "getX", "()D", NSZeroPoint); + DECLARE_METHOD_RETURN(jm_pt_getY, sjc_Point2D, "getY", "()D", NSZeroPoint); + + return NSMakePoint((*env)->CallDoubleMethod(env, point, jm_pt_getX), + (*env)->CallDoubleMethod(env, point, jm_pt_getY)); } jobject NSToJavaSize(JNIEnv *env, NSSize size) { - static JNF_CLASS_CACHE(sjc_Dimension2DDouble, "java/awt/Dimension"); // No Dimension2D$Double :-( - static JNF_CTOR_CACHE(ctor_Dimension2DDouble, sjc_Dimension2DDouble, "(II)V"); - return JNFNewObject(env, ctor_Dimension2DDouble, (jint)size.width, (jint)size.height); + DECLARE_CLASS_RETURN(sjc_Dimension2DDouble, "java/awt/Dimension", NULL); // No Dimension2D$Double :-( + DECLARE_METHOD_RETURN(ctor_Dimension2DDouble, sjc_Dimension2DDouble, "", "(II)V", NULL); + jobject o = (*env)->NewObject(env, sjc_Dimension2DDouble, ctor_Dimension2DDouble, (jint)size.width, (jint)size.height); + CHECK_EXCEPTION(); + return o; } NSSize JavaToNSSize(JNIEnv *env, jobject dimension) { - return NSMakeSize(JNFCallDoubleMethod(env, dimension, jm_sz_getWidth), - JNFCallDoubleMethod(env, dimension, jm_sz_getHeight)); + DECLARE_CLASS_RETURN(sjc_Dimension2D, "java/awt/geom/Dimension2D", NSZeroSize); + DECLARE_METHOD_RETURN(jm_sz_getWidth, sjc_Dimension2D, "getWidth", "()D", NSZeroSize); + DECLARE_METHOD_RETURN(jm_sz_getHeight, sjc_Dimension2D, "getHeight", "()D", NSZeroSize); + + return NSMakeSize((*env)->CallDoubleMethod(env, dimension, jm_sz_getWidth), + (*env)->CallDoubleMethod(env, dimension, jm_sz_getHeight)); } static NSScreen *primaryScreen(JNIEnv *env) { NSScreen *primaryScreen = [[NSScreen screens] objectAtIndex:0]; if (primaryScreen != nil) return primaryScreen; - if (env != NULL) [JNFException raise:env as:kRuntimeException reason:"Failed to convert, no screen."]; return nil; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m @@ -30,7 +30,8 @@ #import "sun_awt_image_BufImgSurfaceData.h" #import "sun_java2d_OSXOffScreenSurfaceData.h" -#import "jni_util.h" +#import "ThreadUtilities.h" +#import "JNIUtilities.h" #import #import "BufImgSurfaceData.h" @@ -103,16 +104,9 @@ static jfieldID CMpDataID; static jfieldID allGrayID; - -static JNF_CLASS_CACHE(jc_OSXOffScreenSurfaceData, "sun/java2d/OSXOffScreenSurfaceData"); -static JNF_MEMBER_CACHE(jm_syncFromCustom, jc_OSXOffScreenSurfaceData, "syncFromCustom", "()V"); -static JNF_MEMBER_CACHE(jm_syncToCustom, jc_OSXOffScreenSurfaceData, "syncToCustom", "()V"); -static JNF_CLASS_CACHE(jc_BufferedImage, "java/awt/image/BufferedImage"); -static JNF_MEMBER_CACHE(jm_SurfaceData, jc_BufferedImage, "sData", "Lsun/java2d/SurfaceData;"); -static JNF_CLASS_CACHE(jc_IndexColorModel, "java/awt/image/IndexColorModel"); -static JNF_MEMBER_CACHE(jm_rgb, jc_IndexColorModel, "rgb", "[I"); -static JNF_MEMBER_CACHE(jm_transparency, jc_IndexColorModel, "transparency", "I"); -static JNF_MEMBER_CACHE(jm_transparent_index, jc_IndexColorModel, "transparent_index", "I"); +static jclass jc_OSXOffScreenSurfaceData = NULL; +#define GET_OSXOSD_CLASS() \ + GET_CLASS(jc_OSXOffScreenSurfaceData, "sun/java2d/OSXOffScreenSurfaceData"); CGColorSpaceRef gColorspaceRGB = NULL; CGColorSpaceRef gColorspaceGray = NULL; @@ -192,7 +186,11 @@ PRINT(" customPixelsFromJava") SurfaceDataOps *sdo = (SurfaceDataOps*)isdo; - JNFCallVoidMethod(env, sdo->sdObject, jm_syncFromCustom); // AWT_THREADING Safe (known object) + GET_OSXOSD_CLASS(); + DECLARE_METHOD(jm_syncFromCustom, jc_OSXOffScreenSurfaceData, "syncFromCustom", "()V"); + + (*env)->CallVoidMethod(env, sdo->sdObject, jm_syncFromCustom); // AWT_THREADING Safe (known object) + CHECK_EXCEPTION(); } IMAGE_SURFACE_INLINE void copyBits(jint w, jint h, jint javaPixelsBytesPerRow, Pixel8bit *pixelsSrc, jint dstPixelsBytesPerRow, Pixel8bit *pixelsDst) @@ -423,7 +421,10 @@ PRINT(" customPixelsToJava") SurfaceDataOps *sdo = (SurfaceDataOps*)isdo; - JNFCallVoidMethod(env, sdo->sdObject, jm_syncToCustom); // AWT_THREADING Safe (known object) + GET_OSXOSD_CLASS(); + DECLARE_METHOD(jm_syncToCustom, jc_OSXOffScreenSurfaceData, "syncToCustom", "()V"); + (*env)->CallVoidMethod(env, sdo->sdObject, jm_syncToCustom); // AWT_THREADING Safe (known object) + CHECK_EXCEPTION(); } IMAGE_SURFACE_INLINE void removeAlphaPre_32bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel32bit *pixelsSrc) @@ -1622,12 +1623,16 @@ //fprintf(stderr, "gColorspaceRGB=%p, gColorspaceGray=%p\n", gColorspaceRGB, gColorspaceGray); } +static jclass jc_BufferedImage = NULL; +static jfieldID jm_SurfaceData = NULL; + JNIEXPORT jobject JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_getSurfaceData (JNIEnv *env, jclass bisd, jobject bufImg) { PRINT("getSurfaceData") - - return JNFGetObjectField(env, bufImg, jm_SurfaceData); + GET_CLASS_RETURN(jc_BufferedImage, "java/awt/image/BufferedImage", NULL); + GET_FIELD_RETURN(jm_SurfaceData, jc_BufferedImage, "sData", "Lsun/java2d/SurfaceData;", NULL); + return (*env)->GetObjectField(env, bufImg, jm_SurfaceData); } JNIEXPORT void JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_setSurfaceData @@ -1635,7 +1640,9 @@ { PRINT("setSurfaceData") - JNFSetObjectField(env, bufImg, jm_SurfaceData, sData); + GET_CLASS(jc_BufferedImage, "java/awt/image/BufferedImage"); + GET_FIELD(jm_SurfaceData, jc_BufferedImage, "sData", "Lsun/java2d/SurfaceData;"); + (*env)->SetObjectField(env, bufImg, jm_SurfaceData, sData); } static jint ImageSD_Lock(JNIEnv *env, SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo, jint lockflags) @@ -1863,15 +1870,24 @@ isdo->lutDataSize = 0; if ((type == java_awt_image_BufferedImage_TYPE_BYTE_INDEXED) && ((*env)->IsSameObject(env, icm, NULL) == NO)) { - jarray lutarray = JNFGetObjectField(env, icm, jm_rgb); + static jclass jc_IndexColorModel = NULL; + if (jc_IndexColorModel == NULL) { + jc_IndexColorModel = (*env)->FindClass(env, "java/awt/image/IndexColorModel"); + } + CHECK_NULL(jc_IndexColorModel); + DECLARE_FIELD(jm_rgb, jc_IndexColorModel, "rgb", "[I"); + DECLARE_FIELD(jm_transparency, jc_IndexColorModel, "transparency", "I"); + DECLARE_FIELD(jm_transparent_index, jc_IndexColorModel, "transparent_index", "I"); + + jarray lutarray = (*env)->GetObjectField(env, icm, jm_rgb); isdo->lutDataSize = (*env)->GetArrayLength(env, lutarray); if (isdo->lutDataSize > 0) { - jint transparency = JNFGetIntField(env, icm, jm_transparency); + jint transparency = (*env)->GetIntField(env, icm, jm_transparency); jint transparent_index = -1; if (transparency == java_awt_Transparency_BITMASK) { - transparent_index = JNFGetIntField(env, icm, jm_transparent_index); + transparent_index = (*env)->GetIntField(env, icm, jm_transparent_index); } Pixel32bit* lutdata = (Pixel32bit*)((*env)->GetPrimitiveArrayCritical(env, lutarray, NULL)); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m @@ -27,6 +27,7 @@ #import "JavaAccessibilityUtilities.h" #import "ThreadUtilities.h" +#import "JNIUtilities.h" @implementation JavaAxAction @@ -57,20 +58,22 @@ - (NSString *)getDescription { - static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleActionDescription, sjc_CAccessibility, "getAccessibleActionDescription", "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)Ljava/lang/String;"); - JNIEnv* env = [ThreadUtilities getJNIEnv]; + DECLARE_CLASS_RETURN(sjc_CAccessibility, "sun/lwawt/macosx/CAccessibility", nil); + DECLARE_METHOD_RETURN(jm_getAccessibleActionDescription, sjc_CAccessibility, "getAccessibleActionDescription", + "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)Ljava/lang/String;", nil); jobject fCompLocal = (*env)->NewLocalRef(env, fComponent); if ((*env)->IsSameObject(env, fCompLocal, NULL)) { return nil; } NSString *str = nil; - jstring jstr = JNFCallStaticObjectMethod( env, + jstring jstr = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibleActionDescription, fAccessibleAction, fIndex, fCompLocal ); + CHECK_EXCEPTION(); if (jstr != NULL) { str = JNFJavaToNSString(env, jstr); // AWT_THREADING Safe (AWTRunLoopMode) (*env)->DeleteLocalRef(env, jstr); @@ -81,11 +84,14 @@ - (void)perform { - static JNF_STATIC_MEMBER_CACHE(jm_doAccessibleAction, sjc_CAccessibility, "doAccessibleAction", "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)V"); + JNIEnv* env = [ThreadUtilities getJNIEnv]; + DECLARE_CLASS(sjc_CAccessibility, "sun/lwawt/macosx/CAccessibility"); + DECLARE_METHOD(jm_doAccessibleAction, sjc_CAccessibility, "doAccessibleAction", + "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)V"); - JNIEnv* env = [ThreadUtilities getJNIEnv]; - - JNFCallStaticVoidMethod(env, jm_doAccessibleAction, fAccessibleAction, fIndex, fComponent); // AWT_THREADING Safe (AWTRunLoopMode) + (*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_doAccessibleAction, + fAccessibleAction, fIndex, fComponent); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); } @end diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.h b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.h --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.h @@ -30,18 +30,10 @@ extern NSMutableDictionary *sRoles; extern void initializeRoles(); -extern JNFClassInfo sjc_CAccessibility; -extern JNFClassInfo sjc_AccessibleComponent; -extern JNFClassInfo sjc_AccessibleContext; -extern JNFClassInfo sjc_Accessible; -extern JNFClassInfo sjc_AccessibleRole; -extern JNFClassInfo sjc_Point; -extern JNFClassInfo sjc_AccessibleText; - -extern JNFMemberInfo *sjm_getAccessibleRole; -extern JNFMemberInfo *sjf_key; -extern JNFMemberInfo *sjf_X; -extern JNFMemberInfo *sjf_Y; +#define GET_CACCESSIBILITY_CLASS() \ + GET_CLASS(sjc_CAccessibility, "sun/lwawt/macosx/CAccessibility"); +#define GET_CACCESSIBILITY_CLASS_RETURN(ret) \ + GET_CLASS_RETURN(sjc_CAccessibility, "sun/lwawt/macosx/CAccessibility", ret); NSSize getAxComponentSize(JNIEnv *env, jobject axComponent, jobject component); NSString *getJavaRole(JNIEnv *env, jobject axComponent, jobject component); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m @@ -24,6 +24,7 @@ */ #import "JavaAccessibilityUtilities.h" +#import "JNIUtilities.h" #import #import @@ -43,38 +44,35 @@ void initializeRoles(); // Unique -static JNF_CLASS_CACHE(sjc_AccessibleState, "javax/accessibility/AccessibleState"); +static jclass sjc_AccessibleState = NULL; +#define GET_ACCESSIBLESTATE_CLASS_RETURN(ret) \ + GET_CLASS_RETURN(sjc_AccessibleState, "javax/accessibility/AccessibleState", ret); -// Duplicate -JNF_CLASS_CACHE(sjc_CAccessibility, "sun/lwawt/macosx/CAccessibility"); -JNF_CLASS_CACHE(sjc_AccessibleComponent, "javax/accessibility/AccessibleComponent"); -JNF_CLASS_CACHE(sjc_AccessibleContext, "javax/accessibility/AccessibleContext"); -JNF_CLASS_CACHE(sjc_Accessible, "javax/accessibility/Accessible"); -JNF_CLASS_CACHE(sjc_AccessibleRole, "javax/accessibility/AccessibleRole"); -JNF_CLASS_CACHE(sjc_Point, "java/awt/Point"); -JNF_CLASS_CACHE(sjc_AccessibleText, "javax/accessibility/AccessibleText"); - -JNF_MEMBER_CACHE(sjf_key, sjc_AccessibleRole, "key", "Ljava/lang/String;"); -JNF_MEMBER_CACHE(sjf_X, sjc_Point, "x", "I"); -JNF_MEMBER_CACHE(sjf_Y, sjc_Point, "y", "I"); +static jclass sjc_CAccessibility = NULL; NSSize getAxComponentSize(JNIEnv *env, jobject axComponent, jobject component) { - static JNF_CLASS_CACHE(jc_Dimension, "java/awt/Dimension"); - static JNF_MEMBER_CACHE(jf_width, jc_Dimension, "width", "I"); - static JNF_MEMBER_CACHE(jf_height, jc_Dimension, "height", "I"); - static JNF_STATIC_MEMBER_CACHE(jm_getSize, sjc_CAccessibility, "getSize", "(Ljavax/accessibility/AccessibleComponent;Ljava/awt/Component;)Ljava/awt/Dimension;"); + DECLARE_CLASS_RETURN(jc_Dimension, "java/awt/Dimension", NSZeroSize); + DECLARE_FIELD_RETURN(jf_width, jc_Dimension, "width", "I", NSZeroSize); + DECLARE_FIELD_RETURN(jf_height, jc_Dimension, "height", "I", NSZeroSize); + DECLARE_STATIC_METHOD_RETURN(jm_getSize, sjc_CAccessibility, "getSize", + "(Ljavax/accessibility/AccessibleComponent;Ljava/awt/Component;)Ljava/awt/Dimension;", NSZeroSize); - jobject dimension = JNFCallStaticObjectMethod(env, jm_getSize, axComponent, component); // AWT_THREADING Safe (AWTRunLoopMode) + jobject dimension = (*env)->CallStaticObjectMethod(env, jc_Dimension, jm_getSize, axComponent, component); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); if (dimension == NULL) return NSZeroSize; - return NSMakeSize(JNFGetIntField(env, dimension, jf_width), JNFGetIntField(env, dimension, jf_height)); + return NSMakeSize((*env)->GetIntField(env, dimension, jf_width), (*env)->GetIntField(env, dimension, jf_height)); } NSString *getJavaRole(JNIEnv *env, jobject axComponent, jobject component) { - static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleRole, sjc_CAccessibility, "getAccessibleRole", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;"); - jobject axRole = JNFCallStaticObjectMethod(env, sjm_getAccessibleRole, axComponent, component); // AWT_THREADING Safe (AWTRunLoopMode) + GET_CACCESSIBILITY_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(sjm_getAccessibleRole, sjc_CAccessibility, "getAccessibleRole", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;", nil); + jobject axRole = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleRole, + axComponent, component); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); if (axRole == NULL) return @"unknown"; NSString* str = JNFJavaToNSString(env, axRole); @@ -84,50 +82,84 @@ jobject getAxSelection(JNIEnv *env, jobject axContext, jobject component) { - static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleSelection, sjc_CAccessibility, "getAccessibleSelection", "(Ljavax/accessibility/AccessibleContext;Ljava/awt/Component;)Ljavax/accessibility/AccessibleSelection;"); - return JNFCallStaticObjectMethod(env, jm_getAccessibleSelection, axContext, component); // AWT_THREADING Safe (AWTRunLoopMode) + GET_CACCESSIBILITY_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getAccessibleSelection, sjc_CAccessibility, "getAccessibleSelection", + "(Ljavax/accessibility/AccessibleContext;Ljava/awt/Component;)Ljavax/accessibility/AccessibleSelection;", nil); + jobject o = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibleSelection, + axContext, component); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); + return o; } jobject getAxContextSelection(JNIEnv *env, jobject axContext, jint index, jobject component) { - static JNF_STATIC_MEMBER_CACHE(jm_ax_getAccessibleSelection, sjc_CAccessibility, "ax_getAccessibleSelection", "(Ljavax/accessibility/AccessibleContext;ILjava/awt/Component;)Ljavax/accessibility/Accessible;"); - return JNFCallStaticObjectMethod(env, jm_ax_getAccessibleSelection, axContext, index, component); // AWT_THREADING Safe (AWTRunLoopMode) + GET_CACCESSIBILITY_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_ax_getAccessibleSelection, sjc_CAccessibility, "ax_getAccessibleSelection", + "(Ljavax/accessibility/AccessibleContext;ILjava/awt/Component;)Ljavax/accessibility/Accessible;", nil); + return (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_ax_getAccessibleSelection, + axContext, index, component); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); } void setAxContextSelection(JNIEnv *env, jobject axContext, jint index, jobject component) { - static JNF_STATIC_MEMBER_CACHE(jm_addAccessibleSelection, sjc_CAccessibility, "addAccessibleSelection", "(Ljavax/accessibility/AccessibleContext;ILjava/awt/Component;)V"); - JNFCallStaticVoidMethod(env, jm_addAccessibleSelection, axContext, index, component); // AWT_THREADING Safe (AWTRunLoopMode) + GET_CACCESSIBILITY_CLASS(); + DECLARE_STATIC_METHOD(jm_addAccessibleSelection, sjc_CAccessibility, "addAccessibleSelection", + "(Ljavax/accessibility/AccessibleContext;ILjava/awt/Component;)V"); + (*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_addAccessibleSelection, + axContext, index, component); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); } jobject getAxContext(JNIEnv *env, jobject accessible, jobject component) { - static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleContext, sjc_CAccessibility, "getAccessibleContext", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleContext;"); - return JNFCallStaticObjectMethod(env, jm_getAccessibleContext, accessible, component); // AWT_THREADING Safe (AWTRunLoopMode) + GET_CACCESSIBILITY_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getAccessibleContext, sjc_CAccessibility, "getAccessibleContext", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleContext;", nil); + jobject o = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibleContext, + accessible, component); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); + return o; } BOOL isChildSelected(JNIEnv *env, jobject accessible, jint index, jobject component) { - static JNF_STATIC_MEMBER_CACHE(jm_isAccessibleChildSelected, sjc_CAccessibility, "isAccessibleChildSelected", "(Ljavax/accessibility/Accessible;ILjava/awt/Component;)Z"); - return JNFCallStaticBooleanMethod(env, jm_isAccessibleChildSelected, accessible, index, component); // AWT_THREADING Safe (AWTRunLoopMode) + GET_CACCESSIBILITY_CLASS_RETURN(NO); + DECLARE_STATIC_METHOD_RETURN(jm_isAccessibleChildSelected, sjc_CAccessibility, "isAccessibleChildSelected", + "(Ljavax/accessibility/Accessible;ILjava/awt/Component;)Z", NO); + jboolean b = (*env)->CallStaticBooleanMethod(env, sjc_CAccessibility, jm_isAccessibleChildSelected, + accessible, index, component); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); + return b; } jobject getAxStateSet(JNIEnv *env, jobject axContext, jobject component) { - static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleStateSet, sjc_CAccessibility, "getAccessibleStateSet", "(Ljavax/accessibility/AccessibleContext;Ljava/awt/Component;)Ljavax/accessibility/AccessibleStateSet;"); - return JNFCallStaticObjectMethod(env, jm_getAccessibleStateSet, axContext, component); // AWT_THREADING Safe (AWTRunLoopMode) + GET_CACCESSIBILITY_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getAccessibleStateSet, sjc_CAccessibility, "getAccessibleStateSet", + "(Ljavax/accessibility/AccessibleContext;Ljava/awt/Component;)Ljavax/accessibility/AccessibleStateSet;", nil); + jobject o = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibleStateSet, + axContext, component); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); + return o; } BOOL containsAxState(JNIEnv *env, jobject axContext, jobject axState, jobject component) { - static JNF_STATIC_MEMBER_CACHE(jm_contains, sjc_CAccessibility, "contains", "(Ljavax/accessibility/AccessibleContext;Ljavax/accessibility/AccessibleState;Ljava/awt/Component;)Z"); - return JNFCallStaticBooleanMethod(env, jm_contains, axContext, axState, component); // AWT_THREADING Safe (AWTRunLoopMode) + GET_CACCESSIBILITY_CLASS_RETURN(NO); + DECLARE_STATIC_METHOD_RETURN(jm_contains, sjc_CAccessibility, "contains", + "(Ljavax/accessibility/AccessibleContext;Ljavax/accessibility/AccessibleState;Ljava/awt/Component;)Z", NO); + jboolean b = (*env)->CallStaticBooleanMethod(env, sjc_CAccessibility, jm_contains, axContext, axState, component); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); + return b; } BOOL isVertical(JNIEnv *env, jobject axContext, jobject component) { - static JNF_STATIC_MEMBER_CACHE(jm_VERTICAL, sjc_AccessibleState, "VERTICAL", "Ljavax/accessibility/AccessibleState;"); - jobject axVertState = JNFGetStaticObjectField(env, jm_VERTICAL); + GET_ACCESSIBLESTATE_CLASS_RETURN(NO); + DECLARE_STATIC_FIELD_RETURN(jm_VERTICAL, sjc_AccessibleState, "VERTICAL", "Ljavax/accessibility/AccessibleState;", NO); + jobject axVertState = (*env)->GetStaticObjectField(env, sjc_AccessibleState, jm_VERTICAL); + CHECK_EXCEPTION_NULL_RETURN(axVertState, NO); BOOL vertical = containsAxState(env, axContext, axVertState, component); (*env)->DeleteLocalRef(env, axVertState); return vertical; @@ -135,8 +167,10 @@ BOOL isHorizontal(JNIEnv *env, jobject axContext, jobject component) { - static JNF_STATIC_MEMBER_CACHE(jm_HORIZONTAL, sjc_AccessibleState, "HORIZONTAL", "Ljavax/accessibility/AccessibleState;"); - jobject axHorizState = JNFGetStaticObjectField(env, jm_HORIZONTAL); + GET_ACCESSIBLESTATE_CLASS_RETURN(NO); + DECLARE_STATIC_FIELD_RETURN(jm_HORIZONTAL, sjc_AccessibleState, "HORIZONTAL", "Ljavax/accessibility/AccessibleState;", NO); + jobject axHorizState = (*env)->GetStaticObjectField(env, sjc_AccessibleState, jm_HORIZONTAL); + CHECK_EXCEPTION_NULL_RETURN(axHorizState, NO); BOOL horizontal = containsAxState(env, axContext, axHorizState, component); (*env)->DeleteLocalRef(env, axHorizState); return horizontal; @@ -144,8 +178,10 @@ BOOL isShowing(JNIEnv *env, jobject axContext, jobject component) { - static JNF_STATIC_MEMBER_CACHE(jm_SHOWING, sjc_AccessibleState, "SHOWING", "Ljavax/accessibility/AccessibleState;"); - jobject axVisibleState = JNFGetStaticObjectField(env, jm_SHOWING); + GET_ACCESSIBLESTATE_CLASS_RETURN(NO); + DECLARE_STATIC_FIELD_RETURN(jm_SHOWING, sjc_AccessibleState, "SHOWING", "Ljavax/accessibility/AccessibleState;", NO); + jobject axVisibleState = (*env)->GetStaticObjectField(env, sjc_AccessibleState, jm_SHOWING); + CHECK_EXCEPTION_NULL_RETURN(axVisibleState, NO); BOOL showing = containsAxState(env, axContext, axVisibleState, component); (*env)->DeleteLocalRef(env, axVisibleState); return showing; @@ -153,11 +189,13 @@ BOOL isSelectable(JNIEnv *env, jobject axContext, jobject component) { - static JNF_STATIC_MEMBER_CACHE( jm_SELECTABLE, + GET_ACCESSIBLESTATE_CLASS_RETURN(NO); + DECLARE_STATIC_FIELD_RETURN(jm_SELECTABLE, sjc_AccessibleState, "SELECTABLE", - "Ljavax/accessibility/AccessibleState;" ); - jobject axSelectableState = JNFGetStaticObjectField(env, jm_SELECTABLE); + "Ljavax/accessibility/AccessibleState;", NO ); + jobject axSelectableState = (*env)->GetStaticObjectField(env, sjc_AccessibleState, jm_SELECTABLE); + CHECK_EXCEPTION_NULL_RETURN(axSelectableState, NO); BOOL selectable = containsAxState(env, axContext, axSelectableState, component); (*env)->DeleteLocalRef(env, axSelectableState); return selectable; @@ -165,16 +203,27 @@ NSPoint getAxComponentLocationOnScreen(JNIEnv *env, jobject axComponent, jobject component) { - static JNF_STATIC_MEMBER_CACHE(jm_getLocationOnScreen, sjc_CAccessibility, "getLocationOnScreen", "(Ljavax/accessibility/AccessibleComponent;Ljava/awt/Component;)Ljava/awt/Point;"); - jobject jpoint = JNFCallStaticObjectMethod(env, jm_getLocationOnScreen, axComponent, component); // AWT_THREADING Safe (AWTRunLoopMode) + GET_CACCESSIBILITY_CLASS_RETURN(NSZeroPoint); + DECLARE_STATIC_METHOD_RETURN(jm_getLocationOnScreen, sjc_CAccessibility, "getLocationOnScreen", + "(Ljavax/accessibility/AccessibleComponent;Ljava/awt/Component;)Ljava/awt/Point;", NSZeroPoint); + DECLARE_CLASS_RETURN(sjc_Point, "java/awt/Point", NSZeroPoint); + DECLARE_FIELD_RETURN(sjf_X, sjc_Point, "x", "I", NSZeroPoint); + DECLARE_FIELD_RETURN(sjf_Y, sjc_Point, "y", "I", NSZeroPoint); + jobject jpoint = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getLocationOnScreen, + axComponent, component); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); if (jpoint == NULL) return NSZeroPoint; - return NSMakePoint(JNFGetIntField(env, jpoint, sjf_X), JNFGetIntField(env, jpoint, sjf_Y)); + return NSMakePoint((*env)->GetIntField(env, jpoint, sjf_X), (*env)->GetIntField(env, jpoint, sjf_Y)); } jint getAxTextCharCount(JNIEnv *env, jobject axText, jobject component) { - static JNF_STATIC_MEMBER_CACHE(jm_getCharCount, sjc_CAccessibility, "getCharCount", "(Ljavax/accessibility/AccessibleText;Ljava/awt/Component;)I"); - return JNFCallStaticIntMethod(env, jm_getCharCount, axText, component); // AWT_THREADING Safe (AWTRunLoopMode) + GET_CACCESSIBILITY_CLASS_RETURN(0); + DECLARE_STATIC_METHOD_RETURN(jm_getCharCount, sjc_CAccessibility, "getCharCount", + "(Ljavax/accessibility/AccessibleText;Ljava/awt/Component;)I", 0); + int i = (*env)->CallStaticIntMethod(env, sjc_CAccessibility, jm_getCharCount, axText, component); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); + return i; } // The following JavaAccessibility methods are copied from the corresponding @@ -265,7 +314,9 @@ JNIEXPORT jstring JNICALL Java_sun_lwawt_macosx_CAccessibility_roleKey (JNIEnv *env, jclass clz, jobject axRole) { - return JNFGetObjectField(env, axRole, sjf_key); + DECLARE_CLASS_RETURN(sjc_AccessibleRole, "javax/accessibility/AccessibleRole", NULL); + DECLARE_FIELD_RETURN(sjf_key, sjc_AccessibleRole, "key", "Ljava/lang/String;", NULL); + return (*env)->GetObjectField(env, axRole, sjf_key); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m @@ -44,6 +44,7 @@ #import "JavaAccessibilityUtilities.h" #import "JavaTextAccessibility.h" #import "ThreadUtilities.h" +#import "JNIUtilities.h" #import "AWTView.h" @@ -53,18 +54,37 @@ #define JAVA_AX_VISIBLE_CHILDREN (-3) // If the value is >=0, it's an index -static JNF_STATIC_MEMBER_CACHE(jm_getChildrenAndRoles, sjc_CAccessibility, "getChildrenAndRoles", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;IZ)[Ljava/lang/Object;"); -static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleComponent, sjc_CAccessibility, "getAccessibleComponent", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleComponent;"); -static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleValue, sjc_CAccessibility, "getAccessibleValue", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleValue;"); -static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleName, sjc_CAccessibility, "getAccessibleName", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;"); -static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleDescription, sjc_CAccessibility, "getAccessibleDescription", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;"); -static JNF_STATIC_MEMBER_CACHE(sjm_isFocusTraversable, sjc_CAccessibility, "isFocusTraversable", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Z"); -static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleIndexInParent, sjc_CAccessibility, "getAccessibleIndexInParent", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)I"); +// GET* macros defined in JavaAccessibilityUtilities.h, so they can be shared. +static jclass sjc_CAccessibility = NULL; + +static jmethodID sjm_getAccessibleName = NULL; +#define GET_ACCESSIBLENAME_METHOD_RETURN(ret) \ + GET_CACCESSIBILITY_CLASS_RETURN(ret); \ + GET_STATIC_METHOD_RETURN(sjm_getAccessibleName, sjc_CAccessibility, "getAccessibleName", \ + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;", ret); + +static jmethodID jm_getChildrenAndRoles = NULL; +#define GET_CHILDRENANDROLES_METHOD_RETURN(ret) \ + GET_CACCESSIBILITY_CLASS_RETURN(ret); \ + GET_STATIC_METHOD_RETURN(jm_getChildrenAndRoles, sjc_CAccessibility, "getChildrenAndRoles",\ + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;IZ)[Ljava/lang/Object;", ret); -static JNF_CLASS_CACHE(sjc_CAccessible, "sun/lwawt/macosx/CAccessible"); +static jmethodID sjm_getAccessibleComponent = NULL; +#define GET_ACCESSIBLECOMPONENT_STATIC_METHOD_RETURN(ret) \ + GET_CACCESSIBILITY_CLASS_RETURN(ret); \ + GET_STATIC_METHOD_RETURN(sjm_getAccessibleComponent, sjc_CAccessibility, "getAccessibleComponent", \ + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleComponent;", ret); -static JNF_MEMBER_CACHE(jf_ptr, sjc_CAccessible, "ptr", "J"); -static JNF_STATIC_MEMBER_CACHE(sjm_getCAccessible, sjc_CAccessible, "getCAccessible", "(Ljavax/accessibility/Accessible;)Lsun/lwawt/macosx/CAccessible;"); +static jmethodID sjm_getAccessibleIndexInParent = NULL; +#define GET_ACCESSIBLEINDEXINPARENT_STATIC_METHOD_RETURN(ret) \ + GET_CACCESSIBILITY_CLASS_RETURN(ret); \ + GET_STATIC_METHOD_RETURN(sjm_getAccessibleIndexInParent, sjc_CAccessibility, "getAccessibleIndexInParent", \ + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)I", ret); + +static jclass sjc_CAccessible = NULL; +#define GET_CACCESSIBLE_CLASS_RETURN(ret) \ + GET_CLASS_RETURN(sjc_CAccessible, "sun/lwawt/macosx/CAccessible", ret); + static jobject sAccessibilityClass = NULL; @@ -256,7 +276,10 @@ } if (sAccessibilityClass == NULL) { - JNF_STATIC_MEMBER_CACHE(jm_getAccessibility, sjc_CAccessibility, "getAccessibility", "([Ljava/lang/String;)Lsun/lwawt/macosx/CAccessibility;"); + JNIEnv *env = [ThreadUtilities getJNIEnv]; + + GET_CACCESSIBILITY_CLASS(); + DECLARE_STATIC_METHOD(jm_getAccessibility, sjc_CAccessibility, "getAccessibility", "([Ljava/lang/String;)Lsun/lwawt/macosx/CAccessibility;"); #ifdef JAVA_AX_NO_IGNORES NSArray *ignoredKeys = [NSArray array]; @@ -266,10 +289,9 @@ jobjectArray result = NULL; jsize count = [ignoredKeys count]; - JNIEnv *env = [ThreadUtilities getJNIEnv]; - - static JNF_CLASS_CACHE(jc_String, "java/lang/String"); - result = JNFNewObjectArray(env, &jc_String, count); + DECLARE_CLASS(jc_String, "java/lang/String"); + result = (*env)->NewObjectArray(env, count, jc_String, NULL); + CHECK_EXCEPTION(); if (!result) { NSLog(@"In %s, can't create Java array of String objects", __FUNCTION__); return; @@ -282,7 +304,8 @@ (*env)->DeleteLocalRef(env, jString); } - sAccessibilityClass = JNFCallStaticObjectMethod(env, jm_getAccessibility, result); // AWT_THREADING Safe (known object) + sAccessibilityClass = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibility, result); // AWT_THREADING Safe (known object) + CHECK_EXCEPTION(); } } @@ -293,10 +316,16 @@ } + (jobject) getCAccessible:(jobject)jaccessible withEnv:(JNIEnv *)env { - if (JNFIsInstanceOf(env, jaccessible, &sjc_CAccessible)) { + DECLARE_CLASS_RETURN(sjc_Accessible, "javax/accessibility/Accessible", NULL); + GET_CACCESSIBLE_CLASS_RETURN(NULL); + DECLARE_STATIC_METHOD_RETURN(sjm_getCAccessible, sjc_CAccessible, "getCAccessible", + "(Ljavax/accessibility/Accessible;)Lsun/lwawt/macosx/CAccessible;", NULL); + if ((*env)->IsInstanceOf(env, jaccessible, sjc_CAccessible)) { return jaccessible; - } else if (JNFIsInstanceOf(env, jaccessible, &sjc_Accessible)) { - return JNFCallStaticObjectMethod(env, sjm_getCAccessible, jaccessible); + } else if ((*env)->IsInstanceOf(env, jaccessible, sjc_Accessible)) { + jobject o = (*env)->CallStaticObjectMethod(env, sjc_CAccessible, sjm_getCAccessible, jaccessible); + CHECK_EXCEPTION(); + return o; } return NULL; } @@ -304,7 +333,10 @@ + (NSArray *)childrenOfParent:(JavaComponentAccessibility *)parent withEnv:(JNIEnv *)env withChildrenCode:(NSInteger)whichChildren allowIgnored:(BOOL)allowIgnored { if (parent->fAccessible == NULL) return nil; - jobjectArray jchildrenAndRoles = (jobjectArray)JNFCallStaticObjectMethod(env, jm_getChildrenAndRoles, parent->fAccessible, parent->fComponent, whichChildren, allowIgnored); // AWT_THREADING Safe (AWTRunLoop) + GET_CHILDRENANDROLES_METHOD_RETURN(nil); + jobjectArray jchildrenAndRoles = (jobjectArray)(*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getChildrenAndRoles, + parent->fAccessible, parent->fComponent, whichChildren, allowIgnored); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (jchildrenAndRoles == NULL) return nil; jsize arrayLen = (*env)->GetArrayLength(env, jchildrenAndRoles); @@ -319,7 +351,10 @@ NSString *childJavaRole = nil; if (jchildJavaRole != NULL) { - jobject jkey = JNFGetObjectField(env, jchildJavaRole, sjf_key); + DECLARE_CLASS_RETURN(sjc_AccessibleRole, "javax/accessibility/AccessibleRole", nil); + DECLARE_FIELD_RETURN(sjf_key, sjc_AccessibleRole, "key", "Ljava/lang/String;", nil); + jobject jkey = (*env)->GetObjectField(env, jchildJavaRole, sjf_key); + CHECK_EXCEPTION(); childJavaRole = JNFJavaToNSString(env, jkey); (*env)->DeleteLocalRef(env, jkey); } @@ -339,9 +374,11 @@ + (JavaComponentAccessibility *)createWithAccessible:(jobject)jaccessible withEnv:(JNIEnv *)env withView:(NSView *)view { + GET_ACCESSIBLEINDEXINPARENT_STATIC_METHOD_RETURN(nil); JavaComponentAccessibility *ret = nil; jobject jcomponent = [(AWTView *)view awtComponent:env]; - jint index = JNFCallStaticIntMethod(env, sjm_getAccessibleIndexInParent, jaccessible, jcomponent); + jint index = (*env)->CallStaticIntMethod(env, sjc_CAccessibility, sjm_getAccessibleIndexInParent, jaccessible, jcomponent); + CHECK_EXCEPTION(); if (index >= 0) { NSString *javaRole = getJavaRole(env, jaccessible, jcomponent); ret = [self createWithAccessible:jaccessible role:javaRole index:index withEnv:env withView:view]; @@ -357,10 +394,12 @@ + (JavaComponentAccessibility *) createWithParent:(JavaComponentAccessibility *)parent accessible:(jobject)jaccessible role:(NSString *)javaRole index:(jint)index withEnv:(JNIEnv *)env withView:(NSView *)view { + GET_CACCESSIBLE_CLASS_RETURN(NULL); + DECLARE_FIELD_RETURN(jf_ptr, sjc_CAccessible, "ptr", "J", NULL); // try to fetch the jCAX from Java, and return autoreleased jobject jCAX = [JavaComponentAccessibility getCAccessible:jaccessible withEnv:env]; if (jCAX == NULL) return nil; - JavaComponentAccessibility *value = (JavaComponentAccessibility *) jlong_to_ptr(JNFGetLongField(env, jCAX, jf_ptr)); + JavaComponentAccessibility *value = (JavaComponentAccessibility *) jlong_to_ptr((*env)->GetLongField(env, jCAX, jf_ptr)); if (value != nil) { (*env)->DeleteLocalRef(env, jCAX); return [[value retain] autorelease]; @@ -394,7 +433,7 @@ // must hard retain pointer poked into Java object [newChild retain]; - JNFSetLongField(env, jCAX, jf_ptr, ptr_to_jlong(newChild)); + (*env)->SetLongField(env, jCAX, jf_ptr, ptr_to_jlong(newChild)); (*env)->DeleteLocalRef(env, jCAX); // return autoreleased instance @@ -403,7 +442,9 @@ - (NSArray *)initializeAttributeNamesWithEnv:(JNIEnv *)env { - static JNF_STATIC_MEMBER_CACHE(jm_getInitialAttributeStates, sjc_CAccessibility, "getInitialAttributeStates", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)[Z"); + GET_CACCESSIBILITY_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getInitialAttributeStates, sjc_CAccessibility, "getInitialAttributeStates", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)[Z", nil); NSMutableArray *attributeNames = [NSMutableArray arrayWithCapacity:20]; [attributeNames retain]; @@ -428,7 +469,9 @@ // Get all the other accessibility attributes states we need in one swell foop. // javaRole isn't pulled in because we need protected access to AccessibleRole.key - jbooleanArray attributeStates = (jbooleanArray)JNFCallStaticObjectMethod(env, jm_getInitialAttributeStates, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jbooleanArray attributeStates = (jbooleanArray)(*env)->CallStaticObjectMethod(env, sjc_CAccessibility, + jm_getInitialAttributeStates, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (attributeStates == NULL) return nil; jboolean *attributeStatesArray = (*env)->GetBooleanArrayElements(env, attributeStates, 0); if (attributeStatesArray == NULL) { @@ -517,11 +560,14 @@ - (void)getActionsWithEnv:(JNIEnv *)env { - static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleAction, sjc_CAccessibility, "getAccessibleAction", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleAction;"); + GET_CACCESSIBILITY_CLASS(); + DECLARE_STATIC_METHOD(jm_getAccessibleAction, sjc_CAccessibility, "getAccessibleAction", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleAction;"); // On MacOSX, text doesn't have actions, in java it does. // cmcnote: NOT TRUE - Editable text has AXShowMenu. Textfields have AXConfirm. Static text has no actions. - jobject axAction = JNFCallStaticObjectMethod(env, jm_getAccessibleAction, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jobject axAction = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibleAction, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (axAction != NULL) { //+++gdb NOTE: In MacOSX, there is just a single Action, not multiple. In java, // the first one seems to be the most basic, so this will be used. @@ -540,22 +586,26 @@ - (id)parent { - static JNF_CLASS_CACHE(sjc_Window, "java/awt/Window"); - static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleParent, sjc_CAccessibility, "getAccessibleParent", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/Accessible;"); - static JNF_STATIC_MEMBER_CACHE(sjm_getSwingAccessible, sjc_CAccessible, "getSwingAccessible", "(Ljavax/accessibility/Accessible;)Ljavax/accessibility/Accessible;"); - if(fParent == nil) { JNIEnv* env = [ThreadUtilities getJNIEnv]; + GET_CACCESSIBILITY_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(sjm_getAccessibleParent, sjc_CAccessibility, "getAccessibleParent", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/Accessible;", nil); + GET_CACCESSIBLE_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(sjm_getSwingAccessible, sjc_CAccessible, "getSwingAccessible", + "(Ljavax/accessibility/Accessible;)Ljavax/accessibility/Accessible;", nil); + DECLARE_CLASS_RETURN(sjc_Window, "java/awt/Window", nil); - jobject jparent = JNFCallStaticObjectMethod(env, sjm_getAccessibleParent, fAccessible, fComponent); + jobject jparent = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleParent, fAccessible, fComponent); + CHECK_EXCEPTION(); if (jparent == NULL) { fParent = fView; } else { AWTView *view = fView; - jobject jax = JNFCallStaticObjectMethod(env, sjm_getSwingAccessible, fAccessible); + jobject jax = (*env)->CallStaticObjectMethod(env, sjc_CAccessible, sjm_getSwingAccessible, fAccessible); - if (JNFIsInstanceOf(env, jax, &sjc_Window)) { + if ((*env)->IsInstanceOf(env, jax, sjc_Window)) { // In this case jparent is an owner toplevel and we should retrieve its own view view = [AWTView awtView:env ofAccessible:jparent]; } @@ -759,11 +809,15 @@ return [super accessibilityIndexOfChild:child]; } + JNIEnv *env = [ThreadUtilities getJNIEnv]; + GET_ACCESSIBLEINDEXINPARENT_STATIC_METHOD_RETURN(0); jint returnValue = - JNFCallStaticIntMethod( [ThreadUtilities getJNIEnv], + (*env)->CallStaticIntMethod( env, + sjc_CAccessibility, sjm_getAccessibleIndexInParent, ((JavaComponentAccessibility *)child)->fAccessible, ((JavaComponentAccessibility *)child)->fComponent ); + CHECK_EXCEPTION(); return (returnValue == -1) ? NSNotFound : returnValue; } @@ -782,10 +836,12 @@ // Flag indicating enabled state of element (NSNumber) - (NSNumber *)accessibilityEnabledAttribute { - static JNF_STATIC_MEMBER_CACHE(jm_isEnabled, sjc_CAccessibility, "isEnabled", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Z"); + JNIEnv* env = [ThreadUtilities getJNIEnv]; + GET_CACCESSIBILITY_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_isEnabled, sjc_CAccessibility, "isEnabled", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Z", nil); - JNIEnv* env = [ThreadUtilities getJNIEnv]; - NSNumber *value = [NSNumber numberWithBool:JNFCallStaticBooleanMethod(env, jm_isEnabled, fAccessible, fComponent)]; // AWT_THREADING Safe (AWTRunLoop) + NSNumber *value = [NSNumber numberWithBool:(*env)->CallStaticBooleanMethod(env, sjc_CAccessibility, jm_isEnabled, fAccessible, fComponent)]; // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (value == nil) { NSLog(@"WARNING: %s called on component that has no accessible component: %@", __FUNCTION__, self); } @@ -809,25 +865,31 @@ - (BOOL)accessibilityIsFocusedAttributeSettable { JNIEnv* env = [ThreadUtilities getJNIEnv]; + GET_CACCESSIBILITY_CLASS_RETURN(NO); + DECLARE_STATIC_METHOD_RETURN(sjm_isFocusTraversable, sjc_CAccessibility, "isFocusTraversable", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Z", NO); // According to javadoc, a component that is focusable will return true from isFocusTraversable, // as well as having AccessibleState.FOCUSABLE in its AccessibleStateSet. // We use the former heuristic; if the component focus-traversable, add a focused attribute // See also initializeAttributeNamesWithEnv: - if (JNFCallStaticBooleanMethod(env, sjm_isFocusTraversable, fAccessible, fComponent)) { // AWT_THREADING Safe (AWTRunLoop) + if ((*env)->CallStaticBooleanMethod(env, sjc_CAccessibility, sjm_isFocusTraversable, fAccessible, fComponent)) { // AWT_THREADING Safe (AWTRunLoop) return YES; } + CHECK_EXCEPTION(); return NO; } - (void)accessibilitySetFocusedAttribute:(id)value { - static JNF_STATIC_MEMBER_CACHE(jm_requestFocus, sjc_CAccessibility, "requestFocus", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)V"); + JNIEnv* env = [ThreadUtilities getJNIEnv]; + + GET_CACCESSIBILITY_CLASS(); + DECLARE_STATIC_METHOD(jm_requestFocus, sjc_CAccessibility, "requestFocus", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)V"); if ([(NSNumber*)value boolValue]) { - JNIEnv* env = [ThreadUtilities getJNIEnv]; - JNFCallStaticVoidMethod(env, jm_requestFocus, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + (*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_requestFocus, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) } } @@ -836,7 +898,12 @@ { JNIEnv* env = [ThreadUtilities getJNIEnv]; - jobject val = JNFCallStaticObjectMethod(env, sjm_getAccessibleDescription, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + GET_CACCESSIBILITY_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(sjm_getAccessibleDescription, sjc_CAccessibility, "getAccessibleDescription", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;", nil); + jobject val = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, + sjm_getAccessibleDescription, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (val == NULL) { return nil; } @@ -865,11 +932,13 @@ // Element's maximum value (id) - (id)accessibilityMaxValueAttribute { - static JNF_STATIC_MEMBER_CACHE(jm_getMaximumAccessibleValue, sjc_CAccessibility, "getMaximumAccessibleValue", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/Number;"); + JNIEnv* env = [ThreadUtilities getJNIEnv]; + GET_CACCESSIBILITY_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getMaximumAccessibleValue, sjc_CAccessibility, "getMaximumAccessibleValue", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/Number;", nil); - JNIEnv* env = [ThreadUtilities getJNIEnv]; - - jobject axValue = JNFCallStaticObjectMethod(env, jm_getMaximumAccessibleValue, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jobject axValue = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getMaximumAccessibleValue, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (axValue == NULL) { return [NSNumber numberWithInt:0]; } @@ -886,11 +955,13 @@ // Element's minimum value (id) - (id)accessibilityMinValueAttribute { - static JNF_STATIC_MEMBER_CACHE(jm_getMinimumAccessibleValue, sjc_CAccessibility, "getMinimumAccessibleValue", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/Number;"); + JNIEnv* env = [ThreadUtilities getJNIEnv]; + GET_CACCESSIBILITY_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getMinimumAccessibleValue, sjc_CAccessibility, "getMinimumAccessibleValue", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/Number;", nil); - JNIEnv* env = [ThreadUtilities getJNIEnv]; - - jobject axValue = JNFCallStaticObjectMethod(env, jm_getMinimumAccessibleValue, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jobject axValue = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getMinimumAccessibleValue, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (axValue == NULL) { return [NSNumber numberWithInt:0]; } @@ -944,7 +1015,10 @@ - (NSValue *)accessibilityPositionAttribute { JNIEnv* env = [ThreadUtilities getJNIEnv]; - jobject axComponent = JNFCallStaticObjectMethod(env, sjm_getAccessibleComponent, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + GET_ACCESSIBLECOMPONENT_STATIC_METHOD_RETURN(nil); + jobject axComponent = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleComponent, + fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); // NSAccessibility wants the bottom left point of the object in // bottom left based screen coords @@ -1005,11 +1079,14 @@ if (value == nil) { // query java if necessary - static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleRoleDisplayString, sjc_CAccessibility, "getAccessibleRoleDisplayString", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;"); + JNIEnv* env = [ThreadUtilities getJNIEnv]; + GET_CACCESSIBILITY_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getAccessibleRoleDisplayString, sjc_CAccessibility, "getAccessibleRoleDisplayString", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;", nil); - JNIEnv* env = [ThreadUtilities getJNIEnv]; - jobject axRole = JNFCallStaticObjectMethod(env, jm_getAccessibleRoleDisplayString, fAccessible, fComponent); + jobject axRole = (*env)->CallStaticObjectMethod(env, jm_getAccessibleRoleDisplayString, fAccessible, fComponent); + CHECK_EXCEPTION(); if (axRole != NULL) { value = JNFJavaToNSString(env, axRole); (*env)->DeleteLocalRef(env, axRole); @@ -1059,21 +1136,26 @@ - (void)accessibilitySetSelectedAttribute:(id)value { - static JNF_STATIC_MEMBER_CACHE( jm_requestSelection, - sjc_CAccessibility, - "requestSelection", - "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)V" ); + JNIEnv* env = [ThreadUtilities getJNIEnv]; + GET_CACCESSIBILITY_CLASS(); + DECLARE_STATIC_METHOD(jm_requestSelection, + sjc_CAccessibility, + "requestSelection", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)V"); if ([(NSNumber*)value boolValue]) { - JNIEnv* env = [ThreadUtilities getJNIEnv]; - JNFCallStaticVoidMethod(env, jm_requestSelection, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + (*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_requestSelection, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); } } // Element size (NSValue) - (NSValue *)accessibilitySizeAttribute { JNIEnv* env = [ThreadUtilities getJNIEnv]; - jobject axComponent = JNFCallStaticObjectMethod(env, sjm_getAccessibleComponent, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + GET_ACCESSIBLECOMPONENT_STATIC_METHOD_RETURN(nil); + jobject axComponent = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, + sjm_getAccessibleComponent, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); NSValue* size = [NSValue valueWithSize:getAxComponentSize(env, axComponent, fComponent)]; (*env)->DeleteLocalRef(env, axComponent); return size; @@ -1133,7 +1215,9 @@ JNIEnv* env = [ThreadUtilities getJNIEnv]; - jobject val = JNFCallStaticObjectMethod(env, sjm_getAccessibleName, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + GET_ACCESSIBLENAME_METHOD_RETURN(nil); + jobject val = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleName, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (val == NULL) { return nil; } @@ -1163,8 +1247,6 @@ // (https://docs.oracle.com/javase/8/docs/api/javax/accessibility/AccessibleValue.html#setCurrentAccessibleValue-java.lang.Number-) - (id)accessibilityValueAttribute { - static JNF_STATIC_MEMBER_CACHE(jm_getCurrentAccessibleValue, sjc_CAccessibility, "getCurrentAccessibleValue", "(Ljavax/accessibility/AccessibleValue;Ljava/awt/Component;)Ljava/lang/Number;"); - JNIEnv* env = [ThreadUtilities getJNIEnv]; // Need to handle popupmenus differently. @@ -1189,11 +1271,14 @@ JavaComponentAccessibility *selectedMenuItem = [selectedChildrenOfMenu objectAtIndex:0]; if (selectedMenuItem != nil) { + GET_CACCESSIBILITY_CLASS_RETURN(nil); + GET_ACCESSIBLENAME_METHOD_RETURN(nil); jobject itemValue = - JNFCallStaticObjectMethod( env, + (*env)->CallStaticObjectMethod( env, sjm_getAccessibleName, selectedMenuItem->fAccessible, selectedMenuItem->fComponent ); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (itemValue == NULL) { return nil; } @@ -1211,9 +1296,16 @@ // cmcnote should coalesce these calls into one java call NSNumber *num = nil; - jobject axValue = JNFCallStaticObjectMethod(env, sjm_getAccessibleValue, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + GET_CACCESSIBILITY_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(sjm_getAccessibleValue, sjc_CAccessibility, "getAccessibleValue", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleValue;", nil); + jobject axValue = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleValue, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (axValue != NULL) { - jobject str = JNFCallStaticObjectMethod(env, jm_getCurrentAccessibleValue, axValue, fComponent); + DECLARE_STATIC_METHOD_RETURN(jm_getCurrentAccessibleValue, sjc_CAccessibility, "getCurrentAccessibleValue", + "(Ljavax/accessibility/AccessibleValue;Ljava/awt/Component;)Ljava/lang/Number;", nil); + jobject str = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getCurrentAccessibleValue, axValue, fComponent); + CHECK_EXCEPTION(); if (str != NULL) { num = JNFJavaToNSNumber(env, str); // AWT_THREADING Safe (AWTRunLoop) (*env)->DeleteLocalRef(env, str); @@ -1311,8 +1403,9 @@ - (id)accessibilityHitTest:(NSPoint)point withEnv:(JNIEnv *)env { - static JNF_CLASS_CACHE(jc_Container, "java/awt/Container"); - static JNF_STATIC_MEMBER_CACHE(jm_accessibilityHitTest, sjc_CAccessibility, "accessibilityHitTest", "(Ljava/awt/Container;FF)Ljavax/accessibility/Accessible;"); + DECLARE_CLASS_RETURN(jc_Container, "java/awt/Container", nil); + DECLARE_STATIC_METHOD_RETURN(jm_accessibilityHitTest, sjc_CAccessibility, "accessibilityHitTest", + "(Ljava/awt/Container;FF)Ljavax/accessibility/Accessible;", nil); // Make it into java screen coords point.y = [[[[self view] window] screen] frame].size.height - point.y; @@ -1321,7 +1414,9 @@ id value = nil; if (JNFIsInstanceOf(env, jparent, &jc_Container)) { - jobject jaccessible = JNFCallStaticObjectMethod(env, jm_accessibilityHitTest, jparent, (jfloat)point.x, (jfloat)point.y); // AWT_THREADING Safe (AWTRunLoop) + jobject jaccessible = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_accessibilityHitTest, + jparent, (jfloat)point.x, (jfloat)point.y); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (jaccessible != NULL) { value = [JavaComponentAccessibility createWithAccessible:jaccessible withEnv:env withView:fView]; (*env)->DeleteLocalRef(env, jaccessible); @@ -1344,19 +1439,22 @@ - (id)accessibilityFocusedUIElement { - static JNF_STATIC_MEMBER_CACHE(jm_getFocusOwner, sjc_CAccessibility, "getFocusOwner", "(Ljava/awt/Component;)Ljavax/accessibility/Accessible;"); - JNIEnv *env = [ThreadUtilities getJNIEnv]; + DECLARE_STATIC_METHOD_RETURN(jm_getFocusOwner, sjc_CAccessibility, "getFocusOwner", + "(Ljava/awt/Component;)Ljavax/accessibility/Accessible;", nil); id value = nil; NSWindow* hostWindow = [[self->fView window] retain]; - jobject focused = JNFCallStaticObjectMethod(env, jm_getFocusOwner, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jobject focused = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getFocusOwner, fComponent); // AWT_THREADING Safe (AWTRunLoop) [hostWindow release]; + CHECK_EXCEPTION(); if (focused != NULL) { - if (JNFIsInstanceOf(env, focused, &sjc_Accessible)) { + DECLARE_CLASS_RETURN(sjc_Accessible, "javax/accessibility/Accessible", nil); + if ((*env)->IsInstanceOf(env, focused, sjc_Accessible)) { value = [JavaComponentAccessibility createWithAccessible:focused withEnv:env withView:fView]; } + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, focused); } @@ -1534,7 +1632,10 @@ - (NSArray *)tabControlsWithEnv:(JNIEnv *)env withTabGroupAxContext:(jobject)axContext withTabCode:(NSInteger)whichTabs allowIgnored:(BOOL)allowIgnored { - jobjectArray jtabsAndRoles = (jobjectArray)JNFCallStaticObjectMethod(env, jm_getChildrenAndRoles, fAccessible, fComponent, whichTabs, allowIgnored); // AWT_THREADING Safe (AWTRunLoop) + GET_CHILDRENANDROLES_METHOD_RETURN(nil); + jobjectArray jtabsAndRoles = (jobjectArray)(*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getChildrenAndRoles, + fAccessible, fComponent, whichTabs, allowIgnored); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if(jtabsAndRoles == NULL) return nil; jsize arrayLen = (*env)->GetArrayLength(env, jtabsAndRoles); @@ -1550,7 +1651,10 @@ (*env)->DeleteLocalRef(env, jtabsAndRoles); return nil; } - jobject jkey = JNFGetObjectField(env, jtabJavaRole, sjf_key); + DECLARE_CLASS_RETURN(sjc_AccessibleRole, "javax/accessibility/AccessibleRole", nil); + DECLARE_FIELD_RETURN(sjf_key, sjc_AccessibleRole, "key", "Ljava/lang/String;", nil); + jobject jkey = (*env)->GetObjectField(env, jtabJavaRole, sjf_key); + CHECK_EXCEPTION(); NSString *tabJavaRole = JNFJavaToNSString(env, jkey); (*env)->DeleteLocalRef(env, jkey); @@ -1852,20 +1956,24 @@ * This may use LWCToolkit.invokeAndWait(); don't call while holding fLock * and try to pass a component so the event happens on the correct thread. */ -static JNF_CLASS_CACHE(sjc_Object, "java/lang/Object"); static BOOL ObjectEquals(JNIEnv *env, jobject a, jobject b, jobject component) { - static JNF_MEMBER_CACHE(jm_equals, sjc_Object, "equals", "(Ljava/lang/Object;)Z"); + DECLARE_CLASS_RETURN(sjc_Object, "java/lang/Object", NO); + DECLARE_METHOD_RETURN(jm_equals, sjc_Object, "equals", "(Ljava/lang/Object;)Z", NO); if ((a == NULL) && (b == NULL)) return YES; if ((a == NULL) || (b == NULL)) return NO; if (pthread_main_np() != 0) { // If we are on the AppKit thread - static JNF_CLASS_CACHE(sjc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit"); - static JNF_STATIC_MEMBER_CACHE(jm_doEquals, sjc_LWCToolkit, "doEquals", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/awt/Component;)Z"); - return JNFCallStaticBooleanMethod(env, jm_doEquals, a, b, component); // AWT_THREADING Safe (AWTRunLoopMode) + DECLARE_CLASS_RETURN(sjc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit", NO); + DECLARE_STATIC_METHOD_RETURN(jm_doEquals, sjc_LWCToolkit, "doEquals", + "(Ljava/lang/Object;Ljava/lang/Object;Ljava/awt/Component;)Z", NO); + return (*env)->CallStaticBooleanMethod(env, sjc_LWCToolkit, jm_doEquals, a, b, component); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); } - return JNFCallBooleanMethod(env, a, jm_equals, b); // AWT_THREADING Safe (!appKit) + jboolean jb = (*env)->CallBooleanMethod(env, a, jm_equals, b); // AWT_THREADING Safe (!appKit) + CHECK_EXCEPTION(); + return jb; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaTextAccessibility.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaTextAccessibility.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaTextAccessibility.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaTextAccessibility.m @@ -27,12 +27,32 @@ #import "JavaAccessibilityAction.h" #import "JavaAccessibilityUtilities.h" #import "ThreadUtilities.h" +#import "JNIUtilities.h" +static jclass sjc_CAccessibility = NULL; +#define GET_CACCESSIBLITY_CLASS() \ + GET_CLASS(sjc_CAccessibility, "sun/lwawt/macosx/CAccessibility"); +#define GET_CACCESSIBLITY_CLASS_RETURN(ret) \ + GET_CLASS_RETURN(sjc_CAccessibility, "sun/lwawt/macosx/CAccessibility", ret); -static JNF_CLASS_CACHE(sjc_CAccessibleText, "sun/lwawt/macosx/CAccessibleText"); -static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleText, sjc_CAccessibility, "getAccessibleText", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleText;"); -static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleEditableText, sjc_CAccessibleText, "getAccessibleEditableText", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleEditableText;"); -static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleName, sjc_CAccessibility, "getAccessibleName", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;"); +static jmethodID sjm_getAccessibleText = NULL; +#define GET_ACCESSIBLETEXT_METHOD_RETURN(ret) \ + GET_CACCESSIBLITY_CLASS_RETURN(ret); \ + GET_STATIC_METHOD_RETURN(sjm_getAccessibleText, sjc_CAccessibility, "getAccessibleText", \ + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleText;", ret); + +static jclass sjc_CAccessibleText = NULL; +#define GET_CACCESSIBLETEXT_CLASS() \ + GET_CLASS(sjc_CAccessibleText, "sun/lwawt/macosx/CAccessibleText"); +#define GET_CACCESSIBLETEXT_CLASS_RETURN(ret) \ + GET_CLASS_RETURN(sjc_CAccessibleText, "sun/lwawt/macosx/CAccessibleText", ret); + +static jmethodID sjm_getAccessibleEditableText = NULL; +#define GET_ACCESSIBLEEDITABLETEXT_METHOD_RETURN(ret) \ + GET_CACCESSIBLETEXT_CLASS_RETURN(ret); \ + GET_STATIC_METHOD_RETURN(sjm_getAccessibleEditableText, sjc_CAccessibleText, "getAccessibleEditableText", \ + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleEditableText;", ret); + /* * Converts an int array to an NSRange wrapped inside an NSValue @@ -108,9 +128,14 @@ - (NSString *)accessibilityValueAttribute { JNIEnv *env = [ThreadUtilities getJNIEnv]; + GET_CACCESSIBLITY_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(sjm_getAccessibleName, sjc_CAccessibility, "getAccessibleName", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;", nil); if ([[self accessibilityRoleAttribute] isEqualToString:NSAccessibilityStaticTextRole]) { // if it's static text, the AppKit AXValue is the java accessibleName - jobject axName = JNFCallStaticObjectMethod(env, sjm_getAccessibleName, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jobject axName = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, + sjm_getAccessibleName, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (axName != NULL) { NSString* str = JNFJavaToNSString(env, axName); (*env)->DeleteLocalRef(env, axName); @@ -120,15 +145,25 @@ } // cmcnote: inefficient to make three distinct JNI calls. Coalesce. radr://3951923 - jobject axText = JNFCallStaticObjectMethod(env, sjm_getAccessibleText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + GET_ACCESSIBLETEXT_METHOD_RETURN(@""); + jobject axText = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, + sjm_getAccessibleText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (axText == NULL) return nil; (*env)->DeleteLocalRef(env, axText); - jobject axEditableText = JNFCallStaticObjectMethod(env, sjm_getAccessibleEditableText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + GET_ACCESSIBLEEDITABLETEXT_METHOD_RETURN(nil); + jobject axEditableText = (*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, + sjm_getAccessibleEditableText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (axEditableText == NULL) return nil; - static JNF_STATIC_MEMBER_CACHE(jm_getTextRange, sjc_CAccessibleText, "getTextRange", "(Ljavax/accessibility/AccessibleEditableText;IILjava/awt/Component;)Ljava/lang/String;"); - jobject jrange = JNFCallStaticObjectMethod(env, jm_getTextRange, axEditableText, 0, getAxTextCharCount(env, axEditableText, fComponent), fComponent); + DECLARE_STATIC_METHOD_RETURN(jm_getTextRange, sjc_CAccessibleText, "getTextRange", + "(Ljavax/accessibility/AccessibleEditableText;IILjava/awt/Component;)Ljava/lang/String;", nil); + CHECK_EXCEPTION(); + jobject jrange = (*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, jm_getTextRange, + axEditableText, 0, getAxTextCharCount(env, axEditableText, fComponent), fComponent); + CHECK_EXCEPTION(); NSString *string = JNFJavaToNSString(env, jrange); // AWT_THREADING Safe (AWTRunLoop) (*env)->DeleteLocalRef(env, jrange); @@ -145,7 +180,10 @@ if (!isEnabled) return NO; JNIEnv* env = [ThreadUtilities getJNIEnv]; - jobject axEditableText = JNFCallStaticObjectMethod(env, sjm_getAccessibleEditableText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + GET_ACCESSIBLEEDITABLETEXT_METHOD_RETURN(NO); + jobject axEditableText = (*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, + sjm_getAccessibleEditableText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (axEditableText == NULL) return NO; (*env)->DeleteLocalRef(env, axEditableText); return YES; @@ -163,8 +201,12 @@ - (NSString *)accessibilitySelectedTextAttribute { JNIEnv* env = [ThreadUtilities getJNIEnv]; - static JNF_STATIC_MEMBER_CACHE(jm_getSelectedText, sjc_CAccessibleText, "getSelectedText", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;"); - jobject axText = JNFCallStaticObjectMethod(env, jm_getSelectedText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + GET_CACCESSIBLETEXT_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getSelectedText, sjc_CAccessibleText, "getSelectedText", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;", nil); + jobject axText = (*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, jm_getSelectedText, + fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (axText == NULL) return @""; NSString* str = JNFJavaToNSString(env, axText); (*env)->DeleteLocalRef(env, axText); @@ -187,16 +229,24 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; jstring jstringValue = JNFNSToJavaString(env, (NSString *)value); - static JNF_STATIC_MEMBER_CACHE(jm_setSelectedText, sjc_CAccessibleText, "setSelectedText", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;Ljava/lang/String;)V"); - JNFCallStaticVoidMethod(env, jm_setSelectedText, fAccessible, fComponent, jstringValue); // AWT_THREADING Safe (AWTRunLoop) + GET_CACCESSIBLETEXT_CLASS(); + DECLARE_STATIC_METHOD(jm_setSelectedText, sjc_CAccessibleText, "setSelectedText", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;Ljava/lang/String;)V"); + (*env)->CallStaticVoidMethod(env, sjc_CAccessibleText, jm_setSelectedText, + fAccessible, fComponent, jstringValue); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); } // Range of selected text (NSValue) - (NSValue *)accessibilitySelectedTextRangeAttribute { JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_STATIC_MEMBER_CACHE(jm_getSelectedTextRange, sjc_CAccessibleText, "getSelectedTextRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)[I"); - jintArray axTextRange = JNFCallStaticObjectMethod(env, jm_getSelectedTextRange, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + GET_CACCESSIBLETEXT_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getSelectedTextRange, sjc_CAccessibleText, "getSelectedTextRange", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)[I", nil); + jintArray axTextRange = (*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, + jm_getSelectedTextRange, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (axTextRange == NULL) return nil; return javaIntArrayToNSRangeValue(env, axTextRange); @@ -221,8 +271,12 @@ jint endIndex = startIndex + range.length; JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_STATIC_MEMBER_CACHE(jm_setSelectedTextRange, sjc_CAccessibleText, "setSelectedTextRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)V"); - JNFCallStaticVoidMethod(env, jm_setSelectedTextRange, fAccessible, fComponent, startIndex, endIndex); // AWT_THREADING Safe (AWTRunLoop) + GET_CACCESSIBLETEXT_CLASS(); + DECLARE_STATIC_METHOD(jm_setSelectedTextRange, sjc_CAccessibleText, "setSelectedTextRange", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)V"); + (*env)->CallStaticVoidMethod(env, sjc_CAccessibleText, jm_setSelectedTextRange, + fAccessible, fComponent, startIndex, endIndex); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); } - (NSNumber *)accessibilityNumberOfCharactersAttribute @@ -230,7 +284,10 @@ // cmcnote: should coalesce these two calls - radr://3951923 // also, static text doesn't always have accessibleText. if axText is null, should get the charcount of the accessibleName instead JNIEnv *env = [ThreadUtilities getJNIEnv]; - jobject axText = JNFCallStaticObjectMethod(env, sjm_getAccessibleText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + GET_ACCESSIBLETEXT_METHOD_RETURN(nil); + jobject axText = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, + sjm_getAccessibleText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); NSNumber* num = [NSNumber numberWithInt:getAxTextCharCount(env, axText, fComponent)]; (*env)->DeleteLocalRef(env, axText); return num; @@ -244,8 +301,12 @@ - (NSValue *)accessibilityVisibleCharacterRangeAttribute { JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_STATIC_MEMBER_CACHE(jm_getVisibleCharacterRange, sjc_CAccessibleText, "getVisibleCharacterRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)[I"); - jintArray axTextRange = JNFCallStaticObjectMethod(env, jm_getVisibleCharacterRange, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + GET_CACCESSIBLETEXT_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getVisibleCharacterRange, sjc_CAccessibleText, "getVisibleCharacterRange", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)[I", nil); + jintArray axTextRange = (*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, + jm_getVisibleCharacterRange, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (axTextRange == NULL) return nil; return javaIntArrayToNSRangeValue(env, axTextRange); @@ -262,8 +323,12 @@ - (NSValue *)accessibilityInsertionPointLineNumberAttribute { JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_STATIC_MEMBER_CACHE(jm_getLineNumberForInsertionPoint, sjc_CAccessibleText, "getLineNumberForInsertionPoint", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)I"); - jint row = JNFCallStaticIntMethod(env, jm_getLineNumberForInsertionPoint, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + GET_CACCESSIBLETEXT_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getLineNumberForInsertionPoint, sjc_CAccessibleText, + "getLineNumberForInsertionPoint", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)I", nil); + jint row = (*env)->CallStaticIntMethod(env, sjc_CAccessibleText, + jm_getLineNumberForInsertionPoint, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (row < 0) return nil; return [NSNumber numberWithInt:row]; } @@ -297,12 +362,17 @@ NSRange range = [(NSValue *)parameter rangeValue]; JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_STATIC_MEMBER_CACHE(jm_getBoundsForRange, sjc_CAccessibleText, "getBoundsForRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)[D"); - jdoubleArray axBounds = (jdoubleArray)JNFCallStaticObjectMethod(env, jm_getBoundsForRange, fAccessible, fComponent, range.location, range.length); // AWT_THREADING Safe (AWTRunLoop) + GET_CACCESSIBLETEXT_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getBoundsForRange, sjc_CAccessibleText, "getBoundsForRange", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)[D", nil); + jdoubleArray axBounds = (jdoubleArray)(*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, jm_getBoundsForRange, + fAccessible, fComponent, range.location, range.length); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (axBounds == NULL) return nil; // We cheat because we know that the array is 4 elements long (x, y, width, height) jdouble *values = (*env)->GetDoubleArrayElements(env, axBounds, 0); + CHECK_EXCEPTION(); if (values == NULL) { // Note: Java will not be on the stack here so a java exception can't happen and no need to call ExceptionCheck. NSLog(@"%s failed calling GetDoubleArrayElements", __FUNCTION__); @@ -324,8 +394,12 @@ if (line == nil) return nil; JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_STATIC_MEMBER_CACHE(jm_getLineNumberForIndex, sjc_CAccessibleText, "getLineNumberForIndex", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)I"); - jint row = JNFCallStaticIntMethod(env, jm_getLineNumberForIndex, fAccessible, fComponent, [line intValue]); // AWT_THREADING Safe (AWTRunLoop) + GET_CACCESSIBLETEXT_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getLineNumberForIndex, sjc_CAccessibleText, "getLineNumberForIndex", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)I", nil); + jint row = (*env)->CallStaticIntMethod(env, sjc_CAccessibleText, jm_getLineNumberForIndex, + fAccessible, fComponent, [line intValue]); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (row < 0) return nil; return [NSNumber numberWithInt:row]; } @@ -336,8 +410,12 @@ if (line == nil) return nil; JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_STATIC_MEMBER_CACHE(jm_getRangeForLine, sjc_CAccessibleText, "getRangeForLine", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)[I"); - jintArray axTextRange = (jintArray)JNFCallStaticObjectMethod(env, jm_getRangeForLine, fAccessible, fComponent, [line intValue]); // AWT_THREADING Safe (AWTRunLoop) + GET_CACCESSIBLETEXT_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getRangeForLine, sjc_CAccessibleText, "getRangeForLine", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)[I", nil); + jintArray axTextRange = (jintArray)(*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, + jm_getRangeForLine, fAccessible, fComponent, [line intValue]); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (axTextRange == NULL) return nil; return javaIntArrayToNSRangeValue(env,axTextRange); @@ -362,9 +440,12 @@ NSRange range = [(NSValue *)parameter rangeValue]; JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_STATIC_MEMBER_CACHE(jm_getStringForRange, sjc_CAccessibleText, "getStringForRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)Ljava/lang/String;"); - jstring jstringForRange = (jstring)JNFCallStaticObjectMethod(env, jm_getStringForRange, fAccessible, fComponent, range.location, range.length); // AWT_THREADING Safe (AWTRunLoop) - + GET_CACCESSIBLETEXT_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getStringForRange, sjc_CAccessibleText, "getStringForRange", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)Ljava/lang/String;", nil); + jstring jstringForRange = (jstring)(*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, jm_getStringForRange, + fAccessible, fComponent, range.location, range.length); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (jstringForRange == NULL) return @""; NSString* str = JNFJavaToNSString(env, jstringForRange); (*env)->DeleteLocalRef(env, jstringForRange); @@ -391,8 +472,12 @@ point.y = [[[[self view] window] screen] frame].size.height - point.y; // flip into java screen coords (0 is at upper-left corner of screen) JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_STATIC_MEMBER_CACHE(jm_getCharacterIndexAtPosition, sjc_CAccessibleText, "getCharacterIndexAtPosition", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)I"); - jint charIndex = JNFCallStaticIntMethod(env, jm_getCharacterIndexAtPosition, fAccessible, fComponent, point.x, point.y); // AWT_THREADING Safe (AWTRunLoop) + GET_CACCESSIBLETEXT_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getCharacterIndexAtPosition, sjc_CAccessibleText, "getCharacterIndexAtPosition", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)I", nil); + jint charIndex = (*env)->CallStaticIntMethod(env, sjc_CAccessibleText, jm_getCharacterIndexAtPosition, + fAccessible, fComponent, point.x, point.y); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (charIndex == -1) return nil; // AccessibleText.getIndexAtPoint returns -1 for an invalid point @@ -420,8 +505,12 @@ NSUInteger index = [(NSNumber *)parameter unsignedIntegerValue]; JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_STATIC_MEMBER_CACHE(jm_getRangeForIndex, sjc_CAccessibleText, "getRangeForIndex", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)[I"); - jintArray axTextRange = (jintArray)JNFCallStaticObjectMethod(env, jm_getRangeForIndex, fAccessible, fComponent, index); // AWT_THREADING Safe (AWTRunLoop) + GET_CACCESSIBLETEXT_CLASS_RETURN(nil); + DECLARE_STATIC_METHOD_RETURN(jm_getRangeForIndex, sjc_CAccessibleText, "getRangeForIndex", + "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)[I", nil); + jintArray axTextRange = (jintArray)(*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, jm_getRangeForIndex, + fAccessible, fComponent, index); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); if (axTextRange == NULL) return nil; return javaIntArrayToNSRangeValue(env, axTextRange); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m @@ -29,7 +29,7 @@ #import #import -#include "jni_util.h" +#import "JNIUtilities.h" #import "LWCToolkit.h" #import "ThreadUtilities.h" #import "CSystemColors.h" @@ -184,9 +184,10 @@ - (void)perform { JNIEnv* env = [ThreadUtilities getJNIEnvUncached]; - static JNF_CLASS_CACHE(sjc_Runnable, "java/lang/Runnable"); - static JNF_MEMBER_CACHE(jm_Runnable_run, sjc_Runnable, "run", "()V"); - JNFCallVoidMethod(env, self.runnable, jm_Runnable_run); + DECLARE_CLASS(sjc_Runnable, "java/lang/Runnable"); + DECLARE_METHOD(jm_Runnable_run, sjc_Runnable, "run", "()V"); + (*env)->CallVoidMethod(env, self.runnable, jm_Runnable_run); + CHECK_EXCEPTION(); [self release]; } @end @@ -195,15 +196,16 @@ AWT_ASSERT_APPKIT_THREAD; JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_CLASS_CACHE(jc_AWTAutoShutdown, "sun/awt/AWTAutoShutdown"); + DECLARE_CLASS(jc_AWTAutoShutdown, "sun/awt/AWTAutoShutdown"); if (busy) { - static JNF_STATIC_MEMBER_CACHE(jm_notifyBusyMethod, jc_AWTAutoShutdown, "notifyToolkitThreadBusy", "()V"); - JNFCallStaticVoidMethod(env, jm_notifyBusyMethod); + DECLARE_STATIC_METHOD(jm_notifyBusyMethod, jc_AWTAutoShutdown, "notifyToolkitThreadBusy", "()V"); + (*env)->CallStaticVoidMethod(env, jc_AWTAutoShutdown, jm_notifyBusyMethod); } else { - static JNF_STATIC_MEMBER_CACHE(jm_notifyFreeMethod, jc_AWTAutoShutdown, "notifyToolkitThreadFree", "()V"); - JNFCallStaticVoidMethod(env, jm_notifyFreeMethod); + DECLARE_STATIC_METHOD(jm_notifyFreeMethod, jc_AWTAutoShutdown, "notifyToolkitThreadFree", "()V"); + (*env)->CallStaticVoidMethod(env, jc_AWTAutoShutdown, jm_notifyFreeMethod); } + CHECK_EXCEPTION(); } static void setUpAWTAppKit(BOOL installObservers) @@ -243,9 +245,11 @@ } JNIEnv* env = [ThreadUtilities getJNIEnv]; - static JNF_CLASS_CACHE(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit"); - static JNF_STATIC_MEMBER_CACHE(jsm_installToolkitThreadInJava, jc_LWCToolkit, "installToolkitThreadInJava", "()V"); - JNFCallStaticVoidMethod(env, jsm_installToolkitThreadInJava); + DECLARE_CLASS(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit"); + DECLARE_STATIC_METHOD(jsm_installToolkitThreadInJava, jc_LWCToolkit, "installToolkitThreadInJava", "()V"); + (*env)->CallStaticVoidMethod(env, jc_LWCToolkit, jsm_installToolkitThreadInJava); + CHECK_EXCEPTION(); + } BOOL isSWTInWebStart(JNIEnv* env) { @@ -753,6 +757,7 @@ jmethodID getButtonDownMasksID = (*env)->GetStaticMethodID(env, inputEventClazz, "getButtonDownMasks", "()[I"); CHECK_NULL(getButtonDownMasksID); jintArray obj = (jintArray)(*env)->CallStaticObjectMethod(env, inputEventClazz, getButtonDownMasksID); + CHECK_EXCEPTION(); jint * tmp = (*env)->GetIntArrayElements(env, obj, JNI_FALSE); CHECK_NULL(tmp); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrintModel.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrintModel.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrintModel.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrintModel.m @@ -30,6 +30,7 @@ #import "PrinterView.h" #import "ThreadUtilities.h" +#import "JNIUtilities.h" @implementation PrintModel @@ -88,9 +89,10 @@ [self retain]; [printerView retain]; - static JNF_CLASS_CACHE(jc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob"); - static JNF_STATIC_MEMBER_CACHE(jm_detachPrintLoop, jc_CPrinterJob, "detachPrintLoop", "(JJ)V"); - JNFCallStaticVoidMethod(env, jm_detachPrintLoop, ptr_to_jlong(self), ptr_to_jlong(printerView)); // AWT_THREADING Safe (known object) + DECLARE_CLASS_RETURN(jc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob", NO); + DECLARE_STATIC_METHOD_RETURN(jm_detachPrintLoop, jc_CPrinterJob, "detachPrintLoop", "(JJ)V", NO); + (*env)->CallStaticVoidMethod(env, jc_CPrinterJob, jm_detachPrintLoop, ptr_to_jlong(self), ptr_to_jlong(printerView)); // AWT_THREADING Safe (known object) + CHECK_EXCEPTION(); } return fResult; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m @@ -32,10 +32,11 @@ #import "ThreadUtilities.h" #import "GeomUtilities.h" - +#import "JNIUtilities.h" -static JNF_CLASS_CACHE(sjc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob"); -static JNF_CLASS_CACHE(sjc_PageFormat, "java/awt/print/PageFormat"); +static jclass sjc_CPrinterJob = NULL; +#define GET_CPRINTERJOB_CLASS() (sjc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob"); +#define GET_CPRINTERJOB_CLASS_RETURN(ret) GET_CLASS_RETURN(sjc_CPrinterJob, "sun/lwawt/macosx/CPrinterJob", ret); @implementation PrinterView @@ -80,15 +81,17 @@ { AWT_ASSERT_NOT_APPKIT_THREAD; - static JNF_MEMBER_CACHE(jm_printToPathGraphics, sjc_CPrinterJob, "printToPathGraphics", "(Lsun/print/PeekGraphics;Ljava/awt/print/PrinterJob;Ljava/awt/print/Printable;Ljava/awt/print/PageFormat;IJ)V"); + JNIEnv* env = [ThreadUtilities getJNIEnvUncached]; + + GET_CPRINTERJOB_CLASS(); + DECLARE_METHOD(jm_printToPathGraphics, sjc_CPrinterJob, "printToPathGraphics", + "(Lsun/print/PeekGraphics;Ljava/awt/print/PrinterJob;Ljava/awt/print/Printable;Ljava/awt/print/PageFormat;IJ)V"); // Create and draw into a new CPrinterGraphics with the current Context. assert(fCurPageFormat != NULL); assert(fCurPainter != NULL); assert(fCurPeekGraphics != NULL); - JNIEnv* env = [ThreadUtilities getJNIEnvUncached]; - if ([self cancelCheck:env]) { [self releaseReferences:env]; @@ -102,7 +105,9 @@ CGContextRef cgRef = (CGContextRef)[[printLoop context] graphicsPort]; CGContextSaveGState(cgRef); //04/28/2004: state needs to be saved here due to addition of lazy state management - JNFCallVoidMethod(env, fPrinterJob, jm_printToPathGraphics, fCurPeekGraphics, fPrinterJob, fCurPainter, fCurPageFormat, jPageIndex, context); // AWT_THREADING Safe (AWTRunLoop) + (*env)->CallVoidMethod(env, fPrinterJob, jm_printToPathGraphics, fCurPeekGraphics, fPrinterJob, + fCurPainter, fCurPageFormat, jPageIndex, context); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); CGContextRestoreGState(cgRef); @@ -113,11 +118,11 @@ { AWT_ASSERT_NOT_APPKIT_THREAD; - static JNF_MEMBER_CACHE(jm_getJobName, sjc_CPrinterJob, "getJobName", "()Ljava/lang/String;"); + JNIEnv* env = [ThreadUtilities getJNIEnvUncached]; + GET_CPRINTERJOB_CLASS_RETURN(nil); + DECLARE_METHOD_RETURN(jm_getJobName, sjc_CPrinterJob, "getJobName", "()Ljava/lang/String;", nil); - JNIEnv* env = [ThreadUtilities getJNIEnvUncached]; - - jobject o = JNFCallObjectMethod(env, fPrinterJob, jm_getJobName); // AWT_THREADING Safe (known object) + jobject o = (*env)->CallObjectMethod(env, fPrinterJob, jm_getJobName); // AWT_THREADING Safe (known object) id result = JNFJavaToNSString(env, o); (*env)->DeleteLocalRef(env, o); return result; @@ -151,9 +156,14 @@ { AWT_ASSERT_NOT_APPKIT_THREAD; - static JNF_MEMBER_CACHE(jm_getPageformatPrintablePeekgraphics, sjc_CPrinterJob, "getPageformatPrintablePeekgraphics", "(I)[Ljava/lang/Object;"); - static JNF_MEMBER_CACHE(jm_printAndGetPageFormatArea, sjc_CPrinterJob, "printAndGetPageFormatArea", "(Ljava/awt/print/Printable;Ljava/awt/Graphics;Ljava/awt/print/PageFormat;I)Ljava/awt/geom/Rectangle2D;"); - static JNF_MEMBER_CACHE(jm_getOrientation, sjc_PageFormat, "getOrientation", "()I"); + JNIEnv* env = [ThreadUtilities getJNIEnvUncached]; + GET_CPRINTERJOB_CLASS_RETURN(NSZeroRect); + DECLARE_METHOD_RETURN(jm_getPageformatPrintablePeekgraphics, sjc_CPrinterJob, + "getPageformatPrintablePeekgraphics", "(I)[Ljava/lang/Object;", NSZeroRect); + DECLARE_METHOD_RETURN(jm_printAndGetPageFormatArea, sjc_CPrinterJob, "printAndGetPageFormatArea", + "(Ljava/awt/print/Printable;Ljava/awt/Graphics;Ljava/awt/print/PageFormat;I)Ljava/awt/geom/Rectangle2D;", NSZeroRect); + 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 // Actual fix that will keep these assertions from being true is radr://3205462 , @@ -162,7 +172,6 @@ //assert(fCurPainter == NULL); //assert(fCurPeekGraphics == NULL); - JNIEnv* env = [ThreadUtilities getJNIEnvUncached]; if(fCurPageFormat != NULL) { JNFDeleteGlobalRef(env, fCurPageFormat); } @@ -184,7 +193,9 @@ return NSZeroRect; } - jobjectArray objectArray = JNFCallObjectMethod(env, fPrinterJob, jm_getPageformatPrintablePeekgraphics, jPageNumber); // AWT_THREADING Safe (AWTRunLoopMode) + jobjectArray objectArray = (*env)->CallObjectMethod(env, fPrinterJob, + jm_getPageformatPrintablePeekgraphics, jPageNumber); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); if (objectArray != NULL) { // Get references to the return objects -> PageFormat, Printable, PeekGraphics // Cheat - we know we either got NULL or a 3 element array @@ -201,12 +212,14 @@ (*env)->DeleteLocalRef(env, peekGraphics); // Actually print and get the PageFormatArea - jobject pageFormatArea = JNFCallObjectMethod(env, fPrinterJob, jm_printAndGetPageFormatArea, fCurPainter, fCurPeekGraphics, fCurPageFormat, jPageNumber); // AWT_THREADING Safe (AWTRunLoopMode) + jobject pageFormatArea = (*env)->CallObjectMethod(env, fPrinterJob, jm_printAndGetPageFormatArea, fCurPainter, + fCurPeekGraphics, fCurPageFormat, jPageNumber); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); if (pageFormatArea != NULL) { NSPrintingOrientation currentOrientation = [[[NSPrintOperation currentOperation] printInfo] orientation]; // set page orientation - switch (JNFCallIntMethod(env, fCurPageFormat, jm_getOrientation)) { + switch ((*env)->CallIntMethod(env, fCurPageFormat, jm_getOrientation)) { case java_awt_print_PageFormat_PORTRAIT: default: if (currentOrientation != NSPortraitOrientation) { @@ -223,6 +236,7 @@ } break; } + CHECK_EXCEPTION(); result = JavaToNSRect(env, pageFormatArea); (*env)->DeleteLocalRef(env, pageFormatArea); } else { @@ -243,9 +257,12 @@ { AWT_ASSERT_NOT_APPKIT_THREAD; - static JNF_MEMBER_CACHE(jm_cancelCheck, sjc_CPrinterJob, "cancelCheck", "()Z"); + GET_CPRINTERJOB_CLASS_RETURN(NO); + DECLARE_METHOD_RETURN(jm_cancelCheck, sjc_CPrinterJob, "cancelCheck", "()Z", NO); - return JNFCallBooleanMethod(env, fPrinterJob, jm_cancelCheck); // AWT_THREADING Safe (known object) + BOOL b = (*env)->CallBooleanMethod(env, fPrinterJob, jm_cancelCheck); // AWT_THREADING Safe (known object) + CHECK_EXCEPTION(); + return b; } // This is called by -[PrintModel safePrintLoop] @@ -253,8 +270,9 @@ { AWT_ASSERT_NOT_APPKIT_THREAD; - static JNF_MEMBER_CACHE(jf_completePrintLoop, sjc_CPrinterJob, "completePrintLoop", "()V"); - JNFCallVoidMethod(env, fPrinterJob, jf_completePrintLoop); + DECLARE_METHOD(jf_completePrintLoop, sjc_CPrinterJob, "completePrintLoop", "()V"); + (*env)->CallVoidMethod(env, fPrinterJob, jf_completePrintLoop); + CHECK_EXCEPTION(); // Clean up after ourselves // Can't put these into -dealloc since that happens (potentially) after the JNIEnv is stale diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/awt_DrawingSurface.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/awt_DrawingSurface.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/awt_DrawingSurface.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/awt_DrawingSurface.m @@ -23,11 +23,10 @@ * questions. */ -#import +#import "JNIUtilities.h" #import "AWTSurfaceLayers.h" -#import "jni_util.h" JNIEXPORT JAWT_DrawingSurfaceInfo* JNICALL awt_DrawingSurface_GetDrawingSurfaceInfo (JAWT_DrawingSurface* ds) @@ -37,32 +36,32 @@ JNIEnv *env = ds->env; jobject target = ds->target; - static JNF_CLASS_CACHE(jc_Component, "java/awt/Component"); - static JNF_MEMBER_CACHE(jf_peer, jc_Component, "peer", "Ljava/awt/peer/ComponentPeer;"); - jobject peer = JNFGetObjectField(env, target, jf_peer); + DECLARE_CLASS_RETURN(jc_Component, "java/awt/Component", NULL); + DECLARE_FIELD_RETURN(jf_peer, jc_Component, "peer", "Ljava/awt/peer/ComponentPeer;", NULL); + jobject peer = (*env)->GetObjectField(env, target, jf_peer); - static JNF_CLASS_CACHE(jc_ComponentPeer, "sun/lwawt/LWComponentPeer"); - static JNF_MEMBER_CACHE(jf_platformComponent, jc_ComponentPeer, - "platformComponent", "Lsun/lwawt/PlatformComponent;"); - jobject platformComponent = JNFGetObjectField(env, peer, jf_platformComponent); + DECLARE_CLASS_RETURN(jc_ComponentPeer, "sun/lwawt/LWComponentPeer", NULL); + DECLARE_FIELD_RETURN(jf_platformComponent, jc_ComponentPeer, + "platformComponent", "Lsun/lwawt/PlatformComponent;", NULL); + jobject platformComponent = (*env)->GetObjectField(env, peer, jf_platformComponent); - static JNF_CLASS_CACHE(jc_PlatformComponent, "sun/lwawt/macosx/CPlatformComponent"); - static JNF_MEMBER_CACHE(jm_getPointer, jc_PlatformComponent, "getPointer", "()J"); - AWTSurfaceLayers *surfaceLayers = jlong_to_ptr(JNFCallLongMethod(env, platformComponent, jm_getPointer)); + DECLARE_CLASS_RETURN(jc_PlatformComponent, "sun/lwawt/macosx/CPlatformComponent", NULL); + DECLARE_METHOD_RETURN(jm_getPointer, jc_PlatformComponent, "getPointer", "()J", NULL); + AWTSurfaceLayers *surfaceLayers = jlong_to_ptr((*env)->CallLongMethod(env, platformComponent, jm_getPointer)); // REMIND: assert(surfaceLayers) dsi->platformInfo = surfaceLayers; dsi->ds = ds; - static JNF_MEMBER_CACHE(jf_x, jc_Component, "x", "I"); - static JNF_MEMBER_CACHE(jf_y, jc_Component, "y", "I"); - static JNF_MEMBER_CACHE(jf_width, jc_Component, "width", "I"); - static JNF_MEMBER_CACHE(jf_height, jc_Component, "height", "I"); + DECLARE_FIELD_RETURN(jf_x, jc_Component, "x", "I", NULL); + DECLARE_FIELD_RETURN(jf_y, jc_Component, "y", "I", NULL); + DECLARE_FIELD_RETURN(jf_width, jc_Component, "width", "I", NULL); + DECLARE_FIELD_RETURN(jf_height, jc_Component, "height", "I", NULL); - dsi->bounds.x = JNFGetIntField(env, target, jf_x); - dsi->bounds.y = JNFGetIntField(env, target, jf_y); - dsi->bounds.width = JNFGetIntField(env, target, jf_width); - dsi->bounds.height = JNFGetIntField(env, target, jf_height); + dsi->bounds.x = (*env)->GetIntField(env, target, jf_x); + dsi->bounds.y = (*env)->GetIntField(env, target, jf_y); + dsi->bounds.width = (*env)->GetIntField(env, target, jf_width); + dsi->bounds.height = (*env)->GetIntField(env, target, jf_height); dsi->clipSize = 1; dsi->clip = &(dsi->bounds); @@ -148,7 +147,9 @@ mid = (*env)->GetMethodID(env, cls, "", "(J)V"); CHECK_NULL_RETURN(mid, NULL); } - return (*env)->NewObject(env, cls, mid, platformInfo); + jobject o = (*env)->NewObject(env, cls, mid, platformInfo); + CHECK_EXCEPTION(); + return o; } JNIEXPORT void JNICALL awt_SetBounds @@ -162,6 +163,7 @@ CHECK_NULL(mid); } (*env)->CallVoidMethod(env, embeddedFrame, mid, x, y, w, h); + CHECK_EXCEPTION(); } JNIEXPORT void JNICALL awt_SynthesizeWindowActivation @@ -175,4 +177,5 @@ CHECK_NULL(mid); } (*env)->CallVoidMethod(env, embeddedFrame, mid, doActivate); + CHECK_EXCEPTION(); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m --- a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m @@ -34,6 +34,7 @@ #import "AWTFont.h" #import "AWTStrike.h" #import "CoreTextSupport.h" +#import "JNIUtilities.h" @implementation AWTFont @@ -122,11 +123,12 @@ return nil; } - static JNF_CLASS_CACHE(jc_Font, "java/awt/Font"); + DECLARE_CLASS_RETURN(jc_Font, "java/awt/Font", nil); // obtain the Font2D - static JNF_MEMBER_CACHE(jm_Font_getFont2D, jc_Font, "getFont2D", "()Lsun/font/Font2D;"); - jobject font2d = JNFCallObjectMethod(env, javaFont, jm_Font_getFont2D); + DECLARE_METHOD_RETURN(jm_Font_getFont2D, jc_Font, "getFont2D", "()Lsun/font/Font2D;", nil); + jobject font2d = (*env)->CallObjectMethod(env, javaFont, jm_Font_getFont2D); + CHECK_EXCEPTION(); if (font2d == NULL) { #ifdef DEBUG NSLog(@"nil font2d"); @@ -136,27 +138,28 @@ // if it's not a CFont, it's likely one of TTF or OTF fonts // from the Sun rendering loops - static JNF_CLASS_CACHE(jc_CFont, "sun/font/CFont"); - if (!JNFIsInstanceOf(env, font2d, &jc_CFont)) { + DECLARE_CLASS_RETURN(jc_CFont, "sun/font/CFont", nil); + if (!(*env)->IsInstanceOf(env, font2d, jc_CFont)) { #ifdef DEBUG NSLog(@"font2d !instanceof CFont"); #endif return nil; } - static JNF_MEMBER_CACHE(jm_CFont_getFontStrike, jc_CFont, "getStrike", "(Ljava/awt/Font;)Lsun/font/FontStrike;"); - jobject fontStrike = JNFCallObjectMethod(env, font2d, jm_CFont_getFontStrike, javaFont); - - static JNF_CLASS_CACHE(jc_CStrike, "sun/font/CStrike"); - if (!JNFIsInstanceOf(env, fontStrike, &jc_CStrike)) { + DECLARE_METHOD_RETURN(jm_CFont_getFontStrike, jc_CFont, "getStrike", "(Ljava/awt/Font;)Lsun/font/FontStrike;", nil); + jobject fontStrike = (*env)->CallObjectMethod(env, font2d, jm_CFont_getFontStrike, javaFont); + CHECK_EXCEPTION(); + DECLARE_CLASS_RETURN(jc_CStrike, "sun/font/CStrike", nil); + if (!(*env)->IsInstanceOf(env, fontStrike, jc_CStrike)) { #ifdef DEBUG NSLog(@"fontStrike !instanceof CStrike"); #endif return nil; } - static JNF_MEMBER_CACHE(jm_CStrike_nativeStrikePtr, jc_CStrike, "getNativeStrikePtr", "()J"); - jlong awtStrikePtr = JNFCallLongMethod(env, fontStrike, jm_CStrike_nativeStrikePtr); + DECLARE_METHOD_RETURN(jm_CStrike_nativeStrikePtr, jc_CStrike, "getNativeStrikePtr", "()J", nil); + jlong awtStrikePtr = (*env)->CallLongMethod(env, fontStrike, jm_CStrike_nativeStrikePtr); + CHECK_EXCEPTION(); if (awtStrikePtr == 0L) { #ifdef DEBUG NSLog(@"nil nativeFontPtr from CFont"); @@ -285,71 +288,6 @@ myFSRefPtr, NULL); } -// /* -// * Class: sun_font_CFontManager -// * Method: loadFileFont -// * Signature: (Ljava/lang/String;)Lsun/font/Font2D; -// */ -// JNIEXPORT /* sun.font.CFont */ jobject JNICALL -// Java_sun_font_CFontManager_loadFileFont -// (JNIEnv *env, jclass obj, jstring fontpath) -// { -// jobject result = NULL; -// -// JNF_COCOA_ENTER(env); -// -// NSString *nsFilePath = JNFJavaToNSString(env, fontpath); -// jstring javaFontName = NULL; -// -// // -// // Note: This API uses ATS and can therefore return Carbon error codes. -// // These codes can be found at: -// // http://developer.apple.com/techpubs/macosx/Carbon/Files/FileManager/File_Manager/ResultCodes/ResultCodes.html -// // -// -// FSRef iFile; -// OSStatus status = CreateFSRef(&iFile, nsFilePath); -// -// if (status == noErr) { -// ATSFontContainerRef oContainer; -// status = ATSFontActivateFromFileReference(&iFile, kATSFontContextLocal, -// kATSFontFormatUnspecified, -// NULL, -// kATSOptionFlagsUseDataFork, -// &oContainer); -// if (status == noErr) { -// ATSFontRef ioArray[1]; -// ItemCount oCount; -// status = ATSFontFindFromContainer(oContainer, -// kATSOptionFlagsUseDataFork, -// 1, ioArray, &oCount); -// -// if (status == noErr) { -// CFStringRef oName; -// status = ATSFontGetPostScriptName(ioArray[0], -// kATSOptionFlagsUseDataFork, -// &oName); -// if (status == noErr) { -// javaFontName = JNFNSToJavaString(env, (NSString *)oName); -// CFRelease(oName); -// } -// } -// } -// } -// -// if (javaFontName != NULL) { -// // create the CFont! -// static JNF_CLASS_CACHE(sjc_CFont, "sun/font/CFont"); -// static JNF_CTOR_CACHE(sjf_CFont_ctor, -// sjc_CFont, "(Ljava/lang/String;)V"); -// result = JNFNewObject(env, sjf_CFont_ctor, javaFontName); -// } -// -// JNF_COCOA_EXIT(env); -// -// return result; -// } - /* * Class: sun_font_CFontManager * Method: loadNativeFonts @@ -359,11 +297,8 @@ Java_sun_font_CFontManager_loadNativeFonts (JNIEnv *env, jobject jthis) { - static JNF_CLASS_CACHE(jc_CFontManager, - "sun/font/CFontManager"); - static JNF_MEMBER_CACHE(jm_registerFont, jc_CFontManager, - "registerFont", - "(Ljava/lang/String;Ljava/lang/String;)V"); + DECLARE_CLASS(jc_CFontManager, "sun/font/CFontManager"); + DECLARE_METHOD(jm_registerFont, jc_CFontManager, "registerFont", "(Ljava/lang/String;Ljava/lang/String;)V"); jint num = 0; @@ -379,8 +314,8 @@ jobject jFontFamilyName = JNFNSToJavaString(env, GetFamilyNameForFontName(fontname)); - JNFCallVoidMethod(env, jthis, - jm_registerFont, jFontName, jFontFamilyName); + (*env)->CallVoidMethod(env, jthis, jm_registerFont, jFontName, jFontFamilyName); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jFontName); (*env)->DeleteLocalRef(env, jFontFamilyName); } @@ -637,6 +572,9 @@ #endif jstring jFontName = (jstring)JNFNSToJavaString(env, fontname); (*env)->CallBooleanMethod(env, arrayListOfString, addMID, jFontName); + if ((*env)->ExceptionOccurred(env)) { + return; + } (*env)->DeleteLocalRef(env, jFontName); } } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m --- a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m @@ -30,6 +30,7 @@ #import "CGGlyphImages.h" #import "CGGlyphOutlines.h" #import "CoreTextSupport.h" +#import "JNIUtilities.h" #include "fontscalerdefs.h" @implementation AWTStrike @@ -196,9 +197,11 @@ bbox.origin.y = -bbox.size.height + decender; // Rectangle2D.Float.setRect(float x, float y, float width, float height); - static JNF_CLASS_CACHE(sjc_Rectangle2D_Float, "java/awt/geom/Rectangle2D$Float"); // cache class id for Rectangle - static JNF_MEMBER_CACHE(sjr_Rectangle2DFloat_setRect, sjc_Rectangle2D_Float, "setRect", "(FFFF)V"); - JNFCallVoidMethod(env, result, sjr_Rectangle2DFloat_setRect, (jfloat)bbox.origin.x, (jfloat)bbox.origin.y, (jfloat)bbox.size.width, (jfloat)bbox.size.height); + DECLARE_CLASS(sjc_Rectangle2D_Float, "java/awt/geom/Rectangle2D$Float"); // cache class id for Rectangle + DECLARE_METHOD(sjr_Rectangle2DFloat_setRect, sjc_Rectangle2D_Float, "setRect", "(FFFF)V"); + (*env)->CallVoidMethod(env, result, sjr_Rectangle2DFloat_setRect, + (jfloat)bbox.origin.x, (jfloat)bbox.origin.y, (jfloat)bbox.size.width, (jfloat)bbox.size.height); + CHECK_EXCEPTION(); JNF_COCOA_EXIT(env); } @@ -221,6 +224,9 @@ jfloatArray pointCoords = NULL; jbyteArray pointTypes = NULL; + DECLARE_CLASS_RETURN(jc_GeneralPath, "java/awt/geom/GeneralPath", NULL); + DECLARE_METHOD_RETURN(jc_GeneralPath_ctor, jc_GeneralPath, "", "(I[BI[FI)V", NULL); + AWT_FONT_CLEANUP_SETUP; AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr); @@ -263,9 +269,8 @@ (*env)->SetByteArrayRegion(env, pointTypes, 0, path->fNumberOfSegments, (jbyte*)path->fSegmentType); - static JNF_CLASS_CACHE(jc_GeneralPath, "java/awt/geom/GeneralPath"); - static JNF_CTOR_CACHE(jc_GeneralPath_ctor, jc_GeneralPath, "(I[BI[FI)V"); - generalPath = JNFNewObject(env, jc_GeneralPath_ctor, java_awt_geom_PathIterator_WIND_NON_ZERO, pointTypes, path->fNumberOfSegments, pointCoords, path->fNumberOfDataElements); // AWT_THREADING Safe (known object) + generalPath = (*env)->NewObject(env, jc_GeneralPath, jc_GeneralPath_ctor, java_awt_geom_PathIterator_WIND_NON_ZERO, pointTypes, + path->fNumberOfSegments, pointCoords, path->fNumberOfDataElements); // AWT_THREADING Safe (known object) // Cleanup cleanup: @@ -423,9 +428,9 @@ * advance: no need to set yMaxLinearAdvanceWidth - it will be zero. */ - JNF_CLASS_CACHE(sjc_StrikeMetrics, "sun/font/StrikeMetrics"); - JNF_CTOR_CACHE(strikeMetricsCtr, sjc_StrikeMetrics, "(FFFFFFFFFF)V"); - metrics = JNFNewObject(env, strikeMetricsCtr, + DECLARE_CLASS_RETURN(sjc_StrikeMetrics, "sun/font/StrikeMetrics", NULL); + DECLARE_METHOD_RETURN(strikeMetricsCtr, sjc_StrikeMetrics, "", "(FFFFFFFFFF)V", NULL); + metrics = (*env)->NewObject(env, sjc_StrikeMetrics, strikeMetricsCtr, 0.0, ay, 0.0, dy, 1.0, 0.0, 0.0, ly, mx, 0.0); 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 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.m @@ -28,6 +28,7 @@ #import "ThreadUtilities.h" #import "LWCToolkit.h" #import "CGLSurfaceData.h" +#import "JNIUtilities.h" extern NSOpenGLPixelFormat *sharedPixelFormat; @@ -134,8 +135,8 @@ AWT_ASSERT_APPKIT_THREAD; JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_CLASS_CACHE(jc_JavaLayer, "sun/java2d/opengl/CGLLayer"); - static JNF_MEMBER_CACHE(jm_drawInCGLContext, jc_JavaLayer, "drawInCGLContext", "()V"); + DECLARE_CLASS(jc_JavaLayer, "sun/java2d/opengl/CGLLayer"); + DECLARE_METHOD(jm_drawInCGLContext, jc_JavaLayer, "drawInCGLContext", "()V"); jobject javaLayerLocalRef = [self.javaLayer jObjectWithEnv:env]; if ((*env)->IsSameObject(env, javaLayerLocalRef, NULL)) { @@ -151,7 +152,8 @@ glViewport(0, 0, textureWidth, textureHeight); - JNFCallVoidMethod(env, javaLayerLocalRef, jm_drawInCGLContext); + (*env)->CallVoidMethod(env, javaLayerLocalRef, jm_drawInCGLContext); + CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, javaLayerLocalRef); // Call super to finalize the drawing. By default all it does is call glFlush(). diff --git a/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h b/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h new file mode 100644 --- /dev/null +++ b/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#ifndef __JNIUTILITIES_H +#define __JNIUTILITIES_H + +#include "jni.h" +#include "jni_util.h" + +/******** LOGGING SUPPORT *********/ + +#define LOG_NULL(dst_var, name) \ + if (dst_var == NULL) { \ + NSLog(@"Bad JNI lookup %s\n", name); \ + } + +/******** GET CLASS SUPPORT *********/ + +#define GET_CLASS(dst_var, cls) \ + if (dst_var == NULL) { \ + dst_var = (*env)->FindClass(env, cls); \ + if (dst_var != NULL) dst_var = (*env)->NewGlobalRef(env, dst_var); \ + } \ + LOG_NULL(dst_var, cls); \ + CHECK_NULL(dst_var); + +#define DECLARE_CLASS(dst_var, cls) \ + static jclass dst_var = NULL; \ + GET_CLASS(dst_var, cls); + +#define GET_CLASS_RETURN(dst_var, cls, ret) \ + if (dst_var == NULL) { \ + dst_var = (*env)->FindClass(env, cls); \ + if (dst_var != NULL) dst_var = (*env)->NewGlobalRef(env, dst_var); \ + } \ + LOG_NULL(dst_var, cls); \ + CHECK_NULL_RETURN(dst_var, ret); + +#define DECLARE_CLASS_RETURN(dst_var, cls, ret) \ + static jclass dst_var = NULL; \ + GET_CLASS_RETURN(dst_var, cls, ret); + + +/******** GET METHOD SUPPORT *********/ + +#define GET_METHOD(dst_var, cls, name, signature) \ + if (dst_var == NULL) { \ + dst_var = (*env)->GetMethodID(env, cls, name, signature); \ + } \ + LOG_NULL(dst_var, name); \ + CHECK_NULL(dst_var); + +#define DECLARE_METHOD(dst_var, cls, name, signature) \ + static jmethodID dst_var = NULL; \ + GET_METHOD(dst_var, cls, name, signature); + +#define GET_METHOD_RETURN(dst_var, cls, name, signature, ret) \ + if (dst_var == NULL) { \ + dst_var = (*env)->GetMethodID(env, cls, name, signature); \ + } \ + LOG_NULL(dst_var, name); \ + CHECK_NULL_RETURN(dst_var, ret); + +#define DECLARE_METHOD_RETURN(dst_var, cls, name, signature, ret) \ + static jmethodID dst_var = NULL; \ + GET_METHOD_RETURN(dst_var, cls, name, signature, ret); + +#define GET_STATIC_METHOD(dst_var, cls, name, signature) \ + if (dst_var == NULL) { \ + dst_var = (*env)->GetStaticMethodID(env, cls, name, signature); \ + } \ + LOG_NULL(dst_var, name); \ + CHECK_NULL(dst_var); + +#define DECLARE_STATIC_METHOD(dst_var, cls, name, signature) \ + static jmethodID dst_var = NULL; \ + GET_STATIC_METHOD(dst_var, cls, name, signature); + +#define GET_STATIC_METHOD_RETURN(dst_var, cls, name, signature, ret) \ + if (dst_var == NULL) { \ + dst_var = (*env)->GetStaticMethodID(env, cls, name, signature); \ + } \ + LOG_NULL(dst_var, name); \ + CHECK_NULL_RETURN(dst_var, ret); + +#define DECLARE_STATIC_METHOD_RETURN(dst_var, cls, name, signature, ret) \ + static jmethodID dst_var = NULL; \ + GET_STATIC_METHOD_RETURN(dst_var, cls, name, signature, ret); + +/******** GET FIELD SUPPORT *********/ + + +#define GET_FIELD(dst_var, cls, name, signature) \ + if (dst_var == NULL) { \ + dst_var = (*env)->GetFieldID(env, cls, name, signature); \ + } \ + LOG_NULL(dst_var, name); \ + CHECK_NULL(dst_var); + +#define DECLARE_FIELD(dst_var, cls, name, signature) \ + static jfieldID dst_var = NULL; \ + GET_FIELD(dst_var, cls, name, signature); + +#define GET_FIELD_RETURN(dst_var, cls, name, signature, ret) \ + if (dst_var == NULL) { \ + dst_var = (*env)->GetFieldID(env, cls, name, signature); \ + } \ + LOG_NULL(dst_var, name); \ + CHECK_NULL_RETURN(dst_var, ret); + +#define DECLARE_FIELD_RETURN(dst_var, cls, name, signature, ret) \ + static jfieldID dst_var = NULL; \ + GET_FIELD_RETURN(dst_var, cls, name, signature, ret); + +#define GET_STATIC_FIELD_RETURN(dst_var, cls, name, signature, ret) \ + if (dst_var == NULL) { \ + dst_var = (*env)->GetStaticFieldID(env, cls, name, signature); \ + } \ + LOG_NULL(dst_var, name); \ + CHECK_NULL_RETURN(dst_var, ret); + +#define DECLARE_STATIC_FIELD_RETURN(dst_var, cls, name, signature, ret) \ + static jfieldID dst_var = NULL; \ + GET_STATIC_FIELD_RETURN(dst_var, cls, name, signature, ret); + +/********* EXCEPTION_HANDLING *********/ + +#define CHECK_EXCEPTION() \ + if ((*env)->ExceptionOccurred(env) != NULL) { \ + (*env)->ExceptionClear(env); \ + }; + +#define CHECK_EXCEPTION_NULL_RETURN(x, y) \ + CHECK_EXCEPTION(); \ + if ((x) == NULL) { \ + return y; \ + }; + +#endif /* __JNIUTILITIES_H */ diff --git a/src/java.desktop/macosx/native/libosxapp/PropertiesUtilities.m b/src/java.desktop/macosx/native/libosxapp/PropertiesUtilities.m --- a/src/java.desktop/macosx/native/libosxapp/PropertiesUtilities.m +++ b/src/java.desktop/macosx/native/libosxapp/PropertiesUtilities.m @@ -24,16 +24,19 @@ */ #import "PropertiesUtilities.h" +#import "JNIUtilities.h" @implementation PropertiesUtilities + (NSString *) javaSystemPropertyForKey:(NSString *)key withEnv:(JNIEnv *)env { - static JNF_CLASS_CACHE(jc_System, "java/lang/System"); - static JNF_STATIC_MEMBER_CACHE(jm_getProperty, jc_System, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;"); + DECLARE_CLASS_RETURN(jc_System, "java/lang/System", nil); + DECLARE_STATIC_METHOD_RETURN(jm_getProperty, jc_System, + "getProperty", "(Ljava/lang/String;)Ljava/lang/String;", nil); jstring jKey = JNFNSToJavaString(env, key); - jstring jValue = JNFCallStaticObjectMethod(env, jm_getProperty, jKey); + jstring jValue = (*env)->CallStaticObjectMethod(env, jc_System, jm_getProperty, jKey); (*env)->DeleteLocalRef(env, jKey); + CHECK_EXCEPTION_NULL_RETURN(jValue, nil); NSString *value = JNFJavaToNSString(env, jValue); (*env)->DeleteLocalRef(env, jValue); diff --git a/src/java.desktop/macosx/native/libosxui/ScreenMenu.m b/src/java.desktop/macosx/native/libosxui/ScreenMenu.m --- a/src/java.desktop/macosx/native/libosxui/ScreenMenu.m +++ b/src/java.desktop/macosx/native/libosxui/ScreenMenu.m @@ -36,8 +36,11 @@ #import "ThreadUtilities.h" #import "CMenuBar.h" +#import "JNIUtilities.h" -static JNF_CLASS_CACHE(sjc_ScreenMenu, "com/apple/laf/ScreenMenu"); +static jclass sjc_ScreenMenu = NULL; +#define GET_SCREENMENU_CLASS() \ + GET_CLASS(sjc_ScreenMenu, "com/apple/laf/ScreenMenu"); static jint ns2awtModifiers(NSUInteger keyMods) { jint result = 0; @@ -104,8 +107,10 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; JNF_COCOA_ENTER(env); //NSLog(@"menuWillOpen %@", [menu title]); - static JNF_MEMBER_CACHE(jm_ScreenMenu_invokeOpenLater, sjc_ScreenMenu, "invokeOpenLater", "()V"); - JNFCallVoidMethod(env, [self.javaObjectWrapper jObject], jm_ScreenMenu_invokeOpenLater); // AWT_THREADING Safe (AWTRunLoopMode) + 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) + CHECK_EXCEPTION(); JNF_COCOA_EXIT(env); } @@ -122,8 +127,10 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; JNF_COCOA_ENTER(env); //NSLog(@"menuDidClose %@", [menu title]); - static JNF_MEMBER_CACHE(jm_ScreenMenu_invokeMenuClosing, sjc_ScreenMenu, "invokeMenuClosing", "()V"); - JNFCallVoidMethod(env, [self.javaObjectWrapper jObject], jm_ScreenMenu_invokeMenuClosing); // AWT_THREADING Safe (AWTRunLoopMode) + 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) + CHECK_EXCEPTION(); JNF_COCOA_EXIT(env); } @@ -140,9 +147,11 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; JNF_COCOA_ENTER(env); // Send that to Java so we can test which item was hit. - static JNF_MEMBER_CACHE(jm_ScreenMenu_updateSelectedItem, sjc_ScreenMenu, "handleItemTargeted", "(IIIII)V"); - JNFCallVoidMethod(env, [self.javaObjectWrapper jObject], jm_ScreenMenu_updateSelectedItem, menuIndex, + GET_SCREENMENU_CLASS(); + DECLARE_METHOD(jm_ScreenMenu_updateSelectedItem, sjc_ScreenMenu, "handleItemTargeted", "(IIIII)V"); + (*env)->CallVoidMethod(env, [self.javaObjectWrapper jObject], jm_ScreenMenu_updateSelectedItem, menuIndex, NSMinY(rect), NSMinX(rect), NSMaxY(rect), NSMaxX(rect)); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); JNF_COCOA_EXIT(env); } @@ -183,8 +192,11 @@ // Call the mouse event handler, which will generate Java mouse events. JNIEnv *env = [ThreadUtilities getJNIEnv]; JNF_COCOA_ENTER(env); - static JNF_MEMBER_CACHE(jm_ScreenMenu_handleMouseEvent, sjc_ScreenMenu, "handleMouseEvent", "(IIIIJ)V"); - JNFCallVoidMethod(env, [self.javaObjectWrapper jObject], jm_ScreenMenu_handleMouseEvent, javaKind, javaX, javaY, javaModifiers, javaWhen); // AWT_THREADING Safe (AWTRunLoopMode) + GET_SCREENMENU_CLASS(); + DECLARE_METHOD(jm_ScreenMenu_handleMouseEvent, sjc_ScreenMenu, "handleMouseEvent", "(IIIIJ)V"); + (*env)->CallVoidMethod(env, [self.javaObjectWrapper jObject], jm_ScreenMenu_handleMouseEvent, + javaKind, javaX, javaY, javaModifiers, javaWhen); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); JNF_COCOA_EXIT(env); } # HG changeset patch # User vkempik # Date 1617882156 0 # Thu Apr 08 11:42:36 2021 +0000 # Node ID 29bb96fa537f8f04b26cdacf2f0c749ec3cb05bb # Parent f40019cd312be6990a0e3022a09c43a78477c822 8259343: [macOS] Update JNI error handling in Cocoa code. diff --git a/make/lib/Lib-java.desktop.gmk b/make/lib/Lib-java.desktop.gmk --- a/make/lib/Lib-java.desktop.gmk +++ b/make/lib/Lib-java.desktop.gmk @@ -96,6 +96,7 @@ LDFLAGS := $(LDFLAGS_JDKLIB) \ $(call SET_SHARED_LIBRARY_ORIGIN), \ LIBS := \ + -ljava \ -framework Accelerate \ -framework ApplicationServices \ -framework AudioToolbox \ @@ -110,6 +111,8 @@ -framework QuartzCore, \ )) + $(BUILD_LIBOSXAPP): $(call FindLib, java.base, java) + TARGETS += $(BUILD_LIBOSXAPP) ############################################################################## diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m @@ -1311,6 +1311,7 @@ array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_firstRectForCharacterRange, theRange.location); // AWT_THREADING Safe (AWTRunLoopMode) + CHECK_EXCEPTION(); _array = (*env)->GetIntArrayElements(env, array, &isCopy); if (_array) { diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m @@ -56,7 +56,7 @@ GET_CPRINTERJOB_CLASS_RETURN(ret); \ GET_METHOD_RETURN(sjm_getNSPrintInfo, sjc_CPrinterJob, "getNSPrintInfo", "()J", ret); -#define GET_CPRINTERDIALOG_METHOD_RETURN(ret) \ +#define GET_CPRINTERDIALOG_FIELD_RETURN(ret) \ GET_CPRINTERDIALOG_CLASS_RETURN(ret); \ GET_METHOD_RETURN(sjm_printerJob, sjc_CPrinterDialog, "fPrinterJob", "Lsun/lwawt/macosx/CPrinterJob;", ret); @@ -624,6 +624,7 @@ // JTable.print attributes are ignored jobject pageable = (*env)->CallObjectMethod(env, jthis, jm_getPageable); // AWT_THREADING Safe (!appKit) + CHECK_EXCEPTION(); javaPrinterJobToNSPrintInfo(env, jthis, pageable, printInfo); PrintModel* printModel = [[PrintModel alloc] initWithPrintInfo:printInfo]; @@ -664,11 +665,12 @@ jboolean result = JNI_FALSE; JNF_COCOA_ENTER(env); - GET_CPRINTERDIALOG_METHOD_RETURN(NO); + GET_CPRINTERDIALOG_FIELD_RETURN(NO); GET_NSPRINTINFO_METHOD_RETURN(NO) jobject printerJob = (*env)->GetObjectField(env, jthis, sjm_printerJob); if (printerJob == NULL) return NO; NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr((*env)->CallLongMethod(env, printerJob, sjm_getNSPrintInfo)); // AWT_THREADING Safe (known object) + CHECK_EXCEPTION(); if (printInfo == NULL) return result; jobject page = (*env)->GetObjectField(env, jthis, jm_page); @@ -713,7 +715,7 @@ jboolean result = JNI_FALSE; JNF_COCOA_ENTER(env); - GET_CPRINTERDIALOG_METHOD_RETURN(NO); + GET_CPRINTERDIALOG_FIELD_RETURN(NO); jobject printerJob = (*env)->GetObjectField(env, jthis, sjm_printerJob); if (printerJob == NULL) return NO; GET_NSPRINTINFO_METHOD_RETURN(NO) diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.m @@ -24,6 +24,7 @@ */ #import "GeomUtilities.h" +#import static jobject NewJavaRect(JNIEnv *env, jdouble x, jdouble y, jdouble w, jdouble h) { DECLARE_CLASS_RETURN(sjc_Rectangle2DDouble, "java/awt/geom/Rectangle2D$Double", NULL); @@ -55,10 +56,11 @@ DECLARE_METHOD_RETURN(jm_rect_getY, sjc_Rectangle2D, "getY", "()D", NSZeroRect); DECLARE_METHOD_RETURN(jm_rect_getWidth, sjc_Rectangle2D, "getWidth", "()D", NSZeroRect); DECLARE_METHOD_RETURN(jm_rect_getHeight, sjc_Rectangle2D, "getHeight", "()D", NSZeroRect); - return NSMakeRect((*env)->CallDoubleMethod(env, rect, jm_rect_getX), - (*env)->CallDoubleMethod(env, rect, jm_rect_getY), - (*env)->CallDoubleMethod(env, rect, jm_rect_getWidth), - (*env)->CallDoubleMethod(env, rect, jm_rect_getHeight)); + jdouble x = (*env)->CallDoubleMethod(env, rect, jm_rect_getX); CHECK_EXCEPTION(); + jdouble y = (*env)->CallDoubleMethod(env, rect, jm_rect_getY); CHECK_EXCEPTION(); + jdouble w = (*env)->CallDoubleMethod(env, rect, jm_rect_getWidth); CHECK_EXCEPTION(); + jdouble h = (*env)->CallDoubleMethod(env, rect, jm_rect_getHeight); CHECK_EXCEPTION(); + return NSMakeRect(x, y, w, h); } jobject NSToJavaPoint(JNIEnv *env, NSPoint point) { @@ -73,9 +75,9 @@ DECLARE_CLASS_RETURN(sjc_Point2D, "java/awt/geom/Point2D", NSZeroPoint); DECLARE_METHOD_RETURN(jm_pt_getX, sjc_Point2D, "getX", "()D", NSZeroPoint); DECLARE_METHOD_RETURN(jm_pt_getY, sjc_Point2D, "getY", "()D", NSZeroPoint); - - return NSMakePoint((*env)->CallDoubleMethod(env, point, jm_pt_getX), - (*env)->CallDoubleMethod(env, point, jm_pt_getY)); + jdouble x = (*env)->CallDoubleMethod(env, point, jm_pt_getX); CHECK_EXCEPTION(); + jdouble y = (*env)->CallDoubleMethod(env, point, jm_pt_getY); CHECK_EXCEPTION(); + return NSMakePoint(x, y); } jobject NSToJavaSize(JNIEnv *env, NSSize size) { @@ -90,14 +92,15 @@ DECLARE_CLASS_RETURN(sjc_Dimension2D, "java/awt/geom/Dimension2D", NSZeroSize); DECLARE_METHOD_RETURN(jm_sz_getWidth, sjc_Dimension2D, "getWidth", "()D", NSZeroSize); DECLARE_METHOD_RETURN(jm_sz_getHeight, sjc_Dimension2D, "getHeight", "()D", NSZeroSize); - - return NSMakeSize((*env)->CallDoubleMethod(env, dimension, jm_sz_getWidth), - (*env)->CallDoubleMethod(env, dimension, jm_sz_getHeight)); + jdouble w = (*env)->CallDoubleMethod(env, dimension, jm_sz_getWidth); CHECK_EXCEPTION(); + jdouble h = (*env)->CallDoubleMethod(env, dimension, jm_sz_getHeight); CHECK_EXCEPTION(); + return NSMakeSize(w, h); } static NSScreen *primaryScreen(JNIEnv *env) { NSScreen *primaryScreen = [[NSScreen screens] objectAtIndex:0]; if (primaryScreen != nil) return primaryScreen; + if (env != NULL) [JNFException raise:env as:kRuntimeException reason:"Failed to convert, no screen."]; return nil; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m @@ -604,6 +604,7 @@ } else { AWTView *view = fView; jobject jax = (*env)->CallStaticObjectMethod(env, sjc_CAccessible, sjm_getSwingAccessible, fAccessible); + CHECK_EXCEPTION(); if ((*env)->IsInstanceOf(env, jax, sjc_Window)) { // In this case jparent is an owner toplevel and we should retrieve its own view @@ -890,6 +891,7 @@ if ([(NSNumber*)value boolValue]) { (*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_requestFocus, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + CHECK_EXCEPTION(); } } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaTextAccessibility.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaTextAccessibility.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaTextAccessibility.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaTextAccessibility.m @@ -160,7 +160,6 @@ DECLARE_STATIC_METHOD_RETURN(jm_getTextRange, sjc_CAccessibleText, "getTextRange", "(Ljavax/accessibility/AccessibleEditableText;IILjava/awt/Component;)Ljava/lang/String;", nil); - CHECK_EXCEPTION(); jobject jrange = (*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, jm_getTextRange, axEditableText, 0, getAxTextCharCount(env, axEditableText, fComponent), fComponent); CHECK_EXCEPTION(); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m @@ -123,6 +123,7 @@ DECLARE_METHOD_RETURN(jm_getJobName, sjc_CPrinterJob, "getJobName", "()Ljava/lang/String;", nil); jobject o = (*env)->CallObjectMethod(env, fPrinterJob, jm_getJobName); // AWT_THREADING Safe (known object) + CHECK_EXCEPTION(); id result = JNFJavaToNSString(env, o); (*env)->DeleteLocalRef(env, o); return result; diff --git a/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h b/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h --- a/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h +++ b/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h @@ -29,11 +29,24 @@ #include "jni.h" #include "jni_util.h" +#import + /******** LOGGING SUPPORT *********/ #define LOG_NULL(dst_var, name) \ if (dst_var == NULL) { \ NSLog(@"Bad JNI lookup %s\n", name); \ + NSLog(@"%@",[NSThread callStackSymbols]); \ + if ([NSThread isMainThread] == NO) { \ + if ((*env)->ExceptionOccurred(env) == NULL) { \ + JNU_ThrowInternalError(env, "Bad JNI Lookup"); \ + } \ + } else { \ + if ((*env)->ExceptionOccurred(env) != NULL) { \ + (*env)->ExceptionDescribe(env); \ + } \ + } \ + [NSException raise:NSGenericException format:@"JNI Lookup Exception"]; \ } /******** GET CLASS SUPPORT *********/ @@ -147,9 +160,44 @@ /********* EXCEPTION_HANDLING *********/ +/* + * Some explanation to set context of the bigger picture. + * Before returning to Java from JNI, NSExceptions are caught - so long as + * the body of the native method is wrapped in the ENTER/EXIT macros. + * So if we want to directly return to Java from some nested Objective-C + * function when detecting a Java exception, we just need to raise an + * NSException. Then clear that right before returning to Java, + * leaving the Java exception to be seen back in Java-land. + * + * But if the current thread is the Appkit thread we might as well clear + * the Java Exception right now since there's nothing to receive it. + * In such a case control will propagate back to the run loop which might + * terminate the application. One drawback of that is that the location of + * termination does not show where the NSException originated. + * And for whatever reason, something swallows that exception. + * So as a debugging aid, when on the AppKit thread we can provide a + * way (via an env. var.) to log the location. + * Additionally provide a similar way to prevent the NSException being + * raised and instead just clear the Java Exception. + * Together these provide alternate behaviours for more debugging info + * or maybe a way for the app to continue running depending on the exact + * nature of the problem that has been detected and how survivable it is. + */ #define CHECK_EXCEPTION() \ if ((*env)->ExceptionOccurred(env) != NULL) { \ - (*env)->ExceptionClear(env); \ + if ([NSThread isMainThread] == YES) { \ + if (getenv("JNU_APPKIT_TRACE")) { \ + (*env)->ExceptionDescribe(env); \ + NSLog(@"%@",[NSThread callStackSymbols]); \ + } else { \ + (*env)->ExceptionClear(env); \ + } \ + } \ + if (getenv("JNU_NO_COCOA_EXCEPTION") == NULL) { \ + [NSException raise:NSGenericException format:@"Java Exception"]; \ + } else { \ + (*env)->ExceptionClear(env); \ + } \ }; #define CHECK_EXCEPTION_NULL_RETURN(x, y) \ # HG changeset patch # User vkempik # Date 1617883563 0 # Thu Apr 08 12:06:03 2021 +0000 # Node ID 3f37447f4a66f530a1662be4e41c802ba6b53563 # Parent 29bb96fa537f8f04b26cdacf2f0c749ec3cb05bb 8259651: [macOS] Replace JNF_COCOA_ENTER/EXIT macros diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTEvent.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTEvent.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTEvent.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTEvent.m @@ -27,7 +27,7 @@ #import "java_awt_event_KeyEvent.h" #import "LWCToolkit.h" -#import "jni_util.h" +#import "JNIUtilities.h" #import #import @@ -675,11 +675,11 @@ { jint jmodifiers = 0; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); jmodifiers = GetJavaMouseModifiers(modifierFlags); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return jmodifiers; } @@ -695,7 +695,7 @@ { BOOL postsTyped = NO; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); jboolean copy = JNI_FALSE; jint *data = (*env)->GetIntArrayElements(env, inData, ©); @@ -723,7 +723,7 @@ (*env)->ReleaseIntArrayElements(env, inData, data, 0); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return postsTyped; } @@ -737,7 +737,7 @@ Java_sun_lwawt_macosx_NSEvent_nsKeyModifiersToJavaKeyInfo (JNIEnv *env, jclass cls, jintArray inData, jintArray outData) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); jboolean copy = JNI_FALSE; jint *data = (*env)->GetIntArrayElements(env, inData, ©); @@ -764,7 +764,7 @@ (*env)->ReleaseIntArrayElements(env, inData, data, 0); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -778,11 +778,11 @@ { jchar javaChar = 0; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); javaChar = NsCharToJavaChar(nsChar, modifierFlags, spaceKeyTyped); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return javaChar; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTSurfaceLayers.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTSurfaceLayers.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTSurfaceLayers.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTSurfaceLayers.m @@ -26,6 +26,7 @@ #import "AWTSurfaceLayers.h" #import "ThreadUtilities.h" #import "LWCToolkit.h" +#import "JNIUtilities.h" #import #import @@ -101,7 +102,7 @@ { __block AWTSurfaceLayers *surfaceLayers = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ @@ -109,7 +110,7 @@ surfaceLayers = [[AWTSurfaceLayers alloc] initWithWindowLayer: windowLayer]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(surfaceLayers); } @@ -122,7 +123,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformComponent_nativeSetBounds (JNIEnv *env, jclass clazz, jlong surfaceLayersPtr, jint x, jint y, jint width, jint height) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTSurfaceLayers *surfaceLayers = OBJC(surfaceLayersPtr); @@ -132,5 +133,5 @@ [surfaceLayers setBounds: rect]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m @@ -1429,7 +1429,7 @@ { __block AWTView *newView = nil; - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); NSRect rect = NSMakeRect(originX, originY, width, height); jobject cPlatformView = (*env)->NewWeakGlobalRef(env, obj); @@ -1442,7 +1442,7 @@ windowLayer:windowLayer]; }]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); return ptr_to_jlong(newView); } @@ -1457,7 +1457,7 @@ Java_sun_lwawt_macosx_CPlatformView_nativeSetAutoResizable (JNIEnv *env, jclass cls, jlong viewPtr, jboolean toResize) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); NSView *view = (NSView *)jlong_to_ptr(viewPtr); @@ -1474,7 +1474,7 @@ } }]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -1489,7 +1489,7 @@ { __block jint ret; //CGDirectDisplayID - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); NSView *view = (NSView *)jlong_to_ptr(viewPtr); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ @@ -1497,7 +1497,7 @@ ret = (jint)[[AWTWindow getNSWindowDisplayID_AppKitThread: window] intValue]; }]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); return ret; } @@ -1514,7 +1514,7 @@ { jobject jRect = NULL; - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); __block NSRect rect = NSZeroRect; @@ -1530,7 +1530,7 @@ }]; jRect = NSToJavaRect(env, rect); - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); return jRect; } @@ -1546,7 +1546,7 @@ { __block jboolean underMouse = JNI_FALSE; - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); NSView *nsView = OBJC(viewPtr); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ @@ -1555,7 +1555,7 @@ underMouse = [nsView hitTest:ptViewCoords] != nil; }]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); return underMouse; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m @@ -1076,7 +1076,7 @@ { __block AWTWindow *window = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env]; NSView *contentView = OBJC(contentViewPtr); @@ -1094,7 +1094,7 @@ if (window) [window.nsWindow retain]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(window ? window.nsWindow : nil); } @@ -1107,7 +1107,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowStyleBits (JNIEnv *env, jclass clazz, jlong windowPtr, jint mask, jint bits) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); @@ -1155,7 +1155,7 @@ } }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1166,7 +1166,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMenuBar (JNIEnv *env, jclass clazz, jlong windowPtr, jlong menuBarPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); CMenuBar *menuBar = OBJC(menuBarPtr); @@ -1190,7 +1190,7 @@ } }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1203,7 +1203,7 @@ { jobject ret = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); __block NSRect contentRect = NSZeroRect; @@ -1224,7 +1224,7 @@ DECLARE_METHOD_RETURN(jc_Insets_ctor, jc_Insets, "", "(IIII)V", NULL); ret = (*env)->NewObject(env, jc_Insets, jc_Insets_ctor, top, left, bottom, right); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ret; } @@ -1236,7 +1236,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowBounds (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY, jdouble width, jdouble height) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSRect jrect = NSMakeRect(originX, originY, width, height); @@ -1270,7 +1270,7 @@ } }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1282,7 +1282,7 @@ (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble originX, jdouble originY, jdouble width, jdouble height) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); NSRect jrect = NSMakeRect(originX, originY, width, height); @@ -1294,7 +1294,7 @@ window.standardFrame = rect; }]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -1305,7 +1305,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowLocationByPlatform (JNIEnv *env, jclass clazz, jlong windowPtr) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ @@ -1319,7 +1319,7 @@ lastTopLeftPoint = [nsWindow cascadeTopLeftFromPoint:lastTopLeftPoint]; }]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -1330,7 +1330,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinMax (JNIEnv *env, jclass clazz, jlong windowPtr, jdouble minW, jdouble minH, jdouble maxW, jdouble maxH) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); if (minW < 1) minW = 1; if (minH < 1) minH = 1; @@ -1353,7 +1353,7 @@ [window updateMinMaxSize:IS(window.styleBits, RESIZABLE)]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1364,7 +1364,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToBack (JNIEnv *env, jclass clazz, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ @@ -1381,7 +1381,7 @@ [(AWTWindow*)[nsWindow delegate] orderChildWindows:NO]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1392,7 +1392,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativePushNSWindowToFront (JNIEnv *env, jclass clazz, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ @@ -1404,7 +1404,7 @@ } }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1415,14 +1415,14 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowTitle (JNIEnv *env, jclass clazz, jlong windowPtr, jstring jtitle) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); [nsWindow performSelectorOnMainThread:@selector(setTitle:) withObject:JNFJavaToNSString(env, jtitle) waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1433,14 +1433,14 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeRevalidateNSWindowShadow (JNIEnv *env, jclass clazz, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [nsWindow invalidateShadow]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1453,14 +1453,14 @@ { jint ret = 0; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWT_ASSERT_APPKIT_THREAD; NSWindow *nsWindow = OBJC(windowPtr); NSDictionary *props = [[nsWindow screen] deviceDescription]; ret = [[props objectForKey:@"NSScreenNumber"] intValue]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ret; } @@ -1473,7 +1473,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowMinimizedIcon (JNIEnv *env, jclass clazz, jlong windowPtr, jlong nsImagePtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); NSImage *image = OBJC(nsImagePtr); @@ -1481,7 +1481,7 @@ [nsWindow setMiniwindowImage:image]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1492,7 +1492,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetNSWindowRepresentedFilename (JNIEnv *env, jclass clazz, jlong windowPtr, jstring filename) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); NSURL *url = (filename == NULL) ? nil : [NSURL fileURLWithPath:JNFNormalizedNSStringForPath(env, filename)]; @@ -1500,7 +1500,7 @@ [nsWindow setRepresentedURL:url]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1514,7 +1514,7 @@ { __block jobject topmostWindowUnderMouse = nil; - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:YES block:^{ AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse]; @@ -1523,7 +1523,7 @@ } }]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); return topmostWindowUnderMouse; } @@ -1536,13 +1536,13 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMouseEnteredExitedEvents__ (JNIEnv *env, jclass clazz) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [AWTWindow synthesizeMouseEnteredExitedEventsForAllWindows]; }]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -1553,7 +1553,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSynthesizeMouseEnteredExitedEvents__JI (JNIEnv *env, jclass clazz, jlong windowPtr, jint eventType) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); if (eventType == NSMouseEntered || eventType == NSMouseExited) { NSWindow *nsWindow = OBJC(windowPtr); @@ -1562,10 +1562,10 @@ [AWTWindow synthesizeMouseEnteredExitedEvents:nsWindow withType:eventType]; }]; } else { - [JNFException raise:env as:kIllegalArgumentException reason:"unknown event type"]; + JNU_ThrowIllegalArgumentException(env, "unknown event type"); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1576,7 +1576,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow__1toggleFullScreenMode (JNIEnv *env, jobject peer, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); SEL toggleFullScreenSelector = @selector(toggleFullScreen:); @@ -1586,13 +1586,13 @@ [nsWindow performSelector:toggleFullScreenSelector withObject:nil]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeSetEnabled (JNIEnv *env, jclass clazz, jlong windowPtr, jboolean isEnabled) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ @@ -1601,13 +1601,13 @@ [window setEnabled: isEnabled]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeDispose (JNIEnv *env, jclass clazz, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ @@ -1626,13 +1626,13 @@ [window release]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeEnterFullScreenMode (JNIEnv *env, jclass clazz, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ @@ -1652,19 +1652,17 @@ NSRect screenRect = [[nsWindow screen] frame]; [nsWindow setFrame:screenRect display:YES]; } else { - [JNFException raise:[ThreadUtilities getJNIEnv] - as:kRuntimeException - reason:"Failed to enter full screen."]; + [NSException raise:@"Java Exception" reason:@"Failed to enter full screen." userInfo:nil]; } }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPlatformWindow_nativeExitFullScreenMode (JNIEnv *env, jclass clazz, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ @@ -1679,12 +1677,10 @@ // GraphicsDevice takes care of restoring pre full screen bounds } else { - [JNFException raise:[ThreadUtilities getJNIEnv] - as:kRuntimeException - reason:"Failed to exit full screen."]; + [NSException raise:@"Java Exception" reason:@"Failed to exit full screen." userInfo:nil]; } }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m @@ -570,12 +570,12 @@ JNIEXPORT void JNICALL Java_com_apple_eawt_Application_nativeInitializeApplicationDelegate (JNIEnv *env, jclass clz) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // Force initialization to happen on AppKit thread! [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [ApplicationDelegate sharedDelegate]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -586,13 +586,13 @@ JNIEXPORT void JNICALL Java_com_apple_eawt__1AppEventHandler_nativeOpenCocoaAboutWindow (JNIEnv *env, jclass clz) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [NSApp orderFrontStandardAboutPanel:nil]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -603,13 +603,13 @@ JNIEXPORT void JNICALL Java_com_apple_eawt__1AppEventHandler_nativeReplyToAppShouldTerminate (JNIEnv *env, jclass clz, jboolean doTerminate) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [NSApp replyToApplicationShouldTerminate:doTerminate]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -620,12 +620,12 @@ JNIEXPORT void JNICALL Java_com_apple_eawt__1AppEventHandler_nativeRegisterForNotification (JNIEnv *env, jclass clz, jint notificationType) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThread:@selector(_registerForNotification:) on:[ApplicationDelegate class] withObject:[NSNumber numberWithInt:notificationType] waitUntilDone:NO]; // AWT_THREADING Safe (non-blocking) -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -636,14 +636,14 @@ JNIEXPORT void JNICALL Java_com_apple_eawt__1AppDockIconHandler_nativeSetDockMenu (JNIEnv *env, jclass clz, jlong nsMenuPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSMenu *menu = (NSMenu *)jlong_to_ptr(nsMenuPtr); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ [ApplicationDelegate sharedDelegate].fDockMenu = menu; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -654,7 +654,7 @@ JNIEXPORT void JNICALL Java_com_apple_eawt__1AppDockIconHandler_nativeSetDockIconImage (JNIEnv *env, jclass clz, jlong nsImagePtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSImage *_image = (NSImage *)jlong_to_ptr(nsImagePtr); [ThreadUtilities performOnMainThread:@selector(_setDockIconImage:) @@ -662,7 +662,7 @@ withObject:_image waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -673,14 +673,14 @@ JNIEXPORT void JNICALL Java_com_apple_eawt__1AppDockIconHandler_nativeSetDockIconProgress (JNIEnv *env, jclass clz, jint value) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThread:@selector(_setDockIconProgress:) on:[ApplicationDelegate class] withObject:[NSNumber numberWithInt:value] waitUntilDone:NO]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -693,13 +693,13 @@ { __block NSImage *image = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ image = [[ApplicationDelegate _dockIconImage] retain]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(image); } @@ -712,7 +712,7 @@ JNIEXPORT void JNICALL Java_com_apple_eawt__1AppDockIconHandler_nativeSetDockIconBadge (JNIEnv *env, jclass clz, jstring badge) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString *badgeString = JNFJavaToNSString(env, badge); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ @@ -721,7 +721,7 @@ [dockTile display]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -732,7 +732,7 @@ JNIEXPORT void JNICALL Java_com_apple_eawt__1AppMiscHandlers_nativeRequestActivation (JNIEnv *env, jclass clz, jboolean allWindows) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ NSApplicationActivationOptions options = allWindows ? NSApplicationActivateAllWindows : 0; @@ -740,7 +740,7 @@ [[NSRunningApplication currentApplication] activateWithOptions:options]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -751,13 +751,13 @@ JNIEXPORT void JNICALL Java_com_apple_eawt__1AppMiscHandlers_nativeRequestUserAttention (JNIEnv *env, jclass clz, jboolean critical) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [NSApp requestUserAttention:critical ? NSCriticalRequest : NSInformationalRequest]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -768,14 +768,14 @@ JNIEXPORT void JNICALL Java_com_apple_eawt__1AppMiscHandlers_nativeOpenHelpViewer (JNIEnv *env, jclass clz) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThread:@selector(showHelp:) on:NSApp withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -786,11 +786,11 @@ JNIEXPORT void JNICALL Java_com_apple_eawt__1AppMiscHandlers_nativeEnableSuddenTermination (JNIEnv *env, jclass clz) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [[NSProcessInfo processInfo] enableSuddenTermination]; // Foundation thread-safe -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -801,11 +801,11 @@ JNIEXPORT void JNICALL Java_com_apple_eawt__1AppMiscHandlers_nativeDisableSuddenTermination (JNIEnv *env, jclass clz) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [[NSProcessInfo processInfo] disableSuddenTermination]; // Foundation thread-safe -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -816,7 +816,7 @@ JNIEXPORT void JNICALL Java_com_apple_eawt__1AppMenuBarHandler_nativeSetMenuState (JNIEnv *env, jclass clz, jint menuID, jboolean visible, jboolean enabled) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ ApplicationDelegate *delegate = [ApplicationDelegate sharedDelegate]; @@ -830,7 +830,7 @@ } }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -841,12 +841,12 @@ JNIEXPORT void JNICALL Java_com_apple_eawt__1AppMenuBarHandler_nativeSetDefaultMenuBar (JNIEnv *env, jclass clz, jlong cMenuBarPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); CMenuBar *menu = (CMenuBar *)jlong_to_ptr(cMenuBarPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [ApplicationDelegate sharedDelegate].fDefaultMenuBar = menu; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m @@ -131,7 +131,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CClipboard_declareTypes (JNIEnv *env, jobject inObject, jlongArray inTypes, jobject inJavaClip) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); jint i; jint nElements = (*env)->GetArrayLength(env, inTypes); @@ -146,7 +146,7 @@ (*env)->ReleasePrimitiveArrayCritical(env, inTypes, elements, JNI_ABORT); [[CClipboard sharedClipboard] declareTypes:formatArray withOwner:inJavaClip jniEnv:env]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -161,7 +161,7 @@ return; } -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); jint nBytes = (*env)->GetArrayLength(env, inBytes); jbyte *rawBytes = (*env)->GetPrimitiveArrayCritical(env, inBytes, NULL); CHECK_NULL(rawBytes); @@ -171,7 +171,7 @@ [ThreadUtilities performOnMainThreadWaiting:YES block:^() { [[NSPasteboard generalPasteboard] setData:bytesAsData forType:format]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -183,7 +183,7 @@ (JNIEnv *env, jobject inObject) { jlongArray returnValue = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); __block NSArray* dataTypes; [ThreadUtilities performOnMainThreadWaiting:YES block:^() { @@ -228,7 +228,7 @@ } (*env)->ReleaseLongArrayElements(env, returnValue, saveFormats, JNI_COMMIT); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue; } @@ -244,7 +244,7 @@ // Note that this routine makes no attempt to interpret the data, since we're returning // a byte array back to Java. CDataTransferer will do that if necessary. -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString *formatAsString = formatForIndex(format); __block NSData* clipData; @@ -253,7 +253,7 @@ }]; if (clipData == NULL) { - [JNFException raise:env as:"java/io/IOException" reason:"Font transform has NaN position"]; + JNU_ThrowIOException(env, "Font transform has NaN position"); return NULL; } else { [clipData autorelease]; @@ -270,7 +270,7 @@ (*env)->SetByteArrayRegion(env, returnValue, 0, dataSize, (jbyte *)dataBuffer); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue; } @@ -283,11 +283,11 @@ (JNIEnv *env, jobject inObject) { __block BOOL ret = NO; - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ ret = [[CClipboard sharedClipboard] checkPasteboardWithoutNotification:nil]; }]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); return ret; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CCursorManager.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CCursorManager.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CCursorManager.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CCursorManager.m @@ -73,31 +73,33 @@ Java_sun_lwawt_macosx_CCursorManager_nativeSetBuiltInCursor (JNIEnv *env, jclass class, jint type, jstring name) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString *cursorName = JNFJavaToNSString(env, name); SEL cursorSelector = (type == sun_lwawt_macosx_CCursorManager_NAMED_CURSOR) ? lookupCursorSelectorForName(cursorName) : lookupCursorSelectorForType(type); if (cursorSelector == nil) { NSString *reason = [NSString stringWithFormat:@"unimplemented built-in cursor type: %d / %@", type, cursorName]; - [JNFException raise:env as:kIllegalArgumentException reason:[reason UTF8String]]; + JNU_ThrowIllegalArgumentException(env, [reason UTF8String]); + return; } if (![[NSCursor class] respondsToSelector:cursorSelector]) { - [JNFException raise:env as:kNoSuchMethodException reason:"missing NSCursor selector"]; + JNU_ThrowByName(env, "java/lang/NoSuchMethodException", "missing NSCursor selector"); + return; } [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ setCursorOnAppKitThread([[NSCursor class] performSelector:cursorSelector]); }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CCursorManager_nativeSetCustomCursor (JNIEnv *env, jclass class, jlong imgPtr, jdouble x, jdouble y) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSImage *image = (NSImage *)jlong_to_ptr(imgPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ @@ -107,7 +109,7 @@ [cursor release]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } JNIEXPORT jobject JNICALL @@ -116,7 +118,7 @@ { jobject jpt = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); CGEventRef event = CGEventCreate(NULL); CGPoint globalPos = CGEventGetLocation(event); @@ -124,7 +126,7 @@ jpt = NSToJavaPoint(env, globalPos); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return jpt; } @@ -134,7 +136,7 @@ Java_sun_lwawt_macosx_CCursorManager_nativeSetAllowsCursorSetInBackground (JNIEnv *env, jclass class, jboolean allows) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); SEL allowsSetInBackground_SEL = @selector(javaSetAllowsCursorSetInBackground:); if ([[NSCursor class] respondsToSelector:allowsSetInBackground_SEL]) { @@ -150,6 +152,6 @@ }]; } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m @@ -26,7 +26,7 @@ #import "CDataTransferer.h" #include "sun_lwawt_macosx_CDataTransferer.h" -#import "jni_util.h" +#import "JNIUtilities.h" #import @@ -109,9 +109,9 @@ (JNIEnv *env, jobject jthis, jstring newformat) { jlong returnValue = -1; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); returnValue = registerFormatWithPasteboard(JNFJavaToNSString(env, newformat)); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue; } @@ -124,9 +124,9 @@ (JNIEnv *env, jobject jthis, jlong index) { jstring returnValue = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); returnValue = JNFNSToJavaString(env, formatForIndex(index)); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue; } @@ -200,7 +200,7 @@ jobjectArray jreturnArray = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // Get byte array elements: jboolean isCopy; jbyte* jbytes = (*env)->GetByteArrayElements(env, jbytearray, &isCopy); @@ -250,6 +250,6 @@ // We're done with the jbytes (backing the plist/plistArray): (*env)->ReleaseByteArrayElements(env, jbytearray, jbytes, JNI_ABORT); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return jreturnArray; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDesktopPeer.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDesktopPeer.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDesktopPeer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDesktopPeer.m @@ -24,6 +24,7 @@ */ +#import "JNIUtilities.h" #import #import #import @@ -37,7 +38,7 @@ (JNIEnv *env, jclass clz, jstring uri) { OSStatus status = noErr; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // I would love to use NSWorkspace here, but it's not thread safe. Why? I don't know. // So we use LaunchServices directly. @@ -49,7 +50,7 @@ LSApplicationParameters params = {0, flags, NULL, NULL, NULL, NULL, NULL}; status = LSOpenURLsWithRole((CFArrayRef)[NSArray arrayWithObject:url], kLSRolesAll, NULL, ¶ms, NULL, 0); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return status; } @@ -62,7 +63,7 @@ (JNIEnv *env, jclass clz, jstring jpath, jboolean print) { OSStatus status = noErr; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // I would love to use NSWorkspace here, but it's not thread safe. Why? I don't know. // So we use LaunchServices directly. @@ -81,7 +82,7 @@ status = LSOpenURLsWithRole((CFArrayRef)[NSArray arrayWithObject:url], kLSRolesAll, NULL, ¶ms, NULL, 0); [url release]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return status; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m @@ -645,7 +645,7 @@ //DLog4(@"[CDragSource draggedImage moved]: (%d, %d) %@\n", (int) screenPoint.x, (int) screenPoint.y, self); JNIEnv* env = [ThreadUtilities getJNIEnv]; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [AWTToolkit eventCountPlusPlus]; // There are two things we would be interested in: // a) mouse pointer has moved @@ -695,7 +695,7 @@ (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMouseMovedMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) CHECK_EXCEPTION(); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } - (BOOL)ignoreModifierKeysWhileDragging { diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m @@ -25,6 +25,7 @@ #import "sun_lwawt_macosx_CDragSourceContextPeer.h" +#import "JNIUtilities.h" #import #import "CDragSource.h" @@ -46,7 +47,7 @@ id controlObj = (id) jlong_to_ptr(jnativepeer); __block CDragSource* dragSource = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // Global references are disposed when the DragSource is removed jobject gComponent = JNFNewGlobalRef(env, jcomponent); @@ -74,7 +75,7 @@ formats:gFormats formatMap:gFormatMap]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(dragSource); } @@ -91,9 +92,9 @@ CDragSource* dragSource = (CDragSource*) jlong_to_ptr(nativeDragSourceVal); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [dragSource drag]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -106,7 +107,7 @@ { CDragSource* dragSource = (CDragSource*) jlong_to_ptr(nativeDragSourceVal); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [dragSource removeFromView:env]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m @@ -731,10 +731,10 @@ { CDropTarget* dropTarget = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); id controlObj = (id) jlong_to_ptr(jnativepeer); dropTarget = [[CDropTarget alloc] init:jdroptarget component:jcomponent control:controlObj]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(dropTarget); } @@ -749,7 +749,7 @@ { id dropTarget = (id)jlong_to_ptr(nativeDropTargetVal); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [dropTarget removeFromView:env]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m @@ -76,7 +76,7 @@ // works off a data copy and doesn't have to go to the native event thread to get the data. // We can have endTransfer just call startTransfer. -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // Get the drop target native object: CDropTarget* dropTarget = GetCDropTarget(jdroptarget); if (dropTarget == nil) { @@ -113,7 +113,7 @@ // if no error return dropTarget's draggingSequence result = [dropTarget getDraggingSequenceNumber]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return result; } @@ -144,7 +144,7 @@ (JNIEnv *env, jobject jthis, jlong jdroptarget, jlong jdroptransfer, jboolean jislocal, jboolean jsuccess, jint jdropaction) { // Get the drop target native object: -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); CDropTarget* dropTarget = GetCDropTarget(jdroptarget); if (dropTarget == nil) { DLog2(@"[CDropTargetContextPeer dropDone]: GetCDropTarget failed for %d.\n", (NSInteger) jdroptarget); @@ -153,7 +153,7 @@ // Notify drop target Java is all done with this dragging sequence: [dropTarget javaDraggingEnded:(jlong)jdroptransfer success:jsuccess action:jdropaction]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CFRetainedResource.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CFRetainedResource.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CFRetainedResource.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CFRetainedResource.m @@ -23,6 +23,8 @@ * questions. */ +#import "JNIUtilities.h" + #import #import @@ -53,11 +55,11 @@ } } else { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); CFRelease(jlong_to_ptr(ptr)); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m @@ -198,7 +198,7 @@ { jobjectArray returnValue = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString *dialogTitle = JNFJavaToNSString(env, title); if ([dialogTitle length] == 0) { dialogTitle = @" "; @@ -235,6 +235,6 @@ } [dialogDelegate release]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m @@ -151,7 +151,7 @@ static jobject createJavaDisplayMode(CGDisplayModeRef mode, JNIEnv *env) { jobject ret = NULL; jint h = DEFAULT_DEVICE_HEIGHT, w = DEFAULT_DEVICE_WIDTH, bpp = 0, refrate = 0; - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); if (mode) { CFStringRef currentBPP = CGDisplayModeCopyPixelEncoding(mode); bpp = getBPPFromModeString(currentBPP); @@ -164,7 +164,7 @@ DECLARE_METHOD_RETURN(jc_DisplayMode_ctor, jc_DisplayMode, "", "(IIII)V", ret); ret = (*env)->NewObject(env, jc_DisplayMode, jc_DisplayMode_ctor, w, h, bpp, refrate); CHECK_EXCEPTION(); - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); return ret; } @@ -234,7 +234,7 @@ jobject ret = NULL; __block NSRect frame = NSZeroRect; __block NSRect visibleFrame = NSZeroRect; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ NSArray *screens = [NSScreen screens]; @@ -258,7 +258,7 @@ DECLARE_METHOD_RETURN(jc_Insets_ctor, jc_Insets, "", "(IIII)V", ret); ret = (*env)->NewObject(env, jc_Insets, jc_Insets_ctor, top, left, bottom, right); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ret; } @@ -272,7 +272,7 @@ Java_sun_awt_CGraphicsDevice_nativeSetDisplayMode (JNIEnv *env, jclass class, jint displayID, jint w, jint h, jint bpp, jint refrate) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); CFArrayRef allModes = getAllValidDisplayModes(displayID); CGDisplayModeRef closestMatch = getBestModeForParameters(allModes, (int)w, (int)h, (int)bpp, (int)refrate); @@ -289,14 +289,14 @@ CGDisplayModeRelease(closestMatch); }]; } else { - [JNFException raise:env as:kIllegalArgumentException reason:"Invalid display mode"]; + JNU_ThrowIllegalArgumentException(env, "Invalid display mode"); } if (retCode != kCGErrorSuccess){ - [JNFException raise:env as:kIllegalArgumentException reason:"Unable to set display mode!"]; + JNU_ThrowIllegalArgumentException(env, "Unable to set display mode!"); } CFRelease(allModes); - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* * Class: sun_awt_CGraphicsDevice @@ -325,7 +325,7 @@ (JNIEnv *env, jclass class, jint displayID) { jobjectArray jreturnArray = NULL; - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); CFArrayRef allModes = getAllValidDisplayModes(displayID); CFIndex numModes = allModes ? CFArrayGetCount(allModes): 0; @@ -354,7 +354,7 @@ if (allModes) { CFRelease(allModes); } - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); return jreturnArray; } @@ -370,7 +370,7 @@ { __block jdouble ret = 1.0f; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ NSArray *screens = [NSScreen screens]; @@ -386,6 +386,6 @@ } }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ret; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m @@ -43,23 +43,19 @@ { jintArray ret = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); /* Get the count */ CGDisplayCount displayCount; if (CGGetOnlineDisplayList(MAX_DISPLAYS, NULL, &displayCount) != kCGErrorSuccess) { - [JNFException raise:env - as:kInternalError - reason:"CGGetOnlineDisplayList() failed to get display count"]; + JNU_ThrowInternalError(env, "CGGetOnlineDisplayList() failed to get display count"); return NULL; } /* Allocate an array and get the size list of display Ids */ CGDirectDisplayID displays[MAX_DISPLAYS]; if (CGGetOnlineDisplayList(displayCount, displays, &displayCount) != kCGErrorSuccess) { - [JNFException raise:env - as:kInternalError - reason:"CGGetOnlineDisplayList() failed to get display list"]; + JNU_ThrowInternalError(env, "CGGetOnlineDisplayList() failed to get display list"); return NULL; } @@ -91,7 +87,7 @@ (*env)->ReleaseIntArrayElements(env, ret, elems, 0); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ret; } @@ -145,21 +141,19 @@ { jlong ret = 0L; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); JNFWeakJObjectWrapper *wrapper = [[JNFWeakJObjectWrapper wrapperWithJObject:this withEnv:env] retain]; /* Register the callback */ if (CGDisplayRegisterReconfigurationCallback(&displaycb_handle, wrapper) != kCGErrorSuccess) { - [JNFException raise:env - as:kInternalError - reason:"CGDisplayRegisterReconfigurationCallback() failed"]; + JNU_ThrowInternalError(env, "CGDisplayRegisterReconfigurationCallback() failed"); return 0L; } ret = ptr_to_jlong(wrapper); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ret; } @@ -173,21 +167,19 @@ Java_sun_awt_CGraphicsEnvironment_deregisterDisplayReconfiguration (JNIEnv *env, jobject this, jlong p) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); JNFWeakJObjectWrapper *wrapper = (JNFWeakJObjectWrapper *)jlong_to_ptr(p); if (!wrapper) return; /* Remove the registration */ if (CGDisplayRemoveReconfigurationCallback(&displaycb_handle, wrapper) != kCGErrorSuccess) { - [JNFException raise:env - as:kInternalError - reason:"CGDisplayRemoveReconfigurationCallback() failed, leaking the callback context!"]; + JNU_ThrowInternalError(env, "CGDisplayRemoveReconfigurationCallback() failed, leaking the callback context!"); return; } [wrapper setJObject:NULL withEnv:env]; // more efficient to pre-clear [wrapper release]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m @@ -111,7 +111,7 @@ { jlong result = 0L; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, width, height); if (imageRep) { @@ -120,7 +120,7 @@ result = ptr_to_jlong(nsImage); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return result; } @@ -135,7 +135,7 @@ { jlong result = 0L; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); jsize num = (*env)->GetArrayLength(env, buffers); NSMutableArray * reps = [NSMutableArray arrayWithCapacity: num]; @@ -164,7 +164,7 @@ result = ptr_to_jlong(nsImage); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return result; } @@ -179,7 +179,7 @@ { NSImage *image = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); IconRef iconRef; if (noErr == GetIconRef(kOnSystemDisk, kSystemIconsCreator, selector, &iconRef)) { @@ -187,7 +187,7 @@ ReleaseIconRef(iconRef); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(image); } @@ -202,12 +202,12 @@ { NSImage *image = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString *path = JNFNormalizedNSStringForPath(env, file); image = [[NSImage alloc] initByReferencingFile:path]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(image); } @@ -222,7 +222,7 @@ { __block NSImage *image = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString *path = JNFNormalizedNSStringForPath(env, file); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ @@ -230,7 +230,7 @@ [image setScalesWhenResized:TRUE]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(image); } @@ -245,11 +245,11 @@ { NSImage *image = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); image = [[NSImage imageNamed:JNFJavaToNSString(env, name)] retain]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(image); } @@ -263,7 +263,7 @@ (JNIEnv *env, jclass klass, jlong nsImgPtr, jintArray buffer, jint sw, jint sh, jint dw, jint dh) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSImage *img = (NSImage *)jlong_to_ptr(nsImgPtr); jint *dst = (*env)->GetPrimitiveArrayCritical(env, buffer, NULL); @@ -274,7 +274,7 @@ (*env)->ReleasePrimitiveArrayCritical(env, buffer, dst, JNI_ABORT); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -287,11 +287,11 @@ { jobject size = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); size = NSToJavaSize(env, [(NSImage *)jlong_to_ptr(nsImgPtr) size]); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return size; } @@ -307,12 +307,12 @@ if (!image) return; NSImage *i = (NSImage *)jlong_to_ptr(image); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [i setScalesWhenResized:TRUE]; [i setSize:NSMakeSize(w, h)]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -326,7 +326,7 @@ if (!image) return; NSImage *i = (NSImage *)jlong_to_ptr(image); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSImageRep *imageRep = nil; NSArray *imageRepresentations = [i representations]; @@ -335,7 +335,7 @@ [imageRep setSize:NSMakeSize(w, h)]; } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } NSComparisonResult getOrder(BOOL order){ @@ -355,7 +355,7 @@ jobjectArray jreturnArray = NULL; NSImage *img = (NSImage *)jlong_to_ptr(image); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSArray *imageRepresentations = [img representations]; if([imageRepresentations count] == 0){ @@ -417,7 +417,7 @@ JNU_CHECK_EXCEPTION_RETURN(env, NULL); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return jreturnArray; } @@ -432,7 +432,7 @@ { jbyteArray result = 0L; - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, width, height); if (imageRep) { @@ -446,7 +446,7 @@ (*env)->ReleasePrimitiveArrayCritical(env, result, tiffData, 0); } - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); return result; } @@ -462,7 +462,7 @@ jlong result = 0L; CHECK_NULL_RETURN(sourceData, 0L); - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); jsize sourceSize = (*env)->GetArrayLength(env, sourceData); if (sourceSize == 0) return 0L; @@ -476,7 +476,7 @@ CHECK_NULL_RETURN(newImage, 0L); result = ptr_to_jlong(newImage); - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); return result; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m @@ -152,7 +152,7 @@ if (!inputMethodController) return NULL; jobject returnValue = 0; __block NSString *keyboardInfo = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ keyboardInfo = [inputMethodController performSelector:@selector(currentInputMethodName)]; @@ -163,7 +163,7 @@ returnValue = JNFNSToJavaString(env, keyboardInfo); [keyboardInfo release]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue; } @@ -175,14 +175,14 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethod_nativeNotifyPeer (JNIEnv *env, jobject this, jlong nativePeer, jobject inputMethod) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTView *view = (AWTView *)jlong_to_ptr(nativePeer); JNFJObjectWrapper *inputMethodWrapper = [[JNFJObjectWrapper alloc] initWithJObject:inputMethod withEnv:env]; [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [CInputMethod _nativeNotifyPeerWithView:view inputMethod:inputMethodWrapper]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } @@ -194,14 +194,14 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethod_nativeEndComposition (JNIEnv *env, jobject this, jlong nativePeer) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTView *view = (AWTView *)jlong_to_ptr(nativePeer); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [CInputMethod _nativeEndComposition:view]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -215,7 +215,7 @@ if (!inputMethodController) return NULL; jobject returnValue = 0; __block NSString *isoAbbreviation; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ isoAbbreviation = (NSString *) [inputMethodController performSelector:@selector(currentInputMethodLocale)]; @@ -245,7 +245,7 @@ returnValue = sLastKeyboardLocaleObj; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue; } @@ -258,7 +258,7 @@ JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CInputMethod_setNativeLocale (JNIEnv *env, jobject this, jstring locale, jboolean isActivating) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString *localeStr = JNFJavaToNSString(env, locale); [localeStr retain]; @@ -267,7 +267,7 @@ }]; [localeStr release]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return JNI_TRUE; } @@ -299,7 +299,7 @@ jobject returnValue = 0; __block NSArray *selectableArray = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ selectableArray = (NSArray *)[inputMethodController performSelector:@selector(availableInputMethodLocales)]; @@ -327,7 +327,7 @@ (*env)->DeleteLocalRef(env, localeObj); } [selectableArray release]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenu.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenu.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenu.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenu.m @@ -30,6 +30,7 @@ #import "CMenu.h" #import "CMenuBar.h" #import "ThreadUtilities.h" +#import "JNIUtilities.h" #import "sun_lwawt_macosx_CMenu.h" @@ -159,7 +160,7 @@ (JNIEnv *env, jobject peer, jlong parentMenu) { CMenu *aCMenu = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer); @@ -168,7 +169,7 @@ // Add it to the parent menu [((CMenu *)jlong_to_ptr(parentMenu)) addJavaSubmenu: aCMenu]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(aCMenu); } @@ -187,7 +188,7 @@ { CMenu *aCMenu = nil; CMenuBar *parent = (CMenuBar *)jlong_to_ptr(parentMenuBar); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer); @@ -203,7 +204,7 @@ [parent javaSetHelpMenu: aCMenu]; } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(aCMenu); } @@ -217,10 +218,10 @@ Java_sun_lwawt_macosx_CMenu_nativeSetMenuTitle (JNIEnv *env, jobject peer, jlong menuObject, jstring label) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // Set the menu's title. [((CMenu *)jlong_to_ptr(menuObject)) setJavaMenuTitle:JNFJavaToNSString(env, label)]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -232,10 +233,10 @@ Java_sun_lwawt_macosx_CMenu_nativeAddSeparator (JNIEnv *env, jobject peer, jlong menuObject) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // Add a separator item. [((CMenu *)jlong_to_ptr(menuObject))addSeparator]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -247,10 +248,10 @@ Java_sun_lwawt_macosx_CMenu_nativeDeleteItem (JNIEnv *env, jobject peer, jlong menuObject, jint index) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // Remove the specified item. [((CMenu *)jlong_to_ptr(menuObject)) deleteJavaItem: index]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -264,10 +265,10 @@ { NSMenu* nsMenu = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // Strong retain this menu; it'll get released in Java_apple_laf_ScreenMenu_addMenuListeners nsMenu = [[((CMenu *)jlong_to_ptr(menuObject)) menu] retain]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(nsMenu); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuBar.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuBar.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuBar.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuBar.m @@ -23,6 +23,8 @@ * questions. */ +#import "JNIUtilities.h" + #import #import #import @@ -407,7 +409,7 @@ (JNIEnv *env, jobject peer) { __block CMenuBar *aCMenuBar = nil; - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer); @@ -420,7 +422,7 @@ return 0L; } - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); return ptr_to_jlong(aCMenuBar); } @@ -434,10 +436,10 @@ (JNIEnv *env, jobject peer, jlong menuBarObject, jlong menuObject, jint index) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); // Remove the specified item. [((CMenuBar *) jlong_to_ptr(menuBarObject)) javaAddMenu:(CMenu *) jlong_to_ptr(menuObject) atIndex:index]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -449,10 +451,10 @@ Java_sun_lwawt_macosx_CMenuBar_nativeDelMenu (JNIEnv *env, jobject peer, jlong menuBarObject, jint index) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); // Remove the specified item. [((CMenuBar *) jlong_to_ptr(menuBarObject)) javaDeleteMenu: index]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -464,8 +466,8 @@ Java_sun_lwawt_macosx_CMenuBar_nativeSetHelpMenu (JNIEnv *env, jobject peer, jlong menuBarObject, jlong menuObject) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); // Remove the specified item. [((CMenuBar *) jlong_to_ptr(menuBarObject)) javaSetHelpMenu: ((CMenu *)jlong_to_ptr(menuObject))]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuItem.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuItem.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuItem.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuItem.m @@ -70,7 +70,7 @@ - (void)handleAction:(NSMenuItem *)sender { AWT_ASSERT_APPKIT_THREAD; JNIEnv *env = [ThreadUtilities getJNIEnv]; - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); // If we are called as a result of user pressing a shortcut, do nothing, // because AVTView has already sent corresponding key event to the Java @@ -130,7 +130,7 @@ (*env)->CallVoidMethod(env, fPeer, jm_handleAction, UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event) } CHECK_EXCEPTION(); - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } @@ -332,7 +332,7 @@ jlong menuItemObj, jstring label, jchar shortcutKey, jint shortcutKeyCode, jint mods) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); NSString *theLabel = JNFJavaToNSString(env, label); NSString *theKeyEquivalent = nil; unichar macKey = shortcutKey; @@ -349,7 +349,7 @@ } [((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaLabel:theLabel shortcut:theKeyEquivalent modifierMask:mods]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -361,10 +361,10 @@ Java_sun_lwawt_macosx_CMenuItem_nativeSetTooltip (JNIEnv *env, jobject peer, jlong menuItemObj, jstring tooltip) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); NSString *theTooltip = JNFJavaToNSString(env, tooltip); [((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaToolTipText:theTooltip]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -376,9 +376,9 @@ Java_sun_lwawt_macosx_CMenuItem_nativeSetImage (JNIEnv *env, jobject peer, jlong menuItemObj, jlong image) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); [((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaImage:(NSImage*)jlong_to_ptr(image)]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -394,7 +394,7 @@ __block CMenuItem *aCMenuItem = nil; BOOL asSeparator = (isSeparator == JNI_TRUE) ? YES: NO; CMenu *parentCMenu = (CMenu *)jlong_to_ptr(parentCMenuObj); - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer); @@ -413,7 +413,7 @@ // setLabel will be called after creation completes. - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); return ptr_to_jlong(aCMenuItem); } @@ -426,10 +426,10 @@ Java_sun_lwawt_macosx_CMenuItem_nativeSetEnabled (JNIEnv *env, jobject peer, jlong menuItemObj, jboolean enable) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj); [item setJavaEnabled: (enable == JNI_TRUE)]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -441,10 +441,10 @@ Java_sun_lwawt_macosx_CCheckboxMenuItem_nativeSetState (JNIEnv *env, jobject peer, jlong menuItemObj, jboolean state) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj); [item setJavaState: (state == JNI_TRUE)]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -456,8 +456,8 @@ Java_sun_lwawt_macosx_CCheckboxMenuItem_nativeSetIsCheckbox (JNIEnv *env, jobject peer, jlong menuItemObj) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); CMenuItem *item = (CMenuItem *)jlong_to_ptr(menuItemObj); [item setIsCheckbox]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPopupMenu.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPopupMenu.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPopupMenu.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPopupMenu.m @@ -60,7 +60,7 @@ __block CPopupMenu *aCPopupMenu = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); jobject cPeerObjGlobal = JNFNewGlobalRef(env, peer); @@ -68,7 +68,7 @@ aCPopupMenu = [[CPopupMenu alloc] initWithPeer:cPeerObjGlobal]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(aCPopupMenu); } @@ -76,7 +76,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPopupMenu_nativeShowPopupMenu (JNIEnv *env, jobject peer, jlong menuPtr, jint x, jint y) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); CPopupMenu* cPopupMenu = (CPopupMenu*)jlong_to_ptr(menuPtr); @@ -88,7 +88,7 @@ inView: nil]; }]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m @@ -480,12 +480,12 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_abortDoc (JNIEnv *env, jobject jthis) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // This is only called during the printLoop from the printLoop thread NSPrintOperation* printLoop = [NSPrintOperation currentOperation]; NSPrintInfo* printInfo = [printLoop printInfo]; [printInfo setJobDisposition:NSPrintCancelJob]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -496,13 +496,13 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_getDefaultPage (JNIEnv *env, jobject jthis, jobject page) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSPrintInfo* printInfo = createDefaultNSPrintInfo(env, NULL); nsPrintInfoToJavaPageFormat(env, printInfo, page); [printInfo release]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -513,7 +513,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_validatePaper (JNIEnv *env, jobject jthis, jobject origpaper, jobject newpaper) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSPrintInfo* printInfo = createDefaultNSPrintInfo(env, NULL); @@ -522,7 +522,7 @@ nsPrintInfoToJavaPaper(env, printInfo, newpaper); [printInfo release]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -534,7 +534,7 @@ (JNIEnv *env, jobject jthis) { jlong result = -1; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // This is used to create the NSPrintInfo for this PrinterJob. Thread // safety is assured by the java side of this call. @@ -542,7 +542,7 @@ result = ptr_to_jlong(printInfo); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return result; } @@ -554,13 +554,13 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_dispose (JNIEnv *env, jobject jthis, jlong nsPrintInfo) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); if (nsPrintInfo != -1) { NSPrintInfo* printInfo = (NSPrintInfo*)jlong_to_ptr(nsPrintInfo); [printInfo release]; } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } @@ -583,7 +583,7 @@ jboolean retVal = JNI_FALSE; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // Get the first page's PageFormat for setting things up (This introduces // and is a facet of the same problem in Radar 2818593/2708932). jobject page = (*env)->CallObjectMethod(env, jthis, jm_getPageFormat, 0); // AWT_THREADING Safe (!appKit) @@ -647,7 +647,7 @@ (*env)->DeleteLocalRef(env, pageFormatArea); } } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return retVal; } @@ -664,7 +664,7 @@ DECLARE_FIELD_RETURN(jm_page, jc_CPrinterPageDialog, "fPage", "Ljava/awt/print/PageFormat;", NO); jboolean result = JNI_FALSE; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); GET_CPRINTERDIALOG_FIELD_RETURN(NO); GET_NSPRINTINFO_METHOD_RETURN(NO) jobject printerJob = (*env)->GetObjectField(env, jthis, sjm_printerJob); @@ -698,7 +698,7 @@ (*env)->DeleteLocalRef(env, page); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return result; } @@ -714,7 +714,7 @@ DECLARE_FIELD_RETURN(jm_pageable, jc_CPrinterJobDialog, "fPageable", "Ljava/awt/print/Pageable;", NO); jboolean result = JNI_FALSE; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); GET_CPRINTERDIALOG_FIELD_RETURN(NO); jobject printerJob = (*env)->GetObjectField(env, jthis, sjm_printerJob); if (printerJob == NULL) return NO; @@ -745,6 +745,6 @@ (*env)->DeleteLocalRef(env, pageable); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return result; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m @@ -23,7 +23,7 @@ * questions. */ -#import "jni_util.h" +#import "JNIUtilities.h" #import #import @@ -168,7 +168,7 @@ (JNIEnv *env, jobject peer, jint mouseLastX, jint mouseLastY, jint buttonsState, jboolean isButtonsDownState, jboolean isMouseMove) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); autoDelay(isMouseMove); // This is the native method called when Robot mouse events occur. @@ -254,7 +254,7 @@ PostMouseEvent(point, button, type, clickCount, eventNumber); - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -316,7 +316,7 @@ (JNIEnv *env, jobject peer, jint x, jint y, jint width, jint height, jdouble scale, jintArray pixels) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); jint picX = x; jint picY = y; @@ -362,7 +362,7 @@ // release the Java int array back up to the JVM (*env)->ReleasePrimitiveArrayCritical(env, pixels, jPixelData, 0); - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /**************************************************** diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m @@ -41,10 +41,10 @@ + (void)initialize { JNIEnv *env = [ThreadUtilities getJNIEnv]; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [CSystemColors reloadColors]; [[NSNotificationCenter defaultCenter] addObserver:[CSystemColors class] selector:@selector(systemColorsDidChange:) name:NSSystemColorsDidChangeNotification object:nil]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTextPipe.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTextPipe.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTextPipe.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTextPipe.m @@ -589,7 +589,7 @@ QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata); AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); jsize len = (*env)->GetStringLength(env, str); @@ -613,7 +613,7 @@ JNFReleaseStringUTF16UniChars(env, str, unichars); } -JNF_COCOA_RENDERER_EXIT(env); +JNI_COCOA_RENDERER_EXIT(env); } @@ -628,7 +628,7 @@ QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata); AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // Setup the text context if (length < MAX_STACK_ALLOC_GLYPH_BUFFER_SIZE) // optimized for stack allocation @@ -642,7 +642,8 @@ { jchar *copyUnichars = malloc(length * sizeof(jchar)); if (!copyUnichars) { - [JNFException raise:env as:kOutOfMemoryError reason:"Failed to malloc memory to create the glyphs for string drawing"]; + JNU_ThrowOutOfMemoryError(env, "Failed to malloc memory to create the glyphs for string drawing"); + return; } @try { @@ -654,7 +655,7 @@ } } -JNF_COCOA_RENDERER_EXIT(env); +JNI_COCOA_RENDERER_EXIT(env); } /* @@ -668,11 +669,11 @@ QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata); AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); DrawTextContext(env, qsdo, awtStrike, &aUnicode, 1, x, y); -JNF_COCOA_RENDERER_EXIT(env); +JNI_COCOA_RENDERER_EXIT(env); } /* @@ -686,7 +687,7 @@ QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata); AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); qsdo->BeginSurface(env, qsdo, SD_Text); if (qsdo->cgRef == NULL) @@ -704,5 +705,5 @@ qsdo->FinishSurface(env, qsdo); -JNF_COCOA_RENDERER_EXIT(env); +JNI_COCOA_RENDERER_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m @@ -333,14 +333,14 @@ (JNIEnv *env, jobject peer) { __block AWTTrayIcon *trayIcon = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); jobject thePeer = JNFNewGlobalRef(env, peer); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ trayIcon = [[AWTTrayIcon alloc] initWithPeer:thePeer]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(trayIcon); } @@ -363,7 +363,7 @@ */ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CTrayIcon_nativeSetToolTip (JNIEnv *env, jobject self, jlong model, jstring jtooltip) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTTrayIcon *icon = jlong_to_ptr(model); NSString *tooltip = JNFJavaToNSString(env, jtooltip); @@ -371,7 +371,7 @@ [icon setTooltip:tooltip]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -381,14 +381,14 @@ */ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CTrayIcon_setNativeImage (JNIEnv *env, jobject self, jlong model, jlong imagePtr, jboolean autosize) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTTrayIcon *icon = jlong_to_ptr(model); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ [icon setImage:jlong_to_ptr(imagePtr) sizing:autosize]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } JNIEXPORT jobject JNICALL @@ -396,7 +396,7 @@ (JNIEnv *env, jobject self, jlong model) { jobject jpt = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); __block NSPoint pt = NSZeroPoint; AWTTrayIcon *icon = jlong_to_ptr(model); @@ -407,7 +407,7 @@ jpt = NSToJavaPoint(env, pt); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return jpt; } @@ -416,7 +416,7 @@ Java_sun_lwawt_macosx_CTrayIcon_nativeShowNotification (JNIEnv *env, jobject self, jlong model, jobject jcaption, jobject jtext, long nsimage) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTTrayIcon *icon = jlong_to_ptr(model); NSString *caption = JNFJavaToNSString(env, jcaption); @@ -434,5 +434,5 @@ deliverNotification:notification]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CWrapper.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CWrapper.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CWrapper.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CWrapper.m @@ -23,6 +23,8 @@ * questions. */ +#import "JNIUtilities.h" + #import #import "ThreadUtilities.h" #import "sun_lwawt_macosx_CWrapper_NSWindow.h" @@ -36,7 +38,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_makeKeyAndOrderFront (JNIEnv *env, jclass cls, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); [ThreadUtilities performOnMainThread:@selector(makeKeyAndOrderFront:) @@ -44,7 +46,7 @@ withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -56,7 +58,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_makeKeyWindow (JNIEnv *env, jclass cls, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); [ThreadUtilities performOnMainThread:@selector(makeKeyWindow) @@ -64,7 +66,7 @@ withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -76,7 +78,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_makeMainWindow (JNIEnv *env, jclass cls, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); [ThreadUtilities performOnMainThread:@selector(makeMainWindow) @@ -84,7 +86,7 @@ withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -98,14 +100,14 @@ { __block jboolean canBecomeMainWindow = JNI_FALSE; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ canBecomeMainWindow = [window canBecomeMainWindow]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return canBecomeMainWindow; } @@ -121,14 +123,14 @@ { __block jboolean isKeyWindow = JNI_FALSE; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ isKeyWindow = [window isKeyWindow]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return isKeyWindow; } @@ -142,7 +144,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_orderFront (JNIEnv *env, jclass cls, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); [ThreadUtilities performOnMainThread:@selector(orderFront:) @@ -150,7 +152,7 @@ withObject:window waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -162,7 +164,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_orderOut (JNIEnv *env, jclass cls, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); [ThreadUtilities performOnMainThread:@selector(orderOut:) @@ -170,7 +172,7 @@ withObject:window waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -182,12 +184,12 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_close (JNIEnv *env, jclass cls, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [window close]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -199,7 +201,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_orderFrontRegardless (JNIEnv *env, jclass cls, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); [ThreadUtilities performOnMainThread:@selector(orderFrontRegardless) @@ -207,7 +209,7 @@ withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -219,7 +221,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_orderWindow (JNIEnv *env, jclass cls, jlong windowPtr, jint order, jlong relativeToPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); NSWindow *relativeTo = (NSWindow *)jlong_to_ptr(relativeToPtr); @@ -227,7 +229,7 @@ [window orderWindow:(NSWindowOrderingMode)order relativeTo:[relativeTo windowNumber]]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } // Used for CWrapper.NSWindow.setLevel() (and level() which isn't implemented yet) @@ -252,7 +254,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_setLevel (JNIEnv *env, jclass cls, jlong windowPtr, jint level) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); if (level >= 0 && level < sun_lwawt_macosx_CWrapper_NSWindow_MAX_WINDOW_LEVELS) { initLevels(); @@ -262,10 +264,10 @@ [window setLevel: LEVELS[level]]; }]; } else { - [JNFException raise:env as:kIllegalArgumentException reason:"unknown level"]; + JNU_ThrowIllegalArgumentException(env, "unknown level"); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -277,7 +279,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_addChildWindow (JNIEnv *env, jclass cls, jlong parentPtr, jlong childPtr, jint order) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *parent = (NSWindow *)jlong_to_ptr(parentPtr); NSWindow *child = (NSWindow *)jlong_to_ptr(childPtr); @@ -285,7 +287,7 @@ [parent addChildWindow:child ordered:order]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -297,7 +299,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_removeChildWindow (JNIEnv *env, jclass cls, jlong parentPtr, jlong childPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *parent = (NSWindow *)jlong_to_ptr(parentPtr); NSWindow *child = (NSWindow *)jlong_to_ptr(childPtr); @@ -306,7 +308,7 @@ withObject:child waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -318,14 +320,14 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_setAlphaValue (JNIEnv *env, jclass cls, jlong windowPtr, jfloat alpha) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [window setAlphaValue:(CGFloat)alpha]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -337,14 +339,14 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_setOpaque (JNIEnv *env, jclass cls, jlong windowPtr, jboolean opaque) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [window setOpaque:(BOOL)opaque]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -356,7 +358,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_setBackgroundColor (JNIEnv *env, jclass cls, jlong windowPtr, jint rgb) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); CGFloat alpha = (((rgb >> 24) & 0xff) / 255.0); @@ -369,7 +371,7 @@ [window setBackgroundColor:color]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -381,7 +383,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_miniaturize (JNIEnv *env, jclass cls, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); [ThreadUtilities performOnMainThread:@selector(miniaturize:) @@ -389,7 +391,7 @@ withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -401,7 +403,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_deminiaturize (JNIEnv *env, jclass cls, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); [ThreadUtilities performOnMainThread:@selector(deminiaturize:) @@ -409,7 +411,7 @@ withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -423,14 +425,14 @@ { __block jboolean isZoomed = JNI_FALSE; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ isZoomed = [window isZoomed]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return isZoomed; } @@ -444,7 +446,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_zoom (JNIEnv *env, jclass cls, jlong windowPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); [ThreadUtilities performOnMainThread:@selector(zoom:) @@ -452,7 +454,7 @@ withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -464,7 +466,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSWindow_makeFirstResponder (JNIEnv *env, jclass cls, jlong windowPtr, jlong responderPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSWindow *window = (NSWindow *)jlong_to_ptr(windowPtr); NSResponder *responder = (NSResponder *)jlong_to_ptr(responderPtr); @@ -473,7 +475,7 @@ withObject:responder waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -485,7 +487,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSView_addSubview (JNIEnv *env, jclass cls, jlong viewPtr, jlong subviewPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSView *view = (NSView *)jlong_to_ptr(viewPtr); NSView *subview = (NSView *)jlong_to_ptr(subviewPtr); @@ -493,7 +495,7 @@ [view addSubview:subview]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -505,7 +507,7 @@ Java_sun_lwawt_macosx_CWrapper_00024NSView_removeFromSuperview (JNIEnv *env, jclass cls, jlong viewPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSView *view = (NSView *)jlong_to_ptr(viewPtr); [ThreadUtilities performOnMainThread:@selector(removeFromSuperview) @@ -513,7 +515,7 @@ withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -525,14 +527,14 @@ Java_sun_lwawt_macosx_CWrapper_00024NSView_setFrame (JNIEnv *env, jclass cls, jlong viewPtr, jint x, jint y, jint w, jint h) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSView *view = (NSView *)jlong_to_ptr(viewPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [view setFrame:NSMakeRect(x, y, w, h)]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -546,14 +548,14 @@ { __block jlong windowPtr = 0L; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSView *view = (NSView *)jlong_to_ptr(viewPtr); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ windowPtr = ptr_to_jlong([view window]); }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return windowPtr; } @@ -567,14 +569,14 @@ Java_sun_lwawt_macosx_CWrapper_00024NSView_setHidden (JNIEnv *env, jclass cls, jlong viewPtr, jboolean toHide) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); NSView *view = (NSView *)jlong_to_ptr(viewPtr); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [view setHidden:(BOOL)toHide]; }]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -587,7 +589,7 @@ (JNIEnv *env, jclass cls, jlong viewPtr, jstring msg) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSView *view = (NSView *)jlong_to_ptr(viewPtr); NSString* s = JNFJavaToNSString(env, msg); @@ -595,5 +597,5 @@ [view setToolTip: s]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m @@ -1241,7 +1241,7 @@ jboolean handled = JNI_FALSE; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); ImageSDOps* srcIsdo = LockImagePixels(env, srcIsd); ImageSDOps* dstIsdo = LockImagePixels(env, dstIsd); @@ -1320,7 +1320,7 @@ UnlockImagePixels(env, srcIsdo); UnlockImagePixels(env, dstIsdo); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return handled; } @@ -1329,7 +1329,7 @@ PRINT("clearSurfacePixels") jboolean handled = JNI_FALSE; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); ImageSDOps *isdo = LockImagePixels(env, bisd); @@ -1361,7 +1361,7 @@ } UnlockImagePixels(env, isdo); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return handled; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m @@ -1479,9 +1479,9 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessibility_focusChanged (JNIEnv *env, jobject jthis) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThread:@selector(postFocusChanged:) on:[JavaComponentAccessibility class] withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1492,9 +1492,9 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessible_valueChanged (JNIEnv *env, jclass jklass, jlong element) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThread:@selector(postValueChanged) on:(JavaComponentAccessibility *)jlong_to_ptr(element) withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1505,12 +1505,12 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessible_selectedTextChanged (JNIEnv *env, jclass jklass, jlong element) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThread:@selector(postSelectedTextChanged) on:(JavaComponentAccessibility *)jlong_to_ptr(element) withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1521,9 +1521,9 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessible_selectionChanged (JNIEnv *env, jclass jklass, jlong element) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThread:@selector(postSelectionChanged) on:(JavaComponentAccessibility *)jlong_to_ptr(element) withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1534,12 +1534,12 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessible_menuOpened (JNIEnv *env, jclass jklass, jlong element) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThread:@selector(postMenuOpened) on:(JavaComponentAccessibility *)jlong_to_ptr(element) withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1550,12 +1550,12 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessible_menuClosed (JNIEnv *env, jclass jklass, jlong element) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThread:@selector(postMenuClosed) on:(JavaComponentAccessibility *)jlong_to_ptr(element) withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1566,12 +1566,12 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessible_menuItemSelected (JNIEnv *env, jclass jklass, jlong element) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThread:@selector(postMenuItemSelected) on:(JavaComponentAccessibility *)jlong_to_ptr(element) withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -1582,9 +1582,9 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CAccessible_unregisterFromCocoaAXSystem (JNIEnv *env, jclass jklass, jlong element) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThread:@selector(unregisterFromCocoaAXSystem) on:(JavaComponentAccessibility *)jlong_to_ptr(element) withObject:nil waitUntilDone:NO]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } @implementation TabGroupAccessibility diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m @@ -474,9 +474,9 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_flushNativeSelectors (JNIEnv *env, jclass clz) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){}]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -541,11 +541,11 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_loadNativeColors (JNIEnv *env, jobject peer, jintArray jSystemColors, jintArray jAppleColors) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); if (doLoadNativeColors(env, jSystemColors, NO)) { doLoadNativeColors(env, jAppleColors, YES); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -560,11 +560,11 @@ jlong result; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // We double retain because this object is owned by both main thread and "other" thread // We release in both doAWTRunLoop and stopAWTRunLoop result = ptr_to_jlong([[[AWTRunLoopObject alloc] init] retain]); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return result; } @@ -578,7 +578,7 @@ (JNIEnv *env, jclass clz, jlong mediator, jboolean processEvents, jboolean inAWT) { AWT_ASSERT_APPKIT_THREAD; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTRunLoopObject* mediatorObject = (AWTRunLoopObject*)jlong_to_ptr(mediator); @@ -604,7 +604,7 @@ } } [mediatorObject release]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -615,7 +615,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_stopAWTRunLoop (JNIEnv *env, jclass clz, jlong mediator) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTRunLoopObject* mediatorObject = (AWTRunLoopObject*)jlong_to_ptr(mediator); @@ -623,7 +623,7 @@ [mediatorObject release]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -634,14 +634,14 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_performOnMainThreadAfterDelay (JNIEnv *env, jclass clz, jobject runnable, jlong delay) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); jobject gRunnable = (*env)->NewGlobalRef(env, runnable); CHECK_NULL(gRunnable); [ThreadUtilities performOnMainThreadWaiting:NO block:^() { JavaRunnable* performer = [[JavaRunnable alloc] initWithRunnable:gRunnable]; [performer performSelector:@selector(perform) withObject:nil afterDelay:(delay/1000.0)]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } @@ -672,13 +672,13 @@ { __block jboolean active = JNI_FALSE; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:YES block:^() { active = (jboolean)[NSRunningApplication currentApplication].active; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return active; } @@ -691,13 +691,13 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_activateApplicationIgnoringOtherApps (JNIEnv *env, jclass clazz) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ if(![NSApp isActive]){ [NSApp activateIgnoringOtherApps:YES]; } }]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } @@ -748,7 +748,7 @@ Java_sun_lwawt_macosx_LWCToolkit_initIDs (JNIEnv *env, jclass klass) { - JNF_COCOA_ENTER(env) + JNI_COCOA_ENTER(env); gNumberOfButtons = sun_lwawt_macosx_LWCToolkit_BUTTONS; @@ -777,7 +777,7 @@ (*env)->ReleaseIntArrayElements(env, obj, tmp, 0); (*env)->DeleteLocalRef(env, obj); - JNF_COCOA_EXIT(env) + JNI_COCOA_EXIT(env); } /* @@ -788,7 +788,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_initAppkit (JNIEnv *env, jclass klass, jobject appkitThreadGroup, jboolean headless) { - JNF_COCOA_ENTER(env) + JNI_COCOA_ENTER(env); [ThreadUtilities setAppkitThreadGroup:(*env)->NewGlobalRef(env, appkitThreadGroup)]; @@ -806,7 +806,7 @@ [AWTStarter start:headless ? YES : NO]; - JNF_COCOA_EXIT(env) + JNI_COCOA_EXIT(env); } JNIEXPORT jint JNICALL DEF_JNI_OnLoad(JavaVM *vm, void *reserved) { diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrintModel.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrintModel.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrintModel.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrintModel.m @@ -127,7 +127,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob__1safePrintLoop (JNIEnv *env, jclass clz, jlong target, jlong view) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); PrintModel *model = (PrintModel *)jlong_to_ptr(target); PrinterView *arg = (PrinterView *)jlong_to_ptr(view); @@ -138,6 +138,6 @@ [model release]; [arg release]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterSurfaceData.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterSurfaceData.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterSurfaceData.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterSurfaceData.m @@ -83,7 +83,7 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterSurfaceData_initOps(JNIEnv *env, jobject jthis, jlong nsRef, jobject jGraphicsState, jobjectArray jGraphicsStateObject, jint width, jint height) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); PRINT("Java_sun_lwawt_macosx_CPrinterSurfaceData_initOps") @@ -116,7 +116,7 @@ sdo->Setup = NULL; sdo->Dispose = PrintSD_dispose; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } static jint PrintSD_Lock(JNIEnv *env, SurfaceDataOps *sdo, SurfaceDataRasInfo *pRasInfo, jint lockflags) diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzRenderer.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzRenderer.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzRenderer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzRenderer.m @@ -636,7 +636,7 @@ { PRINT("Java_sun_java2d_CRenderer_doLine") QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); SDRenderType renderType = SD_Stroke; qsdo->BeginSurface(env, qsdo, renderType); if (qsdo->cgRef != NULL) @@ -644,7 +644,7 @@ doLine(qsdo, x1, y1, x2, y2); } qsdo->FinishSurface(env, qsdo); -JNF_COCOA_RENDERER_EXIT(env); +JNI_COCOA_RENDERER_EXIT(env); } /* @@ -657,7 +657,7 @@ { PRINT("Java_sun_java2d_CRenderer_doRect") QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); SDRenderType renderType = (isfill? SD_Fill : SD_Stroke); qsdo->BeginSurface(env, qsdo, renderType); if (qsdo->cgRef != NULL) @@ -665,7 +665,7 @@ doRect(qsdo, x, y, w, h, isfill); } qsdo->FinishSurface(env, qsdo); -JNF_COCOA_RENDERER_EXIT(env); +JNI_COCOA_RENDERER_EXIT(env); } /* @@ -678,7 +678,7 @@ { PRINT("Java_sun_java2d_CRenderer_doRoundRect") QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); SDRenderType renderType = (isfill? SD_Fill : SD_Stroke); qsdo->BeginSurface(env, qsdo, renderType); if (qsdo->cgRef != NULL) @@ -686,7 +686,7 @@ doRoundRect(qsdo, x, y, w, h, arcWidth, arcHeight, isfill); } qsdo->FinishSurface(env, qsdo); -JNF_COCOA_RENDERER_EXIT(env); +JNI_COCOA_RENDERER_EXIT(env); } /* @@ -699,7 +699,7 @@ { PRINT("Java_sun_java2d_CRenderer_doOval") QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); SDRenderType renderType = (isfill? SD_Fill : SD_Stroke); qsdo->BeginSurface(env, qsdo, renderType); if (qsdo->cgRef != NULL) @@ -707,7 +707,7 @@ doOval(qsdo, x, y, w, h, isfill); } qsdo->FinishSurface(env, qsdo); -JNF_COCOA_RENDERER_EXIT(env); +JNI_COCOA_RENDERER_EXIT(env); } /* @@ -720,7 +720,7 @@ { PRINT("Java_sun_java2d_CRenderer_doArc") QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); SDRenderType renderType = (isfill? SD_Fill : SD_Stroke); qsdo->BeginSurface(env, qsdo, renderType); if (qsdo->cgRef != NULL) @@ -728,7 +728,7 @@ doArc(qsdo, x, y, w, h, angleStart, angleExtent, arcType, isfill); } qsdo->FinishSurface(env, qsdo); -JNF_COCOA_RENDERER_EXIT(env); +JNI_COCOA_RENDERER_EXIT(env); } /* @@ -741,7 +741,7 @@ { PRINT("Java_sun_java2d_CRenderer_doPoly") QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); BOOL eoFill = YES; // polys are WIND_EVEN_ODD by definition SDRenderType renderType = (isfill? (eoFill ? SD_EOFill : SD_Fill) : SD_Stroke); qsdo->BeginSurface(env, qsdo, renderType); @@ -750,7 +750,7 @@ doPoly(env, qsdo, xpointsarray, ypointsarray, npoints, ispolygon, isfill); } qsdo->FinishSurface(env, qsdo); -JNF_COCOA_RENDERER_EXIT(env); +JNI_COCOA_RENDERER_EXIT(env); } /* @@ -763,7 +763,7 @@ { PRINT("Java_sun_java2d_CRenderer_doShape") QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); BOOL eoFill = (windingRule == java_awt_geom_PathIterator_WIND_EVEN_ODD); SDRenderType renderType = (isfill? (eoFill ? SD_EOFill : SD_Fill) : SD_Stroke); qsdo->BeginSurface(env, qsdo, renderType); @@ -774,7 +774,7 @@ doShape(qsdo, types, coordinates, length, isfill, shouldApplyOffset); } qsdo->FinishSurface(env, qsdo); -JNF_COCOA_RENDERER_EXIT(env); +JNI_COCOA_RENDERER_EXIT(env); } #define invalidContext(c) \ @@ -790,12 +790,12 @@ { PRINT("Java_sun_java2d_CRenderer_doImage") QuartzSDOps *qsdo = (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); qsdo->BeginSurface(env, qsdo, SD_Image); if (qsdo->cgRef != NULL) { doImage(env, qsdo, imageSurfaceData, fliph, flipv, w, h, sx, sy, sw, sh, dx, dy, dw, dh); } qsdo->FinishSurface(env, qsdo); -JNF_COCOA_RENDERER_EXIT(env); +JNI_COCOA_RENDERER_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzSurfaceData.h b/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzSurfaceData.h --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzSurfaceData.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzSurfaceData.h @@ -27,6 +27,7 @@ #import "BufImgSurfaceData.h" #import "AWTFont.h" #import +#import "JNIUtilities.h" // these flags are not defined on Tiger on PPC, so we need to make them a no-op #if !defined(kCGBitmapByteOrder32Host) @@ -150,10 +151,5 @@ NSColor* ByteParametersToNSColor(JNIEnv* env, jint *javaGraphicsStates, NSColor* defColor); -#define JNF_COCOA_RENDERER_EXIT(env) \ -} @catch(NSException *localException) { \ - qsdo->FinishSurface(env, qsdo); \ - [JNFException throwToJava:env exception:localException]; \ -} \ - if (_token) JNFNativeMethodExit(_token); \ -} +#define JNI_COCOA_RENDERER_EXIT(env) \ + JNI_COCOA_EXIT_WITH_ACTION(env, qsdo->FinishSurface(env, qsdo)) diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzSurfaceData.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzSurfaceData.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzSurfaceData.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzSurfaceData.m @@ -49,6 +49,12 @@ #define kOffset (0.5f) +#define JNI_COCOA_THROW_OOME(env, msg) \ + if ([NSThread isMainThread] == NO) { \ + JNU_ThrowOutOfMemoryError(env, msg); \ + } \ + [NSException raise:@"Java Exception" reason:@"Java OutOfMemoryException" userInfo:nil] + BOOL gAdjustForJavaDrawing; #pragma mark @@ -914,7 +920,7 @@ qsdo->gradientInfo = (StateGradientInfo*)malloc(sizeof(StateGradientInfo)); if (qsdo->gradientInfo == NULL) { - [JNFException raise:env as:kOutOfMemoryError reason:"Failed to malloc memory for gradient paint"]; + JNI_COCOA_THROW_OOME(env, "Failed to malloc memory for gradient paint"); } qsdo->graphicsStateInfo.simpleStroke = NO; @@ -1015,7 +1021,7 @@ qsdo->shadingInfo = (StateShadingInfo*)malloc(sizeof(StateShadingInfo)); if (qsdo->shadingInfo == NULL) { - [JNFException raise:env as:kOutOfMemoryError reason:"Failed to malloc memory for gradient paint"]; + JNI_COCOA_THROW_OOME(env, "Failed to malloc memory for gradient paint"); } qsdo->graphicsStateInfo.simpleStroke = NO; @@ -1061,7 +1067,7 @@ qsdo->patternInfo = (StatePatternInfo*)malloc(sizeof(StatePatternInfo)); if (qsdo->patternInfo == NULL) { - [JNFException raise:env as:kOutOfMemoryError reason:"Failed to malloc memory for texture paint"]; + JNI_COCOA_THROW_OOME(env, "Failed to malloc memory for texture paint"); } qsdo->graphicsStateInfo.simpleStroke = NO; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m --- a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m @@ -302,7 +302,7 @@ jint num = 0; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSArray *filteredFonts = GetFilteredFonts(); num = (jint)[filteredFonts count]; @@ -320,7 +320,7 @@ (*env)->DeleteLocalRef(env, jFontFamilyName); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -332,7 +332,7 @@ Java_sun_font_CFontManager_loadNativeDirFonts (JNIEnv *env, jclass clz, jstring filename) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString *path = JNFJavaToNSString(env, filename); NSURL *url = [NSURL fileURLWithPath:(NSString *)path]; @@ -342,7 +342,7 @@ NSLog(@"url is : %@", (NSString*)url); printf("res is %d\n", res); #endif -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } #pragma mark --- sun.font.CFont JNI --- @@ -372,7 +372,7 @@ jlong awtFontPtr, jint jtag) { jbyteArray jbytes = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); CTFontTableTag tag = (CTFontTableTag)jtag; int i, found = 0; @@ -414,7 +414,7 @@ (jbyte*)tableBytes); CFRelease(table); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return jbytes; } @@ -431,7 +431,7 @@ { AWTFont *awtFont = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); awtFont = [AWTFont awtFontForName:JNFJavaToNSString(env, nativeFontName) @@ -441,7 +441,7 @@ CFRetain(awtFont); // GC } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(awtFont); } @@ -456,7 +456,7 @@ (JNIEnv *env, jobject cfont, jlong awtFontPtr) { float widthVal; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr); NSFont* nsFont = awtFont->fFont; @@ -465,7 +465,7 @@ NSNumber *width = [fontTraits objectForKey : NSFontWidthTrait]; widthVal = (float)[width floatValue]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return (jfloat)widthVal; } @@ -479,7 +479,7 @@ (JNIEnv *env, jobject cfont, jlong awtFontPtr) { float weightVal; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr); NSFont* nsFont = awtFont->fFont; @@ -488,7 +488,7 @@ NSNumber *weight = [fontTraits objectForKey : NSFontWeightTrait]; weightVal = (float)[weight floatValue]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return (jfloat)weightVal; } @@ -501,13 +501,13 @@ Java_sun_font_CFont_disposeNativeFont (JNIEnv *env, jclass clazz, jlong awtFontPtr) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); if (awtFontPtr) { CFRelease((AWTFont *)jlong_to_ptr(awtFontPtr)); // GC } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m --- a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m @@ -104,7 +104,7 @@ if (_fontThrowJavaException == YES) { \ char s[512]; \ sprintf(s, "%s-%s:%d", __FILE__, __FUNCTION__, __LINE__); \ - [JNFException raise:env as:kRuntimeException reason:s]; \ + JNU_ThrowByName(env, "java/lang/RuntimeException", s); \ } @@ -144,7 +144,7 @@ (JNIEnv *env, jclass clazz, jlong awtStrikePtr, jint glyphCode) { CGSize advance; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr); AWTFont *awtFont = awtStrike->fAWTFont; @@ -159,7 +159,7 @@ advance.width = round(advance.width); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return advance.width; } @@ -174,7 +174,7 @@ jlong awtStrikePtr, jint glyphCode, jobject result /*Rectangle*/, jdouble x, jdouble y) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr); AWTFont *awtFont = awtStrike->fAWTFont; @@ -203,7 +203,7 @@ (jfloat)bbox.origin.x, (jfloat)bbox.origin.y, (jfloat)bbox.size.width, (jfloat)bbox.size.height); CHECK_EXCEPTION(); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -218,7 +218,7 @@ { jobject generalPath = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTPathRef path = NULL; jfloatArray pointCoords = NULL; @@ -290,7 +290,7 @@ } AWT_FONT_CLEANUP_FINISH; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return generalPath; } @@ -305,7 +305,7 @@ jlong awtStrikePtr, jlongArray glyphInfoLongArray, jintArray glyphCodes, jint len) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr); @@ -333,7 +333,7 @@ } } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -345,7 +345,7 @@ (JNIEnv *env, jclass clazz, jlong nativeFontPtr, jdoubleArray glyphTxArray, jdoubleArray invDevTxArray, jint aaStyle, jint fmHint) { AWTStrike *awtStrike = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTFont *awtFont = (AWTFont *)jlong_to_ptr(nativeFontPtr); JRSFontRenderingStyle style = JRSFontGetRenderingStyleForHints(fmHint, aaStyle); @@ -360,7 +360,7 @@ CFRetain(awtStrike); // GC } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(awtStrike); } @@ -373,13 +373,13 @@ Java_sun_font_CStrike_disposeNativeStrikePtr (JNIEnv *env, jclass clazz, jlong awtStrike) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); if (awtStrike) { CFRelease((AWTStrike *)jlong_to_ptr(awtStrike)); // GC } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -393,7 +393,7 @@ { jobject metrics = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWT_FONT_CLEANUP_SETUP; AWTFont *awtfont = ((AWTStrike *)jlong_to_ptr(awtStrikePtr))->fAWTFont; @@ -436,7 +436,7 @@ cleanup: AWT_FONT_CLEANUP_FINISH; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return metrics; } @@ -450,9 +450,9 @@ JNIEXPORT void JNICALL Java_sun_font_CStrikeDisposer_removeGlyphInfoFromCache (JNIEnv *env, jclass cls, jlong glyphInfo) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); AccelGlyphCache_RemoveAllCellInfos((GlyphInfo*)jlong_to_ptr(glyphInfo)); - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m b/src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m --- a/src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m @@ -23,6 +23,8 @@ * questions. */ +#import "JNIUtilities.h" + #import #import "AWTFont.h" @@ -41,12 +43,12 @@ { jint numGlyphs = 0; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr); numGlyphs = [awtFont->fFont numberOfGlyphs]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return numGlyphs; } @@ -90,7 +92,7 @@ (JNIEnv *env, jclass clazz, jlong awtFontPtr, jint count, jcharArray unicodes, jintArray glyphs) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); AWTFont *awtFont = (AWTFont *)jlong_to_ptr(awtFontPtr); @@ -111,5 +113,5 @@ unicodesAsChars, JNI_ABORT); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m @@ -28,6 +28,7 @@ #import "CGLGraphicsConfig.h" #import "CGLSurfaceData.h" #import "ThreadUtilities.h" +#import "JNIUtilities.h" #import #import @@ -194,7 +195,7 @@ jint displayID, jint pixfmt, jint swapInterval) { jlong ret = 0L; - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); NSMutableArray * retArray = [NSMutableArray arrayWithCapacity:3]; [retArray addObject: [NSNumber numberWithInt: (int)displayID]]; [retArray addObject: [NSNumber numberWithInt: (int)pixfmt]]; @@ -206,7 +207,7 @@ } NSNumber * num = (NSNumber *)[retArray objectAtIndex: 0]; ret = (jlong)[num longValue]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); return ret; } 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 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.m @@ -175,7 +175,7 @@ { __block CGLLayer *layer = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); JNFWeakJObjectWrapper *javaLayer = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env]; @@ -185,7 +185,7 @@ layer = [[CGLLayer alloc] initWithJavaLayer: javaLayer]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(layer); } @@ -222,7 +222,7 @@ Java_sun_java2d_opengl_CGLLayer_nativeSetScale (JNIEnv *env, jclass cls, jlong layerPtr, jdouble scale) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); CGLLayer *layer = jlong_to_ptr(layerPtr); // We always call all setXX methods asynchronously, exception is only in // this method where we need to change native texture size and layer's scale @@ -231,5 +231,5 @@ [ThreadUtilities performOnMainThreadWaiting:[NSThread isMainThread] block:^(){ layer.contentsScale = scale; }]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLSurfaceData.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLSurfaceData.m --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLSurfaceData.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLSurfaceData.m @@ -27,7 +27,7 @@ #import "sun_java2d_opengl_CGLSurfaceData.h" -#import "jni_util.h" +#import "JNIUtilities.h" #import "OGLRenderQueue.h" #import "CGLGraphicsConfig.h" #import "CGLSurfaceData.h" @@ -62,9 +62,9 @@ NSOpenGLView *nsView = cglsdo->peerData; if (nsView != NULL) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [nsView unlockFocus]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } } #endif @@ -85,7 +85,7 @@ return JNI_FALSE; } -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo; #if USE_NSVIEW_FOR_SCRATCH @@ -99,7 +99,7 @@ currentVirtualScreen: [ctxinfo->context currentVirtualScreen]]; #endif -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return JNI_TRUE; } @@ -113,7 +113,7 @@ { J2dTraceLn(J2D_TRACE_INFO, "OGLSD_DestroyOGLSurface"); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); CGLSDOps *cglsdo = (CGLSDOps *)oglsdo->privOps; if (oglsdo->drawableType == OGLSD_WINDOW) { @@ -126,7 +126,7 @@ oglsdo->drawableType = OGLSD_UNDEFINED; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /** @@ -154,7 +154,7 @@ CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // avoid changing the context's target view whenever possible, since // calling setView causes flickering; as long as our context is current @@ -181,7 +181,7 @@ j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return oglc; } @@ -235,7 +235,7 @@ return oglc; } -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); CGLSDOps *cglsdo = (CGLSDOps *)dstOps->privOps; NSView *nsView = (NSView *)cglsdo->peerData; @@ -252,7 +252,7 @@ j2d_glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return oglc; } @@ -284,13 +284,13 @@ return JNI_FALSE; } -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSRect surfaceBounds = [v bounds]; oglsdo->drawableType = OGLSD_WINDOW; oglsdo->isOpaque = JNI_TRUE; oglsdo->width = surfaceBounds.size.width; oglsdo->height = surfaceBounds.size.height; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); J2dTraceLn2(J2D_TRACE_VERBOSE, " created window: w=%d h=%d", oglsdo->width, oglsdo->height); @@ -302,9 +302,9 @@ { J2dTraceLn(J2D_TRACE_INFO, "OGLSD_SwapBuffers"); -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [[NSOpenGLContext currentContext] flushBuffer]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } void @@ -446,8 +446,8 @@ OGLContext *oglc = cglsdo->configInfo->context; CGLCtxInfo *ctxinfo = (CGLCtxInfo *)oglc->ctxInfo; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); [ctxinfo->context update]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } } diff --git a/src/java.desktop/macosx/native/libosx/CFileManager.m b/src/java.desktop/macosx/native/libosx/CFileManager.m --- a/src/java.desktop/macosx/native/libosx/CFileManager.m +++ b/src/java.desktop/macosx/native/libosx/CFileManager.m @@ -25,6 +25,8 @@ #import "com_apple_eio_FileManager.h" +#import "JNIUtilities.h" + #import #import @@ -39,13 +41,13 @@ JNIEXPORT void JNICALL Java_com_apple_eio_FileManager__1setFileTypeAndCreator (JNIEnv *env, jclass clz, jstring javaFilename, jint type, jint creator) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString *filename = JNFNormalizedNSStringForPath(env, javaFilename); NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:type], NSFileHFSTypeCode, [NSNumber numberWithInt:creator], NSFileHFSCreatorCode, nil]; [[NSFileManager defaultManager] changeFileAttributes:attr atPath:filename]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -56,11 +58,11 @@ JNIEXPORT void JNICALL Java_com_apple_eio_FileManager__1setFileType (JNIEnv *env, jclass ckz, jstring javaFilename, jint type) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString *filename = JNFNormalizedNSStringForPath(env, javaFilename); NSDictionary *attr = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:type] forKey:NSFileHFSTypeCode]; [[NSFileManager defaultManager] changeFileAttributes:attr atPath:filename]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -71,11 +73,11 @@ JNIEXPORT void JNICALL Java_com_apple_eio_FileManager__1setFileCreator (JNIEnv *env, jclass clz, jstring javaFilename, jint creator) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString *filename = JNFNormalizedNSStringForPath(env, javaFilename); NSDictionary *attr = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:creator] forKey:NSFileHFSCreatorCode]; [[NSFileManager defaultManager] changeFileAttributes:attr atPath:filename]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } /* @@ -87,12 +89,12 @@ (JNIEnv *env, jclass clz, jstring javaFilename) { jint type = 0; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString *filename = JNFNormalizedNSStringForPath(env, javaFilename); NSDictionary *attributes = [[NSFileManager defaultManager] fileAttributesAtPath:filename traverseLink:YES]; NSNumber *val = [attributes objectForKey:NSFileHFSTypeCode]; type = [val intValue]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return type; } @@ -105,12 +107,12 @@ (JNIEnv *env, jclass clz, jstring javaFilename) { jint creator = 0; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString *filename = JNFNormalizedNSStringForPath(env, javaFilename); NSDictionary *attributes = [[NSFileManager defaultManager] fileAttributesAtPath:filename traverseLink:YES]; NSNumber *val = [attributes objectForKey:NSFileHFSCreatorCode]; creator = [val intValue]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return creator; } @@ -123,7 +125,7 @@ (JNIEnv *env, jclass clz, jshort domain, jint folderType, jboolean createIfNeeded) { jstring filename = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); FSRef foundRef; createIfNeeded = createIfNeeded || (folderType == kTemporaryFolderType) || (folderType == kChewableItemsFolderType); @@ -135,7 +137,7 @@ } } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return filename; } @@ -148,7 +150,7 @@ JNIEXPORT void JNICALL Java_com_apple_eio_FileManager__1openURL (JNIEnv *env, jclass clz, jstring urlString) { -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSURL *url = [NSURL URLWithString:JNFNormalizedNSStringForPath(env, urlString)]; @@ -157,7 +159,7 @@ [[NSWorkspace sharedWorkspace] openURL:url]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } @@ -170,7 +172,7 @@ (JNIEnv *env, jclass clz, jstring javaResourceName, jstring javaSubDirName, jstring javaTypeName) { jstring filename = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString *resourceName = JNFNormalizedNSStringForPath(env, javaResourceName); NSString *subDirectory = JNFNormalizedNSStringForPath(env, javaSubDirName); @@ -182,7 +184,7 @@ filename = JNFNormalizedJavaStringForPath(env, path); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return filename; } @@ -196,12 +198,12 @@ (JNIEnv *env, jclass clazz) { jstring filename = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSBundle *mainBundle = [NSBundle mainBundle]; filename = JNFNormalizedJavaStringForPath(env, [mainBundle bundlePath]); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return filename; } @@ -216,7 +218,7 @@ (JNIEnv *env, jclass clz, jstring fileName) { __block BOOL returnValue = NO; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString * path = JNFNormalizedNSStringForPath(env, fileName); NSURL *url = [NSURL fileURLWithPath:path]; @@ -227,7 +229,7 @@ error:nil]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue ? JNI_TRUE: JNI_FALSE; } @@ -242,14 +244,14 @@ (JNIEnv *env, jclass clz, jstring url) { __block jboolean returnValue = JNI_FALSE; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NSString *path = JNFNormalizedNSStringForPath(env, url); [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ returnValue = [[NSWorkspace sharedWorkspace] selectFile:path inFileViewerRootedAtPath:@""]; }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue; } diff --git a/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h b/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h --- a/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h +++ b/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h @@ -206,4 +206,35 @@ return y; \ }; +/* Create a pool and initiate a try block to catch any exception */ +#define JNI_COCOA_ENTER(env) \ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \ + @try { + +/* Don't allow NSExceptions to escape to Java. + * If there is a Java exception that has been thrown that should escape. + * And ensure we drain the auto-release pool. + */ +#define JNI_COCOA_EXIT(env) \ + } \ + @catch (NSException *e) { \ + NSLog(@"%@", [e callStackSymbols]); \ + } \ + @finally { \ + [pool drain]; \ + }; + +/* Same as above but adds a clean up action. + * Requires that whatever is being cleaned up is in scope. + */ +#define JNI_COCOA_EXIT_WITH_ACTION(env, action) \ + } \ + @catch (NSException *e) { \ + { action; }; \ + NSLog(@"%@", [e callStackSymbols]); \ + } \ + @finally { \ + [pool drain]; \ + }; + #endif /* __JNIUTILITIES_H */ diff --git a/src/java.desktop/macosx/native/libosxui/AquaFileView.m b/src/java.desktop/macosx/native/libosxui/AquaFileView.m --- a/src/java.desktop/macosx/native/libosxui/AquaFileView.m +++ b/src/java.desktop/macosx/native/libosxui/AquaFileView.m @@ -24,7 +24,7 @@ */ -#include +#include #import "com_apple_laf_AquaFileView.h" @@ -42,11 +42,11 @@ (JNIEnv *env, jclass clazz) { jstring returnValue = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); returnValue = JNFNSToJavaString(env, getRunningJavaBundle()); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue; }*/ @@ -59,11 +59,11 @@ (JNIEnv *env, jclass clazz) { jstring returnValue = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); returnValue = JNFNSToJavaString(env, [[NSBundle bundleWithIdentifier:@"com.apple.JavaVM"] bundlePath]); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue; } @@ -76,7 +76,7 @@ (JNIEnv *env, jclass clazz) { jstring returnValue = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); CFStringRef machineName = CSCopyMachineName(); returnValue = JNFNSToJavaString(env, (NSString*)machineName); @@ -85,7 +85,7 @@ CFRelease(machineName); } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue; } @@ -98,7 +98,7 @@ (JNIEnv *env, jclass clazz, jbyteArray absolutePath, jboolean isDir) { jint returnValue = com_apple_laf_AquaFileView_UNINITALIZED_LS_INFO; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); jbyte *byteArray = (*env)->GetByteArrayElements(env, absolutePath, NULL); CHECK_NULL_RETURN(byteArray, returnValue); @@ -126,7 +126,7 @@ } } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue; } @@ -139,7 +139,7 @@ (JNIEnv *env, jclass clazz, jbyteArray absolutePath, jboolean isDir) { jstring returnValue = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); jbyte *byteArray = (*env)->GetByteArrayElements(env, absolutePath, NULL); CHECK_NULL_RETURN(byteArray, returnValue); @@ -178,7 +178,7 @@ } } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue; } @@ -191,7 +191,7 @@ (JNIEnv *env, jclass clazz, jbyteArray pathToAlias, jboolean isDir) { jstring returnValue = NULL; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); UInt8 pathCString[MAXPATHLEN + 1]; size_t maxPathLen = sizeof(pathCString) - 1; @@ -224,6 +224,6 @@ } } -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return returnValue; } diff --git a/src/java.desktop/macosx/native/libosxui/AquaNativeResources.m b/src/java.desktop/macosx/native/libosxui/AquaNativeResources.m --- a/src/java.desktop/macosx/native/libosxui/AquaNativeResources.m +++ b/src/java.desktop/macosx/native/libosxui/AquaNativeResources.m @@ -39,10 +39,10 @@ // TODO(cpc): this code is currently disabled at the Java level #if 0 NSColor* color = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); color = [NSColor lightGrayColor];//[AWTColor getMagicBackgroundColor]; if (color) CFRetain(color); // GC -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(color); #else return 0L; diff --git a/src/java.desktop/macosx/native/libosxui/ScreenMenu.m b/src/java.desktop/macosx/native/libosxui/ScreenMenu.m --- a/src/java.desktop/macosx/native/libosxui/ScreenMenu.m +++ b/src/java.desktop/macosx/native/libosxui/ScreenMenu.m @@ -105,13 +105,13 @@ } JNIEnv *env = [ThreadUtilities getJNIEnv]; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); //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) CHECK_EXCEPTION(); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } @@ -125,13 +125,13 @@ } JNIEnv *env = [ThreadUtilities getJNIEnv]; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); //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) CHECK_EXCEPTION(); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } @@ -145,7 +145,7 @@ } JNIEnv *env = [ThreadUtilities getJNIEnv]; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); // 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"); @@ -153,7 +153,7 @@ NSMinY(rect), NSMinX(rect), NSMaxY(rect), NSMaxX(rect)); // AWT_THREADING Safe (AWTRunLoopMode) CHECK_EXCEPTION(); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } @@ -191,13 +191,13 @@ // Call the mouse event handler, which will generate Java mouse events. JNIEnv *env = [ThreadUtilities getJNIEnv]; -JNF_COCOA_ENTER(env); +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, javaKind, javaX, javaY, javaModifiers, javaWhen); // AWT_THREADING Safe (AWTRunLoopMode) CHECK_EXCEPTION(); -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } @end @@ -213,7 +213,7 @@ { NativeToJavaDelegate *delegate = nil; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); JNFJObjectWrapper *wrapper = [JNFJObjectWrapper wrapperWithJObject:listener withEnv:env]; NSMenu *menu = jlong_to_ptr(nativeMenu); @@ -229,7 +229,7 @@ } }]; -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); return ptr_to_jlong(delegate); } @@ -244,7 +244,7 @@ { if (fModelPtr == 0L) return; -JNF_COCOA_ENTER(env); +JNI_COCOA_ENTER(env); NativeToJavaDelegate *delegate = (NativeToJavaDelegate *)jlong_to_ptr(fModelPtr); @@ -258,5 +258,5 @@ CFRelease(delegate); // GC -JNF_COCOA_EXIT(env); +JNI_COCOA_EXIT(env); } # HG changeset patch # User vkempik # Date 1617884483 0 # Thu Apr 08 12:21:23 2021 +0000 # Node ID e2cecb45b79f972594a704fcdaa3c149a1736913 # Parent 3f37447f4a66f530a1662be4e41c802ba6b53563 8259869: [macOS] Remove desktop module dependencies on JNF Reference APIs diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m @@ -142,7 +142,7 @@ { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; - JNFDeleteGlobalRef(env, fInputMethodLOCKABLE); + (*env)->DeleteGlobalRef(env, fInputMethodLOCKABLE); fInputMethodLOCKABLE = NULL; } @@ -1384,14 +1384,10 @@ // 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; @@ -1433,6 +1429,7 @@ 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 --- 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; @@ -52,7 +51,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; @@ -63,7 +62,7 @@ @property (nonatomic) NSRect standardFrame; @property (nonatomic) BOOL isMinimizing; -- (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 --- 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 @@ 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(); @@ -280,7 +280,7 @@ } } -- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)platformWindow +- (id) initWithPlatformWindow:(jobject)platformWindow ownerWindow:owner styleBits:(jint)bits frameRect:(NSRect)rect @@ -470,7 +470,7 @@ 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; @@ -482,7 +482,7 @@ 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); @@ -499,7 +499,7 @@ 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); @@ -520,7 +520,7 @@ [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) @@ -591,7 +591,7 @@ [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); @@ -620,7 +620,7 @@ // 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 } @@ -698,7 +698,7 @@ [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"); @@ -714,7 +714,7 @@ 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"); @@ -745,9 +745,9 @@ - (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); @@ -769,7 +769,7 @@ } 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"); @@ -879,7 +879,7 @@ 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); @@ -897,7 +897,7 @@ "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) { @@ -914,7 +914,7 @@ 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(); @@ -927,7 +927,7 @@ 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(); @@ -946,7 +946,7 @@ 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(); @@ -957,7 +957,7 @@ - (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"); @@ -976,7 +976,7 @@ // 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"); @@ -995,7 +995,7 @@ // 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(); @@ -1078,7 +1078,7 @@ 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]; @@ -1519,7 +1519,7 @@ [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 --- 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 @@ @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 @@ 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 --- 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 @@ // 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 --- 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 --- 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 @@ 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 @@ if (sDraggingFormats != NULL) { JNIEnv *env = [ThreadUtilities getJNIEnv]; - JNFDeleteGlobalRef(env, sDraggingFormats); + (*env)->DeleteGlobalRef(env, sDraggingFormats); sDraggingFormats = NULL; } @@ -165,15 +165,15 @@ // 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 @@ 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 @@ 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 @@ // 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 @@ 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 --- 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 @@ (*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 --- 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 @@ { 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 @@ -(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 --- 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 --- 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 @@ [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 @@ { 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 @@ [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 --- 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 @@ - (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 --- 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 @@ 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 --- 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 @@ -(void) dealloc { JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; - JNFDeleteGlobalRef(env, peer); + (*env)->DeleteGlobalRef(env, peer); [[NSStatusBar systemStatusBar] removeStatusItem: theItem]; @@ -335,7 +335,7 @@ 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 --- 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 @@ qsdo->graphicsStateInfo.batchedLines = NULL; } - JNFDeleteGlobalRef(env, qsdo->javaGraphicsStatesObjects); + (*env)->DeleteGlobalRef(env, qsdo->javaGraphicsStatesObjects); if (qsdo->cgRef != NULL) { @@ -1484,12 +1484,12 @@ } 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 @@ // 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 @@ 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 --- 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 @@ { 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 @@ { 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 @@ 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 @@ (*env)->DeleteLocalRef(env, jstr); } (*env)->DeleteLocalRef(env, fCompLocal); + (*env)->DeleteLocalRef(env, fAccessibleActionLocal); return str; } @@ -103,9 +112,11 @@ { 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 @@ { 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 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m @@ -1799,7 +1799,8 @@ 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; } @@ -1812,7 +1813,7 @@ JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; if (fTabGroupAxContext != NULL) { - JNFDeleteWeakGlobalRef(env, fTabGroupAxContext); + (*env)->DeleteWeakGlobalRef(env, fTabGroupAxContext); fTabGroupAxContext = NULL; } @@ -1845,7 +1846,8 @@ 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 --- 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 @@ 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 @@ { 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 @@ 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 @@ //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 @@ // 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 @@ [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 --- 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; @@ -45,7 +45,7 @@ #endif /* REMOTELAYER */ } -@property (nonatomic, retain) JNFWeakJObjectWrapper *javaLayer; +@property (nonatomic) jobject javaLayer; @property (readwrite, assign) GLuint textureID; @property (readwrite, assign) GLenum target; @property (readwrite, assign) float textureWidth; @@ -57,7 +57,7 @@ @property (nonatomic, retain) NSObject *jrsRemoteLayer; #endif -- (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 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.m @@ -47,7 +47,7 @@ @synthesize jrsRemoteLayer; #endif -- (id) initWithJavaLayer:(JNFWeakJObjectWrapper *)layer; +- (id) initWithJavaLayer:(jobject)layer; { AWT_ASSERT_APPKIT_THREAD; // Initialize ourselves @@ -84,6 +84,8 @@ } - (void) dealloc { + JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; + (*env)->DeleteWeakGlobalRef(env, self.javaLayer); self.javaLayer = nil; [super dealloc]; } @@ -138,7 +140,7 @@ 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; } @@ -177,7 +179,7 @@ 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 --- a/src/java.desktop/macosx/native/libosxui/ScreenMenu.m +++ b/src/java.desktop/macosx/native/libosxui/ScreenMenu.m @@ -65,13 +65,13 @@ { @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 @@ @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 @@ - (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 @@ //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)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 @@ //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)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 @@ // 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 @@ 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 @@ 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 @@ [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); # HG changeset patch # User vkempik # Date 1618483337 -10800 # Thu Apr 15 13:42:17 2021 +0300 # Node ID c34af45c562e97cf261bb452177693724d252bd1 # Parent e2cecb45b79f972594a704fcdaa3c149a1736913 8260616: Removing remaining JNF dependencies in the java.desktop module 8259729: Missed JNFInstanceOf -> IsInstanceOf conversion diff --git a/make/lib/Awt2dLibraries.gmk b/make/lib/Awt2dLibraries.gmk --- a/make/lib/Awt2dLibraries.gmk +++ b/make/lib/Awt2dLibraries.gmk @@ -244,7 +244,6 @@ LIBS_macosx := -lmlib_image \ -framework Cocoa \ -framework OpenGL \ - -framework JavaNativeFoundation \ -framework JavaRuntimeSupport \ -framework ApplicationServices \ -framework AudioToolbox, \ @@ -902,8 +901,7 @@ $(LIBM) -lpthread -liconv -losxapp \ -framework ApplicationServices \ -framework Foundation \ - -framework Cocoa \ - -framework JavaNativeFoundation + -framework Cocoa else ifeq ($(OPENJDK_TARGET_OS), windows) LIBSPLASHSCREEN_LIBS += kernel32.lib user32.lib gdi32.lib delayimp.lib $(WIN_JAVA_LIB) jvm.lib else @@ -999,7 +997,6 @@ -framework Cocoa \ -framework Security \ -framework ExceptionHandling \ - -framework JavaNativeFoundation \ -framework JavaRuntimeSupport \ -framework OpenGL \ -framework QuartzCore -ljava, \ @@ -1037,7 +1034,6 @@ -framework Cocoa \ -framework Carbon \ -framework ApplicationServices \ - -framework JavaNativeFoundation \ -framework JavaRuntimeSupport \ -ljava -ljvm, \ )) diff --git a/make/lib/Lib-java.desktop.gmk b/make/lib/Lib-java.desktop.gmk --- a/make/lib/Lib-java.desktop.gmk +++ b/make/lib/Lib-java.desktop.gmk @@ -104,7 +104,6 @@ -framework Cocoa \ -framework Security \ -framework ExceptionHandling \ - -framework JavaNativeFoundation \ -framework JavaRuntimeSupport \ -framework OpenGL \ -framework IOSurface \ @@ -130,7 +129,6 @@ -losxapp \ -framework Cocoa \ -framework ApplicationServices \ - -framework JavaNativeFoundation \ -framework JavaRuntimeSupport \ -framework SystemConfiguration \ $(JDKLIB_LIBS), \ diff --git a/make/test/JtregNativeJdk.gmk b/make/test/JtregNativeJdk.gmk --- a/make/test/JtregNativeJdk.gmk +++ b/make/test/JtregNativeJdk.gmk @@ -77,7 +77,7 @@ ifeq ($(OPENJDK_TARGET_OS), macosx) BUILD_JDK_JTREG_LIBRARIES_LIBS_libTestMainKeyWindow := \ - -framework Cocoa -framework JavaNativeFoundation + -framework Cocoa BUILD_JDK_JTREG_LIBRARIES_LIBS_libTestDynamicStore := \ -framework Cocoa -framework SystemConfiguration else diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTEvent.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTEvent.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTEvent.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTEvent.m @@ -29,7 +29,6 @@ #import "JNIUtilities.h" -#import #import #import diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTSurfaceLayers.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTSurfaceLayers.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTSurfaceLayers.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTSurfaceLayers.m @@ -28,7 +28,6 @@ #import "LWCToolkit.h" #import "JNIUtilities.h" -#import #import @implementation AWTSurfaceLayers diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m @@ -36,7 +36,6 @@ #import "JNIUtilities.h" #import -#import // keyboard layout static NSString *kbdLayout; @@ -160,7 +159,7 @@ [AWTToolkit eventCountPlusPlus]; - [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() { + [ThreadUtilities performOnMainThreadWaiting:NO block:^() { [[self window] makeFirstResponder: self]; }]; if ([self window] != NULL) { @@ -486,8 +485,8 @@ jstring characters = NULL; jstring charactersIgnoringModifiers = NULL; if ([event type] != NSFlagsChanged) { - characters = JNFNSToJavaString(env, [event characters]); - charactersIgnoringModifiers = JNFNSToJavaString(env, [event charactersIgnoringModifiers]); + characters = NSStringToJavaString(env, [event characters]); + charactersIgnoringModifiers = NSStringToJavaString(env, [event charactersIgnoringModifiers]); } DECLARE_CLASS(jc_NSEvent, "sun/lwawt/macosx/NSEvent"); @@ -600,10 +599,7 @@ DECLARE_FIELD_RETURN(jf_Peer, jc_CPlatformView, "peer", "Lsun/lwawt/LWWindowPeer;", NULL); if ((env == NULL) || (m_cPlatformView == NULL)) { NSLog(@"Apple AWT : Error AWTView:awtComponent given bad parameters."); - if (env != NULL) - { - JNFDumpJavaStack(env); - } + NSLog(@"%@",[NSThread callStackSymbols]); return NULL; } @@ -617,7 +613,7 @@ DECLARE_FIELD_RETURN(jf_Target, jc_LWWindowPeer, "target", "Ljava/awt/Component;", NULL); if (peer == NULL) { NSLog(@"Apple AWT : Error AWTView:awtComponent got null peer from CPlatformView"); - JNFDumpJavaStack(env); + NSLog(@"%@",[NSThread callStackSymbols]); return NULL; } jobject comp = (*env)->GetObjectField(env, peer, jf_Target); @@ -1014,8 +1010,8 @@ } DECLARE_METHOD(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V"); - jstring insertedText = JNFNSToJavaString(env, useString); - (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); // AWT_THREADING Safe (AWTRunLoopMode) + jstring insertedText = NSStringToJavaString(env, useString); + (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, insertedText); @@ -1080,8 +1076,8 @@ // NSInputContext already did the analysis of the TSM event and created attributes indicating // the underlining and color that should be done to the string. We need to look at the underline // style and color to determine what kind of Java hilighting needs to be done. - jstring inProcessText = JNFNSToJavaString(env, incomingString); - (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_startIMUpdate, inProcessText); // AWT_THREADING Safe (AWTRunLoopMode) + jstring inProcessText = NSStringToJavaString(env, incomingString); + (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_startIMUpdate, inProcessText); CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, inProcessText); @@ -1106,7 +1102,7 @@ isGray = !([underlineColorObj isEqual:[NSColor blackColor]]); (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_addAttribute, isThickUnderline, - isGray, effectiveRange.location, effectiveRange.length); // AWT_THREADING Safe (AWTRunLoopMode) + isGray, effectiveRange.location, effectiveRange.length); CHECK_EXCEPTION(); } } @@ -1121,7 +1117,7 @@ } (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_dispatchText, - selectionRange.location, selectionRange.length, JNI_FALSE); // AWT_THREADING Safe (AWTRunLoopMode) + selectionRange.location, selectionRange.length, JNI_FALSE); CHECK_EXCEPTION(); // If the marked text is being cleared (zero-length string) don't handle the key event. if ([incomingString length] == 0) { @@ -1143,7 +1139,7 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; GET_CIM_CLASS(); DECLARE_METHOD(jm_unmarkText, jc_CInputMethod, "unmarkText", "()V"); - (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText); // AWT_THREADING Safe (AWTRunLoopMode) + (*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText); CHECK_EXCEPTION(); } @@ -1196,10 +1192,10 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; DECLARE_METHOD_RETURN(jm_substringFromRange, jc_CInputMethod, "attributedSubstringFromRange", "(II)Ljava/lang/String;", nil); - jobject theString = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_substringFromRange, theRange.location, theRange.length); // AWT_THREADING Safe (AWTRunLoopMode) + jobject theString = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_substringFromRange, theRange.location, theRange.length); CHECK_EXCEPTION_NULL_RETURN(theString, nil); - id result = [[[NSAttributedString alloc] initWithString:JNFJavaToNSString(env, theString)] autorelease]; + id result = [[[NSAttributedString alloc] initWithString:JavaStringToNSString(env, theString)] autorelease]; #ifdef IM_DEBUG NSLog(@"attributedSubstringFromRange returning \"%@\"", result); #endif // IM_DEBUG @@ -1230,7 +1226,7 @@ GET_CIM_CLASS_RETURN(range); DECLARE_METHOD_RETURN(jm_markedRange, jc_CInputMethod, "markedRange", "()[I", range); - array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_markedRange); // AWT_THREADING Safe (AWTRunLoopMode) + array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_markedRange); CHECK_EXCEPTION(); if (array) { @@ -1271,7 +1267,7 @@ fprintf(stderr, "AWTView InputMethod Selector Called : [selectedRange]\n"); #endif // IM_DEBUG - array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_selectedRange); // AWT_THREADING Safe (AWTRunLoopMode) + array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_selectedRange); CHECK_EXCEPTION(); if (array) { _array = (*env)->GetIntArrayElements(env, array, &isCopy); @@ -1310,7 +1306,7 @@ #endif // IM_DEBUG array = (*env)->CallObjectMethod(env, fInputMethodLOCKABLE, jm_firstRectForCharacterRange, - theRange.location); // AWT_THREADING Safe (AWTRunLoopMode) + theRange.location); CHECK_EXCEPTION(); _array = (*env)->GetIntArrayElements(env, array, &isCopy); @@ -1351,7 +1347,7 @@ #endif // IM_DEBUG jint index = (*env)->CallIntMethod(env, fInputMethodLOCKABLE, jm_characterIndexForPoint, - (jint)flippedLocation.x, (jint)flippedLocation.y); // AWT_THREADING Safe (AWTRunLoopMode) + (jint)flippedLocation.x, (jint)flippedLocation.y); CHECK_EXCEPTION(); #ifdef IM_DEBUG diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m @@ -24,7 +24,6 @@ */ #import -#import #import "sun_lwawt_macosx_CPlatformWindow.h" #import "com_apple_eawt_event_GestureHandler.h" @@ -1419,7 +1418,7 @@ NSWindow *nsWindow = OBJC(windowPtr); [nsWindow performSelectorOnMainThread:@selector(setTitle:) - withObject:JNFJavaToNSString(env, jtitle) + withObject:JavaStringToNSString(env, jtitle) waitUntilDone:NO]; JNI_COCOA_EXIT(env); @@ -1495,7 +1494,7 @@ JNI_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(windowPtr); - NSURL *url = (filename == NULL) ? nil : [NSURL fileURLWithPath:JNFNormalizedNSStringForPath(env, filename)]; + NSURL *url = (filename == NULL) ? nil : [NSURL fileURLWithPath:NormalizedPathNSStringFromJavaString(env, filename)]; [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [nsWindow setRepresentedURL:url]; }]; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/ApplicationDelegate.m @@ -32,8 +32,6 @@ #import "com_apple_eawt__AppMenuBarHandler.h" #import "com_apple_eawt__AppMiscHandlers.h" -#import - #import "CPopupMenu.h" #import "ThreadUtilities.h" #import "NSApplicationAWT.h" @@ -290,10 +288,10 @@ //fprintf(stderr,"jm_handleOpenURL\n"); JNIEnv *env = [ThreadUtilities getJNIEnv]; - jstring jURL = JNFNSToJavaString(env, url); + jstring jURL = NSStringToJavaString(env, url); GET_APPEVENTHANDLER_CLASS(); DECLARE_STATIC_METHOD(jm_handleOpenURI, sjc_AppEventHandler, "handleOpenURI", "(Ljava/lang/String;)V"); - (*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handleOpenURI, jURL); // AWT_THREADING Safe (event) + (*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handleOpenURI, jURL); CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jURL); @@ -312,11 +310,11 @@ DECLARE_METHOD_RETURN(jm_ArrayList_ctor, sjc_ArrayList, "", "(I)V", NULL); DECLARE_METHOD_RETURN(jm_ArrayList_add, sjc_ArrayList, "add", "(Ljava/lang/Object;)Z", NULL); - jobject jFileNamesArray = (*env)->NewObject(env, sjc_ArrayList, jm_ArrayList_ctor, (jint)[filenames count]); // AWT_THREADING Safe (known object) + jobject jFileNamesArray = (*env)->NewObject(env, sjc_ArrayList, jm_ArrayList_ctor, (jint)[filenames count]); CHECK_EXCEPTION_NULL_RETURN(jFileNamesArray, NULL); for (NSString *filename in filenames) { - jstring jFileName = JNFNormalizedJavaStringForPath(env, filename); + jstring jFileName = NormalizedPathJavaStringFromNSString(env, filename); (*env)->CallVoidMethod(env, jFileNamesArray, jm_ArrayList_add, jFileName); CHECK_EXCEPTION(); } @@ -338,7 +336,7 @@ // if these files were opened from a Spotlight query, try to get the search text from the current AppleEvent NSAppleEventDescriptor *currentEvent = [[NSAppleEventManager sharedAppleEventManager] currentAppleEvent]; NSString *searchString = [[currentEvent paramDescriptorForKeyword:keyAESearchText] stringValue]; - jstring jSearchString = JNFNSToJavaString(env, searchString); + jstring jSearchString = NSStringToJavaString(env, searchString); // convert the file names array jobject jFileNamesArray = [self _createFilePathArrayFrom:fileNames withEnv:env]; @@ -365,7 +363,7 @@ GET_APPEVENTHANDLER_CLASS_RETURN(NSPrintingCancelled); DECLARE_STATIC_METHOD_RETURN(jm_handlePrintFile, sjc_AppEventHandler, "handlePrintFiles", "(Ljava/util/List;)V", NSPrintingCancelled); - (*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handlePrintFile, jFileNamesArray); // AWT_THREADING Safe (event) + (*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handlePrintFile, jFileNamesArray); CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jFileNamesArray); @@ -380,7 +378,7 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; GET_APPEVENTHANDLER_CLASS(); DECLARE_STATIC_METHOD(jm_handleNativeNotification, sjc_AppEventHandler, "handleNativeNotification", "(I)V"); - (*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handleNativeNotification, notificationType); // AWT_THREADING Safe (event) + (*env)->CallStaticVoidMethod(env, sjc_AppEventHandler, jm_handleNativeNotification, notificationType); CHECK_EXCEPTION(); } @@ -624,7 +622,7 @@ [ThreadUtilities performOnMainThread:@selector(_registerForNotification:) on:[ApplicationDelegate class] withObject:[NSNumber numberWithInt:notificationType] - waitUntilDone:NO]; // AWT_THREADING Safe (non-blocking) + waitUntilDone:NO]; JNI_COCOA_EXIT(env); } @@ -714,7 +712,7 @@ { JNI_COCOA_ENTER(env); - NSString *badgeString = JNFJavaToNSString(env, badge); + NSString *badgeString = JavaStringToNSString(env, badge); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ NSDockTile *dockTile = [NSApp dockTile]; [dockTile setBadgeLabel:badgeString]; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m @@ -27,7 +27,6 @@ #import "ThreadUtilities.h" #import "JNIUtilities.h" #import -#import @interface CClipboard : NSObject { } @property NSInteger changeCount; @@ -99,7 +98,7 @@ DECLARE_METHOD(jm_lostOwnership, jc_CClipboard, "notifyLostOwnership", "()V"); @synchronized(self) { if (self.clipboardOwner) { - (*env)->CallVoidMethod(env, self.clipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event) + (*env)->CallVoidMethod(env, self.clipboardOwner, jm_lostOwnership); CHECK_EXCEPTION(); (*env)->DeleteGlobalRef(env, self.clipboardOwner); self.clipboardOwner = NULL; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CCursorManager.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CCursorManager.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CCursorManager.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CCursorManager.m @@ -26,7 +26,6 @@ #include "sun_lwawt_macosx_CCursorManager.h" #include -#include #include "GeomUtilities.h" #include "ThreadUtilities.h" @@ -75,7 +74,7 @@ { JNI_COCOA_ENTER(env); - NSString *cursorName = JNFJavaToNSString(env, name); + NSString *cursorName = JavaStringToNSString(env, name); SEL cursorSelector = (type == sun_lwawt_macosx_CCursorManager_NAMED_CURSOR) ? lookupCursorSelectorForName(cursorName) : lookupCursorSelectorForType(type); if (cursorSelector == nil) { NSString *reason = [NSString stringWithFormat:@"unimplemented built-in cursor type: %d / %@", type, cursorName]; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m @@ -28,9 +28,6 @@ #import "JNIUtilities.h" -#import - - // ***** NOTE ***** This dictionary corresponds to the static array predefinedClipboardNames // in CDataTransferer.java. NSMutableDictionary *sStandardMappings = nil; @@ -110,7 +107,7 @@ { jlong returnValue = -1; JNI_COCOA_ENTER(env); - returnValue = registerFormatWithPasteboard(JNFJavaToNSString(env, newformat)); + returnValue = registerFormatWithPasteboard(JavaStringToNSString(env, newformat)); JNI_COCOA_EXIT(env); return returnValue; } @@ -125,7 +122,7 @@ { jstring returnValue = NULL; JNI_COCOA_ENTER(env); - returnValue = JNFNSToJavaString(env, formatForIndex(index)); + returnValue = NSStringToJavaString(env, formatForIndex(index)); JNI_COCOA_EXIT(env); return returnValue; } @@ -138,7 +135,7 @@ // Get the java.lang.String class object: jclass stringClazz = (*env)->FindClass(env, "java/lang/String"); CHECK_NULL_RETURN(stringClazz, nil); - jobject jfilenameArray = (*env)->NewObjectArray(env, filenameCount, stringClazz, NULL); // AWT_THREADING Safe (known object) + jobject jfilenameArray = (*env)->NewObjectArray(env, filenameCount, stringClazz, NULL); if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDesktopPeer.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDesktopPeer.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDesktopPeer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDesktopPeer.m @@ -27,7 +27,6 @@ #import "JNIUtilities.h" #import #import -#import /* * Class: sun_lwawt_macosx_CDesktopPeer @@ -43,7 +42,7 @@ // I would love to use NSWorkspace here, but it's not thread safe. Why? I don't know. // So we use LaunchServices directly. - NSURL *url = [NSURL URLWithString:JNFJavaToNSString(env, uri)]; + NSURL *url = [NSURL URLWithString:JavaStringToNSString(env, uri)]; LSLaunchFlags flags = kLSLaunchDefaults; @@ -68,7 +67,7 @@ // I would love to use NSWorkspace here, but it's not thread safe. Why? I don't know. // So we use LaunchServices directly. - NSString *path = JNFNormalizedNSStringForPath(env, jpath); + NSString *path = NormalizedPathNSStringFromJavaString(env, jpath); NSURL *url = [NSURL fileURLWithPath:(NSString *)path]; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m @@ -28,7 +28,6 @@ #import "java_awt_dnd_DnDConstants.h" #import -#import #import "AWTEvent.h" #import "AWTView.h" @@ -572,7 +571,7 @@ GET_DSCP_CLASS(); DECLARE_METHOD(dragDropFinishedMethod, CDragSourceContextPeerClass, "dragDropFinished", "(ZIII)V"); DLog3(@" -> posting dragDropFinished, point %f, %f", point.x, point.y); - (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragDropFinishedMethod, success, dragOp, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragDropFinishedMethod, success, dragOp, (jint) point.x, (jint) point.y); CHECK_EXCEPTION(); DECLARE_METHOD(resetHoveringMethod, CDragSourceContextPeerClass, "resetHovering", "()V"); (*env)->CallVoidMethod(env, fDragSourceContextPeer, resetHoveringMethod); // Hust reset static variable @@ -594,7 +593,7 @@ { AWT_ASSERT_NOT_APPKIT_THREAD; - [self performSelectorOnMainThread:@selector(doDrag) withObject:nil waitUntilDone:YES]; // AWT_THREADING Safe (called from unique asynchronous thread) + [self performSelectorOnMainThread:@selector(doDrag) withObject:nil waitUntilDone:YES]; } /******************************** BEGIN NSDraggingSource Interface ********************************/ @@ -613,7 +612,7 @@ GET_DSCP_CLASS(); DECLARE_METHOD(operationChangedMethod, CDragSourceContextPeerClass, "operationChanged", "(IIII)V"); - (*env)->CallVoidMethod(env, fDragSourceContextPeer, operationChangedMethod, targetActions, modifiedModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + (*env)->CallVoidMethod(env, fDragSourceContextPeer, operationChangedMethod, targetActions, modifiedModifiers, (jint) point.x, (jint) point.y); CHECK_EXCEPTION(); } @@ -688,11 +687,11 @@ DLog3(@" -> posting dragMotion, point %f, %f", point.x, point.y); GET_DSCP_CLASS(); DECLARE_METHOD(dragMotionMethod, CDragSourceContextPeerClass, "dragMotion", "(IIII)V"); - (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMotionMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMotionMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); CHECK_EXCEPTION(); DLog3(@" -> posting dragMouseMoved, point %f, %f", point.x, point.y); DECLARE_METHOD(dragMouseMovedMethod, CDragSourceContextPeerClass, "dragMouseMoved", "(IIII)V"); - (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMouseMovedMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragMouseMovedMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); CHECK_EXCEPTION(); } JNI_COCOA_EXIT(env); @@ -719,7 +718,7 @@ DLog3(@" -> posting dragEnter, point %f, %f", point.x, point.y); GET_DSCP_CLASS(); DECLARE_METHOD(dragEnterMethod, CDragSourceContextPeerClass, "dragEnter", "(IIII)V"); - (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragEnterMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragEnterMethod, targetActions, (jint) fModifiers, (jint) point.x, (jint) point.y); CHECK_EXCEPTION(); } @@ -731,7 +730,7 @@ DLog3(@" -> posting dragExit, point %f, %f", point.x, point.y); GET_DSCP_CLASS(); DECLARE_METHOD(dragExitMethod, CDragSourceContextPeerClass, "dragExit", "(II)V"); - (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragExitMethod, (jint) point.x, (jint) point.y); // AWT_THREADING Safe (event) + (*env)->CallVoidMethod(env, fDragSourceContextPeer, dragExitMethod, (jint) point.x, (jint) point.y); CHECK_EXCEPTION(); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m @@ -26,7 +26,6 @@ #import "sun_lwawt_macosx_CDragSourceContextPeer.h" #import "JNIUtilities.h" -#import #import "CDragSource.h" #import "ThreadUtilities.h" diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m @@ -31,7 +31,6 @@ #import "sun_lwawt_macosx_CDropTarget.h" #import "java_awt_dnd_DnDConstants.h" -#import #import #include diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m @@ -25,8 +25,6 @@ #import "sun_lwawt_macosx_CDropTargetContextPeer.h" -#import - #import "CDataTransferer.h" #import "CDropTarget.h" #import "DnDUtilities.h" diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CFRetainedResource.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CFRetainedResource.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CFRetainedResource.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CFRetainedResource.m @@ -24,9 +24,9 @@ */ #import "JNIUtilities.h" +#import "ThreadUtilities.h" #import -#import #import "sun_lwawt_macosx_CFRetainedResource.h" @@ -49,7 +49,7 @@ }]; } else { // could happen if we are embedded inside SWT/FX application, - [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() { + [ThreadUtilities performOnMainThreadWaiting:NO block:^() { CFRelease(jlong_to_ptr(ptr)); }]; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.h b/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.h --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.h @@ -24,7 +24,6 @@ */ #import -#import @interface CFileDialog : NSObject { // Should we query back to Java for a file filter? diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m @@ -25,11 +25,10 @@ #import #import -#import -#import "CFileDialog.h" #import "ThreadUtilities.h" #import "JNIUtilities.h" +#import "CFileDialog.h" #import "java_awt_FileDialog.h" #import "sun_lwawt_macosx_CFileDialog.h" @@ -143,11 +142,11 @@ - (BOOL) askFilenameFilter:(NSString *)filename { JNIEnv *env = [ThreadUtilities getJNIEnv]; - jstring jString = JNFNormalizedJavaStringForPath(env, filename); + jstring jString = NormalizedPathJavaStringFromNSString(env, filename); DECLARE_CLASS_RETURN(jc_CFileDialog, "sun/lwawt/macosx/CFileDialog", NO); DECLARE_METHOD_RETURN(jm_queryFF, jc_CFileDialog, "queryFilenameFilter", "(Ljava/lang/String;)Z", NO); - BOOL returnValue = (*env)->CallBooleanMethod(env, fFileDialog, jm_queryFF, jString); // AWT_THREADING Safe (AWTRunLoopMode) + BOOL returnValue = (*env)->CallBooleanMethod(env, fFileDialog, jm_queryFF, jString); CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jString); @@ -199,7 +198,7 @@ jobjectArray returnValue = NULL; JNI_COCOA_ENTER(env); - NSString *dialogTitle = JNFJavaToNSString(env, title); + NSString *dialogTitle = JavaStringToNSString(env, title); if ([dialogTitle length] == 0) { dialogTitle = @" "; } @@ -207,15 +206,15 @@ CFileDialog *dialogDelegate = [[CFileDialog alloc] initWithFilter:hasFilter fileDialog:peer title:dialogTitle - directory:JNFJavaToNSString(env, directory) - file:JNFJavaToNSString(env, file) + directory:JavaStringToNSString(env, directory) + file:JavaStringToNSString(env, file) mode:mode multipleMode:multipleMode shouldNavigate:navigateApps canChooseDirectories:chooseDirectories withEnv:env]; - [JNFRunLoop performOnMainThread:@selector(safeSaveOrLoad) + [ThreadUtilities performOnMainThread:@selector(safeSaveOrLoad) on:dialogDelegate withObject:nil waitUntilDone:YES]; @@ -228,7 +227,7 @@ returnValue = (*env)->NewObjectArray(env, count, jc_String, NULL); [urls enumerateObjectsUsingBlock:^(id url, NSUInteger index, BOOL *stop) { - jstring filename = JNFNormalizedJavaStringForPath(env, [url path]); + jstring filename = NormalizedPathJavaStringFromNSString(env, [url path]); (*env)->SetObjectArrayElement(env, returnValue, index, filename); (*env)->DeleteLocalRef(env, filename); }]; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m @@ -28,8 +28,6 @@ #include "GeomUtilities.h" #include "JNIUtilities.h" -#import - /** * Some default values for invalid CoreGraphics display ID. */ diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m @@ -28,8 +28,6 @@ #import "JNIUtilities.h" #import "ThreadUtilities.h" -#import - #define MAX_DISPLAYS 64 /* @@ -114,19 +112,18 @@ [ThreadUtilities performOnMainThreadWaiting:NO block:^() { - JNFPerformEnvBlock(JNFThreadDetachImmediately, ^(JNIEnv *env) { - jobject cgeRef = (jobject)userInfo; + JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; + jobject cgeRef = (jobject)userInfo; - 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, - jc_CGraphicsEnvironment, "_displayReconfiguration","(IZ)V"); - (*env)->CallVoidMethod(env, graphicsEnv, jm_displayReconfiguration, - (jint) display, (jboolean) flags & kCGDisplayRemoveFlag); - (*env)->DeleteLocalRef(env, graphicsEnv); - CHECK_EXCEPTION(); - }); + 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, + jc_CGraphicsEnvironment, "_displayReconfiguration","(IZ)V"); + (*env)->CallVoidMethod(env, graphicsEnv, jm_displayReconfiguration, + (jint) display, (jboolean) flags & kCGDisplayRemoveFlag); + (*env)->DeleteLocalRef(env, graphicsEnv); + CHECK_EXCEPTION(); }]; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m @@ -25,7 +25,6 @@ #import "jni_util.h" #import -#import #import "GeomUtilities.h" #import "ThreadUtilities.h" @@ -204,7 +203,7 @@ JNI_COCOA_ENTER(env); - NSString *path = JNFNormalizedNSStringForPath(env, file); + NSString *path = NormalizedPathNSStringFromJavaString(env, file); image = [[NSImage alloc] initByReferencingFile:path]; JNI_COCOA_EXIT(env); @@ -224,7 +223,7 @@ JNI_COCOA_ENTER(env); - NSString *path = JNFNormalizedNSStringForPath(env, file); + NSString *path = NormalizedPathNSStringFromJavaString(env, file); [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ image = [[[NSWorkspace sharedWorkspace] iconForFile:path] retain]; [image setScalesWhenResized:TRUE]; @@ -247,7 +246,7 @@ JNI_COCOA_ENTER(env); - image = [[NSImage imageNamed:JNFJavaToNSString(env, name)] retain]; + image = [[NSImage imageNamed:JavaStringToNSString(env, name)] retain]; 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 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m @@ -32,7 +32,6 @@ #import "AWTView.h" #import "JNIUtilities.h" -#import #import #define JAVA_LIST @"JAVA_LIST" @@ -160,7 +159,7 @@ }]; if (keyboardInfo == nil) return NULL; - returnValue = JNFNSToJavaString(env, keyboardInfo); + returnValue = NSStringToJavaString(env, keyboardInfo); [keyboardInfo release]; JNI_COCOA_EXIT(env); @@ -259,7 +258,7 @@ (JNIEnv *env, jobject this, jstring locale, jboolean isActivating) { JNI_COCOA_ENTER(env); - NSString *localeStr = JNFJavaToNSString(env, locale); + NSString *localeStr = JavaStringToNSString(env, locale); [localeStr retain]; [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenu.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenu.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenu.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenu.m @@ -23,7 +23,6 @@ * questions. */ -#import #import @@ -220,7 +219,7 @@ { JNI_COCOA_ENTER(env); // Set the menu's title. - [((CMenu *)jlong_to_ptr(menuObject)) setJavaMenuTitle:JNFJavaToNSString(env, label)]; + [((CMenu *)jlong_to_ptr(menuObject)) setJavaMenuTitle:JavaStringToNSString(env, label)]; JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuBar.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuBar.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuBar.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuBar.m @@ -26,7 +26,6 @@ #import "JNIUtilities.h" #import -#import #import diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuComponent.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuComponent.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuComponent.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuComponent.m @@ -24,7 +24,6 @@ */ #import "CMenuComponent.h" -#import #import "ThreadUtilities.h" diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuItem.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuItem.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuItem.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuItem.m @@ -23,7 +23,6 @@ * questions. */ -#import #include #import "CMenuItem.h" #import "CMenu.h" @@ -333,7 +332,7 @@ jchar shortcutKey, jint shortcutKeyCode, jint mods) { JNI_COCOA_ENTER(env); - NSString *theLabel = JNFJavaToNSString(env, label); + NSString *theLabel = JavaStringToNSString(env, label); NSString *theKeyEquivalent = nil; unichar macKey = shortcutKey; @@ -362,7 +361,7 @@ (JNIEnv *env, jobject peer, jlong menuItemObj, jstring tooltip) { JNI_COCOA_ENTER(env); - NSString *theTooltip = JNFJavaToNSString(env, tooltip); + NSString *theTooltip = JavaStringToNSString(env, tooltip); [((CMenuItem *)jlong_to_ptr(menuItemObj)) setJavaToolTipText:theTooltip]; JNI_COCOA_EXIT(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPopupMenu.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPopupMenu.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPopupMenu.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPopupMenu.m @@ -24,7 +24,6 @@ */ #import -#import #import "AWTWindow.h" #import "AWTView.h" diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m @@ -30,7 +30,6 @@ #import "sun_lwawt_macosx_CPrinterPageDialog.h" #import -#import #import "PrinterView.h" #import "PrintModel.h" @@ -87,7 +86,7 @@ NSPrintInfo* defaultPrintInfo = [[NSPrintInfo sharedPrintInfo] copy]; if (printer != NULL) { - NSPrinter* nsPrinter = [NSPrinter printerWithName:JNFJavaToNSString(env, printer)]; + NSPrinter* nsPrinter = [NSPrinter printerWithName:JavaStringToNSString(env, printer)]; if (nsPrinter != nil) { [defaultPrintInfo setPrinter:nsPrinter]; @@ -345,7 +344,7 @@ jobject printerNameObj = (*env)->CallObjectMethod(env, srcPrintJob, jm_getPrinterName); CHECK_EXCEPTION(); if (printerNameObj == NULL) return; - NSString *printerName = JNFJavaToNSString(env, printerNameObj); + NSString *printerName = JavaStringToNSString(env, printerNameObj); if (printerName == nil) return; NSPrinter *printer = [NSPrinter printerWithName:printerName]; if (printer == nil) return; @@ -362,7 +361,7 @@ // get the selected printer's name, and set the appropriate PrintService on the Java side NSString *name = [[src printer] name]; - jstring printerName = JNFNSToJavaString(env, name); + jstring printerName = NSStringToJavaString(env, name); (*env)->CallVoidMethod(env, dstPrinterJob, jm_setService, printerName); CHECK_EXCEPTION(); @@ -601,7 +600,7 @@ jobject printerTrayObj = (*env)->CallObjectMethod(env, jthis, jm_getPrinterTray); CHECK_EXCEPTION(); if (printerTrayObj != NULL) { - NSString *printerTray = JNFJavaToNSString(env, printerTrayObj); + NSString *printerTray = JavaStringToNSString(env, printerTrayObj); if (printerTray != nil) { [[printInfo printSettings] setObject:printerTray forKey:@"InputSlot"]; } @@ -615,7 +614,7 @@ jobject printerNameObj = (*env)->CallObjectMethod(env, jthis, jm_getPrinterName); CHECK_EXCEPTION(); if (printerNameObj != NULL) { - NSString *printerName = JNFJavaToNSString(env, printerNameObj); + NSString *printerName = JavaStringToNSString(env, printerNameObj); if (printerName != nil) { NSPrinter *printer = [NSPrinter printerWithName:printerName]; if (printer != nil) [printInfo setPrinter:printer]; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m @@ -25,7 +25,6 @@ #import "JNIUtilities.h" -#import #import #import "CRobotKeyCode.h" diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CSystemColors.m @@ -28,7 +28,6 @@ #import "java_awt_SystemColor.h" #import "sun_lwawt_macosx_LWCToolkit.h" -#import #import #import "ThreadUtilities.h" diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTextPipe.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTextPipe.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTextPipe.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTextPipe.m @@ -30,8 +30,6 @@ #import "sun_lwawt_macosx_CTextPipe.h" #import "sun_java2d_OSXSurfaceData.h" -#import - #import "CoreTextSupport.h" #import "QuartzSurfaceData.h" #include "AWTStrike.h" @@ -586,6 +584,9 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CTextPipe_doDrawString (JNIEnv *env, jobject jthis, jobject jsurfacedata, jlong awtStrikePtr, jstring str, jdouble x, jdouble y) { + if (str == NULL) { + return; + } QuartzSDOps *qsdo = (QuartzSDOps *)SurfaceData_GetOps(env, jsurfacedata); AWTStrike *awtStrike = (AWTStrike *)jlong_to_ptr(awtStrikePtr); @@ -597,7 +598,7 @@ { jchar unichars[len]; (*env)->GetStringRegion(env, str, 0, len, unichars); - JNF_CHECK_AND_RETHROW_EXCEPTION(env); + CHECK_EXCEPTION(); // Draw the text context DrawTextContext(env, qsdo, awtStrike, unichars, len, x, y); @@ -605,12 +606,16 @@ else { // Get string to draw and the length - const jchar *unichars = JNFGetStringUTF16UniChars(env, str); + const jchar *unichars = (*env)->GetStringChars(env, str, NULL); + if (unichars == NULL) { + JNU_ThrowOutOfMemoryError(env, "Could not get string chars"); + return; + } // Draw the text context DrawTextContext(env, qsdo, awtStrike, unichars, len, x, y); - JNFReleaseStringUTF16UniChars(env, str, unichars); + (*env)->ReleaseStringChars(env, str, unichars); } JNI_COCOA_RENDERER_EXIT(env); @@ -635,7 +640,7 @@ { jchar copyUnichars[length]; (*env)->GetCharArrayRegion(env, unicodes, offset, length, copyUnichars); - JNF_CHECK_AND_RETHROW_EXCEPTION(env); + CHECK_EXCEPTION(); DrawTextContext(env, qsdo, awtStrike, copyUnichars, length, x, y); } else @@ -648,7 +653,7 @@ @try { (*env)->GetCharArrayRegion(env, unicodes, offset, length, copyUnichars); - JNF_CHECK_AND_RETHROW_EXCEPTION(env); + CHECK_EXCEPTION(); DrawTextContext(env, qsdo, awtStrike, copyUnichars, length, x, y); } @finally { free(copyUnichars); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m @@ -26,7 +26,6 @@ #import "jni_util.h" #import -#import #import "CTrayIcon.h" #import "ThreadUtilities.h" @@ -366,7 +365,7 @@ JNI_COCOA_ENTER(env); AWTTrayIcon *icon = jlong_to_ptr(model); - NSString *tooltip = JNFJavaToNSString(env, jtooltip); + NSString *tooltip = JavaStringToNSString(env, jtooltip); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [icon setTooltip:tooltip]; }]; @@ -419,8 +418,8 @@ JNI_COCOA_ENTER(env); AWTTrayIcon *icon = jlong_to_ptr(model); - NSString *caption = JNFJavaToNSString(env, jcaption); - NSString *text = JNFJavaToNSString(env, jtext); + NSString *caption = JavaStringToNSString(env, jcaption); + NSString *text = JavaStringToNSString(env, jtext); NSImage * contentImage = jlong_to_ptr(nsimage); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CWrapper.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CWrapper.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CWrapper.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CWrapper.m @@ -25,7 +25,6 @@ #import "JNIUtilities.h" -#import #import "ThreadUtilities.h" #import "sun_lwawt_macosx_CWrapper_NSWindow.h" @@ -592,7 +591,7 @@ JNI_COCOA_ENTER(env); NSView *view = (NSView *)jlong_to_ptr(viewPtr); - NSString* s = JNFJavaToNSString(env, msg); + NSString* s = JavaStringToNSString(env, msg); [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [view setToolTip: s]; }]; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/GeomUtilities.m @@ -100,7 +100,10 @@ static NSScreen *primaryScreen(JNIEnv *env) { NSScreen *primaryScreen = [[NSScreen screens] objectAtIndex:0]; if (primaryScreen != nil) return primaryScreen; - if (env != NULL) [JNFException raise:env as:kRuntimeException reason:"Failed to convert, no screen."]; + if ((env != NULL) && ([NSThread isMainThread] == NO)) { + JNU_ThrowByName(env, "java/lang/RuntimeException", "Failed to convert, no screen."); + } + [NSException raise:NSGenericException format:@"Failed to convert, no screen."]; return nil; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m @@ -32,7 +32,6 @@ #import "ThreadUtilities.h" #import "JNIUtilities.h" -#import #import "BufImgSurfaceData.h" diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m @@ -83,7 +83,7 @@ fCompLocal ); CHECK_EXCEPTION(); if (jstr != NULL) { - str = JNFJavaToNSString(env, jstr); // AWT_THREADING Safe (AWTRunLoopMode) + str = JavaStringToNSString(env, jstr); (*env)->DeleteLocalRef(env, jstr); } (*env)->DeleteLocalRef(env, fCompLocal); @@ -99,7 +99,7 @@ "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)V"); (*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_doAccessibleAction, - fAccessibleAction, fIndex, fComponent); // AWT_THREADING Safe (AWTRunLoopMode) + fAccessibleAction, fIndex, fComponent); CHECK_EXCEPTION(); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.h b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.h --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.h @@ -23,7 +23,7 @@ * questions. */ -#import +#import "JNIUtilities.h" extern NSString *const JavaAccessibilityIgnore; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityUtilities.m @@ -27,8 +27,6 @@ #import "JNIUtilities.h" #import -#import - static BOOL JavaAccessibilityIsSupportedAttribute(id element, NSString *attribute); static void JavaAccessibilityLogError(NSString *message); @@ -58,7 +56,7 @@ DECLARE_STATIC_METHOD_RETURN(jm_getSize, sjc_CAccessibility, "getSize", "(Ljavax/accessibility/AccessibleComponent;Ljava/awt/Component;)Ljava/awt/Dimension;", NSZeroSize); - jobject dimension = (*env)->CallStaticObjectMethod(env, jc_Dimension, jm_getSize, axComponent, component); // AWT_THREADING Safe (AWTRunLoopMode) + jobject dimension = (*env)->CallStaticObjectMethod(env, jc_Dimension, jm_getSize, axComponent, component); CHECK_EXCEPTION(); if (dimension == NULL) return NSZeroSize; @@ -71,11 +69,11 @@ DECLARE_STATIC_METHOD_RETURN(sjm_getAccessibleRole, sjc_CAccessibility, "getAccessibleRole", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;", nil); jobject axRole = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleRole, - axComponent, component); // AWT_THREADING Safe (AWTRunLoopMode) + axComponent, component); CHECK_EXCEPTION(); if (axRole == NULL) return @"unknown"; - NSString* str = JNFJavaToNSString(env, axRole); + NSString* str = JavaStringToNSString(env, axRole); (*env)->DeleteLocalRef(env, axRole); return str; } @@ -86,7 +84,7 @@ DECLARE_STATIC_METHOD_RETURN(jm_getAccessibleSelection, sjc_CAccessibility, "getAccessibleSelection", "(Ljavax/accessibility/AccessibleContext;Ljava/awt/Component;)Ljavax/accessibility/AccessibleSelection;", nil); jobject o = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibleSelection, - axContext, component); // AWT_THREADING Safe (AWTRunLoopMode) + axContext, component); CHECK_EXCEPTION(); return o; } @@ -97,7 +95,7 @@ DECLARE_STATIC_METHOD_RETURN(jm_ax_getAccessibleSelection, sjc_CAccessibility, "ax_getAccessibleSelection", "(Ljavax/accessibility/AccessibleContext;ILjava/awt/Component;)Ljavax/accessibility/Accessible;", nil); return (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_ax_getAccessibleSelection, - axContext, index, component); // AWT_THREADING Safe (AWTRunLoopMode) + axContext, index, component); CHECK_EXCEPTION(); } @@ -107,7 +105,7 @@ DECLARE_STATIC_METHOD(jm_addAccessibleSelection, sjc_CAccessibility, "addAccessibleSelection", "(Ljavax/accessibility/AccessibleContext;ILjava/awt/Component;)V"); (*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_addAccessibleSelection, - axContext, index, component); // AWT_THREADING Safe (AWTRunLoopMode) + axContext, index, component); CHECK_EXCEPTION(); } @@ -117,7 +115,7 @@ DECLARE_STATIC_METHOD_RETURN(jm_getAccessibleContext, sjc_CAccessibility, "getAccessibleContext", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleContext;", nil); jobject o = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibleContext, - accessible, component); // AWT_THREADING Safe (AWTRunLoopMode) + accessible, component); CHECK_EXCEPTION(); return o; } @@ -128,7 +126,7 @@ DECLARE_STATIC_METHOD_RETURN(jm_isAccessibleChildSelected, sjc_CAccessibility, "isAccessibleChildSelected", "(Ljavax/accessibility/Accessible;ILjava/awt/Component;)Z", NO); jboolean b = (*env)->CallStaticBooleanMethod(env, sjc_CAccessibility, jm_isAccessibleChildSelected, - accessible, index, component); // AWT_THREADING Safe (AWTRunLoopMode) + accessible, index, component); CHECK_EXCEPTION(); return b; } @@ -139,7 +137,7 @@ DECLARE_STATIC_METHOD_RETURN(jm_getAccessibleStateSet, sjc_CAccessibility, "getAccessibleStateSet", "(Ljavax/accessibility/AccessibleContext;Ljava/awt/Component;)Ljavax/accessibility/AccessibleStateSet;", nil); jobject o = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibleStateSet, - axContext, component); // AWT_THREADING Safe (AWTRunLoopMode) + axContext, component); CHECK_EXCEPTION(); return o; } @@ -149,7 +147,7 @@ GET_CACCESSIBILITY_CLASS_RETURN(NO); DECLARE_STATIC_METHOD_RETURN(jm_contains, sjc_CAccessibility, "contains", "(Ljavax/accessibility/AccessibleContext;Ljavax/accessibility/AccessibleState;Ljava/awt/Component;)Z", NO); - jboolean b = (*env)->CallStaticBooleanMethod(env, sjc_CAccessibility, jm_contains, axContext, axState, component); // AWT_THREADING Safe (AWTRunLoopMode) + jboolean b = (*env)->CallStaticBooleanMethod(env, sjc_CAccessibility, jm_contains, axContext, axState, component); CHECK_EXCEPTION(); return b; } @@ -210,7 +208,7 @@ DECLARE_FIELD_RETURN(sjf_X, sjc_Point, "x", "I", NSZeroPoint); DECLARE_FIELD_RETURN(sjf_Y, sjc_Point, "y", "I", NSZeroPoint); jobject jpoint = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getLocationOnScreen, - axComponent, component); // AWT_THREADING Safe (AWTRunLoopMode) + axComponent, component); CHECK_EXCEPTION(); if (jpoint == NULL) return NSZeroPoint; return NSMakePoint((*env)->GetIntField(env, jpoint, sjf_X), (*env)->GetIntField(env, jpoint, sjf_Y)); @@ -221,7 +219,7 @@ GET_CACCESSIBILITY_CLASS_RETURN(0); DECLARE_STATIC_METHOD_RETURN(jm_getCharCount, sjc_CAccessibility, "getCharCount", "(Ljavax/accessibility/AccessibleText;Ljava/awt/Component;)I", 0); - int i = (*env)->CallStaticIntMethod(env, sjc_CAccessibility, jm_getCharCount, axText, component); // AWT_THREADING Safe (AWTRunLoopMode) + int i = (*env)->CallStaticIntMethod(env, sjc_CAccessibility, jm_getCharCount, axText, component); CHECK_EXCEPTION(); return i; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m @@ -35,7 +35,6 @@ #import -#import #import #import @@ -299,7 +298,7 @@ NSInteger i; for (i = 0; i < count; i++) { - jstring jString = JNFNSToJavaString(env, [ignoredKeys objectAtIndex:i]); + jstring jString = NSStringToJavaString(env, [ignoredKeys objectAtIndex:i]); (*env)->SetObjectArrayElement(env, result, i, jString); (*env)->DeleteLocalRef(env, jString); } @@ -335,7 +334,7 @@ if (parent->fAccessible == NULL) return nil; GET_CHILDRENANDROLES_METHOD_RETURN(nil); jobjectArray jchildrenAndRoles = (jobjectArray)(*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getChildrenAndRoles, - parent->fAccessible, parent->fComponent, whichChildren, allowIgnored); // AWT_THREADING Safe (AWTRunLoop) + parent->fAccessible, parent->fComponent, whichChildren, allowIgnored); CHECK_EXCEPTION(); if (jchildrenAndRoles == NULL) return nil; @@ -355,7 +354,7 @@ DECLARE_FIELD_RETURN(sjf_key, sjc_AccessibleRole, "key", "Ljava/lang/String;", nil); jobject jkey = (*env)->GetObjectField(env, jchildJavaRole, sjf_key); CHECK_EXCEPTION(); - childJavaRole = JNFJavaToNSString(env, jkey); + childJavaRole = JavaStringToNSString(env, jkey); (*env)->DeleteLocalRef(env, jkey); } @@ -470,7 +469,7 @@ // Get all the other accessibility attributes states we need in one swell foop. // javaRole isn't pulled in because we need protected access to AccessibleRole.key jbooleanArray attributeStates = (jbooleanArray)(*env)->CallStaticObjectMethod(env, sjc_CAccessibility, - jm_getInitialAttributeStates, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jm_getInitialAttributeStates, fAccessible, fComponent); CHECK_EXCEPTION(); if (attributeStates == NULL) return nil; jboolean *attributeStatesArray = (*env)->GetBooleanArrayElements(env, attributeStates, 0); @@ -566,7 +565,7 @@ // On MacOSX, text doesn't have actions, in java it does. // cmcnote: NOT TRUE - Editable text has AXShowMenu. Textfields have AXConfirm. Static text has no actions. - jobject axAction = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibleAction, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jobject axAction = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibleAction, fAccessible, fComponent); CHECK_EXCEPTION(); if (axAction != NULL) { //+++gdb NOTE: In MacOSX, there is just a single Action, not multiple. In java, @@ -841,7 +840,7 @@ GET_CACCESSIBILITY_CLASS_RETURN(nil); DECLARE_STATIC_METHOD_RETURN(jm_isEnabled, sjc_CAccessibility, "isEnabled", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Z", nil); - NSNumber *value = [NSNumber numberWithBool:(*env)->CallStaticBooleanMethod(env, sjc_CAccessibility, jm_isEnabled, fAccessible, fComponent)]; // AWT_THREADING Safe (AWTRunLoop) + NSNumber *value = [NSNumber numberWithBool:(*env)->CallStaticBooleanMethod(env, sjc_CAccessibility, jm_isEnabled, fAccessible, fComponent)]; CHECK_EXCEPTION(); if (value == nil) { NSLog(@"WARNING: %s called on component that has no accessible component: %@", __FUNCTION__, self); @@ -873,7 +872,7 @@ // as well as having AccessibleState.FOCUSABLE in its AccessibleStateSet. // We use the former heuristic; if the component focus-traversable, add a focused attribute // See also initializeAttributeNamesWithEnv: - if ((*env)->CallStaticBooleanMethod(env, sjc_CAccessibility, sjm_isFocusTraversable, fAccessible, fComponent)) { // AWT_THREADING Safe (AWTRunLoop) + if ((*env)->CallStaticBooleanMethod(env, sjc_CAccessibility, sjm_isFocusTraversable, fAccessible, fComponent)) { return YES; } CHECK_EXCEPTION(); @@ -890,7 +889,7 @@ if ([(NSNumber*)value boolValue]) { - (*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_requestFocus, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + (*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_requestFocus, fAccessible, fComponent); CHECK_EXCEPTION(); } } @@ -904,12 +903,12 @@ DECLARE_STATIC_METHOD_RETURN(sjm_getAccessibleDescription, sjc_CAccessibility, "getAccessibleDescription", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;", nil); jobject val = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, - sjm_getAccessibleDescription, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + sjm_getAccessibleDescription, fAccessible, fComponent); CHECK_EXCEPTION(); if (val == NULL) { return nil; } - NSString* str = JNFJavaToNSString(env, val); + NSString* str = JavaStringToNSString(env, val); (*env)->DeleteLocalRef(env, val); return str; } @@ -931,6 +930,32 @@ return NO; } +/* + * The java/lang/Number concrete class could be for any of the Java primitive + * numerical types or some other subclass. + * All existing A11Y code uses Integer so that is what we look for first + * But all must be able to return a double and NSNumber accepts a double, + * so that's the fall back. + */ +static NSNumber* JavaNumberToNSNumber(JNIEnv *env, jobject jnumber) { + if (jnumber == NULL) { + return nil; + } + DECLARE_CLASS_RETURN(jnumber_Class, "java/lang/Number", nil); + DECLARE_CLASS_RETURN(jinteger_Class, "java/lang/Integer", nil); + DECLARE_METHOD_RETURN(jm_intValue, jnumber_Class, "intValue", "()D", nil); + DECLARE_METHOD_RETURN(jm_doubleValue, jnumber_Class, "doubleValue", "()D", nil); + if ((*env)->IsInstanceOf(env, jnumber, jinteger_Class)) { + jint i = (*env)->CallIntMethod(env, jnumber_Class, jm_intValue); + CHECK_EXCEPTION(); + return [NSNumber numberWithInteger:i]; + } else { + jdouble d = (*env)->CallDoubleMethod(env, jnumber_Class, jm_doubleValue); + CHECK_EXCEPTION(); + return [NSNumber numberWithDouble:d]; + } +} + // Element's maximum value (id) - (id)accessibilityMaxValueAttribute { @@ -939,12 +964,12 @@ DECLARE_STATIC_METHOD_RETURN(jm_getMaximumAccessibleValue, sjc_CAccessibility, "getMaximumAccessibleValue", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/Number;", nil); - jobject axValue = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getMaximumAccessibleValue, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jobject axValue = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getMaximumAccessibleValue, fAccessible, fComponent); CHECK_EXCEPTION(); if (axValue == NULL) { return [NSNumber numberWithInt:0]; } - NSNumber* num = JNFJavaToNSNumber(env, axValue); + NSNumber* num = JavaNumberToNSNumber(env, axValue); (*env)->DeleteLocalRef(env, axValue); return num; } @@ -962,12 +987,12 @@ DECLARE_STATIC_METHOD_RETURN(jm_getMinimumAccessibleValue, sjc_CAccessibility, "getMinimumAccessibleValue", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/Number;", nil); - jobject axValue = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getMinimumAccessibleValue, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jobject axValue = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getMinimumAccessibleValue, fAccessible, fComponent); CHECK_EXCEPTION(); if (axValue == NULL) { return [NSNumber numberWithInt:0]; } - NSNumber* num = JNFJavaToNSNumber(env, axValue); + NSNumber* num = JavaNumberToNSNumber(env, axValue); (*env)->DeleteLocalRef(env, axValue); return num; } @@ -1019,7 +1044,7 @@ JNIEnv* env = [ThreadUtilities getJNIEnv]; GET_ACCESSIBLECOMPONENT_STATIC_METHOD_RETURN(nil); jobject axComponent = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleComponent, - fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + fAccessible, fComponent); CHECK_EXCEPTION(); // NSAccessibility wants the bottom left point of the object in @@ -1090,7 +1115,7 @@ jobject axRole = (*env)->CallStaticObjectMethod(env, jm_getAccessibleRoleDisplayString, fAccessible, fComponent); CHECK_EXCEPTION(); if (axRole != NULL) { - value = JNFJavaToNSString(env, axRole); + value = JavaStringToNSString(env, axRole); (*env)->DeleteLocalRef(env, axRole); } else { value = @"unknown"; @@ -1146,7 +1171,7 @@ "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)V"); if ([(NSNumber*)value boolValue]) { - (*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_requestSelection, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + (*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_requestSelection, fAccessible, fComponent); CHECK_EXCEPTION(); } } @@ -1156,7 +1181,7 @@ JNIEnv* env = [ThreadUtilities getJNIEnv]; GET_ACCESSIBLECOMPONENT_STATIC_METHOD_RETURN(nil); jobject axComponent = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, - sjm_getAccessibleComponent, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + sjm_getAccessibleComponent, fAccessible, fComponent); CHECK_EXCEPTION(); NSValue* size = [NSValue valueWithSize:getAxComponentSize(env, axComponent, fComponent)]; (*env)->DeleteLocalRef(env, axComponent); @@ -1218,12 +1243,12 @@ JNIEnv* env = [ThreadUtilities getJNIEnv]; GET_ACCESSIBLENAME_METHOD_RETURN(nil); - jobject val = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleName, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jobject val = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleName, fAccessible, fComponent); CHECK_EXCEPTION(); if (val == NULL) { return nil; } - NSString* str = JNFJavaToNSString(env, val); + NSString* str = JavaStringToNSString(env, val); (*env)->DeleteLocalRef(env, val); return str; } @@ -1279,12 +1304,12 @@ (*env)->CallStaticObjectMethod( env, sjm_getAccessibleName, selectedMenuItem->fAccessible, - selectedMenuItem->fComponent ); // AWT_THREADING Safe (AWTRunLoop) + selectedMenuItem->fComponent ); CHECK_EXCEPTION(); if (itemValue == NULL) { return nil; } - NSString* itemString = JNFJavaToNSString(env, itemValue); + NSString* itemString = JavaStringToNSString(env, itemValue); (*env)->DeleteLocalRef(env, itemValue); return itemString; } else { @@ -1301,7 +1326,7 @@ GET_CACCESSIBILITY_CLASS_RETURN(nil); DECLARE_STATIC_METHOD_RETURN(sjm_getAccessibleValue, sjc_CAccessibility, "getAccessibleValue", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleValue;", nil); - jobject axValue = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleValue, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jobject axValue = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleValue, fAccessible, fComponent); CHECK_EXCEPTION(); if (axValue != NULL) { DECLARE_STATIC_METHOD_RETURN(jm_getCurrentAccessibleValue, sjc_CAccessibility, "getCurrentAccessibleValue", @@ -1309,7 +1334,7 @@ jobject str = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getCurrentAccessibleValue, axValue, fComponent); CHECK_EXCEPTION(); if (str != NULL) { - num = JNFJavaToNSNumber(env, str); // AWT_THREADING Safe (AWTRunLoop) + num = JavaNumberToNSNumber(env, str); (*env)->DeleteLocalRef(env, str); } (*env)->DeleteLocalRef(env, axValue); @@ -1415,9 +1440,9 @@ jobject jparent = fComponent; id value = nil; - if (JNFIsInstanceOf(env, jparent, &jc_Container)) { + if ((*env)->IsInstanceOf(env, jparent, jc_Container)) { jobject jaccessible = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_accessibilityHitTest, - jparent, (jfloat)point.x, (jfloat)point.y); // AWT_THREADING Safe (AWTRunLoop) + jparent, (jfloat)point.x, (jfloat)point.y); CHECK_EXCEPTION(); if (jaccessible != NULL) { value = [JavaComponentAccessibility createWithAccessible:jaccessible withEnv:env withView:fView]; @@ -1447,7 +1472,7 @@ id value = nil; NSWindow* hostWindow = [[self->fView window] retain]; - jobject focused = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getFocusOwner, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jobject focused = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getFocusOwner, fComponent); [hostWindow release]; CHECK_EXCEPTION(); @@ -1636,7 +1661,7 @@ { GET_CHILDRENANDROLES_METHOD_RETURN(nil); jobjectArray jtabsAndRoles = (jobjectArray)(*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getChildrenAndRoles, - fAccessible, fComponent, whichTabs, allowIgnored); // AWT_THREADING Safe (AWTRunLoop) + fAccessible, fComponent, whichTabs, allowIgnored); CHECK_EXCEPTION(); if(jtabsAndRoles == NULL) return nil; @@ -1657,7 +1682,7 @@ DECLARE_FIELD_RETURN(sjf_key, sjc_AccessibleRole, "key", "Ljava/lang/String;", nil); jobject jkey = (*env)->GetObjectField(env, jtabJavaRole, sjf_key); CHECK_EXCEPTION(); - NSString *tabJavaRole = JNFJavaToNSString(env, jkey); + NSString *tabJavaRole = JavaStringToNSString(env, jkey); (*env)->DeleteLocalRef(env, jkey); NSInteger i; @@ -1973,11 +1998,11 @@ DECLARE_CLASS_RETURN(sjc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit", NO); DECLARE_STATIC_METHOD_RETURN(jm_doEquals, sjc_LWCToolkit, "doEquals", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/awt/Component;)Z", NO); - return (*env)->CallStaticBooleanMethod(env, sjc_LWCToolkit, jm_doEquals, a, b, component); // AWT_THREADING Safe (AWTRunLoopMode) + return (*env)->CallStaticBooleanMethod(env, sjc_LWCToolkit, jm_doEquals, a, b, component); CHECK_EXCEPTION(); } - jboolean jb = (*env)->CallBooleanMethod(env, a, jm_equals, b); // AWT_THREADING Safe (!appKit) + jboolean jb = (*env)->CallBooleanMethod(env, a, jm_equals, b); CHECK_EXCEPTION(); return jb; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaTextAccessibility.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaTextAccessibility.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaTextAccessibility.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaTextAccessibility.m @@ -134,10 +134,10 @@ if ([[self accessibilityRoleAttribute] isEqualToString:NSAccessibilityStaticTextRole]) { // if it's static text, the AppKit AXValue is the java accessibleName jobject axName = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, - sjm_getAccessibleName, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + sjm_getAccessibleName, fAccessible, fComponent); CHECK_EXCEPTION(); if (axName != NULL) { - NSString* str = JNFJavaToNSString(env, axName); + NSString* str = JavaStringToNSString(env, axName); (*env)->DeleteLocalRef(env, axName); return str; } @@ -147,14 +147,14 @@ // cmcnote: inefficient to make three distinct JNI calls. Coalesce. radr://3951923 GET_ACCESSIBLETEXT_METHOD_RETURN(@""); jobject axText = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, - sjm_getAccessibleText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + sjm_getAccessibleText, fAccessible, fComponent); CHECK_EXCEPTION(); if (axText == NULL) return nil; (*env)->DeleteLocalRef(env, axText); GET_ACCESSIBLEEDITABLETEXT_METHOD_RETURN(nil); jobject axEditableText = (*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, - sjm_getAccessibleEditableText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + sjm_getAccessibleEditableText, fAccessible, fComponent); CHECK_EXCEPTION(); if (axEditableText == NULL) return nil; @@ -163,7 +163,7 @@ jobject jrange = (*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, jm_getTextRange, axEditableText, 0, getAxTextCharCount(env, axEditableText, fComponent), fComponent); CHECK_EXCEPTION(); - NSString *string = JNFJavaToNSString(env, jrange); // AWT_THREADING Safe (AWTRunLoop) + NSString *string = JavaStringToNSString(env, jrange); (*env)->DeleteLocalRef(env, jrange); (*env)->DeleteLocalRef(env, axEditableText); @@ -181,7 +181,7 @@ JNIEnv* env = [ThreadUtilities getJNIEnv]; GET_ACCESSIBLEEDITABLETEXT_METHOD_RETURN(NO); jobject axEditableText = (*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, - sjm_getAccessibleEditableText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + sjm_getAccessibleEditableText, fAccessible, fComponent); CHECK_EXCEPTION(); if (axEditableText == NULL) return NO; (*env)->DeleteLocalRef(env, axEditableText); @@ -204,10 +204,10 @@ DECLARE_STATIC_METHOD_RETURN(jm_getSelectedText, sjc_CAccessibleText, "getSelectedText", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;", nil); jobject axText = (*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, jm_getSelectedText, - fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + fAccessible, fComponent); CHECK_EXCEPTION(); if (axText == NULL) return @""; - NSString* str = JNFJavaToNSString(env, axText); + NSString* str = JavaStringToNSString(env, axText); (*env)->DeleteLocalRef(env, axText); return str; } @@ -227,12 +227,12 @@ #endif JNIEnv *env = [ThreadUtilities getJNIEnv]; - jstring jstringValue = JNFNSToJavaString(env, (NSString *)value); + jstring jstringValue = NSStringToJavaString(env, (NSString *)value); GET_CACCESSIBLETEXT_CLASS(); DECLARE_STATIC_METHOD(jm_setSelectedText, sjc_CAccessibleText, "setSelectedText", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;Ljava/lang/String;)V"); (*env)->CallStaticVoidMethod(env, sjc_CAccessibleText, jm_setSelectedText, - fAccessible, fComponent, jstringValue); // AWT_THREADING Safe (AWTRunLoop) + fAccessible, fComponent, jstringValue); CHECK_EXCEPTION(); } @@ -244,7 +244,7 @@ DECLARE_STATIC_METHOD_RETURN(jm_getSelectedTextRange, sjc_CAccessibleText, "getSelectedTextRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)[I", nil); jintArray axTextRange = (*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, - jm_getSelectedTextRange, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jm_getSelectedTextRange, fAccessible, fComponent); CHECK_EXCEPTION(); if (axTextRange == NULL) return nil; @@ -274,7 +274,7 @@ DECLARE_STATIC_METHOD(jm_setSelectedTextRange, sjc_CAccessibleText, "setSelectedTextRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)V"); (*env)->CallStaticVoidMethod(env, sjc_CAccessibleText, jm_setSelectedTextRange, - fAccessible, fComponent, startIndex, endIndex); // AWT_THREADING Safe (AWTRunLoop) + fAccessible, fComponent, startIndex, endIndex); CHECK_EXCEPTION(); } @@ -285,7 +285,7 @@ JNIEnv *env = [ThreadUtilities getJNIEnv]; GET_ACCESSIBLETEXT_METHOD_RETURN(nil); jobject axText = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, - sjm_getAccessibleText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + sjm_getAccessibleText, fAccessible, fComponent); CHECK_EXCEPTION(); NSNumber* num = [NSNumber numberWithInt:getAxTextCharCount(env, axText, fComponent)]; (*env)->DeleteLocalRef(env, axText); @@ -304,7 +304,7 @@ DECLARE_STATIC_METHOD_RETURN(jm_getVisibleCharacterRange, sjc_CAccessibleText, "getVisibleCharacterRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)[I", nil); jintArray axTextRange = (*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, - jm_getVisibleCharacterRange, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jm_getVisibleCharacterRange, fAccessible, fComponent); CHECK_EXCEPTION(); if (axTextRange == NULL) return nil; @@ -326,7 +326,7 @@ DECLARE_STATIC_METHOD_RETURN(jm_getLineNumberForInsertionPoint, sjc_CAccessibleText, "getLineNumberForInsertionPoint", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)I", nil); jint row = (*env)->CallStaticIntMethod(env, sjc_CAccessibleText, - jm_getLineNumberForInsertionPoint, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop) + jm_getLineNumberForInsertionPoint, fAccessible, fComponent); CHECK_EXCEPTION(); if (row < 0) return nil; return [NSNumber numberWithInt:row]; @@ -365,7 +365,7 @@ DECLARE_STATIC_METHOD_RETURN(jm_getBoundsForRange, sjc_CAccessibleText, "getBoundsForRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)[D", nil); jdoubleArray axBounds = (jdoubleArray)(*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, jm_getBoundsForRange, - fAccessible, fComponent, range.location, range.length); // AWT_THREADING Safe (AWTRunLoop) + fAccessible, fComponent, range.location, range.length); CHECK_EXCEPTION(); if (axBounds == NULL) return nil; @@ -397,7 +397,7 @@ DECLARE_STATIC_METHOD_RETURN(jm_getLineNumberForIndex, sjc_CAccessibleText, "getLineNumberForIndex", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)I", nil); jint row = (*env)->CallStaticIntMethod(env, sjc_CAccessibleText, jm_getLineNumberForIndex, - fAccessible, fComponent, [line intValue]); // AWT_THREADING Safe (AWTRunLoop) + fAccessible, fComponent, [line intValue]); CHECK_EXCEPTION(); if (row < 0) return nil; return [NSNumber numberWithInt:row]; @@ -413,7 +413,7 @@ DECLARE_STATIC_METHOD_RETURN(jm_getRangeForLine, sjc_CAccessibleText, "getRangeForLine", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)[I", nil); jintArray axTextRange = (jintArray)(*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, - jm_getRangeForLine, fAccessible, fComponent, [line intValue]); // AWT_THREADING Safe (AWTRunLoop) + jm_getRangeForLine, fAccessible, fComponent, [line intValue]); CHECK_EXCEPTION(); if (axTextRange == NULL) return nil; @@ -443,10 +443,10 @@ DECLARE_STATIC_METHOD_RETURN(jm_getStringForRange, sjc_CAccessibleText, "getStringForRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)Ljava/lang/String;", nil); jstring jstringForRange = (jstring)(*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, jm_getStringForRange, - fAccessible, fComponent, range.location, range.length); // AWT_THREADING Safe (AWTRunLoop) + fAccessible, fComponent, range.location, range.length); CHECK_EXCEPTION(); if (jstringForRange == NULL) return @""; - NSString* str = JNFJavaToNSString(env, jstringForRange); + NSString* str = JavaStringToNSString(env, jstringForRange); (*env)->DeleteLocalRef(env, jstringForRange); return str; } @@ -475,7 +475,7 @@ DECLARE_STATIC_METHOD_RETURN(jm_getCharacterIndexAtPosition, sjc_CAccessibleText, "getCharacterIndexAtPosition", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)I", nil); jint charIndex = (*env)->CallStaticIntMethod(env, sjc_CAccessibleText, jm_getCharacterIndexAtPosition, - fAccessible, fComponent, point.x, point.y); // AWT_THREADING Safe (AWTRunLoop) + fAccessible, fComponent, point.x, point.y); CHECK_EXCEPTION(); if (charIndex == -1) return nil; @@ -508,7 +508,7 @@ DECLARE_STATIC_METHOD_RETURN(jm_getRangeForIndex, sjc_CAccessibleText, "getRangeForIndex", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)[I", nil); jintArray axTextRange = (jintArray)(*env)->CallStaticObjectMethod(env, sjc_CAccessibleText, jm_getRangeForIndex, - fAccessible, fComponent, index); // AWT_THREADING Safe (AWTRunLoop) + fAccessible, fComponent, index); CHECK_EXCEPTION(); if (axTextRange == NULL) return nil; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m @@ -456,7 +456,7 @@ // could happen if we are embedded inside SWT application, // in this case just spin a single empty block through // the event loop to give it a chance to process pending events - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){}]; + [ThreadUtilities performOnMainThreadWaiting:YES block:^(){}]; } if (([AWTToolkit getEventCount] - currentEventNum) != 0) { @@ -517,7 +517,7 @@ UInt32 colorsArray[len]; UInt32 *colors = colorsArray; - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ NSUInteger i; for (i = 0; i < len; i++) { colors[i] = RGB([CSystemColors getColor:i useAppleColor:useAppleColors]); @@ -587,7 +587,7 @@ // Don't use acceptInputForMode because that doesn't setup autorelease pools properly BOOL isRunning = true; while (![mediatorObject shouldEndRunLoop] && isRunning) { - isRunning = [[NSRunLoop currentRunLoop] runMode:(inAWT ? [JNFRunLoop javaRunLoopMode] : NSDefaultRunLoopMode) + isRunning = [[NSRunLoop currentRunLoop] runMode:(inAWT ? [ThreadUtilities javaRunLoopMode] : NSDefaultRunLoopMode) beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.010]]; if (processEvents) { //We do not spin a runloop here as date is nil, so does not matter which mode to use @@ -654,7 +654,7 @@ (JNIEnv *env, jobject self) { __block jboolean isOn = JNI_FALSE; - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ NSUInteger modifiers = [NSEvent modifierFlags]; isOn = (modifiers & NSAlphaShiftKeyMask) != 0; }]; @@ -727,7 +727,7 @@ Java_sun_font_FontManager_getFontPath (JNIEnv *env, jclass obj, jboolean noType1) { - return JNFNSToJavaString(env, @"/Library/Fonts"); + return NSStringToJavaString(env, @"/Library/Fonts"); } // This isn't yet used on unix, the implementation is added since shared diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrintModel.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrintModel.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrintModel.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrintModel.m @@ -26,8 +26,6 @@ #import "PrintModel.h" -#import - #import "PrinterView.h" #import "ThreadUtilities.h" #import "JNIUtilities.h" @@ -53,7 +51,7 @@ - (BOOL)runPageSetup { __block BOOL fResult = NO; - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ NSPageLayout* pageLayout = [NSPageLayout pageLayout]; fResult = ([pageLayout runModalWithPrintInfo:fPrintInfo] == NSOKButton); }]; @@ -64,7 +62,7 @@ - (BOOL)runJobSetup { __block BOOL fResult = NO; - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ NSPrintPanel* printPanel = [NSPrintPanel printPanel]; fResult = ([printPanel runModalWithPrintInfo:fPrintInfo] == NSOKButton); }]; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterSurfaceData.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterSurfaceData.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterSurfaceData.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterSurfaceData.m @@ -26,8 +26,6 @@ #import "PrinterSurfaceData.h" #import "jni_util.h" -#import - //#define DEBUG 1 #if defined DEBUG diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m @@ -28,8 +28,6 @@ #import "java_awt_print_Pageable.h" #import "java_awt_print_PageFormat.h" -#import - #import "ThreadUtilities.h" #import "GeomUtilities.h" #import "JNIUtilities.h" @@ -106,7 +104,7 @@ CGContextSaveGState(cgRef); //04/28/2004: state needs to be saved here due to addition of lazy state management (*env)->CallVoidMethod(env, fPrinterJob, jm_printToPathGraphics, fCurPeekGraphics, fPrinterJob, - fCurPainter, fCurPageFormat, jPageIndex, context); // AWT_THREADING Safe (AWTRunLoop) + fCurPainter, fCurPageFormat, jPageIndex, context); CHECK_EXCEPTION(); CGContextRestoreGState(cgRef); @@ -122,9 +120,9 @@ GET_CPRINTERJOB_CLASS_RETURN(nil); DECLARE_METHOD_RETURN(jm_getJobName, sjc_CPrinterJob, "getJobName", "()Ljava/lang/String;", nil); - jobject o = (*env)->CallObjectMethod(env, fPrinterJob, jm_getJobName); // AWT_THREADING Safe (known object) + jobject o = (*env)->CallObjectMethod(env, fPrinterJob, jm_getJobName); CHECK_EXCEPTION(); - id result = JNFJavaToNSString(env, o); + id result = JavaStringToNSString(env, o); (*env)->DeleteLocalRef(env, o); return result; } @@ -195,7 +193,7 @@ } jobjectArray objectArray = (*env)->CallObjectMethod(env, fPrinterJob, - jm_getPageformatPrintablePeekgraphics, jPageNumber); // AWT_THREADING Safe (AWTRunLoopMode) + jm_getPageformatPrintablePeekgraphics, jPageNumber); CHECK_EXCEPTION(); if (objectArray != NULL) { // Get references to the return objects -> PageFormat, Printable, PeekGraphics @@ -214,7 +212,7 @@ // Actually print and get the PageFormatArea jobject pageFormatArea = (*env)->CallObjectMethod(env, fPrinterJob, jm_printAndGetPageFormatArea, fCurPainter, - fCurPeekGraphics, fCurPageFormat, jPageNumber); // AWT_THREADING Safe (AWTRunLoopMode) + fCurPeekGraphics, fCurPageFormat, jPageNumber); CHECK_EXCEPTION(); if (pageFormatArea != NULL) { NSPrintingOrientation currentOrientation = diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzRenderer.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzRenderer.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzRenderer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzRenderer.m @@ -28,7 +28,6 @@ #import "sun_java2d_OSXSurfaceData.h" #import -#import #import "ImageSurfaceData.h" diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzSurfaceData.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzSurfaceData.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzSurfaceData.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/QuartzSurfaceData.m @@ -35,8 +35,6 @@ #import "sun_lwawt_macosx_CPrinterSurfaceData.h" #import "ImageSurfaceData.h" -#import - #import #import "ThreadUtilities.h" diff --git a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m --- a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m @@ -23,8 +23,6 @@ * questions. */ -#import - #import "java_awt_Font.h" #import "sun_awt_PlatformFont.h" #import "sun_awt_FontDescriptor.h" @@ -310,9 +308,9 @@ jint i; for (i = 0; i < num; i++) { NSString *fontname = [filteredFonts objectAtIndex:i]; - jobject jFontName = JNFNSToJavaString(env, fontname); + jobject jFontName = NSStringToJavaString(env, fontname); jobject jFontFamilyName = - JNFNSToJavaString(env, GetFamilyNameForFontName(fontname)); + NSStringToJavaString(env, GetFamilyNameForFontName(fontname)); (*env)->CallVoidMethod(env, jthis, jm_registerFont, jFontName, jFontFamilyName); CHECK_EXCEPTION(); @@ -334,7 +332,7 @@ { JNI_COCOA_ENTER(env); - NSString *path = JNFJavaToNSString(env, filename); + NSString *path = JavaStringToNSString(env, filename); NSURL *url = [NSURL fileURLWithPath:(NSString *)path]; bool res = CTFontManagerRegisterFontsForURL((CFURLRef)url, kCTFontManagerScopeProcess, nil); #ifdef DEBUG @@ -434,7 +432,7 @@ JNI_COCOA_ENTER(env); awtFont = - [AWTFont awtFontForName:JNFJavaToNSString(env, nativeFontName) + [AWTFont awtFontForName:JavaStringToNSString(env, nativeFontName) style:style]; // autoreleased if (awtFont) { @@ -570,7 +568,7 @@ #ifdef DEBUG NSLog(@"Font is : %@", (NSString*)fontname); #endif - jstring jFontName = (jstring)JNFNSToJavaString(env, fontname); + jstring jFontName = (jstring)NSStringToJavaString(env, fontname); (*env)->CallBooleanMethod(env, arrayListOfString, addMID, jFontName); if ((*env)->ExceptionOccurred(env)) { return; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m --- a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m @@ -23,7 +23,6 @@ * questions. */ -#import #import "java_awt_geom_PathIterator.h" #import "sun_font_CStrike.h" #import "sun_font_CStrikeDisposer.h" diff --git a/src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m b/src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m --- a/src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/font/CCharToGlyphMapper.m @@ -25,8 +25,6 @@ #import "JNIUtilities.h" -#import - #import "AWTFont.h" #import "CoreTextSupport.h" diff --git a/src/java.desktop/macosx/native/libawt_lwawt/font/CGGlyphImages.m b/src/java.desktop/macosx/native/libawt_lwawt/font/CGGlyphImages.m --- a/src/java.desktop/macosx/native/libawt_lwawt/font/CGGlyphImages.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/font/CGGlyphImages.m @@ -24,8 +24,8 @@ */ #import // for vImage_Buffer -#import +#import "JNIUtilities.h" #import "CGGlyphImages.h" #import "CoreTextSupport.h" #import "fontscalerdefs.h" // contains the definition of GlyphInfo struct diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m @@ -33,7 +33,6 @@ #import #import #import -#import #pragma mark - #pragma mark "--- Mac OS X specific methods for GL pipeline ---" 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 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.h +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.h @@ -26,8 +26,6 @@ #ifndef CGLLayer_h_Included #define CGLLayer_h_Included -#import - @interface CGLLayer : CAOpenGLLayer { @private diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLSurfaceData.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLSurfaceData.m --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLSurfaceData.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLSurfaceData.m @@ -315,7 +315,7 @@ CGLSDOps *dstCGLOps = (CGLSDOps *)dstOps->privOps; CGLLayer *layer = (CGLLayer*)dstCGLOps->layer; if (layer != NULL) { - [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ + [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ AWT_ASSERT_APPKIT_THREAD; [layer setNeedsDisplay]; diff --git a/src/java.desktop/macosx/native/libosx/CFileManager.m b/src/java.desktop/macosx/native/libosx/CFileManager.m --- a/src/java.desktop/macosx/native/libosx/CFileManager.m +++ b/src/java.desktop/macosx/native/libosx/CFileManager.m @@ -26,12 +26,9 @@ #import "com_apple_eio_FileManager.h" #import "JNIUtilities.h" +#import "ThreadUtilities.h" #import -#import - -#import "ThreadUtilities.h" - /* * Class: com_apple_eio_FileManager @@ -42,7 +39,7 @@ (JNIEnv *env, jclass clz, jstring javaFilename, jint type, jint creator) { JNI_COCOA_ENTER(env); - NSString *filename = JNFNormalizedNSStringForPath(env, javaFilename); + NSString *filename = NormalizedPathNSStringFromJavaString(env, javaFilename); NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:type], NSFileHFSTypeCode, [NSNumber numberWithInt:creator], NSFileHFSCreatorCode, nil]; @@ -59,7 +56,7 @@ (JNIEnv *env, jclass ckz, jstring javaFilename, jint type) { JNI_COCOA_ENTER(env); - NSString *filename = JNFNormalizedNSStringForPath(env, javaFilename); + NSString *filename = NormalizedPathNSStringFromJavaString(env, javaFilename); NSDictionary *attr = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:type] forKey:NSFileHFSTypeCode]; [[NSFileManager defaultManager] changeFileAttributes:attr atPath:filename]; JNI_COCOA_EXIT(env); @@ -74,7 +71,7 @@ (JNIEnv *env, jclass clz, jstring javaFilename, jint creator) { JNI_COCOA_ENTER(env); - NSString *filename = JNFNormalizedNSStringForPath(env, javaFilename); + NSString *filename = NormalizedPathNSStringFromJavaString(env, javaFilename); NSDictionary *attr = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:creator] forKey:NSFileHFSCreatorCode]; [[NSFileManager defaultManager] changeFileAttributes:attr atPath:filename]; JNI_COCOA_EXIT(env); @@ -90,7 +87,7 @@ { jint type = 0; JNI_COCOA_ENTER(env); - NSString *filename = JNFNormalizedNSStringForPath(env, javaFilename); + NSString *filename = NormalizedPathNSStringFromJavaString(env, javaFilename); NSDictionary *attributes = [[NSFileManager defaultManager] fileAttributesAtPath:filename traverseLink:YES]; NSNumber *val = [attributes objectForKey:NSFileHFSTypeCode]; type = [val intValue]; @@ -108,7 +105,7 @@ { jint creator = 0; JNI_COCOA_ENTER(env); - NSString *filename = JNFNormalizedNSStringForPath(env, javaFilename); + NSString *filename = NormalizedPathNSStringFromJavaString(env, javaFilename); NSDictionary *attributes = [[NSFileManager defaultManager] fileAttributesAtPath:filename traverseLink:YES]; NSNumber *val = [attributes objectForKey:NSFileHFSCreatorCode]; creator = [val intValue]; @@ -133,7 +130,7 @@ char path[PATH_MAX]; if (FSRefMakePath(&foundRef, (UInt8 *)path, sizeof(path)) == noErr) { NSString *filenameString = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:path length:strlen(path)]; - filename = JNFNormalizedJavaStringForPath(env, filenameString); + filename = NormalizedPathJavaStringFromNSString(env, filenameString); } } @@ -152,10 +149,10 @@ { JNI_COCOA_ENTER(env); - NSURL *url = [NSURL URLWithString:JNFNormalizedNSStringForPath(env, urlString)]; + NSURL *url = [NSURL URLWithString:NormalizedPathNSStringFromJavaString(env, urlString)]; // Radar 3208005: Run this on the main thread; file:// style URLs will hang otherwise. - [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ + [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ [[NSWorkspace sharedWorkspace] openURL:url]; }]; @@ -174,15 +171,15 @@ jstring filename = NULL; JNI_COCOA_ENTER(env); - NSString *resourceName = JNFNormalizedNSStringForPath(env, javaResourceName); - NSString *subDirectory = JNFNormalizedNSStringForPath(env, javaSubDirName); - NSString *typeName = JNFNormalizedNSStringForPath(env, javaTypeName); + NSString *resourceName = NormalizedPathNSStringFromJavaString(env, javaResourceName); + NSString *subDirectory = NormalizedPathNSStringFromJavaString(env, javaSubDirName); + NSString *typeName = NormalizedPathNSStringFromJavaString(env, javaTypeName); NSString *path = [[NSBundle mainBundle] pathForResource:resourceName ofType:typeName inDirectory:subDirectory]; - filename = JNFNormalizedJavaStringForPath(env, path); + filename = NormalizedPathJavaStringFromNSString(env, path); JNI_COCOA_EXIT(env); return filename; @@ -201,7 +198,7 @@ JNI_COCOA_ENTER(env); NSBundle *mainBundle = [NSBundle mainBundle]; - filename = JNFNormalizedJavaStringForPath(env, [mainBundle bundlePath]); + filename = NormalizedPathJavaStringFromNSString(env, [mainBundle bundlePath]); JNI_COCOA_EXIT(env); return filename; @@ -220,9 +217,9 @@ __block BOOL returnValue = NO; JNI_COCOA_ENTER(env); - NSString * path = JNFNormalizedNSStringForPath(env, fileName); + NSString * path = NormalizedPathNSStringFromJavaString(env, fileName); NSURL *url = [NSURL fileURLWithPath:path]; - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ returnValue = [[NSFileManager defaultManager] trashItemAtURL:url resultingItemURL:nil @@ -246,8 +243,8 @@ __block jboolean returnValue = JNI_FALSE; JNI_COCOA_ENTER(env); - NSString *path = JNFNormalizedNSStringForPath(env, url); - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + NSString *path = NormalizedPathNSStringFromJavaString(env, url); + [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ returnValue = [[NSWorkspace sharedWorkspace] selectFile:path inFileViewerRootedAtPath:@""]; }]; diff --git a/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h b/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h --- a/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h +++ b/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -237,4 +237,14 @@ [pool drain]; \ }; +/******** STRING CONVERSION SUPPORT *********/ + +JNIEXPORT NSString* JavaStringToNSString(JNIEnv *env, jstring jstr); + +JNIEXPORT jstring NSStringToJavaString(JNIEnv* env, NSString *str); + +JNIEXPORT NSString* NormalizedPathNSStringFromJavaString(JNIEnv *env, jstring pathStr); + +JNIEXPORT jstring NormalizedPathJavaStringFromNSString(JNIEnv* env, NSString *str); + #endif /* __JNIUTILITIES_H */ diff --git a/src/java.desktop/macosx/native/libosxapp/JNIUtilities.m b/src/java.desktop/macosx/native/libosxapp/JNIUtilities.m new file mode 100644 --- /dev/null +++ b/src/java.desktop/macosx/native/libosxapp/JNIUtilities.m @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#include "JNIUtilities.h" + +NSString* JavaStringToNSString(JNIEnv *env, jstring jstr) { + if (jstr == NULL) { + return NULL; + } + jsize len = (*env)->GetStringLength(env, jstr); + const jchar *chars = (*env)->GetStringChars(env, jstr, NULL); + if (chars == NULL) { + return NULL; + } + NSString *result = [NSString stringWithCharacters:(UniChar *)chars length:len]; + (*env)->ReleaseStringChars(env, jstr, chars); + return result; +} + +jstring NSStringToJavaString(JNIEnv* env, NSString *str) { + + if (str == NULL) { + return NULL; + } + jstring jStr = (*env)->NewStringUTF(env, [str UTF8String]); + CHECK_EXCEPTION(); + return jStr; +} + +/* + * These next conversion functions are for file system paths. + * The NSString needs to be in de-composed UTF-16 format for the Apple file system + * The Java String needs to be in pre-composed UTF-16 format for display by Java. + * https://developer.apple.com/library/archive/qa/qa1235/_index.html + * has some information on this. + */ + +/* + * Returns an NSString in decomposed UTF16 format that is compatible with HFS's + * expectation of the UTF16 format for file system paths. + * + * Example string: "/Users/Amélie/" + * + * Java's UTF16 string is "/ U s e r s / A m \351 l i e /" + * macOS UTF16 string suitable for HFS is "/ U s e r s / A m e \314 \201 l i e /" + * + * There is no direct API that takes in NSString UTF16 encoded by Java + * and produces NSString UTF16 for HFS, so we first need to decompose it + * into chars (suitable for low level C file APIs), and only then + * create NSString representation of this decomposition back into UTF16 string. + * + * https://developer.apple.com/documentation/foundation/nsstring/1414559-filesystemrepresentation?language=objc + * describes how to get a file system representation as a char* from an NSString + * and then using FileManager (!) convert it to an NSString. + * But we want an NSString. + * So the steps are + * 1) Convert to NSString + * 2) call [NSString fileSystemRepresentation] which gives us a char* + * 3) Convert the returned char* to an NSString using FileManager (is there a better way?) + */ +NSString* NormalizedPathNSStringFromJavaString(JNIEnv *env, jstring pathStr) { + if (pathStr == NULL) { + return nil; + } + NSString *nsStr = JavaStringToNSString(env, pathStr); + if (nsStr == NULL) { + return nil; + } + const char* chs = [nsStr fileSystemRepresentation]; + int len = strlen(chs); + NSString* result = [[NSFileManager defaultManager] + stringWithFileSystemRepresentation:chs length:len]; + return result; +} + +/* + * Given what is (potentially) a de-composed NSString, convert it to pre-composed + * Then convert it into a Java String. + */ +jstring NormalizedPathJavaStringFromNSString(JNIEnv* env, NSString *str) { + if (str == nil) { + return NULL; + } + NSString *normStr = [str precomposedStringWithCanonicalMapping]; + return NSStringToJavaString(env, normStr); +} diff --git a/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.h b/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.h --- a/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.h +++ b/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.h @@ -23,14 +23,8 @@ * questions. */ -/* - * Must include this before JavaNativeFoundation.h to get jni.h from build - */ -#include "jni.h" -#include "jni_util.h" - +#import "JNIUtilities.h" #import -#import @interface NSApplicationAWT : NSApplication { NSString *fApplicationName; diff --git a/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m b/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m --- a/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m +++ b/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m @@ -160,9 +160,6 @@ [super finishLaunching]; [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self]; - - // inform any interested parties that the AWT has arrived and is pumping - [[NSNotificationCenter defaultCenter] postNotificationName:JNFRunLoopDidStartNotification object:self]; } - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center @@ -271,7 +268,7 @@ // HACK BEGIN // The following is necessary to make the java process behave like a // proper foreground application... - [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){ + [ThreadUtilities performOnMainThreadWaiting:NO block:^(){ ProcessSerialNumber psn; GetCurrentProcess(&psn); TransformProcessType(&psn, kProcessTransformToForegroundApplication); @@ -326,8 +323,8 @@ + (void) runAWTLoopWithApp:(NSApplication*)app { NSAutoreleasePool *pool = [NSAutoreleasePool new]; - // Make sure that when we run in AWTRunLoopMode we don't exit randomly - [[NSRunLoop currentRunLoop] addPort:[NSPort port] forMode:[JNFRunLoop javaRunLoopMode]]; + // Make sure that when we run in javaRunLoopMode we don't exit randomly + [[NSRunLoop currentRunLoop] addPort:[NSPort port] forMode:[ThreadUtilities javaRunLoopMode]]; do { @try { diff --git a/src/java.desktop/macosx/native/libosxapp/PropertiesUtilities.h b/src/java.desktop/macosx/native/libosxapp/PropertiesUtilities.h --- a/src/java.desktop/macosx/native/libosxapp/PropertiesUtilities.h +++ b/src/java.desktop/macosx/native/libosxapp/PropertiesUtilities.h @@ -23,8 +23,10 @@ * questions. */ +#include "jni.h" +#include "jni_util.h" + #import -#import @interface PropertiesUtilities : NSObject diff --git a/src/java.desktop/macosx/native/libosxapp/PropertiesUtilities.m b/src/java.desktop/macosx/native/libosxapp/PropertiesUtilities.m --- a/src/java.desktop/macosx/native/libosxapp/PropertiesUtilities.m +++ b/src/java.desktop/macosx/native/libosxapp/PropertiesUtilities.m @@ -33,12 +33,12 @@ DECLARE_STATIC_METHOD_RETURN(jm_getProperty, jc_System, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;", nil); - jstring jKey = JNFNSToJavaString(env, key); + jstring jKey = NSStringToJavaString(env, key); jstring jValue = (*env)->CallStaticObjectMethod(env, jc_System, jm_getProperty, jKey); (*env)->DeleteLocalRef(env, jKey); CHECK_EXCEPTION_NULL_RETURN(jValue, nil); - NSString *value = JNFJavaToNSString(env, jValue); + NSString *value = JavaStringToNSString(env, jValue); (*env)->DeleteLocalRef(env, jValue); return value; } diff --git a/src/java.desktop/macosx/native/libosxapp/ThreadUtilities.h b/src/java.desktop/macosx/native/libosxapp/ThreadUtilities.h --- a/src/java.desktop/macosx/native/libosxapp/ThreadUtilities.h +++ b/src/java.desktop/macosx/native/libosxapp/ThreadUtilities.h @@ -26,6 +26,8 @@ #ifndef __THREADUTILITIES_H #define __THREADUTILITIES_H +#include "jni.h" + #import #import "AWT_debug.h" @@ -123,16 +125,16 @@ // -------------------------------------------------------------------------- __attribute__((visibility("default"))) -@interface ThreadUtilities { } +@interface ThreadUtilities : NSObject { } /* Extend NSObject so can call performSelectorOnMainThread */ + (JNIEnv*)getJNIEnv; + (JNIEnv*)getJNIEnvUncached; + (void)detachCurrentThread; + (void)setAppkitThreadGroup:(jobject)group; -//Wrappers for the corresponding JNFRunLoop methods with a check for main thread + (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block; + (void)performOnMainThread:(SEL)aSelector on:(id)target withObject:(id)arg waitUntilDone:(BOOL)wait; ++ (NSString*)javaRunLoopMode; @end void OSXAPP_SetJavaVM(JavaVM *vm); diff --git a/src/java.desktop/macosx/native/libosxapp/ThreadUtilities.m b/src/java.desktop/macosx/native/libosxapp/ThreadUtilities.m --- a/src/java.desktop/macosx/native/libosxapp/ThreadUtilities.m +++ b/src/java.desktop/macosx/native/libosxapp/ThreadUtilities.m @@ -24,7 +24,6 @@ */ #import -#import #import #import "ThreadUtilities.h" @@ -34,6 +33,8 @@ JavaVM *jvm = NULL; static JNIEnv *appKitEnv = NULL; static jobject appkitThreadGroup = NULL; +static NSString* JavaRunLoopMode = @"javaRunLoopMode"; +static NSArray *javaModes = nil; static inline void attachCurrentThread(void** env) { if ([NSThread isMainThread]) { @@ -49,6 +50,15 @@ @implementation ThreadUtilities ++ (void)initialize { + /* All the standard modes plus ours */ + javaModes = [[NSArray alloc] initWithObjects:NSDefaultRunLoopMode, + NSModalPanelRunLoopMode, + NSEventTrackingRunLoopMode, + JavaRunLoopMode, + nil]; +} + + (JNIEnv*)getJNIEnv { AWT_ASSERT_APPKIT_THREAD; if (appKitEnv == NULL) { @@ -71,11 +81,34 @@ appkitThreadGroup = group; } +/* This is needed because we can't directly pass a block to + * performSelectorOnMainThreadWaiting .. since it expects a selector + */ ++ (void)invokeBlock:(void (^)())block { + block(); +} + +/* + * When running a block where either we don't wait, or it needs to run on another thread + * we need to copy it from stack to heap, use the copy in the call and release after use. + * Do this only when we must because it could be expensive. + * Note : if waiting cross-thread, possibly the stack allocated copy is accessible ? + */ ++ (void)invokeBlockCopy:(void (^)(void))blockCopy { + blockCopy(); + Block_release(blockCopy); +} + + (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block { if ([NSThread isMainThread] && wait == YES) { block(); } else { - [JNFRunLoop performOnMainThreadWaiting:wait withBlock:block]; + if (wait == YES) { + [self performOnMainThread:@selector(invokeBlock:) on:self withObject:block waitUntilDone:YES]; + } else { + void (^blockCopy)(void) = Block_copy(block); + [self performOnMainThread:@selector(invokeBlockCopy:) on:self withObject:blockCopy waitUntilDone:NO]; + } } } @@ -83,10 +116,14 @@ if ([NSThread isMainThread] && wait == YES) { [target performSelector:aSelector withObject:arg]; } else { - [JNFRunLoop performOnMainThread:aSelector on:target withObject:arg waitUntilDone:wait]; + [target performSelectorOnMainThread:aSelector withObject:arg waitUntilDone:wait modes:javaModes]; } } ++ (NSString*)javaRunLoopMode { + return JavaRunLoopMode; +} + @end diff --git a/src/java.desktop/macosx/native/libosxui/AquaFileView.m b/src/java.desktop/macosx/native/libosxui/AquaFileView.m --- a/src/java.desktop/macosx/native/libosxui/AquaFileView.m +++ b/src/java.desktop/macosx/native/libosxui/AquaFileView.m @@ -30,7 +30,6 @@ #import // for MAXPATHLEN #import -#import /* * Class: com_apple_laf_AquaFileView @@ -44,7 +43,7 @@ jstring returnValue = NULL; JNI_COCOA_ENTER(env); - returnValue = JNFNSToJavaString(env, getRunningJavaBundle()); + returnValue = NSStringToJavaString(env, getRunningJavaBundle()); JNI_COCOA_EXIT(env); return returnValue; @@ -61,7 +60,7 @@ jstring returnValue = NULL; JNI_COCOA_ENTER(env); - returnValue = JNFNSToJavaString(env, [[NSBundle bundleWithIdentifier:@"com.apple.JavaVM"] bundlePath]); + returnValue = NSStringToJavaString(env, [[NSBundle bundleWithIdentifier:@"com.apple.JavaVM"] bundlePath]); JNI_COCOA_EXIT(env); return returnValue; @@ -79,7 +78,7 @@ JNI_COCOA_ENTER(env); CFStringRef machineName = CSCopyMachineName(); - returnValue = JNFNSToJavaString(env, (NSString*)machineName); + returnValue = NSStringToJavaString(env, (NSString*)machineName); if (machineName != NULL) { CFRelease(machineName); @@ -169,7 +168,7 @@ if (theErr == noErr) { CFMutableStringRef mutableDisplayName = CFStringCreateMutableCopy(NULL, 0, displayName); CFStringNormalize(mutableDisplayName, kCFStringNormalizationFormC); - returnValue = JNFNSToJavaString(env, (NSString *)mutableDisplayName); + returnValue = NSStringToJavaString(env, (NSString *)mutableDisplayName); CFRelease(mutableDisplayName); } diff --git a/src/java.desktop/macosx/native/libosxui/AquaLookAndFeel.m b/src/java.desktop/macosx/native/libosxui/AquaLookAndFeel.m --- a/src/java.desktop/macosx/native/libosxui/AquaLookAndFeel.m +++ b/src/java.desktop/macosx/native/libosxui/AquaLookAndFeel.m @@ -23,12 +23,9 @@ * questions. */ -// Must include this before JavaNativeFoundation.h to get jni.h from build #include "jni.h" #include "jni_util.h" -#import - /* * Empty JNI_OnLoad - needed to prevent: * AWT's JNI_OnLoad called multiple times diff --git a/src/java.desktop/macosx/native/libosxui/AquaNativeResources.m b/src/java.desktop/macosx/native/libosxui/AquaNativeResources.m --- a/src/java.desktop/macosx/native/libosxui/AquaNativeResources.m +++ b/src/java.desktop/macosx/native/libosxui/AquaNativeResources.m @@ -26,7 +26,6 @@ #import "com_apple_laf_AquaNativeResources.h" #import -#import /* * Class: com_apple_laf_AquaNativeResources diff --git a/src/java.desktop/macosx/native/libosxui/JRSUIConstantSync.m b/src/java.desktop/macosx/native/libosxui/JRSUIConstantSync.m --- a/src/java.desktop/macosx/native/libosxui/JRSUIConstantSync.m +++ b/src/java.desktop/macosx/native/libosxui/JRSUIConstantSync.m @@ -23,7 +23,7 @@ * questions. */ -#import +#import "JNIUtilities.h" #import #import "apple_laf_JRSUIConstants.h" diff --git a/src/java.desktop/macosx/native/libosxui/JRSUIController.m b/src/java.desktop/macosx/native/libosxui/JRSUIController.m --- a/src/java.desktop/macosx/native/libosxui/JRSUIController.m +++ b/src/java.desktop/macosx/native/libosxui/JRSUIController.m @@ -23,7 +23,7 @@ * questions. */ -#import +#import "JNIUtilities.h" #import #import "apple_laf_JRSUIControl.h" diff --git a/src/java.desktop/macosx/native/libosxui/JRSUIFocus.m b/src/java.desktop/macosx/native/libosxui/JRSUIFocus.m --- a/src/java.desktop/macosx/native/libosxui/JRSUIFocus.m +++ b/src/java.desktop/macosx/native/libosxui/JRSUIFocus.m @@ -23,7 +23,7 @@ * questions. */ -#import +#import "JNIUtilities.h" #import "apple_laf_JRSUIFocus.h" #import "apple_laf_JRSUIControl.h" diff --git a/src/java.desktop/macosx/native/libosxui/ScreenMenu.h b/src/java.desktop/macosx/native/libosxui/ScreenMenu.h --- a/src/java.desktop/macosx/native/libosxui/ScreenMenu.h +++ b/src/java.desktop/macosx/native/libosxui/ScreenMenu.h @@ -25,4 +25,3 @@ #import #import -#import diff --git a/src/java.desktop/macosx/native/libosxui/ScreenMenu.m b/src/java.desktop/macosx/native/libosxui/ScreenMenu.m --- a/src/java.desktop/macosx/native/libosxui/ScreenMenu.m +++ b/src/java.desktop/macosx/native/libosxui/ScreenMenu.m @@ -31,7 +31,6 @@ #import "java_awt_event_InputEvent.h" #import "java_awt_event_MouseEvent.h" -#import #import #import "ThreadUtilities.h" @@ -109,7 +108,7 @@ //NSLog(@"menuWillOpen %@", [menu title]); GET_SCREENMENU_CLASS(); DECLARE_METHOD(jm_ScreenMenu_invokeOpenLater, sjc_ScreenMenu, "invokeOpenLater", "()V"); - (*env)->CallVoidMethod(env, self.javaObject, jm_ScreenMenu_invokeOpenLater); // AWT_THREADING Safe (AWTRunLoopMode) + (*env)->CallVoidMethod(env, self.javaObject, jm_ScreenMenu_invokeOpenLater); CHECK_EXCEPTION(); JNI_COCOA_EXIT(env); @@ -129,7 +128,7 @@ //NSLog(@"menuDidClose %@", [menu title]); GET_SCREENMENU_CLASS(); DECLARE_METHOD(jm_ScreenMenu_invokeMenuClosing, sjc_ScreenMenu, "invokeMenuClosing", "()V"); - (*env)->CallVoidMethod(env, self.javaObject, jm_ScreenMenu_invokeMenuClosing); // AWT_THREADING Safe (AWTRunLoopMode) + (*env)->CallVoidMethod(env, self.javaObject, jm_ScreenMenu_invokeMenuClosing); CHECK_EXCEPTION(); JNI_COCOA_EXIT(env); } @@ -150,12 +149,22 @@ GET_SCREENMENU_CLASS(); DECLARE_METHOD(jm_ScreenMenu_updateSelectedItem, sjc_ScreenMenu, "handleItemTargeted", "(IIIII)V"); (*env)->CallVoidMethod(env, self.javaObject, jm_ScreenMenu_updateSelectedItem, menuIndex, - NSMinY(rect), NSMinX(rect), NSMaxY(rect), NSMaxX(rect)); // AWT_THREADING Safe (AWTRunLoopMode) + NSMinY(rect), NSMinX(rect), NSMaxY(rect), NSMaxX(rect)); CHECK_EXCEPTION(); JNI_COCOA_EXIT(env); } +/* + * The input is an NSTimeInterval (a double representing seconds and fractions of seconds) + * 0.0 means midnight Jan 1, 2001. + * The output is a Java long representing time in milliseconds since midnight Jan 1st 1970. + * There is a Cocoa constant representing that difference : NSTimeIntervalSince1970 + */ +static jlong NSTimeIntervalToJavaMilliseconds(NSTimeInterval interval) { + NSTimeInterval interval1970 = interval + NSTimeIntervalSince1970; + return (jlong)(interval1970 * 1000); +} // Called from event handler callback - (void)handleJavaMouseEvent:(NSEvent *)event @@ -187,7 +196,7 @@ jint javaModifiers = ns2awtModifiers([event modifierFlags]) | ns2awtMouseButton([event buttonNumber]); // Get the event time - jlong javaWhen = JNFNSTimeIntervalToJavaMillis([event timestamp]); + jlong javaWhen = NSTimeIntervalToJavaMilliseconds([event timestamp]); // Call the mouse event handler, which will generate Java mouse events. JNIEnv *env = [ThreadUtilities getJNIEnv]; @@ -195,7 +204,7 @@ GET_SCREENMENU_CLASS(); DECLARE_METHOD(jm_ScreenMenu_handleMouseEvent, sjc_ScreenMenu, "handleMouseEvent", "(IIIIJ)V"); (*env)->CallVoidMethod(env, self.javaObject, jm_ScreenMenu_handleMouseEvent, - javaKind, javaX, javaY, javaModifiers, javaWhen); // AWT_THREADING Safe (AWTRunLoopMode) + javaKind, javaX, javaY, javaModifiers, javaWhen); CHECK_EXCEPTION(); JNI_COCOA_EXIT(env); } @@ -221,7 +230,7 @@ delegate = [[[NativeToJavaDelegate alloc] initFromMenu:menu javaObj:listenerRef] autorelease]; CFRetain(delegate); // GC - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^{ + [ThreadUtilities performOnMainThreadWaiting:YES block:^{ NSMenu *menu = delegate.nsmenu; if ([menu isJavaMenu]) { [menu setDelegate:delegate]; @@ -248,7 +257,7 @@ NativeToJavaDelegate *delegate = (NativeToJavaDelegate *)jlong_to_ptr(fModelPtr); - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^{ + [ThreadUtilities performOnMainThreadWaiting:YES block:^{ NSMenu *menu = delegate.nsmenu; [menu setJavaMenuDelegate:nil]; [menu setDelegate:nil]; diff --git a/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m b/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m --- a/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m +++ b/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m @@ -28,7 +28,6 @@ #import #import -#import #import "NSApplicationAWT.h" #include @@ -202,7 +201,7 @@ // If we are running SWT we should not start a runLoop if (!isSWTRunning()) { - [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() { + [ThreadUtilities performOnMainThreadWaiting:NO block:^() { [NSApplicationAWT runAWTLoopWithApp:[NSApplicationAWT sharedApplication]]; }]; } @@ -218,7 +217,7 @@ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; pthread_mutex_destroy(&splash->lock); - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ if (splash->window) { [splash->window orderOut:nil]; [splash->window release]; @@ -257,7 +256,7 @@ SplashRedrawWindow(Splash * splash) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ // drop the reference to the old view and image [splash->window setContentView: nil]; SplashUpdateScreenData(splash); @@ -316,7 +315,7 @@ void SplashReconfigureNow(Splash * splash) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ SplashCenter(splash); if (!splash->window) { @@ -405,7 +404,7 @@ fcntl(splash->controlpipe[0], F_GETFL, 0) | O_NONBLOCK); splash->time = SplashTime(); splash->currentFrame = 0; - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ SplashCenter(splash); splash->window = (void*) [[NSWindow alloc] @@ -420,7 +419,7 @@ }]; fflush(stdout); if (splash->window) { - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ + [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ [splash->window orderFrontRegardless]; }]; SplashRedrawWindow(splash); diff --git a/test/jdk/java/awt/Window/MainKeyWindowTest/libTestMainKeyWindow.m b/test/jdk/java/awt/Window/MainKeyWindowTest/libTestMainKeyWindow.m --- a/test/jdk/java/awt/Window/MainKeyWindowTest/libTestMainKeyWindow.m +++ b/test/jdk/java/awt/Window/MainKeyWindowTest/libTestMainKeyWindow.m @@ -24,11 +24,45 @@ */ #import -#import +#import static NSWindow *testWindow; static NSColorPanel *colorPanel; +#define JNI_COCOA_ENTER(env) \ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \ + @try { + +#define JNI_COCOA_EXIT(env) \ + } \ + @catch (NSException *e) { \ + NSLog(@"%@", [e callStackSymbols]); \ + } \ + @finally { \ + [pool drain]; \ + }; + +/* + * Pass the block to a selector of a class that extends NSObject + * There is no need to copy the block since this class always waits. + */ +@interface BlockRunner : NSObject { } + ++ (void)invokeBlock:(void (^)())block; +@end + +@implementation BlockRunner + ++ (void)invokeBlock:(void (^)())block{ + block(); +} + ++ (void)performBlock:(void (^)())block { + [self performSelectorOnMainThread:@selector(invokeBlock:) withObject:block waitUntilDone:YES]; +} + +@end + /* * Class: TestMainKeyWindow * Method: setup @@ -36,7 +70,7 @@ */ JNIEXPORT void JNICALL Java_TestMainKeyWindow_setup(JNIEnv *env, jclass cl) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); void (^block)() = ^(){ NSScreen *mainScreen = [NSScreen mainScreen]; @@ -68,10 +102,10 @@ if ([NSThread isMainThread]) { block(); } else { - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:block]; + [BlockRunner performBlock:block]; } - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -81,7 +115,7 @@ */ JNIEXPORT void JNICALL Java_TestMainKeyWindow_takedown(JNIEnv *env, jclass cl) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); void (^block)() = ^(){ if (testWindow != nil) { @@ -97,10 +131,10 @@ if ([NSThread isMainThread]) { block(); } else { - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:block]; + [BlockRunner performBlock:block]; } - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /* @@ -111,13 +145,13 @@ JNIEXPORT void JNICALL Java_TestMainKeyWindow_activateApplication (JNIEnv *env, jclass cl) { - JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); void (^block)() = ^(){ [NSApp activateIgnoringOtherApps:YES]; }; - [JNFRunLoop performOnMainThreadWaiting:YES withBlock:block]; + [BlockRunner performBlock:block]; - JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } # HG changeset patch # User vkempik # Date 1617887445 0 # Thu Apr 08 13:10:45 2021 +0000 # Node ID 792b3f081f29a2f92a71c7d49a32456e5bae9f26 # Parent c34af45c562e97cf261bb452177693724d252bd1 8257988: Remove JNF dependency from libsaproc/MacosxDebuggerLocal.m Reviewed-by: yan diff --git a/make/lib/Lib-jdk.hotspot.agent.gmk b/make/lib/Lib-jdk.hotspot.agent.gmk --- a/make/lib/Lib-jdk.hotspot.agent.gmk +++ b/make/lib/Lib-jdk.hotspot.agent.gmk @@ -67,7 +67,7 @@ LDFLAGS := $(LDFLAGS_JDKLIB) $(SA_LDFLAGS), \ LIBS_linux := -lthread_db $(LIBDL), \ LIBS_solaris := -ldl -ldemangle -lthread -lproc, \ - LIBS_macosx := -framework Foundation -framework JavaNativeFoundation \ + LIBS_macosx := -framework Foundation \ -framework JavaRuntimeSupport -framework Security -framework CoreFoundation, \ LIBS_windows := dbgeng.lib, \ )) diff --git a/src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m b/src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m --- a/src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m +++ b/src/jdk.hotspot.agent/macosx/native/libsaproc/MacosxDebuggerLocal.m @@ -24,8 +24,6 @@ #include #import -#import -#import #include @@ -260,6 +258,39 @@ return addr; } +/* Create a pool and initiate a try block to catch any exception */ +#define JNI_COCOA_ENTER(env) \ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; \ + @try { + +/* Don't allow NSExceptions to escape to Java. + * If there is a Java exception that has been thrown that should escape. + * And ensure we drain the auto-release pool. + */ +#define JNI_COCOA_EXIT(env) \ + } \ + @catch (NSException *e) { \ + NSLog(@"%@", [e callStackSymbols]); \ + } \ + @finally { \ + [pool drain]; \ + }; + +static NSString* JavaStringToNSString(JNIEnv *env, jstring jstr) { + + if (jstr == NULL) { + return NULL; + } + jsize len = (*env)->GetStringLength(env, jstr); + const jchar *chars = (*env)->GetStringChars(env, jstr, NULL); + if (chars == NULL) { + return NULL; + } + NSString *result = [NSString stringWithCharacters:(UniChar *)chars length:len]; + (*env)->ReleaseStringChars(env, jstr, chars); + return result; +} + /* * Class: sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal * Method: lookupByName0 @@ -277,8 +308,9 @@ jlong address = 0; -JNF_COCOA_ENTER(env); - NSString *symbolNameString = JNFJavaToNSString(env, symbolName); + JNI_COCOA_ENTER(env); + + NSString *symbolNameString = JavaStringToNSString(env, symbolName); print_debug("lookupInProcess called for %s\n", [symbolNameString UTF8String]); @@ -289,7 +321,7 @@ } print_debug("address of symbol %s = %llx\n", [symbolNameString UTF8String], address); -JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); return address; } @@ -805,7 +837,7 @@ { print_debug("attach0 called for jpid=%d\n", (int)jpid); -JNF_COCOA_ENTER(env); + JNI_COCOA_ENTER(env); kern_return_t result; task_t gTask = 0; @@ -919,7 +951,7 @@ THROW_NEW_DEBUGGER_EXCEPTION("Can't attach symbolicator to the process"); } -JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } /** For core file, @@ -1013,7 +1045,8 @@ Prelease(ph); return; } -JNF_COCOA_ENTER(env); + + JNI_COCOA_ENTER(env); task_t gTask = getTask(env, this_obj); kern_return_t k_res = 0; @@ -1064,5 +1097,5 @@ detach_cleanup(gTask, env, this_obj, false); -JNF_COCOA_EXIT(env); + JNI_COCOA_EXIT(env); } # HG changeset patch # User prr # Date 1609954455 0 # Wed Jan 06 17:34:15 2021 +0000 # Node ID aac3931683ae2d02f42f2e931116661ed0447022 # Parent 792b3f081f29a2f92a71c7d49a32456e5bae9f26 8259232: Bad JNI lookup during printing Reviewed-by: psadhukhan diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m @@ -57,7 +57,7 @@ #define GET_CPRINTERDIALOG_FIELD_RETURN(ret) \ GET_CPRINTERDIALOG_CLASS_RETURN(ret); \ - GET_METHOD_RETURN(sjm_printerJob, sjc_CPrinterDialog, "fPrinterJob", "Lsun/lwawt/macosx/CPrinterJob;", ret); + GET_FIELD_RETURN(sjm_printerJob, sjc_CPrinterDialog, "fPrinterJob", "Lsun/lwawt/macosx/CPrinterJob;", ret); static NSPrintInfo* createDefaultNSPrintInfo(); diff --git a/test/jdk/java/awt/print/bug8023392/bug8023392.java b/test/jdk/java/awt/print/bug8023392/bug8023392.java --- a/test/jdk/java/awt/print/bug8023392/bug8023392.java +++ b/test/jdk/java/awt/print/bug8023392/bug8023392.java @@ -23,7 +23,7 @@ /* test - @bug 8023392 + @bug 8023392 8259232 @summary Swing text components printed with spaces between chars @author Anton Nashatyrev @run applet/manual=yesno bug8023392.html # HG changeset patch # User kizune # Date 1610411302 0 # Tue Jan 12 00:28:22 2021 +0000 # Node ID 242d26b69648f29ec2748251cc6e50972db33d43 # Parent aac3931683ae2d02f42f2e931116661ed0447022 8259585: Accessible actions do not work on mac os x Reviewed-by: serb diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -62,7 +62,8 @@ { JNIEnv* env = [ThreadUtilities getJNIEnv]; DECLARE_CLASS_RETURN(sjc_CAccessibility, "sun/lwawt/macosx/CAccessibility", nil); - DECLARE_METHOD_RETURN(jm_getAccessibleActionDescription, sjc_CAccessibility, "getAccessibleActionDescription", + DECLARE_STATIC_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 */ @@ -95,7 +96,7 @@ { JNIEnv* env = [ThreadUtilities getJNIEnv]; DECLARE_CLASS(sjc_CAccessibility, "sun/lwawt/macosx/CAccessibility"); - DECLARE_METHOD(jm_doAccessibleAction, sjc_CAccessibility, "doAccessibleAction", + DECLARE_STATIC_METHOD(jm_doAccessibleAction, sjc_CAccessibility, "doAccessibleAction", "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)V"); (*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_doAccessibleAction, # HG changeset patch # User prr # Date 1612552750 0 # Fri Feb 05 19:19:10 2021 +0000 # Node ID 0b6a4eb3e56b840c80bf21f39e15cd1ea49369a2 # Parent 242d26b69648f29ec2748251cc6e50972db33d43 8261198: [macOS] Incorrect JNI parameters in number conversion in A11Y code Reviewed-by: serb, psadhukhan diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m @@ -943,14 +943,14 @@ } DECLARE_CLASS_RETURN(jnumber_Class, "java/lang/Number", nil); DECLARE_CLASS_RETURN(jinteger_Class, "java/lang/Integer", nil); - DECLARE_METHOD_RETURN(jm_intValue, jnumber_Class, "intValue", "()D", nil); + DECLARE_METHOD_RETURN(jm_intValue, jnumber_Class, "intValue", "()I", nil); DECLARE_METHOD_RETURN(jm_doubleValue, jnumber_Class, "doubleValue", "()D", nil); if ((*env)->IsInstanceOf(env, jnumber, jinteger_Class)) { - jint i = (*env)->CallIntMethod(env, jnumber_Class, jm_intValue); + jint i = (*env)->CallIntMethod(env, jnumber, jm_intValue); CHECK_EXCEPTION(); return [NSNumber numberWithInteger:i]; } else { - jdouble d = (*env)->CallDoubleMethod(env, jnumber_Class, jm_doubleValue); + jdouble d = (*env)->CallDoubleMethod(env, jnumber, jm_doubleValue); CHECK_EXCEPTION(); return [NSNumber numberWithDouble:d]; } # HG changeset patch # User kizune # Date 1616263108 0 # Sat Mar 20 17:58:28 2021 +0000 # Node ID ee85b62ef6ddfd27cf0f2cfd3024ab936110cd4e # Parent 0b6a4eb3e56b840c80bf21f39e15cd1ea49369a2 8263846: Bad JNI lookup getFocusOwner in accessibility code on Mac OS X Reviewed-by: azvegint, prr diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m @@ -1467,6 +1467,7 @@ - (id)accessibilityFocusedUIElement { JNIEnv *env = [ThreadUtilities getJNIEnv]; + GET_CACCESSIBILITY_CLASS_RETURN(nil); DECLARE_STATIC_METHOD_RETURN(jm_getFocusOwner, sjc_CAccessibility, "getFocusOwner", "(Ljava/awt/Component;)Ljavax/accessibility/Accessible;", nil); id value = nil;