Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/runtime/Test8010927.java
41149 views
1
/*
2
* Copyright (c) 2013, 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
26
* @bug 8010927
27
* @summary Kitchensink crashed with SIGSEGV, Problematic frame: v ~StubRoutines::checkcast_arraycopy
28
* @library /test/lib
29
* @modules java.base/jdk.internal.misc:+open
30
* @build sun.hotspot.WhiteBox
31
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
32
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+IgnoreUnrecognizedVMOptions
33
* -XX:+WhiteBoxAPI -Xbootclasspath/a:. -Xmx128m -XX:NewSize=20971520
34
* -XX:MaxNewSize=32m -XX:-UseTLAB -XX:-UseAdaptiveSizePolicy
35
* compiler.runtime.Test8010927
36
*/
37
38
package compiler.runtime;
39
40
import jdk.internal.misc.Unsafe;
41
import sun.hotspot.WhiteBox;
42
43
import java.lang.reflect.Field;
44
45
/**
46
* The test creates uncommitted space between oldgen and young gen
47
* by specifying MaxNewSize bigger than NewSize.
48
* NewSize = 20971520 = (512*4K) * 10 for 4k pages
49
* Then it tries to execute arraycopy() with elements type check
50
* to the array at the end of survive space near unused space.
51
*/
52
53
public class Test8010927 {
54
55
private static final Unsafe U;
56
57
static {
58
try {
59
Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
60
unsafe.setAccessible(true);
61
U = (Unsafe) unsafe.get(null);
62
} catch (Exception e) {
63
throw new Error(e);
64
}
65
}
66
67
public static Object[] o;
68
69
public static final boolean debug = Boolean.getBoolean("debug");
70
71
// 2 different obect arrays but same element types
72
static Test8010927[] masterA;
73
static Object[] masterB;
74
static final Test8010927 elem = new Test8010927();
75
static final WhiteBox wb = WhiteBox.getWhiteBox();
76
77
static final int obj_header_size = U.ARRAY_OBJECT_BASE_OFFSET;
78
static final int heap_oop_size = wb.getHeapOopSize();
79
static final int card_size = 512;
80
static final int one_card = (card_size - obj_header_size) / heap_oop_size;
81
82
static final int surv_size = 2112 * 1024;
83
84
// The size is big to not fit into survive space.
85
static final Object[] cache = new Object[(surv_size / card_size)];
86
87
public static void main(String[] args) {
88
masterA = new Test8010927[one_card];
89
masterB = new Object[one_card];
90
for (int i = 0; i < one_card; ++i) {
91
masterA[i] = elem;
92
masterB[i] = elem;
93
}
94
95
// Move cache[] to the old gen.
96
long low_limit = wb.getObjectAddress(cache);
97
System.gc();
98
// Move 'cache' to oldgen.
99
long upper_limit = wb.getObjectAddress(cache);
100
if ((low_limit - upper_limit) > 0) { // substaction works with unsigned values
101
// OldGen is placed before youngger for ParallelOldGC.
102
upper_limit = low_limit + 21000000l; // +20971520
103
}
104
// Each A[one_card] size is 512 bytes,
105
// it will take about 40000 allocations to trigger GC.
106
// cache[] has 8192 elements so GC should happen
107
// each 5th iteration.
108
for (long l = 0; l < 20; l++) {
109
fill_heap();
110
if (debug) {
111
System.out.println("test oop_disjoint_arraycopy");
112
}
113
testA_arraycopy();
114
if (debug) {
115
System.out.println("test checkcast_arraycopy");
116
}
117
testB_arraycopy();
118
// Execute arraycopy to the topmost array in young gen
119
if (debug) {
120
int top_index = get_top_address(low_limit, upper_limit);
121
if (top_index >= 0) {
122
long addr = wb.getObjectAddress(cache[top_index]);
123
System.out.println("top_addr: 0x" + Long.toHexString(addr) + ", 0x" + Long.toHexString(addr + 512));
124
}
125
}
126
}
127
}
128
129
static void fill_heap() {
130
for (int i = 0; i < cache.length; ++i) {
131
o = new Test8010927[one_card];
132
System.arraycopy(masterA, 0, o, 0, masterA.length);
133
cache[i] = o;
134
}
135
for (long j = 0; j < 256; ++j) {
136
o = new Long[10000]; // to trigger GC
137
}
138
}
139
140
static void testA_arraycopy() {
141
for (int i = 0; i < cache.length; ++i) {
142
System.arraycopy(masterA, 0, cache[i], 0, masterA.length);
143
}
144
}
145
146
static void testB_arraycopy() {
147
for (int i = 0; i < cache.length; ++i) {
148
System.arraycopy(masterB, 0, cache[i], 0, masterB.length);
149
}
150
}
151
152
static int get_top_address(long min, long max) {
153
int index = -1;
154
long addr = min;
155
for (int i = 0; i < cache.length; ++i) {
156
long test = wb.getObjectAddress(cache[i]);
157
if (((test - addr) > 0) && ((max - test) > 0)) { // substaction works with unsigned values
158
addr = test;
159
index = i;
160
}
161
}
162
return index;
163
}
164
}
165
166