< 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       assert(!ReplayCompiles || ciReplay::no_replay_state() || !ciReplay::is_klass_unresolved((InstanceKlass*)k), "must be whitelisted for replay compilation");
382       return new (arena()) ciInstanceKlass(k);


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

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

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






623 // ------------------------------------------------------------------
624 // ciObjectFactory::init_ident_of
625 void ciObjectFactory::init_ident_of(ciBaseObject* obj) {
626   obj->set_ident(_next_ident++);
627 }
628 
629 static ciObjectFactory::NonPermObject* emptyBucket = NULL;
630 
631 // ------------------------------------------------------------------
632 // ciObjectFactory::find_non_perm
633 //
634 // Use a small hash table, hashed on the klass of the key.
635 // If there is no entry in the cache corresponding to this oop, return
636 // the null tail of the bucket into which the oop should be inserted.
637 ciObjectFactory::NonPermObject* &ciObjectFactory::find_non_perm(oop key) {
638   assert(Universe::heap()->is_in(key), "must be");
639   ciMetadata* klass = get_metadata(key->klass());
640   NonPermObject* *bp = &_non_perm_bucket[(unsigned) klass->hash() % NON_PERM_BUCKETS];
641   for (NonPermObject* p; (p = (*bp)) != NULL; bp = &p->next()) {
642     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       assert(!ReplayCompiles || ciReplay::no_replay_state() || !ciReplay::is_klass_unresolved((InstanceKlass*)k), "must be whitelisted for replay compilation");
390       return new (arena()) ciInstanceKlass(k);
391     } else if (k->is_flatArray_klass()) {
392       return new (arena()) ciFlatArrayKlass(k);
393     } else if (k->is_objArray_klass()) {
394       return new (arena()) ciObjArrayKlass(k);
395     } else if (k->is_typeArray_klass()) {
396       return new (arena()) ciTypeArrayKlass(k);
397     }
398   } else if (o->is_method()) {
399     methodHandle h_m(THREAD, (Method*)o);
400     ciEnv *env = CURRENT_THREAD_ENV;
401     ciInstanceKlass* holder = env->get_instance_klass(h_m()->method_holder());
402     return new (arena()) ciMethod(h_m, holder);
403   } else if (o->is_methodData()) {
404     // Hold methodHandle alive - might not be necessary ???
405     methodHandle h_m(THREAD, ((MethodData*)o)->method());
406     return new (arena()) ciMethodData((MethodData*)o);
407   }
408 
409   // The Metadata* is of some type not supported by the compiler interface.
410   ShouldNotReachHere();
411   return NULL;
412 }

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

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