changeset 46047:97d615d81827

8161121: VM::isSystemDomainLoader should consider platform class loader Reviewed-by: alanb
author mchung
date Fri, 28 Jul 2017 13:22:33 -0700
parents 54ca7058579d
children 00b5dc9d9be5
files jdk/src/java.base/share/classes/java/lang/Class.java jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java jdk/src/java.base/share/classes/jdk/internal/logger/DefaultLoggerFinder.java jdk/src/java.base/share/classes/jdk/internal/misc/VM.java jdk/src/java.base/share/classes/jdk/internal/reflect/Reflection.java jdk/src/java.management/share/classes/java/lang/management/ManagementFactory.java
diffstat 7 files changed, 13 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/java.base/share/classes/java/lang/Class.java	Fri Jul 28 02:34:40 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/Class.java	Fri Jul 28 13:22:33 2017 -0700
@@ -364,9 +364,9 @@
             // Reflective call to get caller class is only needed if a security manager
             // is present.  Avoid the overhead of making this call otherwise.
             caller = Reflection.getCallerClass();
-            if (VM.isSystemDomainLoader(loader)) {
+            if (loader == null) {
                 ClassLoader ccl = ClassLoader.getClassLoader(caller);
-                if (!VM.isSystemDomainLoader(ccl)) {
+                if (ccl != null) {
                     sm.checkPermission(
                         SecurityConstants.GET_CLASSLOADER_PERMISSION);
                 }
--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Fri Jul 28 02:34:40 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Fri Jul 28 13:22:33 2017 -0700
@@ -2476,7 +2476,7 @@
                 return false;
             }
             ClassLoader loader = defc.getClassLoader();
-            if (!jdk.internal.misc.VM.isSystemDomainLoader(loader)) {
+            if (loader != null) {
                 ClassLoader sysl = ClassLoader.getSystemClassLoader();
                 boolean found = false;
                 while (sysl != null) {
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java	Fri Jul 28 02:34:40 2017 +0000
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Proxy.java	Fri Jul 28 13:22:33 2017 -0700
@@ -453,7 +453,7 @@
         SecurityManager sm = System.getSecurityManager();
         if (sm != null) {
             ClassLoader ccl = caller.getClassLoader();
-            if (VM.isSystemDomainLoader(loader) && !VM.isSystemDomainLoader(ccl)) {
+            if (loader == null && ccl != null) {
                 sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
             }
             ReflectUtil.checkProxyPackageAccess(ccl, interfaces);
--- a/jdk/src/java.base/share/classes/jdk/internal/logger/DefaultLoggerFinder.java	Fri Jul 28 02:34:40 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/logger/DefaultLoggerFinder.java	Fri Jul 28 13:22:33 2017 -0700
@@ -25,6 +25,8 @@
 
 package jdk.internal.logger;
 
+import jdk.internal.misc.VM;
+
 import java.lang.ref.Reference;
 import java.lang.ref.WeakReference;
 import java.util.HashMap;
@@ -140,15 +142,9 @@
         return AccessController.doPrivileged(new PrivilegedAction<>() {
             @Override
             public Boolean run() {
-                final ClassLoader moduleCL = m.getClassLoader();
-                if (moduleCL == null) return true;
-                ClassLoader cl = ClassLoader.getPlatformClassLoader();
-                while (cl != null && moduleCL != cl) {
-                    cl = cl.getParent();
-                }
                 // returns true if moduleCL is the platform class loader
                 // or one of its ancestors.
-                return moduleCL == cl;
+                return VM.isSystemDomainLoader(m.getClassLoader());
             }
         });
     }
--- a/jdk/src/java.base/share/classes/jdk/internal/misc/VM.java	Fri Jul 28 02:34:40 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/misc/VM.java	Fri Jul 28 13:22:33 2017 -0700
@@ -124,11 +124,11 @@
     }
 
     /**
-     * Returns true if the given class loader is in the system domain
-     * in which all permissions are granted.
+     * Returns true if the given class loader is the bootstrap class loader
+     * or the platform class loader.
      */
     public static boolean isSystemDomainLoader(ClassLoader loader) {
-        return loader == null;
+        return loader == null || loader == ClassLoader.getPlatformClassLoader();
     }
 
     /**
--- a/jdk/src/java.base/share/classes/jdk/internal/reflect/Reflection.java	Fri Jul 28 02:34:40 2017 +0000
+++ b/jdk/src/java.base/share/classes/jdk/internal/reflect/Reflection.java	Fri Jul 28 13:22:33 2017 -0700
@@ -316,8 +316,7 @@
      */
     public static boolean isCallerSensitive(Method m) {
         final ClassLoader loader = m.getDeclaringClass().getClassLoader();
-        if (VM.isSystemDomainLoader(loader) ||
-                loader == ClassLoaders.platformClassLoader()) {
+        if (VM.isSystemDomainLoader(loader)) {
             return m.isAnnotationPresent(CallerSensitive.class);
         }
         return false;
--- a/jdk/src/java.management/share/classes/java/lang/management/ManagementFactory.java	Fri Jul 28 02:34:40 2017 +0000
+++ b/jdk/src/java.management/share/classes/java/lang/management/ManagementFactory.java	Fri Jul 28 13:22:33 2017 -0700
@@ -588,8 +588,8 @@
                                Class<T> mxbeanInterface)
             throws java.io.IOException {
 
-        // Only allow MXBean interfaces from rt.jar loaded by the
-        // bootstrap class loader
+        // Only allow MXBean interfaces from the platform modules loaded by the
+        // bootstrap or platform class loader
         final Class<?> cls = mxbeanInterface;
         ClassLoader loader =
             AccessController.doPrivileged(