Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC002/JumbleGC002.java
41159 views
1
/*
2
* Copyright (c) 2003, 2020, 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
* @key stress randomness
27
*
28
* @summary converted from VM Testbase gc/gctests/JumbleGC002.
29
* VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, quarantine]
30
* VM Testbase readme:
31
* DESCRIPTION
32
* The test checks that Garbage Collector can manage jumble in the JVM. The
33
* test fails if any unexpected exceptions and errors are thrown or the JVM
34
* is not crashed.
35
* The test starts a number of threads that is set in *.cfg file or calculates
36
* that value based on the machine. All threads have
37
* java.util.Vector field anf they fill that vector with 4 types of objects:
38
* 1. Initialized long[]
39
* 2. Uninitialized double[]
40
* 3. Initialized int[]
41
* 4. A nsk.share.gc.NonbranchyTree (number of nodes and their size depend
42
* on valkue returned by Runtime.maxMemory())
43
* As soon as the vector is filled, each thread removes half elements of it and
44
* then fills those places of the vector again. However, all threads use just
45
* about 10% of maximum amount of memory that JVM attemts to use, so
46
* OutOfMemoryError is treated as a failure. That means GC does not work
47
* quickly enough to destroy all objects that do not have references. The
48
* procedure of filling and cleaning of the vector is repeated for
49
* INTERNAL_ITERATIONS times.
50
*
51
* @library /vmTestbase
52
* /test/lib
53
* @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.JumbleGC002.JumbleGC002
54
*/
55
56
package gc.gctests.JumbleGC002;
57
58
import java.io.*;
59
import java.util.*;
60
61
import nsk.share.*;
62
import nsk.share.gc.*;
63
import nsk.share.test.LocalRandom;
64
65
/**
66
* This test simply does Algorithms.eatMemory() in a loop
67
* in multiple threads.
68
*/
69
public class JumbleGC002 extends ThreadedGCTest {
70
71
// The test should fill just about 10% of the heap
72
final static double PART_OF_HEAP = 0.1;
73
// Maximum number of elements in an array of primitive types
74
final static int ARRAY_MAX_LENGTH = 10;
75
// Internal number of iterations to create new objects and to drop
76
// references
77
final static int INTERNAL_ITERATIONS = 150;
78
// Size of core for each node of a tree
79
final static int EACH_NODE_SIZE = 1;
80
// Number of bytes that arrays of primitive types take in the vector
81
final static long PRIMITIVE_ARRAYS_SIZE = (long) (8 * ARRAY_MAX_LENGTH
82
+ 8 * ARRAY_MAX_LENGTH + 4 * ARRAY_MAX_LENGTH);
83
84
private class Eater implements Runnable {
85
86
private Vector vector;
87
int numberOfElements;
88
int numberOfQuarters;
89
int id;
90
int nodes;
91
92
public Eater(int id, int numberOfQuarters, int nodes) {
93
this.numberOfQuarters = numberOfQuarters;
94
numberOfElements = 4 * numberOfQuarters;
95
this.id = id;
96
this.nodes = nodes;
97
}
98
99
public void run() {
100
// Make jumble in the heap!
101
initVector();
102
while (getExecutionController().continueExecution()) {
103
fillVector();
104
cleanVector();
105
}
106
}
107
108
// Initialize the vector and build appropriate number of cells in it
109
private void initVector() {
110
vector = new Vector();
111
for (int i = 0; i < numberOfElements; i++) {
112
vector.addElement(null);
113
}
114
}
115
116
// Fill the vector. It is devided into quarters. Each quarters has an
117
// initialized array of long and int, and uninitialized array of double.
118
// Each array has not more than ARRAY_MAX_LENGTH elements. The fourth
119
// element in the quarter is a NonbranchyTree.
120
private void fillVector() {
121
for (int i = 0; i < numberOfQuarters; i++) {
122
123
// Append initialized long[]
124
int length = LocalRandom.nextInt(ARRAY_MAX_LENGTH);
125
long[] l = new long[length];
126
for (int j = 0; j < length; j++) {
127
l[j] = (long) j;
128
}
129
if (vector.elementAt(4 * i) == null) {
130
vector.setElementAt(l, 4 * i);
131
}
132
133
// Append not initialized double[]
134
length = LocalRandom.nextInt(ARRAY_MAX_LENGTH);
135
double[] d = new double[length];
136
if (vector.elementAt(4 * i + 1) == null) {
137
vector.setElementAt(d, 4 * i + 1);
138
}
139
140
// Append initialized int[]
141
length = LocalRandom.nextInt(ARRAY_MAX_LENGTH);
142
int[] n = new int[length];
143
for (int j = 0; j < length; j++) {
144
n[j] = j;
145
}
146
if (vector.elementAt(4 * i + 2) == null) {
147
vector.setElementAt(n, 4 * i + 2);
148
}
149
150
// Append a tree. Every even thread has a "bent" tree.
151
NonbranchyTree tree = new NonbranchyTree(nodes, 0.3f, EACH_NODE_SIZE);
152
if (id % 2 == 0) {
153
tree.bend();
154
}
155
if (vector.elementAt(4 * i + 3) == null) {
156
vector.setElementAt(tree, 4 * i + 3);
157
}
158
}
159
}
160
161
// Drop references to half of the elements of the vector
162
private void cleanVector() {
163
int index = LocalRandom.nextInt(numberOfElements / 2);
164
for (int i = index; i < index + numberOfElements / 2; i++) {
165
vector.setElementAt(null, i);
166
}
167
}
168
}
169
170
protected Runnable createRunnable(int i) {
171
// Perform calculations specific to the test
172
long memoryForThread = (long) (Runtime.getRuntime().maxMemory() * PART_OF_HEAP / runParams.getNumberOfThreads());
173
int numberOfQuarters;
174
175
if (i == 0) {
176
// The very first thread
177
numberOfQuarters = 1;
178
} else {
179
// All other threads
180
numberOfQuarters = 8;
181
}
182
183
// Calculate number of nodes for a tree depending on number of
184
// elements in the Vector
185
186
double freeMemory = (double) memoryForThread / numberOfQuarters
187
- (double) PRIMITIVE_ARRAYS_SIZE;
188
int nodes = (int) (freeMemory / (NonbranchyTree.MIN_NODE_SIZE + EACH_NODE_SIZE));
189
nodes = Math.max(1, nodes);
190
log.debug("Thread " + i + " has a tree with "
191
+ nodes + " node(s).");
192
193
return new Eater(i, numberOfQuarters, nodes);
194
}
195
196
public static void main(String args[]) {
197
GC.runTest(new JumbleGC002(), args);
198
}
199
}
200
201