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