#include "except.h"
#include "defaults.h"
#include "java-except.h"
+#include "ggc.h"
#if defined (DEBUG_JAVA_BINDING_LEVELS)
extern void indent PROTO((void));
static struct binding_level *make_binding_level PARAMS ((void));
static boolean emit_init_test_initialization PARAMS ((struct hash_entry *,
hash_table_key));
+static tree create_primitive_vtable PARAMS ((const char *));
/* Set to non-zero value in order to emit class initilization code
before static field references. */
extern int always_initialize_class_p;
-#ifndef INT_TYPE_SIZE
-#define INT_TYPE_SIZE BITS_PER_WORD
-#endif
+/* Use garbage collection. */
+
+int ggc_p = 1;
/* The DECL_MAP is a mapping from (index, type) to a decl node.
If index < max_locals, it is the index of a local variable.
/* A list of local variables VAR_DECLs for this method that we have seen
debug information, but we have not reached their starting (byte) PC yet. */
-tree pending_local_decls = NULL_TREE;
+static tree pending_local_decls = NULL_TREE;
+
+tree throw_node [2];
/* Push a local variable or stack slot into the decl_map,
and assign it an rtl. */
if (DECL_LANG_SPECIFIC (decl) == NULL)
{
DECL_LANG_SPECIFIC (decl)
- = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
+ = (struct lang_decl *) ggc_alloc (sizeof (struct lang_decl_var));
DECL_LOCAL_START_PC (decl) = 0;
DECL_LOCAL_END_PC (decl) = DECL_CODE_LENGTH (current_function_decl);
DECL_LOCAL_SLOT_NUMBER (decl) = index;
if it has subblocks. */
static int keep_next_if_subblocks;
+
+tree java_global_trees[JTI_MAX];
-tree object_type_node;
-tree unqualified_object_id_node;
-tree object_ptr_type_node;
-tree string_type_node;
-tree string_ptr_type_node;
-tree throwable_type_node;
-tree runtime_exception_type_node;
-tree error_exception_type_node;
-tree *predef_filenames;
-int predef_filenames_size;
-
-tree boolean_type_node;
-
-tree return_address_type_node;
-
-tree byte_type_node;
-tree short_type_node;
-tree int_type_node;
-tree long_type_node;
-
-tree promoted_byte_type_node;
-tree promoted_short_type_node;
-tree promoted_char_type_node;
-tree promoted_boolean_type_node;
-
-tree unsigned_byte_type_node;
-tree unsigned_short_type_node;
-tree unsigned_int_type_node;
-tree unsigned_long_type_node;
-
-/* The type for struct methodtable. */
-tree methodtable_type;
-tree methodtable_ptr_type;
-
-tree utf8const_type;
-tree utf8const_ptr_type;
-tree class_type_node;
-tree class_ptr_type;
-tree field_type_node;
-tree field_ptr_type_node;
-tree field_info_union_node;
-tree jexception_type;
-tree jexception_ptr_type;
-tree lineNumberEntry_type;
-tree lineNumbers_type;
-tree constants_type_node;
-tree dtable_type;
-tree dtable_ptr_type;
-tree method_type_node;
-tree method_ptr_type_node;
-tree nativecode_ptr_array_type_node;
-tree one_elt_array_domain_type;
-tree access_flags_type_node;
-tree class_dtable_decl;
-
-/* Expressions that are constants with value zero, of types
- `long', `float' and `double'. */
-tree long_zero_node;
-tree float_zero_node;
-tree double_zero_node;
-
-tree empty_stmt_node;
-
-/* Nodes for boolean constants TRUE and FALSE. */
-tree boolean_true_node;
-tree boolean_false_node;
-
-tree TYPE_identifier_node;
-tree init_identifier_node;
-tree clinit_identifier_node;
-tree finit_identifier_node;
-tree void_signature_node;
-tree length_identifier_node;
-tree this_identifier_node;
-tree super_identifier_node;
-tree continue_identifier_node;
-tree access0_identifier_node; /* 1.1 */
-tree end_params_node;
-
-/* References to internal libjava functions we use. */
-tree alloc_object_node;
-tree soft_instanceof_node;
-tree soft_checkcast_node;
-tree soft_initclass_node;
-tree soft_newarray_node;
-tree soft_anewarray_node;
-tree soft_multianewarray_node;
-tree soft_badarrayindex_node;
-tree soft_nullpointer_node;
-tree throw_node [2];
-tree soft_checkarraystore_node;
-tree soft_monitorenter_node;
-tree soft_monitorexit_node;
-tree soft_lookupinterfacemethod_node;
-tree soft_lookupjnimethod_node;
-tree soft_getjnienvnewframe_node;
-tree soft_jnipopsystemframe_node;
-tree soft_fmod_node;
-tree soft_exceptioninfo_call_node;
-tree soft_idiv_node;
-tree soft_irem_node;
-tree soft_ldiv_node;
-tree soft_lrem_node;
+tree predef_filenames[PREDEF_FILENAMES_SIZE];
/* Build (and pushdecl) a "promoted type" for all standard
types shorter than int. */
return type;
}
-/* Nodes for integer constants. */
-tree integer_two_node;
-tree integer_four_node;
-tree integer_negative_one_node;
-
/* Return a definition for a builtin function named NAME and whose data type
is TYPE. TYPE should be a function type with argument types.
FUNCTION_CODE tells later passes how to compile calls to this function.
return decl;
}
+/* Return tree that represents a vtable for a primitive array. */
+static tree
+create_primitive_vtable (name)
+ const char *name;
+{
+ tree r;
+ char buf[50];
+
+ sprintf (buf, "_Jv_%sVTable", name);
+ r = build_decl (VAR_DECL, get_identifier (buf), ptr_type_node);
+ DECL_EXTERNAL (r) = 1;
+ make_decl_rtl (r, buf, 1);
+ return r;
+}
+
void
init_decl_processing ()
{
float_zero_node = build_real (float_type_node, dconst0);
double_zero_node = build_real (double_type_node, dconst0);
- /* As your adding items here, please update the code right after
+ /* These are the vtables for arrays of primitives. */
+ boolean_array_vtable = create_primitive_vtable ("boolean");
+ byte_array_vtable = create_primitive_vtable ("byte");
+ char_array_vtable = create_primitive_vtable ("char");
+ short_array_vtable = create_primitive_vtable ("short");
+ int_array_vtable = create_primitive_vtable ("int");
+ long_array_vtable = create_primitive_vtable ("long");
+ float_array_vtable = create_primitive_vtable ("float");
+ double_array_vtable = create_primitive_vtable ("double");
+
+ /* As you're adding items here, please update the code right after
this section, so that the filename containing the source code of
the pre-defined class gets registered correctly. */
unqualified_object_id_node = get_identifier ("Object");
lookup_class (get_identifier ("java.lang.RuntimeException"));
error_exception_type_node =
lookup_class (get_identifier ("java.lang.Error"));
+ rawdata_ptr_type_node
+ = promote_type (lookup_class (get_identifier ("gnu.gcj.RawData")));
- /* This section has to be updated as items are added to the previous
- section. */
- predef_filenames_size = 6;
- predef_filenames = (tree *)xmalloc (predef_filenames_size * sizeof (tree));
+ /* If you add to this section, don't forget to increase
+ PREDEF_FILENAMES_SIZE. */
predef_filenames [0] = get_identifier ("java/lang/Class.java");
predef_filenames [1] = get_identifier ("java/lang/Error.java");
predef_filenames [2] = get_identifier ("java/lang/Object.java");
predef_filenames [3] = get_identifier ("java/lang/RuntimeException.java");
predef_filenames [4] = get_identifier ("java/lang/String.java");
predef_filenames [5] = get_identifier ("java/lang/Throwable.java");
+ predef_filenames [6] = get_identifier ("gnu/gcj/RawData.java");
methodtable_type = make_node (RECORD_TYPE);
layout_type (methodtable_type);
TYPE_identifier_node = get_identifier ("TYPE");
init_identifier_node = get_identifier ("<init>");
clinit_identifier_node = get_identifier ("<clinit>");
- finit_identifier_node = get_identifier ("$finit$");
+ /* Legacy `$finit$' special method identifier. This needs to be
+ recognized as equivalent to `finit$' but isn't generated anymore. */
+ finit_leg_identifier_node = get_identifier ("$finit$");
+ /* The new `finit$' special method identifier. This one is now
+ generated in place of `$finit$'. */
+ finit_identifier_node = get_identifier ("finit$");
void_signature_node = get_identifier ("()V");
length_identifier_node = get_identifier ("length");
this_identifier_node = get_identifier ("this");
0, NOT_BUILT_IN, NULL_PTR);
init_class_processing ();
+ init_jcf_parse ();
+
+ /* Register nodes with the garbage collector. */
+ ggc_add_tree_root (java_global_trees,
+ sizeof (java_global_trees) / sizeof (tree));
+ ggc_add_tree_root (throw_node,
+ sizeof (throw_node) / sizeof (tree));
+ ggc_add_tree_root (predef_filenames,
+ sizeof (predef_filenames) / sizeof (tree));
+ ggc_add_tree_root (&decl_map, 1);
+ ggc_add_tree_root (&pending_local_decls, 1);
}
define_label (input_filename, lineno,
DECL_NAME (label));
}
- else if (warn_unused && !TREE_USED (label))
+ else if (warn_unused[UNUSED_LABEL] && !TREE_USED (label))
warning_with_decl (label, "label `%s' defined but not used");
IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
end_pc = DECL_CODE_LENGTH (current_function_decl);
}
DECL_LANG_SPECIFIC (decl)
- = (struct lang_decl *) permalloc (sizeof (struct lang_decl_var));
+ = (struct lang_decl *) ggc_alloc (sizeof (struct lang_decl_var));
DECL_LOCAL_SLOT_NUMBER (decl) = slot;
DECL_LOCAL_START_PC (decl) = start_pc;
#if 0
/* Called for every element in DECL_FUNCTION_INIT_TEST_TABLE in order
to emit initialization code for each test flag. */
-
+
static boolean
emit_init_test_initialization (entry, key)
struct hash_entry *entry;
hash_table_key key ATTRIBUTE_UNUSED;
{
struct init_test_hash_entry *ite = (struct init_test_hash_entry *) entry;
+ tree klass = build_class_ref ((tree) entry->key);
expand_decl (ite->init_test_decl);
- expand_expr_stmt (build (MODIFY_EXPR, boolean_type_node,
- ite->init_test_decl, boolean_false_node));
+ /* We initialize the class init check variable by looking at the
+ `state' field of the class to see if it is already initialized.
+ This makes things a bit faster if the class is already
+ initialized, which should be the common case. */
+ expand_expr_stmt
+ (build (MODIFY_EXPR, boolean_type_node,
+ ite->init_test_decl,
+ build (GE_EXPR, boolean_type_node,
+ build (COMPONENT_REF, byte_type_node,
+ build1 (INDIRECT_REF, class_type_node, klass),
+ lookup_field (&class_type_node,
+ get_identifier ("state"))),
+ build_int_2 (JV_STATE_DONE, 0))));
return true;
}
permanent_allocation (1);
asynchronous_exceptions = flag_asynchronous_exceptions;
}
+
+/* Mark language-specific parts of T for garbage-collection. */
+
+void
+lang_mark_tree (t)
+ tree t;
+{
+ if (TREE_CODE (t) == IDENTIFIER_NODE)
+ {
+ struct lang_identifier *li = (struct lang_identifier *) t;
+ ggc_mark_tree (li->global_value);
+ ggc_mark_tree (li->local_value);
+ ggc_mark_tree (li->utf8_ref);
+ }
+ else if (TREE_CODE (t) == VAR_DECL
+ || TREE_CODE (t) == PARM_DECL)
+ {
+ struct lang_decl_var *ldv =
+ ((struct lang_decl_var *) DECL_LANG_SPECIFIC (t));
+ if (ldv)
+ {
+ ggc_mark (ldv);
+ ggc_mark_tree (ldv->slot_chain);
+ }
+ }
+ else if (TREE_CODE (t) == FUNCTION_DECL)
+ {
+ struct lang_decl *ld = DECL_LANG_SPECIFIC (t);
+
+ if (ld)
+ {
+ ggc_mark (ld);
+ ggc_mark_tree (ld->throws_list);
+ ggc_mark_tree (ld->function_decl_body);
+ ggc_mark_tree (ld->called_constructor);
+ ggc_mark_tree (ld->inner_access);
+ }
+ }
+ else if (TYPE_P (t))
+ {
+ struct lang_type *lt = TYPE_LANG_SPECIFIC (t);
+
+ if (lt)
+ {
+ ggc_mark (lt);
+ ggc_mark_tree (lt->signature);
+ ggc_mark_tree (lt->cpool_data_ref);
+ ggc_mark_tree (lt->finit_stmt_list);
+ ggc_mark_tree (lt->clinit_stmt_list);
+ ggc_mark_tree (lt->ii_block);
+ ggc_mark_tree (lt->dot_class);
+ }
+ }
+}