[PCH] final java patch

Geoffrey Keating geoffk@redhat.com
Fri Aug 9 12:14:00 GMT 2002


This makes 'struct JCF' and 'struct CPool' GCable.

Bootstrapped & tested on x86-linux with gcac checking.  I didn't wait
for the libjava testsuite to finish, because all the tests on it fail
even on the mainline (at the point of the last merge, anyway).

-- 
Geoff Keating <geoffk@redhat.com>

===File ~/patches/pchbranch-javajcfgc.patch=================
Index: ChangeLog
2002-08-08  Geoffrey Keating  <geoffk@redhat.com>

	* doc/gty.texi (GTY Options): Document %a.
	* gengtype.c (do_scalar_typedef): New function.
	(process_gc_options): Handle `length' option.
	(set_gc_used_type): A pointer to an array of structures doesn't
	qualify as a pointer to a structure.
	(output_escaped_param): Add `%a' escape.
	(write_gc_structure_fields): Allow 'desc' on array of unions.
	(main): Define `uint8', `jword' and `JCF_u2' as scalars; use
	do_scalar_typedef.

Index: java/ChangeLog
2002-08-08  Geoffrey Keating  <geoffk@redhat.com>

	* jcf.h (union cpool_entry): New.
	(struct CPool): Use gengtype to mark.  Change field 'data' to be
	an array of unions.
	(struct JCF): Use gengtype to mark.
	(CPOOL_UINT): Update for new cpool_entry type.
	(CPOOL_USHORT1): Likewise.
	(CPOOL_USHORT2): Likewise.
	(CPOOL_FINISH): Use GC to free cpool subfields.
	* parse.h (struct parser_ctxt): Mark field current_jcf.
	* lex.c (java_init_lex): Use GC to allocate struct JCF.
	* jcf-parse.c (HANDLE_CONSTANT_Utf8): Update for new cpool_entry type.
	(main_jcf): Use gengtype to mark.
	(ggc_mark_jcf): Delete.
	(get_constant): Update for new cpool_entry type.
	(give_name_to_class): Likewise.
	(get_class_constant): Likewise.
	(init_outgoing_cpool): Use GGC to allocate struct CPool.
	(java_parse_file): Use GGC to allocate struct JCF.
	(init_jcf_parse): Don't call ggc_add_root.
	* jcf-reader.c (jcf_parse_constant_pool): Update for new
	cpool_entry type.
	* java-tree.h (current_jcf): Use gengtype to mark.
	(CPOOL_UTF): Update for new cpool_entry type.
	(outgoing_cpool): Use gengtype to mark.
	(struct lang_type): GC struct JCF and struct CPool.
	* config-lang.in (gtfiles): Add jcf.h.
	* constants.c (find_tree_constant): New.
	(set_constant_entry): Allocate cpool subfields using GGC.  Update
	for new cpool_entry type.
	(find_constant1): Update for new cpool_entry type.
	(find_constant2): Likewise.
	(find_utf8_constant): Use find_tree_constant.
	(find_class_or_string_constant): Remove unnecessary cast to jword.
	Update for new cpool_entry type.
	(count_constant_pool_bytes): Update for new cpool_entry type.
	(write_constant_pool): Likewise.
	(alloc_name_constant): Use find_tree_constant.
	(build_constants_constructor): Update for new cpool_entry type.

Index: gengtype.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gengtype.c,v
retrieving revision 1.1.2.31
diff -p -u -p -r1.1.2.31 gengtype.c
--- gengtype.c	4 Aug 2002 20:49:36 -0000	1.1.2.31
+++ gengtype.c	9 Aug 2002 05:02:28 -0000
@@ -90,6 +90,7 @@ static type_p structures;
 static type_p param_structs;
 static pair_p variables;
 
+static void do_scalar_typedef PARAMS ((const char *, struct fileloc *));
 static type_p find_param_structure 
   PARAMS ((type_p t, type_p param[NUM_PARAM]));
 static type_p adjust_field_tree_exp PARAMS ((type_p t, options_p opt));
@@ -124,6 +125,16 @@ do_typedef (s, t, pos)
   typedefs = p;
 }
 
+/* Define S as a typename of a scalar.  */
+
+static void
+do_scalar_typedef (s, pos)
+     const char *s;
+     struct fileloc *pos;
+{
+  do_typedef (s, create_scalar_type (s, strlen (s)), pos);
+}
+
 /* Return the type previously defined for S.  Use POS to report errors.   */
 
 type_p
@@ -868,18 +879,19 @@ note_yacc_type (o, fields, typeinfo, pos
 }
 
 static void process_gc_options PARAMS ((options_p, enum gc_used_enum, 
-					int *, int *));
+					int *, int *, int *));
 static void set_gc_used_type PARAMS ((type_p, enum gc_used_enum, type_p *));
 static void set_gc_used PARAMS ((pair_p));
 
 /* Handle OPT for set_gc_used_type.  */
 
 static void
-process_gc_options (opt, level, maybe_undef, pass_param)
+process_gc_options (opt, level, maybe_undef, pass_param, length)
      options_p opt;
      enum gc_used_enum level;
      int *maybe_undef;
      int *pass_param;
+     int *length;
 {
   options_p o;
   for (o = opt; o; o = o->next)
@@ -889,6 +901,8 @@ process_gc_options (opt, level, maybe_un
       *maybe_undef = 1;
     else if (strcmp (o->name, "use_params") == 0)
       *pass_param = 1;
+    else if (strcmp (o->name, "length") == 0)
+      *length = 1;
 }
 
 /* Set the gc_used field of T to LEVEL, and handle the types it references.  */
@@ -912,15 +926,19 @@ set_gc_used_type (t, level, param)
 	pair_p f;
 	int dummy;
 
-	process_gc_options (t->u.s.opt, level, &dummy, &dummy);
+	process_gc_options (t->u.s.opt, level, &dummy, &dummy, &dummy);
 
 	for (f = t->u.s.fields; f; f = f->next)
 	  {
 	    int maybe_undef = 0;
 	    int pass_param = 0;
-	    process_gc_options (f->opt, level, &maybe_undef, &pass_param);
+	    int length = 0;
+	    process_gc_options (f->opt, level, &maybe_undef, &pass_param,
+				&length);
 	    
-	    if (maybe_undef && f->type->kind == TYPE_POINTER)
+	    if (length && f->type->kind == TYPE_POINTER)
+	      set_gc_used_type (f->type->u.p, GC_USED, NULL);
+	    else if (maybe_undef && f->type->kind == TYPE_POINTER)
 	      set_gc_used_type (f->type->u.p, GC_MAYBE_POINTED_TO, NULL);
 	    else if (pass_param && f->type->kind == TYPE_POINTER && param)
 	      set_gc_used_type (find_param_structure (f->type->u.p, param),
@@ -1380,15 +1398,30 @@ output_escaped_param (of, param, val, pr
   for (p = param; *p; p++)
     if (*p != '%')
       oprintf (of, "%c", *p);
-    else if (*++p == 'h')
-      oprintf (of, "(%s)", val);
-    else if (*p == '0')
-      oprintf (of, "(*x)");
-    else if (*p == '1')
-      oprintf (of, "(%s)", prev_val);
-    else
-      error_at_line (line, "`%s' option contains bad escape %c%c",
-		     oname, '%', *p);
+    else switch (*++p)
+      {
+      case 'h':
+	oprintf (of, "(%s)", val);
+	break;
+      case '0':
+	oprintf (of, "(*x)");
+	break;
+      case '1':
+	oprintf (of, "(%s)", prev_val);
+	break;
+      case 'a':
+	{
+	  const char *pp = val + strlen (val);
+	  while (pp[-1] == ']')
+	    while (*pp != '[')
+	      pp--;
+	  oprintf (of, "%s", pp);
+	}
+	break;
+      default:
+	error_at_line (line, "`%s' option contains bad escape %c%c",
+		       oname, '%', *p);
+      }
 }
 
 /* Print a mangled name representing T to OF.  */
@@ -1510,9 +1543,9 @@ write_gc_structure_fields (of, s, val, p
 	  skip_p = 1;
 	else if (strcmp (oo->name, "default") == 0)
 	  default_p = 1;
-	else if (strcmp (oo->name, "desc") == 0 && UNION_P (t))
+	else if (strcmp (oo->name, "desc") == 0)
 	  ;
- 	else if (strcmp (oo->name, "descbits") == 0 && UNION_P (t))
+ 	else if (strcmp (oo->name, "descbits") == 0)
 	  ;
  	else if (strcmp (oo->name, "param_is") == 0)
 	  ;
@@ -2542,18 +2575,15 @@ main(argc, argv)
 
   srcdir_len = strlen (srcdir);
 
-  do_typedef ("CUMULATIVE_ARGS",
-	      create_scalar_type ("CUMULATIVE_ARGS", 
-				  strlen ("CUMULATIVE_ARGS")),
-	      &pos);
-  do_typedef ("REAL_VALUE_TYPE",
-	      create_scalar_type ("REAL_VALUE_TYPE", 
-				  strlen ("REAL_VALUE_TYPE")),
-	      &pos);
+  do_scalar_typedef ("CUMULATIVE_ARGS", &pos);
+  do_scalar_typedef ("REAL_VALUE_TYPE", &pos);
+  do_scalar_typedef ("uint8", &pos);
+  do_scalar_typedef ("jword", &pos);
+  do_scalar_typedef ("JCF_u2", &pos);
+
   do_typedef ("PTR", create_pointer (create_scalar_type ("void",
 							 strlen ("void"))),
 	      &pos);
-
   do_typedef ("HARD_REG_SET", create_array (
 	      create_scalar_type ("unsigned long", strlen ("unsigned long")),
 	      "2"), &pos);
Index: doc/gty.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/gty.texi,v
retrieving revision 1.1.2.6
diff -p -u -p -r1.1.2.6 gty.texi
--- doc/gty.texi	24 Jul 2002 20:09:59 -0000	1.1.2.6
+++ doc/gty.texi	9 Aug 2002 05:02:30 -0000
@@ -72,6 +72,10 @@ immediately contains the current structu
 @item %0
 This expands to an expression that evaluates to the outermost structure
 that contains the current structure.
+@item %a
+This expands to the string of the form @code{[i1][i2]...} that indexes
+the array item currently being marked.  For instance, if the field
+being marked is @code{foo}, then @code{%1.foo%a} is the same as @code{%h}.
 @end table
 
 The available options are:
Index: java/config-lang.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/config-lang.in,v
retrieving revision 1.12.6.3
diff -p -u -p -r1.12.6.3 config-lang.in
--- java/config-lang.in	8 Aug 2002 22:57:16 -0000	1.12.6.3
+++ java/config-lang.in	9 Aug 2002 05:02:32 -0000
@@ -36,7 +36,7 @@ compilers="jc1\$(exeext) jvgenmain\$(exe
 
 stagestuff="jc1\$(exeext) gcj\$(exeext) jvgenmain\$(exeext) gcjh\$(exeext) jv-scan\$(exeext) jcf-dump\$(exeext)"
 
-gtfiles="\$(srcdir)/java/java-tree.h \$(srcdir)/java/lex.h \$(srcdir)/java/parse.h \$(srcdir)/java/builtins.c \$(srcdir)/java/class.c \$(srcdir)/java/constants.c \$(srcdir)/java/decl.c \$(srcdir)/java/expr.c \$(srcdir)/java/jcf-parse.c \$(srcdir)/java/jcf-write.c \$(srcdir)/java/lang.c \$(srcdir)/java/mangle.c \$(srcdir)/java/parse.y"
+gtfiles="\$(srcdir)/java/java-tree.h \$(srcdir)/java/jcf.h \$(srcdir)/java/lex.h \$(srcdir)/java/parse.h \$(srcdir)/java/builtins.c \$(srcdir)/java/class.c \$(srcdir)/java/constants.c \$(srcdir)/java/decl.c \$(srcdir)/java/expr.c \$(srcdir)/java/jcf-parse.c \$(srcdir)/java/jcf-write.c \$(srcdir)/java/lang.c \$(srcdir)/java/mangle.c \$(srcdir)/java/parse.y"
 
 target_libs=${libgcj_saved}
 lang_dirs="zlib fastjar"
Index: java/constants.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/constants.c,v
retrieving revision 1.19.18.1
diff -p -u -p -r1.19.18.1 constants.c
--- java/constants.c	6 Apr 2002 00:08:52 -0000	1.19.18.1
+++ java/constants.c	9 Aug 2002 05:02:33 -0000
@@ -32,6 +32,7 @@ The Free Software Foundation is independ
 extern struct obstack permanent_obstack;
 
 static void set_constant_entry PARAMS ((CPool *, int, int, jword));
+static int find_tree_constant  PARAMS ((CPool *, int, tree));
 static int find_class_or_string_constant PARAMS ((CPool *, int, tree));
 static int find_name_and_type_constant PARAMS ((CPool *, tree, tree));
 static tree get_tag_node PARAMS ((int));
@@ -49,8 +50,8 @@ set_constant_entry (cpool, index, tag, v
   if (cpool->data == NULL)
     {
       cpool->capacity = 100;
-      cpool->tags = (uint8*) xmalloc (sizeof(uint8) * cpool->capacity);
-      cpool->data = (jword*) xmalloc (sizeof(jword) * cpool->capacity);
+      cpool->tags = (uint8*) ggc_alloc (sizeof(uint8) * cpool->capacity);
+      cpool->data = ggc_alloc (sizeof (union cpool_entry) * cpool->capacity);
       cpool->count = 1;
     }
   if (index >= cpool->capacity)
@@ -58,15 +59,15 @@ set_constant_entry (cpool, index, tag, v
       cpool->capacity *= 2;
       if (index >= cpool->capacity)
 	cpool->capacity = index + 10;
-      cpool->tags = (uint8*) xrealloc (cpool->tags,
-				       sizeof(uint8) * cpool->capacity);
-      cpool->data = (jword*) xrealloc (cpool->data,
-				       sizeof(jword) * cpool->capacity);
+      cpool->tags = (uint8*) ggc_realloc (cpool->tags,
+					  sizeof(uint8) * cpool->capacity);
+      cpool->data = ggc_realloc (cpool->data,
+				 sizeof (union cpool_entry) * cpool->capacity);
     }
   if (index >= cpool->count)
     cpool->count = index + 1;
   cpool->tags[index] = tag;
-  cpool->data[index] = value;
+  cpool->data[index].w = value;
 }
 
 /* Find (or create) a constant pool entry matching TAG and VALUE. */
@@ -80,7 +81,7 @@ find_constant1 (cpool, tag, value)
   int i;
   for (i = cpool->count;  --i > 0; )
     {
-      if (cpool->tags[i] == tag && cpool->data[i] == value)
+      if (cpool->tags[i] == tag && cpool->data[i].w == value)
 	return i;
     }
   i = cpool->count == 0 ? 1 : cpool->count;
@@ -100,8 +101,8 @@ find_constant2 (cpool, tag, word1, word2
   for (i = cpool->count - 1;  --i > 0; )
     {
       if (cpool->tags[i] == tag
-	  && cpool->data[i] == word1
-	  && cpool->data[i+1] == word2)
+	  && cpool->data[i].w == word1
+	  && cpool->data[i+1].w == word2)
 	return i;
     }
   i = cpool->count == 0 ? 1 : cpool->count;
@@ -110,6 +111,25 @@ find_constant2 (cpool, tag, word1, word2
   return i;
 }
 
+static int
+find_tree_constant (cpool, tag, value)
+     CPool *cpool;
+     int tag;
+     tree value;
+{
+  int i;
+  for (i = cpool->count;  --i > 0; )
+    {
+      if (cpool->tags[i] == tag && cpool->data[i].t == value)
+	return i;
+    }
+  i = cpool->count == 0 ? 1 : cpool->count;
+  set_constant_entry (cpool, i, tag, 0);
+  cpool->data[i].t = value;
+  return i;
+}
+
+
 int
 find_utf8_constant (cpool, name)
      CPool *cpool;
@@ -117,7 +137,7 @@ find_utf8_constant (cpool, name)
 {
   if (name == NULL_TREE)
     return 0;
-  return find_constant1 (cpool, CONSTANT_Utf8, (jword) name);
+  return find_tree_constant (cpool, CONSTANT_Utf8, name);
 }
 
 static int
@@ -126,15 +146,15 @@ find_class_or_string_constant (cpool, ta
      int tag;
      tree name;
 {
-  int j = find_utf8_constant (cpool, name);
+  jword j = find_utf8_constant (cpool, name);
   int i;
   for (i = cpool->count;  --i > 0; )
     {
-      if (cpool->tags[i] == tag && cpool->data[i] == (jword) j)
+      if (cpool->tags[i] == tag && cpool->data[i].w == j)
 	return i;
     }
   i = cpool->count;
-  set_constant_entry (cpool, i, tag, (jword) j);
+  set_constant_entry (cpool, i, tag, j);
   return i;
 }
 
@@ -257,7 +277,7 @@ count_constant_pool_bytes (cpool)
 	  break;
 	case CONSTANT_Utf8:
 	  {
-	    tree t = (tree) cpool->data[i];
+	    tree t = cpool->data[i].t;
 	    int len = IDENTIFIER_LENGTH (t);
 	    size += len + 2;
 	  }
@@ -281,7 +301,7 @@ write_constant_pool (cpool, buffer, leng
 {
   unsigned char *ptr = buffer;
   int i = 1;
-  jword *datap = &cpool->data[1];
+  union cpool_entry *datap = &cpool->data[1];
   PUT2 (cpool->count);
   for ( ;  i < cpool->count;  i++, datap++)
     {
@@ -295,23 +315,23 @@ write_constant_pool (cpool, buffer, leng
 	case CONSTANT_InterfaceMethodref:
 	case CONSTANT_Float:
 	case CONSTANT_Integer:
-	  PUT4 (*datap);
+	  PUT4 (datap->w);
 	  break;
 	case CONSTANT_Class:
 	case CONSTANT_String:
-	  PUT2 (*datap);
+	  PUT2 (datap->w);
 	  break;
 	  break;
 	case CONSTANT_Long:
 	case CONSTANT_Double:
-	  PUT4(*datap);
+	  PUT4(datap->w);
 	  i++;
 	  datap++;
-	  PUT4 (*datap);
+	  PUT4 (datap->w);
 	  break;
 	case CONSTANT_Utf8:
 	  {
-	    tree t = (tree) *datap;
+	    tree t = datap->t;
 	    int len = IDENTIFIER_LENGTH (t);
 	    PUT2 (len);
 	    PUTN (IDENTIFIER_POINTER (t), len);
@@ -349,7 +369,7 @@ alloc_name_constant (tag, name)
      int tag;
      tree name;
 {
-  return find_constant1 (outgoing_cpool, tag, (jword) name);
+  return find_tree_constant (outgoing_cpool, tag, name);
 }
 
 /* Build an identifier for the internal name of reference type TYPE. */
@@ -438,7 +458,7 @@ build_constants_constructor ()
 	= tree_cons (NULL_TREE, get_tag_node (outgoing_cpool->tags[i]),
 		     tags_list);
       data_list
-	= tree_cons (NULL_TREE, build_utf8_ref ((tree)outgoing_cpool->data[i]),
+	= tree_cons (NULL_TREE, build_utf8_ref (outgoing_cpool->data[i].t),
 		     data_list);
     }
   if (outgoing_cpool->count > 0)
Index: java/java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.133.6.10
diff -p -u -p -r1.133.6.10 java-tree.h
--- java/java-tree.h	4 Aug 2002 20:49:41 -0000	1.133.6.10
+++ java/java-tree.h	9 Aug 2002 05:02:33 -0000
@@ -222,7 +222,7 @@ extern int flag_store_check;
 extern const char *current_encoding;
 
 /* The Java .class file that provides main_class;  the main input file. */
-extern struct JCF *current_jcf;
+extern GTY(()) struct JCF * current_jcf;
 
 typedef struct CPool constant_pool;
 
@@ -234,7 +234,7 @@ typedef struct CPool constant_pool;
 /* The cpool->data[i] for a ResolvedClass points to a RECORD_TYPE. */
 #define CONSTANT_ResolvedClass     (CONSTANT_Class+CONSTANT_ResolvedFlag)
 
-#define CPOOL_UTF(CPOOL, INDEX) ((tree) (CPOOL)->data[INDEX])
+#define CPOOL_UTF(CPOOL, INDEX) ((CPOOL)->data[INDEX].t)
 
 /* A NameAndType constant is represented as a TREE_LIST.
    The type is the signature string (as an IDENTIFIER_NODE).  */
@@ -669,7 +669,7 @@ extern GTY(()) tree java_global_trees[JT
 #define nativecode_ptr_type_node ptr_type_node
 
 /* They need to be reset before processing each class */
-extern struct CPool *outgoing_cpool; 
+extern GTY(()) struct CPool *outgoing_cpool; 
 /* If non-NULL, an ADDR_EXPR referencing a VAR_DECL containing
    the constant data array for the current class. */
 #define current_constant_pool_data_ref \
@@ -1047,8 +1047,8 @@ struct lang_decl GTY(())
 struct lang_type GTY(())
 {
   tree signature;
-  struct JCF * GTY ((skip (""))) jcf;
-  struct CPool * GTY ((skip (""))) cpool;
+  struct JCF * jcf;
+  struct CPool * cpool;
   tree cpool_data_ref;		/* Cached */
   tree finit_stmt_list;		/* List of statements finit$ will use */
   tree clinit_stmt_list;	/* List of statements <clinit> will use  */
Index: java/jcf-parse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-parse.c,v
retrieving revision 1.101.2.5
diff -p -u -p -r1.101.2.5 jcf-parse.c
--- java/jcf-parse.c	24 Jun 2002 23:27:57 -0000	1.101.2.5
+++ java/jcf-parse.c	9 Aug 2002 05:02:33 -0000
@@ -60,7 +60,7 @@ The Free Software Foundation is independ
     text = (JCF)->read_ptr; \
     save = text[LENGTH]; \
     text[LENGTH] = 0; \
-    (JCF)->cpool.data[INDEX] = (jword) get_identifier (text); \
+    (JCF)->cpool.data[INDEX].t = get_identifier (text); \
     text[LENGTH] = save; \
     JCF_SKIP (JCF, LENGTH); } while (0)
 
@@ -86,7 +86,7 @@ static GTY(()) tree parse_roots[3];
 #define current_file_list parse_roots[2]
 
 /* The Java archive that provides main_class;  the main input file. */
-static struct JCF main_jcf[1];
+static GTY(()) struct JCF * main_jcf;
 
 static struct ZipFile *localToFile;
 
@@ -100,33 +100,9 @@ static void parse_source_file_2 PARAMS (
 static void parse_source_file_3 PARAMS ((void));
 static void parse_class_file PARAMS ((void));
 static void set_source_filename PARAMS ((JCF *, int));
-static void ggc_mark_jcf PARAMS ((void**));
 static void jcf_parse PARAMS ((struct JCF*));
 static void load_inner_classes PARAMS ((tree));
 
-/* Mark (for garbage collection) all the tree nodes that are
-   referenced from JCF's constant pool table. Do that only if the JCF
-   hasn't been marked finished.  */
-
-static void
-ggc_mark_jcf (elt)
-     void **elt;
-{
-  JCF *jcf = *(JCF**) elt;
-  if (jcf != NULL && !jcf->finished)
-    {
-      CPool *cpool = &jcf->cpool;
-      int size = CPOOL_COUNT(cpool);
-      int index;
-      for (index = 1; index < size;  index++)
-	{
-	  int tag = JPOOL_TAG (jcf, index);
-	  if ((tag & CONSTANT_ResolvedFlag) || tag == CONSTANT_Utf8)
-	    ggc_mark_tree ((tree) cpool->data[index]);
-	}
-    }
-}
-
 /* Handle "SourceFile" attribute. */
 
 static void
@@ -270,7 +246,7 @@ get_constant (jcf, index)
     goto bad;
   tag = JPOOL_TAG (jcf, index);
   if ((tag & CONSTANT_ResolvedFlag) || tag == CONSTANT_Utf8)
-    return (tree) jcf->cpool.data[index];
+    return jcf->cpool.data[index].t;
   switch (tag)
     {
     case CONSTANT_Integer:
@@ -363,7 +339,7 @@ get_constant (jcf, index)
       goto bad;
     }
   JPOOL_TAG (jcf, index) = tag | CONSTANT_ResolvedFlag;
-  jcf->cpool.data [index] = (jword) value;
+  jcf->cpool.data[index].t = value;
   return value;
  bad:
   internal_error ("bad value constant type %d, index %d", 
@@ -446,7 +422,7 @@ give_name_to_class (jcf, i)
       if (main_input_filename == NULL && jcf == main_jcf)
 	main_input_filename = input_filename;
 
-      jcf->cpool.data[i] = (jword) this_class;
+      jcf->cpool.data[i].t = this_class;
       JPOOL_TAG (jcf, i) = CONSTANT_ResolvedClass;
       return this_class;
     }
@@ -476,11 +452,11 @@ get_class_constant (JCF *jcf , int i)
           tree cname = unmangle_classname (name, nlength);
           type = lookup_class (cname);
 	}
-      jcf->cpool.data[i] = (jword) type;
+      jcf->cpool.data[i].t = type;
       JPOOL_TAG (jcf, i) = CONSTANT_ResolvedClass;
     }
   else
-    type = (tree) jcf->cpool.data[i];
+    type = jcf->cpool.data[i].t;
   return type;
 }
 
@@ -721,8 +697,7 @@ void
 init_outgoing_cpool ()
 {
   current_constant_pool_data_ref = NULL_TREE;
-  outgoing_cpool = (struct CPool *)xmalloc (sizeof (struct CPool));
-  memset (outgoing_cpool, 0, sizeof (struct CPool));
+  outgoing_cpool = (struct CPool *) ggc_alloc_cleared (sizeof (struct CPool));
 }
 
 static void
@@ -1086,7 +1061,7 @@ java_parse_file (set_yydebug)
       if (magic == 0xcafebabe)
 	{
 	  CLASS_FILE_P (node) = 1;
-	  current_jcf = ALLOC (sizeof (JCF));
+	  current_jcf = ggc_alloc (sizeof (JCF));
 	  JCF_ZERO (current_jcf);
 	  current_jcf->read_state = finput;
 	  current_jcf->filbuf = jcf_filbuf_from_stdio;
@@ -1098,6 +1073,7 @@ java_parse_file (set_yydebug)
       else if (magic == (JCF_u4)ZIPMAGIC)
 	{
 	  ZIP_FILE_P (node) = 1;
+	  main_jcf = ggc_alloc (sizeof (JCF));
 	  JCF_ZERO (main_jcf);
 	  main_jcf->read_state = finput;
 	  main_jcf->filbuf = jcf_filbuf_from_stdio;
@@ -1267,9 +1243,6 @@ process_zip_dir (FILE *finput)
 void
 init_jcf_parse ()
 {
-  /* Register roots with the garbage collector.  */
-  ggc_add_root (&current_jcf, 1, sizeof (JCF), (void (*)(void *))ggc_mark_jcf);
-
   init_src_parse ();
 }
 
Index: java/jcf-reader.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf-reader.c,v
retrieving revision 1.15
diff -p -u -p -r1.15 jcf-reader.c
--- java/jcf-reader.c	23 Mar 2001 19:42:25 -0000	1.15
+++ java/jcf-reader.c	9 Aug 2002 05:02:33 -0000
@@ -284,25 +284,25 @@ DEFUN(jcf_parse_constant_pool, (jcf),
 	{
 	case CONSTANT_String:
 	case CONSTANT_Class:
-	  jcf->cpool.data[i] = JCF_readu2 (jcf);
+	  jcf->cpool.data[i].w = JCF_readu2 (jcf);
 	  break;
 	case CONSTANT_Fieldref:
 	case CONSTANT_Methodref:
 	case CONSTANT_InterfaceMethodref:
 	case CONSTANT_NameAndType:
-	  jcf->cpool.data[i] = JCF_readu2 (jcf);
-	  jcf->cpool.data[i] |= JCF_readu2 (jcf) << 16;
+	  jcf->cpool.data[i].w = JCF_readu2 (jcf);
+	  jcf->cpool.data[i].w |= JCF_readu2 (jcf) << 16;
 	  break;
 	case CONSTANT_Integer:
 	case CONSTANT_Float:
-	  jcf->cpool.data[i] = JCF_readu4 (jcf);
+	  jcf->cpool.data[i].w = JCF_readu4 (jcf);
 	  break;
 	case CONSTANT_Long:
 	case CONSTANT_Double:
-	  jcf->cpool.data[i] = JCF_readu4 (jcf);
+	  jcf->cpool.data[i].w = JCF_readu4 (jcf);
 	  i++; /* These take up two spots in the constant pool */
 	  jcf->cpool.tags[i] = 0;
-	  jcf->cpool.data[i] = JCF_readu4 (jcf);
+	  jcf->cpool.data[i].w = JCF_readu4 (jcf);
 	  break;
 	case CONSTANT_Utf8:
 	  n = JCF_readu2 (jcf);
@@ -310,7 +310,7 @@ DEFUN(jcf_parse_constant_pool, (jcf),
 #ifdef HANDLE_CONSTANT_Utf8
 	  HANDLE_CONSTANT_Utf8(jcf, i, n);
 #else
-	  jcf->cpool.data[i] = JCF_TELL(jcf) - 2;
+	  jcf->cpool.data[i].w = JCF_TELL(jcf) - 2;
 	  JCF_SKIP (jcf, n);
 #endif
 	  break;
Index: java/jcf.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jcf.h,v
retrieving revision 1.26.6.3
diff -p -u -p -r1.26.6.3 jcf.h
--- java/jcf.h	24 Jun 2002 23:28:00 -0000	1.26.6.3
+++ java/jcf.h	9 Aug 2002 05:02:33 -0000
@@ -74,7 +74,15 @@ The Free Software Foundation is independ
 struct JCF;
 typedef int (*jcf_filbuf_t) PARAMS ((struct JCF*, int needed));
 
-typedef struct CPool {
+union cpool_entry GTY(()) {
+  jword GTY ((tag ("0"))) w;
+  tree GTY ((tag ("1"))) t;
+};
+
+#define cpool_entry_is_tree(tag) \
+  (tag & CONSTANT_ResolvedFlag) || tag == CONSTANT_Utf8
+
+typedef struct CPool GTY(()) {
   /* Available number of elements in the constants array, before it
      must be re-allocated. */
   int capacity;
@@ -82,29 +90,33 @@ typedef struct CPool {
   /* The constant_pool_count. */
   int		count;
 
-  uint8*	tags;
+  uint8* GTY((length ("%h.count")))	tags;
 
-  jword*	data;
+  union cpool_entry * GTY((length ("%h.count"),
+			   desc ("cpool_entry_is_tree (%1.tags%a)")))	data;
 } CPool;
 
 struct ZipDirectory;
 
 /* JCF encapsulates the state of reading a Java Class File. */
 
-typedef struct JCF {
-  unsigned char *buffer;
-  unsigned char *buffer_end;
-  unsigned char *read_ptr;
-  unsigned char *read_end;
+typedef struct JCF GTY(()) {
+  unsigned char * GTY ((skip (""))) buffer;
+  unsigned char * GTY ((skip (""))) buffer_end;
+  unsigned char * GTY ((skip (""))) read_ptr;
+  unsigned char * GTY ((skip (""))) read_end;
   int java_source : 1;
   int right_zip : 1;
   int finished : 1;
   jcf_filbuf_t filbuf;
-  void *read_state;
+  PTR GTY ((skip (""))) read_state;
   const char *filename;
   const char *classname;
-  struct ZipDirectory *zipd;	/* Directory entry where it was found */
-  JCF_u2 access_flags, this_class, super_class;
+  /* Directory entry where it was found.  */
+  struct ZipDirectory * GTY ((skip (""))) zipd;
+  JCF_u2 access_flags;
+  JCF_u2 this_class;
+  JCF_u2 super_class;
   CPool cpool;
 } JCF;
 /*typedef JCF*  JCF_FILE;*/
@@ -119,13 +131,13 @@ typedef struct JCF {
 #define JPOOL_SIZE(JCF) CPOOL_COUNT(&(JCF)->cpool)
 #define JPOOL_TAG(JCF, INDEX) ((JCF)->cpool.tags[INDEX])
 /* The INDEX'th constant pool entry as a JCF_u4. */
-#define CPOOL_UINT(CPOOL, INDEX) ((CPOOL)->data[INDEX])
+#define CPOOL_UINT(CPOOL, INDEX) ((CPOOL)->data[INDEX].w)
 #define JPOOL_UINT(JCF, INDEX) CPOOL_UINT(&(JCF)->cpool, INDEX) /*deprecated*/
 /* The first uint16 of the INDEX'th constant pool entry. */
-#define CPOOL_USHORT1(CPOOL, INDEX) ((CPOOL)->data[INDEX] & 0xFFFF)
+#define CPOOL_USHORT1(CPOOL, INDEX) ((CPOOL)->data[INDEX].w & 0xFFFF)
 #define JPOOL_USHORT1(JCF, INDEX) CPOOL_USHORT1(&(JCF)->cpool, INDEX)
 /* The second uint16 of the INDEX'th constant pool entry. */
-#define CPOOL_USHORT2(CPOOL, INDEX) ((CPOOL)->data[INDEX] >> 16)
+#define CPOOL_USHORT2(CPOOL, INDEX) ((CPOOL)->data[INDEX].w >> 16)
 #define JPOOL_USHORT2(JCF, INDEX) CPOOL_USHORT2(&(JCF)->cpool, INDEX)
 #define JPOOL_LONG(JCF, INDEX) \
   WORDS_TO_LONG (JPOOL_UINT(JCF, INDEX), JPOOL_UINT(JCF, (INDEX)+1))
@@ -145,9 +157,10 @@ typedef struct JCF {
 #define CPOOL_INDEX_IN_RANGE(CPOOL, INDEX) \
  ((INDEX) > 0 && (INDEX) < CPOOL_COUNT(CPOOL))
 
-#define CPOOL_FINISH(CPOOL) { \
-  if ((CPOOL)->tags) FREE ((CPOOL)->tags); \
-  if ((CPOOL)->data) FREE ((CPOOL)->data); }
+#define CPOOL_FINISH(CPOOL) {			\
+    (CPOOL)->tags = 0;				\
+    (CPOOL)->data = 0;				\
+  }
 
 #define JCF_FINISH(JCF) { \
   CPOOL_FINISH(&(JCF)->cpool); \
Index: java/lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lex.c,v
retrieving revision 1.80.6.4
diff -p -u -p -r1.80.6.4 lex.c
--- java/lex.c	24 Jul 2002 20:10:06 -0000	1.80.6.4
+++ java/lex.c	9 Aug 2002 05:02:33 -0000
@@ -129,7 +129,7 @@ java_init_lex (finput, encoding)
     CPC_INSTANCE_INITIALIZER_LIST (ctxp) = NULL_TREE;
 
   memset ((PTR) ctxp->modifier_ctx, 0, sizeof (ctxp->modifier_ctx));
-  memset ((PTR) current_jcf, 0, sizeof (JCF));
+  current_jcf = ggc_alloc_cleared (sizeof (JCF));
   ctxp->current_parsed_class = NULL;
   ctxp->package = NULL_TREE;
 #endif
Index: java/parse.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.h,v
retrieving revision 1.81.6.3
diff -p -u -p -r1.81.6.3 parse.h
--- java/parse.h	8 Aug 2002 22:57:16 -0000	1.81.6.3
+++ java/parse.h	9 Aug 2002 05:02:33 -0000
@@ -763,7 +763,7 @@ struct parser_ctxt GTY(()) {
   tree class_type;		    /* Current class */
   tree function_decl;	            /* Current function decl, save/restore */
 
-  struct JCF * GTY((skip (""))) current_jcf; /* CU jcf */
+  struct JCF * current_jcf;	    /* CU jcf */
 
   int prevent_ese;	            /* Prevent expression statement error */
 
============================================================



More information about the Gcc-patches mailing list