comparison src/cpu/ppc/vm/templateInterpreter_ppc.cpp @ 8979:bcccbecdde63

8131048: ppc implement CRC32 intrinsic Reviewed-by: goetz
author gromero
date Mon, 24 Sep 2018 17:18:38 -0400
parents 9575483cce09
children
comparison
equal deleted inserted replaced
7:befd069c650f 8:06b3c106c615
55 #define BLOCK_COMMENT(str) /* nothing */ 55 #define BLOCK_COMMENT(str) /* nothing */
56 #else 56 #else
57 #define BLOCK_COMMENT(str) __ block_comment(str) 57 #define BLOCK_COMMENT(str) __ block_comment(str)
58 #endif 58 #endif
59 59
60 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":") 60 #define BIND(label) __ bind(label); BLOCK_COMMENT(#label ":")
61 61
62 //----------------------------------------------------------------------------- 62 //-----------------------------------------------------------------------------
63 63
64 // Actually we should never reach here since we do stack overflow checks before pushing any frame. 64 // Actually we should never reach here since we do stack overflow checks before pushing any frame.
65 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() { 65 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
781 __ li(R0, 1); 781 __ li(R0, 1);
782 __ stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread); 782 __ stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread);
783 } 783 }
784 generate_counter_incr(&invocation_counter_overflow, NULL, NULL); 784 generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
785 785
786 __ BIND(continue_after_compile); 786 BIND(continue_after_compile);
787 // Reset the _do_not_unlock_if_synchronized flag. 787 // Reset the _do_not_unlock_if_synchronized flag.
788 if (synchronized) { 788 if (synchronized) {
789 __ li(R0, 0); 789 __ li(R0, 0);
790 __ stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread); 790 __ stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread);
791 } 791 }
841 841
842 // Reload signature handler, it may have been created/assigned in the meanwhile. 842 // Reload signature handler, it may have been created/assigned in the meanwhile.
843 __ ld(signature_handler_fd, method_(signature_handler)); 843 __ ld(signature_handler_fd, method_(signature_handler));
844 __ twi_0(signature_handler_fd); // Order wrt. load of klass mirror and entry point (isync is below). 844 __ twi_0(signature_handler_fd); // Order wrt. load of klass mirror and entry point (isync is below).
845 845
846 __ BIND(call_signature_handler); 846 BIND(call_signature_handler);
847 847
848 // Before we call the signature handler we push a new frame to 848 // Before we call the signature handler we push a new frame to
849 // protect the interpreter frame volatile registers when we return 849 // protect the interpreter frame volatile registers when we return
850 // from jni but before we can get back to Java. 850 // from jni but before we can get back to Java.
851 851
911 911
912 __ ld(R11_scratch1, 0, R1_SP); 912 __ ld(R11_scratch1, 0, R1_SP);
913 __ std(R0/*mirror*/, _ijava_state_neg(oop_tmp), R11_scratch1); 913 __ std(R0/*mirror*/, _ijava_state_neg(oop_tmp), R11_scratch1);
914 // R4_ARG2 = &state->_oop_temp; 914 // R4_ARG2 = &state->_oop_temp;
915 __ addi(R4_ARG2, R11_scratch1, _ijava_state_neg(oop_tmp)); 915 __ addi(R4_ARG2, R11_scratch1, _ijava_state_neg(oop_tmp));
916 __ BIND(method_is_not_static); 916 BIND(method_is_not_static);
917 } 917 }
918 918
919 // At this point, arguments have been copied off the stack into 919 // At this point, arguments have been copied off the stack into
920 // their JNI positions. Oops are boxed in-place on the stack, with 920 // their JNI positions. Oops are boxed in-place on the stack, with
921 // handles copied to arguments. The result handler address is in a 921 // handles copied to arguments. The result handler address is in a
1124 // An exception is pending. We call into the runtime only if the 1124 // An exception is pending. We call into the runtime only if the
1125 // caller was not interpreted. If it was interpreted the 1125 // caller was not interpreted. If it was interpreted the
1126 // interpreter will do the correct thing. If it isn't interpreted 1126 // interpreter will do the correct thing. If it isn't interpreted
1127 // (call stub/compiled code) we will change our return and continue. 1127 // (call stub/compiled code) we will change our return and continue.
1128 1128
1129 __ BIND(exception_return_sync_check); 1129 BIND(exception_return_sync_check);
1130 1130
1131 if (synchronized) { 1131 if (synchronized) {
1132 // Don't check for exceptions since we're still in the i2n frame. Do that 1132 // Don't check for exceptions since we're still in the i2n frame. Do that
1133 // manually afterwards. 1133 // manually afterwards.
1134 unlock_method(false); 1134 unlock_method(false);
1135 } 1135 }
1136 __ BIND(exception_return_sync_check_already_unlocked); 1136 BIND(exception_return_sync_check_already_unlocked);
1137 1137
1138 const Register return_pc = R31; 1138 const Register return_pc = R31;
1139 1139
1140 __ ld(return_pc, 0, R1_SP); 1140 __ ld(return_pc, 0, R1_SP);
1141 __ ld(return_pc, _abi(lr), return_pc); 1141 __ ld(return_pc, _abi(lr), return_pc);
1325 case Interpreter::java_lang_math_sqrt : // fall thru 1325 case Interpreter::java_lang_math_sqrt : // fall thru
1326 case Interpreter::java_lang_math_pow : // fall thru 1326 case Interpreter::java_lang_math_pow : // fall thru
1327 case Interpreter::java_lang_math_exp : entry_point = ((InterpreterGenerator*) this)->generate_math_entry(kind); break; 1327 case Interpreter::java_lang_math_exp : entry_point = ((InterpreterGenerator*) this)->generate_math_entry(kind); break;
1328 case Interpreter::java_lang_ref_reference_get 1328 case Interpreter::java_lang_ref_reference_get
1329 : entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break; 1329 : entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
1330 case Interpreter::java_util_zip_CRC32_update
1331 : entry_point = ((InterpreterGenerator*)this)->generate_CRC32_update_entry(); break;
1332 case Interpreter::java_util_zip_CRC32_updateBytes
1333 : // fall thru
1334 case Interpreter::java_util_zip_CRC32_updateByteBuffer
1335 : entry_point = ((InterpreterGenerator*)this)->generate_CRC32_updateBytes_entry(kind); break;
1330 default : ShouldNotReachHere(); break; 1336 default : ShouldNotReachHere(); break;
1331 } 1337 }
1332 1338
1333 if (entry_point) { 1339 if (entry_point) {
1334 return entry_point; 1340 return entry_point;
1335 } 1341 }
1336 1342
1337 return ((InterpreterGenerator*) this)->generate_normal_entry(synchronized); 1343 return ((InterpreterGenerator*) this)->generate_normal_entry(synchronized);
1344 }
1345
1346 // CRC32 Intrinsics.
1347 //
1348 // Contract on scratch and work registers.
1349 // =======================================
1350 //
1351 // On ppc, the register set {R2..R12} is available in the interpreter as scratch/work registers.
1352 // You should, however, keep in mind that {R3_ARG1..R10_ARG8} is the C-ABI argument register set.
1353 // You can't rely on these registers across calls.
1354 //
1355 // The generators for CRC32_update and for CRC32_updateBytes use the
1356 // scratch/work register set internally, passing the work registers
1357 // as arguments to the MacroAssembler emitters as required.
1358 //
1359 // R3_ARG1..R6_ARG4 are preset to hold the incoming java arguments.
1360 // Their contents is not constant but may change according to the requirements
1361 // of the emitted code.
1362 //
1363 // All other registers from the scratch/work register set are used "internally"
1364 // and contain garbage (i.e. unpredictable values) once blr() is reached.
1365 // Basically, only R3_RET contains a defined value which is the function result.
1366 //
1367 /**
1368 * Method entry for static native methods:
1369 * int java.util.zip.CRC32.update(int crc, int b)
1370 */
1371 address InterpreterGenerator::generate_CRC32_update_entry() {
1372 address start = __ pc(); // Remember stub start address (is rtn value).
1373
1374 if (UseCRC32Intrinsics) {
1375 Label slow_path;
1376
1377 // Safepoint check
1378 const Register sync_state = R11_scratch1;
1379 int sync_state_offs = __ load_const_optimized(sync_state, SafepointSynchronize::address_of_state(), /*temp*/R0, true);
1380 __ lwz(sync_state, sync_state_offs, sync_state);
1381 __ cmpwi(CCR0, sync_state, SafepointSynchronize::_not_synchronized);
1382 __ bne(CCR0, slow_path);
1383
1384 // We don't generate local frame and don't align stack because
1385 // we not even call stub code (we generate the code inline)
1386 // and there is no safepoint on this path.
1387
1388 // Load java parameters.
1389 // R15_esp is callers operand stack pointer, i.e. it points to the parameters.
1390 const Register argP = R15_esp;
1391 const Register crc = R3_ARG1; // crc value
1392 const Register data = R4_ARG2; // address of java byte value (kernel_crc32 needs address)
1393 const Register dataLen = R5_ARG3; // source data len (1 byte). Not used because calling the single-byte emitter.
1394 const Register table = R6_ARG4; // address of crc32 table
1395 const Register tmp = dataLen; // Reuse unused len register to show we don't actually need a separate tmp here.
1396
1397 BLOCK_COMMENT("CRC32_update {");
1398
1399 // Arguments are reversed on java expression stack
1400 #ifdef VM_LITTLE_ENDIAN
1401 __ addi(data, argP, 0+1*wordSize); // (stack) address of byte value. Emitter expects address, not value.
1402 // Being passed as an int, the single byte is at offset +0.
1403 #else
1404 __ addi(data, argP, 3+1*wordSize); // (stack) address of byte value. Emitter expects address, not value.
1405 // Being passed from java as an int, the single byte is at offset +3.
1406 #endif
1407 __ lwz(crc, 2*wordSize, argP); // Current crc state, zero extend to 64 bit to have a clean register.
1408
1409 StubRoutines::ppc64::generate_load_crc_table_addr(_masm, table);
1410 __ kernel_crc32_singleByte(crc, data, dataLen, table, tmp);
1411
1412 // Restore caller sp for c2i case and return.
1413 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
1414 __ blr();
1415
1416 // Generate a vanilla native entry as the slow path.
1417 BLOCK_COMMENT("} CRC32_update");
1418 BIND(slow_path);
1419 }
1420
1421 (void) generate_native_entry(false);
1422
1423 return start;
1424 }
1425
1426 // CRC32 Intrinsics.
1427 /**
1428 * Method entry for static native methods:
1429 * int java.util.zip.CRC32.updateBytes( int crc, byte[] b, int off, int len)
1430 * int java.util.zip.CRC32.updateByteBuffer(int crc, long* buf, int off, int len)
1431 */
1432 address InterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
1433 address start = __ pc(); // Remember stub start address (is rtn value).
1434
1435 if (UseCRC32Intrinsics) {
1436 Label slow_path;
1437
1438 // Safepoint check
1439 const Register sync_state = R11_scratch1;
1440 int sync_state_offs = __ load_const_optimized(sync_state, SafepointSynchronize::address_of_state(), /*temp*/R0, true);
1441 __ lwz(sync_state, sync_state_offs, sync_state);
1442 __ cmpwi(CCR0, sync_state, SafepointSynchronize::_not_synchronized);
1443 __ bne(CCR0, slow_path);
1444
1445 // We don't generate local frame and don't align stack because
1446 // we not even call stub code (we generate the code inline)
1447 // and there is no safepoint on this path.
1448
1449 // Load parameters.
1450 // Z_esp is callers operand stack pointer, i.e. it points to the parameters.
1451 const Register argP = R15_esp;
1452 const Register crc = R3_ARG1; // crc value
1453 const Register data = R4_ARG2; // address of java byte array
1454 const Register dataLen = R5_ARG3; // source data len
1455 const Register table = R6_ARG4; // address of crc32 table
1456
1457 const Register t0 = R9; // scratch registers for crc calculation
1458 const Register t1 = R10;
1459 const Register t2 = R11;
1460 const Register t3 = R12;
1461
1462 const Register tc0 = R2; // registers to hold pre-calculated column addresses
1463 const Register tc1 = R7;
1464 const Register tc2 = R8;
1465 const Register tc3 = table; // table address is reconstructed at the end of kernel_crc32_* emitters
1466
1467 const Register tmp = t0; // Only used very locally to calculate byte buffer address.
1468
1469 // Arguments are reversed on java expression stack.
1470 // Calculate address of start element.
1471 if (kind == Interpreter::java_util_zip_CRC32_updateByteBuffer) { // Used for "updateByteBuffer direct".
1472 BLOCK_COMMENT("CRC32_updateByteBuffer {");
1473 // crc @ (SP + 5W) (32bit)
1474 // buf @ (SP + 3W) (64bit ptr to long array)
1475 // off @ (SP + 2W) (32bit)
1476 // dataLen @ (SP + 1W) (32bit)
1477 // data = buf + off
1478 __ ld( data, 3*wordSize, argP); // start of byte buffer
1479 __ lwa( tmp, 2*wordSize, argP); // byte buffer offset
1480 __ lwa( dataLen, 1*wordSize, argP); // #bytes to process
1481 __ lwz( crc, 5*wordSize, argP); // current crc state
1482 __ add( data, data, tmp); // Add byte buffer offset.
1483 } else { // Used for "updateBytes update".
1484 BLOCK_COMMENT("CRC32_updateBytes {");
1485 // crc @ (SP + 4W) (32bit)
1486 // buf @ (SP + 3W) (64bit ptr to byte array)
1487 // off @ (SP + 2W) (32bit)
1488 // dataLen @ (SP + 1W) (32bit)
1489 // data = buf + off + base_offset
1490 __ ld( data, 3*wordSize, argP); // start of byte buffer
1491 __ lwa( tmp, 2*wordSize, argP); // byte buffer offset
1492 __ lwa( dataLen, 1*wordSize, argP); // #bytes to process
1493 __ add( data, data, tmp); // add byte buffer offset
1494 __ lwz( crc, 4*wordSize, argP); // current crc state
1495 __ addi(data, data, arrayOopDesc::base_offset_in_bytes(T_BYTE));
1496 }
1497
1498 StubRoutines::ppc64::generate_load_crc_table_addr(_masm, table);
1499
1500 // Performance measurements show the 1word and 2word variants to be almost equivalent,
1501 // with very light advantages for the 1word variant. We chose the 1word variant for
1502 // code compactness.
1503 __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, tc0, tc1, tc2, tc3);
1504
1505 // Restore caller sp for c2i case and return.
1506 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
1507 __ blr();
1508
1509 // Generate a vanilla native entry as the slow path.
1510 BLOCK_COMMENT("} CRC32_updateBytes(Buffer)");
1511 BIND(slow_path);
1512 }
1513
1514 (void) generate_native_entry(false);
1515
1516 return start;
1338 } 1517 }
1339 1518
1340 // These should never be compiled since the interpreter will prefer 1519 // These should never be compiled since the interpreter will prefer
1341 // the compiled version to the intrinsic version. 1520 // the compiled version to the intrinsic version.
1342 bool AbstractInterpreter::can_be_compiled(methodHandle m) { 1521 bool AbstractInterpreter::can_be_compiled(methodHandle m) {