author | smarks |
Fri, 22 Apr 2016 13:10:53 -0700 | |
changeset 37606 | e74fdd1e637f |
parent 37521 | b6e0f285c998 |
child 38432 | 892603099bb0 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
24367
705490680527
8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents:
18776
diff
changeset
|
2 |
* Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.lang; |
|
27 |
||
28 |
import java.io.*; |
|
29 |
import java.util.StringTokenizer; |
|
37363
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
34350
diff
changeset
|
30 |
import jdk.internal.reflect.CallerSensitive; |
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
34350
diff
changeset
|
31 |
import jdk.internal.reflect.Reflection; |
2 | 32 |
|
33 |
/** |
|
34 |
* Every Java application has a single instance of class |
|
30042 | 35 |
* {@code Runtime} that allows the application to interface with |
2 | 36 |
* the environment in which the application is running. The current |
30042 | 37 |
* runtime can be obtained from the {@code getRuntime} method. |
2 | 38 |
* <p> |
39 |
* An application cannot create its own instance of this class. |
|
40 |
* |
|
41 |
* @author unascribed |
|
42 |
* @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
|
43 |
* @since 1.0 |
2 | 44 |
*/ |
45 |
||
46 |
public class Runtime { |
|
34350 | 47 |
private static final Runtime currentRuntime = new Runtime(); |
2 | 48 |
|
49 |
/** |
|
50 |
* Returns the runtime object associated with the current Java application. |
|
30042 | 51 |
* Most of the methods of class {@code Runtime} are instance |
2 | 52 |
* methods and must be invoked with respect to the current runtime object. |
53 |
* |
|
30042 | 54 |
* @return the {@code Runtime} object associated with the current |
2 | 55 |
* Java application. |
56 |
*/ |
|
57 |
public static Runtime getRuntime() { |
|
58 |
return currentRuntime; |
|
59 |
} |
|
60 |
||
61 |
/** Don't let anyone else instantiate this class */ |
|
62 |
private Runtime() {} |
|
63 |
||
64 |
/** |
|
65 |
* Terminates the currently running Java virtual machine by initiating its |
|
66 |
* shutdown sequence. This method never returns normally. The argument |
|
67 |
* serves as a status code; by convention, a nonzero status code indicates |
|
68 |
* abnormal termination. |
|
69 |
* |
|
70 |
* <p> The virtual machine's shutdown sequence consists of two phases. In |
|
71 |
* the first phase all registered {@link #addShutdownHook shutdown hooks}, |
|
72 |
* if any, are started in some unspecified order and allowed to run |
|
73 |
* concurrently until they finish. In the second phase all uninvoked |
|
74 |
* finalizers are run if {@link #runFinalizersOnExit finalization-on-exit} |
|
30042 | 75 |
* has been enabled. Once this is done the virtual machine {@link #halt halts}. |
2 | 76 |
* |
77 |
* <p> If this method is invoked after the virtual machine has begun its |
|
78 |
* shutdown sequence then if shutdown hooks are being run this method will |
|
79 |
* block indefinitely. If shutdown hooks have already been run and on-exit |
|
80 |
* finalization has been enabled then this method halts the virtual machine |
|
81 |
* with the given status code if the status is nonzero; otherwise, it |
|
82 |
* blocks indefinitely. |
|
83 |
* |
|
30042 | 84 |
* <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
|
85 |
* conventional and convenient means of invoking this method. |
2 | 86 |
* |
87 |
* @param status |
|
88 |
* Termination status. By convention, a nonzero status code |
|
89 |
* indicates abnormal termination. |
|
90 |
* |
|
91 |
* @throws SecurityException |
|
30042 | 92 |
* If a security manager is present and its |
93 |
* {@link SecurityManager#checkExit checkExit} method does not permit |
|
2 | 94 |
* exiting with the specified status |
95 |
* |
|
96 |
* @see java.lang.SecurityException |
|
97 |
* @see java.lang.SecurityManager#checkExit(int) |
|
98 |
* @see #addShutdownHook |
|
99 |
* @see #removeShutdownHook |
|
100 |
* @see #runFinalizersOnExit |
|
101 |
* @see #halt(int) |
|
102 |
*/ |
|
103 |
public void exit(int status) { |
|
104 |
SecurityManager security = System.getSecurityManager(); |
|
105 |
if (security != null) { |
|
106 |
security.checkExit(status); |
|
107 |
} |
|
108 |
Shutdown.exit(status); |
|
109 |
} |
|
110 |
||
111 |
/** |
|
112 |
* Registers a new virtual-machine shutdown hook. |
|
113 |
* |
|
114 |
* <p> The Java virtual machine <i>shuts down</i> in response to two kinds |
|
115 |
* of events: |
|
116 |
* |
|
117 |
* <ul> |
|
118 |
* |
|
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
16906
diff
changeset
|
119 |
* <li> The program <i>exits</i> normally, when the last non-daemon |
30042 | 120 |
* 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
|
121 |
* {@link System#exit(int) System.exit}) method is invoked, or |
2 | 122 |
* |
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
16906
diff
changeset
|
123 |
* <li> The virtual machine is <i>terminated</i> in response to a |
30042 | 124 |
* user interrupt, such as typing {@code ^C}, or a system-wide event, |
2 | 125 |
* such as user logoff or system shutdown. |
126 |
* |
|
127 |
* </ul> |
|
128 |
* |
|
129 |
* <p> A <i>shutdown hook</i> is simply an initialized but unstarted |
|
130 |
* thread. When the virtual machine begins its shutdown sequence it will |
|
131 |
* start all registered shutdown hooks in some unspecified order and let |
|
132 |
* them run concurrently. When all the hooks have finished it will then |
|
133 |
* run all uninvoked finalizers if finalization-on-exit has been enabled. |
|
134 |
* Finally, the virtual machine will halt. Note that daemon threads will |
|
135 |
* continue to run during the shutdown sequence, as will non-daemon threads |
|
30042 | 136 |
* if shutdown was initiated by invoking the {@link #exit exit} method. |
2 | 137 |
* |
138 |
* <p> Once the shutdown sequence has begun it can be stopped only by |
|
30042 | 139 |
* invoking the {@link #halt halt} method, which forcibly |
2 | 140 |
* terminates the virtual machine. |
141 |
* |
|
142 |
* <p> Once the shutdown sequence has begun it is impossible to register a |
|
143 |
* new shutdown hook or de-register a previously-registered hook. |
|
144 |
* Attempting either of these operations will cause an |
|
30042 | 145 |
* {@link IllegalStateException} to be thrown. |
2 | 146 |
* |
147 |
* <p> Shutdown hooks run at a delicate time in the life cycle of a virtual |
|
148 |
* machine and should therefore be coded defensively. They should, in |
|
149 |
* particular, be written to be thread-safe and to avoid deadlocks insofar |
|
150 |
* as possible. They should also not rely blindly upon services that may |
|
151 |
* have registered their own shutdown hooks and therefore may themselves in |
|
152 |
* the process of shutting down. Attempts to use other thread-based |
|
153 |
* services such as the AWT event-dispatch thread, for example, may lead to |
|
154 |
* deadlocks. |
|
155 |
* |
|
156 |
* <p> Shutdown hooks should also finish their work quickly. When a |
|
30042 | 157 |
* program invokes {@link #exit exit} the expectation is |
2 | 158 |
* that the virtual machine will promptly shut down and exit. When the |
159 |
* virtual machine is terminated due to user logoff or system shutdown the |
|
160 |
* underlying operating system may only allow a fixed amount of time in |
|
161 |
* which to shut down and exit. It is therefore inadvisable to attempt any |
|
162 |
* user interaction or to perform a long-running computation in a shutdown |
|
163 |
* hook. |
|
164 |
* |
|
165 |
* <p> Uncaught exceptions are handled in shutdown hooks just as in any |
|
30042 | 166 |
* other thread, by invoking the |
167 |
* {@link ThreadGroup#uncaughtException uncaughtException} method of the |
|
168 |
* thread's {@link ThreadGroup} object. The default implementation of this |
|
169 |
* method prints the exception's stack trace to {@link System#err} and |
|
2 | 170 |
* terminates the thread; it does not cause the virtual machine to exit or |
171 |
* halt. |
|
172 |
* |
|
173 |
* <p> In rare circumstances the virtual machine may <i>abort</i>, that is, |
|
174 |
* stop running without shutting down cleanly. This occurs when the |
|
175 |
* virtual machine is terminated externally, for example with the |
|
30042 | 176 |
* {@code SIGKILL} signal on Unix or the {@code TerminateProcess} call on |
2 | 177 |
* Microsoft Windows. The virtual machine may also abort if a native |
178 |
* method goes awry by, for example, corrupting internal data structures or |
|
179 |
* attempting to access nonexistent memory. If the virtual machine aborts |
|
180 |
* 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
|
181 |
* will be run. |
2 | 182 |
* |
183 |
* @param hook |
|
30042 | 184 |
* An initialized but unstarted {@link Thread} object |
2 | 185 |
* |
186 |
* @throws IllegalArgumentException |
|
187 |
* If the specified hook has already been registered, |
|
188 |
* or if it can be determined that the hook is already running or |
|
189 |
* has already been run |
|
190 |
* |
|
191 |
* @throws IllegalStateException |
|
192 |
* If the virtual machine is already in the process |
|
193 |
* of shutting down |
|
194 |
* |
|
195 |
* @throws SecurityException |
|
196 |
* If a security manager is present and it denies |
|
30042 | 197 |
* {@link RuntimePermission}("shutdownHooks") |
2 | 198 |
* |
199 |
* @see #removeShutdownHook |
|
200 |
* @see #halt(int) |
|
201 |
* @see #exit(int) |
|
202 |
* @since 1.3 |
|
203 |
*/ |
|
204 |
public void addShutdownHook(Thread hook) { |
|
205 |
SecurityManager sm = System.getSecurityManager(); |
|
206 |
if (sm != null) { |
|
207 |
sm.checkPermission(new RuntimePermission("shutdownHooks")); |
|
208 |
} |
|
209 |
ApplicationShutdownHooks.add(hook); |
|
210 |
} |
|
211 |
||
212 |
/** |
|
30042 | 213 |
* De-registers a previously-registered virtual-machine shutdown hook. |
2 | 214 |
* |
215 |
* @param hook the hook to remove |
|
30042 | 216 |
* @return {@code true} if the specified hook had previously been |
217 |
* registered and was successfully de-registered, {@code false} |
|
2 | 218 |
* otherwise. |
219 |
* |
|
220 |
* @throws IllegalStateException |
|
221 |
* If the virtual machine is already in the process of shutting |
|
222 |
* down |
|
223 |
* |
|
224 |
* @throws SecurityException |
|
225 |
* If a security manager is present and it denies |
|
30042 | 226 |
* {@link RuntimePermission}("shutdownHooks") |
2 | 227 |
* |
228 |
* @see #addShutdownHook |
|
229 |
* @see #exit(int) |
|
230 |
* @since 1.3 |
|
231 |
*/ |
|
232 |
public boolean removeShutdownHook(Thread hook) { |
|
233 |
SecurityManager sm = System.getSecurityManager(); |
|
234 |
if (sm != null) { |
|
235 |
sm.checkPermission(new RuntimePermission("shutdownHooks")); |
|
236 |
} |
|
237 |
return ApplicationShutdownHooks.remove(hook); |
|
238 |
} |
|
239 |
||
240 |
/** |
|
241 |
* Forcibly terminates the currently running Java virtual machine. This |
|
242 |
* method never returns normally. |
|
243 |
* |
|
244 |
* <p> This method should be used with extreme caution. Unlike the |
|
30042 | 245 |
* {@link #exit exit} method, this method does not cause shutdown |
2 | 246 |
* hooks to be started and does not run uninvoked finalizers if |
247 |
* finalization-on-exit has been enabled. If the shutdown sequence has |
|
248 |
* already been initiated then this method does not wait for any running |
|
24367
705490680527
8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents:
18776
diff
changeset
|
249 |
* shutdown hooks or finalizers to finish their work. |
2 | 250 |
* |
251 |
* @param status |
|
30042 | 252 |
* Termination status. By convention, a nonzero status code |
253 |
* indicates abnormal termination. If the {@link Runtime#exit exit} |
|
254 |
* (equivalently, {@link System#exit(int) System.exit}) method |
|
255 |
* has already been invoked then this status code |
|
256 |
* will override the status code passed to that method. |
|
2 | 257 |
* |
258 |
* @throws SecurityException |
|
30042 | 259 |
* If a security manager is present and its |
260 |
* {@link SecurityManager#checkExit checkExit} method |
|
261 |
* does not permit an exit with the specified status |
|
2 | 262 |
* |
263 |
* @see #exit |
|
264 |
* @see #addShutdownHook |
|
265 |
* @see #removeShutdownHook |
|
266 |
* @since 1.3 |
|
267 |
*/ |
|
268 |
public void halt(int status) { |
|
269 |
SecurityManager sm = System.getSecurityManager(); |
|
270 |
if (sm != null) { |
|
271 |
sm.checkExit(status); |
|
272 |
} |
|
273 |
Shutdown.halt(status); |
|
274 |
} |
|
275 |
||
276 |
/** |
|
277 |
* Enable or disable finalization on exit; doing so specifies that the |
|
278 |
* finalizers of all objects that have finalizers that have not yet been |
|
279 |
* automatically invoked are to be run before the Java runtime exits. |
|
280 |
* By default, finalization on exit is disabled. |
|
281 |
* |
|
282 |
* <p>If there is a security manager, |
|
30042 | 283 |
* its {@code checkExit} method is first called |
2 | 284 |
* with 0 as its argument to ensure the exit is allowed. |
285 |
* This could result in a SecurityException. |
|
286 |
* |
|
287 |
* @param value true to enable finalization on exit, false to disable |
|
288 |
* @deprecated This method is inherently unsafe. It may result in |
|
289 |
* finalizers being called on live objects while other threads are |
|
290 |
* concurrently manipulating those objects, resulting in erratic |
|
291 |
* behavior or deadlock. |
|
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
37363
diff
changeset
|
292 |
* This method is subject to removal in a future version of Java SE. |
2 | 293 |
* |
294 |
* @throws SecurityException |
|
30042 | 295 |
* if a security manager exists and its {@code checkExit} |
2 | 296 |
* method doesn't allow the exit. |
297 |
* |
|
298 |
* @see java.lang.Runtime#exit(int) |
|
299 |
* @see java.lang.Runtime#gc() |
|
300 |
* @see java.lang.SecurityManager#checkExit(int) |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24367
diff
changeset
|
301 |
* @since 1.1 |
2 | 302 |
*/ |
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
37363
diff
changeset
|
303 |
@Deprecated(since="1.2", forRemoval=true) |
2 | 304 |
public static void runFinalizersOnExit(boolean value) { |
305 |
SecurityManager security = System.getSecurityManager(); |
|
306 |
if (security != null) { |
|
307 |
try { |
|
308 |
security.checkExit(0); |
|
309 |
} catch (SecurityException e) { |
|
310 |
throw new SecurityException("runFinalizersOnExit"); |
|
311 |
} |
|
312 |
} |
|
313 |
Shutdown.setRunFinalizersOnExit(value); |
|
314 |
} |
|
315 |
||
316 |
/** |
|
317 |
* Executes the specified string command in a separate process. |
|
318 |
* |
|
319 |
* <p>This is a convenience method. An invocation of the form |
|
30042 | 320 |
* {@code exec(command)} |
2 | 321 |
* behaves in exactly the same way as the invocation |
30042 | 322 |
* {@link #exec(String, String[], File) exec}{@code (command, null, null)}. |
2 | 323 |
* |
324 |
* @param command a specified system command. |
|
325 |
* |
|
326 |
* @return A new {@link Process} object for managing the subprocess |
|
327 |
* |
|
328 |
* @throws SecurityException |
|
329 |
* If a security manager exists and its |
|
330 |
* {@link SecurityManager#checkExec checkExec} |
|
331 |
* method doesn't allow creation of the subprocess |
|
332 |
* |
|
333 |
* @throws IOException |
|
334 |
* If an I/O error occurs |
|
335 |
* |
|
336 |
* @throws NullPointerException |
|
30042 | 337 |
* If {@code command} is {@code null} |
2 | 338 |
* |
339 |
* @throws IllegalArgumentException |
|
30042 | 340 |
* If {@code command} is empty |
2 | 341 |
* |
342 |
* @see #exec(String[], String[], File) |
|
343 |
* @see ProcessBuilder |
|
344 |
*/ |
|
345 |
public Process exec(String command) throws IOException { |
|
346 |
return exec(command, null, null); |
|
347 |
} |
|
348 |
||
349 |
/** |
|
350 |
* Executes the specified string command in a separate process with the |
|
351 |
* specified environment. |
|
352 |
* |
|
353 |
* <p>This is a convenience method. An invocation of the form |
|
30042 | 354 |
* {@code exec(command, envp)} |
2 | 355 |
* behaves in exactly the same way as the invocation |
30042 | 356 |
* {@link #exec(String, String[], File) exec}{@code (command, envp, null)}. |
2 | 357 |
* |
358 |
* @param command a specified system command. |
|
359 |
* |
|
360 |
* @param envp array of strings, each element of which |
|
361 |
* has environment variable settings in the format |
|
362 |
* <i>name</i>=<i>value</i>, or |
|
30042 | 363 |
* {@code null} if the subprocess should inherit |
2 | 364 |
* the environment of the current process. |
365 |
* |
|
366 |
* @return A new {@link Process} object for managing the subprocess |
|
367 |
* |
|
368 |
* @throws SecurityException |
|
369 |
* If a security manager exists and its |
|
370 |
* {@link SecurityManager#checkExec checkExec} |
|
371 |
* method doesn't allow creation of the subprocess |
|
372 |
* |
|
373 |
* @throws IOException |
|
374 |
* If an I/O error occurs |
|
375 |
* |
|
376 |
* @throws NullPointerException |
|
30042 | 377 |
* If {@code command} is {@code null}, |
378 |
* or one of the elements of {@code envp} is {@code null} |
|
2 | 379 |
* |
380 |
* @throws IllegalArgumentException |
|
30042 | 381 |
* If {@code command} is empty |
2 | 382 |
* |
383 |
* @see #exec(String[], String[], File) |
|
384 |
* @see ProcessBuilder |
|
385 |
*/ |
|
386 |
public Process exec(String command, String[] envp) throws IOException { |
|
387 |
return exec(command, envp, null); |
|
388 |
} |
|
389 |
||
390 |
/** |
|
391 |
* Executes the specified string command in a separate process with the |
|
392 |
* specified environment and working directory. |
|
393 |
* |
|
394 |
* <p>This is a convenience method. An invocation of the form |
|
30042 | 395 |
* {@code exec(command, envp, dir)} |
2 | 396 |
* behaves in exactly the same way as the invocation |
30042 | 397 |
* {@link #exec(String[], String[], File) exec}{@code (cmdarray, envp, dir)}, |
398 |
* where {@code cmdarray} is an array of all the tokens in |
|
399 |
* {@code command}. |
|
2 | 400 |
* |
30042 | 401 |
* <p>More precisely, the {@code command} string is broken |
2 | 402 |
* into tokens using a {@link StringTokenizer} created by the call |
30042 | 403 |
* {@code new {@link StringTokenizer}(command)} with no |
2 | 404 |
* further modification of the character categories. The tokens |
405 |
* produced by the tokenizer are then placed in the new string |
|
30042 | 406 |
* array {@code cmdarray}, in the same order. |
2 | 407 |
* |
408 |
* @param command a specified system command. |
|
409 |
* |
|
410 |
* @param envp array of strings, each element of which |
|
411 |
* has environment variable settings in the format |
|
412 |
* <i>name</i>=<i>value</i>, or |
|
30042 | 413 |
* {@code null} if the subprocess should inherit |
2 | 414 |
* the environment of the current process. |
415 |
* |
|
416 |
* @param dir the working directory of the subprocess, or |
|
30042 | 417 |
* {@code null} if the subprocess should inherit |
2 | 418 |
* the working directory of the current process. |
419 |
* |
|
420 |
* @return A new {@link Process} object for managing the subprocess |
|
421 |
* |
|
422 |
* @throws SecurityException |
|
423 |
* If a security manager exists and its |
|
424 |
* {@link SecurityManager#checkExec checkExec} |
|
425 |
* method doesn't allow creation of the subprocess |
|
426 |
* |
|
427 |
* @throws IOException |
|
428 |
* If an I/O error occurs |
|
429 |
* |
|
430 |
* @throws NullPointerException |
|
30042 | 431 |
* If {@code command} is {@code null}, |
432 |
* or one of the elements of {@code envp} is {@code null} |
|
2 | 433 |
* |
434 |
* @throws IllegalArgumentException |
|
30042 | 435 |
* If {@code command} is empty |
2 | 436 |
* |
437 |
* @see ProcessBuilder |
|
438 |
* @since 1.3 |
|
439 |
*/ |
|
440 |
public Process exec(String command, String[] envp, File dir) |
|
441 |
throws IOException { |
|
442 |
if (command.length() == 0) |
|
443 |
throw new IllegalArgumentException("Empty command"); |
|
444 |
||
445 |
StringTokenizer st = new StringTokenizer(command); |
|
446 |
String[] cmdarray = new String[st.countTokens()]; |
|
447 |
for (int i = 0; st.hasMoreTokens(); i++) |
|
448 |
cmdarray[i] = st.nextToken(); |
|
449 |
return exec(cmdarray, envp, dir); |
|
450 |
} |
|
451 |
||
452 |
/** |
|
453 |
* Executes the specified command and arguments in a separate process. |
|
454 |
* |
|
455 |
* <p>This is a convenience method. An invocation of the form |
|
30042 | 456 |
* {@code exec(cmdarray)} |
2 | 457 |
* behaves in exactly the same way as the invocation |
30042 | 458 |
* {@link #exec(String[], String[], File) exec}{@code (cmdarray, null, null)}. |
2 | 459 |
* |
460 |
* @param cmdarray array containing the command to call and |
|
461 |
* its arguments. |
|
462 |
* |
|
463 |
* @return A new {@link Process} object for managing the subprocess |
|
464 |
* |
|
465 |
* @throws SecurityException |
|
466 |
* If a security manager exists and its |
|
467 |
* {@link SecurityManager#checkExec checkExec} |
|
468 |
* method doesn't allow creation of the subprocess |
|
469 |
* |
|
470 |
* @throws IOException |
|
471 |
* If an I/O error occurs |
|
472 |
* |
|
473 |
* @throws NullPointerException |
|
30042 | 474 |
* If {@code cmdarray} is {@code null}, |
475 |
* or one of the elements of {@code cmdarray} is {@code null} |
|
2 | 476 |
* |
477 |
* @throws IndexOutOfBoundsException |
|
30042 | 478 |
* If {@code cmdarray} is an empty array |
479 |
* (has length {@code 0}) |
|
2 | 480 |
* |
481 |
* @see ProcessBuilder |
|
482 |
*/ |
|
483 |
public Process exec(String cmdarray[]) throws IOException { |
|
484 |
return exec(cmdarray, null, null); |
|
485 |
} |
|
486 |
||
487 |
/** |
|
488 |
* Executes the specified command and arguments in a separate process |
|
489 |
* with the specified environment. |
|
490 |
* |
|
491 |
* <p>This is a convenience method. An invocation of the form |
|
30042 | 492 |
* {@code exec(cmdarray, envp)} |
2 | 493 |
* behaves in exactly the same way as the invocation |
30042 | 494 |
* {@link #exec(String[], String[], File) exec}{@code (cmdarray, envp, null)}. |
2 | 495 |
* |
496 |
* @param cmdarray array containing the command to call and |
|
497 |
* its arguments. |
|
498 |
* |
|
499 |
* @param envp array of strings, each element of which |
|
500 |
* has environment variable settings in the format |
|
501 |
* <i>name</i>=<i>value</i>, or |
|
30042 | 502 |
* {@code null} if the subprocess should inherit |
2 | 503 |
* the environment of the current process. |
504 |
* |
|
505 |
* @return A new {@link Process} object for managing the subprocess |
|
506 |
* |
|
507 |
* @throws SecurityException |
|
508 |
* If a security manager exists and its |
|
509 |
* {@link SecurityManager#checkExec checkExec} |
|
510 |
* method doesn't allow creation of the subprocess |
|
511 |
* |
|
512 |
* @throws IOException |
|
513 |
* If an I/O error occurs |
|
514 |
* |
|
515 |
* @throws NullPointerException |
|
30042 | 516 |
* If {@code cmdarray} is {@code null}, |
517 |
* or one of the elements of {@code cmdarray} is {@code null}, |
|
518 |
* or one of the elements of {@code envp} is {@code null} |
|
2 | 519 |
* |
520 |
* @throws IndexOutOfBoundsException |
|
30042 | 521 |
* If {@code cmdarray} is an empty array |
522 |
* (has length {@code 0}) |
|
2 | 523 |
* |
524 |
* @see ProcessBuilder |
|
525 |
*/ |
|
526 |
public Process exec(String[] cmdarray, String[] envp) throws IOException { |
|
527 |
return exec(cmdarray, envp, null); |
|
528 |
} |
|
529 |
||
530 |
||
531 |
/** |
|
532 |
* Executes the specified command and arguments in a separate process with |
|
533 |
* the specified environment and working directory. |
|
534 |
* |
|
30042 | 535 |
* <p>Given an array of strings {@code cmdarray}, representing the |
536 |
* tokens of a command line, and an array of strings {@code envp}, |
|
2 | 537 |
* representing "environment" variable settings, this method creates |
538 |
* a new process in which to execute the specified command. |
|
539 |
* |
|
30042 | 540 |
* <p>This method checks that {@code cmdarray} is a valid operating |
2 | 541 |
* system command. Which commands are valid is system-dependent, |
542 |
* but at the very least the command must be a non-empty list of |
|
543 |
* non-null strings. |
|
544 |
* |
|
30042 | 545 |
* <p>If {@code envp} is {@code null}, the subprocess inherits the |
2 | 546 |
* environment settings of the current process. |
547 |
* |
|
9500
268f823d9e1c
7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents:
5506
diff
changeset
|
548 |
* <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
|
549 |
* 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
|
550 |
* 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
|
551 |
* 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
|
552 |
* |
2 | 553 |
* <p>{@link ProcessBuilder#start()} is now the preferred way to |
554 |
* start a process with a modified environment. |
|
555 |
* |
|
30042 | 556 |
* <p>The working directory of the new subprocess is specified by {@code dir}. |
557 |
* If {@code dir} is {@code null}, the subprocess inherits the |
|
2 | 558 |
* current working directory of the current process. |
559 |
* |
|
560 |
* <p>If a security manager exists, its |
|
561 |
* {@link SecurityManager#checkExec checkExec} |
|
562 |
* method is invoked with the first component of the array |
|
30042 | 563 |
* {@code cmdarray} as its argument. This may result in a |
2 | 564 |
* {@link SecurityException} being thrown. |
565 |
* |
|
566 |
* <p>Starting an operating system process is highly system-dependent. |
|
567 |
* Among the many things that can go wrong are: |
|
568 |
* <ul> |
|
569 |
* <li>The operating system program file was not found. |
|
570 |
* <li>Access to the program file was denied. |
|
571 |
* <li>The working directory does not exist. |
|
572 |
* </ul> |
|
573 |
* |
|
574 |
* <p>In such cases an exception will be thrown. The exact nature |
|
575 |
* of the exception is system-dependent, but it will always be a |
|
576 |
* subclass of {@link IOException}. |
|
577 |
* |
|
28872
82a09f5a7ed6
8072034: (process) ProcessBuilder.start and Runtime.exec UnsupportedOperationException editorial cleanup
rriggs
parents:
28750
diff
changeset
|
578 |
* <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
|
579 |
* processes, an {@link UnsupportedOperationException} will be thrown. |
82a09f5a7ed6
8072034: (process) ProcessBuilder.start and Runtime.exec UnsupportedOperationException editorial cleanup
rriggs
parents:
28750
diff
changeset
|
580 |
* |
2 | 581 |
* |
582 |
* @param cmdarray array containing the command to call and |
|
583 |
* its arguments. |
|
584 |
* |
|
585 |
* @param envp array of strings, each element of which |
|
586 |
* has environment variable settings in the format |
|
587 |
* <i>name</i>=<i>value</i>, or |
|
30042 | 588 |
* {@code null} if the subprocess should inherit |
2 | 589 |
* the environment of the current process. |
590 |
* |
|
591 |
* @param dir the working directory of the subprocess, or |
|
30042 | 592 |
* {@code null} if the subprocess should inherit |
2 | 593 |
* the working directory of the current process. |
594 |
* |
|
595 |
* @return A new {@link Process} object for managing the subprocess |
|
596 |
* |
|
597 |
* @throws SecurityException |
|
598 |
* If a security manager exists and its |
|
599 |
* {@link SecurityManager#checkExec checkExec} |
|
600 |
* method doesn't allow creation of the subprocess |
|
601 |
* |
|
28750
a1dae439cdab
8055330: (process spec) ProcessBuilder.start and Runtime.exec should throw UnsupportedOperationException on platforms that don't support
rriggs
parents:
27184
diff
changeset
|
602 |
* @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
|
603 |
* 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
|
604 |
* |
2 | 605 |
* @throws IOException |
606 |
* If an I/O error occurs |
|
607 |
* |
|
608 |
* @throws NullPointerException |
|
30042 | 609 |
* If {@code cmdarray} is {@code null}, |
610 |
* or one of the elements of {@code cmdarray} is {@code null}, |
|
611 |
* or one of the elements of {@code envp} is {@code null} |
|
2 | 612 |
* |
613 |
* @throws IndexOutOfBoundsException |
|
30042 | 614 |
* If {@code cmdarray} is an empty array |
615 |
* (has length {@code 0}) |
|
2 | 616 |
* |
617 |
* @see ProcessBuilder |
|
618 |
* @since 1.3 |
|
619 |
*/ |
|
620 |
public Process exec(String[] cmdarray, String[] envp, File dir) |
|
621 |
throws IOException { |
|
622 |
return new ProcessBuilder(cmdarray) |
|
623 |
.environment(envp) |
|
624 |
.directory(dir) |
|
625 |
.start(); |
|
626 |
} |
|
627 |
||
628 |
/** |
|
629 |
* Returns the number of processors available to the Java virtual machine. |
|
630 |
* |
|
631 |
* <p> This value may change during a particular invocation of the virtual |
|
632 |
* machine. Applications that are sensitive to the number of available |
|
633 |
* processors should therefore occasionally poll this property and adjust |
|
634 |
* their resource usage appropriately. </p> |
|
635 |
* |
|
636 |
* @return the maximum number of processors available to the virtual |
|
637 |
* machine; never smaller than one |
|
638 |
* @since 1.4 |
|
639 |
*/ |
|
640 |
public native int availableProcessors(); |
|
641 |
||
642 |
/** |
|
643 |
* Returns the amount of free memory in the Java Virtual Machine. |
|
644 |
* Calling the |
|
30042 | 645 |
* {@code gc} method may result in increasing the value returned |
646 |
* by {@code freeMemory.} |
|
2 | 647 |
* |
648 |
* @return an approximation to the total amount of memory currently |
|
649 |
* available for future allocated objects, measured in bytes. |
|
650 |
*/ |
|
651 |
public native long freeMemory(); |
|
652 |
||
653 |
/** |
|
654 |
* Returns the total amount of memory in the Java virtual machine. |
|
655 |
* The value returned by this method may vary over time, depending on |
|
656 |
* the host environment. |
|
657 |
* <p> |
|
658 |
* Note that the amount of memory required to hold an object of any |
|
659 |
* given type may be implementation-dependent. |
|
660 |
* |
|
661 |
* @return the total amount of memory currently available for current |
|
662 |
* and future objects, measured in bytes. |
|
663 |
*/ |
|
664 |
public native long totalMemory(); |
|
665 |
||
666 |
/** |
|
30042 | 667 |
* Returns the maximum amount of memory that the Java virtual machine |
668 |
* will attempt to use. If there is no inherent limit then the value |
|
669 |
* {@link java.lang.Long#MAX_VALUE} will be returned. |
|
2 | 670 |
* |
671 |
* @return the maximum amount of memory that the virtual machine will |
|
672 |
* attempt to use, measured in bytes |
|
673 |
* @since 1.4 |
|
674 |
*/ |
|
675 |
public native long maxMemory(); |
|
676 |
||
677 |
/** |
|
678 |
* Runs the garbage collector. |
|
679 |
* Calling this method suggests that the Java virtual machine expend |
|
680 |
* effort toward recycling unused objects in order to make the memory |
|
681 |
* they currently occupy available for quick reuse. When control |
|
682 |
* returns from the method call, the virtual machine has made |
|
683 |
* its best effort to recycle all discarded objects. |
|
684 |
* <p> |
|
30042 | 685 |
* The name {@code gc} stands for "garbage |
2 | 686 |
* collector". The virtual machine performs this recycling |
687 |
* process automatically as needed, in a separate thread, even if the |
|
30042 | 688 |
* {@code gc} method is not invoked explicitly. |
2 | 689 |
* <p> |
690 |
* The method {@link System#gc()} is the conventional and convenient |
|
691 |
* means of invoking this method. |
|
692 |
*/ |
|
693 |
public native void gc(); |
|
694 |
||
695 |
/* Wormhole for calling java.lang.ref.Finalizer.runFinalization */ |
|
696 |
private static native void runFinalization0(); |
|
697 |
||
698 |
/** |
|
699 |
* Runs the finalization methods of any objects pending finalization. |
|
700 |
* Calling this method suggests that the Java virtual machine expend |
|
30042 | 701 |
* effort toward running the {@code finalize} methods of objects |
702 |
* that have been found to be discarded but whose {@code finalize} |
|
2 | 703 |
* methods have not yet been run. When control returns from the |
704 |
* method call, the virtual machine has made a best effort to |
|
705 |
* complete all outstanding finalizations. |
|
706 |
* <p> |
|
707 |
* The virtual machine performs the finalization process |
|
708 |
* automatically as needed, in a separate thread, if the |
|
30042 | 709 |
* {@code runFinalization} method is not invoked explicitly. |
2 | 710 |
* <p> |
711 |
* The method {@link System#runFinalization()} is the conventional |
|
712 |
* and convenient means of invoking this method. |
|
713 |
* |
|
714 |
* @see java.lang.Object#finalize() |
|
715 |
*/ |
|
716 |
public void runFinalization() { |
|
717 |
runFinalization0(); |
|
718 |
} |
|
719 |
||
720 |
/** |
|
37606
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
721 |
* Not implemented, does nothing. |
2 | 722 |
* |
37606
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
723 |
* @deprecated |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
724 |
* This method was intended to control instruction tracing. |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
725 |
* It has been superseded by JVM-specific tracing mechanisms. |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
726 |
* |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
727 |
* @param on ignored |
2 | 728 |
*/ |
37606
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
729 |
@Deprecated(since="9", forRemoval=true) |
27184 | 730 |
public void traceInstructions(boolean on) { } |
2 | 731 |
|
732 |
/** |
|
37606
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
733 |
* Not implemented, does nothing. |
2 | 734 |
* |
37606
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
735 |
* @deprecated |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
736 |
* This method was intended to control method call tracing. |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
737 |
* It has been superseded by JVM-specific tracing mechanisms. |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
738 |
* |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
739 |
* @param on ignored |
2 | 740 |
*/ |
37606
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
741 |
@Deprecated(since="9", forRemoval=true) |
27184 | 742 |
public void traceMethodCalls(boolean on) { } |
2 | 743 |
|
744 |
/** |
|
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
745 |
* 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
|
746 |
* argument must be an absolute path name. |
2 | 747 |
* (for example |
30042 | 748 |
* {@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
|
749 |
* |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
750 |
* 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
|
751 |
* 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
|
752 |
* 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
|
753 |
* 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
|
754 |
* 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
|
755 |
* A filename matching the argument does not have to exist in the file |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
756 |
* system. See the JNI Specification for more details. |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
757 |
* |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
758 |
* 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
|
759 |
* an implementation-dependent manner. |
2 | 760 |
* <p> |
30042 | 761 |
* First, if there is a security manager, its {@code checkLink} |
762 |
* method is called with the {@code filename} as its argument. |
|
2 | 763 |
* This may result in a security exception. |
764 |
* <p> |
|
765 |
* This is similar to the method {@link #loadLibrary(String)}, but it |
|
766 |
* accepts a general file name as an argument rather than just a library |
|
767 |
* name, allowing any file of native code to be loaded. |
|
768 |
* <p> |
|
769 |
* The method {@link System#load(String)} is the conventional and |
|
770 |
* convenient means of invoking this method. |
|
771 |
* |
|
772 |
* @param filename the file to load. |
|
773 |
* @exception SecurityException if a security manager exists and its |
|
30042 | 774 |
* {@code checkLink} method doesn't allow |
2 | 775 |
* loading of the specified dynamic library |
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
776 |
* @exception UnsatisfiedLinkError if either the filename is not an |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
777 |
* 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
|
778 |
* 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
|
779 |
* a native library image by the host system. |
30042 | 780 |
* @exception NullPointerException if {@code filename} is |
781 |
* {@code null} |
|
2 | 782 |
* @see java.lang.Runtime#getRuntime() |
783 |
* @see java.lang.SecurityException |
|
784 |
* @see java.lang.SecurityManager#checkLink(java.lang.String) |
|
785 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
786 |
@CallerSensitive |
2 | 787 |
public void load(String filename) { |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
788 |
load0(Reflection.getCallerClass(), filename); |
2 | 789 |
} |
790 |
||
11117
b6e68b1344d4
7116404: Miscellaneous warnings (java.rmi.**, serialization, some core classes)
alanb
parents:
9500
diff
changeset
|
791 |
synchronized void load0(Class<?> fromClass, String filename) { |
2 | 792 |
SecurityManager security = System.getSecurityManager(); |
793 |
if (security != null) { |
|
794 |
security.checkLink(filename); |
|
795 |
} |
|
796 |
if (!(new File(filename).isAbsolute())) { |
|
797 |
throw new UnsatisfiedLinkError( |
|
798 |
"Expecting an absolute path of the library: " + filename); |
|
799 |
} |
|
800 |
ClassLoader.loadLibrary(fromClass, filename, true); |
|
801 |
} |
|
802 |
||
803 |
/** |
|
30042 | 804 |
* Loads the native library specified by the {@code libname} |
805 |
* 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
|
806 |
* specific prefix, file extension or path. If a native library |
30042 | 807 |
* called {@code libname} is statically linked with the VM, then the |
808 |
* JNI_OnLoad_{@code libname} function exported by the library is invoked. |
|
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
809 |
* See the JNI Specification for more details. |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
810 |
* |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
811 |
* 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
|
812 |
* 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
|
813 |
* dependent manner. |
2 | 814 |
* <p> |
30042 | 815 |
* First, if there is a security manager, its {@code checkLink} |
816 |
* method is called with the {@code libname} as its argument. |
|
2 | 817 |
* This may result in a security exception. |
818 |
* <p> |
|
819 |
* The method {@link System#loadLibrary(String)} is the conventional |
|
820 |
* and convenient means of invoking this method. If native |
|
821 |
* methods are to be used in the implementation of a class, a standard |
|
822 |
* strategy is to put the native code in a library file (call it |
|
30042 | 823 |
* {@code LibFile}) and then to put a static initializer: |
2 | 824 |
* <blockquote><pre> |
825 |
* static { System.loadLibrary("LibFile"); } |
|
826 |
* </pre></blockquote> |
|
827 |
* within the class declaration. When the class is loaded and |
|
828 |
* initialized, the necessary native code implementation for the native |
|
829 |
* methods will then be loaded as well. |
|
830 |
* <p> |
|
831 |
* If this method is called more than once with the same library |
|
832 |
* name, the second and subsequent calls are ignored. |
|
833 |
* |
|
834 |
* @param libname the name of the library. |
|
835 |
* @exception SecurityException if a security manager exists and its |
|
30042 | 836 |
* {@code checkLink} method doesn't allow |
2 | 837 |
* loading of the specified dynamic library |
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
838 |
* @exception UnsatisfiedLinkError if either the libname argument |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
839 |
* 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
|
840 |
* 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
|
841 |
* native library image by the host system. |
30042 | 842 |
* @exception NullPointerException if {@code libname} is |
843 |
* {@code null} |
|
2 | 844 |
* @see java.lang.SecurityException |
845 |
* @see java.lang.SecurityManager#checkLink(java.lang.String) |
|
846 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
847 |
@CallerSensitive |
2 | 848 |
public void loadLibrary(String libname) { |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
849 |
loadLibrary0(Reflection.getCallerClass(), libname); |
2 | 850 |
} |
851 |
||
11117
b6e68b1344d4
7116404: Miscellaneous warnings (java.rmi.**, serialization, some core classes)
alanb
parents:
9500
diff
changeset
|
852 |
synchronized void loadLibrary0(Class<?> fromClass, String libname) { |
2 | 853 |
SecurityManager security = System.getSecurityManager(); |
854 |
if (security != null) { |
|
855 |
security.checkLink(libname); |
|
856 |
} |
|
857 |
if (libname.indexOf((int)File.separatorChar) != -1) { |
|
858 |
throw new UnsatisfiedLinkError( |
|
859 |
"Directory separator should not appear in library name: " + libname); |
|
860 |
} |
|
861 |
ClassLoader.loadLibrary(fromClass, libname, false); |
|
862 |
} |
|
863 |
||
864 |
/** |
|
865 |
* Creates a localized version of an input stream. This method takes |
|
30042 | 866 |
* an {@code InputStream} and returns an {@code InputStream} |
2 | 867 |
* equivalent to the argument in all respects except that it is |
868 |
* localized: as characters in the local character set are read from |
|
869 |
* the stream, they are automatically converted from the local |
|
870 |
* character set to Unicode. |
|
871 |
* <p> |
|
872 |
* If the argument is already a localized stream, it may be returned |
|
873 |
* as the result. |
|
874 |
* |
|
875 |
* @param in InputStream to localize |
|
876 |
* @return a localized input stream |
|
877 |
* @see java.io.InputStream |
|
878 |
* @see java.io.BufferedReader#BufferedReader(java.io.Reader) |
|
879 |
* @see java.io.InputStreamReader#InputStreamReader(java.io.InputStream) |
|
880 |
* @deprecated As of JDK 1.1, the preferred way to translate a byte |
|
881 |
* stream in the local encoding into a character stream in Unicode is via |
|
30042 | 882 |
* the {@code InputStreamReader} and {@code BufferedReader} |
2 | 883 |
* classes. |
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
37363
diff
changeset
|
884 |
* This method is subject to removal in a future version of Java SE. |
2 | 885 |
*/ |
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
37363
diff
changeset
|
886 |
@Deprecated(since="1.1", forRemoval=true) |
2 | 887 |
public InputStream getLocalizedInputStream(InputStream in) { |
888 |
return in; |
|
889 |
} |
|
890 |
||
891 |
/** |
|
892 |
* Creates a localized version of an output stream. This method |
|
30042 | 893 |
* takes an {@code OutputStream} and returns an |
894 |
* {@code OutputStream} equivalent to the argument in all respects |
|
2 | 895 |
* except that it is localized: as Unicode characters are written to |
896 |
* the stream, they are automatically converted to the local |
|
897 |
* character set. |
|
898 |
* <p> |
|
899 |
* If the argument is already a localized stream, it may be returned |
|
900 |
* as the result. |
|
901 |
* |
|
902 |
* @deprecated As of JDK 1.1, the preferred way to translate a |
|
903 |
* Unicode character stream into a byte stream in the local encoding is via |
|
30042 | 904 |
* the {@code OutputStreamWriter}, {@code BufferedWriter}, and |
905 |
* {@code PrintWriter} classes. |
|
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
37363
diff
changeset
|
906 |
* This method is subject to removal in a future version of Java SE. |
2 | 907 |
* |
908 |
* @param out OutputStream to localize |
|
909 |
* @return a localized output stream |
|
910 |
* @see java.io.OutputStream |
|
911 |
* @see java.io.BufferedWriter#BufferedWriter(java.io.Writer) |
|
912 |
* @see java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream) |
|
913 |
* @see java.io.PrintWriter#PrintWriter(java.io.OutputStream) |
|
914 |
*/ |
|
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
37363
diff
changeset
|
915 |
@Deprecated(since="1.1", forRemoval=true) |
2 | 916 |
public OutputStream getLocalizedOutputStream(OutputStream out) { |
917 |
return out; |
|
918 |
} |
|
919 |
||
920 |
} |