8336856: Efficient hidden class-based string concatenation strategy

Co-authored-by: Claes Redestad <redestad@openjdk.org>
Reviewed-by: redestad, liach
This commit is contained in:
Shaojin Wen 2024-08-16 13:18:02 +00:00 committed by Claes Redestad
parent ddbc0b6a39
commit 5022109b2a
8 changed files with 1329 additions and 146 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, Alibaba Group Holding Limited. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -48,22 +49,40 @@ public class StringConcat {
@Param("4711")
public int intValue;
public Integer integerValue = intValue;
public float floatValue = 156456.36435637F + intValue;
public String stringValue = String.valueOf(intValue);
public Object objectValue = Long.valueOf(intValue);
public boolean boolValue = true;
public Boolean booleanValue = Boolean.TRUE;
public byte byteValue = (byte)-128;
public String emptyString = "";
@Benchmark
public String concatConstBool() {
return "string" + boolValue;
}
@Benchmark
public String concatConstBoolean() {
return "string" + booleanValue;
}
@Benchmark
public String concatConstInt() {
return "string" + intValue;
}
@Benchmark
public String concatConstInteger() {
return "string" + integerValue;
}
@Benchmark
public String concatConstFloat() {
return "string" + floatValue;
}
@Benchmark
public String concatConstString() {
return "string" + stringValue;
@ -94,6 +113,31 @@ public class StringConcat {
return "string".concat(stringValue);
}
@Benchmark
public String concatConstBoolString() {
return "string" + boolValue + stringValue;
}
@Benchmark
public String concatConstBooleanString() {
return "string" + booleanValue + stringValue;
}
@Benchmark
public String concatConstIntString() {
return "string" + intValue + stringValue;
}
@Benchmark
public String concatConstIntegerString() {
return "string" + integerValue + stringValue;
}
@Benchmark
public String concatConstFloatString() {
return "string" + floatValue + stringValue;
}
@Benchmark
public String concatConstIntConstInt() {
return "string" + intValue + "string" + intValue;
@ -104,6 +148,36 @@ public class StringConcat {
return "string" + stringValue + "string" + intValue;
}
@Benchmark
public String concatConstStringConst() {
return "string" + stringValue + "string";
}
@Benchmark
public String concatConstIntConst() {
return "string" + intValue + "string";
}
@Benchmark
public String concatConstIntegerConst() {
return "string" + integerValue + "string";
}
@Benchmark
public String concatConstFloatConst() {
return "string" + floatValue + "string";
}
@Benchmark
public String concatConstObjectConst() {
return "string" + objectValue + "string";
}
@Benchmark
public String concatConstBooleanConst() {
return "string" + booleanValue + "string";
}
@Benchmark
public String concatMix4String() {
// Investigate "profile pollution" between shared LFs that might eliminate some JIT optimizations
@ -114,6 +188,31 @@ public class StringConcat {
return s1 + s2 + s3 + s4;
}
@Benchmark
public String concat3String() {
return stringValue + stringValue + stringValue;
}
@Benchmark
public String concatStringBoolString() {
return stringValue + boolValue + stringValue;
}
@Benchmark
public String concatStringBooleanString() {
return stringValue + booleanValue + stringValue;
}
@Benchmark
public String concatStringIntString() {
return stringValue + intValue + stringValue;
}
@Benchmark
public String concatStringIntegerString() {
return stringValue + integerValue + stringValue;
}
@Benchmark
public String concatConst4String() {
return "string" + stringValue + stringValue + stringValue + stringValue;
@ -176,6 +275,15 @@ public class StringConcat {
+ f10 + ","+ f11 + ","+ f12 + ","+ f13 + ","+ f14 + ","+ f15 + ","+ f16 + ","+ f17 + ","+ f18 + ","+ f19 + ","
+ f20 + ","+ f21 + ","+ f22;
}
@Benchmark
public String concat30Mix() {
return f0 + "," + f1 + ","+ f2 + ","+ f3 + ","+ f4 + ","+ f5 + ","+ f6 + ","+ f7 + ","+ f8 + ","+ f9 + ","
+f10 + ","+f11 + ","+f12 + ","+ f13 + ","+ f14 + ","+ f15 + ","+ f16 + ","+ f17 + ","+ f18 + ","+ f19 + ","
+f20 + ","+f21 + ","+f22 + "," + boolValue + "," + booleanValue + "," + intValue + "," + integerValue
+ "," + floatValue + "," + byteValue + "," + objectValue;
}
@Benchmark
public String concat123String() {
return f0 + ","+ f1 + ","+ f2 + ","+ f3 + ","+ f4 + ","+ f5 + ","+ f6 + ","+ f7 + ","+ f8 + ","+ f9 + ","
@ -193,9 +301,38 @@ public class StringConcat {
+f120 + ","+f121 + ","+f122;
}
@Benchmark
public String concat13StringConst() {
return f0 + f1 + f2 + f3 + f4
+ f5 + f6 + f7 + f8 + f9
+f10 + f11 + f12 + """
A really long constant string. Such as a copyright header:
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
""";
}
@Benchmark
public String concat23StringConst() {
return f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + f0 + """
return f0 + f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + f13 + f14 + f15 + f16 + f17 + f18 + f19 + f20 + f21 + f22 + """
A really long constant string. Such as a copyright header:
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.