This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
fix for jsr routines that do not have returns
- From: Dan <d2walter at Oakland dot edu>
- To: java-patches at gcc dot gnu dot org
- Date: Sun, 2 Dec 2001 14:27:39 -0500 (EST)
- Subject: fix for jsr routines that do not have returns
example
void fail(){
try {
test();
} finally {
throw new RuntimeException("test exceptions");
}
}
When this is compiled with Sun's javac it produces .class files that fail
to verify or to compile because the jsr does not havee a ret.
I modified gcj to treat such jsr's as gotos.
I am not sure how to submit a patch for this. I used cvs diff -u because
I saw that in the some of the other patches.
Do I need to do anything else besides submit this here?
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/expr.c,v
retrieving revision 1.120
diff -u -r1.120 expr.c
--- expr.c 2001/12/02 10:44:54 1.120
+++ expr.c 2001/12/02 19:13:01
@@ -2849,10 +2849,16 @@
#define JSR(OPERAND_TYPE, OPERAND_VALUE) \
{ \
- tree where = lookup_label (oldpc+OPERAND_VALUE); \
- tree ret = lookup_label (PC); \
- build_java_jsr (where, ret); \
- load_type_state (ret); \
+ int target_pc = oldpc+OPERAND_VALUE; \
+ tree where = lookup_label (target_pc); \
+ if (RETURN_MAP_ADJUSTED (LABEL_RETURN_TYPE_STATE (where))) \
+ { \
+ tree ret = lookup_label (PC); \
+ build_java_jsr (where, ret); \
+ load_type_state (ret); \
+ } \
+ else /* if it never returns treat it as a goto */ \
+ expand_java_goto (target_pc); \
}
/* Push a constant onto the stack. */
Index: verify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/verify.c,v
retrieving revision 1.45
diff -u -r1.45 verify.c
--- verify.c 2001/09/14 00:16:36 1.45
+++ verify.c 2001/12/02 19:13:02
@@ -507,12 +507,11 @@
tree ret_map = LABEL_RETURN_TYPE_STATE (current_subr);
tmp = LABEL_RETURN_LABELS (current_subr);
- /* FIXME: If we exit a subroutine via a throw, we might
- have returned to an earlier caller. Obviously a
- "ret" can only return one level, but a throw may
- return many levels.*/
current_subr = caller;
+ /* if this subroutine can return normally process what the
+ state will be upon return. If it cannot return normally,
+ just continue processing the next pending code */
if (RETURN_MAP_ADJUSTED (ret_map))
{
/* Since we are done with this subroutine , set up
@@ -1168,8 +1167,9 @@
break;
case OPCODE_athrow:
- /* FIXME: athrow also empties the stack. */
POP_TYPE (throwable_type_node, "missing throwable at athrow" );
+ /* the rest of the stack is unimportant because execution
+ does not continue after athrow happens */
INVALIDATE_PC;
break;
@@ -1300,15 +1300,21 @@
if (LABEL_VERIFIED (target))
{
tree return_map = LABEL_RETURN_TYPE_STATE (target);
- int len = TREE_VEC_LENGTH (return_map);
- stack_pointer = len - DECL_MAX_LOCALS (current_function_decl);
- while (--len >= 0)
+ current_subr = LABEL_SUBR_CONTEXT (target);
+ /* execution can only contiune with the return_label
+ if the jsr can return normally */
+ if (RETURN_MAP_ADJUSTED (return_map))
{
- if (TREE_VEC_ELT (return_map, len) != TYPE_UNUSED)
- type_map[len] = TREE_VEC_ELT (return_map, len);
+ int len = TREE_VEC_LENGTH (return_map);
+ stack_pointer = len - DECL_MAX_LOCALS (current_function_decl);
+ while (--len >= 0)
+ {
+ if (TREE_VEC_ELT (return_map, len) != TYPE_UNUSED)
+ type_map[len] = TREE_VEC_ELT (return_map, len);
+ }
+
+ PUSH_PENDING (return_label);
}
- current_subr = LABEL_SUBR_CONTEXT (target);
- PUSH_PENDING (return_label);
}
INVALIDATE_PC;