< prev index next >

test/runtime/Metaspace/DefineClass.java

Print this page
rev 12631 : 8174856: [TESTBUG] Missing DefineClass instances


 233             return count;
 234         }
 235         catch (Exception e) {
 236             throw new RuntimeException("Test failed because we can't read the class statistics!", e);
 237         }
 238     }
 239 
 240     private static void printClassStats(int expectedCount, boolean reportError) {
 241         int count = getClassStats("DefineClass");
 242         String res = "Should have " + expectedCount +
 243                      " DefineClass instances and we have: " + count;
 244         System.out.println(res);
 245         if (reportError && count != expectedCount) {
 246             throw new RuntimeException(res);
 247         }
 248     }
 249 
 250     public static final int ITERATIONS = 10;
 251 
 252     public static void main(String[] args) throws Exception {









 253         String myName = DefineClass.class.getName();
 254         byte[] buf = getBytecodes(myName.substring(myName.lastIndexOf(".") + 1));
 255         int iterations = (args.length > 1 ? Integer.parseInt(args[1]) : ITERATIONS);
 256 
 257         if (args.length == 0 || "defineClass".equals(args[0])) {
 258             MyClassLoader cl = new MyClassLoader();
 259             for (int i = 0; i < iterations; i++) {
 260                 try {
 261                     @SuppressWarnings("unchecked")
 262                     Class<DefineClass> dc = (Class<DefineClass>) cl.myDefineClass(myName, buf, 0, buf.length);
 263                     System.out.println(dc);
 264                 }
 265                 catch (LinkageError jle) {
 266                     // Can only define once!
 267                     if (i == 0) throw new Exception("Should succeed the first time.");
 268                 }
 269             }
 270             // We expect to have two instances of DefineClass here: the initial version in which we are
 271             // executing and another version which was loaded into our own classloader 'MyClassLoader'.
 272             // All the subsequent attempts to reload DefineClass into our 'MyClassLoader' should have failed.




 233             return count;
 234         }
 235         catch (Exception e) {
 236             throw new RuntimeException("Test failed because we can't read the class statistics!", e);
 237         }
 238     }
 239 
 240     private static void printClassStats(int expectedCount, boolean reportError) {
 241         int count = getClassStats("DefineClass");
 242         String res = "Should have " + expectedCount +
 243                      " DefineClass instances and we have: " + count;
 244         System.out.println(res);
 245         if (reportError && count != expectedCount) {
 246             throw new RuntimeException(res);
 247         }
 248     }
 249 
 250     public static final int ITERATIONS = 10;
 251 
 252     public static void main(String[] args) throws Exception {
 253 
 254         ObjectName diagCmd = new ObjectName("com.sun.management:type=DiagnosticCommand");
 255         String result = (String)mbserver.invoke(diagCmd , "vmCommandLine" ,
 256                                                 new Object[] { null }, new String[] {String[].class.getName()});
 257         if (result.contains("-Xcomp") || result.contains("-XX:-UseInterpreter")) {
 258             System.out.println("This test is not executed in in -Xcomp mode!");
 259             return;
 260         }
 261 
 262         String myName = DefineClass.class.getName();
 263         byte[] buf = getBytecodes(myName.substring(myName.lastIndexOf(".") + 1));
 264         int iterations = (args.length > 1 ? Integer.parseInt(args[1]) : ITERATIONS);
 265 
 266         if (args.length == 0 || "defineClass".equals(args[0])) {
 267             MyClassLoader cl = new MyClassLoader();
 268             for (int i = 0; i < iterations; i++) {
 269                 try {
 270                     @SuppressWarnings("unchecked")
 271                     Class<DefineClass> dc = (Class<DefineClass>) cl.myDefineClass(myName, buf, 0, buf.length);
 272                     System.out.println(dc);
 273                 }
 274                 catch (LinkageError jle) {
 275                     // Can only define once!
 276                     if (i == 0) throw new Exception("Should succeed the first time.");
 277                 }
 278             }
 279             // We expect to have two instances of DefineClass here: the initial version in which we are
 280             // executing and another version which was loaded into our own classloader 'MyClassLoader'.
 281             // All the subsequent attempts to reload DefineClass into our 'MyClassLoader' should have failed.


< prev index next >