[kaffe] CVS kaffe (hkraemer): moved creation of wrappers for native methods to engine specific files

Kaffe CVS cvs-commits at kaffe.org
Sun Jun 27 05:31:08 PDT 2004


PatchSet 4873 
Date: 2004/06/27 12:08:11
Author: hkraemer
Branch: HEAD
Tag: (none) 
Log:
moved creation of wrappers for native methods to engine specific files

Members: 
	ChangeLog:1.2439->1.2440 
	kaffe/kaffevm/external.c:1.59->1.60 
	kaffe/kaffevm/intrp/Makefile.am:1.9->1.10 
	kaffe/kaffevm/intrp/Makefile.in:1.101->1.102 
	kaffe/kaffevm/intrp/native-wrapper.c:INITIAL->1.1 
	kaffe/kaffevm/intrp/native-wrapper.h:INITIAL->1.1 
	kaffe/kaffevm/jit/Makefile.am:1.15->1.16 
	kaffe/kaffevm/jit/Makefile.in:1.107->1.108 
	kaffe/kaffevm/jit/constpool.c:1.3->1.4 
	kaffe/kaffevm/jit/constpool.h:1.1->1.2 
	kaffe/kaffevm/jit/machine.c:1.64->1.65 
	kaffe/kaffevm/jit/native-wrapper.c:INITIAL->1.1 
	kaffe/kaffevm/jit/native-wrapper.h:INITIAL->1.1 
	kaffe/kaffevm/jit3/Makefile.am:1.10->1.11 
	kaffe/kaffevm/jit3/Makefile.in:1.78->1.79 
	kaffe/kaffevm/jit3/native-wrapper.c:INITIAL->1.1 
	kaffe/kaffevm/jit3/native-wrapper.h:INITIAL->1.1 
	kaffe/kaffevm/jni/Makefile.am:1.4->1.5 
	kaffe/kaffevm/jni/Makefile.in:1.5->1.6 
	kaffe/kaffevm/jni/jni-native.c:1.1->1.2(DEAD) 
	kaffe/kaffevm/jni/jni.c:1.4->1.5 
	kaffe/kaffevm/jni/jni_i.h:1.3->1.4 
	kaffe/kaffevm/jni/jni_native.h:1.1->1.2(DEAD) 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2439 kaffe/ChangeLog:1.2440
--- kaffe/ChangeLog:1.2439	Sat Jun 26 23:57:18 2004
+++ kaffe/ChangeLog	Sun Jun 27 12:08:11 2004
@@ -1,3 +1,38 @@
+2004-06-27  Helmer Kraemer  <hkraemer at freenet.de>
+
+	* kaffe/kaffevm/intrp/native-wrapper.h, kaffe/kaffevm/intrp/native-wrapper.c,
+	kaffe/kaffevm/jit/native-wrapper.h, kaffe/kaffevm/jit/native-wrapper.c,
+	kaffe/kaffevm/jit3/native-wrapper.h, kaffe/kaffevm/jit3/native-wrapper.c:
+	new files
+
+	* kaffe/kaffevm/intrp/Makefile.am, kaffe/kaffevm/jit/Makefile.am,
+	kaffe/kaffevm/jit3/Makefile.am:
+	added the new native-wrapper.[ch] files
+	
+	* kaffe/kaffevm/intrp/Makefile.in, kaffe/kaffevm/jit/Makefile.in,
+	kaffe/kaffevm/jit3/Makefile.in:
+	regenerated
+
+	* kaffe/kaffevm/jni/jni_native.h, kaffe/kaffevm/jni/jni-native.c:
+	removed
+
+	* kaffe/kaffevm/jni/Makefile.am, kaffe/kaffevm/jni/Makefile.in:
+	updated and regnerated
+	
+	* kaffe/kaffevm/jni/jni.c:
+	(addJNIRef, removeJNIRef) added
+	(Kaffe_RegisterNative) use engine_create_wrapper
+
+	* kaffe/kaffevm/external.c:
+	(strcatJNI, Kaffe_JNI_native) added
+	(native) call engine_create_wrapper
+
+	* kaffe/kaffevm/jit/constants.c:
+	(resetConstants) added
+
+	* kaffe/kaffevm/jit/machine.c:
+	(initInsnSequence) call resetConstants
+	
 2004-06-26  Rob Gonzalez <rob at kaffe.org>
 	* kaffe/kaffevm/verify*.[ch]
 	Finished adding support for multiple inheritence.
Index: kaffe/kaffe/kaffevm/external.c
diff -u kaffe/kaffe/kaffevm/external.c:1.59 kaffe/kaffe/kaffevm/external.c:1.60
--- kaffe/kaffe/kaffevm/external.c:1.59	Sat Jun 26 20:08:47 2004
+++ kaffe/kaffe/kaffevm/external.c	Sun Jun 27 12:08:30 2004
@@ -40,6 +40,7 @@
 #include "jthread.h"
 #include "jsignal.h"
 #include "stats.h"
+#include "native-wrapper.h"
 #define LT_NON_POSIX_NAMESPACE
 #include "ltdl.h"
 #if defined(KAFFE_FEEDBACK)
@@ -385,6 +386,90 @@
 	return (func);
 }
 
+
+static void
+strcatJNI(char* to, const char* from)
+{
+	char* ptr;
+
+	ptr = &to[strlen(to)];
+	for (; *from != 0; from++) {
+		switch (*from) {
+		case '(':
+			/* Ignore */
+			break;
+		case ')':
+			/* Terminate here */
+			goto end;
+		case '_':
+			*ptr++ = '_';
+			*ptr++ = '1';
+			break;
+		case ';':
+			*ptr++ = '_';
+			*ptr++ = '2';
+			break;
+		case '[':
+			*ptr++ = '_';
+			*ptr++ = '3';
+			break;
+		case '/':
+			*ptr++ = '_';
+			break;
+		default:
+			*ptr++ = *from;
+			break;
+		}
+	}
+
+	end:;
+	*ptr = 0;
+}
+
+
+
+
+/*
+ * Look up a native function using the JNI interface system.
+ */
+static jint
+Kaffe_JNI_native(Method* meth)
+{
+	char name[1024];
+	void* func;
+
+	/* Build the simple JNI name for the method */
+#if defined(NO_SHARED_LIBRARIES)
+        strcpy(name, "Java_");
+#elif defined(HAVE_DYN_UNDERSCORE)
+	strcpy(name, "_Java_");
+#else
+	strcpy(name, "Java_");
+#endif
+	strcatJNI(name, meth->class->name->data);
+	strcat(name, "_");
+	strcatJNI(name, meth->name->data);
+
+	func = loadNativeLibrarySym(name);
+	if (func == NULL) {
+		/* Try the long signatures */
+		strcat(name, "__");
+		strcatJNI(name, METHOD_SIGD(meth));
+		func = loadNativeLibrarySym(name);
+		if (func == 0) {
+			return (JNI_FALSE);
+		}
+	}
+
+	meth->accflags |= ACC_JNI;
+
+	/* Wrap the function in a calling wrapper */
+	engine_create_wrapper(meth, func);
+
+	return (JNI_TRUE);
+}
+
+
 bool
 native(Method* m, errorInfo *einfo)
 {
@@ -419,12 +504,12 @@
 	func = loadNativeLibrarySym(stub);
 	if (func != 0) {
 		/* Fill it in */
-		KaffeVM_KNI_wrapper(m, func);
+		engine_create_wrapper(m, func);
 		return (true);
 	}
 
 	/* Try to locate the nature function using the JNI interface */
-        if (KaffeVM_JNI_native(m)) {
+        if (Kaffe_JNI_native(m)) {
                 return (true);
         }
 
Index: kaffe/kaffe/kaffevm/intrp/Makefile.am
diff -u kaffe/kaffe/kaffevm/intrp/Makefile.am:1.9 kaffe/kaffe/kaffevm/intrp/Makefile.am:1.10
--- kaffe/kaffe/kaffevm/intrp/Makefile.am:1.9	Tue Jun 22 15:35:44 2004
+++ kaffe/kaffe/kaffevm/intrp/Makefile.am	Sun Jun 27 12:08:33 2004
@@ -22,7 +22,8 @@
 	$(KVMLIBFLAGS)
 
 libengine_la_SOURCES = \
-	machine.c
+	machine.c \
+	native-wrapper.c
 
 EXTRA_DIST = \
 	Makefile.frag \
@@ -30,4 +31,5 @@
 	icode.h \
 	machine.h \
 	slots.h \
-	stackTrace-impl.h
+	stackTrace-impl.h \
+	native-wrapper.h
Index: kaffe/kaffe/kaffevm/intrp/Makefile.in
diff -u kaffe/kaffe/kaffevm/intrp/Makefile.in:1.101 kaffe/kaffe/kaffevm/intrp/Makefile.in:1.102
--- kaffe/kaffe/kaffevm/intrp/Makefile.in:1.101	Wed Jun 23 09:11:44 2004
+++ kaffe/kaffe/kaffevm/intrp/Makefile.in	Sun Jun 27 12:08:33 2004
@@ -72,12 +72,13 @@
 CONFIG_CLEAN_FILES =
 LTLIBRARIES = $(noinst_LTLIBRARIES)
 libengine_la_LIBADD =
-am_libengine_la_OBJECTS = machine.lo
+am_libengine_la_OBJECTS = machine.lo native-wrapper.lo
 libengine_la_OBJECTS = $(am_libengine_la_OBJECTS)
 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/config -I$(top_builddir)/include/kaffe
 depcomp = $(SHELL) $(top_srcdir)/scripts/depcomp
 am__depfiles_maybe = depfiles
- at AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/machine.Plo
+ at AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/machine.Plo \
+ at AMDEP_TRUE@	./$(DEPDIR)/native-wrapper.Plo
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) \
@@ -347,7 +348,8 @@
 	$(KVMLIBFLAGS)
 
 libengine_la_SOURCES = \
-	machine.c
+	machine.c \
+	native-wrapper.c
 
 EXTRA_DIST = \
 	Makefile.frag \
@@ -355,7 +357,8 @@
 	icode.h \
 	machine.h \
 	slots.h \
-	stackTrace-impl.h
+	stackTrace-impl.h \
+	native-wrapper.h
 
 all: all-am
 
@@ -409,6 +412,7 @@
 	-rm -f *.tab.c
 
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/machine.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/native-wrapper.Plo at am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
===================================================================
Checking out kaffe/kaffe/kaffevm/intrp/native-wrapper.c
RCS:  /home/cvs/kaffe/kaffe/kaffe/kaffevm/intrp/native-wrapper.c,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/kaffe/kaffevm/intrp/native-wrapper.c	Sun Jun 27 12:31:06 2004
@@ -0,0 +1,12 @@
+
+#include "config.h"
+#include "gtypes.h"
+#include "classMethod.h"
+#include "native-wrapper.h"
+
+void
+engine_create_wrapper (Method *meth, void *func)
+{
+	SET_METHOD_NATIVECODE(meth, func);
+	return meth;
+}
===================================================================
Checking out kaffe/kaffe/kaffevm/intrp/native-wrapper.h
RCS:  /home/cvs/kaffe/kaffe/kaffe/kaffevm/intrp/native-wrapper.h,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/kaffe/kaffevm/intrp/native-wrapper.h	Sun Jun 27 12:31:07 2004
@@ -0,0 +1,8 @@
+
+#ifndef __NATIVE_WRAPPER_H__
+#define __NATIVE_WRAPPER_H__
+
+void
+engine_create_wrapper (Method *method, void *func);
+
+#endif /* __NATIVE_WRAPPER_H__ */
Index: kaffe/kaffe/kaffevm/jit/Makefile.am
diff -u kaffe/kaffe/kaffevm/jit/Makefile.am:1.15 kaffe/kaffe/kaffevm/jit/Makefile.am:1.16
--- kaffe/kaffe/kaffevm/jit/Makefile.am:1.15	Tue Jun 22 15:35:45 2004
+++ kaffe/kaffe/kaffevm/jit/Makefile.am	Sun Jun 27 12:08:35 2004
@@ -30,7 +30,8 @@
 	registers.c \
 	slots.c \
 	machine.c \
-	seq.c
+	seq.c \
+	native-wrapper.c
 
 EXTRA_DIST = \
 	Makefile.frag \
@@ -44,7 +45,8 @@
 	registers.h \
 	seq.h \
 	slots.h \
-	stackTrace-impl.h
+	stackTrace-impl.h \
+	native-wrapper.h
 
 DISTCLEANFILES = icode.h jit.def trampolines.c
 
Index: kaffe/kaffe/kaffevm/jit/Makefile.in
diff -u kaffe/kaffe/kaffevm/jit/Makefile.in:1.107 kaffe/kaffe/kaffevm/jit/Makefile.in:1.108
--- kaffe/kaffe/kaffevm/jit/Makefile.in:1.107	Wed Jun 23 09:11:46 2004
+++ kaffe/kaffe/kaffevm/jit/Makefile.in	Sun Jun 27 12:08:35 2004
@@ -73,7 +73,8 @@
 LTLIBRARIES = $(noinst_LTLIBRARIES)
 libengine_la_LIBADD =
 am_libengine_la_OBJECTS = basecode.lo constpool.lo funcs.lo icode.lo \
-	labels.lo registers.lo slots.lo machine.lo seq.lo
+	labels.lo registers.lo slots.lo machine.lo seq.lo \
+	native-wrapper.lo
 libengine_la_OBJECTS = $(am_libengine_la_OBJECTS)
 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/config -I$(top_builddir)/include/kaffe
 depcomp = $(SHELL) $(top_srcdir)/scripts/depcomp
@@ -81,8 +82,10 @@
 @AMDEP_TRUE at DEP_FILES = ./$(DEPDIR)/basecode.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/constpool.Plo ./$(DEPDIR)/funcs.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/icode.Plo ./$(DEPDIR)/labels.Plo \
- at AMDEP_TRUE@	./$(DEPDIR)/machine.Plo ./$(DEPDIR)/registers.Plo \
- at AMDEP_TRUE@	./$(DEPDIR)/seq.Plo ./$(DEPDIR)/slots.Plo
+ at AMDEP_TRUE@	./$(DEPDIR)/machine.Plo \
+ at AMDEP_TRUE@	./$(DEPDIR)/native-wrapper.Plo \
+ at AMDEP_TRUE@	./$(DEPDIR)/registers.Plo ./$(DEPDIR)/seq.Plo \
+ at AMDEP_TRUE@	./$(DEPDIR)/slots.Plo
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) \
@@ -360,7 +363,8 @@
 	registers.c \
 	slots.c \
 	machine.c \
-	seq.c
+	seq.c \
+	native-wrapper.c
 
 EXTRA_DIST = \
 	Makefile.frag \
@@ -374,7 +378,8 @@
 	registers.h \
 	seq.h \
 	slots.h \
-	stackTrace-impl.h
+	stackTrace-impl.h \
+	native-wrapper.h
 
 DISTCLEANFILES = icode.h jit.def trampolines.c
 all: all-am
@@ -434,6 +439,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/icode.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/labels.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/machine.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/native-wrapper.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/registers.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/seq.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/slots.Plo at am__quote@
Index: kaffe/kaffe/kaffevm/jit/constpool.c
diff -u kaffe/kaffe/kaffevm/jit/constpool.c:1.3 kaffe/kaffe/kaffevm/jit/constpool.c:1.4
--- kaffe/kaffe/kaffevm/jit/constpool.c:1.3	Wed May  5 19:06:23 1999
+++ kaffe/kaffe/kaffevm/jit/constpool.c	Sun Jun 27 12:08:36 2004
@@ -109,7 +109,11 @@
 		*(union _constpoolval*)at = c->val;
 		at = (void*)(((uintp)at) + sizeof(c->val));
 	}
+}
 
+void
+resetConstants (void)
+{
 	currConst = firstConst;
 	nConst = 0;
 }
Index: kaffe/kaffe/kaffevm/jit/constpool.h
diff -u kaffe/kaffe/kaffevm/jit/constpool.h:1.1 kaffe/kaffe/kaffevm/jit/constpool.h:1.2
--- kaffe/kaffe/kaffevm/jit/constpool.h:1.1	Tue Mar 31 19:10:54 1998
+++ kaffe/kaffe/kaffevm/jit/constpool.h	Sun Jun 27 12:08:36 2004
@@ -39,5 +39,6 @@
 
 constpool* newConstant(int type, ...);
 void establishConstants(void *at);
+void resetConstants(void);
 
 #endif
Index: kaffe/kaffe/kaffevm/jit/machine.c
diff -u kaffe/kaffe/kaffevm/jit/machine.c:1.64 kaffe/kaffe/kaffevm/jit/machine.c:1.65
--- kaffe/kaffe/kaffevm/jit/machine.c:1.64	Mon May 24 13:18:54 2004
+++ kaffe/kaffe/kaffevm/jit/machine.c	Sun Jun 27 12:08:36 2004
@@ -593,6 +593,7 @@
 	initRegisters();
 	initSlots(stackno);
 	resetLabels();
+	resetConstants();
 
 	localinfo = &slotinfo[0];
 	tempinfo = &localinfo[stackno];
===================================================================
Checking out kaffe/kaffe/kaffevm/jit/native-wrapper.c
RCS:  /home/cvs/kaffe/kaffe/kaffe/kaffevm/jit/native-wrapper.c,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/kaffe/kaffevm/jit/native-wrapper.c	Sun Jun 27 12:31:07 2004
@@ -0,0 +1,427 @@
+
+#include "jni_i.h"
+#include "classMethod.h"
+#include "native-wrapper.h"
+#include "constpool.h"
+#include "seq.h"
+#include "slots.h"
+#include "registers.h"
+#include "labels.h"
+#include "codeproto.h"
+#include "basecode.h"
+#include "icode.h"
+#include "machine.h"
+
+#if defined(KAFFE_FEEDBACK)
+#include "feedback.h"
+#endif
+
+static void*
+startJNIcall(void)
+{
+	threadData 	*thread_data = THREAD_DATA();
+#if defined(NEED_JNIREFS)
+	jnirefs* table;
+
+	table = gc_malloc(sizeof(jnirefs), &gcNormal);
+	table->prev = thread_data->jnireferences;
+	thread_data->jnireferences = table;
+#endif
+	/* No pending exception when we enter JNI routine */
+	thread_data->exceptObj = 0;
+	return( &thread_data->jniEnv ); 
+}
+
+static void
+finishJNIcall(void)
+{
+	jref eobj;
+	threadData	*thread_data = THREAD_DATA();
+
+#if defined(NEED_JNIREFS)
+	{
+		jnirefs* table;
+
+		table = thread_data->jnireferences;
+		thread_data->jnireferences = table->prev;
+	}
+#endif
+	/* If we have a pending exception, throw it */
+	eobj = thread_data->exceptObj;
+	if (eobj != 0) {
+		thread_data->exceptObj = 0;
+		throwExternalException(eobj);
+	}
+}
+
+
+/*
+ * Wrap up a native function in a calling wrapper, with JNI or KNI.
+ */
+static void
+Kaffe_wrapper(Method* xmeth, void* func, bool use_JNI)
+{
+	errorInfo info;
+	int count;
+	nativeCodeInfo ncode;
+	SlotInfo* tmp = 0;
+	bool success = true;
+	int j;
+	int an;
+	int iLockRoot;
+
+	isStatic = METHOD_IS_STATIC(xmeth) ? 1 : 0;
+	count = sizeofSigMethod(xmeth, false);
+	count += 1 - isStatic;
+
+#if defined(KAFFE_FEEDBACK)
+	if( kaffe_feedback_file )
+		lockMutex(kaffe_feedback_file);
+#endif
+	/* Construct a wrapper to call the JNI method with the correct
+	 * arguments.
+	 */
+	enterTranslator();
+
+#if defined(KAFFE_PROFILER)
+	if (profFlag) {
+		profiler_get_clicks(xmeth->jitClicks);
+		xmeth->callsCount = 0;
+		xmeth->totalClicks = 0;
+		xmeth->totalChildrenClicks = 0;
+	}
+#endif
+	globalMethod = xmeth;
+
+	maxArgs = maxLocal = count; /* make sure args are spilled if needed */
+	maxStack = 0;
+	success = initInsnSequence(xmeth, 0, maxLocal, maxStack, &info);
+	if (!success) {
+		goto done;
+	}
+
+	start_basic_block();
+	prologue(xmeth);
+
+	if (use_JNI) {
+		/* Start a JNI call */
+		slot_alloctmp(tmp);
+		begin_func_sync();
+		call_soft(startJNIcall);
+		end_func_sync();
+		return_ref(tmp);
+
+#if defined(NEED_JNIREFS)
+		{
+			int j;
+			int jcount;
+
+			/* Make the necesary JNI ref calls first */
+			if (!METHOD_IS_STATIC(xmeth)) {
+				pusharg_ref(local(0), 0);
+				end_sub_block();
+				call_soft(addJNIref);
+				popargs();
+			}
+			j = METHOD_NARGS(xmeth);
+			jcount = count;
+			while (j > 0) {
+				j--;
+				jcount -= sizeofSigChar(*METHOD_ARG_TYPE(xmeth, j));
+				switch (*METHOD_ARG_TYPE(xmeth, j)) {
+				case 'L':
+				case '[':
+					pusharg_ref(local(jcount), 0);
+					end_sub_block();
+					call_soft(addJNIref);
+					popargs();
+				}
+			}
+			start_sub_block();
+		}
+#endif
+	}
+
+	/* Add synchronisation if necessary */
+	if (xmeth->accflags & ACC_SYNCHRONISED) {
+		mon_enter(xmeth, local(0));
+	}
+
+#if defined(PUSHARG_FORWARDS)
+
+	if (use_JNI) {
+		/* Push the JNI info */
+		pusharg_ref(tmp, 0);
+
+		/* If static, push the class, else push the object */
+		if (METHOD_IS_STATIC(xmeth)) {
+			pusharg_ref_const(xmeth->class, 1);
+			an = 0;
+		}
+		else {
+			pusharg_ref(local(0), 1);
+			an = 1;
+		}
+		count = 2;
+	}
+	else {
+		/* If static, nothing, else push the object */
+		if (!METHOD_IS_STATIC(xmeth)) {
+			pusharg_ref(local(0), 0);
+			an = 1;
+		}
+		else {
+			an = 0;
+		}
+		count = an;
+	}
+
+	/* Push the specified arguments */
+	for (j = 0; j < METHOD_NARGS(xmeth); j++) {
+		switch (*METHOD_ARG_TYPE(xmeth, j)) {
+		case 'L':
+		case '[':
+			pusharg_ref(local(an), count);
+			break;
+		case 'I':
+		case 'Z':
+		case 'S':
+		case 'B':
+		case 'C':
+			pusharg_int(local(an), count);
+			break;
+		case 'F':
+			pusharg_float(local(an), count);
+			break;
+		case 'J':
+			pusharg_long(local(an), count);
+			count += pusharg_long_idx_inc - 1;
+			an++;
+			break;
+		case 'D':
+			pusharg_double(local(an), count);
+			count += pusharg_long_idx_inc - 1;
+			an++;
+			break;
+		}
+		count++;
+		an++;
+	}
+
+#else
+	/* TODO: Deal with 64bits where J and D use only one slot.  */
+	/* Push the specified arguments */
+	count = maxArgs;
+	if (use_JNI) {
+		count++;
+		if (isStatic) {
+			count++;
+		}
+	}
+	an = maxArgs;
+
+	for (j = METHOD_NARGS(xmeth); --j >= 0; ) {
+		count--;
+		an--;
+		switch (*METHOD_ARG_TYPE(xmeth, j)) {
+		case 'L':
+		case '[':
+			pusharg_ref(local(an), count);
+			break;
+		case 'I':
+		case 'Z':
+		case 'S':
+		case 'B':
+		case 'C':
+			pusharg_int(local(an), count);
+			break;
+		case 'F':
+			pusharg_float(local(an), count);
+			break;
+		case 'J':
+			count--;
+			an--;
+			pusharg_long(local(an), count);
+			break;
+		case 'D':
+			count--;
+			an--;
+			pusharg_double(local(an), count);
+			break;
+		}
+	}
+
+	if (use_JNI) {
+		/* If static, push the class, else push the object */
+		if (METHOD_IS_STATIC(xmeth)) {
+			pusharg_ref_const(xmeth->class, 1);
+		}
+		else {
+			pusharg_ref(local(0), 1);
+		}
+
+		/* Push the JNI info */
+		pusharg_ref(tmp, 0);
+	}
+	else {
+		/* If static, nothing, else push the object */
+		if (!METHOD_IS_STATIC(xmeth)) {
+			pusharg_ref(local(0), 0);
+		}
+	}
+
+#endif
+
+	/* Make the call */
+	end_sub_block();
+	call_soft(func);
+	popargs();
+
+	if (use_JNI) {
+		slot_freetmp(tmp);
+	}
+	
+	start_sub_block();
+
+	/* Determine return type */
+	switch (*METHOD_RET_TYPE(xmeth)) {
+	case 'L':
+	case '[':
+		slot_alloctmp(tmp);
+		return_ref(tmp);
+		/* Remove synchronisation if necessary */
+		if (xmeth->accflags & ACC_SYNCHRONISED) {
+			mon_exit(xmeth, local(0));
+		}
+		if (use_JNI) {
+			end_sub_block();
+			call_soft(finishJNIcall);
+			start_sub_block();
+		}
+		returnarg_ref(tmp);
+		break;
+	case 'I':
+	case 'Z':
+	case 'S':
+	case 'B':
+	case 'C':
+		slot_alloctmp(tmp);
+		return_int(tmp);
+		/* Remove synchronisation if necessary */
+		if (xmeth->accflags & ACC_SYNCHRONISED) {
+			mon_exit(xmeth, local(0));
+		}
+		if (use_JNI) {
+			end_sub_block();
+			call_soft(finishJNIcall);
+			start_sub_block();
+		}
+		returnarg_int(tmp);
+		break;
+	case 'F':
+		slot_alloctmp(tmp);
+		return_float(tmp);
+		/* Remove synchronisation if necessary */
+		if (xmeth->accflags & ACC_SYNCHRONISED) {
+			mon_exit(xmeth, local(0));
+		}
+		if (use_JNI) {
+			end_sub_block();
+			call_soft(finishJNIcall);
+			start_sub_block();
+		}
+		returnarg_float(tmp);
+		break;
+	case 'J':
+		slot_alloc2tmp(tmp);
+		return_long(tmp);
+		/* Remove synchronisation if necessary */
+		if (xmeth->accflags & ACC_SYNCHRONISED) {
+			mon_exit(xmeth, local(0));
+		}
+		if (use_JNI) {
+			end_sub_block();
+			call_soft(finishJNIcall);
+			start_sub_block();
+		}
+		returnarg_long(tmp);
+		break;
+	case 'D':
+		slot_alloc2tmp(tmp);
+		return_double(tmp);
+		/* Remove synchronisation if necessary */
+		if (xmeth->accflags & ACC_SYNCHRONISED) {
+			mon_exit(xmeth, local(0));
+		}
+		if (use_JNI) {
+			end_sub_block();
+			call_soft(finishJNIcall);
+			start_sub_block();
+		}
+		returnarg_double(tmp);
+		break;
+	case 'V':
+		/* Remove synchronisation if necessary */
+		if (xmeth->accflags & ACC_SYNCHRONISED) {
+			mon_exit(xmeth, local(0));
+		}
+		if (use_JNI)
+			call_soft(finishJNIcall);
+#if defined(ENABLE_JVMPI)
+		softcall_exit_method(globalMethod);
+#endif
+		ret();
+		break;
+	}
+
+	end_function();
+
+	/* Generate the code */
+	if (tmpslot > maxTemp) {
+		maxTemp = tmpslot;
+	}
+	/* The codeinfo argument is only used in linkLabel, and it is 
+	 * only needed if we have labels referring to bytecode.  This is
+	 * not the case here.
+	 */
+	success = finishInsnSequence(0, &ncode, &info);
+	if (!success) {
+		goto done;
+	}
+
+	assert(xmeth->exception_table == 0);
+	installMethodCode(0, xmeth, &ncode);
+
+	if (use_JNI)
+		xmeth->accflags |= ACC_JNI;
+
+done:
+	resetConstants();
+	resetLabels();
+
+#if defined(KAFFE_PROFILER)
+	if (profFlag) {
+		profiler_click_t end;
+
+		profiler_get_clicks(end);
+		xmeth->jitClicks = end - xmeth->jitClicks;
+	}
+#endif
+	globalMethod = 0;
+
+	leaveTranslator();
+#if defined(KAFFE_FEEDBACK)
+	if( kaffe_feedback_file )
+		unlockMutex(kaffe_feedback_file);
+#endif
+	if (!success) {
+		throwError(&info);
+	}
+}
+
+
+void
+engine_create_wrapper (Method *meth, void *func)
+{
+	Kaffe_wrapper (meth, func, (meth->accflags&ACC_JNI)!=0);
+}
===================================================================
Checking out kaffe/kaffe/kaffevm/jit/native-wrapper.h
RCS:  /home/cvs/kaffe/kaffe/kaffe/kaffevm/jit/native-wrapper.h,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/kaffe/kaffevm/jit/native-wrapper.h	Sun Jun 27 12:31:07 2004
@@ -0,0 +1,9 @@
+
+
+#ifndef __NATIVE_WRAPPER_H__
+#define __NATIVE_WRAPPER_H__
+
+void
+engine_create_wrapper (Method *method, void *func);
+
+#endif /* __NATIVE_WRAPPER_H__ */
Index: kaffe/kaffe/kaffevm/jit3/Makefile.am
diff -u kaffe/kaffe/kaffevm/jit3/Makefile.am:1.10 kaffe/kaffe/kaffevm/jit3/Makefile.am:1.11
--- kaffe/kaffe/kaffevm/jit3/Makefile.am:1.10	Tue Jun 22 15:35:45 2004
+++ kaffe/kaffe/kaffevm/jit3/Makefile.am	Sun Jun 27 12:08:38 2004
@@ -43,7 +43,9 @@
 	seq.h \
 	slots.c \
 	slots.h \
-	stackTrace-impl.h
+	stackTrace-impl.h \
+	native-wrapper.c \
+	native-wrapper.h
 
 EXTRA_DIST = \
 	Makefile.frag
Index: kaffe/kaffe/kaffevm/jit3/Makefile.in
diff -u kaffe/kaffe/kaffevm/jit3/Makefile.in:1.78 kaffe/kaffe/kaffevm/jit3/Makefile.in:1.79
--- kaffe/kaffe/kaffevm/jit3/Makefile.in:1.78	Wed Jun 23 09:11:46 2004
+++ kaffe/kaffe/kaffevm/jit3/Makefile.in	Sun Jun 27 12:08:38 2004
@@ -73,7 +73,8 @@
 LTLIBRARIES = $(noinst_LTLIBRARIES)
 libengine_la_LIBADD =
 am_libengine_la_OBJECTS = basecode.lo constpool.lo funcs.lo icode.lo \
-	labels.lo machine.lo registers.lo seq.lo slots.lo
+	labels.lo machine.lo registers.lo seq.lo slots.lo \
+	native-wrapper.lo
 libengine_la_OBJECTS = $(am_libengine_la_OBJECTS)
 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/config -I$(top_builddir)/include/kaffe
 depcomp = $(SHELL) $(top_srcdir)/scripts/depcomp
@@ -81,8 +82,10 @@
 @AMDEP_TRUE at DEP_FILES = ./$(DEPDIR)/basecode.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/constpool.Plo ./$(DEPDIR)/funcs.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/icode.Plo ./$(DEPDIR)/labels.Plo \
- at AMDEP_TRUE@	./$(DEPDIR)/machine.Plo ./$(DEPDIR)/registers.Plo \
- at AMDEP_TRUE@	./$(DEPDIR)/seq.Plo ./$(DEPDIR)/slots.Plo
+ at AMDEP_TRUE@	./$(DEPDIR)/machine.Plo \
+ at AMDEP_TRUE@	./$(DEPDIR)/native-wrapper.Plo \
+ at AMDEP_TRUE@	./$(DEPDIR)/registers.Plo ./$(DEPDIR)/seq.Plo \
+ at AMDEP_TRUE@	./$(DEPDIR)/slots.Plo
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) \
@@ -373,7 +376,9 @@
 	seq.h \
 	slots.c \
 	slots.h \
-	stackTrace-impl.h
+	stackTrace-impl.h \
+	native-wrapper.c \
+	native-wrapper.h
 
 EXTRA_DIST = \
 	Makefile.frag
@@ -436,6 +441,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/icode.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/labels.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/machine.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/native-wrapper.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/registers.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/seq.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/slots.Plo at am__quote@
===================================================================
Checking out kaffe/kaffe/kaffevm/jit3/native-wrapper.c
RCS:  /home/cvs/kaffe/kaffe/kaffe/kaffevm/jit3/native-wrapper.c,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/kaffe/kaffevm/jit3/native-wrapper.c	Sun Jun 27 12:31:07 2004
@@ -0,0 +1,12 @@
+
+#include "jni_i.h"
+#include "constpool.h"
+#include "seq.h"
+#include "slots.h"
+#include "registers.h"
+#include "labels.h"
+#include "codeproto.h"
+#include "basecode.h"
+#include "icode.h"
+#include "machine.h"
+#include "../jit/native-wrapper.c"
===================================================================
Checking out kaffe/kaffe/kaffevm/jit3/native-wrapper.h
RCS:  /home/cvs/kaffe/kaffe/kaffe/kaffevm/jit3/native-wrapper.h,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/kaffe/kaffevm/jit3/native-wrapper.h	Sun Jun 27 12:31:07 2004
@@ -0,0 +1 @@
+#include "../jit/native-wrapper.h"
Index: kaffe/kaffe/kaffevm/jni/Makefile.am
diff -u kaffe/kaffe/kaffevm/jni/Makefile.am:1.4 kaffe/kaffe/kaffevm/jni/Makefile.am:1.5
--- kaffe/kaffe/kaffevm/jni/Makefile.am:1.4	Sat Jun 26 05:57:45 2004
+++ kaffe/kaffe/kaffevm/jni/Makefile.am	Sun Jun 27 12:08:40 2004
@@ -29,11 +29,9 @@
 	jni-base.c \
 	jni-callmethod.c \
 	jni-fields.c \
-	jni-arrays.c \
-	jni-native.c
+	jni-arrays.c
 
 noinst_HEADERS= \
 	jni_i.h \
 	jnirefs.h \
-	jni_funcs.h \
-	jni_native.h
+	jni_funcs.h
Index: kaffe/kaffe/kaffevm/jni/Makefile.in
diff -u kaffe/kaffe/kaffevm/jni/Makefile.in:1.5 kaffe/kaffe/kaffevm/jni/Makefile.in:1.6
--- kaffe/kaffe/kaffevm/jni/Makefile.in:1.5	Sat Jun 26 05:57:45 2004
+++ kaffe/kaffe/kaffevm/jni/Makefile.in	Sun Jun 27 12:08:40 2004
@@ -75,7 +75,7 @@
 LTLIBRARIES = $(noinst_LTLIBRARIES)
 libkaffejni_la_LIBADD =
 am_libkaffejni_la_OBJECTS = jni.lo jni-base.lo jni-callmethod.lo \
-	jni-fields.lo jni-arrays.lo jni-native.lo
+	jni-fields.lo jni-arrays.lo
 libkaffejni_la_OBJECTS = $(am_libkaffejni_la_OBJECTS)
 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/config -I$(top_builddir)/include/kaffe
 depcomp = $(SHELL) $(top_srcdir)/scripts/depcomp
@@ -83,8 +83,7 @@
 @AMDEP_TRUE at DEP_FILES = ./$(DEPDIR)/jni-arrays.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/jni-base.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/jni-callmethod.Plo \
- at AMDEP_TRUE@	./$(DEPDIR)/jni-fields.Plo \
- at AMDEP_TRUE@	./$(DEPDIR)/jni-native.Plo ./$(DEPDIR)/jni.Plo
+ at AMDEP_TRUE@	./$(DEPDIR)/jni-fields.Plo ./$(DEPDIR)/jni.Plo
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) \

*** Patch too long, truncated ***




More information about the kaffe mailing list