< prev index next >

src/hotspot/share/c1/c1_Optimizer.cpp

Print this page


 485 
 486   void do_Phi            (Phi*             x);
 487   void do_Local          (Local*           x);
 488   void do_Constant       (Constant*        x);
 489   void do_LoadField      (LoadField*       x);
 490   void do_StoreField     (StoreField*      x);
 491   void do_ArrayLength    (ArrayLength*     x);
 492   void do_LoadIndexed    (LoadIndexed*     x);
 493   void do_StoreIndexed   (StoreIndexed*    x);
 494   void do_NegateOp       (NegateOp*        x);
 495   void do_ArithmeticOp   (ArithmeticOp*    x);
 496   void do_ShiftOp        (ShiftOp*         x);
 497   void do_LogicOp        (LogicOp*         x);
 498   void do_CompareOp      (CompareOp*       x);
 499   void do_IfOp           (IfOp*            x);
 500   void do_Convert        (Convert*         x);
 501   void do_NullCheck      (NullCheck*       x);
 502   void do_TypeCast       (TypeCast*        x);
 503   void do_Invoke         (Invoke*          x);
 504   void do_NewInstance    (NewInstance*     x);

 505   void do_NewTypeArray   (NewTypeArray*    x);
 506   void do_NewObjectArray (NewObjectArray*  x);
 507   void do_NewMultiArray  (NewMultiArray*   x);
 508   void do_CheckCast      (CheckCast*       x);
 509   void do_InstanceOf     (InstanceOf*      x);
 510   void do_MonitorEnter   (MonitorEnter*    x);
 511   void do_MonitorExit    (MonitorExit*     x);
 512   void do_Intrinsic      (Intrinsic*       x);
 513   void do_BlockBegin     (BlockBegin*      x);
 514   void do_Goto           (Goto*            x);
 515   void do_If             (If*              x);
 516   void do_IfInstanceOf   (IfInstanceOf*    x);
 517   void do_TableSwitch    (TableSwitch*     x);
 518   void do_LookupSwitch   (LookupSwitch*    x);
 519   void do_Return         (Return*          x);
 520   void do_Throw          (Throw*           x);
 521   void do_Base           (Base*            x);
 522   void do_OsrEntry       (OsrEntry*        x);
 523   void do_ExceptionObject(ExceptionObject* x);
 524   void do_RoundFP        (RoundFP*         x);


 633     _last_explicit_null_check->unpin(Instruction::PinExplicitNullCheck);
 634     _last_explicit_null_check->set_can_trap(false);
 635     return _last_explicit_null_check;
 636   }
 637   void        clear_last_explicit_null_check()               { _last_explicit_null_check = NULL; }
 638 
 639   // Handlers for relevant instructions
 640   // (separated out from NullCheckVisitor for clarity)
 641 
 642   // The basic contract is that these must leave the instruction in
 643   // the desired state; must not assume anything about the state of
 644   // the instruction. We make multiple passes over some basic blocks
 645   // and the last pass is the only one whose result is valid.
 646   void handle_AccessField     (AccessField* x);
 647   void handle_ArrayLength     (ArrayLength* x);
 648   void handle_LoadIndexed     (LoadIndexed* x);
 649   void handle_StoreIndexed    (StoreIndexed* x);
 650   void handle_NullCheck       (NullCheck* x);
 651   void handle_Invoke          (Invoke* x);
 652   void handle_NewInstance     (NewInstance* x);

 653   void handle_NewArray        (NewArray* x);
 654   void handle_AccessMonitor   (AccessMonitor* x);
 655   void handle_Intrinsic       (Intrinsic* x);
 656   void handle_ExceptionObject (ExceptionObject* x);
 657   void handle_Phi             (Phi* x);
 658   void handle_ProfileCall     (ProfileCall* x);
 659   void handle_ProfileReturnType (ProfileReturnType* x);
 660 };
 661 
 662 
 663 // NEEDS_CLEANUP
 664 // There may be other instructions which need to clear the last
 665 // explicit null check. Anything across which we can not hoist the
 666 // debug information for a NullCheck instruction must clear it. It
 667 // might be safer to pattern match "NullCheck ; {AccessField,
 668 // ArrayLength, LoadIndexed}" but it is more easily structured this way.
 669 // Should test to see performance hit of clearing it for all handlers
 670 // with empty bodies below. If it is negligible then we should leave
 671 // that in for safety, otherwise should think more about it.
 672 void NullCheckVisitor::do_Phi            (Phi*             x) { nce()->handle_Phi(x);      }
 673 void NullCheckVisitor::do_Local          (Local*           x) {}
 674 void NullCheckVisitor::do_Constant       (Constant*        x) { /* FIXME: handle object constants */ }
 675 void NullCheckVisitor::do_LoadField      (LoadField*       x) { nce()->handle_AccessField(x); }
 676 void NullCheckVisitor::do_StoreField     (StoreField*      x) { nce()->handle_AccessField(x); }
 677 void NullCheckVisitor::do_ArrayLength    (ArrayLength*     x) { nce()->handle_ArrayLength(x); }
 678 void NullCheckVisitor::do_LoadIndexed    (LoadIndexed*     x) { nce()->handle_LoadIndexed(x); }
 679 void NullCheckVisitor::do_StoreIndexed   (StoreIndexed*    x) { nce()->handle_StoreIndexed(x); }
 680 void NullCheckVisitor::do_NegateOp       (NegateOp*        x) {}
 681 void NullCheckVisitor::do_ArithmeticOp   (ArithmeticOp*    x) { if (x->can_trap()) nce()->clear_last_explicit_null_check(); }
 682 void NullCheckVisitor::do_ShiftOp        (ShiftOp*         x) {}
 683 void NullCheckVisitor::do_LogicOp        (LogicOp*         x) {}
 684 void NullCheckVisitor::do_CompareOp      (CompareOp*       x) {}
 685 void NullCheckVisitor::do_IfOp           (IfOp*            x) {}
 686 void NullCheckVisitor::do_Convert        (Convert*         x) {}
 687 void NullCheckVisitor::do_NullCheck      (NullCheck*       x) { nce()->handle_NullCheck(x); }
 688 void NullCheckVisitor::do_TypeCast       (TypeCast*        x) {}
 689 void NullCheckVisitor::do_Invoke         (Invoke*          x) { nce()->handle_Invoke(x); }
 690 void NullCheckVisitor::do_NewInstance    (NewInstance*     x) { nce()->handle_NewInstance(x); }

 691 void NullCheckVisitor::do_NewTypeArray   (NewTypeArray*    x) { nce()->handle_NewArray(x); }
 692 void NullCheckVisitor::do_NewObjectArray (NewObjectArray*  x) { nce()->handle_NewArray(x); }
 693 void NullCheckVisitor::do_NewMultiArray  (NewMultiArray*   x) { nce()->handle_NewArray(x); }
 694 void NullCheckVisitor::do_CheckCast      (CheckCast*       x) { nce()->clear_last_explicit_null_check(); }
 695 void NullCheckVisitor::do_InstanceOf     (InstanceOf*      x) {}
 696 void NullCheckVisitor::do_MonitorEnter   (MonitorEnter*    x) { nce()->handle_AccessMonitor(x); }
 697 void NullCheckVisitor::do_MonitorExit    (MonitorExit*     x) { nce()->handle_AccessMonitor(x); }
 698 void NullCheckVisitor::do_Intrinsic      (Intrinsic*       x) { nce()->handle_Intrinsic(x);     }
 699 void NullCheckVisitor::do_BlockBegin     (BlockBegin*      x) {}
 700 void NullCheckVisitor::do_Goto           (Goto*            x) {}
 701 void NullCheckVisitor::do_If             (If*              x) {}
 702 void NullCheckVisitor::do_IfInstanceOf   (IfInstanceOf*    x) {}
 703 void NullCheckVisitor::do_TableSwitch    (TableSwitch*     x) {}
 704 void NullCheckVisitor::do_LookupSwitch   (LookupSwitch*    x) {}
 705 void NullCheckVisitor::do_Return         (Return*          x) {}
 706 void NullCheckVisitor::do_Throw          (Throw*           x) { nce()->clear_last_explicit_null_check(); }
 707 void NullCheckVisitor::do_Base           (Base*            x) {}
 708 void NullCheckVisitor::do_OsrEntry       (OsrEntry*        x) {}
 709 void NullCheckVisitor::do_ExceptionObject(ExceptionObject* x) { nce()->handle_ExceptionObject(x); }
 710 void NullCheckVisitor::do_RoundFP        (RoundFP*         x) {}


 845     }
 846   }
 847 }
 848 
 849 
 850 void NullCheckEliminator::iterate(BlockBegin* block) {
 851   work_list()->push(block);
 852   iterate_all();
 853 }
 854 
 855 void NullCheckEliminator::handle_AccessField(AccessField* x) {
 856   if (x->is_static()) {
 857     if (x->as_LoadField() != NULL) {
 858       // If the field is a non-null static final object field (as is
 859       // often the case for sun.misc.Unsafe), put this LoadField into
 860       // the non-null map
 861       ciField* field = x->field();
 862       if (field->is_constant()) {
 863         ciConstant field_val = field->constant_value();
 864         BasicType field_type = field_val.basic_type();
 865         if (field_type == T_OBJECT || field_type == T_ARRAY) {
 866           ciObject* obj_val = field_val.as_object();
 867           if (!obj_val->is_null_object()) {
 868             if (PrintNullCheckElimination) {
 869               tty->print_cr("AccessField %d proven non-null by static final non-null oop check",
 870                             x->id());
 871             }
 872             set_put(x);
 873           }
 874         }
 875       }
 876     }
 877     // Be conservative
 878     clear_last_explicit_null_check();
 879     return;
 880   }
 881 
 882   Value obj = x->obj();
 883   if (set_contains(obj)) {
 884     // Value is non-null => update AccessField
 885     if (last_explicit_null_check_obj() == obj && !x->needs_patching()) {


1020     // Be conservative
1021     clear_last_explicit_null_check();
1022     return;
1023   }
1024 
1025   Value recv = x->receiver();
1026   if (!set_contains(recv)) {
1027     set_put(recv);
1028     if (PrintNullCheckElimination) {
1029       tty->print_cr("Invoke %d of value %d proves value to be non-null", x->id(), recv->id());
1030     }
1031   }
1032   clear_last_explicit_null_check();
1033 }
1034 
1035 
1036 void NullCheckEliminator::handle_NewInstance(NewInstance* x) {
1037   set_put(x);
1038   if (PrintNullCheckElimination) {
1039     tty->print_cr("NewInstance %d is non-null", x->id());







1040   }
1041 }
1042 
1043 
1044 void NullCheckEliminator::handle_NewArray(NewArray* x) {
1045   set_put(x);
1046   if (PrintNullCheckElimination) {
1047     tty->print_cr("NewArray %d is non-null", x->id());
1048   }
1049 }
1050 
1051 
1052 void NullCheckEliminator::handle_ExceptionObject(ExceptionObject* x) {
1053   set_put(x);
1054   if (PrintNullCheckElimination) {
1055     tty->print_cr("ExceptionObject %d is non-null", x->id());
1056   }
1057 }
1058 
1059 




 485 
 486   void do_Phi            (Phi*             x);
 487   void do_Local          (Local*           x);
 488   void do_Constant       (Constant*        x);
 489   void do_LoadField      (LoadField*       x);
 490   void do_StoreField     (StoreField*      x);
 491   void do_ArrayLength    (ArrayLength*     x);
 492   void do_LoadIndexed    (LoadIndexed*     x);
 493   void do_StoreIndexed   (StoreIndexed*    x);
 494   void do_NegateOp       (NegateOp*        x);
 495   void do_ArithmeticOp   (ArithmeticOp*    x);
 496   void do_ShiftOp        (ShiftOp*         x);
 497   void do_LogicOp        (LogicOp*         x);
 498   void do_CompareOp      (CompareOp*       x);
 499   void do_IfOp           (IfOp*            x);
 500   void do_Convert        (Convert*         x);
 501   void do_NullCheck      (NullCheck*       x);
 502   void do_TypeCast       (TypeCast*        x);
 503   void do_Invoke         (Invoke*          x);
 504   void do_NewInstance    (NewInstance*     x);
 505   void do_NewValueTypeInstance(NewValueTypeInstance* x);
 506   void do_NewTypeArray   (NewTypeArray*    x);
 507   void do_NewObjectArray (NewObjectArray*  x);
 508   void do_NewMultiArray  (NewMultiArray*   x);
 509   void do_CheckCast      (CheckCast*       x);
 510   void do_InstanceOf     (InstanceOf*      x);
 511   void do_MonitorEnter   (MonitorEnter*    x);
 512   void do_MonitorExit    (MonitorExit*     x);
 513   void do_Intrinsic      (Intrinsic*       x);
 514   void do_BlockBegin     (BlockBegin*      x);
 515   void do_Goto           (Goto*            x);
 516   void do_If             (If*              x);
 517   void do_IfInstanceOf   (IfInstanceOf*    x);
 518   void do_TableSwitch    (TableSwitch*     x);
 519   void do_LookupSwitch   (LookupSwitch*    x);
 520   void do_Return         (Return*          x);
 521   void do_Throw          (Throw*           x);
 522   void do_Base           (Base*            x);
 523   void do_OsrEntry       (OsrEntry*        x);
 524   void do_ExceptionObject(ExceptionObject* x);
 525   void do_RoundFP        (RoundFP*         x);


 634     _last_explicit_null_check->unpin(Instruction::PinExplicitNullCheck);
 635     _last_explicit_null_check->set_can_trap(false);
 636     return _last_explicit_null_check;
 637   }
 638   void        clear_last_explicit_null_check()               { _last_explicit_null_check = NULL; }
 639 
 640   // Handlers for relevant instructions
 641   // (separated out from NullCheckVisitor for clarity)
 642 
 643   // The basic contract is that these must leave the instruction in
 644   // the desired state; must not assume anything about the state of
 645   // the instruction. We make multiple passes over some basic blocks
 646   // and the last pass is the only one whose result is valid.
 647   void handle_AccessField     (AccessField* x);
 648   void handle_ArrayLength     (ArrayLength* x);
 649   void handle_LoadIndexed     (LoadIndexed* x);
 650   void handle_StoreIndexed    (StoreIndexed* x);
 651   void handle_NullCheck       (NullCheck* x);
 652   void handle_Invoke          (Invoke* x);
 653   void handle_NewInstance     (NewInstance* x);
 654   void handle_NewValueTypeInstance(NewValueTypeInstance* x);
 655   void handle_NewArray        (NewArray* x);
 656   void handle_AccessMonitor   (AccessMonitor* x);
 657   void handle_Intrinsic       (Intrinsic* x);
 658   void handle_ExceptionObject (ExceptionObject* x);
 659   void handle_Phi             (Phi* x);
 660   void handle_ProfileCall     (ProfileCall* x);
 661   void handle_ProfileReturnType (ProfileReturnType* x);
 662 };
 663 
 664 
 665 // NEEDS_CLEANUP
 666 // There may be other instructions which need to clear the last
 667 // explicit null check. Anything across which we can not hoist the
 668 // debug information for a NullCheck instruction must clear it. It
 669 // might be safer to pattern match "NullCheck ; {AccessField,
 670 // ArrayLength, LoadIndexed}" but it is more easily structured this way.
 671 // Should test to see performance hit of clearing it for all handlers
 672 // with empty bodies below. If it is negligible then we should leave
 673 // that in for safety, otherwise should think more about it.
 674 void NullCheckVisitor::do_Phi            (Phi*             x) { nce()->handle_Phi(x);      }
 675 void NullCheckVisitor::do_Local          (Local*           x) {}
 676 void NullCheckVisitor::do_Constant       (Constant*        x) { /* FIXME: handle object constants */ }
 677 void NullCheckVisitor::do_LoadField      (LoadField*       x) { nce()->handle_AccessField(x); }
 678 void NullCheckVisitor::do_StoreField     (StoreField*      x) { nce()->handle_AccessField(x); }
 679 void NullCheckVisitor::do_ArrayLength    (ArrayLength*     x) { nce()->handle_ArrayLength(x); }
 680 void NullCheckVisitor::do_LoadIndexed    (LoadIndexed*     x) { nce()->handle_LoadIndexed(x); }
 681 void NullCheckVisitor::do_StoreIndexed   (StoreIndexed*    x) { nce()->handle_StoreIndexed(x); }
 682 void NullCheckVisitor::do_NegateOp       (NegateOp*        x) {}
 683 void NullCheckVisitor::do_ArithmeticOp   (ArithmeticOp*    x) { if (x->can_trap()) nce()->clear_last_explicit_null_check(); }
 684 void NullCheckVisitor::do_ShiftOp        (ShiftOp*         x) {}
 685 void NullCheckVisitor::do_LogicOp        (LogicOp*         x) {}
 686 void NullCheckVisitor::do_CompareOp      (CompareOp*       x) {}
 687 void NullCheckVisitor::do_IfOp           (IfOp*            x) {}
 688 void NullCheckVisitor::do_Convert        (Convert*         x) {}
 689 void NullCheckVisitor::do_NullCheck      (NullCheck*       x) { nce()->handle_NullCheck(x); }
 690 void NullCheckVisitor::do_TypeCast       (TypeCast*        x) {}
 691 void NullCheckVisitor::do_Invoke         (Invoke*          x) { nce()->handle_Invoke(x); }
 692 void NullCheckVisitor::do_NewInstance    (NewInstance*     x) { nce()->handle_NewInstance(x); }
 693 void NullCheckVisitor::do_NewValueTypeInstance(NewValueTypeInstance*     x) { nce()->handle_NewValueTypeInstance(x); }
 694 void NullCheckVisitor::do_NewTypeArray   (NewTypeArray*    x) { nce()->handle_NewArray(x); }
 695 void NullCheckVisitor::do_NewObjectArray (NewObjectArray*  x) { nce()->handle_NewArray(x); }
 696 void NullCheckVisitor::do_NewMultiArray  (NewMultiArray*   x) { nce()->handle_NewArray(x); }
 697 void NullCheckVisitor::do_CheckCast      (CheckCast*       x) { nce()->clear_last_explicit_null_check(); }
 698 void NullCheckVisitor::do_InstanceOf     (InstanceOf*      x) {}
 699 void NullCheckVisitor::do_MonitorEnter   (MonitorEnter*    x) { nce()->handle_AccessMonitor(x); }
 700 void NullCheckVisitor::do_MonitorExit    (MonitorExit*     x) { nce()->handle_AccessMonitor(x); }
 701 void NullCheckVisitor::do_Intrinsic      (Intrinsic*       x) { nce()->handle_Intrinsic(x);     }
 702 void NullCheckVisitor::do_BlockBegin     (BlockBegin*      x) {}
 703 void NullCheckVisitor::do_Goto           (Goto*            x) {}
 704 void NullCheckVisitor::do_If             (If*              x) {}
 705 void NullCheckVisitor::do_IfInstanceOf   (IfInstanceOf*    x) {}
 706 void NullCheckVisitor::do_TableSwitch    (TableSwitch*     x) {}
 707 void NullCheckVisitor::do_LookupSwitch   (LookupSwitch*    x) {}
 708 void NullCheckVisitor::do_Return         (Return*          x) {}
 709 void NullCheckVisitor::do_Throw          (Throw*           x) { nce()->clear_last_explicit_null_check(); }
 710 void NullCheckVisitor::do_Base           (Base*            x) {}
 711 void NullCheckVisitor::do_OsrEntry       (OsrEntry*        x) {}
 712 void NullCheckVisitor::do_ExceptionObject(ExceptionObject* x) { nce()->handle_ExceptionObject(x); }
 713 void NullCheckVisitor::do_RoundFP        (RoundFP*         x) {}


 848     }
 849   }
 850 }
 851 
 852 
 853 void NullCheckEliminator::iterate(BlockBegin* block) {
 854   work_list()->push(block);
 855   iterate_all();
 856 }
 857 
 858 void NullCheckEliminator::handle_AccessField(AccessField* x) {
 859   if (x->is_static()) {
 860     if (x->as_LoadField() != NULL) {
 861       // If the field is a non-null static final object field (as is
 862       // often the case for sun.misc.Unsafe), put this LoadField into
 863       // the non-null map
 864       ciField* field = x->field();
 865       if (field->is_constant()) {
 866         ciConstant field_val = field->constant_value();
 867         BasicType field_type = field_val.basic_type();
 868         if (field_type == T_OBJECT || field_type == T_ARRAY || field_type == T_VALUETYPE) {
 869           ciObject* obj_val = field_val.as_object();
 870           if (!obj_val->is_null_object()) {
 871             if (PrintNullCheckElimination) {
 872               tty->print_cr("AccessField %d proven non-null by static final non-null oop check",
 873                             x->id());
 874             }
 875             set_put(x);
 876           }
 877         }
 878       }
 879     }
 880     // Be conservative
 881     clear_last_explicit_null_check();
 882     return;
 883   }
 884 
 885   Value obj = x->obj();
 886   if (set_contains(obj)) {
 887     // Value is non-null => update AccessField
 888     if (last_explicit_null_check_obj() == obj && !x->needs_patching()) {


1023     // Be conservative
1024     clear_last_explicit_null_check();
1025     return;
1026   }
1027 
1028   Value recv = x->receiver();
1029   if (!set_contains(recv)) {
1030     set_put(recv);
1031     if (PrintNullCheckElimination) {
1032       tty->print_cr("Invoke %d of value %d proves value to be non-null", x->id(), recv->id());
1033     }
1034   }
1035   clear_last_explicit_null_check();
1036 }
1037 
1038 
1039 void NullCheckEliminator::handle_NewInstance(NewInstance* x) {
1040   set_put(x);
1041   if (PrintNullCheckElimination) {
1042     tty->print_cr("NewInstance %d is non-null", x->id());
1043   }
1044 }
1045 
1046 void NullCheckEliminator::handle_NewValueTypeInstance(NewValueTypeInstance* x) {
1047   set_put(x);
1048   if (PrintNullCheckElimination) {
1049     tty->print_cr("NewValueTypeInstance %d is non-null", x->id());
1050   }
1051 }
1052 
1053 
1054 void NullCheckEliminator::handle_NewArray(NewArray* x) {
1055   set_put(x);
1056   if (PrintNullCheckElimination) {
1057     tty->print_cr("NewArray %d is non-null", x->id());
1058   }
1059 }
1060 
1061 
1062 void NullCheckEliminator::handle_ExceptionObject(ExceptionObject* x) {
1063   set_put(x);
1064   if (PrintNullCheckElimination) {
1065     tty->print_cr("ExceptionObject %d is non-null", x->id());
1066   }
1067 }
1068 
1069 


< prev index next >