From 150d6cfea81afd3900ff69a7ab60efdadf5de76d Mon Sep 17 00:00:00 2001 From: Claes Redestad Date: Fri, 15 May 2020 18:37:08 +0200 Subject: [PATCH] 8245094: Reduce overhead of initializing the default StringConcatFactory strategy Reviewed-by: psandoz, jlaskey --- src/java.base/share/classes/java/lang/System.java | 4 ++++ .../classes/java/lang/invoke/StringConcatFactory.java | 7 +------ .../share/classes/jdk/internal/access/JavaLangAccess.java | 5 +++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/java.base/share/classes/java/lang/System.java b/src/java.base/share/classes/java/lang/System.java index 7fc959ae1be..6ac9d5535e4 100644 --- a/src/java.base/share/classes/java/lang/System.java +++ b/src/java.base/share/classes/java/lang/System.java @@ -2283,6 +2283,10 @@ public final class System { return StringConcatHelper.lookupStatic(name, methodType); } + public long stringConcatInitialCoder() { + return StringConcatHelper.initialCoder(); + } + public Object classData(Class c) { return c.getClassData(); } diff --git a/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java b/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java index 9d14352215a..88b0d6d6d45 100644 --- a/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java +++ b/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java @@ -1724,12 +1724,7 @@ public final class StringConcatFactory { private static final long INITIAL_CODER; static { - try { - MethodHandle initCoder = JLA.stringConcatHelper("initialCoder", methodType(long.class)); - INITIAL_CODER = (long) initCoder.invoke(); - } catch (Throwable e) { - throw new AssertionError(e); - } + INITIAL_CODER = JLA.stringConcatInitialCoder(); PREPENDERS = new ConcurrentHashMap<>(); MIXERS = new ConcurrentHashMap<>(); diff --git a/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java b/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java index fb4130481c4..729bd7bc21c 100644 --- a/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java +++ b/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java @@ -333,6 +333,11 @@ public interface JavaLangAccess { */ MethodHandle stringConcatHelper(String name, MethodType methodType); + /** + * Get the string concat initial coder + */ + long stringConcatInitialCoder(); + /* * Get the class data associated with the given class. * @param c the class