< prev index next >

test/hotspot/jtreg/runtime/exceptionMsgs/AbstractMethodError/AbstractMethodErrorTest.java

Print this page




  82         test_ame6_compiled_itable_stub();
  83         enableChecks = true;
  84 
  85         // Compile
  86         if (!compile(AbstractMethodErrorTest.class, "test_ame5_compiled_vtable_stub") ||
  87             !compile(AbstractMethodErrorTest.class, "test_ame6_compiled_itable_stub") ||
  88             !compile(AME5_C.class, "mc") ||
  89             !compile(AME5_D.class, "mc") ||
  90             !compile(AME5_E.class, "mc") ||
  91             !compile(AME6_C.class, "mc") ||
  92             !compile(AME6_D.class, "mc") ||
  93             !compile(AME6_E.class, "mc")) {
  94             return false;
  95         }
  96 
  97         System.out.println("warmup done.");
  98         return true;
  99     }
 100 
 101     private static String expectedErrorMessageAME1_1 =
 102         "Missing implementation of resolved method 'abstract " +
 103         "java.lang.String anAbstractMethod()' of abstract class AME1_B.";
 104     private static String expectedErrorMessageAME1_2 =
 105         "Receiver class AME1_E does not define or inherit an implementation of the " +
 106         "resolved method 'abstract java.lang.String aFunctionOfMyInterface()' of " +
 107         "interface AME1_C.";
 108 
 109     public static void test_ame1() {
 110         AME1_B objectAbstract = new AME1_D();
 111         AME1_C objectInterface = new AME1_D();
 112         objectInterface.secondFunctionOfMyInterface();
 113         objectAbstract.anAbstractMethod();
 114         objectInterface.aFunctionOfMyInterface();
 115 
 116         try {
 117             objectAbstract = new AME1_E();
 118             // AbstractMethodError gets thrown in the interpreter at:
 119             // InterpreterGenerator::generate_abstract_entry
 120             objectAbstract.anAbstractMethod();
 121             throw new RuntimeException("Expected AbstractRuntimeError was not thrown.");
 122         } catch (AbstractMethodError e) {
 123             String errorMsg = e.getMessage();
 124             if (errorMsg == null) {
 125                 throw new RuntimeException("Caught AbstractMethodError with empty message.");
 126             } else if (!errorMsg.equals(expectedErrorMessageAME1_1)) {


 141             objectInterface.aFunctionOfMyInterface();
 142             throw new RuntimeException("Expected AbstractRuntimeError was not thrown.");
 143         } catch (AbstractMethodError e) {
 144             String errorMsg = e.getMessage();
 145             if (errorMsg == null) {
 146                 throw new RuntimeException("Caught AbstractMethodError with empty message.");
 147             } else if (!errorMsg.equals(expectedErrorMessageAME1_2)) {
 148                 // Thrown via InterpreterRuntime::throw_AbstractMethodErrorVerbose().
 149                 System.out.println("Expected: " + expectedErrorMessageAME1_2 + "\n" +
 150                                    "but got:  " + errorMsg);
 151                 throw new RuntimeException("Wrong error message of AbstractMethodError.");
 152             } else {
 153                 System.out.println("Passed with message: " + errorMsg);
 154             }
 155         } catch (Throwable e) {
 156             throw new RuntimeException("Caught unexpected exception: " + e);
 157         }
 158     }
 159 
 160     private static String expectedErrorMessageAME2_Interpreted =
 161         "Missing implementation of resolved method 'abstract " +
 162         "void aFunctionOfMyInterface()' of interface AME2_A.";
 163     private static String expectedErrorMessageAME2_Compiled =
 164         "Receiver class AME2_C does not define or inherit an implementation of the resolved method " +
 165         "'abstract void aFunctionOfMyInterface()' of interface AME2_A.";
 166 
 167     public AbstractMethodErrorTest() throws InstantiationException, IllegalAccessException {
 168         try {
 169             AME2_B myAbstract = new ImplementsAllFunctions();
 170             myAbstract.fun2();
 171             myAbstract.aFunctionOfMyInterface();
 172 
 173             // AME2_C does not implement the method
 174             // aFunctionOfMyInterface(). Expected runtime behavior is
 175             // throwing an AbstractMethodError.
 176             // The error will be thrown via throw_AbstractMethodErrorWithMethod()
 177             // if the template interpreter calls an abstract method by
 178             // entering the abstract method entry.
 179             myAbstract = new AME2_C();
 180             myAbstract.fun2();
 181             myAbstract.aFunctionOfMyInterface();
 182         } catch (SecurityException e) {
 183             e.printStackTrace();
 184         }
 185     }


 211                     // sparc misses the test case for LinkResolver::runtime_resolve_virtual_method().
 212                     seenCompiled = true;
 213                 } else {
 214                     System.out.println("Expected: " + expectedErrorMessageAME2_Interpreted + "\n" +
 215                                        "or:       " + expectedErrorMessageAME2_Compiled + "\n" +
 216                                        "but got:  " + errorMsg);
 217                     throw new RuntimeException("Wrong error message of AbstractMethodError.");
 218                 }
 219             }
 220         }
 221         if (!(seenInterpreted && seenCompiled)) {
 222             if (seenInterpreted) { System.out.println("Saw interpreted message."); }
 223             if (seenCompiled)    { System.out.println("Saw compiled message."); }
 224             throw new RuntimeException("Test did not produce wrong error messages for AbstractMethodError, " +
 225                                        "but it did not test both cases (interpreted and compiled).");
 226         }
 227     }
 228 
 229     private static String expectedErrorMessageAME3_1 =
 230         "Receiver class AME3_C does not define or inherit an implementation of the resolved method " +
 231         "'void ma()' of class AME3_A. Selected method is 'abstract void AME3_B.ma()'.";
 232 
 233     // Testing abstract class that extends a class that has an implementation.
 234     // Loop so that method gets eventually compiled/osred.
 235     public static void test_ame3_1() throws Exception {
 236         AME3_A c = new AME3_C();
 237 
 238         try {
 239             // Supposed to throw AME with verbose message.
 240             c.ma();
 241 
 242             throw new RuntimeException("Expected AbstractMethodError was not thrown.");
 243         } catch (AbstractMethodError e) {
 244             String errorMsg = e.getMessage();
 245 
 246             // Check the message obtained.
 247             if (errorMsg == null) {
 248                 throw new RuntimeException("Caught AbstractMethodError with empty message.");
 249             } else if (errorMsg.equals(expectedErrorMessageAME3_1)) {
 250                 // Expected test case thrown via LinkResolver::runtime_resolve_virtual_method().
 251                 System.out.println("Passed with message: " + errorMsg);
 252             } else {
 253                 System.out.println("Expected: " + expectedErrorMessageAME3_1 + "\n" +
 254                                    "but got:  " + errorMsg);
 255                 throw new RuntimeException("Wrong error message of AbstractMethodError.");
 256             }
 257         }
 258     }
 259 
 260     private static String expectedErrorMessageAME3_2 =
 261         "Receiver class AME3_C does not define or inherit an implementation of " +
 262         "the resolved method 'abstract void ma()' of abstract class AME3_B.";
 263 
 264     // Testing abstract class that extends a class that has an implementation.
 265     // Loop so that method gets eventually compiled/osred.
 266     public static void test_ame3_2() throws Exception {
 267         AME3_C c = new AME3_C();
 268 
 269         try {
 270             // Supposed to throw AME with verbose message.
 271             c.ma();
 272 
 273             throw new RuntimeException("Expected AbstractMethodError was not thrown.");
 274         } catch (AbstractMethodError e) {
 275             String errorMsg = e.getMessage();
 276 
 277             // Check the message obtained.
 278             if (errorMsg == null) {
 279                 throw new RuntimeException("Caught AbstractMethodError with empty message.");
 280             } else if (errorMsg.equals(expectedErrorMessageAME3_2)) {
 281                 // Expected test case thrown via LinkResolver::runtime_resolve_virtual_method().
 282                 System.out.println("Passed with message: " + errorMsg);
 283             } else {
 284                 System.out.println("Expected: " + expectedErrorMessageAME3_2 + "\n" +
 285                                    "but got:  " + errorMsg);
 286                 throw new RuntimeException("Wrong error message of AbstractMethodError.");
 287             }
 288         }
 289     }
 290 
 291     private static String expectedErrorMessageAME4 =
 292         "Missing implementation of resolved method 'abstract void ma()' of " +
 293         "abstract class AME4_B.";
 294 
 295     // Testing abstract class that extends a class that has an implementation.
 296     public static void test_ame4() throws Exception {
 297         AME4_C c = new AME4_C();
 298         AME4_D d = new AME4_D();
 299         AME4_E e = new AME4_E();  // Errorneous.
 300 
 301         AME4_A a;
 302         try {
 303             // Test: calls errorneous e.ma() in the last iteration.
 304             final int iterations = 10;
 305             for (int i = 0; i < iterations; i++) {
 306                 a = e;
 307                 if (i % 2 == 0 && i < iterations - 1) {
 308                     a = c;
 309                 }
 310                 if (i % 2 == 1 && i < iterations - 1) {
 311                     a = d;
 312                 }


 319             throw new RuntimeException("Expected AbstractMethodError was not thrown.");
 320         } catch (AbstractMethodError exc) {
 321             System.out.println();
 322             String errorMsg = exc.getMessage();
 323 
 324                 // Check the message obtained.
 325             if (enableChecks && errorMsg == null) {
 326                 throw new RuntimeException("Caught AbstractMethodError with empty message.");
 327             } else if (errorMsg.equals(expectedErrorMessageAME4)) {
 328                 // Expected test case.
 329                 System.out.println("Passed with message: " + errorMsg);
 330             } else if (enableChecks) {
 331                 System.out.println("Expected: " + expectedErrorMessageAME4 + "\n" +
 332                                    "but got:  " + errorMsg);
 333                 throw new RuntimeException("Wrong error message of AbstractMethodError.");
 334             }
 335         }
 336     }
 337 
 338     private static String expectedErrorMessageAME5_VtableStub =
 339         "Receiver class AME5_B does not define or inherit an implementation of the resolved method 'abstract void mc()' " +
 340         "of abstract class AME5_A.";
 341 
 342     // AbstractMethodErrors detected in vtable stubs.
 343     // Note: How can we verify that we really stepped through the vtable stub?
 344     // - Bimorphic inlining should not happen since we have no profiling data when
 345     //   we compile the method
 346     // - As a result, an inline cache call should be generated
 347     // - This inline cache call is patched into a real vtable call at the first
 348     //   re-resolve, which happens constantly during the first 10 iterations of the loop.
 349     // => we should be fine! :-)
 350     public static void test_ame5_compiled_vtable_stub() {
 351         // Allocated the objects we need and call a valid method.
 352         boolean caught_ame = false;
 353         AME5_B b = new AME5_B();
 354         AME5_C c = new AME5_C();
 355         AME5_D d = new AME5_D();
 356         AME5_E e = new AME5_E();
 357         b.ma();
 358         c.ma();
 359         d.ma();


 392                                    "but got:  " + errorMsg);
 393                 System.out.println(exc);
 394                 throw new RuntimeException("Wrong error message of AbstractMethodError.");
 395             }
 396             if (enableChecks) {
 397                 System.out.println("Passed with message: " + errorMsg);
 398             }
 399         } catch (Throwable exc) {
 400 
 401         throw exc;
 402         }
 403 
 404         // Check that we got the exception at some point.
 405         if (enableChecks && !caught_ame) {
 406             throw new RuntimeException("Expected AbstractMethodError was not thrown.");
 407         }
 408     }
 409 
 410     private static String expectedErrorMessageAME6_ItableStub =
 411         "Receiver class AME6_B does not define or inherit an implementation of the resolved" +
 412         " method 'abstract void mc()' of interface AME6_A.";
 413 
 414     // -------------------------------------------------------------------------
 415     // AbstractMethodErrors detected in itable stubs.
 416     // Note: How can we verify that we really stepped through the itable stub?
 417     // - Bimorphic inlining should not happen since we have no profiling data when
 418     //   we compile the method
 419     // - As a result, an inline cache call should be generated
 420     // - This inline cache call is patched into a real vtable call at the first
 421     //   re-resolve, which happens constantly during the first 10 iterations of the loop.
 422     // => we should be fine! :-)
 423     public static void test_ame6_compiled_itable_stub() {
 424         // Allocated the objects we need and call a valid method.
 425         boolean caught_ame = false;
 426         AME6_B b = new AME6_B();
 427         AME6_C c = new AME6_C();
 428         AME6_D d = new AME6_D();
 429         AME6_E e = new AME6_E();
 430         b.ma();
 431         c.ma();
 432         d.ma();




  82         test_ame6_compiled_itable_stub();
  83         enableChecks = true;
  84 
  85         // Compile
  86         if (!compile(AbstractMethodErrorTest.class, "test_ame5_compiled_vtable_stub") ||
  87             !compile(AbstractMethodErrorTest.class, "test_ame6_compiled_itable_stub") ||
  88             !compile(AME5_C.class, "mc") ||
  89             !compile(AME5_D.class, "mc") ||
  90             !compile(AME5_E.class, "mc") ||
  91             !compile(AME6_C.class, "mc") ||
  92             !compile(AME6_D.class, "mc") ||
  93             !compile(AME6_E.class, "mc")) {
  94             return false;
  95         }
  96 
  97         System.out.println("warmup done.");
  98         return true;
  99     }
 100 
 101     private static String expectedErrorMessageAME1_1 =
 102         "Missing implementation of resolved method abstract " +
 103         "anAbstractMethod()Ljava/lang/String; of abstract class AME1_B.";
 104     private static String expectedErrorMessageAME1_2 =
 105         "Receiver class AME1_E does not define or inherit an implementation of the " +
 106         "resolved method abstract aFunctionOfMyInterface()Ljava/lang/String; of " +
 107         "interface AME1_C.";
 108 
 109     public static void test_ame1() {
 110         AME1_B objectAbstract = new AME1_D();
 111         AME1_C objectInterface = new AME1_D();
 112         objectInterface.secondFunctionOfMyInterface();
 113         objectAbstract.anAbstractMethod();
 114         objectInterface.aFunctionOfMyInterface();
 115 
 116         try {
 117             objectAbstract = new AME1_E();
 118             // AbstractMethodError gets thrown in the interpreter at:
 119             // InterpreterGenerator::generate_abstract_entry
 120             objectAbstract.anAbstractMethod();
 121             throw new RuntimeException("Expected AbstractRuntimeError was not thrown.");
 122         } catch (AbstractMethodError e) {
 123             String errorMsg = e.getMessage();
 124             if (errorMsg == null) {
 125                 throw new RuntimeException("Caught AbstractMethodError with empty message.");
 126             } else if (!errorMsg.equals(expectedErrorMessageAME1_1)) {


 141             objectInterface.aFunctionOfMyInterface();
 142             throw new RuntimeException("Expected AbstractRuntimeError was not thrown.");
 143         } catch (AbstractMethodError e) {
 144             String errorMsg = e.getMessage();
 145             if (errorMsg == null) {
 146                 throw new RuntimeException("Caught AbstractMethodError with empty message.");
 147             } else if (!errorMsg.equals(expectedErrorMessageAME1_2)) {
 148                 // Thrown via InterpreterRuntime::throw_AbstractMethodErrorVerbose().
 149                 System.out.println("Expected: " + expectedErrorMessageAME1_2 + "\n" +
 150                                    "but got:  " + errorMsg);
 151                 throw new RuntimeException("Wrong error message of AbstractMethodError.");
 152             } else {
 153                 System.out.println("Passed with message: " + errorMsg);
 154             }
 155         } catch (Throwable e) {
 156             throw new RuntimeException("Caught unexpected exception: " + e);
 157         }
 158     }
 159 
 160     private static String expectedErrorMessageAME2_Interpreted =
 161         "Missing implementation of resolved method abstract " +
 162         "aFunctionOfMyInterface()V of interface AME2_A.";
 163     private static String expectedErrorMessageAME2_Compiled =
 164         "Receiver class AME2_C does not define or inherit an implementation of the resolved method " +
 165         "abstract aFunctionOfMyInterface()V of interface AME2_A.";
 166 
 167     public AbstractMethodErrorTest() throws InstantiationException, IllegalAccessException {
 168         try {
 169             AME2_B myAbstract = new ImplementsAllFunctions();
 170             myAbstract.fun2();
 171             myAbstract.aFunctionOfMyInterface();
 172 
 173             // AME2_C does not implement the method
 174             // aFunctionOfMyInterface(). Expected runtime behavior is
 175             // throwing an AbstractMethodError.
 176             // The error will be thrown via throw_AbstractMethodErrorWithMethod()
 177             // if the template interpreter calls an abstract method by
 178             // entering the abstract method entry.
 179             myAbstract = new AME2_C();
 180             myAbstract.fun2();
 181             myAbstract.aFunctionOfMyInterface();
 182         } catch (SecurityException e) {
 183             e.printStackTrace();
 184         }
 185     }


 211                     // sparc misses the test case for LinkResolver::runtime_resolve_virtual_method().
 212                     seenCompiled = true;
 213                 } else {
 214                     System.out.println("Expected: " + expectedErrorMessageAME2_Interpreted + "\n" +
 215                                        "or:       " + expectedErrorMessageAME2_Compiled + "\n" +
 216                                        "but got:  " + errorMsg);
 217                     throw new RuntimeException("Wrong error message of AbstractMethodError.");
 218                 }
 219             }
 220         }
 221         if (!(seenInterpreted && seenCompiled)) {
 222             if (seenInterpreted) { System.out.println("Saw interpreted message."); }
 223             if (seenCompiled)    { System.out.println("Saw compiled message."); }
 224             throw new RuntimeException("Test did not produce wrong error messages for AbstractMethodError, " +
 225                                        "but it did not test both cases (interpreted and compiled).");
 226         }
 227     }
 228 
 229     private static String expectedErrorMessageAME3_1 =
 230         "Receiver class AME3_C does not define or inherit an implementation of the resolved method " +
 231         "ma()V of class AME3_A. Selected method is abstract AME3_B.ma()V.";
 232 
 233     // Testing abstract class that extends a class that has an implementation.
 234     // Loop so that method gets eventually compiled/osred.
 235     public static void test_ame3_1() throws Exception {
 236         AME3_A c = new AME3_C();
 237 
 238         try {
 239             // Supposed to throw AME with verbose message.
 240             c.ma();
 241 
 242             throw new RuntimeException("Expected AbstractMethodError was not thrown.");
 243         } catch (AbstractMethodError e) {
 244             String errorMsg = e.getMessage();
 245 
 246             // Check the message obtained.
 247             if (errorMsg == null) {
 248                 throw new RuntimeException("Caught AbstractMethodError with empty message.");
 249             } else if (errorMsg.equals(expectedErrorMessageAME3_1)) {
 250                 // Expected test case thrown via LinkResolver::runtime_resolve_virtual_method().
 251                 System.out.println("Passed with message: " + errorMsg);
 252             } else {
 253                 System.out.println("Expected: " + expectedErrorMessageAME3_1 + "\n" +
 254                                    "but got:  " + errorMsg);
 255                 throw new RuntimeException("Wrong error message of AbstractMethodError.");
 256             }
 257         }
 258     }
 259 
 260     private static String expectedErrorMessageAME3_2 =
 261         "Receiver class AME3_C does not define or inherit an implementation of " +
 262         "the resolved method abstract ma()V of abstract class AME3_B.";
 263 
 264     // Testing abstract class that extends a class that has an implementation.
 265     // Loop so that method gets eventually compiled/osred.
 266     public static void test_ame3_2() throws Exception {
 267         AME3_C c = new AME3_C();
 268 
 269         try {
 270             // Supposed to throw AME with verbose message.
 271             c.ma();
 272 
 273             throw new RuntimeException("Expected AbstractMethodError was not thrown.");
 274         } catch (AbstractMethodError e) {
 275             String errorMsg = e.getMessage();
 276 
 277             // Check the message obtained.
 278             if (errorMsg == null) {
 279                 throw new RuntimeException("Caught AbstractMethodError with empty message.");
 280             } else if (errorMsg.equals(expectedErrorMessageAME3_2)) {
 281                 // Expected test case thrown via LinkResolver::runtime_resolve_virtual_method().
 282                 System.out.println("Passed with message: " + errorMsg);
 283             } else {
 284                 System.out.println("Expected: " + expectedErrorMessageAME3_2 + "\n" +
 285                                    "but got:  " + errorMsg);
 286                 throw new RuntimeException("Wrong error message of AbstractMethodError.");
 287             }
 288         }
 289     }
 290 
 291     private static String expectedErrorMessageAME4 =
 292         "Missing implementation of resolved method abstract ma()V of " +
 293         "abstract class AME4_B.";
 294 
 295     // Testing abstract class that extends a class that has an implementation.
 296     public static void test_ame4() throws Exception {
 297         AME4_C c = new AME4_C();
 298         AME4_D d = new AME4_D();
 299         AME4_E e = new AME4_E();  // Errorneous.
 300 
 301         AME4_A a;
 302         try {
 303             // Test: calls errorneous e.ma() in the last iteration.
 304             final int iterations = 10;
 305             for (int i = 0; i < iterations; i++) {
 306                 a = e;
 307                 if (i % 2 == 0 && i < iterations - 1) {
 308                     a = c;
 309                 }
 310                 if (i % 2 == 1 && i < iterations - 1) {
 311                     a = d;
 312                 }


 319             throw new RuntimeException("Expected AbstractMethodError was not thrown.");
 320         } catch (AbstractMethodError exc) {
 321             System.out.println();
 322             String errorMsg = exc.getMessage();
 323 
 324                 // Check the message obtained.
 325             if (enableChecks && errorMsg == null) {
 326                 throw new RuntimeException("Caught AbstractMethodError with empty message.");
 327             } else if (errorMsg.equals(expectedErrorMessageAME4)) {
 328                 // Expected test case.
 329                 System.out.println("Passed with message: " + errorMsg);
 330             } else if (enableChecks) {
 331                 System.out.println("Expected: " + expectedErrorMessageAME4 + "\n" +
 332                                    "but got:  " + errorMsg);
 333                 throw new RuntimeException("Wrong error message of AbstractMethodError.");
 334             }
 335         }
 336     }
 337 
 338     private static String expectedErrorMessageAME5_VtableStub =
 339         "Receiver class AME5_B does not define or inherit an implementation of the resolved method abstract mc()V " +
 340         "of abstract class AME5_A.";
 341 
 342     // AbstractMethodErrors detected in vtable stubs.
 343     // Note: How can we verify that we really stepped through the vtable stub?
 344     // - Bimorphic inlining should not happen since we have no profiling data when
 345     //   we compile the method
 346     // - As a result, an inline cache call should be generated
 347     // - This inline cache call is patched into a real vtable call at the first
 348     //   re-resolve, which happens constantly during the first 10 iterations of the loop.
 349     // => we should be fine! :-)
 350     public static void test_ame5_compiled_vtable_stub() {
 351         // Allocated the objects we need and call a valid method.
 352         boolean caught_ame = false;
 353         AME5_B b = new AME5_B();
 354         AME5_C c = new AME5_C();
 355         AME5_D d = new AME5_D();
 356         AME5_E e = new AME5_E();
 357         b.ma();
 358         c.ma();
 359         d.ma();


 392                                    "but got:  " + errorMsg);
 393                 System.out.println(exc);
 394                 throw new RuntimeException("Wrong error message of AbstractMethodError.");
 395             }
 396             if (enableChecks) {
 397                 System.out.println("Passed with message: " + errorMsg);
 398             }
 399         } catch (Throwable exc) {
 400 
 401         throw exc;
 402         }
 403 
 404         // Check that we got the exception at some point.
 405         if (enableChecks && !caught_ame) {
 406             throw new RuntimeException("Expected AbstractMethodError was not thrown.");
 407         }
 408     }
 409 
 410     private static String expectedErrorMessageAME6_ItableStub =
 411         "Receiver class AME6_B does not define or inherit an implementation of the resolved" +
 412         " method abstract mc()V of interface AME6_A.";
 413 
 414     // -------------------------------------------------------------------------
 415     // AbstractMethodErrors detected in itable stubs.
 416     // Note: How can we verify that we really stepped through the itable stub?
 417     // - Bimorphic inlining should not happen since we have no profiling data when
 418     //   we compile the method
 419     // - As a result, an inline cache call should be generated
 420     // - This inline cache call is patched into a real vtable call at the first
 421     //   re-resolve, which happens constantly during the first 10 iterations of the loop.
 422     // => we should be fine! :-)
 423     public static void test_ame6_compiled_itable_stub() {
 424         // Allocated the objects we need and call a valid method.
 425         boolean caught_ame = false;
 426         AME6_B b = new AME6_B();
 427         AME6_C c = new AME6_C();
 428         AME6_D d = new AME6_D();
 429         AME6_E e = new AME6_E();
 430         b.ma();
 431         c.ma();
 432         d.ma();


< prev index next >