Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest03/gctest03.java
41155 views
1
/*
2
* Copyright (c) 2002, 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
/* stress testing
25
Redthreads keep removing new nodes from a binary sort tree(
26
all nodes of its left subtree is less than itself, all nodes
27
of its right subtree is large than itself).
28
Bluethreads keep adding nodes into the binary sort tree.
29
YellowThreads search the binary sort tree.
30
The nodes removed from the tree will become garbages immediately
31
Create 10 Redthreads and 10 Bluethreads to manipulate the
32
the same binary tree involving excessive memory allocation
33
to test if memory management module and gc() crash.
34
*/
35
36
37
/*
38
* @test
39
* @key randomness
40
*
41
* @summary converted from VM Testbase gc/gctests/gctest03.
42
* VM Testbase keywords: [gc]
43
*
44
* @library /vmTestbase
45
* /test/lib
46
* @compile Tree.java appthread.java
47
* @run main/othervm gc.gctests.gctest03.gctest03 10000
48
*/
49
50
package gc.gctests.gctest03;
51
52
import nsk.share.test.*;
53
import nsk.share.gc.*;
54
import nsk.share.TestFailure;
55
import nsk.share.TestBug;
56
57
//import Tree;
58
//import Redthread;
59
//import Bluethread;
60
61
public class gctest03 extends TestBase {
62
private String[] args;
63
64
public gctest03(String[] args) {
65
this.args = args;
66
}
67
68
public void run() {
69
int i = 1;
70
int dataNodeLimit = 100000;
71
72
if (args.length > 0) {
73
try {
74
dataNodeLimit = Integer.valueOf(args[0]).intValue();
75
} catch (NumberFormatException e) {
76
throw new TestBug("Bad input to gctest03. Expected integer, " +
77
" got: ->" + args[0] + "<-", e);
78
}
79
}
80
81
for (int j = 0; j < 10; j++) {
82
DataNode.setDataNodeLimit(dataNodeLimit);
83
DataNode.clearDataNodeCount();
84
85
Tree tr = new Tree();
86
for (i =2; i < 100; i++) {
87
try {
88
DataNode d = new DataNode(i);
89
TreeNode t = new TreeNode(d);
90
tr.insert(t);
91
} catch (DataNodeException e) {
92
throw new TestFailure("DataNodeException caught in gctest03.main()", e);
93
}
94
}
95
96
int sz = 10;
97
98
//create 10 threads adding data into binary tree.
99
// each thread only adds the multiple of its key
100
//(1, 2, 3, 4, 5, 6, 7, 8, 9 , 10). No duplication
101
102
Redthread rth[] = new Redthread[sz];
103
104
for(i=0; i < sz; i++) {
105
rth[i] = new Redthread(tr, i+1);
106
rth[i].setName("Redthread" + i);
107
rth[i].start();
108
}
109
110
//create 10 threads removing data from the tree.
111
112
Bluethread bth[] = new Bluethread[sz];
113
114
for(i=0; i < sz; i++) {
115
bth[i] = new Bluethread(tr, i+1);
116
bth[i].setName("Bluethread" + i);
117
bth[i].start();
118
}
119
120
121
//create 10 threads inquiring data from the tree
122
123
Yellowthread yth[] = new Yellowthread[sz];
124
for(i=0; i < sz; i++) {
125
yth[i] = new Yellowthread(tr, i+1);
126
yth[i].setName("Yellowthread" + i);
127
yth[i].start();
128
}
129
130
for (i = 0; i < sz; i++) {
131
try {
132
rth[i].join();
133
bth[i].join();
134
yth[i].join();
135
} catch (InterruptedException e) {
136
System.err.println("Error joining with threads in gctest03.main()");
137
System.err.println("Loop count: " + i);
138
}
139
}
140
}
141
142
}
143
144
public static void main(String args[]) {
145
GC.runTest(new gctest03(args), args);
146
}
147
}
148
149