Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/g1/TestFromCardCacheIndex.java
40942 views
1
/*
2
* Copyright (c) 2018, 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 TestFromCardCacheIndex.java
26
* @bug 8196485
27
* @summary Ensure that G1 does not miss a remembered set entry due to from card cache default value indices.
28
* @requires vm.gc.G1
29
* @requires vm.debug
30
* @requires vm.bits != "32"
31
* @library /test/lib
32
* @modules java.base/jdk.internal.misc
33
* java.management
34
* @build sun.hotspot.WhiteBox
35
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
36
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. -Xms20M -Xmx20M -XX:+UseCompressedOops -XX:G1HeapRegionSize=1M -XX:HeapBaseMinAddress=2199011721216 -XX:+UseG1GC -verbose:gc gc.g1.TestFromCardCacheIndex
37
*/
38
package gc.g1;
39
40
import sun.hotspot.WhiteBox;
41
42
/**
43
* Repeatedly tries to generate references from objects that contained a card with the same index
44
* of the from card cache default value.
45
*/
46
public class TestFromCardCacheIndex {
47
private static WhiteBox WB;
48
49
// Shift value to calculate card indices from addresses.
50
private static final int CardSizeShift = 9;
51
52
/**
53
* Returns the last address on the heap within the object.
54
*
55
* @param The Object array to get the last address from.
56
*/
57
private static long getObjectLastAddress(Object[] o) {
58
return WB.getObjectAddress(o) + WB.getObjectSize(o) - 1;
59
}
60
61
/**
62
* Returns the (truncated) 32 bit card index for the given address.
63
*
64
* @param The address to get the 32 bit card index from.
65
*/
66
private static int getCardIndex32bit(long address) {
67
return (int)(address >> CardSizeShift);
68
}
69
70
// The source arrays that are placed on the heap in old gen.
71
private static int numArrays = 7000;
72
private static int arraySize = 508;
73
// Size of a humongous byte array, a bit less than a 1M region. This makes sure
74
// that we always create a cross-region reference when referencing it.
75
private static int byteArraySize = 1024*1023;
76
77
public static void main(String[] args) {
78
WB = sun.hotspot.WhiteBox.getWhiteBox();
79
for (int i = 0; i < 5; i++) {
80
runTest();
81
WB.fullGC();
82
}
83
}
84
85
public static void runTest() {
86
System.out.println("Starting test");
87
88
// Spray the heap with random object arrays in the hope that we get one
89
// at the proper place.
90
Object[][] arrays = new Object[numArrays][];
91
for (int i = 0; i < numArrays; i++) {
92
arrays[i] = new Object[arraySize];
93
}
94
95
// Make sure that everything is in old gen.
96
WB.fullGC();
97
98
// Find if we got an allocation at the right spot.
99
Object[] arrayWithCardMinus1 = findArray(arrays);
100
101
if (arrayWithCardMinus1 == null) {
102
System.out.println("Array with card -1 not found. Trying again.");
103
return;
104
} else {
105
System.out.println("Array with card -1 found.");
106
}
107
108
System.out.println("Modifying the last card in the array with a new object in a different region...");
109
// Create a target object that is guaranteed to be in a different region.
110
byte[] target = new byte[byteArraySize];
111
112
// Modify the last entry of the object we found.
113
arrayWithCardMinus1[arraySize - 1] = target;
114
115
target = null;
116
// Make sure that the dirty cards are flushed by doing a GC.
117
System.out.println("Doing a GC.");
118
WB.youngGC();
119
120
System.out.println("The crash didn't reproduce. Trying again.");
121
}
122
123
/**
124
* Finds an returns an array that contains a (32 bit truncated) card with value -1.
125
*/
126
private static Object[] findArray(Object[][] arrays) {
127
for (int i = 0; i < arrays.length; i++) {
128
Object[] target = arrays[i];
129
if (target == null) {
130
continue;
131
}
132
WB.getObjectAddress(target); // startAddress not used
133
final long lastAddress = getObjectLastAddress(target);
134
final int card = getCardIndex32bit(lastAddress);
135
if (card == -1) {
136
Object[] foundArray = target;
137
return foundArray;
138
}
139
}
140
return null;
141
}
142
}
143
144
145