diff options
Diffstat (limited to 'gcc/java')
-rw-r--r-- | gcc/java/ChangeLog | 74 | ||||
-rw-r--r-- | gcc/java/Make-lang.in | 8 | ||||
-rw-r--r-- | gcc/java/config-lang.in | 2 | ||||
-rw-r--r-- | gcc/java/constants.c | 64 | ||||
-rw-r--r-- | gcc/java/gjavah.c | 1 | ||||
-rw-r--r-- | gcc/java/java-tree.h | 10 | ||||
-rw-r--r-- | gcc/java/jcf-dump.c | 1 | ||||
-rw-r--r-- | gcc/java/jcf-parse.c | 49 | ||||
-rw-r--r-- | gcc/java/jcf-reader.c | 18 | ||||
-rw-r--r-- | gcc/java/jcf.h | 49 | ||||
-rw-r--r-- | gcc/java/lex.c | 2 | ||||
-rw-r--r-- | gcc/java/lex.h | 7 | ||||
-rw-r--r-- | gcc/java/parse.h | 33 | ||||
-rw-r--r-- | gcc/java/parse.y | 76 |
14 files changed, 211 insertions, 183 deletions
diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 34d39a45214..00b5e50a9fb 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,77 @@ +2003-01-09 Geoffrey Keating <geoffk@apple.com> + + Merge from pch-branch: + + 2002-12-02 Geoffrey Keating <geoffk@apple.com> + + * Make-lang.in (java/gjavah.o): Update dependencies. + * gjavah.c: Include ggc.h. + + 2002-08-16 Geoffrey Keating <geoffk@redhat.com> + + * Make-lang.in (GCJH_OBJS): Add ggc-none.o. + (JCFDUMP_OBJS): Add ggc-none.o. + (java/jcf-dump.o): Depend on GGC_H. + * jcf-reader.c (jcf_parse_constant_pool): Use ggc_alloc to allocate + CPool substructures. + * jcf-parse.c (process_zip_dir): Use ggc_alloc to allocate JCFs. + * jcf-dump.c: Include ggc.h. + + 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. + + 2002-08-08 Geoffrey Keating <geoffk@redhat.com> + + * parse.y (mark_parser_ctxt): Delete. + (goal): Don't use ggc_add_root. + (create_new_parser_context): Use GC to allocate struct parser_ctxt. + (java_pop_parser_context): Let GC free parser_ctxt. + (java_parser_context_resume): Likewise. + * parse.h (struct parser_ctxt): Use gengtype to mark. + (ctxp): Likewise. + (ctxp_for_generation): Likewise. + * lex.h (struct java_lc_s): Mark for gengtype. + (java_lexer): Rearrange for gengtype. + * config-lang.in (gtfiles): Add lex.h, parse.h. + 2003-01-09 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> * All Files: Remove PARAMS macro. diff --git a/gcc/java/Make-lang.in b/gcc/java/Make-lang.in index b04a975630e..bd839d6a354 100644 --- a/gcc/java/Make-lang.in +++ b/gcc/java/Make-lang.in @@ -113,12 +113,12 @@ JAVA_OBJS = java/parse.o java/class.o java/decl.o java/expr.o \ java/jcf-path.o java/xref.o java/boehm.o java/java-tree-inline.o mkdeps.o GCJH_OBJS = java/gjavah.o java/jcf-io.o java/jcf-depend.o java/jcf-path.o \ - java/zextract.o version.o mkdeps.o errors.o + java/zextract.o version.o mkdeps.o errors.o ggc-none.o JVSCAN_OBJS = java/parse-scan.o java/jv-scan.o version.o JCFDUMP_OBJS = java/jcf-dump.o java/jcf-io.o java/jcf-depend.o java/jcf-path.o \ - java/zextract.o errors.o version.o mkdeps.o + java/zextract.o errors.o version.o mkdeps.o ggc-none.o JVGENMAIN_OBJS = java/jvgenmain.o java/mangle_name.o errors.o @@ -267,9 +267,9 @@ java/parse.o: java/parse.c java/jcf-reader.c $(CONFIG_H) $(SYSTEM_H) \ java/lex.h $(GGC_H) debug.h gt-java-parse.h gtype-java.h java/jcf-dump.o: $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(JAVA_TREE_H) \ java/jcf-dump.c java/jcf-reader.c java/jcf.h java/javaop.h java/javaop.def \ - version.h + version.h $(GGC_H) java/gjavah.o: $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(JAVA_TREE_H) \ - java/gjavah.c java/jcf-reader.c java/jcf.h java/javaop.h version.h + java/gjavah.c java/jcf-reader.c java/jcf.h java/javaop.h version.h $(GGC_H) java/boehm.o: java/boehm.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ $(TREE_H) $(JAVA_TREE_H) java/parse.h toplev.h java/buffer.o: java/buffer.c $(CONFIG_H) java/buffer.h $(SYSTEM_H) coretypes.h \ diff --git a/gcc/java/config-lang.in b/gcc/java/config-lang.in index 993763ed500..05a6fdff7e7 100644 --- a/gcc/java/config-lang.in +++ b/gcc/java/config-lang.in @@ -36,7 +36,7 @@ compilers="jc1\$(exeext) jvgenmain\$(exeext)" stagestuff="jc1\$(exeext) gcj\$(exeext) jvgenmain\$(exeext) gcjh\$(exeext) jv-scan\$(exeext) jcf-dump\$(exeext)" -gtfiles="\$(srcdir)/java/java-tree.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" diff --git a/gcc/java/constants.c b/gcc/java/constants.c index 11efc2bf0c0..a1872387f18 100644 --- a/gcc/java/constants.c +++ b/gcc/java/constants.c @@ -32,6 +32,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ #include "ggc.h" static void set_constant_entry (CPool *, int, int, jword); +static int find_tree_constant (CPool *, int, tree); static int find_class_or_string_constant (CPool *, int, tree); static int find_name_and_type_constant (CPool *, tree, tree); static tree get_tag_node (int); @@ -49,8 +50,8 @@ set_constant_entry (cpool, index, tag, value) if (cpool->data == NULL) { cpool->capacity = 100; - cpool->tags = xmalloc (sizeof(uint8) * cpool->capacity); - cpool->data = xmalloc (sizeof(jword) * cpool->capacity); + cpool->tags = ggc_alloc (sizeof(uint8) * cpool->capacity); + cpool->data = ggc_alloc (sizeof(union cpool_entry) * cpool->capacity); cpool->count = 1; } if (index >= cpool->capacity) @@ -58,13 +59,15 @@ set_constant_entry (cpool, index, tag, value) cpool->capacity *= 2; if (index >= cpool->capacity) cpool->capacity = index + 10; - cpool->tags = xrealloc (cpool->tags, sizeof(uint8) * cpool->capacity); - cpool->data = xrealloc (cpool->data, sizeof(jword) * cpool->capacity); + cpool->tags = 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. */ @@ -78,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; @@ -98,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; @@ -108,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; @@ -115,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 @@ -124,15 +146,15 @@ find_class_or_string_constant (cpool, tag, name) 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; } @@ -255,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; } @@ -279,7 +301,7 @@ write_constant_pool (cpool, buffer, length) { 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++) { @@ -293,23 +315,23 @@ write_constant_pool (cpool, buffer, length) 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); @@ -347,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 +460,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) diff --git a/gcc/java/gjavah.c b/gcc/java/gjavah.c index 45509977cde..0c333137c56 100644 --- a/gcc/java/gjavah.c +++ b/gcc/java/gjavah.c @@ -38,6 +38,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ #include "javaop.h" #include "java-tree.h" #include "java-opcodes.h" +#include "ggc.h" #include "hashtab.h" #include <getopt.h> diff --git a/gcc/java/java-tree.h b/gcc/java/java-tree.h index b4ed394eec7..9a79f3e36b4 100644 --- a/gcc/java/java-tree.h +++ b/gcc/java/java-tree.h @@ -229,7 +229,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; @@ -241,7 +241,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). */ @@ -686,7 +686,7 @@ extern GTY(()) tree java_global_trees[JTI_MAX]; #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; #define wfl_operator \ java_global_trees[JTI_WFL_OPERATOR] @@ -1066,8 +1066,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 */ diff --git a/gcc/java/jcf-dump.c b/gcc/java/jcf-dump.c index e780b8430bf..a5de5c57cb5 100644 --- a/gcc/java/jcf-dump.c +++ b/gcc/java/jcf-dump.c @@ -53,6 +53,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ #include "system.h" #include "coretypes.h" #include "tm.h" +#include "ggc.h" #include "jcf.h" #include "tree.h" diff --git a/gcc/java/jcf-parse.c b/gcc/java/jcf-parse.c index 93798261b3a..cd2c1cf819f 100644 --- a/gcc/java/jcf-parse.c +++ b/gcc/java/jcf-parse.c @@ -62,7 +62,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ 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 (void); static void parse_source_file_3 (void); static void parse_class_file (void); static void set_source_filename (JCF *, int); -static void ggc_mark_jcf (void**); static void jcf_parse (struct JCF*); static void load_inner_classes (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: @@ -352,7 +328,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", @@ -435,7 +411,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; } @@ -465,11 +441,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; } @@ -709,8 +685,7 @@ load_inner_classes (cur_class) void init_outgoing_cpool () { - outgoing_cpool = xmalloc (sizeof (struct CPool)); - memset (outgoing_cpool, 0, sizeof (struct CPool)); + outgoing_cpool = ggc_alloc_cleared (sizeof (struct CPool)); } static void @@ -1074,7 +1049,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; @@ -1086,6 +1061,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; @@ -1223,7 +1199,7 @@ process_zip_dir (FILE *finput) class_name = ALLOC (zdir->filename_length+1-6); file_name = ALLOC (zdir->filename_length+1); - jcf = ALLOC (sizeof (JCF)); + jcf = ggc_alloc (sizeof (JCF)); JCF_ZERO (jcf); strncpy (class_name, class_name_in_zip_dir, zdir->filename_length-6); @@ -1255,9 +1231,6 @@ process_zip_dir (FILE *finput) void init_jcf_parse () { - /* Register roots with the garbage collector. */ - ggc_add_root (¤t_jcf, 1, sizeof (JCF), (void (*)(void *))ggc_mark_jcf); - init_src_parse (); } diff --git a/gcc/java/jcf-reader.c b/gcc/java/jcf-reader.c index 1bd5299e97a..da45cc92ee6 100644 --- a/gcc/java/jcf-reader.c +++ b/gcc/java/jcf-reader.c @@ -264,8 +264,8 @@ jcf_parse_constant_pool (JCF* jcf) { int i, n; JPOOL_SIZE (jcf) = (JCF_FILL (jcf, 2), JCF_readu2 (jcf)); - jcf->cpool.tags = ALLOC (JPOOL_SIZE (jcf)); - jcf->cpool.data = ALLOC (sizeof (jword) * JPOOL_SIZE (jcf)); + jcf->cpool.tags = ggc_alloc (JPOOL_SIZE (jcf)); + jcf->cpool.data = ggc_alloc (sizeof (jword) * JPOOL_SIZE (jcf)); jcf->cpool.tags[0] = 0; #ifdef HANDLE_START_CONSTANT_POOL HANDLE_START_CONSTANT_POOL (JPOOL_SIZE (jcf)); @@ -285,25 +285,25 @@ jcf_parse_constant_pool (JCF* 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); @@ -311,7 +311,7 @@ jcf_parse_constant_pool (JCF* 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; diff --git a/gcc/java/jcf.h b/gcc/java/jcf.h index 0555f362372..c8e6aa7a602 100644 --- a/gcc/java/jcf.h +++ b/gcc/java/jcf.h @@ -55,9 +55,17 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ #endif struct JCF; -typedef int (*jcf_filbuf_t) (struct JCF*, int needed); +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; @@ -65,29 +73,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;*/ @@ -102,13 +114,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)) @@ -128,9 +140,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); \ diff --git a/gcc/java/lex.c b/gcc/java/lex.c index c6744f401e7..976d0cf08af 100644 --- a/gcc/java/lex.c +++ b/gcc/java/lex.c @@ -125,7 +125,7 @@ java_init_lex (finput, encoding) CPC_INSTANCE_INITIALIZER_LIST (ctxp) = NULL_TREE; memset (ctxp->modifier_ctx, 0, sizeof (ctxp->modifier_ctx)); - memset (current_jcf, 0, sizeof (JCF)); + current_jcf = ggc_alloc_cleared (sizeof (JCF)); ctxp->current_parsed_class = NULL; ctxp->package = NULL_TREE; #endif diff --git a/gcc/java/lex.h b/gcc/java/lex.h index 9579036c602..aa9a2beea34 100644 --- a/gcc/java/lex.h +++ b/gcc/java/lex.h @@ -96,13 +96,13 @@ struct java_error { int error; }; -typedef struct _java_lc { +typedef struct java_lc_s GTY(()) { int line; int prev_col; int col; } java_lc; -typedef struct java_lexer +struct java_lexer { /* The file from which we're reading. */ FILE *finput; @@ -155,7 +155,8 @@ typedef struct java_lexer int out_last; #endif /* HAVE_ICONV */ -} java_lexer; +}; +typedef struct java_lexer java_lexer; /* Destroy a lexer object. */ extern void java_destroy_lexer (java_lexer *); diff --git a/gcc/java/parse.h b/gcc/java/parse.h index 37731fbd255..a6681afd6f0 100644 --- a/gcc/java/parse.h +++ b/gcc/java/parse.h @@ -427,9 +427,6 @@ enum { INVOKE_VIRTUAL }; -/* We need the resolution stuff only if we compile jc1 */ -#ifndef JC1_LITE - /* Unresolved type identifiers handling. When we process the source code, we blindly accept an unknown type identifier and try to resolve it later. When an unknown type identifier is encountered @@ -509,13 +506,12 @@ typedef struct _jdep { #define JDEP_RESOLVED_P(J) \ (!(J)->solv || TREE_CODE ((J)->solv) != POINTER_TYPE) -typedef struct _jdeplist { +struct jdeplist_s { jdep *first; jdep *last; - struct _jdeplist *next; -} jdeplist; - -#endif /* JC1_LITE */ + struct jdeplist_s *next; +}; +typedef struct jdeplist_s jdeplist; #define CLASSD_FIRST(CD) ((CD)->first) #define CLASSD_LAST(CD) ((CD)->last) @@ -727,14 +723,15 @@ typedef struct _jdeplist { #define DECL_INHERITED_SOURCE_LINE(DECL) (DECL_CHECK (DECL)->decl.u2.i) /* Parser context data structure. */ -struct parser_ctxt { +struct parser_ctxt GTY(()) { const char *filename; /* Current filename */ struct parser_ctxt *next; - java_lexer *lexer; /* Current lexer state */ + java_lexer * GTY((skip (""))) lexer; /* Current lexer state */ char marker_begining; /* Marker. Should be a sub-struct */ - struct java_line *p_line, *c_line; /* Previous and current line */ + struct java_line * GTY ((skip (""))) p_line; /* Previous line */ + struct java_line * GTY ((skip (""))) c_line; /* Current line */ java_lc elc; /* Error's line column info */ int ccb_indent; /* Keep track of {} indent, lexer */ int first_ccb_indent1; /* First { at ident level 1 */ @@ -742,7 +739,7 @@ struct parser_ctxt { int parser_ccb_indent; /* Keep track of {} indent, parser */ int osb_depth; /* Current depth of [ in an expression */ int osb_limit; /* Limit of this depth */ - int *osb_number; /* Keep track of ['s */ + int * GTY ((skip (""))) osb_number; /* Keep track of ['s */ int lineno; /* Current lineno */ char marker_end; /* End marker. Should be a sub-struct */ @@ -761,13 +758,12 @@ struct parser_ctxt { /* Flag to report certain errors (fix this documentation. FIXME) */ unsigned class_err:1; - /* This section is defined only if we compile jc1 */ -#ifndef JC1_LITE + /* This section is used only if we compile jc1 */ tree modifier_ctx [12]; /* WFL of modifiers */ tree class_type; /* Current class */ tree function_decl; /* Current function decl, save/restore */ - struct JCF *current_jcf; /* CU jcf */ + struct JCF * current_jcf; /* CU jcf */ int prevent_ese; /* Prevent expression statement error */ @@ -778,7 +774,7 @@ struct parser_ctxt { /* These two lists won't survive file traversal */ tree class_list; /* List of classes in a CU */ - jdeplist *classd_list; /* Classe dependencies in a CU */ + jdeplist * GTY((skip (""))) classd_list; /* Classe dependencies in a CU */ tree current_parsed_class; /* Class currently parsed */ tree current_parsed_class_un; /* Curr. parsed class unqualified name */ @@ -801,7 +797,6 @@ struct parser_ctxt { constructor. This flag is used to trap illegal argument usage during an explicit constructor invocation. */ -#endif /* JC1_LITE */ }; /* A set of macros to push/pop/access the currently parsed class. */ @@ -947,7 +942,7 @@ ATTRIBUTE_NORETURN ; extern void java_expand_classes (void); -extern struct parser_ctxt *ctxp; -extern struct parser_ctxt *ctxp_for_generation; +extern GTY(()) struct parser_ctxt *ctxp; +extern GTY(()) struct parser_ctxt *ctxp_for_generation; #endif /* ! GCC_JAVA_PARSE_H */ diff --git a/gcc/java/parse.y b/gcc/java/parse.y index 3dbe3b3ed3a..c67a42e11f6 100644 --- a/gcc/java/parse.y +++ b/gcc/java/parse.y @@ -304,13 +304,16 @@ static tree maybe_build_thisn_access_method (tree); static tree build_outer_field_access (tree, tree); static tree build_outer_field_access_methods (tree); -static tree build_outer_field_access_expr (int, tree, tree, tree, tree); +static tree build_outer_field_access_expr (int, tree, tree, + tree, tree); static tree build_outer_method_access_method (tree); static tree build_new_access_id (void); -static tree build_outer_field_access_method (tree, tree, tree, tree, tree); +static tree build_outer_field_access_method (tree, tree, tree, + tree, tree); static int outer_field_access_p (tree, tree); -static int outer_field_expanded_access_p (tree, tree *, tree *, tree *); +static int outer_field_expanded_access_p (tree, tree *, + tree *, tree *); static tree outer_field_access_fix (tree, tree, tree); static tree build_incomplete_class_ref (int, tree); static tree patch_incomplete_class_ref (tree); @@ -321,7 +324,6 @@ static void add_inner_class_fields (tree, tree); static tree build_dot_class_method (tree); static tree build_dot_class_method_invocation (tree); static void create_new_parser_context (int); -static void mark_parser_ctxt (void *); static tree maybe_build_class_init_for_field (tree, tree); static int attach_init_test_initialization_flags (PTR *, PTR); @@ -594,18 +596,7 @@ static GTY(()) tree src_parse_roots[1]; %% /* 19.2 Production from 2.3: The Syntactic Grammar */ -goal: - { - /* Register static variables with the garbage - collector. */ - ggc_add_root (&ctxp, 1, - sizeof (struct parser_ctxt *), - mark_parser_ctxt); - ggc_add_root (&ctxp_for_generation, 1, - sizeof (struct parser_ctxt *), - mark_parser_ctxt); - } - compilation_unit +goal: compilation_unit {} ; @@ -2669,7 +2660,7 @@ create_new_parser_context (copy_from_previous) { struct parser_ctxt *new; - new = (struct parser_ctxt *)xmalloc(sizeof (struct parser_ctxt)); + new = (struct parser_ctxt *) ggc_alloc (sizeof (struct parser_ctxt)); if (copy_from_previous) { memcpy ((PTR)new, (PTR)ctxp, sizeof (struct parser_ctxt)); @@ -2730,8 +2721,6 @@ java_pop_parser_context (generate) toFree->next = ctxp_for_generation; ctxp_for_generation = toFree; } - else - free (toFree); } /* Create a parser context for the use of saving some global @@ -2830,10 +2819,6 @@ java_parser_context_resume () /* Re-installed the data for the parsing to carry on */ memcpy (&ctxp->marker_begining, &old->marker_begining, (size_t)(&ctxp->marker_end - &ctxp->marker_begining)); - - /* Buffer context can now be discarded */ - free (saver); - free (old); } /* Add a new anchor node to which all statement(s) initializing static @@ -6732,10 +6717,9 @@ process_imports () tree to_be_found = EXPR_WFL_NODE (TREE_PURPOSE (import)); char *original_name; - obstack_grow0 (&temporary_obstack, - IDENTIFIER_POINTER (to_be_found), - IDENTIFIER_LENGTH (to_be_found)); - original_name = obstack_finish (&temporary_obstack); + original_name = xmemdup (IDENTIFIER_POINTER (to_be_found), + IDENTIFIER_LENGTH (to_be_found), + IDENTIFIER_LENGTH (to_be_found) + 1); /* Don't load twice something already defined. */ if (IDENTIFIER_CLASS_VALUE (to_be_found)) @@ -6771,7 +6755,7 @@ process_imports () error_found = 1; } - obstack_free (&temporary_obstack, original_name); + free (original_name); if (error_found) return 1; } @@ -16190,42 +16174,6 @@ resolve_qualified_name (name, context) } #endif -/* Mark P, which is really a `struct parser_ctxt **' for GC. */ - -static void -mark_parser_ctxt (p) - void *p; -{ - struct parser_ctxt *pc = *((struct parser_ctxt **) p); -#ifndef JC1_LITE - size_t i; -#endif - - if (!pc) - return; - -#ifndef JC1_LITE - for (i = 0; i < ARRAY_SIZE (pc->modifier_ctx); ++i) - ggc_mark_tree (pc->modifier_ctx[i]); - ggc_mark_tree (pc->class_type); - ggc_mark_tree (pc->function_decl); - ggc_mark_tree (pc->package); - ggc_mark_tree (pc->class_list); - ggc_mark_tree (pc->current_parsed_class); - ggc_mark_tree (pc->current_parsed_class_un); - ggc_mark_tree (pc->non_static_initialized); - ggc_mark_tree (pc->static_initialized); - ggc_mark_tree (pc->instance_initializers); - ggc_mark_tree (pc->import_list); - ggc_mark_tree (pc->import_demand_list); - ggc_mark_tree (pc->current_loop); - ggc_mark_tree (pc->current_labeled_block); -#endif /* JC1_LITE */ - - if (pc->next) - mark_parser_ctxt (&pc->next); -} - void init_src_parse () { |