src/java.base/share/classes/java/lang/System.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58574 dcc760954243
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
53160
7d1efad039a3 8216205: Java API documentation formatting error in System.getEnv
rriggs
parents: 52978
diff changeset
     2
 * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4355
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4355
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4355
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4355
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4355
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    27
import java.io.BufferedInputStream;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    28
import java.io.BufferedOutputStream;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    29
import java.io.Console;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    30
import java.io.FileDescriptor;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    31
import java.io.FileInputStream;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    32
import java.io.FileOutputStream;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    33
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    34
import java.io.InputStream;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    35
import java.io.PrintStream;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    36
import java.io.UnsupportedEncodingException;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    37
import java.lang.annotation.Annotation;
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
    38
import java.lang.module.ModuleDescriptor;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    39
import java.lang.reflect.Constructor;
15510
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 14676
diff changeset
    40
import java.lang.reflect.Executable;
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
    41
import java.lang.reflect.Method;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    42
import java.lang.reflect.Modifier;
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
    43
import java.net.URI;
50820
35f52a3cd6bd 8205058: (fs) Files read/writeString should throw CharacterCodingException instead of IOException with an IllegalArgumentException as cause
joehw
parents: 50817
diff changeset
    44
import java.nio.charset.CharacterCodingException;
20805
ae41216325dd 8013739: Better LDAP resource management
weijun
parents: 18546
diff changeset
    45
import java.security.AccessControlContext;
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
    46
import java.security.ProtectionDomain;
34370
70d1245398ed 8143931: Back out JDK-8140450
ctornqvi
parents: 34362
diff changeset
    47
import java.security.AccessController;
70d1245398ed 8143931: Back out JDK-8140450
ctornqvi
parents: 34362
diff changeset
    48
import java.security.PrivilegedAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.nio.channels.Channel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.nio.channels.spi.SelectorProvider;
50552
7439ceaae8e4 8201276: (fs) Add methods to Files for reading/writing a string from/to a file
joehw
parents: 50531
diff changeset
    51
import java.nio.charset.Charset;
45652
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents: 45124
diff changeset
    52
import java.util.Iterator;
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents: 45124
diff changeset
    53
import java.util.List;
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
    54
import java.util.Map;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
    55
import java.util.Objects;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
    56
import java.util.Properties;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
    57
import java.util.PropertyPermission;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
    58
import java.util.ResourceBundle;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
    59
import java.util.function.Supplier;
36972
27147cde3256 8152115: (proxy) Examine performance of dynamic proxy creation
plevart
parents: 36511
diff changeset
    60
import java.util.concurrent.ConcurrentHashMap;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    61
import java.util.stream.Stream;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    62
50817
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
    63
import jdk.internal.util.StaticProperty;
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
    64
import jdk.internal.module.ModuleBootstrap;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
    65
import jdk.internal.module.ServicesCatalog;
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 36972
diff changeset
    66
import jdk.internal.reflect.CallerSensitive;
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 36972
diff changeset
    67
import jdk.internal.reflect.Reflection;
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 29986
diff changeset
    68
import jdk.internal.HotSpotIntrinsicCandidate;
52427
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 52084
diff changeset
    69
import jdk.internal.access.JavaLangAccess;
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 52084
diff changeset
    70
import jdk.internal.access.SharedSecrets;
34882
ce2a8ec851c1 8145544: Move sun.misc.VM to jdk.internal.misc
chegar
parents: 34774
diff changeset
    71
import jdk.internal.misc.VM;
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
    72
import jdk.internal.logger.LoggerFinderLoader;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
    73
import jdk.internal.logger.LazyLoggers;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
    74
import jdk.internal.logger.LocalizedLoggerWrapper;
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52615
diff changeset
    75
import jdk.internal.util.SystemProps;
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
    76
import jdk.internal.vm.annotation.Stable;
57792
1b6806340400 8229773: Resolve permissions for code source URLs lazily
redestad
parents: 55693
diff changeset
    77
import sun.nio.fs.DefaultFileSystemProvider;
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
    78
import sun.reflect.annotation.AnnotationType;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
    79
import sun.nio.ch.Interruptible;
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
    80
import sun.security.util.SecurityConstants;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
    81
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
/**
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
    83
 * The {@code System} class contains several useful class fields
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * and methods. It cannot be instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
    86
 * Among the facilities provided by the {@code System} class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * are standard input, standard output, and error output streams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * access to externally defined properties and environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * variables; a means of loading files and libraries; and a utility
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * method for quickly copying a portion of an array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
    92
 * @since   1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
public final class System {
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
    95
    /* Register the natives via the static initializer.
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6668
diff changeset
    96
     *
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6668
diff changeset
    97
     * VM will invoke the initializeSystemClass method to complete
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6668
diff changeset
    98
     * the initialization for this class separated from clinit.
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6668
diff changeset
    99
     * Note that to use properties set by the VM, see the constraints
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6668
diff changeset
   100
     * described in the initializeSystemClass method.
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6668
diff changeset
   101
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static native void registerNatives();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        registerNatives();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /** Don't let anyone instantiate this class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private System() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * The "standard" input stream. This stream is already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * open and ready to supply input data. Typically this stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * corresponds to keyboard input or another input source specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * the host environment or user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32033
diff changeset
   117
    public static final InputStream in = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * The "standard" output stream. This stream is already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * open and ready to accept output data. Typically this stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * corresponds to display output or another output destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * specified by the host environment or user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * For simple stand-alone Java applications, a typical way to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * a line of output data is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *     System.out.println(data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * <p>
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   131
     * See the {@code println} methods in class {@code PrintStream}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @see     java.io.PrintStream#println()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @see     java.io.PrintStream#println(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @see     java.io.PrintStream#println(char)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @see     java.io.PrintStream#println(char[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @see     java.io.PrintStream#println(double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @see     java.io.PrintStream#println(float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @see     java.io.PrintStream#println(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @see     java.io.PrintStream#println(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @see     java.io.PrintStream#println(java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @see     java.io.PrintStream#println(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32033
diff changeset
   144
    public static final PrintStream out = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * The "standard" error output stream. This stream is already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * open and ready to accept output data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Typically this stream corresponds to display output or another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * output destination specified by the host environment or user. By
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * convention, this output stream is used to display error messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * or other information that should come to the immediate attention
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * of a user even if the principal output stream, the value of the
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   155
     * variable {@code out}, has been redirected to a file or other
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * destination that is typically not continuously monitored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32033
diff changeset
   158
    public static final PrintStream err = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   160
    // indicates if a security manager is possible
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   161
    private static final int NEVER = 1;
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   162
    private static final int MAYBE = 2;
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   163
    private static @Stable int allowSecurityManager;
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   164
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   165
    // current security manager
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   166
    private static volatile SecurityManager security;   // read by VM
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   167
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   168
    // return true if a security manager is allowed
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   169
    private static boolean allowSecurityManager() {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   170
        return (allowSecurityManager != NEVER);
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   171
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Reassigns the "standard" input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   176
     * First, if there is a security manager, its {@code checkPermission}
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   177
     * method is called with a {@code RuntimePermission("setIO")} permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *  to see if it's ok to reassign the "standard" input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param in the new standard input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *        if a security manager exists and its
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   184
     *        {@code checkPermission} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *        reassigning of the standard input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @see SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @see java.lang.RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
   190
     * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public static void setIn(InputStream in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        checkIO();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        setIn0(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Reassigns the "standard" output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   200
     * First, if there is a security manager, its {@code checkPermission}
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   201
     * method is called with a {@code RuntimePermission("setIO")} permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *  to see if it's ok to reassign the "standard" output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param out the new standard output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *        if a security manager exists and its
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   208
     *        {@code checkPermission} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *        reassigning of the standard output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @see SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @see java.lang.RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
   214
     * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public static void setOut(PrintStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        checkIO();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        setOut0(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Reassigns the "standard" error output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   224
     * First, if there is a security manager, its {@code checkPermission}
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   225
     * method is called with a {@code RuntimePermission("setIO")} permission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *  to see if it's ok to reassign the "standard" error output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param err the new standard error output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *        if a security manager exists and its
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   232
     *        {@code checkPermission} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *        reassigning of the standard error output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @see SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @see java.lang.RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
   238
     * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public static void setErr(PrintStream err) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        checkIO();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        setErr0(err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
34774
03b4e6dc367b 8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents: 34372
diff changeset
   245
    private static volatile Console cons;
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   246
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Returns the unique {@link java.io.Console Console} object associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * with the current Java virtual machine, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31671
diff changeset
   251
     * @return  The system console, if any, otherwise {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @since   1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     public static Console console() {
39826
5dba95a26226 8162563: Fix double checked locking in System.console()
martin
parents: 38861
diff changeset
   256
         Console c;
5dba95a26226 8162563: Fix double checked locking in System.console()
martin
parents: 38861
diff changeset
   257
         if ((c = cons) == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
             synchronized (System.class) {
39826
5dba95a26226 8162563: Fix double checked locking in System.console()
martin
parents: 38861
diff changeset
   259
                 if ((c = cons) == null) {
5dba95a26226 8162563: Fix double checked locking in System.console()
martin
parents: 38861
diff changeset
   260
                     cons = c = SharedSecrets.getJavaIOAccess().console();
5dba95a26226 8162563: Fix double checked locking in System.console()
martin
parents: 38861
diff changeset
   261
                 }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
         }
34774
03b4e6dc367b 8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents: 34372
diff changeset
   264
         return c;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Returns the channel inherited from the entity that created this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   271
     * This method returns the channel obtained by invoking the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * inheritedChannel} method of the system-wide default
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   274
     * {@link java.nio.channels.spi.SelectorProvider} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <p> In addition to the network-oriented channels described in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * {@link java.nio.channels.spi.SelectorProvider#inheritedChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * inheritedChannel}, this method may return other kinds of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * channels in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31671
diff changeset
   281
     * @return  The inherited channel, if any, otherwise {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *          If an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *          If a security manager is present and it does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *          permit access to the channel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public static Channel inheritedChannel() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return SelectorProvider.provider().inheritedChannel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    private static void checkIO() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            sm.checkPermission(new RuntimePermission("setIO"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    private static native void setIn0(InputStream in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    private static native void setOut0(PrintStream out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    private static native void setErr0(PrintStream err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   308
     * Sets the system-wide security manager.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   310
     * If there is a security manager already installed, this method first
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   311
     * calls the security manager's {@code checkPermission} method
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   312
     * with a {@code RuntimePermission("setSecurityManager")}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * permission to ensure it's ok to replace the existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * security manager.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   315
     * This may result in throwing a {@code SecurityException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * <p> Otherwise, the argument is established as the current
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   318
     * security manager. If the argument is {@code null} and no
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * security manager has been established, then no action is taken and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * the method simply returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   322
     * @implNote In the JDK implementation, if the Java virtual machine is
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   323
     * started with the system property {@code java.security.manager} set to
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   324
     * the special token "{@code disallow}" then the {@code setSecurityManager}
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   325
     * method cannot be used to set a security manager.
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   326
     *
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   327
     * @param  sm the security manager or {@code null}
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   328
     * @throws SecurityException
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   329
     *         if the security manager has already been set and its {@code
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   330
     *         checkPermission} method doesn't allow it to be replaced
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   331
     * @throws UnsupportedOperationException
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   332
     *         if {@code sm} is non-null and a security manager is not allowed
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   333
     *         to be set dynamically
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @see #getSecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @see SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @see java.lang.RuntimePermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   338
    public static void setSecurityManager(SecurityManager sm) {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   339
        if (allowSecurityManager()) {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   340
            if (security == null) {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   341
                // ensure image reader is initialized
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   342
                Object.class.getResource("java/lang/ANY");
57792
1b6806340400 8229773: Resolve permissions for code source URLs lazily
redestad
parents: 55693
diff changeset
   343
                // ensure the default file system is initialized
1b6806340400 8229773: Resolve permissions for code source URLs lazily
redestad
parents: 55693
diff changeset
   344
                DefaultFileSystemProvider.theFileSystem();
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   345
            }
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   346
            if (sm != null) {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   347
                try {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   348
                    // pre-populates the SecurityManager.packageAccess cache
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   349
                    // to avoid recursive permission checking issues with custom
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   350
                    // SecurityManager implementations
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   351
                    sm.checkPackageAccess("java.lang");
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   352
                } catch (Exception e) {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   353
                    // no-op
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   354
                }
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   355
            }
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   356
            setSecurityManager0(sm);
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   357
        } else {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   358
            // security manager not allowed
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   359
            if (sm != null) {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   360
                throw new UnsupportedOperationException(
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   361
                    "Runtime configured to disallow security manager");
43221
eef9383d25cb 8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents: 42338
diff changeset
   362
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    private static synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    void setSecurityManager0(final SecurityManager s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            // ask the currently installed security manager if we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            // can replace it.
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   372
            sm.checkPermission(new RuntimePermission("setSecurityManager"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        if ((s != null) && (s.getClass().getClassLoader() != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            // New security manager class is not on bootstrap classpath.
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   377
            // Force policy to get initialized before we install the new
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            // security manager, in order to prevent infinite loops when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            // trying to initialize the policy (which usually involves
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            // accessing some security and/or system properties, which in turn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            // calls the installed security manager's checkPermission method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            // which will loop infinitely if there is a non-system class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            // (in this case: the new security manager class) on the stack).
29986
97167d851fc4 8078467: Update core libraries to use diamond with anonymous classes
darcy
parents: 28668
diff changeset
   384
            AccessController.doPrivileged(new PrivilegedAction<>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    s.getClass().getProtectionDomain().implies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                        (SecurityConstants.ALL_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        security = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   397
     * Gets the system-wide security manager.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @return  if a security manager has already been established for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *          current application, then that security manager is returned;
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   401
     *          otherwise, {@code null} is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @see     #setSecurityManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public static SecurityManager getSecurityManager() {
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   405
        if (allowSecurityManager()) {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   406
            return security;
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   407
        } else {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   408
            return null;
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
   409
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Returns the current time in milliseconds.  Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * while the unit of time of the return value is a millisecond,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * the granularity of the value depends on the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * operating system and may be larger.  For example, many
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * operating systems measure time in units of tens of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * milliseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   420
     * <p> See the description of the class {@code Date} for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * a discussion of slight discrepancies that may arise between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * "computer time" and coordinated universal time (UTC).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @return  the difference, measured in milliseconds, between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *          the current time and midnight, January 1, 1970 UTC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @see     java.util.Date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 29986
diff changeset
   428
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public static native long currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Returns the current value of the running Java Virtual Machine's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * high-resolution time source, in nanoseconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   435
     * This method can only be used to measure elapsed time and is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * not related to any other notion of system or wall-clock time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * The value returned represents nanoseconds since some fixed but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * arbitrary <i>origin</i> time (perhaps in the future, so values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * may be negative).  The same origin is used by all invocations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * this method in an instance of a Java virtual machine; other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * virtual machine instances are likely to use a different origin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * <p>This method provides nanosecond precision, but not necessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * nanosecond resolution (that is, how frequently the value changes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * - no guarantees are made except that the resolution is at least as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * good as that of {@link #currentTimeMillis()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * <p>Differences in successive calls that span greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * approximately 292 years (2<sup>63</sup> nanoseconds) will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * correctly compute elapsed time due to numerical overflow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * <p>The values returned by this method become meaningful only when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * the difference between two such values, obtained within the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * instance of a Java virtual machine, is computed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *
28668
a5b9168af1bb 8069269: (spec) Defect in the System.nanoTime spec
bpb
parents: 27565
diff changeset
   456
     * <p>For example, to measure how long some code takes to execute:
a5b9168af1bb 8069269: (spec) Defect in the System.nanoTime spec
bpb
parents: 27565
diff changeset
   457
     * <pre> {@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * long startTime = System.nanoTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * // ... the code being measured ...
28668
a5b9168af1bb 8069269: (spec) Defect in the System.nanoTime spec
bpb
parents: 27565
diff changeset
   460
     * long elapsedNanos = System.nanoTime() - startTime;}</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
28668
a5b9168af1bb 8069269: (spec) Defect in the System.nanoTime spec
bpb
parents: 27565
diff changeset
   462
     * <p>To compare elapsed time against a timeout, use <pre> {@code
a5b9168af1bb 8069269: (spec) Defect in the System.nanoTime spec
bpb
parents: 27565
diff changeset
   463
     * if (System.nanoTime() - startTime >= timeoutNanos) ...}</pre>
a5b9168af1bb 8069269: (spec) Defect in the System.nanoTime spec
bpb
parents: 27565
diff changeset
   464
     * instead of <pre> {@code
a5b9168af1bb 8069269: (spec) Defect in the System.nanoTime spec
bpb
parents: 27565
diff changeset
   465
     * if (System.nanoTime() >= startTime + timeoutNanos) ...}</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * because of the possibility of numerical overflow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @return the current value of the running Java Virtual Machine's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *         high-resolution time source, in nanoseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 29986
diff changeset
   472
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    public static native long nanoTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * Copies an array from the specified source array, beginning at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * specified position, to the specified position of the destination array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * A subsequence of array components are copied from the source
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   479
     * array referenced by {@code src} to the destination array
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   480
     * referenced by {@code dest}. The number of components copied is
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   481
     * equal to the {@code length} argument. The components at
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   482
     * positions {@code srcPos} through
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   483
     * {@code srcPos+length-1} in the source array are copied into
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   484
     * positions {@code destPos} through
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   485
     * {@code destPos+length-1}, respectively, of the destination
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * <p>
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   488
     * If the {@code src} and {@code dest} arguments refer to the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * same array object, then the copying is performed as if the
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   490
     * components at positions {@code srcPos} through
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   491
     * {@code srcPos+length-1} were first copied to a temporary
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   492
     * array with {@code length} components and then the contents of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * the temporary array were copied into positions
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   494
     * {@code destPos} through {@code destPos+length-1} of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * destination array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * <p>
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   497
     * If {@code dest} is {@code null}, then a
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   498
     * {@code NullPointerException} is thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * <p>
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   500
     * If {@code src} is {@code null}, then a
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   501
     * {@code NullPointerException} is thrown and the destination
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * array is not modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * Otherwise, if any of the following is true, an
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   505
     * {@code ArrayStoreException} is thrown and the destination is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * not modified:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * <ul>
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   508
     * <li>The {@code src} argument refers to an object that is not an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *     array.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   510
     * <li>The {@code dest} argument refers to an object that is not an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *     array.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   512
     * <li>The {@code src} argument and {@code dest} argument refer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *     to arrays whose component types are different primitive types.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   514
     * <li>The {@code src} argument refers to an array with a primitive
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   515
     *    component type and the {@code dest} argument refers to an array
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *     with a reference component type.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   517
     * <li>The {@code src} argument refers to an array with a reference
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   518
     *    component type and the {@code dest} argument refers to an array
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *     with a primitive component type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * Otherwise, if any of the following is true, an
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   523
     * {@code IndexOutOfBoundsException} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * thrown and the destination is not modified:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * <ul>
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   526
     * <li>The {@code srcPos} argument is negative.
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   527
     * <li>The {@code destPos} argument is negative.
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   528
     * <li>The {@code length} argument is negative.
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   529
     * <li>{@code srcPos+length} is greater than
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   530
     *     {@code src.length}, the length of the source array.
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   531
     * <li>{@code destPos+length} is greater than
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   532
     *     {@code dest.length}, the length of the destination array.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * Otherwise, if any actual component of the source array from
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   536
     * position {@code srcPos} through
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   537
     * {@code srcPos+length-1} cannot be converted to the component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * type of the destination array by assignment conversion, an
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   539
     * {@code ArrayStoreException} is thrown. In this case, let
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * <b><i>k</i></b> be the smallest nonnegative integer less than
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   541
     * length such that {@code src[srcPos+}<i>k</i>{@code ]}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * cannot be converted to the component type of the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * array; when the exception is thrown, source array components from
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   544
     * positions {@code srcPos} through
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   545
     * {@code srcPos+}<i>k</i>{@code -1}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * will already have been copied to destination array positions
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   547
     * {@code destPos} through
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   548
     * {@code destPos+}<i>k</I>{@code -1} and no other
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * positions of the destination array will have been modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * (Because of the restrictions already itemized, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * paragraph effectively applies only to the situation where both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * arrays have component types that are reference types.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @param      src      the source array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * @param      srcPos   starting position in the source array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @param      dest     the destination array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @param      destPos  starting position in the destination data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @param      length   the number of array elements to be copied.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   559
     * @throws     IndexOutOfBoundsException  if copying would cause
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   560
     *             access of data outside array bounds.
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   561
     * @throws     ArrayStoreException  if an element in the {@code src}
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   562
     *             array could not be stored into the {@code dest} array
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   563
     *             because of a type mismatch.
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   564
     * @throws     NullPointerException if either {@code src} or
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   565
     *             {@code dest} is {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     */
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 29986
diff changeset
   567
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    public static native void arraycopy(Object src,  int  srcPos,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                        Object dest, int destPos,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                                        int length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * Returns the same hash code for the given object as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * would be returned by the default method hashCode(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * whether or not the given object's class overrides
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * hashCode().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * The hash code for the null reference is zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @param x object for which the hashCode is to be calculated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @return  the hashCode
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24367
diff changeset
   581
     * @since   1.1
43891
59f9fbf2b7f0 8172928: Add doc link from System.identityHashCode to Object.hashCode
darcy
parents: 43221
diff changeset
   582
     * @see Object#hashCode
59f9fbf2b7f0 8172928: Add doc link from System.identityHashCode to Object.hashCode
darcy
parents: 43221
diff changeset
   583
     * @see java.util.Objects#hashCode(Object)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     */
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 29986
diff changeset
   585
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    public static native int identityHashCode(Object x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * System properties. The following properties are guaranteed to be defined:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * <dt>java.version         <dd>Java version number
48327
d2a837cf9ff1 8192833: JEP 322: Time-Based Release Versioning
mr
parents: 48262
diff changeset
   592
     * <dt>java.version.date    <dd>Java version date
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * <dt>java.vendor          <dd>Java vendor specific string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * <dt>java.vendor.url      <dd>Java vendor URL
48327
d2a837cf9ff1 8192833: JEP 322: Time-Based Release Versioning
mr
parents: 48262
diff changeset
   595
     * <dt>java.vendor.version  <dd>Java vendor version
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * <dt>java.home            <dd>Java installation directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * <dt>java.class.version   <dd>Java class version number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * <dt>java.class.path      <dd>Java classpath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * <dt>os.name              <dd>Operating System Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * <dt>os.arch              <dd>Operating System Architecture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * <dt>os.version           <dd>Operating System Version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * <dt>file.separator       <dd>File separator ("/" on Unix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * <dt>path.separator       <dd>Path separator (":" on Unix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * <dt>line.separator       <dd>Line separator ("\n" on Unix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * <dt>user.name            <dd>User account name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * <dt>user.home            <dd>User home directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * <dt>user.dir             <dd>User's current working directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    private static Properties props;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * Determines the current system properties.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   615
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * First, if there is a security manager, its
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   617
     * {@code checkPropertiesAccess} method is called with no
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * arguments. This may result in a security exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * The current set of system properties for use by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * {@link #getProperty(String)} method is returned as a
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   622
     * {@code Properties} object. If there is no current set of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * system properties, a set of system properties is first created and
55265
d80becbcd3c1 8197927: Allow the system property `java.vendor.version` to be undefined
mr
parents: 55231
diff changeset
   624
     * initialized. This set of system properties includes a value
d80becbcd3c1 8197927: Allow the system property `java.vendor.version` to be undefined
mr
parents: 55231
diff changeset
   625
     * for each of the following keys unless the description of the associated
d80becbcd3c1 8197927: Allow the system property `java.vendor.version` to be undefined
mr
parents: 55231
diff changeset
   626
     * value indicates that the value is optional.
46148
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
   627
     * <table class="striped" style="text-align:left">
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 45005
diff changeset
   628
     * <caption style="display:none">Shows property keys and associated values</caption>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 45005
diff changeset
   629
     * <thead>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45705
diff changeset
   630
     * <tr><th scope="col">Key</th>
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45705
diff changeset
   631
     *     <th scope="col">Description of Associated Value</th></tr>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 45005
diff changeset
   632
     * </thead>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 45005
diff changeset
   633
     * <tbody>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   634
     * <tr><th scope="row">{@systemProperty java.version}</th>
48327
d2a837cf9ff1 8192833: JEP 322: Time-Based Release Versioning
mr
parents: 48262
diff changeset
   635
     *     <td>Java Runtime Environment version, which may be interpreted
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37780
diff changeset
   636
     *     as a {@link Runtime.Version}</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   637
     * <tr><th scope="row">{@systemProperty java.version.date}</th>
48327
d2a837cf9ff1 8192833: JEP 322: Time-Based Release Versioning
mr
parents: 48262
diff changeset
   638
     *     <td>Java Runtime Environment version date, in ISO-8601 YYYY-MM-DD
d2a837cf9ff1 8192833: JEP 322: Time-Based Release Versioning
mr
parents: 48262
diff changeset
   639
     *     format, which may be interpreted as a {@link
d2a837cf9ff1 8192833: JEP 322: Time-Based Release Versioning
mr
parents: 48262
diff changeset
   640
     *     java.time.LocalDate}</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   641
     * <tr><th scope="row">{@systemProperty java.vendor}</th>
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 12038
diff changeset
   642
     *     <td>Java Runtime Environment vendor</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   643
     * <tr><th scope="row">{@systemProperty java.vendor.url}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *     <td>Java vendor URL</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   645
     * <tr><th scope="row">{@systemProperty java.vendor.version}</th>
55265
d80becbcd3c1 8197927: Allow the system property `java.vendor.version` to be undefined
mr
parents: 55231
diff changeset
   646
     *     <td>Java vendor version <em>(optional)</em> </td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   647
     * <tr><th scope="row">{@systemProperty java.home}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *     <td>Java installation directory</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   649
     * <tr><th scope="row">{@systemProperty java.vm.specification.version}</th>
50531
aeb7fb702890 8204565: (spec) Document java.{vm.}?specification.version system properties' relation to $FEATURE
bchristi
parents: 49203
diff changeset
   650
     *     <td>Java Virtual Machine specification version, whose value is the
aeb7fb702890 8204565: (spec) Document java.{vm.}?specification.version system properties' relation to $FEATURE
bchristi
parents: 49203
diff changeset
   651
     *     {@linkplain Runtime.Version#feature feature} element of the
aeb7fb702890 8204565: (spec) Document java.{vm.}?specification.version system properties' relation to $FEATURE
bchristi
parents: 49203
diff changeset
   652
     *     {@linkplain Runtime#version() runtime version}</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   653
     * <tr><th scope="row">{@systemProperty java.vm.specification.vendor}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     *     <td>Java Virtual Machine specification vendor</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   655
     * <tr><th scope="row">{@systemProperty java.vm.specification.name}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *     <td>Java Virtual Machine specification name</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   657
     * <tr><th scope="row">{@systemProperty java.vm.version}</th>
38432
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37780
diff changeset
   658
     *     <td>Java Virtual Machine implementation version which may be
892603099bb0 8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents: 37780
diff changeset
   659
     *     interpreted as a {@link Runtime.Version}</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   660
     * <tr><th scope="row">{@systemProperty java.vm.vendor}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *     <td>Java Virtual Machine implementation vendor</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   662
     * <tr><th scope="row">{@systemProperty java.vm.name}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *     <td>Java Virtual Machine implementation name</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   664
     * <tr><th scope="row">{@systemProperty java.specification.version}</th>
50531
aeb7fb702890 8204565: (spec) Document java.{vm.}?specification.version system properties' relation to $FEATURE
bchristi
parents: 49203
diff changeset
   665
     *     <td>Java Runtime Environment specification version, whose value is
aeb7fb702890 8204565: (spec) Document java.{vm.}?specification.version system properties' relation to $FEATURE
bchristi
parents: 49203
diff changeset
   666
     *     the {@linkplain Runtime.Version#feature feature} element of the
aeb7fb702890 8204565: (spec) Document java.{vm.}?specification.version system properties' relation to $FEATURE
bchristi
parents: 49203
diff changeset
   667
     *     {@linkplain Runtime#version() runtime version}</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   668
     * <tr><th scope="row">{@systemProperty java.specification.vendor}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     *     <td>Java Runtime Environment specification  vendor</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   670
     * <tr><th scope="row">{@systemProperty java.specification.name}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     *     <td>Java Runtime Environment specification  name</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   672
     * <tr><th scope="row">{@systemProperty java.class.version}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     *     <td>Java class format version number</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   674
     * <tr><th scope="row">{@systemProperty java.class.path}</th>
48671
a47ee8b3d308 8191170: Clarify if java.class.path can be undefined
mchung
parents: 48327
diff changeset
   675
     *     <td>Java class path  (refer to
a47ee8b3d308 8191170: Clarify if java.class.path can be undefined
mchung
parents: 48327
diff changeset
   676
     *        {@link ClassLoader#getSystemClassLoader()} for details)</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   677
     * <tr><th scope="row">{@systemProperty java.library.path}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     *     <td>List of paths to search when loading libraries</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   679
     * <tr><th scope="row">{@systemProperty java.io.tmpdir}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     *     <td>Default temp file path</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   681
     * <tr><th scope="row">{@systemProperty java.compiler}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *     <td>Name of JIT compiler to use</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   683
     * <tr><th scope="row">{@systemProperty os.name}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *     <td>Operating system name</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   685
     * <tr><th scope="row">{@systemProperty os.arch}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     *     <td>Operating system architecture</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   687
     * <tr><th scope="row">{@systemProperty os.version}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     *     <td>Operating system version</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   689
     * <tr><th scope="row">{@systemProperty file.separator}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     *     <td>File separator ("/" on UNIX)</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   691
     * <tr><th scope="row">{@systemProperty path.separator}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     *     <td>Path separator (":" on UNIX)</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   693
     * <tr><th scope="row">{@systemProperty line.separator}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     *     <td>Line separator ("\n" on UNIX)</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   695
     * <tr><th scope="row">{@systemProperty user.name}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     *     <td>User's account name</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   697
     * <tr><th scope="row">{@systemProperty user.home}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     *     <td>User's home directory</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   699
     * <tr><th scope="row">{@systemProperty user.dir}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     *     <td>User's current working directory</td></tr>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 45005
diff changeset
   701
     * </tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * Multiple paths in a system property value are separated by the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * separator character of the platform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * Note that even if the security manager does not permit the
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   708
     * {@code getProperties} operation, it may choose to permit the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * {@link #getProperty(String)} operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     *
50817
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   711
     * @apiNote
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   712
     * <strong>Changing a standard system property may have unpredictable results
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   713
     * unless otherwise specified.</strong>
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   714
     * Property values may be cached during initialization or on first use.
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   715
     * Setting a standard property after initialization using {@link #getProperties()},
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   716
     * {@link #setProperties(Properties)}, {@link #setProperty(String, String)}, or
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   717
     * {@link #clearProperty(String)} may not have the desired effect.
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   718
     *
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   719
     * @implNote
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   720
     * In addition to the standard system properties, the system
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 39826
diff changeset
   721
     * properties may include the following keys:
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 45005
diff changeset
   722
     * <table class="striped">
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 45005
diff changeset
   723
     * <caption style="display:none">Shows property keys and associated values</caption>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 45005
diff changeset
   724
     * <thead>
45881
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45705
diff changeset
   725
     * <tr><th scope="col">Key</th>
aaec0fbe17ae 8184208: update class="striped" tables for accessibility
jjg
parents: 45705
diff changeset
   726
     *     <th scope="col">Description of Associated Value</th></tr>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 45005
diff changeset
   727
     * </thead>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 45005
diff changeset
   728
     * <tbody>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   729
     * <tr><th scope="row">{@systemProperty jdk.module.path}</th>
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 39826
diff changeset
   730
     *     <td>The application module path</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   731
     * <tr><th scope="row">{@systemProperty jdk.module.upgrade.path}</th>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   732
     *     <td>The upgrade module path</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   733
     * <tr><th scope="row">{@systemProperty jdk.module.main}</th>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   734
     *     <td>The module name of the initial/main module</td></tr>
52615
9a899e2c3e64 8213920: Use {@systemProperty} tag for properties listed in System.getProperties
pmuthuswamy
parents: 52478
diff changeset
   735
     * <tr><th scope="row">{@systemProperty jdk.module.main.class}</th>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   736
     *     <td>The main class name of the initial module</td></tr>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 45005
diff changeset
   737
     * </tbody>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   738
     * </table>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
   739
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @return     the system properties
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   741
     * @throws     SecurityException  if a security manager exists and its
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   742
     *             {@code checkPropertiesAccess} method doesn't allow access
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   743
     *             to the system properties.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @see        #setProperties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * @see        java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @see        java.lang.SecurityManager#checkPropertiesAccess()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * @see        java.util.Properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    public static Properties getProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            sm.checkPropertiesAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        return props;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    /**
4355
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 3288
diff changeset
   759
     * Returns the system-dependent line separator string.  It always
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 3288
diff changeset
   760
     * returns the same value - the initial value of the {@linkplain
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 3288
diff changeset
   761
     * #getProperty(String) system property} {@code line.separator}.
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 3288
diff changeset
   762
     *
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 3288
diff changeset
   763
     * <p>On UNIX systems, it returns {@code "\n"}; on Microsoft
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 3288
diff changeset
   764
     * Windows systems it returns {@code "\r\n"}.
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 17426
diff changeset
   765
     *
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 17426
diff changeset
   766
     * @return the system-dependent line separator string
10360
d1a6fafde2fa 7082231: Put a @since 1.7 on System.lineSeparator
darcy
parents: 9035
diff changeset
   767
     * @since 1.7
4355
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 3288
diff changeset
   768
     */
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 3288
diff changeset
   769
    public static String lineSeparator() {
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 3288
diff changeset
   770
        return lineSeparator;
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 3288
diff changeset
   771
    }
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 3288
diff changeset
   772
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 3288
diff changeset
   773
    private static String lineSeparator;
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 3288
diff changeset
   774
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 3288
diff changeset
   775
    /**
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   776
     * Sets the system properties to the {@code Properties} argument.
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   777
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * First, if there is a security manager, its
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   779
     * {@code checkPropertiesAccess} method is called with no
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * arguments. This may result in a security exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * The argument becomes the current set of system properties for use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * by the {@link #getProperty(String)} method. If the argument is
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   784
     * {@code null}, then the current set of system properties is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * forgotten.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     *
50817
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   787
     * @apiNote
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   788
     * <strong>Changing a standard system property may have unpredictable results
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   789
     * unless otherwise specified</strong>.
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   790
     * See {@linkplain #getProperties getProperties} for details.
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   791
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * @param      props   the new system properties.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   793
     * @throws     SecurityException  if a security manager exists and its
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   794
     *             {@code checkPropertiesAccess} method doesn't allow access
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   795
     *             to the system properties.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * @see        #getProperties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * @see        java.util.Properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @see        java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * @see        java.lang.SecurityManager#checkPropertiesAccess()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    public static void setProperties(Properties props) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            sm.checkPropertiesAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52615
diff changeset
   806
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        if (props == null) {
52978
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
   808
            Map<String, String> tempProps = SystemProps.initProperties();
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
   809
            VersionProps.init(tempProps);
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
   810
            props = createProperties(tempProps);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        System.props = props;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * Gets the system property indicated by the specified key.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   817
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * First, if there is a security manager, its
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   819
     * {@code checkPropertyAccess} method is called with the key as
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * its argument. This may result in a SecurityException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * If there is no current set of system properties, a set of system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * properties is first created and initialized in the same manner as
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   824
     * for the {@code getProperties} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     *
50817
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   826
     * @apiNote
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   827
     * <strong>Changing a standard system property may have unpredictable results
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   828
     * unless otherwise specified</strong>.
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   829
     * See {@linkplain #getProperties getProperties} for details.
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   830
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * @param      key   the name of the system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * @return     the string value of the system property,
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   833
     *             or {@code null} if there is no property with that key.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     *
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   835
     * @throws     SecurityException  if a security manager exists and its
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   836
     *             {@code checkPropertyAccess} method doesn't allow
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   837
     *             access to the specified system property.
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   838
     * @throws     NullPointerException if {@code key} is {@code null}.
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   839
     * @throws     IllegalArgumentException if {@code key} is empty.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * @see        #setProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * @see        java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * @see        java.lang.System#getProperties()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    public static String getProperty(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        checkKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            sm.checkPropertyAccess(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        return props.getProperty(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * Gets the system property indicated by the specified key.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   857
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * First, if there is a security manager, its
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   859
     * {@code checkPropertyAccess} method is called with the
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   860
     * {@code key} as its argument.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * If there is no current set of system properties, a set of system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * properties is first created and initialized in the same manner as
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   864
     * for the {@code getProperties} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * @param      key   the name of the system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * @param      def   a default value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * @return     the string value of the system property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     *             or the default value if there is no property with that key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     *
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   871
     * @throws     SecurityException  if a security manager exists and its
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   872
     *             {@code checkPropertyAccess} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     *             access to the specified system property.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   874
     * @throws     NullPointerException if {@code key} is {@code null}.
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   875
     * @throws     IllegalArgumentException if {@code key} is empty.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * @see        #setProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * @see        java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * @see        java.lang.System#getProperties()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    public static String getProperty(String key, String def) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        checkKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            sm.checkPropertyAccess(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        return props.getProperty(key, def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * Sets the system property indicated by the specified key.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   892
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * First, if a security manager exists, its
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   894
     * {@code SecurityManager.checkPermission} method
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   895
     * is called with a {@code PropertyPermission(key, "write")}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * permission. This may result in a SecurityException being thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * If no exception is thrown, the specified property is set to the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     *
50817
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   900
     * @apiNote
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   901
     * <strong>Changing a standard system property may have unpredictable results
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   902
     * unless otherwise specified</strong>.
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   903
     * See {@linkplain #getProperties getProperties} for details.
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   904
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * @param      key   the name of the system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * @param      value the value of the system property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * @return     the previous value of the system property,
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   908
     *             or {@code null} if it did not have one.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     *
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   910
     * @throws     SecurityException  if a security manager exists and its
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   911
     *             {@code checkPermission} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     *             setting of the specified property.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   913
     * @throws     NullPointerException if {@code key} or
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   914
     *             {@code value} is {@code null}.
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   915
     * @throws     IllegalArgumentException if {@code key} is empty.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * @see        #getProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * @see        java.lang.System#getProperty(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * @see        java.lang.System#getProperty(java.lang.String, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * @see        java.util.PropertyPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * @see        SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    public static String setProperty(String key, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        checkKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            sm.checkPermission(new PropertyPermission(key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                SecurityConstants.PROPERTY_WRITE_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        return (String) props.setProperty(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * Removes the system property indicated by the specified key.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   936
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * First, if a security manager exists, its
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   938
     * {@code SecurityManager.checkPermission} method
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   939
     * is called with a {@code PropertyPermission(key, "write")}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * permission. This may result in a SecurityException being thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * If no exception is thrown, the specified property is removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     *
50817
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   943
     * @apiNote
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   944
     * <strong>Changing a standard system property may have unpredictable results
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   945
     * unless otherwise specified</strong>.
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   946
     * See {@linkplain #getProperties getProperties} method for details.
fa1e04811ff6 8066709: Make some JDK system properties read only
rriggs
parents: 50552
diff changeset
   947
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * @param      key   the name of the system property to be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * @return     the previous string value of the system property,
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   950
     *             or {@code null} if there was no property with that key.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     *
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   952
     * @throws     SecurityException  if a security manager exists and its
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   953
     *             {@code checkPropertyAccess} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     *              access to the specified system property.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   955
     * @throws     NullPointerException if {@code key} is {@code null}.
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   956
     * @throws     IllegalArgumentException if {@code key} is empty.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * @see        #getProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * @see        #setProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * @see        java.util.Properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * @see        java.lang.SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * @see        java.lang.SecurityManager#checkPropertiesAccess()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    public static String clearProperty(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        checkKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            sm.checkPermission(new PropertyPermission(key, "write"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        return (String) props.remove(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    private static void checkKey(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        if (key == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            throw new NullPointerException("key can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        }
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 52724
diff changeset
   978
        if (key.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            throw new IllegalArgumentException("key can't be empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * Gets the value of the specified environment variable. An
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * environment variable is a system-dependent external named
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * <p>If a security manager exists, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * {@link SecurityManager#checkPermission checkPermission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * method is called with a
53160
7d1efad039a3 8216205: Java API documentation formatting error in System.getEnv
rriggs
parents: 52978
diff changeset
   991
     * {@link RuntimePermission RuntimePermission("getenv."+name)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * permission.  This may result in a {@link SecurityException}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * being thrown.  If no exception is thrown the value of the
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
   994
     * variable {@code name} is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     *
44844
b2b4d98404ba 8179364: update "<a name=" in java.base module to use id attribute
jjg
parents: 44667
diff changeset
   996
     * <p><a id="EnvironmentVSSystemProperties"><i>System
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * properties</i> and <i>environment variables</i></a> are both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * conceptually mappings between names and values.  Both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * mechanisms can be used to pass user-defined information to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * Java process.  Environment variables have a more global effect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * because they are visible to all descendants of the process
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * which defines them, not just the immediate Java subprocess.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * They can have subtly different semantics, such as case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * insensitivity, on different operating systems.  For these
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * reasons, environment variables are more likely to have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * unintended side effects.  It is best to use system properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * where possible.  Environment variables should be used when a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * global effect is desired, or when an external system interface
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1009
     * requires an environment variable (such as {@code PATH}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     *
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1011
     * <p>On UNIX systems the alphabetic case of {@code name} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * typically significant, while on Microsoft Windows systems it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * typically not.  For example, the expression
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1014
     * {@code System.getenv("FOO").equals(System.getenv("foo"))}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * is likely to be true on Microsoft Windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * @param  name the name of the environment variable
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1018
     * @return the string value of the variable, or {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     *         if the variable is not defined in the system environment
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1020
     * @throws NullPointerException if {@code name} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     *         if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     *         {@link SecurityManager#checkPermission checkPermission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     *         method doesn't allow access to the environment variable
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1025
     *         {@code name}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * @see    #getenv()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * @see    ProcessBuilder#environment()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    public static String getenv(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            sm.checkPermission(new RuntimePermission("getenv."+name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        return ProcessEnvironment.getenv(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * Returns an unmodifiable string map view of the current system environment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * The environment is a system-dependent mapping from names to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * values which is passed from parent to child processes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * <p>If the system does not support environment variables, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * empty map is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * <p>The returned map will never contain null keys or values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * Attempting to query the presence of a null key or value will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * throw a {@link NullPointerException}.  Attempting to query
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * the presence of a key or value which is not of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * {@link String} will throw a {@link ClassCastException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * <p>The returned map and its collection views may not obey the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * general contract of the {@link Object#equals} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * {@link Object#hashCode} methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * <p>The returned map is typically case-sensitive on all platforms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * <p>If a security manager exists, its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * {@link SecurityManager#checkPermission checkPermission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * method is called with a
53160
7d1efad039a3 8216205: Java API documentation formatting error in System.getEnv
rriggs
parents: 52978
diff changeset
  1062
     * {@link RuntimePermission RuntimePermission("getenv.*")} permission.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1063
     * This may result in a {@link SecurityException} being thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * <p>When passing information to a Java subprocess,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * <a href=#EnvironmentVSSystemProperties>system properties</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * are generally preferred over environment variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * @return the environment as a map of variable names to values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     *         if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     *         {@link SecurityManager#checkPermission checkPermission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     *         method doesn't allow access to the process environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * @see    #getenv(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * @see    ProcessBuilder#environment()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    public static java.util.Map<String,String> getenv() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        SecurityManager sm = getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            sm.checkPermission(new RuntimePermission("getenv.*"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        return ProcessEnvironment.getenv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    /**
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1088
     * {@code System.Logger} instances log messages that will be
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1089
     * routed to the underlying logging framework the {@link System.LoggerFinder
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1090
     * LoggerFinder} uses.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1091
     *
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1092
     * {@code System.Logger} instances are typically obtained from
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1093
     * the {@link java.lang.System System} class, by calling
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1094
     * {@link java.lang.System#getLogger(java.lang.String) System.getLogger(loggerName)}
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1095
     * or {@link java.lang.System#getLogger(java.lang.String, java.util.ResourceBundle)
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1096
     * System.getLogger(loggerName, bundle)}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1097
     *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1098
     * @see java.lang.System#getLogger(java.lang.String)
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1099
     * @see java.lang.System#getLogger(java.lang.String, java.util.ResourceBundle)
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1100
     * @see java.lang.System.LoggerFinder
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1101
     *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1102
     * @since 9
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1103
     */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1104
    public interface Logger {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1105
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1106
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1107
         * System {@linkplain Logger loggers} levels.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1108
         *
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1109
         * A level has a {@linkplain #getName() name} and {@linkplain
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1110
         * #getSeverity() severity}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1111
         * Level values are {@link #ALL}, {@link #TRACE}, {@link #DEBUG},
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1112
         * {@link #INFO}, {@link #WARNING}, {@link #ERROR}, {@link #OFF},
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1113
         * by order of increasing severity.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1114
         * <br>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1115
         * {@link #ALL} and {@link #OFF}
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1116
         * are simple markers with severities mapped respectively to
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1117
         * {@link java.lang.Integer#MIN_VALUE Integer.MIN_VALUE} and
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1118
         * {@link java.lang.Integer#MAX_VALUE Integer.MAX_VALUE}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1119
         * <p>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1120
         * <b>Severity values and Mapping to {@code java.util.logging.Level}.</b>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1121
         * <p>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1122
         * {@linkplain System.Logger.Level System logger levels} are mapped to
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1123
         * {@linkplain java.util.logging.Level  java.util.logging levels}
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1124
         * of corresponding severity.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1125
         * <br>The mapping is as follows:
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1126
         * <br><br>
46148
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1127
         * <table class="striped">
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1128
         * <caption>System.Logger Severity Level Mapping</caption>
46148
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1129
         * <thead>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1130
         * <tr><th scope="col">System.Logger Levels</th>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1131
         *     <th scope="col">java.util.logging Levels</th>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1132
         * </thead>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1133
         * <tbody>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1134
         * <tr><th scope="row">{@link Logger.Level#ALL ALL}</th>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1135
         *     <td>{@link java.util.logging.Level#ALL ALL}</td>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1136
         * <tr><th scope="row">{@link Logger.Level#TRACE TRACE}</th>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1137
         *     <td>{@link java.util.logging.Level#FINER FINER}</td>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1138
         * <tr><th scope="row">{@link Logger.Level#DEBUG DEBUG}</th>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1139
         *     <td>{@link java.util.logging.Level#FINE FINE}</td>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1140
         * <tr><th scope="row">{@link Logger.Level#INFO INFO}</th>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1141
         *     <td>{@link java.util.logging.Level#INFO INFO}</td>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1142
         * <tr><th scope="row">{@link Logger.Level#WARNING WARNING}</th>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1143
         *     <td>{@link java.util.logging.Level#WARNING WARNING}</td>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1144
         * <tr><th scope="row">{@link Logger.Level#ERROR ERROR}</th>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1145
         *     <td>{@link java.util.logging.Level#SEVERE SEVERE}</td>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1146
         * <tr><th scope="row">{@link Logger.Level#OFF OFF}</th>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1147
         *     <td>{@link java.util.logging.Level#OFF OFF}</td>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 46096
diff changeset
  1148
         * </tbody>
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1149
         * </table>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1150
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1151
         * @since 9
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1152
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1153
         * @see java.lang.System.LoggerFinder
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1154
         * @see java.lang.System.Logger
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1155
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1156
        public enum Level {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1157
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1158
            // for convenience, we're reusing java.util.logging.Level int values
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1159
            // the mapping logic in sun.util.logging.PlatformLogger depends
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1160
            // on this.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1161
            /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1162
             * A marker to indicate that all levels are enabled.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1163
             * This level {@linkplain #getSeverity() severity} is
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1164
             * {@link Integer#MIN_VALUE}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1165
             */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1166
            ALL(Integer.MIN_VALUE),  // typically mapped to/from j.u.l.Level.ALL
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1167
            /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1168
             * {@code TRACE} level: usually used to log diagnostic information.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1169
             * This level {@linkplain #getSeverity() severity} is
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1170
             * {@code 400}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1171
             */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1172
            TRACE(400),   // typically mapped to/from j.u.l.Level.FINER
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1173
            /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1174
             * {@code DEBUG} level: usually used to log debug information traces.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1175
             * This level {@linkplain #getSeverity() severity} is
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1176
             * {@code 500}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1177
             */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1178
            DEBUG(500),   // typically mapped to/from j.u.l.Level.FINEST/FINE/CONFIG
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1179
            /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1180
             * {@code INFO} level: usually used to log information messages.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1181
             * This level {@linkplain #getSeverity() severity} is
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1182
             * {@code 800}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1183
             */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1184
            INFO(800),    // typically mapped to/from j.u.l.Level.INFO
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1185
            /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1186
             * {@code WARNING} level: usually used to log warning messages.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1187
             * This level {@linkplain #getSeverity() severity} is
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1188
             * {@code 900}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1189
             */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1190
            WARNING(900), // typically mapped to/from j.u.l.Level.WARNING
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1191
            /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1192
             * {@code ERROR} level: usually used to log error messages.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1193
             * This level {@linkplain #getSeverity() severity} is
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1194
             * {@code 1000}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1195
             */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1196
            ERROR(1000),  // typically mapped to/from j.u.l.Level.SEVERE
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1197
            /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1198
             * A marker to indicate that all levels are disabled.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1199
             * This level {@linkplain #getSeverity() severity} is
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1200
             * {@link Integer#MAX_VALUE}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1201
             */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1202
            OFF(Integer.MAX_VALUE);  // typically mapped to/from j.u.l.Level.OFF
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1203
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1204
            private final int severity;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1205
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1206
            private Level(int severity) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1207
                this.severity = severity;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1208
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1209
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1210
            /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1211
             * Returns the name of this level.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1212
             * @return this level {@linkplain #name()}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1213
             */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1214
            public final String getName() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1215
                return name();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1216
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1217
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1218
            /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1219
             * Returns the severity of this level.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1220
             * A higher severity means a more severe condition.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1221
             * @return this level severity.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1222
             */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1223
            public final int getSeverity() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1224
                return severity;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1225
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1226
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1227
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1228
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1229
         * Returns the name of this logger.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1230
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1231
         * @return the logger name.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1232
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1233
        public String getName();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1234
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1235
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1236
         * Checks if a message of the given level would be logged by
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1237
         * this logger.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1238
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1239
         * @param level the log message level.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1240
         * @return {@code true} if the given log message level is currently
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1241
         *         being logged.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1242
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1243
         * @throws NullPointerException if {@code level} is {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1244
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1245
        public boolean isLoggable(Level level);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1246
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1247
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1248
         * Logs a message.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1249
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1250
         * @implSpec The default implementation for this method calls
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1251
         * {@code this.log(level, (ResourceBundle)null, msg, (Object[])null);}
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1252
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1253
         * @param level the log message level.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1254
         * @param msg the string message (or a key in the message catalog, if
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1255
         * this logger is a {@link
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1256
         * LoggerFinder#getLocalizedLogger(java.lang.String,
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  1257
         * java.util.ResourceBundle, java.lang.Module) localized logger});
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1258
         * can be {@code null}.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1259
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1260
         * @throws NullPointerException if {@code level} is {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1261
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1262
        public default void log(Level level, String msg) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1263
            log(level, (ResourceBundle) null, msg, (Object[]) null);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1264
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1265
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1266
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1267
         * Logs a lazily supplied message.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1268
         *
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1269
         * If the logger is currently enabled for the given log message level
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1270
         * then a message is logged that is the result produced by the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1271
         * given supplier function.  Otherwise, the supplier is not operated on.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1272
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1273
         * @implSpec When logging is enabled for the given level, the default
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1274
         * implementation for this method calls
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1275
         * {@code this.log(level, (ResourceBundle)null, msgSupplier.get(), (Object[])null);}
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1276
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1277
         * @param level the log message level.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1278
         * @param msgSupplier a supplier function that produces a message.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1279
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1280
         * @throws NullPointerException if {@code level} is {@code null},
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1281
         *         or {@code msgSupplier} is {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1282
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1283
        public default void log(Level level, Supplier<String> msgSupplier) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1284
            Objects.requireNonNull(msgSupplier);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1285
            if (isLoggable(Objects.requireNonNull(level))) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1286
                log(level, (ResourceBundle) null, msgSupplier.get(), (Object[]) null);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1287
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1288
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1289
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1290
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1291
         * Logs a message produced from the given object.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1292
         *
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1293
         * If the logger is currently enabled for the given log message level then
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1294
         * a message is logged that, by default, is the result produced from
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1295
         * calling  toString on the given object.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1296
         * Otherwise, the object is not operated on.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1297
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1298
         * @implSpec When logging is enabled for the given level, the default
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1299
         * implementation for this method calls
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1300
         * {@code this.log(level, (ResourceBundle)null, obj.toString(), (Object[])null);}
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1301
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1302
         * @param level the log message level.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1303
         * @param obj the object to log.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1304
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1305
         * @throws NullPointerException if {@code level} is {@code null}, or
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1306
         *         {@code obj} is {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1307
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1308
        public default void log(Level level, Object obj) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1309
            Objects.requireNonNull(obj);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1310
            if (isLoggable(Objects.requireNonNull(level))) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1311
                this.log(level, (ResourceBundle) null, obj.toString(), (Object[]) null);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1312
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1313
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1314
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1315
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1316
         * Logs a message associated with a given throwable.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1317
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1318
         * @implSpec The default implementation for this method calls
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1319
         * {@code this.log(level, (ResourceBundle)null, msg, thrown);}
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1320
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1321
         * @param level the log message level.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1322
         * @param msg the string message (or a key in the message catalog, if
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1323
         * this logger is a {@link
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1324
         * LoggerFinder#getLocalizedLogger(java.lang.String,
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  1325
         * java.util.ResourceBundle, java.lang.Module) localized logger});
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1326
         * can be {@code null}.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1327
         * @param thrown a {@code Throwable} associated with the log message;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1328
         *        can be {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1329
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1330
         * @throws NullPointerException if {@code level} is {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1331
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1332
        public default void log(Level level, String msg, Throwable thrown) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1333
            this.log(level, null, msg, thrown);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1334
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1335
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1336
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1337
         * Logs a lazily supplied message associated with a given throwable.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1338
         *
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1339
         * If the logger is currently enabled for the given log message level
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1340
         * then a message is logged that is the result produced by the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1341
         * given supplier function.  Otherwise, the supplier is not operated on.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1342
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1343
         * @implSpec When logging is enabled for the given level, the default
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1344
         * implementation for this method calls
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1345
         * {@code this.log(level, (ResourceBundle)null, msgSupplier.get(), thrown);}
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1346
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1347
         * @param level one of the log message level identifiers.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1348
         * @param msgSupplier a supplier function that produces a message.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1349
         * @param thrown a {@code Throwable} associated with log message;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1350
         *               can be {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1351
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1352
         * @throws NullPointerException if {@code level} is {@code null}, or
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1353
         *                               {@code msgSupplier} is {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1354
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1355
        public default void log(Level level, Supplier<String> msgSupplier,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1356
                Throwable thrown) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1357
            Objects.requireNonNull(msgSupplier);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1358
            if (isLoggable(Objects.requireNonNull(level))) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1359
                this.log(level, null, msgSupplier.get(), thrown);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1360
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1361
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1362
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1363
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1364
         * Logs a message with an optional list of parameters.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1365
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1366
         * @implSpec The default implementation for this method calls
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1367
         * {@code this.log(level, (ResourceBundle)null, format, params);}
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1368
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1369
         * @param level one of the log message level identifiers.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1370
         * @param format the string message format in {@link
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1371
         * java.text.MessageFormat} format, (or a key in the message
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1372
         * catalog, if this logger is a {@link
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1373
         * LoggerFinder#getLocalizedLogger(java.lang.String,
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  1374
         * java.util.ResourceBundle, java.lang.Module) localized logger});
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1375
         * can be {@code null}.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1376
         * @param params an optional list of parameters to the message (may be
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1377
         * none).
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1378
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1379
         * @throws NullPointerException if {@code level} is {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1380
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1381
        public default void log(Level level, String format, Object... params) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1382
            this.log(level, null, format, params);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1383
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1384
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1385
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1386
         * Logs a localized message associated with a given throwable.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1387
         *
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1388
         * If the given resource bundle is non-{@code null},  the {@code msg}
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1389
         * string is localized using the given resource bundle.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1390
         * Otherwise the {@code msg} string is not localized.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1391
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1392
         * @param level the log message level.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1393
         * @param bundle a resource bundle to localize {@code msg}; can be
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1394
         * {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1395
         * @param msg the string message (or a key in the message catalog,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1396
         *            if {@code bundle} is not {@code null}); can be {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1397
         * @param thrown a {@code Throwable} associated with the log message;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1398
         *        can be {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1399
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1400
         * @throws NullPointerException if {@code level} is {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1401
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1402
        public void log(Level level, ResourceBundle bundle, String msg,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1403
                Throwable thrown);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1404
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1405
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1406
         * Logs a message with resource bundle and an optional list of
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1407
         * parameters.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1408
         *
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1409
         * If the given resource bundle is non-{@code null},  the {@code format}
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1410
         * string is localized using the given resource bundle.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1411
         * Otherwise the {@code format} string is not localized.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1412
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1413
         * @param level the log message level.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1414
         * @param bundle a resource bundle to localize {@code format}; can be
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1415
         * {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1416
         * @param format the string message format in {@link
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1417
         * java.text.MessageFormat} format, (or a key in the message
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1418
         * catalog if {@code bundle} is not {@code null}); can be {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1419
         * @param params an optional list of parameters to the message (may be
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1420
         * none).
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1421
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1422
         * @throws NullPointerException if {@code level} is {@code null}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1423
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1424
        public void log(Level level, ResourceBundle bundle, String format,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1425
                Object... params);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1426
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1427
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1428
    /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1429
     * The {@code LoggerFinder} service is responsible for creating, managing,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1430
     * and configuring loggers to the underlying framework it uses.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1431
     *
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1432
     * A logger finder is a concrete implementation of this class that has a
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1433
     * zero-argument constructor and implements the abstract methods defined
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1434
     * by this class.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1435
     * The loggers returned from a logger finder are capable of routing log
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1436
     * messages to the logging backend this provider supports.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1437
     * A given invocation of the Java Runtime maintains a single
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1438
     * system-wide LoggerFinder instance that is loaded as follows:
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1439
     * <ul>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1440
     *    <li>First it finds any custom {@code LoggerFinder} provider
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1441
     *        using the {@link java.util.ServiceLoader} facility with the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1442
     *        {@linkplain ClassLoader#getSystemClassLoader() system class
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1443
     *        loader}.</li>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1444
     *    <li>If no {@code LoggerFinder} provider is found, the system default
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1445
     *        {@code LoggerFinder} implementation will be used.</li>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1446
     * </ul>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1447
     * <p>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1448
     * An application can replace the logging backend
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1449
     * <i>even when the java.logging module is present</i>, by simply providing
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1450
     * and declaring an implementation of the {@link LoggerFinder} service.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1451
     * <p>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1452
     * <b>Default Implementation</b>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1453
     * <p>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1454
     * The system default {@code LoggerFinder} implementation uses
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1455
     * {@code java.util.logging} as the backend framework when the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1456
     * {@code java.logging} module is present.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1457
     * It returns a {@linkplain System.Logger logger} instance
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1458
     * that will route log messages to a {@link java.util.logging.Logger
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1459
     * java.util.logging.Logger}. Otherwise, if {@code java.logging} is not
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1460
     * present, the default implementation will return a simple logger
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1461
     * instance that will route log messages of {@code INFO} level and above to
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1462
     * the console ({@code System.err}).
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1463
     * <p>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1464
     * <b>Logging Configuration</b>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1465
     * <p>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1466
     * {@linkplain Logger Logger} instances obtained from the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1467
     * {@code LoggerFinder} factory methods are not directly configurable by
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1468
     * the application. Configuration is the responsibility of the underlying
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1469
     * logging backend, and usually requires using APIs specific to that backend.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1470
     * <p>For the default {@code LoggerFinder} implementation
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1471
     * using {@code java.util.logging} as its backend, refer to
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1472
     * {@link java.util.logging java.util.logging} for logging configuration.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1473
     * For the default {@code LoggerFinder} implementation returning simple loggers
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1474
     * when the {@code java.logging} module is absent, the configuration
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1475
     * is implementation dependent.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1476
     * <p>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1477
     * Usually an application that uses a logging framework will log messages
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1478
     * through a logger facade defined (or supported) by that framework.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1479
     * Applications that wish to use an external framework should log
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1480
     * through the facade associated with that framework.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1481
     * <p>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1482
     * A system class that needs to log messages will typically obtain
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1483
     * a {@link System.Logger} instance to route messages to the logging
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1484
     * framework selected by the application.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1485
     * <p>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1486
     * Libraries and classes that only need loggers to produce log messages
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1487
     * should not attempt to configure loggers by themselves, as that
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1488
     * would make them dependent from a specific implementation of the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1489
     * {@code LoggerFinder} service.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1490
     * <p>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1491
     * In addition, when a security manager is present, loggers provided to
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1492
     * system classes should not be directly configurable through the logging
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1493
     * backend without requiring permissions.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1494
     * <br>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1495
     * It is the responsibility of the provider of
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1496
     * the concrete {@code LoggerFinder} implementation to ensure that
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1497
     * these loggers are not configured by untrusted code without proper
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1498
     * permission checks, as configuration performed on such loggers usually
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1499
     * affects all applications in the same Java Runtime.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1500
     * <p>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1501
     * <b>Message Levels and Mapping to backend levels</b>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1502
     * <p>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1503
     * A logger finder is responsible for mapping from a {@code
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1504
     * System.Logger.Level} to a level supported by the logging backend it uses.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1505
     * <br>The default LoggerFinder using {@code java.util.logging} as the backend
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1506
     * maps {@code System.Logger} levels to
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1507
     * {@linkplain java.util.logging.Level java.util.logging} levels
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1508
     * of corresponding severity - as described in {@link Logger.Level
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1509
     * Logger.Level}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1510
     *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1511
     * @see java.lang.System
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1512
     * @see java.lang.System.Logger
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1513
     *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1514
     * @since 9
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1515
     */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1516
    public static abstract class LoggerFinder {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1517
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1518
         * The {@code RuntimePermission("loggerFinder")} is
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1519
         * necessary to subclass and instantiate the {@code LoggerFinder} class,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1520
         * as well as to obtain loggers from an instance of that class.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1521
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1522
        static final RuntimePermission LOGGERFINDER_PERMISSION =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1523
                new RuntimePermission("loggerFinder");
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1524
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1525
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1526
         * Creates a new instance of {@code LoggerFinder}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1527
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1528
         * @implNote It is recommended that a {@code LoggerFinder} service
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1529
         *   implementation does not perform any heavy initialization in its
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1530
         *   constructor, in order to avoid possible risks of deadlock or class
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1531
         *   loading cycles during the instantiation of the service provider.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1532
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1533
         * @throws SecurityException if a security manager is present and its
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1534
         *         {@code checkPermission} method doesn't allow the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1535
         *         {@code RuntimePermission("loggerFinder")}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1536
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1537
        protected LoggerFinder() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1538
            this(checkPermission());
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1539
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1540
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1541
        private LoggerFinder(Void unused) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1542
            // nothing to do.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1543
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1544
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1545
        private static Void checkPermission() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1546
            final SecurityManager sm = System.getSecurityManager();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1547
            if (sm != null) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1548
                sm.checkPermission(LOGGERFINDER_PERMISSION);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1549
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1550
            return null;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1551
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1552
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1553
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1554
         * Returns an instance of {@link Logger Logger}
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1555
         * for the given {@code module}.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1556
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1557
         * @param name the name of the logger.
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1558
         * @param module the module for which the logger is being requested.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1559
         *
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1560
         * @return a {@link Logger logger} suitable for use within the given
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1561
         *         module.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1562
         * @throws NullPointerException if {@code name} is {@code null} or
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1563
         *        {@code module} is {@code null}.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1564
         * @throws SecurityException if a security manager is present and its
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1565
         *         {@code checkPermission} method doesn't allow the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1566
         *         {@code RuntimePermission("loggerFinder")}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1567
         */
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1568
        public abstract Logger getLogger(String name, Module module);
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1569
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1570
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1571
         * Returns a localizable instance of {@link Logger Logger}
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1572
         * for the given {@code module}.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1573
         * The returned logger will use the provided resource bundle for
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1574
         * message localization.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1575
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1576
         * @implSpec By default, this method calls {@link
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  1577
         * #getLogger(java.lang.String, java.lang.Module)
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1578
         * this.getLogger(name, module)} to obtain a logger, then wraps that
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1579
         * logger in a {@link Logger} instance where all methods that do not
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1580
         * take a {@link ResourceBundle} as parameter are redirected to one
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1581
         * which does - passing the given {@code bundle} for
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1582
         * localization. So for instance, a call to {@link
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1583
         * Logger#log(Logger.Level, String) Logger.log(Level.INFO, msg)}
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1584
         * will end up as a call to {@link
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1585
         * Logger#log(Logger.Level, ResourceBundle, String, Object...)
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1586
         * Logger.log(Level.INFO, bundle, msg, (Object[])null)} on the wrapped
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1587
         * logger instance.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1588
         * Note however that by default, string messages returned by {@link
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1589
         * java.util.function.Supplier Supplier&lt;String&gt;} will not be
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1590
         * localized, as it is assumed that such strings are messages which are
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1591
         * already constructed, rather than keys in a resource bundle.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1592
         * <p>
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1593
         * An implementation of {@code LoggerFinder} may override this method,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1594
         * for example, when the underlying logging backend provides its own
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1595
         * mechanism for localizing log messages, then such a
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1596
         * {@code LoggerFinder} would be free to return a logger
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1597
         * that makes direct use of the mechanism provided by the backend.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1598
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1599
         * @param name    the name of the logger.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1600
         * @param bundle  a resource bundle; can be {@code null}.
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1601
         * @param module  the module for which the logger is being requested.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1602
         * @return an instance of {@link Logger Logger}  which will use the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1603
         * provided resource bundle for message localization.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1604
         *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1605
         * @throws NullPointerException if {@code name} is {@code null} or
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1606
         *         {@code module} is {@code null}.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1607
         * @throws SecurityException if a security manager is present and its
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1608
         *         {@code checkPermission} method doesn't allow the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1609
         *         {@code RuntimePermission("loggerFinder")}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1610
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1611
        public Logger getLocalizedLogger(String name, ResourceBundle bundle,
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1612
                                         Module module) {
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1613
            return new LocalizedLoggerWrapper<>(getLogger(name, module), bundle);
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1614
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1615
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1616
        /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1617
         * Returns the {@code LoggerFinder} instance. There is one
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1618
         * single system-wide {@code LoggerFinder} instance in
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1619
         * the Java Runtime.  See the class specification of how the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1620
         * {@link LoggerFinder LoggerFinder} implementation is located and
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1621
         * loaded.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1622
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1623
         * @return the {@link LoggerFinder LoggerFinder} instance.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1624
         * @throws SecurityException if a security manager is present and its
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1625
         *         {@code checkPermission} method doesn't allow the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1626
         *         {@code RuntimePermission("loggerFinder")}.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1627
         */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1628
        public static LoggerFinder getLoggerFinder() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1629
            final SecurityManager sm = System.getSecurityManager();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1630
            if (sm != null) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1631
                sm.checkPermission(LOGGERFINDER_PERMISSION);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1632
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1633
            return accessProvider();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1634
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1635
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1636
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1637
        private static volatile LoggerFinder service;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1638
        static LoggerFinder accessProvider() {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1639
            // We do not need to synchronize: LoggerFinderLoader will
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1640
            // always return the same instance, so if we don't have it,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1641
            // just fetch it again.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1642
            if (service == null) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1643
                PrivilegedAction<LoggerFinder> pa =
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1644
                        () -> LoggerFinderLoader.getLoggerFinder();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1645
                service = AccessController.doPrivileged(pa, null,
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1646
                        LOGGERFINDER_PERMISSION);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1647
            }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1648
            return service;
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1649
        }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1650
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1651
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1652
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1653
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1654
    /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1655
     * Returns an instance of {@link Logger Logger} for the caller's
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1656
     * use.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1657
     *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1658
     * @implSpec
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1659
     * Instances returned by this method route messages to loggers
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1660
     * obtained by calling {@link LoggerFinder#getLogger(java.lang.String,
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  1661
     * java.lang.Module) LoggerFinder.getLogger(name, module)}, where
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1662
     * {@code module} is the caller's module.
44416
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1663
     * In cases where {@code System.getLogger} is called from a context where
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1664
     * there is no caller frame on the stack (e.g when called directly
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1665
     * from a JNI attached thread), {@code IllegalCallerException} is thrown.
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1666
     * To obtain a logger in such a context, use an auxiliary class that will
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1667
     * implicitly be identified as the caller, or use the system {@link
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1668
     * LoggerFinder#getLoggerFinder() LoggerFinder} to obtain a logger instead.
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1669
     * Note that doing the latter may eagerly initialize the underlying
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1670
     * logging system.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1671
     *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1672
     * @apiNote
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1673
     * This method may defer calling the {@link
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  1674
     * LoggerFinder#getLogger(java.lang.String, java.lang.Module)
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1675
     * LoggerFinder.getLogger} method to create an actual logger supplied by
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1676
     * the logging backend, for instance, to allow loggers to be obtained during
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1677
     * the system initialization time.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1678
     *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1679
     * @param name the name of the logger.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1680
     * @return an instance of {@link Logger} that can be used by the calling
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1681
     *         class.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1682
     * @throws NullPointerException if {@code name} is {@code null}.
44416
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1683
     * @throws IllegalCallerException if there is no Java caller frame on the
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1684
     *         stack.
34933
09a3dab8e1f9 8146691: @since 9 tag missing for System.getLogger
dfuchs
parents: 34882
diff changeset
  1685
     *
09a3dab8e1f9 8146691: @since 9 tag missing for System.getLogger
dfuchs
parents: 34882
diff changeset
  1686
     * @since 9
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1687
     */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1688
    @CallerSensitive
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1689
    public static Logger getLogger(String name) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1690
        Objects.requireNonNull(name);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1691
        final Class<?> caller = Reflection.getCallerClass();
44416
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1692
        if (caller == null) {
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1693
            throw new IllegalCallerException("no caller frame");
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1694
        }
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1695
        return LazyLoggers.getLogger(name, caller.getModule());
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1696
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1697
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1698
    /**
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1699
     * Returns a localizable instance of {@link Logger
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1700
     * Logger} for the caller's use.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1701
     * The returned logger will use the provided resource bundle for message
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1702
     * localization.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1703
     *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1704
     * @implSpec
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1705
     * The returned logger will perform message localization as specified
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1706
     * by {@link LoggerFinder#getLocalizedLogger(java.lang.String,
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  1707
     * java.util.ResourceBundle, java.lang.Module)
44416
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1708
     * LoggerFinder.getLocalizedLogger(name, bundle, module)}, where
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1709
     * {@code module} is the caller's module.
44416
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1710
     * In cases where {@code System.getLogger} is called from a context where
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1711
     * there is no caller frame on the stack (e.g when called directly
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1712
     * from a JNI attached thread), {@code IllegalCallerException} is thrown.
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1713
     * To obtain a logger in such a context, use an auxiliary class that
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1714
     * will implicitly be identified as the caller, or use the system {@link
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1715
     * LoggerFinder#getLoggerFinder() LoggerFinder} to obtain a logger instead.
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1716
     * Note that doing the latter may eagerly initialize the underlying
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1717
     * logging system.
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1718
     *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1719
     * @apiNote
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1720
     * This method is intended to be used after the system is fully initialized.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1721
     * This method may trigger the immediate loading and initialization
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1722
     * of the {@link LoggerFinder} service, which may cause issues if the
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1723
     * Java Runtime is not ready to initialize the concrete service
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1724
     * implementation yet.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1725
     * System classes which may be loaded early in the boot sequence and
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1726
     * need to log localized messages should create a logger using
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1727
     * {@link #getLogger(java.lang.String)} and then use the log methods that
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1728
     * take a resource bundle as parameter.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1729
     *
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1730
     * @param name    the name of the logger.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1731
     * @param bundle  a resource bundle.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1732
     * @return an instance of {@link Logger} which will use the provided
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1733
     * resource bundle for message localization.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1734
     * @throws NullPointerException if {@code name} is {@code null} or
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1735
     *         {@code bundle} is {@code null}.
44416
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1736
     * @throws IllegalCallerException if there is no Java caller frame on the
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1737
     *         stack.
34933
09a3dab8e1f9 8146691: @since 9 tag missing for System.getLogger
dfuchs
parents: 34882
diff changeset
  1738
     *
09a3dab8e1f9 8146691: @since 9 tag missing for System.getLogger
dfuchs
parents: 34882
diff changeset
  1739
     * @since 9
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1740
     */
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1741
    @CallerSensitive
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1742
    public static Logger getLogger(String name, ResourceBundle bundle) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1743
        final ResourceBundle rb = Objects.requireNonNull(bundle);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1744
        Objects.requireNonNull(name);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1745
        final Class<?> caller = Reflection.getCallerClass();
44416
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1746
        if (caller == null) {
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1747
            throw new IllegalCallerException("no caller frame");
2b02517c73a2 8177136: Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
dfuchs
parents: 44359
diff changeset
  1748
        }
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1749
        final SecurityManager sm = System.getSecurityManager();
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1750
        // We don't use LazyLoggers if a resource bundle is specified.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1751
        // Bootstrap sensitive classes in the JDK do not use resource bundles
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1752
        // when logging. This could be revisited later, if it needs to.
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1753
        if (sm != null) {
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1754
            final PrivilegedAction<Logger> pa =
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1755
                    () -> LoggerFinder.accessProvider()
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1756
                            .getLocalizedLogger(name, rb, caller.getModule());
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1757
            return AccessController.doPrivileged(pa, null,
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1758
                                         LoggerFinder.LOGGERFINDER_PERMISSION);
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1759
        }
37672
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1760
        return LoggerFinder.accessProvider()
03684934dc09 8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class.
dfuchs
parents: 37521
diff changeset
  1761
                .getLocalizedLogger(name, rb, caller.getModule());
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1762
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1763
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 32834
diff changeset
  1764
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
     * Terminates the currently running Java Virtual Machine. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     * argument serves as a status code; by convention, a nonzero status
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     * code indicates abnormal termination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     * <p>
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1769
     * This method calls the {@code exit} method in class
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1770
     * {@code Runtime}. This method never returns normally.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
     * <p>
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1772
     * The call {@code System.exit(n)} is effectively equivalent to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
     * the call:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     * Runtime.getRuntime().exit(n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     * @param      status   exit status.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
     * @throws  SecurityException
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1780
     *        if a security manager exists and its {@code checkExit}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
     *        method doesn't allow exit with the specified status.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
     * @see        java.lang.Runtime#exit(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
    public static void exit(int status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
        Runtime.getRuntime().exit(status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
    /**
55231
02db50f278f9 8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents: 53160
diff changeset
  1789
     * Runs the garbage collector in the Java Virtual Machine.
02db50f278f9 8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents: 53160
diff changeset
  1790
     * <p>
02db50f278f9 8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents: 53160
diff changeset
  1791
     * Calling the {@code gc} method suggests that the Java Virtual Machine
02db50f278f9 8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents: 53160
diff changeset
  1792
     * expend effort toward recycling unused objects in order to
02db50f278f9 8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents: 53160
diff changeset
  1793
     * make the memory they currently occupy available for reuse
02db50f278f9 8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents: 53160
diff changeset
  1794
     * by the Java Virtual Machine.
02db50f278f9 8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents: 53160
diff changeset
  1795
     * When control returns from the method call, the Java Virtual Machine
02db50f278f9 8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents: 53160
diff changeset
  1796
     * has made a best effort to reclaim space from all unused objects.
02db50f278f9 8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents: 53160
diff changeset
  1797
     * There is no guarantee that this effort will recycle any particular
02db50f278f9 8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents: 53160
diff changeset
  1798
     * number of unused objects, reclaim any particular amount of space, or
02db50f278f9 8220238: Enhancing j.l.Runtime/System::gc specification with an explicit 'no guarantee' statement
rriggs
parents: 53160
diff changeset
  1799
     * complete at any particular time, if at all, before the method returns or ever.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
     * <p>
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1801
     * The call {@code System.gc()} is effectively equivalent to the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     * call:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     * Runtime.getRuntime().gc()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     * @see     java.lang.Runtime#gc()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
    public static void gc() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
        Runtime.getRuntime().gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
     * Runs the finalization methods of any objects pending finalization.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1815
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
     * Calling this method suggests that the Java Virtual Machine expend
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1817
     * effort toward running the {@code finalize} methods of objects
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1818
     * that have been found to be discarded but whose {@code finalize}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
     * methods have not yet been run. When control returns from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     * method call, the Java Virtual Machine has made a best effort to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     * complete all outstanding finalizations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     * <p>
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1823
     * The call {@code System.runFinalization()} is effectively
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     * equivalent to the call:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
     * Runtime.getRuntime().runFinalization()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
     * @see     java.lang.Runtime#runFinalization()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
    public static void runFinalization() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
        Runtime.getRuntime().runFinalization();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
    /**
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1836
     * Loads the native library specified by the filename argument.  The filename
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1837
     * argument must be an absolute path name.
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1838
     *
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1839
     * If the filename argument, when stripped of any platform-specific library
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1840
     * prefix, path, and file extension, indicates a library whose name is,
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1841
     * for example, L, and a native library called L is statically linked
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1842
     * with the VM, then the JNI_OnLoad_L function exported by the library
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1843
     * is invoked rather than attempting to load a dynamic library.
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1844
     * A filename matching the argument does not have to exist in the
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1845
     * file system.
47707
67aa34b019e1 8164512: Replace ClassLoader use of finalizer with phantom reference to unload native library
mchung
parents: 47476
diff changeset
  1846
     * See the <a href="{@docRoot}/../specs/jni/index.html"> JNI Specification</a>
67aa34b019e1 8164512: Replace ClassLoader use of finalizer with phantom reference to unload native library
mchung
parents: 47476
diff changeset
  1847
     * for more details.
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1848
     *
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1849
     * Otherwise, the filename argument is mapped to a native library image in
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1850
     * an implementation-dependent manner.
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1851
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
     * <p>
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1853
     * The call {@code System.load(name)} is effectively equivalent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
     * to the call:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
     * Runtime.getRuntime().load(name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     * @param      filename   the file to load.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1860
     * @throws     SecurityException  if a security manager exists and its
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1861
     *             {@code checkLink} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     *             loading of the specified dynamic library
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1863
     * @throws     UnsatisfiedLinkError  if either the filename is not an
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1864
     *             absolute path name, the native library is not statically
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1865
     *             linked with the VM, or the library cannot be mapped to
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1866
     *             a native library image by the host system.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1867
     * @throws     NullPointerException if {@code filename} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     * @see        java.lang.Runtime#load(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
     * @see        java.lang.SecurityManager#checkLink(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16479
diff changeset
  1871
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
    public static void load(String filename) {
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16479
diff changeset
  1873
        Runtime.getRuntime().load0(Reflection.getCallerClass(), filename);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
    /**
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1877
     * Loads the native library specified by the {@code libname}
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1878
     * argument.  The {@code libname} argument must not contain any platform
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1879
     * specific prefix, file extension or path. If a native library
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1880
     * called {@code libname} is statically linked with the VM, then the
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1881
     * JNI_OnLoad_{@code libname} function exported by the library is invoked.
47707
67aa34b019e1 8164512: Replace ClassLoader use of finalizer with phantom reference to unload native library
mchung
parents: 47476
diff changeset
  1882
     * See the <a href="{@docRoot}/../specs/jni/index.html"> JNI Specification</a>
67aa34b019e1 8164512: Replace ClassLoader use of finalizer with phantom reference to unload native library
mchung
parents: 47476
diff changeset
  1883
     * for more details.
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1884
     *
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1885
     * Otherwise, the libname argument is loaded from a system library
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1886
     * location and mapped to a native library image in an implementation-
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1887
     * dependent manner.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     * <p>
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1889
     * The call {@code System.loadLibrary(name)} is effectively
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
     * equivalent to the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
     * Runtime.getRuntime().loadLibrary(name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
     * @param      libname   the name of the library.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1896
     * @throws     SecurityException  if a security manager exists and its
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1897
     *             {@code checkLink} method doesn't allow
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     *             loading of the specified dynamic library
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1899
     * @throws     UnsatisfiedLinkError if either the libname argument
16479
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1900
     *             contains a file path, the native library is not statically
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1901
     *             linked with the VM,  or the library cannot be mapped to a
d845c18d13f2 8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents: 15511
diff changeset
  1902
     *             native library image by the host system.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1903
     * @throws     NullPointerException if {@code libname} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
     * @see        java.lang.Runtime#loadLibrary(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
     * @see        java.lang.SecurityManager#checkLink(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16479
diff changeset
  1907
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
    public static void loadLibrary(String libname) {
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16479
diff changeset
  1909
        Runtime.getRuntime().loadLibrary0(Reflection.getCallerClass(), libname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
     * Maps a library name into a platform-specific string representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
     * a native library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
     * @param      libname the name of the library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
     * @return     a platform-dependent native library name.
49203
3a225d9cabe1 8199420: Update javadoc tags in java.lang.System and related
rriggs
parents: 49001
diff changeset
  1918
     * @throws     NullPointerException if {@code libname} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
     * @see        java.lang.System#loadLibrary(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
     * @see        java.lang.ClassLoader#findLibrary(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
    public static native String mapLibraryName(String libname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
    /**
11906
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 11275
diff changeset
  1926
     * Create PrintStream for stdout/err based on encoding.
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 11275
diff changeset
  1927
     */
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 11275
diff changeset
  1928
    private static PrintStream newPrintStream(FileOutputStream fos, String enc) {
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 11275
diff changeset
  1929
       if (enc != null) {
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 11275
diff changeset
  1930
            try {
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 11275
diff changeset
  1931
                return new PrintStream(new BufferedOutputStream(fos, 128), true, enc);
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 11275
diff changeset
  1932
            } catch (UnsupportedEncodingException uee) {}
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 11275
diff changeset
  1933
        }
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 11275
diff changeset
  1934
        return new PrintStream(new BufferedOutputStream(fos, 128), true);
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 11275
diff changeset
  1935
    }
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 11275
diff changeset
  1936
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 11275
diff changeset
  1937
    /**
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1938
     * Logs an exception/error at initialization time to stdout or stderr.
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1939
     *
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1940
     * @param printToStderr to print to stderr rather than stdout
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1941
     * @param printStackTrace to print the stack trace
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1942
     * @param msg the message to print before the exception, can be {@code null}
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1943
     * @param e the exception or error
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1944
     */
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1945
    private static void logInitException(boolean printToStderr,
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1946
                                         boolean printStackTrace,
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1947
                                         String msg,
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1948
                                         Throwable e) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1949
        if (VM.initLevel() < 1) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1950
            throw new InternalError("system classes not initialized");
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1951
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1952
        PrintStream log = (printToStderr) ? err : out;
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1953
        if (msg != null) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1954
            log.println(msg);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1955
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1956
        if (printStackTrace) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1957
            e.printStackTrace(log);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1958
        } else {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1959
            log.println(e);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1960
            for (Throwable suppressed : e.getSuppressed()) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1961
                log.println("Suppressed: " + suppressed);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1962
            }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1963
            Throwable cause = e.getCause();
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1964
            if (cause != null) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1965
                log.println("Caused by: " + cause);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1966
            }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1967
        }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1968
    }
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1969
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  1970
    /**
52978
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1971
     * Create the Properties object from a map - masking out system properties
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1972
     * that are not intended for public access.
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1973
     */
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1974
    private static Properties createProperties(Map<String, String> initialProps) {
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1975
        Properties properties = new Properties(initialProps.size());
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1976
        for (var entry : initialProps.entrySet()) {
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1977
            String prop = entry.getKey();
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1978
            switch (prop) {
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1979
                // Do not add private system properties to the Properties
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1980
                case "sun.nio.MaxDirectMemorySize":
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1981
                case "sun.nio.PageAlignDirectMemory":
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1982
                    // used by java.lang.Integer.IntegerCache
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1983
                case "java.lang.Integer.IntegerCache.high":
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1984
                    // used by sun.launcher.LauncherHelper
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1985
                case "sun.java.launcher.diag":
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1986
                    // used by jdk.internal.loader.ClassLoaders
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1987
                case "jdk.boot.class.path.append":
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1988
                    break;
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1989
                default:
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1990
                    properties.put(prop, entry.getValue());
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1991
            }
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1992
        }
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1993
        return properties;
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1994
    }
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1995
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  1996
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
     * Initialize the system class.  Called after thread initialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
     */
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  1999
    private static void initPhase1() {
8399
0a7dab5d5922 6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents: 7668
diff changeset
  2000
        // VM might invoke JNU_NewStringPlatform() to set those encoding
0a7dab5d5922 6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents: 7668
diff changeset
  2001
        // sensitive properties (user.home, user.name, boot.class.path, etc.)
52724
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52615
diff changeset
  2002
        // during "props" initialization.
0bdbf854472f 4947890: Minimize JNI upcalls in system-properties initialization
rriggs
parents: 52615
diff changeset
  2003
        // The charset is initialized in System.c and does not depend on the Properties.
52978
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  2004
        Map<String, String> tempProps = SystemProps.initProperties();
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  2005
        VersionProps.init(tempProps);
8399
0a7dab5d5922 6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents: 7668
diff changeset
  2006
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6668
diff changeset
  2007
        // There are certain system configurations that may be controlled by
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6668
diff changeset
  2008
        // VM options such as the maximum amount of direct memory and
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6668
diff changeset
  2009
        // Integer cache size used to support the object identity semantics
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6668
diff changeset
  2010
        // of autoboxing.  Typically, the library will obtain these values
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6668
diff changeset
  2011
        // from the properties set by the VM.  If the properties are for
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6668
diff changeset
  2012
        // internal implementation use only, these properties should be
52978
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  2013
        // masked from the system properties.
8399
0a7dab5d5922 6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents: 7668
diff changeset
  2014
        //
0a7dab5d5922 6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents: 7668
diff changeset
  2015
        // Save a private copy of the system properties object that
52978
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  2016
        // can only be accessed by the internal implementation.
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  2017
        VM.saveProperties(tempProps);
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  2018
        props = createProperties(tempProps);
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  2019
95efb32d390b 8215159: Improve initial setup of system Properties
redestad
parents: 52902
diff changeset
  2020
        StaticProperty.javaHome();          // Load StaticProperty to cache the property values
8399
0a7dab5d5922 6999337: java.exe fails to start if some directory names in path to java binaries contain Russian characters
sherman
parents: 7668
diff changeset
  2021
4355
12d58d6de82f 6900043: Add method to return line.separator property
martin
parents: 3288
diff changeset
  2022
        lineSeparator = props.getProperty("line.separator");
2425
99a19a90813e 6807702: Integer.valueOf cache should be configurable
alanb
parents: 2288
diff changeset
  2023
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
        FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
        FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
        FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
        setIn0(new BufferedInputStream(fdIn));
11906
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 11275
diff changeset
  2028
        setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding")));
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 11275
diff changeset
  2029
        setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding")));
dc984e35d8a6 4153167: separate between ANSI and OEM code pages on Windows
sherman
parents: 11275
diff changeset
  2030
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
        // Setup Java signal handlers for HUP, TERM, and INT (where available).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
        Terminator.setup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
25979
42e5d9f8087e 8054857: Fix typos in java.lang.** packages
prappo
parents: 25660
diff changeset
  2034
        // Initialize any miscellaneous operating system settings that need to be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
        // set for the class libraries. Currently this is no-op everywhere except
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
        // for Windows where the process-wide error mode is set before the java.io
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
        // classes are used.
34882
ce2a8ec851c1 8145544: Move sun.misc.VM to jdk.internal.misc
chegar
parents: 34774
diff changeset
  2038
        VM.initializeOSEnvironment();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
        // The main thread is not added to its thread group in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
        // way as other threads; we must do it ourselves here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
        Thread current = Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
        current.getThreadGroup().add(current);
6668
bf6309ced0b6 6888546: restore System.initializeSystemClasses
mchung
parents: 6001
diff changeset
  2044
bf6309ced0b6 6888546: restore System.initializeSystemClasses
mchung
parents: 6001
diff changeset
  2045
        // register shared secrets
bf6309ced0b6 6888546: restore System.initializeSystemClasses
mchung
parents: 6001
diff changeset
  2046
        setJavaLangAccess();
12038
ba8cfc6c5118 7149320: Move sun.misc.VM.booted() to the end of System.initializeSystemClass()
mduigou
parents: 11906
diff changeset
  2047
58574
dcc760954243 8231584: Deadlock with ClassLoader.findLibrary and System.loadLibrary call
akozlov
parents: 57792
diff changeset
  2048
        ClassLoader.initLibraryPaths();
dcc760954243 8231584: Deadlock with ClassLoader.findLibrary and System.loadLibrary call
akozlov
parents: 57792
diff changeset
  2049
12038
ba8cfc6c5118 7149320: Move sun.misc.VM.booted() to the end of System.initializeSystemClass()
mduigou
parents: 11906
diff changeset
  2050
        // Subsystems that are invoked during initialization can invoke
34882
ce2a8ec851c1 8145544: Move sun.misc.VM to jdk.internal.misc
chegar
parents: 34774
diff changeset
  2051
        // VM.isBooted() in order to avoid doing things that should
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2052
        // wait until the VM is fully initialized. The initialization level
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2053
        // is incremented from 0 to 1 here to indicate the first phase of
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2054
        // initialization has completed.
12038
ba8cfc6c5118 7149320: Move sun.misc.VM.booted() to the end of System.initializeSystemClass()
mduigou
parents: 11906
diff changeset
  2055
        // IMPORTANT: Ensure that this remains the last initialization action!
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2056
        VM.initLevel(1);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2057
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2058
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2059
    // @see #initPhase2()
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2060
    static ModuleLayer bootLayer;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2061
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2062
    /*
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2063
     * Invoked by VM.  Phase 2 module system initialization.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2064
     * Only classes in java.base can be loaded in this phase.
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2065
     *
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2066
     * @param printToStderr print exceptions to stderr rather than stdout
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2067
     * @param printStackTrace print stack trace when exception occurs
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2068
     *
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2069
     * @return JNI_OK for success, JNI_ERR for failure
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2070
     */
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2071
    private static int initPhase2(boolean printToStderr, boolean printStackTrace) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2072
        try {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2073
            bootLayer = ModuleBootstrap.boot();
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2074
        } catch (Exception | Error e) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2075
            logInitException(printToStderr, printStackTrace,
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2076
                             "Error occurred during initialization of boot layer", e);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2077
            return -1; // JNI_ERR
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2078
        }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2079
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2080
        // module system initialized
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2081
        VM.initLevel(2);
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2082
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2083
        return 0; // JNI_OK
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2084
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2085
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2086
    /*
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2087
     * Invoked by VM.  Phase 3 is the final system initialization:
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2088
     * 1. set security manager
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2089
     * 2. set system class loader
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2090
     * 3. set TCCL
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2091
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2092
     * This method must be called after the module system initialization.
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2093
     * The security manager and system class loader may be a custom class from
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2094
     * the application classpath or modulepath.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2095
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2096
    private static void initPhase3() {
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2097
        String smProp = System.getProperty("java.security.manager");
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2098
        if (smProp != null) {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2099
            switch (smProp) {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2100
                case "disallow":
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2101
                    allowSecurityManager = NEVER;
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2102
                    break;
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2103
                case "allow":
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2104
                    allowSecurityManager = MAYBE;
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2105
                    break;
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2106
                case "":
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2107
                case "default":
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2108
                    setSecurityManager(new SecurityManager());
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2109
                    allowSecurityManager = MAYBE;
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2110
                    break;
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2111
                default:
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2112
                    try {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2113
                        ClassLoader cl = ClassLoader.getBuiltinAppClassLoader();
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2114
                        Class<?> c = Class.forName(smProp, false, cl);
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2115
                        Constructor<?> ctor = c.getConstructor();
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2116
                        // Must be a public subclass of SecurityManager with
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2117
                        // a public no-arg constructor
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2118
                        if (!SecurityManager.class.isAssignableFrom(c) ||
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2119
                            !Modifier.isPublic(c.getModifiers()) ||
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2120
                            !Modifier.isPublic(ctor.getModifiers())) {
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2121
                            throw new Error("Could not create SecurityManager: "
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2122
                                             + ctor.toString());
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2123
                        }
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2124
                        // custom security manager may be in non-exported package
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2125
                        ctor.setAccessible(true);
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2126
                        SecurityManager sm = (SecurityManager) ctor.newInstance();
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2127
                        setSecurityManager(sm);
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2128
                    } catch (Exception e) {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2129
                        throw new InternalError("Could not create SecurityManager", e);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2130
                    }
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2131
                    allowSecurityManager = MAYBE;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2132
            }
52084
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2133
        } else {
ec4f2762b234 8191053: Provide a mechanism to make system's security manager immutable
mullan
parents: 51772
diff changeset
  2134
            allowSecurityManager = MAYBE;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2135
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2136
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2137
        // initializing the system class loader
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2138
        VM.initLevel(3);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2139
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2140
        // system class loader initialized
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2141
        ClassLoader scl = ClassLoader.initSystemClassLoader();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2142
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2143
        // set TCCL
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2144
        Thread.currentThread().setContextClassLoader(scl);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2145
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2146
        // system is fully initialized
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2147
        VM.initLevel(4);
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2703
diff changeset
  2148
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2703
diff changeset
  2150
    private static void setJavaLangAccess() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
        // Allow privileged classes outside of java.lang
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
  2152
        SharedSecrets.setJavaLangAccess(new JavaLangAccess() {
45652
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents: 45124
diff changeset
  2153
            public List<Method> getDeclaredPublicMethods(Class<?> klass, String name, Class<?>... parameterTypes) {
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents: 45124
diff changeset
  2154
                return klass.getDeclaredPublicMethods(name, parameterTypes);
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
  2155
            }
37363
329dba26ffd2 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 36972
diff changeset
  2156
            public jdk.internal.reflect.ConstantPool getConstantPool(Class<?> klass) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
                return klass.getConstantPool();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
            }
18827
ecbd9c8bef12 7122142: (ann) Race condition between isAnnotationPresent and getAnnotations
plevart
parents: 18546
diff changeset
  2159
            public boolean casAnnotationType(Class<?> klass, AnnotationType oldType, AnnotationType newType) {
ecbd9c8bef12 7122142: (ann) Race condition between isAnnotationPresent and getAnnotations
plevart
parents: 18546
diff changeset
  2160
                return klass.casAnnotationType(oldType, newType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
            }
11117
b6e68b1344d4 7116404: Miscellaneous warnings (java.rmi.**, serialization, some core classes)
alanb
parents: 10360
diff changeset
  2162
            public AnnotationType getAnnotationType(Class<?> klass) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
                return klass.getAnnotationType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
            }
21358
d41ff832d4f6 8027170: Annotations declared on super-super-class should be overridden by super-class.
alundblad
parents: 20831
diff changeset
  2165
            public Map<Class<? extends Annotation>, Annotation> getDeclaredAnnotationMap(Class<?> klass) {
d41ff832d4f6 8027170: Annotations declared on super-super-class should be overridden by super-class.
alundblad
parents: 20831
diff changeset
  2166
                return klass.getDeclaredAnnotationMap();
d41ff832d4f6 8027170: Annotations declared on super-super-class should be overridden by super-class.
alundblad
parents: 20831
diff changeset
  2167
            }
18827
ecbd9c8bef12 7122142: (ann) Race condition between isAnnotationPresent and getAnnotations
plevart
parents: 18546
diff changeset
  2168
            public byte[] getRawClassAnnotations(Class<?> klass) {
ecbd9c8bef12 7122142: (ann) Race condition between isAnnotationPresent and getAnnotations
plevart
parents: 18546
diff changeset
  2169
                return klass.getRawAnnotations();
ecbd9c8bef12 7122142: (ann) Race condition between isAnnotationPresent and getAnnotations
plevart
parents: 18546
diff changeset
  2170
            }
15510
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 14676
diff changeset
  2171
            public byte[] getRawClassTypeAnnotations(Class<?> klass) {
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 14676
diff changeset
  2172
                return klass.getRawTypeAnnotations();
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 14676
diff changeset
  2173
            }
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 14676
diff changeset
  2174
            public byte[] getRawExecutableTypeAnnotations(Executable executable) {
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 14676
diff changeset
  2175
                return Class.getExecutableTypeAnnotationBytes(executable);
898d924a7efd 8004698: Implement Core Reflection for Type Annotations
jfranck
parents: 14676
diff changeset
  2176
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
            public <E extends Enum<E>>
45652
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents: 45124
diff changeset
  2178
            E[] getEnumConstantsShared(Class<E> klass) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
                return klass.getEnumConstantsShared();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
            }
49001
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 48942
diff changeset
  2181
            public void blockedOn(Interruptible b) {
ce06058197a4 8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents: 48942
diff changeset
  2182
                Thread.blockedOn(b);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
            }
2703
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2425
diff changeset
  2184
            public void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook) {
acd4d6a53e3e 6829503: addShutdownHook fails if called after shutdown has commenced.
mchung
parents: 2425
diff changeset
  2185
                Shutdown.add(slot, registerShutdownInProgress, hook);
2277
445a331b4a8b 6810254: Lazily instantiate the shared secret access objects
mchung
parents: 2
diff changeset
  2186
            }
20805
ae41216325dd 8013739: Better LDAP resource management
weijun
parents: 18546
diff changeset
  2187
            public Thread newThreadWithAcc(Runnable target, AccessControlContext acc) {
ae41216325dd 8013739: Better LDAP resource management
weijun
parents: 18546
diff changeset
  2188
                return new Thread(target, acc);
ae41216325dd 8013739: Better LDAP resource management
weijun
parents: 18546
diff changeset
  2189
            }
44534
a076dffbc2c1 8165641: Deprecate Object.finalize
rriggs
parents: 44416
diff changeset
  2190
            @SuppressWarnings("deprecation")
21628
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 21358
diff changeset
  2191
            public void invokeFinalize(Object o) throws Throwable {
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 21358
diff changeset
  2192
                o.finalize();
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 21358
diff changeset
  2193
            }
36972
27147cde3256 8152115: (proxy) Examine performance of dynamic proxy creation
plevart
parents: 36511
diff changeset
  2194
            public ConcurrentHashMap<?, ?> createOrGetClassLoaderValueMap(ClassLoader cl) {
27147cde3256 8152115: (proxy) Examine performance of dynamic proxy creation
plevart
parents: 36511
diff changeset
  2195
                return cl.createOrGetClassLoaderValueMap();
27147cde3256 8152115: (proxy) Examine performance of dynamic proxy creation
plevart
parents: 36511
diff changeset
  2196
            }
44359
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2197
            public Class<?> defineClass(ClassLoader loader, String name, byte[] b, ProtectionDomain pd, String source) {
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2198
                return ClassLoader.defineClass1(loader, name, b, 0, b.length, pd, source);
c6761862ca0b 8174823: Module system implementation refresh (3/2017)
alanb
parents: 43813
diff changeset
  2199
            }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2200
            public Class<?> findBootstrapClassOrNull(ClassLoader cl, String name) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2201
                return cl.findBootstrapClassOrNull(name);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2202
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2203
            public Package definePackage(ClassLoader cl, String name, Module module) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2204
                return cl.definePackage(name, module);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 36225
diff changeset
  2205
            }
35707
66cdb7e01a3e 8148936: Adapt UUID.toString() to Compact Strings
shade
parents: 34933
diff changeset
  2206
            public String fastUUID(long lsb, long msb) {
66cdb7e01a3e 8148936: Adapt UUID.toString() to Compact Strings
shade
parents: 34933
diff changeset
  2207
                return Long.fastUUID(lsb, msb);
25660
01fa3ccedf50 8050114: Expose Integer/Long formatUnsigned methods internally
redestad
parents: 24865
diff changeset
  2208
            }
45004
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44667
diff changeset
  2209
            public void addNonExportedPackages(ModuleLayer layer) {
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44667
diff changeset
  2210
                SecurityManager.addNonExportedPackages(layer);
ea3137042a61 8178380: Module system implementation refresh (5/2017)
alanb
parents: 44667
diff changeset
  2211
            }
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 43221
diff changeset
  2212
            public void invalidatePackageAccessCache() {
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 43221
diff changeset
  2213
                SecurityManager.invalidatePackageAccessCache();
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 43221
diff changeset
  2214
            }
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2215
            public Module defineModule(ClassLoader loader,
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2216
                                       ModuleDescriptor descriptor,
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2217
                                       URI uri) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2218
                return new Module(null, loader, descriptor, uri);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2219
            }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2220
            public Module defineUnnamedModule(ClassLoader loader) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2221
                return new Module(loader);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2222
            }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2223
            public void addReads(Module m1, Module m2) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2224
                m1.implAddReads(m2);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2225
            }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2226
            public void addReadsAllUnnamed(Module m) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2227
                m.implAddReadsAllUnnamed();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2228
            }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2229
            public void addExports(Module m, String pn, Module other) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2230
                m.implAddExports(pn, other);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2231
            }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2232
            public void addExportsToAllUnnamed(Module m, String pn) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2233
                m.implAddExportsToAllUnnamed(pn);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2234
            }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2235
            public void addOpens(Module m, String pn, Module other) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2236
                m.implAddOpens(pn, other);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2237
            }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2238
            public void addOpensToAllUnnamed(Module m, String pn) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2239
                m.implAddOpensToAllUnnamed(pn);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2240
            }
45652
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents: 45124
diff changeset
  2241
            public void addOpensToAllUnnamed(Module m, Iterator<String> packages) {
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents: 45124
diff changeset
  2242
                m.implAddOpensToAllUnnamed(packages);
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents: 45124
diff changeset
  2243
            }
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2244
            public void addUses(Module m, Class<?> service) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2245
                m.implAddUses(service);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2246
            }
45652
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents: 45124
diff changeset
  2247
            public boolean isReflectivelyExported(Module m, String pn, Module other) {
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents: 45124
diff changeset
  2248
                return m.isReflectivelyExported(pn, other);
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents: 45124
diff changeset
  2249
            }
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents: 45124
diff changeset
  2250
            public boolean isReflectivelyOpened(Module m, String pn, Module other) {
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents: 45124
diff changeset
  2251
                return m.isReflectivelyOpened(pn, other);
33342314ce89 8181087: Module system implementation refresh (6/2017)
alanb
parents: 45124
diff changeset
  2252
            }
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2253
            public ServicesCatalog getServicesCatalog(ModuleLayer layer) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2254
                return layer.getServicesCatalog();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2255
            }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2256
            public Stream<ModuleLayer> layers(ModuleLayer layer) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2257
                return layer.layers();
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2258
            }
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2259
            public Stream<ModuleLayer> layers(ClassLoader loader) {
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2260
                return ModuleLayer.layers(loader);
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 44416
diff changeset
  2261
            }
48262
daf3b49f4839 8184947: ZipCoder performance improvements
sherman
parents: 48065
diff changeset
  2262
50820
35f52a3cd6bd 8205058: (fs) Files read/writeString should throw CharacterCodingException instead of IOException with an IllegalArgumentException as cause
joehw
parents: 50817
diff changeset
  2263
            public String newStringNoRepl(byte[] bytes, Charset cs) throws CharacterCodingException  {
50552
7439ceaae8e4 8201276: (fs) Add methods to Files for reading/writing a string from/to a file
joehw
parents: 50531
diff changeset
  2264
                return StringCoding.newStringNoRepl(bytes, cs);
7439ceaae8e4 8201276: (fs) Add methods to Files for reading/writing a string from/to a file
joehw
parents: 50531
diff changeset
  2265
            }
7439ceaae8e4 8201276: (fs) Add methods to Files for reading/writing a string from/to a file
joehw
parents: 50531
diff changeset
  2266
50820
35f52a3cd6bd 8205058: (fs) Files read/writeString should throw CharacterCodingException instead of IOException with an IllegalArgumentException as cause
joehw
parents: 50817
diff changeset
  2267
            public byte[] getBytesNoRepl(String s, Charset cs) throws CharacterCodingException {
50552
7439ceaae8e4 8201276: (fs) Add methods to Files for reading/writing a string from/to a file
joehw
parents: 50531
diff changeset
  2268
                return StringCoding.getBytesNoRepl(s, cs);
7439ceaae8e4 8201276: (fs) Add methods to Files for reading/writing a string from/to a file
joehw
parents: 50531
diff changeset
  2269
            }
7439ceaae8e4 8201276: (fs) Add methods to Files for reading/writing a string from/to a file
joehw
parents: 50531
diff changeset
  2270
48262
daf3b49f4839 8184947: ZipCoder performance improvements
sherman
parents: 48065
diff changeset
  2271
            public String newStringUTF8NoRepl(byte[] bytes, int off, int len) {
daf3b49f4839 8184947: ZipCoder performance improvements
sherman
parents: 48065
diff changeset
  2272
                return StringCoding.newStringUTF8NoRepl(bytes, off, len);
daf3b49f4839 8184947: ZipCoder performance improvements
sherman
parents: 48065
diff changeset
  2273
            }
daf3b49f4839 8184947: ZipCoder performance improvements
sherman
parents: 48065
diff changeset
  2274
daf3b49f4839 8184947: ZipCoder performance improvements
sherman
parents: 48065
diff changeset
  2275
            public byte[] getBytesUTF8NoRepl(String s) {
daf3b49f4839 8184947: ZipCoder performance improvements
sherman
parents: 48065
diff changeset
  2276
                return StringCoding.getBytesUTF8NoRepl(s);
daf3b49f4839 8184947: ZipCoder performance improvements
sherman
parents: 48065
diff changeset
  2277
            }
daf3b49f4839 8184947: ZipCoder performance improvements
sherman
parents: 48065
diff changeset
  2278
51772
5432cebf6627 8210721: Replace legacy serial exception field with Throwable::cause
mchung
parents: 50820
diff changeset
  2279
            public void setCause(Throwable t, Throwable cause) {
5432cebf6627 8210721: Replace legacy serial exception field with Throwable::cause
mchung
parents: 50820
diff changeset
  2280
                t.setCause(cause);
5432cebf6627 8210721: Replace legacy serial exception field with Throwable::cause
mchung
parents: 50820
diff changeset
  2281
            }
55693
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 55265
diff changeset
  2282
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 55265
diff changeset
  2283
            public void loadLibrary(Class<?> caller, String library) {
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 55265
diff changeset
  2284
                assert library.indexOf(java.io.File.separatorChar) < 0;
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 55265
diff changeset
  2285
                ClassLoader.loadLibrary(caller, library, false);
9a97b1393e72 8227587: Add internal privileged System.loadLibrary
redestad
parents: 55265
diff changeset
  2286
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
}