harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arc...@apache.org
Subject svn commit: r367060 - in /incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc: cf_parse.c cf_parse.h
Date Sun, 08 Jan 2006 18:14:27 GMT
Author: archie
Date: Sun Jan  8 10:14:25 2006
New Revision: 367060

URL: http://svn.apache.org/viewcvs?rev=367060&view=rev
Log:
Small optimization: use 16 bit values for instruction offsets
instead of 32 bit values when parsing class files. This works
because bytecode lengthe is currently limited to 65535 bytes.

In the future when this restriction is relaxed the reverse of
this patch can be applied as part of the VM update.

Modified:
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/cf_parse.c
    incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/cf_parse.h

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/cf_parse.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/cf_parse.c?rev=367060&r1=367059&r2=367060&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/cf_parse.c (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/cf_parse.c Sun Jan
 8 10:14:25 2006
@@ -35,9 +35,9 @@
 static int	_jc_parse_interfacemethodref(_jc_cf_parse_state *s,
 			_jc_cf_ref **refp);
 static int	_jc_parse_bytecode(_jc_cf_parse_state *s, _jc_cf_code *code,
-			_jc_uint32 *offset_map, _jc_uint32 length);
-static int	_jc_map_offset(_jc_env *env, _jc_cf_code *code, _jc_uint32 length,
-			_jc_uint32 *offset_map, _jc_uint32 *targetp);
+			_jc_uint16 *offset_map, _jc_uint16 length);
+static int	_jc_map_offset(_jc_env *env, _jc_cf_code *code, _jc_uint16 length,
+			_jc_uint16 *offset_map, _jc_uint16 *targetp);
 static int	_jc_parse_local8(_jc_cf_parse_state *s, _jc_cf_code *code,
 			_jc_uint16 *indexp);
 static int	_jc_parse_local16(_jc_cf_parse_state *s, _jc_cf_code *code,
@@ -963,12 +963,13 @@
 {
 	_jc_cf_parse_state state;
 	_jc_cf_parse_state *const s = &state;
-	_jc_uint32 *offset_map = NULL;
+	_jc_uint16 *offset_map = NULL;
 #if 0
 	_jc_cf_insn *new_insns;
 #endif
-	_jc_uint32 code_length;
+	_jc_uint16 code_length;
 	_jc_uint16 num_attrs;
+	_jc_uint32 u32;
 	int i;
 
 	/* Initialize parse state */
@@ -985,8 +986,15 @@
 		goto fail;
 	if (_jc_parse_uint16(s, &code->max_locals) != JNI_OK)
 		goto fail;
-	if (_jc_parse_uint32(s, &code_length) != JNI_OK)
+	if (_jc_parse_uint32(s, &u32) != JNI_OK)
 		goto fail;
+	if ((_jc_uint16)u32 != u32) {
+		_JC_EX_STORE(s->env, ClassFormatError,
+		    "Illegal `Code' attribute bytecode length %u",
+		    (unsigned int)u32);
+		goto fail;
+	}
+	code_length = (_jc_uint16)u32;
 	if (s->pos + code_length > s->length) {
 		_JC_EX_STORE(s->env, ClassFormatError,
 		    "`Code' attribute bytecode length overflow");
@@ -1000,7 +1008,6 @@
 	if ((code->insns = _jc_vm_zalloc(s->env,
 	    code_length * sizeof(*code->insns))) == NULL)
 		goto fail;
-	code->num_insns = -1;
 
 	/* Parse bytecode */
 	if (_jc_parse_bytecode(s, code, offset_map, code_length) != JNI_OK)
@@ -1027,25 +1034,21 @@
 		goto fail;
 	for (i = 0; i < code->num_traps; i++) {
 		_jc_cf_trap *const trap = &code->traps[i];
-		_jc_uint16 value16;
 
-		if (_jc_parse_uint16(s, &value16) != JNI_OK)
+		if (_jc_parse_uint16(s, &trap->start) != JNI_OK)
 			goto fail;
-		trap->start = value16;
 		if (_jc_map_offset(s->env, code, code_length,
 		    offset_map, &trap->start) != JNI_OK)
 			goto fail;
-		if (_jc_parse_uint16(s, &value16) != JNI_OK)
+		if (_jc_parse_uint16(s, &trap->end) != JNI_OK)
 			goto fail;
-		trap->end = value16;
 		if (trap->end == code_length)
 			trap->end = code->num_insns;
 		else if (_jc_map_offset(s->env, code, code_length,
 		    offset_map, &trap->end) != JNI_OK)
 			goto fail;
-		if (_jc_parse_uint16(s, &value16) != JNI_OK)
+		if (_jc_parse_uint16(s, &trap->target) != JNI_OK)
 			goto fail;
-		trap->target = value16;
 		if (_jc_map_offset(s->env, code, code_length,
 		    offset_map, &trap->target) != JNI_OK)
 			goto fail;
@@ -1146,7 +1149,7 @@
  */
 static int
 _jc_parse_bytecode(_jc_cf_parse_state *s, _jc_cf_code *code,
-	_jc_uint32 *offset_map, _jc_uint32 code_length)
+	_jc_uint16 *offset_map, _jc_uint16 code_length)
 {
 	const size_t start = s->pos;
 	const size_t end = s->pos + code_length;
@@ -1162,7 +1165,7 @@
 
 loop:
 	/* Sanity check */
-	_JC_ASSERT(code->num_insns == -1);
+	_JC_ASSERT(code->num_insns == 0);
 	_JC_ASSERT(s->pos <= end);
 	_JC_ASSERT(inum <= code_length);
 	_JC_ASSERT(inum == insn - code->insns);
@@ -1362,7 +1365,7 @@
 	    {
 		const char *const opname = _jc_bytecode_names[insn->opcode];
 		_jc_cf_lookupswitch *lsw;
-		_jc_uint32 default_target;
+		_jc_uint16 default_target;
 		jint num_pairs;
 		jint value32;
 		int pad;
@@ -1422,7 +1425,7 @@
 	    {
 		const char *const opname = _jc_bytecode_names[insn->opcode];
 		_jc_cf_tableswitch *tsw;
-		_jc_uint32 default_target;
+		_jc_uint16 default_target;
 		jint num_targets;
 		jint value32;
 		jint high;
@@ -1638,10 +1641,10 @@
  * Convert a bytecode offset into an instruction index.
  */
 static int
-_jc_map_offset(_jc_env *env, _jc_cf_code *code, _jc_uint32 length,
-	_jc_uint32 *offset_map, _jc_uint32 *targetp)
+_jc_map_offset(_jc_env *env, _jc_cf_code *code, _jc_uint16 length,
+	_jc_uint16 *offset_map, _jc_uint16 *targetp)
 {
-	_jc_uint32 target = *targetp;
+	_jc_uint16 target = *targetp;
 
 	if (target == 0)
 		return JNI_OK;

Modified: incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/cf_parse.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/cf_parse.h?rev=367060&r1=367059&r2=367060&view=diff
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/cf_parse.h (original)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/jchevm/jchevm/libjc/cf_parse.h Sun Jan
 8 10:14:25 2006
@@ -319,10 +319,10 @@
 };
 struct _jc_cf_lookup {
 	jint		match;
-	_jc_uint32	target;
+	_jc_uint16	target;
 };
 struct _jc_cf_lookupswitch {
-	_jc_uint32	default_target;
+	_jc_uint16	default_target;
 	jint		num_pairs;
 	_jc_cf_lookup	pairs[0];
 };
@@ -334,13 +334,13 @@
 	u_char		type;		/* _JC_TYPE_XXX */
 };
 struct _jc_cf_tableswitch {
-	_jc_uint32	default_target;
 	jint		low;
 	jint		high;
-	_jc_uint32	targets[0];
+	_jc_uint16	default_target;
+	_jc_uint16	targets[0];
 };
 struct _jc_cf_branch {
-	_jc_uint32	target;
+	_jc_uint16	target;
 };
 struct _jc_cf_local {
 	_jc_uint16	index;
@@ -383,15 +383,15 @@
 };
 
 struct _jc_cf_linemap {
-	_jc_uint32	index;			/* instruction index */
+	_jc_uint16	index;			/* instruction index */
 	_jc_uint16	line;
 };
 
 /* Parsed method trap */
 struct _jc_cf_trap {
-	_jc_uint32	start;			/* instruction index */
-	_jc_uint32	end;			/* instruction index */
-	_jc_uint32	target;			/* instruction index */
+	_jc_uint16	start;			/* instruction index */
+	_jc_uint16	end;			/* instruction index */
+	_jc_uint16	target;			/* instruction index */
 	const char	*type;
 };
 
@@ -408,7 +408,7 @@
 	_jc_uint16	max_locals;
 	_jc_uint16	num_traps;
 	_jc_uint16	num_linemaps;
-	_jc_uint32	num_insns;
+	_jc_uint16	num_insns;
 	_jc_cf_insn	*insns;
 	_jc_cf_trap	*traps;
 	_jc_cf_linemap	*linemaps;



Mime
View raw message