Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/vector/SimpleGC/SimpleGC.java
41155 views
1
/*
2
* Copyright (c) 2007, 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/vector/SimpleGC.
29
* VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, monitoring]
30
*
31
* @library /vmTestbase
32
* /test/lib
33
* @run main/othervm gc.vector.SimpleGC.SimpleGC -ms high
34
*/
35
36
package gc.vector.SimpleGC;
37
38
import nsk.share.gc.GC;
39
import nsk.share.gc.GCTestBase;
40
import nsk.share.gc.gp.GarbageProducer;
41
import nsk.share.gc.gp.GarbageProducerAware;
42
import nsk.share.gc.gp.GarbageUtils;
43
import nsk.share.gc.gp.MemoryStrategy;
44
import nsk.share.gc.gp.MemoryStrategyAware;
45
import nsk.share.runner.RunParams;
46
import nsk.share.test.Stresser;
47
48
/**
49
* Test that fills out a certain amount of memory with objects of a given type.
50
* The test accepts MemoryStrategy, type of objects and stress options
51
* as command line args.
52
*/
53
public class SimpleGC extends GCTestBase implements GarbageProducerAware, MemoryStrategyAware {
54
55
private GarbageProducer garbageProducer;
56
private MemoryStrategy memoryStrategy;
57
58
/**
59
* Garbage link.
60
* The field is static to prevent possible compiler optimizations.
61
*/
62
public static Object[] array;
63
64
@Override
65
public void run() {
66
67
long memoryAmount = runParams.getTestMemory();
68
long size = GarbageUtils.getArraySize(memoryAmount, memoryStrategy);
69
int length = GarbageUtils.getArrayCount(memoryAmount, memoryStrategy);
70
Object[] garbage = new Object[length];
71
array = garbage;
72
log.info("Memory to fill out: " + memoryAmount);
73
log.info("Array lenght: " + garbage.length);
74
log.info("Object size: " + size);
75
log.info("Garbage producer: " + garbageProducer.getClass().getCanonicalName());
76
log.info("Memory Strategy: " + memoryStrategy);
77
Stresser stresser = new Stresser(runParams.getStressOptions());
78
stresser.start(10 * garbage.length);
79
80
int iteration = 0;
81
try {
82
while (stresser.iteration()) {
83
for (int i = 0; i < garbage.length && stresser.continueExecution(); ++i) {
84
garbage[i] = garbageProducer.create(size);
85
}
86
for (int i = 0; i < garbage.length; ++i) {
87
garbage[i] = null;
88
}
89
iteration++;
90
if (iteration % 1000 == 0) {
91
log.info(" iteration # " + iteration);
92
}
93
}
94
} catch (OutOfMemoryError oom) {
95
// normally that should never be thrown
96
log.info("OutOfMemory after " + iteration + " iterations");
97
throw oom;
98
} finally {
99
stresser.finish();
100
}
101
log.info("Success. Total iterations: " + iteration);
102
}
103
104
@Override
105
public final void setGarbageProducer(GarbageProducer garbageProducer) {
106
this.garbageProducer = garbageProducer;
107
}
108
109
@Override
110
public final void setMemoryStrategy(MemoryStrategy memoryStrategy) {
111
this.memoryStrategy = memoryStrategy;
112
}
113
114
public static void main(String[] args) {
115
RunParams.getInstance().setRunMemDiagThread(true);
116
GC.runTest(new SimpleGC(), args);
117
}
118
}
119
120