You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ar...@apache.org on 2006/01/03 00:43:12 UTC
svn commit: r365472 - in
/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm:
jc/Makefile.am libjc/Makefile.am libjc/definitions.h libjc/native_lib.c
libjc/structures.h
Author: archie
Date: Mon Jan 2 15:43:08 2006
New Revision: 365472
URL: http://svn.apache.org/viewcvs?rev=365472&view=rev
Log:
Convert libjc from a shared library to a static library. This has two benefits:
- More portable (it no longer needs to dlopen() itself).
- Faster execution (position-independent code not required).
The downside is that the new list (in libjc/native_lib.c) of all native methods
implemented by code in the libjc/native subdirectory must be manually kept
up to date.
Modified:
incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/jc/Makefile.am
incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/Makefile.am
incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/definitions.h
incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native_lib.c
incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/structures.h
Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/jc/Makefile.am
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/jc/Makefile.am?rev=365472&r1=365471&r2=365472&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/jc/Makefile.am (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/jc/Makefile.am Mon Jan 2 15:43:08 2006
@@ -1,10 +1,10 @@
-## $Id: Makefile.am,v 1.4 2005/01/13 04:44:59 archiecobbs Exp $
+## $Id$
bin_PROGRAMS= jc
jc_SOURCES= main.c
-jc_LDADD= ../libjc/libjc.la
+jc_LDADD= ../libjc/libjc.a
AM_CFLAGS= $(CFLAGS) @JC_CFLAGS@
Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/Makefile.am
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/Makefile.am?rev=365472&r1=365471&r2=365472&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/Makefile.am (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/Makefile.am Mon Jan 2 15:43:08 2006
@@ -2,12 +2,10 @@
SUBDIRS= native arch
-lib_LTLIBRARIES= libjc.la
-
-libjc_la_LDFLAGS= -version-info @LIBRARY_VERSION@
+lib_LIBRARIES= libjc.a
# Standard source files
-libjc_la_SOURCES= \
+libjc_a_SOURCES= \
analysis.c \
array.c \
bootstrap.c \
@@ -62,7 +60,7 @@
mv interp.lo $@
# Java native method source files
-libjc_la_SOURCES+= native/gnu_classpath_VMStackWalker.c \
+libjc_a_SOURCES+= native/gnu_classpath_VMStackWalker.c \
native/gnu_classpath_VMSystemProperties.c \
native/java_lang_VMClass.c \
native/java_lang_VMClassLoader.c \
@@ -79,10 +77,10 @@
native/org_dellroad_jc_vm_FinalizerThread.c
# Architecture specific source files
-libjc_la_SOURCES+= arch/@JC_ARCH@/arch_functions.c
+libjc_a_SOURCES+= arch/@JC_ARCH@/arch_functions.c
# Header files
-libjc_la_SOURCES+= cf_parse.h \
+libjc_a_SOURCES+= cf_parse.h \
definitions.h \
libjc.h \
inline.h \
Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/definitions.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/definitions.h?rev=365472&r1=365471&r2=365472&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/definitions.h (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/definitions.h Mon Jan 2 15:43:08 2006
@@ -342,9 +342,10 @@
#define _JC_JAVA_STACK_MARGIN 100
/*
- * Short name for internal java.lang native library.
+ * Short name and handle for internal java.lang native library.
*/
#define _JC_INTERNAL_NATIVE_LIBRARY "JC virtual machine"
+#define _JC_INTERNAL_LIBRARY_HANDLE ((void *)1)
/*
* Number of pages to reserve for low memory situations where
Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native_lib.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native_lib.c?rev=365472&r1=365471&r2=365472&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native_lib.c (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/native_lib.c Mon Jan 2 15:43:08 2006
@@ -19,9 +19,134 @@
*/
#include "libjc.h"
+#include "gnu_classpath_VMStackWalker.h"
+#include "gnu_classpath_VMSystemProperties.h"
+#include "java_lang_Thread.h"
+#include "java_lang_VMClass.h"
+#include "java_lang_VMClassLoader.h"
+#include "java_lang_VMCompiler.h"
+#include "java_lang_VMObject.h"
+#include "java_lang_VMRuntime.h"
+#include "java_lang_VMSystem.h"
+#include "java_lang_VMThread.h"
+#include "java_lang_VMThrowable.h"
+#include "java_lang_reflect_Constructor.h"
+#include "java_lang_reflect_Field.h"
+#include "java_lang_reflect_Method.h"
+#include "org_dellroad_jc_vm_DebugThread.h"
+#include "org_dellroad_jc_vm_FinalizerThread.h"
typedef jint jni_onload_t(JavaVM *jvm, void *reserved);
+/* Internal functions */
+static void *_jc_dlsym(void *handle, const char *name);
+static int _jc_ilib_compare(const void *item1, const void *item2);
+
+/*
+ * Internal JCNI native methods.
+ *
+ * NOTE: This table must be kept up to date and sorted!
+ */
+#define _JC_ILIB_ENTRY(method) { "JCNI_" #method, JCNI_ ## method }
+static const _jc_ilib_entry _jc_ilib_table[] = {
+ _JC_ILIB_ENTRY(gnu_classpath_VMStackWalker_getClassContext),
+ _JC_ILIB_ENTRY(gnu_classpath_VMSystemProperties_preInit),
+ _JC_ILIB_ENTRY(java_lang_VMClassLoader_defineClass),
+ _JC_ILIB_ENTRY(java_lang_VMClassLoader_findLoadedClass),
+ _JC_ILIB_ENTRY(java_lang_VMClassLoader_getPrimitiveClass),
+ _JC_ILIB_ENTRY(java_lang_VMClassLoader_loadClass),
+ _JC_ILIB_ENTRY(java_lang_VMClassLoader_resolveClass),
+ _JC_ILIB_ENTRY(java_lang_VMClass_forName),
+ _JC_ILIB_ENTRY(java_lang_VMClass_getClassLoader),
+ _JC_ILIB_ENTRY(java_lang_VMClass_getComponentType),
+ _JC_ILIB_ENTRY(java_lang_VMClass_getDeclaredClasses),
+ _JC_ILIB_ENTRY(java_lang_VMClass_getDeclaredConstructors),
+ _JC_ILIB_ENTRY(java_lang_VMClass_getDeclaredFields),
+ _JC_ILIB_ENTRY(java_lang_VMClass_getDeclaredMethods),
+ _JC_ILIB_ENTRY(java_lang_VMClass_getDeclaringClass),
+ _JC_ILIB_ENTRY(java_lang_VMClass_getInterfaces),
+ _JC_ILIB_ENTRY(java_lang_VMClass_getModifiers),
+ _JC_ILIB_ENTRY(java_lang_VMClass_getName),
+ _JC_ILIB_ENTRY(java_lang_VMClass_getSuperclass),
+ _JC_ILIB_ENTRY(java_lang_VMClass_isArray),
+ _JC_ILIB_ENTRY(java_lang_VMClass_isAssignableFrom),
+ _JC_ILIB_ENTRY(java_lang_VMClass_isInstance),
+ _JC_ILIB_ENTRY(java_lang_VMClass_isInterface),
+ _JC_ILIB_ENTRY(java_lang_VMClass_isPrimitive),
+ _JC_ILIB_ENTRY(java_lang_VMClass_throwException),
+ _JC_ILIB_ENTRY(java_lang_VMObject_clone),
+ _JC_ILIB_ENTRY(java_lang_VMObject_getClass),
+ _JC_ILIB_ENTRY(java_lang_VMObject_notify),
+ _JC_ILIB_ENTRY(java_lang_VMObject_notifyAll),
+ _JC_ILIB_ENTRY(java_lang_VMObject_wait),
+ _JC_ILIB_ENTRY(java_lang_VMRuntime_availableProcessors),
+ _JC_ILIB_ENTRY(java_lang_VMRuntime_exit),
+ _JC_ILIB_ENTRY(java_lang_VMRuntime_freeMemory),
+ _JC_ILIB_ENTRY(java_lang_VMRuntime_gc),
+ _JC_ILIB_ENTRY(java_lang_VMRuntime_mapLibraryName),
+ _JC_ILIB_ENTRY(java_lang_VMRuntime_maxMemory),
+ _JC_ILIB_ENTRY(java_lang_VMRuntime_nativeLoad),
+ _JC_ILIB_ENTRY(java_lang_VMRuntime_runFinalization),
+ _JC_ILIB_ENTRY(java_lang_VMRuntime_runFinalizationForExit),
+ _JC_ILIB_ENTRY(java_lang_VMRuntime_runFinalizersOnExit),
+ _JC_ILIB_ENTRY(java_lang_VMRuntime_totalMemory),
+ _JC_ILIB_ENTRY(java_lang_VMRuntime_traceInstructions),
+ _JC_ILIB_ENTRY(java_lang_VMRuntime_traceMethodCalls),
+ _JC_ILIB_ENTRY(java_lang_VMSystem_arraycopy),
+ _JC_ILIB_ENTRY(java_lang_VMSystem_currentTimeMillis),
+ _JC_ILIB_ENTRY(java_lang_VMSystem_getenv),
+ _JC_ILIB_ENTRY(java_lang_VMSystem_identityHashCode),
+ _JC_ILIB_ENTRY(java_lang_VMSystem_setErr),
+ _JC_ILIB_ENTRY(java_lang_VMSystem_setIn),
+ _JC_ILIB_ENTRY(java_lang_VMSystem_setOut),
+ _JC_ILIB_ENTRY(java_lang_VMThread_countStackFrames),
+ _JC_ILIB_ENTRY(java_lang_VMThread_currentThread),
+ _JC_ILIB_ENTRY(java_lang_VMThread_interrupt),
+ _JC_ILIB_ENTRY(java_lang_VMThread_interrupted),
+ _JC_ILIB_ENTRY(java_lang_VMThread_isInterrupted),
+ _JC_ILIB_ENTRY(java_lang_VMThread_nativeSetPriority),
+ _JC_ILIB_ENTRY(java_lang_VMThread_nativeStop),
+ _JC_ILIB_ENTRY(java_lang_VMThread_resume),
+ _JC_ILIB_ENTRY(java_lang_VMThread_start),
+ _JC_ILIB_ENTRY(java_lang_VMThread_suspend),
+ _JC_ILIB_ENTRY(java_lang_VMThread_yield),
+ _JC_ILIB_ENTRY(java_lang_VMThrowable_fillInStackTrace),
+ _JC_ILIB_ENTRY(java_lang_VMThrowable_getStackTrace),
+ _JC_ILIB_ENTRY(java_lang_reflect_Constructor_constructNative),
+ _JC_ILIB_ENTRY(java_lang_reflect_Constructor_getExceptionTypes),
+ _JC_ILIB_ENTRY(java_lang_reflect_Constructor_getModifiers),
+ _JC_ILIB_ENTRY(java_lang_reflect_Constructor_getParameterTypes),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_get),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_getBoolean),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_getByte),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_getChar),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_getDouble),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_getFloat),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_getInt),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_getLong),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_getModifiers),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_getShort),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_getType),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_set),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_setBoolean),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_setByte),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_setChar),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_setDouble),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_setFloat),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_setInt),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_setLong),
+ _JC_ILIB_ENTRY(java_lang_reflect_Field_setShort),
+ _JC_ILIB_ENTRY(java_lang_reflect_Method_getExceptionTypes),
+ _JC_ILIB_ENTRY(java_lang_reflect_Method_getModifiers),
+ _JC_ILIB_ENTRY(java_lang_reflect_Method_getParameterTypes),
+ _JC_ILIB_ENTRY(java_lang_reflect_Method_getReturnType),
+ _JC_ILIB_ENTRY(java_lang_reflect_Method_invokeNative),
+ _JC_ILIB_ENTRY(org_dellroad_jc_vm_DebugThread_dumpDebugInfo),
+ _JC_ILIB_ENTRY(org_dellroad_jc_vm_FinalizerThread_finalizeObjects),
+};
+#undef _JC_ILIB_ENTRY
+#define NUM_ILIB_ENTRIES (sizeof(_jc_ilib_table) / sizeof(*_jc_ilib_table))
+
/*
* Invoke a native method.
*
@@ -134,6 +259,20 @@
dlname = (strcmp(name, _JC_INTERNAL_NATIVE_LIBRARY) == 0) ?
NULL : name;
+#ifndef NDEBUG
+ if (dlname == NULL) {
+ int i;
+
+ /* Sanity check that _jc_ilib_table is sorted */
+ for (i = 0; i < NUM_ILIB_ENTRIES - 1; i++) {
+ const _jc_ilib_entry *const entry1 = &_jc_ilib_table[i];
+ const _jc_ilib_entry *const entry2 = &_jc_ilib_table[i + 1];
+
+ _JC_ASSERT(_jc_ilib_compare(entry1, entry2) < 0);
+ }
+ }
+#endif
+
/* Lock loader */
_JC_MUTEX_LOCK(env, loader->mutex);
loader_locked = JNI_TRUE;
@@ -179,15 +318,17 @@
loader->instance->type->name, loader->instance);
}
- /* Try to open the shared library */
- if ((handle = dlopen(dlname, RTLD_NOW)) == NULL) {
+ /* Try to open the shared library; special case libjc */
+ if (dlname == NULL)
+ handle = _JC_INTERNAL_LIBRARY_HANDLE;
+ else if ((handle = dlopen(dlname, RTLD_NOW)) == NULL) {
_JC_EX_STORE(env, UnsatisfiedLinkError,
"failed to open native library `%s': %s", name, dlerror());
goto fail;
}
/* Invoke JNI_OnLoad() (if any) */
- if ((on_load = dlsym(handle, "JNI_OnLoad")) != NULL) {
+ if ((on_load = _jc_dlsym(handle, "JNI_OnLoad")) != NULL) {
const char *vname = NULL;
jint version;
@@ -279,14 +420,16 @@
STAILQ_REMOVE_HEAD(&loader->native_libs, link);
/* Invoke JNI_OnUnload() */
- if ((on_unload = dlsym(lib->handle, "JNI_OnUnload")) != NULL) {
+ if ((on_unload = _jc_dlsym(lib->handle,
+ "JNI_OnUnload")) != NULL) {
VERBOSE(JNI, vm, "invoking JNI_OnUnload() in native"
" library `%s'", lib->name);
(*on_unload)(_JC_JVM2JNI(vm), NULL);
}
/* Close shared library */
- if (dlclose(lib->handle) == -1) {
+ if (lib->handle != _JC_INTERNAL_LIBRARY_HANDLE
+ && dlclose(lib->handle) == -1) {
_jc_eprintf(vm, "%s(%s): %s\n",
"dlclose", lib->name, dlerror());
}
@@ -338,7 +481,7 @@
/* Search native libraries associated with method's class loader */
STAILQ_FOREACH(lib, &loader->native_libs, link) {
- if ((func = dlsym(lib->handle, jni_name)) != NULL) {
+ if ((func = _jc_dlsym(lib->handle, jni_name)) != NULL) {
method->access_flags &= ~_JC_ACC_JCNI;
goto found;
}
@@ -347,7 +490,7 @@
/* Try short JCNI function name */
strncpy(jni_name, "JCNI", 4);
STAILQ_FOREACH(lib, &loader->native_libs, link) {
- if ((func = dlsym(lib->handle, jni_name)) != NULL) {
+ if ((func = _jc_dlsym(lib->handle, jni_name)) != NULL) {
method->access_flags |= _JC_ACC_JCNI;
goto found;
}
@@ -361,7 +504,7 @@
/* Search native libraries associated with method's class loader */
strncpy(jni_name, "Java", 4);
STAILQ_FOREACH(lib, &loader->native_libs, link) {
- if ((func = dlsym(lib->handle, jni_name)) != NULL) {
+ if ((func = _jc_dlsym(lib->handle, jni_name)) != NULL) {
method->access_flags &= ~_JC_ACC_JCNI;
goto found;
}
@@ -370,7 +513,7 @@
/* Try long JCNI function name */
strncpy(jni_name, "JCNI", 4);
STAILQ_FOREACH(lib, &loader->native_libs, link) {
- if ((func = dlsym(lib->handle, jni_name)) != NULL) {
+ if ((func = _jc_dlsym(lib->handle, jni_name)) != NULL) {
method->access_flags |= _JC_ACC_JCNI;
goto found;
}
@@ -403,4 +546,36 @@
return JNI_OK;
}
+/*
+ * dlsym() wrapper that special cases the JC internal native library.
+ */
+static void *
+_jc_dlsym(void *handle, const char *name)
+{
+ _jc_ilib_entry *entry;
+ _jc_ilib_entry key;
+
+ /* Handle normal native libraries */
+ if (handle != _JC_INTERNAL_LIBRARY_HANDLE)
+ return dlsym(handle, name);
+
+ /* Handle JC internal native library */
+ key.name = name;
+ if ((entry = bsearch(&key, _jc_ilib_table, NUM_ILIB_ENTRIES,
+ sizeof(*_jc_ilib_table), _jc_ilib_compare)) == NULL)
+ return NULL;
+ return entry->addr;
+}
+
+/*
+ * Comparison function for _jc_ilib_entry's.
+ */
+static int
+_jc_ilib_compare(const void *item1, const void *item2)
+{
+ const _jc_ilib_entry *const entry1 = item1;
+ const _jc_ilib_entry *const entry2 = item2;
+
+ return strcmp(entry1->name, entry2->name);
+}
Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/structures.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/structures.h?rev=365472&r1=365471&r2=365472&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/structures.h (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/structures.h Mon Jan 2 15:43:08 2006
@@ -45,6 +45,7 @@
typedef struct _jc_heap _jc_heap;
typedef struct _jc_heap_size _jc_heap_size;
typedef struct _jc_heap_sweep _jc_heap_sweep;
+typedef struct _jc_ilib_entry _jc_ilib_entry;
typedef struct _jc_initialization _jc_initialization;
typedef struct _jc_java_stack _jc_java_stack;
typedef struct _jc_jvm _jc_jvm;
@@ -352,6 +353,14 @@
char *name;
void *handle;
STAILQ_ENTRY(_jc_native_lib) link;
+};
+
+/*
+ * JC internal native library entry.
+ */
+struct _jc_ilib_entry {
+ const char *name;
+ void *addr;
};
/*