hotspot/test/compiler/classUnloading/methodUnloading/TestMethodUnloading.java
author cjplummer
Thu, 29 Oct 2015 12:04:04 -0700
changeset 33730 30e064828045
parent 28190 5a6b07edeb21
child 38152 80e5da81fb2c
permissions -rw-r--r--
8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests Summary: Use new external.lib.roots property in TEST.ROOT so /../../test/lib is not needed. Reviewed-by: mseledtsov, sla, iklam
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25933
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
     1
/*
ea319da89b55 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.
ea319da89b55 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.
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
     4
 *
ea319da89b55 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
ea319da89b55 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
ea319da89b55 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.
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
     8
 *
ea319da89b55 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
ea319da89b55 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
ea319da89b55 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
ea319da89b55 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
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    13
 * accompanied this code).
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    14
 *
ea319da89b55 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
ea319da89b55 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,
ea319da89b55 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.
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    18
 *
ea319da89b55 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
ea319da89b55 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
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    21
 * questions.
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    22
 */
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    23
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    24
import sun.hotspot.WhiteBox;
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    25
ea319da89b55 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;
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    27
import java.net.URL;
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    28
import java.net.URLClassLoader;
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    29
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    30
/*
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    31
 * @test MethodUnloadingTest
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    32
 * @bug 8029443
ea319da89b55 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"
33730
30e064828045 8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents: 28190
diff changeset
    34
 * @library /testlibrary /test/lib
25933
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    35
 * @build TestMethodUnloading
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    36
 * @build WorkerClass
ea319da89b55 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
25958
8dc85547d6d6 8011397: JTREG needs to copy additional WhiteBox class file to JTwork/scratch/sun/hotspot
mgerdin
parents: 25933
diff changeset
    38
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
26308
23a4c333f248 8055657: Test compiler/classUnloading/methodUnloading/TestMethodUnloading.java does not work with non-default GC
thartmann
parents: 25958
diff changeset
    39
 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-BackgroundCompilation -XX:-UseCompressedOops -XX:CompileOnly=TestMethodUnloading::doWork TestMethodUnloading
25933
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    40
 */
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    41
public class TestMethodUnloading {
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    42
    private static final String workerClassName = "WorkerClass";
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    43
    private static int work = -1;
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    44
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    45
    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
ea319da89b55 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_SIMPLE = 1;
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    47
    private static int COMP_LEVEL_FULL_OPTIMIZATION = 4;
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    48
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    49
    /**
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    50
     * Does some work by either using the workerClass or locally producing values.
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    51
     * @param workerClass Class performing some work (will be unloaded)
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    52
     * @param useWorker If true the workerClass is used
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    53
     */
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    54
    static private void doWork(Class<?> workerClass, boolean useWorker) throws InstantiationException, IllegalAccessException {
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    55
        if (useWorker) {
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    56
            // Create a new instance
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    57
            Object worker = workerClass.newInstance();
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    58
            // We would like to call a method of WorkerClass here but we cannot cast to WorkerClass
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    59
            // because the class was loaded by a different class loader. One solution would be to use
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    60
            // reflection but since we want C2 to implement the call as an optimized IC we call
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    61
            // Object::hashCode() here which actually calls WorkerClass::hashCode().
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    62
            // C2 will then implement this call as an optimized IC that points to a to-interpreter stub
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    63
            // referencing the Method* for WorkerClass::hashCode().
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    64
            work = worker.hashCode();
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    65
            if (work != 42) {
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    66
                new RuntimeException("Work not done");
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    67
            }
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    68
        } else {
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    69
            // Do some important work here
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    70
            work = 1;
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    71
        }
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    72
    }
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    73
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    74
    /**
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    75
     * Makes sure that method is compiled by forcing compilation if not yet compiled.
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    76
     * @param m Method to be checked
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    77
     */
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    78
    static private void makeSureIsCompiled(Method m) {
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    79
        // Make sure background compilation is disabled
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    80
        if (WHITE_BOX.getBooleanVMFlag("BackgroundCompilation")) {
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    81
            throw new RuntimeException("Background compilation enabled");
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    82
        }
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    83
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    84
        // Check if already compiled
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    85
        if (!WHITE_BOX.isMethodCompiled(m)) {
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    86
            // If not, try to compile it with C2
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    87
            if(!WHITE_BOX.enqueueMethodForCompilation(m, COMP_LEVEL_FULL_OPTIMIZATION)) {
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    88
                // C2 compiler not available, try to compile with C1
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    89
                WHITE_BOX.enqueueMethodForCompilation(m, COMP_LEVEL_SIMPLE);
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    90
            }
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    91
            // Because background compilation is disabled, method should now be compiled
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    92
            if(!WHITE_BOX.isMethodCompiled(m)) {
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    93
                throw new RuntimeException(m + " not compiled");
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    94
            }
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    95
        }
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    96
    }
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    97
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    98
    /**
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
    99
     * This test creates stale Method* metadata in a to-interpreter stub of an optimized IC.
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   100
     *
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   101
     * The following steps are performed:
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   102
     * (1) A workerClass is loaded by a custom class loader
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   103
     * (2) The method doWork that calls a method of the workerClass is compiled. The call
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   104
     *     is implemented as an optimized IC calling a to-interpreted stub. The to-interpreter
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   105
     *     stub contains a Method* to a workerClass method.
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   106
     * (3) Unloading of the workerClass is enforced. The to-interpreter stub now contains a dead Method*.
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   107
     * (4) Depending on the implementation of the IC, the compiled version of doWork should still be
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   108
     *     valid. We call it again without using the workerClass.
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   109
     */
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   110
    static public void main(String[] args) throws Exception {
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   111
        // (1) Create a custom class loader with no parent class loader
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   112
        URL url = TestMethodUnloading.class.getProtectionDomain().getCodeSource().getLocation();
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   113
        URLClassLoader loader = new URLClassLoader(new URL[] {url}, null);
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   114
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   115
        // Load worker class with custom class loader
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   116
        Class<?> workerClass = Class.forName(workerClassName, true, loader);
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   117
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   118
        // (2) Make sure all paths of doWork are profiled and compiled
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   119
        for (int i = 0; i < 100000; ++i) {
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   120
            doWork(workerClass, true);
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   121
            doWork(workerClass, false);
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   122
        }
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   123
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   124
        // Make sure doWork is compiled now
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   125
        Method doWork = TestMethodUnloading.class.getDeclaredMethod("doWork", Class.class, boolean.class);
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   126
        makeSureIsCompiled(doWork);
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   127
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   128
        // (3) Throw away class loader and reference to workerClass to allow unloading
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   129
        loader.close();
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   130
        loader = null;
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   131
        workerClass = null;
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   132
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   133
        // Force garbage collection to trigger unloading of workerClass
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   134
        // Dead reference to WorkerClass::hashCode triggers JDK-8029443
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   135
        WHITE_BOX.fullGC();
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   136
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   137
        // (4) Depending on the implementation of the IC, the compiled version of doWork
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   138
        // may still be valid here. Execute it without a workerClass.
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   139
        doWork(null, false);
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   140
        if (work != 1) {
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   141
            throw new RuntimeException("Work not done");
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   142
        }
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   143
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   144
        doWork(Object.class, false);
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   145
    }
ea319da89b55 8029443: 'assert(klass->is_loader_alive(_is_alive)) failed: must be alive' during VM_CollectForMetadataAllocation
thartmann
parents:
diff changeset
   146
}