hotspot/test/gc/g1/humongousObjects/ClassLoaderGenerator.java
author stsmirno
Mon, 17 Oct 2016 18:54:12 -0400
changeset 41705 332239c052cc
parent 38016 c960918f0bfb
permissions -rw-r--r--
8165687: Fix license and copyright headers in jd9 under hotspot/test Summary: Legal notices and Oracle copyrights were updated (white and blank space, commas) in tests files for uniformity to meet Oracle requirements. Reviewed-by: dholmes, iris Contributed-by: Stanislav Smirnov <stanislav.smirnov@oracle.com>, Vassili Igouchkine <vassili.igouchkine@oracle.com>
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
/*
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
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
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
 */
41705
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 38016
diff changeset
    23
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
    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
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 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
    29
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
    30
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
    31
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
/**
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
 * Generates non-humongous and humongous class loaders.
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
 * Since the generation depends on current host architecture it cannot be done as part of pre-compilation step
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
 */
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
public class ClassLoaderGenerator {
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
    public static void main(String[] args) throws 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
    38
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
        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
    40
            throw new Error("Test Bug: Expected region size 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
    41
        }
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
    42
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
    43
        long regionSize = Long.parseLong(args[0]) * 1024 * 1024;
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
    44
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
        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
    46
        generateClassLoader(regionSize, wrkDir);
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
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
    }
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
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
    50
    public static void generateClassLoader(long regionSize, Path wrkDir) throws 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
    51
        // Generating simple classloader
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
        String finalSimpleClassLoaderPrototype = TestHumongousClassLoader.GENERIC_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
    53
                .replace("${Methods}",
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
    54
                        TestHumongousClassLoader.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
    55
                                .replace("${ClassLoadFilter}",
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
                                        "fileName.equals(\"" + TestHumongousClassLoader.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
    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
                .replace("${ClassHeader}", TestHumongousClassLoader.CLASS_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
    59
                .replace("${ConstructorClause}", TestHumongousClassLoader.CONSTUCTOR_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
    60
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
        Helpers.generateByTemplateAndCompile(TestHumongousClassLoader.SIMPLE_CLASSLOADER_NAME, "ClassLoader",
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
                finalSimpleClassLoaderPrototype, TestHumongousClassLoader.CONSTUCTOR_PROTOTYPE, regionSize / 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
    63
                wrkDir, TestHumongousClassLoader.SIMPLE_CLASSLOADER_NAME + "Base");
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
    64
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
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
        // Preparations for generating humongous classloader
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
        // Generating condition for loadClass method of generated class loader
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
        // We want the generated class loader to load only classes from G1SampleClass enum
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
        // All other classes should be loaded by parent classloader
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
        // As result we get full loadClass method
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
        StringBuilder classesToLoadBuilder = new StringBuilder();
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
        for (G1SampleClass g1SampleClass : 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
    74
            if (classesToLoadBuilder.length() != 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
    75
                classesToLoadBuilder.append(" || ");
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
            classesToLoadBuilder.append("fileName.startsWith(\"" + Helpers.enumNameToClassName(g1SampleClass.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
    78
                    + "\")");
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
        }
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
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
        // Generating final class loader prototype - with specified methods,header and constructor
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
        String finalHumongousClassLoaderPrototype = TestHumongousClassLoader.GENERIC_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
    83
                .replace("${Methods}",
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
                        TestHumongousClassLoader.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
    85
                                .replace("${ClassLoadFilter}", classesToLoadBuilder))
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
                .replace("${ClassHeader}", TestHumongousClassLoader.CLASS_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
    87
                .replace("${ConstructorClause}", TestHumongousClassLoader.CONSTUCTOR_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
    88
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
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
        // Generating humongous classloader with specified name, base class, final class prototype and
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
        // constructor prototype for filler 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
    92
        // Generated class instance should be humongous since we specify size of (regionSize * 3 / 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
    93
        Helpers.generateByTemplateAndCompile(TestHumongousClassLoader.HUMONGOUS_CLASSLOADER_NAME, "ClassLoader",
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
                finalHumongousClassLoaderPrototype, TestHumongousClassLoader.CONSTUCTOR_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
    95
                regionSize * 3 / 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
    96
                wrkDir, TestHumongousClassLoader.HUMONGOUS_CLASSLOADER_NAME + "Base");
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
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
    }
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
}