author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58574 | dcc760954243 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
55231
02db50f278f9
8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents:
53018
diff
changeset
|
2 |
* Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved. |
58574
dcc760954243
8231584: Deadlock with ClassLoader.findLibrary and System.loadLibrary call
akozlov
parents:
55319
diff
changeset
|
3 |
* Copyright (c) 2019, Azul Systems, Inc. All rights reserved. |
2 | 4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 |
* |
|
6 |
* This code is free software; you can redistribute it and/or modify it |
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 8 |
* published by the Free Software Foundation. Oracle designates this |
2 | 9 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 10 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 11 |
* |
12 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
16 |
* accompanied this code). |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License version |
|
19 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
20 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
21 |
* |
|
5506 | 22 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
23 |
* or visit www.oracle.com if you need additional information or have any |
|
24 |
* questions. |
|
2 | 25 |
*/ |
26 |
||
27 |
package java.lang; |
|
28 |
||
29 |
import java.io.*; |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
30 |
import java.math.BigInteger; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
31 |
import java.util.regex.Matcher; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
32 |
import java.util.regex.Pattern; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
33 |
import java.util.stream.Collectors; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
34 |
import java.util.List; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
35 |
import java.util.Optional; |
2 | 36 |
import java.util.StringTokenizer; |
48922
906025796009
8198441: Replace native Runtime::runFinalization0 method with shared secrets
mchung
parents:
48545
diff
changeset
|
37 |
|
52427
3c6aa484536c
8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents:
49508
diff
changeset
|
38 |
import jdk.internal.access.SharedSecrets; |
37363
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
34350
diff
changeset
|
39 |
import jdk.internal.reflect.CallerSensitive; |
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
34350
diff
changeset
|
40 |
import jdk.internal.reflect.Reflection; |
2 | 41 |
|
42 |
/** |
|
43 |
* Every Java application has a single instance of class |
|
30042 | 44 |
* {@code Runtime} that allows the application to interface with |
2 | 45 |
* the environment in which the application is running. The current |
30042 | 46 |
* runtime can be obtained from the {@code getRuntime} method. |
2 | 47 |
* <p> |
48 |
* An application cannot create its own instance of this class. |
|
49 |
* |
|
50 |
* @author unascribed |
|
51 |
* @see java.lang.Runtime#getRuntime() |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24367
diff
changeset
|
52 |
* @since 1.0 |
2 | 53 |
*/ |
54 |
||
55 |
public class Runtime { |
|
34350 | 56 |
private static final Runtime currentRuntime = new Runtime(); |
2 | 57 |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
58 |
private static Version version; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
59 |
|
2 | 60 |
/** |
61 |
* Returns the runtime object associated with the current Java application. |
|
30042 | 62 |
* Most of the methods of class {@code Runtime} are instance |
2 | 63 |
* methods and must be invoked with respect to the current runtime object. |
64 |
* |
|
30042 | 65 |
* @return the {@code Runtime} object associated with the current |
2 | 66 |
* Java application. |
67 |
*/ |
|
68 |
public static Runtime getRuntime() { |
|
69 |
return currentRuntime; |
|
70 |
} |
|
71 |
||
72 |
/** Don't let anyone else instantiate this class */ |
|
73 |
private Runtime() {} |
|
74 |
||
75 |
/** |
|
76 |
* Terminates the currently running Java virtual machine by initiating its |
|
77 |
* shutdown sequence. This method never returns normally. The argument |
|
78 |
* serves as a status code; by convention, a nonzero status code indicates |
|
79 |
* abnormal termination. |
|
80 |
* |
|
48942
a6c4b85163c1
8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents:
48922
diff
changeset
|
81 |
* <p> All registered {@linkplain #addShutdownHook shutdown hooks}, if any, |
a6c4b85163c1
8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents:
48922
diff
changeset
|
82 |
* are started in some unspecified order and allowed to run concurrently |
a6c4b85163c1
8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents:
48922
diff
changeset
|
83 |
* until they finish. Once this is done the virtual machine |
a6c4b85163c1
8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents:
48922
diff
changeset
|
84 |
* {@linkplain #halt halts}. |
2 | 85 |
* |
48942
a6c4b85163c1
8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents:
48922
diff
changeset
|
86 |
* <p> If this method is invoked after all shutdown hooks have already |
a6c4b85163c1
8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents:
48922
diff
changeset
|
87 |
* been run and the status is nonzero then this method halts the |
a6c4b85163c1
8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents:
48922
diff
changeset
|
88 |
* virtual machine with the given status code. Otherwise, this method |
2 | 89 |
* blocks indefinitely. |
90 |
* |
|
30042 | 91 |
* <p> The {@link System#exit(int) System.exit} method is the |
24367
705490680527
8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents:
18776
diff
changeset
|
92 |
* conventional and convenient means of invoking this method. |
2 | 93 |
* |
94 |
* @param status |
|
95 |
* Termination status. By convention, a nonzero status code |
|
96 |
* indicates abnormal termination. |
|
97 |
* |
|
98 |
* @throws SecurityException |
|
30042 | 99 |
* If a security manager is present and its |
100 |
* {@link SecurityManager#checkExit checkExit} method does not permit |
|
2 | 101 |
* exiting with the specified status |
102 |
* |
|
103 |
* @see java.lang.SecurityException |
|
104 |
* @see java.lang.SecurityManager#checkExit(int) |
|
105 |
* @see #addShutdownHook |
|
106 |
* @see #removeShutdownHook |
|
107 |
* @see #halt(int) |
|
108 |
*/ |
|
109 |
public void exit(int status) { |
|
110 |
SecurityManager security = System.getSecurityManager(); |
|
111 |
if (security != null) { |
|
112 |
security.checkExit(status); |
|
113 |
} |
|
114 |
Shutdown.exit(status); |
|
115 |
} |
|
116 |
||
117 |
/** |
|
118 |
* Registers a new virtual-machine shutdown hook. |
|
119 |
* |
|
120 |
* <p> The Java virtual machine <i>shuts down</i> in response to two kinds |
|
121 |
* of events: |
|
122 |
* |
|
123 |
* <ul> |
|
124 |
* |
|
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
16906
diff
changeset
|
125 |
* <li> The program <i>exits</i> normally, when the last non-daemon |
30042 | 126 |
* thread exits or when the {@link #exit exit} (equivalently, |
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
16906
diff
changeset
|
127 |
* {@link System#exit(int) System.exit}) method is invoked, or |
2 | 128 |
* |
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
16906
diff
changeset
|
129 |
* <li> The virtual machine is <i>terminated</i> in response to a |
30042 | 130 |
* user interrupt, such as typing {@code ^C}, or a system-wide event, |
2 | 131 |
* such as user logoff or system shutdown. |
132 |
* |
|
133 |
* </ul> |
|
134 |
* |
|
135 |
* <p> A <i>shutdown hook</i> is simply an initialized but unstarted |
|
136 |
* thread. When the virtual machine begins its shutdown sequence it will |
|
137 |
* start all registered shutdown hooks in some unspecified order and let |
|
138 |
* them run concurrently. When all the hooks have finished it will then |
|
48942
a6c4b85163c1
8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents:
48922
diff
changeset
|
139 |
* halt. Note that daemon threads will continue to run during the shutdown |
a6c4b85163c1
8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents:
48922
diff
changeset
|
140 |
* sequence, as will non-daemon threads if shutdown was initiated by |
a6c4b85163c1
8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents:
48922
diff
changeset
|
141 |
* invoking the {@link #exit exit} method. |
2 | 142 |
* |
143 |
* <p> Once the shutdown sequence has begun it can be stopped only by |
|
30042 | 144 |
* invoking the {@link #halt halt} method, which forcibly |
2 | 145 |
* terminates the virtual machine. |
146 |
* |
|
147 |
* <p> Once the shutdown sequence has begun it is impossible to register a |
|
148 |
* new shutdown hook or de-register a previously-registered hook. |
|
149 |
* Attempting either of these operations will cause an |
|
30042 | 150 |
* {@link IllegalStateException} to be thrown. |
2 | 151 |
* |
152 |
* <p> Shutdown hooks run at a delicate time in the life cycle of a virtual |
|
153 |
* machine and should therefore be coded defensively. They should, in |
|
154 |
* particular, be written to be thread-safe and to avoid deadlocks insofar |
|
155 |
* as possible. They should also not rely blindly upon services that may |
|
156 |
* have registered their own shutdown hooks and therefore may themselves in |
|
157 |
* the process of shutting down. Attempts to use other thread-based |
|
158 |
* services such as the AWT event-dispatch thread, for example, may lead to |
|
159 |
* deadlocks. |
|
160 |
* |
|
161 |
* <p> Shutdown hooks should also finish their work quickly. When a |
|
30042 | 162 |
* program invokes {@link #exit exit} the expectation is |
2 | 163 |
* that the virtual machine will promptly shut down and exit. When the |
164 |
* virtual machine is terminated due to user logoff or system shutdown the |
|
165 |
* underlying operating system may only allow a fixed amount of time in |
|
166 |
* which to shut down and exit. It is therefore inadvisable to attempt any |
|
167 |
* user interaction or to perform a long-running computation in a shutdown |
|
168 |
* hook. |
|
169 |
* |
|
170 |
* <p> Uncaught exceptions are handled in shutdown hooks just as in any |
|
30042 | 171 |
* other thread, by invoking the |
172 |
* {@link ThreadGroup#uncaughtException uncaughtException} method of the |
|
173 |
* thread's {@link ThreadGroup} object. The default implementation of this |
|
174 |
* method prints the exception's stack trace to {@link System#err} and |
|
2 | 175 |
* terminates the thread; it does not cause the virtual machine to exit or |
176 |
* halt. |
|
177 |
* |
|
178 |
* <p> In rare circumstances the virtual machine may <i>abort</i>, that is, |
|
179 |
* stop running without shutting down cleanly. This occurs when the |
|
180 |
* virtual machine is terminated externally, for example with the |
|
30042 | 181 |
* {@code SIGKILL} signal on Unix or the {@code TerminateProcess} call on |
2 | 182 |
* Microsoft Windows. The virtual machine may also abort if a native |
183 |
* method goes awry by, for example, corrupting internal data structures or |
|
184 |
* attempting to access nonexistent memory. If the virtual machine aborts |
|
185 |
* then no guarantee can be made about whether or not any shutdown hooks |
|
24367
705490680527
8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents:
18776
diff
changeset
|
186 |
* will be run. |
2 | 187 |
* |
188 |
* @param hook |
|
30042 | 189 |
* An initialized but unstarted {@link Thread} object |
2 | 190 |
* |
191 |
* @throws IllegalArgumentException |
|
192 |
* If the specified hook has already been registered, |
|
193 |
* or if it can be determined that the hook is already running or |
|
194 |
* has already been run |
|
195 |
* |
|
196 |
* @throws IllegalStateException |
|
197 |
* If the virtual machine is already in the process |
|
198 |
* of shutting down |
|
199 |
* |
|
200 |
* @throws SecurityException |
|
201 |
* If a security manager is present and it denies |
|
30042 | 202 |
* {@link RuntimePermission}("shutdownHooks") |
2 | 203 |
* |
204 |
* @see #removeShutdownHook |
|
205 |
* @see #halt(int) |
|
206 |
* @see #exit(int) |
|
207 |
* @since 1.3 |
|
208 |
*/ |
|
209 |
public void addShutdownHook(Thread hook) { |
|
210 |
SecurityManager sm = System.getSecurityManager(); |
|
211 |
if (sm != null) { |
|
212 |
sm.checkPermission(new RuntimePermission("shutdownHooks")); |
|
213 |
} |
|
214 |
ApplicationShutdownHooks.add(hook); |
|
215 |
} |
|
216 |
||
217 |
/** |
|
30042 | 218 |
* De-registers a previously-registered virtual-machine shutdown hook. |
2 | 219 |
* |
220 |
* @param hook the hook to remove |
|
30042 | 221 |
* @return {@code true} if the specified hook had previously been |
222 |
* registered and was successfully de-registered, {@code false} |
|
2 | 223 |
* otherwise. |
224 |
* |
|
225 |
* @throws IllegalStateException |
|
226 |
* If the virtual machine is already in the process of shutting |
|
227 |
* down |
|
228 |
* |
|
229 |
* @throws SecurityException |
|
230 |
* If a security manager is present and it denies |
|
30042 | 231 |
* {@link RuntimePermission}("shutdownHooks") |
2 | 232 |
* |
233 |
* @see #addShutdownHook |
|
234 |
* @see #exit(int) |
|
235 |
* @since 1.3 |
|
236 |
*/ |
|
237 |
public boolean removeShutdownHook(Thread hook) { |
|
238 |
SecurityManager sm = System.getSecurityManager(); |
|
239 |
if (sm != null) { |
|
240 |
sm.checkPermission(new RuntimePermission("shutdownHooks")); |
|
241 |
} |
|
242 |
return ApplicationShutdownHooks.remove(hook); |
|
243 |
} |
|
244 |
||
245 |
/** |
|
246 |
* Forcibly terminates the currently running Java virtual machine. This |
|
247 |
* method never returns normally. |
|
248 |
* |
|
249 |
* <p> This method should be used with extreme caution. Unlike the |
|
30042 | 250 |
* {@link #exit exit} method, this method does not cause shutdown |
48942
a6c4b85163c1
8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents:
48922
diff
changeset
|
251 |
* hooks to be started. If the shutdown sequence has already been |
a6c4b85163c1
8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents:
48922
diff
changeset
|
252 |
* initiated then this method does not wait for any running |
a6c4b85163c1
8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents:
48922
diff
changeset
|
253 |
* shutdown hooks to finish their work. |
2 | 254 |
* |
255 |
* @param status |
|
30042 | 256 |
* Termination status. By convention, a nonzero status code |
257 |
* indicates abnormal termination. If the {@link Runtime#exit exit} |
|
258 |
* (equivalently, {@link System#exit(int) System.exit}) method |
|
259 |
* has already been invoked then this status code |
|
260 |
* will override the status code passed to that method. |
|
2 | 261 |
* |
262 |
* @throws SecurityException |
|
30042 | 263 |
* If a security manager is present and its |
264 |
* {@link SecurityManager#checkExit checkExit} method |
|
265 |
* does not permit an exit with the specified status |
|
2 | 266 |
* |
267 |
* @see #exit |
|
268 |
* @see #addShutdownHook |
|
269 |
* @see #removeShutdownHook |
|
270 |
* @since 1.3 |
|
271 |
*/ |
|
272 |
public void halt(int status) { |
|
273 |
SecurityManager sm = System.getSecurityManager(); |
|
274 |
if (sm != null) { |
|
275 |
sm.checkExit(status); |
|
276 |
} |
|
49176 | 277 |
Shutdown.beforeHalt(); |
2 | 278 |
Shutdown.halt(status); |
279 |
} |
|
280 |
||
281 |
/** |
|
282 |
* Executes the specified string command in a separate process. |
|
283 |
* |
|
284 |
* <p>This is a convenience method. An invocation of the form |
|
30042 | 285 |
* {@code exec(command)} |
2 | 286 |
* behaves in exactly the same way as the invocation |
30042 | 287 |
* {@link #exec(String, String[], File) exec}{@code (command, null, null)}. |
2 | 288 |
* |
289 |
* @param command a specified system command. |
|
290 |
* |
|
291 |
* @return A new {@link Process} object for managing the subprocess |
|
292 |
* |
|
293 |
* @throws SecurityException |
|
294 |
* If a security manager exists and its |
|
295 |
* {@link SecurityManager#checkExec checkExec} |
|
296 |
* method doesn't allow creation of the subprocess |
|
297 |
* |
|
298 |
* @throws IOException |
|
299 |
* If an I/O error occurs |
|
300 |
* |
|
301 |
* @throws NullPointerException |
|
30042 | 302 |
* If {@code command} is {@code null} |
2 | 303 |
* |
304 |
* @throws IllegalArgumentException |
|
30042 | 305 |
* If {@code command} is empty |
2 | 306 |
* |
307 |
* @see #exec(String[], String[], File) |
|
308 |
* @see ProcessBuilder |
|
309 |
*/ |
|
310 |
public Process exec(String command) throws IOException { |
|
311 |
return exec(command, null, null); |
|
312 |
} |
|
313 |
||
314 |
/** |
|
315 |
* Executes the specified string command in a separate process with the |
|
316 |
* specified environment. |
|
317 |
* |
|
318 |
* <p>This is a convenience method. An invocation of the form |
|
30042 | 319 |
* {@code exec(command, envp)} |
2 | 320 |
* behaves in exactly the same way as the invocation |
30042 | 321 |
* {@link #exec(String, String[], File) exec}{@code (command, envp, null)}. |
2 | 322 |
* |
323 |
* @param command a specified system command. |
|
324 |
* |
|
325 |
* @param envp array of strings, each element of which |
|
326 |
* has environment variable settings in the format |
|
327 |
* <i>name</i>=<i>value</i>, or |
|
30042 | 328 |
* {@code null} if the subprocess should inherit |
2 | 329 |
* the environment of the current process. |
330 |
* |
|
331 |
* @return A new {@link Process} object for managing the subprocess |
|
332 |
* |
|
333 |
* @throws SecurityException |
|
334 |
* If a security manager exists and its |
|
335 |
* {@link SecurityManager#checkExec checkExec} |
|
336 |
* method doesn't allow creation of the subprocess |
|
337 |
* |
|
338 |
* @throws IOException |
|
339 |
* If an I/O error occurs |
|
340 |
* |
|
341 |
* @throws NullPointerException |
|
30042 | 342 |
* If {@code command} is {@code null}, |
343 |
* or one of the elements of {@code envp} is {@code null} |
|
2 | 344 |
* |
345 |
* @throws IllegalArgumentException |
|
30042 | 346 |
* If {@code command} is empty |
2 | 347 |
* |
348 |
* @see #exec(String[], String[], File) |
|
349 |
* @see ProcessBuilder |
|
350 |
*/ |
|
351 |
public Process exec(String command, String[] envp) throws IOException { |
|
352 |
return exec(command, envp, null); |
|
353 |
} |
|
354 |
||
355 |
/** |
|
356 |
* Executes the specified string command in a separate process with the |
|
357 |
* specified environment and working directory. |
|
358 |
* |
|
359 |
* <p>This is a convenience method. An invocation of the form |
|
30042 | 360 |
* {@code exec(command, envp, dir)} |
2 | 361 |
* behaves in exactly the same way as the invocation |
30042 | 362 |
* {@link #exec(String[], String[], File) exec}{@code (cmdarray, envp, dir)}, |
363 |
* where {@code cmdarray} is an array of all the tokens in |
|
364 |
* {@code command}. |
|
2 | 365 |
* |
30042 | 366 |
* <p>More precisely, the {@code command} string is broken |
2 | 367 |
* into tokens using a {@link StringTokenizer} created by the call |
30042 | 368 |
* {@code new {@link StringTokenizer}(command)} with no |
2 | 369 |
* further modification of the character categories. The tokens |
370 |
* produced by the tokenizer are then placed in the new string |
|
30042 | 371 |
* array {@code cmdarray}, in the same order. |
2 | 372 |
* |
373 |
* @param command a specified system command. |
|
374 |
* |
|
375 |
* @param envp array of strings, each element of which |
|
376 |
* has environment variable settings in the format |
|
377 |
* <i>name</i>=<i>value</i>, or |
|
30042 | 378 |
* {@code null} if the subprocess should inherit |
2 | 379 |
* the environment of the current process. |
380 |
* |
|
381 |
* @param dir the working directory of the subprocess, or |
|
30042 | 382 |
* {@code null} if the subprocess should inherit |
2 | 383 |
* the working directory of the current process. |
384 |
* |
|
385 |
* @return A new {@link Process} object for managing the subprocess |
|
386 |
* |
|
387 |
* @throws SecurityException |
|
388 |
* If a security manager exists and its |
|
389 |
* {@link SecurityManager#checkExec checkExec} |
|
390 |
* method doesn't allow creation of the subprocess |
|
391 |
* |
|
392 |
* @throws IOException |
|
393 |
* If an I/O error occurs |
|
394 |
* |
|
395 |
* @throws NullPointerException |
|
30042 | 396 |
* If {@code command} is {@code null}, |
397 |
* or one of the elements of {@code envp} is {@code null} |
|
2 | 398 |
* |
399 |
* @throws IllegalArgumentException |
|
30042 | 400 |
* If {@code command} is empty |
2 | 401 |
* |
402 |
* @see ProcessBuilder |
|
403 |
* @since 1.3 |
|
404 |
*/ |
|
405 |
public Process exec(String command, String[] envp, File dir) |
|
406 |
throws IOException { |
|
53018
8bf9268df0e2
8215281: Use String.isEmpty() when applicable in java.base
redestad
parents:
52427
diff
changeset
|
407 |
if (command.isEmpty()) |
2 | 408 |
throw new IllegalArgumentException("Empty command"); |
409 |
||
410 |
StringTokenizer st = new StringTokenizer(command); |
|
411 |
String[] cmdarray = new String[st.countTokens()]; |
|
412 |
for (int i = 0; st.hasMoreTokens(); i++) |
|
413 |
cmdarray[i] = st.nextToken(); |
|
414 |
return exec(cmdarray, envp, dir); |
|
415 |
} |
|
416 |
||
417 |
/** |
|
418 |
* Executes the specified command and arguments in a separate process. |
|
419 |
* |
|
420 |
* <p>This is a convenience method. An invocation of the form |
|
30042 | 421 |
* {@code exec(cmdarray)} |
2 | 422 |
* behaves in exactly the same way as the invocation |
30042 | 423 |
* {@link #exec(String[], String[], File) exec}{@code (cmdarray, null, null)}. |
2 | 424 |
* |
425 |
* @param cmdarray array containing the command to call and |
|
426 |
* its arguments. |
|
427 |
* |
|
428 |
* @return A new {@link Process} object for managing the subprocess |
|
429 |
* |
|
430 |
* @throws SecurityException |
|
431 |
* If a security manager exists and its |
|
432 |
* {@link SecurityManager#checkExec checkExec} |
|
433 |
* method doesn't allow creation of the subprocess |
|
434 |
* |
|
435 |
* @throws IOException |
|
436 |
* If an I/O error occurs |
|
437 |
* |
|
438 |
* @throws NullPointerException |
|
30042 | 439 |
* If {@code cmdarray} is {@code null}, |
440 |
* or one of the elements of {@code cmdarray} is {@code null} |
|
2 | 441 |
* |
442 |
* @throws IndexOutOfBoundsException |
|
30042 | 443 |
* If {@code cmdarray} is an empty array |
444 |
* (has length {@code 0}) |
|
2 | 445 |
* |
446 |
* @see ProcessBuilder |
|
447 |
*/ |
|
448 |
public Process exec(String cmdarray[]) throws IOException { |
|
449 |
return exec(cmdarray, null, null); |
|
450 |
} |
|
451 |
||
452 |
/** |
|
453 |
* Executes the specified command and arguments in a separate process |
|
454 |
* with the specified environment. |
|
455 |
* |
|
456 |
* <p>This is a convenience method. An invocation of the form |
|
30042 | 457 |
* {@code exec(cmdarray, envp)} |
2 | 458 |
* behaves in exactly the same way as the invocation |
30042 | 459 |
* {@link #exec(String[], String[], File) exec}{@code (cmdarray, envp, null)}. |
2 | 460 |
* |
461 |
* @param cmdarray array containing the command to call and |
|
462 |
* its arguments. |
|
463 |
* |
|
464 |
* @param envp array of strings, each element of which |
|
465 |
* has environment variable settings in the format |
|
466 |
* <i>name</i>=<i>value</i>, or |
|
30042 | 467 |
* {@code null} if the subprocess should inherit |
2 | 468 |
* the environment of the current process. |
469 |
* |
|
470 |
* @return A new {@link Process} object for managing the subprocess |
|
471 |
* |
|
472 |
* @throws SecurityException |
|
473 |
* If a security manager exists and its |
|
474 |
* {@link SecurityManager#checkExec checkExec} |
|
475 |
* method doesn't allow creation of the subprocess |
|
476 |
* |
|
477 |
* @throws IOException |
|
478 |
* If an I/O error occurs |
|
479 |
* |
|
480 |
* @throws NullPointerException |
|
30042 | 481 |
* If {@code cmdarray} is {@code null}, |
482 |
* or one of the elements of {@code cmdarray} is {@code null}, |
|
483 |
* or one of the elements of {@code envp} is {@code null} |
|
2 | 484 |
* |
485 |
* @throws IndexOutOfBoundsException |
|
30042 | 486 |
* If {@code cmdarray} is an empty array |
487 |
* (has length {@code 0}) |
|
2 | 488 |
* |
489 |
* @see ProcessBuilder |
|
490 |
*/ |
|
491 |
public Process exec(String[] cmdarray, String[] envp) throws IOException { |
|
492 |
return exec(cmdarray, envp, null); |
|
493 |
} |
|
494 |
||
495 |
||
496 |
/** |
|
497 |
* Executes the specified command and arguments in a separate process with |
|
498 |
* the specified environment and working directory. |
|
499 |
* |
|
30042 | 500 |
* <p>Given an array of strings {@code cmdarray}, representing the |
501 |
* tokens of a command line, and an array of strings {@code envp}, |
|
2 | 502 |
* representing "environment" variable settings, this method creates |
503 |
* a new process in which to execute the specified command. |
|
504 |
* |
|
30042 | 505 |
* <p>This method checks that {@code cmdarray} is a valid operating |
2 | 506 |
* system command. Which commands are valid is system-dependent, |
507 |
* but at the very least the command must be a non-empty list of |
|
508 |
* non-null strings. |
|
509 |
* |
|
30042 | 510 |
* <p>If {@code envp} is {@code null}, the subprocess inherits the |
2 | 511 |
* environment settings of the current process. |
512 |
* |
|
9500
268f823d9e1c
7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents:
5506
diff
changeset
|
513 |
* <p>A minimal set of system dependent environment variables may |
268f823d9e1c
7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents:
5506
diff
changeset
|
514 |
* be required to start a process on some operating systems. |
268f823d9e1c
7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents:
5506
diff
changeset
|
515 |
* As a result, the subprocess may inherit additional environment variable |
268f823d9e1c
7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents:
5506
diff
changeset
|
516 |
* settings beyond those in the specified environment. |
268f823d9e1c
7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents:
5506
diff
changeset
|
517 |
* |
2 | 518 |
* <p>{@link ProcessBuilder#start()} is now the preferred way to |
519 |
* start a process with a modified environment. |
|
520 |
* |
|
30042 | 521 |
* <p>The working directory of the new subprocess is specified by {@code dir}. |
522 |
* If {@code dir} is {@code null}, the subprocess inherits the |
|
2 | 523 |
* current working directory of the current process. |
524 |
* |
|
525 |
* <p>If a security manager exists, its |
|
526 |
* {@link SecurityManager#checkExec checkExec} |
|
527 |
* method is invoked with the first component of the array |
|
30042 | 528 |
* {@code cmdarray} as its argument. This may result in a |
2 | 529 |
* {@link SecurityException} being thrown. |
530 |
* |
|
531 |
* <p>Starting an operating system process is highly system-dependent. |
|
532 |
* Among the many things that can go wrong are: |
|
533 |
* <ul> |
|
534 |
* <li>The operating system program file was not found. |
|
535 |
* <li>Access to the program file was denied. |
|
536 |
* <li>The working directory does not exist. |
|
537 |
* </ul> |
|
538 |
* |
|
539 |
* <p>In such cases an exception will be thrown. The exact nature |
|
540 |
* of the exception is system-dependent, but it will always be a |
|
541 |
* subclass of {@link IOException}. |
|
542 |
* |
|
28872
82a09f5a7ed6
8072034: (process) ProcessBuilder.start and Runtime.exec UnsupportedOperationException editorial cleanup
rriggs
parents:
28750
diff
changeset
|
543 |
* <p>If the operating system does not support the creation of |
82a09f5a7ed6
8072034: (process) ProcessBuilder.start and Runtime.exec UnsupportedOperationException editorial cleanup
rriggs
parents:
28750
diff
changeset
|
544 |
* processes, an {@link UnsupportedOperationException} will be thrown. |
82a09f5a7ed6
8072034: (process) ProcessBuilder.start and Runtime.exec UnsupportedOperationException editorial cleanup
rriggs
parents:
28750
diff
changeset
|
545 |
* |
2 | 546 |
* |
547 |
* @param cmdarray array containing the command to call and |
|
548 |
* its arguments. |
|
549 |
* |
|
550 |
* @param envp array of strings, each element of which |
|
551 |
* has environment variable settings in the format |
|
552 |
* <i>name</i>=<i>value</i>, or |
|
30042 | 553 |
* {@code null} if the subprocess should inherit |
2 | 554 |
* the environment of the current process. |
555 |
* |
|
556 |
* @param dir the working directory of the subprocess, or |
|
30042 | 557 |
* {@code null} if the subprocess should inherit |
2 | 558 |
* the working directory of the current process. |
559 |
* |
|
560 |
* @return A new {@link Process} object for managing the subprocess |
|
561 |
* |
|
562 |
* @throws SecurityException |
|
563 |
* If a security manager exists and its |
|
564 |
* {@link SecurityManager#checkExec checkExec} |
|
565 |
* method doesn't allow creation of the subprocess |
|
566 |
* |
|
28750
a1dae439cdab
8055330: (process spec) ProcessBuilder.start and Runtime.exec should throw UnsupportedOperationException on platforms that don't support
rriggs
parents:
27184
diff
changeset
|
567 |
* @throws UnsupportedOperationException |
a1dae439cdab
8055330: (process spec) ProcessBuilder.start and Runtime.exec should throw UnsupportedOperationException on platforms that don't support
rriggs
parents:
27184
diff
changeset
|
568 |
* If the operating system does not support the creation of processes. |
a1dae439cdab
8055330: (process spec) ProcessBuilder.start and Runtime.exec should throw UnsupportedOperationException on platforms that don't support
rriggs
parents:
27184
diff
changeset
|
569 |
* |
2 | 570 |
* @throws IOException |
571 |
* If an I/O error occurs |
|
572 |
* |
|
573 |
* @throws NullPointerException |
|
30042 | 574 |
* If {@code cmdarray} is {@code null}, |
575 |
* or one of the elements of {@code cmdarray} is {@code null}, |
|
576 |
* or one of the elements of {@code envp} is {@code null} |
|
2 | 577 |
* |
578 |
* @throws IndexOutOfBoundsException |
|
30042 | 579 |
* If {@code cmdarray} is an empty array |
580 |
* (has length {@code 0}) |
|
2 | 581 |
* |
582 |
* @see ProcessBuilder |
|
583 |
* @since 1.3 |
|
584 |
*/ |
|
585 |
public Process exec(String[] cmdarray, String[] envp, File dir) |
|
586 |
throws IOException { |
|
587 |
return new ProcessBuilder(cmdarray) |
|
588 |
.environment(envp) |
|
589 |
.directory(dir) |
|
590 |
.start(); |
|
591 |
} |
|
592 |
||
593 |
/** |
|
594 |
* Returns the number of processors available to the Java virtual machine. |
|
595 |
* |
|
596 |
* <p> This value may change during a particular invocation of the virtual |
|
597 |
* machine. Applications that are sensitive to the number of available |
|
598 |
* processors should therefore occasionally poll this property and adjust |
|
599 |
* their resource usage appropriately. </p> |
|
600 |
* |
|
601 |
* @return the maximum number of processors available to the virtual |
|
602 |
* machine; never smaller than one |
|
603 |
* @since 1.4 |
|
604 |
*/ |
|
605 |
public native int availableProcessors(); |
|
606 |
||
607 |
/** |
|
608 |
* Returns the amount of free memory in the Java Virtual Machine. |
|
609 |
* Calling the |
|
30042 | 610 |
* {@code gc} method may result in increasing the value returned |
611 |
* by {@code freeMemory.} |
|
2 | 612 |
* |
613 |
* @return an approximation to the total amount of memory currently |
|
614 |
* available for future allocated objects, measured in bytes. |
|
615 |
*/ |
|
616 |
public native long freeMemory(); |
|
617 |
||
618 |
/** |
|
619 |
* Returns the total amount of memory in the Java virtual machine. |
|
620 |
* The value returned by this method may vary over time, depending on |
|
621 |
* the host environment. |
|
622 |
* <p> |
|
623 |
* Note that the amount of memory required to hold an object of any |
|
624 |
* given type may be implementation-dependent. |
|
625 |
* |
|
626 |
* @return the total amount of memory currently available for current |
|
627 |
* and future objects, measured in bytes. |
|
628 |
*/ |
|
629 |
public native long totalMemory(); |
|
630 |
||
631 |
/** |
|
30042 | 632 |
* Returns the maximum amount of memory that the Java virtual machine |
633 |
* will attempt to use. If there is no inherent limit then the value |
|
634 |
* {@link java.lang.Long#MAX_VALUE} will be returned. |
|
2 | 635 |
* |
636 |
* @return the maximum amount of memory that the virtual machine will |
|
637 |
* attempt to use, measured in bytes |
|
638 |
* @since 1.4 |
|
639 |
*/ |
|
640 |
public native long maxMemory(); |
|
641 |
||
642 |
/** |
|
55231
02db50f278f9
8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents:
53018
diff
changeset
|
643 |
* Runs the garbage collector in the Java Virtual Machine. |
02db50f278f9
8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents:
53018
diff
changeset
|
644 |
* <p> |
02db50f278f9
8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents:
53018
diff
changeset
|
645 |
* Calling this method suggests that the Java Virtual Machine |
02db50f278f9
8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents:
53018
diff
changeset
|
646 |
* expend effort toward recycling unused objects in order to |
02db50f278f9
8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents:
53018
diff
changeset
|
647 |
* make the memory they currently occupy available for reuse |
02db50f278f9
8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents:
53018
diff
changeset
|
648 |
* by the Java Virtual Machine. |
02db50f278f9
8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents:
53018
diff
changeset
|
649 |
* When control returns from the method call, the Java Virtual Machine |
02db50f278f9
8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents:
53018
diff
changeset
|
650 |
* has made a best effort to reclaim space from all unused objects. |
02db50f278f9
8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents:
53018
diff
changeset
|
651 |
* There is no guarantee that this effort will recycle any particular |
02db50f278f9
8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents:
53018
diff
changeset
|
652 |
* number of unused objects, reclaim any particular amount of space, or |
02db50f278f9
8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents:
53018
diff
changeset
|
653 |
* complete at any particular time, if at all, before the method returns or ever. |
2 | 654 |
* <p> |
30042 | 655 |
* The name {@code gc} stands for "garbage |
55231
02db50f278f9
8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents:
53018
diff
changeset
|
656 |
* collector". The Java Virtual Machine performs this recycling |
2 | 657 |
* process automatically as needed, in a separate thread, even if the |
30042 | 658 |
* {@code gc} method is not invoked explicitly. |
2 | 659 |
* <p> |
660 |
* The method {@link System#gc()} is the conventional and convenient |
|
661 |
* means of invoking this method. |
|
662 |
*/ |
|
663 |
public native void gc(); |
|
664 |
||
665 |
/** |
|
666 |
* Runs the finalization methods of any objects pending finalization. |
|
667 |
* Calling this method suggests that the Java virtual machine expend |
|
30042 | 668 |
* effort toward running the {@code finalize} methods of objects |
669 |
* that have been found to be discarded but whose {@code finalize} |
|
2 | 670 |
* methods have not yet been run. When control returns from the |
671 |
* method call, the virtual machine has made a best effort to |
|
672 |
* complete all outstanding finalizations. |
|
673 |
* <p> |
|
674 |
* The virtual machine performs the finalization process |
|
675 |
* automatically as needed, in a separate thread, if the |
|
30042 | 676 |
* {@code runFinalization} method is not invoked explicitly. |
2 | 677 |
* <p> |
678 |
* The method {@link System#runFinalization()} is the conventional |
|
679 |
* and convenient means of invoking this method. |
|
680 |
* |
|
681 |
* @see java.lang.Object#finalize() |
|
682 |
*/ |
|
683 |
public void runFinalization() { |
|
48922
906025796009
8198441: Replace native Runtime::runFinalization0 method with shared secrets
mchung
parents:
48545
diff
changeset
|
684 |
SharedSecrets.getJavaLangRefAccess().runFinalization(); |
2 | 685 |
} |
686 |
||
687 |
/** |
|
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
688 |
* Loads the native library specified by the filename argument. The filename |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
689 |
* argument must be an absolute path name. |
2 | 690 |
* (for example |
30042 | 691 |
* {@code Runtime.getRuntime().load("/home/avh/lib/libX11.so");}). |
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
692 |
* |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
693 |
* If the filename argument, when stripped of any platform-specific library |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
694 |
* prefix, path, and file extension, indicates a library whose name is, |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
695 |
* for example, L, and a native library called L is statically linked |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
696 |
* with the VM, then the JNI_OnLoad_L function exported by the library |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
697 |
* is invoked rather than attempting to load a dynamic library. |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
698 |
* A filename matching the argument does not have to exist in the file |
47707
67aa34b019e1
8164512: Replace ClassLoader use of finalizer with phantom reference to unload native library
mchung
parents:
47216
diff
changeset
|
699 |
* system. |
67aa34b019e1
8164512: Replace ClassLoader use of finalizer with phantom reference to unload native library
mchung
parents:
47216
diff
changeset
|
700 |
* See the <a href="{@docRoot}/../specs/jni/index.html"> JNI Specification</a> |
67aa34b019e1
8164512: Replace ClassLoader use of finalizer with phantom reference to unload native library
mchung
parents:
47216
diff
changeset
|
701 |
* for more details. |
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
702 |
* |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
703 |
* Otherwise, the filename argument is mapped to a native library image in |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
704 |
* an implementation-dependent manner. |
2 | 705 |
* <p> |
30042 | 706 |
* First, if there is a security manager, its {@code checkLink} |
707 |
* method is called with the {@code filename} as its argument. |
|
2 | 708 |
* This may result in a security exception. |
709 |
* <p> |
|
710 |
* This is similar to the method {@link #loadLibrary(String)}, but it |
|
711 |
* accepts a general file name as an argument rather than just a library |
|
712 |
* name, allowing any file of native code to be loaded. |
|
713 |
* <p> |
|
714 |
* The method {@link System#load(String)} is the conventional and |
|
715 |
* convenient means of invoking this method. |
|
716 |
* |
|
717 |
* @param filename the file to load. |
|
49203
3a225d9cabe1
8199420: Update javadoc tags in java.lang.System and related
rriggs
parents:
49186
diff
changeset
|
718 |
* @throws SecurityException if a security manager exists and its |
30042 | 719 |
* {@code checkLink} method doesn't allow |
2 | 720 |
* loading of the specified dynamic library |
49203
3a225d9cabe1
8199420: Update javadoc tags in java.lang.System and related
rriggs
parents:
49186
diff
changeset
|
721 |
* @throws UnsatisfiedLinkError if either the filename is not an |
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
722 |
* absolute path name, the native library is not statically |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
723 |
* linked with the VM, or the library cannot be mapped to |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
724 |
* a native library image by the host system. |
49203
3a225d9cabe1
8199420: Update javadoc tags in java.lang.System and related
rriggs
parents:
49186
diff
changeset
|
725 |
* @throws NullPointerException if {@code filename} is |
30042 | 726 |
* {@code null} |
2 | 727 |
* @see java.lang.Runtime#getRuntime() |
728 |
* @see java.lang.SecurityException |
|
729 |
* @see java.lang.SecurityManager#checkLink(java.lang.String) |
|
730 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
731 |
@CallerSensitive |
2 | 732 |
public void load(String filename) { |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
733 |
load0(Reflection.getCallerClass(), filename); |
2 | 734 |
} |
735 |
||
58574
dcc760954243
8231584: Deadlock with ClassLoader.findLibrary and System.loadLibrary call
akozlov
parents:
55319
diff
changeset
|
736 |
void load0(Class<?> fromClass, String filename) { |
2 | 737 |
SecurityManager security = System.getSecurityManager(); |
738 |
if (security != null) { |
|
739 |
security.checkLink(filename); |
|
740 |
} |
|
741 |
if (!(new File(filename).isAbsolute())) { |
|
742 |
throw new UnsatisfiedLinkError( |
|
743 |
"Expecting an absolute path of the library: " + filename); |
|
744 |
} |
|
745 |
ClassLoader.loadLibrary(fromClass, filename, true); |
|
746 |
} |
|
747 |
||
748 |
/** |
|
30042 | 749 |
* Loads the native library specified by the {@code libname} |
750 |
* argument. The {@code libname} argument must not contain any platform |
|
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
751 |
* specific prefix, file extension or path. If a native library |
30042 | 752 |
* called {@code libname} is statically linked with the VM, then the |
753 |
* JNI_OnLoad_{@code libname} function exported by the library is invoked. |
|
47707
67aa34b019e1
8164512: Replace ClassLoader use of finalizer with phantom reference to unload native library
mchung
parents:
47216
diff
changeset
|
754 |
* See the <a href="{@docRoot}/../specs/jni/index.html"> JNI Specification</a> |
67aa34b019e1
8164512: Replace ClassLoader use of finalizer with phantom reference to unload native library
mchung
parents:
47216
diff
changeset
|
755 |
* for more details. |
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
756 |
* |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
757 |
* Otherwise, the libname argument is loaded from a system library |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
758 |
* location and mapped to a native library image in an implementation- |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
759 |
* dependent manner. |
2 | 760 |
* <p> |
30042 | 761 |
* First, if there is a security manager, its {@code checkLink} |
762 |
* method is called with the {@code libname} as its argument. |
|
2 | 763 |
* This may result in a security exception. |
764 |
* <p> |
|
765 |
* The method {@link System#loadLibrary(String)} is the conventional |
|
766 |
* and convenient means of invoking this method. If native |
|
767 |
* methods are to be used in the implementation of a class, a standard |
|
768 |
* strategy is to put the native code in a library file (call it |
|
30042 | 769 |
* {@code LibFile}) and then to put a static initializer: |
2 | 770 |
* <blockquote><pre> |
771 |
* static { System.loadLibrary("LibFile"); } |
|
772 |
* </pre></blockquote> |
|
773 |
* within the class declaration. When the class is loaded and |
|
774 |
* initialized, the necessary native code implementation for the native |
|
775 |
* methods will then be loaded as well. |
|
776 |
* <p> |
|
777 |
* If this method is called more than once with the same library |
|
778 |
* name, the second and subsequent calls are ignored. |
|
779 |
* |
|
780 |
* @param libname the name of the library. |
|
49203
3a225d9cabe1
8199420: Update javadoc tags in java.lang.System and related
rriggs
parents:
49186
diff
changeset
|
781 |
* @throws SecurityException if a security manager exists and its |
30042 | 782 |
* {@code checkLink} method doesn't allow |
2 | 783 |
* loading of the specified dynamic library |
49203
3a225d9cabe1
8199420: Update javadoc tags in java.lang.System and related
rriggs
parents:
49186
diff
changeset
|
784 |
* @throws UnsatisfiedLinkError if either the libname argument |
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
785 |
* contains a file path, the native library is not statically |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
786 |
* linked with the VM, or the library cannot be mapped to a |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
787 |
* native library image by the host system. |
49203
3a225d9cabe1
8199420: Update javadoc tags in java.lang.System and related
rriggs
parents:
49186
diff
changeset
|
788 |
* @throws NullPointerException if {@code libname} is |
30042 | 789 |
* {@code null} |
2 | 790 |
* @see java.lang.SecurityException |
791 |
* @see java.lang.SecurityManager#checkLink(java.lang.String) |
|
792 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
793 |
@CallerSensitive |
2 | 794 |
public void loadLibrary(String libname) { |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
795 |
loadLibrary0(Reflection.getCallerClass(), libname); |
2 | 796 |
} |
797 |
||
58574
dcc760954243
8231584: Deadlock with ClassLoader.findLibrary and System.loadLibrary call
akozlov
parents:
55319
diff
changeset
|
798 |
void loadLibrary0(Class<?> fromClass, String libname) { |
2 | 799 |
SecurityManager security = System.getSecurityManager(); |
800 |
if (security != null) { |
|
801 |
security.checkLink(libname); |
|
802 |
} |
|
803 |
if (libname.indexOf((int)File.separatorChar) != -1) { |
|
804 |
throw new UnsatisfiedLinkError( |
|
58574
dcc760954243
8231584: Deadlock with ClassLoader.findLibrary and System.loadLibrary call
akozlov
parents:
55319
diff
changeset
|
805 |
"Directory separator should not appear in library name: " + libname); |
2 | 806 |
} |
807 |
ClassLoader.loadLibrary(fromClass, libname, false); |
|
808 |
} |
|
809 |
||
810 |
/** |
|
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
811 |
* Returns the version of the Java Runtime Environment as a {@link Version}. |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
812 |
* |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
813 |
* @return the {@link Version} of the Java Runtime Environment |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
814 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
815 |
* @since 9 |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
816 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
817 |
public static Version version() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
818 |
if (version == null) { |
39302
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
819 |
version = new Version(VersionProps.versionNumbers(), |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
820 |
VersionProps.pre(), VersionProps.build(), |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
821 |
VersionProps.optional()); |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
822 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
823 |
return version; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
824 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
825 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
826 |
/** |
39766
745f165bedee
8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents:
39302
diff
changeset
|
827 |
* A representation of a version string for an implementation of the |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
828 |
* Java SE Platform. A version string consists of a version number |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
829 |
* optionally followed by pre-release and build information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
830 |
* |
44844
b2b4d98404ba
8179364: update "<a name=" in java.base module to use id attribute
jjg
parents:
44785
diff
changeset
|
831 |
* <h2><a id="verNum">Version numbers</a></h2> |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
832 |
* |
48327 | 833 |
* <p> A <em>version number</em>, {@code $VNUM}, is a non-empty sequence of |
834 |
* elements separated by period characters (U+002E). An element is either |
|
835 |
* zero, or an unsigned integer numeral without leading zeros. The final |
|
836 |
* element in a version number must not be zero. When an element is |
|
837 |
* incremented, all subsequent elements are removed. The format is: </p> |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
838 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
839 |
* <blockquote><pre> |
48327 | 840 |
* [1-9][0-9]*((\.0)*\.[1-9][0-9]*)* |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
841 |
* </pre></blockquote> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
842 |
* |
48327 | 843 |
* <p> The sequence may be of arbitrary length but the first four elements |
844 |
* are assigned specific meanings, as follows:</p> |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
845 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
846 |
* <blockquote><pre> |
48327 | 847 |
* $FEATURE.$INTERIM.$UPDATE.$PATCH |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
848 |
* </pre></blockquote> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
849 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
850 |
* <ul> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
851 |
* |
48327 | 852 |
* <li><p> <a id="FEATURE">{@code $FEATURE}</a> — The |
853 |
* feature-release counter, incremented for every feature release |
|
854 |
* regardless of release content. Features may be added in a feature |
|
855 |
* release; they may also be removed, if advance notice was given at least |
|
856 |
* one feature release ahead of time. Incompatible changes may be made |
|
857 |
* when justified. </p></li> |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
858 |
* |
48327 | 859 |
* <li><p> <a id="INTERIM">{@code $INTERIM}</a> — The |
860 |
* interim-release counter, incremented for non-feature releases that |
|
861 |
* contain compatible bug fixes and enhancements but no incompatible |
|
862 |
* changes, no feature removals, and no changes to standard APIs. |
|
863 |
* </p></li> |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
864 |
* |
48327 | 865 |
* <li><p> <a id="UPDATE">{@code $UPDATE}</a> — The update-release |
866 |
* counter, incremented for compatible update releases that fix security |
|
867 |
* issues, regressions, and bugs in newer features. </p></li> |
|
868 |
* |
|
869 |
* <li><p> <a id="PATCH">{@code $PATCH}</a> — The emergency |
|
870 |
* patch-release counter, incremented only when it's necessary to produce |
|
871 |
* an emergency release to fix a critical issue. </p></li> |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
872 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
873 |
* </ul> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
874 |
* |
48327 | 875 |
* <p> The fifth and later elements of a version number are free for use by |
876 |
* platform implementors, to identify implementor-specific patch |
|
877 |
* releases. </p> |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
878 |
* |
48327 | 879 |
* <p> A version number never has trailing zero elements. If an element |
880 |
* and all those that follow it logically have the value zero then all of |
|
881 |
* them are omitted. </p> |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
882 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
883 |
* <p> The sequence of numerals in a version number is compared to another |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
884 |
* such sequence in numerical, pointwise fashion; <em>e.g.</em>, {@code |
48327 | 885 |
* 10.0.4} is less than {@code 10.1.2}. If one sequence is shorter than |
886 |
* another then the missing elements of the shorter sequence are considered |
|
887 |
* to be less than the corresponding elements of the longer sequence; |
|
888 |
* <em>e.g.</em>, {@code 10.0.2} is less than {@code 10.0.2.1}. </p> |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
889 |
* |
44844
b2b4d98404ba
8179364: update "<a name=" in java.base module to use id attribute
jjg
parents:
44785
diff
changeset
|
890 |
* <h2><a id="verStr">Version strings</a></h2> |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
891 |
* |
48327 | 892 |
* <p> A <em>version string</em>, {@code $VSTR}, is a version number {@code |
893 |
* $VNUM}, as described above, optionally followed by pre-release and build |
|
894 |
* information, in one of the following formats: </p> |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
895 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
896 |
* <blockquote><pre> |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
897 |
* $VNUM(-$PRE)?\+$BUILD(-$OPT)? |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
898 |
* $VNUM-$PRE(-$OPT)? |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
899 |
* $VNUM(+-$OPT)? |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
900 |
* </pre></blockquote> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
901 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
902 |
* <p> where: </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
903 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
904 |
* <ul> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
905 |
* |
44844
b2b4d98404ba
8179364: update "<a name=" in java.base module to use id attribute
jjg
parents:
44785
diff
changeset
|
906 |
* <li><p> <a id="pre">{@code $PRE}</a>, matching {@code ([a-zA-Z0-9]+)} |
48327 | 907 |
* — A pre-release identifier. Typically {@code ea}, for a |
908 |
* potentially unstable early-access release under active development, or |
|
909 |
* {@code internal}, for an internal developer build. </p></li> |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
910 |
* |
44844
b2b4d98404ba
8179364: update "<a name=" in java.base module to use id attribute
jjg
parents:
44785
diff
changeset
|
911 |
* <li><p> <a id="build">{@code $BUILD}</a>, matching {@code |
48327 | 912 |
* (0|[1-9][0-9]*)} — The build number, incremented for each promoted |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
913 |
* build. {@code $BUILD} is reset to {@code 1} when any portion of {@code |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
914 |
* $VNUM} is incremented. </p></li> |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
915 |
* |
48327 | 916 |
* <li><p> <a id="opt">{@code $OPT}</a>, matching {@code ([-a-zA-Z0-9.]+)} |
917 |
* — Additional build information, if desired. In the case of an |
|
918 |
* {@code internal} build this will often contain the date and time of the |
|
919 |
* build. </p></li> |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
920 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
921 |
* </ul> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
922 |
* |
44265
ac63ae089927
8160956: Runtime.Version.compareTo/compareToIgnoreOpt problem
prappo
parents:
40793
diff
changeset
|
923 |
* <p> A version string {@code 10-ea} matches {@code $VNUM = "10"} and |
ac63ae089927
8160956: Runtime.Version.compareTo/compareToIgnoreOpt problem
prappo
parents:
40793
diff
changeset
|
924 |
* {@code $PRE = "ea"}. The version string {@code 10+-ea} matches |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
925 |
* {@code $VNUM = "10"} and {@code $OPT = "ea"}. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
926 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
927 |
* <p> When comparing two version strings, the value of {@code $OPT}, if |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
928 |
* present, may or may not be significant depending on the chosen |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
929 |
* comparison method. The comparison methods {@link #compareTo(Version) |
39766
745f165bedee
8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents:
39302
diff
changeset
|
930 |
* compareTo()} and {@link #compareToIgnoreOptional(Version) |
745f165bedee
8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents:
39302
diff
changeset
|
931 |
* compareToIgnoreOptional()} should be used consistently with the |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
932 |
* corresponding methods {@link #equals(Object) equals()} and {@link |
39766
745f165bedee
8161236: Runtime.Version.{compareTo, equals}IgnoreOpt should be renamed
iris
parents:
39302
diff
changeset
|
933 |
* #equalsIgnoreOptional(Object) equalsIgnoreOptional()}. </p> |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
934 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
935 |
* <p> A <em>short version string</em>, {@code $SVSTR}, often useful in |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
936 |
* less formal contexts, is a version number optionally followed by a |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
937 |
* pre-release identifier:</p> |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
938 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
939 |
* <blockquote><pre> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
940 |
* $VNUM(-$PRE)? |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
941 |
* </pre></blockquote> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
942 |
* |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
943 |
* <p>This is a <a href="./doc-files/ValueBased.html">value-based</a> |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
944 |
* class; use of identity-sensitive operations (including reference equality |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
945 |
* ({@code ==}), identity hash code, or synchronization) on instances of |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
946 |
* {@code Version} may have unpredictable results and should be avoided. |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
947 |
* </p> |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
948 |
* |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
949 |
* @since 9 |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
950 |
*/ |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
951 |
public static final class Version |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
952 |
implements Comparable<Version> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
953 |
{ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
954 |
private final List<Integer> version; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
955 |
private final Optional<String> pre; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
956 |
private final Optional<Integer> build; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
957 |
private final Optional<String> optional; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
958 |
|
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
959 |
/* |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
960 |
* List of version number components passed to this constructor MUST |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
961 |
* be at least unmodifiable (ideally immutable). In the case on an |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
962 |
* unmodifiable list, the caller MUST hand the list over to this |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
963 |
* constructor and never change the underlying list. |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
964 |
*/ |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
965 |
private Version(List<Integer> unmodifiableListOfVersions, |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
966 |
Optional<String> pre, |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
967 |
Optional<Integer> build, |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
968 |
Optional<String> optional) |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
969 |
{ |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
970 |
this.version = unmodifiableListOfVersions; |
39302
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
971 |
this.pre = pre; |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
972 |
this.build = build; |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
973 |
this.optional = optional; |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
974 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
975 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
976 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
977 |
* Parses the given string as a valid |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
978 |
* <a href="#verStr">version string</a> containing a |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
979 |
* <a href="#verNum">version number</a> followed by pre-release and |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
980 |
* build information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
981 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
982 |
* @param s |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
983 |
* A string to interpret as a version |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
984 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
985 |
* @throws IllegalArgumentException |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
986 |
* If the given string cannot be interpreted as a valid |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
987 |
* version |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
988 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
989 |
* @throws NullPointerException |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
990 |
* If the given string is {@code null} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
991 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
992 |
* @throws NumberFormatException |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
993 |
* If an element of the version number or the build number |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
994 |
* cannot be represented as an {@link Integer} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
995 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
996 |
* @return The Version of the given string |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
997 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
998 |
public static Version parse(String s) { |
39889
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
999 |
if (s == null) |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1000 |
throw new NullPointerException(); |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1001 |
|
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1002 |
// Shortcut to avoid initializing VersionPattern when creating |
48327 | 1003 |
// feature-version constants during startup |
39889
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1004 |
if (isSimpleNumber(s)) { |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1005 |
return new Version(List.of(Integer.parseInt(s)), |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1006 |
Optional.empty(), Optional.empty(), Optional.empty()); |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1007 |
} |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1008 |
Matcher m = VersionPattern.VSTR_PATTERN.matcher(s); |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1009 |
if (!m.matches()) |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1010 |
throw new IllegalArgumentException("Invalid version string: '" |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1011 |
+ s + "'"); |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1012 |
|
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1013 |
// $VNUM is a dot-separated list of integers of arbitrary length |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1014 |
String[] split = m.group(VersionPattern.VNUM_GROUP).split("\\."); |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1015 |
Integer[] version = new Integer[split.length]; |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1016 |
for (int i = 0; i < split.length; i++) { |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1017 |
version[i] = Integer.parseInt(split[i]); |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1018 |
} |
39889
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1019 |
|
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1020 |
Optional<String> pre = Optional.ofNullable( |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1021 |
m.group(VersionPattern.PRE_GROUP)); |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1022 |
|
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1023 |
String b = m.group(VersionPattern.BUILD_GROUP); |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1024 |
// $BUILD is an integer |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1025 |
Optional<Integer> build = (b == null) |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1026 |
? Optional.empty() |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1027 |
: Optional.of(Integer.parseInt(b)); |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1028 |
|
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1029 |
Optional<String> optional = Optional.ofNullable( |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1030 |
m.group(VersionPattern.OPT_GROUP)); |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1031 |
|
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1032 |
// empty '+' |
48545
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1033 |
if (!build.isPresent()) { |
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1034 |
if (m.group(VersionPattern.PLUS_GROUP) != null) { |
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1035 |
if (optional.isPresent()) { |
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1036 |
if (pre.isPresent()) |
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1037 |
throw new IllegalArgumentException("'+' found with" |
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1038 |
+ " pre-release and optional components:'" + s |
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1039 |
+ "'"); |
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1040 |
} else { |
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1041 |
throw new IllegalArgumentException("'+' found with neither" |
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1042 |
+ " build or optional components: '" + s + "'"); |
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1043 |
} |
39889
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1044 |
} else { |
48545
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1045 |
if (optional.isPresent() && !pre.isPresent()) { |
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1046 |
throw new IllegalArgumentException("optional component" |
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1047 |
+ " must be preceeded by a pre-release component" |
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1048 |
+ " or '+': '" + s + "'"); |
fb978155215d
8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
bchristi
parents:
48327
diff
changeset
|
1049 |
} |
39889
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1050 |
} |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1051 |
} |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1052 |
return new Version(List.of(version), pre, build, optional); |
39889
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1053 |
} |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1054 |
|
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1055 |
private static boolean isSimpleNumber(String s) { |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1056 |
for (int i = 0; i < s.length(); i++) { |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1057 |
char c = s.charAt(i); |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1058 |
char lowerBound = (i > 0) ? '0' : '1'; |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1059 |
if (c < lowerBound || c > '9') { |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1060 |
return false; |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1061 |
} |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1062 |
} |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1063 |
return true; |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1064 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1065 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1066 |
/** |
48327 | 1067 |
* Returns the value of the <a href="#FEATURE">feature</a> element of |
1068 |
* the version number. |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1069 |
* |
48327 | 1070 |
* @return The value of the feature element |
1071 |
* |
|
1072 |
* @since 10 |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1073 |
*/ |
48327 | 1074 |
public int feature() { |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1075 |
return version.get(0); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1076 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1077 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1078 |
/** |
48327 | 1079 |
* Returns the value of the <a href="#INTERIM">interim</a> element of |
1080 |
* the version number, or zero if it is absent. |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1081 |
* |
48327 | 1082 |
* @return The value of the interim element, or zero |
1083 |
* |
|
1084 |
* @since 10 |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1085 |
*/ |
48327 | 1086 |
public int interim() { |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1087 |
return (version.size() > 1 ? version.get(1) : 0); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1088 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1089 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1090 |
/** |
48327 | 1091 |
* Returns the value of the <a href="#UPDATE">update</a> element of the |
1092 |
* version number, or zero if it is absent. |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1093 |
* |
48327 | 1094 |
* @return The value of the update element, or zero |
1095 |
* |
|
1096 |
* @since 10 |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1097 |
*/ |
48327 | 1098 |
public int update() { |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1099 |
return (version.size() > 2 ? version.get(2) : 0); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1100 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1101 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1102 |
/** |
48327 | 1103 |
* Returns the value of the <a href="#PATCH">patch</a> element of the |
1104 |
* version number, or zero if it is absent. |
|
1105 |
* |
|
1106 |
* @return The value of the patch element, or zero |
|
1107 |
* |
|
1108 |
* @since 10 |
|
1109 |
*/ |
|
1110 |
public int patch() { |
|
1111 |
return (version.size() > 3 ? version.get(3) : 0); |
|
1112 |
} |
|
1113 |
||
1114 |
/** |
|
1115 |
* Returns the value of the major element of the version number. |
|
1116 |
* |
|
1117 |
* @deprecated As of Java SE 10, the first element of a version |
|
1118 |
* number is not the major-release number but the feature-release |
|
1119 |
* counter, incremented for every time-based release. Use the {@link |
|
1120 |
* #feature()} method in preference to this method. For compatibility, |
|
49508 | 1121 |
* this method returns the value of the <a href="#FEATURE">feature</a> |
48327 | 1122 |
* element. |
1123 |
* |
|
1124 |
* @return The value of the feature element |
|
1125 |
*/ |
|
1126 |
@Deprecated(since = "10") |
|
1127 |
public int major() { |
|
1128 |
return feature(); |
|
1129 |
} |
|
1130 |
||
1131 |
/** |
|
1132 |
* Returns the value of the minor element of the version number, or |
|
1133 |
* zero if it is absent. |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1134 |
* |
48327 | 1135 |
* @deprecated As of Java SE 10, the second element of a version |
1136 |
* number is not the minor-release number but the interim-release |
|
1137 |
* counter, incremented for every interim release. Use the {@link |
|
1138 |
* #interim()} method in preference to this method. For compatibility, |
|
49508 | 1139 |
* this method returns the value of the <a href="#INTERIM">interim</a> |
48327 | 1140 |
* element, or zero if it is absent. |
1141 |
* |
|
1142 |
* @return The value of the interim element, or zero |
|
1143 |
*/ |
|
1144 |
@Deprecated(since = "10") |
|
1145 |
public int minor() { |
|
1146 |
return interim(); |
|
1147 |
} |
|
1148 |
||
1149 |
/** |
|
1150 |
* Returns the value of the security element of the version number, or |
|
1151 |
* zero if it is absent. |
|
1152 |
* |
|
1153 |
* @deprecated As of Java SE 10, the third element of a version |
|
1154 |
* number is not the security level but the update-release counter, |
|
1155 |
* incremented for every update release. Use the {@link #update()} |
|
1156 |
* method in preference to this method. For compatibility, this method |
|
49508 | 1157 |
* returns the value of the <a href="#UPDATE">update</a> element, or |
48327 | 1158 |
* zero if it is absent. |
1159 |
* |
|
1160 |
* @return The value of the update element, or zero |
|
1161 |
*/ |
|
1162 |
@Deprecated(since = "10") |
|
1163 |
public int security() { |
|
1164 |
return update(); |
|
1165 |
} |
|
1166 |
||
1167 |
/** |
|
1168 |
* Returns an unmodifiable {@link java.util.List List} of the integers |
|
49508 | 1169 |
* represented in the <a href="#verNum">version number</a>. |
1170 |
* The {@code List} always contains at least one element corresponding to |
|
1171 |
* the <a href="#FEATURE">feature version number</a>. |
|
48327 | 1172 |
* |
1173 |
* @return An unmodifiable list of the integers |
|
1174 |
* represented in the version number |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1175 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1176 |
public List<Integer> version() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1177 |
return version; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1178 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1179 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1180 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1181 |
* Returns the optional <a href="#pre">pre-release</a> information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1182 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1183 |
* @return The optional pre-release information as a String |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1184 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1185 |
public Optional<String> pre() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1186 |
return pre; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1187 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1188 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1189 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1190 |
* Returns the <a href="#build">build number</a>. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1191 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1192 |
* @return The optional build number. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1193 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1194 |
public Optional<Integer> build() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1195 |
return build; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1196 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1197 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1198 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1199 |
* Returns <a href="#opt">optional</a> additional identifying build |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1200 |
* information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1201 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1202 |
* @return Additional build information as a String |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1203 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1204 |
public Optional<String> optional() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1205 |
return optional; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1206 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1207 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1208 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1209 |
* Compares this version to another. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1210 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1211 |
* <p> Each of the components in the <a href="#verStr">version</a> is |
44265
ac63ae089927
8160956: Runtime.Version.compareTo/compareToIgnoreOpt problem
prappo
parents:
40793
diff
changeset
|
1212 |
* compared in the following order of precedence: version numbers, |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1213 |
* pre-release identifiers, build numbers, optional build information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1214 |
* </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1215 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1216 |
* <p> Comparison begins by examining the sequence of version numbers. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1217 |
* If one sequence is shorter than another, then the missing elements |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1218 |
* of the shorter sequence are considered to be less than the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1219 |
* corresponding elements of the longer sequence. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1220 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1221 |
* <p> A version with a pre-release identifier is always considered to |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1222 |
* be less than a version without one. Pre-release identifiers are |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1223 |
* compared numerically when they consist only of digits, and |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1224 |
* lexicographically otherwise. Numeric identifiers are considered to |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1225 |
* be less than non-numeric identifiers. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1226 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1227 |
* <p> A version without a build number is always less than one with a |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1228 |
* build number; otherwise build numbers are compared numerically. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1229 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1230 |
* <p> The optional build information is compared lexicographically. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1231 |
* During this comparison, a version with optional build information is |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1232 |
* considered to be greater than a version without one. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1233 |
* |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1234 |
* @param obj |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1235 |
* The object to be compared |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1236 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1237 |
* @return A negative integer, zero, or a positive integer if this |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1238 |
* {@code Version} is less than, equal to, or greater than the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1239 |
* given {@code Version} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1240 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1241 |
* @throws NullPointerException |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1242 |
* If the given object is {@code null} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1243 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1244 |
@Override |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1245 |
public int compareTo(Version obj) { |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1246 |
return compare(obj, false); |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1247 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1248 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1249 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1250 |
* Compares this version to another disregarding optional build |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1251 |
* information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1252 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1253 |
* <p> Two versions are compared by examining the version string as |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1254 |
* described in {@link #compareTo(Version)} with the exception that the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1255 |
* optional build information is always ignored. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1256 |
* |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1257 |
* <p> This method provides ordering which is consistent with |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1258 |
* {@code equalsIgnoreOptional()}. </p> |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1259 |
* |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1260 |
* @param obj |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1261 |
* The object to be compared |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1262 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1263 |
* @return A negative integer, zero, or a positive integer if this |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1264 |
* {@code Version} is less than, equal to, or greater than the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1265 |
* given {@code Version} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1266 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1267 |
* @throws NullPointerException |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1268 |
* If the given object is {@code null} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1269 |
*/ |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1270 |
public int compareToIgnoreOptional(Version obj) { |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1271 |
return compare(obj, true); |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1272 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1273 |
|
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1274 |
private int compare(Version obj, boolean ignoreOpt) { |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1275 |
if (obj == null) |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1276 |
throw new NullPointerException(); |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1277 |
|
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1278 |
int ret = compareVersion(obj); |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1279 |
if (ret != 0) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1280 |
return ret; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1281 |
|
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1282 |
ret = comparePre(obj); |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1283 |
if (ret != 0) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1284 |
return ret; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1285 |
|
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1286 |
ret = compareBuild(obj); |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1287 |
if (ret != 0) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1288 |
return ret; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1289 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1290 |
if (!ignoreOpt) |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1291 |
return compareOptional(obj); |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1292 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1293 |
return 0; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1294 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1295 |
|
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1296 |
private int compareVersion(Version obj) { |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1297 |
int size = version.size(); |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1298 |
int oSize = obj.version().size(); |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1299 |
int min = Math.min(size, oSize); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1300 |
for (int i = 0; i < min; i++) { |
44272
4d16899cb312
8176882: Incorrect integer comparison in version numbers
prappo
parents:
44265
diff
changeset
|
1301 |
int val = version.get(i); |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1302 |
int oVal = obj.version().get(i); |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1303 |
if (val != oVal) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1304 |
return val - oVal; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1305 |
} |
44272
4d16899cb312
8176882: Incorrect integer comparison in version numbers
prappo
parents:
44265
diff
changeset
|
1306 |
return size - oSize; |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1307 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1308 |
|
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1309 |
private int comparePre(Version obj) { |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1310 |
Optional<String> oPre = obj.pre(); |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1311 |
if (!pre.isPresent()) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1312 |
if (oPre.isPresent()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1313 |
return 1; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1314 |
} else { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1315 |
if (!oPre.isPresent()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1316 |
return -1; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1317 |
String val = pre.get(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1318 |
String oVal = oPre.get(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1319 |
if (val.matches("\\d+")) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1320 |
return (oVal.matches("\\d+") |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1321 |
? (new BigInteger(val)).compareTo(new BigInteger(oVal)) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1322 |
: -1); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1323 |
} else { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1324 |
return (oVal.matches("\\d+") |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1325 |
? 1 |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1326 |
: val.compareTo(oVal)); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1327 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1328 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1329 |
return 0; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1330 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1331 |
|
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1332 |
private int compareBuild(Version obj) { |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1333 |
Optional<Integer> oBuild = obj.build(); |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1334 |
if (oBuild.isPresent()) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1335 |
return (build.isPresent() |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1336 |
? build.get().compareTo(oBuild.get()) |
44265
ac63ae089927
8160956: Runtime.Version.compareTo/compareToIgnoreOpt problem
prappo
parents:
40793
diff
changeset
|
1337 |
: -1); |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1338 |
} else if (build.isPresent()) { |
44265
ac63ae089927
8160956: Runtime.Version.compareTo/compareToIgnoreOpt problem
prappo
parents:
40793
diff
changeset
|
1339 |
return 1; |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1340 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1341 |
return 0; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1342 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1343 |
|
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1344 |
private int compareOptional(Version obj) { |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1345 |
Optional<String> oOpt = obj.optional(); |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1346 |
if (!optional.isPresent()) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1347 |
if (oOpt.isPresent()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1348 |
return -1; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1349 |
} else { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1350 |
if (!oOpt.isPresent()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1351 |
return 1; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1352 |
return optional.get().compareTo(oOpt.get()); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1353 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1354 |
return 0; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1355 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1356 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1357 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1358 |
* Returns a string representation of this version. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1359 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1360 |
* @return The version string |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1361 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1362 |
@Override |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1363 |
public String toString() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1364 |
StringBuilder sb |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1365 |
= new StringBuilder(version.stream() |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1366 |
.map(Object::toString) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1367 |
.collect(Collectors.joining("."))); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1368 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1369 |
pre.ifPresent(v -> sb.append("-").append(v)); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1370 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1371 |
if (build.isPresent()) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1372 |
sb.append("+").append(build.get()); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1373 |
if (optional.isPresent()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1374 |
sb.append("-").append(optional.get()); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1375 |
} else { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1376 |
if (optional.isPresent()) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1377 |
sb.append(pre.isPresent() ? "-" : "+-"); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1378 |
sb.append(optional.get()); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1379 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1380 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1381 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1382 |
return sb.toString(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1383 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1384 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1385 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1386 |
* Determines whether this {@code Version} is equal to another object. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1387 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1388 |
* <p> Two {@code Version}s are equal if and only if they represent the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1389 |
* same version string. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1390 |
* |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1391 |
* @param obj |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1392 |
* The object to which this {@code Version} is to be compared |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1393 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1394 |
* @return {@code true} if, and only if, the given object is a {@code |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1395 |
* Version} that is identical to this {@code Version} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1396 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1397 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1398 |
@Override |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1399 |
public boolean equals(Object obj) { |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1400 |
boolean ret = equalsIgnoreOptional(obj); |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1401 |
if (!ret) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1402 |
return false; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1403 |
|
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1404 |
Version that = (Version)obj; |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1405 |
return (this.optional().equals(that.optional())); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1406 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1407 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1408 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1409 |
* Determines whether this {@code Version} is equal to another |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1410 |
* disregarding optional build information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1411 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1412 |
* <p> Two {@code Version}s are equal if and only if they represent the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1413 |
* same version string disregarding the optional build information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1414 |
* |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1415 |
* @param obj |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1416 |
* The object to which this {@code Version} is to be compared |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1417 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1418 |
* @return {@code true} if, and only if, the given object is a {@code |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1419 |
* Version} that is identical to this {@code Version} |
44265
ac63ae089927
8160956: Runtime.Version.compareTo/compareToIgnoreOpt problem
prappo
parents:
40793
diff
changeset
|
1420 |
* ignoring the optional build information |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1421 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1422 |
*/ |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1423 |
public boolean equalsIgnoreOptional(Object obj) { |
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1424 |
if (this == obj) |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1425 |
return true; |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1426 |
if (!(obj instanceof Version)) |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1427 |
return false; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1428 |
|
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1429 |
Version that = (Version)obj; |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1430 |
return (this.version().equals(that.version()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1431 |
&& this.pre().equals(that.pre()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1432 |
&& this.build().equals(that.build())); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1433 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1434 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1435 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1436 |
* Returns the hash code of this version. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1437 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1438 |
* @return The hashcode of this version |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1439 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1440 |
@Override |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1441 |
public int hashCode() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1442 |
int h = 1; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1443 |
int p = 17; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1444 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1445 |
h = p * h + version.hashCode(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1446 |
h = p * h + pre.hashCode(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1447 |
h = p * h + build.hashCode(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1448 |
h = p * h + optional.hashCode(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1449 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1450 |
return h; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1451 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1452 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1453 |
|
39889
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1454 |
private static class VersionPattern { |
39302
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
1455 |
// $VNUM(-$PRE)?(\+($BUILD)?(\-$OPT)?)? |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
1456 |
// RE limits the format of version strings |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
1457 |
// ([1-9][0-9]*(?:(?:\.0)*\.[1-9][0-9]*)*)(?:-([a-zA-Z0-9]+))?(?:(\+)(0|[1-9][0-9]*)?)?(?:-([-a-zA-Z0-9.]+))? |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
1458 |
|
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
1459 |
private static final String VNUM |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
1460 |
= "(?<VNUM>[1-9][0-9]*(?:(?:\\.0)*\\.[1-9][0-9]*)*)"; |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
1461 |
private static final String PRE = "(?:-(?<PRE>[a-zA-Z0-9]+))?"; |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
1462 |
private static final String BUILD |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
1463 |
= "(?:(?<PLUS>\\+)(?<BUILD>0|[1-9][0-9]*)?)?"; |
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
1464 |
private static final String OPT = "(?:-(?<OPT>[-a-zA-Z0-9.]+))?"; |
44785
62a18e20f5c1
8177738: Runtime.Version must be a value-based class
prappo
parents:
44272
diff
changeset
|
1465 |
private static final String VSTR_FORMAT = VNUM + PRE + BUILD + OPT; |
39302
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
1466 |
|
39889
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1467 |
static final Pattern VSTR_PATTERN = Pattern.compile(VSTR_FORMAT); |
39302
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
1468 |
|
39889
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1469 |
static final String VNUM_GROUP = "VNUM"; |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1470 |
static final String PRE_GROUP = "PRE"; |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1471 |
static final String PLUS_GROUP = "PLUS"; |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1472 |
static final String BUILD_GROUP = "BUILD"; |
2e82e1c36e90
8162439: Runtime.Version.parse needs fast-path for major versions
redestad
parents:
39766
diff
changeset
|
1473 |
static final String OPT_GROUP = "OPT"; |
39302
aa8d0bc2a6d2
8160000: Runtime.version() cause startup regressions in 9+119
redestad
parents:
38432
diff
changeset
|
1474 |
} |
2 | 1475 |
} |