Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/shenandoah/jni/TestPinnedGarbage.java
41153 views
1
/*
2
* Copyright (c) 2018, Red Hat, Inc. 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 TestPinnedGarbage
26
* @summary Test that garbage in the pinned region does not crash VM
27
* @key randomness
28
* @requires vm.gc.Shenandoah
29
* @library /test/lib
30
*
31
* @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx128m
32
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
33
* -XX:+ShenandoahVerify -XX:+ShenandoahDegeneratedGC
34
* TestPinnedGarbage
35
*
36
* @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx128m
37
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
38
* -XX:+ShenandoahVerify -XX:-ShenandoahDegeneratedGC
39
* TestPinnedGarbage
40
*/
41
42
/* @test TestPinnedGarbage
43
* @summary Test that garbage in the pinned region does not crash VM
44
* @key randomness
45
* @requires vm.gc.Shenandoah
46
* @library /test/lib
47
*
48
* @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx128m
49
* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
50
* TestPinnedGarbage
51
*
52
* @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx128m
53
* -XX:+UseShenandoahGC
54
* -XX:+ShenandoahVerify
55
* TestPinnedGarbage
56
*/
57
58
import java.util.Arrays;
59
import java.util.Random;
60
import jdk.test.lib.Utils;
61
62
public class TestPinnedGarbage {
63
static {
64
System.loadLibrary("TestPinnedGarbage");
65
}
66
67
private static final int NUM_RUNS = 1_000;
68
private static final int OBJS_COUNT = 1 << 10;
69
private static final int GARBAGE_COUNT = 1 << 18;
70
71
private static native void pin(int[] a);
72
private static native void unpin(int[] a);
73
74
public static void main(String[] args) {
75
Random rng = Utils.getRandomInstance();
76
for (int i = 0; i < NUM_RUNS; i++) {
77
test(rng);
78
}
79
}
80
81
private static void test(Random rng) {
82
Object[] objs = new Object[OBJS_COUNT];
83
for (int i = 0; i < OBJS_COUNT; i++) {
84
objs[i] = new MyClass();
85
}
86
87
int[] cog = new int[10];
88
int cogIdx = rng.nextInt(OBJS_COUNT);
89
objs[cogIdx] = cog;
90
pin(cog);
91
92
for (int i = 0; i < GARBAGE_COUNT; i++) {
93
int rIdx = rng.nextInt(OBJS_COUNT);
94
if (rIdx != cogIdx) {
95
objs[rIdx] = new MyClass();
96
}
97
}
98
99
unpin(cog);
100
}
101
102
public static class MyClass {
103
public Object ref = new Object();
104
}
105
106
}
107
108