From fbe2629303bcee5855673b7e37d8c49f19dc9849 Mon Sep 17 00:00:00 2001 From: Shaojin Wen Date: Fri, 6 Sep 2024 18:37:29 +0000 Subject: [PATCH] 8339635: StringConcatFactory optimization for CompactStrings off Reviewed-by: liach --- 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, 15 insertions(+), 1 deletion(-) diff --git a/src/java.base/share/classes/java/lang/System.java b/src/java.base/share/classes/java/lang/System.java index 368db1928f113..2521eb0149398 100644 --- a/src/java.base/share/classes/java/lang/System.java +++ b/src/java.base/share/classes/java/lang/System.java @@ -2642,6 +2642,10 @@ public Object stringConcat1(String[] constants) { return new StringConcatHelper.Concat1(constants); } + public byte stringInitCoder() { + return String.COMPACT_STRINGS ? String.LATIN1 : String.UTF16; + } + public int getCharsLatin1(long i, int index, byte[] buf) { return StringLatin1.getChars(i, index, buf); } 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 8486ede3a272c..6c8d72cec4e85 100644 --- a/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java +++ b/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java @@ -1196,9 +1196,14 @@ private static MethodTypeDesc prependArgs(MethodType concatArgs) { /** * Construct the MethodType of the coder method. The first parameter is the initialized coder. - * Only parameter types which can be UTF16 are added. Returns null if no such parameter exists. + * Only parameter types which can be UTF16 are added. + * Returns null if no such parameter exists or CompactStrings is off. */ private static MethodTypeDesc coderArgsIfMaybeUTF16(MethodType concatArgs) { + if (JLA.stringInitCoder() != 0) { + return null; + } + int parameterCount = concatArgs.parameterCount(); int maybeUTF16Count = 0; 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 98238af383174..dbe116599e099 100644 --- a/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java +++ b/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java @@ -459,6 +459,11 @@ public interface JavaLangAccess { Object stringConcat1(String[] constants); + /** + * Get the string initial coder, When COMPACT_STRINGS is on, it returns 0, and when it is off, it returns 1. + */ + byte stringInitCoder(); + /** * Join strings */