Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/Env.java
41155 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 vm.mlvm.share;
25
26
import java.util.Random;
27
import jdk.test.lib.Utils;
28
29
import nsk.share.ArgumentParser;
30
import nsk.share.Log;
31
import nsk.share.Log.TraceLevel;
32
import nsk.share.test.LazyFormatString;
33
34
public class Env {
35
36
private static class StaticHolder {
37
public static ArgumentParser argParser;
38
public static Log log;
39
static {
40
init(new String[0]);
41
}
42
43
public static void init(String... args) {
44
init(new IgnoreUnknownArgumentParser(args));
45
}
46
47
public static void init(ArgumentParser ap) {
48
StaticHolder.argParser = ap;
49
StaticHolder.log = new Log(System.out, StaticHolder.argParser);
50
}
51
}
52
53
public static ArgumentParser getArgParser() {
54
return StaticHolder.argParser;
55
}
56
57
public static Log getLog() {
58
return StaticHolder.log;
59
}
60
61
public static void init(String... args) {
62
StaticHolder.init(args);
63
}
64
65
public static void init(ArgumentParser ap) {
66
StaticHolder.init(ap);
67
}
68
69
//
70
// RNG
71
//
72
73
private static long _seed = Utils.SEED;
74
75
private static volatile boolean _wasSeedPrinted = false;
76
77
// Thread local variable containing each thread's ID
78
private static final ThreadLocal<Random> _threadRNG =
79
new ThreadLocal<Random>() {
80
@Override protected Random initialValue() {
81
if ( ! _wasSeedPrinted ) {
82
_wasSeedPrinted = true;
83
traceImportant("RNG seed = " + _seed + " (0x" + Long.toHexString(_seed) + ")");
84
// ensure we also print out how to change seed
85
Utils.getRandomInstance();
86
}
87
88
long seed = _seed;
89
String name = Thread.currentThread().getName();
90
for ( int n = 0; n < name.length(); n++ )
91
seed ^= name.charAt(n) << ((n % 7) * 8);
92
93
traceVerbose(Thread.currentThread() + " RNG seed = " + seed + " (0x" + Long.toHexString(seed) + ")");
94
95
return new Random(seed);
96
}
97
};
98
99
public static Random getRNG() {
100
return _threadRNG.get();
101
}
102
103
//
104
// Syntactic sugar
105
//
106
107
public static void traceImportant(String msg) {
108
getLog().trace(TraceLevel.TRACE_IMPORTANT, msg);
109
}
110
111
public static void traceImportant(String msg, Object... args) {
112
getLog().trace(TraceLevel.TRACE_IMPORTANT, new LazyFormatString(msg, args));
113
}
114
115
public static void traceImportant(Throwable t, String msg, Object... args) {
116
getLog().trace(TraceLevel.TRACE_IMPORTANT, new LazyFormatString(msg, args), t);
117
}
118
119
public static void traceNormal(String msg) {
120
getLog().trace(TraceLevel.TRACE_NORMAL, msg);
121
}
122
123
public static void traceNormal(String msg, Object... args) {
124
getLog().trace(TraceLevel.TRACE_NORMAL, new LazyFormatString(msg, args));
125
}
126
127
public static void traceNormal(Throwable t, String msg, Object... args) {
128
getLog().trace(TraceLevel.TRACE_NORMAL, new LazyFormatString(msg, args), t);
129
}
130
131
public static void traceVerbose(String msg) {
132
getLog().trace(TraceLevel.TRACE_VERBOSE, msg);
133
}
134
135
public static void traceVerbose(String msg, Object... args) {
136
getLog().trace(TraceLevel.TRACE_VERBOSE, new LazyFormatString(msg, args));
137
}
138
139
public static void traceVerbose(Throwable t, String msg, Object... args) {
140
getLog().trace(TraceLevel.TRACE_VERBOSE, new LazyFormatString(msg, args), t);
141
}
142
143
public static void traceDebug(String msg) {
144
getLog().trace(TraceLevel.TRACE_DEBUG, msg);
145
}
146
147
public static void traceDebug(String msg, Object... args) {
148
getLog().trace(TraceLevel.TRACE_DEBUG, new LazyFormatString(msg, args));
149
}
150
151
public static void traceDebug(Throwable t, String msg, Object... args) {
152
getLog().trace(TraceLevel.TRACE_DEBUG, new LazyFormatString(msg, args), t);
153
}
154
155
public static void display(String msg) {
156
getLog().trace(TraceLevel.TRACE_IMPORTANT, msg);
157
}
158
159
public static void display(String msg, Object... args) {
160
getLog().trace(TraceLevel.TRACE_IMPORTANT, new LazyFormatString(msg, args));
161
}
162
163
public static void complain(String msg) {
164
getLog().complain(msg);
165
}
166
167
public static void complain(String msg, Object... args) {
168
getLog().complain(new LazyFormatString(msg, args));
169
}
170
171
public static void complain(Throwable t, String msg, Object... args) {
172
getLog().complain(new LazyFormatString(msg, args), t);
173
}
174
175
/**
176
* Throws an arbitrary exception as unchecked one.
177
* The method does not return normally.
178
*
179
* If the exception is not a subclass of java.lang.RuntimeException`
180
* or java.lang.Error, it is wrapped into java.lang.RuntimeException
181
*
182
* @param exception Exception to throw (wrapping it when it is checked on)
183
*/
184
public static void throwAsUncheckedException(Throwable exception) {
185
if (exception instanceof RuntimeException) {
186
throw (RuntimeException) exception;
187
}
188
189
if (exception instanceof Error) {
190
throw (Error) exception;
191
}
192
193
throw new RuntimeException(exception.getMessage(), exception);
194
}
195
}
196
197