Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/codecache/stress/RandomAllocationTest.java
41153 views
1
/*
2
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test RandomAllocationTest
26
* @key stress randomness
27
* @summary stressing code cache by allocating randomly sized "dummy" code blobs
28
* @library /test/lib /
29
* @modules java.base/jdk.internal.misc
30
* java.management
31
*
32
* @build sun.hotspot.WhiteBox compiler.codecache.stress.Helper compiler.codecache.stress.TestCaseImpl
33
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
34
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
35
* -XX:+WhiteBoxAPI
36
* -XX:CompileCommand=dontinline,compiler.codecache.stress.Helper$TestCase::method
37
* -XX:-SegmentedCodeCache
38
* compiler.codecache.stress.RandomAllocationTest
39
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
40
* -XX:+WhiteBoxAPI
41
* -XX:CompileCommand=dontinline,compiler.codecache.stress.Helper$TestCase::method
42
* -XX:+SegmentedCodeCache
43
* compiler.codecache.stress.RandomAllocationTest
44
*/
45
46
package compiler.codecache.stress;
47
48
import sun.hotspot.code.BlobType;
49
50
import java.util.ArrayList;
51
import java.util.Random;
52
import jdk.test.lib.Utils;
53
54
public class RandomAllocationTest implements Runnable {
55
private static final long CODE_CACHE_SIZE
56
= Helper.WHITE_BOX.getUintxVMFlag("ReservedCodeCacheSize");
57
private static final int MAX_BLOB_SIZE = (int) (CODE_CACHE_SIZE >> 7);
58
private static final BlobType[] BLOB_TYPES
59
= BlobType.getAvailable().toArray(new BlobType[0]);
60
private final Random rng = Utils.getRandomInstance();
61
62
public static void main(String[] args) {
63
new CodeCacheStressRunner(new RandomAllocationTest()).runTest();
64
}
65
66
private final ArrayList<Long> blobs = new ArrayList<>();
67
@Override
68
public void run() {
69
boolean allocate = blobs.isEmpty() || rng.nextBoolean();
70
if (allocate) {
71
int type = rng.nextInt(BLOB_TYPES.length);
72
long addr = Helper.WHITE_BOX.allocateCodeBlob(
73
rng.nextInt(MAX_BLOB_SIZE), BLOB_TYPES[type].id);
74
if (addr != 0) {
75
blobs.add(addr);
76
}
77
} else {
78
int index = rng.nextInt(blobs.size());
79
Helper.WHITE_BOX.freeCodeBlob(blobs.remove(index));
80
}
81
}
82
83
}
84
85