137 Symbol* vmsym = vmSymbols::symbol_at(index);
138 ciSymbol* sym = vm_symbol_at(index);
139 assert(sym->get_symbol() == vmsym, "oop must match");
140 }
141 assert(ciSymbols::void_class_signature()->get_symbol() == vmSymbols::void_class_signature(), "spot check");
142 #endif
143 }
144
145 for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
146 BasicType t = (BasicType)i;
147 if (type2name(t) != nullptr && !is_reference_type(t) &&
148 t != T_NARROWOOP && t != T_NARROWKLASS) {
149 ciType::_basic_types[t] = new (_arena) ciType(t);
150 init_ident_of(ciType::_basic_types[t]);
151 }
152 }
153
154 ciEnv::_null_object_instance = new (_arena) ciNullObject();
155 init_ident_of(ciEnv::_null_object_instance);
156
157 #define VM_CLASS_DEFN(name, ignore_s) \
158 if (vmClasses::name##_is_loaded()) \
159 ciEnv::_##name = get_metadata(vmClasses::name())->as_instance_klass();
160
161 VM_CLASSES_DO(VM_CLASS_DEFN)
162 #undef VM_CLASS_DEFN
163
164 for (int len = -1; len != _ci_metadata.length(); ) {
165 len = _ci_metadata.length();
166 for (int i2 = 0; i2 < len; i2++) {
167 ciMetadata* obj = _ci_metadata.at(i2);
168 assert (obj->is_metadata(), "what else would it be?");
169 if (obj->is_loaded() && obj->is_instance_klass()) {
170 obj->as_instance_klass()->compute_nonstatic_fields();
171 obj->as_instance_klass()->transitive_interfaces();
172 }
173 }
174 }
175
176 ciEnv::_unloaded_cisymbol = ciObjectFactory::get_symbol(vmSymbols::dummy_symbol());
177 // Create dummy InstanceKlass and ObjArrayKlass object and assign them idents
178 ciEnv::_unloaded_ciinstance_klass = new (_arena) ciInstanceKlass(ciEnv::_unloaded_cisymbol, nullptr);
179 init_ident_of(ciEnv::_unloaded_ciinstance_klass);
180 ciEnv::_unloaded_ciobjarrayklass = new (_arena) ciObjArrayKlass(ciEnv::_unloaded_cisymbol, ciEnv::_unloaded_ciinstance_klass, 1);
222 s->get_symbol()->decrement_refcount();
223 }
224 // Since _symbols is resource allocated we're not allowed to delete it
225 // but it'll go away just the same.
226 }
227
228 // ------------------------------------------------------------------
229 // ciObjectFactory::get
230 //
231 // Get the ciObject corresponding to some oop. If the ciObject has
232 // already been created, it is returned. Otherwise, a new ciObject
233 // is created.
234 ciObject* ciObjectFactory::get(oop key) {
235 ASSERT_IN_VM;
236
237 Handle keyHandle(Thread::current(), key);
238 assert(Universe::heap()->is_in(keyHandle()), "must be");
239
240 NonPermObject* &bucket = find_non_perm(keyHandle);
241 if (bucket != nullptr) {
242 return bucket->object();
243 }
244
245 // The ciObject does not yet exist. Create it and insert it
246 // into the cache.
247 ciObject* new_object = create_new_object(keyHandle());
248 assert(keyHandle() == new_object->get_oop(), "must be properly recorded");
249 init_ident_of(new_object);
250 assert(Universe::heap()->is_in(new_object->get_oop()), "must be");
251
252 // Not a perm-space object.
253 insert_non_perm(bucket, keyHandle, new_object);
254 notice_new_object(new_object);
255 return new_object;
256 }
257
258 void ciObjectFactory::notice_new_object(ciBaseObject* new_object) {
259 if (TrainingData::need_data()) {
260 ciEnv* env = ciEnv::current();
261 if (env->task() != nullptr) {
262 // Note: task will be null during init_compiler_runtime.
263 CompileTrainingData* td = env->task()->training_data();
264 if (td != nullptr) {
265 td->notice_jit_observation(env, new_object);
266 }
267 }
268 }
269 }
270
271 int ciObjectFactory::metadata_compare(Metadata* const& key, ciMetadata* const& elt) {
272 Metadata* value = elt->constant_encoding();
273 if (key < value) return -1;
274 else if (key > value) return 1;
275 else return 0;
276 }
277
278 // ------------------------------------------------------------------
279 // ciObjectFactory::cached_metadata
280 //
281 // Get the ciMetadata corresponding to some Metadata. If the ciMetadata has
282 // already been created, it is returned. Otherwise, null is returned.
283 ciMetadata* ciObjectFactory::cached_metadata(Metadata* key) {
284 ASSERT_IN_VM;
285
286 bool found = false;
287 int index = _ci_metadata.find_sorted<Metadata*, ciObjectFactory::metadata_compare>(key, found);
288
289 if (!found) {
330 assert(index == i, " bad lookup");
331 }
332 }
333 }
334 #endif
335
336 if (!found) {
337 // The ciMetadata does not yet exist. Create it and insert it
338 // into the cache.
339 ciMetadata* new_object = create_new_metadata(key);
340 init_ident_of(new_object);
341 assert(new_object->is_metadata(), "must be");
342
343 if (len != _ci_metadata.length()) {
344 // creating the new object has recursively entered new objects
345 // into the table. We need to recompute our index.
346 index = _ci_metadata.find_sorted<Metadata*, ciObjectFactory::metadata_compare>(key, found);
347 }
348 assert(!found, "no double insert");
349 _ci_metadata.insert_before(index, new_object);
350 notice_new_object(new_object);
351 return new_object;
352 }
353 return _ci_metadata.at(index)->as_metadata();
354 }
355
356 // ------------------------------------------------------------------
357 // ciObjectFactory::create_new_object
358 //
359 // Create a new ciObject from an oop.
360 //
361 // Implementation note: this functionality could be virtual behavior
362 // of the oop itself. For now, we explicitly marshal the object.
363 ciObject* ciObjectFactory::create_new_object(oop o) {
364 EXCEPTION_CONTEXT;
365
366 if (o->is_instance()) {
367 instanceHandle h_i(THREAD, (instanceOop)o);
368 if (java_lang_invoke_CallSite::is_instance(o))
369 return new (arena()) ciCallSite(h_i);
370 else if (java_lang_invoke_MemberName::is_instance(o))
371 return new (arena()) ciMemberName(h_i);
372 else if (java_lang_invoke_MethodHandle::is_instance(o))
373 return new (arena()) ciMethodHandle(h_i);
397 // is used, which points to it's holder.
398 ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
399 EXCEPTION_CONTEXT;
400
401 if (o->is_klass()) {
402 Klass* k = (Klass*)o;
403 if (k->is_instance_klass()) {
404 assert(!ReplayCompiles || ciReplay::no_replay_state() || !ciReplay::is_klass_unresolved((InstanceKlass*)k), "must be whitelisted for replay compilation");
405 return new (arena()) ciInstanceKlass(k);
406 } else if (k->is_objArray_klass()) {
407 return new (arena()) ciObjArrayKlass(k);
408 } else if (k->is_typeArray_klass()) {
409 return new (arena()) ciTypeArrayKlass(k);
410 }
411 } else if (o->is_method()) {
412 methodHandle h_m(THREAD, (Method*)o);
413 ciEnv *env = CURRENT_THREAD_ENV;
414 ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder());
415 return new (arena()) ciMethod(h_m, holder);
416 } else if (o->is_methodData()) {
417 // Hold methodHandle alive - might not be necessary ???
418 methodHandle h_m(THREAD, ((MethodData*)o)->method());
419 return new (arena()) ciMethodData((MethodData*)o);
420 }
421
422 // The Metadata* is of some type not supported by the compiler interface.
423 ShouldNotReachHere();
424 return nullptr;
425 }
426
427 //------------------------------------------------------------------
428 // ciObjectFactory::get_unloaded_method
429 //
430 // Get the ciMethod representing an unloaded/unfound method.
431 //
432 // Implementation note: unloaded methods are currently stored in
433 // an unordered array, requiring a linear-time lookup for each
434 // unloaded method. This may need to change.
435 ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder,
436 ciSymbol* name,
437 ciSymbol* signature,
438 ciInstanceKlass* accessor) {
439 assert(accessor != nullptr, "need origin of access");
|
137 Symbol* vmsym = vmSymbols::symbol_at(index);
138 ciSymbol* sym = vm_symbol_at(index);
139 assert(sym->get_symbol() == vmsym, "oop must match");
140 }
141 assert(ciSymbols::void_class_signature()->get_symbol() == vmSymbols::void_class_signature(), "spot check");
142 #endif
143 }
144
145 for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
146 BasicType t = (BasicType)i;
147 if (type2name(t) != nullptr && !is_reference_type(t) &&
148 t != T_NARROWOOP && t != T_NARROWKLASS) {
149 ciType::_basic_types[t] = new (_arena) ciType(t);
150 init_ident_of(ciType::_basic_types[t]);
151 }
152 }
153
154 ciEnv::_null_object_instance = new (_arena) ciNullObject();
155 init_ident_of(ciEnv::_null_object_instance);
156
157 #define VM_CLASS_DEFN(name, ignore_s) \
158 if (vmClasses::name##_is_loaded()) { \
159 ciEnv::_##name = get_metadata(vmClasses::name())->as_instance_klass(); \
160 }
161 VM_CLASSES_DO(VM_CLASS_DEFN)
162 #undef VM_CLASS_DEFN
163
164 for (int len = -1; len != _ci_metadata.length(); ) {
165 len = _ci_metadata.length();
166 for (int i2 = 0; i2 < len; i2++) {
167 ciMetadata* obj = _ci_metadata.at(i2);
168 assert (obj->is_metadata(), "what else would it be?");
169 if (obj->is_loaded() && obj->is_instance_klass()) {
170 obj->as_instance_klass()->compute_nonstatic_fields();
171 obj->as_instance_klass()->transitive_interfaces();
172 }
173 }
174 }
175
176 ciEnv::_unloaded_cisymbol = ciObjectFactory::get_symbol(vmSymbols::dummy_symbol());
177 // Create dummy InstanceKlass and ObjArrayKlass object and assign them idents
178 ciEnv::_unloaded_ciinstance_klass = new (_arena) ciInstanceKlass(ciEnv::_unloaded_cisymbol, nullptr);
179 init_ident_of(ciEnv::_unloaded_ciinstance_klass);
180 ciEnv::_unloaded_ciobjarrayklass = new (_arena) ciObjArrayKlass(ciEnv::_unloaded_cisymbol, ciEnv::_unloaded_ciinstance_klass, 1);
222 s->get_symbol()->decrement_refcount();
223 }
224 // Since _symbols is resource allocated we're not allowed to delete it
225 // but it'll go away just the same.
226 }
227
228 // ------------------------------------------------------------------
229 // ciObjectFactory::get
230 //
231 // Get the ciObject corresponding to some oop. If the ciObject has
232 // already been created, it is returned. Otherwise, a new ciObject
233 // is created.
234 ciObject* ciObjectFactory::get(oop key) {
235 ASSERT_IN_VM;
236
237 Handle keyHandle(Thread::current(), key);
238 assert(Universe::heap()->is_in(keyHandle()), "must be");
239
240 NonPermObject* &bucket = find_non_perm(keyHandle);
241 if (bucket != nullptr) {
242 ciObject* obj = bucket->object();
243 notice_object_access(obj);
244 return obj;
245 }
246
247 // The ciObject does not yet exist. Create it and insert it
248 // into the cache.
249 ciObject* new_object = create_new_object(keyHandle());
250 assert(keyHandle() == new_object->get_oop(), "must be properly recorded");
251 init_ident_of(new_object);
252 assert(Universe::heap()->is_in(new_object->get_oop()), "must be");
253
254 // Not a perm-space object.
255 insert_non_perm(bucket, keyHandle, new_object);
256 notice_object_access(new_object);
257 return new_object;
258 }
259
260 #if INCLUDE_CDS
261 void ciObjectFactory::notice_object_access(ciBaseObject* new_object) {
262 if (TrainingData::need_data()) {
263 ciEnv* env = ciEnv::current();
264 if (env->task() != nullptr) {
265 // Note: task will be null during init_compiler_runtime.
266 CompileTrainingData* td = env->task()->training_data();
267 if (td != nullptr) {
268 td->notice_jit_observation(env, new_object);
269 }
270 }
271 }
272 }
273 #endif
274
275 int ciObjectFactory::metadata_compare(Metadata* const& key, ciMetadata* const& elt) {
276 Metadata* value = elt->constant_encoding();
277 if (key < value) return -1;
278 else if (key > value) return 1;
279 else return 0;
280 }
281
282 // ------------------------------------------------------------------
283 // ciObjectFactory::cached_metadata
284 //
285 // Get the ciMetadata corresponding to some Metadata. If the ciMetadata has
286 // already been created, it is returned. Otherwise, null is returned.
287 ciMetadata* ciObjectFactory::cached_metadata(Metadata* key) {
288 ASSERT_IN_VM;
289
290 bool found = false;
291 int index = _ci_metadata.find_sorted<Metadata*, ciObjectFactory::metadata_compare>(key, found);
292
293 if (!found) {
334 assert(index == i, " bad lookup");
335 }
336 }
337 }
338 #endif
339
340 if (!found) {
341 // The ciMetadata does not yet exist. Create it and insert it
342 // into the cache.
343 ciMetadata* new_object = create_new_metadata(key);
344 init_ident_of(new_object);
345 assert(new_object->is_metadata(), "must be");
346
347 if (len != _ci_metadata.length()) {
348 // creating the new object has recursively entered new objects
349 // into the table. We need to recompute our index.
350 index = _ci_metadata.find_sorted<Metadata*, ciObjectFactory::metadata_compare>(key, found);
351 }
352 assert(!found, "no double insert");
353 _ci_metadata.insert_before(index, new_object);
354 notice_object_access(new_object);
355 return new_object;
356 }
357 ciMetadata* metadata = _ci_metadata.at(index)->as_metadata();
358 notice_object_access(metadata);
359 return metadata;
360 }
361
362 // ------------------------------------------------------------------
363 // ciObjectFactory::create_new_object
364 //
365 // Create a new ciObject from an oop.
366 //
367 // Implementation note: this functionality could be virtual behavior
368 // of the oop itself. For now, we explicitly marshal the object.
369 ciObject* ciObjectFactory::create_new_object(oop o) {
370 EXCEPTION_CONTEXT;
371
372 if (o->is_instance()) {
373 instanceHandle h_i(THREAD, (instanceOop)o);
374 if (java_lang_invoke_CallSite::is_instance(o))
375 return new (arena()) ciCallSite(h_i);
376 else if (java_lang_invoke_MemberName::is_instance(o))
377 return new (arena()) ciMemberName(h_i);
378 else if (java_lang_invoke_MethodHandle::is_instance(o))
379 return new (arena()) ciMethodHandle(h_i);
403 // is used, which points to it's holder.
404 ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
405 EXCEPTION_CONTEXT;
406
407 if (o->is_klass()) {
408 Klass* k = (Klass*)o;
409 if (k->is_instance_klass()) {
410 assert(!ReplayCompiles || ciReplay::no_replay_state() || !ciReplay::is_klass_unresolved((InstanceKlass*)k), "must be whitelisted for replay compilation");
411 return new (arena()) ciInstanceKlass(k);
412 } else if (k->is_objArray_klass()) {
413 return new (arena()) ciObjArrayKlass(k);
414 } else if (k->is_typeArray_klass()) {
415 return new (arena()) ciTypeArrayKlass(k);
416 }
417 } else if (o->is_method()) {
418 methodHandle h_m(THREAD, (Method*)o);
419 ciEnv *env = CURRENT_THREAD_ENV;
420 ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder());
421 return new (arena()) ciMethod(h_m, holder);
422 } else if (o->is_methodData()) {
423 // Callers ciMethod::ensure_method_data() and ::method_data() have MH already.
424 return new (arena()) ciMethodData((MethodData*)o);
425 } else if (o->is_methodCounters()) {
426 // Caller ciMethod::ensure_method_counters() has MH already.
427 return new (arena()) ciMetadata(o);
428 }
429
430 // The Metadata* is of some type not supported by the compiler interface.
431 ShouldNotReachHere();
432 return nullptr;
433 }
434
435 //------------------------------------------------------------------
436 // ciObjectFactory::get_unloaded_method
437 //
438 // Get the ciMethod representing an unloaded/unfound method.
439 //
440 // Implementation note: unloaded methods are currently stored in
441 // an unordered array, requiring a linear-time lookup for each
442 // unloaded method. This may need to change.
443 ciMethod* ciObjectFactory::get_unloaded_method(ciInstanceKlass* holder,
444 ciSymbol* name,
445 ciSymbol* signature,
446 ciInstanceKlass* accessor) {
447 assert(accessor != nullptr, "need origin of access");
|