|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package sun.misc; |
|
|
|
import static java.lang.Thread.State.*; |
|
import java.io.IOException; |
|
import java.security.AccessControlException; |
|
import java.util.Properties; |
|
import java.util.HashMap; |
|
import java.util.Map; |
|
import java.util.Set; |
|
|
|
public class VM { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
private static boolean suspended = false; |
|
|
|
|
|
@Deprecated |
|
public static boolean threadsSuspended() { |
|
return suspended; |
|
} |
|
|
|
@SuppressWarnings("deprecation") |
|
public static boolean allowThreadSuspension(ThreadGroup g, boolean b) { |
|
return g.allowThreadSuspension(b); |
|
} |
|
|
|
|
|
@Deprecated |
|
public static boolean suspendThreads() { |
|
suspended = true; |
|
return true; |
|
} |
|
|
|
// Causes any suspended threadgroups to be resumed. |
|
|
|
@Deprecated |
|
public static void unsuspendThreads() { |
|
suspended = false; |
|
} |
|
|
|
// Causes threadgroups no longer marked suspendable to be resumed. |
|
|
|
@Deprecated |
|
public static void unsuspendSomeThreads() { |
|
} |
|
|
|
/* Deprecated fields and methods -- Memory advice not supported in 1.2 */ |
|
|
|
|
|
@Deprecated |
|
public static final int STATE_GREEN = 1; |
|
|
|
|
|
@Deprecated |
|
public static final int STATE_YELLOW = 2; |
|
|
|
|
|
@Deprecated |
|
public static final int STATE_RED = 3; |
|
|
|
|
|
@Deprecated |
|
public static final int getState() { |
|
return STATE_GREEN; |
|
} |
|
|
|
|
|
@Deprecated |
|
public static void registerVMNotification(VMNotification n) { } |
|
|
|
|
|
@Deprecated |
|
public static void asChange(int as_old, int as_new) { } |
|
|
|
|
|
@Deprecated |
|
public static void asChange_otherthread(int as_old, int as_new) { } |
|
|
|
/* |
|
* Not supported in 1.2 because these will have to be exported as |
|
* JVM functions, and we are not sure we want do that. Leaving |
|
* here so it can be easily resurrected -- just remove the // |
|
* comments. |
|
*/ |
|
|
|
/** |
|
* Resume Java profiling. All profiling data is added to any |
|
* earlier profiling, unless <code>resetJavaProfiler</code> is |
|
* called in between. If profiling was not started from the |
|
* command line, <code>resumeJavaProfiler</code> will start it. |
|
* <p> |
|
* |
|
* NOTE: Profiling must be enabled from the command line for a |
|
* java.prof report to be automatically generated on exit; if not, |
|
* writeJavaProfilerReport must be invoked to write a report. |
|
* |
|
* @see resetJavaProfiler |
|
* @see writeJavaProfilerReport |
|
*/ |
|
|
|
// public native static void resumeJavaProfiler(); |
|
|
|
/** |
|
* Suspend Java profiling. |
|
*/ |
|
// public native static void suspendJavaProfiler(); |
|
|
|
/** |
|
* Initialize Java profiling. Any accumulated profiling |
|
* information is discarded. |
|
*/ |
|
// public native static void resetJavaProfiler(); |
|
|
|
/** |
|
* Write the current profiling contents to the file "java.prof". |
|
* If the file already exists, it will be overwritten. |
|
*/ |
|
// public native static void writeJavaProfilerReport(); |
|
|
|
|
|
private static volatile boolean booted = false; |
|
private static final Object lock = new Object(); |
|
|
|
// Invoked by by System.initializeSystemClass just before returning. |
|
// Subsystems that are invoked during initialization can check this |
|
// property in order to avoid doing things that should wait until the |
|
// application class loader has been set up. |
|
|
|
public static void booted() { |
|
synchronized (lock) { |
|
booted = true; |
|
lock.notifyAll(); |
|
} |
|
} |
|
|
|
public static boolean isBooted() { |
|
return booted; |
|
} |
|
|
|
// Waits until VM completes initialization |
|
// |
|
|
|
public static void awaitBooted() throws InterruptedException { |
|
synchronized (lock) { |
|
while (!booted) { |
|
lock.wait(); |
|
} |
|
} |
|
} |
|
|
|
// A user-settable upper limit on the maximum amount of allocatable direct |
|
// buffer memory. This value may be changed during VM initialization if |
|
// "java" is launched with "-XX:MaxDirectMemorySize=<size>". |
|
// |
|
// The initial value of this field is arbitrary; during JRE initialization |
|
// it will be reset to the value specified on the command line, if any, |
|
// otherwise to Runtime.getRuntime().maxMemory(). |
|
|
|
private static long directMemory = 64 * 1024 * 1024; |
|
|
|
// Returns the maximum amount of allocatable direct buffer memory. |
|
// The directMemory variable is initialized during system initialization |
|
// in the saveAndRemoveProperties method. |
|
|
|
public static long maxDirectMemory() { |
|
return directMemory; |
|
} |
|
|
|
// User-controllable flag that determines if direct buffers should be page |
|
// aligned. The "-XX:+PageAlignDirectMemory" option can be used to force |
|
|
|
private static boolean pageAlignDirectMemory; |
|
|
|
// Returns {@code true} if the direct buffers should be page aligned. This |
|
|
|
public static boolean isDirectMemoryPageAligned() { |
|
return pageAlignDirectMemory; |
|
} |
|
|
|
// A user-settable boolean to determine whether ClassLoader.loadClass should |
|
// accept array syntax. This value may be changed during VM initialization |
|
// via the system property "sun.lang.ClassLoader.allowArraySyntax". |
|
// |
|
// The default for 1.5 is "true", array syntax is allowed. In 1.6, the |
|
// default will be "false". The presence of this system property to |
|
// control array syntax allows applications the ability to preview this new |
|
// behaviour. |
|
|
|
private static boolean defaultAllowArraySyntax = false; |
|
private static boolean allowArraySyntax = defaultAllowArraySyntax; |
|
|
|
// The allowArraySyntax boolean is initialized during system initialization |
|
// in the saveAndRemoveProperties method. |
|
// |
|
// It is initialized based on the value of the system property |
|
// "sun.lang.ClassLoader.allowArraySyntax". If the system property is not |
|
// provided, the default for 1.5 is "true". In 1.6, the default will be |
|
// "false". If the system property is provided, then the value of |
|
// allowArraySyntax will be equal to "true" if Boolean.parseBoolean() |
|
// returns "true". Otherwise, the field will be set to "false". |
|
|
|
public static boolean allowArraySyntax() { |
|
return allowArraySyntax; |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
public static boolean isSystemDomainLoader(ClassLoader loader) { |
|
return loader == null; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static String getSavedProperty(String key) { |
|
if (savedProps.isEmpty()) |
|
throw new IllegalStateException("Should be non-empty if initialized"); |
|
|
|
return savedProps.getProperty(key); |
|
} |
|
|
|
// TODO: the Property Management needs to be refactored and |
|
// the appropriate prop keys need to be accessible to the |
|
|
|
private static final Properties savedProps = new Properties(); |
|
|
|
// Save a private copy of the system properties and remove |
|
// the system properties that are not intended for public access. |
|
// |
|
|
|
public static void saveAndRemoveProperties(Properties props) { |
|
if (booted) |
|
throw new IllegalStateException("System initialization has completed"); |
|
|
|
savedProps.putAll(props); |
|
|
|
// Set the maximum amount of direct memory. This value is controlled |
|
// by the vm option -XX:MaxDirectMemorySize=<size>. |
|
// The maximum amount of allocatable direct buffer memory (in bytes) |
|
// from the system property sun.nio.MaxDirectMemorySize set by the VM. |
|
|
|
String s = (String)props.remove("sun.nio.MaxDirectMemorySize"); |
|
if (s != null) { |
|
if (s.equals("-1")) { |
|
|
|
directMemory = Runtime.getRuntime().maxMemory(); |
|
} else { |
|
long l = Long.parseLong(s); |
|
if (l > -1) |
|
directMemory = l; |
|
} |
|
} |
|
|
|
|
|
s = (String)props.remove("sun.nio.PageAlignDirectMemory"); |
|
if ("true".equals(s)) |
|
pageAlignDirectMemory = true; |
|
|
|
// Set a boolean to determine whether ClassLoader.loadClass accepts |
|
// array syntax. This value is controlled by the system property |
|
|
|
s = props.getProperty("sun.lang.ClassLoader.allowArraySyntax"); |
|
allowArraySyntax = (s == null |
|
? defaultAllowArraySyntax |
|
: Boolean.parseBoolean(s)); |
|
|
|
// Remove other private system properties |
|
|
|
props.remove("java.lang.Integer.IntegerCache.high"); |
|
|
|
|
|
props.remove("sun.zip.disableMemoryMapping"); |
|
|
|
|
|
props.remove("sun.java.launcher.diag"); |
|
|
|
|
|
props.remove("sun.cds.enableSharedLookupCache"); |
|
} |
|
|
|
// Initialize any miscellenous operating system settings that need to be |
|
// set for the class libraries. |
|
|
|
public static void initializeOSEnvironment() { |
|
if (!booted) { |
|
OSEnvironment.initialize(); |
|
} |
|
} |
|
|
|
|
|
private static volatile int finalRefCount = 0; |
|
|
|
|
|
private static volatile int peakFinalRefCount = 0; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static int getFinalRefCount() { |
|
return finalRefCount; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static int getPeakFinalRefCount() { |
|
return peakFinalRefCount; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static void addFinalRefCount(int n) { |
|
// The caller must hold lock to synchronize the update. |
|
|
|
finalRefCount += n; |
|
if (finalRefCount > peakFinalRefCount) { |
|
peakFinalRefCount = finalRefCount; |
|
} |
|
} |
|
|
|
|
|
|
|
*/ |
|
public static Thread.State toThreadState(int threadStatus) { |
|
if ((threadStatus & JVMTI_THREAD_STATE_RUNNABLE) != 0) { |
|
return RUNNABLE; |
|
} else if ((threadStatus & JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER) != 0) { |
|
return BLOCKED; |
|
} else if ((threadStatus & JVMTI_THREAD_STATE_WAITING_INDEFINITELY) != 0) { |
|
return WAITING; |
|
} else if ((threadStatus & JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT) != 0) { |
|
return TIMED_WAITING; |
|
} else if ((threadStatus & JVMTI_THREAD_STATE_TERMINATED) != 0) { |
|
return TERMINATED; |
|
} else if ((threadStatus & JVMTI_THREAD_STATE_ALIVE) == 0) { |
|
return NEW; |
|
} else { |
|
return RUNNABLE; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
private final static int JVMTI_THREAD_STATE_ALIVE = 0x0001; |
|
private final static int JVMTI_THREAD_STATE_TERMINATED = 0x0002; |
|
private final static int JVMTI_THREAD_STATE_RUNNABLE = 0x0004; |
|
private final static int JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER = 0x0400; |
|
private final static int JVMTI_THREAD_STATE_WAITING_INDEFINITELY = 0x0010; |
|
private final static int JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT = 0x0020; |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public static native ClassLoader latestUserDefinedLoader0(); |
|
public static ClassLoader latestUserDefinedLoader() { |
|
ClassLoader loader = latestUserDefinedLoader0(); |
|
if (loader != null) { |
|
return loader; |
|
} |
|
try { |
|
return Launcher.ExtClassLoader.getExtClassLoader(); |
|
} catch (IOException e) { |
|
return null; |
|
} |
|
} |
|
|
|
static { |
|
initialize(); |
|
} |
|
private native static void initialize(); |
|
} |