/* 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.
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)
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);
/* 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;
}
}
/* 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))));
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;
}
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;
}
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; )
{
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]),
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));
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;
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;
}