hotspot/test/compiler/codecache/OverflowCodeCacheTest.java
author thartmann
Fri, 12 Dec 2014 09:37:38 +0100
changeset 28190 5a6b07edeb21
parent 27701 c6b49b72dc61
child 29678 dd2f3932c21e
permissions -rw-r--r--
8066433: Move Whitebox test library to top level repository Summary: Moved Whitebox test library to top level repository. Reviewed-by: iignatyev, sla, mr
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
/*
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
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;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    32
import com.oracle.java.testlibrary.Asserts;
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
28190
5a6b07edeb21 8066433: Move Whitebox test library to top level repository
thartmann
parents: 27701
diff changeset
    37
 * @library /testlibrary /../../test/lib
27701
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    38
 * @build OverflowCodeCacheTest
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    39
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    40
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    41
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    42
 *                   -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    43
 *                   -XX:-SegmentedCodeCache OverflowCodeCacheTest
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    44
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    45
 *                   -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    46
 *                   -XX:+SegmentedCodeCache OverflowCodeCacheTest
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    47
 * @summary testing of code cache segments overflow
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    48
 */
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    49
public class OverflowCodeCacheTest {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    50
    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    51
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    52
    public static void main(String[] args) {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    53
        EnumSet<BlobType> blobTypes = BlobType.getAvailable();
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    54
        for (BlobType type : blobTypes) {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    55
            new OverflowCodeCacheTest(type).test();
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    56
        }
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    57
    }
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
    private final BlobType type;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    60
    private final MemoryPoolMXBean bean;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    61
    private OverflowCodeCacheTest(BlobType type) {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    62
        this.type = type;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    63
        this.bean = type.getMemoryPool();
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    64
    }
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    65
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    66
    private void test() {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    67
        System.out.printf("type %s%n", type);
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    68
        System.out.println("allocating till possible...");
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    69
        ArrayList<Long> blobs = new ArrayList<>();
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    70
        try {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    71
            long addr;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    72
            int size = (int) (getHeapSize() >> 7);
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    73
            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
    74
                blobs.add(addr);
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    75
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    76
                BlobType actualType = CodeBlob.getCodeBlob(addr).code_blob_type;
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    77
                if (actualType != type) {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    78
                    // check we got allowed overflow handling
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    79
                    Asserts.assertTrue(type.allowTypeWhenOverflow(actualType),
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    80
                            type + " doesn't allow using " + actualType + " when overflow");
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    81
                }
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    82
            }
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    83
            Asserts.assertNotEquals(WHITE_BOX.getCompilationActivityMode(), 1 /* run_compilation*/,
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    84
                    "Compilation must be disabled when CodeCache(CodeHeap) overflows");
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    85
        } finally {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    86
            for (Long blob : blobs) {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    87
                WHITE_BOX.freeCodeBlob(blob);
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    88
            }
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    89
        }
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
    private long getHeapSize() {
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    93
        return bean.getUsage().getMax();
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    94
    }
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    95
c6b49b72dc61 8059550: JEP-JDK-8043304: Test task: segment overflow w/ empty others
iignatyev
parents:
diff changeset
    96
}