/* Glue to interface gcj with bytecode verifier.
- Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GCC.
return TYPE_NULL;
}
+bool
+vfy_class_has_field (vfy_jclass klass, vfy_string name,
+ vfy_string signature)
+{
+ tree field = TYPE_FIELDS (klass);
+ while (field != NULL_TREE)
+ {
+ if (DECL_NAME (field) == name
+ && build_java_signature (TREE_TYPE (field)) == signature)
+ return true;
+ field = TREE_CHAIN (field);
+ }
+ return false;
+}
+
int
vfy_fail (const char *message, int pc, vfy_jclass ignore1 ATTRIBUTE_UNUSED,
vfy_method *ignore2 ATTRIBUTE_UNUSED)
return ref_compatible (t->klass, k->klass);
}
+/* Return true if two types are equal. Only valid for reference
+ types. */
+static bool
+types_equal (type *t1, type *t2)
+{
+ if (t1->key != reference_type || t1->key != uninitialized_reference_type
+ || t2->key != reference_type || t2->key != uninitialized_reference_type)
+ return false;
+ /* Only single-ref types are allowed. */
+ if (t1->klass->ref_next || t2->klass->ref_next)
+ return false;
+ return refs_equal (t1->klass, t2->klass);
+}
+
static bool
type_isvoid (type *t)
{
return check_class_constant (class_index);
}
-/* Return field's type, compute class' type if requested. */
+/* Return field's type, compute class' type if requested. If
+ PUTFIELD is true, use the special 'putfield' semantics. */
static type
-check_field_constant (int index, type *class_type)
+check_field_constant (int index, type *class_type, bool putfield)
{
vfy_string name, field_type;
const char *typec;
init_type_from_string (&t, field_type);
else
init_type_from_tag (&t, get_type_val_for_signature (typec[0]));
+
+ /* We have an obscure special case here: we can use `putfield' on a
+ field declared in this class, even if `this' has not yet been
+ initialized. */
+ if (putfield
+ && ! type_initialized (&vfr->current_state->this_type)
+ && vfr->current_state->this_type.pc == SELF
+ && types_equal (&vfr->current_state->this_type, &ct)
+ && vfy_class_has_field (vfr->current_class, name, field_type))
+ type_set_uninitialized (class_type, SELF);
+
return t;
}
invalidate_pc ();
break;
case op_getstatic:
- push_type_t (check_field_constant (get_ushort (), NULL));
+ push_type_t (check_field_constant (get_ushort (), NULL, false));
break;
case op_putstatic:
- pop_type_t (check_field_constant (get_ushort (), NULL));
+ pop_type_t (check_field_constant (get_ushort (), NULL, false));
break;
case op_getfield:
{
type klass;
- type field = check_field_constant (get_ushort (), &klass);
+ type field = check_field_constant (get_ushort (), &klass, false);
pop_type_t (klass);
push_type_t (field);
}
case op_putfield:
{
type klass;
- type field = check_field_constant (get_ushort (), &klass);
+ type field = check_field_constant (get_ushort (), &klass, true);
pop_type_t (field);
-
- /* We have an obscure special case here: we can use
- `putfield' on a field declared in this class, even if
- `this' has not yet been initialized. */
- if (! type_initialized (&vfr->current_state->this_type)
- && vfr->current_state->this_type.pc == SELF)
- type_set_uninitialized (&klass, SELF);
pop_type_t (klass);
}
break;
/* Declarations to interface gcj with bytecode verifier.
- Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of GCC.
void vfy_note_local_type (vfy_method *method, int pc, int slot,
vfy_jclass type);
void vfy_note_instruction_seen (int pc);
+bool vfy_class_has_field (vfy_jclass klass, vfy_string name,
+ vfy_string signature);
#define GLOM(name, stuff) name ## stuff
#define VFY_PRIMITIVE_CLASS(name) \