< prev index next >

test/compiler/jvmci/compilerToVM/DisassembleCodeBlobTest.java

Print this page

        

@@ -40,44 +40,58 @@
  */
 
 package compiler.jvmci.compilerToVM;
 
 import jdk.vm.ci.hotspot.CompilerToVMHelper;
+import jdk.vm.ci.code.InstalledCode;
 import jdk.test.lib.Asserts;
 import sun.hotspot.code.NMethod;
 
 import java.util.List;
+import jdk.test.lib.Utils;
 
 public class DisassembleCodeBlobTest {
 
     public static void main(String[] args) {
         DisassembleCodeBlobTest test
                 = new DisassembleCodeBlobTest();
         List<CompileCodeTestCase> testCases
                 = CompileCodeTestCase.generate(/* bci = */ -1);
         testCases.addAll(CompileCodeTestCase.generate(/* bci = */ 0));
         testCases.forEach(test::check);
+        testCases.stream().findAny().ifPresent(test::checkZero);
         test.checkNull();
     }
 
     private void checkNull() {
-        String str = CompilerToVMHelper.disassembleCodeBlob(0L);
-        Asserts.assertNull(str, "not null string returned for null pointer");
+        Utils.runAndCheckException(
+                () -> CompilerToVMHelper.disassembleCodeBlob(null),
+                NullPointerException.class);
+    }
+    
+    private void checkZero(CompileCodeTestCase testCase) {
+        System.out.println("checkZero for " + testCase);
+        testCase.deoptimize();
+        InstalledCode installedCode = testCase.toInstalledCode();
+        String str = CompilerToVMHelper.disassembleCodeBlob(installedCode);
+        Asserts.assertNull(str, testCase
+                + " : non-null return value for invalid installCode");
     }
 
     private void check(CompileCodeTestCase testCase) {
         System.out.println(testCase);
         // to have a clean state
         NMethod nMethod = testCase.deoptimizeAndCompile();
         if (nMethod == null) {
             throw new Error(testCase + " : method is not compiled");
         }
-        String str = CompilerToVMHelper.disassembleCodeBlob(nMethod.address);
+        InstalledCode installedCode = testCase.toInstalledCode(); 
+        String str = CompilerToVMHelper.disassembleCodeBlob(installedCode);
         if (str != null) {
             Asserts.assertGT(str.length(), 0,
                    testCase +  " : returned string has to be non-zero length");
         }
-        String str2 = CompilerToVMHelper.disassembleCodeBlob(nMethod.address);
+        String str2 = CompilerToVMHelper.disassembleCodeBlob(installedCode);
         Asserts.assertEQ(str, str2,
                 testCase + " : 2nd invocation returned different value");
     }
 }
< prev index next >