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