/*
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.internal.misc;
import static java.lang.Thread.State.*;
import dalvik.annotation.optimization.CriticalNative;
import java.util.Properties;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class VM {
/* The following methods used to be native methods that instruct
* the VM to selectively suspend certain threads in low-memory
* situations. They are inherently dangerous and not implementable
* on native threads. We removed them in JDK 1.2. The skeletons
* remain so that existing applications that use these methods
* will still work.
*/
private static boolean suspended = false;
/** @deprecated */
@Deprecated
public static boolean threadsSuspended() {
return suspended;
}
@SuppressWarnings("deprecation")
public static boolean allowThreadSuspension(ThreadGroup g, boolean b) {
return g.allowThreadSuspension(b);
}
/** @deprecated */
@Deprecated
public static boolean suspendThreads() {
suspended = true;
return true;
}
// Causes any suspended threadgroups to be resumed.
/** @deprecated */
@Deprecated
public static void unsuspendThreads() {
suspended = false;
}
// Causes threadgroups no longer marked suspendable to be resumed.
/** @deprecated */
@Deprecated
public static void unsuspendSomeThreads() {
}
/* Deprecated fields and methods -- Memory advice not supported in 1.2 */
/** @deprecated */
@Deprecated
public static final int STATE_GREEN = 1;
/** @deprecated */
@Deprecated
public static final int STATE_YELLOW = 2;
/** @deprecated */
@Deprecated
public static final int STATE_RED = 3;
/** @deprecated */
@Deprecated
public static final int getState() {
return STATE_GREEN;
}
// Android-removed: Not used.
/** @deprecated */
// @Deprecated
// public static void registerVMNotification(VMNotification n) { }
/** @deprecated */
@Deprecated
public static void asChange(int as_old, int as_new) { }
/** @deprecated */
@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 resetJavaProfiler
is
* called in between. If profiling was not started from the
* command line, resumeJavaProfiler
will start it.
*
*
* 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
//
// This method is invoked by the Finalizer thread
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=
* The value returned has the best resolution available to the JVM on
* the current system.
* This is usually down to microseconds - or tenth of microseconds -
* depending on the OS/Hardware and the JVM implementation.
*
* @param offsetInSeconds The offset in seconds from which the nanosecond
* time stamp should be computed.
*
* @apiNote The offset should be recent enough - so that
* {@code offsetInSeconds} is within {@code +/- 2^32} seconds of the
* current UTC time. If the offset is too far off, {@code -1} will be
* returned. As such, {@code -1} must not be considered as a valid
* nano time adjustment, but as an exception value indicating
* that an offset closer to the current time should be used.
*
* @return A nanosecond time stamp adjustment in the form of a single long.
* If the offset is too far off the current time, this method returns -1.
* In that case, the caller should call this method again, passing a
* more accurate offset.
*/
@CriticalNative
public static native long getNanoTimeAdjustment(long offsetInSeconds);
// BEGIN Android-removed: latestUserDefinedLoader()/initialize() not supported.
// /*
// * Returns the first non-null class loader up the execution stack,
// * or null if only code from the null class loader is on the stack.
// */
// public static native ClassLoader latestUserDefinedLoader();
// static {
// initialize();
// }
// private native static void initialize();
// END Android-removed: latestUserDefinedLoader()/initialize() not supported.
// BEGIN Android-removed: initializeFromArchive() not supported.
/*
* Initialize archived static fields in the given Class using archived
* values from CDS dump time. Also initialize the classes of objects in
* the archived graph referenced by those fields.
*
* Those static fields remain as uninitialized if there is no mapped CDS
* java heap data or there is any error during initialization of the
* object class in the archived graph.
*
public static native void initializeFromArchive(Class> c);
*/
// END Android-removed: initializeFromArchive() not supported.
}