changeset 13336:7373c07f4cca

8144723: MethodHandleImpl.initStatics is no longer needed Reviewed-by: vlivanov, mhaupt, forax
author redestad
date Sat, 19 Dec 2015 02:24:27 +0100
parents 65f45c833654
children 86e9fba8f9a4
files src/java.base/share/classes/java/lang/invoke/CallSite.java src/java.base/share/classes/java/lang/invoke/MemberName.java src/java.base/share/classes/java/lang/invoke/MethodHandle.java src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java src/java.base/share/classes/java/lang/invoke/MethodHandles.java
diffstat 6 files changed, 32 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/invoke/CallSite.java	Fri Dec 18 23:54:51 2015 +0000
+++ b/src/java.base/share/classes/java/lang/invoke/CallSite.java	Sat Dec 19 02:24:27 2015 +0100
@@ -83,7 +83,6 @@
  */
 abstract
 public class CallSite {
-    static { MethodHandleImpl.initStatics(); }
 
     // The actual payload of this call site:
     /*package-private*/
--- a/src/java.base/share/classes/java/lang/invoke/MemberName.java	Fri Dec 18 23:54:51 2015 +0000
+++ b/src/java.base/share/classes/java/lang/invoke/MemberName.java	Sat Dec 19 02:24:27 2015 +0100
@@ -1073,11 +1073,6 @@
         }
     }
 
-//    static {
-//        System.out.println("Hello world!  My methods are:");
-//        System.out.println(Factory.INSTANCE.getMethods(MemberName.class, true, null));
-//    }
-
     static {
         // Allow privileged classes outside of java.lang
         jdk.internal.misc.SharedSecrets.setJavaLangInvokeAccess(new jdk.internal.misc.JavaLangInvokeAccess() {
--- a/src/java.base/share/classes/java/lang/invoke/MethodHandle.java	Fri Dec 18 23:54:51 2015 +0000
+++ b/src/java.base/share/classes/java/lang/invoke/MethodHandle.java	Sat Dec 19 02:24:27 2015 +0100
@@ -420,7 +420,6 @@
  * @author John Rose, JSR 292 EG
  */
 public abstract class MethodHandle {
-    static { MethodHandleImpl.initStatics(); }
 
     /**
      * Internal marker interface which distinguishes (to the Java compiler)
--- a/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java	Fri Dec 18 23:54:51 2015 +0000
+++ b/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java	Sat Dec 19 02:24:27 2015 +0100
@@ -32,7 +32,6 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.function.Function;
-import java.util.stream.Collectors;
 
 import sun.invoke.empty.Empty;
 import sun.invoke.util.ValueConversions;
@@ -65,11 +64,6 @@
 
     /// Factory methods to create method handles:
 
-    static void initStatics() {
-        // Trigger selected static initializations.
-        MemberName.Factory.INSTANCE.getClass();
-    }
-
     static MethodHandle makeArrayElementAccessor(Class<?> arrayClass, boolean isSetter) {
         if (arrayClass == Object[].class)
             return (isSetter ? ArrayAccessor.OBJECT_ARRAY_SETTER : ArrayAccessor.OBJECT_ARRAY_GETTER);
@@ -700,33 +694,43 @@
     MethodHandle makeBlockInliningWrapper(MethodHandle target) {
         LambdaForm lform;
         if (DONT_INLINE_THRESHOLD > 0) {
-            lform = PRODUCE_BLOCK_INLINING_FORM.apply(target);
+            lform = Makers.PRODUCE_BLOCK_INLINING_FORM.apply(target);
         } else {
-            lform = PRODUCE_REINVOKER_FORM.apply(target);
+            lform = Makers.PRODUCE_REINVOKER_FORM.apply(target);
         }
         return new CountingWrapper(target, lform,
-                PRODUCE_BLOCK_INLINING_FORM, PRODUCE_REINVOKER_FORM,
+                Makers.PRODUCE_BLOCK_INLINING_FORM, Makers.PRODUCE_REINVOKER_FORM,
                                    DONT_INLINE_THRESHOLD);
     }
 
-    /** Constructs reinvoker lambda form which block inlining during JIT-compilation for a particular method handle */
-    private static final Function<MethodHandle, LambdaForm> PRODUCE_BLOCK_INLINING_FORM = new Function<MethodHandle, LambdaForm>() {
-        @Override
-        public LambdaForm apply(MethodHandle target) {
-            return DelegatingMethodHandle.makeReinvokerForm(target,
-                               MethodTypeForm.LF_DELEGATE_BLOCK_INLINING, CountingWrapper.class, "reinvoker.dontInline", false,
-                               DelegatingMethodHandle.NF_getTarget, CountingWrapper.NF_maybeStopCounting);
-        }
-    };
+    private final static class Makers {
+        /** Constructs reinvoker lambda form which block inlining during JIT-compilation for a particular method handle */
+        static final Function<MethodHandle, LambdaForm> PRODUCE_BLOCK_INLINING_FORM = new Function<MethodHandle, LambdaForm>() {
+            @Override
+            public LambdaForm apply(MethodHandle target) {
+                return DelegatingMethodHandle.makeReinvokerForm(target,
+                                   MethodTypeForm.LF_DELEGATE_BLOCK_INLINING, CountingWrapper.class, "reinvoker.dontInline", false,
+                                   DelegatingMethodHandle.NF_getTarget, CountingWrapper.NF_maybeStopCounting);
+            }
+        };
 
-    /** Constructs simple reinvoker lambda form for a particular method handle */
-    private static final Function<MethodHandle, LambdaForm> PRODUCE_REINVOKER_FORM = new Function<MethodHandle, LambdaForm>() {
-        @Override
-        public LambdaForm apply(MethodHandle target) {
-            return DelegatingMethodHandle.makeReinvokerForm(target,
-                    MethodTypeForm.LF_DELEGATE, DelegatingMethodHandle.class, DelegatingMethodHandle.NF_getTarget);
-        }
-    };
+        /** Constructs simple reinvoker lambda form for a particular method handle */
+        static final Function<MethodHandle, LambdaForm> PRODUCE_REINVOKER_FORM = new Function<MethodHandle, LambdaForm>() {
+            @Override
+            public LambdaForm apply(MethodHandle target) {
+                return DelegatingMethodHandle.makeReinvokerForm(target,
+                        MethodTypeForm.LF_DELEGATE, DelegatingMethodHandle.class, DelegatingMethodHandle.NF_getTarget);
+            }
+        };
+
+        /** Maker of type-polymorphic varargs */
+        static final ClassValue<MethodHandle[]> TYPED_COLLECTORS = new ClassValue<MethodHandle[]>() {
+            @Override
+            protected MethodHandle[] computeValue(Class<?> type) {
+                return new MethodHandle[MAX_JVM_ARITY + 1];
+            }
+        };
+    }
 
     /**
      * Counting method handle. It has 2 states: counting and non-counting.
@@ -1527,15 +1531,6 @@
             return MethodHandles.collectArguments(rightFill, 0, midFill);
     }
 
-    // Type-polymorphic version of varargs maker.
-    private static final ClassValue<MethodHandle[]> TYPED_COLLECTORS
-        = new ClassValue<MethodHandle[]>() {
-            @Override
-            protected MethodHandle[] computeValue(Class<?> type) {
-                return new MethodHandle[256];
-            }
-    };
-
     static final int MAX_JVM_ARITY = 255;  // limit imposed by the JVM
 
     /** Return a method handle that takes the indicated number of
@@ -1557,7 +1552,7 @@
         if (elemType == Object.class)
             return varargsArray(nargs);
         // other cases:  primitive arrays, subtypes of Object[]
-        MethodHandle cache[] = TYPED_COLLECTORS.get(elemType);
+        MethodHandle cache[] = Makers.TYPED_COLLECTORS.get(elemType);
         MethodHandle mh = nargs < cache.length ? cache[nargs] : null;
         if (mh != null)  return mh;
         if (nargs == 0) {
--- a/src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java	Fri Dec 18 23:54:51 2015 +0000
+++ b/src/java.base/share/classes/java/lang/invoke/MethodHandleNatives.java	Sat Dec 19 02:24:27 2015 +0100
@@ -87,9 +87,6 @@
     private static native void registerNatives();
     static {
         registerNatives();
-
-        // The JVM calls MethodHandleNatives.<clinit>.  Cascade the <clinit> calls as needed:
-        MethodHandleImpl.initStatics();
     }
 
     /**
--- a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Fri Dec 18 23:54:51 2015 +0000
+++ b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java	Sat Dec 19 02:24:27 2015 +0100
@@ -61,7 +61,7 @@
     private MethodHandles() { }  // do not instantiate
 
     private static final MemberName.Factory IMPL_NAMES = MemberName.getFactory();
-    static { MethodHandleImpl.initStatics(); }
+
     // See IMPL_LOOKUP below.
 
     //// Method handle creation from ordinary methods.