ADDITIONAL SYSTEM INFORMATION :
Reproduced with JDK 11–22 EA (Corretto latest nightly build):
1. MacOS 14.x, Intel x64
2. MacOS 11.x, Apple M1
3. Linux (Ubuntu 16.04.7), Intel x64
4. Windows 10, Intel x64
A DESCRIPTION OF THE PROBLEM :
C2 compilation RAM and time requirements to optimise `v1 + " " + v2 + " " + ... + " " + vn` statement grow exponentially with each added field and reaches 2GB/20s when fields number is maxed (i.e. increasing it further causes C2 compilation to fail). May be related to JEP 280. It does mention possible performance regressions in the "Risks" section, but it the same time states "Startup time and time to performance do not regress beyond reasonable levels" as one of it's success goals.
REGRESSION : Last worked in version 8u401
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run "Source code for an executable test case" with JDK 22 with "-XX:CompileCommand=MemStat,Test::toString,print" command line option. C2 compilation reports ~1GB of RAM used (on MacOS with Intel CPU — 2GB). Alternatively any JDK >= 11 can by used, but observing compilation memory usage will require enabling and checking NMT frequently.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compiler uses amount of memory similar to JDK 8 (i.e. much less than 100MB).
ACTUAL -
Compilation reports below.
MacOS (Intel) with 123 fields (increasing number further causes C2 compilation err):
> total NA RA result #nodes time type #rc thread method
> 2099999784 111517488 1974482496 ok 230825 20.841 c2 2 0x00007fb3a7027600 Test::toString(()Ljava/lang/String;)
MacOS (Apple) with 123 fields:
> total NA RA result #nodes time type #rc thread method
> 867302816 64827120 787501632 ok 157349 4,776 c2 2 0x0000000139048400 Test::toString(()Ljava/lang/String;)
Ubuntu 16.04 (Intel) with 123 fields:
> total NA RA result #nodes time type #rc thread method
> 937798144 67281720 855640704 ok 131653 27.425 c2 2 0x00007faa5414d700 Test::toString(()Ljava/lang/String;)
If fields number is increased to 181 then total caps at 1.7GB (increasing fields number further causes C2 compilation err).
On Windows (Intel) with 123 fields:
> total NA RA result #nodes time type #rc thread method
> 941489704 68394472 858186784 ok 125189 8.510 c2 2 0x00000150f1034170 Test::toString(()Ljava/lang/String;)
If fields number is increased to 181 then total caps at 1.7GB (increasing fields number further causes C2 compilation err).
---------- BEGIN SOURCE ----------
public class Test {
public static void main(String[] args) {
long start = System.currentTimeMillis();
int sink = 0;
while (System.currentTimeMillis() - start < 60000) {
sink += new Test().toString().length();
}
System.out.println(sink);
}
private String
f0="1", f1="1", f2="1", f3="1", f4="1", f5="1", f6="1", f7="1", f8="1", f9="1",
f10="1", f11="1", f12="1", f13="1", f14="1", f15="1", f16="1", f17="1", f18="1", f19="1",
f20="1", f21="1", f22="1", f23="1", f24="1", f25="1", f26="1", f27="1", f28="1", f29="1",
f30="1", f31="1", f32="1", f33="1", f34="1", f35="1", f36="1", f37="1", f38="1", f39="1",
f40="1", f41="1", f42="1", f43="1", f44="1", f45="1", f46="1", f47="1", f48="1", f49="1",
f50="1", f51="1", f52="1", f53="1", f54="1", f55="1", f56="1", f57="1", f58="1", f59="1",
f60="1", f61="1", f62="1", f63="1", f64="1", f65="1", f66="1", f67="1", f68="1", f69="1",
f70="1", f71="1", f72="1", f73="1", f74="1", f75="1", f76="1", f77="1", f78="1", f79="1",
f80="1", f81="1", f82="1", f83="1", f84="1", f85="1", f86="1", f87="1", f88="1", f89="1",
f90="1", f91="1", f92="1", f93="1", f94="1", f95="1", f96="1", f97="1", f98="1", f99="1",
f100="1",f101="1",f102="1",f103="1",f104="1",f105="1",f106="1",f107="1",f108="1",f109="1",
f110="1",f111="1",f112="1",f113="1",f114="1",f115="1",f116="1",f117="1",f118="1",f119="1",
f120="1",f121="1",f122="1";
@Override
public String toString() {
return f0+","+ f1+","+ f2+","+ f3+","+ f4+","+ f5+","+ f6+","+ f7+","+ f8+","+ f9+","
+ f10+","+ f11+","+ f12+","+ f13+","+ f14+","+ f15+","+ f16+","+ f17+","+ f18+","+ f19+","
+ f20+","+ f21+","+ f22+","+ f23+","+ f24+","+ f25+","+ f26+","+ f27+","+ f28+","+ f29+","
+ f30+","+ f31+","+ f32+","+ f33+","+ f34+","+ f35+","+ f36+","+ f37+","+ f38+","+ f39+","
+ f40+","+ f41+","+ f42+","+ f43+","+ f44+","+ f45+","+ f46+","+ f47+","+ f48+","+ f49+","
+ f50+","+ f51+","+ f52+","+ f53+","+ f54+","+ f55+","+ f56+","+ f57+","+ f58+","+ f59+","
+ f60+","+ f61+","+ f62+","+ f63+","+ f64+","+ f65+","+ f66+","+ f67+","+ f68+","+ f69+","
+ f70+","+ f71+","+ f72+","+ f73+","+ f74+","+ f75+","+ f76+","+ f77+","+ f78+","+ f79+","
+ f80+","+ f81+","+ f82+","+ f83+","+ f84+","+ f85+","+ f86+","+ f87+","+ f88+","+ f89+","
+ f90+","+ f91+","+ f92+","+ f93+","+ f94+","+ f95+","+ f96+","+ f97+","+ f98+","+ f99+","
+f100+","+f101+","+f102+","+f103+","+f104+","+f105+","+f106+","+f107+","+f108+","+f109+","
+f110+","+f111+","+f112+","+f113+","+f114+","+f115+","+f116+","+f117+","+f118+","+f119+","
+f120+","+f121+","+f122;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
1. disable affected method compilation at runtime (-XX:CompileCommand=exclude,...), but requires time consuming search for such methods
2. compile with "-XDstringConcat=inline" option
FREQUENCY : always