1 /* |
1 /* |
|
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2017 SAP SE. All rights reserved. |
3 * Copyright (c) 2017 SAP SE. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
5 * |
5 * This code is free software; you can redistribute it and/or modify it |
6 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * under the terms of the GNU General Public License version 2 only, as |
27 * @requires vm.compMode != "Xcomp" |
28 * @requires vm.compMode != "Xcomp" |
28 * @summary Failures during class definition can lead to memory leaks in metaspace |
29 * @summary Failures during class definition can lead to memory leaks in metaspace |
29 * @library /test/lib |
30 * @library /test/lib |
30 * @run main/othervm test.DefineClass defineClass |
31 * @run main/othervm test.DefineClass defineClass |
31 * @run main/othervm test.DefineClass defineSystemClass |
32 * @run main/othervm test.DefineClass defineSystemClass |
32 * @run main/othervm -XX:+UnlockDiagnosticVMOptions |
33 * @run main/othervm -XX:+AllowParallelDefineClass |
33 -XX:+UnsyncloadClass -XX:+AllowParallelDefineClass |
|
34 test.DefineClass defineClassParallel |
34 test.DefineClass defineClassParallel |
35 * @run main/othervm -XX:+UnlockDiagnosticVMOptions |
35 * @run main/othervm -XX:-AllowParallelDefineClass |
36 -XX:+UnsyncloadClass -XX:-AllowParallelDefineClass |
|
37 test.DefineClass defineClassParallel |
|
38 * @run main/othervm -XX:+UnlockDiagnosticVMOptions |
|
39 -XX:-UnsyncloadClass -XX:+AllowParallelDefineClass |
|
40 test.DefineClass defineClassParallel |
|
41 * @run main/othervm -XX:+UnlockDiagnosticVMOptions |
|
42 -XX:-UnsyncloadClass -XX:-AllowParallelDefineClass |
|
43 test.DefineClass defineClassParallel |
36 test.DefineClass defineClassParallel |
44 * @run main/othervm -Djdk.attach.allowAttachSelf test.DefineClass redefineClass |
37 * @run main/othervm -Djdk.attach.allowAttachSelf test.DefineClass redefineClass |
45 * @run main/othervm -Djdk.attach.allowAttachSelf test.DefineClass redefineClassWithError |
38 * @run main/othervm -Djdk.attach.allowAttachSelf test.DefineClass redefineClassWithError |
46 * @author volker.simonis@gmail.com |
39 * @author volker.simonis@gmail.com |
47 */ |
40 */ |
124 @SuppressWarnings("unchecked") |
117 @SuppressWarnings("unchecked") |
125 Class<DefineClass> dc = (Class<DefineClass>) pcl.myDefineClass(DefineClass.class.getName(), buf, 0, buf.length); |
118 Class<DefineClass> dc = (Class<DefineClass>) pcl.myDefineClass(DefineClass.class.getName(), buf, 0, buf.length); |
126 } |
119 } |
127 catch (LinkageError jle) { |
120 catch (LinkageError jle) { |
128 // Expected with a parallel capable class loader and |
121 // Expected with a parallel capable class loader and |
129 // -XX:+UnsyncloadClass or -XX:+AllowParallelDefineClass |
122 // -XX:+AllowParallelDefineClass |
130 pcl.incrementLinkageErrors(); |
123 pcl.incrementLinkageErrors(); |
131 } |
124 } |
132 |
125 |
133 } |
126 } |
134 } |
127 } |
318 for (int i = 0; i < iterations; i++) { |
311 for (int i = 0; i < iterations; i++) { |
319 threads[i].join(); |
312 threads[i].join(); |
320 } |
313 } |
321 System.out.print("Counted " + pcl.getLinkageErrors() + " LinkageErrors "); |
314 System.out.print("Counted " + pcl.getLinkageErrors() + " LinkageErrors "); |
322 System.out.println(pcl.getLinkageErrors() == 0 ? |
315 System.out.println(pcl.getLinkageErrors() == 0 ? |
323 "" : "(use -XX:+UnsyncloadClass and/or -XX:+AllowParallelDefineClass to avoid this)"); |
316 "" : "(use -XX:+AllowParallelDefineClass to avoid this)"); |
324 System.gc(); |
317 System.gc(); |
325 System.out.println("System.gc()"); |
318 System.out.println("System.gc()"); |
326 // After System.gc() we expect to remain with two instances: one is the initial version which is |
319 // After System.gc() we expect to remain with two instances: one is the initial version which is |
327 // kept alive by this main method and another one in the parallel class loader. |
320 // kept alive by this main method and another one in the parallel class loader. |
328 printClassStats(2, true); |
321 printClassStats(2, true); |