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

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 

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/ciReplay.hpp"
 42 #include "ci/ciSymbol.hpp"
 43 #include "ci/ciSymbols.hpp"
 44 #include "ci/ciTypeArray.hpp"
 45 #include "ci/ciTypeArrayKlass.hpp"
 46 #include "ci/ciUtilities.inline.hpp"
 47 #include "classfile/javaClasses.inline.hpp"
 48 #include "classfile/vmClasses.hpp"

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

361 //
362 // Create a new ciObject from an oop.
363 //
364 // Implementation note: this functionality could be virtual behavior
365 // of the oop itself.  For now, we explicitly marshal the object.
366 ciObject* ciObjectFactory::create_new_object(oop o) {
367   EXCEPTION_CONTEXT;
368 
369   if (o->is_instance()) {
370     instanceHandle h_i(THREAD, (instanceOop)o);
371     if (java_lang_invoke_CallSite::is_instance(o))
372       return new (arena()) ciCallSite(h_i);
373     else if (java_lang_invoke_MemberName::is_instance(o))
374       return new (arena()) ciMemberName(h_i);
375     else if (java_lang_invoke_MethodHandle::is_instance(o))
376       return new (arena()) ciMethodHandle(h_i);
377     else if (java_lang_invoke_MethodType::is_instance(o))
378       return new (arena()) ciMethodType(h_i);
379     else
380       return new (arena()) ciInstance(h_i);
381   } else if (o->is_refArray()) {
382     objArrayHandle h_oa(THREAD, (objArrayOop)o);
383     return new (arena()) ciObjArray(h_oa);
384   } else if (o->is_typeArray()) {
385     typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
386     return new (arena()) ciTypeArray(h_ta);
387   } else if (o->is_flatArray()) {
388     flatArrayHandle h_ta(THREAD, (flatArrayOop)o);
389     return new (arena()) ciFlatArray(h_ta);
390   }
391 
392   // The oop is of some type not supported by the compiler interface.
393   ShouldNotReachHere();
394   return nullptr;
395 }
396 
397 // ------------------------------------------------------------------
398 // ciObjectFactory::create_new_metadata
399 //
400 // Create a new ciMetadata from a Metadata*.
401 //
402 // Implementation note: in order to keep Metadata live, an auxiliary ciObject
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_inline_klass()) {
410       return new (arena()) ciInlineKlass(k);
411     } else if (k->is_instance_klass()) {
412       assert(!ReplayCompiles || ciReplay::no_replay_state() || !ciReplay::is_klass_unresolved((InstanceKlass*)k), "must be whitelisted for replay compilation");
413       return new (arena()) ciInstanceKlass(k);
414     } else if (k->is_flatArray_klass()) {
415       return new (arena()) ciFlatArrayKlass(k);
416     } else if (k->is_refArray_klass() || k->is_objArray_klass()) {
417       return new (arena()) ciObjArrayKlass(k);
418     } else if (k->is_typeArray_klass()) {
419       return new (arena()) ciTypeArrayKlass(k);
420     }
421   } else if (o->is_method()) {
422     methodHandle h_m(THREAD, (Method*)o);
423     ciEnv *env = CURRENT_THREAD_ENV;
424     ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder());
425     return new (arena()) ciMethod(h_m, holder);
426   } else if (o->is_methodData()) {
427     // Hold methodHandle alive - might not be necessary ???
428     methodHandle h_m(THREAD, ((MethodData*)o)->method());
429     return new (arena()) ciMethodData((MethodData*)o);
430   }
431 
432   // The Metadata* is of some type not supported by the compiler interface.
433   ShouldNotReachHere();
434   return nullptr;
435 }
436 

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