hotspot/test/runtime/Metaspace/FragmentMetaspace.java
author ctornqvi
Thu, 23 May 2013 17:39:32 +0200
changeset 17827 de9b8cf69309
child 28179 094d2e4a54b1
permissions -rw-r--r--
8009576: Test returns ClassNotFoundException Summary: Small classpath fix and move tests into open Reviewed-by: mgerdin, zgu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17827
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
     1
/*
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
     4
 *
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
     7
 * published by the Free Software Foundation.
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
     8
 *
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    13
 * accompanied this code).
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    14
 *
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    18
 *
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    21
 * questions.
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    22
 */
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    23
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    24
/**
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    25
 * @test
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    26
 * @library /runtime/testlibrary
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    27
 * @build GeneratedClassLoader
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    28
 * @run main/othervm/timeout=200 FragmentMetaspace
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    29
 */
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    30
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    31
import java.io.IOException;
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    32
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    33
/**
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    34
 * Test that tries to fragment the native memory used by class loaders.
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    35
 * This test creates class loaders that load classes of increasing size for every
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    36
 * iteration. By increasing the size of the class meta data needed for every iteration
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    37
 * we stress the subsystem for allocating native memory for meta data.
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    38
 */
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    39
public class FragmentMetaspace {
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    40
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    41
    public static void main(String... args) {
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    42
        runGrowing(Long.valueOf(System.getProperty("time", "80000")));
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    43
        // try to clean up and unload classes to decrease
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    44
        // class verification time in debug vm
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    45
        System.gc();
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    46
    }
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    47
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    48
    private static void runGrowing(long time) {
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    49
        long startTime = System.currentTimeMillis();
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    50
        for (int i = 0; System.currentTimeMillis() < startTime + time; ++i) {
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    51
            try {
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    52
                GeneratedClassLoader gcl = new GeneratedClassLoader();
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    53
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    54
                Class<?> c = gcl.getGeneratedClasses(i, 100)[0];
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    55
                c.newInstance();
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    56
                c = null;
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    57
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    58
                gcl = null;
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    59
            } catch (IOException|InstantiationException|IllegalAccessException ex) {
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    60
                throw new RuntimeException(ex);
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    61
            }
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    62
        }
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    63
    }
de9b8cf69309 8009576: Test returns ClassNotFoundException
ctornqvi
parents:
diff changeset
    64
}