Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions test/hotspot/jtreg/compiler/c2/aarch64/TestTrampoline.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package compiler.c2.aarch64;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Iterator;
import jdk.test.lib.process.OutputAnalyzer;
Expand Down Expand Up @@ -96,6 +97,26 @@ private static void test(String s, int i) {

public static void main(String[] args) {
String s = "Returns the char value at the specified index.";

boolean isWindows = System.getProperty("os.name").startsWith("Windows");
if (isWindows) {
/*
Depending on the Windows code page, the UTF-16 path in the String.charAt method
may be executed during JVM startup. However, it may not execute often enough to
cause it to be inlined by C2. In this case, C2 may not fully inline the
String.charAt method, resulting in the unexpected generation of trampolines.
Therefore, we execute the UTF-16 path in the String.charAt method in a loop
enough times to ensure that it will be inlined by C2.
*/
String jnuEncoding = System.getProperty("sun.jnu.encoding");
if (jnuEncoding != null && Charset.isSupported(jnuEncoding)) {
byte[] bytes = s.getBytes(Charset.forName(jnuEncoding));

for (int i = 0; i < ITERATIONS_TO_HEAT_LOOP; ++i) {
String encoded = new String(bytes, Charset.forName(jnuEncoding));
}
}
}
for (int i = 0; i < ITERATIONS_TO_HEAT_LOOP; ++i) {
test(s, i % s.length());
}
Expand Down
Loading