Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/gc/containers/ContainersTest.java
41155 views
1
/*
2
* Copyright (c) 2010, 2018, 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
package vm.gc.containers;
24
25
import java.lang.management.ManagementFactory;
26
import java.lang.management.MemoryUsage;
27
import java.util.*;
28
import nsk.share.TestBug;
29
import nsk.share.gc.*;
30
import nsk.share.gc.gp.GarbageProducer;
31
import nsk.share.gc.gp.GarbageProducerAware;
32
import nsk.share.gc.gp.MemoryStrategy;
33
import nsk.share.gc.gp.MemoryStrategyAware;
34
import nsk.share.test.ExecutionController;
35
36
/*
37
* The main class and launcher for all containers tests.
38
* Allow to set containers via set -ct parameters. See parseFromString decription.
39
*/
40
public class ContainersTest extends ThreadedGCTest implements MemoryStrategyAware, GarbageProducerAware {
41
42
private GarbageProducer garbageProducer;
43
private MemoryStrategy memoryStrategy;
44
MemoryUsage mbean = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
45
46
public ContainersTest(String[] args) {
47
for (int i = 0; i < args.length; i++) {
48
if (args[i].equals("-ct")) {
49
descrs.add(ContainerDescription.parseFromString(args[i + 1]));
50
}
51
}
52
if (descrs.size() == 0) {
53
throw new TestBug("No containers were given");
54
}
55
}
56
57
@Override
58
public void setMemoryStrategy(MemoryStrategy memoryStrategy) {
59
this.memoryStrategy = memoryStrategy;
60
}
61
62
@Override
63
public void setGarbageProducer(GarbageProducer gp) {
64
this.garbageProducer = gp;
65
}
66
67
private class Mutator implements Runnable {
68
69
Container container;
70
71
public Mutator(Container container) {
72
this.container = container;
73
}
74
75
@Override
76
public void run() {
77
ExecutionController stresser = getExecutionController();
78
container.setExecutionController(stresser);
79
try {
80
container.initialize();
81
while (stresser.continueExecution()) {
82
container.update();
83
}
84
} catch (OutOfMemoryError oome) {
85
// The OOME is teoretically possible in the case
86
// if data structure has a large overhead
87
}
88
}
89
}
90
List<ContainerDescription> descrs = new ArrayList<ContainerDescription>();
91
List<Container> containers = new ArrayList<Container>();
92
93
@Override
94
protected Runnable createRunnable(int i) {
95
return new Mutator(containers.get(i));
96
}
97
98
public Container createContainter(long maxMemory, ContainerDescription descr) {
99
String[] prefixes = {"java.util", "java.util.concurrent", "vm.gc.containers"};
100
String name = descr.getName();
101
Class clz = null;
102
for (String prefix : prefixes) {
103
try {
104
clz = Class.forName(prefix + "." + name);
105
} catch (ClassNotFoundException ex) {
106
// no such class, contiue
107
}
108
}
109
Object container;
110
try {
111
container = clz.newInstance();
112
} catch (Exception ex) {
113
throw new TestBug("Not able to create a container", ex);
114
}
115
// Deques are also collections...
116
if (container instanceof Map) {
117
return new MapContainer((Map) container, maxMemory,
118
descr.getGarbageProducer() != null ? descr.getGarbageProducer() : garbageProducer,
119
descr.getMemoryStrategy() != null ? descr.getMemoryStrategy() : memoryStrategy,
120
descr.getSpeed());
121
} else if (container instanceof Deque) {
122
return new DequeueContainer((Deque) container, maxMemory,
123
descr.getGarbageProducer() != null ? descr.getGarbageProducer() : garbageProducer,
124
descr.getMemoryStrategy() != null ? descr.getMemoryStrategy() : memoryStrategy,
125
descr.getSpeed(), runParams.getNumberOfThreads());
126
} else if (container instanceof Collection) {
127
return new CollectionContainer((Collection) container, maxMemory,
128
descr.getGarbageProducer() != null ? descr.getGarbageProducer() : garbageProducer,
129
descr.getMemoryStrategy() != null ? descr.getMemoryStrategy() : memoryStrategy,
130
descr.getSpeed());
131
}
132
throw new TestBug("Not able to create a container");
133
}
134
135
void createEmptyContainers(long maxMemory) {
136
containers = new ArrayList<Container>();
137
for (int i = 0; containers.size() < runParams.getNumberOfThreads(); i++) {
138
Container container = createContainter(maxMemory / runParams.getNumberOfThreads(),
139
descrs.get(i % descrs.size()));
140
// we share container between workers if threadsCount > 1
141
for (int cnt = descrs.get(i % descrs.size()).getThreadsCount();
142
cnt != 0 && containers.size() < runParams.getNumberOfThreads();
143
cnt--) {
144
containers.add(container);
145
}
146
}
147
}
148
149
@Override
150
public void run() {
151
long maxMemory = runParams.getTestMemory();
152
createEmptyContainers(maxMemory);
153
super.run();
154
}
155
156
public static void main(String args[]) {
157
GC.runTest(new ContainersTest(args), args);
158
}
159
}
160
161