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 = nullptr;
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() != nullptr) {
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 == nullptr, "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 = nullptr);
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* current_thread_helper(Node* &tls_output, ByteSize handle_offset,
138 bool is_immutable);
139 Node* generate_current_thread(Node* &tls_output);
140 Node* generate_virtual_thread(Node* threadObj);
141 Node* load_mirror_from_klass(Node* klass);
142 Node* load_klass_from_mirror_common(Node* mirror, bool never_see_null,
143 RegionNode* region, int null_path,
144 int offset);
145 Node* load_klass_from_mirror(Node* mirror, bool never_see_null,
146 RegionNode* region, int null_path) {
147 int offset = java_lang_Class::klass_offset();
148 return load_klass_from_mirror_common(mirror, never_see_null,
149 region, null_path,
150 offset);
151 }
152 Node* load_array_klass_from_mirror(Node* mirror, bool never_see_null,
153 RegionNode* region, int null_path) {
154 int offset = java_lang_Class::array_klass_offset();
155 return load_klass_from_mirror_common(mirror, never_see_null,
156 region, null_path,
157 offset);
158 }
159 Node* generate_access_flags_guard(Node* kls,
160 int modifier_mask, int modifier_bits,
161 RegionNode* region);
162 Node* generate_interface_guard(Node* kls, RegionNode* region);
163 Node* generate_hidden_class_guard(Node* kls, RegionNode* region);
164 Node* generate_array_guard(Node* kls, RegionNode* region) {
165 return generate_array_guard_common(kls, region, false, false);
166 }
167 Node* generate_non_array_guard(Node* kls, RegionNode* region) {
168 return generate_array_guard_common(kls, region, false, true);
169 }
170 Node* generate_objArray_guard(Node* kls, RegionNode* region) {
171 return generate_array_guard_common(kls, region, true, false);
172 }
173 Node* generate_non_objArray_guard(Node* kls, RegionNode* region) {
174 return generate_array_guard_common(kls, region, true, true);
175 }
176 Node* generate_array_guard_common(Node* kls, RegionNode* region,
177 bool obj_array, bool not_array);
178 Node* generate_virtual_guard(Node* obj_klass, RegionNode* slow_region);
179 CallJavaNode* generate_method_call(vmIntrinsicID method_id, bool is_virtual, bool is_static, bool res_not_null);
180 CallJavaNode* generate_method_call_static(vmIntrinsicID method_id, bool res_not_null) {
181 return generate_method_call(method_id, false, true, res_not_null);
182 }
183 Node* load_field_from_object(Node* fromObj, const char* fieldName, const char* fieldTypeString, DecoratorSet decorators = IN_HEAP, bool is_static = false, ciInstanceKlass* fromKls = nullptr);
184 Node* field_address_from_object(Node* fromObj, const char* fieldName, const char* fieldTypeString, bool is_exact = true, bool is_static = false, ciInstanceKlass* fromKls = nullptr);
185
186 Node* make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2, StrIntrinsicNode::ArgEnc ae);
187 bool inline_string_compareTo(StrIntrinsicNode::ArgEnc ae);
188 bool inline_string_indexOf(StrIntrinsicNode::ArgEnc ae);
189 bool inline_string_indexOfI(StrIntrinsicNode::ArgEnc ae);
190 Node* make_indexOf_node(Node* src_start, Node* src_count, Node* tgt_start, Node* tgt_count,
191 RegionNode* region, Node* phi, StrIntrinsicNode::ArgEnc ae);
192 bool inline_string_indexOfChar(StrIntrinsicNode::ArgEnc ae);
193 bool inline_string_equals(StrIntrinsicNode::ArgEnc ae);
194 bool inline_vectorizedHashCode();
195 bool inline_string_toBytesU();
196 bool inline_string_getCharsU();
197 bool inline_string_copy(bool compress);
207 void inline_math_mathExact(Node* math, Node* test);
208 bool inline_math_addExactI(bool is_increment);
209 bool inline_math_addExactL(bool is_increment);
210 bool inline_math_multiplyExactI();
211 bool inline_math_multiplyExactL();
212 bool inline_math_multiplyHigh();
213 bool inline_math_unsignedMultiplyHigh();
214 bool inline_math_negateExactI();
215 bool inline_math_negateExactL();
216 bool inline_math_subtractExactI(bool is_decrement);
217 bool inline_math_subtractExactL(bool is_decrement);
218 bool inline_min_max(vmIntrinsics::ID id);
219 bool inline_notify(vmIntrinsics::ID id);
220 Node* generate_min_max(vmIntrinsics::ID id, Node* x, Node* y);
221 // This returns Type::AnyPtr, RawPtr, or OopPtr.
222 int classify_unsafe_addr(Node* &base, Node* &offset, BasicType type);
223 Node* make_unsafe_address(Node*& base, Node* offset, BasicType type = T_ILLEGAL, bool can_cast = false);
224
225 typedef enum { Relaxed, Opaque, Volatile, Acquire, Release } AccessKind;
226 DecoratorSet mo_decorator_for_access_kind(AccessKind kind);
227 bool inline_unsafe_access(bool is_store, BasicType type, AccessKind kind, bool is_unaligned);
228 static bool klass_needs_init_guard(Node* kls);
229 bool inline_unsafe_allocate();
230 bool inline_unsafe_newArray(bool uninitialized);
231 bool inline_unsafe_writeback0();
232 bool inline_unsafe_writebackSync0(bool is_pre);
233 bool inline_unsafe_copyMemory();
234 bool inline_unsafe_setMemory();
235
236 bool inline_native_currentCarrierThread();
237 bool inline_native_currentThread();
238 bool inline_native_setCurrentThread();
239
240 bool inline_native_scopedValueCache();
241 const Type* scopedValueCache_type();
242 Node* scopedValueCache_helper();
243 bool inline_native_setScopedValueCache();
244
245 bool inline_native_time_funcs(address method, const char* funcName);
246 #if INCLUDE_JVMTI
247 bool inline_native_notify_jvmti_funcs(address funcAddr, const char* funcName, bool is_start, bool is_end);
248 bool inline_native_notify_jvmti_hide();
249 bool inline_native_notify_jvmti_sync();
250 #endif
251
252 #ifdef JFR_HAVE_INTRINSICS
253 bool inline_native_classID();
254 bool inline_native_getEventWriter();
255 bool inline_native_jvm_commit();
256 void extend_setCurrentThread(Node* jt, Node* thread);
257 #endif
258 bool inline_native_Class_query(vmIntrinsics::ID id);
259 bool inline_native_subtype_check();
260 bool inline_native_getLength();
261 bool inline_array_copyOf(bool is_copyOfRange);
262 bool inline_array_equals(StrIntrinsicNode::ArgEnc ae);
263 bool inline_preconditions_checkIndex(BasicType bt);
264 void copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array);
265 bool inline_native_clone(bool is_virtual);
266 bool inline_native_Reflection_getCallerClass();
267 // Helper function for inlining native object hash method
268 bool inline_native_hashcode(bool is_virtual, bool is_static);
269 bool inline_native_getClass();
270
271 // Helper functions for inlining arraycopy
272 bool inline_arraycopy();
273 AllocateArrayNode* tightly_coupled_allocation(Node* ptr);
274 static CallStaticJavaNode* get_uncommon_trap_from_success_proj(Node* node);
275 SafePointNode* create_safepoint_with_state_before_array_allocation(const AllocateArrayNode* alloc) const;
276 void replace_unrelated_uncommon_traps_with_alloc_state(AllocateArrayNode* alloc, JVMState* saved_jvms_before_guards);
277 void replace_unrelated_uncommon_traps_with_alloc_state(JVMState* saved_jvms_before_guards);
278 void create_new_uncommon_trap(CallStaticJavaNode* uncommon_trap_call);
|
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 = nullptr;
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 != nullptr) {
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 == nullptr, "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 = nullptr);
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* current_thread_helper(Node* &tls_output, ByteSize handle_offset,
147 bool is_immutable);
148 Node* generate_current_thread(Node* &tls_output);
149 Node* generate_virtual_thread(Node* threadObj);
150 Node* load_klass_from_mirror_common(Node* mirror, bool never_see_null,
151 RegionNode* region, int null_path,
152 int offset);
153 Node* load_klass_from_mirror(Node* mirror, bool never_see_null,
154 RegionNode* region, int null_path) {
155 int offset = java_lang_Class::klass_offset();
156 return load_klass_from_mirror_common(mirror, never_see_null,
157 region, null_path,
158 offset);
159 }
160 Node* load_array_klass_from_mirror(Node* mirror, bool never_see_null,
161 RegionNode* region, int null_path) {
162 int offset = java_lang_Class::array_klass_offset();
163 return load_klass_from_mirror_common(mirror, never_see_null,
164 region, null_path,
165 offset);
166 }
167 Node* generate_access_flags_guard(Node* kls,
168 int modifier_mask, int modifier_bits,
169 RegionNode* region);
170 Node* generate_interface_guard(Node* kls, RegionNode* region);
171
172 enum ArrayKind {
173 AnyArray,
174 NonArray,
175 ObjectArray,
176 NonObjectArray,
177 TypeArray
178 };
179
180 Node* generate_hidden_class_guard(Node* kls, RegionNode* region);
181
182 Node* generate_array_guard(Node* kls, RegionNode* region) {
183 return generate_array_guard_common(kls, region, AnyArray);
184 }
185 Node* generate_non_array_guard(Node* kls, RegionNode* region) {
186 return generate_array_guard_common(kls, region, NonArray);
187 }
188 Node* generate_objArray_guard(Node* kls, RegionNode* region) {
189 return generate_array_guard_common(kls, region, ObjectArray);
190 }
191 Node* generate_non_objArray_guard(Node* kls, RegionNode* region) {
192 return generate_array_guard_common(kls, region, NonObjectArray);
193 }
194 Node* generate_typeArray_guard(Node* kls, RegionNode* region) {
195 return generate_array_guard_common(kls, region, TypeArray);
196 }
197 Node* generate_array_guard_common(Node* kls, RegionNode* region, ArrayKind kind);
198 Node* generate_virtual_guard(Node* obj_klass, RegionNode* slow_region);
199 CallJavaNode* generate_method_call(vmIntrinsicID method_id, bool is_virtual, bool is_static, bool res_not_null);
200 CallJavaNode* generate_method_call_static(vmIntrinsicID method_id, bool res_not_null) {
201 return generate_method_call(method_id, false, true, res_not_null);
202 }
203 Node* load_field_from_object(Node* fromObj, const char* fieldName, const char* fieldTypeString, DecoratorSet decorators = IN_HEAP, bool is_static = false, ciInstanceKlass* fromKls = nullptr);
204 Node* field_address_from_object(Node* fromObj, const char* fieldName, const char* fieldTypeString, bool is_exact = true, bool is_static = false, ciInstanceKlass* fromKls = nullptr);
205
206 Node* make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2, StrIntrinsicNode::ArgEnc ae);
207 bool inline_string_compareTo(StrIntrinsicNode::ArgEnc ae);
208 bool inline_string_indexOf(StrIntrinsicNode::ArgEnc ae);
209 bool inline_string_indexOfI(StrIntrinsicNode::ArgEnc ae);
210 Node* make_indexOf_node(Node* src_start, Node* src_count, Node* tgt_start, Node* tgt_count,
211 RegionNode* region, Node* phi, StrIntrinsicNode::ArgEnc ae);
212 bool inline_string_indexOfChar(StrIntrinsicNode::ArgEnc ae);
213 bool inline_string_equals(StrIntrinsicNode::ArgEnc ae);
214 bool inline_vectorizedHashCode();
215 bool inline_string_toBytesU();
216 bool inline_string_getCharsU();
217 bool inline_string_copy(bool compress);
227 void inline_math_mathExact(Node* math, Node* test);
228 bool inline_math_addExactI(bool is_increment);
229 bool inline_math_addExactL(bool is_increment);
230 bool inline_math_multiplyExactI();
231 bool inline_math_multiplyExactL();
232 bool inline_math_multiplyHigh();
233 bool inline_math_unsignedMultiplyHigh();
234 bool inline_math_negateExactI();
235 bool inline_math_negateExactL();
236 bool inline_math_subtractExactI(bool is_decrement);
237 bool inline_math_subtractExactL(bool is_decrement);
238 bool inline_min_max(vmIntrinsics::ID id);
239 bool inline_notify(vmIntrinsics::ID id);
240 Node* generate_min_max(vmIntrinsics::ID id, Node* x, Node* y);
241 // This returns Type::AnyPtr, RawPtr, or OopPtr.
242 int classify_unsafe_addr(Node* &base, Node* &offset, BasicType type);
243 Node* make_unsafe_address(Node*& base, Node* offset, BasicType type = T_ILLEGAL, bool can_cast = false);
244
245 typedef enum { Relaxed, Opaque, Volatile, Acquire, Release } AccessKind;
246 DecoratorSet mo_decorator_for_access_kind(AccessKind kind);
247 bool inline_unsafe_access(bool is_store, BasicType type, AccessKind kind, bool is_unaligned, bool is_flat = false);
248 static bool klass_needs_init_guard(Node* kls);
249 bool inline_unsafe_allocate();
250 bool inline_unsafe_newArray(bool uninitialized);
251 bool inline_newNullRestrictedArray();
252 bool inline_unsafe_writeback0();
253 bool inline_unsafe_writebackSync0(bool is_pre);
254 bool inline_unsafe_copyMemory();
255 bool inline_unsafe_isFlatArray();
256 bool inline_unsafe_make_private_buffer();
257 bool inline_unsafe_finish_private_buffer();
258 bool inline_unsafe_setMemory();
259
260 bool inline_native_currentCarrierThread();
261 bool inline_native_currentThread();
262 bool inline_native_setCurrentThread();
263
264 bool inline_native_scopedValueCache();
265 const Type* scopedValueCache_type();
266 Node* scopedValueCache_helper();
267 bool inline_native_setScopedValueCache();
268
269 bool inline_native_time_funcs(address method, const char* funcName);
270 #if INCLUDE_JVMTI
271 bool inline_native_notify_jvmti_funcs(address funcAddr, const char* funcName, bool is_start, bool is_end);
272 bool inline_native_notify_jvmti_hide();
273 bool inline_native_notify_jvmti_sync();
274 #endif
275
276 #ifdef JFR_HAVE_INTRINSICS
277 bool inline_native_classID();
278 bool inline_native_getEventWriter();
279 bool inline_native_jvm_commit();
280 void extend_setCurrentThread(Node* jt, Node* thread);
281 #endif
282 bool inline_native_Class_query(vmIntrinsics::ID id);
283 bool inline_primitive_Class_conversion(vmIntrinsics::ID id);
284 bool inline_native_subtype_check();
285 bool inline_native_getLength();
286 bool inline_array_copyOf(bool is_copyOfRange);
287 bool inline_array_equals(StrIntrinsicNode::ArgEnc ae);
288 bool inline_preconditions_checkIndex(BasicType bt);
289 void copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array);
290 bool inline_native_clone(bool is_virtual);
291 bool inline_native_Reflection_getCallerClass();
292 // Helper function for inlining native object hash method
293 bool inline_native_hashcode(bool is_virtual, bool is_static);
294 bool inline_native_getClass();
295
296 // Helper functions for inlining arraycopy
297 bool inline_arraycopy();
298 AllocateArrayNode* tightly_coupled_allocation(Node* ptr);
299 static CallStaticJavaNode* get_uncommon_trap_from_success_proj(Node* node);
300 SafePointNode* create_safepoint_with_state_before_array_allocation(const AllocateArrayNode* alloc) const;
301 void replace_unrelated_uncommon_traps_with_alloc_state(AllocateArrayNode* alloc, JVMState* saved_jvms_before_guards);
302 void replace_unrelated_uncommon_traps_with_alloc_state(JVMState* saved_jvms_before_guards);
303 void create_new_uncommon_trap(CallStaticJavaNode* uncommon_trap_call);
|