< prev index next >

src/hotspot/share/ci/ciObjectFactory.cpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   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/ciSymbol.hpp"
  40 #include "ci/ciTypeArray.hpp"
  41 #include "ci/ciTypeArrayKlass.hpp"
  42 #include "ci/ciUtilities.inline.hpp"


  43 #include "classfile/javaClasses.inline.hpp"
  44 #include "classfile/systemDictionary.hpp"
  45 #include "gc/shared/collectedHeap.inline.hpp"
  46 #include "memory/allocation.inline.hpp"
  47 #include "oops/oop.inline.hpp"
  48 #include "runtime/fieldType.hpp"
  49 #include "runtime/handles.inline.hpp"
  50 #include "utilities/macros.hpp"
  51 
  52 // ciObjectFactory
  53 //
  54 // This class handles requests for the creation of new instances
  55 // of ciObject and its subclasses.  It contains a caching mechanism
  56 // which ensures that for each oop, at most one ciObject is created.
  57 // This invariant allows more efficient implementation of ciObject.
  58 //
  59 // Implementation note: the oop->ciObject mapping is represented as
  60 // a table stored in an array.  Even though objects are moved
  61 // by the garbage collector, the compactor preserves their relative
  62 // order; address comparison of oops (in perm space) is safe so long


 131       Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i);
 132       assert(vmSymbols::find_sid(vmsym) == i, "1-1 mapping");
 133       ciSymbol* sym = new (_arena) ciSymbol(vmsym, (vmSymbols::SID) i);
 134       init_ident_of(sym);
 135       _shared_ci_symbols[i] = sym;
 136     }
 137 #ifdef ASSERT
 138     for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) {
 139       Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i);
 140       ciSymbol* sym = vm_symbol_at((vmSymbols::SID) i);
 141       assert(sym->get_symbol() == vmsym, "oop must match");
 142     }
 143     assert(ciSymbol::void_class_signature()->get_symbol() == vmSymbols::void_class_signature(), "spot check");
 144 #endif
 145   }
 146 
 147   _ci_metadata = new (_arena) GrowableArray<ciMetadata*>(_arena, 64, 0, NULL);
 148 
 149   for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
 150     BasicType t = (BasicType)i;
 151     if (type2name(t) != NULL && t != T_OBJECT && t != T_ARRAY && t != T_NARROWOOP && t != T_NARROWKLASS) {

 152       ciType::_basic_types[t] = new (_arena) ciType(t);
 153       init_ident_of(ciType::_basic_types[t]);
 154     }
 155   }
 156 
 157   ciEnv::_null_object_instance = new (_arena) ciNullObject();
 158   init_ident_of(ciEnv::_null_object_instance);
 159 
 160 #define WK_KLASS_DEFN(name, ignore_s)                              \
 161   if (SystemDictionary::name##_is_loaded()) \
 162     ciEnv::_##name = get_metadata(SystemDictionary::name())->as_instance_klass();
 163 
 164   WK_KLASSES_DO(WK_KLASS_DEFN)
 165 #undef WK_KLASS_DEFN
 166 
 167   for (int len = -1; len != _ci_metadata->length(); ) {
 168     len = _ci_metadata->length();
 169     for (int i2 = 0; i2 < len; i2++) {
 170       ciMetadata* obj = _ci_metadata->at(i2);
 171       assert (obj->is_metadata(), "what else would it be?");


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



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


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


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


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


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






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


   1 /*
   2  * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   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/ciValueKlass.hpp"
  30 #include "ci/ciMemberName.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/ciTypeArray.hpp"
  42 #include "ci/ciTypeArrayKlass.hpp"
  43 #include "ci/ciUtilities.inline.hpp"
  44 #include "ci/ciValueArray.hpp"
  45 #include "ci/ciValueArrayKlass.hpp"
  46 #include "classfile/javaClasses.inline.hpp"
  47 #include "classfile/systemDictionary.hpp"
  48 #include "gc/shared/collectedHeap.inline.hpp"
  49 #include "memory/allocation.inline.hpp"
  50 #include "oops/oop.inline.hpp"
  51 #include "runtime/fieldType.hpp"
  52 #include "runtime/handles.inline.hpp"
  53 #include "utilities/macros.hpp"
  54 
  55 // ciObjectFactory
  56 //
  57 // This class handles requests for the creation of new instances
  58 // of ciObject and its subclasses.  It contains a caching mechanism
  59 // which ensures that for each oop, at most one ciObject is created.
  60 // This invariant allows more efficient implementation of ciObject.
  61 //
  62 // Implementation note: the oop->ciObject mapping is represented as
  63 // a table stored in an array.  Even though objects are moved
  64 // by the garbage collector, the compactor preserves their relative
  65 // order; address comparison of oops (in perm space) is safe so long


 134       Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i);
 135       assert(vmSymbols::find_sid(vmsym) == i, "1-1 mapping");
 136       ciSymbol* sym = new (_arena) ciSymbol(vmsym, (vmSymbols::SID) i);
 137       init_ident_of(sym);
 138       _shared_ci_symbols[i] = sym;
 139     }
 140 #ifdef ASSERT
 141     for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) {
 142       Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i);
 143       ciSymbol* sym = vm_symbol_at((vmSymbols::SID) i);
 144       assert(sym->get_symbol() == vmsym, "oop must match");
 145     }
 146     assert(ciSymbol::void_class_signature()->get_symbol() == vmSymbols::void_class_signature(), "spot check");
 147 #endif
 148   }
 149 
 150   _ci_metadata = new (_arena) GrowableArray<ciMetadata*>(_arena, 64, 0, NULL);
 151 
 152   for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
 153     BasicType t = (BasicType)i;
 154     if (type2name(t) != NULL && t != T_OBJECT && t != T_ARRAY &&
 155         t != T_VALUETYPE && t != T_NARROWOOP && t != T_NARROWKLASS) {
 156       ciType::_basic_types[t] = new (_arena) ciType(t);
 157       init_ident_of(ciType::_basic_types[t]);
 158     }
 159   }
 160 
 161   ciEnv::_null_object_instance = new (_arena) ciNullObject();
 162   init_ident_of(ciEnv::_null_object_instance);
 163 
 164 #define WK_KLASS_DEFN(name, ignore_s)                              \
 165   if (SystemDictionary::name##_is_loaded()) \
 166     ciEnv::_##name = get_metadata(SystemDictionary::name())->as_instance_klass();
 167 
 168   WK_KLASSES_DO(WK_KLASS_DEFN)
 169 #undef WK_KLASS_DEFN
 170 
 171   for (int len = -1; len != _ci_metadata->length(); ) {
 172     len = _ci_metadata->length();
 173     for (int i2 = 0; i2 < len; i2++) {
 174       ciMetadata* obj = _ci_metadata->at(i2);
 175       assert (obj->is_metadata(), "what else would it be?");


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


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


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


< prev index next >