< prev index next >

src/hotspot/share/ci/ciObjectFactory.cpp

Print this page

  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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "ci/ciCallSite.hpp"



 26 #include "ci/ciInstance.hpp"
 27 #include "ci/ciInstanceKlass.hpp"
 28 #include "ci/ciMemberName.hpp"
 29 #include "ci/ciMethod.hpp"
 30 #include "ci/ciMethodData.hpp"
 31 #include "ci/ciMethodHandle.hpp"
 32 #include "ci/ciMethodType.hpp"
 33 #include "ci/ciNullObject.hpp"
 34 #include "ci/ciObjArray.hpp"
 35 #include "ci/ciObjArrayKlass.hpp"
 36 #include "ci/ciObject.hpp"
 37 #include "ci/ciObjectFactory.hpp"

 38 #include "ci/ciReplay.hpp"
 39 #include "ci/ciSymbol.hpp"
 40 #include "ci/ciSymbols.hpp"
 41 #include "ci/ciTypeArray.hpp"
 42 #include "ci/ciTypeArrayKlass.hpp"
 43 #include "ci/ciUtilities.inline.hpp"
 44 #include "classfile/javaClasses.inline.hpp"
 45 #include "classfile/vmClasses.hpp"
 46 #include "compiler/compiler_globals.hpp"
 47 #include "compiler/compileTask.hpp"
 48 #include "gc/shared/collectedHeap.inline.hpp"
 49 #include "memory/allocation.inline.hpp"
 50 #include "memory/universe.hpp"
 51 #include "oops/oop.inline.hpp"
 52 #include "oops/trainingData.hpp"
 53 #include "runtime/handles.inline.hpp"
 54 #include "runtime/signature.hpp"
 55 #include "utilities/macros.hpp"
 56 
 57 // ciObjectFactory

127     // Create the shared symbols, but not in _shared_ci_metadata.
128     for (auto index : EnumRange<vmSymbolID>{}) {
129       Symbol* vmsym = vmSymbols::symbol_at(index);
130       assert(vmSymbols::find_sid(vmsym) == index, "1-1 mapping");
131       ciSymbol* sym = new (_arena) ciSymbol(vmsym, index);
132       init_ident_of(sym);
133       _shared_ci_symbols[vmSymbols::as_int(index)] = sym;
134     }
135 #ifdef ASSERT
136     for (auto index : EnumRange<vmSymbolID>{}) {
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);

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);
374     else if (java_lang_invoke_MethodType::is_instance(o))
375       return new (arena()) ciMethodType(h_i);
376     else
377       return new (arena()) ciInstance(h_i);
378   } else if (o->is_objArray()) {
379     objArrayHandle h_oa(THREAD, (objArrayOop)o);
380     return new (arena()) ciObjArray(h_oa);
381   } else if (o->is_typeArray()) {
382     typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
383     return new (arena()) ciTypeArray(h_ta);



384   }
385 
386   // The oop is of some type not supported by the compiler interface.
387   ShouldNotReachHere();
388   return nullptr;
389 }
390 
391 // ------------------------------------------------------------------
392 // ciObjectFactory::create_new_metadata
393 //
394 // Create a new ciMetadata from a Metadata*.
395 //
396 // Implementation note: in order to keep Metadata live, an auxiliary ciObject
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 //------------------------------------------------------------------

622 
623 //------------------------------------------------------------------
624 // ciObjectFactory::get_return_address
625 //
626 // Get a ciReturnAddress for a specified bci.
627 ciReturnAddress* ciObjectFactory::get_return_address(int bci) {
628   for (int i = 0; i < _return_addresses.length(); i++) {
629     ciReturnAddress* entry = _return_addresses.at(i);
630     if (entry->bci() == bci) {
631       // We've found a match.
632       return entry;
633     }
634   }
635 
636   ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci);
637   init_ident_of(new_ret_addr);
638   _return_addresses.append(new_ret_addr);
639   return new_ret_addr;
640 }
641 












642 // ------------------------------------------------------------------
643 // ciObjectFactory::init_ident_of
644 void ciObjectFactory::init_ident_of(ciBaseObject* obj) {
645   obj->set_ident(_next_ident++);
646 }
647 
648 static ciObjectFactory::NonPermObject* emptyBucket = nullptr;
649 
650 // ------------------------------------------------------------------
651 // ciObjectFactory::find_non_perm
652 //
653 // Use a small hash table, hashed on the klass of the key.
654 // If there is no entry in the cache corresponding to this oop, return
655 // the null tail of the bucket into which the oop should be inserted.
656 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(Handle keyHandle) {
657   assert(Universe::heap()->is_in(keyHandle()), "must be");
658   ciMetadata* klass = get_metadata(keyHandle->klass()); // This may safepoint!
659   NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
660   for (NonPermObject* p; (p = (*bp)) != nullptr; bp = &p->next()) {
661     if (is_equal(p, keyHandle()))  break;

  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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "ci/ciCallSite.hpp"
 26 #include "ci/ciFlatArray.hpp"
 27 #include "ci/ciFlatArrayKlass.hpp"
 28 #include "ci/ciInlineKlass.hpp"
 29 #include "ci/ciInstance.hpp"
 30 #include "ci/ciInstanceKlass.hpp"
 31 #include "ci/ciMemberName.hpp"
 32 #include "ci/ciMethod.hpp"
 33 #include "ci/ciMethodData.hpp"
 34 #include "ci/ciMethodHandle.hpp"
 35 #include "ci/ciMethodType.hpp"
 36 #include "ci/ciNullObject.hpp"
 37 #include "ci/ciObjArray.hpp"
 38 #include "ci/ciObjArrayKlass.hpp"
 39 #include "ci/ciObject.hpp"
 40 #include "ci/ciObjectFactory.hpp"
 41 #include "ci/ciRefArrayKlass.hpp"
 42 #include "ci/ciReplay.hpp"
 43 #include "ci/ciSymbol.hpp"
 44 #include "ci/ciSymbols.hpp"
 45 #include "ci/ciTypeArray.hpp"
 46 #include "ci/ciTypeArrayKlass.hpp"
 47 #include "ci/ciUtilities.inline.hpp"
 48 #include "classfile/javaClasses.inline.hpp"
 49 #include "classfile/vmClasses.hpp"
 50 #include "compiler/compiler_globals.hpp"
 51 #include "compiler/compileTask.hpp"
 52 #include "gc/shared/collectedHeap.inline.hpp"
 53 #include "memory/allocation.inline.hpp"
 54 #include "memory/universe.hpp"
 55 #include "oops/oop.inline.hpp"
 56 #include "oops/trainingData.hpp"
 57 #include "runtime/handles.inline.hpp"
 58 #include "runtime/signature.hpp"
 59 #include "utilities/macros.hpp"
 60 
 61 // ciObjectFactory

131     // Create the shared symbols, but not in _shared_ci_metadata.
132     for (auto index : EnumRange<vmSymbolID>{}) {
133       Symbol* vmsym = vmSymbols::symbol_at(index);
134       assert(vmSymbols::find_sid(vmsym) == index, "1-1 mapping");
135       ciSymbol* sym = new (_arena) ciSymbol(vmsym, index);
136       init_ident_of(sym);
137       _shared_ci_symbols[vmSymbols::as_int(index)] = sym;
138     }
139 #ifdef ASSERT
140     for (auto index : EnumRange<vmSymbolID>{}) {
141       Symbol* vmsym = vmSymbols::symbol_at(index);
142       ciSymbol* sym = vm_symbol_at(index);
143       assert(sym->get_symbol() == vmsym, "oop must match");
144     }
145     assert(ciSymbols::void_class_signature()->get_symbol() == vmSymbols::void_class_signature(), "spot check");
146 #endif
147   }
148 
149   for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
150     BasicType t = (BasicType)i;
151     if (type2name(t) != nullptr && t != T_FLAT_ELEMENT && !is_reference_type(t) &&
152         t != T_NARROWOOP && t != T_NARROWKLASS) {
153       ciType::_basic_types[t] = new (_arena) ciType(t);
154       init_ident_of(ciType::_basic_types[t]);
155     }
156   }
157 
158   ciEnv::_null_object_instance = new (_arena) ciNullObject();
159   init_ident_of(ciEnv::_null_object_instance);
160 
161 #define VM_CLASS_DEFN(name, ignore_s)                              \
162   if (vmClasses::name##_is_loaded()) \
163     ciEnv::_##name = get_metadata(vmClasses::name())->as_instance_klass();
164 
165   VM_CLASSES_DO(VM_CLASS_DEFN)
166 #undef VM_CLASS_DEFN
167 
168   for (int len = -1; len != _ci_metadata.length(); ) {
169     len = _ci_metadata.length();
170     for (int i2 = 0; i2 < len; i2++) {
171       ciMetadata* obj = _ci_metadata.at(i2);

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);
378     else if (java_lang_invoke_MethodType::is_instance(o))
379       return new (arena()) ciMethodType(h_i);
380     else
381       return new (arena()) ciInstance(h_i);
382   } else if (o->is_refArray()) {
383     objArrayHandle h_oa(THREAD, (objArrayOop)o);
384     return new (arena()) ciObjArray(h_oa);
385   } else if (o->is_typeArray()) {
386     typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
387     return new (arena()) ciTypeArray(h_ta);
388   } else if (o->is_flatArray()) {
389     flatArrayHandle h_ta(THREAD, (flatArrayOop)o);
390     return new (arena()) ciFlatArray(h_ta);
391   }
392 
393   // The oop is of some type not supported by the compiler interface.
394   ShouldNotReachHere();
395   return nullptr;
396 }
397 
398 // ------------------------------------------------------------------
399 // ciObjectFactory::create_new_metadata
400 //
401 // Create a new ciMetadata from a Metadata*.
402 //
403 // Implementation note: in order to keep Metadata live, an auxiliary ciObject
404 // is used, which points to it's holder.
405 ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
406   EXCEPTION_CONTEXT;
407 
408   if (o->is_klass()) {
409     Klass* k = (Klass*)o;
410     if (k->is_inline_klass()) {
411       return new (arena()) ciInlineKlass(k);
412     } else if (k->is_instance_klass()) {
413       assert(!ReplayCompiles || ciReplay::no_replay_state() || !ciReplay::is_klass_unresolved((InstanceKlass*)k), "must be whitelisted for replay compilation");
414       return new (arena()) ciInstanceKlass(k);
415     } else if (k->is_objArray_klass()) {
416       if (k->is_flatArray_klass()) {
417         return new (arena()) ciFlatArrayKlass(k);
418       } else if (k->is_refArray_klass()) {
419         return new (arena()) ciRefArrayKlass(k);
420       } else {
421         return new (arena()) ciObjArrayKlass(k);
422       }
423     } else if (k->is_typeArray_klass()) {
424       return new (arena()) ciTypeArrayKlass(k);
425     }
426   } else if (o->is_method()) {
427     methodHandle h_m(THREAD, (Method*)o);
428     ciEnv *env = CURRENT_THREAD_ENV;
429     ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder());
430     return new (arena()) ciMethod(h_m, holder);
431   } else if (o->is_methodData()) {
432     // Hold methodHandle alive - might not be necessary ???
433     methodHandle h_m(THREAD, ((MethodData*)o)->method());
434     return new (arena()) ciMethodData((MethodData*)o);
435   }
436 
437   // The Metadata* is of some type not supported by the compiler interface.
438   ShouldNotReachHere();
439   return nullptr;
440 }
441 
442 //------------------------------------------------------------------

637 
638 //------------------------------------------------------------------
639 // ciObjectFactory::get_return_address
640 //
641 // Get a ciReturnAddress for a specified bci.
642 ciReturnAddress* ciObjectFactory::get_return_address(int bci) {
643   for (int i = 0; i < _return_addresses.length(); i++) {
644     ciReturnAddress* entry = _return_addresses.at(i);
645     if (entry->bci() == bci) {
646       // We've found a match.
647       return entry;
648     }
649   }
650 
651   ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci);
652   init_ident_of(new_ret_addr);
653   _return_addresses.append(new_ret_addr);
654   return new_ret_addr;
655 }
656 
657 ciWrapper* ciObjectFactory::make_early_larval_wrapper(ciType* type) {
658   ciWrapper* wrapper = new (arena()) ciWrapper(type, ciWrapper::EarlyLarval);
659   init_ident_of(wrapper);
660   return wrapper;
661 }
662 
663 ciWrapper* ciObjectFactory::make_null_free_wrapper(ciType* type) {
664   ciWrapper* wrapper = new (arena()) ciWrapper(type, ciWrapper::NullFree);
665   init_ident_of(wrapper);
666   return wrapper;
667 }
668 
669 // ------------------------------------------------------------------
670 // ciObjectFactory::init_ident_of
671 void ciObjectFactory::init_ident_of(ciBaseObject* obj) {
672   obj->set_ident(_next_ident++);
673 }
674 
675 static ciObjectFactory::NonPermObject* emptyBucket = nullptr;
676 
677 // ------------------------------------------------------------------
678 // ciObjectFactory::find_non_perm
679 //
680 // Use a small hash table, hashed on the klass of the key.
681 // If there is no entry in the cache corresponding to this oop, return
682 // the null tail of the bucket into which the oop should be inserted.
683 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(Handle keyHandle) {
684   assert(Universe::heap()->is_in(keyHandle()), "must be");
685   ciMetadata* klass = get_metadata(keyHandle->klass()); // This may safepoint!
686   NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
687   for (NonPermObject* p; (p = (*bp)) != nullptr; bp = &p->next()) {
688     if (is_equal(p, keyHandle()))  break;
< prev index next >