< prev index next >

src/hotspot/share/ci/ciObjectFactory.cpp

Print this page

  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 "precompiled.hpp"
 26 #include "ci/ciCallSite.hpp"


 27 #include "ci/ciInstance.hpp"
 28 #include "ci/ciInstanceKlass.hpp"
 29 #include "ci/ciMemberName.hpp"
 30 #include "ci/ciMethod.hpp"
 31 #include "ci/ciMethodData.hpp"
 32 #include "ci/ciMethodHandle.hpp"
 33 #include "ci/ciMethodType.hpp"
 34 #include "ci/ciNullObject.hpp"
 35 #include "ci/ciObjArray.hpp"
 36 #include "ci/ciObjArrayKlass.hpp"
 37 #include "ci/ciObject.hpp"
 38 #include "ci/ciObjectFactory.hpp"
 39 #include "ci/ciReplay.hpp"
 40 #include "ci/ciSymbol.hpp"
 41 #include "ci/ciSymbols.hpp"
 42 #include "ci/ciTypeArray.hpp"
 43 #include "ci/ciTypeArrayKlass.hpp"
 44 #include "ci/ciUtilities.inline.hpp"

 45 #include "classfile/javaClasses.inline.hpp"
 46 #include "classfile/vmClasses.hpp"
 47 #include "compiler/compiler_globals.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 "runtime/handles.inline.hpp"
 53 #include "runtime/signature.hpp"
 54 #include "utilities/macros.hpp"
 55 
 56 // ciObjectFactory
 57 //
 58 // This class handles requests for the creation of new instances
 59 // of ciObject and its subclasses.  It contains a caching mechanism
 60 // which ensures that for each oop, at most one ciObject is created.
 61 // This invariant allows more efficient implementation of ciObject.
 62 //
 63 // Implementation note: the oop->ciObject mapping is represented as
 64 // a table stored in an array.  Even though objects are moved

348   EXCEPTION_CONTEXT;
349 
350   if (o->is_instance()) {
351     instanceHandle h_i(THREAD, (instanceOop)o);
352     if (java_lang_invoke_CallSite::is_instance(o))
353       return new (arena()) ciCallSite(h_i);
354     else if (java_lang_invoke_MemberName::is_instance(o))
355       return new (arena()) ciMemberName(h_i);
356     else if (java_lang_invoke_MethodHandle::is_instance(o))
357       return new (arena()) ciMethodHandle(h_i);
358     else if (java_lang_invoke_MethodType::is_instance(o))
359       return new (arena()) ciMethodType(h_i);
360     else
361       return new (arena()) ciInstance(h_i);
362   } else if (o->is_objArray()) {
363     objArrayHandle h_oa(THREAD, (objArrayOop)o);
364     return new (arena()) ciObjArray(h_oa);
365   } else if (o->is_typeArray()) {
366     typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
367     return new (arena()) ciTypeArray(h_ta);



368   }
369 
370   // The oop is of some type not supported by the compiler interface.
371   ShouldNotReachHere();
372   return nullptr;
373 }
374 
375 // ------------------------------------------------------------------
376 // ciObjectFactory::create_new_metadata
377 //
378 // Create a new ciMetadata from a Metadata*.
379 //
380 // Implementation note: in order to keep Metadata live, an auxiliary ciObject
381 // is used, which points to it's holder.
382 ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
383   EXCEPTION_CONTEXT;
384 
385   if (o->is_klass()) {
386     Klass* k = (Klass*)o;
387     if (k->is_instance_klass()) {


388       assert(!ReplayCompiles || ciReplay::no_replay_state() || !ciReplay::is_klass_unresolved((InstanceKlass*)k), "must be whitelisted for replay compilation");
389       return new (arena()) ciInstanceKlass(k);


390     } else if (k->is_objArray_klass()) {
391       return new (arena()) ciObjArrayKlass(k);
392     } else if (k->is_typeArray_klass()) {
393       return new (arena()) ciTypeArrayKlass(k);
394     }
395   } else if (o->is_method()) {
396     methodHandle h_m(THREAD, (Method*)o);
397     ciEnv *env = CURRENT_THREAD_ENV;
398     ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder());
399     return new (arena()) ciMethod(h_m, holder);
400   } else if (o->is_methodData()) {
401     // Hold methodHandle alive - might not be necessary ???
402     methodHandle h_m(THREAD, ((MethodData*)o)->method());
403     return new (arena()) ciMethodData((MethodData*)o);
404   }
405 
406   // The Metadata* is of some type not supported by the compiler interface.
407   ShouldNotReachHere();
408   return nullptr;
409 }

610 
611 //------------------------------------------------------------------
612 // ciObjectFactory::get_return_address
613 //
614 // Get a ciReturnAddress for a specified bci.
615 ciReturnAddress* ciObjectFactory::get_return_address(int bci) {
616   for (int i = 0; i < _return_addresses.length(); i++) {
617     ciReturnAddress* entry = _return_addresses.at(i);
618     if (entry->bci() == bci) {
619       // We've found a match.
620       return entry;
621     }
622   }
623 
624   ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci);
625   init_ident_of(new_ret_addr);
626   _return_addresses.append(new_ret_addr);
627   return new_ret_addr;
628 }
629 






630 // ------------------------------------------------------------------
631 // ciObjectFactory::init_ident_of
632 void ciObjectFactory::init_ident_of(ciBaseObject* obj) {
633   obj->set_ident(_next_ident++);
634 }
635 
636 static ciObjectFactory::NonPermObject* emptyBucket = nullptr;
637 
638 // ------------------------------------------------------------------
639 // ciObjectFactory::find_non_perm
640 //
641 // Use a small hash table, hashed on the klass of the key.
642 // If there is no entry in the cache corresponding to this oop, return
643 // the null tail of the bucket into which the oop should be inserted.
644 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) {
645   assert(Universe::heap()->is_in(key), "must be");
646   ciMetadata* klass = get_metadata(key->klass());
647   NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
648   for (NonPermObject* p; (p = (*bp)) != nullptr; bp = &p->next()) {
649     if (is_equal(p, key))  break;

  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 "precompiled.hpp"
 26 #include "ci/ciCallSite.hpp"
 27 #include "ci/ciFlatArray.hpp"
 28 #include "ci/ciFlatArrayKlass.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 "ci/ciInlineKlass.hpp"
 48 #include "classfile/javaClasses.inline.hpp"
 49 #include "classfile/vmClasses.hpp"
 50 #include "compiler/compiler_globals.hpp"
 51 #include "gc/shared/collectedHeap.inline.hpp"
 52 #include "memory/allocation.inline.hpp"
 53 #include "memory/universe.hpp"
 54 #include "oops/oop.inline.hpp"
 55 #include "runtime/handles.inline.hpp"
 56 #include "runtime/signature.hpp"
 57 #include "utilities/macros.hpp"
 58 
 59 // ciObjectFactory
 60 //
 61 // This class handles requests for the creation of new instances
 62 // of ciObject and its subclasses.  It contains a caching mechanism
 63 // which ensures that for each oop, at most one ciObject is created.
 64 // This invariant allows more efficient implementation of ciObject.
 65 //
 66 // Implementation note: the oop->ciObject mapping is represented as
 67 // a table stored in an array.  Even though objects are moved

351   EXCEPTION_CONTEXT;
352 
353   if (o->is_instance()) {
354     instanceHandle h_i(THREAD, (instanceOop)o);
355     if (java_lang_invoke_CallSite::is_instance(o))
356       return new (arena()) ciCallSite(h_i);
357     else if (java_lang_invoke_MemberName::is_instance(o))
358       return new (arena()) ciMemberName(h_i);
359     else if (java_lang_invoke_MethodHandle::is_instance(o))
360       return new (arena()) ciMethodHandle(h_i);
361     else if (java_lang_invoke_MethodType::is_instance(o))
362       return new (arena()) ciMethodType(h_i);
363     else
364       return new (arena()) ciInstance(h_i);
365   } else if (o->is_objArray()) {
366     objArrayHandle h_oa(THREAD, (objArrayOop)o);
367     return new (arena()) ciObjArray(h_oa);
368   } else if (o->is_typeArray()) {
369     typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
370     return new (arena()) ciTypeArray(h_ta);
371   } else if (o->is_flatArray()) {
372     flatArrayHandle h_ta(THREAD, (flatArrayOop)o);
373     return new (arena()) ciFlatArray(h_ta);
374   }
375 
376   // The oop is of some type not supported by the compiler interface.
377   ShouldNotReachHere();
378   return nullptr;
379 }
380 
381 // ------------------------------------------------------------------
382 // ciObjectFactory::create_new_metadata
383 //
384 // Create a new ciMetadata from a Metadata*.
385 //
386 // Implementation note: in order to keep Metadata live, an auxiliary ciObject
387 // is used, which points to it's holder.
388 ciMetadata* ciObjectFactory::create_new_metadata(Metadata* o) {
389   EXCEPTION_CONTEXT;
390 
391   if (o->is_klass()) {
392     Klass* k = (Klass*)o;
393     if (k->is_inline_klass()) {
394       return new (arena()) ciInlineKlass(k);
395     } else if (k->is_instance_klass()) {
396       assert(!ReplayCompiles || ciReplay::no_replay_state() || !ciReplay::is_klass_unresolved((InstanceKlass*)k), "must be whitelisted for replay compilation");
397       return new (arena()) ciInstanceKlass(k);
398     } else if (k->is_flatArray_klass()) {
399       return new (arena()) ciFlatArrayKlass(k);
400     } else if (k->is_objArray_klass()) {
401       return new (arena()) ciObjArrayKlass(k);
402     } else if (k->is_typeArray_klass()) {
403       return new (arena()) ciTypeArrayKlass(k);
404     }
405   } else if (o->is_method()) {
406     methodHandle h_m(THREAD, (Method*)o);
407     ciEnv *env = CURRENT_THREAD_ENV;
408     ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder());
409     return new (arena()) ciMethod(h_m, holder);
410   } else if (o->is_methodData()) {
411     // Hold methodHandle alive - might not be necessary ???
412     methodHandle h_m(THREAD, ((MethodData*)o)->method());
413     return new (arena()) ciMethodData((MethodData*)o);
414   }
415 
416   // The Metadata* is of some type not supported by the compiler interface.
417   ShouldNotReachHere();
418   return nullptr;
419 }

620 
621 //------------------------------------------------------------------
622 // ciObjectFactory::get_return_address
623 //
624 // Get a ciReturnAddress for a specified bci.
625 ciReturnAddress* ciObjectFactory::get_return_address(int bci) {
626   for (int i = 0; i < _return_addresses.length(); i++) {
627     ciReturnAddress* entry = _return_addresses.at(i);
628     if (entry->bci() == bci) {
629       // We've found a match.
630       return entry;
631     }
632   }
633 
634   ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci);
635   init_ident_of(new_ret_addr);
636   _return_addresses.append(new_ret_addr);
637   return new_ret_addr;
638 }
639 
640 ciWrapper* ciObjectFactory::make_null_free_wrapper(ciType* type) {
641   ciWrapper* wrapper = new (arena()) ciWrapper(type);
642   init_ident_of(wrapper);
643   return wrapper;
644 }
645 
646 // ------------------------------------------------------------------
647 // ciObjectFactory::init_ident_of
648 void ciObjectFactory::init_ident_of(ciBaseObject* obj) {
649   obj->set_ident(_next_ident++);
650 }
651 
652 static ciObjectFactory::NonPermObject* emptyBucket = nullptr;
653 
654 // ------------------------------------------------------------------
655 // ciObjectFactory::find_non_perm
656 //
657 // Use a small hash table, hashed on the klass of the key.
658 // If there is no entry in the cache corresponding to this oop, return
659 // the null tail of the bucket into which the oop should be inserted.
660 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) {
661   assert(Universe::heap()->is_in(key), "must be");
662   ciMetadata* klass = get_metadata(key->klass());
663   NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
664   for (NonPermObject* p; (p = (*bp)) != nullptr; bp = &p->next()) {
665     if (is_equal(p, key))  break;
< prev index next >