2929 * @library /test/lib
3030 *
3131 * @requires os.arch=="amd64" | os.arch=="x86_64" | os.arch=="i386" | os.arch=="x86" | os.arch=="aarch64" | os.arch=="riscv64"
32+ * @requires vm.debug
3233 *
3334 * @run driver compiler.sharedstubs.SharedStubToInterpTest
3435 */
3536
3637package compiler .sharedstubs ;
3738
3839import java .util .ArrayList ;
39- import java .util .Iterator ;
4040import java .util .List ;
41+ import java .util .regex .Pattern ;
4142import jdk .test .lib .process .OutputAnalyzer ;
4243import jdk .test .lib .process .ProcessTools ;
4344
@@ -50,6 +51,7 @@ private static void runTest(String compiler, String test) throws Exception {
5051 command .add (compiler );
5152 command .add ("-XX:+UnlockDiagnosticVMOptions" );
5253 command .add ("-Xbatch" );
54+ command .add ("-XX:+PrintRelocations" );
5355 command .add ("-XX:CompileCommand=compileonly," + testClassName + "::" + "test" );
5456 command .add ("-XX:CompileCommand=dontinline," + testClassName + "::" + "test" );
5557 command .add ("-XX:CompileCommand=print," + testClassName + "::" + "test" );
@@ -82,48 +84,14 @@ public static void main(String[] args) throws Exception {
8284 }
8385 }
8486
85- private static String skipTo (Iterator <String > iter , String substring ) {
86- while (iter .hasNext ()) {
87- String nextLine = iter .next ();
88- if (nextLine .contains (substring )) {
89- return nextLine ;
90- }
91- }
92- return null ;
93- }
94-
9587 private static void checkOutput (OutputAnalyzer output ) {
96- Iterator <String > iter = output .asLines ().listIterator ();
97-
98- String match = skipTo (iter , "Compiled method" );
99- while (match != null && !match .contains ("Test::test" )) {
100- match = skipTo (iter , "Compiled method" );
101- }
102- if (match == null ) {
103- throw new RuntimeException ("Missing compiler output for the method 'test'" );
104- }
105-
106- while (iter .hasNext ()) {
107- String nextLine = iter .next ();
108- if (nextLine .contains ("{static_stub}" )) {
109- // Static stubs must be created at the end of the Stub section.
110- throw new RuntimeException ("Found {static_stub} before Deopt Handler Code" );
111- } else if (nextLine .contains ("{runtime_call DeoptimizationBlob}" )) {
112- // Shared static stubs are put after Deopt Handler Code.
113- break ;
114- }
115- }
116-
117- int foundStaticStubs = 0 ;
118- while (iter .hasNext ()) {
119- if (iter .next ().contains ("{static_stub}" )) {
120- foundStaticStubs += 1 ;
121- }
122- }
123-
124- final int expectedStaticStubs = 2 ;
125- if (foundStaticStubs != expectedStaticStubs ) {
126- throw new RuntimeException ("Found static stubs: " + foundStaticStubs + "; Expected static stubs: " + expectedStaticStubs );
88+ List <String > addrs = Pattern .compile ("\\ (static_stub\\ ) addr=(\\ w+) .*\\ [static_call=" )
89+ .matcher (output .getStdout ())
90+ .results ()
91+ .map (m -> m .group (1 ))
92+ .toList ();
93+ if (addrs .stream ().distinct ().count () >= addrs .size ()) {
94+ throw new RuntimeException ("No static stubs reused: distinct " + addrs .stream ().distinct ().count () + ", in total " + addrs .size ());
12795 }
12896 }
12997
0 commit comments