< prev index next >

test/hotspot/jtreg/compiler/cha/StrengthReduceInterfaceCall.java

Print this page

        

@@ -51,10 +51,11 @@
 import jdk.internal.misc.Unsafe;
 import jdk.internal.org.objectweb.asm.ClassWriter;
 import jdk.internal.org.objectweb.asm.MethodVisitor;
 import jdk.internal.vm.annotation.DontInline;
 import sun.hotspot.WhiteBox;
+import sun.hotspot.code.NMethod;
 
 import java.io.IOException;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.invoke.MethodHandle;

@@ -693,14 +694,10 @@
     }
 
     public static final Unsafe U = Unsafe.getUnsafe();
 
     interface Test<T> {
-        boolean isCompiled();
-        void assertNotCompiled();
-        void assertCompiled();
-
         void call(T o);
         T receiver(int id);
 
         default Runnable monomophic() {
             return () -> {

@@ -731,18 +728,10 @@
                 call(receiver(1)); // 33%
                 call(receiver(2)); // 33%
             };
         }
 
-        default void compile(Runnable r) {
-            assertNotCompiled();
-            while(!isCompiled()) {
-                r.run();
-            }
-            assertCompiled();
-        }
-
         default void initialize(Class<?>... cs) {
             for (Class<?> c : cs) {
                 U.ensureClassInitialized(c);
             }
         }

@@ -787,18 +776,35 @@
                     throw new Error(e);
                 }
             }));
         }
 
-        @Override
-        public boolean isCompiled()     { return WB.isMethodCompiled(TEST); }
 
-        @Override
-        public void assertNotCompiled() { assertFalse(isCompiled()); }
+        public void compile(Runnable r) {
+            while (!WB.isMethodCompiled(TEST)) {
+                for (int i = 0; i < 100; i++) {
+                    r.run();
+                }
+            }
+            assertCompiled(); // record nmethod info
+        }
 
-        @Override
-        public void assertCompiled()    { assertTrue(isCompiled()); }
+        private NMethod prevNM = null;
+
+        public void assertNotCompiled() {
+            NMethod curNM = NMethod.get(TEST, false);
+            assertTrue(prevNM != null); // was previously compiled
+            assertTrue(curNM == null || prevNM.compile_id != curNM.compile_id); // either no nmethod present or recompiled
+            prevNM = curNM; // update nmethod info
+        }
+
+        public void assertCompiled() {
+            NMethod curNM = NMethod.get(TEST, false);
+            assertTrue(curNM != null); // nmethod is present
+            assertTrue(prevNM == null || prevNM.compile_id == curNM.compile_id); // no recompilations if nmethod present
+            prevNM = curNM; // update nmethod info
+        }
 
         @Override
         public void call(T i) {
             assertTrue(test(i) != WRONG);
         }
< prev index next >