From: Keith Seitz <keiths@redhat.com>
To: Java Patch List <java-patches@gcc.gnu.org>
Subject: [RFA/JVMTI] SetEventNotificationMode and SetEventCallbacks
Date: Fri, 01 Sep 2006 19:01:00 -0000 [thread overview]
Message-ID: <44F8836D.90006@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1821 bytes --]
Hi,
Let me apologize ahead of time for posting a nearly 1,000 line patch. I
promise not to do it again (at least today!)...
This patch implements the two JVMTI functions $subject. As you can
imagine, JVMTI event notifications in libgcj are going to be quite
invasive. Hoping to minimize the damage from this, I've adopted
basically the same technique that I was using with JDWP and
Jdwp::isDebugging.
Only this time, it's not just a simple boolean check. :-(
The proposed method for adding event notifications to libgcj would look
something like this (e.g. ThreadEnd):
#include <jvmti.h>
#include "jvmti-int.h"
...
if (JVMTI_REQUESTED_EVENT (ThreadEnd))
{
_Jv_JVMTI_PostEvent (JVMTI_EVENT_THREAD_END, ending_thread);
}
and so on. _Jv_JVMTI_PostEvent uses stdargs so that additional
event-specific parameters may be passed via the same interface.
If this patch is accepted, I think it would be wise to build it on
several different architectures before committing to ensure no weirdness
occurs which would break gcc bootstrapping.
Comments/questions/concerns?
Keith
ChangeLog
2006-09-01 Keith Seitz <keiths@redhat.com>
* jvmti.cc (_Jv_JVMTI_RequestedEvents): New global.
(_Jv_JVMTI_DisposeEnvironment): Check for enabled events.
(check_enabled_event): New function.
(check_enabled_events): New function.
(post_event): New function.
(_Jv_JVMTI_SetEventNotificationMode): New function.
(_Jv_JVMTI_SetEventCallbacks): New function.
(_Jv_JVMTI_Interface): Define SetEventNotificationMode and
SetEventCallbacks members.
* include/jvmti-int.h: New file.
* include/jvmti_md.h (EVENT_SLOTS) [__GCJ_JNI_IMP__]: Define.
(_CLASSPATH_JVMTIENV_CONTENTS) [__GCJ_JNI_IMPL__]: Define.
[-- Attachment #2: jvmti-events.patch --]
[-- Type: text/x-patch, Size: 27407 bytes --]
Index: include/jvmti_md.h
===================================================================
--- include/jvmti_md.h (revision 116609)
+++ include/jvmti_md.h (working copy)
@@ -27,6 +27,32 @@
#ifndef __GCJ_JVMTI_MD_H__
#define __GCJ_JVMTI_MD_H__
-// nothing
+#ifdef __GCJ_JNI_IMPL__
+/* If __GCJ_JNI_IMPL__ is defined, then we assume that we're building
+ libgcj itself, and we include functions which should not be exposed
+ to JVMTI users. */
+
+/* The number of event slots needed to keep track of event reporting
+ constraints for an environment. This will only work if the order of
+ events listed in jvmtiEvent and jvmtiEventCallbacks is kept the same
+ (which should not be a problem). */
+#define EVENT_SLOTS \
+ (int)(JVMTI_EVENT_VM_OBJECT_ALLOC - JVMTI_EVENT_VM_INIT + 1)
+
+/* Contents of the jvmtiEnv; but only inside the implementation. */
+#define _CLASSPATH_JVMTIENV_CONTENTS \
+ /* Event handlers registered via SetEventCallbacks */ \
+ jvmtiEventCallbacks callbacks; \
+ \
+ /* Array of event thread for which to report event. */ \
+ /* NULL means all threads. One for each callback. */ \
+ jthread thread[EVENT_SLOTS]; \
+ \
+ /* Array of notification modes for callbacks. */ \
+ /* One for each callback. */ \
+ bool enabled[EVENT_SLOTS];
+
+#endif /* __GCJ_JNI_IMPL__ */
+
#endif /* __GCJ_JVMTI_MD_H__ */
Index: include/jvmti-int.h
===================================================================
--- include/jvmti-int.h (revision 0)
+++ include/jvmti-int.h (revision 0)
@@ -0,0 +1,87 @@
+/* jvmti-int.h -- Internal JVMTI definitions
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+As a special exception, if you link this library with other files to
+produce an executable, this library does not by itself cause the
+resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why the
+executable file might be covered by the GNU General Public License. */
+
+#ifndef __GCJ_JVTMI_INT_H__
+#define __GCJ_JVMTI_INT_H__
+
+/* A macro to map jvmtiEvent to an index in thread[] and enabled[]
+ in the jvmtiEnv. This will only work if the order of events listed
+ in jvmtiEvent and jvmtiEventCallbacks is kept the same (which should
+ not be a problem). */
+#define EVENT_INDEX(jvmtievent) (int)(jvmtievent - JVMTI_EVENT_VM_INIT)
+
+/* A global bit field to help limit the impact of JVMTI on normal
+ operations. Unset fields (events) mean no JVMTI environment requested
+ that event type. */
+struct _gcj_jvmti_events
+{
+ unsigned int VMInit : 1;
+ unsigned int VMDeath : 1;
+ unsigned int ThreadStart : 1;
+ unsigned int ThreadEnd : 1;
+ unsigned int ClassFileLoadHook : 1;
+ unsigned int ClassLoad : 1;
+ unsigned int ClassPrepare : 1;
+ unsigned int VMStart : 1;
+ unsigned int Exception : 1;
+ unsigned int ExceptionCatch : 1;
+ unsigned int SingleStep : 1;
+ unsigned int FramePop : 1;
+ unsigned int Breakpoint : 1;
+ unsigned int FieldAccess : 1;
+ unsigned int FieldModification : 1;
+ unsigned int MethodEntry : 1;
+ unsigned int MethodExit : 1;
+ unsigned int NativeMethodBind : 1;
+ unsigned int CompiledMethodLoad : 1;
+ unsigned int CompiledMethodUnload : 1;
+ unsigned int DynamicCodeGenerated : 1;
+ unsigned int DataDumpRequest : 1;
+ unsigned int reserved72 : 1;
+ unsigned int MonitorWait : 1;
+ unsigned int MonitorWaited : 1;
+ unsigned int MonitorContendedEnter : 1;
+ unsigned int MonitorContendedEntered : 1;
+ unsigned int reserved77 : 1;
+ unsigned int reserved78 : 1;
+ unsigned int reserved79 : 1;
+ unsigned int reserved80 : 1;
+ unsigned int GarbageCollectionStart : 1;
+ unsigned int GarbageCollectionFinish : 1;
+ unsigned int ObjectFree : 1;
+ unsigned int VMObjectAlloc : 1;
+};
+extern struct _gcj_jvmti_events _Jv_JVMTI_RequestedEvents;
+
+/* A macro to test whether an event should be posted to JVMTI.*/
+#define JVMTI_REQUESTED_EVENT(Event) (_Jv_JVMTI_RequestedEvents.Event == 1)
+
+/* Post the event to requesting JVMTI environments.
+
+ For speed, this function should only be called after
+ JVMTI_REQUESTED_EVENT is checked. */
+extern void _Jv_JVMTI_PostEvent (jvmtiEvent type, jthread event_thread, ...);
+#endif __GCJ_JVMTI_INT_H__
Index: jvmti.cc
===================================================================
--- jvmti.cc (revision 116636)
+++ jvmti.cc (working copy)
@@ -15,6 +15,7 @@
#include <java-threads.h>
#include <java-gc.h>
#include <jvmti.h>
+#include "jvmti-int.h"
#include <gcj/method.h>
@@ -32,6 +33,9 @@
#include <java/util/HashMap.h>
#include <java/net/URL.h>
+static void check_enabled_events (void);
+static void check_enabled_event (jvmtiEvent);
+
extern struct JNINativeInterface _Jv_JNIFunctions;
struct _Jv_rawMonitorID
@@ -54,6 +58,9 @@
#define FOREACH_ENVIRONMENT(Ele) \
for (Ele = _jvmtiEnvironments; Ele != NULL; Ele = Ele->next)
+// Global bit field of requested events
+struct _gcj_jvmti_events _Jv_JVMTI_RequestedEvents;
+
// Some commonly-used checks
#define THREAD_DEFAULT_TO_CURRENT(jthread) \
@@ -505,6 +512,9 @@
}
_Jv_Free (env);
+
+ check_enabled_events ();
+
return JVMTI_ERROR_NONE;
}
@@ -649,13 +659,397 @@
return JVMTI_ERROR_NONE;
}
+/* An event is enabled only if it has both an event handler
+ and it is enabled in the environment. */
+static void
+check_enabled_event (jvmtiEvent type)
+{
+ int index = EVENT_INDEX(type); // safe since caller checks this
+
+#define CHECK_EVENT(Event) \
+ do \
+ { \
+ struct jvmti_env_list *e; \
+ FOREACH_ENVIRONMENT (e) \
+ { \
+ if (e->env->enabled[index] && e->env->callbacks.Event != NULL) \
+ { \
+ _Jv_JVMTI_RequestedEvents.Event = 1; \
+ return; /* no need to go any further */ \
+ } \
+ } \
+ _Jv_JVMTI_RequestedEvents.Event = 0; \
+ } \
+ while (0)
+
+ switch (type)
+ {
+ case JVMTI_EVENT_VM_INIT:
+ CHECK_EVENT (VMInit);
+ break;
+
+ case JVMTI_EVENT_VM_DEATH:
+ CHECK_EVENT (VMDeath);
+ break;
+
+ case JVMTI_EVENT_THREAD_START:
+ CHECK_EVENT (ThreadStart);
+ break;
+
+ case JVMTI_EVENT_THREAD_END:
+ CHECK_EVENT (ThreadEnd);
+ break;
+
+ case JVMTI_EVENT_CLASS_FILE_LOAD_HOOK:
+ CHECK_EVENT (ClassFileLoadHook);
+ break;
+
+ case JVMTI_EVENT_CLASS_LOAD:
+ CHECK_EVENT (ClassLoad);
+ break;
+
+ case JVMTI_EVENT_CLASS_PREPARE:
+ CHECK_EVENT (ClassPrepare);
+ break;
+
+ case JVMTI_EVENT_VM_START:
+ CHECK_EVENT (VMStart);
+ break;
+
+ case JVMTI_EVENT_EXCEPTION:
+ CHECK_EVENT (Exception);
+ break;
+
+ case JVMTI_EVENT_EXCEPTION_CATCH:
+ CHECK_EVENT (ExceptionCatch);
+ break;
+
+ case JVMTI_EVENT_SINGLE_STEP:
+ CHECK_EVENT (SingleStep);
+ break;
+
+ case JVMTI_EVENT_FRAME_POP:
+ CHECK_EVENT (FramePop);
+ break;
+
+ case JVMTI_EVENT_BREAKPOINT:
+ CHECK_EVENT (Breakpoint);
+ break;
+
+ case JVMTI_EVENT_FIELD_ACCESS:
+ CHECK_EVENT (FieldAccess);
+ break;
+
+ case JVMTI_EVENT_FIELD_MODIFICATION:
+ CHECK_EVENT (FieldModification);
+ break;
+
+ case JVMTI_EVENT_METHOD_ENTRY:
+ CHECK_EVENT (MethodEntry);
+ break;
+
+ case JVMTI_EVENT_METHOD_EXIT:
+ CHECK_EVENT (MethodExit);
+ break;
+
+ case JVMTI_EVENT_NATIVE_METHOD_BIND:
+ CHECK_EVENT (NativeMethodBind);
+ break;
+
+ case JVMTI_EVENT_COMPILED_METHOD_LOAD:
+ CHECK_EVENT (CompiledMethodLoad);
+ break;
+
+ case JVMTI_EVENT_COMPILED_METHOD_UNLOAD:
+ CHECK_EVENT (CompiledMethodUnload);
+ break;
+
+ case JVMTI_EVENT_DYNAMIC_CODE_GENERATED:
+ CHECK_EVENT (DynamicCodeGenerated);
+ break;
+
+ case JVMTI_EVENT_DATA_DUMP_REQUEST:
+ CHECK_EVENT (DataDumpRequest);
+ break;
+
+ case JVMTI_EVENT_MONITOR_WAIT:
+ CHECK_EVENT (MonitorWait);
+ break;
+
+ case JVMTI_EVENT_MONITOR_WAITED:
+ CHECK_EVENT (MonitorWaited);
+ break;
+
+ case JVMTI_EVENT_MONITOR_CONTENDED_ENTER:
+ CHECK_EVENT (MonitorContendedEnter);
+ break;
+
+ case JVMTI_EVENT_MONITOR_CONTENDED_ENTERED:
+ CHECK_EVENT (MonitorContendedEntered);
+ break;
+
+ case JVMTI_EVENT_GARBAGE_COLLECTION_START:
+ CHECK_EVENT (GarbageCollectionStart);
+ break;
+
+ case JVMTI_EVENT_GARBAGE_COLLECTION_FINISH:
+ CHECK_EVENT (GarbageCollectionFinish);
+ break;
+
+ case JVMTI_EVENT_OBJECT_FREE:
+ CHECK_EVENT (ObjectFree);
+ break;
+
+ case JVMTI_EVENT_VM_OBJECT_ALLOC:
+ CHECK_EVENT (VMObjectAlloc);
+ break;
+
+ default:
+ fprintf (stderr,
+ "libgcj: check_enabled_event for unknown JVMTI event (%d)\n",
+ (int) type);
+ }
+#undef CHECK_EVENT
+}
+
+static void
+check_enabled_events ()
+{
+ check_enabled_event (JVMTI_EVENT_VM_INIT);
+ check_enabled_event (JVMTI_EVENT_VM_DEATH);
+ check_enabled_event (JVMTI_EVENT_THREAD_START);
+ check_enabled_event (JVMTI_EVENT_THREAD_END);
+ check_enabled_event (JVMTI_EVENT_CLASS_FILE_LOAD_HOOK);
+ check_enabled_event (JVMTI_EVENT_CLASS_LOAD);
+ check_enabled_event (JVMTI_EVENT_CLASS_PREPARE);
+ check_enabled_event (JVMTI_EVENT_VM_START);
+ check_enabled_event (JVMTI_EVENT_EXCEPTION);
+ check_enabled_event (JVMTI_EVENT_EXCEPTION_CATCH);
+ check_enabled_event (JVMTI_EVENT_SINGLE_STEP);
+ check_enabled_event (JVMTI_EVENT_FRAME_POP);
+ check_enabled_event (JVMTI_EVENT_BREAKPOINT);
+ check_enabled_event (JVMTI_EVENT_FIELD_ACCESS);
+ check_enabled_event (JVMTI_EVENT_FIELD_MODIFICATION);
+ check_enabled_event (JVMTI_EVENT_METHOD_ENTRY);
+ check_enabled_event (JVMTI_EVENT_METHOD_EXIT);
+ check_enabled_event (JVMTI_EVENT_NATIVE_METHOD_BIND);
+ check_enabled_event (JVMTI_EVENT_COMPILED_METHOD_LOAD);
+ check_enabled_event (JVMTI_EVENT_COMPILED_METHOD_UNLOAD);
+ check_enabled_event (JVMTI_EVENT_DYNAMIC_CODE_GENERATED);
+ check_enabled_event (JVMTI_EVENT_DATA_DUMP_REQUEST);
+ check_enabled_event (JVMTI_EVENT_MONITOR_WAIT);
+ check_enabled_event (JVMTI_EVENT_MONITOR_WAITED);
+ check_enabled_event (JVMTI_EVENT_MONITOR_CONTENDED_ENTER);
+ check_enabled_event (JVMTI_EVENT_MONITOR_CONTENDED_ENTERED);
+ check_enabled_event (JVMTI_EVENT_GARBAGE_COLLECTION_START);
+ check_enabled_event (JVMTI_EVENT_GARBAGE_COLLECTION_FINISH);
+ check_enabled_event (JVMTI_EVENT_OBJECT_FREE);
+ check_enabled_event (JVMTI_EVENT_VM_OBJECT_ALLOC);
+}
+
+static jvmtiError JNICALL
+_Jv_JVMTI_SetEventNotificationMode (jvmtiEnv *env, jvmtiEventMode mode,
+ jvmtiEvent type, jthread event_thread, ...)
+{
+ REQUIRE_PHASE (env, JVMTI_PHASE_ONLOAD | JVMTI_PHASE_LIVE);
+
+ if (event_thread != NULL)
+ {
+ using namespace java::lang;
+ THREAD_CHECK_VALID (event_thread);
+ Thread *t = reinterpret_cast<Thread *> (event_thread);
+ THREAD_CHECK_IS_ALIVE (t);
+ }
+
+ bool enabled;
+ switch (mode)
+ {
+ case JVMTI_DISABLE:
+ enabled = false;
+ break;
+
+ case JVMTI_ENABLE:
+ enabled = true;
+ break;
+
+ default:
+ return JVMTI_ERROR_ILLEGAL_ARGUMENT;
+ }
+
+#define RECORD_EVENT(Event) /* arg not used */ \
+ do \
+ { \
+ env->thread[EVENT_INDEX(type)] = event_thread; \
+ env->enabled[EVENT_INDEX(type)] = enabled; \
+ } \
+ while (0)
+
+ switch (type)
+ {
+ case JVMTI_EVENT_VM_INIT:
+ ILLEGAL_ARGUMENT (event_thread != NULL);
+ RECORD_EVENT (VMInit);
+ break;
+
+ case JVMTI_EVENT_VM_DEATH:
+ ILLEGAL_ARGUMENT (event_thread != NULL);
+ RECORD_EVENT (VMDeath);
+ break;
+
+ case JVMTI_EVENT_THREAD_START:
+ ILLEGAL_ARGUMENT (event_thread != NULL);
+ RECORD_EVENT (ThreadStart);
+ break;
+
+ case JVMTI_EVENT_THREAD_END:
+ RECORD_EVENT (ThreadEnd);
+ break;
+
+ case JVMTI_EVENT_CLASS_FILE_LOAD_HOOK:
+ RECORD_EVENT (ClassFileLoadHook);
+ break;
+
+ case JVMTI_EVENT_CLASS_LOAD:
+ RECORD_EVENT (ClassLoad);
+ break;
+
+ case JVMTI_EVENT_CLASS_PREPARE:
+ RECORD_EVENT (ClassPrepare);
+ break;
+
+ case JVMTI_EVENT_VM_START:
+ ILLEGAL_ARGUMENT (event_thread != NULL);
+ RECORD_EVENT (VMStart);
+ break;
+
+ case JVMTI_EVENT_EXCEPTION:
+ RECORD_EVENT (Exception);
+ break;
+
+ case JVMTI_EVENT_EXCEPTION_CATCH:
+ RECORD_EVENT (ExceptionCatch);
+ break;
+
+ case JVMTI_EVENT_SINGLE_STEP:
+ RECORD_EVENT (SingleStep);
+ break;
+
+ case JVMTI_EVENT_FRAME_POP:
+ RECORD_EVENT (FramePop);
+ break;
+
+ case JVMTI_EVENT_BREAKPOINT:
+ RECORD_EVENT (Breakpoint);
+ break;
+
+ case JVMTI_EVENT_FIELD_ACCESS:
+ RECORD_EVENT (FieldAccess);
+ break;
+
+ case JVMTI_EVENT_FIELD_MODIFICATION:
+ RECORD_EVENT (FieldModification);
+ break;
+
+ case JVMTI_EVENT_METHOD_ENTRY:
+ RECORD_EVENT (MethodEntry);
+ break;
+
+ case JVMTI_EVENT_METHOD_EXIT:
+ RECORD_EVENT (MethodExit);
+ break;
+
+ case JVMTI_EVENT_NATIVE_METHOD_BIND:
+ RECORD_EVENT (NativeMethodBind);
+ break;
+
+ case JVMTI_EVENT_COMPILED_METHOD_LOAD:
+ ILLEGAL_ARGUMENT (event_thread != NULL);
+ RECORD_EVENT (CompiledMethodLoad);
+ break;
+
+ case JVMTI_EVENT_COMPILED_METHOD_UNLOAD:
+ ILLEGAL_ARGUMENT (event_thread != NULL);
+ RECORD_EVENT (CompiledMethodUnload);
+ break;
+
+ case JVMTI_EVENT_DYNAMIC_CODE_GENERATED:
+ ILLEGAL_ARGUMENT (event_thread != NULL);
+ RECORD_EVENT (DynamicCodeGenerated);
+ break;
+
+ case JVMTI_EVENT_DATA_DUMP_REQUEST:
+ ILLEGAL_ARGUMENT (event_thread != NULL);
+ RECORD_EVENT (DataDumpRequest);
+ break;
+
+ case JVMTI_EVENT_MONITOR_WAIT:
+ RECORD_EVENT (MonitorWait);
+ break;
+
+ case JVMTI_EVENT_MONITOR_WAITED:
+ RECORD_EVENT (MonitorWaited);
+ break;
+
+ case JVMTI_EVENT_MONITOR_CONTENDED_ENTER:
+ RECORD_EVENT (MonitorContendedEnter);
+ break;
+
+ case JVMTI_EVENT_MONITOR_CONTENDED_ENTERED:
+ RECORD_EVENT (MonitorContendedEntered);
+ break;
+
+ case JVMTI_EVENT_GARBAGE_COLLECTION_START:
+ RECORD_EVENT (GarbageCollectionStart);
+ break;
+
+ case JVMTI_EVENT_GARBAGE_COLLECTION_FINISH:
+ RECORD_EVENT (GarbageCollectionFinish);
+ break;
+
+ case JVMTI_EVENT_OBJECT_FREE:
+ RECORD_EVENT (ObjectFree);
+ break;
+
+ case JVMTI_EVENT_VM_OBJECT_ALLOC:
+ RECORD_EVENT (VMObjectAlloc);
+ break;
+
+ default:
+ return JVMTI_ERROR_INVALID_EVENT_TYPE;
+ }
+
+ check_enabled_event (type);
+
+ return JVMTI_ERROR_NONE;
+#undef RECORD_EVENT
+}
+
+static jvmtiError JNICALL
+_Jv_JVMTI_SetEventCallbacks (jvmtiEnv *env,
+ const jvmtiEventCallbacks *callbacks,
+ jint size_of_callbacks)
+{
+ REQUIRE_PHASE (env, JVMTI_PHASE_ONLOAD | JVMTI_PHASE_LIVE);
+ ILLEGAL_ARGUMENT (size_of_callbacks < 0);
+
+ // Copy the list of callbacks into the environment
+ memcpy (&env->callbacks, callbacks, sizeof (jvmtiEventCallbacks));
+
+ /* Check which events are now enabeld (JVMTI makes no requirements
+ about the order in which SetEventCallbacks and SetEventNotifications
+ are called. So we must check all events here. */
+ check_enabled_events ();
+
+ return JVMTI_ERROR_NONE;
+}
+
#define RESERVED NULL
#define UNIMPLEMENTED NULL
struct _Jv_jvmtiEnv _Jv_JVMTI_Interface =
{
RESERVED, // reserved1
- UNIMPLEMENTED, // SetEventNotification
+ _Jv_JVMTI_SetEventNotificationMode, // SetEventNotificationMode
RESERVED, // reserved3
UNIMPLEMENTED, // GetAllThreads
_Jv_JVMTI_SuspendThread, // SuspendThread
@@ -775,7 +1169,7 @@
RESERVED, // reserved119
_Jv_JVMTI_SetJNIFunctionTable, // SetJNIFunctionTable
_Jv_JVMTI_GetJNIFunctionTable, // GetJNIFunctionTable
- UNIMPLEMENTED, // SetEventCallbacks
+ _Jv_JVMTI_SetEventCallbacks, // SetEventCallbacks
UNIMPLEMENTED, // GenerateEvents
UNIMPLEMENTED, // GetExtensionFunctions
UNIMPLEMENTED, // GetExtensionEvents
@@ -843,4 +1237,384 @@
{
_jvmtiEnvironments = NULL;
_envListLock = new java::lang::Object ();
+ memset (&_Jv_JVMTI_RequestedEvents, 0, sizeof (struct _gcj_jvmti_events));
}
+
+static void
+post_event (jvmtiEnv *env, jvmtiEvent type, jthread event_thread, ...)
+{
+#define ARG(Type,Name) Type Name = (Type) va_arg (args, Type)
+
+#define GET_BOOLEAN_ARG(Name) \
+ ARG (int, b); \
+ jboolean Name = (b == 0) ? false : true
+
+#define GET_CHAR_ARG(Name) \
+ ARG (int, c); \
+ char Name = static_cast<char> (c)
+
+ va_list args;
+ va_start (args, event_thread);
+ switch (type)
+ {
+ case JVMTI_EVENT_VM_INIT:
+ if (env->callbacks.VMInit != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ env->callbacks.VMInit (env, jni_env, event_thread);
+ }
+ break;
+
+ case JVMTI_EVENT_VM_DEATH:
+ if (env->callbacks.VMDeath != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ env->callbacks.VMDeath (env, jni_env);
+ }
+ break;
+
+ case JVMTI_EVENT_THREAD_START:
+ if (env->callbacks.ThreadStart != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ env->callbacks.ThreadStart (env, jni_env, event_thread);
+ }
+ break;
+
+ case JVMTI_EVENT_THREAD_END:
+ if (env->callbacks.ThreadEnd != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ env->callbacks.ThreadEnd (env, jni_env, event_thread);
+ }
+ break;
+
+ case JVMTI_EVENT_CLASS_FILE_LOAD_HOOK:
+ if (env->callbacks.ClassFileLoadHook != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jclass, class_being_redefined);
+ ARG (jobject, loader);
+ ARG (const char *, name);
+ ARG (jobject, protection_domain);
+ ARG (jint, class_data_len);
+ ARG (const unsigned char *, class_data);
+ ARG (jint *, new_class_data_len);
+ ARG (unsigned char **, new_class_data);
+ env->callbacks.ClassFileLoadHook (env, jni_env,
+ class_being_redefined, loader,
+ name, protection_domain,
+ class_data_len, class_data,
+ new_class_data_len,
+ new_class_data);
+ }
+ break;
+
+ case JVMTI_EVENT_CLASS_LOAD:
+ if (env->callbacks.ClassLoad != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jclass, klass);
+ env->callbacks.ClassLoad (env, jni_env, event_thread, klass);
+ }
+ break;
+
+ case JVMTI_EVENT_CLASS_PREPARE:
+ if (env->callbacks.ClassPrepare != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jclass, klass);
+ env->callbacks.ClassPrepare (env, jni_env, event_thread, klass);
+ }
+ break;
+
+ case JVMTI_EVENT_VM_START:
+ if (env->callbacks.VMStart != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ env->callbacks.VMStart (env, jni_env);
+ }
+ break;
+
+ case JVMTI_EVENT_EXCEPTION:
+ if (env->callbacks.Exception != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jmethodID, method);
+ ARG (jlocation, location);
+ ARG (jobject, exception);
+ ARG (jmethodID, catch_method);
+ ARG (jlocation, catch_location);
+ env->callbacks.Exception (env, jni_env, event_thread, method,
+ location, exception, catch_method,
+ catch_location);
+ }
+ break;
+
+ case JVMTI_EVENT_EXCEPTION_CATCH:
+ if (env->callbacks.ExceptionCatch != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jmethodID, method);
+ ARG (jlocation, location);
+ ARG (jobject, exception);
+ env->callbacks.ExceptionCatch (env, jni_env, event_thread, method,
+ location, exception);
+ }
+ break;
+
+ case JVMTI_EVENT_SINGLE_STEP:
+ if (env->callbacks.SingleStep != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jmethodID, method);
+ ARG (jlocation, location);
+ env->callbacks.SingleStep (env, jni_env, event_thread, method,
+ location);
+ }
+ break;
+
+ case JVMTI_EVENT_FRAME_POP:
+ if (env->callbacks.FramePop != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jmethodID, method);
+ GET_BOOLEAN_ARG (was_popped_by_exception);
+ env->callbacks.FramePop (env, jni_env, event_thread, method,
+ was_popped_by_exception);
+ }
+ break;
+
+ case JVMTI_EVENT_BREAKPOINT:
+ if (env->callbacks.Breakpoint != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jmethodID, method);
+ ARG (jlocation, location);
+ env->callbacks.Breakpoint (env, jni_env, event_thread, method,
+ location);
+ }
+ break;
+
+ case JVMTI_EVENT_FIELD_ACCESS:
+ if (env->callbacks.FieldAccess != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jmethodID, method);
+ ARG (jlocation, location);
+ ARG (jclass, field_class);
+ ARG (jobject, object);
+ ARG (jfieldID, field);
+ env->callbacks.FieldAccess (env, jni_env, event_thread, method,
+ location, field_class, object, field);
+ }
+ break;
+
+ case JVMTI_EVENT_FIELD_MODIFICATION:
+ if (env->callbacks.FieldModification != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jmethodID, method);
+ ARG (jlocation, location);
+ ARG (jclass, field_class);
+ ARG (jobject, object);
+ ARG (jfieldID, field);
+ GET_CHAR_ARG (signature_type);
+ ARG (jvalue, new_value);
+ env->callbacks.FieldModification (env, jni_env, event_thread, method,
+ location, field_class, object,
+ field, signature_type, new_value);
+ }
+ break;
+
+ case JVMTI_EVENT_METHOD_ENTRY:
+ if (env->callbacks.MethodEntry != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jmethodID, method);
+ env->callbacks.MethodEntry (env, jni_env, event_thread, method);
+ }
+ break;
+
+ case JVMTI_EVENT_METHOD_EXIT:
+ if (env->callbacks.MethodExit != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jmethodID, method);
+ GET_BOOLEAN_ARG (was_popped_by_exception);
+ ARG (jvalue, return_value);
+ env->callbacks.MethodExit (env, jni_env, event_thread, method,
+ was_popped_by_exception, return_value);
+ }
+ break;
+
+ case JVMTI_EVENT_NATIVE_METHOD_BIND:
+ if (env->callbacks.NativeMethodBind != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jmethodID, method);
+ ARG (void *, address);
+ ARG (void **, new_address_ptr);
+ env->callbacks.NativeMethodBind (env, jni_env, event_thread, method,
+ address, new_address_ptr);
+ }
+ break;
+
+ case JVMTI_EVENT_COMPILED_METHOD_LOAD:
+ if (env->callbacks.CompiledMethodLoad != NULL)
+ {
+ ARG (jmethodID, method);
+ ARG (jint, code_size);
+ ARG (const void *, code_addr);
+ ARG (jint, map_length);
+ ARG (const jvmtiAddrLocationMap *, map);
+ ARG (const void *, compile_info);
+ env->callbacks.CompiledMethodLoad (env, method, code_size, code_addr,
+ map_length, map, compile_info);
+ }
+ break;
+
+ case JVMTI_EVENT_COMPILED_METHOD_UNLOAD:
+ if (env->callbacks.CompiledMethodUnload != NULL)
+ {
+ ARG (jmethodID, method);
+ ARG (const void *, code_addr);
+ env->callbacks.CompiledMethodUnload (env, method, code_addr);
+ }
+ break;
+
+ case JVMTI_EVENT_DYNAMIC_CODE_GENERATED:
+ if (env->callbacks.DynamicCodeGenerated != NULL)
+ {
+ ARG (const char *, name);
+ ARG (const void *, address);
+ ARG (jint, length);
+ env->callbacks.DynamicCodeGenerated (env, name, address, length);
+ }
+ break;
+
+ case JVMTI_EVENT_DATA_DUMP_REQUEST:
+ if (env->callbacks.DataDumpRequest != NULL)
+ {
+ env->callbacks.DataDumpRequest (env);
+ }
+ break;
+
+ case JVMTI_EVENT_MONITOR_WAIT:
+ if (env->callbacks.MonitorWait != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jobject, object);
+ ARG (jlong, timeout);
+ env->callbacks.MonitorWait (env, jni_env, event_thread, object,
+ timeout);
+ }
+ break;
+
+ case JVMTI_EVENT_MONITOR_WAITED:
+ if (env->callbacks.MonitorWaited != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jobject, object);
+ GET_BOOLEAN_ARG (timed_out);
+ env->callbacks.MonitorWaited (env, jni_env, event_thread, object,
+ timed_out);
+ }
+ break;
+
+ case JVMTI_EVENT_MONITOR_CONTENDED_ENTER:
+ if (env->callbacks.MonitorContendedEnter != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jobject, object);
+ env->callbacks.MonitorContendedEnter (env, jni_env, event_thread,
+ object);
+ }
+ break;
+
+ case JVMTI_EVENT_MONITOR_CONTENDED_ENTERED:
+ if (env->callbacks.MonitorContendedEntered != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jobject, object);
+ env->callbacks.MonitorContendedEnter (env, jni_env, event_thread,
+ object);
+ }
+ break;
+
+ case JVMTI_EVENT_GARBAGE_COLLECTION_START:
+ if (env->callbacks.GarbageCollectionStart != NULL)
+ {
+ env->callbacks.GarbageCollectionStart (env);
+ }
+ break;
+
+ case JVMTI_EVENT_GARBAGE_COLLECTION_FINISH:
+ if (env->callbacks.GarbageCollectionFinish != NULL)
+ {
+ env->callbacks.GarbageCollectionFinish (env);
+ }
+ break;
+
+ case JVMTI_EVENT_OBJECT_FREE:
+ if (env->callbacks.ObjectFree != NULL)
+ {
+ ARG (jlong, tag);
+ env->callbacks.ObjectFree (env, tag);
+ }
+ break;
+
+ case JVMTI_EVENT_VM_OBJECT_ALLOC:
+ if (env->callbacks.VMObjectAlloc != NULL)
+ {
+ ARG (JNIEnv *, jni_env);
+ ARG (jobject, object);
+ ARG (jclass, object_class);
+ ARG (jlong, size);
+ env->callbacks.VMObjectAlloc (env, jni_env, event_thread,
+ object, object_class, size);
+ }
+ break;
+
+ default:
+ fprintf (stderr, "libgcj: post of unknown JVMTI event (%d)\n",
+ (int) type);
+ break;
+ }
+ va_end (args);
+#undef ARG
+#undef GET_BOOLEAN_ARG
+#undef GET_CHAR_ARG
+}
+
+/* Post an event to requesting JVMTI environments
+ *
+ * This function should not be called without consulting
+ * _Jv_JVMTI_RequestedEvents first (for speed). It does no real
+ * harm (other than kill speed), since this function will still
+ * only send the event if it was properly requested by an environment.
+ */
+void
+_Jv_JVMTI_PostEvent (jvmtiEvent type, jthread event_thread, ...)
+{
+ va_list args;
+ va_start (args, event_thread);
+
+ struct jvmti_env_list *e;
+ FOREACH_ENVIRONMENT (e)
+ {
+ /* Events are only posted if the event was explicitly enabled,
+ it has a registered event handler, and the event thread
+ matches (either globally or restricted to a specific thread).
+ Here we check all but the event handler, which will be handled
+ by post_event. */
+ if (e->env->enabled[EVENT_INDEX(type)]
+ && (e->env->thread[EVENT_INDEX(type)] == NULL
+ || e->env->thread[EVENT_INDEX(type)] == event_thread))
+ {
+ post_event (e->env, type, event_thread, args);
+ }
+ }
+
+ va_end (args);
+}
next reply other threads:[~2006-09-01 19:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-01 19:01 Keith Seitz [this message]
2006-09-06 22:26 ` Tom Tromey
2006-09-08 18:53 ` Keith Seitz
2006-09-14 17:53 ` Tom Tromey
2006-09-21 0:26 ` Keith Seitz
2006-09-22 0:23 ` Tom Tromey
2006-09-22 2:13 ` Keith Seitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=44F8836D.90006@redhat.com \
--to=keiths@redhat.com \
--cc=java-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).