CACAO
loader.hpp
Go to the documentation of this file.
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;
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)
53 #else
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) */
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 
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  */
109  /**
110  * The class file format version supported by CACAO
111  */
113 
114  /**
115  * The class file format version used by JDK 7
116  */
117  static const ClassFileVersion JDK_7;
118 
119 
120  ClassFileVersion(uint16_t major, uint16_t minor = 0) : _majr(major), _minr(minor) {}
121 
123  return _majr == v._majr && _minr == v._minr;
124  }
125 
126  /// A strict weak ordering as required by STL
127  bool operator <(ClassFileVersion v) const {
128  if (_majr < v._majr)
129  return true;
130  if (v._majr < _majr)
131  return false;
132 
133  // major versions are equal
134 
135  if (_minr < v._minr)
136  return true;
137  return false;
138  }
139 
141  return (*this == v) || (*this < v);
142  }
143 
144  // we can't call these major/minor because GCC defines macros of that name
145  uint16_t majr() const { return _majr; }
146  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 */
161 
162 void loader_load_all_classes(void);
163 
165 
166 #if defined(ENABLE_JAVASE)
168 #endif
169 
170 /* free resources */
171 void loader_close(void);
172 
173 /* class loading functions */
177 
178 /* (don't use the following directly) */
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  */
uint16_t majr() const
Definition: loader.hpp:145
java_object_t * object
Definition: loader.hpp:97
constant_nameandtype(Utf8String name, Utf8String desc)
Definition: loader.hpp:81
classinfo * load_class_from_classbuffer(ClassBuffer &cb)
Definition: loader.cpp:2021
classinfo * load_newly_created_array(classinfo *c, classloader_t *loader)
Definition: loader.cpp:2094
classinfo * load_class_from_sysloader(Utf8String name)
Definition: loader.cpp:1012
static const ClassFileVersion JDK_7
The class file format version used by JDK 7.
Definition: loader.hpp:117
hashtable_classloader_entry * hashlink
Definition: loader.hpp:98
ClassFileVersion(uint16_t major, uint16_t minor=0)
Definition: loader.hpp:120
void loader_close(void)
Definition: loader.cpp:2263
void loader_init(void)
Definition: loader.cpp:184
classinfo * load_class_bootstrap(Utf8String name)
Definition: loader.cpp:1276
JNIEnv jclass jobject const char * name
Definition: jvmti.h:312
classloader_t * loader_hashtable_classloader_add(java_handle_t *cl)
Definition: loader.cpp:305
bool loader_skip_attribute_body(ClassBuffer &cb)
Definition: loader.cpp:499
java_object_t classloader_t
Definition: loader.hpp:54
A version of the Java class file format.
Definition: loader.hpp:108
bool operator<(ClassFileVersion v) const
A strict weak ordering as required by STL.
Definition: loader.hpp:127
classloader_t * loader_hashtable_classloader_find(java_handle_t *cl)
Definition: loader.cpp:387
const Utf8String name
Definition: loader.hpp:83
void loader_load_all_classes(void)
Definition: loader.cpp:439
JNIEnv jclass jobject loader
Definition: jvmti.h:312
bool loader_load_attribute_signature(ClassBuffer &cb, Utf8String &signature)
Definition: loader.cpp:960
uint16_t minr() const
Definition: loader.hpp:146
void loader_preinit(void)
Definition: loader.cpp:141
bool operator<=(ClassFileVersion v) const
Definition: loader.hpp:140
Definition: loader.hpp:96
classinfo * load_class_from_classloader(Utf8String name, classloader_t *cl)
Definition: loader.cpp:1071
static const ClassFileVersion CACAO_VERSION
The class file format version supported by CACAO.
Definition: loader.hpp:112
bool operator==(ClassFileVersion v) const
Definition: loader.hpp:122
const Utf8String descriptor
Definition: loader.hpp:84