CACAO
references.hpp
Go to the documentation of this file.
1 /* src/vm/references.hpp - references to classes/fields/methods
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 #ifndef REFERENCES_HPP_
26 #define REFERENCES_HPP_ 1
27 
28 #include "config.h"
29 
30 #include "vm/global.hpp"
31 #include "vm/types.hpp"
32 #include "vm/utf8.hpp"
33 
34 struct classinfo;
35 struct typedesc;
36 struct fieldinfo;
37 struct methoddesc;
38 struct methodinfo;
39 
40 /* constant_classref **********************************************************/
41 
42 /// a value that never occurrs in classinfo.header.vftbl
43 #define CLASSREF_PSEUDO_VFTBL (reinterpret_cast<void *>(1))
44 
46  void* const pseudo_vftbl; /* for distinguishing it from classinfo */
47  classinfo* const referer; /* class containing the reference */
48  const Utf8String name; /* name of the class refered to */
49 
51  : pseudo_vftbl(CLASSREF_PSEUDO_VFTBL), referer(referer), name(name) {}
52 };
53 
54 
55 /* classref_or_classinfo ******************************************************/
56 
57 /**
58  * @Cpp11 Replace static constructors with regular constructors.
59  * With C++98 this breaks other unions that use classref_or_classinfo.
60  */
62  constant_classref *ref; /* a symbolic class reference */
63  classinfo *cls; /* an already loaded class */
64  void *any; /* used for general access (x != NULL,...) */
65 
66  bool is_classref() const { return ref->pseudo_vftbl == CLASSREF_PSEUDO_VFTBL; }
67  bool is_classinfo() const { return !is_classref(); }
68 };
69 
70 
71 /* parseddesc_t ***************************************************************/
72 
73 union parseddesc_t {
74  typedesc *fd; /* parsed field descriptor */
75  methoddesc *md; /* parsed method descriptor */
76 
77  // test against NULL;
78  operator bool() const { return fd; }
79 };
80 
81 /* structs ********************************************************************/
82 
83 /**
84  * Fieldref, Methodref and InterfaceMethodref
85  */
91  : name(name), descriptor(descriptor), parseddesc(parseddesc) {
92  p.classref = ref;
93  }
94 
95  union {
96  // set when FMIref is unresolved
97  constant_classref *classref; /* class having this field/meth./intfm. */
98 
99  // set when FMIref is resolved
100  fieldinfo *field; /* resolved field */
101  methodinfo *method; /* resolved method */
102  } p;
103  const Utf8String name; /* field/method/interfacemethod name */
104  const Utf8String descriptor; /* field/method/intfmeth. type descriptor string */
105  const parseddesc_t parseddesc; /* parsed descriptor */
106 
107  bool is_resolved() const { return p.classref->pseudo_vftbl != CLASSREF_PSEUDO_VFTBL; }
108 };
109 
110 /// The kinds of methodhandles that can appear in a class file
121 };
122 
123 /***
124  * A MethodHandle constant stored in the constant pool
125  */
128  : kind(kind), fmi(fmi), handle(NULL) {}
129 
132 
133  /// resolved java.lang.invoke.MethodHandle object
135 };
136 
137 /**
138  * A MethodType constant stored in the constant pool
139  */
142  : descriptor(desc), parseddesc(parseddesc), type(NULL) {}
143 
145  const methoddesc *const parseddesc;
146 
147  /// resolved java.lang.invoke.MethodType object
149 };
150 
151 /**
152  * An invokedynamic call site.
153  */
156  : bootstrap_method_index(bsm), name(name), descriptor(desc), parseddesc(parseddesc), handle(NULL) {}
157 
158  const uint16_t bootstrap_method_index;
161  const methoddesc *const parseddesc;
162 
163  /// resolved java.lang.invoke.MethodHandle object for this CallSite
165 };
166 
167 
168 /* inline functions ***********************************************************/
169 
170 /**
171  * Functions for casting a classref/classinfo to a classref_or_classinfo
172  * @Cpp11 Replace with constructors in classref_or_classinfo.
173  * With C++98 this breaks other unions that use classref_or_classinfo.
174  * @{
175  */
178  out.cls = c;
179  return out;
180 }
183  out.ref = c;
184  return out;
185 }
186 /**
187  * @}
188  */
189 
190 
191 /* macros *********************************************************************/
192 
193 /* macro for accessing the name of a classref/classinfo */
194 #define CLASSREF_OR_CLASSINFO_NAME(value) \
195  ((value).is_classref() ? (value).ref->name : (value).cls->name)
196 
197 /* macro for accessing the class name of a method reference */
198 #define METHODREF_CLASSNAME(fmiref) \
199  ((fmiref)->is_resolved() ? (fmiref)->p.method->clazz->name \
200  : (fmiref)->p.classref->name)
201 
202 /* macro for accessing the class name of a method reference */
203 #define FIELDREF_CLASSNAME(fmiref) \
204  ((fmiref)->is_resolved() ? (fmiref)->p.field->clazz->name \
205  : (fmiref)->p.classref->name)
206 
207 #endif // REFERENCES_HPP_
208 
209 /*
210  * These are local overrides for various environment variables in Emacs.
211  * Please do not remove this and leave it at the end of the file, where
212  * Emacs will automagically detect them.
213  * ---------------------------------------------------------------------
214  * Local variables:
215  * mode: c++
216  * indent-tabs-mode: t
217  * c-basic-offset: 4
218  * tab-width: 4
219  * End:
220  * vim:noexpandtab:sw=4:ts=4:
221  */
222 
A MethodType constant stored in the constant pool.
Definition: references.hpp:140
constant_FMIref *const fmi
Definition: references.hpp:131
bool is_classref() const
Definition: references.hpp:66
constant_MethodHandle(MethodHandleKind kind, constant_FMIref *fmi)
Definition: references.hpp:127
An invokedynamic call site.
Definition: references.hpp:154
void *const pseudo_vftbl
Definition: references.hpp:46
union constant_FMIref::@26 p
methoddesc * md
Definition: references.hpp:75
java_object_t * handle
resolved java.lang.invoke.MethodHandle object
Definition: references.hpp:134
constant_classref * ref
Definition: references.hpp:62
constant_InvokeDynamic(uint16_t bsm, Utf8String name, Utf8String desc, methoddesc *parseddesc)
Definition: references.hpp:155
JNIEnv jclass jobject const char * name
Definition: jvmti.h:312
methodinfo * method
Definition: references.hpp:101
const Utf8String name
Definition: references.hpp:103
const MethodHandleKind kind
Definition: references.hpp:130
const uint16_t bootstrap_method_index
Definition: references.hpp:158
const methoddesc *const parseddesc
Definition: references.hpp:161
const Utf8String name
Definition: references.hpp:159
java_object_t * type
resolved java.lang.invoke.MethodType object
Definition: references.hpp:148
bool is_resolved() const
Definition: references.hpp:107
constant_classref(classinfo *referer, Utf8String name)
Definition: references.hpp:50
constant_MethodType(Utf8String desc, methoddesc *parseddesc)
Definition: references.hpp:141
typedesc * fd
Definition: references.hpp:74
const Utf8String descriptor
Definition: references.hpp:160
constant_FMIref(constant_classref *ref, Utf8String name, Utf8String descriptor, parseddesc_t parseddesc)
Definition: references.hpp:87
Fieldref, Methodref and InterfaceMethodref.
Definition: references.hpp:86
java_object_t * handle
resolved java.lang.invoke.MethodHandle object for this CallSite
Definition: references.hpp:164
const Utf8String descriptor
Definition: references.hpp:104
const Utf8String descriptor
Definition: references.hpp:144
const methoddesc *const parseddesc
Definition: references.hpp:145
constant_classref * classref
Definition: references.hpp:97
OStream & out()
Definition: OStream.cpp:39
classinfo *const referer
Definition: references.hpp:47
static classref_or_classinfo to_classref_or_classinfo(classinfo *c)
Functions for casting a classref/classinfo to a classref_or_classinfo.
Definition: references.hpp:176
#define CLASSREF_PSEUDO_VFTBL
a value that never occurrs in classinfo.header.vftbl
Definition: references.hpp:43
const parseddesc_t parseddesc
Definition: references.hpp:105
fieldinfo * field
Definition: references.hpp:100
MethodHandleKind
The kinds of methodhandles that can appear in a class file.
Definition: references.hpp:111
const Utf8String name
Definition: references.hpp:48
bool is_classinfo() const
Definition: references.hpp:67