Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestOutOfBoundsArrayLoad.java
41149 views
1
/*
2
* Copyright (c) 2021 SAP SE. 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
/**
26
* @test
27
* @requires vm.gc.Serial
28
* @bug 8262295
29
* @library /test/lib /
30
* @summary Out of bounds array load on clone source crashes GC which
31
* interpretes the loaded value as oop. A small heap is configured to
32
* get a lot of GCs.
33
*
34
* @comment C2 generates the out of bounds load with serial, parallel and
35
* shenandoah gc but not with g1 and z gc. For simplicity serial gc is
36
* configured.
37
*
38
* @build sun.hotspot.WhiteBox
39
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
40
* @run main/othervm -XX:+UseSerialGC -Xmx128m
41
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.
42
* -XX:-BackgroundCompilation
43
* -XX:CompileCommand=dontinline,*::*_dontinline
44
* compiler.arraycopy.TestOutOfBoundsArrayLoad
45
*/
46
47
package compiler.arraycopy;
48
49
import compiler.whitebox.CompilerWhiteBoxTest;
50
51
public class TestOutOfBoundsArrayLoad {
52
53
public static Object escape1;
54
public static Object escape2;
55
56
public static void main(String[] args_ignored) {
57
try {
58
Object[] arrNotEmpty = {null, null, null, null, null, };
59
60
// Warm-up
61
for (int i = CompilerWhiteBoxTest.THRESHOLD; i > 0; i--) {
62
testMethod_dontinline(arrNotEmpty);
63
}
64
// Call testmethod with empty array often enough to trigger GC.
65
// GC is assumed to crash.
66
for (int i = 20_000_000; i > 0; i--) {
67
// Trick for ParallelGC: empty[4] will be loaded in the testmethod
68
// (out of bounds!) and interpreted as oop (or
69
// narrowOop). PSScavenge::should_scavenge() will skip the loaded
70
// value if it is before the young generation. So before calling the
71
// test method we allocate the empty array and an array of -1 values
72
// right behind it. So empty[4] will likely result in
73
// 0xffffffffffffffff Which is not before the young generation.
74
Object[] empty = new Object[0];
75
long[] l = new long[4];
76
l[0] = -1L; l[1] = -1L; l[2] = -1L; l[3] = -1L;
77
escape2 = l;
78
testMethod_dontinline(empty);
79
}
80
} catch (Throwable t) {
81
t.printStackTrace();
82
System.exit(1);
83
}
84
}
85
86
public static void testMethod_dontinline(Object[] src) throws Exception {
87
Object[] clone = src.clone();
88
// Load L below is executed speculatively at this point from src without range check.
89
// The result is put into the OopMap of the allocation in the next line.
90
// If src.length is 0 then the loaded value is no heap reference and GC crashes.
91
escape1 = new Object();
92
if (src.length > 4) {
93
escape2 = clone[4]; // Load L
94
}
95
}
96
}
97
98