Skip to content

Commit

Permalink
8339635: StringConcatFactory optimization for CompactStrings off
Browse files Browse the repository at this point in the history
Reviewed-by: liach
  • Loading branch information
wenshao authored and liach committed Sep 6, 2024
1 parent 8e580ec commit fbe2629
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/java.base/share/classes/java/lang/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit fbe2629

Please sign in to comment.