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) { |