Changes: Christian Thalinger
- $Id: native.c 4357 2006-01-22 23:33:38Z twisti $
+ $Id: native.c 5200 2006-07-31 16:30:33Z twisti $
*/
#include <assert.h>
-#if !defined(ENABLE_STATICVM)
+#if !defined(WITH_STATIC_CLASSPATH)
# include <ltdl.h>
#endif
#include "vm/types.h"
-#include "cacao/cacao.h"
#include "mm/memory.h"
#include "native/jni.h"
#include "native/native.h"
#include "native/include/java_lang_Throwable.h"
+
+#if defined(ENABLE_THREADS)
+# include "threads/native/lock.h"
+#else
+# include "threads/none/lock.h"
+#endif
+
#include "toolbox/logging.h"
#include "vm/builtin.h"
#include "vm/exceptions.h"
#include "vm/options.h"
#include "vm/resolve.h"
#include "vm/stringlocal.h"
+#include "vm/vm.h"
#include "vm/jit/asmpart.h"
#include "vm/jit/jit.h"
+#if defined(ENABLE_JVMTI)
+#include "native/jvmti/cacaodbg.h"
+#endif
+
/* include table of native functions ******************************************/
#include "native/include/gnu_classpath_VMStackWalker.h"
#include "native/include/gnu_classpath_VMSystemProperties.h"
+#include "native/include/gnu_java_lang_management_VMClassLoadingMXBeanImpl.h"
+#include "native/include/gnu_java_lang_management_VMMemoryMXBeanImpl.h"
+#include "native/include/gnu_java_lang_management_VMRuntimeMXBeanImpl.h"
#include "native/include/java_lang_Class.h"
#include "native/include/java_lang_Object.h"
#include "native/include/java_lang_VMClass.h"
#include "native/include/java_lang_VMSystem.h"
#include "native/include/java_lang_VMThread.h"
#include "native/include/java_lang_VMThrowable.h"
+#include "native/include/java_lang_management_VMManagementFactory.h"
#include "native/include/java_lang_reflect_Constructor.h"
#include "native/include/java_lang_reflect_Field.h"
#include "native/include/java_lang_reflect_Method.h"
#include "native/include/java_lang_reflect_VMProxy.h"
#include "native/include/java_security_VMAccessController.h"
-#if defined(ENABLE_STATICVM)
+#if defined(ENABLE_JVMTI)
+#include "native/include/gnu_classpath_jdwp_event_EventRequest.h"
+#include "native/include/java_nio_ByteBuffer.h"
+#include "native/include/gnu_classpath_jdwp_VMVirtualMachine.h"
+#include "native/include/gnu_classpath_jdwp_VMFrame.h"
+#include "native/include/gnu_classpath_jdwp_VMMethod.h"
+#endif
+
+#if defined(WITH_STATIC_CLASSPATH)
/* these are required to prevent compiler warnings */
#include "native/nativetable.inc"
-#else /* defined(ENABLE_STATICVM) */
+#else /* defined(WITH_STATIC_CLASSPATH) */
-/* Ensure that symbols for functions implemented within CACAO are used and */
-/* exported to dlopen. */
+/* Ensure that symbols for functions implemented within CACAO are used
+ and exported to dlopen. */
static functionptr dummynativetable[] = {
(functionptr) Java_gnu_classpath_VMStackWalker_getClassContext,
(functionptr) Java_gnu_classpath_VMSystemProperties_preInit,
+ (functionptr) Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_getLoadedClassCount,
+ (functionptr) Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_getUnloadedClassCount,
+ (functionptr) Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_isVerbose,
+ (functionptr) Java_gnu_java_lang_management_VMClassLoadingMXBeanImpl_setVerbose,
+
+ (functionptr) Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getHeapMemoryUsage,
+ (functionptr) Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getNonHeapMemoryUsage,
+ (functionptr) Java_gnu_java_lang_management_VMMemoryMXBeanImpl_getObjectPendingFinalizationCount,
+ (functionptr) Java_gnu_java_lang_management_VMMemoryMXBeanImpl_isVerbose,
+ (functionptr) Java_gnu_java_lang_management_VMMemoryMXBeanImpl_setVerbose,
+
+ (functionptr) Java_gnu_java_lang_management_VMRuntimeMXBeanImpl_getInputArguments,
+ (functionptr) Java_gnu_java_lang_management_VMRuntimeMXBeanImpl_getStartTime,
+
(functionptr) Java_java_lang_VMClass_isInstance,
(functionptr) Java_java_lang_VMClass_isAssignableFrom,
(functionptr) Java_java_lang_VMClass_isInterface,
(functionptr) Java_java_lang_VMThrowable_fillInStackTrace,
(functionptr) Java_java_lang_VMThrowable_getStackTrace,
- (functionptr) Java_java_lang_reflect_Constructor_getModifiers,
+ (functionptr) Java_java_lang_management_VMManagementFactory_getMemoryPoolNames,
+ (functionptr) Java_java_lang_management_VMManagementFactory_getMemoryManagerNames,
+ (functionptr) Java_java_lang_management_VMManagementFactory_getGarbageCollectorNames,
+
+ (functionptr) Java_java_lang_reflect_Constructor_getModifiersInternal,
(functionptr) Java_java_lang_reflect_Constructor_constructNative,
- (functionptr) Java_java_lang_reflect_Field_getModifiers,
+ (functionptr) Java_java_lang_reflect_Field_getModifiersInternal,
(functionptr) Java_java_lang_reflect_Field_getType,
(functionptr) Java_java_lang_reflect_Field_get,
(functionptr) Java_java_lang_reflect_Field_getBoolean,
(functionptr) Java_java_lang_reflect_Field_setFloat,
(functionptr) Java_java_lang_reflect_Field_setDouble,
- (functionptr) Java_java_lang_reflect_Method_getModifiers,
+ (functionptr) Java_java_lang_reflect_Method_getModifiersInternal,
(functionptr) Java_java_lang_reflect_Method_getReturnType,
(functionptr) Java_java_lang_reflect_Method_getParameterTypes,
(functionptr) Java_java_lang_reflect_Method_getExceptionTypes,
(functionptr) Java_java_lang_reflect_VMProxy_generateProxyClass,
(functionptr) Java_java_security_VMAccessController_getStack,
+
+#if defined(ENABLE_JVMTI)
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_suspendThread,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_resumeThread,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getSuspendCount,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getAllLoadedClassesCount,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getClassStatus,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getAllClassMethods,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getClassMethod,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getFrames,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getFrame,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getFrameCount,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getThreadStatus,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getLoadRequests,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_executeMethod,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getSourceFile,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_registerEvent,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_unregisterEvent,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_clearEvents,
+ (functionptr) Java_gnu_classpath_jdwp_VMVirtualMachine_getAllLoadedClasses,
+ (functionptr) Java_gnu_classpath_jdwp_VMFrame_setValue,
+ (functionptr) Java_gnu_classpath_jdwp_VMFrame_getValue,
+ (functionptr) Java_gnu_classpath_jdwp_VMMethod_getName,
+ (functionptr) Java_gnu_classpath_jdwp_VMMethod_getSignature,
+ (functionptr) Java_gnu_classpath_jdwp_VMMethod_getModifiers,
+ (functionptr) Java_gnu_classpath_jdwp_VMMethod_getLineTable,
+ (functionptr) Java_gnu_classpath_jdwp_VMMethod_getVariableTable
+#endif
+
};
-#endif /* defined(ENABLE_STATICVM) */
+#endif /* defined(WITH_STATIC_CLASSPATH) */
/* tables for methods *********************************************************/
-#ifdef ENABLE_STATICVM
+#if defined(WITH_STATIC_CLASSPATH)
#define NATIVETABLESIZE (sizeof(nativetable)/sizeof(struct nativeref))
/* table for fast string comparison */
/* global variables ***********************************************************/
-#if !defined(ENABLE_STATICVM)
-static hashtable hashtable_library;
+#if !defined(WITH_STATIC_CLASSPATH)
+static hashtable *hashtable_library;
static lt_dlhandle mainhandle;
#endif
bool native_init(void)
{
-#if !defined(ENABLE_STATICVM)
+#if !defined(WITH_STATIC_CLASSPATH)
void *p;
- /* We need to access the dummy native table, not only to remove a warning */
- /* but to be sure that the table is not optimized away (gcc does this */
- /* since 3.4). */
+ /* We need to access the dummy native table, not only to remove a
+ warning but to be sure that the table is not optimized away
+ (gcc does this since 3.4). */
p = &dummynativetable;
/* initialize library hashtable, 10 entries should be enough */
- hashtable_create(&hashtable_library, 10);
+ hashtable_library = NEW(hashtable);
+ hashtable_create(hashtable_library, 10);
#endif
/* everything's ok */
*******************************************************************************/
-#if !defined(ENABLE_STATICVM)
+#if !defined(WITH_STATIC_CLASSPATH)
void native_hashtable_library_add(utf *filename, java_objectheader *loader,
lt_dlhandle handle)
{
u4 key; /* hashkey */
u4 slot; /* slot in hashtable */
+ LOCK_MONITOR_ENTER(hashtable_library->header);
+
/* normally addresses are aligned to 4, 8 or 16 bytes */
key = ((u4) (ptrint) loader) >> 4; /* align to 16-byte boundaries */
- slot = key & (hashtable_library.size - 1);
- le = hashtable_library.ptr[slot];
+ slot = key & (hashtable_library->size - 1);
+ le = hashtable_library->ptr[slot];
/* search external hash chain for the entry */
/* no loader found? create a new entry */
- if (!le) {
+ if (le == NULL) {
le = NEW(hashtable_library_loader_entry);
- le->loader = loader;
+ le->loader = loader;
le->namelink = NULL;
/* insert entry into hashtable */
le->hashlink =
- (hashtable_library_loader_entry *) hashtable_library.ptr[slot];
- hashtable_library.ptr[slot] = le;
+ (hashtable_library_loader_entry *) hashtable_library->ptr[slot];
+ hashtable_library->ptr[slot] = le;
/* update number of hashtable-entries */
- hashtable_library.entries++;
+ hashtable_library->entries++;
}
ne = le->namelink;
while (ne) {
- if (ne->name == filename)
+ if (ne->name == filename) {
+ LOCK_MONITOR_EXIT(hashtable_library->header);
+
return;
+ }
ne = ne->hashlink; /* next element in external chain */
}
ne = NEW(hashtable_library_name_entry);
- ne->name = filename;
+ ne->name = filename;
ne->handle = handle;
/* insert entry into external chain */
ne->hashlink = le->namelink;
le->namelink = ne;
+
+ LOCK_MONITOR_EXIT(hashtable_library->header);
}
-#endif /* !defined(ENABLE_STATICVM) */
+#endif /* !defined(WITH_STATIC_CLASSPATH) */
/* native_hashtable_library_find ***********************************************
*******************************************************************************/
-#if !defined(ENABLE_STATICVM)
+#if !defined(WITH_STATIC_CLASSPATH)
hashtable_library_name_entry *native_hashtable_library_find(utf *filename,
java_objectheader *loader)
{
/* normally addresses are aligned to 4, 8 or 16 bytes */
key = ((u4) (ptrint) loader) >> 4; /* align to 16-byte boundaries */
- slot = key & (hashtable_library.size - 1);
- le = hashtable_library.ptr[slot];
+ slot = key & (hashtable_library->size - 1);
+ le = hashtable_library->ptr[slot];
/* search external hash chain for the entry */
return ne;
}
-#endif /* !defined(ENABLE_STATICVM) */
+#endif /* !defined(WITH_STATIC_CLASSPATH) */
/* native_findfunction *********************************************************
*******************************************************************************/
-#if defined(ENABLE_STATICVM)
+#if defined(WITH_STATIC_CLASSPATH)
functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
bool isstatic)
{
return NULL;
}
-#endif /* defined(ENABLE_STATICVM) */
+#endif /* defined(WITH_STATIC_CLASSPATH) */
/* native_make_overloaded_function *********************************************
*******************************************************************************/
-#if !defined(ENABLE_STATICVM)
+#if !defined(WITH_STATIC_CLASSPATH)
static char *native_make_overloaded_function(char *name, utf *desc)
{
char *newname;
if (opt_verbosejni) {
printf("[Dynamic-linking native method ");
- utf_display_classname(m->class->name);
+ utf_display_printable_ascii_classname(m->class->name);
printf(".");
- utf_display(m->name);
+ utf_display_printable_ascii(m->name);
printf(" ... ");
}
/* calculate length of native function name */
- namelen = strlen("Java_") + utf_strlen(m->class->name) + strlen("_") +
- utf_strlen(m->name) + strlen("0");
+ namelen = strlen("Java_") + utf_get_number_of_u2s(m->class->name) + strlen("_") +
+ utf_get_number_of_u2s(m->name) + strlen("0");
/* check for underscores in class name */
newname = native_make_overloaded_function(name, m->descriptor);
- /* check the library hash entries of the classloader of the methods's */
- /* class */
+ /* check the library hash entries of the classloader of the
+ methods's class */
sym = NULL;
/* normally addresses are aligned to 4, 8 or 16 bytes */
key = ((u4) (ptrint) m->class->classloader) >> 4; /* align to 16-byte */
- slot = key & (hashtable_library.size - 1);
- le = hashtable_library.ptr[slot];
+ slot = key & (hashtable_library->size - 1);
+ le = hashtable_library->ptr[slot];
/* iterate through loaders in this hash slot */
- while (le && !sym) {
+ while ((le != NULL) && (sym == NULL)) {
/* iterate through names in this loader */
ne = le->namelink;
- while (ne && !sym) {
+ while ((ne != NULL) && (sym == NULL)) {
sym = lt_dlsym(ne->handle, name);
- if (!sym)
+ if (sym == NULL)
sym = lt_dlsym(ne->handle, newname);
ne = ne->hashlink;
le = le->hashlink;
}
- if (sym)
+ if (sym != NULL)
if (opt_verbosejni)
printf("JNI ]\n");
- /* if not found, try to find the native function symbol in the main */
- /* program */
+ /* If not found, try to find the native function symbol in the
+ main program. */
- if (!sym) {
+ if (sym == NULL) {
sym = lt_dlsym(mainhandle, name);
- if (!sym)
+ if (sym == NULL)
sym = lt_dlsym(mainhandle, newname);
- if (sym)
+ if (sym != NULL)
if (opt_verbosejni)
printf("internal ]\n");
}
+#if defined(ENABLE_JVMTI)
+ /* fire Native Method Bind event */
+ if (jvmti) jvmti_NativeMethodBind(m, sym, &sym);
+#endif
+
/* no symbol found? throw exception */
- if (!sym)
+ if (sym == NULL) {
+ if (opt_verbosejni)
+ printf("failed ]\n");
+
*exceptionptr =
new_exception_utfmessage(string_java_lang_UnsatisfiedLinkError,
m->name);
+ }
/* release memory */
return (functionptr) (ptrint) sym;
}
-#endif /* !defined(ENABLE_STATICVM) */
+#endif /* !defined(WITH_STATIC_CLASSPATH) */
/* native_new_and_init *********************************************************
/* call initializer */
- ASM_CALLJAVAFUNCTION(m, o, NULL, NULL, NULL);
+ (void) vm_call_method(m, o);
return o;
}
/* call initializer */
- ASM_CALLJAVAFUNCTION(m, o, s, NULL, NULL);
+ (void) vm_call_method(m, o, s);
return o;
}
/* call initializer */
- ASM_CALLJAVAFUNCTION(m, o, (void *) (ptrint) i, NULL, NULL);
+ (void) vm_call_method(m, o, i);
return o;
}
/* call initializer */
- ASM_CALLJAVAFUNCTION(m, o, t, NULL, NULL);
+ (void) vm_call_method(m, o, t);
return o;
}