< 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) {
382     return null_check_common(value, type, true, NULL, _gvn.type(value)->speculative_always_null());
383   }
384 
385   // Check if value is null and abort if it is
386   Node* must_be_not_null(Node* value, bool do_replace_in_map);

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

821   void merge_memory(Node* new_mem, Node* region, int new_path);
822   void make_slow_call_ex(Node* call, ciInstanceKlass* ex_klass, bool separate_io_proj, bool deoptimize = false);
823 
824   // Helper functions to build synchronizations
825   int next_monitor();
826   Node* insert_mem_bar(int opcode, Node* precedent = NULL);
827   Node* insert_mem_bar_volatile(int opcode, int alias_idx, Node* precedent = NULL);
828   // Optional 'precedent' is appended as an extra edge, to force ordering.
829   FastLockNode* shared_lock(Node* obj);
830   void shared_unlock(Node* box, Node* obj);
831 
832   // helper functions for the fast path/slow path idioms
833   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);
834 
835   // Generate an instance-of idiom.  Used by both the instance-of bytecode
836   // and the reflective instance-of call.
837   Node* gen_instanceof(Node *subobj, Node* superkls, bool safe_for_replace = false);
838 
839   // Generate a check-cast idiom.  Used by both the check-cast bytecode
840   // and the array-store bytecode
841   Node* gen_checkcast( Node *subobj, Node* superkls,
842                        Node* *failure_control = NULL );







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

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

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

901 
902   // Vector API support (implemented in vectorIntrinsics.cpp)
903   Node* box_vector(Node* in, const TypeInstPtr* vbox_type, BasicType elem_bt, int num_elem, bool deoptimize_on_exception = false);
904   Node* unbox_vector(Node* in, const TypeInstPtr* vbox_type, BasicType elem_bt, int num_elem, bool shuffle_to_vector = false);
905   Node* vector_shift_count(Node* cnt, int shift_op, BasicType bt, int num_elem);
906 };
907 
908 // Helper class to support building of control flow branches. Upon
909 // creation the map and sp at bci are cloned and restored upon de-
910 // struction. Typical use:
911 //
912 // { PreserveJVMState pjvms(this);
913 //   // code of new branch
914 // }
915 // // here the JVM state at bci is established
916 
917 class PreserveJVMState: public StackObj {
918  protected:
919   GraphKit*      _kit;
920 #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     return null_check(argument(0));
377   }
378   Node* zero_check_int(Node* value) {
379     assert(value->bottom_type()->basic_type() == T_INT,
380            "wrong type: %s", type2name(value->bottom_type()->basic_type()));
381     return null_check_common(value, T_INT);
382   }
383   Node* zero_check_long(Node* value) {
384     assert(value->bottom_type()->basic_type() == T_LONG,
385            "wrong type: %s", type2name(value->bottom_type()->basic_type()));
386     return null_check_common(value, T_LONG);
387   }
388   // Throw an uncommon trap if a given value is __not__ null.
389   // Return the value cast to null, and be clever about dominating checks.
390   Node* null_assert(Node* value, BasicType type = T_OBJECT) {
391     return null_check_common(value, type, true, NULL, _gvn.type(value)->speculative_always_null());
392   }
393 
394   // Check if value is null and abort if it is
395   Node* must_be_not_null(Node* value, bool do_replace_in_map);

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

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

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