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

          Line data    Source code
       1             : /* src/vm/jit/verify/typecheck-builtins.inc - type checking for ICMD_BUILTIN
       2             : 
       3             :    Copyright (C) 1996-2014
       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             : #define ISBUILTIN(v)   (bte->fp == (functionptr) (v))
      27             : 
      28             : {
      29             :         builtintable_entry *bte;
      30             : 
      31       79492 :         bte = state->iptr->sx.s23.s3.bte;
      32             : 
      33             :         /* XXX this is an ugly if-chain but twisti did not want a function */
      34             :         /* pointer in builtintable_entry for this, so here you go.. ;)     */
      35             : 
      36       79492 :         if (ISBUILTIN(BUILTIN_new)) {
      37       53098 :                 dv->type = TYPE_ADR;
      38             : #if defined(TYPECHECK_TYPEINFERER)
      39           0 :                 assert(state->iptr[-1].opc == ICMD_ACONST);
      40           0 :                 dv->typeinfo.init_class(state->iptr[-1].sx.val.c);
      41             : #else
      42       53098 :                 if (state->iptr[-1].opc != ICMD_ACONST)
      43           0 :                         TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_new without class");
      44       53098 :                 dv->typeinfo.init_newobject(state->iptr);
      45             : #endif
      46             :         }
      47       26394 :         else if (ISBUILTIN(BUILTIN_newarray_boolean)) {
      48           3 :                 TYPECHECK_INT(OP1);
      49           3 :                 dv->type = TYPE_ADR;
      50           3 :                 dv->typeinfo.init_primitive_array(ARRAYTYPE_BOOLEAN);
      51             :         }
      52       26391 :         else if (ISBUILTIN(BUILTIN_newarray_char)) {
      53        3715 :                 TYPECHECK_INT(OP1);
      54        3715 :                 dv->type = TYPE_ADR;
      55        3715 :                 dv->typeinfo.init_primitive_array(ARRAYTYPE_CHAR);
      56             :         }
      57       22676 :         else if (ISBUILTIN(BUILTIN_newarray_float)) {
      58           6 :                 TYPECHECK_INT(OP1);
      59           6 :                 dv->type = TYPE_ADR;
      60           6 :                 dv->typeinfo.init_primitive_array(ARRAYTYPE_FLOAT);
      61             :         }
      62       22670 :         else if (ISBUILTIN(BUILTIN_newarray_double)) {
      63           6 :                 TYPECHECK_INT(OP1);
      64           6 :                 dv->type = TYPE_ADR;
      65           6 :                 dv->typeinfo.init_primitive_array(ARRAYTYPE_DOUBLE);
      66             :         }
      67       22664 :         else if (ISBUILTIN(BUILTIN_newarray_byte)) {
      68        1741 :                 TYPECHECK_INT(OP1);
      69        1741 :                 dv->type = TYPE_ADR;
      70        1741 :                 dv->typeinfo.init_primitive_array(ARRAYTYPE_BYTE);
      71             :         }
      72       20923 :         else if (ISBUILTIN(BUILTIN_newarray_short)) {
      73          27 :                 TYPECHECK_INT(OP1);
      74          27 :                 dv->type = TYPE_ADR;
      75          27 :                 dv->typeinfo.init_primitive_array(ARRAYTYPE_SHORT);
      76             :         }
      77       20896 :         else if (ISBUILTIN(BUILTIN_newarray_int)) {
      78         419 :                 TYPECHECK_INT(OP1);
      79         419 :                 dv->type = TYPE_ADR;
      80         419 :                 dv->typeinfo.init_primitive_array(ARRAYTYPE_INT);
      81             :         }
      82       20477 :         else if (ISBUILTIN(BUILTIN_newarray_long)) {
      83          20 :                 TYPECHECK_INT(OP1);
      84          20 :                 dv->type = TYPE_ADR;
      85          20 :                 dv->typeinfo.init_primitive_array(ARRAYTYPE_LONG);
      86             :         }
      87       20457 :         else if (ISBUILTIN(BUILTIN_newarray))
      88             :         {
      89        9298 :                 TYPECHECK_INT(OP1);
      90        9298 :                 if (state->iptr[-1].opc != ICMD_ACONST)
      91           0 :                         TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_newarray without class");
      92             :                 /* XXX check that it is an array class(ref) */
      93        9298 :                 dv->type = TYPE_ADR;
      94        9298 :                 dv->typeinfo.init_class(state->iptr[-1].sx.val.c);
      95             :         }
      96       11159 :         else if (ISBUILTIN(BUILTIN_arrayinstanceof))
      97             :         {
      98          99 :                 TYPECHECK_ADR(OP1);
      99          99 :                 if (state->iptr[-1].opc != ICMD_ACONST)
     100           0 :                         TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_arrayinstanceof without class");
     101          99 :                 dv->type = TYPE_INT;
     102             :                 /* XXX check that it is an array class(ref) */
     103             :         }
     104             :         else {
     105             :                 methoddesc *md;
     106             :                 Type        rtype;
     107             : #if !defined(TYPECHECK_TYPEINFERER)
     108             :                 s4 i;
     109             : #endif
     110             : #if defined(TYPECHECK_STACKBASED)
     111             :                 typedescriptor_t *av;
     112             : #endif
     113             : 
     114             :                 /* verify a generic builtin call */
     115             : 
     116             :                 TYPECHECK_COUNT(stat_ins_builtin_gen);
     117             : 
     118       11060 :                 md = bte->md;
     119             : #if !defined(TYPECHECK_TYPEINFERER)
     120       11060 :                 i = md->paramcount;
     121             : 
     122             :                 /* check the types of the arguments on the stack */
     123             : 
     124             : #if defined(TYPECHECK_STACKBASED)
     125           0 :                 av = stack - (md->paramslots - 1);
     126             : #endif
     127             : 
     128       27219 :                 for (i--; i >= 0; i--) {
     129             : #if defined(TYPECHECK_VARIABLESBASED)
     130       16159 :                         varinfo *av = VAR(state->iptr->sx.s23.s2.args[i]);
     131             : #endif
     132             : 
     133       16159 :                         if (av->type != md->paramtypes[i].type) {
     134           0 :                                 TYPECHECK_VERIFYERROR_bool("parameter type mismatch for builtin method");
     135             :                         }
     136             : 
     137             : #ifdef TYPECHECK_DEBUG
     138             :                         /* generic builtins may only take primitive types and java.lang.Object references */
     139       16159 :                         if (av->type == TYPE_ADR && md->paramtypes[i].classref->name != utf8::java_lang_Object) {
     140           0 :                                 exceptions_throw_internalerror("generic builtin method with non-generic reference parameter");
     141           0 :                                 return false;
     142             :                         }
     143             : #endif
     144             : 
     145             : #if defined(TYPECHECK_STACKBASED)
     146           0 :                         av += (IS_2_WORD_TYPE(av->type)) ? 2 : 1;
     147             : #endif
     148             :                 }
     149             : #endif /* !defined(TYPECHECK_TYPEINFERER) */
     150             : 
     151             :                 /* set the return type */
     152             : 
     153       11060 :                 rtype = md->returntype.type;
     154       11060 :                 if (rtype != TYPE_VOID) {
     155        1741 :                         dv->type = rtype;
     156        1741 :                         if (!dv->typeinfo.init_from_typedesc(&md->returntype, NULL))
     157           0 :                                 return false;
     158             :                 }
     159             :         }
     160             : }
     161             : 
     162             : #undef ISBUILTIN
     163             : 
     164             : /*
     165             :  * These are local overrides for various environment variables in Emacs.
     166             :  * Please do not remove this and leave it at the end of the file, where
     167             :  * Emacs will automagically detect them.
     168             :  * ---------------------------------------------------------------------
     169             :  * Local variables:
     170             :  * mode: c
     171             :  * indent-tabs-mode: t
     172             :  * c-basic-offset: 4
     173             :  * tab-width: 4
     174             :  * End:
     175             :  * vim:noexpandtab:sw=4:ts=4:filetype=c:
     176             :  */

Generated by: LCOV version 1.11