src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/Threads.java
author dtitov
Tue, 08 Oct 2019 09:13:08 -0700
changeset 58503 726a3945e934
parent 54955 46409371a691
permissions -rw-r--r--
8170299: Debugger does not stop inside the low memory notifications code Reviewed-by: sspitsyn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 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: 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
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    45
class ThreadsList extends VMObject {
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    46
    private static AddressField  threadsField;
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    47
    private static CIntegerField lengthField;
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    48
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    49
    static {
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    50
        VM.registerVMInitializedObserver((o, d) -> initialize(VM.getVM().getTypeDataBase()));
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    51
    }
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    52
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    53
    private static synchronized void initialize(TypeDataBase db) {
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    54
        Type type = db.lookupType("ThreadsList");
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    55
        lengthField = type.getCIntegerField("_length");
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    56
        threadsField = type.getAddressField("_threads");
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    57
    }
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    58
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    59
    public Address getJavaThreadAddressAt(int i) {
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    60
      Address threadAddr = threadsField.getValue(addr);
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    61
      Address at = threadAddr.getAddressAt(VM.getVM().getAddressSize() * i);
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    62
      return at;
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    63
    }
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    64
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    65
    public long length() {
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    66
        return lengthField.getValue(addr);
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    67
    }
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    68
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    69
    public ThreadsList(Address addr) {
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    70
        super(addr);
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    71
    }
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    72
}
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    73
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
public class Threads {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    private static JavaThreadFactory threadFactory;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    private static AddressField      threadListField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    private static VirtualConstructor virtualConstructor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    private static JavaThreadPDAccess access;
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    79
    private static ThreadsList _list;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
        VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
            public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
                initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
        });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    private static synchronized void initialize(TypeDataBase db) {
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    90
        Type type = db.lookupType("ThreadsSMRSupport");
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
    91
        threadListField = type.getAddressField("_java_thread_list");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
        // Instantiate appropriate platform-specific JavaThreadFactory
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
        String os  = VM.getVM().getOS();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
        String cpu = VM.getVM().getCPU();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
        access = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
        // FIXME: find the platform specific PD class by reflection?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
        if (os.equals("solaris")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
            if (cpu.equals("sparc")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
                access = new SolarisSPARCJavaThreadPDAccess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
            } else if (cpu.equals("x86")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
                access = new SolarisX86JavaThreadPDAccess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
            } else if (cpu.equals("amd64")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
                access = new SolarisAMD64JavaThreadPDAccess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        } else if (os.equals("win32")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
            if (cpu.equals("x86")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
                access =  new Win32X86JavaThreadPDAccess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
            } else if (cpu.equals("amd64")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
                access =  new Win32AMD64JavaThreadPDAccess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
        } else if (os.equals("linux")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
            if (cpu.equals("x86")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
                access = new LinuxX86JavaThreadPDAccess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
            } else if (cpu.equals("amd64")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
                access = new LinuxAMD64JavaThreadPDAccess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
            } else if (cpu.equals("sparc")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
                access = new LinuxSPARCJavaThreadPDAccess();
28369
a62a208f18de 8049716: PPC64: Implement SA on Linux/PPC64
simonis
parents: 27475
diff changeset
   120
            } else if (cpu.equals("ppc64")) {
a62a208f18de 8049716: PPC64: Implement SA on Linux/PPC64
simonis
parents: 27475
diff changeset
   121
                access = new LinuxPPC64JavaThreadPDAccess();
31399
167037a29ab4 8078521: AARCH64: Add AArch64 SA support
aph
parents: 28369
diff changeset
   122
            } else if (cpu.equals("aarch64")) {
167037a29ab4 8078521: AARCH64: Add AArch64 SA support
aph
parents: 28369
diff changeset
   123
                access = new LinuxAARCH64JavaThreadPDAccess();
13529
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   124
            } else {
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   125
              try {
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   126
                access = (JavaThreadPDAccess)
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   127
                  Class.forName("sun.jvm.hotspot.runtime.linux_" +
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   128
                     cpu.toLowerCase() + ".Linux" + cpu.toUpperCase() +
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   129
                     "JavaThreadPDAccess").newInstance();
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   130
              } catch (Exception e) {
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   131
                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
   132
                                           " not yet supported");
dc25e69fd16d 7154641: Servicability agent should work on platforms other than x86, sparc
bpittore
parents: 12728
diff changeset
   133
              }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
            }
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 8110
diff changeset
   135
        } else if (os.equals("bsd")) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 8110
diff changeset
   136
            if (cpu.equals("x86")) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 8110
diff changeset
   137
                access = new BsdX86JavaThreadPDAccess();
12728
a8abd64eaa1b 7163117: Agent can't connect to process on Mac OSX
nloodin
parents: 10565
diff changeset
   138
            } else if (cpu.equals("amd64") || cpu.equals("x86_64")) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 8110
diff changeset
   139
                access = new BsdAMD64JavaThreadPDAccess();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 8110
diff changeset
   140
            }
16351
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
   141
        } else if (os.equals("darwin")) {
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
   142
            if (cpu.equals("amd64") || cpu.equals("x86_64")) {
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
   143
                access = new BsdAMD64JavaThreadPDAccess();
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
   144
            }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
        if (access == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
            throw new RuntimeException("OS/CPU combination " + os + "/" + cpu +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
            " not yet supported");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
        virtualConstructor = new VirtualConstructor(db);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
        // Add mappings for all known thread types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
        virtualConstructor.addMapping("JavaThread", JavaThread.class);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
        if (!VM.getVM().isCore()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
            virtualConstructor.addMapping("CompilerThread", CompilerThread.class);
27475
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 16351
diff changeset
   157
            virtualConstructor.addMapping("CodeCacheSweeperThread", CodeCacheSweeperThread.class);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
        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
   160
        virtualConstructor.addMapping("ServiceThread", ServiceThread.class);
58503
726a3945e934 8170299: Debugger does not stop inside the low memory notifications code
dtitov
parents: 54955
diff changeset
   161
        virtualConstructor.addMapping("NotificationThread", NotificationThread.class);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    public Threads() {
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   165
        _list = VMObjectFactory.newObject(ThreadsList.class, threadListField.getValue());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    /** NOTE: this returns objects of type JavaThread, CompilerThread,
58503
726a3945e934 8170299: Debugger does not stop inside the low memory notifications code
dtitov
parents: 54955
diff changeset
   169
      JvmtiAgentThread, NotificationThread, and ServiceThread.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      The latter four are subclasses of the former. Most operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      (fetching the top frame, etc.) are only allowed to be performed on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      a "pure" JavaThread. For this reason, {@link
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      sun.jvm.hotspot.runtime.JavaThread#isJavaThread} has been
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      changed from the definition in the VM (which returns true for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      all of these thread types) to return true for JavaThreads and
58503
726a3945e934 8170299: Debugger does not stop inside the low memory notifications code
dtitov
parents: 54955
diff changeset
   176
      false for the four subclasses. FIXME: should reconsider the
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      inheritance hierarchy; see {@link
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      sun.jvm.hotspot.runtime.JavaThread#isJavaThread}. */
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   179
    public JavaThread getJavaThreadAt(int i) {
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   180
        if (i < _list.length()) {
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   181
            return createJavaThreadWrapper(_list.getJavaThreadAddressAt(i));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
        }
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   183
        return null;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
16351
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
   186
    public int getNumberOfThreads() {
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   187
        return (int) _list.length();
16351
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
   188
    }
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 13873
diff changeset
   189
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    /** Routine for instantiating appropriately-typed wrapper for a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      JavaThread. Currently needs to be public for OopUtilities to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      access it. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    public JavaThread createJavaThreadWrapper(Address threadAddr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
        try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
            JavaThread thread = (JavaThread)virtualConstructor.instantiateWrapperFor(threadAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
            thread.setThreadPDAccess(access);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
            return thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
        } catch (Exception e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
            throw new RuntimeException("Unable to deduce type of thread from address " + threadAddr +
40892
330a02d935ad 8156500: Move Reference pending list into VM to prevent deadlocks
kbarrett
parents: 37129
diff changeset
   200
            " (expected type JavaThread, CompilerThread, ServiceThread, JvmtiAgentThread or CodeCacheSweeperThread)", e);
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    /** Memory operations */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    public void oopsDo(AddressVisitor oopVisitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
        // FIXME: add more of VM functionality
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   207
        Threads threads = VM.getVM().getThreads();
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   208
        for (int i = 0; i < threads.getNumberOfThreads(); i++) {
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   209
            JavaThread thread = threads.getJavaThreadAt(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
            thread.oopsDo(oopVisitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    // refer to Threads::owning_thread_from_monitor_owner
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    public JavaThread owningThreadFromMonitor(Address o) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
        if (o == null) return null;
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   217
        for (int i = 0; i < getNumberOfThreads(); i++) {
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   218
            JavaThread thread = getJavaThreadAt(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
            if (o.equals(thread.threadObjectAddress())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
                return thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   224
        for (int i = 0; i < getNumberOfThreads(); i++) {
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   225
            JavaThread thread = getJavaThreadAt(i);
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   226
            if (thread.isLockOwned(o))
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   227
                return thread;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
        }
2526
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 1
diff changeset
   229
        return null;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    public JavaThread owningThreadFromMonitor(ObjectMonitor monitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
        return owningThreadFromMonitor(monitor.owner());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    // refer to Threads::get_pending_threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    // Get list of Java threads that are waiting to enter the specified monitor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    public List getPendingThreads(ObjectMonitor monitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
        List pendingThreads = new ArrayList();
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   240
        for (int i = 0; i < getNumberOfThreads(); i++) {
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   241
            JavaThread thread = getJavaThreadAt(i);
27475
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 16351
diff changeset
   242
            if (thread.isCompilerThread() || thread.isCodeCacheSweeperThread()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
                continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
            ObjectMonitor pending = thread.getCurrentPendingMonitor();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
            if (monitor.equals(pending)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
                pendingThreads.add(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
        return pendingThreads;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    // Get list of Java threads that have called Object.wait on the specified monitor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    public List getWaitingThreads(ObjectMonitor monitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
        List pendingThreads = new ArrayList();
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   256
        for (int i = 0; i < getNumberOfThreads(); i++) {
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   257
            JavaThread thread = getJavaThreadAt(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
            ObjectMonitor waiting = thread.getCurrentWaitingMonitor();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
            if (monitor.equals(waiting)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
                pendingThreads.add(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
        return pendingThreads;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    // FIXME: add other accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
}