< prev index next >

src/share/vm/runtime/sharedRuntime.cpp

Print this page




1091 }
1092 
1093 // Finds receiver, CallInfo (i.e. receiver method), and calling bytecode
1094 // for a call current in progress, i.e., arguments has been pushed on stack
1095 // but callee has not been invoked yet.  Caller frame must be compiled.
1096 Handle SharedRuntime::find_callee_info_helper(JavaThread* thread,
1097                                               vframeStream& vfst,
1098                                               Bytecodes::Code& bc,
1099                                               CallInfo& callinfo, TRAPS) {
1100   Handle receiver;
1101   Handle nullHandle;  //create a handy null handle for exception returns
1102 
1103   assert(!vfst.at_end(), "Java frame must exist");
1104 
1105   // Find caller and bci from vframe
1106   methodHandle caller(THREAD, vfst.method());
1107   int          bci   = vfst.bci();
1108 
1109   Bytecode_invoke bytecode(caller, bci);
1110   int bytecode_index = bytecode.index();

1111 
1112   methodHandle attached_method = extract_attached_method(vfst);
1113   if (attached_method.not_null()) {
1114     methodHandle callee = bytecode.static_target(CHECK_NH);
1115     vmIntrinsics::ID id = callee->intrinsic_id();
1116     // When VM replaces MH.invokeBasic/linkTo* call with a direct/virtual call,
1117     // it attaches statically resolved method to the call site.
1118     if (MethodHandles::is_signature_polymorphic(id) &&
1119         MethodHandles::is_signature_polymorphic_intrinsic(id)) {
1120       bc = MethodHandles::signature_polymorphic_intrinsic_bytecode(id);
1121 
1122       // Adjust invocation mode according to the attached method.
1123       switch (bc) {
1124         case Bytecodes::_invokeinterface:
1125           if (!attached_method->method_holder()->is_interface()) {
1126             bc = Bytecodes::_invokevirtual;
1127           }
1128           break;
1129         case Bytecodes::_invokehandle:
1130           if (!MethodHandles::is_signature_polymorphic_method(attached_method())) {
1131             bc = attached_method->is_static() ? Bytecodes::_invokestatic
1132                                               : Bytecodes::_invokevirtual;
1133           }
1134           break;
1135       }
1136     }
1137   } else {
1138     bc = bytecode.invoke_code();

1139   }
1140 
1141   bool has_receiver = bc != Bytecodes::_invokestatic &&
1142                       bc != Bytecodes::_invokedynamic &&
1143                       bc != Bytecodes::_invokehandle;
1144 
1145   // Find receiver for non-static call
1146   if (has_receiver) {
1147     // This register map must be update since we need to find the receiver for
1148     // compiled frames. The receiver might be in a register.
1149     RegisterMap reg_map2(thread);
1150     frame stubFrame   = thread->last_frame();
1151     // Caller-frame is a compiled frame
1152     frame callerFrame = stubFrame.sender(&reg_map2);
1153 
1154     methodHandle callee = attached_method;
1155     if (callee.is_null()) {
1156       callee = bytecode.static_target(CHECK_NH);
1157       if (callee.is_null()) {
1158         THROW_(vmSymbols::java_lang_NoSuchMethodException(), nullHandle);
1159       }
1160     }
1161     if (ValueTypePassFieldsAsArgs && callee->method_holder()->is_value()) {
1162       // If the receiver is a value type that is passed as fields, no oop is available.
1163       // Resolve the call without receiver null checking.
1164       assert(bc == Bytecodes::_invokevirtual, "only allowed with invokevirtual");

1165       constantPoolHandle constants(THREAD, caller->constants());
1166       LinkInfo link_info(constants, bytecode_index, CHECK_NH);
1167       LinkResolver::resolve_virtual_call(callinfo, receiver, NULL, link_info, /*check_null_or_abstract*/ false, CHECK_NH);
1168       return receiver; // is null
1169     } else {
1170       // Retrieve from a compiled argument list
1171       receiver = Handle(THREAD, callerFrame.retrieve_receiver(&reg_map2));
1172 
1173       if (receiver.is_null()) {
1174         THROW_(vmSymbols::java_lang_NullPointerException(), nullHandle);
1175       }
1176     }
1177   }
1178 
1179   assert(receiver.is_null() || receiver->is_oop(), "wrong receiver");
1180 
1181   // Resolve method
1182   if (attached_method.not_null()) {
1183     // Parameterized by attached method.
1184     LinkResolver::resolve_invoke(callinfo, receiver, attached_method, bc, CHECK_NH);
1185   } else {
1186     // Parameterized by bytecode.


1355   if (callee != NULL) {
1356     assert(callee->is_compiled(), "must be nmethod for patching");
1357   }
1358 
1359   if (callee != NULL && !callee->is_in_use()) {
1360     // Patch call site to C2I adapter if callee nmethod is deoptimized or unloaded.
1361     callee = NULL;
1362   }
1363   nmethodLocker nl_callee(callee);
1364 #ifdef ASSERT
1365   address dest_entry_point = callee == NULL ? 0 : callee->entry_point(); // used below
1366 #endif
1367 
1368   bool is_nmethod = caller_nm->is_nmethod();
1369 
1370   if (is_virtual) {
1371     Klass* receiver_klass = NULL;
1372     if (ValueTypePassFieldsAsArgs && callee_method->method_holder()->is_value()) {
1373       // If the receiver is a value type that is passed as fields, no oop is available
1374       receiver_klass = callee_method->method_holder();




1375     } else {
1376       assert(receiver.not_null() || invoke_code == Bytecodes::_invokehandle, "sanity check");
1377       receiver_klass = invoke_code == Bytecodes::_invokehandle ? NULL : receiver->klass();
1378     }
1379     bool static_bound = call_info.resolved_method()->can_be_statically_bound();
1380     CompiledIC::compute_monomorphic_entry(callee_method, receiver_klass,
1381                      is_optimized, static_bound, is_nmethod, virtual_call_info,
1382                      CHECK_(methodHandle()));
1383   } else {
1384     // static call
1385     CompiledStaticCall::compute_entry(callee_method, is_nmethod, static_call_info);
1386   }
1387 
1388   // grab lock, check for deoptimization and potentially patch caller
1389   {
1390     MutexLocker ml_patch(CompiledIC_lock);
1391 
1392     // Lock blocks for safepoint during which both nmethods can change state.
1393 
1394     // Now that we are ready to patch if the Method* was redefined then


2439 
2440  private:
2441 
2442 #ifndef PRODUCT
2443   static int _lookups; // number of calls to lookup
2444   static int _buckets; // number of buckets checked
2445   static int _equals;  // number of buckets checked with matching hash
2446   static int _hits;    // number of successful lookups
2447   static int _compact; // number of equals calls with compact signature
2448 #endif
2449 
2450   AdapterHandlerEntry* bucket(int i) {
2451     return (AdapterHandlerEntry*)BasicHashtable<mtCode>::bucket(i);
2452   }
2453 
2454  public:
2455   AdapterHandlerTable()
2456     : BasicHashtable<mtCode>(293, (DumpSharedSpaces ? sizeof(CDSAdapterHandlerEntry) : sizeof(AdapterHandlerEntry))) { }
2457 
2458   // Create a new entry suitable for insertion in the table
2459   AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry, address c2i_unverified_entry) {
2460     AdapterHandlerEntry* entry = (AdapterHandlerEntry*)BasicHashtable<mtCode>::new_entry(fingerprint->compute_hash());
2461     entry->init(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
2462     if (DumpSharedSpaces) {
2463       ((CDSAdapterHandlerEntry*)entry)->init();
2464     }
2465     return entry;
2466   }
2467 
2468   // Insert an entry into the table
2469   void add(AdapterHandlerEntry* entry) {
2470     int index = hash_to_index(entry->hash());
2471     add_entry(index, entry);
2472   }
2473 
2474   void free_entry(AdapterHandlerEntry* entry) {
2475     entry->deallocate();
2476     BasicHashtable<mtCode>::free_entry(entry);
2477   }
2478 
2479   // Find a entry with the same fingerprint if it exists
2480   AdapterHandlerEntry* lookup(int total_args_passed, BasicType* sig_bt) {
2481     NOT_PRODUCT(_lookups++);


2590 }
2591 
2592 void AdapterHandlerLibrary::initialize() {
2593   if (_adapters != NULL) return;
2594   _adapters = new AdapterHandlerTable();
2595 
2596   // Create a special handler for abstract methods.  Abstract methods
2597   // are never compiled so an i2c entry is somewhat meaningless, but
2598   // throw AbstractMethodError just in case.
2599   // Pass wrong_method_abstract for the c2i transitions to return
2600   // AbstractMethodError for invalid invocations.
2601   address wrong_method_abstract = SharedRuntime::get_handle_wrong_method_abstract_stub();
2602   _abstract_method_handler = AdapterHandlerLibrary::new_entry(new AdapterFingerPrint(0, NULL),
2603                                                               StubRoutines::throw_AbstractMethodError_entry(),
2604                                                               wrong_method_abstract, wrong_method_abstract);
2605 }
2606 
2607 AdapterHandlerEntry* AdapterHandlerLibrary::new_entry(AdapterFingerPrint* fingerprint,
2608                                                       address i2c_entry,
2609                                                       address c2i_entry,
2610                                                       address c2i_unverified_entry) {
2611   return _adapters->new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);

2612 }
2613 
2614 // Value type arguments are not passed by reference, instead each
2615 // field of the value type is passed as an argument. This helper
2616 // function collects the fields of the value types (including embedded
2617 // value type's fields) in a list. Included with the field's type is
2618 // the offset of each field in the value type: i2c and c2i adapters
2619 // need that to load or store fields. Finally, the list of fields is
2620 // sorted in order of increasing offsets: the adapters and the
2621 // compiled code need and agreed upon order of fields.
2622 //
2623 // The list of basic type that is returned starts with a T_VALUETYPE
2624 // and ends with an extra T_VOID. T_VALUETYPE/T_VOID are used as
2625 // delimiters. Every entry between the two is a field of the value
2626 // type. If there's an embedded value type in the list, it also starts
2627 // with a T_VALUETYPE and ends with a T_VOID. This is so we can
2628 // generate a unique fingerprint for the method's adapters and we can
2629 // generate the list of basic types from the interpreter point of view
2630 // (value types passed as reference: iterate on the list until a
2631 // T_VALUETYPE, drop everything until and including the closing


3334   objArrayHandle array(THREAD, array_oop);
3335   int i = 0;
3336   if (has_value_receiver) {
3337     ValueKlass* vk = ValueKlass::cast(callee->method_holder());
3338     oop res = vk->allocate_instance(CHECK);
3339     array->obj_at_put(i, res);
3340     i++;
3341   }
3342   for (SignatureStream ss(callee->signature()); !ss.at_return_type(); ss.next()) {
3343     if (ss.type() == T_VALUETYPE) {
3344       Klass* k = ss.as_klass(class_loader, protection_domain, SignatureStream::ReturnNull, THREAD);
3345       assert(k != NULL && !HAS_PENDING_EXCEPTION, "can't resolve klass");
3346       ValueKlass* vk = ValueKlass::cast(k);
3347       oop res = vk->allocate_instance(CHECK);
3348       array->obj_at_put(i, res);
3349       i++;
3350     }
3351   }
3352   thread->set_vm_result(array());
3353   thread->set_vm_result_2(callee()); // TODO: required to keep callee live?























3354 }
3355 JRT_END


1091 }
1092 
1093 // Finds receiver, CallInfo (i.e. receiver method), and calling bytecode
1094 // for a call current in progress, i.e., arguments has been pushed on stack
1095 // but callee has not been invoked yet.  Caller frame must be compiled.
1096 Handle SharedRuntime::find_callee_info_helper(JavaThread* thread,
1097                                               vframeStream& vfst,
1098                                               Bytecodes::Code& bc,
1099                                               CallInfo& callinfo, TRAPS) {
1100   Handle receiver;
1101   Handle nullHandle;  //create a handy null handle for exception returns
1102 
1103   assert(!vfst.at_end(), "Java frame must exist");
1104 
1105   // Find caller and bci from vframe
1106   methodHandle caller(THREAD, vfst.method());
1107   int          bci   = vfst.bci();
1108 
1109   Bytecode_invoke bytecode(caller, bci);
1110   int bytecode_index = bytecode.index();
1111   bc = bytecode.invoke_code();
1112 
1113   methodHandle attached_method = extract_attached_method(vfst);
1114   if (attached_method.not_null()) {
1115     methodHandle callee = bytecode.static_target(CHECK_NH);
1116     vmIntrinsics::ID id = callee->intrinsic_id();
1117     // When VM replaces MH.invokeBasic/linkTo* call with a direct/virtual call,
1118     // it attaches statically resolved method to the call site.
1119     if (MethodHandles::is_signature_polymorphic(id) &&
1120         MethodHandles::is_signature_polymorphic_intrinsic(id)) {
1121       bc = MethodHandles::signature_polymorphic_intrinsic_bytecode(id);
1122 
1123       // Adjust invocation mode according to the attached method.
1124       switch (bc) {
1125         case Bytecodes::_invokeinterface:
1126           if (!attached_method->method_holder()->is_interface()) {
1127             bc = Bytecodes::_invokevirtual;
1128           }
1129           break;
1130         case Bytecodes::_invokehandle:
1131           if (!MethodHandles::is_signature_polymorphic_method(attached_method())) {
1132             bc = attached_method->is_static() ? Bytecodes::_invokestatic
1133                                               : Bytecodes::_invokevirtual;
1134           }
1135           break;
1136       }

1137     } else {
1138       assert(ValueTypePassFieldsAsArgs, "invalid use of attached methods");
1139     }
1140   }
1141 
1142   bool has_receiver = bc != Bytecodes::_invokestatic &&
1143                       bc != Bytecodes::_invokedynamic &&
1144                       bc != Bytecodes::_invokehandle;
1145 
1146   // Find receiver for non-static call
1147   if (has_receiver) {
1148     // This register map must be update since we need to find the receiver for
1149     // compiled frames. The receiver might be in a register.
1150     RegisterMap reg_map2(thread);
1151     frame stubFrame   = thread->last_frame();
1152     // Caller-frame is a compiled frame
1153     frame callerFrame = stubFrame.sender(&reg_map2);
1154 
1155     methodHandle callee = attached_method;
1156     if (callee.is_null()) {
1157       callee = bytecode.static_target(CHECK_NH);
1158       if (callee.is_null()) {
1159         THROW_(vmSymbols::java_lang_NoSuchMethodException(), nullHandle);
1160       }
1161     }
1162     if (ValueTypePassFieldsAsArgs && callee->method_holder()->is_value()) {
1163       // If the receiver is a value type that is passed as fields, no oop is available.
1164       // Resolve the call without receiver null checking.
1165       assert(bc == Bytecodes::_invokevirtual, "only allowed with invokevirtual");
1166       assert(!attached_method.is_null(), "must have attached method");
1167       constantPoolHandle constants(THREAD, caller->constants());
1168       LinkInfo link_info(attached_method->method_holder(), attached_method->name(), attached_method->signature());
1169       LinkResolver::resolve_virtual_call(callinfo, receiver, NULL, link_info, /*check_null_or_abstract*/ false, CHECK_NH);
1170       return receiver; // is null
1171     } else {
1172       // Retrieve from a compiled argument list
1173       receiver = Handle(THREAD, callerFrame.retrieve_receiver(&reg_map2));
1174 
1175       if (receiver.is_null()) {
1176         THROW_(vmSymbols::java_lang_NullPointerException(), nullHandle);
1177       }
1178     }
1179   }
1180 
1181   assert(receiver.is_null() || receiver->is_oop(), "wrong receiver");
1182 
1183   // Resolve method
1184   if (attached_method.not_null()) {
1185     // Parameterized by attached method.
1186     LinkResolver::resolve_invoke(callinfo, receiver, attached_method, bc, CHECK_NH);
1187   } else {
1188     // Parameterized by bytecode.


1357   if (callee != NULL) {
1358     assert(callee->is_compiled(), "must be nmethod for patching");
1359   }
1360 
1361   if (callee != NULL && !callee->is_in_use()) {
1362     // Patch call site to C2I adapter if callee nmethod is deoptimized or unloaded.
1363     callee = NULL;
1364   }
1365   nmethodLocker nl_callee(callee);
1366 #ifdef ASSERT
1367   address dest_entry_point = callee == NULL ? 0 : callee->entry_point(); // used below
1368 #endif
1369 
1370   bool is_nmethod = caller_nm->is_nmethod();
1371 
1372   if (is_virtual) {
1373     Klass* receiver_klass = NULL;
1374     if (ValueTypePassFieldsAsArgs && callee_method->method_holder()->is_value()) {
1375       // If the receiver is a value type that is passed as fields, no oop is available
1376       receiver_klass = callee_method->method_holder();
1377       if (FullGCALotWithValueTypes) {
1378         // Trigger a full GC to verify that the GC knows about the contents of oop fields
1379         Universe::heap()->collect(GCCause::_full_gc_alot);
1380       }
1381     } else {
1382       assert(receiver.not_null() || invoke_code == Bytecodes::_invokehandle, "sanity check");
1383       receiver_klass = invoke_code == Bytecodes::_invokehandle ? NULL : receiver->klass();
1384     }
1385     bool static_bound = call_info.resolved_method()->can_be_statically_bound();
1386     CompiledIC::compute_monomorphic_entry(callee_method, receiver_klass,
1387                      is_optimized, static_bound, is_nmethod, virtual_call_info,
1388                      CHECK_(methodHandle()));
1389   } else {
1390     // static call
1391     CompiledStaticCall::compute_entry(callee_method, is_nmethod, static_call_info);
1392   }
1393 
1394   // grab lock, check for deoptimization and potentially patch caller
1395   {
1396     MutexLocker ml_patch(CompiledIC_lock);
1397 
1398     // Lock blocks for safepoint during which both nmethods can change state.
1399 
1400     // Now that we are ready to patch if the Method* was redefined then


2445 
2446  private:
2447 
2448 #ifndef PRODUCT
2449   static int _lookups; // number of calls to lookup
2450   static int _buckets; // number of buckets checked
2451   static int _equals;  // number of buckets checked with matching hash
2452   static int _hits;    // number of successful lookups
2453   static int _compact; // number of equals calls with compact signature
2454 #endif
2455 
2456   AdapterHandlerEntry* bucket(int i) {
2457     return (AdapterHandlerEntry*)BasicHashtable<mtCode>::bucket(i);
2458   }
2459 
2460  public:
2461   AdapterHandlerTable()
2462     : BasicHashtable<mtCode>(293, (DumpSharedSpaces ? sizeof(CDSAdapterHandlerEntry) : sizeof(AdapterHandlerEntry))) { }
2463 
2464   // Create a new entry suitable for insertion in the table
2465   AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry, address c2i_unverified_entry, Symbol* sig_extended) {
2466     AdapterHandlerEntry* entry = (AdapterHandlerEntry*)BasicHashtable<mtCode>::new_entry(fingerprint->compute_hash());
2467     entry->init(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry, sig_extended);
2468     if (DumpSharedSpaces) {
2469       ((CDSAdapterHandlerEntry*)entry)->init();
2470     }
2471     return entry;
2472   }
2473 
2474   // Insert an entry into the table
2475   void add(AdapterHandlerEntry* entry) {
2476     int index = hash_to_index(entry->hash());
2477     add_entry(index, entry);
2478   }
2479 
2480   void free_entry(AdapterHandlerEntry* entry) {
2481     entry->deallocate();
2482     BasicHashtable<mtCode>::free_entry(entry);
2483   }
2484 
2485   // Find a entry with the same fingerprint if it exists
2486   AdapterHandlerEntry* lookup(int total_args_passed, BasicType* sig_bt) {
2487     NOT_PRODUCT(_lookups++);


2596 }
2597 
2598 void AdapterHandlerLibrary::initialize() {
2599   if (_adapters != NULL) return;
2600   _adapters = new AdapterHandlerTable();
2601 
2602   // Create a special handler for abstract methods.  Abstract methods
2603   // are never compiled so an i2c entry is somewhat meaningless, but
2604   // throw AbstractMethodError just in case.
2605   // Pass wrong_method_abstract for the c2i transitions to return
2606   // AbstractMethodError for invalid invocations.
2607   address wrong_method_abstract = SharedRuntime::get_handle_wrong_method_abstract_stub();
2608   _abstract_method_handler = AdapterHandlerLibrary::new_entry(new AdapterFingerPrint(0, NULL),
2609                                                               StubRoutines::throw_AbstractMethodError_entry(),
2610                                                               wrong_method_abstract, wrong_method_abstract);
2611 }
2612 
2613 AdapterHandlerEntry* AdapterHandlerLibrary::new_entry(AdapterFingerPrint* fingerprint,
2614                                                       address i2c_entry,
2615                                                       address c2i_entry,
2616                                                       address c2i_unverified_entry,
2617                                                       Symbol* sig_extended) {
2618   return _adapters->new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry, sig_extended);
2619 }
2620 
2621 // Value type arguments are not passed by reference, instead each
2622 // field of the value type is passed as an argument. This helper
2623 // function collects the fields of the value types (including embedded
2624 // value type's fields) in a list. Included with the field's type is
2625 // the offset of each field in the value type: i2c and c2i adapters
2626 // need that to load or store fields. Finally, the list of fields is
2627 // sorted in order of increasing offsets: the adapters and the
2628 // compiled code need and agreed upon order of fields.
2629 //
2630 // The list of basic type that is returned starts with a T_VALUETYPE
2631 // and ends with an extra T_VOID. T_VALUETYPE/T_VOID are used as
2632 // delimiters. Every entry between the two is a field of the value
2633 // type. If there's an embedded value type in the list, it also starts
2634 // with a T_VALUETYPE and ends with a T_VOID. This is so we can
2635 // generate a unique fingerprint for the method's adapters and we can
2636 // generate the list of basic types from the interpreter point of view
2637 // (value types passed as reference: iterate on the list until a
2638 // T_VALUETYPE, drop everything until and including the closing


3341   objArrayHandle array(THREAD, array_oop);
3342   int i = 0;
3343   if (has_value_receiver) {
3344     ValueKlass* vk = ValueKlass::cast(callee->method_holder());
3345     oop res = vk->allocate_instance(CHECK);
3346     array->obj_at_put(i, res);
3347     i++;
3348   }
3349   for (SignatureStream ss(callee->signature()); !ss.at_return_type(); ss.next()) {
3350     if (ss.type() == T_VALUETYPE) {
3351       Klass* k = ss.as_klass(class_loader, protection_domain, SignatureStream::ReturnNull, THREAD);
3352       assert(k != NULL && !HAS_PENDING_EXCEPTION, "can't resolve klass");
3353       ValueKlass* vk = ValueKlass::cast(k);
3354       oop res = vk->allocate_instance(CHECK);
3355       array->obj_at_put(i, res);
3356       i++;
3357     }
3358   }
3359   thread->set_vm_result(array());
3360   thread->set_vm_result_2(callee()); // TODO: required to keep callee live?
3361 }
3362 JRT_END
3363 
3364 // Iterate of the array of heap allocated value types and apply the GC post barrier to all reference fields.
3365 // This is called from the C2I adapter after value type arguments are heap allocated and initialized.
3366 JRT_LEAF(void, SharedRuntime::apply_post_barriers(JavaThread* thread, objArrayOopDesc* array))
3367 {
3368   assert(ValueTypePassFieldsAsArgs, "no reason to call this");
3369   assert(array->is_oop(), "should be oop");
3370   for (int i = 0; i < array->length(); ++i) {
3371     instanceOop valueOop = (instanceOop)array->obj_at(i);
3372     ValueKlass* vk = ValueKlass::cast(valueOop->klass());
3373     if (vk->contains_oops()) {
3374       const address dst_oop_addr = ((address) (void*) valueOop);
3375       OopMapBlock* map = vk->start_of_nonstatic_oop_maps();
3376       OopMapBlock* const end = map + vk->nonstatic_oop_map_count();
3377       while (map != end) {
3378         address doop_address = dst_oop_addr + map->offset();
3379         oopDesc::bs()->write_ref_array((HeapWord*) doop_address, map->count());
3380         map++;
3381       }
3382     }
3383   }
3384 }
3385 JRT_END
< prev index next >