3218 __ sldi(Rret_type, Rret_type, LogBytesPerWord);
3219 // Get return address.
3220 __ ldx(Rret_addr, Rtable_addr, Rret_type);
3221 }
3222 }
3223
3224 // Helper for virtual calls. Load target out of vtable and jump off!
3225 // Kills all passed registers.
3226 void TemplateTable::generate_vtable_call(Register Rrecv_klass, Register Rindex, Register Rret, Register Rtemp) {
3227
3228 assert_different_registers(Rrecv_klass, Rtemp, Rret);
3229 const Register Rtarget_method = Rindex;
3230
3231 // Get target method & entry point.
3232 const int base = InstanceKlass::vtable_start_offset() * wordSize;
3233 // Calc vtable addr scale the vtable index by 8.
3234 __ sldi(Rindex, Rindex, exact_log2(vtableEntry::size() * wordSize));
3235 // Load target.
3236 __ addi(Rrecv_klass, Rrecv_klass, base + vtableEntry::method_offset_in_bytes());
3237 __ ldx(Rtarget_method, Rindex, Rrecv_klass);
3238 __ call_from_interpreter(Rtarget_method, Rret, Rrecv_klass /* scratch1 */, Rtemp /* scratch2 */);
3239 }
3240
3241 // Virtual or final call. Final calls are rewritten on the fly to run through "fast_finalcall" next time.
3242 void TemplateTable::invokevirtual(int byte_no) {
3243 transition(vtos, vtos);
3244
3245 Register Rtable_addr = R11_scratch1,
3246 Rret_type = R12_scratch2,
3247 Rret_addr = R5_ARG3,
3248 Rflags = R22_tmp2, // Should survive C call.
3249 Rrecv = R3_ARG1,
3250 Rrecv_klass = Rrecv,
3251 Rvtableindex_or_method = R31, // Should survive C call.
3252 Rnum_params = R4_ARG2,
3253 Rnew_bc = R6_ARG4;
3254
3255 Label LnotFinal;
3256
3257 load_invoke_cp_cache_entry(byte_no, Rvtableindex_or_method, noreg, Rflags, /*virtual*/ true, false, false);
3301 Register Rnum_params = Rrecv;
3302
3303 __ ld(Rnum_params, in_bytes(Method::const_offset()), Rmethod);
3304 __ lhz(Rnum_params /* number of params */, in_bytes(ConstMethod::size_of_parameters_offset()), Rnum_params);
3305
3306 // Get return address.
3307 Register Rtable_addr = Rscratch1,
3308 Rret_addr = Rflags,
3309 Rret_type = Rret_addr;
3310 // Get return type. It's coded into the upper 4 bits of the lower half of the 64 bit value.
3311 __ rldicl(Rret_type, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits);
3312 __ load_dispatch_table(Rtable_addr, Interpreter::invoke_return_entry_table());
3313 __ sldi(Rret_type, Rret_type, LogBytesPerWord);
3314 __ ldx(Rret_addr, Rret_type, Rtable_addr);
3315
3316 // Load receiver and receiver NULL check.
3317 __ load_receiver(Rnum_params, Rrecv);
3318 __ null_check_throw(Rrecv, -1, Rscratch1);
3319
3320 __ profile_final_call(Rrecv, Rscratch1);
3321
3322 // Do the call.
3323 __ call_from_interpreter(Rmethod, Rret_addr, Rscratch1, Rscratch2);
3324 }
3325
3326 void TemplateTable::invokespecial(int byte_no) {
3327 assert(byte_no == f1_byte, "use this argument");
3328 transition(vtos, vtos);
3329
3330 Register Rtable_addr = R3_ARG1,
3331 Rret_addr = R4_ARG2,
3332 Rflags = R5_ARG3,
3333 Rreceiver = R6_ARG4,
3334 Rmethod = R31;
3335
3336 prepare_invoke(byte_no, Rmethod, Rret_addr, noreg, Rreceiver, Rflags, R11_scratch1);
3337
3338 // Receiver NULL check.
3339 __ null_check_throw(Rreceiver, -1, R11_scratch1);
3340
3341 __ profile_call(R11_scratch1, R12_scratch2);
3342 __ call_from_interpreter(Rmethod, Rret_addr, R11_scratch1, R12_scratch2);
3343 }
3344
3345 void TemplateTable::invokestatic(int byte_no) {
3346 assert(byte_no == f1_byte, "use this argument");
3347 transition(vtos, vtos);
3348
3349 Register Rtable_addr = R3_ARG1,
3350 Rret_addr = R4_ARG2,
3351 Rflags = R5_ARG3;
3352
3353 prepare_invoke(byte_no, R19_method, Rret_addr, noreg, noreg, Rflags, R11_scratch1);
3354
3355 __ profile_call(R11_scratch1, R12_scratch2);
3356 __ call_from_interpreter(R19_method, Rret_addr, R11_scratch1, R12_scratch2);
3357 }
3358
3359 void TemplateTable::invokeinterface_object_method(Register Rrecv_klass,
3360 Register Rret,
3361 Register Rflags,
3362 Register Rindex,
3363 Register Rtemp1,
3364 Register Rtemp2) {
3365
3366 assert_different_registers(Rindex, Rret, Rrecv_klass, Rflags, Rtemp1, Rtemp2);
3367 Label LnotFinal;
3368
3369 // Check for vfinal.
3370 __ testbitdi(CCR0, R0, Rflags, ConstantPoolCacheEntry::is_vfinal_shift);
3371 __ bfalse(CCR0, LnotFinal);
3372
3373 Register Rscratch = Rflags; // Rflags is dead now.
3374
3375 // Final call case.
3376 __ profile_final_call(Rtemp1, Rscratch);
3377 // Do the final call - the index (f2) contains the method.
3378 __ call_from_interpreter(Rindex, Rret, Rscratch, Rrecv_klass /* scratch */);
3379
3380 // Non-final callc case.
3381 __ bind(LnotFinal);
3382 __ profile_virtual_call(Rrecv_klass, Rtemp1, Rscratch, false);
3383 generate_vtable_call(Rrecv_klass, Rindex, Rret, Rscratch);
3384 }
3385
3386 void TemplateTable::invokeinterface(int byte_no) {
3387 assert(byte_no == f1_byte, "use this argument");
3388 transition(vtos, vtos);
3389
3390 const Register Rscratch1 = R11_scratch1,
3391 Rscratch2 = R12_scratch2,
3392 Rscratch3 = R9_ARG7,
3393 Rscratch4 = R10_ARG8,
3394 Rtable_addr = Rscratch2,
3395 Rinterface_klass = R5_ARG3,
3396 Rret_type = R8_ARG6,
3408
3409 // Check corner case object method.
3410 Label LobjectMethod;
3411
3412 __ testbitdi(CCR0, R0, Rflags, ConstantPoolCacheEntry::is_forced_virtual_shift);
3413 __ btrue(CCR0, LobjectMethod);
3414
3415 // Fallthrough: The normal invokeinterface case.
3416 __ profile_virtual_call(Rrecv_klass, Rscratch1, Rscratch2, false);
3417
3418 // Find entry point to call.
3419 Label Lthrow_icc, Lthrow_ame;
3420 // Result will be returned in Rindex.
3421 __ mr(Rscratch4, Rrecv_klass);
3422 __ mr(Rscratch3, Rindex);
3423 __ lookup_interface_method(Rrecv_klass, Rinterface_klass, Rindex, Rindex, Rscratch1, Rscratch2, Lthrow_icc);
3424
3425 __ cmpdi(CCR0, Rindex, 0);
3426 __ beq(CCR0, Lthrow_ame);
3427 // Found entry. Jump off!
3428 __ call_from_interpreter(Rindex, Rret_addr, Rscratch1, Rscratch2);
3429
3430 // Vtable entry was NULL => Throw abstract method error.
3431 __ bind(Lthrow_ame);
3432 __ mr(Rrecv_klass, Rscratch4);
3433 __ mr(Rindex, Rscratch3);
3434 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
3435
3436 // Interface was not found => Throw incompatible class change error.
3437 __ bind(Lthrow_icc);
3438 __ mr(Rrecv_klass, Rscratch4);
3439 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_IncompatibleClassChangeError));
3440
3441 __ should_not_reach_here();
3442
3443 // Special case of invokeinterface called for virtual method of
3444 // java.lang.Object. See ConstantPoolCacheEntry::set_method() for details:
3445 // The invokeinterface was rewritten to a invokevirtual, hence we have
3446 // to handle this corner case. This code isn't produced by javac, but could
3447 // be produced by another compliant java compiler.
3451
3452 void TemplateTable::invokedynamic(int byte_no) {
3453 transition(vtos, vtos);
3454
3455 const Register Rret_addr = R3_ARG1,
3456 Rflags = R4_ARG2,
3457 Rmethod = R22_tmp2,
3458 Rscratch1 = R11_scratch1,
3459 Rscratch2 = R12_scratch2;
3460
3461 prepare_invoke(byte_no, Rmethod, Rret_addr, Rscratch1, noreg, Rflags, Rscratch2);
3462
3463 // Profile this call.
3464 __ profile_call(Rscratch1, Rscratch2);
3465
3466 // Off we go. With the new method handles, we don't jump to a method handle
3467 // entry any more. Instead, we pushed an "appendix" in prepare invoke, which happens
3468 // to be the callsite object the bootstrap method returned. This is passed to a
3469 // "link" method which does the dispatch (Most likely just grabs the MH stored
3470 // inside the callsite and does an invokehandle).
3471 __ call_from_interpreter(Rmethod, Rret_addr, Rscratch1 /* scratch1 */, Rscratch2 /* scratch2 */);
3472 }
3473
3474 void TemplateTable::invokehandle(int byte_no) {
3475 transition(vtos, vtos);
3476
3477 const Register Rret_addr = R3_ARG1,
3478 Rflags = R4_ARG2,
3479 Rrecv = R5_ARG3,
3480 Rmethod = R22_tmp2,
3481 Rscratch1 = R11_scratch1,
3482 Rscratch2 = R12_scratch2;
3483
3484 prepare_invoke(byte_no, Rmethod, Rret_addr, Rscratch1, Rrecv, Rflags, Rscratch2);
3485 __ verify_method_ptr(Rmethod);
3486 __ null_check_throw(Rrecv, -1, Rscratch2);
3487
3488 __ profile_final_call(Rrecv, Rscratch1);
3489
3490 // Still no call from handle => We call the method handle interpreter here.
3491 __ call_from_interpreter(Rmethod, Rret_addr, Rscratch1 /* scratch1 */, Rscratch2 /* scratch2 */);
3492 }
3493
3494 // =============================================================================
3495 // Allocation
3496
3497 // Puts allocated obj ref onto the expression stack.
3498 void TemplateTable::_new() {
3499 transition(vtos, atos);
3500
3501 Label Lslow_case,
3502 Ldone,
3503 Linitialize_header,
3504 Lallocate_shared,
3505 Linitialize_object; // Including clearing the fields.
3506
3507 const Register RallocatedObject = R17_tos,
3508 RinstanceKlass = R9_ARG7,
3509 Rscratch = R11_scratch1,
3510 Roffset = R8_ARG6,
|
3218 __ sldi(Rret_type, Rret_type, LogBytesPerWord);
3219 // Get return address.
3220 __ ldx(Rret_addr, Rtable_addr, Rret_type);
3221 }
3222 }
3223
3224 // Helper for virtual calls. Load target out of vtable and jump off!
3225 // Kills all passed registers.
3226 void TemplateTable::generate_vtable_call(Register Rrecv_klass, Register Rindex, Register Rret, Register Rtemp) {
3227
3228 assert_different_registers(Rrecv_klass, Rtemp, Rret);
3229 const Register Rtarget_method = Rindex;
3230
3231 // Get target method & entry point.
3232 const int base = InstanceKlass::vtable_start_offset() * wordSize;
3233 // Calc vtable addr scale the vtable index by 8.
3234 __ sldi(Rindex, Rindex, exact_log2(vtableEntry::size() * wordSize));
3235 // Load target.
3236 __ addi(Rrecv_klass, Rrecv_klass, base + vtableEntry::method_offset_in_bytes());
3237 __ ldx(Rtarget_method, Rindex, Rrecv_klass);
3238 // Argument and return type profiling.
3239 __ profile_arguments_type(Rtarget_method, Rrecv_klass /* scratch1 */, Rtemp /* scratch2 */, true);
3240 __ call_from_interpreter(Rtarget_method, Rret, Rrecv_klass /* scratch1 */, Rtemp /* scratch2 */);
3241 }
3242
3243 // Virtual or final call. Final calls are rewritten on the fly to run through "fast_finalcall" next time.
3244 void TemplateTable::invokevirtual(int byte_no) {
3245 transition(vtos, vtos);
3246
3247 Register Rtable_addr = R11_scratch1,
3248 Rret_type = R12_scratch2,
3249 Rret_addr = R5_ARG3,
3250 Rflags = R22_tmp2, // Should survive C call.
3251 Rrecv = R3_ARG1,
3252 Rrecv_klass = Rrecv,
3253 Rvtableindex_or_method = R31, // Should survive C call.
3254 Rnum_params = R4_ARG2,
3255 Rnew_bc = R6_ARG4;
3256
3257 Label LnotFinal;
3258
3259 load_invoke_cp_cache_entry(byte_no, Rvtableindex_or_method, noreg, Rflags, /*virtual*/ true, false, false);
3303 Register Rnum_params = Rrecv;
3304
3305 __ ld(Rnum_params, in_bytes(Method::const_offset()), Rmethod);
3306 __ lhz(Rnum_params /* number of params */, in_bytes(ConstMethod::size_of_parameters_offset()), Rnum_params);
3307
3308 // Get return address.
3309 Register Rtable_addr = Rscratch1,
3310 Rret_addr = Rflags,
3311 Rret_type = Rret_addr;
3312 // Get return type. It's coded into the upper 4 bits of the lower half of the 64 bit value.
3313 __ rldicl(Rret_type, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits);
3314 __ load_dispatch_table(Rtable_addr, Interpreter::invoke_return_entry_table());
3315 __ sldi(Rret_type, Rret_type, LogBytesPerWord);
3316 __ ldx(Rret_addr, Rret_type, Rtable_addr);
3317
3318 // Load receiver and receiver NULL check.
3319 __ load_receiver(Rnum_params, Rrecv);
3320 __ null_check_throw(Rrecv, -1, Rscratch1);
3321
3322 __ profile_final_call(Rrecv, Rscratch1);
3323 // Argument and return type profiling.
3324 __ profile_arguments_type(Rmethod, Rscratch1, Rscratch2, true);
3325
3326 // Do the call.
3327 __ call_from_interpreter(Rmethod, Rret_addr, Rscratch1, Rscratch2);
3328 }
3329
3330 void TemplateTable::invokespecial(int byte_no) {
3331 assert(byte_no == f1_byte, "use this argument");
3332 transition(vtos, vtos);
3333
3334 Register Rtable_addr = R3_ARG1,
3335 Rret_addr = R4_ARG2,
3336 Rflags = R5_ARG3,
3337 Rreceiver = R6_ARG4,
3338 Rmethod = R31;
3339
3340 prepare_invoke(byte_no, Rmethod, Rret_addr, noreg, Rreceiver, Rflags, R11_scratch1);
3341
3342 // Receiver NULL check.
3343 __ null_check_throw(Rreceiver, -1, R11_scratch1);
3344
3345 __ profile_call(R11_scratch1, R12_scratch2);
3346 // Argument and return type profiling.
3347 __ profile_arguments_type(Rmethod, R11_scratch1, R12_scratch2, false);
3348 __ call_from_interpreter(Rmethod, Rret_addr, R11_scratch1, R12_scratch2);
3349 }
3350
3351 void TemplateTable::invokestatic(int byte_no) {
3352 assert(byte_no == f1_byte, "use this argument");
3353 transition(vtos, vtos);
3354
3355 Register Rtable_addr = R3_ARG1,
3356 Rret_addr = R4_ARG2,
3357 Rflags = R5_ARG3;
3358
3359 prepare_invoke(byte_no, R19_method, Rret_addr, noreg, noreg, Rflags, R11_scratch1);
3360
3361 __ profile_call(R11_scratch1, R12_scratch2);
3362 // Argument and return type profiling.
3363 __ profile_arguments_type(R19_method, R11_scratch1, R12_scratch2, false);
3364 __ call_from_interpreter(R19_method, Rret_addr, R11_scratch1, R12_scratch2);
3365 }
3366
3367 void TemplateTable::invokeinterface_object_method(Register Rrecv_klass,
3368 Register Rret,
3369 Register Rflags,
3370 Register Rindex,
3371 Register Rtemp1,
3372 Register Rtemp2) {
3373
3374 assert_different_registers(Rindex, Rret, Rrecv_klass, Rflags, Rtemp1, Rtemp2);
3375 Label LnotFinal;
3376
3377 // Check for vfinal.
3378 __ testbitdi(CCR0, R0, Rflags, ConstantPoolCacheEntry::is_vfinal_shift);
3379 __ bfalse(CCR0, LnotFinal);
3380
3381 Register Rscratch = Rflags; // Rflags is dead now.
3382
3383 // Final call case.
3384 __ profile_final_call(Rtemp1, Rscratch);
3385 // Argument and return type profiling.
3386 __ profile_arguments_type(Rindex, Rscratch, Rrecv_klass /* scratch */, true);
3387 // Do the final call - the index (f2) contains the method.
3388 __ call_from_interpreter(Rindex, Rret, Rscratch, Rrecv_klass /* scratch */);
3389
3390 // Non-final callc case.
3391 __ bind(LnotFinal);
3392 __ profile_virtual_call(Rrecv_klass, Rtemp1, Rscratch, false);
3393 generate_vtable_call(Rrecv_klass, Rindex, Rret, Rscratch);
3394 }
3395
3396 void TemplateTable::invokeinterface(int byte_no) {
3397 assert(byte_no == f1_byte, "use this argument");
3398 transition(vtos, vtos);
3399
3400 const Register Rscratch1 = R11_scratch1,
3401 Rscratch2 = R12_scratch2,
3402 Rscratch3 = R9_ARG7,
3403 Rscratch4 = R10_ARG8,
3404 Rtable_addr = Rscratch2,
3405 Rinterface_klass = R5_ARG3,
3406 Rret_type = R8_ARG6,
3418
3419 // Check corner case object method.
3420 Label LobjectMethod;
3421
3422 __ testbitdi(CCR0, R0, Rflags, ConstantPoolCacheEntry::is_forced_virtual_shift);
3423 __ btrue(CCR0, LobjectMethod);
3424
3425 // Fallthrough: The normal invokeinterface case.
3426 __ profile_virtual_call(Rrecv_klass, Rscratch1, Rscratch2, false);
3427
3428 // Find entry point to call.
3429 Label Lthrow_icc, Lthrow_ame;
3430 // Result will be returned in Rindex.
3431 __ mr(Rscratch4, Rrecv_klass);
3432 __ mr(Rscratch3, Rindex);
3433 __ lookup_interface_method(Rrecv_klass, Rinterface_klass, Rindex, Rindex, Rscratch1, Rscratch2, Lthrow_icc);
3434
3435 __ cmpdi(CCR0, Rindex, 0);
3436 __ beq(CCR0, Lthrow_ame);
3437 // Found entry. Jump off!
3438 // Argument and return type profiling.
3439 __ profile_arguments_type(Rindex, Rscratch1, Rscratch2, true);
3440 __ call_from_interpreter(Rindex, Rret_addr, Rscratch1, Rscratch2);
3441
3442 // Vtable entry was NULL => Throw abstract method error.
3443 __ bind(Lthrow_ame);
3444 __ mr(Rrecv_klass, Rscratch4);
3445 __ mr(Rindex, Rscratch3);
3446 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
3447
3448 // Interface was not found => Throw incompatible class change error.
3449 __ bind(Lthrow_icc);
3450 __ mr(Rrecv_klass, Rscratch4);
3451 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_IncompatibleClassChangeError));
3452
3453 __ should_not_reach_here();
3454
3455 // Special case of invokeinterface called for virtual method of
3456 // java.lang.Object. See ConstantPoolCacheEntry::set_method() for details:
3457 // The invokeinterface was rewritten to a invokevirtual, hence we have
3458 // to handle this corner case. This code isn't produced by javac, but could
3459 // be produced by another compliant java compiler.
3463
3464 void TemplateTable::invokedynamic(int byte_no) {
3465 transition(vtos, vtos);
3466
3467 const Register Rret_addr = R3_ARG1,
3468 Rflags = R4_ARG2,
3469 Rmethod = R22_tmp2,
3470 Rscratch1 = R11_scratch1,
3471 Rscratch2 = R12_scratch2;
3472
3473 prepare_invoke(byte_no, Rmethod, Rret_addr, Rscratch1, noreg, Rflags, Rscratch2);
3474
3475 // Profile this call.
3476 __ profile_call(Rscratch1, Rscratch2);
3477
3478 // Off we go. With the new method handles, we don't jump to a method handle
3479 // entry any more. Instead, we pushed an "appendix" in prepare invoke, which happens
3480 // to be the callsite object the bootstrap method returned. This is passed to a
3481 // "link" method which does the dispatch (Most likely just grabs the MH stored
3482 // inside the callsite and does an invokehandle).
3483 // Argument and return type profiling.
3484 __ profile_arguments_type(Rmethod, Rscratch1, Rscratch2, false);
3485 __ call_from_interpreter(Rmethod, Rret_addr, Rscratch1 /* scratch1 */, Rscratch2 /* scratch2 */);
3486 }
3487
3488 void TemplateTable::invokehandle(int byte_no) {
3489 transition(vtos, vtos);
3490
3491 const Register Rret_addr = R3_ARG1,
3492 Rflags = R4_ARG2,
3493 Rrecv = R5_ARG3,
3494 Rmethod = R22_tmp2,
3495 Rscratch1 = R11_scratch1,
3496 Rscratch2 = R12_scratch2;
3497
3498 prepare_invoke(byte_no, Rmethod, Rret_addr, Rscratch1, Rrecv, Rflags, Rscratch2);
3499 __ verify_method_ptr(Rmethod);
3500 __ null_check_throw(Rrecv, -1, Rscratch2);
3501
3502 __ profile_final_call(Rrecv, Rscratch1);
3503
3504 // Still no call from handle => We call the method handle interpreter here.
3505 // Argument and return type profiling.
3506 __ profile_arguments_type(Rmethod, Rscratch1, Rscratch2, true);
3507 __ call_from_interpreter(Rmethod, Rret_addr, Rscratch1 /* scratch1 */, Rscratch2 /* scratch2 */);
3508 }
3509
3510 // =============================================================================
3511 // Allocation
3512
3513 // Puts allocated obj ref onto the expression stack.
3514 void TemplateTable::_new() {
3515 transition(vtos, atos);
3516
3517 Label Lslow_case,
3518 Ldone,
3519 Linitialize_header,
3520 Lallocate_shared,
3521 Linitialize_object; // Including clearing the fields.
3522
3523 const Register RallocatedObject = R17_tos,
3524 RinstanceKlass = R9_ARG7,
3525 Rscratch = R11_scratch1,
3526 Roffset = R8_ARG6,
|