25 #ifndef SHARE_OOPS_OOPSHIERARCHY_HPP
26 #define SHARE_OOPS_OOPSHIERARCHY_HPP
27
28 #include "cppstdlib/type_traits.hpp"
29 #include "metaprogramming/primitiveConversions.hpp"
30 #include "utilities/globalDefinitions.hpp"
31
32 // OBJECT hierarchy
33 // This hierarchy is a representation hierarchy, i.e. if A is a superclass
34 // of B, A's representation is a prefix of B's representation.
35
36 // Global offset instead of address for an oop within a java object.
37 enum class narrowOop : uint32_t { null = 0 };
38
39 typedef void* OopOrNarrowOopStar;
40
41 #ifndef CHECK_UNHANDLED_OOPS
42
43 typedef class oopDesc* oop;
44 typedef class instanceOopDesc* instanceOop;
45 typedef class stackChunkOopDesc* stackChunkOop;
46 typedef class arrayOopDesc* arrayOop;
47 typedef class objArrayOopDesc* objArrayOop;
48 typedef class typeArrayOopDesc* typeArrayOop;
49
50 #else
51
52 // When CHECK_UNHANDLED_OOPS is defined, an "oop" is a class with a
53 // carefully chosen set of constructors and conversion operators to go
54 // to and from the underlying oopDesc pointer type.
55 //
56 // Because oop and its subclasses <type>Oop are class types, arbitrary
57 // conversions are not accepted by the compiler. Applying a cast to
58 // an oop will cause the best matched conversion operator to be
59 // invoked returning the underlying oopDesc* type if appropriate.
60 // No copy constructors, explicit user conversions or operators of
61 // numerical type should be defined within the oop class. Most C++
62 // compilers will issue a compile time error concerning the overloading
63 // ambiguity between operators of numerical and pointer types. If
64 // a conversion to or from an oop to a numerical type is needed,
65 // use the inline template methods, cast_*_oop, defined below.
66 //
67 // Converting null to oop to Handle implicit is no longer accepted by the
133 operator type##OopDesc* () const { return (type##OopDesc*)obj(); } \
134 type##OopDesc* operator->() const { \
135 return (type##OopDesc*)obj(); \
136 } \
137 type##Oop& operator=(const type##Oop& o) { \
138 oop::operator=(o); \
139 return *this; \
140 } \
141 }; \
142 \
143 template<> \
144 struct PrimitiveConversions::Translate<type##Oop> : public std::true_type { \
145 typedef type##Oop Value; \
146 typedef type##OopDesc* Decayed; \
147 \
148 static Decayed decay(Value x) { return (type##OopDesc*)x.obj(); } \
149 static Value recover(Decayed x) { return type##Oop(x); } \
150 };
151
152 DEF_OOP(instance);
153 DEF_OOP(stackChunk);
154 DEF_OOP(array);
155 DEF_OOP(objArray);
156 DEF_OOP(typeArray);
157
158 #endif // CHECK_UNHANDLED_OOPS
159
160 // Cast functions to convert to and from oops.
161 template <typename T> inline oop cast_to_oop(T value) {
162 return (oopDesc*)value;
163 }
164 template <typename T> inline T cast_from_oop(oop o) {
165 return (T)(CHECK_UNHANDLED_OOPS_ONLY((oopDesc*))o);
166 }
167
168 inline intptr_t p2i(narrowOop o) {
169 return static_cast<intptr_t>(o);
170 }
171
172 // The metadata hierarchy is separate from the oop hierarchy
173
174 // class MetaspaceObj
175 class ConstMethod;
176 class ConstantPoolCache;
177 class MethodData;
178 // class Metadata
179 class Method;
180 class ConstantPool;
181
182 // The klass hierarchy is separate from the oop hierarchy.
183
184 class Klass;
185 class InstanceKlass;
186 class InstanceMirrorKlass;
187 class InstanceClassLoaderKlass;
188 class InstanceRefKlass;
189 class InstanceStackChunkKlass;
190 class ArrayKlass;
191 class ObjArrayKlass;
192 class TypeArrayKlass;
193
194 #endif // SHARE_OOPS_OOPSHIERARCHY_HPP
|
25 #ifndef SHARE_OOPS_OOPSHIERARCHY_HPP
26 #define SHARE_OOPS_OOPSHIERARCHY_HPP
27
28 #include "cppstdlib/type_traits.hpp"
29 #include "metaprogramming/primitiveConversions.hpp"
30 #include "utilities/globalDefinitions.hpp"
31
32 // OBJECT hierarchy
33 // This hierarchy is a representation hierarchy, i.e. if A is a superclass
34 // of B, A's representation is a prefix of B's representation.
35
36 // Global offset instead of address for an oop within a java object.
37 enum class narrowOop : uint32_t { null = 0 };
38
39 typedef void* OopOrNarrowOopStar;
40
41 #ifndef CHECK_UNHANDLED_OOPS
42
43 typedef class oopDesc* oop;
44 typedef class instanceOopDesc* instanceOop;
45 typedef class inlineOopDesc* inlineOop;
46 typedef class stackChunkOopDesc* stackChunkOop;
47 typedef class arrayOopDesc* arrayOop;
48 typedef class objArrayOopDesc* objArrayOop;
49 typedef class flatArrayOopDesc* flatArrayOop;
50 typedef class refArrayOopDesc* refArrayOop;
51 typedef class typeArrayOopDesc* typeArrayOop;
52
53 #else
54
55 // When CHECK_UNHANDLED_OOPS is defined, an "oop" is a class with a
56 // carefully chosen set of constructors and conversion operators to go
57 // to and from the underlying oopDesc pointer type.
58 //
59 // Because oop and its subclasses <type>Oop are class types, arbitrary
60 // conversions are not accepted by the compiler. Applying a cast to
61 // an oop will cause the best matched conversion operator to be
62 // invoked returning the underlying oopDesc* type if appropriate.
63 // No copy constructors, explicit user conversions or operators of
64 // numerical type should be defined within the oop class. Most C++
65 // compilers will issue a compile time error concerning the overloading
66 // ambiguity between operators of numerical and pointer types. If
67 // a conversion to or from an oop to a numerical type is needed,
68 // use the inline template methods, cast_*_oop, defined below.
69 //
70 // Converting null to oop to Handle implicit is no longer accepted by the
136 operator type##OopDesc* () const { return (type##OopDesc*)obj(); } \
137 type##OopDesc* operator->() const { \
138 return (type##OopDesc*)obj(); \
139 } \
140 type##Oop& operator=(const type##Oop& o) { \
141 oop::operator=(o); \
142 return *this; \
143 } \
144 }; \
145 \
146 template<> \
147 struct PrimitiveConversions::Translate<type##Oop> : public std::true_type { \
148 typedef type##Oop Value; \
149 typedef type##OopDesc* Decayed; \
150 \
151 static Decayed decay(Value x) { return (type##OopDesc*)x.obj(); } \
152 static Value recover(Decayed x) { return type##Oop(x); } \
153 };
154
155 DEF_OOP(instance);
156 DEF_OOP(inline);
157 DEF_OOP(stackChunk);
158 DEF_OOP(array);
159 DEF_OOP(objArray);
160 DEF_OOP(typeArray);
161 DEF_OOP(flatArray);
162 DEF_OOP(refArray);
163
164 #endif // CHECK_UNHANDLED_OOPS
165
166 // Cast functions to convert to and from oops.
167 template <typename T> inline oop cast_to_oop(T value) {
168 return (oopDesc*)value;
169 }
170 template <typename T> inline T cast_from_oop(oop o) {
171 return (T)(CHECK_UNHANDLED_OOPS_ONLY((oopDesc*))o);
172 }
173
174 inline intptr_t p2i(narrowOop o) {
175 return static_cast<intptr_t>(o);
176 }
177
178 // The metadata hierarchy is separate from the oop hierarchy
179
180 // class MetaspaceObj
181 class ConstMethod;
182 class ConstantPoolCache;
183 class MethodData;
184 // class Metadata
185 class Method;
186 class ConstantPool;
187
188 // The klass hierarchy is separate from the oop hierarchy.
189
190 class Klass;
191 class InstanceKlass;
192 class InlineKlass;
193 class InstanceMirrorKlass;
194 class InstanceClassLoaderKlass;
195 class InstanceRefKlass;
196 class InstanceStackChunkKlass;
197 class ArrayKlass;
198 class ObjArrayKlass;
199 class FlatArrayKlass;
200 class RefArrayKlass;
201 class TypeArrayKlass;
202
203 #endif // SHARE_OOPS_OOPSHIERARCHY_HPP
|