Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/MatrixJuggleGC/MatrixJuggleGC.java
41159 views
1
/*
2
* Copyright (c) 2002, 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
/*
26
* @test
27
* @key stress randomness
28
*
29
* @summary converted from VM Testbase gc/gctests/MatrixJuggleGC.
30
* VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
31
* VM Testbase readme:
32
* ********************************
33
* set TIMEOUT = 20
34
* *******************************
35
* This test creates a 2 dimensional matrix of (100X100)10,000 elements.
36
* Each element in this matrix houses the address of a "Cell" that
37
* occupies about 100 bytes. The total memory occupied by this structure is
38
* about 1M.
39
* Once this structure, has been built, 5 threads are let loose that
40
* randomly choose an element in this matrix and set its contents to null
41
* effectively creating 100bytes of garbage. The threads continue to act
42
* until all 5 threads combined have "nulled out" half the cells in the matrix.
43
* At this point, 5 refiller threads proceed to refill the empty
44
* matrix elements with new cells.
45
* Once the refiller threads have refilled all the empty matrix elements
46
* with new cells, the cycle begins all over again with the 5 "emptier"
47
* threads "nulling out" cells randomly.
48
* This is repeated 50 times. Every iteration produces 0.5 Meg
49
* of garbage. The maximum amount of live memory at use at any time is 1Meg.
50
* If no garbage collection takes place during any of the ten iterations,
51
* the total amount(live + garbage) of heap space consumed at the end
52
* of the program is 0.5*50 + 1 = 26Meg.
53
* The test fails if an OutOfMemory Exception is thrown.
54
* ----------------------------- --------
55
* | | | | | | | 100 |
56
* | | | | | *--|------>| bytes|
57
* | | | | | | --------
58
* -----------------------------
59
* . . . . . .
60
* . . . . . .
61
* . . . . . .
62
* .
63
* | | | | | |
64
* | | | | | |
65
* | | | | | |
66
* ------------------------------
67
* | | | | | |
68
* | | | | | |
69
* | | | | | |
70
* ------------------------------
71
* | | | | | |
72
* | | | | | |
73
* | | | | | |
74
* ------------------------------
75
* | | | | | |
76
* | | | | | |
77
* | | | | | |
78
* -----------------------------
79
*
80
* @library /vmTestbase
81
* /test/lib
82
* @run main/othervm gc.gctests.MatrixJuggleGC.MatrixJuggleGC -iterations 1000000
83
*/
84
85
package gc.gctests.MatrixJuggleGC;
86
87
import nsk.share.test.*;
88
import nsk.share.gc.*;
89
import java.util.Stack;
90
import java.util.EmptyStackException;
91
92
public class MatrixJuggleGC extends GCTestBase {
93
private int threadCount = 5;
94
private Matrix cm = new Matrix(100, 100);
95
private Stack<IndexPair> emptiedLocations = new Stack<IndexPair>();
96
97
private class CellEmptier extends Thread {
98
private boolean keepEmptying(){
99
int numberOfCells;
100
int matrixSize;
101
102
matrixSize = cm.returnArrayBound();
103
numberOfCells = (matrixSize + 1) * (matrixSize + 1) ;
104
if (cm.getCellCount() < numberOfCells/2)
105
return true;
106
else
107
return false;
108
}
109
110
public void run() {
111
int i, j, matrixSize,emptyCells;
112
113
matrixSize = cm.returnArrayBound();
114
while (keepEmptying()) {
115
i = LocalRandom.nextInt(0, matrixSize);
116
j = LocalRandom.nextInt(0, matrixSize);
117
emptiedLocations.push(new IndexPair(i,j));
118
cm.clear(i, j);
119
}
120
}
121
}
122
123
private class CellRefiller extends Thread {
124
public void run() {
125
int i, j, emptyCells;
126
while (!emptiedLocations.empty()) {
127
try {
128
IndexPair pair = emptiedLocations.pop();
129
cm.repopulate(pair.getI(), pair.getJ());
130
} catch (EmptyStackException e) {
131
break;
132
}
133
}
134
}
135
}
136
137
private class StackDump extends Thread {
138
public void run() {
139
int emptyCells;
140
while (true) {
141
emptyCells = emptiedLocations.size();
142
System.out.println("Number of empty cells = " + emptyCells);
143
}
144
}
145
}
146
147
private void runIteration() {
148
Thread emptierArray[] = new Thread[threadCount];
149
Thread fillerArray[] = new Thread[threadCount];
150
for (int i = 0; i < threadCount; i++)
151
emptierArray[i] = new CellEmptier();
152
for (int i = 0; i < threadCount; i++)
153
emptierArray[i].start();
154
155
// wait for "emptier" threads to finish their job
156
157
int i = 0;
158
while (i < threadCount) {
159
try {
160
emptierArray[i].join();
161
} catch(InterruptedException e) {}
162
i++;
163
}
164
165
// Now start refilling.
166
167
for (i = 0; i < threadCount; i++)
168
fillerArray[i] = new CellRefiller();
169
for (i = 0; i < threadCount; i++)
170
fillerArray[i].start();
171
172
i = 0;
173
while (i < threadCount ){
174
try {
175
fillerArray[i].join();
176
} catch(InterruptedException e){}
177
i++;
178
}
179
// reset count of cells
180
cm.resetCellCount();
181
}
182
183
public void run() {
184
threadCount = runParams.getNumberOfThreads();
185
Stresser stresser = new Stresser(runParams.getStressOptions());
186
stresser.start(runParams.getIterations());
187
while (stresser.iteration())
188
runIteration();
189
stresser.finish();
190
}
191
192
public static void main(String args[]) {
193
GC.runTest(new MatrixJuggleGC(), args);
194
}
195
}
196
197