< prev index next >

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"
  62 #include "utilities/dtrace.hpp"


1138       switch (bc) {
1139         case Bytecodes::_invokeinterface:
1140           if (!attached_method->method_holder()->is_interface()) {
1141             bc = Bytecodes::_invokevirtual;
1142           }
1143           break;
1144         case Bytecodes::_invokehandle:
1145           if (!MethodHandles::is_signature_polymorphic_method(attached_method())) {
1146             bc = attached_method->is_static() ? Bytecodes::_invokestatic
1147                                               : Bytecodes::_invokevirtual;
1148           }
1149           break;
1150       }
1151     }
1152   } else {
1153     bc = bytecode.invoke_code();
1154   }
1155 
1156   bool has_receiver = bc != Bytecodes::_invokestatic &&
1157                       bc != Bytecodes::_invokedynamic &&
1158                       bc != Bytecodes::_invokehandle;

1159 
1160   // Find receiver for non-static call
1161   if (has_receiver) {
1162     // This register map must be update since we need to find the receiver for
1163     // compiled frames. The receiver might be in a register.
1164     RegisterMap reg_map2(thread);
1165     frame stubFrame   = thread->last_frame();
1166     // Caller-frame is a compiled frame
1167     frame callerFrame = stubFrame.sender(&reg_map2);
1168 
1169     if (attached_method.is_null()) {
1170       methodHandle callee = bytecode.static_target(CHECK_NH);
1171       if (callee.is_null()) {
1172         THROW_(vmSymbols::java_lang_NoSuchMethodException(), nullHandle);
1173       }
1174     }
1175 
1176     // Retrieve from a compiled argument list
1177     receiver = Handle(THREAD, callerFrame.retrieve_receiver(&reg_map2));
1178 


1350   // not been deoptimized.  Return values: For a virtual call this is an
1351   // (cached_oop, destination address) pair. For a static call/optimized
1352   // virtual this is just a destination address.
1353 
1354   StaticCallInfo static_call_info;
1355   CompiledICInfo virtual_call_info;
1356 
1357   // Make sure the callee nmethod does not get deoptimized and removed before
1358   // we are done patching the code.
1359   nmethod* callee_nm = callee_method->code();
1360   if (callee_nm != NULL && !callee_nm->is_in_use()) {
1361     // Patch call site to C2I adapter if callee nmethod is deoptimized or unloaded.
1362     callee_nm = NULL;
1363   }
1364   nmethodLocker nl_callee(callee_nm);
1365 #ifdef ASSERT
1366   address dest_entry_point = callee_nm == NULL ? 0 : callee_nm->entry_point(); // used below
1367 #endif
1368 
1369   if (is_virtual) {
1370     assert(receiver.not_null() || invoke_code == Bytecodes::_invokehandle, "sanity check");
1371     bool static_bound = call_info.resolved_method()->can_be_statically_bound();
1372     KlassHandle h_klass(THREAD, invoke_code == Bytecodes::_invokehandle ? NULL : receiver->klass());
1373     CompiledIC::compute_monomorphic_entry(callee_method, h_klass,
1374                      is_optimized, static_bound, virtual_call_info,
1375                      CHECK_(methodHandle()));
1376   } else {
1377     // static call
1378     CompiledStaticCall::compute_entry(callee_method, static_call_info);
1379   }
1380 
1381   // grab lock, check for deoptimization and potentially patch caller
1382   {
1383     MutexLocker ml_patch(CompiledIC_lock);
1384 
1385     // Lock blocks for safepoint during which both nmethods can change state.
1386 
1387     // Now that we are ready to patch if the Method* was redefined then
1388     // don't update call site and let the caller retry.
1389     // Don't update call site if callee nmethod was unloaded or deoptimized.
1390     // Don't update call site if callee nmethod was replaced by an other nmethod
1391     // which may happen when multiply alive nmethod (tiered compilation)
1392     // will be supported.


2482   } else {
2483     // Adapters are not supposed to be used.
2484     // Generate a special one to cause an error if used (and store this
2485     // singleton in place of the useless _abstract_method_error adapter).
2486     address entry = (address) &unexpected_adapter_call;
2487     _abstract_method_handler = AdapterHandlerLibrary::new_entry(new AdapterFingerPrint(0, NULL),
2488                                                                 entry,
2489                                                                 entry,
2490                                                                 entry);
2491 
2492   }
2493 }
2494 
2495 AdapterHandlerEntry* AdapterHandlerLibrary::new_entry(AdapterFingerPrint* fingerprint,
2496                                                       address i2c_entry,
2497                                                       address c2i_entry,
2498                                                       address c2i_unverified_entry) {
2499   return _adapters->new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
2500 }
2501 























































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







2534 
2535     BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_args_passed);
2536     VMRegPair* regs   = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed);
2537     int i = 0;
2538     if (!method->is_static())  // Pass in receiver first
2539       sig_bt[i++] = T_OBJECT;









2540     for (SignatureStream ss(method->signature()); !ss.at_return_type(); ss.next()) {
2541       sig_bt[i++] = ss.type();  // Collect remaining bits of signature
2542       if (ss.type() == T_LONG || ss.type() == T_DOUBLE)
2543         sig_bt[i++] = T_VOID;   // Longs & doubles take 2 Java slots











2544     }
2545     assert(i == total_args_passed, "");































2546 
2547     // Lookup method signature's fingerprint
2548     entry = _adapters->lookup(total_args_passed, sig_bt);
2549 
2550 #ifdef ASSERT
2551     AdapterHandlerEntry* shared_entry = NULL;
2552     // Start adapter sharing verification only after the VM is booted.
2553     if (VerifyAdapterSharing && (entry != NULL)) {
2554       shared_entry = entry;
2555       entry = NULL;
2556     }
2557 #endif
2558 
2559     if (entry != NULL) {
2560       return entry;
2561     }
2562 
2563     // Get a description of the compiled java calling convention and the largest used (VMReg) stack slot usage
2564     int comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, false);
2565 
2566     // Make a C heap allocated version of the fingerprint to store in the adapter
2567     fingerprint = new AdapterFingerPrint(total_args_passed, sig_bt);
2568 
2569     // StubRoutines::code2() is initialized after this function can be called. As a result,
2570     // VerifyAdapterCalls and VerifyAdapterSharing can fail if we re-use code that generated
2571     // prior to StubRoutines::code2() being set. Checks refer to checks generated in an I2C
2572     // stub that ensure that an I2C stub is called from an interpreter frame.
2573     bool contains_all_checks = StubRoutines::code2() != NULL;
2574 
2575     // Create I2C & C2I handlers
2576     BufferBlob* buf = buffer_blob(); // the temporary code buffer in CodeCache
2577     if (buf != NULL) {
2578       CodeBuffer buffer(buf);
2579       short buffer_locs[20];
2580       buffer.insts()->initialize_shared_locs((relocInfo*)buffer_locs,
2581                                              sizeof(buffer_locs)/sizeof(relocInfo));
2582 

2583       MacroAssembler _masm(&buffer);
2584       entry = SharedRuntime::generate_i2c2i_adapters(&_masm,
2585                                                      total_args_passed,
2586                                                      comp_args_on_stack,
2587                                                      sig_bt,
2588                                                      regs,
2589                                                      fingerprint);

2590 #ifdef ASSERT
2591       if (VerifyAdapterSharing) {
2592         if (shared_entry != NULL) {
2593           assert(shared_entry->compare_code(buf->code_begin(), buffer.insts_size()), "code must match");
2594           // Release the one just created and return the original
2595           _adapters->free_entry(entry);
2596           return shared_entry;
2597         } else  {
2598           entry->save_code(buf->code_begin(), buffer.insts_size());
2599         }
2600       }
2601 #endif
2602 
2603       new_adapter = AdapterBlob::create(&buffer);
2604       NOT_PRODUCT(insts_size = buffer.insts_size());
2605     }
2606     if (new_adapter == NULL) {
2607       // CodeCache is full, disable compilation
2608       // Ought to log this but compile log is only per compile thread
2609       // and we're some non descript Java thread.
2610       return NULL; // Out of CodeCache space
2611     }
2612     entry->relocate(new_adapter->content_begin());
2613 #ifndef PRODUCT
2614     // debugging suppport
2615     if (PrintAdapterHandlers || PrintStubCode) {
2616       ttyLocker ttyl;
2617       entry->print_adapter_on(tty);
2618       tty->print_cr("i2c argument handler #%d for: %s %s %s (%d bytes generated)",
2619                     _adapters->number_of_entries(), (method->is_static() ? "static" : "receiver"),
2620                     method->signature()->as_C_string(), fingerprint->as_string(), insts_size);
2621       tty->print_cr("c2i argument handler starts at %p", entry->get_c2i_entry());
2622       if (Verbose || PrintStubCode) {
2623         address first_pc = entry->base_address();


3057           continue;
3058         }
3059       }
3060     }
3061     if (method->has_reserved_stack_access()) {
3062       ResourceMark rm(thread);
3063       activation = prv_fr;
3064       warning("Potentially dangerous stack overflow in "
3065               "ReservedStackAccess annotated method %s [%d]",
3066               method->name_and_sig_as_C_string(), count++);
3067       EventReservedStackActivation event;
3068       if (event.should_commit()) {
3069         event.set_method(method);
3070         event.commit();
3071       }
3072     }
3073   }
3074   return activation;
3075 }
3076 

















































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


1141       switch (bc) {
1142         case Bytecodes::_invokeinterface:
1143           if (!attached_method->method_holder()->is_interface()) {
1144             bc = Bytecodes::_invokevirtual;
1145           }
1146           break;
1147         case Bytecodes::_invokehandle:
1148           if (!MethodHandles::is_signature_polymorphic_method(attached_method())) {
1149             bc = attached_method->is_static() ? Bytecodes::_invokestatic
1150                                               : Bytecodes::_invokevirtual;
1151           }
1152           break;
1153       }
1154     }
1155   } else {
1156     bc = bytecode.invoke_code();
1157   }
1158 
1159   bool has_receiver = bc != Bytecodes::_invokestatic &&
1160                       bc != Bytecodes::_invokedynamic &&
1161                       bc != Bytecodes::_invokehandle &&
1162                       bc != Bytecodes::_invokedirect;
1163 
1164   // Find receiver for non-static call
1165   if (has_receiver) {
1166     // This register map must be update since we need to find the receiver for
1167     // compiled frames. The receiver might be in a register.
1168     RegisterMap reg_map2(thread);
1169     frame stubFrame   = thread->last_frame();
1170     // Caller-frame is a compiled frame
1171     frame callerFrame = stubFrame.sender(&reg_map2);
1172 
1173     if (attached_method.is_null()) {
1174       methodHandle callee = bytecode.static_target(CHECK_NH);
1175       if (callee.is_null()) {
1176         THROW_(vmSymbols::java_lang_NoSuchMethodException(), nullHandle);
1177       }
1178     }
1179 
1180     // Retrieve from a compiled argument list
1181     receiver = Handle(THREAD, callerFrame.retrieve_receiver(&reg_map2));
1182 


1354   // not been deoptimized.  Return values: For a virtual call this is an
1355   // (cached_oop, destination address) pair. For a static call/optimized
1356   // virtual this is just a destination address.
1357 
1358   StaticCallInfo static_call_info;
1359   CompiledICInfo virtual_call_info;
1360 
1361   // Make sure the callee nmethod does not get deoptimized and removed before
1362   // we are done patching the code.
1363   nmethod* callee_nm = callee_method->code();
1364   if (callee_nm != NULL && !callee_nm->is_in_use()) {
1365     // Patch call site to C2I adapter if callee nmethod is deoptimized or unloaded.
1366     callee_nm = NULL;
1367   }
1368   nmethodLocker nl_callee(callee_nm);
1369 #ifdef ASSERT
1370   address dest_entry_point = callee_nm == NULL ? 0 : callee_nm->entry_point(); // used below
1371 #endif
1372 
1373   if (is_virtual) {
1374     assert(receiver.not_null() || invoke_code == Bytecodes::_invokehandle || invoke_code == Bytecodes::_invokedirect, "sanity check");
1375     bool static_bound = call_info.resolved_method()->can_be_statically_bound();
1376     KlassHandle h_klass(THREAD, (invoke_code == Bytecodes::_invokehandle || invoke_code == Bytecodes::_invokedirect) ? NULL : receiver->klass());
1377     CompiledIC::compute_monomorphic_entry(callee_method, h_klass,
1378                      is_optimized, static_bound, virtual_call_info,
1379                      CHECK_(methodHandle()));
1380   } else {
1381     // static call
1382     CompiledStaticCall::compute_entry(callee_method, static_call_info);
1383   }
1384 
1385   // grab lock, check for deoptimization and potentially patch caller
1386   {
1387     MutexLocker ml_patch(CompiledIC_lock);
1388 
1389     // Lock blocks for safepoint during which both nmethods can change state.
1390 
1391     // Now that we are ready to patch if the Method* was redefined then
1392     // don't update call site and let the caller retry.
1393     // Don't update call site if callee nmethod was unloaded or deoptimized.
1394     // Don't update call site if callee nmethod was replaced by an other nmethod
1395     // which may happen when multiply alive nmethod (tiered compilation)
1396     // will be supported.


2486   } else {
2487     // Adapters are not supposed to be used.
2488     // Generate a special one to cause an error if used (and store this
2489     // singleton in place of the useless _abstract_method_error adapter).
2490     address entry = (address) &unexpected_adapter_call;
2491     _abstract_method_handler = AdapterHandlerLibrary::new_entry(new AdapterFingerPrint(0, NULL),
2492                                                                 entry,
2493                                                                 entry,
2494                                                                 entry);
2495 
2496   }
2497 }
2498 
2499 AdapterHandlerEntry* AdapterHandlerLibrary::new_entry(AdapterFingerPrint* fingerprint,
2500                                                       address i2c_entry,
2501                                                       address c2i_entry,
2502                                                       address c2i_unverified_entry) {
2503   return _adapters->new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
2504 }
2505 
2506 // Value type arguments are not passed by reference, instead each
2507 // field of the value type is passed as an argument. This helper
2508 // function collects the fields of the value types (including embedded
2509 // value type's fields) in a list. Included with the field's type is
2510 // the offset of each field in the value type: i2c and c2i adapters
2511 // need that to load or store fields. Finally, the list of fields is
2512 // sorted in order of increasing offsets: the adapters and the
2513 // compiled code need and agreed upon order of fields.
2514 //
2515 // The list of basic type that is returned starts with a T_VALUETYPE
2516 // and ends with an extra T_VOID. T_VALUETYPE/T_VOID are used as
2517 // delimiters. Every entry between the two is a field of the value
2518 // type. If there's an embedded value type in the list, it also starts
2519 // with a T_VALUETYPE and ends with a T_VOID. This is so we can
2520 // generate a unique fingerprint for the method's adapters and we can
2521 // generate the list of basic types from the interpreter point of view
2522 // (value types passed as reference: iterate on the list until a
2523 // T_VALUETYPE, drop everything until and including the closing
2524 // T_VOID) or the compiler point of view (each field of the value
2525 // types is an argument: drop all T_VALUETYPE/T_VOID from the list).
2526 static GrowableArray<SigEntry> collect_fields(ValueKlass* vk, int base_off = 0) {
2527   GrowableArray<SigEntry> sig;
2528   sig.push(SigEntry(T_VALUETYPE, base_off));
2529   for (JavaFieldStream fs(vk); !fs.done(); fs.next()) {
2530     if (fs.access_flags().is_static())  continue;
2531     fieldDescriptor& fd = fs.field_descriptor();
2532     BasicType bt = fd.field_type();
2533     int offset = base_off + fd.offset() - (base_off > 0 ? vk->first_field_offset() : 0);
2534     if (bt == T_VALUETYPE) {
2535       Symbol* signature = fd.signature();
2536       JavaThread* THREAD = JavaThread::current();
2537       oop loader = vk->class_loader();
2538       oop protection_domain = vk->protection_domain();
2539       Klass* klass = SystemDictionary::resolve_or_null(signature,
2540                                                        Handle(THREAD, loader), Handle(THREAD, protection_domain),
2541                                                        THREAD);
2542       assert(klass != NULL && !HAS_PENDING_EXCEPTION, "lookup shouldn't fail");
2543       const GrowableArray<SigEntry>& embedded = collect_fields(ValueKlass::cast(klass), offset);
2544       sig.appendAll(&embedded);
2545     } else {
2546       sig.push(SigEntry(bt, offset));
2547       if (bt == T_LONG || bt == T_DOUBLE) {
2548         sig.push(SigEntry(T_VOID, offset));
2549       }
2550     }
2551   }
2552   int offset = base_off + vk->size_helper()*HeapWordSize - (base_off > 0 ? vk->first_field_offset() : 0);
2553   sig.push(SigEntry(T_VOID, offset)); // hack: use T_VOID to mark end of value type fields
2554   if (base_off == 0) {
2555     sig.sort(SigEntry::compare);
2556   }
2557   assert(sig.at(0)._bt == T_VALUETYPE && sig.at(sig.length()-1)._bt == T_VOID, "broken structure");
2558   return sig;
2559 }
2560 
2561 AdapterHandlerEntry* AdapterHandlerLibrary::get_adapter(const methodHandle& method) {
2562   // Use customized signature handler.  Need to lock around updates to
2563   // the AdapterHandlerTable (it is not safe for concurrent readers
2564   // and a single writer: this could be fixed if it becomes a
2565   // problem).
2566 
2567   ResourceMark rm;
2568 
2569   NOT_PRODUCT(int insts_size = 0);
2570   AdapterBlob* new_adapter = NULL;
2571   AdapterHandlerEntry* entry = NULL;
2572   AdapterFingerPrint* fingerprint = NULL;
2573   {
2574     MutexLocker mu(AdapterHandlerLibrary_lock);
2575     // make sure data structure is initialized
2576     initialize();
2577 
2578     if (CodeCacheExtensions::skip_compiler_support()) {
2579       // adapters are useless and should not be used, including the
2580       // abstract_method_handler. However, some callers check that
2581       // an adapter was installed.
2582       // Return the singleton adapter, stored into _abstract_method_handler
2583       // and modified to cause an error if we ever call it.
2584       return _abstract_method_handler;
2585     }
2586 
2587     if (method->is_abstract()) {
2588       return _abstract_method_handler;
2589     }
2590 
2591     // Fill in the signature array, for the calling-convention call.
2592     GrowableArray<SigEntry> sig;
2593     {
2594       MutexUnlocker mul(AdapterHandlerLibrary_lock);
2595       Thread* THREAD = Thread::current();
2596       Handle class_loader(THREAD, method->method_holder()->class_loader());
2597       Handle protection_domain(THREAD, method->method_holder()->protection_domain());
2598       GrowableArray<BasicType> sig_bt_tmp;
2599       int value_klasses = 0;
2600 


2601       int i = 0;
2602       if (!method->is_static()) {  // Pass in receiver first
2603         Klass* holder = method->method_holder();
2604         if (ValueTypePassFieldsAsArgs && holder->is_value()) {
2605           value_klasses++;
2606           ValueKlass* vk = ValueKlass::cast(holder);
2607           const GrowableArray<SigEntry>& sig_vk = collect_fields(vk);
2608           sig.appendAll(&sig_vk);
2609         } else {
2610           sig.push(SigEntry(T_OBJECT));
2611         }
2612       }
2613       for (SignatureStream ss(method->signature()); !ss.at_return_type(); ss.next()) {
2614         if (ValueTypePassFieldsAsArgs && ss.type() == T_VALUETYPE) {
2615           value_klasses++;
2616           Klass* k = ss.as_klass(class_loader, protection_domain, SignatureStream::ReturnNull, THREAD);
2617           assert(k != NULL && !HAS_PENDING_EXCEPTION, "");
2618           ValueKlass* vk = ValueKlass::cast(k);
2619           const GrowableArray<SigEntry>& sig_vk = collect_fields(vk);
2620           sig.appendAll(&sig_vk);
2621         } else {
2622           sig.push(SigEntry(ss.type()));
2623           if (ss.type() == T_LONG || ss.type() == T_DOUBLE) {
2624             sig.push(SigEntry(T_VOID));
2625           }
2626         }
2627       }
2628     }
2629 
2630     int values = 0;
2631     if (ValueTypePassFieldsAsArgs) {
2632       for (int i = 0; i < sig.length(); i++) {
2633         if (sig.at(i)._bt == T_VALUETYPE) {
2634           values++;
2635         }
2636       }
2637     }
2638     int total_args_passed_cc = sig.length() - 2 * values;
2639     BasicType* sig_bt_cc = NEW_RESOURCE_ARRAY(BasicType, total_args_passed_cc);
2640     
2641     int j = 0;
2642     for (int i = 0; i < sig.length(); i++) {
2643       if (!ValueTypePassFieldsAsArgs) {
2644         sig_bt_cc[j++] = sig.at(i)._bt;
2645       } else if (sig.at(i)._bt != T_VALUETYPE &&
2646                  (sig.at(i)._bt != T_VOID ||
2647                   sig.at(i-1)._bt == T_LONG ||
2648                   sig.at(i-1)._bt == T_DOUBLE)) {
2649         sig_bt_cc[j++] = sig.at(i)._bt;
2650       }
2651     }
2652     assert(j == total_args_passed_cc, "");
2653 
2654     int total_args_passed_fp = sig.length();
2655     BasicType* sig_bt_fp = NEW_RESOURCE_ARRAY(BasicType, total_args_passed_fp);
2656     for (int i = 0; i < sig.length(); i++) {
2657       sig_bt_fp[i] = sig.at(i)._bt;
2658     }
2659 
2660     VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed_cc);
2661 
2662     // Lookup method signature's fingerprint
2663     entry = _adapters->lookup(total_args_passed_fp, sig_bt_fp);
2664 
2665 #ifdef ASSERT
2666     AdapterHandlerEntry* shared_entry = NULL;
2667     // Start adapter sharing verification only after the VM is booted.
2668     if (VerifyAdapterSharing && (entry != NULL)) {
2669       shared_entry = entry;
2670       entry = NULL;
2671     }
2672 #endif
2673 
2674     if (entry != NULL) {
2675       return entry;
2676     }
2677 
2678     // Get a description of the compiled java calling convention and the largest used (VMReg) stack slot usage
2679     int comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt_cc, regs, total_args_passed_cc, false);
2680 
2681     // Make a C heap allocated version of the fingerprint to store in the adapter
2682     fingerprint = new AdapterFingerPrint(total_args_passed_fp, sig_bt_fp);
2683 
2684     // StubRoutines::code2() is initialized after this function can be called. As a result,
2685     // VerifyAdapterCalls and VerifyAdapterSharing can fail if we re-use code that generated
2686     // prior to StubRoutines::code2() being set. Checks refer to checks generated in an I2C
2687     // stub that ensure that an I2C stub is called from an interpreter frame.
2688     bool contains_all_checks = StubRoutines::code2() != NULL;
2689 
2690     // Create I2C & C2I handlers
2691     BufferBlob* buf = buffer_blob(); // the temporary code buffer in CodeCache
2692     if (buf != NULL) {
2693       CodeBuffer buffer(buf);
2694       short buffer_locs[20];
2695       buffer.insts()->initialize_shared_locs((relocInfo*)buffer_locs,
2696                                              sizeof(buffer_locs)/sizeof(relocInfo));
2697 
2698 
2699       MacroAssembler _masm(&buffer);
2700       entry = SharedRuntime::generate_i2c2i_adapters(&_masm,

2701                                                      comp_args_on_stack,
2702                                                      sig,
2703                                                      regs,
2704                                                      fingerprint,
2705                                                      new_adapter);
2706 #ifdef ASSERT
2707       if (VerifyAdapterSharing) {
2708         if (shared_entry != NULL) {
2709           assert(shared_entry->compare_code(buf->code_begin(), buffer.insts_size()), "code must match");
2710           // Release the one just created and return the original
2711           _adapters->free_entry(entry);
2712           return shared_entry;
2713         } else  {
2714           entry->save_code(buf->code_begin(), buffer.insts_size());
2715         }
2716       }
2717 #endif
2718 

2719       NOT_PRODUCT(insts_size = buffer.insts_size());
2720     }
2721     if (new_adapter == NULL) {
2722       // CodeCache is full, disable compilation
2723       // Ought to log this but compile log is only per compile thread
2724       // and we're some non descript Java thread.
2725       return NULL; // Out of CodeCache space
2726     }
2727     entry->relocate(new_adapter->content_begin());
2728 #ifndef PRODUCT
2729     // debugging suppport
2730     if (PrintAdapterHandlers || PrintStubCode) {
2731       ttyLocker ttyl;
2732       entry->print_adapter_on(tty);
2733       tty->print_cr("i2c argument handler #%d for: %s %s %s (%d bytes generated)",
2734                     _adapters->number_of_entries(), (method->is_static() ? "static" : "receiver"),
2735                     method->signature()->as_C_string(), fingerprint->as_string(), insts_size);
2736       tty->print_cr("c2i argument handler starts at %p", entry->get_c2i_entry());
2737       if (Verbose || PrintStubCode) {
2738         address first_pc = entry->base_address();


3172           continue;
3173         }
3174       }
3175     }
3176     if (method->has_reserved_stack_access()) {
3177       ResourceMark rm(thread);
3178       activation = prv_fr;
3179       warning("Potentially dangerous stack overflow in "
3180               "ReservedStackAccess annotated method %s [%d]",
3181               method->name_and_sig_as_C_string(), count++);
3182       EventReservedStackActivation event;
3183       if (event.should_commit()) {
3184         event.set_method(method);
3185         event.commit();
3186       }
3187     }
3188   }
3189   return activation;
3190 }
3191 
3192 // We are at a compiled code to interpreter call. We need backing
3193 // buffers for all value type arguments. Allocate an object array to
3194 // hold them (convenient because once we're done with it we don't have
3195 // to worry about freeing it).
3196 JRT_ENTRY(void, SharedRuntime::allocate_value_types(JavaThread* thread))
3197 {
3198   assert(ValueTypePassFieldsAsArgs, "no reason to call this");
3199   ResourceMark rm;
3200   JavaThread* THREAD = thread;
3201   vframeStream vfst(thread);
3202   methodHandle caller(thread, vfst.method());
3203   int bci   = vfst.bci();
3204   Bytecode_invoke bytecode(caller, bci);
3205   methodHandle callee = bytecode.static_target(CHECK);
3206 
3207   int nb_slots = 0;
3208   if (!callee->is_static() && callee->method_holder()->is_value()) {
3209     nb_slots++;
3210   }
3211   Handle class_loader(THREAD, callee->method_holder()->class_loader());
3212   Handle protection_domain(THREAD, callee->method_holder()->protection_domain());
3213   for (SignatureStream ss(callee->signature()); !ss.at_return_type(); ss.next()) {
3214     if (ss.type() == T_VALUETYPE) {
3215       nb_slots++;
3216     }
3217   }
3218   objArrayHandle array = ObjArrayKlass::cast(Universe::objectArrayKlassObj())->allocate(nb_slots, CHECK);
3219   int i = 0;
3220   if (!callee->is_static() && callee->method_holder()->is_value()) {
3221     ValueKlass* vk = ValueKlass::cast(callee->method_holder());
3222     oop res = vk->allocate_instance(CHECK);
3223     array->obj_at_put(i, res);
3224     i++;
3225   }
3226   for (SignatureStream ss(callee->signature()); !ss.at_return_type(); ss.next()) {
3227     if (ss.type() == T_VALUETYPE) {
3228       Klass* k = ss.as_klass(class_loader, protection_domain, SignatureStream::ReturnNull, THREAD);
3229       assert(k != NULL && !HAS_PENDING_EXCEPTION, "");
3230       ValueKlass* vk = ValueKlass::cast(k);
3231       oop res = vk->allocate_instance(CHECK);
3232       array->obj_at_put(i, res);
3233       i++;
3234     }
3235   }
3236   thread->set_vm_result(array());
3237 }
3238 JRT_END
< prev index next >