1 // jvmti.cc - JVMTI implementation
3 /* Copyright (C) 2006, 2007 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
15 #include <java-threads.h>
17 #include <java-interp.h>
19 #include "jvmti-int.h"
21 #include <gcj/method.h>
23 #include <gnu/classpath/SystemProperties.h>
24 #include <gnu/gcj/runtime/BootClassLoader.h>
25 #include <gnu/gcj/jvmti/Breakpoint.h>
26 #include <gnu/gcj/jvmti/BreakpointManager.h>
28 #include <java/lang/Class.h>
29 #include <java/lang/ClassLoader.h>
30 #include <java/lang/Object.h>
31 #include <java/lang/OutOfMemoryError.h>
32 #include <java/lang/Thread.h>
33 #include <java/lang/ThreadGroup.h>
34 #include <java/lang/Throwable.h>
35 #include <java/lang/VMClassLoader.h>
36 #include <java/lang/reflect/Field.h>
37 #include <java/lang/reflect/Modifier.h>
38 #include <java/util/Collection.h>
39 #include <java/util/HashMap.h>
40 #include <java/net/URL.h>
42 static void check_enabled_events (void);
43 static void check_enabled_event (jvmtiEvent
);
49 bool ThreadStart
= false;
50 bool ThreadEnd
= false;
51 bool ClassFileLoadHook
= false;
52 bool ClassLoad
= false;
53 bool ClassPrepare
= false;
55 bool Exception
= false;
56 bool ExceptionCatch
= false;
57 bool SingleStep
= false;
58 bool FramePop
= false;
59 bool Breakpoint
= false;
60 bool FieldAccess
= false;
61 bool FieldModification
= false;
62 bool MethodEntry
= false;
63 bool MethodExit
= false;
64 bool NativeMethodBind
= false;
65 bool CompiledMethodLoad
= false;
66 bool CompiledMethodUnload
= false;
67 bool DynamicCodeGenerated
= false;
68 bool DataDumpRequest
= false;
69 bool reserved72
= false;
70 bool MonitorWait
= false;
71 bool MonitorWaited
= false;
72 bool MonitorContendedEnter
= false;
73 bool MonitorContendedEntered
= false;
74 bool reserved77
= false;
75 bool reserved78
= false;
76 bool reserved79
= false;
77 bool reserved80
= false;
78 bool GarbageCollectionStart
= false;
79 bool GarbageCollectionFinish
= false;
80 bool ObjectFree
= false;
81 bool VMObjectAlloc
= false;
84 extern struct JNINativeInterface _Jv_JNIFunctions
;
86 struct _Jv_rawMonitorID
89 _Jv_ConditionVariable_t condition
;
92 /* A simple linked list of all JVMTI environments. Since
93 events must be delivered to environments in the order
94 in which the environments were created, new environments
95 are added to the end of the list. */
99 struct jvmti_env_list
*next
;
101 static struct jvmti_env_list
*_jvmtiEnvironments
= NULL
;
102 static java::lang::Object
*_envListLock
= NULL
;
103 #define FOREACH_ENVIRONMENT(Ele) \
104 for (Ele = _jvmtiEnvironments; Ele != NULL; Ele = Ele->next)
106 // Some commonly-used checks
108 #define THREAD_DEFAULT_TO_CURRENT(Ajthread) \
111 if (Ajthread == NULL) \
112 Ajthread = java::lang::Thread::currentThread (); \
116 #define THREAD_CHECK_VALID(Athread) \
119 if (!java::lang::Thread::class$.isAssignableFrom (&(Athread->class$))) \
120 return JVMTI_ERROR_INVALID_THREAD; \
124 #define THREAD_CHECK_IS_ALIVE(Athread) \
127 if (!Athread->isAlive ()) \
128 return JVMTI_ERROR_THREAD_NOT_ALIVE; \
132 // FIXME: if current phase is not set in Phases,
133 // return JVMTI_ERROR_WRONG_PHASE
134 #define REQUIRE_PHASE(Env, Phases)
136 #define NULL_CHECK(Ptr) \
140 return JVMTI_ERROR_NULL_POINTER; \
144 #define ILLEGAL_ARGUMENT(Cond) \
148 return JVMTI_ERROR_ILLEGAL_ARGUMENT; \
152 static jvmtiError JNICALL
153 _Jv_JVMTI_SuspendThread (MAYBE_UNUSED jvmtiEnv
*env
, jthread thread
)
155 using namespace java::lang
;
157 THREAD_DEFAULT_TO_CURRENT (thread
);
158 THREAD_CHECK_VALID (thread
);
159 THREAD_CHECK_IS_ALIVE (thread
);
161 _Jv_Thread_t
*data
= _Jv_ThreadGetData (thread
);
162 _Jv_SuspendThread (data
);
163 return JVMTI_ERROR_NONE
;
166 static jvmtiError JNICALL
167 _Jv_JVMTI_ResumeThread (MAYBE_UNUSED jvmtiEnv
*env
, jthread thread
)
169 using namespace java::lang
;
171 THREAD_DEFAULT_TO_CURRENT (thread
);
172 THREAD_CHECK_VALID (thread
);
173 THREAD_CHECK_IS_ALIVE (thread
);
175 _Jv_Thread_t
*data
= _Jv_ThreadGetData (thread
);
176 _Jv_ResumeThread (data
);
177 return JVMTI_ERROR_NONE
;
180 static jvmtiError JNICALL
181 _Jv_JVMTI_InterruptThread (MAYBE_UNUSED jvmtiEnv
*env
, jthread thread
)
183 using namespace java::lang
;
185 REQUIRE_PHASE (env
, JVMTI_PHASE_LIVE
);
186 // FIXME: capability handling? 'can_signal_thread'
188 return JVMTI_ERROR_INVALID_THREAD
;
190 THREAD_CHECK_VALID (thread
);
191 THREAD_CHECK_IS_ALIVE (thread
);
193 return JVMTI_ERROR_NONE
;
196 static jvmtiError JNICALL
197 _Jv_JVMTI_GetAllThreads(MAYBE_UNUSED jvmtiEnv
*env
, jint
*thread_cnt
,
200 REQUIRE_PHASE (env
, JVMTI_PHASE_LIVE
);
201 NULL_CHECK (thread_cnt
);
202 NULL_CHECK (threads
);
204 using namespace java::lang
;
206 ThreadGroup
*root_grp
= ThreadGroup::root
;
207 jint estimate
= root_grp
->activeCount ();
209 JArray
<Thread
*> *thr_arr
;
211 // Allocate some extra space since threads can be created between calls
214 thr_arr
= reinterpret_cast<JArray
<Thread
*> *> (JvNewObjectArray
216 &Thread::class$
, NULL
));
218 catch (java::lang::OutOfMemoryError
*err
)
220 return JVMTI_ERROR_OUT_OF_MEMORY
;
223 *thread_cnt
= root_grp
->enumerate (thr_arr
);
225 jvmtiError jerr
= env
->Allocate ((jlong
) ((*thread_cnt
) * sizeof (jthread
)),
226 (unsigned char **) threads
);
228 if (jerr
!= JVMTI_ERROR_NONE
)
231 // Transfer the threads to the result array
232 jthread
*tmp_arr
= reinterpret_cast<jthread
*> (elements (thr_arr
));
234 memcpy ((*threads
), tmp_arr
, (*thread_cnt
));
236 return JVMTI_ERROR_NONE
;
239 static jvmtiError JNICALL
240 _Jv_JVMTI_GetFrameCount (MAYBE_UNUSED jvmtiEnv
*env
, jthread thread
,
243 REQUIRE_PHASE (env
, JVMTI_PHASE_LIVE
);
245 NULL_CHECK (frame_count
);
247 using namespace java::lang
;
249 THREAD_DEFAULT_TO_CURRENT (thread
);
251 Thread
*thr
= reinterpret_cast<Thread
*> (thread
);
252 THREAD_CHECK_VALID (thr
);
253 THREAD_CHECK_IS_ALIVE (thr
);
255 _Jv_Frame
*frame
= reinterpret_cast<_Jv_Frame
*> (thr
->frame
);
258 while (frame
!= NULL
)
264 return JVMTI_ERROR_NONE
;
267 static jvmtiError JNICALL
268 _Jv_JVMTI_CreateRawMonitor (MAYBE_UNUSED jvmtiEnv
*env
, const char *name
,
269 jrawMonitorID
*result
)
271 REQUIRE_PHASE (env
, JVMTI_PHASE_ONLOAD
| JVMTI_PHASE_LIVE
);
274 *result
= (jrawMonitorID
) _Jv_MallocUnchecked (sizeof (_Jv_rawMonitorID
));
276 return JVMTI_ERROR_OUT_OF_MEMORY
;
277 _Jv_MutexInit (&(*result
)->mutex
);
278 _Jv_CondInit (&(*result
)->condition
);
279 return JVMTI_ERROR_NONE
;
282 static jvmtiError JNICALL
283 _Jv_JVMTI_DestroyRawMonitor (MAYBE_UNUSED jvmtiEnv
*env
, jrawMonitorID monitor
)
285 REQUIRE_PHASE (env
, JVMTI_PHASE_ONLOAD
| JVMTI_PHASE_LIVE
);
286 // Note we have no better way of knowing whether this object is
287 // really a raw monitor.
289 return JVMTI_ERROR_INVALID_MONITOR
;
290 // FIXME: perform checks on monitor, release it if this thread owns
292 #ifdef _Jv_HaveMutexDestroy
293 _Jv_MutexDestroy (&monitor
->mutex
);
296 return JVMTI_ERROR_NONE
;
299 static jvmtiError JNICALL
300 _Jv_JVMTI_RawMonitorEnter (MAYBE_UNUSED jvmtiEnv
*env
, jrawMonitorID monitor
)
303 return JVMTI_ERROR_INVALID_MONITOR
;
304 _Jv_MutexLock (&monitor
->mutex
);
305 return JVMTI_ERROR_NONE
;
308 static jvmtiError JNICALL
309 _Jv_JVMTI_RawMonitorExit (MAYBE_UNUSED jvmtiEnv
*env
, jrawMonitorID monitor
)
312 return JVMTI_ERROR_INVALID_MONITOR
;
313 if (_Jv_MutexUnlock (&monitor
->mutex
))
314 return JVMTI_ERROR_NOT_MONITOR_OWNER
;
315 return JVMTI_ERROR_NONE
;
318 static jvmtiError JNICALL
319 _Jv_JVMTI_RawMonitorWait (MAYBE_UNUSED jvmtiEnv
*env
, jrawMonitorID monitor
,
323 return JVMTI_ERROR_INVALID_MONITOR
;
324 int r
= _Jv_CondWait (&monitor
->condition
, &monitor
->mutex
, millis
, 0);
325 if (r
== _JV_NOT_OWNER
)
326 return JVMTI_ERROR_NOT_MONITOR_OWNER
;
327 if (r
== _JV_INTERRUPTED
)
328 return JVMTI_ERROR_INTERRUPT
;
329 return JVMTI_ERROR_NONE
;
332 static jvmtiError JNICALL
333 _Jv_JVMTI_RawMonitorNotify (MAYBE_UNUSED jvmtiEnv
*env
, jrawMonitorID monitor
)
336 return JVMTI_ERROR_INVALID_MONITOR
;
337 if (_Jv_CondNotify (&monitor
->condition
, &monitor
->mutex
) == _JV_NOT_OWNER
)
338 return JVMTI_ERROR_NOT_MONITOR_OWNER
;
339 return JVMTI_ERROR_NONE
;
342 static jvmtiError JNICALL
343 _Jv_JVMTI_RawMonitorNotifyAll (MAYBE_UNUSED jvmtiEnv
*env
,
344 jrawMonitorID monitor
)
347 return JVMTI_ERROR_INVALID_MONITOR
;
348 if (_Jv_CondNotifyAll (&monitor
->condition
, &monitor
->mutex
)
350 return JVMTI_ERROR_NOT_MONITOR_OWNER
;
351 return JVMTI_ERROR_NONE
;
354 static jvmtiError JNICALL
355 _Jv_JVMTI_SetBreakpoint (jvmtiEnv
*env
, jmethodID method
, jlocation location
)
357 REQUIRE_PHASE (env
, JVMTI_PHASE_LIVE
);
359 using namespace gnu::gcj::jvmti
;
361 = BreakpointManager::getBreakpoint (reinterpret_cast<jlong
> (method
),
366 jvmtiError err
= env
->GetMethodDeclaringClass (method
, &klass
);
367 if (err
!= JVMTI_ERROR_NONE
)
370 if (!_Jv_IsInterpretedClass (klass
))
371 return JVMTI_ERROR_INVALID_CLASS
;
373 _Jv_MethodBase
*base
= _Jv_FindInterpreterMethod (klass
, method
);
375 return JVMTI_ERROR_INVALID_METHODID
;
378 err
= env
->GetMethodModifiers (method
, &flags
);
379 if (err
!= JVMTI_ERROR_NONE
)
382 if (flags
& java::lang::reflect::Modifier::NATIVE
)
383 return JVMTI_ERROR_NATIVE_METHOD
;
385 _Jv_InterpMethod
*imeth
= reinterpret_cast<_Jv_InterpMethod
*> (base
);
386 if (imeth
->get_insn (location
) == NULL
)
387 return JVMTI_ERROR_INVALID_LOCATION
;
389 // Now the breakpoint can be safely installed
390 bp
= BreakpointManager::newBreakpoint (reinterpret_cast<jlong
> (method
),
395 // Duplicate breakpoints are not permitted by JVMTI
396 return JVMTI_ERROR_DUPLICATE
;
399 return JVMTI_ERROR_NONE
;
402 static jvmtiError JNICALL
403 _Jv_JVMTI_ClearBreakpoint (MAYBE_UNUSED jvmtiEnv
*env
, jmethodID method
,
406 REQUIRE_PHASE (env
, JVMTI_PHASE_LIVE
);
408 using namespace gnu::gcj::jvmti
;
411 = BreakpointManager::getBreakpoint (reinterpret_cast<jlong
> (method
),
414 return JVMTI_ERROR_NOT_FOUND
;
416 BreakpointManager::deleteBreakpoint (reinterpret_cast<jlong
> (method
), location
);
417 return JVMTI_ERROR_NONE
;
420 static jvmtiError JNICALL
421 _Jv_JVMTI_Allocate (MAYBE_UNUSED jvmtiEnv
*env
, jlong size
,
422 unsigned char **result
)
424 ILLEGAL_ARGUMENT (size
< 0);
430 *result
= (unsigned char *) _Jv_MallocUnchecked (size
);
432 return JVMTI_ERROR_OUT_OF_MEMORY
;
434 return JVMTI_ERROR_NONE
;
437 static jvmtiError JNICALL
438 _Jv_JVMTI_Deallocate (MAYBE_UNUSED jvmtiEnv
*env
, unsigned char *mem
)
442 return JVMTI_ERROR_NONE
;
445 static jvmtiError JNICALL
446 _Jv_JVMTI_GetClassStatus (MAYBE_UNUSED jvmtiEnv
*env
, jclass klass
,
449 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
450 NULL_CHECK (status_ptr
);
452 return JVMTI_ERROR_INVALID_CLASS
;
454 if (klass
->isArray ())
455 *status_ptr
= JVMTI_CLASS_STATUS_ARRAY
;
456 else if (klass
->isPrimitive ())
457 *status_ptr
= JVMTI_CLASS_STATUS_PRIMITIVE
;
460 jbyte state
= _Jv_GetClassState (klass
);
462 if (state
>= JV_STATE_LINKED
)
463 (*status_ptr
) |= JVMTI_CLASS_STATUS_VERIFIED
;
464 if (state
>= JV_STATE_PREPARED
)
465 (*status_ptr
) |= JVMTI_CLASS_STATUS_PREPARED
;
466 if (state
== JV_STATE_ERROR
|| state
== JV_STATE_PHANTOM
)
467 (*status_ptr
) |= JVMTI_CLASS_STATUS_ERROR
;
468 else if (state
== JV_STATE_DONE
)
469 (*status_ptr
) |= JVMTI_CLASS_STATUS_INITIALIZED
;
472 return JVMTI_ERROR_NONE
;
475 static jvmtiError JNICALL
476 _Jv_JVMTI_GetClassModifiers (MAYBE_UNUSED jvmtiEnv
*env
, jclass klass
,
479 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
480 // Don't bother checking KLASS' type.
482 return JVMTI_ERROR_INVALID_CLASS
;
484 *mods
= klass
->getModifiers();
485 return JVMTI_ERROR_NONE
;
488 static jvmtiError JNICALL
489 _Jv_JVMTI_GetClassMethods (MAYBE_UNUSED jvmtiEnv
*env
, jclass klass
,
490 jint
*count_ptr
, jmethodID
**methods_ptr
)
492 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
493 // FIXME: capability can_maintain_original_method_order
494 // Don't bother checking KLASS' type.
496 return JVMTI_ERROR_INVALID_CLASS
;
497 NULL_CHECK (count_ptr
);
498 NULL_CHECK (methods_ptr
);
499 *count_ptr
= JvNumMethods(klass
);
502 = (jmethodID
*) _Jv_MallocUnchecked (*count_ptr
* sizeof (jmethodID
));
503 if (*methods_ptr
== NULL
)
504 return JVMTI_ERROR_OUT_OF_MEMORY
;
506 jmethodID start
= JvGetFirstMethod (klass
);
507 for (jint i
= 0; i
< *count_ptr
; ++i
)
509 (*methods_ptr
)[i
] = start
+ i
;
511 return JVMTI_ERROR_NONE
;
514 static jvmtiError JNICALL
515 _Jv_JVMTI_IsInterface (MAYBE_UNUSED jvmtiEnv
*env
, jclass klass
,
518 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
520 return JVMTI_ERROR_INVALID_CLASS
;
522 *result
= klass
->isInterface();
523 return JVMTI_ERROR_NONE
;
526 static jvmtiError JNICALL
527 _Jv_JVMTI_IsArrayClass (MAYBE_UNUSED jvmtiEnv
*env
, jclass klass
,
530 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
532 return JVMTI_ERROR_INVALID_CLASS
;
534 *result
= klass
->isArray();
535 return JVMTI_ERROR_NONE
;
538 static jvmtiError JNICALL
539 _Jv_JVMTI_GetClassLoader (MAYBE_UNUSED jvmtiEnv
*env
, jclass klass
,
542 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
544 return JVMTI_ERROR_INVALID_CLASS
;
546 *result
= klass
->getClassLoaderInternal();
547 return JVMTI_ERROR_NONE
;
550 static jvmtiError JNICALL
551 _Jv_JVMTI_GetObjectHashCode (MAYBE_UNUSED jvmtiEnv
*env
, jobject obj
,
554 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
556 return JVMTI_ERROR_INVALID_OBJECT
;
558 *result
= _Jv_HashCode (obj
);
559 return JVMTI_ERROR_NONE
;
562 static jvmtiError JNICALL
563 _Jv_JVMTI_GetFieldModifiers (MAYBE_UNUSED jvmtiEnv
*env
, jclass klass
,
564 jfieldID field
, jint
*result
)
566 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
568 return JVMTI_ERROR_INVALID_CLASS
;
570 return JVMTI_ERROR_INVALID_FIELDID
;
572 *result
= field
->getModifiers();
573 return JVMTI_ERROR_NONE
;
576 static jvmtiError JNICALL
577 _Jv_JVMTI_IsFieldSynthetic (MAYBE_UNUSED jvmtiEnv
*env
, jclass klass
,
578 jfieldID field
, jboolean
*result
)
580 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
582 return JVMTI_ERROR_INVALID_CLASS
;
584 return JVMTI_ERROR_INVALID_FIELDID
;
587 // FIXME: capability can_get_synthetic_attribute
588 *result
= ((field
->getModifiers() & java::lang::reflect::Modifier::SYNTHETIC
)
590 return JVMTI_ERROR_NONE
;
593 static jvmtiError JNICALL
594 _Jv_JVMTI_GetMethodName (MAYBE_UNUSED jvmtiEnv
*env
, jmethodID method
,
595 char **name_ptr
, char **signature_ptr
,
598 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
601 return JVMTI_ERROR_INVALID_METHODID
;
603 if (name_ptr
!= NULL
)
605 int len
= static_cast<int> (method
->name
->len ());
606 *name_ptr
= (char *) _Jv_MallocUnchecked (len
+ 1);
607 if (*name_ptr
== NULL
)
608 return JVMTI_ERROR_OUT_OF_MEMORY
;
609 strncpy (*name_ptr
, method
->name
->chars (), len
);
610 (*name_ptr
)[len
] = '\0';
613 if (signature_ptr
!= NULL
)
615 int len
= static_cast<int> (method
->signature
->len ());
616 *signature_ptr
= (char *) _Jv_MallocUnchecked (len
+ 1);
617 if (*signature_ptr
== NULL
)
619 if (name_ptr
!= NULL
)
620 _Jv_Free (*name_ptr
);
621 return JVMTI_ERROR_OUT_OF_MEMORY
;
623 strncpy (*signature_ptr
, method
->signature
->chars (), len
);
624 (*signature_ptr
)[len
] = '\0';
627 if (generic_ptr
!= NULL
)
632 return JVMTI_ERROR_NONE
;
635 static jvmtiError JNICALL
636 _Jv_JVMTI_GetMethodModifiers (MAYBE_UNUSED jvmtiEnv
*env
, jmethodID method
,
639 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
641 return JVMTI_ERROR_INVALID_METHODID
;
644 // FIXME: mask off some internal bits...
645 *result
= method
->accflags
;
646 return JVMTI_ERROR_NONE
;
649 static jvmtiError JNICALL
650 _Jv_JVMTI_GetLineNumberTable (jvmtiEnv
*env
, jmethodID method
,
651 jint
*entry_count_ptr
,
652 jvmtiLineNumberEntry
**table_ptr
)
654 NULL_CHECK (entry_count_ptr
);
655 NULL_CHECK (table_ptr
);
658 jvmtiError jerr
= env
->GetMethodDeclaringClass (method
, &klass
);
659 if (jerr
!= JVMTI_ERROR_NONE
)
662 _Jv_MethodBase
*base
= _Jv_FindInterpreterMethod (klass
, method
);
664 return JVMTI_ERROR_INVALID_METHODID
;
666 if (java::lang::reflect::Modifier::isNative (method
->accflags
)
667 || !_Jv_IsInterpretedClass (klass
))
668 return JVMTI_ERROR_NATIVE_METHOD
;
670 _Jv_InterpMethod
*imeth
= reinterpret_cast<_Jv_InterpMethod
*> (base
);
672 jintArray lines
= NULL
;
673 jlongArray indices
= NULL
;
674 imeth
->get_line_table (start
, end
, lines
, indices
);
676 return JVMTI_ERROR_ABSENT_INFORMATION
;
678 jvmtiLineNumberEntry
*table
;
679 jsize len
= lines
->length
* sizeof (jvmtiLineNumberEntry
);
680 table
= (jvmtiLineNumberEntry
*) _Jv_MallocUnchecked (len
);
682 return JVMTI_ERROR_OUT_OF_MEMORY
;
684 jint
*line
= elements (lines
);
685 jlong
*index
= elements (indices
);
686 for (int i
= 0; i
< lines
->length
; ++i
)
688 table
[i
].start_location
= index
[i
];
689 table
[i
].line_number
= line
[i
];
693 *entry_count_ptr
= lines
->length
;
694 return JVMTI_ERROR_NONE
;
697 static jvmtiError JNICALL
698 _Jv_JVMTI_IsMethodNative (MAYBE_UNUSED jvmtiEnv
*env
, jmethodID method
,
701 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
703 return JVMTI_ERROR_INVALID_METHODID
;
706 *result
= ((method
->accflags
& java::lang::reflect::Modifier::NATIVE
) != 0);
707 return JVMTI_ERROR_NONE
;
710 static jvmtiError JNICALL
711 _Jv_JVMTI_IsMethodSynthetic (MAYBE_UNUSED jvmtiEnv
*env
, jmethodID method
,
714 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
716 return JVMTI_ERROR_INVALID_METHODID
;
719 // FIXME capability can_get_synthetic_attribute
721 *result
= ((method
->accflags
& java::lang::reflect::Modifier::SYNTHETIC
)
723 return JVMTI_ERROR_NONE
;
726 static jvmtiError JNICALL
727 _Jv_JVMTI_GetMethodDeclaringClass (MAYBE_UNUSED jvmtiEnv
*env
,
729 jclass
*declaring_class_ptr
)
731 REQUIRE_PHASE (env
, JVMTI_PHASE_LIVE
);
732 NULL_CHECK (declaring_class_ptr
);
734 jclass klass
= _Jv_GetMethodDeclaringClass (method
);
737 *declaring_class_ptr
= klass
;
738 return JVMTI_ERROR_NONE
;
741 return JVMTI_ERROR_INVALID_METHODID
;
744 static jvmtiError JNICALL
745 _Jv_JVMTI_GetClassLoaderClasses (MAYBE_UNUSED jvmtiEnv
*env
,
750 using namespace java::lang
;
751 using namespace java::util
;
753 REQUIRE_PHASE (env
, JVMTI_PHASE_LIVE
);
754 NULL_CHECK (count_ptr
);
755 NULL_CHECK (result_ptr
);
757 ClassLoader
*loader
= (ClassLoader
*) init_loader
;
759 loader
= VMClassLoader::bootLoader
;
761 Collection
*values
= loader
->loadedClasses
->values();
762 jobjectArray array
= values
->toArray();
763 *count_ptr
= array
->length
;
764 jobject
*elts
= elements (array
);
766 = (jclass
*) _Jv_MallocUnchecked (*count_ptr
* sizeof (jclass
));
768 return JVMTI_ERROR_OUT_OF_MEMORY
;
770 // FIXME: JNI references...
771 memcpy (result
, elts
, *count_ptr
* sizeof (jclass
));
773 *result_ptr
= result
;
775 return JVMTI_ERROR_NONE
;
778 static jvmtiError JNICALL
779 _Jv_JVMTI_GetStackTrace (MAYBE_UNUSED jvmtiEnv
*env
, jthread thread
,
780 jint start_depth
, jint max_frames
,
781 jvmtiFrameInfo
*frames
, jint
*frame_count
)
783 REQUIRE_PHASE (env
, JVMTI_PHASE_LIVE
);
785 ILLEGAL_ARGUMENT (max_frames
< 0);
788 NULL_CHECK (frame_count
);
790 using namespace java::lang
;
792 THREAD_DEFAULT_TO_CURRENT (thread
);
794 Thread
*thr
= reinterpret_cast<Thread
*> (thread
);
795 THREAD_CHECK_VALID (thr
);
796 THREAD_CHECK_IS_ALIVE (thr
);
798 jvmtiError jerr
= env
->GetFrameCount (thread
, frame_count
);
799 if (jerr
!= JVMTI_ERROR_NONE
)
802 // start_depth can be either a positive number, indicating the depth of the
803 // stack at which to begin the trace, or a negative number indicating the
804 // number of frames at the bottom of the stack to exclude. These checks
805 // ensure that it is a valid value in either case
807 ILLEGAL_ARGUMENT (start_depth
>= (*frame_count
));
808 ILLEGAL_ARGUMENT (start_depth
< (-(*frame_count
)));
810 _Jv_Frame
*frame
= reinterpret_cast<_Jv_Frame
*> (thr
->frame
);
812 // If start_depth is negative use this to determine at what depth to start
813 // the trace by adding it to the length of the call stack. This allows the
814 // use of the same frame "discarding" mechanism as for a positive start_depth
816 start_depth
= *frame_count
+ start_depth
;
818 // If start_depth > 0 "remove" start_depth frames from the beginning
819 // of the stack before beginning the trace by moving along the frame list.
820 while (start_depth
> 0)
827 // Now check to see if the array supplied by the agent is large enough to
828 // hold frame_count frames, after adjustment for start_depth.
829 if ((*frame_count
) > max_frames
)
830 (*frame_count
) = max_frames
;
832 for (int i
= 0; i
< (*frame_count
); i
++)
834 frames
[i
].method
= frame
->self
->get_method ();
836 // Set the location in the frame, native frames have location = -1
837 if (frame
->frame_type
== frame_interpreter
)
839 _Jv_InterpMethod
*imeth
840 = static_cast<_Jv_InterpMethod
*> (frame
->self
);
841 _Jv_InterpFrame
*interp_frame
842 = static_cast<_Jv_InterpFrame
*> (frame
);
843 frames
[i
].location
= imeth
->insn_index (interp_frame
->pc
);
846 frames
[i
].location
= -1;
851 return JVMTI_ERROR_NONE
;
854 static jvmtiError JNICALL
855 _Jv_JVMTI_ForceGarbageCollection (MAYBE_UNUSED jvmtiEnv
*env
)
857 REQUIRE_PHASE (env
, JVMTI_PHASE_LIVE
);
859 return JVMTI_ERROR_NONE
;
862 static jvmtiError JNICALL
863 _Jv_JVMTI_SetJNIFunctionTable (MAYBE_UNUSED jvmtiEnv
*env
,
864 const jniNativeInterface
*function_table
)
866 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
867 NULL_CHECK (function_table
);
868 memcpy (&_Jv_JNIFunctions
, function_table
, sizeof (jniNativeInterface
));
869 return JVMTI_ERROR_NONE
;
872 static jvmtiError JNICALL
873 _Jv_JVMTI_GetJNIFunctionTable (MAYBE_UNUSED jvmtiEnv
*env
,
874 jniNativeInterface
**function_table
)
876 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
877 NULL_CHECK (function_table
);
879 = (jniNativeInterface
*) _Jv_MallocUnchecked (sizeof (jniNativeInterface
));
880 if (*function_table
== NULL
)
881 return JVMTI_ERROR_OUT_OF_MEMORY
;
882 memcpy (*function_table
, &_Jv_JNIFunctions
, sizeof (jniNativeInterface
));
883 return JVMTI_ERROR_NONE
;
886 static jvmtiError JNICALL
887 _Jv_JVMTI_DisposeEnvironment (jvmtiEnv
*env
)
891 if (_jvmtiEnvironments
== NULL
)
892 return JVMTI_ERROR_INVALID_ENVIRONMENT
;
895 JvSynchronize
dummy (_envListLock
);
896 if (_jvmtiEnvironments
->env
== env
)
898 struct jvmti_env_list
*next
= _jvmtiEnvironments
->next
;
899 _Jv_Free (_jvmtiEnvironments
);
900 _jvmtiEnvironments
= next
;
904 struct jvmti_env_list
*e
= _jvmtiEnvironments
;
905 while (e
->next
!= NULL
&& e
->next
->env
!= env
)
908 return JVMTI_ERROR_INVALID_ENVIRONMENT
;
910 struct jvmti_env_list
*next
= e
->next
->next
;
918 check_enabled_events ();
920 return JVMTI_ERROR_NONE
;
923 static jvmtiError JNICALL
924 _Jv_JVMTI_GetSystemProperty (MAYBE_UNUSED jvmtiEnv
*env
, const char *property
,
927 REQUIRE_PHASE (env
, JVMTI_PHASE_ONLOAD
| JVMTI_PHASE_LIVE
);
928 NULL_CHECK (property
);
931 jstring name
= JvNewStringUTF(property
);
932 jstring result_str
= gnu::classpath::SystemProperties::getProperty(name
);
934 if (result_str
== NULL
)
935 return JVMTI_ERROR_NOT_AVAILABLE
;
937 int len
= JvGetStringUTFLength (result_str
);
938 *result
= (char *) _Jv_MallocUnchecked (len
+ 1);
940 return JVMTI_ERROR_OUT_OF_MEMORY
;
941 JvGetStringUTFRegion (result_str
, 0, result_str
->length(), *result
);
942 (*result
)[len
] = '\0';
944 return JVMTI_ERROR_NONE
;
947 static jvmtiError JNICALL
948 _Jv_JVMTI_SetSystemProperty (MAYBE_UNUSED jvmtiEnv
*env
, const char *property
,
951 REQUIRE_PHASE (env
, JVMTI_PHASE_ONLOAD
);
953 NULL_CHECK (property
);
956 // FIXME: When would a property not be writeable?
957 return JVMTI_ERROR_NONE
;
960 jstring prop_str
= JvNewStringUTF(property
);
961 jstring value_str
= JvNewStringUTF(value
);
962 gnu::classpath::SystemProperties::setProperty(prop_str
, value_str
);
963 return JVMTI_ERROR_NONE
;
966 static jvmtiError JNICALL
967 _Jv_JVMTI_GetTime (MAYBE_UNUSED jvmtiEnv
*env
, jlong
*nanos_ptr
)
969 NULL_CHECK (nanos_ptr
);
970 *nanos_ptr
= _Jv_platform_nanotime();
971 return JVMTI_ERROR_NONE
;
974 static jvmtiError JNICALL
975 _Jv_JVMTI_GetAvailableProcessors (MAYBE_UNUSED jvmtiEnv
*env
,
976 jint
*nprocessors_ptr
)
978 NULL_CHECK (nprocessors_ptr
);
979 #ifdef _SC_NPROCESSORS_ONLN
980 *nprocessors_ptr
= sysconf(_SC_NPROCESSORS_ONLN
);
982 *nprocessors_ptr
= 1;
984 return JVMTI_ERROR_NONE
;
987 static jvmtiError JNICALL
988 _Jv_JVMTI_AddToBootstrapClassLoaderSearch (MAYBE_UNUSED jvmtiEnv
*env
,
991 using namespace java::lang
;
992 using namespace java::net
;
993 using namespace gnu::gcj::runtime
;
995 REQUIRE_PHASE (env
, JVMTI_PHASE_ONLOAD
);
996 NULL_CHECK (segment
);
998 jstring str_segment
= JvNewStringUTF(segment
);
1002 url
= new URL(JvNewStringUTF("file"), NULL
, str_segment
);
1004 catch (jthrowable ignore
)
1006 return JVMTI_ERROR_ILLEGAL_ARGUMENT
;
1009 BootClassLoader
*loader
= VMClassLoader::bootLoader
;
1010 // Don't call this too early.
1011 // assert (loader != NULL);
1012 loader
->addURL(url
);
1013 return JVMTI_ERROR_NONE
;
1016 static jvmtiError JNICALL
1017 _Jv_JVMTI_SetVerboseFlag (MAYBE_UNUSED jvmtiEnv
*env
, jvmtiVerboseFlag flag
,
1022 case JVMTI_VERBOSE_OTHER
:
1023 case JVMTI_VERBOSE_GC
:
1024 case JVMTI_VERBOSE_JNI
:
1027 case JVMTI_VERBOSE_CLASS
:
1028 gcj::verbose_class_flag
= value
;
1031 return JVMTI_ERROR_ILLEGAL_ARGUMENT
;
1033 return JVMTI_ERROR_NONE
;
1036 static jvmtiError JNICALL
1037 _Jv_JVMTI_GetObjectSize (MAYBE_UNUSED jvmtiEnv
*env
, jobject object
,
1040 REQUIRE_PHASE (env
, JVMTI_PHASE_START
| JVMTI_PHASE_LIVE
);
1042 return JVMTI_ERROR_INVALID_OBJECT
;
1043 NULL_CHECK (result
);
1045 jclass klass
= object
->getClass();
1046 if (klass
->isArray())
1048 jclass comp
= klass
->getComponentType();
1050 = (jint
) (_Jv_uintptr_t
) _Jv_GetArrayElementFromElementType(NULL
,
1051 klass
->getComponentType());
1052 // FIXME: correct for primitive types?
1053 jint compSize
= comp
->size();
1054 __JArray
*array
= (__JArray
*) object
;
1055 *result
= base
+ array
->length
* compSize
;
1059 // Note that if OBJECT is a String then it may (if
1060 // str->data==str) take more space. Do we care?
1061 *result
= klass
->size();
1063 return JVMTI_ERROR_NONE
;
1066 /* An event is enabled only if it has both an event handler
1067 and it is enabled in the environment. */
1069 check_enabled_event (jvmtiEvent type
)
1074 #define GET_OFFSET(Event) \
1077 enabled = &JVMTI::Event; \
1078 offset = offsetof (jvmtiEventCallbacks, Event); \
1084 case JVMTI_EVENT_VM_INIT
:
1085 GET_OFFSET (VMInit
);
1088 case JVMTI_EVENT_VM_DEATH
:
1089 GET_OFFSET (VMDeath
);
1092 case JVMTI_EVENT_THREAD_START
:
1093 GET_OFFSET (ThreadStart
);
1096 case JVMTI_EVENT_THREAD_END
:
1097 GET_OFFSET (ThreadEnd
);
1100 case JVMTI_EVENT_CLASS_FILE_LOAD_HOOK
:
1101 GET_OFFSET (ClassFileLoadHook
);
1104 case JVMTI_EVENT_CLASS_LOAD
:
1105 GET_OFFSET (ClassLoad
);
1108 case JVMTI_EVENT_CLASS_PREPARE
:
1109 GET_OFFSET (ClassPrepare
);
1112 case JVMTI_EVENT_VM_START
:
1113 GET_OFFSET (VMStart
);
1116 case JVMTI_EVENT_EXCEPTION
:
1117 GET_OFFSET (Exception
);
1120 case JVMTI_EVENT_EXCEPTION_CATCH
:
1121 GET_OFFSET (ExceptionCatch
);
1124 case JVMTI_EVENT_SINGLE_STEP
:
1125 GET_OFFSET (SingleStep
);
1128 case JVMTI_EVENT_FRAME_POP
:
1129 GET_OFFSET (FramePop
);
1132 case JVMTI_EVENT_BREAKPOINT
:
1133 GET_OFFSET (Breakpoint
);
1136 case JVMTI_EVENT_FIELD_ACCESS
:
1137 GET_OFFSET (FieldAccess
);
1140 case JVMTI_EVENT_FIELD_MODIFICATION
:
1141 GET_OFFSET (FieldModification
);
1144 case JVMTI_EVENT_METHOD_ENTRY
:
1145 GET_OFFSET (MethodEntry
);
1148 case JVMTI_EVENT_METHOD_EXIT
:
1149 GET_OFFSET (MethodExit
);
1152 case JVMTI_EVENT_NATIVE_METHOD_BIND
:
1153 GET_OFFSET (NativeMethodBind
);
1156 case JVMTI_EVENT_COMPILED_METHOD_LOAD
:
1157 GET_OFFSET (CompiledMethodLoad
);
1160 case JVMTI_EVENT_COMPILED_METHOD_UNLOAD
:
1161 GET_OFFSET (CompiledMethodUnload
);
1164 case JVMTI_EVENT_DYNAMIC_CODE_GENERATED
:
1165 GET_OFFSET (DynamicCodeGenerated
);
1168 case JVMTI_EVENT_DATA_DUMP_REQUEST
:
1169 GET_OFFSET (DataDumpRequest
);
1172 case JVMTI_EVENT_MONITOR_WAIT
:
1173 GET_OFFSET (MonitorWait
);
1176 case JVMTI_EVENT_MONITOR_WAITED
:
1177 GET_OFFSET (MonitorWaited
);
1180 case JVMTI_EVENT_MONITOR_CONTENDED_ENTER
:
1181 GET_OFFSET (MonitorContendedEnter
);
1184 case JVMTI_EVENT_MONITOR_CONTENDED_ENTERED
:
1185 GET_OFFSET (MonitorContendedEntered
);
1188 case JVMTI_EVENT_GARBAGE_COLLECTION_START
:
1189 GET_OFFSET (GarbageCollectionStart
);
1192 case JVMTI_EVENT_GARBAGE_COLLECTION_FINISH
:
1193 GET_OFFSET (GarbageCollectionFinish
);
1196 case JVMTI_EVENT_OBJECT_FREE
:
1197 GET_OFFSET (ObjectFree
);
1200 case JVMTI_EVENT_VM_OBJECT_ALLOC
:
1201 GET_OFFSET (VMObjectAlloc
);
1206 "libgcj: check_enabled_event for unknown JVMTI event (%d)\n",
1212 int index
= EVENT_INDEX (type
); // safe since caller checks this
1214 JvSynchronize
dummy (_envListLock
);
1215 struct jvmti_env_list
*e
;
1216 FOREACH_ENVIRONMENT (e
)
1219 = reinterpret_cast<char *> (&e
->env
->callbacks
) + offset
;
1220 void **callback
= reinterpret_cast<void **> (addr
);
1221 if (e
->env
->enabled
[index
] && *callback
!= NULL
)
1232 check_enabled_events ()
1234 check_enabled_event (JVMTI_EVENT_VM_INIT
);
1235 check_enabled_event (JVMTI_EVENT_VM_DEATH
);
1236 check_enabled_event (JVMTI_EVENT_THREAD_START
);
1237 check_enabled_event (JVMTI_EVENT_THREAD_END
);
1238 check_enabled_event (JVMTI_EVENT_CLASS_FILE_LOAD_HOOK
);
1239 check_enabled_event (JVMTI_EVENT_CLASS_LOAD
);
1240 check_enabled_event (JVMTI_EVENT_CLASS_PREPARE
);
1241 check_enabled_event (JVMTI_EVENT_VM_START
);
1242 check_enabled_event (JVMTI_EVENT_EXCEPTION
);
1243 check_enabled_event (JVMTI_EVENT_EXCEPTION_CATCH
);
1244 check_enabled_event (JVMTI_EVENT_SINGLE_STEP
);
1245 check_enabled_event (JVMTI_EVENT_FRAME_POP
);
1246 check_enabled_event (JVMTI_EVENT_BREAKPOINT
);
1247 check_enabled_event (JVMTI_EVENT_FIELD_ACCESS
);
1248 check_enabled_event (JVMTI_EVENT_FIELD_MODIFICATION
);
1249 check_enabled_event (JVMTI_EVENT_METHOD_ENTRY
);
1250 check_enabled_event (JVMTI_EVENT_METHOD_EXIT
);
1251 check_enabled_event (JVMTI_EVENT_NATIVE_METHOD_BIND
);
1252 check_enabled_event (JVMTI_EVENT_COMPILED_METHOD_LOAD
);
1253 check_enabled_event (JVMTI_EVENT_COMPILED_METHOD_UNLOAD
);
1254 check_enabled_event (JVMTI_EVENT_DYNAMIC_CODE_GENERATED
);
1255 check_enabled_event (JVMTI_EVENT_DATA_DUMP_REQUEST
);
1256 check_enabled_event (JVMTI_EVENT_MONITOR_WAIT
);
1257 check_enabled_event (JVMTI_EVENT_MONITOR_WAITED
);
1258 check_enabled_event (JVMTI_EVENT_MONITOR_CONTENDED_ENTER
);
1259 check_enabled_event (JVMTI_EVENT_MONITOR_CONTENDED_ENTERED
);
1260 check_enabled_event (JVMTI_EVENT_GARBAGE_COLLECTION_START
);
1261 check_enabled_event (JVMTI_EVENT_GARBAGE_COLLECTION_FINISH
);
1262 check_enabled_event (JVMTI_EVENT_OBJECT_FREE
);
1263 check_enabled_event (JVMTI_EVENT_VM_OBJECT_ALLOC
);
1266 static jvmtiError JNICALL
1267 _Jv_JVMTI_SetEventNotificationMode (jvmtiEnv
*env
, jvmtiEventMode mode
,
1268 jvmtiEvent type
, jthread event_thread
, ...)
1270 REQUIRE_PHASE (env
, JVMTI_PHASE_ONLOAD
| JVMTI_PHASE_LIVE
);
1272 if (event_thread
!= NULL
)
1274 THREAD_CHECK_VALID (event_thread
);
1275 THREAD_CHECK_IS_ALIVE (event_thread
);
1289 return JVMTI_ERROR_ILLEGAL_ARGUMENT
;
1294 case JVMTI_EVENT_VM_INIT
:
1295 case JVMTI_EVENT_VM_DEATH
:
1296 case JVMTI_EVENT_THREAD_START
:
1297 case JVMTI_EVENT_VM_START
:
1298 case JVMTI_EVENT_COMPILED_METHOD_LOAD
:
1299 case JVMTI_EVENT_COMPILED_METHOD_UNLOAD
:
1300 case JVMTI_EVENT_DYNAMIC_CODE_GENERATED
:
1301 case JVMTI_EVENT_DATA_DUMP_REQUEST
:
1302 ILLEGAL_ARGUMENT (event_thread
!= NULL
);
1305 case JVMTI_EVENT_THREAD_END
:
1306 case JVMTI_EVENT_CLASS_FILE_LOAD_HOOK
:
1307 case JVMTI_EVENT_CLASS_LOAD
:
1308 case JVMTI_EVENT_CLASS_PREPARE
:
1309 case JVMTI_EVENT_EXCEPTION
:
1310 case JVMTI_EVENT_EXCEPTION_CATCH
:
1311 case JVMTI_EVENT_SINGLE_STEP
:
1312 case JVMTI_EVENT_FRAME_POP
:
1313 case JVMTI_EVENT_BREAKPOINT
:
1314 case JVMTI_EVENT_FIELD_ACCESS
:
1315 case JVMTI_EVENT_FIELD_MODIFICATION
:
1316 case JVMTI_EVENT_METHOD_ENTRY
:
1317 case JVMTI_EVENT_METHOD_EXIT
:
1318 case JVMTI_EVENT_NATIVE_METHOD_BIND
:
1319 case JVMTI_EVENT_MONITOR_WAIT
:
1320 case JVMTI_EVENT_MONITOR_WAITED
:
1321 case JVMTI_EVENT_MONITOR_CONTENDED_ENTER
:
1322 case JVMTI_EVENT_MONITOR_CONTENDED_ENTERED
:
1323 case JVMTI_EVENT_GARBAGE_COLLECTION_START
:
1324 case JVMTI_EVENT_GARBAGE_COLLECTION_FINISH
:
1325 case JVMTI_EVENT_OBJECT_FREE
:
1326 case JVMTI_EVENT_VM_OBJECT_ALLOC
:
1330 return JVMTI_ERROR_INVALID_EVENT_TYPE
;
1333 env
->thread
[EVENT_INDEX(type
)] = event_thread
;
1334 env
->enabled
[EVENT_INDEX(type
)] = enabled
;
1335 check_enabled_event (type
);
1336 return JVMTI_ERROR_NONE
;
1339 static jvmtiError JNICALL
1340 _Jv_JVMTI_SetEventCallbacks (jvmtiEnv
*env
,
1341 const jvmtiEventCallbacks
*callbacks
,
1342 jint size_of_callbacks
)
1344 REQUIRE_PHASE (env
, JVMTI_PHASE_ONLOAD
| JVMTI_PHASE_LIVE
);
1345 ILLEGAL_ARGUMENT (size_of_callbacks
< 0);
1347 // Copy the list of callbacks into the environment
1348 memcpy (&env
->callbacks
, callbacks
, sizeof (jvmtiEventCallbacks
));
1350 /* Check which events are now enabeld (JVMTI makes no requirements
1351 about the order in which SetEventCallbacks and SetEventNotifications
1352 are called. So we must check all events here. */
1353 check_enabled_events ();
1355 return JVMTI_ERROR_NONE
;
1358 static jvmtiError JNICALL
1359 _Jv_JVMTI_GetErrorName (MAYBE_UNUSED jvmtiEnv
*env
, jvmtiError error
,
1362 NULL_CHECK (name_ptr
);
1367 case JVMTI_ERROR_NONE
:
1371 case JVMTI_ERROR_NULL_POINTER
:
1372 name
= "null pointer";
1375 case JVMTI_ERROR_OUT_OF_MEMORY
:
1376 name
= "out of memory";
1379 case JVMTI_ERROR_ACCESS_DENIED
:
1380 name
= "access denied";
1383 case JVMTI_ERROR_WRONG_PHASE
:
1384 name
= "wrong phase";
1387 case JVMTI_ERROR_INTERNAL
:
1388 name
= "internal error";
1391 case JVMTI_ERROR_UNATTACHED_THREAD
:
1392 name
= "unattached thread";
1395 case JVMTI_ERROR_INVALID_ENVIRONMENT
:
1396 name
= "invalid environment";
1399 case JVMTI_ERROR_INVALID_PRIORITY
:
1400 name
= "invalid priority";
1403 case JVMTI_ERROR_THREAD_NOT_SUSPENDED
:
1404 name
= "thread not suspended";
1407 case JVMTI_ERROR_THREAD_SUSPENDED
:
1408 name
= "thread suspended";
1411 case JVMTI_ERROR_THREAD_NOT_ALIVE
:
1412 name
= "thread not alive";
1415 case JVMTI_ERROR_CLASS_NOT_PREPARED
:
1416 name
= "class not prepared";
1419 case JVMTI_ERROR_NO_MORE_FRAMES
:
1420 name
= "no more frames";
1423 case JVMTI_ERROR_OPAQUE_FRAME
:
1424 name
= "opaque frame";
1427 case JVMTI_ERROR_DUPLICATE
:
1431 case JVMTI_ERROR_NOT_FOUND
:
1435 case JVMTI_ERROR_NOT_MONITOR_OWNER
:
1436 name
= "not monitor owner";
1439 case JVMTI_ERROR_INTERRUPT
:
1440 name
= "interrupted";
1443 case JVMTI_ERROR_UNMODIFIABLE_CLASS
:
1444 name
= "unmodifiable class";
1447 case JVMTI_ERROR_NOT_AVAILABLE
:
1448 name
= "not available";
1451 case JVMTI_ERROR_ABSENT_INFORMATION
:
1452 name
= "absent information";
1455 case JVMTI_ERROR_INVALID_EVENT_TYPE
:
1456 name
= "invalid event type";
1459 case JVMTI_ERROR_NATIVE_METHOD
:
1460 name
= "native method";
1463 case JVMTI_ERROR_INVALID_THREAD
:
1464 name
= "invalid thread";
1467 case JVMTI_ERROR_INVALID_THREAD_GROUP
:
1468 name
= "invalid thread group";
1471 case JVMTI_ERROR_INVALID_OBJECT
:
1472 name
= "invalid object";
1475 case JVMTI_ERROR_INVALID_CLASS
:
1476 name
= "invalid class";
1479 case JVMTI_ERROR_INVALID_METHODID
:
1480 name
= "invalid method ID";
1483 case JVMTI_ERROR_INVALID_LOCATION
:
1484 name
= "invalid location";
1487 case JVMTI_ERROR_INVALID_FIELDID
:
1488 name
= "invalid field ID";
1491 case JVMTI_ERROR_TYPE_MISMATCH
:
1492 name
= "type mismatch";
1495 case JVMTI_ERROR_INVALID_SLOT
:
1496 name
= "invalid slot";
1499 case JVMTI_ERROR_INVALID_MONITOR
:
1500 name
= "invalid monitor";
1503 case JVMTI_ERROR_INVALID_CLASS_FORMAT
:
1504 name
= "invalid class format";
1507 case JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION
:
1508 name
= "circular class definition";
1511 case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED
:
1512 name
= "unsupported redefinition: method added";
1515 case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED
:
1516 name
= "unsupported redefinition: schema changed";
1519 case JVMTI_ERROR_INVALID_TYPESTATE
:
1520 name
= "invalid type state";
1523 case JVMTI_ERROR_FAILS_VERIFICATION
:
1524 name
= "fails verification";
1527 case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED
:
1528 name
= "unsupported redefinition: hierarchy changed";
1531 case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED
:
1532 name
= "unsupported redefinition: method deleted";
1535 case JVMTI_ERROR_UNSUPPORTED_VERSION
:
1536 name
= "unsupported version";
1539 case JVMTI_ERROR_NAMES_DONT_MATCH
:
1540 name
= "names do not match";
1543 case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED
:
1544 name
= "unsupported redefinition: class modifiers changed";
1547 case JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED
:
1548 name
= "unsupported redefinition: method modifiers changed";
1551 case JVMTI_ERROR_MUST_POSSESS_CAPABILITY
:
1552 name
= "must possess capability";
1555 case JVMTI_ERROR_ILLEGAL_ARGUMENT
:
1556 name
= "illegal argument";
1560 return JVMTI_ERROR_ILLEGAL_ARGUMENT
;
1563 *name_ptr
= (char *) _Jv_MallocUnchecked (strlen (name
) + 1);
1564 if (*name_ptr
== NULL
)
1565 return JVMTI_ERROR_OUT_OF_MEMORY
;
1567 strcpy (*name_ptr
, name
);
1568 return JVMTI_ERROR_NONE
;
1571 #define RESERVED NULL
1572 #define UNIMPLEMENTED NULL
1574 struct _Jv_jvmtiEnv _Jv_JVMTI_Interface
=
1576 RESERVED
, // reserved1
1577 _Jv_JVMTI_SetEventNotificationMode
, // SetEventNotificationMode
1578 RESERVED
, // reserved3
1579 _Jv_JVMTI_GetAllThreads
, // GetAllThreads
1580 _Jv_JVMTI_SuspendThread
, // SuspendThread
1581 _Jv_JVMTI_ResumeThread
, // ResumeThread
1582 UNIMPLEMENTED
, // StopThread
1583 _Jv_JVMTI_InterruptThread
, // InterruptThread
1584 UNIMPLEMENTED
, // GetThreadInfo
1585 UNIMPLEMENTED
, // GetOwnedMonitorInfo
1586 UNIMPLEMENTED
, // GetCurrentContendedMonitor
1587 UNIMPLEMENTED
, // RunAgentThread
1588 UNIMPLEMENTED
, // GetTopThreadGroups
1589 UNIMPLEMENTED
, // GetThreadGroupInfo
1590 UNIMPLEMENTED
, // GetThreadGroupChildren
1591 _Jv_JVMTI_GetFrameCount
, // GetFrameCount
1592 UNIMPLEMENTED
, // GetThreadState
1593 RESERVED
, // reserved18
1594 UNIMPLEMENTED
, // GetFrameLocation
1595 UNIMPLEMENTED
, // NotifyPopFrame
1596 UNIMPLEMENTED
, // GetLocalObject
1597 UNIMPLEMENTED
, // GetLocalInt
1598 UNIMPLEMENTED
, // GetLocalLong
1599 UNIMPLEMENTED
, // GetLocalFloat
1600 UNIMPLEMENTED
, // GetLocalDouble
1601 UNIMPLEMENTED
, // SetLocalObject
1602 UNIMPLEMENTED
, // SetLocalInt
1603 UNIMPLEMENTED
, // SetLocalLong
1604 UNIMPLEMENTED
, // SetLocalFloat
1605 UNIMPLEMENTED
, // SetLocalDouble
1606 _Jv_JVMTI_CreateRawMonitor
, // CreateRawMonitor
1607 _Jv_JVMTI_DestroyRawMonitor
, // DestroyRawMonitor
1608 _Jv_JVMTI_RawMonitorEnter
, // RawMonitorEnter
1609 _Jv_JVMTI_RawMonitorExit
, // RawMonitorExit
1610 _Jv_JVMTI_RawMonitorWait
, // RawMonitorWait
1611 _Jv_JVMTI_RawMonitorNotify
, // RawMonitorNotify
1612 _Jv_JVMTI_RawMonitorNotifyAll
, // RawMonitorNotifyAll
1613 _Jv_JVMTI_SetBreakpoint
, // SetBreakpoint
1614 _Jv_JVMTI_ClearBreakpoint
, // ClearBreakpoint
1615 RESERVED
, // reserved40
1616 UNIMPLEMENTED
, // SetFieldAccessWatch
1617 UNIMPLEMENTED
, // ClearFieldAccessWatch
1618 UNIMPLEMENTED
, // SetFieldModificationWatch
1619 UNIMPLEMENTED
, // ClearFieldModificationWatch
1620 RESERVED
, // reserved45
1621 _Jv_JVMTI_Allocate
, // Allocate
1622 _Jv_JVMTI_Deallocate
, // Deallocate
1623 UNIMPLEMENTED
, // GetClassSignature
1624 _Jv_JVMTI_GetClassStatus
, // GetClassStatus
1625 UNIMPLEMENTED
, // GetSourceFileName
1626 _Jv_JVMTI_GetClassModifiers
, // GetClassModifiers
1627 _Jv_JVMTI_GetClassMethods
, // GetClassMethods
1628 UNIMPLEMENTED
, // GetClassFields
1629 UNIMPLEMENTED
, // GetImplementedInterfaces
1630 _Jv_JVMTI_IsInterface
, // IsInterface
1631 _Jv_JVMTI_IsArrayClass
, // IsArrayClass
1632 _Jv_JVMTI_GetClassLoader
, // GetClassLoader
1633 _Jv_JVMTI_GetObjectHashCode
, // GetObjectHashCode
1634 UNIMPLEMENTED
, // GetObjectMonitorUsage
1635 UNIMPLEMENTED
, // GetFieldName
1636 UNIMPLEMENTED
, // GetFieldDeclaringClass
1637 _Jv_JVMTI_GetFieldModifiers
, // GetFieldModifiers
1638 _Jv_JVMTI_IsFieldSynthetic
, // IsFieldSynthetic
1639 _Jv_JVMTI_GetMethodName
, // GetMethodName
1640 _Jv_JVMTI_GetMethodDeclaringClass
, // GetMethodDeclaringClass
1641 _Jv_JVMTI_GetMethodModifiers
, // GetMethodModifers
1642 RESERVED
, // reserved67
1643 UNIMPLEMENTED
, // GetMaxLocals
1644 UNIMPLEMENTED
, // GetArgumentsSize
1645 _Jv_JVMTI_GetLineNumberTable
, // GetLineNumberTable
1646 UNIMPLEMENTED
, // GetMethodLocation
1647 UNIMPLEMENTED
, // GetLocalVariableTable
1648 RESERVED
, // reserved73
1649 RESERVED
, // reserved74
1650 UNIMPLEMENTED
, // GetBytecodes
1651 _Jv_JVMTI_IsMethodNative
, // IsMethodNative
1652 _Jv_JVMTI_IsMethodSynthetic
, // IsMethodSynthetic
1653 UNIMPLEMENTED
, // GetLoadedClasses
1654 _Jv_JVMTI_GetClassLoaderClasses
, // GetClassLoaderClasses
1655 UNIMPLEMENTED
, // PopFrame
1656 RESERVED
, // reserved81
1657 RESERVED
, // reserved82
1658 RESERVED
, // reserved83
1659 RESERVED
, // reserved84
1660 RESERVED
, // reserved85
1661 RESERVED
, // reserved86
1662 UNIMPLEMENTED
, // RedefineClasses
1663 UNIMPLEMENTED
, // GetVersionNumber
1664 UNIMPLEMENTED
, // GetCapabilities
1665 UNIMPLEMENTED
, // GetSourceDebugExtension
1666 UNIMPLEMENTED
, // IsMethodObsolete
1667 UNIMPLEMENTED
, // SuspendThreadList
1668 UNIMPLEMENTED
, // ResumeThreadList
1669 RESERVED
, // reserved94
1670 RESERVED
, // reserved95
1671 RESERVED
, // reserved96
1672 RESERVED
, // reserved97
1673 RESERVED
, // reserved98
1674 RESERVED
, // reserved99
1675 UNIMPLEMENTED
, // GetAllStackTraces
1676 UNIMPLEMENTED
, // GetThreadListStackTraces
1677 UNIMPLEMENTED
, // GetThreadLocalStorage
1678 UNIMPLEMENTED
, // SetThreadLocalStorage
1679 _Jv_JVMTI_GetStackTrace
, // GetStackTrace
1680 RESERVED
, // reserved105
1681 UNIMPLEMENTED
, // GetTag
1682 UNIMPLEMENTED
, // SetTag
1683 _Jv_JVMTI_ForceGarbageCollection
, // ForceGarbageCollection
1684 UNIMPLEMENTED
, // IterateOverObjectsReachable
1685 UNIMPLEMENTED
, // IterateOverReachableObjects
1686 UNIMPLEMENTED
, // IterateOverHeap
1687 UNIMPLEMENTED
, // IterateOverInstanceOfClass
1688 RESERVED
, // reserved113
1689 UNIMPLEMENTED
, // GetObjectsWithTags
1690 RESERVED
, // reserved115
1691 RESERVED
, // reserved116
1692 RESERVED
, // reserved117
1693 RESERVED
, // reserved118
1694 RESERVED
, // reserved119
1695 _Jv_JVMTI_SetJNIFunctionTable
, // SetJNIFunctionTable
1696 _Jv_JVMTI_GetJNIFunctionTable
, // GetJNIFunctionTable
1697 _Jv_JVMTI_SetEventCallbacks
, // SetEventCallbacks
1698 UNIMPLEMENTED
, // GenerateEvents
1699 UNIMPLEMENTED
, // GetExtensionFunctions
1700 UNIMPLEMENTED
, // GetExtensionEvents
1701 UNIMPLEMENTED
, // SetExtensionEventCallback
1702 _Jv_JVMTI_DisposeEnvironment
, // DisposeEnvironment
1703 _Jv_JVMTI_GetErrorName
, // GetErrorName
1704 UNIMPLEMENTED
, // GetJLocationFormat
1705 UNIMPLEMENTED
, // GetSystemProperties
1706 _Jv_JVMTI_GetSystemProperty
, // GetSystemProperty
1707 _Jv_JVMTI_SetSystemProperty
, // SetSystemProperty
1708 UNIMPLEMENTED
, // GetPhase
1709 UNIMPLEMENTED
, // GetCurrentThreadCpuTimerInfo
1710 UNIMPLEMENTED
, // GetCurrentThreadCpuTime
1711 UNIMPLEMENTED
, // GetThreadCpuTimerInfo
1712 UNIMPLEMENTED
, // GetThreadCpuTime
1713 UNIMPLEMENTED
, // GetTimerInfo
1714 _Jv_JVMTI_GetTime
, // GetTime
1715 UNIMPLEMENTED
, // GetPotentialCapabilities
1716 RESERVED
, // reserved141
1717 UNIMPLEMENTED
, // AddCapabilities
1718 UNIMPLEMENTED
, // RelinquishCapabilities
1719 _Jv_JVMTI_GetAvailableProcessors
, // GetAvailableProcessors
1720 RESERVED
, // reserved145
1721 RESERVED
, // reserved146
1722 UNIMPLEMENTED
, // GetEnvironmentLocalStorage
1723 UNIMPLEMENTED
, // SetEnvironmentLocalStorage
1724 _Jv_JVMTI_AddToBootstrapClassLoaderSearch
, // AddToBootstrapClassLoaderSearch
1725 _Jv_JVMTI_SetVerboseFlag
, // SetVerboseFlag
1726 RESERVED
, // reserved151
1727 RESERVED
, // reserved152
1728 RESERVED
, // reserved153
1729 _Jv_JVMTI_GetObjectSize
// GetObjectSize
1733 _Jv_GetJVMTIEnv (void)
1736 = (_Jv_JVMTIEnv
*) _Jv_MallocUnchecked (sizeof (_Jv_JVMTIEnv
));
1737 env
->p
= &_Jv_JVMTI_Interface
;
1740 JvSynchronize
dummy (_envListLock
);
1741 struct jvmti_env_list
*element
1742 = (struct jvmti_env_list
*) _Jv_MallocUnchecked (sizeof (struct jvmti_env_list
));
1744 element
->next
= NULL
;
1746 if (_jvmtiEnvironments
== NULL
)
1747 _jvmtiEnvironments
= element
;
1750 struct jvmti_env_list
*e
;
1751 for (e
= _jvmtiEnvironments
; e
->next
!= NULL
; e
= e
->next
)
1763 _jvmtiEnvironments
= NULL
;
1764 _envListLock
= new java::lang::Object ();
1766 // No environments, so this should set all JVMTI:: members to false
1767 check_enabled_events ();
1771 post_event (jvmtiEnv
*env
, jvmtiEvent type
, jthread event_thread
, va_list args
)
1773 #define ARG(Type,Name) Type Name = (Type) va_arg (args, Type)
1775 #define GET_BOOLEAN_ARG(Name) \
1777 jboolean Name = (b == 0) ? false : true
1779 #define GET_CHAR_ARG(Name) \
1781 char Name = static_cast<char> (c)
1785 case JVMTI_EVENT_VM_INIT
:
1786 if (env
->callbacks
.VMInit
!= NULL
)
1788 ARG (JNIEnv
*, jni_env
);
1789 env
->callbacks
.VMInit (env
, jni_env
, event_thread
);
1793 case JVMTI_EVENT_VM_DEATH
:
1794 if (env
->callbacks
.VMDeath
!= NULL
)
1796 ARG (JNIEnv
*, jni_env
);
1797 env
->callbacks
.VMDeath (env
, jni_env
);
1801 case JVMTI_EVENT_THREAD_START
:
1802 if (env
->callbacks
.ThreadStart
!= NULL
)
1804 ARG (JNIEnv
*, jni_env
);
1805 env
->callbacks
.ThreadStart (env
, jni_env
, event_thread
);
1809 case JVMTI_EVENT_THREAD_END
:
1810 if (env
->callbacks
.ThreadEnd
!= NULL
)
1812 ARG (JNIEnv
*, jni_env
);
1813 env
->callbacks
.ThreadEnd (env
, jni_env
, event_thread
);
1817 case JVMTI_EVENT_CLASS_FILE_LOAD_HOOK
:
1818 if (env
->callbacks
.ClassFileLoadHook
!= NULL
)
1820 ARG (JNIEnv
*, jni_env
);
1821 ARG (jclass
, class_being_redefined
);
1822 ARG (jobject
, loader
);
1823 ARG (const char *, name
);
1824 ARG (jobject
, protection_domain
);
1825 ARG (jint
, class_data_len
);
1826 ARG (const unsigned char *, class_data
);
1827 ARG (jint
*, new_class_data_len
);
1828 ARG (unsigned char **, new_class_data
);
1829 env
->callbacks
.ClassFileLoadHook (env
, jni_env
,
1830 class_being_redefined
, loader
,
1831 name
, protection_domain
,
1832 class_data_len
, class_data
,
1838 case JVMTI_EVENT_CLASS_LOAD
:
1839 if (env
->callbacks
.ClassLoad
!= NULL
)
1841 ARG (JNIEnv
*, jni_env
);
1842 ARG (jclass
, klass
);
1843 env
->callbacks
.ClassLoad (env
, jni_env
, event_thread
, klass
);
1847 case JVMTI_EVENT_CLASS_PREPARE
:
1848 if (env
->callbacks
.ClassPrepare
!= NULL
)
1850 ARG (JNIEnv
*, jni_env
);
1851 ARG (jclass
, klass
);
1852 env
->callbacks
.ClassPrepare (env
, jni_env
, event_thread
, klass
);
1856 case JVMTI_EVENT_VM_START
:
1857 if (env
->callbacks
.VMStart
!= NULL
)
1859 ARG (JNIEnv
*, jni_env
);
1860 env
->callbacks
.VMStart (env
, jni_env
);
1864 case JVMTI_EVENT_EXCEPTION
:
1865 if (env
->callbacks
.Exception
!= NULL
)
1867 ARG (JNIEnv
*, jni_env
);
1868 ARG (jmethodID
, method
);
1869 ARG (jlocation
, location
);
1870 ARG (jobject
, exception
);
1871 ARG (jmethodID
, catch_method
);
1872 ARG (jlocation
, catch_location
);
1873 env
->callbacks
.Exception (env
, jni_env
, event_thread
, method
,
1874 location
, exception
, catch_method
,
1879 case JVMTI_EVENT_EXCEPTION_CATCH
:
1880 if (env
->callbacks
.ExceptionCatch
!= NULL
)
1882 ARG (JNIEnv
*, jni_env
);
1883 ARG (jmethodID
, method
);
1884 ARG (jlocation
, location
);
1885 ARG (jobject
, exception
);
1886 env
->callbacks
.ExceptionCatch (env
, jni_env
, event_thread
, method
,
1887 location
, exception
);
1891 case JVMTI_EVENT_SINGLE_STEP
:
1892 if (env
->callbacks
.SingleStep
!= NULL
)
1894 ARG (JNIEnv
*, jni_env
);
1895 ARG (jmethodID
, method
);
1896 ARG (jlocation
, location
);
1897 env
->callbacks
.SingleStep (env
, jni_env
, event_thread
, method
,
1902 case JVMTI_EVENT_FRAME_POP
:
1903 if (env
->callbacks
.FramePop
!= NULL
)
1905 ARG (JNIEnv
*, jni_env
);
1906 ARG (jmethodID
, method
);
1907 GET_BOOLEAN_ARG (was_popped_by_exception
);
1908 env
->callbacks
.FramePop (env
, jni_env
, event_thread
, method
,
1909 was_popped_by_exception
);
1913 case JVMTI_EVENT_BREAKPOINT
:
1914 if (env
->callbacks
.Breakpoint
!= NULL
)
1916 ARG (JNIEnv
*, jni_env
);
1917 ARG (jmethodID
, method
);
1918 ARG (jlocation
, location
);
1919 env
->callbacks
.Breakpoint (env
, jni_env
, event_thread
, method
,
1924 case JVMTI_EVENT_FIELD_ACCESS
:
1925 if (env
->callbacks
.FieldAccess
!= NULL
)
1927 ARG (JNIEnv
*, jni_env
);
1928 ARG (jmethodID
, method
);
1929 ARG (jlocation
, location
);
1930 ARG (jclass
, field_class
);
1931 ARG (jobject
, object
);
1932 ARG (jfieldID
, field
);
1933 env
->callbacks
.FieldAccess (env
, jni_env
, event_thread
, method
,
1934 location
, field_class
, object
, field
);
1938 case JVMTI_EVENT_FIELD_MODIFICATION
:
1939 if (env
->callbacks
.FieldModification
!= NULL
)
1941 ARG (JNIEnv
*, jni_env
);
1942 ARG (jmethodID
, method
);
1943 ARG (jlocation
, location
);
1944 ARG (jclass
, field_class
);
1945 ARG (jobject
, object
);
1946 ARG (jfieldID
, field
);
1947 GET_CHAR_ARG (signature_type
);
1948 ARG (jvalue
, new_value
);
1949 env
->callbacks
.FieldModification (env
, jni_env
, event_thread
, method
,
1950 location
, field_class
, object
,
1951 field
, signature_type
, new_value
);
1955 case JVMTI_EVENT_METHOD_ENTRY
:
1956 if (env
->callbacks
.MethodEntry
!= NULL
)
1958 ARG (JNIEnv
*, jni_env
);
1959 ARG (jmethodID
, method
);
1960 env
->callbacks
.MethodEntry (env
, jni_env
, event_thread
, method
);
1964 case JVMTI_EVENT_METHOD_EXIT
:
1965 if (env
->callbacks
.MethodExit
!= NULL
)
1967 ARG (JNIEnv
*, jni_env
);
1968 ARG (jmethodID
, method
);
1969 GET_BOOLEAN_ARG (was_popped_by_exception
);
1970 ARG (jvalue
, return_value
);
1971 env
->callbacks
.MethodExit (env
, jni_env
, event_thread
, method
,
1972 was_popped_by_exception
, return_value
);
1976 case JVMTI_EVENT_NATIVE_METHOD_BIND
:
1977 if (env
->callbacks
.NativeMethodBind
!= NULL
)
1979 ARG (JNIEnv
*, jni_env
);
1980 ARG (jmethodID
, method
);
1981 ARG (void *, address
);
1982 ARG (void **, new_address_ptr
);
1983 env
->callbacks
.NativeMethodBind (env
, jni_env
, event_thread
, method
,
1984 address
, new_address_ptr
);
1988 case JVMTI_EVENT_COMPILED_METHOD_LOAD
:
1989 if (env
->callbacks
.CompiledMethodLoad
!= NULL
)
1991 ARG (jmethodID
, method
);
1992 ARG (jint
, code_size
);
1993 ARG (const void *, code_addr
);
1994 ARG (jint
, map_length
);
1995 ARG (const jvmtiAddrLocationMap
*, map
);
1996 ARG (const void *, compile_info
);
1997 env
->callbacks
.CompiledMethodLoad (env
, method
, code_size
, code_addr
,
1998 map_length
, map
, compile_info
);
2002 case JVMTI_EVENT_COMPILED_METHOD_UNLOAD
:
2003 if (env
->callbacks
.CompiledMethodUnload
!= NULL
)
2005 ARG (jmethodID
, method
);
2006 ARG (const void *, code_addr
);
2007 env
->callbacks
.CompiledMethodUnload (env
, method
, code_addr
);
2011 case JVMTI_EVENT_DYNAMIC_CODE_GENERATED
:
2012 if (env
->callbacks
.DynamicCodeGenerated
!= NULL
)
2014 ARG (const char *, name
);
2015 ARG (const void *, address
);
2017 env
->callbacks
.DynamicCodeGenerated (env
, name
, address
, length
);
2021 case JVMTI_EVENT_DATA_DUMP_REQUEST
:
2022 if (env
->callbacks
.DataDumpRequest
!= NULL
)
2024 env
->callbacks
.DataDumpRequest (env
);
2028 case JVMTI_EVENT_MONITOR_WAIT
:
2029 if (env
->callbacks
.MonitorWait
!= NULL
)
2031 ARG (JNIEnv
*, jni_env
);
2032 ARG (jobject
, object
);
2033 ARG (jlong
, timeout
);
2034 env
->callbacks
.MonitorWait (env
, jni_env
, event_thread
, object
,
2039 case JVMTI_EVENT_MONITOR_WAITED
:
2040 if (env
->callbacks
.MonitorWaited
!= NULL
)
2042 ARG (JNIEnv
*, jni_env
);
2043 ARG (jobject
, object
);
2044 GET_BOOLEAN_ARG (timed_out
);
2045 env
->callbacks
.MonitorWaited (env
, jni_env
, event_thread
, object
,
2050 case JVMTI_EVENT_MONITOR_CONTENDED_ENTER
:
2051 if (env
->callbacks
.MonitorContendedEnter
!= NULL
)
2053 ARG (JNIEnv
*, jni_env
);
2054 ARG (jobject
, object
);
2055 env
->callbacks
.MonitorContendedEnter (env
, jni_env
, event_thread
,
2060 case JVMTI_EVENT_MONITOR_CONTENDED_ENTERED
:
2061 if (env
->callbacks
.MonitorContendedEntered
!= NULL
)
2063 ARG (JNIEnv
*, jni_env
);
2064 ARG (jobject
, object
);
2065 env
->callbacks
.MonitorContendedEntered (env
, jni_env
, event_thread
,
2070 case JVMTI_EVENT_GARBAGE_COLLECTION_START
:
2071 if (env
->callbacks
.GarbageCollectionStart
!= NULL
)
2073 env
->callbacks
.GarbageCollectionStart (env
);
2077 case JVMTI_EVENT_GARBAGE_COLLECTION_FINISH
:
2078 if (env
->callbacks
.GarbageCollectionFinish
!= NULL
)
2080 env
->callbacks
.GarbageCollectionFinish (env
);
2084 case JVMTI_EVENT_OBJECT_FREE
:
2085 if (env
->callbacks
.ObjectFree
!= NULL
)
2088 env
->callbacks
.ObjectFree (env
, tag
);
2092 case JVMTI_EVENT_VM_OBJECT_ALLOC
:
2093 if (env
->callbacks
.VMObjectAlloc
!= NULL
)
2095 ARG (JNIEnv
*, jni_env
);
2096 ARG (jobject
, object
);
2097 ARG (jclass
, object_class
);
2099 env
->callbacks
.VMObjectAlloc (env
, jni_env
, event_thread
,
2100 object
, object_class
, size
);
2105 fprintf (stderr
, "libgcj: post of unknown JVMTI event (%d)\n",
2111 #undef GET_BOOLEAN_ARG
2115 /* Post an event to requesting JVMTI environments
2117 * This function should not be called without consulting the
2118 * JVMTI_REQUESTED_EVENT macro first (for speed). It does no real
2119 * harm (other than kill speed), since this function will still
2120 * only send the event if it was properly requested by an environment.
2123 _Jv_JVMTI_PostEvent (jvmtiEvent type
, jthread event_thread
, ...)
2126 va_start (args
, event_thread
);
2128 JvSynchronize
dummy (_envListLock
);
2129 struct jvmti_env_list
*e
;
2130 FOREACH_ENVIRONMENT (e
)
2132 /* Events are only posted if the event was explicitly enabled,
2133 it has a registered event handler, and the event thread
2134 matches (either globally or restricted to a specific thread).
2135 Here we check all but the event handler, which will be handled
2137 if (e
->env
->enabled
[EVENT_INDEX(type
)]
2138 && (e
->env
->thread
[EVENT_INDEX(type
)] == NULL
2139 || e
->env
->thread
[EVENT_INDEX(type
)] == event_thread
))
2141 post_event (e
->env
, type
, event_thread
, args
);