src/java.base/share/classes/jdk/internal/misc/VM.java
changeset 48942 a6c4b85163c1
parent 47216 71c04702a3d5
child 50951 b96466cdfc45
--- a/src/java.base/share/classes/jdk/internal/misc/VM.java	Fri Feb 23 14:26:29 2018 -0500
+++ b/src/java.base/share/classes/jdk/internal/misc/VM.java	Fri Feb 23 12:10:56 2018 -0800
@@ -27,9 +27,7 @@
 
 import static java.lang.Thread.State.*;
 import java.util.Map;
-import java.util.HashMap;
 import java.util.Properties;
-import java.util.Collections;
 
 public class VM {
 
@@ -38,6 +36,8 @@
     private static final int MODULE_SYSTEM_INITED        = 2;
     private static final int SYSTEM_LOADER_INITIALIZING  = 3;
     private static final int SYSTEM_BOOTED               = 4;
+    private static final int SYSTEM_SHUTDOWN             = 5;
+
 
     // 0, 1, 2, ...
     private static volatile int initLevel;
@@ -52,7 +52,7 @@
      */
     public static void initLevel(int value) {
         synchronized (lock) {
-            if (value <= initLevel || value > SYSTEM_BOOTED)
+            if (value <= initLevel || value > SYSTEM_SHUTDOWN)
                 throw new InternalError("Bad level: " + value);
             initLevel = value;
             lock.notifyAll();
@@ -94,6 +94,23 @@
         return initLevel >= SYSTEM_BOOTED;
     }
 
+    /**
+     * Set shutdown state.  Shutdown completes when all registered shutdown
+     * hooks have been run.
+     *
+     * @see java.lang.Shutdown
+     */
+    public static void shutdown() {
+        initLevel(SYSTEM_SHUTDOWN);
+    }
+
+    /**
+     * Returns {@code true} if the VM has been shutdown
+     */
+    public static boolean isShutdown() {
+        return initLevel == SYSTEM_SHUTDOWN;
+    }
+
     // 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>".