diff --git a/test/hotspot/jtreg/compiler/c2/aarch64/TestTrampoline.java b/test/hotspot/jtreg/compiler/c2/aarch64/TestTrampoline.java index 114f7f9bfab59..40ed265c0754c 100644 --- a/test/hotspot/jtreg/compiler/c2/aarch64/TestTrampoline.java +++ b/test/hotspot/jtreg/compiler/c2/aarch64/TestTrampoline.java @@ -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; @@ -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()); }