hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/Threads.java
author pliden
Thu, 17 Mar 2016 08:07:53 +0100
changeset 37129 af29e306e50b
parent 35217 ce4b5303a813
child 40892 330a02d935ad
permissions -rw-r--r--
8151601: Cleanup locking of the Reference pending list Reviewed-by: brutisso, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
37129
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents: 35217
diff changeset
     2
 * Copyright (c) 2000, 2016, 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: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
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: 3261
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.*;
28369
a62a208f18de 8049716: PPC64: Implement SA on Linux/PPC64
simonis
parents: 27475
diff changeset
    28
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.runtime.solaris_sparc.SolarisSPARCJavaThreadPDAccess;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.runtime.solaris_x86.SolarisX86JavaThreadPDAccess;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.runtime.solaris_amd64.SolarisAMD64JavaThreadPDAccess;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.runtime.win32_amd64.Win32AMD64JavaThreadPDAccess;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
import sun.jvm.hotspot.runtime.win32_x86.Win32X86JavaThreadPDAccess;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
import sun.jvm.hotspot.runtime.linux_x86.LinuxX86JavaThreadPDAccess;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
import sun.jvm.hotspot.runtime.linux_amd64.LinuxAMD64JavaThreadPDAccess;
31399
167037a29ab4 8078521: AARCH64: Add AArch64 SA support
aph
parents: 28369
diff changeset
    38
import sun.jvm.hotspot.runtime.linux_aarch64.LinuxAARCH64JavaThreadPDAccess;
28369
a62a208f18de 8049716: PPC64: Implement SA on Linux/PPC64
simonis
parents: 27475
diff changeset
    39
import sun.jvm.hotspot.runtime.linux_ppc64.LinuxPPC64JavaThreadPDAccess;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
import sun.jvm.hotspot.runtime.linux_sparc.LinuxSPARCJavaThreadPDAccess;
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 8110
diff changeset
    41
import sun.jvm.hotspot.runtime.bsd_x86.BsdX86JavaThreadPDAccess;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 8110
diff changeset
    42
import sun.jvm.hotspot.runtime.bsd_amd64.BsdAMD64JavaThreadPDAccess;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
public class Threads {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    private static JavaThreadFactory threadFactory;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    private static AddressField      threadListField;
16351
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
    48
    private static CIntegerField     numOfThreadsField;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    private static VirtualConstructor virtualConstructor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    private static JavaThreadPDAccess access;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
        VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
            public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
                initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    private static synchronized void initialize(TypeDataBase db) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
        Type type = db.lookupType("Threads");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
        threadListField = type.getAddressField("_thread_list");
16351
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
    64
        numOfThreadsField = type.getCIntegerField("_number_of_threads");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
        // Instantiate appropriate platform-specific JavaThreadFactory
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
        String os  = VM.getVM().getOS();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
        String cpu = VM.getVM().getCPU();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
        access = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
        // FIXME: find the platform specific PD class by reflection?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
        if (os.equals("solaris")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
            if (cpu.equals("sparc")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
                access = new SolarisSPARCJavaThreadPDAccess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
            } else if (cpu.equals("x86")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
                access = new SolarisX86JavaThreadPDAccess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
            } else if (cpu.equals("amd64")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
                access = new SolarisAMD64JavaThreadPDAccess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
        } else if (os.equals("win32")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
            if (cpu.equals("x86")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
                access =  new Win32X86JavaThreadPDAccess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
            } else if (cpu.equals("amd64")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
                access =  new Win32AMD64JavaThreadPDAccess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
        } else if (os.equals("linux")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
            if (cpu.equals("x86")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
                access = new LinuxX86JavaThreadPDAccess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
            } else if (cpu.equals("amd64")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
                access = new LinuxAMD64JavaThreadPDAccess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
            } else if (cpu.equals("sparc")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
                access = new LinuxSPARCJavaThreadPDAccess();
28369
a62a208f18de 8049716: PPC64: Implement SA on Linux/PPC64
simonis
parents: 27475
diff changeset
    93
            } else if (cpu.equals("ppc64")) {
a62a208f18de 8049716: PPC64: Implement SA on Linux/PPC64
simonis
parents: 27475
diff changeset
    94
                access = new LinuxPPC64JavaThreadPDAccess();
31399
167037a29ab4 8078521: AARCH64: Add AArch64 SA support
aph
parents: 28369
diff changeset
    95
            } else if (cpu.equals("aarch64")) {
167037a29ab4 8078521: AARCH64: Add AArch64 SA support
aph
parents: 28369
diff changeset
    96
                access = new LinuxAARCH64JavaThreadPDAccess();
13529
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
    97
            } else {
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
    98
              try {
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
    99
                access = (JavaThreadPDAccess)
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   100
                  Class.forName("sun.jvm.hotspot.runtime.linux_" +
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   101
                     cpu.toLowerCase() + ".Linux" + cpu.toUpperCase() +
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   102
                     "JavaThreadPDAccess").newInstance();
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   103
              } catch (Exception e) {
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   104
                throw new RuntimeException("OS/CPU combination " + os + "/" + cpu +
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   105
                                           " not yet supported");
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   106
              }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
            }
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 8110
diff changeset
   108
        } else if (os.equals("bsd")) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 8110
diff changeset
   109
            if (cpu.equals("x86")) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 8110
diff changeset
   110
                access = new BsdX86JavaThreadPDAccess();
12728
a8abd64eaa1b 7163117: Agent can't connect to process on Mac OSX
nloodin
parents: 10565
diff changeset
   111
            } else if (cpu.equals("amd64") || cpu.equals("x86_64")) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 8110
diff changeset
   112
                access = new BsdAMD64JavaThreadPDAccess();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 8110
diff changeset
   113
            }
16351
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
   114
        } else if (os.equals("darwin")) {
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
   115
            if (cpu.equals("amd64") || cpu.equals("x86_64")) {
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
   116
                access = new BsdAMD64JavaThreadPDAccess();
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
   117
            }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
        if (access == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
            throw new RuntimeException("OS/CPU combination " + os + "/" + cpu +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
            " not yet supported");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
        virtualConstructor = new VirtualConstructor(db);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
        // Add mappings for all known thread types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
        virtualConstructor.addMapping("JavaThread", JavaThread.class);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
        if (!VM.getVM().isCore()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
            virtualConstructor.addMapping("CompilerThread", CompilerThread.class);
27475
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 16351
diff changeset
   130
            virtualConstructor.addMapping("CodeCacheSweeperThread", CodeCacheSweeperThread.class);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
        // for now, use JavaThread itself. fix it later with appropriate class if needed
37129
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents: 35217
diff changeset
   133
        virtualConstructor.addMapping("ReferencePendingListLockerThread", JavaThread.class);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
        virtualConstructor.addMapping("JvmtiAgentThread", JvmtiAgentThread.class);
8110
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 5547
diff changeset
   135
        virtualConstructor.addMapping("ServiceThread", ServiceThread.class);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    public Threads() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    /** NOTE: this returns objects of type JavaThread, CompilerThread,
8110
c992c8d52344 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 5547
diff changeset
   142
      JvmtiAgentThread, and ServiceThread.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      The latter four are subclasses of the former. Most operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      (fetching the top frame, etc.) are only allowed to be performed on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      a "pure" JavaThread. For this reason, {@link
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      sun.jvm.hotspot.runtime.JavaThread#isJavaThread} has been
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      changed from the definition in the VM (which returns true for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      all of these thread types) to return true for JavaThreads and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      false for the three subclasses. FIXME: should reconsider the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      inheritance hierarchy; see {@link
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      sun.jvm.hotspot.runtime.JavaThread#isJavaThread}. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    public JavaThread first() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
        Address threadAddr = threadListField.getValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
        if (threadAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
            return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
        return createJavaThreadWrapper(threadAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
16351
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
   161
    public int getNumberOfThreads() {
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
   162
        return (int) numOfThreadsField.getValue();
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
   163
    }
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
   164
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    /** Routine for instantiating appropriately-typed wrapper for a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      JavaThread. Currently needs to be public for OopUtilities to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      access it. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    public JavaThread createJavaThreadWrapper(Address threadAddr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
        try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
            JavaThread thread = (JavaThread)virtualConstructor.instantiateWrapperFor(threadAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
            thread.setThreadPDAccess(access);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
            return thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
        } catch (Exception e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
            throw new RuntimeException("Unable to deduce type of thread from address " + threadAddr +
37129
af29e306e50b 8151601: Cleanup locking of the Reference pending list
pliden
parents: 35217
diff changeset
   175
            " (expected type JavaThread, CompilerThread, ServiceThread, JvmtiAgentThread, ReferencePendingListLockerThread, or CodeCacheSweeperThread)", e);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    /** Memory operations */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    public void oopsDo(AddressVisitor oopVisitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
        // FIXME: add more of VM functionality
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
        for (JavaThread thread = first(); thread != null; thread = thread.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
            thread.oopsDo(oopVisitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    // refer to Threads::owning_thread_from_monitor_owner
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    public JavaThread owningThreadFromMonitor(Address o) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
        if (o == null) return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
        for (JavaThread thread = first(); thread != null; thread = thread.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
            if (o.equals(thread.threadObjectAddress())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
                return thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
        for (JavaThread thread = first(); thread != null; thread = thread.next()) {
2526
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 1
diff changeset
   197
          if (thread.isLockOwned(o))
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 1
diff changeset
   198
            return thread;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
        }
2526
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 1
diff changeset
   200
        return null;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    public JavaThread owningThreadFromMonitor(ObjectMonitor monitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
        return owningThreadFromMonitor(monitor.owner());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    // refer to Threads::get_pending_threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    // Get list of Java threads that are waiting to enter the specified monitor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    public List getPendingThreads(ObjectMonitor monitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
        List pendingThreads = new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
        for (JavaThread thread = first(); thread != null; thread = thread.next()) {
27475
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 16351
diff changeset
   212
            if (thread.isCompilerThread() || thread.isCodeCacheSweeperThread()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
                continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
            ObjectMonitor pending = thread.getCurrentPendingMonitor();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
            if (monitor.equals(pending)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
                pendingThreads.add(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
        return pendingThreads;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    // Get list of Java threads that have called Object.wait on the specified monitor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    public List getWaitingThreads(ObjectMonitor monitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
        List pendingThreads = new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
        for (JavaThread thread = first(); thread != null; thread = thread.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
            ObjectMonitor waiting = thread.getCurrentWaitingMonitor();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
            if (monitor.equals(waiting)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
                pendingThreads.add(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
        return pendingThreads;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    // FIXME: add other accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
}