author | lana |
Wed, 28 Dec 2011 10:51:24 -0800 | |
changeset 11360 | cfa173720adb |
parent 9959 | a6730101c2d0 |
child 13391 | 30245956af37 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
8921
14bfe81f2a9d
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
8076
diff
changeset
|
2 |
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 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 |
||
1 | 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 |
||
3908 | 62 |
enum { FLAG_BITS = 2 }; |
1 | 63 |
enum { |
3908 | 64 |
PERM_FLAG = 1, |
65 |
SCAVENGABLE_FLAG = 2 |
|
1 | 66 |
}; |
67 |
protected: |
|
68 |
ciObject(); |
|
69 |
ciObject(oop o); |
|
70 |
ciObject(Handle h); |
|
71 |
ciObject(ciKlass* klass); |
|
72 |
||
73 |
jobject handle() const { return _handle; } |
|
74 |
// Get the VM oop that this object holds. |
|
75 |
oop get_oop() const { |
|
76 |
assert(_handle != NULL, "null oop"); |
|
77 |
return JNIHandles::resolve_non_null(_handle); |
|
78 |
} |
|
79 |
||
3908 | 80 |
void init_flags_from(oop x) { |
81 |
int flags = 0; |
|
82 |
if (x != NULL) { |
|
83 |
if (x->is_perm()) |
|
84 |
flags |= PERM_FLAG; |
|
85 |
if (x->is_scavengable()) |
|
86 |
flags |= SCAVENGABLE_FLAG; |
|
87 |
} |
|
88 |
_ident |= flags; |
|
1 | 89 |
} |
90 |
||
91 |
// Virtual behavior of the print() method. |
|
92 |
virtual void print_impl(outputStream* st) {} |
|
93 |
||
94 |
virtual const char* type_string() { return "ciObject"; } |
|
95 |
||
96 |
void set_ident(uint id); |
|
97 |
public: |
|
98 |
// The klass of this ciObject. |
|
99 |
ciKlass* klass(); |
|
100 |
||
101 |
// A number unique to this object. |
|
102 |
uint ident(); |
|
103 |
||
104 |
// Are two ciObjects equal? |
|
105 |
bool equals(ciObject* obj); |
|
106 |
||
107 |
// A hash value for the convenience of compilers. |
|
108 |
int hash(); |
|
109 |
||
3908 | 110 |
// Tells if this oop has an encoding as a constant. |
9959
a6730101c2d0
7048030: is_scavengable changes causing compiler to embed more constants
kvn
parents:
8921
diff
changeset
|
111 |
// True if is_perm is true. |
3908 | 112 |
// Also true if ScavengeRootsInCode is non-zero. |
1 | 113 |
// If it does not have an encoding, the compiler is responsible for |
114 |
// making other arrangements for dealing with the oop. |
|
3908 | 115 |
// See ciEnv::make_array |
116 |
bool can_be_constant(); |
|
117 |
||
118 |
// Tells if this oop should be made a constant. |
|
9959
a6730101c2d0
7048030: is_scavengable changes causing compiler to embed more constants
kvn
parents:
8921
diff
changeset
|
119 |
// True if is_perm is true or ScavengeRootsInCode > 1. |
3908 | 120 |
bool should_be_constant(); |
1 | 121 |
|
122 |
// Is this object guaranteed to be in the permanent part of the heap? |
|
123 |
// If so, CollectedHeap::can_elide_permanent_oop_store_barriers is relevant. |
|
124 |
// If the answer is false, no guarantees are made. |
|
125 |
bool is_perm() { return (_ident & PERM_FLAG) != 0; } |
|
126 |
||
3908 | 127 |
// Might this object possibly move during a scavenge operation? |
128 |
// If the answer is true and ScavengeRootsInCode==0, the oop cannot be embedded in code. |
|
129 |
bool is_scavengable() { return (_ident & SCAVENGABLE_FLAG) != 0; } |
|
130 |
||
1 | 131 |
// The address which the compiler should embed into the |
132 |
// generated code to represent this oop. This address |
|
133 |
// is not the true address of the oop -- it will get patched |
|
134 |
// during nmethod creation. |
|
135 |
// |
|
136 |
// Usage note: no address arithmetic allowed. Oop must |
|
137 |
// be registered with the oopRecorder. |
|
3908 | 138 |
jobject constant_encoding(); |
1 | 139 |
|
140 |
// What kind of ciObject is this? |
|
141 |
virtual bool is_null_object() const { return false; } |
|
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4566
diff
changeset
|
142 |
virtual bool is_call_site() const { return false; } |
4566
b363f6ef4068
6829187: compiler optimizations required for JSR 292
twisti
parents:
3908
diff
changeset
|
143 |
virtual bool is_cpcache() const { return false; } |
1 | 144 |
virtual bool is_instance() { return false; } |
145 |
virtual bool is_method() { return false; } |
|
146 |
virtual bool is_method_data() { return false; } |
|
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4566
diff
changeset
|
147 |
virtual bool is_method_handle() const { return false; } |
1 | 148 |
virtual bool is_array() { return false; } |
149 |
virtual bool is_obj_array() { return false; } |
|
150 |
virtual bool is_type_array() { return false; } |
|
151 |
virtual bool is_symbol() { return false; } |
|
152 |
virtual bool is_type() { return false; } |
|
153 |
virtual bool is_return_address() { return false; } |
|
154 |
virtual bool is_klass() { return false; } |
|
155 |
virtual bool is_instance_klass() { return false; } |
|
156 |
virtual bool is_method_klass() { return false; } |
|
157 |
virtual bool is_array_klass() { return false; } |
|
158 |
virtual bool is_obj_array_klass() { return false; } |
|
159 |
virtual bool is_type_array_klass() { return false; } |
|
160 |
virtual bool is_symbol_klass() { return false; } |
|
161 |
virtual bool is_klass_klass() { return false; } |
|
162 |
virtual bool is_instance_klass_klass() { return false; } |
|
163 |
virtual bool is_array_klass_klass() { return false; } |
|
164 |
virtual bool is_obj_array_klass_klass() { return false; } |
|
165 |
virtual bool is_type_array_klass_klass() { return false; } |
|
166 |
||
167 |
// Is this a type or value which has no associated class? |
|
168 |
// It is true of primitive types and null objects. |
|
169 |
virtual bool is_classless() const { return false; } |
|
170 |
||
171 |
// Is this ciObject a Java Language Object? That is, |
|
172 |
// is the ciObject an instance or an array |
|
173 |
virtual bool is_java_object() { return false; } |
|
174 |
||
175 |
// Does this ciObject represent a Java Language class? |
|
176 |
// That is, is the ciObject an instanceKlass or arrayKlass? |
|
177 |
virtual bool is_java_klass() { return false; } |
|
178 |
||
179 |
// Is this ciObject the ciInstanceKlass representing |
|
180 |
// java.lang.Object()? |
|
181 |
virtual bool is_java_lang_Object() { return false; } |
|
182 |
||
183 |
// Does this ciObject refer to a real oop in the VM? |
|
184 |
// |
|
185 |
// Note: some ciObjects refer to oops which have yet to be |
|
186 |
// created. We refer to these as "unloaded". Specifically, |
|
187 |
// there are unloaded ciMethods, ciObjArrayKlasses, and |
|
188 |
// ciInstanceKlasses. By convention the ciNullObject is |
|
189 |
// considered loaded, and primitive types are considered loaded. |
|
190 |
bool is_loaded() const { |
|
191 |
return handle() != NULL || is_classless(); |
|
192 |
} |
|
193 |
||
194 |
// Subclass casting with assertions. |
|
195 |
ciNullObject* as_null_object() { |
|
196 |
assert(is_null_object(), "bad cast"); |
|
197 |
return (ciNullObject*)this; |
|
198 |
} |
|
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4566
diff
changeset
|
199 |
ciCallSite* as_call_site() { |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4566
diff
changeset
|
200 |
assert(is_call_site(), "bad cast"); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4566
diff
changeset
|
201 |
return (ciCallSite*) this; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4566
diff
changeset
|
202 |
} |
4566
b363f6ef4068
6829187: compiler optimizations required for JSR 292
twisti
parents:
3908
diff
changeset
|
203 |
ciCPCache* as_cpcache() { |
b363f6ef4068
6829187: compiler optimizations required for JSR 292
twisti
parents:
3908
diff
changeset
|
204 |
assert(is_cpcache(), "bad cast"); |
b363f6ef4068
6829187: compiler optimizations required for JSR 292
twisti
parents:
3908
diff
changeset
|
205 |
return (ciCPCache*) this; |
b363f6ef4068
6829187: compiler optimizations required for JSR 292
twisti
parents:
3908
diff
changeset
|
206 |
} |
1 | 207 |
ciInstance* as_instance() { |
208 |
assert(is_instance(), "bad cast"); |
|
209 |
return (ciInstance*)this; |
|
210 |
} |
|
211 |
ciMethod* as_method() { |
|
212 |
assert(is_method(), "bad cast"); |
|
213 |
return (ciMethod*)this; |
|
214 |
} |
|
215 |
ciMethodData* as_method_data() { |
|
216 |
assert(is_method_data(), "bad cast"); |
|
217 |
return (ciMethodData*)this; |
|
218 |
} |
|
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4566
diff
changeset
|
219 |
ciMethodHandle* as_method_handle() { |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4566
diff
changeset
|
220 |
assert(is_method_handle(), "bad cast"); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4566
diff
changeset
|
221 |
return (ciMethodHandle*) this; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4566
diff
changeset
|
222 |
} |
1 | 223 |
ciArray* as_array() { |
224 |
assert(is_array(), "bad cast"); |
|
225 |
return (ciArray*)this; |
|
226 |
} |
|
227 |
ciObjArray* as_obj_array() { |
|
228 |
assert(is_obj_array(), "bad cast"); |
|
229 |
return (ciObjArray*)this; |
|
230 |
} |
|
231 |
ciTypeArray* as_type_array() { |
|
232 |
assert(is_type_array(), "bad cast"); |
|
233 |
return (ciTypeArray*)this; |
|
234 |
} |
|
235 |
ciSymbol* as_symbol() { |
|
236 |
assert(is_symbol(), "bad cast"); |
|
237 |
return (ciSymbol*)this; |
|
238 |
} |
|
239 |
ciType* as_type() { |
|
240 |
assert(is_type(), "bad cast"); |
|
241 |
return (ciType*)this; |
|
242 |
} |
|
243 |
ciReturnAddress* as_return_address() { |
|
244 |
assert(is_return_address(), "bad cast"); |
|
245 |
return (ciReturnAddress*)this; |
|
246 |
} |
|
247 |
ciKlass* as_klass() { |
|
248 |
assert(is_klass(), "bad cast"); |
|
249 |
return (ciKlass*)this; |
|
250 |
} |
|
251 |
ciInstanceKlass* as_instance_klass() { |
|
252 |
assert(is_instance_klass(), "bad cast"); |
|
253 |
return (ciInstanceKlass*)this; |
|
254 |
} |
|
255 |
ciMethodKlass* as_method_klass() { |
|
256 |
assert(is_method_klass(), "bad cast"); |
|
257 |
return (ciMethodKlass*)this; |
|
258 |
} |
|
259 |
ciArrayKlass* as_array_klass() { |
|
260 |
assert(is_array_klass(), "bad cast"); |
|
261 |
return (ciArrayKlass*)this; |
|
262 |
} |
|
263 |
ciObjArrayKlass* as_obj_array_klass() { |
|
264 |
assert(is_obj_array_klass(), "bad cast"); |
|
265 |
return (ciObjArrayKlass*)this; |
|
266 |
} |
|
267 |
ciTypeArrayKlass* as_type_array_klass() { |
|
268 |
assert(is_type_array_klass(), "bad cast"); |
|
269 |
return (ciTypeArrayKlass*)this; |
|
270 |
} |
|
271 |
ciKlassKlass* as_klass_klass() { |
|
272 |
assert(is_klass_klass(), "bad cast"); |
|
273 |
return (ciKlassKlass*)this; |
|
274 |
} |
|
275 |
ciInstanceKlassKlass* as_instance_klass_klass() { |
|
276 |
assert(is_instance_klass_klass(), "bad cast"); |
|
277 |
return (ciInstanceKlassKlass*)this; |
|
278 |
} |
|
279 |
ciArrayKlassKlass* as_array_klass_klass() { |
|
280 |
assert(is_array_klass_klass(), "bad cast"); |
|
281 |
return (ciArrayKlassKlass*)this; |
|
282 |
} |
|
283 |
ciObjArrayKlassKlass* as_obj_array_klass_klass() { |
|
284 |
assert(is_obj_array_klass_klass(), "bad cast"); |
|
285 |
return (ciObjArrayKlassKlass*)this; |
|
286 |
} |
|
287 |
ciTypeArrayKlassKlass* as_type_array_klass_klass() { |
|
288 |
assert(is_type_array_klass_klass(), "bad cast"); |
|
289 |
return (ciTypeArrayKlassKlass*)this; |
|
290 |
} |
|
291 |
||
292 |
// Print debugging output about this ciObject. |
|
293 |
void print(outputStream* st = tty); |
|
294 |
||
295 |
// Print debugging output about the oop this ciObject represents. |
|
296 |
void print_oop(outputStream* st = tty); |
|
297 |
}; |
|
7397 | 298 |
|
299 |
#endif // SHARE_VM_CI_CIOBJECT_HPP |