LCOV - code coverage report
Current view: top level - vm - loader.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 6 12 50.0 %
Date: 2017-07-14 10:03:36 Functions: 3 5 60.0 %

          Line data    Source code
       1             : /* src/vm/loader.hpp - class loader header
       2             : 
       3             :    Copyright (C) 1996-2013
       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             : #ifndef LOADER_HPP_
      27             : #define LOADER_HPP_ 1
      28             : 
      29             : #include "config.h"
      30             : 
      31             : #include <stdint.h>                     // for uint8_t, int32_t
      32             : 
      33             : #include "vm/global.hpp"                // for java_handle_t, etc
      34             : #include "vm/types.hpp"                 // for s4, s8
      35             : #include "vm/utf8.hpp"                  // for Utf8String
      36             : 
      37             : struct classinfo;
      38             : struct constant_nameandtype;
      39             : 
      40             : namespace cacao { struct ClassBuffer; }
      41             : 
      42             : 
      43             : /* classloader *****************************************************************
      44             : 
      45             :    [!ENABLE_HANDLES]: The classloader is a Java Object which cannot move.
      46             :    [ENABLE_HANDLES] : The classloader entry itself is a static handle for a
      47             :                       given classloader (use loader_hashtable_classloader_foo).
      48             : 
      49             : *******************************************************************************/
      50             : 
      51             : #if defined(ENABLE_HANDLES)
      52             : typedef hashtable_classloader_entry classloader_t;
      53             : #else
      54             : typedef java_object_t               classloader_t;
      55             : #endif
      56             : 
      57             : /* constant pool entries *******************************************************
      58             : 
      59             :         All constant pool entries need a data structure which contain the entrys
      60             :         value. In some cases this structure exist already, in the remaining cases
      61             :         this structure must be generated:
      62             : 
      63             :                 kind                      structure                     generated?
      64             :         ----------------------------------------------------------------------
      65             :     CONSTANT_Class               constant_classref                  yes
      66             :     CONSTANT_Fieldref            constant_FMIref                    yes
      67             :     CONSTANT_Methodref           constant_FMIref                    yes
      68             :     CONSTANT_InterfaceMethodref  constant_FMIref                    yes
      69             :     CONSTANT_String              unicode                             no
      70             :     CONSTANT_Integer             int32_t                            yes
      71             :     CONSTANT_Float               float                              yes
      72             :     CONSTANT_Long                int64_t                            yes
      73             :     CONSTANT_Double              double                             yes
      74             :     CONSTANT_NameAndType         constant_nameandtype               yes
      75             :     CONSTANT_Utf8                unicode                             no
      76             :     CONSTANT_UNUSED              -
      77             : 
      78             : *******************************************************************************/
      79             : 
      80             : struct  constant_nameandtype {         /* NameAndType (Field or Method)       */
      81      576467 :         constant_nameandtype(Utf8String name, Utf8String desc) : name(name), descriptor(desc) {}
      82             : 
      83             :         const Utf8String name;               /* field/method name                   */
      84             :         const Utf8String descriptor;         /* field/method type descriptor string */
      85             : };
      86             : 
      87             : 
      88             : /* hashtable_classloader_entry *************************************************
      89             : 
      90             :    ATTENTION: The pointer to the classloader object needs to be the
      91             :    first field of the entry, so that it can be used as an indirection
      92             :    cell. This is checked by gc_init() during startup.
      93             : 
      94             : *******************************************************************************/
      95             : 
      96             : struct hashtable_classloader_entry {
      97             :         java_object_t               *object;
      98             :         hashtable_classloader_entry *hashlink;
      99             : };
     100             : 
     101             : 
     102             : namespace cacao {
     103             :         /**
     104             :          * A version of the Java class file format.
     105             :          *
     106             :          * @Cpp11 Make all methods, ctors, statics a constexpr
     107             :          */
     108             :         struct ClassFileVersion {
     109             :                 /**
     110             :                  * The class file format version supported by CACAO
     111             :                  */
     112             :                 static const ClassFileVersion CACAO_VERSION;
     113             : 
     114             :                 /**
     115             :                  * The class file format version used by JDK 7
     116             :                  */
     117             :                 static const ClassFileVersion JDK_7;
     118             : 
     119             : 
     120       36120 :                 ClassFileVersion(uint16_t major, uint16_t minor = 0) : _majr(major), _minr(minor) {}
     121             : 
     122             :                 bool operator ==(ClassFileVersion v) const {
     123             :                         return _majr == v._majr && _minr == v._minr;
     124             :                 }
     125             : 
     126             :                 /// A strict weak ordering as required by STL
     127       35790 :                 bool operator <(ClassFileVersion v) const {
     128       35790 :                         if (_majr < v._majr)
     129           0 :                                 return true;
     130       35790 :                         if (v._majr < _majr)
     131       35790 :                                 return false;
     132             : 
     133             :                         // major versions are equal
     134             : 
     135           0 :                         if (_minr < v._minr)
     136           0 :                                 return true;
     137           0 :                         return false;
     138             :                 }
     139             : 
     140             :                 bool operator <=(ClassFileVersion v) const {
     141             :                         return (*this == v) || (*this < v);
     142             :                 }
     143             : 
     144             :                 // we can't call these major/minor because GCC defines macros of that name
     145           0 :                 uint16_t majr() const { return _majr; }
     146           0 :                 uint16_t minr() const { return _minr; }
     147             :         private:
     148             :                 uint16_t _majr, _minr;
     149             :         };
     150             : }
     151             : 
     152             : 
     153             : /* function prototypes ********************************************************/
     154             : 
     155             : void loader_preinit(void);
     156             : void loader_init(void);
     157             : 
     158             : /* classloader management functions */
     159             : classloader_t *loader_hashtable_classloader_add(java_handle_t *cl);
     160             : classloader_t *loader_hashtable_classloader_find(java_handle_t *cl);
     161             : 
     162             : void loader_load_all_classes(void);
     163             : 
     164             : bool loader_skip_attribute_body(cacao::ClassBuffer& cb);
     165             : 
     166             : #if defined(ENABLE_JAVASE)
     167             : bool loader_load_attribute_signature(cacao::ClassBuffer& cb, Utf8String& signature);
     168             : #endif
     169             : 
     170             : /* free resources */
     171             : void loader_close(void);
     172             : 
     173             : /* class loading functions */
     174             : classinfo *load_class_from_sysloader(Utf8String name);
     175             : classinfo *load_class_from_classloader(Utf8String name, classloader_t *cl);
     176             : classinfo *load_class_bootstrap(Utf8String name);
     177             : 
     178             : /* (don't use the following directly) */
     179             : classinfo *load_class_from_classbuffer(cacao::ClassBuffer& cb);
     180             : classinfo *load_newly_created_array(classinfo *c, classloader_t *loader);
     181             : 
     182             : #endif // LOADER_HPP_
     183             : 
     184             : 
     185             : /*
     186             :  * These are local overrides for various environment variables in Emacs.
     187             :  * Please do not remove this and leave it at the end of the file, where
     188             :  * Emacs will automagically detect them.
     189             :  * ---------------------------------------------------------------------
     190             :  * Local variables:
     191             :  * mode: c++
     192             :  * indent-tabs-mode: t
     193             :  * c-basic-offset: 4
     194             :  * tab-width: 4
     195             :  * End:
     196             :  * vim:noexpandtab:sw=4:ts=4:
     197             :  */

Generated by: LCOV version 1.11