gcj/232: segmentation violation at except.c:2180

Alexandre Petit-Bianco apbianco@cygnus.com
Wed Oct 18 21:40:00 GMT 2000


The following reply was made to PR gcj/232; it has been noted by GNATS.

From: Alexandre Petit-Bianco <apbianco@cygnus.com>
To: Fred Gray <fegray@uiuc.edu>
Cc: java-gnats@sourceware.cygnus.com
Subject: Re: gcj/232: segmentation violation at except.c:2180
Date: Wed, 18 Oct 2000 21:39:36 -0700 (PDT)

 Fred Gray writes:
 >  > The problem is that gcj does not like the use of a static final String as
 >  > a monitor lock.
 
 I have a patch for this.
 
 >  I think that this is an oversimplification of the situation, because the
 >  following also fails, though only when compiled from bytecode:
 
 Yes. From gcj's generated bytecodes. The patch also covers that. 
 
 Now I can build jetty v2.4.4 from source (with the exception of
 ./com/mortbay/HTTP/HttpTests.java which contains an error) and I can
 also build jetty from classes, as extracted from the tarball you
 posted.
 
 Let me know,
 
 ./A
 
 2000-10-18  Alexandre Petit-Bianco  <apbianco@cygnus.com>
 
 	* jcf-write.c (OP1): Update `last_bc'.
 	(struct jcf_block): Fixed indentation and typo in comments.  New
 	field `last_bc'.
 	(generate_bytecode_insns): Insert `nop' if `jsr' immediately
 	follows `monitorenter'.
 	* parse.y (patch_synchronized_statement): New local `tmp'. Call
 	`patch_string'.
 
 Index: jcf-write.c
 ===================================================================
 RCS file: /cvs/gcc/egcs/gcc/java/jcf-write.c,v
 retrieving revision 1.69
 diff -u -p -r1.69 jcf-write.c
 --- jcf-write.c	2000/09/23 17:09:39	1.69
 +++ jcf-write.c	2000/10/19 04:24:28
 @@ -57,7 +57,7 @@ char *jcf_write_base_directory = NULL;
  /* Add a 1-byte instruction/operand I to bytecode.data,
     assuming space has already been RESERVE'd. */
  
 -#define OP1(I) (*state->bytecode.ptr++ = (I), CHECK_OP(state))
 +#define OP1(I) (state->last_bc = *state->bytecode.ptr++ = (I), CHECK_OP(state))
  
  /* Like OP1, but I is a 2-byte big endian integer. */
  
 @@ -131,13 +131,14 @@ struct jcf_block
  
    int linenumber;
  
 -  /* After finish_jcf_block is called, The actual instructions contained in this block.
 -     Before than NULL, and the instructions are in state->bytecode. */
 +  /* After finish_jcf_block is called, The actual instructions
 +     contained in this block.  Before than NULL, and the instructions
 +     are in state->bytecode. */
    union {
      struct chunk *chunk;
  
      /* If pc==PENDING_CLEANUP_PC, start_label is the start of the region
 -       coveed by the cleanup. */
 +       covered by the cleanup. */
      struct jcf_block *start_label;
    } v;
  
 @@ -272,8 +273,10 @@ struct jcf_partial
    /* If non-NULL, use this for the return value. */
    tree return_value_decl;
  
 -  /* Information about the current switch statemenet. */
 +  /* Information about the current switch statement. */
    struct jcf_switch_state *sw_state;
 +
 +  enum java_opcode last_bc;	/* The last emitted bytecode */
  };
  
  static void generate_bytecode_insns PARAMS ((tree, int, struct jcf_partial *));
 @@ -2158,7 +2161,15 @@ generate_bytecode_insns (exp, target, st
  	tree src = TREE_OPERAND (exp, 0);
  	tree src_type = TREE_TYPE (src);
  	tree dst_type = TREE_TYPE (exp);
 -	generate_bytecode_insns (TREE_OPERAND (exp, 0), target, state);
 +	/* Detect the situation of compiling an empty synchronized
 +	   block.  A nop should be emitted in order to produce
 +	   verifiable bytecode. */
 +	if (exp == empty_stmt_node
 +	    && state->last_bc == OPCODE_monitorenter
 +	    && state->labeled_blocks->pc == PENDING_CLEANUP_PC)
 +	  OP1 (OPCODE_nop);
 +	else
 +	  generate_bytecode_insns (TREE_OPERAND (exp, 0), target, state);
  	if (target == IGNORE_TARGET || src_type == dst_type)
  	  break;
  	if (TREE_CODE (dst_type) == POINTER_TYPE)
 Index: parse.y
 ===================================================================
 RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
 retrieving revision 1.217
 diff -u -p -r1.217 parse.y
 --- parse.y	2000/10/19 04:19:09	1.217
 +++ parse.y	2000/10/19 04:25:04
 @@ -14745,13 +14745,17 @@ patch_synchronized_statement (node, wfl_
    tree expr = java_complete_tree (TREE_OPERAND (node, 0));
    tree block = TREE_OPERAND (node, 1);
  
 -  tree enter, exit, expr_decl, assignment;
 +  tree tmp, enter, exit, expr_decl, assignment;
  
    if (expr == error_mark_node)
      {
        block = java_complete_tree (block);
        return expr;
      }
 +
 +  /* We might be trying to synchronize on a STRING_CST */
 +  if ((tmp = patch_string (expr)))
 +    expr = tmp;
  
    /* The TYPE of expr must be a reference type */
    if (!JREFERENCE_TYPE_P (TREE_TYPE (expr)))


More information about the Java-prs mailing list