< prev index next >

src/share/vm/runtime/sharedRuntime.cpp

Print this page




  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/stringTable.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "code/codeCache.hpp"
  30 #include "code/compiledIC.hpp"
  31 #include "code/codeCacheExtensions.hpp"
  32 #include "code/scopeDesc.hpp"
  33 #include "code/vtableStubs.hpp"
  34 #include "compiler/abstractCompiler.hpp"
  35 #include "compiler/compileBroker.hpp"
  36 #include "compiler/disassembler.hpp"
  37 #include "gc/shared/gcLocker.inline.hpp"
  38 #include "interpreter/interpreter.hpp"
  39 #include "interpreter/interpreterRuntime.hpp"
  40 #include "logging/log.hpp"

  41 #include "memory/universe.inline.hpp"
  42 #include "oops/fieldStreams.hpp"
  43 #include "oops/objArrayKlass.inline.hpp"
  44 #include "oops/objArrayOop.inline.hpp"
  45 #include "oops/oop.inline.hpp"
  46 #include "oops/valueKlass.hpp"
  47 #include "prims/forte.hpp"
  48 #include "prims/jvmtiExport.hpp"
  49 #include "prims/jvmtiRedefineClassesTrace.hpp"
  50 #include "prims/methodHandles.hpp"
  51 #include "prims/nativeLookup.hpp"
  52 #include "runtime/arguments.hpp"
  53 #include "runtime/atomic.inline.hpp"
  54 #include "runtime/biasedLocking.hpp"
  55 #include "runtime/compilationPolicy.hpp"
  56 #include "runtime/handles.inline.hpp"
  57 #include "runtime/init.hpp"
  58 #include "runtime/interfaceSupport.hpp"
  59 #include "runtime/javaCalls.hpp"
  60 #include "runtime/sharedRuntime.hpp"


2349 
2350  private:
2351 
2352 #ifndef PRODUCT
2353   static int _lookups; // number of calls to lookup
2354   static int _buckets; // number of buckets checked
2355   static int _equals;  // number of buckets checked with matching hash
2356   static int _hits;    // number of successful lookups
2357   static int _compact; // number of equals calls with compact signature
2358 #endif
2359 
2360   AdapterHandlerEntry* bucket(int i) {
2361     return (AdapterHandlerEntry*)BasicHashtable<mtCode>::bucket(i);
2362   }
2363 
2364  public:
2365   AdapterHandlerTable()
2366     : BasicHashtable<mtCode>(293, sizeof(AdapterHandlerEntry)) { }
2367 
2368   // Create a new entry suitable for insertion in the table
2369   AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry, address c2i_unverified_entry) {
2370     AdapterHandlerEntry* entry = (AdapterHandlerEntry*)BasicHashtable<mtCode>::new_entry(fingerprint->compute_hash());
2371     entry->init(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
2372     return entry;
2373   }
2374 
2375   // Insert an entry into the table
2376   void add(AdapterHandlerEntry* entry) {
2377     int index = hash_to_index(entry->hash());
2378     add_entry(index, entry);
2379   }
2380 
2381   void free_entry(AdapterHandlerEntry* entry) {
2382     entry->deallocate();
2383     BasicHashtable<mtCode>::free_entry(entry);
2384   }
2385 
2386   // Find a entry with the same fingerprint if it exists
2387   AdapterHandlerEntry* lookup(int total_args_passed, BasicType* sig_bt) {
2388     NOT_PRODUCT(_lookups++);
2389     AdapterFingerPrint fp(total_args_passed, sig_bt);
2390     unsigned int hash = fp.compute_hash();
2391     int index = hash_to_index(hash);


2509     address wrong_method_abstract = SharedRuntime::get_handle_wrong_method_abstract_stub();
2510     _abstract_method_handler = AdapterHandlerLibrary::new_entry(new AdapterFingerPrint(0, NULL),
2511                                                                 StubRoutines::throw_AbstractMethodError_entry(),
2512                                                                 wrong_method_abstract, wrong_method_abstract);
2513   } else {
2514     // Adapters are not supposed to be used.
2515     // Generate a special one to cause an error if used (and store this
2516     // singleton in place of the useless _abstract_method_error adapter).
2517     address entry = (address) &unexpected_adapter_call;
2518     _abstract_method_handler = AdapterHandlerLibrary::new_entry(new AdapterFingerPrint(0, NULL),
2519                                                                 entry,
2520                                                                 entry,
2521                                                                 entry);
2522 
2523   }
2524 }
2525 
2526 AdapterHandlerEntry* AdapterHandlerLibrary::new_entry(AdapterFingerPrint* fingerprint,
2527                                                       address i2c_entry,
2528                                                       address c2i_entry,
2529                                                       address c2i_unverified_entry) {
2530   return _adapters->new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);

2531 }
2532 
2533 // Value type arguments are not passed by reference, instead each
2534 // field of the value type is passed as an argument. This helper
2535 // function collects the fields of the value types (including embedded
2536 // value type's fields) in a list. Included with the field's type is
2537 // the offset of each field in the value type: i2c and c2i adapters
2538 // need that to load or store fields. Finally, the list of fields is
2539 // sorted in order of increasing offsets: the adapters and the
2540 // compiled code need and agreed upon order of fields.
2541 //
2542 // The list of basic type that is returned starts with a T_VALUETYPE
2543 // and ends with an extra T_VOID. T_VALUETYPE/T_VOID are used as
2544 // delimiters. Every entry between the two is a field of the value
2545 // type. If there's an embedded value type in the list, it also starts
2546 // with a T_VALUETYPE and ends with a T_VOID. This is so we can
2547 // generate a unique fingerprint for the method's adapters and we can
2548 // generate the list of basic types from the interpreter point of view
2549 // (value types passed as reference: iterate on the list until a
2550 // T_VALUETYPE, drop everything until and including the closing


3219         event.set_method(method);
3220         event.commit();
3221       }
3222     }
3223   }
3224   return activation;
3225 }
3226 
3227 // We are at a compiled code to interpreter call. We need backing
3228 // buffers for all value type arguments. Allocate an object array to
3229 // hold them (convenient because once we're done with it we don't have
3230 // to worry about freeing it).
3231 JRT_ENTRY(void, SharedRuntime::allocate_value_types(JavaThread* thread, Method* callee_method))
3232 {
3233   assert(ValueTypePassFieldsAsArgs, "no reason to call this");
3234   ResourceMark rm;
3235   JavaThread* THREAD = thread;
3236   methodHandle callee(callee_method);
3237 
3238   int nb_slots = 0;
3239   if (!callee->is_static() && callee->method_holder()->is_value()) {

3240     nb_slots++;
3241   }
3242   Handle class_loader(THREAD, callee->method_holder()->class_loader());
3243   Handle protection_domain(THREAD, callee->method_holder()->protection_domain());
3244   for (SignatureStream ss(callee->signature()); !ss.at_return_type(); ss.next()) {
3245     if (ss.type() == T_VALUETYPE) {
3246       nb_slots++;
3247     }
3248   }
3249   objArrayHandle array = ObjArrayKlass::cast(Universe::objectArrayKlassObj())->allocate(nb_slots, CHECK);
3250   int i = 0;
3251   if (!callee->is_static() && callee->method_holder()->is_value()) {
3252     ValueKlass* vk = ValueKlass::cast(callee->method_holder());
3253     oop res = vk->allocate_instance(CHECK);
3254     array->obj_at_put(i, res);
3255     i++;
3256   }
3257   for (SignatureStream ss(callee->signature()); !ss.at_return_type(); ss.next()) {
3258     if (ss.type() == T_VALUETYPE) {
3259       Klass* k = ss.as_klass(class_loader, protection_domain, SignatureStream::ReturnNull, THREAD);
3260       assert(k != NULL && !HAS_PENDING_EXCEPTION, "can't resolve klass");
3261       ValueKlass* vk = ValueKlass::cast(k);
3262       oop res = vk->allocate_instance(CHECK);
3263       array->obj_at_put(i, res);
3264       i++;
3265     }
3266   }
3267   thread->set_vm_result(array());

























3268   thread->set_vm_result_2(callee()); // TODO: required to keep callee live?
3269 }
3270 JRT_END


  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/stringTable.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "classfile/vmSymbols.hpp"
  29 #include "code/codeCache.hpp"
  30 #include "code/compiledIC.hpp"
  31 #include "code/codeCacheExtensions.hpp"
  32 #include "code/scopeDesc.hpp"
  33 #include "code/vtableStubs.hpp"
  34 #include "compiler/abstractCompiler.hpp"
  35 #include "compiler/compileBroker.hpp"
  36 #include "compiler/disassembler.hpp"
  37 #include "gc/shared/gcLocker.inline.hpp"
  38 #include "interpreter/interpreter.hpp"
  39 #include "interpreter/interpreterRuntime.hpp"
  40 #include "logging/log.hpp"
  41 #include "memory/oopFactory.hpp"
  42 #include "memory/universe.inline.hpp"
  43 #include "oops/fieldStreams.hpp"
  44 #include "oops/objArrayKlass.inline.hpp"
  45 #include "oops/objArrayOop.inline.hpp"
  46 #include "oops/oop.inline.hpp"
  47 #include "oops/valueKlass.hpp"
  48 #include "prims/forte.hpp"
  49 #include "prims/jvmtiExport.hpp"
  50 #include "prims/jvmtiRedefineClassesTrace.hpp"
  51 #include "prims/methodHandles.hpp"
  52 #include "prims/nativeLookup.hpp"
  53 #include "runtime/arguments.hpp"
  54 #include "runtime/atomic.inline.hpp"
  55 #include "runtime/biasedLocking.hpp"
  56 #include "runtime/compilationPolicy.hpp"
  57 #include "runtime/handles.inline.hpp"
  58 #include "runtime/init.hpp"
  59 #include "runtime/interfaceSupport.hpp"
  60 #include "runtime/javaCalls.hpp"
  61 #include "runtime/sharedRuntime.hpp"


2350 
2351  private:
2352 
2353 #ifndef PRODUCT
2354   static int _lookups; // number of calls to lookup
2355   static int _buckets; // number of buckets checked
2356   static int _equals;  // number of buckets checked with matching hash
2357   static int _hits;    // number of successful lookups
2358   static int _compact; // number of equals calls with compact signature
2359 #endif
2360 
2361   AdapterHandlerEntry* bucket(int i) {
2362     return (AdapterHandlerEntry*)BasicHashtable<mtCode>::bucket(i);
2363   }
2364 
2365  public:
2366   AdapterHandlerTable()
2367     : BasicHashtable<mtCode>(293, sizeof(AdapterHandlerEntry)) { }
2368 
2369   // Create a new entry suitable for insertion in the table
2370   AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry, address c2i_unverified_entry, Symbol* sig_extended) {
2371     AdapterHandlerEntry* entry = (AdapterHandlerEntry*)BasicHashtable<mtCode>::new_entry(fingerprint->compute_hash());
2372     entry->init(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry, sig_extended);
2373     return entry;
2374   }
2375 
2376   // Insert an entry into the table
2377   void add(AdapterHandlerEntry* entry) {
2378     int index = hash_to_index(entry->hash());
2379     add_entry(index, entry);
2380   }
2381 
2382   void free_entry(AdapterHandlerEntry* entry) {
2383     entry->deallocate();
2384     BasicHashtable<mtCode>::free_entry(entry);
2385   }
2386 
2387   // Find a entry with the same fingerprint if it exists
2388   AdapterHandlerEntry* lookup(int total_args_passed, BasicType* sig_bt) {
2389     NOT_PRODUCT(_lookups++);
2390     AdapterFingerPrint fp(total_args_passed, sig_bt);
2391     unsigned int hash = fp.compute_hash();
2392     int index = hash_to_index(hash);


2510     address wrong_method_abstract = SharedRuntime::get_handle_wrong_method_abstract_stub();
2511     _abstract_method_handler = AdapterHandlerLibrary::new_entry(new AdapterFingerPrint(0, NULL),
2512                                                                 StubRoutines::throw_AbstractMethodError_entry(),
2513                                                                 wrong_method_abstract, wrong_method_abstract);
2514   } else {
2515     // Adapters are not supposed to be used.
2516     // Generate a special one to cause an error if used (and store this
2517     // singleton in place of the useless _abstract_method_error adapter).
2518     address entry = (address) &unexpected_adapter_call;
2519     _abstract_method_handler = AdapterHandlerLibrary::new_entry(new AdapterFingerPrint(0, NULL),
2520                                                                 entry,
2521                                                                 entry,
2522                                                                 entry);
2523 
2524   }
2525 }
2526 
2527 AdapterHandlerEntry* AdapterHandlerLibrary::new_entry(AdapterFingerPrint* fingerprint,
2528                                                       address i2c_entry,
2529                                                       address c2i_entry,
2530                                                       address c2i_unverified_entry,
2531                                                       Symbol* sig_extended) {
2532   return _adapters->new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry, sig_extended);
2533 }
2534 
2535 // Value type arguments are not passed by reference, instead each
2536 // field of the value type is passed as an argument. This helper
2537 // function collects the fields of the value types (including embedded
2538 // value type's fields) in a list. Included with the field's type is
2539 // the offset of each field in the value type: i2c and c2i adapters
2540 // need that to load or store fields. Finally, the list of fields is
2541 // sorted in order of increasing offsets: the adapters and the
2542 // compiled code need and agreed upon order of fields.
2543 //
2544 // The list of basic type that is returned starts with a T_VALUETYPE
2545 // and ends with an extra T_VOID. T_VALUETYPE/T_VOID are used as
2546 // delimiters. Every entry between the two is a field of the value
2547 // type. If there's an embedded value type in the list, it also starts
2548 // with a T_VALUETYPE and ends with a T_VOID. This is so we can
2549 // generate a unique fingerprint for the method's adapters and we can
2550 // generate the list of basic types from the interpreter point of view
2551 // (value types passed as reference: iterate on the list until a
2552 // T_VALUETYPE, drop everything until and including the closing


3221         event.set_method(method);
3222         event.commit();
3223       }
3224     }
3225   }
3226   return activation;
3227 }
3228 
3229 // We are at a compiled code to interpreter call. We need backing
3230 // buffers for all value type arguments. Allocate an object array to
3231 // hold them (convenient because once we're done with it we don't have
3232 // to worry about freeing it).
3233 JRT_ENTRY(void, SharedRuntime::allocate_value_types(JavaThread* thread, Method* callee_method))
3234 {
3235   assert(ValueTypePassFieldsAsArgs, "no reason to call this");
3236   ResourceMark rm;
3237   JavaThread* THREAD = thread;
3238   methodHandle callee(callee_method);
3239 
3240   int nb_slots = 0;
3241   bool has_value_receiver = !callee->is_static() && callee->method_holder()->is_value();
3242   if (has_value_receiver) {
3243     nb_slots++;
3244   }
3245   Handle class_loader(THREAD, callee->method_holder()->class_loader());
3246   Handle protection_domain(THREAD, callee->method_holder()->protection_domain());
3247   for (SignatureStream ss(callee->signature()); !ss.at_return_type(); ss.next()) {
3248     if (ss.type() == T_VALUETYPE) {
3249       nb_slots++;
3250     }
3251   }
3252   objArrayHandle array = oopFactory::new_objectArray(nb_slots, CHECK);
3253   int i = 0;
3254   if (has_value_receiver) {
3255     ValueKlass* vk = ValueKlass::cast(callee->method_holder());
3256     oop res = vk->allocate_instance(CHECK);
3257     array->obj_at_put(i, res);
3258     i++;
3259   }
3260   for (SignatureStream ss(callee->signature()); !ss.at_return_type(); ss.next()) {
3261     if (ss.type() == T_VALUETYPE) {
3262       Klass* k = ss.as_klass(class_loader, protection_domain, SignatureStream::ReturnNull, THREAD);
3263       assert(k != NULL && !HAS_PENDING_EXCEPTION, "can't resolve klass");
3264       ValueKlass* vk = ValueKlass::cast(k);
3265       oop res = vk->allocate_instance(CHECK);
3266       array->obj_at_put(i, res);
3267       i++;
3268     }
3269   }
3270   thread->set_vm_result(array());
3271   thread->set_vm_result_2(callee()); // TODO: required to keep callee live?
3272 }
3273 JRT_END
3274 
3275 // Iterate of the array of heap allocated value types and apply the GC post barrier to all reference fields.
3276 // This is called from the C2I adapter after value type arguments were heap allocated and initialized.
3277 JRT_LEAF(void, SharedRuntime::apply_post_barriers(JavaThread* thread, objArrayOopDesc* array, Method* callee_method))
3278 {
3279   assert(ValueTypePassFieldsAsArgs, "no reason to call this");
3280   assert(array->is_oop(), "should be oop");
3281   methodHandle callee(callee_method);
3282   for (int i = 0; i < array->length(); ++i) {
3283     instanceOop valueOop = (instanceOop)array->obj_at(i);
3284     ValueKlass* vk = ValueKlass::cast(valueOop->klass());
3285     if (vk->contains_oops()) {
3286       const address dst_oop_addr = ((address) (void*) valueOop);
3287       OopMapBlock* map = vk->start_of_nonstatic_oop_maps();
3288       OopMapBlock* const end = map + vk->nonstatic_oop_map_count();
3289       while (map != end) {
3290         address doop_address = dst_oop_addr + map->offset();
3291         oopDesc::bs()->write_ref_array((HeapWord*) doop_address, map->count());
3292         map++;
3293       }
3294     }
3295   }
3296   thread->set_vm_result_2(callee()); // TODO: required to keep callee live?
3297 }
3298 JRT_END
< prev index next >