Mercurial > hg > truffle
annotate test/compiler/classUnloading/methodUnloading/TestMethodUnloading.java @ 20766:d961743b7897
Merge
author | asaha |
---|---|
date | Fri, 31 Oct 2014 15:22:44 -0700 |
parents | d2c5fee67143 |
children |
rev | line source |
---|---|
20290
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
1 /* |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
4 * |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
8 * |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
13 * accompanied this code). |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
14 * |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
18 * |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
21 * questions. |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
22 */ |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
23 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
24 import sun.hotspot.WhiteBox; |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
25 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
26 import java.lang.reflect.Method; |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
27 import java.net.URL; |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
28 import java.net.URLClassLoader; |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
29 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
30 /* |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
31 * @test MethodUnloadingTest |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
32 * @bug 8029443 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
33 * @summary "Tests the unloading of methods to to class unloading" |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
34 * @library /testlibrary /testlibrary/whitebox |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
35 * @build TestMethodUnloading |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
36 * @build WorkerClass |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
37 * @run main ClassFileInstaller sun.hotspot.WhiteBox |
20384
d2c5fee67143
8055657: Test compiler/classUnloading/methodUnloading/TestMethodUnloading.java does not work with non-default GC
thartmann
parents:
20290
diff
changeset
|
38 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-BackgroundCompilation -XX:-UseCompressedOops -XX:CompileOnly=TestMethodUnloading::doWork TestMethodUnloading |
20290
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
39 */ |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
40 public class TestMethodUnloading { |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
41 private static final String workerClassName = "WorkerClass"; |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
42 private static int work = -1; |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
43 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
44 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
45 private static int COMP_LEVEL_SIMPLE = 1; |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
46 private static int COMP_LEVEL_FULL_OPTIMIZATION = 4; |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
47 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
48 /** |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
49 * Does some work by either using the workerClass or locally producing values. |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
50 * @param workerClass Class performing some work (will be unloaded) |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
51 * @param useWorker If true the workerClass is used |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
52 */ |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
53 static private void doWork(Class<?> workerClass, boolean useWorker) throws InstantiationException, IllegalAccessException { |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
54 if (useWorker) { |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
55 // Create a new instance |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
56 Object worker = workerClass.newInstance(); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
57 // We would like to call a method of WorkerClass here but we cannot cast to WorkerClass |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
58 // because the class was loaded by a different class loader. One solution would be to use |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
59 // reflection but since we want C2 to implement the call as an optimized IC we call |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
60 // Object::hashCode() here which actually calls WorkerClass::hashCode(). |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
61 // C2 will then implement this call as an optimized IC that points to a to-interpreter stub |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
62 // referencing the Method* for WorkerClass::hashCode(). |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
63 work = worker.hashCode(); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
64 if (work != 42) { |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
65 new RuntimeException("Work not done"); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
66 } |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
67 } else { |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
68 // Do some important work here |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
69 work = 1; |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
70 } |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
71 } |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
72 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
73 /** |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
74 * Makes sure that method is compiled by forcing compilation if not yet compiled. |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
75 * @param m Method to be checked |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
76 */ |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
77 static private void makeSureIsCompiled(Method m) { |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
78 // Make sure background compilation is disabled |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
79 if (WHITE_BOX.getBooleanVMFlag("BackgroundCompilation")) { |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
80 throw new RuntimeException("Background compilation enabled"); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
81 } |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
82 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
83 // Check if already compiled |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
84 if (!WHITE_BOX.isMethodCompiled(m)) { |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
85 // If not, try to compile it with C2 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
86 if(!WHITE_BOX.enqueueMethodForCompilation(m, COMP_LEVEL_FULL_OPTIMIZATION)) { |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
87 // C2 compiler not available, try to compile with C1 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
88 WHITE_BOX.enqueueMethodForCompilation(m, COMP_LEVEL_SIMPLE); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
89 } |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
90 // Because background compilation is disabled, method should now be compiled |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
91 if(!WHITE_BOX.isMethodCompiled(m)) { |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
92 throw new RuntimeException(m + " not compiled"); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
93 } |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
94 } |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
95 } |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
96 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
97 /** |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
98 * This test creates stale Method* metadata in a to-interpreter stub of an optimized IC. |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
99 * |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
100 * The following steps are performed: |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
101 * (1) A workerClass is loaded by a custom class loader |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
102 * (2) The method doWork that calls a method of the workerClass is compiled. The call |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
103 * is implemented as an optimized IC calling a to-interpreted stub. The to-interpreter |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
104 * stub contains a Method* to a workerClass method. |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
105 * (3) Unloading of the workerClass is enforced. The to-interpreter stub now contains a dead Method*. |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
106 * (4) Depending on the implementation of the IC, the compiled version of doWork should still be |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
107 * valid. We call it again without using the workerClass. |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
108 */ |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
109 static public void main(String[] args) throws Exception { |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
110 // (1) Create a custom class loader with no parent class loader |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
111 URL url = TestMethodUnloading.class.getProtectionDomain().getCodeSource().getLocation(); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
112 URLClassLoader loader = new URLClassLoader(new URL[] {url}, null); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
113 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
114 // Load worker class with custom class loader |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
115 Class<?> workerClass = Class.forName(workerClassName, true, loader); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
116 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
117 // (2) Make sure all paths of doWork are profiled and compiled |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
118 for (int i = 0; i < 100000; ++i) { |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
119 doWork(workerClass, true); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
120 doWork(workerClass, false); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
121 } |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
122 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
123 // Make sure doWork is compiled now |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
124 Method doWork = TestMethodUnloading.class.getDeclaredMethod("doWork", Class.class, boolean.class); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
125 makeSureIsCompiled(doWork); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
126 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
127 // (3) Throw away class loader and reference to workerClass to allow unloading |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
128 loader.close(); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
129 loader = null; |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
130 workerClass = null; |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
131 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
132 // Force garbage collection to trigger unloading of workerClass |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
133 // Dead reference to WorkerClass::hashCode triggers JDK-8029443 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
134 WHITE_BOX.fullGC(); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
135 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
136 // (4) Depending on the implementation of the IC, the compiled version of doWork |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
137 // may still be valid here. Execute it without a workerClass. |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
138 doWork(null, false); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
139 if (work != 1) { |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
140 throw new RuntimeException("Work not done"); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
141 } |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
142 |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
143 doWork(Object.class, false); |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
144 } |
85c339200299
8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff
changeset
|
145 } |