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