CACAO
typecheck-fields.inc
Go to the documentation of this file.
1 /* src/vm/jit/verify/typecheck-fields.inc - type checking for field ICMDs
2 
3  Copyright (C) 1996-2005, 2006, 2008
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 
26 {
27  unresolved_field *uf;
28  constant_FMIref *fieldref;
29 #if !defined(TYPECHECK_TYPEINFERER)
30  typeinfo_t *instanceti;
31  typeinfo_t *valueti;
32  resolve_result_t result;
33 #endif
34 
35  TYPECHECK_COUNT(stat_ins_field);
36 
37 #if !defined(TYPECHECK_TYPEINFERER)
38  instanceti = (instance) ? &(instance->typeinfo) : NULL;
39  valueti = (value && value->type == TYPE_ADR) ? &(value->typeinfo) : NULL;
40 #endif
41 
42  /* get the field reference from the instruction */
43 
44  if (INSTRUCTION_IS_UNRESOLVED(state->iptr)) {
45  uf = state->iptr->sx.s23.s3.uf;
46  fieldref = uf->fieldref;
47  }
48  else {
49  uf = NULL;
50  fieldref = state->iptr->sx.s23.s3.fmiref;
51  }
52 
53 #if !defined(TYPECHECK_TYPEINFERER)
54  /* check the basic value type for PUT instructions */
55 
56  if (value && value->type != fieldref->parseddesc.fd->type)
57  VERIFY_ERROR("Field type mismatch");
58 
59  /* try to resolve the field reference lazily */
60 
61  result = resolve_field_lazy(state->m, fieldref);
62 
63  if (result == resolveSucceeded) {
64  fieldinfo *fi;
65 
66  /* perform verification checks now */
67 
68  fi = fieldref->p.field;
69 
71  state->m, fieldref, fi->clazz, fi,
72  instanceti, valueti,
73  (instance == NULL),
74  (value != NULL));
75  }
76 
77  if (result == resolveFailed)
78  EXCEPTION;
79 
80  /* if not resolved, yet, create an unresolved field */
81 
82  if (result != resolveSucceeded) {
83  if (!uf) {
84  uf = resolve_create_unresolved_field(state->m->clazz,
85  state->m, state->iptr);
86  if (!uf)
87  EXCEPTION;
88 
89  state->iptr->sx.s23.s3.uf = uf;
90  state->iptr->flags.bits |= INS_FLAG_UNRESOLVED;
91  }
92 
93  /* record the subtype constraints for this field access */
94 
96  uf, state->m->clazz, state->m,
97  instanceti, valueti))
98  EXCEPTION; /* XXX maybe wrap exception? */
99 
100  TYPECHECK_COUNTIF(INSTRUCTION_IS_UNRESOLVED(state->iptr),stat_ins_field_unresolved);
102  !state->iptr->sx.s23.s3.fmiref->p.field->clazz->initialized,
103  stat_ins_field_uninitialized);
104  }
105 #endif /* !defined(TYPECHECK_TYPEINFERER) */
106 
107  /* write the result type */
108 
109  if (value == NULL) {
110 #if defined(TYPECHECK_STACKBASED)
111  typedescriptor_t *dv;
112 
113  if (IS_2_WORD_TYPE(fieldref->parseddesc.fd->type)) {
115  stack += 2;
116  dv = &(stack[-1]);
117  stack[0].type = TYPE_VOID;
118  }
119  else {
121  stack += 1;
122  dv = stack;
123  }
124 #define DST dv
125 #else
126 #define DST VAROP(state->iptr->dst)
127 #endif
128  DST->type = fieldref->parseddesc.fd->type;
129  if (DST->type == TYPE_ADR) {
130  if (!DST->typeinfo.init_from_typedesc(fieldref->parseddesc.fd, NULL))
131  EXCEPTION;
132  }
133 #undef DST
134  }
135 }
136 
137 /*
138  * These are local overrides for various environment variables in Emacs.
139  * Please do not remove this and leave it at the end of the file, where
140  * Emacs will automagically detect them.
141  * ---------------------------------------------------------------------
142  * Local variables:
143  * mode: c
144  * indent-tabs-mode: t
145  * c-basic-offset: 4
146  * tab-width: 4
147  * End:
148  * vim:noexpandtab:sw=4:ts=4:filetype=c:
149  */
#define TYPECHECK_COUNT(cnt)
#define EXCEPTION
#define DST(typed, index)
Definition: stack.cpp:415
unresolved_field * resolve_create_unresolved_field(classinfo *referer, methodinfo *refmethod, instruction *iptr)
Definition: resolve.cpp:2402
#define CHECK_STACK_SPACE(d)
resolve_result_t resolve_field_lazy(methodinfo *refmethod, constant_FMIref *fieldref)
Definition: resolve.cpp:1261
union constant_FMIref::@26 p
#define IS_2_WORD_TYPE(a)
Definition: global.hpp:132
#define VERIFY_ERROR(msg)
constant_FMIref * fieldref
Definition: resolve.hpp:88
alloc::list< PassInfo::IDTy >::type & stack
typedesc * fd
Definition: references.hpp:74
Fieldref, Methodref and InterfaceMethodref.
Definition: references.hpp:86
resolve_result_t resolve_field_verifier_checks(methodinfo *refmethod, constant_FMIref *fieldref, classinfo *container, fieldinfo *fi, typeinfo_t *instanceti, typeinfo_t *valueti, bool isstatic, bool isput)
Definition: resolve.cpp:1081
classinfo * clazz
Definition: field.hpp:55
#define TYPECHECK_COUNTIF(cond, cnt)
#define INSTRUCTION_IS_UNRESOLVED(iptr)
const parseddesc_t parseddesc
Definition: references.hpp:105
#define INSTRUCTION_IS_RESOLVED(iptr)
fieldinfo * field
Definition: references.hpp:100
resolve_result_t
Definition: resolve.hpp:67
bool resolve_constrain_unresolved_field(unresolved_field *ref, classinfo *referer, methodinfo *refmethod, typeinfo_t *instanceti, typeinfo_t *valueti)
Definition: resolve.cpp:2485