1/*
2 Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 This code is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License version 2 only, as
7 published by the Free Software Foundation.
8
9 This code is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 version 2 for more details (a copy is included in the LICENSE file that
13 accompanied this code).
14
15 You should have received a copy of the GNU General Public License version
16 2 along with this work; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 or visit www.oracle.com if you need additional information or have any
21 questions.
22 */
23
24 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
25
26# include "precompiled.hpp"
27# include "classfile/javaClasses.inline.hpp"
28# include "memory/resourceArea.hpp"
29# include "utilities/macros.hpp"
30#if INCLUDE_JVMTI
31# include "logging/log.hpp"
32# include "oops/oop.inline.hpp"
33# include "prims/jvmtiEnter.inline.hpp"
34# include "prims/jvmtiRawMonitor.hpp"
35# include "prims/jvmtiUtil.hpp"
36# include "runtime/fieldDescriptor.inline.hpp"
37# include "runtime/threadSMR.hpp"
38
39
40
41// Error names
42const char* JvmtiUtil::_error_names[] = {
43 "JVMTI_ERROR_NONE",
44 NULL,
45 NULL,
46 NULL,
47 NULL,
48 NULL,
49 NULL,
50 NULL,
51 NULL,
52 NULL,
53 "JVMTI_ERROR_INVALID_THREAD",
54 "JVMTI_ERROR_INVALID_THREAD_GROUP",
55 "JVMTI_ERROR_INVALID_PRIORITY",
56 "JVMTI_ERROR_THREAD_NOT_SUSPENDED",
57 "JVMTI_ERROR_THREAD_SUSPENDED",
58 "JVMTI_ERROR_THREAD_NOT_ALIVE",
59 NULL,
60 NULL,
61 NULL,
62 NULL,
63 "JVMTI_ERROR_INVALID_OBJECT",
64 "JVMTI_ERROR_INVALID_CLASS",
65 "JVMTI_ERROR_CLASS_NOT_PREPARED",
66 "JVMTI_ERROR_INVALID_METHODID",
67 "JVMTI_ERROR_INVALID_LOCATION",
68 "JVMTI_ERROR_INVALID_FIELDID",
69 "JVMTI_ERROR_INVALID_MODULE",
70 NULL,
71 NULL,
72 NULL,
73 NULL,
74 "JVMTI_ERROR_NO_MORE_FRAMES",
75 "JVMTI_ERROR_OPAQUE_FRAME",
76 NULL,
77 "JVMTI_ERROR_TYPE_MISMATCH",
78 "JVMTI_ERROR_INVALID_SLOT",
79 NULL,
80 NULL,
81 NULL,
82 NULL,
83 "JVMTI_ERROR_DUPLICATE",
84 "JVMTI_ERROR_NOT_FOUND",
85 NULL,
86 NULL,
87 NULL,
88 NULL,
89 NULL,
90 NULL,
91 NULL,
92 NULL,
93 "JVMTI_ERROR_INVALID_MONITOR",
94 "JVMTI_ERROR_NOT_MONITOR_OWNER",
95 "JVMTI_ERROR_INTERRUPT",
96 NULL,
97 NULL,
98 NULL,
99 NULL,
100 NULL,
101 NULL,
102 NULL,
103 "JVMTI_ERROR_INVALID_CLASS_FORMAT",
104 "JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION",
105 "JVMTI_ERROR_FAILS_VERIFICATION",
106 "JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED",
107 "JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED",
108 "JVMTI_ERROR_INVALID_TYPESTATE",
109 "JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED",
110 "JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED",
111 "JVMTI_ERROR_UNSUPPORTED_VERSION",
112 "JVMTI_ERROR_NAMES_DONT_MATCH",
113 "JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED",
114 "JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED",
115 "JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_ATTRIBUTE_CHANGED",
116 NULL,
117 NULL,
118 NULL,
119 NULL,
120 NULL,
121 NULL,
122 "JVMTI_ERROR_UNMODIFIABLE_CLASS",
123 "JVMTI_ERROR_UNMODIFIABLE_MODULE",
124 NULL,
125 NULL,
126 NULL,
127 NULL,
128 NULL,
129 NULL,
130 NULL,
131 NULL,
132 NULL,
133 NULL,
134 NULL,
135 NULL,
136 NULL,
137 NULL,
138 NULL,
139 NULL,
140 NULL,
141 "JVMTI_ERROR_NOT_AVAILABLE",
142 "JVMTI_ERROR_MUST_POSSESS_CAPABILITY",
143 "JVMTI_ERROR_NULL_POINTER",
144 "JVMTI_ERROR_ABSENT_INFORMATION",
145 "JVMTI_ERROR_INVALID_EVENT_TYPE",
146 "JVMTI_ERROR_ILLEGAL_ARGUMENT",
147 "JVMTI_ERROR_NATIVE_METHOD",
148 NULL,
149 "JVMTI_ERROR_CLASS_LOADER_UNSUPPORTED",
150 NULL,
151 NULL,
152 NULL,
153 "JVMTI_ERROR_OUT_OF_MEMORY",
154 "JVMTI_ERROR_ACCESS_DENIED",
155 "JVMTI_ERROR_WRONG_PHASE",
156 "JVMTI_ERROR_INTERNAL",
157 NULL,
158 "JVMTI_ERROR_UNATTACHED_THREAD",
159 "JVMTI_ERROR_INVALID_ENVIRONMENT"
160};
161
162
163// Event threaded
164const bool JvmtiUtil::_event_threaded[] = {
165 false,
166 false,
167 false,
168 false,
169 false,
170 false,
171 false,
172 false,
173 false,
174 false,
175 false,
176 false,
177 false,
178 false,
179 false,
180 false,
181 false,
182 false,
183 false,
184 false,
185 false,
186 false,
187 false,
188 false,
189 false,
190 false,
191 false,
192 false,
193 false,
194 false,
195 false,
196 false,
197 false,
198 false,
199 false,
200 false,
201 false,
202 false,
203 false,
204 false,
205 false,
206 false,
207 false,
208 false,
209 false,
210 false,
211 false,
212 false,
213 false,
214 false,
215 false,
216 false,
217 false,
218 true,
219 false,
220 true,
221 true,
222 false,
223 true,
224 true,
225 true,
226 true,
227 true,
228 true,
229 true,
230 true,
231 true,
232 false,
233 false,
234 false,
235 false,
236 false,
237 false,
238 true,
239 true,
240 true,
241 true,
242 false,
243 false,
244 false,
245 false,
246 false,
247 false,
248 false,
249 false,
250 false,
251 true
252};
253
254
255
256// Check Event Capabilities
257const bool JvmtiUtil::has_event_capability(jvmtiEvent event_type, const jvmtiCapabilities* capabilities_ptr) {
258 switch (event_type) {
259 case JVMTI_EVENT_SINGLE_STEP:
260 return capabilities_ptr->can_generate_single_step_events != 0;
261 case JVMTI_EVENT_BREAKPOINT:
262 return capabilities_ptr->can_generate_breakpoint_events != 0;
263 case JVMTI_EVENT_FIELD_ACCESS:
264 return capabilities_ptr->can_generate_field_access_events != 0;
265 case JVMTI_EVENT_FIELD_MODIFICATION:
266 return capabilities_ptr->can_generate_field_modification_events != 0;
267 case JVMTI_EVENT_FRAME_POP:
268 return capabilities_ptr->can_generate_frame_pop_events != 0;
269 case JVMTI_EVENT_METHOD_ENTRY:
270 return capabilities_ptr->can_generate_method_entry_events != 0;
271 case JVMTI_EVENT_METHOD_EXIT:
272 return capabilities_ptr->can_generate_method_exit_events != 0;
273 case JVMTI_EVENT_NATIVE_METHOD_BIND:
274 return capabilities_ptr->can_generate_native_method_bind_events != 0;
275 case JVMTI_EVENT_EXCEPTION:
276 return capabilities_ptr->can_generate_exception_events != 0;
277 case JVMTI_EVENT_EXCEPTION_CATCH:
278 return capabilities_ptr->can_generate_exception_events != 0;
279 case JVMTI_EVENT_COMPILED_METHOD_LOAD:
280 return capabilities_ptr->can_generate_compiled_method_load_events != 0;
281 case JVMTI_EVENT_COMPILED_METHOD_UNLOAD:
282 return capabilities_ptr->can_generate_compiled_method_load_events != 0;
283 case JVMTI_EVENT_MONITOR_CONTENDED_ENTER:
284 return capabilities_ptr->can_generate_monitor_events != 0;
285 case JVMTI_EVENT_MONITOR_CONTENDED_ENTERED:
286 return capabilities_ptr->can_generate_monitor_events != 0;
287 case JVMTI_EVENT_MONITOR_WAIT:
288 return capabilities_ptr->can_generate_monitor_events != 0;
289 case JVMTI_EVENT_MONITOR_WAITED:
290 return capabilities_ptr->can_generate_monitor_events != 0;
291 case JVMTI_EVENT_VM_OBJECT_ALLOC:
292 return capabilities_ptr->can_generate_vm_object_alloc_events != 0;
293 case JVMTI_EVENT_SAMPLED_OBJECT_ALLOC:
294 return capabilities_ptr->can_generate_sampled_object_alloc_events != 0;
295 case JVMTI_EVENT_OBJECT_FREE:
296 return capabilities_ptr->can_generate_object_free_events != 0;
297 case JVMTI_EVENT_GARBAGE_COLLECTION_START:
298 return capabilities_ptr->can_generate_garbage_collection_events != 0;
299 case JVMTI_EVENT_GARBAGE_COLLECTION_FINISH:
300 return capabilities_ptr->can_generate_garbage_collection_events != 0;
301 default: break; }
302 // if it does not have a capability it is required
303 return JNI_TRUE;
304}
305
306
307extern "C" {
308
309
310 //
311 // Memory Management functions
312 //
313
314static jvmtiError JNICALL
315jvmti_Allocate(jvmtiEnv* env,
316 jlong size,
317 unsigned char** mem_ptr) {
318
319 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
320 if (!jvmti_env->is_valid()) {
321 return JVMTI_ERROR_INVALID_ENVIRONMENT;
322 }
323 jvmtiError err;
324 Thread* this_thread = NULL;
325 bool transition;
326 if (Threads::number_of_threads() == 0) {
327 transition = false;
328 } else {
329 this_thread = Thread::current_or_null();
330 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
331 }
332 if (transition) {
333 if (!this_thread->is_Java_thread()) {
334 return JVMTI_ERROR_UNATTACHED_THREAD;
335 }
336 JavaThread* current_thread = (JavaThread*)this_thread;
337 ThreadInVMfromNative __tiv(current_thread);
338 VM_ENTRY_BASE(jvmtiError, jvmti_Allocate , current_thread)
339 debug_only(VMNativeEntryWrapper __vew;)
340 if (mem_ptr == NULL) {
341 return JVMTI_ERROR_NULL_POINTER;
342 }
343 err = jvmti_env->Allocate(size, mem_ptr);
344 } else {
345 if (mem_ptr == NULL) {
346 return JVMTI_ERROR_NULL_POINTER;
347 }
348 err = jvmti_env->Allocate(size, mem_ptr);
349 }
350 return err;
351}
352
353static jvmtiError JNICALL
354jvmti_Deallocate(jvmtiEnv* env,
355 unsigned char* mem) {
356
357 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
358 if (!jvmti_env->is_valid()) {
359 return JVMTI_ERROR_INVALID_ENVIRONMENT;
360 }
361 jvmtiError err;
362 Thread* this_thread = NULL;
363 bool transition;
364 if (Threads::number_of_threads() == 0) {
365 transition = false;
366 } else {
367 this_thread = Thread::current_or_null();
368 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
369 }
370 if (transition) {
371 if (!this_thread->is_Java_thread()) {
372 return JVMTI_ERROR_UNATTACHED_THREAD;
373 }
374 JavaThread* current_thread = (JavaThread*)this_thread;
375 ThreadInVMfromNative __tiv(current_thread);
376 VM_ENTRY_BASE(jvmtiError, jvmti_Deallocate , current_thread)
377 debug_only(VMNativeEntryWrapper __vew;)
378 err = jvmti_env->Deallocate(mem);
379 } else {
380 err = jvmti_env->Deallocate(mem);
381 }
382 return err;
383}
384
385 //
386 // Thread functions
387 //
388
389static jvmtiError JNICALL
390jvmti_GetThreadState(jvmtiEnv* env,
391 jthread thread,
392 jint* thread_state_ptr) {
393
394#if !INCLUDE_JVMTI
395 return JVMTI_ERROR_NOT_AVAILABLE;
396#else
397 if(!JvmtiEnv::is_vm_live()) {
398 return JVMTI_ERROR_WRONG_PHASE;
399 }
400 Thread* this_thread = Thread::current_or_null();
401 if (this_thread == NULL || !this_thread->is_Java_thread()) {
402 return JVMTI_ERROR_UNATTACHED_THREAD;
403 }
404 JavaThread* current_thread = (JavaThread*)this_thread;
405 ThreadInVMfromNative __tiv(current_thread);
406 VM_ENTRY_BASE(jvmtiError, jvmti_GetThreadState , current_thread)
407 debug_only(VMNativeEntryWrapper __vew;)
408 CautiouslyPreserveExceptionMark __em(this_thread);
409 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
410 if (!jvmti_env->is_valid()) {
411 return JVMTI_ERROR_INVALID_ENVIRONMENT;
412 }
413 jvmtiError err;
414 if (thread_state_ptr == NULL) {
415 return JVMTI_ERROR_NULL_POINTER;
416 }
417 err = jvmti_env->GetThreadState(thread, thread_state_ptr);
418 return err;
419#endif // INCLUDE_JVMTI
420}
421
422static jvmtiError JNICALL
423jvmti_GetCurrentThread(jvmtiEnv* env,
424 jthread* thread_ptr) {
425
426#if !INCLUDE_JVMTI
427 return JVMTI_ERROR_NOT_AVAILABLE;
428#else
429 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
430 return JVMTI_ERROR_WRONG_PHASE;
431 }
432 Thread* this_thread = Thread::current_or_null();
433 if (this_thread == NULL || !this_thread->is_Java_thread()) {
434 return JVMTI_ERROR_UNATTACHED_THREAD;
435 }
436 JavaThread* current_thread = (JavaThread*)this_thread;
437 ThreadInVMfromNative __tiv(current_thread);
438 VM_ENTRY_BASE(jvmtiError, jvmti_GetCurrentThread , current_thread)
439 debug_only(VMNativeEntryWrapper __vew;)
440 CautiouslyPreserveExceptionMark __em(this_thread);
441 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
442 if (!jvmti_env->is_valid()) {
443 return JVMTI_ERROR_INVALID_ENVIRONMENT;
444 }
445 jvmtiError err;
446 if (thread_ptr == NULL) {
447 return JVMTI_ERROR_NULL_POINTER;
448 }
449 err = jvmti_env->GetCurrentThread(thread_ptr);
450 return err;
451#endif // INCLUDE_JVMTI
452}
453
454static jvmtiError JNICALL
455jvmti_GetAllThreads(jvmtiEnv* env,
456 jint* threads_count_ptr,
457 jthread** threads_ptr) {
458
459#if !INCLUDE_JVMTI
460 return JVMTI_ERROR_NOT_AVAILABLE;
461#else
462 if(!JvmtiEnv::is_vm_live()) {
463 return JVMTI_ERROR_WRONG_PHASE;
464 }
465 Thread* this_thread = Thread::current_or_null();
466 if (this_thread == NULL || !this_thread->is_Java_thread()) {
467 return JVMTI_ERROR_UNATTACHED_THREAD;
468 }
469 JavaThread* current_thread = (JavaThread*)this_thread;
470 ThreadInVMfromNative __tiv(current_thread);
471 VM_ENTRY_BASE(jvmtiError, jvmti_GetAllThreads , current_thread)
472 debug_only(VMNativeEntryWrapper __vew;)
473 CautiouslyPreserveExceptionMark __em(this_thread);
474 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
475 if (!jvmti_env->is_valid()) {
476 return JVMTI_ERROR_INVALID_ENVIRONMENT;
477 }
478 jvmtiError err;
479 if (threads_count_ptr == NULL) {
480 return JVMTI_ERROR_NULL_POINTER;
481 }
482 if (threads_ptr == NULL) {
483 return JVMTI_ERROR_NULL_POINTER;
484 }
485 err = jvmti_env->GetAllThreads(threads_count_ptr, threads_ptr);
486 return err;
487#endif // INCLUDE_JVMTI
488}
489
490static jvmtiError JNICALL
491jvmti_SuspendThread(jvmtiEnv* env,
492 jthread thread) {
493
494#if !INCLUDE_JVMTI
495 return JVMTI_ERROR_NOT_AVAILABLE;
496#else
497 if(!JvmtiEnv::is_vm_live()) {
498 return JVMTI_ERROR_WRONG_PHASE;
499 }
500 Thread* this_thread = Thread::current_or_null();
501 if (this_thread == NULL || !this_thread->is_Java_thread()) {
502 return JVMTI_ERROR_UNATTACHED_THREAD;
503 }
504 JavaThread* current_thread = (JavaThread*)this_thread;
505 ThreadInVMfromNative __tiv(current_thread);
506 VM_ENTRY_BASE(jvmtiError, jvmti_SuspendThread , current_thread)
507 debug_only(VMNativeEntryWrapper __vew;)
508 CautiouslyPreserveExceptionMark __em(this_thread);
509 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
510 if (!jvmti_env->is_valid()) {
511 return JVMTI_ERROR_INVALID_ENVIRONMENT;
512 }
513
514 if (jvmti_env->get_capabilities()->can_suspend == 0) {
515 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
516 }
517 jvmtiError err;
518 JavaThread* java_thread = NULL;
519 ThreadsListHandle tlh(this_thread);
520 if (thread == NULL) {
521 java_thread = current_thread;
522 } else {
523 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
524 if (err != JVMTI_ERROR_NONE) {
525 return err;
526 }
527 }
528 err = jvmti_env->SuspendThread(java_thread);
529 return err;
530#endif // INCLUDE_JVMTI
531}
532
533static jvmtiError JNICALL
534jvmti_SuspendThreadList(jvmtiEnv* env,
535 jint request_count,
536 const jthread* request_list,
537 jvmtiError* results) {
538
539#if !INCLUDE_JVMTI
540 return JVMTI_ERROR_NOT_AVAILABLE;
541#else
542 if(!JvmtiEnv::is_vm_live()) {
543 return JVMTI_ERROR_WRONG_PHASE;
544 }
545 Thread* this_thread = Thread::current_or_null();
546 if (this_thread == NULL || !this_thread->is_Java_thread()) {
547 return JVMTI_ERROR_UNATTACHED_THREAD;
548 }
549 JavaThread* current_thread = (JavaThread*)this_thread;
550 ThreadInVMfromNative __tiv(current_thread);
551 VM_ENTRY_BASE(jvmtiError, jvmti_SuspendThreadList , current_thread)
552 debug_only(VMNativeEntryWrapper __vew;)
553 CautiouslyPreserveExceptionMark __em(this_thread);
554 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
555 if (!jvmti_env->is_valid()) {
556 return JVMTI_ERROR_INVALID_ENVIRONMENT;
557 }
558
559 if (jvmti_env->get_capabilities()->can_suspend == 0) {
560 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
561 }
562 jvmtiError err;
563 if (request_count < 0) {
564 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
565 }
566 if (request_list == NULL) {
567 return JVMTI_ERROR_NULL_POINTER;
568 }
569 if (results == NULL) {
570 return JVMTI_ERROR_NULL_POINTER;
571 }
572 err = jvmti_env->SuspendThreadList(request_count, request_list, results);
573 return err;
574#endif // INCLUDE_JVMTI
575}
576
577static jvmtiError JNICALL
578jvmti_ResumeThread(jvmtiEnv* env,
579 jthread thread) {
580
581#if !INCLUDE_JVMTI
582 return JVMTI_ERROR_NOT_AVAILABLE;
583#else
584 if(!JvmtiEnv::is_vm_live()) {
585 return JVMTI_ERROR_WRONG_PHASE;
586 }
587 Thread* this_thread = Thread::current_or_null();
588 if (this_thread == NULL || !this_thread->is_Java_thread()) {
589 return JVMTI_ERROR_UNATTACHED_THREAD;
590 }
591 JavaThread* current_thread = (JavaThread*)this_thread;
592 ThreadInVMfromNative __tiv(current_thread);
593 VM_ENTRY_BASE(jvmtiError, jvmti_ResumeThread , current_thread)
594 debug_only(VMNativeEntryWrapper __vew;)
595 CautiouslyPreserveExceptionMark __em(this_thread);
596 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
597 if (!jvmti_env->is_valid()) {
598 return JVMTI_ERROR_INVALID_ENVIRONMENT;
599 }
600
601 if (jvmti_env->get_capabilities()->can_suspend == 0) {
602 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
603 }
604 jvmtiError err;
605 JavaThread* java_thread = NULL;
606 ThreadsListHandle tlh(this_thread);
607 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
608 if (err != JVMTI_ERROR_NONE) {
609 return err;
610 }
611 err = jvmti_env->ResumeThread(java_thread);
612 return err;
613#endif // INCLUDE_JVMTI
614}
615
616static jvmtiError JNICALL
617jvmti_ResumeThreadList(jvmtiEnv* env,
618 jint request_count,
619 const jthread* request_list,
620 jvmtiError* results) {
621
622#if !INCLUDE_JVMTI
623 return JVMTI_ERROR_NOT_AVAILABLE;
624#else
625 if(!JvmtiEnv::is_vm_live()) {
626 return JVMTI_ERROR_WRONG_PHASE;
627 }
628 Thread* this_thread = Thread::current_or_null();
629 if (this_thread == NULL || !this_thread->is_Java_thread()) {
630 return JVMTI_ERROR_UNATTACHED_THREAD;
631 }
632 JavaThread* current_thread = (JavaThread*)this_thread;
633 ThreadInVMfromNative __tiv(current_thread);
634 VM_ENTRY_BASE(jvmtiError, jvmti_ResumeThreadList , current_thread)
635 debug_only(VMNativeEntryWrapper __vew;)
636 CautiouslyPreserveExceptionMark __em(this_thread);
637 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
638 if (!jvmti_env->is_valid()) {
639 return JVMTI_ERROR_INVALID_ENVIRONMENT;
640 }
641
642 if (jvmti_env->get_capabilities()->can_suspend == 0) {
643 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
644 }
645 jvmtiError err;
646 if (request_count < 0) {
647 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
648 }
649 if (request_list == NULL) {
650 return JVMTI_ERROR_NULL_POINTER;
651 }
652 if (results == NULL) {
653 return JVMTI_ERROR_NULL_POINTER;
654 }
655 err = jvmti_env->ResumeThreadList(request_count, request_list, results);
656 return err;
657#endif // INCLUDE_JVMTI
658}
659
660static jvmtiError JNICALL
661jvmti_StopThread(jvmtiEnv* env,
662 jthread thread,
663 jobject exception) {
664
665#if !INCLUDE_JVMTI
666 return JVMTI_ERROR_NOT_AVAILABLE;
667#else
668 if(!JvmtiEnv::is_vm_live()) {
669 return JVMTI_ERROR_WRONG_PHASE;
670 }
671 Thread* this_thread = Thread::current_or_null();
672 if (this_thread == NULL || !this_thread->is_Java_thread()) {
673 return JVMTI_ERROR_UNATTACHED_THREAD;
674 }
675 JavaThread* current_thread = (JavaThread*)this_thread;
676 ThreadInVMfromNative __tiv(current_thread);
677 VM_ENTRY_BASE(jvmtiError, jvmti_StopThread , current_thread)
678 debug_only(VMNativeEntryWrapper __vew;)
679 CautiouslyPreserveExceptionMark __em(this_thread);
680 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
681 if (!jvmti_env->is_valid()) {
682 return JVMTI_ERROR_INVALID_ENVIRONMENT;
683 }
684
685 if (jvmti_env->get_capabilities()->can_signal_thread == 0) {
686 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
687 }
688 jvmtiError err;
689 JavaThread* java_thread = NULL;
690 ThreadsListHandle tlh(this_thread);
691 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
692 if (err != JVMTI_ERROR_NONE) {
693 return err;
694 }
695 err = jvmti_env->StopThread(java_thread, exception);
696 return err;
697#endif // INCLUDE_JVMTI
698}
699
700static jvmtiError JNICALL
701jvmti_InterruptThread(jvmtiEnv* env,
702 jthread thread) {
703
704#if !INCLUDE_JVMTI
705 return JVMTI_ERROR_NOT_AVAILABLE;
706#else
707 if(!JvmtiEnv::is_vm_live()) {
708 return JVMTI_ERROR_WRONG_PHASE;
709 }
710 Thread* this_thread = Thread::current_or_null();
711 if (this_thread == NULL || !this_thread->is_Java_thread()) {
712 return JVMTI_ERROR_UNATTACHED_THREAD;
713 }
714 JavaThread* current_thread = (JavaThread*)this_thread;
715 ThreadInVMfromNative __tiv(current_thread);
716 VM_ENTRY_BASE(jvmtiError, jvmti_InterruptThread , current_thread)
717 debug_only(VMNativeEntryWrapper __vew;)
718 CautiouslyPreserveExceptionMark __em(this_thread);
719 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
720 if (!jvmti_env->is_valid()) {
721 return JVMTI_ERROR_INVALID_ENVIRONMENT;
722 }
723
724 if (jvmti_env->get_capabilities()->can_signal_thread == 0) {
725 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
726 }
727 jvmtiError err;
728 err = jvmti_env->InterruptThread(thread);
729 return err;
730#endif // INCLUDE_JVMTI
731}
732
733static jvmtiError JNICALL
734jvmti_GetThreadInfo(jvmtiEnv* env,
735 jthread thread,
736 jvmtiThreadInfo* info_ptr) {
737
738#if !INCLUDE_JVMTI
739 return JVMTI_ERROR_NOT_AVAILABLE;
740#else
741 if(!JvmtiEnv::is_vm_live()) {
742 return JVMTI_ERROR_WRONG_PHASE;
743 }
744 Thread* this_thread = Thread::current_or_null();
745 if (this_thread == NULL || !this_thread->is_Java_thread()) {
746 return JVMTI_ERROR_UNATTACHED_THREAD;
747 }
748 JavaThread* current_thread = (JavaThread*)this_thread;
749 ThreadInVMfromNative __tiv(current_thread);
750 VM_ENTRY_BASE(jvmtiError, jvmti_GetThreadInfo , current_thread)
751 debug_only(VMNativeEntryWrapper __vew;)
752 CautiouslyPreserveExceptionMark __em(this_thread);
753 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
754 if (!jvmti_env->is_valid()) {
755 return JVMTI_ERROR_INVALID_ENVIRONMENT;
756 }
757 jvmtiError err;
758 if (info_ptr == NULL) {
759 return JVMTI_ERROR_NULL_POINTER;
760 }
761 err = jvmti_env->GetThreadInfo(thread, info_ptr);
762 return err;
763#endif // INCLUDE_JVMTI
764}
765
766static jvmtiError JNICALL
767jvmti_GetOwnedMonitorInfo(jvmtiEnv* env,
768 jthread thread,
769 jint* owned_monitor_count_ptr,
770 jobject** owned_monitors_ptr) {
771
772#if !INCLUDE_JVMTI
773 return JVMTI_ERROR_NOT_AVAILABLE;
774#else
775 if(!JvmtiEnv::is_vm_live()) {
776 return JVMTI_ERROR_WRONG_PHASE;
777 }
778 Thread* this_thread = Thread::current_or_null();
779 if (this_thread == NULL || !this_thread->is_Java_thread()) {
780 return JVMTI_ERROR_UNATTACHED_THREAD;
781 }
782 JavaThread* current_thread = (JavaThread*)this_thread;
783 ThreadInVMfromNative __tiv(current_thread);
784 VM_ENTRY_BASE(jvmtiError, jvmti_GetOwnedMonitorInfo , current_thread)
785 debug_only(VMNativeEntryWrapper __vew;)
786 CautiouslyPreserveExceptionMark __em(this_thread);
787 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
788 if (!jvmti_env->is_valid()) {
789 return JVMTI_ERROR_INVALID_ENVIRONMENT;
790 }
791
792 if (jvmti_env->get_capabilities()->can_get_owned_monitor_info == 0) {
793 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
794 }
795 jvmtiError err;
796 JavaThread* java_thread = NULL;
797 ThreadsListHandle tlh(this_thread);
798 if (thread == NULL) {
799 java_thread = current_thread;
800 } else {
801 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
802 if (err != JVMTI_ERROR_NONE) {
803 return err;
804 }
805 }
806 if (owned_monitor_count_ptr == NULL) {
807 return JVMTI_ERROR_NULL_POINTER;
808 }
809 if (owned_monitors_ptr == NULL) {
810 return JVMTI_ERROR_NULL_POINTER;
811 }
812 err = jvmti_env->GetOwnedMonitorInfo(java_thread, owned_monitor_count_ptr, owned_monitors_ptr);
813 return err;
814#endif // INCLUDE_JVMTI
815}
816
817static jvmtiError JNICALL
818jvmti_GetOwnedMonitorStackDepthInfo(jvmtiEnv* env,
819 jthread thread,
820 jint* monitor_info_count_ptr,
821 jvmtiMonitorStackDepthInfo** monitor_info_ptr) {
822
823#if !INCLUDE_JVMTI
824 return JVMTI_ERROR_NOT_AVAILABLE;
825#else
826 if(!JvmtiEnv::is_vm_live()) {
827 return JVMTI_ERROR_WRONG_PHASE;
828 }
829 Thread* this_thread = Thread::current_or_null();
830 if (this_thread == NULL || !this_thread->is_Java_thread()) {
831 return JVMTI_ERROR_UNATTACHED_THREAD;
832 }
833 JavaThread* current_thread = (JavaThread*)this_thread;
834 ThreadInVMfromNative __tiv(current_thread);
835 VM_ENTRY_BASE(jvmtiError, jvmti_GetOwnedMonitorStackDepthInfo , current_thread)
836 debug_only(VMNativeEntryWrapper __vew;)
837 CautiouslyPreserveExceptionMark __em(this_thread);
838 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
839 if (!jvmti_env->is_valid()) {
840 return JVMTI_ERROR_INVALID_ENVIRONMENT;
841 }
842
843 if (jvmti_env->get_capabilities()->can_get_owned_monitor_stack_depth_info == 0) {
844 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
845 }
846 jvmtiError err;
847 JavaThread* java_thread = NULL;
848 ThreadsListHandle tlh(this_thread);
849 if (thread == NULL) {
850 java_thread = current_thread;
851 } else {
852 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
853 if (err != JVMTI_ERROR_NONE) {
854 return err;
855 }
856 }
857 if (monitor_info_count_ptr == NULL) {
858 return JVMTI_ERROR_NULL_POINTER;
859 }
860 if (monitor_info_ptr == NULL) {
861 return JVMTI_ERROR_NULL_POINTER;
862 }
863 err = jvmti_env->GetOwnedMonitorStackDepthInfo(java_thread, monitor_info_count_ptr, monitor_info_ptr);
864 return err;
865#endif // INCLUDE_JVMTI
866}
867
868static jvmtiError JNICALL
869jvmti_GetCurrentContendedMonitor(jvmtiEnv* env,
870 jthread thread,
871 jobject* monitor_ptr) {
872
873#if !INCLUDE_JVMTI
874 return JVMTI_ERROR_NOT_AVAILABLE;
875#else
876 if(!JvmtiEnv::is_vm_live()) {
877 return JVMTI_ERROR_WRONG_PHASE;
878 }
879 Thread* this_thread = Thread::current_or_null();
880 if (this_thread == NULL || !this_thread->is_Java_thread()) {
881 return JVMTI_ERROR_UNATTACHED_THREAD;
882 }
883 JavaThread* current_thread = (JavaThread*)this_thread;
884 ThreadInVMfromNative __tiv(current_thread);
885 VM_ENTRY_BASE(jvmtiError, jvmti_GetCurrentContendedMonitor , current_thread)
886 debug_only(VMNativeEntryWrapper __vew;)
887 CautiouslyPreserveExceptionMark __em(this_thread);
888 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
889 if (!jvmti_env->is_valid()) {
890 return JVMTI_ERROR_INVALID_ENVIRONMENT;
891 }
892
893 if (jvmti_env->get_capabilities()->can_get_current_contended_monitor == 0) {
894 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
895 }
896 jvmtiError err;
897 JavaThread* java_thread = NULL;
898 ThreadsListHandle tlh(this_thread);
899 if (thread == NULL) {
900 java_thread = current_thread;
901 } else {
902 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
903 if (err != JVMTI_ERROR_NONE) {
904 return err;
905 }
906 }
907 if (monitor_ptr == NULL) {
908 return JVMTI_ERROR_NULL_POINTER;
909 }
910 err = jvmti_env->GetCurrentContendedMonitor(java_thread, monitor_ptr);
911 return err;
912#endif // INCLUDE_JVMTI
913}
914
915static jvmtiError JNICALL
916jvmti_RunAgentThread(jvmtiEnv* env,
917 jthread thread,
918 jvmtiStartFunction proc,
919 const void* arg,
920 jint priority) {
921
922#if !INCLUDE_JVMTI
923 return JVMTI_ERROR_NOT_AVAILABLE;
924#else
925 if(!JvmtiEnv::is_vm_live()) {
926 return JVMTI_ERROR_WRONG_PHASE;
927 }
928 Thread* this_thread = Thread::current_or_null();
929 if (this_thread == NULL || !this_thread->is_Java_thread()) {
930 return JVMTI_ERROR_UNATTACHED_THREAD;
931 }
932 JavaThread* current_thread = (JavaThread*)this_thread;
933 ThreadInVMfromNative __tiv(current_thread);
934 VM_ENTRY_BASE(jvmtiError, jvmti_RunAgentThread , current_thread)
935 debug_only(VMNativeEntryWrapper __vew;)
936 CautiouslyPreserveExceptionMark __em(this_thread);
937 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
938 if (!jvmti_env->is_valid()) {
939 return JVMTI_ERROR_INVALID_ENVIRONMENT;
940 }
941 jvmtiError err;
942 if (proc == NULL) {
943 return JVMTI_ERROR_NULL_POINTER;
944 }
945 err = jvmti_env->RunAgentThread(thread, proc, arg, priority);
946 return err;
947#endif // INCLUDE_JVMTI
948}
949
950static jvmtiError JNICALL
951jvmti_SetThreadLocalStorage(jvmtiEnv* env,
952 jthread thread,
953 const void* data) {
954 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
955 return JVMTI_ERROR_WRONG_PHASE;
956 }
957 Thread* this_thread = Thread::current_or_null();
958 if (this_thread == NULL || !this_thread->is_Java_thread()) {
959 return JVMTI_ERROR_UNATTACHED_THREAD;
960 }
961 JavaThread* current_thread = (JavaThread*)this_thread;
962 ThreadInVMfromNative __tiv(current_thread);
963 VM_ENTRY_BASE(jvmtiError, jvmti_SetThreadLocalStorage , current_thread)
964 debug_only(VMNativeEntryWrapper __vew;)
965 CautiouslyPreserveExceptionMark __em(this_thread);
966 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
967 if (!jvmti_env->is_valid()) {
968 return JVMTI_ERROR_INVALID_ENVIRONMENT;
969 }
970 jvmtiError err;
971 JavaThread* java_thread = NULL;
972 ThreadsListHandle tlh(this_thread);
973 if (thread == NULL) {
974 java_thread = current_thread;
975 } else {
976 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
977 if (err != JVMTI_ERROR_NONE) {
978 return err;
979 }
980 }
981 err = jvmti_env->SetThreadLocalStorage(java_thread, data);
982 return err;
983}
984
985static jvmtiError JNICALL
986jvmti_GetThreadLocalStorage(jvmtiEnv* env,
987 jthread thread,
988 void** data_ptr) {
989 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
990 return JVMTI_ERROR_WRONG_PHASE;
991 }
992 Thread* this_thread = Thread::current_or_null();
993 if (this_thread == NULL || !this_thread->is_Java_thread()) {
994 return JVMTI_ERROR_UNATTACHED_THREAD;
995 }
996
997 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
998 if (!jvmti_env->is_valid()) {
999 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1000 }
1001 jvmtiError err;
1002 if (data_ptr == NULL) {
1003 return JVMTI_ERROR_NULL_POINTER;
1004 }
1005 err = jvmti_env->GetThreadLocalStorage(thread, data_ptr);
1006 return err;
1007}
1008
1009 //
1010 // Thread Group functions
1011 //
1012
1013static jvmtiError JNICALL
1014jvmti_GetTopThreadGroups(jvmtiEnv* env,
1015 jint* group_count_ptr,
1016 jthreadGroup** groups_ptr) {
1017
1018#if !INCLUDE_JVMTI
1019 return JVMTI_ERROR_NOT_AVAILABLE;
1020#else
1021 if(!JvmtiEnv::is_vm_live()) {
1022 return JVMTI_ERROR_WRONG_PHASE;
1023 }
1024 Thread* this_thread = Thread::current_or_null();
1025 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1026 return JVMTI_ERROR_UNATTACHED_THREAD;
1027 }
1028 JavaThread* current_thread = (JavaThread*)this_thread;
1029 ThreadInVMfromNative __tiv(current_thread);
1030 VM_ENTRY_BASE(jvmtiError, jvmti_GetTopThreadGroups , current_thread)
1031 debug_only(VMNativeEntryWrapper __vew;)
1032 CautiouslyPreserveExceptionMark __em(this_thread);
1033 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1034 if (!jvmti_env->is_valid()) {
1035 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1036 }
1037 jvmtiError err;
1038 if (group_count_ptr == NULL) {
1039 return JVMTI_ERROR_NULL_POINTER;
1040 }
1041 if (groups_ptr == NULL) {
1042 return JVMTI_ERROR_NULL_POINTER;
1043 }
1044 err = jvmti_env->GetTopThreadGroups(group_count_ptr, groups_ptr);
1045 return err;
1046#endif // INCLUDE_JVMTI
1047}
1048
1049static jvmtiError JNICALL
1050jvmti_GetThreadGroupInfo(jvmtiEnv* env,
1051 jthreadGroup group,
1052 jvmtiThreadGroupInfo* info_ptr) {
1053
1054#if !INCLUDE_JVMTI
1055 return JVMTI_ERROR_NOT_AVAILABLE;
1056#else
1057 if(!JvmtiEnv::is_vm_live()) {
1058 return JVMTI_ERROR_WRONG_PHASE;
1059 }
1060 Thread* this_thread = Thread::current_or_null();
1061 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1062 return JVMTI_ERROR_UNATTACHED_THREAD;
1063 }
1064 JavaThread* current_thread = (JavaThread*)this_thread;
1065 ThreadInVMfromNative __tiv(current_thread);
1066 VM_ENTRY_BASE(jvmtiError, jvmti_GetThreadGroupInfo , current_thread)
1067 debug_only(VMNativeEntryWrapper __vew;)
1068 CautiouslyPreserveExceptionMark __em(this_thread);
1069 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1070 if (!jvmti_env->is_valid()) {
1071 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1072 }
1073 jvmtiError err;
1074 if (info_ptr == NULL) {
1075 return JVMTI_ERROR_NULL_POINTER;
1076 }
1077 err = jvmti_env->GetThreadGroupInfo(group, info_ptr);
1078 return err;
1079#endif // INCLUDE_JVMTI
1080}
1081
1082static jvmtiError JNICALL
1083jvmti_GetThreadGroupChildren(jvmtiEnv* env,
1084 jthreadGroup group,
1085 jint* thread_count_ptr,
1086 jthread** threads_ptr,
1087 jint* group_count_ptr,
1088 jthreadGroup** groups_ptr) {
1089
1090#if !INCLUDE_JVMTI
1091 return JVMTI_ERROR_NOT_AVAILABLE;
1092#else
1093 if(!JvmtiEnv::is_vm_live()) {
1094 return JVMTI_ERROR_WRONG_PHASE;
1095 }
1096 Thread* this_thread = Thread::current_or_null();
1097 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1098 return JVMTI_ERROR_UNATTACHED_THREAD;
1099 }
1100 JavaThread* current_thread = (JavaThread*)this_thread;
1101 ThreadInVMfromNative __tiv(current_thread);
1102 VM_ENTRY_BASE(jvmtiError, jvmti_GetThreadGroupChildren , current_thread)
1103 debug_only(VMNativeEntryWrapper __vew;)
1104 CautiouslyPreserveExceptionMark __em(this_thread);
1105 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1106 if (!jvmti_env->is_valid()) {
1107 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1108 }
1109 jvmtiError err;
1110 if (thread_count_ptr == NULL) {
1111 return JVMTI_ERROR_NULL_POINTER;
1112 }
1113 if (threads_ptr == NULL) {
1114 return JVMTI_ERROR_NULL_POINTER;
1115 }
1116 if (group_count_ptr == NULL) {
1117 return JVMTI_ERROR_NULL_POINTER;
1118 }
1119 if (groups_ptr == NULL) {
1120 return JVMTI_ERROR_NULL_POINTER;
1121 }
1122 err = jvmti_env->GetThreadGroupChildren(group, thread_count_ptr, threads_ptr, group_count_ptr, groups_ptr);
1123 return err;
1124#endif // INCLUDE_JVMTI
1125}
1126
1127 //
1128 // Stack Frame functions
1129 //
1130
1131static jvmtiError JNICALL
1132jvmti_GetStackTrace(jvmtiEnv* env,
1133 jthread thread,
1134 jint start_depth,
1135 jint max_frame_count,
1136 jvmtiFrameInfo* frame_buffer,
1137 jint* count_ptr) {
1138
1139#if !INCLUDE_JVMTI
1140 return JVMTI_ERROR_NOT_AVAILABLE;
1141#else
1142 if(!JvmtiEnv::is_vm_live()) {
1143 return JVMTI_ERROR_WRONG_PHASE;
1144 }
1145 Thread* this_thread = Thread::current_or_null();
1146 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1147 return JVMTI_ERROR_UNATTACHED_THREAD;
1148 }
1149 JavaThread* current_thread = (JavaThread*)this_thread;
1150 ThreadInVMfromNative __tiv(current_thread);
1151 VM_ENTRY_BASE(jvmtiError, jvmti_GetStackTrace , current_thread)
1152 debug_only(VMNativeEntryWrapper __vew;)
1153 CautiouslyPreserveExceptionMark __em(this_thread);
1154 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1155 if (!jvmti_env->is_valid()) {
1156 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1157 }
1158 jvmtiError err;
1159 JavaThread* java_thread = NULL;
1160 ThreadsListHandle tlh(this_thread);
1161 if (thread == NULL) {
1162 java_thread = current_thread;
1163 } else {
1164 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1165 if (err != JVMTI_ERROR_NONE) {
1166 return err;
1167 }
1168 }
1169 if (max_frame_count < 0) {
1170 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
1171 }
1172 if (frame_buffer == NULL) {
1173 return JVMTI_ERROR_NULL_POINTER;
1174 }
1175 if (count_ptr == NULL) {
1176 return JVMTI_ERROR_NULL_POINTER;
1177 }
1178 err = jvmti_env->GetStackTrace(java_thread, start_depth, max_frame_count, frame_buffer, count_ptr);
1179 return err;
1180#endif // INCLUDE_JVMTI
1181}
1182
1183static jvmtiError JNICALL
1184jvmti_GetAllStackTraces(jvmtiEnv* env,
1185 jint max_frame_count,
1186 jvmtiStackInfo** stack_info_ptr,
1187 jint* thread_count_ptr) {
1188
1189#if !INCLUDE_JVMTI
1190 return JVMTI_ERROR_NOT_AVAILABLE;
1191#else
1192 if(!JvmtiEnv::is_vm_live()) {
1193 return JVMTI_ERROR_WRONG_PHASE;
1194 }
1195 Thread* this_thread = Thread::current_or_null();
1196 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1197 return JVMTI_ERROR_UNATTACHED_THREAD;
1198 }
1199 JavaThread* current_thread = (JavaThread*)this_thread;
1200 ThreadInVMfromNative __tiv(current_thread);
1201 VM_ENTRY_BASE(jvmtiError, jvmti_GetAllStackTraces , current_thread)
1202 debug_only(VMNativeEntryWrapper __vew;)
1203 CautiouslyPreserveExceptionMark __em(this_thread);
1204 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1205 if (!jvmti_env->is_valid()) {
1206 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1207 }
1208 jvmtiError err;
1209 if (max_frame_count < 0) {
1210 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
1211 }
1212 if (stack_info_ptr == NULL) {
1213 return JVMTI_ERROR_NULL_POINTER;
1214 }
1215 if (thread_count_ptr == NULL) {
1216 return JVMTI_ERROR_NULL_POINTER;
1217 }
1218 err = jvmti_env->GetAllStackTraces(max_frame_count, stack_info_ptr, thread_count_ptr);
1219 return err;
1220#endif // INCLUDE_JVMTI
1221}
1222
1223static jvmtiError JNICALL
1224jvmti_GetThreadListStackTraces(jvmtiEnv* env,
1225 jint thread_count,
1226 const jthread* thread_list,
1227 jint max_frame_count,
1228 jvmtiStackInfo** stack_info_ptr) {
1229
1230#if !INCLUDE_JVMTI
1231 return JVMTI_ERROR_NOT_AVAILABLE;
1232#else
1233 if(!JvmtiEnv::is_vm_live()) {
1234 return JVMTI_ERROR_WRONG_PHASE;
1235 }
1236 Thread* this_thread = Thread::current_or_null();
1237 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1238 return JVMTI_ERROR_UNATTACHED_THREAD;
1239 }
1240 JavaThread* current_thread = (JavaThread*)this_thread;
1241 ThreadInVMfromNative __tiv(current_thread);
1242 VM_ENTRY_BASE(jvmtiError, jvmti_GetThreadListStackTraces , current_thread)
1243 debug_only(VMNativeEntryWrapper __vew;)
1244 CautiouslyPreserveExceptionMark __em(this_thread);
1245 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1246 if (!jvmti_env->is_valid()) {
1247 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1248 }
1249 jvmtiError err;
1250 if (thread_count < 0) {
1251 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
1252 }
1253 if (thread_list == NULL) {
1254 return JVMTI_ERROR_NULL_POINTER;
1255 }
1256 if (max_frame_count < 0) {
1257 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
1258 }
1259 if (stack_info_ptr == NULL) {
1260 return JVMTI_ERROR_NULL_POINTER;
1261 }
1262 err = jvmti_env->GetThreadListStackTraces(thread_count, thread_list, max_frame_count, stack_info_ptr);
1263 return err;
1264#endif // INCLUDE_JVMTI
1265}
1266
1267static jvmtiError JNICALL
1268jvmti_GetFrameCount(jvmtiEnv* env,
1269 jthread thread,
1270 jint* count_ptr) {
1271
1272#if !INCLUDE_JVMTI
1273 return JVMTI_ERROR_NOT_AVAILABLE;
1274#else
1275 if(!JvmtiEnv::is_vm_live()) {
1276 return JVMTI_ERROR_WRONG_PHASE;
1277 }
1278 Thread* this_thread = Thread::current_or_null();
1279 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1280 return JVMTI_ERROR_UNATTACHED_THREAD;
1281 }
1282 JavaThread* current_thread = (JavaThread*)this_thread;
1283 ThreadInVMfromNative __tiv(current_thread);
1284 VM_ENTRY_BASE(jvmtiError, jvmti_GetFrameCount , current_thread)
1285 debug_only(VMNativeEntryWrapper __vew;)
1286 CautiouslyPreserveExceptionMark __em(this_thread);
1287 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1288 if (!jvmti_env->is_valid()) {
1289 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1290 }
1291 jvmtiError err;
1292 JavaThread* java_thread = NULL;
1293 ThreadsListHandle tlh(this_thread);
1294 if (thread == NULL) {
1295 java_thread = current_thread;
1296 } else {
1297 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1298 if (err != JVMTI_ERROR_NONE) {
1299 return err;
1300 }
1301 }
1302 if (count_ptr == NULL) {
1303 return JVMTI_ERROR_NULL_POINTER;
1304 }
1305 err = jvmti_env->GetFrameCount(java_thread, count_ptr);
1306 return err;
1307#endif // INCLUDE_JVMTI
1308}
1309
1310static jvmtiError JNICALL
1311jvmti_PopFrame(jvmtiEnv* env,
1312 jthread thread) {
1313
1314#if !INCLUDE_JVMTI
1315 return JVMTI_ERROR_NOT_AVAILABLE;
1316#else
1317 if(!JvmtiEnv::is_vm_live()) {
1318 return JVMTI_ERROR_WRONG_PHASE;
1319 }
1320 Thread* this_thread = Thread::current_or_null();
1321 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1322 return JVMTI_ERROR_UNATTACHED_THREAD;
1323 }
1324 JavaThread* current_thread = (JavaThread*)this_thread;
1325 ThreadInVMfromNative __tiv(current_thread);
1326 VM_ENTRY_BASE(jvmtiError, jvmti_PopFrame , current_thread)
1327 debug_only(VMNativeEntryWrapper __vew;)
1328 CautiouslyPreserveExceptionMark __em(this_thread);
1329 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1330 if (!jvmti_env->is_valid()) {
1331 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1332 }
1333
1334 if (jvmti_env->get_capabilities()->can_pop_frame == 0) {
1335 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1336 }
1337 jvmtiError err;
1338 JavaThread* java_thread = NULL;
1339 ThreadsListHandle tlh(this_thread);
1340 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1341 if (err != JVMTI_ERROR_NONE) {
1342 return err;
1343 }
1344 err = jvmti_env->PopFrame(java_thread);
1345 return err;
1346#endif // INCLUDE_JVMTI
1347}
1348
1349static jvmtiError JNICALL
1350jvmti_GetFrameLocation(jvmtiEnv* env,
1351 jthread thread,
1352 jint depth,
1353 jmethodID* method_ptr,
1354 jlocation* location_ptr) {
1355
1356#if !INCLUDE_JVMTI
1357 return JVMTI_ERROR_NOT_AVAILABLE;
1358#else
1359 if(!JvmtiEnv::is_vm_live()) {
1360 return JVMTI_ERROR_WRONG_PHASE;
1361 }
1362 Thread* this_thread = Thread::current_or_null();
1363 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1364 return JVMTI_ERROR_UNATTACHED_THREAD;
1365 }
1366 JavaThread* current_thread = (JavaThread*)this_thread;
1367 ThreadInVMfromNative __tiv(current_thread);
1368 VM_ENTRY_BASE(jvmtiError, jvmti_GetFrameLocation , current_thread)
1369 debug_only(VMNativeEntryWrapper __vew;)
1370 CautiouslyPreserveExceptionMark __em(this_thread);
1371 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1372 if (!jvmti_env->is_valid()) {
1373 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1374 }
1375 jvmtiError err;
1376 JavaThread* java_thread = NULL;
1377 ThreadsListHandle tlh(this_thread);
1378 if (thread == NULL) {
1379 java_thread = current_thread;
1380 } else {
1381 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1382 if (err != JVMTI_ERROR_NONE) {
1383 return err;
1384 }
1385 }
1386
1387 if (depth < 0) {
1388 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
1389 }
1390 if (method_ptr == NULL) {
1391 return JVMTI_ERROR_NULL_POINTER;
1392 }
1393 if (location_ptr == NULL) {
1394 return JVMTI_ERROR_NULL_POINTER;
1395 }
1396 err = jvmti_env->GetFrameLocation(java_thread, depth, method_ptr, location_ptr);
1397 return err;
1398#endif // INCLUDE_JVMTI
1399}
1400
1401static jvmtiError JNICALL
1402jvmti_NotifyFramePop(jvmtiEnv* env,
1403 jthread thread,
1404 jint depth) {
1405
1406#if !INCLUDE_JVMTI
1407 return JVMTI_ERROR_NOT_AVAILABLE;
1408#else
1409 if(!JvmtiEnv::is_vm_live()) {
1410 return JVMTI_ERROR_WRONG_PHASE;
1411 }
1412 Thread* this_thread = Thread::current_or_null();
1413 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1414 return JVMTI_ERROR_UNATTACHED_THREAD;
1415 }
1416 JavaThread* current_thread = (JavaThread*)this_thread;
1417 ThreadInVMfromNative __tiv(current_thread);
1418 VM_ENTRY_BASE(jvmtiError, jvmti_NotifyFramePop , current_thread)
1419 debug_only(VMNativeEntryWrapper __vew;)
1420 CautiouslyPreserveExceptionMark __em(this_thread);
1421 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1422 if (!jvmti_env->is_valid()) {
1423 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1424 }
1425
1426 if (jvmti_env->get_capabilities()->can_generate_frame_pop_events == 0) {
1427 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1428 }
1429 jvmtiError err;
1430 JavaThread* java_thread = NULL;
1431 ThreadsListHandle tlh(this_thread);
1432 if (thread == NULL) {
1433 java_thread = current_thread;
1434 } else {
1435 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1436 if (err != JVMTI_ERROR_NONE) {
1437 return err;
1438 }
1439 }
1440
1441 if (depth < 0) {
1442 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
1443 }
1444 err = jvmti_env->NotifyFramePop(java_thread, depth);
1445 return err;
1446#endif // INCLUDE_JVMTI
1447}
1448
1449 //
1450 // Force Early Return functions
1451 //
1452
1453static jvmtiError JNICALL
1454jvmti_ForceEarlyReturnObject(jvmtiEnv* env,
1455 jthread thread,
1456 jobject value) {
1457
1458#if !INCLUDE_JVMTI
1459 return JVMTI_ERROR_NOT_AVAILABLE;
1460#else
1461 if(!JvmtiEnv::is_vm_live()) {
1462 return JVMTI_ERROR_WRONG_PHASE;
1463 }
1464 Thread* this_thread = Thread::current_or_null();
1465 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1466 return JVMTI_ERROR_UNATTACHED_THREAD;
1467 }
1468 JavaThread* current_thread = (JavaThread*)this_thread;
1469 ThreadInVMfromNative __tiv(current_thread);
1470 VM_ENTRY_BASE(jvmtiError, jvmti_ForceEarlyReturnObject , current_thread)
1471 debug_only(VMNativeEntryWrapper __vew;)
1472 CautiouslyPreserveExceptionMark __em(this_thread);
1473 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1474 if (!jvmti_env->is_valid()) {
1475 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1476 }
1477
1478 if (jvmti_env->get_capabilities()->can_force_early_return == 0) {
1479 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1480 }
1481 jvmtiError err;
1482 JavaThread* java_thread = NULL;
1483 ThreadsListHandle tlh(this_thread);
1484 if (thread == NULL) {
1485 java_thread = current_thread;
1486 } else {
1487 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1488 if (err != JVMTI_ERROR_NONE) {
1489 return err;
1490 }
1491 }
1492 err = jvmti_env->ForceEarlyReturnObject(java_thread, value);
1493 return err;
1494#endif // INCLUDE_JVMTI
1495}
1496
1497static jvmtiError JNICALL
1498jvmti_ForceEarlyReturnInt(jvmtiEnv* env,
1499 jthread thread,
1500 jint value) {
1501
1502#if !INCLUDE_JVMTI
1503 return JVMTI_ERROR_NOT_AVAILABLE;
1504#else
1505 if(!JvmtiEnv::is_vm_live()) {
1506 return JVMTI_ERROR_WRONG_PHASE;
1507 }
1508 Thread* this_thread = Thread::current_or_null();
1509 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1510 return JVMTI_ERROR_UNATTACHED_THREAD;
1511 }
1512 JavaThread* current_thread = (JavaThread*)this_thread;
1513 ThreadInVMfromNative __tiv(current_thread);
1514 VM_ENTRY_BASE(jvmtiError, jvmti_ForceEarlyReturnInt , current_thread)
1515 debug_only(VMNativeEntryWrapper __vew;)
1516 CautiouslyPreserveExceptionMark __em(this_thread);
1517 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1518 if (!jvmti_env->is_valid()) {
1519 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1520 }
1521
1522 if (jvmti_env->get_capabilities()->can_force_early_return == 0) {
1523 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1524 }
1525 jvmtiError err;
1526 JavaThread* java_thread = NULL;
1527 ThreadsListHandle tlh(this_thread);
1528 if (thread == NULL) {
1529 java_thread = current_thread;
1530 } else {
1531 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1532 if (err != JVMTI_ERROR_NONE) {
1533 return err;
1534 }
1535 }
1536 err = jvmti_env->ForceEarlyReturnInt(java_thread, value);
1537 return err;
1538#endif // INCLUDE_JVMTI
1539}
1540
1541static jvmtiError JNICALL
1542jvmti_ForceEarlyReturnLong(jvmtiEnv* env,
1543 jthread thread,
1544 jlong value) {
1545
1546#if !INCLUDE_JVMTI
1547 return JVMTI_ERROR_NOT_AVAILABLE;
1548#else
1549 if(!JvmtiEnv::is_vm_live()) {
1550 return JVMTI_ERROR_WRONG_PHASE;
1551 }
1552 Thread* this_thread = Thread::current_or_null();
1553 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1554 return JVMTI_ERROR_UNATTACHED_THREAD;
1555 }
1556 JavaThread* current_thread = (JavaThread*)this_thread;
1557 ThreadInVMfromNative __tiv(current_thread);
1558 VM_ENTRY_BASE(jvmtiError, jvmti_ForceEarlyReturnLong , current_thread)
1559 debug_only(VMNativeEntryWrapper __vew;)
1560 CautiouslyPreserveExceptionMark __em(this_thread);
1561 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1562 if (!jvmti_env->is_valid()) {
1563 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1564 }
1565
1566 if (jvmti_env->get_capabilities()->can_force_early_return == 0) {
1567 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1568 }
1569 jvmtiError err;
1570 JavaThread* java_thread = NULL;
1571 ThreadsListHandle tlh(this_thread);
1572 if (thread == NULL) {
1573 java_thread = current_thread;
1574 } else {
1575 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1576 if (err != JVMTI_ERROR_NONE) {
1577 return err;
1578 }
1579 }
1580 err = jvmti_env->ForceEarlyReturnLong(java_thread, value);
1581 return err;
1582#endif // INCLUDE_JVMTI
1583}
1584
1585static jvmtiError JNICALL
1586jvmti_ForceEarlyReturnFloat(jvmtiEnv* env,
1587 jthread thread,
1588 jfloat value) {
1589
1590#if !INCLUDE_JVMTI
1591 return JVMTI_ERROR_NOT_AVAILABLE;
1592#else
1593 if(!JvmtiEnv::is_vm_live()) {
1594 return JVMTI_ERROR_WRONG_PHASE;
1595 }
1596 Thread* this_thread = Thread::current_or_null();
1597 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1598 return JVMTI_ERROR_UNATTACHED_THREAD;
1599 }
1600 JavaThread* current_thread = (JavaThread*)this_thread;
1601 ThreadInVMfromNative __tiv(current_thread);
1602 VM_ENTRY_BASE(jvmtiError, jvmti_ForceEarlyReturnFloat , current_thread)
1603 debug_only(VMNativeEntryWrapper __vew;)
1604 CautiouslyPreserveExceptionMark __em(this_thread);
1605 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1606 if (!jvmti_env->is_valid()) {
1607 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1608 }
1609
1610 if (jvmti_env->get_capabilities()->can_force_early_return == 0) {
1611 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1612 }
1613 jvmtiError err;
1614 JavaThread* java_thread = NULL;
1615 ThreadsListHandle tlh(this_thread);
1616 if (thread == NULL) {
1617 java_thread = current_thread;
1618 } else {
1619 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1620 if (err != JVMTI_ERROR_NONE) {
1621 return err;
1622 }
1623 }
1624 err = jvmti_env->ForceEarlyReturnFloat(java_thread, value);
1625 return err;
1626#endif // INCLUDE_JVMTI
1627}
1628
1629static jvmtiError JNICALL
1630jvmti_ForceEarlyReturnDouble(jvmtiEnv* env,
1631 jthread thread,
1632 jdouble value) {
1633
1634#if !INCLUDE_JVMTI
1635 return JVMTI_ERROR_NOT_AVAILABLE;
1636#else
1637 if(!JvmtiEnv::is_vm_live()) {
1638 return JVMTI_ERROR_WRONG_PHASE;
1639 }
1640 Thread* this_thread = Thread::current_or_null();
1641 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1642 return JVMTI_ERROR_UNATTACHED_THREAD;
1643 }
1644 JavaThread* current_thread = (JavaThread*)this_thread;
1645 ThreadInVMfromNative __tiv(current_thread);
1646 VM_ENTRY_BASE(jvmtiError, jvmti_ForceEarlyReturnDouble , current_thread)
1647 debug_only(VMNativeEntryWrapper __vew;)
1648 CautiouslyPreserveExceptionMark __em(this_thread);
1649 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1650 if (!jvmti_env->is_valid()) {
1651 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1652 }
1653
1654 if (jvmti_env->get_capabilities()->can_force_early_return == 0) {
1655 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1656 }
1657 jvmtiError err;
1658 JavaThread* java_thread = NULL;
1659 ThreadsListHandle tlh(this_thread);
1660 if (thread == NULL) {
1661 java_thread = current_thread;
1662 } else {
1663 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1664 if (err != JVMTI_ERROR_NONE) {
1665 return err;
1666 }
1667 }
1668 err = jvmti_env->ForceEarlyReturnDouble(java_thread, value);
1669 return err;
1670#endif // INCLUDE_JVMTI
1671}
1672
1673static jvmtiError JNICALL
1674jvmti_ForceEarlyReturnVoid(jvmtiEnv* env,
1675 jthread thread) {
1676
1677#if !INCLUDE_JVMTI
1678 return JVMTI_ERROR_NOT_AVAILABLE;
1679#else
1680 if(!JvmtiEnv::is_vm_live()) {
1681 return JVMTI_ERROR_WRONG_PHASE;
1682 }
1683 Thread* this_thread = Thread::current_or_null();
1684 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1685 return JVMTI_ERROR_UNATTACHED_THREAD;
1686 }
1687 JavaThread* current_thread = (JavaThread*)this_thread;
1688 ThreadInVMfromNative __tiv(current_thread);
1689 VM_ENTRY_BASE(jvmtiError, jvmti_ForceEarlyReturnVoid , current_thread)
1690 debug_only(VMNativeEntryWrapper __vew;)
1691 CautiouslyPreserveExceptionMark __em(this_thread);
1692 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1693 if (!jvmti_env->is_valid()) {
1694 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1695 }
1696
1697 if (jvmti_env->get_capabilities()->can_force_early_return == 0) {
1698 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1699 }
1700 jvmtiError err;
1701 JavaThread* java_thread = NULL;
1702 ThreadsListHandle tlh(this_thread);
1703 if (thread == NULL) {
1704 java_thread = current_thread;
1705 } else {
1706 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1707 if (err != JVMTI_ERROR_NONE) {
1708 return err;
1709 }
1710 }
1711 err = jvmti_env->ForceEarlyReturnVoid(java_thread);
1712 return err;
1713#endif // INCLUDE_JVMTI
1714}
1715
1716 //
1717 // Heap functions
1718 //
1719
1720static jvmtiError JNICALL
1721jvmti_FollowReferences(jvmtiEnv* env,
1722 jint heap_filter,
1723 jclass klass,
1724 jobject initial_object,
1725 const jvmtiHeapCallbacks* callbacks,
1726 const void* user_data) {
1727
1728#if !INCLUDE_JVMTI
1729 return JVMTI_ERROR_NOT_AVAILABLE;
1730#else
1731 if(!JvmtiEnv::is_vm_live()) {
1732 return JVMTI_ERROR_WRONG_PHASE;
1733 }
1734 Thread* this_thread = Thread::current_or_null();
1735 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1736 return JVMTI_ERROR_UNATTACHED_THREAD;
1737 }
1738 JavaThread* current_thread = (JavaThread*)this_thread;
1739 ThreadInVMfromNative __tiv(current_thread);
1740 VM_ENTRY_BASE(jvmtiError, jvmti_FollowReferences , current_thread)
1741 debug_only(VMNativeEntryWrapper __vew;)
1742 CautiouslyPreserveExceptionMark __em(this_thread);
1743 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1744 if (!jvmti_env->is_valid()) {
1745 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1746 }
1747
1748 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
1749 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1750 }
1751 jvmtiError err;
1752 if (callbacks == NULL) {
1753 return JVMTI_ERROR_NULL_POINTER;
1754 }
1755 err = jvmti_env->FollowReferences(heap_filter, klass, initial_object, callbacks, user_data);
1756 return err;
1757#endif // INCLUDE_JVMTI
1758}
1759
1760static jvmtiError JNICALL
1761jvmti_IterateThroughHeap(jvmtiEnv* env,
1762 jint heap_filter,
1763 jclass klass,
1764 const jvmtiHeapCallbacks* callbacks,
1765 const void* user_data) {
1766
1767#if !INCLUDE_JVMTI
1768 return JVMTI_ERROR_NOT_AVAILABLE;
1769#else
1770 if(!JvmtiEnv::is_vm_live()) {
1771 return JVMTI_ERROR_WRONG_PHASE;
1772 }
1773 Thread* this_thread = Thread::current_or_null();
1774 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1775 return JVMTI_ERROR_UNATTACHED_THREAD;
1776 }
1777 JavaThread* current_thread = (JavaThread*)this_thread;
1778 ThreadInVMfromNative __tiv(current_thread);
1779 VM_ENTRY_BASE(jvmtiError, jvmti_IterateThroughHeap , current_thread)
1780 debug_only(VMNativeEntryWrapper __vew;)
1781 CautiouslyPreserveExceptionMark __em(this_thread);
1782 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1783 if (!jvmti_env->is_valid()) {
1784 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1785 }
1786
1787 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
1788 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1789 }
1790 jvmtiError err;
1791 if (callbacks == NULL) {
1792 return JVMTI_ERROR_NULL_POINTER;
1793 }
1794 err = jvmti_env->IterateThroughHeap(heap_filter, klass, callbacks, user_data);
1795 return err;
1796#endif // INCLUDE_JVMTI
1797}
1798
1799static jvmtiError JNICALL
1800jvmti_GetTag(jvmtiEnv* env,
1801 jobject object,
1802 jlong* tag_ptr) {
1803
1804#if !INCLUDE_JVMTI
1805 return JVMTI_ERROR_NOT_AVAILABLE;
1806#else
1807 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
1808 return JVMTI_ERROR_WRONG_PHASE;
1809 }
1810 Thread* this_thread = Thread::current_or_null();
1811 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1812 return JVMTI_ERROR_UNATTACHED_THREAD;
1813 }
1814 JavaThread* current_thread = (JavaThread*)this_thread;
1815 ThreadInVMfromNative __tiv(current_thread);
1816 VM_ENTRY_BASE(jvmtiError, jvmti_GetTag , current_thread)
1817 debug_only(VMNativeEntryWrapper __vew;)
1818 CautiouslyPreserveExceptionMark __em(this_thread);
1819 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1820 if (!jvmti_env->is_valid()) {
1821 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1822 }
1823
1824 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
1825 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1826 }
1827 jvmtiError err;
1828 if (tag_ptr == NULL) {
1829 return JVMTI_ERROR_NULL_POINTER;
1830 }
1831 err = jvmti_env->GetTag(object, tag_ptr);
1832 return err;
1833#endif // INCLUDE_JVMTI
1834}
1835
1836static jvmtiError JNICALL
1837jvmti_SetTag(jvmtiEnv* env,
1838 jobject object,
1839 jlong tag) {
1840
1841#if !INCLUDE_JVMTI
1842 return JVMTI_ERROR_NOT_AVAILABLE;
1843#else
1844 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
1845 return JVMTI_ERROR_WRONG_PHASE;
1846 }
1847 Thread* this_thread = Thread::current_or_null();
1848 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1849 return JVMTI_ERROR_UNATTACHED_THREAD;
1850 }
1851 JavaThread* current_thread = (JavaThread*)this_thread;
1852 ThreadInVMfromNative __tiv(current_thread);
1853 VM_ENTRY_BASE(jvmtiError, jvmti_SetTag , current_thread)
1854 debug_only(VMNativeEntryWrapper __vew;)
1855 CautiouslyPreserveExceptionMark __em(this_thread);
1856 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1857 if (!jvmti_env->is_valid()) {
1858 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1859 }
1860
1861 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
1862 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1863 }
1864 jvmtiError err;
1865 err = jvmti_env->SetTag(object, tag);
1866 return err;
1867#endif // INCLUDE_JVMTI
1868}
1869
1870static jvmtiError JNICALL
1871jvmti_GetObjectsWithTags(jvmtiEnv* env,
1872 jint tag_count,
1873 const jlong* tags,
1874 jint* count_ptr,
1875 jobject** object_result_ptr,
1876 jlong** tag_result_ptr) {
1877
1878#if !INCLUDE_JVMTI
1879 return JVMTI_ERROR_NOT_AVAILABLE;
1880#else
1881 if(!JvmtiEnv::is_vm_live()) {
1882 return JVMTI_ERROR_WRONG_PHASE;
1883 }
1884 Thread* this_thread = Thread::current_or_null();
1885 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1886 return JVMTI_ERROR_UNATTACHED_THREAD;
1887 }
1888 JavaThread* current_thread = (JavaThread*)this_thread;
1889 ThreadInVMfromNative __tiv(current_thread);
1890 VM_ENTRY_BASE(jvmtiError, jvmti_GetObjectsWithTags , current_thread)
1891 debug_only(VMNativeEntryWrapper __vew;)
1892 CautiouslyPreserveExceptionMark __em(this_thread);
1893 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1894 if (!jvmti_env->is_valid()) {
1895 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1896 }
1897
1898 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
1899 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1900 }
1901 jvmtiError err;
1902 if (tag_count < 0) {
1903 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
1904 }
1905 if (tags == NULL) {
1906 return JVMTI_ERROR_NULL_POINTER;
1907 }
1908 if (count_ptr == NULL) {
1909 return JVMTI_ERROR_NULL_POINTER;
1910 }
1911 err = jvmti_env->GetObjectsWithTags(tag_count, tags, count_ptr, object_result_ptr, tag_result_ptr);
1912 return err;
1913#endif // INCLUDE_JVMTI
1914}
1915
1916static jvmtiError JNICALL
1917jvmti_ForceGarbageCollection(jvmtiEnv* env) {
1918
1919#if !INCLUDE_JVMTI
1920 return JVMTI_ERROR_NOT_AVAILABLE;
1921#else
1922 if(!JvmtiEnv::is_vm_live()) {
1923 return JVMTI_ERROR_WRONG_PHASE;
1924 }
1925 Thread* this_thread = Thread::current_or_null();
1926 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1927 return JVMTI_ERROR_UNATTACHED_THREAD;
1928 }
1929 JavaThread* current_thread = (JavaThread*)this_thread;
1930 ThreadInVMfromNative __tiv(current_thread);
1931 VM_ENTRY_BASE(jvmtiError, jvmti_ForceGarbageCollection , current_thread)
1932 debug_only(VMNativeEntryWrapper __vew;)
1933 CautiouslyPreserveExceptionMark __em(this_thread);
1934 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1935 if (!jvmti_env->is_valid()) {
1936 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1937 }
1938 jvmtiError err;
1939 err = jvmti_env->ForceGarbageCollection();
1940 return err;
1941#endif // INCLUDE_JVMTI
1942}
1943
1944 //
1945 // Heap (1.0) functions
1946 //
1947
1948static jvmtiError JNICALL
1949jvmti_IterateOverObjectsReachableFromObject(jvmtiEnv* env,
1950 jobject object,
1951 jvmtiObjectReferenceCallback object_reference_callback,
1952 const void* user_data) {
1953
1954#if !INCLUDE_JVMTI
1955 return JVMTI_ERROR_NOT_AVAILABLE;
1956#else
1957 if(!JvmtiEnv::is_vm_live()) {
1958 return JVMTI_ERROR_WRONG_PHASE;
1959 }
1960 Thread* this_thread = Thread::current_or_null();
1961 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1962 return JVMTI_ERROR_UNATTACHED_THREAD;
1963 }
1964 JavaThread* current_thread = (JavaThread*)this_thread;
1965 ThreadInVMfromNative __tiv(current_thread);
1966 VM_ENTRY_BASE(jvmtiError, jvmti_IterateOverObjectsReachableFromObject , current_thread)
1967 debug_only(VMNativeEntryWrapper __vew;)
1968 CautiouslyPreserveExceptionMark __em(this_thread);
1969 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1970 if (!jvmti_env->is_valid()) {
1971 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1972 }
1973
1974 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
1975 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1976 }
1977 jvmtiError err;
1978 if (object_reference_callback == NULL) {
1979 return JVMTI_ERROR_NULL_POINTER;
1980 }
1981 err = jvmti_env->IterateOverObjectsReachableFromObject(object, object_reference_callback, user_data);
1982 return err;
1983#endif // INCLUDE_JVMTI
1984}
1985
1986static jvmtiError JNICALL
1987jvmti_IterateOverReachableObjects(jvmtiEnv* env,
1988 jvmtiHeapRootCallback heap_root_callback,
1989 jvmtiStackReferenceCallback stack_ref_callback,
1990 jvmtiObjectReferenceCallback object_ref_callback,
1991 const void* user_data) {
1992
1993#if !INCLUDE_JVMTI
1994 return JVMTI_ERROR_NOT_AVAILABLE;
1995#else
1996 if(!JvmtiEnv::is_vm_live()) {
1997 return JVMTI_ERROR_WRONG_PHASE;
1998 }
1999 Thread* this_thread = Thread::current_or_null();
2000 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2001 return JVMTI_ERROR_UNATTACHED_THREAD;
2002 }
2003 JavaThread* current_thread = (JavaThread*)this_thread;
2004 ThreadInVMfromNative __tiv(current_thread);
2005 VM_ENTRY_BASE(jvmtiError, jvmti_IterateOverReachableObjects , current_thread)
2006 debug_only(VMNativeEntryWrapper __vew;)
2007 CautiouslyPreserveExceptionMark __em(this_thread);
2008 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2009 if (!jvmti_env->is_valid()) {
2010 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2011 }
2012
2013 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
2014 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2015 }
2016 jvmtiError err;
2017 err = jvmti_env->IterateOverReachableObjects(heap_root_callback, stack_ref_callback, object_ref_callback, user_data);
2018 return err;
2019#endif // INCLUDE_JVMTI
2020}
2021
2022static jvmtiError JNICALL
2023jvmti_IterateOverHeap(jvmtiEnv* env,
2024 jvmtiHeapObjectFilter object_filter,
2025 jvmtiHeapObjectCallback heap_object_callback,
2026 const void* user_data) {
2027
2028#if !INCLUDE_JVMTI
2029 return JVMTI_ERROR_NOT_AVAILABLE;
2030#else
2031 if(!JvmtiEnv::is_vm_live()) {
2032 return JVMTI_ERROR_WRONG_PHASE;
2033 }
2034 Thread* this_thread = Thread::current_or_null();
2035 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2036 return JVMTI_ERROR_UNATTACHED_THREAD;
2037 }
2038 JavaThread* current_thread = (JavaThread*)this_thread;
2039 ThreadInVMfromNative __tiv(current_thread);
2040 VM_ENTRY_BASE(jvmtiError, jvmti_IterateOverHeap , current_thread)
2041 debug_only(VMNativeEntryWrapper __vew;)
2042 CautiouslyPreserveExceptionMark __em(this_thread);
2043 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2044 if (!jvmti_env->is_valid()) {
2045 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2046 }
2047
2048 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
2049 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2050 }
2051 jvmtiError err;
2052 if (heap_object_callback == NULL) {
2053 return JVMTI_ERROR_NULL_POINTER;
2054 }
2055 err = jvmti_env->IterateOverHeap(object_filter, heap_object_callback, user_data);
2056 return err;
2057#endif // INCLUDE_JVMTI
2058}
2059
2060static jvmtiError JNICALL
2061jvmti_IterateOverInstancesOfClass(jvmtiEnv* env,
2062 jclass klass,
2063 jvmtiHeapObjectFilter object_filter,
2064 jvmtiHeapObjectCallback heap_object_callback,
2065 const void* user_data) {
2066
2067#if !INCLUDE_JVMTI
2068 return JVMTI_ERROR_NOT_AVAILABLE;
2069#else
2070 if(!JvmtiEnv::is_vm_live()) {
2071 return JVMTI_ERROR_WRONG_PHASE;
2072 }
2073 Thread* this_thread = Thread::current_or_null();
2074 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2075 return JVMTI_ERROR_UNATTACHED_THREAD;
2076 }
2077 JavaThread* current_thread = (JavaThread*)this_thread;
2078 ThreadInVMfromNative __tiv(current_thread);
2079 VM_ENTRY_BASE(jvmtiError, jvmti_IterateOverInstancesOfClass , current_thread)
2080 debug_only(VMNativeEntryWrapper __vew;)
2081 CautiouslyPreserveExceptionMark __em(this_thread);
2082 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2083 if (!jvmti_env->is_valid()) {
2084 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2085 }
2086
2087 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
2088 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2089 }
2090 jvmtiError err;
2091 oop k_mirror = JNIHandles::resolve_external_guard(klass);
2092 if (k_mirror == NULL) {
2093 return JVMTI_ERROR_INVALID_CLASS;
2094 }
2095 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
2096 return JVMTI_ERROR_INVALID_CLASS;
2097 }
2098 if (heap_object_callback == NULL) {
2099 return JVMTI_ERROR_NULL_POINTER;
2100 }
2101 err = jvmti_env->IterateOverInstancesOfClass(k_mirror, object_filter, heap_object_callback, user_data);
2102 return err;
2103#endif // INCLUDE_JVMTI
2104}
2105
2106 //
2107 // Local Variable functions
2108 //
2109
2110static jvmtiError JNICALL
2111jvmti_GetLocalObject(jvmtiEnv* env,
2112 jthread thread,
2113 jint depth,
2114 jint slot,
2115 jobject* value_ptr) {
2116
2117#if !INCLUDE_JVMTI
2118 return JVMTI_ERROR_NOT_AVAILABLE;
2119#else
2120 if(!JvmtiEnv::is_vm_live()) {
2121 return JVMTI_ERROR_WRONG_PHASE;
2122 }
2123 Thread* this_thread = Thread::current_or_null();
2124 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2125 return JVMTI_ERROR_UNATTACHED_THREAD;
2126 }
2127 JavaThread* current_thread = (JavaThread*)this_thread;
2128 ThreadInVMfromNative __tiv(current_thread);
2129 VM_ENTRY_BASE(jvmtiError, jvmti_GetLocalObject , current_thread)
2130 debug_only(VMNativeEntryWrapper __vew;)
2131 CautiouslyPreserveExceptionMark __em(this_thread);
2132 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2133 if (!jvmti_env->is_valid()) {
2134 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2135 }
2136
2137 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
2138 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2139 }
2140 jvmtiError err;
2141 JavaThread* java_thread = NULL;
2142 ThreadsListHandle tlh(this_thread);
2143 if (thread == NULL) {
2144 java_thread = current_thread;
2145 } else {
2146 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
2147 if (err != JVMTI_ERROR_NONE) {
2148 return err;
2149 }
2150 }
2151
2152 if (depth < 0) {
2153 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2154 }
2155 if (value_ptr == NULL) {
2156 return JVMTI_ERROR_NULL_POINTER;
2157 }
2158 err = jvmti_env->GetLocalObject(java_thread, depth, slot, value_ptr);
2159 return err;
2160#endif // INCLUDE_JVMTI
2161}
2162
2163static jvmtiError JNICALL
2164jvmti_GetLocalInstance(jvmtiEnv* env,
2165 jthread thread,
2166 jint depth,
2167 jobject* value_ptr) {
2168
2169#if !INCLUDE_JVMTI
2170 return JVMTI_ERROR_NOT_AVAILABLE;
2171#else
2172 if(!JvmtiEnv::is_vm_live()) {
2173 return JVMTI_ERROR_WRONG_PHASE;
2174 }
2175 Thread* this_thread = Thread::current_or_null();
2176 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2177 return JVMTI_ERROR_UNATTACHED_THREAD;
2178 }
2179 JavaThread* current_thread = (JavaThread*)this_thread;
2180 ThreadInVMfromNative __tiv(current_thread);
2181 VM_ENTRY_BASE(jvmtiError, jvmti_GetLocalInstance , current_thread)
2182 debug_only(VMNativeEntryWrapper __vew;)
2183 CautiouslyPreserveExceptionMark __em(this_thread);
2184 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2185 if (!jvmti_env->is_valid()) {
2186 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2187 }
2188
2189 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
2190 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2191 }
2192 jvmtiError err;
2193 JavaThread* java_thread = NULL;
2194 ThreadsListHandle tlh(this_thread);
2195 if (thread == NULL) {
2196 java_thread = current_thread;
2197 } else {
2198 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
2199 if (err != JVMTI_ERROR_NONE) {
2200 return err;
2201 }
2202 }
2203
2204 if (depth < 0) {
2205 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2206 }
2207 if (value_ptr == NULL) {
2208 return JVMTI_ERROR_NULL_POINTER;
2209 }
2210 err = jvmti_env->GetLocalInstance(java_thread, depth, value_ptr);
2211 return err;
2212#endif // INCLUDE_JVMTI
2213}
2214
2215static jvmtiError JNICALL
2216jvmti_GetLocalInt(jvmtiEnv* env,
2217 jthread thread,
2218 jint depth,
2219 jint slot,
2220 jint* value_ptr) {
2221
2222#if !INCLUDE_JVMTI
2223 return JVMTI_ERROR_NOT_AVAILABLE;
2224#else
2225 if(!JvmtiEnv::is_vm_live()) {
2226 return JVMTI_ERROR_WRONG_PHASE;
2227 }
2228 Thread* this_thread = Thread::current_or_null();
2229 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2230 return JVMTI_ERROR_UNATTACHED_THREAD;
2231 }
2232 JavaThread* current_thread = (JavaThread*)this_thread;
2233 ThreadInVMfromNative __tiv(current_thread);
2234 VM_ENTRY_BASE(jvmtiError, jvmti_GetLocalInt , current_thread)
2235 debug_only(VMNativeEntryWrapper __vew;)
2236 CautiouslyPreserveExceptionMark __em(this_thread);
2237 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2238 if (!jvmti_env->is_valid()) {
2239 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2240 }
2241
2242 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
2243 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2244 }
2245 jvmtiError err;
2246 JavaThread* java_thread = NULL;
2247 ThreadsListHandle tlh(this_thread);
2248 if (thread == NULL) {
2249 java_thread = current_thread;
2250 } else {
2251 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
2252 if (err != JVMTI_ERROR_NONE) {
2253 return err;
2254 }
2255 }
2256
2257 if (depth < 0) {
2258 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2259 }
2260 if (value_ptr == NULL) {
2261 return JVMTI_ERROR_NULL_POINTER;
2262 }
2263 err = jvmti_env->GetLocalInt(java_thread, depth, slot, value_ptr);
2264 return err;
2265#endif // INCLUDE_JVMTI
2266}
2267
2268static jvmtiError JNICALL
2269jvmti_GetLocalLong(jvmtiEnv* env,
2270 jthread thread,
2271 jint depth,
2272 jint slot,
2273 jlong* value_ptr) {
2274
2275#if !INCLUDE_JVMTI
2276 return JVMTI_ERROR_NOT_AVAILABLE;
2277#else
2278 if(!JvmtiEnv::is_vm_live()) {
2279 return JVMTI_ERROR_WRONG_PHASE;
2280 }
2281 Thread* this_thread = Thread::current_or_null();
2282 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2283 return JVMTI_ERROR_UNATTACHED_THREAD;
2284 }
2285 JavaThread* current_thread = (JavaThread*)this_thread;
2286 ThreadInVMfromNative __tiv(current_thread);
2287 VM_ENTRY_BASE(jvmtiError, jvmti_GetLocalLong , current_thread)
2288 debug_only(VMNativeEntryWrapper __vew;)
2289 CautiouslyPreserveExceptionMark __em(this_thread);
2290 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2291 if (!jvmti_env->is_valid()) {
2292 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2293 }
2294
2295 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
2296 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2297 }
2298 jvmtiError err;
2299 JavaThread* java_thread = NULL;
2300 ThreadsListHandle tlh(this_thread);
2301 if (thread == NULL) {
2302 java_thread = current_thread;
2303 } else {
2304 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
2305 if (err != JVMTI_ERROR_NONE) {
2306 return err;
2307 }
2308 }
2309
2310 if (depth < 0) {
2311 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2312 }
2313 if (value_ptr == NULL) {
2314 return JVMTI_ERROR_NULL_POINTER;
2315 }
2316 err = jvmti_env->GetLocalLong(java_thread, depth, slot, value_ptr);
2317 return err;
2318#endif // INCLUDE_JVMTI
2319}
2320
2321static jvmtiError JNICALL
2322jvmti_GetLocalFloat(jvmtiEnv* env,
2323 jthread thread,
2324 jint depth,
2325 jint slot,
2326 jfloat* value_ptr) {
2327
2328#if !INCLUDE_JVMTI
2329 return JVMTI_ERROR_NOT_AVAILABLE;
2330#else
2331 if(!JvmtiEnv::is_vm_live()) {
2332 return JVMTI_ERROR_WRONG_PHASE;
2333 }
2334 Thread* this_thread = Thread::current_or_null();
2335 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2336 return JVMTI_ERROR_UNATTACHED_THREAD;
2337 }
2338 JavaThread* current_thread = (JavaThread*)this_thread;
2339 ThreadInVMfromNative __tiv(current_thread);
2340 VM_ENTRY_BASE(jvmtiError, jvmti_GetLocalFloat , current_thread)
2341 debug_only(VMNativeEntryWrapper __vew;)
2342 CautiouslyPreserveExceptionMark __em(this_thread);
2343 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2344 if (!jvmti_env->is_valid()) {
2345 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2346 }
2347
2348 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
2349 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2350 }
2351 jvmtiError err;
2352 JavaThread* java_thread = NULL;
2353 ThreadsListHandle tlh(this_thread);
2354 if (thread == NULL) {
2355 java_thread = current_thread;
2356 } else {
2357 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
2358 if (err != JVMTI_ERROR_NONE) {
2359 return err;
2360 }
2361 }
2362
2363 if (depth < 0) {
2364 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2365 }
2366 if (value_ptr == NULL) {
2367 return JVMTI_ERROR_NULL_POINTER;
2368 }
2369 err = jvmti_env->GetLocalFloat(java_thread, depth, slot, value_ptr);
2370 return err;
2371#endif // INCLUDE_JVMTI
2372}
2373
2374static jvmtiError JNICALL
2375jvmti_GetLocalDouble(jvmtiEnv* env,
2376 jthread thread,
2377 jint depth,
2378 jint slot,
2379 jdouble* value_ptr) {
2380
2381#if !INCLUDE_JVMTI
2382 return JVMTI_ERROR_NOT_AVAILABLE;
2383#else
2384 if(!JvmtiEnv::is_vm_live()) {
2385 return JVMTI_ERROR_WRONG_PHASE;
2386 }
2387 Thread* this_thread = Thread::current_or_null();
2388 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2389 return JVMTI_ERROR_UNATTACHED_THREAD;
2390 }
2391 JavaThread* current_thread = (JavaThread*)this_thread;
2392 ThreadInVMfromNative __tiv(current_thread);
2393 VM_ENTRY_BASE(jvmtiError, jvmti_GetLocalDouble , current_thread)
2394 debug_only(VMNativeEntryWrapper __vew;)
2395 CautiouslyPreserveExceptionMark __em(this_thread);
2396 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2397 if (!jvmti_env->is_valid()) {
2398 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2399 }
2400
2401 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
2402 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2403 }
2404 jvmtiError err;
2405 JavaThread* java_thread = NULL;
2406 ThreadsListHandle tlh(this_thread);
2407 if (thread == NULL) {
2408 java_thread = current_thread;
2409 } else {
2410 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
2411 if (err != JVMTI_ERROR_NONE) {
2412 return err;
2413 }
2414 }
2415
2416 if (depth < 0) {
2417 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2418 }
2419 if (value_ptr == NULL) {
2420 return JVMTI_ERROR_NULL_POINTER;
2421 }
2422 err = jvmti_env->GetLocalDouble(java_thread, depth, slot, value_ptr);
2423 return err;
2424#endif // INCLUDE_JVMTI
2425}
2426
2427static jvmtiError JNICALL
2428jvmti_SetLocalObject(jvmtiEnv* env,
2429 jthread thread,
2430 jint depth,
2431 jint slot,
2432 jobject value) {
2433
2434#if !INCLUDE_JVMTI
2435 return JVMTI_ERROR_NOT_AVAILABLE;
2436#else
2437 if(!JvmtiEnv::is_vm_live()) {
2438 return JVMTI_ERROR_WRONG_PHASE;
2439 }
2440 Thread* this_thread = Thread::current_or_null();
2441 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2442 return JVMTI_ERROR_UNATTACHED_THREAD;
2443 }
2444 JavaThread* current_thread = (JavaThread*)this_thread;
2445 ThreadInVMfromNative __tiv(current_thread);
2446 VM_ENTRY_BASE(jvmtiError, jvmti_SetLocalObject , current_thread)
2447 debug_only(VMNativeEntryWrapper __vew;)
2448 CautiouslyPreserveExceptionMark __em(this_thread);
2449 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2450 if (!jvmti_env->is_valid()) {
2451 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2452 }
2453
2454 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
2455 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2456 }
2457 jvmtiError err;
2458 JavaThread* java_thread = NULL;
2459 ThreadsListHandle tlh(this_thread);
2460 if (thread == NULL) {
2461 java_thread = current_thread;
2462 } else {
2463 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
2464 if (err != JVMTI_ERROR_NONE) {
2465 return err;
2466 }
2467 }
2468
2469 if (depth < 0) {
2470 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2471 }
2472 err = jvmti_env->SetLocalObject(java_thread, depth, slot, value);
2473 return err;
2474#endif // INCLUDE_JVMTI
2475}
2476
2477static jvmtiError JNICALL
2478jvmti_SetLocalInt(jvmtiEnv* env,
2479 jthread thread,
2480 jint depth,
2481 jint slot,
2482 jint value) {
2483
2484#if !INCLUDE_JVMTI
2485 return JVMTI_ERROR_NOT_AVAILABLE;
2486#else
2487 if(!JvmtiEnv::is_vm_live()) {
2488 return JVMTI_ERROR_WRONG_PHASE;
2489 }
2490 Thread* this_thread = Thread::current_or_null();
2491 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2492 return JVMTI_ERROR_UNATTACHED_THREAD;
2493 }
2494 JavaThread* current_thread = (JavaThread*)this_thread;
2495 ThreadInVMfromNative __tiv(current_thread);
2496 VM_ENTRY_BASE(jvmtiError, jvmti_SetLocalInt , current_thread)
2497 debug_only(VMNativeEntryWrapper __vew;)
2498 CautiouslyPreserveExceptionMark __em(this_thread);
2499 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2500 if (!jvmti_env->is_valid()) {
2501 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2502 }
2503
2504 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
2505 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2506 }
2507 jvmtiError err;
2508 JavaThread* java_thread = NULL;
2509 ThreadsListHandle tlh(this_thread);
2510 if (thread == NULL) {
2511 java_thread = current_thread;
2512 } else {
2513 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
2514 if (err != JVMTI_ERROR_NONE) {
2515 return err;
2516 }
2517 }
2518
2519 if (depth < 0) {
2520 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2521 }
2522 err = jvmti_env->SetLocalInt(java_thread, depth, slot, value);
2523 return err;
2524#endif // INCLUDE_JVMTI
2525}
2526
2527static jvmtiError JNICALL
2528jvmti_SetLocalLong(jvmtiEnv* env,
2529 jthread thread,
2530 jint depth,
2531 jint slot,
2532 jlong value) {
2533
2534#if !INCLUDE_JVMTI
2535 return JVMTI_ERROR_NOT_AVAILABLE;
2536#else
2537 if(!JvmtiEnv::is_vm_live()) {
2538 return JVMTI_ERROR_WRONG_PHASE;
2539 }
2540 Thread* this_thread = Thread::current_or_null();
2541 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2542 return JVMTI_ERROR_UNATTACHED_THREAD;
2543 }
2544 JavaThread* current_thread = (JavaThread*)this_thread;
2545 ThreadInVMfromNative __tiv(current_thread);
2546 VM_ENTRY_BASE(jvmtiError, jvmti_SetLocalLong , current_thread)
2547 debug_only(VMNativeEntryWrapper __vew;)
2548 CautiouslyPreserveExceptionMark __em(this_thread);
2549 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2550 if (!jvmti_env->is_valid()) {
2551 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2552 }
2553
2554 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
2555 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2556 }
2557 jvmtiError err;
2558 JavaThread* java_thread = NULL;
2559 ThreadsListHandle tlh(this_thread);
2560 if (thread == NULL) {
2561 java_thread = current_thread;
2562 } else {
2563 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
2564 if (err != JVMTI_ERROR_NONE) {
2565 return err;
2566 }
2567 }
2568
2569 if (depth < 0) {
2570 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2571 }
2572 err = jvmti_env->SetLocalLong(java_thread, depth, slot, value);
2573 return err;
2574#endif // INCLUDE_JVMTI
2575}
2576
2577static jvmtiError JNICALL
2578jvmti_SetLocalFloat(jvmtiEnv* env,
2579 jthread thread,
2580 jint depth,
2581 jint slot,
2582 jfloat value) {
2583
2584#if !INCLUDE_JVMTI
2585 return JVMTI_ERROR_NOT_AVAILABLE;
2586#else
2587 if(!JvmtiEnv::is_vm_live()) {
2588 return JVMTI_ERROR_WRONG_PHASE;
2589 }
2590 Thread* this_thread = Thread::current_or_null();
2591 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2592 return JVMTI_ERROR_UNATTACHED_THREAD;
2593 }
2594 JavaThread* current_thread = (JavaThread*)this_thread;
2595 ThreadInVMfromNative __tiv(current_thread);
2596 VM_ENTRY_BASE(jvmtiError, jvmti_SetLocalFloat , current_thread)
2597 debug_only(VMNativeEntryWrapper __vew;)
2598 CautiouslyPreserveExceptionMark __em(this_thread);
2599 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2600 if (!jvmti_env->is_valid()) {
2601 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2602 }
2603
2604 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
2605 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2606 }
2607 jvmtiError err;
2608 JavaThread* java_thread = NULL;
2609 ThreadsListHandle tlh(this_thread);
2610 if (thread == NULL) {
2611 java_thread = current_thread;
2612 } else {
2613 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
2614 if (err != JVMTI_ERROR_NONE) {
2615 return err;
2616 }
2617 }
2618
2619 if (depth < 0) {
2620 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2621 }
2622 err = jvmti_env->SetLocalFloat(java_thread, depth, slot, value);
2623 return err;
2624#endif // INCLUDE_JVMTI
2625}
2626
2627static jvmtiError JNICALL
2628jvmti_SetLocalDouble(jvmtiEnv* env,
2629 jthread thread,
2630 jint depth,
2631 jint slot,
2632 jdouble value) {
2633
2634#if !INCLUDE_JVMTI
2635 return JVMTI_ERROR_NOT_AVAILABLE;
2636#else
2637 if(!JvmtiEnv::is_vm_live()) {
2638 return JVMTI_ERROR_WRONG_PHASE;
2639 }
2640 Thread* this_thread = Thread::current_or_null();
2641 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2642 return JVMTI_ERROR_UNATTACHED_THREAD;
2643 }
2644 JavaThread* current_thread = (JavaThread*)this_thread;
2645 ThreadInVMfromNative __tiv(current_thread);
2646 VM_ENTRY_BASE(jvmtiError, jvmti_SetLocalDouble , current_thread)
2647 debug_only(VMNativeEntryWrapper __vew;)
2648 CautiouslyPreserveExceptionMark __em(this_thread);
2649 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2650 if (!jvmti_env->is_valid()) {
2651 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2652 }
2653
2654 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
2655 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2656 }
2657 jvmtiError err;
2658 JavaThread* java_thread = NULL;
2659 ThreadsListHandle tlh(this_thread);
2660 if (thread == NULL) {
2661 java_thread = current_thread;
2662 } else {
2663 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
2664 if (err != JVMTI_ERROR_NONE) {
2665 return err;
2666 }
2667 }
2668
2669 if (depth < 0) {
2670 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2671 }
2672 err = jvmti_env->SetLocalDouble(java_thread, depth, slot, value);
2673 return err;
2674#endif // INCLUDE_JVMTI
2675}
2676
2677 //
2678 // Breakpoint functions
2679 //
2680
2681static jvmtiError JNICALL
2682jvmti_SetBreakpoint(jvmtiEnv* env,
2683 jmethodID method,
2684 jlocation location) {
2685
2686#if !INCLUDE_JVMTI
2687 return JVMTI_ERROR_NOT_AVAILABLE;
2688#else
2689 if(!JvmtiEnv::is_vm_live()) {
2690 return JVMTI_ERROR_WRONG_PHASE;
2691 }
2692 Thread* this_thread = Thread::current_or_null();
2693 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2694 return JVMTI_ERROR_UNATTACHED_THREAD;
2695 }
2696 JavaThread* current_thread = (JavaThread*)this_thread;
2697 ThreadInVMfromNative __tiv(current_thread);
2698 VM_ENTRY_BASE(jvmtiError, jvmti_SetBreakpoint , current_thread)
2699 debug_only(VMNativeEntryWrapper __vew;)
2700 CautiouslyPreserveExceptionMark __em(this_thread);
2701 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2702 if (!jvmti_env->is_valid()) {
2703 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2704 }
2705
2706 if (jvmti_env->get_capabilities()->can_generate_breakpoint_events == 0) {
2707 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2708 }
2709 jvmtiError err;
2710 Method* method_oop = Method::checked_resolve_jmethod_id(method);
2711 if (method_oop == NULL) {
2712 return JVMTI_ERROR_INVALID_METHODID;
2713 }
2714 err = jvmti_env->SetBreakpoint(method_oop, location);
2715 return err;
2716#endif // INCLUDE_JVMTI
2717}
2718
2719static jvmtiError JNICALL
2720jvmti_ClearBreakpoint(jvmtiEnv* env,
2721 jmethodID method,
2722 jlocation location) {
2723
2724#if !INCLUDE_JVMTI
2725 return JVMTI_ERROR_NOT_AVAILABLE;
2726#else
2727 if(!JvmtiEnv::is_vm_live()) {
2728 return JVMTI_ERROR_WRONG_PHASE;
2729 }
2730 Thread* this_thread = Thread::current_or_null();
2731 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2732 return JVMTI_ERROR_UNATTACHED_THREAD;
2733 }
2734 JavaThread* current_thread = (JavaThread*)this_thread;
2735 ThreadInVMfromNative __tiv(current_thread);
2736 VM_ENTRY_BASE(jvmtiError, jvmti_ClearBreakpoint , current_thread)
2737 debug_only(VMNativeEntryWrapper __vew;)
2738 CautiouslyPreserveExceptionMark __em(this_thread);
2739 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2740 if (!jvmti_env->is_valid()) {
2741 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2742 }
2743
2744 if (jvmti_env->get_capabilities()->can_generate_breakpoint_events == 0) {
2745 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2746 }
2747 jvmtiError err;
2748 Method* method_oop = Method::checked_resolve_jmethod_id(method);
2749 if (method_oop == NULL) {
2750 return JVMTI_ERROR_INVALID_METHODID;
2751 }
2752 err = jvmti_env->ClearBreakpoint(method_oop, location);
2753 return err;
2754#endif // INCLUDE_JVMTI
2755}
2756
2757 //
2758 // Watched Field functions
2759 //
2760
2761static jvmtiError JNICALL
2762jvmti_SetFieldAccessWatch(jvmtiEnv* env,
2763 jclass klass,
2764 jfieldID field) {
2765
2766#if !INCLUDE_JVMTI
2767 return JVMTI_ERROR_NOT_AVAILABLE;
2768#else
2769 if(!JvmtiEnv::is_vm_live()) {
2770 return JVMTI_ERROR_WRONG_PHASE;
2771 }
2772 Thread* this_thread = Thread::current_or_null();
2773 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2774 return JVMTI_ERROR_UNATTACHED_THREAD;
2775 }
2776 JavaThread* current_thread = (JavaThread*)this_thread;
2777 ThreadInVMfromNative __tiv(current_thread);
2778 VM_ENTRY_BASE(jvmtiError, jvmti_SetFieldAccessWatch , current_thread)
2779 debug_only(VMNativeEntryWrapper __vew;)
2780 CautiouslyPreserveExceptionMark __em(this_thread);
2781 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2782 if (!jvmti_env->is_valid()) {
2783 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2784 }
2785
2786 if (jvmti_env->get_capabilities()->can_generate_field_access_events == 0) {
2787 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2788 }
2789 jvmtiError err;
2790 oop k_mirror = JNIHandles::resolve_external_guard(klass);
2791 if (k_mirror == NULL) {
2792 return JVMTI_ERROR_INVALID_CLASS;
2793 }
2794 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
2795 return JVMTI_ERROR_INVALID_CLASS;
2796 }
2797
2798 if (java_lang_Class::is_primitive(k_mirror)) {
2799 return JVMTI_ERROR_INVALID_CLASS;
2800 }
2801 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
2802 if (k_oop == NULL) {
2803 return JVMTI_ERROR_INVALID_CLASS;
2804 }
2805 ResourceMark rm_fdesc(current_thread);
2806 fieldDescriptor fdesc;
2807 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
2808 return JVMTI_ERROR_INVALID_FIELDID;
2809 }
2810 err = jvmti_env->SetFieldAccessWatch(&fdesc);
2811 return err;
2812#endif // INCLUDE_JVMTI
2813}
2814
2815static jvmtiError JNICALL
2816jvmti_ClearFieldAccessWatch(jvmtiEnv* env,
2817 jclass klass,
2818 jfieldID field) {
2819
2820#if !INCLUDE_JVMTI
2821 return JVMTI_ERROR_NOT_AVAILABLE;
2822#else
2823 if(!JvmtiEnv::is_vm_live()) {
2824 return JVMTI_ERROR_WRONG_PHASE;
2825 }
2826 Thread* this_thread = Thread::current_or_null();
2827 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2828 return JVMTI_ERROR_UNATTACHED_THREAD;
2829 }
2830 JavaThread* current_thread = (JavaThread*)this_thread;
2831 ThreadInVMfromNative __tiv(current_thread);
2832 VM_ENTRY_BASE(jvmtiError, jvmti_ClearFieldAccessWatch , current_thread)
2833 debug_only(VMNativeEntryWrapper __vew;)
2834 CautiouslyPreserveExceptionMark __em(this_thread);
2835 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2836 if (!jvmti_env->is_valid()) {
2837 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2838 }
2839
2840 if (jvmti_env->get_capabilities()->can_generate_field_access_events == 0) {
2841 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2842 }
2843 jvmtiError err;
2844 oop k_mirror = JNIHandles::resolve_external_guard(klass);
2845 if (k_mirror == NULL) {
2846 return JVMTI_ERROR_INVALID_CLASS;
2847 }
2848 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
2849 return JVMTI_ERROR_INVALID_CLASS;
2850 }
2851
2852 if (java_lang_Class::is_primitive(k_mirror)) {
2853 return JVMTI_ERROR_INVALID_CLASS;
2854 }
2855 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
2856 if (k_oop == NULL) {
2857 return JVMTI_ERROR_INVALID_CLASS;
2858 }
2859 ResourceMark rm_fdesc(current_thread);
2860 fieldDescriptor fdesc;
2861 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
2862 return JVMTI_ERROR_INVALID_FIELDID;
2863 }
2864 err = jvmti_env->ClearFieldAccessWatch(&fdesc);
2865 return err;
2866#endif // INCLUDE_JVMTI
2867}
2868
2869static jvmtiError JNICALL
2870jvmti_SetFieldModificationWatch(jvmtiEnv* env,
2871 jclass klass,
2872 jfieldID field) {
2873
2874#if !INCLUDE_JVMTI
2875 return JVMTI_ERROR_NOT_AVAILABLE;
2876#else
2877 if(!JvmtiEnv::is_vm_live()) {
2878 return JVMTI_ERROR_WRONG_PHASE;
2879 }
2880 Thread* this_thread = Thread::current_or_null();
2881 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2882 return JVMTI_ERROR_UNATTACHED_THREAD;
2883 }
2884 JavaThread* current_thread = (JavaThread*)this_thread;
2885 ThreadInVMfromNative __tiv(current_thread);
2886 VM_ENTRY_BASE(jvmtiError, jvmti_SetFieldModificationWatch , current_thread)
2887 debug_only(VMNativeEntryWrapper __vew;)
2888 CautiouslyPreserveExceptionMark __em(this_thread);
2889 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2890 if (!jvmti_env->is_valid()) {
2891 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2892 }
2893
2894 if (jvmti_env->get_capabilities()->can_generate_field_modification_events == 0) {
2895 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2896 }
2897 jvmtiError err;
2898 oop k_mirror = JNIHandles::resolve_external_guard(klass);
2899 if (k_mirror == NULL) {
2900 return JVMTI_ERROR_INVALID_CLASS;
2901 }
2902 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
2903 return JVMTI_ERROR_INVALID_CLASS;
2904 }
2905
2906 if (java_lang_Class::is_primitive(k_mirror)) {
2907 return JVMTI_ERROR_INVALID_CLASS;
2908 }
2909 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
2910 if (k_oop == NULL) {
2911 return JVMTI_ERROR_INVALID_CLASS;
2912 }
2913 ResourceMark rm_fdesc(current_thread);
2914 fieldDescriptor fdesc;
2915 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
2916 return JVMTI_ERROR_INVALID_FIELDID;
2917 }
2918 err = jvmti_env->SetFieldModificationWatch(&fdesc);
2919 return err;
2920#endif // INCLUDE_JVMTI
2921}
2922
2923static jvmtiError JNICALL
2924jvmti_ClearFieldModificationWatch(jvmtiEnv* env,
2925 jclass klass,
2926 jfieldID field) {
2927
2928#if !INCLUDE_JVMTI
2929 return JVMTI_ERROR_NOT_AVAILABLE;
2930#else
2931 if(!JvmtiEnv::is_vm_live()) {
2932 return JVMTI_ERROR_WRONG_PHASE;
2933 }
2934 Thread* this_thread = Thread::current_or_null();
2935 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2936 return JVMTI_ERROR_UNATTACHED_THREAD;
2937 }
2938 JavaThread* current_thread = (JavaThread*)this_thread;
2939 ThreadInVMfromNative __tiv(current_thread);
2940 VM_ENTRY_BASE(jvmtiError, jvmti_ClearFieldModificationWatch , current_thread)
2941 debug_only(VMNativeEntryWrapper __vew;)
2942 CautiouslyPreserveExceptionMark __em(this_thread);
2943 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2944 if (!jvmti_env->is_valid()) {
2945 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2946 }
2947
2948 if (jvmti_env->get_capabilities()->can_generate_field_modification_events == 0) {
2949 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2950 }
2951 jvmtiError err;
2952 oop k_mirror = JNIHandles::resolve_external_guard(klass);
2953 if (k_mirror == NULL) {
2954 return JVMTI_ERROR_INVALID_CLASS;
2955 }
2956 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
2957 return JVMTI_ERROR_INVALID_CLASS;
2958 }
2959
2960 if (java_lang_Class::is_primitive(k_mirror)) {
2961 return JVMTI_ERROR_INVALID_CLASS;
2962 }
2963 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
2964 if (k_oop == NULL) {
2965 return JVMTI_ERROR_INVALID_CLASS;
2966 }
2967 ResourceMark rm_fdesc(current_thread);
2968 fieldDescriptor fdesc;
2969 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
2970 return JVMTI_ERROR_INVALID_FIELDID;
2971 }
2972 err = jvmti_env->ClearFieldModificationWatch(&fdesc);
2973 return err;
2974#endif // INCLUDE_JVMTI
2975}
2976
2977 //
2978 // Module functions
2979 //
2980
2981static jvmtiError JNICALL
2982jvmti_GetAllModules(jvmtiEnv* env,
2983 jint* module_count_ptr,
2984 jobject** modules_ptr) {
2985
2986#if !INCLUDE_JVMTI
2987 return JVMTI_ERROR_NOT_AVAILABLE;
2988#else
2989 if(!JvmtiEnv::is_vm_live()) {
2990 return JVMTI_ERROR_WRONG_PHASE;
2991 }
2992 Thread* this_thread = Thread::current_or_null();
2993 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2994 return JVMTI_ERROR_UNATTACHED_THREAD;
2995 }
2996 JavaThread* current_thread = (JavaThread*)this_thread;
2997 ThreadInVMfromNative __tiv(current_thread);
2998 VM_ENTRY_BASE(jvmtiError, jvmti_GetAllModules , current_thread)
2999 debug_only(VMNativeEntryWrapper __vew;)
3000 CautiouslyPreserveExceptionMark __em(this_thread);
3001 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3002 if (!jvmti_env->is_valid()) {
3003 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3004 }
3005 jvmtiError err;
3006 if (module_count_ptr == NULL) {
3007 return JVMTI_ERROR_NULL_POINTER;
3008 }
3009 if (modules_ptr == NULL) {
3010 return JVMTI_ERROR_NULL_POINTER;
3011 }
3012 err = jvmti_env->GetAllModules(module_count_ptr, modules_ptr);
3013 return err;
3014#endif // INCLUDE_JVMTI
3015}
3016
3017static jvmtiError JNICALL
3018jvmti_GetNamedModule(jvmtiEnv* env,
3019 jobject class_loader,
3020 const char* package_name,
3021 jobject* module_ptr) {
3022
3023#if !INCLUDE_JVMTI
3024 return JVMTI_ERROR_NOT_AVAILABLE;
3025#else
3026 if(!JvmtiEnv::is_vm_live()) {
3027 return JVMTI_ERROR_WRONG_PHASE;
3028 }
3029 Thread* this_thread = Thread::current_or_null();
3030 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3031 return JVMTI_ERROR_UNATTACHED_THREAD;
3032 }
3033 JavaThread* current_thread = (JavaThread*)this_thread;
3034 ThreadInVMfromNative __tiv(current_thread);
3035 VM_ENTRY_BASE(jvmtiError, jvmti_GetNamedModule , current_thread)
3036 debug_only(VMNativeEntryWrapper __vew;)
3037 CautiouslyPreserveExceptionMark __em(this_thread);
3038 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3039 if (!jvmti_env->is_valid()) {
3040 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3041 }
3042 jvmtiError err;
3043 if (package_name == NULL) {
3044 return JVMTI_ERROR_NULL_POINTER;
3045 }
3046 if (module_ptr == NULL) {
3047 return JVMTI_ERROR_NULL_POINTER;
3048 }
3049 err = jvmti_env->GetNamedModule(class_loader, package_name, module_ptr);
3050 return err;
3051#endif // INCLUDE_JVMTI
3052}
3053
3054static jvmtiError JNICALL
3055jvmti_AddModuleReads(jvmtiEnv* env,
3056 jobject module,
3057 jobject to_module) {
3058
3059#if !INCLUDE_JVMTI
3060 return JVMTI_ERROR_NOT_AVAILABLE;
3061#else
3062 if(!JvmtiEnv::is_vm_live()) {
3063 return JVMTI_ERROR_WRONG_PHASE;
3064 }
3065 Thread* this_thread = Thread::current_or_null();
3066 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3067 return JVMTI_ERROR_UNATTACHED_THREAD;
3068 }
3069 JavaThread* current_thread = (JavaThread*)this_thread;
3070 ThreadInVMfromNative __tiv(current_thread);
3071 VM_ENTRY_BASE(jvmtiError, jvmti_AddModuleReads , current_thread)
3072 debug_only(VMNativeEntryWrapper __vew;)
3073 CautiouslyPreserveExceptionMark __em(this_thread);
3074 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3075 if (!jvmti_env->is_valid()) {
3076 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3077 }
3078 jvmtiError err;
3079 if (module == NULL) {
3080 return JVMTI_ERROR_NULL_POINTER;
3081 }
3082 if (to_module == NULL) {
3083 return JVMTI_ERROR_NULL_POINTER;
3084 }
3085 err = jvmti_env->AddModuleReads(module, to_module);
3086 return err;
3087#endif // INCLUDE_JVMTI
3088}
3089
3090static jvmtiError JNICALL
3091jvmti_AddModuleExports(jvmtiEnv* env,
3092 jobject module,
3093 const char* pkg_name,
3094 jobject to_module) {
3095
3096#if !INCLUDE_JVMTI
3097 return JVMTI_ERROR_NOT_AVAILABLE;
3098#else
3099 if(!JvmtiEnv::is_vm_live()) {
3100 return JVMTI_ERROR_WRONG_PHASE;
3101 }
3102 Thread* this_thread = Thread::current_or_null();
3103 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3104 return JVMTI_ERROR_UNATTACHED_THREAD;
3105 }
3106 JavaThread* current_thread = (JavaThread*)this_thread;
3107 ThreadInVMfromNative __tiv(current_thread);
3108 VM_ENTRY_BASE(jvmtiError, jvmti_AddModuleExports , current_thread)
3109 debug_only(VMNativeEntryWrapper __vew;)
3110 CautiouslyPreserveExceptionMark __em(this_thread);
3111 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3112 if (!jvmti_env->is_valid()) {
3113 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3114 }
3115 jvmtiError err;
3116 if (module == NULL) {
3117 return JVMTI_ERROR_NULL_POINTER;
3118 }
3119 if (pkg_name == NULL) {
3120 return JVMTI_ERROR_NULL_POINTER;
3121 }
3122 if (to_module == NULL) {
3123 return JVMTI_ERROR_NULL_POINTER;
3124 }
3125 err = jvmti_env->AddModuleExports(module, pkg_name, to_module);
3126 return err;
3127#endif // INCLUDE_JVMTI
3128}
3129
3130static jvmtiError JNICALL
3131jvmti_AddModuleOpens(jvmtiEnv* env,
3132 jobject module,
3133 const char* pkg_name,
3134 jobject to_module) {
3135
3136#if !INCLUDE_JVMTI
3137 return JVMTI_ERROR_NOT_AVAILABLE;
3138#else
3139 if(!JvmtiEnv::is_vm_live()) {
3140 return JVMTI_ERROR_WRONG_PHASE;
3141 }
3142 Thread* this_thread = Thread::current_or_null();
3143 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3144 return JVMTI_ERROR_UNATTACHED_THREAD;
3145 }
3146 JavaThread* current_thread = (JavaThread*)this_thread;
3147 ThreadInVMfromNative __tiv(current_thread);
3148 VM_ENTRY_BASE(jvmtiError, jvmti_AddModuleOpens , current_thread)
3149 debug_only(VMNativeEntryWrapper __vew;)
3150 CautiouslyPreserveExceptionMark __em(this_thread);
3151 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3152 if (!jvmti_env->is_valid()) {
3153 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3154 }
3155 jvmtiError err;
3156 if (module == NULL) {
3157 return JVMTI_ERROR_NULL_POINTER;
3158 }
3159 if (pkg_name == NULL) {
3160 return JVMTI_ERROR_NULL_POINTER;
3161 }
3162 if (to_module == NULL) {
3163 return JVMTI_ERROR_NULL_POINTER;
3164 }
3165 err = jvmti_env->AddModuleOpens(module, pkg_name, to_module);
3166 return err;
3167#endif // INCLUDE_JVMTI
3168}
3169
3170static jvmtiError JNICALL
3171jvmti_AddModuleUses(jvmtiEnv* env,
3172 jobject module,
3173 jclass service) {
3174
3175#if !INCLUDE_JVMTI
3176 return JVMTI_ERROR_NOT_AVAILABLE;
3177#else
3178 if(!JvmtiEnv::is_vm_live()) {
3179 return JVMTI_ERROR_WRONG_PHASE;
3180 }
3181 Thread* this_thread = Thread::current_or_null();
3182 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3183 return JVMTI_ERROR_UNATTACHED_THREAD;
3184 }
3185 JavaThread* current_thread = (JavaThread*)this_thread;
3186 ThreadInVMfromNative __tiv(current_thread);
3187 VM_ENTRY_BASE(jvmtiError, jvmti_AddModuleUses , current_thread)
3188 debug_only(VMNativeEntryWrapper __vew;)
3189 CautiouslyPreserveExceptionMark __em(this_thread);
3190 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3191 if (!jvmti_env->is_valid()) {
3192 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3193 }
3194 jvmtiError err;
3195 if (module == NULL) {
3196 return JVMTI_ERROR_NULL_POINTER;
3197 }
3198 if (service == NULL) {
3199 return JVMTI_ERROR_NULL_POINTER;
3200 }
3201 err = jvmti_env->AddModuleUses(module, service);
3202 return err;
3203#endif // INCLUDE_JVMTI
3204}
3205
3206static jvmtiError JNICALL
3207jvmti_AddModuleProvides(jvmtiEnv* env,
3208 jobject module,
3209 jclass service,
3210 jclass impl_class) {
3211
3212#if !INCLUDE_JVMTI
3213 return JVMTI_ERROR_NOT_AVAILABLE;
3214#else
3215 if(!JvmtiEnv::is_vm_live()) {
3216 return JVMTI_ERROR_WRONG_PHASE;
3217 }
3218 Thread* this_thread = Thread::current_or_null();
3219 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3220 return JVMTI_ERROR_UNATTACHED_THREAD;
3221 }
3222 JavaThread* current_thread = (JavaThread*)this_thread;
3223 ThreadInVMfromNative __tiv(current_thread);
3224 VM_ENTRY_BASE(jvmtiError, jvmti_AddModuleProvides , current_thread)
3225 debug_only(VMNativeEntryWrapper __vew;)
3226 CautiouslyPreserveExceptionMark __em(this_thread);
3227 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3228 if (!jvmti_env->is_valid()) {
3229 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3230 }
3231 jvmtiError err;
3232 if (module == NULL) {
3233 return JVMTI_ERROR_NULL_POINTER;
3234 }
3235 if (service == NULL) {
3236 return JVMTI_ERROR_NULL_POINTER;
3237 }
3238 if (impl_class == NULL) {
3239 return JVMTI_ERROR_NULL_POINTER;
3240 }
3241 err = jvmti_env->AddModuleProvides(module, service, impl_class);
3242 return err;
3243#endif // INCLUDE_JVMTI
3244}
3245
3246static jvmtiError JNICALL
3247jvmti_IsModifiableModule(jvmtiEnv* env,
3248 jobject module,
3249 jboolean* is_modifiable_module_ptr) {
3250
3251#if !INCLUDE_JVMTI
3252 return JVMTI_ERROR_NOT_AVAILABLE;
3253#else
3254 if(!JvmtiEnv::is_vm_live()) {
3255 return JVMTI_ERROR_WRONG_PHASE;
3256 }
3257 Thread* this_thread = Thread::current_or_null();
3258 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3259 return JVMTI_ERROR_UNATTACHED_THREAD;
3260 }
3261 JavaThread* current_thread = (JavaThread*)this_thread;
3262 ThreadInVMfromNative __tiv(current_thread);
3263 VM_ENTRY_BASE(jvmtiError, jvmti_IsModifiableModule , current_thread)
3264 debug_only(VMNativeEntryWrapper __vew;)
3265 CautiouslyPreserveExceptionMark __em(this_thread);
3266 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3267 if (!jvmti_env->is_valid()) {
3268 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3269 }
3270 jvmtiError err;
3271 if (module == NULL) {
3272 return JVMTI_ERROR_NULL_POINTER;
3273 }
3274 if (is_modifiable_module_ptr == NULL) {
3275 return JVMTI_ERROR_NULL_POINTER;
3276 }
3277 err = jvmti_env->IsModifiableModule(module, is_modifiable_module_ptr);
3278 return err;
3279#endif // INCLUDE_JVMTI
3280}
3281
3282 //
3283 // Class functions
3284 //
3285
3286static jvmtiError JNICALL
3287jvmti_GetLoadedClasses(jvmtiEnv* env,
3288 jint* class_count_ptr,
3289 jclass** classes_ptr) {
3290 if(!JvmtiEnv::is_vm_live()) {
3291 return JVMTI_ERROR_WRONG_PHASE;
3292 }
3293 Thread* this_thread = Thread::current_or_null();
3294 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3295 return JVMTI_ERROR_UNATTACHED_THREAD;
3296 }
3297 JavaThread* current_thread = (JavaThread*)this_thread;
3298 ThreadInVMfromNative __tiv(current_thread);
3299 VM_ENTRY_BASE(jvmtiError, jvmti_GetLoadedClasses , current_thread)
3300 debug_only(VMNativeEntryWrapper __vew;)
3301 CautiouslyPreserveExceptionMark __em(this_thread);
3302 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3303 if (!jvmti_env->is_valid()) {
3304 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3305 }
3306 jvmtiError err;
3307 if (class_count_ptr == NULL) {
3308 return JVMTI_ERROR_NULL_POINTER;
3309 }
3310 if (classes_ptr == NULL) {
3311 return JVMTI_ERROR_NULL_POINTER;
3312 }
3313 err = jvmti_env->GetLoadedClasses(class_count_ptr, classes_ptr);
3314 return err;
3315}
3316
3317static jvmtiError JNICALL
3318jvmti_GetClassLoaderClasses(jvmtiEnv* env,
3319 jobject initiating_loader,
3320 jint* class_count_ptr,
3321 jclass** classes_ptr) {
3322 if(!JvmtiEnv::is_vm_live()) {
3323 return JVMTI_ERROR_WRONG_PHASE;
3324 }
3325 Thread* this_thread = Thread::current_or_null();
3326 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3327 return JVMTI_ERROR_UNATTACHED_THREAD;
3328 }
3329 JavaThread* current_thread = (JavaThread*)this_thread;
3330 ThreadInVMfromNative __tiv(current_thread);
3331 VM_ENTRY_BASE(jvmtiError, jvmti_GetClassLoaderClasses , current_thread)
3332 debug_only(VMNativeEntryWrapper __vew;)
3333 CautiouslyPreserveExceptionMark __em(this_thread);
3334 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3335 if (!jvmti_env->is_valid()) {
3336 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3337 }
3338 jvmtiError err;
3339 if (class_count_ptr == NULL) {
3340 return JVMTI_ERROR_NULL_POINTER;
3341 }
3342 if (classes_ptr == NULL) {
3343 return JVMTI_ERROR_NULL_POINTER;
3344 }
3345 err = jvmti_env->GetClassLoaderClasses(initiating_loader, class_count_ptr, classes_ptr);
3346 return err;
3347}
3348
3349static jvmtiError JNICALL
3350jvmti_GetClassSignature(jvmtiEnv* env,
3351 jclass klass,
3352 char** signature_ptr,
3353 char** generic_ptr) {
3354
3355#if !INCLUDE_JVMTI
3356 return JVMTI_ERROR_NOT_AVAILABLE;
3357#else
3358 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
3359 return JVMTI_ERROR_WRONG_PHASE;
3360 }
3361 Thread* this_thread = Thread::current_or_null();
3362 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3363 return JVMTI_ERROR_UNATTACHED_THREAD;
3364 }
3365 JavaThread* current_thread = (JavaThread*)this_thread;
3366 ThreadInVMfromNative __tiv(current_thread);
3367 VM_ENTRY_BASE(jvmtiError, jvmti_GetClassSignature , current_thread)
3368 debug_only(VMNativeEntryWrapper __vew;)
3369 CautiouslyPreserveExceptionMark __em(this_thread);
3370 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3371 if (!jvmti_env->is_valid()) {
3372 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3373 }
3374 jvmtiError err;
3375 oop k_mirror = JNIHandles::resolve_external_guard(klass);
3376 if (k_mirror == NULL) {
3377 return JVMTI_ERROR_INVALID_CLASS;
3378 }
3379 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
3380 return JVMTI_ERROR_INVALID_CLASS;
3381 }
3382 err = jvmti_env->GetClassSignature(k_mirror, signature_ptr, generic_ptr);
3383 return err;
3384#endif // INCLUDE_JVMTI
3385}
3386
3387static jvmtiError JNICALL
3388jvmti_GetClassStatus(jvmtiEnv* env,
3389 jclass klass,
3390 jint* status_ptr) {
3391
3392#if !INCLUDE_JVMTI
3393 return JVMTI_ERROR_NOT_AVAILABLE;
3394#else
3395 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
3396 return JVMTI_ERROR_WRONG_PHASE;
3397 }
3398 Thread* this_thread = Thread::current_or_null();
3399 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3400 return JVMTI_ERROR_UNATTACHED_THREAD;
3401 }
3402 JavaThread* current_thread = (JavaThread*)this_thread;
3403 ThreadInVMfromNative __tiv(current_thread);
3404 VM_ENTRY_BASE(jvmtiError, jvmti_GetClassStatus , current_thread)
3405 debug_only(VMNativeEntryWrapper __vew;)
3406 CautiouslyPreserveExceptionMark __em(this_thread);
3407 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3408 if (!jvmti_env->is_valid()) {
3409 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3410 }
3411 jvmtiError err;
3412 oop k_mirror = JNIHandles::resolve_external_guard(klass);
3413 if (k_mirror == NULL) {
3414 return JVMTI_ERROR_INVALID_CLASS;
3415 }
3416 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
3417 return JVMTI_ERROR_INVALID_CLASS;
3418 }
3419 if (status_ptr == NULL) {
3420 return JVMTI_ERROR_NULL_POINTER;
3421 }
3422 err = jvmti_env->GetClassStatus(k_mirror, status_ptr);
3423 return err;
3424#endif // INCLUDE_JVMTI
3425}
3426
3427static jvmtiError JNICALL
3428jvmti_GetSourceFileName(jvmtiEnv* env,
3429 jclass klass,
3430 char** source_name_ptr) {
3431
3432#if !INCLUDE_JVMTI
3433 return JVMTI_ERROR_NOT_AVAILABLE;
3434#else
3435 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
3436 return JVMTI_ERROR_WRONG_PHASE;
3437 }
3438 Thread* this_thread = Thread::current_or_null();
3439 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3440 return JVMTI_ERROR_UNATTACHED_THREAD;
3441 }
3442 JavaThread* current_thread = (JavaThread*)this_thread;
3443 ThreadInVMfromNative __tiv(current_thread);
3444 VM_ENTRY_BASE(jvmtiError, jvmti_GetSourceFileName , current_thread)
3445 debug_only(VMNativeEntryWrapper __vew;)
3446 CautiouslyPreserveExceptionMark __em(this_thread);
3447 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3448 if (!jvmti_env->is_valid()) {
3449 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3450 }
3451
3452 if (jvmti_env->get_capabilities()->can_get_source_file_name == 0) {
3453 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
3454 }
3455 jvmtiError err;
3456 oop k_mirror = JNIHandles::resolve_external_guard(klass);
3457 if (k_mirror == NULL) {
3458 return JVMTI_ERROR_INVALID_CLASS;
3459 }
3460 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
3461 return JVMTI_ERROR_INVALID_CLASS;
3462 }
3463 if (source_name_ptr == NULL) {
3464 return JVMTI_ERROR_NULL_POINTER;
3465 }
3466 err = jvmti_env->GetSourceFileName(k_mirror, source_name_ptr);
3467 return err;
3468#endif // INCLUDE_JVMTI
3469}
3470
3471static jvmtiError JNICALL
3472jvmti_GetClassModifiers(jvmtiEnv* env,
3473 jclass klass,
3474 jint* modifiers_ptr) {
3475
3476#if !INCLUDE_JVMTI
3477 return JVMTI_ERROR_NOT_AVAILABLE;
3478#else
3479 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
3480 return JVMTI_ERROR_WRONG_PHASE;
3481 }
3482 Thread* this_thread = Thread::current_or_null();
3483 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3484 return JVMTI_ERROR_UNATTACHED_THREAD;
3485 }
3486 JavaThread* current_thread = (JavaThread*)this_thread;
3487 ThreadInVMfromNative __tiv(current_thread);
3488 VM_ENTRY_BASE(jvmtiError, jvmti_GetClassModifiers , current_thread)
3489 debug_only(VMNativeEntryWrapper __vew;)
3490 CautiouslyPreserveExceptionMark __em(this_thread);
3491 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3492 if (!jvmti_env->is_valid()) {
3493 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3494 }
3495 jvmtiError err;
3496 oop k_mirror = JNIHandles::resolve_external_guard(klass);
3497 if (k_mirror == NULL) {
3498 return JVMTI_ERROR_INVALID_CLASS;
3499 }
3500 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
3501 return JVMTI_ERROR_INVALID_CLASS;
3502 }
3503 if (modifiers_ptr == NULL) {
3504 return JVMTI_ERROR_NULL_POINTER;
3505 }
3506 err = jvmti_env->GetClassModifiers(k_mirror, modifiers_ptr);
3507 return err;
3508#endif // INCLUDE_JVMTI
3509}
3510
3511static jvmtiError JNICALL
3512jvmti_GetClassMethods(jvmtiEnv* env,
3513 jclass klass,
3514 jint* method_count_ptr,
3515 jmethodID** methods_ptr) {
3516
3517#if !INCLUDE_JVMTI
3518 return JVMTI_ERROR_NOT_AVAILABLE;
3519#else
3520 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
3521 return JVMTI_ERROR_WRONG_PHASE;
3522 }
3523 Thread* this_thread = Thread::current_or_null();
3524 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3525 return JVMTI_ERROR_UNATTACHED_THREAD;
3526 }
3527 JavaThread* current_thread = (JavaThread*)this_thread;
3528 ThreadInVMfromNative __tiv(current_thread);
3529 VM_ENTRY_BASE(jvmtiError, jvmti_GetClassMethods , current_thread)
3530 debug_only(VMNativeEntryWrapper __vew;)
3531 CautiouslyPreserveExceptionMark __em(this_thread);
3532 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3533 if (!jvmti_env->is_valid()) {
3534 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3535 }
3536 jvmtiError err;
3537 oop k_mirror = JNIHandles::resolve_external_guard(klass);
3538 if (k_mirror == NULL) {
3539 return JVMTI_ERROR_INVALID_CLASS;
3540 }
3541 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
3542 return JVMTI_ERROR_INVALID_CLASS;
3543 }
3544 if (method_count_ptr == NULL) {
3545 return JVMTI_ERROR_NULL_POINTER;
3546 }
3547 if (methods_ptr == NULL) {
3548 return JVMTI_ERROR_NULL_POINTER;
3549 }
3550 err = jvmti_env->GetClassMethods(k_mirror, method_count_ptr, methods_ptr);
3551 return err;
3552#endif // INCLUDE_JVMTI
3553}
3554
3555static jvmtiError JNICALL
3556jvmti_GetClassFields(jvmtiEnv* env,
3557 jclass klass,
3558 jint* field_count_ptr,
3559 jfieldID** fields_ptr) {
3560
3561#if !INCLUDE_JVMTI
3562 return JVMTI_ERROR_NOT_AVAILABLE;
3563#else
3564 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
3565 return JVMTI_ERROR_WRONG_PHASE;
3566 }
3567 Thread* this_thread = Thread::current_or_null();
3568 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3569 return JVMTI_ERROR_UNATTACHED_THREAD;
3570 }
3571 JavaThread* current_thread = (JavaThread*)this_thread;
3572 ThreadInVMfromNative __tiv(current_thread);
3573 VM_ENTRY_BASE(jvmtiError, jvmti_GetClassFields , current_thread)
3574 debug_only(VMNativeEntryWrapper __vew;)
3575 CautiouslyPreserveExceptionMark __em(this_thread);
3576 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3577 if (!jvmti_env->is_valid()) {
3578 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3579 }
3580 jvmtiError err;
3581 oop k_mirror = JNIHandles::resolve_external_guard(klass);
3582 if (k_mirror == NULL) {
3583 return JVMTI_ERROR_INVALID_CLASS;
3584 }
3585 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
3586 return JVMTI_ERROR_INVALID_CLASS;
3587 }
3588 if (field_count_ptr == NULL) {
3589 return JVMTI_ERROR_NULL_POINTER;
3590 }
3591 if (fields_ptr == NULL) {
3592 return JVMTI_ERROR_NULL_POINTER;
3593 }
3594 err = jvmti_env->GetClassFields(k_mirror, field_count_ptr, fields_ptr);
3595 return err;
3596#endif // INCLUDE_JVMTI
3597}
3598
3599static jvmtiError JNICALL
3600jvmti_GetImplementedInterfaces(jvmtiEnv* env,
3601 jclass klass,
3602 jint* interface_count_ptr,
3603 jclass** interfaces_ptr) {
3604
3605#if !INCLUDE_JVMTI
3606 return JVMTI_ERROR_NOT_AVAILABLE;
3607#else
3608 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
3609 return JVMTI_ERROR_WRONG_PHASE;
3610 }
3611 Thread* this_thread = Thread::current_or_null();
3612 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3613 return JVMTI_ERROR_UNATTACHED_THREAD;
3614 }
3615 JavaThread* current_thread = (JavaThread*)this_thread;
3616 ThreadInVMfromNative __tiv(current_thread);
3617 VM_ENTRY_BASE(jvmtiError, jvmti_GetImplementedInterfaces , current_thread)
3618 debug_only(VMNativeEntryWrapper __vew;)
3619 CautiouslyPreserveExceptionMark __em(this_thread);
3620 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3621 if (!jvmti_env->is_valid()) {
3622 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3623 }
3624 jvmtiError err;
3625 oop k_mirror = JNIHandles::resolve_external_guard(klass);
3626 if (k_mirror == NULL) {
3627 return JVMTI_ERROR_INVALID_CLASS;
3628 }
3629 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
3630 return JVMTI_ERROR_INVALID_CLASS;
3631 }
3632 if (interface_count_ptr == NULL) {
3633 return JVMTI_ERROR_NULL_POINTER;
3634 }
3635 if (interfaces_ptr == NULL) {
3636 return JVMTI_ERROR_NULL_POINTER;
3637 }
3638 err = jvmti_env->GetImplementedInterfaces(k_mirror, interface_count_ptr, interfaces_ptr);
3639 return err;
3640#endif // INCLUDE_JVMTI
3641}
3642
3643static jvmtiError JNICALL
3644jvmti_GetClassVersionNumbers(jvmtiEnv* env,
3645 jclass klass,
3646 jint* minor_version_ptr,
3647 jint* major_version_ptr) {
3648
3649#if !INCLUDE_JVMTI
3650 return JVMTI_ERROR_NOT_AVAILABLE;
3651#else
3652 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
3653 return JVMTI_ERROR_WRONG_PHASE;
3654 }
3655 Thread* this_thread = Thread::current_or_null();
3656 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3657 return JVMTI_ERROR_UNATTACHED_THREAD;
3658 }
3659 JavaThread* current_thread = (JavaThread*)this_thread;
3660 ThreadInVMfromNative __tiv(current_thread);
3661 VM_ENTRY_BASE(jvmtiError, jvmti_GetClassVersionNumbers , current_thread)
3662 debug_only(VMNativeEntryWrapper __vew;)
3663 CautiouslyPreserveExceptionMark __em(this_thread);
3664 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3665 if (!jvmti_env->is_valid()) {
3666 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3667 }
3668 jvmtiError err;
3669 oop k_mirror = JNIHandles::resolve_external_guard(klass);
3670 if (k_mirror == NULL) {
3671 return JVMTI_ERROR_INVALID_CLASS;
3672 }
3673 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
3674 return JVMTI_ERROR_INVALID_CLASS;
3675 }
3676 if (minor_version_ptr == NULL) {
3677 return JVMTI_ERROR_NULL_POINTER;
3678 }
3679 if (major_version_ptr == NULL) {
3680 return JVMTI_ERROR_NULL_POINTER;
3681 }
3682 err = jvmti_env->GetClassVersionNumbers(k_mirror, minor_version_ptr, major_version_ptr);
3683 return err;
3684#endif // INCLUDE_JVMTI
3685}
3686
3687static jvmtiError JNICALL
3688jvmti_GetConstantPool(jvmtiEnv* env,
3689 jclass klass,
3690 jint* constant_pool_count_ptr,
3691 jint* constant_pool_byte_count_ptr,
3692 unsigned char** constant_pool_bytes_ptr) {
3693
3694#if !INCLUDE_JVMTI
3695 return JVMTI_ERROR_NOT_AVAILABLE;
3696#else
3697 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
3698 return JVMTI_ERROR_WRONG_PHASE;
3699 }
3700 Thread* this_thread = Thread::current_or_null();
3701 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3702 return JVMTI_ERROR_UNATTACHED_THREAD;
3703 }
3704 JavaThread* current_thread = (JavaThread*)this_thread;
3705 ThreadInVMfromNative __tiv(current_thread);
3706 VM_ENTRY_BASE(jvmtiError, jvmti_GetConstantPool , current_thread)
3707 debug_only(VMNativeEntryWrapper __vew;)
3708 CautiouslyPreserveExceptionMark __em(this_thread);
3709 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3710 if (!jvmti_env->is_valid()) {
3711 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3712 }
3713
3714 if (jvmti_env->get_capabilities()->can_get_constant_pool == 0) {
3715 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
3716 }
3717 jvmtiError err;
3718 oop k_mirror = JNIHandles::resolve_external_guard(klass);
3719 if (k_mirror == NULL) {
3720 return JVMTI_ERROR_INVALID_CLASS;
3721 }
3722 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
3723 return JVMTI_ERROR_INVALID_CLASS;
3724 }
3725 if (constant_pool_count_ptr == NULL) {
3726 return JVMTI_ERROR_NULL_POINTER;
3727 }
3728 if (constant_pool_byte_count_ptr == NULL) {
3729 return JVMTI_ERROR_NULL_POINTER;
3730 }
3731 if (constant_pool_bytes_ptr == NULL) {
3732 return JVMTI_ERROR_NULL_POINTER;
3733 }
3734 err = jvmti_env->GetConstantPool(k_mirror, constant_pool_count_ptr, constant_pool_byte_count_ptr, constant_pool_bytes_ptr);
3735 return err;
3736#endif // INCLUDE_JVMTI
3737}
3738
3739static jvmtiError JNICALL
3740jvmti_IsInterface(jvmtiEnv* env,
3741 jclass klass,
3742 jboolean* is_interface_ptr) {
3743
3744#if !INCLUDE_JVMTI
3745 return JVMTI_ERROR_NOT_AVAILABLE;
3746#else
3747 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
3748 return JVMTI_ERROR_WRONG_PHASE;
3749 }
3750 Thread* this_thread = Thread::current_or_null();
3751 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3752 return JVMTI_ERROR_UNATTACHED_THREAD;
3753 }
3754 JavaThread* current_thread = (JavaThread*)this_thread;
3755 ThreadInVMfromNative __tiv(current_thread);
3756 VM_ENTRY_BASE(jvmtiError, jvmti_IsInterface , current_thread)
3757 debug_only(VMNativeEntryWrapper __vew;)
3758 CautiouslyPreserveExceptionMark __em(this_thread);
3759 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3760 if (!jvmti_env->is_valid()) {
3761 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3762 }
3763 jvmtiError err;
3764 oop k_mirror = JNIHandles::resolve_external_guard(klass);
3765 if (k_mirror == NULL) {
3766 return JVMTI_ERROR_INVALID_CLASS;
3767 }
3768 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
3769 return JVMTI_ERROR_INVALID_CLASS;
3770 }
3771 if (is_interface_ptr == NULL) {
3772 return JVMTI_ERROR_NULL_POINTER;
3773 }
3774 err = jvmti_env->IsInterface(k_mirror, is_interface_ptr);
3775 return err;
3776#endif // INCLUDE_JVMTI
3777}
3778
3779static jvmtiError JNICALL
3780jvmti_IsArrayClass(jvmtiEnv* env,
3781 jclass klass,
3782 jboolean* is_array_class_ptr) {
3783
3784#if !INCLUDE_JVMTI
3785 return JVMTI_ERROR_NOT_AVAILABLE;
3786#else
3787 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
3788 return JVMTI_ERROR_WRONG_PHASE;
3789 }
3790 Thread* this_thread = Thread::current_or_null();
3791 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3792 return JVMTI_ERROR_UNATTACHED_THREAD;
3793 }
3794 JavaThread* current_thread = (JavaThread*)this_thread;
3795 ThreadInVMfromNative __tiv(current_thread);
3796 VM_ENTRY_BASE(jvmtiError, jvmti_IsArrayClass , current_thread)
3797 debug_only(VMNativeEntryWrapper __vew;)
3798 CautiouslyPreserveExceptionMark __em(this_thread);
3799 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3800 if (!jvmti_env->is_valid()) {
3801 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3802 }
3803 jvmtiError err;
3804 oop k_mirror = JNIHandles::resolve_external_guard(klass);
3805 if (k_mirror == NULL) {
3806 return JVMTI_ERROR_INVALID_CLASS;
3807 }
3808 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
3809 return JVMTI_ERROR_INVALID_CLASS;
3810 }
3811 if (is_array_class_ptr == NULL) {
3812 return JVMTI_ERROR_NULL_POINTER;
3813 }
3814 err = jvmti_env->IsArrayClass(k_mirror, is_array_class_ptr);
3815 return err;
3816#endif // INCLUDE_JVMTI
3817}
3818
3819static jvmtiError JNICALL
3820jvmti_IsModifiableClass(jvmtiEnv* env,
3821 jclass klass,
3822 jboolean* is_modifiable_class_ptr) {
3823 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
3824 return JVMTI_ERROR_WRONG_PHASE;
3825 }
3826 Thread* this_thread = Thread::current_or_null();
3827 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3828 return JVMTI_ERROR_UNATTACHED_THREAD;
3829 }
3830 JavaThread* current_thread = (JavaThread*)this_thread;
3831 ThreadInVMfromNative __tiv(current_thread);
3832 VM_ENTRY_BASE(jvmtiError, jvmti_IsModifiableClass , current_thread)
3833 debug_only(VMNativeEntryWrapper __vew;)
3834 CautiouslyPreserveExceptionMark __em(this_thread);
3835 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3836 if (!jvmti_env->is_valid()) {
3837 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3838 }
3839 jvmtiError err;
3840 oop k_mirror = JNIHandles::resolve_external_guard(klass);
3841 if (k_mirror == NULL) {
3842 return JVMTI_ERROR_INVALID_CLASS;
3843 }
3844 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
3845 return JVMTI_ERROR_INVALID_CLASS;
3846 }
3847 if (is_modifiable_class_ptr == NULL) {
3848 return JVMTI_ERROR_NULL_POINTER;
3849 }
3850 err = jvmti_env->IsModifiableClass(k_mirror, is_modifiable_class_ptr);
3851 return err;
3852}
3853
3854static jvmtiError JNICALL
3855jvmti_GetClassLoader(jvmtiEnv* env,
3856 jclass klass,
3857 jobject* classloader_ptr) {
3858
3859#if !INCLUDE_JVMTI
3860 return JVMTI_ERROR_NOT_AVAILABLE;
3861#else
3862 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
3863 return JVMTI_ERROR_WRONG_PHASE;
3864 }
3865 Thread* this_thread = Thread::current_or_null();
3866 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3867 return JVMTI_ERROR_UNATTACHED_THREAD;
3868 }
3869 JavaThread* current_thread = (JavaThread*)this_thread;
3870 ThreadInVMfromNative __tiv(current_thread);
3871 VM_ENTRY_BASE(jvmtiError, jvmti_GetClassLoader , current_thread)
3872 debug_only(VMNativeEntryWrapper __vew;)
3873 CautiouslyPreserveExceptionMark __em(this_thread);
3874 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3875 if (!jvmti_env->is_valid()) {
3876 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3877 }
3878 jvmtiError err;
3879 oop k_mirror = JNIHandles::resolve_external_guard(klass);
3880 if (k_mirror == NULL) {
3881 return JVMTI_ERROR_INVALID_CLASS;
3882 }
3883 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
3884 return JVMTI_ERROR_INVALID_CLASS;
3885 }
3886 if (classloader_ptr == NULL) {
3887 return JVMTI_ERROR_NULL_POINTER;
3888 }
3889 err = jvmti_env->GetClassLoader(k_mirror, classloader_ptr);
3890 return err;
3891#endif // INCLUDE_JVMTI
3892}
3893
3894static jvmtiError JNICALL
3895jvmti_GetSourceDebugExtension(jvmtiEnv* env,
3896 jclass klass,
3897 char** source_debug_extension_ptr) {
3898
3899#if !INCLUDE_JVMTI
3900 return JVMTI_ERROR_NOT_AVAILABLE;
3901#else
3902 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
3903 return JVMTI_ERROR_WRONG_PHASE;
3904 }
3905 Thread* this_thread = Thread::current_or_null();
3906 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3907 return JVMTI_ERROR_UNATTACHED_THREAD;
3908 }
3909 JavaThread* current_thread = (JavaThread*)this_thread;
3910 ThreadInVMfromNative __tiv(current_thread);
3911 VM_ENTRY_BASE(jvmtiError, jvmti_GetSourceDebugExtension , current_thread)
3912 debug_only(VMNativeEntryWrapper __vew;)
3913 CautiouslyPreserveExceptionMark __em(this_thread);
3914 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3915 if (!jvmti_env->is_valid()) {
3916 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3917 }
3918
3919 if (jvmti_env->get_capabilities()->can_get_source_debug_extension == 0) {
3920 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
3921 }
3922 jvmtiError err;
3923 oop k_mirror = JNIHandles::resolve_external_guard(klass);
3924 if (k_mirror == NULL) {
3925 return JVMTI_ERROR_INVALID_CLASS;
3926 }
3927 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
3928 return JVMTI_ERROR_INVALID_CLASS;
3929 }
3930 if (source_debug_extension_ptr == NULL) {
3931 return JVMTI_ERROR_NULL_POINTER;
3932 }
3933 err = jvmti_env->GetSourceDebugExtension(k_mirror, source_debug_extension_ptr);
3934 return err;
3935#endif // INCLUDE_JVMTI
3936}
3937
3938static jvmtiError JNICALL
3939jvmti_RetransformClasses(jvmtiEnv* env,
3940 jint class_count,
3941 const jclass* classes) {
3942 if(!JvmtiEnv::is_vm_live()) {
3943 return JVMTI_ERROR_WRONG_PHASE;
3944 }
3945 Thread* this_thread = Thread::current_or_null();
3946 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3947 return JVMTI_ERROR_UNATTACHED_THREAD;
3948 }
3949 JavaThread* current_thread = (JavaThread*)this_thread;
3950 ThreadInVMfromNative __tiv(current_thread);
3951 VM_ENTRY_BASE(jvmtiError, jvmti_RetransformClasses , current_thread)
3952 debug_only(VMNativeEntryWrapper __vew;)
3953 CautiouslyPreserveExceptionMark __em(this_thread);
3954 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3955 if (!jvmti_env->is_valid()) {
3956 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3957 }
3958
3959 if (jvmti_env->get_capabilities()->can_retransform_classes == 0) {
3960 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
3961 }
3962 jvmtiError err;
3963 if (class_count < 0) {
3964 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
3965 }
3966 if (classes == NULL) {
3967 return JVMTI_ERROR_NULL_POINTER;
3968 }
3969 err = jvmti_env->RetransformClasses(class_count, classes);
3970 return err;
3971}
3972
3973static jvmtiError JNICALL
3974jvmti_RedefineClasses(jvmtiEnv* env,
3975 jint class_count,
3976 const jvmtiClassDefinition* class_definitions) {
3977 if(!JvmtiEnv::is_vm_live()) {
3978 return JVMTI_ERROR_WRONG_PHASE;
3979 }
3980 Thread* this_thread = Thread::current_or_null();
3981 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3982 return JVMTI_ERROR_UNATTACHED_THREAD;
3983 }
3984 JavaThread* current_thread = (JavaThread*)this_thread;
3985 ThreadInVMfromNative __tiv(current_thread);
3986 VM_ENTRY_BASE(jvmtiError, jvmti_RedefineClasses , current_thread)
3987 debug_only(VMNativeEntryWrapper __vew;)
3988 CautiouslyPreserveExceptionMark __em(this_thread);
3989 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3990 if (!jvmti_env->is_valid()) {
3991 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3992 }
3993
3994 if (jvmti_env->get_capabilities()->can_redefine_classes == 0) {
3995 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
3996 }
3997 jvmtiError err;
3998 if (class_count < 0) {
3999 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
4000 }
4001 if (class_definitions == NULL) {
4002 return JVMTI_ERROR_NULL_POINTER;
4003 }
4004 err = jvmti_env->RedefineClasses(class_count, class_definitions);
4005 return err;
4006}
4007
4008 //
4009 // Object functions
4010 //
4011
4012static jvmtiError JNICALL
4013jvmti_GetObjectSize(jvmtiEnv* env,
4014 jobject object,
4015 jlong* size_ptr) {
4016 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4017 return JVMTI_ERROR_WRONG_PHASE;
4018 }
4019 Thread* this_thread = Thread::current_or_null();
4020 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4021 return JVMTI_ERROR_UNATTACHED_THREAD;
4022 }
4023 JavaThread* current_thread = (JavaThread*)this_thread;
4024 ThreadInVMfromNative __tiv(current_thread);
4025 VM_ENTRY_BASE(jvmtiError, jvmti_GetObjectSize , current_thread)
4026 debug_only(VMNativeEntryWrapper __vew;)
4027 CautiouslyPreserveExceptionMark __em(this_thread);
4028 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4029 if (!jvmti_env->is_valid()) {
4030 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4031 }
4032 jvmtiError err;
4033 if (size_ptr == NULL) {
4034 return JVMTI_ERROR_NULL_POINTER;
4035 }
4036 err = jvmti_env->GetObjectSize(object, size_ptr);
4037 return err;
4038}
4039
4040static jvmtiError JNICALL
4041jvmti_GetObjectHashCode(jvmtiEnv* env,
4042 jobject object,
4043 jint* hash_code_ptr) {
4044
4045#if !INCLUDE_JVMTI
4046 return JVMTI_ERROR_NOT_AVAILABLE;
4047#else
4048 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4049 return JVMTI_ERROR_WRONG_PHASE;
4050 }
4051 Thread* this_thread = Thread::current_or_null();
4052 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4053 return JVMTI_ERROR_UNATTACHED_THREAD;
4054 }
4055 JavaThread* current_thread = (JavaThread*)this_thread;
4056 ThreadInVMfromNative __tiv(current_thread);
4057 VM_ENTRY_BASE(jvmtiError, jvmti_GetObjectHashCode , current_thread)
4058 debug_only(VMNativeEntryWrapper __vew;)
4059 CautiouslyPreserveExceptionMark __em(this_thread);
4060 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4061 if (!jvmti_env->is_valid()) {
4062 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4063 }
4064 jvmtiError err;
4065 if (hash_code_ptr == NULL) {
4066 return JVMTI_ERROR_NULL_POINTER;
4067 }
4068 err = jvmti_env->GetObjectHashCode(object, hash_code_ptr);
4069 return err;
4070#endif // INCLUDE_JVMTI
4071}
4072
4073static jvmtiError JNICALL
4074jvmti_GetObjectMonitorUsage(jvmtiEnv* env,
4075 jobject object,
4076 jvmtiMonitorUsage* info_ptr) {
4077
4078#if !INCLUDE_JVMTI
4079 return JVMTI_ERROR_NOT_AVAILABLE;
4080#else
4081 if(!JvmtiEnv::is_vm_live()) {
4082 return JVMTI_ERROR_WRONG_PHASE;
4083 }
4084 Thread* this_thread = Thread::current_or_null();
4085 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4086 return JVMTI_ERROR_UNATTACHED_THREAD;
4087 }
4088 JavaThread* current_thread = (JavaThread*)this_thread;
4089 ThreadInVMfromNative __tiv(current_thread);
4090 VM_ENTRY_BASE(jvmtiError, jvmti_GetObjectMonitorUsage , current_thread)
4091 debug_only(VMNativeEntryWrapper __vew;)
4092 CautiouslyPreserveExceptionMark __em(this_thread);
4093 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4094 if (!jvmti_env->is_valid()) {
4095 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4096 }
4097
4098 if (jvmti_env->get_capabilities()->can_get_monitor_info == 0) {
4099 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4100 }
4101 jvmtiError err;
4102 if (info_ptr == NULL) {
4103 return JVMTI_ERROR_NULL_POINTER;
4104 }
4105 err = jvmti_env->GetObjectMonitorUsage(object, info_ptr);
4106 return err;
4107#endif // INCLUDE_JVMTI
4108}
4109
4110 //
4111 // Field functions
4112 //
4113
4114static jvmtiError JNICALL
4115jvmti_GetFieldName(jvmtiEnv* env,
4116 jclass klass,
4117 jfieldID field,
4118 char** name_ptr,
4119 char** signature_ptr,
4120 char** generic_ptr) {
4121
4122#if !INCLUDE_JVMTI
4123 return JVMTI_ERROR_NOT_AVAILABLE;
4124#else
4125 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4126 return JVMTI_ERROR_WRONG_PHASE;
4127 }
4128 Thread* this_thread = Thread::current_or_null();
4129 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4130 return JVMTI_ERROR_UNATTACHED_THREAD;
4131 }
4132 JavaThread* current_thread = (JavaThread*)this_thread;
4133 ThreadInVMfromNative __tiv(current_thread);
4134 VM_ENTRY_BASE(jvmtiError, jvmti_GetFieldName , current_thread)
4135 debug_only(VMNativeEntryWrapper __vew;)
4136 CautiouslyPreserveExceptionMark __em(this_thread);
4137 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4138 if (!jvmti_env->is_valid()) {
4139 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4140 }
4141 jvmtiError err;
4142 oop k_mirror = JNIHandles::resolve_external_guard(klass);
4143 if (k_mirror == NULL) {
4144 return JVMTI_ERROR_INVALID_CLASS;
4145 }
4146 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
4147 return JVMTI_ERROR_INVALID_CLASS;
4148 }
4149
4150 if (java_lang_Class::is_primitive(k_mirror)) {
4151 return JVMTI_ERROR_INVALID_CLASS;
4152 }
4153 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
4154 if (k_oop == NULL) {
4155 return JVMTI_ERROR_INVALID_CLASS;
4156 }
4157 ResourceMark rm_fdesc(current_thread);
4158 fieldDescriptor fdesc;
4159 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
4160 return JVMTI_ERROR_INVALID_FIELDID;
4161 }
4162 err = jvmti_env->GetFieldName(&fdesc, name_ptr, signature_ptr, generic_ptr);
4163 return err;
4164#endif // INCLUDE_JVMTI
4165}
4166
4167static jvmtiError JNICALL
4168jvmti_GetFieldDeclaringClass(jvmtiEnv* env,
4169 jclass klass,
4170 jfieldID field,
4171 jclass* declaring_class_ptr) {
4172
4173#if !INCLUDE_JVMTI
4174 return JVMTI_ERROR_NOT_AVAILABLE;
4175#else
4176 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4177 return JVMTI_ERROR_WRONG_PHASE;
4178 }
4179 Thread* this_thread = Thread::current_or_null();
4180 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4181 return JVMTI_ERROR_UNATTACHED_THREAD;
4182 }
4183 JavaThread* current_thread = (JavaThread*)this_thread;
4184 ThreadInVMfromNative __tiv(current_thread);
4185 VM_ENTRY_BASE(jvmtiError, jvmti_GetFieldDeclaringClass , current_thread)
4186 debug_only(VMNativeEntryWrapper __vew;)
4187 CautiouslyPreserveExceptionMark __em(this_thread);
4188 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4189 if (!jvmti_env->is_valid()) {
4190 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4191 }
4192 jvmtiError err;
4193 oop k_mirror = JNIHandles::resolve_external_guard(klass);
4194 if (k_mirror == NULL) {
4195 return JVMTI_ERROR_INVALID_CLASS;
4196 }
4197 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
4198 return JVMTI_ERROR_INVALID_CLASS;
4199 }
4200
4201 if (java_lang_Class::is_primitive(k_mirror)) {
4202 return JVMTI_ERROR_INVALID_CLASS;
4203 }
4204 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
4205 if (k_oop == NULL) {
4206 return JVMTI_ERROR_INVALID_CLASS;
4207 }
4208 ResourceMark rm_fdesc(current_thread);
4209 fieldDescriptor fdesc;
4210 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
4211 return JVMTI_ERROR_INVALID_FIELDID;
4212 }
4213 if (declaring_class_ptr == NULL) {
4214 return JVMTI_ERROR_NULL_POINTER;
4215 }
4216 err = jvmti_env->GetFieldDeclaringClass(&fdesc, declaring_class_ptr);
4217 return err;
4218#endif // INCLUDE_JVMTI
4219}
4220
4221static jvmtiError JNICALL
4222jvmti_GetFieldModifiers(jvmtiEnv* env,
4223 jclass klass,
4224 jfieldID field,
4225 jint* modifiers_ptr) {
4226
4227#if !INCLUDE_JVMTI
4228 return JVMTI_ERROR_NOT_AVAILABLE;
4229#else
4230 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4231 return JVMTI_ERROR_WRONG_PHASE;
4232 }
4233 Thread* this_thread = Thread::current_or_null();
4234 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4235 return JVMTI_ERROR_UNATTACHED_THREAD;
4236 }
4237 JavaThread* current_thread = (JavaThread*)this_thread;
4238 ThreadInVMfromNative __tiv(current_thread);
4239 VM_ENTRY_BASE(jvmtiError, jvmti_GetFieldModifiers , current_thread)
4240 debug_only(VMNativeEntryWrapper __vew;)
4241 CautiouslyPreserveExceptionMark __em(this_thread);
4242 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4243 if (!jvmti_env->is_valid()) {
4244 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4245 }
4246 jvmtiError err;
4247 oop k_mirror = JNIHandles::resolve_external_guard(klass);
4248 if (k_mirror == NULL) {
4249 return JVMTI_ERROR_INVALID_CLASS;
4250 }
4251 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
4252 return JVMTI_ERROR_INVALID_CLASS;
4253 }
4254
4255 if (java_lang_Class::is_primitive(k_mirror)) {
4256 return JVMTI_ERROR_INVALID_CLASS;
4257 }
4258 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
4259 if (k_oop == NULL) {
4260 return JVMTI_ERROR_INVALID_CLASS;
4261 }
4262 ResourceMark rm_fdesc(current_thread);
4263 fieldDescriptor fdesc;
4264 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
4265 return JVMTI_ERROR_INVALID_FIELDID;
4266 }
4267 if (modifiers_ptr == NULL) {
4268 return JVMTI_ERROR_NULL_POINTER;
4269 }
4270 err = jvmti_env->GetFieldModifiers(&fdesc, modifiers_ptr);
4271 return err;
4272#endif // INCLUDE_JVMTI
4273}
4274
4275static jvmtiError JNICALL
4276jvmti_IsFieldSynthetic(jvmtiEnv* env,
4277 jclass klass,
4278 jfieldID field,
4279 jboolean* is_synthetic_ptr) {
4280
4281#if !INCLUDE_JVMTI
4282 return JVMTI_ERROR_NOT_AVAILABLE;
4283#else
4284 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4285 return JVMTI_ERROR_WRONG_PHASE;
4286 }
4287 Thread* this_thread = Thread::current_or_null();
4288 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4289 return JVMTI_ERROR_UNATTACHED_THREAD;
4290 }
4291 JavaThread* current_thread = (JavaThread*)this_thread;
4292 ThreadInVMfromNative __tiv(current_thread);
4293 VM_ENTRY_BASE(jvmtiError, jvmti_IsFieldSynthetic , current_thread)
4294 debug_only(VMNativeEntryWrapper __vew;)
4295 CautiouslyPreserveExceptionMark __em(this_thread);
4296 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4297 if (!jvmti_env->is_valid()) {
4298 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4299 }
4300
4301 if (jvmti_env->get_capabilities()->can_get_synthetic_attribute == 0) {
4302 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4303 }
4304 jvmtiError err;
4305 oop k_mirror = JNIHandles::resolve_external_guard(klass);
4306 if (k_mirror == NULL) {
4307 return JVMTI_ERROR_INVALID_CLASS;
4308 }
4309 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
4310 return JVMTI_ERROR_INVALID_CLASS;
4311 }
4312
4313 if (java_lang_Class::is_primitive(k_mirror)) {
4314 return JVMTI_ERROR_INVALID_CLASS;
4315 }
4316 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
4317 if (k_oop == NULL) {
4318 return JVMTI_ERROR_INVALID_CLASS;
4319 }
4320 ResourceMark rm_fdesc(current_thread);
4321 fieldDescriptor fdesc;
4322 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
4323 return JVMTI_ERROR_INVALID_FIELDID;
4324 }
4325 if (is_synthetic_ptr == NULL) {
4326 return JVMTI_ERROR_NULL_POINTER;
4327 }
4328 err = jvmti_env->IsFieldSynthetic(&fdesc, is_synthetic_ptr);
4329 return err;
4330#endif // INCLUDE_JVMTI
4331}
4332
4333 //
4334 // Method functions
4335 //
4336
4337static jvmtiError JNICALL
4338jvmti_GetMethodName(jvmtiEnv* env,
4339 jmethodID method,
4340 char** name_ptr,
4341 char** signature_ptr,
4342 char** generic_ptr) {
4343
4344#if !INCLUDE_JVMTI
4345 return JVMTI_ERROR_NOT_AVAILABLE;
4346#else
4347 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4348 return JVMTI_ERROR_WRONG_PHASE;
4349 }
4350 Thread* this_thread = Thread::current_or_null();
4351 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4352 return JVMTI_ERROR_UNATTACHED_THREAD;
4353 }
4354 JavaThread* current_thread = (JavaThread*)this_thread;
4355 ThreadInVMfromNative __tiv(current_thread);
4356 VM_ENTRY_BASE(jvmtiError, jvmti_GetMethodName , current_thread)
4357 debug_only(VMNativeEntryWrapper __vew;)
4358 CautiouslyPreserveExceptionMark __em(this_thread);
4359 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4360 if (!jvmti_env->is_valid()) {
4361 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4362 }
4363 jvmtiError err;
4364 Method* method_oop = Method::checked_resolve_jmethod_id(method);
4365 if (method_oop == NULL) {
4366 return JVMTI_ERROR_INVALID_METHODID;
4367 }
4368 err = jvmti_env->GetMethodName(method_oop, name_ptr, signature_ptr, generic_ptr);
4369 return err;
4370#endif // INCLUDE_JVMTI
4371}
4372
4373static jvmtiError JNICALL
4374jvmti_GetMethodDeclaringClass(jvmtiEnv* env,
4375 jmethodID method,
4376 jclass* declaring_class_ptr) {
4377
4378#if !INCLUDE_JVMTI
4379 return JVMTI_ERROR_NOT_AVAILABLE;
4380#else
4381 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4382 return JVMTI_ERROR_WRONG_PHASE;
4383 }
4384 Thread* this_thread = Thread::current_or_null();
4385 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4386 return JVMTI_ERROR_UNATTACHED_THREAD;
4387 }
4388 JavaThread* current_thread = (JavaThread*)this_thread;
4389 ThreadInVMfromNative __tiv(current_thread);
4390 VM_ENTRY_BASE(jvmtiError, jvmti_GetMethodDeclaringClass , current_thread)
4391 debug_only(VMNativeEntryWrapper __vew;)
4392 CautiouslyPreserveExceptionMark __em(this_thread);
4393 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4394 if (!jvmti_env->is_valid()) {
4395 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4396 }
4397 jvmtiError err;
4398 Method* method_oop = Method::checked_resolve_jmethod_id(method);
4399 if (method_oop == NULL) {
4400 return JVMTI_ERROR_INVALID_METHODID;
4401 }
4402 if (declaring_class_ptr == NULL) {
4403 return JVMTI_ERROR_NULL_POINTER;
4404 }
4405 err = jvmti_env->GetMethodDeclaringClass(method_oop, declaring_class_ptr);
4406 return err;
4407#endif // INCLUDE_JVMTI
4408}
4409
4410static jvmtiError JNICALL
4411jvmti_GetMethodModifiers(jvmtiEnv* env,
4412 jmethodID method,
4413 jint* modifiers_ptr) {
4414
4415#if !INCLUDE_JVMTI
4416 return JVMTI_ERROR_NOT_AVAILABLE;
4417#else
4418 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4419 return JVMTI_ERROR_WRONG_PHASE;
4420 }
4421 Thread* this_thread = Thread::current_or_null();
4422 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4423 return JVMTI_ERROR_UNATTACHED_THREAD;
4424 }
4425 JavaThread* current_thread = (JavaThread*)this_thread;
4426 ThreadInVMfromNative __tiv(current_thread);
4427 VM_ENTRY_BASE(jvmtiError, jvmti_GetMethodModifiers , current_thread)
4428 debug_only(VMNativeEntryWrapper __vew;)
4429 CautiouslyPreserveExceptionMark __em(this_thread);
4430 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4431 if (!jvmti_env->is_valid()) {
4432 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4433 }
4434 jvmtiError err;
4435 Method* method_oop = Method::checked_resolve_jmethod_id(method);
4436 if (method_oop == NULL) {
4437 return JVMTI_ERROR_INVALID_METHODID;
4438 }
4439 if (modifiers_ptr == NULL) {
4440 return JVMTI_ERROR_NULL_POINTER;
4441 }
4442 err = jvmti_env->GetMethodModifiers(method_oop, modifiers_ptr);
4443 return err;
4444#endif // INCLUDE_JVMTI
4445}
4446
4447static jvmtiError JNICALL
4448jvmti_GetMaxLocals(jvmtiEnv* env,
4449 jmethodID method,
4450 jint* max_ptr) {
4451
4452#if !INCLUDE_JVMTI
4453 return JVMTI_ERROR_NOT_AVAILABLE;
4454#else
4455 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4456 return JVMTI_ERROR_WRONG_PHASE;
4457 }
4458 Thread* this_thread = Thread::current_or_null();
4459 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4460 return JVMTI_ERROR_UNATTACHED_THREAD;
4461 }
4462 JavaThread* current_thread = (JavaThread*)this_thread;
4463 ThreadInVMfromNative __tiv(current_thread);
4464 VM_ENTRY_BASE(jvmtiError, jvmti_GetMaxLocals , current_thread)
4465 debug_only(VMNativeEntryWrapper __vew;)
4466 CautiouslyPreserveExceptionMark __em(this_thread);
4467 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4468 if (!jvmti_env->is_valid()) {
4469 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4470 }
4471 jvmtiError err;
4472 Method* method_oop = Method::checked_resolve_jmethod_id(method);
4473 if (method_oop == NULL) {
4474 return JVMTI_ERROR_INVALID_METHODID;
4475 }
4476 if (method_oop->is_native()) {
4477 return JVMTI_ERROR_NATIVE_METHOD;
4478 }
4479 if (max_ptr == NULL) {
4480 return JVMTI_ERROR_NULL_POINTER;
4481 }
4482 err = jvmti_env->GetMaxLocals(method_oop, max_ptr);
4483 return err;
4484#endif // INCLUDE_JVMTI
4485}
4486
4487static jvmtiError JNICALL
4488jvmti_GetArgumentsSize(jvmtiEnv* env,
4489 jmethodID method,
4490 jint* size_ptr) {
4491
4492#if !INCLUDE_JVMTI
4493 return JVMTI_ERROR_NOT_AVAILABLE;
4494#else
4495 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4496 return JVMTI_ERROR_WRONG_PHASE;
4497 }
4498 Thread* this_thread = Thread::current_or_null();
4499 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4500 return JVMTI_ERROR_UNATTACHED_THREAD;
4501 }
4502 JavaThread* current_thread = (JavaThread*)this_thread;
4503 ThreadInVMfromNative __tiv(current_thread);
4504 VM_ENTRY_BASE(jvmtiError, jvmti_GetArgumentsSize , current_thread)
4505 debug_only(VMNativeEntryWrapper __vew;)
4506 CautiouslyPreserveExceptionMark __em(this_thread);
4507 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4508 if (!jvmti_env->is_valid()) {
4509 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4510 }
4511 jvmtiError err;
4512 Method* method_oop = Method::checked_resolve_jmethod_id(method);
4513 if (method_oop == NULL) {
4514 return JVMTI_ERROR_INVALID_METHODID;
4515 }
4516 if (method_oop->is_native()) {
4517 return JVMTI_ERROR_NATIVE_METHOD;
4518 }
4519 if (size_ptr == NULL) {
4520 return JVMTI_ERROR_NULL_POINTER;
4521 }
4522 err = jvmti_env->GetArgumentsSize(method_oop, size_ptr);
4523 return err;
4524#endif // INCLUDE_JVMTI
4525}
4526
4527static jvmtiError JNICALL
4528jvmti_GetLineNumberTable(jvmtiEnv* env,
4529 jmethodID method,
4530 jint* entry_count_ptr,
4531 jvmtiLineNumberEntry** table_ptr) {
4532
4533#if !INCLUDE_JVMTI
4534 return JVMTI_ERROR_NOT_AVAILABLE;
4535#else
4536 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4537 return JVMTI_ERROR_WRONG_PHASE;
4538 }
4539 Thread* this_thread = Thread::current_or_null();
4540 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4541 return JVMTI_ERROR_UNATTACHED_THREAD;
4542 }
4543 JavaThread* current_thread = (JavaThread*)this_thread;
4544 ThreadInVMfromNative __tiv(current_thread);
4545 VM_ENTRY_BASE(jvmtiError, jvmti_GetLineNumberTable , current_thread)
4546 debug_only(VMNativeEntryWrapper __vew;)
4547 CautiouslyPreserveExceptionMark __em(this_thread);
4548 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4549 if (!jvmti_env->is_valid()) {
4550 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4551 }
4552
4553 if (jvmti_env->get_capabilities()->can_get_line_numbers == 0) {
4554 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4555 }
4556 jvmtiError err;
4557 Method* method_oop = Method::checked_resolve_jmethod_id(method);
4558 if (method_oop == NULL) {
4559 return JVMTI_ERROR_INVALID_METHODID;
4560 }
4561 if (method_oop->is_native()) {
4562 return JVMTI_ERROR_NATIVE_METHOD;
4563 }
4564 if (entry_count_ptr == NULL) {
4565 return JVMTI_ERROR_NULL_POINTER;
4566 }
4567 if (table_ptr == NULL) {
4568 return JVMTI_ERROR_NULL_POINTER;
4569 }
4570 err = jvmti_env->GetLineNumberTable(method_oop, entry_count_ptr, table_ptr);
4571 return err;
4572#endif // INCLUDE_JVMTI
4573}
4574
4575static jvmtiError JNICALL
4576jvmti_GetMethodLocation(jvmtiEnv* env,
4577 jmethodID method,
4578 jlocation* start_location_ptr,
4579 jlocation* end_location_ptr) {
4580
4581#if !INCLUDE_JVMTI
4582 return JVMTI_ERROR_NOT_AVAILABLE;
4583#else
4584 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4585 return JVMTI_ERROR_WRONG_PHASE;
4586 }
4587 Thread* this_thread = Thread::current_or_null();
4588 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4589 return JVMTI_ERROR_UNATTACHED_THREAD;
4590 }
4591 JavaThread* current_thread = (JavaThread*)this_thread;
4592 ThreadInVMfromNative __tiv(current_thread);
4593 VM_ENTRY_BASE(jvmtiError, jvmti_GetMethodLocation , current_thread)
4594 debug_only(VMNativeEntryWrapper __vew;)
4595 CautiouslyPreserveExceptionMark __em(this_thread);
4596 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4597 if (!jvmti_env->is_valid()) {
4598 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4599 }
4600 jvmtiError err;
4601 Method* method_oop = Method::checked_resolve_jmethod_id(method);
4602 if (method_oop == NULL) {
4603 return JVMTI_ERROR_INVALID_METHODID;
4604 }
4605 if (method_oop->is_native()) {
4606 return JVMTI_ERROR_NATIVE_METHOD;
4607 }
4608 if (start_location_ptr == NULL) {
4609 return JVMTI_ERROR_NULL_POINTER;
4610 }
4611 if (end_location_ptr == NULL) {
4612 return JVMTI_ERROR_NULL_POINTER;
4613 }
4614 err = jvmti_env->GetMethodLocation(method_oop, start_location_ptr, end_location_ptr);
4615 return err;
4616#endif // INCLUDE_JVMTI
4617}
4618
4619static jvmtiError JNICALL
4620jvmti_GetLocalVariableTable(jvmtiEnv* env,
4621 jmethodID method,
4622 jint* entry_count_ptr,
4623 jvmtiLocalVariableEntry** table_ptr) {
4624
4625#if !INCLUDE_JVMTI
4626 return JVMTI_ERROR_NOT_AVAILABLE;
4627#else
4628 if(!JvmtiEnv::is_vm_live()) {
4629 return JVMTI_ERROR_WRONG_PHASE;
4630 }
4631 Thread* this_thread = Thread::current_or_null();
4632 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4633 return JVMTI_ERROR_UNATTACHED_THREAD;
4634 }
4635 JavaThread* current_thread = (JavaThread*)this_thread;
4636 ThreadInVMfromNative __tiv(current_thread);
4637 VM_ENTRY_BASE(jvmtiError, jvmti_GetLocalVariableTable , current_thread)
4638 debug_only(VMNativeEntryWrapper __vew;)
4639 CautiouslyPreserveExceptionMark __em(this_thread);
4640 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4641 if (!jvmti_env->is_valid()) {
4642 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4643 }
4644
4645 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
4646 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4647 }
4648 jvmtiError err;
4649 Method* method_oop = Method::checked_resolve_jmethod_id(method);
4650 if (method_oop == NULL) {
4651 return JVMTI_ERROR_INVALID_METHODID;
4652 }
4653 if (method_oop->is_native()) {
4654 return JVMTI_ERROR_NATIVE_METHOD;
4655 }
4656 if (entry_count_ptr == NULL) {
4657 return JVMTI_ERROR_NULL_POINTER;
4658 }
4659 if (table_ptr == NULL) {
4660 return JVMTI_ERROR_NULL_POINTER;
4661 }
4662 err = jvmti_env->GetLocalVariableTable(method_oop, entry_count_ptr, table_ptr);
4663 return err;
4664#endif // INCLUDE_JVMTI
4665}
4666
4667static jvmtiError JNICALL
4668jvmti_GetBytecodes(jvmtiEnv* env,
4669 jmethodID method,
4670 jint* bytecode_count_ptr,
4671 unsigned char** bytecodes_ptr) {
4672
4673#if !INCLUDE_JVMTI
4674 return JVMTI_ERROR_NOT_AVAILABLE;
4675#else
4676 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4677 return JVMTI_ERROR_WRONG_PHASE;
4678 }
4679 Thread* this_thread = Thread::current_or_null();
4680 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4681 return JVMTI_ERROR_UNATTACHED_THREAD;
4682 }
4683 JavaThread* current_thread = (JavaThread*)this_thread;
4684 ThreadInVMfromNative __tiv(current_thread);
4685 VM_ENTRY_BASE(jvmtiError, jvmti_GetBytecodes , current_thread)
4686 debug_only(VMNativeEntryWrapper __vew;)
4687 CautiouslyPreserveExceptionMark __em(this_thread);
4688 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4689 if (!jvmti_env->is_valid()) {
4690 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4691 }
4692
4693 if (jvmti_env->get_capabilities()->can_get_bytecodes == 0) {
4694 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4695 }
4696 jvmtiError err;
4697 Method* method_oop = Method::checked_resolve_jmethod_id(method);
4698 if (method_oop == NULL) {
4699 return JVMTI_ERROR_INVALID_METHODID;
4700 }
4701 if (method_oop->is_native()) {
4702 return JVMTI_ERROR_NATIVE_METHOD;
4703 }
4704 if (bytecode_count_ptr == NULL) {
4705 return JVMTI_ERROR_NULL_POINTER;
4706 }
4707 if (bytecodes_ptr == NULL) {
4708 return JVMTI_ERROR_NULL_POINTER;
4709 }
4710 err = jvmti_env->GetBytecodes(method_oop, bytecode_count_ptr, bytecodes_ptr);
4711 return err;
4712#endif // INCLUDE_JVMTI
4713}
4714
4715static jvmtiError JNICALL
4716jvmti_IsMethodNative(jvmtiEnv* env,
4717 jmethodID method,
4718 jboolean* is_native_ptr) {
4719
4720#if !INCLUDE_JVMTI
4721 return JVMTI_ERROR_NOT_AVAILABLE;
4722#else
4723 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4724 return JVMTI_ERROR_WRONG_PHASE;
4725 }
4726 Thread* this_thread = Thread::current_or_null();
4727 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4728 return JVMTI_ERROR_UNATTACHED_THREAD;
4729 }
4730 JavaThread* current_thread = (JavaThread*)this_thread;
4731 ThreadInVMfromNative __tiv(current_thread);
4732 VM_ENTRY_BASE(jvmtiError, jvmti_IsMethodNative , current_thread)
4733 debug_only(VMNativeEntryWrapper __vew;)
4734 CautiouslyPreserveExceptionMark __em(this_thread);
4735 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4736 if (!jvmti_env->is_valid()) {
4737 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4738 }
4739 jvmtiError err;
4740 Method* method_oop = Method::checked_resolve_jmethod_id(method);
4741 if (method_oop == NULL) {
4742 return JVMTI_ERROR_INVALID_METHODID;
4743 }
4744 if (is_native_ptr == NULL) {
4745 return JVMTI_ERROR_NULL_POINTER;
4746 }
4747 err = jvmti_env->IsMethodNative(method_oop, is_native_ptr);
4748 return err;
4749#endif // INCLUDE_JVMTI
4750}
4751
4752static jvmtiError JNICALL
4753jvmti_IsMethodSynthetic(jvmtiEnv* env,
4754 jmethodID method,
4755 jboolean* is_synthetic_ptr) {
4756
4757#if !INCLUDE_JVMTI
4758 return JVMTI_ERROR_NOT_AVAILABLE;
4759#else
4760 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4761 return JVMTI_ERROR_WRONG_PHASE;
4762 }
4763 Thread* this_thread = Thread::current_or_null();
4764 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4765 return JVMTI_ERROR_UNATTACHED_THREAD;
4766 }
4767 JavaThread* current_thread = (JavaThread*)this_thread;
4768 ThreadInVMfromNative __tiv(current_thread);
4769 VM_ENTRY_BASE(jvmtiError, jvmti_IsMethodSynthetic , current_thread)
4770 debug_only(VMNativeEntryWrapper __vew;)
4771 CautiouslyPreserveExceptionMark __em(this_thread);
4772 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4773 if (!jvmti_env->is_valid()) {
4774 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4775 }
4776
4777 if (jvmti_env->get_capabilities()->can_get_synthetic_attribute == 0) {
4778 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4779 }
4780 jvmtiError err;
4781 Method* method_oop = Method::checked_resolve_jmethod_id(method);
4782 if (method_oop == NULL) {
4783 return JVMTI_ERROR_INVALID_METHODID;
4784 }
4785 if (is_synthetic_ptr == NULL) {
4786 return JVMTI_ERROR_NULL_POINTER;
4787 }
4788 err = jvmti_env->IsMethodSynthetic(method_oop, is_synthetic_ptr);
4789 return err;
4790#endif // INCLUDE_JVMTI
4791}
4792
4793static jvmtiError JNICALL
4794jvmti_IsMethodObsolete(jvmtiEnv* env,
4795 jmethodID method,
4796 jboolean* is_obsolete_ptr) {
4797
4798#if !INCLUDE_JVMTI
4799 return JVMTI_ERROR_NOT_AVAILABLE;
4800#else
4801 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4802 return JVMTI_ERROR_WRONG_PHASE;
4803 }
4804 Thread* this_thread = Thread::current_or_null();
4805 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4806 return JVMTI_ERROR_UNATTACHED_THREAD;
4807 }
4808 JavaThread* current_thread = (JavaThread*)this_thread;
4809 ThreadInVMfromNative __tiv(current_thread);
4810 VM_ENTRY_BASE(jvmtiError, jvmti_IsMethodObsolete , current_thread)
4811 debug_only(VMNativeEntryWrapper __vew;)
4812 CautiouslyPreserveExceptionMark __em(this_thread);
4813 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4814 if (!jvmti_env->is_valid()) {
4815 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4816 }
4817 jvmtiError err;
4818 Method* method_oop = Method::checked_resolve_jmethod_id(method);
4819 if (method_oop == NULL) {
4820 return JVMTI_ERROR_INVALID_METHODID;
4821 }
4822 if (is_obsolete_ptr == NULL) {
4823 return JVMTI_ERROR_NULL_POINTER;
4824 }
4825 err = jvmti_env->IsMethodObsolete(method_oop, is_obsolete_ptr);
4826 return err;
4827#endif // INCLUDE_JVMTI
4828}
4829
4830static jvmtiError JNICALL
4831jvmti_SetNativeMethodPrefix(jvmtiEnv* env,
4832 const char* prefix) {
4833
4834 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4835 if (!jvmti_env->is_valid()) {
4836 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4837 }
4838
4839 if (jvmti_env->get_capabilities()->can_set_native_method_prefix == 0) {
4840 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4841 }
4842 jvmtiError err;
4843 if (Threads::number_of_threads() != 0) {
4844 Thread* this_thread = Thread::current_or_null();
4845 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4846 return JVMTI_ERROR_UNATTACHED_THREAD;
4847 }
4848 JavaThread* current_thread = (JavaThread*)this_thread;
4849 ThreadInVMfromNative __tiv(current_thread);
4850 VM_ENTRY_BASE(jvmtiError, jvmti_SetNativeMethodPrefix , current_thread)
4851 debug_only(VMNativeEntryWrapper __vew;)
4852 CautiouslyPreserveExceptionMark __em(this_thread);
4853 err = jvmti_env->SetNativeMethodPrefix(prefix);
4854 } else {
4855 err = jvmti_env->SetNativeMethodPrefix(prefix);
4856 }
4857 return err;
4858}
4859
4860static jvmtiError JNICALL
4861jvmti_SetNativeMethodPrefixes(jvmtiEnv* env,
4862 jint prefix_count,
4863 char** prefixes) {
4864
4865 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4866 if (!jvmti_env->is_valid()) {
4867 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4868 }
4869
4870 if (jvmti_env->get_capabilities()->can_set_native_method_prefix == 0) {
4871 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4872 }
4873 jvmtiError err;
4874 if (Threads::number_of_threads() != 0) {
4875 Thread* this_thread = Thread::current_or_null();
4876 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4877 return JVMTI_ERROR_UNATTACHED_THREAD;
4878 }
4879 JavaThread* current_thread = (JavaThread*)this_thread;
4880 ThreadInVMfromNative __tiv(current_thread);
4881 VM_ENTRY_BASE(jvmtiError, jvmti_SetNativeMethodPrefixes , current_thread)
4882 debug_only(VMNativeEntryWrapper __vew;)
4883 CautiouslyPreserveExceptionMark __em(this_thread);
4884 if (prefix_count < 0) {
4885 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
4886 }
4887 if (prefixes == NULL) {
4888 return JVMTI_ERROR_NULL_POINTER;
4889 }
4890 err = jvmti_env->SetNativeMethodPrefixes(prefix_count, prefixes);
4891 } else {
4892 if (prefix_count < 0) {
4893 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
4894 }
4895 if (prefixes == NULL) {
4896 return JVMTI_ERROR_NULL_POINTER;
4897 }
4898 err = jvmti_env->SetNativeMethodPrefixes(prefix_count, prefixes);
4899 }
4900 return err;
4901}
4902
4903 //
4904 // Raw Monitor functions
4905 //
4906
4907static jvmtiError JNICALL
4908jvmti_CreateRawMonitor(jvmtiEnv* env,
4909 const char* name,
4910 jrawMonitorID* monitor_ptr) {
4911
4912#if !INCLUDE_JVMTI
4913 return JVMTI_ERROR_NOT_AVAILABLE;
4914#else
4915 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4916 return JVMTI_ERROR_WRONG_PHASE;
4917 }
4918 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4919 if (!jvmti_env->is_valid()) {
4920 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4921 }
4922 jvmtiError err;
4923 Thread* this_thread = NULL;
4924 bool transition;
4925 if (Threads::number_of_threads() == 0) {
4926 transition = false;
4927 } else {
4928 this_thread = Thread::current_or_null();
4929 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
4930 }
4931 if (transition) {
4932 if (!this_thread->is_Java_thread()) {
4933 return JVMTI_ERROR_UNATTACHED_THREAD;
4934 }
4935 JavaThread* current_thread = (JavaThread*)this_thread;
4936 ThreadInVMfromNative __tiv(current_thread);
4937 VM_ENTRY_BASE(jvmtiError, jvmti_CreateRawMonitor , current_thread)
4938 debug_only(VMNativeEntryWrapper __vew;)
4939 if (name == NULL) {
4940 return JVMTI_ERROR_NULL_POINTER;
4941 }
4942 if (monitor_ptr == NULL) {
4943 return JVMTI_ERROR_NULL_POINTER;
4944 }
4945 err = jvmti_env->CreateRawMonitor(name, monitor_ptr);
4946 } else {
4947 if (name == NULL) {
4948 return JVMTI_ERROR_NULL_POINTER;
4949 }
4950 if (monitor_ptr == NULL) {
4951 return JVMTI_ERROR_NULL_POINTER;
4952 }
4953 err = jvmti_env->CreateRawMonitor(name, monitor_ptr);
4954 }
4955 return err;
4956#endif // INCLUDE_JVMTI
4957}
4958
4959static jvmtiError JNICALL
4960jvmti_DestroyRawMonitor(jvmtiEnv* env,
4961 jrawMonitorID monitor) {
4962
4963#if !INCLUDE_JVMTI
4964 return JVMTI_ERROR_NOT_AVAILABLE;
4965#else
4966 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4967 return JVMTI_ERROR_WRONG_PHASE;
4968 }
4969 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4970 if (!jvmti_env->is_valid()) {
4971 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4972 }
4973 jvmtiError err;
4974 Thread* this_thread = NULL;
4975 bool transition;
4976 if (Threads::number_of_threads() == 0) {
4977 transition = false;
4978 } else {
4979 this_thread = Thread::current_or_null();
4980 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
4981 }
4982 if (transition) {
4983 if (!this_thread->is_Java_thread()) {
4984 return JVMTI_ERROR_UNATTACHED_THREAD;
4985 }
4986 JavaThread* current_thread = (JavaThread*)this_thread;
4987 ThreadInVMfromNative __tiv(current_thread);
4988 VM_ENTRY_BASE(jvmtiError, jvmti_DestroyRawMonitor , current_thread)
4989 debug_only(VMNativeEntryWrapper __vew;)
4990 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
4991 if (rmonitor == NULL) {
4992 return JVMTI_ERROR_INVALID_MONITOR;
4993 }
4994 if (!rmonitor->is_valid()) {
4995 return JVMTI_ERROR_INVALID_MONITOR;
4996 }
4997 err = jvmti_env->DestroyRawMonitor(rmonitor);
4998 } else {
4999 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
5000 if (rmonitor == NULL) {
5001 return JVMTI_ERROR_INVALID_MONITOR;
5002 }
5003 if (!rmonitor->is_valid()) {
5004 return JVMTI_ERROR_INVALID_MONITOR;
5005 }
5006 err = jvmti_env->DestroyRawMonitor(rmonitor);
5007 }
5008 return err;
5009#endif // INCLUDE_JVMTI
5010}
5011
5012static jvmtiError JNICALL
5013jvmti_RawMonitorEnter(jvmtiEnv* env,
5014 jrawMonitorID monitor) {
5015
5016#if !INCLUDE_JVMTI
5017 return JVMTI_ERROR_NOT_AVAILABLE;
5018#else
5019
5020 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5021 if (!jvmti_env->is_valid()) {
5022 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5023 }
5024 jvmtiError err;
5025 Thread* this_thread = NULL;
5026 bool transition;
5027 if (Threads::number_of_threads() == 0) {
5028 transition = false;
5029 } else {
5030 this_thread = Thread::current_or_null();
5031 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
5032 }
5033 if (transition) {
5034 if (!this_thread->is_Java_thread()) {
5035 return JVMTI_ERROR_UNATTACHED_THREAD;
5036 }
5037
5038 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
5039 if (rmonitor == NULL) {
5040 return JVMTI_ERROR_INVALID_MONITOR;
5041 }
5042 if (!rmonitor->is_valid()) {
5043 return JVMTI_ERROR_INVALID_MONITOR;
5044 }
5045 err = jvmti_env->RawMonitorEnter(rmonitor);
5046 } else {
5047 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
5048 if (rmonitor == NULL) {
5049 return JVMTI_ERROR_INVALID_MONITOR;
5050 }
5051 if (!rmonitor->is_valid()) {
5052 return JVMTI_ERROR_INVALID_MONITOR;
5053 }
5054 err = jvmti_env->RawMonitorEnter(rmonitor);
5055 }
5056 return err;
5057#endif // INCLUDE_JVMTI
5058}
5059
5060static jvmtiError JNICALL
5061jvmti_RawMonitorExit(jvmtiEnv* env,
5062 jrawMonitorID monitor) {
5063
5064#if !INCLUDE_JVMTI
5065 return JVMTI_ERROR_NOT_AVAILABLE;
5066#else
5067
5068 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5069 if (!jvmti_env->is_valid()) {
5070 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5071 }
5072 jvmtiError err;
5073 Thread* this_thread = NULL;
5074 bool transition;
5075 if (Threads::number_of_threads() == 0) {
5076 transition = false;
5077 } else {
5078 this_thread = Thread::current_or_null();
5079 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
5080 }
5081 if (transition) {
5082 if (!this_thread->is_Java_thread()) {
5083 return JVMTI_ERROR_UNATTACHED_THREAD;
5084 }
5085
5086 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
5087 if (rmonitor == NULL) {
5088 return JVMTI_ERROR_INVALID_MONITOR;
5089 }
5090 if (!rmonitor->is_valid()) {
5091 return JVMTI_ERROR_INVALID_MONITOR;
5092 }
5093 err = jvmti_env->RawMonitorExit(rmonitor);
5094 } else {
5095 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
5096 if (rmonitor == NULL) {
5097 return JVMTI_ERROR_INVALID_MONITOR;
5098 }
5099 if (!rmonitor->is_valid()) {
5100 return JVMTI_ERROR_INVALID_MONITOR;
5101 }
5102 err = jvmti_env->RawMonitorExit(rmonitor);
5103 }
5104 return err;
5105#endif // INCLUDE_JVMTI
5106}
5107
5108static jvmtiError JNICALL
5109jvmti_RawMonitorWait(jvmtiEnv* env,
5110 jrawMonitorID monitor,
5111 jlong millis) {
5112
5113#if !INCLUDE_JVMTI
5114 return JVMTI_ERROR_NOT_AVAILABLE;
5115#else
5116
5117 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5118 if (!jvmti_env->is_valid()) {
5119 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5120 }
5121 jvmtiError err;
5122 Thread* this_thread = NULL;
5123 bool transition;
5124 if (Threads::number_of_threads() == 0) {
5125 transition = false;
5126 } else {
5127 this_thread = Thread::current_or_null();
5128 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
5129 }
5130 if (transition) {
5131 if (!this_thread->is_Java_thread()) {
5132 return JVMTI_ERROR_UNATTACHED_THREAD;
5133 }
5134
5135 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
5136 if (rmonitor == NULL) {
5137 return JVMTI_ERROR_INVALID_MONITOR;
5138 }
5139 if (!rmonitor->is_valid()) {
5140 return JVMTI_ERROR_INVALID_MONITOR;
5141 }
5142 err = jvmti_env->RawMonitorWait(rmonitor, millis);
5143 } else {
5144 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
5145 if (rmonitor == NULL) {
5146 return JVMTI_ERROR_INVALID_MONITOR;
5147 }
5148 if (!rmonitor->is_valid()) {
5149 return JVMTI_ERROR_INVALID_MONITOR;
5150 }
5151 err = jvmti_env->RawMonitorWait(rmonitor, millis);
5152 }
5153 return err;
5154#endif // INCLUDE_JVMTI
5155}
5156
5157static jvmtiError JNICALL
5158jvmti_RawMonitorNotify(jvmtiEnv* env,
5159 jrawMonitorID monitor) {
5160
5161#if !INCLUDE_JVMTI
5162 return JVMTI_ERROR_NOT_AVAILABLE;
5163#else
5164
5165 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5166 if (!jvmti_env->is_valid()) {
5167 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5168 }
5169 jvmtiError err;
5170 Thread* this_thread = NULL;
5171 bool transition;
5172 if (Threads::number_of_threads() == 0) {
5173 transition = false;
5174 } else {
5175 this_thread = Thread::current_or_null();
5176 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
5177 }
5178 if (transition) {
5179 if (!this_thread->is_Java_thread()) {
5180 return JVMTI_ERROR_UNATTACHED_THREAD;
5181 }
5182 JavaThread* current_thread = (JavaThread*)this_thread;
5183 ThreadInVMfromNative __tiv(current_thread);
5184 VM_ENTRY_BASE(jvmtiError, jvmti_RawMonitorNotify , current_thread)
5185 debug_only(VMNativeEntryWrapper __vew;)
5186 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
5187 if (rmonitor == NULL) {
5188 return JVMTI_ERROR_INVALID_MONITOR;
5189 }
5190 if (!rmonitor->is_valid()) {
5191 return JVMTI_ERROR_INVALID_MONITOR;
5192 }
5193 err = jvmti_env->RawMonitorNotify(rmonitor);
5194 } else {
5195 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
5196 if (rmonitor == NULL) {
5197 return JVMTI_ERROR_INVALID_MONITOR;
5198 }
5199 if (!rmonitor->is_valid()) {
5200 return JVMTI_ERROR_INVALID_MONITOR;
5201 }
5202 err = jvmti_env->RawMonitorNotify(rmonitor);
5203 }
5204 return err;
5205#endif // INCLUDE_JVMTI
5206}
5207
5208static jvmtiError JNICALL
5209jvmti_RawMonitorNotifyAll(jvmtiEnv* env,
5210 jrawMonitorID monitor) {
5211
5212#if !INCLUDE_JVMTI
5213 return JVMTI_ERROR_NOT_AVAILABLE;
5214#else
5215
5216 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5217 if (!jvmti_env->is_valid()) {
5218 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5219 }
5220 jvmtiError err;
5221 Thread* this_thread = NULL;
5222 bool transition;
5223 if (Threads::number_of_threads() == 0) {
5224 transition = false;
5225 } else {
5226 this_thread = Thread::current_or_null();
5227 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
5228 }
5229 if (transition) {
5230 if (!this_thread->is_Java_thread()) {
5231 return JVMTI_ERROR_UNATTACHED_THREAD;
5232 }
5233 JavaThread* current_thread = (JavaThread*)this_thread;
5234 ThreadInVMfromNative __tiv(current_thread);
5235 VM_ENTRY_BASE(jvmtiError, jvmti_RawMonitorNotifyAll , current_thread)
5236 debug_only(VMNativeEntryWrapper __vew;)
5237 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
5238 if (rmonitor == NULL) {
5239 return JVMTI_ERROR_INVALID_MONITOR;
5240 }
5241 if (!rmonitor->is_valid()) {
5242 return JVMTI_ERROR_INVALID_MONITOR;
5243 }
5244 err = jvmti_env->RawMonitorNotifyAll(rmonitor);
5245 } else {
5246 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
5247 if (rmonitor == NULL) {
5248 return JVMTI_ERROR_INVALID_MONITOR;
5249 }
5250 if (!rmonitor->is_valid()) {
5251 return JVMTI_ERROR_INVALID_MONITOR;
5252 }
5253 err = jvmti_env->RawMonitorNotifyAll(rmonitor);
5254 }
5255 return err;
5256#endif // INCLUDE_JVMTI
5257}
5258
5259 //
5260 // JNI Function Interception functions
5261 //
5262
5263static jvmtiError JNICALL
5264jvmti_SetJNIFunctionTable(jvmtiEnv* env,
5265 const jniNativeInterface* function_table) {
5266
5267#if !INCLUDE_JVMTI
5268 return JVMTI_ERROR_NOT_AVAILABLE;
5269#else
5270 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
5271 return JVMTI_ERROR_WRONG_PHASE;
5272 }
5273 Thread* this_thread = Thread::current_or_null();
5274 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5275 return JVMTI_ERROR_UNATTACHED_THREAD;
5276 }
5277 JavaThread* current_thread = (JavaThread*)this_thread;
5278 ThreadInVMfromNative __tiv(current_thread);
5279 VM_ENTRY_BASE(jvmtiError, jvmti_SetJNIFunctionTable , current_thread)
5280 debug_only(VMNativeEntryWrapper __vew;)
5281 CautiouslyPreserveExceptionMark __em(this_thread);
5282 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5283 if (!jvmti_env->is_valid()) {
5284 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5285 }
5286 jvmtiError err;
5287 if (function_table == NULL) {
5288 return JVMTI_ERROR_NULL_POINTER;
5289 }
5290 err = jvmti_env->SetJNIFunctionTable(function_table);
5291 return err;
5292#endif // INCLUDE_JVMTI
5293}
5294
5295static jvmtiError JNICALL
5296jvmti_GetJNIFunctionTable(jvmtiEnv* env,
5297 jniNativeInterface** function_table) {
5298
5299#if !INCLUDE_JVMTI
5300 return JVMTI_ERROR_NOT_AVAILABLE;
5301#else
5302 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
5303 return JVMTI_ERROR_WRONG_PHASE;
5304 }
5305 Thread* this_thread = Thread::current_or_null();
5306 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5307 return JVMTI_ERROR_UNATTACHED_THREAD;
5308 }
5309 JavaThread* current_thread = (JavaThread*)this_thread;
5310 ThreadInVMfromNative __tiv(current_thread);
5311 VM_ENTRY_BASE(jvmtiError, jvmti_GetJNIFunctionTable , current_thread)
5312 debug_only(VMNativeEntryWrapper __vew;)
5313 CautiouslyPreserveExceptionMark __em(this_thread);
5314 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5315 if (!jvmti_env->is_valid()) {
5316 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5317 }
5318 jvmtiError err;
5319 if (function_table == NULL) {
5320 return JVMTI_ERROR_NULL_POINTER;
5321 }
5322 err = jvmti_env->GetJNIFunctionTable(function_table);
5323 return err;
5324#endif // INCLUDE_JVMTI
5325}
5326
5327 //
5328 // Event Management functions
5329 //
5330
5331static jvmtiError JNICALL
5332jvmti_SetEventCallbacks(jvmtiEnv* env,
5333 const jvmtiEventCallbacks* callbacks,
5334 jint size_of_callbacks) {
5335 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
5336 return JVMTI_ERROR_WRONG_PHASE;
5337 }
5338 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5339 if (!jvmti_env->is_valid()) {
5340 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5341 }
5342 jvmtiError err;
5343 if (Threads::number_of_threads() != 0) {
5344 Thread* this_thread = Thread::current_or_null();
5345 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5346 return JVMTI_ERROR_UNATTACHED_THREAD;
5347 }
5348 JavaThread* current_thread = (JavaThread*)this_thread;
5349 ThreadInVMfromNative __tiv(current_thread);
5350 VM_ENTRY_BASE(jvmtiError, jvmti_SetEventCallbacks , current_thread)
5351 debug_only(VMNativeEntryWrapper __vew;)
5352 CautiouslyPreserveExceptionMark __em(this_thread);
5353 if (size_of_callbacks < 0) {
5354 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
5355 }
5356 err = jvmti_env->SetEventCallbacks(callbacks, size_of_callbacks);
5357 } else {
5358 if (size_of_callbacks < 0) {
5359 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
5360 }
5361 err = jvmti_env->SetEventCallbacks(callbacks, size_of_callbacks);
5362 }
5363 return err;
5364}
5365
5366static jvmtiError JNICALL
5367jvmti_SetEventNotificationMode(jvmtiEnv* env,
5368 jvmtiEventMode mode,
5369 jvmtiEvent event_type,
5370 jthread event_thread,
5371 ...) {
5372 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
5373 return JVMTI_ERROR_WRONG_PHASE;
5374 }
5375 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5376 if (!jvmti_env->is_valid()) {
5377 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5378 }
5379 jvmtiError err;
5380 if (Threads::number_of_threads() != 0) {
5381 Thread* this_thread = Thread::current_or_null();
5382 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5383 return JVMTI_ERROR_UNATTACHED_THREAD;
5384 }
5385 JavaThread* current_thread = (JavaThread*)this_thread;
5386 ThreadInVMfromNative __tiv(current_thread);
5387 VM_ENTRY_BASE(jvmtiError, jvmti_SetEventNotificationMode , current_thread)
5388 debug_only(VMNativeEntryWrapper __vew;)
5389 CautiouslyPreserveExceptionMark __em(this_thread);
5390 err = jvmti_env->SetEventNotificationMode(mode, event_type, event_thread, NULL);
5391 } else {
5392 err = jvmti_env->SetEventNotificationMode(mode, event_type, event_thread, NULL);
5393 }
5394 return err;
5395}
5396
5397static jvmtiError JNICALL
5398jvmti_GenerateEvents(jvmtiEnv* env,
5399 jvmtiEvent event_type) {
5400
5401#if !INCLUDE_JVMTI
5402 return JVMTI_ERROR_NOT_AVAILABLE;
5403#else
5404 if(!JvmtiEnv::is_vm_live()) {
5405 return JVMTI_ERROR_WRONG_PHASE;
5406 }
5407 Thread* this_thread = Thread::current_or_null();
5408 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5409 return JVMTI_ERROR_UNATTACHED_THREAD;
5410 }
5411 JavaThread* current_thread = (JavaThread*)this_thread;
5412 ThreadInVMfromNative __tiv(current_thread);
5413 VM_ENTRY_BASE(jvmtiError, jvmti_GenerateEvents , current_thread)
5414 debug_only(VMNativeEntryWrapper __vew;)
5415 CautiouslyPreserveExceptionMark __em(this_thread);
5416 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5417 if (!jvmti_env->is_valid()) {
5418 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5419 }
5420 jvmtiError err;
5421 err = jvmti_env->GenerateEvents(event_type);
5422 return err;
5423#endif // INCLUDE_JVMTI
5424}
5425
5426 //
5427 // Extension Mechanism functions
5428 //
5429
5430static jvmtiError JNICALL
5431jvmti_GetExtensionFunctions(jvmtiEnv* env,
5432 jint* extension_count_ptr,
5433 jvmtiExtensionFunctionInfo** extensions) {
5434
5435#if !INCLUDE_JVMTI
5436 return JVMTI_ERROR_NOT_AVAILABLE;
5437#else
5438 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
5439 return JVMTI_ERROR_WRONG_PHASE;
5440 }
5441 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5442 if (!jvmti_env->is_valid()) {
5443 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5444 }
5445 jvmtiError err;
5446 if (Threads::number_of_threads() != 0) {
5447 Thread* this_thread = Thread::current_or_null();
5448 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5449 return JVMTI_ERROR_UNATTACHED_THREAD;
5450 }
5451 JavaThread* current_thread = (JavaThread*)this_thread;
5452 ThreadInVMfromNative __tiv(current_thread);
5453 VM_ENTRY_BASE(jvmtiError, jvmti_GetExtensionFunctions , current_thread)
5454 debug_only(VMNativeEntryWrapper __vew;)
5455 CautiouslyPreserveExceptionMark __em(this_thread);
5456 if (extension_count_ptr == NULL) {
5457 return JVMTI_ERROR_NULL_POINTER;
5458 }
5459 if (extensions == NULL) {
5460 return JVMTI_ERROR_NULL_POINTER;
5461 }
5462 err = jvmti_env->GetExtensionFunctions(extension_count_ptr, extensions);
5463 } else {
5464 if (extension_count_ptr == NULL) {
5465 return JVMTI_ERROR_NULL_POINTER;
5466 }
5467 if (extensions == NULL) {
5468 return JVMTI_ERROR_NULL_POINTER;
5469 }
5470 err = jvmti_env->GetExtensionFunctions(extension_count_ptr, extensions);
5471 }
5472 return err;
5473#endif // INCLUDE_JVMTI
5474}
5475
5476static jvmtiError JNICALL
5477jvmti_GetExtensionEvents(jvmtiEnv* env,
5478 jint* extension_count_ptr,
5479 jvmtiExtensionEventInfo** extensions) {
5480
5481#if !INCLUDE_JVMTI
5482 return JVMTI_ERROR_NOT_AVAILABLE;
5483#else
5484 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
5485 return JVMTI_ERROR_WRONG_PHASE;
5486 }
5487 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5488 if (!jvmti_env->is_valid()) {
5489 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5490 }
5491 jvmtiError err;
5492 if (Threads::number_of_threads() != 0) {
5493 Thread* this_thread = Thread::current_or_null();
5494 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5495 return JVMTI_ERROR_UNATTACHED_THREAD;
5496 }
5497 JavaThread* current_thread = (JavaThread*)this_thread;
5498 ThreadInVMfromNative __tiv(current_thread);
5499 VM_ENTRY_BASE(jvmtiError, jvmti_GetExtensionEvents , current_thread)
5500 debug_only(VMNativeEntryWrapper __vew;)
5501 CautiouslyPreserveExceptionMark __em(this_thread);
5502 if (extension_count_ptr == NULL) {
5503 return JVMTI_ERROR_NULL_POINTER;
5504 }
5505 if (extensions == NULL) {
5506 return JVMTI_ERROR_NULL_POINTER;
5507 }
5508 err = jvmti_env->GetExtensionEvents(extension_count_ptr, extensions);
5509 } else {
5510 if (extension_count_ptr == NULL) {
5511 return JVMTI_ERROR_NULL_POINTER;
5512 }
5513 if (extensions == NULL) {
5514 return JVMTI_ERROR_NULL_POINTER;
5515 }
5516 err = jvmti_env->GetExtensionEvents(extension_count_ptr, extensions);
5517 }
5518 return err;
5519#endif // INCLUDE_JVMTI
5520}
5521
5522static jvmtiError JNICALL
5523jvmti_SetExtensionEventCallback(jvmtiEnv* env,
5524 jint extension_event_index,
5525 jvmtiExtensionEvent callback) {
5526
5527#if !INCLUDE_JVMTI
5528 return JVMTI_ERROR_NOT_AVAILABLE;
5529#else
5530 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
5531 return JVMTI_ERROR_WRONG_PHASE;
5532 }
5533 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5534 if (!jvmti_env->is_valid()) {
5535 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5536 }
5537 jvmtiError err;
5538 if (Threads::number_of_threads() != 0) {
5539 Thread* this_thread = Thread::current_or_null();
5540 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5541 return JVMTI_ERROR_UNATTACHED_THREAD;
5542 }
5543 JavaThread* current_thread = (JavaThread*)this_thread;
5544 ThreadInVMfromNative __tiv(current_thread);
5545 VM_ENTRY_BASE(jvmtiError, jvmti_SetExtensionEventCallback , current_thread)
5546 debug_only(VMNativeEntryWrapper __vew;)
5547 CautiouslyPreserveExceptionMark __em(this_thread);
5548 err = jvmti_env->SetExtensionEventCallback(extension_event_index, callback);
5549 } else {
5550 err = jvmti_env->SetExtensionEventCallback(extension_event_index, callback);
5551 }
5552 return err;
5553#endif // INCLUDE_JVMTI
5554}
5555
5556 //
5557 // Capability functions
5558 //
5559
5560static jvmtiError JNICALL
5561jvmti_GetPotentialCapabilities(jvmtiEnv* env,
5562 jvmtiCapabilities* capabilities_ptr) {
5563 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
5564 return JVMTI_ERROR_WRONG_PHASE;
5565 }
5566 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5567 if (!jvmti_env->is_valid()) {
5568 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5569 }
5570 jvmtiError err;
5571 if (Threads::number_of_threads() != 0) {
5572 Thread* this_thread = Thread::current_or_null();
5573 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5574 return JVMTI_ERROR_UNATTACHED_THREAD;
5575 }
5576 JavaThread* current_thread = (JavaThread*)this_thread;
5577 ThreadInVMfromNative __tiv(current_thread);
5578 VM_ENTRY_BASE(jvmtiError, jvmti_GetPotentialCapabilities , current_thread)
5579 debug_only(VMNativeEntryWrapper __vew;)
5580 CautiouslyPreserveExceptionMark __em(this_thread);
5581 if (capabilities_ptr == NULL) {
5582 return JVMTI_ERROR_NULL_POINTER;
5583 }
5584 err = jvmti_env->GetPotentialCapabilities(capabilities_ptr);
5585 } else {
5586 if (capabilities_ptr == NULL) {
5587 return JVMTI_ERROR_NULL_POINTER;
5588 }
5589 err = jvmti_env->GetPotentialCapabilities(capabilities_ptr);
5590 }
5591 return err;
5592}
5593
5594static jvmtiError JNICALL
5595jvmti_AddCapabilities(jvmtiEnv* env,
5596 const jvmtiCapabilities* capabilities_ptr) {
5597 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
5598 return JVMTI_ERROR_WRONG_PHASE;
5599 }
5600 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5601 if (!jvmti_env->is_valid()) {
5602 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5603 }
5604 jvmtiError err;
5605 if (Threads::number_of_threads() != 0) {
5606 Thread* this_thread = Thread::current_or_null();
5607 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5608 return JVMTI_ERROR_UNATTACHED_THREAD;
5609 }
5610 JavaThread* current_thread = (JavaThread*)this_thread;
5611 ThreadInVMfromNative __tiv(current_thread);
5612 VM_ENTRY_BASE(jvmtiError, jvmti_AddCapabilities , current_thread)
5613 debug_only(VMNativeEntryWrapper __vew;)
5614 CautiouslyPreserveExceptionMark __em(this_thread);
5615 if (capabilities_ptr == NULL) {
5616 return JVMTI_ERROR_NULL_POINTER;
5617 }
5618 err = jvmti_env->AddCapabilities(capabilities_ptr);
5619 } else {
5620 if (capabilities_ptr == NULL) {
5621 return JVMTI_ERROR_NULL_POINTER;
5622 }
5623 err = jvmti_env->AddCapabilities(capabilities_ptr);
5624 }
5625 return err;
5626}
5627
5628static jvmtiError JNICALL
5629jvmti_RelinquishCapabilities(jvmtiEnv* env,
5630 const jvmtiCapabilities* capabilities_ptr) {
5631
5632#if !INCLUDE_JVMTI
5633 return JVMTI_ERROR_NOT_AVAILABLE;
5634#else
5635 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
5636 return JVMTI_ERROR_WRONG_PHASE;
5637 }
5638 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5639 if (!jvmti_env->is_valid()) {
5640 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5641 }
5642 jvmtiError err;
5643 if (Threads::number_of_threads() != 0) {
5644 Thread* this_thread = Thread::current_or_null();
5645 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5646 return JVMTI_ERROR_UNATTACHED_THREAD;
5647 }
5648 JavaThread* current_thread = (JavaThread*)this_thread;
5649 ThreadInVMfromNative __tiv(current_thread);
5650 VM_ENTRY_BASE(jvmtiError, jvmti_RelinquishCapabilities , current_thread)
5651 debug_only(VMNativeEntryWrapper __vew;)
5652 CautiouslyPreserveExceptionMark __em(this_thread);
5653 if (capabilities_ptr == NULL) {
5654 return JVMTI_ERROR_NULL_POINTER;
5655 }
5656 err = jvmti_env->RelinquishCapabilities(capabilities_ptr);
5657 } else {
5658 if (capabilities_ptr == NULL) {
5659 return JVMTI_ERROR_NULL_POINTER;
5660 }
5661 err = jvmti_env->RelinquishCapabilities(capabilities_ptr);
5662 }
5663 return err;
5664#endif // INCLUDE_JVMTI
5665}
5666
5667static jvmtiError JNICALL
5668jvmti_GetCapabilities(jvmtiEnv* env,
5669 jvmtiCapabilities* capabilities_ptr) {
5670
5671 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5672 if (!jvmti_env->is_valid()) {
5673 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5674 }
5675 jvmtiError err;
5676 if (Threads::number_of_threads() != 0) {
5677 Thread* this_thread = Thread::current_or_null();
5678 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5679 return JVMTI_ERROR_UNATTACHED_THREAD;
5680 }
5681 JavaThread* current_thread = (JavaThread*)this_thread;
5682 ThreadInVMfromNative __tiv(current_thread);
5683 VM_ENTRY_BASE(jvmtiError, jvmti_GetCapabilities , current_thread)
5684 debug_only(VMNativeEntryWrapper __vew;)
5685 CautiouslyPreserveExceptionMark __em(this_thread);
5686 if (capabilities_ptr == NULL) {
5687 return JVMTI_ERROR_NULL_POINTER;
5688 }
5689 err = jvmti_env->GetCapabilities(capabilities_ptr);
5690 } else {
5691 if (capabilities_ptr == NULL) {
5692 return JVMTI_ERROR_NULL_POINTER;
5693 }
5694 err = jvmti_env->GetCapabilities(capabilities_ptr);
5695 }
5696 return err;
5697}
5698
5699 //
5700 // Timers functions
5701 //
5702
5703static jvmtiError JNICALL
5704jvmti_GetCurrentThreadCpuTimerInfo(jvmtiEnv* env,
5705 jvmtiTimerInfo* info_ptr) {
5706
5707#if !INCLUDE_JVMTI
5708 return JVMTI_ERROR_NOT_AVAILABLE;
5709#else
5710 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
5711 return JVMTI_ERROR_WRONG_PHASE;
5712 }
5713 Thread* this_thread = Thread::current_or_null();
5714 if (this_thread == NULL || (!this_thread->is_Java_thread() && !this_thread->is_Named_thread())) {
5715 return JVMTI_ERROR_UNATTACHED_THREAD;
5716 }
5717
5718 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5719 if (!jvmti_env->is_valid()) {
5720 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5721 }
5722
5723 if (jvmti_env->get_capabilities()->can_get_current_thread_cpu_time == 0) {
5724 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
5725 }
5726 jvmtiError err;
5727 if (info_ptr == NULL) {
5728 return JVMTI_ERROR_NULL_POINTER;
5729 }
5730 err = jvmti_env->GetCurrentThreadCpuTimerInfo(info_ptr);
5731 return err;
5732#endif // INCLUDE_JVMTI
5733}
5734
5735static jvmtiError JNICALL
5736jvmti_GetCurrentThreadCpuTime(jvmtiEnv* env,
5737 jlong* nanos_ptr) {
5738
5739#if !INCLUDE_JVMTI
5740 return JVMTI_ERROR_NOT_AVAILABLE;
5741#else
5742 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
5743 return JVMTI_ERROR_WRONG_PHASE;
5744 }
5745 Thread* this_thread = Thread::current_or_null();
5746 if (this_thread == NULL || (!this_thread->is_Java_thread() && !this_thread->is_Named_thread())) {
5747 return JVMTI_ERROR_UNATTACHED_THREAD;
5748 }
5749
5750 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5751 if (!jvmti_env->is_valid()) {
5752 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5753 }
5754
5755 if (jvmti_env->get_capabilities()->can_get_current_thread_cpu_time == 0) {
5756 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
5757 }
5758 jvmtiError err;
5759 if (nanos_ptr == NULL) {
5760 return JVMTI_ERROR_NULL_POINTER;
5761 }
5762 err = jvmti_env->GetCurrentThreadCpuTime(nanos_ptr);
5763 return err;
5764#endif // INCLUDE_JVMTI
5765}
5766
5767static jvmtiError JNICALL
5768jvmti_GetThreadCpuTimerInfo(jvmtiEnv* env,
5769 jvmtiTimerInfo* info_ptr) {
5770
5771#if !INCLUDE_JVMTI
5772 return JVMTI_ERROR_NOT_AVAILABLE;
5773#else
5774 if(!JvmtiEnv::is_vm_live()) {
5775 return JVMTI_ERROR_WRONG_PHASE;
5776 }
5777 Thread* this_thread = Thread::current_or_null();
5778 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5779 return JVMTI_ERROR_UNATTACHED_THREAD;
5780 }
5781 JavaThread* current_thread = (JavaThread*)this_thread;
5782 ThreadInVMfromNative __tiv(current_thread);
5783 VM_ENTRY_BASE(jvmtiError, jvmti_GetThreadCpuTimerInfo , current_thread)
5784 debug_only(VMNativeEntryWrapper __vew;)
5785 CautiouslyPreserveExceptionMark __em(this_thread);
5786 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5787 if (!jvmti_env->is_valid()) {
5788 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5789 }
5790
5791 if (jvmti_env->get_capabilities()->can_get_thread_cpu_time == 0) {
5792 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
5793 }
5794 jvmtiError err;
5795 if (info_ptr == NULL) {
5796 return JVMTI_ERROR_NULL_POINTER;
5797 }
5798 err = jvmti_env->GetThreadCpuTimerInfo(info_ptr);
5799 return err;
5800#endif // INCLUDE_JVMTI
5801}
5802
5803static jvmtiError JNICALL
5804jvmti_GetThreadCpuTime(jvmtiEnv* env,
5805 jthread thread,
5806 jlong* nanos_ptr) {
5807
5808#if !INCLUDE_JVMTI
5809 return JVMTI_ERROR_NOT_AVAILABLE;
5810#else
5811 if(!JvmtiEnv::is_vm_live()) {
5812 return JVMTI_ERROR_WRONG_PHASE;
5813 }
5814 Thread* this_thread = Thread::current_or_null();
5815 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5816 return JVMTI_ERROR_UNATTACHED_THREAD;
5817 }
5818 JavaThread* current_thread = (JavaThread*)this_thread;
5819 ThreadInVMfromNative __tiv(current_thread);
5820 VM_ENTRY_BASE(jvmtiError, jvmti_GetThreadCpuTime , current_thread)
5821 debug_only(VMNativeEntryWrapper __vew;)
5822 CautiouslyPreserveExceptionMark __em(this_thread);
5823 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5824 if (!jvmti_env->is_valid()) {
5825 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5826 }
5827
5828 if (jvmti_env->get_capabilities()->can_get_thread_cpu_time == 0) {
5829 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
5830 }
5831 jvmtiError err;
5832 JavaThread* java_thread = NULL;
5833 ThreadsListHandle tlh(this_thread);
5834 if (thread == NULL) {
5835 java_thread = current_thread;
5836 } else {
5837 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
5838 if (err != JVMTI_ERROR_NONE) {
5839 return err;
5840 }
5841 }
5842 if (nanos_ptr == NULL) {
5843 return JVMTI_ERROR_NULL_POINTER;
5844 }
5845 err = jvmti_env->GetThreadCpuTime(java_thread, nanos_ptr);
5846 return err;
5847#endif // INCLUDE_JVMTI
5848}
5849
5850static jvmtiError JNICALL
5851jvmti_GetTimerInfo(jvmtiEnv* env,
5852 jvmtiTimerInfo* info_ptr) {
5853
5854#if !INCLUDE_JVMTI
5855 return JVMTI_ERROR_NOT_AVAILABLE;
5856#else
5857
5858 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5859 if (!jvmti_env->is_valid()) {
5860 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5861 }
5862 jvmtiError err;
5863 Thread* this_thread = NULL;
5864 bool transition;
5865 if (Threads::number_of_threads() == 0) {
5866 transition = false;
5867 } else {
5868 this_thread = Thread::current_or_null();
5869 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
5870 }
5871 if (transition) {
5872 if (!this_thread->is_Java_thread()) {
5873 return JVMTI_ERROR_UNATTACHED_THREAD;
5874 }
5875 JavaThread* current_thread = (JavaThread*)this_thread;
5876 ThreadInVMfromNative __tiv(current_thread);
5877 VM_ENTRY_BASE(jvmtiError, jvmti_GetTimerInfo , current_thread)
5878 debug_only(VMNativeEntryWrapper __vew;)
5879 if (info_ptr == NULL) {
5880 return JVMTI_ERROR_NULL_POINTER;
5881 }
5882 err = jvmti_env->GetTimerInfo(info_ptr);
5883 } else {
5884 if (info_ptr == NULL) {
5885 return JVMTI_ERROR_NULL_POINTER;
5886 }
5887 err = jvmti_env->GetTimerInfo(info_ptr);
5888 }
5889 return err;
5890#endif // INCLUDE_JVMTI
5891}
5892
5893static jvmtiError JNICALL
5894jvmti_GetTime(jvmtiEnv* env,
5895 jlong* nanos_ptr) {
5896
5897#if !INCLUDE_JVMTI
5898 return JVMTI_ERROR_NOT_AVAILABLE;
5899#else
5900
5901 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5902 if (!jvmti_env->is_valid()) {
5903 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5904 }
5905 jvmtiError err;
5906 Thread* this_thread = NULL;
5907 bool transition;
5908 if (Threads::number_of_threads() == 0) {
5909 transition = false;
5910 } else {
5911 this_thread = Thread::current_or_null();
5912 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
5913 }
5914 if (transition) {
5915 if (!this_thread->is_Java_thread()) {
5916 return JVMTI_ERROR_UNATTACHED_THREAD;
5917 }
5918 JavaThread* current_thread = (JavaThread*)this_thread;
5919 ThreadInVMfromNative __tiv(current_thread);
5920 VM_ENTRY_BASE(jvmtiError, jvmti_GetTime , current_thread)
5921 debug_only(VMNativeEntryWrapper __vew;)
5922 if (nanos_ptr == NULL) {
5923 return JVMTI_ERROR_NULL_POINTER;
5924 }
5925 err = jvmti_env->GetTime(nanos_ptr);
5926 } else {
5927 if (nanos_ptr == NULL) {
5928 return JVMTI_ERROR_NULL_POINTER;
5929 }
5930 err = jvmti_env->GetTime(nanos_ptr);
5931 }
5932 return err;
5933#endif // INCLUDE_JVMTI
5934}
5935
5936static jvmtiError JNICALL
5937jvmti_GetAvailableProcessors(jvmtiEnv* env,
5938 jint* processor_count_ptr) {
5939
5940#if !INCLUDE_JVMTI
5941 return JVMTI_ERROR_NOT_AVAILABLE;
5942#else
5943
5944 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5945 if (!jvmti_env->is_valid()) {
5946 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5947 }
5948 jvmtiError err;
5949 if (Threads::number_of_threads() != 0) {
5950 Thread* this_thread = Thread::current_or_null();
5951 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5952 return JVMTI_ERROR_UNATTACHED_THREAD;
5953 }
5954 JavaThread* current_thread = (JavaThread*)this_thread;
5955 ThreadInVMfromNative __tiv(current_thread);
5956 VM_ENTRY_BASE(jvmtiError, jvmti_GetAvailableProcessors , current_thread)
5957 debug_only(VMNativeEntryWrapper __vew;)
5958 CautiouslyPreserveExceptionMark __em(this_thread);
5959 if (processor_count_ptr == NULL) {
5960 return JVMTI_ERROR_NULL_POINTER;
5961 }
5962 err = jvmti_env->GetAvailableProcessors(processor_count_ptr);
5963 } else {
5964 if (processor_count_ptr == NULL) {
5965 return JVMTI_ERROR_NULL_POINTER;
5966 }
5967 err = jvmti_env->GetAvailableProcessors(processor_count_ptr);
5968 }
5969 return err;
5970#endif // INCLUDE_JVMTI
5971}
5972
5973 //
5974 // Class Loader Search functions
5975 //
5976
5977static jvmtiError JNICALL
5978jvmti_AddToBootstrapClassLoaderSearch(jvmtiEnv* env,
5979 const char* segment) {
5980 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
5981 return JVMTI_ERROR_WRONG_PHASE;
5982 }
5983 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5984 if (!jvmti_env->is_valid()) {
5985 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5986 }
5987 jvmtiError err;
5988 if (Threads::number_of_threads() != 0) {
5989 Thread* this_thread = Thread::current_or_null();
5990 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5991 return JVMTI_ERROR_UNATTACHED_THREAD;
5992 }
5993 JavaThread* current_thread = (JavaThread*)this_thread;
5994 ThreadInVMfromNative __tiv(current_thread);
5995 VM_ENTRY_BASE(jvmtiError, jvmti_AddToBootstrapClassLoaderSearch , current_thread)
5996 debug_only(VMNativeEntryWrapper __vew;)
5997 CautiouslyPreserveExceptionMark __em(this_thread);
5998 if (segment == NULL) {
5999 return JVMTI_ERROR_NULL_POINTER;
6000 }
6001 err = jvmti_env->AddToBootstrapClassLoaderSearch(segment);
6002 } else {
6003 if (segment == NULL) {
6004 return JVMTI_ERROR_NULL_POINTER;
6005 }
6006 err = jvmti_env->AddToBootstrapClassLoaderSearch(segment);
6007 }
6008 return err;
6009}
6010
6011static jvmtiError JNICALL
6012jvmti_AddToSystemClassLoaderSearch(jvmtiEnv* env,
6013 const char* segment) {
6014 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
6015 return JVMTI_ERROR_WRONG_PHASE;
6016 }
6017 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6018 if (!jvmti_env->is_valid()) {
6019 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6020 }
6021 jvmtiError err;
6022 if (Threads::number_of_threads() != 0) {
6023 Thread* this_thread = Thread::current_or_null();
6024 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6025 return JVMTI_ERROR_UNATTACHED_THREAD;
6026 }
6027 JavaThread* current_thread = (JavaThread*)this_thread;
6028 ThreadInVMfromNative __tiv(current_thread);
6029 VM_ENTRY_BASE(jvmtiError, jvmti_AddToSystemClassLoaderSearch , current_thread)
6030 debug_only(VMNativeEntryWrapper __vew;)
6031 CautiouslyPreserveExceptionMark __em(this_thread);
6032 if (segment == NULL) {
6033 return JVMTI_ERROR_NULL_POINTER;
6034 }
6035 err = jvmti_env->AddToSystemClassLoaderSearch(segment);
6036 } else {
6037 if (segment == NULL) {
6038 return JVMTI_ERROR_NULL_POINTER;
6039 }
6040 err = jvmti_env->AddToSystemClassLoaderSearch(segment);
6041 }
6042 return err;
6043}
6044
6045 //
6046 // System Properties functions
6047 //
6048
6049static jvmtiError JNICALL
6050jvmti_GetSystemProperties(jvmtiEnv* env,
6051 jint* count_ptr,
6052 char*** property_ptr) {
6053
6054#if !INCLUDE_JVMTI
6055 return JVMTI_ERROR_NOT_AVAILABLE;
6056#else
6057 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
6058 return JVMTI_ERROR_WRONG_PHASE;
6059 }
6060 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6061 if (!jvmti_env->is_valid()) {
6062 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6063 }
6064 jvmtiError err;
6065 if (Threads::number_of_threads() != 0) {
6066 Thread* this_thread = Thread::current_or_null();
6067 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6068 return JVMTI_ERROR_UNATTACHED_THREAD;
6069 }
6070 JavaThread* current_thread = (JavaThread*)this_thread;
6071 ThreadInVMfromNative __tiv(current_thread);
6072 VM_ENTRY_BASE(jvmtiError, jvmti_GetSystemProperties , current_thread)
6073 debug_only(VMNativeEntryWrapper __vew;)
6074 CautiouslyPreserveExceptionMark __em(this_thread);
6075 if (count_ptr == NULL) {
6076 return JVMTI_ERROR_NULL_POINTER;
6077 }
6078 if (property_ptr == NULL) {
6079 return JVMTI_ERROR_NULL_POINTER;
6080 }
6081 err = jvmti_env->GetSystemProperties(count_ptr, property_ptr);
6082 } else {
6083 if (count_ptr == NULL) {
6084 return JVMTI_ERROR_NULL_POINTER;
6085 }
6086 if (property_ptr == NULL) {
6087 return JVMTI_ERROR_NULL_POINTER;
6088 }
6089 err = jvmti_env->GetSystemProperties(count_ptr, property_ptr);
6090 }
6091 return err;
6092#endif // INCLUDE_JVMTI
6093}
6094
6095static jvmtiError JNICALL
6096jvmti_GetSystemProperty(jvmtiEnv* env,
6097 const char* property,
6098 char** value_ptr) {
6099
6100#if !INCLUDE_JVMTI
6101 return JVMTI_ERROR_NOT_AVAILABLE;
6102#else
6103 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
6104 return JVMTI_ERROR_WRONG_PHASE;
6105 }
6106 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6107 if (!jvmti_env->is_valid()) {
6108 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6109 }
6110 jvmtiError err;
6111 if (Threads::number_of_threads() != 0) {
6112 Thread* this_thread = Thread::current_or_null();
6113 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6114 return JVMTI_ERROR_UNATTACHED_THREAD;
6115 }
6116 JavaThread* current_thread = (JavaThread*)this_thread;
6117 ThreadInVMfromNative __tiv(current_thread);
6118 VM_ENTRY_BASE(jvmtiError, jvmti_GetSystemProperty , current_thread)
6119 debug_only(VMNativeEntryWrapper __vew;)
6120 CautiouslyPreserveExceptionMark __em(this_thread);
6121 if (property == NULL) {
6122 return JVMTI_ERROR_NULL_POINTER;
6123 }
6124 if (value_ptr == NULL) {
6125 return JVMTI_ERROR_NULL_POINTER;
6126 }
6127 err = jvmti_env->GetSystemProperty(property, value_ptr);
6128 } else {
6129 if (property == NULL) {
6130 return JVMTI_ERROR_NULL_POINTER;
6131 }
6132 if (value_ptr == NULL) {
6133 return JVMTI_ERROR_NULL_POINTER;
6134 }
6135 err = jvmti_env->GetSystemProperty(property, value_ptr);
6136 }
6137 return err;
6138#endif // INCLUDE_JVMTI
6139}
6140
6141static jvmtiError JNICALL
6142jvmti_SetSystemProperty(jvmtiEnv* env,
6143 const char* property,
6144 const char* value_ptr) {
6145
6146#if !INCLUDE_JVMTI
6147 return JVMTI_ERROR_NOT_AVAILABLE;
6148#else
6149 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD) {
6150 return JVMTI_ERROR_WRONG_PHASE;
6151 }
6152 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6153 if (!jvmti_env->is_valid()) {
6154 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6155 }
6156 jvmtiError err;
6157 if (Threads::number_of_threads() != 0) {
6158 Thread* this_thread = Thread::current_or_null();
6159 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6160 return JVMTI_ERROR_UNATTACHED_THREAD;
6161 }
6162 JavaThread* current_thread = (JavaThread*)this_thread;
6163 ThreadInVMfromNative __tiv(current_thread);
6164 VM_ENTRY_BASE(jvmtiError, jvmti_SetSystemProperty , current_thread)
6165 debug_only(VMNativeEntryWrapper __vew;)
6166 CautiouslyPreserveExceptionMark __em(this_thread);
6167 if (property == NULL) {
6168 return JVMTI_ERROR_NULL_POINTER;
6169 }
6170 err = jvmti_env->SetSystemProperty(property, value_ptr);
6171 } else {
6172 if (property == NULL) {
6173 return JVMTI_ERROR_NULL_POINTER;
6174 }
6175 err = jvmti_env->SetSystemProperty(property, value_ptr);
6176 }
6177 return err;
6178#endif // INCLUDE_JVMTI
6179}
6180
6181 //
6182 // General functions
6183 //
6184
6185static jvmtiError JNICALL
6186jvmti_GetPhase(jvmtiEnv* env,
6187 jvmtiPhase* phase_ptr) {
6188
6189 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6190 if (!jvmti_env->is_valid()) {
6191 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6192 }
6193 jvmtiError err;
6194 if (Threads::number_of_threads() != 0) {
6195 Thread* this_thread = Thread::current_or_null();
6196 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6197 return JVMTI_ERROR_UNATTACHED_THREAD;
6198 }
6199 JavaThread* current_thread = (JavaThread*)this_thread;
6200 ThreadInVMfromNative __tiv(current_thread);
6201 VM_ENTRY_BASE(jvmtiError, jvmti_GetPhase , current_thread)
6202 debug_only(VMNativeEntryWrapper __vew;)
6203 CautiouslyPreserveExceptionMark __em(this_thread);
6204 if (phase_ptr == NULL) {
6205 return JVMTI_ERROR_NULL_POINTER;
6206 }
6207 err = jvmti_env->GetPhase(phase_ptr);
6208 } else {
6209 if (phase_ptr == NULL) {
6210 return JVMTI_ERROR_NULL_POINTER;
6211 }
6212 err = jvmti_env->GetPhase(phase_ptr);
6213 }
6214 return err;
6215}
6216
6217static jvmtiError JNICALL
6218jvmti_DisposeEnvironment(jvmtiEnv* env) {
6219
6220 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6221 if (!jvmti_env->is_valid()) {
6222 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6223 }
6224 jvmtiError err;
6225 if (Threads::number_of_threads() != 0) {
6226 Thread* this_thread = Thread::current_or_null();
6227 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6228 return JVMTI_ERROR_UNATTACHED_THREAD;
6229 }
6230 JavaThread* current_thread = (JavaThread*)this_thread;
6231 ThreadInVMfromNative __tiv(current_thread);
6232 VM_ENTRY_BASE(jvmtiError, jvmti_DisposeEnvironment , current_thread)
6233 debug_only(VMNativeEntryWrapper __vew;)
6234 CautiouslyPreserveExceptionMark __em(this_thread);
6235 err = jvmti_env->DisposeEnvironment();
6236 } else {
6237 err = jvmti_env->DisposeEnvironment();
6238 }
6239 return err;
6240}
6241
6242static jvmtiError JNICALL
6243jvmti_SetEnvironmentLocalStorage(jvmtiEnv* env,
6244 const void* data) {
6245
6246 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6247 if (!jvmti_env->is_valid()) {
6248 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6249 }
6250 jvmtiError err;
6251 Thread* this_thread = NULL;
6252 bool transition;
6253 if (Threads::number_of_threads() == 0) {
6254 transition = false;
6255 } else {
6256 this_thread = Thread::current_or_null();
6257 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
6258 }
6259 if (transition) {
6260 if (!this_thread->is_Java_thread()) {
6261 return JVMTI_ERROR_UNATTACHED_THREAD;
6262 }
6263
6264 err = jvmti_env->SetEnvironmentLocalStorage(data);
6265 } else {
6266 err = jvmti_env->SetEnvironmentLocalStorage(data);
6267 }
6268 return err;
6269}
6270
6271static jvmtiError JNICALL
6272jvmti_GetEnvironmentLocalStorage(jvmtiEnv* env,
6273 void** data_ptr) {
6274
6275 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6276 if (!jvmti_env->is_valid()) {
6277 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6278 }
6279 jvmtiError err;
6280 Thread* this_thread = NULL;
6281 bool transition;
6282 if (Threads::number_of_threads() == 0) {
6283 transition = false;
6284 } else {
6285 this_thread = Thread::current_or_null();
6286 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
6287 }
6288 if (transition) {
6289 if (!this_thread->is_Java_thread()) {
6290 return JVMTI_ERROR_UNATTACHED_THREAD;
6291 }
6292
6293 if (data_ptr == NULL) {
6294 return JVMTI_ERROR_NULL_POINTER;
6295 }
6296 err = jvmti_env->GetEnvironmentLocalStorage(data_ptr);
6297 } else {
6298 if (data_ptr == NULL) {
6299 return JVMTI_ERROR_NULL_POINTER;
6300 }
6301 err = jvmti_env->GetEnvironmentLocalStorage(data_ptr);
6302 }
6303 return err;
6304}
6305
6306static jvmtiError JNICALL
6307jvmti_GetVersionNumber(jvmtiEnv* env,
6308 jint* version_ptr) {
6309
6310 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6311 if (!jvmti_env->is_valid()) {
6312 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6313 }
6314 jvmtiError err;
6315 if (Threads::number_of_threads() != 0) {
6316 Thread* this_thread = Thread::current_or_null();
6317 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6318 return JVMTI_ERROR_UNATTACHED_THREAD;
6319 }
6320 JavaThread* current_thread = (JavaThread*)this_thread;
6321 ThreadInVMfromNative __tiv(current_thread);
6322 VM_ENTRY_BASE(jvmtiError, jvmti_GetVersionNumber , current_thread)
6323 debug_only(VMNativeEntryWrapper __vew;)
6324 CautiouslyPreserveExceptionMark __em(this_thread);
6325 if (version_ptr == NULL) {
6326 return JVMTI_ERROR_NULL_POINTER;
6327 }
6328 err = jvmti_env->GetVersionNumber(version_ptr);
6329 } else {
6330 if (version_ptr == NULL) {
6331 return JVMTI_ERROR_NULL_POINTER;
6332 }
6333 err = jvmti_env->GetVersionNumber(version_ptr);
6334 }
6335 return err;
6336}
6337
6338static jvmtiError JNICALL
6339jvmti_GetErrorName(jvmtiEnv* env,
6340 jvmtiError error,
6341 char** name_ptr) {
6342
6343#if !INCLUDE_JVMTI
6344 return JVMTI_ERROR_NOT_AVAILABLE;
6345#else
6346
6347 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6348 if (!jvmti_env->is_valid()) {
6349 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6350 }
6351 jvmtiError err;
6352 if (Threads::number_of_threads() != 0) {
6353 Thread* this_thread = Thread::current_or_null();
6354 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6355 return JVMTI_ERROR_UNATTACHED_THREAD;
6356 }
6357 JavaThread* current_thread = (JavaThread*)this_thread;
6358 ThreadInVMfromNative __tiv(current_thread);
6359 VM_ENTRY_BASE(jvmtiError, jvmti_GetErrorName , current_thread)
6360 debug_only(VMNativeEntryWrapper __vew;)
6361 CautiouslyPreserveExceptionMark __em(this_thread);
6362 if (name_ptr == NULL) {
6363 return JVMTI_ERROR_NULL_POINTER;
6364 }
6365 err = jvmti_env->GetErrorName(error, name_ptr);
6366 } else {
6367 if (name_ptr == NULL) {
6368 return JVMTI_ERROR_NULL_POINTER;
6369 }
6370 err = jvmti_env->GetErrorName(error, name_ptr);
6371 }
6372 return err;
6373#endif // INCLUDE_JVMTI
6374}
6375
6376static jvmtiError JNICALL
6377jvmti_SetVerboseFlag(jvmtiEnv* env,
6378 jvmtiVerboseFlag flag,
6379 jboolean value) {
6380
6381#if !INCLUDE_JVMTI
6382 return JVMTI_ERROR_NOT_AVAILABLE;
6383#else
6384
6385 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6386 if (!jvmti_env->is_valid()) {
6387 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6388 }
6389 jvmtiError err;
6390 if (Threads::number_of_threads() != 0) {
6391 Thread* this_thread = Thread::current_or_null();
6392 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6393 return JVMTI_ERROR_UNATTACHED_THREAD;
6394 }
6395 JavaThread* current_thread = (JavaThread*)this_thread;
6396 ThreadInVMfromNative __tiv(current_thread);
6397 VM_ENTRY_BASE(jvmtiError, jvmti_SetVerboseFlag , current_thread)
6398 debug_only(VMNativeEntryWrapper __vew;)
6399 CautiouslyPreserveExceptionMark __em(this_thread);
6400 err = jvmti_env->SetVerboseFlag(flag, value);
6401 } else {
6402 err = jvmti_env->SetVerboseFlag(flag, value);
6403 }
6404 return err;
6405#endif // INCLUDE_JVMTI
6406}
6407
6408static jvmtiError JNICALL
6409jvmti_GetJLocationFormat(jvmtiEnv* env,
6410 jvmtiJlocationFormat* format_ptr) {
6411
6412#if !INCLUDE_JVMTI
6413 return JVMTI_ERROR_NOT_AVAILABLE;
6414#else
6415
6416 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6417 if (!jvmti_env->is_valid()) {
6418 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6419 }
6420 jvmtiError err;
6421 if (Threads::number_of_threads() != 0) {
6422 Thread* this_thread = Thread::current_or_null();
6423 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6424 return JVMTI_ERROR_UNATTACHED_THREAD;
6425 }
6426 JavaThread* current_thread = (JavaThread*)this_thread;
6427 ThreadInVMfromNative __tiv(current_thread);
6428 VM_ENTRY_BASE(jvmtiError, jvmti_GetJLocationFormat , current_thread)
6429 debug_only(VMNativeEntryWrapper __vew;)
6430 CautiouslyPreserveExceptionMark __em(this_thread);
6431 if (format_ptr == NULL) {
6432 return JVMTI_ERROR_NULL_POINTER;
6433 }
6434 err = jvmti_env->GetJLocationFormat(format_ptr);
6435 } else {
6436 if (format_ptr == NULL) {
6437 return JVMTI_ERROR_NULL_POINTER;
6438 }
6439 err = jvmti_env->GetJLocationFormat(format_ptr);
6440 }
6441 return err;
6442#endif // INCLUDE_JVMTI
6443}
6444
6445 //
6446 // Heap Monitoring functions
6447 //
6448
6449static jvmtiError JNICALL
6450jvmti_SetHeapSamplingInterval(jvmtiEnv* env,
6451 jint sampling_interval) {
6452
6453#if !INCLUDE_JVMTI
6454 return JVMTI_ERROR_NOT_AVAILABLE;
6455#else
6456 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
6457 return JVMTI_ERROR_WRONG_PHASE;
6458 }
6459 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6460 if (!jvmti_env->is_valid()) {
6461 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6462 }
6463
6464 if (jvmti_env->get_capabilities()->can_generate_sampled_object_alloc_events == 0) {
6465 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
6466 }
6467 jvmtiError err;
6468 if (Threads::number_of_threads() != 0) {
6469 Thread* this_thread = Thread::current_or_null();
6470 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6471 return JVMTI_ERROR_UNATTACHED_THREAD;
6472 }
6473 JavaThread* current_thread = (JavaThread*)this_thread;
6474 ThreadInVMfromNative __tiv(current_thread);
6475 VM_ENTRY_BASE(jvmtiError, jvmti_SetHeapSamplingInterval , current_thread)
6476 debug_only(VMNativeEntryWrapper __vew;)
6477 CautiouslyPreserveExceptionMark __em(this_thread);
6478 err = jvmti_env->SetHeapSamplingInterval(sampling_interval);
6479 } else {
6480 err = jvmti_env->SetHeapSamplingInterval(sampling_interval);
6481 }
6482 return err;
6483#endif // INCLUDE_JVMTI
6484}
6485
6486} /* end extern "C" */
6487
6488// JVMTI API functions
6489struct jvmtiInterface_1_ jvmti_Interface = {
6490 /* 1 : RESERVED */
6491 NULL,
6492 /* 2 : Set Event Notification Mode */
6493 jvmti_SetEventNotificationMode,
6494 /* 3 : Get All Modules */
6495 jvmti_GetAllModules,
6496 /* 4 : Get All Threads */
6497 jvmti_GetAllThreads,
6498 /* 5 : Suspend Thread */
6499 jvmti_SuspendThread,
6500 /* 6 : Resume Thread */
6501 jvmti_ResumeThread,
6502 /* 7 : Stop Thread */
6503 jvmti_StopThread,
6504 /* 8 : Interrupt Thread */
6505 jvmti_InterruptThread,
6506 /* 9 : Get Thread Info */
6507 jvmti_GetThreadInfo,
6508 /* 10 : Get Owned Monitor Info */
6509 jvmti_GetOwnedMonitorInfo,
6510 /* 11 : Get Current Contended Monitor */
6511 jvmti_GetCurrentContendedMonitor,
6512 /* 12 : Run Agent Thread */
6513 jvmti_RunAgentThread,
6514 /* 13 : Get Top Thread Groups */
6515 jvmti_GetTopThreadGroups,
6516 /* 14 : Get Thread Group Info */
6517 jvmti_GetThreadGroupInfo,
6518 /* 15 : Get Thread Group Children */
6519 jvmti_GetThreadGroupChildren,
6520 /* 16 : Get Frame Count */
6521 jvmti_GetFrameCount,
6522 /* 17 : Get Thread State */
6523 jvmti_GetThreadState,
6524 /* 18 : Get Current Thread */
6525 jvmti_GetCurrentThread,
6526 /* 19 : Get Frame Location */
6527 jvmti_GetFrameLocation,
6528 /* 20 : Notify Frame Pop */
6529 jvmti_NotifyFramePop,
6530 /* 21 : Get Local Variable - Object */
6531 jvmti_GetLocalObject,
6532 /* 22 : Get Local Variable - Int */
6533 jvmti_GetLocalInt,
6534 /* 23 : Get Local Variable - Long */
6535 jvmti_GetLocalLong,
6536 /* 24 : Get Local Variable - Float */
6537 jvmti_GetLocalFloat,
6538 /* 25 : Get Local Variable - Double */
6539 jvmti_GetLocalDouble,
6540 /* 26 : Set Local Variable - Object */
6541 jvmti_SetLocalObject,
6542 /* 27 : Set Local Variable - Int */
6543 jvmti_SetLocalInt,
6544 /* 28 : Set Local Variable - Long */
6545 jvmti_SetLocalLong,
6546 /* 29 : Set Local Variable - Float */
6547 jvmti_SetLocalFloat,
6548 /* 30 : Set Local Variable - Double */
6549 jvmti_SetLocalDouble,
6550 /* 31 : Create Raw Monitor */
6551 jvmti_CreateRawMonitor,
6552 /* 32 : Destroy Raw Monitor */
6553 jvmti_DestroyRawMonitor,
6554 /* 33 : Raw Monitor Enter */
6555 jvmti_RawMonitorEnter,
6556 /* 34 : Raw Monitor Exit */
6557 jvmti_RawMonitorExit,
6558 /* 35 : Raw Monitor Wait */
6559 jvmti_RawMonitorWait,
6560 /* 36 : Raw Monitor Notify */
6561 jvmti_RawMonitorNotify,
6562 /* 37 : Raw Monitor Notify All */
6563 jvmti_RawMonitorNotifyAll,
6564 /* 38 : Set Breakpoint */
6565 jvmti_SetBreakpoint,
6566 /* 39 : Clear Breakpoint */
6567 jvmti_ClearBreakpoint,
6568 /* 40 : Get Named Module */
6569 jvmti_GetNamedModule,
6570 /* 41 : Set Field Access Watch */
6571 jvmti_SetFieldAccessWatch,
6572 /* 42 : Clear Field Access Watch */
6573 jvmti_ClearFieldAccessWatch,
6574 /* 43 : Set Field Modification Watch */
6575 jvmti_SetFieldModificationWatch,
6576 /* 44 : Clear Field Modification Watch */
6577 jvmti_ClearFieldModificationWatch,
6578 /* 45 : Is Modifiable Class */
6579 jvmti_IsModifiableClass,
6580 /* 46 : Allocate */
6581 jvmti_Allocate,
6582 /* 47 : Deallocate */
6583 jvmti_Deallocate,
6584 /* 48 : Get Class Signature */
6585 jvmti_GetClassSignature,
6586 /* 49 : Get Class Status */
6587 jvmti_GetClassStatus,
6588 /* 50 : Get Source File Name */
6589 jvmti_GetSourceFileName,
6590 /* 51 : Get Class Modifiers */
6591 jvmti_GetClassModifiers,
6592 /* 52 : Get Class Methods */
6593 jvmti_GetClassMethods,
6594 /* 53 : Get Class Fields */
6595 jvmti_GetClassFields,
6596 /* 54 : Get Implemented Interfaces */
6597 jvmti_GetImplementedInterfaces,
6598 /* 55 : Is Interface */
6599 jvmti_IsInterface,
6600 /* 56 : Is Array Class */
6601 jvmti_IsArrayClass,
6602 /* 57 : Get Class Loader */
6603 jvmti_GetClassLoader,
6604 /* 58 : Get Object Hash Code */
6605 jvmti_GetObjectHashCode,
6606 /* 59 : Get Object Monitor Usage */
6607 jvmti_GetObjectMonitorUsage,
6608 /* 60 : Get Field Name (and Signature) */
6609 jvmti_GetFieldName,
6610 /* 61 : Get Field Declaring Class */
6611 jvmti_GetFieldDeclaringClass,
6612 /* 62 : Get Field Modifiers */
6613 jvmti_GetFieldModifiers,
6614 /* 63 : Is Field Synthetic */
6615 jvmti_IsFieldSynthetic,
6616 /* 64 : Get Method Name (and Signature) */
6617 jvmti_GetMethodName,
6618 /* 65 : Get Method Declaring Class */
6619 jvmti_GetMethodDeclaringClass,
6620 /* 66 : Get Method Modifiers */
6621 jvmti_GetMethodModifiers,
6622 /* 67 : RESERVED */
6623 NULL,
6624 /* 68 : Get Max Locals */
6625 jvmti_GetMaxLocals,
6626 /* 69 : Get Arguments Size */
6627 jvmti_GetArgumentsSize,
6628 /* 70 : Get Line Number Table */
6629 jvmti_GetLineNumberTable,
6630 /* 71 : Get Method Location */
6631 jvmti_GetMethodLocation,
6632 /* 72 : Get Local Variable Table */
6633 jvmti_GetLocalVariableTable,
6634 /* 73 : Set Native Method Prefix */
6635 jvmti_SetNativeMethodPrefix,
6636 /* 74 : Set Native Method Prefixes */
6637 jvmti_SetNativeMethodPrefixes,
6638 /* 75 : Get Bytecodes */
6639 jvmti_GetBytecodes,
6640 /* 76 : Is Method Native */
6641 jvmti_IsMethodNative,
6642 /* 77 : Is Method Synthetic */
6643 jvmti_IsMethodSynthetic,
6644 /* 78 : Get Loaded Classes */
6645 jvmti_GetLoadedClasses,
6646 /* 79 : Get Classloader Classes */
6647 jvmti_GetClassLoaderClasses,
6648 /* 80 : Pop Frame */
6649 jvmti_PopFrame,
6650 /* 81 : Force Early Return - Object */
6651 jvmti_ForceEarlyReturnObject,
6652 /* 82 : Force Early Return - Int */
6653 jvmti_ForceEarlyReturnInt,
6654 /* 83 : Force Early Return - Long */
6655 jvmti_ForceEarlyReturnLong,
6656 /* 84 : Force Early Return - Float */
6657 jvmti_ForceEarlyReturnFloat,
6658 /* 85 : Force Early Return - Double */
6659 jvmti_ForceEarlyReturnDouble,
6660 /* 86 : Force Early Return - Void */
6661 jvmti_ForceEarlyReturnVoid,
6662 /* 87 : Redefine Classes */
6663 jvmti_RedefineClasses,
6664 /* 88 : Get Version Number */
6665 jvmti_GetVersionNumber,
6666 /* 89 : Get Capabilities */
6667 jvmti_GetCapabilities,
6668 /* 90 : Get Source Debug Extension */
6669 jvmti_GetSourceDebugExtension,
6670 /* 91 : Is Method Obsolete */
6671 jvmti_IsMethodObsolete,
6672 /* 92 : Suspend Thread List */
6673 jvmti_SuspendThreadList,
6674 /* 93 : Resume Thread List */
6675 jvmti_ResumeThreadList,
6676 /* 94 : Add Module Reads */
6677 jvmti_AddModuleReads,
6678 /* 95 : Add Module Exports */
6679 jvmti_AddModuleExports,
6680 /* 96 : Add Module Opens */
6681 jvmti_AddModuleOpens,
6682 /* 97 : Add Module Uses */
6683 jvmti_AddModuleUses,
6684 /* 98 : Add Module Provides */
6685 jvmti_AddModuleProvides,
6686 /* 99 : Is Modifiable Module */
6687 jvmti_IsModifiableModule,
6688 /* 100 : Get All Stack Traces */
6689 jvmti_GetAllStackTraces,
6690 /* 101 : Get Thread List Stack Traces */
6691 jvmti_GetThreadListStackTraces,
6692 /* 102 : Get Thread Local Storage */
6693 jvmti_GetThreadLocalStorage,
6694 /* 103 : Set Thread Local Storage */
6695 jvmti_SetThreadLocalStorage,
6696 /* 104 : Get Stack Trace */
6697 jvmti_GetStackTrace,
6698 /* 105 : RESERVED */
6699 NULL,
6700 /* 106 : Get Tag */
6701 jvmti_GetTag,
6702 /* 107 : Set Tag */
6703 jvmti_SetTag,
6704 /* 108 : Force Garbage Collection */
6705 jvmti_ForceGarbageCollection,
6706 /* 109 : Iterate Over Objects Reachable From Object */
6707 jvmti_IterateOverObjectsReachableFromObject,
6708 /* 110 : Iterate Over Reachable Objects */
6709 jvmti_IterateOverReachableObjects,
6710 /* 111 : Iterate Over Heap */
6711 jvmti_IterateOverHeap,
6712 /* 112 : Iterate Over Instances Of Class */
6713 jvmti_IterateOverInstancesOfClass,
6714 /* 113 : RESERVED */
6715 NULL,
6716 /* 114 : Get Objects With Tags */
6717 jvmti_GetObjectsWithTags,
6718 /* 115 : Follow References */
6719 jvmti_FollowReferences,
6720 /* 116 : Iterate Through Heap */
6721 jvmti_IterateThroughHeap,
6722 /* 117 : RESERVED */
6723 NULL,
6724 /* 118 : RESERVED */
6725 NULL,
6726 /* 119 : RESERVED */
6727 NULL,
6728 /* 120 : Set JNI Function Table */
6729 jvmti_SetJNIFunctionTable,
6730 /* 121 : Get JNI Function Table */
6731 jvmti_GetJNIFunctionTable,
6732 /* 122 : Set Event Callbacks */
6733 jvmti_SetEventCallbacks,
6734 /* 123 : Generate Events */
6735 jvmti_GenerateEvents,
6736 /* 124 : Get Extension Functions */
6737 jvmti_GetExtensionFunctions,
6738 /* 125 : Get Extension Events */
6739 jvmti_GetExtensionEvents,
6740 /* 126 : Set Extension Event Callback */
6741 jvmti_SetExtensionEventCallback,
6742 /* 127 : Dispose Environment */
6743 jvmti_DisposeEnvironment,
6744 /* 128 : Get Error Name */
6745 jvmti_GetErrorName,
6746 /* 129 : Get JLocation Format */
6747 jvmti_GetJLocationFormat,
6748 /* 130 : Get System Properties */
6749 jvmti_GetSystemProperties,
6750 /* 131 : Get System Property */
6751 jvmti_GetSystemProperty,
6752 /* 132 : Set System Property */
6753 jvmti_SetSystemProperty,
6754 /* 133 : Get Phase */
6755 jvmti_GetPhase,
6756 /* 134 : Get Current Thread CPU Timer Information */
6757 jvmti_GetCurrentThreadCpuTimerInfo,
6758 /* 135 : Get Current Thread CPU Time */
6759 jvmti_GetCurrentThreadCpuTime,
6760 /* 136 : Get Thread CPU Timer Information */
6761 jvmti_GetThreadCpuTimerInfo,
6762 /* 137 : Get Thread CPU Time */
6763 jvmti_GetThreadCpuTime,
6764 /* 138 : Get Timer Information */
6765 jvmti_GetTimerInfo,
6766 /* 139 : Get Time */
6767 jvmti_GetTime,
6768 /* 140 : Get Potential Capabilities */
6769 jvmti_GetPotentialCapabilities,
6770 /* 141 : RESERVED */
6771 NULL,
6772 /* 142 : Add Capabilities */
6773 jvmti_AddCapabilities,
6774 /* 143 : Relinquish Capabilities */
6775 jvmti_RelinquishCapabilities,
6776 /* 144 : Get Available Processors */
6777 jvmti_GetAvailableProcessors,
6778 /* 145 : Get Class Version Numbers */
6779 jvmti_GetClassVersionNumbers,
6780 /* 146 : Get Constant Pool */
6781 jvmti_GetConstantPool,
6782 /* 147 : Get Environment Local Storage */
6783 jvmti_GetEnvironmentLocalStorage,
6784 /* 148 : Set Environment Local Storage */
6785 jvmti_SetEnvironmentLocalStorage,
6786 /* 149 : Add To Bootstrap Class Loader Search */
6787 jvmti_AddToBootstrapClassLoaderSearch,
6788 /* 150 : Set Verbose Flag */
6789 jvmti_SetVerboseFlag,
6790 /* 151 : Add To System Class Loader Search */
6791 jvmti_AddToSystemClassLoaderSearch,
6792 /* 152 : Retransform Classes */
6793 jvmti_RetransformClasses,
6794 /* 153 : Get Owned Monitor Stack Depth Info */
6795 jvmti_GetOwnedMonitorStackDepthInfo,
6796 /* 154 : Get Object Size */
6797 jvmti_GetObjectSize,
6798 /* 155 : Get Local Instance */
6799 jvmti_GetLocalInstance,
6800 /* 156 : Set Heap Sampling Interval */
6801 jvmti_SetHeapSamplingInterval
6802};
6803#endif // INCLUDE_JVMTI
6804