Thu, 28 Jun 2012 17:03:16 -0400
6995781: Native Memory Tracking (Phase 1)
7151532: DCmd for hotspot native memory tracking
Summary: Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd
Reviewed-by: acorn, coleenp, fparain
1 /*
2 * Copyright (c) 1999, 2012, 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 */
25 #include "precompiled.hpp"
26 #include "classfile/systemDictionary.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "compiler/compileBroker.hpp"
29 #include "compiler/compileLog.hpp"
30 #include "oops/objArrayKlass.hpp"
31 #include "opto/addnode.hpp"
32 #include "opto/callGenerator.hpp"
33 #include "opto/cfgnode.hpp"
34 #include "opto/idealKit.hpp"
35 #include "opto/mulnode.hpp"
36 #include "opto/parse.hpp"
37 #include "opto/runtime.hpp"
38 #include "opto/subnode.hpp"
39 #include "prims/nativeLookup.hpp"
40 #include "runtime/sharedRuntime.hpp"
42 class LibraryIntrinsic : public InlineCallGenerator {
43 // Extend the set of intrinsics known to the runtime:
44 public:
45 private:
46 bool _is_virtual;
47 vmIntrinsics::ID _intrinsic_id;
49 public:
50 LibraryIntrinsic(ciMethod* m, bool is_virtual, vmIntrinsics::ID id)
51 : InlineCallGenerator(m),
52 _is_virtual(is_virtual),
53 _intrinsic_id(id)
54 {
55 }
56 virtual bool is_intrinsic() const { return true; }
57 virtual bool is_virtual() const { return _is_virtual; }
58 virtual JVMState* generate(JVMState* jvms);
59 vmIntrinsics::ID intrinsic_id() const { return _intrinsic_id; }
60 };
63 // Local helper class for LibraryIntrinsic:
64 class LibraryCallKit : public GraphKit {
65 private:
66 LibraryIntrinsic* _intrinsic; // the library intrinsic being called
68 public:
69 LibraryCallKit(JVMState* caller, LibraryIntrinsic* intrinsic)
70 : GraphKit(caller),
71 _intrinsic(intrinsic)
72 {
73 }
75 ciMethod* caller() const { return jvms()->method(); }
76 int bci() const { return jvms()->bci(); }
77 LibraryIntrinsic* intrinsic() const { return _intrinsic; }
78 vmIntrinsics::ID intrinsic_id() const { return _intrinsic->intrinsic_id(); }
79 ciMethod* callee() const { return _intrinsic->method(); }
80 ciSignature* signature() const { return callee()->signature(); }
81 int arg_size() const { return callee()->arg_size(); }
83 bool try_to_inline();
85 // Helper functions to inline natives
86 void push_result(RegionNode* region, PhiNode* value);
87 Node* generate_guard(Node* test, RegionNode* region, float true_prob);
88 Node* generate_slow_guard(Node* test, RegionNode* region);
89 Node* generate_fair_guard(Node* test, RegionNode* region);
90 Node* generate_negative_guard(Node* index, RegionNode* region,
91 // resulting CastII of index:
92 Node* *pos_index = NULL);
93 Node* generate_nonpositive_guard(Node* index, bool never_negative,
94 // resulting CastII of index:
95 Node* *pos_index = NULL);
96 Node* generate_limit_guard(Node* offset, Node* subseq_length,
97 Node* array_length,
98 RegionNode* region);
99 Node* generate_current_thread(Node* &tls_output);
100 address basictype2arraycopy(BasicType t, Node *src_offset, Node *dest_offset,
101 bool disjoint_bases, const char* &name, bool dest_uninitialized);
102 Node* load_mirror_from_klass(Node* klass);
103 Node* load_klass_from_mirror_common(Node* mirror, bool never_see_null,
104 int nargs,
105 RegionNode* region, int null_path,
106 int offset);
107 Node* load_klass_from_mirror(Node* mirror, bool never_see_null, int nargs,
108 RegionNode* region, int null_path) {
109 int offset = java_lang_Class::klass_offset_in_bytes();
110 return load_klass_from_mirror_common(mirror, never_see_null, nargs,
111 region, null_path,
112 offset);
113 }
114 Node* load_array_klass_from_mirror(Node* mirror, bool never_see_null,
115 int nargs,
116 RegionNode* region, int null_path) {
117 int offset = java_lang_Class::array_klass_offset_in_bytes();
118 return load_klass_from_mirror_common(mirror, never_see_null, nargs,
119 region, null_path,
120 offset);
121 }
122 Node* generate_access_flags_guard(Node* kls,
123 int modifier_mask, int modifier_bits,
124 RegionNode* region);
125 Node* generate_interface_guard(Node* kls, RegionNode* region);
126 Node* generate_array_guard(Node* kls, RegionNode* region) {
127 return generate_array_guard_common(kls, region, false, false);
128 }
129 Node* generate_non_array_guard(Node* kls, RegionNode* region) {
130 return generate_array_guard_common(kls, region, false, true);
131 }
132 Node* generate_objArray_guard(Node* kls, RegionNode* region) {
133 return generate_array_guard_common(kls, region, true, false);
134 }
135 Node* generate_non_objArray_guard(Node* kls, RegionNode* region) {
136 return generate_array_guard_common(kls, region, true, true);
137 }
138 Node* generate_array_guard_common(Node* kls, RegionNode* region,
139 bool obj_array, bool not_array);
140 Node* generate_virtual_guard(Node* obj_klass, RegionNode* slow_region);
141 CallJavaNode* generate_method_call(vmIntrinsics::ID method_id,
142 bool is_virtual = false, bool is_static = false);
143 CallJavaNode* generate_method_call_static(vmIntrinsics::ID method_id) {
144 return generate_method_call(method_id, false, true);
145 }
146 CallJavaNode* generate_method_call_virtual(vmIntrinsics::ID method_id) {
147 return generate_method_call(method_id, true, false);
148 }
150 Node* make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2);
151 Node* make_string_method_node(int opcode, Node* str1, Node* str2);
152 bool inline_string_compareTo();
153 bool inline_string_indexOf();
154 Node* string_indexOf(Node* string_object, ciTypeArray* target_array, jint offset, jint cache_i, jint md2_i);
155 bool inline_string_equals();
156 Node* pop_math_arg();
157 bool runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName);
158 bool inline_math_native(vmIntrinsics::ID id);
159 bool inline_trig(vmIntrinsics::ID id);
160 bool inline_trans(vmIntrinsics::ID id);
161 bool inline_abs(vmIntrinsics::ID id);
162 bool inline_sqrt(vmIntrinsics::ID id);
163 bool inline_pow(vmIntrinsics::ID id);
164 bool inline_exp(vmIntrinsics::ID id);
165 bool inline_min_max(vmIntrinsics::ID id);
166 Node* generate_min_max(vmIntrinsics::ID id, Node* x, Node* y);
167 // This returns Type::AnyPtr, RawPtr, or OopPtr.
168 int classify_unsafe_addr(Node* &base, Node* &offset);
169 Node* make_unsafe_address(Node* base, Node* offset);
170 // Helper for inline_unsafe_access.
171 // Generates the guards that check whether the result of
172 // Unsafe.getObject should be recorded in an SATB log buffer.
173 void insert_g1_pre_barrier(Node* base_oop, Node* offset, Node* pre_val);
174 bool inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile);
175 bool inline_unsafe_prefetch(bool is_native_ptr, bool is_store, bool is_static);
176 bool inline_unsafe_allocate();
177 bool inline_unsafe_copyMemory();
178 bool inline_native_currentThread();
179 #ifdef TRACE_HAVE_INTRINSICS
180 bool inline_native_classID();
181 bool inline_native_threadID();
182 #endif
183 bool inline_native_time_funcs(address method, const char* funcName);
184 bool inline_native_isInterrupted();
185 bool inline_native_Class_query(vmIntrinsics::ID id);
186 bool inline_native_subtype_check();
188 bool inline_native_newArray();
189 bool inline_native_getLength();
190 bool inline_array_copyOf(bool is_copyOfRange);
191 bool inline_array_equals();
192 void copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array, bool card_mark);
193 bool inline_native_clone(bool is_virtual);
194 bool inline_native_Reflection_getCallerClass();
195 bool is_method_invoke_or_aux_frame(JVMState* jvms);
196 // Helper function for inlining native object hash method
197 bool inline_native_hashcode(bool is_virtual, bool is_static);
198 bool inline_native_getClass();
200 // Helper functions for inlining arraycopy
201 bool inline_arraycopy();
202 void generate_arraycopy(const TypePtr* adr_type,
203 BasicType basic_elem_type,
204 Node* src, Node* src_offset,
205 Node* dest, Node* dest_offset,
206 Node* copy_length,
207 bool disjoint_bases = false,
208 bool length_never_negative = false,
209 RegionNode* slow_region = NULL);
210 AllocateArrayNode* tightly_coupled_allocation(Node* ptr,
211 RegionNode* slow_region);
212 void generate_clear_array(const TypePtr* adr_type,
213 Node* dest,
214 BasicType basic_elem_type,
215 Node* slice_off,
216 Node* slice_len,
217 Node* slice_end);
218 bool generate_block_arraycopy(const TypePtr* adr_type,
219 BasicType basic_elem_type,
220 AllocateNode* alloc,
221 Node* src, Node* src_offset,
222 Node* dest, Node* dest_offset,
223 Node* dest_size, bool dest_uninitialized);
224 void generate_slow_arraycopy(const TypePtr* adr_type,
225 Node* src, Node* src_offset,
226 Node* dest, Node* dest_offset,
227 Node* copy_length, bool dest_uninitialized);
228 Node* generate_checkcast_arraycopy(const TypePtr* adr_type,
229 Node* dest_elem_klass,
230 Node* src, Node* src_offset,
231 Node* dest, Node* dest_offset,
232 Node* copy_length, bool dest_uninitialized);
233 Node* generate_generic_arraycopy(const TypePtr* adr_type,
234 Node* src, Node* src_offset,
235 Node* dest, Node* dest_offset,
236 Node* copy_length, bool dest_uninitialized);
237 void generate_unchecked_arraycopy(const TypePtr* adr_type,
238 BasicType basic_elem_type,
239 bool disjoint_bases,
240 Node* src, Node* src_offset,
241 Node* dest, Node* dest_offset,
242 Node* copy_length, bool dest_uninitialized);
243 bool inline_unsafe_CAS(BasicType type);
244 bool inline_unsafe_ordered_store(BasicType type);
245 bool inline_fp_conversions(vmIntrinsics::ID id);
246 bool inline_numberOfLeadingZeros(vmIntrinsics::ID id);
247 bool inline_numberOfTrailingZeros(vmIntrinsics::ID id);
248 bool inline_bitCount(vmIntrinsics::ID id);
249 bool inline_reverseBytes(vmIntrinsics::ID id);
251 bool inline_reference_get();
252 };
255 //---------------------------make_vm_intrinsic----------------------------
256 CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) {
257 vmIntrinsics::ID id = m->intrinsic_id();
258 assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
260 if (DisableIntrinsic[0] != '\0'
261 && strstr(DisableIntrinsic, vmIntrinsics::name_at(id)) != NULL) {
262 // disabled by a user request on the command line:
263 // example: -XX:DisableIntrinsic=_hashCode,_getClass
264 return NULL;
265 }
267 if (!m->is_loaded()) {
268 // do not attempt to inline unloaded methods
269 return NULL;
270 }
272 // Only a few intrinsics implement a virtual dispatch.
273 // They are expensive calls which are also frequently overridden.
274 if (is_virtual) {
275 switch (id) {
276 case vmIntrinsics::_hashCode:
277 case vmIntrinsics::_clone:
278 // OK, Object.hashCode and Object.clone intrinsics come in both flavors
279 break;
280 default:
281 return NULL;
282 }
283 }
285 // -XX:-InlineNatives disables nearly all intrinsics:
286 if (!InlineNatives) {
287 switch (id) {
288 case vmIntrinsics::_indexOf:
289 case vmIntrinsics::_compareTo:
290 case vmIntrinsics::_equals:
291 case vmIntrinsics::_equalsC:
292 break; // InlineNatives does not control String.compareTo
293 default:
294 return NULL;
295 }
296 }
298 switch (id) {
299 case vmIntrinsics::_compareTo:
300 if (!SpecialStringCompareTo) return NULL;
301 break;
302 case vmIntrinsics::_indexOf:
303 if (!SpecialStringIndexOf) return NULL;
304 break;
305 case vmIntrinsics::_equals:
306 if (!SpecialStringEquals) return NULL;
307 break;
308 case vmIntrinsics::_equalsC:
309 if (!SpecialArraysEquals) return NULL;
310 break;
311 case vmIntrinsics::_arraycopy:
312 if (!InlineArrayCopy) return NULL;
313 break;
314 case vmIntrinsics::_copyMemory:
315 if (StubRoutines::unsafe_arraycopy() == NULL) return NULL;
316 if (!InlineArrayCopy) return NULL;
317 break;
318 case vmIntrinsics::_hashCode:
319 if (!InlineObjectHash) return NULL;
320 break;
321 case vmIntrinsics::_clone:
322 case vmIntrinsics::_copyOf:
323 case vmIntrinsics::_copyOfRange:
324 if (!InlineObjectCopy) return NULL;
325 // These also use the arraycopy intrinsic mechanism:
326 if (!InlineArrayCopy) return NULL;
327 break;
328 case vmIntrinsics::_checkIndex:
329 // We do not intrinsify this. The optimizer does fine with it.
330 return NULL;
332 case vmIntrinsics::_getCallerClass:
333 if (!UseNewReflection) return NULL;
334 if (!InlineReflectionGetCallerClass) return NULL;
335 if (!JDK_Version::is_gte_jdk14x_version()) return NULL;
336 break;
338 case vmIntrinsics::_bitCount_i:
339 if (!Matcher::match_rule_supported(Op_PopCountI)) return NULL;
340 break;
342 case vmIntrinsics::_bitCount_l:
343 if (!Matcher::match_rule_supported(Op_PopCountL)) return NULL;
344 break;
346 case vmIntrinsics::_numberOfLeadingZeros_i:
347 if (!Matcher::match_rule_supported(Op_CountLeadingZerosI)) return NULL;
348 break;
350 case vmIntrinsics::_numberOfLeadingZeros_l:
351 if (!Matcher::match_rule_supported(Op_CountLeadingZerosL)) return NULL;
352 break;
354 case vmIntrinsics::_numberOfTrailingZeros_i:
355 if (!Matcher::match_rule_supported(Op_CountTrailingZerosI)) return NULL;
356 break;
358 case vmIntrinsics::_numberOfTrailingZeros_l:
359 if (!Matcher::match_rule_supported(Op_CountTrailingZerosL)) return NULL;
360 break;
362 case vmIntrinsics::_Reference_get:
363 // It is only when G1 is enabled that we absolutely
364 // need to use the intrinsic version of Reference.get()
365 // so that the value in the referent field, if necessary,
366 // can be registered by the pre-barrier code.
367 if (!UseG1GC) return NULL;
368 break;
370 default:
371 assert(id <= vmIntrinsics::LAST_COMPILER_INLINE, "caller responsibility");
372 assert(id != vmIntrinsics::_Object_init && id != vmIntrinsics::_invoke, "enum out of order?");
373 break;
374 }
376 // -XX:-InlineClassNatives disables natives from the Class class.
377 // The flag applies to all reflective calls, notably Array.newArray
378 // (visible to Java programmers as Array.newInstance).
379 if (m->holder()->name() == ciSymbol::java_lang_Class() ||
380 m->holder()->name() == ciSymbol::java_lang_reflect_Array()) {
381 if (!InlineClassNatives) return NULL;
382 }
384 // -XX:-InlineThreadNatives disables natives from the Thread class.
385 if (m->holder()->name() == ciSymbol::java_lang_Thread()) {
386 if (!InlineThreadNatives) return NULL;
387 }
389 // -XX:-InlineMathNatives disables natives from the Math,Float and Double classes.
390 if (m->holder()->name() == ciSymbol::java_lang_Math() ||
391 m->holder()->name() == ciSymbol::java_lang_Float() ||
392 m->holder()->name() == ciSymbol::java_lang_Double()) {
393 if (!InlineMathNatives) return NULL;
394 }
396 // -XX:-InlineUnsafeOps disables natives from the Unsafe class.
397 if (m->holder()->name() == ciSymbol::sun_misc_Unsafe()) {
398 if (!InlineUnsafeOps) return NULL;
399 }
401 return new LibraryIntrinsic(m, is_virtual, (vmIntrinsics::ID) id);
402 }
404 //----------------------register_library_intrinsics-----------------------
405 // Initialize this file's data structures, for each Compile instance.
406 void Compile::register_library_intrinsics() {
407 // Nothing to do here.
408 }
410 JVMState* LibraryIntrinsic::generate(JVMState* jvms) {
411 LibraryCallKit kit(jvms, this);
412 Compile* C = kit.C;
413 int nodes = C->unique();
414 #ifndef PRODUCT
415 if ((PrintIntrinsics || PrintInlining NOT_PRODUCT( || PrintOptoInlining) ) && Verbose) {
416 char buf[1000];
417 const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf));
418 tty->print_cr("Intrinsic %s", str);
419 }
420 #endif
422 if (kit.try_to_inline()) {
423 if (PrintIntrinsics || PrintInlining NOT_PRODUCT( || PrintOptoInlining) ) {
424 CompileTask::print_inlining(kit.callee(), jvms->depth() - 1, kit.bci(), is_virtual() ? "(intrinsic, virtual)" : "(intrinsic)");
425 }
426 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked);
427 if (C->log()) {
428 C->log()->elem("intrinsic id='%s'%s nodes='%d'",
429 vmIntrinsics::name_at(intrinsic_id()),
430 (is_virtual() ? " virtual='1'" : ""),
431 C->unique() - nodes);
432 }
433 return kit.transfer_exceptions_into_jvms();
434 }
436 // The intrinsic bailed out
437 if (PrintIntrinsics || PrintInlining NOT_PRODUCT( || PrintOptoInlining) ) {
438 if (jvms->has_method()) {
439 // Not a root compile.
440 const char* msg = is_virtual() ? "failed to inline (intrinsic, virtual)" : "failed to inline (intrinsic)";
441 CompileTask::print_inlining(kit.callee(), jvms->depth() - 1, kit.bci(), msg);
442 } else {
443 // Root compile
444 tty->print("Did not generate intrinsic %s%s at bci:%d in",
445 vmIntrinsics::name_at(intrinsic_id()),
446 (is_virtual() ? " (virtual)" : ""), kit.bci());
447 }
448 }
449 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed);
450 return NULL;
451 }
453 bool LibraryCallKit::try_to_inline() {
454 // Handle symbolic names for otherwise undistinguished boolean switches:
455 const bool is_store = true;
456 const bool is_native_ptr = true;
457 const bool is_static = true;
459 if (!jvms()->has_method()) {
460 // Root JVMState has a null method.
461 assert(map()->memory()->Opcode() == Op_Parm, "");
462 // Insert the memory aliasing node
463 set_all_memory(reset_memory());
464 }
465 assert(merged_memory(), "");
467 switch (intrinsic_id()) {
468 case vmIntrinsics::_hashCode:
469 return inline_native_hashcode(intrinsic()->is_virtual(), !is_static);
470 case vmIntrinsics::_identityHashCode:
471 return inline_native_hashcode(/*!virtual*/ false, is_static);
472 case vmIntrinsics::_getClass:
473 return inline_native_getClass();
475 case vmIntrinsics::_dsin:
476 case vmIntrinsics::_dcos:
477 case vmIntrinsics::_dtan:
478 case vmIntrinsics::_dabs:
479 case vmIntrinsics::_datan2:
480 case vmIntrinsics::_dsqrt:
481 case vmIntrinsics::_dexp:
482 case vmIntrinsics::_dlog:
483 case vmIntrinsics::_dlog10:
484 case vmIntrinsics::_dpow:
485 return inline_math_native(intrinsic_id());
487 case vmIntrinsics::_min:
488 case vmIntrinsics::_max:
489 return inline_min_max(intrinsic_id());
491 case vmIntrinsics::_arraycopy:
492 return inline_arraycopy();
494 case vmIntrinsics::_compareTo:
495 return inline_string_compareTo();
496 case vmIntrinsics::_indexOf:
497 return inline_string_indexOf();
498 case vmIntrinsics::_equals:
499 return inline_string_equals();
501 case vmIntrinsics::_getObject:
502 return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT, false);
503 case vmIntrinsics::_getBoolean:
504 return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN, false);
505 case vmIntrinsics::_getByte:
506 return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE, false);
507 case vmIntrinsics::_getShort:
508 return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT, false);
509 case vmIntrinsics::_getChar:
510 return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR, false);
511 case vmIntrinsics::_getInt:
512 return inline_unsafe_access(!is_native_ptr, !is_store, T_INT, false);
513 case vmIntrinsics::_getLong:
514 return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG, false);
515 case vmIntrinsics::_getFloat:
516 return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT, false);
517 case vmIntrinsics::_getDouble:
518 return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE, false);
520 case vmIntrinsics::_putObject:
521 return inline_unsafe_access(!is_native_ptr, is_store, T_OBJECT, false);
522 case vmIntrinsics::_putBoolean:
523 return inline_unsafe_access(!is_native_ptr, is_store, T_BOOLEAN, false);
524 case vmIntrinsics::_putByte:
525 return inline_unsafe_access(!is_native_ptr, is_store, T_BYTE, false);
526 case vmIntrinsics::_putShort:
527 return inline_unsafe_access(!is_native_ptr, is_store, T_SHORT, false);
528 case vmIntrinsics::_putChar:
529 return inline_unsafe_access(!is_native_ptr, is_store, T_CHAR, false);
530 case vmIntrinsics::_putInt:
531 return inline_unsafe_access(!is_native_ptr, is_store, T_INT, false);
532 case vmIntrinsics::_putLong:
533 return inline_unsafe_access(!is_native_ptr, is_store, T_LONG, false);
534 case vmIntrinsics::_putFloat:
535 return inline_unsafe_access(!is_native_ptr, is_store, T_FLOAT, false);
536 case vmIntrinsics::_putDouble:
537 return inline_unsafe_access(!is_native_ptr, is_store, T_DOUBLE, false);
539 case vmIntrinsics::_getByte_raw:
540 return inline_unsafe_access(is_native_ptr, !is_store, T_BYTE, false);
541 case vmIntrinsics::_getShort_raw:
542 return inline_unsafe_access(is_native_ptr, !is_store, T_SHORT, false);
543 case vmIntrinsics::_getChar_raw:
544 return inline_unsafe_access(is_native_ptr, !is_store, T_CHAR, false);
545 case vmIntrinsics::_getInt_raw:
546 return inline_unsafe_access(is_native_ptr, !is_store, T_INT, false);
547 case vmIntrinsics::_getLong_raw:
548 return inline_unsafe_access(is_native_ptr, !is_store, T_LONG, false);
549 case vmIntrinsics::_getFloat_raw:
550 return inline_unsafe_access(is_native_ptr, !is_store, T_FLOAT, false);
551 case vmIntrinsics::_getDouble_raw:
552 return inline_unsafe_access(is_native_ptr, !is_store, T_DOUBLE, false);
553 case vmIntrinsics::_getAddress_raw:
554 return inline_unsafe_access(is_native_ptr, !is_store, T_ADDRESS, false);
556 case vmIntrinsics::_putByte_raw:
557 return inline_unsafe_access(is_native_ptr, is_store, T_BYTE, false);
558 case vmIntrinsics::_putShort_raw:
559 return inline_unsafe_access(is_native_ptr, is_store, T_SHORT, false);
560 case vmIntrinsics::_putChar_raw:
561 return inline_unsafe_access(is_native_ptr, is_store, T_CHAR, false);
562 case vmIntrinsics::_putInt_raw:
563 return inline_unsafe_access(is_native_ptr, is_store, T_INT, false);
564 case vmIntrinsics::_putLong_raw:
565 return inline_unsafe_access(is_native_ptr, is_store, T_LONG, false);
566 case vmIntrinsics::_putFloat_raw:
567 return inline_unsafe_access(is_native_ptr, is_store, T_FLOAT, false);
568 case vmIntrinsics::_putDouble_raw:
569 return inline_unsafe_access(is_native_ptr, is_store, T_DOUBLE, false);
570 case vmIntrinsics::_putAddress_raw:
571 return inline_unsafe_access(is_native_ptr, is_store, T_ADDRESS, false);
573 case vmIntrinsics::_getObjectVolatile:
574 return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT, true);
575 case vmIntrinsics::_getBooleanVolatile:
576 return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN, true);
577 case vmIntrinsics::_getByteVolatile:
578 return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE, true);
579 case vmIntrinsics::_getShortVolatile:
580 return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT, true);
581 case vmIntrinsics::_getCharVolatile:
582 return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR, true);
583 case vmIntrinsics::_getIntVolatile:
584 return inline_unsafe_access(!is_native_ptr, !is_store, T_INT, true);
585 case vmIntrinsics::_getLongVolatile:
586 return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG, true);
587 case vmIntrinsics::_getFloatVolatile:
588 return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT, true);
589 case vmIntrinsics::_getDoubleVolatile:
590 return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE, true);
592 case vmIntrinsics::_putObjectVolatile:
593 return inline_unsafe_access(!is_native_ptr, is_store, T_OBJECT, true);
594 case vmIntrinsics::_putBooleanVolatile:
595 return inline_unsafe_access(!is_native_ptr, is_store, T_BOOLEAN, true);
596 case vmIntrinsics::_putByteVolatile:
597 return inline_unsafe_access(!is_native_ptr, is_store, T_BYTE, true);
598 case vmIntrinsics::_putShortVolatile:
599 return inline_unsafe_access(!is_native_ptr, is_store, T_SHORT, true);
600 case vmIntrinsics::_putCharVolatile:
601 return inline_unsafe_access(!is_native_ptr, is_store, T_CHAR, true);
602 case vmIntrinsics::_putIntVolatile:
603 return inline_unsafe_access(!is_native_ptr, is_store, T_INT, true);
604 case vmIntrinsics::_putLongVolatile:
605 return inline_unsafe_access(!is_native_ptr, is_store, T_LONG, true);
606 case vmIntrinsics::_putFloatVolatile:
607 return inline_unsafe_access(!is_native_ptr, is_store, T_FLOAT, true);
608 case vmIntrinsics::_putDoubleVolatile:
609 return inline_unsafe_access(!is_native_ptr, is_store, T_DOUBLE, true);
611 case vmIntrinsics::_prefetchRead:
612 return inline_unsafe_prefetch(!is_native_ptr, !is_store, !is_static);
613 case vmIntrinsics::_prefetchWrite:
614 return inline_unsafe_prefetch(!is_native_ptr, is_store, !is_static);
615 case vmIntrinsics::_prefetchReadStatic:
616 return inline_unsafe_prefetch(!is_native_ptr, !is_store, is_static);
617 case vmIntrinsics::_prefetchWriteStatic:
618 return inline_unsafe_prefetch(!is_native_ptr, is_store, is_static);
620 case vmIntrinsics::_compareAndSwapObject:
621 return inline_unsafe_CAS(T_OBJECT);
622 case vmIntrinsics::_compareAndSwapInt:
623 return inline_unsafe_CAS(T_INT);
624 case vmIntrinsics::_compareAndSwapLong:
625 return inline_unsafe_CAS(T_LONG);
627 case vmIntrinsics::_putOrderedObject:
628 return inline_unsafe_ordered_store(T_OBJECT);
629 case vmIntrinsics::_putOrderedInt:
630 return inline_unsafe_ordered_store(T_INT);
631 case vmIntrinsics::_putOrderedLong:
632 return inline_unsafe_ordered_store(T_LONG);
634 case vmIntrinsics::_currentThread:
635 return inline_native_currentThread();
636 case vmIntrinsics::_isInterrupted:
637 return inline_native_isInterrupted();
639 #ifdef TRACE_HAVE_INTRINSICS
640 case vmIntrinsics::_classID:
641 return inline_native_classID();
642 case vmIntrinsics::_threadID:
643 return inline_native_threadID();
644 case vmIntrinsics::_counterTime:
645 return inline_native_time_funcs(CAST_FROM_FN_PTR(address, TRACE_TIME_METHOD), "counterTime");
646 #endif
647 case vmIntrinsics::_currentTimeMillis:
648 return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeMillis), "currentTimeMillis");
649 case vmIntrinsics::_nanoTime:
650 return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeNanos), "nanoTime");
651 case vmIntrinsics::_allocateInstance:
652 return inline_unsafe_allocate();
653 case vmIntrinsics::_copyMemory:
654 return inline_unsafe_copyMemory();
655 case vmIntrinsics::_newArray:
656 return inline_native_newArray();
657 case vmIntrinsics::_getLength:
658 return inline_native_getLength();
659 case vmIntrinsics::_copyOf:
660 return inline_array_copyOf(false);
661 case vmIntrinsics::_copyOfRange:
662 return inline_array_copyOf(true);
663 case vmIntrinsics::_equalsC:
664 return inline_array_equals();
665 case vmIntrinsics::_clone:
666 return inline_native_clone(intrinsic()->is_virtual());
668 case vmIntrinsics::_isAssignableFrom:
669 return inline_native_subtype_check();
671 case vmIntrinsics::_isInstance:
672 case vmIntrinsics::_getModifiers:
673 case vmIntrinsics::_isInterface:
674 case vmIntrinsics::_isArray:
675 case vmIntrinsics::_isPrimitive:
676 case vmIntrinsics::_getSuperclass:
677 case vmIntrinsics::_getComponentType:
678 case vmIntrinsics::_getClassAccessFlags:
679 return inline_native_Class_query(intrinsic_id());
681 case vmIntrinsics::_floatToRawIntBits:
682 case vmIntrinsics::_floatToIntBits:
683 case vmIntrinsics::_intBitsToFloat:
684 case vmIntrinsics::_doubleToRawLongBits:
685 case vmIntrinsics::_doubleToLongBits:
686 case vmIntrinsics::_longBitsToDouble:
687 return inline_fp_conversions(intrinsic_id());
689 case vmIntrinsics::_numberOfLeadingZeros_i:
690 case vmIntrinsics::_numberOfLeadingZeros_l:
691 return inline_numberOfLeadingZeros(intrinsic_id());
693 case vmIntrinsics::_numberOfTrailingZeros_i:
694 case vmIntrinsics::_numberOfTrailingZeros_l:
695 return inline_numberOfTrailingZeros(intrinsic_id());
697 case vmIntrinsics::_bitCount_i:
698 case vmIntrinsics::_bitCount_l:
699 return inline_bitCount(intrinsic_id());
701 case vmIntrinsics::_reverseBytes_i:
702 case vmIntrinsics::_reverseBytes_l:
703 case vmIntrinsics::_reverseBytes_s:
704 case vmIntrinsics::_reverseBytes_c:
705 return inline_reverseBytes((vmIntrinsics::ID) intrinsic_id());
707 case vmIntrinsics::_getCallerClass:
708 return inline_native_Reflection_getCallerClass();
710 case vmIntrinsics::_Reference_get:
711 return inline_reference_get();
713 default:
714 // If you get here, it may be that someone has added a new intrinsic
715 // to the list in vmSymbols.hpp without implementing it here.
716 #ifndef PRODUCT
717 if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) {
718 tty->print_cr("*** Warning: Unimplemented intrinsic %s(%d)",
719 vmIntrinsics::name_at(intrinsic_id()), intrinsic_id());
720 }
721 #endif
722 return false;
723 }
724 }
726 //------------------------------push_result------------------------------
727 // Helper function for finishing intrinsics.
728 void LibraryCallKit::push_result(RegionNode* region, PhiNode* value) {
729 record_for_igvn(region);
730 set_control(_gvn.transform(region));
731 BasicType value_type = value->type()->basic_type();
732 push_node(value_type, _gvn.transform(value));
733 }
735 //------------------------------generate_guard---------------------------
736 // Helper function for generating guarded fast-slow graph structures.
737 // The given 'test', if true, guards a slow path. If the test fails
738 // then a fast path can be taken. (We generally hope it fails.)
739 // In all cases, GraphKit::control() is updated to the fast path.
740 // The returned value represents the control for the slow path.
741 // The return value is never 'top'; it is either a valid control
742 // or NULL if it is obvious that the slow path can never be taken.
743 // Also, if region and the slow control are not NULL, the slow edge
744 // is appended to the region.
745 Node* LibraryCallKit::generate_guard(Node* test, RegionNode* region, float true_prob) {
746 if (stopped()) {
747 // Already short circuited.
748 return NULL;
749 }
751 // Build an if node and its projections.
752 // If test is true we take the slow path, which we assume is uncommon.
753 if (_gvn.type(test) == TypeInt::ZERO) {
754 // The slow branch is never taken. No need to build this guard.
755 return NULL;
756 }
758 IfNode* iff = create_and_map_if(control(), test, true_prob, COUNT_UNKNOWN);
760 Node* if_slow = _gvn.transform( new (C, 1) IfTrueNode(iff) );
761 if (if_slow == top()) {
762 // The slow branch is never taken. No need to build this guard.
763 return NULL;
764 }
766 if (region != NULL)
767 region->add_req(if_slow);
769 Node* if_fast = _gvn.transform( new (C, 1) IfFalseNode(iff) );
770 set_control(if_fast);
772 return if_slow;
773 }
775 inline Node* LibraryCallKit::generate_slow_guard(Node* test, RegionNode* region) {
776 return generate_guard(test, region, PROB_UNLIKELY_MAG(3));
777 }
778 inline Node* LibraryCallKit::generate_fair_guard(Node* test, RegionNode* region) {
779 return generate_guard(test, region, PROB_FAIR);
780 }
782 inline Node* LibraryCallKit::generate_negative_guard(Node* index, RegionNode* region,
783 Node* *pos_index) {
784 if (stopped())
785 return NULL; // already stopped
786 if (_gvn.type(index)->higher_equal(TypeInt::POS)) // [0,maxint]
787 return NULL; // index is already adequately typed
788 Node* cmp_lt = _gvn.transform( new (C, 3) CmpINode(index, intcon(0)) );
789 Node* bol_lt = _gvn.transform( new (C, 2) BoolNode(cmp_lt, BoolTest::lt) );
790 Node* is_neg = generate_guard(bol_lt, region, PROB_MIN);
791 if (is_neg != NULL && pos_index != NULL) {
792 // Emulate effect of Parse::adjust_map_after_if.
793 Node* ccast = new (C, 2) CastIINode(index, TypeInt::POS);
794 ccast->set_req(0, control());
795 (*pos_index) = _gvn.transform(ccast);
796 }
797 return is_neg;
798 }
800 inline Node* LibraryCallKit::generate_nonpositive_guard(Node* index, bool never_negative,
801 Node* *pos_index) {
802 if (stopped())
803 return NULL; // already stopped
804 if (_gvn.type(index)->higher_equal(TypeInt::POS1)) // [1,maxint]
805 return NULL; // index is already adequately typed
806 Node* cmp_le = _gvn.transform( new (C, 3) CmpINode(index, intcon(0)) );
807 BoolTest::mask le_or_eq = (never_negative ? BoolTest::eq : BoolTest::le);
808 Node* bol_le = _gvn.transform( new (C, 2) BoolNode(cmp_le, le_or_eq) );
809 Node* is_notp = generate_guard(bol_le, NULL, PROB_MIN);
810 if (is_notp != NULL && pos_index != NULL) {
811 // Emulate effect of Parse::adjust_map_after_if.
812 Node* ccast = new (C, 2) CastIINode(index, TypeInt::POS1);
813 ccast->set_req(0, control());
814 (*pos_index) = _gvn.transform(ccast);
815 }
816 return is_notp;
817 }
819 // Make sure that 'position' is a valid limit index, in [0..length].
820 // There are two equivalent plans for checking this:
821 // A. (offset + copyLength) unsigned<= arrayLength
822 // B. offset <= (arrayLength - copyLength)
823 // We require that all of the values above, except for the sum and
824 // difference, are already known to be non-negative.
825 // Plan A is robust in the face of overflow, if offset and copyLength
826 // are both hugely positive.
827 //
828 // Plan B is less direct and intuitive, but it does not overflow at
829 // all, since the difference of two non-negatives is always
830 // representable. Whenever Java methods must perform the equivalent
831 // check they generally use Plan B instead of Plan A.
832 // For the moment we use Plan A.
833 inline Node* LibraryCallKit::generate_limit_guard(Node* offset,
834 Node* subseq_length,
835 Node* array_length,
836 RegionNode* region) {
837 if (stopped())
838 return NULL; // already stopped
839 bool zero_offset = _gvn.type(offset) == TypeInt::ZERO;
840 if (zero_offset && subseq_length->eqv_uncast(array_length))
841 return NULL; // common case of whole-array copy
842 Node* last = subseq_length;
843 if (!zero_offset) // last += offset
844 last = _gvn.transform( new (C, 3) AddINode(last, offset));
845 Node* cmp_lt = _gvn.transform( new (C, 3) CmpUNode(array_length, last) );
846 Node* bol_lt = _gvn.transform( new (C, 2) BoolNode(cmp_lt, BoolTest::lt) );
847 Node* is_over = generate_guard(bol_lt, region, PROB_MIN);
848 return is_over;
849 }
852 //--------------------------generate_current_thread--------------------
853 Node* LibraryCallKit::generate_current_thread(Node* &tls_output) {
854 ciKlass* thread_klass = env()->Thread_klass();
855 const Type* thread_type = TypeOopPtr::make_from_klass(thread_klass)->cast_to_ptr_type(TypePtr::NotNull);
856 Node* thread = _gvn.transform(new (C, 1) ThreadLocalNode());
857 Node* p = basic_plus_adr(top()/*!oop*/, thread, in_bytes(JavaThread::threadObj_offset()));
858 Node* threadObj = make_load(NULL, p, thread_type, T_OBJECT);
859 tls_output = thread;
860 return threadObj;
861 }
864 //------------------------------make_string_method_node------------------------
865 // Helper method for String intrinsic functions. This version is called
866 // with str1 and str2 pointing to String object nodes.
867 //
868 Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1, Node* str2) {
869 Node* no_ctrl = NULL;
871 // Get start addr of string
872 Node* str1_value = load_String_value(no_ctrl, str1);
873 Node* str1_offset = load_String_offset(no_ctrl, str1);
874 Node* str1_start = array_element_address(str1_value, str1_offset, T_CHAR);
876 // Get length of string 1
877 Node* str1_len = load_String_length(no_ctrl, str1);
879 Node* str2_value = load_String_value(no_ctrl, str2);
880 Node* str2_offset = load_String_offset(no_ctrl, str2);
881 Node* str2_start = array_element_address(str2_value, str2_offset, T_CHAR);
883 Node* str2_len = NULL;
884 Node* result = NULL;
886 switch (opcode) {
887 case Op_StrIndexOf:
888 // Get length of string 2
889 str2_len = load_String_length(no_ctrl, str2);
891 result = new (C, 6) StrIndexOfNode(control(), memory(TypeAryPtr::CHARS),
892 str1_start, str1_len, str2_start, str2_len);
893 break;
894 case Op_StrComp:
895 // Get length of string 2
896 str2_len = load_String_length(no_ctrl, str2);
898 result = new (C, 6) StrCompNode(control(), memory(TypeAryPtr::CHARS),
899 str1_start, str1_len, str2_start, str2_len);
900 break;
901 case Op_StrEquals:
902 result = new (C, 5) StrEqualsNode(control(), memory(TypeAryPtr::CHARS),
903 str1_start, str2_start, str1_len);
904 break;
905 default:
906 ShouldNotReachHere();
907 return NULL;
908 }
910 // All these intrinsics have checks.
911 C->set_has_split_ifs(true); // Has chance for split-if optimization
913 return _gvn.transform(result);
914 }
916 // Helper method for String intrinsic functions. This version is called
917 // with str1 and str2 pointing to char[] nodes, with cnt1 and cnt2 pointing
918 // to Int nodes containing the lenghts of str1 and str2.
919 //
920 Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2) {
922 Node* result = NULL;
923 switch (opcode) {
924 case Op_StrIndexOf:
925 result = new (C, 6) StrIndexOfNode(control(), memory(TypeAryPtr::CHARS),
926 str1_start, cnt1, str2_start, cnt2);
927 break;
928 case Op_StrComp:
929 result = new (C, 6) StrCompNode(control(), memory(TypeAryPtr::CHARS),
930 str1_start, cnt1, str2_start, cnt2);
931 break;
932 case Op_StrEquals:
933 result = new (C, 5) StrEqualsNode(control(), memory(TypeAryPtr::CHARS),
934 str1_start, str2_start, cnt1);
935 break;
936 default:
937 ShouldNotReachHere();
938 return NULL;
939 }
941 // All these intrinsics have checks.
942 C->set_has_split_ifs(true); // Has chance for split-if optimization
944 return _gvn.transform(result);
945 }
947 //------------------------------inline_string_compareTo------------------------
948 bool LibraryCallKit::inline_string_compareTo() {
950 if (!Matcher::has_match_rule(Op_StrComp)) return false;
952 _sp += 2;
953 Node *argument = pop(); // pop non-receiver first: it was pushed second
954 Node *receiver = pop();
956 // Null check on self without removing any arguments. The argument
957 // null check technically happens in the wrong place, which can lead to
958 // invalid stack traces when string compare is inlined into a method
959 // which handles NullPointerExceptions.
960 _sp += 2;
961 receiver = do_null_check(receiver, T_OBJECT);
962 argument = do_null_check(argument, T_OBJECT);
963 _sp -= 2;
964 if (stopped()) {
965 return true;
966 }
968 Node* compare = make_string_method_node(Op_StrComp, receiver, argument);
969 push(compare);
970 return true;
971 }
973 //------------------------------inline_string_equals------------------------
974 bool LibraryCallKit::inline_string_equals() {
976 if (!Matcher::has_match_rule(Op_StrEquals)) return false;
978 int nargs = 2;
979 _sp += nargs;
980 Node* argument = pop(); // pop non-receiver first: it was pushed second
981 Node* receiver = pop();
983 // Null check on self without removing any arguments. The argument
984 // null check technically happens in the wrong place, which can lead to
985 // invalid stack traces when string compare is inlined into a method
986 // which handles NullPointerExceptions.
987 _sp += nargs;
988 receiver = do_null_check(receiver, T_OBJECT);
989 //should not do null check for argument for String.equals(), because spec
990 //allows to specify NULL as argument.
991 _sp -= nargs;
993 if (stopped()) {
994 return true;
995 }
997 // paths (plus control) merge
998 RegionNode* region = new (C, 5) RegionNode(5);
999 Node* phi = new (C, 5) PhiNode(region, TypeInt::BOOL);
1001 // does source == target string?
1002 Node* cmp = _gvn.transform(new (C, 3) CmpPNode(receiver, argument));
1003 Node* bol = _gvn.transform(new (C, 2) BoolNode(cmp, BoolTest::eq));
1005 Node* if_eq = generate_slow_guard(bol, NULL);
1006 if (if_eq != NULL) {
1007 // receiver == argument
1008 phi->init_req(2, intcon(1));
1009 region->init_req(2, if_eq);
1010 }
1012 // get String klass for instanceOf
1013 ciInstanceKlass* klass = env()->String_klass();
1015 if (!stopped()) {
1016 _sp += nargs; // gen_instanceof might do an uncommon trap
1017 Node* inst = gen_instanceof(argument, makecon(TypeKlassPtr::make(klass)));
1018 _sp -= nargs;
1019 Node* cmp = _gvn.transform(new (C, 3) CmpINode(inst, intcon(1)));
1020 Node* bol = _gvn.transform(new (C, 2) BoolNode(cmp, BoolTest::ne));
1022 Node* inst_false = generate_guard(bol, NULL, PROB_MIN);
1023 //instanceOf == true, fallthrough
1025 if (inst_false != NULL) {
1026 phi->init_req(3, intcon(0));
1027 region->init_req(3, inst_false);
1028 }
1029 }
1031 if (!stopped()) {
1032 const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(klass);
1034 // Properly cast the argument to String
1035 argument = _gvn.transform(new (C, 2) CheckCastPPNode(control(), argument, string_type));
1036 // This path is taken only when argument's type is String:NotNull.
1037 argument = cast_not_null(argument, false);
1039 Node* no_ctrl = NULL;
1041 // Get start addr of receiver
1042 Node* receiver_val = load_String_value(no_ctrl, receiver);
1043 Node* receiver_offset = load_String_offset(no_ctrl, receiver);
1044 Node* receiver_start = array_element_address(receiver_val, receiver_offset, T_CHAR);
1046 // Get length of receiver
1047 Node* receiver_cnt = load_String_length(no_ctrl, receiver);
1049 // Get start addr of argument
1050 Node* argument_val = load_String_value(no_ctrl, argument);
1051 Node* argument_offset = load_String_offset(no_ctrl, argument);
1052 Node* argument_start = array_element_address(argument_val, argument_offset, T_CHAR);
1054 // Get length of argument
1055 Node* argument_cnt = load_String_length(no_ctrl, argument);
1057 // Check for receiver count != argument count
1058 Node* cmp = _gvn.transform( new(C, 3) CmpINode(receiver_cnt, argument_cnt) );
1059 Node* bol = _gvn.transform( new(C, 2) BoolNode(cmp, BoolTest::ne) );
1060 Node* if_ne = generate_slow_guard(bol, NULL);
1061 if (if_ne != NULL) {
1062 phi->init_req(4, intcon(0));
1063 region->init_req(4, if_ne);
1064 }
1066 // Check for count == 0 is done by assembler code for StrEquals.
1068 if (!stopped()) {
1069 Node* equals = make_string_method_node(Op_StrEquals, receiver_start, receiver_cnt, argument_start, argument_cnt);
1070 phi->init_req(1, equals);
1071 region->init_req(1, control());
1072 }
1073 }
1075 // post merge
1076 set_control(_gvn.transform(region));
1077 record_for_igvn(region);
1079 push(_gvn.transform(phi));
1081 return true;
1082 }
1084 //------------------------------inline_array_equals----------------------------
1085 bool LibraryCallKit::inline_array_equals() {
1087 if (!Matcher::has_match_rule(Op_AryEq)) return false;
1089 _sp += 2;
1090 Node *argument2 = pop();
1091 Node *argument1 = pop();
1093 Node* equals =
1094 _gvn.transform(new (C, 4) AryEqNode(control(), memory(TypeAryPtr::CHARS),
1095 argument1, argument2) );
1096 push(equals);
1097 return true;
1098 }
1100 // Java version of String.indexOf(constant string)
1101 // class StringDecl {
1102 // StringDecl(char[] ca) {
1103 // offset = 0;
1104 // count = ca.length;
1105 // value = ca;
1106 // }
1107 // int offset;
1108 // int count;
1109 // char[] value;
1110 // }
1111 //
1112 // static int string_indexOf_J(StringDecl string_object, char[] target_object,
1113 // int targetOffset, int cache_i, int md2) {
1114 // int cache = cache_i;
1115 // int sourceOffset = string_object.offset;
1116 // int sourceCount = string_object.count;
1117 // int targetCount = target_object.length;
1118 //
1119 // int targetCountLess1 = targetCount - 1;
1120 // int sourceEnd = sourceOffset + sourceCount - targetCountLess1;
1121 //
1122 // char[] source = string_object.value;
1123 // char[] target = target_object;
1124 // int lastChar = target[targetCountLess1];
1125 //
1126 // outer_loop:
1127 // for (int i = sourceOffset; i < sourceEnd; ) {
1128 // int src = source[i + targetCountLess1];
1129 // if (src == lastChar) {
1130 // // With random strings and a 4-character alphabet,
1131 // // reverse matching at this point sets up 0.8% fewer
1132 // // frames, but (paradoxically) makes 0.3% more probes.
1133 // // Since those probes are nearer the lastChar probe,
1134 // // there is may be a net D$ win with reverse matching.
1135 // // But, reversing loop inhibits unroll of inner loop
1136 // // for unknown reason. So, does running outer loop from
1137 // // (sourceOffset - targetCountLess1) to (sourceOffset + sourceCount)
1138 // for (int j = 0; j < targetCountLess1; j++) {
1139 // if (target[targetOffset + j] != source[i+j]) {
1140 // if ((cache & (1 << source[i+j])) == 0) {
1141 // if (md2 < j+1) {
1142 // i += j+1;
1143 // continue outer_loop;
1144 // }
1145 // }
1146 // i += md2;
1147 // continue outer_loop;
1148 // }
1149 // }
1150 // return i - sourceOffset;
1151 // }
1152 // if ((cache & (1 << src)) == 0) {
1153 // i += targetCountLess1;
1154 // } // using "i += targetCount;" and an "else i++;" causes a jump to jump.
1155 // i++;
1156 // }
1157 // return -1;
1158 // }
1160 //------------------------------string_indexOf------------------------
1161 Node* LibraryCallKit::string_indexOf(Node* string_object, ciTypeArray* target_array, jint targetOffset_i,
1162 jint cache_i, jint md2_i) {
1164 Node* no_ctrl = NULL;
1165 float likely = PROB_LIKELY(0.9);
1166 float unlikely = PROB_UNLIKELY(0.9);
1168 const int nargs = 2; // number of arguments to push back for uncommon trap in predicate
1170 Node* source = load_String_value(no_ctrl, string_object);
1171 Node* sourceOffset = load_String_offset(no_ctrl, string_object);
1172 Node* sourceCount = load_String_length(no_ctrl, string_object);
1174 Node* target = _gvn.transform( makecon(TypeOopPtr::make_from_constant(target_array, true)) );
1175 jint target_length = target_array->length();
1176 const TypeAry* target_array_type = TypeAry::make(TypeInt::CHAR, TypeInt::make(0, target_length, Type::WidenMin));
1177 const TypeAryPtr* target_type = TypeAryPtr::make(TypePtr::BotPTR, target_array_type, target_array->klass(), true, Type::OffsetBot);
1179 IdealKit kit(this, false, true);
1180 #define __ kit.
1181 Node* zero = __ ConI(0);
1182 Node* one = __ ConI(1);
1183 Node* cache = __ ConI(cache_i);
1184 Node* md2 = __ ConI(md2_i);
1185 Node* lastChar = __ ConI(target_array->char_at(target_length - 1));
1186 Node* targetCount = __ ConI(target_length);
1187 Node* targetCountLess1 = __ ConI(target_length - 1);
1188 Node* targetOffset = __ ConI(targetOffset_i);
1189 Node* sourceEnd = __ SubI(__ AddI(sourceOffset, sourceCount), targetCountLess1);
1191 IdealVariable rtn(kit), i(kit), j(kit); __ declarations_done();
1192 Node* outer_loop = __ make_label(2 /* goto */);
1193 Node* return_ = __ make_label(1);
1195 __ set(rtn,__ ConI(-1));
1196 __ loop(this, nargs, i, sourceOffset, BoolTest::lt, sourceEnd); {
1197 Node* i2 = __ AddI(__ value(i), targetCountLess1);
1198 // pin to prohibit loading of "next iteration" value which may SEGV (rare)
1199 Node* src = load_array_element(__ ctrl(), source, i2, TypeAryPtr::CHARS);
1200 __ if_then(src, BoolTest::eq, lastChar, unlikely); {
1201 __ loop(this, nargs, j, zero, BoolTest::lt, targetCountLess1); {
1202 Node* tpj = __ AddI(targetOffset, __ value(j));
1203 Node* targ = load_array_element(no_ctrl, target, tpj, target_type);
1204 Node* ipj = __ AddI(__ value(i), __ value(j));
1205 Node* src2 = load_array_element(no_ctrl, source, ipj, TypeAryPtr::CHARS);
1206 __ if_then(targ, BoolTest::ne, src2); {
1207 __ if_then(__ AndI(cache, __ LShiftI(one, src2)), BoolTest::eq, zero); {
1208 __ if_then(md2, BoolTest::lt, __ AddI(__ value(j), one)); {
1209 __ increment(i, __ AddI(__ value(j), one));
1210 __ goto_(outer_loop);
1211 } __ end_if(); __ dead(j);
1212 }__ end_if(); __ dead(j);
1213 __ increment(i, md2);
1214 __ goto_(outer_loop);
1215 }__ end_if();
1216 __ increment(j, one);
1217 }__ end_loop(); __ dead(j);
1218 __ set(rtn, __ SubI(__ value(i), sourceOffset)); __ dead(i);
1219 __ goto_(return_);
1220 }__ end_if();
1221 __ if_then(__ AndI(cache, __ LShiftI(one, src)), BoolTest::eq, zero, likely); {
1222 __ increment(i, targetCountLess1);
1223 }__ end_if();
1224 __ increment(i, one);
1225 __ bind(outer_loop);
1226 }__ end_loop(); __ dead(i);
1227 __ bind(return_);
1229 // Final sync IdealKit and GraphKit.
1230 final_sync(kit);
1231 Node* result = __ value(rtn);
1232 #undef __
1233 C->set_has_loops(true);
1234 return result;
1235 }
1237 //------------------------------inline_string_indexOf------------------------
1238 bool LibraryCallKit::inline_string_indexOf() {
1240 _sp += 2;
1241 Node *argument = pop(); // pop non-receiver first: it was pushed second
1242 Node *receiver = pop();
1244 Node* result;
1245 // Disable the use of pcmpestri until it can be guaranteed that
1246 // the load doesn't cross into the uncommited space.
1247 if (Matcher::has_match_rule(Op_StrIndexOf) &&
1248 UseSSE42Intrinsics) {
1249 // Generate SSE4.2 version of indexOf
1250 // We currently only have match rules that use SSE4.2
1252 // Null check on self without removing any arguments. The argument
1253 // null check technically happens in the wrong place, which can lead to
1254 // invalid stack traces when string compare is inlined into a method
1255 // which handles NullPointerExceptions.
1256 _sp += 2;
1257 receiver = do_null_check(receiver, T_OBJECT);
1258 argument = do_null_check(argument, T_OBJECT);
1259 _sp -= 2;
1261 if (stopped()) {
1262 return true;
1263 }
1265 ciInstanceKlass* str_klass = env()->String_klass();
1266 const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(str_klass);
1268 // Make the merge point
1269 RegionNode* result_rgn = new (C, 4) RegionNode(4);
1270 Node* result_phi = new (C, 4) PhiNode(result_rgn, TypeInt::INT);
1271 Node* no_ctrl = NULL;
1273 // Get start addr of source string
1274 Node* source = load_String_value(no_ctrl, receiver);
1275 Node* source_offset = load_String_offset(no_ctrl, receiver);
1276 Node* source_start = array_element_address(source, source_offset, T_CHAR);
1278 // Get length of source string
1279 Node* source_cnt = load_String_length(no_ctrl, receiver);
1281 // Get start addr of substring
1282 Node* substr = load_String_value(no_ctrl, argument);
1283 Node* substr_offset = load_String_offset(no_ctrl, argument);
1284 Node* substr_start = array_element_address(substr, substr_offset, T_CHAR);
1286 // Get length of source string
1287 Node* substr_cnt = load_String_length(no_ctrl, argument);
1289 // Check for substr count > string count
1290 Node* cmp = _gvn.transform( new(C, 3) CmpINode(substr_cnt, source_cnt) );
1291 Node* bol = _gvn.transform( new(C, 2) BoolNode(cmp, BoolTest::gt) );
1292 Node* if_gt = generate_slow_guard(bol, NULL);
1293 if (if_gt != NULL) {
1294 result_phi->init_req(2, intcon(-1));
1295 result_rgn->init_req(2, if_gt);
1296 }
1298 if (!stopped()) {
1299 // Check for substr count == 0
1300 cmp = _gvn.transform( new(C, 3) CmpINode(substr_cnt, intcon(0)) );
1301 bol = _gvn.transform( new(C, 2) BoolNode(cmp, BoolTest::eq) );
1302 Node* if_zero = generate_slow_guard(bol, NULL);
1303 if (if_zero != NULL) {
1304 result_phi->init_req(3, intcon(0));
1305 result_rgn->init_req(3, if_zero);
1306 }
1307 }
1309 if (!stopped()) {
1310 result = make_string_method_node(Op_StrIndexOf, source_start, source_cnt, substr_start, substr_cnt);
1311 result_phi->init_req(1, result);
1312 result_rgn->init_req(1, control());
1313 }
1314 set_control(_gvn.transform(result_rgn));
1315 record_for_igvn(result_rgn);
1316 result = _gvn.transform(result_phi);
1318 } else { // Use LibraryCallKit::string_indexOf
1319 // don't intrinsify if argument isn't a constant string.
1320 if (!argument->is_Con()) {
1321 return false;
1322 }
1323 const TypeOopPtr* str_type = _gvn.type(argument)->isa_oopptr();
1324 if (str_type == NULL) {
1325 return false;
1326 }
1327 ciInstanceKlass* klass = env()->String_klass();
1328 ciObject* str_const = str_type->const_oop();
1329 if (str_const == NULL || str_const->klass() != klass) {
1330 return false;
1331 }
1332 ciInstance* str = str_const->as_instance();
1333 assert(str != NULL, "must be instance");
1335 ciObject* v = str->field_value_by_offset(java_lang_String::value_offset_in_bytes()).as_object();
1336 ciTypeArray* pat = v->as_type_array(); // pattern (argument) character array
1338 int o;
1339 int c;
1340 if (java_lang_String::has_offset_field()) {
1341 o = str->field_value_by_offset(java_lang_String::offset_offset_in_bytes()).as_int();
1342 c = str->field_value_by_offset(java_lang_String::count_offset_in_bytes()).as_int();
1343 } else {
1344 o = 0;
1345 c = pat->length();
1346 }
1348 // constant strings have no offset and count == length which
1349 // simplifies the resulting code somewhat so lets optimize for that.
1350 if (o != 0 || c != pat->length()) {
1351 return false;
1352 }
1354 // Null check on self without removing any arguments. The argument
1355 // null check technically happens in the wrong place, which can lead to
1356 // invalid stack traces when string compare is inlined into a method
1357 // which handles NullPointerExceptions.
1358 _sp += 2;
1359 receiver = do_null_check(receiver, T_OBJECT);
1360 // No null check on the argument is needed since it's a constant String oop.
1361 _sp -= 2;
1362 if (stopped()) {
1363 return true;
1364 }
1366 // The null string as a pattern always returns 0 (match at beginning of string)
1367 if (c == 0) {
1368 push(intcon(0));
1369 return true;
1370 }
1372 // Generate default indexOf
1373 jchar lastChar = pat->char_at(o + (c - 1));
1374 int cache = 0;
1375 int i;
1376 for (i = 0; i < c - 1; i++) {
1377 assert(i < pat->length(), "out of range");
1378 cache |= (1 << (pat->char_at(o + i) & (sizeof(cache) * BitsPerByte - 1)));
1379 }
1381 int md2 = c;
1382 for (i = 0; i < c - 1; i++) {
1383 assert(i < pat->length(), "out of range");
1384 if (pat->char_at(o + i) == lastChar) {
1385 md2 = (c - 1) - i;
1386 }
1387 }
1389 result = string_indexOf(receiver, pat, o, cache, md2);
1390 }
1392 push(result);
1393 return true;
1394 }
1396 //--------------------------pop_math_arg--------------------------------
1397 // Pop a double argument to a math function from the stack
1398 // rounding it if necessary.
1399 Node * LibraryCallKit::pop_math_arg() {
1400 Node *arg = pop_pair();
1401 if( Matcher::strict_fp_requires_explicit_rounding && UseSSE<=1 )
1402 arg = _gvn.transform( new (C, 2) RoundDoubleNode(0, arg) );
1403 return arg;
1404 }
1406 //------------------------------inline_trig----------------------------------
1407 // Inline sin/cos/tan instructions, if possible. If rounding is required, do
1408 // argument reduction which will turn into a fast/slow diamond.
1409 bool LibraryCallKit::inline_trig(vmIntrinsics::ID id) {
1410 _sp += arg_size(); // restore stack pointer
1411 Node* arg = pop_math_arg();
1412 Node* trig = NULL;
1414 switch (id) {
1415 case vmIntrinsics::_dsin:
1416 trig = _gvn.transform((Node*)new (C, 2) SinDNode(arg));
1417 break;
1418 case vmIntrinsics::_dcos:
1419 trig = _gvn.transform((Node*)new (C, 2) CosDNode(arg));
1420 break;
1421 case vmIntrinsics::_dtan:
1422 trig = _gvn.transform((Node*)new (C, 2) TanDNode(arg));
1423 break;
1424 default:
1425 assert(false, "bad intrinsic was passed in");
1426 return false;
1427 }
1429 // Rounding required? Check for argument reduction!
1430 if( Matcher::strict_fp_requires_explicit_rounding ) {
1432 static const double pi_4 = 0.7853981633974483;
1433 static const double neg_pi_4 = -0.7853981633974483;
1434 // pi/2 in 80-bit extended precision
1435 // static const unsigned char pi_2_bits_x[] = {0x35,0xc2,0x68,0x21,0xa2,0xda,0x0f,0xc9,0xff,0x3f,0x00,0x00,0x00,0x00,0x00,0x00};
1436 // -pi/2 in 80-bit extended precision
1437 // static const unsigned char neg_pi_2_bits_x[] = {0x35,0xc2,0x68,0x21,0xa2,0xda,0x0f,0xc9,0xff,0xbf,0x00,0x00,0x00,0x00,0x00,0x00};
1438 // Cutoff value for using this argument reduction technique
1439 //static const double pi_2_minus_epsilon = 1.564660403643354;
1440 //static const double neg_pi_2_plus_epsilon = -1.564660403643354;
1442 // Pseudocode for sin:
1443 // if (x <= Math.PI / 4.0) {
1444 // if (x >= -Math.PI / 4.0) return fsin(x);
1445 // if (x >= -Math.PI / 2.0) return -fcos(x + Math.PI / 2.0);
1446 // } else {
1447 // if (x <= Math.PI / 2.0) return fcos(x - Math.PI / 2.0);
1448 // }
1449 // return StrictMath.sin(x);
1451 // Pseudocode for cos:
1452 // if (x <= Math.PI / 4.0) {
1453 // if (x >= -Math.PI / 4.0) return fcos(x);
1454 // if (x >= -Math.PI / 2.0) return fsin(x + Math.PI / 2.0);
1455 // } else {
1456 // if (x <= Math.PI / 2.0) return -fsin(x - Math.PI / 2.0);
1457 // }
1458 // return StrictMath.cos(x);
1460 // Actually, sticking in an 80-bit Intel value into C2 will be tough; it
1461 // requires a special machine instruction to load it. Instead we'll try
1462 // the 'easy' case. If we really need the extra range +/- PI/2 we'll
1463 // probably do the math inside the SIN encoding.
1465 // Make the merge point
1466 RegionNode *r = new (C, 3) RegionNode(3);
1467 Node *phi = new (C, 3) PhiNode(r,Type::DOUBLE);
1469 // Flatten arg so we need only 1 test
1470 Node *abs = _gvn.transform(new (C, 2) AbsDNode(arg));
1471 // Node for PI/4 constant
1472 Node *pi4 = makecon(TypeD::make(pi_4));
1473 // Check PI/4 : abs(arg)
1474 Node *cmp = _gvn.transform(new (C, 3) CmpDNode(pi4,abs));
1475 // Check: If PI/4 < abs(arg) then go slow
1476 Node *bol = _gvn.transform( new (C, 2) BoolNode( cmp, BoolTest::lt ) );
1477 // Branch either way
1478 IfNode *iff = create_and_xform_if(control(),bol, PROB_STATIC_FREQUENT, COUNT_UNKNOWN);
1479 set_control(opt_iff(r,iff));
1481 // Set fast path result
1482 phi->init_req(2,trig);
1484 // Slow path - non-blocking leaf call
1485 Node* call = NULL;
1486 switch (id) {
1487 case vmIntrinsics::_dsin:
1488 call = make_runtime_call(RC_LEAF, OptoRuntime::Math_D_D_Type(),
1489 CAST_FROM_FN_PTR(address, SharedRuntime::dsin),
1490 "Sin", NULL, arg, top());
1491 break;
1492 case vmIntrinsics::_dcos:
1493 call = make_runtime_call(RC_LEAF, OptoRuntime::Math_D_D_Type(),
1494 CAST_FROM_FN_PTR(address, SharedRuntime::dcos),
1495 "Cos", NULL, arg, top());
1496 break;
1497 case vmIntrinsics::_dtan:
1498 call = make_runtime_call(RC_LEAF, OptoRuntime::Math_D_D_Type(),
1499 CAST_FROM_FN_PTR(address, SharedRuntime::dtan),
1500 "Tan", NULL, arg, top());
1501 break;
1502 }
1503 assert(control()->in(0) == call, "");
1504 Node* slow_result = _gvn.transform(new (C, 1) ProjNode(call,TypeFunc::Parms));
1505 r->init_req(1,control());
1506 phi->init_req(1,slow_result);
1508 // Post-merge
1509 set_control(_gvn.transform(r));
1510 record_for_igvn(r);
1511 trig = _gvn.transform(phi);
1513 C->set_has_split_ifs(true); // Has chance for split-if optimization
1514 }
1515 // Push result back on JVM stack
1516 push_pair(trig);
1517 return true;
1518 }
1520 //------------------------------inline_sqrt-------------------------------------
1521 // Inline square root instruction, if possible.
1522 bool LibraryCallKit::inline_sqrt(vmIntrinsics::ID id) {
1523 assert(id == vmIntrinsics::_dsqrt, "Not square root");
1524 _sp += arg_size(); // restore stack pointer
1525 push_pair(_gvn.transform(new (C, 2) SqrtDNode(0, pop_math_arg())));
1526 return true;
1527 }
1529 //------------------------------inline_abs-------------------------------------
1530 // Inline absolute value instruction, if possible.
1531 bool LibraryCallKit::inline_abs(vmIntrinsics::ID id) {
1532 assert(id == vmIntrinsics::_dabs, "Not absolute value");
1533 _sp += arg_size(); // restore stack pointer
1534 push_pair(_gvn.transform(new (C, 2) AbsDNode(pop_math_arg())));
1535 return true;
1536 }
1538 //------------------------------inline_exp-------------------------------------
1539 // Inline exp instructions, if possible. The Intel hardware only misses
1540 // really odd corner cases (+/- Infinity). Just uncommon-trap them.
1541 bool LibraryCallKit::inline_exp(vmIntrinsics::ID id) {
1542 assert(id == vmIntrinsics::_dexp, "Not exp");
1544 // If this inlining ever returned NaN in the past, we do not intrinsify it
1545 // every again. NaN results requires StrictMath.exp handling.
1546 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false;
1548 _sp += arg_size(); // restore stack pointer
1549 Node *x = pop_math_arg();
1550 Node *result = _gvn.transform(new (C, 2) ExpDNode(0,x));
1552 //-------------------
1553 //result=(result.isNaN())? StrictMath::exp():result;
1554 // Check: If isNaN() by checking result!=result? then go to Strict Math
1555 Node* cmpisnan = _gvn.transform(new (C, 3) CmpDNode(result,result));
1556 // Build the boolean node
1557 Node* bolisnum = _gvn.transform( new (C, 2) BoolNode(cmpisnan, BoolTest::eq) );
1559 { BuildCutout unless(this, bolisnum, PROB_STATIC_FREQUENT);
1560 // End the current control-flow path
1561 push_pair(x);
1562 // Math.exp intrinsic returned a NaN, which requires StrictMath.exp
1563 // to handle. Recompile without intrinsifying Math.exp
1564 uncommon_trap(Deoptimization::Reason_intrinsic,
1565 Deoptimization::Action_make_not_entrant);
1566 }
1568 C->set_has_split_ifs(true); // Has chance for split-if optimization
1570 push_pair(result);
1572 return true;
1573 }
1575 //------------------------------inline_pow-------------------------------------
1576 // Inline power instructions, if possible.
1577 bool LibraryCallKit::inline_pow(vmIntrinsics::ID id) {
1578 assert(id == vmIntrinsics::_dpow, "Not pow");
1580 // If this inlining ever returned NaN in the past, we do not intrinsify it
1581 // every again. NaN results requires StrictMath.pow handling.
1582 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false;
1584 // Do not intrinsify on older platforms which lack cmove.
1585 if (ConditionalMoveLimit == 0) return false;
1587 // Pseudocode for pow
1588 // if (x <= 0.0) {
1589 // if ((double)((int)y)==y) { // if y is int
1590 // result = ((1&(int)y)==0)?-DPow(abs(x), y):DPow(abs(x), y)
1591 // } else {
1592 // result = NaN;
1593 // }
1594 // } else {
1595 // result = DPow(x,y);
1596 // }
1597 // if (result != result)? {
1598 // uncommon_trap();
1599 // }
1600 // return result;
1602 _sp += arg_size(); // restore stack pointer
1603 Node* y = pop_math_arg();
1604 Node* x = pop_math_arg();
1606 Node *fast_result = _gvn.transform( new (C, 3) PowDNode(0, x, y) );
1608 // Short form: if not top-level (i.e., Math.pow but inlining Math.pow
1609 // inside of something) then skip the fancy tests and just check for
1610 // NaN result.
1611 Node *result = NULL;
1612 if( jvms()->depth() >= 1 ) {
1613 result = fast_result;
1614 } else {
1616 // Set the merge point for If node with condition of (x <= 0.0)
1617 // There are four possible paths to region node and phi node
1618 RegionNode *r = new (C, 4) RegionNode(4);
1619 Node *phi = new (C, 4) PhiNode(r, Type::DOUBLE);
1621 // Build the first if node: if (x <= 0.0)
1622 // Node for 0 constant
1623 Node *zeronode = makecon(TypeD::ZERO);
1624 // Check x:0
1625 Node *cmp = _gvn.transform(new (C, 3) CmpDNode(x, zeronode));
1626 // Check: If (x<=0) then go complex path
1627 Node *bol1 = _gvn.transform( new (C, 2) BoolNode( cmp, BoolTest::le ) );
1628 // Branch either way
1629 IfNode *if1 = create_and_xform_if(control(),bol1, PROB_STATIC_INFREQUENT, COUNT_UNKNOWN);
1630 Node *opt_test = _gvn.transform(if1);
1631 //assert( opt_test->is_If(), "Expect an IfNode");
1632 IfNode *opt_if1 = (IfNode*)opt_test;
1633 // Fast path taken; set region slot 3
1634 Node *fast_taken = _gvn.transform( new (C, 1) IfFalseNode(opt_if1) );
1635 r->init_req(3,fast_taken); // Capture fast-control
1637 // Fast path not-taken, i.e. slow path
1638 Node *complex_path = _gvn.transform( new (C, 1) IfTrueNode(opt_if1) );
1640 // Set fast path result
1641 Node *fast_result = _gvn.transform( new (C, 3) PowDNode(0, y, x) );
1642 phi->init_req(3, fast_result);
1644 // Complex path
1645 // Build the second if node (if y is int)
1646 // Node for (int)y
1647 Node *inty = _gvn.transform( new (C, 2) ConvD2INode(y));
1648 // Node for (double)((int) y)
1649 Node *doubleinty= _gvn.transform( new (C, 2) ConvI2DNode(inty));
1650 // Check (double)((int) y) : y
1651 Node *cmpinty= _gvn.transform(new (C, 3) CmpDNode(doubleinty, y));
1652 // Check if (y isn't int) then go to slow path
1654 Node *bol2 = _gvn.transform( new (C, 2) BoolNode( cmpinty, BoolTest::ne ) );
1655 // Branch either way
1656 IfNode *if2 = create_and_xform_if(complex_path,bol2, PROB_STATIC_INFREQUENT, COUNT_UNKNOWN);
1657 Node *slow_path = opt_iff(r,if2); // Set region path 2
1659 // Calculate DPow(abs(x), y)*(1 & (int)y)
1660 // Node for constant 1
1661 Node *conone = intcon(1);
1662 // 1& (int)y
1663 Node *signnode= _gvn.transform( new (C, 3) AndINode(conone, inty) );
1664 // zero node
1665 Node *conzero = intcon(0);
1666 // Check (1&(int)y)==0?
1667 Node *cmpeq1 = _gvn.transform(new (C, 3) CmpINode(signnode, conzero));
1668 // Check if (1&(int)y)!=0?, if so the result is negative
1669 Node *bol3 = _gvn.transform( new (C, 2) BoolNode( cmpeq1, BoolTest::ne ) );
1670 // abs(x)
1671 Node *absx=_gvn.transform( new (C, 2) AbsDNode(x));
1672 // abs(x)^y
1673 Node *absxpowy = _gvn.transform( new (C, 3) PowDNode(0, y, absx) );
1674 // -abs(x)^y
1675 Node *negabsxpowy = _gvn.transform(new (C, 2) NegDNode (absxpowy));
1676 // (1&(int)y)==1?-DPow(abs(x), y):DPow(abs(x), y)
1677 Node *signresult = _gvn.transform( CMoveNode::make(C, NULL, bol3, absxpowy, negabsxpowy, Type::DOUBLE));
1678 // Set complex path fast result
1679 phi->init_req(2, signresult);
1681 static const jlong nan_bits = CONST64(0x7ff8000000000000);
1682 Node *slow_result = makecon(TypeD::make(*(double*)&nan_bits)); // return NaN
1683 r->init_req(1,slow_path);
1684 phi->init_req(1,slow_result);
1686 // Post merge
1687 set_control(_gvn.transform(r));
1688 record_for_igvn(r);
1689 result=_gvn.transform(phi);
1690 }
1692 //-------------------
1693 //result=(result.isNaN())? uncommon_trap():result;
1694 // Check: If isNaN() by checking result!=result? then go to Strict Math
1695 Node* cmpisnan = _gvn.transform(new (C, 3) CmpDNode(result,result));
1696 // Build the boolean node
1697 Node* bolisnum = _gvn.transform( new (C, 2) BoolNode(cmpisnan, BoolTest::eq) );
1699 { BuildCutout unless(this, bolisnum, PROB_STATIC_FREQUENT);
1700 // End the current control-flow path
1701 push_pair(x);
1702 push_pair(y);
1703 // Math.pow intrinsic returned a NaN, which requires StrictMath.pow
1704 // to handle. Recompile without intrinsifying Math.pow.
1705 uncommon_trap(Deoptimization::Reason_intrinsic,
1706 Deoptimization::Action_make_not_entrant);
1707 }
1709 C->set_has_split_ifs(true); // Has chance for split-if optimization
1711 push_pair(result);
1713 return true;
1714 }
1716 //------------------------------inline_trans-------------------------------------
1717 // Inline transcendental instructions, if possible. The Intel hardware gets
1718 // these right, no funny corner cases missed.
1719 bool LibraryCallKit::inline_trans(vmIntrinsics::ID id) {
1720 _sp += arg_size(); // restore stack pointer
1721 Node* arg = pop_math_arg();
1722 Node* trans = NULL;
1724 switch (id) {
1725 case vmIntrinsics::_dlog:
1726 trans = _gvn.transform((Node*)new (C, 2) LogDNode(arg));
1727 break;
1728 case vmIntrinsics::_dlog10:
1729 trans = _gvn.transform((Node*)new (C, 2) Log10DNode(arg));
1730 break;
1731 default:
1732 assert(false, "bad intrinsic was passed in");
1733 return false;
1734 }
1736 // Push result back on JVM stack
1737 push_pair(trans);
1738 return true;
1739 }
1741 //------------------------------runtime_math-----------------------------
1742 bool LibraryCallKit::runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName) {
1743 Node* a = NULL;
1744 Node* b = NULL;
1746 assert(call_type == OptoRuntime::Math_DD_D_Type() || call_type == OptoRuntime::Math_D_D_Type(),
1747 "must be (DD)D or (D)D type");
1749 // Inputs
1750 _sp += arg_size(); // restore stack pointer
1751 if (call_type == OptoRuntime::Math_DD_D_Type()) {
1752 b = pop_math_arg();
1753 }
1754 a = pop_math_arg();
1756 const TypePtr* no_memory_effects = NULL;
1757 Node* trig = make_runtime_call(RC_LEAF, call_type, funcAddr, funcName,
1758 no_memory_effects,
1759 a, top(), b, b ? top() : NULL);
1760 Node* value = _gvn.transform(new (C, 1) ProjNode(trig, TypeFunc::Parms+0));
1761 #ifdef ASSERT
1762 Node* value_top = _gvn.transform(new (C, 1) ProjNode(trig, TypeFunc::Parms+1));
1763 assert(value_top == top(), "second value must be top");
1764 #endif
1766 push_pair(value);
1767 return true;
1768 }
1770 //------------------------------inline_math_native-----------------------------
1771 bool LibraryCallKit::inline_math_native(vmIntrinsics::ID id) {
1772 switch (id) {
1773 // These intrinsics are not properly supported on all hardware
1774 case vmIntrinsics::_dcos: return Matcher::has_match_rule(Op_CosD) ? inline_trig(id) :
1775 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dcos), "COS");
1776 case vmIntrinsics::_dsin: return Matcher::has_match_rule(Op_SinD) ? inline_trig(id) :
1777 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dsin), "SIN");
1778 case vmIntrinsics::_dtan: return Matcher::has_match_rule(Op_TanD) ? inline_trig(id) :
1779 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dtan), "TAN");
1781 case vmIntrinsics::_dlog: return Matcher::has_match_rule(Op_LogD) ? inline_trans(id) :
1782 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dlog), "LOG");
1783 case vmIntrinsics::_dlog10: return Matcher::has_match_rule(Op_Log10D) ? inline_trans(id) :
1784 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dlog10), "LOG10");
1786 // These intrinsics are supported on all hardware
1787 case vmIntrinsics::_dsqrt: return Matcher::has_match_rule(Op_SqrtD) ? inline_sqrt(id) : false;
1788 case vmIntrinsics::_dabs: return Matcher::has_match_rule(Op_AbsD) ? inline_abs(id) : false;
1790 case vmIntrinsics::_dexp: return
1791 Matcher::has_match_rule(Op_ExpD) ? inline_exp(id) :
1792 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dexp), "EXP");
1793 case vmIntrinsics::_dpow: return
1794 Matcher::has_match_rule(Op_PowD) ? inline_pow(id) :
1795 runtime_math(OptoRuntime::Math_DD_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dpow), "POW");
1797 // These intrinsics are not yet correctly implemented
1798 case vmIntrinsics::_datan2:
1799 return false;
1801 default:
1802 ShouldNotReachHere();
1803 return false;
1804 }
1805 }
1807 static bool is_simple_name(Node* n) {
1808 return (n->req() == 1 // constant
1809 || (n->is_Type() && n->as_Type()->type()->singleton())
1810 || n->is_Proj() // parameter or return value
1811 || n->is_Phi() // local of some sort
1812 );
1813 }
1815 //----------------------------inline_min_max-----------------------------------
1816 bool LibraryCallKit::inline_min_max(vmIntrinsics::ID id) {
1817 push(generate_min_max(id, argument(0), argument(1)));
1819 return true;
1820 }
1822 Node*
1823 LibraryCallKit::generate_min_max(vmIntrinsics::ID id, Node* x0, Node* y0) {
1824 // These are the candidate return value:
1825 Node* xvalue = x0;
1826 Node* yvalue = y0;
1828 if (xvalue == yvalue) {
1829 return xvalue;
1830 }
1832 bool want_max = (id == vmIntrinsics::_max);
1834 const TypeInt* txvalue = _gvn.type(xvalue)->isa_int();
1835 const TypeInt* tyvalue = _gvn.type(yvalue)->isa_int();
1836 if (txvalue == NULL || tyvalue == NULL) return top();
1837 // This is not really necessary, but it is consistent with a
1838 // hypothetical MaxINode::Value method:
1839 int widen = MAX2(txvalue->_widen, tyvalue->_widen);
1841 // %%% This folding logic should (ideally) be in a different place.
1842 // Some should be inside IfNode, and there to be a more reliable
1843 // transformation of ?: style patterns into cmoves. We also want
1844 // more powerful optimizations around cmove and min/max.
1846 // Try to find a dominating comparison of these guys.
1847 // It can simplify the index computation for Arrays.copyOf
1848 // and similar uses of System.arraycopy.
1849 // First, compute the normalized version of CmpI(x, y).
1850 int cmp_op = Op_CmpI;
1851 Node* xkey = xvalue;
1852 Node* ykey = yvalue;
1853 Node* ideal_cmpxy = _gvn.transform( new(C, 3) CmpINode(xkey, ykey) );
1854 if (ideal_cmpxy->is_Cmp()) {
1855 // E.g., if we have CmpI(length - offset, count),
1856 // it might idealize to CmpI(length, count + offset)
1857 cmp_op = ideal_cmpxy->Opcode();
1858 xkey = ideal_cmpxy->in(1);
1859 ykey = ideal_cmpxy->in(2);
1860 }
1862 // Start by locating any relevant comparisons.
1863 Node* start_from = (xkey->outcnt() < ykey->outcnt()) ? xkey : ykey;
1864 Node* cmpxy = NULL;
1865 Node* cmpyx = NULL;
1866 for (DUIterator_Fast kmax, k = start_from->fast_outs(kmax); k < kmax; k++) {
1867 Node* cmp = start_from->fast_out(k);
1868 if (cmp->outcnt() > 0 && // must have prior uses
1869 cmp->in(0) == NULL && // must be context-independent
1870 cmp->Opcode() == cmp_op) { // right kind of compare
1871 if (cmp->in(1) == xkey && cmp->in(2) == ykey) cmpxy = cmp;
1872 if (cmp->in(1) == ykey && cmp->in(2) == xkey) cmpyx = cmp;
1873 }
1874 }
1876 const int NCMPS = 2;
1877 Node* cmps[NCMPS] = { cmpxy, cmpyx };
1878 int cmpn;
1879 for (cmpn = 0; cmpn < NCMPS; cmpn++) {
1880 if (cmps[cmpn] != NULL) break; // find a result
1881 }
1882 if (cmpn < NCMPS) {
1883 // Look for a dominating test that tells us the min and max.
1884 int depth = 0; // Limit search depth for speed
1885 Node* dom = control();
1886 for (; dom != NULL; dom = IfNode::up_one_dom(dom, true)) {
1887 if (++depth >= 100) break;
1888 Node* ifproj = dom;
1889 if (!ifproj->is_Proj()) continue;
1890 Node* iff = ifproj->in(0);
1891 if (!iff->is_If()) continue;
1892 Node* bol = iff->in(1);
1893 if (!bol->is_Bool()) continue;
1894 Node* cmp = bol->in(1);
1895 if (cmp == NULL) continue;
1896 for (cmpn = 0; cmpn < NCMPS; cmpn++)
1897 if (cmps[cmpn] == cmp) break;
1898 if (cmpn == NCMPS) continue;
1899 BoolTest::mask btest = bol->as_Bool()->_test._test;
1900 if (ifproj->is_IfFalse()) btest = BoolTest(btest).negate();
1901 if (cmp->in(1) == ykey) btest = BoolTest(btest).commute();
1902 // At this point, we know that 'x btest y' is true.
1903 switch (btest) {
1904 case BoolTest::eq:
1905 // They are proven equal, so we can collapse the min/max.
1906 // Either value is the answer. Choose the simpler.
1907 if (is_simple_name(yvalue) && !is_simple_name(xvalue))
1908 return yvalue;
1909 return xvalue;
1910 case BoolTest::lt: // x < y
1911 case BoolTest::le: // x <= y
1912 return (want_max ? yvalue : xvalue);
1913 case BoolTest::gt: // x > y
1914 case BoolTest::ge: // x >= y
1915 return (want_max ? xvalue : yvalue);
1916 }
1917 }
1918 }
1920 // We failed to find a dominating test.
1921 // Let's pick a test that might GVN with prior tests.
1922 Node* best_bol = NULL;
1923 BoolTest::mask best_btest = BoolTest::illegal;
1924 for (cmpn = 0; cmpn < NCMPS; cmpn++) {
1925 Node* cmp = cmps[cmpn];
1926 if (cmp == NULL) continue;
1927 for (DUIterator_Fast jmax, j = cmp->fast_outs(jmax); j < jmax; j++) {
1928 Node* bol = cmp->fast_out(j);
1929 if (!bol->is_Bool()) continue;
1930 BoolTest::mask btest = bol->as_Bool()->_test._test;
1931 if (btest == BoolTest::eq || btest == BoolTest::ne) continue;
1932 if (cmp->in(1) == ykey) btest = BoolTest(btest).commute();
1933 if (bol->outcnt() > (best_bol == NULL ? 0 : best_bol->outcnt())) {
1934 best_bol = bol->as_Bool();
1935 best_btest = btest;
1936 }
1937 }
1938 }
1940 Node* answer_if_true = NULL;
1941 Node* answer_if_false = NULL;
1942 switch (best_btest) {
1943 default:
1944 if (cmpxy == NULL)
1945 cmpxy = ideal_cmpxy;
1946 best_bol = _gvn.transform( new(C, 2) BoolNode(cmpxy, BoolTest::lt) );
1947 // and fall through:
1948 case BoolTest::lt: // x < y
1949 case BoolTest::le: // x <= y
1950 answer_if_true = (want_max ? yvalue : xvalue);
1951 answer_if_false = (want_max ? xvalue : yvalue);
1952 break;
1953 case BoolTest::gt: // x > y
1954 case BoolTest::ge: // x >= y
1955 answer_if_true = (want_max ? xvalue : yvalue);
1956 answer_if_false = (want_max ? yvalue : xvalue);
1957 break;
1958 }
1960 jint hi, lo;
1961 if (want_max) {
1962 // We can sharpen the minimum.
1963 hi = MAX2(txvalue->_hi, tyvalue->_hi);
1964 lo = MAX2(txvalue->_lo, tyvalue->_lo);
1965 } else {
1966 // We can sharpen the maximum.
1967 hi = MIN2(txvalue->_hi, tyvalue->_hi);
1968 lo = MIN2(txvalue->_lo, tyvalue->_lo);
1969 }
1971 // Use a flow-free graph structure, to avoid creating excess control edges
1972 // which could hinder other optimizations.
1973 // Since Math.min/max is often used with arraycopy, we want
1974 // tightly_coupled_allocation to be able to see beyond min/max expressions.
1975 Node* cmov = CMoveNode::make(C, NULL, best_bol,
1976 answer_if_false, answer_if_true,
1977 TypeInt::make(lo, hi, widen));
1979 return _gvn.transform(cmov);
1981 /*
1982 // This is not as desirable as it may seem, since Min and Max
1983 // nodes do not have a full set of optimizations.
1984 // And they would interfere, anyway, with 'if' optimizations
1985 // and with CMoveI canonical forms.
1986 switch (id) {
1987 case vmIntrinsics::_min:
1988 result_val = _gvn.transform(new (C, 3) MinINode(x,y)); break;
1989 case vmIntrinsics::_max:
1990 result_val = _gvn.transform(new (C, 3) MaxINode(x,y)); break;
1991 default:
1992 ShouldNotReachHere();
1993 }
1994 */
1995 }
1997 inline int
1998 LibraryCallKit::classify_unsafe_addr(Node* &base, Node* &offset) {
1999 const TypePtr* base_type = TypePtr::NULL_PTR;
2000 if (base != NULL) base_type = _gvn.type(base)->isa_ptr();
2001 if (base_type == NULL) {
2002 // Unknown type.
2003 return Type::AnyPtr;
2004 } else if (base_type == TypePtr::NULL_PTR) {
2005 // Since this is a NULL+long form, we have to switch to a rawptr.
2006 base = _gvn.transform( new (C, 2) CastX2PNode(offset) );
2007 offset = MakeConX(0);
2008 return Type::RawPtr;
2009 } else if (base_type->base() == Type::RawPtr) {
2010 return Type::RawPtr;
2011 } else if (base_type->isa_oopptr()) {
2012 // Base is never null => always a heap address.
2013 if (base_type->ptr() == TypePtr::NotNull) {
2014 return Type::OopPtr;
2015 }
2016 // Offset is small => always a heap address.
2017 const TypeX* offset_type = _gvn.type(offset)->isa_intptr_t();
2018 if (offset_type != NULL &&
2019 base_type->offset() == 0 && // (should always be?)
2020 offset_type->_lo >= 0 &&
2021 !MacroAssembler::needs_explicit_null_check(offset_type->_hi)) {
2022 return Type::OopPtr;
2023 }
2024 // Otherwise, it might either be oop+off or NULL+addr.
2025 return Type::AnyPtr;
2026 } else {
2027 // No information:
2028 return Type::AnyPtr;
2029 }
2030 }
2032 inline Node* LibraryCallKit::make_unsafe_address(Node* base, Node* offset) {
2033 int kind = classify_unsafe_addr(base, offset);
2034 if (kind == Type::RawPtr) {
2035 return basic_plus_adr(top(), base, offset);
2036 } else {
2037 return basic_plus_adr(base, offset);
2038 }
2039 }
2041 //-------------------inline_numberOfLeadingZeros_int/long-----------------------
2042 // inline int Integer.numberOfLeadingZeros(int)
2043 // inline int Long.numberOfLeadingZeros(long)
2044 bool LibraryCallKit::inline_numberOfLeadingZeros(vmIntrinsics::ID id) {
2045 assert(id == vmIntrinsics::_numberOfLeadingZeros_i || id == vmIntrinsics::_numberOfLeadingZeros_l, "not numberOfLeadingZeros");
2046 if (id == vmIntrinsics::_numberOfLeadingZeros_i && !Matcher::match_rule_supported(Op_CountLeadingZerosI)) return false;
2047 if (id == vmIntrinsics::_numberOfLeadingZeros_l && !Matcher::match_rule_supported(Op_CountLeadingZerosL)) return false;
2048 _sp += arg_size(); // restore stack pointer
2049 switch (id) {
2050 case vmIntrinsics::_numberOfLeadingZeros_i:
2051 push(_gvn.transform(new (C, 2) CountLeadingZerosINode(pop())));
2052 break;
2053 case vmIntrinsics::_numberOfLeadingZeros_l:
2054 push(_gvn.transform(new (C, 2) CountLeadingZerosLNode(pop_pair())));
2055 break;
2056 default:
2057 ShouldNotReachHere();
2058 }
2059 return true;
2060 }
2062 //-------------------inline_numberOfTrailingZeros_int/long----------------------
2063 // inline int Integer.numberOfTrailingZeros(int)
2064 // inline int Long.numberOfTrailingZeros(long)
2065 bool LibraryCallKit::inline_numberOfTrailingZeros(vmIntrinsics::ID id) {
2066 assert(id == vmIntrinsics::_numberOfTrailingZeros_i || id == vmIntrinsics::_numberOfTrailingZeros_l, "not numberOfTrailingZeros");
2067 if (id == vmIntrinsics::_numberOfTrailingZeros_i && !Matcher::match_rule_supported(Op_CountTrailingZerosI)) return false;
2068 if (id == vmIntrinsics::_numberOfTrailingZeros_l && !Matcher::match_rule_supported(Op_CountTrailingZerosL)) return false;
2069 _sp += arg_size(); // restore stack pointer
2070 switch (id) {
2071 case vmIntrinsics::_numberOfTrailingZeros_i:
2072 push(_gvn.transform(new (C, 2) CountTrailingZerosINode(pop())));
2073 break;
2074 case vmIntrinsics::_numberOfTrailingZeros_l:
2075 push(_gvn.transform(new (C, 2) CountTrailingZerosLNode(pop_pair())));
2076 break;
2077 default:
2078 ShouldNotReachHere();
2079 }
2080 return true;
2081 }
2083 //----------------------------inline_bitCount_int/long-----------------------
2084 // inline int Integer.bitCount(int)
2085 // inline int Long.bitCount(long)
2086 bool LibraryCallKit::inline_bitCount(vmIntrinsics::ID id) {
2087 assert(id == vmIntrinsics::_bitCount_i || id == vmIntrinsics::_bitCount_l, "not bitCount");
2088 if (id == vmIntrinsics::_bitCount_i && !Matcher::has_match_rule(Op_PopCountI)) return false;
2089 if (id == vmIntrinsics::_bitCount_l && !Matcher::has_match_rule(Op_PopCountL)) return false;
2090 _sp += arg_size(); // restore stack pointer
2091 switch (id) {
2092 case vmIntrinsics::_bitCount_i:
2093 push(_gvn.transform(new (C, 2) PopCountINode(pop())));
2094 break;
2095 case vmIntrinsics::_bitCount_l:
2096 push(_gvn.transform(new (C, 2) PopCountLNode(pop_pair())));
2097 break;
2098 default:
2099 ShouldNotReachHere();
2100 }
2101 return true;
2102 }
2104 //----------------------------inline_reverseBytes_int/long/char/short-------------------
2105 // inline Integer.reverseBytes(int)
2106 // inline Long.reverseBytes(long)
2107 // inline Character.reverseBytes(char)
2108 // inline Short.reverseBytes(short)
2109 bool LibraryCallKit::inline_reverseBytes(vmIntrinsics::ID id) {
2110 assert(id == vmIntrinsics::_reverseBytes_i || id == vmIntrinsics::_reverseBytes_l ||
2111 id == vmIntrinsics::_reverseBytes_c || id == vmIntrinsics::_reverseBytes_s,
2112 "not reverse Bytes");
2113 if (id == vmIntrinsics::_reverseBytes_i && !Matcher::has_match_rule(Op_ReverseBytesI)) return false;
2114 if (id == vmIntrinsics::_reverseBytes_l && !Matcher::has_match_rule(Op_ReverseBytesL)) return false;
2115 if (id == vmIntrinsics::_reverseBytes_c && !Matcher::has_match_rule(Op_ReverseBytesUS)) return false;
2116 if (id == vmIntrinsics::_reverseBytes_s && !Matcher::has_match_rule(Op_ReverseBytesS)) return false;
2117 _sp += arg_size(); // restore stack pointer
2118 switch (id) {
2119 case vmIntrinsics::_reverseBytes_i:
2120 push(_gvn.transform(new (C, 2) ReverseBytesINode(0, pop())));
2121 break;
2122 case vmIntrinsics::_reverseBytes_l:
2123 push_pair(_gvn.transform(new (C, 2) ReverseBytesLNode(0, pop_pair())));
2124 break;
2125 case vmIntrinsics::_reverseBytes_c:
2126 push(_gvn.transform(new (C, 2) ReverseBytesUSNode(0, pop())));
2127 break;
2128 case vmIntrinsics::_reverseBytes_s:
2129 push(_gvn.transform(new (C, 2) ReverseBytesSNode(0, pop())));
2130 break;
2131 default:
2132 ;
2133 }
2134 return true;
2135 }
2137 //----------------------------inline_unsafe_access----------------------------
2139 const static BasicType T_ADDRESS_HOLDER = T_LONG;
2141 // Helper that guards and inserts a G1 pre-barrier.
2142 void LibraryCallKit::insert_g1_pre_barrier(Node* base_oop, Node* offset, Node* pre_val) {
2143 assert(UseG1GC, "should not call this otherwise");
2145 // We could be accessing the referent field of a reference object. If so, when G1
2146 // is enabled, we need to log the value in the referent field in an SATB buffer.
2147 // This routine performs some compile time filters and generates suitable
2148 // runtime filters that guard the pre-barrier code.
2150 // Some compile time checks.
2152 // If offset is a constant, is it java_lang_ref_Reference::_reference_offset?
2153 const TypeX* otype = offset->find_intptr_t_type();
2154 if (otype != NULL && otype->is_con() &&
2155 otype->get_con() != java_lang_ref_Reference::referent_offset) {
2156 // Constant offset but not the reference_offset so just return
2157 return;
2158 }
2160 // We only need to generate the runtime guards for instances.
2161 const TypeOopPtr* btype = base_oop->bottom_type()->isa_oopptr();
2162 if (btype != NULL) {
2163 if (btype->isa_aryptr()) {
2164 // Array type so nothing to do
2165 return;
2166 }
2168 const TypeInstPtr* itype = btype->isa_instptr();
2169 if (itype != NULL) {
2170 // Can the klass of base_oop be statically determined
2171 // to be _not_ a sub-class of Reference?
2172 ciKlass* klass = itype->klass();
2173 if (klass->is_subtype_of(env()->Reference_klass()) &&
2174 !env()->Reference_klass()->is_subtype_of(klass)) {
2175 return;
2176 }
2177 }
2178 }
2180 // The compile time filters did not reject base_oop/offset so
2181 // we need to generate the following runtime filters
2182 //
2183 // if (offset == java_lang_ref_Reference::_reference_offset) {
2184 // if (base != null) {
2185 // if (instance_of(base, java.lang.ref.Reference)) {
2186 // pre_barrier(_, pre_val, ...);
2187 // }
2188 // }
2189 // }
2191 float likely = PROB_LIKELY(0.999);
2192 float unlikely = PROB_UNLIKELY(0.999);
2194 IdealKit ideal(this);
2195 #define __ ideal.
2197 Node* referent_off = __ ConX(java_lang_ref_Reference::referent_offset);
2199 __ if_then(offset, BoolTest::eq, referent_off, unlikely); {
2200 __ if_then(base_oop, BoolTest::ne, null(), likely); {
2202 // Update graphKit memory and control from IdealKit.
2203 sync_kit(ideal);
2205 Node* ref_klass_con = makecon(TypeKlassPtr::make(env()->Reference_klass()));
2206 Node* is_instof = gen_instanceof(base_oop, ref_klass_con);
2208 // Update IdealKit memory and control from graphKit.
2209 __ sync_kit(this);
2211 Node* one = __ ConI(1);
2213 __ if_then(is_instof, BoolTest::eq, one, unlikely); {
2215 // Update graphKit from IdeakKit.
2216 sync_kit(ideal);
2218 // Use the pre-barrier to record the value in the referent field
2219 pre_barrier(false /* do_load */,
2220 __ ctrl(),
2221 NULL /* obj */, NULL /* adr */, max_juint /* alias_idx */, NULL /* val */, NULL /* val_type */,
2222 pre_val /* pre_val */,
2223 T_OBJECT);
2225 // Update IdealKit from graphKit.
2226 __ sync_kit(this);
2228 } __ end_if(); // _ref_type != ref_none
2229 } __ end_if(); // base != NULL
2230 } __ end_if(); // offset == referent_offset
2232 // Final sync IdealKit and GraphKit.
2233 final_sync(ideal);
2234 #undef __
2235 }
2238 // Interpret Unsafe.fieldOffset cookies correctly:
2239 extern jlong Unsafe_field_offset_to_byte_offset(jlong field_offset);
2241 bool LibraryCallKit::inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile) {
2242 if (callee()->is_static()) return false; // caller must have the capability!
2244 #ifndef PRODUCT
2245 {
2246 ResourceMark rm;
2247 // Check the signatures.
2248 ciSignature* sig = signature();
2249 #ifdef ASSERT
2250 if (!is_store) {
2251 // Object getObject(Object base, int/long offset), etc.
2252 BasicType rtype = sig->return_type()->basic_type();
2253 if (rtype == T_ADDRESS_HOLDER && callee()->name() == ciSymbol::getAddress_name())
2254 rtype = T_ADDRESS; // it is really a C void*
2255 assert(rtype == type, "getter must return the expected value");
2256 if (!is_native_ptr) {
2257 assert(sig->count() == 2, "oop getter has 2 arguments");
2258 assert(sig->type_at(0)->basic_type() == T_OBJECT, "getter base is object");
2259 assert(sig->type_at(1)->basic_type() == T_LONG, "getter offset is correct");
2260 } else {
2261 assert(sig->count() == 1, "native getter has 1 argument");
2262 assert(sig->type_at(0)->basic_type() == T_LONG, "getter base is long");
2263 }
2264 } else {
2265 // void putObject(Object base, int/long offset, Object x), etc.
2266 assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value");
2267 if (!is_native_ptr) {
2268 assert(sig->count() == 3, "oop putter has 3 arguments");
2269 assert(sig->type_at(0)->basic_type() == T_OBJECT, "putter base is object");
2270 assert(sig->type_at(1)->basic_type() == T_LONG, "putter offset is correct");
2271 } else {
2272 assert(sig->count() == 2, "native putter has 2 arguments");
2273 assert(sig->type_at(0)->basic_type() == T_LONG, "putter base is long");
2274 }
2275 BasicType vtype = sig->type_at(sig->count()-1)->basic_type();
2276 if (vtype == T_ADDRESS_HOLDER && callee()->name() == ciSymbol::putAddress_name())
2277 vtype = T_ADDRESS; // it is really a C void*
2278 assert(vtype == type, "putter must accept the expected value");
2279 }
2280 #endif // ASSERT
2281 }
2282 #endif //PRODUCT
2284 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
2286 int type_words = type2size[ (type == T_ADDRESS) ? T_LONG : type ];
2288 // Argument words: "this" plus (oop/offset) or (lo/hi) args plus maybe 1 or 2 value words
2289 int nargs = 1 + (is_native_ptr ? 2 : 3) + (is_store ? type_words : 0);
2291 debug_only(int saved_sp = _sp);
2292 _sp += nargs;
2294 Node* val;
2295 debug_only(val = (Node*)(uintptr_t)-1);
2298 if (is_store) {
2299 // Get the value being stored. (Pop it first; it was pushed last.)
2300 switch (type) {
2301 case T_DOUBLE:
2302 case T_LONG:
2303 case T_ADDRESS:
2304 val = pop_pair();
2305 break;
2306 default:
2307 val = pop();
2308 }
2309 }
2311 // Build address expression. See the code in inline_unsafe_prefetch.
2312 Node *adr;
2313 Node *heap_base_oop = top();
2314 Node* offset = top();
2316 if (!is_native_ptr) {
2317 // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset
2318 offset = pop_pair();
2319 // The base is either a Java object or a value produced by Unsafe.staticFieldBase
2320 Node* base = pop();
2321 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
2322 // to be plain byte offsets, which are also the same as those accepted
2323 // by oopDesc::field_base.
2324 assert(Unsafe_field_offset_to_byte_offset(11) == 11,
2325 "fieldOffset must be byte-scaled");
2326 // 32-bit machines ignore the high half!
2327 offset = ConvL2X(offset);
2328 adr = make_unsafe_address(base, offset);
2329 heap_base_oop = base;
2330 } else {
2331 Node* ptr = pop_pair();
2332 // Adjust Java long to machine word:
2333 ptr = ConvL2X(ptr);
2334 adr = make_unsafe_address(NULL, ptr);
2335 }
2337 // Pop receiver last: it was pushed first.
2338 Node *receiver = pop();
2340 assert(saved_sp == _sp, "must have correct argument count");
2342 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
2344 // First guess at the value type.
2345 const Type *value_type = Type::get_const_basic_type(type);
2347 // Try to categorize the address. If it comes up as TypeJavaPtr::BOTTOM,
2348 // there was not enough information to nail it down.
2349 Compile::AliasType* alias_type = C->alias_type(adr_type);
2350 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
2352 // We will need memory barriers unless we can determine a unique
2353 // alias category for this reference. (Note: If for some reason
2354 // the barriers get omitted and the unsafe reference begins to "pollute"
2355 // the alias analysis of the rest of the graph, either Compile::can_alias
2356 // or Compile::must_alias will throw a diagnostic assert.)
2357 bool need_mem_bar = (alias_type->adr_type() == TypeOopPtr::BOTTOM);
2359 // If we are reading the value of the referent field of a Reference
2360 // object (either by using Unsafe directly or through reflection)
2361 // then, if G1 is enabled, we need to record the referent in an
2362 // SATB log buffer using the pre-barrier mechanism.
2363 bool need_read_barrier = UseG1GC && !is_native_ptr && !is_store &&
2364 offset != top() && heap_base_oop != top();
2366 if (!is_store && type == T_OBJECT) {
2367 // Attempt to infer a sharper value type from the offset and base type.
2368 ciKlass* sharpened_klass = NULL;
2370 // See if it is an instance field, with an object type.
2371 if (alias_type->field() != NULL) {
2372 assert(!is_native_ptr, "native pointer op cannot use a java address");
2373 if (alias_type->field()->type()->is_klass()) {
2374 sharpened_klass = alias_type->field()->type()->as_klass();
2375 }
2376 }
2378 // See if it is a narrow oop array.
2379 if (adr_type->isa_aryptr()) {
2380 if (adr_type->offset() >= objArrayOopDesc::base_offset_in_bytes()) {
2381 const TypeOopPtr *elem_type = adr_type->is_aryptr()->elem()->isa_oopptr();
2382 if (elem_type != NULL) {
2383 sharpened_klass = elem_type->klass();
2384 }
2385 }
2386 }
2388 if (sharpened_klass != NULL) {
2389 const TypeOopPtr* tjp = TypeOopPtr::make_from_klass(sharpened_klass);
2391 // Sharpen the value type.
2392 value_type = tjp;
2394 #ifndef PRODUCT
2395 if (PrintIntrinsics || PrintInlining || PrintOptoInlining) {
2396 tty->print(" from base type: "); adr_type->dump();
2397 tty->print(" sharpened value: "); value_type->dump();
2398 }
2399 #endif
2400 }
2401 }
2403 // Null check on self without removing any arguments. The argument
2404 // null check technically happens in the wrong place, which can lead to
2405 // invalid stack traces when the primitive is inlined into a method
2406 // which handles NullPointerExceptions.
2407 _sp += nargs;
2408 do_null_check(receiver, T_OBJECT);
2409 _sp -= nargs;
2410 if (stopped()) {
2411 return true;
2412 }
2413 // Heap pointers get a null-check from the interpreter,
2414 // as a courtesy. However, this is not guaranteed by Unsafe,
2415 // and it is not possible to fully distinguish unintended nulls
2416 // from intended ones in this API.
2418 if (is_volatile) {
2419 // We need to emit leading and trailing CPU membars (see below) in
2420 // addition to memory membars when is_volatile. This is a little
2421 // too strong, but avoids the need to insert per-alias-type
2422 // volatile membars (for stores; compare Parse::do_put_xxx), which
2423 // we cannot do effectively here because we probably only have a
2424 // rough approximation of type.
2425 need_mem_bar = true;
2426 // For Stores, place a memory ordering barrier now.
2427 if (is_store)
2428 insert_mem_bar(Op_MemBarRelease);
2429 }
2431 // Memory barrier to prevent normal and 'unsafe' accesses from
2432 // bypassing each other. Happens after null checks, so the
2433 // exception paths do not take memory state from the memory barrier,
2434 // so there's no problems making a strong assert about mixing users
2435 // of safe & unsafe memory. Otherwise fails in a CTW of rt.jar
2436 // around 5701, class sun/reflect/UnsafeBooleanFieldAccessorImpl.
2437 if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder);
2439 if (!is_store) {
2440 Node* p = make_load(control(), adr, value_type, type, adr_type, is_volatile);
2441 // load value and push onto stack
2442 switch (type) {
2443 case T_BOOLEAN:
2444 case T_CHAR:
2445 case T_BYTE:
2446 case T_SHORT:
2447 case T_INT:
2448 case T_FLOAT:
2449 push(p);
2450 break;
2451 case T_OBJECT:
2452 if (need_read_barrier) {
2453 insert_g1_pre_barrier(heap_base_oop, offset, p);
2454 }
2455 push(p);
2456 break;
2457 case T_ADDRESS:
2458 // Cast to an int type.
2459 p = _gvn.transform( new (C, 2) CastP2XNode(NULL,p) );
2460 p = ConvX2L(p);
2461 push_pair(p);
2462 break;
2463 case T_DOUBLE:
2464 case T_LONG:
2465 push_pair( p );
2466 break;
2467 default: ShouldNotReachHere();
2468 }
2469 } else {
2470 // place effect of store into memory
2471 switch (type) {
2472 case T_DOUBLE:
2473 val = dstore_rounding(val);
2474 break;
2475 case T_ADDRESS:
2476 // Repackage the long as a pointer.
2477 val = ConvL2X(val);
2478 val = _gvn.transform( new (C, 2) CastX2PNode(val) );
2479 break;
2480 }
2482 if (type != T_OBJECT ) {
2483 (void) store_to_memory(control(), adr, val, type, adr_type, is_volatile);
2484 } else {
2485 // Possibly an oop being stored to Java heap or native memory
2486 if (!TypePtr::NULL_PTR->higher_equal(_gvn.type(heap_base_oop))) {
2487 // oop to Java heap.
2488 (void) store_oop_to_unknown(control(), heap_base_oop, adr, adr_type, val, type);
2489 } else {
2490 // We can't tell at compile time if we are storing in the Java heap or outside
2491 // of it. So we need to emit code to conditionally do the proper type of
2492 // store.
2494 IdealKit ideal(this);
2495 #define __ ideal.
2496 // QQQ who knows what probability is here??
2497 __ if_then(heap_base_oop, BoolTest::ne, null(), PROB_UNLIKELY(0.999)); {
2498 // Sync IdealKit and graphKit.
2499 sync_kit(ideal);
2500 Node* st = store_oop_to_unknown(control(), heap_base_oop, adr, adr_type, val, type);
2501 // Update IdealKit memory.
2502 __ sync_kit(this);
2503 } __ else_(); {
2504 __ store(__ ctrl(), adr, val, type, alias_type->index(), is_volatile);
2505 } __ end_if();
2506 // Final sync IdealKit and GraphKit.
2507 final_sync(ideal);
2508 #undef __
2509 }
2510 }
2511 }
2513 if (is_volatile) {
2514 if (!is_store)
2515 insert_mem_bar(Op_MemBarAcquire);
2516 else
2517 insert_mem_bar(Op_MemBarVolatile);
2518 }
2520 if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder);
2522 return true;
2523 }
2525 //----------------------------inline_unsafe_prefetch----------------------------
2527 bool LibraryCallKit::inline_unsafe_prefetch(bool is_native_ptr, bool is_store, bool is_static) {
2528 #ifndef PRODUCT
2529 {
2530 ResourceMark rm;
2531 // Check the signatures.
2532 ciSignature* sig = signature();
2533 #ifdef ASSERT
2534 // Object getObject(Object base, int/long offset), etc.
2535 BasicType rtype = sig->return_type()->basic_type();
2536 if (!is_native_ptr) {
2537 assert(sig->count() == 2, "oop prefetch has 2 arguments");
2538 assert(sig->type_at(0)->basic_type() == T_OBJECT, "prefetch base is object");
2539 assert(sig->type_at(1)->basic_type() == T_LONG, "prefetcha offset is correct");
2540 } else {
2541 assert(sig->count() == 1, "native prefetch has 1 argument");
2542 assert(sig->type_at(0)->basic_type() == T_LONG, "prefetch base is long");
2543 }
2544 #endif // ASSERT
2545 }
2546 #endif // !PRODUCT
2548 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
2550 // Argument words: "this" if not static, plus (oop/offset) or (lo/hi) args
2551 int nargs = (is_static ? 0 : 1) + (is_native_ptr ? 2 : 3);
2553 debug_only(int saved_sp = _sp);
2554 _sp += nargs;
2556 // Build address expression. See the code in inline_unsafe_access.
2557 Node *adr;
2558 if (!is_native_ptr) {
2559 // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset
2560 Node* offset = pop_pair();
2561 // The base is either a Java object or a value produced by Unsafe.staticFieldBase
2562 Node* base = pop();
2563 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
2564 // to be plain byte offsets, which are also the same as those accepted
2565 // by oopDesc::field_base.
2566 assert(Unsafe_field_offset_to_byte_offset(11) == 11,
2567 "fieldOffset must be byte-scaled");
2568 // 32-bit machines ignore the high half!
2569 offset = ConvL2X(offset);
2570 adr = make_unsafe_address(base, offset);
2571 } else {
2572 Node* ptr = pop_pair();
2573 // Adjust Java long to machine word:
2574 ptr = ConvL2X(ptr);
2575 adr = make_unsafe_address(NULL, ptr);
2576 }
2578 if (is_static) {
2579 assert(saved_sp == _sp, "must have correct argument count");
2580 } else {
2581 // Pop receiver last: it was pushed first.
2582 Node *receiver = pop();
2583 assert(saved_sp == _sp, "must have correct argument count");
2585 // Null check on self without removing any arguments. The argument
2586 // null check technically happens in the wrong place, which can lead to
2587 // invalid stack traces when the primitive is inlined into a method
2588 // which handles NullPointerExceptions.
2589 _sp += nargs;
2590 do_null_check(receiver, T_OBJECT);
2591 _sp -= nargs;
2592 if (stopped()) {
2593 return true;
2594 }
2595 }
2597 // Generate the read or write prefetch
2598 Node *prefetch;
2599 if (is_store) {
2600 prefetch = new (C, 3) PrefetchWriteNode(i_o(), adr);
2601 } else {
2602 prefetch = new (C, 3) PrefetchReadNode(i_o(), adr);
2603 }
2604 prefetch->init_req(0, control());
2605 set_i_o(_gvn.transform(prefetch));
2607 return true;
2608 }
2610 //----------------------------inline_unsafe_CAS----------------------------
2612 bool LibraryCallKit::inline_unsafe_CAS(BasicType type) {
2613 // This basic scheme here is the same as inline_unsafe_access, but
2614 // differs in enough details that combining them would make the code
2615 // overly confusing. (This is a true fact! I originally combined
2616 // them, but even I was confused by it!) As much code/comments as
2617 // possible are retained from inline_unsafe_access though to make
2618 // the correspondences clearer. - dl
2620 if (callee()->is_static()) return false; // caller must have the capability!
2622 #ifndef PRODUCT
2623 {
2624 ResourceMark rm;
2625 // Check the signatures.
2626 ciSignature* sig = signature();
2627 #ifdef ASSERT
2628 BasicType rtype = sig->return_type()->basic_type();
2629 assert(rtype == T_BOOLEAN, "CAS must return boolean");
2630 assert(sig->count() == 4, "CAS has 4 arguments");
2631 assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object");
2632 assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long");
2633 #endif // ASSERT
2634 }
2635 #endif //PRODUCT
2637 // number of stack slots per value argument (1 or 2)
2638 int type_words = type2size[type];
2640 // Cannot inline wide CAS on machines that don't support it natively
2641 if (type2aelembytes(type) > BytesPerInt && !VM_Version::supports_cx8())
2642 return false;
2644 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
2646 // Argument words: "this" plus oop plus offset plus oldvalue plus newvalue;
2647 int nargs = 1 + 1 + 2 + type_words + type_words;
2649 // pop arguments: newval, oldval, offset, base, and receiver
2650 debug_only(int saved_sp = _sp);
2651 _sp += nargs;
2652 Node* newval = (type_words == 1) ? pop() : pop_pair();
2653 Node* oldval = (type_words == 1) ? pop() : pop_pair();
2654 Node *offset = pop_pair();
2655 Node *base = pop();
2656 Node *receiver = pop();
2657 assert(saved_sp == _sp, "must have correct argument count");
2659 // Null check receiver.
2660 _sp += nargs;
2661 do_null_check(receiver, T_OBJECT);
2662 _sp -= nargs;
2663 if (stopped()) {
2664 return true;
2665 }
2667 // Build field offset expression.
2668 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
2669 // to be plain byte offsets, which are also the same as those accepted
2670 // by oopDesc::field_base.
2671 assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled");
2672 // 32-bit machines ignore the high half of long offsets
2673 offset = ConvL2X(offset);
2674 Node* adr = make_unsafe_address(base, offset);
2675 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
2677 // (Unlike inline_unsafe_access, there seems no point in trying
2678 // to refine types. Just use the coarse types here.
2679 const Type *value_type = Type::get_const_basic_type(type);
2680 Compile::AliasType* alias_type = C->alias_type(adr_type);
2681 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
2682 int alias_idx = C->get_alias_index(adr_type);
2684 // Memory-model-wise, a CAS acts like a little synchronized block,
2685 // so needs barriers on each side. These don't translate into
2686 // actual barriers on most machines, but we still need rest of
2687 // compiler to respect ordering.
2689 insert_mem_bar(Op_MemBarRelease);
2690 insert_mem_bar(Op_MemBarCPUOrder);
2692 // 4984716: MemBars must be inserted before this
2693 // memory node in order to avoid a false
2694 // dependency which will confuse the scheduler.
2695 Node *mem = memory(alias_idx);
2697 // For now, we handle only those cases that actually exist: ints,
2698 // longs, and Object. Adding others should be straightforward.
2699 Node* cas;
2700 switch(type) {
2701 case T_INT:
2702 cas = _gvn.transform(new (C, 5) CompareAndSwapINode(control(), mem, adr, newval, oldval));
2703 break;
2704 case T_LONG:
2705 cas = _gvn.transform(new (C, 5) CompareAndSwapLNode(control(), mem, adr, newval, oldval));
2706 break;
2707 case T_OBJECT:
2708 // Transformation of a value which could be NULL pointer (CastPP #NULL)
2709 // could be delayed during Parse (for example, in adjust_map_after_if()).
2710 // Execute transformation here to avoid barrier generation in such case.
2711 if (_gvn.type(newval) == TypePtr::NULL_PTR)
2712 newval = _gvn.makecon(TypePtr::NULL_PTR);
2714 // Reference stores need a store barrier.
2715 // (They don't if CAS fails, but it isn't worth checking.)
2716 pre_barrier(true /* do_load*/,
2717 control(), base, adr, alias_idx, newval, value_type->make_oopptr(),
2718 NULL /* pre_val*/,
2719 T_OBJECT);
2720 #ifdef _LP64
2721 if (adr->bottom_type()->is_ptr_to_narrowoop()) {
2722 Node *newval_enc = _gvn.transform(new (C, 2) EncodePNode(newval, newval->bottom_type()->make_narrowoop()));
2723 Node *oldval_enc = _gvn.transform(new (C, 2) EncodePNode(oldval, oldval->bottom_type()->make_narrowoop()));
2724 cas = _gvn.transform(new (C, 5) CompareAndSwapNNode(control(), mem, adr,
2725 newval_enc, oldval_enc));
2726 } else
2727 #endif
2728 {
2729 cas = _gvn.transform(new (C, 5) CompareAndSwapPNode(control(), mem, adr, newval, oldval));
2730 }
2731 post_barrier(control(), cas, base, adr, alias_idx, newval, T_OBJECT, true);
2732 break;
2733 default:
2734 ShouldNotReachHere();
2735 break;
2736 }
2738 // SCMemProjNodes represent the memory state of CAS. Their main
2739 // role is to prevent CAS nodes from being optimized away when their
2740 // results aren't used.
2741 Node* proj = _gvn.transform( new (C, 1) SCMemProjNode(cas));
2742 set_memory(proj, alias_idx);
2744 // Add the trailing membar surrounding the access
2745 insert_mem_bar(Op_MemBarCPUOrder);
2746 insert_mem_bar(Op_MemBarAcquire);
2748 push(cas);
2749 return true;
2750 }
2752 bool LibraryCallKit::inline_unsafe_ordered_store(BasicType type) {
2753 // This is another variant of inline_unsafe_access, differing in
2754 // that it always issues store-store ("release") barrier and ensures
2755 // store-atomicity (which only matters for "long").
2757 if (callee()->is_static()) return false; // caller must have the capability!
2759 #ifndef PRODUCT
2760 {
2761 ResourceMark rm;
2762 // Check the signatures.
2763 ciSignature* sig = signature();
2764 #ifdef ASSERT
2765 BasicType rtype = sig->return_type()->basic_type();
2766 assert(rtype == T_VOID, "must return void");
2767 assert(sig->count() == 3, "has 3 arguments");
2768 assert(sig->type_at(0)->basic_type() == T_OBJECT, "base is object");
2769 assert(sig->type_at(1)->basic_type() == T_LONG, "offset is long");
2770 #endif // ASSERT
2771 }
2772 #endif //PRODUCT
2774 // number of stack slots per value argument (1 or 2)
2775 int type_words = type2size[type];
2777 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
2779 // Argument words: "this" plus oop plus offset plus value;
2780 int nargs = 1 + 1 + 2 + type_words;
2782 // pop arguments: val, offset, base, and receiver
2783 debug_only(int saved_sp = _sp);
2784 _sp += nargs;
2785 Node* val = (type_words == 1) ? pop() : pop_pair();
2786 Node *offset = pop_pair();
2787 Node *base = pop();
2788 Node *receiver = pop();
2789 assert(saved_sp == _sp, "must have correct argument count");
2791 // Null check receiver.
2792 _sp += nargs;
2793 do_null_check(receiver, T_OBJECT);
2794 _sp -= nargs;
2795 if (stopped()) {
2796 return true;
2797 }
2799 // Build field offset expression.
2800 assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled");
2801 // 32-bit machines ignore the high half of long offsets
2802 offset = ConvL2X(offset);
2803 Node* adr = make_unsafe_address(base, offset);
2804 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
2805 const Type *value_type = Type::get_const_basic_type(type);
2806 Compile::AliasType* alias_type = C->alias_type(adr_type);
2808 insert_mem_bar(Op_MemBarRelease);
2809 insert_mem_bar(Op_MemBarCPUOrder);
2810 // Ensure that the store is atomic for longs:
2811 bool require_atomic_access = true;
2812 Node* store;
2813 if (type == T_OBJECT) // reference stores need a store barrier.
2814 store = store_oop_to_unknown(control(), base, adr, adr_type, val, type);
2815 else {
2816 store = store_to_memory(control(), adr, val, type, adr_type, require_atomic_access);
2817 }
2818 insert_mem_bar(Op_MemBarCPUOrder);
2819 return true;
2820 }
2822 bool LibraryCallKit::inline_unsafe_allocate() {
2823 if (callee()->is_static()) return false; // caller must have the capability!
2824 int nargs = 1 + 1;
2825 assert(signature()->size() == nargs-1, "alloc has 1 argument");
2826 null_check_receiver(callee()); // check then ignore argument(0)
2827 _sp += nargs; // set original stack for use by uncommon_trap
2828 Node* cls = do_null_check(argument(1), T_OBJECT);
2829 _sp -= nargs;
2830 if (stopped()) return true;
2832 Node* kls = load_klass_from_mirror(cls, false, nargs, NULL, 0);
2833 _sp += nargs; // set original stack for use by uncommon_trap
2834 kls = do_null_check(kls, T_OBJECT);
2835 _sp -= nargs;
2836 if (stopped()) return true; // argument was like int.class
2838 // Note: The argument might still be an illegal value like
2839 // Serializable.class or Object[].class. The runtime will handle it.
2840 // But we must make an explicit check for initialization.
2841 Node* insp = basic_plus_adr(kls, in_bytes(instanceKlass::init_state_offset()));
2842 // Use T_BOOLEAN for instanceKlass::_init_state so the compiler
2843 // can generate code to load it as unsigned byte.
2844 Node* inst = make_load(NULL, insp, TypeInt::UBYTE, T_BOOLEAN);
2845 Node* bits = intcon(instanceKlass::fully_initialized);
2846 Node* test = _gvn.transform( new (C, 3) SubINode(inst, bits) );
2847 // The 'test' is non-zero if we need to take a slow path.
2849 Node* obj = new_instance(kls, test);
2850 push(obj);
2852 return true;
2853 }
2855 #ifdef TRACE_HAVE_INTRINSICS
2856 /*
2857 * oop -> myklass
2858 * myklass->trace_id |= USED
2859 * return myklass->trace_id & ~0x3
2860 */
2861 bool LibraryCallKit::inline_native_classID() {
2862 int nargs = 1 + 1;
2863 null_check_receiver(callee()); // check then ignore argument(0)
2864 _sp += nargs;
2865 Node* cls = do_null_check(argument(1), T_OBJECT);
2866 _sp -= nargs;
2867 Node* kls = load_klass_from_mirror(cls, false, nargs, NULL, 0);
2868 _sp += nargs;
2869 kls = do_null_check(kls, T_OBJECT);
2870 _sp -= nargs;
2871 ByteSize offset = TRACE_ID_OFFSET;
2872 Node* insp = basic_plus_adr(kls, in_bytes(offset));
2873 Node* tvalue = make_load(NULL, insp, TypeLong::LONG, T_LONG);
2874 Node* bits = longcon(~0x03l); // ignore bit 0 & 1
2875 Node* andl = _gvn.transform(new (C, 3) AndLNode(tvalue, bits));
2876 Node* clsused = longcon(0x01l); // set the class bit
2877 Node* orl = _gvn.transform(new (C, 3) OrLNode(tvalue, clsused));
2879 const TypePtr *adr_type = _gvn.type(insp)->isa_ptr();
2880 store_to_memory(control(), insp, orl, T_LONG, adr_type);
2881 push_pair(andl);
2882 return true;
2883 }
2885 bool LibraryCallKit::inline_native_threadID() {
2886 Node* tls_ptr = NULL;
2887 Node* cur_thr = generate_current_thread(tls_ptr);
2888 Node* p = basic_plus_adr(top()/*!oop*/, tls_ptr, in_bytes(JavaThread::osthread_offset()));
2889 Node* osthread = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS);
2890 p = basic_plus_adr(top()/*!oop*/, osthread, in_bytes(OSThread::thread_id_offset()));
2892 Node* threadid = NULL;
2893 size_t thread_id_size = OSThread::thread_id_size();
2894 if (thread_id_size == (size_t) BytesPerLong) {
2895 threadid = ConvL2I(make_load(control(), p, TypeLong::LONG, T_LONG));
2896 push(threadid);
2897 } else if (thread_id_size == (size_t) BytesPerInt) {
2898 threadid = make_load(control(), p, TypeInt::INT, T_INT);
2899 push(threadid);
2900 } else {
2901 ShouldNotReachHere();
2902 }
2903 return true;
2904 }
2905 #endif
2907 //------------------------inline_native_time_funcs--------------
2908 // inline code for System.currentTimeMillis() and System.nanoTime()
2909 // these have the same type and signature
2910 bool LibraryCallKit::inline_native_time_funcs(address funcAddr, const char* funcName) {
2911 const TypeFunc *tf = OptoRuntime::void_long_Type();
2912 const TypePtr* no_memory_effects = NULL;
2913 Node* time = make_runtime_call(RC_LEAF, tf, funcAddr, funcName, no_memory_effects);
2914 Node* value = _gvn.transform(new (C, 1) ProjNode(time, TypeFunc::Parms+0));
2915 #ifdef ASSERT
2916 Node* value_top = _gvn.transform(new (C, 1) ProjNode(time, TypeFunc::Parms + 1));
2917 assert(value_top == top(), "second value must be top");
2918 #endif
2919 push_pair(value);
2920 return true;
2921 }
2923 //------------------------inline_native_currentThread------------------
2924 bool LibraryCallKit::inline_native_currentThread() {
2925 Node* junk = NULL;
2926 push(generate_current_thread(junk));
2927 return true;
2928 }
2930 //------------------------inline_native_isInterrupted------------------
2931 bool LibraryCallKit::inline_native_isInterrupted() {
2932 const int nargs = 1+1; // receiver + boolean
2933 assert(nargs == arg_size(), "sanity");
2934 // Add a fast path to t.isInterrupted(clear_int):
2935 // (t == Thread.current() && (!TLS._osthread._interrupted || !clear_int))
2936 // ? TLS._osthread._interrupted : /*slow path:*/ t.isInterrupted(clear_int)
2937 // So, in the common case that the interrupt bit is false,
2938 // we avoid making a call into the VM. Even if the interrupt bit
2939 // is true, if the clear_int argument is false, we avoid the VM call.
2940 // However, if the receiver is not currentThread, we must call the VM,
2941 // because there must be some locking done around the operation.
2943 // We only go to the fast case code if we pass two guards.
2944 // Paths which do not pass are accumulated in the slow_region.
2945 RegionNode* slow_region = new (C, 1) RegionNode(1);
2946 record_for_igvn(slow_region);
2947 RegionNode* result_rgn = new (C, 4) RegionNode(1+3); // fast1, fast2, slow
2948 PhiNode* result_val = new (C, 4) PhiNode(result_rgn, TypeInt::BOOL);
2949 enum { no_int_result_path = 1,
2950 no_clear_result_path = 2,
2951 slow_result_path = 3
2952 };
2954 // (a) Receiving thread must be the current thread.
2955 Node* rec_thr = argument(0);
2956 Node* tls_ptr = NULL;
2957 Node* cur_thr = generate_current_thread(tls_ptr);
2958 Node* cmp_thr = _gvn.transform( new (C, 3) CmpPNode(cur_thr, rec_thr) );
2959 Node* bol_thr = _gvn.transform( new (C, 2) BoolNode(cmp_thr, BoolTest::ne) );
2961 bool known_current_thread = (_gvn.type(bol_thr) == TypeInt::ZERO);
2962 if (!known_current_thread)
2963 generate_slow_guard(bol_thr, slow_region);
2965 // (b) Interrupt bit on TLS must be false.
2966 Node* p = basic_plus_adr(top()/*!oop*/, tls_ptr, in_bytes(JavaThread::osthread_offset()));
2967 Node* osthread = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS);
2968 p = basic_plus_adr(top()/*!oop*/, osthread, in_bytes(OSThread::interrupted_offset()));
2969 // Set the control input on the field _interrupted read to prevent it floating up.
2970 Node* int_bit = make_load(control(), p, TypeInt::BOOL, T_INT);
2971 Node* cmp_bit = _gvn.transform( new (C, 3) CmpINode(int_bit, intcon(0)) );
2972 Node* bol_bit = _gvn.transform( new (C, 2) BoolNode(cmp_bit, BoolTest::ne) );
2974 IfNode* iff_bit = create_and_map_if(control(), bol_bit, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN);
2976 // First fast path: if (!TLS._interrupted) return false;
2977 Node* false_bit = _gvn.transform( new (C, 1) IfFalseNode(iff_bit) );
2978 result_rgn->init_req(no_int_result_path, false_bit);
2979 result_val->init_req(no_int_result_path, intcon(0));
2981 // drop through to next case
2982 set_control( _gvn.transform(new (C, 1) IfTrueNode(iff_bit)) );
2984 // (c) Or, if interrupt bit is set and clear_int is false, use 2nd fast path.
2985 Node* clr_arg = argument(1);
2986 Node* cmp_arg = _gvn.transform( new (C, 3) CmpINode(clr_arg, intcon(0)) );
2987 Node* bol_arg = _gvn.transform( new (C, 2) BoolNode(cmp_arg, BoolTest::ne) );
2988 IfNode* iff_arg = create_and_map_if(control(), bol_arg, PROB_FAIR, COUNT_UNKNOWN);
2990 // Second fast path: ... else if (!clear_int) return true;
2991 Node* false_arg = _gvn.transform( new (C, 1) IfFalseNode(iff_arg) );
2992 result_rgn->init_req(no_clear_result_path, false_arg);
2993 result_val->init_req(no_clear_result_path, intcon(1));
2995 // drop through to next case
2996 set_control( _gvn.transform(new (C, 1) IfTrueNode(iff_arg)) );
2998 // (d) Otherwise, go to the slow path.
2999 slow_region->add_req(control());
3000 set_control( _gvn.transform(slow_region) );
3002 if (stopped()) {
3003 // There is no slow path.
3004 result_rgn->init_req(slow_result_path, top());
3005 result_val->init_req(slow_result_path, top());
3006 } else {
3007 // non-virtual because it is a private non-static
3008 CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_isInterrupted);
3010 Node* slow_val = set_results_for_java_call(slow_call);
3011 // this->control() comes from set_results_for_java_call
3013 // If we know that the result of the slow call will be true, tell the optimizer!
3014 if (known_current_thread) slow_val = intcon(1);
3016 Node* fast_io = slow_call->in(TypeFunc::I_O);
3017 Node* fast_mem = slow_call->in(TypeFunc::Memory);
3018 // These two phis are pre-filled with copies of of the fast IO and Memory
3019 Node* io_phi = PhiNode::make(result_rgn, fast_io, Type::ABIO);
3020 Node* mem_phi = PhiNode::make(result_rgn, fast_mem, Type::MEMORY, TypePtr::BOTTOM);
3022 result_rgn->init_req(slow_result_path, control());
3023 io_phi ->init_req(slow_result_path, i_o());
3024 mem_phi ->init_req(slow_result_path, reset_memory());
3025 result_val->init_req(slow_result_path, slow_val);
3027 set_all_memory( _gvn.transform(mem_phi) );
3028 set_i_o( _gvn.transform(io_phi) );
3029 }
3031 push_result(result_rgn, result_val);
3032 C->set_has_split_ifs(true); // Has chance for split-if optimization
3034 return true;
3035 }
3037 //---------------------------load_mirror_from_klass----------------------------
3038 // Given a klass oop, load its java mirror (a java.lang.Class oop).
3039 Node* LibraryCallKit::load_mirror_from_klass(Node* klass) {
3040 Node* p = basic_plus_adr(klass, in_bytes(Klass::java_mirror_offset()));
3041 return make_load(NULL, p, TypeInstPtr::MIRROR, T_OBJECT);
3042 }
3044 //-----------------------load_klass_from_mirror_common-------------------------
3045 // Given a java mirror (a java.lang.Class oop), load its corresponding klass oop.
3046 // Test the klass oop for null (signifying a primitive Class like Integer.TYPE),
3047 // and branch to the given path on the region.
3048 // If never_see_null, take an uncommon trap on null, so we can optimistically
3049 // compile for the non-null case.
3050 // If the region is NULL, force never_see_null = true.
3051 Node* LibraryCallKit::load_klass_from_mirror_common(Node* mirror,
3052 bool never_see_null,
3053 int nargs,
3054 RegionNode* region,
3055 int null_path,
3056 int offset) {
3057 if (region == NULL) never_see_null = true;
3058 Node* p = basic_plus_adr(mirror, offset);
3059 const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL;
3060 Node* kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type) );
3061 _sp += nargs; // any deopt will start just before call to enclosing method
3062 Node* null_ctl = top();
3063 kls = null_check_oop(kls, &null_ctl, never_see_null);
3064 if (region != NULL) {
3065 // Set region->in(null_path) if the mirror is a primitive (e.g, int.class).
3066 region->init_req(null_path, null_ctl);
3067 } else {
3068 assert(null_ctl == top(), "no loose ends");
3069 }
3070 _sp -= nargs;
3071 return kls;
3072 }
3074 //--------------------(inline_native_Class_query helpers)---------------------
3075 // Use this for JVM_ACC_INTERFACE, JVM_ACC_IS_CLONEABLE, JVM_ACC_HAS_FINALIZER.
3076 // Fall through if (mods & mask) == bits, take the guard otherwise.
3077 Node* LibraryCallKit::generate_access_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) {
3078 // Branch around if the given klass has the given modifier bit set.
3079 // Like generate_guard, adds a new path onto the region.
3080 Node* modp = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset()));
3081 Node* mods = make_load(NULL, modp, TypeInt::INT, T_INT);
3082 Node* mask = intcon(modifier_mask);
3083 Node* bits = intcon(modifier_bits);
3084 Node* mbit = _gvn.transform( new (C, 3) AndINode(mods, mask) );
3085 Node* cmp = _gvn.transform( new (C, 3) CmpINode(mbit, bits) );
3086 Node* bol = _gvn.transform( new (C, 2) BoolNode(cmp, BoolTest::ne) );
3087 return generate_fair_guard(bol, region);
3088 }
3089 Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) {
3090 return generate_access_flags_guard(kls, JVM_ACC_INTERFACE, 0, region);
3091 }
3093 //-------------------------inline_native_Class_query-------------------
3094 bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) {
3095 int nargs = 1+0; // just the Class mirror, in most cases
3096 const Type* return_type = TypeInt::BOOL;
3097 Node* prim_return_value = top(); // what happens if it's a primitive class?
3098 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
3099 bool expect_prim = false; // most of these guys expect to work on refs
3101 enum { _normal_path = 1, _prim_path = 2, PATH_LIMIT };
3103 switch (id) {
3104 case vmIntrinsics::_isInstance:
3105 nargs = 1+1; // the Class mirror, plus the object getting queried about
3106 // nothing is an instance of a primitive type
3107 prim_return_value = intcon(0);
3108 break;
3109 case vmIntrinsics::_getModifiers:
3110 prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC);
3111 assert(is_power_of_2((int)JVM_ACC_WRITTEN_FLAGS+1), "change next line");
3112 return_type = TypeInt::make(0, JVM_ACC_WRITTEN_FLAGS, Type::WidenMin);
3113 break;
3114 case vmIntrinsics::_isInterface:
3115 prim_return_value = intcon(0);
3116 break;
3117 case vmIntrinsics::_isArray:
3118 prim_return_value = intcon(0);
3119 expect_prim = true; // cf. ObjectStreamClass.getClassSignature
3120 break;
3121 case vmIntrinsics::_isPrimitive:
3122 prim_return_value = intcon(1);
3123 expect_prim = true; // obviously
3124 break;
3125 case vmIntrinsics::_getSuperclass:
3126 prim_return_value = null();
3127 return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR);
3128 break;
3129 case vmIntrinsics::_getComponentType:
3130 prim_return_value = null();
3131 return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR);
3132 break;
3133 case vmIntrinsics::_getClassAccessFlags:
3134 prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC);
3135 return_type = TypeInt::INT; // not bool! 6297094
3136 break;
3137 default:
3138 ShouldNotReachHere();
3139 }
3141 Node* mirror = argument(0);
3142 Node* obj = (nargs <= 1)? top(): argument(1);
3144 const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr();
3145 if (mirror_con == NULL) return false; // cannot happen?
3147 #ifndef PRODUCT
3148 if (PrintIntrinsics || PrintInlining || PrintOptoInlining) {
3149 ciType* k = mirror_con->java_mirror_type();
3150 if (k) {
3151 tty->print("Inlining %s on constant Class ", vmIntrinsics::name_at(intrinsic_id()));
3152 k->print_name();
3153 tty->cr();
3154 }
3155 }
3156 #endif
3158 // Null-check the mirror, and the mirror's klass ptr (in case it is a primitive).
3159 RegionNode* region = new (C, PATH_LIMIT) RegionNode(PATH_LIMIT);
3160 record_for_igvn(region);
3161 PhiNode* phi = new (C, PATH_LIMIT) PhiNode(region, return_type);
3163 // The mirror will never be null of Reflection.getClassAccessFlags, however
3164 // it may be null for Class.isInstance or Class.getModifiers. Throw a NPE
3165 // if it is. See bug 4774291.
3167 // For Reflection.getClassAccessFlags(), the null check occurs in
3168 // the wrong place; see inline_unsafe_access(), above, for a similar
3169 // situation.
3170 _sp += nargs; // set original stack for use by uncommon_trap
3171 mirror = do_null_check(mirror, T_OBJECT);
3172 _sp -= nargs;
3173 // If mirror or obj is dead, only null-path is taken.
3174 if (stopped()) return true;
3176 if (expect_prim) never_see_null = false; // expect nulls (meaning prims)
3178 // Now load the mirror's klass metaobject, and null-check it.
3179 // Side-effects region with the control path if the klass is null.
3180 Node* kls = load_klass_from_mirror(mirror, never_see_null, nargs,
3181 region, _prim_path);
3182 // If kls is null, we have a primitive mirror.
3183 phi->init_req(_prim_path, prim_return_value);
3184 if (stopped()) { push_result(region, phi); return true; }
3186 Node* p; // handy temp
3187 Node* null_ctl;
3189 // Now that we have the non-null klass, we can perform the real query.
3190 // For constant classes, the query will constant-fold in LoadNode::Value.
3191 Node* query_value = top();
3192 switch (id) {
3193 case vmIntrinsics::_isInstance:
3194 // nothing is an instance of a primitive type
3195 _sp += nargs; // gen_instanceof might do an uncommon trap
3196 query_value = gen_instanceof(obj, kls);
3197 _sp -= nargs;
3198 break;
3200 case vmIntrinsics::_getModifiers:
3201 p = basic_plus_adr(kls, in_bytes(Klass::modifier_flags_offset()));
3202 query_value = make_load(NULL, p, TypeInt::INT, T_INT);
3203 break;
3205 case vmIntrinsics::_isInterface:
3206 // (To verify this code sequence, check the asserts in JVM_IsInterface.)
3207 if (generate_interface_guard(kls, region) != NULL)
3208 // A guard was added. If the guard is taken, it was an interface.
3209 phi->add_req(intcon(1));
3210 // If we fall through, it's a plain class.
3211 query_value = intcon(0);
3212 break;
3214 case vmIntrinsics::_isArray:
3215 // (To verify this code sequence, check the asserts in JVM_IsArrayClass.)
3216 if (generate_array_guard(kls, region) != NULL)
3217 // A guard was added. If the guard is taken, it was an array.
3218 phi->add_req(intcon(1));
3219 // If we fall through, it's a plain class.
3220 query_value = intcon(0);
3221 break;
3223 case vmIntrinsics::_isPrimitive:
3224 query_value = intcon(0); // "normal" path produces false
3225 break;
3227 case vmIntrinsics::_getSuperclass:
3228 // The rules here are somewhat unfortunate, but we can still do better
3229 // with random logic than with a JNI call.
3230 // Interfaces store null or Object as _super, but must report null.
3231 // Arrays store an intermediate super as _super, but must report Object.
3232 // Other types can report the actual _super.
3233 // (To verify this code sequence, check the asserts in JVM_IsInterface.)
3234 if (generate_interface_guard(kls, region) != NULL)
3235 // A guard was added. If the guard is taken, it was an interface.
3236 phi->add_req(null());
3237 if (generate_array_guard(kls, region) != NULL)
3238 // A guard was added. If the guard is taken, it was an array.
3239 phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror())));
3240 // If we fall through, it's a plain class. Get its _super.
3241 p = basic_plus_adr(kls, in_bytes(Klass::super_offset()));
3242 kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeKlassPtr::OBJECT_OR_NULL) );
3243 null_ctl = top();
3244 kls = null_check_oop(kls, &null_ctl);
3245 if (null_ctl != top()) {
3246 // If the guard is taken, Object.superClass is null (both klass and mirror).
3247 region->add_req(null_ctl);
3248 phi ->add_req(null());
3249 }
3250 if (!stopped()) {
3251 query_value = load_mirror_from_klass(kls);
3252 }
3253 break;
3255 case vmIntrinsics::_getComponentType:
3256 if (generate_array_guard(kls, region) != NULL) {
3257 // Be sure to pin the oop load to the guard edge just created:
3258 Node* is_array_ctrl = region->in(region->req()-1);
3259 Node* cma = basic_plus_adr(kls, in_bytes(arrayKlass::component_mirror_offset()));
3260 Node* cmo = make_load(is_array_ctrl, cma, TypeInstPtr::MIRROR, T_OBJECT);
3261 phi->add_req(cmo);
3262 }
3263 query_value = null(); // non-array case is null
3264 break;
3266 case vmIntrinsics::_getClassAccessFlags:
3267 p = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset()));
3268 query_value = make_load(NULL, p, TypeInt::INT, T_INT);
3269 break;
3271 default:
3272 ShouldNotReachHere();
3273 }
3275 // Fall-through is the normal case of a query to a real class.
3276 phi->init_req(1, query_value);
3277 region->init_req(1, control());
3279 push_result(region, phi);
3280 C->set_has_split_ifs(true); // Has chance for split-if optimization
3282 return true;
3283 }
3285 //--------------------------inline_native_subtype_check------------------------
3286 // This intrinsic takes the JNI calls out of the heart of
3287 // UnsafeFieldAccessorImpl.set, which improves Field.set, readObject, etc.
3288 bool LibraryCallKit::inline_native_subtype_check() {
3289 int nargs = 1+1; // the Class mirror, plus the other class getting examined
3291 // Pull both arguments off the stack.
3292 Node* args[2]; // two java.lang.Class mirrors: superc, subc
3293 args[0] = argument(0);
3294 args[1] = argument(1);
3295 Node* klasses[2]; // corresponding Klasses: superk, subk
3296 klasses[0] = klasses[1] = top();
3298 enum {
3299 // A full decision tree on {superc is prim, subc is prim}:
3300 _prim_0_path = 1, // {P,N} => false
3301 // {P,P} & superc!=subc => false
3302 _prim_same_path, // {P,P} & superc==subc => true
3303 _prim_1_path, // {N,P} => false
3304 _ref_subtype_path, // {N,N} & subtype check wins => true
3305 _both_ref_path, // {N,N} & subtype check loses => false
3306 PATH_LIMIT
3307 };
3309 RegionNode* region = new (C, PATH_LIMIT) RegionNode(PATH_LIMIT);
3310 Node* phi = new (C, PATH_LIMIT) PhiNode(region, TypeInt::BOOL);
3311 record_for_igvn(region);
3313 const TypePtr* adr_type = TypeRawPtr::BOTTOM; // memory type of loads
3314 const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL;
3315 int class_klass_offset = java_lang_Class::klass_offset_in_bytes();
3317 // First null-check both mirrors and load each mirror's klass metaobject.
3318 int which_arg;
3319 for (which_arg = 0; which_arg <= 1; which_arg++) {
3320 Node* arg = args[which_arg];
3321 _sp += nargs; // set original stack for use by uncommon_trap
3322 arg = do_null_check(arg, T_OBJECT);
3323 _sp -= nargs;
3324 if (stopped()) break;
3325 args[which_arg] = _gvn.transform(arg);
3327 Node* p = basic_plus_adr(arg, class_klass_offset);
3328 Node* kls = LoadKlassNode::make(_gvn, immutable_memory(), p, adr_type, kls_type);
3329 klasses[which_arg] = _gvn.transform(kls);
3330 }
3332 // Having loaded both klasses, test each for null.
3333 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
3334 for (which_arg = 0; which_arg <= 1; which_arg++) {
3335 Node* kls = klasses[which_arg];
3336 Node* null_ctl = top();
3337 _sp += nargs; // set original stack for use by uncommon_trap
3338 kls = null_check_oop(kls, &null_ctl, never_see_null);
3339 _sp -= nargs;
3340 int prim_path = (which_arg == 0 ? _prim_0_path : _prim_1_path);
3341 region->init_req(prim_path, null_ctl);
3342 if (stopped()) break;
3343 klasses[which_arg] = kls;
3344 }
3346 if (!stopped()) {
3347 // now we have two reference types, in klasses[0..1]
3348 Node* subk = klasses[1]; // the argument to isAssignableFrom
3349 Node* superk = klasses[0]; // the receiver
3350 region->set_req(_both_ref_path, gen_subtype_check(subk, superk));
3351 // now we have a successful reference subtype check
3352 region->set_req(_ref_subtype_path, control());
3353 }
3355 // If both operands are primitive (both klasses null), then
3356 // we must return true when they are identical primitives.
3357 // It is convenient to test this after the first null klass check.
3358 set_control(region->in(_prim_0_path)); // go back to first null check
3359 if (!stopped()) {
3360 // Since superc is primitive, make a guard for the superc==subc case.
3361 Node* cmp_eq = _gvn.transform( new (C, 3) CmpPNode(args[0], args[1]) );
3362 Node* bol_eq = _gvn.transform( new (C, 2) BoolNode(cmp_eq, BoolTest::eq) );
3363 generate_guard(bol_eq, region, PROB_FAIR);
3364 if (region->req() == PATH_LIMIT+1) {
3365 // A guard was added. If the added guard is taken, superc==subc.
3366 region->swap_edges(PATH_LIMIT, _prim_same_path);
3367 region->del_req(PATH_LIMIT);
3368 }
3369 region->set_req(_prim_0_path, control()); // Not equal after all.
3370 }
3372 // these are the only paths that produce 'true':
3373 phi->set_req(_prim_same_path, intcon(1));
3374 phi->set_req(_ref_subtype_path, intcon(1));
3376 // pull together the cases:
3377 assert(region->req() == PATH_LIMIT, "sane region");
3378 for (uint i = 1; i < region->req(); i++) {
3379 Node* ctl = region->in(i);
3380 if (ctl == NULL || ctl == top()) {
3381 region->set_req(i, top());
3382 phi ->set_req(i, top());
3383 } else if (phi->in(i) == NULL) {
3384 phi->set_req(i, intcon(0)); // all other paths produce 'false'
3385 }
3386 }
3388 set_control(_gvn.transform(region));
3389 push(_gvn.transform(phi));
3391 return true;
3392 }
3394 //---------------------generate_array_guard_common------------------------
3395 Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region,
3396 bool obj_array, bool not_array) {
3397 // If obj_array/non_array==false/false:
3398 // Branch around if the given klass is in fact an array (either obj or prim).
3399 // If obj_array/non_array==false/true:
3400 // Branch around if the given klass is not an array klass of any kind.
3401 // If obj_array/non_array==true/true:
3402 // Branch around if the kls is not an oop array (kls is int[], String, etc.)
3403 // If obj_array/non_array==true/false:
3404 // Branch around if the kls is an oop array (Object[] or subtype)
3405 //
3406 // Like generate_guard, adds a new path onto the region.
3407 jint layout_con = 0;
3408 Node* layout_val = get_layout_helper(kls, layout_con);
3409 if (layout_val == NULL) {
3410 bool query = (obj_array
3411 ? Klass::layout_helper_is_objArray(layout_con)
3412 : Klass::layout_helper_is_javaArray(layout_con));
3413 if (query == not_array) {
3414 return NULL; // never a branch
3415 } else { // always a branch
3416 Node* always_branch = control();
3417 if (region != NULL)
3418 region->add_req(always_branch);
3419 set_control(top());
3420 return always_branch;
3421 }
3422 }
3423 // Now test the correct condition.
3424 jint nval = (obj_array
3425 ? ((jint)Klass::_lh_array_tag_type_value
3426 << Klass::_lh_array_tag_shift)
3427 : Klass::_lh_neutral_value);
3428 Node* cmp = _gvn.transform( new(C, 3) CmpINode(layout_val, intcon(nval)) );
3429 BoolTest::mask btest = BoolTest::lt; // correct for testing is_[obj]array
3430 // invert the test if we are looking for a non-array
3431 if (not_array) btest = BoolTest(btest).negate();
3432 Node* bol = _gvn.transform( new(C, 2) BoolNode(cmp, btest) );
3433 return generate_fair_guard(bol, region);
3434 }
3437 //-----------------------inline_native_newArray--------------------------
3438 bool LibraryCallKit::inline_native_newArray() {
3439 int nargs = 2;
3440 Node* mirror = argument(0);
3441 Node* count_val = argument(1);
3443 _sp += nargs; // set original stack for use by uncommon_trap
3444 mirror = do_null_check(mirror, T_OBJECT);
3445 _sp -= nargs;
3446 // If mirror or obj is dead, only null-path is taken.
3447 if (stopped()) return true;
3449 enum { _normal_path = 1, _slow_path = 2, PATH_LIMIT };
3450 RegionNode* result_reg = new(C, PATH_LIMIT) RegionNode(PATH_LIMIT);
3451 PhiNode* result_val = new(C, PATH_LIMIT) PhiNode(result_reg,
3452 TypeInstPtr::NOTNULL);
3453 PhiNode* result_io = new(C, PATH_LIMIT) PhiNode(result_reg, Type::ABIO);
3454 PhiNode* result_mem = new(C, PATH_LIMIT) PhiNode(result_reg, Type::MEMORY,
3455 TypePtr::BOTTOM);
3457 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
3458 Node* klass_node = load_array_klass_from_mirror(mirror, never_see_null,
3459 nargs,
3460 result_reg, _slow_path);
3461 Node* normal_ctl = control();
3462 Node* no_array_ctl = result_reg->in(_slow_path);
3464 // Generate code for the slow case. We make a call to newArray().
3465 set_control(no_array_ctl);
3466 if (!stopped()) {
3467 // Either the input type is void.class, or else the
3468 // array klass has not yet been cached. Either the
3469 // ensuing call will throw an exception, or else it
3470 // will cache the array klass for next time.
3471 PreserveJVMState pjvms(this);
3472 CallJavaNode* slow_call = generate_method_call_static(vmIntrinsics::_newArray);
3473 Node* slow_result = set_results_for_java_call(slow_call);
3474 // this->control() comes from set_results_for_java_call
3475 result_reg->set_req(_slow_path, control());
3476 result_val->set_req(_slow_path, slow_result);
3477 result_io ->set_req(_slow_path, i_o());
3478 result_mem->set_req(_slow_path, reset_memory());
3479 }
3481 set_control(normal_ctl);
3482 if (!stopped()) {
3483 // Normal case: The array type has been cached in the java.lang.Class.
3484 // The following call works fine even if the array type is polymorphic.
3485 // It could be a dynamic mix of int[], boolean[], Object[], etc.
3486 Node* obj = new_array(klass_node, count_val, nargs);
3487 result_reg->init_req(_normal_path, control());
3488 result_val->init_req(_normal_path, obj);
3489 result_io ->init_req(_normal_path, i_o());
3490 result_mem->init_req(_normal_path, reset_memory());
3491 }
3493 // Return the combined state.
3494 set_i_o( _gvn.transform(result_io) );
3495 set_all_memory( _gvn.transform(result_mem) );
3496 push_result(result_reg, result_val);
3497 C->set_has_split_ifs(true); // Has chance for split-if optimization
3499 return true;
3500 }
3502 //----------------------inline_native_getLength--------------------------
3503 bool LibraryCallKit::inline_native_getLength() {
3504 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false;
3506 int nargs = 1;
3507 Node* array = argument(0);
3509 _sp += nargs; // set original stack for use by uncommon_trap
3510 array = do_null_check(array, T_OBJECT);
3511 _sp -= nargs;
3513 // If array is dead, only null-path is taken.
3514 if (stopped()) return true;
3516 // Deoptimize if it is a non-array.
3517 Node* non_array = generate_non_array_guard(load_object_klass(array), NULL);
3519 if (non_array != NULL) {
3520 PreserveJVMState pjvms(this);
3521 set_control(non_array);
3522 _sp += nargs; // push the arguments back on the stack
3523 uncommon_trap(Deoptimization::Reason_intrinsic,
3524 Deoptimization::Action_maybe_recompile);
3525 }
3527 // If control is dead, only non-array-path is taken.
3528 if (stopped()) return true;
3530 // The works fine even if the array type is polymorphic.
3531 // It could be a dynamic mix of int[], boolean[], Object[], etc.
3532 push( load_array_length(array) );
3534 C->set_has_split_ifs(true); // Has chance for split-if optimization
3536 return true;
3537 }
3539 //------------------------inline_array_copyOf----------------------------
3540 bool LibraryCallKit::inline_array_copyOf(bool is_copyOfRange) {
3541 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false;
3543 // Restore the stack and pop off the arguments.
3544 int nargs = 3 + (is_copyOfRange? 1: 0);
3545 Node* original = argument(0);
3546 Node* start = is_copyOfRange? argument(1): intcon(0);
3547 Node* end = is_copyOfRange? argument(2): argument(1);
3548 Node* array_type_mirror = is_copyOfRange? argument(3): argument(2);
3550 Node* newcopy;
3552 //set the original stack and the reexecute bit for the interpreter to reexecute
3553 //the bytecode that invokes Arrays.copyOf if deoptimization happens
3554 { PreserveReexecuteState preexecs(this);
3555 _sp += nargs;
3556 jvms()->set_should_reexecute(true);
3558 array_type_mirror = do_null_check(array_type_mirror, T_OBJECT);
3559 original = do_null_check(original, T_OBJECT);
3561 // Check if a null path was taken unconditionally.
3562 if (stopped()) return true;
3564 Node* orig_length = load_array_length(original);
3566 Node* klass_node = load_klass_from_mirror(array_type_mirror, false, 0,
3567 NULL, 0);
3568 klass_node = do_null_check(klass_node, T_OBJECT);
3570 RegionNode* bailout = new (C, 1) RegionNode(1);
3571 record_for_igvn(bailout);
3573 // Despite the generic type of Arrays.copyOf, the mirror might be int, int[], etc.
3574 // Bail out if that is so.
3575 Node* not_objArray = generate_non_objArray_guard(klass_node, bailout);
3576 if (not_objArray != NULL) {
3577 // Improve the klass node's type from the new optimistic assumption:
3578 ciKlass* ak = ciArrayKlass::make(env()->Object_klass());
3579 const Type* akls = TypeKlassPtr::make(TypePtr::NotNull, ak, 0/*offset*/);
3580 Node* cast = new (C, 2) CastPPNode(klass_node, akls);
3581 cast->init_req(0, control());
3582 klass_node = _gvn.transform(cast);
3583 }
3585 // Bail out if either start or end is negative.
3586 generate_negative_guard(start, bailout, &start);
3587 generate_negative_guard(end, bailout, &end);
3589 Node* length = end;
3590 if (_gvn.type(start) != TypeInt::ZERO) {
3591 length = _gvn.transform( new (C, 3) SubINode(end, start) );
3592 }
3594 // Bail out if length is negative.
3595 // ...Not needed, since the new_array will throw the right exception.
3596 //generate_negative_guard(length, bailout, &length);
3598 if (bailout->req() > 1) {
3599 PreserveJVMState pjvms(this);
3600 set_control( _gvn.transform(bailout) );
3601 uncommon_trap(Deoptimization::Reason_intrinsic,
3602 Deoptimization::Action_maybe_recompile);
3603 }
3605 if (!stopped()) {
3607 // How many elements will we copy from the original?
3608 // The answer is MinI(orig_length - start, length).
3609 Node* orig_tail = _gvn.transform( new(C, 3) SubINode(orig_length, start) );
3610 Node* moved = generate_min_max(vmIntrinsics::_min, orig_tail, length);
3612 newcopy = new_array(klass_node, length, 0);
3614 // Generate a direct call to the right arraycopy function(s).
3615 // We know the copy is disjoint but we might not know if the
3616 // oop stores need checking.
3617 // Extreme case: Arrays.copyOf((Integer[])x, 10, String[].class).
3618 // This will fail a store-check if x contains any non-nulls.
3619 bool disjoint_bases = true;
3620 bool length_never_negative = true;
3621 generate_arraycopy(TypeAryPtr::OOPS, T_OBJECT,
3622 original, start, newcopy, intcon(0), moved,
3623 disjoint_bases, length_never_negative);
3624 }
3625 } //original reexecute and sp are set back here
3627 if(!stopped()) {
3628 push(newcopy);
3629 }
3631 C->set_has_split_ifs(true); // Has chance for split-if optimization
3633 return true;
3634 }
3637 //----------------------generate_virtual_guard---------------------------
3638 // Helper for hashCode and clone. Peeks inside the vtable to avoid a call.
3639 Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass,
3640 RegionNode* slow_region) {
3641 ciMethod* method = callee();
3642 int vtable_index = method->vtable_index();
3643 // Get the methodOop out of the appropriate vtable entry.
3644 int entry_offset = (instanceKlass::vtable_start_offset() +
3645 vtable_index*vtableEntry::size()) * wordSize +
3646 vtableEntry::method_offset_in_bytes();
3647 Node* entry_addr = basic_plus_adr(obj_klass, entry_offset);
3648 Node* target_call = make_load(NULL, entry_addr, TypeInstPtr::NOTNULL, T_OBJECT);
3650 // Compare the target method with the expected method (e.g., Object.hashCode).
3651 const TypeInstPtr* native_call_addr = TypeInstPtr::make(method);
3653 Node* native_call = makecon(native_call_addr);
3654 Node* chk_native = _gvn.transform( new(C, 3) CmpPNode(target_call, native_call) );
3655 Node* test_native = _gvn.transform( new(C, 2) BoolNode(chk_native, BoolTest::ne) );
3657 return generate_slow_guard(test_native, slow_region);
3658 }
3660 //-----------------------generate_method_call----------------------------
3661 // Use generate_method_call to make a slow-call to the real
3662 // method if the fast path fails. An alternative would be to
3663 // use a stub like OptoRuntime::slow_arraycopy_Java.
3664 // This only works for expanding the current library call,
3665 // not another intrinsic. (E.g., don't use this for making an
3666 // arraycopy call inside of the copyOf intrinsic.)
3667 CallJavaNode*
3668 LibraryCallKit::generate_method_call(vmIntrinsics::ID method_id, bool is_virtual, bool is_static) {
3669 // When compiling the intrinsic method itself, do not use this technique.
3670 guarantee(callee() != C->method(), "cannot make slow-call to self");
3672 ciMethod* method = callee();
3673 // ensure the JVMS we have will be correct for this call
3674 guarantee(method_id == method->intrinsic_id(), "must match");
3676 const TypeFunc* tf = TypeFunc::make(method);
3677 int tfdc = tf->domain()->cnt();
3678 CallJavaNode* slow_call;
3679 if (is_static) {
3680 assert(!is_virtual, "");
3681 slow_call = new(C, tfdc) CallStaticJavaNode(tf,
3682 SharedRuntime::get_resolve_static_call_stub(),
3683 method, bci());
3684 } else if (is_virtual) {
3685 null_check_receiver(method);
3686 int vtable_index = methodOopDesc::invalid_vtable_index;
3687 if (UseInlineCaches) {
3688 // Suppress the vtable call
3689 } else {
3690 // hashCode and clone are not a miranda methods,
3691 // so the vtable index is fixed.
3692 // No need to use the linkResolver to get it.
3693 vtable_index = method->vtable_index();
3694 }
3695 slow_call = new(C, tfdc) CallDynamicJavaNode(tf,
3696 SharedRuntime::get_resolve_virtual_call_stub(),
3697 method, vtable_index, bci());
3698 } else { // neither virtual nor static: opt_virtual
3699 null_check_receiver(method);
3700 slow_call = new(C, tfdc) CallStaticJavaNode(tf,
3701 SharedRuntime::get_resolve_opt_virtual_call_stub(),
3702 method, bci());
3703 slow_call->set_optimized_virtual(true);
3704 }
3705 set_arguments_for_java_call(slow_call);
3706 set_edges_for_java_call(slow_call);
3707 return slow_call;
3708 }
3711 //------------------------------inline_native_hashcode--------------------
3712 // Build special case code for calls to hashCode on an object.
3713 bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) {
3714 assert(is_static == callee()->is_static(), "correct intrinsic selection");
3715 assert(!(is_virtual && is_static), "either virtual, special, or static");
3717 enum { _slow_path = 1, _fast_path, _null_path, PATH_LIMIT };
3719 RegionNode* result_reg = new(C, PATH_LIMIT) RegionNode(PATH_LIMIT);
3720 PhiNode* result_val = new(C, PATH_LIMIT) PhiNode(result_reg,
3721 TypeInt::INT);
3722 PhiNode* result_io = new(C, PATH_LIMIT) PhiNode(result_reg, Type::ABIO);
3723 PhiNode* result_mem = new(C, PATH_LIMIT) PhiNode(result_reg, Type::MEMORY,
3724 TypePtr::BOTTOM);
3725 Node* obj = NULL;
3726 if (!is_static) {
3727 // Check for hashing null object
3728 obj = null_check_receiver(callee());
3729 if (stopped()) return true; // unconditionally null
3730 result_reg->init_req(_null_path, top());
3731 result_val->init_req(_null_path, top());
3732 } else {
3733 // Do a null check, and return zero if null.
3734 // System.identityHashCode(null) == 0
3735 obj = argument(0);
3736 Node* null_ctl = top();
3737 obj = null_check_oop(obj, &null_ctl);
3738 result_reg->init_req(_null_path, null_ctl);
3739 result_val->init_req(_null_path, _gvn.intcon(0));
3740 }
3742 // Unconditionally null? Then return right away.
3743 if (stopped()) {
3744 set_control( result_reg->in(_null_path) );
3745 if (!stopped())
3746 push( result_val ->in(_null_path) );
3747 return true;
3748 }
3750 // After null check, get the object's klass.
3751 Node* obj_klass = load_object_klass(obj);
3753 // This call may be virtual (invokevirtual) or bound (invokespecial).
3754 // For each case we generate slightly different code.
3756 // We only go to the fast case code if we pass a number of guards. The
3757 // paths which do not pass are accumulated in the slow_region.
3758 RegionNode* slow_region = new (C, 1) RegionNode(1);
3759 record_for_igvn(slow_region);
3761 // If this is a virtual call, we generate a funny guard. We pull out
3762 // the vtable entry corresponding to hashCode() from the target object.
3763 // If the target method which we are calling happens to be the native
3764 // Object hashCode() method, we pass the guard. We do not need this
3765 // guard for non-virtual calls -- the caller is known to be the native
3766 // Object hashCode().
3767 if (is_virtual) {
3768 generate_virtual_guard(obj_klass, slow_region);
3769 }
3771 // Get the header out of the object, use LoadMarkNode when available
3772 Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes());
3773 Node* header = make_load(control(), header_addr, TypeX_X, TypeX_X->basic_type());
3775 // Test the header to see if it is unlocked.
3776 Node *lock_mask = _gvn.MakeConX(markOopDesc::biased_lock_mask_in_place);
3777 Node *lmasked_header = _gvn.transform( new (C, 3) AndXNode(header, lock_mask) );
3778 Node *unlocked_val = _gvn.MakeConX(markOopDesc::unlocked_value);
3779 Node *chk_unlocked = _gvn.transform( new (C, 3) CmpXNode( lmasked_header, unlocked_val));
3780 Node *test_unlocked = _gvn.transform( new (C, 2) BoolNode( chk_unlocked, BoolTest::ne) );
3782 generate_slow_guard(test_unlocked, slow_region);
3784 // Get the hash value and check to see that it has been properly assigned.
3785 // We depend on hash_mask being at most 32 bits and avoid the use of
3786 // hash_mask_in_place because it could be larger than 32 bits in a 64-bit
3787 // vm: see markOop.hpp.
3788 Node *hash_mask = _gvn.intcon(markOopDesc::hash_mask);
3789 Node *hash_shift = _gvn.intcon(markOopDesc::hash_shift);
3790 Node *hshifted_header= _gvn.transform( new (C, 3) URShiftXNode(header, hash_shift) );
3791 // This hack lets the hash bits live anywhere in the mark object now, as long
3792 // as the shift drops the relevant bits into the low 32 bits. Note that
3793 // Java spec says that HashCode is an int so there's no point in capturing
3794 // an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build).
3795 hshifted_header = ConvX2I(hshifted_header);
3796 Node *hash_val = _gvn.transform( new (C, 3) AndINode(hshifted_header, hash_mask) );
3798 Node *no_hash_val = _gvn.intcon(markOopDesc::no_hash);
3799 Node *chk_assigned = _gvn.transform( new (C, 3) CmpINode( hash_val, no_hash_val));
3800 Node *test_assigned = _gvn.transform( new (C, 2) BoolNode( chk_assigned, BoolTest::eq) );
3802 generate_slow_guard(test_assigned, slow_region);
3804 Node* init_mem = reset_memory();
3805 // fill in the rest of the null path:
3806 result_io ->init_req(_null_path, i_o());
3807 result_mem->init_req(_null_path, init_mem);
3809 result_val->init_req(_fast_path, hash_val);
3810 result_reg->init_req(_fast_path, control());
3811 result_io ->init_req(_fast_path, i_o());
3812 result_mem->init_req(_fast_path, init_mem);
3814 // Generate code for the slow case. We make a call to hashCode().
3815 set_control(_gvn.transform(slow_region));
3816 if (!stopped()) {
3817 // No need for PreserveJVMState, because we're using up the present state.
3818 set_all_memory(init_mem);
3819 vmIntrinsics::ID hashCode_id = vmIntrinsics::_hashCode;
3820 if (is_static) hashCode_id = vmIntrinsics::_identityHashCode;
3821 CallJavaNode* slow_call = generate_method_call(hashCode_id, is_virtual, is_static);
3822 Node* slow_result = set_results_for_java_call(slow_call);
3823 // this->control() comes from set_results_for_java_call
3824 result_reg->init_req(_slow_path, control());
3825 result_val->init_req(_slow_path, slow_result);
3826 result_io ->set_req(_slow_path, i_o());
3827 result_mem ->set_req(_slow_path, reset_memory());
3828 }
3830 // Return the combined state.
3831 set_i_o( _gvn.transform(result_io) );
3832 set_all_memory( _gvn.transform(result_mem) );
3833 push_result(result_reg, result_val);
3835 return true;
3836 }
3838 //---------------------------inline_native_getClass----------------------------
3839 // Build special case code for calls to getClass on an object.
3840 bool LibraryCallKit::inline_native_getClass() {
3841 Node* obj = null_check_receiver(callee());
3842 if (stopped()) return true;
3843 push( load_mirror_from_klass(load_object_klass(obj)) );
3844 return true;
3845 }
3847 //-----------------inline_native_Reflection_getCallerClass---------------------
3848 // In the presence of deep enough inlining, getCallerClass() becomes a no-op.
3849 //
3850 // NOTE that this code must perform the same logic as
3851 // vframeStream::security_get_caller_frame in that it must skip
3852 // Method.invoke() and auxiliary frames.
3857 bool LibraryCallKit::inline_native_Reflection_getCallerClass() {
3858 ciMethod* method = callee();
3860 #ifndef PRODUCT
3861 if ((PrintIntrinsics || PrintInlining || PrintOptoInlining) && Verbose) {
3862 tty->print_cr("Attempting to inline sun.reflect.Reflection.getCallerClass");
3863 }
3864 #endif
3866 debug_only(int saved_sp = _sp);
3868 // Argument words: (int depth)
3869 int nargs = 1;
3871 _sp += nargs;
3872 Node* caller_depth_node = pop();
3874 assert(saved_sp == _sp, "must have correct argument count");
3876 // The depth value must be a constant in order for the runtime call
3877 // to be eliminated.
3878 const TypeInt* caller_depth_type = _gvn.type(caller_depth_node)->isa_int();
3879 if (caller_depth_type == NULL || !caller_depth_type->is_con()) {
3880 #ifndef PRODUCT
3881 if ((PrintIntrinsics || PrintInlining || PrintOptoInlining) && Verbose) {
3882 tty->print_cr(" Bailing out because caller depth was not a constant");
3883 }
3884 #endif
3885 return false;
3886 }
3887 // Note that the JVM state at this point does not include the
3888 // getCallerClass() frame which we are trying to inline. The
3889 // semantics of getCallerClass(), however, are that the "first"
3890 // frame is the getCallerClass() frame, so we subtract one from the
3891 // requested depth before continuing. We don't inline requests of
3892 // getCallerClass(0).
3893 int caller_depth = caller_depth_type->get_con() - 1;
3894 if (caller_depth < 0) {
3895 #ifndef PRODUCT
3896 if ((PrintIntrinsics || PrintInlining || PrintOptoInlining) && Verbose) {
3897 tty->print_cr(" Bailing out because caller depth was %d", caller_depth);
3898 }
3899 #endif
3900 return false;
3901 }
3903 if (!jvms()->has_method()) {
3904 #ifndef PRODUCT
3905 if ((PrintIntrinsics || PrintInlining || PrintOptoInlining) && Verbose) {
3906 tty->print_cr(" Bailing out because intrinsic was inlined at top level");
3907 }
3908 #endif
3909 return false;
3910 }
3911 int _depth = jvms()->depth(); // cache call chain depth
3913 // Walk back up the JVM state to find the caller at the required
3914 // depth. NOTE that this code must perform the same logic as
3915 // vframeStream::security_get_caller_frame in that it must skip
3916 // Method.invoke() and auxiliary frames. Note also that depth is
3917 // 1-based (1 is the bottom of the inlining).
3918 int inlining_depth = _depth;
3919 JVMState* caller_jvms = NULL;
3921 if (inlining_depth > 0) {
3922 caller_jvms = jvms();
3923 assert(caller_jvms = jvms()->of_depth(inlining_depth), "inlining_depth == our depth");
3924 do {
3925 // The following if-tests should be performed in this order
3926 if (is_method_invoke_or_aux_frame(caller_jvms)) {
3927 // Skip a Method.invoke() or auxiliary frame
3928 } else if (caller_depth > 0) {
3929 // Skip real frame
3930 --caller_depth;
3931 } else {
3932 // We're done: reached desired caller after skipping.
3933 break;
3934 }
3935 caller_jvms = caller_jvms->caller();
3936 --inlining_depth;
3937 } while (inlining_depth > 0);
3938 }
3940 if (inlining_depth == 0) {
3941 #ifndef PRODUCT
3942 if ((PrintIntrinsics || PrintInlining || PrintOptoInlining) && Verbose) {
3943 tty->print_cr(" Bailing out because caller depth (%d) exceeded inlining depth (%d)", caller_depth_type->get_con(), _depth);
3944 tty->print_cr(" JVM state at this point:");
3945 for (int i = _depth; i >= 1; i--) {
3946 tty->print_cr(" %d) %s", i, jvms()->of_depth(i)->method()->name()->as_utf8());
3947 }
3948 }
3949 #endif
3950 return false; // Reached end of inlining
3951 }
3953 // Acquire method holder as java.lang.Class
3954 ciInstanceKlass* caller_klass = caller_jvms->method()->holder();
3955 ciInstance* caller_mirror = caller_klass->java_mirror();
3956 // Push this as a constant
3957 push(makecon(TypeInstPtr::make(caller_mirror)));
3958 #ifndef PRODUCT
3959 if ((PrintIntrinsics || PrintInlining || PrintOptoInlining) && Verbose) {
3960 tty->print_cr(" Succeeded: caller = %s.%s, caller depth = %d, depth = %d", caller_klass->name()->as_utf8(), caller_jvms->method()->name()->as_utf8(), caller_depth_type->get_con(), _depth);
3961 tty->print_cr(" JVM state at this point:");
3962 for (int i = _depth; i >= 1; i--) {
3963 tty->print_cr(" %d) %s", i, jvms()->of_depth(i)->method()->name()->as_utf8());
3964 }
3965 }
3966 #endif
3967 return true;
3968 }
3970 // Helper routine for above
3971 bool LibraryCallKit::is_method_invoke_or_aux_frame(JVMState* jvms) {
3972 ciMethod* method = jvms->method();
3974 // Is this the Method.invoke method itself?
3975 if (method->intrinsic_id() == vmIntrinsics::_invoke)
3976 return true;
3978 // Is this a helper, defined somewhere underneath MethodAccessorImpl.
3979 ciKlass* k = method->holder();
3980 if (k->is_instance_klass()) {
3981 ciInstanceKlass* ik = k->as_instance_klass();
3982 for (; ik != NULL; ik = ik->super()) {
3983 if (ik->name() == ciSymbol::sun_reflect_MethodAccessorImpl() &&
3984 ik == env()->find_system_klass(ik->name())) {
3985 return true;
3986 }
3987 }
3988 }
3989 else if (method->is_method_handle_adapter()) {
3990 // This is an internal adapter frame from the MethodHandleCompiler -- skip it
3991 return true;
3992 }
3994 return false;
3995 }
3997 bool LibraryCallKit::inline_fp_conversions(vmIntrinsics::ID id) {
3998 // restore the arguments
3999 _sp += arg_size();
4001 switch (id) {
4002 case vmIntrinsics::_floatToRawIntBits:
4003 push(_gvn.transform( new (C, 2) MoveF2INode(pop())));
4004 break;
4006 case vmIntrinsics::_intBitsToFloat:
4007 push(_gvn.transform( new (C, 2) MoveI2FNode(pop())));
4008 break;
4010 case vmIntrinsics::_doubleToRawLongBits:
4011 push_pair(_gvn.transform( new (C, 2) MoveD2LNode(pop_pair())));
4012 break;
4014 case vmIntrinsics::_longBitsToDouble:
4015 push_pair(_gvn.transform( new (C, 2) MoveL2DNode(pop_pair())));
4016 break;
4018 case vmIntrinsics::_doubleToLongBits: {
4019 Node* value = pop_pair();
4021 // two paths (plus control) merge in a wood
4022 RegionNode *r = new (C, 3) RegionNode(3);
4023 Node *phi = new (C, 3) PhiNode(r, TypeLong::LONG);
4025 Node *cmpisnan = _gvn.transform( new (C, 3) CmpDNode(value, value));
4026 // Build the boolean node
4027 Node *bolisnan = _gvn.transform( new (C, 2) BoolNode( cmpisnan, BoolTest::ne ) );
4029 // Branch either way.
4030 // NaN case is less traveled, which makes all the difference.
4031 IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN);
4032 Node *opt_isnan = _gvn.transform(ifisnan);
4033 assert( opt_isnan->is_If(), "Expect an IfNode");
4034 IfNode *opt_ifisnan = (IfNode*)opt_isnan;
4035 Node *iftrue = _gvn.transform( new (C, 1) IfTrueNode(opt_ifisnan) );
4037 set_control(iftrue);
4039 static const jlong nan_bits = CONST64(0x7ff8000000000000);
4040 Node *slow_result = longcon(nan_bits); // return NaN
4041 phi->init_req(1, _gvn.transform( slow_result ));
4042 r->init_req(1, iftrue);
4044 // Else fall through
4045 Node *iffalse = _gvn.transform( new (C, 1) IfFalseNode(opt_ifisnan) );
4046 set_control(iffalse);
4048 phi->init_req(2, _gvn.transform( new (C, 2) MoveD2LNode(value)));
4049 r->init_req(2, iffalse);
4051 // Post merge
4052 set_control(_gvn.transform(r));
4053 record_for_igvn(r);
4055 Node* result = _gvn.transform(phi);
4056 assert(result->bottom_type()->isa_long(), "must be");
4057 push_pair(result);
4059 C->set_has_split_ifs(true); // Has chance for split-if optimization
4061 break;
4062 }
4064 case vmIntrinsics::_floatToIntBits: {
4065 Node* value = pop();
4067 // two paths (plus control) merge in a wood
4068 RegionNode *r = new (C, 3) RegionNode(3);
4069 Node *phi = new (C, 3) PhiNode(r, TypeInt::INT);
4071 Node *cmpisnan = _gvn.transform( new (C, 3) CmpFNode(value, value));
4072 // Build the boolean node
4073 Node *bolisnan = _gvn.transform( new (C, 2) BoolNode( cmpisnan, BoolTest::ne ) );
4075 // Branch either way.
4076 // NaN case is less traveled, which makes all the difference.
4077 IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN);
4078 Node *opt_isnan = _gvn.transform(ifisnan);
4079 assert( opt_isnan->is_If(), "Expect an IfNode");
4080 IfNode *opt_ifisnan = (IfNode*)opt_isnan;
4081 Node *iftrue = _gvn.transform( new (C, 1) IfTrueNode(opt_ifisnan) );
4083 set_control(iftrue);
4085 static const jint nan_bits = 0x7fc00000;
4086 Node *slow_result = makecon(TypeInt::make(nan_bits)); // return NaN
4087 phi->init_req(1, _gvn.transform( slow_result ));
4088 r->init_req(1, iftrue);
4090 // Else fall through
4091 Node *iffalse = _gvn.transform( new (C, 1) IfFalseNode(opt_ifisnan) );
4092 set_control(iffalse);
4094 phi->init_req(2, _gvn.transform( new (C, 2) MoveF2INode(value)));
4095 r->init_req(2, iffalse);
4097 // Post merge
4098 set_control(_gvn.transform(r));
4099 record_for_igvn(r);
4101 Node* result = _gvn.transform(phi);
4102 assert(result->bottom_type()->isa_int(), "must be");
4103 push(result);
4105 C->set_has_split_ifs(true); // Has chance for split-if optimization
4107 break;
4108 }
4110 default:
4111 ShouldNotReachHere();
4112 }
4114 return true;
4115 }
4117 #ifdef _LP64
4118 #define XTOP ,top() /*additional argument*/
4119 #else //_LP64
4120 #define XTOP /*no additional argument*/
4121 #endif //_LP64
4123 //----------------------inline_unsafe_copyMemory-------------------------
4124 bool LibraryCallKit::inline_unsafe_copyMemory() {
4125 if (callee()->is_static()) return false; // caller must have the capability!
4126 int nargs = 1 + 5 + 3; // 5 args: (src: ptr,off, dst: ptr,off, size)
4127 assert(signature()->size() == nargs-1, "copy has 5 arguments");
4128 null_check_receiver(callee()); // check then ignore argument(0)
4129 if (stopped()) return true;
4131 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
4133 Node* src_ptr = argument(1);
4134 Node* src_off = ConvL2X(argument(2));
4135 assert(argument(3)->is_top(), "2nd half of long");
4136 Node* dst_ptr = argument(4);
4137 Node* dst_off = ConvL2X(argument(5));
4138 assert(argument(6)->is_top(), "2nd half of long");
4139 Node* size = ConvL2X(argument(7));
4140 assert(argument(8)->is_top(), "2nd half of long");
4142 assert(Unsafe_field_offset_to_byte_offset(11) == 11,
4143 "fieldOffset must be byte-scaled");
4145 Node* src = make_unsafe_address(src_ptr, src_off);
4146 Node* dst = make_unsafe_address(dst_ptr, dst_off);
4148 // Conservatively insert a memory barrier on all memory slices.
4149 // Do not let writes of the copy source or destination float below the copy.
4150 insert_mem_bar(Op_MemBarCPUOrder);
4152 // Call it. Note that the length argument is not scaled.
4153 make_runtime_call(RC_LEAF|RC_NO_FP,
4154 OptoRuntime::fast_arraycopy_Type(),
4155 StubRoutines::unsafe_arraycopy(),
4156 "unsafe_arraycopy",
4157 TypeRawPtr::BOTTOM,
4158 src, dst, size XTOP);
4160 // Do not let reads of the copy destination float above the copy.
4161 insert_mem_bar(Op_MemBarCPUOrder);
4163 return true;
4164 }
4166 //------------------------clone_coping-----------------------------------
4167 // Helper function for inline_native_clone.
4168 void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array, bool card_mark) {
4169 assert(obj_size != NULL, "");
4170 Node* raw_obj = alloc_obj->in(1);
4171 assert(alloc_obj->is_CheckCastPP() && raw_obj->is_Proj() && raw_obj->in(0)->is_Allocate(), "");
4173 AllocateNode* alloc = NULL;
4174 if (ReduceBulkZeroing) {
4175 // We will be completely responsible for initializing this object -
4176 // mark Initialize node as complete.
4177 alloc = AllocateNode::Ideal_allocation(alloc_obj, &_gvn);
4178 // The object was just allocated - there should be no any stores!
4179 guarantee(alloc != NULL && alloc->maybe_set_complete(&_gvn), "");
4180 // Mark as complete_with_arraycopy so that on AllocateNode
4181 // expansion, we know this AllocateNode is initialized by an array
4182 // copy and a StoreStore barrier exists after the array copy.
4183 alloc->initialization()->set_complete_with_arraycopy();
4184 }
4186 // Copy the fastest available way.
4187 // TODO: generate fields copies for small objects instead.
4188 Node* src = obj;
4189 Node* dest = alloc_obj;
4190 Node* size = _gvn.transform(obj_size);
4192 // Exclude the header but include array length to copy by 8 bytes words.
4193 // Can't use base_offset_in_bytes(bt) since basic type is unknown.
4194 int base_off = is_array ? arrayOopDesc::length_offset_in_bytes() :
4195 instanceOopDesc::base_offset_in_bytes();
4196 // base_off:
4197 // 8 - 32-bit VM
4198 // 12 - 64-bit VM, compressed oops
4199 // 16 - 64-bit VM, normal oops
4200 if (base_off % BytesPerLong != 0) {
4201 assert(UseCompressedOops, "");
4202 if (is_array) {
4203 // Exclude length to copy by 8 bytes words.
4204 base_off += sizeof(int);
4205 } else {
4206 // Include klass to copy by 8 bytes words.
4207 base_off = instanceOopDesc::klass_offset_in_bytes();
4208 }
4209 assert(base_off % BytesPerLong == 0, "expect 8 bytes alignment");
4210 }
4211 src = basic_plus_adr(src, base_off);
4212 dest = basic_plus_adr(dest, base_off);
4214 // Compute the length also, if needed:
4215 Node* countx = size;
4216 countx = _gvn.transform( new (C, 3) SubXNode(countx, MakeConX(base_off)) );
4217 countx = _gvn.transform( new (C, 3) URShiftXNode(countx, intcon(LogBytesPerLong) ));
4219 const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM;
4220 bool disjoint_bases = true;
4221 generate_unchecked_arraycopy(raw_adr_type, T_LONG, disjoint_bases,
4222 src, NULL, dest, NULL, countx,
4223 /*dest_uninitialized*/true);
4225 // If necessary, emit some card marks afterwards. (Non-arrays only.)
4226 if (card_mark) {
4227 assert(!is_array, "");
4228 // Put in store barrier for any and all oops we are sticking
4229 // into this object. (We could avoid this if we could prove
4230 // that the object type contains no oop fields at all.)
4231 Node* no_particular_value = NULL;
4232 Node* no_particular_field = NULL;
4233 int raw_adr_idx = Compile::AliasIdxRaw;
4234 post_barrier(control(),
4235 memory(raw_adr_type),
4236 alloc_obj,
4237 no_particular_field,
4238 raw_adr_idx,
4239 no_particular_value,
4240 T_OBJECT,
4241 false);
4242 }
4244 // Do not let reads from the cloned object float above the arraycopy.
4245 if (alloc != NULL) {
4246 // Do not let stores that initialize this object be reordered with
4247 // a subsequent store that would make this object accessible by
4248 // other threads.
4249 // Record what AllocateNode this StoreStore protects so that
4250 // escape analysis can go from the MemBarStoreStoreNode to the
4251 // AllocateNode and eliminate the MemBarStoreStoreNode if possible
4252 // based on the escape status of the AllocateNode.
4253 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out(AllocateNode::RawAddress));
4254 } else {
4255 insert_mem_bar(Op_MemBarCPUOrder);
4256 }
4257 }
4259 //------------------------inline_native_clone----------------------------
4260 // Here are the simple edge cases:
4261 // null receiver => normal trap
4262 // virtual and clone was overridden => slow path to out-of-line clone
4263 // not cloneable or finalizer => slow path to out-of-line Object.clone
4264 //
4265 // The general case has two steps, allocation and copying.
4266 // Allocation has two cases, and uses GraphKit::new_instance or new_array.
4267 //
4268 // Copying also has two cases, oop arrays and everything else.
4269 // Oop arrays use arrayof_oop_arraycopy (same as System.arraycopy).
4270 // Everything else uses the tight inline loop supplied by CopyArrayNode.
4271 //
4272 // These steps fold up nicely if and when the cloned object's klass
4273 // can be sharply typed as an object array, a type array, or an instance.
4274 //
4275 bool LibraryCallKit::inline_native_clone(bool is_virtual) {
4276 int nargs = 1;
4277 PhiNode* result_val;
4279 //set the original stack and the reexecute bit for the interpreter to reexecute
4280 //the bytecode that invokes Object.clone if deoptimization happens
4281 { PreserveReexecuteState preexecs(this);
4282 jvms()->set_should_reexecute(true);
4284 //null_check_receiver will adjust _sp (push and pop)
4285 Node* obj = null_check_receiver(callee());
4286 if (stopped()) return true;
4288 _sp += nargs;
4290 Node* obj_klass = load_object_klass(obj);
4291 const TypeKlassPtr* tklass = _gvn.type(obj_klass)->isa_klassptr();
4292 const TypeOopPtr* toop = ((tklass != NULL)
4293 ? tklass->as_instance_type()
4294 : TypeInstPtr::NOTNULL);
4296 // Conservatively insert a memory barrier on all memory slices.
4297 // Do not let writes into the original float below the clone.
4298 insert_mem_bar(Op_MemBarCPUOrder);
4300 // paths into result_reg:
4301 enum {
4302 _slow_path = 1, // out-of-line call to clone method (virtual or not)
4303 _objArray_path, // plain array allocation, plus arrayof_oop_arraycopy
4304 _array_path, // plain array allocation, plus arrayof_long_arraycopy
4305 _instance_path, // plain instance allocation, plus arrayof_long_arraycopy
4306 PATH_LIMIT
4307 };
4308 RegionNode* result_reg = new(C, PATH_LIMIT) RegionNode(PATH_LIMIT);
4309 result_val = new(C, PATH_LIMIT) PhiNode(result_reg,
4310 TypeInstPtr::NOTNULL);
4311 PhiNode* result_i_o = new(C, PATH_LIMIT) PhiNode(result_reg, Type::ABIO);
4312 PhiNode* result_mem = new(C, PATH_LIMIT) PhiNode(result_reg, Type::MEMORY,
4313 TypePtr::BOTTOM);
4314 record_for_igvn(result_reg);
4316 const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM;
4317 int raw_adr_idx = Compile::AliasIdxRaw;
4319 Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)NULL);
4320 if (array_ctl != NULL) {
4321 // It's an array.
4322 PreserveJVMState pjvms(this);
4323 set_control(array_ctl);
4324 Node* obj_length = load_array_length(obj);
4325 Node* obj_size = NULL;
4326 Node* alloc_obj = new_array(obj_klass, obj_length, 0, &obj_size);
4328 if (!use_ReduceInitialCardMarks()) {
4329 // If it is an oop array, it requires very special treatment,
4330 // because card marking is required on each card of the array.
4331 Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)NULL);
4332 if (is_obja != NULL) {
4333 PreserveJVMState pjvms2(this);
4334 set_control(is_obja);
4335 // Generate a direct call to the right arraycopy function(s).
4336 bool disjoint_bases = true;
4337 bool length_never_negative = true;
4338 generate_arraycopy(TypeAryPtr::OOPS, T_OBJECT,
4339 obj, intcon(0), alloc_obj, intcon(0),
4340 obj_length,
4341 disjoint_bases, length_never_negative);
4342 result_reg->init_req(_objArray_path, control());
4343 result_val->init_req(_objArray_path, alloc_obj);
4344 result_i_o ->set_req(_objArray_path, i_o());
4345 result_mem ->set_req(_objArray_path, reset_memory());
4346 }
4347 }
4348 // Otherwise, there are no card marks to worry about.
4349 // (We can dispense with card marks if we know the allocation
4350 // comes out of eden (TLAB)... In fact, ReduceInitialCardMarks
4351 // causes the non-eden paths to take compensating steps to
4352 // simulate a fresh allocation, so that no further
4353 // card marks are required in compiled code to initialize
4354 // the object.)
4356 if (!stopped()) {
4357 copy_to_clone(obj, alloc_obj, obj_size, true, false);
4359 // Present the results of the copy.
4360 result_reg->init_req(_array_path, control());
4361 result_val->init_req(_array_path, alloc_obj);
4362 result_i_o ->set_req(_array_path, i_o());
4363 result_mem ->set_req(_array_path, reset_memory());
4364 }
4365 }
4367 // We only go to the instance fast case code if we pass a number of guards.
4368 // The paths which do not pass are accumulated in the slow_region.
4369 RegionNode* slow_region = new (C, 1) RegionNode(1);
4370 record_for_igvn(slow_region);
4371 if (!stopped()) {
4372 // It's an instance (we did array above). Make the slow-path tests.
4373 // If this is a virtual call, we generate a funny guard. We grab
4374 // the vtable entry corresponding to clone() from the target object.
4375 // If the target method which we are calling happens to be the
4376 // Object clone() method, we pass the guard. We do not need this
4377 // guard for non-virtual calls; the caller is known to be the native
4378 // Object clone().
4379 if (is_virtual) {
4380 generate_virtual_guard(obj_klass, slow_region);
4381 }
4383 // The object must be cloneable and must not have a finalizer.
4384 // Both of these conditions may be checked in a single test.
4385 // We could optimize the cloneable test further, but we don't care.
4386 generate_access_flags_guard(obj_klass,
4387 // Test both conditions:
4388 JVM_ACC_IS_CLONEABLE | JVM_ACC_HAS_FINALIZER,
4389 // Must be cloneable but not finalizer:
4390 JVM_ACC_IS_CLONEABLE,
4391 slow_region);
4392 }
4394 if (!stopped()) {
4395 // It's an instance, and it passed the slow-path tests.
4396 PreserveJVMState pjvms(this);
4397 Node* obj_size = NULL;
4398 Node* alloc_obj = new_instance(obj_klass, NULL, &obj_size);
4400 copy_to_clone(obj, alloc_obj, obj_size, false, !use_ReduceInitialCardMarks());
4402 // Present the results of the slow call.
4403 result_reg->init_req(_instance_path, control());
4404 result_val->init_req(_instance_path, alloc_obj);
4405 result_i_o ->set_req(_instance_path, i_o());
4406 result_mem ->set_req(_instance_path, reset_memory());
4407 }
4409 // Generate code for the slow case. We make a call to clone().
4410 set_control(_gvn.transform(slow_region));
4411 if (!stopped()) {
4412 PreserveJVMState pjvms(this);
4413 CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_clone, is_virtual);
4414 Node* slow_result = set_results_for_java_call(slow_call);
4415 // this->control() comes from set_results_for_java_call
4416 result_reg->init_req(_slow_path, control());
4417 result_val->init_req(_slow_path, slow_result);
4418 result_i_o ->set_req(_slow_path, i_o());
4419 result_mem ->set_req(_slow_path, reset_memory());
4420 }
4422 // Return the combined state.
4423 set_control( _gvn.transform(result_reg) );
4424 set_i_o( _gvn.transform(result_i_o) );
4425 set_all_memory( _gvn.transform(result_mem) );
4426 } //original reexecute and sp are set back here
4428 push(_gvn.transform(result_val));
4430 return true;
4431 }
4433 //------------------------------basictype2arraycopy----------------------------
4434 address LibraryCallKit::basictype2arraycopy(BasicType t,
4435 Node* src_offset,
4436 Node* dest_offset,
4437 bool disjoint_bases,
4438 const char* &name,
4439 bool dest_uninitialized) {
4440 const TypeInt* src_offset_inttype = gvn().find_int_type(src_offset);;
4441 const TypeInt* dest_offset_inttype = gvn().find_int_type(dest_offset);;
4443 bool aligned = false;
4444 bool disjoint = disjoint_bases;
4446 // if the offsets are the same, we can treat the memory regions as
4447 // disjoint, because either the memory regions are in different arrays,
4448 // or they are identical (which we can treat as disjoint.) We can also
4449 // treat a copy with a destination index less that the source index
4450 // as disjoint since a low->high copy will work correctly in this case.
4451 if (src_offset_inttype != NULL && src_offset_inttype->is_con() &&
4452 dest_offset_inttype != NULL && dest_offset_inttype->is_con()) {
4453 // both indices are constants
4454 int s_offs = src_offset_inttype->get_con();
4455 int d_offs = dest_offset_inttype->get_con();
4456 int element_size = type2aelembytes(t);
4457 aligned = ((arrayOopDesc::base_offset_in_bytes(t) + s_offs * element_size) % HeapWordSize == 0) &&
4458 ((arrayOopDesc::base_offset_in_bytes(t) + d_offs * element_size) % HeapWordSize == 0);
4459 if (s_offs >= d_offs) disjoint = true;
4460 } else if (src_offset == dest_offset && src_offset != NULL) {
4461 // This can occur if the offsets are identical non-constants.
4462 disjoint = true;
4463 }
4465 return StubRoutines::select_arraycopy_function(t, aligned, disjoint, name, dest_uninitialized);
4466 }
4469 //------------------------------inline_arraycopy-----------------------
4470 bool LibraryCallKit::inline_arraycopy() {
4471 // Restore the stack and pop off the arguments.
4472 int nargs = 5; // 2 oops, 3 ints, no size_t or long
4473 assert(callee()->signature()->size() == nargs, "copy has 5 arguments");
4475 Node *src = argument(0);
4476 Node *src_offset = argument(1);
4477 Node *dest = argument(2);
4478 Node *dest_offset = argument(3);
4479 Node *length = argument(4);
4481 // Compile time checks. If any of these checks cannot be verified at compile time,
4482 // we do not make a fast path for this call. Instead, we let the call remain as it
4483 // is. The checks we choose to mandate at compile time are:
4484 //
4485 // (1) src and dest are arrays.
4486 const Type* src_type = src->Value(&_gvn);
4487 const Type* dest_type = dest->Value(&_gvn);
4488 const TypeAryPtr* top_src = src_type->isa_aryptr();
4489 const TypeAryPtr* top_dest = dest_type->isa_aryptr();
4490 if (top_src == NULL || top_src->klass() == NULL ||
4491 top_dest == NULL || top_dest->klass() == NULL) {
4492 // Conservatively insert a memory barrier on all memory slices.
4493 // Do not let writes into the source float below the arraycopy.
4494 insert_mem_bar(Op_MemBarCPUOrder);
4496 // Call StubRoutines::generic_arraycopy stub.
4497 generate_arraycopy(TypeRawPtr::BOTTOM, T_CONFLICT,
4498 src, src_offset, dest, dest_offset, length);
4500 // Do not let reads from the destination float above the arraycopy.
4501 // Since we cannot type the arrays, we don't know which slices
4502 // might be affected. We could restrict this barrier only to those
4503 // memory slices which pertain to array elements--but don't bother.
4504 if (!InsertMemBarAfterArraycopy)
4505 // (If InsertMemBarAfterArraycopy, there is already one in place.)
4506 insert_mem_bar(Op_MemBarCPUOrder);
4507 return true;
4508 }
4510 // (2) src and dest arrays must have elements of the same BasicType
4511 // Figure out the size and type of the elements we will be copying.
4512 BasicType src_elem = top_src->klass()->as_array_klass()->element_type()->basic_type();
4513 BasicType dest_elem = top_dest->klass()->as_array_klass()->element_type()->basic_type();
4514 if (src_elem == T_ARRAY) src_elem = T_OBJECT;
4515 if (dest_elem == T_ARRAY) dest_elem = T_OBJECT;
4517 if (src_elem != dest_elem || dest_elem == T_VOID) {
4518 // The component types are not the same or are not recognized. Punt.
4519 // (But, avoid the native method wrapper to JVM_ArrayCopy.)
4520 generate_slow_arraycopy(TypePtr::BOTTOM,
4521 src, src_offset, dest, dest_offset, length,
4522 /*dest_uninitialized*/false);
4523 return true;
4524 }
4526 //---------------------------------------------------------------------------
4527 // We will make a fast path for this call to arraycopy.
4529 // We have the following tests left to perform:
4530 //
4531 // (3) src and dest must not be null.
4532 // (4) src_offset must not be negative.
4533 // (5) dest_offset must not be negative.
4534 // (6) length must not be negative.
4535 // (7) src_offset + length must not exceed length of src.
4536 // (8) dest_offset + length must not exceed length of dest.
4537 // (9) each element of an oop array must be assignable
4539 RegionNode* slow_region = new (C, 1) RegionNode(1);
4540 record_for_igvn(slow_region);
4542 // (3) operands must not be null
4543 // We currently perform our null checks with the do_null_check routine.
4544 // This means that the null exceptions will be reported in the caller
4545 // rather than (correctly) reported inside of the native arraycopy call.
4546 // This should be corrected, given time. We do our null check with the
4547 // stack pointer restored.
4548 _sp += nargs;
4549 src = do_null_check(src, T_ARRAY);
4550 dest = do_null_check(dest, T_ARRAY);
4551 _sp -= nargs;
4553 // (4) src_offset must not be negative.
4554 generate_negative_guard(src_offset, slow_region);
4556 // (5) dest_offset must not be negative.
4557 generate_negative_guard(dest_offset, slow_region);
4559 // (6) length must not be negative (moved to generate_arraycopy()).
4560 // generate_negative_guard(length, slow_region);
4562 // (7) src_offset + length must not exceed length of src.
4563 generate_limit_guard(src_offset, length,
4564 load_array_length(src),
4565 slow_region);
4567 // (8) dest_offset + length must not exceed length of dest.
4568 generate_limit_guard(dest_offset, length,
4569 load_array_length(dest),
4570 slow_region);
4572 // (9) each element of an oop array must be assignable
4573 // The generate_arraycopy subroutine checks this.
4575 // This is where the memory effects are placed:
4576 const TypePtr* adr_type = TypeAryPtr::get_array_body_type(dest_elem);
4577 generate_arraycopy(adr_type, dest_elem,
4578 src, src_offset, dest, dest_offset, length,
4579 false, false, slow_region);
4581 return true;
4582 }
4584 //-----------------------------generate_arraycopy----------------------
4585 // Generate an optimized call to arraycopy.
4586 // Caller must guard against non-arrays.
4587 // Caller must determine a common array basic-type for both arrays.
4588 // Caller must validate offsets against array bounds.
4589 // The slow_region has already collected guard failure paths
4590 // (such as out of bounds length or non-conformable array types).
4591 // The generated code has this shape, in general:
4592 //
4593 // if (length == 0) return // via zero_path
4594 // slowval = -1
4595 // if (types unknown) {
4596 // slowval = call generic copy loop
4597 // if (slowval == 0) return // via checked_path
4598 // } else if (indexes in bounds) {
4599 // if ((is object array) && !(array type check)) {
4600 // slowval = call checked copy loop
4601 // if (slowval == 0) return // via checked_path
4602 // } else {
4603 // call bulk copy loop
4604 // return // via fast_path
4605 // }
4606 // }
4607 // // adjust params for remaining work:
4608 // if (slowval != -1) {
4609 // n = -1^slowval; src_offset += n; dest_offset += n; length -= n
4610 // }
4611 // slow_region:
4612 // call slow arraycopy(src, src_offset, dest, dest_offset, length)
4613 // return // via slow_call_path
4614 //
4615 // This routine is used from several intrinsics: System.arraycopy,
4616 // Object.clone (the array subcase), and Arrays.copyOf[Range].
4617 //
4618 void
4619 LibraryCallKit::generate_arraycopy(const TypePtr* adr_type,
4620 BasicType basic_elem_type,
4621 Node* src, Node* src_offset,
4622 Node* dest, Node* dest_offset,
4623 Node* copy_length,
4624 bool disjoint_bases,
4625 bool length_never_negative,
4626 RegionNode* slow_region) {
4628 if (slow_region == NULL) {
4629 slow_region = new(C,1) RegionNode(1);
4630 record_for_igvn(slow_region);
4631 }
4633 Node* original_dest = dest;
4634 AllocateArrayNode* alloc = NULL; // used for zeroing, if needed
4635 bool dest_uninitialized = false;
4637 // See if this is the initialization of a newly-allocated array.
4638 // If so, we will take responsibility here for initializing it to zero.
4639 // (Note: Because tightly_coupled_allocation performs checks on the
4640 // out-edges of the dest, we need to avoid making derived pointers
4641 // from it until we have checked its uses.)
4642 if (ReduceBulkZeroing
4643 && !ZeroTLAB // pointless if already zeroed
4644 && basic_elem_type != T_CONFLICT // avoid corner case
4645 && !src->eqv_uncast(dest)
4646 && ((alloc = tightly_coupled_allocation(dest, slow_region))
4647 != NULL)
4648 && _gvn.find_int_con(alloc->in(AllocateNode::ALength), 1) > 0
4649 && alloc->maybe_set_complete(&_gvn)) {
4650 // "You break it, you buy it."
4651 InitializeNode* init = alloc->initialization();
4652 assert(init->is_complete(), "we just did this");
4653 init->set_complete_with_arraycopy();
4654 assert(dest->is_CheckCastPP(), "sanity");
4655 assert(dest->in(0)->in(0) == init, "dest pinned");
4656 adr_type = TypeRawPtr::BOTTOM; // all initializations are into raw memory
4657 // From this point on, every exit path is responsible for
4658 // initializing any non-copied parts of the object to zero.
4659 // Also, if this flag is set we make sure that arraycopy interacts properly
4660 // with G1, eliding pre-barriers. See CR 6627983.
4661 dest_uninitialized = true;
4662 } else {
4663 // No zeroing elimination here.
4664 alloc = NULL;
4665 //original_dest = dest;
4666 //dest_uninitialized = false;
4667 }
4669 // Results are placed here:
4670 enum { fast_path = 1, // normal void-returning assembly stub
4671 checked_path = 2, // special assembly stub with cleanup
4672 slow_call_path = 3, // something went wrong; call the VM
4673 zero_path = 4, // bypass when length of copy is zero
4674 bcopy_path = 5, // copy primitive array by 64-bit blocks
4675 PATH_LIMIT = 6
4676 };
4677 RegionNode* result_region = new(C, PATH_LIMIT) RegionNode(PATH_LIMIT);
4678 PhiNode* result_i_o = new(C, PATH_LIMIT) PhiNode(result_region, Type::ABIO);
4679 PhiNode* result_memory = new(C, PATH_LIMIT) PhiNode(result_region, Type::MEMORY, adr_type);
4680 record_for_igvn(result_region);
4681 _gvn.set_type_bottom(result_i_o);
4682 _gvn.set_type_bottom(result_memory);
4683 assert(adr_type != TypePtr::BOTTOM, "must be RawMem or a T[] slice");
4685 // The slow_control path:
4686 Node* slow_control;
4687 Node* slow_i_o = i_o();
4688 Node* slow_mem = memory(adr_type);
4689 debug_only(slow_control = (Node*) badAddress);
4691 // Checked control path:
4692 Node* checked_control = top();
4693 Node* checked_mem = NULL;
4694 Node* checked_i_o = NULL;
4695 Node* checked_value = NULL;
4697 if (basic_elem_type == T_CONFLICT) {
4698 assert(!dest_uninitialized, "");
4699 Node* cv = generate_generic_arraycopy(adr_type,
4700 src, src_offset, dest, dest_offset,
4701 copy_length, dest_uninitialized);
4702 if (cv == NULL) cv = intcon(-1); // failure (no stub available)
4703 checked_control = control();
4704 checked_i_o = i_o();
4705 checked_mem = memory(adr_type);
4706 checked_value = cv;
4707 set_control(top()); // no fast path
4708 }
4710 Node* not_pos = generate_nonpositive_guard(copy_length, length_never_negative);
4711 if (not_pos != NULL) {
4712 PreserveJVMState pjvms(this);
4713 set_control(not_pos);
4715 // (6) length must not be negative.
4716 if (!length_never_negative) {
4717 generate_negative_guard(copy_length, slow_region);
4718 }
4720 // copy_length is 0.
4721 if (!stopped() && dest_uninitialized) {
4722 Node* dest_length = alloc->in(AllocateNode::ALength);
4723 if (copy_length->eqv_uncast(dest_length)
4724 || _gvn.find_int_con(dest_length, 1) <= 0) {
4725 // There is no zeroing to do. No need for a secondary raw memory barrier.
4726 } else {
4727 // Clear the whole thing since there are no source elements to copy.
4728 generate_clear_array(adr_type, dest, basic_elem_type,
4729 intcon(0), NULL,
4730 alloc->in(AllocateNode::AllocSize));
4731 // Use a secondary InitializeNode as raw memory barrier.
4732 // Currently it is needed only on this path since other
4733 // paths have stub or runtime calls as raw memory barriers.
4734 InitializeNode* init = insert_mem_bar_volatile(Op_Initialize,
4735 Compile::AliasIdxRaw,
4736 top())->as_Initialize();
4737 init->set_complete(&_gvn); // (there is no corresponding AllocateNode)
4738 }
4739 }
4741 // Present the results of the fast call.
4742 result_region->init_req(zero_path, control());
4743 result_i_o ->init_req(zero_path, i_o());
4744 result_memory->init_req(zero_path, memory(adr_type));
4745 }
4747 if (!stopped() && dest_uninitialized) {
4748 // We have to initialize the *uncopied* part of the array to zero.
4749 // The copy destination is the slice dest[off..off+len]. The other slices
4750 // are dest_head = dest[0..off] and dest_tail = dest[off+len..dest.length].
4751 Node* dest_size = alloc->in(AllocateNode::AllocSize);
4752 Node* dest_length = alloc->in(AllocateNode::ALength);
4753 Node* dest_tail = _gvn.transform( new(C,3) AddINode(dest_offset,
4754 copy_length) );
4756 // If there is a head section that needs zeroing, do it now.
4757 if (find_int_con(dest_offset, -1) != 0) {
4758 generate_clear_array(adr_type, dest, basic_elem_type,
4759 intcon(0), dest_offset,
4760 NULL);
4761 }
4763 // Next, perform a dynamic check on the tail length.
4764 // It is often zero, and we can win big if we prove this.
4765 // There are two wins: Avoid generating the ClearArray
4766 // with its attendant messy index arithmetic, and upgrade
4767 // the copy to a more hardware-friendly word size of 64 bits.
4768 Node* tail_ctl = NULL;
4769 if (!stopped() && !dest_tail->eqv_uncast(dest_length)) {
4770 Node* cmp_lt = _gvn.transform( new(C,3) CmpINode(dest_tail, dest_length) );
4771 Node* bol_lt = _gvn.transform( new(C,2) BoolNode(cmp_lt, BoolTest::lt) );
4772 tail_ctl = generate_slow_guard(bol_lt, NULL);
4773 assert(tail_ctl != NULL || !stopped(), "must be an outcome");
4774 }
4776 // At this point, let's assume there is no tail.
4777 if (!stopped() && alloc != NULL && basic_elem_type != T_OBJECT) {
4778 // There is no tail. Try an upgrade to a 64-bit copy.
4779 bool didit = false;
4780 { PreserveJVMState pjvms(this);
4781 didit = generate_block_arraycopy(adr_type, basic_elem_type, alloc,
4782 src, src_offset, dest, dest_offset,
4783 dest_size, dest_uninitialized);
4784 if (didit) {
4785 // Present the results of the block-copying fast call.
4786 result_region->init_req(bcopy_path, control());
4787 result_i_o ->init_req(bcopy_path, i_o());
4788 result_memory->init_req(bcopy_path, memory(adr_type));
4789 }
4790 }
4791 if (didit)
4792 set_control(top()); // no regular fast path
4793 }
4795 // Clear the tail, if any.
4796 if (tail_ctl != NULL) {
4797 Node* notail_ctl = stopped() ? NULL : control();
4798 set_control(tail_ctl);
4799 if (notail_ctl == NULL) {
4800 generate_clear_array(adr_type, dest, basic_elem_type,
4801 dest_tail, NULL,
4802 dest_size);
4803 } else {
4804 // Make a local merge.
4805 Node* done_ctl = new(C,3) RegionNode(3);
4806 Node* done_mem = new(C,3) PhiNode(done_ctl, Type::MEMORY, adr_type);
4807 done_ctl->init_req(1, notail_ctl);
4808 done_mem->init_req(1, memory(adr_type));
4809 generate_clear_array(adr_type, dest, basic_elem_type,
4810 dest_tail, NULL,
4811 dest_size);
4812 done_ctl->init_req(2, control());
4813 done_mem->init_req(2, memory(adr_type));
4814 set_control( _gvn.transform(done_ctl) );
4815 set_memory( _gvn.transform(done_mem), adr_type );
4816 }
4817 }
4818 }
4820 BasicType copy_type = basic_elem_type;
4821 assert(basic_elem_type != T_ARRAY, "caller must fix this");
4822 if (!stopped() && copy_type == T_OBJECT) {
4823 // If src and dest have compatible element types, we can copy bits.
4824 // Types S[] and D[] are compatible if D is a supertype of S.
4825 //
4826 // If they are not, we will use checked_oop_disjoint_arraycopy,
4827 // which performs a fast optimistic per-oop check, and backs off
4828 // further to JVM_ArrayCopy on the first per-oop check that fails.
4829 // (Actually, we don't move raw bits only; the GC requires card marks.)
4831 // Get the klassOop for both src and dest
4832 Node* src_klass = load_object_klass(src);
4833 Node* dest_klass = load_object_klass(dest);
4835 // Generate the subtype check.
4836 // This might fold up statically, or then again it might not.
4837 //
4838 // Non-static example: Copying List<String>.elements to a new String[].
4839 // The backing store for a List<String> is always an Object[],
4840 // but its elements are always type String, if the generic types
4841 // are correct at the source level.
4842 //
4843 // Test S[] against D[], not S against D, because (probably)
4844 // the secondary supertype cache is less busy for S[] than S.
4845 // This usually only matters when D is an interface.
4846 Node* not_subtype_ctrl = gen_subtype_check(src_klass, dest_klass);
4847 // Plug failing path into checked_oop_disjoint_arraycopy
4848 if (not_subtype_ctrl != top()) {
4849 PreserveJVMState pjvms(this);
4850 set_control(not_subtype_ctrl);
4851 // (At this point we can assume disjoint_bases, since types differ.)
4852 int ek_offset = in_bytes(objArrayKlass::element_klass_offset());
4853 Node* p1 = basic_plus_adr(dest_klass, ek_offset);
4854 Node* n1 = LoadKlassNode::make(_gvn, immutable_memory(), p1, TypeRawPtr::BOTTOM);
4855 Node* dest_elem_klass = _gvn.transform(n1);
4856 Node* cv = generate_checkcast_arraycopy(adr_type,
4857 dest_elem_klass,
4858 src, src_offset, dest, dest_offset,
4859 ConvI2X(copy_length), dest_uninitialized);
4860 if (cv == NULL) cv = intcon(-1); // failure (no stub available)
4861 checked_control = control();
4862 checked_i_o = i_o();
4863 checked_mem = memory(adr_type);
4864 checked_value = cv;
4865 }
4866 // At this point we know we do not need type checks on oop stores.
4868 // Let's see if we need card marks:
4869 if (alloc != NULL && use_ReduceInitialCardMarks()) {
4870 // If we do not need card marks, copy using the jint or jlong stub.
4871 copy_type = LP64_ONLY(UseCompressedOops ? T_INT : T_LONG) NOT_LP64(T_INT);
4872 assert(type2aelembytes(basic_elem_type) == type2aelembytes(copy_type),
4873 "sizes agree");
4874 }
4875 }
4877 if (!stopped()) {
4878 // Generate the fast path, if possible.
4879 PreserveJVMState pjvms(this);
4880 generate_unchecked_arraycopy(adr_type, copy_type, disjoint_bases,
4881 src, src_offset, dest, dest_offset,
4882 ConvI2X(copy_length), dest_uninitialized);
4884 // Present the results of the fast call.
4885 result_region->init_req(fast_path, control());
4886 result_i_o ->init_req(fast_path, i_o());
4887 result_memory->init_req(fast_path, memory(adr_type));
4888 }
4890 // Here are all the slow paths up to this point, in one bundle:
4891 slow_control = top();
4892 if (slow_region != NULL)
4893 slow_control = _gvn.transform(slow_region);
4894 debug_only(slow_region = (RegionNode*)badAddress);
4896 set_control(checked_control);
4897 if (!stopped()) {
4898 // Clean up after the checked call.
4899 // The returned value is either 0 or -1^K,
4900 // where K = number of partially transferred array elements.
4901 Node* cmp = _gvn.transform( new(C, 3) CmpINode(checked_value, intcon(0)) );
4902 Node* bol = _gvn.transform( new(C, 2) BoolNode(cmp, BoolTest::eq) );
4903 IfNode* iff = create_and_map_if(control(), bol, PROB_MAX, COUNT_UNKNOWN);
4905 // If it is 0, we are done, so transfer to the end.
4906 Node* checks_done = _gvn.transform( new(C, 1) IfTrueNode(iff) );
4907 result_region->init_req(checked_path, checks_done);
4908 result_i_o ->init_req(checked_path, checked_i_o);
4909 result_memory->init_req(checked_path, checked_mem);
4911 // If it is not zero, merge into the slow call.
4912 set_control( _gvn.transform( new(C, 1) IfFalseNode(iff) ));
4913 RegionNode* slow_reg2 = new(C, 3) RegionNode(3);
4914 PhiNode* slow_i_o2 = new(C, 3) PhiNode(slow_reg2, Type::ABIO);
4915 PhiNode* slow_mem2 = new(C, 3) PhiNode(slow_reg2, Type::MEMORY, adr_type);
4916 record_for_igvn(slow_reg2);
4917 slow_reg2 ->init_req(1, slow_control);
4918 slow_i_o2 ->init_req(1, slow_i_o);
4919 slow_mem2 ->init_req(1, slow_mem);
4920 slow_reg2 ->init_req(2, control());
4921 slow_i_o2 ->init_req(2, checked_i_o);
4922 slow_mem2 ->init_req(2, checked_mem);
4924 slow_control = _gvn.transform(slow_reg2);
4925 slow_i_o = _gvn.transform(slow_i_o2);
4926 slow_mem = _gvn.transform(slow_mem2);
4928 if (alloc != NULL) {
4929 // We'll restart from the very beginning, after zeroing the whole thing.
4930 // This can cause double writes, but that's OK since dest is brand new.
4931 // So we ignore the low 31 bits of the value returned from the stub.
4932 } else {
4933 // We must continue the copy exactly where it failed, or else
4934 // another thread might see the wrong number of writes to dest.
4935 Node* checked_offset = _gvn.transform( new(C, 3) XorINode(checked_value, intcon(-1)) );
4936 Node* slow_offset = new(C, 3) PhiNode(slow_reg2, TypeInt::INT);
4937 slow_offset->init_req(1, intcon(0));
4938 slow_offset->init_req(2, checked_offset);
4939 slow_offset = _gvn.transform(slow_offset);
4941 // Adjust the arguments by the conditionally incoming offset.
4942 Node* src_off_plus = _gvn.transform( new(C, 3) AddINode(src_offset, slow_offset) );
4943 Node* dest_off_plus = _gvn.transform( new(C, 3) AddINode(dest_offset, slow_offset) );
4944 Node* length_minus = _gvn.transform( new(C, 3) SubINode(copy_length, slow_offset) );
4946 // Tweak the node variables to adjust the code produced below:
4947 src_offset = src_off_plus;
4948 dest_offset = dest_off_plus;
4949 copy_length = length_minus;
4950 }
4951 }
4953 set_control(slow_control);
4954 if (!stopped()) {
4955 // Generate the slow path, if needed.
4956 PreserveJVMState pjvms(this); // replace_in_map may trash the map
4958 set_memory(slow_mem, adr_type);
4959 set_i_o(slow_i_o);
4961 if (dest_uninitialized) {
4962 generate_clear_array(adr_type, dest, basic_elem_type,
4963 intcon(0), NULL,
4964 alloc->in(AllocateNode::AllocSize));
4965 }
4967 generate_slow_arraycopy(adr_type,
4968 src, src_offset, dest, dest_offset,
4969 copy_length, /*dest_uninitialized*/false);
4971 result_region->init_req(slow_call_path, control());
4972 result_i_o ->init_req(slow_call_path, i_o());
4973 result_memory->init_req(slow_call_path, memory(adr_type));
4974 }
4976 // Remove unused edges.
4977 for (uint i = 1; i < result_region->req(); i++) {
4978 if (result_region->in(i) == NULL)
4979 result_region->init_req(i, top());
4980 }
4982 // Finished; return the combined state.
4983 set_control( _gvn.transform(result_region) );
4984 set_i_o( _gvn.transform(result_i_o) );
4985 set_memory( _gvn.transform(result_memory), adr_type );
4987 // The memory edges above are precise in order to model effects around
4988 // array copies accurately to allow value numbering of field loads around
4989 // arraycopy. Such field loads, both before and after, are common in Java
4990 // collections and similar classes involving header/array data structures.
4991 //
4992 // But with low number of register or when some registers are used or killed
4993 // by arraycopy calls it causes registers spilling on stack. See 6544710.
4994 // The next memory barrier is added to avoid it. If the arraycopy can be
4995 // optimized away (which it can, sometimes) then we can manually remove
4996 // the membar also.
4997 //
4998 // Do not let reads from the cloned object float above the arraycopy.
4999 if (alloc != NULL) {
5000 // Do not let stores that initialize this object be reordered with
5001 // a subsequent store that would make this object accessible by
5002 // other threads.
5003 // Record what AllocateNode this StoreStore protects so that
5004 // escape analysis can go from the MemBarStoreStoreNode to the
5005 // AllocateNode and eliminate the MemBarStoreStoreNode if possible
5006 // based on the escape status of the AllocateNode.
5007 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out(AllocateNode::RawAddress));
5008 } else if (InsertMemBarAfterArraycopy)
5009 insert_mem_bar(Op_MemBarCPUOrder);
5010 }
5013 // Helper function which determines if an arraycopy immediately follows
5014 // an allocation, with no intervening tests or other escapes for the object.
5015 AllocateArrayNode*
5016 LibraryCallKit::tightly_coupled_allocation(Node* ptr,
5017 RegionNode* slow_region) {
5018 if (stopped()) return NULL; // no fast path
5019 if (C->AliasLevel() == 0) return NULL; // no MergeMems around
5021 AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(ptr, &_gvn);
5022 if (alloc == NULL) return NULL;
5024 Node* rawmem = memory(Compile::AliasIdxRaw);
5025 // Is the allocation's memory state untouched?
5026 if (!(rawmem->is_Proj() && rawmem->in(0)->is_Initialize())) {
5027 // Bail out if there have been raw-memory effects since the allocation.
5028 // (Example: There might have been a call or safepoint.)
5029 return NULL;
5030 }
5031 rawmem = rawmem->in(0)->as_Initialize()->memory(Compile::AliasIdxRaw);
5032 if (!(rawmem->is_Proj() && rawmem->in(0) == alloc)) {
5033 return NULL;
5034 }
5036 // There must be no unexpected observers of this allocation.
5037 for (DUIterator_Fast imax, i = ptr->fast_outs(imax); i < imax; i++) {
5038 Node* obs = ptr->fast_out(i);
5039 if (obs != this->map()) {
5040 return NULL;
5041 }
5042 }
5044 // This arraycopy must unconditionally follow the allocation of the ptr.
5045 Node* alloc_ctl = ptr->in(0);
5046 assert(just_allocated_object(alloc_ctl) == ptr, "most recent allo");
5048 Node* ctl = control();
5049 while (ctl != alloc_ctl) {
5050 // There may be guards which feed into the slow_region.
5051 // Any other control flow means that we might not get a chance
5052 // to finish initializing the allocated object.
5053 if ((ctl->is_IfFalse() || ctl->is_IfTrue()) && ctl->in(0)->is_If()) {
5054 IfNode* iff = ctl->in(0)->as_If();
5055 Node* not_ctl = iff->proj_out(1 - ctl->as_Proj()->_con);
5056 assert(not_ctl != NULL && not_ctl != ctl, "found alternate");
5057 if (slow_region != NULL && slow_region->find_edge(not_ctl) >= 1) {
5058 ctl = iff->in(0); // This test feeds the known slow_region.
5059 continue;
5060 }
5061 // One more try: Various low-level checks bottom out in
5062 // uncommon traps. If the debug-info of the trap omits
5063 // any reference to the allocation, as we've already
5064 // observed, then there can be no objection to the trap.
5065 bool found_trap = false;
5066 for (DUIterator_Fast jmax, j = not_ctl->fast_outs(jmax); j < jmax; j++) {
5067 Node* obs = not_ctl->fast_out(j);
5068 if (obs->in(0) == not_ctl && obs->is_Call() &&
5069 (obs->as_Call()->entry_point() == SharedRuntime::uncommon_trap_blob()->entry_point())) {
5070 found_trap = true; break;
5071 }
5072 }
5073 if (found_trap) {
5074 ctl = iff->in(0); // This test feeds a harmless uncommon trap.
5075 continue;
5076 }
5077 }
5078 return NULL;
5079 }
5081 // If we get this far, we have an allocation which immediately
5082 // precedes the arraycopy, and we can take over zeroing the new object.
5083 // The arraycopy will finish the initialization, and provide
5084 // a new control state to which we will anchor the destination pointer.
5086 return alloc;
5087 }
5089 // Helper for initialization of arrays, creating a ClearArray.
5090 // It writes zero bits in [start..end), within the body of an array object.
5091 // The memory effects are all chained onto the 'adr_type' alias category.
5092 //
5093 // Since the object is otherwise uninitialized, we are free
5094 // to put a little "slop" around the edges of the cleared area,
5095 // as long as it does not go back into the array's header,
5096 // or beyond the array end within the heap.
5097 //
5098 // The lower edge can be rounded down to the nearest jint and the
5099 // upper edge can be rounded up to the nearest MinObjAlignmentInBytes.
5100 //
5101 // Arguments:
5102 // adr_type memory slice where writes are generated
5103 // dest oop of the destination array
5104 // basic_elem_type element type of the destination
5105 // slice_idx array index of first element to store
5106 // slice_len number of elements to store (or NULL)
5107 // dest_size total size in bytes of the array object
5108 //
5109 // Exactly one of slice_len or dest_size must be non-NULL.
5110 // If dest_size is non-NULL, zeroing extends to the end of the object.
5111 // If slice_len is non-NULL, the slice_idx value must be a constant.
5112 void
5113 LibraryCallKit::generate_clear_array(const TypePtr* adr_type,
5114 Node* dest,
5115 BasicType basic_elem_type,
5116 Node* slice_idx,
5117 Node* slice_len,
5118 Node* dest_size) {
5119 // one or the other but not both of slice_len and dest_size:
5120 assert((slice_len != NULL? 1: 0) + (dest_size != NULL? 1: 0) == 1, "");
5121 if (slice_len == NULL) slice_len = top();
5122 if (dest_size == NULL) dest_size = top();
5124 // operate on this memory slice:
5125 Node* mem = memory(adr_type); // memory slice to operate on
5127 // scaling and rounding of indexes:
5128 int scale = exact_log2(type2aelembytes(basic_elem_type));
5129 int abase = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5130 int clear_low = (-1 << scale) & (BytesPerInt - 1);
5131 int bump_bit = (-1 << scale) & BytesPerInt;
5133 // determine constant starts and ends
5134 const intptr_t BIG_NEG = -128;
5135 assert(BIG_NEG + 2*abase < 0, "neg enough");
5136 intptr_t slice_idx_con = (intptr_t) find_int_con(slice_idx, BIG_NEG);
5137 intptr_t slice_len_con = (intptr_t) find_int_con(slice_len, BIG_NEG);
5138 if (slice_len_con == 0) {
5139 return; // nothing to do here
5140 }
5141 intptr_t start_con = (abase + (slice_idx_con << scale)) & ~clear_low;
5142 intptr_t end_con = find_intptr_t_con(dest_size, -1);
5143 if (slice_idx_con >= 0 && slice_len_con >= 0) {
5144 assert(end_con < 0, "not two cons");
5145 end_con = round_to(abase + ((slice_idx_con + slice_len_con) << scale),
5146 BytesPerLong);
5147 }
5149 if (start_con >= 0 && end_con >= 0) {
5150 // Constant start and end. Simple.
5151 mem = ClearArrayNode::clear_memory(control(), mem, dest,
5152 start_con, end_con, &_gvn);
5153 } else if (start_con >= 0 && dest_size != top()) {
5154 // Constant start, pre-rounded end after the tail of the array.
5155 Node* end = dest_size;
5156 mem = ClearArrayNode::clear_memory(control(), mem, dest,
5157 start_con, end, &_gvn);
5158 } else if (start_con >= 0 && slice_len != top()) {
5159 // Constant start, non-constant end. End needs rounding up.
5160 // End offset = round_up(abase + ((slice_idx_con + slice_len) << scale), 8)
5161 intptr_t end_base = abase + (slice_idx_con << scale);
5162 int end_round = (-1 << scale) & (BytesPerLong - 1);
5163 Node* end = ConvI2X(slice_len);
5164 if (scale != 0)
5165 end = _gvn.transform( new(C,3) LShiftXNode(end, intcon(scale) ));
5166 end_base += end_round;
5167 end = _gvn.transform( new(C,3) AddXNode(end, MakeConX(end_base)) );
5168 end = _gvn.transform( new(C,3) AndXNode(end, MakeConX(~end_round)) );
5169 mem = ClearArrayNode::clear_memory(control(), mem, dest,
5170 start_con, end, &_gvn);
5171 } else if (start_con < 0 && dest_size != top()) {
5172 // Non-constant start, pre-rounded end after the tail of the array.
5173 // This is almost certainly a "round-to-end" operation.
5174 Node* start = slice_idx;
5175 start = ConvI2X(start);
5176 if (scale != 0)
5177 start = _gvn.transform( new(C,3) LShiftXNode( start, intcon(scale) ));
5178 start = _gvn.transform( new(C,3) AddXNode(start, MakeConX(abase)) );
5179 if ((bump_bit | clear_low) != 0) {
5180 int to_clear = (bump_bit | clear_low);
5181 // Align up mod 8, then store a jint zero unconditionally
5182 // just before the mod-8 boundary.
5183 if (((abase + bump_bit) & ~to_clear) - bump_bit
5184 < arrayOopDesc::length_offset_in_bytes() + BytesPerInt) {
5185 bump_bit = 0;
5186 assert((abase & to_clear) == 0, "array base must be long-aligned");
5187 } else {
5188 // Bump 'start' up to (or past) the next jint boundary:
5189 start = _gvn.transform( new(C,3) AddXNode(start, MakeConX(bump_bit)) );
5190 assert((abase & clear_low) == 0, "array base must be int-aligned");
5191 }
5192 // Round bumped 'start' down to jlong boundary in body of array.
5193 start = _gvn.transform( new(C,3) AndXNode(start, MakeConX(~to_clear)) );
5194 if (bump_bit != 0) {
5195 // Store a zero to the immediately preceding jint:
5196 Node* x1 = _gvn.transform( new(C,3) AddXNode(start, MakeConX(-bump_bit)) );
5197 Node* p1 = basic_plus_adr(dest, x1);
5198 mem = StoreNode::make(_gvn, control(), mem, p1, adr_type, intcon(0), T_INT);
5199 mem = _gvn.transform(mem);
5200 }
5201 }
5202 Node* end = dest_size; // pre-rounded
5203 mem = ClearArrayNode::clear_memory(control(), mem, dest,
5204 start, end, &_gvn);
5205 } else {
5206 // Non-constant start, unrounded non-constant end.
5207 // (Nobody zeroes a random midsection of an array using this routine.)
5208 ShouldNotReachHere(); // fix caller
5209 }
5211 // Done.
5212 set_memory(mem, adr_type);
5213 }
5216 bool
5217 LibraryCallKit::generate_block_arraycopy(const TypePtr* adr_type,
5218 BasicType basic_elem_type,
5219 AllocateNode* alloc,
5220 Node* src, Node* src_offset,
5221 Node* dest, Node* dest_offset,
5222 Node* dest_size, bool dest_uninitialized) {
5223 // See if there is an advantage from block transfer.
5224 int scale = exact_log2(type2aelembytes(basic_elem_type));
5225 if (scale >= LogBytesPerLong)
5226 return false; // it is already a block transfer
5228 // Look at the alignment of the starting offsets.
5229 int abase = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5231 intptr_t src_off_con = (intptr_t) find_int_con(src_offset, -1);
5232 intptr_t dest_off_con = (intptr_t) find_int_con(dest_offset, -1);
5233 if (src_off_con < 0 || dest_off_con < 0)
5234 // At present, we can only understand constants.
5235 return false;
5237 intptr_t src_off = abase + (src_off_con << scale);
5238 intptr_t dest_off = abase + (dest_off_con << scale);
5240 if (((src_off | dest_off) & (BytesPerLong-1)) != 0) {
5241 // Non-aligned; too bad.
5242 // One more chance: Pick off an initial 32-bit word.
5243 // This is a common case, since abase can be odd mod 8.
5244 if (((src_off | dest_off) & (BytesPerLong-1)) == BytesPerInt &&
5245 ((src_off ^ dest_off) & (BytesPerLong-1)) == 0) {
5246 Node* sptr = basic_plus_adr(src, src_off);
5247 Node* dptr = basic_plus_adr(dest, dest_off);
5248 Node* sval = make_load(control(), sptr, TypeInt::INT, T_INT, adr_type);
5249 store_to_memory(control(), dptr, sval, T_INT, adr_type);
5250 src_off += BytesPerInt;
5251 dest_off += BytesPerInt;
5252 } else {
5253 return false;
5254 }
5255 }
5256 assert(src_off % BytesPerLong == 0, "");
5257 assert(dest_off % BytesPerLong == 0, "");
5259 // Do this copy by giant steps.
5260 Node* sptr = basic_plus_adr(src, src_off);
5261 Node* dptr = basic_plus_adr(dest, dest_off);
5262 Node* countx = dest_size;
5263 countx = _gvn.transform( new (C, 3) SubXNode(countx, MakeConX(dest_off)) );
5264 countx = _gvn.transform( new (C, 3) URShiftXNode(countx, intcon(LogBytesPerLong)) );
5266 bool disjoint_bases = true; // since alloc != NULL
5267 generate_unchecked_arraycopy(adr_type, T_LONG, disjoint_bases,
5268 sptr, NULL, dptr, NULL, countx, dest_uninitialized);
5270 return true;
5271 }
5274 // Helper function; generates code for the slow case.
5275 // We make a call to a runtime method which emulates the native method,
5276 // but without the native wrapper overhead.
5277 void
5278 LibraryCallKit::generate_slow_arraycopy(const TypePtr* adr_type,
5279 Node* src, Node* src_offset,
5280 Node* dest, Node* dest_offset,
5281 Node* copy_length, bool dest_uninitialized) {
5282 assert(!dest_uninitialized, "Invariant");
5283 Node* call = make_runtime_call(RC_NO_LEAF | RC_UNCOMMON,
5284 OptoRuntime::slow_arraycopy_Type(),
5285 OptoRuntime::slow_arraycopy_Java(),
5286 "slow_arraycopy", adr_type,
5287 src, src_offset, dest, dest_offset,
5288 copy_length);
5290 // Handle exceptions thrown by this fellow:
5291 make_slow_call_ex(call, env()->Throwable_klass(), false);
5292 }
5294 // Helper function; generates code for cases requiring runtime checks.
5295 Node*
5296 LibraryCallKit::generate_checkcast_arraycopy(const TypePtr* adr_type,
5297 Node* dest_elem_klass,
5298 Node* src, Node* src_offset,
5299 Node* dest, Node* dest_offset,
5300 Node* copy_length, bool dest_uninitialized) {
5301 if (stopped()) return NULL;
5303 address copyfunc_addr = StubRoutines::checkcast_arraycopy(dest_uninitialized);
5304 if (copyfunc_addr == NULL) { // Stub was not generated, go slow path.
5305 return NULL;
5306 }
5308 // Pick out the parameters required to perform a store-check
5309 // for the target array. This is an optimistic check. It will
5310 // look in each non-null element's class, at the desired klass's
5311 // super_check_offset, for the desired klass.
5312 int sco_offset = in_bytes(Klass::super_check_offset_offset());
5313 Node* p3 = basic_plus_adr(dest_elem_klass, sco_offset);
5314 Node* n3 = new(C, 3) LoadINode(NULL, memory(p3), p3, _gvn.type(p3)->is_ptr());
5315 Node* check_offset = ConvI2X(_gvn.transform(n3));
5316 Node* check_value = dest_elem_klass;
5318 Node* src_start = array_element_address(src, src_offset, T_OBJECT);
5319 Node* dest_start = array_element_address(dest, dest_offset, T_OBJECT);
5321 // (We know the arrays are never conjoint, because their types differ.)
5322 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
5323 OptoRuntime::checkcast_arraycopy_Type(),
5324 copyfunc_addr, "checkcast_arraycopy", adr_type,
5325 // five arguments, of which two are
5326 // intptr_t (jlong in LP64)
5327 src_start, dest_start,
5328 copy_length XTOP,
5329 check_offset XTOP,
5330 check_value);
5332 return _gvn.transform(new (C, 1) ProjNode(call, TypeFunc::Parms));
5333 }
5336 // Helper function; generates code for cases requiring runtime checks.
5337 Node*
5338 LibraryCallKit::generate_generic_arraycopy(const TypePtr* adr_type,
5339 Node* src, Node* src_offset,
5340 Node* dest, Node* dest_offset,
5341 Node* copy_length, bool dest_uninitialized) {
5342 assert(!dest_uninitialized, "Invariant");
5343 if (stopped()) return NULL;
5344 address copyfunc_addr = StubRoutines::generic_arraycopy();
5345 if (copyfunc_addr == NULL) { // Stub was not generated, go slow path.
5346 return NULL;
5347 }
5349 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
5350 OptoRuntime::generic_arraycopy_Type(),
5351 copyfunc_addr, "generic_arraycopy", adr_type,
5352 src, src_offset, dest, dest_offset, copy_length);
5354 return _gvn.transform(new (C, 1) ProjNode(call, TypeFunc::Parms));
5355 }
5357 // Helper function; generates the fast out-of-line call to an arraycopy stub.
5358 void
5359 LibraryCallKit::generate_unchecked_arraycopy(const TypePtr* adr_type,
5360 BasicType basic_elem_type,
5361 bool disjoint_bases,
5362 Node* src, Node* src_offset,
5363 Node* dest, Node* dest_offset,
5364 Node* copy_length, bool dest_uninitialized) {
5365 if (stopped()) return; // nothing to do
5367 Node* src_start = src;
5368 Node* dest_start = dest;
5369 if (src_offset != NULL || dest_offset != NULL) {
5370 assert(src_offset != NULL && dest_offset != NULL, "");
5371 src_start = array_element_address(src, src_offset, basic_elem_type);
5372 dest_start = array_element_address(dest, dest_offset, basic_elem_type);
5373 }
5375 // Figure out which arraycopy runtime method to call.
5376 const char* copyfunc_name = "arraycopy";
5377 address copyfunc_addr =
5378 basictype2arraycopy(basic_elem_type, src_offset, dest_offset,
5379 disjoint_bases, copyfunc_name, dest_uninitialized);
5381 // Call it. Note that the count_ix value is not scaled to a byte-size.
5382 make_runtime_call(RC_LEAF|RC_NO_FP,
5383 OptoRuntime::fast_arraycopy_Type(),
5384 copyfunc_addr, copyfunc_name, adr_type,
5385 src_start, dest_start, copy_length XTOP);
5386 }
5388 //----------------------------inline_reference_get----------------------------
5390 bool LibraryCallKit::inline_reference_get() {
5391 const int nargs = 1; // self
5393 guarantee(java_lang_ref_Reference::referent_offset > 0,
5394 "should have already been set");
5396 int referent_offset = java_lang_ref_Reference::referent_offset;
5398 // Restore the stack and pop off the argument
5399 _sp += nargs;
5400 Node *reference_obj = pop();
5402 // Null check on self without removing any arguments.
5403 _sp += nargs;
5404 reference_obj = do_null_check(reference_obj, T_OBJECT);
5405 _sp -= nargs;;
5407 if (stopped()) return true;
5409 Node *adr = basic_plus_adr(reference_obj, reference_obj, referent_offset);
5411 ciInstanceKlass* klass = env()->Object_klass();
5412 const TypeOopPtr* object_type = TypeOopPtr::make_from_klass(klass);
5414 Node* no_ctrl = NULL;
5415 Node *result = make_load(no_ctrl, adr, object_type, T_OBJECT);
5417 // Use the pre-barrier to record the value in the referent field
5418 pre_barrier(false /* do_load */,
5419 control(),
5420 NULL /* obj */, NULL /* adr */, max_juint /* alias_idx */, NULL /* val */, NULL /* val_type */,
5421 result /* pre_val */,
5422 T_OBJECT);
5424 push(result);
5425 return true;
5426 }