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.StringTokenizer;
34 import java.util.Map;
35 import java.security.AccessController;
36 import java.security.PrivilegedAction;
37 import java.security.AllPermission;
38 import java.nio.channels.Channel;
39 import java.nio.channels.spi.SelectorProvider;
40 import sun.nio.ch.Interruptible;
41 import sun.reflect.CallerSensitive;
42 import sun.reflect.Reflection;
43 import sun.security.util.SecurityConstants;
44 import sun.reflect.annotation.AnnotationType;
45
46 /**
47 * The <code>System</code> class contains several useful class fields
48 * and methods. It cannot be instantiated.
49 *
50 * <p>Among the facilities provided by the <code>System</code> class
51 * are standard input, standard output, and error output streams;
52 * access to externally defined properties and environment
53 * variables; a means of loading files and libraries; and a utility
54 * method for quickly copying a portion of an array.
55 *
56 * @author unascribed
57 * @since 1.0
58 */
59 public final class System {
60
61 /* register the natives via the static initializer.
62 *
63 * VM will invoke the initializeSystemClass method to complete
64 * the initialization for this class separated from clinit.
332 public static SecurityManager getSecurityManager() {
333 return security;
334 }
335
336 /**
337 * Returns the current time in milliseconds. Note that
338 * while the unit of time of the return value is a millisecond,
339 * the granularity of the value depends on the underlying
340 * operating system and may be larger. For example, many
341 * operating systems measure time in units of tens of
342 * milliseconds.
343 *
344 * <p> See the description of the class <code>Date</code> for
345 * a discussion of slight discrepancies that may arise between
346 * "computer time" and coordinated universal time (UTC).
347 *
348 * @return the difference, measured in milliseconds, between
349 * the current time and midnight, January 1, 1970 UTC.
350 * @see java.util.Date
351 */
352 public static native long currentTimeMillis();
353
354 /**
355 * Returns the current value of the running Java Virtual Machine's
356 * high-resolution time source, in nanoseconds.
357 *
358 * <p>This method can only be used to measure elapsed time and is
359 * not related to any other notion of system or wall-clock time.
360 * The value returned represents nanoseconds since some fixed but
361 * arbitrary <i>origin</i> time (perhaps in the future, so values
362 * may be negative). The same origin is used by all invocations of
363 * this method in an instance of a Java virtual machine; other
364 * virtual machine instances are likely to use a different origin.
365 *
366 * <p>This method provides nanosecond precision, but not necessarily
367 * nanosecond resolution (that is, how frequently the value changes)
368 * - no guarantees are made except that the resolution is at least as
369 * good as that of {@link #currentTimeMillis()}.
370 *
371 * <p>Differences in successive calls that span greater than
375 * <p>The values returned by this method become meaningful only when
376 * the difference between two such values, obtained within the same
377 * instance of a Java virtual machine, is computed.
378 *
379 * <p>For example, to measure how long some code takes to execute:
380 * <pre> {@code
381 * long startTime = System.nanoTime();
382 * // ... the code being measured ...
383 * long elapsedNanos = System.nanoTime() - startTime;}</pre>
384 *
385 * <p>To compare elapsed time against a timeout, use <pre> {@code
386 * if (System.nanoTime() - startTime >= timeoutNanos) ...}</pre>
387 * instead of <pre> {@code
388 * if (System.nanoTime() >= startTime + timeoutNanos) ...}</pre>
389 * because of the possibility of numerical overflow.
390 *
391 * @return the current value of the running Java Virtual Machine's
392 * high-resolution time source, in nanoseconds
393 * @since 1.5
394 */
395 public static native long nanoTime();
396
397 /**
398 * Copies an array from the specified source array, beginning at the
399 * specified position, to the specified position of the destination array.
400 * A subsequence of array components are copied from the source
401 * array referenced by <code>src</code> to the destination array
402 * referenced by <code>dest</code>. The number of components copied is
403 * equal to the <code>length</code> argument. The components at
404 * positions <code>srcPos</code> through
405 * <code>srcPos+length-1</code> in the source array are copied into
406 * positions <code>destPos</code> through
407 * <code>destPos+length-1</code>, respectively, of the destination
408 * array.
409 * <p>
410 * If the <code>src</code> and <code>dest</code> arguments refer to the
411 * same array object, then the copying is performed as if the
412 * components at positions <code>srcPos</code> through
413 * <code>srcPos+length-1</code> were first copied to a temporary
414 * array with <code>length</code> components and then the contents of
469 * <code>destPos</code> through
470 * <code>destPos+</code><i>k</I><code>-1</code> and no other
471 * positions of the destination array will have been modified.
472 * (Because of the restrictions already itemized, this
473 * paragraph effectively applies only to the situation where both
474 * arrays have component types that are reference types.)
475 *
476 * @param src the source array.
477 * @param srcPos starting position in the source array.
478 * @param dest the destination array.
479 * @param destPos starting position in the destination data.
480 * @param length the number of array elements to be copied.
481 * @exception IndexOutOfBoundsException if copying would cause
482 * access of data outside array bounds.
483 * @exception ArrayStoreException if an element in the <code>src</code>
484 * array could not be stored into the <code>dest</code> array
485 * because of a type mismatch.
486 * @exception NullPointerException if either <code>src</code> or
487 * <code>dest</code> is <code>null</code>.
488 */
489 public static native void arraycopy(Object src, int srcPos,
490 Object dest, int destPos,
491 int length);
492
493 /**
494 * Returns the same hash code for the given object as
495 * would be returned by the default method hashCode(),
496 * whether or not the given object's class overrides
497 * hashCode().
498 * The hash code for the null reference is zero.
499 *
500 * @param x object for which the hashCode is to be calculated
501 * @return the hashCode
502 * @since 1.1
503 */
504 public static native int identityHashCode(Object x);
505
506 /**
507 * System properties. The following properties are guaranteed to be defined:
508 * <dl>
509 * <dt>java.version <dd>Java version number
510 * <dt>java.vendor <dd>Java vendor specific string
511 * <dt>java.vendor.url <dd>Java vendor URL
512 * <dt>java.home <dd>Java installation directory
513 * <dt>java.class.version <dd>Java class version number
514 * <dt>java.class.path <dd>Java classpath
515 * <dt>os.name <dd>Operating System Name
516 * <dt>os.arch <dd>Operating System Architecture
517 * <dt>os.version <dd>Operating System Version
518 * <dt>file.separator <dd>File separator ("/" on Unix)
519 * <dt>path.separator <dd>Path separator (":" on Unix)
520 * <dt>line.separator <dd>Line separator ("\n" on Unix)
521 * <dt>user.name <dd>User account name
522 * <dt>user.home <dd>User home directory
523 * <dt>user.dir <dd>User's current working directory
|
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.StringTokenizer;
34 import java.util.Map;
35 import java.security.AccessController;
36 import java.security.PrivilegedAction;
37 import java.security.AllPermission;
38 import java.nio.channels.Channel;
39 import java.nio.channels.spi.SelectorProvider;
40 import sun.nio.ch.Interruptible;
41 import sun.reflect.CallerSensitive;
42 import sun.reflect.Reflection;
43 import sun.security.util.SecurityConstants;
44 import sun.reflect.annotation.AnnotationType;
45 import jdk.internal.HotSpotIntrinsicCandidate;
46
47 /**
48 * The <code>System</code> class contains several useful class fields
49 * and methods. It cannot be instantiated.
50 *
51 * <p>Among the facilities provided by the <code>System</code> class
52 * are standard input, standard output, and error output streams;
53 * access to externally defined properties and environment
54 * variables; a means of loading files and libraries; and a utility
55 * method for quickly copying a portion of an array.
56 *
57 * @author unascribed
58 * @since 1.0
59 */
60 public final class System {
61
62 /* register the natives via the static initializer.
63 *
64 * VM will invoke the initializeSystemClass method to complete
65 * the initialization for this class separated from clinit.
333 public static SecurityManager getSecurityManager() {
334 return security;
335 }
336
337 /**
338 * Returns the current time in milliseconds. Note that
339 * while the unit of time of the return value is a millisecond,
340 * the granularity of the value depends on the underlying
341 * operating system and may be larger. For example, many
342 * operating systems measure time in units of tens of
343 * milliseconds.
344 *
345 * <p> See the description of the class <code>Date</code> for
346 * a discussion of slight discrepancies that may arise between
347 * "computer time" and coordinated universal time (UTC).
348 *
349 * @return the difference, measured in milliseconds, between
350 * the current time and midnight, January 1, 1970 UTC.
351 * @see java.util.Date
352 */
353 @HotSpotIntrinsicCandidate
354 public static native long currentTimeMillis();
355
356 /**
357 * Returns the current value of the running Java Virtual Machine's
358 * high-resolution time source, in nanoseconds.
359 *
360 * <p>This method can only be used to measure elapsed time and is
361 * not related to any other notion of system or wall-clock time.
362 * The value returned represents nanoseconds since some fixed but
363 * arbitrary <i>origin</i> time (perhaps in the future, so values
364 * may be negative). The same origin is used by all invocations of
365 * this method in an instance of a Java virtual machine; other
366 * virtual machine instances are likely to use a different origin.
367 *
368 * <p>This method provides nanosecond precision, but not necessarily
369 * nanosecond resolution (that is, how frequently the value changes)
370 * - no guarantees are made except that the resolution is at least as
371 * good as that of {@link #currentTimeMillis()}.
372 *
373 * <p>Differences in successive calls that span greater than
377 * <p>The values returned by this method become meaningful only when
378 * the difference between two such values, obtained within the same
379 * instance of a Java virtual machine, is computed.
380 *
381 * <p>For example, to measure how long some code takes to execute:
382 * <pre> {@code
383 * long startTime = System.nanoTime();
384 * // ... the code being measured ...
385 * long elapsedNanos = System.nanoTime() - startTime;}</pre>
386 *
387 * <p>To compare elapsed time against a timeout, use <pre> {@code
388 * if (System.nanoTime() - startTime >= timeoutNanos) ...}</pre>
389 * instead of <pre> {@code
390 * if (System.nanoTime() >= startTime + timeoutNanos) ...}</pre>
391 * because of the possibility of numerical overflow.
392 *
393 * @return the current value of the running Java Virtual Machine's
394 * high-resolution time source, in nanoseconds
395 * @since 1.5
396 */
397 @HotSpotIntrinsicCandidate
398 public static native long nanoTime();
399
400 /**
401 * Copies an array from the specified source array, beginning at the
402 * specified position, to the specified position of the destination array.
403 * A subsequence of array components are copied from the source
404 * array referenced by <code>src</code> to the destination array
405 * referenced by <code>dest</code>. The number of components copied is
406 * equal to the <code>length</code> argument. The components at
407 * positions <code>srcPos</code> through
408 * <code>srcPos+length-1</code> in the source array are copied into
409 * positions <code>destPos</code> through
410 * <code>destPos+length-1</code>, respectively, of the destination
411 * array.
412 * <p>
413 * If the <code>src</code> and <code>dest</code> arguments refer to the
414 * same array object, then the copying is performed as if the
415 * components at positions <code>srcPos</code> through
416 * <code>srcPos+length-1</code> were first copied to a temporary
417 * array with <code>length</code> components and then the contents of
472 * <code>destPos</code> through
473 * <code>destPos+</code><i>k</I><code>-1</code> and no other
474 * positions of the destination array will have been modified.
475 * (Because of the restrictions already itemized, this
476 * paragraph effectively applies only to the situation where both
477 * arrays have component types that are reference types.)
478 *
479 * @param src the source array.
480 * @param srcPos starting position in the source array.
481 * @param dest the destination array.
482 * @param destPos starting position in the destination data.
483 * @param length the number of array elements to be copied.
484 * @exception IndexOutOfBoundsException if copying would cause
485 * access of data outside array bounds.
486 * @exception ArrayStoreException if an element in the <code>src</code>
487 * array could not be stored into the <code>dest</code> array
488 * because of a type mismatch.
489 * @exception NullPointerException if either <code>src</code> or
490 * <code>dest</code> is <code>null</code>.
491 */
492 @HotSpotIntrinsicCandidate
493 public static native void arraycopy(Object src, int srcPos,
494 Object dest, int destPos,
495 int length);
496
497 /**
498 * Returns the same hash code for the given object as
499 * would be returned by the default method hashCode(),
500 * whether or not the given object's class overrides
501 * hashCode().
502 * The hash code for the null reference is zero.
503 *
504 * @param x object for which the hashCode is to be calculated
505 * @return the hashCode
506 * @since 1.1
507 */
508 @HotSpotIntrinsicCandidate
509 public static native int identityHashCode(Object x);
510
511 /**
512 * System properties. The following properties are guaranteed to be defined:
513 * <dl>
514 * <dt>java.version <dd>Java version number
515 * <dt>java.vendor <dd>Java vendor specific string
516 * <dt>java.vendor.url <dd>Java vendor URL
517 * <dt>java.home <dd>Java installation directory
518 * <dt>java.class.version <dd>Java class version number
519 * <dt>java.class.path <dd>Java classpath
520 * <dt>os.name <dd>Operating System Name
521 * <dt>os.arch <dd>Operating System Architecture
522 * <dt>os.version <dd>Operating System Version
523 * <dt>file.separator <dd>File separator ("/" on Unix)
524 * <dt>path.separator <dd>Path separator (":" on Unix)
525 * <dt>line.separator <dd>Line separator ("\n" on Unix)
526 * <dt>user.name <dd>User account name
527 * <dt>user.home <dd>User home directory
528 * <dt>user.dir <dd>User's current working directory
|