hotspot/test/compiler/whitebox/AllocationCodeBlobTest.java
author cjplummer
Thu, 29 Oct 2015 12:04:04 -0700
changeset 33730 30e064828045
parent 30604 b8d532cb6420
child 35761 a900c9e65458
permissions -rw-r--r--
8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests Summary: Use new external.lib.roots property in TEST.ROOT so /../../test/lib is not needed. Reviewed-by: mseledtsov, sla, iklam
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27642
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
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.
27642
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
     4
 *
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
     8
 *
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    14
 *
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    18
 *
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    21
 * questions.
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    22
 *
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    23
 */
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    24
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    25
import java.lang.management.MemoryPoolMXBean;
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    26
import java.util.EnumSet;
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    27
import java.util.ArrayList;
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    28
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    29
import sun.hotspot.WhiteBox;
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    30
import sun.hotspot.code.BlobType;
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    31
import jdk.test.lib.Asserts;
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    32
import jdk.test.lib.InfiniteLoop;
27642
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    33
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    34
/*
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    35
 * @test AllocationCodeBlobTest
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    36
 * @bug 8059624 8064669
33730
30e064828045 8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents: 30604
diff changeset
    37
 * @library /testlibrary /test/lib
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28190
diff changeset
    38
 * @modules java.management
27642
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    39
 * @build AllocationCodeBlobTest
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    40
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    41
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    42
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    43
 *                   -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    44
 *                   -XX:-SegmentedCodeCache AllocationCodeBlobTest
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    45
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    46
 *                   -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    47
 *                   -XX:+SegmentedCodeCache AllocationCodeBlobTest
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    48
 * @summary testing of WB::allocate/freeCodeBlob()
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    49
 */
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    50
public class AllocationCodeBlobTest {
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    51
    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    52
    private static final long CODE_CACHE_SIZE
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    53
            = WHITE_BOX.getUintxVMFlag("ReservedCodeCacheSize");
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    54
    private static final int SIZE = 1;
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    55
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    56
    public static void main(String[] args) {
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    57
        // check that Sweeper handels dummy blobs correctly
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    58
        Thread t = new Thread(
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    59
                new InfiniteLoop(WHITE_BOX::forceNMethodSweep, 1L),
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    60
                "ForcedSweeper");
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    61
        t.setDaemon(true);
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    62
        System.out.println("Starting " + t.getName());
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    63
        t.start();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    64
27642
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    65
        EnumSet<BlobType> blobTypes = BlobType.getAvailable();
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    66
        for (BlobType type : blobTypes) {
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    67
            new AllocationCodeBlobTest(type).test();
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    68
        }
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    69
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    70
        // check that deoptimization works well w/ dummy blobs
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    71
        t = new Thread(
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    72
                new InfiniteLoop(WHITE_BOX::deoptimizeAll, 1L),
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    73
                "Deoptimize Thread");
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    74
        t.setDaemon(true);
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    75
        System.out.println("Starting " + t.getName());
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    76
        t.start();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    77
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    78
        for (int i = 0; i < 10_000; ++i) {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    79
            for (BlobType type : blobTypes) {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    80
                long addr = WHITE_BOX.allocateCodeBlob(SIZE, type.id);
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    81
            }
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    82
        }
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents: 27642
diff changeset
    83
27642
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    84
    }
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    85
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    86
    private final BlobType type;
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    87
    private final MemoryPoolMXBean bean;
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    88
    private AllocationCodeBlobTest(BlobType type) {
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    89
        this.type = type;
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    90
        bean = type.getMemoryPool();
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    91
    }
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    92
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    93
    private void test() {
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    94
        System.out.printf("type %s%n", type);
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    95
        long start = getUsage();
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    96
        long addr = WHITE_BOX.allocateCodeBlob(SIZE, type.id);
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    97
        Asserts.assertNE(0, addr, "allocation failed");
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    98
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
    99
        long firstAllocation = getUsage();
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   100
        Asserts.assertLTE(start + SIZE, firstAllocation,
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   101
                "allocation should increase memory usage: "
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   102
                + start + " + " + SIZE + " <= " + firstAllocation);
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   103
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   104
        WHITE_BOX.freeCodeBlob(addr);
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   105
        long firstFree = getUsage();
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   106
        Asserts.assertLTE(firstFree, firstAllocation,
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   107
                "free shouldn't increase memory usage: "
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   108
                + firstFree + " <= " + firstAllocation);
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   109
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   110
        addr = WHITE_BOX.allocateCodeBlob(SIZE, type.id);
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   111
        Asserts.assertNE(0, addr, "allocation failed");
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   112
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   113
        long secondAllocation = getUsage();
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   114
        Asserts.assertEQ(firstAllocation, secondAllocation);
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   115
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   116
        WHITE_BOX.freeCodeBlob(addr);
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   117
        System.out.println("allocating till possible...");
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   118
        ArrayList<Long> blobs = new ArrayList<>();
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   119
        int size = (int) (CODE_CACHE_SIZE >> 7);
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   120
        while ((addr = WHITE_BOX.allocateCodeBlob(size, type.id)) != 0) {
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   121
            blobs.add(addr);
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   122
        }
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   123
        for (Long blob : blobs) {
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   124
            WHITE_BOX.freeCodeBlob(blob);
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   125
        }
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   126
    }
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   127
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   128
    private long getUsage() {
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   129
        return bean.getUsage().getUsed();
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   130
    }
8c9eff693145 8059624: Test task: WhiteBox API for testing segmented codecache feature
iignatyev
parents:
diff changeset
   131
}