* src/vm/Makefile.am (libvm_la_SOURCES): Added above file.
* src/native/native.cpp (resolve_method): Added native_resolved hook.
* src/threads/posix/thread-posix.cpp (threads_startup_thread): Added hooks.
* src/vm/linker.cpp (link_class): Added class_linked hook.
* src/vm/loader.cpp (load_class_from_classbuffer): Added class_loaded hook.
* src/vm/vm.cpp (VM::VM): Added vm_init hook.
* src/vm/jit/patcher-common.cpp (patcher_breakpoint): Added breakpoint hook.
* src/vm/jit/trace.cpp: Added hooks.
* src/cacao/cacao.cpp: Launcher is not allowed to interact with JVMTI.
* src/native/jni.cpp (jni_RegisterNatives): Removed bogus JVMTI events.
* src/native/vm/cldc1.1/java_lang_Object.cpp: Likewise.
* src/native/vm/gnuclasspath/java_lang_VMObject.cpp: Likewise.
#include "native/jni.hpp"
#include "native/native.hpp"
-#if defined(ENABLE_JVMTI)
-# include "native/jvmti/jvmti.h"
-# include "native/jvmti/cacaodbg.h"
-#endif
-
#include "vm/os.hpp"
#include "vm/vm.hpp"
(void) VM_create(&vm, &env, vm_args);
-#if defined(ENABLE_JVMTI)
-# error This should be a JVMTI function.
- Mutex_init(&dbgcomlock);
- if (jvmti) jvmti_set_phase(JVMTI_PHASE_START);
-#endif
-
#if defined(ENABLE_LIBJVM)
libjvm_vm_run = os::dlsym(libjvm_handle, "vm_run");
classinfo* c = LLNI_classinfo_unwrap(clazz);
- /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
- if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
- */
-
NativeMethods& nm = VM::get_current()->get_nativemethods();
nm.register_methods(c->name, methods, nMethods);
- return 0;
+ return 0;
}
#include "vm/exceptions.hpp"
#include "vm/global.h"
#include "vm/globals.hpp"
+#include "vm/hook.hpp"
#include "vm/loader.hpp"
#include "vm/options.h"
#include "vm/os.hpp"
exceptions_throw_unsatisfiedlinkerror(m->name);
}
+ // Hook point just after method resolving finished.
+ Hook::native_resolved(m, symbol, &symbol);
+
return symbol;
}
*/
JNIEXPORT void JNICALL Java_java_lang_Object_wait(JNIEnv *env, jobject _this, jlong timeout)
{
-#if defined(ENABLE_JVMTI)
- /* Monitor Wait */
- if (jvmti) jvmti_MonitorWaiting(true, _this, timeout);
-#endif
-
#if defined(ENABLE_THREADS)
lock_wait_for_object((java_handle_t *) _this, timeout, 0);
#endif
-
-#if defined(ENABLE_JVMTI)
- /* Monitor Waited */
- /* XXX: How do you know if wait timed out ?*/
- if (jvmti) jvmti_MonitorWaiting(false, _this, 0);
-#endif
}
} // extern "C"
*/
JNIEXPORT void JNICALL Java_java_lang_VMObject_wait(JNIEnv* env, jclass clazz, jobject o, jlong ms, jint ns)
{
-#if defined(ENABLE_JVMTI)
- /* Monitor Wait */
- if (jvmti) jvmti_MonitorWaiting(true, o, ms);
-#endif
-
#if defined(ENABLE_THREADS)
lock_wait_for_object(o, ms, ns);
#endif
-
-#if defined(ENABLE_JVMTI)
- /* Monitor Waited */
- /* XXX: How do you know if wait timed out ?*/
- if (jvmti) jvmti_MonitorWaiting(false, o, 0);
-#endif
}
} // extern "C"
#include "vm/exceptions.hpp"
#include "vm/global.h"
#include "vm/globals.hpp"
+#include "vm/hook.hpp"
#include "vm/javaobjects.hpp"
#include "vm/options.h"
#include "vm/os.hpp"
# include "mm/boehm-gc/include/gc.h"
#endif
-#if defined(ENABLE_JVMTI)
-#include "native/jvmti/cacaodbg.h"
-#endif
-
#if defined(__DARWIN__)
/* Darwin has no working semaphore implementation. This one is taken
thread->_global_sp = (Cell *) (intrp_thread_stack + opt_stacksize);
#endif
-#if defined(ENABLE_JVMTI)
- /* fire thread start event */
-
- if (jvmti)
- jvmti_ThreadStartEnd(JVMTI_EVENT_THREAD_START);
-#endif
+ // Hook point just before the threads initial method is executed.
+ Hook::thread_start(t);
DEBUGTHREADS("starting", t);
DEBUGTHREADS("stopping", t);
-#if defined(ENABLE_JVMTI)
- /* fire thread end event */
-
- if (jvmti)
- jvmti_ThreadStartEnd(JVMTI_EVENT_THREAD_END);
-#endif
+ // Hook point just after the threads initial method returned.
+ Hook::thread_end(t);
/* We ignore the return value. */
finalizer.hpp \
globals.cpp \
globals.hpp \
+ hook.hpp \
initialize.cpp \
initialize.hpp \
javaobjects.cpp \
--- /dev/null
+/* src/vm/hook.hpp - hook points inside the VM
+
+ Copyright (C) 2009
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+ This file is part of CACAO.
+
+ This program 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.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+*/
+
+
+#ifndef _HOOK_HPP
+#define _HOOK_HPP
+
+#include "config.h"
+
+
+/**
+ * Hook points are inline functions acting as probes scattered throughout
+ * several VM subsystems. They can be used to implement event generation
+ * or statistics gathering without polluting the source code. Hence all
+ * compiler macro and runtime checks should be done in this file. One
+ * example of where hooks are useful is JVMTI event firing.
+ */
+namespace Hook {
+ void breakpoint (Breakpoint *bp);
+ void class_linked (classinfo *c);
+ void class_loaded (classinfo *c);
+ void method_enter (methodinfo *m);
+ void method_exit (methodinfo *m);
+ void method_unwind (methodinfo *m);
+ void native_resolved(methodinfo *m, void *symbol, void **symbolptr);
+ void thread_start (threadobject *t);
+ void thread_end (threadobject *t);
+ void vm_init ();
+}
+
+
+inline void Hook::breakpoint(Breakpoint *bp)
+{
+#if defined(ENABLE_JVMTI)
+ methodinfo* m = bp->method;
+ int32_t l = bp->location;
+
+ log_message_method("JVMTI: Reached breakpoint in method ", m);
+ log_println("JVMTI: Reached breakpoint at location %d", l);
+#endif
+}
+
+inline void Hook::class_linked(classinfo *c)
+{
+ /* nop */
+}
+
+inline void Hook::class_loaded(classinfo *c)
+{
+ /* nop */
+}
+
+inline void Hook::method_enter(methodinfo *m)
+{
+ /* nop */
+}
+
+inline void Hook::method_exit(methodinfo *m)
+{
+ /* nop */
+}
+
+inline void Hook::method_unwind(methodinfo *m)
+{
+ /* nop */
+}
+
+inline void Hook::native_resolved(methodinfo *m, void *symbol, void **symbolptr)
+{
+ /* nop */
+}
+
+inline void Hook::thread_start(threadobject *t)
+{
+ /* nop */
+}
+
+inline void Hook::thread_end(threadobject *t)
+{
+ /* nop */
+}
+
+inline void Hook::vm_init()
+{
+ /* nop */
+}
+
+
+#endif /* _HOOK_HPP */
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c++
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
#include "vm/breakpoint.hpp"
#include "vm/exceptions.hpp"
+#include "vm/hook.hpp"
#include "vm/initialize.hpp"
#include "vm/options.h"
#include "vm/os.hpp"
// Get stuff from the patcher reference.
Breakpoint* breakp = (Breakpoint*) pr->ref;
-#if defined(ENABLE_JVMTI)
- methodinfo* m = breakp->method;
- int32_t l = breakp->location;
-
- log_message_method("JVMTI: Reached breakpoint in method ", m);
- log_println("JVMTI: Reached breakpoint at location %d", l);
-#endif
+ // Hook point when a breakpoint was triggered.
+ Hook::breakpoint(breakp);
// In case the breakpoint wants to be kept active, we simply
// fail to "patch" at this point.
#include "vm/array.hpp"
#include "vm/global.h"
#include "vm/globals.hpp"
+#include "vm/hook.hpp"
#include "vm/javaobjects.hpp"
#include "vm/options.h"
#include "vm/string.hpp"
return;
#endif
+ // Hook point on entry into Java method.
+ Hook::method_enter(m);
+
md = m->parseddesc;
/* calculate message length */
return;
#endif
+ // Hook point upon exit from Java method.
+ Hook::method_exit(m);
+
md = m->parseddesc;
/* outdent the log message */
#include "vm/classcache.hpp"
#include "vm/exceptions.hpp"
#include "vm/globals.hpp"
+#include "vm/hook.hpp"
#include "vm/loader.hpp"
#include "vm/options.h"
#include "vm/primitive.hpp"
RT_TIMING_TIME_DIFF(time_start,time_end,RT_TIMING_LINK_TOTAL);
+ // Hook point just after a class was linked.
+ Hook::class_linked(r);
+
return r;
}
#include "vm/field.hpp"
#include "vm/global.h"
#include "vm/globals.hpp"
+#include "vm/hook.hpp"
#include "vm/javaobjects.hpp"
#include "vm/linker.hpp"
#include "vm/loader.hpp"
#include "vm/jit/stubs.hpp"
-#if defined(ENABLE_JVMTI)
-# include "native/jvmti/cacaodbg.h"
-#endif
-
/* global variables ***********************************************************/
printf("]\n");
}
-#if defined(ENABLE_JVMTI)
- /* fire Class Load JVMTI event */
- if (jvmti) jvmti_ClassLoadPrepare(false, c);
-#endif
-
-
return c;
}
c->state = (c->state & ~CLASS_LOADING) | CLASS_LOADED;
-#if defined(ENABLE_JVMTI)
- /* fire Class Prepare JVMTI event */
-
- if (jvmti)
- jvmti_ClassLoadPrepare(true, c);
-#endif
-
#if !defined(NDEBUG)
if (loadverbose)
log_message_class("Loading done class: ", c);
#endif
+ // Hook point just after a class was loaded.
+ Hook::class_loaded(c);
+
return c;
}
#include "vm/finalizer.hpp"
#include "vm/global.h"
#include "vm/globals.hpp"
+#include "vm/hook.hpp"
#include "vm/initialize.hpp"
#include "vm/options.h"
#include "vm/os.hpp"
// Set the VM inittime.
_inittime = builtin_currenttimemillis();
+ // Hook point after the VM is initialized.
+ Hook::vm_init();
+
// Print the run-time VM configuration after all stuff is set and
// the VM is initialized.
if (opt_PrintConfig)