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