#include "vm/types.h"
-#include "mm/gc-common.h"
+#include "mm/gc.hpp"
#include "mm/memory.h"
#include "native/jni.h"
#include "vm/exceptions.h"
#include "vm/global.h"
#include "vm/initialize.h"
-#include "vm/primitive.h"
+#include "vm/primitive.hpp"
#include "vm/resolve.h"
#include "vm/stringlocal.h"
-#include "vm/vm.h"
+#include "vm/vm.hpp"
#include "vm/jit/argument.h"
#include "vm/jit/asmpart.h"
/* debug **********************************************************************/
#if !defined(NDEBUG)
-# define TRACEJNICALLS(text) \
+
+# define TRACEJNICALLS(x) \
do { \
if (opt_TraceJNICalls) { \
- log_println text; \
+ log_println x; \
} \
} while (0)
+
+# define TRACEJNICALLSENTER(x) \
+ do { \
+ if (opt_TraceJNICalls) { \
+ log_start(); \
+ log_print x; \
+ } \
+ } while (0)
+
+# define TRACEJNICALLSEXIT(x) \
+ do { \
+ if (opt_TraceJNICalls) { \
+ log_print x; \
+ log_finish(); \
+ } \
+ } while (0)
+
#else
-# define TRACEJNICALLS(text)
+
+# define TRACEJNICALLS(x)
+# define TRACEJNICALLSENTER(x)
+# define TRACEJNICALLSEXIT(x)
+
#endif
*******************************************************************************/
-jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
+jobject jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
{
java_handle_t *o;
classinfo *c;
methodinfo *m;
va_list ap;
- STATISTICS(jniinvokation());
+ TRACEJNICALLSENTER(("jni_NewObject(env=%p, clazz=%p, methodID=%p, ...)", env, clazz, methodID));
c = LLNI_classinfo_unwrap(clazz);
m = (methodinfo *) methodID;
_Jv_jni_CallVoidMethod(o, LLNI_vftbl_direct(o), m, ap);
va_end(ap);
+ TRACEJNICALLSEXIT(("->%p", o));
+
return jni_NewLocalRef(env, (jobject) o);
}
{
STATISTICS(jniinvokation());
- *vm = (JavaVM *) _Jv_jvm;
+ *vm = VM_get_javavm();
return 0;
}
*******************************************************************************/
-jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
+jobject jni_NewGlobalRef(JNIEnv* env, jobject obj)
{
hashtable_global_ref_entry *gre;
u4 key; /* hashkey */
u4 slot; /* slot in hashtable */
java_handle_t *o;
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("jni_NewGlobalRef(env=%p, obj=%p)", env, obj));
o = (java_handle_t *) obj;
/* global ref not found, create a new one */
if (gre == NULL) {
- gre = NEW(hashtable_global_ref_entry);
+ gre = GCNEW_UNCOLLECTABLE(hashtable_global_ref_entry, 1);
#if defined(ENABLE_GC_CACAO)
/* register global ref with the GC */
*******************************************************************************/
-void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
+void jni_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
{
hashtable_global_ref_entry *gre;
hashtable_global_ref_entry *prevgre;
u4 slot; /* slot in hashtable */
java_handle_t *o;
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("jni_DeleteGlobalRef(env=%p, globalRef=%p)", env, globalRef));
o = (java_handle_t *) globalRef;
gc_reference_unregister(&(gre->o));
#endif
- FREE(gre, hashtable_global_ref_entry);
+ GCFREE(gre);
}
LLNI_CRITICAL_END;
gre = gre->hashlink; /* next element in external chain */
}
- log_println("JNI-DeleteGlobalRef: global reference not found");
+ log_println("jni_DeleteGlobalRef: Global reference not found.");
LLNI_CRITICAL_END;
*******************************************************************************/
-jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
+jobject jni_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
{
#if defined(ENABLE_JAVASE)
# if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
gnu_classpath_Pointer32 *paddress;
# endif
- TRACEJNICALLS(("_Jv_JNI_NewDirectByteBuffer(env=%p, address=%p, capacity=%ld", env, address, capacity));
+ TRACEJNICALLSENTER(("jni_NewDirectByteBuffer(env=%p, address=%p, capacity=%ld)", env, address, capacity));
/* alocate a gnu.classpath.Pointer{32,64} object */
/* add local reference and return the value */
+ TRACEJNICALLSEXIT(("->%p", nbuf));
+
return jni_NewLocalRef(env, nbuf);
# elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
int64_t addr;
int32_t cap;
- TRACEJNICALLS(("_Jv_JNI_NewDirectByteBuffer(env=%p, address=%p, capacity=%ld", env, address, capacity));
+ TRACEJNICALLSENTER(("jni_NewDirectByteBuffer(env=%p, address=%p, capacity=%ld)", env, address, capacity));
/* Be paranoid about address sign-extension. */
/* Add local reference and return the value. */
+ TRACEJNICALLSEXIT(("->%p", o));
+
return jni_NewLocalRef(env, o);
# else
# endif
#else
- vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
+ vm_abort("jni_NewDirectByteBuffer: Not implemented in this configuration.");
/* keep compiler happy */
TRACEJNICALLS(("_Jv_JNI_DestroyJavaVM(vm=%p)", vm));
- if (vm_created == false)
+ if (VM_is_created() == false)
return JNI_ERR;
status = vm_destroy(vm);
result = thread_current_is_attached();
if (result == true) {
- *p_env = _Jv_env;
+ *p_env = VM_get_jnienv();
return JNI_OK;
}
return JNI_EVERSION;
}
- if (!threads_attach_current_thread(vm_aargs, false))
+ if (!thread_attach_current_external_thread(vm_aargs, false))
return JNI_ERR;
if (!localref_table_init())
return JNI_ERR;
#endif
- *p_env = _Jv_env;
+ *p_env = VM_get_jnienv();
return JNI_OK;
}
-jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
+jint jni_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
{
int result;
- TRACEJNICALLS(("_Jv_JNI_AttachCurrentThread(vm=%p, p_env=%p, thr_args=%p)", vm, p_env, thr_args));
+ TRACEJNICALLS(("jni_AttachCurrentThread(vm=%p, p_env=%p, thr_args=%p)", vm, p_env, thr_args));
- if (vm_created == false)
+ if (VM_is_created() == false)
return JNI_ERR;
result = jni_attach_current_thread(p_env, thr_args, false);
*******************************************************************************/
-jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
+jint jni_DetachCurrentThread(JavaVM *vm)
{
#if defined(ENABLE_THREADS)
- threadobject *t;
- bool result;
-
- TRACEJNICALLS(("_Jv_JNI_DetachCurrentThread(vm=%p)", vm));
+ bool result;
- t = thread_get_current();
+ TRACEJNICALLS(("jni_DetachCurrentThread(vm=%p)", vm));
- /* Sanity check. */
-
- assert(t != NULL);
-
- /* If the given thread has already been detached, this operation
+ /* If the current thread has already been detached, this operation
is a no-op. */
- result = thread_is_attached(t);
+ result = thread_current_is_attached();
if (result == false)
return true;
if (!localref_table_destroy())
return JNI_ERR;
- if (!threads_detach_thread(t))
+ if (!thread_detach_current_external_thread())
return JNI_ERR;
#endif
{
TRACEJNICALLS(("jni_GetEnv(vm=%p, env=%p, version=%d)", vm, env, version));
- if (vm_created == false) {
+ if (VM_is_created() == false) {
*env = NULL;
return JNI_EDETACHED;
}
/* Check the JNI version. */
if (jni_version_check(version) == true) {
- *env = _Jv_env;
+ *env = VM_get_jnienv();
return JNI_OK;
}
*******************************************************************************/
-jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
+jint jni_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
{
int result;
- TRACEJNICALLS(("_Jv_JNI_AttachCurrentThreadAsDaemon(vm=%p, penv=%p, args=%p)", vm, penv, args));
+ TRACEJNICALLS(("jni_AttachCurrentThreadAsDaemon(vm=%p, penv=%p, args=%p)", vm, penv, args));
- if (vm_created == false)
+ if (VM_is_created() == false)
return JNI_ERR;
result = jni_attach_current_thread(penv, args, true);
NULL,
_Jv_JNI_DestroyJavaVM,
- _Jv_JNI_AttachCurrentThread,
- _Jv_JNI_DetachCurrentThread,
+ jni_AttachCurrentThread,
+ jni_DetachCurrentThread,
jni_GetEnv,
- _Jv_JNI_AttachCurrentThreadAsDaemon
+ jni_AttachCurrentThreadAsDaemon
};
jni_PushLocalFrame,
jni_PopLocalFrame,
- _Jv_JNI_NewGlobalRef,
- _Jv_JNI_DeleteGlobalRef,
+ jni_NewGlobalRef,
+ jni_DeleteGlobalRef,
jni_DeleteLocalRef,
_Jv_JNI_IsSameObject,
jni_NewLocalRef,
jni_EnsureLocalCapacity,
_Jv_JNI_AllocObject,
- _Jv_JNI_NewObject,
+ jni_NewObject,
_Jv_JNI_NewObjectV,
_Jv_JNI_NewObjectA,
/* New JNI 1.4 functions. */
- _Jv_JNI_NewDirectByteBuffer,
+ jni_NewDirectByteBuffer,
_Jv_JNI_GetDirectBufferAddress,
_Jv_JNI_GetDirectBufferCapacity,
/* We currently only support 1 VM running. */
- vmBuf[0] = (JavaVM *) _Jv_jvm;
+ vmBuf[0] = VM_get_javavm();
*nVMs = 1;
return JNI_OK;
/* actually create the JVM */
- if (!vm_createjvm(p_vm, p_env, vm_args))
+ if (!VM_create(p_vm, p_env, vm_args))
return JNI_ERR;
return JNI_OK;