< prev index next >

src/hotspot/share/opto/library_call.hpp

Print this page

 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 #include "ci/ciMethod.hpp"
 26 #include "classfile/javaClasses.hpp"
 27 #include "opto/callGenerator.hpp"
 28 #include "opto/graphKit.hpp"
 29 #include "opto/castnode.hpp"
 30 #include "opto/convertnode.hpp"

 31 #include "opto/intrinsicnode.hpp"
 32 #include "opto/movenode.hpp"
 33 
 34 class LibraryIntrinsic : public InlineCallGenerator {
 35   // Extend the set of intrinsics known to the runtime:
 36  public:
 37  private:
 38   bool             _is_virtual;
 39   bool             _does_virtual_dispatch;
 40   int8_t           _predicates_count;  // Intrinsic is predicated by several conditions
 41   int8_t           _last_predicate; // Last generated predicate
 42   vmIntrinsics::ID _intrinsic_id;
 43 
 44  public:
 45   LibraryIntrinsic(ciMethod* m, bool is_virtual, int predicates_count, bool does_virtual_dispatch, vmIntrinsics::ID id)
 46     : InlineCallGenerator(m),
 47       _is_virtual(is_virtual),
 48       _does_virtual_dispatch(does_virtual_dispatch),
 49       _predicates_count((int8_t)predicates_count),
 50       _last_predicate((int8_t)-1),

 88       ciSignature* declared_signature = NULL;
 89       ciMethod* ignored_callee = caller()->get_method_at_bci(bci(), ignored_will_link, &declared_signature);
 90       const int nargs = declared_signature->arg_size_for_bc(caller()->java_code_at_bci(bci()));
 91       _reexecute_sp = sp() + nargs;  // "push" arguments back on stack
 92     }
 93   }
 94 
 95   virtual LibraryCallKit* is_LibraryCallKit() const { return (LibraryCallKit*)this; }
 96 
 97   ciMethod*         caller()    const    { return jvms()->method(); }
 98   int               bci()       const    { return jvms()->bci(); }
 99   LibraryIntrinsic* intrinsic() const    { return _intrinsic; }
100   vmIntrinsics::ID  intrinsic_id() const { return _intrinsic->intrinsic_id(); }
101   ciMethod*         callee()    const    { return _intrinsic->method(); }
102 
103   bool  try_to_inline(int predicate);
104   Node* try_to_predicate(int predicate);
105 
106   void push_result() {
107     // Push the result onto the stack.
108     if (!stopped() && result() != NULL) {
109       BasicType bt = result()->bottom_type()->basic_type();
110       push_node(bt, result());








111     }
112   }
113 
114  private:
115   void fatal_unexpected_iid(vmIntrinsics::ID iid) {
116     fatal("unexpected intrinsic %d: %s", vmIntrinsics::as_int(iid), vmIntrinsics::name_at(iid));
117   }
118 
119   void  set_result(Node* n) { assert(_result == NULL, "only set once"); _result = n; }
120   void  set_result(RegionNode* region, PhiNode* value);
121   Node*     result() { return _result; }
122 
123   virtual int reexecute_sp() { return _reexecute_sp; }
124 
125   // Helper functions to inline natives
126   Node* generate_guard(Node* test, RegionNode* region, float true_prob);
127   Node* generate_slow_guard(Node* test, RegionNode* region);
128   Node* generate_fair_guard(Node* test, RegionNode* region);
129   Node* generate_negative_guard(Node* index, RegionNode* region,
130                                 // resulting CastII of index:
131                                 Node* *pos_index = NULL);
132   Node* generate_limit_guard(Node* offset, Node* subseq_length,
133                              Node* array_length,
134                              RegionNode* region);
135   void  generate_string_range_check(Node* array, Node* offset,
136                                     Node* length, bool char_count);
137   Node* generate_current_thread(Node* &tls_output);
138   Node* load_mirror_from_klass(Node* klass);
139   Node* load_klass_from_mirror_common(Node* mirror, bool never_see_null,
140                                       RegionNode* region, int null_path,
141                                       int offset);
142   Node* load_klass_from_mirror(Node* mirror, bool never_see_null,
143                                RegionNode* region, int null_path) {
144     int offset = java_lang_Class::klass_offset();
145     return load_klass_from_mirror_common(mirror, never_see_null,
146                                          region, null_path,
147                                          offset);
148   }
149   Node* load_array_klass_from_mirror(Node* mirror, bool never_see_null,
150                                      RegionNode* region, int null_path) {
151     int offset = java_lang_Class::array_klass_offset();
152     return load_klass_from_mirror_common(mirror, never_see_null,
153                                          region, null_path,
154                                          offset);
155   }
156   Node* generate_access_flags_guard(Node* kls,
157                                     int modifier_mask, int modifier_bits,
158                                     RegionNode* region);
159   Node* generate_interface_guard(Node* kls, RegionNode* region);











160   Node* generate_hidden_class_guard(Node* kls, RegionNode* region);

161   Node* generate_array_guard(Node* kls, RegionNode* region) {
162     return generate_array_guard_common(kls, region, false, false);
163   }
164   Node* generate_non_array_guard(Node* kls, RegionNode* region) {
165     return generate_array_guard_common(kls, region, false, true);
166   }
167   Node* generate_objArray_guard(Node* kls, RegionNode* region) {
168     return generate_array_guard_common(kls, region, true, false);
169   }
170   Node* generate_non_objArray_guard(Node* kls, RegionNode* region) {
171     return generate_array_guard_common(kls, region, true, true);











172   }
173   Node* generate_array_guard_common(Node* kls, RegionNode* region,
174                                     bool obj_array, bool not_array);
175   Node* generate_virtual_guard(Node* obj_klass, RegionNode* slow_region);
176   CallJavaNode* generate_method_call(vmIntrinsics::ID method_id,
177                                      bool is_virtual = false, bool is_static = false);
178   CallJavaNode* generate_method_call_static(vmIntrinsics::ID method_id) {
179     return generate_method_call(method_id, false, true);
180   }
181   CallJavaNode* generate_method_call_virtual(vmIntrinsics::ID method_id) {
182     return generate_method_call(method_id, true, false);
183   }
184   Node* load_field_from_object(Node* fromObj, const char* fieldName, const char* fieldTypeString, DecoratorSet decorators, bool is_static, ciInstanceKlass* fromKls);
185   Node* field_address_from_object(Node* fromObj, const char* fieldName, const char* fieldTypeString, bool is_exact, bool is_static, ciInstanceKlass* fromKls);
186 
187   Node* make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2, StrIntrinsicNode::ArgEnc ae);
188   bool inline_string_compareTo(StrIntrinsicNode::ArgEnc ae);
189   bool inline_string_indexOf(StrIntrinsicNode::ArgEnc ae);
190   bool inline_string_indexOfI(StrIntrinsicNode::ArgEnc ae);
191   Node* make_indexOf_node(Node* src_start, Node* src_count, Node* tgt_start, Node* tgt_count,
192                           RegionNode* region, Node* phi, StrIntrinsicNode::ArgEnc ae);
193   bool inline_string_indexOfChar(StrIntrinsicNode::ArgEnc ae);
194   bool inline_string_equals(StrIntrinsicNode::ArgEnc ae);

213   bool inline_math_negateExactI();
214   bool inline_math_negateExactL();
215   bool inline_math_subtractExactI(bool is_decrement);
216   bool inline_math_subtractExactL(bool is_decrement);
217   bool inline_min_max(vmIntrinsics::ID id);
218   bool inline_notify(vmIntrinsics::ID id);
219   Node* generate_min_max(vmIntrinsics::ID id, Node* x, Node* y);
220   // This returns Type::AnyPtr, RawPtr, or OopPtr.
221   int classify_unsafe_addr(Node* &base, Node* &offset, BasicType type);
222   Node* make_unsafe_address(Node*& base, Node* offset, BasicType type = T_ILLEGAL, bool can_cast = false);
223 
224   typedef enum { Relaxed, Opaque, Volatile, Acquire, Release } AccessKind;
225   DecoratorSet mo_decorator_for_access_kind(AccessKind kind);
226   bool inline_unsafe_access(bool is_store, BasicType type, AccessKind kind, bool is_unaligned);
227   static bool klass_needs_init_guard(Node* kls);
228   bool inline_unsafe_allocate();
229   bool inline_unsafe_newArray(bool uninitialized);
230   bool inline_unsafe_writeback0();
231   bool inline_unsafe_writebackSync0(bool is_pre);
232   bool inline_unsafe_copyMemory();


233   bool inline_native_currentThread();
234 
235   bool inline_native_time_funcs(address method, const char* funcName);
236 #ifdef JFR_HAVE_INTRINSICS
237   bool inline_native_classID();
238   bool inline_native_getEventWriter();
239 #endif
240   bool inline_native_Class_query(vmIntrinsics::ID id);

241   bool inline_native_subtype_check();
242   bool inline_native_getLength();
243   bool inline_array_copyOf(bool is_copyOfRange);
244   bool inline_array_equals(StrIntrinsicNode::ArgEnc ae);
245   bool inline_preconditions_checkIndex(BasicType bt);
246   void copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array);
247   bool inline_native_clone(bool is_virtual);
248   bool inline_native_Reflection_getCallerClass();
249   // Helper function for inlining native object hash method
250   bool inline_native_hashcode(bool is_virtual, bool is_static);
251   bool inline_native_getClass();
252 
253   // Helper functions for inlining arraycopy
254   bool inline_arraycopy();
255   AllocateArrayNode* tightly_coupled_allocation(Node* ptr);
256   JVMState* arraycopy_restore_alloc_state(AllocateArrayNode* alloc, int& saved_reexecute_sp);
257   void arraycopy_move_allocation_here(AllocateArrayNode* alloc, Node* dest, JVMState* saved_jvms, int saved_reexecute_sp,
258                                       uint new_idx);
259 
260   typedef enum { LS_get_add, LS_get_set, LS_cmp_swap, LS_cmp_swap_weak, LS_cmp_exchange } LoadStoreKind;

 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 #include "ci/ciMethod.hpp"
 26 #include "classfile/javaClasses.hpp"
 27 #include "opto/callGenerator.hpp"
 28 #include "opto/graphKit.hpp"
 29 #include "opto/castnode.hpp"
 30 #include "opto/convertnode.hpp"
 31 #include "opto/inlinetypenode.hpp"
 32 #include "opto/intrinsicnode.hpp"
 33 #include "opto/movenode.hpp"
 34 
 35 class LibraryIntrinsic : public InlineCallGenerator {
 36   // Extend the set of intrinsics known to the runtime:
 37  public:
 38  private:
 39   bool             _is_virtual;
 40   bool             _does_virtual_dispatch;
 41   int8_t           _predicates_count;  // Intrinsic is predicated by several conditions
 42   int8_t           _last_predicate; // Last generated predicate
 43   vmIntrinsics::ID _intrinsic_id;
 44 
 45  public:
 46   LibraryIntrinsic(ciMethod* m, bool is_virtual, int predicates_count, bool does_virtual_dispatch, vmIntrinsics::ID id)
 47     : InlineCallGenerator(m),
 48       _is_virtual(is_virtual),
 49       _does_virtual_dispatch(does_virtual_dispatch),
 50       _predicates_count((int8_t)predicates_count),
 51       _last_predicate((int8_t)-1),

 89       ciSignature* declared_signature = NULL;
 90       ciMethod* ignored_callee = caller()->get_method_at_bci(bci(), ignored_will_link, &declared_signature);
 91       const int nargs = declared_signature->arg_size_for_bc(caller()->java_code_at_bci(bci()));
 92       _reexecute_sp = sp() + nargs;  // "push" arguments back on stack
 93     }
 94   }
 95 
 96   virtual LibraryCallKit* is_LibraryCallKit() const { return (LibraryCallKit*)this; }
 97 
 98   ciMethod*         caller()    const    { return jvms()->method(); }
 99   int               bci()       const    { return jvms()->bci(); }
100   LibraryIntrinsic* intrinsic() const    { return _intrinsic; }
101   vmIntrinsics::ID  intrinsic_id() const { return _intrinsic->intrinsic_id(); }
102   ciMethod*         callee()    const    { return _intrinsic->method(); }
103 
104   bool  try_to_inline(int predicate);
105   Node* try_to_predicate(int predicate);
106 
107   void push_result() {
108     // Push the result onto the stack.
109     Node* res = result();
110     if (!stopped() && res != NULL) {
111       BasicType bt = res->bottom_type()->basic_type();
112       if (C->inlining_incrementally() && res->is_InlineType()) {
113         // The caller expects an oop when incrementally inlining an intrinsic that returns an
114         // inline type. Make sure the call is re-executed if the allocation triggers a deoptimization.
115         PreserveReexecuteState preexecs(this);
116         jvms()->set_should_reexecute(true);
117         res = res->as_InlineType()->buffer(this);
118       }
119       push_node(bt, res);
120     }
121   }
122 
123  private:
124   void fatal_unexpected_iid(vmIntrinsics::ID iid) {
125     fatal("unexpected intrinsic %d: %s", vmIntrinsics::as_int(iid), vmIntrinsics::name_at(iid));
126   }
127 
128   void  set_result(Node* n) { assert(_result == NULL, "only set once"); _result = n; }
129   void  set_result(RegionNode* region, PhiNode* value);
130   Node*     result() { return _result; }
131 
132   virtual int reexecute_sp() { return _reexecute_sp; }
133 
134   // Helper functions to inline natives
135   Node* generate_guard(Node* test, RegionNode* region, float true_prob);
136   Node* generate_slow_guard(Node* test, RegionNode* region);
137   Node* generate_fair_guard(Node* test, RegionNode* region);
138   Node* generate_negative_guard(Node* index, RegionNode* region,
139                                 // resulting CastII of index:
140                                 Node* *pos_index = NULL);
141   Node* generate_limit_guard(Node* offset, Node* subseq_length,
142                              Node* array_length,
143                              RegionNode* region);
144   void  generate_string_range_check(Node* array, Node* offset,
145                                     Node* length, bool char_count);
146   Node* generate_current_thread(Node* &tls_output);

147   Node* load_klass_from_mirror_common(Node* mirror, bool never_see_null,
148                                       RegionNode* region, int null_path,
149                                       int offset);
150   Node* load_klass_from_mirror(Node* mirror, bool never_see_null,
151                                RegionNode* region, int null_path) {
152     int offset = java_lang_Class::klass_offset();
153     return load_klass_from_mirror_common(mirror, never_see_null,
154                                          region, null_path,
155                                          offset);
156   }
157   Node* load_array_klass_from_mirror(Node* mirror, bool never_see_null,
158                                      RegionNode* region, int null_path) {
159     int offset = java_lang_Class::array_klass_offset();
160     return load_klass_from_mirror_common(mirror, never_see_null,
161                                          region, null_path,
162                                          offset);
163   }
164   Node* generate_access_flags_guard(Node* kls,
165                                     int modifier_mask, int modifier_bits,
166                                     RegionNode* region);
167   Node* generate_interface_guard(Node* kls, RegionNode* region);
168 
169   enum ArrayKind {
170     AnyArray,
171     NonArray,
172     ObjectArray,
173     NonObjectArray,
174     TypeArray,
175     FlatArray,
176     NonFlatArray
177   };
178 
179   Node* generate_hidden_class_guard(Node* kls, RegionNode* region);
180 
181   Node* generate_array_guard(Node* kls, RegionNode* region) {
182     return generate_array_guard_common(kls, region, AnyArray);
183   }
184   Node* generate_non_array_guard(Node* kls, RegionNode* region) {
185     return generate_array_guard_common(kls, region, NonArray);
186   }
187   Node* generate_objArray_guard(Node* kls, RegionNode* region) {
188     return generate_array_guard_common(kls, region, ObjectArray);
189   }
190   Node* generate_non_objArray_guard(Node* kls, RegionNode* region) {
191     return generate_array_guard_common(kls, region, NonObjectArray);
192   }
193   Node* generate_typeArray_guard(Node* kls, RegionNode* region) {
194     return generate_array_guard_common(kls, region, TypeArray);
195   }
196   Node* generate_flatArray_guard(Node* kls, RegionNode* region) {
197     assert(UseFlatArray, "can never be flattened");
198     return generate_array_guard_common(kls, region, FlatArray);
199   }
200   Node* generate_non_flatArray_guard(Node* kls, RegionNode* region) {
201     assert(UseFlatArray, "can never be flattened");
202     return generate_array_guard_common(kls, region, NonFlatArray);
203   }
204   Node* generate_array_guard_common(Node* kls, RegionNode* region, ArrayKind kind);

205   Node* generate_virtual_guard(Node* obj_klass, RegionNode* slow_region);
206   CallJavaNode* generate_method_call(vmIntrinsics::ID method_id,
207                                      bool is_virtual = false, bool is_static = false);
208   CallJavaNode* generate_method_call_static(vmIntrinsics::ID method_id) {
209     return generate_method_call(method_id, false, true);
210   }
211   CallJavaNode* generate_method_call_virtual(vmIntrinsics::ID method_id) {
212     return generate_method_call(method_id, true, false);
213   }
214   Node* load_field_from_object(Node* fromObj, const char* fieldName, const char* fieldTypeString, DecoratorSet decorators, bool is_static, ciInstanceKlass* fromKls);
215   Node* field_address_from_object(Node* fromObj, const char* fieldName, const char* fieldTypeString, bool is_exact, bool is_static, ciInstanceKlass* fromKls);
216 
217   Node* make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2, StrIntrinsicNode::ArgEnc ae);
218   bool inline_string_compareTo(StrIntrinsicNode::ArgEnc ae);
219   bool inline_string_indexOf(StrIntrinsicNode::ArgEnc ae);
220   bool inline_string_indexOfI(StrIntrinsicNode::ArgEnc ae);
221   Node* make_indexOf_node(Node* src_start, Node* src_count, Node* tgt_start, Node* tgt_count,
222                           RegionNode* region, Node* phi, StrIntrinsicNode::ArgEnc ae);
223   bool inline_string_indexOfChar(StrIntrinsicNode::ArgEnc ae);
224   bool inline_string_equals(StrIntrinsicNode::ArgEnc ae);

243   bool inline_math_negateExactI();
244   bool inline_math_negateExactL();
245   bool inline_math_subtractExactI(bool is_decrement);
246   bool inline_math_subtractExactL(bool is_decrement);
247   bool inline_min_max(vmIntrinsics::ID id);
248   bool inline_notify(vmIntrinsics::ID id);
249   Node* generate_min_max(vmIntrinsics::ID id, Node* x, Node* y);
250   // This returns Type::AnyPtr, RawPtr, or OopPtr.
251   int classify_unsafe_addr(Node* &base, Node* &offset, BasicType type);
252   Node* make_unsafe_address(Node*& base, Node* offset, BasicType type = T_ILLEGAL, bool can_cast = false);
253 
254   typedef enum { Relaxed, Opaque, Volatile, Acquire, Release } AccessKind;
255   DecoratorSet mo_decorator_for_access_kind(AccessKind kind);
256   bool inline_unsafe_access(bool is_store, BasicType type, AccessKind kind, bool is_unaligned);
257   static bool klass_needs_init_guard(Node* kls);
258   bool inline_unsafe_allocate();
259   bool inline_unsafe_newArray(bool uninitialized);
260   bool inline_unsafe_writeback0();
261   bool inline_unsafe_writebackSync0(bool is_pre);
262   bool inline_unsafe_copyMemory();
263   bool inline_unsafe_make_private_buffer();
264   bool inline_unsafe_finish_private_buffer();
265   bool inline_native_currentThread();
266 
267   bool inline_native_time_funcs(address method, const char* funcName);
268 #ifdef JFR_HAVE_INTRINSICS
269   bool inline_native_classID();
270   bool inline_native_getEventWriter();
271 #endif
272   bool inline_native_Class_query(vmIntrinsics::ID id);
273   bool inline_primitive_Class_conversion(vmIntrinsics::ID id);
274   bool inline_native_subtype_check();
275   bool inline_native_getLength();
276   bool inline_array_copyOf(bool is_copyOfRange);
277   bool inline_array_equals(StrIntrinsicNode::ArgEnc ae);
278   bool inline_preconditions_checkIndex(BasicType bt);
279   void copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array);
280   bool inline_native_clone(bool is_virtual);
281   bool inline_native_Reflection_getCallerClass();
282   // Helper function for inlining native object hash method
283   bool inline_native_hashcode(bool is_virtual, bool is_static);
284   bool inline_native_getClass();
285 
286   // Helper functions for inlining arraycopy
287   bool inline_arraycopy();
288   AllocateArrayNode* tightly_coupled_allocation(Node* ptr);
289   JVMState* arraycopy_restore_alloc_state(AllocateArrayNode* alloc, int& saved_reexecute_sp);
290   void arraycopy_move_allocation_here(AllocateArrayNode* alloc, Node* dest, JVMState* saved_jvms, int saved_reexecute_sp,
291                                       uint new_idx);
292 
293   typedef enum { LS_get_add, LS_get_set, LS_cmp_swap, LS_cmp_swap_weak, LS_cmp_exchange } LoadStoreKind;
< prev index next >