1 /* 2 * Copyright (c) 1994, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 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 * 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. 24 */ 25 package java.lang; 26 27 import java.io.*; 28 import java.lang.reflect.Executable; 29 import java.lang.annotation.Annotation; 30 import java.security.AccessControlContext; 31 import java.util.Properties; 32 import java.util.PropertyPermission; 33 import java.util.Map; 34 import java.security.AccessController; 35 import java.security.PrivilegedAction; 36 import java.nio.channels.Channel; 37 import java.nio.channels.spi.SelectorProvider; 38 import java.util.Objects; 39 import java.util.ResourceBundle; 40 import java.util.function.Supplier; 41 import sun.nio.ch.Interruptible; 42 import sun.reflect.CallerSensitive; 43 import sun.reflect.Reflection; 44 import sun.security.util.SecurityConstants; 45 import sun.reflect.annotation.AnnotationType; 46 import jdk.internal.HotSpotIntrinsicCandidate; 47 import jdk.internal.misc.JavaLangAccess;; 48 import jdk.internal.misc.SharedSecrets;; 49 import jdk.internal.misc.VM; 50 import jdk.internal.logger.LoggerFinderLoader; 51 import jdk.internal.logger.LazyLoggers; 52 import jdk.internal.logger.LocalizedLoggerWrapper; 53 54 /** 55 * The <code>System</code> class contains several useful class fields 56 * and methods. It cannot be instantiated. 57 * 58 * <p>Among the facilities provided by the <code>System</code> class 59 * are standard input, standard output, and error output streams; 60 * access to externally defined properties and environment 61 * variables; a means of loading files and libraries; and a utility 62 * method for quickly copying a portion of an array. 63 * 64 * @author unascribed 65 * @since 1.0 66 */ 67 public final class System { 68 69 /* register the natives via the static initializer. 70 * 71 * VM will invoke the initializeSystemClass method to complete 72 * the initialization for this class separated from clinit. 73 * Note that to use properties set by the VM, see the constraints 74 * described in the initializeSystemClass method. 75 */ 76 private static native void registerNatives(); 77 static { 78 registerNatives(); 79 } 80 81 /** Don't let anyone instantiate this class */ 82 private System() { 83 } 84 85 /** 86 * The "standard" input stream. This stream is already 87 * open and ready to supply input data. Typically this stream 88 * corresponds to keyboard input or another input source specified by 89 * the host environment or user. 90 */ 91 public static final InputStream in = null; 92 93 /** 94 * The "standard" output stream. This stream is already 95 * open and ready to accept output data. Typically this stream 96 * corresponds to display output or another output destination 97 * specified by the host environment or user. 98 * <p> 99 * For simple stand-alone Java applications, a typical way to write 100 * a line of output data is: 101 * <blockquote><pre> 102 * System.out.println(data) 103 * </pre></blockquote> 104 * <p> 105 * See the <code>println</code> methods in class <code>PrintStream</code>. 106 * 107 * @see java.io.PrintStream#println() 108 * @see java.io.PrintStream#println(boolean) 109 * @see java.io.PrintStream#println(char) 110 * @see java.io.PrintStream#println(char[]) 111 * @see java.io.PrintStream#println(double) 112 * @see java.io.PrintStream#println(float) 113 * @see java.io.PrintStream#println(int) 114 * @see java.io.PrintStream#println(long) 115 * @see java.io.PrintStream#println(java.lang.Object) 116 * @see java.io.PrintStream#println(java.lang.String) 117 */ 118 public static final PrintStream out = null; 119 120 /** 121 * The "standard" error output stream. This stream is already 122 * open and ready to accept output data. 123 * <p> 124 * Typically this stream corresponds to display output or another 125 * output destination specified by the host environment or user. By 126 * convention, this output stream is used to display error messages 127 * or other information that should come to the immediate attention 128 * of a user even if the principal output stream, the value of the 129 * variable <code>out</code>, has been redirected to a file or other 130 * destination that is typically not continuously monitored. 131 */ 132 public static final PrintStream err = null; 133 134 /* The security manager for the system. 135 */ 136 private static volatile SecurityManager security; 137 138 /** 139 * Reassigns the "standard" input stream. 140 * 141 * <p>First, if there is a security manager, its <code>checkPermission</code> 142 * method is called with a <code>RuntimePermission("setIO")</code> permission 143 * to see if it's ok to reassign the "standard" input stream. 144 * 145 * @param in the new standard input stream. 146 * 147 * @throws SecurityException 148 * if a security manager exists and its 149 * <code>checkPermission</code> method doesn't allow 150 * reassigning of the standard input stream. 151 * 152 * @see SecurityManager#checkPermission 153 * @see java.lang.RuntimePermission 154 * 155 * @since 1.1 156 */ 157 public static void setIn(InputStream in) { 158 checkIO(); 159 setIn0(in); 160 } 161 162 /** 163 * Reassigns the "standard" output stream. 164 * 165 * <p>First, if there is a security manager, its <code>checkPermission</code> 166 * method is called with a <code>RuntimePermission("setIO")</code> permission 167 * to see if it's ok to reassign the "standard" output stream. 168 * 169 * @param out the new standard output stream 170 * 171 * @throws SecurityException 172 * if a security manager exists and its 173 * <code>checkPermission</code> method doesn't allow 174 * reassigning of the standard output stream. 175 * 176 * @see SecurityManager#checkPermission 177 * @see java.lang.RuntimePermission 178 * 179 * @since 1.1 180 */ 181 public static void setOut(PrintStream out) { 182 checkIO(); 183 setOut0(out); 184 } 185 186 /** 187 * Reassigns the "standard" error output stream. 188 * 189 * <p>First, if there is a security manager, its <code>checkPermission</code> 190 * method is called with a <code>RuntimePermission("setIO")</code> permission 191 * to see if it's ok to reassign the "standard" error output stream. 192 * 193 * @param err the new standard error output stream. 194 * 195 * @throws SecurityException 196 * if a security manager exists and its 197 * <code>checkPermission</code> method doesn't allow 198 * reassigning of the standard error output stream. 199 * 200 * @see SecurityManager#checkPermission 201 * @see java.lang.RuntimePermission 202 * 203 * @since 1.1 204 */ 205 public static void setErr(PrintStream err) { 206 checkIO(); 207 setErr0(err); 208 } 209 210 private static volatile Console cons; 211 /** 212 * Returns the unique {@link java.io.Console Console} object associated 213 * with the current Java virtual machine, if any. 214 * 215 * @return The system console, if any, otherwise {@code null}. 216 * 217 * @since 1.6 218 */ 219 public static Console console() { 220 Console c = cons; 221 if (c == null) { 222 synchronized (System.class) { 223 cons = c = SharedSecrets.getJavaIOAccess().console(); 224 } 225 } 226 return c; 227 } 228 229 /** 230 * Returns the channel inherited from the entity that created this 231 * Java virtual machine. 232 * 233 * <p> This method returns the channel obtained by invoking the 234 * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel 235 * inheritedChannel} method of the system-wide default 236 * {@link java.nio.channels.spi.SelectorProvider} object. </p> 237 * 238 * <p> In addition to the network-oriented channels described in 239 * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel 240 * inheritedChannel}, this method may return other kinds of 241 * channels in the future. 242 * 243 * @return The inherited channel, if any, otherwise {@code null}. 244 * 245 * @throws IOException 246 * If an I/O error occurs 247 * 248 * @throws SecurityException 249 * If a security manager is present and it does not 250 * permit access to the channel. 251 * 252 * @since 1.5 253 */ 254 public static Channel inheritedChannel() throws IOException { 255 return SelectorProvider.provider().inheritedChannel(); 256 } 257 258 private static void checkIO() { 259 SecurityManager sm = getSecurityManager(); 260 if (sm != null) { 261 sm.checkPermission(new RuntimePermission("setIO")); 262 } 263 } 264 265 private static native void setIn0(InputStream in); 266 private static native void setOut0(PrintStream out); 267 private static native void setErr0(PrintStream err); 268 269 /** 270 * Sets the System security. 271 * 272 * <p> If there is a security manager already installed, this method first 273 * calls the security manager's <code>checkPermission</code> method 274 * with a <code>RuntimePermission("setSecurityManager")</code> 275 * permission to ensure it's ok to replace the existing 276 * security manager. 277 * This may result in throwing a <code>SecurityException</code>. 278 * 279 * <p> Otherwise, the argument is established as the current 280 * security manager. If the argument is <code>null</code> and no 281 * security manager has been established, then no action is taken and 282 * the method simply returns. 283 * 284 * @param s the security manager. 285 * @exception SecurityException if the security manager has already 286 * been set and its <code>checkPermission</code> method 287 * doesn't allow it to be replaced. 288 * @see #getSecurityManager 289 * @see SecurityManager#checkPermission 290 * @see java.lang.RuntimePermission 291 */ 292 public static 293 void setSecurityManager(final SecurityManager s) { 294 try { 295 s.checkPackageAccess("java.lang"); 296 } catch (Exception e) { 297 // no-op 298 } 299 setSecurityManager0(s); 300 } 301 302 private static synchronized 303 void setSecurityManager0(final SecurityManager s) { 304 SecurityManager sm = getSecurityManager(); 305 if (sm != null) { 306 // ask the currently installed security manager if we 307 // can replace it. 308 sm.checkPermission(new RuntimePermission 309 ("setSecurityManager")); 310 } 311 312 if ((s != null) && (s.getClass().getClassLoader() != null)) { 313 // New security manager class is not on bootstrap classpath. 314 // Cause policy to get initialized before we install the new 315 // security manager, in order to prevent infinite loops when 316 // trying to initialize the policy (which usually involves 317 // accessing some security and/or system properties, which in turn 318 // calls the installed security manager's checkPermission method 319 // which will loop infinitely if there is a non-system class 320 // (in this case: the new security manager class) on the stack). 321 AccessController.doPrivileged(new PrivilegedAction<>() { 322 public Object run() { 323 s.getClass().getProtectionDomain().implies 324 (SecurityConstants.ALL_PERMISSION); 325 return null; 326 } 327 }); 328 } 329 330 security = s; 331 } 332 333 /** 334 * Gets the system security interface. 335 * 336 * @return if a security manager has already been established for the 337 * current application, then that security manager is returned; 338 * otherwise, <code>null</code> is returned. 339 * @see #setSecurityManager 340 */ 341 public static SecurityManager getSecurityManager() { 342 return security; 343 } 344 345 /** 346 * Returns the current time in milliseconds. Note that 347 * while the unit of time of the return value is a millisecond, 348 * the granularity of the value depends on the underlying 349 * operating system and may be larger. For example, many 350 * operating systems measure time in units of tens of 351 * milliseconds. 352 * 353 * <p> See the description of the class <code>Date</code> for 354 * a discussion of slight discrepancies that may arise between 355 * "computer time" and coordinated universal time (UTC). 356 * 357 * @return the difference, measured in milliseconds, between 358 * the current time and midnight, January 1, 1970 UTC. 359 * @see java.util.Date 360 */ 361 @HotSpotIntrinsicCandidate 362 public static native long currentTimeMillis(); 363 364 /** 365 * Returns the current value of the running Java Virtual Machine's 366 * high-resolution time source, in nanoseconds. 367 * 368 * <p>This method can only be used to measure elapsed time and is 369 * not related to any other notion of system or wall-clock time. 370 * The value returned represents nanoseconds since some fixed but 371 * arbitrary <i>origin</i> time (perhaps in the future, so values 372 * may be negative). The same origin is used by all invocations of 373 * this method in an instance of a Java virtual machine; other 374 * virtual machine instances are likely to use a different origin. 375 * 376 * <p>This method provides nanosecond precision, but not necessarily 377 * nanosecond resolution (that is, how frequently the value changes) 378 * - no guarantees are made except that the resolution is at least as 379 * good as that of {@link #currentTimeMillis()}. 380 * 381 * <p>Differences in successive calls that span greater than 382 * approximately 292 years (2<sup>63</sup> nanoseconds) will not 383 * correctly compute elapsed time due to numerical overflow. 384 * 385 * <p>The values returned by this method become meaningful only when 386 * the difference between two such values, obtained within the same 387 * instance of a Java virtual machine, is computed. 388 * 389 * <p>For example, to measure how long some code takes to execute: 390 * <pre> {@code 391 * long startTime = System.nanoTime(); 392 * // ... the code being measured ... 393 * long elapsedNanos = System.nanoTime() - startTime;}</pre> 394 * 395 * <p>To compare elapsed time against a timeout, use <pre> {@code 396 * if (System.nanoTime() - startTime >= timeoutNanos) ...}</pre> 397 * instead of <pre> {@code 398 * if (System.nanoTime() >= startTime + timeoutNanos) ...}</pre> 399 * because of the possibility of numerical overflow. 400 * 401 * @return the current value of the running Java Virtual Machine's 402 * high-resolution time source, in nanoseconds 403 * @since 1.5 404 */ 405 @HotSpotIntrinsicCandidate 406 public static native long nanoTime(); 407 408 /** 409 * Copies an array from the specified source array, beginning at the 410 * specified position, to the specified position of the destination array. 411 * A subsequence of array components are copied from the source 412 * array referenced by <code>src</code> to the destination array 413 * referenced by <code>dest</code>. The number of components copied is 414 * equal to the <code>length</code> argument. The components at 415 * positions <code>srcPos</code> through 416 * <code>srcPos+length-1</code> in the source array are copied into 417 * positions <code>destPos</code> through 418 * <code>destPos+length-1</code>, respectively, of the destination 419 * array. 420 * <p> 421 * If the <code>src</code> and <code>dest</code> arguments refer to the 422 * same array object, then the copying is performed as if the 423 * components at positions <code>srcPos</code> through 424 * <code>srcPos+length-1</code> were first copied to a temporary 425 * array with <code>length</code> components and then the contents of 426 * the temporary array were copied into positions 427 * <code>destPos</code> through <code>destPos+length-1</code> of the 428 * destination array. 429 * <p> 430 * If <code>dest</code> is <code>null</code>, then a 431 * <code>NullPointerException</code> is thrown. 432 * <p> 433 * If <code>src</code> is <code>null</code>, then a 434 * <code>NullPointerException</code> is thrown and the destination 435 * array is not modified. 436 * <p> 437 * Otherwise, if any of the following is true, an 438 * <code>ArrayStoreException</code> is thrown and the destination is 439 * not modified: 440 * <ul> 441 * <li>The <code>src</code> argument refers to an object that is not an 442 * array. 443 * <li>The <code>dest</code> argument refers to an object that is not an 444 * array. 445 * <li>The <code>src</code> argument and <code>dest</code> argument refer 446 * to arrays whose component types are different primitive types. 447 * <li>The <code>src</code> argument refers to an array with a primitive 448 * component type and the <code>dest</code> argument refers to an array 449 * with a reference component type. 450 * <li>The <code>src</code> argument refers to an array with a reference 451 * component type and the <code>dest</code> argument refers to an array 452 * with a primitive component type. 453 * </ul> 454 * <p> 455 * Otherwise, if any of the following is true, an 456 * <code>IndexOutOfBoundsException</code> is 457 * thrown and the destination is not modified: 458 * <ul> 459 * <li>The <code>srcPos</code> argument is negative. 460 * <li>The <code>destPos</code> argument is negative. 461 * <li>The <code>length</code> argument is negative. 462 * <li><code>srcPos+length</code> is greater than 463 * <code>src.length</code>, the length of the source array. 464 * <li><code>destPos+length</code> is greater than 465 * <code>dest.length</code>, the length of the destination array. 466 * </ul> 467 * <p> 468 * Otherwise, if any actual component of the source array from 469 * position <code>srcPos</code> through 470 * <code>srcPos+length-1</code> cannot be converted to the component 471 * type of the destination array by assignment conversion, an 472 * <code>ArrayStoreException</code> is thrown. In this case, let 473 * <b><i>k</i></b> be the smallest nonnegative integer less than 474 * length such that <code>src[srcPos+</code><i>k</i><code>]</code> 475 * cannot be converted to the component type of the destination 476 * array; when the exception is thrown, source array components from 477 * positions <code>srcPos</code> through 478 * <code>srcPos+</code><i>k</i><code>-1</code> 479 * will already have been copied to destination array positions 480 * <code>destPos</code> through 481 * <code>destPos+</code><i>k</I><code>-1</code> and no other 482 * positions of the destination array will have been modified. 483 * (Because of the restrictions already itemized, this 484 * paragraph effectively applies only to the situation where both 485 * arrays have component types that are reference types.) 486 * 487 * @param src the source array. 488 * @param srcPos starting position in the source array. 489 * @param dest the destination array. 490 * @param destPos starting position in the destination data. 491 * @param length the number of array elements to be copied. 492 * @exception IndexOutOfBoundsException if copying would cause 493 * access of data outside array bounds. 494 * @exception ArrayStoreException if an element in the <code>src</code> 495 * array could not be stored into the <code>dest</code> array 496 * because of a type mismatch. 497 * @exception NullPointerException if either <code>src</code> or 498 * <code>dest</code> is <code>null</code>. 499 */ 500 @HotSpotIntrinsicCandidate 501 public static native void arraycopy(Object src, int srcPos, 502 Object dest, int destPos, 503 int length); 504 505 /** 506 * Returns the same hash code for the given object as 507 * would be returned by the default method hashCode(), 508 * whether or not the given object's class overrides 509 * hashCode(). 510 * The hash code for the null reference is zero. 511 * 512 * @param x object for which the hashCode is to be calculated 513 * @return the hashCode 514 * @since 1.1 515 */ 516 @HotSpotIntrinsicCandidate 517 public static native int identityHashCode(Object x); 518 519 /** 520 * System properties. The following properties are guaranteed to be defined: 521 * <dl> 522 * <dt>java.version <dd>Java version number 523 * <dt>java.vendor <dd>Java vendor specific string 524 * <dt>java.vendor.url <dd>Java vendor URL 525 * <dt>java.home <dd>Java installation directory 526 * <dt>java.class.version <dd>Java class version number 527 * <dt>java.class.path <dd>Java classpath 528 * <dt>os.name <dd>Operating System Name 529 * <dt>os.arch <dd>Operating System Architecture 530 * <dt>os.version <dd>Operating System Version 531 * <dt>file.separator <dd>File separator ("/" on Unix) 532 * <dt>path.separator <dd>Path separator (":" on Unix) 533 * <dt>line.separator <dd>Line separator ("\n" on Unix) 534 * <dt>user.name <dd>User account name 535 * <dt>user.home <dd>User home directory 536 * <dt>user.dir <dd>User's current working directory 537 * </dl> 538 */ 539 540 private static Properties props; 541 private static native Properties initProperties(Properties props); 542 543 /** 544 * Determines the current system properties. 545 * <p> 546 * First, if there is a security manager, its 547 * <code>checkPropertiesAccess</code> method is called with no 548 * arguments. This may result in a security exception. 549 * <p> 550 * The current set of system properties for use by the 551 * {@link #getProperty(String)} method is returned as a 552 * <code>Properties</code> object. If there is no current set of 553 * system properties, a set of system properties is first created and 554 * initialized. This set of system properties always includes values 555 * for the following keys: 556 * <table summary="Shows property keys and associated values"> 557 * <tr><th>Key</th> 558 * <th>Description of Associated Value</th></tr> 559 * <tr><td><code>java.version</code></td> 560 * <td>Java Runtime Environment version</td></tr> 561 * <tr><td><code>java.vendor</code></td> 562 * <td>Java Runtime Environment vendor</td></tr> 563 * <tr><td><code>java.vendor.url</code></td> 564 * <td>Java vendor URL</td></tr> 565 * <tr><td><code>java.home</code></td> 566 * <td>Java installation directory</td></tr> 567 * <tr><td><code>java.vm.specification.version</code></td> 568 * <td>Java Virtual Machine specification version</td></tr> 569 * <tr><td><code>java.vm.specification.vendor</code></td> 570 * <td>Java Virtual Machine specification vendor</td></tr> 571 * <tr><td><code>java.vm.specification.name</code></td> 572 * <td>Java Virtual Machine specification name</td></tr> 573 * <tr><td><code>java.vm.version</code></td> 574 * <td>Java Virtual Machine implementation version</td></tr> 575 * <tr><td><code>java.vm.vendor</code></td> 576 * <td>Java Virtual Machine implementation vendor</td></tr> 577 * <tr><td><code>java.vm.name</code></td> 578 * <td>Java Virtual Machine implementation name</td></tr> 579 * <tr><td><code>java.specification.version</code></td> 580 * <td>Java Runtime Environment specification version</td></tr> 581 * <tr><td><code>java.specification.vendor</code></td> 582 * <td>Java Runtime Environment specification vendor</td></tr> 583 * <tr><td><code>java.specification.name</code></td> 584 * <td>Java Runtime Environment specification name</td></tr> 585 * <tr><td><code>java.class.version</code></td> 586 * <td>Java class format version number</td></tr> 587 * <tr><td><code>java.class.path</code></td> 588 * <td>Java class path</td></tr> 589 * <tr><td><code>java.library.path</code></td> 590 * <td>List of paths to search when loading libraries</td></tr> 591 * <tr><td><code>java.io.tmpdir</code></td> 592 * <td>Default temp file path</td></tr> 593 * <tr><td><code>java.compiler</code></td> 594 * <td>Name of JIT compiler to use</td></tr> 595 * <tr><td><code>os.name</code></td> 596 * <td>Operating system name</td></tr> 597 * <tr><td><code>os.arch</code></td> 598 * <td>Operating system architecture</td></tr> 599 * <tr><td><code>os.version</code></td> 600 * <td>Operating system version</td></tr> 601 * <tr><td><code>file.separator</code></td> 602 * <td>File separator ("/" on UNIX)</td></tr> 603 * <tr><td><code>path.separator</code></td> 604 * <td>Path separator (":" on UNIX)</td></tr> 605 * <tr><td><code>line.separator</code></td> 606 * <td>Line separator ("\n" on UNIX)</td></tr> 607 * <tr><td><code>user.name</code></td> 608 * <td>User's account name</td></tr> 609 * <tr><td><code>user.home</code></td> 610 * <td>User's home directory</td></tr> 611 * <tr><td><code>user.dir</code></td> 612 * <td>User's current working directory</td></tr> 613 * </table> 614 * <p> 615 * Multiple paths in a system property value are separated by the path 616 * separator character of the platform. 617 * <p> 618 * Note that even if the security manager does not permit the 619 * <code>getProperties</code> operation, it may choose to permit the 620 * {@link #getProperty(String)} operation. 621 * 622 * @return the system properties 623 * @exception SecurityException if a security manager exists and its 624 * <code>checkPropertiesAccess</code> method doesn't allow access 625 * to the system properties. 626 * @see #setProperties 627 * @see java.lang.SecurityException 628 * @see java.lang.SecurityManager#checkPropertiesAccess() 629 * @see java.util.Properties 630 */ 631 public static Properties getProperties() { 632 SecurityManager sm = getSecurityManager(); 633 if (sm != null) { 634 sm.checkPropertiesAccess(); 635 } 636 637 return props; 638 } 639 640 /** 641 * Returns the system-dependent line separator string. It always 642 * returns the same value - the initial value of the {@linkplain 643 * #getProperty(String) system property} {@code line.separator}. 644 * 645 * <p>On UNIX systems, it returns {@code "\n"}; on Microsoft 646 * Windows systems it returns {@code "\r\n"}. 647 * 648 * @return the system-dependent line separator string 649 * @since 1.7 650 */ 651 public static String lineSeparator() { 652 return lineSeparator; 653 } 654 655 private static String lineSeparator; 656 657 /** 658 * Sets the system properties to the <code>Properties</code> 659 * argument. 660 * <p> 661 * First, if there is a security manager, its 662 * <code>checkPropertiesAccess</code> method is called with no 663 * arguments. This may result in a security exception. 664 * <p> 665 * The argument becomes the current set of system properties for use 666 * by the {@link #getProperty(String)} method. If the argument is 667 * <code>null</code>, then the current set of system properties is 668 * forgotten. 669 * 670 * @param props the new system properties. 671 * @exception SecurityException if a security manager exists and its 672 * <code>checkPropertiesAccess</code> method doesn't allow access 673 * to the system properties. 674 * @see #getProperties 675 * @see java.util.Properties 676 * @see java.lang.SecurityException 677 * @see java.lang.SecurityManager#checkPropertiesAccess() 678 */ 679 public static void setProperties(Properties props) { 680 SecurityManager sm = getSecurityManager(); 681 if (sm != null) { 682 sm.checkPropertiesAccess(); 683 } 684 if (props == null) { 685 props = new Properties(); 686 initProperties(props); 687 } 688 System.props = props; 689 } 690 691 /** 692 * Gets the system property indicated by the specified key. 693 * <p> 694 * First, if there is a security manager, its 695 * <code>checkPropertyAccess</code> method is called with the key as 696 * its argument. This may result in a SecurityException. 697 * <p> 698 * If there is no current set of system properties, a set of system 699 * properties is first created and initialized in the same manner as 700 * for the <code>getProperties</code> method. 701 * 702 * @param key the name of the system property. 703 * @return the string value of the system property, 704 * or <code>null</code> if there is no property with that key. 705 * 706 * @exception SecurityException if a security manager exists and its 707 * <code>checkPropertyAccess</code> method doesn't allow 708 * access to the specified system property. 709 * @exception NullPointerException if <code>key</code> is 710 * <code>null</code>. 711 * @exception IllegalArgumentException if <code>key</code> is empty. 712 * @see #setProperty 713 * @see java.lang.SecurityException 714 * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String) 715 * @see java.lang.System#getProperties() 716 */ 717 public static String getProperty(String key) { 718 checkKey(key); 719 SecurityManager sm = getSecurityManager(); 720 if (sm != null) { 721 sm.checkPropertyAccess(key); 722 } 723 724 return props.getProperty(key); 725 } 726 727 /** 728 * Gets the system property indicated by the specified key. 729 * <p> 730 * First, if there is a security manager, its 731 * <code>checkPropertyAccess</code> method is called with the 732 * <code>key</code> as its argument. 733 * <p> 734 * If there is no current set of system properties, a set of system 735 * properties is first created and initialized in the same manner as 736 * for the <code>getProperties</code> method. 737 * 738 * @param key the name of the system property. 739 * @param def a default value. 740 * @return the string value of the system property, 741 * or the default value if there is no property with that key. 742 * 743 * @exception SecurityException if a security manager exists and its 744 * <code>checkPropertyAccess</code> method doesn't allow 745 * access to the specified system property. 746 * @exception NullPointerException if <code>key</code> is 747 * <code>null</code>. 748 * @exception IllegalArgumentException if <code>key</code> is empty. 749 * @see #setProperty 750 * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String) 751 * @see java.lang.System#getProperties() 752 */ 753 public static String getProperty(String key, String def) { 754 checkKey(key); 755 SecurityManager sm = getSecurityManager(); 756 if (sm != null) { 757 sm.checkPropertyAccess(key); 758 } 759 760 return props.getProperty(key, def); 761 } 762 763 /** 764 * Sets the system property indicated by the specified key. 765 * <p> 766 * First, if a security manager exists, its 767 * <code>SecurityManager.checkPermission</code> method 768 * is called with a <code>PropertyPermission(key, "write")</code> 769 * permission. This may result in a SecurityException being thrown. 770 * If no exception is thrown, the specified property is set to the given 771 * value. 772 * 773 * @param key the name of the system property. 774 * @param value the value of the system property. 775 * @return the previous value of the system property, 776 * or <code>null</code> if it did not have one. 777 * 778 * @exception SecurityException if a security manager exists and its 779 * <code>checkPermission</code> method doesn't allow 780 * setting of the specified property. 781 * @exception NullPointerException if <code>key</code> or 782 * <code>value</code> is <code>null</code>. 783 * @exception IllegalArgumentException if <code>key</code> is empty. 784 * @see #getProperty 785 * @see java.lang.System#getProperty(java.lang.String) 786 * @see java.lang.System#getProperty(java.lang.String, java.lang.String) 787 * @see java.util.PropertyPermission 788 * @see SecurityManager#checkPermission 789 * @since 1.2 790 */ 791 public static String setProperty(String key, String value) { 792 checkKey(key); 793 SecurityManager sm = getSecurityManager(); 794 if (sm != null) { 795 sm.checkPermission(new PropertyPermission(key, 796 SecurityConstants.PROPERTY_WRITE_ACTION)); 797 } 798 799 return (String) props.setProperty(key, value); 800 } 801 802 /** 803 * Removes the system property indicated by the specified key. 804 * <p> 805 * First, if a security manager exists, its 806 * <code>SecurityManager.checkPermission</code> method 807 * is called with a <code>PropertyPermission(key, "write")</code> 808 * permission. This may result in a SecurityException being thrown. 809 * If no exception is thrown, the specified property is removed. 810 * 811 * @param key the name of the system property to be removed. 812 * @return the previous string value of the system property, 813 * or <code>null</code> if there was no property with that key. 814 * 815 * @exception SecurityException if a security manager exists and its 816 * <code>checkPropertyAccess</code> method doesn't allow 817 * access to the specified system property. 818 * @exception NullPointerException if <code>key</code> is 819 * <code>null</code>. 820 * @exception IllegalArgumentException if <code>key</code> is empty. 821 * @see #getProperty 822 * @see #setProperty 823 * @see java.util.Properties 824 * @see java.lang.SecurityException 825 * @see java.lang.SecurityManager#checkPropertiesAccess() 826 * @since 1.5 827 */ 828 public static String clearProperty(String key) { 829 checkKey(key); 830 SecurityManager sm = getSecurityManager(); 831 if (sm != null) { 832 sm.checkPermission(new PropertyPermission(key, "write")); 833 } 834 835 return (String) props.remove(key); 836 } 837 838 private static void checkKey(String key) { 839 if (key == null) { 840 throw new NullPointerException("key can't be null"); 841 } 842 if (key.equals("")) { 843 throw new IllegalArgumentException("key can't be empty"); 844 } 845 } 846 847 /** 848 * Gets the value of the specified environment variable. An 849 * environment variable is a system-dependent external named 850 * value. 851 * 852 * <p>If a security manager exists, its 853 * {@link SecurityManager#checkPermission checkPermission} 854 * method is called with a 855 * <code>{@link RuntimePermission}("getenv."+name)</code> 856 * permission. This may result in a {@link SecurityException} 857 * being thrown. If no exception is thrown the value of the 858 * variable <code>name</code> is returned. 859 * 860 * <p><a name="EnvironmentVSSystemProperties"><i>System 861 * properties</i> and <i>environment variables</i></a> are both 862 * conceptually mappings between names and values. Both 863 * mechanisms can be used to pass user-defined information to a 864 * Java process. Environment variables have a more global effect, 865 * because they are visible to all descendants of the process 866 * which defines them, not just the immediate Java subprocess. 867 * They can have subtly different semantics, such as case 868 * insensitivity, on different operating systems. For these 869 * reasons, environment variables are more likely to have 870 * unintended side effects. It is best to use system properties 871 * where possible. Environment variables should be used when a 872 * global effect is desired, or when an external system interface 873 * requires an environment variable (such as <code>PATH</code>). 874 * 875 * <p>On UNIX systems the alphabetic case of <code>name</code> is 876 * typically significant, while on Microsoft Windows systems it is 877 * typically not. For example, the expression 878 * <code>System.getenv("FOO").equals(System.getenv("foo"))</code> 879 * is likely to be true on Microsoft Windows. 880 * 881 * @param name the name of the environment variable 882 * @return the string value of the variable, or <code>null</code> 883 * if the variable is not defined in the system environment 884 * @throws NullPointerException if <code>name</code> is <code>null</code> 885 * @throws SecurityException 886 * if a security manager exists and its 887 * {@link SecurityManager#checkPermission checkPermission} 888 * method doesn't allow access to the environment variable 889 * <code>name</code> 890 * @see #getenv() 891 * @see ProcessBuilder#environment() 892 */ 893 public static String getenv(String name) { 894 SecurityManager sm = getSecurityManager(); 895 if (sm != null) { 896 sm.checkPermission(new RuntimePermission("getenv."+name)); 897 } 898 899 return ProcessEnvironment.getenv(name); 900 } 901 902 903 /** 904 * Returns an unmodifiable string map view of the current system environment. 905 * The environment is a system-dependent mapping from names to 906 * values which is passed from parent to child processes. 907 * 908 * <p>If the system does not support environment variables, an 909 * empty map is returned. 910 * 911 * <p>The returned map will never contain null keys or values. 912 * Attempting to query the presence of a null key or value will 913 * throw a {@link NullPointerException}. Attempting to query 914 * the presence of a key or value which is not of type 915 * {@link String} will throw a {@link ClassCastException}. 916 * 917 * <p>The returned map and its collection views may not obey the 918 * general contract of the {@link Object#equals} and 919 * {@link Object#hashCode} methods. 920 * 921 * <p>The returned map is typically case-sensitive on all platforms. 922 * 923 * <p>If a security manager exists, its 924 * {@link SecurityManager#checkPermission checkPermission} 925 * method is called with a 926 * <code>{@link RuntimePermission}("getenv.*")</code> 927 * permission. This may result in a {@link SecurityException} being 928 * thrown. 929 * 930 * <p>When passing information to a Java subprocess, 931 * <a href=#EnvironmentVSSystemProperties>system properties</a> 932 * are generally preferred over environment variables. 933 * 934 * @return the environment as a map of variable names to values 935 * @throws SecurityException 936 * if a security manager exists and its 937 * {@link SecurityManager#checkPermission checkPermission} 938 * method doesn't allow access to the process environment 939 * @see #getenv(String) 940 * @see ProcessBuilder#environment() 941 * @since 1.5 942 */ 943 public static java.util.Map<String,String> getenv() { 944 SecurityManager sm = getSecurityManager(); 945 if (sm != null) { 946 sm.checkPermission(new RuntimePermission("getenv.*")); 947 } 948 949 return ProcessEnvironment.getenv(); 950 } 951 952 /** 953 * {@code System.Logger} instances log messages that will be 954 * routed to the underlying logging framework the {@link System.LoggerFinder 955 * LoggerFinder} uses. 956 * <p> 957 * {@code System.Logger} instances are typically obtained from 958 * the {@link java.lang.System System} class, by calling 959 * {@link java.lang.System#getLogger(java.lang.String) System.getLogger(loggerName)} 960 * or {@link java.lang.System#getLogger(java.lang.String, java.util.ResourceBundle) 961 * System.getLogger(loggerName, bundle)}. 962 * 963 * @see java.lang.System#getLogger(java.lang.String) 964 * @see java.lang.System#getLogger(java.lang.String, java.util.ResourceBundle) 965 * @see java.lang.System.LoggerFinder 966 * 967 * @since 9 968 * 969 */ 970 public interface Logger { 971 972 /** 973 * System {@linkplain Logger loggers} levels. 974 * <p> 975 * A level has a {@linkplain #getName() name} and {@linkplain 976 * #getSeverity() severity}. 977 * Level values are {@link #ALL}, {@link #TRACE}, {@link #DEBUG}, 978 * {@link #INFO}, {@link #WARNING}, {@link #ERROR}, {@link #OFF}, 979 * by order of increasing severity. 980 * <br> 981 * {@link #ALL} and {@link #OFF} 982 * are simple markers with severities mapped respectively to 983 * {@link java.lang.Integer#MIN_VALUE Integer.MIN_VALUE} and 984 * {@link java.lang.Integer#MAX_VALUE Integer.MAX_VALUE}. 985 * <p> 986 * <b>Severity values and Mapping to {@code java.util.logging.Level}.</b> 987 * <p> 988 * {@linkplain System.Logger.Level System logger levels} are mapped to 989 * {@linkplain java.util.logging.Level java.util.logging levels} 990 * of corresponding severity. 991 * <br>The mapping is as follows: 992 * <br><br> 993 * <table border="1"> 994 * <caption>System.Logger Severity Level Mapping</caption> 995 * <tr><td><b>System.Logger Levels</b></td> 996 * <td>{@link Logger.Level#ALL ALL}</td> 997 * <td>{@link Logger.Level#TRACE TRACE}</td> 998 * <td>{@link Logger.Level#DEBUG DEBUG}</td> 999 * <td>{@link Logger.Level#INFO INFO}</td> 1000 * <td>{@link Logger.Level#WARNING WARNING}</td> 1001 * <td>{@link Logger.Level#ERROR ERROR}</td> 1002 * <td>{@link Logger.Level#OFF OFF}</td> 1003 * </tr> 1004 * <tr><td><b>java.util.logging Levels</b></td> 1005 * <td>{@link java.util.logging.Level#ALL ALL}</td> 1006 * <td>{@link java.util.logging.Level#FINER FINER}</td> 1007 * <td>{@link java.util.logging.Level#FINE FINE}</td> 1008 * <td>{@link java.util.logging.Level#INFO INFO}</td> 1009 * <td>{@link java.util.logging.Level#WARNING WARNING}</td> 1010 * <td>{@link java.util.logging.Level#SEVERE SEVERE}</td> 1011 * <td>{@link java.util.logging.Level#OFF OFF}</td> 1012 * </tr> 1013 * </table> 1014 * 1015 * @since 9 1016 * 1017 * @see java.lang.System.LoggerFinder 1018 * @see java.lang.System.Logger 1019 */ 1020 public enum Level { 1021 1022 // for convenience, we're reusing java.util.logging.Level int values 1023 // the mapping logic in sun.util.logging.PlatformLogger depends 1024 // on this. 1025 /** 1026 * A marker to indicate that all levels are enabled. 1027 * This level {@linkplain #getSeverity() severity} is 1028 * {@link Integer#MIN_VALUE}. 1029 */ 1030 ALL(Integer.MIN_VALUE), // typically mapped to/from j.u.l.Level.ALL 1031 /** 1032 * {@code TRACE} level: usually used to log diagnostic information. 1033 * This level {@linkplain #getSeverity() severity} is 1034 * {@code 400}. 1035 */ 1036 TRACE(400), // typically mapped to/from j.u.l.Level.FINER 1037 /** 1038 * {@code DEBUG} level: usually used to log debug information traces. 1039 * This level {@linkplain #getSeverity() severity} is 1040 * {@code 500}. 1041 */ 1042 DEBUG(500), // typically mapped to/from j.u.l.Level.FINEST/FINE/CONFIG 1043 /** 1044 * {@code INFO} level: usually used to log information messages. 1045 * This level {@linkplain #getSeverity() severity} is 1046 * {@code 800}. 1047 */ 1048 INFO(800), // typically mapped to/from j.u.l.Level.INFO 1049 /** 1050 * {@code WARNING} level: usually used to log warning messages. 1051 * This level {@linkplain #getSeverity() severity} is 1052 * {@code 900}. 1053 */ 1054 WARNING(900), // typically mapped to/from j.u.l.Level.WARNING 1055 /** 1056 * {@code ERROR} level: usually used to log error messages. 1057 * This level {@linkplain #getSeverity() severity} is 1058 * {@code 1000}. 1059 */ 1060 ERROR(1000), // typically mapped to/from j.u.l.Level.SEVERE 1061 /** 1062 * A marker to indicate that all levels are disabled. 1063 * This level {@linkplain #getSeverity() severity} is 1064 * {@link Integer#MAX_VALUE}. 1065 */ 1066 OFF(Integer.MAX_VALUE); // typically mapped to/from j.u.l.Level.OFF 1067 1068 private final int severity; 1069 1070 private Level(int severity) { 1071 this.severity = severity; 1072 } 1073 1074 /** 1075 * Returns the name of this level. 1076 * @return this level {@linkplain #name()}. 1077 */ 1078 public final String getName() { 1079 return name(); 1080 } 1081 1082 /** 1083 * Returns the severity of this level. 1084 * A higher severity means a more severe condition. 1085 * @return this level severity. 1086 */ 1087 public final int getSeverity() { 1088 return severity; 1089 } 1090 } 1091 1092 /** 1093 * Returns the name of this logger. 1094 * 1095 * @return the logger name. 1096 */ 1097 public String getName(); 1098 1099 /** 1100 * Checks if a message of the given level would be logged by 1101 * this logger. 1102 * 1103 * @param level the log message level. 1104 * @return {@code true} if the given log message level is currently 1105 * being logged. 1106 * 1107 * @throws NullPointerException if {@code level} is {@code null}. 1108 */ 1109 public boolean isLoggable(Level level); 1110 1111 /** 1112 * Logs a message. 1113 * 1114 * @implSpec The default implementation for this method calls 1115 * {@code this.log(level, (ResourceBundle)null, msg, (Object[])null);} 1116 * 1117 * @param level the log message level. 1118 * @param msg the string message (or a key in the message catalog, if 1119 * this logger is a {@link 1120 * LoggerFinder#getLocalizedLogger(java.lang.String, java.util.ResourceBundle, java.lang.Class) 1121 * localized logger}); can be {@code null}. 1122 * 1123 * @throws NullPointerException if {@code level} is {@code null}. 1124 */ 1125 public default void log(Level level, String msg) { 1126 log(level, (ResourceBundle) null, msg, (Object[]) null); 1127 } 1128 1129 /** 1130 * Logs a lazily supplied message. 1131 * <p> 1132 * If the logger is currently enabled for the given log message level 1133 * then a message is logged that is the result produced by the 1134 * given supplier function. Otherwise, the supplier is not operated on. 1135 * 1136 * @implSpec When logging is enabled for the given level, the default 1137 * implementation for this method calls 1138 * {@code this.log(level, (ResourceBundle)null, msgSupplier.get(), (Object[])null);} 1139 * 1140 * @param level the log message level. 1141 * @param msgSupplier a supplier function that produces a message. 1142 * 1143 * @throws NullPointerException if {@code level} is {@code null}, 1144 * or {@code msgSupplier} is {@code null}. 1145 */ 1146 public default void log(Level level, Supplier<String> msgSupplier) { 1147 Objects.requireNonNull(msgSupplier); 1148 if (isLoggable(Objects.requireNonNull(level))) { 1149 log(level, (ResourceBundle) null, msgSupplier.get(), (Object[]) null); 1150 } 1151 } 1152 1153 /** 1154 * Logs a message produced from the given object. 1155 * <p> 1156 * If the logger is currently enabled for the given log message level then 1157 * a message is logged that, by default, is the result produced from 1158 * calling toString on the given object. 1159 * Otherwise, the object is not operated on. 1160 * 1161 * @implSpec When logging is enabled for the given level, the default 1162 * implementation for this method calls 1163 * {@code this.log(level, (ResourceBundle)null, obj.toString(), (Object[])null);} 1164 * 1165 * @param level the log message level. 1166 * @param obj the object to log. 1167 * 1168 * @throws NullPointerException if {@code level} is {@code null}, or 1169 * {@code obj} is {@code null}. 1170 */ 1171 public default void log(Level level, Object obj) { 1172 Objects.requireNonNull(obj); 1173 if (isLoggable(Objects.requireNonNull(level))) { 1174 this.log(level, (ResourceBundle) null, obj.toString(), (Object[]) null); 1175 } 1176 } 1177 1178 /** 1179 * Logs a message associated with a given throwable. 1180 * 1181 * @implSpec The default implementation for this method calls 1182 * {@code this.log(level, (ResourceBundle)null, msg, thrown);} 1183 * 1184 * @param level the log message level. 1185 * @param msg the string message (or a key in the message catalog, if 1186 * this logger is a {@link 1187 * LoggerFinder#getLocalizedLogger(java.lang.String, java.util.ResourceBundle, java.lang.Class) 1188 * localized logger}); can be {@code null}. 1189 * @param thrown a {@code Throwable} associated with the log message; 1190 * can be {@code null}. 1191 * 1192 * @throws NullPointerException if {@code level} is {@code null}. 1193 */ 1194 public default void log(Level level, String msg, Throwable thrown) { 1195 this.log(level, null, msg, thrown); 1196 } 1197 1198 /** 1199 * Logs a lazily supplied message associated with a given throwable. 1200 * <p> 1201 * If the logger is currently enabled for the given log message level 1202 * then a message is logged that is the result produced by the 1203 * given supplier function. Otherwise, the supplier is not operated on. 1204 * 1205 * @implSpec When logging is enabled for the given level, the default 1206 * implementation for this method calls 1207 * {@code this.log(level, (ResourceBundle)null, msgSupplier.get(), thrown);} 1208 * 1209 * @param level one of the log message level identifiers. 1210 * @param msgSupplier a supplier function that produces a message. 1211 * @param thrown a {@code Throwable} associated with log message; 1212 * can be {@code null}. 1213 * 1214 * @throws NullPointerException if {@code level} is {@code null}, or 1215 * {@code msgSupplier} is {@code null}. 1216 */ 1217 public default void log(Level level, Supplier<String> msgSupplier, 1218 Throwable thrown) { 1219 Objects.requireNonNull(msgSupplier); 1220 if (isLoggable(Objects.requireNonNull(level))) { 1221 this.log(level, null, msgSupplier.get(), thrown); 1222 } 1223 } 1224 1225 /** 1226 * Logs a message with an optional list of parameters. 1227 * 1228 * @implSpec The default implementation for this method calls 1229 * {@code this.log(level, (ResourceBundle)null, format, params);} 1230 * 1231 * @param level one of the log message level identifiers. 1232 * @param format the string message format in {@link 1233 * java.text.MessageFormat} format, (or a key in the message 1234 * catalog, if this logger is a {@link 1235 * LoggerFinder#getLocalizedLogger(java.lang.String, java.util.ResourceBundle, java.lang.Class) 1236 * localized logger}); can be {@code null}. 1237 * @param params an optional list of parameters to the message (may be 1238 * none). 1239 * 1240 * @throws NullPointerException if {@code level} is {@code null}. 1241 */ 1242 public default void log(Level level, String format, Object... params) { 1243 this.log(level, null, format, params); 1244 } 1245 1246 /** 1247 * Logs a localized message associated with a given throwable. 1248 * <p> 1249 * If the given resource bundle is non-{@code null}, the {@code msg} 1250 * string is localized using the given resource bundle. 1251 * Otherwise the {@code msg} string is not localized. 1252 * 1253 * @param level the log message level. 1254 * @param bundle a resource bundle to localize {@code msg}; can be 1255 * {@code null}. 1256 * @param msg the string message (or a key in the message catalog, 1257 * if {@code bundle} is not {@code null}); can be {@code null}. 1258 * @param thrown a {@code Throwable} associated with the log message; 1259 * can be {@code null}. 1260 * 1261 * @throws NullPointerException if {@code level} is {@code null}. 1262 */ 1263 public void log(Level level, ResourceBundle bundle, String msg, 1264 Throwable thrown); 1265 1266 /** 1267 * Logs a message with resource bundle and an optional list of 1268 * parameters. 1269 * <p> 1270 * If the given resource bundle is non-{@code null}, the {@code format} 1271 * string is localized using the given resource bundle. 1272 * Otherwise the {@code format} string is not localized. 1273 * 1274 * @param level the log message level. 1275 * @param bundle a resource bundle to localize {@code format}; can be 1276 * {@code null}. 1277 * @param format the string message format in {@link 1278 * java.text.MessageFormat} format, (or a key in the message 1279 * catalog if {@code bundle} is not {@code null}); can be {@code null}. 1280 * @param params an optional list of parameters to the message (may be 1281 * none). 1282 * 1283 * @throws NullPointerException if {@code level} is {@code null}. 1284 */ 1285 public void log(Level level, ResourceBundle bundle, String format, 1286 Object... params); 1287 1288 1289 } 1290 1291 /** 1292 * The {@code LoggerFinder} service is responsible for creating, managing, 1293 * and configuring loggers to the underlying framework it uses. 1294 * <p> 1295 * A logger finder is a concrete implementation of this class that has a 1296 * zero-argument constructor and implements the abstract methods defined 1297 * by this class. 1298 * The loggers returned from a logger finder are capable of routing log 1299 * messages to the logging backend this provider supports. 1300 * A given invocation of the Java Runtime maintains a single 1301 * system-wide LoggerFinder instance that is loaded as follows: 1302 * <ul> 1303 * <li>First it finds any custom {@code LoggerFinder} provider 1304 * using the {@link java.util.ServiceLoader} facility with the 1305 * {@linkplain ClassLoader#getSystemClassLoader() system class 1306 * loader}.</li> 1307 * <li>If no {@code LoggerFinder} provider is found, the system default 1308 * {@code LoggerFinder} implementation will be used.</li> 1309 * </ul> 1310 * <p> 1311 * An application can replace the logging backend 1312 * <i>even when the java.logging module is present</i>, by simply providing 1313 * and declaring an implementation of the {@link LoggerFinder} service. 1314 * <p> 1315 * <b>Default Implementation</b> 1316 * <p> 1317 * The system default {@code LoggerFinder} implementation uses 1318 * {@code java.util.logging} as the backend framework when the 1319 * {@code java.logging} module is present. 1320 * It returns a {@linkplain System.Logger logger} instance 1321 * that will route log messages to a {@link java.util.logging.Logger 1322 * java.util.logging.Logger}. Otherwise, if {@code java.logging} is not 1323 * present, the default implementation will return a simple logger 1324 * instance that will route log messages of {@code INFO} level and above to 1325 * the console ({@code System.err}). 1326 * <p> 1327 * <b>Logging Configuration</b> 1328 * <p> 1329 * {@linkplain Logger Logger} instances obtained from the 1330 * {@code LoggerFinder} factory methods are not directly configurable by 1331 * the application. Configuration is the responsibility of the underlying 1332 * logging backend, and usually requires using APIs specific to that backend. 1333 * <p>For the default {@code LoggerFinder} implementation 1334 * using {@code java.util.logging} as its backend, refer to 1335 * {@link java.util.logging java.util.logging} for logging configuration. 1336 * For the default {@code LoggerFinder} implementation returning simple loggers 1337 * when the {@code java.logging} module is absent, the configuration 1338 * is implementation dependent. 1339 * <p> 1340 * Usually an application that uses a logging framework will log messages 1341 * through a logger facade defined (or supported) by that framework. 1342 * Applications that wish to use an external framework should log 1343 * through the facade associated with that framework. 1344 * <p> 1345 * A system class that needs to log messages will typically obtain 1346 * a {@link System.Logger} instance to route messages to the logging 1347 * framework selected by the application. 1348 * <p> 1349 * Libraries and classes that only need loggers to produce log messages 1350 * should not attempt to configure loggers by themselves, as that 1351 * would make them dependent from a specific implementation of the 1352 * {@code LoggerFinder} service. 1353 * <p> 1354 * In addition, when a security manager is present, loggers provided to 1355 * system classes should not be directly configurable through the logging 1356 * backend without requiring permissions. 1357 * <br> 1358 * It is the responsibility of the provider of 1359 * the concrete {@code LoggerFinder} implementation to ensure that 1360 * these loggers are not configured by untrusted code without proper 1361 * permission checks, as configuration performed on such loggers usually 1362 * affects all applications in the same Java Runtime. 1363 * <p> 1364 * <b>Message Levels and Mapping to backend levels</b> 1365 * <p> 1366 * A logger finder is responsible for mapping from a {@code 1367 * System.Logger.Level} to a level supported by the logging backend it uses. 1368 * <br>The default LoggerFinder using {@code java.util.logging} as the backend 1369 * maps {@code System.Logger} levels to 1370 * {@linkplain java.util.logging.Level java.util.logging} levels 1371 * of corresponding severity - as described in {@link Logger.Level 1372 * Logger.Level}. 1373 * 1374 * @see java.lang.System 1375 * @see java.lang.System.Logger 1376 * 1377 * @since 9 1378 */ 1379 public static abstract class LoggerFinder { 1380 /** 1381 * The {@code RuntimePermission("loggerFinder")} is 1382 * necessary to subclass and instantiate the {@code LoggerFinder} class, 1383 * as well as to obtain loggers from an instance of that class. 1384 */ 1385 static final RuntimePermission LOGGERFINDER_PERMISSION = 1386 new RuntimePermission("loggerFinder"); 1387 1388 /** 1389 * Creates a new instance of {@code LoggerFinder}. 1390 * 1391 * @implNote It is recommended that a {@code LoggerFinder} service 1392 * implementation does not perform any heavy initialization in its 1393 * constructor, in order to avoid possible risks of deadlock or class 1394 * loading cycles during the instantiation of the service provider. 1395 * 1396 * @throws SecurityException if a security manager is present and its 1397 * {@code checkPermission} method doesn't allow the 1398 * {@code RuntimePermission("loggerFinder")}. 1399 */ 1400 protected LoggerFinder() { 1401 this(checkPermission()); 1402 } 1403 1404 private LoggerFinder(Void unused) { 1405 // nothing to do. 1406 } 1407 1408 private static Void checkPermission() { 1409 final SecurityManager sm = System.getSecurityManager(); 1410 if (sm != null) { 1411 sm.checkPermission(LOGGERFINDER_PERMISSION); 1412 } 1413 return null; 1414 } 1415 1416 /** 1417 * Returns an instance of {@link Logger Logger} 1418 * for the given {@code caller}. 1419 * 1420 * @param name the name of the logger. 1421 * @param caller the class for which the logger is being requested; 1422 * can be {@code null}. 1423 * 1424 * @return a {@link Logger logger} suitable for the given caller's 1425 * use. 1426 * @throws NullPointerException if {@code name} is {@code null} or 1427 * {@code caller} is {@code null}. 1428 * @throws SecurityException if a security manager is present and its 1429 * {@code checkPermission} method doesn't allow the 1430 * {@code RuntimePermission("loggerFinder")}. 1431 */ 1432 public abstract Logger getLogger(String name, /* Module */ Class<?> caller); 1433 1434 /** 1435 * Returns a localizable instance of {@link Logger Logger} 1436 * for the given {@code caller}. 1437 * The returned logger will use the provided resource bundle for 1438 * message localization. 1439 * 1440 * @implSpec By default, this method calls {@link 1441 * #getLogger(java.lang.String, java.lang.Class) 1442 * this.getLogger(name, caller)} to obtain a logger, then wraps that 1443 * logger in a {@link Logger} instance where all methods that do not 1444 * take a {@link ResourceBundle} as parameter are redirected to one 1445 * which does - passing the given {@code bundle} for 1446 * localization. So for instance, a call to {@link 1447 * Logger#log(Level, String) Logger.log(Level.INFO, msg)} 1448 * will end up as a call to {@link 1449 * Logger#log(Level, ResourceBundle, String, Object...) 1450 * Logger.log(Level.INFO, bundle, msg, (Object[])null)} on the wrapped 1451 * logger instance. 1452 * Note however that by default, string messages returned by {@link 1453 * java.util.function.Supplier Supplier<String>} will not be 1454 * localized, as it is assumed that such strings are messages which are 1455 * already constructed, rather than keys in a resource bundle. 1456 * <p> 1457 * An implementation of {@code LoggerFinder} may override this method, 1458 * for example, when the underlying logging backend provides its own 1459 * mechanism for localizing log messages, then such a 1460 * {@code LoggerFinder} would be free to return a logger 1461 * that makes direct use of the mechanism provided by the backend. 1462 * 1463 * @param name the name of the logger. 1464 * @param bundle a resource bundle; can be {@code null}. 1465 * @param caller the class for which the logger is being requested. 1466 * @return an instance of {@link Logger Logger} which will use the 1467 * provided resource bundle for message localization. 1468 * 1469 * @throws NullPointerException if {@code name} is {@code null} or 1470 * {@code caller} is {@code null}. 1471 * @throws SecurityException if a security manager is present and its 1472 * {@code checkPermission} method doesn't allow the 1473 * {@code RuntimePermission("loggerFinder")}. 1474 */ 1475 public Logger getLocalizedLogger(String name, ResourceBundle bundle, 1476 /* Module */ Class<?> caller) { 1477 return new LocalizedLoggerWrapper<>(getLogger(name, caller), bundle); 1478 } 1479 1480 /** 1481 * Returns the {@code LoggerFinder} instance. There is one 1482 * single system-wide {@code LoggerFinder} instance in 1483 * the Java Runtime. See the class specification of how the 1484 * {@link LoggerFinder LoggerFinder} implementation is located and 1485 * loaded. 1486 1487 * @return the {@link LoggerFinder LoggerFinder} instance. 1488 * @throws SecurityException if a security manager is present and its 1489 * {@code checkPermission} method doesn't allow the 1490 * {@code RuntimePermission("loggerFinder")}. 1491 */ 1492 public static LoggerFinder getLoggerFinder() { 1493 final SecurityManager sm = System.getSecurityManager(); 1494 if (sm != null) { 1495 sm.checkPermission(LOGGERFINDER_PERMISSION); 1496 } 1497 return accessProvider(); 1498 } 1499 1500 1501 private static volatile LoggerFinder service; 1502 static LoggerFinder accessProvider() { 1503 // We do not need to synchronize: LoggerFinderLoader will 1504 // always return the same instance, so if we don't have it, 1505 // just fetch it again. 1506 if (service == null) { 1507 PrivilegedAction<LoggerFinder> pa = 1508 () -> LoggerFinderLoader.getLoggerFinder(); 1509 service = AccessController.doPrivileged(pa, null, 1510 LOGGERFINDER_PERMISSION); 1511 } 1512 return service; 1513 } 1514 1515 } 1516 1517 1518 /** 1519 * Returns an instance of {@link Logger Logger} for the caller's 1520 * use. 1521 * 1522 * @implSpec 1523 * Instances returned by this method route messages to loggers 1524 * obtained by calling {@link LoggerFinder#getLogger(java.lang.String, java.lang.Class) 1525 * LoggerFinder.getLogger(name, caller)}. 1526 * 1527 * @apiNote 1528 * This method may defer calling the {@link 1529 * LoggerFinder#getLogger(java.lang.String, java.lang.Class) 1530 * LoggerFinder.getLogger} method to create an actual logger supplied by 1531 * the logging backend, for instance, to allow loggers to be obtained during 1532 * the system initialization time. 1533 * 1534 * @param name the name of the logger. 1535 * @return an instance of {@link Logger} that can be used by the calling 1536 * class. 1537 * @throws NullPointerException if {@code name} is {@code null}. 1538 * 1539 * @since 9 1540 */ 1541 @CallerSensitive 1542 public static Logger getLogger(String name) { 1543 Objects.requireNonNull(name); 1544 final Class<?> caller = Reflection.getCallerClass(); 1545 return LazyLoggers.getLogger(name, caller); 1546 } 1547 1548 /** 1549 * Returns a localizable instance of {@link Logger 1550 * Logger} for the caller's use. 1551 * The returned logger will use the provided resource bundle for message 1552 * localization. 1553 * 1554 * @implSpec 1555 * The returned logger will perform message localization as specified 1556 * by {@link LoggerFinder#getLocalizedLogger(java.lang.String, 1557 * java.util.ResourceBundle, java.lang.Class) 1558 * LoggerFinder.getLocalizedLogger(name, bundle, caller}. 1559 * 1560 * @apiNote 1561 * This method is intended to be used after the system is fully initialized. 1562 * This method may trigger the immediate loading and initialization 1563 * of the {@link LoggerFinder} service, which may cause issues if the 1564 * Java Runtime is not ready to initialize the concrete service 1565 * implementation yet. 1566 * System classes which may be loaded early in the boot sequence and 1567 * need to log localized messages should create a logger using 1568 * {@link #getLogger(java.lang.String)} and then use the log methods that 1569 * take a resource bundle as parameter. 1570 * 1571 * @param name the name of the logger. 1572 * @param bundle a resource bundle. 1573 * @return an instance of {@link Logger} which will use the provided 1574 * resource bundle for message localization. 1575 * @throws NullPointerException if {@code name} is {@code null} or 1576 * {@code bundle} is {@code null}. 1577 * 1578 * @since 9 1579 */ 1580 @CallerSensitive 1581 public static Logger getLogger(String name, ResourceBundle bundle) { 1582 final ResourceBundle rb = Objects.requireNonNull(bundle); 1583 Objects.requireNonNull(name); 1584 final Class<?> caller = Reflection.getCallerClass(); 1585 final SecurityManager sm = System.getSecurityManager(); 1586 // We don't use LazyLoggers if a resource bundle is specified. 1587 // Bootstrap sensitive classes in the JDK do not use resource bundles 1588 // when logging. This could be revisited later, if it needs to. 1589 if (sm != null) { 1590 return AccessController.doPrivileged((PrivilegedAction<Logger>) 1591 () -> LoggerFinder.accessProvider().getLocalizedLogger(name, rb, caller), 1592 null, 1593 LoggerFinder.LOGGERFINDER_PERMISSION); 1594 } 1595 return LoggerFinder.accessProvider().getLocalizedLogger(name, rb, caller); 1596 } 1597 1598 /** 1599 * Terminates the currently running Java Virtual Machine. The 1600 * argument serves as a status code; by convention, a nonzero status 1601 * code indicates abnormal termination. 1602 * <p> 1603 * This method calls the <code>exit</code> method in class 1604 * <code>Runtime</code>. This method never returns normally. 1605 * <p> 1606 * The call <code>System.exit(n)</code> is effectively equivalent to 1607 * the call: 1608 * <blockquote><pre> 1609 * Runtime.getRuntime().exit(n) 1610 * </pre></blockquote> 1611 * 1612 * @param status exit status. 1613 * @throws SecurityException 1614 * if a security manager exists and its <code>checkExit</code> 1615 * method doesn't allow exit with the specified status. 1616 * @see java.lang.Runtime#exit(int) 1617 */ 1618 public static void exit(int status) { 1619 Runtime.getRuntime().exit(status); 1620 } 1621 1622 /** 1623 * Runs the garbage collector. 1624 * <p> 1625 * Calling the <code>gc</code> method suggests that the Java Virtual 1626 * Machine expend effort toward recycling unused objects in order to 1627 * make the memory they currently occupy available for quick reuse. 1628 * When control returns from the method call, the Java Virtual 1629 * Machine has made a best effort to reclaim space from all discarded 1630 * objects. 1631 * <p> 1632 * The call <code>System.gc()</code> is effectively equivalent to the 1633 * call: 1634 * <blockquote><pre> 1635 * Runtime.getRuntime().gc() 1636 * </pre></blockquote> 1637 * 1638 * @see java.lang.Runtime#gc() 1639 */ 1640 public static void gc() { 1641 Runtime.getRuntime().gc(); 1642 } 1643 1644 /** 1645 * Runs the finalization methods of any objects pending finalization. 1646 * <p> 1647 * Calling this method suggests that the Java Virtual Machine expend 1648 * effort toward running the <code>finalize</code> methods of objects 1649 * that have been found to be discarded but whose <code>finalize</code> 1650 * methods have not yet been run. When control returns from the 1651 * method call, the Java Virtual Machine has made a best effort to 1652 * complete all outstanding finalizations. 1653 * <p> 1654 * The call <code>System.runFinalization()</code> is effectively 1655 * equivalent to the call: 1656 * <blockquote><pre> 1657 * Runtime.getRuntime().runFinalization() 1658 * </pre></blockquote> 1659 * 1660 * @see java.lang.Runtime#runFinalization() 1661 */ 1662 public static void runFinalization() { 1663 Runtime.getRuntime().runFinalization(); 1664 } 1665 1666 /** 1667 * Enable or disable finalization on exit; doing so specifies that the 1668 * finalizers of all objects that have finalizers that have not yet been 1669 * automatically invoked are to be run before the Java runtime exits. 1670 * By default, finalization on exit is disabled. 1671 * 1672 * <p>If there is a security manager, 1673 * its <code>checkExit</code> method is first called 1674 * with 0 as its argument to ensure the exit is allowed. 1675 * This could result in a SecurityException. 1676 * 1677 * @deprecated This method is inherently unsafe. It may result in 1678 * finalizers being called on live objects while other threads are 1679 * concurrently manipulating those objects, resulting in erratic 1680 * behavior or deadlock. 1681 * @param value indicating enabling or disabling of finalization 1682 * @throws SecurityException 1683 * if a security manager exists and its <code>checkExit</code> 1684 * method doesn't allow the exit. 1685 * 1686 * @see java.lang.Runtime#exit(int) 1687 * @see java.lang.Runtime#gc() 1688 * @see java.lang.SecurityManager#checkExit(int) 1689 * @since 1.1 1690 */ 1691 @Deprecated 1692 public static void runFinalizersOnExit(boolean value) { 1693 Runtime.runFinalizersOnExit(value); 1694 } 1695 1696 /** 1697 * Loads the native library specified by the filename argument. The filename 1698 * argument must be an absolute path name. 1699 * 1700 * If the filename argument, when stripped of any platform-specific library 1701 * prefix, path, and file extension, indicates a library whose name is, 1702 * for example, L, and a native library called L is statically linked 1703 * with the VM, then the JNI_OnLoad_L function exported by the library 1704 * is invoked rather than attempting to load a dynamic library. 1705 * A filename matching the argument does not have to exist in the 1706 * file system. 1707 * See the JNI Specification for more details. 1708 * 1709 * Otherwise, the filename argument is mapped to a native library image in 1710 * an implementation-dependent manner. 1711 * 1712 * <p> 1713 * The call <code>System.load(name)</code> is effectively equivalent 1714 * to the call: 1715 * <blockquote><pre> 1716 * Runtime.getRuntime().load(name) 1717 * </pre></blockquote> 1718 * 1719 * @param filename the file to load. 1720 * @exception SecurityException if a security manager exists and its 1721 * <code>checkLink</code> method doesn't allow 1722 * loading of the specified dynamic library 1723 * @exception UnsatisfiedLinkError if either the filename is not an 1724 * absolute path name, the native library is not statically 1725 * linked with the VM, or the library cannot be mapped to 1726 * a native library image by the host system. 1727 * @exception NullPointerException if <code>filename</code> is 1728 * <code>null</code> 1729 * @see java.lang.Runtime#load(java.lang.String) 1730 * @see java.lang.SecurityManager#checkLink(java.lang.String) 1731 */ 1732 @CallerSensitive 1733 public static void load(String filename) { 1734 Runtime.getRuntime().load0(Reflection.getCallerClass(), filename); 1735 } 1736 1737 /** 1738 * Loads the native library specified by the <code>libname</code> 1739 * argument. The <code>libname</code> argument must not contain any platform 1740 * specific prefix, file extension or path. If a native library 1741 * called <code>libname</code> is statically linked with the VM, then the 1742 * JNI_OnLoad_<code>libname</code> function exported by the library is invoked. 1743 * See the JNI Specification for more details. 1744 * 1745 * Otherwise, the libname argument is loaded from a system library 1746 * location and mapped to a native library image in an implementation- 1747 * dependent manner. 1748 * <p> 1749 * The call <code>System.loadLibrary(name)</code> is effectively 1750 * equivalent to the call 1751 * <blockquote><pre> 1752 * Runtime.getRuntime().loadLibrary(name) 1753 * </pre></blockquote> 1754 * 1755 * @param libname the name of the library. 1756 * @exception SecurityException if a security manager exists and its 1757 * <code>checkLink</code> method doesn't allow 1758 * loading of the specified dynamic library 1759 * @exception UnsatisfiedLinkError if either the libname argument 1760 * contains a file path, the native library is not statically 1761 * linked with the VM, or the library cannot be mapped to a 1762 * native library image by the host system. 1763 * @exception NullPointerException if <code>libname</code> is 1764 * <code>null</code> 1765 * @see java.lang.Runtime#loadLibrary(java.lang.String) 1766 * @see java.lang.SecurityManager#checkLink(java.lang.String) 1767 */ 1768 @CallerSensitive 1769 public static void loadLibrary(String libname) { 1770 Runtime.getRuntime().loadLibrary0(Reflection.getCallerClass(), libname); 1771 } 1772 1773 /** 1774 * Maps a library name into a platform-specific string representing 1775 * a native library. 1776 * 1777 * @param libname the name of the library. 1778 * @return a platform-dependent native library name. 1779 * @exception NullPointerException if <code>libname</code> is 1780 * <code>null</code> 1781 * @see java.lang.System#loadLibrary(java.lang.String) 1782 * @see java.lang.ClassLoader#findLibrary(java.lang.String) 1783 * @since 1.2 1784 */ 1785 public static native String mapLibraryName(String libname); 1786 1787 /** 1788 * Create PrintStream for stdout/err based on encoding. 1789 */ 1790 private static PrintStream newPrintStream(FileOutputStream fos, String enc) { 1791 if (enc != null) { 1792 try { 1793 return new PrintStream(new BufferedOutputStream(fos, 128), true, enc); 1794 } catch (UnsupportedEncodingException uee) {} 1795 } 1796 return new PrintStream(new BufferedOutputStream(fos, 128), true); 1797 } 1798 1799 1800 /** 1801 * Initialize the system class. Called after thread initialization. 1802 */ 1803 private static void initializeSystemClass() { 1804 1805 // VM might invoke JNU_NewStringPlatform() to set those encoding 1806 // sensitive properties (user.home, user.name, boot.class.path, etc.) 1807 // during "props" initialization, in which it may need access, via 1808 // System.getProperty(), to the related system encoding property that 1809 // have been initialized (put into "props") at early stage of the 1810 // initialization. So make sure the "props" is available at the 1811 // very beginning of the initialization and all system properties to 1812 // be put into it directly. 1813 props = new Properties(); 1814 initProperties(props); // initialized by the VM 1815 1816 // There are certain system configurations that may be controlled by 1817 // VM options such as the maximum amount of direct memory and 1818 // Integer cache size used to support the object identity semantics 1819 // of autoboxing. Typically, the library will obtain these values 1820 // from the properties set by the VM. If the properties are for 1821 // internal implementation use only, these properties should be 1822 // removed from the system properties. 1823 // 1824 // See java.lang.Integer.IntegerCache and the 1825 // VM.saveAndRemoveProperties method for example. 1826 // 1827 // Save a private copy of the system properties object that 1828 // can only be accessed by the internal implementation. Remove 1829 // certain system properties that are not intended for public access. 1830 VM.saveAndRemoveProperties(props); 1831 1832 1833 lineSeparator = props.getProperty("line.separator"); 1834 sun.misc.Version.init(); 1835 1836 FileInputStream fdIn = new FileInputStream(FileDescriptor.in); 1837 FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out); 1838 FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err); 1839 setIn0(new BufferedInputStream(fdIn)); 1840 setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding"))); 1841 setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding"))); 1842 1843 // Load the zip library now in order to keep java.util.zip.ZipFile 1844 // from trying to use itself to load this library later. 1845 loadLibrary("zip"); 1846 1847 // Setup Java signal handlers for HUP, TERM, and INT (where available). 1848 Terminator.setup(); 1849 1850 // Initialize any miscellaneous operating system settings that need to be 1851 // set for the class libraries. Currently this is no-op everywhere except 1852 // for Windows where the process-wide error mode is set before the java.io 1853 // classes are used. 1854 VM.initializeOSEnvironment(); 1855 1856 // The main thread is not added to its thread group in the same 1857 // way as other threads; we must do it ourselves here. 1858 Thread current = Thread.currentThread(); 1859 current.getThreadGroup().add(current); 1860 1861 // register shared secrets 1862 setJavaLangAccess(); 1863 1864 // Subsystems that are invoked during initialization can invoke 1865 // VM.isBooted() in order to avoid doing things that should 1866 // wait until the application class loader has been set up. 1867 // IMPORTANT: Ensure that this remains the last initialization action! 1868 VM.booted(); 1869 } 1870 1871 private static void setJavaLangAccess() { 1872 // Allow privileged classes outside of java.lang 1873 SharedSecrets.setJavaLangAccess(new JavaLangAccess(){ 1874 public sun.reflect.ConstantPool getConstantPool(Class<?> klass) { 1875 return klass.getConstantPool(); 1876 } 1877 public boolean casAnnotationType(Class<?> klass, AnnotationType oldType, AnnotationType newType) { 1878 return klass.casAnnotationType(oldType, newType); 1879 } 1880 public AnnotationType getAnnotationType(Class<?> klass) { 1881 return klass.getAnnotationType(); 1882 } 1883 public Map<Class<? extends Annotation>, Annotation> getDeclaredAnnotationMap(Class<?> klass) { 1884 return klass.getDeclaredAnnotationMap(); 1885 } 1886 public byte[] getRawClassAnnotations(Class<?> klass) { 1887 return klass.getRawAnnotations(); 1888 } 1889 public byte[] getRawClassTypeAnnotations(Class<?> klass) { 1890 return klass.getRawTypeAnnotations(); 1891 } 1892 public byte[] getRawExecutableTypeAnnotations(Executable executable) { 1893 return Class.getExecutableTypeAnnotationBytes(executable); 1894 } 1895 public <E extends Enum<E>> 1896 E[] getEnumConstantsShared(Class<E> klass) { 1897 return klass.getEnumConstantsShared(); 1898 } 1899 public void blockedOn(Thread t, Interruptible b) { 1900 t.blockedOn(b); 1901 } 1902 public void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook) { 1903 Shutdown.add(slot, registerShutdownInProgress, hook); 1904 } 1905 public String newStringUnsafe(char[] chars) { 1906 return new String(chars, true); 1907 } 1908 public Thread newThreadWithAcc(Runnable target, AccessControlContext acc) { 1909 return new Thread(target, acc); 1910 } 1911 public void invokeFinalize(Object o) throws Throwable { 1912 o.finalize(); 1913 } 1914 public String fastUUID(long lsb, long msb) { 1915 return Long.fastUUID(lsb, msb); 1916 } 1917 }); 1918 } 1919 }