src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/Thread.java
author lkorinth
Wed, 13 Nov 2019 11:37:29 +0100
changeset 59053 ba6c248cae19
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector Reviewed-by: kbarrett, tschatzl, erikj, coleenp, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
59053
ba6c248cae19 8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector
lkorinth
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.*;
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
public class Thread extends VMObject {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  private static long tlabFieldOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  private static CIntegerField suspendFlagsField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  // Thread::SuspendFlags enum constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  private static int EXTERNAL_SUSPEND;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  private static int EXT_SUSPENDED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  private static int HAS_ASYNC_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  private static AddressField activeHandlesField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  private static AddressField currentPendingMonitorField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  private static AddressField currentWaitingMonitorField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
25335
2557b9b45520 8046282: SA update
poonam
parents: 8110
diff changeset
    44
  private static JLongField allocatedBytesField;
2557b9b45520 8046282: SA update
poonam
parents: 8110
diff changeset
    45
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  private static synchronized void initialize(TypeDataBase db) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    Type type = db.lookupType("Thread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    suspendFlagsField = type.getCIntegerField("_suspend_flags");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    EXTERNAL_SUSPEND = db.lookupIntConstant("Thread::_external_suspend").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    EXT_SUSPENDED = db.lookupIntConstant("Thread::_ext_suspended").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    HAS_ASYNC_EXCEPTION = db.lookupIntConstant("Thread::_has_async_exception").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    tlabFieldOffset    = type.getField("_tlab").getOffset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    activeHandlesField = type.getAddressField("_active_handles");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    currentPendingMonitorField = type.getAddressField("_current_pending_monitor");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    currentWaitingMonitorField = type.getAddressField("_current_waiting_monitor");
25335
2557b9b45520 8046282: SA update
poonam
parents: 8110
diff changeset
    66
    allocatedBytesField = type.getJLongField("_allocated_bytes");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  public Thread(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    super(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  public int suspendFlags() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    return (int) suspendFlagsField.getValue(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  public boolean isExternalSuspend() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    return (suspendFlags() & EXTERNAL_SUSPEND) != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  public boolean isExtSuspended() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    return (suspendFlags() & EXT_SUSPENDED) != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  public boolean isBeingExtSuspended() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    return isExtSuspended() || isExternalSuspend();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // historical usage: checked for VM or external suspension
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  public boolean isAnySuspended() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    return isExtSuspended();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  public boolean hasAsyncException() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    return (suspendFlags() & HAS_ASYNC_EXCEPTION) != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  public ThreadLocalAllocBuffer tlab() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    return new ThreadLocalAllocBuffer(addr.addOffsetTo(tlabFieldOffset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  public JNIHandleBlock activeHandles() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    Address a = activeHandlesField.getAddress(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    if (a == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    return new JNIHandleBlock(a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
25335
2557b9b45520 8046282: SA update
poonam
parents: 8110
diff changeset
   110
  public long allocatedBytes() {
2557b9b45520 8046282: SA update
poonam
parents: 8110
diff changeset
   111
    return allocatedBytesField.getValue(addr);
2557b9b45520 8046282: SA update
poonam
parents: 8110
diff changeset
   112
  }
2557b9b45520 8046282: SA update
poonam
parents: 8110
diff changeset
   113
27475
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 25335
diff changeset
   114
  public boolean   isVMThread()                  { return false; }
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 25335
diff changeset
   115
  public boolean   isJavaThread()                { return false; }
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 25335
diff changeset
   116
  public boolean   isCompilerThread()            { return false; }
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 25335
diff changeset
   117
  public boolean   isCodeCacheSweeperThread()    { return false; }
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 25335
diff changeset
   118
  public boolean   isHiddenFromExternalView()    { return false; }
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 25335
diff changeset
   119
  public boolean   isJvmtiAgentThread()          { return false; }
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 25335
diff changeset
   120
  public boolean   isWatcherThread()             { return false; }
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 25335
diff changeset
   121
  public boolean   isServiceThread()             { return false; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  /** Memory operations */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  public void oopsDo(AddressVisitor oopVisitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    // FIXME: Empty for now; will later traverse JNI handles and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    // pending exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  public ObjectMonitor getCurrentPendingMonitor() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    Address monitorAddr = currentPendingMonitorField.getValue(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    if (monitorAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    return new ObjectMonitor(monitorAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  public ObjectMonitor getCurrentWaitingMonitor() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    Address monitorAddr = currentWaitingMonitorField.getValue(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    if (monitorAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    return new ObjectMonitor(monitorAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  public boolean isLockOwned(Address lock) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    if (isInStack(lock)) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  public boolean isInStack(Address a) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    // In the Serviceability Agent we need access to the thread's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    // stack pointer to be able to answer this question. Since it is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    // only a debugging system at the moment we need access to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    // underlying thread, which is only present for Java threads; see
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    // JavaThread.java.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  /** Assistance for ObjectMonitor implementation */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  Address threadObjectAddress() { return addr; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
}