Mercurial > hg > truffle
annotate src/share/vm/ci/ciObjectFactory.cpp @ 2047:eb575e79136f
Fixed an issue that caused the client compiler to fail in the graal configuration.
author | Thomas Wuerthinger <wuerthinger@ssw.jku.at> |
---|---|
date | Fri, 07 Jan 2011 19:08:13 +0100 |
parents | 06f017f7daa7 |
children | d25d4ca69222 |
rev | line source |
---|---|
0 | 1 /* |
1972 | 2 * Copyright (c) 1999, 2010, 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:
1507
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1507
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:
1507
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "ci/ciCPCache.hpp" | |
27 #include "ci/ciCallSite.hpp" | |
28 #include "ci/ciInstance.hpp" | |
29 #include "ci/ciInstanceKlass.hpp" | |
30 #include "ci/ciInstanceKlassKlass.hpp" | |
31 #include "ci/ciMethod.hpp" | |
32 #include "ci/ciMethodData.hpp" | |
33 #include "ci/ciMethodHandle.hpp" | |
34 #include "ci/ciMethodKlass.hpp" | |
35 #include "ci/ciNullObject.hpp" | |
36 #include "ci/ciObjArray.hpp" | |
37 #include "ci/ciObjArrayKlass.hpp" | |
38 #include "ci/ciObjArrayKlassKlass.hpp" | |
39 #include "ci/ciObjectFactory.hpp" | |
40 #include "ci/ciSymbol.hpp" | |
41 #include "ci/ciSymbolKlass.hpp" | |
42 #include "ci/ciTypeArray.hpp" | |
43 #include "ci/ciTypeArrayKlass.hpp" | |
44 #include "ci/ciTypeArrayKlassKlass.hpp" | |
45 #include "ci/ciUtilities.hpp" | |
46 #include "classfile/systemDictionary.hpp" | |
47 #include "gc_interface/collectedHeap.inline.hpp" | |
48 #include "memory/allocation.inline.hpp" | |
49 #include "oops/oop.inline.hpp" | |
50 #include "oops/oop.inline2.hpp" | |
51 #include "runtime/fieldType.hpp" | |
0 | 52 |
53 // ciObjectFactory | |
54 // | |
55 // This class handles requests for the creation of new instances | |
56 // of ciObject and its subclasses. It contains a caching mechanism | |
57 // which ensures that for each oop, at most one ciObject is created. | |
58 // This invariant allows more efficient implementation of ciObject. | |
59 // | |
60 // Implementation note: the oop->ciObject mapping is represented as | |
61 // a table stored in an array. Even though objects are moved | |
62 // by the garbage collector, the compactor preserves their relative | |
63 // order; address comparison of oops (in perm space) is safe so long | |
64 // as we prohibit GC during our comparisons. We currently use binary | |
65 // search to find the oop in the table, and inserting a new oop | |
66 // into the table may be costly. If this cost ends up being | |
67 // problematic the underlying data structure can be switched to some | |
68 // sort of balanced binary tree. | |
69 | |
70 GrowableArray<ciObject*>* ciObjectFactory::_shared_ci_objects = NULL; | |
71 ciSymbol* ciObjectFactory::_shared_ci_symbols[vmSymbols::SID_LIMIT]; | |
72 int ciObjectFactory::_shared_ident_limit = 0; | |
73 volatile bool ciObjectFactory::_initialized = false; | |
74 | |
75 | |
76 // ------------------------------------------------------------------ | |
77 // ciObjectFactory::ciObjectFactory | |
78 ciObjectFactory::ciObjectFactory(Arena* arena, | |
79 int expected_size) { | |
80 | |
81 for (int i = 0; i < NON_PERM_BUCKETS; i++) { | |
82 _non_perm_bucket[i] = NULL; | |
83 } | |
84 _non_perm_count = 0; | |
85 | |
86 _next_ident = _shared_ident_limit; | |
87 _arena = arena; | |
88 _ci_objects = new (arena) GrowableArray<ciObject*>(arena, expected_size, 0, NULL); | |
89 | |
90 // If the shared ci objects exist append them to this factory's objects | |
91 | |
92 if (_shared_ci_objects != NULL) { | |
93 _ci_objects->appendAll(_shared_ci_objects); | |
94 } | |
95 | |
96 _unloaded_methods = new (arena) GrowableArray<ciMethod*>(arena, 4, 0, NULL); | |
97 _unloaded_klasses = new (arena) GrowableArray<ciKlass*>(arena, 8, 0, NULL); | |
1602 | 98 _unloaded_instances = new (arena) GrowableArray<ciInstance*>(arena, 4, 0, NULL); |
0 | 99 _return_addresses = |
100 new (arena) GrowableArray<ciReturnAddress*>(arena, 8, 0, NULL); | |
101 } | |
102 | |
1478
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
103 void ciObjectFactory::cleanup() { |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
104 int start = 0; |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
105 if (_shared_ci_objects != NULL) start = _shared_ci_objects->length(); |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
106 for (int i = start; i < _ci_objects->length(); ++i) { |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
107 _ci_objects->at(i)->cleanup(); |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
108 } |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
109 } |
5571b97fc1ec
More JNI global handle clean ups.
Thomas Wuerthinger <wuerthinger@ssw.jku.at>
parents:
1142
diff
changeset
|
110 |
0 | 111 // ------------------------------------------------------------------ |
112 // ciObjectFactory::ciObjectFactory | |
113 void ciObjectFactory::initialize() { | |
114 ASSERT_IN_VM; | |
115 JavaThread* thread = JavaThread::current(); | |
116 HandleMark handle_mark(thread); | |
117 | |
118 // This Arena is long lived and exists in the resource mark of the | |
119 // compiler thread that initializes the initial ciObjectFactory which | |
120 // creates the shared ciObjects that all later ciObjectFactories use. | |
121 Arena* arena = new Arena(); | |
122 ciEnv initial(arena); | |
123 ciEnv* env = ciEnv::current(); | |
124 env->_factory->init_shared_objects(); | |
125 | |
126 _initialized = true; | |
127 | |
128 } | |
129 | |
130 void ciObjectFactory::init_shared_objects() { | |
131 | |
132 _next_ident = 1; // start numbering CI objects at 1 | |
133 | |
134 { | |
135 // Create the shared symbols, but not in _shared_ci_objects. | |
136 int i; | |
137 for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) { | |
138 symbolHandle sym_handle = vmSymbolHandles::symbol_handle_at((vmSymbols::SID) i); | |
139 assert(vmSymbols::find_sid(sym_handle()) == i, "1-1 mapping"); | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1142
diff
changeset
|
140 ciSymbol* sym = new (_arena) ciSymbol(sym_handle, (vmSymbols::SID) i); |
0 | 141 init_ident_of(sym); |
142 _shared_ci_symbols[i] = sym; | |
143 } | |
144 #ifdef ASSERT | |
145 for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) { | |
146 symbolHandle sym_handle = vmSymbolHandles::symbol_handle_at((vmSymbols::SID) i); | |
147 ciSymbol* sym = vm_symbol_at((vmSymbols::SID) i); | |
148 assert(sym->get_oop() == sym_handle(), "oop must match"); | |
149 } | |
150 assert(ciSymbol::void_class_signature()->get_oop() == vmSymbols::void_class_signature(), "spot check"); | |
151 #endif | |
152 } | |
153 | |
154 _ci_objects = new (_arena) GrowableArray<ciObject*>(_arena, 64, 0, NULL); | |
155 | |
156 for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) { | |
157 BasicType t = (BasicType)i; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
158 if (type2name(t) != NULL && t != T_OBJECT && t != T_ARRAY && t != T_NARROWOOP) { |
0 | 159 ciType::_basic_types[t] = new (_arena) ciType(t); |
160 init_ident_of(ciType::_basic_types[t]); | |
161 } | |
162 } | |
163 | |
164 ciEnv::_null_object_instance = new (_arena) ciNullObject(); | |
165 init_ident_of(ciEnv::_null_object_instance); | |
166 ciEnv::_method_klass_instance = | |
167 get(Universe::methodKlassObj())->as_method_klass(); | |
168 ciEnv::_symbol_klass_instance = | |
169 get(Universe::symbolKlassObj())->as_symbol_klass(); | |
170 ciEnv::_klass_klass_instance = | |
171 get(Universe::klassKlassObj())->as_klass_klass(); | |
172 ciEnv::_instance_klass_klass_instance = | |
173 get(Universe::instanceKlassKlassObj()) | |
174 ->as_instance_klass_klass(); | |
175 ciEnv::_type_array_klass_klass_instance = | |
176 get(Universe::typeArrayKlassKlassObj()) | |
177 ->as_type_array_klass_klass(); | |
178 ciEnv::_obj_array_klass_klass_instance = | |
179 get(Universe::objArrayKlassKlassObj()) | |
180 ->as_obj_array_klass_klass(); | |
1142 | 181 |
182 #define WK_KLASS_DEFN(name, ignore_s, opt) \ | |
183 if (SystemDictionary::name() != NULL) \ | |
184 ciEnv::_##name = get(SystemDictionary::name())->as_instance_klass(); | |
185 | |
186 WK_KLASSES_DO(WK_KLASS_DEFN) | |
187 #undef WK_KLASS_DEFN | |
0 | 188 |
189 for (int len = -1; len != _ci_objects->length(); ) { | |
190 len = _ci_objects->length(); | |
191 for (int i2 = 0; i2 < len; i2++) { | |
192 ciObject* obj = _ci_objects->at(i2); | |
193 if (obj->is_loaded() && obj->is_instance_klass()) { | |
194 obj->as_instance_klass()->compute_nonstatic_fields(); | |
195 } | |
196 } | |
197 } | |
198 | |
199 ciEnv::_unloaded_cisymbol = (ciSymbol*) ciObjectFactory::get(vmSymbols::dummy_symbol_oop()); | |
200 // Create dummy instanceKlass and objArrayKlass object and assign them idents | |
201 ciEnv::_unloaded_ciinstance_klass = new (_arena) ciInstanceKlass(ciEnv::_unloaded_cisymbol, NULL, NULL); | |
202 init_ident_of(ciEnv::_unloaded_ciinstance_klass); | |
203 ciEnv::_unloaded_ciobjarrayklass = new (_arena) ciObjArrayKlass(ciEnv::_unloaded_cisymbol, ciEnv::_unloaded_ciinstance_klass, 1); | |
204 init_ident_of(ciEnv::_unloaded_ciobjarrayklass); | |
205 assert(ciEnv::_unloaded_ciobjarrayklass->is_obj_array_klass(), "just checking"); | |
206 | |
207 get(Universe::boolArrayKlassObj()); | |
208 get(Universe::charArrayKlassObj()); | |
209 get(Universe::singleArrayKlassObj()); | |
210 get(Universe::doubleArrayKlassObj()); | |
211 get(Universe::byteArrayKlassObj()); | |
212 get(Universe::shortArrayKlassObj()); | |
213 get(Universe::intArrayKlassObj()); | |
214 get(Universe::longArrayKlassObj()); | |
215 | |
216 | |
217 | |
218 assert(_non_perm_count == 0, "no shared non-perm objects"); | |
219 | |
220 // The shared_ident_limit is the first ident number that will | |
221 // be used for non-shared objects. That is, numbers less than | |
222 // this limit are permanently assigned to shared CI objects, | |
223 // while the higher numbers are recycled afresh by each new ciEnv. | |
224 | |
225 _shared_ident_limit = _next_ident; | |
226 _shared_ci_objects = _ci_objects; | |
227 } | |
228 | |
229 // ------------------------------------------------------------------ | |
230 // ciObjectFactory::get | |
231 // | |
232 // Get the ciObject corresponding to some oop. If the ciObject has | |
233 // already been created, it is returned. Otherwise, a new ciObject | |
234 // is created. | |
235 ciObject* ciObjectFactory::get(oop key) { | |
236 ASSERT_IN_VM; | |
237 | |
238 #ifdef ASSERT | |
909
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
239 if (CIObjectFactoryVerify) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
240 oop last = NULL; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
241 for (int j = 0; j< _ci_objects->length(); j++) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
242 oop o = _ci_objects->at(j)->get_oop(); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
243 assert(last < o, "out of order"); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
244 last = o; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
245 } |
0 | 246 } |
247 #endif // ASSERT | |
248 int len = _ci_objects->length(); | |
249 int index = find(key, _ci_objects); | |
250 #ifdef ASSERT | |
909
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
251 if (CIObjectFactoryVerify) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
252 for (int i=0; i<_ci_objects->length(); i++) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
253 if (_ci_objects->at(i)->get_oop() == key) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
254 assert(index == i, " bad lookup"); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
255 } |
0 | 256 } |
257 } | |
258 #endif | |
259 if (!is_found_at(index, key, _ci_objects)) { | |
260 // Check in the non-perm area before putting it in the list. | |
261 NonPermObject* &bucket = find_non_perm(key); | |
262 if (bucket != NULL) { | |
263 return bucket->object(); | |
264 } | |
265 | |
266 // Check in the shared symbol area before putting it in the list. | |
267 if (key->is_symbol()) { | |
268 vmSymbols::SID sid = vmSymbols::find_sid((symbolOop)key); | |
269 if (sid != vmSymbols::NO_SID) { | |
270 // do not pollute the main cache with it | |
271 return vm_symbol_at(sid); | |
272 } | |
273 } | |
274 | |
275 // The ciObject does not yet exist. Create it and insert it | |
276 // into the cache. | |
277 Handle keyHandle(key); | |
278 ciObject* new_object = create_new_object(keyHandle()); | |
279 assert(keyHandle() == new_object->get_oop(), "must be properly recorded"); | |
280 init_ident_of(new_object); | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
909
diff
changeset
|
281 if (!new_object->is_perm()) { |
0 | 282 // Not a perm-space object. |
283 insert_non_perm(bucket, keyHandle(), new_object); | |
284 return new_object; | |
285 } | |
286 if (len != _ci_objects->length()) { | |
287 // creating the new object has recursively entered new objects | |
288 // into the table. We need to recompute our index. | |
289 index = find(keyHandle(), _ci_objects); | |
290 } | |
291 assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert"); | |
292 insert(index, new_object, _ci_objects); | |
293 return new_object; | |
294 } | |
295 return _ci_objects->at(index); | |
296 } | |
297 | |
298 // ------------------------------------------------------------------ | |
299 // ciObjectFactory::create_new_object | |
300 // | |
301 // Create a new ciObject from an oop. | |
302 // | |
303 // Implementation note: this functionality could be virtual behavior | |
304 // of the oop itself. For now, we explicitly marshal the object. | |
305 ciObject* ciObjectFactory::create_new_object(oop o) { | |
306 EXCEPTION_CONTEXT; | |
307 | |
308 if (o->is_symbol()) { | |
309 symbolHandle h_o(THREAD, (symbolOop)o); | |
1507
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1142
diff
changeset
|
310 assert(vmSymbols::find_sid(h_o()) == vmSymbols::NO_SID, ""); |
cd5dbf694d45
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
1142
diff
changeset
|
311 return new (arena()) ciSymbol(h_o, vmSymbols::NO_SID); |
0 | 312 } else if (o->is_klass()) { |
313 KlassHandle h_k(THREAD, (klassOop)o); | |
314 Klass* k = ((klassOop)o)->klass_part(); | |
315 if (k->oop_is_instance()) { | |
316 return new (arena()) ciInstanceKlass(h_k); | |
317 } else if (k->oop_is_objArray()) { | |
318 return new (arena()) ciObjArrayKlass(h_k); | |
319 } else if (k->oop_is_typeArray()) { | |
320 return new (arena()) ciTypeArrayKlass(h_k); | |
321 } else if (k->oop_is_method()) { | |
322 return new (arena()) ciMethodKlass(h_k); | |
323 } else if (k->oop_is_symbol()) { | |
324 return new (arena()) ciSymbolKlass(h_k); | |
325 } else if (k->oop_is_klass()) { | |
326 if (k->oop_is_objArrayKlass()) { | |
327 return new (arena()) ciObjArrayKlassKlass(h_k); | |
328 } else if (k->oop_is_typeArrayKlass()) { | |
329 return new (arena()) ciTypeArrayKlassKlass(h_k); | |
330 } else if (k->oop_is_instanceKlass()) { | |
331 return new (arena()) ciInstanceKlassKlass(h_k); | |
332 } else { | |
333 assert(o == Universe::klassKlassObj(), "bad klassKlass"); | |
334 return new (arena()) ciKlassKlass(h_k); | |
335 } | |
336 } | |
337 } else if (o->is_method()) { | |
338 methodHandle h_m(THREAD, (methodOop)o); | |
339 return new (arena()) ciMethod(h_m); | |
340 } else if (o->is_methodData()) { | |
341 methodDataHandle h_md(THREAD, (methodDataOop)o); | |
342 return new (arena()) ciMethodData(h_md); | |
343 } else if (o->is_instance()) { | |
344 instanceHandle h_i(THREAD, (instanceOop)o); | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
345 if (java_dyn_CallSite::is_instance(o)) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
346 return new (arena()) ciCallSite(h_i); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
347 else if (java_dyn_MethodHandle::is_instance(o)) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
348 return new (arena()) ciMethodHandle(h_i); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
349 else |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1137
diff
changeset
|
350 return new (arena()) ciInstance(h_i); |
0 | 351 } else if (o->is_objArray()) { |
352 objArrayHandle h_oa(THREAD, (objArrayOop)o); | |
353 return new (arena()) ciObjArray(h_oa); | |
354 } else if (o->is_typeArray()) { | |
355 typeArrayHandle h_ta(THREAD, (typeArrayOop)o); | |
356 return new (arena()) ciTypeArray(h_ta); | |
1137
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
357 } else if (o->is_constantPoolCache()) { |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
358 constantPoolCacheHandle h_cpc(THREAD, (constantPoolCacheOop) o); |
97125851f396
6829187: compiler optimizations required for JSR 292
twisti
parents:
1080
diff
changeset
|
359 return new (arena()) ciCPCache(h_cpc); |
0 | 360 } |
361 | |
362 // The oop is of some type not supported by the compiler interface. | |
363 ShouldNotReachHere(); | |
364 return NULL; | |
365 } | |
366 | |
367 //------------------------------------------------------------------ | |
368 // ciObjectFactory::get_unloaded_method | |
369 // | |
370 // Get the ciMethod representing an unloaded/unfound method. | |
371 // | |
372 // Implementation note: unloaded methods are currently stored in | |
373 // an unordered array, requiring a linear-time lookup for each | |
374 // unloaded method. This may need to change. | |
375 ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder, | |
376 ciSymbol* name, | |
377 ciSymbol* signature) { | |
378 for (int i=0; i<_unloaded_methods->length(); i++) { | |
379 ciMethod* entry = _unloaded_methods->at(i); | |
380 if (entry->holder()->equals(holder) && | |
381 entry->name()->equals(name) && | |
382 entry->signature()->as_symbol()->equals(signature)) { | |
383 // We've found a match. | |
384 return entry; | |
385 } | |
386 } | |
387 | |
388 // This is a new unloaded method. Create it and stick it in | |
389 // the cache. | |
390 ciMethod* new_method = new (arena()) ciMethod(holder, name, signature); | |
391 | |
392 init_ident_of(new_method); | |
393 _unloaded_methods->append(new_method); | |
394 | |
395 return new_method; | |
396 } | |
397 | |
398 //------------------------------------------------------------------ | |
399 // ciObjectFactory::get_unloaded_klass | |
400 // | |
401 // Get a ciKlass representing an unloaded klass. | |
402 // | |
403 // Implementation note: unloaded klasses are currently stored in | |
404 // an unordered array, requiring a linear-time lookup for each | |
405 // unloaded klass. This may need to change. | |
406 ciKlass* ciObjectFactory::get_unloaded_klass(ciKlass* accessing_klass, | |
407 ciSymbol* name, | |
408 bool create_if_not_found) { | |
409 EXCEPTION_CONTEXT; | |
410 oop loader = NULL; | |
411 oop domain = NULL; | |
412 if (accessing_klass != NULL) { | |
413 loader = accessing_klass->loader(); | |
414 domain = accessing_klass->protection_domain(); | |
415 } | |
416 for (int i=0; i<_unloaded_klasses->length(); i++) { | |
417 ciKlass* entry = _unloaded_klasses->at(i); | |
418 if (entry->name()->equals(name) && | |
419 entry->loader() == loader && | |
420 entry->protection_domain() == domain) { | |
421 // We've found a match. | |
422 return entry; | |
423 } | |
424 } | |
425 | |
426 if (!create_if_not_found) | |
427 return NULL; | |
428 | |
429 // This is a new unloaded klass. Create it and stick it in | |
430 // the cache. | |
431 ciKlass* new_klass = NULL; | |
432 | |
433 // Two cases: this is an unloaded objArrayKlass or an | |
434 // unloaded instanceKlass. Deal with both. | |
435 if (name->byte_at(0) == '[') { | |
436 // Decompose the name.' | |
437 jint dimension = 0; | |
438 symbolOop element_name = NULL; | |
439 BasicType element_type= FieldType::get_array_info(name->get_symbolOop(), | |
440 &dimension, | |
441 &element_name, | |
442 THREAD); | |
443 if (HAS_PENDING_EXCEPTION) { | |
444 CLEAR_PENDING_EXCEPTION; | |
445 CURRENT_THREAD_ENV->record_out_of_memory_failure(); | |
446 return ciEnv::_unloaded_ciobjarrayklass; | |
447 } | |
448 assert(element_type != T_ARRAY, "unsuccessful decomposition"); | |
449 ciKlass* element_klass = NULL; | |
450 if (element_type == T_OBJECT) { | |
451 ciEnv *env = CURRENT_THREAD_ENV; | |
452 ciSymbol* ci_name = env->get_object(element_name)->as_symbol(); | |
453 element_klass = | |
454 env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass(); | |
455 } else { | |
456 assert(dimension > 1, "one dimensional type arrays are always loaded."); | |
457 | |
458 // The type array itself takes care of one of the dimensions. | |
459 dimension--; | |
460 | |
461 // The element klass is a typeArrayKlass. | |
462 element_klass = ciTypeArrayKlass::make(element_type); | |
463 } | |
464 new_klass = new (arena()) ciObjArrayKlass(name, element_klass, dimension); | |
465 } else { | |
466 jobject loader_handle = NULL; | |
467 jobject domain_handle = NULL; | |
468 if (accessing_klass != NULL) { | |
469 loader_handle = accessing_klass->loader_handle(); | |
470 domain_handle = accessing_klass->protection_domain_handle(); | |
471 } | |
472 new_klass = new (arena()) ciInstanceKlass(name, loader_handle, domain_handle); | |
473 } | |
474 init_ident_of(new_klass); | |
475 _unloaded_klasses->append(new_klass); | |
476 | |
477 return new_klass; | |
478 } | |
479 | |
1602 | 480 |
481 //------------------------------------------------------------------ | |
482 // ciObjectFactory::get_unloaded_instance | |
483 // | |
484 // Get a ciInstance representing an as-yet undetermined instance of a given class. | |
485 // | |
486 ciInstance* ciObjectFactory::get_unloaded_instance(ciInstanceKlass* instance_klass) { | |
487 for (int i=0; i<_unloaded_instances->length(); i++) { | |
488 ciInstance* entry = _unloaded_instances->at(i); | |
489 if (entry->klass()->equals(instance_klass)) { | |
490 // We've found a match. | |
491 return entry; | |
492 } | |
493 } | |
494 | |
495 // This is a new unloaded instance. Create it and stick it in | |
496 // the cache. | |
497 ciInstance* new_instance = new (arena()) ciInstance(instance_klass); | |
498 | |
499 init_ident_of(new_instance); | |
500 _unloaded_instances->append(new_instance); | |
501 | |
502 // make sure it looks the way we want: | |
503 assert(!new_instance->is_loaded(), ""); | |
504 assert(new_instance->klass() == instance_klass, ""); | |
505 | |
506 return new_instance; | |
507 } | |
508 | |
509 | |
510 //------------------------------------------------------------------ | |
511 // ciObjectFactory::get_unloaded_klass_mirror | |
512 // | |
513 // Get a ciInstance representing an unresolved klass mirror. | |
514 // | |
515 // Currently, this ignores the parameters and returns a unique unloaded instance. | |
516 ciInstance* ciObjectFactory::get_unloaded_klass_mirror(ciKlass* type) { | |
517 assert(ciEnv::_Class_klass != NULL, ""); | |
518 return get_unloaded_instance(ciEnv::_Class_klass->as_instance_klass()); | |
519 } | |
520 | |
521 //------------------------------------------------------------------ | |
522 // ciObjectFactory::get_unloaded_method_handle_constant | |
523 // | |
524 // Get a ciInstance representing an unresolved method handle constant. | |
525 // | |
526 // Currently, this ignores the parameters and returns a unique unloaded instance. | |
527 ciInstance* ciObjectFactory::get_unloaded_method_handle_constant(ciKlass* holder, | |
528 ciSymbol* name, | |
529 ciSymbol* signature, | |
530 int ref_kind) { | |
531 if (ciEnv::_MethodHandle_klass == NULL) return NULL; | |
532 return get_unloaded_instance(ciEnv::_MethodHandle_klass->as_instance_klass()); | |
533 } | |
534 | |
535 //------------------------------------------------------------------ | |
536 // ciObjectFactory::get_unloaded_method_type_constant | |
537 // | |
538 // Get a ciInstance representing an unresolved method type constant. | |
539 // | |
540 // Currently, this ignores the parameters and returns a unique unloaded instance. | |
541 ciInstance* ciObjectFactory::get_unloaded_method_type_constant(ciSymbol* signature) { | |
542 if (ciEnv::_MethodType_klass == NULL) return NULL; | |
543 return get_unloaded_instance(ciEnv::_MethodType_klass->as_instance_klass()); | |
544 } | |
545 | |
546 | |
547 | |
0 | 548 //------------------------------------------------------------------ |
549 // ciObjectFactory::get_empty_methodData | |
550 // | |
551 // Get the ciMethodData representing the methodData for a method with | |
552 // none. | |
553 ciMethodData* ciObjectFactory::get_empty_methodData() { | |
554 ciMethodData* new_methodData = new (arena()) ciMethodData(); | |
555 init_ident_of(new_methodData); | |
556 return new_methodData; | |
557 } | |
558 | |
559 //------------------------------------------------------------------ | |
560 // ciObjectFactory::get_return_address | |
561 // | |
562 // Get a ciReturnAddress for a specified bci. | |
563 ciReturnAddress* ciObjectFactory::get_return_address(int bci) { | |
564 for (int i=0; i<_return_addresses->length(); i++) { | |
565 ciReturnAddress* entry = _return_addresses->at(i); | |
566 if (entry->bci() == bci) { | |
567 // We've found a match. | |
568 return entry; | |
569 } | |
570 } | |
571 | |
572 ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci); | |
573 init_ident_of(new_ret_addr); | |
574 _return_addresses->append(new_ret_addr); | |
575 return new_ret_addr; | |
576 } | |
577 | |
578 // ------------------------------------------------------------------ | |
579 // ciObjectFactory::init_ident_of | |
580 void ciObjectFactory::init_ident_of(ciObject* obj) { | |
581 obj->set_ident(_next_ident++); | |
582 } | |
583 | |
584 | |
585 // ------------------------------------------------------------------ | |
586 // ciObjectFactory::find | |
587 // | |
588 // Use binary search to find the position of this oop in the cache. | |
589 // If there is no entry in the cache corresponding to this oop, return | |
590 // the position at which the oop should be inserted. | |
591 int ciObjectFactory::find(oop key, GrowableArray<ciObject*>* objects) { | |
592 int min = 0; | |
593 int max = objects->length()-1; | |
594 | |
595 // print_contents(); | |
596 | |
597 while (max >= min) { | |
598 int mid = (max + min) / 2; | |
599 oop value = objects->at(mid)->get_oop(); | |
600 if (value < key) { | |
601 min = mid + 1; | |
602 } else if (value > key) { | |
603 max = mid - 1; | |
604 } else { | |
605 return mid; | |
606 } | |
607 } | |
608 return min; | |
609 } | |
610 | |
611 // ------------------------------------------------------------------ | |
612 // ciObjectFactory::is_found_at | |
613 // | |
614 // Verify that the binary seach found the given key. | |
615 bool ciObjectFactory::is_found_at(int index, oop key, GrowableArray<ciObject*>* objects) { | |
616 return (index < objects->length() && | |
617 objects->at(index)->get_oop() == key); | |
618 } | |
619 | |
620 | |
621 // ------------------------------------------------------------------ | |
622 // ciObjectFactory::insert | |
623 // | |
624 // Insert a ciObject into the table at some index. | |
625 void ciObjectFactory::insert(int index, ciObject* obj, GrowableArray<ciObject*>* objects) { | |
626 int len = objects->length(); | |
627 if (len == index) { | |
628 objects->append(obj); | |
629 } else { | |
630 objects->append(objects->at(len-1)); | |
631 int pos; | |
632 for (pos = len-2; pos >= index; pos--) { | |
633 objects->at_put(pos+1,objects->at(pos)); | |
634 } | |
635 objects->at_put(index, obj); | |
636 } | |
637 #ifdef ASSERT | |
909
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
638 if (CIObjectFactoryVerify) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
639 oop last = NULL; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
640 for (int j = 0; j< objects->length(); j++) { |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
641 oop o = objects->at(j)->get_oop(); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
642 assert(last < o, "out of order"); |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
643 last = o; |
b32a809aab08
6866585: debug code in ciObjectFactory too slow for large objects
jcoomes
parents:
196
diff
changeset
|
644 } |
0 | 645 } |
646 #endif // ASSERT | |
647 } | |
648 | |
649 static ciObjectFactory::NonPermObject* emptyBucket = NULL; | |
650 | |
651 // ------------------------------------------------------------------ | |
652 // ciObjectFactory::find_non_perm | |
653 // | |
654 // Use a small hash table, hashed on the klass of the key. | |
655 // If there is no entry in the cache corresponding to this oop, return | |
656 // the null tail of the bucket into which the oop should be inserted. | |
657 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) { | |
658 // Be careful: is_perm might change from false to true. | |
659 // Thus, there might be a matching perm object in the table. | |
660 // If there is, this probe must find it. | |
661 if (key->is_perm() && _non_perm_count == 0) { | |
662 return emptyBucket; | |
663 } else if (key->is_instance()) { | |
1142 | 664 if (key->klass() == SystemDictionary::Class_klass()) { |
0 | 665 // class mirror instances are always perm |
666 return emptyBucket; | |
667 } | |
668 // fall through to probe | |
669 } else if (key->is_array()) { | |
670 // fall through to probe | |
671 } else { | |
672 // not an array or instance | |
673 return emptyBucket; | |
674 } | |
675 | |
676 ciObject* klass = get(key->klass()); | |
677 NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS]; | |
678 for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) { | |
679 if (is_equal(p, key)) break; | |
680 } | |
681 return (*bp); | |
682 } | |
683 | |
684 | |
685 | |
686 // ------------------------------------------------------------------ | |
687 // Code for for NonPermObject | |
688 // | |
689 inline ciObjectFactory::NonPermObject::NonPermObject(ciObjectFactory::NonPermObject* &bucket, oop key, ciObject* object) { | |
690 assert(ciObjectFactory::is_initialized(), ""); | |
691 _object = object; | |
692 _next = bucket; | |
693 bucket = this; | |
694 } | |
695 | |
696 | |
697 | |
698 // ------------------------------------------------------------------ | |
699 // ciObjectFactory::insert_non_perm | |
700 // | |
701 // Insert a ciObject into the non-perm table. | |
702 void ciObjectFactory::insert_non_perm(ciObjectFactory::NonPermObject* &where, oop key, ciObject* obj) { | |
703 assert(&where != &emptyBucket, "must not try to fill empty bucket"); | |
704 NonPermObject* p = new (arena()) NonPermObject(where, key, obj); | |
705 assert(where == p && is_equal(p, key) && p->object() == obj, "entry must match"); | |
706 assert(find_non_perm(key) == p, "must find the same spot"); | |
707 ++_non_perm_count; | |
708 } | |
709 | |
710 // ------------------------------------------------------------------ | |
711 // ciObjectFactory::vm_symbol_at | |
712 // Get the ciSymbol corresponding to some index in vmSymbols. | |
713 ciSymbol* ciObjectFactory::vm_symbol_at(int index) { | |
714 assert(index >= vmSymbols::FIRST_SID && index < vmSymbols::SID_LIMIT, "oob"); | |
715 return _shared_ci_symbols[index]; | |
716 } | |
717 | |
718 // ------------------------------------------------------------------ | |
719 // ciObjectFactory::print_contents_impl | |
720 void ciObjectFactory::print_contents_impl() { | |
721 int len = _ci_objects->length(); | |
722 tty->print_cr("ciObjectFactory (%d) oop contents:", len); | |
723 for (int i=0; i<len; i++) { | |
724 _ci_objects->at(i)->print(); | |
725 tty->cr(); | |
726 } | |
727 } | |
728 | |
729 // ------------------------------------------------------------------ | |
730 // ciObjectFactory::print_contents | |
731 void ciObjectFactory::print_contents() { | |
732 print(); | |
733 tty->cr(); | |
734 GUARDED_VM_ENTRY(print_contents_impl();) | |
735 } | |
736 | |
737 // ------------------------------------------------------------------ | |
738 // ciObjectFactory::print | |
739 // | |
740 // Print debugging information about the object factory | |
741 void ciObjectFactory::print() { | |
1602 | 742 tty->print("<ciObjectFactory oops=%d unloaded_methods=%d unloaded_instances=%d unloaded_klasses=%d>", |
0 | 743 _ci_objects->length(), _unloaded_methods->length(), |
1602 | 744 _unloaded_instances->length(), |
0 | 745 _unloaded_klasses->length()); |
746 } |