491
492 void do_Phi (Phi* x);
493 void do_Local (Local* x);
494 void do_Constant (Constant* x);
495 void do_LoadField (LoadField* x);
496 void do_StoreField (StoreField* x);
497 void do_ArrayLength (ArrayLength* x);
498 void do_LoadIndexed (LoadIndexed* x);
499 void do_StoreIndexed (StoreIndexed* x);
500 void do_NegateOp (NegateOp* x);
501 void do_ArithmeticOp (ArithmeticOp* x);
502 void do_ShiftOp (ShiftOp* x);
503 void do_LogicOp (LogicOp* x);
504 void do_CompareOp (CompareOp* x);
505 void do_IfOp (IfOp* x);
506 void do_Convert (Convert* x);
507 void do_NullCheck (NullCheck* x);
508 void do_TypeCast (TypeCast* x);
509 void do_Invoke (Invoke* x);
510 void do_NewInstance (NewInstance* x);
511 void do_NewTypeArray (NewTypeArray* x);
512 void do_NewObjectArray (NewObjectArray* x);
513 void do_NewMultiArray (NewMultiArray* x);
514 void do_CheckCast (CheckCast* x);
515 void do_InstanceOf (InstanceOf* x);
516 void do_MonitorEnter (MonitorEnter* x);
517 void do_MonitorExit (MonitorExit* x);
518 void do_Intrinsic (Intrinsic* x);
519 void do_BlockBegin (BlockBegin* x);
520 void do_Goto (Goto* x);
521 void do_If (If* x);
522 void do_IfInstanceOf (IfInstanceOf* x);
523 void do_TableSwitch (TableSwitch* x);
524 void do_LookupSwitch (LookupSwitch* x);
525 void do_Return (Return* x);
526 void do_Throw (Throw* x);
527 void do_Base (Base* x);
528 void do_OsrEntry (OsrEntry* x);
529 void do_ExceptionObject(ExceptionObject* x);
530 void do_RoundFP (RoundFP* x);
639 _last_explicit_null_check->unpin(Instruction::PinExplicitNullCheck);
640 _last_explicit_null_check->set_can_trap(false);
641 return _last_explicit_null_check;
642 }
643 void clear_last_explicit_null_check() { _last_explicit_null_check = NULL; }
644
645 // Handlers for relevant instructions
646 // (separated out from NullCheckVisitor for clarity)
647
648 // The basic contract is that these must leave the instruction in
649 // the desired state; must not assume anything about the state of
650 // the instruction. We make multiple passes over some basic blocks
651 // and the last pass is the only one whose result is valid.
652 void handle_AccessField (AccessField* x);
653 void handle_ArrayLength (ArrayLength* x);
654 void handle_LoadIndexed (LoadIndexed* x);
655 void handle_StoreIndexed (StoreIndexed* x);
656 void handle_NullCheck (NullCheck* x);
657 void handle_Invoke (Invoke* x);
658 void handle_NewInstance (NewInstance* x);
659 void handle_NewArray (NewArray* x);
660 void handle_AccessMonitor (AccessMonitor* x);
661 void handle_Intrinsic (Intrinsic* x);
662 void handle_ExceptionObject (ExceptionObject* x);
663 void handle_Phi (Phi* x);
664 void handle_ProfileCall (ProfileCall* x);
665 void handle_ProfileReturnType (ProfileReturnType* x);
666 };
667
668
669 // NEEDS_CLEANUP
670 // There may be other instructions which need to clear the last
671 // explicit null check. Anything across which we can not hoist the
672 // debug information for a NullCheck instruction must clear it. It
673 // might be safer to pattern match "NullCheck ; {AccessField,
674 // ArrayLength, LoadIndexed}" but it is more easily structured this way.
675 // Should test to see performance hit of clearing it for all handlers
676 // with empty bodies below. If it is negligible then we should leave
677 // that in for safety, otherwise should think more about it.
678 void NullCheckVisitor::do_Phi (Phi* x) { nce()->handle_Phi(x); }
679 void NullCheckVisitor::do_Local (Local* x) {}
680 void NullCheckVisitor::do_Constant (Constant* x) { /* FIXME: handle object constants */ }
681 void NullCheckVisitor::do_LoadField (LoadField* x) { nce()->handle_AccessField(x); }
682 void NullCheckVisitor::do_StoreField (StoreField* x) { nce()->handle_AccessField(x); }
683 void NullCheckVisitor::do_ArrayLength (ArrayLength* x) { nce()->handle_ArrayLength(x); }
684 void NullCheckVisitor::do_LoadIndexed (LoadIndexed* x) { nce()->handle_LoadIndexed(x); }
685 void NullCheckVisitor::do_StoreIndexed (StoreIndexed* x) { nce()->handle_StoreIndexed(x); }
686 void NullCheckVisitor::do_NegateOp (NegateOp* x) {}
687 void NullCheckVisitor::do_ArithmeticOp (ArithmeticOp* x) { if (x->can_trap()) nce()->clear_last_explicit_null_check(); }
688 void NullCheckVisitor::do_ShiftOp (ShiftOp* x) {}
689 void NullCheckVisitor::do_LogicOp (LogicOp* x) {}
690 void NullCheckVisitor::do_CompareOp (CompareOp* x) {}
691 void NullCheckVisitor::do_IfOp (IfOp* x) {}
692 void NullCheckVisitor::do_Convert (Convert* x) {}
693 void NullCheckVisitor::do_NullCheck (NullCheck* x) { nce()->handle_NullCheck(x); }
694 void NullCheckVisitor::do_TypeCast (TypeCast* x) {}
695 void NullCheckVisitor::do_Invoke (Invoke* x) { nce()->handle_Invoke(x); }
696 void NullCheckVisitor::do_NewInstance (NewInstance* x) { nce()->handle_NewInstance(x); }
697 void NullCheckVisitor::do_NewTypeArray (NewTypeArray* x) { nce()->handle_NewArray(x); }
698 void NullCheckVisitor::do_NewObjectArray (NewObjectArray* x) { nce()->handle_NewArray(x); }
699 void NullCheckVisitor::do_NewMultiArray (NewMultiArray* x) { nce()->handle_NewArray(x); }
700 void NullCheckVisitor::do_CheckCast (CheckCast* x) { nce()->clear_last_explicit_null_check(); }
701 void NullCheckVisitor::do_InstanceOf (InstanceOf* x) {}
702 void NullCheckVisitor::do_MonitorEnter (MonitorEnter* x) { nce()->handle_AccessMonitor(x); }
703 void NullCheckVisitor::do_MonitorExit (MonitorExit* x) { nce()->handle_AccessMonitor(x); }
704 void NullCheckVisitor::do_Intrinsic (Intrinsic* x) { nce()->handle_Intrinsic(x); }
705 void NullCheckVisitor::do_BlockBegin (BlockBegin* x) {}
706 void NullCheckVisitor::do_Goto (Goto* x) {}
707 void NullCheckVisitor::do_If (If* x) {}
708 void NullCheckVisitor::do_IfInstanceOf (IfInstanceOf* x) {}
709 void NullCheckVisitor::do_TableSwitch (TableSwitch* x) {}
710 void NullCheckVisitor::do_LookupSwitch (LookupSwitch* x) {}
711 void NullCheckVisitor::do_Return (Return* x) {}
712 void NullCheckVisitor::do_Throw (Throw* x) { nce()->clear_last_explicit_null_check(); }
713 void NullCheckVisitor::do_Base (Base* x) {}
714 void NullCheckVisitor::do_OsrEntry (OsrEntry* x) {}
715 void NullCheckVisitor::do_ExceptionObject(ExceptionObject* x) { nce()->handle_ExceptionObject(x); }
716 void NullCheckVisitor::do_RoundFP (RoundFP* x) {}
851 }
852 }
853 }
854
855
856 void NullCheckEliminator::iterate(BlockBegin* block) {
857 work_list()->push(block);
858 iterate_all();
859 }
860
861 void NullCheckEliminator::handle_AccessField(AccessField* x) {
862 if (x->is_static()) {
863 if (x->as_LoadField() != NULL) {
864 // If the field is a non-null static final object field (as is
865 // often the case for sun.misc.Unsafe), put this LoadField into
866 // the non-null map
867 ciField* field = x->field();
868 if (field->is_constant()) {
869 ciConstant field_val = field->constant_value();
870 BasicType field_type = field_val.basic_type();
871 if (field_type == T_OBJECT || field_type == T_ARRAY) {
872 ciObject* obj_val = field_val.as_object();
873 if (!obj_val->is_null_object()) {
874 if (PrintNullCheckElimination) {
875 tty->print_cr("AccessField %d proven non-null by static final non-null oop check",
876 x->id());
877 }
878 set_put(x);
879 }
880 }
881 }
882 }
883 // Be conservative
884 clear_last_explicit_null_check();
885 return;
886 }
887
888 Value obj = x->obj();
889 if (set_contains(obj)) {
890 // Value is non-null => update AccessField
891 if (last_explicit_null_check_obj() == obj && !x->needs_patching()) {
1026 // Be conservative
1027 clear_last_explicit_null_check();
1028 return;
1029 }
1030
1031 Value recv = x->receiver();
1032 if (!set_contains(recv)) {
1033 set_put(recv);
1034 if (PrintNullCheckElimination) {
1035 tty->print_cr("Invoke %d of value %d proves value to be non-null", x->id(), recv->id());
1036 }
1037 }
1038 clear_last_explicit_null_check();
1039 }
1040
1041
1042 void NullCheckEliminator::handle_NewInstance(NewInstance* x) {
1043 set_put(x);
1044 if (PrintNullCheckElimination) {
1045 tty->print_cr("NewInstance %d is non-null", x->id());
1046 }
1047 }
1048
1049
1050 void NullCheckEliminator::handle_NewArray(NewArray* x) {
1051 set_put(x);
1052 if (PrintNullCheckElimination) {
1053 tty->print_cr("NewArray %d is non-null", x->id());
1054 }
1055 }
1056
1057
1058 void NullCheckEliminator::handle_ExceptionObject(ExceptionObject* x) {
1059 set_put(x);
1060 if (PrintNullCheckElimination) {
1061 tty->print_cr("ExceptionObject %d is non-null", x->id());
1062 }
1063 }
1064
1065
|
491
492 void do_Phi (Phi* x);
493 void do_Local (Local* x);
494 void do_Constant (Constant* x);
495 void do_LoadField (LoadField* x);
496 void do_StoreField (StoreField* x);
497 void do_ArrayLength (ArrayLength* x);
498 void do_LoadIndexed (LoadIndexed* x);
499 void do_StoreIndexed (StoreIndexed* x);
500 void do_NegateOp (NegateOp* x);
501 void do_ArithmeticOp (ArithmeticOp* x);
502 void do_ShiftOp (ShiftOp* x);
503 void do_LogicOp (LogicOp* x);
504 void do_CompareOp (CompareOp* x);
505 void do_IfOp (IfOp* x);
506 void do_Convert (Convert* x);
507 void do_NullCheck (NullCheck* x);
508 void do_TypeCast (TypeCast* x);
509 void do_Invoke (Invoke* x);
510 void do_NewInstance (NewInstance* x);
511 void do_NewValueTypeInstance(NewValueTypeInstance* x);
512 void do_NewTypeArray (NewTypeArray* x);
513 void do_NewObjectArray (NewObjectArray* x);
514 void do_NewMultiArray (NewMultiArray* x);
515 void do_CheckCast (CheckCast* x);
516 void do_InstanceOf (InstanceOf* x);
517 void do_MonitorEnter (MonitorEnter* x);
518 void do_MonitorExit (MonitorExit* x);
519 void do_Intrinsic (Intrinsic* x);
520 void do_BlockBegin (BlockBegin* x);
521 void do_Goto (Goto* x);
522 void do_If (If* x);
523 void do_IfInstanceOf (IfInstanceOf* x);
524 void do_TableSwitch (TableSwitch* x);
525 void do_LookupSwitch (LookupSwitch* x);
526 void do_Return (Return* x);
527 void do_Throw (Throw* x);
528 void do_Base (Base* x);
529 void do_OsrEntry (OsrEntry* x);
530 void do_ExceptionObject(ExceptionObject* x);
531 void do_RoundFP (RoundFP* x);
640 _last_explicit_null_check->unpin(Instruction::PinExplicitNullCheck);
641 _last_explicit_null_check->set_can_trap(false);
642 return _last_explicit_null_check;
643 }
644 void clear_last_explicit_null_check() { _last_explicit_null_check = NULL; }
645
646 // Handlers for relevant instructions
647 // (separated out from NullCheckVisitor for clarity)
648
649 // The basic contract is that these must leave the instruction in
650 // the desired state; must not assume anything about the state of
651 // the instruction. We make multiple passes over some basic blocks
652 // and the last pass is the only one whose result is valid.
653 void handle_AccessField (AccessField* x);
654 void handle_ArrayLength (ArrayLength* x);
655 void handle_LoadIndexed (LoadIndexed* x);
656 void handle_StoreIndexed (StoreIndexed* x);
657 void handle_NullCheck (NullCheck* x);
658 void handle_Invoke (Invoke* x);
659 void handle_NewInstance (NewInstance* x);
660 void handle_NewValueTypeInstance(NewValueTypeInstance* x);
661 void handle_NewArray (NewArray* x);
662 void handle_AccessMonitor (AccessMonitor* x);
663 void handle_Intrinsic (Intrinsic* x);
664 void handle_ExceptionObject (ExceptionObject* x);
665 void handle_Phi (Phi* x);
666 void handle_ProfileCall (ProfileCall* x);
667 void handle_ProfileReturnType (ProfileReturnType* x);
668 };
669
670
671 // NEEDS_CLEANUP
672 // There may be other instructions which need to clear the last
673 // explicit null check. Anything across which we can not hoist the
674 // debug information for a NullCheck instruction must clear it. It
675 // might be safer to pattern match "NullCheck ; {AccessField,
676 // ArrayLength, LoadIndexed}" but it is more easily structured this way.
677 // Should test to see performance hit of clearing it for all handlers
678 // with empty bodies below. If it is negligible then we should leave
679 // that in for safety, otherwise should think more about it.
680 void NullCheckVisitor::do_Phi (Phi* x) { nce()->handle_Phi(x); }
681 void NullCheckVisitor::do_Local (Local* x) {}
682 void NullCheckVisitor::do_Constant (Constant* x) { /* FIXME: handle object constants */ }
683 void NullCheckVisitor::do_LoadField (LoadField* x) { nce()->handle_AccessField(x); }
684 void NullCheckVisitor::do_StoreField (StoreField* x) { nce()->handle_AccessField(x); }
685 void NullCheckVisitor::do_ArrayLength (ArrayLength* x) { nce()->handle_ArrayLength(x); }
686 void NullCheckVisitor::do_LoadIndexed (LoadIndexed* x) { nce()->handle_LoadIndexed(x); }
687 void NullCheckVisitor::do_StoreIndexed (StoreIndexed* x) { nce()->handle_StoreIndexed(x); }
688 void NullCheckVisitor::do_NegateOp (NegateOp* x) {}
689 void NullCheckVisitor::do_ArithmeticOp (ArithmeticOp* x) { if (x->can_trap()) nce()->clear_last_explicit_null_check(); }
690 void NullCheckVisitor::do_ShiftOp (ShiftOp* x) {}
691 void NullCheckVisitor::do_LogicOp (LogicOp* x) {}
692 void NullCheckVisitor::do_CompareOp (CompareOp* x) {}
693 void NullCheckVisitor::do_IfOp (IfOp* x) {}
694 void NullCheckVisitor::do_Convert (Convert* x) {}
695 void NullCheckVisitor::do_NullCheck (NullCheck* x) { nce()->handle_NullCheck(x); }
696 void NullCheckVisitor::do_TypeCast (TypeCast* x) {}
697 void NullCheckVisitor::do_Invoke (Invoke* x) { nce()->handle_Invoke(x); }
698 void NullCheckVisitor::do_NewInstance (NewInstance* x) { nce()->handle_NewInstance(x); }
699 void NullCheckVisitor::do_NewValueTypeInstance(NewValueTypeInstance* x) { nce()->handle_NewValueTypeInstance(x); }
700 void NullCheckVisitor::do_NewTypeArray (NewTypeArray* x) { nce()->handle_NewArray(x); }
701 void NullCheckVisitor::do_NewObjectArray (NewObjectArray* x) { nce()->handle_NewArray(x); }
702 void NullCheckVisitor::do_NewMultiArray (NewMultiArray* x) { nce()->handle_NewArray(x); }
703 void NullCheckVisitor::do_CheckCast (CheckCast* x) { nce()->clear_last_explicit_null_check(); }
704 void NullCheckVisitor::do_InstanceOf (InstanceOf* x) {}
705 void NullCheckVisitor::do_MonitorEnter (MonitorEnter* x) { nce()->handle_AccessMonitor(x); }
706 void NullCheckVisitor::do_MonitorExit (MonitorExit* x) { nce()->handle_AccessMonitor(x); }
707 void NullCheckVisitor::do_Intrinsic (Intrinsic* x) { nce()->handle_Intrinsic(x); }
708 void NullCheckVisitor::do_BlockBegin (BlockBegin* x) {}
709 void NullCheckVisitor::do_Goto (Goto* x) {}
710 void NullCheckVisitor::do_If (If* x) {}
711 void NullCheckVisitor::do_IfInstanceOf (IfInstanceOf* x) {}
712 void NullCheckVisitor::do_TableSwitch (TableSwitch* x) {}
713 void NullCheckVisitor::do_LookupSwitch (LookupSwitch* x) {}
714 void NullCheckVisitor::do_Return (Return* x) {}
715 void NullCheckVisitor::do_Throw (Throw* x) { nce()->clear_last_explicit_null_check(); }
716 void NullCheckVisitor::do_Base (Base* x) {}
717 void NullCheckVisitor::do_OsrEntry (OsrEntry* x) {}
718 void NullCheckVisitor::do_ExceptionObject(ExceptionObject* x) { nce()->handle_ExceptionObject(x); }
719 void NullCheckVisitor::do_RoundFP (RoundFP* x) {}
854 }
855 }
856 }
857
858
859 void NullCheckEliminator::iterate(BlockBegin* block) {
860 work_list()->push(block);
861 iterate_all();
862 }
863
864 void NullCheckEliminator::handle_AccessField(AccessField* x) {
865 if (x->is_static()) {
866 if (x->as_LoadField() != NULL) {
867 // If the field is a non-null static final object field (as is
868 // often the case for sun.misc.Unsafe), put this LoadField into
869 // the non-null map
870 ciField* field = x->field();
871 if (field->is_constant()) {
872 ciConstant field_val = field->constant_value();
873 BasicType field_type = field_val.basic_type();
874 if (field_type == T_OBJECT || field_type == T_ARRAY || field_type == T_VALUETYPE) {
875 ciObject* obj_val = field_val.as_object();
876 if (!obj_val->is_null_object()) {
877 if (PrintNullCheckElimination) {
878 tty->print_cr("AccessField %d proven non-null by static final non-null oop check",
879 x->id());
880 }
881 set_put(x);
882 }
883 }
884 }
885 }
886 // Be conservative
887 clear_last_explicit_null_check();
888 return;
889 }
890
891 Value obj = x->obj();
892 if (set_contains(obj)) {
893 // Value is non-null => update AccessField
894 if (last_explicit_null_check_obj() == obj && !x->needs_patching()) {
1029 // Be conservative
1030 clear_last_explicit_null_check();
1031 return;
1032 }
1033
1034 Value recv = x->receiver();
1035 if (!set_contains(recv)) {
1036 set_put(recv);
1037 if (PrintNullCheckElimination) {
1038 tty->print_cr("Invoke %d of value %d proves value to be non-null", x->id(), recv->id());
1039 }
1040 }
1041 clear_last_explicit_null_check();
1042 }
1043
1044
1045 void NullCheckEliminator::handle_NewInstance(NewInstance* x) {
1046 set_put(x);
1047 if (PrintNullCheckElimination) {
1048 tty->print_cr("NewInstance %d is non-null", x->id());
1049 }
1050 }
1051
1052 void NullCheckEliminator::handle_NewValueTypeInstance(NewValueTypeInstance* x) {
1053 set_put(x);
1054 if (PrintNullCheckElimination) {
1055 tty->print_cr("NewValueTypeInstance %d is non-null", x->id());
1056 }
1057 }
1058
1059
1060 void NullCheckEliminator::handle_NewArray(NewArray* x) {
1061 set_put(x);
1062 if (PrintNullCheckElimination) {
1063 tty->print_cr("NewArray %d is non-null", x->id());
1064 }
1065 }
1066
1067
1068 void NullCheckEliminator::handle_ExceptionObject(ExceptionObject* x) {
1069 set_put(x);
1070 if (PrintNullCheckElimination) {
1071 tty->print_cr("ExceptionObject %d is non-null", x->id());
1072 }
1073 }
1074
1075
|