annotate agent/src/share/classes/sun/jvm/hotspot/runtime/Thread.java @ 2195:bf8517f4e4d0

6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread" Summary: Defer posting events from the compiler thread: use service thread Reviewed-by: coleenp, dholmes, never, dcubed
author kamg
date Wed, 02 Feb 2011 14:38:01 -0500
parents c18cbe5936b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 1552
diff changeset
2 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 844
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 844
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 844
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.runtime;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 public class Thread extends VMObject {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 private static long tlabFieldOffset;
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 private static CIntegerField suspendFlagsField;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // Thread::SuspendFlags enum constants
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private static int EXTERNAL_SUSPEND;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private static int EXT_SUSPENDED;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private static int HAS_ASYNC_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private static AddressField activeHandlesField;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private static AddressField currentPendingMonitorField;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private static AddressField currentWaitingMonitorField;
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
45 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49 });
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 private static synchronized void initialize(TypeDataBase db) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 Type type = db.lookupType("Thread");
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 suspendFlagsField = type.getCIntegerField("_suspend_flags");
a61af66fc99e Initial load
duke
parents:
diff changeset
56 EXTERNAL_SUSPEND = db.lookupIntConstant("Thread::_external_suspend").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
57 EXT_SUSPENDED = db.lookupIntConstant("Thread::_ext_suspended").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
58 HAS_ASYNC_EXCEPTION = db.lookupIntConstant("Thread::_has_async_exception").intValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 tlabFieldOffset = type.getField("_tlab").getOffset();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 activeHandlesField = type.getAddressField("_active_handles");
a61af66fc99e Initial load
duke
parents:
diff changeset
62 currentPendingMonitorField = type.getAddressField("_current_pending_monitor");
a61af66fc99e Initial load
duke
parents:
diff changeset
63 currentWaitingMonitorField = type.getAddressField("_current_waiting_monitor");
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 public Thread(Address addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 super(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 public int suspendFlags() {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 return (int) suspendFlagsField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 public boolean isExternalSuspend() {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 return (suspendFlags() & EXTERNAL_SUSPEND) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 public boolean isExtSuspended() {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 return (suspendFlags() & EXT_SUSPENDED) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 public boolean isBeingExtSuspended() {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 return isExtSuspended() || isExternalSuspend();
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // historical usage: checked for VM or external suspension
a61af66fc99e Initial load
duke
parents:
diff changeset
87 public boolean isAnySuspended() {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 return isExtSuspended();
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 public boolean hasAsyncException() {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return (suspendFlags() & HAS_ASYNC_EXCEPTION) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 public ThreadLocalAllocBuffer tlab() {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return new ThreadLocalAllocBuffer(addr.addOffsetTo(tlabFieldOffset));
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 public JNIHandleBlock activeHandles() {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 Address a = activeHandlesField.getAddress(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (a == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 return new JNIHandleBlock(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 public boolean isVMThread() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 public boolean isJavaThread() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 public boolean isCompilerThread() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 public boolean isHiddenFromExternalView() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 public boolean isJvmtiAgentThread() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
112 public boolean isWatcherThread() { return false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 public boolean isConcurrentMarkSweepThread() { return false; }
2195
bf8517f4e4d0 6766644: Redefinition of compiled method fails with assertion "Can not load classes with the Compiler thread"
kamg
parents: 1552
diff changeset
114 public boolean isServiceThread() { return false; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 /** Memory operations */
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public void oopsDo(AddressVisitor oopVisitor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // FIXME: Empty for now; will later traverse JNI handles and
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // pending exception
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 public ObjectMonitor getCurrentPendingMonitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 Address monitorAddr = currentPendingMonitorField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
124 if (monitorAddr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return new ObjectMonitor(monitorAddr);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 public ObjectMonitor getCurrentWaitingMonitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 Address monitorAddr = currentWaitingMonitorField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 if (monitorAddr == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return new ObjectMonitor(monitorAddr);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 public boolean isLockOwned(Address lock) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if (isInStack(lock)) return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 public boolean isInStack(Address a) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // In the Serviceability Agent we need access to the thread's
a61af66fc99e Initial load
duke
parents:
diff changeset
145 // stack pointer to be able to answer this question. Since it is
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // only a debugging system at the moment we need access to the
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // underlying thread, which is only present for Java threads; see
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // JavaThread.java.
a61af66fc99e Initial load
duke
parents:
diff changeset
149 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 /** Assistance for ObjectMonitor implementation */
a61af66fc99e Initial load
duke
parents:
diff changeset
153 Address threadObjectAddress() { return addr; }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }