10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "c1/c1_CodeStubs.hpp"
26 #include "c1/c1_InstructionPrinter.hpp"
27 #include "c1/c1_LIR.hpp"
28 #include "c1/c1_LIRAssembler.hpp"
29 #include "c1/c1_ValueStack.hpp"
30 #include "ci/ciInstance.hpp"
31 #include "runtime/safepointMechanism.inline.hpp"
32 #include "runtime/sharedRuntime.hpp"
33 #include "runtime/vm_version.hpp"
34
35 Register LIR_Opr::as_register() const {
36 return FrameMap::cpu_rnr2reg(cpu_regnr());
37 }
38
39 Register LIR_Opr::as_register_lo() const {
40 return FrameMap::cpu_rnr2reg(cpu_regnrLo());
41 }
42
43 Register LIR_Opr::as_register_hi() const {
44 return FrameMap::cpu_rnr2reg(cpu_regnrHi());
45 }
46
47 LIR_Opr LIR_OprFact::illegalOpr = LIR_OprFact::illegal();
48 LIR_Opr LIR_OprFact::nullOpr = LIR_Opr();
49
269 assert(_ublock != nullptr, "must have old block");
270 _ublock = b;
271 }
272
273 void LIR_OpBranch::negate_cond() {
274 switch (cond()) {
275 case lir_cond_equal: set_cond(lir_cond_notEqual); break;
276 case lir_cond_notEqual: set_cond(lir_cond_equal); break;
277 case lir_cond_less: set_cond(lir_cond_greaterEqual); break;
278 case lir_cond_lessEqual: set_cond(lir_cond_greater); break;
279 case lir_cond_greaterEqual: set_cond(lir_cond_less); break;
280 case lir_cond_greater: set_cond(lir_cond_lessEqual); break;
281 default: ShouldNotReachHere();
282 }
283 }
284
285
286 LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
287 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3,
288 bool fast_check, CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch,
289 CodeStub* stub)
290
291 : LIR_Op(code, result, nullptr)
292 , _object(object)
293 , _array(LIR_OprFact::illegalOpr)
294 , _klass(klass)
295 , _tmp1(tmp1)
296 , _tmp2(tmp2)
297 , _tmp3(tmp3)
298 , _info_for_patch(info_for_patch)
299 , _info_for_exception(info_for_exception)
300 , _stub(stub)
301 , _profiled_method(nullptr)
302 , _profiled_bci(-1)
303 , _should_profile(false)
304 , _fast_check(fast_check)
305 {
306 if (code == lir_checkcast) {
307 assert(info_for_exception != nullptr, "checkcast throws exceptions");
308 } else if (code == lir_instanceof) {
309 assert(info_for_exception == nullptr, "instanceof throws no exceptions");
310 } else {
311 ShouldNotReachHere();
312 }
313 }
314
315
316
317 LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception)
318 : LIR_Op(code, LIR_OprFact::illegalOpr, nullptr)
319 , _object(object)
320 , _array(array)
321 , _klass(nullptr)
322 , _tmp1(tmp1)
323 , _tmp2(tmp2)
324 , _tmp3(tmp3)
325 , _info_for_patch(nullptr)
326 , _info_for_exception(info_for_exception)
327 , _stub(nullptr)
328 , _profiled_method(nullptr)
329 , _profiled_bci(-1)
330 , _should_profile(false)
331 , _fast_check(false)
332 {
333 if (code == lir_store_check) {
334 _stub = new ArrayStoreExceptionStub(object, info_for_exception);
335 assert(info_for_exception != nullptr, "store_check throws exceptions");
336 } else {
337 ShouldNotReachHere();
338 }
339 }
340
341
342 LIR_OpArrayCopy::LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length,
343 LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info)
344 : LIR_Op(lir_arraycopy, LIR_OprFact::illegalOpr, info)
345 , _src(src)
346 , _src_pos(src_pos)
347 , _dst(dst)
348 , _dst_pos(dst_pos)
349 , _length(length)
350 , _tmp(tmp)
351 , _expected_type(expected_type)
352 , _flags(flags) {
353 #if defined(X86) || defined(AARCH64) || defined(S390) || defined(RISCV) || defined(PPC64)
354 if (expected_type != nullptr && flags == 0) {
355 _stub = nullptr;
356 } else {
357 _stub = new ArrayCopyStub(this);
358 }
359 #else
360 _stub = new ArrayCopyStub(this);
394 // complete rework of LIR instruction visitor.
395 // The virtual call for each instruction type is replaced by a big
396 // switch that adds the operands for each instruction
397
398 void LIR_OpVisitState::visit(LIR_Op* op) {
399 // copy information from the LIR_Op
400 reset();
401 set_op(op);
402
403 switch (op->code()) {
404
405 // LIR_Op0
406 case lir_breakpoint: // result and info always invalid
407 case lir_membar: // result and info always invalid
408 case lir_membar_acquire: // result and info always invalid
409 case lir_membar_release: // result and info always invalid
410 case lir_membar_loadload: // result and info always invalid
411 case lir_membar_storestore: // result and info always invalid
412 case lir_membar_loadstore: // result and info always invalid
413 case lir_membar_storeload: // result and info always invalid
414 case lir_on_spin_wait:
415 {
416 assert(op->as_Op0() != nullptr, "must be");
417 assert(op->_info == nullptr, "info not used by this instruction");
418 assert(op->_result->is_illegal(), "not used");
419 break;
420 }
421
422 case lir_nop: // may have info, result always invalid
423 case lir_std_entry: // may have result, info always invalid
424 case lir_osr_entry: // may have result, info always invalid
425 case lir_get_thread: // may have result, info always invalid
426 {
427 assert(op->as_Op0() != nullptr, "must be");
428 if (op->_info != nullptr) do_info(op->_info);
429 if (op->_result->is_valid()) do_output(op->_result);
430 break;
431 }
432
433
777
778
779 // LIR_OpLock
780 case lir_lock:
781 case lir_unlock: {
782 assert(op->as_OpLock() != nullptr, "must be");
783 LIR_OpLock* opLock = (LIR_OpLock*)op;
784
785 if (opLock->_info) do_info(opLock->_info);
786
787 // TODO: check if these operands really have to be temp
788 // (or if input is sufficient). This may have influence on the oop map!
789 assert(opLock->_lock->is_valid(), "used"); do_temp(opLock->_lock);
790 assert(opLock->_hdr->is_valid(), "used"); do_temp(opLock->_hdr);
791 assert(opLock->_obj->is_valid(), "used"); do_temp(opLock->_obj);
792
793 if (opLock->_scratch->is_valid()) do_temp(opLock->_scratch);
794 assert(opLock->_result->is_illegal(), "unused");
795
796 do_stub(opLock->_stub);
797
798 break;
799 }
800
801
802 // LIR_OpDelay
803 case lir_delay_slot: {
804 assert(op->as_OpDelay() != nullptr, "must be");
805 LIR_OpDelay* opDelay = (LIR_OpDelay*)op;
806
807 visit(opDelay->delay_op());
808 break;
809 }
810
811 // LIR_OpTypeCheck
812 case lir_instanceof:
813 case lir_checkcast:
814 case lir_store_check: {
815 assert(op->as_OpTypeCheck() != nullptr, "must be");
816 LIR_OpTypeCheck* opTypeCheck = (LIR_OpTypeCheck*)op;
817
818 if (opTypeCheck->_info_for_exception) do_info(opTypeCheck->_info_for_exception);
819 if (opTypeCheck->_info_for_patch) do_info(opTypeCheck->_info_for_patch);
820 if (opTypeCheck->_object->is_valid()) do_input(opTypeCheck->_object);
821 if (op->code() == lir_store_check && opTypeCheck->_object->is_valid()) {
822 do_temp(opTypeCheck->_object);
823 }
824 if (opTypeCheck->_array->is_valid()) do_input(opTypeCheck->_array);
825 if (opTypeCheck->_tmp1->is_valid()) do_temp(opTypeCheck->_tmp1);
826 if (opTypeCheck->_tmp2->is_valid()) do_temp(opTypeCheck->_tmp2);
827 if (opTypeCheck->_tmp3->is_valid()) do_temp(opTypeCheck->_tmp3);
828 if (opTypeCheck->_result->is_valid()) do_output(opTypeCheck->_result);
829 if (opTypeCheck->_stub != nullptr) do_stub(opTypeCheck->_stub);
830 break;
831 }
832
833 // LIR_OpCompareAndSwap
834 case lir_cas_long:
835 case lir_cas_obj:
836 case lir_cas_int: {
837 assert(op->as_OpCompareAndSwap() != nullptr, "must be");
838 LIR_OpCompareAndSwap* opCmpAndSwap = (LIR_OpCompareAndSwap*)op;
839
840 if (opCmpAndSwap->_info) do_info(opCmpAndSwap->_info);
841 assert(opCmpAndSwap->_addr->is_valid(), "used"); do_input(opCmpAndSwap->_addr);
842 do_temp(opCmpAndSwap->_addr);
843 assert(opCmpAndSwap->_cmp_value->is_valid(), "used"); do_input(opCmpAndSwap->_cmp_value);
844 do_temp(opCmpAndSwap->_cmp_value);
845 assert(opCmpAndSwap->_new_value->is_valid(), "used"); do_input(opCmpAndSwap->_new_value);
846 do_temp(opCmpAndSwap->_new_value);
847 if (opCmpAndSwap->_tmp1->is_valid()) do_temp(opCmpAndSwap->_tmp1);
848 if (opCmpAndSwap->_tmp2->is_valid()) do_temp(opCmpAndSwap->_tmp2);
849 if (opCmpAndSwap->_result->is_valid()) do_output(opCmpAndSwap->_result);
850
851 break;
852 }
890 case lir_profile_call: {
891 assert(op->as_OpProfileCall() != nullptr, "must be");
892 LIR_OpProfileCall* opProfileCall = (LIR_OpProfileCall*)op;
893
894 if (opProfileCall->_recv->is_valid()) do_temp(opProfileCall->_recv);
895 assert(opProfileCall->_mdo->is_valid(), "used"); do_temp(opProfileCall->_mdo);
896 assert(opProfileCall->_tmp1->is_valid(), "used"); do_temp(opProfileCall->_tmp1);
897 break;
898 }
899
900 // LIR_OpProfileType:
901 case lir_profile_type: {
902 assert(op->as_OpProfileType() != nullptr, "must be");
903 LIR_OpProfileType* opProfileType = (LIR_OpProfileType*)op;
904
905 do_input(opProfileType->_mdp); do_temp(opProfileType->_mdp);
906 do_input(opProfileType->_obj);
907 do_temp(opProfileType->_tmp);
908 break;
909 }
910 default:
911 op->visit(this);
912 }
913 }
914
915 void LIR_Op::visit(LIR_OpVisitState* state) {
916 ShouldNotReachHere();
917 }
918
919 void LIR_OpVisitState::do_stub(CodeStub* stub) {
920 if (stub != nullptr) {
921 stub->visit(this);
922 }
923 }
924
925 XHandlers* LIR_OpVisitState::all_xhandler() {
926 XHandlers* result = nullptr;
927
928 int i;
929 for (i = 0; i < info_count(); i++) {
930 if (info_at(i)->exception_handlers() != nullptr) {
963 !has_slow_case();
964 }
965 #endif
966
967 // LIR_OpReturn
968 LIR_OpReturn::LIR_OpReturn(LIR_Opr opr) :
969 LIR_Op1(lir_return, opr, (CodeEmitInfo*)nullptr /* info */),
970 _stub(nullptr) {
971 if (VM_Version::supports_stack_watermark_barrier()) {
972 _stub = new C1SafepointPollStub();
973 }
974 }
975
976 //---------------------------------------------------
977
978
979 void LIR_OpJavaCall::emit_code(LIR_Assembler* masm) {
980 masm->emit_call(this);
981 }
982
983 void LIR_OpRTCall::emit_code(LIR_Assembler* masm) {
984 masm->emit_rtcall(this);
985 }
986
987 void LIR_OpLabel::emit_code(LIR_Assembler* masm) {
988 masm->emit_opLabel(this);
989 }
990
991 void LIR_OpArrayCopy::emit_code(LIR_Assembler* masm) {
992 masm->emit_arraycopy(this);
993 ArrayCopyStub* code_stub = stub();
994 if (code_stub != nullptr) {
995 masm->append_code_stub(code_stub);
996 }
997 }
998
999 void LIR_OpUpdateCRC32::emit_code(LIR_Assembler* masm) {
1000 masm->emit_updatecrc32(this);
1001 }
1002
1026 masm->append_code_stub(stub());
1027 }
1028 }
1029
1030 void LIR_Op2::emit_code(LIR_Assembler* masm) {
1031 masm->emit_op2(this);
1032 }
1033
1034 void LIR_OpAllocArray::emit_code(LIR_Assembler* masm) {
1035 masm->emit_alloc_array(this);
1036 masm->append_code_stub(stub());
1037 }
1038
1039 void LIR_OpTypeCheck::emit_code(LIR_Assembler* masm) {
1040 masm->emit_opTypeCheck(this);
1041 if (stub()) {
1042 masm->append_code_stub(stub());
1043 }
1044 }
1045
1046 void LIR_OpCompareAndSwap::emit_code(LIR_Assembler* masm) {
1047 masm->emit_compare_and_swap(this);
1048 }
1049
1050 void LIR_Op3::emit_code(LIR_Assembler* masm) {
1051 masm->emit_op3(this);
1052 }
1053
1054 void LIR_Op4::emit_code(LIR_Assembler* masm) {
1055 masm->emit_op4(this);
1056 }
1057
1058 void LIR_OpLock::emit_code(LIR_Assembler* masm) {
1059 masm->emit_lock(this);
1060 if (stub()) {
1061 masm->append_code_stub(stub());
1062 }
1063 }
1064
1065 void LIR_OpLoadKlass::emit_code(LIR_Assembler* masm) {
1066 masm->emit_load_klass(this);
1067 }
1068
1069 #ifdef ASSERT
1070 void LIR_OpAssert::emit_code(LIR_Assembler* masm) {
1071 masm->emit_assert(this);
1072 }
1073 #endif
1074
1075 void LIR_OpDelay::emit_code(LIR_Assembler* masm) {
1076 masm->emit_delay(this);
1077 }
1078
1079 void LIR_OpProfileCall::emit_code(LIR_Assembler* masm) {
1080 masm->emit_profile_call(this);
1081 }
1082
1083 void LIR_OpProfileType::emit_code(LIR_Assembler* masm) {
1084 masm->emit_profile_type(this);
1085 }
1086
1087 // LIR_List
1088 LIR_List::LIR_List(Compilation* compilation, BlockBegin* block)
1089 : _operations(8)
1090 , _compilation(compilation)
1091 #ifndef PRODUCT
1092 , _block(block)
1093 #endif
1094 #ifdef ASSERT
1095 , _file(nullptr)
1096 , _line(0)
1097 #endif
1098 #ifdef RISCV
1099 , _cmp_opr1(LIR_OprFact::illegalOpr)
1100 , _cmp_opr2(LIR_OprFact::illegalOpr)
1101 #endif
1102 { }
1103
1104
1105 #ifdef ASSERT
1106 void LIR_List::set_file_and_line(const char * file, int line) {
1342 reg,
1343 LIR_OprFact::address(addr),
1344 info));
1345 }
1346
1347 void LIR_List::allocate_object(LIR_Opr dst, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4,
1348 int header_size, int object_size, LIR_Opr klass, bool init_check, CodeStub* stub) {
1349 append(new LIR_OpAllocObj(
1350 klass,
1351 dst,
1352 t1,
1353 t2,
1354 t3,
1355 t4,
1356 header_size,
1357 object_size,
1358 init_check,
1359 stub));
1360 }
1361
1362 void LIR_List::allocate_array(LIR_Opr dst, LIR_Opr len, LIR_Opr t1,LIR_Opr t2, LIR_Opr t3,LIR_Opr t4, BasicType type, LIR_Opr klass, CodeStub* stub, bool zero_array) {
1363 append(new LIR_OpAllocArray(
1364 klass,
1365 len,
1366 dst,
1367 t1,
1368 t2,
1369 t3,
1370 t4,
1371 type,
1372 stub,
1373 zero_array));
1374 }
1375
1376 void LIR_List::shift_left(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {
1377 append(new LIR_Op2(
1378 lir_shl,
1379 value,
1380 count,
1381 dst,
1382 tmp));
1383 }
1384
1385 void LIR_List::shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {
1386 append(new LIR_Op2(
1387 lir_shr,
1388 value,
1389 count,
1390 dst,
1391 tmp));
1392 }
1393
1394
1395 void LIR_List::unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {
1396 append(new LIR_Op2(
1397 lir_ushr,
1398 value,
1399 count,
1400 dst,
1401 tmp));
1402 }
1403
1404 void LIR_List::fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less) {
1405 append(new LIR_Op2(is_unordered_less ? lir_ucmp_fd2i : lir_cmp_fd2i,
1406 left,
1407 right,
1408 dst));
1409 }
1410
1411 void LIR_List::lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info) {
1412 append(new LIR_OpLock(
1413 lir_lock,
1414 hdr,
1415 obj,
1416 lock,
1417 scratch,
1418 stub,
1419 info));
1420 }
1421
1422 void LIR_List::unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub) {
1423 append(new LIR_OpLock(
1424 lir_unlock,
1425 hdr,
1426 obj,
1427 lock,
1428 scratch,
1429 stub,
1430 nullptr));
1431 }
1432
1433
1434 void check_LIR() {
1435 // cannot do the proper checking as PRODUCT and other modes return different results
1436 // guarantee(sizeof(LIR_Opr) == wordSize, "may not have a v-table");
1437 }
1438
1439
1440
1441 void LIR_List::checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
1442 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1443 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
1444 ciMethod* profiled_method, int profiled_bci) {
1445 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_checkcast, result, object, klass,
1446 tmp1, tmp2, tmp3, fast_check, info_for_exception, info_for_patch, stub);
1447 if (profiled_method != nullptr) {
1448 c->set_profiled_method(profiled_method);
1449 c->set_profiled_bci(profiled_bci);
1450 c->set_should_profile(true);
1451 }
1452 append(c);
1453 }
1454
1455 void LIR_List::instanceof(LIR_Opr result, LIR_Opr object, ciKlass* klass, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check, CodeEmitInfo* info_for_patch, ciMethod* profiled_method, int profiled_bci) {
1456 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_instanceof, result, object, klass, tmp1, tmp2, tmp3, fast_check, nullptr, info_for_patch, nullptr);
1457 if (profiled_method != nullptr) {
1458 c->set_profiled_method(profiled_method);
1459 c->set_profiled_bci(profiled_bci);
1460 c->set_should_profile(true);
1461 }
1462 append(c);
1463 }
1464
1465
1466 void LIR_List::store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3,
1467 CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci) {
1468 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_store_check, object, array, tmp1, tmp2, tmp3, info_for_exception);
1469 if (profiled_method != nullptr) {
1470 c->set_profiled_method(profiled_method);
1471 c->set_profiled_bci(profiled_bci);
1472 c->set_should_profile(true);
1473 }
1474 append(c);
1475 }
1476
1477 void LIR_List::null_check(LIR_Opr opr, CodeEmitInfo* info, bool deoptimize_on_null) {
1478 if (deoptimize_on_null) {
1479 // Emit an explicit null check and deoptimize if opr is null
1480 CodeStub* deopt = new DeoptimizeStub(info, Deoptimization::Reason_null_check, Deoptimization::Action_none);
1481 cmp(lir_cond_equal, opr, LIR_OprFact::oopConst(nullptr));
1482 branch(lir_cond_equal, deopt);
1483 } else {
1484 // Emit an implicit null check
1485 append(new LIR_Op1(lir_null_check, opr, info));
1486 }
1487 }
1488
1489 void LIR_List::cas_long(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
1490 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
1491 append(new LIR_OpCompareAndSwap(lir_cas_long, addr, cmp_value, new_value, t1, t2, result));
1492 }
1493
1494 void LIR_List::cas_obj(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
1495 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
1496 append(new LIR_OpCompareAndSwap(lir_cas_obj, addr, cmp_value, new_value, t1, t2, result));
1497 }
1498
1499 void LIR_List::cas_int(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
1500 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
1501 append(new LIR_OpCompareAndSwap(lir_cas_int, addr, cmp_value, new_value, t1, t2, result));
1502 }
1503
1504
1505 #ifdef PRODUCT
1506
1507 void print_LIR(BlockList* blocks) {
1508 }
1684 }
1685
1686 const char * LIR_Op::name() const {
1687 const char* s = nullptr;
1688 switch(code()) {
1689 // LIR_Op0
1690 case lir_membar: s = "membar"; break;
1691 case lir_membar_acquire: s = "membar_acquire"; break;
1692 case lir_membar_release: s = "membar_release"; break;
1693 case lir_membar_loadload: s = "membar_loadload"; break;
1694 case lir_membar_storestore: s = "membar_storestore"; break;
1695 case lir_membar_loadstore: s = "membar_loadstore"; break;
1696 case lir_membar_storeload: s = "membar_storeload"; break;
1697 case lir_label: s = "label"; break;
1698 case lir_nop: s = "nop"; break;
1699 case lir_on_spin_wait: s = "on_spin_wait"; break;
1700 case lir_std_entry: s = "std_entry"; break;
1701 case lir_osr_entry: s = "osr_entry"; break;
1702 case lir_breakpoint: s = "breakpoint"; break;
1703 case lir_get_thread: s = "get_thread"; break;
1704 // LIR_Op1
1705 case lir_push: s = "push"; break;
1706 case lir_pop: s = "pop"; break;
1707 case lir_null_check: s = "null_check"; break;
1708 case lir_return: s = "return"; break;
1709 case lir_safepoint: s = "safepoint"; break;
1710 case lir_leal: s = "leal"; break;
1711 case lir_branch: s = "branch"; break;
1712 case lir_cond_float_branch: s = "flt_cond_br"; break;
1713 case lir_move: s = "move"; break;
1714 case lir_abs: s = "abs"; break;
1715 case lir_neg: s = "neg"; break;
1716 case lir_sqrt: s = "sqrt"; break;
1717 case lir_f2hf: s = "f2hf"; break;
1718 case lir_hf2f: s = "hf2f"; break;
1719 case lir_rtcall: s = "rtcall"; break;
1720 case lir_throw: s = "throw"; break;
1721 case lir_unwind: s = "unwind"; break;
1722 case lir_convert: s = "convert"; break;
1723 case lir_alloc_object: s = "alloc_obj"; break;
1749 // LIR_Op4
1750 case lir_cmove: s = "cmove"; break;
1751 // LIR_OpJavaCall
1752 case lir_static_call: s = "static"; break;
1753 case lir_optvirtual_call: s = "optvirtual"; break;
1754 case lir_icvirtual_call: s = "icvirtual"; break;
1755 case lir_dynamic_call: s = "dynamic"; break;
1756 // LIR_OpArrayCopy
1757 case lir_arraycopy: s = "arraycopy"; break;
1758 // LIR_OpUpdateCRC32
1759 case lir_updatecrc32: s = "updatecrc32"; break;
1760 // LIR_OpLock
1761 case lir_lock: s = "lock"; break;
1762 case lir_unlock: s = "unlock"; break;
1763 // LIR_OpDelay
1764 case lir_delay_slot: s = "delay"; break;
1765 // LIR_OpTypeCheck
1766 case lir_instanceof: s = "instanceof"; break;
1767 case lir_checkcast: s = "checkcast"; break;
1768 case lir_store_check: s = "store_check"; break;
1769 // LIR_OpCompareAndSwap
1770 case lir_cas_long: s = "cas_long"; break;
1771 case lir_cas_obj: s = "cas_obj"; break;
1772 case lir_cas_int: s = "cas_int"; break;
1773 // LIR_OpProfileCall
1774 case lir_profile_call: s = "profile_call"; break;
1775 // LIR_OpProfileType
1776 case lir_profile_type: s = "profile_type"; break;
1777 // LIR_OpAssert
1778 #ifdef ASSERT
1779 case lir_assert: s = "assert"; break;
1780 #endif
1781 case lir_none: ShouldNotReachHere();break;
1782 default: s = "illegal_op"; break;
1783 }
1784 return s;
1785 }
1786
1787 // LIR_OpJavaCall
1788 void LIR_OpJavaCall::print_instr(outputStream* out) const {
1789 out->print("call: ");
1790 out->print("[addr: " INTPTR_FORMAT "]", p2i(address()));
1791 if (receiver()->is_valid()) {
1792 out->print(" [recv: "); receiver()->print(out); out->print("]");
1793 }
1794 if (result_opr()->is_valid()) {
1795 out->print(" [result: "); result_opr()->print(out); out->print("]");
1796 }
1982 out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry()));
1983 }
1984
1985
1986 void LIR_OpTypeCheck::print_instr(outputStream* out) const {
1987 object()->print(out); out->print(" ");
1988 if (code() == lir_store_check) {
1989 array()->print(out); out->print(" ");
1990 }
1991 if (code() != lir_store_check) {
1992 klass()->print_name_on(out); out->print(" ");
1993 if (fast_check()) out->print("fast_check ");
1994 }
1995 tmp1()->print(out); out->print(" ");
1996 tmp2()->print(out); out->print(" ");
1997 tmp3()->print(out); out->print(" ");
1998 result_opr()->print(out); out->print(" ");
1999 if (info_for_exception() != nullptr) out->print(" [bci:%d]", info_for_exception()->stack()->bci());
2000 }
2001
2002
2003 // LIR_Op3
2004 void LIR_Op3::print_instr(outputStream* out) const {
2005 in_opr1()->print(out); out->print(" ");
2006 in_opr2()->print(out); out->print(" ");
2007 in_opr3()->print(out); out->print(" ");
2008 result_opr()->print(out);
2009 }
2010
2011 // LIR_Op4
2012 void LIR_Op4::print_instr(outputStream* out) const {
2013 print_condition(out, condition()); out->print(" ");
2014 in_opr1()->print(out); out->print(" ");
2015 in_opr2()->print(out); out->print(" ");
2016 in_opr3()->print(out); out->print(" ");
2017 in_opr4()->print(out); out->print(" ");
2018 result_opr()->print(out);
2019 }
2020
2021 void LIR_OpLock::print_instr(outputStream* out) const {
2057 mdo()->print(out); out->print(" ");
2058 recv()->print(out); out->print(" ");
2059 tmp1()->print(out); out->print(" ");
2060 }
2061
2062 // LIR_OpProfileType
2063 void LIR_OpProfileType::print_instr(outputStream* out) const {
2064 out->print("exact = ");
2065 if (exact_klass() == nullptr) {
2066 out->print("unknown");
2067 } else {
2068 exact_klass()->print_name_on(out);
2069 }
2070 out->print(" current = "); ciTypeEntries::print_ciklass(out, current_klass());
2071 out->print(" ");
2072 mdp()->print(out); out->print(" ");
2073 obj()->print(out); out->print(" ");
2074 tmp()->print(out); out->print(" ");
2075 }
2076
2077 #endif // PRODUCT
2078
2079 // Implementation of LIR_InsertionBuffer
2080
2081 void LIR_InsertionBuffer::append(int index, LIR_Op* op) {
2082 assert(_index_and_count.length() % 2 == 0, "must have a count for each index");
2083
2084 int i = number_of_insertion_points() - 1;
2085 if (i < 0 || index_at(i) < index) {
2086 append_new(index, 1);
2087 } else {
2088 assert(index_at(i) == index, "can append LIR_Ops in ascending order only");
2089 assert(count_at(i) > 0, "check");
2090 set_count_at(i, count_at(i) + 1);
2091 }
2092 _ops.push(op);
2093
2094 DEBUG_ONLY(verify());
2095 }
2096
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "c1/c1_CodeStubs.hpp"
26 #include "c1/c1_InstructionPrinter.hpp"
27 #include "c1/c1_LIR.hpp"
28 #include "c1/c1_LIRAssembler.hpp"
29 #include "c1/c1_ValueStack.hpp"
30 #include "ci/ciInlineKlass.hpp"
31 #include "ci/ciInstance.hpp"
32 #include "runtime/safepointMechanism.inline.hpp"
33 #include "runtime/sharedRuntime.hpp"
34 #include "runtime/vm_version.hpp"
35
36 Register LIR_Opr::as_register() const {
37 return FrameMap::cpu_rnr2reg(cpu_regnr());
38 }
39
40 Register LIR_Opr::as_register_lo() const {
41 return FrameMap::cpu_rnr2reg(cpu_regnrLo());
42 }
43
44 Register LIR_Opr::as_register_hi() const {
45 return FrameMap::cpu_rnr2reg(cpu_regnrHi());
46 }
47
48 LIR_Opr LIR_OprFact::illegalOpr = LIR_OprFact::illegal();
49 LIR_Opr LIR_OprFact::nullOpr = LIR_Opr();
50
270 assert(_ublock != nullptr, "must have old block");
271 _ublock = b;
272 }
273
274 void LIR_OpBranch::negate_cond() {
275 switch (cond()) {
276 case lir_cond_equal: set_cond(lir_cond_notEqual); break;
277 case lir_cond_notEqual: set_cond(lir_cond_equal); break;
278 case lir_cond_less: set_cond(lir_cond_greaterEqual); break;
279 case lir_cond_lessEqual: set_cond(lir_cond_greater); break;
280 case lir_cond_greaterEqual: set_cond(lir_cond_less); break;
281 case lir_cond_greater: set_cond(lir_cond_lessEqual); break;
282 default: ShouldNotReachHere();
283 }
284 }
285
286
287 LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr result, LIR_Opr object, ciKlass* klass,
288 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3,
289 bool fast_check, CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch,
290 CodeStub* stub, bool need_null_check)
291
292 : LIR_Op(code, result, nullptr)
293 , _object(object)
294 , _array(LIR_OprFact::illegalOpr)
295 , _klass(klass)
296 , _tmp1(tmp1)
297 , _tmp2(tmp2)
298 , _tmp3(tmp3)
299 , _info_for_patch(info_for_patch)
300 , _info_for_exception(info_for_exception)
301 , _stub(stub)
302 , _profiled_method(nullptr)
303 , _profiled_bci(-1)
304 , _should_profile(false)
305 , _fast_check(fast_check)
306 , _need_null_check(need_null_check)
307 {
308 if (code == lir_checkcast) {
309 assert(info_for_exception != nullptr, "checkcast throws exceptions");
310 } else if (code == lir_instanceof) {
311 assert(info_for_exception == nullptr, "instanceof throws no exceptions");
312 } else {
313 ShouldNotReachHere();
314 }
315 }
316
317
318
319 LIR_OpTypeCheck::LIR_OpTypeCheck(LIR_Code code, LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, CodeEmitInfo* info_for_exception)
320 : LIR_Op(code, LIR_OprFact::illegalOpr, nullptr)
321 , _object(object)
322 , _array(array)
323 , _klass(nullptr)
324 , _tmp1(tmp1)
325 , _tmp2(tmp2)
326 , _tmp3(tmp3)
327 , _info_for_patch(nullptr)
328 , _info_for_exception(info_for_exception)
329 , _stub(nullptr)
330 , _profiled_method(nullptr)
331 , _profiled_bci(-1)
332 , _should_profile(false)
333 , _fast_check(false)
334 , _need_null_check(true)
335 {
336 if (code == lir_store_check) {
337 _stub = new ArrayStoreExceptionStub(object, info_for_exception);
338 assert(info_for_exception != nullptr, "store_check throws exceptions");
339 } else {
340 ShouldNotReachHere();
341 }
342 }
343
344 LIR_OpFlattenedArrayCheck::LIR_OpFlattenedArrayCheck(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub)
345 : LIR_Op(lir_flat_array_check, LIR_OprFact::illegalOpr, nullptr)
346 , _array(array)
347 , _value(value)
348 , _tmp(tmp)
349 , _stub(stub) {}
350
351
352 LIR_OpNullFreeArrayCheck::LIR_OpNullFreeArrayCheck(LIR_Opr array, LIR_Opr tmp)
353 : LIR_Op(lir_null_free_array_check, LIR_OprFact::illegalOpr, nullptr)
354 , _array(array)
355 , _tmp(tmp) {}
356
357
358 LIR_OpSubstitutabilityCheck::LIR_OpSubstitutabilityCheck(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
359 LIR_Opr tmp1, LIR_Opr tmp2,
360 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
361 CodeEmitInfo* info, CodeStub* stub)
362 : LIR_Op(lir_substitutability_check, result, info)
363 , _left(left)
364 , _right(right)
365 , _equal_result(equal_result)
366 , _not_equal_result(not_equal_result)
367 , _tmp1(tmp1)
368 , _tmp2(tmp2)
369 , _left_klass(left_klass)
370 , _right_klass(right_klass)
371 , _left_klass_op(left_klass_op)
372 , _right_klass_op(right_klass_op)
373 , _stub(stub) {}
374
375
376 LIR_OpArrayCopy::LIR_OpArrayCopy(LIR_Opr src, LIR_Opr src_pos, LIR_Opr dst, LIR_Opr dst_pos, LIR_Opr length,
377 LIR_Opr tmp, ciArrayKlass* expected_type, int flags, CodeEmitInfo* info)
378 : LIR_Op(lir_arraycopy, LIR_OprFact::illegalOpr, info)
379 , _src(src)
380 , _src_pos(src_pos)
381 , _dst(dst)
382 , _dst_pos(dst_pos)
383 , _length(length)
384 , _tmp(tmp)
385 , _expected_type(expected_type)
386 , _flags(flags) {
387 #if defined(X86) || defined(AARCH64) || defined(S390) || defined(RISCV) || defined(PPC64)
388 if (expected_type != nullptr && flags == 0) {
389 _stub = nullptr;
390 } else {
391 _stub = new ArrayCopyStub(this);
392 }
393 #else
394 _stub = new ArrayCopyStub(this);
428 // complete rework of LIR instruction visitor.
429 // The virtual call for each instruction type is replaced by a big
430 // switch that adds the operands for each instruction
431
432 void LIR_OpVisitState::visit(LIR_Op* op) {
433 // copy information from the LIR_Op
434 reset();
435 set_op(op);
436
437 switch (op->code()) {
438
439 // LIR_Op0
440 case lir_breakpoint: // result and info always invalid
441 case lir_membar: // result and info always invalid
442 case lir_membar_acquire: // result and info always invalid
443 case lir_membar_release: // result and info always invalid
444 case lir_membar_loadload: // result and info always invalid
445 case lir_membar_storestore: // result and info always invalid
446 case lir_membar_loadstore: // result and info always invalid
447 case lir_membar_storeload: // result and info always invalid
448 case lir_check_orig_pc: // result and info always invalid
449 case lir_on_spin_wait:
450 {
451 assert(op->as_Op0() != nullptr, "must be");
452 assert(op->_info == nullptr, "info not used by this instruction");
453 assert(op->_result->is_illegal(), "not used");
454 break;
455 }
456
457 case lir_nop: // may have info, result always invalid
458 case lir_std_entry: // may have result, info always invalid
459 case lir_osr_entry: // may have result, info always invalid
460 case lir_get_thread: // may have result, info always invalid
461 {
462 assert(op->as_Op0() != nullptr, "must be");
463 if (op->_info != nullptr) do_info(op->_info);
464 if (op->_result->is_valid()) do_output(op->_result);
465 break;
466 }
467
468
812
813
814 // LIR_OpLock
815 case lir_lock:
816 case lir_unlock: {
817 assert(op->as_OpLock() != nullptr, "must be");
818 LIR_OpLock* opLock = (LIR_OpLock*)op;
819
820 if (opLock->_info) do_info(opLock->_info);
821
822 // TODO: check if these operands really have to be temp
823 // (or if input is sufficient). This may have influence on the oop map!
824 assert(opLock->_lock->is_valid(), "used"); do_temp(opLock->_lock);
825 assert(opLock->_hdr->is_valid(), "used"); do_temp(opLock->_hdr);
826 assert(opLock->_obj->is_valid(), "used"); do_temp(opLock->_obj);
827
828 if (opLock->_scratch->is_valid()) do_temp(opLock->_scratch);
829 assert(opLock->_result->is_illegal(), "unused");
830
831 do_stub(opLock->_stub);
832 do_stub(opLock->_throw_ie_stub);
833
834 break;
835 }
836
837
838 // LIR_OpDelay
839 case lir_delay_slot: {
840 assert(op->as_OpDelay() != nullptr, "must be");
841 LIR_OpDelay* opDelay = (LIR_OpDelay*)op;
842
843 visit(opDelay->delay_op());
844 break;
845 }
846
847 // LIR_OpTypeCheck
848 case lir_instanceof:
849 case lir_checkcast:
850 case lir_store_check: {
851 assert(op->as_OpTypeCheck() != nullptr, "must be");
852 LIR_OpTypeCheck* opTypeCheck = (LIR_OpTypeCheck*)op;
853
854 if (opTypeCheck->_info_for_exception) do_info(opTypeCheck->_info_for_exception);
855 if (opTypeCheck->_info_for_patch) do_info(opTypeCheck->_info_for_patch);
856 if (opTypeCheck->_object->is_valid()) do_input(opTypeCheck->_object);
857 if (op->code() == lir_store_check && opTypeCheck->_object->is_valid()) {
858 do_temp(opTypeCheck->_object);
859 }
860 if (opTypeCheck->_array->is_valid()) do_input(opTypeCheck->_array);
861 if (opTypeCheck->_tmp1->is_valid()) do_temp(opTypeCheck->_tmp1);
862 if (opTypeCheck->_tmp2->is_valid()) do_temp(opTypeCheck->_tmp2);
863 if (opTypeCheck->_tmp3->is_valid()) do_temp(opTypeCheck->_tmp3);
864 if (opTypeCheck->_result->is_valid()) do_output(opTypeCheck->_result);
865 if (opTypeCheck->_stub != nullptr) do_stub(opTypeCheck->_stub);
866 break;
867 }
868
869 // LIR_OpFlattenedArrayCheck
870 case lir_flat_array_check: {
871 assert(op->as_OpFlattenedArrayCheck() != nullptr, "must be");
872 LIR_OpFlattenedArrayCheck* opFlattenedArrayCheck = (LIR_OpFlattenedArrayCheck*)op;
873
874 if (opFlattenedArrayCheck->_array->is_valid()) do_input(opFlattenedArrayCheck->_array);
875 if (opFlattenedArrayCheck->_value->is_valid()) do_input(opFlattenedArrayCheck->_value);
876 if (opFlattenedArrayCheck->_tmp->is_valid()) do_temp(opFlattenedArrayCheck->_tmp);
877
878 do_stub(opFlattenedArrayCheck->_stub);
879
880 break;
881 }
882
883 // LIR_OpNullFreeArrayCheck
884 case lir_null_free_array_check: {
885 assert(op->as_OpNullFreeArrayCheck() != nullptr, "must be");
886 LIR_OpNullFreeArrayCheck* opNullFreeArrayCheck = (LIR_OpNullFreeArrayCheck*)op;
887
888 if (opNullFreeArrayCheck->_array->is_valid()) do_input(opNullFreeArrayCheck->_array);
889 if (opNullFreeArrayCheck->_tmp->is_valid()) do_temp(opNullFreeArrayCheck->_tmp);
890 break;
891 }
892
893 // LIR_OpSubstitutabilityCheck
894 case lir_substitutability_check: {
895 assert(op->as_OpSubstitutabilityCheck() != nullptr, "must be");
896 LIR_OpSubstitutabilityCheck* opSubstitutabilityCheck = (LIR_OpSubstitutabilityCheck*)op;
897 do_input(opSubstitutabilityCheck->_left);
898 do_temp (opSubstitutabilityCheck->_left);
899 do_input(opSubstitutabilityCheck->_right);
900 do_temp (opSubstitutabilityCheck->_right);
901 do_input(opSubstitutabilityCheck->_equal_result);
902 do_temp (opSubstitutabilityCheck->_equal_result);
903 do_input(opSubstitutabilityCheck->_not_equal_result);
904 do_temp (opSubstitutabilityCheck->_not_equal_result);
905 if (opSubstitutabilityCheck->_tmp1->is_valid()) do_temp(opSubstitutabilityCheck->_tmp1);
906 if (opSubstitutabilityCheck->_tmp2->is_valid()) do_temp(opSubstitutabilityCheck->_tmp2);
907 if (opSubstitutabilityCheck->_left_klass_op->is_valid()) do_temp(opSubstitutabilityCheck->_left_klass_op);
908 if (opSubstitutabilityCheck->_right_klass_op->is_valid()) do_temp(opSubstitutabilityCheck->_right_klass_op);
909 if (opSubstitutabilityCheck->_result->is_valid()) do_output(opSubstitutabilityCheck->_result);
910
911 do_info(opSubstitutabilityCheck->_info);
912 do_stub(opSubstitutabilityCheck->_stub);
913 break;
914 }
915
916 // LIR_OpCompareAndSwap
917 case lir_cas_long:
918 case lir_cas_obj:
919 case lir_cas_int: {
920 assert(op->as_OpCompareAndSwap() != nullptr, "must be");
921 LIR_OpCompareAndSwap* opCmpAndSwap = (LIR_OpCompareAndSwap*)op;
922
923 if (opCmpAndSwap->_info) do_info(opCmpAndSwap->_info);
924 assert(opCmpAndSwap->_addr->is_valid(), "used"); do_input(opCmpAndSwap->_addr);
925 do_temp(opCmpAndSwap->_addr);
926 assert(opCmpAndSwap->_cmp_value->is_valid(), "used"); do_input(opCmpAndSwap->_cmp_value);
927 do_temp(opCmpAndSwap->_cmp_value);
928 assert(opCmpAndSwap->_new_value->is_valid(), "used"); do_input(opCmpAndSwap->_new_value);
929 do_temp(opCmpAndSwap->_new_value);
930 if (opCmpAndSwap->_tmp1->is_valid()) do_temp(opCmpAndSwap->_tmp1);
931 if (opCmpAndSwap->_tmp2->is_valid()) do_temp(opCmpAndSwap->_tmp2);
932 if (opCmpAndSwap->_result->is_valid()) do_output(opCmpAndSwap->_result);
933
934 break;
935 }
973 case lir_profile_call: {
974 assert(op->as_OpProfileCall() != nullptr, "must be");
975 LIR_OpProfileCall* opProfileCall = (LIR_OpProfileCall*)op;
976
977 if (opProfileCall->_recv->is_valid()) do_temp(opProfileCall->_recv);
978 assert(opProfileCall->_mdo->is_valid(), "used"); do_temp(opProfileCall->_mdo);
979 assert(opProfileCall->_tmp1->is_valid(), "used"); do_temp(opProfileCall->_tmp1);
980 break;
981 }
982
983 // LIR_OpProfileType:
984 case lir_profile_type: {
985 assert(op->as_OpProfileType() != nullptr, "must be");
986 LIR_OpProfileType* opProfileType = (LIR_OpProfileType*)op;
987
988 do_input(opProfileType->_mdp); do_temp(opProfileType->_mdp);
989 do_input(opProfileType->_obj);
990 do_temp(opProfileType->_tmp);
991 break;
992 }
993
994 // LIR_OpProfileInlineType:
995 case lir_profile_inline_type: {
996 assert(op->as_OpProfileInlineType() != nullptr, "must be");
997 LIR_OpProfileInlineType* opProfileInlineType = (LIR_OpProfileInlineType*)op;
998
999 do_input(opProfileInlineType->_mdp); do_temp(opProfileInlineType->_mdp);
1000 do_input(opProfileInlineType->_obj);
1001 do_temp(opProfileInlineType->_tmp);
1002 break;
1003 }
1004 default:
1005 op->visit(this);
1006 }
1007 }
1008
1009 void LIR_Op::visit(LIR_OpVisitState* state) {
1010 ShouldNotReachHere();
1011 }
1012
1013 void LIR_OpVisitState::do_stub(CodeStub* stub) {
1014 if (stub != nullptr) {
1015 stub->visit(this);
1016 }
1017 }
1018
1019 XHandlers* LIR_OpVisitState::all_xhandler() {
1020 XHandlers* result = nullptr;
1021
1022 int i;
1023 for (i = 0; i < info_count(); i++) {
1024 if (info_at(i)->exception_handlers() != nullptr) {
1057 !has_slow_case();
1058 }
1059 #endif
1060
1061 // LIR_OpReturn
1062 LIR_OpReturn::LIR_OpReturn(LIR_Opr opr) :
1063 LIR_Op1(lir_return, opr, (CodeEmitInfo*)nullptr /* info */),
1064 _stub(nullptr) {
1065 if (VM_Version::supports_stack_watermark_barrier()) {
1066 _stub = new C1SafepointPollStub();
1067 }
1068 }
1069
1070 //---------------------------------------------------
1071
1072
1073 void LIR_OpJavaCall::emit_code(LIR_Assembler* masm) {
1074 masm->emit_call(this);
1075 }
1076
1077 bool LIR_OpJavaCall::maybe_return_as_fields(ciInlineKlass** vk_ret) const {
1078 ciType* return_type = method()->return_type();
1079 if (InlineTypeReturnedAsFields) {
1080 if (return_type->is_inlinetype()) {
1081 ciInlineKlass* vk = return_type->as_inline_klass();
1082 if (vk->can_be_returned_as_fields()) {
1083 if (vk_ret != nullptr) {
1084 *vk_ret = vk;
1085 }
1086 return true;
1087 }
1088 } else if (return_type->is_instance_klass() &&
1089 (method()->is_method_handle_intrinsic() || !return_type->is_loaded() ||
1090 StressCallingConvention)) {
1091 // An inline type might be returned from the call but we don't know its type.
1092 // This can happen with method handle intrinsics or when the return type is
1093 // not loaded (method holder is not loaded or preload attribute is missing).
1094 // If an inline type is returned, we either get an oop to a buffer and nothing
1095 // needs to be done or one of the values being returned is the klass of the
1096 // inline type (RAX on x64, with LSB set to 1) and we need to allocate an inline
1097 // type instance of that type and initialize it with the fields values being
1098 // returned in other registers.
1099 return true;
1100 }
1101 }
1102 return false;
1103 }
1104
1105 void LIR_OpRTCall::emit_code(LIR_Assembler* masm) {
1106 masm->emit_rtcall(this);
1107 }
1108
1109 void LIR_OpLabel::emit_code(LIR_Assembler* masm) {
1110 masm->emit_opLabel(this);
1111 }
1112
1113 void LIR_OpArrayCopy::emit_code(LIR_Assembler* masm) {
1114 masm->emit_arraycopy(this);
1115 ArrayCopyStub* code_stub = stub();
1116 if (code_stub != nullptr) {
1117 masm->append_code_stub(code_stub);
1118 }
1119 }
1120
1121 void LIR_OpUpdateCRC32::emit_code(LIR_Assembler* masm) {
1122 masm->emit_updatecrc32(this);
1123 }
1124
1148 masm->append_code_stub(stub());
1149 }
1150 }
1151
1152 void LIR_Op2::emit_code(LIR_Assembler* masm) {
1153 masm->emit_op2(this);
1154 }
1155
1156 void LIR_OpAllocArray::emit_code(LIR_Assembler* masm) {
1157 masm->emit_alloc_array(this);
1158 masm->append_code_stub(stub());
1159 }
1160
1161 void LIR_OpTypeCheck::emit_code(LIR_Assembler* masm) {
1162 masm->emit_opTypeCheck(this);
1163 if (stub()) {
1164 masm->append_code_stub(stub());
1165 }
1166 }
1167
1168 void LIR_OpFlattenedArrayCheck::emit_code(LIR_Assembler* masm) {
1169 masm->emit_opFlattenedArrayCheck(this);
1170 if (stub() != nullptr) {
1171 masm->append_code_stub(stub());
1172 }
1173 }
1174
1175 void LIR_OpNullFreeArrayCheck::emit_code(LIR_Assembler* masm) {
1176 masm->emit_opNullFreeArrayCheck(this);
1177 }
1178
1179 void LIR_OpSubstitutabilityCheck::emit_code(LIR_Assembler* masm) {
1180 masm->emit_opSubstitutabilityCheck(this);
1181 if (stub() != nullptr) {
1182 masm->append_code_stub(stub());
1183 }
1184 }
1185
1186 void LIR_OpCompareAndSwap::emit_code(LIR_Assembler* masm) {
1187 masm->emit_compare_and_swap(this);
1188 }
1189
1190 void LIR_Op3::emit_code(LIR_Assembler* masm) {
1191 masm->emit_op3(this);
1192 }
1193
1194 void LIR_Op4::emit_code(LIR_Assembler* masm) {
1195 masm->emit_op4(this);
1196 }
1197
1198 void LIR_OpLock::emit_code(LIR_Assembler* masm) {
1199 masm->emit_lock(this);
1200 if (stub()) {
1201 masm->append_code_stub(stub());
1202 }
1203 if (throw_ie_stub()) {
1204 masm->append_code_stub(throw_ie_stub());
1205 }
1206 }
1207
1208 void LIR_OpLoadKlass::emit_code(LIR_Assembler* masm) {
1209 masm->emit_load_klass(this);
1210 }
1211
1212 #ifdef ASSERT
1213 void LIR_OpAssert::emit_code(LIR_Assembler* masm) {
1214 masm->emit_assert(this);
1215 }
1216 #endif
1217
1218 void LIR_OpDelay::emit_code(LIR_Assembler* masm) {
1219 masm->emit_delay(this);
1220 }
1221
1222 void LIR_OpProfileCall::emit_code(LIR_Assembler* masm) {
1223 masm->emit_profile_call(this);
1224 }
1225
1226 void LIR_OpProfileType::emit_code(LIR_Assembler* masm) {
1227 masm->emit_profile_type(this);
1228 }
1229
1230 void LIR_OpProfileInlineType::emit_code(LIR_Assembler* masm) {
1231 masm->emit_profile_inline_type(this);
1232 }
1233
1234 // LIR_List
1235 LIR_List::LIR_List(Compilation* compilation, BlockBegin* block)
1236 : _operations(8)
1237 , _compilation(compilation)
1238 #ifndef PRODUCT
1239 , _block(block)
1240 #endif
1241 #ifdef ASSERT
1242 , _file(nullptr)
1243 , _line(0)
1244 #endif
1245 #ifdef RISCV
1246 , _cmp_opr1(LIR_OprFact::illegalOpr)
1247 , _cmp_opr2(LIR_OprFact::illegalOpr)
1248 #endif
1249 { }
1250
1251
1252 #ifdef ASSERT
1253 void LIR_List::set_file_and_line(const char * file, int line) {
1489 reg,
1490 LIR_OprFact::address(addr),
1491 info));
1492 }
1493
1494 void LIR_List::allocate_object(LIR_Opr dst, LIR_Opr t1, LIR_Opr t2, LIR_Opr t3, LIR_Opr t4,
1495 int header_size, int object_size, LIR_Opr klass, bool init_check, CodeStub* stub) {
1496 append(new LIR_OpAllocObj(
1497 klass,
1498 dst,
1499 t1,
1500 t2,
1501 t3,
1502 t4,
1503 header_size,
1504 object_size,
1505 init_check,
1506 stub));
1507 }
1508
1509 void LIR_List::allocate_array(LIR_Opr dst, LIR_Opr len, LIR_Opr t1,LIR_Opr t2, LIR_Opr t3,LIR_Opr t4, BasicType type, LIR_Opr klass, CodeStub* stub, bool zero_array, bool is_null_free) {
1510 append(new LIR_OpAllocArray(
1511 klass,
1512 len,
1513 dst,
1514 t1,
1515 t2,
1516 t3,
1517 t4,
1518 type,
1519 stub,
1520 zero_array,
1521 is_null_free));
1522 }
1523
1524 void LIR_List::shift_left(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {
1525 append(new LIR_Op2(
1526 lir_shl,
1527 value,
1528 count,
1529 dst,
1530 tmp));
1531 }
1532
1533 void LIR_List::shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {
1534 append(new LIR_Op2(
1535 lir_shr,
1536 value,
1537 count,
1538 dst,
1539 tmp));
1540 }
1541
1542
1543 void LIR_List::unsigned_shift_right(LIR_Opr value, LIR_Opr count, LIR_Opr dst, LIR_Opr tmp) {
1544 append(new LIR_Op2(
1545 lir_ushr,
1546 value,
1547 count,
1548 dst,
1549 tmp));
1550 }
1551
1552 void LIR_List::fcmp2int(LIR_Opr left, LIR_Opr right, LIR_Opr dst, bool is_unordered_less) {
1553 append(new LIR_Op2(is_unordered_less ? lir_ucmp_fd2i : lir_cmp_fd2i,
1554 left,
1555 right,
1556 dst));
1557 }
1558
1559 void LIR_List::lock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub, CodeEmitInfo* info, CodeStub* throw_ie_stub) {
1560 append(new LIR_OpLock(
1561 lir_lock,
1562 hdr,
1563 obj,
1564 lock,
1565 scratch,
1566 stub,
1567 info,
1568 throw_ie_stub));
1569 }
1570
1571 void LIR_List::unlock_object(LIR_Opr hdr, LIR_Opr obj, LIR_Opr lock, LIR_Opr scratch, CodeStub* stub) {
1572 append(new LIR_OpLock(
1573 lir_unlock,
1574 hdr,
1575 obj,
1576 lock,
1577 scratch,
1578 stub,
1579 nullptr));
1580 }
1581
1582
1583 void check_LIR() {
1584 // cannot do the proper checking as PRODUCT and other modes return different results
1585 // guarantee(sizeof(LIR_Opr) == wordSize, "may not have a v-table");
1586 }
1587
1588
1589
1590 void LIR_List::checkcast (LIR_Opr result, LIR_Opr object, ciKlass* klass,
1591 LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check,
1592 CodeEmitInfo* info_for_exception, CodeEmitInfo* info_for_patch, CodeStub* stub,
1593 ciMethod* profiled_method, int profiled_bci, bool is_null_free) {
1594 // If klass is non-nullable, LIRGenerator::do_CheckCast has already performed null-check
1595 // on the object.
1596 bool need_null_check = !is_null_free;
1597 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_checkcast, result, object, klass,
1598 tmp1, tmp2, tmp3, fast_check, info_for_exception, info_for_patch, stub,
1599 need_null_check);
1600 if (profiled_method != nullptr) {
1601 c->set_profiled_method(profiled_method);
1602 c->set_profiled_bci(profiled_bci);
1603 c->set_should_profile(true);
1604 }
1605 append(c);
1606 }
1607
1608 void LIR_List::instanceof(LIR_Opr result, LIR_Opr object, ciKlass* klass, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3, bool fast_check, CodeEmitInfo* info_for_patch, ciMethod* profiled_method, int profiled_bci) {
1609 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_instanceof, result, object, klass, tmp1, tmp2, tmp3, fast_check, nullptr, info_for_patch, nullptr);
1610 if (profiled_method != nullptr) {
1611 c->set_profiled_method(profiled_method);
1612 c->set_profiled_bci(profiled_bci);
1613 c->set_should_profile(true);
1614 }
1615 append(c);
1616 }
1617
1618
1619 void LIR_List::store_check(LIR_Opr object, LIR_Opr array, LIR_Opr tmp1, LIR_Opr tmp2, LIR_Opr tmp3,
1620 CodeEmitInfo* info_for_exception, ciMethod* profiled_method, int profiled_bci) {
1621 // FIXME -- if the types of the array and/or the object are known statically, we can avoid loading the klass
1622 LIR_OpTypeCheck* c = new LIR_OpTypeCheck(lir_store_check, object, array, tmp1, tmp2, tmp3, info_for_exception);
1623 if (profiled_method != nullptr) {
1624 c->set_profiled_method(profiled_method);
1625 c->set_profiled_bci(profiled_bci);
1626 c->set_should_profile(true);
1627 }
1628 append(c);
1629 }
1630
1631 void LIR_List::null_check(LIR_Opr opr, CodeEmitInfo* info, bool deoptimize_on_null) {
1632 if (deoptimize_on_null) {
1633 // Emit an explicit null check and deoptimize if opr is null
1634 CodeStub* deopt = new DeoptimizeStub(info, Deoptimization::Reason_null_check, Deoptimization::Action_none);
1635 cmp(lir_cond_equal, opr, LIR_OprFact::oopConst(nullptr));
1636 branch(lir_cond_equal, deopt);
1637 } else {
1638 // Emit an implicit null check
1639 append(new LIR_Op1(lir_null_check, opr, info));
1640 }
1641 }
1642
1643 void LIR_List::check_flat_array(LIR_Opr array, LIR_Opr value, LIR_Opr tmp, CodeStub* stub) {
1644 LIR_OpFlattenedArrayCheck* c = new LIR_OpFlattenedArrayCheck(array, value, tmp, stub);
1645 append(c);
1646 }
1647
1648 void LIR_List::check_null_free_array(LIR_Opr array, LIR_Opr tmp) {
1649 LIR_OpNullFreeArrayCheck* c = new LIR_OpNullFreeArrayCheck(array, tmp);
1650 append(c);
1651 }
1652
1653 void LIR_List::substitutability_check(LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr equal_result, LIR_Opr not_equal_result,
1654 LIR_Opr tmp1, LIR_Opr tmp2,
1655 ciKlass* left_klass, ciKlass* right_klass, LIR_Opr left_klass_op, LIR_Opr right_klass_op,
1656 CodeEmitInfo* info, CodeStub* stub) {
1657 LIR_OpSubstitutabilityCheck* c = new LIR_OpSubstitutabilityCheck(result, left, right, equal_result, not_equal_result,
1658 tmp1, tmp2,
1659 left_klass, right_klass, left_klass_op, right_klass_op,
1660 info, stub);
1661 append(c);
1662 }
1663
1664 void LIR_List::cas_long(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
1665 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
1666 append(new LIR_OpCompareAndSwap(lir_cas_long, addr, cmp_value, new_value, t1, t2, result));
1667 }
1668
1669 void LIR_List::cas_obj(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
1670 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
1671 append(new LIR_OpCompareAndSwap(lir_cas_obj, addr, cmp_value, new_value, t1, t2, result));
1672 }
1673
1674 void LIR_List::cas_int(LIR_Opr addr, LIR_Opr cmp_value, LIR_Opr new_value,
1675 LIR_Opr t1, LIR_Opr t2, LIR_Opr result) {
1676 append(new LIR_OpCompareAndSwap(lir_cas_int, addr, cmp_value, new_value, t1, t2, result));
1677 }
1678
1679
1680 #ifdef PRODUCT
1681
1682 void print_LIR(BlockList* blocks) {
1683 }
1859 }
1860
1861 const char * LIR_Op::name() const {
1862 const char* s = nullptr;
1863 switch(code()) {
1864 // LIR_Op0
1865 case lir_membar: s = "membar"; break;
1866 case lir_membar_acquire: s = "membar_acquire"; break;
1867 case lir_membar_release: s = "membar_release"; break;
1868 case lir_membar_loadload: s = "membar_loadload"; break;
1869 case lir_membar_storestore: s = "membar_storestore"; break;
1870 case lir_membar_loadstore: s = "membar_loadstore"; break;
1871 case lir_membar_storeload: s = "membar_storeload"; break;
1872 case lir_label: s = "label"; break;
1873 case lir_nop: s = "nop"; break;
1874 case lir_on_spin_wait: s = "on_spin_wait"; break;
1875 case lir_std_entry: s = "std_entry"; break;
1876 case lir_osr_entry: s = "osr_entry"; break;
1877 case lir_breakpoint: s = "breakpoint"; break;
1878 case lir_get_thread: s = "get_thread"; break;
1879 case lir_check_orig_pc: s = "check_orig_pc"; break;
1880 // LIR_Op1
1881 case lir_push: s = "push"; break;
1882 case lir_pop: s = "pop"; break;
1883 case lir_null_check: s = "null_check"; break;
1884 case lir_return: s = "return"; break;
1885 case lir_safepoint: s = "safepoint"; break;
1886 case lir_leal: s = "leal"; break;
1887 case lir_branch: s = "branch"; break;
1888 case lir_cond_float_branch: s = "flt_cond_br"; break;
1889 case lir_move: s = "move"; break;
1890 case lir_abs: s = "abs"; break;
1891 case lir_neg: s = "neg"; break;
1892 case lir_sqrt: s = "sqrt"; break;
1893 case lir_f2hf: s = "f2hf"; break;
1894 case lir_hf2f: s = "hf2f"; break;
1895 case lir_rtcall: s = "rtcall"; break;
1896 case lir_throw: s = "throw"; break;
1897 case lir_unwind: s = "unwind"; break;
1898 case lir_convert: s = "convert"; break;
1899 case lir_alloc_object: s = "alloc_obj"; break;
1925 // LIR_Op4
1926 case lir_cmove: s = "cmove"; break;
1927 // LIR_OpJavaCall
1928 case lir_static_call: s = "static"; break;
1929 case lir_optvirtual_call: s = "optvirtual"; break;
1930 case lir_icvirtual_call: s = "icvirtual"; break;
1931 case lir_dynamic_call: s = "dynamic"; break;
1932 // LIR_OpArrayCopy
1933 case lir_arraycopy: s = "arraycopy"; break;
1934 // LIR_OpUpdateCRC32
1935 case lir_updatecrc32: s = "updatecrc32"; break;
1936 // LIR_OpLock
1937 case lir_lock: s = "lock"; break;
1938 case lir_unlock: s = "unlock"; break;
1939 // LIR_OpDelay
1940 case lir_delay_slot: s = "delay"; break;
1941 // LIR_OpTypeCheck
1942 case lir_instanceof: s = "instanceof"; break;
1943 case lir_checkcast: s = "checkcast"; break;
1944 case lir_store_check: s = "store_check"; break;
1945 // LIR_OpFlattenedArrayCheck
1946 case lir_flat_array_check: s = "flat_array_check"; break;
1947 // LIR_OpNullFreeArrayCheck
1948 case lir_null_free_array_check: s = "null_free_array_check"; break;
1949 // LIR_OpSubstitutabilityCheck
1950 case lir_substitutability_check: s = "substitutability_check"; break;
1951 // LIR_OpCompareAndSwap
1952 case lir_cas_long: s = "cas_long"; break;
1953 case lir_cas_obj: s = "cas_obj"; break;
1954 case lir_cas_int: s = "cas_int"; break;
1955 // LIR_OpProfileCall
1956 case lir_profile_call: s = "profile_call"; break;
1957 // LIR_OpProfileType
1958 case lir_profile_type: s = "profile_type"; break;
1959 // LIR_OpProfileInlineType
1960 case lir_profile_inline_type: s = "profile_inline_type"; break;
1961 // LIR_OpAssert
1962 #ifdef ASSERT
1963 case lir_assert: s = "assert"; break;
1964 #endif
1965 case lir_none: ShouldNotReachHere();break;
1966 default: s = "illegal_op"; break;
1967 }
1968 return s;
1969 }
1970
1971 // LIR_OpJavaCall
1972 void LIR_OpJavaCall::print_instr(outputStream* out) const {
1973 out->print("call: ");
1974 out->print("[addr: " INTPTR_FORMAT "]", p2i(address()));
1975 if (receiver()->is_valid()) {
1976 out->print(" [recv: "); receiver()->print(out); out->print("]");
1977 }
1978 if (result_opr()->is_valid()) {
1979 out->print(" [result: "); result_opr()->print(out); out->print("]");
1980 }
2166 out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry()));
2167 }
2168
2169
2170 void LIR_OpTypeCheck::print_instr(outputStream* out) const {
2171 object()->print(out); out->print(" ");
2172 if (code() == lir_store_check) {
2173 array()->print(out); out->print(" ");
2174 }
2175 if (code() != lir_store_check) {
2176 klass()->print_name_on(out); out->print(" ");
2177 if (fast_check()) out->print("fast_check ");
2178 }
2179 tmp1()->print(out); out->print(" ");
2180 tmp2()->print(out); out->print(" ");
2181 tmp3()->print(out); out->print(" ");
2182 result_opr()->print(out); out->print(" ");
2183 if (info_for_exception() != nullptr) out->print(" [bci:%d]", info_for_exception()->stack()->bci());
2184 }
2185
2186 void LIR_OpFlattenedArrayCheck::print_instr(outputStream* out) const {
2187 array()->print(out); out->print(" ");
2188 value()->print(out); out->print(" ");
2189 tmp()->print(out); out->print(" ");
2190 if (stub() != nullptr) {
2191 out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry()));
2192 }
2193 }
2194
2195 void LIR_OpNullFreeArrayCheck::print_instr(outputStream* out) const {
2196 array()->print(out); out->print(" ");
2197 tmp()->print(out); out->print(" ");
2198 }
2199
2200 void LIR_OpSubstitutabilityCheck::print_instr(outputStream* out) const {
2201 result_opr()->print(out); out->print(" ");
2202 left()->print(out); out->print(" ");
2203 right()->print(out); out->print(" ");
2204 equal_result()->print(out); out->print(" ");
2205 not_equal_result()->print(out); out->print(" ");
2206 tmp1()->print(out); out->print(" ");
2207 tmp2()->print(out); out->print(" ");
2208 if (left_klass() == nullptr) {
2209 out->print("unknown ");
2210 } else {
2211 left_klass()->print(out); out->print(" ");
2212 }
2213 if (right_klass() == nullptr) {
2214 out->print("unknown ");
2215 } else {
2216 right_klass()->print(out); out->print(" ");
2217 }
2218 left_klass_op()->print(out); out->print(" ");
2219 right_klass_op()->print(out); out->print(" ");
2220 if (stub() != nullptr) {
2221 out->print("[label:" INTPTR_FORMAT "]", p2i(stub()->entry()));
2222 }
2223 }
2224
2225 // LIR_Op3
2226 void LIR_Op3::print_instr(outputStream* out) const {
2227 in_opr1()->print(out); out->print(" ");
2228 in_opr2()->print(out); out->print(" ");
2229 in_opr3()->print(out); out->print(" ");
2230 result_opr()->print(out);
2231 }
2232
2233 // LIR_Op4
2234 void LIR_Op4::print_instr(outputStream* out) const {
2235 print_condition(out, condition()); out->print(" ");
2236 in_opr1()->print(out); out->print(" ");
2237 in_opr2()->print(out); out->print(" ");
2238 in_opr3()->print(out); out->print(" ");
2239 in_opr4()->print(out); out->print(" ");
2240 result_opr()->print(out);
2241 }
2242
2243 void LIR_OpLock::print_instr(outputStream* out) const {
2279 mdo()->print(out); out->print(" ");
2280 recv()->print(out); out->print(" ");
2281 tmp1()->print(out); out->print(" ");
2282 }
2283
2284 // LIR_OpProfileType
2285 void LIR_OpProfileType::print_instr(outputStream* out) const {
2286 out->print("exact = ");
2287 if (exact_klass() == nullptr) {
2288 out->print("unknown");
2289 } else {
2290 exact_klass()->print_name_on(out);
2291 }
2292 out->print(" current = "); ciTypeEntries::print_ciklass(out, current_klass());
2293 out->print(" ");
2294 mdp()->print(out); out->print(" ");
2295 obj()->print(out); out->print(" ");
2296 tmp()->print(out); out->print(" ");
2297 }
2298
2299 // LIR_OpProfileInlineType
2300 void LIR_OpProfileInlineType::print_instr(outputStream* out) const {
2301 out->print(" flag = %x ", flag());
2302 mdp()->print(out); out->print(" ");
2303 obj()->print(out); out->print(" ");
2304 tmp()->print(out); out->print(" ");
2305 }
2306
2307 #endif // PRODUCT
2308
2309 // Implementation of LIR_InsertionBuffer
2310
2311 void LIR_InsertionBuffer::append(int index, LIR_Op* op) {
2312 assert(_index_and_count.length() % 2 == 0, "must have a count for each index");
2313
2314 int i = number_of_insertion_points() - 1;
2315 if (i < 0 || index_at(i) < index) {
2316 append_new(index, 1);
2317 } else {
2318 assert(index_at(i) == index, "can append LIR_Ops in ascending order only");
2319 assert(count_at(i) > 0, "check");
2320 set_count_at(i, count_at(i) + 1);
2321 }
2322 _ops.push(op);
2323
2324 DEBUG_ONLY(verify());
2325 }
2326
|