< 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/ciNativeEntryPoint.hpp"
 31 #include "ci/ciMethod.hpp"
 32 #include "ci/ciMethodData.hpp"
 33 #include "ci/ciMethodHandle.hpp"
 34 #include "ci/ciMethodType.hpp"
 35 #include "ci/ciNullObject.hpp"
 36 #include "ci/ciObjArray.hpp"
 37 #include "ci/ciObjArrayKlass.hpp"
 38 #include "ci/ciObject.hpp"
 39 #include "ci/ciObjectFactory.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

341   if (o->is_instance()) {
342     instanceHandle h_i(THREAD, (instanceOop)o);
343     if (java_lang_invoke_CallSite::is_instance(o))
344       return new (arena()) ciCallSite(h_i);
345     else if (java_lang_invoke_MemberName::is_instance(o))
346       return new (arena()) ciMemberName(h_i);
347     else if (jdk_internal_invoke_NativeEntryPoint::is_instance(o))
348       return new (arena()) ciNativeEntryPoint(h_i);
349     else if (java_lang_invoke_MethodHandle::is_instance(o))
350       return new (arena()) ciMethodHandle(h_i);
351     else if (java_lang_invoke_MethodType::is_instance(o))
352       return new (arena()) ciMethodType(h_i);
353     else
354       return new (arena()) ciInstance(h_i);
355   } else if (o->is_objArray()) {
356     objArrayHandle h_oa(THREAD, (objArrayOop)o);
357     return new (arena()) ciObjArray(h_oa);
358   } else if (o->is_typeArray()) {
359     typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
360     return new (arena()) ciTypeArray(h_ta);



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


381       return new (arena()) ciInstanceKlass(k);


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

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

602 
603 //------------------------------------------------------------------
604 // ciObjectFactory::get_return_address
605 //
606 // Get a ciReturnAddress for a specified bci.
607 ciReturnAddress* ciObjectFactory::get_return_address(int bci) {
608   for (int i = 0; i < _return_addresses.length(); i++) {
609     ciReturnAddress* entry = _return_addresses.at(i);
610     if (entry->bci() == bci) {
611       // We've found a match.
612       return entry;
613     }
614   }
615 
616   ciReturnAddress* new_ret_addr = new (arena()) ciReturnAddress(bci);
617   init_ident_of(new_ret_addr);
618   _return_addresses.append(new_ret_addr);
619   return new_ret_addr;
620 }
621 






622 // ------------------------------------------------------------------
623 // ciObjectFactory::init_ident_of
624 void ciObjectFactory::init_ident_of(ciBaseObject* obj) {
625   obj->set_ident(_next_ident++);
626 }
627 
628 static ciObjectFactory::NonPermObject* emptyBucket = NULL;
629 
630 // ------------------------------------------------------------------
631 // ciObjectFactory::find_non_perm
632 //
633 // Use a small hash table, hashed on the klass of the key.
634 // If there is no entry in the cache corresponding to this oop, return
635 // the null tail of the bucket into which the oop should be inserted.
636 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) {
637   assert(Universe::heap()->is_in(key), "must be");
638   ciMetadata* klass = get_metadata(key->klass());
639   NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
640   for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) {
641     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/ciNativeEntryPoint.hpp"
 33 #include "ci/ciMethod.hpp"
 34 #include "ci/ciMethodData.hpp"
 35 #include "ci/ciMethodHandle.hpp"
 36 #include "ci/ciMethodType.hpp"
 37 #include "ci/ciNullObject.hpp"
 38 #include "ci/ciObjArray.hpp"
 39 #include "ci/ciObjArrayKlass.hpp"
 40 #include "ci/ciObject.hpp"
 41 #include "ci/ciObjectFactory.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

344   if (o->is_instance()) {
345     instanceHandle h_i(THREAD, (instanceOop)o);
346     if (java_lang_invoke_CallSite::is_instance(o))
347       return new (arena()) ciCallSite(h_i);
348     else if (java_lang_invoke_MemberName::is_instance(o))
349       return new (arena()) ciMemberName(h_i);
350     else if (jdk_internal_invoke_NativeEntryPoint::is_instance(o))
351       return new (arena()) ciNativeEntryPoint(h_i);
352     else if (java_lang_invoke_MethodHandle::is_instance(o))
353       return new (arena()) ciMethodHandle(h_i);
354     else if (java_lang_invoke_MethodType::is_instance(o))
355       return new (arena()) ciMethodType(h_i);
356     else
357       return new (arena()) ciInstance(h_i);
358   } else if (o->is_objArray()) {
359     objArrayHandle h_oa(THREAD, (objArrayOop)o);
360     return new (arena()) ciObjArray(h_oa);
361   } else if (o->is_typeArray()) {
362     typeArrayHandle h_ta(THREAD, (typeArrayOop)o);
363     return new (arena()) ciTypeArray(h_ta);
364   } else if (o->is_flatArray()) {
365     flatArrayHandle h_ta(THREAD, (flatArrayOop)o);
366     return new (arena()) ciFlatArray(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_inline_klass()) {
387       return new (arena()) ciInlineKlass(k);
388     } else if (k->is_instance_klass()) {
389       return new (arena()) ciInstanceKlass(k);
390     } else if (k->is_flatArray_klass()) {
391       return new (arena()) ciFlatArrayKlass(k);
392     } else if (k->is_objArray_klass()) {
393       return new (arena()) ciObjArrayKlass(k);
394     } else if (k->is_typeArray_klass()) {
395       return new (arena()) ciTypeArrayKlass(k);
396     }
397   } else if (o->is_method()) {
398     methodHandle h_m(THREAD, (Method*)o);
399     ciEnv *env = CURRENT_THREAD_ENV;
400     ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder());
401     return new (arena()) ciMethod(h_m, holder);
402   } else if (o->is_methodData()) {
403     // Hold methodHandle alive - might not be necessary ???
404     methodHandle h_m(THREAD, ((MethodData*)o)->method());
405     return new (arena()) ciMethodData((MethodData*)o);
406   }
407 
408   // The Metadata* is of some type not supported by the compiler interface.
409   ShouldNotReachHere();
410   return NULL;
411 }

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

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