hotspot/test/compiler/codecache/stress/RandomAllocationTest.java
author stsmirno
Mon, 17 Oct 2016 18:54:12 -0400
changeset 41705 332239c052cc
parent 40631 ed82623d7831
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:
28501
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
     1
/*
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40338
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
28501
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
     4
 *
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
     8
 *
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    13
 * accompanied this code).
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    14
 *
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    18
 *
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    21
 * questions.
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    22
 */
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    23
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    24
/*
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    25
 * @test RandomAllocationTest
40338
d92668bfe3e8 8162852: Mark stress compiler and gc tests with stress keyword
lmesnik
parents: 40059
diff changeset
    26
 * @key stress
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    27
 * @summary stressing code cache by allocating randomly sized "dummy" code blobs
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40338
diff changeset
    28
 * @library /test/lib /
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    29
 * @modules java.base/jdk.internal.misc
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    30
 *          java.management
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    31
 *
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40338
diff changeset
    32
 * @build sun.hotspot.WhiteBox
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    33
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    34
 *                                sun.hotspot.WhiteBox$WhiteBoxPermission
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    35
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    36
 *                   -XX:+WhiteBoxAPI
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    37
 *                   -XX:CompileCommand=dontinline,compiler.codecache.stress.Helper$TestCase::method
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    38
 *                   -XX:-SegmentedCodeCache
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    39
 *                   compiler.codecache.stress.RandomAllocationTest
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    40
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    41
 *                   -XX:+WhiteBoxAPI
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    42
 *                   -XX:CompileCommand=dontinline,compiler.codecache.stress.Helper$TestCase::method
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    43
 *                   -XX:+SegmentedCodeCache
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    44
 *                   compiler.codecache.stress.RandomAllocationTest
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    45
 */
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    46
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    47
package compiler.codecache.stress;
28501
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    48
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    49
import sun.hotspot.code.BlobType;
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    50
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    51
import java.util.ArrayList;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    52
28501
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    53
public class RandomAllocationTest implements Runnable {
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    54
    private static final long CODE_CACHE_SIZE
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    55
            = Helper.WHITE_BOX.getUintxVMFlag("ReservedCodeCacheSize");
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    56
    private static final int MAX_BLOB_SIZE = (int) (CODE_CACHE_SIZE >> 7);
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    57
    private static final BlobType[] BLOB_TYPES
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    58
            = BlobType.getAvailable().toArray(new BlobType[0]);
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    59
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    60
    public static void main(String[] args) {
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    61
        new CodeCacheStressRunner(new RandomAllocationTest()).runTest();
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    62
    }
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    63
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    64
    private final ArrayList<Long> blobs = new ArrayList<>();
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    65
    @Override
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    66
    public void run() {
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    67
        boolean allocate = blobs.isEmpty() || Helper.RNG.nextBoolean();
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    68
        if (allocate) {
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    69
            int type = Helper.RNG.nextInt(BLOB_TYPES.length);
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    70
            long addr = Helper.WHITE_BOX.allocateCodeBlob(
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    71
                    Helper.RNG.nextInt(MAX_BLOB_SIZE), BLOB_TYPES[type].id);
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    72
            if (addr != 0) {
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    73
                blobs.add(addr);
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    74
            }
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    75
        } else {
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    76
            int index = Helper.RNG.nextInt(blobs.size());
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    77
            Helper.WHITE_BOX.freeCodeBlob(blobs.remove(index));
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    78
        }
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    79
    }
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    80
c9c359a66a15 8059551: JEP-JDK-8043304: Test task: stress tests
pchistyakov
parents:
diff changeset
    81
}