< prev index next >

src/hotspot/share/ci/ciObjectFactory.cpp

Print this page

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 // ------------------------------------------------------------------

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);

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 void ciObjectFactory::notice_object_access(ciBaseObject* new_object) {
261   if (TrainingData::need_data()) {
262     ciEnv* env = ciEnv::current();
263     if (env->task() != nullptr) {
264       // Note: task will be null during init_compiler_runtime.
265       CompileTrainingData* td = env->task()->training_data();
266       if (td != nullptr) {
267         td->notice_jit_observation(env, new_object);
268       }
269     }
270   }
271 }
272 
273 int ciObjectFactory::metadata_compare(Metadata* const& key, ciMetadata* const& elt) {
274   Metadata* value = elt->constant_encoding();
275   if (key < value)      return -1;
276   else if (key > value) return 1;
277   else                  return 0;
278 }
279 
280 // ------------------------------------------------------------------

332         assert(index == i, " bad lookup");
333       }
334     }
335   }
336 #endif
337 
338   if (!found) {
339     // The ciMetadata does not yet exist. Create it and insert it
340     // into the cache.
341     ciMetadata* new_object = create_new_metadata(key);
342     init_ident_of(new_object);
343     assert(new_object->is_metadata(), "must be");
344 
345     if (len != _ci_metadata.length()) {
346       // creating the new object has recursively entered new objects
347       // into the table.  We need to recompute our index.
348       index = _ci_metadata.find_sorted<Metadata*, ciObjectFactory::metadata_compare>(key, found);
349     }
350     assert(!found, "no double insert");
351     _ci_metadata.insert_before(index, new_object);
352     notice_object_access(new_object);
353     return new_object;
354   }
355   ciMetadata* metadata = _ci_metadata.at(index)->as_metadata();
356   notice_object_access(metadata);
357   return metadata;
358 }
359 
360 // ------------------------------------------------------------------
361 // ciObjectFactory::create_new_object
362 //
363 // Create a new ciObject from an oop.
364 //
365 // Implementation note: this functionality could be virtual behavior
366 // of the oop itself.  For now, we explicitly marshal the object.
367 ciObject* ciObjectFactory::create_new_object(oop o) {
368   EXCEPTION_CONTEXT;
369 
370   if (o->is_instance()) {
371     instanceHandle h_i(THREAD, (instanceOop)o);
372     if (java_lang_invoke_CallSite::is_instance(o))
373       return new (arena()) ciCallSite(h_i);
374     else if (java_lang_invoke_MemberName::is_instance(o))
375       return new (arena()) ciMemberName(h_i);
376     else if (java_lang_invoke_MethodHandle::is_instance(o))
377       return new (arena()) ciMethodHandle(h_i);
< prev index next >