Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/ThreadGC/ThreadGC.java
41155 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/ThreadGC.
30
* VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
31
* VM Testbase readme:
32
* This tests attempts to stress the garbage collector my making
33
* synchronous calls to the garbage collector after producing garbage.
34
* The garbage collector is invoked in a separate thread.
35
* The test runs for one minute (see nsk.share.runner.ThreadsRunner and
36
* nsk.share.runner.RunParams. It passes if no exceptions are generated.
37
*
38
* @library /vmTestbase
39
* /test/lib
40
* @run main/othervm gc.gctests.ThreadGC.ThreadGC -gp random(arrays) -ms low
41
*/
42
43
package gc.gctests.ThreadGC;
44
45
import nsk.share.gc.*;
46
import nsk.share.gc.gp.*;
47
import java.util.*;
48
49
public class ThreadGC extends ThreadedGCTest implements GarbageProducerAware, MemoryStrategyAware {
50
private GarbageProducer garbageProducer;
51
private MemoryStrategy memoryStrategy;
52
private Reclaimer reclaimer;
53
private int count;
54
private long size;
55
56
private class Devourer implements Runnable {
57
private Object[] arr = null;
58
private int index;
59
60
public void run() {
61
if (arr == null || index >= count) {
62
arr = null;
63
arr = new Object[count];
64
index = 0;
65
synchronized (reclaimer) {
66
reclaimer.notify();
67
}
68
}
69
arr[index] = garbageProducer.create(size);
70
++index;
71
}
72
}
73
74
private class Reclaimer implements Runnable {
75
private long waitTime = 1000;
76
77
public void run() {
78
try {
79
synchronized (this) {
80
this.wait(waitTime);
81
}
82
} catch (InterruptedException e) {
83
}
84
System.gc();
85
}
86
}
87
88
protected Runnable createRunnable(int i) {
89
if (i == 0)
90
return new Devourer();
91
else if (i == 1) {
92
reclaimer = new Reclaimer();
93
return reclaimer;
94
} else
95
return null;
96
}
97
98
public void run() {
99
size = GarbageUtils.getArraySize(runParams.getTestMemory(), memoryStrategy);
100
count = GarbageUtils.getArrayCount(runParams.getTestMemory(), memoryStrategy);
101
runParams.setIterations(count);
102
super.run();
103
}
104
105
public static void main(String[] args) {
106
GC.runTest(new ThreadGC(), args);
107
}
108
109
public void setGarbageProducer(GarbageProducer garbageProducer) {
110
this.garbageProducer = garbageProducer;
111
}
112
113
public void setMemoryStrategy(MemoryStrategy memoryStrategy) {
114
this.memoryStrategy = memoryStrategy;
115
}
116
117
}
118
119