X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=blobdiff_plain;f=gcc%2Fjava%2Fconstants.c;h=ca5eb77ce30cc2fba648e5ceb1741100768ec131;hp=68154c0b3a6bedc139f1d8edf16c4f153214497b;hb=3eafef1ab2554978e8e09caa01cce033143513ac;hpb=e4b5271963eb88fd2003b0052865245c93f57294 diff --git a/gcc/java/constants.c b/gcc/java/constants.c index 68154c0b3a6..ca5eb77ce30 100644 --- a/gcc/java/constants.c +++ b/gcc/java/constants.c @@ -1,6 +1,6 @@ /* Handle the constant pool of the Java(TM) Virtual Machine. Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, - 2007 Free Software Foundation, Inc. + 2007, 2008 Free Software Foundation, Inc. This file is part of GCC. @@ -44,9 +44,8 @@ set_constant_entry (CPool *cpool, int index, int tag, jword value) if (cpool->data == NULL) { cpool->capacity = 100; - cpool->tags = ggc_alloc_cleared (sizeof(uint8) * cpool->capacity); - cpool->data = ggc_alloc_cleared (sizeof(union cpool_entry) - * cpool->capacity); + cpool->tags = GGC_CNEWVEC (uint8, cpool->capacity); + cpool->data = GGC_CNEWVEC (union cpool_entry, cpool->capacity); cpool->count = 1; } if (index >= cpool->capacity) @@ -55,10 +54,9 @@ set_constant_entry (CPool *cpool, int index, int tag, jword value) cpool->capacity *= 2; if (index >= cpool->capacity) cpool->capacity = index + 10; - cpool->tags = ggc_realloc (cpool->tags, - sizeof(uint8) * cpool->capacity); - cpool->data = ggc_realloc (cpool->data, - sizeof(union cpool_entry) * cpool->capacity); + cpool->tags = GGC_RESIZEVEC (uint8, cpool->tags, cpool->capacity); + cpool->data = GGC_RESIZEVEC (union cpool_entry, cpool->data, + cpool->capacity); /* Make sure GC never sees uninitialized tag values. */ memset (cpool->tags + old_cap, 0, cpool->capacity - old_cap); @@ -329,14 +327,14 @@ get_tag_node (int tag) /* Given a class, return its constant pool, creating one if necessary. */ CPool * -cpool_for_class (tree class) +cpool_for_class (tree klass) { - CPool *cpool = TYPE_CPOOL (class); + CPool *cpool = TYPE_CPOOL (klass); if (cpool == NULL) { - cpool = ggc_alloc_cleared (sizeof (struct CPool)); - TYPE_CPOOL (class) = cpool; + cpool = GGC_CNEW (struct CPool); + TYPE_CPOOL (klass) = cpool; } return cpool; } @@ -372,13 +370,13 @@ find_name_and_type_constant_tree (CPool *cpool, tree name, tree type) } /* Look for a field ref that matches DECL in the constant pool of - CLASS. + KLASS. Return the index of the entry. */ int -alloc_constant_fieldref (tree class, tree decl) +alloc_constant_fieldref (tree klass, tree decl) { - CPool *outgoing_cpool = cpool_for_class (class); + CPool *outgoing_cpool = cpool_for_class (klass); int class_index = find_tree_constant (outgoing_cpool, CONSTANT_Class, DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))); @@ -445,27 +443,30 @@ build_constant_data_ref (bool indirect) TREE_THIS_NOTRAP (klass) = 1; data = fold_convert (build_pointer_type (cpool_type), data); d = build1 (INDIRECT_REF, cpool_type, data); - TREE_INVARIANT (d) = 1; return d; } else { - tree type, decl; tree decl_name = mangled_classname ("_CD_", output_class); + tree decl = IDENTIFIER_GLOBAL_VALUE (decl_name); - /* Build a type with unspecified bounds. The will make sure - that targets do the right thing with whatever size we end - up with at the end. Using bounds that are too small risks - assuming the data is in the small data section. */ - type = build_array_type (ptr_type_node, NULL_TREE); - - /* We need to lay out the type ourselves, since build_array_type - thinks the type is incomplete. */ - layout_type (type); - - decl = build_decl (VAR_DECL, decl_name, type); - TREE_STATIC (decl) = 1; + if (! decl) + { + /* Build a type with unspecified bounds. The will make sure + that targets do the right thing with whatever size we end + up with at the end. Using bounds that are too small risks + assuming the data is in the small data section. */ + tree type = build_array_type (ptr_type_node, NULL_TREE); + + /* We need to lay out the type ourselves, since build_array_type + thinks the type is incomplete. */ + layout_type (type); + + decl = build_decl (input_location, VAR_DECL, decl_name, type); + TREE_STATIC (decl) = 1; + IDENTIFIER_GLOBAL_VALUE (decl_name) = decl; + } return decl; } @@ -485,7 +486,6 @@ build_ref_from_constant_pool (int index) i = build_int_cst (NULL_TREE, index); d = build4 (ARRAY_REF, TREE_TYPE (TREE_TYPE (d)), d, i, NULL_TREE, NULL_TREE); - TREE_INVARIANT (d) = 1; return d; } @@ -500,6 +500,7 @@ build_constants_constructor (void) tree cons; tree tags_list = NULL_TREE; tree data_list = NULL_TREE; + VEC(constructor_elt,gc) *v = NULL; int i; for (i = outgoing_cpool->count; --i > 0; ) @@ -518,13 +519,13 @@ build_constants_constructor (void) { unsigned HOST_WIDE_INT temp = outgoing_cpool->data[i].w; - /* Make sure that on a 64-bit big-endian machine this - 32-bit jint appears in the first word. + /* Make sure that on a big-endian machine with 64-bit + pointers this 32-bit jint appears in the first word. FIXME: This is a kludge. The field we're initializing is not a scalar but a union, and that's how we should represent it in the compiler. We should fix this. */ - if (BYTES_BIG_ENDIAN && BITS_PER_WORD > 32) - temp <<= BITS_PER_WORD - 32; + if (BYTES_BIG_ENDIAN && POINTER_SIZE > 32) + temp <<= POINTER_SIZE - 32; tags_list = tree_cons (NULL_TREE, get_tag_node (outgoing_cpool->tags[i]), @@ -557,13 +558,22 @@ build_constants_constructor (void) tree data_decl, tags_decl, tags_type; tree max_index = build_int_cst (sizetype, outgoing_cpool->count - 1); tree index_type = build_index_type (max_index); + tree tem; /* Add dummy 0'th element of constant pool. */ tags_list = tree_cons (NULL_TREE, get_tag_node (0), tags_list); data_list = tree_cons (NULL_TREE, null_pointer_node, data_list); + /* Change the type of the decl to have the proper array size. + ??? Make sure to transition the old type-pointer-to list to this + new type to not invalidate all build address expressions. */ data_decl = build_constant_data_ref (false); + tem = TYPE_POINTER_TO (TREE_TYPE (data_decl)); + if (!tem) + tem = build_pointer_type (TREE_TYPE (data_decl)); + TYPE_POINTER_TO (TREE_TYPE (data_decl)) = NULL_TREE; TREE_TYPE (data_decl) = build_array_type (ptr_type_node, index_type); + TYPE_POINTER_TO (TREE_TYPE (data_decl)) = tem; DECL_INITIAL (data_decl) = build_constructor_from_list (TREE_TYPE (data_decl), data_list); DECL_SIZE (data_decl) = TYPE_SIZE (TREE_TYPE (data_decl)); @@ -572,7 +582,8 @@ build_constants_constructor (void) data_value = build_address_of (data_decl); tags_type = build_array_type (unsigned_byte_type_node, index_type); - tags_decl = build_decl (VAR_DECL, mangled_classname ("_CT_", + tags_decl = build_decl (input_location, + VAR_DECL, mangled_classname ("_CT_", current_class), tags_type); TREE_STATIC (tags_decl) = 1; @@ -586,12 +597,12 @@ build_constants_constructor (void) data_value = null_pointer_node; tags_value = null_pointer_node; } - START_RECORD_CONSTRUCTOR (cons, constants_type_node); - PUSH_FIELD_VALUE (cons, "size", + START_RECORD_CONSTRUCTOR (v, constants_type_node); + PUSH_FIELD_VALUE (v, "size", build_int_cst (NULL_TREE, outgoing_cpool->count)); - PUSH_FIELD_VALUE (cons, "tags", tags_value); - PUSH_FIELD_VALUE (cons, "data", data_value); - FINISH_RECORD_CONSTRUCTOR (cons); + PUSH_FIELD_VALUE (v, "tags", tags_value); + PUSH_FIELD_VALUE (v, "data", data_value); + FINISH_RECORD_CONSTRUCTOR (cons, v, constants_type_node); return cons; }