Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/monitoring/ThreadMXBean/ThreadMXBeanTestBase.java
40948 views
1
/*
2
* Copyright (c) 2011, 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
package nsk.monitoring.ThreadMXBean;
25
26
import java.util.*;
27
import nsk.share.test.*;
28
import nsk.monitoring.share.*;
29
import nsk.share.gc.Memory;
30
31
public abstract class ThreadMXBeanTestBase extends MonitoringTestBase
32
implements Initializable {
33
34
/**
35
* Maximum allocation object size. about 2 Mb
36
*/
37
private static final int MAX_OBJECT_SIZE = 2*1024*1024;
38
/**
39
* Allocations count for each MXBeanTestThread
40
*/
41
private static final int ALLOCATIONS = 100;
42
/**
43
* Minimum size of allocated objects for a single thread stressing GC: 1Mb
44
*/
45
protected static final int MIN_STRESS_ALLOCATION_AMOUNT = 1024*1024;
46
/**
47
* Percent of maximum difference of actual result from expected one
48
*/
49
protected static final int DELTA_PERCENT = 15;
50
/**
51
* Instance of com.sun.management.ThreadMXBean used by all tests
52
* Obtained in initialize() method
53
*/
54
protected com.sun.management.ThreadMXBean threadMXBean;
55
/**
56
* Stresser class instance used in StressTest
57
*/
58
protected Stresser stresser;
59
/**
60
* String indicating the GarbageProducer type used in test
61
*/
62
protected String garbageProducerId;
63
/**
64
* Defined array with allocation objects sizes
65
*/
66
protected static int[] allocArr = new int[ALLOCATIONS];
67
68
/**
69
* Obtains instance of com.sun.management.ThreadMXBean
70
* and stores it in threadMXBean field
71
* If com.sun.management.ThreadMXBean API is not available,
72
* threadMXBean is set to null and appropriate message is
73
* prompted
74
*/
75
public void initialize() {
76
if (monitoringFactory.hasThreadMXBeanNew()) {
77
threadMXBean =
78
(com.sun.management.ThreadMXBean) monitoringFactory.getThreadMXBeanNew();
79
// ensure LocalRandom is loaded and has enough memory
80
LocalRandom.init();
81
for (int i = 0; i < ALLOCATIONS; i++) {
82
allocArr[i] = Memory.getArrayExtraSize() + Memory.getIntSize()
83
+ Memory.getReferenceSize() // don't be zero-length
84
+ LocalRandom.nextInt(MAX_OBJECT_SIZE);
85
}
86
} else {
87
log.info("com.sun.management.ThreadMXBean API is not available!");
88
}
89
}
90
91
/**
92
* Obtains instance of Stresser and stores it in stresser field
93
* @param args Stresser arguments
94
*/
95
public void setStresser(String[] args) {
96
if (stresser == null)
97
stresser = new Stresser(args);
98
}
99
100
/**
101
* Parses input String arrays searching for GarbageProducer
102
* settings. If found, sets garbageProducerID filed.
103
* @param args input arguments
104
* @return input arguments without GarbageProducer options
105
*/
106
public String[] setGarbageProducer(String[] args) {
107
if (garbageProducerId == null) {
108
ArrayList<String> list = new ArrayList<String>();
109
for (int i = 0; i < args.length; i++) {
110
if (args[i].equals("-gp")) {
111
garbageProducerId = args[++i];
112
} else {
113
list.add(args[i]);
114
}
115
}
116
return list.toArray(new String[] {});
117
} else {
118
return args;
119
}
120
}
121
122
/**
123
* Starts all specified TestThread threads
124
* @param threads threads to start
125
*/
126
public BarrierHandler startThreads(MXBeanTestThread... threads) {
127
BarrierHandler handler = new BarrierHandler(threads);
128
for (MXBeanTestThread thread : threads) {
129
thread.setHandler(handler);
130
thread.start();
131
}
132
handler.start();
133
return handler;
134
}
135
136
/**
137
* Returns expected memory size allocated by MXBeanTestThreads during
138
* stress test (allocateStress() method execution)
139
*
140
* @param array of MXBeanTestThreads
141
* @return expected amount of memory allocated by each StressTestThread
142
*/
143
public long[] getStressAllocatedBytes(MXBeanTestThread... threads) {
144
long[] result = new long[threads.length];
145
int counter = 0;
146
for (MXBeanTestThread thread : threads) {
147
result[counter++] = thread.getStressAllocatedBytes();
148
}
149
return result;
150
}
151
}
152
153