harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arc...@apache.org
Subject svn commit: r372068 - in /incubator/harmony/enhanced/jchevm: include/jc_defs.h libjc/arch/i386/arch_functions.c libjc/arch/ppc/arch_functions.c libjc/derive2.c libjc/interp.c libjc/invoke.c libjc/libjc.h libjc/reflect.c libjc/resolve2.c libjc/tables.c
Date Wed, 25 Jan 2006 01:01:16 GMT
Author: archie
Date: Tue Jan 24 17:00:48 2006
New Revision: 372068

URL: http://svn.apache.org/viewcvs?rev=372068&view=rev
Log:
Pre-compute the number of parameter words for all methods, not just
for non-native methods. Use this value to eliminate some loops.
Replace the _jc_dword_type[] table with _jc_type_words[].

Modified:
    incubator/harmony/enhanced/jchevm/include/jc_defs.h
    incubator/harmony/enhanced/jchevm/libjc/arch/i386/arch_functions.c
    incubator/harmony/enhanced/jchevm/libjc/arch/ppc/arch_functions.c
    incubator/harmony/enhanced/jchevm/libjc/derive2.c
    incubator/harmony/enhanced/jchevm/libjc/interp.c
    incubator/harmony/enhanced/jchevm/libjc/invoke.c
    incubator/harmony/enhanced/jchevm/libjc/libjc.h
    incubator/harmony/enhanced/jchevm/libjc/reflect.c
    incubator/harmony/enhanced/jchevm/libjc/resolve2.c
    incubator/harmony/enhanced/jchevm/libjc/tables.c

Modified: incubator/harmony/enhanced/jchevm/include/jc_defs.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/include/jc_defs.h?rev=372068&r1=372067&r2=372068&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/include/jc_defs.h (original)
+++ incubator/harmony/enhanced/jchevm/include/jc_defs.h Tue Jan 24 17:00:48 2006
@@ -325,7 +325,6 @@
 	_jc_uint16	num_traps;
 	_jc_uint16	num_linemaps;
 	_jc_uint16	num_insns;
-	_jc_uint16	num_params2;
 };
 
 /* Method descriptor */
@@ -341,6 +340,7 @@
 	_jc_word		vtable_index;	/* index in vtable, mtable */
 	_jc_uint16		access_flags;
 	_jc_uint16		num_parameters;
+	_jc_uint16		num_params2;	/* counts long/double twice */
 	_jc_uint16		num_exceptions;
 	_jc_uint16		signature_hash_bucket;
 	const void		*native_function;

Modified: incubator/harmony/enhanced/jchevm/libjc/arch/i386/arch_functions.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/arch/i386/arch_functions.c?rev=372068&r1=372067&r2=372068&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/arch/i386/arch_functions.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/arch/i386/arch_functions.c Tue Jan 24 17:00:48
2006
@@ -68,11 +68,7 @@
 	nparams2 = 1;						/* "env" */
 	if (!_JC_ACC_TEST(method, STATIC))
 		nparams2++;					/* "this" */
-	nparams2 += method->num_parameters;
-	for (pnum = 0; pnum < method->num_parameters; pnum++) {
-		if (_jc_dword_type[method->param_ptypes[pnum]])
-			nparams2++;
-	}
+	nparams2 += method->num_params2;
 
 	/* Get types of parameter words 1 and 2 (we know type for 0, "env") */
 	if (_JC_ACC_TEST(method, STATIC)) {
@@ -150,7 +146,7 @@
 		/* Copy 4th and later parameter words */
 		offset = (offsets[3] + (nparams2 - 4)) * 4;
 		pnum = method->num_parameters - 1;
-		if (_jc_dword_type[method->param_ptypes[pnum]])
+		if (_jc_type_words[method->param_ptypes[pnum]] == 2)
 			pnum = -pnum;
 		for (pword = nparams2 - 1; pword >= 3; pword--, offset -= 4) {
 
@@ -198,7 +194,7 @@
 			/* Keep track of corresponding parameter index */
 			if (pnum < 0)	/* was second word of long/double */
 				pnum = -pnum;
-			else if (_jc_dword_type[method->param_ptypes[--pnum]])
+			else if (_jc_type_words[method->param_ptypes[--pnum]] == 2)
 				pnum = -pnum;
 		}
 

Modified: incubator/harmony/enhanced/jchevm/libjc/arch/ppc/arch_functions.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/arch/ppc/arch_functions.c?rev=372068&r1=372067&r2=372068&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/arch/ppc/arch_functions.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/arch/ppc/arch_functions.c Tue Jan 24 17:00:48
2006
@@ -47,11 +47,7 @@
 	nparams2 = 1;						/* "env" */
 	if (!_JC_ACC_TEST(method, STATIC))
 		nparams2++;					/* "this" */
-	nparams2 += method->num_parameters;
-	for (pnum = 0; pnum < method->num_parameters; pnum++) {
-		if (_jc_dword_type[method->param_ptypes[pnum]])
-			nparams2++;
-	}
+	nparams2 += method->num_params2;
 
 	/* Get types of parameter words 1 and 2 (we know type for 0, "env") */
 	if (_JC_ACC_TEST(method, STATIC)) {
@@ -129,7 +125,7 @@
 		/* Copy 4th and later parameter words */
 		offset = (offsets[3] + (nparams2 - 4)) * 4;
 		pnum = method->num_parameters - 1;
-		if (_jc_dword_type[method->param_ptypes[pnum]])
+		if (_jc_type_words[method->param_ptypes[pnum]] == 2)
 			pnum = -pnum;
 		for (pword = nparams2 - 1; pword >= 3; pword--, offset -= 4) {
 
@@ -177,7 +173,7 @@
 			/* Keep track of corresponding parameter index */
 			if (pnum < 0)	/* was second word of long/double */
 				pnum = -pnum;
-			else if (_jc_dword_type[method->param_ptypes[--pnum]])
+			else if (_jc_type_words[method->param_ptypes[--pnum]] == 2)
 				pnum = -pnum;
 		}
 

Modified: incubator/harmony/enhanced/jchevm/libjc/derive2.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/derive2.c?rev=372068&r1=372067&r2=372068&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/derive2.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/derive2.c Tue Jan 24 17:00:48 2006
@@ -375,6 +375,7 @@
 		size_t slen;
 		int nparam;
 		void *mem;
+		int j;
 
 		/* Allocate structure */
 		nlen = strlen(cmethod->name) + 1;
@@ -420,6 +421,14 @@
 
 		/* Get parameter ptypes */
 		_jc_resolve_signature(env, method, NULL);
+
+		/* Determine parameter count with long/double counted twice */
+		_JC_ASSERT(method->num_params2 == 0);
+		for (j = 0; j < method->num_parameters; j++) {
+			const u_char ptype = method->param_ptypes[j];
+
+			method->num_params2 += _jc_type_words[ptype];
+		}
 	}
 
 	/* Done */

Modified: incubator/harmony/enhanced/jchevm/libjc/interp.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/interp.c?rev=372068&r1=372067&r2=372068&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/interp.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/interp.c Tue Jan 24 17:00:48 2006
@@ -2134,7 +2134,7 @@
 	sp = env->sp;
 
 	/* Check Java stack overflow */
-	if (sp + 1 + method->code.num_params2 > env->stack_data_end) {
+	if (sp + 1 + method->num_params2 > env->stack_data_end) {
 		_jc_post_exception(env, _JC_StackOverflowError);
 		_jc_throw_exception(env);
 	}
@@ -2197,7 +2197,7 @@
 			break;
 		}
 	}
-	_JC_ASSERT(sp - env->sp == method->code.num_params2
+	_JC_ASSERT(sp - env->sp == method->num_params2
 	    + !_JC_ACC_TEST(method, STATIC));
 
 #ifndef NDEBUG

Modified: incubator/harmony/enhanced/jchevm/libjc/invoke.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/invoke.c?rev=372068&r1=372067&r2=372068&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/invoke.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/invoke.c Tue Jan 24 17:00:48 2006
@@ -403,7 +403,7 @@
 
 	/* Allocate array of _jc_word's to hold the parameters */
 	if ((params = _JC_STACK_ALLOC(env,
-	    method->code.num_params2 * sizeof(*params))) == NULL) {
+	    method->num_params2 * sizeof(*params))) == NULL) {
 		_jc_post_exception_info(env);
 		return JNI_ERR;
 	}
@@ -478,7 +478,7 @@
 
 	/* Allocate array of _jc_word's to hold the parameters */
 	if ((params = _JC_STACK_ALLOC(env,
-	    method->code.num_params2 * sizeof(*params))) == NULL) {
+	    method->num_params2 * sizeof(*params))) == NULL) {
 		_jc_post_exception_info(env);
 		return JNI_ERR;
 	}
@@ -569,7 +569,6 @@
 	_jc_word *params2;
 	u_char *ptypes;
 	jobject ref;
-	int nparams2;
 	int i;
 	int j;
 
@@ -579,13 +578,6 @@
 	_JC_ASSERT(_JC_ACC_TEST(method, NATIVE));
 	_JC_ASSERT(func != NULL);
 
-	/* Count number of method parameters, counting long/double twice */
-	nparams2 = method->num_parameters;
-	for (i = 0; i < method->num_parameters; i++) {
-		if (_jc_dword_type[method->param_ptypes[i]])
-			nparams2++;
-	}
-
 	/* Check for null */
 	if (!_JC_ACC_TEST(method, STATIC) && obj == NULL) {
 		_jc_post_exception(env, _JC_NullPointerException);
@@ -617,7 +609,8 @@
 		goto done;
 
 	/* Create array of C function parameters */
-	if ((params2 = _JC_STACK_ALLOC(env, (2 + nparams2) * sizeof(*params2)
+	if ((params2 = _JC_STACK_ALLOC(env,
+	    (2 + method->num_params2) * sizeof(*params2)
 	    + (2 + method->num_parameters + 1))) == NULL) {
 		_jc_post_exception_info(env);
 		goto done;
@@ -638,15 +631,14 @@
 			params2[2 + j++] = (_jc_word)ref;
 		} else {
 			params2[2 + j++] = *params++;
-			if (_jc_dword_type[ptype])
+			if (_jc_type_words[ptype] == 2)
 				params2[2 + j++] = *params++;
 		}
 	}
-	_JC_ASSERT(j == nparams2);
-	nparams2 += 2;
+	_JC_ASSERT(j == method->num_params2);
 
 	/* Set up parameter types */
-	ptypes = (u_char *)(params2 + nparams2);
+	ptypes = (u_char *)(params2 + 2 + method->num_params2);
 	ptypes[0] = _JC_TYPE_REFERENCE;		/* JNIEnv parameter */
 	ptypes[1] = _JC_TYPE_REFERENCE;		/* 'this' or Class object */
 	memcpy(ptypes + 2, method->param_ptypes, method->num_parameters + 1);
@@ -669,7 +661,7 @@
 
 	/* Invoke the method */
 	_jc_dynamic_invoke(func, JNI_FALSE, 2 + method->num_parameters,
-	    ptypes, nparams2, params2, &env->retval);
+	    ptypes, 2 + method->num_params2, params2, &env->retval);
 
 	/* Returning from native */
 	_jc_resuming_java(env, NULL);
@@ -726,7 +718,7 @@
 
 	/* Allocate array of _jc_word's to hold the parameters */
 	if ((params = _JC_STACK_ALLOC(env,
-	    method->code.num_params2 * sizeof(*params))) == NULL) {
+	    method->num_params2 * sizeof(*params))) == NULL) {
 		_jc_post_exception_info(env);
 		return JNI_ERR;
 	}
@@ -832,8 +824,6 @@
 	_jc_native_frame frame;
 	_jc_catch_frame catch;
 	u_char *ptypes;
-	int nparams2;
-	int i;
 
 	/* Catch exceptions here */
 	catch.next = env->catch_list;
@@ -876,15 +866,9 @@
 	/* Sanity check */
 	_JC_ASSERT(func != NULL);
 
-	/* Count number of method parameters, counting long/double twice */
-	nparams2 = method->num_parameters;
-	for (i = 0; i < method->num_parameters; i++) {
-		if (_jc_dword_type[method->param_ptypes[i]])
-			nparams2++;
-	}
-
 	/* Create array of _jc_word's for the C function parameters */
-	if ((params2 = _JC_STACK_ALLOC(env, (2 + nparams2) * sizeof(*params2)
+	if ((params2 = _JC_STACK_ALLOC(env,
+	    (2 + method->num_params2) * sizeof(*params2)
 	    + (2 + method->num_parameters + 1))) == NULL) {
 		_jc_post_exception_info(env);
 		goto done;
@@ -892,18 +876,18 @@
 	if (!_JC_ACC_TEST(method, STATIC)) {
 		params2[0] = (_jc_word)env;
 		params2[1] = (_jc_word)obj;
-		memcpy(params2 + 2, params, nparams2 * sizeof(*params2));
-		nparams2 += 2;
-		ptypes = (u_char *)(params2 + nparams2);
+		memcpy(params2 + 2, params,
+		    method->num_params2 * sizeof(*params2));
+		ptypes = (u_char *)(params2 + 2 + method->num_params2);
 		ptypes[0] = _JC_TYPE_REFERENCE;
 		ptypes[1] = _JC_TYPE_REFERENCE;
 		memcpy(ptypes + 2, method->param_ptypes,
 		    method->num_parameters + 1);
 	} else {
 		params2[0] = (_jc_word)env;
-		memcpy(params2 + 1, params, nparams2 * sizeof(*params2));
-		nparams2++;
-		ptypes = (u_char *)(params2 + nparams2);
+		memcpy(params2 + 1, params,
+		    method->num_params2 * sizeof(*params2));
+		ptypes = (u_char *)(params2 + 1 + method->num_params2);
 		ptypes[0] = _JC_TYPE_REFERENCE;
 		memcpy(ptypes + 1, method->param_ptypes,
 		    method->num_parameters + 1);
@@ -936,7 +920,8 @@
 	/* Invoke the method */
 	_jc_dynamic_invoke(func, JNI_TRUE,
 	    (_JC_ACC_TEST(method, STATIC) ? 1 : 2) + method->num_parameters,
-	    ptypes, nparams2, params2, &env->retval);
+	    ptypes, 1 + !_JC_ACC_TEST(method, STATIC) + method->num_params2,
+	    params2, &env->retval);
 
 	/* No exceptions were thrown */
 	status = JNI_OK;

Modified: incubator/harmony/enhanced/jchevm/libjc/libjc.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/libjc.h?rev=372068&r1=372067&r2=372068&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/libjc.h (original)
+++ incubator/harmony/enhanced/jchevm/libjc/libjc.h Tue Jan 24 17:00:48 2006
@@ -508,8 +508,8 @@
 extern const void	*const _jc_interp_funcs[_JC_TYPE_MAX];
 extern const void	*const _jc_interp_native_funcs[_JC_TYPE_MAX];
 extern const u_char	_jc_sig_types[0x100];
-extern const u_char	_jc_dword_type[_JC_TYPE_MAX];
 extern const size_t	_jc_type_sizes[_JC_TYPE_MAX];
+extern const u_char	_jc_type_words[_JC_TYPE_MAX];
 extern const size_t	_jc_type_align[_JC_TYPE_MAX];
 extern const int	_jc_field_type_sort[_JC_TYPE_MAX];
 extern const size_t	_jc_array_head_sizes[_JC_TYPE_MAX];

Modified: incubator/harmony/enhanced/jchevm/libjc/reflect.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/reflect.c?rev=372068&r1=372067&r2=372068&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/reflect.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/reflect.c Tue Jan 24 17:00:48 2006
@@ -389,7 +389,6 @@
 	jobject this_ref = NULL;
 	_jc_word *params;
 	jint status;
-	int nwords;
 	int pi;
 	int i;
 
@@ -459,15 +458,9 @@
 		goto fail;
 	}
 
-	/* Count parameter words */
-	nwords = method->num_parameters;
-	for (i = 0; i < method->num_parameters; i++) {
-		if (_jc_dword_type[method->param_ptypes[i]])
-			nwords++;
-	}
-
 	/* Allocate parameter array */
-	if ((params = _JC_STACK_ALLOC(env, nwords * sizeof(*params))) == NULL) {
+	if ((params = _JC_STACK_ALLOC(env,
+	    method->num_params2 * sizeof(*params))) == NULL) {
 		_jc_post_exception_info(env);
 		goto fail;
 	}

Modified: incubator/harmony/enhanced/jchevm/libjc/resolve2.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/resolve2.c?rev=372068&r1=372067&r2=372068&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/resolve2.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/resolve2.c Tue Jan 24 17:00:48 2006
@@ -326,14 +326,6 @@
 		if (_jc_resolve_signature(env, method, info) == -1)
 			return JNI_ERR;
 
-		/* Determine parameter count with long/double counted twice */
-		_JC_ASSERT(method->code.num_params2 == 0);
-		method->code.num_params2 = method->num_parameters;
-		for (j = 0; j < method->num_parameters; j++) {
-			if (_jc_dword_type[method->param_ptypes[j]])
-				method->code.num_params2++;
-		}
-
 		/* Resolve exception types */
 		for (j = 0; j < method->num_exceptions; j++) {
 			if ((method->exceptions[j] = _jc_load_type(env, loader,
@@ -774,7 +766,6 @@
 			_jc_invoke *const invoke = &info->invoke;
 			_jc_method *imethod;
 			_jc_type *type;
-			int j;
 
 			/* Resolve method's class */
 			if ((type = _jc_load_type(env,
@@ -893,12 +884,8 @@
 			    == _JC_ACC_TEST(imethod->class, INTERFACE));
 
 			/* Count the number of words to pop off the stack */
-			invoke->pop = imethod->num_parameters
-			    + (opcode != _JC_invokestatic);
-			for (j = 0; j < imethod->num_parameters; j++) {
-				if (_jc_dword_type[imethod->param_ptypes[j]])
-					invoke->pop++;
-			}
+			invoke->pop = (opcode != _JC_invokestatic)
+			    + imethod->num_params2;
 
 			/* Optimization: de-virtualize final methods */
 			if (_JC_ACC_TEST(imethod->class, FINAL)

Modified: incubator/harmony/enhanced/jchevm/libjc/tables.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/tables.c?rev=372068&r1=372067&r2=372068&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/tables.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/tables.c Tue Jan 24 17:00:48 2006
@@ -69,6 +69,22 @@
 };
 
 /*
+ * Number of Java stack words occupied by Java types.
+ */
+const u_char _jc_type_words[_JC_TYPE_MAX] = {
+	[_JC_TYPE_BOOLEAN]=	1,
+	[_JC_TYPE_BYTE]=	1,
+	[_JC_TYPE_CHAR]=	1,
+	[_JC_TYPE_SHORT]=	1,
+	[_JC_TYPE_INT]=		1,
+	[_JC_TYPE_LONG]=	2,
+	[_JC_TYPE_FLOAT]=	1,
+	[_JC_TYPE_DOUBLE]=	2,
+	[_JC_TYPE_REFERENCE]=	1,
+	[_JC_TYPE_VOID]=	0,
+};
+
+/*
  * Alignment requirements of various Java types.
  */
 const size_t _jc_type_align[_JC_TYPE_MAX] = {
@@ -81,21 +97,6 @@
 	[_JC_TYPE_FLOAT]=	__alignof__(jfloat),
 	[_JC_TYPE_DOUBLE]=	__alignof__(jdouble),
 	[_JC_TYPE_REFERENCE]=	__alignof__(void *),
-};
-
-/*
- * Whether each Java type requires one or two Java stack words.
- */
-const u_char _jc_dword_type[_JC_TYPE_MAX] = {
-	[_JC_TYPE_BOOLEAN]=	JNI_FALSE,
-	[_JC_TYPE_BYTE]=	JNI_FALSE,
-	[_JC_TYPE_CHAR]=	JNI_FALSE,
-	[_JC_TYPE_SHORT]=	JNI_FALSE,
-	[_JC_TYPE_INT]=		JNI_FALSE,
-	[_JC_TYPE_LONG]=	JNI_TRUE,
-	[_JC_TYPE_FLOAT]=	JNI_FALSE,
-	[_JC_TYPE_DOUBLE]=	JNI_TRUE,
-	[_JC_TYPE_REFERENCE]=	JNI_FALSE,
 };
 
 /*



Mime
View raw message