< prev index next >

src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java

Print this page

        

@@ -28,11 +28,11 @@
 import jdk.internal.org.objectweb.asm.ClassWriter;
 import jdk.internal.org.objectweb.asm.Label;
 import jdk.internal.org.objectweb.asm.MethodVisitor;
 import jdk.internal.org.objectweb.asm.Opcodes;
 import jdk.internal.vm.annotation.ForceInline;
-import sun.misc.Unsafe;
+import jdk.internal.misc.Unsafe;
 
 import java.lang.invoke.MethodHandles.Lookup;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.*;

@@ -1495,11 +1495,11 @@
             // and deduce the coder from there. Arguments would be either converted to Strings
             // during the initial filtering, or handled by primitive specializations in CODER_MIXERS.
             //
             // The method handle shape after all length and coder mixers is:
             //   (int, byte, <args>)String = ("index", "coder", <args>)
-            byte initialCoder = 0; // initial coder
+            byte initialCoder = INITIAL_CODER;
             int initialLen = 0;    // initial length, in characters
             for (RecipeElement el : recipe.getElements()) {
                 switch (el.getTag()) {
                     case CONST: {
                         Object constant = el.getValue();

@@ -1628,15 +1628,18 @@
         private static final MethodHandle NEW_ARRAY;
         private static final ConcurrentMap<Class<?>, MethodHandle> PREPENDERS;
         private static final ConcurrentMap<Class<?>, MethodHandle> LENGTH_MIXERS;
         private static final ConcurrentMap<Class<?>, MethodHandle> CODER_MIXERS;
         private static final Class<?> STRING_HELPER;
+        private static final byte INITIAL_CODER;
 
         static {
             try {
                 STRING_HELPER = Class.forName("java.lang.StringConcatHelper");
-            } catch (ClassNotFoundException e) {
+                MethodHandle initCoder = lookupStatic(Lookup.IMPL_LOOKUP, STRING_HELPER, "initialCoder", byte.class);
+                INITIAL_CODER = (byte) initCoder.invoke();
+            } catch (Throwable e) {
                 throw new AssertionError(e);
             }
 
             PREPENDERS = new ConcurrentHashMap<>();
             LENGTH_MIXERS = new ConcurrentHashMap<>();
< prev index next >