< 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

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



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


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


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

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

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






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

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

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

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