jdk/src/share/classes/sun/misc/VM.java
author alanb
Mon, 18 Oct 2010 10:29:59 +0100
changeset 6902 3352f8839320
parent 6882 637546039be3
child 7540 df3383a0e30d
permissions -rw-r--r--
4837564: (bf) Please make DirectByteBuffer performance enhancements Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3958
diff changeset
     2
 * Copyright (c) 1996, 2005, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.misc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
public class VM {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    /* The following methods used to be native methods that instruct
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
     * the VM to selectively suspend certain threads in low-memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
     * situations. They are inherently dangerous and not implementable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
     * on native threads. We removed them in JDK 1.2. The skeletons
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * remain so that existing applications that use these methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * will still work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static boolean suspended = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    public static boolean threadsSuspended() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        return suspended;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static boolean allowThreadSuspension(ThreadGroup g, boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        return g.allowThreadSuspension(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public static boolean suspendThreads() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        suspended = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // Causes any suspended threadgroups to be resumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public static void unsuspendThreads() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        suspended = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // Causes threadgroups no longer marked suspendable to be resumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public static void unsuspendSomeThreads() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /* Deprecated fields and methods -- Memory advice not supported in 1.2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static final int STATE_GREEN = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public static final int STATE_YELLOW = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static final int STATE_RED = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static final int getState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        return STATE_GREEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public static void registerVMNotification(VMNotification n) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public static void asChange(int as_old, int as_new) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /** @deprecated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public static void asChange_otherthread(int as_old, int as_new) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Not supported in 1.2 because these will have to be exported as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * JVM functions, and we are not sure we want do that. Leaving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * here so it can be easily resurrected -- just remove the //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * comments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Resume Java profiling.  All profiling data is added to any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * earlier profiling, unless <code>resetJavaProfiler</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * called in between.  If profiling was not started from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * command line, <code>resumeJavaProfiler</code> will start it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * NOTE: Profiling must be enabled from the command line for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * java.prof report to be automatically generated on exit; if not,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * writeJavaProfilerReport must be invoked to write a report.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @see     resetJavaProfiler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @see     writeJavaProfilerReport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    // public native static void resumeJavaProfiler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Suspend Java profiling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    // public native static void suspendJavaProfiler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Initialize Java profiling.  Any accumulated profiling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * information is discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    // public native static void resetJavaProfiler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Write the current profiling contents to the file "java.prof".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * If the file already exists, it will be overwritten.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    // public native static void writeJavaProfilerReport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private static volatile boolean booted = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    // Invoked by by System.initializeSystemClass just before returning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    // Subsystems that are invoked during initialization can check this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    // property in order to avoid doing things that should wait until the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    // application class loader has been set up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public static void booted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        booted = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public static boolean isBooted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return booted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    // A user-settable upper limit on the maximum amount of allocatable direct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    // buffer memory.  This value may be changed during VM initialization if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    // "java" is launched with "-XX:MaxDirectMemorySize=<size>".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    // The initial value of this field is arbitrary; during JRE initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    // it will be reset to the value specified on the command line, if any,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    // otherwise to Runtime.getRuntime.maxDirectMemory().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private static long directMemory = 64 * 1024 * 1024;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   173
    // 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
   174
    // The directMemory variable is initialized during system initialization
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   175
    // in the saveAndRemoveProperties method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public static long maxDirectMemory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        return directMemory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   181
    // User-controllable flag that determines if direct buffers should be page
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   182
    // aligned. The "-XX:+PageAlignDirectMemory" option can be used to force
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   183
    // buffers, allocated by ByteBuffer.allocateDirect, to be page aligned.
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   184
    private static boolean pageAlignDirectMemory;
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   185
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   186
    // 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
   187
    // variable is initialized by saveAndRemoveProperties.
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   188
    public static boolean isDirectMemoryPageAligned() {
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   189
        return pageAlignDirectMemory;
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   190
    }
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   191
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    // A user-settable boolean to determine whether ClassLoader.loadClass should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    // accept array syntax.  This value may be changed during VM initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    // via the system property "sun.lang.ClassLoader.allowArraySyntax".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    // The default for 1.5 is "true", array syntax is allowed.  In 1.6, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    // default will be "false".  The presence of this system property to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    // control array syntax allows applications the ability to preview this new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    // behaviour.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private static boolean defaultAllowArraySyntax = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    private static boolean allowArraySyntax = defaultAllowArraySyntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   204
    // The allowArraySyntax boolean is initialized during system initialization
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   205
    // in the saveAndRemoveProperties method.
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   206
    //
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   207
    // It is initialized based on the value of the system property
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    // "sun.lang.ClassLoader.allowArraySyntax".  If the system property is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    // provided, the default for 1.5 is "true".  In 1.6, the default will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    // "false".  If the system property is provided, then the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    // allowArraySyntax will be equal to "true" if Boolean.parseBoolean()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    // returns "true".   Otherwise, the field will be set to "false".
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
    public static boolean allowArraySyntax() {
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   215
        return allowArraySyntax;
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   216
    }
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   217
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   218
    /**
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   219
     * 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
   220
     * 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
   221
     * 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
   222
     * 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
   223
     * 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
   224
     * cause the library to deadlock.
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   225
     *
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   226
     * 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
   227
     * the ones set by sun.misc.Version.init().
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   228
     *
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   229
     */
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   230
    public static String getSavedProperty(String key) {
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   231
        if (savedProps.isEmpty())
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   232
            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
   233
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   234
        return savedProps.getProperty(key);
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   235
    }
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   236
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   237
    private static final Properties savedProps = new Properties();
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   238
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   239
    // 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
   240
    // the system properties that are not intended for public access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    //
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   242
    // 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
   243
    public static void saveAndRemoveProperties(Properties props) {
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   244
        if (booted)
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   245
            throw new IllegalStateException("System initialization has completed");
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   246
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   247
        savedProps.putAll(props);
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   248
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   249
        // 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
   250
        // by the vm option -XX:MaxDirectMemorySize=<size>.
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   251
        // 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
   252
        // 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
   253
        // The system property will be removed.
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   254
        String s = (String)props.remove("sun.nio.MaxDirectMemorySize");
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   255
        if (s != null) {
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   256
            if (s.equals("-1")) {
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   257
                // -XX:MaxDirectMemorySize not given, take default
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   258
                directMemory = Runtime.getRuntime().maxMemory();
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   259
            } else {
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   260
                long l = Long.parseLong(s);
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   261
                if (l > -1)
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   262
                    directMemory = l;
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   263
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   265
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   266
        // Check if direct buffers should be page aligned
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   267
        s = (String)props.remove("sun.nio.PageAlignDirectMemory");
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   268
        if ("true".equals(s))
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   269
            pageAlignDirectMemory = true;
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6882
diff changeset
   270
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   271
        // Set a boolean to determine whether ClassLoader.loadClass accepts
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   272
        // array syntax.  This value is controlled by the system property
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   273
        // "sun.lang.ClassLoader.allowArraySyntax".
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   274
        s = props.getProperty("sun.lang.ClassLoader.allowArraySyntax");
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   275
        allowArraySyntax = (s == null
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   276
                               ? defaultAllowArraySyntax
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   277
                               : Boolean.parseBoolean(s));
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
        // Remove other private system properties
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   280
        // used by java.lang.Integer.IntegerCache
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   281
        props.remove("java.lang.Integer.IntegerCache.high");
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   282
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   283
        // used by java.util.zip.ZipFile
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 5506
diff changeset
   284
        props.remove("sun.zip.disableMemoryMapping");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    // Initialize any miscellenous operating system settings that need to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    // set for the class libraries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public static void initializeOSEnvironment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (!booted) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            OSEnvironment.initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /* Current count of objects pending for finalization */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    private static volatile int finalRefCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /* Peak count of objects pending for finalization */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    private static volatile int peakFinalRefCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Gets the number of objects pending for finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @return the number of objects pending for finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public static int getFinalRefCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        return finalRefCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * Gets the peak number of objects pending for finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @return the peak number of objects pending for finalization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public static int getPeakFinalRefCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        return peakFinalRefCount;
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
     * Add <tt>n</tt> to the objects pending for finalization count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @param n an integer value to be added to the objects pending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * for finalization count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public static void addFinalRefCount(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        // The caller must hold lock to synchronize the update.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        finalRefCount += n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (finalRefCount > peakFinalRefCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            peakFinalRefCount = finalRefCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public static Thread.State toThreadState(int threadStatus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        // Initialize the threadStateMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        initThreadStateMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        Thread.State s = threadStateMap.get(threadStatus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            // default to RUNNABLE if the threadStatus value is unknown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            s = Thread.State.RUNNABLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    // a map of threadStatus values to the corresponding Thread.State
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    private static Map<Integer, Thread.State> threadStateMap = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    private static Map<Integer, String> threadStateNames = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    private synchronized static void initThreadStateMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        if (threadStateMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        final Thread.State[] ts = Thread.State.values();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        final int[][] vmThreadStateValues = new int[ts.length][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        final String[][] vmThreadStateNames = new String[ts.length][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        getThreadStateValues(vmThreadStateValues, vmThreadStateNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        threadStateMap = new HashMap<Integer, Thread.State>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        threadStateNames = new HashMap<Integer, String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        for (int i = 0; i < ts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            String state = ts[i].name();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            int[] values = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            String[] names = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            for (int j = 0; j < ts.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                if (vmThreadStateNames[j][0].startsWith(state)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    values = vmThreadStateValues[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    names = vmThreadStateNames[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            if (values == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                throw new InternalError("No VM thread state mapped to " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            if (values.length != names.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                throw new InternalError("VM thread state values and names " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    " mapped to " + state + ": length not matched" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            for (int k = 0; k < values.length; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                threadStateMap.put(values[k], ts[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                threadStateNames.put(values[k], names[k]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    // Fill in vmThreadStateValues with int arrays, each of which contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    // the threadStatus values mapping to the Thread.State enum constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    // Fill in vmThreadStateNames with String arrays, each of which contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    // the name of each threadStatus value of the format:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    //    <Thread.State.name()>[.<Substate name>]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    // e.g. WAITING.OBJECT_WAIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    private native static void getThreadStateValues(int[][] vmThreadStateValues,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                                                    String[][] vmThreadStateNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    private native static void initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
}