< 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 NULL;
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 NULL;
409 }

479       return entry;
480     }
481   }
482 
483   if (!create_if_not_found)
484     return NULL;
485 
486   // This is a new unloaded klass.  Create it and stick it in
487   // the cache.
488   ciKlass* new_klass = NULL;
489 
490   // Two cases: this is an unloaded ObjArrayKlass or an
491   // unloaded InstanceKlass.  Deal with both.
492   if (name->char_at(0) == JVM_SIGNATURE_ARRAY) {
493     // Decompose the name.'
494     SignatureStream ss(name->get_symbol(), false);
495     int dimension = ss.skip_array_prefix();  // skip all '['s
496     BasicType element_type = ss.type();
497     assert(element_type != T_ARRAY, "unsuccessful decomposition");
498     ciKlass* element_klass = NULL;
499     if (element_type == T_OBJECT) {
500       ciEnv *env = CURRENT_THREAD_ENV;
501       ciSymbol* ci_name = env->get_symbol(ss.as_symbol());
502       element_klass =
503         env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass();
504     } else {
505       assert(dimension > 1, "one dimensional type arrays are always loaded.");
506 
507       // The type array itself takes care of one of the dimensions.
508       dimension--;
509 
510       // The element klass is a TypeArrayKlass.
511       element_klass = ciTypeArrayKlass::make(element_type);
512     }
513     new_klass = new (arena()) ciObjArrayKlass(name, element_klass, dimension);
514   } else {
515     jobject loader_handle = NULL;
516     jobject domain_handle = NULL;
517     if (accessing_klass != NULL) {
518       loader_handle = accessing_klass->loader_handle();
519       domain_handle = accessing_klass->protection_domain_handle();

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 = NULL;
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)) != NULL; 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 NULL;
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 NULL;
419 }

489       return entry;
490     }
491   }
492 
493   if (!create_if_not_found)
494     return NULL;
495 
496   // This is a new unloaded klass.  Create it and stick it in
497   // the cache.
498   ciKlass* new_klass = NULL;
499 
500   // Two cases: this is an unloaded ObjArrayKlass or an
501   // unloaded InstanceKlass.  Deal with both.
502   if (name->char_at(0) == JVM_SIGNATURE_ARRAY) {
503     // Decompose the name.'
504     SignatureStream ss(name->get_symbol(), false);
505     int dimension = ss.skip_array_prefix();  // skip all '['s
506     BasicType element_type = ss.type();
507     assert(element_type != T_ARRAY, "unsuccessful decomposition");
508     ciKlass* element_klass = NULL;
509     if (element_type == T_OBJECT || element_type == T_PRIMITIVE_OBJECT) {
510       ciEnv *env = CURRENT_THREAD_ENV;
511       ciSymbol* ci_name = env->get_symbol(ss.as_symbol());
512       element_klass =
513         env->get_klass_by_name(accessing_klass, ci_name, false)->as_instance_klass();
514     } else {
515       assert(dimension > 1, "one dimensional type arrays are always loaded.");
516 
517       // The type array itself takes care of one of the dimensions.
518       dimension--;
519 
520       // The element klass is a TypeArrayKlass.
521       element_klass = ciTypeArrayKlass::make(element_type);
522     }
523     new_klass = new (arena()) ciObjArrayKlass(name, element_klass, dimension);
524   } else {
525     jobject loader_handle = NULL;
526     jobject domain_handle = NULL;
527     if (accessing_klass != NULL) {
528       loader_handle = accessing_klass->loader_handle();
529       domain_handle = accessing_klass->protection_domain_handle();

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 = NULL;
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)) != NULL; bp = &p->next()) {
665     if (is_equal(p, key))  break;
< prev index next >