1 /*
2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
113 }
114 } else if (os.equals("darwin")) {
115 if (cpu.equals("amd64") || cpu.equals("x86_64")) {
116 access = new BsdAMD64JavaThreadPDAccess();
117 }
118 }
119
120 if (access == null) {
121 throw new RuntimeException("OS/CPU combination " + os + "/" + cpu +
122 " not yet supported");
123 }
124
125 virtualConstructor = new VirtualConstructor(db);
126 // Add mappings for all known thread types
127 virtualConstructor.addMapping("JavaThread", JavaThread.class);
128 if (!VM.getVM().isCore()) {
129 virtualConstructor.addMapping("CompilerThread", CompilerThread.class);
130 virtualConstructor.addMapping("CodeCacheSweeperThread", CodeCacheSweeperThread.class);
131 }
132 // for now, use JavaThread itself. fix it later with appropriate class if needed
133 virtualConstructor.addMapping("SurrogateLockerThread", JavaThread.class);
134 virtualConstructor.addMapping("JvmtiAgentThread", JvmtiAgentThread.class);
135 virtualConstructor.addMapping("ServiceThread", ServiceThread.class);
136 }
137
138 public Threads() {
139 }
140
141 /** NOTE: this returns objects of type JavaThread, CompilerThread,
142 JvmtiAgentThread, and ServiceThread.
143 The latter four are subclasses of the former. Most operations
144 (fetching the top frame, etc.) are only allowed to be performed on
145 a "pure" JavaThread. For this reason, {@link
146 sun.jvm.hotspot.runtime.JavaThread#isJavaThread} has been
147 changed from the definition in the VM (which returns true for
148 all of these thread types) to return true for JavaThreads and
149 false for the three subclasses. FIXME: should reconsider the
150 inheritance hierarchy; see {@link
151 sun.jvm.hotspot.runtime.JavaThread#isJavaThread}. */
152 public JavaThread first() {
153 Address threadAddr = threadListField.getValue();
155 return null;
156 }
157
158 return createJavaThreadWrapper(threadAddr);
159 }
160
161 public int getNumberOfThreads() {
162 return (int) numOfThreadsField.getValue();
163 }
164
165 /** Routine for instantiating appropriately-typed wrapper for a
166 JavaThread. Currently needs to be public for OopUtilities to
167 access it. */
168 public JavaThread createJavaThreadWrapper(Address threadAddr) {
169 try {
170 JavaThread thread = (JavaThread)virtualConstructor.instantiateWrapperFor(threadAddr);
171 thread.setThreadPDAccess(access);
172 return thread;
173 } catch (Exception e) {
174 throw new RuntimeException("Unable to deduce type of thread from address " + threadAddr +
175 " (expected type JavaThread, CompilerThread, ServiceThread, JvmtiAgentThread, SurrogateLockerThread, or CodeCacheSweeperThread)", e);
176 }
177 }
178
179 /** Memory operations */
180 public void oopsDo(AddressVisitor oopVisitor) {
181 // FIXME: add more of VM functionality
182 for (JavaThread thread = first(); thread != null; thread = thread.next()) {
183 thread.oopsDo(oopVisitor);
184 }
185 }
186
187 // refer to Threads::owning_thread_from_monitor_owner
188 public JavaThread owningThreadFromMonitor(Address o) {
189 if (o == null) return null;
190 for (JavaThread thread = first(); thread != null; thread = thread.next()) {
191 if (o.equals(thread.threadObjectAddress())) {
192 return thread;
193 }
194 }
195
|
1 /*
2 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
113 }
114 } else if (os.equals("darwin")) {
115 if (cpu.equals("amd64") || cpu.equals("x86_64")) {
116 access = new BsdAMD64JavaThreadPDAccess();
117 }
118 }
119
120 if (access == null) {
121 throw new RuntimeException("OS/CPU combination " + os + "/" + cpu +
122 " not yet supported");
123 }
124
125 virtualConstructor = new VirtualConstructor(db);
126 // Add mappings for all known thread types
127 virtualConstructor.addMapping("JavaThread", JavaThread.class);
128 if (!VM.getVM().isCore()) {
129 virtualConstructor.addMapping("CompilerThread", CompilerThread.class);
130 virtualConstructor.addMapping("CodeCacheSweeperThread", CodeCacheSweeperThread.class);
131 }
132 // for now, use JavaThread itself. fix it later with appropriate class if needed
133 virtualConstructor.addMapping("ReferencePendingListLockerThread", JavaThread.class);
134 virtualConstructor.addMapping("JvmtiAgentThread", JvmtiAgentThread.class);
135 virtualConstructor.addMapping("ServiceThread", ServiceThread.class);
136 }
137
138 public Threads() {
139 }
140
141 /** NOTE: this returns objects of type JavaThread, CompilerThread,
142 JvmtiAgentThread, and ServiceThread.
143 The latter four are subclasses of the former. Most operations
144 (fetching the top frame, etc.) are only allowed to be performed on
145 a "pure" JavaThread. For this reason, {@link
146 sun.jvm.hotspot.runtime.JavaThread#isJavaThread} has been
147 changed from the definition in the VM (which returns true for
148 all of these thread types) to return true for JavaThreads and
149 false for the three subclasses. FIXME: should reconsider the
150 inheritance hierarchy; see {@link
151 sun.jvm.hotspot.runtime.JavaThread#isJavaThread}. */
152 public JavaThread first() {
153 Address threadAddr = threadListField.getValue();
155 return null;
156 }
157
158 return createJavaThreadWrapper(threadAddr);
159 }
160
161 public int getNumberOfThreads() {
162 return (int) numOfThreadsField.getValue();
163 }
164
165 /** Routine for instantiating appropriately-typed wrapper for a
166 JavaThread. Currently needs to be public for OopUtilities to
167 access it. */
168 public JavaThread createJavaThreadWrapper(Address threadAddr) {
169 try {
170 JavaThread thread = (JavaThread)virtualConstructor.instantiateWrapperFor(threadAddr);
171 thread.setThreadPDAccess(access);
172 return thread;
173 } catch (Exception e) {
174 throw new RuntimeException("Unable to deduce type of thread from address " + threadAddr +
175 " (expected type JavaThread, CompilerThread, ServiceThread, JvmtiAgentThread, ReferencePendingListLockerThread, or CodeCacheSweeperThread)", e);
176 }
177 }
178
179 /** Memory operations */
180 public void oopsDo(AddressVisitor oopVisitor) {
181 // FIXME: add more of VM functionality
182 for (JavaThread thread = first(); thread != null; thread = thread.next()) {
183 thread.oopsDo(oopVisitor);
184 }
185 }
186
187 // refer to Threads::owning_thread_from_monitor_owner
188 public JavaThread owningThreadFromMonitor(Address o) {
189 if (o == null) return null;
190 for (JavaThread thread = first(); thread != null; thread = thread.next()) {
191 if (o.equals(thread.threadObjectAddress())) {
192 return thread;
193 }
194 }
195
|