Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GetCurrentThreadCpuTime/curthrcputime001.java
40948 views
1
/*
2
* Copyright (c) 2003, 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
24
package nsk.jvmti.GetCurrentThreadCpuTime;
25
26
import java.io.PrintStream;
27
28
import nsk.share.*;
29
import nsk.share.jvmti.*;
30
31
/** Debuggee class for this test. */
32
public class curthrcputime001 extends DebugeeClass {
33
34
/** Load native library if required. */
35
static {
36
loadLibrary("curthrcputime001");
37
}
38
39
/** Run test from command line. */
40
public static void main(String argv[]) {
41
argv = nsk.share.jvmti.JVMTITest.commonInit(argv);
42
43
// JCK-compatible exit
44
System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);
45
}
46
47
/** Run test from JCK-compatible environment. */
48
public static int run(String argv[], PrintStream out) {
49
return new curthrcputime001().runIt(argv, out);
50
}
51
52
/* =================================================================== */
53
54
// scaffold objects
55
ArgumentHandler argHandler = null;
56
Log log = null;
57
long timeout = 0;
58
int status = Consts.TEST_PASSED;
59
60
static final String TESTED_THREAD_NAME = "curthrcputime001Thread";
61
static final int SLEEP_TIME = 5 * 1000; // milliseconds
62
63
/** Run debuggee. */
64
public int runIt(String argv[], PrintStream out) {
65
argHandler = new ArgumentHandler(argv);
66
log = new Log(out, argHandler);
67
timeout = argHandler.getWaitTime() * 60 * 1000; // milliseconds
68
69
int iterations = argHandler.findOptionIntValue("iterations", 1000);
70
71
curthrcputime001Thread thread = new curthrcputime001Thread(TESTED_THREAD_NAME, iterations);
72
73
// sync before thread started
74
log.display("Sync: tested thread created");
75
status = checkStatus(status);
76
77
// start and finish tested thread
78
try {
79
synchronized (thread.endingMonitor) {
80
// start thread and wait for start notification
81
synchronized (thread.startingMonitor) {
82
thread.start();
83
thread.startingMonitor.wait();
84
}
85
86
// sync after thread started
87
log.display("Sync: tested thread started");
88
status = checkStatus(status);
89
90
// let thread to finish
91
}
92
93
// wait for thread to finish
94
thread.join();
95
96
} catch (InterruptedException e) {
97
throw new Failure("Main thread interrupted while running tested thread:\n\t"
98
+ e);
99
}
100
101
// sync after thread finished
102
log.display("Sync: tested thread finished");
103
status = checkStatus(status);
104
105
return status;
106
}
107
}
108
109
/* =================================================================== */
110
111
/** Class for tested thread. */
112
class curthrcputime001Thread extends Thread {
113
public int iterations;
114
115
public Object startingMonitor = new Object();
116
public Object endingMonitor = new Object();
117
118
/** Make thread with specific name. */
119
public curthrcputime001Thread(String name, int iterations) {
120
super(name);
121
this.iterations = iterations;
122
}
123
124
/** Run some code. */
125
public void run() {
126
127
runIterations(iterations);
128
129
// notify about start
130
synchronized (startingMonitor) {
131
startingMonitor.notifyAll();
132
}
133
134
runIterations(iterations);
135
136
// wait for finishing enabled
137
synchronized (endingMonitor) {
138
}
139
140
runIterations(iterations);
141
142
}
143
144
/** Run some code with given number of iterations. */
145
void runIterations(int n) {
146
for (int k = 0; k < n; k++) {
147
int s = k;
148
for (int i = 0; i < n; i++) {
149
if (i % 2 == 0) {
150
s += i * 10;
151
} else {
152
s -= i * 10;
153
}
154
}
155
}
156
}
157
}
158
159