Mercurial > hg > truffle
comparison src/share/vm/c1/c1_LIRGenerator.cpp @ 2491:0654ee04b214
Merge with OpenJDK.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 22 Apr 2011 15:30:53 +0200 |
parents | d25d4ca69222 d86923d96dca |
children | be4ca325525a |
comparison
equal
deleted
inserted
replaced
2490:29246b1d2d3c | 2491:0654ee04b214 |
---|---|
704 } else { | 704 } else { |
705 return NULL; | 705 return NULL; |
706 } | 706 } |
707 } | 707 } |
708 | 708 |
709 static Value maxvalue(IfOp* ifop) { | |
710 switch (ifop->cond()) { | |
711 case If::eql: return NULL; | |
712 case If::neq: return NULL; | |
713 case If::lss: // x < y ? x : y | |
714 case If::leq: // x <= y ? x : y | |
715 if (ifop->x() == ifop->tval() && | |
716 ifop->y() == ifop->fval()) return ifop->y(); | |
717 return NULL; | |
718 | |
719 case If::gtr: // x > y ? y : x | |
720 case If::geq: // x >= y ? y : x | |
721 if (ifop->x() == ifop->tval() && | |
722 ifop->y() == ifop->fval()) return ifop->y(); | |
723 return NULL; | |
724 | |
725 } | |
726 } | |
727 | |
728 static ciType* phi_declared_type(Phi* phi) { | |
729 ciType* t = phi->operand_at(0)->declared_type(); | |
730 if (t == NULL) { | |
731 return NULL; | |
732 } | |
733 for(int i = 1; i < phi->operand_count(); i++) { | |
734 if (t != phi->operand_at(i)->declared_type()) { | |
735 return NULL; | |
736 } | |
737 } | |
738 return t; | |
739 } | |
740 | |
709 void LIRGenerator::arraycopy_helper(Intrinsic* x, int* flagsp, ciArrayKlass** expected_typep) { | 741 void LIRGenerator::arraycopy_helper(Intrinsic* x, int* flagsp, ciArrayKlass** expected_typep) { |
710 Instruction* src = x->argument_at(0); | 742 Instruction* src = x->argument_at(0); |
711 Instruction* src_pos = x->argument_at(1); | 743 Instruction* src_pos = x->argument_at(1); |
712 Instruction* dst = x->argument_at(2); | 744 Instruction* dst = x->argument_at(2); |
713 Instruction* dst_pos = x->argument_at(3); | 745 Instruction* dst_pos = x->argument_at(3); |
714 Instruction* length = x->argument_at(4); | 746 Instruction* length = x->argument_at(4); |
715 | 747 |
716 // first try to identify the likely type of the arrays involved | 748 // first try to identify the likely type of the arrays involved |
717 ciArrayKlass* expected_type = NULL; | 749 ciArrayKlass* expected_type = NULL; |
718 bool is_exact = false; | 750 bool is_exact = false, src_objarray = false, dst_objarray = false; |
719 { | 751 { |
720 ciArrayKlass* src_exact_type = as_array_klass(src->exact_type()); | 752 ciArrayKlass* src_exact_type = as_array_klass(src->exact_type()); |
721 ciArrayKlass* src_declared_type = as_array_klass(src->declared_type()); | 753 ciArrayKlass* src_declared_type = as_array_klass(src->declared_type()); |
754 Phi* phi; | |
755 if (src_declared_type == NULL && (phi = src->as_Phi()) != NULL) { | |
756 src_declared_type = as_array_klass(phi_declared_type(phi)); | |
757 } | |
722 ciArrayKlass* dst_exact_type = as_array_klass(dst->exact_type()); | 758 ciArrayKlass* dst_exact_type = as_array_klass(dst->exact_type()); |
723 ciArrayKlass* dst_declared_type = as_array_klass(dst->declared_type()); | 759 ciArrayKlass* dst_declared_type = as_array_klass(dst->declared_type()); |
760 if (dst_declared_type == NULL && (phi = dst->as_Phi()) != NULL) { | |
761 dst_declared_type = as_array_klass(phi_declared_type(phi)); | |
762 } | |
763 | |
724 if (src_exact_type != NULL && src_exact_type == dst_exact_type) { | 764 if (src_exact_type != NULL && src_exact_type == dst_exact_type) { |
725 // the types exactly match so the type is fully known | 765 // the types exactly match so the type is fully known |
726 is_exact = true; | 766 is_exact = true; |
727 expected_type = src_exact_type; | 767 expected_type = src_exact_type; |
728 } else if (dst_exact_type != NULL && dst_exact_type->is_obj_array_klass()) { | 768 } else if (dst_exact_type != NULL && dst_exact_type->is_obj_array_klass()) { |
742 } | 782 } |
743 // at least pass along a good guess | 783 // at least pass along a good guess |
744 if (expected_type == NULL) expected_type = dst_exact_type; | 784 if (expected_type == NULL) expected_type = dst_exact_type; |
745 if (expected_type == NULL) expected_type = src_declared_type; | 785 if (expected_type == NULL) expected_type = src_declared_type; |
746 if (expected_type == NULL) expected_type = dst_declared_type; | 786 if (expected_type == NULL) expected_type = dst_declared_type; |
787 | |
788 src_objarray = (src_exact_type && src_exact_type->is_obj_array_klass()) || (src_declared_type && src_declared_type->is_obj_array_klass()); | |
789 dst_objarray = (dst_exact_type && dst_exact_type->is_obj_array_klass()) || (dst_declared_type && dst_declared_type->is_obj_array_klass()); | |
747 } | 790 } |
748 | 791 |
749 // if a probable array type has been identified, figure out if any | 792 // if a probable array type has been identified, figure out if any |
750 // of the required checks for a fast case can be elided. | 793 // of the required checks for a fast case can be elided. |
751 int flags = LIR_OpArrayCopy::all_flags; | 794 int flags = LIR_OpArrayCopy::all_flags; |
795 | |
796 if (!src_objarray) | |
797 flags &= ~LIR_OpArrayCopy::src_objarray; | |
798 if (!dst_objarray) | |
799 flags &= ~LIR_OpArrayCopy::dst_objarray; | |
800 | |
801 if (!x->arg_needs_null_check(0)) | |
802 flags &= ~LIR_OpArrayCopy::src_null_check; | |
803 if (!x->arg_needs_null_check(2)) | |
804 flags &= ~LIR_OpArrayCopy::dst_null_check; | |
805 | |
806 | |
752 if (expected_type != NULL) { | 807 if (expected_type != NULL) { |
753 // try to skip null checks | 808 Value length_limit = NULL; |
754 if (src->as_NewArray() != NULL) | 809 |
810 IfOp* ifop = length->as_IfOp(); | |
811 if (ifop != NULL) { | |
812 // look for expressions like min(v, a.length) which ends up as | |
813 // x > y ? y : x or x >= y ? y : x | |
814 if ((ifop->cond() == If::gtr || ifop->cond() == If::geq) && | |
815 ifop->x() == ifop->fval() && | |
816 ifop->y() == ifop->tval()) { | |
817 length_limit = ifop->y(); | |
818 } | |
819 } | |
820 | |
821 // try to skip null checks and range checks | |
822 NewArray* src_array = src->as_NewArray(); | |
823 if (src_array != NULL) { | |
755 flags &= ~LIR_OpArrayCopy::src_null_check; | 824 flags &= ~LIR_OpArrayCopy::src_null_check; |
756 if (dst->as_NewArray() != NULL) | 825 if (length_limit != NULL && |
826 src_array->length() == length_limit && | |
827 is_constant_zero(src_pos)) { | |
828 flags &= ~LIR_OpArrayCopy::src_range_check; | |
829 } | |
830 } | |
831 | |
832 NewArray* dst_array = dst->as_NewArray(); | |
833 if (dst_array != NULL) { | |
757 flags &= ~LIR_OpArrayCopy::dst_null_check; | 834 flags &= ~LIR_OpArrayCopy::dst_null_check; |
835 if (length_limit != NULL && | |
836 dst_array->length() == length_limit && | |
837 is_constant_zero(dst_pos)) { | |
838 flags &= ~LIR_OpArrayCopy::dst_range_check; | |
839 } | |
840 } | |
758 | 841 |
759 // check from incoming constant values | 842 // check from incoming constant values |
760 if (positive_constant(src_pos)) | 843 if (positive_constant(src_pos)) |
761 flags &= ~LIR_OpArrayCopy::src_pos_positive_check; | 844 flags &= ~LIR_OpArrayCopy::src_pos_positive_check; |
762 if (positive_constant(dst_pos)) | 845 if (positive_constant(dst_pos)) |
784 } | 867 } |
785 } | 868 } |
786 if (is_exact) { | 869 if (is_exact) { |
787 flags &= ~LIR_OpArrayCopy::type_check; | 870 flags &= ~LIR_OpArrayCopy::type_check; |
788 } | 871 } |
872 } | |
873 | |
874 IntConstant* src_int = src_pos->type()->as_IntConstant(); | |
875 IntConstant* dst_int = dst_pos->type()->as_IntConstant(); | |
876 if (src_int && dst_int) { | |
877 int s_offs = src_int->value(); | |
878 int d_offs = dst_int->value(); | |
879 if (src_int->value() >= dst_int->value()) { | |
880 flags &= ~LIR_OpArrayCopy::overlapping; | |
881 } | |
882 if (expected_type != NULL) { | |
883 BasicType t = expected_type->element_type()->basic_type(); | |
884 int element_size = type2aelembytes(t); | |
885 if (((arrayOopDesc::base_offset_in_bytes(t) + s_offs * element_size) % HeapWordSize == 0) && | |
886 ((arrayOopDesc::base_offset_in_bytes(t) + d_offs * element_size) % HeapWordSize == 0)) { | |
887 flags &= ~LIR_OpArrayCopy::unaligned; | |
888 } | |
889 } | |
890 } else if (src_pos == dst_pos || is_constant_zero(dst_pos)) { | |
891 // src and dest positions are the same, or dst is zero so assume | |
892 // nonoverlapping copy. | |
893 flags &= ~LIR_OpArrayCopy::overlapping; | |
789 } | 894 } |
790 | 895 |
791 if (src == dst) { | 896 if (src == dst) { |
792 // moving within a single array so no type checks are needed | 897 // moving within a single array so no type checks are needed |
793 if (flags & LIR_OpArrayCopy::type_check) { | 898 if (flags & LIR_OpArrayCopy::type_check) { |
1349 } | 1454 } |
1350 assert(new_val->is_register(), "must be a register at this point"); | 1455 assert(new_val->is_register(), "must be a register at this point"); |
1351 | 1456 |
1352 if (addr->is_address()) { | 1457 if (addr->is_address()) { |
1353 LIR_Address* address = addr->as_address_ptr(); | 1458 LIR_Address* address = addr->as_address_ptr(); |
1354 LIR_Opr ptr = new_register(T_OBJECT); | 1459 LIR_Opr ptr = new_pointer_register(); |
1355 if (!address->index()->is_valid() && address->disp() == 0) { | 1460 if (!address->index()->is_valid() && address->disp() == 0) { |
1356 __ move(address->base(), ptr); | 1461 __ move(address->base(), ptr); |
1357 } else { | 1462 } else { |
1358 assert(address->disp() != max_jint, "lea doesn't support patched addresses!"); | 1463 assert(address->disp() != max_jint, "lea doesn't support patched addresses!"); |
1359 __ leal(addr, ptr); | 1464 __ leal(addr, ptr); |
1401 | 1506 |
1402 assert(sizeof(*((CardTableModRefBS*)_bs)->byte_map_base) == sizeof(jbyte), "adjust this code"); | 1507 assert(sizeof(*((CardTableModRefBS*)_bs)->byte_map_base) == sizeof(jbyte), "adjust this code"); |
1403 LIR_Const* card_table_base = new LIR_Const(((CardTableModRefBS*)_bs)->byte_map_base); | 1508 LIR_Const* card_table_base = new LIR_Const(((CardTableModRefBS*)_bs)->byte_map_base); |
1404 if (addr->is_address()) { | 1509 if (addr->is_address()) { |
1405 LIR_Address* address = addr->as_address_ptr(); | 1510 LIR_Address* address = addr->as_address_ptr(); |
1406 LIR_Opr ptr = new_register(T_OBJECT); | 1511 // ptr cannot be an object because we use this barrier for array card marks |
1512 // and addr can point in the middle of an array. | |
1513 LIR_Opr ptr = new_pointer_register(); | |
1407 if (!address->index()->is_valid() && address->disp() == 0) { | 1514 if (!address->index()->is_valid() && address->disp() == 0) { |
1408 __ move(address->base(), ptr); | 1515 __ move(address->base(), ptr); |
1409 } else { | 1516 } else { |
1410 assert(address->disp() != max_jint, "lea doesn't support patched addresses!"); | 1517 assert(address->disp() != max_jint, "lea doesn't support patched addresses!"); |
1411 __ leal(addr, ptr); | 1518 __ leal(addr, ptr); |
1557 pre_barrier(LIR_OprFact::address(address), | 1664 pre_barrier(LIR_OprFact::address(address), |
1558 needs_patching, | 1665 needs_patching, |
1559 (info ? new CodeEmitInfo(info) : NULL)); | 1666 (info ? new CodeEmitInfo(info) : NULL)); |
1560 } | 1667 } |
1561 | 1668 |
1562 if (is_volatile) { | 1669 if (is_volatile && !needs_patching) { |
1563 assert(!needs_patching && x->is_loaded(), | |
1564 "how do we know it's volatile if it's not loaded"); | |
1565 volatile_field_store(value.result(), address, info); | 1670 volatile_field_store(value.result(), address, info); |
1566 } else { | 1671 } else { |
1567 LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none; | 1672 LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none; |
1568 __ store(value.result(), address, info, patch_code); | 1673 __ store(value.result(), address, info, patch_code); |
1569 } | 1674 } |
1625 address = new LIR_Address(object.result(), PATCHED_ADDR, field_type); | 1730 address = new LIR_Address(object.result(), PATCHED_ADDR, field_type); |
1626 } else { | 1731 } else { |
1627 address = generate_address(object.result(), x->offset(), field_type); | 1732 address = generate_address(object.result(), x->offset(), field_type); |
1628 } | 1733 } |
1629 | 1734 |
1630 if (is_volatile) { | 1735 if (is_volatile && !needs_patching) { |
1631 assert(!needs_patching && x->is_loaded(), | |
1632 "how do we know it's volatile if it's not loaded"); | |
1633 volatile_field_load(address, reg, info); | 1736 volatile_field_load(address, reg, info); |
1634 } else { | 1737 } else { |
1635 LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none; | 1738 LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none; |
1636 __ load(address, reg, info, patch_code); | 1739 __ load(address, reg, info, patch_code); |
1637 } | 1740 } |
2514 // Load CallSite object from constant pool cache. | 2617 // Load CallSite object from constant pool cache. |
2515 __ oop2reg(cpcache->constant_encoding(), tmp); | 2618 __ oop2reg(cpcache->constant_encoding(), tmp); |
2516 __ load(new LIR_Address(tmp, (int)call_site_offset, T_OBJECT), tmp); | 2619 __ load(new LIR_Address(tmp, (int)call_site_offset, T_OBJECT), tmp); |
2517 | 2620 |
2518 // Load target MethodHandle from CallSite object. | 2621 // Load target MethodHandle from CallSite object. |
2519 __ load(new LIR_Address(tmp, java_dyn_CallSite::target_offset_in_bytes(), T_OBJECT), receiver); | 2622 __ load(new LIR_Address(tmp, java_lang_invoke_CallSite::target_offset_in_bytes(), T_OBJECT), receiver); |
2520 | 2623 |
2521 __ call_dynamic(target, receiver, result_register, | 2624 __ call_dynamic(target, receiver, result_register, |
2522 SharedRuntime::get_resolve_opt_virtual_call_stub(), | 2625 SharedRuntime::get_resolve_opt_virtual_call_stub(), |
2523 arg_list, info); | 2626 arg_list, info); |
2524 break; | 2627 break; |