Mercurial > hg > truffle
annotate src/share/vm/prims/jvmtiEnv.cpp @ 1120:9127aa69352e
6648438: 4/4 src/share/vm/prims/jvmtiEnv.cpp:457 assert(phase == JVMTI_PHASE_LIVE,"sanity check")
Summary: Return error on invalid JVMTI_PHASE instead of asserting.
Reviewed-by: dholmes, ohair
author | dcubed |
---|---|
date | Mon, 14 Dec 2009 09:51:09 -0700 |
parents | a61af66fc99e |
children | 98cd9901c161 |
rev | line source |
---|---|
0 | 1 /* |
1120
9127aa69352e
6648438: 4/4 src/share/vm/prims/jvmtiEnv.cpp:457 assert(phase == JVMTI_PHASE_LIVE,"sanity check")
dcubed
parents:
0
diff
changeset
|
2 * Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved. |
0 | 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 | |
26 # include "incls/_precompiled.incl" | |
27 # include "incls/_jvmtiEnv.cpp.incl" | |
28 | |
29 | |
30 #define FIXLATER 0 // REMOVE this when completed. | |
31 | |
32 // FIXLATER: hook into JvmtiTrace | |
33 #define TraceJVMTICalls false | |
34 | |
35 JvmtiEnv::JvmtiEnv() : JvmtiEnvBase() { | |
36 } | |
37 | |
38 JvmtiEnv::~JvmtiEnv() { | |
39 } | |
40 | |
41 JvmtiEnv* | |
42 JvmtiEnv::create_a_jvmti() { | |
43 return new JvmtiEnv(); | |
44 } | |
45 | |
46 // VM operation class to copy jni function table at safepoint. | |
47 // More than one java threads or jvmti agents may be reading/ | |
48 // modifying jni function tables. To reduce the risk of bad | |
49 // interaction b/w these threads it is copied at safepoint. | |
50 class VM_JNIFunctionTableCopier : public VM_Operation { | |
51 private: | |
52 const struct JNINativeInterface_ *_function_table; | |
53 public: | |
54 VM_JNIFunctionTableCopier(const struct JNINativeInterface_ *func_tbl) { | |
55 _function_table = func_tbl; | |
56 }; | |
57 | |
58 VMOp_Type type() const { return VMOp_JNIFunctionTableCopier; } | |
59 void doit() { | |
60 copy_jni_function_table(_function_table); | |
61 }; | |
62 }; | |
63 | |
64 // | |
65 // Do not change the "prefix" marker below, everything above it is copied | |
66 // unchanged into the filled stub, everything below is controlled by the | |
67 // stub filler (only method bodies are carried forward, and then only for | |
68 // functionality still in the spec). | |
69 // | |
70 // end file prefix | |
71 | |
72 // | |
73 // Memory Management functions | |
74 // | |
75 | |
76 // mem_ptr - pre-checked for NULL | |
77 jvmtiError | |
78 JvmtiEnv::Allocate(jlong size, unsigned char** mem_ptr) { | |
79 return allocate(size, mem_ptr); | |
80 } /* end Allocate */ | |
81 | |
82 | |
83 // mem - NULL is a valid value, must be checked | |
84 jvmtiError | |
85 JvmtiEnv::Deallocate(unsigned char* mem) { | |
86 return deallocate(mem); | |
87 } /* end Deallocate */ | |
88 | |
89 // Threads_lock NOT held, java_thread not protected by lock | |
90 // java_thread - pre-checked | |
91 // data - NULL is a valid value, must be checked | |
92 jvmtiError | |
93 JvmtiEnv::SetThreadLocalStorage(JavaThread* java_thread, const void* data) { | |
94 JvmtiThreadState* state = java_thread->jvmti_thread_state(); | |
95 if (state == NULL) { | |
96 if (data == NULL) { | |
97 // leaving state unset same as data set to NULL | |
98 return JVMTI_ERROR_NONE; | |
99 } | |
100 // otherwise, create the state | |
101 state = JvmtiThreadState::state_for(java_thread); | |
102 } | |
103 state->env_thread_state(this)->set_agent_thread_local_storage_data((void*)data); | |
104 return JVMTI_ERROR_NONE; | |
105 } /* end SetThreadLocalStorage */ | |
106 | |
107 | |
108 // Threads_lock NOT held | |
109 // thread - NOT pre-checked | |
110 // data_ptr - pre-checked for NULL | |
111 jvmtiError | |
112 JvmtiEnv::GetThreadLocalStorage(jthread thread, void** data_ptr) { | |
113 JavaThread* current_thread = JavaThread::current(); | |
114 if (thread == NULL) { | |
115 JvmtiThreadState* state = current_thread->jvmti_thread_state(); | |
116 *data_ptr = (state == NULL) ? NULL : | |
117 state->env_thread_state(this)->get_agent_thread_local_storage_data(); | |
118 } else { | |
119 | |
120 // jvmti_GetThreadLocalStorage is "in native" and doesn't transition | |
121 // the thread to _thread_in_vm. However, when the TLS for a thread | |
122 // other than the current thread is required we need to transition | |
123 // from native so as to resolve the jthread. | |
124 | |
125 ThreadInVMfromNative __tiv(current_thread); | |
126 __ENTRY(jvmtiError, JvmtiEnv::GetThreadLocalStorage , current_thread) | |
127 debug_only(VMNativeEntryWrapper __vew;) | |
128 | |
129 oop thread_oop = JNIHandles::resolve_external_guard(thread); | |
130 if (thread_oop == NULL) { | |
131 return JVMTI_ERROR_INVALID_THREAD; | |
132 } | |
133 if (!thread_oop->is_a(SystemDictionary::thread_klass())) { | |
134 return JVMTI_ERROR_INVALID_THREAD; | |
135 } | |
136 JavaThread* java_thread = java_lang_Thread::thread(thread_oop); | |
137 if (java_thread == NULL) { | |
138 return JVMTI_ERROR_THREAD_NOT_ALIVE; | |
139 } | |
140 JvmtiThreadState* state = java_thread->jvmti_thread_state(); | |
141 *data_ptr = (state == NULL) ? NULL : | |
142 state->env_thread_state(this)->get_agent_thread_local_storage_data(); | |
143 } | |
144 return JVMTI_ERROR_NONE; | |
145 } /* end GetThreadLocalStorage */ | |
146 | |
147 // | |
148 // Class functions | |
149 // | |
150 | |
151 // class_count_ptr - pre-checked for NULL | |
152 // classes_ptr - pre-checked for NULL | |
153 jvmtiError | |
154 JvmtiEnv::GetLoadedClasses(jint* class_count_ptr, jclass** classes_ptr) { | |
155 return JvmtiGetLoadedClasses::getLoadedClasses(this, class_count_ptr, classes_ptr); | |
156 } /* end GetLoadedClasses */ | |
157 | |
158 | |
159 // initiating_loader - NULL is a valid value, must be checked | |
160 // class_count_ptr - pre-checked for NULL | |
161 // classes_ptr - pre-checked for NULL | |
162 jvmtiError | |
163 JvmtiEnv::GetClassLoaderClasses(jobject initiating_loader, jint* class_count_ptr, jclass** classes_ptr) { | |
164 return JvmtiGetLoadedClasses::getClassLoaderClasses(this, initiating_loader, | |
165 class_count_ptr, classes_ptr); | |
166 } /* end GetClassLoaderClasses */ | |
167 | |
168 // k_mirror - may be primitive, this must be checked | |
169 // is_modifiable_class_ptr - pre-checked for NULL | |
170 jvmtiError | |
171 JvmtiEnv::IsModifiableClass(oop k_mirror, jboolean* is_modifiable_class_ptr) { | |
172 *is_modifiable_class_ptr = VM_RedefineClasses::is_modifiable_class(k_mirror)? | |
173 JNI_TRUE : JNI_FALSE; | |
174 return JVMTI_ERROR_NONE; | |
175 } /* end IsModifiableClass */ | |
176 | |
177 // class_count - pre-checked to be greater than or equal to 0 | |
178 // classes - pre-checked for NULL | |
179 jvmtiError | |
180 JvmtiEnv::RetransformClasses(jint class_count, const jclass* classes) { | |
181 //TODO: add locking | |
182 | |
183 int index; | |
184 JavaThread* current_thread = JavaThread::current(); | |
185 ResourceMark rm(current_thread); | |
186 | |
187 jvmtiClassDefinition* class_definitions = | |
188 NEW_RESOURCE_ARRAY(jvmtiClassDefinition, class_count); | |
189 NULL_CHECK(class_definitions, JVMTI_ERROR_OUT_OF_MEMORY); | |
190 | |
191 for (index = 0; index < class_count; index++) { | |
192 HandleMark hm(current_thread); | |
193 | |
194 jclass jcls = classes[index]; | |
195 oop k_mirror = JNIHandles::resolve_external_guard(jcls); | |
196 if (k_mirror == NULL) { | |
197 return JVMTI_ERROR_INVALID_CLASS; | |
198 } | |
199 if (!k_mirror->is_a(SystemDictionary::class_klass())) { | |
200 return JVMTI_ERROR_INVALID_CLASS; | |
201 } | |
202 | |
203 if (java_lang_Class::is_primitive(k_mirror)) { | |
204 return JVMTI_ERROR_UNMODIFIABLE_CLASS; | |
205 } | |
206 | |
207 klassOop k_oop = java_lang_Class::as_klassOop(k_mirror); | |
208 KlassHandle klass(current_thread, k_oop); | |
209 | |
210 jint status = klass->jvmti_class_status(); | |
211 if (status & (JVMTI_CLASS_STATUS_ERROR)) { | |
212 return JVMTI_ERROR_INVALID_CLASS; | |
213 } | |
214 if (status & (JVMTI_CLASS_STATUS_ARRAY)) { | |
215 return JVMTI_ERROR_UNMODIFIABLE_CLASS; | |
216 } | |
217 | |
218 instanceKlassHandle ikh(current_thread, k_oop); | |
219 if (ikh->get_cached_class_file_bytes() == NULL) { | |
220 // not cached, we need to reconstitute the class file from VM representation | |
221 constantPoolHandle constants(current_thread, ikh->constants()); | |
222 ObjectLocker ol(constants, current_thread); // lock constant pool while we query it | |
223 | |
224 JvmtiClassFileReconstituter reconstituter(ikh); | |
225 if (reconstituter.get_error() != JVMTI_ERROR_NONE) { | |
226 return reconstituter.get_error(); | |
227 } | |
228 | |
229 class_definitions[index].class_byte_count = (jint)reconstituter.class_file_size(); | |
230 class_definitions[index].class_bytes = (unsigned char*) | |
231 reconstituter.class_file_bytes(); | |
232 } else { | |
233 // it is cached, get it from the cache | |
234 class_definitions[index].class_byte_count = ikh->get_cached_class_file_len(); | |
235 class_definitions[index].class_bytes = ikh->get_cached_class_file_bytes(); | |
236 } | |
237 class_definitions[index].klass = jcls; | |
238 } | |
239 VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform); | |
240 VMThread::execute(&op); | |
241 return (op.check_error()); | |
242 } /* end RetransformClasses */ | |
243 | |
244 | |
245 // class_count - pre-checked to be greater than or equal to 0 | |
246 // class_definitions - pre-checked for NULL | |
247 jvmtiError | |
248 JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) { | |
249 //TODO: add locking | |
250 VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine); | |
251 VMThread::execute(&op); | |
252 return (op.check_error()); | |
253 } /* end RedefineClasses */ | |
254 | |
255 | |
256 // | |
257 // Object functions | |
258 // | |
259 | |
260 // size_ptr - pre-checked for NULL | |
261 jvmtiError | |
262 JvmtiEnv::GetObjectSize(jobject object, jlong* size_ptr) { | |
263 oop mirror = JNIHandles::resolve_external_guard(object); | |
264 NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT); | |
265 | |
266 if (mirror->klass() == SystemDictionary::class_klass()) { | |
267 if (!java_lang_Class::is_primitive(mirror)) { | |
268 mirror = java_lang_Class::as_klassOop(mirror); | |
269 assert(mirror != NULL, "class for non-primitive mirror must exist"); | |
270 } | |
271 } | |
272 | |
273 *size_ptr = mirror->size() * wordSize; | |
274 return JVMTI_ERROR_NONE; | |
275 } /* end GetObjectSize */ | |
276 | |
277 // | |
278 // Method functions | |
279 // | |
280 | |
281 // prefix - NULL is a valid value, must be checked | |
282 jvmtiError | |
283 JvmtiEnv::SetNativeMethodPrefix(const char* prefix) { | |
284 return prefix == NULL? | |
285 SetNativeMethodPrefixes(0, NULL) : | |
286 SetNativeMethodPrefixes(1, (char**)&prefix); | |
287 } /* end SetNativeMethodPrefix */ | |
288 | |
289 | |
290 // prefix_count - pre-checked to be greater than or equal to 0 | |
291 // prefixes - pre-checked for NULL | |
292 jvmtiError | |
293 JvmtiEnv::SetNativeMethodPrefixes(jint prefix_count, char** prefixes) { | |
294 // Have to grab JVMTI thread state lock to be sure that some thread | |
295 // isn't accessing the prefixes at the same time we are setting them. | |
296 // No locks during VM bring-up. | |
297 if (Threads::number_of_threads() == 0) { | |
298 return set_native_method_prefixes(prefix_count, prefixes); | |
299 } else { | |
300 MutexLocker mu(JvmtiThreadState_lock); | |
301 return set_native_method_prefixes(prefix_count, prefixes); | |
302 } | |
303 } /* end SetNativeMethodPrefixes */ | |
304 | |
305 // | |
306 // Event Management functions | |
307 // | |
308 | |
309 // callbacks - NULL is a valid value, must be checked | |
310 // size_of_callbacks - pre-checked to be greater than or equal to 0 | |
311 jvmtiError | |
312 JvmtiEnv::SetEventCallbacks(const jvmtiEventCallbacks* callbacks, jint size_of_callbacks) { | |
313 JvmtiEventController::set_event_callbacks(this, callbacks, size_of_callbacks); | |
314 return JVMTI_ERROR_NONE; | |
315 } /* end SetEventCallbacks */ | |
316 | |
317 | |
318 // event_thread - NULL is a valid value, must be checked | |
319 jvmtiError | |
320 JvmtiEnv::SetEventNotificationMode(jvmtiEventMode mode, jvmtiEvent event_type, jthread event_thread, ...) { | |
321 JavaThread* java_thread = NULL; | |
322 if (event_thread != NULL) { | |
323 oop thread_oop = JNIHandles::resolve_external_guard(event_thread); | |
324 if (thread_oop == NULL) { | |
325 return JVMTI_ERROR_INVALID_THREAD; | |
326 } | |
327 if (!thread_oop->is_a(SystemDictionary::thread_klass())) { | |
328 return JVMTI_ERROR_INVALID_THREAD; | |
329 } | |
330 java_thread = java_lang_Thread::thread(thread_oop); | |
331 if (java_thread == NULL) { | |
332 return JVMTI_ERROR_THREAD_NOT_ALIVE; | |
333 } | |
334 } | |
335 | |
336 // event_type must be valid | |
337 if (!JvmtiEventController::is_valid_event_type(event_type)) { | |
338 return JVMTI_ERROR_INVALID_EVENT_TYPE; | |
339 } | |
340 | |
341 // global events cannot be controlled at thread level. | |
342 if (java_thread != NULL && JvmtiEventController::is_global_event(event_type)) { | |
343 return JVMTI_ERROR_ILLEGAL_ARGUMENT; | |
344 } | |
345 | |
346 bool enabled = (mode == JVMTI_ENABLE); | |
347 | |
348 // assure that needed capabilities are present | |
349 if (enabled && !JvmtiUtil::has_event_capability(event_type, get_capabilities())) { | |
350 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY; | |
351 } | |
352 | |
353 if (event_type == JVMTI_EVENT_CLASS_FILE_LOAD_HOOK && enabled) { | |
354 record_class_file_load_hook_enabled(); | |
355 } | |
356 JvmtiEventController::set_user_enabled(this, java_thread, event_type, enabled); | |
357 | |
358 return JVMTI_ERROR_NONE; | |
359 } /* end SetEventNotificationMode */ | |
360 | |
361 // | |
362 // Capability functions | |
363 // | |
364 | |
365 // capabilities_ptr - pre-checked for NULL | |
366 jvmtiError | |
367 JvmtiEnv::GetPotentialCapabilities(jvmtiCapabilities* capabilities_ptr) { | |
368 JvmtiManageCapabilities::get_potential_capabilities(get_capabilities(), | |
369 get_prohibited_capabilities(), | |
370 capabilities_ptr); | |
371 return JVMTI_ERROR_NONE; | |
372 } /* end GetPotentialCapabilities */ | |
373 | |
374 | |
375 // capabilities_ptr - pre-checked for NULL | |
376 jvmtiError | |
377 JvmtiEnv::AddCapabilities(const jvmtiCapabilities* capabilities_ptr) { | |
378 return JvmtiManageCapabilities::add_capabilities(get_capabilities(), | |
379 get_prohibited_capabilities(), | |
380 capabilities_ptr, | |
381 get_capabilities()); | |
382 } /* end AddCapabilities */ | |
383 | |
384 | |
385 // capabilities_ptr - pre-checked for NULL | |
386 jvmtiError | |
387 JvmtiEnv::RelinquishCapabilities(const jvmtiCapabilities* capabilities_ptr) { | |
388 JvmtiManageCapabilities::relinquish_capabilities(get_capabilities(), capabilities_ptr, get_capabilities()); | |
389 return JVMTI_ERROR_NONE; | |
390 } /* end RelinquishCapabilities */ | |
391 | |
392 | |
393 // capabilities_ptr - pre-checked for NULL | |
394 jvmtiError | |
395 JvmtiEnv::GetCapabilities(jvmtiCapabilities* capabilities_ptr) { | |
396 JvmtiManageCapabilities::copy_capabilities(get_capabilities(), capabilities_ptr); | |
397 return JVMTI_ERROR_NONE; | |
398 } /* end GetCapabilities */ | |
399 | |
400 // | |
401 // Class Loader Search functions | |
402 // | |
403 | |
404 // segment - pre-checked for NULL | |
405 jvmtiError | |
406 JvmtiEnv::AddToBootstrapClassLoaderSearch(const char* segment) { | |
407 jvmtiPhase phase = get_phase(); | |
408 if (phase == JVMTI_PHASE_ONLOAD) { | |
409 Arguments::append_sysclasspath(segment); | |
410 return JVMTI_ERROR_NONE; | |
1120
9127aa69352e
6648438: 4/4 src/share/vm/prims/jvmtiEnv.cpp:457 assert(phase == JVMTI_PHASE_LIVE,"sanity check")
dcubed
parents:
0
diff
changeset
|
411 } else if (phase == JVMTI_PHASE_LIVE) { |
9127aa69352e
6648438: 4/4 src/share/vm/prims/jvmtiEnv.cpp:457 assert(phase == JVMTI_PHASE_LIVE,"sanity check")
dcubed
parents:
0
diff
changeset
|
412 // The phase is checked by the wrapper that called this function, |
9127aa69352e
6648438: 4/4 src/share/vm/prims/jvmtiEnv.cpp:457 assert(phase == JVMTI_PHASE_LIVE,"sanity check")
dcubed
parents:
0
diff
changeset
|
413 // but this thread could be racing with the thread that is |
9127aa69352e
6648438: 4/4 src/share/vm/prims/jvmtiEnv.cpp:457 assert(phase == JVMTI_PHASE_LIVE,"sanity check")
dcubed
parents:
0
diff
changeset
|
414 // terminating the VM so we check one more time. |
0 | 415 |
416 // create the zip entry | |
417 ClassPathZipEntry* zip_entry = ClassLoader::create_class_path_zip_entry(segment); | |
418 if (zip_entry == NULL) { | |
419 return JVMTI_ERROR_ILLEGAL_ARGUMENT; | |
420 } | |
421 | |
422 // lock the loader | |
423 Thread* thread = Thread::current(); | |
424 HandleMark hm; | |
425 Handle loader_lock = Handle(thread, SystemDictionary::system_loader_lock()); | |
426 | |
427 ObjectLocker ol(loader_lock, thread); | |
428 | |
429 // add the jar file to the bootclasspath | |
430 if (TraceClassLoading) { | |
431 tty->print_cr("[Opened %s]", zip_entry->name()); | |
432 } | |
433 ClassLoader::add_to_list(zip_entry); | |
434 return JVMTI_ERROR_NONE; | |
1120
9127aa69352e
6648438: 4/4 src/share/vm/prims/jvmtiEnv.cpp:457 assert(phase == JVMTI_PHASE_LIVE,"sanity check")
dcubed
parents:
0
diff
changeset
|
435 } else { |
9127aa69352e
6648438: 4/4 src/share/vm/prims/jvmtiEnv.cpp:457 assert(phase == JVMTI_PHASE_LIVE,"sanity check")
dcubed
parents:
0
diff
changeset
|
436 return JVMTI_ERROR_WRONG_PHASE; |
0 | 437 } |
438 | |
439 } /* end AddToBootstrapClassLoaderSearch */ | |
440 | |
441 | |
442 // segment - pre-checked for NULL | |
443 jvmtiError | |
444 JvmtiEnv::AddToSystemClassLoaderSearch(const char* segment) { | |
445 jvmtiPhase phase = get_phase(); | |
446 | |
447 if (phase == JVMTI_PHASE_ONLOAD) { | |
448 for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) { | |
449 if (strcmp("java.class.path", p->key()) == 0) { | |
450 p->append_value(segment); | |
451 break; | |
452 } | |
453 } | |
454 return JVMTI_ERROR_NONE; | |
1120
9127aa69352e
6648438: 4/4 src/share/vm/prims/jvmtiEnv.cpp:457 assert(phase == JVMTI_PHASE_LIVE,"sanity check")
dcubed
parents:
0
diff
changeset
|
455 } else if (phase == JVMTI_PHASE_LIVE) { |
9127aa69352e
6648438: 4/4 src/share/vm/prims/jvmtiEnv.cpp:457 assert(phase == JVMTI_PHASE_LIVE,"sanity check")
dcubed
parents:
0
diff
changeset
|
456 // The phase is checked by the wrapper that called this function, |
9127aa69352e
6648438: 4/4 src/share/vm/prims/jvmtiEnv.cpp:457 assert(phase == JVMTI_PHASE_LIVE,"sanity check")
dcubed
parents:
0
diff
changeset
|
457 // but this thread could be racing with the thread that is |
9127aa69352e
6648438: 4/4 src/share/vm/prims/jvmtiEnv.cpp:457 assert(phase == JVMTI_PHASE_LIVE,"sanity check")
dcubed
parents:
0
diff
changeset
|
458 // terminating the VM so we check one more time. |
0 | 459 HandleMark hm; |
460 | |
461 // create the zip entry (which will open the zip file and hence | |
462 // check that the segment is indeed a zip file). | |
463 ClassPathZipEntry* zip_entry = ClassLoader::create_class_path_zip_entry(segment); | |
464 if (zip_entry == NULL) { | |
465 return JVMTI_ERROR_ILLEGAL_ARGUMENT; | |
466 } | |
467 delete zip_entry; // no longer needed | |
468 | |
469 // lock the loader | |
470 Thread* THREAD = Thread::current(); | |
471 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader()); | |
472 | |
473 ObjectLocker ol(loader, THREAD); | |
474 | |
475 // need the path as java.lang.String | |
476 Handle path = java_lang_String::create_from_str(segment, THREAD); | |
477 if (HAS_PENDING_EXCEPTION) { | |
478 CLEAR_PENDING_EXCEPTION; | |
479 return JVMTI_ERROR_INTERNAL; | |
480 } | |
481 | |
482 instanceKlassHandle loader_ik(THREAD, loader->klass()); | |
483 | |
484 // Invoke the appendToClassPathForInstrumentation method - if the method | |
485 // is not found it means the loader doesn't support adding to the class path | |
486 // in the live phase. | |
487 { | |
488 JavaValue res(T_VOID); | |
489 JavaCalls::call_special(&res, | |
490 loader, | |
491 loader_ik, | |
492 vmSymbolHandles::appendToClassPathForInstrumentation_name(), | |
493 vmSymbolHandles::appendToClassPathForInstrumentation_signature(), | |
494 path, | |
495 THREAD); | |
496 if (HAS_PENDING_EXCEPTION) { | |
497 symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name(); | |
498 CLEAR_PENDING_EXCEPTION; | |
499 | |
500 if (ex_name == vmSymbols::java_lang_NoSuchMethodError()) { | |
501 return JVMTI_ERROR_CLASS_LOADER_UNSUPPORTED; | |
502 } else { | |
503 return JVMTI_ERROR_INTERNAL; | |
504 } | |
505 } | |
506 } | |
507 | |
508 return JVMTI_ERROR_NONE; | |
1120
9127aa69352e
6648438: 4/4 src/share/vm/prims/jvmtiEnv.cpp:457 assert(phase == JVMTI_PHASE_LIVE,"sanity check")
dcubed
parents:
0
diff
changeset
|
509 } else { |
9127aa69352e
6648438: 4/4 src/share/vm/prims/jvmtiEnv.cpp:457 assert(phase == JVMTI_PHASE_LIVE,"sanity check")
dcubed
parents:
0
diff
changeset
|
510 return JVMTI_ERROR_WRONG_PHASE; |
0 | 511 } |
512 } /* end AddToSystemClassLoaderSearch */ | |
513 | |
514 // | |
515 // General functions | |
516 // | |
517 | |
518 // phase_ptr - pre-checked for NULL | |
519 jvmtiError | |
520 JvmtiEnv::GetPhase(jvmtiPhase* phase_ptr) { | |
521 *phase_ptr = get_phase(); | |
522 return JVMTI_ERROR_NONE; | |
523 } /* end GetPhase */ | |
524 | |
525 | |
526 jvmtiError | |
527 JvmtiEnv::DisposeEnvironment() { | |
528 dispose(); | |
529 return JVMTI_ERROR_NONE; | |
530 } /* end DisposeEnvironment */ | |
531 | |
532 | |
533 // data - NULL is a valid value, must be checked | |
534 jvmtiError | |
535 JvmtiEnv::SetEnvironmentLocalStorage(const void* data) { | |
536 set_env_local_storage(data); | |
537 return JVMTI_ERROR_NONE; | |
538 } /* end SetEnvironmentLocalStorage */ | |
539 | |
540 | |
541 // data_ptr - pre-checked for NULL | |
542 jvmtiError | |
543 JvmtiEnv::GetEnvironmentLocalStorage(void** data_ptr) { | |
544 *data_ptr = (void*)get_env_local_storage(); | |
545 return JVMTI_ERROR_NONE; | |
546 } /* end GetEnvironmentLocalStorage */ | |
547 | |
548 // version_ptr - pre-checked for NULL | |
549 jvmtiError | |
550 JvmtiEnv::GetVersionNumber(jint* version_ptr) { | |
551 *version_ptr = JVMTI_VERSION; | |
552 return JVMTI_ERROR_NONE; | |
553 } /* end GetVersionNumber */ | |
554 | |
555 | |
556 // name_ptr - pre-checked for NULL | |
557 jvmtiError | |
558 JvmtiEnv::GetErrorName(jvmtiError error, char** name_ptr) { | |
559 if (error < JVMTI_ERROR_NONE || error > JVMTI_ERROR_MAX) { | |
560 return JVMTI_ERROR_ILLEGAL_ARGUMENT; | |
561 } | |
562 const char *name = JvmtiUtil::error_name(error); | |
563 if (name == NULL) { | |
564 return JVMTI_ERROR_ILLEGAL_ARGUMENT; | |
565 } | |
566 size_t len = strlen(name) + 1; | |
567 jvmtiError err = allocate(len, (unsigned char**)name_ptr); | |
568 if (err == JVMTI_ERROR_NONE) { | |
569 memcpy(*name_ptr, name, len); | |
570 } | |
571 return err; | |
572 } /* end GetErrorName */ | |
573 | |
574 | |
575 jvmtiError | |
576 JvmtiEnv::SetVerboseFlag(jvmtiVerboseFlag flag, jboolean value) { | |
577 switch (flag) { | |
578 case JVMTI_VERBOSE_OTHER: | |
579 // ignore | |
580 break; | |
581 case JVMTI_VERBOSE_CLASS: | |
582 TraceClassLoading = value != 0; | |
583 TraceClassUnloading = value != 0; | |
584 break; | |
585 case JVMTI_VERBOSE_GC: | |
586 PrintGC = value != 0; | |
587 TraceClassUnloading = value != 0; | |
588 break; | |
589 case JVMTI_VERBOSE_JNI: | |
590 PrintJNIResolving = value != 0; | |
591 break; | |
592 default: | |
593 return JVMTI_ERROR_ILLEGAL_ARGUMENT; | |
594 }; | |
595 return JVMTI_ERROR_NONE; | |
596 } /* end SetVerboseFlag */ | |
597 | |
598 | |
599 // format_ptr - pre-checked for NULL | |
600 jvmtiError | |
601 JvmtiEnv::GetJLocationFormat(jvmtiJlocationFormat* format_ptr) { | |
602 *format_ptr = JVMTI_JLOCATION_JVMBCI; | |
603 return JVMTI_ERROR_NONE; | |
604 } /* end GetJLocationFormat */ | |
605 | |
606 #ifndef JVMTI_KERNEL | |
607 | |
608 // | |
609 // Thread functions | |
610 // | |
611 | |
612 // Threads_lock NOT held | |
613 // thread - NOT pre-checked | |
614 // thread_state_ptr - pre-checked for NULL | |
615 jvmtiError | |
616 JvmtiEnv::GetThreadState(jthread thread, jint* thread_state_ptr) { | |
617 jint state; | |
618 oop thread_oop; | |
619 JavaThread* thr; | |
620 | |
621 if (thread == NULL) { | |
622 thread_oop = JavaThread::current()->threadObj(); | |
623 } else { | |
624 thread_oop = JNIHandles::resolve_external_guard(thread); | |
625 } | |
626 | |
627 if (thread_oop == NULL || !thread_oop->is_a(SystemDictionary::thread_klass())) { | |
628 return JVMTI_ERROR_INVALID_THREAD; | |
629 } | |
630 | |
631 // get most state bits | |
632 state = (jint)java_lang_Thread::get_thread_status(thread_oop); | |
633 | |
634 // add more state bits | |
635 thr = java_lang_Thread::thread(thread_oop); | |
636 if (thr != NULL) { | |
637 JavaThreadState jts = thr->thread_state(); | |
638 | |
639 if (thr->is_being_ext_suspended()) { | |
640 state |= JVMTI_THREAD_STATE_SUSPENDED; | |
641 } | |
642 if (jts == _thread_in_native) { | |
643 state |= JVMTI_THREAD_STATE_IN_NATIVE; | |
644 } | |
645 OSThread* osThread = thr->osthread(); | |
646 if (osThread != NULL && osThread->interrupted()) { | |
647 state |= JVMTI_THREAD_STATE_INTERRUPTED; | |
648 } | |
649 } | |
650 | |
651 *thread_state_ptr = state; | |
652 return JVMTI_ERROR_NONE; | |
653 } /* end GetThreadState */ | |
654 | |
655 | |
656 // thread_ptr - pre-checked for NULL | |
657 jvmtiError | |
658 JvmtiEnv::GetCurrentThread(jthread* thread_ptr) { | |
659 JavaThread* current_thread = JavaThread::current(); | |
660 *thread_ptr = (jthread)JNIHandles::make_local(current_thread, current_thread->threadObj()); | |
661 return JVMTI_ERROR_NONE; | |
662 } /* end GetCurrentThread */ | |
663 | |
664 | |
665 // threads_count_ptr - pre-checked for NULL | |
666 // threads_ptr - pre-checked for NULL | |
667 jvmtiError | |
668 JvmtiEnv::GetAllThreads(jint* threads_count_ptr, jthread** threads_ptr) { | |
669 int nthreads = 0; | |
670 Handle *thread_objs = NULL; | |
671 ResourceMark rm; | |
672 HandleMark hm; | |
673 | |
674 // enumerate threads (including agent threads) | |
675 ThreadsListEnumerator tle(Thread::current(), true); | |
676 nthreads = tle.num_threads(); | |
677 *threads_count_ptr = nthreads; | |
678 | |
679 if (nthreads == 0) { | |
680 *threads_ptr = NULL; | |
681 return JVMTI_ERROR_NONE; | |
682 } | |
683 | |
684 thread_objs = NEW_RESOURCE_ARRAY(Handle, nthreads); | |
685 NULL_CHECK(thread_objs, JVMTI_ERROR_OUT_OF_MEMORY); | |
686 | |
687 for (int i=0; i < nthreads; i++) { | |
688 thread_objs[i] = Handle(tle.get_threadObj(i)); | |
689 } | |
690 | |
691 // have to make global handles outside of Threads_lock | |
692 jthread *jthreads = new_jthreadArray(nthreads, thread_objs); | |
693 NULL_CHECK(jthreads, JVMTI_ERROR_OUT_OF_MEMORY); | |
694 | |
695 *threads_ptr = jthreads; | |
696 return JVMTI_ERROR_NONE; | |
697 } /* end GetAllThreads */ | |
698 | |
699 | |
700 // Threads_lock NOT held, java_thread not protected by lock | |
701 // java_thread - pre-checked | |
702 jvmtiError | |
703 JvmtiEnv::SuspendThread(JavaThread* java_thread) { | |
704 // don't allow hidden thread suspend request. | |
705 if (java_thread->is_hidden_from_external_view()) { | |
706 return (JVMTI_ERROR_NONE); | |
707 } | |
708 | |
709 { | |
710 MutexLockerEx ml(java_thread->SR_lock(), Mutex::_no_safepoint_check_flag); | |
711 if (java_thread->is_external_suspend()) { | |
712 // don't allow nested external suspend requests. | |
713 return (JVMTI_ERROR_THREAD_SUSPENDED); | |
714 } | |
715 if (java_thread->is_exiting()) { // thread is in the process of exiting | |
716 return (JVMTI_ERROR_THREAD_NOT_ALIVE); | |
717 } | |
718 java_thread->set_external_suspend(); | |
719 } | |
720 | |
721 if (!JvmtiSuspendControl::suspend(java_thread)) { | |
722 // the thread was in the process of exiting | |
723 return (JVMTI_ERROR_THREAD_NOT_ALIVE); | |
724 } | |
725 return JVMTI_ERROR_NONE; | |
726 } /* end SuspendThread */ | |
727 | |
728 | |
729 // request_count - pre-checked to be greater than or equal to 0 | |
730 // request_list - pre-checked for NULL | |
731 // results - pre-checked for NULL | |
732 jvmtiError | |
733 JvmtiEnv::SuspendThreadList(jint request_count, const jthread* request_list, jvmtiError* results) { | |
734 int needSafepoint = 0; // > 0 if we need a safepoint | |
735 for (int i = 0; i < request_count; i++) { | |
736 JavaThread *java_thread = get_JavaThread(request_list[i]); | |
737 if (java_thread == NULL) { | |
738 results[i] = JVMTI_ERROR_INVALID_THREAD; | |
739 continue; | |
740 } | |
741 // the thread has not yet run or has exited (not on threads list) | |
742 if (java_thread->threadObj() == NULL) { | |
743 results[i] = JVMTI_ERROR_THREAD_NOT_ALIVE; | |
744 continue; | |
745 } | |
746 if (java_lang_Thread::thread(java_thread->threadObj()) == NULL) { | |
747 results[i] = JVMTI_ERROR_THREAD_NOT_ALIVE; | |
748 continue; | |
749 } | |
750 // don't allow hidden thread suspend request. | |
751 if (java_thread->is_hidden_from_external_view()) { | |
752 results[i] = JVMTI_ERROR_NONE; // indicate successful suspend | |
753 continue; | |
754 } | |
755 | |
756 { | |
757 MutexLockerEx ml(java_thread->SR_lock(), Mutex::_no_safepoint_check_flag); | |
758 if (java_thread->is_external_suspend()) { | |
759 // don't allow nested external suspend requests. | |
760 results[i] = JVMTI_ERROR_THREAD_SUSPENDED; | |
761 continue; | |
762 } | |
763 if (java_thread->is_exiting()) { // thread is in the process of exiting | |
764 results[i] = JVMTI_ERROR_THREAD_NOT_ALIVE; | |
765 continue; | |
766 } | |
767 java_thread->set_external_suspend(); | |
768 } | |
769 if (java_thread->thread_state() == _thread_in_native) { | |
770 // We need to try and suspend native threads here. Threads in | |
771 // other states will self-suspend on their next transition. | |
772 if (!JvmtiSuspendControl::suspend(java_thread)) { | |
773 // The thread was in the process of exiting. Force another | |
774 // safepoint to make sure that this thread transitions. | |
775 needSafepoint++; | |
776 results[i] = JVMTI_ERROR_THREAD_NOT_ALIVE; | |
777 continue; | |
778 } | |
779 } else { | |
780 needSafepoint++; | |
781 } | |
782 results[i] = JVMTI_ERROR_NONE; // indicate successful suspend | |
783 } | |
784 if (needSafepoint > 0) { | |
785 VM_ForceSafepoint vfs; | |
786 VMThread::execute(&vfs); | |
787 } | |
788 // per-thread suspend results returned via results parameter | |
789 return JVMTI_ERROR_NONE; | |
790 } /* end SuspendThreadList */ | |
791 | |
792 | |
793 // Threads_lock NOT held, java_thread not protected by lock | |
794 // java_thread - pre-checked | |
795 jvmtiError | |
796 JvmtiEnv::ResumeThread(JavaThread* java_thread) { | |
797 // don't allow hidden thread resume request. | |
798 if (java_thread->is_hidden_from_external_view()) { | |
799 return JVMTI_ERROR_NONE; | |
800 } | |
801 | |
802 if (!java_thread->is_being_ext_suspended()) { | |
803 return JVMTI_ERROR_THREAD_NOT_SUSPENDED; | |
804 } | |
805 | |
806 if (!JvmtiSuspendControl::resume(java_thread)) { | |
807 return JVMTI_ERROR_INTERNAL; | |
808 } | |
809 return JVMTI_ERROR_NONE; | |
810 } /* end ResumeThread */ | |
811 | |
812 | |
813 // request_count - pre-checked to be greater than or equal to 0 | |
814 // request_list - pre-checked for NULL | |
815 // results - pre-checked for NULL | |
816 jvmtiError | |
817 JvmtiEnv::ResumeThreadList(jint request_count, const jthread* request_list, jvmtiError* results) { | |
818 for (int i = 0; i < request_count; i++) { | |
819 JavaThread *java_thread = get_JavaThread(request_list[i]); | |
820 if (java_thread == NULL) { | |
821 results[i] = JVMTI_ERROR_INVALID_THREAD; | |
822 continue; | |
823 } | |
824 // don't allow hidden thread resume request. | |
825 if (java_thread->is_hidden_from_external_view()) { | |
826 results[i] = JVMTI_ERROR_NONE; // indicate successful resume | |
827 continue; | |
828 } | |
829 if (!java_thread->is_being_ext_suspended()) { | |
830 results[i] = JVMTI_ERROR_THREAD_NOT_SUSPENDED; | |
831 continue; | |
832 } | |
833 | |
834 if (!JvmtiSuspendControl::resume(java_thread)) { | |
835 results[i] = JVMTI_ERROR_INTERNAL; | |
836 continue; | |
837 } | |
838 | |
839 results[i] = JVMTI_ERROR_NONE; // indicate successful suspend | |
840 } | |
841 // per-thread resume results returned via results parameter | |
842 return JVMTI_ERROR_NONE; | |
843 } /* end ResumeThreadList */ | |
844 | |
845 | |
846 // Threads_lock NOT held, java_thread not protected by lock | |
847 // java_thread - pre-checked | |
848 jvmtiError | |
849 JvmtiEnv::StopThread(JavaThread* java_thread, jobject exception) { | |
850 oop e = JNIHandles::resolve_external_guard(exception); | |
851 NULL_CHECK(e, JVMTI_ERROR_NULL_POINTER); | |
852 | |
853 JavaThread::send_async_exception(java_thread->threadObj(), e); | |
854 | |
855 return JVMTI_ERROR_NONE; | |
856 | |
857 } /* end StopThread */ | |
858 | |
859 | |
860 // Threads_lock NOT held | |
861 // thread - NOT pre-checked | |
862 jvmtiError | |
863 JvmtiEnv::InterruptThread(jthread thread) { | |
864 oop thread_oop = JNIHandles::resolve_external_guard(thread); | |
865 if (thread_oop == NULL || !thread_oop->is_a(SystemDictionary::thread_klass())) | |
866 return JVMTI_ERROR_INVALID_THREAD; | |
867 | |
868 JavaThread* current_thread = JavaThread::current(); | |
869 | |
870 // Todo: this is a duplicate of JVM_Interrupt; share code in future | |
871 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate | |
872 MutexLockerEx ml(current_thread->threadObj() == thread_oop ? NULL : Threads_lock); | |
873 // We need to re-resolve the java_thread, since a GC might have happened during the | |
874 // acquire of the lock | |
875 | |
876 JavaThread* java_thread = java_lang_Thread::thread(JNIHandles::resolve_external_guard(thread)); | |
877 NULL_CHECK(java_thread, JVMTI_ERROR_THREAD_NOT_ALIVE); | |
878 | |
879 Thread::interrupt(java_thread); | |
880 | |
881 return JVMTI_ERROR_NONE; | |
882 } /* end InterruptThread */ | |
883 | |
884 | |
885 // Threads_lock NOT held | |
886 // thread - NOT pre-checked | |
887 // info_ptr - pre-checked for NULL | |
888 jvmtiError | |
889 JvmtiEnv::GetThreadInfo(jthread thread, jvmtiThreadInfo* info_ptr) { | |
890 ResourceMark rm; | |
891 HandleMark hm; | |
892 | |
893 JavaThread* current_thread = JavaThread::current(); | |
894 | |
895 // if thread is NULL the current thread is used | |
896 oop thread_oop; | |
897 if (thread == NULL) { | |
898 thread_oop = current_thread->threadObj(); | |
899 } else { | |
900 thread_oop = JNIHandles::resolve_external_guard(thread); | |
901 } | |
902 if (thread_oop == NULL || !thread_oop->is_a(SystemDictionary::thread_klass())) | |
903 return JVMTI_ERROR_INVALID_THREAD; | |
904 | |
905 Handle thread_obj(current_thread, thread_oop); | |
906 typeArrayHandle name; | |
907 ThreadPriority priority; | |
908 Handle thread_group; | |
909 Handle context_class_loader; | |
910 bool is_daemon; | |
911 | |
912 { MutexLocker mu(Threads_lock); | |
913 | |
914 name = typeArrayHandle(current_thread, java_lang_Thread::name(thread_obj())); | |
915 priority = java_lang_Thread::priority(thread_obj()); | |
916 thread_group = Handle(current_thread, java_lang_Thread::threadGroup(thread_obj())); | |
917 is_daemon = java_lang_Thread::is_daemon(thread_obj()); | |
918 | |
919 oop loader = java_lang_Thread::context_class_loader(thread_obj()); | |
920 context_class_loader = Handle(current_thread, loader); | |
921 } | |
922 { const char *n; | |
923 | |
924 if (name() != NULL) { | |
925 n = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length()); | |
926 } else { | |
927 n = UNICODE::as_utf8(NULL, 0); | |
928 } | |
929 | |
930 info_ptr->name = (char *) jvmtiMalloc(strlen(n)+1); | |
931 if (info_ptr->name == NULL) | |
932 return JVMTI_ERROR_OUT_OF_MEMORY; | |
933 | |
934 strcpy(info_ptr->name, n); | |
935 } | |
936 info_ptr->is_daemon = is_daemon; | |
937 info_ptr->priority = priority; | |
938 | |
939 info_ptr->context_class_loader = (context_class_loader.is_null()) ? NULL : | |
940 jni_reference(context_class_loader); | |
941 info_ptr->thread_group = jni_reference(thread_group); | |
942 | |
943 return JVMTI_ERROR_NONE; | |
944 } /* end GetThreadInfo */ | |
945 | |
946 | |
947 // Threads_lock NOT held, java_thread not protected by lock | |
948 // java_thread - pre-checked | |
949 // owned_monitor_count_ptr - pre-checked for NULL | |
950 // owned_monitors_ptr - pre-checked for NULL | |
951 jvmtiError | |
952 JvmtiEnv::GetOwnedMonitorInfo(JavaThread* java_thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr) { | |
953 jvmtiError err = JVMTI_ERROR_NONE; | |
954 JavaThread* calling_thread = JavaThread::current(); | |
955 | |
956 // growable array of jvmti monitors info on the C-heap | |
957 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list = | |
958 new (ResourceObj::C_HEAP) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, true); | |
959 | |
960 uint32_t debug_bits = 0; | |
961 if (is_thread_fully_suspended(java_thread, true, &debug_bits)) { | |
962 err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list); | |
963 } else { | |
964 // JVMTI get monitors info at safepoint. Do not require target thread to | |
965 // be suspended. | |
966 VM_GetOwnedMonitorInfo op(this, calling_thread, java_thread, owned_monitors_list); | |
967 VMThread::execute(&op); | |
968 err = op.result(); | |
969 } | |
970 jint owned_monitor_count = owned_monitors_list->length(); | |
971 if (err == JVMTI_ERROR_NONE) { | |
972 if ((err = allocate(owned_monitor_count * sizeof(jobject *), | |
973 (unsigned char**)owned_monitors_ptr)) == JVMTI_ERROR_NONE) { | |
974 // copy into the returned array | |
975 for (int i = 0; i < owned_monitor_count; i++) { | |
976 (*owned_monitors_ptr)[i] = | |
977 ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor; | |
978 } | |
979 *owned_monitor_count_ptr = owned_monitor_count; | |
980 } | |
981 } | |
982 // clean up. | |
983 for (int i = 0; i < owned_monitor_count; i++) { | |
984 deallocate((unsigned char*)owned_monitors_list->at(i)); | |
985 } | |
986 delete owned_monitors_list; | |
987 | |
988 return err; | |
989 } /* end GetOwnedMonitorInfo */ | |
990 | |
991 | |
992 // Threads_lock NOT held, java_thread not protected by lock | |
993 // java_thread - pre-checked | |
994 // monitor_info_count_ptr - pre-checked for NULL | |
995 // monitor_info_ptr - pre-checked for NULL | |
996 jvmtiError | |
997 JvmtiEnv::GetOwnedMonitorStackDepthInfo(JavaThread* java_thread, jint* monitor_info_count_ptr, jvmtiMonitorStackDepthInfo** monitor_info_ptr) { | |
998 jvmtiError err = JVMTI_ERROR_NONE; | |
999 JavaThread* calling_thread = JavaThread::current(); | |
1000 | |
1001 // growable array of jvmti monitors info on the C-heap | |
1002 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list = | |
1003 new (ResourceObj::C_HEAP) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, true); | |
1004 | |
1005 uint32_t debug_bits = 0; | |
1006 if (is_thread_fully_suspended(java_thread, true, &debug_bits)) { | |
1007 err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list); | |
1008 } else { | |
1009 // JVMTI get owned monitors info at safepoint. Do not require target thread to | |
1010 // be suspended. | |
1011 VM_GetOwnedMonitorInfo op(this, calling_thread, java_thread, owned_monitors_list); | |
1012 VMThread::execute(&op); | |
1013 err = op.result(); | |
1014 } | |
1015 | |
1016 jint owned_monitor_count = owned_monitors_list->length(); | |
1017 if (err == JVMTI_ERROR_NONE) { | |
1018 if ((err = allocate(owned_monitor_count * sizeof(jvmtiMonitorStackDepthInfo), | |
1019 (unsigned char**)monitor_info_ptr)) == JVMTI_ERROR_NONE) { | |
1020 // copy to output array. | |
1021 for (int i = 0; i < owned_monitor_count; i++) { | |
1022 (*monitor_info_ptr)[i].monitor = | |
1023 ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor; | |
1024 (*monitor_info_ptr)[i].stack_depth = | |
1025 ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->stack_depth; | |
1026 } | |
1027 } | |
1028 *monitor_info_count_ptr = owned_monitor_count; | |
1029 } | |
1030 | |
1031 // clean up. | |
1032 for (int i = 0; i < owned_monitor_count; i++) { | |
1033 deallocate((unsigned char*)owned_monitors_list->at(i)); | |
1034 } | |
1035 delete owned_monitors_list; | |
1036 | |
1037 return err; | |
1038 } /* end GetOwnedMonitorStackDepthInfo */ | |
1039 | |
1040 | |
1041 // Threads_lock NOT held, java_thread not protected by lock | |
1042 // java_thread - pre-checked | |
1043 // monitor_ptr - pre-checked for NULL | |
1044 jvmtiError | |
1045 JvmtiEnv::GetCurrentContendedMonitor(JavaThread* java_thread, jobject* monitor_ptr) { | |
1046 jvmtiError err = JVMTI_ERROR_NONE; | |
1047 uint32_t debug_bits = 0; | |
1048 JavaThread* calling_thread = JavaThread::current(); | |
1049 if (is_thread_fully_suspended(java_thread, true, &debug_bits)) { | |
1050 err = get_current_contended_monitor(calling_thread, java_thread, monitor_ptr); | |
1051 } else { | |
1052 // get contended monitor information at safepoint. | |
1053 VM_GetCurrentContendedMonitor op(this, calling_thread, java_thread, monitor_ptr); | |
1054 VMThread::execute(&op); | |
1055 err = op.result(); | |
1056 } | |
1057 return err; | |
1058 } /* end GetCurrentContendedMonitor */ | |
1059 | |
1060 | |
1061 // Threads_lock NOT held | |
1062 // thread - NOT pre-checked | |
1063 // proc - pre-checked for NULL | |
1064 // arg - NULL is a valid value, must be checked | |
1065 jvmtiError | |
1066 JvmtiEnv::RunAgentThread(jthread thread, jvmtiStartFunction proc, const void* arg, jint priority) { | |
1067 oop thread_oop = JNIHandles::resolve_external_guard(thread); | |
1068 if (thread_oop == NULL || !thread_oop->is_a(SystemDictionary::thread_klass())) { | |
1069 return JVMTI_ERROR_INVALID_THREAD; | |
1070 } | |
1071 if (priority < JVMTI_THREAD_MIN_PRIORITY || priority > JVMTI_THREAD_MAX_PRIORITY) { | |
1072 return JVMTI_ERROR_INVALID_PRIORITY; | |
1073 } | |
1074 | |
1075 //Thread-self | |
1076 JavaThread* current_thread = JavaThread::current(); | |
1077 | |
1078 Handle thread_hndl(current_thread, thread_oop); | |
1079 { | |
1080 MutexLocker mu(Threads_lock); // grab Threads_lock | |
1081 | |
1082 JvmtiAgentThread *new_thread = new JvmtiAgentThread(this, proc, arg); | |
1083 | |
1084 // At this point it may be possible that no osthread was created for the | |
1085 // JavaThread due to lack of memory. | |
1086 if (new_thread == NULL || new_thread->osthread() == NULL) { | |
1087 if (new_thread) delete new_thread; | |
1088 return JVMTI_ERROR_OUT_OF_MEMORY; | |
1089 } | |
1090 | |
1091 java_lang_Thread::set_thread(thread_hndl(), new_thread); | |
1092 java_lang_Thread::set_priority(thread_hndl(), (ThreadPriority)priority); | |
1093 java_lang_Thread::set_daemon(thread_hndl()); | |
1094 | |
1095 new_thread->set_threadObj(thread_hndl()); | |
1096 Threads::add(new_thread); | |
1097 Thread::start(new_thread); | |
1098 } // unlock Threads_lock | |
1099 | |
1100 return JVMTI_ERROR_NONE; | |
1101 } /* end RunAgentThread */ | |
1102 | |
1103 // | |
1104 // Thread Group functions | |
1105 // | |
1106 | |
1107 // group_count_ptr - pre-checked for NULL | |
1108 // groups_ptr - pre-checked for NULL | |
1109 jvmtiError | |
1110 JvmtiEnv::GetTopThreadGroups(jint* group_count_ptr, jthreadGroup** groups_ptr) { | |
1111 JavaThread* current_thread = JavaThread::current(); | |
1112 | |
1113 // Only one top level thread group now. | |
1114 *group_count_ptr = 1; | |
1115 | |
1116 // Allocate memory to store global-refs to the thread groups. | |
1117 // Assume this area is freed by caller. | |
1118 *groups_ptr = (jthreadGroup *) jvmtiMalloc((sizeof(jthreadGroup)) * (*group_count_ptr)); | |
1119 | |
1120 NULL_CHECK(*groups_ptr, JVMTI_ERROR_OUT_OF_MEMORY); | |
1121 | |
1122 // Convert oop to Handle, then convert Handle to global-ref. | |
1123 { | |
1124 HandleMark hm(current_thread); | |
1125 Handle system_thread_group(current_thread, Universe::system_thread_group()); | |
1126 *groups_ptr[0] = jni_reference(system_thread_group); | |
1127 } | |
1128 | |
1129 return JVMTI_ERROR_NONE; | |
1130 } /* end GetTopThreadGroups */ | |
1131 | |
1132 | |
1133 // info_ptr - pre-checked for NULL | |
1134 jvmtiError | |
1135 JvmtiEnv::GetThreadGroupInfo(jthreadGroup group, jvmtiThreadGroupInfo* info_ptr) { | |
1136 ResourceMark rm; | |
1137 HandleMark hm; | |
1138 | |
1139 JavaThread* current_thread = JavaThread::current(); | |
1140 | |
1141 Handle group_obj (current_thread, JNIHandles::resolve_external_guard(group)); | |
1142 NULL_CHECK(group_obj(), JVMTI_ERROR_INVALID_THREAD_GROUP); | |
1143 | |
1144 typeArrayHandle name; | |
1145 Handle parent_group; | |
1146 bool is_daemon; | |
1147 ThreadPriority max_priority; | |
1148 | |
1149 { MutexLocker mu(Threads_lock); | |
1150 | |
1151 name = typeArrayHandle(current_thread, | |
1152 java_lang_ThreadGroup::name(group_obj())); | |
1153 parent_group = Handle(current_thread, java_lang_ThreadGroup::parent(group_obj())); | |
1154 is_daemon = java_lang_ThreadGroup::is_daemon(group_obj()); | |
1155 max_priority = java_lang_ThreadGroup::maxPriority(group_obj()); | |
1156 } | |
1157 | |
1158 info_ptr->is_daemon = is_daemon; | |
1159 info_ptr->max_priority = max_priority; | |
1160 info_ptr->parent = jni_reference(parent_group); | |
1161 | |
1162 if (name() != NULL) { | |
1163 const char* n = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length()); | |
1164 info_ptr->name = (char *)jvmtiMalloc(strlen(n)+1); | |
1165 NULL_CHECK(info_ptr->name, JVMTI_ERROR_OUT_OF_MEMORY); | |
1166 strcpy(info_ptr->name, n); | |
1167 } else { | |
1168 info_ptr->name = NULL; | |
1169 } | |
1170 | |
1171 return JVMTI_ERROR_NONE; | |
1172 } /* end GetThreadGroupInfo */ | |
1173 | |
1174 | |
1175 // thread_count_ptr - pre-checked for NULL | |
1176 // threads_ptr - pre-checked for NULL | |
1177 // group_count_ptr - pre-checked for NULL | |
1178 // groups_ptr - pre-checked for NULL | |
1179 jvmtiError | |
1180 JvmtiEnv::GetThreadGroupChildren(jthreadGroup group, jint* thread_count_ptr, jthread** threads_ptr, jint* group_count_ptr, jthreadGroup** groups_ptr) { | |
1181 JavaThread* current_thread = JavaThread::current(); | |
1182 oop group_obj = (oop) JNIHandles::resolve_external_guard(group); | |
1183 NULL_CHECK(group_obj, JVMTI_ERROR_INVALID_THREAD_GROUP); | |
1184 | |
1185 Handle *thread_objs = NULL; | |
1186 Handle *group_objs = NULL; | |
1187 int nthreads = 0; | |
1188 int ngroups = 0; | |
1189 int hidden_threads = 0; | |
1190 | |
1191 ResourceMark rm; | |
1192 HandleMark hm; | |
1193 | |
1194 Handle group_hdl(current_thread, group_obj); | |
1195 | |
1196 { MutexLocker mu(Threads_lock); | |
1197 | |
1198 nthreads = java_lang_ThreadGroup::nthreads(group_hdl()); | |
1199 ngroups = java_lang_ThreadGroup::ngroups(group_hdl()); | |
1200 | |
1201 if (nthreads > 0) { | |
1202 objArrayOop threads = java_lang_ThreadGroup::threads(group_hdl()); | |
1203 assert(nthreads <= threads->length(), "too many threads"); | |
1204 thread_objs = NEW_RESOURCE_ARRAY(Handle,nthreads); | |
1205 for (int i=0, j=0; i<nthreads; i++) { | |
1206 oop thread_obj = threads->obj_at(i); | |
1207 assert(thread_obj != NULL, "thread_obj is NULL"); | |
1208 JavaThread *javathread = java_lang_Thread::thread(thread_obj); | |
1209 // Filter out hidden java threads. | |
1210 if (javathread != NULL && javathread->is_hidden_from_external_view()) { | |
1211 hidden_threads++; | |
1212 continue; | |
1213 } | |
1214 thread_objs[j++] = Handle(current_thread, thread_obj); | |
1215 } | |
1216 nthreads -= hidden_threads; | |
1217 } | |
1218 if (ngroups > 0) { | |
1219 objArrayOop groups = java_lang_ThreadGroup::groups(group_hdl()); | |
1220 assert(ngroups <= groups->length(), "too many threads"); | |
1221 group_objs = NEW_RESOURCE_ARRAY(Handle,ngroups); | |
1222 for (int i=0; i<ngroups; i++) { | |
1223 oop group_obj = groups->obj_at(i); | |
1224 assert(group_obj != NULL, "group_obj != NULL"); | |
1225 group_objs[i] = Handle(current_thread, group_obj); | |
1226 } | |
1227 } | |
1228 } | |
1229 | |
1230 // have to make global handles outside of Threads_lock | |
1231 *group_count_ptr = ngroups; | |
1232 *thread_count_ptr = nthreads; | |
1233 *threads_ptr = new_jthreadArray(nthreads, thread_objs); | |
1234 *groups_ptr = new_jthreadGroupArray(ngroups, group_objs); | |
1235 if ((nthreads > 0) && (*threads_ptr == NULL)) { | |
1236 return JVMTI_ERROR_OUT_OF_MEMORY; | |
1237 } | |
1238 if ((ngroups > 0) && (*groups_ptr == NULL)) { | |
1239 return JVMTI_ERROR_OUT_OF_MEMORY; | |
1240 } | |
1241 | |
1242 return JVMTI_ERROR_NONE; | |
1243 } /* end GetThreadGroupChildren */ | |
1244 | |
1245 | |
1246 // | |
1247 // Stack Frame functions | |
1248 // | |
1249 | |
1250 // Threads_lock NOT held, java_thread not protected by lock | |
1251 // java_thread - pre-checked | |
1252 // max_frame_count - pre-checked to be greater than or equal to 0 | |
1253 // frame_buffer - pre-checked for NULL | |
1254 // count_ptr - pre-checked for NULL | |
1255 jvmtiError | |
1256 JvmtiEnv::GetStackTrace(JavaThread* java_thread, jint start_depth, jint max_frame_count, jvmtiFrameInfo* frame_buffer, jint* count_ptr) { | |
1257 jvmtiError err = JVMTI_ERROR_NONE; | |
1258 uint32_t debug_bits = 0; | |
1259 if (is_thread_fully_suspended(java_thread, true, &debug_bits)) { | |
1260 err = get_stack_trace(java_thread, start_depth, max_frame_count, frame_buffer, count_ptr); | |
1261 } else { | |
1262 // JVMTI get stack trace at safepoint. Do not require target thread to | |
1263 // be suspended. | |
1264 VM_GetStackTrace op(this, java_thread, start_depth, max_frame_count, frame_buffer, count_ptr); | |
1265 VMThread::execute(&op); | |
1266 err = op.result(); | |
1267 } | |
1268 | |
1269 return err; | |
1270 } /* end GetStackTrace */ | |
1271 | |
1272 | |
1273 // max_frame_count - pre-checked to be greater than or equal to 0 | |
1274 // stack_info_ptr - pre-checked for NULL | |
1275 // thread_count_ptr - pre-checked for NULL | |
1276 jvmtiError | |
1277 JvmtiEnv::GetAllStackTraces(jint max_frame_count, jvmtiStackInfo** stack_info_ptr, jint* thread_count_ptr) { | |
1278 jvmtiError err = JVMTI_ERROR_NONE; | |
1279 JavaThread* calling_thread = JavaThread::current(); | |
1280 | |
1281 // JVMTI get stack traces at safepoint. | |
1282 VM_GetAllStackTraces op(this, calling_thread, max_frame_count); | |
1283 VMThread::execute(&op); | |
1284 *thread_count_ptr = op.final_thread_count(); | |
1285 *stack_info_ptr = op.stack_info(); | |
1286 err = op.result(); | |
1287 return err; | |
1288 } /* end GetAllStackTraces */ | |
1289 | |
1290 | |
1291 // thread_count - pre-checked to be greater than or equal to 0 | |
1292 // thread_list - pre-checked for NULL | |
1293 // max_frame_count - pre-checked to be greater than or equal to 0 | |
1294 // stack_info_ptr - pre-checked for NULL | |
1295 jvmtiError | |
1296 JvmtiEnv::GetThreadListStackTraces(jint thread_count, const jthread* thread_list, jint max_frame_count, jvmtiStackInfo** stack_info_ptr) { | |
1297 jvmtiError err = JVMTI_ERROR_NONE; | |
1298 // JVMTI get stack traces at safepoint. | |
1299 VM_GetThreadListStackTraces op(this, thread_count, thread_list, max_frame_count); | |
1300 VMThread::execute(&op); | |
1301 err = op.result(); | |
1302 if (err == JVMTI_ERROR_NONE) { | |
1303 *stack_info_ptr = op.stack_info(); | |
1304 } | |
1305 return err; | |
1306 } /* end GetThreadListStackTraces */ | |
1307 | |
1308 | |
1309 // Threads_lock NOT held, java_thread not protected by lock | |
1310 // java_thread - pre-checked | |
1311 // count_ptr - pre-checked for NULL | |
1312 jvmtiError | |
1313 JvmtiEnv::GetFrameCount(JavaThread* java_thread, jint* count_ptr) { | |
1314 jvmtiError err = JVMTI_ERROR_NONE; | |
1315 | |
1316 // retrieve or create JvmtiThreadState. | |
1317 JvmtiThreadState* state = JvmtiThreadState::state_for(java_thread); | |
1318 uint32_t debug_bits = 0; | |
1319 if (is_thread_fully_suspended(java_thread, true, &debug_bits)) { | |
1320 err = get_frame_count(state, count_ptr); | |
1321 } else { | |
1322 // get java stack frame count at safepoint. | |
1323 VM_GetFrameCount op(this, state, count_ptr); | |
1324 VMThread::execute(&op); | |
1325 err = op.result(); | |
1326 } | |
1327 return err; | |
1328 } /* end GetFrameCount */ | |
1329 | |
1330 | |
1331 // Threads_lock NOT held, java_thread not protected by lock | |
1332 // java_thread - pre-checked | |
1333 jvmtiError | |
1334 JvmtiEnv::PopFrame(JavaThread* java_thread) { | |
1335 JavaThread* current_thread = JavaThread::current(); | |
1336 HandleMark hm(current_thread); | |
1337 uint32_t debug_bits = 0; | |
1338 | |
1339 // Check if java_thread is fully suspended | |
1340 if (!is_thread_fully_suspended(java_thread, true /* wait for suspend completion */, &debug_bits)) { | |
1341 return JVMTI_ERROR_THREAD_NOT_SUSPENDED; | |
1342 } | |
1343 // Check to see if a PopFrame was already in progress | |
1344 if (java_thread->popframe_condition() != JavaThread::popframe_inactive) { | |
1345 // Probably possible for JVMTI clients to trigger this, but the | |
1346 // JPDA backend shouldn't allow this to happen | |
1347 return JVMTI_ERROR_INTERNAL; | |
1348 } | |
1349 | |
1350 { | |
1351 // Was workaround bug | |
1352 // 4812902: popFrame hangs if the method is waiting at a synchronize | |
1353 // Catch this condition and return an error to avoid hanging. | |
1354 // Now JVMTI spec allows an implementation to bail out with an opaque frame error. | |
1355 OSThread* osThread = java_thread->osthread(); | |
1356 if (osThread->get_state() == MONITOR_WAIT) { | |
1357 return JVMTI_ERROR_OPAQUE_FRAME; | |
1358 } | |
1359 } | |
1360 | |
1361 { | |
1362 ResourceMark rm(current_thread); | |
1363 // Check if there are more than one Java frame in this thread, that the top two frames | |
1364 // are Java (not native) frames, and that there is no intervening VM frame | |
1365 int frame_count = 0; | |
1366 bool is_interpreted[2]; | |
1367 intptr_t *frame_sp[2]; | |
1368 // The 2-nd arg of constructor is needed to stop iterating at java entry frame. | |
1369 for (vframeStream vfs(java_thread, true); !vfs.at_end(); vfs.next()) { | |
1370 methodHandle mh(current_thread, vfs.method()); | |
1371 if (mh->is_native()) return(JVMTI_ERROR_OPAQUE_FRAME); | |
1372 is_interpreted[frame_count] = vfs.is_interpreted_frame(); | |
1373 frame_sp[frame_count] = vfs.frame_id(); | |
1374 if (++frame_count > 1) break; | |
1375 } | |
1376 if (frame_count < 2) { | |
1377 // We haven't found two adjacent non-native Java frames on the top. | |
1378 // There can be two situations here: | |
1379 // 1. There are no more java frames | |
1380 // 2. Two top java frames are separated by non-java native frames | |
1381 if(vframeFor(java_thread, 1) == NULL) { | |
1382 return JVMTI_ERROR_NO_MORE_FRAMES; | |
1383 } else { | |
1384 // Intervening non-java native or VM frames separate java frames. | |
1385 // Current implementation does not support this. See bug #5031735. | |
1386 // In theory it is possible to pop frames in such cases. | |
1387 return JVMTI_ERROR_OPAQUE_FRAME; | |
1388 } | |
1389 } | |
1390 | |
1391 // If any of the top 2 frames is a compiled one, need to deoptimize it | |
1392 for (int i = 0; i < 2; i++) { | |
1393 if (!is_interpreted[i]) { | |
1394 VM_DeoptimizeFrame op(java_thread, frame_sp[i]); | |
1395 VMThread::execute(&op); | |
1396 } | |
1397 } | |
1398 | |
1399 // Update the thread state to reflect that the top frame is popped | |
1400 // so that cur_stack_depth is maintained properly and all frameIDs | |
1401 // are invalidated. | |
1402 // The current frame will be popped later when the suspended thread | |
1403 // is resumed and right before returning from VM to Java. | |
1404 // (see call_VM_base() in assembler_<cpu>.cpp). | |
1405 | |
1406 // It's fine to update the thread state here because no JVMTI events | |
1407 // shall be posted for this PopFrame. | |
1408 | |
1409 // retreive or create the state | |
1410 JvmtiThreadState* state = JvmtiThreadState::state_for(java_thread); | |
1411 | |
1412 state->update_for_pop_top_frame(); | |
1413 java_thread->set_popframe_condition(JavaThread::popframe_pending_bit); | |
1414 // Set pending step flag for this popframe and it is cleared when next | |
1415 // step event is posted. | |
1416 state->set_pending_step_for_popframe(); | |
1417 } | |
1418 | |
1419 return JVMTI_ERROR_NONE; | |
1420 } /* end PopFrame */ | |
1421 | |
1422 | |
1423 // Threads_lock NOT held, java_thread not protected by lock | |
1424 // java_thread - pre-checked | |
1425 // java_thread - unchecked | |
1426 // depth - pre-checked as non-negative | |
1427 // method_ptr - pre-checked for NULL | |
1428 // location_ptr - pre-checked for NULL | |
1429 jvmtiError | |
1430 JvmtiEnv::GetFrameLocation(JavaThread* java_thread, jint depth, jmethodID* method_ptr, jlocation* location_ptr) { | |
1431 jvmtiError err = JVMTI_ERROR_NONE; | |
1432 uint32_t debug_bits = 0; | |
1433 | |
1434 if (is_thread_fully_suspended(java_thread, true, &debug_bits)) { | |
1435 err = get_frame_location(java_thread, depth, method_ptr, location_ptr); | |
1436 } else { | |
1437 // JVMTI get java stack frame location at safepoint. | |
1438 VM_GetFrameLocation op(this, java_thread, depth, method_ptr, location_ptr); | |
1439 VMThread::execute(&op); | |
1440 err = op.result(); | |
1441 } | |
1442 return err; | |
1443 } /* end GetFrameLocation */ | |
1444 | |
1445 | |
1446 // Threads_lock NOT held, java_thread not protected by lock | |
1447 // java_thread - pre-checked | |
1448 // java_thread - unchecked | |
1449 // depth - pre-checked as non-negative | |
1450 jvmtiError | |
1451 JvmtiEnv::NotifyFramePop(JavaThread* java_thread, jint depth) { | |
1452 ResourceMark rm; | |
1453 uint32_t debug_bits = 0; | |
1454 | |
1455 if (!JvmtiEnv::is_thread_fully_suspended(java_thread, true, &debug_bits)) { | |
1456 return JVMTI_ERROR_THREAD_NOT_SUSPENDED; | |
1457 } | |
1458 | |
1459 if (TraceJVMTICalls) { | |
1460 JvmtiSuspendControl::print(); | |
1461 } | |
1462 | |
1463 vframe *vf = vframeFor(java_thread, depth); | |
1464 if (vf == NULL) { | |
1465 return JVMTI_ERROR_NO_MORE_FRAMES; | |
1466 } | |
1467 | |
1468 if (!vf->is_java_frame() || ((javaVFrame*) vf)->method()->is_native()) { | |
1469 return JVMTI_ERROR_OPAQUE_FRAME; | |
1470 } | |
1471 | |
1472 assert(vf->frame_pointer() != NULL, "frame pointer mustn't be NULL"); | |
1473 | |
1474 JvmtiThreadState *state = JvmtiThreadState::state_for(java_thread); | |
1475 int frame_number = state->count_frames() - depth; | |
1476 state->env_thread_state(this)->set_frame_pop(frame_number); | |
1477 | |
1478 return JVMTI_ERROR_NONE; | |
1479 } /* end NotifyFramePop */ | |
1480 | |
1481 | |
1482 // | |
1483 // Force Early Return functions | |
1484 // | |
1485 | |
1486 // Threads_lock NOT held, java_thread not protected by lock | |
1487 // java_thread - pre-checked | |
1488 jvmtiError | |
1489 JvmtiEnv::ForceEarlyReturnObject(JavaThread* java_thread, jobject value) { | |
1490 jvalue val; | |
1491 val.l = value; | |
1492 return force_early_return(java_thread, val, atos); | |
1493 } /* end ForceEarlyReturnObject */ | |
1494 | |
1495 | |
1496 // Threads_lock NOT held, java_thread not protected by lock | |
1497 // java_thread - pre-checked | |
1498 jvmtiError | |
1499 JvmtiEnv::ForceEarlyReturnInt(JavaThread* java_thread, jint value) { | |
1500 jvalue val; | |
1501 val.i = value; | |
1502 return force_early_return(java_thread, val, itos); | |
1503 } /* end ForceEarlyReturnInt */ | |
1504 | |
1505 | |
1506 // Threads_lock NOT held, java_thread not protected by lock | |
1507 // java_thread - pre-checked | |
1508 jvmtiError | |
1509 JvmtiEnv::ForceEarlyReturnLong(JavaThread* java_thread, jlong value) { | |
1510 jvalue val; | |
1511 val.j = value; | |
1512 return force_early_return(java_thread, val, ltos); | |
1513 } /* end ForceEarlyReturnLong */ | |
1514 | |
1515 | |
1516 // Threads_lock NOT held, java_thread not protected by lock | |
1517 // java_thread - pre-checked | |
1518 jvmtiError | |
1519 JvmtiEnv::ForceEarlyReturnFloat(JavaThread* java_thread, jfloat value) { | |
1520 jvalue val; | |
1521 val.f = value; | |
1522 return force_early_return(java_thread, val, ftos); | |
1523 } /* end ForceEarlyReturnFloat */ | |
1524 | |
1525 | |
1526 // Threads_lock NOT held, java_thread not protected by lock | |
1527 // java_thread - pre-checked | |
1528 jvmtiError | |
1529 JvmtiEnv::ForceEarlyReturnDouble(JavaThread* java_thread, jdouble value) { | |
1530 jvalue val; | |
1531 val.d = value; | |
1532 return force_early_return(java_thread, val, dtos); | |
1533 } /* end ForceEarlyReturnDouble */ | |
1534 | |
1535 | |
1536 // Threads_lock NOT held, java_thread not protected by lock | |
1537 // java_thread - pre-checked | |
1538 jvmtiError | |
1539 JvmtiEnv::ForceEarlyReturnVoid(JavaThread* java_thread) { | |
1540 jvalue val; | |
1541 val.j = 0L; | |
1542 return force_early_return(java_thread, val, vtos); | |
1543 } /* end ForceEarlyReturnVoid */ | |
1544 | |
1545 | |
1546 // | |
1547 // Heap functions | |
1548 // | |
1549 | |
1550 // klass - NULL is a valid value, must be checked | |
1551 // initial_object - NULL is a valid value, must be checked | |
1552 // callbacks - pre-checked for NULL | |
1553 // user_data - NULL is a valid value, must be checked | |
1554 jvmtiError | |
1555 JvmtiEnv::FollowReferences(jint heap_filter, jclass klass, jobject initial_object, const jvmtiHeapCallbacks* callbacks, const void* user_data) { | |
1556 // check klass if provided | |
1557 klassOop k_oop = NULL; | |
1558 if (klass != NULL) { | |
1559 oop k_mirror = JNIHandles::resolve_external_guard(klass); | |
1560 if (k_mirror == NULL) { | |
1561 return JVMTI_ERROR_INVALID_CLASS; | |
1562 } | |
1563 if (java_lang_Class::is_primitive(k_mirror)) { | |
1564 return JVMTI_ERROR_NONE; | |
1565 } | |
1566 k_oop = java_lang_Class::as_klassOop(k_mirror); | |
1567 if (k_oop == NULL) { | |
1568 return JVMTI_ERROR_INVALID_CLASS; | |
1569 } | |
1570 } | |
1571 | |
1572 Thread *thread = Thread::current(); | |
1573 HandleMark hm(thread); | |
1574 KlassHandle kh (thread, k_oop); | |
1575 | |
1576 TraceTime t("FollowReferences", TraceJVMTIObjectTagging); | |
1577 JvmtiTagMap::tag_map_for(this)->follow_references(heap_filter, kh, initial_object, callbacks, user_data); | |
1578 return JVMTI_ERROR_NONE; | |
1579 } /* end FollowReferences */ | |
1580 | |
1581 | |
1582 // klass - NULL is a valid value, must be checked | |
1583 // callbacks - pre-checked for NULL | |
1584 // user_data - NULL is a valid value, must be checked | |
1585 jvmtiError | |
1586 JvmtiEnv::IterateThroughHeap(jint heap_filter, jclass klass, const jvmtiHeapCallbacks* callbacks, const void* user_data) { | |
1587 // check klass if provided | |
1588 klassOop k_oop = NULL; | |
1589 if (klass != NULL) { | |
1590 oop k_mirror = JNIHandles::resolve_external_guard(klass); | |
1591 if (k_mirror == NULL) { | |
1592 return JVMTI_ERROR_INVALID_CLASS; | |
1593 } | |
1594 if (java_lang_Class::is_primitive(k_mirror)) { | |
1595 return JVMTI_ERROR_NONE; | |
1596 } | |
1597 k_oop = java_lang_Class::as_klassOop(k_mirror); | |
1598 if (k_oop == NULL) { | |
1599 return JVMTI_ERROR_INVALID_CLASS; | |
1600 } | |
1601 } | |
1602 | |
1603 Thread *thread = Thread::current(); | |
1604 HandleMark hm(thread); | |
1605 KlassHandle kh (thread, k_oop); | |
1606 | |
1607 TraceTime t("IterateThroughHeap", TraceJVMTIObjectTagging); | |
1608 JvmtiTagMap::tag_map_for(this)->iterate_through_heap(heap_filter, kh, callbacks, user_data); | |
1609 return JVMTI_ERROR_NONE; | |
1610 } /* end IterateThroughHeap */ | |
1611 | |
1612 | |
1613 // tag_ptr - pre-checked for NULL | |
1614 jvmtiError | |
1615 JvmtiEnv::GetTag(jobject object, jlong* tag_ptr) { | |
1616 oop o = JNIHandles::resolve_external_guard(object); | |
1617 NULL_CHECK(o, JVMTI_ERROR_INVALID_OBJECT); | |
1618 *tag_ptr = JvmtiTagMap::tag_map_for(this)->get_tag(object); | |
1619 return JVMTI_ERROR_NONE; | |
1620 } /* end GetTag */ | |
1621 | |
1622 | |
1623 jvmtiError | |
1624 JvmtiEnv::SetTag(jobject object, jlong tag) { | |
1625 oop o = JNIHandles::resolve_external_guard(object); | |
1626 NULL_CHECK(o, JVMTI_ERROR_INVALID_OBJECT); | |
1627 JvmtiTagMap::tag_map_for(this)->set_tag(object, tag); | |
1628 return JVMTI_ERROR_NONE; | |
1629 } /* end SetTag */ | |
1630 | |
1631 | |
1632 // tag_count - pre-checked to be greater than or equal to 0 | |
1633 // tags - pre-checked for NULL | |
1634 // count_ptr - pre-checked for NULL | |
1635 // object_result_ptr - NULL is a valid value, must be checked | |
1636 // tag_result_ptr - NULL is a valid value, must be checked | |
1637 jvmtiError | |
1638 JvmtiEnv::GetObjectsWithTags(jint tag_count, const jlong* tags, jint* count_ptr, jobject** object_result_ptr, jlong** tag_result_ptr) { | |
1639 TraceTime t("GetObjectsWithTags", TraceJVMTIObjectTagging); | |
1640 return JvmtiTagMap::tag_map_for(this)->get_objects_with_tags((jlong*)tags, tag_count, count_ptr, object_result_ptr, tag_result_ptr); | |
1641 } /* end GetObjectsWithTags */ | |
1642 | |
1643 | |
1644 jvmtiError | |
1645 JvmtiEnv::ForceGarbageCollection() { | |
1646 Universe::heap()->collect(GCCause::_jvmti_force_gc); | |
1647 return JVMTI_ERROR_NONE; | |
1648 } /* end ForceGarbageCollection */ | |
1649 | |
1650 | |
1651 // | |
1652 // Heap (1.0) functions | |
1653 // | |
1654 | |
1655 // object_reference_callback - pre-checked for NULL | |
1656 // user_data - NULL is a valid value, must be checked | |
1657 jvmtiError | |
1658 JvmtiEnv::IterateOverObjectsReachableFromObject(jobject object, jvmtiObjectReferenceCallback object_reference_callback, const void* user_data) { | |
1659 oop o = JNIHandles::resolve_external_guard(object); | |
1660 NULL_CHECK(o, JVMTI_ERROR_INVALID_OBJECT); | |
1661 JvmtiTagMap::tag_map_for(this)->iterate_over_objects_reachable_from_object(object, object_reference_callback, user_data); | |
1662 return JVMTI_ERROR_NONE; | |
1663 } /* end IterateOverObjectsReachableFromObject */ | |
1664 | |
1665 | |
1666 // heap_root_callback - NULL is a valid value, must be checked | |
1667 // stack_ref_callback - NULL is a valid value, must be checked | |
1668 // object_ref_callback - NULL is a valid value, must be checked | |
1669 // user_data - NULL is a valid value, must be checked | |
1670 jvmtiError | |
1671 JvmtiEnv::IterateOverReachableObjects(jvmtiHeapRootCallback heap_root_callback, jvmtiStackReferenceCallback stack_ref_callback, jvmtiObjectReferenceCallback object_ref_callback, const void* user_data) { | |
1672 TraceTime t("IterateOverReachableObjects", TraceJVMTIObjectTagging); | |
1673 JvmtiTagMap::tag_map_for(this)->iterate_over_reachable_objects(heap_root_callback, stack_ref_callback, object_ref_callback, user_data); | |
1674 return JVMTI_ERROR_NONE; | |
1675 } /* end IterateOverReachableObjects */ | |
1676 | |
1677 | |
1678 // heap_object_callback - pre-checked for NULL | |
1679 // user_data - NULL is a valid value, must be checked | |
1680 jvmtiError | |
1681 JvmtiEnv::IterateOverHeap(jvmtiHeapObjectFilter object_filter, jvmtiHeapObjectCallback heap_object_callback, const void* user_data) { | |
1682 TraceTime t("IterateOverHeap", TraceJVMTIObjectTagging); | |
1683 Thread *thread = Thread::current(); | |
1684 HandleMark hm(thread); | |
1685 JvmtiTagMap::tag_map_for(this)->iterate_over_heap(object_filter, KlassHandle(), heap_object_callback, user_data); | |
1686 return JVMTI_ERROR_NONE; | |
1687 } /* end IterateOverHeap */ | |
1688 | |
1689 | |
1690 // k_mirror - may be primitive, this must be checked | |
1691 // heap_object_callback - pre-checked for NULL | |
1692 // user_data - NULL is a valid value, must be checked | |
1693 jvmtiError | |
1694 JvmtiEnv::IterateOverInstancesOfClass(oop k_mirror, jvmtiHeapObjectFilter object_filter, jvmtiHeapObjectCallback heap_object_callback, const void* user_data) { | |
1695 if (java_lang_Class::is_primitive(k_mirror)) { | |
1696 // DO PRIMITIVE CLASS PROCESSING | |
1697 return JVMTI_ERROR_NONE; | |
1698 } | |
1699 klassOop k_oop = java_lang_Class::as_klassOop(k_mirror); | |
1700 if (k_oop == NULL) { | |
1701 return JVMTI_ERROR_INVALID_CLASS; | |
1702 } | |
1703 Thread *thread = Thread::current(); | |
1704 HandleMark hm(thread); | |
1705 KlassHandle klass (thread, k_oop); | |
1706 TraceTime t("IterateOverInstancesOfClass", TraceJVMTIObjectTagging); | |
1707 JvmtiTagMap::tag_map_for(this)->iterate_over_heap(object_filter, klass, heap_object_callback, user_data); | |
1708 return JVMTI_ERROR_NONE; | |
1709 } /* end IterateOverInstancesOfClass */ | |
1710 | |
1711 | |
1712 // | |
1713 // Local Variable functions | |
1714 // | |
1715 | |
1716 // Threads_lock NOT held, java_thread not protected by lock | |
1717 // java_thread - pre-checked | |
1718 // java_thread - unchecked | |
1719 // depth - pre-checked as non-negative | |
1720 // value_ptr - pre-checked for NULL | |
1721 jvmtiError | |
1722 JvmtiEnv::GetLocalObject(JavaThread* java_thread, jint depth, jint slot, jobject* value_ptr) { | |
1723 JavaThread* current_thread = JavaThread::current(); | |
1724 // rm object is created to clean up the javaVFrame created in | |
1725 // doit_prologue(), but after doit() is finished with it. | |
1726 ResourceMark rm(current_thread); | |
1727 | |
1728 VM_GetOrSetLocal op(java_thread, current_thread, depth, slot); | |
1729 VMThread::execute(&op); | |
1730 jvmtiError err = op.result(); | |
1731 if (err != JVMTI_ERROR_NONE) { | |
1732 return err; | |
1733 } else { | |
1734 *value_ptr = op.value().l; | |
1735 return JVMTI_ERROR_NONE; | |
1736 } | |
1737 } /* end GetLocalObject */ | |
1738 | |
1739 | |
1740 // Threads_lock NOT held, java_thread not protected by lock | |
1741 // java_thread - pre-checked | |
1742 // java_thread - unchecked | |
1743 // depth - pre-checked as non-negative | |
1744 // value_ptr - pre-checked for NULL | |
1745 jvmtiError | |
1746 JvmtiEnv::GetLocalInt(JavaThread* java_thread, jint depth, jint slot, jint* value_ptr) { | |
1747 // rm object is created to clean up the javaVFrame created in | |
1748 // doit_prologue(), but after doit() is finished with it. | |
1749 ResourceMark rm; | |
1750 | |
1751 VM_GetOrSetLocal op(java_thread, depth, slot, T_INT); | |
1752 VMThread::execute(&op); | |
1753 *value_ptr = op.value().i; | |
1754 return op.result(); | |
1755 } /* end GetLocalInt */ | |
1756 | |
1757 | |
1758 // Threads_lock NOT held, java_thread not protected by lock | |
1759 // java_thread - pre-checked | |
1760 // java_thread - unchecked | |
1761 // depth - pre-checked as non-negative | |
1762 // value_ptr - pre-checked for NULL | |
1763 jvmtiError | |
1764 JvmtiEnv::GetLocalLong(JavaThread* java_thread, jint depth, jint slot, jlong* value_ptr) { | |
1765 // rm object is created to clean up the javaVFrame created in | |
1766 // doit_prologue(), but after doit() is finished with it. | |
1767 ResourceMark rm; | |
1768 | |
1769 VM_GetOrSetLocal op(java_thread, depth, slot, T_LONG); | |
1770 VMThread::execute(&op); | |
1771 *value_ptr = op.value().j; | |
1772 return op.result(); | |
1773 } /* end GetLocalLong */ | |
1774 | |
1775 | |
1776 // Threads_lock NOT held, java_thread not protected by lock | |
1777 // java_thread - pre-checked | |
1778 // java_thread - unchecked | |
1779 // depth - pre-checked as non-negative | |
1780 // value_ptr - pre-checked for NULL | |
1781 jvmtiError | |
1782 JvmtiEnv::GetLocalFloat(JavaThread* java_thread, jint depth, jint slot, jfloat* value_ptr) { | |
1783 // rm object is created to clean up the javaVFrame created in | |
1784 // doit_prologue(), but after doit() is finished with it. | |
1785 ResourceMark rm; | |
1786 | |
1787 VM_GetOrSetLocal op(java_thread, depth, slot, T_FLOAT); | |
1788 VMThread::execute(&op); | |
1789 *value_ptr = op.value().f; | |
1790 return op.result(); | |
1791 } /* end GetLocalFloat */ | |
1792 | |
1793 | |
1794 // Threads_lock NOT held, java_thread not protected by lock | |
1795 // java_thread - pre-checked | |
1796 // java_thread - unchecked | |
1797 // depth - pre-checked as non-negative | |
1798 // value_ptr - pre-checked for NULL | |
1799 jvmtiError | |
1800 JvmtiEnv::GetLocalDouble(JavaThread* java_thread, jint depth, jint slot, jdouble* value_ptr) { | |
1801 // rm object is created to clean up the javaVFrame created in | |
1802 // doit_prologue(), but after doit() is finished with it. | |
1803 ResourceMark rm; | |
1804 | |
1805 VM_GetOrSetLocal op(java_thread, depth, slot, T_DOUBLE); | |
1806 VMThread::execute(&op); | |
1807 *value_ptr = op.value().d; | |
1808 return op.result(); | |
1809 } /* end GetLocalDouble */ | |
1810 | |
1811 | |
1812 // Threads_lock NOT held, java_thread not protected by lock | |
1813 // java_thread - pre-checked | |
1814 // java_thread - unchecked | |
1815 // depth - pre-checked as non-negative | |
1816 jvmtiError | |
1817 JvmtiEnv::SetLocalObject(JavaThread* java_thread, jint depth, jint slot, jobject value) { | |
1818 // rm object is created to clean up the javaVFrame created in | |
1819 // doit_prologue(), but after doit() is finished with it. | |
1820 ResourceMark rm; | |
1821 jvalue val; | |
1822 val.l = value; | |
1823 VM_GetOrSetLocal op(java_thread, depth, slot, T_OBJECT, val); | |
1824 VMThread::execute(&op); | |
1825 return op.result(); | |
1826 } /* end SetLocalObject */ | |
1827 | |
1828 | |
1829 // Threads_lock NOT held, java_thread not protected by lock | |
1830 // java_thread - pre-checked | |
1831 // java_thread - unchecked | |
1832 // depth - pre-checked as non-negative | |
1833 jvmtiError | |
1834 JvmtiEnv::SetLocalInt(JavaThread* java_thread, jint depth, jint slot, jint value) { | |
1835 // rm object is created to clean up the javaVFrame created in | |
1836 // doit_prologue(), but after doit() is finished with it. | |
1837 ResourceMark rm; | |
1838 jvalue val; | |
1839 val.i = value; | |
1840 VM_GetOrSetLocal op(java_thread, depth, slot, T_INT, val); | |
1841 VMThread::execute(&op); | |
1842 return op.result(); | |
1843 } /* end SetLocalInt */ | |
1844 | |
1845 | |
1846 // Threads_lock NOT held, java_thread not protected by lock | |
1847 // java_thread - pre-checked | |
1848 // java_thread - unchecked | |
1849 // depth - pre-checked as non-negative | |
1850 jvmtiError | |
1851 JvmtiEnv::SetLocalLong(JavaThread* java_thread, jint depth, jint slot, jlong value) { | |
1852 // rm object is created to clean up the javaVFrame created in | |
1853 // doit_prologue(), but after doit() is finished with it. | |
1854 ResourceMark rm; | |
1855 jvalue val; | |
1856 val.j = value; | |
1857 VM_GetOrSetLocal op(java_thread, depth, slot, T_LONG, val); | |
1858 VMThread::execute(&op); | |
1859 return op.result(); | |
1860 } /* end SetLocalLong */ | |
1861 | |
1862 | |
1863 // Threads_lock NOT held, java_thread not protected by lock | |
1864 // java_thread - pre-checked | |
1865 // java_thread - unchecked | |
1866 // depth - pre-checked as non-negative | |
1867 jvmtiError | |
1868 JvmtiEnv::SetLocalFloat(JavaThread* java_thread, jint depth, jint slot, jfloat value) { | |
1869 // rm object is created to clean up the javaVFrame created in | |
1870 // doit_prologue(), but after doit() is finished with it. | |
1871 ResourceMark rm; | |
1872 jvalue val; | |
1873 val.f = value; | |
1874 VM_GetOrSetLocal op(java_thread, depth, slot, T_FLOAT, val); | |
1875 VMThread::execute(&op); | |
1876 return op.result(); | |
1877 } /* end SetLocalFloat */ | |
1878 | |
1879 | |
1880 // Threads_lock NOT held, java_thread not protected by lock | |
1881 // java_thread - pre-checked | |
1882 // java_thread - unchecked | |
1883 // depth - pre-checked as non-negative | |
1884 jvmtiError | |
1885 JvmtiEnv::SetLocalDouble(JavaThread* java_thread, jint depth, jint slot, jdouble value) { | |
1886 // rm object is created to clean up the javaVFrame created in | |
1887 // doit_prologue(), but after doit() is finished with it. | |
1888 ResourceMark rm; | |
1889 jvalue val; | |
1890 val.d = value; | |
1891 VM_GetOrSetLocal op(java_thread, depth, slot, T_DOUBLE, val); | |
1892 VMThread::execute(&op); | |
1893 return op.result(); | |
1894 } /* end SetLocalDouble */ | |
1895 | |
1896 | |
1897 // | |
1898 // Breakpoint functions | |
1899 // | |
1900 | |
1901 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method | |
1902 jvmtiError | |
1903 JvmtiEnv::SetBreakpoint(methodOop method_oop, jlocation location) { | |
1904 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID); | |
1905 if (location < 0) { // simple invalid location check first | |
1906 return JVMTI_ERROR_INVALID_LOCATION; | |
1907 } | |
1908 // verify that the breakpoint is not past the end of the method | |
1909 if (location >= (jlocation) method_oop->code_size()) { | |
1910 return JVMTI_ERROR_INVALID_LOCATION; | |
1911 } | |
1912 | |
1913 ResourceMark rm; | |
1914 JvmtiBreakpoint bp(method_oop, location); | |
1915 JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints(); | |
1916 if (jvmti_breakpoints.set(bp) == JVMTI_ERROR_DUPLICATE) | |
1917 return JVMTI_ERROR_DUPLICATE; | |
1918 | |
1919 if (TraceJVMTICalls) { | |
1920 jvmti_breakpoints.print(); | |
1921 } | |
1922 | |
1923 return JVMTI_ERROR_NONE; | |
1924 } /* end SetBreakpoint */ | |
1925 | |
1926 | |
1927 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method | |
1928 jvmtiError | |
1929 JvmtiEnv::ClearBreakpoint(methodOop method_oop, jlocation location) { | |
1930 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID); | |
1931 | |
1932 if (location < 0) { // simple invalid location check first | |
1933 return JVMTI_ERROR_INVALID_LOCATION; | |
1934 } | |
1935 | |
1936 // verify that the breakpoint is not past the end of the method | |
1937 if (location >= (jlocation) method_oop->code_size()) { | |
1938 return JVMTI_ERROR_INVALID_LOCATION; | |
1939 } | |
1940 | |
1941 JvmtiBreakpoint bp(method_oop, location); | |
1942 | |
1943 JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints(); | |
1944 if (jvmti_breakpoints.clear(bp) == JVMTI_ERROR_NOT_FOUND) | |
1945 return JVMTI_ERROR_NOT_FOUND; | |
1946 | |
1947 if (TraceJVMTICalls) { | |
1948 jvmti_breakpoints.print(); | |
1949 } | |
1950 | |
1951 return JVMTI_ERROR_NONE; | |
1952 } /* end ClearBreakpoint */ | |
1953 | |
1954 | |
1955 // | |
1956 // Watched Field functions | |
1957 // | |
1958 | |
1959 jvmtiError | |
1960 JvmtiEnv::SetFieldAccessWatch(fieldDescriptor* fdesc_ptr) { | |
1961 // make sure we haven't set this watch before | |
1962 if (fdesc_ptr->is_field_access_watched()) return JVMTI_ERROR_DUPLICATE; | |
1963 fdesc_ptr->set_is_field_access_watched(true); | |
1964 update_klass_field_access_flag(fdesc_ptr); | |
1965 | |
1966 JvmtiEventController::change_field_watch(JVMTI_EVENT_FIELD_ACCESS, true); | |
1967 | |
1968 return JVMTI_ERROR_NONE; | |
1969 } /* end SetFieldAccessWatch */ | |
1970 | |
1971 | |
1972 jvmtiError | |
1973 JvmtiEnv::ClearFieldAccessWatch(fieldDescriptor* fdesc_ptr) { | |
1974 // make sure we have a watch to clear | |
1975 if (!fdesc_ptr->is_field_access_watched()) return JVMTI_ERROR_NOT_FOUND; | |
1976 fdesc_ptr->set_is_field_access_watched(false); | |
1977 update_klass_field_access_flag(fdesc_ptr); | |
1978 | |
1979 JvmtiEventController::change_field_watch(JVMTI_EVENT_FIELD_ACCESS, false); | |
1980 | |
1981 return JVMTI_ERROR_NONE; | |
1982 } /* end ClearFieldAccessWatch */ | |
1983 | |
1984 | |
1985 jvmtiError | |
1986 JvmtiEnv::SetFieldModificationWatch(fieldDescriptor* fdesc_ptr) { | |
1987 // make sure we haven't set this watch before | |
1988 if (fdesc_ptr->is_field_modification_watched()) return JVMTI_ERROR_DUPLICATE; | |
1989 fdesc_ptr->set_is_field_modification_watched(true); | |
1990 update_klass_field_access_flag(fdesc_ptr); | |
1991 | |
1992 JvmtiEventController::change_field_watch(JVMTI_EVENT_FIELD_MODIFICATION, true); | |
1993 | |
1994 return JVMTI_ERROR_NONE; | |
1995 } /* end SetFieldModificationWatch */ | |
1996 | |
1997 | |
1998 jvmtiError | |
1999 JvmtiEnv::ClearFieldModificationWatch(fieldDescriptor* fdesc_ptr) { | |
2000 // make sure we have a watch to clear | |
2001 if (!fdesc_ptr->is_field_modification_watched()) return JVMTI_ERROR_NOT_FOUND; | |
2002 fdesc_ptr->set_is_field_modification_watched(false); | |
2003 update_klass_field_access_flag(fdesc_ptr); | |
2004 | |
2005 JvmtiEventController::change_field_watch(JVMTI_EVENT_FIELD_MODIFICATION, false); | |
2006 | |
2007 return JVMTI_ERROR_NONE; | |
2008 } /* end ClearFieldModificationWatch */ | |
2009 | |
2010 // | |
2011 // Class functions | |
2012 // | |
2013 | |
2014 | |
2015 // k_mirror - may be primitive, this must be checked | |
2016 // signature_ptr - NULL is a valid value, must be checked | |
2017 // generic_ptr - NULL is a valid value, must be checked | |
2018 jvmtiError | |
2019 JvmtiEnv::GetClassSignature(oop k_mirror, char** signature_ptr, char** generic_ptr) { | |
2020 ResourceMark rm; | |
2021 bool isPrimitive = java_lang_Class::is_primitive(k_mirror); | |
2022 klassOop k = NULL; | |
2023 if (!isPrimitive) { | |
2024 k = java_lang_Class::as_klassOop(k_mirror); | |
2025 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS); | |
2026 } | |
2027 if (signature_ptr != NULL) { | |
2028 char* result = NULL; | |
2029 if (isPrimitive) { | |
2030 char tchar = type2char(java_lang_Class::primitive_type(k_mirror)); | |
2031 result = (char*) jvmtiMalloc(2); | |
2032 result[0] = tchar; | |
2033 result[1] = '\0'; | |
2034 } else { | |
2035 const char* class_sig = Klass::cast(k)->signature_name(); | |
2036 result = (char *) jvmtiMalloc(strlen(class_sig)+1); | |
2037 strcpy(result, class_sig); | |
2038 } | |
2039 *signature_ptr = result; | |
2040 } | |
2041 if (generic_ptr != NULL) { | |
2042 *generic_ptr = NULL; | |
2043 if (!isPrimitive && Klass::cast(k)->oop_is_instance()) { | |
2044 symbolOop soo = instanceKlass::cast(k)->generic_signature(); | |
2045 if (soo != NULL) { | |
2046 const char *gen_sig = soo->as_C_string(); | |
2047 if (gen_sig != NULL) { | |
2048 char* gen_result; | |
2049 jvmtiError err = allocate(strlen(gen_sig) + 1, | |
2050 (unsigned char **)&gen_result); | |
2051 if (err != JVMTI_ERROR_NONE) { | |
2052 return err; | |
2053 } | |
2054 strcpy(gen_result, gen_sig); | |
2055 *generic_ptr = gen_result; | |
2056 } | |
2057 } | |
2058 } | |
2059 } | |
2060 return JVMTI_ERROR_NONE; | |
2061 } /* end GetClassSignature */ | |
2062 | |
2063 | |
2064 // k_mirror - may be primitive, this must be checked | |
2065 // status_ptr - pre-checked for NULL | |
2066 jvmtiError | |
2067 JvmtiEnv::GetClassStatus(oop k_mirror, jint* status_ptr) { | |
2068 jint result = 0; | |
2069 if (java_lang_Class::is_primitive(k_mirror)) { | |
2070 result |= JVMTI_CLASS_STATUS_PRIMITIVE; | |
2071 } else { | |
2072 klassOop k = java_lang_Class::as_klassOop(k_mirror); | |
2073 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS); | |
2074 result = Klass::cast(k)->jvmti_class_status(); | |
2075 } | |
2076 *status_ptr = result; | |
2077 | |
2078 return JVMTI_ERROR_NONE; | |
2079 } /* end GetClassStatus */ | |
2080 | |
2081 | |
2082 // k_mirror - may be primitive, this must be checked | |
2083 // source_name_ptr - pre-checked for NULL | |
2084 jvmtiError | |
2085 JvmtiEnv::GetSourceFileName(oop k_mirror, char** source_name_ptr) { | |
2086 if (java_lang_Class::is_primitive(k_mirror)) { | |
2087 return JVMTI_ERROR_ABSENT_INFORMATION; | |
2088 } | |
2089 klassOop k_klass = java_lang_Class::as_klassOop(k_mirror); | |
2090 NULL_CHECK(k_klass, JVMTI_ERROR_INVALID_CLASS); | |
2091 | |
2092 if (!Klass::cast(k_klass)->oop_is_instance()) { | |
2093 return JVMTI_ERROR_ABSENT_INFORMATION; | |
2094 } | |
2095 | |
2096 symbolOop sfnOop = instanceKlass::cast(k_klass)->source_file_name(); | |
2097 NULL_CHECK(sfnOop, JVMTI_ERROR_ABSENT_INFORMATION); | |
2098 { | |
2099 JavaThread* current_thread = JavaThread::current(); | |
2100 ResourceMark rm(current_thread); | |
2101 const char* sfncp = (const char*) sfnOop->as_C_string(); | |
2102 *source_name_ptr = (char *) jvmtiMalloc(strlen(sfncp)+1); | |
2103 strcpy(*source_name_ptr, sfncp); | |
2104 } | |
2105 | |
2106 return JVMTI_ERROR_NONE; | |
2107 } /* end GetSourceFileName */ | |
2108 | |
2109 | |
2110 // k_mirror - may be primitive, this must be checked | |
2111 // modifiers_ptr - pre-checked for NULL | |
2112 jvmtiError | |
2113 JvmtiEnv::GetClassModifiers(oop k_mirror, jint* modifiers_ptr) { | |
2114 JavaThread* current_thread = JavaThread::current(); | |
2115 jint result = 0; | |
2116 if (!java_lang_Class::is_primitive(k_mirror)) { | |
2117 klassOop k = java_lang_Class::as_klassOop(k_mirror); | |
2118 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS); | |
2119 assert((Klass::cast(k)->oop_is_instance() || Klass::cast(k)->oop_is_array()), "should be an instance or an array klass"); | |
2120 result = Klass::cast(k)->compute_modifier_flags(current_thread); | |
2121 JavaThread* THREAD = current_thread; // pass to macros | |
2122 if (HAS_PENDING_EXCEPTION) { | |
2123 CLEAR_PENDING_EXCEPTION; | |
2124 return JVMTI_ERROR_INTERNAL; | |
2125 }; | |
2126 | |
2127 // Reset the deleted ACC_SUPER bit ( deleted in compute_modifier_flags()). | |
2128 if(Klass::cast(k)->is_super()) { | |
2129 result |= JVM_ACC_SUPER; | |
2130 } | |
2131 } else { | |
2132 result = (JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC); | |
2133 } | |
2134 *modifiers_ptr = result; | |
2135 | |
2136 return JVMTI_ERROR_NONE; | |
2137 } /* end GetClassModifiers */ | |
2138 | |
2139 | |
2140 // k_mirror - may be primitive, this must be checked | |
2141 // method_count_ptr - pre-checked for NULL | |
2142 // methods_ptr - pre-checked for NULL | |
2143 jvmtiError | |
2144 JvmtiEnv::GetClassMethods(oop k_mirror, jint* method_count_ptr, jmethodID** methods_ptr) { | |
2145 JavaThread* current_thread = JavaThread::current(); | |
2146 HandleMark hm(current_thread); | |
2147 | |
2148 if (java_lang_Class::is_primitive(k_mirror)) { | |
2149 *method_count_ptr = 0; | |
2150 *methods_ptr = (jmethodID*) jvmtiMalloc(0 * sizeof(jmethodID)); | |
2151 return JVMTI_ERROR_NONE; | |
2152 } | |
2153 klassOop k = java_lang_Class::as_klassOop(k_mirror); | |
2154 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS); | |
2155 | |
2156 // Return CLASS_NOT_PREPARED error as per JVMTI spec. | |
2157 if (!(Klass::cast(k)->jvmti_class_status() & (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY) )) { | |
2158 return JVMTI_ERROR_CLASS_NOT_PREPARED; | |
2159 } | |
2160 | |
2161 if (!Klass::cast(k)->oop_is_instance()) { | |
2162 *method_count_ptr = 0; | |
2163 *methods_ptr = (jmethodID*) jvmtiMalloc(0 * sizeof(jmethodID)); | |
2164 return JVMTI_ERROR_NONE; | |
2165 } | |
2166 instanceKlassHandle instanceK_h(current_thread, k); | |
2167 // Allocate the result and fill it in | |
2168 int result_length = instanceK_h->methods()->length(); | |
2169 jmethodID* result_list = (jmethodID*)jvmtiMalloc(result_length * sizeof(jmethodID)); | |
2170 int index; | |
2171 if (JvmtiExport::can_maintain_original_method_order()) { | |
2172 // Use the original method ordering indices stored in the class, so we can emit | |
2173 // jmethodIDs in the order they appeared in the class file | |
2174 for (index = 0; index < result_length; index++) { | |
2175 methodOop m = methodOop(instanceK_h->methods()->obj_at(index)); | |
2176 int original_index = instanceK_h->method_ordering()->int_at(index); | |
2177 assert(original_index >= 0 && original_index < result_length, "invalid original method index"); | |
2178 jmethodID id = m->jmethod_id(); | |
2179 result_list[original_index] = id; | |
2180 } | |
2181 } else { | |
2182 // otherwise just copy in any order | |
2183 for (index = 0; index < result_length; index++) { | |
2184 methodOop m = methodOop(instanceK_h->methods()->obj_at(index)); | |
2185 jmethodID id = m->jmethod_id(); | |
2186 result_list[index] = id; | |
2187 } | |
2188 } | |
2189 // Fill in return value. | |
2190 *method_count_ptr = result_length; | |
2191 *methods_ptr = result_list; | |
2192 | |
2193 return JVMTI_ERROR_NONE; | |
2194 } /* end GetClassMethods */ | |
2195 | |
2196 | |
2197 // k_mirror - may be primitive, this must be checked | |
2198 // field_count_ptr - pre-checked for NULL | |
2199 // fields_ptr - pre-checked for NULL | |
2200 jvmtiError | |
2201 JvmtiEnv::GetClassFields(oop k_mirror, jint* field_count_ptr, jfieldID** fields_ptr) { | |
2202 if (java_lang_Class::is_primitive(k_mirror)) { | |
2203 *field_count_ptr = 0; | |
2204 *fields_ptr = (jfieldID*) jvmtiMalloc(0 * sizeof(jfieldID)); | |
2205 return JVMTI_ERROR_NONE; | |
2206 } | |
2207 JavaThread* current_thread = JavaThread::current(); | |
2208 HandleMark hm(current_thread); | |
2209 klassOop k = java_lang_Class::as_klassOop(k_mirror); | |
2210 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS); | |
2211 | |
2212 // Return CLASS_NOT_PREPARED error as per JVMTI spec. | |
2213 if (!(Klass::cast(k)->jvmti_class_status() & (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY) )) { | |
2214 return JVMTI_ERROR_CLASS_NOT_PREPARED; | |
2215 } | |
2216 | |
2217 if (!Klass::cast(k)->oop_is_instance()) { | |
2218 *field_count_ptr = 0; | |
2219 *fields_ptr = (jfieldID*) jvmtiMalloc(0 * sizeof(jfieldID)); | |
2220 return JVMTI_ERROR_NONE; | |
2221 } | |
2222 | |
2223 | |
2224 instanceKlassHandle instanceK_h(current_thread, k); | |
2225 | |
2226 int result_count = 0; | |
2227 // First, count the fields. | |
2228 FilteredFieldStream flds(instanceK_h, true, true); | |
2229 result_count = flds.field_count(); | |
2230 | |
2231 // Allocate the result and fill it in | |
2232 jfieldID* result_list = (jfieldID*) jvmtiMalloc(result_count * sizeof(jfieldID)); | |
2233 // The JVMTI spec requires fields in the order they occur in the class file, | |
2234 // this is the reverse order of what FieldStream hands out. | |
2235 int id_index = (result_count - 1); | |
2236 | |
2237 for (FilteredFieldStream src_st(instanceK_h, true, true); !src_st.eos(); src_st.next()) { | |
2238 result_list[id_index--] = jfieldIDWorkaround::to_jfieldID( | |
2239 instanceK_h, src_st.offset(), | |
2240 src_st.access_flags().is_static()); | |
2241 } | |
2242 assert(id_index == -1, "just checking"); | |
2243 // Fill in the results | |
2244 *field_count_ptr = result_count; | |
2245 *fields_ptr = result_list; | |
2246 | |
2247 return JVMTI_ERROR_NONE; | |
2248 } /* end GetClassFields */ | |
2249 | |
2250 | |
2251 // k_mirror - may be primitive, this must be checked | |
2252 // interface_count_ptr - pre-checked for NULL | |
2253 // interfaces_ptr - pre-checked for NULL | |
2254 jvmtiError | |
2255 JvmtiEnv::GetImplementedInterfaces(oop k_mirror, jint* interface_count_ptr, jclass** interfaces_ptr) { | |
2256 { | |
2257 if (java_lang_Class::is_primitive(k_mirror)) { | |
2258 *interface_count_ptr = 0; | |
2259 *interfaces_ptr = (jclass*) jvmtiMalloc(0 * sizeof(jclass)); | |
2260 return JVMTI_ERROR_NONE; | |
2261 } | |
2262 JavaThread* current_thread = JavaThread::current(); | |
2263 HandleMark hm(current_thread); | |
2264 klassOop k = java_lang_Class::as_klassOop(k_mirror); | |
2265 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS); | |
2266 | |
2267 // Return CLASS_NOT_PREPARED error as per JVMTI spec. | |
2268 if (!(Klass::cast(k)->jvmti_class_status() & (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY) )) | |
2269 return JVMTI_ERROR_CLASS_NOT_PREPARED; | |
2270 | |
2271 if (!Klass::cast(k)->oop_is_instance()) { | |
2272 *interface_count_ptr = 0; | |
2273 *interfaces_ptr = (jclass*) jvmtiMalloc(0 * sizeof(jclass)); | |
2274 return JVMTI_ERROR_NONE; | |
2275 } | |
2276 | |
2277 objArrayHandle interface_list(current_thread, instanceKlass::cast(k)->local_interfaces()); | |
2278 const int result_length = (interface_list.is_null() ? 0 : interface_list->length()); | |
2279 jclass* result_list = (jclass*) jvmtiMalloc(result_length * sizeof(jclass)); | |
2280 for (int i_index = 0; i_index < result_length; i_index += 1) { | |
2281 oop oop_at = interface_list->obj_at(i_index); | |
2282 assert(oop_at->is_klass(), "interfaces must be klassOops"); | |
2283 klassOop klassOop_at = klassOop(oop_at); // ???: is there a better way? | |
2284 assert(Klass::cast(klassOop_at)->is_interface(), "interfaces must be interfaces"); | |
2285 oop mirror_at = Klass::cast(klassOop_at)->java_mirror(); | |
2286 Handle handle_at = Handle(current_thread, mirror_at); | |
2287 result_list[i_index] = (jclass) jni_reference(handle_at); | |
2288 } | |
2289 *interface_count_ptr = result_length; | |
2290 *interfaces_ptr = result_list; | |
2291 } | |
2292 | |
2293 return JVMTI_ERROR_NONE; | |
2294 } /* end GetImplementedInterfaces */ | |
2295 | |
2296 | |
2297 // k_mirror - may be primitive, this must be checked | |
2298 // minor_version_ptr - pre-checked for NULL | |
2299 // major_version_ptr - pre-checked for NULL | |
2300 jvmtiError | |
2301 JvmtiEnv::GetClassVersionNumbers(oop k_mirror, jint* minor_version_ptr, jint* major_version_ptr) { | |
2302 if (java_lang_Class::is_primitive(k_mirror)) { | |
2303 return JVMTI_ERROR_ABSENT_INFORMATION; | |
2304 } | |
2305 klassOop k_oop = java_lang_Class::as_klassOop(k_mirror); | |
2306 Thread *thread = Thread::current(); | |
2307 HandleMark hm(thread); | |
2308 KlassHandle klass(thread, k_oop); | |
2309 | |
2310 jint status = klass->jvmti_class_status(); | |
2311 if (status & (JVMTI_CLASS_STATUS_ERROR)) { | |
2312 return JVMTI_ERROR_INVALID_CLASS; | |
2313 } | |
2314 if (status & (JVMTI_CLASS_STATUS_ARRAY)) { | |
2315 return JVMTI_ERROR_ABSENT_INFORMATION; | |
2316 } | |
2317 | |
2318 instanceKlassHandle ik(thread, k_oop); | |
2319 *minor_version_ptr = ik->minor_version(); | |
2320 *major_version_ptr = ik->major_version(); | |
2321 | |
2322 return JVMTI_ERROR_NONE; | |
2323 } /* end GetClassVersionNumbers */ | |
2324 | |
2325 | |
2326 // k_mirror - may be primitive, this must be checked | |
2327 // constant_pool_count_ptr - pre-checked for NULL | |
2328 // constant_pool_byte_count_ptr - pre-checked for NULL | |
2329 // constant_pool_bytes_ptr - pre-checked for NULL | |
2330 jvmtiError | |
2331 JvmtiEnv::GetConstantPool(oop k_mirror, jint* constant_pool_count_ptr, jint* constant_pool_byte_count_ptr, unsigned char** constant_pool_bytes_ptr) { | |
2332 if (java_lang_Class::is_primitive(k_mirror)) { | |
2333 return JVMTI_ERROR_ABSENT_INFORMATION; | |
2334 } | |
2335 | |
2336 klassOop k_oop = java_lang_Class::as_klassOop(k_mirror); | |
2337 Thread *thread = Thread::current(); | |
2338 HandleMark hm(thread); | |
2339 ResourceMark rm(thread); | |
2340 KlassHandle klass(thread, k_oop); | |
2341 | |
2342 jint status = klass->jvmti_class_status(); | |
2343 if (status & (JVMTI_CLASS_STATUS_ERROR)) { | |
2344 return JVMTI_ERROR_INVALID_CLASS; | |
2345 } | |
2346 if (status & (JVMTI_CLASS_STATUS_ARRAY)) { | |
2347 return JVMTI_ERROR_ABSENT_INFORMATION; | |
2348 } | |
2349 | |
2350 instanceKlassHandle ikh(thread, k_oop); | |
2351 constantPoolHandle constants(thread, ikh->constants()); | |
2352 ObjectLocker ol(constants, thread); // lock constant pool while we query it | |
2353 | |
2354 JvmtiConstantPoolReconstituter reconstituter(ikh); | |
2355 if (reconstituter.get_error() != JVMTI_ERROR_NONE) { | |
2356 return reconstituter.get_error(); | |
2357 } | |
2358 | |
2359 unsigned char *cpool_bytes; | |
2360 int cpool_size = reconstituter.cpool_size(); | |
2361 if (reconstituter.get_error() != JVMTI_ERROR_NONE) { | |
2362 return reconstituter.get_error(); | |
2363 } | |
2364 jvmtiError res = allocate(cpool_size, &cpool_bytes); | |
2365 if (res != JVMTI_ERROR_NONE) { | |
2366 return res; | |
2367 } | |
2368 reconstituter.copy_cpool_bytes(cpool_bytes); | |
2369 if (reconstituter.get_error() != JVMTI_ERROR_NONE) { | |
2370 return reconstituter.get_error(); | |
2371 } | |
2372 | |
2373 *constant_pool_count_ptr = constants->length(); | |
2374 *constant_pool_byte_count_ptr = cpool_size; | |
2375 *constant_pool_bytes_ptr = cpool_bytes; | |
2376 | |
2377 return JVMTI_ERROR_NONE; | |
2378 } /* end GetConstantPool */ | |
2379 | |
2380 | |
2381 // k_mirror - may be primitive, this must be checked | |
2382 // is_interface_ptr - pre-checked for NULL | |
2383 jvmtiError | |
2384 JvmtiEnv::IsInterface(oop k_mirror, jboolean* is_interface_ptr) { | |
2385 { | |
2386 bool result = false; | |
2387 if (!java_lang_Class::is_primitive(k_mirror)) { | |
2388 klassOop k = java_lang_Class::as_klassOop(k_mirror); | |
2389 if (k != NULL && Klass::cast(k)->is_interface()) { | |
2390 result = true; | |
2391 } | |
2392 } | |
2393 *is_interface_ptr = result; | |
2394 } | |
2395 | |
2396 return JVMTI_ERROR_NONE; | |
2397 } /* end IsInterface */ | |
2398 | |
2399 | |
2400 // k_mirror - may be primitive, this must be checked | |
2401 // is_array_class_ptr - pre-checked for NULL | |
2402 jvmtiError | |
2403 JvmtiEnv::IsArrayClass(oop k_mirror, jboolean* is_array_class_ptr) { | |
2404 { | |
2405 bool result = false; | |
2406 if (!java_lang_Class::is_primitive(k_mirror)) { | |
2407 klassOop k = java_lang_Class::as_klassOop(k_mirror); | |
2408 if (k != NULL && Klass::cast(k)->oop_is_array()) { | |
2409 result = true; | |
2410 } | |
2411 } | |
2412 *is_array_class_ptr = result; | |
2413 } | |
2414 | |
2415 return JVMTI_ERROR_NONE; | |
2416 } /* end IsArrayClass */ | |
2417 | |
2418 | |
2419 // k_mirror - may be primitive, this must be checked | |
2420 // classloader_ptr - pre-checked for NULL | |
2421 jvmtiError | |
2422 JvmtiEnv::GetClassLoader(oop k_mirror, jobject* classloader_ptr) { | |
2423 { | |
2424 if (java_lang_Class::is_primitive(k_mirror)) { | |
2425 *classloader_ptr = (jclass) jni_reference(Handle()); | |
2426 return JVMTI_ERROR_NONE; | |
2427 } | |
2428 JavaThread* current_thread = JavaThread::current(); | |
2429 HandleMark hm(current_thread); | |
2430 klassOop k = java_lang_Class::as_klassOop(k_mirror); | |
2431 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS); | |
2432 | |
2433 oop result_oop = Klass::cast(k)->class_loader(); | |
2434 if (result_oop == NULL) { | |
2435 *classloader_ptr = (jclass) jni_reference(Handle()); | |
2436 return JVMTI_ERROR_NONE; | |
2437 } | |
2438 Handle result_handle = Handle(current_thread, result_oop); | |
2439 jclass result_jnihandle = (jclass) jni_reference(result_handle); | |
2440 *classloader_ptr = result_jnihandle; | |
2441 } | |
2442 return JVMTI_ERROR_NONE; | |
2443 } /* end GetClassLoader */ | |
2444 | |
2445 | |
2446 // k_mirror - may be primitive, this must be checked | |
2447 // source_debug_extension_ptr - pre-checked for NULL | |
2448 jvmtiError | |
2449 JvmtiEnv::GetSourceDebugExtension(oop k_mirror, char** source_debug_extension_ptr) { | |
2450 { | |
2451 if (java_lang_Class::is_primitive(k_mirror)) { | |
2452 return JVMTI_ERROR_ABSENT_INFORMATION; | |
2453 } | |
2454 klassOop k = java_lang_Class::as_klassOop(k_mirror); | |
2455 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS); | |
2456 if (!Klass::cast(k)->oop_is_instance()) { | |
2457 return JVMTI_ERROR_ABSENT_INFORMATION; | |
2458 } | |
2459 symbolOop sdeOop = instanceKlass::cast(k)->source_debug_extension(); | |
2460 NULL_CHECK(sdeOop, JVMTI_ERROR_ABSENT_INFORMATION); | |
2461 | |
2462 { | |
2463 JavaThread* current_thread = JavaThread::current(); | |
2464 ResourceMark rm(current_thread); | |
2465 const char* sdecp = (const char*) sdeOop->as_C_string(); | |
2466 *source_debug_extension_ptr = (char *) jvmtiMalloc(strlen(sdecp)+1); | |
2467 strcpy(*source_debug_extension_ptr, sdecp); | |
2468 } | |
2469 } | |
2470 | |
2471 return JVMTI_ERROR_NONE; | |
2472 } /* end GetSourceDebugExtension */ | |
2473 | |
2474 // | |
2475 // Object functions | |
2476 // | |
2477 | |
2478 // hash_code_ptr - pre-checked for NULL | |
2479 jvmtiError | |
2480 JvmtiEnv::GetObjectHashCode(jobject object, jint* hash_code_ptr) { | |
2481 oop mirror = JNIHandles::resolve_external_guard(object); | |
2482 NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT); | |
2483 NULL_CHECK(hash_code_ptr, JVMTI_ERROR_NULL_POINTER); | |
2484 | |
2485 { | |
2486 jint result = (jint) mirror->identity_hash(); | |
2487 *hash_code_ptr = result; | |
2488 } | |
2489 return JVMTI_ERROR_NONE; | |
2490 } /* end GetObjectHashCode */ | |
2491 | |
2492 | |
2493 // info_ptr - pre-checked for NULL | |
2494 jvmtiError | |
2495 JvmtiEnv::GetObjectMonitorUsage(jobject object, jvmtiMonitorUsage* info_ptr) { | |
2496 JavaThread* calling_thread = JavaThread::current(); | |
2497 jvmtiError err = get_object_monitor_usage(calling_thread, object, info_ptr); | |
2498 if (err == JVMTI_ERROR_THREAD_NOT_SUSPENDED) { | |
2499 // Some of the critical threads were not suspended. go to a safepoint and try again | |
2500 VM_GetObjectMonitorUsage op(this, calling_thread, object, info_ptr); | |
2501 VMThread::execute(&op); | |
2502 err = op.result(); | |
2503 } | |
2504 return err; | |
2505 } /* end GetObjectMonitorUsage */ | |
2506 | |
2507 | |
2508 // | |
2509 // Field functions | |
2510 // | |
2511 | |
2512 // name_ptr - NULL is a valid value, must be checked | |
2513 // signature_ptr - NULL is a valid value, must be checked | |
2514 // generic_ptr - NULL is a valid value, must be checked | |
2515 jvmtiError | |
2516 JvmtiEnv::GetFieldName(fieldDescriptor* fdesc_ptr, char** name_ptr, char** signature_ptr, char** generic_ptr) { | |
2517 JavaThread* current_thread = JavaThread::current(); | |
2518 ResourceMark rm(current_thread); | |
2519 if (name_ptr == NULL) { | |
2520 // just don't return the name | |
2521 } else { | |
2522 const char* fieldName = fdesc_ptr->name()->as_C_string(); | |
2523 *name_ptr = (char*) jvmtiMalloc(strlen(fieldName) + 1); | |
2524 if (*name_ptr == NULL) | |
2525 return JVMTI_ERROR_OUT_OF_MEMORY; | |
2526 strcpy(*name_ptr, fieldName); | |
2527 } | |
2528 if (signature_ptr== NULL) { | |
2529 // just don't return the signature | |
2530 } else { | |
2531 const char* fieldSignature = fdesc_ptr->signature()->as_C_string(); | |
2532 *signature_ptr = (char*) jvmtiMalloc(strlen(fieldSignature) + 1); | |
2533 if (*signature_ptr == NULL) | |
2534 return JVMTI_ERROR_OUT_OF_MEMORY; | |
2535 strcpy(*signature_ptr, fieldSignature); | |
2536 } | |
2537 if (generic_ptr != NULL) { | |
2538 *generic_ptr = NULL; | |
2539 symbolOop soop = fdesc_ptr->generic_signature(); | |
2540 if (soop != NULL) { | |
2541 const char* gen_sig = soop->as_C_string(); | |
2542 if (gen_sig != NULL) { | |
2543 jvmtiError err = allocate(strlen(gen_sig) + 1, (unsigned char **)generic_ptr); | |
2544 if (err != JVMTI_ERROR_NONE) { | |
2545 return err; | |
2546 } | |
2547 strcpy(*generic_ptr, gen_sig); | |
2548 } | |
2549 } | |
2550 } | |
2551 return JVMTI_ERROR_NONE; | |
2552 } /* end GetFieldName */ | |
2553 | |
2554 | |
2555 // declaring_class_ptr - pre-checked for NULL | |
2556 jvmtiError | |
2557 JvmtiEnv::GetFieldDeclaringClass(fieldDescriptor* fdesc_ptr, jclass* declaring_class_ptr) { | |
2558 | |
2559 *declaring_class_ptr = get_jni_class_non_null(fdesc_ptr->field_holder()); | |
2560 return JVMTI_ERROR_NONE; | |
2561 } /* end GetFieldDeclaringClass */ | |
2562 | |
2563 | |
2564 // modifiers_ptr - pre-checked for NULL | |
2565 jvmtiError | |
2566 JvmtiEnv::GetFieldModifiers(fieldDescriptor* fdesc_ptr, jint* modifiers_ptr) { | |
2567 | |
2568 AccessFlags resultFlags = fdesc_ptr->access_flags(); | |
2569 jint result = resultFlags.as_int(); | |
2570 *modifiers_ptr = result; | |
2571 | |
2572 return JVMTI_ERROR_NONE; | |
2573 } /* end GetFieldModifiers */ | |
2574 | |
2575 | |
2576 // is_synthetic_ptr - pre-checked for NULL | |
2577 jvmtiError | |
2578 JvmtiEnv::IsFieldSynthetic(fieldDescriptor* fdesc_ptr, jboolean* is_synthetic_ptr) { | |
2579 *is_synthetic_ptr = fdesc_ptr->is_synthetic(); | |
2580 return JVMTI_ERROR_NONE; | |
2581 } /* end IsFieldSynthetic */ | |
2582 | |
2583 | |
2584 // | |
2585 // Method functions | |
2586 // | |
2587 | |
2588 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method | |
2589 // name_ptr - NULL is a valid value, must be checked | |
2590 // signature_ptr - NULL is a valid value, must be checked | |
2591 // generic_ptr - NULL is a valid value, must be checked | |
2592 jvmtiError | |
2593 JvmtiEnv::GetMethodName(methodOop method_oop, char** name_ptr, char** signature_ptr, char** generic_ptr) { | |
2594 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID); | |
2595 JavaThread* current_thread = JavaThread::current(); | |
2596 | |
2597 ResourceMark rm(current_thread); // get the utf8 name and signature | |
2598 if (name_ptr == NULL) { | |
2599 // just don't return the name | |
2600 } else { | |
2601 const char* utf8_name = (const char *) method_oop->name()->as_utf8(); | |
2602 *name_ptr = (char *) jvmtiMalloc(strlen(utf8_name)+1); | |
2603 strcpy(*name_ptr, utf8_name); | |
2604 } | |
2605 if (signature_ptr == NULL) { | |
2606 // just don't return the signature | |
2607 } else { | |
2608 const char* utf8_signature = (const char *) method_oop->signature()->as_utf8(); | |
2609 *signature_ptr = (char *) jvmtiMalloc(strlen(utf8_signature) + 1); | |
2610 strcpy(*signature_ptr, utf8_signature); | |
2611 } | |
2612 | |
2613 if (generic_ptr != NULL) { | |
2614 *generic_ptr = NULL; | |
2615 symbolOop soop = method_oop->generic_signature(); | |
2616 if (soop != NULL) { | |
2617 const char* gen_sig = soop->as_C_string(); | |
2618 if (gen_sig != NULL) { | |
2619 jvmtiError err = allocate(strlen(gen_sig) + 1, (unsigned char **)generic_ptr); | |
2620 if (err != JVMTI_ERROR_NONE) { | |
2621 return err; | |
2622 } | |
2623 strcpy(*generic_ptr, gen_sig); | |
2624 } | |
2625 } | |
2626 } | |
2627 return JVMTI_ERROR_NONE; | |
2628 } /* end GetMethodName */ | |
2629 | |
2630 | |
2631 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method | |
2632 // declaring_class_ptr - pre-checked for NULL | |
2633 jvmtiError | |
2634 JvmtiEnv::GetMethodDeclaringClass(methodOop method_oop, jclass* declaring_class_ptr) { | |
2635 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID); | |
2636 (*declaring_class_ptr) = get_jni_class_non_null(method_oop->method_holder()); | |
2637 return JVMTI_ERROR_NONE; | |
2638 } /* end GetMethodDeclaringClass */ | |
2639 | |
2640 | |
2641 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method | |
2642 // modifiers_ptr - pre-checked for NULL | |
2643 jvmtiError | |
2644 JvmtiEnv::GetMethodModifiers(methodOop method_oop, jint* modifiers_ptr) { | |
2645 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID); | |
2646 (*modifiers_ptr) = method_oop->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS; | |
2647 return JVMTI_ERROR_NONE; | |
2648 } /* end GetMethodModifiers */ | |
2649 | |
2650 | |
2651 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method | |
2652 // max_ptr - pre-checked for NULL | |
2653 jvmtiError | |
2654 JvmtiEnv::GetMaxLocals(methodOop method_oop, jint* max_ptr) { | |
2655 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID); | |
2656 // get max stack | |
2657 (*max_ptr) = method_oop->max_locals(); | |
2658 return JVMTI_ERROR_NONE; | |
2659 } /* end GetMaxLocals */ | |
2660 | |
2661 | |
2662 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method | |
2663 // size_ptr - pre-checked for NULL | |
2664 jvmtiError | |
2665 JvmtiEnv::GetArgumentsSize(methodOop method_oop, jint* size_ptr) { | |
2666 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID); | |
2667 // get size of arguments | |
2668 | |
2669 (*size_ptr) = method_oop->size_of_parameters(); | |
2670 return JVMTI_ERROR_NONE; | |
2671 } /* end GetArgumentsSize */ | |
2672 | |
2673 | |
2674 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method | |
2675 // entry_count_ptr - pre-checked for NULL | |
2676 // table_ptr - pre-checked for NULL | |
2677 jvmtiError | |
2678 JvmtiEnv::GetLineNumberTable(methodOop method_oop, jint* entry_count_ptr, jvmtiLineNumberEntry** table_ptr) { | |
2679 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID); | |
2680 if (!method_oop->has_linenumber_table()) { | |
2681 return (JVMTI_ERROR_ABSENT_INFORMATION); | |
2682 } | |
2683 | |
2684 // The line number table is compressed so we don't know how big it is until decompressed. | |
2685 // Decompression is really fast so we just do it twice. | |
2686 | |
2687 // Compute size of table | |
2688 jint num_entries = 0; | |
2689 CompressedLineNumberReadStream stream(method_oop->compressed_linenumber_table()); | |
2690 while (stream.read_pair()) { | |
2691 num_entries++; | |
2692 } | |
2693 jvmtiLineNumberEntry *jvmti_table = | |
2694 (jvmtiLineNumberEntry *)jvmtiMalloc(num_entries * (sizeof(jvmtiLineNumberEntry))); | |
2695 | |
2696 // Fill jvmti table | |
2697 if (num_entries > 0) { | |
2698 int index = 0; | |
2699 CompressedLineNumberReadStream stream(method_oop->compressed_linenumber_table()); | |
2700 while (stream.read_pair()) { | |
2701 jvmti_table[index].start_location = (jlocation) stream.bci(); | |
2702 jvmti_table[index].line_number = (jint) stream.line(); | |
2703 index++; | |
2704 } | |
2705 assert(index == num_entries, "sanity check"); | |
2706 } | |
2707 | |
2708 // Set up results | |
2709 (*entry_count_ptr) = num_entries; | |
2710 (*table_ptr) = jvmti_table; | |
2711 | |
2712 return JVMTI_ERROR_NONE; | |
2713 } /* end GetLineNumberTable */ | |
2714 | |
2715 | |
2716 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method | |
2717 // start_location_ptr - pre-checked for NULL | |
2718 // end_location_ptr - pre-checked for NULL | |
2719 jvmtiError | |
2720 JvmtiEnv::GetMethodLocation(methodOop method_oop, jlocation* start_location_ptr, jlocation* end_location_ptr) { | |
2721 | |
2722 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID); | |
2723 // get start and end location | |
2724 (*end_location_ptr) = (jlocation) (method_oop->code_size() - 1); | |
2725 if (method_oop->code_size() == 0) { | |
2726 // there is no code so there is no start location | |
2727 (*start_location_ptr) = (jlocation)(-1); | |
2728 } else { | |
2729 (*start_location_ptr) = (jlocation)(0); | |
2730 } | |
2731 | |
2732 return JVMTI_ERROR_NONE; | |
2733 } /* end GetMethodLocation */ | |
2734 | |
2735 | |
2736 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method | |
2737 // entry_count_ptr - pre-checked for NULL | |
2738 // table_ptr - pre-checked for NULL | |
2739 jvmtiError | |
2740 JvmtiEnv::GetLocalVariableTable(methodOop method_oop, jint* entry_count_ptr, jvmtiLocalVariableEntry** table_ptr) { | |
2741 | |
2742 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID); | |
2743 JavaThread* current_thread = JavaThread::current(); | |
2744 | |
2745 // does the klass have any local variable information? | |
2746 instanceKlass* ik = instanceKlass::cast(method_oop->method_holder()); | |
2747 if (!ik->access_flags().has_localvariable_table()) { | |
2748 return (JVMTI_ERROR_ABSENT_INFORMATION); | |
2749 } | |
2750 | |
2751 constantPoolOop constants = method_oop->constants(); | |
2752 NULL_CHECK(constants, JVMTI_ERROR_ABSENT_INFORMATION); | |
2753 | |
2754 // in the vm localvariable table representation, 6 consecutive elements in the table | |
2755 // represent a 6-tuple of shorts | |
2756 // [start_pc, length, name_index, descriptor_index, signature_index, index] | |
2757 jint num_entries = method_oop->localvariable_table_length(); | |
2758 jvmtiLocalVariableEntry *jvmti_table = (jvmtiLocalVariableEntry *) | |
2759 jvmtiMalloc(num_entries * (sizeof(jvmtiLocalVariableEntry))); | |
2760 | |
2761 if (num_entries > 0) { | |
2762 LocalVariableTableElement* table = method_oop->localvariable_table_start(); | |
2763 for (int i = 0; i < num_entries; i++) { | |
2764 // get the 5 tuple information from the vm table | |
2765 jlocation start_location = (jlocation) table[i].start_bci; | |
2766 jint length = (jint) table[i].length; | |
2767 int name_index = (int) table[i].name_cp_index; | |
2768 int signature_index = (int) table[i].descriptor_cp_index; | |
2769 int generic_signature_index = (int) table[i].signature_cp_index; | |
2770 jint slot = (jint) table[i].slot; | |
2771 | |
2772 // get utf8 name and signature | |
2773 char *name_buf = NULL; | |
2774 char *sig_buf = NULL; | |
2775 char *gen_sig_buf = NULL; | |
2776 { | |
2777 ResourceMark rm(current_thread); | |
2778 | |
2779 const char *utf8_name = (const char *) constants->symbol_at(name_index)->as_utf8(); | |
2780 name_buf = (char *) jvmtiMalloc(strlen(utf8_name)+1); | |
2781 strcpy(name_buf, utf8_name); | |
2782 | |
2783 const char *utf8_signature = (const char *) constants->symbol_at(signature_index)->as_utf8(); | |
2784 sig_buf = (char *) jvmtiMalloc(strlen(utf8_signature)+1); | |
2785 strcpy(sig_buf, utf8_signature); | |
2786 | |
2787 if (generic_signature_index > 0) { | |
2788 const char *utf8_gen_sign = (const char *) | |
2789 constants->symbol_at(generic_signature_index)->as_utf8(); | |
2790 gen_sig_buf = (char *) jvmtiMalloc(strlen(utf8_gen_sign)+1); | |
2791 strcpy(gen_sig_buf, utf8_gen_sign); | |
2792 } | |
2793 } | |
2794 | |
2795 // fill in the jvmti local variable table | |
2796 jvmti_table[i].start_location = start_location; | |
2797 jvmti_table[i].length = length; | |
2798 jvmti_table[i].name = name_buf; | |
2799 jvmti_table[i].signature = sig_buf; | |
2800 jvmti_table[i].generic_signature = gen_sig_buf; | |
2801 jvmti_table[i].slot = slot; | |
2802 } | |
2803 } | |
2804 | |
2805 // set results | |
2806 (*entry_count_ptr) = num_entries; | |
2807 (*table_ptr) = jvmti_table; | |
2808 | |
2809 return JVMTI_ERROR_NONE; | |
2810 } /* end GetLocalVariableTable */ | |
2811 | |
2812 | |
2813 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method | |
2814 // bytecode_count_ptr - pre-checked for NULL | |
2815 // bytecodes_ptr - pre-checked for NULL | |
2816 jvmtiError | |
2817 JvmtiEnv::GetBytecodes(methodOop method_oop, jint* bytecode_count_ptr, unsigned char** bytecodes_ptr) { | |
2818 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID); | |
2819 | |
2820 HandleMark hm; | |
2821 methodHandle method(method_oop); | |
2822 jint size = (jint)method->code_size(); | |
2823 jvmtiError err = allocate(size, bytecodes_ptr); | |
2824 if (err != JVMTI_ERROR_NONE) { | |
2825 return err; | |
2826 } | |
2827 | |
2828 (*bytecode_count_ptr) = size; | |
2829 // get byte codes | |
2830 JvmtiClassFileReconstituter::copy_bytecodes(method, *bytecodes_ptr); | |
2831 | |
2832 return JVMTI_ERROR_NONE; | |
2833 } /* end GetBytecodes */ | |
2834 | |
2835 | |
2836 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method | |
2837 // is_native_ptr - pre-checked for NULL | |
2838 jvmtiError | |
2839 JvmtiEnv::IsMethodNative(methodOop method_oop, jboolean* is_native_ptr) { | |
2840 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID); | |
2841 (*is_native_ptr) = method_oop->is_native(); | |
2842 return JVMTI_ERROR_NONE; | |
2843 } /* end IsMethodNative */ | |
2844 | |
2845 | |
2846 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method | |
2847 // is_synthetic_ptr - pre-checked for NULL | |
2848 jvmtiError | |
2849 JvmtiEnv::IsMethodSynthetic(methodOop method_oop, jboolean* is_synthetic_ptr) { | |
2850 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID); | |
2851 (*is_synthetic_ptr) = method_oop->is_synthetic(); | |
2852 return JVMTI_ERROR_NONE; | |
2853 } /* end IsMethodSynthetic */ | |
2854 | |
2855 | |
2856 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method | |
2857 // is_obsolete_ptr - pre-checked for NULL | |
2858 jvmtiError | |
2859 JvmtiEnv::IsMethodObsolete(methodOop method_oop, jboolean* is_obsolete_ptr) { | |
2860 if (method_oop == NULL || method_oop->is_obsolete()) { | |
2861 *is_obsolete_ptr = true; | |
2862 } else { | |
2863 *is_obsolete_ptr = false; | |
2864 } | |
2865 return JVMTI_ERROR_NONE; | |
2866 } /* end IsMethodObsolete */ | |
2867 | |
2868 // | |
2869 // Raw Monitor functions | |
2870 // | |
2871 | |
2872 // name - pre-checked for NULL | |
2873 // monitor_ptr - pre-checked for NULL | |
2874 jvmtiError | |
2875 JvmtiEnv::CreateRawMonitor(const char* name, jrawMonitorID* monitor_ptr) { | |
2876 JvmtiRawMonitor* rmonitor = new JvmtiRawMonitor(name); | |
2877 NULL_CHECK(rmonitor, JVMTI_ERROR_OUT_OF_MEMORY); | |
2878 | |
2879 *monitor_ptr = (jrawMonitorID)rmonitor; | |
2880 | |
2881 return JVMTI_ERROR_NONE; | |
2882 } /* end CreateRawMonitor */ | |
2883 | |
2884 | |
2885 // rmonitor - pre-checked for validity | |
2886 jvmtiError | |
2887 JvmtiEnv::DestroyRawMonitor(JvmtiRawMonitor * rmonitor) { | |
2888 if (Threads::number_of_threads() == 0) { | |
2889 // Remove this monitor from pending raw monitors list | |
2890 // if it has entered in onload or start phase. | |
2891 JvmtiPendingMonitors::destroy(rmonitor); | |
2892 } else { | |
2893 Thread* thread = Thread::current(); | |
2894 if (rmonitor->is_entered(thread)) { | |
2895 // The caller owns this monitor which we are about to destroy. | |
2896 // We exit the underlying synchronization object so that the | |
2897 // "delete monitor" call below can work without an assertion | |
2898 // failure on systems that don't like destroying synchronization | |
2899 // objects that are locked. | |
2900 int r; | |
2901 intptr_t recursion = rmonitor->recursions(); | |
2902 for (intptr_t i=0; i <= recursion; i++) { | |
2903 r = rmonitor->raw_exit(thread); | |
2904 assert(r == ObjectMonitor::OM_OK, "raw_exit should have worked"); | |
2905 if (r != ObjectMonitor::OM_OK) { // robustness | |
2906 return JVMTI_ERROR_INTERNAL; | |
2907 } | |
2908 } | |
2909 } | |
2910 if (rmonitor->owner() != NULL) { | |
2911 // The caller is trying to destroy a monitor that is locked by | |
2912 // someone else. While this is not forbidden by the JVMTI | |
2913 // spec, it will cause an assertion failure on systems that don't | |
2914 // like destroying synchronization objects that are locked. | |
2915 // We indicate a problem with the error return (and leak the | |
2916 // monitor's memory). | |
2917 return JVMTI_ERROR_NOT_MONITOR_OWNER; | |
2918 } | |
2919 } | |
2920 | |
2921 delete rmonitor; | |
2922 | |
2923 return JVMTI_ERROR_NONE; | |
2924 } /* end DestroyRawMonitor */ | |
2925 | |
2926 | |
2927 // rmonitor - pre-checked for validity | |
2928 jvmtiError | |
2929 JvmtiEnv::RawMonitorEnter(JvmtiRawMonitor * rmonitor) { | |
2930 if (Threads::number_of_threads() == 0) { | |
2931 // No JavaThreads exist so ObjectMonitor enter cannot be | |
2932 // used, add this raw monitor to the pending list. | |
2933 // The pending monitors will be actually entered when | |
2934 // the VM is setup. | |
2935 // See transition_pending_raw_monitors in create_vm() | |
2936 // in thread.cpp. | |
2937 JvmtiPendingMonitors::enter(rmonitor); | |
2938 } else { | |
2939 int r; | |
2940 Thread* thread = Thread::current(); | |
2941 | |
2942 if (thread->is_Java_thread()) { | |
2943 JavaThread* current_thread = (JavaThread*)thread; | |
2944 | |
2945 #ifdef PROPER_TRANSITIONS | |
2946 // Not really unknown but ThreadInVMfromNative does more than we want | |
2947 ThreadInVMfromUnknown __tiv; | |
2948 { | |
2949 ThreadBlockInVM __tbivm(current_thread); | |
2950 r = rmonitor->raw_enter(current_thread); | |
2951 } | |
2952 #else | |
2953 /* Transition to thread_blocked without entering vm state */ | |
2954 /* This is really evil. Normally you can't undo _thread_blocked */ | |
2955 /* transitions like this because it would cause us to miss a */ | |
2956 /* safepoint but since the thread was already in _thread_in_native */ | |
2957 /* the thread is not leaving a safepoint safe state and it will */ | |
2958 /* block when it tries to return from native. We can't safepoint */ | |
2959 /* block in here because we could deadlock the vmthread. Blech. */ | |
2960 | |
2961 JavaThreadState state = current_thread->thread_state(); | |
2962 assert(state == _thread_in_native, "Must be _thread_in_native"); | |
2963 // frame should already be walkable since we are in native | |
2964 assert(!current_thread->has_last_Java_frame() || | |
2965 current_thread->frame_anchor()->walkable(), "Must be walkable"); | |
2966 current_thread->set_thread_state(_thread_blocked); | |
2967 | |
2968 r = rmonitor->raw_enter(current_thread); | |
2969 // restore state, still at a safepoint safe state | |
2970 current_thread->set_thread_state(state); | |
2971 | |
2972 #endif /* PROPER_TRANSITIONS */ | |
2973 assert(r == ObjectMonitor::OM_OK, "raw_enter should have worked"); | |
2974 } else { | |
2975 if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) { | |
2976 r = rmonitor->raw_enter(thread); | |
2977 } else { | |
2978 ShouldNotReachHere(); | |
2979 } | |
2980 } | |
2981 | |
2982 if (r != ObjectMonitor::OM_OK) { // robustness | |
2983 return JVMTI_ERROR_INTERNAL; | |
2984 } | |
2985 } | |
2986 return JVMTI_ERROR_NONE; | |
2987 } /* end RawMonitorEnter */ | |
2988 | |
2989 | |
2990 // rmonitor - pre-checked for validity | |
2991 jvmtiError | |
2992 JvmtiEnv::RawMonitorExit(JvmtiRawMonitor * rmonitor) { | |
2993 jvmtiError err = JVMTI_ERROR_NONE; | |
2994 | |
2995 if (Threads::number_of_threads() == 0) { | |
2996 // No JavaThreads exist so just remove this monitor from the pending list. | |
2997 // Bool value from exit is false if rmonitor is not in the list. | |
2998 if (!JvmtiPendingMonitors::exit(rmonitor)) { | |
2999 err = JVMTI_ERROR_NOT_MONITOR_OWNER; | |
3000 } | |
3001 } else { | |
3002 int r; | |
3003 Thread* thread = Thread::current(); | |
3004 | |
3005 if (thread->is_Java_thread()) { | |
3006 JavaThread* current_thread = (JavaThread*)thread; | |
3007 #ifdef PROPER_TRANSITIONS | |
3008 // Not really unknown but ThreadInVMfromNative does more than we want | |
3009 ThreadInVMfromUnknown __tiv; | |
3010 #endif /* PROPER_TRANSITIONS */ | |
3011 r = rmonitor->raw_exit(current_thread); | |
3012 } else { | |
3013 if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) { | |
3014 r = rmonitor->raw_exit(thread); | |
3015 } else { | |
3016 ShouldNotReachHere(); | |
3017 } | |
3018 } | |
3019 | |
3020 if (r == ObjectMonitor::OM_ILLEGAL_MONITOR_STATE) { | |
3021 err = JVMTI_ERROR_NOT_MONITOR_OWNER; | |
3022 } else { | |
3023 assert(r == ObjectMonitor::OM_OK, "raw_exit should have worked"); | |
3024 if (r != ObjectMonitor::OM_OK) { // robustness | |
3025 err = JVMTI_ERROR_INTERNAL; | |
3026 } | |
3027 } | |
3028 } | |
3029 return err; | |
3030 } /* end RawMonitorExit */ | |
3031 | |
3032 | |
3033 // rmonitor - pre-checked for validity | |
3034 jvmtiError | |
3035 JvmtiEnv::RawMonitorWait(JvmtiRawMonitor * rmonitor, jlong millis) { | |
3036 int r; | |
3037 Thread* thread = Thread::current(); | |
3038 | |
3039 if (thread->is_Java_thread()) { | |
3040 JavaThread* current_thread = (JavaThread*)thread; | |
3041 #ifdef PROPER_TRANSITIONS | |
3042 // Not really unknown but ThreadInVMfromNative does more than we want | |
3043 ThreadInVMfromUnknown __tiv; | |
3044 { | |
3045 ThreadBlockInVM __tbivm(current_thread); | |
3046 r = rmonitor->raw_wait(millis, true, current_thread); | |
3047 } | |
3048 #else | |
3049 /* Transition to thread_blocked without entering vm state */ | |
3050 /* This is really evil. Normally you can't undo _thread_blocked */ | |
3051 /* transitions like this because it would cause us to miss a */ | |
3052 /* safepoint but since the thread was already in _thread_in_native */ | |
3053 /* the thread is not leaving a safepoint safe state and it will */ | |
3054 /* block when it tries to return from native. We can't safepoint */ | |
3055 /* block in here because we could deadlock the vmthread. Blech. */ | |
3056 | |
3057 JavaThreadState state = current_thread->thread_state(); | |
3058 assert(state == _thread_in_native, "Must be _thread_in_native"); | |
3059 // frame should already be walkable since we are in native | |
3060 assert(!current_thread->has_last_Java_frame() || | |
3061 current_thread->frame_anchor()->walkable(), "Must be walkable"); | |
3062 current_thread->set_thread_state(_thread_blocked); | |
3063 | |
3064 r = rmonitor->raw_wait(millis, true, current_thread); | |
3065 // restore state, still at a safepoint safe state | |
3066 current_thread->set_thread_state(state); | |
3067 | |
3068 #endif /* PROPER_TRANSITIONS */ | |
3069 } else { | |
3070 if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) { | |
3071 r = rmonitor->raw_wait(millis, true, thread); | |
3072 } else { | |
3073 ShouldNotReachHere(); | |
3074 } | |
3075 } | |
3076 | |
3077 switch (r) { | |
3078 case ObjectMonitor::OM_INTERRUPTED: | |
3079 return JVMTI_ERROR_INTERRUPT; | |
3080 case ObjectMonitor::OM_ILLEGAL_MONITOR_STATE: | |
3081 return JVMTI_ERROR_NOT_MONITOR_OWNER; | |
3082 } | |
3083 assert(r == ObjectMonitor::OM_OK, "raw_wait should have worked"); | |
3084 if (r != ObjectMonitor::OM_OK) { // robustness | |
3085 return JVMTI_ERROR_INTERNAL; | |
3086 } | |
3087 | |
3088 return JVMTI_ERROR_NONE; | |
3089 } /* end RawMonitorWait */ | |
3090 | |
3091 | |
3092 // rmonitor - pre-checked for validity | |
3093 jvmtiError | |
3094 JvmtiEnv::RawMonitorNotify(JvmtiRawMonitor * rmonitor) { | |
3095 int r; | |
3096 Thread* thread = Thread::current(); | |
3097 | |
3098 if (thread->is_Java_thread()) { | |
3099 JavaThread* current_thread = (JavaThread*)thread; | |
3100 // Not really unknown but ThreadInVMfromNative does more than we want | |
3101 ThreadInVMfromUnknown __tiv; | |
3102 r = rmonitor->raw_notify(current_thread); | |
3103 } else { | |
3104 if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) { | |
3105 r = rmonitor->raw_notify(thread); | |
3106 } else { | |
3107 ShouldNotReachHere(); | |
3108 } | |
3109 } | |
3110 | |
3111 if (r == ObjectMonitor::OM_ILLEGAL_MONITOR_STATE) { | |
3112 return JVMTI_ERROR_NOT_MONITOR_OWNER; | |
3113 } | |
3114 assert(r == ObjectMonitor::OM_OK, "raw_notify should have worked"); | |
3115 if (r != ObjectMonitor::OM_OK) { // robustness | |
3116 return JVMTI_ERROR_INTERNAL; | |
3117 } | |
3118 | |
3119 return JVMTI_ERROR_NONE; | |
3120 } /* end RawMonitorNotify */ | |
3121 | |
3122 | |
3123 // rmonitor - pre-checked for validity | |
3124 jvmtiError | |
3125 JvmtiEnv::RawMonitorNotifyAll(JvmtiRawMonitor * rmonitor) { | |
3126 int r; | |
3127 Thread* thread = Thread::current(); | |
3128 | |
3129 if (thread->is_Java_thread()) { | |
3130 JavaThread* current_thread = (JavaThread*)thread; | |
3131 ThreadInVMfromUnknown __tiv; | |
3132 r = rmonitor->raw_notifyAll(current_thread); | |
3133 } else { | |
3134 if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) { | |
3135 r = rmonitor->raw_notifyAll(thread); | |
3136 } else { | |
3137 ShouldNotReachHere(); | |
3138 } | |
3139 } | |
3140 | |
3141 if (r == ObjectMonitor::OM_ILLEGAL_MONITOR_STATE) { | |
3142 return JVMTI_ERROR_NOT_MONITOR_OWNER; | |
3143 } | |
3144 assert(r == ObjectMonitor::OM_OK, "raw_notifyAll should have worked"); | |
3145 if (r != ObjectMonitor::OM_OK) { // robustness | |
3146 return JVMTI_ERROR_INTERNAL; | |
3147 } | |
3148 | |
3149 return JVMTI_ERROR_NONE; | |
3150 } /* end RawMonitorNotifyAll */ | |
3151 | |
3152 | |
3153 // | |
3154 // JNI Function Interception functions | |
3155 // | |
3156 | |
3157 | |
3158 // function_table - pre-checked for NULL | |
3159 jvmtiError | |
3160 JvmtiEnv::SetJNIFunctionTable(const jniNativeInterface* function_table) { | |
3161 // Copy jni function table at safepoint. | |
3162 VM_JNIFunctionTableCopier copier(function_table); | |
3163 VMThread::execute(&copier); | |
3164 | |
3165 return JVMTI_ERROR_NONE; | |
3166 } /* end SetJNIFunctionTable */ | |
3167 | |
3168 | |
3169 // function_table - pre-checked for NULL | |
3170 jvmtiError | |
3171 JvmtiEnv::GetJNIFunctionTable(jniNativeInterface** function_table) { | |
3172 *function_table=(jniNativeInterface*)jvmtiMalloc(sizeof(jniNativeInterface)); | |
3173 if (*function_table == NULL) | |
3174 return JVMTI_ERROR_OUT_OF_MEMORY; | |
3175 memcpy(*function_table,(JavaThread::current())->get_jni_functions(),sizeof(jniNativeInterface)); | |
3176 return JVMTI_ERROR_NONE; | |
3177 } /* end GetJNIFunctionTable */ | |
3178 | |
3179 | |
3180 // | |
3181 // Event Management functions | |
3182 // | |
3183 | |
3184 jvmtiError | |
3185 JvmtiEnv::GenerateEvents(jvmtiEvent event_type) { | |
3186 // can only generate two event types | |
3187 if (event_type != JVMTI_EVENT_COMPILED_METHOD_LOAD && | |
3188 event_type != JVMTI_EVENT_DYNAMIC_CODE_GENERATED) { | |
3189 return JVMTI_ERROR_ILLEGAL_ARGUMENT; | |
3190 } | |
3191 | |
3192 // for compiled_method_load events we must check that the environment | |
3193 // has the can_generate_compiled_method_load_events capability. | |
3194 if (event_type == JVMTI_EVENT_COMPILED_METHOD_LOAD) { | |
3195 if (get_capabilities()->can_generate_compiled_method_load_events == 0) { | |
3196 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY; | |
3197 } | |
3198 return JvmtiCodeBlobEvents::generate_compiled_method_load_events(this); | |
3199 } else { | |
3200 return JvmtiCodeBlobEvents::generate_dynamic_code_events(this); | |
3201 } | |
3202 | |
3203 } /* end GenerateEvents */ | |
3204 | |
3205 | |
3206 // | |
3207 // Extension Mechanism functions | |
3208 // | |
3209 | |
3210 // extension_count_ptr - pre-checked for NULL | |
3211 // extensions - pre-checked for NULL | |
3212 jvmtiError | |
3213 JvmtiEnv::GetExtensionFunctions(jint* extension_count_ptr, jvmtiExtensionFunctionInfo** extensions) { | |
3214 return JvmtiExtensions::get_functions(this, extension_count_ptr, extensions); | |
3215 } /* end GetExtensionFunctions */ | |
3216 | |
3217 | |
3218 // extension_count_ptr - pre-checked for NULL | |
3219 // extensions - pre-checked for NULL | |
3220 jvmtiError | |
3221 JvmtiEnv::GetExtensionEvents(jint* extension_count_ptr, jvmtiExtensionEventInfo** extensions) { | |
3222 return JvmtiExtensions::get_events(this, extension_count_ptr, extensions); | |
3223 } /* end GetExtensionEvents */ | |
3224 | |
3225 | |
3226 // callback - NULL is a valid value, must be checked | |
3227 jvmtiError | |
3228 JvmtiEnv::SetExtensionEventCallback(jint extension_event_index, jvmtiExtensionEvent callback) { | |
3229 return JvmtiExtensions::set_event_callback(this, extension_event_index, callback); | |
3230 } /* end SetExtensionEventCallback */ | |
3231 | |
3232 // | |
3233 // Timers functions | |
3234 // | |
3235 | |
3236 // info_ptr - pre-checked for NULL | |
3237 jvmtiError | |
3238 JvmtiEnv::GetCurrentThreadCpuTimerInfo(jvmtiTimerInfo* info_ptr) { | |
3239 os::current_thread_cpu_time_info(info_ptr); | |
3240 return JVMTI_ERROR_NONE; | |
3241 } /* end GetCurrentThreadCpuTimerInfo */ | |
3242 | |
3243 | |
3244 // nanos_ptr - pre-checked for NULL | |
3245 jvmtiError | |
3246 JvmtiEnv::GetCurrentThreadCpuTime(jlong* nanos_ptr) { | |
3247 *nanos_ptr = os::current_thread_cpu_time(); | |
3248 return JVMTI_ERROR_NONE; | |
3249 } /* end GetCurrentThreadCpuTime */ | |
3250 | |
3251 | |
3252 // info_ptr - pre-checked for NULL | |
3253 jvmtiError | |
3254 JvmtiEnv::GetThreadCpuTimerInfo(jvmtiTimerInfo* info_ptr) { | |
3255 os::thread_cpu_time_info(info_ptr); | |
3256 return JVMTI_ERROR_NONE; | |
3257 } /* end GetThreadCpuTimerInfo */ | |
3258 | |
3259 | |
3260 // Threads_lock NOT held, java_thread not protected by lock | |
3261 // java_thread - pre-checked | |
3262 // nanos_ptr - pre-checked for NULL | |
3263 jvmtiError | |
3264 JvmtiEnv::GetThreadCpuTime(JavaThread* java_thread, jlong* nanos_ptr) { | |
3265 *nanos_ptr = os::thread_cpu_time(java_thread); | |
3266 return JVMTI_ERROR_NONE; | |
3267 } /* end GetThreadCpuTime */ | |
3268 | |
3269 | |
3270 // info_ptr - pre-checked for NULL | |
3271 jvmtiError | |
3272 JvmtiEnv::GetTimerInfo(jvmtiTimerInfo* info_ptr) { | |
3273 os::javaTimeNanos_info(info_ptr); | |
3274 return JVMTI_ERROR_NONE; | |
3275 } /* end GetTimerInfo */ | |
3276 | |
3277 | |
3278 // nanos_ptr - pre-checked for NULL | |
3279 jvmtiError | |
3280 JvmtiEnv::GetTime(jlong* nanos_ptr) { | |
3281 *nanos_ptr = os::javaTimeNanos(); | |
3282 return JVMTI_ERROR_NONE; | |
3283 } /* end GetTime */ | |
3284 | |
3285 | |
3286 // processor_count_ptr - pre-checked for NULL | |
3287 jvmtiError | |
3288 JvmtiEnv::GetAvailableProcessors(jint* processor_count_ptr) { | |
3289 *processor_count_ptr = os::active_processor_count(); | |
3290 return JVMTI_ERROR_NONE; | |
3291 } /* end GetAvailableProcessors */ | |
3292 | |
3293 // | |
3294 // System Properties functions | |
3295 // | |
3296 | |
3297 // count_ptr - pre-checked for NULL | |
3298 // property_ptr - pre-checked for NULL | |
3299 jvmtiError | |
3300 JvmtiEnv::GetSystemProperties(jint* count_ptr, char*** property_ptr) { | |
3301 jvmtiError err = JVMTI_ERROR_NONE; | |
3302 | |
3303 *count_ptr = Arguments::PropertyList_count(Arguments::system_properties()); | |
3304 | |
3305 err = allocate(*count_ptr * sizeof(char *), (unsigned char **)property_ptr); | |
3306 if (err != JVMTI_ERROR_NONE) { | |
3307 return err; | |
3308 } | |
3309 int i = 0 ; | |
3310 for (SystemProperty* p = Arguments::system_properties(); p != NULL && i < *count_ptr; p = p->next(), i++) { | |
3311 const char *key = p->key(); | |
3312 char **tmp_value = *property_ptr+i; | |
3313 err = allocate((strlen(key)+1) * sizeof(char), (unsigned char**)tmp_value); | |
3314 if (err == JVMTI_ERROR_NONE) { | |
3315 strcpy(*tmp_value, key); | |
3316 } else { | |
3317 // clean up previously allocated memory. | |
3318 for (int j=0; j<i; j++) { | |
3319 Deallocate((unsigned char*)*property_ptr+j); | |
3320 } | |
3321 Deallocate((unsigned char*)property_ptr); | |
3322 break; | |
3323 } | |
3324 } | |
3325 return err; | |
3326 } /* end GetSystemProperties */ | |
3327 | |
3328 | |
3329 // property - pre-checked for NULL | |
3330 // value_ptr - pre-checked for NULL | |
3331 jvmtiError | |
3332 JvmtiEnv::GetSystemProperty(const char* property, char** value_ptr) { | |
3333 jvmtiError err = JVMTI_ERROR_NONE; | |
3334 const char *value; | |
3335 | |
3336 value = Arguments::PropertyList_get_value(Arguments::system_properties(), property); | |
3337 if (value == NULL) { | |
3338 err = JVMTI_ERROR_NOT_AVAILABLE; | |
3339 } else { | |
3340 err = allocate((strlen(value)+1) * sizeof(char), (unsigned char **)value_ptr); | |
3341 if (err == JVMTI_ERROR_NONE) { | |
3342 strcpy(*value_ptr, value); | |
3343 } | |
3344 } | |
3345 return err; | |
3346 } /* end GetSystemProperty */ | |
3347 | |
3348 | |
3349 // property - pre-checked for NULL | |
3350 // value - NULL is a valid value, must be checked | |
3351 jvmtiError | |
3352 JvmtiEnv::SetSystemProperty(const char* property, const char* value) { | |
3353 jvmtiError err =JVMTI_ERROR_NOT_AVAILABLE; | |
3354 | |
3355 for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) { | |
3356 if (strcmp(property, p->key()) == 0) { | |
3357 if (p->set_value((char *)value)) { | |
3358 err = JVMTI_ERROR_NONE; | |
3359 } | |
3360 } | |
3361 } | |
3362 return err; | |
3363 } /* end SetSystemProperty */ | |
3364 | |
3365 #endif // !JVMTI_KERNEL |