< 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/instanceKlass.hpp"
 52 #include "oops/oop.inline.hpp"
 53 #include "oops/trainingData.hpp"
 54 #include "runtime/handles.inline.hpp"
 55 #include "runtime/signature.hpp"
 56 #include "utilities/macros.hpp"
 57 

151     // Create the shared symbols, but not in _shared_ci_metadata.
152     for (auto index : EnumRange<vmSymbolID>{}) {
153       Symbol* vmsym = vmSymbols::symbol_at(index);
154       assert(vmSymbols::find_sid(vmsym) == index, "1-1 mapping");
155       ciSymbol* sym = new (_arena) ciSymbol(vmsym, index);
156       init_ident_of(sym);
157       _shared_ci_symbols[vmSymbols::as_int(index)] = sym;
158     }
159 #ifdef ASSERT
160     for (auto index : EnumRange<vmSymbolID>{}) {
161       Symbol* vmsym = vmSymbols::symbol_at(index);
162       ciSymbol* sym = vm_symbol_at(index);
163       assert(sym->get_symbol() == vmsym, "oop must match");
164     }
165     assert(ciSymbols::void_class_signature()->get_symbol() == vmSymbols::void_class_signature(), "spot check");
166 #endif
167   }
168 
169   for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
170     BasicType t = (BasicType)i;
171     if (type2name(t) != nullptr && !is_reference_type(t) &&
172         t != T_NARROWOOP && t != T_NARROWKLASS) {
173       ciType::_basic_types[t] = new (_arena) ciType(t);
174       init_ident_of(ciType::_basic_types[t]);
175     }
176   }
177 
178   ciEnv::_null_object_instance = new (_arena) ciNullObject();
179   init_ident_of(ciEnv::_null_object_instance);
180 
181 #define VM_CLASS_DEFN(name, ignore_s)                              \
182   if (vmClasses::name##_is_loaded()) \
183     ciEnv::_##name = get_metadata(vmClasses::name())->as_instance_klass();
184 
185   VM_CLASSES_DO(VM_CLASS_DEFN)
186 #undef VM_CLASS_DEFN
187 
188   for (int len = -1; len != _ci_metadata.length(); ) {
189     len = _ci_metadata.length();
190     for (int i2 = 0; i2 < len; i2++) {
191       ciMetadata* obj = _ci_metadata.at(i2);

382 //
383 // Create a new ciObject from an oop.
384 //
385 // Implementation note: this functionality could be virtual behavior
386 // of the oop itself.  For now, we explicitly marshal the object.
387 ciObject* ciObjectFactory::create_new_object(oop o) {
388   EXCEPTION_CONTEXT;
389 
390   if (o->is_instance()) {
391     instanceHandle h_i(THREAD, (instanceOop)o);
392     if (java_lang_invoke_CallSite::is_instance(o))
393       return new (arena()) ciCallSite(h_i);
394     else if (java_lang_invoke_MemberName::is_instance(o))
395       return new (arena()) ciMemberName(h_i);
396     else if (java_lang_invoke_MethodHandle::is_instance(o))
397       return new (arena()) ciMethodHandle(h_i);
398     else if (java_lang_invoke_MethodType::is_instance(o))
399       return new (arena()) ciMethodType(h_i);
400     else
401       return new (arena()) ciInstance(h_i);
402   } else if (o->is_objArray()) {
403     objArrayHandle h_oa(THREAD, (objArrayOop)o);
404     return new (arena()) ciObjArray(h_oa);
405   } else if (o->is_typeArray()) {
406     typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
407     return new (arena()) ciTypeArray(h_ta);



408   }
409 
410   // The oop is of some type not supported by the compiler interface.
411   ShouldNotReachHere();
412   return nullptr;
413 }
414 
415 // ------------------------------------------------------------------
416 // ciObjectFactory::create_new_metadata
417 //
418 // Create a new ciMetadata from a Metadata*.
419 //
420 // Implementation note: in order to keep Metadata live, an auxiliary ciObject
421 // is used, which points to it's holder.
422 ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
423   EXCEPTION_CONTEXT;
424 
425   if (o->is_klass()) {
426     Klass* k = (Klass*)o;
427     if (k->is_instance_klass()) {


428       assert(!ReplayCompiles || ciReplay::no_replay_state() || !ciReplay::is_klass_unresolved((InstanceKlass*)k), "must be whitelisted for replay compilation");
429       return new (arena()) ciInstanceKlass(k);
430     } else if (k->is_objArray_klass()) {
431       return new (arena()) ciObjArrayKlass(k);






432     } else if (k->is_typeArray_klass()) {
433       return new (arena()) ciTypeArrayKlass(k);
434     }
435   } else if (o->is_method()) {
436     methodHandle h_m(THREAD, (Method*)o);
437     ciEnv *env = CURRENT_THREAD_ENV;
438     ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder());
439     return new (arena()) ciMethod(h_m, holder);
440   } else if (o->is_methodData()) {
441     // Hold methodHandle alive - might not be necessary ???
442     methodHandle h_m(THREAD, ((MethodData*)o)->method());
443     return new (arena()) ciMethodData((MethodData*)o);
444   }
445 
446   // The Metadata* is of some type not supported by the compiler interface.
447   ShouldNotReachHere();
448   return nullptr;
449 }
450 
451 //------------------------------------------------------------------

646 
647 //------------------------------------------------------------------
648 // ciObjectFactory::get_return_address
649 //
650 // Get a ciReturnAddress for a specified bci.
651 ciReturnAddress* ciObjectFactory::get_return_address(int bci) {
652   for (int i = 0; i < _return_addresses.length(); i++) {
653     ciReturnAddress* entry = _return_addresses.at(i);
654     if (entry->bci() == bci) {
655       // We've found a match.
656       return entry;
657     }
658   }
659 
660   ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci);
661   init_ident_of(new_ret_addr);
662   _return_addresses.append(new_ret_addr);
663   return new_ret_addr;
664 }
665 












666 // ------------------------------------------------------------------
667 // ciObjectFactory::init_ident_of
668 void ciObjectFactory::init_ident_of(ciBaseObject* obj) {
669   obj->set_ident(_next_ident++);
670 }
671 
672 static ciObjectFactory::NonPermObject* emptyBucket = nullptr;
673 
674 // ------------------------------------------------------------------
675 // ciObjectFactory::find_non_perm
676 //
677 // Use a small hash table, hashed on the klass of the key.
678 // If there is no entry in the cache corresponding to this oop, return
679 // the null tail of the bucket into which the oop should be inserted.
680 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(Handle keyHandle) {
681   assert(Universe::heap()->is_in(keyHandle()), "must be");
682   ciMetadata* klass = get_metadata(keyHandle->klass()); // This may safepoint!
683   NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
684   for (NonPermObject* p; (p = (*bp)) != nullptr; bp = &p->next()) {
685     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/instanceKlass.hpp"
 56 #include "oops/oop.inline.hpp"
 57 #include "oops/trainingData.hpp"
 58 #include "runtime/handles.inline.hpp"
 59 #include "runtime/signature.hpp"
 60 #include "utilities/macros.hpp"
 61 

155     // Create the shared symbols, but not in _shared_ci_metadata.
156     for (auto index : EnumRange<vmSymbolID>{}) {
157       Symbol* vmsym = vmSymbols::symbol_at(index);
158       assert(vmSymbols::find_sid(vmsym) == index, "1-1 mapping");
159       ciSymbol* sym = new (_arena) ciSymbol(vmsym, index);
160       init_ident_of(sym);
161       _shared_ci_symbols[vmSymbols::as_int(index)] = sym;
162     }
163 #ifdef ASSERT
164     for (auto index : EnumRange<vmSymbolID>{}) {
165       Symbol* vmsym = vmSymbols::symbol_at(index);
166       ciSymbol* sym = vm_symbol_at(index);
167       assert(sym->get_symbol() == vmsym, "oop must match");
168     }
169     assert(ciSymbols::void_class_signature()->get_symbol() == vmSymbols::void_class_signature(), "spot check");
170 #endif
171   }
172 
173   for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
174     BasicType t = (BasicType)i;
175     if (type2name(t) != nullptr && t != T_FLAT_ELEMENT && !is_reference_type(t) &&
176         t != T_NARROWOOP && t != T_NARROWKLASS) {
177       ciType::_basic_types[t] = new (_arena) ciType(t);
178       init_ident_of(ciType::_basic_types[t]);
179     }
180   }
181 
182   ciEnv::_null_object_instance = new (_arena) ciNullObject();
183   init_ident_of(ciEnv::_null_object_instance);
184 
185 #define VM_CLASS_DEFN(name, ignore_s)                              \
186   if (vmClasses::name##_is_loaded()) \
187     ciEnv::_##name = get_metadata(vmClasses::name())->as_instance_klass();
188 
189   VM_CLASSES_DO(VM_CLASS_DEFN)
190 #undef VM_CLASS_DEFN
191 
192   for (int len = -1; len != _ci_metadata.length(); ) {
193     len = _ci_metadata.length();
194     for (int i2 = 0; i2 < len; i2++) {
195       ciMetadata* obj = _ci_metadata.at(i2);

386 //
387 // Create a new ciObject from an oop.
388 //
389 // Implementation note: this functionality could be virtual behavior
390 // of the oop itself.  For now, we explicitly marshal the object.
391 ciObject* ciObjectFactory::create_new_object(oop o) {
392   EXCEPTION_CONTEXT;
393 
394   if (o->is_instance()) {
395     instanceHandle h_i(THREAD, (instanceOop)o);
396     if (java_lang_invoke_CallSite::is_instance(o))
397       return new (arena()) ciCallSite(h_i);
398     else if (java_lang_invoke_MemberName::is_instance(o))
399       return new (arena()) ciMemberName(h_i);
400     else if (java_lang_invoke_MethodHandle::is_instance(o))
401       return new (arena()) ciMethodHandle(h_i);
402     else if (java_lang_invoke_MethodType::is_instance(o))
403       return new (arena()) ciMethodType(h_i);
404     else
405       return new (arena()) ciInstance(h_i);
406   } else if (o->is_refArray()) {
407     objArrayHandle h_oa(THREAD, (objArrayOop)o);
408     return new (arena()) ciObjArray(h_oa);
409   } else if (o->is_typeArray()) {
410     typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
411     return new (arena()) ciTypeArray(h_ta);
412   } else if (o->is_flatArray()) {
413     flatArrayHandle h_ta(THREAD, (flatArrayOop)o);
414     return new (arena()) ciFlatArray(h_ta);
415   }
416 
417   // The oop is of some type not supported by the compiler interface.
418   ShouldNotReachHere();
419   return nullptr;
420 }
421 
422 // ------------------------------------------------------------------
423 // ciObjectFactory::create_new_metadata
424 //
425 // Create a new ciMetadata from a Metadata*.
426 //
427 // Implementation note: in order to keep Metadata live, an auxiliary ciObject
428 // is used, which points to it's holder.
429 ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
430   EXCEPTION_CONTEXT;
431 
432   if (o->is_klass()) {
433     Klass* k = (Klass*)o;
434     if (k->is_inline_klass()) {
435       return new (arena()) ciInlineKlass(k);
436     } else if (k->is_instance_klass()) {
437       assert(!ReplayCompiles || ciReplay::no_replay_state() || !ciReplay::is_klass_unresolved((InstanceKlass*)k), "must be whitelisted for replay compilation");
438       return new (arena()) ciInstanceKlass(k);
439     } else if (k->is_objArray_klass()) {
440       if (k->is_flatArray_klass()) {
441         return new (arena()) ciFlatArrayKlass(k);
442       } else if (k->is_refArray_klass()) {
443         return new (arena()) ciRefArrayKlass(k);
444       } else {
445         return new (arena()) ciObjArrayKlass(k);
446       }
447     } else if (k->is_typeArray_klass()) {
448       return new (arena()) ciTypeArrayKlass(k);
449     }
450   } else if (o->is_method()) {
451     methodHandle h_m(THREAD, (Method*)o);
452     ciEnv *env = CURRENT_THREAD_ENV;
453     ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder());
454     return new (arena()) ciMethod(h_m, holder);
455   } else if (o->is_methodData()) {
456     // Hold methodHandle alive - might not be necessary ???
457     methodHandle h_m(THREAD, ((MethodData*)o)->method());
458     return new (arena()) ciMethodData((MethodData*)o);
459   }
460 
461   // The Metadata* is of some type not supported by the compiler interface.
462   ShouldNotReachHere();
463   return nullptr;
464 }
465 
466 //------------------------------------------------------------------

661 
662 //------------------------------------------------------------------
663 // ciObjectFactory::get_return_address
664 //
665 // Get a ciReturnAddress for a specified bci.
666 ciReturnAddress* ciObjectFactory::get_return_address(int bci) {
667   for (int i = 0; i < _return_addresses.length(); i++) {
668     ciReturnAddress* entry = _return_addresses.at(i);
669     if (entry->bci() == bci) {
670       // We've found a match.
671       return entry;
672     }
673   }
674 
675   ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci);
676   init_ident_of(new_ret_addr);
677   _return_addresses.append(new_ret_addr);
678   return new_ret_addr;
679 }
680 
681 ciWrapper* ciObjectFactory::make_early_larval_wrapper(ciType* type) {
682   ciWrapper* wrapper = new (arena()) ciWrapper(type, ciWrapper::EarlyLarval);
683   init_ident_of(wrapper);
684   return wrapper;
685 }
686 
687 ciWrapper* ciObjectFactory::make_null_free_wrapper(ciType* type) {
688   ciWrapper* wrapper = new (arena()) ciWrapper(type, ciWrapper::NullFree);
689   init_ident_of(wrapper);
690   return wrapper;
691 }
692 
693 // ------------------------------------------------------------------
694 // ciObjectFactory::init_ident_of
695 void ciObjectFactory::init_ident_of(ciBaseObject* obj) {
696   obj->set_ident(_next_ident++);
697 }
698 
699 static ciObjectFactory::NonPermObject* emptyBucket = nullptr;
700 
701 // ------------------------------------------------------------------
702 // ciObjectFactory::find_non_perm
703 //
704 // Use a small hash table, hashed on the klass of the key.
705 // If there is no entry in the cache corresponding to this oop, return
706 // the null tail of the bucket into which the oop should be inserted.
707 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(Handle keyHandle) {
708   assert(Universe::heap()->is_in(keyHandle()), "must be");
709   ciMetadata* klass = get_metadata(keyHandle->klass()); // This may safepoint!
710   NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
711   for (NonPermObject* p; (p = (*bp)) != nullptr; bp = &p->next()) {
712     if (is_equal(p, keyHandle()))  break;
< prev index next >