< prev index next >

test/hotspot/jtreg/runtime/exceptionMsgs/IncompatibleClassChangeError/IncompatibleClassChangeErrorTest.java

Print this page
rev 49017 : 8197405: Improve messages of AbstractMethodErrors and IncompatibleClassChangeErrors.
Reviewed-by: coleenp, dholmes
rev 49018 : [mq]: EditsDavidII.patch


  25 /**
  26  * @test
  27  * @summary Check that the verbose message of ICCE is printed correctly.
  28  *          The test forces errors in vtable stubs and interpreter.
  29  * @requires !(os.arch=="aarch64" | os.arch=="arm")
  30  * @library /test/lib /
  31  * @build sun.hotspot.WhiteBox
  32  * @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  33  * @compile IncompatibleClassChangeErrorTest.java
  34  * @compile ImplementsSomeInterfaces.jasm ICC_B.jasm
  35  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  36  *                   -XX:-BackgroundCompilation -XX:-Inline
  37  *                   -XX:CompileCommand=exclude,IncompatibleClassChangeErrorTest::test_iccInt
  38  *                   IncompatibleClassChangeErrorTest
  39  */
  40 
  41 import sun.hotspot.WhiteBox;
  42 import compiler.whitebox.CompilerWhiteBoxTest;
  43 import java.lang.reflect.Method;
  44 
  45 // This test assembles an errornous installation of classes.
  46 // First, compile the test by @compile. This results in a legal set
  47 // of classes.
  48 // Then, with jasm, generate incompatible classes that overwrite
  49 // the class files in the build directory.
  50 // Last, call the real tests throwing IncompatibleClassChangeErrors
  51 // and check the messages generated.
  52 public class IncompatibleClassChangeErrorTest {
  53 
  54     private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
  55 
  56     private static boolean enableChecks = true;
  57 
  58     private static String expectedErrorMessageInterpreted =
  59         "Class ImplementsSomeInterfaces " +
  60         "does not implement the requested interface InterfaceICCE1";
  61     private static String expectedErrorMessageCompiled =
  62         "Class ICC_B does not implement the requested interface ICC_iB";
  63         // old message: "vtable stub"
  64 
  65     public static void setup_test() {


  80             WHITE_BOX.enqueueMethodForCompilation(method, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
  81             if (!WHITE_BOX.isMethodCompiled(method)) {
  82                 throw new RuntimeException(method.getName() + " is not compiled");
  83             }
  84             method = ICC_C.class.getMethod("b");
  85             WHITE_BOX.enqueueMethodForCompilation(method, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
  86             if (!WHITE_BOX.isMethodCompiled(method)) {
  87                 throw new RuntimeException("ICC_C." + method.getName() + " is not compiled");
  88             }
  89             method = ICC_D.class.getMethod("b");
  90             WHITE_BOX.enqueueMethodForCompilation(method, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
  91             if (!WHITE_BOX.isMethodCompiled(method)) {
  92                 throw new RuntimeException("ICC_D." + method.getName() + " is not compiled");
  93             }
  94             method = ICC_E.class.getMethod("b");
  95             WHITE_BOX.enqueueMethodForCompilation(method, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
  96             if (!WHITE_BOX.isMethodCompiled(method)) {
  97                 throw new RuntimeException("ICC_E." + method.getName() + " is not compiled");
  98             }
  99         } catch (NoSuchMethodException e) { }

 100     }
 101 
 102     // Should never be compiled.
 103     public static void test_iccInt() {
 104         boolean caught_icc = false;
 105         try {
 106             InterfaceICCE1 objectInterface = new ImplementsSomeInterfaces();
 107             // IncompatibleClassChangeError gets thrown in
 108             // - TemplateTable::invokeinterface()
 109             // - LinkResolver::runtime_resolve_interface_method()
 110             objectInterface.aFunctionOfMyInterface();
 111         } catch (IncompatibleClassChangeError e) {
 112             caught_icc = true;
 113             String errorMsg = e.getMessage();
 114             if (enableChecks && !errorMsg.equals(expectedErrorMessageInterpreted)) {
 115                 System.out.println("Expected: " + expectedErrorMessageInterpreted + "\n" +
 116                                    "but got:  " + errorMsg);
 117                 throw new RuntimeException("Wrong error message of IncompatibleClassChangeError.");
 118             }
 119         } catch (Throwable e) {


 277     }
 278 }
 279 
 280 // Helper classes to test incompatible class change in itable stub.
 281 //
 282 // Class hierachy:
 283 //
 284 //          iA,iB   (interfaces)
 285 //          /|\ \
 286 //         C D E \
 287 //                B (bad class, missing interface implementation)
 288 
 289 interface ICC_iA {
 290     public void a();
 291 }
 292 
 293 interface ICC_iB {
 294     public void b();
 295 }
 296 
 297 // This is the errornous class. A variant of it not
 298 // implementing ICC_iB is copied into the test before
 299 // it is run.
 300 class ICC_B implements ICC_iA
 301                        // This interface is missing in the .jasm implementation.
 302                        , ICC_iB
 303                        {
 304     public void a() {
 305         System.out.print("B.a() ");
 306     }
 307 
 308     public void b() {
 309         System.out.print("B.b() ");
 310     }
 311 }
 312 
 313 class ICC_C implements ICC_iA, ICC_iB {
 314     public void a() {
 315         System.out.print("C.a() ");
 316     }
 317 




  25 /**
  26  * @test
  27  * @summary Check that the verbose message of ICCE is printed correctly.
  28  *          The test forces errors in vtable stubs and interpreter.
  29  * @requires !(os.arch=="aarch64" | os.arch=="arm")
  30  * @library /test/lib /
  31  * @build sun.hotspot.WhiteBox
  32  * @run driver ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
  33  * @compile IncompatibleClassChangeErrorTest.java
  34  * @compile ImplementsSomeInterfaces.jasm ICC_B.jasm
  35  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  36  *                   -XX:-BackgroundCompilation -XX:-Inline
  37  *                   -XX:CompileCommand=exclude,IncompatibleClassChangeErrorTest::test_iccInt
  38  *                   IncompatibleClassChangeErrorTest
  39  */
  40 
  41 import sun.hotspot.WhiteBox;
  42 import compiler.whitebox.CompilerWhiteBoxTest;
  43 import java.lang.reflect.Method;
  44 
  45 // This test assembles an errorneous installation of classes.
  46 // First, compile the test by @compile. This results in a legal set
  47 // of classes.
  48 // Then, with jasm, generate incompatible classes that overwrite
  49 // the class files in the build directory.
  50 // Last, call the real tests throwing IncompatibleClassChangeErrors
  51 // and check the messages generated.
  52 public class IncompatibleClassChangeErrorTest {
  53 
  54     private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
  55 
  56     private static boolean enableChecks = true;
  57 
  58     private static String expectedErrorMessageInterpreted =
  59         "Class ImplementsSomeInterfaces " +
  60         "does not implement the requested interface InterfaceICCE1";
  61     private static String expectedErrorMessageCompiled =
  62         "Class ICC_B does not implement the requested interface ICC_iB";
  63         // old message: "vtable stub"
  64 
  65     public static void setup_test() {


  80             WHITE_BOX.enqueueMethodForCompilation(method, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
  81             if (!WHITE_BOX.isMethodCompiled(method)) {
  82                 throw new RuntimeException(method.getName() + " is not compiled");
  83             }
  84             method = ICC_C.class.getMethod("b");
  85             WHITE_BOX.enqueueMethodForCompilation(method, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
  86             if (!WHITE_BOX.isMethodCompiled(method)) {
  87                 throw new RuntimeException("ICC_C." + method.getName() + " is not compiled");
  88             }
  89             method = ICC_D.class.getMethod("b");
  90             WHITE_BOX.enqueueMethodForCompilation(method, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
  91             if (!WHITE_BOX.isMethodCompiled(method)) {
  92                 throw new RuntimeException("ICC_D." + method.getName() + " is not compiled");
  93             }
  94             method = ICC_E.class.getMethod("b");
  95             WHITE_BOX.enqueueMethodForCompilation(method, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
  96             if (!WHITE_BOX.isMethodCompiled(method)) {
  97                 throw new RuntimeException("ICC_E." + method.getName() + " is not compiled");
  98             }
  99         } catch (NoSuchMethodException e) { }
 100         System.out.println("warmup done.");
 101     }
 102 
 103     // Should never be compiled.
 104     public static void test_iccInt() {
 105         boolean caught_icc = false;
 106         try {
 107             InterfaceICCE1 objectInterface = new ImplementsSomeInterfaces();
 108             // IncompatibleClassChangeError gets thrown in
 109             // - TemplateTable::invokeinterface()
 110             // - LinkResolver::runtime_resolve_interface_method()
 111             objectInterface.aFunctionOfMyInterface();
 112         } catch (IncompatibleClassChangeError e) {
 113             caught_icc = true;
 114             String errorMsg = e.getMessage();
 115             if (enableChecks && !errorMsg.equals(expectedErrorMessageInterpreted)) {
 116                 System.out.println("Expected: " + expectedErrorMessageInterpreted + "\n" +
 117                                    "but got:  " + errorMsg);
 118                 throw new RuntimeException("Wrong error message of IncompatibleClassChangeError.");
 119             }
 120         } catch (Throwable e) {


 278     }
 279 }
 280 
 281 // Helper classes to test incompatible class change in itable stub.
 282 //
 283 // Class hierachy:
 284 //
 285 //          iA,iB   (interfaces)
 286 //          /|\ \
 287 //         C D E \
 288 //                B (bad class, missing interface implementation)
 289 
 290 interface ICC_iA {
 291     public void a();
 292 }
 293 
 294 interface ICC_iB {
 295     public void b();
 296 }
 297 
 298 // This is the errorneous class. A variant of it not
 299 // implementing ICC_iB is copied into the test before
 300 // it is run.
 301 class ICC_B implements ICC_iA
 302                        // This interface is missing in the .jasm implementation.
 303                        , ICC_iB
 304                        {
 305     public void a() {
 306         System.out.print("B.a() ");
 307     }
 308 
 309     public void b() {
 310         System.out.print("B.b() ");
 311     }
 312 }
 313 
 314 class ICC_C implements ICC_iA, ICC_iB {
 315     public void a() {
 316         System.out.print("C.a() ");
 317     }
 318 


< prev index next >