You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pa...@apache.org on 2017/10/23 10:57:07 UTC

svn commit: r1812992 - /felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java

Author: pauls
Date: Mon Oct 23 10:57:07 2017
New Revision: 1812992

URL: http://svn.apache.org/viewvc?rev=1812992&view=rev
Log:
FELIX-5725: Cache lookup of jdk.internal.reflection classes to prevent high cpu usage when a lot of reflection is used on java9.

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java?rev=1812992&r1=1812991&r2=1812992&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java Mon Oct 23 10:57:07 2017
@@ -1489,7 +1489,7 @@ public class BundleWiringImpl implements
                         ? Util.getClassPackage(name)
                                 : Util.getResourcePackage(name);
 
-                        boolean accessor = name.startsWith("sun.reflect.Generated");
+                        boolean accessor = name.startsWith("sun.reflect.Generated") || name.startsWith("jdk.internal.reflect.");
 
                         if (accessor)
                         {
@@ -1561,8 +1561,27 @@ public class BundleWiringImpl implements
                                     }
                                 }
                             }
-                            m_accessorLookupCache.put(name, CNFE_CLASS_LOADER);
-                            CNFE_CLASS_LOADER.loadClass(name);
+
+                            try
+                            {
+                                result = tryImplicitBootDelegation(name, isClass);
+                            }
+                            catch (Exception ex)
+                            {
+                                // Ignore, will throw using CNFE_CLASS_LOADER
+                            }
+
+                            if (result != null)
+                            {
+                                m_accessorLookupCache.put(name, BundleRevisionImpl.getSecureAction()
+                                        .getClassLoader(this.getClass()));
+                                return result;
+                            }
+                            else
+                            {
+                                m_accessorLookupCache.put(name, CNFE_CLASS_LOADER);
+                                CNFE_CLASS_LOADER.loadClass(name);
+                            }
                         }
 
                         // Look in the revision's imports. Note that the search may
@@ -1719,6 +1738,12 @@ public class BundleWiringImpl implements
                             : (Object) ((BundleWiringImpl) provider.getWiring()).getResourceByDelegation(name);
         }
 
+        return tryImplicitBootDelegation(name, isClass);
+    }
+
+    private Object tryImplicitBootDelegation(final String name, final boolean isClass)
+            throws ClassNotFoundException, ResourceNotFoundException
+    {
         // If implicit boot delegation is enabled, then try to guess whether
         // we should boot delegate.
         if (m_implicitBootDelegation)