/* Process expressions for the GNU compiler for the Java(TM) language.
- Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
+ Free Software Foundation, Inc.
This file is part of GNU CC.
#include "parse.h"
#include "toplev.h"
#include "except.h"
-#include "defaults.h"
+#include "ggc.h"
static void flush_quick_stack PARAMS ((void));
static void push_value PARAMS ((tree));
static void java_stack_swap PARAMS ((void));
static void java_stack_dup PARAMS ((int, int));
static void build_java_athrow PARAMS ((tree));
-static void build_java_jsr PARAMS ((tree, tree));
+static void build_java_jsr PARAMS ((int, int));
static void build_java_ret PARAMS ((tree));
static void expand_java_multianewarray PARAMS ((tree, int));
static void expand_java_arraystore PARAMS ((tree));
static tree build_java_monitor PARAMS ((tree, tree));
static void expand_java_pushc PARAMS ((int, tree));
static void expand_java_return PARAMS ((tree));
+static void expand_load_internal PARAMS ((int, tree, int));
static void expand_java_NEW PARAMS ((tree));
static void expand_java_INSTANCEOF PARAMS ((tree));
static void expand_java_CHECKCAST PARAMS ((tree));
static void java_stack_pop PARAMS ((int));
static tree build_java_throw_out_of_bounds_exception PARAMS ((tree));
static tree build_java_check_indexed_type PARAMS ((tree, tree));
-static tree java_array_data_offset PARAMS ((tree));
static tree case_identity PARAMS ((tree, tree));
+static unsigned char peek_opcode_at_pc PARAMS ((struct JCF *, int, int));
+static bool emit_init_test_initialization PARAMS ((struct hash_entry *,
+ PTR ptr));
+static int get_offset_table_index PARAMS ((tree));
static tree operand_type[59];
extern struct obstack permanent_obstack;
+static tree methods_ident = NULL_TREE;
+static tree ncode_ident = NULL_TREE;
+tree dtable_ident = NULL_TREE;
+
/* Set to non-zero value in order to emit class initilization code
before static field references. */
int always_initialize_class_p;
-void
-init_expr_processing()
-{
- operand_type[21] = operand_type[54] = int_type_node;
- operand_type[22] = operand_type[55] = long_type_node;
- operand_type[23] = operand_type[56] = float_type_node;
- operand_type[24] = operand_type[57] = double_type_node;
- operand_type[25] = operand_type[58] = ptr_type_node;
-}
-
/* We store the stack state in two places:
Within a basic block, we use the quick_stack, which is a
pushdown list (TREE_LISTs) of expression nodes.
So dup cannot just add an extra element to the quick_stack, but iadd can.
*/
-tree quick_stack = NULL_TREE;
+static tree quick_stack = NULL_TREE;
/* A free-list of unused permamnet TREE_LIST nodes. */
-tree tree_list_free_list = NULL_TREE;
+static tree tree_list_free_list = NULL_TREE;
/* The stack pointer of the Java virtual machine.
This does include the size of the quick_stack. */
const unsigned char *linenumber_table;
int linenumber_count;
+void
+init_expr_processing()
+{
+ operand_type[21] = operand_type[54] = int_type_node;
+ operand_type[22] = operand_type[55] = long_type_node;
+ operand_type[23] = operand_type[56] = float_type_node;
+ operand_type[24] = operand_type[57] = double_type_node;
+ operand_type[25] = operand_type[58] = ptr_type_node;
+ ggc_add_tree_root (operand_type, 59);
+ ggc_add_tree_root (&methods_ident, 1);
+ ggc_add_tree_root (&ncode_ident, 1);
+ ggc_add_tree_root (&quick_stack, 1);
+ ggc_add_tree_root (&tree_list_free_list, 1);
+}
+
tree
truthvalue_conversion (expr)
tree expr;
}
}
-void
-push_type (type)
+/* Push TYPE on the type stack.
+ Return true on success, 0 on overflow. */
+
+int
+push_type_0 (type)
tree type;
{
int n_words;
type = promote_type (type);
n_words = 1 + TYPE_IS_WIDE (type);
if (stack_pointer + n_words > DECL_MAX_STACK (current_function_decl))
- fatal ("stack overflow");
+ return 0;
stack_type_map[stack_pointer++] = type;
n_words--;
while (--n_words >= 0)
stack_type_map[stack_pointer++] = TYPE_SECOND;
+ return 1;
+}
+
+void
+push_type (type)
+ tree type;
+{
+ if (! push_type_0 (type))
+ abort ();
}
static void
}
push_type (type);
if (tree_list_free_list == NULL_TREE)
- quick_stack = perm_tree_cons (NULL_TREE, value, quick_stack);
+ quick_stack = tree_cons (NULL_TREE, value, quick_stack);
else
{
tree node = tree_list_free_list;
/* Pop a type from the type stack.
TYPE is the expected type. Return the actual type, which must be
- convertible to TYPE, otherwise NULL_TREE is returned. */
+ convertible to TYPE.
+ On an error, *MESSAGEP is set to a freshly malloc'd error message. */
tree
-pop_type_0 (type)
+pop_type_0 (type, messagep)
tree type;
+ char **messagep;
{
int n_words;
tree t;
+ *messagep = NULL;
if (TREE_CODE (type) == RECORD_TYPE)
type = promote_type (type);
n_words = 1 + TYPE_IS_WIDE (type);
if (stack_pointer < n_words)
- fatal ("stack underflow");
+ {
+ *messagep = xstrdup ("stack underflow");
+ return type;
+ }
while (--n_words > 0)
{
if (stack_type_map[--stack_pointer] != void_type_node)
- fatal ("Invalid multi-word value on type stack");
+ {
+ *messagep = xstrdup ("Invalid multi-word value on type stack");
+ return type;
+ }
}
t = stack_type_map[--stack_pointer];
if (type == NULL_TREE || t == type)
/* This is a kludge, but matches what Sun's verifier does.
It can be tricked, but is safe as long as type errors
(i.e. interface method calls) are caught at run-time. */
- else if (CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (type)))
- && t == object_ptr_type_node)
- return t;
- }
- return NULL_TREE;
+ else if (CLASS_INTERFACE (TYPE_NAME (TREE_TYPE (type))))
+ return object_ptr_type_node;
+ }
+
+ /* lang_printable_name uses a static buffer, so we must save the result
+ from calling it the first time. */
+ {
+ char *temp = xstrdup (lang_printable_name (type, 0));
+ *messagep = concat ("expected type '", temp,
+ "' but stack contains '", lang_printable_name (t, 0),
+ "'", NULL);
+ free (temp);
+ }
+ return type;
}
/* Pop a type from the type stack.
pop_type (type)
tree type;
{
- tree t = pop_type_0 (type);
- if (t != NULL_TREE)
- return t;
- error ("unexpected type on stack");
+ char *message = NULL;
+ type = pop_type_0 (type, &message);
+ if (message != NULL)
+ {
+ error ("%s", message);
+ free (message);
+ }
return type;
}
(TREE_TYPE (TREE_VEC_ELT (basetype_vec, i)),
target_type))
return 1;
- if (n == 0)
- return 0;
+ if (n == 0)
+ return 0;
}
for ( ; source_depth > target_depth; source_depth--)
while (count > 0)
{
tree type, val;
+
if (stack_pointer == 0)
- fatal ("stack underflow");
+ abort ();
+
type = stack_type_map[stack_pointer - 1];
if (type == TYPE_SECOND)
{
count--;
if (stack_pointer == 1 || count <= 0)
- fatal ("stack underflow");
+ abort ();
+
type = stack_type_map[stack_pointer - 2];
}
val = pop_value (type);
|| (type2 = stack_type_map[stack_pointer - 2]) == TYPE_UNKNOWN
|| type1 == TYPE_SECOND || type2 == TYPE_SECOND
|| TYPE_IS_WIDE (type1) || TYPE_IS_WIDE (type2))
- fatal ("bad stack swap");
+ /* Bad stack swap. */
+ abort ();
flush_quick_stack ();
decl1 = find_stack_slot (stack_pointer - 1, type1);
if (type == TYPE_SECOND)
{
if (src_index <= low_index)
- fatal ("dup operation splits 64-bit number");
+ /* Dup operation splits 64-bit number. */
+ abort ();
+
stack_type_map[dst_index] = type;
src_index--; dst_index--;
type = stack_type_map[src_index];
if (! TYPE_IS_WIDE (type))
- fatal ("internal error - dup operation");
+ abort ();
}
else if (TYPE_IS_WIDE (type))
- fatal ("internal error - dup operation");
+ abort ();
+
if (src_index != dst_index)
{
tree src_decl = find_stack_slot (src_index, type);
call = build (CALL_EXPR,
void_type_node,
- build_address_of (throw_node[exceptions_via_longjmp ? 1 : 0]),
+ build_address_of (throw_node),
build_tree_list (NULL_TREE, node),
NULL_TREE);
TREE_SIDE_EFFECTS (call) = 1;
/* Implementation for jsr/ret */
static void
-build_java_jsr (where, ret)
- tree where;
- tree ret;
+build_java_jsr (target_pc, return_pc)
+ int target_pc, return_pc;
{
+ tree where = lookup_label (target_pc);
+ tree ret = lookup_label (return_pc);
tree ret_label = fold (build1 (ADDR_EXPR, return_address_type_node, ret));
push_value (ret_label);
flush_quick_stack ();
emit_jump (label_rtx (where));
expand_label (ret);
+ if (instruction_bits [return_pc] & BCODE_VERIFIED)
+ load_type_state (ret);
}
static void
/* Implementation of operations on array: new, load, store, length */
-/* Array core info access macros */
-
-#define JAVA_ARRAY_LENGTH_OFFSET(A) \
- byte_position (TREE_CHAIN (TYPE_FIELDS (TREE_TYPE (TREE_TYPE (A)))))
-
tree
decode_newarray_type (atype)
int atype;
else if (type == long_type_node)
return 11;
else
- fatal ("Can't compute type code - patch_newarray");
+ abort ();
}
/* Build a call to _Jv_ThrowBadArrayIndex(), the
tree node;
{
tree type = TREE_TYPE (node);
+ tree array_type = TREE_TYPE (type);
HOST_WIDE_INT length;
+
if (!is_array_type_p (type))
- fatal ("array length on a non-array reference");
+ abort ();
+
length = java_array_type_length (type);
if (length >= 0)
return build_int_2 (length, 0);
- return fold (build1 (INDIRECT_REF,
- int_type_node,
- fold (build (PLUS_EXPR, ptr_type_node,
- node,
- JAVA_ARRAY_LENGTH_OFFSET(node)))));
+
+ node = build (COMPONENT_REF, int_type_node,
+ build_java_indirect_ref (array_type, node,
+ flag_check_references),
+ lookup_field (&array_type, get_identifier ("length")));
+ IS_ARRAY_LENGTH_ACCESS (node) = 1;
+ return node;
}
-/* Optionally checks an array against the NULL pointer, eventually throwing a
- NullPointerException. It could replace signal handling, but tied to NULL.
- ARG1: the pointer to check, ARG2: the expression to use if
- the pointer is non-null and ARG3 the type that should be returned. */
+/* Optionally checks a reference against the NULL pointer. ARG1: the
+ expr, ARG2: we should check the reference. Don't generate extra
+ checks if we're not generating code. */
-tree
-build_java_arraynull_check (node, expr, type)
- tree node ATTRIBUTE_UNUSED;
- tree expr;
- tree type ATTRIBUTE_UNUSED;
+tree
+java_check_reference (expr, check)
+ tree expr;
+ int check;
{
-#if 0
- static int java_array_access_throws_null_exception = 0;
- node = ???;
- if (java_array_access_throws_null_exception)
- return (build (COND_EXPR,
- type,
- build (EQ_EXPR, int_type_node, node, null_pointer_node),
- build_java_athrow (node), expr ));
- else
-#endif
- return (expr);
+ if (!flag_syntax_only && check)
+ {
+ tree cond;
+ expr = save_expr (expr);
+ cond = build (COND_EXPR, void_type_node,
+ build (EQ_EXPR, boolean_type_node, expr, null_pointer_node),
+ build (CALL_EXPR, void_type_node,
+ build_address_of (soft_nullpointer_node),
+ NULL_TREE, NULL_TREE),
+ empty_stmt_node);
+ expr = build (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
+ }
+
+ return expr;
}
-static tree
-java_array_data_offset (array)
- tree array;
-{
- tree array_type = TREE_TYPE (TREE_TYPE (array));
- tree data_fld = TREE_CHAIN (TREE_CHAIN (TYPE_FIELDS (array_type)));
+/* Reference an object: just like an INDIRECT_REF, but with checking. */
- if (data_fld == NULL_TREE)
- return size_in_bytes (array_type);
- else
- return byte_position (data_fld);
+tree
+build_java_indirect_ref (type, expr, check)
+ tree type;
+ tree expr;
+ int check;
+{
+ return build1 (INDIRECT_REF, type, java_check_reference (expr, check));
}
/* Implement array indexing (either as l-value or r-value).
build_java_arrayaccess (array, type, index)
tree array, type, index;
{
- tree arith, node, throw = NULL_TREE;
-
- arith = fold (build (PLUS_EXPR, int_type_node,
- java_array_data_offset (array),
- fold (build (MULT_EXPR, int_type_node,
- index, size_in_bytes(type)))));
+ tree node, throw = NULL_TREE;
+ tree data_field;
+ tree ref;
+ tree array_type = TREE_TYPE (TREE_TYPE (array));
if (flag_bounds_check)
{
}
}
- node = build1 (INDIRECT_REF, type,
- fold (build (PLUS_EXPR, ptr_type_node,
- array,
- (throw ? build (COMPOUND_EXPR, int_type_node,
- throw, arith )
- : arith))));
+ /* If checking bounds, wrap the index expr with a COMPOUND_EXPR in order
+ to have the bounds check evaluated first. */
+ if (throw != NULL_TREE)
+ index = build (COMPOUND_EXPR, int_type_node, throw, index);
+
+ data_field = lookup_field (&array_type, get_identifier ("data"));
- return (fold (build_java_arraynull_check (array, node, type)));
+ ref = build (COMPONENT_REF, TREE_TYPE (data_field),
+ build_java_indirect_ref (array_type, array,
+ flag_check_references),
+ data_field);
+
+ node = build (ARRAY_REF, type, ref, index);
+ return node;
+}
+
+/* Generate code to throw an ArrayStoreException if OBJECT is not assignable
+ (at runtime) to an element of ARRAY. A NOP_EXPR is returned if it can
+ determine that no check is required. */
+
+tree
+build_java_arraystore_check (array, object)
+ tree array;
+ tree object;
+{
+ tree check, element_type, source;
+ tree array_type_p = TREE_TYPE (array);
+ tree object_type = TYPE_NAME (TREE_TYPE (TREE_TYPE (object)));
+
+ if (! is_array_type_p (array_type_p))
+ abort ();
+
+ /* Get the TYPE_DECL for ARRAY's element type. */
+ element_type = TYPE_NAME (TREE_TYPE (TREE_TYPE (TREE_TYPE (array_type_p))));
+
+ if (TREE_CODE (element_type) != TYPE_DECL
+ || TREE_CODE (object_type) != TYPE_DECL)
+ abort ();
+
+ if (!flag_store_check)
+ return build1 (NOP_EXPR, array_type_p, array);
+
+ /* No check is needed if the element type is final or is itself an array.
+ Also check that element_type matches object_type, since in the bytecode
+ compilation case element_type may be the actual element type of the arra
+ rather than its declared type. */
+ if (element_type == object_type
+ && (TYPE_ARRAY_P (TREE_TYPE (element_type))
+ || CLASS_FINAL (element_type)))
+ return build1 (NOP_EXPR, array_type_p, array);
+
+ /* OBJECT might be wrapped by a SAVE_EXPR. */
+ if (TREE_CODE (object) == SAVE_EXPR)
+ source = TREE_OPERAND (object, 0);
+ else
+ source = object;
+
+ /* Avoid the check if OBJECT was just loaded from the same array. */
+ if (TREE_CODE (source) == ARRAY_REF)
+ {
+ tree target;
+ source = TREE_OPERAND (source, 0); /* COMPONENT_REF. */
+ source = TREE_OPERAND (source, 0); /* INDIRECT_REF. */
+ source = TREE_OPERAND (source, 0); /* Source array's DECL or SAVE_EXPR. */
+ if (TREE_CODE (source) == SAVE_EXPR)
+ source = TREE_OPERAND (source, 0);
+
+ target = array;
+ if (TREE_CODE (target) == SAVE_EXPR)
+ target = TREE_OPERAND (target, 0);
+
+ if (source == target)
+ return build1 (NOP_EXPR, array_type_p, array);
+ }
+
+ /* Build an invocation of _Jv_CheckArrayStore */
+ check = build (CALL_EXPR, void_type_node,
+ build_address_of (soft_checkarraystore_node),
+ tree_cons (NULL_TREE, array,
+ build_tree_list (NULL_TREE, object)),
+ NULL_TREE);
+ TREE_SIDE_EFFECTS (check) = 1;
+
+ return check;
}
/* Makes sure that INDEXED_TYPE is appropriate. If not, make it from
tree elt_type;
if (!is_array_type_p (TREE_TYPE (array_node)))
- fatal ("array indexing on a non-array reference");
+ abort ();
elt_type = (TYPE_ARRAY_ELEMENT (TREE_TYPE (TREE_TYPE (array_node))));
return boolean_type_node;
if (indexed_type != elt_type )
- fatal ("type array element mismatch");
+ abort ();
else
return indexed_type;
}
-/* newarray triggers a call to _Jv_NewArray. This function should be called
- with an integer code (the type of array to create) and get from the stack
- the size of the dimmension. */
+/* newarray triggers a call to _Jv_NewPrimArray. This function should be
+ called with an integer code (the type of array to create), and the length
+ of the array to create. */
tree
build_newarray (atype_value, length)
int atype_value;
tree length;
{
+ tree type_arg;
+
+ tree prim_type = decode_newarray_type (atype_value);
tree type
- = build_java_array_type (decode_newarray_type (atype_value),
+ = build_java_array_type (prim_type,
host_integerp (length, 0) == INTEGER_CST
? tree_low_cst (length, 0) : -1);
+ /* If compiling to native, pass a reference to the primitive type class
+ and save the runtime some work. However, the bytecode generator
+ expects to find the type_code int here. */
+ if (flag_emit_class_files)
+ type_arg = build_int_2 (atype_value, 0);
+ else
+ type_arg = build_class_ref (prim_type);
+
return build (CALL_EXPR, promote_type (type),
build_address_of (soft_newarray_node),
tree_cons (NULL_TREE,
- build_int_2 (atype_value, 0),
+ type_arg,
build_tree_list (NULL_TREE, length)),
NULL_TREE);
}
if (TREE_CODE (rhs_type_node) == POINTER_TYPE)
{
- tree check = build (CALL_EXPR, void_type_node,
- build_address_of (soft_checkarraystore_node),
- tree_cons (NULL_TREE, array,
- build_tree_list (NULL_TREE, rhs_node)),
- NULL_TREE);
- TREE_SIDE_EFFECTS (check) = 1;
+ tree check = build_java_arraystore_check (array, rhs_node);
expand_expr_stmt (check);
}
tree array = pop_value (ptr_type_node);
tree length = build_java_array_length_access (array);
- push_value (build_java_arraynull_check (array, length, int_type_node));
+ push_value (length);
}
/* Emit code for the call to _Jv_Monitor{Enter,Exit}. CALL can be
else if (type == float_type_node || type == double_type_node)
{
REAL_VALUE_TYPE x;
-#ifdef REAL_ARITHMETIC
REAL_VALUE_FROM_INT (x, ival, 0, TYPE_MODE (type));
-#else
- x = ival;
-#endif
value = build_real (type, x);
}
else
- fatal ("internal error in expand_java_pushc");
+ abort ();
+
push_value (value);
}
-#ifndef INT_TYPE_SIZE
-#define INT_TYPE_SIZE BITS_PER_WORD
-#endif
-
static void
expand_java_return (type)
tree type;
}
}
+static void
+expand_load_internal (index, type, pc)
+ int index;
+ tree type;
+ int pc;
+{
+ tree copy;
+ tree var = find_local_variable (index, type, pc);
+
+ /* Now VAR is the VAR_DECL (or PARM_DECL) that we are going to push
+ on the stack. If there is an assignment to this VAR_DECL between
+ the stack push and the use, then the wrong code could be
+ generated. To avoid this we create a new local and copy our
+ value into it. Then we push this new local on the stack.
+ Hopefully this all gets optimized out. */
+ copy = build_decl (VAR_DECL, NULL_TREE, type);
+ DECL_CONTEXT (copy) = current_function_decl;
+ layout_decl (copy, 0);
+ DECL_REGISTER (copy) = 1;
+ expand_decl (copy);
+ MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (copy);
+ DECL_INITIAL (copy) = var;
+ expand_decl_init (copy);
+ push_value (copy);
+}
+
tree
build_address_of (value)
tree value;
return build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (value)), value);
}
+bool class_has_finalize_method (type)
+ tree type;
+{
+ tree super = CLASSTYPE_SUPER (type);
+
+ if (super == NULL_TREE)
+ return false; /* Every class with a real finalizer inherits */
+ /* from java.lang.Object. */
+ else
+ return HAS_FINALIZER_P (type) || class_has_finalize_method (super);
+}
+
static void
expand_java_NEW (type)
tree type;
{
+ tree alloc_node;
+
+ alloc_node = (class_has_finalize_method (type) ? alloc_object_node
+ : alloc_no_finalizer_node);
if (! CLASS_LOADED_P (type))
load_class (type, 1);
safe_layout_class (type);
push_value (build (CALL_EXPR, promote_type (type),
- build_address_of (alloc_object_node),
+ build_address_of (alloc_node),
tree_cons (NULL_TREE, build_class_ref (type),
build_tree_list (NULL_TREE,
size_in_bytes (type))),
return build (COMPONENT_REF, class_ptr_type,
build1 (INDIRECT_REF, dtable_type,
build (COMPONENT_REF, dtable_ptr_type,
- build1 (INDIRECT_REF, object_type_node, value),
+ build_java_indirect_ref (object_type_node, value,
+ flag_check_references),
vtable_field)),
class_field);
}
if (CLASS_P (type) && ! CLASS_LOADED_P (type))
{
load_class (type, 1);
+ safe_layout_class (type);
if (! TYPE_SIZE (type) || TREE_CODE (TYPE_SIZE (type)) == ERROR_MARK)
return error_mark_node;
}
value,
boolean_true_node, boolean_false_node);
}
- else if (DECL_P (klass) && DECL_P (valclass)
+ else if (! TYPE_ARRAY_P (type)
+ && ! TYPE_ARRAY_P (valtype)
+ && DECL_P (klass) && DECL_P (valclass)
&& ! CLASS_INTERFACE (valclass)
&& ! CLASS_INTERFACE (klass)
&& ! inherits_from_p (type, valtype)
}
if (! call)
- fatal ("Internal compiler error in build_java_soft_divmod");
+ abort ();
call = build (CALL_EXPR, type,
build_address_of (call),
tree second_compare = fold (build (COND_EXPR, int_type_node,
ifexp2, integer_zero_node,
op == COMPARE_L_EXPR
- ? integer_negative_one_node
+ ? integer_minus_one_node
: integer_one_node));
return fold (build (COND_EXPR, int_type_node, ifexp1,
op == COMPARE_L_EXPR ? integer_one_node
- : integer_negative_one_node,
+ : integer_minus_one_node,
second_compare));
}
case COMPARE_EXPR:
ifexp2, integer_one_node,
integer_zero_node));
return fold (build (COND_EXPR, int_type_node,
- ifexp1, integer_negative_one_node, second_compare));
+ ifexp1, integer_minus_one_node, second_compare));
}
case TRUNC_DIV_EXPR:
case TRUNC_MOD_EXPR:
/* Lookup the field named NAME in *TYPEP or its super classes.
If not found, return NULL_TREE.
- (If the *TYPEP is not found, return error_mark_node.)
+ (If the *TYPEP is not found, or if the field reference is
+ ambiguous, return error_mark_node.)
If found, return the FIELD_DECL, and set *TYPEP to the
class containing the field. */
do
{
tree field, basetype_vec;
+ tree save_field;
int n, i;
for (field = TYPE_FIELDS (*typep); field; field = TREE_CHAIN (field))
/* Process implemented interfaces. */
basetype_vec = TYPE_BINFO_BASETYPES (*typep);
n = TREE_VEC_LENGTH (basetype_vec);
+ save_field = NULL_TREE;
for (i = 0; i < n; i++)
{
tree t = BINFO_TYPE (TREE_VEC_ELT (basetype_vec, i));
if ((field = lookup_field (&t, name)))
- return field;
+ {
+ if (save_field == field)
+ continue;
+ if (save_field == NULL_TREE)
+ save_field = field;
+ else
+ {
+ tree i1 = DECL_CONTEXT (save_field);
+ tree i2 = DECL_CONTEXT (field);
+ error ("reference `%s' is ambiguous: appears in interface `%s' and interface `%s'",
+ IDENTIFIER_POINTER (name),
+ IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (i1))),
+ IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (i2))));
+ return error_mark_node;
+ }
+ }
}
+
+ if (save_field != NULL_TREE)
+ return save_field;
+
*typep = CLASSTYPE_SUPER (*typep);
} while (*typep);
return NULL_TREE;
#ifdef JAVA_USE_HANDLES
self_value = unhand_expr (self_value);
#endif
- self_value = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (self_value)),
- self_value);
+ self_value = build_java_indirect_ref (TREE_TYPE (TREE_TYPE (self_value)),
+ self_value, flag_check_references);
return fold (build (COMPONENT_REF, TREE_TYPE (field_decl),
self_value, field_decl));
}
tree name;
{
tree decl;
- push_obstacks (&permanent_obstack, &permanent_obstack);
decl = build_decl (LABEL_DECL, name,
TREE_TYPE (return_address_type_node));
- pop_obstacks ();
DECL_CONTEXT (decl) = current_function_decl;
DECL_IGNORED_P (decl) = 1;
return decl;
}
#endif
-/* Recursive helper function to pop argument types during verifiation. */
-
-void
-pop_argument_types (arg_types)
- tree arg_types;
-{
- if (arg_types == end_params_node)
- return;
- if (TREE_CODE (arg_types) == TREE_LIST)
- {
- pop_argument_types (TREE_CHAIN (arg_types));
- pop_type (TREE_VALUE (arg_types));
- return;
- }
- abort ();
-}
-
static tree
pop_arguments (arg_types)
tree arg_types;
build_class_init (clas, expr)
tree clas, expr;
{
- tree init, call;
+ tree init;
struct init_test_hash_entry *ite;
if (inherits_from_p (current_class, clas))
return expr;
TRUE, NULL);
if (ite->init_test_decl == 0)
- ite->init_test_decl = build_decl (VAR_DECL, NULL_TREE,
- boolean_type_node);
- /* Tell the check-init code to ignore this decl. */
- DECL_BIT_INDEX(ite->init_test_decl) = -1;
+ {
+ /* Build a declaration and mark it as a flag used to track
+ static class initializations. */
+ ite->init_test_decl = build_decl (VAR_DECL, NULL_TREE,
+ boolean_type_node);
+ MAYBE_CREATE_VAR_LANG_DECL_SPECIFIC (ite->init_test_decl);
+ LOCAL_CLASS_INITIALIZATION_FLAG (ite->init_test_decl) = 1;
+ DECL_CONTEXT (ite->init_test_decl) = current_function_decl;
+ DECL_FUNCTION_INIT_TEST_CLASS (ite->init_test_decl) = clas;
+ /* Tell the check-init code to ignore this decl when not
+ optimizing class initialization. */
+ if (!STATIC_CLASS_INIT_OPT_P ())
+ DECL_BIT_INDEX(ite->init_test_decl) = -1;
+ }
init = build (CALL_EXPR, void_type_node,
build_address_of (soft_initclass_node),
build_tree_list (NULL_TREE, build_class_ref (clas)),
NULL_TREE);
TREE_SIDE_EFFECTS (init) = 1;
- call = build (COMPOUND_EXPR, TREE_TYPE (expr), init,
- build (MODIFY_EXPR, boolean_type_node,
- ite->init_test_decl, boolean_true_node));
- TREE_SIDE_EFFECTS (call) = 1;
init = build (COND_EXPR, void_type_node,
build (EQ_EXPR, boolean_type_node,
ite->init_test_decl, boolean_false_node),
- call, integer_zero_node);
+ init, integer_zero_node);
+ TREE_SIDE_EFFECTS (init) = 1;
+ init = build (COMPOUND_EXPR, TREE_TYPE (expr), init,
+ build (MODIFY_EXPR, boolean_type_node,
+ ite->init_test_decl, boolean_true_node));
TREE_SIDE_EFFECTS (init) = 1;
}
return init;
}
-static tree methods_ident = NULL_TREE;
-static tree ncode_ident = NULL_TREE;
-tree dtable_ident = NULL_TREE;
-
tree
-build_known_method_ref (method, method_type, self_type, method_signature, arg_list)
+build_known_method_ref (method, method_type, self_type,
+ method_signature, arg_list)
tree method, method_type ATTRIBUTE_UNUSED, self_type,
method_signature ATTRIBUTE_UNUSED, arg_list ATTRIBUTE_UNUSED;
{
tree func;
if (is_compiled_class (self_type))
{
- make_decl_rtl (method, NULL, 1);
+ make_decl_rtl (method, NULL);
func = build1 (ADDR_EXPR, method_ptr_type_node, method);
}
else
{
/* We don't know whether the method has been (statically) compiled.
Compile this code to get a reference to the method's code:
-
+
SELF_TYPE->methods[METHOD_INDEX].ncode
-
+
This is guaranteed to work (assuming SELF_TYPE has
been initialized), since if the method is not compiled yet,
its ncode points to a trampoline that forces compilation. */
-
+
int method_index = 0;
tree meth;
tree ref = build_class_ref (self_type);
if (method == meth)
break;
if (meth == NULL_TREE)
- fatal ("method '%s' not found in class",
- IDENTIFIER_POINTER (DECL_NAME (method)));
+ fatal_error ("method '%s' not found in class",
+ IDENTIFIER_POINTER (DECL_NAME (method)));
method_index++;
}
method_index *= int_size_in_bytes (method_type_node);
if (dtable_ident == NULL_TREE)
dtable_ident = get_identifier ("vtable");
- dtable = build1 (INDIRECT_REF, object_type_node, objectref );
+ dtable = build_java_indirect_ref (object_type_node, objectref,
+ flag_check_references);
dtable = build (COMPONENT_REF, dtable_ptr_type, dtable,
lookup_field (&object_type_node, dtable_ident));
return dtable;
}
+/* Determine the index in the virtual offset table (otable) for a call to
+ METHOD. If this method has not been seen before, it will be added to the
+ otable_methods. If it has, the existing otable slot will be reused. */
+
+int
+get_offset_table_index (method)
+ tree method;
+{
+ int i = 1;
+ tree method_list;
+
+ if (otable_methods == NULL_TREE)
+ {
+ otable_methods = build_tree_list (method, method);
+ return 1;
+ }
+
+ method_list = otable_methods;
+
+ while (1)
+ {
+ if (TREE_VALUE (method_list) == method)
+ return i;
+ i++;
+ if (TREE_CHAIN (method_list) == NULL_TREE)
+ break;
+ else
+ method_list = TREE_CHAIN (method_list);
+ }
+
+ TREE_CHAIN (method_list) = build_tree_list (method, method);
+ return i;
+}
+
tree
build_invokevirtual (dtable, method)
tree dtable, method;
tree func;
tree nativecode_ptr_ptr_type_node
= build_pointer_type (nativecode_ptr_type_node);
- tree method_index = convert (sizetype, DECL_VINDEX (method));
+ tree method_index;
+ tree otable_index;
+
+ if (flag_indirect_dispatch)
+ {
+ otable_index = build_int_2 (get_offset_table_index (method), 0);
+ method_index = build (ARRAY_REF, integer_type_node, otable_decl,
+ otable_index);
+ }
+ else
+ {
+ method_index = convert (sizetype, DECL_VINDEX (method));
+
+ if (TARGET_VTABLE_USES_DESCRIPTORS)
+ /* Add one to skip bogus descriptor for class and GC descriptor. */
+ method_index = size_binop (PLUS_EXPR, method_index, size_int (1));
+ else
+ /* Add 1 to skip "class" field of dtable, and 1 to skip GC descriptor. */
+ method_index = size_binop (PLUS_EXPR, method_index, size_int (2));
+
+ method_index = size_binop (MULT_EXPR, method_index,
+ TYPE_SIZE_UNIT (nativecode_ptr_ptr_type_node));
+
+ if (TARGET_VTABLE_USES_DESCRIPTORS)
+ method_index = size_binop (MULT_EXPR, method_index,
+ size_int (TARGET_VTABLE_USES_DESCRIPTORS));
+ }
- /* Add one to skip "class" field of dtable, and one to skip unused
- vtable entry (for C++ compatibility). */
- method_index = size_binop (PLUS_EXPR, method_index, size_int (2));
- method_index = size_binop (MULT_EXPR, method_index,
- TYPE_SIZE_UNIT (nativecode_ptr_ptr_type_node));
func = fold (build (PLUS_EXPR, nativecode_ptr_ptr_type_node, dtable,
convert (nativecode_ptr_ptr_type_node, method_index)));
- func = build1 (INDIRECT_REF, nativecode_ptr_type_node, func);
+
+ if (TARGET_VTABLE_USES_DESCRIPTORS)
+ func = build1 (NOP_EXPR, nativecode_ptr_type_node, func);
+ else
+ func = build1 (INDIRECT_REF, nativecode_ptr_type_node, func);
return func;
}
tree interface;
tree idx;
tree meth;
+ tree otable_index;
int i;
/* We expand invokeinterface here. _Jv_LookupInterfaceMethod() will
abstract nor static. */
if (class_ident == NULL_TREE)
- class_ident = get_identifier ("class");
-
- dtable = build1 (INDIRECT_REF, dtable_type, dtable);
+ {
+ class_ident = get_identifier ("class");
+ ggc_add_tree_root (&class_ident, 1);
+ }
+
+ dtable = build_java_indirect_ref (dtable_type, dtable, flag_check_references);
dtable = build (COMPONENT_REF, class_ptr_type, dtable,
lookup_field (&dtable_type, class_ident));
interface = DECL_CONTEXT (method);
+ layout_class_methods (interface);
- i = 1;
- for (meth = TYPE_METHODS (interface); ; meth = TREE_CHAIN (meth), i++)
+ if (flag_indirect_dispatch)
{
- if (meth == method)
- {
- idx = build_int_2 (i, 0);
- break;
+ otable_index = build_int_2 (get_offset_table_index (method), 0);
+ idx = build (ARRAY_REF, integer_type_node, otable_decl, otable_index);
+ }
+ else
+ {
+ i = 1;
+ for (meth = TYPE_METHODS (interface); ; meth = TREE_CHAIN (meth), i++)
+ {
+ if (meth == method)
+ {
+ idx = build_int_2 (i, 0);
+ break;
+ }
+ if (meth == NULL_TREE)
+ abort ();
}
- if (meth == NULL_TREE)
- fatal ("internal error in build_invokeinterface");
}
lookup_arg = tree_cons (NULL_TREE, dtable,
tree method_name = COMPONENT_REF_NAME (¤t_jcf->cpool, method_ref_index);
tree self_type = get_class_constant
(current_jcf, COMPONENT_REF_CLASS_INDEX(¤t_jcf->cpool, method_ref_index));
- const char *self_name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (self_type)));
+ const char *const self_name
+ = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (self_type)));
tree call, func, method, arg_list, method_type;
- tree cond = NULL_TREE;
+ tree check = NULL_TREE;
if (! CLASS_LOADED_P (self_type))
{
load_class (self_type, 1);
safe_layout_class (self_type);
if (TREE_CODE (TYPE_SIZE (self_type)) == ERROR_MARK)
- fatal ("failed to find class '%s'", self_name);
+ fatal_error ("failed to find class '%s'", self_name);
}
layout_class_methods (self_type);
method_name, method_signature);
if (method == NULL_TREE)
{
- error ("Class '%s' has no method named '%s' matching signature '%s'",
+ error ("class '%s' has no method named '%s' matching signature '%s'",
self_name,
IDENTIFIER_POINTER (method_name),
IDENTIFIER_POINTER (method_signature));
the new `self' expression once. */
tree save_arg = save_expr (TREE_VALUE (arg_list));
TREE_VALUE (arg_list) = save_arg;
- cond = build (EQ_EXPR, boolean_type_node, save_arg, null_pointer_node);
+ check = java_check_reference (save_arg, 1);
func = build_known_method_ref (method, method_type, self_type,
method_signature, arg_list);
}
func = build_invokeinterface (dtable, method);
}
func = build1 (NOP_EXPR, build_pointer_type (method_type), func);
+
call = build (CALL_EXPR, TREE_TYPE (method_type), func, arg_list, NULL_TREE);
TREE_SIDE_EFFECTS (call) = 1;
+ call = check_for_builtin (method, call);
- if (cond != NULL_TREE)
- {
- /* We have to make the `then' branch a compound expression to
- make the types turn out right. This seems bizarre. */
- call = build (COND_EXPR, TREE_TYPE (call), cond,
- build (COMPOUND_EXPR, TREE_TYPE (call),
- build (CALL_EXPR, void_type_node,
- build_address_of (soft_nullpointer_node),
- NULL_TREE, NULL_TREE),
- (FLOAT_TYPE_P (TREE_TYPE (call))
- ? build_real (TREE_TYPE (call), dconst0)
- : build1 (CONVERT_EXPR, TREE_TYPE (call),
- integer_zero_node))),
- call);
+ if (check != NULL_TREE)
+ {
+ call = build (COMPOUND_EXPR, TREE_TYPE (call), check, call);
TREE_SIDE_EFFECTS (call) = 1;
}
TREE_CHAIN (env_var) = res_var;
}
- push_obstacks (&permanent_obstack, &permanent_obstack);
meth_var = build_decl (VAR_DECL, get_identifier ("meth"), ptr_type_node);
TREE_STATIC (meth_var) = 1;
TREE_PUBLIC (meth_var) = 0;
DECL_EXTERNAL (meth_var) = 0;
- make_decl_rtl (meth_var, NULL, 0);
- meth_var = pushdecl_top_level (meth_var);
- pop_obstacks ();
+ DECL_CONTEXT (meth_var) = method;
+ DECL_ARTIFICIAL (meth_var) = 1;
+ DECL_INITIAL (meth_var) = null_pointer_node;
+ TREE_USED (meth_var) = 1;
+ chainon (env_var, meth_var);
+ layout_decl (meth_var, 0);
+ make_decl_rtl (meth_var, NULL);
+ rest_of_decl_compilation (meth_var, NULL, 0, 0);
/* One strange way that the front ends are different is that they
store arguments differently. */
}
else if (field_decl == NULL_TREE)
{
- error ("Missing field '%s' in '%s'",
+ error ("missing field '%s' in '%s'",
IDENTIFIER_POINTER (field_name), self_name);
is_error = 1;
}
else if (build_java_signature (TREE_TYPE (field_decl)) != field_signature)
{
- error ("Mismatching signature for field '%s' in '%s'",
+ error ("mismatching signature for field '%s' in '%s'",
IDENTIFIER_POINTER (field_name), self_name);
is_error = 1;
}
return;
}
- /* Inline references to java.lang.PRIMTYPE.TYPE.
- In addition to being a useful (minor) optimization,
- this is also needed to avoid circularities in the implementation
- of these fields in libjava. */
- if (field_name == TYPE_identifier_node && ! is_putting
- && ! flag_emit_class_files && field_type == class_ptr_type
- && strncmp (self_name, "java.lang.", 10) == 0)
- {
- tree typ = build_primtype_type_ref (self_name);
- if (typ)
- {
- push_value (typ);
- return;
- }
- }
-
field_ref = build_field_ref (field_ref, self_type, field_name);
if (is_static)
field_ref = build_class_init (self_type, field_ref);
else if (FIELD_STATIC (field_decl))
{
if (!DECL_CLINIT_P (current_function_decl))
- error_with_decl (field_decl,
+ warning_with_decl (field_decl,
"assignment to final static field `%s' not in class initializer");
}
else
{
tree cfndecl_name = DECL_NAME (current_function_decl);
if (! DECL_CONSTRUCTOR_P (current_function_decl)
- && (cfndecl_name != finit_identifier_node))
- error_with_decl (field_decl, "assignment to final field `%s' not in constructor");
+ && !ID_FINIT_P (cfndecl_name))
+ warning_with_decl (field_decl, "assignment to final field `%s' not in constructor");
}
}
expand_assignment (field_ref, new_value, 0, 0);
push_value (field_ref);
}
-tree
-build_primtype_type_ref (self_name)
- const char *self_name;
-{
- const char *class_name = self_name+10;
- tree typ;
- if (strncmp(class_name, "Byte", 4) == 0)
- typ = byte_type_node;
- else if (strncmp(class_name, "Short", 5) == 0)
- typ = short_type_node;
- else if (strncmp(class_name, "Integer", 7) == 0)
- typ = int_type_node;
- else if (strncmp(class_name, "Long", 4) == 0)
- typ = long_type_node;
- else if (strncmp(class_name, "Float", 5) == 0)
- typ = float_type_node;
- else if (strncmp(class_name, "Double", 6) == 0)
- typ = double_type_node;
- else if (strncmp(class_name, "Boolean", 7) == 0)
- typ = boolean_type_node;
- else if (strncmp(class_name, "Char", 4) == 0)
- typ = char_type_node;
- else if (strncmp(class_name, "Void", 4) == 0)
- typ = void_type_node;
- else
- typ = NULL_TREE;
- if (typ != NULL_TREE)
- return build_class_ref (typ);
- else
- return NULL_TREE;
-}
-
void
load_type_state (label)
tree label;
}
/* Do the expansion of a Java switch. With Gcc, switches are front-end
- dependant things, but they rely on gcc routines. This function is
+ dependent things, but they rely on gcc routines. This function is
placed here because it uses things defined locally in parse.y. */
static tree
struct rtx_def *
java_lang_expand_expr (exp, target, tmode, modifier)
register tree exp;
- rtx target ATTRIBUTE_UNUSED;
- enum machine_mode tmode ATTRIBUTE_UNUSED;
- enum expand_modifier modifier ATTRIBUTE_UNUSED;
+ rtx target;
+ enum machine_mode tmode;
+ enum expand_modifier modifier;
{
tree current;
{
tree temp, value, init_decl;
struct rtx_def *r;
- push_obstacks (&permanent_obstack, &permanent_obstack);
START_RECORD_CONSTRUCTOR (temp, object_type_node);
PUSH_FIELD_VALUE (temp, "vtable",
get_primitive_array_vtable (element_type));
FINISH_RECORD_CONSTRUCTOR (temp);
START_RECORD_CONSTRUCTOR (value, array_type);
PUSH_SUPER_VALUE (value, temp);
- /* FIXME: build a new `length' here to get it on the right
- obstack. */
- PUSH_FIELD_VALUE (value, "length", build_int_2 (ilength, 0));
+ PUSH_FIELD_VALUE (value, "length", length);
PUSH_FIELD_VALUE (value, "data", init);
FINISH_RECORD_CONSTRUCTOR (value);
DECL_INITIAL (init_decl) = value;
DECL_IGNORED_P (init_decl) = 1;
TREE_READONLY (init_decl) = 1;
- make_decl_rtl (init_decl, NULL, 1);
+ rest_of_decl_compilation (init_decl, NULL, 1, 0);
+ TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (init_decl)) = 1;
init = build1 (ADDR_EXPR, TREE_TYPE (exp), init_decl);
r = expand_expr (init, target, tmode, modifier);
- pop_obstacks ();
return r;
}
&& ilength >= 10 && JPRIMITIVE_TYPE_P (element_type))
{
tree init_decl;
- push_obstacks (&permanent_obstack, &permanent_obstack);
init_decl = build_decl (VAR_DECL, generate_name (),
TREE_TYPE (init));
pushdecl_top_level (init_decl);
DECL_INITIAL (init_decl) = init;
DECL_IGNORED_P (init_decl) = 1;
TREE_READONLY (init_decl) = 1;
+ rest_of_decl_compilation (init_decl, NULL, 1, 0);
TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (init_decl)) = 1;
- make_decl_rtl (init_decl, NULL, 1);
- pop_obstacks ();
init = init_decl;
}
expand_assignment (build (COMPONENT_REF, TREE_TYPE (data_fld),
- build1 (INDIRECT_REF, array_type,
- array_decl), data_fld), init, 0, 0);
+ build_java_indirect_ref (array_type,
+ array_decl, flag_check_references),
+ data_fld), init, 0, 0);
return tmp;
}
case BLOCK:
{
tree local;
tree body = BLOCK_EXPR_BODY (exp);
+ /* Set to 1 or more when we found a static class
+ initialization flag. */
+ int found_class_initialization_flag = 0;
+
pushlevel (2); /* 2 and above */
expand_start_bindings (0);
local = BLOCK_EXPR_DECLS (exp);
while (local)
{
tree next = TREE_CHAIN (local);
+ found_class_initialization_flag +=
+ LOCAL_CLASS_INITIALIZATION_FLAG_P (local);
layout_decl (local, 0);
expand_decl (pushdecl (local));
local = next;
}
+
+ /* Emit initialization code for test flags if we saw one. */
+ if (! always_initialize_class_p
+ && current_function_decl
+ && found_class_initialization_flag)
+ hash_traverse
+ (&DECL_FUNCTION_INIT_TEST_TABLE (current_function_decl),
+ emit_init_test_initialization, NULL);
+
/* Avoid deep recursion for long block. */
while (TREE_CODE (body) == COMPOUND_EXPR)
{
}
expand_expr (body, const0_rtx, VOIDmode, 0);
emit_queue ();
- poplevel (1, 1, 0);
expand_end_bindings (getdecls (), 1, 0);
+ poplevel (1, 1, 0);
return const0_rtx;
}
return const0_rtx;
/* We expand a try[-catch] block */
/* Expand the try block */
- push_obstacks (&permanent_obstack, &permanent_obstack);
expand_eh_region_start ();
- pop_obstacks ();
expand_expr_stmt (TREE_OPERAND (exp, 0));
- push_obstacks (&permanent_obstack, &permanent_obstack);
expand_start_all_catch ();
- pop_obstacks ();
/* Expand all catch clauses (EH handlers) */
for (current = TREE_OPERAND (exp, 1); current;
current = TREE_CHAIN (current))
{
- tree type;
tree catch = TREE_OPERAND (current, 0);
tree decl = BLOCK_EXPR_DECLS (catch);
- type = (decl ? TREE_TYPE (TREE_TYPE (decl)) : NULL_TREE);
- start_catch_handler (prepare_eh_table_type (type));
- expand_expr_stmt (TREE_OPERAND (current, 0));
+ tree type = (decl ? TREE_TYPE (TREE_TYPE (decl)) : NULL_TREE);
- expand_resume_after_catch ();
- end_catch_handler ();
+ expand_start_catch (type);
+ expand_expr_stmt (TREE_OPERAND (current, 0));
+ expand_end_catch ();
}
expand_end_all_catch ();
return const0_rtx;
+ case JAVA_EXC_OBJ_EXPR:
+ return expand_expr (build_exception_object_ref (TREE_TYPE (exp)),
+ target, tmode, modifier);
+
default:
- fatal ("Can't expand '%s' tree - java_lang_expand_expr",
- tree_code_name [TREE_CODE (exp)]);
+ internal_error ("can't expand %s", tree_code_name [TREE_CODE (exp)]);
}
}
+/* Go over METHOD's bytecode and note instruction starts in
+ instruction_bits[]. */
+
void
-expand_byte_code (jcf, method)
+note_instructions (jcf, method)
JCF *jcf;
tree method;
{
- int PC;
- int i;
+ int PC;
+ unsigned char* byte_ops;
+ long length = DECL_CODE_LENGTH (method);
+
int saw_index;
- const unsigned char *linenumber_pointer;
- int dead_code_index = -1;
+ jint INT_temp;
#undef RET /* Defined by config/i386/i386.h */
#undef AND /* Causes problems with opcodes for iand and land. */
#define FLOAT_type_node float_type_node
#define DOUBLE_type_node double_type_node
#define VOID_type_node void_type_node
- jint INT_temp;
- unsigned char* byte_ops;
- long length = DECL_CODE_LENGTH (method);
-
- stack_pointer = 0;
- JCF_SEEK (jcf, DECL_CODE_OFFSET (method));
- byte_ops = jcf->read_ptr;
-
#define CONST_INDEX_1 (saw_index = 1, IMMEDIATE_u1)
#define CONST_INDEX_2 (saw_index = 1, IMMEDIATE_u2)
#define VAR_INDEX_1 (saw_index = 1, IMMEDIATE_u1)
#define CHECK_PC_IN_RANGE(PC) ((void)1) /* Already handled by verifier. */
- instruction_bits = oballoc (length + 1);
- bzero (instruction_bits, length + 1);
-
- /* We make an initial pass of the line number table, to note
- which instructions have associated line number entries. */
- linenumber_pointer = linenumber_table;
- for (i = 0; i < linenumber_count; i++)
- {
- int pc = GET_u2 (linenumber_pointer);
- linenumber_pointer += 4;
- if (pc >= length)
- warning ("invalid PC in line number table");
- else
- {
- if ((instruction_bits[pc] & BCODE_HAS_LINENUMBER) != 0)
- instruction_bits[pc] |= BCODE_HAS_MULTI_LINENUMBERS;
- instruction_bits[pc] |= BCODE_HAS_LINENUMBER;
- }
- }
+ JCF_SEEK (jcf, DECL_CODE_OFFSET (method));
+ byte_ops = jcf->read_ptr;
+ instruction_bits = xrealloc (instruction_bits, length + 1);
+ memset (instruction_bits, 0, length + 1);
- /* Do a preliminary pass.
- * This figures out which PC can be the targets of jumps. */
+ /* This pass figures out which PC can be the targets of jumps. */
for (PC = 0; PC < length;)
{
int oldpc = PC; /* PC at instruction start. */
} \
}
-/* nothing */ /* XXX JH */
-
#define PRE_IMPL(IGNORE1, IGNORE2) /* nothing */
#define PRE_MONITOR(OPERAND_TYPE, OPERAND_VALUE) /* nothing */
#undef JAVAOP
}
} /* for */
+}
+
+void
+expand_byte_code (jcf, method)
+ JCF *jcf;
+ tree method;
+{
+ int PC;
+ int i;
+ const unsigned char *linenumber_pointer;
+ int dead_code_index = -1;
+ unsigned char* byte_ops;
+ long length = DECL_CODE_LENGTH (method);
+
+ stack_pointer = 0;
+ JCF_SEEK (jcf, DECL_CODE_OFFSET (method));
+ byte_ops = jcf->read_ptr;
+
+ /* We make an initial pass of the line number table, to note
+ which instructions have associated line number entries. */
+ linenumber_pointer = linenumber_table;
+ for (i = 0; i < linenumber_count; i++)
+ {
+ int pc = GET_u2 (linenumber_pointer);
+ linenumber_pointer += 4;
+ if (pc >= length)
+ warning ("invalid PC in line number table");
+ else
+ {
+ if ((instruction_bits[pc] & BCODE_HAS_LINENUMBER) != 0)
+ instruction_bits[pc] |= BCODE_HAS_MULTI_LINENUMBERS;
+ instruction_bits[pc] |= BCODE_HAS_LINENUMBER;
+ }
+ }
if (! verify_jvm_instructions (jcf, byte_ops, length))
return;
if (dead_code_index != -1)
{
/* We've just reached the end of a region of dead code. */
- warning ("Unreachable bytecode from %d to before %d.",
+ warning ("unreachable bytecode from %d to before %d",
dead_code_index, PC);
dead_code_index = -1;
}
if (dead_code_index != -1)
{
/* We've just reached the end of a region of dead code. */
- warning ("Unreachable bytecode from %d to the end of the method.",
+ warning ("unreachable bytecode from %d to the end of the method",
dead_code_index);
}
}
if (JPOOL_TAG (jcf, index) == CONSTANT_String)
{
tree name;
- push_obstacks (&permanent_obstack, &permanent_obstack);
name = get_name_constant (jcf, JPOOL_USHORT1 (jcf, index));
index = alloc_name_constant (CONSTANT_String, name);
c = build_ref_from_constant_pool (index);
TREE_TYPE (c) = promote_type (string_type_node);
- pop_obstacks ();
}
else
c = get_constant (jcf, index);
if (instruction_bits [PC] & BCODE_EXCEPTION_TARGET)
{
tree type = pop_type (ptr_type_node);
- push_value (build1 (NOP_EXPR, type, soft_exceptioninfo_call_node));
+ push_value (build (JAVA_EXC_OBJ_EXPR, type));
}
switch (byte_ops[PC++])
build_java_ret (find_local_variable (index, ptr_type_node, oldpc)); \
}
-#define JSR(OPERAND_TYPE, OPERAND_VALUE) \
- { \
- tree where = lookup_label (oldpc+OPERAND_VALUE); \
- tree ret = lookup_label (PC); \
- build_java_jsr (where, ret); \
- load_type_state (ret); \
- }
+#define JSR(OPERAND_TYPE, OPERAND_VALUE) \
+ build_java_jsr (oldpc+OPERAND_VALUE, PC);
/* Push a constant onto the stack. */
#define PUSHC(OPERAND_TYPE, OPERAND_VALUE) \
/* internal macro added for use by the WIDE case */
#define LOAD_INTERNAL(OPTYPE, OPVALUE) \
- push_value (find_local_variable (OPVALUE, type_map[OPVALUE], oldpc));
+ expand_load_internal (OPVALUE, type_map[OPVALUE], oldpc);
/* Push local variable onto the opcode stack. */
#define LOAD(OPERAND_TYPE, OPERAND_VALUE) \
tree type = TREE_TYPE (selector); \
flush_quick_stack (); \
expand_start_case (0, selector, type, "switch statement");\
- push_momentary (); \
while (--npairs >= 0) \
{ \
jint match = IMMEDIATE_s4; jint offset = IMMEDIATE_s4; \
label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); \
pushcase (NULL_TREE, 0, label, &duplicate); \
expand_java_goto (oldpc + default_offset); \
- pop_momentary (); \
expand_end_case (selector); \
}
tree type = TREE_TYPE (selector); \
flush_quick_stack (); \
expand_start_case (0, selector, type, "switch statement");\
- push_momentary (); \
for (; low <= high; low++) \
{ \
jint offset = IMMEDIATE_s4; \
label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); \
pushcase (NULL_TREE, 0, label, &duplicate); \
expand_java_goto (oldpc + default_offset); \
- pop_momentary (); \
expand_end_case (selector); \
}
return PC;
}
+/* Return the opcode at PC in the code section pointed to by
+ CODE_OFFSET. */
+
+static unsigned char
+peek_opcode_at_pc (jcf, code_offset, pc)
+ JCF *jcf;
+ int code_offset, pc;
+{
+ unsigned char opcode;
+ long absolute_offset = (long)JCF_TELL (jcf);
+
+ JCF_SEEK (jcf, code_offset);
+ opcode = jcf->read_ptr [pc];
+ JCF_SEEK (jcf, absolute_offset);
+ return opcode;
+}
+
+/* Some bytecode compilers are emitting accurate LocalVariableTable
+ attributes. Here's an example:
+
+ PC <t>store_<n>
+ PC+1 ...
+
+ Attribute "LocalVariableTable"
+ slot #<n>: ... (PC: PC+1 length: L)
+
+ This is accurate because the local in slot <n> really exists after
+ the opcode at PC is executed, hence from PC+1 to PC+1+L.
+
+ This procedure recognizes this situation and extends the live range
+ of the local in SLOT to START_PC-1 or START_PC-2 (depending on the
+ length of the store instruction.)
+
+ This function is used by `give_name_to_locals' so that a local's
+ DECL features a DECL_LOCAL_START_PC such that the first related
+ store operation will use DECL as a destination, not a unrelated
+ temporary created for the occasion.
+
+ This function uses a global (instruction_bits) `note_instructions' should
+ have allocated and filled properly. */
+
+int
+maybe_adjust_start_pc (jcf, code_offset, start_pc, slot)
+ struct JCF *jcf;
+ int code_offset, start_pc, slot;
+{
+ int first, index, opcode;
+ int pc, insn_pc;
+ int wide_found = 0;
+
+ if (!start_pc)
+ return start_pc;
+
+ first = index = -1;
+
+ /* Find last previous instruction and remember it */
+ for (pc = start_pc-1; pc; pc--)
+ if (instruction_bits [pc] & BCODE_INSTRUCTION_START)
+ break;
+ insn_pc = pc;
+
+ /* Retrieve the instruction, handle `wide'. */
+ opcode = (int) peek_opcode_at_pc (jcf, code_offset, pc++);
+ if (opcode == OPCODE_wide)
+ {
+ wide_found = 1;
+ opcode = (int) peek_opcode_at_pc (jcf, code_offset, pc++);
+ }
+
+ switch (opcode)
+ {
+ case OPCODE_astore_0:
+ case OPCODE_astore_1:
+ case OPCODE_astore_2:
+ case OPCODE_astore_3:
+ first = OPCODE_astore_0;
+ break;
+
+ case OPCODE_istore_0:
+ case OPCODE_istore_1:
+ case OPCODE_istore_2:
+ case OPCODE_istore_3:
+ first = OPCODE_istore_0;
+ break;
+
+ case OPCODE_lstore_0:
+ case OPCODE_lstore_1:
+ case OPCODE_lstore_2:
+ case OPCODE_lstore_3:
+ first = OPCODE_lstore_0;
+ break;
+
+ case OPCODE_fstore_0:
+ case OPCODE_fstore_1:
+ case OPCODE_fstore_2:
+ case OPCODE_fstore_3:
+ first = OPCODE_fstore_0;
+ break;
+
+ case OPCODE_dstore_0:
+ case OPCODE_dstore_1:
+ case OPCODE_dstore_2:
+ case OPCODE_dstore_3:
+ first = OPCODE_dstore_0;
+ break;
+
+ case OPCODE_astore:
+ case OPCODE_istore:
+ case OPCODE_lstore:
+ case OPCODE_fstore:
+ case OPCODE_dstore:
+ index = peek_opcode_at_pc (jcf, code_offset, pc);
+ if (wide_found)
+ {
+ int other = peek_opcode_at_pc (jcf, code_offset, ++pc);
+ index = (other << 8) + index;
+ }
+ break;
+ }
+
+ /* Now we decide: first >0 means we have a <t>store_<n>, index >0
+ means we have a <t>store. */
+ if ((first > 0 && opcode - first == slot) || (index > 0 && index == slot))
+ start_pc = insn_pc;
+
+ return start_pc;
+}
+
/* Force the (direct) sub-operands of NODE to be evaluated in left-to-right
order, as specified by Java Language Specification.
if (TREE_SIDE_EFFECTS (TREE_OPERAND (node, 1)))
TREE_OPERAND (node, 0) = save_expr (TREE_OPERAND (node, 0));
}
- else if (TREE_CODE (node) == CALL_EXPR || TREE_CODE (node) == NEW_CLASS_EXPR)
+ else if (TREE_CODE (node) == CALL_EXPR
+ || TREE_CODE (node) == NEW_CLASS_EXPR
+ || (TREE_CODE (node) == COMPOUND_EXPR
+ && TREE_CODE (TREE_OPERAND (node, 0)) == CALL_EXPR
+ && TREE_CODE (TREE_OPERAND (node, 1)) == SAVE_EXPR))
{
tree arg, cmp;
if (!TREE_OPERAND (node, 1))
return node;
+ arg = node;
+
+ /* Position arg properly, account for wrapped around ctors. */
+ if (TREE_CODE (node) == COMPOUND_EXPR)
+ arg = TREE_OPERAND (node, 0);
+
+ arg = TREE_OPERAND (arg, 1);
+
+ /* Not having a list of argument here is an error. */
+ if (TREE_CODE (arg) != TREE_LIST)
+ abort ();
+
/* This reverses the evaluation order. This is a desired effect. */
- for (cmp = NULL_TREE, arg = TREE_OPERAND (node, 1);
- arg; arg = TREE_CHAIN (arg))
+ for (cmp = NULL_TREE; arg; arg = TREE_CHAIN (arg))
{
tree saved = save_expr (force_evaluation_order (TREE_VALUE (arg)));
cmp = (cmp == NULL_TREE ? saved :
}
return node;
}
+
+/* Called for every element in DECL_FUNCTION_INIT_TEST_TABLE of a
+ method in order to emit initialization code for each test flag. */
+
+static bool
+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);
+ tree rhs;
+
+ /* If the DECL_INITIAL of the test flag is set to true, it
+ means that the class is already initialized the time it
+ is in use. */
+ if (DECL_INITIAL (ite->init_test_decl) == boolean_true_node)
+ rhs = boolean_true_node;
+ /* Otherwise, 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. */
+ else
+ rhs = 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));
+
+ expand_expr_stmt (build (MODIFY_EXPR, boolean_type_node,
+ ite->init_test_decl, rhs));
+ return true;
+}