hotspot/test/compiler/codecache/OverflowCodeCacheTest.java
author dsamersoff
Sun, 01 May 2016 12:47:00 +0300
changeset 38152 80e5da81fb2c
parent 33730 30e064828045
child 40059 c2304140ed64
permissions -rw-r--r--
8154258: [TESTBUG] Various serviceability tests fail compilation Summary: Replace sun.misc.Unsafe with jdk.internal.misc.Unsafe Reviewed-by: chegar, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27701
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28190
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
27701
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
     4
 *
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
     8
 *
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    14
 *
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    18
 *
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    21
 * questions.
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    22
 *
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    23
 */
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    24
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    25
import java.lang.management.MemoryPoolMXBean;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    26
import java.util.EnumSet;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    27
import java.util.ArrayList;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    28
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    29
import sun.hotspot.WhiteBox;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    30
import sun.hotspot.code.BlobType;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    31
import sun.hotspot.code.CodeBlob;
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    32
import jdk.test.lib.Asserts;
27701
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    33
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    34
/*
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    35
 * @test OverflowCodeCacheTest
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    36
 * @bug 8059550
33730
30e064828045 8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents: 30604
diff changeset
    37
 * @library /testlibrary /test/lib
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 33730
diff changeset
    38
 * @modules java.base/jdk.internal.misc
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28190
diff changeset
    39
 * @modules java.management
27701
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    40
 * @build OverflowCodeCacheTest
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    41
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    42
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    43
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    44
 *                   -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    45
 *                   -XX:-SegmentedCodeCache OverflowCodeCacheTest
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    46
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    47
 *                   -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    48
 *                   -XX:+SegmentedCodeCache OverflowCodeCacheTest
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    49
 * @summary testing of code cache segments overflow
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    50
 */
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    51
public class OverflowCodeCacheTest {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    52
    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    53
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    54
    public static void main(String[] args) {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    55
        EnumSet<BlobType> blobTypes = BlobType.getAvailable();
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    56
        for (BlobType type : blobTypes) {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    57
            new OverflowCodeCacheTest(type).test();
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    58
        }
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    59
    }
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    60
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    61
    private final BlobType type;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    62
    private final MemoryPoolMXBean bean;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    63
    private OverflowCodeCacheTest(BlobType type) {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    64
        this.type = type;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    65
        this.bean = type.getMemoryPool();
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    66
    }
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    67
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    68
    private void test() {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    69
        System.out.printf("type %s%n", type);
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    70
        System.out.println("allocating till possible...");
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    71
        ArrayList<Long> blobs = new ArrayList<>();
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    72
        try {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    73
            long addr;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    74
            int size = (int) (getHeapSize() >> 7);
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    75
            while ((addr = WHITE_BOX.allocateCodeBlob(size, type.id)) != 0) {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    76
                blobs.add(addr);
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    77
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    78
                BlobType actualType = CodeBlob.getCodeBlob(addr).code_blob_type;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    79
                if (actualType != type) {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    80
                    // check we got allowed overflow handling
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    81
                    Asserts.assertTrue(type.allowTypeWhenOverflow(actualType),
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    82
                            type + " doesn't allow using " + actualType + " when overflow");
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    83
                }
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    84
            }
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    85
            Asserts.assertNotEquals(WHITE_BOX.getCompilationActivityMode(), 1 /* run_compilation*/,
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    86
                    "Compilation must be disabled when CodeCache(CodeHeap) overflows");
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    87
        } finally {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    88
            for (Long blob : blobs) {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    89
                WHITE_BOX.freeCodeBlob(blob);
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    90
            }
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    91
        }
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    92
    }
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    93
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    94
    private long getHeapSize() {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    95
        return bean.getUsage().getMax();
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    96
    }
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    97
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    98
}