* Removed all Id tags.
[cacao.git] / src / vm / jit / verify / typecheck-fields.inc
1 /* src/vm/jit/verify/typecheck-fields.inc - type checking for field ICMDs
2
3    Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Edwin Steiner
28
29    Changes: 
30
31 */
32
33
34 {
35         unresolved_field *uf;
36         constant_FMIref *fieldref;
37         typeinfo *instanceti;
38         typeinfo *valueti;
39 #if !defined(TYPECHECK_TYPEINFERER)
40         resolve_result_t result;
41 #endif
42
43         TYPECHECK_COUNT(stat_ins_field);
44
45         instanceti = (instance) ? &(instance->typeinfo) : NULL;
46         valueti    = (value && value->type == TYPE_ADR) ? &(value->typeinfo) : NULL;
47
48         /* get the field reference from the instruction */
49
50         if (INSTRUCTION_IS_UNRESOLVED(state->iptr)) {
51                 uf = state->iptr->sx.s23.s3.uf;
52                 fieldref = uf->fieldref;
53         }
54         else {
55                 uf = NULL;
56                 fieldref = state->iptr->sx.s23.s3.fmiref;
57         }
58
59 #if !defined(TYPECHECK_TYPEINFERER)
60         /* check the basic value type for PUT instructions */
61
62         if (value && value->type != fieldref->parseddesc.fd->type)
63                 VERIFY_ERROR("Field type mismatch");
64
65         /* try to resolve the field reference lazily */
66
67         result = resolve_field_lazy(state->m, fieldref);
68
69         if (result == resolveSucceeded) {
70                 fieldinfo *fi;
71
72                 /* perform verification checks now */
73
74                 fi  = fieldref->p.field;
75
76                 result = resolve_field_verifier_checks(
77                                 state->m, fieldref, fi->class, fi,
78                                 instanceti, valueti,
79                                 (instance == NULL),
80                                 (value != NULL));
81         }
82
83         if (result == resolveFailed)
84                 EXCEPTION;
85
86         /* if not resolved, yet, create an unresolved field */
87
88         if (result != resolveSucceeded) {
89                 if (!uf) {
90                         uf = resolve_create_unresolved_field(state->m->class, 
91                                         state->m, state->iptr);
92                         if (!uf)
93                                 EXCEPTION;
94
95                         state->iptr->sx.s23.s3.uf = uf;
96                         state->iptr->flags.bits |= INS_FLAG_UNRESOLVED;
97                 }
98
99                 /* record the subtype constraints for this field access */
100
101                 if (!resolve_constrain_unresolved_field(
102                                         uf, state->m->class, state->m,
103                                         instanceti, valueti))
104                         EXCEPTION; /* XXX maybe wrap exception? */
105
106                 TYPECHECK_COUNTIF(INSTRUCTION_IS_UNRESOLVED(state->iptr),stat_ins_field_unresolved);
107                 TYPECHECK_COUNTIF(INSTRUCTION_IS_RESOLVED(state->iptr) && 
108                                 !state->iptr->sx.s23.s3.fmiref->p.field->class->initialized,
109                                 stat_ins_field_uninitialized);
110         }
111 #endif /* !defined(TYPECHECK_TYPEINFERER) */
112                 
113         /* write the result type */
114
115         if (value == NULL) {
116 #if defined(TYPECHECK_STACKBASED)
117                 typedescriptor *dv;
118
119                 if (IS_2_WORD_TYPE(fieldref->parseddesc.fd->type)) {
120                         CHECK_STACK_SPACE(2);
121                         stack += 2;
122                         dv = &(stack[-1]);
123                         stack[0].type = TYPE_VOID;
124                 }
125                 else {
126                         CHECK_STACK_SPACE(1);
127                         stack += 1;
128                         dv = stack;
129                 }
130 #define DST dv
131 #else
132 #define DST VAROP(state->iptr->dst)
133 #endif
134                 DST->type = fieldref->parseddesc.fd->type;
135                 if (DST->type == TYPE_ADR) {
136                         if (!typeinfo_init_from_typedesc(fieldref->parseddesc.fd,NULL,&(DST->typeinfo)))
137                                 EXCEPTION;
138                 }
139 #undef DST
140         }
141 }
142
143 /*
144  * These are local overrides for various environment variables in Emacs.
145  * Please do not remove this and leave it at the end of the file, where
146  * Emacs will automagically detect them.
147  * ---------------------------------------------------------------------
148  * Local variables:
149  * mode: c
150  * indent-tabs-mode: t
151  * c-basic-offset: 4
152  * tab-width: 4
153  * End:
154  * vim:noexpandtab:sw=4:ts=4:filetype=c:
155  */