hotspot/test/gc/g1/humongousObjects/TestHumongousClassLoader.java
author mchernov
Mon, 27 Mar 2017 19:05:54 +0300
changeset 46350 5fdb409ba877
parent 41705 332239c052cc
child 46829 997b9221c2a3
permissions -rw-r--r--
8177551: [TESTBUG] TestHumongousClassLoader.java can fail on systems with non-g1 collector. Reviewed-by: dfazunen, tschatzl, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38016
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
     1
/*
46350
5fdb409ba877 8177551: [TESTBUG] TestHumongousClassLoader.java can fail on systems with non-g1 collector.
mchernov
parents: 41705
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
38016
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
     4
 *
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
     8
 *
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    13
 * accompanied this code).
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    14
 *
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    18
 *
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    21
 * questions.
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    22
 */
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    23
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    24
package gc.g1.humongousObjects;
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    25
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    26
import gc.testlibrary.Helpers;
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    27
import jdk.test.lib.Asserts;
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    28
import sun.hotspot.WhiteBox;
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    29
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    30
import java.io.IOException;
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    31
import java.lang.reflect.InvocationTargetException;
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    32
import java.net.URL;
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    33
import java.net.URLClassLoader;
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    34
import java.nio.file.Path;
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    35
import java.nio.file.Paths;
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    36
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    37
/**
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    38
 * @test gc.g1.humongousObjects.TestHumongousClassLoader
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    39
 * @summary Checks that unreachable classes and unreachable humongous class loader are unloaded after GC
39414
4adf52148100 8160088: update hotspot tests depending on GC to use @requires vm.gc.X
dfazunen
parents: 38152
diff changeset
    40
 * @requires vm.gc.G1
38016
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    41
 * @requires vm.opt.G1HeapRegionSize == "null" | vm.opt.G1HeapRegionSize == "1M"
38122
9f1dd2adb9fd 8155527: New test TestHumongousClassLoader fails with "-XX:+ExplicitGCInvokesConcurrent" option
kzhaldyb
parents: 38099
diff changeset
    42
 * @requires vm.opt.ExplicitGCInvokesConcurrent != true
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 39414
diff changeset
    43
 * @library /test/lib /
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 38151
diff changeset
    44
 * @modules java.base/jdk.internal.misc
38016
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    45
 * @modules java.management
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    46
 * @build sun.hotspot.WhiteBox
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    47
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    48
 *                                sun.hotspot.WhiteBox$WhiteBoxPermission
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    49
 *
46350
5fdb409ba877 8177551: [TESTBUG] TestHumongousClassLoader.java can fail on systems with non-g1 collector.
mchernov
parents: 41705
diff changeset
    50
 * @run main/othervm/timeout=240  -Xms256M -Xmx256M -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.
38016
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    51
 *                                gc.g1.humongousObjects.ClassLoaderGenerator 1
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    52
 *
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    53
 * @run main/othervm -Xms256M -Xmx256M -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 38122
diff changeset
    54
 *                   -Xlog:class+load,class+unload=debug:file=TestHumongousClassLoader_Full_GC.log
38016
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    55
 *                   -XX:G1HeapRegionSize=1M
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    56
 *                   gc.g1.humongousObjects.TestHumongousClassLoader FULL_GC
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    57
 *
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    58
 * @run main/othervm -Xms256M -Xmx256M -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 38122
diff changeset
    59
 *                   -Xlog:class+load,class+unload=debug:file=TestHumongousClassLoader_Full_GC_Mem_Pressure.log
38016
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    60
 *                   -XX:G1HeapRegionSize=1M
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    61
 *                   gc.g1.humongousObjects.TestHumongousClassLoader FULL_GC_MEMORY_PRESSURE
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    62
 *
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    63
 *@run main/othervm -Xms256M -Xmx256M -XX:+UseG1GC -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 38122
diff changeset
    64
 *                   -Xlog:class+load,class+unload=debug:file=TestHumongousClassLoader_CMC.log
38016
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    65
 *                   -XX:G1HeapRegionSize=1M -XX:MaxTenuringThreshold=1
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    66
 *                   gc.g1.humongousObjects.TestHumongousClassLoader CMC
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    67
 *
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    68
 */
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    69
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    70
public class TestHumongousClassLoader {
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    71
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    72
    private static final WhiteBox WB = WhiteBox.getWhiteBox();
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    73
    private static final String SAMPLE_CLASS_NAME_PREFIX = "SampleClassFiller";
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    74
    public static final String SIMPLE_CLASSLOADER_NAME = "SimpleClassLoader";
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    75
    public static final String HUMONGOUS_CLASSLOADER_NAME = "HumongousClassLoader";
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    76
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    77
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    78
    public static final String LOAD_CLASS_METHOD_PROTOTYPE =
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    79
            "    @Override\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    80
                    + "    public Class loadClass(String fileName) throws ClassNotFoundException {\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    81
                    + "        if (${ClassLoadFilter}) {\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    82
                    + "            System.out.println(\"Loading class \" + fileName);\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    83
                    + "            byte[] b = null;\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    84
                    + "            try {\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    85
                    + "                b = Files.readAllBytes(new File(fileName + \".class\").toPath());\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    86
                    + "            } catch (IOException e) {\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    87
                    + "                e.printStackTrace();\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    88
                    + "            }\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    89
                    + "            Class c = defineClass(fileName, b, 0, b.length);\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    90
                    + "            resolveClass(c);\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    91
                    + "            return c;\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    92
                    + "        } else {\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    93
                    + "            return super.loadClass(fileName);\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    94
                    + "        }\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    95
                    + "\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    96
                    + "\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    97
                    + "    }\n";
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    98
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
    99
    public static final String CLASS_HEADER = "import java.io.File;\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   100
            + "import java.io.IOException;\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   101
            + "import java.nio.file.Files;\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   102
            + "import java.nio.file.Paths;\n";
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   103
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   104
    public static final String GENERIC_PROTOTYPE = "${ClassHeader}\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   105
            + "public class ${ClassName} extends ${BaseClass}{\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   106
            + "    ${ConstructorClause}\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   107
            + "    ${Methods}\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   108
            + "    ${Fields}\n"
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   109
            + "}\n";
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   110
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   111
    public static final String CONSTUCTOR_PROTOTYPE = "public ${ClassName}(ClassLoader parent) { super(parent);}\n";
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   112
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   113
    private enum GC {
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   114
        FULL_GC {
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   115
            @Override
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   116
            public void provoke() {
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   117
                System.gc();
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   118
            }
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   119
        },
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   120
        CMC {
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   121
            @Override
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   122
            public void provoke() {
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   123
                // We need 2 young gc to promote class loader to old gen
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   124
                // Otherwise it will not be unloaded after CMC
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   125
                WHITE_BOX.youngGC();
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   126
                Helpers.waitTillCMCFinished(WHITE_BOX, 0);
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   127
                WHITE_BOX.youngGC();
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   128
                Helpers.waitTillCMCFinished(WHITE_BOX, 0);
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   129
                WHITE_BOX.g1StartConcMarkCycle();
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   130
                Helpers.waitTillCMCFinished(WHITE_BOX, 0);
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   131
            }
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   132
        },
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   133
        FULL_GC_MEMORY_PRESSURE {
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   134
            @Override
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   135
            public void provoke() {
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   136
                WHITE_BOX.fullGC();
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   137
            }
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   138
        };
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   139
        private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   140
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   141
        public abstract void provoke();
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   142
    }
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   143
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   144
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException,
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   145
            IllegalAccessException, IOException, NoSuchMethodException, InvocationTargetException {
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   146
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   147
        if (args.length != 1) {
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   148
            throw new Error("Test Bug: Expected GC type wasn't provided as command line argument");
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   149
        }
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   150
        GC gc = GC.valueOf(args[0]);
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   151
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   152
        Path wrkDir = Paths.get("");
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   153
        URL[] url = {wrkDir.toUri().toURL()};
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   154
        URLClassLoader urlLoader = new URLClassLoader(url);
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   155
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   156
        Class<?> simpleClassLoaderClass = urlLoader.loadClass(SIMPLE_CLASSLOADER_NAME);
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   157
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   158
        ClassLoader simpleClassLoader = (ClassLoader) simpleClassLoaderClass
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   159
                .getConstructor(java.lang.ClassLoader.class)
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   160
                .newInstance(TestHumongousClassLoader.class.getClassLoader());
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   161
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   162
        // Sanity check
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   163
        Asserts.assertEquals(WB.g1IsHumongous(simpleClassLoader), false,
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   164
                "Test Bug: simpleClassLoader is expected to be non-humongous but it's humongous");
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   165
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   166
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   167
        Class<?> humongousClassLoaderClass = simpleClassLoader.loadClass(HUMONGOUS_CLASSLOADER_NAME);
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   168
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   169
        ClassLoader humongousClassLoader = (ClassLoader) humongousClassLoaderClass
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   170
                .getConstructor(java.lang.ClassLoader.class)
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   171
                .newInstance(simpleClassLoader);
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   172
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   173
        // Sanity check
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   174
        Asserts.assertEquals(WB.g1IsHumongous(humongousClassLoader), true,
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   175
                "Test Bug: humongousClassLoader is expected to be humongous but it's non-humongous");
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   176
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   177
        //Asserts.assertEquals(1,0);
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   178
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   179
        Object[] loadedClasses = new Object[]{
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   180
                G1SampleClass.LARGEST_NON_HUMONGOUS.getCls(humongousClassLoader, wrkDir, SAMPLE_CLASS_NAME_PREFIX)
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   181
                        .newInstance(),
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   182
                G1SampleClass.SMALLEST_HUMONGOUS.getCls(humongousClassLoader, wrkDir, SAMPLE_CLASS_NAME_PREFIX)
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   183
                        .newInstance(),
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   184
                G1SampleClass.ONE_REGION_HUMONGOUS.getCls(humongousClassLoader, wrkDir, SAMPLE_CLASS_NAME_PREFIX)
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   185
                        .newInstance(),
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   186
                G1SampleClass.TWO_REGION_HUMONGOUS.getCls(humongousClassLoader, wrkDir, SAMPLE_CLASS_NAME_PREFIX)
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   187
                        .newInstance(),
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   188
        };
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   189
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   190
        // forgetting references to loaded classes
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   191
        for (int i = 0; i < loadedClasses.length; ++i) {
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   192
            loadedClasses[i] = null;
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   193
        }
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   194
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   195
        // forgetting referencies to classloaders
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   196
        humongousClassLoader = null;
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   197
        humongousClassLoaderClass = null;
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   198
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   199
        simpleClassLoader = null;
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   200
        simpleClassLoaderClass = null;
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   201
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   202
        gc.provoke();
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   203
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   204
        // Test checks
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   205
        Asserts.assertEquals(WB.isClassAlive(HUMONGOUS_CLASSLOADER_NAME), false,
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   206
                String.format("Classloader class %s is loaded after we forget all references to it",
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   207
                        HUMONGOUS_CLASSLOADER_NAME));
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   208
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   209
        for (G1SampleClass sampleClass : G1SampleClass.values()) {
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   210
            String className = Helpers.enumNameToClassName(sampleClass.name()) + "Class";
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   211
            Asserts.assertEquals(WB.isClassAlive(className), false,
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   212
                    String.format("Class %s is loaded after we forget all references to it", className));
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   213
        }
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   214
    }
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   215
c960918f0bfb 8132718: Add tests which check that when humongous classloader object becomes unreachable it and all classes that were loaded in it should be collected
kzhaldyb
parents:
diff changeset
   216
}