< prev index next >

src/hotspot/share/opto/graphKit.hpp

Print this page

 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 #ifndef SHARE_OPTO_GRAPHKIT_HPP
 26 #define SHARE_OPTO_GRAPHKIT_HPP
 27 
 28 #include "ci/ciEnv.hpp"
 29 #include "ci/ciMethodData.hpp"
 30 #include "gc/shared/c2/barrierSetC2.hpp"
 31 #include "opto/addnode.hpp"
 32 #include "opto/callnode.hpp"
 33 #include "opto/cfgnode.hpp"
 34 #include "opto/compile.hpp"
 35 #include "opto/divnode.hpp"

 36 #include "opto/mulnode.hpp"
 37 #include "opto/phaseX.hpp"
 38 #include "opto/subnode.hpp"
 39 #include "opto/type.hpp"
 40 #include "runtime/deoptimization.hpp"
 41 
 42 class BarrierSetC2;
 43 class FastLockNode;
 44 class FastUnlockNode;
 45 class IdealKit;
 46 class LibraryCallKit;
 47 class Parse;
 48 class RootNode;
 49 
 50 //-----------------------------------------------------------------------------
 51 //----------------------------GraphKit-----------------------------------------
 52 // Toolkit for building the common sorts of subgraphs.
 53 // Does not know about bytecode parsing or type-flow results.
 54 // It is able to create graphs implementing the semantics of most
 55 // or all bytecodes, so that it can expand intrinsics and calls.
 56 // It may depend on JVMState structure, but it must not depend
 57 // on specific bytecode streams.
 58 class GraphKit : public Phase {
 59   friend class PreserveJVMState;
 60 
 61  protected:
 62   ciEnv*            _env;       // Compilation environment
 63   PhaseGVN         &_gvn;       // Some optimizations while parsing
 64   SafePointNode*    _map;       // Parser map from JVM to Nodes
 65   SafePointNode*    _exceptions;// Parser map(s) for exception state(s)
 66   int               _bci;       // JVM Bytecode Pointer
 67   ciMethod*         _method;    // JVM Current Method
 68   BarrierSetC2*     _barrier_set;



 69 
 70  private:
 71   int               _sp;        // JVM Expression Stack Pointer; don't modify directly!
 72 
 73  private:
 74   SafePointNode*     map_not_null() const {
 75     assert(_map != NULL, "must call stopped() to test for reset compiler map");
 76     return _map;
 77   }
 78 
 79  public:
 80   GraphKit();                   // empty constructor
 81   GraphKit(JVMState* jvms);     // the JVM state on which to operate
 82 
 83 #ifdef ASSERT
 84   ~GraphKit() {
 85     assert(!has_exceptions(), "user must call transfer_exceptions_into_jvms");





 86   }
 87 #endif
 88 
 89   virtual Parse*          is_Parse()          const { return NULL; }
 90   virtual LibraryCallKit* is_LibraryCallKit() const { return NULL; }
 91 
 92   ciEnv*        env()               const { return _env; }
 93   PhaseGVN&     gvn()               const { return _gvn; }
 94   void*         barrier_set_state() const { return C->barrier_set_state(); }
 95 
 96   void record_for_igvn(Node* n) const { C->record_for_igvn(n); }  // delegate to Compile
 97 
 98   // Handy well-known nodes:
 99   Node*         null()          const { return zerocon(T_OBJECT); }
100   Node*         top()           const { return C->top(); }
101   RootNode*     root()          const { return C->root(); }
102 
103   // Create or find a constant node
104   Node* intcon(jint con)        const { return _gvn.intcon(con); }
105   Node* longcon(jlong con)      const { return _gvn.longcon(con); }
106   Node* integercon(jlong con, BasicType bt)   const {
107     if (bt == T_INT) {
108       return intcon(checked_cast<jint>(con));
109     }
110     assert(bt == T_LONG, "basic type not an int or long");
111     return longcon(con);
112   }
113   Node* makecon(const Type *t)  const { return _gvn.makecon(t); }
114   Node* zerocon(BasicType bt)   const { return _gvn.zerocon(bt); }
115   // (See also macro MakeConX in type.hpp, which uses intcon or longcon.)
116 

341   Node* ConvL2I(Node* offset);
342   // Find out the klass of an object.
343   Node* load_object_klass(Node* object);
344   // Find out the length of an array.
345   Node* load_array_length(Node* array);
346   // Cast array allocation's length as narrow as possible.
347   // If replace_length_in_map is true, replace length with CastIINode in map.
348   // This method is invoked after creating/moving ArrayAllocationNode or in load_array_length
349   Node* array_ideal_length(AllocateArrayNode* alloc,
350                            const TypeOopPtr* oop_type,
351                            bool replace_length_in_map);
352 
353 
354   // Helper function to do a NULL pointer check or ZERO check based on type.
355   // Throw an exception if a given value is null.
356   // Return the value cast to not-null.
357   // Be clever about equivalent dominating null checks.
358   Node* null_check_common(Node* value, BasicType type,
359                           bool assert_null = false,
360                           Node* *null_control = NULL,
361                           bool speculative = false);

362   Node* null_check(Node* value, BasicType type = T_OBJECT) {
363     return null_check_common(value, type, false, NULL, !_gvn.type(value)->speculative_maybe_null());
364   }
365   Node* null_check_receiver() {
366     assert(argument(0)->bottom_type()->isa_ptr(), "must be");
367     return null_check(argument(0));
368   }
369   Node* zero_check_int(Node* value) {
370     assert(value->bottom_type()->basic_type() == T_INT,
371            "wrong type: %s", type2name(value->bottom_type()->basic_type()));
372     return null_check_common(value, T_INT);
373   }
374   Node* zero_check_long(Node* value) {
375     assert(value->bottom_type()->basic_type() == T_LONG,
376            "wrong type: %s", type2name(value->bottom_type()->basic_type()));
377     return null_check_common(value, T_LONG);
378   }
379   // Throw an uncommon trap if a given value is __not__ null.
380   // Return the value cast to null, and be clever about dominating checks.
381   Node* null_assert(Node* value, BasicType type = T_OBJECT) {

581                            unaligned, mismatched, unsafe);
582   }
583   // This is the base version which is given alias index
584   // Return the new StoreXNode
585   Node* store_to_memory(Node* ctl, Node* adr, Node* val, BasicType bt,
586                         int adr_idx,
587                         MemNode::MemOrd,
588                         bool require_atomic_access = false,
589                         bool unaligned = false,
590                         bool mismatched = false,
591                         bool unsafe = false);
592 
593   // Perform decorated accesses
594 
595   Node* access_store_at(Node* obj,   // containing obj
596                         Node* adr,   // actual adress to store val at
597                         const TypePtr* adr_type,
598                         Node* val,
599                         const Type* val_type,
600                         BasicType bt,
601                         DecoratorSet decorators);

602 
603   Node* access_load_at(Node* obj,   // containing obj
604                        Node* adr,   // actual adress to load val at
605                        const TypePtr* adr_type,
606                        const Type* val_type,
607                        BasicType bt,
608                        DecoratorSet decorators);

609 
610   Node* access_load(Node* adr,   // actual adress to load val at
611                     const Type* val_type,
612                     BasicType bt,
613                     DecoratorSet decorators);
614 
615   Node* access_atomic_cmpxchg_val_at(Node* obj,
616                                      Node* adr,
617                                      const TypePtr* adr_type,
618                                      int alias_idx,
619                                      Node* expected_val,
620                                      Node* new_val,
621                                      const Type* value_type,
622                                      BasicType bt,
623                                      DecoratorSet decorators);
624 
625   Node* access_atomic_cmpxchg_bool_at(Node* obj,
626                                       Node* adr,
627                                       const TypePtr* adr_type,
628                                       int alias_idx,

666   void make_dtrace_method_entry_exit(ciMethod* method, bool is_entry);
667   void make_dtrace_method_entry(ciMethod* method) {
668     make_dtrace_method_entry_exit(method, true);
669   }
670   void make_dtrace_method_exit(ciMethod* method) {
671     make_dtrace_method_entry_exit(method, false);
672   }
673 
674   //--------------- stub generation -------------------
675  public:
676   void gen_stub(address C_function,
677                 const char *name,
678                 int is_fancy_jump,
679                 bool pass_tls,
680                 bool return_pc);
681 
682   //---------- help for generating calls --------------
683 
684   // Do a null check on the receiver as it would happen before the call to
685   // callee (with all arguments still on the stack).
686   Node* null_check_receiver_before_call(ciMethod* callee) {
687     assert(!callee->is_static(), "must be a virtual method");



688     // Callsite signature can be different from actual method being called (i.e _linkTo* sites).
689     // Use callsite signature always.
690     ciMethod* declared_method = method()->get_method_at_bci(bci());
691     const int nargs = declared_method->arg_size();
692     inc_sp(nargs);
693     Node* n = null_check_receiver();


694     dec_sp(nargs);














695     return n;
696   }
697 
698   // Fill in argument edges for the call from argument(0), argument(1), ...
699   // (The next step is to call set_edges_for_java_call.)
700   void  set_arguments_for_java_call(CallJavaNode* call);
701 
702   // Fill in non-argument edges for the call.
703   // Transform the call, and update the basics: control, i_o, memory.
704   // (The next step is usually to call set_results_for_java_call.)
705   void set_edges_for_java_call(CallJavaNode* call,
706                                bool must_throw = false, bool separate_io_proj = false);
707 
708   // Finish up a java call that was started by set_edges_for_java_call.
709   // Call add_exception on any throw arising from the call.
710   // Return the call result (transformed).
711   Node* set_results_for_java_call(CallJavaNode* call, bool separate_io_proj = false, bool deoptimize = false);
712 
713   // Similar to set_edges_for_java_call, but simplified for runtime calls.
714   void  set_predefined_output_for_runtime_call(Node* call) {
715     set_predefined_output_for_runtime_call(call, NULL, NULL);
716   }
717   void  set_predefined_output_for_runtime_call(Node* call,
718                                                Node* keep_mem,
719                                                const TypePtr* hook_mem);
720   Node* set_predefined_input_for_runtime_call(SafePointNode* call, Node* narrow_mem = NULL);

825   void merge_memory(Node* new_mem, Node* region, int new_path);
826   void make_slow_call_ex(Node* call, ciInstanceKlass* ex_klass, bool separate_io_proj, bool deoptimize = false);
827 
828   // Helper functions to build synchronizations
829   int next_monitor();
830   Node* insert_mem_bar(int opcode, Node* precedent = NULL);
831   Node* insert_mem_bar_volatile(int opcode, int alias_idx, Node* precedent = NULL);
832   // Optional 'precedent' is appended as an extra edge, to force ordering.
833   FastLockNode* shared_lock(Node* obj);
834   void shared_unlock(Node* box, Node* obj);
835 
836   // helper functions for the fast path/slow path idioms
837   Node* fast_and_slow(Node* in, const Type *result_type, Node* null_result, IfNode* fast_test, Node* fast_result, address slow_call, const TypeFunc *slow_call_type, Node* slow_arg, Klass* ex_klass, Node* slow_result);
838 
839   // Generate an instance-of idiom.  Used by both the instance-of bytecode
840   // and the reflective instance-of call.
841   Node* gen_instanceof(Node *subobj, Node* superkls, bool safe_for_replace = false);
842 
843   // Generate a check-cast idiom.  Used by both the check-cast bytecode
844   // and the array-store bytecode
845   Node* gen_checkcast( Node *subobj, Node* superkls,
846                        Node* *failure_control = NULL );







847 
848   Node* gen_subtype_check(Node* obj, Node* superklass);
849 
850   // Exact type check used for predicted calls and casts.
851   // Rewrites (*casted_receiver) to be casted to the stronger type.
852   // (Caller is responsible for doing replace_in_map.)
853   Node* type_check_receiver(Node* receiver, ciKlass* klass, float prob,
854                             Node* *casted_receiver);

855 
856   // Inexact type check used for predicted calls.
857   Node* subtype_check_receiver(Node* receiver, ciKlass* klass,
858                                Node** casted_receiver);
859 
860   // implementation of object creation
861   Node* set_output_for_allocation(AllocateNode* alloc,
862                                   const TypeOopPtr* oop_type,
863                                   bool deoptimize_on_exception=false);
864   Node* get_layout_helper(Node* klass_node, jint& constant_value);
865   Node* new_instance(Node* klass_node,
866                      Node* slow_test = NULL,
867                      Node* *return_size_val = NULL,
868                      bool deoptimize_on_exception = false);

869   Node* new_array(Node* klass_node, Node* count_val, int nargs,
870                   Node* *return_size_val = NULL,
871                   bool deoptimize_on_exception = false);
872 
873   // java.lang.String helpers
874   Node* load_String_length(Node* str, bool set_ctrl);
875   Node* load_String_value(Node* str, bool set_ctrl);
876   Node* load_String_coder(Node* str, bool set_ctrl);
877   void store_String_value(Node* str, Node* value);
878   void store_String_coder(Node* str, Node* value);
879   Node* capture_memory(const TypePtr* src_type, const TypePtr* dst_type);
880   Node* compress_string(Node* src, const TypeAryPtr* src_type, Node* dst, Node* count);
881   void inflate_string(Node* src, Node* dst, const TypeAryPtr* dst_type, Node* count);
882   void inflate_string_slow(Node* src, Node* dst, Node* start, Node* count);
883 
884   // Handy for making control flow
885   IfNode* create_and_map_if(Node* ctrl, Node* tst, float prob, float cnt) {
886     IfNode* iff = new IfNode(ctrl, tst, prob, cnt);// New IfNode's
887     _gvn.set_type(iff, iff->Value(&_gvn)); // Value may be known at parse-time
888     // Place 'if' on worklist if it will be in graph
889     if (!tst->is_Con())  record_for_igvn(iff);     // Range-check and Null-check removal is later
890     return iff;
891   }
892 
893   IfNode* create_and_xform_if(Node* ctrl, Node* tst, float prob, float cnt) {
894     IfNode* iff = new IfNode(ctrl, tst, prob, cnt);// New IfNode's
895     _gvn.transform(iff);                           // Value may be known at parse-time
896     // Place 'if' on worklist if it will be in graph
897     if (!tst->is_Con())  record_for_igvn(iff);     // Range-check and Null-check removal is later
898     return iff;
899   }
900 
901   void add_empty_predicates(int nargs = 0);
902   void add_empty_predicate_impl(Deoptimization::DeoptReason reason, int nargs);
903 
904   Node* make_constant_from_field(ciField* field, Node* obj);

905 
906   // Vector API support (implemented in vectorIntrinsics.cpp)
907   Node* box_vector(Node* in, const TypeInstPtr* vbox_type, BasicType elem_bt, int num_elem, bool deoptimize_on_exception = false);
908   Node* unbox_vector(Node* in, const TypeInstPtr* vbox_type, BasicType elem_bt, int num_elem, bool shuffle_to_vector = false);
909   Node* vector_shift_count(Node* cnt, int shift_op, BasicType bt, int num_elem);
910 };
911 
912 // Helper class to support building of control flow branches. Upon
913 // creation the map and sp at bci are cloned and restored upon de-
914 // struction. Typical use:
915 //
916 // { PreserveJVMState pjvms(this);
917 //   // code of new branch
918 // }
919 // // here the JVM state at bci is established
920 
921 class PreserveJVMState: public StackObj {
922  protected:
923   GraphKit*      _kit;
924 #ifdef ASSERT

 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 #ifndef SHARE_OPTO_GRAPHKIT_HPP
 26 #define SHARE_OPTO_GRAPHKIT_HPP
 27 
 28 #include "ci/ciEnv.hpp"
 29 #include "ci/ciMethodData.hpp"
 30 #include "gc/shared/c2/barrierSetC2.hpp"
 31 #include "opto/addnode.hpp"
 32 #include "opto/callnode.hpp"
 33 #include "opto/cfgnode.hpp"
 34 #include "opto/compile.hpp"
 35 #include "opto/divnode.hpp"
 36 #include "opto/inlinetypenode.hpp"
 37 #include "opto/mulnode.hpp"
 38 #include "opto/phaseX.hpp"
 39 #include "opto/subnode.hpp"
 40 #include "opto/type.hpp"
 41 #include "runtime/deoptimization.hpp"
 42 
 43 class BarrierSetC2;
 44 class FastLockNode;
 45 class FastUnlockNode;
 46 class IdealKit;
 47 class LibraryCallKit;
 48 class Parse;
 49 class RootNode;
 50 
 51 //-----------------------------------------------------------------------------
 52 //----------------------------GraphKit-----------------------------------------
 53 // Toolkit for building the common sorts of subgraphs.
 54 // Does not know about bytecode parsing or type-flow results.
 55 // It is able to create graphs implementing the semantics of most
 56 // or all bytecodes, so that it can expand intrinsics and calls.
 57 // It may depend on JVMState structure, but it must not depend
 58 // on specific bytecode streams.
 59 class GraphKit : public Phase {
 60   friend class PreserveJVMState;
 61 
 62  protected:
 63   ciEnv*            _env;       // Compilation environment
 64   PhaseGVN         &_gvn;       // Some optimizations while parsing
 65   SafePointNode*    _map;       // Parser map from JVM to Nodes
 66   SafePointNode*    _exceptions;// Parser map(s) for exception state(s)
 67   int               _bci;       // JVM Bytecode Pointer
 68   ciMethod*         _method;    // JVM Current Method
 69   BarrierSetC2*     _barrier_set;
 70 #ifdef ASSERT
 71   uint              _worklist_size;
 72 #endif
 73 
 74  private:
 75   int               _sp;        // JVM Expression Stack Pointer; don't modify directly!
 76 
 77  private:
 78   SafePointNode*     map_not_null() const {
 79     assert(_map != NULL, "must call stopped() to test for reset compiler map");
 80     return _map;
 81   }
 82 
 83  public:
 84   GraphKit();                   // empty constructor
 85   GraphKit(JVMState* jvms, PhaseGVN* gvn = NULL);     // the JVM state on which to operate
 86 
 87 #ifdef ASSERT
 88   ~GraphKit() {
 89     assert(!has_exceptions(), "user must call transfer_exceptions_into_jvms");
 90     // During incremental inlining, the Node_Array of the C->for_igvn() worklist and the IGVN
 91     // worklist are shared but the _in_worklist VectorSet is not. To avoid inconsistencies,
 92     // we should not add nodes to the _for_igvn worklist when using IGVN for the GraphKit.
 93     assert((_gvn.is_IterGVN() == NULL) || (_gvn.C->for_igvn()->size() == _worklist_size),
 94            "GraphKit should not modify _for_igvn worklist after parsing");
 95   }
 96 #endif
 97 
 98   virtual Parse*          is_Parse()          const { return NULL; }
 99   virtual LibraryCallKit* is_LibraryCallKit() const { return NULL; }
100 
101   ciEnv*        env()               const { return _env; }
102   PhaseGVN&     gvn()               const { return _gvn; }
103   void*         barrier_set_state() const { return C->barrier_set_state(); }
104 
105   void record_for_igvn(Node* n) const { _gvn.record_for_igvn(n); }
106 
107   // Handy well-known nodes:
108   Node*         null()          const { return zerocon(T_OBJECT); }
109   Node*         top()           const { return C->top(); }
110   RootNode*     root()          const { return C->root(); }
111 
112   // Create or find a constant node
113   Node* intcon(jint con)        const { return _gvn.intcon(con); }
114   Node* longcon(jlong con)      const { return _gvn.longcon(con); }
115   Node* integercon(jlong con, BasicType bt)   const {
116     if (bt == T_INT) {
117       return intcon(checked_cast<jint>(con));
118     }
119     assert(bt == T_LONG, "basic type not an int or long");
120     return longcon(con);
121   }
122   Node* makecon(const Type *t)  const { return _gvn.makecon(t); }
123   Node* zerocon(BasicType bt)   const { return _gvn.zerocon(bt); }
124   // (See also macro MakeConX in type.hpp, which uses intcon or longcon.)
125 

350   Node* ConvL2I(Node* offset);
351   // Find out the klass of an object.
352   Node* load_object_klass(Node* object);
353   // Find out the length of an array.
354   Node* load_array_length(Node* array);
355   // Cast array allocation's length as narrow as possible.
356   // If replace_length_in_map is true, replace length with CastIINode in map.
357   // This method is invoked after creating/moving ArrayAllocationNode or in load_array_length
358   Node* array_ideal_length(AllocateArrayNode* alloc,
359                            const TypeOopPtr* oop_type,
360                            bool replace_length_in_map);
361 
362 
363   // Helper function to do a NULL pointer check or ZERO check based on type.
364   // Throw an exception if a given value is null.
365   // Return the value cast to not-null.
366   // Be clever about equivalent dominating null checks.
367   Node* null_check_common(Node* value, BasicType type,
368                           bool assert_null = false,
369                           Node* *null_control = NULL,
370                           bool speculative = false,
371                           bool is_init_check = false);
372   Node* null_check(Node* value, BasicType type = T_OBJECT) {
373     return null_check_common(value, type, false, NULL, !_gvn.type(value)->speculative_maybe_null());
374   }
375   Node* null_check_receiver() {
376     assert(argument(0)->bottom_type()->isa_ptr(), "must be");
377     return null_check(argument(0));
378   }
379   Node* zero_check_int(Node* value) {
380     assert(value->bottom_type()->basic_type() == T_INT,
381            "wrong type: %s", type2name(value->bottom_type()->basic_type()));
382     return null_check_common(value, T_INT);
383   }
384   Node* zero_check_long(Node* value) {
385     assert(value->bottom_type()->basic_type() == T_LONG,
386            "wrong type: %s", type2name(value->bottom_type()->basic_type()));
387     return null_check_common(value, T_LONG);
388   }
389   // Throw an uncommon trap if a given value is __not__ null.
390   // Return the value cast to null, and be clever about dominating checks.
391   Node* null_assert(Node* value, BasicType type = T_OBJECT) {

591                            unaligned, mismatched, unsafe);
592   }
593   // This is the base version which is given alias index
594   // Return the new StoreXNode
595   Node* store_to_memory(Node* ctl, Node* adr, Node* val, BasicType bt,
596                         int adr_idx,
597                         MemNode::MemOrd,
598                         bool require_atomic_access = false,
599                         bool unaligned = false,
600                         bool mismatched = false,
601                         bool unsafe = false);
602 
603   // Perform decorated accesses
604 
605   Node* access_store_at(Node* obj,   // containing obj
606                         Node* adr,   // actual adress to store val at
607                         const TypePtr* adr_type,
608                         Node* val,
609                         const Type* val_type,
610                         BasicType bt,
611                         DecoratorSet decorators,
612                         bool safe_for_replace = true);
613 
614   Node* access_load_at(Node* obj,   // containing obj
615                        Node* adr,   // actual adress to load val at
616                        const TypePtr* adr_type,
617                        const Type* val_type,
618                        BasicType bt,
619                        DecoratorSet decorators,
620                        Node* ctl = NULL);
621 
622   Node* access_load(Node* adr,   // actual adress to load val at
623                     const Type* val_type,
624                     BasicType bt,
625                     DecoratorSet decorators);
626 
627   Node* access_atomic_cmpxchg_val_at(Node* obj,
628                                      Node* adr,
629                                      const TypePtr* adr_type,
630                                      int alias_idx,
631                                      Node* expected_val,
632                                      Node* new_val,
633                                      const Type* value_type,
634                                      BasicType bt,
635                                      DecoratorSet decorators);
636 
637   Node* access_atomic_cmpxchg_bool_at(Node* obj,
638                                       Node* adr,
639                                       const TypePtr* adr_type,
640                                       int alias_idx,

678   void make_dtrace_method_entry_exit(ciMethod* method, bool is_entry);
679   void make_dtrace_method_entry(ciMethod* method) {
680     make_dtrace_method_entry_exit(method, true);
681   }
682   void make_dtrace_method_exit(ciMethod* method) {
683     make_dtrace_method_entry_exit(method, false);
684   }
685 
686   //--------------- stub generation -------------------
687  public:
688   void gen_stub(address C_function,
689                 const char *name,
690                 int is_fancy_jump,
691                 bool pass_tls,
692                 bool return_pc);
693 
694   //---------- help for generating calls --------------
695 
696   // Do a null check on the receiver as it would happen before the call to
697   // callee (with all arguments still on the stack).
698   Node* null_check_receiver_before_call(ciMethod* callee, bool replace_value = true) {
699     assert(!callee->is_static(), "must be a virtual method");
700     if (argument(0)->is_InlineType()) {
701       return argument(0);
702     }
703     // Callsite signature can be different from actual method being called (i.e _linkTo* sites).
704     // Use callsite signature always.
705     ciMethod* declared_method = method()->get_method_at_bci(bci());
706     const int nargs = declared_method->arg_size();
707     inc_sp(nargs);
708     Node* n = null_check_receiver();
709     // TODO Remove this code once InlineTypeNodes are replaced by InlineTypePtrNodes
710     set_argument(0, n);
711     dec_sp(nargs);
712     // Scalarize inline type receiver
713     const Type* recv_type = gvn().type(n);
714     if (recv_type->is_inlinetypeptr()) {
715       assert(!recv_type->maybe_null(), "should never be null");
716       Node* vt = InlineTypeNode::make_from_oop(this, n, recv_type->inline_klass());
717       set_argument(0, vt);
718       if (replace_value && is_Parse()) {
719         // Only replace in map if we are not incrementally inlining because we
720         // share a map with the caller which might expect the inline type as oop.
721         assert(!Compile::current()->inlining_incrementally(), "sanity");
722         replace_in_map(n, vt);
723       }
724       n = vt;
725     }
726     return n;
727   }
728 
729   // Fill in argument edges for the call from argument(0), argument(1), ...
730   // (The next step is to call set_edges_for_java_call.)
731   void  set_arguments_for_java_call(CallJavaNode* call, bool is_late_inline = false);
732 
733   // Fill in non-argument edges for the call.
734   // Transform the call, and update the basics: control, i_o, memory.
735   // (The next step is usually to call set_results_for_java_call.)
736   void set_edges_for_java_call(CallJavaNode* call,
737                                bool must_throw = false, bool separate_io_proj = false);
738 
739   // Finish up a java call that was started by set_edges_for_java_call.
740   // Call add_exception on any throw arising from the call.
741   // Return the call result (transformed).
742   Node* set_results_for_java_call(CallJavaNode* call, bool separate_io_proj = false, bool deoptimize = false);
743 
744   // Similar to set_edges_for_java_call, but simplified for runtime calls.
745   void  set_predefined_output_for_runtime_call(Node* call) {
746     set_predefined_output_for_runtime_call(call, NULL, NULL);
747   }
748   void  set_predefined_output_for_runtime_call(Node* call,
749                                                Node* keep_mem,
750                                                const TypePtr* hook_mem);
751   Node* set_predefined_input_for_runtime_call(SafePointNode* call, Node* narrow_mem = NULL);

856   void merge_memory(Node* new_mem, Node* region, int new_path);
857   void make_slow_call_ex(Node* call, ciInstanceKlass* ex_klass, bool separate_io_proj, bool deoptimize = false);
858 
859   // Helper functions to build synchronizations
860   int next_monitor();
861   Node* insert_mem_bar(int opcode, Node* precedent = NULL);
862   Node* insert_mem_bar_volatile(int opcode, int alias_idx, Node* precedent = NULL);
863   // Optional 'precedent' is appended as an extra edge, to force ordering.
864   FastLockNode* shared_lock(Node* obj);
865   void shared_unlock(Node* box, Node* obj);
866 
867   // helper functions for the fast path/slow path idioms
868   Node* fast_and_slow(Node* in, const Type *result_type, Node* null_result, IfNode* fast_test, Node* fast_result, address slow_call, const TypeFunc *slow_call_type, Node* slow_arg, Klass* ex_klass, Node* slow_result);
869 
870   // Generate an instance-of idiom.  Used by both the instance-of bytecode
871   // and the reflective instance-of call.
872   Node* gen_instanceof(Node *subobj, Node* superkls, bool safe_for_replace = false);
873 
874   // Generate a check-cast idiom.  Used by both the check-cast bytecode
875   // and the array-store bytecode
876   Node* gen_checkcast(Node *subobj, Node* superkls, Node* *failure_control = NULL, bool null_free = false);
877 
878   // Inline types
879   Node* inline_type_test(Node* obj, bool is_inline = true);
880   Node* is_val_mirror(Node* mirror);
881   Node* array_lh_test(Node* kls, jint mask, jint val, bool eq = true);
882   Node* flat_array_test(Node* ary, bool flat = true);
883   Node* null_free_array_test(Node* klass, bool null_free = true);
884   Node* inline_array_null_guard(Node* ary, Node* val, int nargs, bool safe_for_replace = false);
885 
886   Node* gen_subtype_check(Node* obj, Node* superklass);
887 
888   // Exact type check used for predicted calls and casts.
889   // Rewrites (*casted_receiver) to be casted to the stronger type.
890   // (Caller is responsible for doing replace_in_map.)
891   Node* type_check_receiver(Node* receiver, ciKlass* klass, float prob,
892                             Node* *casted_receiver);
893   Node* type_check(Node* recv_klass, const TypeKlassPtr* tklass, float prob);
894 
895   // Inexact type check used for predicted calls.
896   Node* subtype_check_receiver(Node* receiver, ciKlass* klass,
897                                Node** casted_receiver);
898 
899   // implementation of object creation
900   Node* set_output_for_allocation(AllocateNode* alloc,
901                                   const TypeOopPtr* oop_type,
902                                   bool deoptimize_on_exception=false);
903   Node* get_layout_helper(Node* klass_node, jint& constant_value);
904   Node* new_instance(Node* klass_node,
905                      Node* slow_test = NULL,
906                      Node* *return_size_val = NULL,
907                      bool deoptimize_on_exception = false,
908                      InlineTypeBaseNode* inline_type_node = NULL);
909   Node* new_array(Node* klass_node, Node* count_val, int nargs,
910                   Node* *return_size_val = NULL,
911                   bool deoptimize_on_exception = false);
912 
913   // java.lang.String helpers
914   Node* load_String_length(Node* str, bool set_ctrl);
915   Node* load_String_value(Node* str, bool set_ctrl);
916   Node* load_String_coder(Node* str, bool set_ctrl);
917   void store_String_value(Node* str, Node* value);
918   void store_String_coder(Node* str, Node* value);
919   Node* capture_memory(const TypePtr* src_type, const TypePtr* dst_type);
920   Node* compress_string(Node* src, const TypeAryPtr* src_type, Node* dst, Node* count);
921   void inflate_string(Node* src, Node* dst, const TypeAryPtr* dst_type, Node* count);
922   void inflate_string_slow(Node* src, Node* dst, Node* start, Node* count);
923 
924   // Handy for making control flow
925   IfNode* create_and_map_if(Node* ctrl, Node* tst, float prob, float cnt) {
926     IfNode* iff = new IfNode(ctrl, tst, prob, cnt);// New IfNode's
927     _gvn.set_type(iff, iff->Value(&_gvn)); // Value may be known at parse-time
928     // Place 'if' on worklist if it will be in graph
929     if (!tst->is_Con())  record_for_igvn(iff);     // Range-check and Null-check removal is later
930     return iff;
931   }
932 
933   IfNode* create_and_xform_if(Node* ctrl, Node* tst, float prob, float cnt) {
934     IfNode* iff = new IfNode(ctrl, tst, prob, cnt);// New IfNode's
935     _gvn.transform(iff);                           // Value may be known at parse-time
936     // Place 'if' on worklist if it will be in graph
937     if (!tst->is_Con())  record_for_igvn(iff);     // Range-check and Null-check removal is later
938     return iff;
939   }
940 
941   void add_empty_predicates(int nargs = 0);
942   void add_empty_predicate_impl(Deoptimization::DeoptReason reason, int nargs);
943 
944   Node* make_constant_from_field(ciField* field, Node* obj);
945   Node* load_mirror_from_klass(Node* klass);
946 
947   // Vector API support (implemented in vectorIntrinsics.cpp)
948   Node* box_vector(Node* in, const TypeInstPtr* vbox_type, BasicType elem_bt, int num_elem, bool deoptimize_on_exception = false);
949   Node* unbox_vector(Node* in, const TypeInstPtr* vbox_type, BasicType elem_bt, int num_elem, bool shuffle_to_vector = false);
950   Node* vector_shift_count(Node* cnt, int shift_op, BasicType bt, int num_elem);
951 };
952 
953 // Helper class to support building of control flow branches. Upon
954 // creation the map and sp at bci are cloned and restored upon de-
955 // struction. Typical use:
956 //
957 // { PreserveJVMState pjvms(this);
958 //   // code of new branch
959 // }
960 // // here the JVM state at bci is established
961 
962 class PreserveJVMState: public StackObj {
963  protected:
964   GraphKit*      _kit;
965 #ifdef ASSERT
< prev index next >