src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/OSThread.java
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 58901 2700c409ff10
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
58901
2700c409ff10 8229516: Thread.isInterrupted() always returns false after thread termination
dholmes
parents: 47216
diff changeset
     2
 * Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot.runtime;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// The OSThread class holds OS-specific thread information.  It is equivalent
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// to the sys_thread_t structure of the classic JVM implementation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
public class OSThread extends VMObject {
19152
44fdfecd8f6c 8019396: SA-JDI OSThread class initialization throws an exception
dsamersoff
parents: 15455
diff changeset
    34
    private static Field threadIdField;
46636
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    35
    private static CIntegerField threadStateField;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    36
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    37
    // ThreadStates read from underlying process
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    38
    private static int ALLOCATED;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    39
    private static int INITIALIZED;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    40
    private static int RUNNABLE;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    41
    private static int MONITOR_WAIT;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    42
    private static int CONDVAR_WAIT;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    43
    private static int OBJECT_WAIT;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    44
    private static int BREAKPOINTED;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    45
    private static int SLEEPING;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    46
    private static int ZOMBIE;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    47
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
        VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
            public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
                initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    private static synchronized void initialize(TypeDataBase db) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
        Type type = db.lookupType("OSThread");
19152
44fdfecd8f6c 8019396: SA-JDI OSThread class initialization throws an exception
dsamersoff
parents: 15455
diff changeset
    58
        threadIdField = type.getField("_thread_id");
46636
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    59
        threadStateField = type.getCIntegerField("_state");
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    60
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    61
        ALLOCATED = db.lookupIntConstant("ALLOCATED").intValue();
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    62
        INITIALIZED = db.lookupIntConstant("INITIALIZED").intValue();
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    63
        RUNNABLE = db.lookupIntConstant("RUNNABLE").intValue();
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    64
        MONITOR_WAIT = db.lookupIntConstant("MONITOR_WAIT").intValue();
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    65
        CONDVAR_WAIT = db.lookupIntConstant("CONDVAR_WAIT").intValue();
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    66
        OBJECT_WAIT = db.lookupIntConstant("OBJECT_WAIT").intValue();
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    67
        BREAKPOINTED = db.lookupIntConstant("BREAKPOINTED").intValue();
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    68
        SLEEPING = db.lookupIntConstant("SLEEPING").intValue();
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    69
        ZOMBIE = db.lookupIntConstant("ZOMBIE").intValue();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    public OSThread(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
        super(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
15455
c0a94d1e6b59 8000973: SA on windows thread inspection is broken
minqi
parents: 5547
diff changeset
    76
    public int threadId() {
19152
44fdfecd8f6c 8019396: SA-JDI OSThread class initialization throws an exception
dsamersoff
parents: 15455
diff changeset
    77
        return threadIdField.getJInt(addr);
15455
c0a94d1e6b59 8000973: SA on windows thread inspection is broken
minqi
parents: 5547
diff changeset
    78
    }
c0a94d1e6b59 8000973: SA on windows thread inspection is broken
minqi
parents: 5547
diff changeset
    79
46636
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    80
    public ThreadState getThreadState() {
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    81
        int val = (int)threadStateField.getValue(addr);
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    82
        if (val ==  ALLOCATED) {
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    83
            return ThreadState.ALLOCATED;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    84
        } else if (val ==  INITIALIZED) {
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    85
            return ThreadState.INITIALIZED;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    86
        } else if (val ==  RUNNABLE) {
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    87
            return ThreadState.RUNNABLE;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    88
        } else if (val ==  MONITOR_WAIT) {
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    89
            return ThreadState.MONITOR_WAIT;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    90
        } else if (val ==  CONDVAR_WAIT) {
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    91
            return ThreadState.CONDVAR_WAIT;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    92
        } else if (val ==  OBJECT_WAIT) {
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    93
            return ThreadState.OBJECT_WAIT;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    94
        } else if (val ==  BREAKPOINTED) {
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    95
            return ThreadState.BREAKPOINTED;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    96
        } else if (val ==  SLEEPING) {
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    97
            return ThreadState.SLEEPING;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    98
        } else if (val ==  ZOMBIE) {
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    99
            return ThreadState.ZOMBIE;
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
   100
        } else {
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
   101
            throw new RuntimeException("Illegal thread state " + val);
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
   102
        }
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
   103
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
}