< prev index next >

src/java.base/share/classes/jdk/internal/misc/VM.java

Print this page

 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package jdk.internal.misc;
 27 
 28 import static java.lang.Thread.State.*;
 29 
 30 import java.text.NumberFormat;
 31 import java.util.ArrayList;
 32 import java.util.Collections;
 33 import java.util.List;
 34 import java.util.Map;
 35 
 36 import jdk.internal.access.SharedSecrets;
 37 
 38 import sun.nio.ch.FileChannelImpl;
 39 
 40 public class VM {
 41 
 42     // the init level when the VM is fully initialized
 43     private static final int JAVA_LANG_SYSTEM_INITED     = 1;
 44     private static final int MODULE_SYSTEM_INITED        = 2;
 45     private static final int SYSTEM_LOADER_INITIALIZING  = 3;
 46     private static final int SYSTEM_BOOTED               = 4;
 47     private static final int SYSTEM_SHUTDOWN             = 5;
 48 
 49     // 0, 1, 2, ...
 50     private static volatile int initLevel;
 51     private static final Object lock = new Object();
 52 
 53     /**
 54      * Sets the init level.
 55      *
 56      * @see java.lang.System#initPhase1
 57      * @see java.lang.System#initPhase2

 74     }
 75 
 76     /**
 77      * Waits for the init level to get the given value.
 78      *
 79      * @see java.lang.ref.Finalizer
 80      */
 81     public static void awaitInitLevel(int value) throws InterruptedException {
 82         synchronized (lock) {
 83             while (initLevel < value) {
 84                 lock.wait();
 85             }
 86         }
 87     }
 88 
 89     /**
 90      * Returns {@code true} if the module system has been initialized.
 91      * @see java.lang.System#initPhase2
 92      */
 93     public static boolean isModuleSystemInited() {
 94         return VM.initLevel() >= MODULE_SYSTEM_INITED;












 95     }
 96 
 97     /**
 98      * Returns {@code true} if the VM is fully initialized.
 99      */
100     public static boolean isBooted() {
101         return initLevel >= SYSTEM_BOOTED;
102     }
103 
104     /**
105      * Set shutdown state.  Shutdown completes when all registered shutdown
106      * hooks have been run.
107      *
108      * @see java.lang.Shutdown
109      */
110     public static void shutdown() {
111         initLevel(SYSTEM_SHUTDOWN);
112     }
113 
114     /**

 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 package jdk.internal.misc;
 27 
 28 import static java.lang.Thread.State.*;
 29 

 30 import java.util.ArrayList;
 31 import java.util.Collections;
 32 import java.util.List;
 33 import java.util.Map;
 34 
 35 import jdk.internal.access.SharedSecrets;
 36 import jdk.internal.vm.annotation.Stable;
 37 import sun.nio.ch.FileChannelImpl;
 38 
 39 public class VM {
 40 
 41     // the init level when the VM is fully initialized
 42     private static final int JAVA_LANG_SYSTEM_INITED     = 1;
 43     private static final int MODULE_SYSTEM_INITED        = 2;
 44     private static final int SYSTEM_LOADER_INITIALIZING  = 3;
 45     private static final int SYSTEM_BOOTED               = 4;
 46     private static final int SYSTEM_SHUTDOWN             = 5;
 47 
 48     // 0, 1, 2, ...
 49     private static volatile int initLevel;
 50     private static final Object lock = new Object();
 51 
 52     /**
 53      * Sets the init level.
 54      *
 55      * @see java.lang.System#initPhase1
 56      * @see java.lang.System#initPhase2

 73     }
 74 
 75     /**
 76      * Waits for the init level to get the given value.
 77      *
 78      * @see java.lang.ref.Finalizer
 79      */
 80     public static void awaitInitLevel(int value) throws InterruptedException {
 81         synchronized (lock) {
 82             while (initLevel < value) {
 83                 lock.wait();
 84             }
 85         }
 86     }
 87 
 88     /**
 89      * Returns {@code true} if the module system has been initialized.
 90      * @see java.lang.System#initPhase2
 91      */
 92     public static boolean isModuleSystemInited() {
 93         return initLevel >= MODULE_SYSTEM_INITED;
 94     }
 95 
 96     private static @Stable boolean javaLangInvokeInited;
 97     public static void setJavaLangInvokeInited() {
 98         if (javaLangInvokeInited) {
 99             throw new InternalError("java.lang.invoke already inited");
100         }
101         javaLangInvokeInited = true;
102     }
103 
104     public static boolean isJavaLangInvokeInited() {
105         return javaLangInvokeInited;
106     }
107 
108     /**
109      * Returns {@code true} if the VM is fully initialized.
110      */
111     public static boolean isBooted() {
112         return initLevel >= SYSTEM_BOOTED;
113     }
114 
115     /**
116      * Set shutdown state.  Shutdown completes when all registered shutdown
117      * hooks have been run.
118      *
119      * @see java.lang.Shutdown
120      */
121     public static void shutdown() {
122         initLevel(SYSTEM_SHUTDOWN);
123     }
124 
125     /**
< prev index next >