Mercurial > hg > truffle
annotate src/share/vm/ci/ciObject.hpp @ 4530:6c6cb7be1324
bugfix
author | Christian Haeubl <christian.haeubl@oracle.com> |
---|---|
date | Wed, 08 Feb 2012 21:13:35 -0800 |
parents | 46f211fe010c |
children | 957c266d8bc5 |
rev | line source |
---|---|
0 | 1 /* |
2426
1d1603768966
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
2177
diff
changeset
|
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_CI_CIOBJECT_HPP |
26 #define SHARE_VM_CI_CIOBJECT_HPP | |
27 | |
28 #include "ci/ciClassList.hpp" | |
29 #include "memory/allocation.hpp" | |
30 #include "runtime/handles.hpp" | |
31 #include "runtime/jniHandles.hpp" | |
32 | |
0 | 33 // ciObject |
34 // | |
35 // This class represents an oop in the HotSpot virtual machine. | |
36 // Its subclasses are structured in a hierarchy which mirrors | |
37 // an aggregate of the VM's oop and klass hierarchies (see | |
38 // oopHierarchy.hpp). Each instance of ciObject holds a handle | |
39 // to a corresponding oop on the VM side and provides routines | |
40 // for accessing the information in its oop. By using the ciObject | |
41 // hierarchy for accessing oops in the VM, the compiler ensures | |
42 // that it is safe with respect to garbage collection; that is, | |
43 // GC and compilation can proceed independently without | |
44 // interference. | |
45 // | |
46 // Within the VM, the oop and klass hierarchies are separate. | |
47 // The compiler interface does not preserve this separation -- | |
48 // the distinction between `klassOop' and `Klass' are not | |
49 // reflected in the interface and instead the Klass hierarchy | |
50 // is directly modeled as the subclasses of ciKlass. | |
51 class ciObject : public ResourceObj { | |
52 CI_PACKAGE_ACCESS | |
53 friend class ciEnv; | |
54 | |
55 private: | |
56 // A JNI handle referring to an oop in the VM. This | |
57 // handle may, in a small set of cases, correctly be NULL. | |
58 jobject _handle; | |
59 ciKlass* _klass; | |
60 uint _ident; | |
61 | |
989 | 62 enum { FLAG_BITS = 2 }; |
0 | 63 enum { |
989 | 64 PERM_FLAG = 1, |
65 SCAVENGABLE_FLAG = 2 | |
0 | 66 }; |
67 protected: | |
68 ciObject(); | |
69 ciObject(oop o); | |
70 ciObject(Handle h); | |
71 ciObject(ciKlass* klass); | |
72 | |
1406
35069ca331f2
Hooked C1XCompiler class into the system.
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1138
diff
changeset
|
73 public: |
0 | 74 jobject handle() const { return _handle; } |
75 // Get the VM oop that this object holds. | |
76 oop get_oop() const { | |
77 assert(_handle != NULL, "null oop"); | |
78 return JNIHandles::resolve_non_null(_handle); | |
79 } | |
1406
35069ca331f2
Hooked C1XCompiler class into the system.
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1138
diff
changeset
|
80 protected: |
0 | 81 |
989 | 82 void init_flags_from(oop x) { |
83 int flags = 0; | |
84 if (x != NULL) { | |
85 if (x->is_perm()) | |
86 flags |= PERM_FLAG; | |
87 if (x->is_scavengable()) | |
88 flags |= SCAVENGABLE_FLAG; | |
89 } | |
90 _ident |= flags; | |
0 | 91 } |
92 | |
93 // Virtual behavior of the print() method. | |
94 virtual void print_impl(outputStream* st) {} | |
95 | |
96 virtual const char* type_string() { return "ciObject"; } | |
97 | |
98 void set_ident(uint id); | |
99 public: | |
100 // The klass of this ciObject. | |
101 ciKlass* klass(); | |
102 | |
103 // A number unique to this object. | |
104 uint ident(); | |
105 | |
106 // Are two ciObjects equal? | |
107 bool equals(ciObject* obj); | |
108 | |
109 // A hash value for the convenience of compilers. | |
110 int hash(); | |
111 | |
989 | 112 // Tells if this oop has an encoding as a constant. |
3402
28a9fe9534ea
7048030: is_scavengable changes causing compiler to embed more constants
kvn
parents:
2426
diff
changeset
|
113 // True if is_perm is true. |
989 | 114 // Also true if ScavengeRootsInCode is non-zero. |
0 | 115 // If it does not have an encoding, the compiler is responsible for |
116 // making other arrangements for dealing with the oop. | |
989 | 117 // See ciEnv::make_array |
118 bool can_be_constant(); | |
119 | |
120 // Tells if this oop should be made a constant. | |
3402
28a9fe9534ea
7048030: is_scavengable changes causing compiler to embed more constants
kvn
parents:
2426
diff
changeset
|
121 // True if is_perm is true or ScavengeRootsInCode > 1. |
989 | 122 bool should_be_constant(); |
0 | 123 |
124 // Is this object guaranteed to be in the permanent part of the heap? | |
125 // If so, CollectedHeap::can_elide_permanent_oop_store_barriers is relevant. | |
126 // If the answer is false, no guarantees are made. | |
127 bool is_perm() { return (_ident & PERM_FLAG) != 0; } | |
128 | |
989 | 129 // Might this object possibly move during a scavenge operation? |
130 // If the answer is true and ScavengeRootsInCode==0, the oop cannot be embedded in code. | |
131 bool is_scavengable() { return (_ident & SCAVENGABLE_FLAG) != 0; } | |
132 | |
0 | 133 // The address which the compiler should embed into the |
134 // generated code to represent this oop. This address | |
135 // is not the true address of the oop -- it will get patched | |
136 // during nmethod creation. | |
137 // | |
138 // Usage note: no address arithmetic allowed. Oop must | |
139 // be registered with the oopRecorder. | |
989 | 140 jobject constant_encoding(); |
0 | 141 |
142 // What kind of ciObject is this? | |
143 virtual bool is_null_object() const { return false; } | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
144 virtual bool is_call_site() const { return false; } |
1137
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
989
diff
changeset
|
145 virtual bool is_cpcache() const { return false; } |
0 | 146 virtual bool is_instance() { return false; } |
147 virtual bool is_method() { return false; } | |
148 virtual bool is_method_data() { return false; } | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
149 virtual bool is_method_handle() const { return false; } |
0 | 150 virtual bool is_array() { return false; } |
151 virtual bool is_obj_array() { return false; } | |
152 virtual bool is_type_array() { return false; } | |
153 virtual bool is_symbol() { return false; } | |
154 virtual bool is_type() { return false; } | |
155 virtual bool is_return_address() { return false; } | |
156 virtual bool is_klass() { return false; } | |
157 virtual bool is_instance_klass() { return false; } | |
158 virtual bool is_method_klass() { return false; } | |
159 virtual bool is_array_klass() { return false; } | |
160 virtual bool is_obj_array_klass() { return false; } | |
161 virtual bool is_type_array_klass() { return false; } | |
162 virtual bool is_symbol_klass() { return false; } | |
163 virtual bool is_klass_klass() { return false; } | |
164 virtual bool is_instance_klass_klass() { return false; } | |
165 virtual bool is_array_klass_klass() { return false; } | |
166 virtual bool is_obj_array_klass_klass() { return false; } | |
167 virtual bool is_type_array_klass_klass() { return false; } | |
168 | |
169 // Is this a type or value which has no associated class? | |
170 // It is true of primitive types and null objects. | |
171 virtual bool is_classless() const { return false; } | |
172 | |
173 // Is this ciObject a Java Language Object? That is, | |
174 // is the ciObject an instance or an array | |
175 virtual bool is_java_object() { return false; } | |
176 | |
177 // Does this ciObject represent a Java Language class? | |
178 // That is, is the ciObject an instanceKlass or arrayKlass? | |
179 virtual bool is_java_klass() { return false; } | |
180 | |
181 // Is this ciObject the ciInstanceKlass representing | |
182 // java.lang.Object()? | |
183 virtual bool is_java_lang_Object() { return false; } | |
184 | |
185 // Does this ciObject refer to a real oop in the VM? | |
186 // | |
187 // Note: some ciObjects refer to oops which have yet to be | |
188 // created. We refer to these as "unloaded". Specifically, | |
189 // there are unloaded ciMethods, ciObjArrayKlasses, and | |
190 // ciInstanceKlasses. By convention the ciNullObject is | |
191 // considered loaded, and primitive types are considered loaded. | |
192 bool is_loaded() const { | |
193 return handle() != NULL || is_classless(); | |
194 } | |
195 | |
196 // Subclass casting with assertions. | |
197 ciNullObject* as_null_object() { | |
198 assert(is_null_object(), "bad cast"); | |
199 return (ciNullObject*)this; | |
200 } | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
201 ciCallSite* as_call_site() { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
202 assert(is_call_site(), "bad cast"); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
203 return (ciCallSite*) this; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
204 } |
1137
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
989
diff
changeset
|
205 ciCPCache* as_cpcache() { |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
989
diff
changeset
|
206 assert(is_cpcache(), "bad cast"); |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
989
diff
changeset
|
207 return (ciCPCache*) this; |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
989
diff
changeset
|
208 } |
0 | 209 ciInstance* as_instance() { |
210 assert(is_instance(), "bad cast"); | |
211 return (ciInstance*)this; | |
212 } | |
213 ciMethod* as_method() { | |
214 assert(is_method(), "bad cast"); | |
215 return (ciMethod*)this; | |
216 } | |
217 ciMethodData* as_method_data() { | |
218 assert(is_method_data(), "bad cast"); | |
219 return (ciMethodData*)this; | |
220 } | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
221 ciMethodHandle* as_method_handle() { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
222 assert(is_method_handle(), "bad cast"); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
223 return (ciMethodHandle*) this; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
224 } |
0 | 225 ciArray* as_array() { |
226 assert(is_array(), "bad cast"); | |
227 return (ciArray*)this; | |
228 } | |
229 ciObjArray* as_obj_array() { | |
230 assert(is_obj_array(), "bad cast"); | |
231 return (ciObjArray*)this; | |
232 } | |
233 ciTypeArray* as_type_array() { | |
234 assert(is_type_array(), "bad cast"); | |
235 return (ciTypeArray*)this; | |
236 } | |
237 ciSymbol* as_symbol() { | |
238 assert(is_symbol(), "bad cast"); | |
239 return (ciSymbol*)this; | |
240 } | |
241 ciType* as_type() { | |
242 assert(is_type(), "bad cast"); | |
243 return (ciType*)this; | |
244 } | |
245 ciReturnAddress* as_return_address() { | |
246 assert(is_return_address(), "bad cast"); | |
247 return (ciReturnAddress*)this; | |
248 } | |
249 ciKlass* as_klass() { | |
250 assert(is_klass(), "bad cast"); | |
251 return (ciKlass*)this; | |
252 } | |
253 ciInstanceKlass* as_instance_klass() { | |
254 assert(is_instance_klass(), "bad cast"); | |
255 return (ciInstanceKlass*)this; | |
256 } | |
257 ciMethodKlass* as_method_klass() { | |
258 assert(is_method_klass(), "bad cast"); | |
259 return (ciMethodKlass*)this; | |
260 } | |
261 ciArrayKlass* as_array_klass() { | |
262 assert(is_array_klass(), "bad cast"); | |
263 return (ciArrayKlass*)this; | |
264 } | |
265 ciObjArrayKlass* as_obj_array_klass() { | |
266 assert(is_obj_array_klass(), "bad cast"); | |
267 return (ciObjArrayKlass*)this; | |
268 } | |
269 ciTypeArrayKlass* as_type_array_klass() { | |
270 assert(is_type_array_klass(), "bad cast"); | |
271 return (ciTypeArrayKlass*)this; | |
272 } | |
273 ciKlassKlass* as_klass_klass() { | |
274 assert(is_klass_klass(), "bad cast"); | |
275 return (ciKlassKlass*)this; | |
276 } | |
277 ciInstanceKlassKlass* as_instance_klass_klass() { | |
278 assert(is_instance_klass_klass(), "bad cast"); | |
279 return (ciInstanceKlassKlass*)this; | |
280 } | |
281 ciArrayKlassKlass* as_array_klass_klass() { | |
282 assert(is_array_klass_klass(), "bad cast"); | |
283 return (ciArrayKlassKlass*)this; | |
284 } | |
285 ciObjArrayKlassKlass* as_obj_array_klass_klass() { | |
286 assert(is_obj_array_klass_klass(), "bad cast"); | |
287 return (ciObjArrayKlassKlass*)this; | |
288 } | |
289 ciTypeArrayKlassKlass* as_type_array_klass_klass() { | |
290 assert(is_type_array_klass_klass(), "bad cast"); | |
291 return (ciTypeArrayKlassKlass*)this; | |
292 } | |
293 | |
294 // Print debugging output about this ciObject. | |
295 void print(outputStream* st = tty); | |
296 | |
297 // Print debugging output about the oop this ciObject represents. | |
298 void print_oop(outputStream* st = tty); | |
299 }; | |
1972 | 300 |
301 #endif // SHARE_VM_CI_CIOBJECT_HPP |