src/share/vm/runtime/sharedRuntime.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/runtime

src/share/vm/runtime/sharedRuntime.cpp

Print this page




  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/oop.inline.hpp"
  43 #include "prims/forte.hpp"
  44 #include "prims/jvmtiExport.hpp"
  45 #include "prims/jvmtiRedefineClassesTrace.hpp"
  46 #include "prims/methodHandles.hpp"
  47 #include "prims/nativeLookup.hpp"
  48 #include "runtime/arguments.hpp"
  49 #include "runtime/atomic.inline.hpp"
  50 #include "runtime/biasedLocking.hpp"
  51 #include "runtime/compilationPolicy.hpp"
  52 #include "runtime/handles.inline.hpp"
  53 #include "runtime/init.hpp"
  54 #include "runtime/interfaceSupport.hpp"
  55 #include "runtime/javaCalls.hpp"
  56 #include "runtime/sharedRuntime.hpp"
  57 #include "runtime/stubRoutines.hpp"
  58 #include "runtime/vframe.hpp"
  59 #include "runtime/vframeArray.hpp"
  60 #include "trace/tracing.hpp"
  61 #include "utilities/copy.hpp"


1774   int comp_args_on_stack = java_calling_convention(sig_bt, regs_without_member_name, total_args_passed - 1, is_outgoing);
1775 
1776   for (int i = 0; i < member_arg_pos; i++) {
1777     VMReg a =    regs_with_member_name[i].first();
1778     VMReg b = regs_without_member_name[i].first();
1779     assert(a->value() == b->value(), "register allocation mismatch: a=" INTX_FORMAT ", b=" INTX_FORMAT, a->value(), b->value());
1780   }
1781   assert(regs_with_member_name[member_arg_pos].first()->is_valid(), "bad member arg");
1782 }
1783 #endif
1784 
1785 // ---------------------------------------------------------------------------
1786 // We are calling the interpreter via a c2i. Normally this would mean that
1787 // we were called by a compiled method. However we could have lost a race
1788 // where we went int -> i2c -> c2i and so the caller could in fact be
1789 // interpreted. If the caller is compiled we attempt to patch the caller
1790 // so he no longer calls into the interpreter.
1791 IRT_LEAF(void, SharedRuntime::fixup_callers_callsite(Method* method, address caller_pc))
1792   Method* moop(method);
1793 
1794   address entry_point = moop->from_compiled_entry();
1795 
1796   // It's possible that deoptimization can occur at a call site which hasn't
1797   // been resolved yet, in which case this function will be called from
1798   // an nmethod that has been patched for deopt and we can ignore the
1799   // request for a fixup.
1800   // Also it is possible that we lost a race in that from_compiled_entry
1801   // is now back to the i2c in that case we don't need to patch and if
1802   // we did we'd leap into space because the callsite needs to use
1803   // "to interpreter" stub in order to load up the Method*. Don't
1804   // ask me how I know this...
1805 
1806   CodeBlob* cb = CodeCache::find_blob(caller_pc);
1807   if (!cb->is_nmethod() || entry_point == moop->get_c2i_entry()) {
1808     return;
1809   }
1810 
1811   // The check above makes sure this is a nmethod.
1812   nmethod* nm = cb->as_nmethod_or_null();
1813   assert(nm, "must be");
1814 


2307 // A hashtable mapping from AdapterFingerPrints to AdapterHandlerEntries
2308 class AdapterHandlerTable : public BasicHashtable<mtCode> {
2309   friend class AdapterHandlerTableIterator;
2310 
2311  private:
2312 
2313 #ifndef PRODUCT
2314   static int _lookups; // number of calls to lookup
2315   static int _buckets; // number of buckets checked
2316   static int _equals;  // number of buckets checked with matching hash
2317   static int _hits;    // number of successful lookups
2318   static int _compact; // number of equals calls with compact signature
2319 #endif
2320 
2321   AdapterHandlerEntry* bucket(int i) {
2322     return (AdapterHandlerEntry*)BasicHashtable<mtCode>::bucket(i);
2323   }
2324 
2325  public:
2326   AdapterHandlerTable()
2327     : BasicHashtable<mtCode>(293, sizeof(AdapterHandlerEntry)) { }
2328 
2329   // Create a new entry suitable for insertion in the table
2330   AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry, address c2i_unverified_entry) {
2331     AdapterHandlerEntry* entry = (AdapterHandlerEntry*)BasicHashtable<mtCode>::new_entry(fingerprint->compute_hash());
2332     entry->init(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);



2333     return entry;
2334   }
2335 
2336   // Insert an entry into the table
2337   void add(AdapterHandlerEntry* entry) {
2338     int index = hash_to_index(entry->hash());
2339     add_entry(index, entry);
2340   }
2341 
2342   void free_entry(AdapterHandlerEntry* entry) {
2343     entry->deallocate();
2344     BasicHashtable<mtCode>::free_entry(entry);
2345   }
2346 
2347   // Find a entry with the same fingerprint if it exists
2348   AdapterHandlerEntry* lookup(int total_args_passed, BasicType* sig_bt) {
2349     NOT_PRODUCT(_lookups++);
2350     AdapterFingerPrint fp(total_args_passed, sig_bt);
2351     unsigned int hash = fp.compute_hash();
2352     int index = hash_to_index(hash);


2475     // Adapters are not supposed to be used.
2476     // Generate a special one to cause an error if used (and store this
2477     // singleton in place of the useless _abstract_method_error adapter).
2478     address entry = (address) &unexpected_adapter_call;
2479     _abstract_method_handler = AdapterHandlerLibrary::new_entry(new AdapterFingerPrint(0, NULL),
2480                                                                 entry,
2481                                                                 entry,
2482                                                                 entry);
2483 
2484   }
2485 }
2486 
2487 AdapterHandlerEntry* AdapterHandlerLibrary::new_entry(AdapterFingerPrint* fingerprint,
2488                                                       address i2c_entry,
2489                                                       address c2i_entry,
2490                                                       address c2i_unverified_entry) {
2491   return _adapters->new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
2492 }
2493 
2494 AdapterHandlerEntry* AdapterHandlerLibrary::get_adapter(const methodHandle& method) {






















2495   // Use customized signature handler.  Need to lock around updates to
2496   // the AdapterHandlerTable (it is not safe for concurrent readers
2497   // and a single writer: this could be fixed if it becomes a
2498   // problem).
2499 
2500   ResourceMark rm;
2501 
2502   NOT_PRODUCT(int insts_size);
2503   AdapterBlob* new_adapter = NULL;
2504   AdapterHandlerEntry* entry = NULL;
2505   AdapterFingerPrint* fingerprint = NULL;
2506   {
2507     MutexLocker mu(AdapterHandlerLibrary_lock);
2508     // make sure data structure is initialized
2509     initialize();
2510 
2511     if (CodeCacheExtensions::skip_compiler_support()) {
2512       // adapters are useless and should not be used, including the
2513       // abstract_method_handler. However, some callers check that
2514       // an adapter was installed.
2515       // Return the singleton adapter, stored into _abstract_method_handler
2516       // and modified to cause an error if we ever call it.
2517       return _abstract_method_handler;
2518     }
2519 
2520     if (method->is_abstract()) {
2521       return _abstract_method_handler;
2522     }
2523 
2524     // Fill in the signature array, for the calling-convention call.
2525     int total_args_passed = method->size_of_parameters(); // All args on stack
2526 
2527     BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_args_passed);
2528     VMRegPair* regs   = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed);
2529     int i = 0;
2530     if (!method->is_static())  // Pass in receiver first
2531       sig_bt[i++] = T_OBJECT;


2973 void AdapterHandlerLibrary::print_handler_on(outputStream* st, const CodeBlob* b) {
2974   AdapterHandlerTableIterator iter(_adapters);
2975   while (iter.has_next()) {
2976     AdapterHandlerEntry* a = iter.next();
2977     if (b == CodeCache::find_blob(a->get_i2c_entry())) {
2978       st->print("Adapter for signature: ");
2979       a->print_adapter_on(tty);
2980       return;
2981     }
2982   }
2983   assert(false, "Should have found handler");
2984 }
2985 
2986 void AdapterHandlerEntry::print_adapter_on(outputStream* st) const {
2987   st->print_cr("AHE@" INTPTR_FORMAT ": %s i2c: " INTPTR_FORMAT " c2i: " INTPTR_FORMAT " c2iUV: " INTPTR_FORMAT,
2988                p2i(this), fingerprint()->as_string(),
2989                p2i(get_i2c_entry()), p2i(get_c2i_entry()), p2i(get_c2i_unverified_entry()));
2990 
2991 }
2992 











2993 #ifndef PRODUCT
2994 
2995 void AdapterHandlerLibrary::print_statistics() {
2996   _adapters->print_statistics();
2997 }
2998 
2999 #endif /* PRODUCT */
3000 
3001 JRT_LEAF(void, SharedRuntime::enable_stack_reserved_zone(JavaThread* thread))
3002   assert(thread->is_Java_thread(), "Only Java threads have a stack reserved zone");
3003   thread->enable_stack_reserved_zone();
3004   thread->set_reserved_stack_activation(thread->stack_base());
3005 JRT_END
3006 
3007 frame SharedRuntime::look_for_reserved_stack_annotated_method(JavaThread* thread, frame fr) {
3008   frame activation;
3009   int decode_offset = 0;
3010   nmethod* nm = NULL;
3011   frame prv_fr = fr;
3012   int count = 1;




  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 "memory/metaspaceShared.hpp"
  43 #include "oops/oop.inline.hpp"
  44 #include "prims/forte.hpp"
  45 #include "prims/jvmtiExport.hpp"
  46 #include "prims/jvmtiRedefineClassesTrace.hpp"
  47 #include "prims/methodHandles.hpp"
  48 #include "prims/nativeLookup.hpp"
  49 #include "runtime/arguments.hpp"
  50 #include "runtime/atomic.inline.hpp"
  51 #include "runtime/biasedLocking.hpp"
  52 #include "runtime/compilationPolicy.hpp"
  53 #include "runtime/handles.inline.hpp"
  54 #include "runtime/init.hpp"
  55 #include "runtime/interfaceSupport.hpp"
  56 #include "runtime/javaCalls.hpp"
  57 #include "runtime/sharedRuntime.hpp"
  58 #include "runtime/stubRoutines.hpp"
  59 #include "runtime/vframe.hpp"
  60 #include "runtime/vframeArray.hpp"
  61 #include "trace/tracing.hpp"
  62 #include "utilities/copy.hpp"


1775   int comp_args_on_stack = java_calling_convention(sig_bt, regs_without_member_name, total_args_passed - 1, is_outgoing);
1776 
1777   for (int i = 0; i < member_arg_pos; i++) {
1778     VMReg a =    regs_with_member_name[i].first();
1779     VMReg b = regs_without_member_name[i].first();
1780     assert(a->value() == b->value(), "register allocation mismatch: a=" INTX_FORMAT ", b=" INTX_FORMAT, a->value(), b->value());
1781   }
1782   assert(regs_with_member_name[member_arg_pos].first()->is_valid(), "bad member arg");
1783 }
1784 #endif
1785 
1786 // ---------------------------------------------------------------------------
1787 // We are calling the interpreter via a c2i. Normally this would mean that
1788 // we were called by a compiled method. However we could have lost a race
1789 // where we went int -> i2c -> c2i and so the caller could in fact be
1790 // interpreted. If the caller is compiled we attempt to patch the caller
1791 // so he no longer calls into the interpreter.
1792 IRT_LEAF(void, SharedRuntime::fixup_callers_callsite(Method* method, address caller_pc))
1793   Method* moop(method);
1794 
1795   address entry_point = moop->from_compiled_entry_no_trampoline();
1796 
1797   // It's possible that deoptimization can occur at a call site which hasn't
1798   // been resolved yet, in which case this function will be called from
1799   // an nmethod that has been patched for deopt and we can ignore the
1800   // request for a fixup.
1801   // Also it is possible that we lost a race in that from_compiled_entry
1802   // is now back to the i2c in that case we don't need to patch and if
1803   // we did we'd leap into space because the callsite needs to use
1804   // "to interpreter" stub in order to load up the Method*. Don't
1805   // ask me how I know this...
1806 
1807   CodeBlob* cb = CodeCache::find_blob(caller_pc);
1808   if (!cb->is_nmethod() || entry_point == moop->get_c2i_entry()) {
1809     return;
1810   }
1811 
1812   // The check above makes sure this is a nmethod.
1813   nmethod* nm = cb->as_nmethod_or_null();
1814   assert(nm, "must be");
1815 


2308 // A hashtable mapping from AdapterFingerPrints to AdapterHandlerEntries
2309 class AdapterHandlerTable : public BasicHashtable<mtCode> {
2310   friend class AdapterHandlerTableIterator;
2311 
2312  private:
2313 
2314 #ifndef PRODUCT
2315   static int _lookups; // number of calls to lookup
2316   static int _buckets; // number of buckets checked
2317   static int _equals;  // number of buckets checked with matching hash
2318   static int _hits;    // number of successful lookups
2319   static int _compact; // number of equals calls with compact signature
2320 #endif
2321 
2322   AdapterHandlerEntry* bucket(int i) {
2323     return (AdapterHandlerEntry*)BasicHashtable<mtCode>::bucket(i);
2324   }
2325 
2326  public:
2327   AdapterHandlerTable()
2328     : BasicHashtable<mtCode>(293, (DumpSharedSpaces ? sizeof(CDSAdapterHandlerEntry) : sizeof(AdapterHandlerEntry))) { }
2329 
2330   // Create a new entry suitable for insertion in the table
2331   AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry, address c2i_unverified_entry) {
2332     AdapterHandlerEntry* entry = (AdapterHandlerEntry*)BasicHashtable<mtCode>::new_entry(fingerprint->compute_hash());
2333     entry->init(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
2334     if (DumpSharedSpaces) {
2335       ((CDSAdapterHandlerEntry*)entry)->init();
2336     }
2337     return entry;
2338   }
2339 
2340   // Insert an entry into the table
2341   void add(AdapterHandlerEntry* entry) {
2342     int index = hash_to_index(entry->hash());
2343     add_entry(index, entry);
2344   }
2345 
2346   void free_entry(AdapterHandlerEntry* entry) {
2347     entry->deallocate();
2348     BasicHashtable<mtCode>::free_entry(entry);
2349   }
2350 
2351   // Find a entry with the same fingerprint if it exists
2352   AdapterHandlerEntry* lookup(int total_args_passed, BasicType* sig_bt) {
2353     NOT_PRODUCT(_lookups++);
2354     AdapterFingerPrint fp(total_args_passed, sig_bt);
2355     unsigned int hash = fp.compute_hash();
2356     int index = hash_to_index(hash);


2479     // Adapters are not supposed to be used.
2480     // Generate a special one to cause an error if used (and store this
2481     // singleton in place of the useless _abstract_method_error adapter).
2482     address entry = (address) &unexpected_adapter_call;
2483     _abstract_method_handler = AdapterHandlerLibrary::new_entry(new AdapterFingerPrint(0, NULL),
2484                                                                 entry,
2485                                                                 entry,
2486                                                                 entry);
2487 
2488   }
2489 }
2490 
2491 AdapterHandlerEntry* AdapterHandlerLibrary::new_entry(AdapterFingerPrint* fingerprint,
2492                                                       address i2c_entry,
2493                                                       address c2i_entry,
2494                                                       address c2i_unverified_entry) {
2495   return _adapters->new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
2496 }
2497 
2498 AdapterHandlerEntry* AdapterHandlerLibrary::get_adapter(const methodHandle& method) {
2499   AdapterHandlerEntry* entry = get_adapter0(method);
2500   if (method->is_shared()) {
2501     MutexLocker mu(AdapterHandlerLibrary_lock);
2502     if (method->adapter() == NULL) {
2503       method->update_adapter_trampoline(entry);
2504     }
2505     address trampoline = method->from_compiled_entry();
2506     if (*(int*)trampoline == 0) {
2507       CodeBuffer buffer(trampoline, (int)SharedRuntime::trampoline_size());
2508       MacroAssembler _masm(&buffer);
2509       SharedRuntime::generate_trampoline(&_masm, entry->get_c2i_entry());
2510 
2511       if (PrintInterpreter) {
2512         Disassembler::decode(buffer.insts_begin(), buffer.insts_end());
2513       }
2514     }
2515   }
2516 
2517   return entry;
2518 }
2519 
2520 AdapterHandlerEntry* AdapterHandlerLibrary::get_adapter0(const methodHandle& method) {
2521   // Use customized signature handler.  Need to lock around updates to
2522   // the AdapterHandlerTable (it is not safe for concurrent readers
2523   // and a single writer: this could be fixed if it becomes a
2524   // problem).
2525 
2526   ResourceMark rm;
2527 
2528   NOT_PRODUCT(int insts_size);
2529   AdapterBlob* new_adapter = NULL;
2530   AdapterHandlerEntry* entry = NULL;
2531   AdapterFingerPrint* fingerprint = NULL;
2532   {
2533     MutexLocker mu(AdapterHandlerLibrary_lock);
2534     // make sure data structure is initialized
2535     initialize();
2536 
2537     if (!DumpSharedSpaces && CodeCacheExtensions::skip_compiler_support()) {
2538       // adapters are useless and should not be used, including the
2539       // abstract_method_handler. However, some callers check that
2540       // an adapter was installed.
2541       // Return the singleton adapter, stored into _abstract_method_handler
2542       // and modified to cause an error if we ever call it.
2543       return _abstract_method_handler;
2544     }
2545 
2546     if (method->is_abstract()) {
2547       return _abstract_method_handler;
2548     }
2549 
2550     // Fill in the signature array, for the calling-convention call.
2551     int total_args_passed = method->size_of_parameters(); // All args on stack
2552 
2553     BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_args_passed);
2554     VMRegPair* regs   = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed);
2555     int i = 0;
2556     if (!method->is_static())  // Pass in receiver first
2557       sig_bt[i++] = T_OBJECT;


2999 void AdapterHandlerLibrary::print_handler_on(outputStream* st, const CodeBlob* b) {
3000   AdapterHandlerTableIterator iter(_adapters);
3001   while (iter.has_next()) {
3002     AdapterHandlerEntry* a = iter.next();
3003     if (b == CodeCache::find_blob(a->get_i2c_entry())) {
3004       st->print("Adapter for signature: ");
3005       a->print_adapter_on(tty);
3006       return;
3007     }
3008   }
3009   assert(false, "Should have found handler");
3010 }
3011 
3012 void AdapterHandlerEntry::print_adapter_on(outputStream* st) const {
3013   st->print_cr("AHE@" INTPTR_FORMAT ": %s i2c: " INTPTR_FORMAT " c2i: " INTPTR_FORMAT " c2iUV: " INTPTR_FORMAT,
3014                p2i(this), fingerprint()->as_string(),
3015                p2i(get_i2c_entry()), p2i(get_c2i_entry()), p2i(get_c2i_unverified_entry()));
3016 
3017 }
3018 
3019 #if INCLUDE_CDS
3020 
3021 void CDSAdapterHandlerEntry::init() {
3022   assert(DumpSharedSpaces, "used during dump time only");
3023   _c2i_entry_trampoline = (address)MetaspaceShared::misc_code_space_alloc(SharedRuntime::trampoline_size());
3024   _adapter_trampoline = (AdapterHandlerEntry**)MetaspaceShared::misc_data_space_alloc(sizeof(AdapterHandlerEntry*));
3025 };
3026 
3027 #endif // INCLUDE_CDS
3028 
3029 
3030 #ifndef PRODUCT
3031 
3032 void AdapterHandlerLibrary::print_statistics() {
3033   _adapters->print_statistics();
3034 }
3035 
3036 #endif /* PRODUCT */
3037 
3038 JRT_LEAF(void, SharedRuntime::enable_stack_reserved_zone(JavaThread* thread))
3039   assert(thread->is_Java_thread(), "Only Java threads have a stack reserved zone");
3040   thread->enable_stack_reserved_zone();
3041   thread->set_reserved_stack_activation(thread->stack_base());
3042 JRT_END
3043 
3044 frame SharedRuntime::look_for_reserved_stack_annotated_method(JavaThread* thread, frame fr) {
3045   frame activation;
3046   int decode_offset = 0;
3047   nmethod* nm = NULL;
3048   frame prv_fr = fr;
3049   int count = 1;


src/share/vm/runtime/sharedRuntime.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File