harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arc...@apache.org
Subject svn commit: r358915 - in /incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm: include/jc_defs.h libjc/Makefile.am libjc/analysis.c libjc/definitions.h libjc/interp.c libjc/libjc.h libjc/resolve2.c libjc/structures.h libjc/tables.c
Date Sat, 24 Dec 2005 03:15:43 GMT
Author: archie
Date: Fri Dec 23 19:15:36 2005
New Revision: 358915

URL: http://svn.apache.org/viewcvs?rev=358915&view=rev
Log:
Implement a simple bytecode analysis to compute stack depth at each
instruction. Use this information to access locals using the stack
pointer instead of the saved locals pointer (kindof the Java equivalent
of GCC's -fomit-frame-pointer). Results in a slight speed increase.

Added:
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/analysis.c   (with
props)
Modified:
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jc_defs.h
    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/interp.c
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/libjc.h
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/resolve2.c
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/structures.h
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/tables.c

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jc_defs.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jc_defs.h?rev=358915&r1=358914&r2=358915&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jc_defs.h (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/include/jc_defs.h Fri
Dec 23 19:15:36 2005
@@ -222,7 +222,7 @@
  ************************************************************************/
 
 struct _jc_iinc {
-	jint		index;
+	jint		local;
 	jint	  	value;
 };
 
@@ -283,7 +283,7 @@
 	_jc_lookupswitch	*lookupswitch;
 	_jc_tableswitch		*tableswitch;
 	_jc_uint16		target;
-	_jc_uint16		local;
+	jint			local;
 	_jc_value		constant;
 	const char		*utf8;
 };

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=358915&r1=358914&r2=358915&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 Fri
Dec 23 19:15:36 2005
@@ -8,6 +8,7 @@
 
 # Standard source files
 libjc_la_SOURCES= \
+			analysis.c \
 			array.c \
 			bootstrap.c \
 			cf_parse.c \

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/analysis.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/analysis.c?rev=358915&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/analysis.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/analysis.c Fri Dec
23 19:15:36 2005
@@ -0,0 +1,306 @@
+
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors,
+ * as applicable.
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ * $Id$
+ */
+
+#include "libjc.h"
+
+/* Internal functions */
+static jint	_jc_compute_stack_depth2(_jc_env *env,
+			const _jc_depth_state *state0, int ip);
+
+/*
+ * Compute Java operand stack depth at the start of each instruction.
+ *
+ * Stores an exeption on error.
+ */
+jint
+_jc_compute_stack_depth(_jc_env *env, _jc_method_code *code, int *depth)
+{
+	_jc_depth_state state;
+	int i;
+
+	/* Initialize state */
+	memset(&state, 0, sizeof(state));
+	state.code = code;
+	state.depth = depth;
+	if ((state.retsp = _JC_STACK_ALLOC(env,
+	    code->num_insns * sizeof(*state.retsp))) == NULL)
+		return JNI_ERR;
+	memset(state.depth, 0xff, code->num_insns * sizeof(*state.depth));
+	memset(state.retsp, 0xff, code->num_insns * sizeof(*state.retsp));
+
+	/* Flow from entry point */
+	if (_jc_compute_stack_depth2(env, &state, 0) != JNI_OK)
+		return JNI_ERR;
+
+	/* Flow from each trap target */
+	state.sp = 1;
+	for (i = 0; i < code->num_traps; i++) {
+		_jc_interp_trap *const trap = &code->traps[i];
+
+		if (_jc_compute_stack_depth2(env,
+		    &state, trap->target) != JNI_OK)
+			return JNI_ERR;
+	}
+
+	/* Done */
+	return JNI_OK;
+}
+
+static jint
+_jc_compute_stack_depth2(_jc_env *env, const _jc_depth_state *state0, int ip)
+{
+	_jc_method_code *const code = state0->code;
+	_jc_depth_state state;
+
+	/* Initialize my own state based on given state */
+	memset(&state, 0, sizeof(state));
+	state.sp = state0->sp;
+	state.ip = ip;
+	state.code = state0->code;
+	state.depth = state0->depth;
+	state.retsp = state0->retsp;
+	if ((state.locals = _JC_STACK_ALLOC(env, (code->max_locals
+	    + code->max_stack) * sizeof(*state.locals))) == NULL)
+		return JNI_ERR;
+	state.stack = state.locals + code->max_locals;
+	if (state0->locals == NULL) {
+		memset(state.locals, 0xff, (code->max_locals
+		    + code->max_stack) * sizeof(*state.locals));
+	} else {
+		memcpy(state.locals, state0->locals, (code->max_locals
+		    + code->max_stack) * sizeof(*state.locals));
+	}
+
+	/* Flow forward */
+	while (JNI_TRUE) {
+		_jc_insn_info *const info = &code->info[state.ip];
+		int delta;
+
+		/* Sanity check */
+		_JC_ASSERT(state.ip >= 0 && state.ip < code->num_insns);
+		_JC_ASSERT(state.sp >= 0 && state.sp <= code->max_stack);
+
+		/* Have we already done this chunk? */
+		if (state.depth[state.ip] != -1) {
+			_JC_ASSERT(state.depth[state.ip] == state.sp);
+			break;
+		}
+		state.depth[state.ip] = state.sp;
+
+		/*
+		 * Update stack and locals state. We only care about
+		 * operations that can affect "returnAddress" values,
+		 * which we must track in order to handle "ret".
+		 */
+		switch (code->opcodes[state.ip]) {
+		case _JC_astore:
+			_JC_ASSERT(state.sp >= 1);
+			state.locals[info->local] = state.stack[state.sp - 1];
+			break;
+		case _JC_dup:
+			_JC_ASSERT(state.sp >= 1);
+			state.stack[0] = state.stack[-1];
+			break;
+		case _JC_dup_x1:
+			_JC_ASSERT(state.sp >= 2);
+			state.stack[0] = state.stack[-1];
+			state.stack[-1] = state.stack[-2];
+			state.stack[-2] = state.stack[0];
+			break;
+		case _JC_dup_x2:
+			_JC_ASSERT(state.sp >= 3);
+			state.stack[0] = state.stack[-1];
+			state.stack[-1] = state.stack[-2];
+			state.stack[-2] = state.stack[-3];
+			state.stack[-3] = state.stack[0];
+			break;
+		case _JC_dup2:
+			_JC_ASSERT(state.sp >= 2);
+			state.stack[1] = state.stack[-1];
+			state.stack[0] = state.stack[-2];
+			break;
+		case _JC_dup2_x1:
+			_JC_ASSERT(state.sp >= 3);
+			state.stack[1] = state.stack[-1];
+			state.stack[0] = state.stack[-2];
+			state.stack[-1] = state.stack[-3];
+			state.stack[-2] = state.stack[1];
+			state.stack[-3] = state.stack[0];
+			break;
+		case _JC_dup2_x2:
+			_JC_ASSERT(state.sp >= 4);
+			state.stack[1] = state.stack[-1];
+			state.stack[0] = state.stack[-2];
+			state.stack[-1] = state.stack[-3];
+			state.stack[-2] = state.stack[-4];
+			state.stack[-3] = state.stack[1];
+			state.stack[-4] = state.stack[0];
+			break;
+		case _JC_jsr:
+			state.stack[0] = state.ip + 1;
+			break;
+		case _JC_swap:
+		    {
+		    	int temp;
+
+			_JC_ASSERT(state.sp >= 2);
+			temp = state.stack[-2];
+			state.stack[-2] = state.stack[-1];
+			state.stack[-1] = temp;
+			break;
+		    }
+		}
+
+		/* Update stack pointer */
+		switch (code->opcodes[state.ip]) {
+		case _JC_getstatic:
+			delta = _jc_dword_type[_jc_sig_types[
+			    (u_char)*info->field.field->signature]] ? 2 : 1;
+			break;
+		case _JC_invokeinterface:
+		case _JC_invokespecial:
+		case _JC_invokestatic:
+		case _JC_invokevirtual:
+		    {
+			_jc_method *const method = info->invoke.method;
+		    	u_char ptype;
+
+			delta = -info->invoke.pop;
+			ptype = method->param_ptypes[method->num_parameters];
+			if (ptype != _JC_TYPE_VOID)
+				delta += _jc_dword_type[ptype] ? 2 : 1;
+			break;
+		    }
+		case _JC_multianewarray:
+			delta = -info->multianewarray.dims + 1;
+			break;
+		case _JC_putstatic:
+			delta = _jc_dword_type[_jc_sig_types[
+			    (u_char)*info->field.field->signature]] ? -2 : -1;
+			break;
+		default:
+			delta = (signed char)(_jc_bytecode_stackadj[
+			    code->opcodes[state.ip]] ^ _JC_STACKADJ_INVALID);
+			_JC_ASSERT(delta >= -4 && delta <= 2);
+			break;
+		}
+		state.sp += delta;
+
+		/* Flow to next instruction(s) */
+		switch (code->opcodes[state.ip]) {
+		case _JC_goto:
+			state.ip = info->target;
+			break;
+		case _JC_areturn:
+		case _JC_dreturn:
+		case _JC_freturn:
+		case _JC_ireturn:
+		case _JC_lreturn:
+		case _JC_return:
+		case _JC_athrow:
+			return JNI_OK;
+		case _JC_if_acmpeq:
+		case _JC_if_acmpne:
+		case _JC_if_icmpeq:
+		case _JC_if_icmpne:
+		case _JC_if_icmplt:
+		case _JC_if_icmpge:
+		case _JC_if_icmpgt:
+		case _JC_if_icmple:
+		case _JC_ifeq:
+		case _JC_ifne:
+		case _JC_iflt:
+		case _JC_ifge:
+		case _JC_ifgt:
+		case _JC_ifle:
+		case _JC_ifnonnull:
+		case _JC_ifnull:
+			if (_jc_compute_stack_depth2(env,
+			    &state, info->target) != JNI_OK)
+				return JNI_ERR;
+			state.ip++;
+			break;
+		case _JC_jsr:
+
+			/* Flow into subroutine */
+			if (_jc_compute_stack_depth2(env,
+			    &state, info->target) != JNI_OK)
+				return JNI_ERR;
+
+			/* Retrieve our new stack depth */
+			_JC_ASSERT(state.retsp[info->target] != -1);
+			state.sp = state.retsp[info->target];
+
+			/* Continue with next instruction */
+			state.ip++;
+			break;
+		case _JC_lookupswitch:
+		    {
+		    	_jc_lookupswitch *const lsw = info->lookupswitch;
+			int i;
+
+			for (i = 0; i < lsw->num_pairs; i++) {
+				_jc_lookup *const entry = &lsw->pairs[i];
+
+				if (_jc_compute_stack_depth2(env,
+				    &state, entry->target) != JNI_OK)
+					return JNI_ERR;
+			}
+			state.ip = lsw->default_target;
+			break;
+		    }
+		case _JC_ret:
+		    {
+		    	int jsr_ip;
+		    	int sub_ip;
+
+			/* Let JSR instruction know what SP it gets back */
+			jsr_ip = state.locals[info->local] - 1;
+			_JC_ASSERT(jsr_ip >= 0 && jsr_ip <= code->num_insns);
+			_JC_ASSERT(code->opcodes[jsr_ip] == _JC_jsr);
+			sub_ip = code->info[jsr_ip].target;
+			_JC_ASSERT(sub_ip >= 0 && sub_ip <= code->num_insns);
+			state.retsp[sub_ip] = state.sp;
+			return JNI_OK;
+		    }
+		case _JC_tableswitch:
+		    {
+		    	_jc_tableswitch *const tsw = info->tableswitch;
+			int i;
+
+			for (i = 0; i < tsw->high - tsw->low + 1; i++) {
+				if (_jc_compute_stack_depth2(env,
+				    &state, tsw->targets[i]) != JNI_OK)
+					return JNI_ERR;
+			}
+			state.ip = tsw->default_target;
+			break;
+		    }
+		default:
+			state.ip++;
+			break;
+		}
+	}
+
+	/* Done */
+	return JNI_OK;
+}
+
+

Propchange: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/analysis.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/analysis.c
------------------------------------------------------------------------------
    svn:keywords = Id

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=358915&r1=358914&r2=358915&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 Fri
Dec 23 19:15:36 2005
@@ -198,6 +198,7 @@
 #define _JC_putfield_f		0xed
 #define _JC_putfield_d		0xee
 #define _JC_putfield_l		0xef
+#define _JC_failure		0xff
 
 /*
  * Lockword layout
@@ -505,6 +506,9 @@
 #define _JC_CPATH_DIRECTORY		1
 #define _JC_CPATH_ZIPFILE		2
 #define _JC_CPATH_ERROR			3
+
+/* Invalid bytecode stack adjustment value */
+#define _JC_STACKADJ_INVALID		0x80
 
 /*
  * Array bounds check for offset + length. Returns true if bounds are OK.

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/interp.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/interp.c?rev=358915&r1=358914&r2=358915&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/interp.c (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/interp.c Fri Dec
23 19:15:36 2005
@@ -68,11 +68,11 @@
 #define STACKJ(i)	(*(jlong *)(sp + (i)))
 #define STACKD(i)	(*(jdouble *)(sp + (i)))
 #define STACKL(i)	(*(_jc_object **)(sp + (i)))
-#define LOCALI(i)	(*(jint *)(locals + i))
-#define LOCALF(i)	(*(jfloat *)(locals + i))
-#define LOCALJ(i)	(*(jlong *)(locals + i))
-#define LOCALD(i)	(*(jdouble *)(locals + i))
-#define LOCALL(i)	(*(_jc_object **)(locals + i))
+#define LOCALI(i)	(*(jint *)(sp + i))
+#define LOCALF(i)	(*(jfloat *)(sp + i))
+#define LOCALJ(i)	(*(jlong *)(sp + i))
+#define LOCALD(i)	(*(jdouble *)(sp + i))
+#define LOCALL(i)	(*(_jc_object **)(sp + i))
 #define PUSHI(v)	do { STACKI(0) = (v); sp++; } while (0)
 #define PUSHF(v)	do { STACKF(0) = (v); sp++; } while (0)
 #define PUSHJ(v)	do { STACKJ(0) = (v); sp += 2; } while (0)
@@ -149,6 +149,7 @@
 		ACTION(f2i),
 		ACTION(f2l),
 		ACTION(fadd),
+		ACTION(failure),
 		ACTION(faload),
 		ACTION(fastore),
 		ACTION(fcmpg),
@@ -354,7 +355,7 @@
 	/* Synchronize */
 	if (_JC_ACC_TEST(method, SYNCHRONIZED)) {
 		lock = _JC_ACC_TEST(method, STATIC) ?
-		    method->class->instance : LOCALL(0);
+		    method->class->instance : LOCALL(-code->max_locals);
 		if (_jc_lock_object(env, lock) != JNI_OK) {
 			lock = NULL;
 			goto exception;
@@ -676,6 +677,9 @@
 	PUSHF(array->elems[index]);
 	NEXT();
     }
+do_failure:
+	_jc_post_exception_msg(env, _JC_InternalError, "failure opcode");
+	goto exception;
 do_fastore:
     {
 	_jc_float_array *array;
@@ -1002,7 +1006,7 @@
 	POP(1);
 	JUMP(STACKL(0) == NULL ? INFO(target) : pc + 1);
 do_iinc:
-	LOCALI(INFO(iinc).index) += INFO(iinc).value;
+	LOCALI(INFO(iinc).local) += INFO(iinc).value;
 	NEXT();
 do_iload:
 	PUSHI(LOCALI(INFO(local)));

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/libjc.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/libjc.h?rev=358915&r1=358914&r2=358915&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/libjc.h (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/libjc.h Fri Dec
23 19:15:36 2005
@@ -60,6 +60,10 @@
 #include "structures.h"
 #include "arch_libjc.h"
 
+/* analysis.c */
+extern jint		_jc_compute_stack_depth(_jc_env *env,
+				_jc_method_code *code, int *depth);
+
 /* array.c */
 extern jint		_jc_setup_array_types(_jc_env *env);
 
@@ -513,6 +517,7 @@
 extern const char	_jc_hex_chars[16];
 extern const char	*const _jc_verbose_names[_JC_VERBOSE_MAX];
 extern const char	*const _jc_bytecode_names[0x100];
+extern const signed char _jc_bytecode_stackadj[0x100];
 
 /* utf.c */
 extern jint		_jc_utf_decode(const u_char *utf,

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/resolve2.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/resolve2.c?rev=358915&r1=358914&r2=358915&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/resolve2.c (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/resolve2.c Fri Dec
23 19:15:36 2005
@@ -486,6 +486,7 @@
 	_jc_cf_code code_mem;
 	_jc_cf_code *const code = &code_mem;
 	jboolean mutex_locked;
+	int *depth;
 	int i;
 
 	/* Sanity check */
@@ -819,7 +820,7 @@
 			info->target = insn->u.branch.target;
 			break;
 		case _JC_iinc:
-			info->iinc.index = insn->u.iinc.index;
+			info->iinc.local = insn->u.iinc.index;
 			info->iinc.value = insn->u.iinc.value;
 			break;
 		case _JC_invokeinterface:
@@ -1093,6 +1094,56 @@
 
 		/* Copy opcode */
 		interp->opcodes[i] = opcode;
+	}
+
+	/* Compute stack depth at the start of each instruction */
+	if ((depth = _JC_STACK_ALLOC(env,
+	    code->num_insns * sizeof(*depth))) == NULL)
+		goto post_fail;
+	if (_jc_compute_stack_depth(env, interp, depth) != JNI_OK)
+		goto post_fail;
+
+	/*
+	 * Change all local indicies into stack pointer offsets.
+	 * We must include any stack operations performed before
+	 * the local is referenced.
+	 */
+	for (i = 0; i < code->num_insns; i++) {
+		_jc_cf_insn *const insn = &code->insns[i];
+		_jc_insn_info *const info = &interp->info[i];
+
+		/* Handle the case of unreachable code */
+		if (depth[i] == -1) {
+			insn->opcode = _JC_failure;
+			continue;
+		}
+
+		/* Change local index to SP offset */
+		_JC_ASSERT(depth[i] >= 0 && depth[i] <= code->max_stack);
+		switch (insn->opcode) {
+		case _JC_aload:
+		case _JC_dload:
+		case _JC_fload:
+		case _JC_iload:
+		case _JC_lload:
+		case _JC_ret:
+			info->local += -code->max_locals - depth[i];
+			break;
+		case _JC_astore:
+		case _JC_fstore:
+		case _JC_istore:
+			info->local += -code->max_locals - (depth[i] - 1);
+			break;
+		case _JC_dstore:
+		case _JC_lstore:
+			info->local += -code->max_locals - (depth[i] - 2);
+			break;
+		case _JC_iinc:
+			info->iinc.local += -code->max_locals - depth[i];
+			break;
+		default:
+			break;
+		}
 	}
 
 	/* Done */

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=358915&r1=358914&r2=358915&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 Fri
Dec 23 19:15:36 2005
@@ -38,6 +38,7 @@
 typedef struct _jc_class_ref _jc_class_ref;
 typedef struct _jc_classbytes _jc_classbytes;
 typedef struct _jc_cpath_entry _jc_cpath_entry;
+typedef struct _jc_depth_state	_jc_depth_state;
 typedef struct _jc_ex_info _jc_ex_info;
 typedef struct _jc_fat_lock _jc_fat_lock;
 typedef struct _jc_fat_locks _jc_fat_locks;
@@ -81,6 +82,20 @@
 	int		size;		/* number of nodes in tree */
 	_jc_splay_node	*root;		/* root of the tree */
 	_jc_splay_cmp_t	*compare;	/* item comparision function */
+};
+
+/************************************************************************
+ *		    Java stack depth computation state			*
+ ************************************************************************/
+
+struct _jc_depth_state {
+	int		sp;
+	int		ip;
+	_jc_method_code	*code;
+	int		*depth;
+	int		*retsp;
+	int		*locals;
+	int		*stack;
 };
 
 /************************************************************************

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/tables.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/tables.c?rev=358915&r1=358914&r2=358915&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/tables.c (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/tables.c Fri Dec
23 19:15:36 2005
@@ -328,6 +328,7 @@
 	BYTECODE(f2i),
 	BYTECODE(f2l),
 	BYTECODE(fadd),
+	BYTECODE(failure),
 	BYTECODE(faload),
 	BYTECODE(fastore),
 	BYTECODE(fcmpg),
@@ -352,7 +353,25 @@
 	BYTECODE(fstore_3),
 	BYTECODE(fsub),
 	BYTECODE(getfield),
+	BYTECODE(getfield_z),
+	BYTECODE(getfield_b),
+	BYTECODE(getfield_c),
+	BYTECODE(getfield_s),
+	BYTECODE(getfield_i),
+	BYTECODE(getfield_j),
+	BYTECODE(getfield_f),
+	BYTECODE(getfield_d),
+	BYTECODE(getfield_l),
 	BYTECODE(getstatic),
+	BYTECODE(getstatic_z),
+	BYTECODE(getstatic_b),
+	BYTECODE(getstatic_c),
+	BYTECODE(getstatic_s),
+	BYTECODE(getstatic_i),
+	BYTECODE(getstatic_j),
+	BYTECODE(getstatic_f),
+	BYTECODE(getstatic_d),
+	BYTECODE(getstatic_l),
 	BYTECODE(goto),
 	BYTECODE(goto_w),
 	BYTECODE(i2b),
@@ -401,6 +420,7 @@
 	BYTECODE(invokeinterface),
 	BYTECODE(invokespecial),
 	BYTECODE(invokestatic),
+	BYTECODE(invokestatic2),
 	BYTECODE(invokevirtual),
 	BYTECODE(ior),
 	BYTECODE(irem),
@@ -462,7 +482,24 @@
 	BYTECODE(pop),
 	BYTECODE(pop2),
 	BYTECODE(putfield),
+	BYTECODE(putfield_z),
+	BYTECODE(putfield_b),
+	BYTECODE(putfield_c),
+	BYTECODE(putfield_s),
+	BYTECODE(putfield_i),
+	BYTECODE(putfield_j),
+	BYTECODE(putfield_f),
+	BYTECODE(putfield_d),
+	BYTECODE(putfield_l),
 	BYTECODE(putstatic),
+	BYTECODE(putstatic_z),
+	BYTECODE(putstatic_b),
+	BYTECODE(putstatic_c),
+	BYTECODE(putstatic_s),
+	BYTECODE(putstatic_i),
+	BYTECODE(putstatic_j),
+	BYTECODE(putstatic_f),
+	BYTECODE(putstatic_d),
 	BYTECODE(ret),
 	BYTECODE(return),
 	BYTECODE(saload),
@@ -472,3 +509,172 @@
 	BYTECODE(tableswitch),
 	BYTECODE(wide),
 };
+#undef BYTECODE
+
+/*
+ * Bytecode stack adjustments. This only contains instructions
+ * that _jc_compute_stack_depth() would see.
+ */
+#define BYTECODE(name, amount)						\
+	[_JC_ ## name]= ((signed char)((amount) ^ _JC_STACKADJ_INVALID))
+const signed char _jc_bytecode_stackadj[0x100] = {
+	BYTECODE(aaload, -1),
+	BYTECODE(aastore, -3),
+	BYTECODE(aload, 1),
+	BYTECODE(anewarray, 0),
+	BYTECODE(areturn, -1),
+	BYTECODE(arraylength, 0),
+	BYTECODE(astore, -1),
+	BYTECODE(athrow, -1),
+	BYTECODE(baload, -1),
+	BYTECODE(bastore, -3),
+	BYTECODE(caload, -1),
+	BYTECODE(castore, -3),
+	BYTECODE(checkcast, 0),
+	BYTECODE(d2f, -1),
+	BYTECODE(d2i, -1),
+	BYTECODE(d2l, 0),
+	BYTECODE(dadd, -2),
+	BYTECODE(daload, 0),
+	BYTECODE(dastore, -4),
+	BYTECODE(dcmpg, -3),
+	BYTECODE(dcmpl, -3),
+	BYTECODE(ddiv, -2),
+	BYTECODE(dload, 2),
+	BYTECODE(dmul, -2),
+	BYTECODE(dneg, 0),
+	BYTECODE(drem, -2),
+	BYTECODE(dreturn, -2),
+	BYTECODE(dstore, -2),
+	BYTECODE(dsub, -2),
+	BYTECODE(dup, 1),
+	BYTECODE(dup_x1, 1),
+	BYTECODE(dup_x2, 1),
+	BYTECODE(dup2, 2),
+	BYTECODE(dup2_x1, 2),
+	BYTECODE(dup2_x2, 2),
+	BYTECODE(f2d, 1),
+	BYTECODE(f2i, 0),
+	BYTECODE(f2l, 1),
+	BYTECODE(fadd, -1),
+	BYTECODE(faload, -1),
+	BYTECODE(fastore, -3),
+	BYTECODE(fcmpg, -1),
+	BYTECODE(fcmpl, -1),
+	BYTECODE(fdiv, -1),
+	BYTECODE(fload, 1),
+	BYTECODE(fmul, -1),
+	BYTECODE(fneg, 0),
+	BYTECODE(frem, -1),
+	BYTECODE(freturn, -1),
+	BYTECODE(fstore, -1),
+	BYTECODE(fsub, -1),
+	BYTECODE(getfield_z, 0),
+	BYTECODE(getfield_b, 0),
+	BYTECODE(getfield_c, 0),
+	BYTECODE(getfield_s, 0),
+	BYTECODE(getfield_i, 0),
+	BYTECODE(getfield_j, 1),
+	BYTECODE(getfield_f, 0),
+	BYTECODE(getfield_d, 1),
+	BYTECODE(getfield_l, 0),
+	/* getstatic: variable */
+	BYTECODE(goto, 0),
+	BYTECODE(i2b, 0),
+	BYTECODE(i2c, 0),
+	BYTECODE(i2d, 1),
+	BYTECODE(i2f, 0),
+	BYTECODE(i2l, 1),
+	BYTECODE(i2s, 0),
+	BYTECODE(iadd, -1),
+	BYTECODE(iaload, -1),
+	BYTECODE(iand, -1),
+	BYTECODE(iastore, -3),
+	BYTECODE(idiv, -1),
+	BYTECODE(if_acmpeq, -2),
+	BYTECODE(if_acmpne, -2),
+	BYTECODE(if_icmpeq, -2),
+	BYTECODE(if_icmpne, -2),
+	BYTECODE(if_icmplt, -2),
+	BYTECODE(if_icmpge, -2),
+	BYTECODE(if_icmpgt, -2),
+	BYTECODE(if_icmple, -2),
+	BYTECODE(ifeq, -1),
+	BYTECODE(ifne, -1),
+	BYTECODE(iflt, -1),
+	BYTECODE(ifge, -1),
+	BYTECODE(ifgt, -1),
+	BYTECODE(ifle, -1),
+	BYTECODE(ifnonnull, -1),
+	BYTECODE(ifnull, -1),
+	BYTECODE(iinc, 0),
+	BYTECODE(iload, 1),
+	BYTECODE(imul, -1),
+	BYTECODE(ineg, 0),
+	BYTECODE(instanceof, 0),
+	/* invokeinterface: variable */
+	/* invokespecial: variable */
+	/* invokestatic: variable */
+	/* invokevirtual: variable */
+	BYTECODE(ior, -1),
+	BYTECODE(irem, -1),
+	BYTECODE(ireturn, -1),
+	BYTECODE(ishl, -1),
+	BYTECODE(ishr, -1),
+	BYTECODE(istore, -1),
+	BYTECODE(isub, -1),
+	BYTECODE(iushr, -1),
+	BYTECODE(ixor, -1),
+	BYTECODE(jsr, 1),
+	BYTECODE(l2d, 0),
+	BYTECODE(l2f, -1),
+	BYTECODE(l2i, -1),
+	BYTECODE(ladd, -2),
+	BYTECODE(laload, 0),
+	BYTECODE(land, -2),
+	BYTECODE(lastore, -4),
+	BYTECODE(lcmp, -3),
+	BYTECODE(ldc, 1),
+	BYTECODE(ldc_string, 1),
+	BYTECODE(ldc2_w, 2),
+	BYTECODE(ldiv, -2),
+	BYTECODE(lload, 2),
+	BYTECODE(lmul, -2),
+	BYTECODE(lneg, 0),
+	BYTECODE(lookupswitch, -1),
+	BYTECODE(lor, -2),
+	BYTECODE(lrem, -2),
+	BYTECODE(lreturn, -2),
+	BYTECODE(lshl, -1),
+	BYTECODE(lshr, -1),
+	BYTECODE(lstore, -2),
+	BYTECODE(lsub, -2),
+	BYTECODE(lushr, -1),
+	BYTECODE(lxor, -2),
+	BYTECODE(monitorenter, -1),
+	BYTECODE(monitorexit, -1),
+	/* multianewarray: variable */
+	BYTECODE(new, 1),
+	BYTECODE(newarray, 0),
+	BYTECODE(nop, 0),
+	BYTECODE(pop, -1),
+	BYTECODE(pop2, -2),
+	BYTECODE(putfield_z, -2),
+	BYTECODE(putfield_b, -2),
+	BYTECODE(putfield_c, -2),
+	BYTECODE(putfield_s, -2),
+	BYTECODE(putfield_i, -2),
+	BYTECODE(putfield_j, -3),
+	BYTECODE(putfield_f, -2),
+	BYTECODE(putfield_d, -3),
+	BYTECODE(putfield_l, -2),
+	/* putstatic: variable */
+	BYTECODE(ret, 0),
+	BYTECODE(return, 0),
+	BYTECODE(saload, -1),
+	BYTECODE(sastore, -3),
+	BYTECODE(swap, 0),
+	BYTECODE(tableswitch, -1),
+};
+#undef BYTECODE
+



Mime
View raw message