Mercurial > hg > graal-compiler
annotate src/share/vm/ci/ciObject.hpp @ 1412:9195b99c841b
Added first VM entry method.
TODO: Check why initialization method of compiler is not called. Register native methods only once.
author | Thomas Wuerthinger <thomas.wuerthinger@gmail.com> |
---|---|
date | Mon, 17 May 2010 16:37:23 +0200 |
parents | 35069ca331f2 |
children | 5571b97fc1ec |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved. | |
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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 // ciObject | |
26 // | |
27 // This class represents an oop in the HotSpot virtual machine. | |
28 // Its subclasses are structured in a hierarchy which mirrors | |
29 // an aggregate of the VM's oop and klass hierarchies (see | |
30 // oopHierarchy.hpp). Each instance of ciObject holds a handle | |
31 // to a corresponding oop on the VM side and provides routines | |
32 // for accessing the information in its oop. By using the ciObject | |
33 // hierarchy for accessing oops in the VM, the compiler ensures | |
34 // that it is safe with respect to garbage collection; that is, | |
35 // GC and compilation can proceed independently without | |
36 // interference. | |
37 // | |
38 // Within the VM, the oop and klass hierarchies are separate. | |
39 // The compiler interface does not preserve this separation -- | |
40 // the distinction between `klassOop' and `Klass' are not | |
41 // reflected in the interface and instead the Klass hierarchy | |
42 // is directly modeled as the subclasses of ciKlass. | |
43 class ciObject : public ResourceObj { | |
44 CI_PACKAGE_ACCESS | |
45 friend class ciEnv; | |
46 | |
47 private: | |
48 // A JNI handle referring to an oop in the VM. This | |
49 // handle may, in a small set of cases, correctly be NULL. | |
50 jobject _handle; | |
51 ciKlass* _klass; | |
52 uint _ident; | |
53 | |
989 | 54 enum { FLAG_BITS = 2 }; |
0 | 55 enum { |
989 | 56 PERM_FLAG = 1, |
57 SCAVENGABLE_FLAG = 2 | |
0 | 58 }; |
59 protected: | |
60 ciObject(); | |
61 ciObject(oop o); | |
62 ciObject(Handle h); | |
63 ciObject(ciKlass* klass); | |
64 | |
1406
35069ca331f2
Hooked C1XCompiler class into the system.
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1138
diff
changeset
|
65 public: |
0 | 66 jobject handle() const { return _handle; } |
67 // Get the VM oop that this object holds. | |
68 oop get_oop() const { | |
69 assert(_handle != NULL, "null oop"); | |
70 return JNIHandles::resolve_non_null(_handle); | |
71 } | |
1406
35069ca331f2
Hooked C1XCompiler class into the system.
Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
parents:
1138
diff
changeset
|
72 protected: |
0 | 73 |
989 | 74 void init_flags_from(oop x) { |
75 int flags = 0; | |
76 if (x != NULL) { | |
77 if (x->is_perm()) | |
78 flags |= PERM_FLAG; | |
79 if (x->is_scavengable()) | |
80 flags |= SCAVENGABLE_FLAG; | |
81 } | |
82 _ident |= flags; | |
0 | 83 } |
84 | |
85 // Virtual behavior of the print() method. | |
86 virtual void print_impl(outputStream* st) {} | |
87 | |
88 virtual const char* type_string() { return "ciObject"; } | |
89 | |
90 void set_ident(uint id); | |
91 public: | |
92 // The klass of this ciObject. | |
93 ciKlass* klass(); | |
94 | |
95 // A number unique to this object. | |
96 uint ident(); | |
97 | |
98 // Are two ciObjects equal? | |
99 bool equals(ciObject* obj); | |
100 | |
101 // A hash value for the convenience of compilers. | |
102 int hash(); | |
103 | |
989 | 104 // Tells if this oop has an encoding as a constant. |
105 // True if is_scavengable is false. | |
106 // Also true if ScavengeRootsInCode is non-zero. | |
0 | 107 // If it does not have an encoding, the compiler is responsible for |
108 // making other arrangements for dealing with the oop. | |
989 | 109 // See ciEnv::make_array |
110 bool can_be_constant(); | |
111 | |
112 // Tells if this oop should be made a constant. | |
113 // True if is_scavengable is false or ScavengeRootsInCode > 1. | |
114 bool should_be_constant(); | |
0 | 115 |
116 // Is this object guaranteed to be in the permanent part of the heap? | |
117 // If so, CollectedHeap::can_elide_permanent_oop_store_barriers is relevant. | |
118 // If the answer is false, no guarantees are made. | |
119 bool is_perm() { return (_ident & PERM_FLAG) != 0; } | |
120 | |
989 | 121 // Might this object possibly move during a scavenge operation? |
122 // If the answer is true and ScavengeRootsInCode==0, the oop cannot be embedded in code. | |
123 bool is_scavengable() { return (_ident & SCAVENGABLE_FLAG) != 0; } | |
124 | |
0 | 125 // The address which the compiler should embed into the |
126 // generated code to represent this oop. This address | |
127 // is not the true address of the oop -- it will get patched | |
128 // during nmethod creation. | |
129 // | |
130 // Usage note: no address arithmetic allowed. Oop must | |
131 // be registered with the oopRecorder. | |
989 | 132 jobject constant_encoding(); |
0 | 133 |
134 // What kind of ciObject is this? | |
135 virtual bool is_null_object() const { return false; } | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
136 virtual bool is_call_site() const { return false; } |
1137
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
989
diff
changeset
|
137 virtual bool is_cpcache() const { return false; } |
0 | 138 virtual bool is_instance() { return false; } |
139 virtual bool is_method() { return false; } | |
140 virtual bool is_method_data() { return false; } | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
141 virtual bool is_method_handle() const { return false; } |
0 | 142 virtual bool is_array() { return false; } |
143 virtual bool is_obj_array() { return false; } | |
144 virtual bool is_type_array() { return false; } | |
145 virtual bool is_symbol() { return false; } | |
146 virtual bool is_type() { return false; } | |
147 virtual bool is_return_address() { return false; } | |
148 virtual bool is_klass() { return false; } | |
149 virtual bool is_instance_klass() { return false; } | |
150 virtual bool is_method_klass() { return false; } | |
151 virtual bool is_array_klass() { return false; } | |
152 virtual bool is_obj_array_klass() { return false; } | |
153 virtual bool is_type_array_klass() { return false; } | |
154 virtual bool is_symbol_klass() { return false; } | |
155 virtual bool is_klass_klass() { return false; } | |
156 virtual bool is_instance_klass_klass() { return false; } | |
157 virtual bool is_array_klass_klass() { return false; } | |
158 virtual bool is_obj_array_klass_klass() { return false; } | |
159 virtual bool is_type_array_klass_klass() { return false; } | |
160 | |
161 // Is this a type or value which has no associated class? | |
162 // It is true of primitive types and null objects. | |
163 virtual bool is_classless() const { return false; } | |
164 | |
165 // Is this ciObject a Java Language Object? That is, | |
166 // is the ciObject an instance or an array | |
167 virtual bool is_java_object() { return false; } | |
168 | |
169 // Does this ciObject represent a Java Language class? | |
170 // That is, is the ciObject an instanceKlass or arrayKlass? | |
171 virtual bool is_java_klass() { return false; } | |
172 | |
173 // Is this ciObject the ciInstanceKlass representing | |
174 // java.lang.Object()? | |
175 virtual bool is_java_lang_Object() { return false; } | |
176 | |
177 // Does this ciObject refer to a real oop in the VM? | |
178 // | |
179 // Note: some ciObjects refer to oops which have yet to be | |
180 // created. We refer to these as "unloaded". Specifically, | |
181 // there are unloaded ciMethods, ciObjArrayKlasses, and | |
182 // ciInstanceKlasses. By convention the ciNullObject is | |
183 // considered loaded, and primitive types are considered loaded. | |
184 bool is_loaded() const { | |
185 return handle() != NULL || is_classless(); | |
186 } | |
187 | |
188 // Subclass casting with assertions. | |
189 ciNullObject* as_null_object() { | |
190 assert(is_null_object(), "bad cast"); | |
191 return (ciNullObject*)this; | |
192 } | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
193 ciCallSite* as_call_site() { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
194 assert(is_call_site(), "bad cast"); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
195 return (ciCallSite*) this; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
196 } |
1137
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
989
diff
changeset
|
197 ciCPCache* as_cpcache() { |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
989
diff
changeset
|
198 assert(is_cpcache(), "bad cast"); |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
989
diff
changeset
|
199 return (ciCPCache*) this; |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
989
diff
changeset
|
200 } |
0 | 201 ciInstance* as_instance() { |
202 assert(is_instance(), "bad cast"); | |
203 return (ciInstance*)this; | |
204 } | |
205 ciMethod* as_method() { | |
206 assert(is_method(), "bad cast"); | |
207 return (ciMethod*)this; | |
208 } | |
209 ciMethodData* as_method_data() { | |
210 assert(is_method_data(), "bad cast"); | |
211 return (ciMethodData*)this; | |
212 } | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
213 ciMethodHandle* as_method_handle() { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
214 assert(is_method_handle(), "bad cast"); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
215 return (ciMethodHandle*) this; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
216 } |
0 | 217 ciArray* as_array() { |
218 assert(is_array(), "bad cast"); | |
219 return (ciArray*)this; | |
220 } | |
221 ciObjArray* as_obj_array() { | |
222 assert(is_obj_array(), "bad cast"); | |
223 return (ciObjArray*)this; | |
224 } | |
225 ciTypeArray* as_type_array() { | |
226 assert(is_type_array(), "bad cast"); | |
227 return (ciTypeArray*)this; | |
228 } | |
229 ciSymbol* as_symbol() { | |
230 assert(is_symbol(), "bad cast"); | |
231 return (ciSymbol*)this; | |
232 } | |
233 ciType* as_type() { | |
234 assert(is_type(), "bad cast"); | |
235 return (ciType*)this; | |
236 } | |
237 ciReturnAddress* as_return_address() { | |
238 assert(is_return_address(), "bad cast"); | |
239 return (ciReturnAddress*)this; | |
240 } | |
241 ciKlass* as_klass() { | |
242 assert(is_klass(), "bad cast"); | |
243 return (ciKlass*)this; | |
244 } | |
245 ciInstanceKlass* as_instance_klass() { | |
246 assert(is_instance_klass(), "bad cast"); | |
247 return (ciInstanceKlass*)this; | |
248 } | |
249 ciMethodKlass* as_method_klass() { | |
250 assert(is_method_klass(), "bad cast"); | |
251 return (ciMethodKlass*)this; | |
252 } | |
253 ciArrayKlass* as_array_klass() { | |
254 assert(is_array_klass(), "bad cast"); | |
255 return (ciArrayKlass*)this; | |
256 } | |
257 ciObjArrayKlass* as_obj_array_klass() { | |
258 assert(is_obj_array_klass(), "bad cast"); | |
259 return (ciObjArrayKlass*)this; | |
260 } | |
261 ciTypeArrayKlass* as_type_array_klass() { | |
262 assert(is_type_array_klass(), "bad cast"); | |
263 return (ciTypeArrayKlass*)this; | |
264 } | |
265 ciSymbolKlass* as_symbol_klass() { | |
266 assert(is_symbol_klass(), "bad cast"); | |
267 return (ciSymbolKlass*)this; | |
268 } | |
269 ciKlassKlass* as_klass_klass() { | |
270 assert(is_klass_klass(), "bad cast"); | |
271 return (ciKlassKlass*)this; | |
272 } | |
273 ciInstanceKlassKlass* as_instance_klass_klass() { | |
274 assert(is_instance_klass_klass(), "bad cast"); | |
275 return (ciInstanceKlassKlass*)this; | |
276 } | |
277 ciArrayKlassKlass* as_array_klass_klass() { | |
278 assert(is_array_klass_klass(), "bad cast"); | |
279 return (ciArrayKlassKlass*)this; | |
280 } | |
281 ciObjArrayKlassKlass* as_obj_array_klass_klass() { | |
282 assert(is_obj_array_klass_klass(), "bad cast"); | |
283 return (ciObjArrayKlassKlass*)this; | |
284 } | |
285 ciTypeArrayKlassKlass* as_type_array_klass_klass() { | |
286 assert(is_type_array_klass_klass(), "bad cast"); | |
287 return (ciTypeArrayKlassKlass*)this; | |
288 } | |
289 | |
290 // Print debugging output about this ciObject. | |
291 void print(outputStream* st = tty); | |
292 | |
293 // Print debugging output about the oop this ciObject represents. | |
294 void print_oop(outputStream* st = tty); | |
295 }; |