/* src/native/native.c - table of native functions
- Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
- R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
- C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
- Institut f. Computersprachen - TU Wien
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
This file is part of CACAO.
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., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
- Contact: cacao@complang.tuwien.ac.at
+ Contact: cacao@cacaojvm.org
Authors: Reinhard Grafl
Roman Obermaisser
Changes: Christian Thalinger
- $Id: native.c 2912 2005-07-05 10:04:12Z twisti $
+ $Id: native.c 5200 2006-07-31 16:30:33Z twisti $
*/
+#include "config.h"
+
#include <assert.h>
-#if !defined(ENABLE_STATICVM)
-# include "libltdl/ltdl.h"
+#if !defined(WITH_STATIC_CLASSPATH)
+# include <ltdl.h>
#endif
-#include "config.h"
-#include "types.h"
-#include "cacao/cacao.h"
+#include "vm/types.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/global.h"
+#include "vm/hashtable.h"
#include "vm/loader.h"
#include "vm/options.h"
#include "vm/resolve.h"
#include "vm/stringlocal.h"
-#include "vm/tables.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_Proxy.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_VMClass_getClassLoader,
(functionptr) Java_java_lang_VMClass_forName,
(functionptr) Java_java_lang_VMClass_isArray,
- (functionptr) Java_java_lang_VMClass_initialize,
- (functionptr) Java_java_lang_VMClass_loadArrayClass,
(functionptr) Java_java_lang_VMClass_throwException,
(functionptr) Java_java_lang_VMClassLoader_defineClass,
(functionptr) Java_java_lang_VMClassLoader_loadClass,
(functionptr) Java_java_lang_VMClassLoader_getPrimitiveClass,
(functionptr) Java_java_lang_VMClassLoader_nativeGetResources,
+ (functionptr) Java_java_lang_VMClassLoader_findLoadedClass,
(functionptr) Java_java_lang_VMObject_getClass,
(functionptr) Java_java_lang_VMObject_clone,
(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_Proxy_getProxyClass0,
- (functionptr) Java_java_lang_reflect_Proxy_getProxyData0,
- (functionptr) Java_java_lang_reflect_Proxy_generateProxyClass0,
-
- (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_Method_invokeNative,
- (functionptr) Java_java_security_VMAccessController_getStack,
-};
-
-#endif /* defined(ENABLE_STATICVM) */
-
-
-/************* use classinfo structure as java.lang.Class object **************/
+ (functionptr) Java_java_lang_reflect_VMProxy_getProxyClass,
+ (functionptr) Java_java_lang_reflect_VMProxy_getProxyData,
+ (functionptr) Java_java_lang_reflect_VMProxy_generateProxyClass,
-bool use_class_as_object(classinfo *c)
-{
- if (!c->classvftbl) {
- /* is the class loaded */
- if (!c->loaded) {
-/* if (!class_load(c)) */
-/* throw_exception_exit(); */
- log_text("use_class_as_object: class_load should not happen");
- assert(0);
- }
-
- /* is the class linked */
- if (!c->linked)
- if (!link_class(c))
- return false;
-
- assert(class_java_lang_Class);
+ (functionptr) Java_java_security_VMAccessController_getStack,
- c->header.vftbl = class_java_lang_Class->vftbl;
- c->classvftbl = true;
- }
+#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
- return true;
-}
+};
+#endif /* defined(WITH_STATIC_CLASSPATH) */
-/************************** tables for methods ********************************/
-#undef JOWENN_DEBUG
-#undef JOWENN_DEBUG1
+/* tables for methods *********************************************************/
-#ifdef ENABLE_STATICVM
+#if defined(WITH_STATIC_CLASSPATH)
#define NATIVETABLESIZE (sizeof(nativetable)/sizeof(struct nativeref))
/* table for fast string comparison */
#endif
-/* XXX don't define this in a header file!!! */
-
-static struct nativeCall nativeCalls[] =
-{
-#include "nativecalls.inc"
-};
-
-#define NATIVECALLSSIZE (sizeof(nativeCalls) / sizeof(struct nativeCall))
-
-struct nativeCompCall nativeCompCalls[NATIVECALLSSIZE];
-
-
/* global variables ***********************************************************/
-#if !defined(ENABLE_STATICVM)
-static hashtable library_hash;
+#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 */
- init_hashtable(&library_hash, 10);
+ hashtable_library = NEW(hashtable);
+ hashtable_create(hashtable_library, 10);
#endif
/* everything's ok */
}
-/* native_library_hash_add *****************************************************
+/* native_hashtable_library_add ************************************************
Adds an entry to the native library hashtable.
*******************************************************************************/
-#if !defined(ENABLE_STATICVM)
-void native_library_hash_add(utf *filename, java_objectheader *loader,
- lt_dlhandle handle)
+#if !defined(WITH_STATIC_CLASSPATH)
+void native_hashtable_library_add(utf *filename, java_objectheader *loader,
+ lt_dlhandle handle)
{
- library_hash_loader_entry *le;
- library_hash_name_entry *ne; /* library name */
+ hashtable_library_loader_entry *le;
+ hashtable_library_name_entry *ne; /* library name */
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 & (library_hash.size - 1);
- le = library_hash.ptr[slot];
+ key = ((u4) (ptrint) loader) >> 4; /* align to 16-byte boundaries */
+ 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) {
- le = NEW(library_hash_loader_entry);
+ if (le == NULL) {
+ le = NEW(hashtable_library_loader_entry);
- le->loader = loader;
+ le->loader = loader;
le->namelink = NULL;
/* insert entry into hashtable */
- le->hashlink = (library_hash_loader_entry *) library_hash.ptr[slot];
- library_hash.ptr[slot] = le;
+ le->hashlink =
+ (hashtable_library_loader_entry *) hashtable_library->ptr[slot];
+ hashtable_library->ptr[slot] = le;
/* update number of hashtable-entries */
- library_hash.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 */
}
/* not found? add the library name to the classloader */
- ne = NEW(library_hash_name_entry);
+ 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(WITH_STATIC_CLASSPATH) */
+
+
+/* native_hashtable_library_find ***********************************************
+
+ Find an entry in the native library hashtable.
+
+*******************************************************************************/
+
+#if !defined(WITH_STATIC_CLASSPATH)
+hashtable_library_name_entry *native_hashtable_library_find(utf *filename,
+ java_objectheader *loader)
+{
+ hashtable_library_loader_entry *le;
+ hashtable_library_name_entry *ne; /* library name */
+ u4 key; /* hashkey */
+ u4 slot; /* slot in hashtable */
+
+ /* 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];
+
+ /* search external hash chain for the entry */
+
+ while (le) {
+ if (le->loader == loader)
+ break;
+
+ le = le->hashlink; /* next element in external chain */
+ }
+
+ /* no loader found? return NULL */
+
+ if (!le)
+ return NULL;
+
+ /* search for library name */
+
+ ne = le->namelink;
+
+ while (ne) {
+ if (ne->name == filename)
+ return ne;
+
+ ne = ne->hashlink; /* next element in external chain */
+ }
+
+ /* return entry, if no entry was found, ne is NULL */
+
+ 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;
char *utf_ptr;
char *utf_endptr;
s4 dumpsize;
- library_hash_loader_entry *le;
- library_hash_name_entry *ne;
+ hashtable_library_loader_entry *le;
+ hashtable_library_name_entry *ne;
u4 key; /* hashkey */
u4 slot; /* slot in hashtable */
u4 i;
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 */
name[i] = '\0';
- /* check the library hash entries of the classloader of the methods's */
- /* class */
+ /* generate overloaded function (having the types in it's name) */
+
+ newname = native_make_overloaded_function(name, m->descriptor);
+
+ /* 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 & (library_hash.size - 1);
- le = library_hash.ptr[slot];
+ key = ((u4) (ptrint) m->class->classloader) >> 4; /* align to 16-byte */
+ 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) {
- /* we didn't find the symbol yet, try to resolve an overloaded */
- /* function (having the types in it's name) */
-
- newname = native_make_overloaded_function(name, m->descriptor);
-
- /* try to find the overloaded symbol */
-
+ 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) */
-
-
-/****************** function class_findfield_approx ****************************
-
- searches in 'classinfo'-structure for a field with the
- specified name
-
-*******************************************************************************/
-
-fieldinfo *class_findfield_approx(classinfo *c, utf *name)
-{
- s4 i;
-
- for (i = 0; i < c->fieldscount; i++) {
- /* compare field names */
- if ((c->fields[i].name == name))
- return &(c->fields[i]);
- }
-
- /* field was not found, raise exception */
- *exceptionptr = new_exception(string_java_lang_NoSuchFieldException);
-
- return NULL;
-}
-
-
-s4 class_findfield_index_approx(classinfo *c, utf *name)
-{
- s4 i;
-
- for (i = 0; i < c->fieldscount; i++) {
- /* compare field names */
- if ((c->fields[i].name == name))
- return i;
- }
-
- /* field was not found, raise exception */
- *exceptionptr = new_exception(string_java_lang_NoSuchFieldException);
-
- return -1;
-}
+#endif /* !defined(WITH_STATIC_CLASSPATH) */
/* native_new_and_init *********************************************************
if (!o)
return NULL;
- /* find initializer */
+ /* try to find the initializer */
m = class_findmethod(c, utf_init, utf_void__void);
- /* initializer not found */
+ /* ATTENTION: returning the object here is ok, since the class may
+ not have an initializer */
if (!m)
return o;
/* 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;
}
-void copy_vftbl(vftbl_t **dest, vftbl_t *src)
-{
- *dest = src;
-#if 0
- /* XXX this kind of copying does not work (in the general
- * case). The interface tables would have to be copied, too. I
- * don't see why we should make a copy anyway. -Edwin
- */
- *dest = mem_alloc(sizeof(vftbl) + sizeof(methodptr)*(src->vftbllength-1));
- memcpy(*dest, src, sizeof(vftbl) - sizeof(methodptr));
- memcpy(&(*dest)->table, &src->table, src->vftbllength * sizeof(methodptr));
-#endif
-}
-
-
-/******************************************************************************************
-
- creates method signature (excluding return type) from array of
- class-objects representing the parameters of the method
-
-*******************************************************************************************/
-
-
-utf *create_methodsig(java_objectarray* types, char *retType)
-{
- char *buffer; /* buffer for building the desciptor */
- char *pos; /* current position in buffer */
- utf *result; /* the method signature */
- u4 buffer_size = 3; /* minimal size=3: room for parenthesis and returntype */
- u4 i, j;
-
- if (!types) return NULL;
-
- /* determine required buffer-size */
- for (i = 0; i < types->header.size; i++) {
- classinfo *c = (classinfo *) types->data[i];
- buffer_size = buffer_size + c->name->blength + 2;
- }
-
- if (retType) buffer_size += strlen(retType);
-
- /* allocate buffer */
- buffer = MNEW(char, buffer_size);
- pos = buffer;
-
- /* method-desciptor starts with parenthesis */
- *pos++ = '(';
-
- for (i = 0; i < types->header.size; i++) {
- char ch;
-
- /* current argument */
- classinfo *c = (classinfo *) types->data[i];
-
- /* current position in utf-text */
- char *utf_ptr = c->name->text;
-
- /* determine type of argument */
- if ((ch = utf_nextu2(&utf_ptr)) == '[') {
- /* arrayclass */
- for (utf_ptr--; utf_ptr < UTF_END(c->name); utf_ptr++) {
- *pos++ = *utf_ptr; /* copy text */
- }
-
- } else {
- /* check for primitive types */
- for (j = 0; j < PRIMITIVETYPE_COUNT; j++) {
- char *utf_pos = utf_ptr - 1;
- char *primitive = primitivetype_table[j].wrapname;
-
- /* compare text */
- while (utf_pos < UTF_END(c->name)) {
- if (*utf_pos++ != *primitive++) goto nomatch;
- }
-
- /* primitive type found */
- *pos++ = primitivetype_table[j].typesig;
- goto next_type;
-
- nomatch:
- ;
- }
-
- /* no primitive type and no arrayclass, so must be object */
- *pos++ = 'L';
-
- /* copy text */
- for (utf_ptr--; utf_ptr < UTF_END(c->name); utf_ptr++) {
- *pos++ = *utf_ptr;
- }
-
- *pos++ = ';';
-
- next_type:
- ;
- }
- }
-
- *pos++ = ')';
-
- if (retType) {
- for (i = 0; i < strlen(retType); i++) {
- *pos++ = retType[i];
- }
- }
-
- /* create utf-string */
- result = utf_new(buffer, (pos - buffer));
- MFREE(buffer, char, buffer_size);
-
- return result;
-}
-
-
/* native_get_parametertypes ***************************************************
Use the descriptor of a method to generate a java/lang/Class array
/* get classes */
- for (i = 0; i < paramcount; i++) {
+ for (i = 0; i < paramcount; i++)
if (!resolve_class_from_typedesc(¶mtypes[i], true, false,
(classinfo **) &oa->data[i]))
return NULL;
- use_class_as_object((classinfo *) oa->data[i]);
- }
-
return oa;
}
resolveEager, true, false, &c))
return NULL;
- use_class_as_object(c);
-
oa->data[i] = (java_objectheader *) c;
}
&c))
return NULL;
- use_class_as_object(c);
-
return c;
}
-/*****************************************************************************/
-/*****************************************************************************/
-
-
-/*--------------------------------------------------------*/
-void printNativeCall(nativeCall nc) {
- int i,j;
-
- printf("\n%s's Native Methods call:\n",nc.classname); fflush(stdout);
- for (i=0; i<nc.methCnt; i++) {
- printf("\tMethod=%s %s\n",nc.methods[i].methodname, nc.methods[i].descriptor);fflush(stdout);
-
- for (j=0; j<nc.callCnt[i]; j++) {
- printf("\t\t<%i,%i>aCalled = %s %s %s\n",i,j,
- nc.methods[i].methodCalls[j].classname,
- nc.methods[i].methodCalls[j].methodname,
- nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
- }
- }
- printf("-+++++--------------------\n");fflush(stdout);
-}
-
-/*--------------------------------------------------------*/
-void printCompNativeCall(nativeCompCall nc) {
- int i,j;
- printf("printCompNativeCall BEGIN\n");fflush(stdout);
- printf("\n%s's Native Comp Methods call:\n",nc.classname->text);fflush(stdout);
- utf_display(nc.classname); fflush(stdout);
-
- for (i=0; i<nc.methCnt; i++) {
- printf("\tMethod=%s %s\n",nc.methods[i].methodname->text,nc.methods[i].descriptor->text);fflush(stdout);
- utf_display(nc.methods[i].methodname); fflush(stdout);
- utf_display(nc.methods[i].descriptor);fflush(stdout);
- printf("\n");fflush(stdout);
-
- for (j=0; j<nc.callCnt[i]; j++) {
- printf("\t\t<%i,%i>bCalled = ",i,j);fflush(stdout);
- utf_display(nc.methods[i].methodCalls[j].classname);fflush(stdout);
- utf_display(nc.methods[i].methodCalls[j].methodname); fflush(stdout);
- utf_display(nc.methods[i].methodCalls[j].descriptor);fflush(stdout);
- printf("\n");fflush(stdout);
- }
- }
-printf("---------------------\n");fflush(stdout);
-}
-
-
-/*--------------------------------------------------------*/
-classMeth findNativeMethodCalls(utf *c, utf *m, utf *d )
-{
- int i = 0;
- int j = 0;
- int cnt = 0;
- classMeth mc;
- mc.i_class = i;
- mc.j_method = j;
- mc.methCnt = cnt;
-
- return mc;
-}
-
-/*--------------------------------------------------------*/
-nativeCall* findNativeClassCalls(char *aclassname ) {
-int i;
-
-for (i=0;i<NATIVECALLSSIZE; i++) {
- /* convert table to utf later to speed up search */
- if (strcmp(nativeCalls[i].classname, aclassname) == 0)
- return &nativeCalls[i];
- }
-
-return NULL;
-}
-/*--------------------------------------------------------*/
-/*--------------------------------------------------------*/
-void utfNativeCall(nativeCall nc, nativeCompCall *ncc) {
- int i,j;
-
-
- ncc->classname = utf_new_char(nc.classname);
- ncc->methCnt = nc.methCnt;
-
- for (i=0; i<nc.methCnt; i++) {
- ncc->methods[i].methodname = utf_new_char(nc.methods[i].methodname);
- ncc->methods[i].descriptor = utf_new_char(nc.methods[i].descriptor);
- ncc->callCnt[i] = nc.callCnt[i];
-
- for (j=0; j<nc.callCnt[i]; j++) {
-
- ncc->methods[i].methodCalls[j].classname = utf_new_char(nc.methods[i].methodCalls[j].classname);
-
- if (strcmp("", nc.methods[i].methodCalls[j].methodname) != 0) {
- ncc->methods[i].methodCalls[j].methodname = utf_new_char(nc.methods[i].methodCalls[j].methodname);
- ncc->methods[i].methodCalls[j].descriptor = utf_new_char(nc.methods[i].methodCalls[j].descriptor);
- }
- else {
- ncc->methods[i].methodCalls[j].methodname = NULL;
- ncc->methods[i].methodCalls[j].descriptor = NULL;
- }
- }
- }
-}
-
-
-
-/*--------------------------------------------------------*/
-
-bool natcall2utf(bool natcallcompdone) {
-int i;
-
-if (natcallcompdone)
- return true;
-
-for (i=0;i<NATIVECALLSSIZE; i++) {
- utfNativeCall (nativeCalls[i], &nativeCompCalls[i]);
- }
-
-return true;
-}
-
/*
* 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