jdk/src/java.base/share/classes/jdk/internal/misc/VM.java
author mchung
Thu, 12 May 2016 11:16:56 -0700
changeset 37899 1b8ec90a1e15
parent 36511 9d0388c6b336
child 38583 d887ee89eec0
permissions -rw-r--r--
8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader Reviewed-by: acorn, alanb, chegar, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
28765
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
     2
 * Copyright (c) 1996, 2015, 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.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
public class VM {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    /* The following methods used to be native methods that instruct
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
     * the VM to selectively suspend certain threads in low-memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
     * situations. They are inherently dangerous and not implementable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
     * on native threads. We removed them in JDK 1.2. The skeletons
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
     * remain so that existing applications that use these methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
     * will still work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private static boolean suspended = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    public static boolean threadsSuspended() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        return suspended;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
11117
b6e68b1344d4 7116404: Miscellaneous warnings (java.rmi.**, serialization, some core classes)
alanb
parents: 10797
diff changeset
    48
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public static boolean allowThreadSuspension(ThreadGroup g, boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        return g.allowThreadSuspension(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static boolean suspendThreads() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        suspended = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    // Causes any suspended threadgroups to be resumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static void unsuspendThreads() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        suspended = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // Causes threadgroups no longer marked suspendable to be resumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public static void unsuspendSomeThreads() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /* Deprecated fields and methods -- Memory advice not supported in 1.2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static final int STATE_GREEN = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static final int STATE_YELLOW = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public static final int STATE_RED = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static final int getState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return STATE_GREEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public static void registerVMNotification(VMNotification n) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public static void asChange(int as_old, int as_new) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public static void asChange_otherthread(int as_old, int as_new) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Not supported in 1.2 because these will have to be exported as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * JVM functions, and we are not sure we want do that. Leaving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * here so it can be easily resurrected -- just remove the //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * comments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Resume Java profiling.  All profiling data is added to any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * earlier profiling, unless <code>resetJavaProfiler</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * called in between.  If profiling was not started from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * command line, <code>resumeJavaProfiler</code> will start it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * NOTE: Profiling must be enabled from the command line for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * java.prof report to be automatically generated on exit; if not,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * writeJavaProfilerReport must be invoked to write a report.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @see     resetJavaProfiler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @see     writeJavaProfilerReport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    // public native static void resumeJavaProfiler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Suspend Java profiling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    // public native static void suspendJavaProfiler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Initialize Java profiling.  Any accumulated profiling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * information is discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    // public native static void resetJavaProfiler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Write the current profiling contents to the file "java.prof".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * If the file already exists, it will be overwritten.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    // public native static void writeJavaProfilerReport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   147
    // the init level when the VM is fully initialized
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   148
    private static final int JAVA_LANG_SYSTEM_INITED     = 1;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   149
    private static final int MODULE_SYSTEM_INITED        = 2;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   150
    private static final int SYSTEM_LOADER_INITIALIZING  = 3;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   151
    private static final int SYSTEM_BOOTED               = 4;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   152
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   153
    // 0, 1, 2, ...
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   154
    private static volatile int initLevel;
21628
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
   155
    private static final Object lock = new Object();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   157
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   158
     * Sets the init level.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   159
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   160
     * @see java.lang.System#initPhase1
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   161
     * @see java.lang.System#initPhase2
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   162
     * @see java.lang.System#initPhase3
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   163
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   164
    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
   165
        synchronized (lock) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   166
            if (value <= initLevel || value > SYSTEM_BOOTED)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   167
                throw new InternalError();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   168
            initLevel = value;
21628
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
   169
            lock.notifyAll();
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
   170
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   173
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   174
     * Returns the current init level.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   175
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   176
    public static int initLevel() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   177
        return initLevel;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   180
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   181
     * Waits for the init level to get the given value.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   182
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   183
     * @see java.lang.ref.Finalizer
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   184
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   185
    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
   186
        synchronized (lock) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   187
            while (initLevel < value) {
21628
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
   188
                lock.wait();
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
   189
            }
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
   190
        }
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
   191
    }
50fd58446d64 8027351: (ref) Private finalize method invoked in preference to protected superclass method
mchung
parents: 14342
diff changeset
   192
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   193
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   194
     * Returns {@code true} if the module system has been initialized.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   195
     * @see java.lang.System#initPhase2
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   196
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   197
    public static boolean isModuleSystemInited() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   198
        return VM.initLevel() >= MODULE_SYSTEM_INITED;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   199
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   200
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   201
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   202
     * Returns {@code true} if the VM is fully initialized.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   203
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   204
    public static boolean isBooted() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   205
        return initLevel >= SYSTEM_BOOTED;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   206
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   207
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    // A user-settable upper limit on the maximum amount of allocatable direct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    // buffer memory.  This value may be changed during VM initialization if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    // "java" is launched with "-XX:MaxDirectMemorySize=<size>".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    // The initial value of this field is arbitrary; during JRE initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    // 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
   214
    // otherwise to Runtime.getRuntime().maxMemory().
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    private static long directMemory = 64 * 1024 * 1024;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   218
    // 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
   219
    // The directMemory variable is initialized during system initialization
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   220
    // in the saveAndRemoveProperties method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public static long maxDirectMemory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return directMemory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   226
    // User-controllable flag that determines if direct buffers should be page
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   227
    // aligned. The "-XX:+PageAlignDirectMemory" option can be used to force
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   228
    // buffers, allocated by ByteBuffer.allocateDirect, to be page aligned.
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   229
    private static boolean pageAlignDirectMemory;
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   230
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   231
    // 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
   232
    // variable is initialized by saveAndRemoveProperties.
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   233
    public static boolean isDirectMemoryPageAligned() {
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   234
        return pageAlignDirectMemory;
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   235
    }
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   236
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   237
    /**
13589
da4cb574f4a6 7193339: Prepare system classes be defined by a non-null module loader
mchung
parents: 11515
diff changeset
   238
     * Returns true if the given class loader is in the system domain
da4cb574f4a6 7193339: Prepare system classes be defined by a non-null module loader
mchung
parents: 11515
diff changeset
   239
     * in which all permissions are granted.
da4cb574f4a6 7193339: Prepare system classes be defined by a non-null module loader
mchung
parents: 11515
diff changeset
   240
     */
da4cb574f4a6 7193339: Prepare system classes be defined by a non-null module loader
mchung
parents: 11515
diff changeset
   241
    public static boolean isSystemDomainLoader(ClassLoader loader) {
da4cb574f4a6 7193339: Prepare system classes be defined by a non-null module loader
mchung
parents: 11515
diff changeset
   242
        return loader == null;
da4cb574f4a6 7193339: Prepare system classes be defined by a non-null module loader
mchung
parents: 11515
diff changeset
   243
    }
da4cb574f4a6 7193339: Prepare system classes be defined by a non-null module loader
mchung
parents: 11515
diff changeset
   244
da4cb574f4a6 7193339: Prepare system classes be defined by a non-null module loader
mchung
parents: 11515
diff changeset
   245
    /**
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   246
     * 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
   247
     * 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
   248
     * 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
   249
     * It accesses a private copy of the system properties so
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   250
     * that user's locking of the system properties object will not
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   251
     * cause the library to deadlock.
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   252
     *
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   253
     * Note that the saved system properties do not include
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   254
     * the ones set by sun.misc.Version.init().
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   255
     *
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   256
     */
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   257
    public static String getSavedProperty(String key) {
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   258
        if (savedProps.isEmpty())
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   259
            throw new IllegalStateException("Should be non-empty if initialized");
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   260
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   261
        return savedProps.getProperty(key);
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   262
    }
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   263
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7668
diff changeset
   264
    // TODO: the Property Management needs to be refactored and
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7668
diff changeset
   265
    // the appropriate prop keys need to be accessible to the
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7668
diff changeset
   266
    // calling classes to avoid duplication of keys.
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   267
    private static final Properties savedProps = new Properties();
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   268
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   269
    // 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
   270
    // the system properties that are not intended for public access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    //
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   272
    // 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
   273
    public static void saveAndRemoveProperties(Properties props) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   274
        if (initLevel() != 0)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   275
            throw new IllegalStateException("Wrong init level");
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   276
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   277
        savedProps.putAll(props);
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   278
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   279
        // 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
   280
        // by the vm option -XX:MaxDirectMemorySize=<size>.
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   281
        // 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
   282
        // 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
   283
        // The system property will be removed.
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   284
        String s = (String)props.remove("sun.nio.MaxDirectMemorySize");
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   285
        if (s != null) {
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   286
            if (s.equals("-1")) {
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   287
                // -XX:MaxDirectMemorySize not given, take default
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   288
                directMemory = Runtime.getRuntime().maxMemory();
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   289
            } else {
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   290
                long l = Long.parseLong(s);
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   291
                if (l > -1)
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   292
                    directMemory = l;
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   293
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   295
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   296
        // Check if direct buffers should be page aligned
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   297
        s = (String)props.remove("sun.nio.PageAlignDirectMemory");
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   298
        if ("true".equals(s))
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   299
            pageAlignDirectMemory = true;
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   300
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   301
        // Remove other private system properties
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   302
        // used by java.lang.Integer.IntegerCache
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   303
        props.remove("java.lang.Integer.IntegerCache.high");
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   304
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7668
diff changeset
   305
        // used by sun.launcher.LauncherHelper
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 7668
diff changeset
   306
        props.remove("sun.java.launcher.diag");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   307
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   308
        // used by jdk.internal.loader.ClassLoaders
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   309
        props.remove("jdk.boot.class.path.append");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   312
    // Initialize any miscellaneous operating system settings that need to be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    // set for the class libraries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public static void initializeOSEnvironment() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35616
diff changeset
   316
        if (initLevel() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            OSEnvironment.initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /* 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
   322
    private static volatile int finalRefCount;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    /* 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
   325
    private static volatile int peakFinalRefCount;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Gets the number of objects pending for finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @return the number of objects pending for finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public static int getFinalRefCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        return finalRefCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * Gets the peak number of objects pending for finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @return the peak number of objects pending for finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public static int getPeakFinalRefCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return peakFinalRefCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /*
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 28765
diff changeset
   346
     * Add {@code n} to the objects pending for finalization count.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @param n an integer value to be added to the objects pending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * for finalization count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public static void addFinalRefCount(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        // The caller must hold lock to synchronize the update.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        finalRefCount += n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        if (finalRefCount > peakFinalRefCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            peakFinalRefCount = finalRefCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
7540
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   360
    /**
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   361
     * Returns Thread.State for the given threadStatus
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   362
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    public static Thread.State toThreadState(int threadStatus) {
7540
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   364
        if ((threadStatus & JVMTI_THREAD_STATE_RUNNABLE) != 0) {
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   365
            return RUNNABLE;
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   366
        } else if ((threadStatus & JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER) != 0) {
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   367
            return BLOCKED;
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   368
        } else if ((threadStatus & JVMTI_THREAD_STATE_WAITING_INDEFINITELY) != 0) {
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   369
            return WAITING;
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   370
        } else if ((threadStatus & JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT) != 0) {
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   371
            return TIMED_WAITING;
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   372
        } else if ((threadStatus & JVMTI_THREAD_STATE_TERMINATED) != 0) {
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   373
            return TERMINATED;
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   374
        } else if ((threadStatus & JVMTI_THREAD_STATE_ALIVE) == 0) {
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   375
            return NEW;
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   376
        } else {
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   377
            return RUNNABLE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
7540
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   381
    /* The threadStatus field is set by the VM at state transition
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   382
     * in the hotspot implementation. Its value is set according to
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   383
     * the JVM TI specification GetThreadState function.
df3383a0e30d 6977034: Thread.getState() very slow
mchung
parents: 6902
diff changeset
   384
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30655
diff changeset
   385
    private static final int JVMTI_THREAD_STATE_ALIVE = 0x0001;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30655
diff changeset
   386
    private static final int JVMTI_THREAD_STATE_TERMINATED = 0x0002;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30655
diff changeset
   387
    private static final int JVMTI_THREAD_STATE_RUNNABLE = 0x0004;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30655
diff changeset
   388
    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
   389
    private static final int JVMTI_THREAD_STATE_WAITING_INDEFINITELY = 0x0010;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30655
diff changeset
   390
    private static final int JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT = 0x0020;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
10797
f51518b30c84 7104209: Cleanup and remove librmi (native library)
chegar
parents: 9035
diff changeset
   392
    /*
37899
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   393
     * Returns the first user-defined class loader up the execution stack,
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   394
     * 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
   395
     * bootstrap class loader is on the stack.
10797
f51518b30c84 7104209: Cleanup and remove librmi (native library)
chegar
parents: 9035
diff changeset
   396
     */
37899
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   397
    public static ClassLoader latestUserDefinedLoader() {
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   398
        ClassLoader loader = latestUserDefinedLoader0();
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   399
        return loader != null ? loader : ClassLoader.getPlatformClassLoader();
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   400
    }
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   401
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   402
    /*
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   403
     * Returns the first user-defined class loader up the execution stack,
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   404
     * 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
   405
     * 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
   406
     * it returns null.
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   407
     *
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   408
     * 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
   409
     * remove the logic in the VM.
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   410
     */
1b8ec90a1e15 8155977: ObjectInputStream::resolveClass & resolveProxyClass for platform loader
mchung
parents: 36511
diff changeset
   411
    private static native ClassLoader latestUserDefinedLoader0();
10797
f51518b30c84 7104209: Cleanup and remove librmi (native library)
chegar
parents: 9035
diff changeset
   412
22951
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 22571
diff changeset
   413
    /**
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 22571
diff changeset
   414
     * 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
   415
     */
24506
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   416
    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
   417
        long uid = getuid();
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   418
        long euid = geteuid();
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   419
        long gid = getgid();
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   420
        long egid = getegid();
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   421
        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
   422
    }
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   423
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   424
    /**
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   425
     * 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
   426
     * 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
   427
     */
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   428
    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
   429
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   430
    /**
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   431
     * 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
   432
     * 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
   433
     */
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   434
    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
   435
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   436
    /**
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   437
     * 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
   438
     * 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
   439
     */
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   440
    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
   441
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   442
    /**
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   443
     * 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
   444
     * 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
   445
     */
abb4cc4647ee 8043537: Changes for JDK-8039951 introduced circular dependency between Kerberos and com.sun.security.auth
weijun
parents: 23010
diff changeset
   446
    public static native long getegid();
22951
5fd21112b2b6 8034043: Native methods for preferences API should not be in libjava
alanb
parents: 22571
diff changeset
   447
28765
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   448
    /**
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   449
     * 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
   450
     *
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   451
     * 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
   452
     * {@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
   453
     *  java.time.Instant.ofEpochSecond(offsetInSeconds,
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   454
     *  getNanoTimeAdjustment(offsetInSeconds))}.
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   455
     * <p>
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   456
     * 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
   457
     * the current system.
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   458
     * 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
   459
     * 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
   460
     *
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   461
     * @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
   462
     *        time stamp should be computed.
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   463
     *
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   464
     * @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
   465
     *         {@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
   466
     *         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
   467
     *         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
   468
     *         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
   469
     *         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
   470
     *
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   471
     * @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
   472
     *     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
   473
     *     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
   474
     *     more accurate offset.
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   475
     */
8878e8455f2a 8068730: Increase the precision of the implementation of java.time.Clock.systemUTC()
dfuchs
parents: 28059
diff changeset
   476
    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
   477
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30655
diff changeset
   481
    private static native void initialize();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
}