Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/OSThread.java
41161 views
/*1* Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324package sun.jvm.hotspot.runtime;2526import java.util.*;27import sun.jvm.hotspot.debugger.*;28import sun.jvm.hotspot.types.*;29import sun.jvm.hotspot.utilities.Observable;30import sun.jvm.hotspot.utilities.Observer;3132// The OSThread class holds OS-specific thread information. It is equivalent33// to the sys_thread_t structure of the classic JVM implementation.34public class OSThread extends VMObject {35private static Field threadIdField;36private static CIntegerField threadStateField;3738// ThreadStates read from underlying process39private static int ALLOCATED;40private static int INITIALIZED;41private static int RUNNABLE;42private static int MONITOR_WAIT;43private static int CONDVAR_WAIT;44private static int OBJECT_WAIT;45private static int BREAKPOINTED;46private static int SLEEPING;47private static int ZOMBIE;4849static {50VM.registerVMInitializedObserver(new Observer() {51public void update(Observable o, Object data) {52initialize(VM.getVM().getTypeDataBase());53}54});55}5657private static synchronized void initialize(TypeDataBase db) {58Type type = db.lookupType("OSThread");59threadIdField = type.getField("_thread_id");60threadStateField = type.getCIntegerField("_state");6162ALLOCATED = db.lookupIntConstant("ALLOCATED").intValue();63INITIALIZED = db.lookupIntConstant("INITIALIZED").intValue();64RUNNABLE = db.lookupIntConstant("RUNNABLE").intValue();65MONITOR_WAIT = db.lookupIntConstant("MONITOR_WAIT").intValue();66CONDVAR_WAIT = db.lookupIntConstant("CONDVAR_WAIT").intValue();67OBJECT_WAIT = db.lookupIntConstant("OBJECT_WAIT").intValue();68BREAKPOINTED = db.lookupIntConstant("BREAKPOINTED").intValue();69SLEEPING = db.lookupIntConstant("SLEEPING").intValue();70ZOMBIE = db.lookupIntConstant("ZOMBIE").intValue();71}7273public OSThread(Address addr) {74super(addr);75}7677public int threadId() {78return threadIdField.getJInt(addr);79}8081public ThreadState getThreadState() {82int val = (int)threadStateField.getValue(addr);83if (val == ALLOCATED) {84return ThreadState.ALLOCATED;85} else if (val == INITIALIZED) {86return ThreadState.INITIALIZED;87} else if (val == RUNNABLE) {88return ThreadState.RUNNABLE;89} else if (val == MONITOR_WAIT) {90return ThreadState.MONITOR_WAIT;91} else if (val == CONDVAR_WAIT) {92return ThreadState.CONDVAR_WAIT;93} else if (val == OBJECT_WAIT) {94return ThreadState.OBJECT_WAIT;95} else if (val == BREAKPOINTED) {96return ThreadState.BREAKPOINTED;97} else if (val == SLEEPING) {98return ThreadState.SLEEPING;99} else if (val == ZOMBIE) {100return ThreadState.ZOMBIE;101} else {102throw new RuntimeException("Illegal thread state " + val);103}104}105}106107108