< prev index next >

src/hotspot/share/opto/graphKit.hpp

Print this page

  1 /*
  2  * Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 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 != nullptr, "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(failing_internal() || !has_exceptions(),
 86            "unless compilation failed, user must call transfer_exceptions_into_jvms");
 87   }
 88 #endif
 89 
 90   virtual Parse*          is_Parse()          const { return nullptr; }
 91   virtual LibraryCallKit* is_LibraryCallKit() const { return nullptr; }
 92 
 93   ciEnv*        env()               const { return _env; }
 94   PhaseGVN&     gvn()               const { return _gvn; }
 95   void*         barrier_set_state() const { return C->barrier_set_state(); }
 96 
 97   void record_for_igvn(Node* n) const { C->record_for_igvn(n); }  // delegate to Compile
 98   void remove_for_igvn(Node* n) const { C->remove_for_igvn(n); }
 99 
100   // Handy well-known nodes:
101   Node*         null()          const { return zerocon(T_OBJECT); }
102   Node*         top()           const { return C->top(); }
103   RootNode*     root()          const { return C->root(); }
104 
105   // Create or find a constant node
106   Node* intcon(jint con)        const { return _gvn.intcon(con); }
107   Node* longcon(jlong con)      const { return _gvn.longcon(con); }
108   Node* integercon(jlong con, BasicType bt)   const {
109     if (bt == T_INT) {
110       return intcon(checked_cast<jint>(con));
111     }
112     assert(bt == T_LONG, "basic type not an int or long");
113     return longcon(con);
114   }
115   Node* makecon(const Type *t)  const { return _gvn.makecon(t); }
116   Node* zerocon(BasicType bt)   const { return _gvn.zerocon(bt); }
117   // (See also macro MakeConX in type.hpp, which uses intcon or longcon.)

355   Node* ConvL2I(Node* offset);
356   // Find out the klass of an object.
357   Node* load_object_klass(Node* object);
358   // Find out the length of an array.
359   Node* load_array_length(Node* array);
360   // Cast array allocation's length as narrow as possible.
361   // If replace_length_in_map is true, replace length with CastIINode in map.
362   // This method is invoked after creating/moving ArrayAllocationNode or in load_array_length
363   Node* array_ideal_length(AllocateArrayNode* alloc,
364                            const TypeOopPtr* oop_type,
365                            bool replace_length_in_map);
366 
367 
368   // Helper function to do a null pointer check or ZERO check based on type.
369   // Throw an exception if a given value is null.
370   // Return the value cast to not-null.
371   // Be clever about equivalent dominating null checks.
372   Node* null_check_common(Node* value, BasicType type,
373                           bool assert_null = false,
374                           Node* *null_control = nullptr,
375                           bool speculative = false);

376   Node* null_check(Node* value, BasicType type = T_OBJECT) {
377     return null_check_common(value, type, false, nullptr, !_gvn.type(value)->speculative_maybe_null());
378   }
379   Node* null_check_receiver() {
380     assert(argument(0)->bottom_type()->isa_ptr(), "must be");
381     return null_check(argument(0));
382   }
383   Node* zero_check_int(Node* value) {
384     assert(value->bottom_type()->basic_type() == T_INT,
385            "wrong type: %s", type2name(value->bottom_type()->basic_type()));
386     return null_check_common(value, T_INT);
387   }
388   Node* zero_check_long(Node* value) {
389     assert(value->bottom_type()->basic_type() == T_LONG,
390            "wrong type: %s", type2name(value->bottom_type()->basic_type()));
391     return null_check_common(value, T_LONG);
392   }
393   // Throw an uncommon trap if a given value is __not__ null.
394   // Return the value cast to null, and be clever about dominating checks.
395   Node* null_assert(Node* value, BasicType type = T_OBJECT) {
396     return null_check_common(value, type, true, nullptr, _gvn.type(value)->speculative_always_null());
397   }
398 
399   // Check if value is null and abort if it is
400   Node* must_be_not_null(Node* value, bool do_replace_in_map);

562   // procedure must indicate that the store requires `release'
563   // semantics, if the stored value is an object reference that might
564   // point to a new object and may become externally visible.
565   // Return the new StoreXNode
566   Node* store_to_memory(Node* ctl, Node* adr, Node* val, BasicType bt,
567                         MemNode::MemOrd,
568                         bool require_atomic_access = false,
569                         bool unaligned = false,
570                         bool mismatched = false,
571                         bool unsafe = false,
572                         int barrier_data = 0);
573 
574   // Perform decorated accesses
575 
576   Node* access_store_at(Node* obj,   // containing obj
577                         Node* adr,   // actual address to store val at
578                         const TypePtr* adr_type,
579                         Node* val,
580                         const Type* val_type,
581                         BasicType bt,
582                         DecoratorSet decorators);


583 
584   Node* access_load_at(Node* obj,   // containing obj
585                        Node* adr,   // actual address to load val at
586                        const TypePtr* adr_type,
587                        const Type* val_type,
588                        BasicType bt,
589                        DecoratorSet decorators);

590 
591   Node* access_load(Node* adr,   // actual address to load val at
592                     const Type* val_type,
593                     BasicType bt,
594                     DecoratorSet decorators);
595 
596   Node* access_atomic_cmpxchg_val_at(Node* obj,
597                                      Node* adr,
598                                      const TypePtr* adr_type,
599                                      int alias_idx,
600                                      Node* expected_val,
601                                      Node* new_val,
602                                      const Type* value_type,
603                                      BasicType bt,
604                                      DecoratorSet decorators);
605 
606   Node* access_atomic_cmpxchg_bool_at(Node* obj,
607                                       Node* adr,
608                                       const TypePtr* adr_type,
609                                       int alias_idx,

622                               BasicType bt,
623                               DecoratorSet decorators);
624 
625   Node* access_atomic_add_at(Node* obj,
626                              Node* adr,
627                              const TypePtr* adr_type,
628                              int alias_idx,
629                              Node* new_val,
630                              const Type* value_type,
631                              BasicType bt,
632                              DecoratorSet decorators);
633 
634   void access_clone(Node* src, Node* dst, Node* size, bool is_array);
635 
636   // Return addressing for an array element.
637   Node* array_element_address(Node* ary, Node* idx, BasicType elembt,
638                               // Optional constraint on the array size:
639                               const TypeInt* sizetype = nullptr,
640                               // Optional control dependency (for example, on range check)
641                               Node* ctrl = nullptr);


642 
643   // Return a load of array element at idx.
644   Node* load_array_element(Node* ary, Node* idx, const TypeAryPtr* arytype, bool set_ctrl);
645 
646   //---------------- Dtrace support --------------------
647   void make_dtrace_method_entry_exit(ciMethod* method, bool is_entry);
648   void make_dtrace_method_entry(ciMethod* method) {
649     make_dtrace_method_entry_exit(method, true);
650   }
651   void make_dtrace_method_exit(ciMethod* method) {
652     make_dtrace_method_entry_exit(method, false);
653   }
654 
655   //--------------- stub generation -------------------
656  public:
657   void gen_stub(address C_function,
658                 const char *name,
659                 int is_fancy_jump,
660                 bool pass_tls,
661                 bool return_pc);
662 
663   //---------- help for generating calls --------------
664 
665   // Do a null check on the receiver as it would happen before the call to
666   // callee (with all arguments still on the stack).
667   Node* null_check_receiver_before_call(ciMethod* callee) {
668     assert(!callee->is_static(), "must be a virtual method");
669     // Callsite signature can be different from actual method being called (i.e _linkTo* sites).
670     // Use callsite signature always.
671     ciMethod* declared_method = method()->get_method_at_bci(bci());
672     const int nargs = declared_method->arg_size();
673     inc_sp(nargs);
674     Node* n = null_check_receiver();
675     dec_sp(nargs);
676     return n;
677   }
678 
679   // Fill in argument edges for the call from argument(0), argument(1), ...
680   // (The next step is to call set_edges_for_java_call.)
681   void  set_arguments_for_java_call(CallJavaNode* call);
682 
683   // Fill in non-argument edges for the call.
684   // Transform the call, and update the basics: control, i_o, memory.
685   // (The next step is usually to call set_results_for_java_call.)
686   void set_edges_for_java_call(CallJavaNode* call,
687                                bool must_throw = false, bool separate_io_proj = false);
688 
689   // Finish up a java call that was started by set_edges_for_java_call.
690   // Call add_exception on any throw arising from the call.
691   // Return the call result (transformed).
692   Node* set_results_for_java_call(CallJavaNode* call, bool separate_io_proj = false, bool deoptimize = false);
693 
694   // Similar to set_edges_for_java_call, but simplified for runtime calls.
695   void  set_predefined_output_for_runtime_call(Node* call) {
696     set_predefined_output_for_runtime_call(call, nullptr, nullptr);
697   }
698   void  set_predefined_output_for_runtime_call(Node* call,
699                                                Node* keep_mem,
700                                                const TypePtr* hook_mem);
701   Node* set_predefined_input_for_runtime_call(SafePointNode* call, Node* narrow_mem = nullptr);

794   void merge_memory(Node* new_mem, Node* region, int new_path);
795   void make_slow_call_ex(Node* call, ciInstanceKlass* ex_klass, bool separate_io_proj, bool deoptimize = false);
796 
797   // Helper functions to build synchronizations
798   int next_monitor();
799   Node* insert_mem_bar(int opcode, Node* precedent = nullptr);
800   Node* insert_mem_bar_volatile(int opcode, int alias_idx, Node* precedent = nullptr);
801   // Optional 'precedent' is appended as an extra edge, to force ordering.
802   FastLockNode* shared_lock(Node* obj);
803   void shared_unlock(Node* box, Node* obj);
804 
805   // helper functions for the fast path/slow path idioms
806   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);
807 
808   // Generate an instance-of idiom.  Used by both the instance-of bytecode
809   // and the reflective instance-of call.
810   Node* gen_instanceof(Node *subobj, Node* superkls, bool safe_for_replace = false);
811 
812   // Generate a check-cast idiom.  Used by both the check-cast bytecode
813   // and the array-store bytecode
814   Node* gen_checkcast( Node *subobj, Node* superkls,
815                        Node* *failure_control = nullptr );







816 
817   Node* gen_subtype_check(Node* obj, Node* superklass);
818 
819   // Exact type check used for predicted calls and casts.
820   // Rewrites (*casted_receiver) to be casted to the stronger type.
821   // (Caller is responsible for doing replace_in_map.)
822   Node* type_check_receiver(Node* receiver, ciKlass* klass, float prob,
823                             Node* *casted_receiver);

824 
825   // Inexact type check used for predicted calls.
826   Node* subtype_check_receiver(Node* receiver, ciKlass* klass,
827                                Node** casted_receiver);
828 
829   // implementation of object creation
830   Node* set_output_for_allocation(AllocateNode* alloc,
831                                   const TypeOopPtr* oop_type,
832                                   bool deoptimize_on_exception=false);
833   Node* get_layout_helper(Node* klass_node, jint& constant_value);
834   Node* new_instance(Node* klass_node,
835                      Node* slow_test = nullptr,
836                      Node* *return_size_val = nullptr,
837                      bool deoptimize_on_exception = false);

838   Node* new_array(Node* klass_node, Node* count_val, int nargs,
839                   Node* *return_size_val = nullptr,
840                   bool deoptimize_on_exception = false);

841 
842   // java.lang.String helpers
843   Node* load_String_length(Node* str, bool set_ctrl);
844   Node* load_String_value(Node* str, bool set_ctrl);
845   Node* load_String_coder(Node* str, bool set_ctrl);
846   void store_String_value(Node* str, Node* value);
847   void store_String_coder(Node* str, Node* value);
848   Node* capture_memory(const TypePtr* src_type, const TypePtr* dst_type);
849   Node* compress_string(Node* src, const TypeAryPtr* src_type, Node* dst, Node* count);
850   void inflate_string(Node* src, Node* dst, const TypeAryPtr* dst_type, Node* count);
851   void inflate_string_slow(Node* src, Node* dst, Node* start, Node* count);
852 
853   // Handy for making control flow
854   IfNode* create_and_map_if(Node* ctrl, Node* tst, float prob, float cnt) {
855     IfNode* iff = new IfNode(ctrl, tst, prob, cnt);// New IfNode's
856     _gvn.set_type(iff, iff->Value(&_gvn)); // Value may be known at parse-time
857     // Place 'if' on worklist if it will be in graph
858     if (!tst->is_Con())  record_for_igvn(iff);     // Range-check and Null-check removal is later
859     return iff;
860   }
861 
862   IfNode* create_and_xform_if(Node* ctrl, Node* tst, float prob, float cnt) {
863     IfNode* iff = new IfNode(ctrl, tst, prob, cnt);// New IfNode's
864     _gvn.transform(iff);                           // Value may be known at parse-time
865     // Place 'if' on worklist if it will be in graph
866     if (!tst->is_Con())  record_for_igvn(iff);     // Range-check and Null-check removal is later
867     return iff;
868   }
869 
870   void add_parse_predicates(int nargs = 0);
871   void add_parse_predicate(Deoptimization::DeoptReason reason, int nargs);
872 
873   Node* make_constant_from_field(ciField* field, Node* obj);

874 
875   // Vector API support (implemented in vectorIntrinsics.cpp)
876   Node* box_vector(Node* in, const TypeInstPtr* vbox_type, BasicType elem_bt, int num_elem, bool deoptimize_on_exception = false);
877   Node* unbox_vector(Node* in, const TypeInstPtr* vbox_type, BasicType elem_bt, int num_elem);
878   Node* vector_shift_count(Node* cnt, int shift_op, BasicType bt, int num_elem);
879 };
880 
881 // Helper class to support building of control flow branches. Upon
882 // creation the map and sp at bci are cloned and restored upon de-
883 // struction. Typical use:
884 //
885 // { PreserveJVMState pjvms(this);
886 //   // code of new branch
887 // }
888 // // here the JVM state at bci is established
889 
890 class PreserveJVMState: public StackObj {
891  protected:
892   GraphKit*      _kit;
893 #ifdef ASSERT

  1 /*
  2  * Copyright (c) 2001, 2026, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 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 != nullptr, "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 = nullptr);     // the JVM state on which to operate
 86 
 87   // Create a GraphKit from a debug state, useful for various kinds of macro expansion
 88   GraphKit(const SafePointNode* sft, PhaseIterGVN& igvn);
 89 
 90 #ifdef ASSERT
 91   ~GraphKit() {
 92     assert(failing_internal() || !has_exceptions(),
 93            "unless compilation failed, user must call transfer_exceptions_into_jvms");
 94   }
 95 #endif
 96 
 97   virtual Parse*          is_Parse()          const { return nullptr; }
 98   virtual LibraryCallKit* is_LibraryCallKit() const { return nullptr; }
 99 
100   ciEnv*        env()               const { return _env; }
101   PhaseGVN&     gvn()               const { return _gvn; }
102   void*         barrier_set_state() const { return C->barrier_set_state(); }
103 
104   void record_for_igvn(Node* n) const { _gvn.record_for_igvn(n); }
105   void remove_for_igvn(Node* n) const { C->remove_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.)

362   Node* ConvL2I(Node* offset);
363   // Find out the klass of an object.
364   Node* load_object_klass(Node* object);
365   // Find out the length of an array.
366   Node* load_array_length(Node* array);
367   // Cast array allocation's length as narrow as possible.
368   // If replace_length_in_map is true, replace length with CastIINode in map.
369   // This method is invoked after creating/moving ArrayAllocationNode or in load_array_length
370   Node* array_ideal_length(AllocateArrayNode* alloc,
371                            const TypeOopPtr* oop_type,
372                            bool replace_length_in_map);
373 
374 
375   // Helper function to do a null pointer check or ZERO check based on type.
376   // Throw an exception if a given value is null.
377   // Return the value cast to not-null.
378   // Be clever about equivalent dominating null checks.
379   Node* null_check_common(Node* value, BasicType type,
380                           bool assert_null = false,
381                           Node* *null_control = nullptr,
382                           bool speculative = false,
383                           bool null_marker_check = false);
384   Node* null_check(Node* value, BasicType type = T_OBJECT) {
385     return null_check_common(value, type, false, nullptr, !_gvn.type(value)->speculative_maybe_null());
386   }
387   Node* null_check_receiver() {

388     return null_check(argument(0));
389   }
390   Node* zero_check_int(Node* value) {
391     assert(value->bottom_type()->basic_type() == T_INT,
392            "wrong type: %s", type2name(value->bottom_type()->basic_type()));
393     return null_check_common(value, T_INT);
394   }
395   Node* zero_check_long(Node* value) {
396     assert(value->bottom_type()->basic_type() == T_LONG,
397            "wrong type: %s", type2name(value->bottom_type()->basic_type()));
398     return null_check_common(value, T_LONG);
399   }
400   // Throw an uncommon trap if a given value is __not__ null.
401   // Return the value cast to null, and be clever about dominating checks.
402   Node* null_assert(Node* value, BasicType type = T_OBJECT) {
403     return null_check_common(value, type, true, nullptr, _gvn.type(value)->speculative_always_null());
404   }
405 
406   // Check if value is null and abort if it is
407   Node* must_be_not_null(Node* value, bool do_replace_in_map);

569   // procedure must indicate that the store requires `release'
570   // semantics, if the stored value is an object reference that might
571   // point to a new object and may become externally visible.
572   // Return the new StoreXNode
573   Node* store_to_memory(Node* ctl, Node* adr, Node* val, BasicType bt,
574                         MemNode::MemOrd,
575                         bool require_atomic_access = false,
576                         bool unaligned = false,
577                         bool mismatched = false,
578                         bool unsafe = false,
579                         int barrier_data = 0);
580 
581   // Perform decorated accesses
582 
583   Node* access_store_at(Node* obj,   // containing obj
584                         Node* adr,   // actual address to store val at
585                         const TypePtr* adr_type,
586                         Node* val,
587                         const Type* val_type,
588                         BasicType bt,
589                         DecoratorSet decorators,
590                         bool safe_for_replace = true,
591                         const InlineTypeNode* vt = nullptr);
592 
593   Node* access_load_at(Node* obj,   // containing obj
594                        Node* adr,   // actual address to load val at
595                        const TypePtr* adr_type,
596                        const Type* val_type,
597                        BasicType bt,
598                        DecoratorSet decorators,
599                        Node* ctl = nullptr);
600 
601   Node* access_load(Node* adr,   // actual address to load val at
602                     const Type* val_type,
603                     BasicType bt,
604                     DecoratorSet decorators);
605 
606   Node* access_atomic_cmpxchg_val_at(Node* obj,
607                                      Node* adr,
608                                      const TypePtr* adr_type,
609                                      int alias_idx,
610                                      Node* expected_val,
611                                      Node* new_val,
612                                      const Type* value_type,
613                                      BasicType bt,
614                                      DecoratorSet decorators);
615 
616   Node* access_atomic_cmpxchg_bool_at(Node* obj,
617                                       Node* adr,
618                                       const TypePtr* adr_type,
619                                       int alias_idx,

632                               BasicType bt,
633                               DecoratorSet decorators);
634 
635   Node* access_atomic_add_at(Node* obj,
636                              Node* adr,
637                              const TypePtr* adr_type,
638                              int alias_idx,
639                              Node* new_val,
640                              const Type* value_type,
641                              BasicType bt,
642                              DecoratorSet decorators);
643 
644   void access_clone(Node* src, Node* dst, Node* size, bool is_array);
645 
646   // Return addressing for an array element.
647   Node* array_element_address(Node* ary, Node* idx, BasicType elembt,
648                               // Optional constraint on the array size:
649                               const TypeInt* sizetype = nullptr,
650                               // Optional control dependency (for example, on range check)
651                               Node* ctrl = nullptr);
652   Node* cast_to_flat_array(Node* array, ciInlineKlass* elem_vk);
653   Node* cast_to_flat_array_exact(Node* array, ciInlineKlass* elem_vk, bool is_null_free, bool is_atomic);
654 
655   // Return a load of array element at idx.
656   Node* load_array_element(Node* ary, Node* idx, const TypeAryPtr* arytype, bool set_ctrl);
657 
658   //---------------- Dtrace support --------------------
659   void make_dtrace_method_entry_exit(ciMethod* method, bool is_entry);
660   void make_dtrace_method_entry(ciMethod* method) {
661     make_dtrace_method_entry_exit(method, true);
662   }
663   void make_dtrace_method_exit(ciMethod* method) {
664     make_dtrace_method_entry_exit(method, false);
665   }
666 
667   //--------------- stub generation -------------------
668  public:
669   void gen_stub(address C_function,
670                 const char *name,
671                 int is_fancy_jump,
672                 bool pass_tls,
673                 bool return_pc);
674 
675   //---------- help for generating calls --------------
676 
677   // Do a null check on the receiver as it would happen before the call to
678   // callee (with all arguments still on the stack).
679   Node* null_check_receiver_before_call(ciMethod* callee) {
680     assert(!callee->is_static(), "must be a virtual method");
681     // Callsite signature can be different from actual method being called (i.e _linkTo* sites).
682     // Use callsite signature always.
683     ciMethod* declared_method = method()->get_method_at_bci(bci());
684     const int nargs = declared_method->arg_size();
685     inc_sp(nargs);
686     Node* n = null_check_receiver();
687     dec_sp(nargs);
688     return n;
689   }
690 
691   // Fill in argument edges for the call from argument(0), argument(1), ...
692   // (The next step is to call set_edges_for_java_call.)
693   void  set_arguments_for_java_call(CallJavaNode* call, bool is_late_inline = false);
694 
695   // Fill in non-argument edges for the call.
696   // Transform the call, and update the basics: control, i_o, memory.
697   // (The next step is usually to call set_results_for_java_call.)
698   void set_edges_for_java_call(CallJavaNode* call,
699                                bool must_throw = false, bool separate_io_proj = false);
700 
701   // Finish up a java call that was started by set_edges_for_java_call.
702   // Call add_exception on any throw arising from the call.
703   // Return the call result (transformed).
704   Node* set_results_for_java_call(CallJavaNode* call, bool separate_io_proj = false, bool deoptimize = false);
705 
706   // Similar to set_edges_for_java_call, but simplified for runtime calls.
707   void  set_predefined_output_for_runtime_call(Node* call) {
708     set_predefined_output_for_runtime_call(call, nullptr, nullptr);
709   }
710   void  set_predefined_output_for_runtime_call(Node* call,
711                                                Node* keep_mem,
712                                                const TypePtr* hook_mem);
713   Node* set_predefined_input_for_runtime_call(SafePointNode* call, Node* narrow_mem = nullptr);

806   void merge_memory(Node* new_mem, Node* region, int new_path);
807   void make_slow_call_ex(Node* call, ciInstanceKlass* ex_klass, bool separate_io_proj, bool deoptimize = false);
808 
809   // Helper functions to build synchronizations
810   int next_monitor();
811   Node* insert_mem_bar(int opcode, Node* precedent = nullptr);
812   Node* insert_mem_bar_volatile(int opcode, int alias_idx, Node* precedent = nullptr);
813   // Optional 'precedent' is appended as an extra edge, to force ordering.
814   FastLockNode* shared_lock(Node* obj);
815   void shared_unlock(Node* box, Node* obj);
816 
817   // helper functions for the fast path/slow path idioms
818   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);
819 
820   // Generate an instance-of idiom.  Used by both the instance-of bytecode
821   // and the reflective instance-of call.
822   Node* gen_instanceof(Node *subobj, Node* superkls, bool safe_for_replace = false);
823 
824   // Generate a check-cast idiom.  Used by both the check-cast bytecode
825   // and the array-store bytecode
826   Node* gen_checkcast(Node *subobj, Node* superkls, Node* *failure_control = nullptr, bool null_free = false, bool maybe_larval = false);
827 
828   // Inline types
829   Node* mark_word_test(Node* obj, uintptr_t mask_val, bool eq, bool check_lock = true);
830   Node* inline_type_test(Node* obj, bool is_inline = true);
831   Node* flat_array_test(Node* array_or_klass, bool flat = true);
832   Node* null_free_array_test(Node* array, bool null_free = true);
833   Node* null_free_atomic_array_test(Node* array, ciInlineKlass* vk);
834   Node* inline_array_null_guard(Node* ary, Node* val, int nargs, bool safe_for_replace = false);
835 
836   Node* gen_subtype_check(Node* obj, Node* superklass);
837 
838   // Exact type check used for predicted calls and casts.
839   // Rewrites (*casted_receiver) to be casted to the stronger type.
840   // (Caller is responsible for doing replace_in_map.)
841   Node* type_check_receiver(Node* receiver, ciKlass* klass, float prob,
842                             Node* *casted_receiver);
843   Node* type_check(Node* recv_klass, const TypeKlassPtr* tklass, float prob);
844 
845   // Inexact type check used for predicted calls.
846   Node* subtype_check_receiver(Node* receiver, ciKlass* klass,
847                                Node** casted_receiver);
848 
849   // implementation of object creation
850   Node* set_output_for_allocation(AllocateNode* alloc,
851                                   const TypeOopPtr* oop_type,
852                                   bool deoptimize_on_exception=false);
853   Node* get_layout_helper(Node* klass_node, jint& constant_value);
854   Node* new_instance(Node* klass_node,
855                      Node* slow_test = nullptr,
856                      Node* *return_size_val = nullptr,
857                      bool deoptimize_on_exception = false,
858                      InlineTypeNode* inline_type_node = nullptr);
859   Node* new_array(Node* klass_node, Node* count_val, int nargs,
860                   Node* *return_size_val = nullptr,
861                   bool deoptimize_on_exception = false,
862                   Node* init_val = nullptr);
863 
864   // java.lang.String helpers
865   Node* load_String_length(Node* str, bool set_ctrl);
866   Node* load_String_value(Node* str, bool set_ctrl);
867   Node* load_String_coder(Node* str, bool set_ctrl);
868   void store_String_value(Node* str, Node* value);
869   void store_String_coder(Node* str, Node* value);
870   Node* capture_memory(const TypePtr* src_type, const TypePtr* dst_type);
871   Node* compress_string(Node* src, const TypeAryPtr* src_type, Node* dst, Node* count);
872   void inflate_string(Node* src, Node* dst, const TypeAryPtr* dst_type, Node* count);
873   void inflate_string_slow(Node* src, Node* dst, Node* start, Node* count);
874 
875   // Handy for making control flow
876   IfNode* create_and_map_if(Node* ctrl, Node* tst, float prob, float cnt) {
877     IfNode* iff = new IfNode(ctrl, tst, prob, cnt);// New IfNode's
878     _gvn.set_type(iff, iff->Value(&_gvn)); // Value may be known at parse-time
879     // Place 'if' on worklist if it will be in graph
880     if (!tst->is_Con())  record_for_igvn(iff);     // Range-check and Null-check removal is later
881     return iff;
882   }
883 
884   IfNode* create_and_xform_if(Node* ctrl, Node* tst, float prob, float cnt) {
885     IfNode* iff = new IfNode(ctrl, tst, prob, cnt);// New IfNode's
886     _gvn.transform(iff);                           // Value may be known at parse-time
887     // Place 'if' on worklist if it will be in graph
888     if (!tst->is_Con())  record_for_igvn(iff);     // Range-check and Null-check removal is later
889     return iff;
890   }
891 
892   void add_parse_predicates(int nargs = 0);
893   void add_parse_predicate(Deoptimization::DeoptReason reason, int nargs);
894 
895   Node* make_constant_from_field(ciField* field, Node* obj);
896   Node* load_mirror_from_klass(Node* klass);
897 
898   // Vector API support (implemented in vectorIntrinsics.cpp)
899   Node* box_vector(Node* in, const TypeInstPtr* vbox_type, BasicType elem_bt, int num_elem, bool deoptimize_on_exception = false);
900   Node* unbox_vector(Node* in, const TypeInstPtr* vbox_type, BasicType elem_bt, int num_elem);
901   Node* vector_shift_count(Node* cnt, int shift_op, BasicType bt, int num_elem);
902 };
903 
904 // Helper class to support building of control flow branches. Upon
905 // creation the map and sp at bci are cloned and restored upon de-
906 // struction. Typical use:
907 //
908 // { PreserveJVMState pjvms(this);
909 //   // code of new branch
910 // }
911 // // here the JVM state at bci is established
912 
913 class PreserveJVMState: public StackObj {
914  protected:
915   GraphKit*      _kit;
916 #ifdef ASSERT
< prev index next >