diff --git a/make/common/MakeBase.gmk b/make/common/MakeBase.gmk index 9790a76540c..6a384bca8ef 100644 --- a/make/common/MakeBase.gmk +++ b/make/common/MakeBase.gmk @@ -529,7 +529,7 @@ else ifeq ($(OPENJDK_TARGET_OS),macosx) $(call MakeDir, $(@D)) $(RM) '$(call DecodeSpace, $@)' $(CP) -fRP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)' - if [ -n "`$(XATTR) -l '$(call DecodeSpace, $@)'`" ]; then $(XATTR) -c '$(call DecodeSpace, $@)'; fi + if [ -n "`$(XATTR) -ls '$(call DecodeSpace, $@)'`" ]; then $(XATTR) -cs '$(call DecodeSpace, $@)'; fi endef else define install-file diff --git a/make/mapfiles/libjava/mapfile-vers b/make/mapfiles/libjava/mapfile-vers index 1a8d712c7b8..d2c82345060 100644 --- a/make/mapfiles/libjava/mapfile-vers +++ b/make/mapfiles/libjava/mapfile-vers @@ -130,8 +130,8 @@ SUNWprivate_1.1 { Java_java_lang_ClassLoader_defineClass2; Java_java_lang_ClassLoader_findBuiltinLib; Java_java_lang_ClassLoader_findLoadedClass0; - Java_java_lang_ClassLoader_00024NativeLibrary_find; - Java_java_lang_ClassLoader_00024NativeLibrary_load; + Java_java_lang_ClassLoader_00024NativeLibrary_findEntry; + Java_java_lang_ClassLoader_00024NativeLibrary_load0; Java_java_lang_ClassLoader_00024NativeLibrary_unload; Java_java_lang_ClassLoader_registerNatives; Java_java_lang_Double_longBitsToDouble; diff --git a/make/mapfiles/libjava/reorder-sparc b/make/mapfiles/libjava/reorder-sparc index da91bfb6f68..990ca32b6fb 100644 --- a/make/mapfiles/libjava/reorder-sparc +++ b/make/mapfiles/libjava/reorder-sparc @@ -48,8 +48,8 @@ text: .text%Java_java_io_FileInputStream_available0; text: .text%Java_java_io_FileInputStream_close0; text: .text%Java_java_lang_System_mapLibraryName; text: .text%Java_java_io_UnixFileSystem_getBooleanAttributes0; -text: .text%Java_java_lang_ClassLoader_00024NativeLibrary_load; -text: .text%Java_java_lang_ClassLoader_00024NativeLibrary_find; +text: .text%Java_java_lang_ClassLoader_00024NativeLibrary_load0; +text: .text%Java_java_lang_ClassLoader_00024NativeLibrary_findEntry; text: .text%Java_java_security_AccessController_doPrivileged__Ljava_security_PrivilegedExceptionAction_2; text: .text%Java_java_io_UnixFileSystem_list; text: .text%JNU_ClassString; diff --git a/make/mapfiles/libjava/reorder-sparcv9 b/make/mapfiles/libjava/reorder-sparcv9 index aa605871ecc..4e3ce84b862 100644 --- a/make/mapfiles/libjava/reorder-sparcv9 +++ b/make/mapfiles/libjava/reorder-sparcv9 @@ -57,8 +57,8 @@ text: .text%JNU_CopyObjectArray; text: .text%Java_java_io_UnixFileSystem_getBooleanAttributes0; text: .text%Java_java_security_AccessController_doPrivileged__Ljava_security_PrivilegedExceptionAction_2Ljava_security_AccessControlContext_2; text: .text%Java_java_lang_System_mapLibraryName; -text: .text%Java_java_lang_ClassLoader_00024NativeLibrary_load; -text: .text%Java_java_lang_ClassLoader_00024NativeLibrary_find; +text: .text%Java_java_lang_ClassLoader_00024NativeLibrary_load0; +text: .text%Java_java_lang_ClassLoader_00024NativeLibrary_findEntry; text: .text%Java_java_io_UnixFileSystem_getLength; text: .text%Java_java_lang_Object_getClass; text: .text%Java_java_lang_ClassLoader_defineClass0; diff --git a/make/mapfiles/libjava/reorder-x86 b/make/mapfiles/libjava/reorder-x86 index 46948fc4ada..de28893a4d2 100644 --- a/make/mapfiles/libjava/reorder-x86 +++ b/make/mapfiles/libjava/reorder-x86 @@ -50,8 +50,8 @@ text: .text%Java_java_lang_ClassLoader_findBootstrapClass; text: .text%Java_java_security_AccessController_doPrivileged__Ljava_security_PrivilegedExceptionAction_2Ljava_security_AccessControlContext_2; text: .text%Java_java_lang_System_mapLibraryName; text: .text%cpchars: OUTPUTDIR/System.o; -text: .text%Java_java_lang_ClassLoader_00024NativeLibrary_load; -text: .text%Java_java_lang_ClassLoader_00024NativeLibrary_find; +text: .text%Java_java_lang_ClassLoader_00024NativeLibrary_load0; +text: .text%Java_java_lang_ClassLoader_00024NativeLibrary_findEntry; text: .text%Java_java_lang_Float_floatToRawIntBits; text: .text%Java_java_lang_Double_doubleToRawLongBits; text: .text%Java_java_io_FileInputStream_open0; diff --git a/make/test/JtregNativeJdk.gmk b/make/test/JtregNativeJdk.gmk index 5d0b14d16c1..3e8d3af1d4e 100644 --- a/make/test/JtregNativeJdk.gmk +++ b/make/test/JtregNativeJdk.gmk @@ -44,6 +44,7 @@ $(eval $(call IncludeCustomExtension, test/JtregNativeJdk.gmk)) # Add more directories here when needed. BUILD_JDK_JTREG_NATIVE_SRC += \ $(TOPDIR)/test/jdk/native_sanity \ + $(TOPDIR)/test/jdk/java/lang/ClassLoader/nativeLibrary \ $(TOPDIR)/test/jdk/java/lang/String/nativeEncoding \ # diff --git a/src/java.base/share/classes/java/lang/ClassLoader.java b/src/java.base/share/classes/java/lang/ClassLoader.java index 9a60f55ea48..b91b4619be6 100644 --- a/src/java.base/share/classes/java/lang/ClassLoader.java +++ b/src/java.base/share/classes/java/lang/ClassLoader.java @@ -37,17 +37,20 @@ import java.security.CodeSource; import java.security.PrivilegedAction; import java.security.ProtectionDomain; import java.security.cert.Certificate; +import java.util.Arrays; import java.util.Collections; +import java.util.Deque; import java.util.Enumeration; import java.util.HashMap; +import java.util.HashSet; import java.util.Hashtable; +import java.util.LinkedList; import java.util.Map; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Set; import java.util.Spliterator; import java.util.Spliterators; -import java.util.Stack; import java.util.Vector; import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; @@ -58,9 +61,9 @@ import java.util.stream.StreamSupport; import jdk.internal.perf.PerfCounter; import jdk.internal.loader.BootLoader; import jdk.internal.loader.ClassLoaders; -import jdk.internal.misc.SharedSecrets; import jdk.internal.misc.Unsafe; import jdk.internal.misc.VM; +import jdk.internal.ref.CleanerFactory; import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.Reflection; import sun.reflect.misc.ReflectUtil; @@ -2375,75 +2378,161 @@ public abstract class ClassLoader { * @since 1.2 */ static class NativeLibrary { + // the class from which the library is loaded, also indicates + // the loader this native library belongs. + final Class fromClass; + // the canonicalized name of the native library. + // or static library name + final String name; + // Indicates if the native library is linked into the VM + final boolean isBuiltin; + // opaque handle to native library, used in native code. long handle; // the version of JNI environment the native library requires. - private int jniVersion; - // the class from which the library is loaded, also indicates - // the loader this native library belongs. - private Class fromClass; - // the canonicalized name of the native library. - // or static library name - String name; - // Indicates if the native library is linked into the VM - boolean isBuiltin; - // Indicates if the native library is loaded - boolean loaded; - native void load(String name, boolean isBuiltin); + int jniVersion; - native long find(String name); - native void unload(String name, boolean isBuiltin); + native boolean load0(String name, boolean isBuiltin); - public NativeLibrary(Class fromClass, String name, boolean isBuiltin) { + native long findEntry(String name); + + NativeLibrary(Class fromClass, String name, boolean isBuiltin) { this.name = name; this.fromClass = fromClass; this.isBuiltin = isBuiltin; } - @SuppressWarnings("deprecation") - protected void finalize() { - synchronized (loadedLibraryNames) { - if (fromClass.getClassLoader() != null && loaded) { - this.fromClass = null; // no context when unloaded + /* + * Loads the native library and registers for cleanup when its + * associated class loader is unloaded + */ + boolean load() { + if (handle != 0) { + throw new InternalError("Native library " + name + " has been loaded"); + } - /* remove the native library name */ - int size = loadedLibraryNames.size(); - for (int i = 0; i < size; i++) { - if (name.equals(loadedLibraryNames.elementAt(i))) { - loadedLibraryNames.removeElementAt(i); - break; + if (!load0(name, isBuiltin)) return false; + + // register the class loader for cleanup when unloaded + // built class loaders are never unloaded + ClassLoader loader = fromClass.getClassLoader(); + if (loader != null && + loader != getBuiltinPlatformClassLoader() && + loader != getBuiltinAppClassLoader()) { + CleanerFactory.cleaner().register(loader, + new Unloader(name, handle, isBuiltin)); + } + return true; + } + + static boolean loadLibrary(Class fromClass, String name, boolean isBuiltin) { + ClassLoader loader = + fromClass == null ? null : fromClass.getClassLoader(); + + synchronized (loadedLibraryNames) { + Map libs = + loader != null ? loader.nativeLibraries() : systemNativeLibraries(); + if (libs.containsKey(name)) { + return true; + } + + if (loadedLibraryNames.contains(name)) { + throw new UnsatisfiedLinkError("Native Library " + name + + " already loaded in another classloader"); + } + + /* + * When a library is being loaded, JNI_OnLoad function can cause + * another loadLibrary invocation that should succeed. + * + * We use a static stack to hold the list of libraries we are + * loading because this can happen only when called by the + * same thread because Runtime.load and Runtime.loadLibrary + * are synchronous. + * + * If there is a pending load operation for the library, we + * immediately return success; otherwise, we raise + * UnsatisfiedLinkError. + */ + for (NativeLibrary lib : nativeLibraryContext) { + if (name.equals(lib.name)) { + if (loader == lib.fromClass.getClassLoader()) { + return true; + } else { + throw new UnsatisfiedLinkError("Native Library " + + name + " is being loaded in another classloader"); } } - /* unload the library. */ - ClassLoader.nativeLibraryContext.push(this); + } + NativeLibrary lib = new NativeLibrary(fromClass, name, isBuiltin); + // load the native library + nativeLibraryContext.push(lib); + try { + if (!lib.load()) return false; + } finally { + nativeLibraryContext.pop(); + } + // register the loaded native library + loadedLibraryNames.add(name); + libs.put(name, lib); + } + return true; + } + + // Invoked in the VM to determine the context class in JNI_OnLoad + // and JNI_OnUnload + static Class getFromClass() { + return nativeLibraryContext.peek().fromClass; + } + + // native libraries being loaded + static Deque nativeLibraryContext = new LinkedList<>(); + + /* + * The run() method will be invoked when this class loader becomes + * phantom reachable to unload the native library. + */ + static class Unloader implements Runnable { + // This represents the context when a native library is unloaded + // and getFromClass() will return null, + static final NativeLibrary UNLOADER = + new NativeLibrary(null, "dummy", false); + final String name; + final long handle; + final boolean isBuiltin; + + Unloader(String name, long handle, boolean isBuiltin) { + if (handle == 0) { + throw new IllegalArgumentException( + "Invalid handle for native library " + name); + } + + this.name = name; + this.handle = handle; + this.isBuiltin = isBuiltin; + } + + @Override + public void run() { + synchronized (loadedLibraryNames) { + /* remove the native library name */ + loadedLibraryNames.remove(name); + nativeLibraryContext.push(UNLOADER); try { - unload(name, isBuiltin); + unload(name, isBuiltin, handle); } finally { - ClassLoader.nativeLibraryContext.pop(); + nativeLibraryContext.pop(); } + } } } - // Invoked in the VM to determine the context class in - // JNI_Load/JNI_Unload - static Class getFromClass() { - return ClassLoader.nativeLibraryContext.peek().fromClass; - } + + // JNI FindClass expects the caller class if invoked from JNI_OnLoad + // and JNI_OnUnload is NativeLibrary class + static native void unload(String name, boolean isBuiltin, long handle); } - // All native library names we've loaded. - private static Vector loadedLibraryNames = new Vector<>(); - - // Native libraries belonging to system classes. - private static Vector systemNativeLibraries - = new Vector<>(); - - // Native libraries associated with the class loader. - private Vector nativeLibraries = new Vector<>(); - - // native libraries being loaded/unloaded. - private static Stack nativeLibraryContext = new Stack<>(); - // The paths searched for libraries private static String usr_paths[]; private static String sys_paths[]; @@ -2455,7 +2544,7 @@ public abstract class ClassLoader { int psCount = 0; if (ClassLoaderHelper.allowsQuotedPathElements && - ldPath.indexOf('\"') >= 0) { + ldPath.indexOf('\"') >= 0) { // First, remove quotes put around quoted parts of paths. // Second, use a quotation mark as a new path separator. // This will preserve any quoted old path separators. @@ -2465,7 +2554,7 @@ public abstract class ClassLoader { char ch = ldPath.charAt(i); if (ch == '\"') { while (++i < ldLen && - (ch = ldPath.charAt(i)) != '\"') { + (ch = ldPath.charAt(i)) != '\"') { buf[bufLen++] = ch; } } else { @@ -2481,7 +2570,7 @@ public abstract class ClassLoader { ps = '\"'; } else { for (int i = ldPath.indexOf(ps); i >= 0; - i = ldPath.indexOf(ps, i + 1)) { + i = ldPath.indexOf(ps, i + 1)) { psCount++; } } @@ -2491,11 +2580,11 @@ public abstract class ClassLoader { for (int j = 0; j < psCount; ++j) { int pathEnd = ldPath.indexOf(ps, pathStart); paths[j] = (pathStart < pathEnd) ? - ldPath.substring(pathStart, pathEnd) : "."; + ldPath.substring(pathStart, pathEnd) : "."; pathStart = pathEnd + 1; } paths[psCount] = (pathStart < ldLen) ? - ldPath.substring(pathStart, ldLen) : "."; + ldPath.substring(pathStart, ldLen) : "."; return paths; } @@ -2520,7 +2609,7 @@ public abstract class ClassLoader { File libfile = new File(libfilename); if (!libfile.isAbsolute()) { throw new UnsatisfiedLinkError( - "ClassLoader.findLibrary failed to return an absolute path: " + libfilename); + "ClassLoader.findLibrary failed to return an absolute path: " + libfilename); } if (loadLibrary0(fromClass, libfile)) { return; @@ -2551,10 +2640,11 @@ public abstract class ClassLoader { } } // Oops, it failed - throw new UnsatisfiedLinkError("no " + name + " in java.library.path"); + throw new UnsatisfiedLinkError("no " + name + + " in java.library.path: " + Arrays.toString(usr_paths)); } - static native String findBuiltinLib(String name); + private static native String findBuiltinLib(String name); private static boolean loadLibrary0(Class fromClass, final File file) { // Check to see if we're attempting to access a static library @@ -2575,85 +2665,72 @@ public abstract class ClassLoader { return false; } } - ClassLoader loader = - (fromClass == null) ? null : fromClass.getClassLoader(); - Vector libs = - loader != null ? loader.nativeLibraries : systemNativeLibraries; - synchronized (libs) { - int size = libs.size(); - for (int i = 0; i < size; i++) { - NativeLibrary lib = libs.elementAt(i); - if (name.equals(lib.name)) { - return true; - } - } - - synchronized (loadedLibraryNames) { - if (loadedLibraryNames.contains(name)) { - throw new UnsatisfiedLinkError - ("Native Library " + - name + - " already loaded in another classloader"); - } - /* If the library is being loaded (must be by the same thread, - * because Runtime.load and Runtime.loadLibrary are - * synchronous). The reason is can occur is that the JNI_OnLoad - * function can cause another loadLibrary invocation. - * - * Thus we can use a static stack to hold the list of libraries - * we are loading. - * - * If there is a pending load operation for the library, we - * immediately return success; otherwise, we raise - * UnsatisfiedLinkError. - */ - int n = nativeLibraryContext.size(); - for (int i = 0; i < n; i++) { - NativeLibrary lib = nativeLibraryContext.elementAt(i); - if (name.equals(lib.name)) { - if (loader == lib.fromClass.getClassLoader()) { - return true; - } else { - throw new UnsatisfiedLinkError - ("Native Library " + - name + - " is being loaded in another classloader"); - } - } - } - NativeLibrary lib = new NativeLibrary(fromClass, name, isBuiltin); - nativeLibraryContext.push(lib); - try { - lib.load(name, isBuiltin); - } finally { - nativeLibraryContext.pop(); - } - if (lib.loaded) { - loadedLibraryNames.addElement(name); - libs.addElement(lib); - return true; - } - return false; - } - } + return NativeLibrary.loadLibrary(fromClass, name, isBuiltin); } - // Invoked in the VM class linking code. - static long findNative(ClassLoader loader, String name) { - Vector libs = - loader != null ? loader.nativeLibraries : systemNativeLibraries; - synchronized (libs) { - int size = libs.size(); - for (int i = 0; i < size; i++) { - NativeLibrary lib = libs.elementAt(i); - long entry = lib.find(name); - if (entry != 0) - return entry; - } + /* + * Invoked in the VM class linking code. + */ + private static long findNative(ClassLoader loader, String entryName) { + Map libs = + loader != null ? loader.nativeLibraries() : systemNativeLibraries(); + if (libs.isEmpty()) + return 0; + + // the native libraries map may be updated in another thread + // when a native library is being loaded. No symbol will be + // searched from it yet. + for (NativeLibrary lib : libs.values()) { + long entry = lib.findEntry(entryName); + if (entry != 0) return entry; } return 0; } + // All native library names we've loaded. + // This also serves as the lock to obtain nativeLibraries + // and write to nativeLibraryContext. + private static final Set loadedLibraryNames = new HashSet<>(); + + // Native libraries belonging to system classes. + private static volatile Map systemNativeLibraries; + + // Native libraries associated with the class loader. + private volatile Map nativeLibraries; + + /* + * Returns the native libraries map associated with bootstrap class loader + * This method will create the map at the first time when called. + */ + private static Map systemNativeLibraries() { + Map libs = systemNativeLibraries; + if (libs == null) { + synchronized (loadedLibraryNames) { + libs = systemNativeLibraries; + if (libs == null) { + libs = systemNativeLibraries = new ConcurrentHashMap<>(); + } + } + } + return libs; + } + + /* + * Returns the native libraries map associated with this class loader + * This method will create the map at the first time when called. + */ + private Map nativeLibraries() { + Map libs = nativeLibraries; + if (libs == null) { + synchronized (loadedLibraryNames) { + libs = nativeLibraries; + if (libs == null) { + libs = nativeLibraries = new ConcurrentHashMap<>(); + } + } + } + return libs; + } // -- Assertion management -- diff --git a/src/java.base/share/classes/java/lang/Runtime.java b/src/java.base/share/classes/java/lang/Runtime.java index 230d75a412d..dc36b769a07 100644 --- a/src/java.base/share/classes/java/lang/Runtime.java +++ b/src/java.base/share/classes/java/lang/Runtime.java @@ -765,7 +765,9 @@ public class Runtime { * with the VM, then the JNI_OnLoad_L function exported by the library * is invoked rather than attempting to load a dynamic library. * A filename matching the argument does not have to exist in the file - * system. See the JNI Specification for more details. + * system. + * See the JNI Specification + * for more details. * * Otherwise, the filename argument is mapped to a native library image in * an implementation-dependent manner. @@ -818,7 +820,8 @@ public class Runtime { * specific prefix, file extension or path. If a native library * called {@code libname} is statically linked with the VM, then the * JNI_OnLoad_{@code libname} function exported by the library is invoked. - * See the JNI Specification for more details. + * See the JNI Specification + * for more details. * * Otherwise, the libname argument is loaded from a system library * location and mapped to a native library image in an implementation- diff --git a/src/java.base/share/classes/java/lang/System.java b/src/java.base/share/classes/java/lang/System.java index 86ec3c5cad3..d2a8f71b86c 100644 --- a/src/java.base/share/classes/java/lang/System.java +++ b/src/java.base/share/classes/java/lang/System.java @@ -1799,7 +1799,8 @@ public final class System { * is invoked rather than attempting to load a dynamic library. * A filename matching the argument does not have to exist in the * file system. - * See the JNI Specification for more details. + * See the JNI Specification + * for more details. * * Otherwise, the filename argument is mapped to a native library image in * an implementation-dependent manner. @@ -1835,7 +1836,8 @@ public final class System { * specific prefix, file extension or path. If a native library * called libname is statically linked with the VM, then the * JNI_OnLoad_libname function exported by the library is invoked. - * See the JNI Specification for more details. + * See the JNI Specification + * for more details. * * Otherwise, the libname argument is loaded from a system library * location and mapped to a native library image in an implementation- diff --git a/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java b/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java index 056350f25c3..e62a0321a7f 100644 --- a/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java +++ b/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java @@ -62,10 +62,16 @@ public final class InnocuousThread extends Thread { * set to the system class loader. */ public static Thread newThread(String name, Runnable target) { - return new InnocuousThread(INNOCUOUSTHREADGROUP, - target, - name, - ClassLoader.getSystemClassLoader()); + return AccessController.doPrivileged( + new PrivilegedAction() { + @Override + public Thread run() { + return new InnocuousThread(INNOCUOUSTHREADGROUP, + target, + name, + ClassLoader.getSystemClassLoader()); + } + }); } /** @@ -80,8 +86,14 @@ public final class InnocuousThread extends Thread { * Returns a new InnocuousThread with null context class loader. */ public static Thread newSystemThread(String name, Runnable target) { - return new InnocuousThread(INNOCUOUSTHREADGROUP, - target, name, null); + return AccessController.doPrivileged( + new PrivilegedAction() { + @Override + public Thread run() { + return new InnocuousThread(INNOCUOUSTHREADGROUP, + target, name, null); + } + }); } private InnocuousThread(ThreadGroup group, Runnable target, String name, ClassLoader tccl) { diff --git a/src/java.base/share/native/libjava/ClassLoader.c b/src/java.base/share/native/libjava/ClassLoader.c index f3803805c59..b3d2ef109de 100644 --- a/src/java.base/share/native/libjava/ClassLoader.c +++ b/src/java.base/share/native/libjava/ClassLoader.c @@ -260,7 +260,6 @@ Java_java_lang_ClassLoader_findLoadedClass0(JNIEnv *env, jobject loader, static jfieldID handleID; static jfieldID jniVersionID; -static jfieldID loadedID; static void *procHandle; static jboolean initIDs(JNIEnv *env) @@ -276,9 +275,6 @@ static jboolean initIDs(JNIEnv *env) jniVersionID = (*env)->GetFieldID(env, this, "jniVersion", "I"); if (jniVersionID == 0) return JNI_FALSE; - loadedID = (*env)->GetFieldID(env, this, "loaded", "Z"); - if (loadedID == 0) - return JNI_FALSE; procHandle = getProcessHandle(); } return JNI_TRUE; @@ -335,30 +331,31 @@ static void *findJniFunction(JNIEnv *env, void *handle, /* * Class: java_lang_ClassLoader_NativeLibrary - * Method: load - * Signature: (Ljava/lang/String;Z)V + * Method: load0 + * Signature: (Ljava/lang/String;Z)Z */ -JNIEXPORT void JNICALL -Java_java_lang_ClassLoader_00024NativeLibrary_load +JNIEXPORT jboolean JNICALL +Java_java_lang_ClassLoader_00024NativeLibrary_load0 (JNIEnv *env, jobject this, jstring name, jboolean isBuiltin) { const char *cname; jint jniVersion; jthrowable cause; void * handle; + jboolean loaded = JNI_FALSE; if (!initIDs(env)) - return; + return JNI_FALSE; cname = JNU_GetStringPlatformChars(env, name, 0); if (cname == 0) - return; + return JNI_FALSE; handle = isBuiltin ? procHandle : JVM_LoadLibrary(cname); if (handle) { JNI_OnLoad_t JNI_OnLoad; JNI_OnLoad = (JNI_OnLoad_t)findJniFunction(env, handle, - isBuiltin ? cname : NULL, - JNI_TRUE); + isBuiltin ? cname : NULL, + JNI_TRUE); if (JNI_OnLoad) { JavaVM *jvm; (*env)->GetJavaVM(env, &jvm); @@ -400,20 +397,21 @@ Java_java_lang_ClassLoader_00024NativeLibrary_load goto done; } (*env)->SetLongField(env, this, handleID, ptr_to_jlong(handle)); - (*env)->SetBooleanField(env, this, loadedID, JNI_TRUE); + loaded = JNI_TRUE; done: JNU_ReleaseStringPlatformChars(env, name, cname); + return loaded; } /* * Class: java_lang_ClassLoader_NativeLibrary * Method: unload - * Signature: (Z)V + * Signature: (Ljava/lang/String;ZJ)V */ JNIEXPORT void JNICALL Java_java_lang_ClassLoader_00024NativeLibrary_unload -(JNIEnv *env, jobject this, jstring name, jboolean isBuiltin) +(JNIEnv *env, jclass cls, jstring name, jboolean isBuiltin, jlong address) { const char *onUnloadSymbols[] = JNI_ONUNLOAD_SYMBOLS; void *handle; @@ -426,10 +424,10 @@ Java_java_lang_ClassLoader_00024NativeLibrary_unload if (cname == NULL) { return; } - handle = jlong_to_ptr((*env)->GetLongField(env, this, handleID)); + handle = jlong_to_ptr(address); JNI_OnUnload = (JNI_OnUnload_t )findJniFunction(env, handle, - isBuiltin ? cname : NULL, - JNI_FALSE); + isBuiltin ? cname : NULL, + JNI_FALSE); if (JNI_OnUnload) { JavaVM *jvm; (*env)->GetJavaVM(env, &jvm); @@ -443,11 +441,11 @@ Java_java_lang_ClassLoader_00024NativeLibrary_unload /* * Class: java_lang_ClassLoader_NativeLibrary - * Method: find + * Method: findEntry * Signature: (Ljava/lang/String;)J */ JNIEXPORT jlong JNICALL -Java_java_lang_ClassLoader_00024NativeLibrary_find +Java_java_lang_ClassLoader_00024NativeLibrary_findEntry (JNIEnv *env, jobject this, jstring name) { jlong handle; diff --git a/src/java.xml/share/classes/com/sun/java_cup/internal/runtime/lr_parser.java b/src/java.xml/share/classes/com/sun/java_cup/internal/runtime/lr_parser.java index 98f7bbbe41d..e0ceedac972 100644 --- a/src/java.xml/share/classes/com/sun/java_cup/internal/runtime/lr_parser.java +++ b/src/java.xml/share/classes/com/sun/java_cup/internal/runtime/lr_parser.java @@ -946,7 +946,7 @@ public abstract class lr_parser { if (debug) debug_message("# Pop stack by one, state was # " + (stack.peek()).parse_state); - left_pos = ((Symbol)stack.pop()).left; + left_pos = stack.pop().left; tos--; /* if we have hit bottom, we fail */ diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/lib/ExsltDatetime.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/lib/ExsltDatetime.java index 479f152813c..4e8f766f0a1 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/lib/ExsltDatetime.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/lib/ExsltDatetime.java @@ -1,6 +1,6 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * @LastModified: Nov 2017 */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -616,7 +616,7 @@ public class ExsltDatetime public static boolean leapYear() { Calendar cal = Calendar.getInstance(); - int yr = (int)cal.get(Calendar.YEAR); + int yr = cal.get(Calendar.YEAR); return (yr % 400 == 0 || (yr % 100 != 0 && yr % 4 == 0)); } diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/AttributeSet.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/AttributeSet.java index 43eef701616..6812385191f 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/AttributeSet.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/AttributeSet.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. - * @LastModified: Oct 2017 + * @LastModified: Nov 2017 */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -115,7 +115,7 @@ final class AttributeSet extends TopLevelElement { final List contents = getContents(); final int count = contents.size(); for (int i=0; i attributes = elements(); while (attributes.hasNext()) { - SyntaxTreeNode element = (SyntaxTreeNode)attributes.next(); + SyntaxTreeNode element = attributes.next(); if (element instanceof XslAttribute) { final XslAttribute attribute = (XslAttribute)element; attribute.translate(classGen, methodGen); diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/BinOpExpr.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/BinOpExpr.java index 20f7310a363..b61c668b31f 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/BinOpExpr.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/BinOpExpr.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. - * @LastModified: Oct 2017 + * @LastModified: Nov 2017 */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -83,11 +83,11 @@ final class BinOpExpr extends Expression { new MethodType(Type.Void, tleft, tright)); if (ptype != null) { - final Type arg1 = (Type) ptype.argsType().get(0); + final Type arg1 = ptype.argsType().get(0); if (!arg1.identicalTo(tleft)) { _left = new CastExpr(_left, arg1); } - final Type arg2 = (Type) ptype.argsType().get(1); + final Type arg2 = ptype.argsType().get(1); if (!arg2.identicalTo(tright)) { _right = new CastExpr(_right, arg1); } diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FilterExpr.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FilterExpr.java index 77462ab101a..92e83abbb57 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FilterExpr.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FilterExpr.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. - * @LastModified: Oct 2017 + * @LastModified: Nov 2017 */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -75,7 +75,7 @@ class FilterExpr extends Expression { if (_predicates != null) { final int n = _predicates.size(); for (int i = 0; i < n; i++) { - final Expression exp = (Expression)_predicates.get(i); + final Expression exp = _predicates.get(i); exp.setParser(parser); exp.setParent(this); } diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionAvailableCall.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionAvailableCall.java index 8c5ea0d8a1a..bcee236a83c 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionAvailableCall.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionAvailableCall.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. - * @LastModified: Oct 2017 + * @LastModified: Nov 2017 */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -53,7 +53,7 @@ final class FunctionAvailableCall extends FunctionCall { */ public FunctionAvailableCall(QName fname, List arguments) { super(fname, arguments); - _arg = (Expression)arguments.get(0); + _arg = arguments.get(0); _type = null; if (_arg instanceof LiteralExpr) { diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java index 3e88bdfb51e..ade55416067 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. - * @LastModified: Oct 2017 + * @LastModified: Nov 2017 */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -443,7 +443,7 @@ class FunctionCall extends Expression { if (ptype != null) { for (int i = 0; i < n; i++) { - final Type argType = (Type) ptype.argsType().get(i); + final Type argType = ptype.argsType().get(i); final Expression exp = _arguments.get(i); if (!argType.identicalTo(exp.getType())) { try { @@ -557,7 +557,7 @@ class FunctionCall extends Expression { hasThisArgument = true; Expression firstArg = _arguments.get(0); - Type firstArgType = (Type)firstArg.typeCheck(stable); + Type firstArgType = firstArg.typeCheck(stable); if (_namespace_format == NAMESPACE_FORMAT_CLASS && firstArgType instanceof ObjectType @@ -608,7 +608,7 @@ class FunctionCall extends Expression { _type = null; // reset internal type for (int j, i = 0; i < nMethods; i++) { // Check if all paramteters to this method can be converted - final Method method = (Method)methods.get(i); + final Method method = methods.get(i); final Class[] paramTypes = method.getParameterTypes(); int currMethodDistance = 0; diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/LogicalExpr.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/LogicalExpr.java index 56868aec957..27d9f3ae297 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/LogicalExpr.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/LogicalExpr.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. - * @LastModified: Oct 2017 + * @LastModified: Nov 2017 */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -137,11 +137,11 @@ final class LogicalExpr extends Expression { // Yes, the operation is supported if (haveType != null) { // Check if left-hand side operand must be type casted - Type arg1 = (Type)haveType.argsType().get(0); + Type arg1 = haveType.argsType().get(0); if (!arg1.identicalTo(tleft)) _left = new CastExpr(_left, arg1); // Check if right-hand side operand must be type casted - Type arg2 = (Type) haveType.argsType().get(1); + Type arg2 = haveType.argsType().get(1); if (!arg2.identicalTo(tright)) _right = new CastExpr(_right, arg1); // Return the result type for the operator we will use diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Message.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Message.java index 71dc212dc40..4b578abee91 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Message.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Message.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. - * @LastModified: Oct 2017 + * @LastModified: Nov 2017 */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -67,7 +67,7 @@ final class Message extends Instruction { il.append(new PUSH(cpg, "")); break; case 1: - SyntaxTreeNode child = (SyntaxTreeNode) elementAt(0); + SyntaxTreeNode child = elementAt(0); if (child instanceof Text) { il.append(new PUSH(cpg, ((Text) child).getText())); break; diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Mode.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Mode.java index 48c1efcb290..b6363668a0f 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Mode.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Mode.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. - * @LastModified: Oct 2017 + * @LastModified: Nov 2017 */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -229,12 +229,12 @@ final class Mode implements Constants { } private int partition(List