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#ifdef JVMTI_TRACE
41jbyte JvmtiTrace::_event_trace_flags[87];
42
43jint JvmtiTrace::_max_event_index = 86;
44
45// Event names
46const char* JvmtiTrace::_event_names[] = {
47 NULL,
48 NULL,
49 NULL,
50 NULL,
51 NULL,
52 NULL,
53 NULL,
54 NULL,
55 NULL,
56 NULL,
57 NULL,
58 NULL,
59 NULL,
60 NULL,
61 NULL,
62 NULL,
63 NULL,
64 NULL,
65 NULL,
66 NULL,
67 NULL,
68 NULL,
69 NULL,
70 NULL,
71 NULL,
72 NULL,
73 NULL,
74 NULL,
75 NULL,
76 NULL,
77 NULL,
78 NULL,
79 NULL,
80 NULL,
81 NULL,
82 NULL,
83 NULL,
84 NULL,
85 NULL,
86 NULL,
87 NULL,
88 NULL,
89 NULL,
90 NULL,
91 NULL,
92 NULL,
93 NULL,
94 NULL,
95 NULL,
96 NULL,
97 "VMInit",
98 "VMDeath",
99 "ThreadStart",
100 "ThreadEnd",
101 "ClassFileLoadHook",
102 "ClassLoad",
103 "ClassPrepare",
104 "VMStart",
105 "Exception",
106 "ExceptionCatch",
107 "SingleStep",
108 "FramePop",
109 "Breakpoint",
110 "FieldAccess",
111 "FieldModification",
112 "MethodEntry",
113 "MethodExit",
114 "NativeMethodBind",
115 "CompiledMethodLoad",
116 "CompiledMethodUnload",
117 "DynamicCodeGenerated",
118 "DataDumpRequest",
119 NULL,
120 "MonitorWait",
121 "MonitorWaited",
122 "MonitorContendedEnter",
123 "MonitorContendedEntered",
124 NULL,
125 NULL,
126 NULL,
127 "ResourceExhausted",
128 "GarbageCollectionStart",
129 "GarbageCollectionFinish",
130 "ObjectFree",
131 "VMObjectAlloc",
132 NULL,
133 "SampledObjectAlloc"
134};
135
136
137// Heap Reference Enumeration names
138const char* jvmtiHeapReferenceKindConstantNames[] = {
139 "JVMTI_HEAP_REFERENCE_CLASS",
140 "JVMTI_HEAP_REFERENCE_FIELD",
141 "JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT",
142 "JVMTI_HEAP_REFERENCE_CLASS_LOADER",
143 "JVMTI_HEAP_REFERENCE_SIGNERS",
144 "JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN",
145 "JVMTI_HEAP_REFERENCE_INTERFACE",
146 "JVMTI_HEAP_REFERENCE_STATIC_FIELD",
147 "JVMTI_HEAP_REFERENCE_CONSTANT_POOL",
148 "JVMTI_HEAP_REFERENCE_SUPERCLASS",
149 "JVMTI_HEAP_REFERENCE_JNI_GLOBAL",
150 "JVMTI_HEAP_REFERENCE_SYSTEM_CLASS",
151 "JVMTI_HEAP_REFERENCE_MONITOR",
152 "JVMTI_HEAP_REFERENCE_STACK_LOCAL",
153 "JVMTI_HEAP_REFERENCE_JNI_LOCAL",
154 "JVMTI_HEAP_REFERENCE_THREAD",
155 "JVMTI_HEAP_REFERENCE_OTHER",
156 NULL
157};
158
159// Heap Reference Enumeration value
160jint jvmtiHeapReferenceKindConstantValues[] = {
161 1,
162 2,
163 3,
164 4,
165 5,
166 6,
167 7,
168 8,
169 9,
170 10,
171 21,
172 22,
173 23,
174 24,
175 25,
176 26,
177 27,
178 0
179};
180
181
182
183// Primitive Type Enumeration names
184const char* jvmtiPrimitiveTypeConstantNames[] = {
185 "JVMTI_PRIMITIVE_TYPE_BOOLEAN",
186 "JVMTI_PRIMITIVE_TYPE_BYTE",
187 "JVMTI_PRIMITIVE_TYPE_CHAR",
188 "JVMTI_PRIMITIVE_TYPE_SHORT",
189 "JVMTI_PRIMITIVE_TYPE_INT",
190 "JVMTI_PRIMITIVE_TYPE_LONG",
191 "JVMTI_PRIMITIVE_TYPE_FLOAT",
192 "JVMTI_PRIMITIVE_TYPE_DOUBLE",
193 NULL
194};
195
196// Primitive Type Enumeration value
197jint jvmtiPrimitiveTypeConstantValues[] = {
198 90,
199 66,
200 67,
201 83,
202 73,
203 74,
204 70,
205 68,
206 0
207};
208
209
210
211// Heap Object Filter Enumeration names
212const char* jvmtiHeapObjectFilterConstantNames[] = {
213 "JVMTI_HEAP_OBJECT_TAGGED",
214 "JVMTI_HEAP_OBJECT_UNTAGGED",
215 "JVMTI_HEAP_OBJECT_EITHER",
216 NULL
217};
218
219// Heap Object Filter Enumeration value
220jint jvmtiHeapObjectFilterConstantValues[] = {
221 1,
222 2,
223 3,
224 0
225};
226
227
228
229// Heap Root Kind Enumeration names
230const char* jvmtiHeapRootKindConstantNames[] = {
231 "JVMTI_HEAP_ROOT_JNI_GLOBAL",
232 "JVMTI_HEAP_ROOT_SYSTEM_CLASS",
233 "JVMTI_HEAP_ROOT_MONITOR",
234 "JVMTI_HEAP_ROOT_STACK_LOCAL",
235 "JVMTI_HEAP_ROOT_JNI_LOCAL",
236 "JVMTI_HEAP_ROOT_THREAD",
237 "JVMTI_HEAP_ROOT_OTHER",
238 NULL
239};
240
241// Heap Root Kind Enumeration value
242jint jvmtiHeapRootKindConstantValues[] = {
243 1,
244 2,
245 3,
246 4,
247 5,
248 6,
249 7,
250 0
251};
252
253
254
255// Object Reference Enumeration names
256const char* jvmtiObjectReferenceKindConstantNames[] = {
257 "JVMTI_REFERENCE_CLASS",
258 "JVMTI_REFERENCE_FIELD",
259 "JVMTI_REFERENCE_ARRAY_ELEMENT",
260 "JVMTI_REFERENCE_CLASS_LOADER",
261 "JVMTI_REFERENCE_SIGNERS",
262 "JVMTI_REFERENCE_PROTECTION_DOMAIN",
263 "JVMTI_REFERENCE_INTERFACE",
264 "JVMTI_REFERENCE_STATIC_FIELD",
265 "JVMTI_REFERENCE_CONSTANT_POOL",
266 NULL
267};
268
269// Object Reference Enumeration value
270jint jvmtiObjectReferenceKindConstantValues[] = {
271 1,
272 2,
273 3,
274 4,
275 5,
276 6,
277 7,
278 8,
279 9,
280 0
281};
282
283
284
285// Iteration Control Enumeration names
286const char* jvmtiIterationControlConstantNames[] = {
287 "JVMTI_ITERATION_CONTINUE",
288 "JVMTI_ITERATION_IGNORE",
289 "JVMTI_ITERATION_ABORT",
290 NULL
291};
292
293// Iteration Control Enumeration value
294jint jvmtiIterationControlConstantValues[] = {
295 1,
296 2,
297 0,
298 0
299};
300
301
302
303// Event Enable/Disable names
304const char* jvmtiEventModeConstantNames[] = {
305 "JVMTI_ENABLE",
306 "JVMTI_DISABLE",
307 NULL
308};
309
310// Event Enable/Disable value
311jint jvmtiEventModeConstantValues[] = {
312 1,
313 0,
314 0
315};
316
317
318
319// Extension Function/Event Parameter Types names
320const char* jvmtiParamTypesConstantNames[] = {
321 "JVMTI_TYPE_JBYTE",
322 "JVMTI_TYPE_JCHAR",
323 "JVMTI_TYPE_JSHORT",
324 "JVMTI_TYPE_JINT",
325 "JVMTI_TYPE_JLONG",
326 "JVMTI_TYPE_JFLOAT",
327 "JVMTI_TYPE_JDOUBLE",
328 "JVMTI_TYPE_JBOOLEAN",
329 "JVMTI_TYPE_JOBJECT",
330 "JVMTI_TYPE_JTHREAD",
331 "JVMTI_TYPE_JCLASS",
332 "JVMTI_TYPE_JVALUE",
333 "JVMTI_TYPE_JFIELDID",
334 "JVMTI_TYPE_JMETHODID",
335 "JVMTI_TYPE_CCHAR",
336 "JVMTI_TYPE_CVOID",
337 "JVMTI_TYPE_JNIENV",
338 NULL
339};
340
341// Extension Function/Event Parameter Types value
342jint jvmtiParamTypesConstantValues[] = {
343 101,
344 102,
345 103,
346 104,
347 105,
348 106,
349 107,
350 108,
351 109,
352 110,
353 111,
354 112,
355 113,
356 114,
357 115,
358 116,
359 117,
360 0
361};
362
363
364
365// Extension Function/Event Parameter Kinds names
366const char* jvmtiParamKindConstantNames[] = {
367 "JVMTI_KIND_IN",
368 "JVMTI_KIND_IN_PTR",
369 "JVMTI_KIND_IN_BUF",
370 "JVMTI_KIND_ALLOC_BUF",
371 "JVMTI_KIND_ALLOC_ALLOC_BUF",
372 "JVMTI_KIND_OUT",
373 "JVMTI_KIND_OUT_BUF",
374 NULL
375};
376
377// Extension Function/Event Parameter Kinds value
378jint jvmtiParamKindConstantValues[] = {
379 91,
380 92,
381 93,
382 94,
383 95,
384 96,
385 97,
386 0
387};
388
389
390
391// Timer Kinds names
392const char* jvmtiTimerKindConstantNames[] = {
393 "JVMTI_TIMER_USER_CPU",
394 "JVMTI_TIMER_TOTAL_CPU",
395 "JVMTI_TIMER_ELAPSED",
396 NULL
397};
398
399// Timer Kinds value
400jint jvmtiTimerKindConstantValues[] = {
401 30,
402 31,
403 32,
404 0
405};
406
407
408
409// Phases of execution names
410const char* jvmtiPhaseConstantNames[] = {
411 "JVMTI_PHASE_ONLOAD",
412 "JVMTI_PHASE_PRIMORDIAL",
413 "JVMTI_PHASE_START",
414 "JVMTI_PHASE_LIVE",
415 "JVMTI_PHASE_DEAD",
416 NULL
417};
418
419// Phases of execution value
420jint jvmtiPhaseConstantValues[] = {
421 1,
422 2,
423 6,
424 4,
425 8,
426 0
427};
428
429
430
431// Verbose Flag Enumeration names
432const char* jvmtiVerboseFlagConstantNames[] = {
433 "JVMTI_VERBOSE_OTHER",
434 "JVMTI_VERBOSE_GC",
435 "JVMTI_VERBOSE_CLASS",
436 "JVMTI_VERBOSE_JNI",
437 NULL
438};
439
440// Verbose Flag Enumeration value
441jint jvmtiVerboseFlagConstantValues[] = {
442 0,
443 1,
444 2,
445 4,
446 0
447};
448
449
450
451// JLocation Format Enumeration names
452const char* jvmtiJlocationFormatConstantNames[] = {
453 "JVMTI_JLOCATION_JVMBCI",
454 "JVMTI_JLOCATION_MACHINEPC",
455 "JVMTI_JLOCATION_OTHER",
456 NULL
457};
458
459// JLocation Format Enumeration value
460jint jvmtiJlocationFormatConstantValues[] = {
461 1,
462 2,
463 0,
464 0
465};
466
467jbyte JvmtiTrace::_trace_flags[157];
468
469jint JvmtiTrace::_max_function_index = 156;
470
471// Function names
472const char* JvmtiTrace::_function_names[] = {
473 NULL,
474 NULL,
475 "SetEventNotificationMode",
476 "GetAllModules",
477 "GetAllThreads",
478 "SuspendThread",
479 "ResumeThread",
480 "StopThread",
481 "InterruptThread",
482 "GetThreadInfo",
483 "GetOwnedMonitorInfo",
484 "GetCurrentContendedMonitor",
485 "RunAgentThread",
486 "GetTopThreadGroups",
487 "GetThreadGroupInfo",
488 "GetThreadGroupChildren",
489 "GetFrameCount",
490 "GetThreadState",
491 "GetCurrentThread",
492 "GetFrameLocation",
493 "NotifyFramePop",
494 "GetLocalObject",
495 "GetLocalInt",
496 "GetLocalLong",
497 "GetLocalFloat",
498 "GetLocalDouble",
499 "SetLocalObject",
500 "SetLocalInt",
501 "SetLocalLong",
502 "SetLocalFloat",
503 "SetLocalDouble",
504 "CreateRawMonitor",
505 "DestroyRawMonitor",
506 "RawMonitorEnter",
507 "RawMonitorExit",
508 "RawMonitorWait",
509 "RawMonitorNotify",
510 "RawMonitorNotifyAll",
511 "SetBreakpoint",
512 "ClearBreakpoint",
513 "GetNamedModule",
514 "SetFieldAccessWatch",
515 "ClearFieldAccessWatch",
516 "SetFieldModificationWatch",
517 "ClearFieldModificationWatch",
518 "IsModifiableClass",
519 "Allocate",
520 "Deallocate",
521 "GetClassSignature",
522 "GetClassStatus",
523 "GetSourceFileName",
524 "GetClassModifiers",
525 "GetClassMethods",
526 "GetClassFields",
527 "GetImplementedInterfaces",
528 "IsInterface",
529 "IsArrayClass",
530 "GetClassLoader",
531 "GetObjectHashCode",
532 "GetObjectMonitorUsage",
533 "GetFieldName",
534 "GetFieldDeclaringClass",
535 "GetFieldModifiers",
536 "IsFieldSynthetic",
537 "GetMethodName",
538 "GetMethodDeclaringClass",
539 "GetMethodModifiers",
540 NULL,
541 "GetMaxLocals",
542 "GetArgumentsSize",
543 "GetLineNumberTable",
544 "GetMethodLocation",
545 "GetLocalVariableTable",
546 "SetNativeMethodPrefix",
547 "SetNativeMethodPrefixes",
548 "GetBytecodes",
549 "IsMethodNative",
550 "IsMethodSynthetic",
551 "GetLoadedClasses",
552 "GetClassLoaderClasses",
553 "PopFrame",
554 "ForceEarlyReturnObject",
555 "ForceEarlyReturnInt",
556 "ForceEarlyReturnLong",
557 "ForceEarlyReturnFloat",
558 "ForceEarlyReturnDouble",
559 "ForceEarlyReturnVoid",
560 "RedefineClasses",
561 "GetVersionNumber",
562 "GetCapabilities",
563 "GetSourceDebugExtension",
564 "IsMethodObsolete",
565 "SuspendThreadList",
566 "ResumeThreadList",
567 "AddModuleReads",
568 "AddModuleExports",
569 "AddModuleOpens",
570 "AddModuleUses",
571 "AddModuleProvides",
572 "IsModifiableModule",
573 "GetAllStackTraces",
574 "GetThreadListStackTraces",
575 "GetThreadLocalStorage",
576 "SetThreadLocalStorage",
577 "GetStackTrace",
578 NULL,
579 "GetTag",
580 "SetTag",
581 "ForceGarbageCollection",
582 "IterateOverObjectsReachableFromObject",
583 "IterateOverReachableObjects",
584 "IterateOverHeap",
585 "IterateOverInstancesOfClass",
586 NULL,
587 "GetObjectsWithTags",
588 "FollowReferences",
589 "IterateThroughHeap",
590 NULL,
591 NULL,
592 NULL,
593 "SetJNIFunctionTable",
594 "GetJNIFunctionTable",
595 "SetEventCallbacks",
596 "GenerateEvents",
597 "GetExtensionFunctions",
598 "GetExtensionEvents",
599 "SetExtensionEventCallback",
600 "DisposeEnvironment",
601 "GetErrorName",
602 "GetJLocationFormat",
603 "GetSystemProperties",
604 "GetSystemProperty",
605 "SetSystemProperty",
606 "GetPhase",
607 "GetCurrentThreadCpuTimerInfo",
608 "GetCurrentThreadCpuTime",
609 "GetThreadCpuTimerInfo",
610 "GetThreadCpuTime",
611 "GetTimerInfo",
612 "GetTime",
613 "GetPotentialCapabilities",
614 NULL,
615 "AddCapabilities",
616 "RelinquishCapabilities",
617 "GetAvailableProcessors",
618 "GetClassVersionNumbers",
619 "GetConstantPool",
620 "GetEnvironmentLocalStorage",
621 "SetEnvironmentLocalStorage",
622 "AddToBootstrapClassLoaderSearch",
623 "SetVerboseFlag",
624 "AddToSystemClassLoaderSearch",
625 "RetransformClasses",
626 "GetOwnedMonitorStackDepthInfo",
627 "GetObjectSize",
628 "GetLocalInstance",
629 "SetHeapSamplingInterval"
630};
631
632// Exclude list
633short JvmtiTrace::_exclude_functions[] = {
634 102,
635 103,
636 134,
637 135,
638 147,
639 148,
640 33,
641 34,
642 35,
643 36,
644 37,
645 46,
646 47,
647 0
648};
649
650
651extern "C" {
652
653
654 //
655 // Memory Management functions
656 //
657
658static jvmtiError JNICALL
659jvmtiTrace_Allocate(jvmtiEnv* env,
660 jlong size,
661 unsigned char** mem_ptr) {
662 SafeResourceMark rm;
663 jint trace_flags = JvmtiTrace::trace_flags(46);
664 const char *func_name = NULL;
665 const char *curr_thread_name = NULL;
666 if (trace_flags) {
667 func_name = JvmtiTrace::function_name(46);
668 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
669 }
670
671 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
672 if (!jvmti_env->is_valid()) {
673 if (trace_flags) {
674 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
675 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
676 }
677 return JVMTI_ERROR_INVALID_ENVIRONMENT;
678 }
679 jvmtiError err;
680 Thread* this_thread = NULL;
681 bool transition;
682 if (Threads::number_of_threads() == 0) {
683 transition = false;
684 } else {
685 this_thread = Thread::current_or_null();
686 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
687 }
688 if (transition) {
689 if (!this_thread->is_Java_thread()) {
690 if (trace_flags) {
691 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
692 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
693 }
694 return JVMTI_ERROR_UNATTACHED_THREAD;
695 }
696 JavaThread* current_thread = (JavaThread*)this_thread;
697 ThreadInVMfromNative __tiv(current_thread);
698 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_Allocate , current_thread)
699 debug_only(VMNativeEntryWrapper __vew;)
700 if (mem_ptr == NULL) {
701 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
702 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
703 log_trace(jvmti)("[%s] %s { size=" JLONG_FORMAT "", curr_thread_name, func_name, size);
704 }
705 log_error(jvmti)("[%s] %s } %s - erroneous arg is mem_ptr", curr_thread_name, func_name,
706 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
707 }
708 return JVMTI_ERROR_NULL_POINTER;
709 }
710
711 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
712 log_trace(jvmti)("[%s] %s { size=" JLONG_FORMAT "", curr_thread_name, func_name, size);
713 }
714 err = jvmti_env->Allocate(size, mem_ptr);
715 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
716 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
717 log_trace(jvmti)("[%s] %s { size=" JLONG_FORMAT "", curr_thread_name, func_name, size);
718 }
719 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
720 JvmtiUtil::error_name(err));
721 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
722 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
723 }
724 } else {
725 if (mem_ptr == NULL) {
726 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
727 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
728 log_trace(jvmti)("[%s] %s { size=" JLONG_FORMAT "", curr_thread_name, func_name, size);
729 }
730 log_error(jvmti)("[%s] %s } %s - erroneous arg is mem_ptr", curr_thread_name, func_name,
731 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
732 }
733 return JVMTI_ERROR_NULL_POINTER;
734 }
735
736 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
737 log_trace(jvmti)("[%s] %s { size=" JLONG_FORMAT "", curr_thread_name, func_name, size);
738 }
739 err = jvmti_env->Allocate(size, mem_ptr);
740 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
741 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
742 log_trace(jvmti)("[%s] %s { size=" JLONG_FORMAT "", curr_thread_name, func_name, size);
743 }
744 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
745 JvmtiUtil::error_name(err));
746 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
747 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
748 }
749 }
750 return err;
751}
752
753static jvmtiError JNICALL
754jvmtiTrace_Deallocate(jvmtiEnv* env,
755 unsigned char* mem) {
756 SafeResourceMark rm;
757 jint trace_flags = JvmtiTrace::trace_flags(47);
758 const char *func_name = NULL;
759 const char *curr_thread_name = NULL;
760 if (trace_flags) {
761 func_name = JvmtiTrace::function_name(47);
762 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
763 }
764
765 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
766 if (!jvmti_env->is_valid()) {
767 if (trace_flags) {
768 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
769 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
770 }
771 return JVMTI_ERROR_INVALID_ENVIRONMENT;
772 }
773 jvmtiError err;
774 Thread* this_thread = NULL;
775 bool transition;
776 if (Threads::number_of_threads() == 0) {
777 transition = false;
778 } else {
779 this_thread = Thread::current_or_null();
780 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
781 }
782 if (transition) {
783 if (!this_thread->is_Java_thread()) {
784 if (trace_flags) {
785 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
786 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
787 }
788 return JVMTI_ERROR_UNATTACHED_THREAD;
789 }
790 JavaThread* current_thread = (JavaThread*)this_thread;
791 ThreadInVMfromNative __tiv(current_thread);
792 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_Deallocate , current_thread)
793 debug_only(VMNativeEntryWrapper __vew;)
794
795 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
796 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
797 }
798 err = jvmti_env->Deallocate(mem);
799 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
800 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
801 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
802 }
803 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
804 JvmtiUtil::error_name(err));
805 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
806 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
807 }
808 } else {
809
810 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
811 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
812 }
813 err = jvmti_env->Deallocate(mem);
814 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
815 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
816 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
817 }
818 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
819 JvmtiUtil::error_name(err));
820 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
821 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
822 }
823 }
824 return err;
825}
826
827 //
828 // Thread functions
829 //
830
831static jvmtiError JNICALL
832jvmtiTrace_GetThreadState(jvmtiEnv* env,
833 jthread thread,
834 jint* thread_state_ptr) {
835
836#if !INCLUDE_JVMTI
837 return JVMTI_ERROR_NOT_AVAILABLE;
838#else
839 SafeResourceMark rm;
840 jint trace_flags = JvmtiTrace::trace_flags(17);
841 const char *func_name = NULL;
842 const char *curr_thread_name = NULL;
843 if (trace_flags) {
844 func_name = JvmtiTrace::function_name(17);
845 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
846 }
847 if(!JvmtiEnv::is_vm_live()) {
848 if (trace_flags) {
849 log_trace(jvmti)("[-] %s %s(%d)", func_name,
850 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
851 }
852 return JVMTI_ERROR_WRONG_PHASE;
853 }
854 Thread* this_thread = Thread::current_or_null();
855 if (this_thread == NULL || !this_thread->is_Java_thread()) {
856 if (trace_flags) {
857 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
858 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
859 }
860 return JVMTI_ERROR_UNATTACHED_THREAD;
861 }
862 JavaThread* current_thread = (JavaThread*)this_thread;
863 ThreadInVMfromNative __tiv(current_thread);
864 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetThreadState , current_thread)
865 debug_only(VMNativeEntryWrapper __vew;)
866 CautiouslyPreserveExceptionMark __em(this_thread);
867 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
868 if (!jvmti_env->is_valid()) {
869 if (trace_flags) {
870 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
871 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
872 }
873 return JVMTI_ERROR_INVALID_ENVIRONMENT;
874 }
875 jvmtiError err;
876 if (thread_state_ptr == NULL) {
877 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
878 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
879 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
880 }
881 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread_state_ptr", curr_thread_name, func_name,
882 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
883 }
884 return JVMTI_ERROR_NULL_POINTER;
885 }
886
887 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
888 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
889 }
890 err = jvmti_env->GetThreadState(thread, thread_state_ptr);
891 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
892 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
893 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
894 }
895 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
896 JvmtiUtil::error_name(err));
897 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
898 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
899 }
900 return err;
901#endif // INCLUDE_JVMTI
902}
903
904static jvmtiError JNICALL
905jvmtiTrace_GetCurrentThread(jvmtiEnv* env,
906 jthread* thread_ptr) {
907
908#if !INCLUDE_JVMTI
909 return JVMTI_ERROR_NOT_AVAILABLE;
910#else
911 SafeResourceMark rm;
912 jint trace_flags = JvmtiTrace::trace_flags(18);
913 const char *func_name = NULL;
914 const char *curr_thread_name = NULL;
915 if (trace_flags) {
916 func_name = JvmtiTrace::function_name(18);
917 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
918 }
919 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
920 if (trace_flags) {
921 log_trace(jvmti)("[-] %s %s", func_name,
922 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
923 }
924 return JVMTI_ERROR_WRONG_PHASE;
925 }
926 Thread* this_thread = Thread::current_or_null();
927 if (this_thread == NULL || !this_thread->is_Java_thread()) {
928 if (trace_flags) {
929 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
930 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
931 }
932 return JVMTI_ERROR_UNATTACHED_THREAD;
933 }
934 JavaThread* current_thread = (JavaThread*)this_thread;
935 ThreadInVMfromNative __tiv(current_thread);
936 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetCurrentThread , current_thread)
937 debug_only(VMNativeEntryWrapper __vew;)
938 CautiouslyPreserveExceptionMark __em(this_thread);
939 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
940 if (!jvmti_env->is_valid()) {
941 if (trace_flags) {
942 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
943 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
944 }
945 return JVMTI_ERROR_INVALID_ENVIRONMENT;
946 }
947 jvmtiError err;
948 if (thread_ptr == NULL) {
949 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
950 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
951 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
952 }
953 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread_ptr", curr_thread_name, func_name,
954 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
955 }
956 return JVMTI_ERROR_NULL_POINTER;
957 }
958
959 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
960 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
961 }
962 err = jvmti_env->GetCurrentThread(thread_ptr);
963 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
964 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
965 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
966 }
967 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
968 JvmtiUtil::error_name(err));
969 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
970 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
971 }
972 return err;
973#endif // INCLUDE_JVMTI
974}
975
976static jvmtiError JNICALL
977jvmtiTrace_GetAllThreads(jvmtiEnv* env,
978 jint* threads_count_ptr,
979 jthread** threads_ptr) {
980
981#if !INCLUDE_JVMTI
982 return JVMTI_ERROR_NOT_AVAILABLE;
983#else
984 SafeResourceMark rm;
985 jint trace_flags = JvmtiTrace::trace_flags(4);
986 const char *func_name = NULL;
987 const char *curr_thread_name = NULL;
988 if (trace_flags) {
989 func_name = JvmtiTrace::function_name(4);
990 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
991 }
992 if(!JvmtiEnv::is_vm_live()) {
993 if (trace_flags) {
994 log_trace(jvmti)("[-] %s %s(%d)", func_name,
995 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
996 }
997 return JVMTI_ERROR_WRONG_PHASE;
998 }
999 Thread* this_thread = Thread::current_or_null();
1000 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1001 if (trace_flags) {
1002 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
1003 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
1004 }
1005 return JVMTI_ERROR_UNATTACHED_THREAD;
1006 }
1007 JavaThread* current_thread = (JavaThread*)this_thread;
1008 ThreadInVMfromNative __tiv(current_thread);
1009 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetAllThreads , current_thread)
1010 debug_only(VMNativeEntryWrapper __vew;)
1011 CautiouslyPreserveExceptionMark __em(this_thread);
1012 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1013 if (!jvmti_env->is_valid()) {
1014 if (trace_flags) {
1015 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
1016 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
1017 }
1018 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1019 }
1020 jvmtiError err;
1021 if (threads_count_ptr == NULL) {
1022 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1023 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1024 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1025 }
1026 log_error(jvmti)("[%s] %s } %s - erroneous arg is threads_count_ptr", curr_thread_name, func_name,
1027 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
1028 }
1029 return JVMTI_ERROR_NULL_POINTER;
1030 }
1031 if (threads_ptr == NULL) {
1032 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1033 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1034 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1035 }
1036 log_error(jvmti)("[%s] %s } %s - erroneous arg is threads_ptr", curr_thread_name, func_name,
1037 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
1038 }
1039 return JVMTI_ERROR_NULL_POINTER;
1040 }
1041
1042 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
1043 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1044 }
1045 err = jvmti_env->GetAllThreads(threads_count_ptr, threads_ptr);
1046 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1047 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1048 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1049 }
1050 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
1051 JvmtiUtil::error_name(err));
1052 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
1053 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
1054 }
1055 return err;
1056#endif // INCLUDE_JVMTI
1057}
1058
1059static jvmtiError JNICALL
1060jvmtiTrace_SuspendThread(jvmtiEnv* env,
1061 jthread thread) {
1062
1063#if !INCLUDE_JVMTI
1064 return JVMTI_ERROR_NOT_AVAILABLE;
1065#else
1066 SafeResourceMark rm;
1067 jint trace_flags = JvmtiTrace::trace_flags(5);
1068 const char *func_name = NULL;
1069 const char *curr_thread_name = NULL;
1070 if (trace_flags) {
1071 func_name = JvmtiTrace::function_name(5);
1072 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
1073 }
1074 if(!JvmtiEnv::is_vm_live()) {
1075 if (trace_flags) {
1076 log_trace(jvmti)("[-] %s %s(%d)", func_name,
1077 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
1078 }
1079 return JVMTI_ERROR_WRONG_PHASE;
1080 }
1081 Thread* this_thread = Thread::current_or_null();
1082 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1083 if (trace_flags) {
1084 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
1085 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
1086 }
1087 return JVMTI_ERROR_UNATTACHED_THREAD;
1088 }
1089 JavaThread* current_thread = (JavaThread*)this_thread;
1090 ThreadInVMfromNative __tiv(current_thread);
1091 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SuspendThread , current_thread)
1092 debug_only(VMNativeEntryWrapper __vew;)
1093 CautiouslyPreserveExceptionMark __em(this_thread);
1094 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1095 if (!jvmti_env->is_valid()) {
1096 if (trace_flags) {
1097 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
1098 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
1099 }
1100 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1101 }
1102
1103 if (jvmti_env->get_capabilities()->can_suspend == 0) {
1104 if (trace_flags) {
1105 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
1106 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
1107 }
1108 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1109 }
1110 jvmtiError err;
1111 JavaThread* java_thread = NULL;
1112 ThreadsListHandle tlh(this_thread);
1113 if (thread == NULL) {
1114 java_thread = current_thread;
1115 } else {
1116 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1117 if (err != JVMTI_ERROR_NONE) {
1118 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1119 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1120 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1121 }
1122 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
1123 JvmtiUtil::error_name(err), p2i(thread));
1124 }
1125 return err;
1126 }
1127 }
1128
1129 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
1130 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1131 JvmtiTrace::safe_get_thread_name(java_thread));
1132 }
1133 err = jvmti_env->SuspendThread(java_thread);
1134 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1135 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1136 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1137 JvmtiTrace::safe_get_thread_name(java_thread));
1138 }
1139 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
1140 JvmtiUtil::error_name(err));
1141 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
1142 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
1143 }
1144 return err;
1145#endif // INCLUDE_JVMTI
1146}
1147
1148static jvmtiError JNICALL
1149jvmtiTrace_SuspendThreadList(jvmtiEnv* env,
1150 jint request_count,
1151 const jthread* request_list,
1152 jvmtiError* results) {
1153
1154#if !INCLUDE_JVMTI
1155 return JVMTI_ERROR_NOT_AVAILABLE;
1156#else
1157 SafeResourceMark rm;
1158 jint trace_flags = JvmtiTrace::trace_flags(92);
1159 const char *func_name = NULL;
1160 const char *curr_thread_name = NULL;
1161 if (trace_flags) {
1162 func_name = JvmtiTrace::function_name(92);
1163 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
1164 }
1165 if(!JvmtiEnv::is_vm_live()) {
1166 if (trace_flags) {
1167 log_trace(jvmti)("[-] %s %s(%d)", func_name,
1168 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
1169 }
1170 return JVMTI_ERROR_WRONG_PHASE;
1171 }
1172 Thread* this_thread = Thread::current_or_null();
1173 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1174 if (trace_flags) {
1175 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
1176 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
1177 }
1178 return JVMTI_ERROR_UNATTACHED_THREAD;
1179 }
1180 JavaThread* current_thread = (JavaThread*)this_thread;
1181 ThreadInVMfromNative __tiv(current_thread);
1182 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SuspendThreadList , current_thread)
1183 debug_only(VMNativeEntryWrapper __vew;)
1184 CautiouslyPreserveExceptionMark __em(this_thread);
1185 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1186 if (!jvmti_env->is_valid()) {
1187 if (trace_flags) {
1188 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
1189 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
1190 }
1191 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1192 }
1193
1194 if (jvmti_env->get_capabilities()->can_suspend == 0) {
1195 if (trace_flags) {
1196 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
1197 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
1198 }
1199 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1200 }
1201 jvmtiError err;
1202 if (request_count < 0) {
1203 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1204 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1205 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1206 }
1207 log_error(jvmti)("[%s] %s } %s - erroneous arg is request_count", curr_thread_name, func_name,
1208 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT));
1209 }
1210 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
1211 }
1212 if (request_list == NULL) {
1213 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1214 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1215 log_trace(jvmti)("[%s] %s { request_count=" INT32_FORMAT "", curr_thread_name, func_name, request_count);
1216 }
1217 log_error(jvmti)("[%s] %s } %s - erroneous arg is request_list", curr_thread_name, func_name,
1218 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
1219 }
1220 return JVMTI_ERROR_NULL_POINTER;
1221 }
1222 if (results == NULL) {
1223 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1224 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1225 log_trace(jvmti)("[%s] %s { request_count=" INT32_FORMAT " request_list=" PTR_FORMAT "", curr_thread_name, func_name, request_count,
1226 p2i(request_list)
1227 );
1228 }
1229 log_error(jvmti)("[%s] %s } %s - erroneous arg is results", curr_thread_name, func_name,
1230 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
1231 }
1232 return JVMTI_ERROR_NULL_POINTER;
1233 }
1234
1235 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
1236 log_trace(jvmti)("[%s] %s { request_count=" INT32_FORMAT " request_list=" PTR_FORMAT "", curr_thread_name, func_name, request_count,
1237 p2i(request_list)
1238 );
1239 }
1240 err = jvmti_env->SuspendThreadList(request_count, request_list, results);
1241 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1242 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1243 log_trace(jvmti)("[%s] %s { request_count=" INT32_FORMAT " request_list=" PTR_FORMAT "", curr_thread_name, func_name, request_count,
1244 p2i(request_list)
1245 );
1246 }
1247 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
1248 JvmtiUtil::error_name(err));
1249 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
1250 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
1251 }
1252 return err;
1253#endif // INCLUDE_JVMTI
1254}
1255
1256static jvmtiError JNICALL
1257jvmtiTrace_ResumeThread(jvmtiEnv* env,
1258 jthread thread) {
1259
1260#if !INCLUDE_JVMTI
1261 return JVMTI_ERROR_NOT_AVAILABLE;
1262#else
1263 SafeResourceMark rm;
1264 jint trace_flags = JvmtiTrace::trace_flags(6);
1265 const char *func_name = NULL;
1266 const char *curr_thread_name = NULL;
1267 if (trace_flags) {
1268 func_name = JvmtiTrace::function_name(6);
1269 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
1270 }
1271 if(!JvmtiEnv::is_vm_live()) {
1272 if (trace_flags) {
1273 log_trace(jvmti)("[-] %s %s(%d)", func_name,
1274 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
1275 }
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 if (trace_flags) {
1281 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
1282 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
1283 }
1284 return JVMTI_ERROR_UNATTACHED_THREAD;
1285 }
1286 JavaThread* current_thread = (JavaThread*)this_thread;
1287 ThreadInVMfromNative __tiv(current_thread);
1288 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_ResumeThread , current_thread)
1289 debug_only(VMNativeEntryWrapper __vew;)
1290 CautiouslyPreserveExceptionMark __em(this_thread);
1291 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1292 if (!jvmti_env->is_valid()) {
1293 if (trace_flags) {
1294 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
1295 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
1296 }
1297 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1298 }
1299
1300 if (jvmti_env->get_capabilities()->can_suspend == 0) {
1301 if (trace_flags) {
1302 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
1303 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
1304 }
1305 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1306 }
1307 jvmtiError err;
1308 JavaThread* java_thread = NULL;
1309 ThreadsListHandle tlh(this_thread);
1310 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1311 if (err != JVMTI_ERROR_NONE) {
1312 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1313 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1314 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1315 }
1316 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
1317 JvmtiUtil::error_name(err), p2i(thread));
1318 }
1319 return err;
1320 }
1321
1322 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
1323 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1324 JvmtiTrace::safe_get_thread_name(java_thread));
1325 }
1326 err = jvmti_env->ResumeThread(java_thread);
1327 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1328 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1329 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1330 JvmtiTrace::safe_get_thread_name(java_thread));
1331 }
1332 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
1333 JvmtiUtil::error_name(err));
1334 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
1335 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
1336 }
1337 return err;
1338#endif // INCLUDE_JVMTI
1339}
1340
1341static jvmtiError JNICALL
1342jvmtiTrace_ResumeThreadList(jvmtiEnv* env,
1343 jint request_count,
1344 const jthread* request_list,
1345 jvmtiError* results) {
1346
1347#if !INCLUDE_JVMTI
1348 return JVMTI_ERROR_NOT_AVAILABLE;
1349#else
1350 SafeResourceMark rm;
1351 jint trace_flags = JvmtiTrace::trace_flags(93);
1352 const char *func_name = NULL;
1353 const char *curr_thread_name = NULL;
1354 if (trace_flags) {
1355 func_name = JvmtiTrace::function_name(93);
1356 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
1357 }
1358 if(!JvmtiEnv::is_vm_live()) {
1359 if (trace_flags) {
1360 log_trace(jvmti)("[-] %s %s(%d)", func_name,
1361 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
1362 }
1363 return JVMTI_ERROR_WRONG_PHASE;
1364 }
1365 Thread* this_thread = Thread::current_or_null();
1366 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1367 if (trace_flags) {
1368 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
1369 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
1370 }
1371 return JVMTI_ERROR_UNATTACHED_THREAD;
1372 }
1373 JavaThread* current_thread = (JavaThread*)this_thread;
1374 ThreadInVMfromNative __tiv(current_thread);
1375 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_ResumeThreadList , current_thread)
1376 debug_only(VMNativeEntryWrapper __vew;)
1377 CautiouslyPreserveExceptionMark __em(this_thread);
1378 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1379 if (!jvmti_env->is_valid()) {
1380 if (trace_flags) {
1381 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
1382 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
1383 }
1384 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1385 }
1386
1387 if (jvmti_env->get_capabilities()->can_suspend == 0) {
1388 if (trace_flags) {
1389 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
1390 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
1391 }
1392 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1393 }
1394 jvmtiError err;
1395 if (request_count < 0) {
1396 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1397 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1398 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1399 }
1400 log_error(jvmti)("[%s] %s } %s - erroneous arg is request_count", curr_thread_name, func_name,
1401 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT));
1402 }
1403 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
1404 }
1405 if (request_list == NULL) {
1406 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1407 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1408 log_trace(jvmti)("[%s] %s { request_count=" INT32_FORMAT "", curr_thread_name, func_name, request_count);
1409 }
1410 log_error(jvmti)("[%s] %s } %s - erroneous arg is request_list", curr_thread_name, func_name,
1411 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
1412 }
1413 return JVMTI_ERROR_NULL_POINTER;
1414 }
1415 if (results == NULL) {
1416 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1417 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1418 log_trace(jvmti)("[%s] %s { request_count=" INT32_FORMAT " request_list=" PTR_FORMAT "", curr_thread_name, func_name, request_count,
1419 p2i(request_list)
1420 );
1421 }
1422 log_error(jvmti)("[%s] %s } %s - erroneous arg is results", curr_thread_name, func_name,
1423 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
1424 }
1425 return JVMTI_ERROR_NULL_POINTER;
1426 }
1427
1428 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
1429 log_trace(jvmti)("[%s] %s { request_count=" INT32_FORMAT " request_list=" PTR_FORMAT "", curr_thread_name, func_name, request_count,
1430 p2i(request_list)
1431 );
1432 }
1433 err = jvmti_env->ResumeThreadList(request_count, request_list, results);
1434 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1435 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1436 log_trace(jvmti)("[%s] %s { request_count=" INT32_FORMAT " request_list=" PTR_FORMAT "", curr_thread_name, func_name, request_count,
1437 p2i(request_list)
1438 );
1439 }
1440 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
1441 JvmtiUtil::error_name(err));
1442 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
1443 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
1444 }
1445 return err;
1446#endif // INCLUDE_JVMTI
1447}
1448
1449static jvmtiError JNICALL
1450jvmtiTrace_StopThread(jvmtiEnv* env,
1451 jthread thread,
1452 jobject exception) {
1453
1454#if !INCLUDE_JVMTI
1455 return JVMTI_ERROR_NOT_AVAILABLE;
1456#else
1457 SafeResourceMark rm;
1458 jint trace_flags = JvmtiTrace::trace_flags(7);
1459 const char *func_name = NULL;
1460 const char *curr_thread_name = NULL;
1461 if (trace_flags) {
1462 func_name = JvmtiTrace::function_name(7);
1463 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
1464 }
1465 if(!JvmtiEnv::is_vm_live()) {
1466 if (trace_flags) {
1467 log_trace(jvmti)("[-] %s %s(%d)", func_name,
1468 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
1469 }
1470 return JVMTI_ERROR_WRONG_PHASE;
1471 }
1472 Thread* this_thread = Thread::current_or_null();
1473 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1474 if (trace_flags) {
1475 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
1476 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
1477 }
1478 return JVMTI_ERROR_UNATTACHED_THREAD;
1479 }
1480 JavaThread* current_thread = (JavaThread*)this_thread;
1481 ThreadInVMfromNative __tiv(current_thread);
1482 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_StopThread , current_thread)
1483 debug_only(VMNativeEntryWrapper __vew;)
1484 CautiouslyPreserveExceptionMark __em(this_thread);
1485 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1486 if (!jvmti_env->is_valid()) {
1487 if (trace_flags) {
1488 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
1489 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
1490 }
1491 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1492 }
1493
1494 if (jvmti_env->get_capabilities()->can_signal_thread == 0) {
1495 if (trace_flags) {
1496 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
1497 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
1498 }
1499 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1500 }
1501 jvmtiError err;
1502 JavaThread* java_thread = NULL;
1503 ThreadsListHandle tlh(this_thread);
1504 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1505 if (err != JVMTI_ERROR_NONE) {
1506 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1507 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1508 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1509 }
1510 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
1511 JvmtiUtil::error_name(err), p2i(thread));
1512 }
1513 return err;
1514 }
1515
1516 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
1517 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1518 JvmtiTrace::safe_get_thread_name(java_thread));
1519 }
1520 err = jvmti_env->StopThread(java_thread, exception);
1521 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1522 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1523 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1524 JvmtiTrace::safe_get_thread_name(java_thread));
1525 }
1526 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
1527 JvmtiUtil::error_name(err));
1528 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
1529 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
1530 }
1531 return err;
1532#endif // INCLUDE_JVMTI
1533}
1534
1535static jvmtiError JNICALL
1536jvmtiTrace_InterruptThread(jvmtiEnv* env,
1537 jthread thread) {
1538
1539#if !INCLUDE_JVMTI
1540 return JVMTI_ERROR_NOT_AVAILABLE;
1541#else
1542 SafeResourceMark rm;
1543 jint trace_flags = JvmtiTrace::trace_flags(8);
1544 const char *func_name = NULL;
1545 const char *curr_thread_name = NULL;
1546 if (trace_flags) {
1547 func_name = JvmtiTrace::function_name(8);
1548 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
1549 }
1550 if(!JvmtiEnv::is_vm_live()) {
1551 if (trace_flags) {
1552 log_trace(jvmti)("[-] %s %s(%d)", func_name,
1553 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
1554 }
1555 return JVMTI_ERROR_WRONG_PHASE;
1556 }
1557 Thread* this_thread = Thread::current_or_null();
1558 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1559 if (trace_flags) {
1560 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
1561 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
1562 }
1563 return JVMTI_ERROR_UNATTACHED_THREAD;
1564 }
1565 JavaThread* current_thread = (JavaThread*)this_thread;
1566 ThreadInVMfromNative __tiv(current_thread);
1567 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_InterruptThread , current_thread)
1568 debug_only(VMNativeEntryWrapper __vew;)
1569 CautiouslyPreserveExceptionMark __em(this_thread);
1570 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1571 if (!jvmti_env->is_valid()) {
1572 if (trace_flags) {
1573 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
1574 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
1575 }
1576 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1577 }
1578
1579 if (jvmti_env->get_capabilities()->can_signal_thread == 0) {
1580 if (trace_flags) {
1581 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
1582 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
1583 }
1584 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1585 }
1586 jvmtiError err;
1587
1588 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
1589 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1590 }
1591 err = jvmti_env->InterruptThread(thread);
1592 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1593 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1594 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1595 }
1596 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
1597 JvmtiUtil::error_name(err));
1598 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
1599 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
1600 }
1601 return err;
1602#endif // INCLUDE_JVMTI
1603}
1604
1605static jvmtiError JNICALL
1606jvmtiTrace_GetThreadInfo(jvmtiEnv* env,
1607 jthread thread,
1608 jvmtiThreadInfo* info_ptr) {
1609
1610#if !INCLUDE_JVMTI
1611 return JVMTI_ERROR_NOT_AVAILABLE;
1612#else
1613 SafeResourceMark rm;
1614 jint trace_flags = JvmtiTrace::trace_flags(9);
1615 const char *func_name = NULL;
1616 const char *curr_thread_name = NULL;
1617 if (trace_flags) {
1618 func_name = JvmtiTrace::function_name(9);
1619 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
1620 }
1621 if(!JvmtiEnv::is_vm_live()) {
1622 if (trace_flags) {
1623 log_trace(jvmti)("[-] %s %s(%d)", func_name,
1624 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
1625 }
1626 return JVMTI_ERROR_WRONG_PHASE;
1627 }
1628 Thread* this_thread = Thread::current_or_null();
1629 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1630 if (trace_flags) {
1631 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
1632 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
1633 }
1634 return JVMTI_ERROR_UNATTACHED_THREAD;
1635 }
1636 JavaThread* current_thread = (JavaThread*)this_thread;
1637 ThreadInVMfromNative __tiv(current_thread);
1638 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetThreadInfo , current_thread)
1639 debug_only(VMNativeEntryWrapper __vew;)
1640 CautiouslyPreserveExceptionMark __em(this_thread);
1641 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1642 if (!jvmti_env->is_valid()) {
1643 if (trace_flags) {
1644 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
1645 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
1646 }
1647 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1648 }
1649 jvmtiError err;
1650 if (info_ptr == NULL) {
1651 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1652 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1653 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1654 }
1655 log_error(jvmti)("[%s] %s } %s - erroneous arg is info_ptr", curr_thread_name, func_name,
1656 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
1657 }
1658 return JVMTI_ERROR_NULL_POINTER;
1659 }
1660
1661 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
1662 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1663 }
1664 err = jvmti_env->GetThreadInfo(thread, info_ptr);
1665 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1666 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1667 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1668 }
1669 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
1670 JvmtiUtil::error_name(err));
1671 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
1672 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
1673 }
1674 return err;
1675#endif // INCLUDE_JVMTI
1676}
1677
1678static jvmtiError JNICALL
1679jvmtiTrace_GetOwnedMonitorInfo(jvmtiEnv* env,
1680 jthread thread,
1681 jint* owned_monitor_count_ptr,
1682 jobject** owned_monitors_ptr) {
1683
1684#if !INCLUDE_JVMTI
1685 return JVMTI_ERROR_NOT_AVAILABLE;
1686#else
1687 SafeResourceMark rm;
1688 jint trace_flags = JvmtiTrace::trace_flags(10);
1689 const char *func_name = NULL;
1690 const char *curr_thread_name = NULL;
1691 if (trace_flags) {
1692 func_name = JvmtiTrace::function_name(10);
1693 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
1694 }
1695 if(!JvmtiEnv::is_vm_live()) {
1696 if (trace_flags) {
1697 log_trace(jvmti)("[-] %s %s(%d)", func_name,
1698 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
1699 }
1700 return JVMTI_ERROR_WRONG_PHASE;
1701 }
1702 Thread* this_thread = Thread::current_or_null();
1703 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1704 if (trace_flags) {
1705 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
1706 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
1707 }
1708 return JVMTI_ERROR_UNATTACHED_THREAD;
1709 }
1710 JavaThread* current_thread = (JavaThread*)this_thread;
1711 ThreadInVMfromNative __tiv(current_thread);
1712 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetOwnedMonitorInfo , current_thread)
1713 debug_only(VMNativeEntryWrapper __vew;)
1714 CautiouslyPreserveExceptionMark __em(this_thread);
1715 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1716 if (!jvmti_env->is_valid()) {
1717 if (trace_flags) {
1718 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
1719 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
1720 }
1721 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1722 }
1723
1724 if (jvmti_env->get_capabilities()->can_get_owned_monitor_info == 0) {
1725 if (trace_flags) {
1726 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
1727 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
1728 }
1729 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1730 }
1731 jvmtiError err;
1732 JavaThread* java_thread = NULL;
1733 ThreadsListHandle tlh(this_thread);
1734 if (thread == NULL) {
1735 java_thread = current_thread;
1736 } else {
1737 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1738 if (err != JVMTI_ERROR_NONE) {
1739 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1740 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1741 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1742 }
1743 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
1744 JvmtiUtil::error_name(err), p2i(thread));
1745 }
1746 return err;
1747 }
1748 }
1749 if (owned_monitor_count_ptr == NULL) {
1750 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1751 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1752 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1753 JvmtiTrace::safe_get_thread_name(java_thread));
1754 }
1755 log_error(jvmti)("[%s] %s } %s - erroneous arg is owned_monitor_count_ptr", curr_thread_name, func_name,
1756 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
1757 }
1758 return JVMTI_ERROR_NULL_POINTER;
1759 }
1760 if (owned_monitors_ptr == NULL) {
1761 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1762 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1763 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1764 JvmtiTrace::safe_get_thread_name(java_thread));
1765 }
1766 log_error(jvmti)("[%s] %s } %s - erroneous arg is owned_monitors_ptr", curr_thread_name, func_name,
1767 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
1768 }
1769 return JVMTI_ERROR_NULL_POINTER;
1770 }
1771
1772 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
1773 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1774 JvmtiTrace::safe_get_thread_name(java_thread));
1775 }
1776 err = jvmti_env->GetOwnedMonitorInfo(java_thread, owned_monitor_count_ptr, owned_monitors_ptr);
1777 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1778 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1779 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1780 JvmtiTrace::safe_get_thread_name(java_thread));
1781 }
1782 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
1783 JvmtiUtil::error_name(err));
1784 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
1785 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
1786 }
1787 return err;
1788#endif // INCLUDE_JVMTI
1789}
1790
1791static jvmtiError JNICALL
1792jvmtiTrace_GetOwnedMonitorStackDepthInfo(jvmtiEnv* env,
1793 jthread thread,
1794 jint* monitor_info_count_ptr,
1795 jvmtiMonitorStackDepthInfo** monitor_info_ptr) {
1796
1797#if !INCLUDE_JVMTI
1798 return JVMTI_ERROR_NOT_AVAILABLE;
1799#else
1800 SafeResourceMark rm;
1801 jint trace_flags = JvmtiTrace::trace_flags(153);
1802 const char *func_name = NULL;
1803 const char *curr_thread_name = NULL;
1804 if (trace_flags) {
1805 func_name = JvmtiTrace::function_name(153);
1806 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
1807 }
1808 if(!JvmtiEnv::is_vm_live()) {
1809 if (trace_flags) {
1810 log_trace(jvmti)("[-] %s %s(%d)", func_name,
1811 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
1812 }
1813 return JVMTI_ERROR_WRONG_PHASE;
1814 }
1815 Thread* this_thread = Thread::current_or_null();
1816 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1817 if (trace_flags) {
1818 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
1819 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
1820 }
1821 return JVMTI_ERROR_UNATTACHED_THREAD;
1822 }
1823 JavaThread* current_thread = (JavaThread*)this_thread;
1824 ThreadInVMfromNative __tiv(current_thread);
1825 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetOwnedMonitorStackDepthInfo , current_thread)
1826 debug_only(VMNativeEntryWrapper __vew;)
1827 CautiouslyPreserveExceptionMark __em(this_thread);
1828 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1829 if (!jvmti_env->is_valid()) {
1830 if (trace_flags) {
1831 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
1832 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
1833 }
1834 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1835 }
1836
1837 if (jvmti_env->get_capabilities()->can_get_owned_monitor_stack_depth_info == 0) {
1838 if (trace_flags) {
1839 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
1840 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
1841 }
1842 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1843 }
1844 jvmtiError err;
1845 JavaThread* java_thread = NULL;
1846 ThreadsListHandle tlh(this_thread);
1847 if (thread == NULL) {
1848 java_thread = current_thread;
1849 } else {
1850 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1851 if (err != JVMTI_ERROR_NONE) {
1852 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1853 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1854 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1855 }
1856 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
1857 JvmtiUtil::error_name(err), p2i(thread));
1858 }
1859 return err;
1860 }
1861 }
1862 if (monitor_info_count_ptr == NULL) {
1863 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1864 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1865 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1866 JvmtiTrace::safe_get_thread_name(java_thread));
1867 }
1868 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor_info_count_ptr", curr_thread_name, func_name,
1869 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
1870 }
1871 return JVMTI_ERROR_NULL_POINTER;
1872 }
1873 if (monitor_info_ptr == NULL) {
1874 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1875 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1876 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1877 JvmtiTrace::safe_get_thread_name(java_thread));
1878 }
1879 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor_info_ptr", curr_thread_name, func_name,
1880 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
1881 }
1882 return JVMTI_ERROR_NULL_POINTER;
1883 }
1884
1885 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
1886 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1887 JvmtiTrace::safe_get_thread_name(java_thread));
1888 }
1889 err = jvmti_env->GetOwnedMonitorStackDepthInfo(java_thread, monitor_info_count_ptr, monitor_info_ptr);
1890 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1891 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1892 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1893 JvmtiTrace::safe_get_thread_name(java_thread));
1894 }
1895 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
1896 JvmtiUtil::error_name(err));
1897 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
1898 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
1899 }
1900 return err;
1901#endif // INCLUDE_JVMTI
1902}
1903
1904static jvmtiError JNICALL
1905jvmtiTrace_GetCurrentContendedMonitor(jvmtiEnv* env,
1906 jthread thread,
1907 jobject* monitor_ptr) {
1908
1909#if !INCLUDE_JVMTI
1910 return JVMTI_ERROR_NOT_AVAILABLE;
1911#else
1912 SafeResourceMark rm;
1913 jint trace_flags = JvmtiTrace::trace_flags(11);
1914 const char *func_name = NULL;
1915 const char *curr_thread_name = NULL;
1916 if (trace_flags) {
1917 func_name = JvmtiTrace::function_name(11);
1918 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
1919 }
1920 if(!JvmtiEnv::is_vm_live()) {
1921 if (trace_flags) {
1922 log_trace(jvmti)("[-] %s %s(%d)", func_name,
1923 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
1924 }
1925 return JVMTI_ERROR_WRONG_PHASE;
1926 }
1927 Thread* this_thread = Thread::current_or_null();
1928 if (this_thread == NULL || !this_thread->is_Java_thread()) {
1929 if (trace_flags) {
1930 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
1931 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
1932 }
1933 return JVMTI_ERROR_UNATTACHED_THREAD;
1934 }
1935 JavaThread* current_thread = (JavaThread*)this_thread;
1936 ThreadInVMfromNative __tiv(current_thread);
1937 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetCurrentContendedMonitor , current_thread)
1938 debug_only(VMNativeEntryWrapper __vew;)
1939 CautiouslyPreserveExceptionMark __em(this_thread);
1940 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
1941 if (!jvmti_env->is_valid()) {
1942 if (trace_flags) {
1943 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
1944 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
1945 }
1946 return JVMTI_ERROR_INVALID_ENVIRONMENT;
1947 }
1948
1949 if (jvmti_env->get_capabilities()->can_get_current_contended_monitor == 0) {
1950 if (trace_flags) {
1951 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
1952 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
1953 }
1954 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
1955 }
1956 jvmtiError err;
1957 JavaThread* java_thread = NULL;
1958 ThreadsListHandle tlh(this_thread);
1959 if (thread == NULL) {
1960 java_thread = current_thread;
1961 } else {
1962 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
1963 if (err != JVMTI_ERROR_NONE) {
1964 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1965 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1966 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
1967 }
1968 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
1969 JvmtiUtil::error_name(err), p2i(thread));
1970 }
1971 return err;
1972 }
1973 }
1974 if (monitor_ptr == NULL) {
1975 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1976 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1977 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1978 JvmtiTrace::safe_get_thread_name(java_thread));
1979 }
1980 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor_ptr", curr_thread_name, func_name,
1981 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
1982 }
1983 return JVMTI_ERROR_NULL_POINTER;
1984 }
1985
1986 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
1987 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1988 JvmtiTrace::safe_get_thread_name(java_thread));
1989 }
1990 err = jvmti_env->GetCurrentContendedMonitor(java_thread, monitor_ptr);
1991 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
1992 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
1993 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
1994 JvmtiTrace::safe_get_thread_name(java_thread));
1995 }
1996 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
1997 JvmtiUtil::error_name(err));
1998 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
1999 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
2000 }
2001 return err;
2002#endif // INCLUDE_JVMTI
2003}
2004
2005static jvmtiError JNICALL
2006jvmtiTrace_RunAgentThread(jvmtiEnv* env,
2007 jthread thread,
2008 jvmtiStartFunction proc,
2009 const void* arg,
2010 jint priority) {
2011
2012#if !INCLUDE_JVMTI
2013 return JVMTI_ERROR_NOT_AVAILABLE;
2014#else
2015 SafeResourceMark rm;
2016 jint trace_flags = JvmtiTrace::trace_flags(12);
2017 const char *func_name = NULL;
2018 const char *curr_thread_name = NULL;
2019 if (trace_flags) {
2020 func_name = JvmtiTrace::function_name(12);
2021 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
2022 }
2023 if(!JvmtiEnv::is_vm_live()) {
2024 if (trace_flags) {
2025 log_trace(jvmti)("[-] %s %s(%d)", func_name,
2026 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
2027 }
2028 return JVMTI_ERROR_WRONG_PHASE;
2029 }
2030 Thread* this_thread = Thread::current_or_null();
2031 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2032 if (trace_flags) {
2033 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
2034 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
2035 }
2036 return JVMTI_ERROR_UNATTACHED_THREAD;
2037 }
2038 JavaThread* current_thread = (JavaThread*)this_thread;
2039 ThreadInVMfromNative __tiv(current_thread);
2040 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_RunAgentThread , 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 if (trace_flags) {
2046 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
2047 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
2048 }
2049 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2050 }
2051 jvmtiError err;
2052 if (proc == NULL) {
2053 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2054 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2055 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2056 }
2057 log_error(jvmti)("[%s] %s } %s - erroneous arg is proc", curr_thread_name, func_name,
2058 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2059 }
2060 return JVMTI_ERROR_NULL_POINTER;
2061 }
2062
2063 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
2064 log_trace(jvmti)("[%s] %s { arg=" PTR_FORMAT " priority=" INT32_FORMAT "", curr_thread_name, func_name,
2065 p2i(arg)
2066 , priority);
2067 }
2068 err = jvmti_env->RunAgentThread(thread, proc, arg, priority);
2069 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2070 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2071 log_trace(jvmti)("[%s] %s { arg=" PTR_FORMAT " priority=" INT32_FORMAT "", curr_thread_name, func_name,
2072 p2i(arg)
2073 , priority);
2074 }
2075 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
2076 JvmtiUtil::error_name(err));
2077 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
2078 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
2079 }
2080 return err;
2081#endif // INCLUDE_JVMTI
2082}
2083
2084static jvmtiError JNICALL
2085jvmtiTrace_SetThreadLocalStorage(jvmtiEnv* env,
2086 jthread thread,
2087 const void* data) {
2088 SafeResourceMark rm;
2089 jint trace_flags = JvmtiTrace::trace_flags(103);
2090 const char *func_name = NULL;
2091 const char *curr_thread_name = NULL;
2092 if (trace_flags) {
2093 func_name = JvmtiTrace::function_name(103);
2094 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
2095 }
2096 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
2097 if (trace_flags) {
2098 log_trace(jvmti)("[-] %s %s", func_name,
2099 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
2100 }
2101 return JVMTI_ERROR_WRONG_PHASE;
2102 }
2103 Thread* this_thread = Thread::current_or_null();
2104 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2105 if (trace_flags) {
2106 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
2107 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
2108 }
2109 return JVMTI_ERROR_UNATTACHED_THREAD;
2110 }
2111 JavaThread* current_thread = (JavaThread*)this_thread;
2112 ThreadInVMfromNative __tiv(current_thread);
2113 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetThreadLocalStorage , current_thread)
2114 debug_only(VMNativeEntryWrapper __vew;)
2115 CautiouslyPreserveExceptionMark __em(this_thread);
2116 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2117 if (!jvmti_env->is_valid()) {
2118 if (trace_flags) {
2119 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
2120 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
2121 }
2122 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2123 }
2124 jvmtiError err;
2125 JavaThread* java_thread = NULL;
2126 ThreadsListHandle tlh(this_thread);
2127 if (thread == NULL) {
2128 java_thread = current_thread;
2129 } else {
2130 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
2131 if (err != JVMTI_ERROR_NONE) {
2132 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2133 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2134 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2135 }
2136 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
2137 JvmtiUtil::error_name(err), p2i(thread));
2138 }
2139 return err;
2140 }
2141 }
2142
2143 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
2144 log_trace(jvmti)("[%s] %s { thread=%s data=" PTR_FORMAT "", curr_thread_name, func_name,
2145 JvmtiTrace::safe_get_thread_name(java_thread),
2146 p2i(data)
2147 );
2148 }
2149 err = jvmti_env->SetThreadLocalStorage(java_thread, data);
2150 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2151 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2152 log_trace(jvmti)("[%s] %s { thread=%s data=" PTR_FORMAT "", curr_thread_name, func_name,
2153 JvmtiTrace::safe_get_thread_name(java_thread),
2154 p2i(data)
2155 );
2156 }
2157 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
2158 JvmtiUtil::error_name(err));
2159 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
2160 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
2161 }
2162 return err;
2163}
2164
2165static jvmtiError JNICALL
2166jvmtiTrace_GetThreadLocalStorage(jvmtiEnv* env,
2167 jthread thread,
2168 void** data_ptr) {
2169 SafeResourceMark rm;
2170 jint trace_flags = JvmtiTrace::trace_flags(102);
2171 const char *func_name = NULL;
2172 const char *curr_thread_name = NULL;
2173 if (trace_flags) {
2174 func_name = JvmtiTrace::function_name(102);
2175 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
2176 }
2177 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
2178 if (trace_flags) {
2179 log_trace(jvmti)("[-] %s %s", func_name,
2180 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
2181 }
2182 return JVMTI_ERROR_WRONG_PHASE;
2183 }
2184 Thread* this_thread = Thread::current_or_null();
2185 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2186 if (trace_flags) {
2187 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
2188 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
2189 }
2190 return JVMTI_ERROR_UNATTACHED_THREAD;
2191 }
2192
2193 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2194 if (!jvmti_env->is_valid()) {
2195 if (trace_flags) {
2196 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
2197 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
2198 }
2199 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2200 }
2201 jvmtiError err;
2202 if (data_ptr == NULL) {
2203 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2204 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2205 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2206 }
2207 log_error(jvmti)("[%s] %s } %s - erroneous arg is data_ptr", curr_thread_name, func_name,
2208 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2209 }
2210 return JVMTI_ERROR_NULL_POINTER;
2211 }
2212
2213 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
2214 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2215 }
2216 err = jvmti_env->GetThreadLocalStorage(thread, data_ptr);
2217 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2218 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2219 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2220 }
2221 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
2222 JvmtiUtil::error_name(err));
2223 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
2224 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
2225 }
2226 return err;
2227}
2228
2229 //
2230 // Thread Group functions
2231 //
2232
2233static jvmtiError JNICALL
2234jvmtiTrace_GetTopThreadGroups(jvmtiEnv* env,
2235 jint* group_count_ptr,
2236 jthreadGroup** groups_ptr) {
2237
2238#if !INCLUDE_JVMTI
2239 return JVMTI_ERROR_NOT_AVAILABLE;
2240#else
2241 SafeResourceMark rm;
2242 jint trace_flags = JvmtiTrace::trace_flags(13);
2243 const char *func_name = NULL;
2244 const char *curr_thread_name = NULL;
2245 if (trace_flags) {
2246 func_name = JvmtiTrace::function_name(13);
2247 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
2248 }
2249 if(!JvmtiEnv::is_vm_live()) {
2250 if (trace_flags) {
2251 log_trace(jvmti)("[-] %s %s(%d)", func_name,
2252 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
2253 }
2254 return JVMTI_ERROR_WRONG_PHASE;
2255 }
2256 Thread* this_thread = Thread::current_or_null();
2257 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2258 if (trace_flags) {
2259 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
2260 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
2261 }
2262 return JVMTI_ERROR_UNATTACHED_THREAD;
2263 }
2264 JavaThread* current_thread = (JavaThread*)this_thread;
2265 ThreadInVMfromNative __tiv(current_thread);
2266 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetTopThreadGroups , current_thread)
2267 debug_only(VMNativeEntryWrapper __vew;)
2268 CautiouslyPreserveExceptionMark __em(this_thread);
2269 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2270 if (!jvmti_env->is_valid()) {
2271 if (trace_flags) {
2272 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
2273 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
2274 }
2275 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2276 }
2277 jvmtiError err;
2278 if (group_count_ptr == NULL) {
2279 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2280 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2281 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2282 }
2283 log_error(jvmti)("[%s] %s } %s - erroneous arg is group_count_ptr", curr_thread_name, func_name,
2284 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2285 }
2286 return JVMTI_ERROR_NULL_POINTER;
2287 }
2288 if (groups_ptr == NULL) {
2289 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2290 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2291 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2292 }
2293 log_error(jvmti)("[%s] %s } %s - erroneous arg is groups_ptr", curr_thread_name, func_name,
2294 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2295 }
2296 return JVMTI_ERROR_NULL_POINTER;
2297 }
2298
2299 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
2300 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2301 }
2302 err = jvmti_env->GetTopThreadGroups(group_count_ptr, groups_ptr);
2303 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2304 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2305 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2306 }
2307 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
2308 JvmtiUtil::error_name(err));
2309 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
2310 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
2311 }
2312 return err;
2313#endif // INCLUDE_JVMTI
2314}
2315
2316static jvmtiError JNICALL
2317jvmtiTrace_GetThreadGroupInfo(jvmtiEnv* env,
2318 jthreadGroup group,
2319 jvmtiThreadGroupInfo* info_ptr) {
2320
2321#if !INCLUDE_JVMTI
2322 return JVMTI_ERROR_NOT_AVAILABLE;
2323#else
2324 SafeResourceMark rm;
2325 jint trace_flags = JvmtiTrace::trace_flags(14);
2326 const char *func_name = NULL;
2327 const char *curr_thread_name = NULL;
2328 if (trace_flags) {
2329 func_name = JvmtiTrace::function_name(14);
2330 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
2331 }
2332 if(!JvmtiEnv::is_vm_live()) {
2333 if (trace_flags) {
2334 log_trace(jvmti)("[-] %s %s(%d)", func_name,
2335 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
2336 }
2337 return JVMTI_ERROR_WRONG_PHASE;
2338 }
2339 Thread* this_thread = Thread::current_or_null();
2340 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2341 if (trace_flags) {
2342 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
2343 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
2344 }
2345 return JVMTI_ERROR_UNATTACHED_THREAD;
2346 }
2347 JavaThread* current_thread = (JavaThread*)this_thread;
2348 ThreadInVMfromNative __tiv(current_thread);
2349 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetThreadGroupInfo , current_thread)
2350 debug_only(VMNativeEntryWrapper __vew;)
2351 CautiouslyPreserveExceptionMark __em(this_thread);
2352 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2353 if (!jvmti_env->is_valid()) {
2354 if (trace_flags) {
2355 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
2356 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
2357 }
2358 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2359 }
2360 jvmtiError err;
2361 if (info_ptr == NULL) {
2362 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2363 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2364 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2365 }
2366 log_error(jvmti)("[%s] %s } %s - erroneous arg is info_ptr", curr_thread_name, func_name,
2367 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2368 }
2369 return JVMTI_ERROR_NULL_POINTER;
2370 }
2371
2372 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
2373 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2374 }
2375 err = jvmti_env->GetThreadGroupInfo(group, info_ptr);
2376 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2377 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2378 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2379 }
2380 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
2381 JvmtiUtil::error_name(err));
2382 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
2383 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
2384 }
2385 return err;
2386#endif // INCLUDE_JVMTI
2387}
2388
2389static jvmtiError JNICALL
2390jvmtiTrace_GetThreadGroupChildren(jvmtiEnv* env,
2391 jthreadGroup group,
2392 jint* thread_count_ptr,
2393 jthread** threads_ptr,
2394 jint* group_count_ptr,
2395 jthreadGroup** groups_ptr) {
2396
2397#if !INCLUDE_JVMTI
2398 return JVMTI_ERROR_NOT_AVAILABLE;
2399#else
2400 SafeResourceMark rm;
2401 jint trace_flags = JvmtiTrace::trace_flags(15);
2402 const char *func_name = NULL;
2403 const char *curr_thread_name = NULL;
2404 if (trace_flags) {
2405 func_name = JvmtiTrace::function_name(15);
2406 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
2407 }
2408 if(!JvmtiEnv::is_vm_live()) {
2409 if (trace_flags) {
2410 log_trace(jvmti)("[-] %s %s(%d)", func_name,
2411 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
2412 }
2413 return JVMTI_ERROR_WRONG_PHASE;
2414 }
2415 Thread* this_thread = Thread::current_or_null();
2416 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2417 if (trace_flags) {
2418 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
2419 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
2420 }
2421 return JVMTI_ERROR_UNATTACHED_THREAD;
2422 }
2423 JavaThread* current_thread = (JavaThread*)this_thread;
2424 ThreadInVMfromNative __tiv(current_thread);
2425 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetThreadGroupChildren , current_thread)
2426 debug_only(VMNativeEntryWrapper __vew;)
2427 CautiouslyPreserveExceptionMark __em(this_thread);
2428 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2429 if (!jvmti_env->is_valid()) {
2430 if (trace_flags) {
2431 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
2432 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
2433 }
2434 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2435 }
2436 jvmtiError err;
2437 if (thread_count_ptr == NULL) {
2438 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2439 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2440 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2441 }
2442 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread_count_ptr", curr_thread_name, func_name,
2443 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2444 }
2445 return JVMTI_ERROR_NULL_POINTER;
2446 }
2447 if (threads_ptr == NULL) {
2448 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2449 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2450 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2451 }
2452 log_error(jvmti)("[%s] %s } %s - erroneous arg is threads_ptr", curr_thread_name, func_name,
2453 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2454 }
2455 return JVMTI_ERROR_NULL_POINTER;
2456 }
2457 if (group_count_ptr == NULL) {
2458 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2459 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2460 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2461 }
2462 log_error(jvmti)("[%s] %s } %s - erroneous arg is group_count_ptr", curr_thread_name, func_name,
2463 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2464 }
2465 return JVMTI_ERROR_NULL_POINTER;
2466 }
2467 if (groups_ptr == NULL) {
2468 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2469 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2470 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2471 }
2472 log_error(jvmti)("[%s] %s } %s - erroneous arg is groups_ptr", curr_thread_name, func_name,
2473 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2474 }
2475 return JVMTI_ERROR_NULL_POINTER;
2476 }
2477
2478 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
2479 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2480 }
2481 err = jvmti_env->GetThreadGroupChildren(group, thread_count_ptr, threads_ptr, group_count_ptr, groups_ptr);
2482 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2483 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2484 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2485 }
2486 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
2487 JvmtiUtil::error_name(err));
2488 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
2489 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
2490 }
2491 return err;
2492#endif // INCLUDE_JVMTI
2493}
2494
2495 //
2496 // Stack Frame functions
2497 //
2498
2499static jvmtiError JNICALL
2500jvmtiTrace_GetStackTrace(jvmtiEnv* env,
2501 jthread thread,
2502 jint start_depth,
2503 jint max_frame_count,
2504 jvmtiFrameInfo* frame_buffer,
2505 jint* count_ptr) {
2506
2507#if !INCLUDE_JVMTI
2508 return JVMTI_ERROR_NOT_AVAILABLE;
2509#else
2510 SafeResourceMark rm;
2511 jint trace_flags = JvmtiTrace::trace_flags(104);
2512 const char *func_name = NULL;
2513 const char *curr_thread_name = NULL;
2514 if (trace_flags) {
2515 func_name = JvmtiTrace::function_name(104);
2516 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
2517 }
2518 if(!JvmtiEnv::is_vm_live()) {
2519 if (trace_flags) {
2520 log_trace(jvmti)("[-] %s %s(%d)", func_name,
2521 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
2522 }
2523 return JVMTI_ERROR_WRONG_PHASE;
2524 }
2525 Thread* this_thread = Thread::current_or_null();
2526 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2527 if (trace_flags) {
2528 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
2529 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
2530 }
2531 return JVMTI_ERROR_UNATTACHED_THREAD;
2532 }
2533 JavaThread* current_thread = (JavaThread*)this_thread;
2534 ThreadInVMfromNative __tiv(current_thread);
2535 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetStackTrace , current_thread)
2536 debug_only(VMNativeEntryWrapper __vew;)
2537 CautiouslyPreserveExceptionMark __em(this_thread);
2538 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2539 if (!jvmti_env->is_valid()) {
2540 if (trace_flags) {
2541 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
2542 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
2543 }
2544 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2545 }
2546 jvmtiError err;
2547 JavaThread* java_thread = NULL;
2548 ThreadsListHandle tlh(this_thread);
2549 if (thread == NULL) {
2550 java_thread = current_thread;
2551 } else {
2552 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
2553 if (err != JVMTI_ERROR_NONE) {
2554 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2555 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2556 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2557 }
2558 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
2559 JvmtiUtil::error_name(err), p2i(thread));
2560 }
2561 return err;
2562 }
2563 }
2564 if (max_frame_count < 0) {
2565 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2566 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2567 log_trace(jvmti)("[%s] %s { thread=%s start_depth=" INT32_FORMAT "", curr_thread_name, func_name,
2568 JvmtiTrace::safe_get_thread_name(java_thread), start_depth);
2569 }
2570 log_error(jvmti)("[%s] %s } %s - erroneous arg is max_frame_count", curr_thread_name, func_name,
2571 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT));
2572 }
2573 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2574 }
2575 if (frame_buffer == NULL) {
2576 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2577 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2578 log_trace(jvmti)("[%s] %s { thread=%s start_depth=" INT32_FORMAT " max_frame_count=" INT32_FORMAT "", curr_thread_name, func_name,
2579 JvmtiTrace::safe_get_thread_name(java_thread), start_depth, max_frame_count);
2580 }
2581 log_error(jvmti)("[%s] %s } %s - erroneous arg is frame_buffer", curr_thread_name, func_name,
2582 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2583 }
2584 return JVMTI_ERROR_NULL_POINTER;
2585 }
2586 if (count_ptr == NULL) {
2587 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2588 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2589 log_trace(jvmti)("[%s] %s { thread=%s start_depth=" INT32_FORMAT " max_frame_count=" INT32_FORMAT "", curr_thread_name, func_name,
2590 JvmtiTrace::safe_get_thread_name(java_thread), start_depth, max_frame_count);
2591 }
2592 log_error(jvmti)("[%s] %s } %s - erroneous arg is count_ptr", curr_thread_name, func_name,
2593 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2594 }
2595 return JVMTI_ERROR_NULL_POINTER;
2596 }
2597
2598 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
2599 log_trace(jvmti)("[%s] %s { thread=%s start_depth=" INT32_FORMAT " max_frame_count=" INT32_FORMAT "", curr_thread_name, func_name,
2600 JvmtiTrace::safe_get_thread_name(java_thread), start_depth, max_frame_count);
2601 }
2602 err = jvmti_env->GetStackTrace(java_thread, start_depth, max_frame_count, frame_buffer, count_ptr);
2603 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2604 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2605 log_trace(jvmti)("[%s] %s { thread=%s start_depth=" INT32_FORMAT " max_frame_count=" INT32_FORMAT "", curr_thread_name, func_name,
2606 JvmtiTrace::safe_get_thread_name(java_thread), start_depth, max_frame_count);
2607 }
2608 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
2609 JvmtiUtil::error_name(err));
2610 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
2611 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
2612 }
2613 return err;
2614#endif // INCLUDE_JVMTI
2615}
2616
2617static jvmtiError JNICALL
2618jvmtiTrace_GetAllStackTraces(jvmtiEnv* env,
2619 jint max_frame_count,
2620 jvmtiStackInfo** stack_info_ptr,
2621 jint* thread_count_ptr) {
2622
2623#if !INCLUDE_JVMTI
2624 return JVMTI_ERROR_NOT_AVAILABLE;
2625#else
2626 SafeResourceMark rm;
2627 jint trace_flags = JvmtiTrace::trace_flags(100);
2628 const char *func_name = NULL;
2629 const char *curr_thread_name = NULL;
2630 if (trace_flags) {
2631 func_name = JvmtiTrace::function_name(100);
2632 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
2633 }
2634 if(!JvmtiEnv::is_vm_live()) {
2635 if (trace_flags) {
2636 log_trace(jvmti)("[-] %s %s(%d)", func_name,
2637 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
2638 }
2639 return JVMTI_ERROR_WRONG_PHASE;
2640 }
2641 Thread* this_thread = Thread::current_or_null();
2642 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2643 if (trace_flags) {
2644 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
2645 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
2646 }
2647 return JVMTI_ERROR_UNATTACHED_THREAD;
2648 }
2649 JavaThread* current_thread = (JavaThread*)this_thread;
2650 ThreadInVMfromNative __tiv(current_thread);
2651 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetAllStackTraces , current_thread)
2652 debug_only(VMNativeEntryWrapper __vew;)
2653 CautiouslyPreserveExceptionMark __em(this_thread);
2654 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2655 if (!jvmti_env->is_valid()) {
2656 if (trace_flags) {
2657 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
2658 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
2659 }
2660 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2661 }
2662 jvmtiError err;
2663 if (max_frame_count < 0) {
2664 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2665 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2666 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2667 }
2668 log_error(jvmti)("[%s] %s } %s - erroneous arg is max_frame_count", curr_thread_name, func_name,
2669 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT));
2670 }
2671 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2672 }
2673 if (stack_info_ptr == NULL) {
2674 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2675 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2676 log_trace(jvmti)("[%s] %s { max_frame_count=" INT32_FORMAT "", curr_thread_name, func_name, max_frame_count);
2677 }
2678 log_error(jvmti)("[%s] %s } %s - erroneous arg is stack_info_ptr", curr_thread_name, func_name,
2679 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2680 }
2681 return JVMTI_ERROR_NULL_POINTER;
2682 }
2683 if (thread_count_ptr == NULL) {
2684 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2685 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2686 log_trace(jvmti)("[%s] %s { max_frame_count=" INT32_FORMAT "", curr_thread_name, func_name, max_frame_count);
2687 }
2688 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread_count_ptr", curr_thread_name, func_name,
2689 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2690 }
2691 return JVMTI_ERROR_NULL_POINTER;
2692 }
2693
2694 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
2695 log_trace(jvmti)("[%s] %s { max_frame_count=" INT32_FORMAT "", curr_thread_name, func_name, max_frame_count);
2696 }
2697 err = jvmti_env->GetAllStackTraces(max_frame_count, stack_info_ptr, thread_count_ptr);
2698 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2699 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2700 log_trace(jvmti)("[%s] %s { max_frame_count=" INT32_FORMAT "", curr_thread_name, func_name, max_frame_count);
2701 }
2702 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
2703 JvmtiUtil::error_name(err));
2704 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
2705 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
2706 }
2707 return err;
2708#endif // INCLUDE_JVMTI
2709}
2710
2711static jvmtiError JNICALL
2712jvmtiTrace_GetThreadListStackTraces(jvmtiEnv* env,
2713 jint thread_count,
2714 const jthread* thread_list,
2715 jint max_frame_count,
2716 jvmtiStackInfo** stack_info_ptr) {
2717
2718#if !INCLUDE_JVMTI
2719 return JVMTI_ERROR_NOT_AVAILABLE;
2720#else
2721 SafeResourceMark rm;
2722 jint trace_flags = JvmtiTrace::trace_flags(101);
2723 const char *func_name = NULL;
2724 const char *curr_thread_name = NULL;
2725 if (trace_flags) {
2726 func_name = JvmtiTrace::function_name(101);
2727 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
2728 }
2729 if(!JvmtiEnv::is_vm_live()) {
2730 if (trace_flags) {
2731 log_trace(jvmti)("[-] %s %s(%d)", func_name,
2732 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
2733 }
2734 return JVMTI_ERROR_WRONG_PHASE;
2735 }
2736 Thread* this_thread = Thread::current_or_null();
2737 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2738 if (trace_flags) {
2739 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
2740 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
2741 }
2742 return JVMTI_ERROR_UNATTACHED_THREAD;
2743 }
2744 JavaThread* current_thread = (JavaThread*)this_thread;
2745 ThreadInVMfromNative __tiv(current_thread);
2746 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetThreadListStackTraces , current_thread)
2747 debug_only(VMNativeEntryWrapper __vew;)
2748 CautiouslyPreserveExceptionMark __em(this_thread);
2749 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2750 if (!jvmti_env->is_valid()) {
2751 if (trace_flags) {
2752 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
2753 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
2754 }
2755 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2756 }
2757 jvmtiError err;
2758 if (thread_count < 0) {
2759 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2760 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2761 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2762 }
2763 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread_count", curr_thread_name, func_name,
2764 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT));
2765 }
2766 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2767 }
2768 if (thread_list == NULL) {
2769 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2770 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2771 log_trace(jvmti)("[%s] %s { thread_count=" INT32_FORMAT "", curr_thread_name, func_name, thread_count);
2772 }
2773 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread_list", curr_thread_name, func_name,
2774 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2775 }
2776 return JVMTI_ERROR_NULL_POINTER;
2777 }
2778 if (max_frame_count < 0) {
2779 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2780 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2781 log_trace(jvmti)("[%s] %s { thread_count=" INT32_FORMAT " thread_list=" PTR_FORMAT "", curr_thread_name, func_name, thread_count,
2782 p2i(thread_list)
2783 );
2784 }
2785 log_error(jvmti)("[%s] %s } %s - erroneous arg is max_frame_count", curr_thread_name, func_name,
2786 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT));
2787 }
2788 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
2789 }
2790 if (stack_info_ptr == NULL) {
2791 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2792 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2793 log_trace(jvmti)("[%s] %s { thread_count=" INT32_FORMAT " thread_list=" PTR_FORMAT " max_frame_count=" INT32_FORMAT "", curr_thread_name, func_name, thread_count,
2794 p2i(thread_list)
2795 , max_frame_count);
2796 }
2797 log_error(jvmti)("[%s] %s } %s - erroneous arg is stack_info_ptr", curr_thread_name, func_name,
2798 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2799 }
2800 return JVMTI_ERROR_NULL_POINTER;
2801 }
2802
2803 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
2804 log_trace(jvmti)("[%s] %s { thread_count=" INT32_FORMAT " thread_list=" PTR_FORMAT " max_frame_count=" INT32_FORMAT "", curr_thread_name, func_name, thread_count,
2805 p2i(thread_list)
2806 , max_frame_count);
2807 }
2808 err = jvmti_env->GetThreadListStackTraces(thread_count, thread_list, max_frame_count, stack_info_ptr);
2809 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2810 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2811 log_trace(jvmti)("[%s] %s { thread_count=" INT32_FORMAT " thread_list=" PTR_FORMAT " max_frame_count=" INT32_FORMAT "", curr_thread_name, func_name, thread_count,
2812 p2i(thread_list)
2813 , max_frame_count);
2814 }
2815 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
2816 JvmtiUtil::error_name(err));
2817 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
2818 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
2819 }
2820 return err;
2821#endif // INCLUDE_JVMTI
2822}
2823
2824static jvmtiError JNICALL
2825jvmtiTrace_GetFrameCount(jvmtiEnv* env,
2826 jthread thread,
2827 jint* count_ptr) {
2828
2829#if !INCLUDE_JVMTI
2830 return JVMTI_ERROR_NOT_AVAILABLE;
2831#else
2832 SafeResourceMark rm;
2833 jint trace_flags = JvmtiTrace::trace_flags(16);
2834 const char *func_name = NULL;
2835 const char *curr_thread_name = NULL;
2836 if (trace_flags) {
2837 func_name = JvmtiTrace::function_name(16);
2838 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
2839 }
2840 if(!JvmtiEnv::is_vm_live()) {
2841 if (trace_flags) {
2842 log_trace(jvmti)("[-] %s %s(%d)", func_name,
2843 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
2844 }
2845 return JVMTI_ERROR_WRONG_PHASE;
2846 }
2847 Thread* this_thread = Thread::current_or_null();
2848 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2849 if (trace_flags) {
2850 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
2851 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
2852 }
2853 return JVMTI_ERROR_UNATTACHED_THREAD;
2854 }
2855 JavaThread* current_thread = (JavaThread*)this_thread;
2856 ThreadInVMfromNative __tiv(current_thread);
2857 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetFrameCount , current_thread)
2858 debug_only(VMNativeEntryWrapper __vew;)
2859 CautiouslyPreserveExceptionMark __em(this_thread);
2860 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2861 if (!jvmti_env->is_valid()) {
2862 if (trace_flags) {
2863 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
2864 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
2865 }
2866 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2867 }
2868 jvmtiError err;
2869 JavaThread* java_thread = NULL;
2870 ThreadsListHandle tlh(this_thread);
2871 if (thread == NULL) {
2872 java_thread = current_thread;
2873 } else {
2874 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
2875 if (err != JVMTI_ERROR_NONE) {
2876 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2877 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2878 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2879 }
2880 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
2881 JvmtiUtil::error_name(err), p2i(thread));
2882 }
2883 return err;
2884 }
2885 }
2886 if (count_ptr == NULL) {
2887 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2888 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2889 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
2890 JvmtiTrace::safe_get_thread_name(java_thread));
2891 }
2892 log_error(jvmti)("[%s] %s } %s - erroneous arg is count_ptr", curr_thread_name, func_name,
2893 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
2894 }
2895 return JVMTI_ERROR_NULL_POINTER;
2896 }
2897
2898 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
2899 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
2900 JvmtiTrace::safe_get_thread_name(java_thread));
2901 }
2902 err = jvmti_env->GetFrameCount(java_thread, count_ptr);
2903 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2904 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2905 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
2906 JvmtiTrace::safe_get_thread_name(java_thread));
2907 }
2908 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
2909 JvmtiUtil::error_name(err));
2910 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
2911 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
2912 }
2913 return err;
2914#endif // INCLUDE_JVMTI
2915}
2916
2917static jvmtiError JNICALL
2918jvmtiTrace_PopFrame(jvmtiEnv* env,
2919 jthread thread) {
2920
2921#if !INCLUDE_JVMTI
2922 return JVMTI_ERROR_NOT_AVAILABLE;
2923#else
2924 SafeResourceMark rm;
2925 jint trace_flags = JvmtiTrace::trace_flags(80);
2926 const char *func_name = NULL;
2927 const char *curr_thread_name = NULL;
2928 if (trace_flags) {
2929 func_name = JvmtiTrace::function_name(80);
2930 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
2931 }
2932 if(!JvmtiEnv::is_vm_live()) {
2933 if (trace_flags) {
2934 log_trace(jvmti)("[-] %s %s(%d)", func_name,
2935 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
2936 }
2937 return JVMTI_ERROR_WRONG_PHASE;
2938 }
2939 Thread* this_thread = Thread::current_or_null();
2940 if (this_thread == NULL || !this_thread->is_Java_thread()) {
2941 if (trace_flags) {
2942 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
2943 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
2944 }
2945 return JVMTI_ERROR_UNATTACHED_THREAD;
2946 }
2947 JavaThread* current_thread = (JavaThread*)this_thread;
2948 ThreadInVMfromNative __tiv(current_thread);
2949 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_PopFrame , current_thread)
2950 debug_only(VMNativeEntryWrapper __vew;)
2951 CautiouslyPreserveExceptionMark __em(this_thread);
2952 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
2953 if (!jvmti_env->is_valid()) {
2954 if (trace_flags) {
2955 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
2956 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
2957 }
2958 return JVMTI_ERROR_INVALID_ENVIRONMENT;
2959 }
2960
2961 if (jvmti_env->get_capabilities()->can_pop_frame == 0) {
2962 if (trace_flags) {
2963 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
2964 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
2965 }
2966 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
2967 }
2968 jvmtiError err;
2969 JavaThread* java_thread = NULL;
2970 ThreadsListHandle tlh(this_thread);
2971 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
2972 if (err != JVMTI_ERROR_NONE) {
2973 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2974 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2975 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
2976 }
2977 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
2978 JvmtiUtil::error_name(err), p2i(thread));
2979 }
2980 return err;
2981 }
2982
2983 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
2984 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
2985 JvmtiTrace::safe_get_thread_name(java_thread));
2986 }
2987 err = jvmti_env->PopFrame(java_thread);
2988 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
2989 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
2990 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
2991 JvmtiTrace::safe_get_thread_name(java_thread));
2992 }
2993 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
2994 JvmtiUtil::error_name(err));
2995 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
2996 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
2997 }
2998 return err;
2999#endif // INCLUDE_JVMTI
3000}
3001
3002static jvmtiError JNICALL
3003jvmtiTrace_GetFrameLocation(jvmtiEnv* env,
3004 jthread thread,
3005 jint depth,
3006 jmethodID* method_ptr,
3007 jlocation* location_ptr) {
3008
3009#if !INCLUDE_JVMTI
3010 return JVMTI_ERROR_NOT_AVAILABLE;
3011#else
3012 SafeResourceMark rm;
3013 jint trace_flags = JvmtiTrace::trace_flags(19);
3014 const char *func_name = NULL;
3015 const char *curr_thread_name = NULL;
3016 if (trace_flags) {
3017 func_name = JvmtiTrace::function_name(19);
3018 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
3019 }
3020 if(!JvmtiEnv::is_vm_live()) {
3021 if (trace_flags) {
3022 log_trace(jvmti)("[-] %s %s(%d)", func_name,
3023 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
3024 }
3025 return JVMTI_ERROR_WRONG_PHASE;
3026 }
3027 Thread* this_thread = Thread::current_or_null();
3028 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3029 if (trace_flags) {
3030 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
3031 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
3032 }
3033 return JVMTI_ERROR_UNATTACHED_THREAD;
3034 }
3035 JavaThread* current_thread = (JavaThread*)this_thread;
3036 ThreadInVMfromNative __tiv(current_thread);
3037 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetFrameLocation , current_thread)
3038 debug_only(VMNativeEntryWrapper __vew;)
3039 CautiouslyPreserveExceptionMark __em(this_thread);
3040 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3041 if (!jvmti_env->is_valid()) {
3042 if (trace_flags) {
3043 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
3044 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
3045 }
3046 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3047 }
3048 jvmtiError err;
3049 JavaThread* java_thread = NULL;
3050 ThreadsListHandle tlh(this_thread);
3051 if (thread == NULL) {
3052 java_thread = current_thread;
3053 } else {
3054 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
3055 if (err != JVMTI_ERROR_NONE) {
3056 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3057 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3058 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
3059 }
3060 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
3061 JvmtiUtil::error_name(err), p2i(thread));
3062 }
3063 return err;
3064 }
3065 }
3066
3067 if (depth < 0) {
3068 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3069 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3070 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
3071 JvmtiTrace::safe_get_thread_name(java_thread));
3072 }
3073 log_error(jvmti)("[%s] %s } %s - erroneous arg is depth - negative depth - jthread = " INT32_FORMAT "", curr_thread_name, func_name,
3074 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT), depth);
3075 }
3076 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
3077 }
3078 if (method_ptr == NULL) {
3079 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3080 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3081 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d", curr_thread_name, func_name,
3082 JvmtiTrace::safe_get_thread_name(java_thread), depth);
3083 }
3084 log_error(jvmti)("[%s] %s } %s - erroneous arg is method_ptr", curr_thread_name, func_name,
3085 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
3086 }
3087 return JVMTI_ERROR_NULL_POINTER;
3088 }
3089 if (location_ptr == NULL) {
3090 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3091 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3092 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d", curr_thread_name, func_name,
3093 JvmtiTrace::safe_get_thread_name(java_thread), depth);
3094 }
3095 log_error(jvmti)("[%s] %s } %s - erroneous arg is location_ptr", curr_thread_name, func_name,
3096 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
3097 }
3098 return JVMTI_ERROR_NULL_POINTER;
3099 }
3100
3101 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
3102 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d", curr_thread_name, func_name,
3103 JvmtiTrace::safe_get_thread_name(java_thread), depth);
3104 }
3105 err = jvmti_env->GetFrameLocation(java_thread, depth, method_ptr, location_ptr);
3106 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3107 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3108 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d", curr_thread_name, func_name,
3109 JvmtiTrace::safe_get_thread_name(java_thread), depth);
3110 }
3111 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
3112 JvmtiUtil::error_name(err));
3113 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
3114 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
3115 }
3116 return err;
3117#endif // INCLUDE_JVMTI
3118}
3119
3120static jvmtiError JNICALL
3121jvmtiTrace_NotifyFramePop(jvmtiEnv* env,
3122 jthread thread,
3123 jint depth) {
3124
3125#if !INCLUDE_JVMTI
3126 return JVMTI_ERROR_NOT_AVAILABLE;
3127#else
3128 SafeResourceMark rm;
3129 jint trace_flags = JvmtiTrace::trace_flags(20);
3130 const char *func_name = NULL;
3131 const char *curr_thread_name = NULL;
3132 if (trace_flags) {
3133 func_name = JvmtiTrace::function_name(20);
3134 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
3135 }
3136 if(!JvmtiEnv::is_vm_live()) {
3137 if (trace_flags) {
3138 log_trace(jvmti)("[-] %s %s(%d)", func_name,
3139 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
3140 }
3141 return JVMTI_ERROR_WRONG_PHASE;
3142 }
3143 Thread* this_thread = Thread::current_or_null();
3144 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3145 if (trace_flags) {
3146 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
3147 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
3148 }
3149 return JVMTI_ERROR_UNATTACHED_THREAD;
3150 }
3151 JavaThread* current_thread = (JavaThread*)this_thread;
3152 ThreadInVMfromNative __tiv(current_thread);
3153 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_NotifyFramePop , current_thread)
3154 debug_only(VMNativeEntryWrapper __vew;)
3155 CautiouslyPreserveExceptionMark __em(this_thread);
3156 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3157 if (!jvmti_env->is_valid()) {
3158 if (trace_flags) {
3159 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
3160 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
3161 }
3162 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3163 }
3164
3165 if (jvmti_env->get_capabilities()->can_generate_frame_pop_events == 0) {
3166 if (trace_flags) {
3167 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
3168 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
3169 }
3170 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
3171 }
3172 jvmtiError err;
3173 JavaThread* java_thread = NULL;
3174 ThreadsListHandle tlh(this_thread);
3175 if (thread == NULL) {
3176 java_thread = current_thread;
3177 } else {
3178 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
3179 if (err != JVMTI_ERROR_NONE) {
3180 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3181 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3182 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
3183 }
3184 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
3185 JvmtiUtil::error_name(err), p2i(thread));
3186 }
3187 return err;
3188 }
3189 }
3190
3191 if (depth < 0) {
3192 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3193 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3194 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
3195 JvmtiTrace::safe_get_thread_name(java_thread));
3196 }
3197 log_error(jvmti)("[%s] %s } %s - erroneous arg is depth - negative depth - jthread = " INT32_FORMAT "", curr_thread_name, func_name,
3198 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT), depth);
3199 }
3200 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
3201 }
3202
3203 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
3204 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d", curr_thread_name, func_name,
3205 JvmtiTrace::safe_get_thread_name(java_thread), depth);
3206 }
3207 err = jvmti_env->NotifyFramePop(java_thread, depth);
3208 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3209 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3210 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d", curr_thread_name, func_name,
3211 JvmtiTrace::safe_get_thread_name(java_thread), depth);
3212 }
3213 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
3214 JvmtiUtil::error_name(err));
3215 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
3216 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
3217 }
3218 return err;
3219#endif // INCLUDE_JVMTI
3220}
3221
3222 //
3223 // Force Early Return functions
3224 //
3225
3226static jvmtiError JNICALL
3227jvmtiTrace_ForceEarlyReturnObject(jvmtiEnv* env,
3228 jthread thread,
3229 jobject value) {
3230
3231#if !INCLUDE_JVMTI
3232 return JVMTI_ERROR_NOT_AVAILABLE;
3233#else
3234 SafeResourceMark rm;
3235 jint trace_flags = JvmtiTrace::trace_flags(81);
3236 const char *func_name = NULL;
3237 const char *curr_thread_name = NULL;
3238 if (trace_flags) {
3239 func_name = JvmtiTrace::function_name(81);
3240 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
3241 }
3242 if(!JvmtiEnv::is_vm_live()) {
3243 if (trace_flags) {
3244 log_trace(jvmti)("[-] %s %s(%d)", func_name,
3245 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
3246 }
3247 return JVMTI_ERROR_WRONG_PHASE;
3248 }
3249 Thread* this_thread = Thread::current_or_null();
3250 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3251 if (trace_flags) {
3252 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
3253 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
3254 }
3255 return JVMTI_ERROR_UNATTACHED_THREAD;
3256 }
3257 JavaThread* current_thread = (JavaThread*)this_thread;
3258 ThreadInVMfromNative __tiv(current_thread);
3259 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_ForceEarlyReturnObject , current_thread)
3260 debug_only(VMNativeEntryWrapper __vew;)
3261 CautiouslyPreserveExceptionMark __em(this_thread);
3262 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3263 if (!jvmti_env->is_valid()) {
3264 if (trace_flags) {
3265 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
3266 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
3267 }
3268 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3269 }
3270
3271 if (jvmti_env->get_capabilities()->can_force_early_return == 0) {
3272 if (trace_flags) {
3273 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
3274 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
3275 }
3276 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
3277 }
3278 jvmtiError err;
3279 JavaThread* java_thread = NULL;
3280 ThreadsListHandle tlh(this_thread);
3281 if (thread == NULL) {
3282 java_thread = current_thread;
3283 } else {
3284 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
3285 if (err != JVMTI_ERROR_NONE) {
3286 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3287 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3288 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
3289 }
3290 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
3291 JvmtiUtil::error_name(err), p2i(thread));
3292 }
3293 return err;
3294 }
3295 }
3296
3297 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
3298 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
3299 JvmtiTrace::safe_get_thread_name(java_thread));
3300 }
3301 err = jvmti_env->ForceEarlyReturnObject(java_thread, value);
3302 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3303 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3304 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
3305 JvmtiTrace::safe_get_thread_name(java_thread));
3306 }
3307 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
3308 JvmtiUtil::error_name(err));
3309 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
3310 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
3311 }
3312 return err;
3313#endif // INCLUDE_JVMTI
3314}
3315
3316static jvmtiError JNICALL
3317jvmtiTrace_ForceEarlyReturnInt(jvmtiEnv* env,
3318 jthread thread,
3319 jint value) {
3320
3321#if !INCLUDE_JVMTI
3322 return JVMTI_ERROR_NOT_AVAILABLE;
3323#else
3324 SafeResourceMark rm;
3325 jint trace_flags = JvmtiTrace::trace_flags(82);
3326 const char *func_name = NULL;
3327 const char *curr_thread_name = NULL;
3328 if (trace_flags) {
3329 func_name = JvmtiTrace::function_name(82);
3330 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
3331 }
3332 if(!JvmtiEnv::is_vm_live()) {
3333 if (trace_flags) {
3334 log_trace(jvmti)("[-] %s %s(%d)", func_name,
3335 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
3336 }
3337 return JVMTI_ERROR_WRONG_PHASE;
3338 }
3339 Thread* this_thread = Thread::current_or_null();
3340 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3341 if (trace_flags) {
3342 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
3343 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
3344 }
3345 return JVMTI_ERROR_UNATTACHED_THREAD;
3346 }
3347 JavaThread* current_thread = (JavaThread*)this_thread;
3348 ThreadInVMfromNative __tiv(current_thread);
3349 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_ForceEarlyReturnInt , current_thread)
3350 debug_only(VMNativeEntryWrapper __vew;)
3351 CautiouslyPreserveExceptionMark __em(this_thread);
3352 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3353 if (!jvmti_env->is_valid()) {
3354 if (trace_flags) {
3355 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
3356 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
3357 }
3358 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3359 }
3360
3361 if (jvmti_env->get_capabilities()->can_force_early_return == 0) {
3362 if (trace_flags) {
3363 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
3364 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
3365 }
3366 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
3367 }
3368 jvmtiError err;
3369 JavaThread* java_thread = NULL;
3370 ThreadsListHandle tlh(this_thread);
3371 if (thread == NULL) {
3372 java_thread = current_thread;
3373 } else {
3374 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
3375 if (err != JVMTI_ERROR_NONE) {
3376 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3377 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3378 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
3379 }
3380 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
3381 JvmtiUtil::error_name(err), p2i(thread));
3382 }
3383 return err;
3384 }
3385 }
3386
3387 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
3388 log_trace(jvmti)("[%s] %s { thread=%s value=" INT32_FORMAT "", curr_thread_name, func_name,
3389 JvmtiTrace::safe_get_thread_name(java_thread), value);
3390 }
3391 err = jvmti_env->ForceEarlyReturnInt(java_thread, value);
3392 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3393 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3394 log_trace(jvmti)("[%s] %s { thread=%s value=" INT32_FORMAT "", curr_thread_name, func_name,
3395 JvmtiTrace::safe_get_thread_name(java_thread), value);
3396 }
3397 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
3398 JvmtiUtil::error_name(err));
3399 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
3400 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
3401 }
3402 return err;
3403#endif // INCLUDE_JVMTI
3404}
3405
3406static jvmtiError JNICALL
3407jvmtiTrace_ForceEarlyReturnLong(jvmtiEnv* env,
3408 jthread thread,
3409 jlong value) {
3410
3411#if !INCLUDE_JVMTI
3412 return JVMTI_ERROR_NOT_AVAILABLE;
3413#else
3414 SafeResourceMark rm;
3415 jint trace_flags = JvmtiTrace::trace_flags(83);
3416 const char *func_name = NULL;
3417 const char *curr_thread_name = NULL;
3418 if (trace_flags) {
3419 func_name = JvmtiTrace::function_name(83);
3420 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
3421 }
3422 if(!JvmtiEnv::is_vm_live()) {
3423 if (trace_flags) {
3424 log_trace(jvmti)("[-] %s %s(%d)", func_name,
3425 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
3426 }
3427 return JVMTI_ERROR_WRONG_PHASE;
3428 }
3429 Thread* this_thread = Thread::current_or_null();
3430 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3431 if (trace_flags) {
3432 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
3433 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
3434 }
3435 return JVMTI_ERROR_UNATTACHED_THREAD;
3436 }
3437 JavaThread* current_thread = (JavaThread*)this_thread;
3438 ThreadInVMfromNative __tiv(current_thread);
3439 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_ForceEarlyReturnLong , current_thread)
3440 debug_only(VMNativeEntryWrapper __vew;)
3441 CautiouslyPreserveExceptionMark __em(this_thread);
3442 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3443 if (!jvmti_env->is_valid()) {
3444 if (trace_flags) {
3445 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
3446 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
3447 }
3448 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3449 }
3450
3451 if (jvmti_env->get_capabilities()->can_force_early_return == 0) {
3452 if (trace_flags) {
3453 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
3454 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
3455 }
3456 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
3457 }
3458 jvmtiError err;
3459 JavaThread* java_thread = NULL;
3460 ThreadsListHandle tlh(this_thread);
3461 if (thread == NULL) {
3462 java_thread = current_thread;
3463 } else {
3464 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
3465 if (err != JVMTI_ERROR_NONE) {
3466 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3467 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3468 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
3469 }
3470 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
3471 JvmtiUtil::error_name(err), p2i(thread));
3472 }
3473 return err;
3474 }
3475 }
3476
3477 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
3478 log_trace(jvmti)("[%s] %s { thread=%s value=" JLONG_FORMAT "", curr_thread_name, func_name,
3479 JvmtiTrace::safe_get_thread_name(java_thread), value);
3480 }
3481 err = jvmti_env->ForceEarlyReturnLong(java_thread, value);
3482 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3483 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3484 log_trace(jvmti)("[%s] %s { thread=%s value=" JLONG_FORMAT "", curr_thread_name, func_name,
3485 JvmtiTrace::safe_get_thread_name(java_thread), value);
3486 }
3487 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
3488 JvmtiUtil::error_name(err));
3489 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
3490 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
3491 }
3492 return err;
3493#endif // INCLUDE_JVMTI
3494}
3495
3496static jvmtiError JNICALL
3497jvmtiTrace_ForceEarlyReturnFloat(jvmtiEnv* env,
3498 jthread thread,
3499 jfloat value) {
3500
3501#if !INCLUDE_JVMTI
3502 return JVMTI_ERROR_NOT_AVAILABLE;
3503#else
3504 SafeResourceMark rm;
3505 jint trace_flags = JvmtiTrace::trace_flags(84);
3506 const char *func_name = NULL;
3507 const char *curr_thread_name = NULL;
3508 if (trace_flags) {
3509 func_name = JvmtiTrace::function_name(84);
3510 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
3511 }
3512 if(!JvmtiEnv::is_vm_live()) {
3513 if (trace_flags) {
3514 log_trace(jvmti)("[-] %s %s(%d)", func_name,
3515 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
3516 }
3517 return JVMTI_ERROR_WRONG_PHASE;
3518 }
3519 Thread* this_thread = Thread::current_or_null();
3520 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3521 if (trace_flags) {
3522 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
3523 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
3524 }
3525 return JVMTI_ERROR_UNATTACHED_THREAD;
3526 }
3527 JavaThread* current_thread = (JavaThread*)this_thread;
3528 ThreadInVMfromNative __tiv(current_thread);
3529 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_ForceEarlyReturnFloat , 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 if (trace_flags) {
3535 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
3536 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
3537 }
3538 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3539 }
3540
3541 if (jvmti_env->get_capabilities()->can_force_early_return == 0) {
3542 if (trace_flags) {
3543 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
3544 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
3545 }
3546 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
3547 }
3548 jvmtiError err;
3549 JavaThread* java_thread = NULL;
3550 ThreadsListHandle tlh(this_thread);
3551 if (thread == NULL) {
3552 java_thread = current_thread;
3553 } else {
3554 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
3555 if (err != JVMTI_ERROR_NONE) {
3556 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3557 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3558 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
3559 }
3560 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
3561 JvmtiUtil::error_name(err), p2i(thread));
3562 }
3563 return err;
3564 }
3565 }
3566
3567 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
3568 log_trace(jvmti)("[%s] %s { thread=%s value=%f", curr_thread_name, func_name,
3569 JvmtiTrace::safe_get_thread_name(java_thread), value);
3570 }
3571 err = jvmti_env->ForceEarlyReturnFloat(java_thread, value);
3572 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3573 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3574 log_trace(jvmti)("[%s] %s { thread=%s value=%f", curr_thread_name, func_name,
3575 JvmtiTrace::safe_get_thread_name(java_thread), value);
3576 }
3577 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
3578 JvmtiUtil::error_name(err));
3579 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
3580 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
3581 }
3582 return err;
3583#endif // INCLUDE_JVMTI
3584}
3585
3586static jvmtiError JNICALL
3587jvmtiTrace_ForceEarlyReturnDouble(jvmtiEnv* env,
3588 jthread thread,
3589 jdouble value) {
3590
3591#if !INCLUDE_JVMTI
3592 return JVMTI_ERROR_NOT_AVAILABLE;
3593#else
3594 SafeResourceMark rm;
3595 jint trace_flags = JvmtiTrace::trace_flags(85);
3596 const char *func_name = NULL;
3597 const char *curr_thread_name = NULL;
3598 if (trace_flags) {
3599 func_name = JvmtiTrace::function_name(85);
3600 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
3601 }
3602 if(!JvmtiEnv::is_vm_live()) {
3603 if (trace_flags) {
3604 log_trace(jvmti)("[-] %s %s(%d)", func_name,
3605 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
3606 }
3607 return JVMTI_ERROR_WRONG_PHASE;
3608 }
3609 Thread* this_thread = Thread::current_or_null();
3610 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3611 if (trace_flags) {
3612 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
3613 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
3614 }
3615 return JVMTI_ERROR_UNATTACHED_THREAD;
3616 }
3617 JavaThread* current_thread = (JavaThread*)this_thread;
3618 ThreadInVMfromNative __tiv(current_thread);
3619 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_ForceEarlyReturnDouble , current_thread)
3620 debug_only(VMNativeEntryWrapper __vew;)
3621 CautiouslyPreserveExceptionMark __em(this_thread);
3622 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3623 if (!jvmti_env->is_valid()) {
3624 if (trace_flags) {
3625 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
3626 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
3627 }
3628 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3629 }
3630
3631 if (jvmti_env->get_capabilities()->can_force_early_return == 0) {
3632 if (trace_flags) {
3633 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
3634 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
3635 }
3636 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
3637 }
3638 jvmtiError err;
3639 JavaThread* java_thread = NULL;
3640 ThreadsListHandle tlh(this_thread);
3641 if (thread == NULL) {
3642 java_thread = current_thread;
3643 } else {
3644 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
3645 if (err != JVMTI_ERROR_NONE) {
3646 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3647 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3648 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
3649 }
3650 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
3651 JvmtiUtil::error_name(err), p2i(thread));
3652 }
3653 return err;
3654 }
3655 }
3656
3657 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
3658 log_trace(jvmti)("[%s] %s { thread=%s value=%f", curr_thread_name, func_name,
3659 JvmtiTrace::safe_get_thread_name(java_thread), value);
3660 }
3661 err = jvmti_env->ForceEarlyReturnDouble(java_thread, value);
3662 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3663 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3664 log_trace(jvmti)("[%s] %s { thread=%s value=%f", curr_thread_name, func_name,
3665 JvmtiTrace::safe_get_thread_name(java_thread), value);
3666 }
3667 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
3668 JvmtiUtil::error_name(err));
3669 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
3670 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
3671 }
3672 return err;
3673#endif // INCLUDE_JVMTI
3674}
3675
3676static jvmtiError JNICALL
3677jvmtiTrace_ForceEarlyReturnVoid(jvmtiEnv* env,
3678 jthread thread) {
3679
3680#if !INCLUDE_JVMTI
3681 return JVMTI_ERROR_NOT_AVAILABLE;
3682#else
3683 SafeResourceMark rm;
3684 jint trace_flags = JvmtiTrace::trace_flags(86);
3685 const char *func_name = NULL;
3686 const char *curr_thread_name = NULL;
3687 if (trace_flags) {
3688 func_name = JvmtiTrace::function_name(86);
3689 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
3690 }
3691 if(!JvmtiEnv::is_vm_live()) {
3692 if (trace_flags) {
3693 log_trace(jvmti)("[-] %s %s(%d)", func_name,
3694 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
3695 }
3696 return JVMTI_ERROR_WRONG_PHASE;
3697 }
3698 Thread* this_thread = Thread::current_or_null();
3699 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3700 if (trace_flags) {
3701 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
3702 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
3703 }
3704 return JVMTI_ERROR_UNATTACHED_THREAD;
3705 }
3706 JavaThread* current_thread = (JavaThread*)this_thread;
3707 ThreadInVMfromNative __tiv(current_thread);
3708 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_ForceEarlyReturnVoid , current_thread)
3709 debug_only(VMNativeEntryWrapper __vew;)
3710 CautiouslyPreserveExceptionMark __em(this_thread);
3711 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3712 if (!jvmti_env->is_valid()) {
3713 if (trace_flags) {
3714 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
3715 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
3716 }
3717 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3718 }
3719
3720 if (jvmti_env->get_capabilities()->can_force_early_return == 0) {
3721 if (trace_flags) {
3722 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
3723 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
3724 }
3725 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
3726 }
3727 jvmtiError err;
3728 JavaThread* java_thread = NULL;
3729 ThreadsListHandle tlh(this_thread);
3730 if (thread == NULL) {
3731 java_thread = current_thread;
3732 } else {
3733 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
3734 if (err != JVMTI_ERROR_NONE) {
3735 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3736 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3737 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
3738 }
3739 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
3740 JvmtiUtil::error_name(err), p2i(thread));
3741 }
3742 return err;
3743 }
3744 }
3745
3746 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
3747 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
3748 JvmtiTrace::safe_get_thread_name(java_thread));
3749 }
3750 err = jvmti_env->ForceEarlyReturnVoid(java_thread);
3751 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3752 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3753 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
3754 JvmtiTrace::safe_get_thread_name(java_thread));
3755 }
3756 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
3757 JvmtiUtil::error_name(err));
3758 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
3759 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
3760 }
3761 return err;
3762#endif // INCLUDE_JVMTI
3763}
3764
3765 //
3766 // Heap functions
3767 //
3768
3769static jvmtiError JNICALL
3770jvmtiTrace_FollowReferences(jvmtiEnv* env,
3771 jint heap_filter,
3772 jclass klass,
3773 jobject initial_object,
3774 const jvmtiHeapCallbacks* callbacks,
3775 const void* user_data) {
3776
3777#if !INCLUDE_JVMTI
3778 return JVMTI_ERROR_NOT_AVAILABLE;
3779#else
3780 SafeResourceMark rm;
3781 jint trace_flags = JvmtiTrace::trace_flags(115);
3782 const char *func_name = NULL;
3783 const char *curr_thread_name = NULL;
3784 if (trace_flags) {
3785 func_name = JvmtiTrace::function_name(115);
3786 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
3787 }
3788 if(!JvmtiEnv::is_vm_live()) {
3789 if (trace_flags) {
3790 log_trace(jvmti)("[-] %s %s(%d)", func_name,
3791 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
3792 }
3793 return JVMTI_ERROR_WRONG_PHASE;
3794 }
3795 Thread* this_thread = Thread::current_or_null();
3796 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3797 if (trace_flags) {
3798 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
3799 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
3800 }
3801 return JVMTI_ERROR_UNATTACHED_THREAD;
3802 }
3803 JavaThread* current_thread = (JavaThread*)this_thread;
3804 ThreadInVMfromNative __tiv(current_thread);
3805 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_FollowReferences , current_thread)
3806 debug_only(VMNativeEntryWrapper __vew;)
3807 CautiouslyPreserveExceptionMark __em(this_thread);
3808 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3809 if (!jvmti_env->is_valid()) {
3810 if (trace_flags) {
3811 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
3812 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
3813 }
3814 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3815 }
3816
3817 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
3818 if (trace_flags) {
3819 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
3820 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
3821 }
3822 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
3823 }
3824 jvmtiError err;
3825 if (callbacks == NULL) {
3826 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3827 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3828 log_trace(jvmti)("[%s] %s { heap_filter=" INT32_FORMAT " klass=" PTR_FORMAT "", curr_thread_name, func_name, heap_filter,
3829 p2i(klass)
3830 );
3831 }
3832 log_error(jvmti)("[%s] %s } %s - erroneous arg is callbacks", curr_thread_name, func_name,
3833 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
3834 }
3835 return JVMTI_ERROR_NULL_POINTER;
3836 }
3837
3838 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
3839 log_trace(jvmti)("[%s] %s { heap_filter=" INT32_FORMAT " klass=" PTR_FORMAT " callbacks=" PTR_FORMAT " user_data=" PTR_FORMAT "", curr_thread_name, func_name, heap_filter,
3840 p2i(klass)
3841 ,
3842 p2i(callbacks)
3843,
3844 p2i(user_data)
3845 );
3846 }
3847 err = jvmti_env->FollowReferences(heap_filter, klass, initial_object, callbacks, user_data);
3848 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3849 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3850 log_trace(jvmti)("[%s] %s { heap_filter=" INT32_FORMAT " klass=" PTR_FORMAT " callbacks=" PTR_FORMAT " user_data=" PTR_FORMAT "", curr_thread_name, func_name, heap_filter,
3851 p2i(klass)
3852 ,
3853 p2i(callbacks)
3854,
3855 p2i(user_data)
3856 );
3857 }
3858 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
3859 JvmtiUtil::error_name(err));
3860 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
3861 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
3862 }
3863 return err;
3864#endif // INCLUDE_JVMTI
3865}
3866
3867static jvmtiError JNICALL
3868jvmtiTrace_IterateThroughHeap(jvmtiEnv* env,
3869 jint heap_filter,
3870 jclass klass,
3871 const jvmtiHeapCallbacks* callbacks,
3872 const void* user_data) {
3873
3874#if !INCLUDE_JVMTI
3875 return JVMTI_ERROR_NOT_AVAILABLE;
3876#else
3877 SafeResourceMark rm;
3878 jint trace_flags = JvmtiTrace::trace_flags(116);
3879 const char *func_name = NULL;
3880 const char *curr_thread_name = NULL;
3881 if (trace_flags) {
3882 func_name = JvmtiTrace::function_name(116);
3883 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
3884 }
3885 if(!JvmtiEnv::is_vm_live()) {
3886 if (trace_flags) {
3887 log_trace(jvmti)("[-] %s %s(%d)", func_name,
3888 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
3889 }
3890 return JVMTI_ERROR_WRONG_PHASE;
3891 }
3892 Thread* this_thread = Thread::current_or_null();
3893 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3894 if (trace_flags) {
3895 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
3896 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
3897 }
3898 return JVMTI_ERROR_UNATTACHED_THREAD;
3899 }
3900 JavaThread* current_thread = (JavaThread*)this_thread;
3901 ThreadInVMfromNative __tiv(current_thread);
3902 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_IterateThroughHeap , current_thread)
3903 debug_only(VMNativeEntryWrapper __vew;)
3904 CautiouslyPreserveExceptionMark __em(this_thread);
3905 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
3906 if (!jvmti_env->is_valid()) {
3907 if (trace_flags) {
3908 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
3909 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
3910 }
3911 return JVMTI_ERROR_INVALID_ENVIRONMENT;
3912 }
3913
3914 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
3915 if (trace_flags) {
3916 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
3917 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
3918 }
3919 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
3920 }
3921 jvmtiError err;
3922 if (callbacks == NULL) {
3923 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3924 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3925 log_trace(jvmti)("[%s] %s { heap_filter=" INT32_FORMAT " klass=" PTR_FORMAT "", curr_thread_name, func_name, heap_filter,
3926 p2i(klass)
3927 );
3928 }
3929 log_error(jvmti)("[%s] %s } %s - erroneous arg is callbacks", curr_thread_name, func_name,
3930 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
3931 }
3932 return JVMTI_ERROR_NULL_POINTER;
3933 }
3934
3935 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
3936 log_trace(jvmti)("[%s] %s { heap_filter=" INT32_FORMAT " klass=" PTR_FORMAT " callbacks=" PTR_FORMAT " user_data=" PTR_FORMAT "", curr_thread_name, func_name, heap_filter,
3937 p2i(klass)
3938 ,
3939 p2i(callbacks)
3940,
3941 p2i(user_data)
3942 );
3943 }
3944 err = jvmti_env->IterateThroughHeap(heap_filter, klass, callbacks, user_data);
3945 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
3946 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
3947 log_trace(jvmti)("[%s] %s { heap_filter=" INT32_FORMAT " klass=" PTR_FORMAT " callbacks=" PTR_FORMAT " user_data=" PTR_FORMAT "", curr_thread_name, func_name, heap_filter,
3948 p2i(klass)
3949 ,
3950 p2i(callbacks)
3951,
3952 p2i(user_data)
3953 );
3954 }
3955 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
3956 JvmtiUtil::error_name(err));
3957 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
3958 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
3959 }
3960 return err;
3961#endif // INCLUDE_JVMTI
3962}
3963
3964static jvmtiError JNICALL
3965jvmtiTrace_GetTag(jvmtiEnv* env,
3966 jobject object,
3967 jlong* tag_ptr) {
3968
3969#if !INCLUDE_JVMTI
3970 return JVMTI_ERROR_NOT_AVAILABLE;
3971#else
3972 SafeResourceMark rm;
3973 jint trace_flags = JvmtiTrace::trace_flags(106);
3974 const char *func_name = NULL;
3975 const char *curr_thread_name = NULL;
3976 if (trace_flags) {
3977 func_name = JvmtiTrace::function_name(106);
3978 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
3979 }
3980 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
3981 if (trace_flags) {
3982 log_trace(jvmti)("[-] %s %s", func_name,
3983 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
3984 }
3985 return JVMTI_ERROR_WRONG_PHASE;
3986 }
3987 Thread* this_thread = Thread::current_or_null();
3988 if (this_thread == NULL || !this_thread->is_Java_thread()) {
3989 if (trace_flags) {
3990 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
3991 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
3992 }
3993 return JVMTI_ERROR_UNATTACHED_THREAD;
3994 }
3995 JavaThread* current_thread = (JavaThread*)this_thread;
3996 ThreadInVMfromNative __tiv(current_thread);
3997 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetTag , current_thread)
3998 debug_only(VMNativeEntryWrapper __vew;)
3999 CautiouslyPreserveExceptionMark __em(this_thread);
4000 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4001 if (!jvmti_env->is_valid()) {
4002 if (trace_flags) {
4003 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
4004 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
4005 }
4006 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4007 }
4008
4009 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
4010 if (trace_flags) {
4011 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
4012 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
4013 }
4014 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4015 }
4016 jvmtiError err;
4017 if (tag_ptr == NULL) {
4018 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4019 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4020 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
4021 }
4022 log_error(jvmti)("[%s] %s } %s - erroneous arg is tag_ptr", curr_thread_name, func_name,
4023 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
4024 }
4025 return JVMTI_ERROR_NULL_POINTER;
4026 }
4027
4028 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
4029 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
4030 }
4031 err = jvmti_env->GetTag(object, tag_ptr);
4032 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4033 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4034 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
4035 }
4036 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
4037 JvmtiUtil::error_name(err));
4038 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
4039 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
4040 }
4041 return err;
4042#endif // INCLUDE_JVMTI
4043}
4044
4045static jvmtiError JNICALL
4046jvmtiTrace_SetTag(jvmtiEnv* env,
4047 jobject object,
4048 jlong tag) {
4049
4050#if !INCLUDE_JVMTI
4051 return JVMTI_ERROR_NOT_AVAILABLE;
4052#else
4053 SafeResourceMark rm;
4054 jint trace_flags = JvmtiTrace::trace_flags(107);
4055 const char *func_name = NULL;
4056 const char *curr_thread_name = NULL;
4057 if (trace_flags) {
4058 func_name = JvmtiTrace::function_name(107);
4059 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
4060 }
4061 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
4062 if (trace_flags) {
4063 log_trace(jvmti)("[-] %s %s", func_name,
4064 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
4065 }
4066 return JVMTI_ERROR_WRONG_PHASE;
4067 }
4068 Thread* this_thread = Thread::current_or_null();
4069 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4070 if (trace_flags) {
4071 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
4072 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
4073 }
4074 return JVMTI_ERROR_UNATTACHED_THREAD;
4075 }
4076 JavaThread* current_thread = (JavaThread*)this_thread;
4077 ThreadInVMfromNative __tiv(current_thread);
4078 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetTag , current_thread)
4079 debug_only(VMNativeEntryWrapper __vew;)
4080 CautiouslyPreserveExceptionMark __em(this_thread);
4081 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4082 if (!jvmti_env->is_valid()) {
4083 if (trace_flags) {
4084 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
4085 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
4086 }
4087 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4088 }
4089
4090 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
4091 if (trace_flags) {
4092 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
4093 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
4094 }
4095 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4096 }
4097 jvmtiError err;
4098
4099 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
4100 log_trace(jvmti)("[%s] %s { tag=" JLONG_FORMAT "", curr_thread_name, func_name, tag);
4101 }
4102 err = jvmti_env->SetTag(object, tag);
4103 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4104 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4105 log_trace(jvmti)("[%s] %s { tag=" JLONG_FORMAT "", curr_thread_name, func_name, tag);
4106 }
4107 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
4108 JvmtiUtil::error_name(err));
4109 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
4110 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
4111 }
4112 return err;
4113#endif // INCLUDE_JVMTI
4114}
4115
4116static jvmtiError JNICALL
4117jvmtiTrace_GetObjectsWithTags(jvmtiEnv* env,
4118 jint tag_count,
4119 const jlong* tags,
4120 jint* count_ptr,
4121 jobject** object_result_ptr,
4122 jlong** tag_result_ptr) {
4123
4124#if !INCLUDE_JVMTI
4125 return JVMTI_ERROR_NOT_AVAILABLE;
4126#else
4127 SafeResourceMark rm;
4128 jint trace_flags = JvmtiTrace::trace_flags(114);
4129 const char *func_name = NULL;
4130 const char *curr_thread_name = NULL;
4131 if (trace_flags) {
4132 func_name = JvmtiTrace::function_name(114);
4133 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
4134 }
4135 if(!JvmtiEnv::is_vm_live()) {
4136 if (trace_flags) {
4137 log_trace(jvmti)("[-] %s %s(%d)", func_name,
4138 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
4139 }
4140 return JVMTI_ERROR_WRONG_PHASE;
4141 }
4142 Thread* this_thread = Thread::current_or_null();
4143 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4144 if (trace_flags) {
4145 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
4146 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
4147 }
4148 return JVMTI_ERROR_UNATTACHED_THREAD;
4149 }
4150 JavaThread* current_thread = (JavaThread*)this_thread;
4151 ThreadInVMfromNative __tiv(current_thread);
4152 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetObjectsWithTags , current_thread)
4153 debug_only(VMNativeEntryWrapper __vew;)
4154 CautiouslyPreserveExceptionMark __em(this_thread);
4155 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4156 if (!jvmti_env->is_valid()) {
4157 if (trace_flags) {
4158 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
4159 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
4160 }
4161 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4162 }
4163
4164 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
4165 if (trace_flags) {
4166 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
4167 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
4168 }
4169 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4170 }
4171 jvmtiError err;
4172 if (tag_count < 0) {
4173 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4174 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4175 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
4176 }
4177 log_error(jvmti)("[%s] %s } %s - erroneous arg is tag_count", curr_thread_name, func_name,
4178 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT));
4179 }
4180 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
4181 }
4182 if (tags == NULL) {
4183 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4184 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4185 log_trace(jvmti)("[%s] %s { tag_count=" INT32_FORMAT "", curr_thread_name, func_name, tag_count);
4186 }
4187 log_error(jvmti)("[%s] %s } %s - erroneous arg is tags", curr_thread_name, func_name,
4188 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
4189 }
4190 return JVMTI_ERROR_NULL_POINTER;
4191 }
4192 if (count_ptr == NULL) {
4193 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4194 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4195 log_trace(jvmti)("[%s] %s { tag_count=" INT32_FORMAT " tags=" PTR_FORMAT "", curr_thread_name, func_name, tag_count,
4196 p2i(tags)
4197 );
4198 }
4199 log_error(jvmti)("[%s] %s } %s - erroneous arg is count_ptr", curr_thread_name, func_name,
4200 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
4201 }
4202 return JVMTI_ERROR_NULL_POINTER;
4203 }
4204
4205 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
4206 log_trace(jvmti)("[%s] %s { tag_count=" INT32_FORMAT " tags=" PTR_FORMAT "", curr_thread_name, func_name, tag_count,
4207 p2i(tags)
4208 );
4209 }
4210 err = jvmti_env->GetObjectsWithTags(tag_count, tags, count_ptr, object_result_ptr, tag_result_ptr);
4211 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4212 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4213 log_trace(jvmti)("[%s] %s { tag_count=" INT32_FORMAT " tags=" PTR_FORMAT "", curr_thread_name, func_name, tag_count,
4214 p2i(tags)
4215 );
4216 }
4217 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
4218 JvmtiUtil::error_name(err));
4219 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
4220 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
4221 }
4222 return err;
4223#endif // INCLUDE_JVMTI
4224}
4225
4226static jvmtiError JNICALL
4227jvmtiTrace_ForceGarbageCollection(jvmtiEnv* env) {
4228
4229#if !INCLUDE_JVMTI
4230 return JVMTI_ERROR_NOT_AVAILABLE;
4231#else
4232 SafeResourceMark rm;
4233 jint trace_flags = JvmtiTrace::trace_flags(108);
4234 const char *func_name = NULL;
4235 const char *curr_thread_name = NULL;
4236 if (trace_flags) {
4237 func_name = JvmtiTrace::function_name(108);
4238 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
4239 }
4240 if(!JvmtiEnv::is_vm_live()) {
4241 if (trace_flags) {
4242 log_trace(jvmti)("[-] %s %s(%d)", func_name,
4243 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
4244 }
4245 return JVMTI_ERROR_WRONG_PHASE;
4246 }
4247 Thread* this_thread = Thread::current_or_null();
4248 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4249 if (trace_flags) {
4250 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
4251 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
4252 }
4253 return JVMTI_ERROR_UNATTACHED_THREAD;
4254 }
4255 JavaThread* current_thread = (JavaThread*)this_thread;
4256 ThreadInVMfromNative __tiv(current_thread);
4257 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_ForceGarbageCollection , current_thread)
4258 debug_only(VMNativeEntryWrapper __vew;)
4259 CautiouslyPreserveExceptionMark __em(this_thread);
4260 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4261 if (!jvmti_env->is_valid()) {
4262 if (trace_flags) {
4263 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
4264 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
4265 }
4266 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4267 }
4268 jvmtiError err;
4269
4270 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
4271 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
4272 }
4273 err = jvmti_env->ForceGarbageCollection();
4274 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4275 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4276 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
4277 }
4278 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
4279 JvmtiUtil::error_name(err));
4280 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
4281 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
4282 }
4283 return err;
4284#endif // INCLUDE_JVMTI
4285}
4286
4287 //
4288 // Heap (1.0) functions
4289 //
4290
4291static jvmtiError JNICALL
4292jvmtiTrace_IterateOverObjectsReachableFromObject(jvmtiEnv* env,
4293 jobject object,
4294 jvmtiObjectReferenceCallback object_reference_callback,
4295 const void* user_data) {
4296
4297#if !INCLUDE_JVMTI
4298 return JVMTI_ERROR_NOT_AVAILABLE;
4299#else
4300 SafeResourceMark rm;
4301 jint trace_flags = JvmtiTrace::trace_flags(109);
4302 const char *func_name = NULL;
4303 const char *curr_thread_name = NULL;
4304 if (trace_flags) {
4305 func_name = JvmtiTrace::function_name(109);
4306 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
4307 }
4308 if(!JvmtiEnv::is_vm_live()) {
4309 if (trace_flags) {
4310 log_trace(jvmti)("[-] %s %s(%d)", func_name,
4311 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
4312 }
4313 return JVMTI_ERROR_WRONG_PHASE;
4314 }
4315 Thread* this_thread = Thread::current_or_null();
4316 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4317 if (trace_flags) {
4318 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
4319 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
4320 }
4321 return JVMTI_ERROR_UNATTACHED_THREAD;
4322 }
4323 JavaThread* current_thread = (JavaThread*)this_thread;
4324 ThreadInVMfromNative __tiv(current_thread);
4325 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_IterateOverObjectsReachableFromObject , current_thread)
4326 debug_only(VMNativeEntryWrapper __vew;)
4327 CautiouslyPreserveExceptionMark __em(this_thread);
4328 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4329 if (!jvmti_env->is_valid()) {
4330 if (trace_flags) {
4331 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
4332 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
4333 }
4334 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4335 }
4336
4337 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
4338 if (trace_flags) {
4339 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
4340 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
4341 }
4342 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4343 }
4344 jvmtiError err;
4345 if (object_reference_callback == NULL) {
4346 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4347 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4348 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
4349 }
4350 log_error(jvmti)("[%s] %s } %s - erroneous arg is object_reference_callback", curr_thread_name, func_name,
4351 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
4352 }
4353 return JVMTI_ERROR_NULL_POINTER;
4354 }
4355
4356 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
4357 log_trace(jvmti)("[%s] %s { user_data=" PTR_FORMAT "", curr_thread_name, func_name,
4358 p2i(user_data)
4359 );
4360 }
4361 err = jvmti_env->IterateOverObjectsReachableFromObject(object, object_reference_callback, user_data);
4362 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4363 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4364 log_trace(jvmti)("[%s] %s { user_data=" PTR_FORMAT "", curr_thread_name, func_name,
4365 p2i(user_data)
4366 );
4367 }
4368 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
4369 JvmtiUtil::error_name(err));
4370 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
4371 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
4372 }
4373 return err;
4374#endif // INCLUDE_JVMTI
4375}
4376
4377static jvmtiError JNICALL
4378jvmtiTrace_IterateOverReachableObjects(jvmtiEnv* env,
4379 jvmtiHeapRootCallback heap_root_callback,
4380 jvmtiStackReferenceCallback stack_ref_callback,
4381 jvmtiObjectReferenceCallback object_ref_callback,
4382 const void* user_data) {
4383
4384#if !INCLUDE_JVMTI
4385 return JVMTI_ERROR_NOT_AVAILABLE;
4386#else
4387 SafeResourceMark rm;
4388 jint trace_flags = JvmtiTrace::trace_flags(110);
4389 const char *func_name = NULL;
4390 const char *curr_thread_name = NULL;
4391 if (trace_flags) {
4392 func_name = JvmtiTrace::function_name(110);
4393 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
4394 }
4395 if(!JvmtiEnv::is_vm_live()) {
4396 if (trace_flags) {
4397 log_trace(jvmti)("[-] %s %s(%d)", func_name,
4398 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
4399 }
4400 return JVMTI_ERROR_WRONG_PHASE;
4401 }
4402 Thread* this_thread = Thread::current_or_null();
4403 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4404 if (trace_flags) {
4405 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
4406 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
4407 }
4408 return JVMTI_ERROR_UNATTACHED_THREAD;
4409 }
4410 JavaThread* current_thread = (JavaThread*)this_thread;
4411 ThreadInVMfromNative __tiv(current_thread);
4412 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_IterateOverReachableObjects , current_thread)
4413 debug_only(VMNativeEntryWrapper __vew;)
4414 CautiouslyPreserveExceptionMark __em(this_thread);
4415 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4416 if (!jvmti_env->is_valid()) {
4417 if (trace_flags) {
4418 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
4419 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
4420 }
4421 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4422 }
4423
4424 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
4425 if (trace_flags) {
4426 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
4427 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
4428 }
4429 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4430 }
4431 jvmtiError err;
4432
4433 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
4434 log_trace(jvmti)("[%s] %s { user_data=" PTR_FORMAT "", curr_thread_name, func_name,
4435 p2i(user_data)
4436 );
4437 }
4438 err = jvmti_env->IterateOverReachableObjects(heap_root_callback, stack_ref_callback, object_ref_callback, user_data);
4439 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4440 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4441 log_trace(jvmti)("[%s] %s { user_data=" PTR_FORMAT "", curr_thread_name, func_name,
4442 p2i(user_data)
4443 );
4444 }
4445 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
4446 JvmtiUtil::error_name(err));
4447 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
4448 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
4449 }
4450 return err;
4451#endif // INCLUDE_JVMTI
4452}
4453
4454static jvmtiError JNICALL
4455jvmtiTrace_IterateOverHeap(jvmtiEnv* env,
4456 jvmtiHeapObjectFilter object_filter,
4457 jvmtiHeapObjectCallback heap_object_callback,
4458 const void* user_data) {
4459
4460#if !INCLUDE_JVMTI
4461 return JVMTI_ERROR_NOT_AVAILABLE;
4462#else
4463 SafeResourceMark rm;
4464 jint trace_flags = JvmtiTrace::trace_flags(111);
4465 const char *func_name = NULL;
4466 const char *curr_thread_name = NULL;
4467 if (trace_flags) {
4468 func_name = JvmtiTrace::function_name(111);
4469 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
4470 }
4471 if(!JvmtiEnv::is_vm_live()) {
4472 if (trace_flags) {
4473 log_trace(jvmti)("[-] %s %s(%d)", func_name,
4474 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
4475 }
4476 return JVMTI_ERROR_WRONG_PHASE;
4477 }
4478 Thread* this_thread = Thread::current_or_null();
4479 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4480 if (trace_flags) {
4481 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
4482 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
4483 }
4484 return JVMTI_ERROR_UNATTACHED_THREAD;
4485 }
4486 JavaThread* current_thread = (JavaThread*)this_thread;
4487 ThreadInVMfromNative __tiv(current_thread);
4488 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_IterateOverHeap , current_thread)
4489 debug_only(VMNativeEntryWrapper __vew;)
4490 CautiouslyPreserveExceptionMark __em(this_thread);
4491 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4492 if (!jvmti_env->is_valid()) {
4493 if (trace_flags) {
4494 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
4495 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
4496 }
4497 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4498 }
4499
4500 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
4501 if (trace_flags) {
4502 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
4503 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
4504 }
4505 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4506 }
4507 jvmtiError err;
4508 if (heap_object_callback == NULL) {
4509 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4510 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4511 log_trace(jvmti)("[%s] %s { object_filter=%d:%s", curr_thread_name, func_name, object_filter,
4512 JvmtiTrace::enum_name(jvmtiHeapObjectFilterConstantNames, jvmtiHeapObjectFilterConstantValues, object_filter));
4513 }
4514 log_error(jvmti)("[%s] %s } %s - erroneous arg is heap_object_callback", curr_thread_name, func_name,
4515 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
4516 }
4517 return JVMTI_ERROR_NULL_POINTER;
4518 }
4519
4520 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
4521 log_trace(jvmti)("[%s] %s { object_filter=%d:%s user_data=" PTR_FORMAT "", curr_thread_name, func_name, object_filter,
4522 JvmtiTrace::enum_name(jvmtiHeapObjectFilterConstantNames, jvmtiHeapObjectFilterConstantValues, object_filter),
4523 p2i(user_data)
4524 );
4525 }
4526 err = jvmti_env->IterateOverHeap(object_filter, heap_object_callback, user_data);
4527 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4528 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4529 log_trace(jvmti)("[%s] %s { object_filter=%d:%s user_data=" PTR_FORMAT "", curr_thread_name, func_name, object_filter,
4530 JvmtiTrace::enum_name(jvmtiHeapObjectFilterConstantNames, jvmtiHeapObjectFilterConstantValues, object_filter),
4531 p2i(user_data)
4532 );
4533 }
4534 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
4535 JvmtiUtil::error_name(err));
4536 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
4537 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
4538 }
4539 return err;
4540#endif // INCLUDE_JVMTI
4541}
4542
4543static jvmtiError JNICALL
4544jvmtiTrace_IterateOverInstancesOfClass(jvmtiEnv* env,
4545 jclass klass,
4546 jvmtiHeapObjectFilter object_filter,
4547 jvmtiHeapObjectCallback heap_object_callback,
4548 const void* user_data) {
4549
4550#if !INCLUDE_JVMTI
4551 return JVMTI_ERROR_NOT_AVAILABLE;
4552#else
4553 SafeResourceMark rm;
4554 jint trace_flags = JvmtiTrace::trace_flags(112);
4555 const char *func_name = NULL;
4556 const char *curr_thread_name = NULL;
4557 if (trace_flags) {
4558 func_name = JvmtiTrace::function_name(112);
4559 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
4560 }
4561 if(!JvmtiEnv::is_vm_live()) {
4562 if (trace_flags) {
4563 log_trace(jvmti)("[-] %s %s(%d)", func_name,
4564 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
4565 }
4566 return JVMTI_ERROR_WRONG_PHASE;
4567 }
4568 Thread* this_thread = Thread::current_or_null();
4569 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4570 if (trace_flags) {
4571 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
4572 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
4573 }
4574 return JVMTI_ERROR_UNATTACHED_THREAD;
4575 }
4576 JavaThread* current_thread = (JavaThread*)this_thread;
4577 ThreadInVMfromNative __tiv(current_thread);
4578 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_IterateOverInstancesOfClass , current_thread)
4579 debug_only(VMNativeEntryWrapper __vew;)
4580 CautiouslyPreserveExceptionMark __em(this_thread);
4581 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4582 if (!jvmti_env->is_valid()) {
4583 if (trace_flags) {
4584 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
4585 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
4586 }
4587 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4588 }
4589
4590 if (jvmti_env->get_capabilities()->can_tag_objects == 0) {
4591 if (trace_flags) {
4592 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
4593 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
4594 }
4595 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4596 }
4597 jvmtiError err;
4598 oop k_mirror = JNIHandles::resolve_external_guard(klass);
4599 if (k_mirror == NULL) {
4600 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4601 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4602 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
4603 }
4604 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
4605 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
4606 }
4607 return JVMTI_ERROR_INVALID_CLASS;
4608 }
4609 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
4610 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4611 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4612 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
4613 }
4614 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
4615 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
4616 }
4617 return JVMTI_ERROR_INVALID_CLASS;
4618 }
4619 if (heap_object_callback == NULL) {
4620 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4621 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4622 log_trace(jvmti)("[%s] %s { klass=%s object_filter=%d:%s", curr_thread_name, func_name,
4623 JvmtiTrace::get_class_name(k_mirror), object_filter,
4624 JvmtiTrace::enum_name(jvmtiHeapObjectFilterConstantNames, jvmtiHeapObjectFilterConstantValues, object_filter));
4625 }
4626 log_error(jvmti)("[%s] %s } %s - erroneous arg is heap_object_callback", curr_thread_name, func_name,
4627 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
4628 }
4629 return JVMTI_ERROR_NULL_POINTER;
4630 }
4631
4632 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
4633 log_trace(jvmti)("[%s] %s { klass=%s object_filter=%d:%s user_data=" PTR_FORMAT "", curr_thread_name, func_name,
4634 JvmtiTrace::get_class_name(k_mirror), object_filter,
4635 JvmtiTrace::enum_name(jvmtiHeapObjectFilterConstantNames, jvmtiHeapObjectFilterConstantValues, object_filter),
4636 p2i(user_data)
4637 );
4638 }
4639 err = jvmti_env->IterateOverInstancesOfClass(k_mirror, object_filter, heap_object_callback, user_data);
4640 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4641 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4642 log_trace(jvmti)("[%s] %s { klass=%s object_filter=%d:%s user_data=" PTR_FORMAT "", curr_thread_name, func_name,
4643 JvmtiTrace::get_class_name(k_mirror), object_filter,
4644 JvmtiTrace::enum_name(jvmtiHeapObjectFilterConstantNames, jvmtiHeapObjectFilterConstantValues, object_filter),
4645 p2i(user_data)
4646 );
4647 }
4648 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
4649 JvmtiUtil::error_name(err));
4650 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
4651 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
4652 }
4653 return err;
4654#endif // INCLUDE_JVMTI
4655}
4656
4657 //
4658 // Local Variable functions
4659 //
4660
4661static jvmtiError JNICALL
4662jvmtiTrace_GetLocalObject(jvmtiEnv* env,
4663 jthread thread,
4664 jint depth,
4665 jint slot,
4666 jobject* value_ptr) {
4667
4668#if !INCLUDE_JVMTI
4669 return JVMTI_ERROR_NOT_AVAILABLE;
4670#else
4671 SafeResourceMark rm;
4672 jint trace_flags = JvmtiTrace::trace_flags(21);
4673 const char *func_name = NULL;
4674 const char *curr_thread_name = NULL;
4675 if (trace_flags) {
4676 func_name = JvmtiTrace::function_name(21);
4677 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
4678 }
4679 if(!JvmtiEnv::is_vm_live()) {
4680 if (trace_flags) {
4681 log_trace(jvmti)("[-] %s %s(%d)", func_name,
4682 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
4683 }
4684 return JVMTI_ERROR_WRONG_PHASE;
4685 }
4686 Thread* this_thread = Thread::current_or_null();
4687 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4688 if (trace_flags) {
4689 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
4690 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
4691 }
4692 return JVMTI_ERROR_UNATTACHED_THREAD;
4693 }
4694 JavaThread* current_thread = (JavaThread*)this_thread;
4695 ThreadInVMfromNative __tiv(current_thread);
4696 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetLocalObject , current_thread)
4697 debug_only(VMNativeEntryWrapper __vew;)
4698 CautiouslyPreserveExceptionMark __em(this_thread);
4699 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4700 if (!jvmti_env->is_valid()) {
4701 if (trace_flags) {
4702 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
4703 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
4704 }
4705 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4706 }
4707
4708 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
4709 if (trace_flags) {
4710 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
4711 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
4712 }
4713 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4714 }
4715 jvmtiError err;
4716 JavaThread* java_thread = NULL;
4717 ThreadsListHandle tlh(this_thread);
4718 if (thread == NULL) {
4719 java_thread = current_thread;
4720 } else {
4721 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
4722 if (err != JVMTI_ERROR_NONE) {
4723 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4724 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4725 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
4726 }
4727 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
4728 JvmtiUtil::error_name(err), p2i(thread));
4729 }
4730 return err;
4731 }
4732 }
4733
4734 if (depth < 0) {
4735 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4736 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4737 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
4738 JvmtiTrace::safe_get_thread_name(java_thread));
4739 }
4740 log_error(jvmti)("[%s] %s } %s - erroneous arg is depth - negative depth - jthread = " INT32_FORMAT "", curr_thread_name, func_name,
4741 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT), depth);
4742 }
4743 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
4744 }
4745 if (value_ptr == NULL) {
4746 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4747 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4748 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
4749 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
4750 }
4751 log_error(jvmti)("[%s] %s } %s - erroneous arg is value_ptr", curr_thread_name, func_name,
4752 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
4753 }
4754 return JVMTI_ERROR_NULL_POINTER;
4755 }
4756
4757 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
4758 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
4759 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
4760 }
4761 err = jvmti_env->GetLocalObject(java_thread, depth, slot, value_ptr);
4762 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4763 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4764 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
4765 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
4766 }
4767 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
4768 JvmtiUtil::error_name(err));
4769 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
4770 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
4771 }
4772 return err;
4773#endif // INCLUDE_JVMTI
4774}
4775
4776static jvmtiError JNICALL
4777jvmtiTrace_GetLocalInstance(jvmtiEnv* env,
4778 jthread thread,
4779 jint depth,
4780 jobject* value_ptr) {
4781
4782#if !INCLUDE_JVMTI
4783 return JVMTI_ERROR_NOT_AVAILABLE;
4784#else
4785 SafeResourceMark rm;
4786 jint trace_flags = JvmtiTrace::trace_flags(155);
4787 const char *func_name = NULL;
4788 const char *curr_thread_name = NULL;
4789 if (trace_flags) {
4790 func_name = JvmtiTrace::function_name(155);
4791 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
4792 }
4793 if(!JvmtiEnv::is_vm_live()) {
4794 if (trace_flags) {
4795 log_trace(jvmti)("[-] %s %s(%d)", func_name,
4796 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
4797 }
4798 return JVMTI_ERROR_WRONG_PHASE;
4799 }
4800 Thread* this_thread = Thread::current_or_null();
4801 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4802 if (trace_flags) {
4803 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
4804 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
4805 }
4806 return JVMTI_ERROR_UNATTACHED_THREAD;
4807 }
4808 JavaThread* current_thread = (JavaThread*)this_thread;
4809 ThreadInVMfromNative __tiv(current_thread);
4810 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetLocalInstance , 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 if (trace_flags) {
4816 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
4817 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
4818 }
4819 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4820 }
4821
4822 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
4823 if (trace_flags) {
4824 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
4825 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
4826 }
4827 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4828 }
4829 jvmtiError err;
4830 JavaThread* java_thread = NULL;
4831 ThreadsListHandle tlh(this_thread);
4832 if (thread == NULL) {
4833 java_thread = current_thread;
4834 } else {
4835 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
4836 if (err != JVMTI_ERROR_NONE) {
4837 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4838 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4839 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
4840 }
4841 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
4842 JvmtiUtil::error_name(err), p2i(thread));
4843 }
4844 return err;
4845 }
4846 }
4847
4848 if (depth < 0) {
4849 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4850 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4851 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
4852 JvmtiTrace::safe_get_thread_name(java_thread));
4853 }
4854 log_error(jvmti)("[%s] %s } %s - erroneous arg is depth - negative depth - jthread = " INT32_FORMAT "", curr_thread_name, func_name,
4855 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT), depth);
4856 }
4857 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
4858 }
4859 if (value_ptr == NULL) {
4860 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4861 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4862 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d", curr_thread_name, func_name,
4863 JvmtiTrace::safe_get_thread_name(java_thread), depth);
4864 }
4865 log_error(jvmti)("[%s] %s } %s - erroneous arg is value_ptr", curr_thread_name, func_name,
4866 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
4867 }
4868 return JVMTI_ERROR_NULL_POINTER;
4869 }
4870
4871 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
4872 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d", curr_thread_name, func_name,
4873 JvmtiTrace::safe_get_thread_name(java_thread), depth);
4874 }
4875 err = jvmti_env->GetLocalInstance(java_thread, depth, value_ptr);
4876 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4877 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4878 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d", curr_thread_name, func_name,
4879 JvmtiTrace::safe_get_thread_name(java_thread), depth);
4880 }
4881 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
4882 JvmtiUtil::error_name(err));
4883 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
4884 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
4885 }
4886 return err;
4887#endif // INCLUDE_JVMTI
4888}
4889
4890static jvmtiError JNICALL
4891jvmtiTrace_GetLocalInt(jvmtiEnv* env,
4892 jthread thread,
4893 jint depth,
4894 jint slot,
4895 jint* value_ptr) {
4896
4897#if !INCLUDE_JVMTI
4898 return JVMTI_ERROR_NOT_AVAILABLE;
4899#else
4900 SafeResourceMark rm;
4901 jint trace_flags = JvmtiTrace::trace_flags(22);
4902 const char *func_name = NULL;
4903 const char *curr_thread_name = NULL;
4904 if (trace_flags) {
4905 func_name = JvmtiTrace::function_name(22);
4906 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
4907 }
4908 if(!JvmtiEnv::is_vm_live()) {
4909 if (trace_flags) {
4910 log_trace(jvmti)("[-] %s %s(%d)", func_name,
4911 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
4912 }
4913 return JVMTI_ERROR_WRONG_PHASE;
4914 }
4915 Thread* this_thread = Thread::current_or_null();
4916 if (this_thread == NULL || !this_thread->is_Java_thread()) {
4917 if (trace_flags) {
4918 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
4919 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
4920 }
4921 return JVMTI_ERROR_UNATTACHED_THREAD;
4922 }
4923 JavaThread* current_thread = (JavaThread*)this_thread;
4924 ThreadInVMfromNative __tiv(current_thread);
4925 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetLocalInt , current_thread)
4926 debug_only(VMNativeEntryWrapper __vew;)
4927 CautiouslyPreserveExceptionMark __em(this_thread);
4928 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
4929 if (!jvmti_env->is_valid()) {
4930 if (trace_flags) {
4931 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
4932 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
4933 }
4934 return JVMTI_ERROR_INVALID_ENVIRONMENT;
4935 }
4936
4937 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
4938 if (trace_flags) {
4939 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
4940 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
4941 }
4942 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
4943 }
4944 jvmtiError err;
4945 JavaThread* java_thread = NULL;
4946 ThreadsListHandle tlh(this_thread);
4947 if (thread == NULL) {
4948 java_thread = current_thread;
4949 } else {
4950 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
4951 if (err != JVMTI_ERROR_NONE) {
4952 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4953 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4954 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
4955 }
4956 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
4957 JvmtiUtil::error_name(err), p2i(thread));
4958 }
4959 return err;
4960 }
4961 }
4962
4963 if (depth < 0) {
4964 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4965 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4966 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
4967 JvmtiTrace::safe_get_thread_name(java_thread));
4968 }
4969 log_error(jvmti)("[%s] %s } %s - erroneous arg is depth - negative depth - jthread = " INT32_FORMAT "", curr_thread_name, func_name,
4970 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT), depth);
4971 }
4972 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
4973 }
4974 if (value_ptr == NULL) {
4975 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4976 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4977 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
4978 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
4979 }
4980 log_error(jvmti)("[%s] %s } %s - erroneous arg is value_ptr", curr_thread_name, func_name,
4981 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
4982 }
4983 return JVMTI_ERROR_NULL_POINTER;
4984 }
4985
4986 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
4987 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
4988 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
4989 }
4990 err = jvmti_env->GetLocalInt(java_thread, depth, slot, value_ptr);
4991 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
4992 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
4993 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
4994 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
4995 }
4996 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
4997 JvmtiUtil::error_name(err));
4998 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
4999 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
5000 }
5001 return err;
5002#endif // INCLUDE_JVMTI
5003}
5004
5005static jvmtiError JNICALL
5006jvmtiTrace_GetLocalLong(jvmtiEnv* env,
5007 jthread thread,
5008 jint depth,
5009 jint slot,
5010 jlong* value_ptr) {
5011
5012#if !INCLUDE_JVMTI
5013 return JVMTI_ERROR_NOT_AVAILABLE;
5014#else
5015 SafeResourceMark rm;
5016 jint trace_flags = JvmtiTrace::trace_flags(23);
5017 const char *func_name = NULL;
5018 const char *curr_thread_name = NULL;
5019 if (trace_flags) {
5020 func_name = JvmtiTrace::function_name(23);
5021 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
5022 }
5023 if(!JvmtiEnv::is_vm_live()) {
5024 if (trace_flags) {
5025 log_trace(jvmti)("[-] %s %s(%d)", func_name,
5026 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
5027 }
5028 return JVMTI_ERROR_WRONG_PHASE;
5029 }
5030 Thread* this_thread = Thread::current_or_null();
5031 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5032 if (trace_flags) {
5033 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
5034 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
5035 }
5036 return JVMTI_ERROR_UNATTACHED_THREAD;
5037 }
5038 JavaThread* current_thread = (JavaThread*)this_thread;
5039 ThreadInVMfromNative __tiv(current_thread);
5040 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetLocalLong , current_thread)
5041 debug_only(VMNativeEntryWrapper __vew;)
5042 CautiouslyPreserveExceptionMark __em(this_thread);
5043 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5044 if (!jvmti_env->is_valid()) {
5045 if (trace_flags) {
5046 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
5047 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
5048 }
5049 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5050 }
5051
5052 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
5053 if (trace_flags) {
5054 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
5055 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
5056 }
5057 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
5058 }
5059 jvmtiError err;
5060 JavaThread* java_thread = NULL;
5061 ThreadsListHandle tlh(this_thread);
5062 if (thread == NULL) {
5063 java_thread = current_thread;
5064 } else {
5065 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
5066 if (err != JVMTI_ERROR_NONE) {
5067 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5068 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5069 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
5070 }
5071 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
5072 JvmtiUtil::error_name(err), p2i(thread));
5073 }
5074 return err;
5075 }
5076 }
5077
5078 if (depth < 0) {
5079 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5080 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5081 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
5082 JvmtiTrace::safe_get_thread_name(java_thread));
5083 }
5084 log_error(jvmti)("[%s] %s } %s - erroneous arg is depth - negative depth - jthread = " INT32_FORMAT "", curr_thread_name, func_name,
5085 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT), depth);
5086 }
5087 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
5088 }
5089 if (value_ptr == NULL) {
5090 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5091 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5092 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
5093 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
5094 }
5095 log_error(jvmti)("[%s] %s } %s - erroneous arg is value_ptr", curr_thread_name, func_name,
5096 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
5097 }
5098 return JVMTI_ERROR_NULL_POINTER;
5099 }
5100
5101 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
5102 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
5103 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
5104 }
5105 err = jvmti_env->GetLocalLong(java_thread, depth, slot, value_ptr);
5106 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5107 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5108 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
5109 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
5110 }
5111 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
5112 JvmtiUtil::error_name(err));
5113 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
5114 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
5115 }
5116 return err;
5117#endif // INCLUDE_JVMTI
5118}
5119
5120static jvmtiError JNICALL
5121jvmtiTrace_GetLocalFloat(jvmtiEnv* env,
5122 jthread thread,
5123 jint depth,
5124 jint slot,
5125 jfloat* value_ptr) {
5126
5127#if !INCLUDE_JVMTI
5128 return JVMTI_ERROR_NOT_AVAILABLE;
5129#else
5130 SafeResourceMark rm;
5131 jint trace_flags = JvmtiTrace::trace_flags(24);
5132 const char *func_name = NULL;
5133 const char *curr_thread_name = NULL;
5134 if (trace_flags) {
5135 func_name = JvmtiTrace::function_name(24);
5136 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
5137 }
5138 if(!JvmtiEnv::is_vm_live()) {
5139 if (trace_flags) {
5140 log_trace(jvmti)("[-] %s %s(%d)", func_name,
5141 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
5142 }
5143 return JVMTI_ERROR_WRONG_PHASE;
5144 }
5145 Thread* this_thread = Thread::current_or_null();
5146 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5147 if (trace_flags) {
5148 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
5149 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
5150 }
5151 return JVMTI_ERROR_UNATTACHED_THREAD;
5152 }
5153 JavaThread* current_thread = (JavaThread*)this_thread;
5154 ThreadInVMfromNative __tiv(current_thread);
5155 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetLocalFloat , current_thread)
5156 debug_only(VMNativeEntryWrapper __vew;)
5157 CautiouslyPreserveExceptionMark __em(this_thread);
5158 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5159 if (!jvmti_env->is_valid()) {
5160 if (trace_flags) {
5161 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
5162 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
5163 }
5164 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5165 }
5166
5167 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
5168 if (trace_flags) {
5169 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
5170 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
5171 }
5172 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
5173 }
5174 jvmtiError err;
5175 JavaThread* java_thread = NULL;
5176 ThreadsListHandle tlh(this_thread);
5177 if (thread == NULL) {
5178 java_thread = current_thread;
5179 } else {
5180 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
5181 if (err != JVMTI_ERROR_NONE) {
5182 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5183 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5184 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
5185 }
5186 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
5187 JvmtiUtil::error_name(err), p2i(thread));
5188 }
5189 return err;
5190 }
5191 }
5192
5193 if (depth < 0) {
5194 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5195 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5196 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
5197 JvmtiTrace::safe_get_thread_name(java_thread));
5198 }
5199 log_error(jvmti)("[%s] %s } %s - erroneous arg is depth - negative depth - jthread = " INT32_FORMAT "", curr_thread_name, func_name,
5200 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT), depth);
5201 }
5202 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
5203 }
5204 if (value_ptr == NULL) {
5205 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5206 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5207 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
5208 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
5209 }
5210 log_error(jvmti)("[%s] %s } %s - erroneous arg is value_ptr", curr_thread_name, func_name,
5211 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
5212 }
5213 return JVMTI_ERROR_NULL_POINTER;
5214 }
5215
5216 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
5217 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
5218 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
5219 }
5220 err = jvmti_env->GetLocalFloat(java_thread, depth, slot, value_ptr);
5221 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5222 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5223 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
5224 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
5225 }
5226 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
5227 JvmtiUtil::error_name(err));
5228 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
5229 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
5230 }
5231 return err;
5232#endif // INCLUDE_JVMTI
5233}
5234
5235static jvmtiError JNICALL
5236jvmtiTrace_GetLocalDouble(jvmtiEnv* env,
5237 jthread thread,
5238 jint depth,
5239 jint slot,
5240 jdouble* value_ptr) {
5241
5242#if !INCLUDE_JVMTI
5243 return JVMTI_ERROR_NOT_AVAILABLE;
5244#else
5245 SafeResourceMark rm;
5246 jint trace_flags = JvmtiTrace::trace_flags(25);
5247 const char *func_name = NULL;
5248 const char *curr_thread_name = NULL;
5249 if (trace_flags) {
5250 func_name = JvmtiTrace::function_name(25);
5251 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
5252 }
5253 if(!JvmtiEnv::is_vm_live()) {
5254 if (trace_flags) {
5255 log_trace(jvmti)("[-] %s %s(%d)", func_name,
5256 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
5257 }
5258 return JVMTI_ERROR_WRONG_PHASE;
5259 }
5260 Thread* this_thread = Thread::current_or_null();
5261 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5262 if (trace_flags) {
5263 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
5264 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
5265 }
5266 return JVMTI_ERROR_UNATTACHED_THREAD;
5267 }
5268 JavaThread* current_thread = (JavaThread*)this_thread;
5269 ThreadInVMfromNative __tiv(current_thread);
5270 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetLocalDouble , current_thread)
5271 debug_only(VMNativeEntryWrapper __vew;)
5272 CautiouslyPreserveExceptionMark __em(this_thread);
5273 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5274 if (!jvmti_env->is_valid()) {
5275 if (trace_flags) {
5276 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
5277 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
5278 }
5279 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5280 }
5281
5282 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
5283 if (trace_flags) {
5284 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
5285 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
5286 }
5287 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
5288 }
5289 jvmtiError err;
5290 JavaThread* java_thread = NULL;
5291 ThreadsListHandle tlh(this_thread);
5292 if (thread == NULL) {
5293 java_thread = current_thread;
5294 } else {
5295 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
5296 if (err != JVMTI_ERROR_NONE) {
5297 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5298 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5299 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
5300 }
5301 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
5302 JvmtiUtil::error_name(err), p2i(thread));
5303 }
5304 return err;
5305 }
5306 }
5307
5308 if (depth < 0) {
5309 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5310 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5311 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
5312 JvmtiTrace::safe_get_thread_name(java_thread));
5313 }
5314 log_error(jvmti)("[%s] %s } %s - erroneous arg is depth - negative depth - jthread = " INT32_FORMAT "", curr_thread_name, func_name,
5315 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT), depth);
5316 }
5317 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
5318 }
5319 if (value_ptr == NULL) {
5320 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5321 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5322 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
5323 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
5324 }
5325 log_error(jvmti)("[%s] %s } %s - erroneous arg is value_ptr", curr_thread_name, func_name,
5326 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
5327 }
5328 return JVMTI_ERROR_NULL_POINTER;
5329 }
5330
5331 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
5332 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
5333 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
5334 }
5335 err = jvmti_env->GetLocalDouble(java_thread, depth, slot, value_ptr);
5336 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5337 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5338 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
5339 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
5340 }
5341 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
5342 JvmtiUtil::error_name(err));
5343 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
5344 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
5345 }
5346 return err;
5347#endif // INCLUDE_JVMTI
5348}
5349
5350static jvmtiError JNICALL
5351jvmtiTrace_SetLocalObject(jvmtiEnv* env,
5352 jthread thread,
5353 jint depth,
5354 jint slot,
5355 jobject value) {
5356
5357#if !INCLUDE_JVMTI
5358 return JVMTI_ERROR_NOT_AVAILABLE;
5359#else
5360 SafeResourceMark rm;
5361 jint trace_flags = JvmtiTrace::trace_flags(26);
5362 const char *func_name = NULL;
5363 const char *curr_thread_name = NULL;
5364 if (trace_flags) {
5365 func_name = JvmtiTrace::function_name(26);
5366 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
5367 }
5368 if(!JvmtiEnv::is_vm_live()) {
5369 if (trace_flags) {
5370 log_trace(jvmti)("[-] %s %s(%d)", func_name,
5371 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
5372 }
5373 return JVMTI_ERROR_WRONG_PHASE;
5374 }
5375 Thread* this_thread = Thread::current_or_null();
5376 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5377 if (trace_flags) {
5378 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
5379 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
5380 }
5381 return JVMTI_ERROR_UNATTACHED_THREAD;
5382 }
5383 JavaThread* current_thread = (JavaThread*)this_thread;
5384 ThreadInVMfromNative __tiv(current_thread);
5385 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetLocalObject , current_thread)
5386 debug_only(VMNativeEntryWrapper __vew;)
5387 CautiouslyPreserveExceptionMark __em(this_thread);
5388 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5389 if (!jvmti_env->is_valid()) {
5390 if (trace_flags) {
5391 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
5392 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
5393 }
5394 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5395 }
5396
5397 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
5398 if (trace_flags) {
5399 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
5400 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
5401 }
5402 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
5403 }
5404 jvmtiError err;
5405 JavaThread* java_thread = NULL;
5406 ThreadsListHandle tlh(this_thread);
5407 if (thread == NULL) {
5408 java_thread = current_thread;
5409 } else {
5410 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
5411 if (err != JVMTI_ERROR_NONE) {
5412 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5413 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5414 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
5415 }
5416 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
5417 JvmtiUtil::error_name(err), p2i(thread));
5418 }
5419 return err;
5420 }
5421 }
5422
5423 if (depth < 0) {
5424 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5425 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5426 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
5427 JvmtiTrace::safe_get_thread_name(java_thread));
5428 }
5429 log_error(jvmti)("[%s] %s } %s - erroneous arg is depth - negative depth - jthread = " INT32_FORMAT "", curr_thread_name, func_name,
5430 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT), depth);
5431 }
5432 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
5433 }
5434
5435 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
5436 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
5437 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
5438 }
5439 err = jvmti_env->SetLocalObject(java_thread, depth, slot, value);
5440 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5441 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5442 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT "", curr_thread_name, func_name,
5443 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot);
5444 }
5445 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
5446 JvmtiUtil::error_name(err));
5447 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
5448 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
5449 }
5450 return err;
5451#endif // INCLUDE_JVMTI
5452}
5453
5454static jvmtiError JNICALL
5455jvmtiTrace_SetLocalInt(jvmtiEnv* env,
5456 jthread thread,
5457 jint depth,
5458 jint slot,
5459 jint value) {
5460
5461#if !INCLUDE_JVMTI
5462 return JVMTI_ERROR_NOT_AVAILABLE;
5463#else
5464 SafeResourceMark rm;
5465 jint trace_flags = JvmtiTrace::trace_flags(27);
5466 const char *func_name = NULL;
5467 const char *curr_thread_name = NULL;
5468 if (trace_flags) {
5469 func_name = JvmtiTrace::function_name(27);
5470 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
5471 }
5472 if(!JvmtiEnv::is_vm_live()) {
5473 if (trace_flags) {
5474 log_trace(jvmti)("[-] %s %s(%d)", func_name,
5475 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
5476 }
5477 return JVMTI_ERROR_WRONG_PHASE;
5478 }
5479 Thread* this_thread = Thread::current_or_null();
5480 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5481 if (trace_flags) {
5482 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
5483 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
5484 }
5485 return JVMTI_ERROR_UNATTACHED_THREAD;
5486 }
5487 JavaThread* current_thread = (JavaThread*)this_thread;
5488 ThreadInVMfromNative __tiv(current_thread);
5489 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetLocalInt , current_thread)
5490 debug_only(VMNativeEntryWrapper __vew;)
5491 CautiouslyPreserveExceptionMark __em(this_thread);
5492 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5493 if (!jvmti_env->is_valid()) {
5494 if (trace_flags) {
5495 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
5496 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
5497 }
5498 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5499 }
5500
5501 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
5502 if (trace_flags) {
5503 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
5504 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
5505 }
5506 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
5507 }
5508 jvmtiError err;
5509 JavaThread* java_thread = NULL;
5510 ThreadsListHandle tlh(this_thread);
5511 if (thread == NULL) {
5512 java_thread = current_thread;
5513 } else {
5514 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
5515 if (err != JVMTI_ERROR_NONE) {
5516 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5517 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5518 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
5519 }
5520 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
5521 JvmtiUtil::error_name(err), p2i(thread));
5522 }
5523 return err;
5524 }
5525 }
5526
5527 if (depth < 0) {
5528 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5529 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5530 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
5531 JvmtiTrace::safe_get_thread_name(java_thread));
5532 }
5533 log_error(jvmti)("[%s] %s } %s - erroneous arg is depth - negative depth - jthread = " INT32_FORMAT "", curr_thread_name, func_name,
5534 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT), depth);
5535 }
5536 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
5537 }
5538
5539 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
5540 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT " value=" INT32_FORMAT "", curr_thread_name, func_name,
5541 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot, value);
5542 }
5543 err = jvmti_env->SetLocalInt(java_thread, depth, slot, value);
5544 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5545 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5546 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT " value=" INT32_FORMAT "", curr_thread_name, func_name,
5547 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot, value);
5548 }
5549 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
5550 JvmtiUtil::error_name(err));
5551 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
5552 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
5553 }
5554 return err;
5555#endif // INCLUDE_JVMTI
5556}
5557
5558static jvmtiError JNICALL
5559jvmtiTrace_SetLocalLong(jvmtiEnv* env,
5560 jthread thread,
5561 jint depth,
5562 jint slot,
5563 jlong value) {
5564
5565#if !INCLUDE_JVMTI
5566 return JVMTI_ERROR_NOT_AVAILABLE;
5567#else
5568 SafeResourceMark rm;
5569 jint trace_flags = JvmtiTrace::trace_flags(28);
5570 const char *func_name = NULL;
5571 const char *curr_thread_name = NULL;
5572 if (trace_flags) {
5573 func_name = JvmtiTrace::function_name(28);
5574 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
5575 }
5576 if(!JvmtiEnv::is_vm_live()) {
5577 if (trace_flags) {
5578 log_trace(jvmti)("[-] %s %s(%d)", func_name,
5579 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
5580 }
5581 return JVMTI_ERROR_WRONG_PHASE;
5582 }
5583 Thread* this_thread = Thread::current_or_null();
5584 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5585 if (trace_flags) {
5586 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
5587 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
5588 }
5589 return JVMTI_ERROR_UNATTACHED_THREAD;
5590 }
5591 JavaThread* current_thread = (JavaThread*)this_thread;
5592 ThreadInVMfromNative __tiv(current_thread);
5593 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetLocalLong , current_thread)
5594 debug_only(VMNativeEntryWrapper __vew;)
5595 CautiouslyPreserveExceptionMark __em(this_thread);
5596 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5597 if (!jvmti_env->is_valid()) {
5598 if (trace_flags) {
5599 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
5600 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
5601 }
5602 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5603 }
5604
5605 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
5606 if (trace_flags) {
5607 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
5608 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
5609 }
5610 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
5611 }
5612 jvmtiError err;
5613 JavaThread* java_thread = NULL;
5614 ThreadsListHandle tlh(this_thread);
5615 if (thread == NULL) {
5616 java_thread = current_thread;
5617 } else {
5618 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
5619 if (err != JVMTI_ERROR_NONE) {
5620 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5621 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5622 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
5623 }
5624 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
5625 JvmtiUtil::error_name(err), p2i(thread));
5626 }
5627 return err;
5628 }
5629 }
5630
5631 if (depth < 0) {
5632 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5633 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5634 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
5635 JvmtiTrace::safe_get_thread_name(java_thread));
5636 }
5637 log_error(jvmti)("[%s] %s } %s - erroneous arg is depth - negative depth - jthread = " INT32_FORMAT "", curr_thread_name, func_name,
5638 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT), depth);
5639 }
5640 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
5641 }
5642
5643 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
5644 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT " value=" JLONG_FORMAT "", curr_thread_name, func_name,
5645 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot, value);
5646 }
5647 err = jvmti_env->SetLocalLong(java_thread, depth, slot, value);
5648 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5649 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5650 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT " value=" JLONG_FORMAT "", curr_thread_name, func_name,
5651 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot, value);
5652 }
5653 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
5654 JvmtiUtil::error_name(err));
5655 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
5656 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
5657 }
5658 return err;
5659#endif // INCLUDE_JVMTI
5660}
5661
5662static jvmtiError JNICALL
5663jvmtiTrace_SetLocalFloat(jvmtiEnv* env,
5664 jthread thread,
5665 jint depth,
5666 jint slot,
5667 jfloat value) {
5668
5669#if !INCLUDE_JVMTI
5670 return JVMTI_ERROR_NOT_AVAILABLE;
5671#else
5672 SafeResourceMark rm;
5673 jint trace_flags = JvmtiTrace::trace_flags(29);
5674 const char *func_name = NULL;
5675 const char *curr_thread_name = NULL;
5676 if (trace_flags) {
5677 func_name = JvmtiTrace::function_name(29);
5678 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
5679 }
5680 if(!JvmtiEnv::is_vm_live()) {
5681 if (trace_flags) {
5682 log_trace(jvmti)("[-] %s %s(%d)", func_name,
5683 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
5684 }
5685 return JVMTI_ERROR_WRONG_PHASE;
5686 }
5687 Thread* this_thread = Thread::current_or_null();
5688 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5689 if (trace_flags) {
5690 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
5691 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
5692 }
5693 return JVMTI_ERROR_UNATTACHED_THREAD;
5694 }
5695 JavaThread* current_thread = (JavaThread*)this_thread;
5696 ThreadInVMfromNative __tiv(current_thread);
5697 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetLocalFloat , current_thread)
5698 debug_only(VMNativeEntryWrapper __vew;)
5699 CautiouslyPreserveExceptionMark __em(this_thread);
5700 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5701 if (!jvmti_env->is_valid()) {
5702 if (trace_flags) {
5703 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
5704 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
5705 }
5706 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5707 }
5708
5709 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
5710 if (trace_flags) {
5711 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
5712 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
5713 }
5714 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
5715 }
5716 jvmtiError err;
5717 JavaThread* java_thread = NULL;
5718 ThreadsListHandle tlh(this_thread);
5719 if (thread == NULL) {
5720 java_thread = current_thread;
5721 } else {
5722 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
5723 if (err != JVMTI_ERROR_NONE) {
5724 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5725 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5726 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
5727 }
5728 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
5729 JvmtiUtil::error_name(err), p2i(thread));
5730 }
5731 return err;
5732 }
5733 }
5734
5735 if (depth < 0) {
5736 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5737 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5738 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
5739 JvmtiTrace::safe_get_thread_name(java_thread));
5740 }
5741 log_error(jvmti)("[%s] %s } %s - erroneous arg is depth - negative depth - jthread = " INT32_FORMAT "", curr_thread_name, func_name,
5742 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT), depth);
5743 }
5744 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
5745 }
5746
5747 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
5748 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT " value=%f", curr_thread_name, func_name,
5749 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot, value);
5750 }
5751 err = jvmti_env->SetLocalFloat(java_thread, depth, slot, value);
5752 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5753 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5754 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT " value=%f", curr_thread_name, func_name,
5755 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot, value);
5756 }
5757 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
5758 JvmtiUtil::error_name(err));
5759 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
5760 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
5761 }
5762 return err;
5763#endif // INCLUDE_JVMTI
5764}
5765
5766static jvmtiError JNICALL
5767jvmtiTrace_SetLocalDouble(jvmtiEnv* env,
5768 jthread thread,
5769 jint depth,
5770 jint slot,
5771 jdouble value) {
5772
5773#if !INCLUDE_JVMTI
5774 return JVMTI_ERROR_NOT_AVAILABLE;
5775#else
5776 SafeResourceMark rm;
5777 jint trace_flags = JvmtiTrace::trace_flags(30);
5778 const char *func_name = NULL;
5779 const char *curr_thread_name = NULL;
5780 if (trace_flags) {
5781 func_name = JvmtiTrace::function_name(30);
5782 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
5783 }
5784 if(!JvmtiEnv::is_vm_live()) {
5785 if (trace_flags) {
5786 log_trace(jvmti)("[-] %s %s(%d)", func_name,
5787 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
5788 }
5789 return JVMTI_ERROR_WRONG_PHASE;
5790 }
5791 Thread* this_thread = Thread::current_or_null();
5792 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5793 if (trace_flags) {
5794 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
5795 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
5796 }
5797 return JVMTI_ERROR_UNATTACHED_THREAD;
5798 }
5799 JavaThread* current_thread = (JavaThread*)this_thread;
5800 ThreadInVMfromNative __tiv(current_thread);
5801 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetLocalDouble , current_thread)
5802 debug_only(VMNativeEntryWrapper __vew;)
5803 CautiouslyPreserveExceptionMark __em(this_thread);
5804 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5805 if (!jvmti_env->is_valid()) {
5806 if (trace_flags) {
5807 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
5808 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
5809 }
5810 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5811 }
5812
5813 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
5814 if (trace_flags) {
5815 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
5816 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
5817 }
5818 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
5819 }
5820 jvmtiError err;
5821 JavaThread* java_thread = NULL;
5822 ThreadsListHandle tlh(this_thread);
5823 if (thread == NULL) {
5824 java_thread = current_thread;
5825 } else {
5826 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
5827 if (err != JVMTI_ERROR_NONE) {
5828 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5829 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5830 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
5831 }
5832 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
5833 JvmtiUtil::error_name(err), p2i(thread));
5834 }
5835 return err;
5836 }
5837 }
5838
5839 if (depth < 0) {
5840 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5841 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5842 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
5843 JvmtiTrace::safe_get_thread_name(java_thread));
5844 }
5845 log_error(jvmti)("[%s] %s } %s - erroneous arg is depth - negative depth - jthread = " INT32_FORMAT "", curr_thread_name, func_name,
5846 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT), depth);
5847 }
5848 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
5849 }
5850
5851 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
5852 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT " value=%f", curr_thread_name, func_name,
5853 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot, value);
5854 }
5855 err = jvmti_env->SetLocalDouble(java_thread, depth, slot, value);
5856 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5857 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5858 log_trace(jvmti)("[%s] %s { thread=%sdepth=%d slot=" INT32_FORMAT " value=%f", curr_thread_name, func_name,
5859 JvmtiTrace::safe_get_thread_name(java_thread), depth, slot, value);
5860 }
5861 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
5862 JvmtiUtil::error_name(err));
5863 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
5864 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
5865 }
5866 return err;
5867#endif // INCLUDE_JVMTI
5868}
5869
5870 //
5871 // Breakpoint functions
5872 //
5873
5874static jvmtiError JNICALL
5875jvmtiTrace_SetBreakpoint(jvmtiEnv* env,
5876 jmethodID method,
5877 jlocation location) {
5878
5879#if !INCLUDE_JVMTI
5880 return JVMTI_ERROR_NOT_AVAILABLE;
5881#else
5882 SafeResourceMark rm;
5883 jint trace_flags = JvmtiTrace::trace_flags(38);
5884 const char *func_name = NULL;
5885 const char *curr_thread_name = NULL;
5886 if (trace_flags) {
5887 func_name = JvmtiTrace::function_name(38);
5888 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
5889 }
5890 if(!JvmtiEnv::is_vm_live()) {
5891 if (trace_flags) {
5892 log_trace(jvmti)("[-] %s %s(%d)", func_name,
5893 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
5894 }
5895 return JVMTI_ERROR_WRONG_PHASE;
5896 }
5897 Thread* this_thread = Thread::current_or_null();
5898 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5899 if (trace_flags) {
5900 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
5901 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
5902 }
5903 return JVMTI_ERROR_UNATTACHED_THREAD;
5904 }
5905 JavaThread* current_thread = (JavaThread*)this_thread;
5906 ThreadInVMfromNative __tiv(current_thread);
5907 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetBreakpoint , current_thread)
5908 debug_only(VMNativeEntryWrapper __vew;)
5909 CautiouslyPreserveExceptionMark __em(this_thread);
5910 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5911 if (!jvmti_env->is_valid()) {
5912 if (trace_flags) {
5913 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
5914 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
5915 }
5916 return JVMTI_ERROR_INVALID_ENVIRONMENT;
5917 }
5918
5919 if (jvmti_env->get_capabilities()->can_generate_breakpoint_events == 0) {
5920 if (trace_flags) {
5921 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
5922 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
5923 }
5924 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
5925 }
5926 jvmtiError err;
5927 Method* method_oop = Method::checked_resolve_jmethod_id(method);
5928 if (method_oop == NULL) {
5929 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5930 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5931 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
5932 }
5933 log_error(jvmti)("[%s] %s } %s - erroneous arg is method", curr_thread_name, func_name,
5934 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_METHODID));
5935 }
5936 return JVMTI_ERROR_INVALID_METHODID;
5937 }
5938
5939 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
5940 log_trace(jvmti)("[%s] %s { method=%s.%s location=" JLONG_FORMAT "", curr_thread_name, func_name,
5941 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
5942 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
5943 , location);
5944 }
5945 err = jvmti_env->SetBreakpoint(method_oop, location);
5946 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
5947 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
5948 log_trace(jvmti)("[%s] %s { method=%s.%s location=" JLONG_FORMAT "", curr_thread_name, func_name,
5949 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
5950 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
5951 , location);
5952 }
5953 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
5954 JvmtiUtil::error_name(err));
5955 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
5956 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
5957 }
5958 return err;
5959#endif // INCLUDE_JVMTI
5960}
5961
5962static jvmtiError JNICALL
5963jvmtiTrace_ClearBreakpoint(jvmtiEnv* env,
5964 jmethodID method,
5965 jlocation location) {
5966
5967#if !INCLUDE_JVMTI
5968 return JVMTI_ERROR_NOT_AVAILABLE;
5969#else
5970 SafeResourceMark rm;
5971 jint trace_flags = JvmtiTrace::trace_flags(39);
5972 const char *func_name = NULL;
5973 const char *curr_thread_name = NULL;
5974 if (trace_flags) {
5975 func_name = JvmtiTrace::function_name(39);
5976 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
5977 }
5978 if(!JvmtiEnv::is_vm_live()) {
5979 if (trace_flags) {
5980 log_trace(jvmti)("[-] %s %s(%d)", func_name,
5981 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
5982 }
5983 return JVMTI_ERROR_WRONG_PHASE;
5984 }
5985 Thread* this_thread = Thread::current_or_null();
5986 if (this_thread == NULL || !this_thread->is_Java_thread()) {
5987 if (trace_flags) {
5988 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
5989 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
5990 }
5991 return JVMTI_ERROR_UNATTACHED_THREAD;
5992 }
5993 JavaThread* current_thread = (JavaThread*)this_thread;
5994 ThreadInVMfromNative __tiv(current_thread);
5995 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_ClearBreakpoint , current_thread)
5996 debug_only(VMNativeEntryWrapper __vew;)
5997 CautiouslyPreserveExceptionMark __em(this_thread);
5998 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
5999 if (!jvmti_env->is_valid()) {
6000 if (trace_flags) {
6001 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
6002 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
6003 }
6004 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6005 }
6006
6007 if (jvmti_env->get_capabilities()->can_generate_breakpoint_events == 0) {
6008 if (trace_flags) {
6009 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
6010 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
6011 }
6012 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
6013 }
6014 jvmtiError err;
6015 Method* method_oop = Method::checked_resolve_jmethod_id(method);
6016 if (method_oop == NULL) {
6017 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6018 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6019 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6020 }
6021 log_error(jvmti)("[%s] %s } %s - erroneous arg is method", curr_thread_name, func_name,
6022 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_METHODID));
6023 }
6024 return JVMTI_ERROR_INVALID_METHODID;
6025 }
6026
6027 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
6028 log_trace(jvmti)("[%s] %s { method=%s.%s location=" JLONG_FORMAT "", curr_thread_name, func_name,
6029 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
6030 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
6031 , location);
6032 }
6033 err = jvmti_env->ClearBreakpoint(method_oop, location);
6034 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6035 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6036 log_trace(jvmti)("[%s] %s { method=%s.%s location=" JLONG_FORMAT "", curr_thread_name, func_name,
6037 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
6038 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
6039 , location);
6040 }
6041 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
6042 JvmtiUtil::error_name(err));
6043 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
6044 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
6045 }
6046 return err;
6047#endif // INCLUDE_JVMTI
6048}
6049
6050 //
6051 // Watched Field functions
6052 //
6053
6054static jvmtiError JNICALL
6055jvmtiTrace_SetFieldAccessWatch(jvmtiEnv* env,
6056 jclass klass,
6057 jfieldID field) {
6058
6059#if !INCLUDE_JVMTI
6060 return JVMTI_ERROR_NOT_AVAILABLE;
6061#else
6062 SafeResourceMark rm;
6063 jint trace_flags = JvmtiTrace::trace_flags(41);
6064 const char *func_name = NULL;
6065 const char *curr_thread_name = NULL;
6066 if (trace_flags) {
6067 func_name = JvmtiTrace::function_name(41);
6068 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
6069 }
6070 if(!JvmtiEnv::is_vm_live()) {
6071 if (trace_flags) {
6072 log_trace(jvmti)("[-] %s %s(%d)", func_name,
6073 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
6074 }
6075 return JVMTI_ERROR_WRONG_PHASE;
6076 }
6077 Thread* this_thread = Thread::current_or_null();
6078 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6079 if (trace_flags) {
6080 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
6081 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
6082 }
6083 return JVMTI_ERROR_UNATTACHED_THREAD;
6084 }
6085 JavaThread* current_thread = (JavaThread*)this_thread;
6086 ThreadInVMfromNative __tiv(current_thread);
6087 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetFieldAccessWatch , current_thread)
6088 debug_only(VMNativeEntryWrapper __vew;)
6089 CautiouslyPreserveExceptionMark __em(this_thread);
6090 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6091 if (!jvmti_env->is_valid()) {
6092 if (trace_flags) {
6093 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
6094 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
6095 }
6096 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6097 }
6098
6099 if (jvmti_env->get_capabilities()->can_generate_field_access_events == 0) {
6100 if (trace_flags) {
6101 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
6102 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
6103 }
6104 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
6105 }
6106 jvmtiError err;
6107 oop k_mirror = JNIHandles::resolve_external_guard(klass);
6108 if (k_mirror == NULL) {
6109 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6110 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6111 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6112 }
6113 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6114 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6115 }
6116 return JVMTI_ERROR_INVALID_CLASS;
6117 }
6118 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
6119 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6120 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6121 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6122 }
6123 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6124 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6125 }
6126 return JVMTI_ERROR_INVALID_CLASS;
6127 }
6128
6129 if (java_lang_Class::is_primitive(k_mirror)) {
6130 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6131 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6132 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6133 }
6134 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - is a primitive class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6135 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6136 }
6137 return JVMTI_ERROR_INVALID_CLASS;
6138 }
6139 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
6140 if (k_oop == NULL) {
6141 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6142 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6143 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6144 }
6145 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - no Klass* - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6146 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6147 }
6148 return JVMTI_ERROR_INVALID_CLASS;
6149 }
6150 ResourceMark rm_fdesc(current_thread);
6151 fieldDescriptor fdesc;
6152 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
6153 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6154 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6155 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
6156 JvmtiTrace::get_class_name(k_mirror));
6157 }
6158 log_error(jvmti)("[%s] %s } %s - erroneous arg is field", curr_thread_name, func_name,
6159 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_FIELDID));
6160 }
6161 return JVMTI_ERROR_INVALID_FIELDID;
6162 }
6163
6164 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
6165 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
6166 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
6167 }
6168 err = jvmti_env->SetFieldAccessWatch(&fdesc);
6169 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6170 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6171 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
6172 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
6173 }
6174 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
6175 JvmtiUtil::error_name(err));
6176 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
6177 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
6178 }
6179 return err;
6180#endif // INCLUDE_JVMTI
6181}
6182
6183static jvmtiError JNICALL
6184jvmtiTrace_ClearFieldAccessWatch(jvmtiEnv* env,
6185 jclass klass,
6186 jfieldID field) {
6187
6188#if !INCLUDE_JVMTI
6189 return JVMTI_ERROR_NOT_AVAILABLE;
6190#else
6191 SafeResourceMark rm;
6192 jint trace_flags = JvmtiTrace::trace_flags(42);
6193 const char *func_name = NULL;
6194 const char *curr_thread_name = NULL;
6195 if (trace_flags) {
6196 func_name = JvmtiTrace::function_name(42);
6197 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
6198 }
6199 if(!JvmtiEnv::is_vm_live()) {
6200 if (trace_flags) {
6201 log_trace(jvmti)("[-] %s %s(%d)", func_name,
6202 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
6203 }
6204 return JVMTI_ERROR_WRONG_PHASE;
6205 }
6206 Thread* this_thread = Thread::current_or_null();
6207 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6208 if (trace_flags) {
6209 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
6210 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
6211 }
6212 return JVMTI_ERROR_UNATTACHED_THREAD;
6213 }
6214 JavaThread* current_thread = (JavaThread*)this_thread;
6215 ThreadInVMfromNative __tiv(current_thread);
6216 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_ClearFieldAccessWatch , current_thread)
6217 debug_only(VMNativeEntryWrapper __vew;)
6218 CautiouslyPreserveExceptionMark __em(this_thread);
6219 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6220 if (!jvmti_env->is_valid()) {
6221 if (trace_flags) {
6222 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
6223 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
6224 }
6225 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6226 }
6227
6228 if (jvmti_env->get_capabilities()->can_generate_field_access_events == 0) {
6229 if (trace_flags) {
6230 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
6231 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
6232 }
6233 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
6234 }
6235 jvmtiError err;
6236 oop k_mirror = JNIHandles::resolve_external_guard(klass);
6237 if (k_mirror == NULL) {
6238 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6239 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6240 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6241 }
6242 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6243 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6244 }
6245 return JVMTI_ERROR_INVALID_CLASS;
6246 }
6247 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
6248 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6249 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6250 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6251 }
6252 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6253 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6254 }
6255 return JVMTI_ERROR_INVALID_CLASS;
6256 }
6257
6258 if (java_lang_Class::is_primitive(k_mirror)) {
6259 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6260 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6261 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6262 }
6263 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - is a primitive class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6264 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6265 }
6266 return JVMTI_ERROR_INVALID_CLASS;
6267 }
6268 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
6269 if (k_oop == NULL) {
6270 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6271 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6272 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6273 }
6274 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - no Klass* - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6275 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6276 }
6277 return JVMTI_ERROR_INVALID_CLASS;
6278 }
6279 ResourceMark rm_fdesc(current_thread);
6280 fieldDescriptor fdesc;
6281 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
6282 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6283 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6284 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
6285 JvmtiTrace::get_class_name(k_mirror));
6286 }
6287 log_error(jvmti)("[%s] %s } %s - erroneous arg is field", curr_thread_name, func_name,
6288 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_FIELDID));
6289 }
6290 return JVMTI_ERROR_INVALID_FIELDID;
6291 }
6292
6293 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
6294 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
6295 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
6296 }
6297 err = jvmti_env->ClearFieldAccessWatch(&fdesc);
6298 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6299 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6300 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
6301 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
6302 }
6303 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
6304 JvmtiUtil::error_name(err));
6305 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
6306 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
6307 }
6308 return err;
6309#endif // INCLUDE_JVMTI
6310}
6311
6312static jvmtiError JNICALL
6313jvmtiTrace_SetFieldModificationWatch(jvmtiEnv* env,
6314 jclass klass,
6315 jfieldID field) {
6316
6317#if !INCLUDE_JVMTI
6318 return JVMTI_ERROR_NOT_AVAILABLE;
6319#else
6320 SafeResourceMark rm;
6321 jint trace_flags = JvmtiTrace::trace_flags(43);
6322 const char *func_name = NULL;
6323 const char *curr_thread_name = NULL;
6324 if (trace_flags) {
6325 func_name = JvmtiTrace::function_name(43);
6326 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
6327 }
6328 if(!JvmtiEnv::is_vm_live()) {
6329 if (trace_flags) {
6330 log_trace(jvmti)("[-] %s %s(%d)", func_name,
6331 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
6332 }
6333 return JVMTI_ERROR_WRONG_PHASE;
6334 }
6335 Thread* this_thread = Thread::current_or_null();
6336 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6337 if (trace_flags) {
6338 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
6339 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
6340 }
6341 return JVMTI_ERROR_UNATTACHED_THREAD;
6342 }
6343 JavaThread* current_thread = (JavaThread*)this_thread;
6344 ThreadInVMfromNative __tiv(current_thread);
6345 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetFieldModificationWatch , current_thread)
6346 debug_only(VMNativeEntryWrapper __vew;)
6347 CautiouslyPreserveExceptionMark __em(this_thread);
6348 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6349 if (!jvmti_env->is_valid()) {
6350 if (trace_flags) {
6351 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
6352 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
6353 }
6354 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6355 }
6356
6357 if (jvmti_env->get_capabilities()->can_generate_field_modification_events == 0) {
6358 if (trace_flags) {
6359 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
6360 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
6361 }
6362 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
6363 }
6364 jvmtiError err;
6365 oop k_mirror = JNIHandles::resolve_external_guard(klass);
6366 if (k_mirror == NULL) {
6367 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6368 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6369 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6370 }
6371 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6372 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6373 }
6374 return JVMTI_ERROR_INVALID_CLASS;
6375 }
6376 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
6377 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6378 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6379 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6380 }
6381 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6382 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6383 }
6384 return JVMTI_ERROR_INVALID_CLASS;
6385 }
6386
6387 if (java_lang_Class::is_primitive(k_mirror)) {
6388 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6389 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6390 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6391 }
6392 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - is a primitive class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6393 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6394 }
6395 return JVMTI_ERROR_INVALID_CLASS;
6396 }
6397 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
6398 if (k_oop == NULL) {
6399 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6400 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6401 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6402 }
6403 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - no Klass* - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6404 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6405 }
6406 return JVMTI_ERROR_INVALID_CLASS;
6407 }
6408 ResourceMark rm_fdesc(current_thread);
6409 fieldDescriptor fdesc;
6410 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
6411 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6412 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6413 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
6414 JvmtiTrace::get_class_name(k_mirror));
6415 }
6416 log_error(jvmti)("[%s] %s } %s - erroneous arg is field", curr_thread_name, func_name,
6417 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_FIELDID));
6418 }
6419 return JVMTI_ERROR_INVALID_FIELDID;
6420 }
6421
6422 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
6423 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
6424 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
6425 }
6426 err = jvmti_env->SetFieldModificationWatch(&fdesc);
6427 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6428 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6429 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
6430 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
6431 }
6432 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
6433 JvmtiUtil::error_name(err));
6434 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
6435 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
6436 }
6437 return err;
6438#endif // INCLUDE_JVMTI
6439}
6440
6441static jvmtiError JNICALL
6442jvmtiTrace_ClearFieldModificationWatch(jvmtiEnv* env,
6443 jclass klass,
6444 jfieldID field) {
6445
6446#if !INCLUDE_JVMTI
6447 return JVMTI_ERROR_NOT_AVAILABLE;
6448#else
6449 SafeResourceMark rm;
6450 jint trace_flags = JvmtiTrace::trace_flags(44);
6451 const char *func_name = NULL;
6452 const char *curr_thread_name = NULL;
6453 if (trace_flags) {
6454 func_name = JvmtiTrace::function_name(44);
6455 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
6456 }
6457 if(!JvmtiEnv::is_vm_live()) {
6458 if (trace_flags) {
6459 log_trace(jvmti)("[-] %s %s(%d)", func_name,
6460 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
6461 }
6462 return JVMTI_ERROR_WRONG_PHASE;
6463 }
6464 Thread* this_thread = Thread::current_or_null();
6465 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6466 if (trace_flags) {
6467 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
6468 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
6469 }
6470 return JVMTI_ERROR_UNATTACHED_THREAD;
6471 }
6472 JavaThread* current_thread = (JavaThread*)this_thread;
6473 ThreadInVMfromNative __tiv(current_thread);
6474 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_ClearFieldModificationWatch , current_thread)
6475 debug_only(VMNativeEntryWrapper __vew;)
6476 CautiouslyPreserveExceptionMark __em(this_thread);
6477 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6478 if (!jvmti_env->is_valid()) {
6479 if (trace_flags) {
6480 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
6481 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
6482 }
6483 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6484 }
6485
6486 if (jvmti_env->get_capabilities()->can_generate_field_modification_events == 0) {
6487 if (trace_flags) {
6488 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
6489 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
6490 }
6491 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
6492 }
6493 jvmtiError err;
6494 oop k_mirror = JNIHandles::resolve_external_guard(klass);
6495 if (k_mirror == NULL) {
6496 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6497 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6498 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6499 }
6500 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6501 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6502 }
6503 return JVMTI_ERROR_INVALID_CLASS;
6504 }
6505 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
6506 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6507 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6508 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6509 }
6510 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6511 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6512 }
6513 return JVMTI_ERROR_INVALID_CLASS;
6514 }
6515
6516 if (java_lang_Class::is_primitive(k_mirror)) {
6517 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6518 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6519 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6520 }
6521 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - is a primitive class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6522 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6523 }
6524 return JVMTI_ERROR_INVALID_CLASS;
6525 }
6526 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
6527 if (k_oop == NULL) {
6528 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6529 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6530 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6531 }
6532 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - no Klass* - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
6533 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
6534 }
6535 return JVMTI_ERROR_INVALID_CLASS;
6536 }
6537 ResourceMark rm_fdesc(current_thread);
6538 fieldDescriptor fdesc;
6539 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
6540 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6541 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6542 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
6543 JvmtiTrace::get_class_name(k_mirror));
6544 }
6545 log_error(jvmti)("[%s] %s } %s - erroneous arg is field", curr_thread_name, func_name,
6546 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_FIELDID));
6547 }
6548 return JVMTI_ERROR_INVALID_FIELDID;
6549 }
6550
6551 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
6552 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
6553 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
6554 }
6555 err = jvmti_env->ClearFieldModificationWatch(&fdesc);
6556 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6557 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6558 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
6559 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
6560 }
6561 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
6562 JvmtiUtil::error_name(err));
6563 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
6564 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
6565 }
6566 return err;
6567#endif // INCLUDE_JVMTI
6568}
6569
6570 //
6571 // Module functions
6572 //
6573
6574static jvmtiError JNICALL
6575jvmtiTrace_GetAllModules(jvmtiEnv* env,
6576 jint* module_count_ptr,
6577 jobject** modules_ptr) {
6578
6579#if !INCLUDE_JVMTI
6580 return JVMTI_ERROR_NOT_AVAILABLE;
6581#else
6582 SafeResourceMark rm;
6583 jint trace_flags = JvmtiTrace::trace_flags(3);
6584 const char *func_name = NULL;
6585 const char *curr_thread_name = NULL;
6586 if (trace_flags) {
6587 func_name = JvmtiTrace::function_name(3);
6588 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
6589 }
6590 if(!JvmtiEnv::is_vm_live()) {
6591 if (trace_flags) {
6592 log_trace(jvmti)("[-] %s %s(%d)", func_name,
6593 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
6594 }
6595 return JVMTI_ERROR_WRONG_PHASE;
6596 }
6597 Thread* this_thread = Thread::current_or_null();
6598 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6599 if (trace_flags) {
6600 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
6601 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
6602 }
6603 return JVMTI_ERROR_UNATTACHED_THREAD;
6604 }
6605 JavaThread* current_thread = (JavaThread*)this_thread;
6606 ThreadInVMfromNative __tiv(current_thread);
6607 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetAllModules , current_thread)
6608 debug_only(VMNativeEntryWrapper __vew;)
6609 CautiouslyPreserveExceptionMark __em(this_thread);
6610 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6611 if (!jvmti_env->is_valid()) {
6612 if (trace_flags) {
6613 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
6614 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
6615 }
6616 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6617 }
6618 jvmtiError err;
6619 if (module_count_ptr == NULL) {
6620 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6621 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6622 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6623 }
6624 log_error(jvmti)("[%s] %s } %s - erroneous arg is module_count_ptr", curr_thread_name, func_name,
6625 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
6626 }
6627 return JVMTI_ERROR_NULL_POINTER;
6628 }
6629 if (modules_ptr == NULL) {
6630 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6631 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6632 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6633 }
6634 log_error(jvmti)("[%s] %s } %s - erroneous arg is modules_ptr", curr_thread_name, func_name,
6635 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
6636 }
6637 return JVMTI_ERROR_NULL_POINTER;
6638 }
6639
6640 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
6641 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6642 }
6643 err = jvmti_env->GetAllModules(module_count_ptr, modules_ptr);
6644 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6645 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6646 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6647 }
6648 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
6649 JvmtiUtil::error_name(err));
6650 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
6651 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
6652 }
6653 return err;
6654#endif // INCLUDE_JVMTI
6655}
6656
6657static jvmtiError JNICALL
6658jvmtiTrace_GetNamedModule(jvmtiEnv* env,
6659 jobject class_loader,
6660 const char* package_name,
6661 jobject* module_ptr) {
6662
6663#if !INCLUDE_JVMTI
6664 return JVMTI_ERROR_NOT_AVAILABLE;
6665#else
6666 SafeResourceMark rm;
6667 jint trace_flags = JvmtiTrace::trace_flags(40);
6668 const char *func_name = NULL;
6669 const char *curr_thread_name = NULL;
6670 if (trace_flags) {
6671 func_name = JvmtiTrace::function_name(40);
6672 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
6673 }
6674 if(!JvmtiEnv::is_vm_live()) {
6675 if (trace_flags) {
6676 log_trace(jvmti)("[-] %s %s(%d)", func_name,
6677 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
6678 }
6679 return JVMTI_ERROR_WRONG_PHASE;
6680 }
6681 Thread* this_thread = Thread::current_or_null();
6682 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6683 if (trace_flags) {
6684 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
6685 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
6686 }
6687 return JVMTI_ERROR_UNATTACHED_THREAD;
6688 }
6689 JavaThread* current_thread = (JavaThread*)this_thread;
6690 ThreadInVMfromNative __tiv(current_thread);
6691 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetNamedModule , current_thread)
6692 debug_only(VMNativeEntryWrapper __vew;)
6693 CautiouslyPreserveExceptionMark __em(this_thread);
6694 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6695 if (!jvmti_env->is_valid()) {
6696 if (trace_flags) {
6697 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
6698 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
6699 }
6700 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6701 }
6702 jvmtiError err;
6703 if (package_name == NULL) {
6704 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6705 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6706 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6707 }
6708 log_error(jvmti)("[%s] %s } %s - erroneous arg is package_name", curr_thread_name, func_name,
6709 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
6710 }
6711 return JVMTI_ERROR_NULL_POINTER;
6712 }
6713 if (module_ptr == NULL) {
6714 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6715 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6716 log_trace(jvmti)("[%s] %s { package_name='%s'", curr_thread_name, func_name, package_name);
6717 }
6718 log_error(jvmti)("[%s] %s } %s - erroneous arg is module_ptr", curr_thread_name, func_name,
6719 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
6720 }
6721 return JVMTI_ERROR_NULL_POINTER;
6722 }
6723
6724 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
6725 log_trace(jvmti)("[%s] %s { package_name='%s'", curr_thread_name, func_name, package_name);
6726 }
6727 err = jvmti_env->GetNamedModule(class_loader, package_name, module_ptr);
6728 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6729 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6730 log_trace(jvmti)("[%s] %s { package_name='%s'", curr_thread_name, func_name, package_name);
6731 }
6732 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
6733 JvmtiUtil::error_name(err));
6734 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
6735 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
6736 }
6737 return err;
6738#endif // INCLUDE_JVMTI
6739}
6740
6741static jvmtiError JNICALL
6742jvmtiTrace_AddModuleReads(jvmtiEnv* env,
6743 jobject module,
6744 jobject to_module) {
6745
6746#if !INCLUDE_JVMTI
6747 return JVMTI_ERROR_NOT_AVAILABLE;
6748#else
6749 SafeResourceMark rm;
6750 jint trace_flags = JvmtiTrace::trace_flags(94);
6751 const char *func_name = NULL;
6752 const char *curr_thread_name = NULL;
6753 if (trace_flags) {
6754 func_name = JvmtiTrace::function_name(94);
6755 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
6756 }
6757 if(!JvmtiEnv::is_vm_live()) {
6758 if (trace_flags) {
6759 log_trace(jvmti)("[-] %s %s(%d)", func_name,
6760 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
6761 }
6762 return JVMTI_ERROR_WRONG_PHASE;
6763 }
6764 Thread* this_thread = Thread::current_or_null();
6765 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6766 if (trace_flags) {
6767 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
6768 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
6769 }
6770 return JVMTI_ERROR_UNATTACHED_THREAD;
6771 }
6772 JavaThread* current_thread = (JavaThread*)this_thread;
6773 ThreadInVMfromNative __tiv(current_thread);
6774 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_AddModuleReads , current_thread)
6775 debug_only(VMNativeEntryWrapper __vew;)
6776 CautiouslyPreserveExceptionMark __em(this_thread);
6777 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6778 if (!jvmti_env->is_valid()) {
6779 if (trace_flags) {
6780 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
6781 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
6782 }
6783 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6784 }
6785 jvmtiError err;
6786 if (module == NULL) {
6787 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6788 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6789 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6790 }
6791 log_error(jvmti)("[%s] %s } %s - erroneous arg is module", curr_thread_name, func_name,
6792 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
6793 }
6794 return JVMTI_ERROR_NULL_POINTER;
6795 }
6796 if (to_module == NULL) {
6797 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6798 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6799 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6800 }
6801 log_error(jvmti)("[%s] %s } %s - erroneous arg is to_module", curr_thread_name, func_name,
6802 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
6803 }
6804 return JVMTI_ERROR_NULL_POINTER;
6805 }
6806
6807 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
6808 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6809 }
6810 err = jvmti_env->AddModuleReads(module, to_module);
6811 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6812 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6813 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6814 }
6815 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
6816 JvmtiUtil::error_name(err));
6817 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
6818 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
6819 }
6820 return err;
6821#endif // INCLUDE_JVMTI
6822}
6823
6824static jvmtiError JNICALL
6825jvmtiTrace_AddModuleExports(jvmtiEnv* env,
6826 jobject module,
6827 const char* pkg_name,
6828 jobject to_module) {
6829
6830#if !INCLUDE_JVMTI
6831 return JVMTI_ERROR_NOT_AVAILABLE;
6832#else
6833 SafeResourceMark rm;
6834 jint trace_flags = JvmtiTrace::trace_flags(95);
6835 const char *func_name = NULL;
6836 const char *curr_thread_name = NULL;
6837 if (trace_flags) {
6838 func_name = JvmtiTrace::function_name(95);
6839 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
6840 }
6841 if(!JvmtiEnv::is_vm_live()) {
6842 if (trace_flags) {
6843 log_trace(jvmti)("[-] %s %s(%d)", func_name,
6844 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
6845 }
6846 return JVMTI_ERROR_WRONG_PHASE;
6847 }
6848 Thread* this_thread = Thread::current_or_null();
6849 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6850 if (trace_flags) {
6851 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
6852 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
6853 }
6854 return JVMTI_ERROR_UNATTACHED_THREAD;
6855 }
6856 JavaThread* current_thread = (JavaThread*)this_thread;
6857 ThreadInVMfromNative __tiv(current_thread);
6858 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_AddModuleExports , current_thread)
6859 debug_only(VMNativeEntryWrapper __vew;)
6860 CautiouslyPreserveExceptionMark __em(this_thread);
6861 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6862 if (!jvmti_env->is_valid()) {
6863 if (trace_flags) {
6864 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
6865 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
6866 }
6867 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6868 }
6869 jvmtiError err;
6870 if (module == NULL) {
6871 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6872 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6873 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6874 }
6875 log_error(jvmti)("[%s] %s } %s - erroneous arg is module", curr_thread_name, func_name,
6876 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
6877 }
6878 return JVMTI_ERROR_NULL_POINTER;
6879 }
6880 if (pkg_name == NULL) {
6881 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6882 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6883 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6884 }
6885 log_error(jvmti)("[%s] %s } %s - erroneous arg is pkg_name", curr_thread_name, func_name,
6886 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
6887 }
6888 return JVMTI_ERROR_NULL_POINTER;
6889 }
6890 if (to_module == NULL) {
6891 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6892 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6893 log_trace(jvmti)("[%s] %s { pkg_name='%s'", curr_thread_name, func_name, pkg_name);
6894 }
6895 log_error(jvmti)("[%s] %s } %s - erroneous arg is to_module", curr_thread_name, func_name,
6896 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
6897 }
6898 return JVMTI_ERROR_NULL_POINTER;
6899 }
6900
6901 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
6902 log_trace(jvmti)("[%s] %s { pkg_name='%s'", curr_thread_name, func_name, pkg_name);
6903 }
6904 err = jvmti_env->AddModuleExports(module, pkg_name, to_module);
6905 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6906 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6907 log_trace(jvmti)("[%s] %s { pkg_name='%s'", curr_thread_name, func_name, pkg_name);
6908 }
6909 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
6910 JvmtiUtil::error_name(err));
6911 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
6912 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
6913 }
6914 return err;
6915#endif // INCLUDE_JVMTI
6916}
6917
6918static jvmtiError JNICALL
6919jvmtiTrace_AddModuleOpens(jvmtiEnv* env,
6920 jobject module,
6921 const char* pkg_name,
6922 jobject to_module) {
6923
6924#if !INCLUDE_JVMTI
6925 return JVMTI_ERROR_NOT_AVAILABLE;
6926#else
6927 SafeResourceMark rm;
6928 jint trace_flags = JvmtiTrace::trace_flags(96);
6929 const char *func_name = NULL;
6930 const char *curr_thread_name = NULL;
6931 if (trace_flags) {
6932 func_name = JvmtiTrace::function_name(96);
6933 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
6934 }
6935 if(!JvmtiEnv::is_vm_live()) {
6936 if (trace_flags) {
6937 log_trace(jvmti)("[-] %s %s(%d)", func_name,
6938 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
6939 }
6940 return JVMTI_ERROR_WRONG_PHASE;
6941 }
6942 Thread* this_thread = Thread::current_or_null();
6943 if (this_thread == NULL || !this_thread->is_Java_thread()) {
6944 if (trace_flags) {
6945 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
6946 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
6947 }
6948 return JVMTI_ERROR_UNATTACHED_THREAD;
6949 }
6950 JavaThread* current_thread = (JavaThread*)this_thread;
6951 ThreadInVMfromNative __tiv(current_thread);
6952 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_AddModuleOpens , current_thread)
6953 debug_only(VMNativeEntryWrapper __vew;)
6954 CautiouslyPreserveExceptionMark __em(this_thread);
6955 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
6956 if (!jvmti_env->is_valid()) {
6957 if (trace_flags) {
6958 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
6959 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
6960 }
6961 return JVMTI_ERROR_INVALID_ENVIRONMENT;
6962 }
6963 jvmtiError err;
6964 if (module == NULL) {
6965 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6966 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6967 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6968 }
6969 log_error(jvmti)("[%s] %s } %s - erroneous arg is module", curr_thread_name, func_name,
6970 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
6971 }
6972 return JVMTI_ERROR_NULL_POINTER;
6973 }
6974 if (pkg_name == NULL) {
6975 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6976 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6977 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
6978 }
6979 log_error(jvmti)("[%s] %s } %s - erroneous arg is pkg_name", curr_thread_name, func_name,
6980 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
6981 }
6982 return JVMTI_ERROR_NULL_POINTER;
6983 }
6984 if (to_module == NULL) {
6985 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
6986 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
6987 log_trace(jvmti)("[%s] %s { pkg_name='%s'", curr_thread_name, func_name, pkg_name);
6988 }
6989 log_error(jvmti)("[%s] %s } %s - erroneous arg is to_module", curr_thread_name, func_name,
6990 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
6991 }
6992 return JVMTI_ERROR_NULL_POINTER;
6993 }
6994
6995 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
6996 log_trace(jvmti)("[%s] %s { pkg_name='%s'", curr_thread_name, func_name, pkg_name);
6997 }
6998 err = jvmti_env->AddModuleOpens(module, pkg_name, to_module);
6999 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7000 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7001 log_trace(jvmti)("[%s] %s { pkg_name='%s'", curr_thread_name, func_name, pkg_name);
7002 }
7003 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
7004 JvmtiUtil::error_name(err));
7005 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
7006 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
7007 }
7008 return err;
7009#endif // INCLUDE_JVMTI
7010}
7011
7012static jvmtiError JNICALL
7013jvmtiTrace_AddModuleUses(jvmtiEnv* env,
7014 jobject module,
7015 jclass service) {
7016
7017#if !INCLUDE_JVMTI
7018 return JVMTI_ERROR_NOT_AVAILABLE;
7019#else
7020 SafeResourceMark rm;
7021 jint trace_flags = JvmtiTrace::trace_flags(97);
7022 const char *func_name = NULL;
7023 const char *curr_thread_name = NULL;
7024 if (trace_flags) {
7025 func_name = JvmtiTrace::function_name(97);
7026 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
7027 }
7028 if(!JvmtiEnv::is_vm_live()) {
7029 if (trace_flags) {
7030 log_trace(jvmti)("[-] %s %s(%d)", func_name,
7031 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
7032 }
7033 return JVMTI_ERROR_WRONG_PHASE;
7034 }
7035 Thread* this_thread = Thread::current_or_null();
7036 if (this_thread == NULL || !this_thread->is_Java_thread()) {
7037 if (trace_flags) {
7038 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
7039 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
7040 }
7041 return JVMTI_ERROR_UNATTACHED_THREAD;
7042 }
7043 JavaThread* current_thread = (JavaThread*)this_thread;
7044 ThreadInVMfromNative __tiv(current_thread);
7045 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_AddModuleUses , current_thread)
7046 debug_only(VMNativeEntryWrapper __vew;)
7047 CautiouslyPreserveExceptionMark __em(this_thread);
7048 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
7049 if (!jvmti_env->is_valid()) {
7050 if (trace_flags) {
7051 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
7052 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
7053 }
7054 return JVMTI_ERROR_INVALID_ENVIRONMENT;
7055 }
7056 jvmtiError err;
7057 if (module == NULL) {
7058 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7059 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7060 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7061 }
7062 log_error(jvmti)("[%s] %s } %s - erroneous arg is module", curr_thread_name, func_name,
7063 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7064 }
7065 return JVMTI_ERROR_NULL_POINTER;
7066 }
7067 if (service == NULL) {
7068 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7069 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7070 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7071 }
7072 log_error(jvmti)("[%s] %s } %s - erroneous arg is service", curr_thread_name, func_name,
7073 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7074 }
7075 return JVMTI_ERROR_NULL_POINTER;
7076 }
7077
7078 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
7079 log_trace(jvmti)("[%s] %s { service=" PTR_FORMAT "", curr_thread_name, func_name,
7080 p2i(service)
7081 );
7082 }
7083 err = jvmti_env->AddModuleUses(module, service);
7084 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7085 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7086 log_trace(jvmti)("[%s] %s { service=" PTR_FORMAT "", curr_thread_name, func_name,
7087 p2i(service)
7088 );
7089 }
7090 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
7091 JvmtiUtil::error_name(err));
7092 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
7093 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
7094 }
7095 return err;
7096#endif // INCLUDE_JVMTI
7097}
7098
7099static jvmtiError JNICALL
7100jvmtiTrace_AddModuleProvides(jvmtiEnv* env,
7101 jobject module,
7102 jclass service,
7103 jclass impl_class) {
7104
7105#if !INCLUDE_JVMTI
7106 return JVMTI_ERROR_NOT_AVAILABLE;
7107#else
7108 SafeResourceMark rm;
7109 jint trace_flags = JvmtiTrace::trace_flags(98);
7110 const char *func_name = NULL;
7111 const char *curr_thread_name = NULL;
7112 if (trace_flags) {
7113 func_name = JvmtiTrace::function_name(98);
7114 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
7115 }
7116 if(!JvmtiEnv::is_vm_live()) {
7117 if (trace_flags) {
7118 log_trace(jvmti)("[-] %s %s(%d)", func_name,
7119 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
7120 }
7121 return JVMTI_ERROR_WRONG_PHASE;
7122 }
7123 Thread* this_thread = Thread::current_or_null();
7124 if (this_thread == NULL || !this_thread->is_Java_thread()) {
7125 if (trace_flags) {
7126 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
7127 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
7128 }
7129 return JVMTI_ERROR_UNATTACHED_THREAD;
7130 }
7131 JavaThread* current_thread = (JavaThread*)this_thread;
7132 ThreadInVMfromNative __tiv(current_thread);
7133 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_AddModuleProvides , current_thread)
7134 debug_only(VMNativeEntryWrapper __vew;)
7135 CautiouslyPreserveExceptionMark __em(this_thread);
7136 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
7137 if (!jvmti_env->is_valid()) {
7138 if (trace_flags) {
7139 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
7140 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
7141 }
7142 return JVMTI_ERROR_INVALID_ENVIRONMENT;
7143 }
7144 jvmtiError err;
7145 if (module == NULL) {
7146 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7147 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7148 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7149 }
7150 log_error(jvmti)("[%s] %s } %s - erroneous arg is module", curr_thread_name, func_name,
7151 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7152 }
7153 return JVMTI_ERROR_NULL_POINTER;
7154 }
7155 if (service == NULL) {
7156 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7157 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7158 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7159 }
7160 log_error(jvmti)("[%s] %s } %s - erroneous arg is service", curr_thread_name, func_name,
7161 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7162 }
7163 return JVMTI_ERROR_NULL_POINTER;
7164 }
7165 if (impl_class == NULL) {
7166 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7167 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7168 log_trace(jvmti)("[%s] %s { service=" PTR_FORMAT "", curr_thread_name, func_name,
7169 p2i(service)
7170 );
7171 }
7172 log_error(jvmti)("[%s] %s } %s - erroneous arg is impl_class", curr_thread_name, func_name,
7173 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7174 }
7175 return JVMTI_ERROR_NULL_POINTER;
7176 }
7177
7178 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
7179 log_trace(jvmti)("[%s] %s { service=" PTR_FORMAT " impl_class=" PTR_FORMAT "", curr_thread_name, func_name,
7180 p2i(service)
7181 ,
7182 p2i(impl_class)
7183 );
7184 }
7185 err = jvmti_env->AddModuleProvides(module, service, impl_class);
7186 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7187 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7188 log_trace(jvmti)("[%s] %s { service=" PTR_FORMAT " impl_class=" PTR_FORMAT "", curr_thread_name, func_name,
7189 p2i(service)
7190 ,
7191 p2i(impl_class)
7192 );
7193 }
7194 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
7195 JvmtiUtil::error_name(err));
7196 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
7197 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
7198 }
7199 return err;
7200#endif // INCLUDE_JVMTI
7201}
7202
7203static jvmtiError JNICALL
7204jvmtiTrace_IsModifiableModule(jvmtiEnv* env,
7205 jobject module,
7206 jboolean* is_modifiable_module_ptr) {
7207
7208#if !INCLUDE_JVMTI
7209 return JVMTI_ERROR_NOT_AVAILABLE;
7210#else
7211 SafeResourceMark rm;
7212 jint trace_flags = JvmtiTrace::trace_flags(99);
7213 const char *func_name = NULL;
7214 const char *curr_thread_name = NULL;
7215 if (trace_flags) {
7216 func_name = JvmtiTrace::function_name(99);
7217 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
7218 }
7219 if(!JvmtiEnv::is_vm_live()) {
7220 if (trace_flags) {
7221 log_trace(jvmti)("[-] %s %s(%d)", func_name,
7222 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
7223 }
7224 return JVMTI_ERROR_WRONG_PHASE;
7225 }
7226 Thread* this_thread = Thread::current_or_null();
7227 if (this_thread == NULL || !this_thread->is_Java_thread()) {
7228 if (trace_flags) {
7229 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
7230 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
7231 }
7232 return JVMTI_ERROR_UNATTACHED_THREAD;
7233 }
7234 JavaThread* current_thread = (JavaThread*)this_thread;
7235 ThreadInVMfromNative __tiv(current_thread);
7236 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_IsModifiableModule , current_thread)
7237 debug_only(VMNativeEntryWrapper __vew;)
7238 CautiouslyPreserveExceptionMark __em(this_thread);
7239 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
7240 if (!jvmti_env->is_valid()) {
7241 if (trace_flags) {
7242 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
7243 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
7244 }
7245 return JVMTI_ERROR_INVALID_ENVIRONMENT;
7246 }
7247 jvmtiError err;
7248 if (module == NULL) {
7249 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7250 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7251 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7252 }
7253 log_error(jvmti)("[%s] %s } %s - erroneous arg is module", curr_thread_name, func_name,
7254 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7255 }
7256 return JVMTI_ERROR_NULL_POINTER;
7257 }
7258 if (is_modifiable_module_ptr == NULL) {
7259 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7260 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7261 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7262 }
7263 log_error(jvmti)("[%s] %s } %s - erroneous arg is is_modifiable_module_ptr", curr_thread_name, func_name,
7264 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7265 }
7266 return JVMTI_ERROR_NULL_POINTER;
7267 }
7268
7269 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
7270 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7271 }
7272 err = jvmti_env->IsModifiableModule(module, is_modifiable_module_ptr);
7273 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7274 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7275 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7276 }
7277 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
7278 JvmtiUtil::error_name(err));
7279 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
7280 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
7281 }
7282 return err;
7283#endif // INCLUDE_JVMTI
7284}
7285
7286 //
7287 // Class functions
7288 //
7289
7290static jvmtiError JNICALL
7291jvmtiTrace_GetLoadedClasses(jvmtiEnv* env,
7292 jint* class_count_ptr,
7293 jclass** classes_ptr) {
7294 SafeResourceMark rm;
7295 jint trace_flags = JvmtiTrace::trace_flags(78);
7296 const char *func_name = NULL;
7297 const char *curr_thread_name = NULL;
7298 if (trace_flags) {
7299 func_name = JvmtiTrace::function_name(78);
7300 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
7301 }
7302 if(!JvmtiEnv::is_vm_live()) {
7303 if (trace_flags) {
7304 log_trace(jvmti)("[-] %s %s(%d)", func_name,
7305 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
7306 }
7307 return JVMTI_ERROR_WRONG_PHASE;
7308 }
7309 Thread* this_thread = Thread::current_or_null();
7310 if (this_thread == NULL || !this_thread->is_Java_thread()) {
7311 if (trace_flags) {
7312 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
7313 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
7314 }
7315 return JVMTI_ERROR_UNATTACHED_THREAD;
7316 }
7317 JavaThread* current_thread = (JavaThread*)this_thread;
7318 ThreadInVMfromNative __tiv(current_thread);
7319 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetLoadedClasses , current_thread)
7320 debug_only(VMNativeEntryWrapper __vew;)
7321 CautiouslyPreserveExceptionMark __em(this_thread);
7322 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
7323 if (!jvmti_env->is_valid()) {
7324 if (trace_flags) {
7325 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
7326 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
7327 }
7328 return JVMTI_ERROR_INVALID_ENVIRONMENT;
7329 }
7330 jvmtiError err;
7331 if (class_count_ptr == NULL) {
7332 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7333 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7334 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7335 }
7336 log_error(jvmti)("[%s] %s } %s - erroneous arg is class_count_ptr", curr_thread_name, func_name,
7337 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7338 }
7339 return JVMTI_ERROR_NULL_POINTER;
7340 }
7341 if (classes_ptr == NULL) {
7342 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7343 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7344 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7345 }
7346 log_error(jvmti)("[%s] %s } %s - erroneous arg is classes_ptr", curr_thread_name, func_name,
7347 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7348 }
7349 return JVMTI_ERROR_NULL_POINTER;
7350 }
7351
7352 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
7353 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7354 }
7355 err = jvmti_env->GetLoadedClasses(class_count_ptr, classes_ptr);
7356 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7357 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7358 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7359 }
7360 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
7361 JvmtiUtil::error_name(err));
7362 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
7363 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
7364 }
7365 return err;
7366}
7367
7368static jvmtiError JNICALL
7369jvmtiTrace_GetClassLoaderClasses(jvmtiEnv* env,
7370 jobject initiating_loader,
7371 jint* class_count_ptr,
7372 jclass** classes_ptr) {
7373 SafeResourceMark rm;
7374 jint trace_flags = JvmtiTrace::trace_flags(79);
7375 const char *func_name = NULL;
7376 const char *curr_thread_name = NULL;
7377 if (trace_flags) {
7378 func_name = JvmtiTrace::function_name(79);
7379 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
7380 }
7381 if(!JvmtiEnv::is_vm_live()) {
7382 if (trace_flags) {
7383 log_trace(jvmti)("[-] %s %s(%d)", func_name,
7384 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
7385 }
7386 return JVMTI_ERROR_WRONG_PHASE;
7387 }
7388 Thread* this_thread = Thread::current_or_null();
7389 if (this_thread == NULL || !this_thread->is_Java_thread()) {
7390 if (trace_flags) {
7391 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
7392 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
7393 }
7394 return JVMTI_ERROR_UNATTACHED_THREAD;
7395 }
7396 JavaThread* current_thread = (JavaThread*)this_thread;
7397 ThreadInVMfromNative __tiv(current_thread);
7398 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetClassLoaderClasses , current_thread)
7399 debug_only(VMNativeEntryWrapper __vew;)
7400 CautiouslyPreserveExceptionMark __em(this_thread);
7401 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
7402 if (!jvmti_env->is_valid()) {
7403 if (trace_flags) {
7404 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
7405 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
7406 }
7407 return JVMTI_ERROR_INVALID_ENVIRONMENT;
7408 }
7409 jvmtiError err;
7410 if (class_count_ptr == NULL) {
7411 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7412 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7413 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7414 }
7415 log_error(jvmti)("[%s] %s } %s - erroneous arg is class_count_ptr", curr_thread_name, func_name,
7416 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7417 }
7418 return JVMTI_ERROR_NULL_POINTER;
7419 }
7420 if (classes_ptr == NULL) {
7421 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7422 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7423 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7424 }
7425 log_error(jvmti)("[%s] %s } %s - erroneous arg is classes_ptr", curr_thread_name, func_name,
7426 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7427 }
7428 return JVMTI_ERROR_NULL_POINTER;
7429 }
7430
7431 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
7432 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7433 }
7434 err = jvmti_env->GetClassLoaderClasses(initiating_loader, class_count_ptr, classes_ptr);
7435 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7436 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7437 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7438 }
7439 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
7440 JvmtiUtil::error_name(err));
7441 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
7442 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
7443 }
7444 return err;
7445}
7446
7447static jvmtiError JNICALL
7448jvmtiTrace_GetClassSignature(jvmtiEnv* env,
7449 jclass klass,
7450 char** signature_ptr,
7451 char** generic_ptr) {
7452
7453#if !INCLUDE_JVMTI
7454 return JVMTI_ERROR_NOT_AVAILABLE;
7455#else
7456 SafeResourceMark rm;
7457 jint trace_flags = JvmtiTrace::trace_flags(48);
7458 const char *func_name = NULL;
7459 const char *curr_thread_name = NULL;
7460 if (trace_flags) {
7461 func_name = JvmtiTrace::function_name(48);
7462 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
7463 }
7464 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
7465 if (trace_flags) {
7466 log_trace(jvmti)("[-] %s %s", func_name,
7467 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
7468 }
7469 return JVMTI_ERROR_WRONG_PHASE;
7470 }
7471 Thread* this_thread = Thread::current_or_null();
7472 if (this_thread == NULL || !this_thread->is_Java_thread()) {
7473 if (trace_flags) {
7474 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
7475 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
7476 }
7477 return JVMTI_ERROR_UNATTACHED_THREAD;
7478 }
7479 JavaThread* current_thread = (JavaThread*)this_thread;
7480 ThreadInVMfromNative __tiv(current_thread);
7481 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetClassSignature , current_thread)
7482 debug_only(VMNativeEntryWrapper __vew;)
7483 CautiouslyPreserveExceptionMark __em(this_thread);
7484 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
7485 if (!jvmti_env->is_valid()) {
7486 if (trace_flags) {
7487 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
7488 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
7489 }
7490 return JVMTI_ERROR_INVALID_ENVIRONMENT;
7491 }
7492 jvmtiError err;
7493 oop k_mirror = JNIHandles::resolve_external_guard(klass);
7494 if (k_mirror == NULL) {
7495 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7496 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7497 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7498 }
7499 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
7500 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
7501 }
7502 return JVMTI_ERROR_INVALID_CLASS;
7503 }
7504 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
7505 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7506 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7507 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7508 }
7509 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
7510 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
7511 }
7512 return JVMTI_ERROR_INVALID_CLASS;
7513 }
7514
7515 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
7516 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
7517 JvmtiTrace::get_class_name(k_mirror));
7518 }
7519 err = jvmti_env->GetClassSignature(k_mirror, signature_ptr, generic_ptr);
7520 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7521 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7522 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
7523 JvmtiTrace::get_class_name(k_mirror));
7524 }
7525 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
7526 JvmtiUtil::error_name(err));
7527 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
7528 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
7529 }
7530 return err;
7531#endif // INCLUDE_JVMTI
7532}
7533
7534static jvmtiError JNICALL
7535jvmtiTrace_GetClassStatus(jvmtiEnv* env,
7536 jclass klass,
7537 jint* status_ptr) {
7538
7539#if !INCLUDE_JVMTI
7540 return JVMTI_ERROR_NOT_AVAILABLE;
7541#else
7542 SafeResourceMark rm;
7543 jint trace_flags = JvmtiTrace::trace_flags(49);
7544 const char *func_name = NULL;
7545 const char *curr_thread_name = NULL;
7546 if (trace_flags) {
7547 func_name = JvmtiTrace::function_name(49);
7548 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
7549 }
7550 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
7551 if (trace_flags) {
7552 log_trace(jvmti)("[-] %s %s", func_name,
7553 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
7554 }
7555 return JVMTI_ERROR_WRONG_PHASE;
7556 }
7557 Thread* this_thread = Thread::current_or_null();
7558 if (this_thread == NULL || !this_thread->is_Java_thread()) {
7559 if (trace_flags) {
7560 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
7561 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
7562 }
7563 return JVMTI_ERROR_UNATTACHED_THREAD;
7564 }
7565 JavaThread* current_thread = (JavaThread*)this_thread;
7566 ThreadInVMfromNative __tiv(current_thread);
7567 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetClassStatus , current_thread)
7568 debug_only(VMNativeEntryWrapper __vew;)
7569 CautiouslyPreserveExceptionMark __em(this_thread);
7570 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
7571 if (!jvmti_env->is_valid()) {
7572 if (trace_flags) {
7573 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
7574 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
7575 }
7576 return JVMTI_ERROR_INVALID_ENVIRONMENT;
7577 }
7578 jvmtiError err;
7579 oop k_mirror = JNIHandles::resolve_external_guard(klass);
7580 if (k_mirror == NULL) {
7581 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7582 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7583 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7584 }
7585 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
7586 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
7587 }
7588 return JVMTI_ERROR_INVALID_CLASS;
7589 }
7590 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
7591 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7592 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7593 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7594 }
7595 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
7596 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
7597 }
7598 return JVMTI_ERROR_INVALID_CLASS;
7599 }
7600 if (status_ptr == NULL) {
7601 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7602 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7603 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
7604 JvmtiTrace::get_class_name(k_mirror));
7605 }
7606 log_error(jvmti)("[%s] %s } %s - erroneous arg is status_ptr", curr_thread_name, func_name,
7607 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7608 }
7609 return JVMTI_ERROR_NULL_POINTER;
7610 }
7611
7612 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
7613 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
7614 JvmtiTrace::get_class_name(k_mirror));
7615 }
7616 err = jvmti_env->GetClassStatus(k_mirror, status_ptr);
7617 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7618 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7619 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
7620 JvmtiTrace::get_class_name(k_mirror));
7621 }
7622 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
7623 JvmtiUtil::error_name(err));
7624 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
7625 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
7626 }
7627 return err;
7628#endif // INCLUDE_JVMTI
7629}
7630
7631static jvmtiError JNICALL
7632jvmtiTrace_GetSourceFileName(jvmtiEnv* env,
7633 jclass klass,
7634 char** source_name_ptr) {
7635
7636#if !INCLUDE_JVMTI
7637 return JVMTI_ERROR_NOT_AVAILABLE;
7638#else
7639 SafeResourceMark rm;
7640 jint trace_flags = JvmtiTrace::trace_flags(50);
7641 const char *func_name = NULL;
7642 const char *curr_thread_name = NULL;
7643 if (trace_flags) {
7644 func_name = JvmtiTrace::function_name(50);
7645 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
7646 }
7647 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
7648 if (trace_flags) {
7649 log_trace(jvmti)("[-] %s %s", func_name,
7650 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
7651 }
7652 return JVMTI_ERROR_WRONG_PHASE;
7653 }
7654 Thread* this_thread = Thread::current_or_null();
7655 if (this_thread == NULL || !this_thread->is_Java_thread()) {
7656 if (trace_flags) {
7657 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
7658 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
7659 }
7660 return JVMTI_ERROR_UNATTACHED_THREAD;
7661 }
7662 JavaThread* current_thread = (JavaThread*)this_thread;
7663 ThreadInVMfromNative __tiv(current_thread);
7664 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetSourceFileName , current_thread)
7665 debug_only(VMNativeEntryWrapper __vew;)
7666 CautiouslyPreserveExceptionMark __em(this_thread);
7667 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
7668 if (!jvmti_env->is_valid()) {
7669 if (trace_flags) {
7670 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
7671 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
7672 }
7673 return JVMTI_ERROR_INVALID_ENVIRONMENT;
7674 }
7675
7676 if (jvmti_env->get_capabilities()->can_get_source_file_name == 0) {
7677 if (trace_flags) {
7678 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
7679 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
7680 }
7681 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
7682 }
7683 jvmtiError err;
7684 oop k_mirror = JNIHandles::resolve_external_guard(klass);
7685 if (k_mirror == NULL) {
7686 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7687 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7688 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7689 }
7690 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
7691 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
7692 }
7693 return JVMTI_ERROR_INVALID_CLASS;
7694 }
7695 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
7696 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7697 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7698 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7699 }
7700 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
7701 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
7702 }
7703 return JVMTI_ERROR_INVALID_CLASS;
7704 }
7705 if (source_name_ptr == NULL) {
7706 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7707 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7708 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
7709 JvmtiTrace::get_class_name(k_mirror));
7710 }
7711 log_error(jvmti)("[%s] %s } %s - erroneous arg is source_name_ptr", curr_thread_name, func_name,
7712 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7713 }
7714 return JVMTI_ERROR_NULL_POINTER;
7715 }
7716
7717 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
7718 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
7719 JvmtiTrace::get_class_name(k_mirror));
7720 }
7721 err = jvmti_env->GetSourceFileName(k_mirror, source_name_ptr);
7722 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7723 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7724 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
7725 JvmtiTrace::get_class_name(k_mirror));
7726 }
7727 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
7728 JvmtiUtil::error_name(err));
7729 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
7730 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
7731 }
7732 return err;
7733#endif // INCLUDE_JVMTI
7734}
7735
7736static jvmtiError JNICALL
7737jvmtiTrace_GetClassModifiers(jvmtiEnv* env,
7738 jclass klass,
7739 jint* modifiers_ptr) {
7740
7741#if !INCLUDE_JVMTI
7742 return JVMTI_ERROR_NOT_AVAILABLE;
7743#else
7744 SafeResourceMark rm;
7745 jint trace_flags = JvmtiTrace::trace_flags(51);
7746 const char *func_name = NULL;
7747 const char *curr_thread_name = NULL;
7748 if (trace_flags) {
7749 func_name = JvmtiTrace::function_name(51);
7750 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
7751 }
7752 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
7753 if (trace_flags) {
7754 log_trace(jvmti)("[-] %s %s", func_name,
7755 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
7756 }
7757 return JVMTI_ERROR_WRONG_PHASE;
7758 }
7759 Thread* this_thread = Thread::current_or_null();
7760 if (this_thread == NULL || !this_thread->is_Java_thread()) {
7761 if (trace_flags) {
7762 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
7763 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
7764 }
7765 return JVMTI_ERROR_UNATTACHED_THREAD;
7766 }
7767 JavaThread* current_thread = (JavaThread*)this_thread;
7768 ThreadInVMfromNative __tiv(current_thread);
7769 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetClassModifiers , current_thread)
7770 debug_only(VMNativeEntryWrapper __vew;)
7771 CautiouslyPreserveExceptionMark __em(this_thread);
7772 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
7773 if (!jvmti_env->is_valid()) {
7774 if (trace_flags) {
7775 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
7776 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
7777 }
7778 return JVMTI_ERROR_INVALID_ENVIRONMENT;
7779 }
7780 jvmtiError err;
7781 oop k_mirror = JNIHandles::resolve_external_guard(klass);
7782 if (k_mirror == NULL) {
7783 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7784 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7785 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7786 }
7787 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
7788 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
7789 }
7790 return JVMTI_ERROR_INVALID_CLASS;
7791 }
7792 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
7793 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7794 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7795 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7796 }
7797 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
7798 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
7799 }
7800 return JVMTI_ERROR_INVALID_CLASS;
7801 }
7802 if (modifiers_ptr == NULL) {
7803 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7804 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7805 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
7806 JvmtiTrace::get_class_name(k_mirror));
7807 }
7808 log_error(jvmti)("[%s] %s } %s - erroneous arg is modifiers_ptr", curr_thread_name, func_name,
7809 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7810 }
7811 return JVMTI_ERROR_NULL_POINTER;
7812 }
7813
7814 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
7815 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
7816 JvmtiTrace::get_class_name(k_mirror));
7817 }
7818 err = jvmti_env->GetClassModifiers(k_mirror, modifiers_ptr);
7819 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7820 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7821 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
7822 JvmtiTrace::get_class_name(k_mirror));
7823 }
7824 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
7825 JvmtiUtil::error_name(err));
7826 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
7827 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
7828 }
7829 return err;
7830#endif // INCLUDE_JVMTI
7831}
7832
7833static jvmtiError JNICALL
7834jvmtiTrace_GetClassMethods(jvmtiEnv* env,
7835 jclass klass,
7836 jint* method_count_ptr,
7837 jmethodID** methods_ptr) {
7838
7839#if !INCLUDE_JVMTI
7840 return JVMTI_ERROR_NOT_AVAILABLE;
7841#else
7842 SafeResourceMark rm;
7843 jint trace_flags = JvmtiTrace::trace_flags(52);
7844 const char *func_name = NULL;
7845 const char *curr_thread_name = NULL;
7846 if (trace_flags) {
7847 func_name = JvmtiTrace::function_name(52);
7848 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
7849 }
7850 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
7851 if (trace_flags) {
7852 log_trace(jvmti)("[-] %s %s", func_name,
7853 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
7854 }
7855 return JVMTI_ERROR_WRONG_PHASE;
7856 }
7857 Thread* this_thread = Thread::current_or_null();
7858 if (this_thread == NULL || !this_thread->is_Java_thread()) {
7859 if (trace_flags) {
7860 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
7861 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
7862 }
7863 return JVMTI_ERROR_UNATTACHED_THREAD;
7864 }
7865 JavaThread* current_thread = (JavaThread*)this_thread;
7866 ThreadInVMfromNative __tiv(current_thread);
7867 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetClassMethods , current_thread)
7868 debug_only(VMNativeEntryWrapper __vew;)
7869 CautiouslyPreserveExceptionMark __em(this_thread);
7870 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
7871 if (!jvmti_env->is_valid()) {
7872 if (trace_flags) {
7873 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
7874 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
7875 }
7876 return JVMTI_ERROR_INVALID_ENVIRONMENT;
7877 }
7878 jvmtiError err;
7879 oop k_mirror = JNIHandles::resolve_external_guard(klass);
7880 if (k_mirror == NULL) {
7881 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7882 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7883 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7884 }
7885 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
7886 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
7887 }
7888 return JVMTI_ERROR_INVALID_CLASS;
7889 }
7890 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
7891 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7892 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7893 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7894 }
7895 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
7896 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
7897 }
7898 return JVMTI_ERROR_INVALID_CLASS;
7899 }
7900 if (method_count_ptr == NULL) {
7901 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7902 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7903 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
7904 JvmtiTrace::get_class_name(k_mirror));
7905 }
7906 log_error(jvmti)("[%s] %s } %s - erroneous arg is method_count_ptr", curr_thread_name, func_name,
7907 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7908 }
7909 return JVMTI_ERROR_NULL_POINTER;
7910 }
7911 if (methods_ptr == NULL) {
7912 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7913 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7914 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
7915 JvmtiTrace::get_class_name(k_mirror));
7916 }
7917 log_error(jvmti)("[%s] %s } %s - erroneous arg is methods_ptr", curr_thread_name, func_name,
7918 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
7919 }
7920 return JVMTI_ERROR_NULL_POINTER;
7921 }
7922
7923 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
7924 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
7925 JvmtiTrace::get_class_name(k_mirror));
7926 }
7927 err = jvmti_env->GetClassMethods(k_mirror, method_count_ptr, methods_ptr);
7928 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7929 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7930 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
7931 JvmtiTrace::get_class_name(k_mirror));
7932 }
7933 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
7934 JvmtiUtil::error_name(err));
7935 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
7936 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
7937 }
7938 return err;
7939#endif // INCLUDE_JVMTI
7940}
7941
7942static jvmtiError JNICALL
7943jvmtiTrace_GetClassFields(jvmtiEnv* env,
7944 jclass klass,
7945 jint* field_count_ptr,
7946 jfieldID** fields_ptr) {
7947
7948#if !INCLUDE_JVMTI
7949 return JVMTI_ERROR_NOT_AVAILABLE;
7950#else
7951 SafeResourceMark rm;
7952 jint trace_flags = JvmtiTrace::trace_flags(53);
7953 const char *func_name = NULL;
7954 const char *curr_thread_name = NULL;
7955 if (trace_flags) {
7956 func_name = JvmtiTrace::function_name(53);
7957 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
7958 }
7959 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
7960 if (trace_flags) {
7961 log_trace(jvmti)("[-] %s %s", func_name,
7962 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
7963 }
7964 return JVMTI_ERROR_WRONG_PHASE;
7965 }
7966 Thread* this_thread = Thread::current_or_null();
7967 if (this_thread == NULL || !this_thread->is_Java_thread()) {
7968 if (trace_flags) {
7969 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
7970 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
7971 }
7972 return JVMTI_ERROR_UNATTACHED_THREAD;
7973 }
7974 JavaThread* current_thread = (JavaThread*)this_thread;
7975 ThreadInVMfromNative __tiv(current_thread);
7976 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetClassFields , current_thread)
7977 debug_only(VMNativeEntryWrapper __vew;)
7978 CautiouslyPreserveExceptionMark __em(this_thread);
7979 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
7980 if (!jvmti_env->is_valid()) {
7981 if (trace_flags) {
7982 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
7983 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
7984 }
7985 return JVMTI_ERROR_INVALID_ENVIRONMENT;
7986 }
7987 jvmtiError err;
7988 oop k_mirror = JNIHandles::resolve_external_guard(klass);
7989 if (k_mirror == NULL) {
7990 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
7991 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
7992 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
7993 }
7994 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
7995 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
7996 }
7997 return JVMTI_ERROR_INVALID_CLASS;
7998 }
7999 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
8000 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8001 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8002 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8003 }
8004 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8005 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8006 }
8007 return JVMTI_ERROR_INVALID_CLASS;
8008 }
8009 if (field_count_ptr == NULL) {
8010 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8011 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8012 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8013 JvmtiTrace::get_class_name(k_mirror));
8014 }
8015 log_error(jvmti)("[%s] %s } %s - erroneous arg is field_count_ptr", curr_thread_name, func_name,
8016 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
8017 }
8018 return JVMTI_ERROR_NULL_POINTER;
8019 }
8020 if (fields_ptr == NULL) {
8021 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8022 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8023 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8024 JvmtiTrace::get_class_name(k_mirror));
8025 }
8026 log_error(jvmti)("[%s] %s } %s - erroneous arg is fields_ptr", curr_thread_name, func_name,
8027 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
8028 }
8029 return JVMTI_ERROR_NULL_POINTER;
8030 }
8031
8032 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
8033 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8034 JvmtiTrace::get_class_name(k_mirror));
8035 }
8036 err = jvmti_env->GetClassFields(k_mirror, field_count_ptr, fields_ptr);
8037 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8038 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8039 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8040 JvmtiTrace::get_class_name(k_mirror));
8041 }
8042 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
8043 JvmtiUtil::error_name(err));
8044 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
8045 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
8046 }
8047 return err;
8048#endif // INCLUDE_JVMTI
8049}
8050
8051static jvmtiError JNICALL
8052jvmtiTrace_GetImplementedInterfaces(jvmtiEnv* env,
8053 jclass klass,
8054 jint* interface_count_ptr,
8055 jclass** interfaces_ptr) {
8056
8057#if !INCLUDE_JVMTI
8058 return JVMTI_ERROR_NOT_AVAILABLE;
8059#else
8060 SafeResourceMark rm;
8061 jint trace_flags = JvmtiTrace::trace_flags(54);
8062 const char *func_name = NULL;
8063 const char *curr_thread_name = NULL;
8064 if (trace_flags) {
8065 func_name = JvmtiTrace::function_name(54);
8066 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
8067 }
8068 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
8069 if (trace_flags) {
8070 log_trace(jvmti)("[-] %s %s", func_name,
8071 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
8072 }
8073 return JVMTI_ERROR_WRONG_PHASE;
8074 }
8075 Thread* this_thread = Thread::current_or_null();
8076 if (this_thread == NULL || !this_thread->is_Java_thread()) {
8077 if (trace_flags) {
8078 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
8079 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
8080 }
8081 return JVMTI_ERROR_UNATTACHED_THREAD;
8082 }
8083 JavaThread* current_thread = (JavaThread*)this_thread;
8084 ThreadInVMfromNative __tiv(current_thread);
8085 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetImplementedInterfaces , current_thread)
8086 debug_only(VMNativeEntryWrapper __vew;)
8087 CautiouslyPreserveExceptionMark __em(this_thread);
8088 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
8089 if (!jvmti_env->is_valid()) {
8090 if (trace_flags) {
8091 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
8092 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
8093 }
8094 return JVMTI_ERROR_INVALID_ENVIRONMENT;
8095 }
8096 jvmtiError err;
8097 oop k_mirror = JNIHandles::resolve_external_guard(klass);
8098 if (k_mirror == NULL) {
8099 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8100 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8101 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8102 }
8103 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8104 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8105 }
8106 return JVMTI_ERROR_INVALID_CLASS;
8107 }
8108 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
8109 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8110 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8111 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8112 }
8113 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8114 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8115 }
8116 return JVMTI_ERROR_INVALID_CLASS;
8117 }
8118 if (interface_count_ptr == NULL) {
8119 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8120 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8121 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8122 JvmtiTrace::get_class_name(k_mirror));
8123 }
8124 log_error(jvmti)("[%s] %s } %s - erroneous arg is interface_count_ptr", curr_thread_name, func_name,
8125 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
8126 }
8127 return JVMTI_ERROR_NULL_POINTER;
8128 }
8129 if (interfaces_ptr == NULL) {
8130 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8131 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8132 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8133 JvmtiTrace::get_class_name(k_mirror));
8134 }
8135 log_error(jvmti)("[%s] %s } %s - erroneous arg is interfaces_ptr", curr_thread_name, func_name,
8136 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
8137 }
8138 return JVMTI_ERROR_NULL_POINTER;
8139 }
8140
8141 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
8142 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8143 JvmtiTrace::get_class_name(k_mirror));
8144 }
8145 err = jvmti_env->GetImplementedInterfaces(k_mirror, interface_count_ptr, interfaces_ptr);
8146 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8147 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8148 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8149 JvmtiTrace::get_class_name(k_mirror));
8150 }
8151 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
8152 JvmtiUtil::error_name(err));
8153 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
8154 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
8155 }
8156 return err;
8157#endif // INCLUDE_JVMTI
8158}
8159
8160static jvmtiError JNICALL
8161jvmtiTrace_GetClassVersionNumbers(jvmtiEnv* env,
8162 jclass klass,
8163 jint* minor_version_ptr,
8164 jint* major_version_ptr) {
8165
8166#if !INCLUDE_JVMTI
8167 return JVMTI_ERROR_NOT_AVAILABLE;
8168#else
8169 SafeResourceMark rm;
8170 jint trace_flags = JvmtiTrace::trace_flags(145);
8171 const char *func_name = NULL;
8172 const char *curr_thread_name = NULL;
8173 if (trace_flags) {
8174 func_name = JvmtiTrace::function_name(145);
8175 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
8176 }
8177 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
8178 if (trace_flags) {
8179 log_trace(jvmti)("[-] %s %s", func_name,
8180 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
8181 }
8182 return JVMTI_ERROR_WRONG_PHASE;
8183 }
8184 Thread* this_thread = Thread::current_or_null();
8185 if (this_thread == NULL || !this_thread->is_Java_thread()) {
8186 if (trace_flags) {
8187 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
8188 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
8189 }
8190 return JVMTI_ERROR_UNATTACHED_THREAD;
8191 }
8192 JavaThread* current_thread = (JavaThread*)this_thread;
8193 ThreadInVMfromNative __tiv(current_thread);
8194 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetClassVersionNumbers , current_thread)
8195 debug_only(VMNativeEntryWrapper __vew;)
8196 CautiouslyPreserveExceptionMark __em(this_thread);
8197 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
8198 if (!jvmti_env->is_valid()) {
8199 if (trace_flags) {
8200 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
8201 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
8202 }
8203 return JVMTI_ERROR_INVALID_ENVIRONMENT;
8204 }
8205 jvmtiError err;
8206 oop k_mirror = JNIHandles::resolve_external_guard(klass);
8207 if (k_mirror == NULL) {
8208 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8209 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8210 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8211 }
8212 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8213 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8214 }
8215 return JVMTI_ERROR_INVALID_CLASS;
8216 }
8217 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
8218 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8219 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8220 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8221 }
8222 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8223 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8224 }
8225 return JVMTI_ERROR_INVALID_CLASS;
8226 }
8227 if (minor_version_ptr == NULL) {
8228 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8229 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8230 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8231 JvmtiTrace::get_class_name(k_mirror));
8232 }
8233 log_error(jvmti)("[%s] %s } %s - erroneous arg is minor_version_ptr", curr_thread_name, func_name,
8234 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
8235 }
8236 return JVMTI_ERROR_NULL_POINTER;
8237 }
8238 if (major_version_ptr == NULL) {
8239 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8240 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8241 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8242 JvmtiTrace::get_class_name(k_mirror));
8243 }
8244 log_error(jvmti)("[%s] %s } %s - erroneous arg is major_version_ptr", curr_thread_name, func_name,
8245 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
8246 }
8247 return JVMTI_ERROR_NULL_POINTER;
8248 }
8249
8250 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
8251 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8252 JvmtiTrace::get_class_name(k_mirror));
8253 }
8254 err = jvmti_env->GetClassVersionNumbers(k_mirror, minor_version_ptr, major_version_ptr);
8255 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8256 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8257 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8258 JvmtiTrace::get_class_name(k_mirror));
8259 }
8260 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
8261 JvmtiUtil::error_name(err));
8262 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
8263 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
8264 }
8265 return err;
8266#endif // INCLUDE_JVMTI
8267}
8268
8269static jvmtiError JNICALL
8270jvmtiTrace_GetConstantPool(jvmtiEnv* env,
8271 jclass klass,
8272 jint* constant_pool_count_ptr,
8273 jint* constant_pool_byte_count_ptr,
8274 unsigned char** constant_pool_bytes_ptr) {
8275
8276#if !INCLUDE_JVMTI
8277 return JVMTI_ERROR_NOT_AVAILABLE;
8278#else
8279 SafeResourceMark rm;
8280 jint trace_flags = JvmtiTrace::trace_flags(146);
8281 const char *func_name = NULL;
8282 const char *curr_thread_name = NULL;
8283 if (trace_flags) {
8284 func_name = JvmtiTrace::function_name(146);
8285 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
8286 }
8287 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
8288 if (trace_flags) {
8289 log_trace(jvmti)("[-] %s %s", func_name,
8290 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
8291 }
8292 return JVMTI_ERROR_WRONG_PHASE;
8293 }
8294 Thread* this_thread = Thread::current_or_null();
8295 if (this_thread == NULL || !this_thread->is_Java_thread()) {
8296 if (trace_flags) {
8297 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
8298 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
8299 }
8300 return JVMTI_ERROR_UNATTACHED_THREAD;
8301 }
8302 JavaThread* current_thread = (JavaThread*)this_thread;
8303 ThreadInVMfromNative __tiv(current_thread);
8304 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetConstantPool , current_thread)
8305 debug_only(VMNativeEntryWrapper __vew;)
8306 CautiouslyPreserveExceptionMark __em(this_thread);
8307 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
8308 if (!jvmti_env->is_valid()) {
8309 if (trace_flags) {
8310 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
8311 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
8312 }
8313 return JVMTI_ERROR_INVALID_ENVIRONMENT;
8314 }
8315
8316 if (jvmti_env->get_capabilities()->can_get_constant_pool == 0) {
8317 if (trace_flags) {
8318 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
8319 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
8320 }
8321 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
8322 }
8323 jvmtiError err;
8324 oop k_mirror = JNIHandles::resolve_external_guard(klass);
8325 if (k_mirror == NULL) {
8326 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8327 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8328 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8329 }
8330 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8331 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8332 }
8333 return JVMTI_ERROR_INVALID_CLASS;
8334 }
8335 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
8336 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8337 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8338 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8339 }
8340 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8341 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8342 }
8343 return JVMTI_ERROR_INVALID_CLASS;
8344 }
8345 if (constant_pool_count_ptr == NULL) {
8346 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8347 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8348 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8349 JvmtiTrace::get_class_name(k_mirror));
8350 }
8351 log_error(jvmti)("[%s] %s } %s - erroneous arg is constant_pool_count_ptr", curr_thread_name, func_name,
8352 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
8353 }
8354 return JVMTI_ERROR_NULL_POINTER;
8355 }
8356 if (constant_pool_byte_count_ptr == NULL) {
8357 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8358 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8359 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8360 JvmtiTrace::get_class_name(k_mirror));
8361 }
8362 log_error(jvmti)("[%s] %s } %s - erroneous arg is constant_pool_byte_count_ptr", curr_thread_name, func_name,
8363 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
8364 }
8365 return JVMTI_ERROR_NULL_POINTER;
8366 }
8367 if (constant_pool_bytes_ptr == NULL) {
8368 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8369 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8370 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8371 JvmtiTrace::get_class_name(k_mirror));
8372 }
8373 log_error(jvmti)("[%s] %s } %s - erroneous arg is constant_pool_bytes_ptr", curr_thread_name, func_name,
8374 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
8375 }
8376 return JVMTI_ERROR_NULL_POINTER;
8377 }
8378
8379 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
8380 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8381 JvmtiTrace::get_class_name(k_mirror));
8382 }
8383 err = jvmti_env->GetConstantPool(k_mirror, constant_pool_count_ptr, constant_pool_byte_count_ptr, constant_pool_bytes_ptr);
8384 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8385 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8386 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8387 JvmtiTrace::get_class_name(k_mirror));
8388 }
8389 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
8390 JvmtiUtil::error_name(err));
8391 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
8392 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
8393 }
8394 return err;
8395#endif // INCLUDE_JVMTI
8396}
8397
8398static jvmtiError JNICALL
8399jvmtiTrace_IsInterface(jvmtiEnv* env,
8400 jclass klass,
8401 jboolean* is_interface_ptr) {
8402
8403#if !INCLUDE_JVMTI
8404 return JVMTI_ERROR_NOT_AVAILABLE;
8405#else
8406 SafeResourceMark rm;
8407 jint trace_flags = JvmtiTrace::trace_flags(55);
8408 const char *func_name = NULL;
8409 const char *curr_thread_name = NULL;
8410 if (trace_flags) {
8411 func_name = JvmtiTrace::function_name(55);
8412 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
8413 }
8414 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
8415 if (trace_flags) {
8416 log_trace(jvmti)("[-] %s %s", func_name,
8417 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
8418 }
8419 return JVMTI_ERROR_WRONG_PHASE;
8420 }
8421 Thread* this_thread = Thread::current_or_null();
8422 if (this_thread == NULL || !this_thread->is_Java_thread()) {
8423 if (trace_flags) {
8424 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
8425 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
8426 }
8427 return JVMTI_ERROR_UNATTACHED_THREAD;
8428 }
8429 JavaThread* current_thread = (JavaThread*)this_thread;
8430 ThreadInVMfromNative __tiv(current_thread);
8431 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_IsInterface , current_thread)
8432 debug_only(VMNativeEntryWrapper __vew;)
8433 CautiouslyPreserveExceptionMark __em(this_thread);
8434 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
8435 if (!jvmti_env->is_valid()) {
8436 if (trace_flags) {
8437 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
8438 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
8439 }
8440 return JVMTI_ERROR_INVALID_ENVIRONMENT;
8441 }
8442 jvmtiError err;
8443 oop k_mirror = JNIHandles::resolve_external_guard(klass);
8444 if (k_mirror == NULL) {
8445 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8446 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8447 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8448 }
8449 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8450 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8451 }
8452 return JVMTI_ERROR_INVALID_CLASS;
8453 }
8454 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
8455 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8456 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8457 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8458 }
8459 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8460 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8461 }
8462 return JVMTI_ERROR_INVALID_CLASS;
8463 }
8464 if (is_interface_ptr == NULL) {
8465 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8466 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8467 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8468 JvmtiTrace::get_class_name(k_mirror));
8469 }
8470 log_error(jvmti)("[%s] %s } %s - erroneous arg is is_interface_ptr", curr_thread_name, func_name,
8471 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
8472 }
8473 return JVMTI_ERROR_NULL_POINTER;
8474 }
8475
8476 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
8477 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8478 JvmtiTrace::get_class_name(k_mirror));
8479 }
8480 err = jvmti_env->IsInterface(k_mirror, is_interface_ptr);
8481 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8482 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8483 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8484 JvmtiTrace::get_class_name(k_mirror));
8485 }
8486 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
8487 JvmtiUtil::error_name(err));
8488 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
8489 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
8490 }
8491 return err;
8492#endif // INCLUDE_JVMTI
8493}
8494
8495static jvmtiError JNICALL
8496jvmtiTrace_IsArrayClass(jvmtiEnv* env,
8497 jclass klass,
8498 jboolean* is_array_class_ptr) {
8499
8500#if !INCLUDE_JVMTI
8501 return JVMTI_ERROR_NOT_AVAILABLE;
8502#else
8503 SafeResourceMark rm;
8504 jint trace_flags = JvmtiTrace::trace_flags(56);
8505 const char *func_name = NULL;
8506 const char *curr_thread_name = NULL;
8507 if (trace_flags) {
8508 func_name = JvmtiTrace::function_name(56);
8509 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
8510 }
8511 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
8512 if (trace_flags) {
8513 log_trace(jvmti)("[-] %s %s", func_name,
8514 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
8515 }
8516 return JVMTI_ERROR_WRONG_PHASE;
8517 }
8518 Thread* this_thread = Thread::current_or_null();
8519 if (this_thread == NULL || !this_thread->is_Java_thread()) {
8520 if (trace_flags) {
8521 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
8522 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
8523 }
8524 return JVMTI_ERROR_UNATTACHED_THREAD;
8525 }
8526 JavaThread* current_thread = (JavaThread*)this_thread;
8527 ThreadInVMfromNative __tiv(current_thread);
8528 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_IsArrayClass , current_thread)
8529 debug_only(VMNativeEntryWrapper __vew;)
8530 CautiouslyPreserveExceptionMark __em(this_thread);
8531 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
8532 if (!jvmti_env->is_valid()) {
8533 if (trace_flags) {
8534 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
8535 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
8536 }
8537 return JVMTI_ERROR_INVALID_ENVIRONMENT;
8538 }
8539 jvmtiError err;
8540 oop k_mirror = JNIHandles::resolve_external_guard(klass);
8541 if (k_mirror == NULL) {
8542 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8543 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8544 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8545 }
8546 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8547 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8548 }
8549 return JVMTI_ERROR_INVALID_CLASS;
8550 }
8551 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
8552 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8553 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8554 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8555 }
8556 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8557 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8558 }
8559 return JVMTI_ERROR_INVALID_CLASS;
8560 }
8561 if (is_array_class_ptr == NULL) {
8562 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8563 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8564 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8565 JvmtiTrace::get_class_name(k_mirror));
8566 }
8567 log_error(jvmti)("[%s] %s } %s - erroneous arg is is_array_class_ptr", curr_thread_name, func_name,
8568 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
8569 }
8570 return JVMTI_ERROR_NULL_POINTER;
8571 }
8572
8573 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
8574 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8575 JvmtiTrace::get_class_name(k_mirror));
8576 }
8577 err = jvmti_env->IsArrayClass(k_mirror, is_array_class_ptr);
8578 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8579 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8580 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8581 JvmtiTrace::get_class_name(k_mirror));
8582 }
8583 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
8584 JvmtiUtil::error_name(err));
8585 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
8586 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
8587 }
8588 return err;
8589#endif // INCLUDE_JVMTI
8590}
8591
8592static jvmtiError JNICALL
8593jvmtiTrace_IsModifiableClass(jvmtiEnv* env,
8594 jclass klass,
8595 jboolean* is_modifiable_class_ptr) {
8596 SafeResourceMark rm;
8597 jint trace_flags = JvmtiTrace::trace_flags(45);
8598 const char *func_name = NULL;
8599 const char *curr_thread_name = NULL;
8600 if (trace_flags) {
8601 func_name = JvmtiTrace::function_name(45);
8602 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
8603 }
8604 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
8605 if (trace_flags) {
8606 log_trace(jvmti)("[-] %s %s", func_name,
8607 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
8608 }
8609 return JVMTI_ERROR_WRONG_PHASE;
8610 }
8611 Thread* this_thread = Thread::current_or_null();
8612 if (this_thread == NULL || !this_thread->is_Java_thread()) {
8613 if (trace_flags) {
8614 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
8615 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
8616 }
8617 return JVMTI_ERROR_UNATTACHED_THREAD;
8618 }
8619 JavaThread* current_thread = (JavaThread*)this_thread;
8620 ThreadInVMfromNative __tiv(current_thread);
8621 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_IsModifiableClass , current_thread)
8622 debug_only(VMNativeEntryWrapper __vew;)
8623 CautiouslyPreserveExceptionMark __em(this_thread);
8624 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
8625 if (!jvmti_env->is_valid()) {
8626 if (trace_flags) {
8627 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
8628 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
8629 }
8630 return JVMTI_ERROR_INVALID_ENVIRONMENT;
8631 }
8632 jvmtiError err;
8633 oop k_mirror = JNIHandles::resolve_external_guard(klass);
8634 if (k_mirror == NULL) {
8635 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8636 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8637 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8638 }
8639 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8640 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8641 }
8642 return JVMTI_ERROR_INVALID_CLASS;
8643 }
8644 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
8645 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8646 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8647 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8648 }
8649 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8650 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8651 }
8652 return JVMTI_ERROR_INVALID_CLASS;
8653 }
8654 if (is_modifiable_class_ptr == NULL) {
8655 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8656 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8657 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8658 JvmtiTrace::get_class_name(k_mirror));
8659 }
8660 log_error(jvmti)("[%s] %s } %s - erroneous arg is is_modifiable_class_ptr", curr_thread_name, func_name,
8661 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
8662 }
8663 return JVMTI_ERROR_NULL_POINTER;
8664 }
8665
8666 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
8667 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8668 JvmtiTrace::get_class_name(k_mirror));
8669 }
8670 err = jvmti_env->IsModifiableClass(k_mirror, is_modifiable_class_ptr);
8671 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8672 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8673 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8674 JvmtiTrace::get_class_name(k_mirror));
8675 }
8676 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
8677 JvmtiUtil::error_name(err));
8678 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
8679 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
8680 }
8681 return err;
8682}
8683
8684static jvmtiError JNICALL
8685jvmtiTrace_GetClassLoader(jvmtiEnv* env,
8686 jclass klass,
8687 jobject* classloader_ptr) {
8688
8689#if !INCLUDE_JVMTI
8690 return JVMTI_ERROR_NOT_AVAILABLE;
8691#else
8692 SafeResourceMark rm;
8693 jint trace_flags = JvmtiTrace::trace_flags(57);
8694 const char *func_name = NULL;
8695 const char *curr_thread_name = NULL;
8696 if (trace_flags) {
8697 func_name = JvmtiTrace::function_name(57);
8698 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
8699 }
8700 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
8701 if (trace_flags) {
8702 log_trace(jvmti)("[-] %s %s", func_name,
8703 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
8704 }
8705 return JVMTI_ERROR_WRONG_PHASE;
8706 }
8707 Thread* this_thread = Thread::current_or_null();
8708 if (this_thread == NULL || !this_thread->is_Java_thread()) {
8709 if (trace_flags) {
8710 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
8711 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
8712 }
8713 return JVMTI_ERROR_UNATTACHED_THREAD;
8714 }
8715 JavaThread* current_thread = (JavaThread*)this_thread;
8716 ThreadInVMfromNative __tiv(current_thread);
8717 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetClassLoader , current_thread)
8718 debug_only(VMNativeEntryWrapper __vew;)
8719 CautiouslyPreserveExceptionMark __em(this_thread);
8720 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
8721 if (!jvmti_env->is_valid()) {
8722 if (trace_flags) {
8723 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
8724 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
8725 }
8726 return JVMTI_ERROR_INVALID_ENVIRONMENT;
8727 }
8728 jvmtiError err;
8729 oop k_mirror = JNIHandles::resolve_external_guard(klass);
8730 if (k_mirror == NULL) {
8731 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8732 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8733 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8734 }
8735 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8736 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8737 }
8738 return JVMTI_ERROR_INVALID_CLASS;
8739 }
8740 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
8741 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8742 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8743 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8744 }
8745 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8746 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8747 }
8748 return JVMTI_ERROR_INVALID_CLASS;
8749 }
8750 if (classloader_ptr == NULL) {
8751 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8752 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8753 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8754 JvmtiTrace::get_class_name(k_mirror));
8755 }
8756 log_error(jvmti)("[%s] %s } %s - erroneous arg is classloader_ptr", curr_thread_name, func_name,
8757 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
8758 }
8759 return JVMTI_ERROR_NULL_POINTER;
8760 }
8761
8762 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
8763 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8764 JvmtiTrace::get_class_name(k_mirror));
8765 }
8766 err = jvmti_env->GetClassLoader(k_mirror, classloader_ptr);
8767 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8768 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8769 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8770 JvmtiTrace::get_class_name(k_mirror));
8771 }
8772 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
8773 JvmtiUtil::error_name(err));
8774 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
8775 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
8776 }
8777 return err;
8778#endif // INCLUDE_JVMTI
8779}
8780
8781static jvmtiError JNICALL
8782jvmtiTrace_GetSourceDebugExtension(jvmtiEnv* env,
8783 jclass klass,
8784 char** source_debug_extension_ptr) {
8785
8786#if !INCLUDE_JVMTI
8787 return JVMTI_ERROR_NOT_AVAILABLE;
8788#else
8789 SafeResourceMark rm;
8790 jint trace_flags = JvmtiTrace::trace_flags(90);
8791 const char *func_name = NULL;
8792 const char *curr_thread_name = NULL;
8793 if (trace_flags) {
8794 func_name = JvmtiTrace::function_name(90);
8795 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
8796 }
8797 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
8798 if (trace_flags) {
8799 log_trace(jvmti)("[-] %s %s", func_name,
8800 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
8801 }
8802 return JVMTI_ERROR_WRONG_PHASE;
8803 }
8804 Thread* this_thread = Thread::current_or_null();
8805 if (this_thread == NULL || !this_thread->is_Java_thread()) {
8806 if (trace_flags) {
8807 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
8808 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
8809 }
8810 return JVMTI_ERROR_UNATTACHED_THREAD;
8811 }
8812 JavaThread* current_thread = (JavaThread*)this_thread;
8813 ThreadInVMfromNative __tiv(current_thread);
8814 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetSourceDebugExtension , current_thread)
8815 debug_only(VMNativeEntryWrapper __vew;)
8816 CautiouslyPreserveExceptionMark __em(this_thread);
8817 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
8818 if (!jvmti_env->is_valid()) {
8819 if (trace_flags) {
8820 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
8821 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
8822 }
8823 return JVMTI_ERROR_INVALID_ENVIRONMENT;
8824 }
8825
8826 if (jvmti_env->get_capabilities()->can_get_source_debug_extension == 0) {
8827 if (trace_flags) {
8828 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
8829 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
8830 }
8831 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
8832 }
8833 jvmtiError err;
8834 oop k_mirror = JNIHandles::resolve_external_guard(klass);
8835 if (k_mirror == NULL) {
8836 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8837 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8838 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8839 }
8840 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8841 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8842 }
8843 return JVMTI_ERROR_INVALID_CLASS;
8844 }
8845 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
8846 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8847 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8848 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8849 }
8850 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
8851 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
8852 }
8853 return JVMTI_ERROR_INVALID_CLASS;
8854 }
8855 if (source_debug_extension_ptr == NULL) {
8856 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8857 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8858 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8859 JvmtiTrace::get_class_name(k_mirror));
8860 }
8861 log_error(jvmti)("[%s] %s } %s - erroneous arg is source_debug_extension_ptr", curr_thread_name, func_name,
8862 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
8863 }
8864 return JVMTI_ERROR_NULL_POINTER;
8865 }
8866
8867 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
8868 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8869 JvmtiTrace::get_class_name(k_mirror));
8870 }
8871 err = jvmti_env->GetSourceDebugExtension(k_mirror, source_debug_extension_ptr);
8872 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8873 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8874 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
8875 JvmtiTrace::get_class_name(k_mirror));
8876 }
8877 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
8878 JvmtiUtil::error_name(err));
8879 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
8880 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
8881 }
8882 return err;
8883#endif // INCLUDE_JVMTI
8884}
8885
8886static jvmtiError JNICALL
8887jvmtiTrace_RetransformClasses(jvmtiEnv* env,
8888 jint class_count,
8889 const jclass* classes) {
8890 SafeResourceMark rm;
8891 jint trace_flags = JvmtiTrace::trace_flags(152);
8892 const char *func_name = NULL;
8893 const char *curr_thread_name = NULL;
8894 if (trace_flags) {
8895 func_name = JvmtiTrace::function_name(152);
8896 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
8897 }
8898 if(!JvmtiEnv::is_vm_live()) {
8899 if (trace_flags) {
8900 log_trace(jvmti)("[-] %s %s(%d)", func_name,
8901 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
8902 }
8903 return JVMTI_ERROR_WRONG_PHASE;
8904 }
8905 Thread* this_thread = Thread::current_or_null();
8906 if (this_thread == NULL || !this_thread->is_Java_thread()) {
8907 if (trace_flags) {
8908 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
8909 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
8910 }
8911 return JVMTI_ERROR_UNATTACHED_THREAD;
8912 }
8913 JavaThread* current_thread = (JavaThread*)this_thread;
8914 ThreadInVMfromNative __tiv(current_thread);
8915 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_RetransformClasses , current_thread)
8916 debug_only(VMNativeEntryWrapper __vew;)
8917 CautiouslyPreserveExceptionMark __em(this_thread);
8918 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
8919 if (!jvmti_env->is_valid()) {
8920 if (trace_flags) {
8921 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
8922 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
8923 }
8924 return JVMTI_ERROR_INVALID_ENVIRONMENT;
8925 }
8926
8927 if (jvmti_env->get_capabilities()->can_retransform_classes == 0) {
8928 if (trace_flags) {
8929 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
8930 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
8931 }
8932 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
8933 }
8934 jvmtiError err;
8935 if (class_count < 0) {
8936 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8937 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8938 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
8939 }
8940 log_error(jvmti)("[%s] %s } %s - erroneous arg is class_count", curr_thread_name, func_name,
8941 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT));
8942 }
8943 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
8944 }
8945 if (classes == NULL) {
8946 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8947 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8948 log_trace(jvmti)("[%s] %s { class_count=" INT32_FORMAT "", curr_thread_name, func_name, class_count);
8949 }
8950 log_error(jvmti)("[%s] %s } %s - erroneous arg is classes", curr_thread_name, func_name,
8951 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
8952 }
8953 return JVMTI_ERROR_NULL_POINTER;
8954 }
8955
8956 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
8957 log_trace(jvmti)("[%s] %s { class_count=" INT32_FORMAT " classes=" PTR_FORMAT "", curr_thread_name, func_name, class_count,
8958 p2i(classes)
8959 );
8960 }
8961 err = jvmti_env->RetransformClasses(class_count, classes);
8962 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
8963 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
8964 log_trace(jvmti)("[%s] %s { class_count=" INT32_FORMAT " classes=" PTR_FORMAT "", curr_thread_name, func_name, class_count,
8965 p2i(classes)
8966 );
8967 }
8968 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
8969 JvmtiUtil::error_name(err));
8970 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
8971 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
8972 }
8973 return err;
8974}
8975
8976static jvmtiError JNICALL
8977jvmtiTrace_RedefineClasses(jvmtiEnv* env,
8978 jint class_count,
8979 const jvmtiClassDefinition* class_definitions) {
8980 SafeResourceMark rm;
8981 jint trace_flags = JvmtiTrace::trace_flags(87);
8982 const char *func_name = NULL;
8983 const char *curr_thread_name = NULL;
8984 if (trace_flags) {
8985 func_name = JvmtiTrace::function_name(87);
8986 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
8987 }
8988 if(!JvmtiEnv::is_vm_live()) {
8989 if (trace_flags) {
8990 log_trace(jvmti)("[-] %s %s(%d)", func_name,
8991 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
8992 }
8993 return JVMTI_ERROR_WRONG_PHASE;
8994 }
8995 Thread* this_thread = Thread::current_or_null();
8996 if (this_thread == NULL || !this_thread->is_Java_thread()) {
8997 if (trace_flags) {
8998 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
8999 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
9000 }
9001 return JVMTI_ERROR_UNATTACHED_THREAD;
9002 }
9003 JavaThread* current_thread = (JavaThread*)this_thread;
9004 ThreadInVMfromNative __tiv(current_thread);
9005 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_RedefineClasses , current_thread)
9006 debug_only(VMNativeEntryWrapper __vew;)
9007 CautiouslyPreserveExceptionMark __em(this_thread);
9008 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
9009 if (!jvmti_env->is_valid()) {
9010 if (trace_flags) {
9011 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
9012 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
9013 }
9014 return JVMTI_ERROR_INVALID_ENVIRONMENT;
9015 }
9016
9017 if (jvmti_env->get_capabilities()->can_redefine_classes == 0) {
9018 if (trace_flags) {
9019 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
9020 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
9021 }
9022 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
9023 }
9024 jvmtiError err;
9025 if (class_count < 0) {
9026 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9027 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9028 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9029 }
9030 log_error(jvmti)("[%s] %s } %s - erroneous arg is class_count", curr_thread_name, func_name,
9031 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT));
9032 }
9033 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
9034 }
9035 if (class_definitions == NULL) {
9036 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9037 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9038 log_trace(jvmti)("[%s] %s { class_count=" INT32_FORMAT "", curr_thread_name, func_name, class_count);
9039 }
9040 log_error(jvmti)("[%s] %s } %s - erroneous arg is class_definitions", curr_thread_name, func_name,
9041 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
9042 }
9043 return JVMTI_ERROR_NULL_POINTER;
9044 }
9045
9046 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
9047 log_trace(jvmti)("[%s] %s { class_count=" INT32_FORMAT " class_definitions=" PTR_FORMAT "", curr_thread_name, func_name, class_count,
9048 p2i(class_definitions)
9049 );
9050 }
9051 err = jvmti_env->RedefineClasses(class_count, class_definitions);
9052 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9053 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9054 log_trace(jvmti)("[%s] %s { class_count=" INT32_FORMAT " class_definitions=" PTR_FORMAT "", curr_thread_name, func_name, class_count,
9055 p2i(class_definitions)
9056 );
9057 }
9058 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
9059 JvmtiUtil::error_name(err));
9060 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
9061 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
9062 }
9063 return err;
9064}
9065
9066 //
9067 // Object functions
9068 //
9069
9070static jvmtiError JNICALL
9071jvmtiTrace_GetObjectSize(jvmtiEnv* env,
9072 jobject object,
9073 jlong* size_ptr) {
9074 SafeResourceMark rm;
9075 jint trace_flags = JvmtiTrace::trace_flags(154);
9076 const char *func_name = NULL;
9077 const char *curr_thread_name = NULL;
9078 if (trace_flags) {
9079 func_name = JvmtiTrace::function_name(154);
9080 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
9081 }
9082 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
9083 if (trace_flags) {
9084 log_trace(jvmti)("[-] %s %s", func_name,
9085 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
9086 }
9087 return JVMTI_ERROR_WRONG_PHASE;
9088 }
9089 Thread* this_thread = Thread::current_or_null();
9090 if (this_thread == NULL || !this_thread->is_Java_thread()) {
9091 if (trace_flags) {
9092 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
9093 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
9094 }
9095 return JVMTI_ERROR_UNATTACHED_THREAD;
9096 }
9097 JavaThread* current_thread = (JavaThread*)this_thread;
9098 ThreadInVMfromNative __tiv(current_thread);
9099 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetObjectSize , current_thread)
9100 debug_only(VMNativeEntryWrapper __vew;)
9101 CautiouslyPreserveExceptionMark __em(this_thread);
9102 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
9103 if (!jvmti_env->is_valid()) {
9104 if (trace_flags) {
9105 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
9106 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
9107 }
9108 return JVMTI_ERROR_INVALID_ENVIRONMENT;
9109 }
9110 jvmtiError err;
9111 if (size_ptr == NULL) {
9112 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9113 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9114 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9115 }
9116 log_error(jvmti)("[%s] %s } %s - erroneous arg is size_ptr", curr_thread_name, func_name,
9117 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
9118 }
9119 return JVMTI_ERROR_NULL_POINTER;
9120 }
9121
9122 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
9123 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9124 }
9125 err = jvmti_env->GetObjectSize(object, size_ptr);
9126 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9127 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9128 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9129 }
9130 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
9131 JvmtiUtil::error_name(err));
9132 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
9133 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
9134 }
9135 return err;
9136}
9137
9138static jvmtiError JNICALL
9139jvmtiTrace_GetObjectHashCode(jvmtiEnv* env,
9140 jobject object,
9141 jint* hash_code_ptr) {
9142
9143#if !INCLUDE_JVMTI
9144 return JVMTI_ERROR_NOT_AVAILABLE;
9145#else
9146 SafeResourceMark rm;
9147 jint trace_flags = JvmtiTrace::trace_flags(58);
9148 const char *func_name = NULL;
9149 const char *curr_thread_name = NULL;
9150 if (trace_flags) {
9151 func_name = JvmtiTrace::function_name(58);
9152 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
9153 }
9154 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
9155 if (trace_flags) {
9156 log_trace(jvmti)("[-] %s %s", func_name,
9157 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
9158 }
9159 return JVMTI_ERROR_WRONG_PHASE;
9160 }
9161 Thread* this_thread = Thread::current_or_null();
9162 if (this_thread == NULL || !this_thread->is_Java_thread()) {
9163 if (trace_flags) {
9164 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
9165 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
9166 }
9167 return JVMTI_ERROR_UNATTACHED_THREAD;
9168 }
9169 JavaThread* current_thread = (JavaThread*)this_thread;
9170 ThreadInVMfromNative __tiv(current_thread);
9171 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetObjectHashCode , current_thread)
9172 debug_only(VMNativeEntryWrapper __vew;)
9173 CautiouslyPreserveExceptionMark __em(this_thread);
9174 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
9175 if (!jvmti_env->is_valid()) {
9176 if (trace_flags) {
9177 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
9178 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
9179 }
9180 return JVMTI_ERROR_INVALID_ENVIRONMENT;
9181 }
9182 jvmtiError err;
9183 if (hash_code_ptr == NULL) {
9184 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9185 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9186 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9187 }
9188 log_error(jvmti)("[%s] %s } %s - erroneous arg is hash_code_ptr", curr_thread_name, func_name,
9189 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
9190 }
9191 return JVMTI_ERROR_NULL_POINTER;
9192 }
9193
9194 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
9195 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9196 }
9197 err = jvmti_env->GetObjectHashCode(object, hash_code_ptr);
9198 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9199 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9200 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9201 }
9202 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
9203 JvmtiUtil::error_name(err));
9204 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
9205 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
9206 }
9207 return err;
9208#endif // INCLUDE_JVMTI
9209}
9210
9211static jvmtiError JNICALL
9212jvmtiTrace_GetObjectMonitorUsage(jvmtiEnv* env,
9213 jobject object,
9214 jvmtiMonitorUsage* info_ptr) {
9215
9216#if !INCLUDE_JVMTI
9217 return JVMTI_ERROR_NOT_AVAILABLE;
9218#else
9219 SafeResourceMark rm;
9220 jint trace_flags = JvmtiTrace::trace_flags(59);
9221 const char *func_name = NULL;
9222 const char *curr_thread_name = NULL;
9223 if (trace_flags) {
9224 func_name = JvmtiTrace::function_name(59);
9225 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
9226 }
9227 if(!JvmtiEnv::is_vm_live()) {
9228 if (trace_flags) {
9229 log_trace(jvmti)("[-] %s %s(%d)", func_name,
9230 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
9231 }
9232 return JVMTI_ERROR_WRONG_PHASE;
9233 }
9234 Thread* this_thread = Thread::current_or_null();
9235 if (this_thread == NULL || !this_thread->is_Java_thread()) {
9236 if (trace_flags) {
9237 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
9238 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
9239 }
9240 return JVMTI_ERROR_UNATTACHED_THREAD;
9241 }
9242 JavaThread* current_thread = (JavaThread*)this_thread;
9243 ThreadInVMfromNative __tiv(current_thread);
9244 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetObjectMonitorUsage , current_thread)
9245 debug_only(VMNativeEntryWrapper __vew;)
9246 CautiouslyPreserveExceptionMark __em(this_thread);
9247 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
9248 if (!jvmti_env->is_valid()) {
9249 if (trace_flags) {
9250 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
9251 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
9252 }
9253 return JVMTI_ERROR_INVALID_ENVIRONMENT;
9254 }
9255
9256 if (jvmti_env->get_capabilities()->can_get_monitor_info == 0) {
9257 if (trace_flags) {
9258 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
9259 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
9260 }
9261 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
9262 }
9263 jvmtiError err;
9264 if (info_ptr == NULL) {
9265 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9266 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9267 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9268 }
9269 log_error(jvmti)("[%s] %s } %s - erroneous arg is info_ptr", curr_thread_name, func_name,
9270 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
9271 }
9272 return JVMTI_ERROR_NULL_POINTER;
9273 }
9274
9275 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
9276 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9277 }
9278 err = jvmti_env->GetObjectMonitorUsage(object, info_ptr);
9279 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9280 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9281 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9282 }
9283 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
9284 JvmtiUtil::error_name(err));
9285 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
9286 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
9287 }
9288 return err;
9289#endif // INCLUDE_JVMTI
9290}
9291
9292 //
9293 // Field functions
9294 //
9295
9296static jvmtiError JNICALL
9297jvmtiTrace_GetFieldName(jvmtiEnv* env,
9298 jclass klass,
9299 jfieldID field,
9300 char** name_ptr,
9301 char** signature_ptr,
9302 char** generic_ptr) {
9303
9304#if !INCLUDE_JVMTI
9305 return JVMTI_ERROR_NOT_AVAILABLE;
9306#else
9307 SafeResourceMark rm;
9308 jint trace_flags = JvmtiTrace::trace_flags(60);
9309 const char *func_name = NULL;
9310 const char *curr_thread_name = NULL;
9311 if (trace_flags) {
9312 func_name = JvmtiTrace::function_name(60);
9313 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
9314 }
9315 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
9316 if (trace_flags) {
9317 log_trace(jvmti)("[-] %s %s", func_name,
9318 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
9319 }
9320 return JVMTI_ERROR_WRONG_PHASE;
9321 }
9322 Thread* this_thread = Thread::current_or_null();
9323 if (this_thread == NULL || !this_thread->is_Java_thread()) {
9324 if (trace_flags) {
9325 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
9326 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
9327 }
9328 return JVMTI_ERROR_UNATTACHED_THREAD;
9329 }
9330 JavaThread* current_thread = (JavaThread*)this_thread;
9331 ThreadInVMfromNative __tiv(current_thread);
9332 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetFieldName , current_thread)
9333 debug_only(VMNativeEntryWrapper __vew;)
9334 CautiouslyPreserveExceptionMark __em(this_thread);
9335 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
9336 if (!jvmti_env->is_valid()) {
9337 if (trace_flags) {
9338 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
9339 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
9340 }
9341 return JVMTI_ERROR_INVALID_ENVIRONMENT;
9342 }
9343 jvmtiError err;
9344 oop k_mirror = JNIHandles::resolve_external_guard(klass);
9345 if (k_mirror == NULL) {
9346 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9347 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9348 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9349 }
9350 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9351 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9352 }
9353 return JVMTI_ERROR_INVALID_CLASS;
9354 }
9355 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
9356 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9357 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9358 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9359 }
9360 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9361 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9362 }
9363 return JVMTI_ERROR_INVALID_CLASS;
9364 }
9365
9366 if (java_lang_Class::is_primitive(k_mirror)) {
9367 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9368 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9369 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9370 }
9371 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - is a primitive class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9372 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9373 }
9374 return JVMTI_ERROR_INVALID_CLASS;
9375 }
9376 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
9377 if (k_oop == NULL) {
9378 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9379 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9380 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9381 }
9382 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - no Klass* - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9383 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9384 }
9385 return JVMTI_ERROR_INVALID_CLASS;
9386 }
9387 ResourceMark rm_fdesc(current_thread);
9388 fieldDescriptor fdesc;
9389 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
9390 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9391 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9392 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
9393 JvmtiTrace::get_class_name(k_mirror));
9394 }
9395 log_error(jvmti)("[%s] %s } %s - erroneous arg is field", curr_thread_name, func_name,
9396 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_FIELDID));
9397 }
9398 return JVMTI_ERROR_INVALID_FIELDID;
9399 }
9400
9401 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
9402 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
9403 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
9404 }
9405 err = jvmti_env->GetFieldName(&fdesc, name_ptr, signature_ptr, generic_ptr);
9406 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9407 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9408 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
9409 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
9410 }
9411 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
9412 JvmtiUtil::error_name(err));
9413 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
9414 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
9415 }
9416 return err;
9417#endif // INCLUDE_JVMTI
9418}
9419
9420static jvmtiError JNICALL
9421jvmtiTrace_GetFieldDeclaringClass(jvmtiEnv* env,
9422 jclass klass,
9423 jfieldID field,
9424 jclass* declaring_class_ptr) {
9425
9426#if !INCLUDE_JVMTI
9427 return JVMTI_ERROR_NOT_AVAILABLE;
9428#else
9429 SafeResourceMark rm;
9430 jint trace_flags = JvmtiTrace::trace_flags(61);
9431 const char *func_name = NULL;
9432 const char *curr_thread_name = NULL;
9433 if (trace_flags) {
9434 func_name = JvmtiTrace::function_name(61);
9435 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
9436 }
9437 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
9438 if (trace_flags) {
9439 log_trace(jvmti)("[-] %s %s", func_name,
9440 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
9441 }
9442 return JVMTI_ERROR_WRONG_PHASE;
9443 }
9444 Thread* this_thread = Thread::current_or_null();
9445 if (this_thread == NULL || !this_thread->is_Java_thread()) {
9446 if (trace_flags) {
9447 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
9448 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
9449 }
9450 return JVMTI_ERROR_UNATTACHED_THREAD;
9451 }
9452 JavaThread* current_thread = (JavaThread*)this_thread;
9453 ThreadInVMfromNative __tiv(current_thread);
9454 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetFieldDeclaringClass , current_thread)
9455 debug_only(VMNativeEntryWrapper __vew;)
9456 CautiouslyPreserveExceptionMark __em(this_thread);
9457 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
9458 if (!jvmti_env->is_valid()) {
9459 if (trace_flags) {
9460 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
9461 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
9462 }
9463 return JVMTI_ERROR_INVALID_ENVIRONMENT;
9464 }
9465 jvmtiError err;
9466 oop k_mirror = JNIHandles::resolve_external_guard(klass);
9467 if (k_mirror == NULL) {
9468 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9469 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9470 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9471 }
9472 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9473 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9474 }
9475 return JVMTI_ERROR_INVALID_CLASS;
9476 }
9477 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
9478 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9479 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9480 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9481 }
9482 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9483 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9484 }
9485 return JVMTI_ERROR_INVALID_CLASS;
9486 }
9487
9488 if (java_lang_Class::is_primitive(k_mirror)) {
9489 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9490 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9491 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9492 }
9493 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - is a primitive class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9494 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9495 }
9496 return JVMTI_ERROR_INVALID_CLASS;
9497 }
9498 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
9499 if (k_oop == NULL) {
9500 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9501 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9502 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9503 }
9504 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - no Klass* - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9505 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9506 }
9507 return JVMTI_ERROR_INVALID_CLASS;
9508 }
9509 ResourceMark rm_fdesc(current_thread);
9510 fieldDescriptor fdesc;
9511 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
9512 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9513 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9514 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
9515 JvmtiTrace::get_class_name(k_mirror));
9516 }
9517 log_error(jvmti)("[%s] %s } %s - erroneous arg is field", curr_thread_name, func_name,
9518 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_FIELDID));
9519 }
9520 return JVMTI_ERROR_INVALID_FIELDID;
9521 }
9522 if (declaring_class_ptr == NULL) {
9523 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9524 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9525 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
9526 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
9527 }
9528 log_error(jvmti)("[%s] %s } %s - erroneous arg is declaring_class_ptr", curr_thread_name, func_name,
9529 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
9530 }
9531 return JVMTI_ERROR_NULL_POINTER;
9532 }
9533
9534 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
9535 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
9536 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
9537 }
9538 err = jvmti_env->GetFieldDeclaringClass(&fdesc, declaring_class_ptr);
9539 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9540 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9541 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
9542 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
9543 }
9544 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
9545 JvmtiUtil::error_name(err));
9546 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
9547 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
9548 }
9549 return err;
9550#endif // INCLUDE_JVMTI
9551}
9552
9553static jvmtiError JNICALL
9554jvmtiTrace_GetFieldModifiers(jvmtiEnv* env,
9555 jclass klass,
9556 jfieldID field,
9557 jint* modifiers_ptr) {
9558
9559#if !INCLUDE_JVMTI
9560 return JVMTI_ERROR_NOT_AVAILABLE;
9561#else
9562 SafeResourceMark rm;
9563 jint trace_flags = JvmtiTrace::trace_flags(62);
9564 const char *func_name = NULL;
9565 const char *curr_thread_name = NULL;
9566 if (trace_flags) {
9567 func_name = JvmtiTrace::function_name(62);
9568 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
9569 }
9570 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
9571 if (trace_flags) {
9572 log_trace(jvmti)("[-] %s %s", func_name,
9573 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
9574 }
9575 return JVMTI_ERROR_WRONG_PHASE;
9576 }
9577 Thread* this_thread = Thread::current_or_null();
9578 if (this_thread == NULL || !this_thread->is_Java_thread()) {
9579 if (trace_flags) {
9580 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
9581 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
9582 }
9583 return JVMTI_ERROR_UNATTACHED_THREAD;
9584 }
9585 JavaThread* current_thread = (JavaThread*)this_thread;
9586 ThreadInVMfromNative __tiv(current_thread);
9587 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetFieldModifiers , current_thread)
9588 debug_only(VMNativeEntryWrapper __vew;)
9589 CautiouslyPreserveExceptionMark __em(this_thread);
9590 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
9591 if (!jvmti_env->is_valid()) {
9592 if (trace_flags) {
9593 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
9594 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
9595 }
9596 return JVMTI_ERROR_INVALID_ENVIRONMENT;
9597 }
9598 jvmtiError err;
9599 oop k_mirror = JNIHandles::resolve_external_guard(klass);
9600 if (k_mirror == NULL) {
9601 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9602 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9603 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9604 }
9605 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9606 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9607 }
9608 return JVMTI_ERROR_INVALID_CLASS;
9609 }
9610 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
9611 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9612 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9613 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9614 }
9615 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9616 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9617 }
9618 return JVMTI_ERROR_INVALID_CLASS;
9619 }
9620
9621 if (java_lang_Class::is_primitive(k_mirror)) {
9622 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9623 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9624 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9625 }
9626 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - is a primitive class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9627 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9628 }
9629 return JVMTI_ERROR_INVALID_CLASS;
9630 }
9631 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
9632 if (k_oop == NULL) {
9633 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9634 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9635 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9636 }
9637 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - no Klass* - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9638 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9639 }
9640 return JVMTI_ERROR_INVALID_CLASS;
9641 }
9642 ResourceMark rm_fdesc(current_thread);
9643 fieldDescriptor fdesc;
9644 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
9645 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9646 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9647 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
9648 JvmtiTrace::get_class_name(k_mirror));
9649 }
9650 log_error(jvmti)("[%s] %s } %s - erroneous arg is field", curr_thread_name, func_name,
9651 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_FIELDID));
9652 }
9653 return JVMTI_ERROR_INVALID_FIELDID;
9654 }
9655 if (modifiers_ptr == NULL) {
9656 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9657 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9658 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
9659 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
9660 }
9661 log_error(jvmti)("[%s] %s } %s - erroneous arg is modifiers_ptr", curr_thread_name, func_name,
9662 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
9663 }
9664 return JVMTI_ERROR_NULL_POINTER;
9665 }
9666
9667 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
9668 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
9669 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
9670 }
9671 err = jvmti_env->GetFieldModifiers(&fdesc, modifiers_ptr);
9672 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9673 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9674 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
9675 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
9676 }
9677 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
9678 JvmtiUtil::error_name(err));
9679 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
9680 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
9681 }
9682 return err;
9683#endif // INCLUDE_JVMTI
9684}
9685
9686static jvmtiError JNICALL
9687jvmtiTrace_IsFieldSynthetic(jvmtiEnv* env,
9688 jclass klass,
9689 jfieldID field,
9690 jboolean* is_synthetic_ptr) {
9691
9692#if !INCLUDE_JVMTI
9693 return JVMTI_ERROR_NOT_AVAILABLE;
9694#else
9695 SafeResourceMark rm;
9696 jint trace_flags = JvmtiTrace::trace_flags(63);
9697 const char *func_name = NULL;
9698 const char *curr_thread_name = NULL;
9699 if (trace_flags) {
9700 func_name = JvmtiTrace::function_name(63);
9701 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
9702 }
9703 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
9704 if (trace_flags) {
9705 log_trace(jvmti)("[-] %s %s", func_name,
9706 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
9707 }
9708 return JVMTI_ERROR_WRONG_PHASE;
9709 }
9710 Thread* this_thread = Thread::current_or_null();
9711 if (this_thread == NULL || !this_thread->is_Java_thread()) {
9712 if (trace_flags) {
9713 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
9714 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
9715 }
9716 return JVMTI_ERROR_UNATTACHED_THREAD;
9717 }
9718 JavaThread* current_thread = (JavaThread*)this_thread;
9719 ThreadInVMfromNative __tiv(current_thread);
9720 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_IsFieldSynthetic , current_thread)
9721 debug_only(VMNativeEntryWrapper __vew;)
9722 CautiouslyPreserveExceptionMark __em(this_thread);
9723 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
9724 if (!jvmti_env->is_valid()) {
9725 if (trace_flags) {
9726 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
9727 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
9728 }
9729 return JVMTI_ERROR_INVALID_ENVIRONMENT;
9730 }
9731
9732 if (jvmti_env->get_capabilities()->can_get_synthetic_attribute == 0) {
9733 if (trace_flags) {
9734 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
9735 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
9736 }
9737 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
9738 }
9739 jvmtiError err;
9740 oop k_mirror = JNIHandles::resolve_external_guard(klass);
9741 if (k_mirror == NULL) {
9742 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9743 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9744 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9745 }
9746 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - resolved to NULL - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9747 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9748 }
9749 return JVMTI_ERROR_INVALID_CLASS;
9750 }
9751 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
9752 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9753 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9754 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9755 }
9756 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - not a class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9757 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9758 }
9759 return JVMTI_ERROR_INVALID_CLASS;
9760 }
9761
9762 if (java_lang_Class::is_primitive(k_mirror)) {
9763 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9764 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9765 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9766 }
9767 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - is a primitive class - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9768 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9769 }
9770 return JVMTI_ERROR_INVALID_CLASS;
9771 }
9772 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
9773 if (k_oop == NULL) {
9774 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9775 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9776 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9777 }
9778 log_error(jvmti)("[%s] %s } %s - erroneous arg is klass - no Klass* - jclass = " PTR_FORMAT "", curr_thread_name, func_name,
9779 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_CLASS), p2i(klass));
9780 }
9781 return JVMTI_ERROR_INVALID_CLASS;
9782 }
9783 ResourceMark rm_fdesc(current_thread);
9784 fieldDescriptor fdesc;
9785 if (!JvmtiEnv::get_field_descriptor(k_oop, field, &fdesc)) {
9786 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9787 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9788 log_trace(jvmti)("[%s] %s { klass=%s", curr_thread_name, func_name,
9789 JvmtiTrace::get_class_name(k_mirror));
9790 }
9791 log_error(jvmti)("[%s] %s } %s - erroneous arg is field", curr_thread_name, func_name,
9792 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_FIELDID));
9793 }
9794 return JVMTI_ERROR_INVALID_FIELDID;
9795 }
9796 if (is_synthetic_ptr == NULL) {
9797 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9798 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9799 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
9800 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
9801 }
9802 log_error(jvmti)("[%s] %s } %s - erroneous arg is is_synthetic_ptr", curr_thread_name, func_name,
9803 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
9804 }
9805 return JVMTI_ERROR_NULL_POINTER;
9806 }
9807
9808 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
9809 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
9810 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
9811 }
9812 err = jvmti_env->IsFieldSynthetic(&fdesc, is_synthetic_ptr);
9813 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9814 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9815 log_trace(jvmti)("[%s] %s { klass=%s field=%s", curr_thread_name, func_name,
9816 JvmtiTrace::get_class_name(k_mirror), fdesc.name()->as_C_string());
9817 }
9818 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
9819 JvmtiUtil::error_name(err));
9820 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
9821 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
9822 }
9823 return err;
9824#endif // INCLUDE_JVMTI
9825}
9826
9827 //
9828 // Method functions
9829 //
9830
9831static jvmtiError JNICALL
9832jvmtiTrace_GetMethodName(jvmtiEnv* env,
9833 jmethodID method,
9834 char** name_ptr,
9835 char** signature_ptr,
9836 char** generic_ptr) {
9837
9838#if !INCLUDE_JVMTI
9839 return JVMTI_ERROR_NOT_AVAILABLE;
9840#else
9841 SafeResourceMark rm;
9842 jint trace_flags = JvmtiTrace::trace_flags(64);
9843 const char *func_name = NULL;
9844 const char *curr_thread_name = NULL;
9845 if (trace_flags) {
9846 func_name = JvmtiTrace::function_name(64);
9847 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
9848 }
9849 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
9850 if (trace_flags) {
9851 log_trace(jvmti)("[-] %s %s", func_name,
9852 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
9853 }
9854 return JVMTI_ERROR_WRONG_PHASE;
9855 }
9856 Thread* this_thread = Thread::current_or_null();
9857 if (this_thread == NULL || !this_thread->is_Java_thread()) {
9858 if (trace_flags) {
9859 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
9860 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
9861 }
9862 return JVMTI_ERROR_UNATTACHED_THREAD;
9863 }
9864 JavaThread* current_thread = (JavaThread*)this_thread;
9865 ThreadInVMfromNative __tiv(current_thread);
9866 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetMethodName , current_thread)
9867 debug_only(VMNativeEntryWrapper __vew;)
9868 CautiouslyPreserveExceptionMark __em(this_thread);
9869 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
9870 if (!jvmti_env->is_valid()) {
9871 if (trace_flags) {
9872 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
9873 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
9874 }
9875 return JVMTI_ERROR_INVALID_ENVIRONMENT;
9876 }
9877 jvmtiError err;
9878 Method* method_oop = Method::checked_resolve_jmethod_id(method);
9879 if (method_oop == NULL) {
9880 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9881 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9882 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9883 }
9884 log_error(jvmti)("[%s] %s } %s - erroneous arg is method", curr_thread_name, func_name,
9885 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_METHODID));
9886 }
9887 return JVMTI_ERROR_INVALID_METHODID;
9888 }
9889
9890 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
9891 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
9892 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
9893 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
9894 );
9895 }
9896 err = jvmti_env->GetMethodName(method_oop, name_ptr, signature_ptr, generic_ptr);
9897 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9898 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9899 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
9900 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
9901 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
9902 );
9903 }
9904 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
9905 JvmtiUtil::error_name(err));
9906 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
9907 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
9908 }
9909 return err;
9910#endif // INCLUDE_JVMTI
9911}
9912
9913static jvmtiError JNICALL
9914jvmtiTrace_GetMethodDeclaringClass(jvmtiEnv* env,
9915 jmethodID method,
9916 jclass* declaring_class_ptr) {
9917
9918#if !INCLUDE_JVMTI
9919 return JVMTI_ERROR_NOT_AVAILABLE;
9920#else
9921 SafeResourceMark rm;
9922 jint trace_flags = JvmtiTrace::trace_flags(65);
9923 const char *func_name = NULL;
9924 const char *curr_thread_name = NULL;
9925 if (trace_flags) {
9926 func_name = JvmtiTrace::function_name(65);
9927 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
9928 }
9929 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
9930 if (trace_flags) {
9931 log_trace(jvmti)("[-] %s %s", func_name,
9932 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
9933 }
9934 return JVMTI_ERROR_WRONG_PHASE;
9935 }
9936 Thread* this_thread = Thread::current_or_null();
9937 if (this_thread == NULL || !this_thread->is_Java_thread()) {
9938 if (trace_flags) {
9939 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
9940 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
9941 }
9942 return JVMTI_ERROR_UNATTACHED_THREAD;
9943 }
9944 JavaThread* current_thread = (JavaThread*)this_thread;
9945 ThreadInVMfromNative __tiv(current_thread);
9946 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetMethodDeclaringClass , current_thread)
9947 debug_only(VMNativeEntryWrapper __vew;)
9948 CautiouslyPreserveExceptionMark __em(this_thread);
9949 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
9950 if (!jvmti_env->is_valid()) {
9951 if (trace_flags) {
9952 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
9953 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
9954 }
9955 return JVMTI_ERROR_INVALID_ENVIRONMENT;
9956 }
9957 jvmtiError err;
9958 Method* method_oop = Method::checked_resolve_jmethod_id(method);
9959 if (method_oop == NULL) {
9960 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9961 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9962 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
9963 }
9964 log_error(jvmti)("[%s] %s } %s - erroneous arg is method", curr_thread_name, func_name,
9965 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_METHODID));
9966 }
9967 return JVMTI_ERROR_INVALID_METHODID;
9968 }
9969 if (declaring_class_ptr == NULL) {
9970 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9971 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9972 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
9973 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
9974 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
9975 );
9976 }
9977 log_error(jvmti)("[%s] %s } %s - erroneous arg is declaring_class_ptr", curr_thread_name, func_name,
9978 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
9979 }
9980 return JVMTI_ERROR_NULL_POINTER;
9981 }
9982
9983 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
9984 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
9985 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
9986 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
9987 );
9988 }
9989 err = jvmti_env->GetMethodDeclaringClass(method_oop, declaring_class_ptr);
9990 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
9991 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
9992 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
9993 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
9994 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
9995 );
9996 }
9997 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
9998 JvmtiUtil::error_name(err));
9999 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
10000 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
10001 }
10002 return err;
10003#endif // INCLUDE_JVMTI
10004}
10005
10006static jvmtiError JNICALL
10007jvmtiTrace_GetMethodModifiers(jvmtiEnv* env,
10008 jmethodID method,
10009 jint* modifiers_ptr) {
10010
10011#if !INCLUDE_JVMTI
10012 return JVMTI_ERROR_NOT_AVAILABLE;
10013#else
10014 SafeResourceMark rm;
10015 jint trace_flags = JvmtiTrace::trace_flags(66);
10016 const char *func_name = NULL;
10017 const char *curr_thread_name = NULL;
10018 if (trace_flags) {
10019 func_name = JvmtiTrace::function_name(66);
10020 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
10021 }
10022 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
10023 if (trace_flags) {
10024 log_trace(jvmti)("[-] %s %s", func_name,
10025 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
10026 }
10027 return JVMTI_ERROR_WRONG_PHASE;
10028 }
10029 Thread* this_thread = Thread::current_or_null();
10030 if (this_thread == NULL || !this_thread->is_Java_thread()) {
10031 if (trace_flags) {
10032 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
10033 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
10034 }
10035 return JVMTI_ERROR_UNATTACHED_THREAD;
10036 }
10037 JavaThread* current_thread = (JavaThread*)this_thread;
10038 ThreadInVMfromNative __tiv(current_thread);
10039 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetMethodModifiers , current_thread)
10040 debug_only(VMNativeEntryWrapper __vew;)
10041 CautiouslyPreserveExceptionMark __em(this_thread);
10042 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
10043 if (!jvmti_env->is_valid()) {
10044 if (trace_flags) {
10045 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
10046 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
10047 }
10048 return JVMTI_ERROR_INVALID_ENVIRONMENT;
10049 }
10050 jvmtiError err;
10051 Method* method_oop = Method::checked_resolve_jmethod_id(method);
10052 if (method_oop == NULL) {
10053 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10054 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10055 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
10056 }
10057 log_error(jvmti)("[%s] %s } %s - erroneous arg is method", curr_thread_name, func_name,
10058 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_METHODID));
10059 }
10060 return JVMTI_ERROR_INVALID_METHODID;
10061 }
10062 if (modifiers_ptr == NULL) {
10063 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10064 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10065 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10066 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10067 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10068 );
10069 }
10070 log_error(jvmti)("[%s] %s } %s - erroneous arg is modifiers_ptr", curr_thread_name, func_name,
10071 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
10072 }
10073 return JVMTI_ERROR_NULL_POINTER;
10074 }
10075
10076 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
10077 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10078 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10079 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10080 );
10081 }
10082 err = jvmti_env->GetMethodModifiers(method_oop, modifiers_ptr);
10083 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10084 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10085 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10086 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10087 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10088 );
10089 }
10090 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
10091 JvmtiUtil::error_name(err));
10092 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
10093 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
10094 }
10095 return err;
10096#endif // INCLUDE_JVMTI
10097}
10098
10099static jvmtiError JNICALL
10100jvmtiTrace_GetMaxLocals(jvmtiEnv* env,
10101 jmethodID method,
10102 jint* max_ptr) {
10103
10104#if !INCLUDE_JVMTI
10105 return JVMTI_ERROR_NOT_AVAILABLE;
10106#else
10107 SafeResourceMark rm;
10108 jint trace_flags = JvmtiTrace::trace_flags(68);
10109 const char *func_name = NULL;
10110 const char *curr_thread_name = NULL;
10111 if (trace_flags) {
10112 func_name = JvmtiTrace::function_name(68);
10113 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
10114 }
10115 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
10116 if (trace_flags) {
10117 log_trace(jvmti)("[-] %s %s", func_name,
10118 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
10119 }
10120 return JVMTI_ERROR_WRONG_PHASE;
10121 }
10122 Thread* this_thread = Thread::current_or_null();
10123 if (this_thread == NULL || !this_thread->is_Java_thread()) {
10124 if (trace_flags) {
10125 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
10126 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
10127 }
10128 return JVMTI_ERROR_UNATTACHED_THREAD;
10129 }
10130 JavaThread* current_thread = (JavaThread*)this_thread;
10131 ThreadInVMfromNative __tiv(current_thread);
10132 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetMaxLocals , current_thread)
10133 debug_only(VMNativeEntryWrapper __vew;)
10134 CautiouslyPreserveExceptionMark __em(this_thread);
10135 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
10136 if (!jvmti_env->is_valid()) {
10137 if (trace_flags) {
10138 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
10139 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
10140 }
10141 return JVMTI_ERROR_INVALID_ENVIRONMENT;
10142 }
10143 jvmtiError err;
10144 Method* method_oop = Method::checked_resolve_jmethod_id(method);
10145 if (method_oop == NULL) {
10146 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10147 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10148 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
10149 }
10150 log_error(jvmti)("[%s] %s } %s - erroneous arg is method", curr_thread_name, func_name,
10151 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_METHODID));
10152 }
10153 return JVMTI_ERROR_INVALID_METHODID;
10154 }
10155 if (method_oop->is_native()) {
10156 return JVMTI_ERROR_NATIVE_METHOD;
10157 }
10158 if (max_ptr == NULL) {
10159 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10160 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10161 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10162 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10163 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10164 );
10165 }
10166 log_error(jvmti)("[%s] %s } %s - erroneous arg is max_ptr", curr_thread_name, func_name,
10167 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
10168 }
10169 return JVMTI_ERROR_NULL_POINTER;
10170 }
10171
10172 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
10173 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10174 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10175 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10176 );
10177 }
10178 err = jvmti_env->GetMaxLocals(method_oop, max_ptr);
10179 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10180 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10181 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10182 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10183 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10184 );
10185 }
10186 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
10187 JvmtiUtil::error_name(err));
10188 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
10189 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
10190 }
10191 return err;
10192#endif // INCLUDE_JVMTI
10193}
10194
10195static jvmtiError JNICALL
10196jvmtiTrace_GetArgumentsSize(jvmtiEnv* env,
10197 jmethodID method,
10198 jint* size_ptr) {
10199
10200#if !INCLUDE_JVMTI
10201 return JVMTI_ERROR_NOT_AVAILABLE;
10202#else
10203 SafeResourceMark rm;
10204 jint trace_flags = JvmtiTrace::trace_flags(69);
10205 const char *func_name = NULL;
10206 const char *curr_thread_name = NULL;
10207 if (trace_flags) {
10208 func_name = JvmtiTrace::function_name(69);
10209 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
10210 }
10211 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
10212 if (trace_flags) {
10213 log_trace(jvmti)("[-] %s %s", func_name,
10214 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
10215 }
10216 return JVMTI_ERROR_WRONG_PHASE;
10217 }
10218 Thread* this_thread = Thread::current_or_null();
10219 if (this_thread == NULL || !this_thread->is_Java_thread()) {
10220 if (trace_flags) {
10221 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
10222 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
10223 }
10224 return JVMTI_ERROR_UNATTACHED_THREAD;
10225 }
10226 JavaThread* current_thread = (JavaThread*)this_thread;
10227 ThreadInVMfromNative __tiv(current_thread);
10228 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetArgumentsSize , current_thread)
10229 debug_only(VMNativeEntryWrapper __vew;)
10230 CautiouslyPreserveExceptionMark __em(this_thread);
10231 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
10232 if (!jvmti_env->is_valid()) {
10233 if (trace_flags) {
10234 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
10235 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
10236 }
10237 return JVMTI_ERROR_INVALID_ENVIRONMENT;
10238 }
10239 jvmtiError err;
10240 Method* method_oop = Method::checked_resolve_jmethod_id(method);
10241 if (method_oop == NULL) {
10242 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10243 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10244 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
10245 }
10246 log_error(jvmti)("[%s] %s } %s - erroneous arg is method", curr_thread_name, func_name,
10247 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_METHODID));
10248 }
10249 return JVMTI_ERROR_INVALID_METHODID;
10250 }
10251 if (method_oop->is_native()) {
10252 return JVMTI_ERROR_NATIVE_METHOD;
10253 }
10254 if (size_ptr == NULL) {
10255 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10256 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10257 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10258 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10259 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10260 );
10261 }
10262 log_error(jvmti)("[%s] %s } %s - erroneous arg is size_ptr", curr_thread_name, func_name,
10263 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
10264 }
10265 return JVMTI_ERROR_NULL_POINTER;
10266 }
10267
10268 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
10269 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10270 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10271 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10272 );
10273 }
10274 err = jvmti_env->GetArgumentsSize(method_oop, size_ptr);
10275 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10276 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10277 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10278 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10279 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10280 );
10281 }
10282 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
10283 JvmtiUtil::error_name(err));
10284 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
10285 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
10286 }
10287 return err;
10288#endif // INCLUDE_JVMTI
10289}
10290
10291static jvmtiError JNICALL
10292jvmtiTrace_GetLineNumberTable(jvmtiEnv* env,
10293 jmethodID method,
10294 jint* entry_count_ptr,
10295 jvmtiLineNumberEntry** table_ptr) {
10296
10297#if !INCLUDE_JVMTI
10298 return JVMTI_ERROR_NOT_AVAILABLE;
10299#else
10300 SafeResourceMark rm;
10301 jint trace_flags = JvmtiTrace::trace_flags(70);
10302 const char *func_name = NULL;
10303 const char *curr_thread_name = NULL;
10304 if (trace_flags) {
10305 func_name = JvmtiTrace::function_name(70);
10306 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
10307 }
10308 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
10309 if (trace_flags) {
10310 log_trace(jvmti)("[-] %s %s", func_name,
10311 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
10312 }
10313 return JVMTI_ERROR_WRONG_PHASE;
10314 }
10315 Thread* this_thread = Thread::current_or_null();
10316 if (this_thread == NULL || !this_thread->is_Java_thread()) {
10317 if (trace_flags) {
10318 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
10319 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
10320 }
10321 return JVMTI_ERROR_UNATTACHED_THREAD;
10322 }
10323 JavaThread* current_thread = (JavaThread*)this_thread;
10324 ThreadInVMfromNative __tiv(current_thread);
10325 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetLineNumberTable , current_thread)
10326 debug_only(VMNativeEntryWrapper __vew;)
10327 CautiouslyPreserveExceptionMark __em(this_thread);
10328 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
10329 if (!jvmti_env->is_valid()) {
10330 if (trace_flags) {
10331 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
10332 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
10333 }
10334 return JVMTI_ERROR_INVALID_ENVIRONMENT;
10335 }
10336
10337 if (jvmti_env->get_capabilities()->can_get_line_numbers == 0) {
10338 if (trace_flags) {
10339 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
10340 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
10341 }
10342 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
10343 }
10344 jvmtiError err;
10345 Method* method_oop = Method::checked_resolve_jmethod_id(method);
10346 if (method_oop == NULL) {
10347 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10348 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10349 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
10350 }
10351 log_error(jvmti)("[%s] %s } %s - erroneous arg is method", curr_thread_name, func_name,
10352 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_METHODID));
10353 }
10354 return JVMTI_ERROR_INVALID_METHODID;
10355 }
10356 if (method_oop->is_native()) {
10357 return JVMTI_ERROR_NATIVE_METHOD;
10358 }
10359 if (entry_count_ptr == NULL) {
10360 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10361 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10362 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10363 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10364 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10365 );
10366 }
10367 log_error(jvmti)("[%s] %s } %s - erroneous arg is entry_count_ptr", curr_thread_name, func_name,
10368 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
10369 }
10370 return JVMTI_ERROR_NULL_POINTER;
10371 }
10372 if (table_ptr == NULL) {
10373 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10374 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10375 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10376 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10377 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10378 );
10379 }
10380 log_error(jvmti)("[%s] %s } %s - erroneous arg is table_ptr", curr_thread_name, func_name,
10381 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
10382 }
10383 return JVMTI_ERROR_NULL_POINTER;
10384 }
10385
10386 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
10387 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10388 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10389 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10390 );
10391 }
10392 err = jvmti_env->GetLineNumberTable(method_oop, entry_count_ptr, table_ptr);
10393 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10394 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10395 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10396 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10397 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10398 );
10399 }
10400 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
10401 JvmtiUtil::error_name(err));
10402 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
10403 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
10404 }
10405 return err;
10406#endif // INCLUDE_JVMTI
10407}
10408
10409static jvmtiError JNICALL
10410jvmtiTrace_GetMethodLocation(jvmtiEnv* env,
10411 jmethodID method,
10412 jlocation* start_location_ptr,
10413 jlocation* end_location_ptr) {
10414
10415#if !INCLUDE_JVMTI
10416 return JVMTI_ERROR_NOT_AVAILABLE;
10417#else
10418 SafeResourceMark rm;
10419 jint trace_flags = JvmtiTrace::trace_flags(71);
10420 const char *func_name = NULL;
10421 const char *curr_thread_name = NULL;
10422 if (trace_flags) {
10423 func_name = JvmtiTrace::function_name(71);
10424 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
10425 }
10426 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
10427 if (trace_flags) {
10428 log_trace(jvmti)("[-] %s %s", func_name,
10429 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
10430 }
10431 return JVMTI_ERROR_WRONG_PHASE;
10432 }
10433 Thread* this_thread = Thread::current_or_null();
10434 if (this_thread == NULL || !this_thread->is_Java_thread()) {
10435 if (trace_flags) {
10436 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
10437 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
10438 }
10439 return JVMTI_ERROR_UNATTACHED_THREAD;
10440 }
10441 JavaThread* current_thread = (JavaThread*)this_thread;
10442 ThreadInVMfromNative __tiv(current_thread);
10443 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetMethodLocation , current_thread)
10444 debug_only(VMNativeEntryWrapper __vew;)
10445 CautiouslyPreserveExceptionMark __em(this_thread);
10446 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
10447 if (!jvmti_env->is_valid()) {
10448 if (trace_flags) {
10449 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
10450 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
10451 }
10452 return JVMTI_ERROR_INVALID_ENVIRONMENT;
10453 }
10454 jvmtiError err;
10455 Method* method_oop = Method::checked_resolve_jmethod_id(method);
10456 if (method_oop == NULL) {
10457 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10458 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10459 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
10460 }
10461 log_error(jvmti)("[%s] %s } %s - erroneous arg is method", curr_thread_name, func_name,
10462 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_METHODID));
10463 }
10464 return JVMTI_ERROR_INVALID_METHODID;
10465 }
10466 if (method_oop->is_native()) {
10467 return JVMTI_ERROR_NATIVE_METHOD;
10468 }
10469 if (start_location_ptr == NULL) {
10470 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10471 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10472 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10473 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10474 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10475 );
10476 }
10477 log_error(jvmti)("[%s] %s } %s - erroneous arg is start_location_ptr", curr_thread_name, func_name,
10478 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
10479 }
10480 return JVMTI_ERROR_NULL_POINTER;
10481 }
10482 if (end_location_ptr == NULL) {
10483 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10484 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10485 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10486 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10487 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10488 );
10489 }
10490 log_error(jvmti)("[%s] %s } %s - erroneous arg is end_location_ptr", curr_thread_name, func_name,
10491 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
10492 }
10493 return JVMTI_ERROR_NULL_POINTER;
10494 }
10495
10496 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
10497 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10498 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10499 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10500 );
10501 }
10502 err = jvmti_env->GetMethodLocation(method_oop, start_location_ptr, end_location_ptr);
10503 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10504 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10505 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10506 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10507 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10508 );
10509 }
10510 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
10511 JvmtiUtil::error_name(err));
10512 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
10513 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
10514 }
10515 return err;
10516#endif // INCLUDE_JVMTI
10517}
10518
10519static jvmtiError JNICALL
10520jvmtiTrace_GetLocalVariableTable(jvmtiEnv* env,
10521 jmethodID method,
10522 jint* entry_count_ptr,
10523 jvmtiLocalVariableEntry** table_ptr) {
10524
10525#if !INCLUDE_JVMTI
10526 return JVMTI_ERROR_NOT_AVAILABLE;
10527#else
10528 SafeResourceMark rm;
10529 jint trace_flags = JvmtiTrace::trace_flags(72);
10530 const char *func_name = NULL;
10531 const char *curr_thread_name = NULL;
10532 if (trace_flags) {
10533 func_name = JvmtiTrace::function_name(72);
10534 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
10535 }
10536 if(!JvmtiEnv::is_vm_live()) {
10537 if (trace_flags) {
10538 log_trace(jvmti)("[-] %s %s(%d)", func_name,
10539 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
10540 }
10541 return JVMTI_ERROR_WRONG_PHASE;
10542 }
10543 Thread* this_thread = Thread::current_or_null();
10544 if (this_thread == NULL || !this_thread->is_Java_thread()) {
10545 if (trace_flags) {
10546 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
10547 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
10548 }
10549 return JVMTI_ERROR_UNATTACHED_THREAD;
10550 }
10551 JavaThread* current_thread = (JavaThread*)this_thread;
10552 ThreadInVMfromNative __tiv(current_thread);
10553 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetLocalVariableTable , current_thread)
10554 debug_only(VMNativeEntryWrapper __vew;)
10555 CautiouslyPreserveExceptionMark __em(this_thread);
10556 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
10557 if (!jvmti_env->is_valid()) {
10558 if (trace_flags) {
10559 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
10560 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
10561 }
10562 return JVMTI_ERROR_INVALID_ENVIRONMENT;
10563 }
10564
10565 if (jvmti_env->get_capabilities()->can_access_local_variables == 0) {
10566 if (trace_flags) {
10567 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
10568 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
10569 }
10570 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
10571 }
10572 jvmtiError err;
10573 Method* method_oop = Method::checked_resolve_jmethod_id(method);
10574 if (method_oop == NULL) {
10575 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10576 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10577 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
10578 }
10579 log_error(jvmti)("[%s] %s } %s - erroneous arg is method", curr_thread_name, func_name,
10580 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_METHODID));
10581 }
10582 return JVMTI_ERROR_INVALID_METHODID;
10583 }
10584 if (method_oop->is_native()) {
10585 return JVMTI_ERROR_NATIVE_METHOD;
10586 }
10587 if (entry_count_ptr == NULL) {
10588 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10589 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10590 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10591 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10592 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10593 );
10594 }
10595 log_error(jvmti)("[%s] %s } %s - erroneous arg is entry_count_ptr", curr_thread_name, func_name,
10596 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
10597 }
10598 return JVMTI_ERROR_NULL_POINTER;
10599 }
10600 if (table_ptr == NULL) {
10601 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10602 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10603 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10604 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10605 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10606 );
10607 }
10608 log_error(jvmti)("[%s] %s } %s - erroneous arg is table_ptr", curr_thread_name, func_name,
10609 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
10610 }
10611 return JVMTI_ERROR_NULL_POINTER;
10612 }
10613
10614 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
10615 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10616 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10617 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10618 );
10619 }
10620 err = jvmti_env->GetLocalVariableTable(method_oop, entry_count_ptr, table_ptr);
10621 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10622 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10623 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10624 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10625 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10626 );
10627 }
10628 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
10629 JvmtiUtil::error_name(err));
10630 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
10631 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
10632 }
10633 return err;
10634#endif // INCLUDE_JVMTI
10635}
10636
10637static jvmtiError JNICALL
10638jvmtiTrace_GetBytecodes(jvmtiEnv* env,
10639 jmethodID method,
10640 jint* bytecode_count_ptr,
10641 unsigned char** bytecodes_ptr) {
10642
10643#if !INCLUDE_JVMTI
10644 return JVMTI_ERROR_NOT_AVAILABLE;
10645#else
10646 SafeResourceMark rm;
10647 jint trace_flags = JvmtiTrace::trace_flags(75);
10648 const char *func_name = NULL;
10649 const char *curr_thread_name = NULL;
10650 if (trace_flags) {
10651 func_name = JvmtiTrace::function_name(75);
10652 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
10653 }
10654 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
10655 if (trace_flags) {
10656 log_trace(jvmti)("[-] %s %s", func_name,
10657 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
10658 }
10659 return JVMTI_ERROR_WRONG_PHASE;
10660 }
10661 Thread* this_thread = Thread::current_or_null();
10662 if (this_thread == NULL || !this_thread->is_Java_thread()) {
10663 if (trace_flags) {
10664 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
10665 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
10666 }
10667 return JVMTI_ERROR_UNATTACHED_THREAD;
10668 }
10669 JavaThread* current_thread = (JavaThread*)this_thread;
10670 ThreadInVMfromNative __tiv(current_thread);
10671 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetBytecodes , current_thread)
10672 debug_only(VMNativeEntryWrapper __vew;)
10673 CautiouslyPreserveExceptionMark __em(this_thread);
10674 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
10675 if (!jvmti_env->is_valid()) {
10676 if (trace_flags) {
10677 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
10678 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
10679 }
10680 return JVMTI_ERROR_INVALID_ENVIRONMENT;
10681 }
10682
10683 if (jvmti_env->get_capabilities()->can_get_bytecodes == 0) {
10684 if (trace_flags) {
10685 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
10686 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
10687 }
10688 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
10689 }
10690 jvmtiError err;
10691 Method* method_oop = Method::checked_resolve_jmethod_id(method);
10692 if (method_oop == NULL) {
10693 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10694 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10695 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
10696 }
10697 log_error(jvmti)("[%s] %s } %s - erroneous arg is method", curr_thread_name, func_name,
10698 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_METHODID));
10699 }
10700 return JVMTI_ERROR_INVALID_METHODID;
10701 }
10702 if (method_oop->is_native()) {
10703 return JVMTI_ERROR_NATIVE_METHOD;
10704 }
10705 if (bytecode_count_ptr == NULL) {
10706 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10707 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10708 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10709 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10710 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10711 );
10712 }
10713 log_error(jvmti)("[%s] %s } %s - erroneous arg is bytecode_count_ptr", curr_thread_name, func_name,
10714 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
10715 }
10716 return JVMTI_ERROR_NULL_POINTER;
10717 }
10718 if (bytecodes_ptr == NULL) {
10719 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10720 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10721 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10722 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10723 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10724 );
10725 }
10726 log_error(jvmti)("[%s] %s } %s - erroneous arg is bytecodes_ptr", curr_thread_name, func_name,
10727 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
10728 }
10729 return JVMTI_ERROR_NULL_POINTER;
10730 }
10731
10732 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
10733 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10734 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10735 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10736 );
10737 }
10738 err = jvmti_env->GetBytecodes(method_oop, bytecode_count_ptr, bytecodes_ptr);
10739 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10740 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10741 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10742 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10743 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10744 );
10745 }
10746 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
10747 JvmtiUtil::error_name(err));
10748 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
10749 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
10750 }
10751 return err;
10752#endif // INCLUDE_JVMTI
10753}
10754
10755static jvmtiError JNICALL
10756jvmtiTrace_IsMethodNative(jvmtiEnv* env,
10757 jmethodID method,
10758 jboolean* is_native_ptr) {
10759
10760#if !INCLUDE_JVMTI
10761 return JVMTI_ERROR_NOT_AVAILABLE;
10762#else
10763 SafeResourceMark rm;
10764 jint trace_flags = JvmtiTrace::trace_flags(76);
10765 const char *func_name = NULL;
10766 const char *curr_thread_name = NULL;
10767 if (trace_flags) {
10768 func_name = JvmtiTrace::function_name(76);
10769 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
10770 }
10771 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
10772 if (trace_flags) {
10773 log_trace(jvmti)("[-] %s %s", func_name,
10774 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
10775 }
10776 return JVMTI_ERROR_WRONG_PHASE;
10777 }
10778 Thread* this_thread = Thread::current_or_null();
10779 if (this_thread == NULL || !this_thread->is_Java_thread()) {
10780 if (trace_flags) {
10781 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
10782 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
10783 }
10784 return JVMTI_ERROR_UNATTACHED_THREAD;
10785 }
10786 JavaThread* current_thread = (JavaThread*)this_thread;
10787 ThreadInVMfromNative __tiv(current_thread);
10788 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_IsMethodNative , current_thread)
10789 debug_only(VMNativeEntryWrapper __vew;)
10790 CautiouslyPreserveExceptionMark __em(this_thread);
10791 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
10792 if (!jvmti_env->is_valid()) {
10793 if (trace_flags) {
10794 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
10795 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
10796 }
10797 return JVMTI_ERROR_INVALID_ENVIRONMENT;
10798 }
10799 jvmtiError err;
10800 Method* method_oop = Method::checked_resolve_jmethod_id(method);
10801 if (method_oop == NULL) {
10802 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10803 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10804 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
10805 }
10806 log_error(jvmti)("[%s] %s } %s - erroneous arg is method", curr_thread_name, func_name,
10807 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_METHODID));
10808 }
10809 return JVMTI_ERROR_INVALID_METHODID;
10810 }
10811 if (is_native_ptr == NULL) {
10812 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10813 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10814 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10815 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10816 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10817 );
10818 }
10819 log_error(jvmti)("[%s] %s } %s - erroneous arg is is_native_ptr", curr_thread_name, func_name,
10820 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
10821 }
10822 return JVMTI_ERROR_NULL_POINTER;
10823 }
10824
10825 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
10826 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10827 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10828 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10829 );
10830 }
10831 err = jvmti_env->IsMethodNative(method_oop, is_native_ptr);
10832 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10833 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10834 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10835 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10836 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10837 );
10838 }
10839 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
10840 JvmtiUtil::error_name(err));
10841 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
10842 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
10843 }
10844 return err;
10845#endif // INCLUDE_JVMTI
10846}
10847
10848static jvmtiError JNICALL
10849jvmtiTrace_IsMethodSynthetic(jvmtiEnv* env,
10850 jmethodID method,
10851 jboolean* is_synthetic_ptr) {
10852
10853#if !INCLUDE_JVMTI
10854 return JVMTI_ERROR_NOT_AVAILABLE;
10855#else
10856 SafeResourceMark rm;
10857 jint trace_flags = JvmtiTrace::trace_flags(77);
10858 const char *func_name = NULL;
10859 const char *curr_thread_name = NULL;
10860 if (trace_flags) {
10861 func_name = JvmtiTrace::function_name(77);
10862 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
10863 }
10864 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
10865 if (trace_flags) {
10866 log_trace(jvmti)("[-] %s %s", func_name,
10867 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
10868 }
10869 return JVMTI_ERROR_WRONG_PHASE;
10870 }
10871 Thread* this_thread = Thread::current_or_null();
10872 if (this_thread == NULL || !this_thread->is_Java_thread()) {
10873 if (trace_flags) {
10874 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
10875 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
10876 }
10877 return JVMTI_ERROR_UNATTACHED_THREAD;
10878 }
10879 JavaThread* current_thread = (JavaThread*)this_thread;
10880 ThreadInVMfromNative __tiv(current_thread);
10881 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_IsMethodSynthetic , current_thread)
10882 debug_only(VMNativeEntryWrapper __vew;)
10883 CautiouslyPreserveExceptionMark __em(this_thread);
10884 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
10885 if (!jvmti_env->is_valid()) {
10886 if (trace_flags) {
10887 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
10888 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
10889 }
10890 return JVMTI_ERROR_INVALID_ENVIRONMENT;
10891 }
10892
10893 if (jvmti_env->get_capabilities()->can_get_synthetic_attribute == 0) {
10894 if (trace_flags) {
10895 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
10896 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
10897 }
10898 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
10899 }
10900 jvmtiError err;
10901 Method* method_oop = Method::checked_resolve_jmethod_id(method);
10902 if (method_oop == NULL) {
10903 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10904 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10905 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
10906 }
10907 log_error(jvmti)("[%s] %s } %s - erroneous arg is method", curr_thread_name, func_name,
10908 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_METHODID));
10909 }
10910 return JVMTI_ERROR_INVALID_METHODID;
10911 }
10912 if (is_synthetic_ptr == NULL) {
10913 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10914 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10915 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10916 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10917 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10918 );
10919 }
10920 log_error(jvmti)("[%s] %s } %s - erroneous arg is is_synthetic_ptr", curr_thread_name, func_name,
10921 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
10922 }
10923 return JVMTI_ERROR_NULL_POINTER;
10924 }
10925
10926 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
10927 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10928 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10929 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10930 );
10931 }
10932 err = jvmti_env->IsMethodSynthetic(method_oop, is_synthetic_ptr);
10933 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10934 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10935 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
10936 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
10937 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
10938 );
10939 }
10940 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
10941 JvmtiUtil::error_name(err));
10942 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
10943 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
10944 }
10945 return err;
10946#endif // INCLUDE_JVMTI
10947}
10948
10949static jvmtiError JNICALL
10950jvmtiTrace_IsMethodObsolete(jvmtiEnv* env,
10951 jmethodID method,
10952 jboolean* is_obsolete_ptr) {
10953
10954#if !INCLUDE_JVMTI
10955 return JVMTI_ERROR_NOT_AVAILABLE;
10956#else
10957 SafeResourceMark rm;
10958 jint trace_flags = JvmtiTrace::trace_flags(91);
10959 const char *func_name = NULL;
10960 const char *curr_thread_name = NULL;
10961 if (trace_flags) {
10962 func_name = JvmtiTrace::function_name(91);
10963 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
10964 }
10965 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
10966 if (trace_flags) {
10967 log_trace(jvmti)("[-] %s %s", func_name,
10968 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
10969 }
10970 return JVMTI_ERROR_WRONG_PHASE;
10971 }
10972 Thread* this_thread = Thread::current_or_null();
10973 if (this_thread == NULL || !this_thread->is_Java_thread()) {
10974 if (trace_flags) {
10975 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
10976 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
10977 }
10978 return JVMTI_ERROR_UNATTACHED_THREAD;
10979 }
10980 JavaThread* current_thread = (JavaThread*)this_thread;
10981 ThreadInVMfromNative __tiv(current_thread);
10982 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_IsMethodObsolete , current_thread)
10983 debug_only(VMNativeEntryWrapper __vew;)
10984 CautiouslyPreserveExceptionMark __em(this_thread);
10985 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
10986 if (!jvmti_env->is_valid()) {
10987 if (trace_flags) {
10988 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
10989 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
10990 }
10991 return JVMTI_ERROR_INVALID_ENVIRONMENT;
10992 }
10993 jvmtiError err;
10994 Method* method_oop = Method::checked_resolve_jmethod_id(method);
10995 if (method_oop == NULL) {
10996 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
10997 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
10998 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
10999 }
11000 log_error(jvmti)("[%s] %s } %s - erroneous arg is method", curr_thread_name, func_name,
11001 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_METHODID));
11002 }
11003 return JVMTI_ERROR_INVALID_METHODID;
11004 }
11005 if (is_obsolete_ptr == NULL) {
11006 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11007 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11008 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
11009 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
11010 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
11011 );
11012 }
11013 log_error(jvmti)("[%s] %s } %s - erroneous arg is is_obsolete_ptr", curr_thread_name, func_name,
11014 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
11015 }
11016 return JVMTI_ERROR_NULL_POINTER;
11017 }
11018
11019 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11020 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
11021 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
11022 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
11023 );
11024 }
11025 err = jvmti_env->IsMethodObsolete(method_oop, is_obsolete_ptr);
11026 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11027 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11028 log_trace(jvmti)("[%s] %s { method=%s.%s", curr_thread_name, func_name,
11029 method_oop == NULL? "NULL" : method_oop->klass_name()->as_C_string(),
11030 method_oop == NULL? "NULL" : method_oop->name()->as_C_string()
11031 );
11032 }
11033 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11034 JvmtiUtil::error_name(err));
11035 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11036 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11037 }
11038 return err;
11039#endif // INCLUDE_JVMTI
11040}
11041
11042static jvmtiError JNICALL
11043jvmtiTrace_SetNativeMethodPrefix(jvmtiEnv* env,
11044 const char* prefix) {
11045 SafeResourceMark rm;
11046 jint trace_flags = JvmtiTrace::trace_flags(73);
11047 const char *func_name = NULL;
11048 const char *curr_thread_name = NULL;
11049 if (trace_flags) {
11050 func_name = JvmtiTrace::function_name(73);
11051 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
11052 }
11053
11054 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
11055 if (!jvmti_env->is_valid()) {
11056 if (trace_flags) {
11057 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
11058 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
11059 }
11060 return JVMTI_ERROR_INVALID_ENVIRONMENT;
11061 }
11062
11063 if (jvmti_env->get_capabilities()->can_set_native_method_prefix == 0) {
11064 if (trace_flags) {
11065 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
11066 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
11067 }
11068 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
11069 }
11070 jvmtiError err;
11071 if (Threads::number_of_threads() != 0) {
11072 Thread* this_thread = Thread::current_or_null();
11073 if (this_thread == NULL || !this_thread->is_Java_thread()) {
11074 if (trace_flags) {
11075 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
11076 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
11077 }
11078 return JVMTI_ERROR_UNATTACHED_THREAD;
11079 }
11080 JavaThread* current_thread = (JavaThread*)this_thread;
11081 ThreadInVMfromNative __tiv(current_thread);
11082 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetNativeMethodPrefix , current_thread)
11083 debug_only(VMNativeEntryWrapper __vew;)
11084 CautiouslyPreserveExceptionMark __em(this_thread);
11085
11086 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11087 log_trace(jvmti)("[%s] %s { prefix='%s'", curr_thread_name, func_name, prefix);
11088 }
11089 err = jvmti_env->SetNativeMethodPrefix(prefix);
11090 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11091 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11092 log_trace(jvmti)("[%s] %s { prefix='%s'", curr_thread_name, func_name, prefix);
11093 }
11094 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11095 JvmtiUtil::error_name(err));
11096 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11097 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11098 }
11099 } else {
11100
11101 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11102 log_trace(jvmti)("[%s] %s { prefix='%s'", curr_thread_name, func_name, prefix);
11103 }
11104 err = jvmti_env->SetNativeMethodPrefix(prefix);
11105 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11106 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11107 log_trace(jvmti)("[%s] %s { prefix='%s'", curr_thread_name, func_name, prefix);
11108 }
11109 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11110 JvmtiUtil::error_name(err));
11111 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11112 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11113 }
11114 }
11115 return err;
11116}
11117
11118static jvmtiError JNICALL
11119jvmtiTrace_SetNativeMethodPrefixes(jvmtiEnv* env,
11120 jint prefix_count,
11121 char** prefixes) {
11122 SafeResourceMark rm;
11123 jint trace_flags = JvmtiTrace::trace_flags(74);
11124 const char *func_name = NULL;
11125 const char *curr_thread_name = NULL;
11126 if (trace_flags) {
11127 func_name = JvmtiTrace::function_name(74);
11128 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
11129 }
11130
11131 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
11132 if (!jvmti_env->is_valid()) {
11133 if (trace_flags) {
11134 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
11135 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
11136 }
11137 return JVMTI_ERROR_INVALID_ENVIRONMENT;
11138 }
11139
11140 if (jvmti_env->get_capabilities()->can_set_native_method_prefix == 0) {
11141 if (trace_flags) {
11142 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
11143 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
11144 }
11145 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
11146 }
11147 jvmtiError err;
11148 if (Threads::number_of_threads() != 0) {
11149 Thread* this_thread = Thread::current_or_null();
11150 if (this_thread == NULL || !this_thread->is_Java_thread()) {
11151 if (trace_flags) {
11152 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
11153 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
11154 }
11155 return JVMTI_ERROR_UNATTACHED_THREAD;
11156 }
11157 JavaThread* current_thread = (JavaThread*)this_thread;
11158 ThreadInVMfromNative __tiv(current_thread);
11159 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetNativeMethodPrefixes , current_thread)
11160 debug_only(VMNativeEntryWrapper __vew;)
11161 CautiouslyPreserveExceptionMark __em(this_thread);
11162 if (prefix_count < 0) {
11163 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11164 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11165 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11166 }
11167 log_error(jvmti)("[%s] %s } %s - erroneous arg is prefix_count", curr_thread_name, func_name,
11168 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT));
11169 }
11170 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
11171 }
11172 if (prefixes == NULL) {
11173 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11174 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11175 log_trace(jvmti)("[%s] %s { prefix_count=" INT32_FORMAT "", curr_thread_name, func_name, prefix_count);
11176 }
11177 log_error(jvmti)("[%s] %s } %s - erroneous arg is prefixes", curr_thread_name, func_name,
11178 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
11179 }
11180 return JVMTI_ERROR_NULL_POINTER;
11181 }
11182
11183 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11184 log_trace(jvmti)("[%s] %s { prefix_count=" INT32_FORMAT "", curr_thread_name, func_name, prefix_count);
11185 }
11186 err = jvmti_env->SetNativeMethodPrefixes(prefix_count, prefixes);
11187 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11188 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11189 log_trace(jvmti)("[%s] %s { prefix_count=" INT32_FORMAT "", curr_thread_name, func_name, prefix_count);
11190 }
11191 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11192 JvmtiUtil::error_name(err));
11193 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11194 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11195 }
11196 } else {
11197 if (prefix_count < 0) {
11198 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11199 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11200 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11201 }
11202 log_error(jvmti)("[%s] %s } %s - erroneous arg is prefix_count", curr_thread_name, func_name,
11203 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT));
11204 }
11205 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
11206 }
11207 if (prefixes == NULL) {
11208 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11209 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11210 log_trace(jvmti)("[%s] %s { prefix_count=" INT32_FORMAT "", curr_thread_name, func_name, prefix_count);
11211 }
11212 log_error(jvmti)("[%s] %s } %s - erroneous arg is prefixes", curr_thread_name, func_name,
11213 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
11214 }
11215 return JVMTI_ERROR_NULL_POINTER;
11216 }
11217
11218 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11219 log_trace(jvmti)("[%s] %s { prefix_count=" INT32_FORMAT "", curr_thread_name, func_name, prefix_count);
11220 }
11221 err = jvmti_env->SetNativeMethodPrefixes(prefix_count, prefixes);
11222 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11223 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11224 log_trace(jvmti)("[%s] %s { prefix_count=" INT32_FORMAT "", curr_thread_name, func_name, prefix_count);
11225 }
11226 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11227 JvmtiUtil::error_name(err));
11228 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11229 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11230 }
11231 }
11232 return err;
11233}
11234
11235 //
11236 // Raw Monitor functions
11237 //
11238
11239static jvmtiError JNICALL
11240jvmtiTrace_CreateRawMonitor(jvmtiEnv* env,
11241 const char* name,
11242 jrawMonitorID* monitor_ptr) {
11243
11244#if !INCLUDE_JVMTI
11245 return JVMTI_ERROR_NOT_AVAILABLE;
11246#else
11247 SafeResourceMark rm;
11248 jint trace_flags = JvmtiTrace::trace_flags(31);
11249 const char *func_name = NULL;
11250 const char *curr_thread_name = NULL;
11251 if (trace_flags) {
11252 func_name = JvmtiTrace::function_name(31);
11253 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
11254 }
11255 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
11256 if (trace_flags) {
11257 log_trace(jvmti)("[-] %s %s", func_name,
11258 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
11259 }
11260 return JVMTI_ERROR_WRONG_PHASE;
11261 }
11262 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
11263 if (!jvmti_env->is_valid()) {
11264 if (trace_flags) {
11265 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
11266 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
11267 }
11268 return JVMTI_ERROR_INVALID_ENVIRONMENT;
11269 }
11270 jvmtiError err;
11271 Thread* this_thread = NULL;
11272 bool transition;
11273 if (Threads::number_of_threads() == 0) {
11274 transition = false;
11275 } else {
11276 this_thread = Thread::current_or_null();
11277 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
11278 }
11279 if (transition) {
11280 if (!this_thread->is_Java_thread()) {
11281 if (trace_flags) {
11282 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
11283 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
11284 }
11285 return JVMTI_ERROR_UNATTACHED_THREAD;
11286 }
11287 JavaThread* current_thread = (JavaThread*)this_thread;
11288 ThreadInVMfromNative __tiv(current_thread);
11289 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_CreateRawMonitor , current_thread)
11290 debug_only(VMNativeEntryWrapper __vew;)
11291 if (name == NULL) {
11292 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11293 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11294 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11295 }
11296 log_error(jvmti)("[%s] %s } %s - erroneous arg is name", curr_thread_name, func_name,
11297 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
11298 }
11299 return JVMTI_ERROR_NULL_POINTER;
11300 }
11301 if (monitor_ptr == NULL) {
11302 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11303 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11304 log_trace(jvmti)("[%s] %s { name='%s'", curr_thread_name, func_name, name);
11305 }
11306 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor_ptr", curr_thread_name, func_name,
11307 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
11308 }
11309 return JVMTI_ERROR_NULL_POINTER;
11310 }
11311
11312 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11313 log_trace(jvmti)("[%s] %s { name='%s'", curr_thread_name, func_name, name);
11314 }
11315 err = jvmti_env->CreateRawMonitor(name, monitor_ptr);
11316 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11317 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11318 log_trace(jvmti)("[%s] %s { name='%s'", curr_thread_name, func_name, name);
11319 }
11320 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11321 JvmtiUtil::error_name(err));
11322 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11323 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11324 }
11325 } else {
11326 if (name == NULL) {
11327 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11328 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11329 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11330 }
11331 log_error(jvmti)("[%s] %s } %s - erroneous arg is name", curr_thread_name, func_name,
11332 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
11333 }
11334 return JVMTI_ERROR_NULL_POINTER;
11335 }
11336 if (monitor_ptr == NULL) {
11337 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11338 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11339 log_trace(jvmti)("[%s] %s { name='%s'", curr_thread_name, func_name, name);
11340 }
11341 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor_ptr", curr_thread_name, func_name,
11342 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
11343 }
11344 return JVMTI_ERROR_NULL_POINTER;
11345 }
11346
11347 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11348 log_trace(jvmti)("[%s] %s { name='%s'", curr_thread_name, func_name, name);
11349 }
11350 err = jvmti_env->CreateRawMonitor(name, monitor_ptr);
11351 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11352 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11353 log_trace(jvmti)("[%s] %s { name='%s'", curr_thread_name, func_name, name);
11354 }
11355 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11356 JvmtiUtil::error_name(err));
11357 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11358 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11359 }
11360 }
11361 return err;
11362#endif // INCLUDE_JVMTI
11363}
11364
11365static jvmtiError JNICALL
11366jvmtiTrace_DestroyRawMonitor(jvmtiEnv* env,
11367 jrawMonitorID monitor) {
11368
11369#if !INCLUDE_JVMTI
11370 return JVMTI_ERROR_NOT_AVAILABLE;
11371#else
11372 SafeResourceMark rm;
11373 jint trace_flags = JvmtiTrace::trace_flags(32);
11374 const char *func_name = NULL;
11375 const char *curr_thread_name = NULL;
11376 if (trace_flags) {
11377 func_name = JvmtiTrace::function_name(32);
11378 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
11379 }
11380 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
11381 if (trace_flags) {
11382 log_trace(jvmti)("[-] %s %s", func_name,
11383 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
11384 }
11385 return JVMTI_ERROR_WRONG_PHASE;
11386 }
11387 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
11388 if (!jvmti_env->is_valid()) {
11389 if (trace_flags) {
11390 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
11391 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
11392 }
11393 return JVMTI_ERROR_INVALID_ENVIRONMENT;
11394 }
11395 jvmtiError err;
11396 Thread* this_thread = NULL;
11397 bool transition;
11398 if (Threads::number_of_threads() == 0) {
11399 transition = false;
11400 } else {
11401 this_thread = Thread::current_or_null();
11402 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
11403 }
11404 if (transition) {
11405 if (!this_thread->is_Java_thread()) {
11406 if (trace_flags) {
11407 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
11408 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
11409 }
11410 return JVMTI_ERROR_UNATTACHED_THREAD;
11411 }
11412 JavaThread* current_thread = (JavaThread*)this_thread;
11413 ThreadInVMfromNative __tiv(current_thread);
11414 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_DestroyRawMonitor , current_thread)
11415 debug_only(VMNativeEntryWrapper __vew;)
11416 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
11417 if (rmonitor == NULL) {
11418 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11419 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11420 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11421 }
11422 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - raw monitor is NULL", curr_thread_name, func_name,
11423 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR));
11424 }
11425 return JVMTI_ERROR_INVALID_MONITOR;
11426 }
11427 if (!rmonitor->is_valid()) {
11428 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11429 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11430 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11431 }
11432 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - not a raw monitor " PTR_FORMAT "", curr_thread_name, func_name,
11433 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR), p2i(rmonitor));
11434 }
11435 return JVMTI_ERROR_INVALID_MONITOR;
11436 }
11437
11438 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11439 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11440 }
11441 err = jvmti_env->DestroyRawMonitor(rmonitor);
11442 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11443 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11444 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11445 }
11446 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11447 JvmtiUtil::error_name(err));
11448 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11449 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11450 }
11451 } else {
11452 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
11453 if (rmonitor == NULL) {
11454 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11455 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11456 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11457 }
11458 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - raw monitor is NULL", curr_thread_name, func_name,
11459 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR));
11460 }
11461 return JVMTI_ERROR_INVALID_MONITOR;
11462 }
11463 if (!rmonitor->is_valid()) {
11464 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11465 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11466 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11467 }
11468 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - not a raw monitor " PTR_FORMAT "", curr_thread_name, func_name,
11469 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR), p2i(rmonitor));
11470 }
11471 return JVMTI_ERROR_INVALID_MONITOR;
11472 }
11473
11474 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11475 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11476 }
11477 err = jvmti_env->DestroyRawMonitor(rmonitor);
11478 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11479 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11480 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11481 }
11482 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11483 JvmtiUtil::error_name(err));
11484 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11485 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11486 }
11487 }
11488 return err;
11489#endif // INCLUDE_JVMTI
11490}
11491
11492static jvmtiError JNICALL
11493jvmtiTrace_RawMonitorEnter(jvmtiEnv* env,
11494 jrawMonitorID monitor) {
11495
11496#if !INCLUDE_JVMTI
11497 return JVMTI_ERROR_NOT_AVAILABLE;
11498#else
11499 SafeResourceMark rm;
11500 jint trace_flags = JvmtiTrace::trace_flags(33);
11501 const char *func_name = NULL;
11502 const char *curr_thread_name = NULL;
11503 if (trace_flags) {
11504 func_name = JvmtiTrace::function_name(33);
11505 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
11506 }
11507
11508 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
11509 if (!jvmti_env->is_valid()) {
11510 if (trace_flags) {
11511 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
11512 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
11513 }
11514 return JVMTI_ERROR_INVALID_ENVIRONMENT;
11515 }
11516 jvmtiError err;
11517 Thread* this_thread = NULL;
11518 bool transition;
11519 if (Threads::number_of_threads() == 0) {
11520 transition = false;
11521 } else {
11522 this_thread = Thread::current_or_null();
11523 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
11524 }
11525 if (transition) {
11526 if (!this_thread->is_Java_thread()) {
11527 if (trace_flags) {
11528 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
11529 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
11530 }
11531 return JVMTI_ERROR_UNATTACHED_THREAD;
11532 }
11533
11534 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
11535 if (rmonitor == NULL) {
11536 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11537 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11538 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11539 }
11540 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - raw monitor is NULL", curr_thread_name, func_name,
11541 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR));
11542 }
11543 return JVMTI_ERROR_INVALID_MONITOR;
11544 }
11545 if (!rmonitor->is_valid()) {
11546 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11547 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11548 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11549 }
11550 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - not a raw monitor " PTR_FORMAT "", curr_thread_name, func_name,
11551 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR), p2i(rmonitor));
11552 }
11553 return JVMTI_ERROR_INVALID_MONITOR;
11554 }
11555
11556 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11557 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11558 }
11559 err = jvmti_env->RawMonitorEnter(rmonitor);
11560 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11561 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11562 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11563 }
11564 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11565 JvmtiUtil::error_name(err));
11566 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11567 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11568 }
11569 } else {
11570 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
11571 if (rmonitor == NULL) {
11572 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11573 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11574 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11575 }
11576 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - raw monitor is NULL", curr_thread_name, func_name,
11577 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR));
11578 }
11579 return JVMTI_ERROR_INVALID_MONITOR;
11580 }
11581 if (!rmonitor->is_valid()) {
11582 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11583 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11584 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11585 }
11586 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - not a raw monitor " PTR_FORMAT "", curr_thread_name, func_name,
11587 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR), p2i(rmonitor));
11588 }
11589 return JVMTI_ERROR_INVALID_MONITOR;
11590 }
11591
11592 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11593 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11594 }
11595 err = jvmti_env->RawMonitorEnter(rmonitor);
11596 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11597 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11598 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11599 }
11600 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11601 JvmtiUtil::error_name(err));
11602 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11603 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11604 }
11605 }
11606 return err;
11607#endif // INCLUDE_JVMTI
11608}
11609
11610static jvmtiError JNICALL
11611jvmtiTrace_RawMonitorExit(jvmtiEnv* env,
11612 jrawMonitorID monitor) {
11613
11614#if !INCLUDE_JVMTI
11615 return JVMTI_ERROR_NOT_AVAILABLE;
11616#else
11617 SafeResourceMark rm;
11618 jint trace_flags = JvmtiTrace::trace_flags(34);
11619 const char *func_name = NULL;
11620 const char *curr_thread_name = NULL;
11621 if (trace_flags) {
11622 func_name = JvmtiTrace::function_name(34);
11623 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
11624 }
11625
11626 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
11627 if (!jvmti_env->is_valid()) {
11628 if (trace_flags) {
11629 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
11630 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
11631 }
11632 return JVMTI_ERROR_INVALID_ENVIRONMENT;
11633 }
11634 jvmtiError err;
11635 Thread* this_thread = NULL;
11636 bool transition;
11637 if (Threads::number_of_threads() == 0) {
11638 transition = false;
11639 } else {
11640 this_thread = Thread::current_or_null();
11641 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
11642 }
11643 if (transition) {
11644 if (!this_thread->is_Java_thread()) {
11645 if (trace_flags) {
11646 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
11647 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
11648 }
11649 return JVMTI_ERROR_UNATTACHED_THREAD;
11650 }
11651
11652 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
11653 if (rmonitor == NULL) {
11654 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11655 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11656 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11657 }
11658 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - raw monitor is NULL", curr_thread_name, func_name,
11659 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR));
11660 }
11661 return JVMTI_ERROR_INVALID_MONITOR;
11662 }
11663 if (!rmonitor->is_valid()) {
11664 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11665 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11666 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11667 }
11668 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - not a raw monitor " PTR_FORMAT "", curr_thread_name, func_name,
11669 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR), p2i(rmonitor));
11670 }
11671 return JVMTI_ERROR_INVALID_MONITOR;
11672 }
11673
11674 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11675 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11676 }
11677 err = jvmti_env->RawMonitorExit(rmonitor);
11678 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11679 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11680 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11681 }
11682 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11683 JvmtiUtil::error_name(err));
11684 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11685 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11686 }
11687 } else {
11688 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
11689 if (rmonitor == NULL) {
11690 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11691 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11692 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11693 }
11694 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - raw monitor is NULL", curr_thread_name, func_name,
11695 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR));
11696 }
11697 return JVMTI_ERROR_INVALID_MONITOR;
11698 }
11699 if (!rmonitor->is_valid()) {
11700 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11701 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11702 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11703 }
11704 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - not a raw monitor " PTR_FORMAT "", curr_thread_name, func_name,
11705 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR), p2i(rmonitor));
11706 }
11707 return JVMTI_ERROR_INVALID_MONITOR;
11708 }
11709
11710 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11711 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11712 }
11713 err = jvmti_env->RawMonitorExit(rmonitor);
11714 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11715 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11716 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11717 }
11718 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11719 JvmtiUtil::error_name(err));
11720 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11721 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11722 }
11723 }
11724 return err;
11725#endif // INCLUDE_JVMTI
11726}
11727
11728static jvmtiError JNICALL
11729jvmtiTrace_RawMonitorWait(jvmtiEnv* env,
11730 jrawMonitorID monitor,
11731 jlong millis) {
11732
11733#if !INCLUDE_JVMTI
11734 return JVMTI_ERROR_NOT_AVAILABLE;
11735#else
11736 SafeResourceMark rm;
11737 jint trace_flags = JvmtiTrace::trace_flags(35);
11738 const char *func_name = NULL;
11739 const char *curr_thread_name = NULL;
11740 if (trace_flags) {
11741 func_name = JvmtiTrace::function_name(35);
11742 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
11743 }
11744
11745 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
11746 if (!jvmti_env->is_valid()) {
11747 if (trace_flags) {
11748 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
11749 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
11750 }
11751 return JVMTI_ERROR_INVALID_ENVIRONMENT;
11752 }
11753 jvmtiError err;
11754 Thread* this_thread = NULL;
11755 bool transition;
11756 if (Threads::number_of_threads() == 0) {
11757 transition = false;
11758 } else {
11759 this_thread = Thread::current_or_null();
11760 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
11761 }
11762 if (transition) {
11763 if (!this_thread->is_Java_thread()) {
11764 if (trace_flags) {
11765 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
11766 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
11767 }
11768 return JVMTI_ERROR_UNATTACHED_THREAD;
11769 }
11770
11771 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
11772 if (rmonitor == NULL) {
11773 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11774 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11775 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11776 }
11777 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - raw monitor is NULL", curr_thread_name, func_name,
11778 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR));
11779 }
11780 return JVMTI_ERROR_INVALID_MONITOR;
11781 }
11782 if (!rmonitor->is_valid()) {
11783 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11784 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11785 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11786 }
11787 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - not a raw monitor " PTR_FORMAT "", curr_thread_name, func_name,
11788 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR), p2i(rmonitor));
11789 }
11790 return JVMTI_ERROR_INVALID_MONITOR;
11791 }
11792
11793 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11794 log_trace(jvmti)("[%s] %s { monitor=%s millis=" JLONG_FORMAT "", curr_thread_name, func_name, rmonitor->get_name(), millis);
11795 }
11796 err = jvmti_env->RawMonitorWait(rmonitor, millis);
11797 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11798 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11799 log_trace(jvmti)("[%s] %s { monitor=%s millis=" JLONG_FORMAT "", curr_thread_name, func_name, rmonitor->get_name(), millis);
11800 }
11801 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11802 JvmtiUtil::error_name(err));
11803 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11804 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11805 }
11806 } else {
11807 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
11808 if (rmonitor == NULL) {
11809 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11810 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11811 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11812 }
11813 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - raw monitor is NULL", curr_thread_name, func_name,
11814 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR));
11815 }
11816 return JVMTI_ERROR_INVALID_MONITOR;
11817 }
11818 if (!rmonitor->is_valid()) {
11819 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11820 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11821 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11822 }
11823 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - not a raw monitor " PTR_FORMAT "", curr_thread_name, func_name,
11824 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR), p2i(rmonitor));
11825 }
11826 return JVMTI_ERROR_INVALID_MONITOR;
11827 }
11828
11829 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11830 log_trace(jvmti)("[%s] %s { monitor=%s millis=" JLONG_FORMAT "", curr_thread_name, func_name, rmonitor->get_name(), millis);
11831 }
11832 err = jvmti_env->RawMonitorWait(rmonitor, millis);
11833 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11834 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11835 log_trace(jvmti)("[%s] %s { monitor=%s millis=" JLONG_FORMAT "", curr_thread_name, func_name, rmonitor->get_name(), millis);
11836 }
11837 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11838 JvmtiUtil::error_name(err));
11839 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11840 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11841 }
11842 }
11843 return err;
11844#endif // INCLUDE_JVMTI
11845}
11846
11847static jvmtiError JNICALL
11848jvmtiTrace_RawMonitorNotify(jvmtiEnv* env,
11849 jrawMonitorID monitor) {
11850
11851#if !INCLUDE_JVMTI
11852 return JVMTI_ERROR_NOT_AVAILABLE;
11853#else
11854 SafeResourceMark rm;
11855 jint trace_flags = JvmtiTrace::trace_flags(36);
11856 const char *func_name = NULL;
11857 const char *curr_thread_name = NULL;
11858 if (trace_flags) {
11859 func_name = JvmtiTrace::function_name(36);
11860 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
11861 }
11862
11863 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
11864 if (!jvmti_env->is_valid()) {
11865 if (trace_flags) {
11866 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
11867 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
11868 }
11869 return JVMTI_ERROR_INVALID_ENVIRONMENT;
11870 }
11871 jvmtiError err;
11872 Thread* this_thread = NULL;
11873 bool transition;
11874 if (Threads::number_of_threads() == 0) {
11875 transition = false;
11876 } else {
11877 this_thread = Thread::current_or_null();
11878 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
11879 }
11880 if (transition) {
11881 if (!this_thread->is_Java_thread()) {
11882 if (trace_flags) {
11883 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
11884 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
11885 }
11886 return JVMTI_ERROR_UNATTACHED_THREAD;
11887 }
11888 JavaThread* current_thread = (JavaThread*)this_thread;
11889 ThreadInVMfromNative __tiv(current_thread);
11890 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_RawMonitorNotify , current_thread)
11891 debug_only(VMNativeEntryWrapper __vew;)
11892 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
11893 if (rmonitor == NULL) {
11894 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11895 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11896 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11897 }
11898 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - raw monitor is NULL", curr_thread_name, func_name,
11899 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR));
11900 }
11901 return JVMTI_ERROR_INVALID_MONITOR;
11902 }
11903 if (!rmonitor->is_valid()) {
11904 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11905 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11906 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11907 }
11908 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - not a raw monitor " PTR_FORMAT "", curr_thread_name, func_name,
11909 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR), p2i(rmonitor));
11910 }
11911 return JVMTI_ERROR_INVALID_MONITOR;
11912 }
11913
11914 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11915 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11916 }
11917 err = jvmti_env->RawMonitorNotify(rmonitor);
11918 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11919 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11920 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11921 }
11922 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11923 JvmtiUtil::error_name(err));
11924 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11925 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11926 }
11927 } else {
11928 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
11929 if (rmonitor == NULL) {
11930 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11931 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11932 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11933 }
11934 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - raw monitor is NULL", curr_thread_name, func_name,
11935 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR));
11936 }
11937 return JVMTI_ERROR_INVALID_MONITOR;
11938 }
11939 if (!rmonitor->is_valid()) {
11940 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11941 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11942 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
11943 }
11944 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - not a raw monitor " PTR_FORMAT "", curr_thread_name, func_name,
11945 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR), p2i(rmonitor));
11946 }
11947 return JVMTI_ERROR_INVALID_MONITOR;
11948 }
11949
11950 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
11951 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11952 }
11953 err = jvmti_env->RawMonitorNotify(rmonitor);
11954 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
11955 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
11956 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
11957 }
11958 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
11959 JvmtiUtil::error_name(err));
11960 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
11961 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
11962 }
11963 }
11964 return err;
11965#endif // INCLUDE_JVMTI
11966}
11967
11968static jvmtiError JNICALL
11969jvmtiTrace_RawMonitorNotifyAll(jvmtiEnv* env,
11970 jrawMonitorID monitor) {
11971
11972#if !INCLUDE_JVMTI
11973 return JVMTI_ERROR_NOT_AVAILABLE;
11974#else
11975 SafeResourceMark rm;
11976 jint trace_flags = JvmtiTrace::trace_flags(37);
11977 const char *func_name = NULL;
11978 const char *curr_thread_name = NULL;
11979 if (trace_flags) {
11980 func_name = JvmtiTrace::function_name(37);
11981 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
11982 }
11983
11984 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
11985 if (!jvmti_env->is_valid()) {
11986 if (trace_flags) {
11987 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
11988 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
11989 }
11990 return JVMTI_ERROR_INVALID_ENVIRONMENT;
11991 }
11992 jvmtiError err;
11993 Thread* this_thread = NULL;
11994 bool transition;
11995 if (Threads::number_of_threads() == 0) {
11996 transition = false;
11997 } else {
11998 this_thread = Thread::current_or_null();
11999 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
12000 }
12001 if (transition) {
12002 if (!this_thread->is_Java_thread()) {
12003 if (trace_flags) {
12004 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
12005 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
12006 }
12007 return JVMTI_ERROR_UNATTACHED_THREAD;
12008 }
12009 JavaThread* current_thread = (JavaThread*)this_thread;
12010 ThreadInVMfromNative __tiv(current_thread);
12011 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_RawMonitorNotifyAll , current_thread)
12012 debug_only(VMNativeEntryWrapper __vew;)
12013 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
12014 if (rmonitor == NULL) {
12015 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12016 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12017 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12018 }
12019 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - raw monitor is NULL", curr_thread_name, func_name,
12020 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR));
12021 }
12022 return JVMTI_ERROR_INVALID_MONITOR;
12023 }
12024 if (!rmonitor->is_valid()) {
12025 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12026 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12027 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12028 }
12029 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - not a raw monitor " PTR_FORMAT "", curr_thread_name, func_name,
12030 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR), p2i(rmonitor));
12031 }
12032 return JVMTI_ERROR_INVALID_MONITOR;
12033 }
12034
12035 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12036 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
12037 }
12038 err = jvmti_env->RawMonitorNotifyAll(rmonitor);
12039 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12040 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12041 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
12042 }
12043 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12044 JvmtiUtil::error_name(err));
12045 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12046 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12047 }
12048 } else {
12049 JvmtiRawMonitor *rmonitor = (JvmtiRawMonitor *)monitor;
12050 if (rmonitor == NULL) {
12051 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12052 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12053 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12054 }
12055 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - raw monitor is NULL", curr_thread_name, func_name,
12056 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR));
12057 }
12058 return JVMTI_ERROR_INVALID_MONITOR;
12059 }
12060 if (!rmonitor->is_valid()) {
12061 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12062 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12063 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12064 }
12065 log_error(jvmti)("[%s] %s } %s - erroneous arg is monitor - not a raw monitor " PTR_FORMAT "", curr_thread_name, func_name,
12066 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_MONITOR), p2i(rmonitor));
12067 }
12068 return JVMTI_ERROR_INVALID_MONITOR;
12069 }
12070
12071 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12072 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
12073 }
12074 err = jvmti_env->RawMonitorNotifyAll(rmonitor);
12075 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12076 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12077 log_trace(jvmti)("[%s] %s { monitor=%s", curr_thread_name, func_name, rmonitor->get_name());
12078 }
12079 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12080 JvmtiUtil::error_name(err));
12081 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12082 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12083 }
12084 }
12085 return err;
12086#endif // INCLUDE_JVMTI
12087}
12088
12089 //
12090 // JNI Function Interception functions
12091 //
12092
12093static jvmtiError JNICALL
12094jvmtiTrace_SetJNIFunctionTable(jvmtiEnv* env,
12095 const jniNativeInterface* function_table) {
12096
12097#if !INCLUDE_JVMTI
12098 return JVMTI_ERROR_NOT_AVAILABLE;
12099#else
12100 SafeResourceMark rm;
12101 jint trace_flags = JvmtiTrace::trace_flags(120);
12102 const char *func_name = NULL;
12103 const char *curr_thread_name = NULL;
12104 if (trace_flags) {
12105 func_name = JvmtiTrace::function_name(120);
12106 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
12107 }
12108 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
12109 if (trace_flags) {
12110 log_trace(jvmti)("[-] %s %s", func_name,
12111 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
12112 }
12113 return JVMTI_ERROR_WRONG_PHASE;
12114 }
12115 Thread* this_thread = Thread::current_or_null();
12116 if (this_thread == NULL || !this_thread->is_Java_thread()) {
12117 if (trace_flags) {
12118 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
12119 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
12120 }
12121 return JVMTI_ERROR_UNATTACHED_THREAD;
12122 }
12123 JavaThread* current_thread = (JavaThread*)this_thread;
12124 ThreadInVMfromNative __tiv(current_thread);
12125 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetJNIFunctionTable , current_thread)
12126 debug_only(VMNativeEntryWrapper __vew;)
12127 CautiouslyPreserveExceptionMark __em(this_thread);
12128 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
12129 if (!jvmti_env->is_valid()) {
12130 if (trace_flags) {
12131 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
12132 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
12133 }
12134 return JVMTI_ERROR_INVALID_ENVIRONMENT;
12135 }
12136 jvmtiError err;
12137 if (function_table == NULL) {
12138 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12139 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12140 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12141 }
12142 log_error(jvmti)("[%s] %s } %s - erroneous arg is function_table", curr_thread_name, func_name,
12143 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
12144 }
12145 return JVMTI_ERROR_NULL_POINTER;
12146 }
12147
12148 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12149 log_trace(jvmti)("[%s] %s { function_table=" PTR_FORMAT "", curr_thread_name, func_name,
12150 p2i(function_table)
12151);
12152 }
12153 err = jvmti_env->SetJNIFunctionTable(function_table);
12154 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12155 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12156 log_trace(jvmti)("[%s] %s { function_table=" PTR_FORMAT "", curr_thread_name, func_name,
12157 p2i(function_table)
12158);
12159 }
12160 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12161 JvmtiUtil::error_name(err));
12162 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12163 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12164 }
12165 return err;
12166#endif // INCLUDE_JVMTI
12167}
12168
12169static jvmtiError JNICALL
12170jvmtiTrace_GetJNIFunctionTable(jvmtiEnv* env,
12171 jniNativeInterface** function_table) {
12172
12173#if !INCLUDE_JVMTI
12174 return JVMTI_ERROR_NOT_AVAILABLE;
12175#else
12176 SafeResourceMark rm;
12177 jint trace_flags = JvmtiTrace::trace_flags(121);
12178 const char *func_name = NULL;
12179 const char *curr_thread_name = NULL;
12180 if (trace_flags) {
12181 func_name = JvmtiTrace::function_name(121);
12182 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
12183 }
12184 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
12185 if (trace_flags) {
12186 log_trace(jvmti)("[-] %s %s", func_name,
12187 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
12188 }
12189 return JVMTI_ERROR_WRONG_PHASE;
12190 }
12191 Thread* this_thread = Thread::current_or_null();
12192 if (this_thread == NULL || !this_thread->is_Java_thread()) {
12193 if (trace_flags) {
12194 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
12195 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
12196 }
12197 return JVMTI_ERROR_UNATTACHED_THREAD;
12198 }
12199 JavaThread* current_thread = (JavaThread*)this_thread;
12200 ThreadInVMfromNative __tiv(current_thread);
12201 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetJNIFunctionTable , current_thread)
12202 debug_only(VMNativeEntryWrapper __vew;)
12203 CautiouslyPreserveExceptionMark __em(this_thread);
12204 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
12205 if (!jvmti_env->is_valid()) {
12206 if (trace_flags) {
12207 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
12208 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
12209 }
12210 return JVMTI_ERROR_INVALID_ENVIRONMENT;
12211 }
12212 jvmtiError err;
12213 if (function_table == NULL) {
12214 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12215 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12216 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12217 }
12218 log_error(jvmti)("[%s] %s } %s - erroneous arg is function_table", curr_thread_name, func_name,
12219 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
12220 }
12221 return JVMTI_ERROR_NULL_POINTER;
12222 }
12223
12224 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12225 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12226 }
12227 err = jvmti_env->GetJNIFunctionTable(function_table);
12228 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12229 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12230 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12231 }
12232 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12233 JvmtiUtil::error_name(err));
12234 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12235 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12236 }
12237 return err;
12238#endif // INCLUDE_JVMTI
12239}
12240
12241 //
12242 // Event Management functions
12243 //
12244
12245static jvmtiError JNICALL
12246jvmtiTrace_SetEventCallbacks(jvmtiEnv* env,
12247 const jvmtiEventCallbacks* callbacks,
12248 jint size_of_callbacks) {
12249 SafeResourceMark rm;
12250 jint trace_flags = JvmtiTrace::trace_flags(122);
12251 const char *func_name = NULL;
12252 const char *curr_thread_name = NULL;
12253 if (trace_flags) {
12254 func_name = JvmtiTrace::function_name(122);
12255 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
12256 }
12257 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
12258 if (trace_flags) {
12259 log_trace(jvmti)("[-] %s %s", func_name,
12260 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
12261 }
12262 return JVMTI_ERROR_WRONG_PHASE;
12263 }
12264 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
12265 if (!jvmti_env->is_valid()) {
12266 if (trace_flags) {
12267 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
12268 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
12269 }
12270 return JVMTI_ERROR_INVALID_ENVIRONMENT;
12271 }
12272 jvmtiError err;
12273 if (Threads::number_of_threads() != 0) {
12274 Thread* this_thread = Thread::current_or_null();
12275 if (this_thread == NULL || !this_thread->is_Java_thread()) {
12276 if (trace_flags) {
12277 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
12278 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
12279 }
12280 return JVMTI_ERROR_UNATTACHED_THREAD;
12281 }
12282 JavaThread* current_thread = (JavaThread*)this_thread;
12283 ThreadInVMfromNative __tiv(current_thread);
12284 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetEventCallbacks , current_thread)
12285 debug_only(VMNativeEntryWrapper __vew;)
12286 CautiouslyPreserveExceptionMark __em(this_thread);
12287 if (size_of_callbacks < 0) {
12288 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12289 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12290 log_trace(jvmti)("[%s] %s { callbacks=" PTR_FORMAT "", curr_thread_name, func_name,
12291 p2i(callbacks)
12292);
12293 }
12294 log_error(jvmti)("[%s] %s } %s - erroneous arg is size_of_callbacks", curr_thread_name, func_name,
12295 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT));
12296 }
12297 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
12298 }
12299
12300 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12301 log_trace(jvmti)("[%s] %s { callbacks=" PTR_FORMAT " size_of_callbacks=" INT32_FORMAT "", curr_thread_name, func_name,
12302 p2i(callbacks)
12303, size_of_callbacks);
12304 }
12305 err = jvmti_env->SetEventCallbacks(callbacks, size_of_callbacks);
12306 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12307 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12308 log_trace(jvmti)("[%s] %s { callbacks=" PTR_FORMAT " size_of_callbacks=" INT32_FORMAT "", curr_thread_name, func_name,
12309 p2i(callbacks)
12310, size_of_callbacks);
12311 }
12312 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12313 JvmtiUtil::error_name(err));
12314 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12315 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12316 }
12317 } else {
12318 if (size_of_callbacks < 0) {
12319 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12320 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12321 log_trace(jvmti)("[%s] %s { callbacks=" PTR_FORMAT "", curr_thread_name, func_name,
12322 p2i(callbacks)
12323);
12324 }
12325 log_error(jvmti)("[%s] %s } %s - erroneous arg is size_of_callbacks", curr_thread_name, func_name,
12326 JvmtiUtil::error_name(JVMTI_ERROR_ILLEGAL_ARGUMENT));
12327 }
12328 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
12329 }
12330
12331 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12332 log_trace(jvmti)("[%s] %s { callbacks=" PTR_FORMAT " size_of_callbacks=" INT32_FORMAT "", curr_thread_name, func_name,
12333 p2i(callbacks)
12334, size_of_callbacks);
12335 }
12336 err = jvmti_env->SetEventCallbacks(callbacks, size_of_callbacks);
12337 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12338 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12339 log_trace(jvmti)("[%s] %s { callbacks=" PTR_FORMAT " size_of_callbacks=" INT32_FORMAT "", curr_thread_name, func_name,
12340 p2i(callbacks)
12341, size_of_callbacks);
12342 }
12343 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12344 JvmtiUtil::error_name(err));
12345 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12346 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12347 }
12348 }
12349 return err;
12350}
12351
12352static jvmtiError JNICALL
12353jvmtiTrace_SetEventNotificationMode(jvmtiEnv* env,
12354 jvmtiEventMode mode,
12355 jvmtiEvent event_type,
12356 jthread event_thread,
12357 ...) {
12358 SafeResourceMark rm;
12359 jint trace_flags = JvmtiTrace::trace_flags(2);
12360 const char *func_name = NULL;
12361 const char *curr_thread_name = NULL;
12362 if (trace_flags) {
12363 func_name = JvmtiTrace::function_name(2);
12364 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
12365 }
12366 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
12367 if (trace_flags) {
12368 log_trace(jvmti)("[-] %s %s", func_name,
12369 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
12370 }
12371 return JVMTI_ERROR_WRONG_PHASE;
12372 }
12373 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
12374 if (!jvmti_env->is_valid()) {
12375 if (trace_flags) {
12376 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
12377 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
12378 }
12379 return JVMTI_ERROR_INVALID_ENVIRONMENT;
12380 }
12381 jvmtiError err;
12382 if (Threads::number_of_threads() != 0) {
12383 Thread* this_thread = Thread::current_or_null();
12384 if (this_thread == NULL || !this_thread->is_Java_thread()) {
12385 if (trace_flags) {
12386 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
12387 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
12388 }
12389 return JVMTI_ERROR_UNATTACHED_THREAD;
12390 }
12391 JavaThread* current_thread = (JavaThread*)this_thread;
12392 ThreadInVMfromNative __tiv(current_thread);
12393 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetEventNotificationMode , current_thread)
12394 debug_only(VMNativeEntryWrapper __vew;)
12395 CautiouslyPreserveExceptionMark __em(this_thread);
12396
12397 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12398 log_trace(jvmti)("[%s] %s { mode=%d:%s event_type=%d:%s", curr_thread_name, func_name, mode,
12399 JvmtiTrace::enum_name(jvmtiEventModeConstantNames, jvmtiEventModeConstantValues, mode), event_type,
12400 JvmtiTrace::event_name(event_type)
12401 );
12402 }
12403 err = jvmti_env->SetEventNotificationMode(mode, event_type, event_thread, NULL);
12404 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12405 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12406 log_trace(jvmti)("[%s] %s { mode=%d:%s event_type=%d:%s", curr_thread_name, func_name, mode,
12407 JvmtiTrace::enum_name(jvmtiEventModeConstantNames, jvmtiEventModeConstantValues, mode), event_type,
12408 JvmtiTrace::event_name(event_type)
12409 );
12410 }
12411 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12412 JvmtiUtil::error_name(err));
12413 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12414 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12415 }
12416 } else {
12417
12418 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12419 log_trace(jvmti)("[%s] %s { mode=%d:%s event_type=%d:%s", curr_thread_name, func_name, mode,
12420 JvmtiTrace::enum_name(jvmtiEventModeConstantNames, jvmtiEventModeConstantValues, mode), event_type,
12421 JvmtiTrace::event_name(event_type)
12422 );
12423 }
12424 err = jvmti_env->SetEventNotificationMode(mode, event_type, event_thread, NULL);
12425 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12426 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12427 log_trace(jvmti)("[%s] %s { mode=%d:%s event_type=%d:%s", curr_thread_name, func_name, mode,
12428 JvmtiTrace::enum_name(jvmtiEventModeConstantNames, jvmtiEventModeConstantValues, mode), event_type,
12429 JvmtiTrace::event_name(event_type)
12430 );
12431 }
12432 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12433 JvmtiUtil::error_name(err));
12434 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12435 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12436 }
12437 }
12438 return err;
12439}
12440
12441static jvmtiError JNICALL
12442jvmtiTrace_GenerateEvents(jvmtiEnv* env,
12443 jvmtiEvent event_type) {
12444
12445#if !INCLUDE_JVMTI
12446 return JVMTI_ERROR_NOT_AVAILABLE;
12447#else
12448 SafeResourceMark rm;
12449 jint trace_flags = JvmtiTrace::trace_flags(123);
12450 const char *func_name = NULL;
12451 const char *curr_thread_name = NULL;
12452 if (trace_flags) {
12453 func_name = JvmtiTrace::function_name(123);
12454 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
12455 }
12456 if(!JvmtiEnv::is_vm_live()) {
12457 if (trace_flags) {
12458 log_trace(jvmti)("[-] %s %s(%d)", func_name,
12459 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
12460 }
12461 return JVMTI_ERROR_WRONG_PHASE;
12462 }
12463 Thread* this_thread = Thread::current_or_null();
12464 if (this_thread == NULL || !this_thread->is_Java_thread()) {
12465 if (trace_flags) {
12466 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
12467 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
12468 }
12469 return JVMTI_ERROR_UNATTACHED_THREAD;
12470 }
12471 JavaThread* current_thread = (JavaThread*)this_thread;
12472 ThreadInVMfromNative __tiv(current_thread);
12473 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GenerateEvents , current_thread)
12474 debug_only(VMNativeEntryWrapper __vew;)
12475 CautiouslyPreserveExceptionMark __em(this_thread);
12476 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
12477 if (!jvmti_env->is_valid()) {
12478 if (trace_flags) {
12479 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
12480 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
12481 }
12482 return JVMTI_ERROR_INVALID_ENVIRONMENT;
12483 }
12484 jvmtiError err;
12485
12486 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12487 log_trace(jvmti)("[%s] %s { event_type=%d:%s", curr_thread_name, func_name, event_type,
12488 JvmtiTrace::event_name(event_type)
12489 );
12490 }
12491 err = jvmti_env->GenerateEvents(event_type);
12492 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12493 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12494 log_trace(jvmti)("[%s] %s { event_type=%d:%s", curr_thread_name, func_name, event_type,
12495 JvmtiTrace::event_name(event_type)
12496 );
12497 }
12498 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12499 JvmtiUtil::error_name(err));
12500 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12501 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12502 }
12503 return err;
12504#endif // INCLUDE_JVMTI
12505}
12506
12507 //
12508 // Extension Mechanism functions
12509 //
12510
12511static jvmtiError JNICALL
12512jvmtiTrace_GetExtensionFunctions(jvmtiEnv* env,
12513 jint* extension_count_ptr,
12514 jvmtiExtensionFunctionInfo** extensions) {
12515
12516#if !INCLUDE_JVMTI
12517 return JVMTI_ERROR_NOT_AVAILABLE;
12518#else
12519 SafeResourceMark rm;
12520 jint trace_flags = JvmtiTrace::trace_flags(124);
12521 const char *func_name = NULL;
12522 const char *curr_thread_name = NULL;
12523 if (trace_flags) {
12524 func_name = JvmtiTrace::function_name(124);
12525 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
12526 }
12527 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
12528 if (trace_flags) {
12529 log_trace(jvmti)("[-] %s %s", func_name,
12530 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
12531 }
12532 return JVMTI_ERROR_WRONG_PHASE;
12533 }
12534 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
12535 if (!jvmti_env->is_valid()) {
12536 if (trace_flags) {
12537 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
12538 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
12539 }
12540 return JVMTI_ERROR_INVALID_ENVIRONMENT;
12541 }
12542 jvmtiError err;
12543 if (Threads::number_of_threads() != 0) {
12544 Thread* this_thread = Thread::current_or_null();
12545 if (this_thread == NULL || !this_thread->is_Java_thread()) {
12546 if (trace_flags) {
12547 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
12548 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
12549 }
12550 return JVMTI_ERROR_UNATTACHED_THREAD;
12551 }
12552 JavaThread* current_thread = (JavaThread*)this_thread;
12553 ThreadInVMfromNative __tiv(current_thread);
12554 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetExtensionFunctions , current_thread)
12555 debug_only(VMNativeEntryWrapper __vew;)
12556 CautiouslyPreserveExceptionMark __em(this_thread);
12557 if (extension_count_ptr == NULL) {
12558 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12559 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12560 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12561 }
12562 log_error(jvmti)("[%s] %s } %s - erroneous arg is extension_count_ptr", curr_thread_name, func_name,
12563 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
12564 }
12565 return JVMTI_ERROR_NULL_POINTER;
12566 }
12567 if (extensions == NULL) {
12568 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12569 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12570 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12571 }
12572 log_error(jvmti)("[%s] %s } %s - erroneous arg is extensions", curr_thread_name, func_name,
12573 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
12574 }
12575 return JVMTI_ERROR_NULL_POINTER;
12576 }
12577
12578 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12579 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12580 }
12581 err = jvmti_env->GetExtensionFunctions(extension_count_ptr, extensions);
12582 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12583 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12584 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12585 }
12586 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12587 JvmtiUtil::error_name(err));
12588 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12589 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12590 }
12591 } else {
12592 if (extension_count_ptr == NULL) {
12593 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12594 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12595 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12596 }
12597 log_error(jvmti)("[%s] %s } %s - erroneous arg is extension_count_ptr", curr_thread_name, func_name,
12598 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
12599 }
12600 return JVMTI_ERROR_NULL_POINTER;
12601 }
12602 if (extensions == NULL) {
12603 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12604 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12605 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12606 }
12607 log_error(jvmti)("[%s] %s } %s - erroneous arg is extensions", curr_thread_name, func_name,
12608 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
12609 }
12610 return JVMTI_ERROR_NULL_POINTER;
12611 }
12612
12613 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12614 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12615 }
12616 err = jvmti_env->GetExtensionFunctions(extension_count_ptr, extensions);
12617 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12618 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12619 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12620 }
12621 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12622 JvmtiUtil::error_name(err));
12623 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12624 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12625 }
12626 }
12627 return err;
12628#endif // INCLUDE_JVMTI
12629}
12630
12631static jvmtiError JNICALL
12632jvmtiTrace_GetExtensionEvents(jvmtiEnv* env,
12633 jint* extension_count_ptr,
12634 jvmtiExtensionEventInfo** extensions) {
12635
12636#if !INCLUDE_JVMTI
12637 return JVMTI_ERROR_NOT_AVAILABLE;
12638#else
12639 SafeResourceMark rm;
12640 jint trace_flags = JvmtiTrace::trace_flags(125);
12641 const char *func_name = NULL;
12642 const char *curr_thread_name = NULL;
12643 if (trace_flags) {
12644 func_name = JvmtiTrace::function_name(125);
12645 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
12646 }
12647 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
12648 if (trace_flags) {
12649 log_trace(jvmti)("[-] %s %s", func_name,
12650 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
12651 }
12652 return JVMTI_ERROR_WRONG_PHASE;
12653 }
12654 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
12655 if (!jvmti_env->is_valid()) {
12656 if (trace_flags) {
12657 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
12658 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
12659 }
12660 return JVMTI_ERROR_INVALID_ENVIRONMENT;
12661 }
12662 jvmtiError err;
12663 if (Threads::number_of_threads() != 0) {
12664 Thread* this_thread = Thread::current_or_null();
12665 if (this_thread == NULL || !this_thread->is_Java_thread()) {
12666 if (trace_flags) {
12667 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
12668 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
12669 }
12670 return JVMTI_ERROR_UNATTACHED_THREAD;
12671 }
12672 JavaThread* current_thread = (JavaThread*)this_thread;
12673 ThreadInVMfromNative __tiv(current_thread);
12674 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetExtensionEvents , current_thread)
12675 debug_only(VMNativeEntryWrapper __vew;)
12676 CautiouslyPreserveExceptionMark __em(this_thread);
12677 if (extension_count_ptr == NULL) {
12678 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12679 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12680 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12681 }
12682 log_error(jvmti)("[%s] %s } %s - erroneous arg is extension_count_ptr", curr_thread_name, func_name,
12683 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
12684 }
12685 return JVMTI_ERROR_NULL_POINTER;
12686 }
12687 if (extensions == NULL) {
12688 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12689 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12690 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12691 }
12692 log_error(jvmti)("[%s] %s } %s - erroneous arg is extensions", curr_thread_name, func_name,
12693 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
12694 }
12695 return JVMTI_ERROR_NULL_POINTER;
12696 }
12697
12698 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12699 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12700 }
12701 err = jvmti_env->GetExtensionEvents(extension_count_ptr, extensions);
12702 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12703 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12704 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12705 }
12706 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12707 JvmtiUtil::error_name(err));
12708 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12709 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12710 }
12711 } else {
12712 if (extension_count_ptr == NULL) {
12713 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12714 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12715 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12716 }
12717 log_error(jvmti)("[%s] %s } %s - erroneous arg is extension_count_ptr", curr_thread_name, func_name,
12718 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
12719 }
12720 return JVMTI_ERROR_NULL_POINTER;
12721 }
12722 if (extensions == NULL) {
12723 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12724 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12725 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12726 }
12727 log_error(jvmti)("[%s] %s } %s - erroneous arg is extensions", curr_thread_name, func_name,
12728 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
12729 }
12730 return JVMTI_ERROR_NULL_POINTER;
12731 }
12732
12733 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12734 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12735 }
12736 err = jvmti_env->GetExtensionEvents(extension_count_ptr, extensions);
12737 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12738 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12739 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12740 }
12741 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12742 JvmtiUtil::error_name(err));
12743 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12744 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12745 }
12746 }
12747 return err;
12748#endif // INCLUDE_JVMTI
12749}
12750
12751static jvmtiError JNICALL
12752jvmtiTrace_SetExtensionEventCallback(jvmtiEnv* env,
12753 jint extension_event_index,
12754 jvmtiExtensionEvent callback) {
12755
12756#if !INCLUDE_JVMTI
12757 return JVMTI_ERROR_NOT_AVAILABLE;
12758#else
12759 SafeResourceMark rm;
12760 jint trace_flags = JvmtiTrace::trace_flags(126);
12761 const char *func_name = NULL;
12762 const char *curr_thread_name = NULL;
12763 if (trace_flags) {
12764 func_name = JvmtiTrace::function_name(126);
12765 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
12766 }
12767 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
12768 if (trace_flags) {
12769 log_trace(jvmti)("[-] %s %s", func_name,
12770 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
12771 }
12772 return JVMTI_ERROR_WRONG_PHASE;
12773 }
12774 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
12775 if (!jvmti_env->is_valid()) {
12776 if (trace_flags) {
12777 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
12778 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
12779 }
12780 return JVMTI_ERROR_INVALID_ENVIRONMENT;
12781 }
12782 jvmtiError err;
12783 if (Threads::number_of_threads() != 0) {
12784 Thread* this_thread = Thread::current_or_null();
12785 if (this_thread == NULL || !this_thread->is_Java_thread()) {
12786 if (trace_flags) {
12787 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
12788 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
12789 }
12790 return JVMTI_ERROR_UNATTACHED_THREAD;
12791 }
12792 JavaThread* current_thread = (JavaThread*)this_thread;
12793 ThreadInVMfromNative __tiv(current_thread);
12794 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetExtensionEventCallback , current_thread)
12795 debug_only(VMNativeEntryWrapper __vew;)
12796 CautiouslyPreserveExceptionMark __em(this_thread);
12797
12798 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12799 log_trace(jvmti)("[%s] %s { extension_event_index=" INT32_FORMAT "", curr_thread_name, func_name, extension_event_index);
12800 }
12801 err = jvmti_env->SetExtensionEventCallback(extension_event_index, callback);
12802 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12803 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12804 log_trace(jvmti)("[%s] %s { extension_event_index=" INT32_FORMAT "", curr_thread_name, func_name, extension_event_index);
12805 }
12806 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12807 JvmtiUtil::error_name(err));
12808 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12809 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12810 }
12811 } else {
12812
12813 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12814 log_trace(jvmti)("[%s] %s { extension_event_index=" INT32_FORMAT "", curr_thread_name, func_name, extension_event_index);
12815 }
12816 err = jvmti_env->SetExtensionEventCallback(extension_event_index, callback);
12817 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12818 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12819 log_trace(jvmti)("[%s] %s { extension_event_index=" INT32_FORMAT "", curr_thread_name, func_name, extension_event_index);
12820 }
12821 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12822 JvmtiUtil::error_name(err));
12823 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12824 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12825 }
12826 }
12827 return err;
12828#endif // INCLUDE_JVMTI
12829}
12830
12831 //
12832 // Capability functions
12833 //
12834
12835static jvmtiError JNICALL
12836jvmtiTrace_GetPotentialCapabilities(jvmtiEnv* env,
12837 jvmtiCapabilities* capabilities_ptr) {
12838 SafeResourceMark rm;
12839 jint trace_flags = JvmtiTrace::trace_flags(140);
12840 const char *func_name = NULL;
12841 const char *curr_thread_name = NULL;
12842 if (trace_flags) {
12843 func_name = JvmtiTrace::function_name(140);
12844 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
12845 }
12846 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
12847 if (trace_flags) {
12848 log_trace(jvmti)("[-] %s %s", func_name,
12849 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
12850 }
12851 return JVMTI_ERROR_WRONG_PHASE;
12852 }
12853 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
12854 if (!jvmti_env->is_valid()) {
12855 if (trace_flags) {
12856 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
12857 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
12858 }
12859 return JVMTI_ERROR_INVALID_ENVIRONMENT;
12860 }
12861 jvmtiError err;
12862 if (Threads::number_of_threads() != 0) {
12863 Thread* this_thread = Thread::current_or_null();
12864 if (this_thread == NULL || !this_thread->is_Java_thread()) {
12865 if (trace_flags) {
12866 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
12867 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
12868 }
12869 return JVMTI_ERROR_UNATTACHED_THREAD;
12870 }
12871 JavaThread* current_thread = (JavaThread*)this_thread;
12872 ThreadInVMfromNative __tiv(current_thread);
12873 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetPotentialCapabilities , current_thread)
12874 debug_only(VMNativeEntryWrapper __vew;)
12875 CautiouslyPreserveExceptionMark __em(this_thread);
12876 if (capabilities_ptr == NULL) {
12877 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12878 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12879 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12880 }
12881 log_error(jvmti)("[%s] %s } %s - erroneous arg is capabilities_ptr", curr_thread_name, func_name,
12882 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
12883 }
12884 return JVMTI_ERROR_NULL_POINTER;
12885 }
12886
12887 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12888 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12889 }
12890 err = jvmti_env->GetPotentialCapabilities(capabilities_ptr);
12891 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12892 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12893 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12894 }
12895 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12896 JvmtiUtil::error_name(err));
12897 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12898 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12899 }
12900 } else {
12901 if (capabilities_ptr == NULL) {
12902 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12903 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12904 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12905 }
12906 log_error(jvmti)("[%s] %s } %s - erroneous arg is capabilities_ptr", curr_thread_name, func_name,
12907 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
12908 }
12909 return JVMTI_ERROR_NULL_POINTER;
12910 }
12911
12912 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12913 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12914 }
12915 err = jvmti_env->GetPotentialCapabilities(capabilities_ptr);
12916 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12917 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12918 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12919 }
12920 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12921 JvmtiUtil::error_name(err));
12922 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12923 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12924 }
12925 }
12926 return err;
12927}
12928
12929static jvmtiError JNICALL
12930jvmtiTrace_AddCapabilities(jvmtiEnv* env,
12931 const jvmtiCapabilities* capabilities_ptr) {
12932 SafeResourceMark rm;
12933 jint trace_flags = JvmtiTrace::trace_flags(142);
12934 const char *func_name = NULL;
12935 const char *curr_thread_name = NULL;
12936 if (trace_flags) {
12937 func_name = JvmtiTrace::function_name(142);
12938 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
12939 }
12940 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
12941 if (trace_flags) {
12942 log_trace(jvmti)("[-] %s %s", func_name,
12943 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
12944 }
12945 return JVMTI_ERROR_WRONG_PHASE;
12946 }
12947 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
12948 if (!jvmti_env->is_valid()) {
12949 if (trace_flags) {
12950 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
12951 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
12952 }
12953 return JVMTI_ERROR_INVALID_ENVIRONMENT;
12954 }
12955 jvmtiError err;
12956 if (Threads::number_of_threads() != 0) {
12957 Thread* this_thread = Thread::current_or_null();
12958 if (this_thread == NULL || !this_thread->is_Java_thread()) {
12959 if (trace_flags) {
12960 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
12961 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
12962 }
12963 return JVMTI_ERROR_UNATTACHED_THREAD;
12964 }
12965 JavaThread* current_thread = (JavaThread*)this_thread;
12966 ThreadInVMfromNative __tiv(current_thread);
12967 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_AddCapabilities , current_thread)
12968 debug_only(VMNativeEntryWrapper __vew;)
12969 CautiouslyPreserveExceptionMark __em(this_thread);
12970 if (capabilities_ptr == NULL) {
12971 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12972 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12973 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
12974 }
12975 log_error(jvmti)("[%s] %s } %s - erroneous arg is capabilities_ptr", curr_thread_name, func_name,
12976 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
12977 }
12978 return JVMTI_ERROR_NULL_POINTER;
12979 }
12980
12981 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
12982 log_trace(jvmti)("[%s] %s { capabilities_ptr=" PTR_FORMAT "", curr_thread_name, func_name,
12983 p2i(capabilities_ptr)
12984);
12985 }
12986 err = jvmti_env->AddCapabilities(capabilities_ptr);
12987 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
12988 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
12989 log_trace(jvmti)("[%s] %s { capabilities_ptr=" PTR_FORMAT "", curr_thread_name, func_name,
12990 p2i(capabilities_ptr)
12991);
12992 }
12993 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
12994 JvmtiUtil::error_name(err));
12995 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
12996 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
12997 }
12998 } else {
12999 if (capabilities_ptr == NULL) {
13000 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13001 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13002 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13003 }
13004 log_error(jvmti)("[%s] %s } %s - erroneous arg is capabilities_ptr", curr_thread_name, func_name,
13005 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13006 }
13007 return JVMTI_ERROR_NULL_POINTER;
13008 }
13009
13010 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13011 log_trace(jvmti)("[%s] %s { capabilities_ptr=" PTR_FORMAT "", curr_thread_name, func_name,
13012 p2i(capabilities_ptr)
13013);
13014 }
13015 err = jvmti_env->AddCapabilities(capabilities_ptr);
13016 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13017 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13018 log_trace(jvmti)("[%s] %s { capabilities_ptr=" PTR_FORMAT "", curr_thread_name, func_name,
13019 p2i(capabilities_ptr)
13020);
13021 }
13022 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13023 JvmtiUtil::error_name(err));
13024 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13025 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13026 }
13027 }
13028 return err;
13029}
13030
13031static jvmtiError JNICALL
13032jvmtiTrace_RelinquishCapabilities(jvmtiEnv* env,
13033 const jvmtiCapabilities* capabilities_ptr) {
13034
13035#if !INCLUDE_JVMTI
13036 return JVMTI_ERROR_NOT_AVAILABLE;
13037#else
13038 SafeResourceMark rm;
13039 jint trace_flags = JvmtiTrace::trace_flags(143);
13040 const char *func_name = NULL;
13041 const char *curr_thread_name = NULL;
13042 if (trace_flags) {
13043 func_name = JvmtiTrace::function_name(143);
13044 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
13045 }
13046 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
13047 if (trace_flags) {
13048 log_trace(jvmti)("[-] %s %s", func_name,
13049 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
13050 }
13051 return JVMTI_ERROR_WRONG_PHASE;
13052 }
13053 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
13054 if (!jvmti_env->is_valid()) {
13055 if (trace_flags) {
13056 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
13057 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
13058 }
13059 return JVMTI_ERROR_INVALID_ENVIRONMENT;
13060 }
13061 jvmtiError err;
13062 if (Threads::number_of_threads() != 0) {
13063 Thread* this_thread = Thread::current_or_null();
13064 if (this_thread == NULL || !this_thread->is_Java_thread()) {
13065 if (trace_flags) {
13066 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
13067 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
13068 }
13069 return JVMTI_ERROR_UNATTACHED_THREAD;
13070 }
13071 JavaThread* current_thread = (JavaThread*)this_thread;
13072 ThreadInVMfromNative __tiv(current_thread);
13073 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_RelinquishCapabilities , current_thread)
13074 debug_only(VMNativeEntryWrapper __vew;)
13075 CautiouslyPreserveExceptionMark __em(this_thread);
13076 if (capabilities_ptr == NULL) {
13077 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13078 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13079 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13080 }
13081 log_error(jvmti)("[%s] %s } %s - erroneous arg is capabilities_ptr", curr_thread_name, func_name,
13082 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13083 }
13084 return JVMTI_ERROR_NULL_POINTER;
13085 }
13086
13087 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13088 log_trace(jvmti)("[%s] %s { capabilities_ptr=" PTR_FORMAT "", curr_thread_name, func_name,
13089 p2i(capabilities_ptr)
13090);
13091 }
13092 err = jvmti_env->RelinquishCapabilities(capabilities_ptr);
13093 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13094 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13095 log_trace(jvmti)("[%s] %s { capabilities_ptr=" PTR_FORMAT "", curr_thread_name, func_name,
13096 p2i(capabilities_ptr)
13097);
13098 }
13099 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13100 JvmtiUtil::error_name(err));
13101 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13102 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13103 }
13104 } else {
13105 if (capabilities_ptr == NULL) {
13106 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13107 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13108 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13109 }
13110 log_error(jvmti)("[%s] %s } %s - erroneous arg is capabilities_ptr", curr_thread_name, func_name,
13111 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13112 }
13113 return JVMTI_ERROR_NULL_POINTER;
13114 }
13115
13116 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13117 log_trace(jvmti)("[%s] %s { capabilities_ptr=" PTR_FORMAT "", curr_thread_name, func_name,
13118 p2i(capabilities_ptr)
13119);
13120 }
13121 err = jvmti_env->RelinquishCapabilities(capabilities_ptr);
13122 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13123 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13124 log_trace(jvmti)("[%s] %s { capabilities_ptr=" PTR_FORMAT "", curr_thread_name, func_name,
13125 p2i(capabilities_ptr)
13126);
13127 }
13128 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13129 JvmtiUtil::error_name(err));
13130 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13131 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13132 }
13133 }
13134 return err;
13135#endif // INCLUDE_JVMTI
13136}
13137
13138static jvmtiError JNICALL
13139jvmtiTrace_GetCapabilities(jvmtiEnv* env,
13140 jvmtiCapabilities* capabilities_ptr) {
13141 SafeResourceMark rm;
13142 jint trace_flags = JvmtiTrace::trace_flags(89);
13143 const char *func_name = NULL;
13144 const char *curr_thread_name = NULL;
13145 if (trace_flags) {
13146 func_name = JvmtiTrace::function_name(89);
13147 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
13148 }
13149
13150 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
13151 if (!jvmti_env->is_valid()) {
13152 if (trace_flags) {
13153 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
13154 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
13155 }
13156 return JVMTI_ERROR_INVALID_ENVIRONMENT;
13157 }
13158 jvmtiError err;
13159 if (Threads::number_of_threads() != 0) {
13160 Thread* this_thread = Thread::current_or_null();
13161 if (this_thread == NULL || !this_thread->is_Java_thread()) {
13162 if (trace_flags) {
13163 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
13164 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
13165 }
13166 return JVMTI_ERROR_UNATTACHED_THREAD;
13167 }
13168 JavaThread* current_thread = (JavaThread*)this_thread;
13169 ThreadInVMfromNative __tiv(current_thread);
13170 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetCapabilities , current_thread)
13171 debug_only(VMNativeEntryWrapper __vew;)
13172 CautiouslyPreserveExceptionMark __em(this_thread);
13173 if (capabilities_ptr == NULL) {
13174 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13175 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13176 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13177 }
13178 log_error(jvmti)("[%s] %s } %s - erroneous arg is capabilities_ptr", curr_thread_name, func_name,
13179 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13180 }
13181 return JVMTI_ERROR_NULL_POINTER;
13182 }
13183
13184 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13185 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13186 }
13187 err = jvmti_env->GetCapabilities(capabilities_ptr);
13188 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13189 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13190 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13191 }
13192 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13193 JvmtiUtil::error_name(err));
13194 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13195 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13196 }
13197 } else {
13198 if (capabilities_ptr == NULL) {
13199 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13200 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13201 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13202 }
13203 log_error(jvmti)("[%s] %s } %s - erroneous arg is capabilities_ptr", curr_thread_name, func_name,
13204 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13205 }
13206 return JVMTI_ERROR_NULL_POINTER;
13207 }
13208
13209 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13210 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13211 }
13212 err = jvmti_env->GetCapabilities(capabilities_ptr);
13213 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13214 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13215 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13216 }
13217 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13218 JvmtiUtil::error_name(err));
13219 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13220 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13221 }
13222 }
13223 return err;
13224}
13225
13226 //
13227 // Timers functions
13228 //
13229
13230static jvmtiError JNICALL
13231jvmtiTrace_GetCurrentThreadCpuTimerInfo(jvmtiEnv* env,
13232 jvmtiTimerInfo* info_ptr) {
13233
13234#if !INCLUDE_JVMTI
13235 return JVMTI_ERROR_NOT_AVAILABLE;
13236#else
13237 SafeResourceMark rm;
13238 jint trace_flags = JvmtiTrace::trace_flags(134);
13239 const char *func_name = NULL;
13240 const char *curr_thread_name = NULL;
13241 if (trace_flags) {
13242 func_name = JvmtiTrace::function_name(134);
13243 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
13244 }
13245 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
13246 if (trace_flags) {
13247 log_trace(jvmti)("[-] %s %s", func_name,
13248 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
13249 }
13250 return JVMTI_ERROR_WRONG_PHASE;
13251 }
13252 Thread* this_thread = Thread::current_or_null();
13253 if (this_thread == NULL || (!this_thread->is_Java_thread() && !this_thread->is_Named_thread())) {
13254 if (trace_flags) {
13255 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
13256 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
13257 }
13258 return JVMTI_ERROR_UNATTACHED_THREAD;
13259 }
13260
13261 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
13262 if (!jvmti_env->is_valid()) {
13263 if (trace_flags) {
13264 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
13265 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
13266 }
13267 return JVMTI_ERROR_INVALID_ENVIRONMENT;
13268 }
13269
13270 if (jvmti_env->get_capabilities()->can_get_current_thread_cpu_time == 0) {
13271 if (trace_flags) {
13272 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
13273 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
13274 }
13275 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
13276 }
13277 jvmtiError err;
13278 if (info_ptr == NULL) {
13279 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13280 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13281 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13282 }
13283 log_error(jvmti)("[%s] %s } %s - erroneous arg is info_ptr", curr_thread_name, func_name,
13284 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13285 }
13286 return JVMTI_ERROR_NULL_POINTER;
13287 }
13288
13289 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13290 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13291 }
13292 err = jvmti_env->GetCurrentThreadCpuTimerInfo(info_ptr);
13293 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13294 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13295 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13296 }
13297 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13298 JvmtiUtil::error_name(err));
13299 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13300 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13301 }
13302 return err;
13303#endif // INCLUDE_JVMTI
13304}
13305
13306static jvmtiError JNICALL
13307jvmtiTrace_GetCurrentThreadCpuTime(jvmtiEnv* env,
13308 jlong* nanos_ptr) {
13309
13310#if !INCLUDE_JVMTI
13311 return JVMTI_ERROR_NOT_AVAILABLE;
13312#else
13313 SafeResourceMark rm;
13314 jint trace_flags = JvmtiTrace::trace_flags(135);
13315 const char *func_name = NULL;
13316 const char *curr_thread_name = NULL;
13317 if (trace_flags) {
13318 func_name = JvmtiTrace::function_name(135);
13319 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
13320 }
13321 if(JvmtiEnv::get_phase(env)!=JVMTI_PHASE_START && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
13322 if (trace_flags) {
13323 log_trace(jvmti)("[-] %s %s", func_name,
13324 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
13325 }
13326 return JVMTI_ERROR_WRONG_PHASE;
13327 }
13328 Thread* this_thread = Thread::current_or_null();
13329 if (this_thread == NULL || (!this_thread->is_Java_thread() && !this_thread->is_Named_thread())) {
13330 if (trace_flags) {
13331 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
13332 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
13333 }
13334 return JVMTI_ERROR_UNATTACHED_THREAD;
13335 }
13336
13337 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
13338 if (!jvmti_env->is_valid()) {
13339 if (trace_flags) {
13340 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
13341 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
13342 }
13343 return JVMTI_ERROR_INVALID_ENVIRONMENT;
13344 }
13345
13346 if (jvmti_env->get_capabilities()->can_get_current_thread_cpu_time == 0) {
13347 if (trace_flags) {
13348 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
13349 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
13350 }
13351 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
13352 }
13353 jvmtiError err;
13354 if (nanos_ptr == NULL) {
13355 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13356 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13357 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13358 }
13359 log_error(jvmti)("[%s] %s } %s - erroneous arg is nanos_ptr", curr_thread_name, func_name,
13360 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13361 }
13362 return JVMTI_ERROR_NULL_POINTER;
13363 }
13364
13365 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13366 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13367 }
13368 err = jvmti_env->GetCurrentThreadCpuTime(nanos_ptr);
13369 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13370 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13371 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13372 }
13373 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13374 JvmtiUtil::error_name(err));
13375 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13376 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13377 }
13378 return err;
13379#endif // INCLUDE_JVMTI
13380}
13381
13382static jvmtiError JNICALL
13383jvmtiTrace_GetThreadCpuTimerInfo(jvmtiEnv* env,
13384 jvmtiTimerInfo* info_ptr) {
13385
13386#if !INCLUDE_JVMTI
13387 return JVMTI_ERROR_NOT_AVAILABLE;
13388#else
13389 SafeResourceMark rm;
13390 jint trace_flags = JvmtiTrace::trace_flags(136);
13391 const char *func_name = NULL;
13392 const char *curr_thread_name = NULL;
13393 if (trace_flags) {
13394 func_name = JvmtiTrace::function_name(136);
13395 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
13396 }
13397 if(!JvmtiEnv::is_vm_live()) {
13398 if (trace_flags) {
13399 log_trace(jvmti)("[-] %s %s(%d)", func_name,
13400 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
13401 }
13402 return JVMTI_ERROR_WRONG_PHASE;
13403 }
13404 Thread* this_thread = Thread::current_or_null();
13405 if (this_thread == NULL || !this_thread->is_Java_thread()) {
13406 if (trace_flags) {
13407 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
13408 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
13409 }
13410 return JVMTI_ERROR_UNATTACHED_THREAD;
13411 }
13412 JavaThread* current_thread = (JavaThread*)this_thread;
13413 ThreadInVMfromNative __tiv(current_thread);
13414 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetThreadCpuTimerInfo , current_thread)
13415 debug_only(VMNativeEntryWrapper __vew;)
13416 CautiouslyPreserveExceptionMark __em(this_thread);
13417 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
13418 if (!jvmti_env->is_valid()) {
13419 if (trace_flags) {
13420 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
13421 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
13422 }
13423 return JVMTI_ERROR_INVALID_ENVIRONMENT;
13424 }
13425
13426 if (jvmti_env->get_capabilities()->can_get_thread_cpu_time == 0) {
13427 if (trace_flags) {
13428 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
13429 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
13430 }
13431 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
13432 }
13433 jvmtiError err;
13434 if (info_ptr == NULL) {
13435 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13436 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13437 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13438 }
13439 log_error(jvmti)("[%s] %s } %s - erroneous arg is info_ptr", curr_thread_name, func_name,
13440 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13441 }
13442 return JVMTI_ERROR_NULL_POINTER;
13443 }
13444
13445 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13446 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13447 }
13448 err = jvmti_env->GetThreadCpuTimerInfo(info_ptr);
13449 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13450 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13451 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13452 }
13453 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13454 JvmtiUtil::error_name(err));
13455 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13456 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13457 }
13458 return err;
13459#endif // INCLUDE_JVMTI
13460}
13461
13462static jvmtiError JNICALL
13463jvmtiTrace_GetThreadCpuTime(jvmtiEnv* env,
13464 jthread thread,
13465 jlong* nanos_ptr) {
13466
13467#if !INCLUDE_JVMTI
13468 return JVMTI_ERROR_NOT_AVAILABLE;
13469#else
13470 SafeResourceMark rm;
13471 jint trace_flags = JvmtiTrace::trace_flags(137);
13472 const char *func_name = NULL;
13473 const char *curr_thread_name = NULL;
13474 if (trace_flags) {
13475 func_name = JvmtiTrace::function_name(137);
13476 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
13477 }
13478 if(!JvmtiEnv::is_vm_live()) {
13479 if (trace_flags) {
13480 log_trace(jvmti)("[-] %s %s(%d)", func_name,
13481 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE), JvmtiEnv::get_phase());
13482 }
13483 return JVMTI_ERROR_WRONG_PHASE;
13484 }
13485 Thread* this_thread = Thread::current_or_null();
13486 if (this_thread == NULL || !this_thread->is_Java_thread()) {
13487 if (trace_flags) {
13488 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
13489 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
13490 }
13491 return JVMTI_ERROR_UNATTACHED_THREAD;
13492 }
13493 JavaThread* current_thread = (JavaThread*)this_thread;
13494 ThreadInVMfromNative __tiv(current_thread);
13495 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetThreadCpuTime , current_thread)
13496 debug_only(VMNativeEntryWrapper __vew;)
13497 CautiouslyPreserveExceptionMark __em(this_thread);
13498 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
13499 if (!jvmti_env->is_valid()) {
13500 if (trace_flags) {
13501 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
13502 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
13503 }
13504 return JVMTI_ERROR_INVALID_ENVIRONMENT;
13505 }
13506
13507 if (jvmti_env->get_capabilities()->can_get_thread_cpu_time == 0) {
13508 if (trace_flags) {
13509 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
13510 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
13511 }
13512 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
13513 }
13514 jvmtiError err;
13515 JavaThread* java_thread = NULL;
13516 ThreadsListHandle tlh(this_thread);
13517 if (thread == NULL) {
13518 java_thread = current_thread;
13519 } else {
13520 err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL);
13521 if (err != JVMTI_ERROR_NONE) {
13522 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13523 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13524 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13525 }
13526 log_error(jvmti)("[%s] %s } %s - erroneous arg is thread - jthread did not convert to a JavaThread - jthread = " PTR_FORMAT "", curr_thread_name, func_name,
13527 JvmtiUtil::error_name(err), p2i(thread));
13528 }
13529 return err;
13530 }
13531 }
13532 if (nanos_ptr == NULL) {
13533 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13534 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13535 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
13536 JvmtiTrace::safe_get_thread_name(java_thread));
13537 }
13538 log_error(jvmti)("[%s] %s } %s - erroneous arg is nanos_ptr", curr_thread_name, func_name,
13539 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13540 }
13541 return JVMTI_ERROR_NULL_POINTER;
13542 }
13543
13544 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13545 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
13546 JvmtiTrace::safe_get_thread_name(java_thread));
13547 }
13548 err = jvmti_env->GetThreadCpuTime(java_thread, nanos_ptr);
13549 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13550 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13551 log_trace(jvmti)("[%s] %s { thread=%s", curr_thread_name, func_name,
13552 JvmtiTrace::safe_get_thread_name(java_thread));
13553 }
13554 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13555 JvmtiUtil::error_name(err));
13556 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13557 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13558 }
13559 return err;
13560#endif // INCLUDE_JVMTI
13561}
13562
13563static jvmtiError JNICALL
13564jvmtiTrace_GetTimerInfo(jvmtiEnv* env,
13565 jvmtiTimerInfo* info_ptr) {
13566
13567#if !INCLUDE_JVMTI
13568 return JVMTI_ERROR_NOT_AVAILABLE;
13569#else
13570 SafeResourceMark rm;
13571 jint trace_flags = JvmtiTrace::trace_flags(138);
13572 const char *func_name = NULL;
13573 const char *curr_thread_name = NULL;
13574 if (trace_flags) {
13575 func_name = JvmtiTrace::function_name(138);
13576 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
13577 }
13578
13579 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
13580 if (!jvmti_env->is_valid()) {
13581 if (trace_flags) {
13582 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
13583 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
13584 }
13585 return JVMTI_ERROR_INVALID_ENVIRONMENT;
13586 }
13587 jvmtiError err;
13588 Thread* this_thread = NULL;
13589 bool transition;
13590 if (Threads::number_of_threads() == 0) {
13591 transition = false;
13592 } else {
13593 this_thread = Thread::current_or_null();
13594 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
13595 }
13596 if (transition) {
13597 if (!this_thread->is_Java_thread()) {
13598 if (trace_flags) {
13599 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
13600 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
13601 }
13602 return JVMTI_ERROR_UNATTACHED_THREAD;
13603 }
13604 JavaThread* current_thread = (JavaThread*)this_thread;
13605 ThreadInVMfromNative __tiv(current_thread);
13606 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetTimerInfo , current_thread)
13607 debug_only(VMNativeEntryWrapper __vew;)
13608 if (info_ptr == NULL) {
13609 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13610 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13611 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13612 }
13613 log_error(jvmti)("[%s] %s } %s - erroneous arg is info_ptr", curr_thread_name, func_name,
13614 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13615 }
13616 return JVMTI_ERROR_NULL_POINTER;
13617 }
13618
13619 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13620 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13621 }
13622 err = jvmti_env->GetTimerInfo(info_ptr);
13623 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13624 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13625 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13626 }
13627 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13628 JvmtiUtil::error_name(err));
13629 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13630 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13631 }
13632 } else {
13633 if (info_ptr == NULL) {
13634 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13635 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13636 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13637 }
13638 log_error(jvmti)("[%s] %s } %s - erroneous arg is info_ptr", curr_thread_name, func_name,
13639 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13640 }
13641 return JVMTI_ERROR_NULL_POINTER;
13642 }
13643
13644 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13645 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13646 }
13647 err = jvmti_env->GetTimerInfo(info_ptr);
13648 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13649 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13650 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13651 }
13652 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13653 JvmtiUtil::error_name(err));
13654 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13655 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13656 }
13657 }
13658 return err;
13659#endif // INCLUDE_JVMTI
13660}
13661
13662static jvmtiError JNICALL
13663jvmtiTrace_GetTime(jvmtiEnv* env,
13664 jlong* nanos_ptr) {
13665
13666#if !INCLUDE_JVMTI
13667 return JVMTI_ERROR_NOT_AVAILABLE;
13668#else
13669 SafeResourceMark rm;
13670 jint trace_flags = JvmtiTrace::trace_flags(139);
13671 const char *func_name = NULL;
13672 const char *curr_thread_name = NULL;
13673 if (trace_flags) {
13674 func_name = JvmtiTrace::function_name(139);
13675 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
13676 }
13677
13678 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
13679 if (!jvmti_env->is_valid()) {
13680 if (trace_flags) {
13681 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
13682 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
13683 }
13684 return JVMTI_ERROR_INVALID_ENVIRONMENT;
13685 }
13686 jvmtiError err;
13687 Thread* this_thread = NULL;
13688 bool transition;
13689 if (Threads::number_of_threads() == 0) {
13690 transition = false;
13691 } else {
13692 this_thread = Thread::current_or_null();
13693 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
13694 }
13695 if (transition) {
13696 if (!this_thread->is_Java_thread()) {
13697 if (trace_flags) {
13698 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
13699 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
13700 }
13701 return JVMTI_ERROR_UNATTACHED_THREAD;
13702 }
13703 JavaThread* current_thread = (JavaThread*)this_thread;
13704 ThreadInVMfromNative __tiv(current_thread);
13705 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetTime , current_thread)
13706 debug_only(VMNativeEntryWrapper __vew;)
13707 if (nanos_ptr == NULL) {
13708 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13709 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13710 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13711 }
13712 log_error(jvmti)("[%s] %s } %s - erroneous arg is nanos_ptr", curr_thread_name, func_name,
13713 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13714 }
13715 return JVMTI_ERROR_NULL_POINTER;
13716 }
13717
13718 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13719 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13720 }
13721 err = jvmti_env->GetTime(nanos_ptr);
13722 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13723 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13724 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13725 }
13726 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13727 JvmtiUtil::error_name(err));
13728 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13729 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13730 }
13731 } else {
13732 if (nanos_ptr == NULL) {
13733 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13734 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13735 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13736 }
13737 log_error(jvmti)("[%s] %s } %s - erroneous arg is nanos_ptr", curr_thread_name, func_name,
13738 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13739 }
13740 return JVMTI_ERROR_NULL_POINTER;
13741 }
13742
13743 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13744 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13745 }
13746 err = jvmti_env->GetTime(nanos_ptr);
13747 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13748 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13749 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13750 }
13751 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13752 JvmtiUtil::error_name(err));
13753 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13754 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13755 }
13756 }
13757 return err;
13758#endif // INCLUDE_JVMTI
13759}
13760
13761static jvmtiError JNICALL
13762jvmtiTrace_GetAvailableProcessors(jvmtiEnv* env,
13763 jint* processor_count_ptr) {
13764
13765#if !INCLUDE_JVMTI
13766 return JVMTI_ERROR_NOT_AVAILABLE;
13767#else
13768 SafeResourceMark rm;
13769 jint trace_flags = JvmtiTrace::trace_flags(144);
13770 const char *func_name = NULL;
13771 const char *curr_thread_name = NULL;
13772 if (trace_flags) {
13773 func_name = JvmtiTrace::function_name(144);
13774 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
13775 }
13776
13777 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
13778 if (!jvmti_env->is_valid()) {
13779 if (trace_flags) {
13780 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
13781 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
13782 }
13783 return JVMTI_ERROR_INVALID_ENVIRONMENT;
13784 }
13785 jvmtiError err;
13786 if (Threads::number_of_threads() != 0) {
13787 Thread* this_thread = Thread::current_or_null();
13788 if (this_thread == NULL || !this_thread->is_Java_thread()) {
13789 if (trace_flags) {
13790 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
13791 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
13792 }
13793 return JVMTI_ERROR_UNATTACHED_THREAD;
13794 }
13795 JavaThread* current_thread = (JavaThread*)this_thread;
13796 ThreadInVMfromNative __tiv(current_thread);
13797 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetAvailableProcessors , current_thread)
13798 debug_only(VMNativeEntryWrapper __vew;)
13799 CautiouslyPreserveExceptionMark __em(this_thread);
13800 if (processor_count_ptr == NULL) {
13801 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13802 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13803 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13804 }
13805 log_error(jvmti)("[%s] %s } %s - erroneous arg is processor_count_ptr", curr_thread_name, func_name,
13806 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13807 }
13808 return JVMTI_ERROR_NULL_POINTER;
13809 }
13810
13811 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13812 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13813 }
13814 err = jvmti_env->GetAvailableProcessors(processor_count_ptr);
13815 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13816 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13817 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13818 }
13819 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13820 JvmtiUtil::error_name(err));
13821 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13822 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13823 }
13824 } else {
13825 if (processor_count_ptr == NULL) {
13826 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13827 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13828 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13829 }
13830 log_error(jvmti)("[%s] %s } %s - erroneous arg is processor_count_ptr", curr_thread_name, func_name,
13831 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13832 }
13833 return JVMTI_ERROR_NULL_POINTER;
13834 }
13835
13836 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13837 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13838 }
13839 err = jvmti_env->GetAvailableProcessors(processor_count_ptr);
13840 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13841 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13842 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13843 }
13844 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13845 JvmtiUtil::error_name(err));
13846 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13847 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13848 }
13849 }
13850 return err;
13851#endif // INCLUDE_JVMTI
13852}
13853
13854 //
13855 // Class Loader Search functions
13856 //
13857
13858static jvmtiError JNICALL
13859jvmtiTrace_AddToBootstrapClassLoaderSearch(jvmtiEnv* env,
13860 const char* segment) {
13861 SafeResourceMark rm;
13862 jint trace_flags = JvmtiTrace::trace_flags(149);
13863 const char *func_name = NULL;
13864 const char *curr_thread_name = NULL;
13865 if (trace_flags) {
13866 func_name = JvmtiTrace::function_name(149);
13867 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
13868 }
13869 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
13870 if (trace_flags) {
13871 log_trace(jvmti)("[-] %s %s", func_name,
13872 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
13873 }
13874 return JVMTI_ERROR_WRONG_PHASE;
13875 }
13876 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
13877 if (!jvmti_env->is_valid()) {
13878 if (trace_flags) {
13879 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
13880 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
13881 }
13882 return JVMTI_ERROR_INVALID_ENVIRONMENT;
13883 }
13884 jvmtiError err;
13885 if (Threads::number_of_threads() != 0) {
13886 Thread* this_thread = Thread::current_or_null();
13887 if (this_thread == NULL || !this_thread->is_Java_thread()) {
13888 if (trace_flags) {
13889 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
13890 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
13891 }
13892 return JVMTI_ERROR_UNATTACHED_THREAD;
13893 }
13894 JavaThread* current_thread = (JavaThread*)this_thread;
13895 ThreadInVMfromNative __tiv(current_thread);
13896 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_AddToBootstrapClassLoaderSearch , current_thread)
13897 debug_only(VMNativeEntryWrapper __vew;)
13898 CautiouslyPreserveExceptionMark __em(this_thread);
13899 if (segment == NULL) {
13900 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13901 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13902 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13903 }
13904 log_error(jvmti)("[%s] %s } %s - erroneous arg is segment", curr_thread_name, func_name,
13905 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13906 }
13907 return JVMTI_ERROR_NULL_POINTER;
13908 }
13909
13910 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13911 log_trace(jvmti)("[%s] %s { segment='%s'", curr_thread_name, func_name, segment);
13912 }
13913 err = jvmti_env->AddToBootstrapClassLoaderSearch(segment);
13914 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13915 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13916 log_trace(jvmti)("[%s] %s { segment='%s'", curr_thread_name, func_name, segment);
13917 }
13918 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13919 JvmtiUtil::error_name(err));
13920 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13921 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13922 }
13923 } else {
13924 if (segment == NULL) {
13925 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13926 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13927 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13928 }
13929 log_error(jvmti)("[%s] %s } %s - erroneous arg is segment", curr_thread_name, func_name,
13930 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
13931 }
13932 return JVMTI_ERROR_NULL_POINTER;
13933 }
13934
13935 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
13936 log_trace(jvmti)("[%s] %s { segment='%s'", curr_thread_name, func_name, segment);
13937 }
13938 err = jvmti_env->AddToBootstrapClassLoaderSearch(segment);
13939 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13940 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13941 log_trace(jvmti)("[%s] %s { segment='%s'", curr_thread_name, func_name, segment);
13942 }
13943 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
13944 JvmtiUtil::error_name(err));
13945 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
13946 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
13947 }
13948 }
13949 return err;
13950}
13951
13952static jvmtiError JNICALL
13953jvmtiTrace_AddToSystemClassLoaderSearch(jvmtiEnv* env,
13954 const char* segment) {
13955 SafeResourceMark rm;
13956 jint trace_flags = JvmtiTrace::trace_flags(151);
13957 const char *func_name = NULL;
13958 const char *curr_thread_name = NULL;
13959 if (trace_flags) {
13960 func_name = JvmtiTrace::function_name(151);
13961 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
13962 }
13963 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
13964 if (trace_flags) {
13965 log_trace(jvmti)("[-] %s %s", func_name,
13966 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
13967 }
13968 return JVMTI_ERROR_WRONG_PHASE;
13969 }
13970 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
13971 if (!jvmti_env->is_valid()) {
13972 if (trace_flags) {
13973 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
13974 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
13975 }
13976 return JVMTI_ERROR_INVALID_ENVIRONMENT;
13977 }
13978 jvmtiError err;
13979 if (Threads::number_of_threads() != 0) {
13980 Thread* this_thread = Thread::current_or_null();
13981 if (this_thread == NULL || !this_thread->is_Java_thread()) {
13982 if (trace_flags) {
13983 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
13984 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
13985 }
13986 return JVMTI_ERROR_UNATTACHED_THREAD;
13987 }
13988 JavaThread* current_thread = (JavaThread*)this_thread;
13989 ThreadInVMfromNative __tiv(current_thread);
13990 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_AddToSystemClassLoaderSearch , current_thread)
13991 debug_only(VMNativeEntryWrapper __vew;)
13992 CautiouslyPreserveExceptionMark __em(this_thread);
13993 if (segment == NULL) {
13994 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
13995 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
13996 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
13997 }
13998 log_error(jvmti)("[%s] %s } %s - erroneous arg is segment", curr_thread_name, func_name,
13999 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14000 }
14001 return JVMTI_ERROR_NULL_POINTER;
14002 }
14003
14004 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14005 log_trace(jvmti)("[%s] %s { segment='%s'", curr_thread_name, func_name, segment);
14006 }
14007 err = jvmti_env->AddToSystemClassLoaderSearch(segment);
14008 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14009 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14010 log_trace(jvmti)("[%s] %s { segment='%s'", curr_thread_name, func_name, segment);
14011 }
14012 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14013 JvmtiUtil::error_name(err));
14014 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14015 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14016 }
14017 } else {
14018 if (segment == NULL) {
14019 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14020 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14021 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14022 }
14023 log_error(jvmti)("[%s] %s } %s - erroneous arg is segment", curr_thread_name, func_name,
14024 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14025 }
14026 return JVMTI_ERROR_NULL_POINTER;
14027 }
14028
14029 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14030 log_trace(jvmti)("[%s] %s { segment='%s'", curr_thread_name, func_name, segment);
14031 }
14032 err = jvmti_env->AddToSystemClassLoaderSearch(segment);
14033 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14034 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14035 log_trace(jvmti)("[%s] %s { segment='%s'", curr_thread_name, func_name, segment);
14036 }
14037 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14038 JvmtiUtil::error_name(err));
14039 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14040 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14041 }
14042 }
14043 return err;
14044}
14045
14046 //
14047 // System Properties functions
14048 //
14049
14050static jvmtiError JNICALL
14051jvmtiTrace_GetSystemProperties(jvmtiEnv* env,
14052 jint* count_ptr,
14053 char*** property_ptr) {
14054
14055#if !INCLUDE_JVMTI
14056 return JVMTI_ERROR_NOT_AVAILABLE;
14057#else
14058 SafeResourceMark rm;
14059 jint trace_flags = JvmtiTrace::trace_flags(130);
14060 const char *func_name = NULL;
14061 const char *curr_thread_name = NULL;
14062 if (trace_flags) {
14063 func_name = JvmtiTrace::function_name(130);
14064 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
14065 }
14066 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
14067 if (trace_flags) {
14068 log_trace(jvmti)("[-] %s %s", func_name,
14069 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
14070 }
14071 return JVMTI_ERROR_WRONG_PHASE;
14072 }
14073 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
14074 if (!jvmti_env->is_valid()) {
14075 if (trace_flags) {
14076 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
14077 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
14078 }
14079 return JVMTI_ERROR_INVALID_ENVIRONMENT;
14080 }
14081 jvmtiError err;
14082 if (Threads::number_of_threads() != 0) {
14083 Thread* this_thread = Thread::current_or_null();
14084 if (this_thread == NULL || !this_thread->is_Java_thread()) {
14085 if (trace_flags) {
14086 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
14087 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
14088 }
14089 return JVMTI_ERROR_UNATTACHED_THREAD;
14090 }
14091 JavaThread* current_thread = (JavaThread*)this_thread;
14092 ThreadInVMfromNative __tiv(current_thread);
14093 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetSystemProperties , current_thread)
14094 debug_only(VMNativeEntryWrapper __vew;)
14095 CautiouslyPreserveExceptionMark __em(this_thread);
14096 if (count_ptr == NULL) {
14097 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14098 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14099 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14100 }
14101 log_error(jvmti)("[%s] %s } %s - erroneous arg is count_ptr", curr_thread_name, func_name,
14102 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14103 }
14104 return JVMTI_ERROR_NULL_POINTER;
14105 }
14106 if (property_ptr == NULL) {
14107 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14108 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14109 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14110 }
14111 log_error(jvmti)("[%s] %s } %s - erroneous arg is property_ptr", curr_thread_name, func_name,
14112 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14113 }
14114 return JVMTI_ERROR_NULL_POINTER;
14115 }
14116
14117 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14118 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14119 }
14120 err = jvmti_env->GetSystemProperties(count_ptr, property_ptr);
14121 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14122 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14123 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14124 }
14125 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14126 JvmtiUtil::error_name(err));
14127 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14128 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14129 }
14130 } else {
14131 if (count_ptr == NULL) {
14132 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14133 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14134 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14135 }
14136 log_error(jvmti)("[%s] %s } %s - erroneous arg is count_ptr", curr_thread_name, func_name,
14137 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14138 }
14139 return JVMTI_ERROR_NULL_POINTER;
14140 }
14141 if (property_ptr == NULL) {
14142 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14143 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14144 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14145 }
14146 log_error(jvmti)("[%s] %s } %s - erroneous arg is property_ptr", curr_thread_name, func_name,
14147 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14148 }
14149 return JVMTI_ERROR_NULL_POINTER;
14150 }
14151
14152 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14153 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14154 }
14155 err = jvmti_env->GetSystemProperties(count_ptr, property_ptr);
14156 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14157 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14158 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14159 }
14160 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14161 JvmtiUtil::error_name(err));
14162 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14163 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14164 }
14165 }
14166 return err;
14167#endif // INCLUDE_JVMTI
14168}
14169
14170static jvmtiError JNICALL
14171jvmtiTrace_GetSystemProperty(jvmtiEnv* env,
14172 const char* property,
14173 char** value_ptr) {
14174
14175#if !INCLUDE_JVMTI
14176 return JVMTI_ERROR_NOT_AVAILABLE;
14177#else
14178 SafeResourceMark rm;
14179 jint trace_flags = JvmtiTrace::trace_flags(131);
14180 const char *func_name = NULL;
14181 const char *curr_thread_name = NULL;
14182 if (trace_flags) {
14183 func_name = JvmtiTrace::function_name(131);
14184 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
14185 }
14186 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
14187 if (trace_flags) {
14188 log_trace(jvmti)("[-] %s %s", func_name,
14189 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
14190 }
14191 return JVMTI_ERROR_WRONG_PHASE;
14192 }
14193 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
14194 if (!jvmti_env->is_valid()) {
14195 if (trace_flags) {
14196 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
14197 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
14198 }
14199 return JVMTI_ERROR_INVALID_ENVIRONMENT;
14200 }
14201 jvmtiError err;
14202 if (Threads::number_of_threads() != 0) {
14203 Thread* this_thread = Thread::current_or_null();
14204 if (this_thread == NULL || !this_thread->is_Java_thread()) {
14205 if (trace_flags) {
14206 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
14207 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
14208 }
14209 return JVMTI_ERROR_UNATTACHED_THREAD;
14210 }
14211 JavaThread* current_thread = (JavaThread*)this_thread;
14212 ThreadInVMfromNative __tiv(current_thread);
14213 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetSystemProperty , current_thread)
14214 debug_only(VMNativeEntryWrapper __vew;)
14215 CautiouslyPreserveExceptionMark __em(this_thread);
14216 if (property == NULL) {
14217 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14218 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14219 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14220 }
14221 log_error(jvmti)("[%s] %s } %s - erroneous arg is property", curr_thread_name, func_name,
14222 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14223 }
14224 return JVMTI_ERROR_NULL_POINTER;
14225 }
14226 if (value_ptr == NULL) {
14227 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14228 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14229 log_trace(jvmti)("[%s] %s { property='%s'", curr_thread_name, func_name, property);
14230 }
14231 log_error(jvmti)("[%s] %s } %s - erroneous arg is value_ptr", curr_thread_name, func_name,
14232 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14233 }
14234 return JVMTI_ERROR_NULL_POINTER;
14235 }
14236
14237 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14238 log_trace(jvmti)("[%s] %s { property='%s'", curr_thread_name, func_name, property);
14239 }
14240 err = jvmti_env->GetSystemProperty(property, value_ptr);
14241 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14242 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14243 log_trace(jvmti)("[%s] %s { property='%s'", curr_thread_name, func_name, property);
14244 }
14245 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14246 JvmtiUtil::error_name(err));
14247 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14248 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14249 }
14250 } else {
14251 if (property == NULL) {
14252 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14253 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14254 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14255 }
14256 log_error(jvmti)("[%s] %s } %s - erroneous arg is property", curr_thread_name, func_name,
14257 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14258 }
14259 return JVMTI_ERROR_NULL_POINTER;
14260 }
14261 if (value_ptr == NULL) {
14262 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14263 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14264 log_trace(jvmti)("[%s] %s { property='%s'", curr_thread_name, func_name, property);
14265 }
14266 log_error(jvmti)("[%s] %s } %s - erroneous arg is value_ptr", curr_thread_name, func_name,
14267 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14268 }
14269 return JVMTI_ERROR_NULL_POINTER;
14270 }
14271
14272 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14273 log_trace(jvmti)("[%s] %s { property='%s'", curr_thread_name, func_name, property);
14274 }
14275 err = jvmti_env->GetSystemProperty(property, value_ptr);
14276 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14277 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14278 log_trace(jvmti)("[%s] %s { property='%s'", curr_thread_name, func_name, property);
14279 }
14280 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14281 JvmtiUtil::error_name(err));
14282 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14283 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14284 }
14285 }
14286 return err;
14287#endif // INCLUDE_JVMTI
14288}
14289
14290static jvmtiError JNICALL
14291jvmtiTrace_SetSystemProperty(jvmtiEnv* env,
14292 const char* property,
14293 const char* value_ptr) {
14294
14295#if !INCLUDE_JVMTI
14296 return JVMTI_ERROR_NOT_AVAILABLE;
14297#else
14298 SafeResourceMark rm;
14299 jint trace_flags = JvmtiTrace::trace_flags(132);
14300 const char *func_name = NULL;
14301 const char *curr_thread_name = NULL;
14302 if (trace_flags) {
14303 func_name = JvmtiTrace::function_name(132);
14304 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
14305 }
14306 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD) {
14307 if (trace_flags) {
14308 log_trace(jvmti)("[-] %s %s", func_name,
14309 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
14310 }
14311 return JVMTI_ERROR_WRONG_PHASE;
14312 }
14313 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
14314 if (!jvmti_env->is_valid()) {
14315 if (trace_flags) {
14316 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
14317 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
14318 }
14319 return JVMTI_ERROR_INVALID_ENVIRONMENT;
14320 }
14321 jvmtiError err;
14322 if (Threads::number_of_threads() != 0) {
14323 Thread* this_thread = Thread::current_or_null();
14324 if (this_thread == NULL || !this_thread->is_Java_thread()) {
14325 if (trace_flags) {
14326 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
14327 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
14328 }
14329 return JVMTI_ERROR_UNATTACHED_THREAD;
14330 }
14331 JavaThread* current_thread = (JavaThread*)this_thread;
14332 ThreadInVMfromNative __tiv(current_thread);
14333 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetSystemProperty , current_thread)
14334 debug_only(VMNativeEntryWrapper __vew;)
14335 CautiouslyPreserveExceptionMark __em(this_thread);
14336 if (property == NULL) {
14337 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14338 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14339 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14340 }
14341 log_error(jvmti)("[%s] %s } %s - erroneous arg is property", curr_thread_name, func_name,
14342 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14343 }
14344 return JVMTI_ERROR_NULL_POINTER;
14345 }
14346
14347 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14348 log_trace(jvmti)("[%s] %s { property='%s' value_ptr='%s'", curr_thread_name, func_name, property, value_ptr);
14349 }
14350 err = jvmti_env->SetSystemProperty(property, value_ptr);
14351 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14352 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14353 log_trace(jvmti)("[%s] %s { property='%s' value_ptr='%s'", curr_thread_name, func_name, property, value_ptr);
14354 }
14355 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14356 JvmtiUtil::error_name(err));
14357 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14358 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14359 }
14360 } else {
14361 if (property == NULL) {
14362 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14363 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14364 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14365 }
14366 log_error(jvmti)("[%s] %s } %s - erroneous arg is property", curr_thread_name, func_name,
14367 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14368 }
14369 return JVMTI_ERROR_NULL_POINTER;
14370 }
14371
14372 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14373 log_trace(jvmti)("[%s] %s { property='%s' value_ptr='%s'", curr_thread_name, func_name, property, value_ptr);
14374 }
14375 err = jvmti_env->SetSystemProperty(property, value_ptr);
14376 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14377 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14378 log_trace(jvmti)("[%s] %s { property='%s' value_ptr='%s'", curr_thread_name, func_name, property, value_ptr);
14379 }
14380 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14381 JvmtiUtil::error_name(err));
14382 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14383 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14384 }
14385 }
14386 return err;
14387#endif // INCLUDE_JVMTI
14388}
14389
14390 //
14391 // General functions
14392 //
14393
14394static jvmtiError JNICALL
14395jvmtiTrace_GetPhase(jvmtiEnv* env,
14396 jvmtiPhase* phase_ptr) {
14397 SafeResourceMark rm;
14398 jint trace_flags = JvmtiTrace::trace_flags(133);
14399 const char *func_name = NULL;
14400 const char *curr_thread_name = NULL;
14401 if (trace_flags) {
14402 func_name = JvmtiTrace::function_name(133);
14403 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
14404 }
14405
14406 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
14407 if (!jvmti_env->is_valid()) {
14408 if (trace_flags) {
14409 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
14410 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
14411 }
14412 return JVMTI_ERROR_INVALID_ENVIRONMENT;
14413 }
14414 jvmtiError err;
14415 if (Threads::number_of_threads() != 0) {
14416 Thread* this_thread = Thread::current_or_null();
14417 if (this_thread == NULL || !this_thread->is_Java_thread()) {
14418 if (trace_flags) {
14419 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
14420 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
14421 }
14422 return JVMTI_ERROR_UNATTACHED_THREAD;
14423 }
14424 JavaThread* current_thread = (JavaThread*)this_thread;
14425 ThreadInVMfromNative __tiv(current_thread);
14426 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetPhase , current_thread)
14427 debug_only(VMNativeEntryWrapper __vew;)
14428 CautiouslyPreserveExceptionMark __em(this_thread);
14429 if (phase_ptr == NULL) {
14430 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14431 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14432 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14433 }
14434 log_error(jvmti)("[%s] %s } %s - erroneous arg is phase_ptr", curr_thread_name, func_name,
14435 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14436 }
14437 return JVMTI_ERROR_NULL_POINTER;
14438 }
14439
14440 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14441 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14442 }
14443 err = jvmti_env->GetPhase(phase_ptr);
14444 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14445 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14446 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14447 }
14448 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14449 JvmtiUtil::error_name(err));
14450 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14451 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14452 }
14453 } else {
14454 if (phase_ptr == NULL) {
14455 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14456 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14457 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14458 }
14459 log_error(jvmti)("[%s] %s } %s - erroneous arg is phase_ptr", curr_thread_name, func_name,
14460 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14461 }
14462 return JVMTI_ERROR_NULL_POINTER;
14463 }
14464
14465 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14466 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14467 }
14468 err = jvmti_env->GetPhase(phase_ptr);
14469 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14470 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14471 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14472 }
14473 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14474 JvmtiUtil::error_name(err));
14475 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14476 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14477 }
14478 }
14479 return err;
14480}
14481
14482static jvmtiError JNICALL
14483jvmtiTrace_DisposeEnvironment(jvmtiEnv* env) {
14484 SafeResourceMark rm;
14485 jint trace_flags = JvmtiTrace::trace_flags(127);
14486 const char *func_name = NULL;
14487 const char *curr_thread_name = NULL;
14488 if (trace_flags) {
14489 func_name = JvmtiTrace::function_name(127);
14490 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
14491 }
14492
14493 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
14494 if (!jvmti_env->is_valid()) {
14495 if (trace_flags) {
14496 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
14497 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
14498 }
14499 return JVMTI_ERROR_INVALID_ENVIRONMENT;
14500 }
14501 jvmtiError err;
14502 if (Threads::number_of_threads() != 0) {
14503 Thread* this_thread = Thread::current_or_null();
14504 if (this_thread == NULL || !this_thread->is_Java_thread()) {
14505 if (trace_flags) {
14506 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
14507 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
14508 }
14509 return JVMTI_ERROR_UNATTACHED_THREAD;
14510 }
14511 JavaThread* current_thread = (JavaThread*)this_thread;
14512 ThreadInVMfromNative __tiv(current_thread);
14513 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_DisposeEnvironment , current_thread)
14514 debug_only(VMNativeEntryWrapper __vew;)
14515 CautiouslyPreserveExceptionMark __em(this_thread);
14516
14517 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14518 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14519 }
14520 err = jvmti_env->DisposeEnvironment();
14521 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14522 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14523 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14524 }
14525 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14526 JvmtiUtil::error_name(err));
14527 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14528 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14529 }
14530 } else {
14531
14532 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14533 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14534 }
14535 err = jvmti_env->DisposeEnvironment();
14536 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14537 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14538 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14539 }
14540 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14541 JvmtiUtil::error_name(err));
14542 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14543 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14544 }
14545 }
14546 return err;
14547}
14548
14549static jvmtiError JNICALL
14550jvmtiTrace_SetEnvironmentLocalStorage(jvmtiEnv* env,
14551 const void* data) {
14552 SafeResourceMark rm;
14553 jint trace_flags = JvmtiTrace::trace_flags(148);
14554 const char *func_name = NULL;
14555 const char *curr_thread_name = NULL;
14556 if (trace_flags) {
14557 func_name = JvmtiTrace::function_name(148);
14558 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
14559 }
14560
14561 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
14562 if (!jvmti_env->is_valid()) {
14563 if (trace_flags) {
14564 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
14565 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
14566 }
14567 return JVMTI_ERROR_INVALID_ENVIRONMENT;
14568 }
14569 jvmtiError err;
14570 Thread* this_thread = NULL;
14571 bool transition;
14572 if (Threads::number_of_threads() == 0) {
14573 transition = false;
14574 } else {
14575 this_thread = Thread::current_or_null();
14576 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
14577 }
14578 if (transition) {
14579 if (!this_thread->is_Java_thread()) {
14580 if (trace_flags) {
14581 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
14582 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
14583 }
14584 return JVMTI_ERROR_UNATTACHED_THREAD;
14585 }
14586
14587
14588 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14589 log_trace(jvmti)("[%s] %s { data=" PTR_FORMAT "", curr_thread_name, func_name,
14590 p2i(data)
14591 );
14592 }
14593 err = jvmti_env->SetEnvironmentLocalStorage(data);
14594 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14595 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14596 log_trace(jvmti)("[%s] %s { data=" PTR_FORMAT "", curr_thread_name, func_name,
14597 p2i(data)
14598 );
14599 }
14600 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14601 JvmtiUtil::error_name(err));
14602 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14603 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14604 }
14605 } else {
14606
14607 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14608 log_trace(jvmti)("[%s] %s { data=" PTR_FORMAT "", curr_thread_name, func_name,
14609 p2i(data)
14610 );
14611 }
14612 err = jvmti_env->SetEnvironmentLocalStorage(data);
14613 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14614 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14615 log_trace(jvmti)("[%s] %s { data=" PTR_FORMAT "", curr_thread_name, func_name,
14616 p2i(data)
14617 );
14618 }
14619 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14620 JvmtiUtil::error_name(err));
14621 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14622 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14623 }
14624 }
14625 return err;
14626}
14627
14628static jvmtiError JNICALL
14629jvmtiTrace_GetEnvironmentLocalStorage(jvmtiEnv* env,
14630 void** data_ptr) {
14631 SafeResourceMark rm;
14632 jint trace_flags = JvmtiTrace::trace_flags(147);
14633 const char *func_name = NULL;
14634 const char *curr_thread_name = NULL;
14635 if (trace_flags) {
14636 func_name = JvmtiTrace::function_name(147);
14637 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
14638 }
14639
14640 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
14641 if (!jvmti_env->is_valid()) {
14642 if (trace_flags) {
14643 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
14644 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
14645 }
14646 return JVMTI_ERROR_INVALID_ENVIRONMENT;
14647 }
14648 jvmtiError err;
14649 Thread* this_thread = NULL;
14650 bool transition;
14651 if (Threads::number_of_threads() == 0) {
14652 transition = false;
14653 } else {
14654 this_thread = Thread::current_or_null();
14655 transition = ((this_thread != NULL) && !this_thread->is_Named_thread());
14656 }
14657 if (transition) {
14658 if (!this_thread->is_Java_thread()) {
14659 if (trace_flags) {
14660 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
14661 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
14662 }
14663 return JVMTI_ERROR_UNATTACHED_THREAD;
14664 }
14665
14666 if (data_ptr == NULL) {
14667 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14668 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14669 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14670 }
14671 log_error(jvmti)("[%s] %s } %s - erroneous arg is data_ptr", curr_thread_name, func_name,
14672 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14673 }
14674 return JVMTI_ERROR_NULL_POINTER;
14675 }
14676
14677 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14678 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14679 }
14680 err = jvmti_env->GetEnvironmentLocalStorage(data_ptr);
14681 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14682 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14683 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14684 }
14685 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14686 JvmtiUtil::error_name(err));
14687 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14688 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14689 }
14690 } else {
14691 if (data_ptr == NULL) {
14692 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14693 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14694 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14695 }
14696 log_error(jvmti)("[%s] %s } %s - erroneous arg is data_ptr", curr_thread_name, func_name,
14697 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14698 }
14699 return JVMTI_ERROR_NULL_POINTER;
14700 }
14701
14702 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14703 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14704 }
14705 err = jvmti_env->GetEnvironmentLocalStorage(data_ptr);
14706 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14707 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14708 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14709 }
14710 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14711 JvmtiUtil::error_name(err));
14712 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14713 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14714 }
14715 }
14716 return err;
14717}
14718
14719static jvmtiError JNICALL
14720jvmtiTrace_GetVersionNumber(jvmtiEnv* env,
14721 jint* version_ptr) {
14722 SafeResourceMark rm;
14723 jint trace_flags = JvmtiTrace::trace_flags(88);
14724 const char *func_name = NULL;
14725 const char *curr_thread_name = NULL;
14726 if (trace_flags) {
14727 func_name = JvmtiTrace::function_name(88);
14728 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
14729 }
14730
14731 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
14732 if (!jvmti_env->is_valid()) {
14733 if (trace_flags) {
14734 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
14735 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
14736 }
14737 return JVMTI_ERROR_INVALID_ENVIRONMENT;
14738 }
14739 jvmtiError err;
14740 if (Threads::number_of_threads() != 0) {
14741 Thread* this_thread = Thread::current_or_null();
14742 if (this_thread == NULL || !this_thread->is_Java_thread()) {
14743 if (trace_flags) {
14744 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
14745 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
14746 }
14747 return JVMTI_ERROR_UNATTACHED_THREAD;
14748 }
14749 JavaThread* current_thread = (JavaThread*)this_thread;
14750 ThreadInVMfromNative __tiv(current_thread);
14751 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetVersionNumber , current_thread)
14752 debug_only(VMNativeEntryWrapper __vew;)
14753 CautiouslyPreserveExceptionMark __em(this_thread);
14754 if (version_ptr == NULL) {
14755 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14756 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14757 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14758 }
14759 log_error(jvmti)("[%s] %s } %s - erroneous arg is version_ptr", curr_thread_name, func_name,
14760 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14761 }
14762 return JVMTI_ERROR_NULL_POINTER;
14763 }
14764
14765 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14766 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14767 }
14768 err = jvmti_env->GetVersionNumber(version_ptr);
14769 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14770 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14771 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14772 }
14773 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14774 JvmtiUtil::error_name(err));
14775 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14776 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14777 }
14778 } else {
14779 if (version_ptr == NULL) {
14780 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14781 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14782 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14783 }
14784 log_error(jvmti)("[%s] %s } %s - erroneous arg is version_ptr", curr_thread_name, func_name,
14785 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14786 }
14787 return JVMTI_ERROR_NULL_POINTER;
14788 }
14789
14790 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14791 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14792 }
14793 err = jvmti_env->GetVersionNumber(version_ptr);
14794 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14795 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14796 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
14797 }
14798 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14799 JvmtiUtil::error_name(err));
14800 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14801 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14802 }
14803 }
14804 return err;
14805}
14806
14807static jvmtiError JNICALL
14808jvmtiTrace_GetErrorName(jvmtiEnv* env,
14809 jvmtiError error,
14810 char** name_ptr) {
14811
14812#if !INCLUDE_JVMTI
14813 return JVMTI_ERROR_NOT_AVAILABLE;
14814#else
14815 SafeResourceMark rm;
14816 jint trace_flags = JvmtiTrace::trace_flags(128);
14817 const char *func_name = NULL;
14818 const char *curr_thread_name = NULL;
14819 if (trace_flags) {
14820 func_name = JvmtiTrace::function_name(128);
14821 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
14822 }
14823
14824 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
14825 if (!jvmti_env->is_valid()) {
14826 if (trace_flags) {
14827 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
14828 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
14829 }
14830 return JVMTI_ERROR_INVALID_ENVIRONMENT;
14831 }
14832 jvmtiError err;
14833 if (Threads::number_of_threads() != 0) {
14834 Thread* this_thread = Thread::current_or_null();
14835 if (this_thread == NULL || !this_thread->is_Java_thread()) {
14836 if (trace_flags) {
14837 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
14838 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
14839 }
14840 return JVMTI_ERROR_UNATTACHED_THREAD;
14841 }
14842 JavaThread* current_thread = (JavaThread*)this_thread;
14843 ThreadInVMfromNative __tiv(current_thread);
14844 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetErrorName , current_thread)
14845 debug_only(VMNativeEntryWrapper __vew;)
14846 CautiouslyPreserveExceptionMark __em(this_thread);
14847 if (name_ptr == NULL) {
14848 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14849 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14850 log_trace(jvmti)("[%s] %s { error=%d:%s", curr_thread_name, func_name, error,
14851 JvmtiUtil::error_name(error)
14852);
14853 }
14854 log_error(jvmti)("[%s] %s } %s - erroneous arg is name_ptr", curr_thread_name, func_name,
14855 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14856 }
14857 return JVMTI_ERROR_NULL_POINTER;
14858 }
14859
14860 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14861 log_trace(jvmti)("[%s] %s { error=%d:%s", curr_thread_name, func_name, error,
14862 JvmtiUtil::error_name(error)
14863);
14864 }
14865 err = jvmti_env->GetErrorName(error, name_ptr);
14866 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14867 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14868 log_trace(jvmti)("[%s] %s { error=%d:%s", curr_thread_name, func_name, error,
14869 JvmtiUtil::error_name(error)
14870);
14871 }
14872 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14873 JvmtiUtil::error_name(err));
14874 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14875 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14876 }
14877 } else {
14878 if (name_ptr == NULL) {
14879 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14880 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14881 log_trace(jvmti)("[%s] %s { error=%d:%s", curr_thread_name, func_name, error,
14882 JvmtiUtil::error_name(error)
14883);
14884 }
14885 log_error(jvmti)("[%s] %s } %s - erroneous arg is name_ptr", curr_thread_name, func_name,
14886 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
14887 }
14888 return JVMTI_ERROR_NULL_POINTER;
14889 }
14890
14891 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14892 log_trace(jvmti)("[%s] %s { error=%d:%s", curr_thread_name, func_name, error,
14893 JvmtiUtil::error_name(error)
14894);
14895 }
14896 err = jvmti_env->GetErrorName(error, name_ptr);
14897 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14898 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14899 log_trace(jvmti)("[%s] %s { error=%d:%s", curr_thread_name, func_name, error,
14900 JvmtiUtil::error_name(error)
14901);
14902 }
14903 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14904 JvmtiUtil::error_name(err));
14905 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14906 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14907 }
14908 }
14909 return err;
14910#endif // INCLUDE_JVMTI
14911}
14912
14913static jvmtiError JNICALL
14914jvmtiTrace_SetVerboseFlag(jvmtiEnv* env,
14915 jvmtiVerboseFlag flag,
14916 jboolean value) {
14917
14918#if !INCLUDE_JVMTI
14919 return JVMTI_ERROR_NOT_AVAILABLE;
14920#else
14921 SafeResourceMark rm;
14922 jint trace_flags = JvmtiTrace::trace_flags(150);
14923 const char *func_name = NULL;
14924 const char *curr_thread_name = NULL;
14925 if (trace_flags) {
14926 func_name = JvmtiTrace::function_name(150);
14927 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
14928 }
14929
14930 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
14931 if (!jvmti_env->is_valid()) {
14932 if (trace_flags) {
14933 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
14934 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
14935 }
14936 return JVMTI_ERROR_INVALID_ENVIRONMENT;
14937 }
14938 jvmtiError err;
14939 if (Threads::number_of_threads() != 0) {
14940 Thread* this_thread = Thread::current_or_null();
14941 if (this_thread == NULL || !this_thread->is_Java_thread()) {
14942 if (trace_flags) {
14943 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
14944 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
14945 }
14946 return JVMTI_ERROR_UNATTACHED_THREAD;
14947 }
14948 JavaThread* current_thread = (JavaThread*)this_thread;
14949 ThreadInVMfromNative __tiv(current_thread);
14950 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetVerboseFlag , current_thread)
14951 debug_only(VMNativeEntryWrapper __vew;)
14952 CautiouslyPreserveExceptionMark __em(this_thread);
14953
14954 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14955 log_trace(jvmti)("[%s] %s { flag=%d:%s value=%s", curr_thread_name, func_name, flag,
14956 JvmtiTrace::enum_name(jvmtiVerboseFlagConstantNames, jvmtiVerboseFlagConstantValues, flag), value? "true" : "false");
14957 }
14958 err = jvmti_env->SetVerboseFlag(flag, value);
14959 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14960 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14961 log_trace(jvmti)("[%s] %s { flag=%d:%s value=%s", curr_thread_name, func_name, flag,
14962 JvmtiTrace::enum_name(jvmtiVerboseFlagConstantNames, jvmtiVerboseFlagConstantValues, flag), value? "true" : "false");
14963 }
14964 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14965 JvmtiUtil::error_name(err));
14966 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14967 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14968 }
14969 } else {
14970
14971 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
14972 log_trace(jvmti)("[%s] %s { flag=%d:%s value=%s", curr_thread_name, func_name, flag,
14973 JvmtiTrace::enum_name(jvmtiVerboseFlagConstantNames, jvmtiVerboseFlagConstantValues, flag), value? "true" : "false");
14974 }
14975 err = jvmti_env->SetVerboseFlag(flag, value);
14976 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
14977 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
14978 log_trace(jvmti)("[%s] %s { flag=%d:%s value=%s", curr_thread_name, func_name, flag,
14979 JvmtiTrace::enum_name(jvmtiVerboseFlagConstantNames, jvmtiVerboseFlagConstantValues, flag), value? "true" : "false");
14980 }
14981 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
14982 JvmtiUtil::error_name(err));
14983 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
14984 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
14985 }
14986 }
14987 return err;
14988#endif // INCLUDE_JVMTI
14989}
14990
14991static jvmtiError JNICALL
14992jvmtiTrace_GetJLocationFormat(jvmtiEnv* env,
14993 jvmtiJlocationFormat* format_ptr) {
14994
14995#if !INCLUDE_JVMTI
14996 return JVMTI_ERROR_NOT_AVAILABLE;
14997#else
14998 SafeResourceMark rm;
14999 jint trace_flags = JvmtiTrace::trace_flags(129);
15000 const char *func_name = NULL;
15001 const char *curr_thread_name = NULL;
15002 if (trace_flags) {
15003 func_name = JvmtiTrace::function_name(129);
15004 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
15005 }
15006
15007 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
15008 if (!jvmti_env->is_valid()) {
15009 if (trace_flags) {
15010 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
15011 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
15012 }
15013 return JVMTI_ERROR_INVALID_ENVIRONMENT;
15014 }
15015 jvmtiError err;
15016 if (Threads::number_of_threads() != 0) {
15017 Thread* this_thread = Thread::current_or_null();
15018 if (this_thread == NULL || !this_thread->is_Java_thread()) {
15019 if (trace_flags) {
15020 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
15021 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
15022 }
15023 return JVMTI_ERROR_UNATTACHED_THREAD;
15024 }
15025 JavaThread* current_thread = (JavaThread*)this_thread;
15026 ThreadInVMfromNative __tiv(current_thread);
15027 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_GetJLocationFormat , current_thread)
15028 debug_only(VMNativeEntryWrapper __vew;)
15029 CautiouslyPreserveExceptionMark __em(this_thread);
15030 if (format_ptr == NULL) {
15031 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
15032 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
15033 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
15034 }
15035 log_error(jvmti)("[%s] %s } %s - erroneous arg is format_ptr", curr_thread_name, func_name,
15036 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
15037 }
15038 return JVMTI_ERROR_NULL_POINTER;
15039 }
15040
15041 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
15042 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
15043 }
15044 err = jvmti_env->GetJLocationFormat(format_ptr);
15045 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
15046 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
15047 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
15048 }
15049 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
15050 JvmtiUtil::error_name(err));
15051 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
15052 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
15053 }
15054 } else {
15055 if (format_ptr == NULL) {
15056 if ((trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
15057 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
15058 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
15059 }
15060 log_error(jvmti)("[%s] %s } %s - erroneous arg is format_ptr", curr_thread_name, func_name,
15061 JvmtiUtil::error_name(JVMTI_ERROR_NULL_POINTER));
15062 }
15063 return JVMTI_ERROR_NULL_POINTER;
15064 }
15065
15066 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
15067 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
15068 }
15069 err = jvmti_env->GetJLocationFormat(format_ptr);
15070 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
15071 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
15072 log_trace(jvmti)("[%s] %s { ", curr_thread_name, func_name);
15073 }
15074 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
15075 JvmtiUtil::error_name(err));
15076 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
15077 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
15078 }
15079 }
15080 return err;
15081#endif // INCLUDE_JVMTI
15082}
15083
15084 //
15085 // Heap Monitoring functions
15086 //
15087
15088static jvmtiError JNICALL
15089jvmtiTrace_SetHeapSamplingInterval(jvmtiEnv* env,
15090 jint sampling_interval) {
15091
15092#if !INCLUDE_JVMTI
15093 return JVMTI_ERROR_NOT_AVAILABLE;
15094#else
15095 SafeResourceMark rm;
15096 jint trace_flags = JvmtiTrace::trace_flags(156);
15097 const char *func_name = NULL;
15098 const char *curr_thread_name = NULL;
15099 if (trace_flags) {
15100 func_name = JvmtiTrace::function_name(156);
15101 curr_thread_name = JvmtiTrace::safe_get_current_thread_name();
15102 }
15103 if(JvmtiEnv::get_phase()!=JVMTI_PHASE_ONLOAD && JvmtiEnv::get_phase()!=JVMTI_PHASE_LIVE) {
15104 if (trace_flags) {
15105 log_trace(jvmti)("[-] %s %s", func_name,
15106 JvmtiUtil::error_name(JVMTI_ERROR_WRONG_PHASE));
15107 }
15108 return JVMTI_ERROR_WRONG_PHASE;
15109 }
15110 JvmtiEnv* jvmti_env = JvmtiEnv::JvmtiEnv_from_jvmti_env(env);
15111 if (!jvmti_env->is_valid()) {
15112 if (trace_flags) {
15113 log_trace(jvmti)("[%s] %s %s env=" PTR_FORMAT, curr_thread_name, func_name,
15114 JvmtiUtil::error_name(JVMTI_ERROR_INVALID_ENVIRONMENT), p2i(env));
15115 }
15116 return JVMTI_ERROR_INVALID_ENVIRONMENT;
15117 }
15118
15119 if (jvmti_env->get_capabilities()->can_generate_sampled_object_alloc_events == 0) {
15120 if (trace_flags) {
15121 log_trace(jvmti)("[%s] %s %s", curr_thread_name, func_name,
15122 JvmtiUtil::error_name(JVMTI_ERROR_MUST_POSSESS_CAPABILITY));
15123 }
15124 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
15125 }
15126 jvmtiError err;
15127 if (Threads::number_of_threads() != 0) {
15128 Thread* this_thread = Thread::current_or_null();
15129 if (this_thread == NULL || !this_thread->is_Java_thread()) {
15130 if (trace_flags) {
15131 log_trace(jvmti)("[non-attached thread] %s %s", func_name,
15132 JvmtiUtil::error_name(JVMTI_ERROR_UNATTACHED_THREAD));
15133 }
15134 return JVMTI_ERROR_UNATTACHED_THREAD;
15135 }
15136 JavaThread* current_thread = (JavaThread*)this_thread;
15137 ThreadInVMfromNative __tiv(current_thread);
15138 VM_ENTRY_BASE(jvmtiError, jvmtiTrace_SetHeapSamplingInterval , current_thread)
15139 debug_only(VMNativeEntryWrapper __vew;)
15140 CautiouslyPreserveExceptionMark __em(this_thread);
15141
15142 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
15143 log_trace(jvmti)("[%s] %s { sampling_interval=" INT32_FORMAT "", curr_thread_name, func_name, sampling_interval);
15144 }
15145 err = jvmti_env->SetHeapSamplingInterval(sampling_interval);
15146 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
15147 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
15148 log_trace(jvmti)("[%s] %s { sampling_interval=" INT32_FORMAT "", curr_thread_name, func_name, sampling_interval);
15149 }
15150 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
15151 JvmtiUtil::error_name(err));
15152 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
15153 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
15154 }
15155 } else {
15156
15157 if ((trace_flags & JvmtiTrace::SHOW_IN) != 0) {
15158 log_trace(jvmti)("[%s] %s { sampling_interval=" INT32_FORMAT "", curr_thread_name, func_name, sampling_interval);
15159 }
15160 err = jvmti_env->SetHeapSamplingInterval(sampling_interval);
15161 if ( err != JVMTI_ERROR_NONE && (trace_flags & JvmtiTrace::SHOW_ERROR) != 0) {
15162 if ((trace_flags & JvmtiTrace::SHOW_IN) == 0) {
15163 log_trace(jvmti)("[%s] %s { sampling_interval=" INT32_FORMAT "", curr_thread_name, func_name, sampling_interval);
15164 }
15165 log_error(jvmti)("[%s] %s } %s", curr_thread_name, func_name,
15166 JvmtiUtil::error_name(err));
15167 } else if ((trace_flags & JvmtiTrace::SHOW_OUT) != 0) {
15168 log_trace(jvmti)("[%s] %s }", curr_thread_name, func_name);
15169 }
15170 }
15171 return err;
15172#endif // INCLUDE_JVMTI
15173}
15174
15175} /* end extern "C" */
15176
15177// JVMTI API functions
15178struct jvmtiInterface_1_ jvmtiTrace_Interface = {
15179 /* 1 : RESERVED */
15180 NULL,
15181 /* 2 : Set Event Notification Mode */
15182 jvmtiTrace_SetEventNotificationMode,
15183 /* 3 : Get All Modules */
15184 jvmtiTrace_GetAllModules,
15185 /* 4 : Get All Threads */
15186 jvmtiTrace_GetAllThreads,
15187 /* 5 : Suspend Thread */
15188 jvmtiTrace_SuspendThread,
15189 /* 6 : Resume Thread */
15190 jvmtiTrace_ResumeThread,
15191 /* 7 : Stop Thread */
15192 jvmtiTrace_StopThread,
15193 /* 8 : Interrupt Thread */
15194 jvmtiTrace_InterruptThread,
15195 /* 9 : Get Thread Info */
15196 jvmtiTrace_GetThreadInfo,
15197 /* 10 : Get Owned Monitor Info */
15198 jvmtiTrace_GetOwnedMonitorInfo,
15199 /* 11 : Get Current Contended Monitor */
15200 jvmtiTrace_GetCurrentContendedMonitor,
15201 /* 12 : Run Agent Thread */
15202 jvmtiTrace_RunAgentThread,
15203 /* 13 : Get Top Thread Groups */
15204 jvmtiTrace_GetTopThreadGroups,
15205 /* 14 : Get Thread Group Info */
15206 jvmtiTrace_GetThreadGroupInfo,
15207 /* 15 : Get Thread Group Children */
15208 jvmtiTrace_GetThreadGroupChildren,
15209 /* 16 : Get Frame Count */
15210 jvmtiTrace_GetFrameCount,
15211 /* 17 : Get Thread State */
15212 jvmtiTrace_GetThreadState,
15213 /* 18 : Get Current Thread */
15214 jvmtiTrace_GetCurrentThread,
15215 /* 19 : Get Frame Location */
15216 jvmtiTrace_GetFrameLocation,
15217 /* 20 : Notify Frame Pop */
15218 jvmtiTrace_NotifyFramePop,
15219 /* 21 : Get Local Variable - Object */
15220 jvmtiTrace_GetLocalObject,
15221 /* 22 : Get Local Variable - Int */
15222 jvmtiTrace_GetLocalInt,
15223 /* 23 : Get Local Variable - Long */
15224 jvmtiTrace_GetLocalLong,
15225 /* 24 : Get Local Variable - Float */
15226 jvmtiTrace_GetLocalFloat,
15227 /* 25 : Get Local Variable - Double */
15228 jvmtiTrace_GetLocalDouble,
15229 /* 26 : Set Local Variable - Object */
15230 jvmtiTrace_SetLocalObject,
15231 /* 27 : Set Local Variable - Int */
15232 jvmtiTrace_SetLocalInt,
15233 /* 28 : Set Local Variable - Long */
15234 jvmtiTrace_SetLocalLong,
15235 /* 29 : Set Local Variable - Float */
15236 jvmtiTrace_SetLocalFloat,
15237 /* 30 : Set Local Variable - Double */
15238 jvmtiTrace_SetLocalDouble,
15239 /* 31 : Create Raw Monitor */
15240 jvmtiTrace_CreateRawMonitor,
15241 /* 32 : Destroy Raw Monitor */
15242 jvmtiTrace_DestroyRawMonitor,
15243 /* 33 : Raw Monitor Enter */
15244 jvmtiTrace_RawMonitorEnter,
15245 /* 34 : Raw Monitor Exit */
15246 jvmtiTrace_RawMonitorExit,
15247 /* 35 : Raw Monitor Wait */
15248 jvmtiTrace_RawMonitorWait,
15249 /* 36 : Raw Monitor Notify */
15250 jvmtiTrace_RawMonitorNotify,
15251 /* 37 : Raw Monitor Notify All */
15252 jvmtiTrace_RawMonitorNotifyAll,
15253 /* 38 : Set Breakpoint */
15254 jvmtiTrace_SetBreakpoint,
15255 /* 39 : Clear Breakpoint */
15256 jvmtiTrace_ClearBreakpoint,
15257 /* 40 : Get Named Module */
15258 jvmtiTrace_GetNamedModule,
15259 /* 41 : Set Field Access Watch */
15260 jvmtiTrace_SetFieldAccessWatch,
15261 /* 42 : Clear Field Access Watch */
15262 jvmtiTrace_ClearFieldAccessWatch,
15263 /* 43 : Set Field Modification Watch */
15264 jvmtiTrace_SetFieldModificationWatch,
15265 /* 44 : Clear Field Modification Watch */
15266 jvmtiTrace_ClearFieldModificationWatch,
15267 /* 45 : Is Modifiable Class */
15268 jvmtiTrace_IsModifiableClass,
15269 /* 46 : Allocate */
15270 jvmtiTrace_Allocate,
15271 /* 47 : Deallocate */
15272 jvmtiTrace_Deallocate,
15273 /* 48 : Get Class Signature */
15274 jvmtiTrace_GetClassSignature,
15275 /* 49 : Get Class Status */
15276 jvmtiTrace_GetClassStatus,
15277 /* 50 : Get Source File Name */
15278 jvmtiTrace_GetSourceFileName,
15279 /* 51 : Get Class Modifiers */
15280 jvmtiTrace_GetClassModifiers,
15281 /* 52 : Get Class Methods */
15282 jvmtiTrace_GetClassMethods,
15283 /* 53 : Get Class Fields */
15284 jvmtiTrace_GetClassFields,
15285 /* 54 : Get Implemented Interfaces */
15286 jvmtiTrace_GetImplementedInterfaces,
15287 /* 55 : Is Interface */
15288 jvmtiTrace_IsInterface,
15289 /* 56 : Is Array Class */
15290 jvmtiTrace_IsArrayClass,
15291 /* 57 : Get Class Loader */
15292 jvmtiTrace_GetClassLoader,
15293 /* 58 : Get Object Hash Code */
15294 jvmtiTrace_GetObjectHashCode,
15295 /* 59 : Get Object Monitor Usage */
15296 jvmtiTrace_GetObjectMonitorUsage,
15297 /* 60 : Get Field Name (and Signature) */
15298 jvmtiTrace_GetFieldName,
15299 /* 61 : Get Field Declaring Class */
15300 jvmtiTrace_GetFieldDeclaringClass,
15301 /* 62 : Get Field Modifiers */
15302 jvmtiTrace_GetFieldModifiers,
15303 /* 63 : Is Field Synthetic */
15304 jvmtiTrace_IsFieldSynthetic,
15305 /* 64 : Get Method Name (and Signature) */
15306 jvmtiTrace_GetMethodName,
15307 /* 65 : Get Method Declaring Class */
15308 jvmtiTrace_GetMethodDeclaringClass,
15309 /* 66 : Get Method Modifiers */
15310 jvmtiTrace_GetMethodModifiers,
15311 /* 67 : RESERVED */
15312 NULL,
15313 /* 68 : Get Max Locals */
15314 jvmtiTrace_GetMaxLocals,
15315 /* 69 : Get Arguments Size */
15316 jvmtiTrace_GetArgumentsSize,
15317 /* 70 : Get Line Number Table */
15318 jvmtiTrace_GetLineNumberTable,
15319 /* 71 : Get Method Location */
15320 jvmtiTrace_GetMethodLocation,
15321 /* 72 : Get Local Variable Table */
15322 jvmtiTrace_GetLocalVariableTable,
15323 /* 73 : Set Native Method Prefix */
15324 jvmtiTrace_SetNativeMethodPrefix,
15325 /* 74 : Set Native Method Prefixes */
15326 jvmtiTrace_SetNativeMethodPrefixes,
15327 /* 75 : Get Bytecodes */
15328 jvmtiTrace_GetBytecodes,
15329 /* 76 : Is Method Native */
15330 jvmtiTrace_IsMethodNative,
15331 /* 77 : Is Method Synthetic */
15332 jvmtiTrace_IsMethodSynthetic,
15333 /* 78 : Get Loaded Classes */
15334 jvmtiTrace_GetLoadedClasses,
15335 /* 79 : Get Classloader Classes */
15336 jvmtiTrace_GetClassLoaderClasses,
15337 /* 80 : Pop Frame */
15338 jvmtiTrace_PopFrame,
15339 /* 81 : Force Early Return - Object */
15340 jvmtiTrace_ForceEarlyReturnObject,
15341 /* 82 : Force Early Return - Int */
15342 jvmtiTrace_ForceEarlyReturnInt,
15343 /* 83 : Force Early Return - Long */
15344 jvmtiTrace_ForceEarlyReturnLong,
15345 /* 84 : Force Early Return - Float */
15346 jvmtiTrace_ForceEarlyReturnFloat,
15347 /* 85 : Force Early Return - Double */
15348 jvmtiTrace_ForceEarlyReturnDouble,
15349 /* 86 : Force Early Return - Void */
15350 jvmtiTrace_ForceEarlyReturnVoid,
15351 /* 87 : Redefine Classes */
15352 jvmtiTrace_RedefineClasses,
15353 /* 88 : Get Version Number */
15354 jvmtiTrace_GetVersionNumber,
15355 /* 89 : Get Capabilities */
15356 jvmtiTrace_GetCapabilities,
15357 /* 90 : Get Source Debug Extension */
15358 jvmtiTrace_GetSourceDebugExtension,
15359 /* 91 : Is Method Obsolete */
15360 jvmtiTrace_IsMethodObsolete,
15361 /* 92 : Suspend Thread List */
15362 jvmtiTrace_SuspendThreadList,
15363 /* 93 : Resume Thread List */
15364 jvmtiTrace_ResumeThreadList,
15365 /* 94 : Add Module Reads */
15366 jvmtiTrace_AddModuleReads,
15367 /* 95 : Add Module Exports */
15368 jvmtiTrace_AddModuleExports,
15369 /* 96 : Add Module Opens */
15370 jvmtiTrace_AddModuleOpens,
15371 /* 97 : Add Module Uses */
15372 jvmtiTrace_AddModuleUses,
15373 /* 98 : Add Module Provides */
15374 jvmtiTrace_AddModuleProvides,
15375 /* 99 : Is Modifiable Module */
15376 jvmtiTrace_IsModifiableModule,
15377 /* 100 : Get All Stack Traces */
15378 jvmtiTrace_GetAllStackTraces,
15379 /* 101 : Get Thread List Stack Traces */
15380 jvmtiTrace_GetThreadListStackTraces,
15381 /* 102 : Get Thread Local Storage */
15382 jvmtiTrace_GetThreadLocalStorage,
15383 /* 103 : Set Thread Local Storage */
15384 jvmtiTrace_SetThreadLocalStorage,
15385 /* 104 : Get Stack Trace */
15386 jvmtiTrace_GetStackTrace,
15387 /* 105 : RESERVED */
15388 NULL,
15389 /* 106 : Get Tag */
15390 jvmtiTrace_GetTag,
15391 /* 107 : Set Tag */
15392 jvmtiTrace_SetTag,
15393 /* 108 : Force Garbage Collection */
15394 jvmtiTrace_ForceGarbageCollection,
15395 /* 109 : Iterate Over Objects Reachable From Object */
15396 jvmtiTrace_IterateOverObjectsReachableFromObject,
15397 /* 110 : Iterate Over Reachable Objects */
15398 jvmtiTrace_IterateOverReachableObjects,
15399 /* 111 : Iterate Over Heap */
15400 jvmtiTrace_IterateOverHeap,
15401 /* 112 : Iterate Over Instances Of Class */
15402 jvmtiTrace_IterateOverInstancesOfClass,
15403 /* 113 : RESERVED */
15404 NULL,
15405 /* 114 : Get Objects With Tags */
15406 jvmtiTrace_GetObjectsWithTags,
15407 /* 115 : Follow References */
15408 jvmtiTrace_FollowReferences,
15409 /* 116 : Iterate Through Heap */
15410 jvmtiTrace_IterateThroughHeap,
15411 /* 117 : RESERVED */
15412 NULL,
15413 /* 118 : RESERVED */
15414 NULL,
15415 /* 119 : RESERVED */
15416 NULL,
15417 /* 120 : Set JNI Function Table */
15418 jvmtiTrace_SetJNIFunctionTable,
15419 /* 121 : Get JNI Function Table */
15420 jvmtiTrace_GetJNIFunctionTable,
15421 /* 122 : Set Event Callbacks */
15422 jvmtiTrace_SetEventCallbacks,
15423 /* 123 : Generate Events */
15424 jvmtiTrace_GenerateEvents,
15425 /* 124 : Get Extension Functions */
15426 jvmtiTrace_GetExtensionFunctions,
15427 /* 125 : Get Extension Events */
15428 jvmtiTrace_GetExtensionEvents,
15429 /* 126 : Set Extension Event Callback */
15430 jvmtiTrace_SetExtensionEventCallback,
15431 /* 127 : Dispose Environment */
15432 jvmtiTrace_DisposeEnvironment,
15433 /* 128 : Get Error Name */
15434 jvmtiTrace_GetErrorName,
15435 /* 129 : Get JLocation Format */
15436 jvmtiTrace_GetJLocationFormat,
15437 /* 130 : Get System Properties */
15438 jvmtiTrace_GetSystemProperties,
15439 /* 131 : Get System Property */
15440 jvmtiTrace_GetSystemProperty,
15441 /* 132 : Set System Property */
15442 jvmtiTrace_SetSystemProperty,
15443 /* 133 : Get Phase */
15444 jvmtiTrace_GetPhase,
15445 /* 134 : Get Current Thread CPU Timer Information */
15446 jvmtiTrace_GetCurrentThreadCpuTimerInfo,
15447 /* 135 : Get Current Thread CPU Time */
15448 jvmtiTrace_GetCurrentThreadCpuTime,
15449 /* 136 : Get Thread CPU Timer Information */
15450 jvmtiTrace_GetThreadCpuTimerInfo,
15451 /* 137 : Get Thread CPU Time */
15452 jvmtiTrace_GetThreadCpuTime,
15453 /* 138 : Get Timer Information */
15454 jvmtiTrace_GetTimerInfo,
15455 /* 139 : Get Time */
15456 jvmtiTrace_GetTime,
15457 /* 140 : Get Potential Capabilities */
15458 jvmtiTrace_GetPotentialCapabilities,
15459 /* 141 : RESERVED */
15460 NULL,
15461 /* 142 : Add Capabilities */
15462 jvmtiTrace_AddCapabilities,
15463 /* 143 : Relinquish Capabilities */
15464 jvmtiTrace_RelinquishCapabilities,
15465 /* 144 : Get Available Processors */
15466 jvmtiTrace_GetAvailableProcessors,
15467 /* 145 : Get Class Version Numbers */
15468 jvmtiTrace_GetClassVersionNumbers,
15469 /* 146 : Get Constant Pool */
15470 jvmtiTrace_GetConstantPool,
15471 /* 147 : Get Environment Local Storage */
15472 jvmtiTrace_GetEnvironmentLocalStorage,
15473 /* 148 : Set Environment Local Storage */
15474 jvmtiTrace_SetEnvironmentLocalStorage,
15475 /* 149 : Add To Bootstrap Class Loader Search */
15476 jvmtiTrace_AddToBootstrapClassLoaderSearch,
15477 /* 150 : Set Verbose Flag */
15478 jvmtiTrace_SetVerboseFlag,
15479 /* 151 : Add To System Class Loader Search */
15480 jvmtiTrace_AddToSystemClassLoaderSearch,
15481 /* 152 : Retransform Classes */
15482 jvmtiTrace_RetransformClasses,
15483 /* 153 : Get Owned Monitor Stack Depth Info */
15484 jvmtiTrace_GetOwnedMonitorStackDepthInfo,
15485 /* 154 : Get Object Size */
15486 jvmtiTrace_GetObjectSize,
15487 /* 155 : Get Local Instance */
15488 jvmtiTrace_GetLocalInstance,
15489 /* 156 : Set Heap Sampling Interval */
15490 jvmtiTrace_SetHeapSamplingInterval
15491};
15492#endif // INCLUDE_JVMTI
15493
15494#endif /*JVMTI_TRACE */
15495