LCOV - code coverage report
Current view: top level - vm/jit/verify - typecheck-fields.inc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 24 37 64.9 %
Date: 2015-06-10 18:10:59 Functions: 0 0 -

          Line data    Source code
       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      225545 :         instanceti = (instance) ? &(instance->typeinfo) : NULL;
      39      225545 :         valueti    = (value && value->type == TYPE_ADR) ? &(value->typeinfo) : NULL;
      40             : #endif
      41             : 
      42             :         /* get the field reference from the instruction */
      43             : 
      44      225545 :         if (INSTRUCTION_IS_UNRESOLVED(state->iptr)) {
      45         673 :                 uf = state->iptr->sx.s23.s3.uf;
      46         673 :                 fieldref = uf->fieldref;
      47             :         }
      48             :         else {
      49      224872 :                 uf = NULL;
      50      224872 :                 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      225545 :         if (value && value->type != fieldref->parseddesc.fd->type)
      57           0 :                 VERIFY_ERROR("Field type mismatch");
      58             : 
      59             :         /* try to resolve the field reference lazily */
      60             : 
      61      225545 :         result = resolve_field_lazy(state->m, fieldref);
      62             : 
      63      225545 :         if (result == resolveSucceeded) {
      64             :                 fieldinfo *fi;
      65             : 
      66             :                 /* perform verification checks now */
      67             : 
      68      205704 :                 fi  = fieldref->p.field;
      69             : 
      70             :                 result = resolve_field_verifier_checks(
      71             :                                 state->m, fieldref, fi->clazz, fi,
      72             :                                 instanceti, valueti,
      73             :                                 (instance == NULL),
      74      205704 :                                 (value != NULL));
      75             :         }
      76             : 
      77      225545 :         if (result == resolveFailed)
      78           0 :                 EXCEPTION;
      79             : 
      80             :         /* if not resolved, yet, create an unresolved field */
      81             : 
      82      225545 :         if (result != resolveSucceeded) {
      83       21595 :                 if (!uf) {
      84             :                         uf = resolve_create_unresolved_field(state->m->clazz, 
      85       20922 :                                         state->m, state->iptr);
      86       20922 :                         if (!uf)
      87           0 :                                 EXCEPTION;
      88             : 
      89       20922 :                         state->iptr->sx.s23.s3.uf = uf;
      90       20922 :                         state->iptr->flags.bits |= INS_FLAG_UNRESOLVED;
      91             :                 }
      92             : 
      93             :                 /* record the subtype constraints for this field access */
      94             : 
      95       21595 :                 if (!resolve_constrain_unresolved_field(
      96             :                                         uf, state->m->clazz, state->m,
      97             :                                         instanceti, valueti))
      98           0 :                         EXCEPTION; /* XXX maybe wrap exception? */
      99             : 
     100             :                 TYPECHECK_COUNTIF(INSTRUCTION_IS_UNRESOLVED(state->iptr),stat_ins_field_unresolved);
     101             :                 TYPECHECK_COUNTIF(INSTRUCTION_IS_RESOLVED(state->iptr) && 
     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      225545 :         if (value == NULL) {
     110             : #if defined(TYPECHECK_STACKBASED)
     111             :                 typedescriptor_t *dv;
     112             : 
     113           0 :                 if (IS_2_WORD_TYPE(fieldref->parseddesc.fd->type)) {
     114           0 :                         CHECK_STACK_SPACE(2);
     115           0 :                         stack += 2;
     116           0 :                         dv = &(stack[-1]);
     117           0 :                         stack[0].type = TYPE_VOID;
     118             :                 }
     119             :                 else {
     120           0 :                         CHECK_STACK_SPACE(1);
     121           0 :                         stack += 1;
     122           0 :                         dv = stack;
     123             :                 }
     124             : #define DST dv
     125             : #else
     126             : #define DST VAROP(state->iptr->dst)
     127             : #endif
     128      150518 :                 DST->type = fieldref->parseddesc.fd->type;
     129      150518 :                 if (DST->type == TYPE_ADR) {
     130      102275 :                         if (!DST->typeinfo.init_from_typedesc(fieldref->parseddesc.fd, NULL))
     131           0 :                                 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             :  */

Generated by: LCOV version 1.11