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