src/java.base/share/classes/jdk/internal/misc/VM.java
author mchung
Fri, 23 Feb 2018 12:10:56 -0800
changeset 48942 a6c4b85163c1
parent 47216 71c04702a3d5
child 50951 b96466cdfc45
permissions -rw-r--r--
8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit Reviewed-by: dholmes, alanb, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
39062
93c6e022db74 8159630: Add new test for jdk.internal.misc.VM::getRuntimeArguments
mchung
parents: 38583
diff changeset
     2
 * Copyright (c) 1996, 2016, 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: 3958
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: 3958
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: 3958
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3958
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3958
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
34882
ce2a8ec851c1 8145544: Move sun.misc.VM to jdk.internal.misc
chegar
parents: 34774
diff changeset
    26
package jdk.internal.misc;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
7540
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
    28
import static java.lang.Thread.State.*;
44852
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
    29
import java.util.Map;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
public class VM {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    34
    // the init level when the VM is fully initialized
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    35
    private static final int JAVA_LANG_SYSTEM_INITED     = 1;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    36
    private static final int MODULE_SYSTEM_INITED        = 2;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    37
    private static final int SYSTEM_LOADER_INITIALIZING  = 3;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    38
    private static final int SYSTEM_BOOTED               = 4;
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    39
    private static final int SYSTEM_SHUTDOWN             = 5;
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    40
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    41
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    42
    // 0, 1, 2, ...
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    43
    private static volatile int initLevel;
21628
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
    44
    private static final Object lock = new Object();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    46
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    47
     * Sets the init level.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    48
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    49
     * @see java.lang.System#initPhase1
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    50
     * @see java.lang.System#initPhase2
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    51
     * @see java.lang.System#initPhase3
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    52
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    53
    public static void initLevel(int value) {
21628
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
    54
        synchronized (lock) {
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    55
            if (value <= initLevel || value > SYSTEM_SHUTDOWN)
41121
91734a3ed04b 8151832: Improve exception messages in exception thrown by new JDK 9 code
coffeys
parents: 39469
diff changeset
    56
                throw new InternalError("Bad level: " + value);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    57
            initLevel = value;
21628
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
    58
            lock.notifyAll();
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
    59
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    62
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    63
     * Returns the current init level.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    64
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    65
    public static int initLevel() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    66
        return initLevel;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    69
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    70
     * Waits for the init level to get the given value.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    71
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    72
     * @see java.lang.ref.Finalizer
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    73
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    74
    public static void awaitInitLevel(int value) throws InterruptedException {
21628
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
    75
        synchronized (lock) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    76
            while (initLevel < value) {
21628
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
    77
                lock.wait();
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
    78
            }
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
    79
        }
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
    80
    }
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
    81
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    82
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    83
     * Returns {@code true} if the module system has been initialized.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    84
     * @see java.lang.System#initPhase2
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    85
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    86
    public static boolean isModuleSystemInited() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    87
        return VM.initLevel() >= MODULE_SYSTEM_INITED;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    88
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    89
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    90
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    91
     * Returns {@code true} if the VM is fully initialized.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    92
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    93
    public static boolean isBooted() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    94
        return initLevel >= SYSTEM_BOOTED;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    95
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
    96
48942
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    97
    /**
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    98
     * Set shutdown state.  Shutdown completes when all registered shutdown
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
    99
     * hooks have been run.
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   100
     *
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   101
     * @see java.lang.Shutdown
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   102
     */
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   103
    public static void shutdown() {
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   104
        initLevel(SYSTEM_SHUTDOWN);
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   105
    }
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   106
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   107
    /**
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   108
     * Returns {@code true} if the VM has been shutdown
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   109
     */
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   110
    public static boolean isShutdown() {
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   111
        return initLevel == SYSTEM_SHUTDOWN;
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   112
    }
a6c4b85163c1 8198249: Remove deprecated Runtime::runFinalizersOnExit and System::runFinalizersOnExit
mchung
parents: 47216
diff changeset
   113
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    // A user-settable upper limit on the maximum amount of allocatable direct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    // buffer memory.  This value may be changed during VM initialization if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    // "java" is launched with "-XX:MaxDirectMemorySize=<size>".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    // The initial value of this field is arbitrary; during JRE initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    // it will be reset to the value specified on the command line, if any,
11515
841d5f796b28 7128584: Typo in sun.misc.VM's private directMemory field comment
chegar
parents: 11117
diff changeset
   120
    // otherwise to Runtime.getRuntime().maxMemory().
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private static long directMemory = 64 * 1024 * 1024;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   124
    // Returns the maximum amount of allocatable direct buffer memory.
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   125
    // The directMemory variable is initialized during system initialization
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   126
    // in the saveAndRemoveProperties method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public static long maxDirectMemory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return directMemory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   132
    // User-controllable flag that determines if direct buffers should be page
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   133
    // aligned. The "-XX:+PageAlignDirectMemory" option can be used to force
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   134
    // buffers, allocated by ByteBuffer.allocateDirect, to be page aligned.
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   135
    private static boolean pageAlignDirectMemory;
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   136
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   137
    // Returns {@code true} if the direct buffers should be page aligned. This
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   138
    // variable is initialized by saveAndRemoveProperties.
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   139
    public static boolean isDirectMemoryPageAligned() {
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   140
        return pageAlignDirectMemory;
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   141
    }
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   142
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   143
    /**
46047
97d615d81827 8161121: VM::isSystemDomainLoader should consider platform class loader
mchung
parents: 44852
diff changeset
   144
     * Returns true if the given class loader is the bootstrap class loader
97d615d81827 8161121: VM::isSystemDomainLoader should consider platform class loader
mchung
parents: 44852
diff changeset
   145
     * or the platform class loader.
13589
da4cb574f4a6 7193339: Prepare system classes be defined by a non-null module loader
mchung
parents: 11515
diff changeset
   146
     */
da4cb574f4a6 7193339: Prepare system classes be defined by a non-null module loader
mchung
parents: 11515
diff changeset
   147
    public static boolean isSystemDomainLoader(ClassLoader loader) {
46047
97d615d81827 8161121: VM::isSystemDomainLoader should consider platform class loader
mchung
parents: 44852
diff changeset
   148
        return loader == null || loader == ClassLoader.getPlatformClassLoader();
13589
da4cb574f4a6 7193339: Prepare system classes be defined by a non-null module loader
mchung
parents: 11515
diff changeset
   149
    }
da4cb574f4a6 7193339: Prepare system classes be defined by a non-null module loader
mchung
parents: 11515
diff changeset
   150
da4cb574f4a6 7193339: Prepare system classes be defined by a non-null module loader
mchung
parents: 11515
diff changeset
   151
    /**
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   152
     * Returns the system property of the specified key saved at
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   153
     * system initialization time.  This method should only be used
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   154
     * for the system properties that are not changed during runtime.
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   155
     *
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   156
     * Note that the saved system properties do not include
44852
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   157
     * the ones set by java.lang.VersionProps.init().
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   158
     */
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   159
    public static String getSavedProperty(String key) {
44852
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   160
        if (savedProps == null)
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   161
            throw new IllegalStateException("Not yet initialized");
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   162
44852
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   163
        return savedProps.get(key);
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   164
    }
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   165
44852
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   166
    /**
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   167
     * Gets an unmodifiable view of the system properties saved at system
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   168
     * initialization time. This method should only be used
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   169
     * for the system properties that are not changed during runtime.
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   170
     *
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   171
     * Note that the saved system properties do not include
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   172
     * the ones set by java.lang.VersionProps.init().
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   173
     */
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   174
    public static Map<String, String> getSavedProperties() {
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   175
        if (savedProps == null)
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   176
            throw new IllegalStateException("Not yet initialized");
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   177
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   178
        return savedProps;
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   179
    }
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   180
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   181
    private static Map<String, String> savedProps;
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   182
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   183
    // Save a private copy of the system properties and remove
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   184
    // the system properties that are not intended for public access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    //
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   186
    // This method can only be invoked during system initialization.
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   187
    public static void saveAndRemoveProperties(Properties props) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   188
        if (initLevel() != 0)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   189
            throw new IllegalStateException("Wrong init level");
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   190
44852
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   191
        @SuppressWarnings({"rawtypes", "unchecked"})
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   192
        Map<String, String> sp =
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   193
            Map.ofEntries(props.entrySet().toArray(new Map.Entry[0]));
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   194
        // only main thread is running at this time, so savedProps and
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   195
        // its content will be correctly published to threads started later
82cacb64e969 8177845: Need a mechanism to load Graal
dnsimon
parents: 41121
diff changeset
   196
        savedProps = sp;
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   197
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   198
        // Set the maximum amount of direct memory.  This value is controlled
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   199
        // by the vm option -XX:MaxDirectMemorySize=<size>.
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   200
        // The maximum amount of allocatable direct buffer memory (in bytes)
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   201
        // from the system property sun.nio.MaxDirectMemorySize set by the VM.
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   202
        // The system property will be removed.
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   203
        String s = (String)props.remove("sun.nio.MaxDirectMemorySize");
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   204
        if (s != null) {
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   205
            if (s.equals("-1")) {
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   206
                // -XX:MaxDirectMemorySize not given, take default
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   207
                directMemory = Runtime.getRuntime().maxMemory();
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   208
            } else {
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   209
                long l = Long.parseLong(s);
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   210
                if (l > -1)
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   211
                    directMemory = l;
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   212
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   214
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   215
        // Check if direct buffers should be page aligned
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   216
        s = (String)props.remove("sun.nio.PageAlignDirectMemory");
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   217
        if ("true".equals(s))
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   218
            pageAlignDirectMemory = true;
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   219
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   220
        // Remove other private system properties
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   221
        // used by java.lang.Integer.IntegerCache
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   222
        props.remove("java.lang.Integer.IntegerCache.high");
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   223
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7668
diff changeset
   224
        // used by sun.launcher.LauncherHelper
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7668
diff changeset
   225
        props.remove("sun.java.launcher.diag");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   226
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   227
        // used by jdk.internal.loader.ClassLoaders
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   228
        props.remove("jdk.boot.class.path.append");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   231
    // Initialize any miscellaneous operating system settings that need to be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    // set for the class libraries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public static void initializeOSEnvironment() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   235
        if (initLevel() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            OSEnvironment.initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /* Current count of objects pending for finalization */
34774
03b4e6dc367b 8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents: 34686
diff changeset
   241
    private static volatile int finalRefCount;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /* Peak count of objects pending for finalization */
34774
03b4e6dc367b 8145680: Remove unnecessary explicit initialization of volatile variables in java.base
redestad
parents: 34686
diff changeset
   244
    private static volatile int peakFinalRefCount;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Gets the number of objects pending for finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @return the number of objects pending for finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public static int getFinalRefCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return finalRefCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Gets the peak number of objects pending for finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @return the peak number of objects pending for finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public static int getPeakFinalRefCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return peakFinalRefCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /*
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 28765
diff changeset
   265
     * Add {@code n} to the objects pending for finalization count.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param n an integer value to be added to the objects pending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * for finalization count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public static void addFinalRefCount(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        // The caller must hold lock to synchronize the update.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        finalRefCount += n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (finalRefCount > peakFinalRefCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            peakFinalRefCount = finalRefCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
7540
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   279
    /**
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   280
     * Returns Thread.State for the given threadStatus
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   281
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public static Thread.State toThreadState(int threadStatus) {
7540
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   283
        if ((threadStatus & JVMTI_THREAD_STATE_RUNNABLE) != 0) {
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   284
            return RUNNABLE;
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   285
        } else if ((threadStatus & JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER) != 0) {
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   286
            return BLOCKED;
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   287
        } else if ((threadStatus & JVMTI_THREAD_STATE_WAITING_INDEFINITELY) != 0) {
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   288
            return WAITING;
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   289
        } else if ((threadStatus & JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT) != 0) {
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   290
            return TIMED_WAITING;
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   291
        } else if ((threadStatus & JVMTI_THREAD_STATE_TERMINATED) != 0) {
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   292
            return TERMINATED;
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   293
        } else if ((threadStatus & JVMTI_THREAD_STATE_ALIVE) == 0) {
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   294
            return NEW;
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   295
        } else {
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   296
            return RUNNABLE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
7540
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   300
    /* The threadStatus field is set by the VM at state transition
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   301
     * in the hotspot implementation. Its value is set according to
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   302
     * the JVM TI specification GetThreadState function.
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   303
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30655
diff changeset
   304
    private static final int JVMTI_THREAD_STATE_ALIVE = 0x0001;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30655
diff changeset
   305
    private static final int JVMTI_THREAD_STATE_TERMINATED = 0x0002;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30655
diff changeset
   306
    private static final int JVMTI_THREAD_STATE_RUNNABLE = 0x0004;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30655
diff changeset
   307
    private static final int JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER = 0x0400;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30655
diff changeset
   308
    private static final int JVMTI_THREAD_STATE_WAITING_INDEFINITELY = 0x0010;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30655
diff changeset
   309
    private static final int JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT = 0x0020;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
10797
f51518b30c84 7104209: Cleanup and remove librmi (native library)
chegar
parents: 9035
diff changeset
   311
    /*
37899
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   312
     * Returns the first user-defined class loader up the execution stack,
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   313
     * or the platform class loader if only code from the platform or
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   314
     * bootstrap class loader is on the stack.
10797
f51518b30c84 7104209: Cleanup and remove librmi (native library)
chegar
parents: 9035
diff changeset
   315
     */
37899
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   316
    public static ClassLoader latestUserDefinedLoader() {
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   317
        ClassLoader loader = latestUserDefinedLoader0();
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   318
        return loader != null ? loader : ClassLoader.getPlatformClassLoader();
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   319
    }
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   320
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   321
    /*
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   322
     * Returns the first user-defined class loader up the execution stack,
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   323
     * or null if only code from the platform or bootstrap class loader is
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   324
     * on the stack.  VM does not keep a reference of platform loader and so
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   325
     * it returns null.
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   326
     *
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   327
     * This method should be replaced with StackWalker::walk and then we can
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   328
     * remove the logic in the VM.
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   329
     */
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   330
    private static native ClassLoader latestUserDefinedLoader0();
10797
f51518b30c84 7104209: Cleanup and remove librmi (native library)
chegar
parents: 9035
diff changeset
   331
22951
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 22571
diff changeset
   332
    /**
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 22571
diff changeset
   333
     * Returns {@code true} if we are in a set UID program.
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 22571
diff changeset
   334
     */
24506
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   335
    public static boolean isSetUID() {
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   336
        long uid = getuid();
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   337
        long euid = geteuid();
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   338
        long gid = getgid();
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   339
        long egid = getegid();
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   340
        return uid != euid  || gid != egid;
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   341
    }
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   342
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   343
    /**
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   344
     * Returns the real user ID of the calling process,
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   345
     * or -1 if the value is not available.
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   346
     */
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   347
    public static native long getuid();
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   348
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   349
    /**
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   350
     * Returns the effective user ID of the calling process,
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   351
     * or -1 if the value is not available.
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   352
     */
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   353
    public static native long geteuid();
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   354
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   355
    /**
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   356
     * Returns the real group ID of the calling process,
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   357
     * or -1 if the value is not available.
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   358
     */
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   359
    public static native long getgid();
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   360
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   361
    /**
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   362
     * Returns the effective group ID of the calling process,
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   363
     * or -1 if the value is not available.
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   364
     */
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   365
    public static native long getegid();
22951
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 22571
diff changeset
   366
28765
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   367
    /**
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   368
     * Get a nanosecond time stamp adjustment in the form of a single long.
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   369
     *
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   370
     * This value can be used to create an instant using
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   371
     * {@link java.time.Instant#ofEpochSecond(long, long)
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   372
     *  java.time.Instant.ofEpochSecond(offsetInSeconds,
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   373
     *  getNanoTimeAdjustment(offsetInSeconds))}.
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   374
     * <p>
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   375
     * The value returned has the best resolution available to the JVM on
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   376
     * the current system.
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   377
     * This is usually down to microseconds - or tenth of microseconds -
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   378
     * depending on the OS/Hardware and the JVM implementation.
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   379
     *
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   380
     * @param offsetInSeconds The offset in seconds from which the nanosecond
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   381
     *        time stamp should be computed.
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   382
     *
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   383
     * @apiNote The offset should be recent enough - so that
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   384
     *         {@code offsetInSeconds} is within {@code +/- 2^32} seconds of the
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   385
     *         current UTC time. If the offset is too far off, {@code -1} will be
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   386
     *         returned. As such, {@code -1} must not be considered as a valid
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   387
     *         nano time adjustment, but as an exception value indicating
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   388
     *         that an offset closer to the current time should be used.
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   389
     *
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   390
     * @return A nanosecond time stamp adjustment in the form of a single long.
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   391
     *     If the offset is too far off the current time, this method returns -1.
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   392
     *     In that case, the caller should call this method again, passing a
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   393
     *     more accurate offset.
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   394
     */
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   395
    public static native long getNanoTimeAdjustment(long offsetInSeconds);
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   396
38583
d887ee89eec0 8157986: Runtime support for javac to determine arguments to the runtime environment
mchung
parents: 37899
diff changeset
   397
    /**
d887ee89eec0 8157986: Runtime support for javac to determine arguments to the runtime environment
mchung
parents: 37899
diff changeset
   398
     * Returns the VM arguments for this runtime environment.
d887ee89eec0 8157986: Runtime support for javac to determine arguments to the runtime environment
mchung
parents: 37899
diff changeset
   399
     *
d887ee89eec0 8157986: Runtime support for javac to determine arguments to the runtime environment
mchung
parents: 37899
diff changeset
   400
     * @implNote
d887ee89eec0 8157986: Runtime support for javac to determine arguments to the runtime environment
mchung
parents: 37899
diff changeset
   401
     * The HotSpot JVM processes the input arguments from multiple sources
d887ee89eec0 8157986: Runtime support for javac to determine arguments to the runtime environment
mchung
parents: 37899
diff changeset
   402
     * in the following order:
d887ee89eec0 8157986: Runtime support for javac to determine arguments to the runtime environment
mchung
parents: 37899
diff changeset
   403
     * 1. JAVA_TOOL_OPTIONS environment variable
d887ee89eec0 8157986: Runtime support for javac to determine arguments to the runtime environment
mchung
parents: 37899
diff changeset
   404
     * 2. Options from JNI Invocation API
d887ee89eec0 8157986: Runtime support for javac to determine arguments to the runtime environment
mchung
parents: 37899
diff changeset
   405
     * 3. _JAVA_OPTIONS environment variable
d887ee89eec0 8157986: Runtime support for javac to determine arguments to the runtime environment
mchung
parents: 37899
diff changeset
   406
     *
d887ee89eec0 8157986: Runtime support for javac to determine arguments to the runtime environment
mchung
parents: 37899
diff changeset
   407
     * If VM options file is specified via -XX:VMOptionsFile, the vm options
d887ee89eec0 8157986: Runtime support for javac to determine arguments to the runtime environment
mchung
parents: 37899
diff changeset
   408
     * file is read and expanded in place of -XX:VMOptionFile option.
d887ee89eec0 8157986: Runtime support for javac to determine arguments to the runtime environment
mchung
parents: 37899
diff changeset
   409
     */
d887ee89eec0 8157986: Runtime support for javac to determine arguments to the runtime environment
mchung
parents: 37899
diff changeset
   410
    public static native String[] getRuntimeArguments();
d887ee89eec0 8157986: Runtime support for javac to determine arguments to the runtime environment
mchung
parents: 37899
diff changeset
   411
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30655
diff changeset
   415
    private static native void initialize();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
}