112 access = new BsdAMD64JavaThreadPDAccess();
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
|
112 access = new BsdAMD64JavaThreadPDAccess();
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 virtualConstructor.addMapping("JvmtiAgentThread", JvmtiAgentThread.class);
133 virtualConstructor.addMapping("ServiceThread", ServiceThread.class);
134 }
135
136 public Threads() {
137 }
138
139 /** NOTE: this returns objects of type JavaThread, CompilerThread,
140 JvmtiAgentThread, and ServiceThread.
141 The latter four are subclasses of the former. Most operations
142 (fetching the top frame, etc.) are only allowed to be performed on
143 a "pure" JavaThread. For this reason, {@link
144 sun.jvm.hotspot.runtime.JavaThread#isJavaThread} has been
145 changed from the definition in the VM (which returns true for
146 all of these thread types) to return true for JavaThreads and
147 false for the three subclasses. FIXME: should reconsider the
148 inheritance hierarchy; see {@link
149 sun.jvm.hotspot.runtime.JavaThread#isJavaThread}. */
150 public JavaThread first() {
151 Address threadAddr = threadListField.getValue();
153 return null;
154 }
155
156 return createJavaThreadWrapper(threadAddr);
157 }
158
159 public int getNumberOfThreads() {
160 return (int) numOfThreadsField.getValue();
161 }
162
163 /** Routine for instantiating appropriately-typed wrapper for a
164 JavaThread. Currently needs to be public for OopUtilities to
165 access it. */
166 public JavaThread createJavaThreadWrapper(Address threadAddr) {
167 try {
168 JavaThread thread = (JavaThread)virtualConstructor.instantiateWrapperFor(threadAddr);
169 thread.setThreadPDAccess(access);
170 return thread;
171 } catch (Exception e) {
172 throw new RuntimeException("Unable to deduce type of thread from address " + threadAddr +
173 " (expected type JavaThread, CompilerThread, ServiceThread, JvmtiAgentThread or CodeCacheSweeperThread)", e);
174 }
175 }
176
177 /** Memory operations */
178 public void oopsDo(AddressVisitor oopVisitor) {
179 // FIXME: add more of VM functionality
180 for (JavaThread thread = first(); thread != null; thread = thread.next()) {
181 thread.oopsDo(oopVisitor);
182 }
183 }
184
185 // refer to Threads::owning_thread_from_monitor_owner
186 public JavaThread owningThreadFromMonitor(Address o) {
187 if (o == null) return null;
188 for (JavaThread thread = first(); thread != null; thread = thread.next()) {
189 if (o.equals(thread.threadObjectAddress())) {
190 return thread;
191 }
192 }
193
|