annotate src/share/vm/opto/library_call.cpp @ 3352:6759698e3140

7133857: exp() and pow() should use the x87 ISA on x86 Summary: use x87 instructions to implement exp() and pow() in interpreter/c1/c2. Reviewed-by: kvn, never, twisti
author roland
date Tue, 15 May 2012 10:10:23 +0200
parents 8f972594effc
children 8b0a4867acf0
rev   line source
duke@0 1 /*
rbackman@3274 2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #include "precompiled.hpp"
stefank@1879 26 #include "classfile/systemDictionary.hpp"
stefank@1879 27 #include "classfile/vmSymbols.hpp"
twisti@2252 28 #include "compiler/compileBroker.hpp"
stefank@1879 29 #include "compiler/compileLog.hpp"
stefank@1879 30 #include "oops/objArrayKlass.hpp"
stefank@1879 31 #include "opto/addnode.hpp"
stefank@1879 32 #include "opto/callGenerator.hpp"
stefank@1879 33 #include "opto/cfgnode.hpp"
stefank@1879 34 #include "opto/idealKit.hpp"
stefank@1879 35 #include "opto/mulnode.hpp"
stefank@1879 36 #include "opto/parse.hpp"
stefank@1879 37 #include "opto/runtime.hpp"
stefank@1879 38 #include "opto/subnode.hpp"
stefank@1879 39 #include "prims/nativeLookup.hpp"
stefank@1879 40 #include "runtime/sharedRuntime.hpp"
duke@0 41
duke@0 42 class LibraryIntrinsic : public InlineCallGenerator {
duke@0 43 // Extend the set of intrinsics known to the runtime:
duke@0 44 public:
duke@0 45 private:
duke@0 46 bool _is_virtual;
duke@0 47 vmIntrinsics::ID _intrinsic_id;
duke@0 48
duke@0 49 public:
duke@0 50 LibraryIntrinsic(ciMethod* m, bool is_virtual, vmIntrinsics::ID id)
duke@0 51 : InlineCallGenerator(m),
duke@0 52 _is_virtual(is_virtual),
duke@0 53 _intrinsic_id(id)
duke@0 54 {
duke@0 55 }
duke@0 56 virtual bool is_intrinsic() const { return true; }
duke@0 57 virtual bool is_virtual() const { return _is_virtual; }
duke@0 58 virtual JVMState* generate(JVMState* jvms);
duke@0 59 vmIntrinsics::ID intrinsic_id() const { return _intrinsic_id; }
duke@0 60 };
duke@0 61
duke@0 62
duke@0 63 // Local helper class for LibraryIntrinsic:
duke@0 64 class LibraryCallKit : public GraphKit {
duke@0 65 private:
duke@0 66 LibraryIntrinsic* _intrinsic; // the library intrinsic being called
duke@0 67
duke@0 68 public:
duke@0 69 LibraryCallKit(JVMState* caller, LibraryIntrinsic* intrinsic)
duke@0 70 : GraphKit(caller),
duke@0 71 _intrinsic(intrinsic)
duke@0 72 {
duke@0 73 }
duke@0 74
duke@0 75 ciMethod* caller() const { return jvms()->method(); }
duke@0 76 int bci() const { return jvms()->bci(); }
duke@0 77 LibraryIntrinsic* intrinsic() const { return _intrinsic; }
duke@0 78 vmIntrinsics::ID intrinsic_id() const { return _intrinsic->intrinsic_id(); }
duke@0 79 ciMethod* callee() const { return _intrinsic->method(); }
duke@0 80 ciSignature* signature() const { return callee()->signature(); }
duke@0 81 int arg_size() const { return callee()->arg_size(); }
duke@0 82
duke@0 83 bool try_to_inline();
duke@0 84
duke@0 85 // Helper functions to inline natives
duke@0 86 void push_result(RegionNode* region, PhiNode* value);
duke@0 87 Node* generate_guard(Node* test, RegionNode* region, float true_prob);
duke@0 88 Node* generate_slow_guard(Node* test, RegionNode* region);
duke@0 89 Node* generate_fair_guard(Node* test, RegionNode* region);
duke@0 90 Node* generate_negative_guard(Node* index, RegionNode* region,
duke@0 91 // resulting CastII of index:
duke@0 92 Node* *pos_index = NULL);
duke@0 93 Node* generate_nonpositive_guard(Node* index, bool never_negative,
duke@0 94 // resulting CastII of index:
duke@0 95 Node* *pos_index = NULL);
duke@0 96 Node* generate_limit_guard(Node* offset, Node* subseq_length,
duke@0 97 Node* array_length,
duke@0 98 RegionNode* region);
duke@0 99 Node* generate_current_thread(Node* &tls_output);
duke@0 100 address basictype2arraycopy(BasicType t, Node *src_offset, Node *dest_offset,
iveresov@2171 101 bool disjoint_bases, const char* &name, bool dest_uninitialized);
duke@0 102 Node* load_mirror_from_klass(Node* klass);
duke@0 103 Node* load_klass_from_mirror_common(Node* mirror, bool never_see_null,
duke@0 104 int nargs,
duke@0 105 RegionNode* region, int null_path,
duke@0 106 int offset);
duke@0 107 Node* load_klass_from_mirror(Node* mirror, bool never_see_null, int nargs,
duke@0 108 RegionNode* region, int null_path) {
duke@0 109 int offset = java_lang_Class::klass_offset_in_bytes();
duke@0 110 return load_klass_from_mirror_common(mirror, never_see_null, nargs,
duke@0 111 region, null_path,
duke@0 112 offset);
duke@0 113 }
duke@0 114 Node* load_array_klass_from_mirror(Node* mirror, bool never_see_null,
duke@0 115 int nargs,
duke@0 116 RegionNode* region, int null_path) {
duke@0 117 int offset = java_lang_Class::array_klass_offset_in_bytes();
duke@0 118 return load_klass_from_mirror_common(mirror, never_see_null, nargs,
duke@0 119 region, null_path,
duke@0 120 offset);
duke@0 121 }
duke@0 122 Node* generate_access_flags_guard(Node* kls,
duke@0 123 int modifier_mask, int modifier_bits,
duke@0 124 RegionNode* region);
duke@0 125 Node* generate_interface_guard(Node* kls, RegionNode* region);
duke@0 126 Node* generate_array_guard(Node* kls, RegionNode* region) {
duke@0 127 return generate_array_guard_common(kls, region, false, false);
duke@0 128 }
duke@0 129 Node* generate_non_array_guard(Node* kls, RegionNode* region) {
duke@0 130 return generate_array_guard_common(kls, region, false, true);
duke@0 131 }
duke@0 132 Node* generate_objArray_guard(Node* kls, RegionNode* region) {
duke@0 133 return generate_array_guard_common(kls, region, true, false);
duke@0 134 }
duke@0 135 Node* generate_non_objArray_guard(Node* kls, RegionNode* region) {
duke@0 136 return generate_array_guard_common(kls, region, true, true);
duke@0 137 }
duke@0 138 Node* generate_array_guard_common(Node* kls, RegionNode* region,
duke@0 139 bool obj_array, bool not_array);
duke@0 140 Node* generate_virtual_guard(Node* obj_klass, RegionNode* slow_region);
duke@0 141 CallJavaNode* generate_method_call(vmIntrinsics::ID method_id,
duke@0 142 bool is_virtual = false, bool is_static = false);
duke@0 143 CallJavaNode* generate_method_call_static(vmIntrinsics::ID method_id) {
duke@0 144 return generate_method_call(method_id, false, true);
duke@0 145 }
duke@0 146 CallJavaNode* generate_method_call_virtual(vmIntrinsics::ID method_id) {
duke@0 147 return generate_method_call(method_id, true, false);
duke@0 148 }
duke@0 149
kvn@3325 150 Node* make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2);
kvn@3325 151 Node* make_string_method_node(int opcode, Node* str1, Node* str2);
duke@0 152 bool inline_string_compareTo();
duke@0 153 bool inline_string_indexOf();
duke@0 154 Node* string_indexOf(Node* string_object, ciTypeArray* target_array, jint offset, jint cache_i, jint md2_i);
cfang@681 155 bool inline_string_equals();
duke@0 156 Node* pop_math_arg();
duke@0 157 bool runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName);
duke@0 158 bool inline_math_native(vmIntrinsics::ID id);
duke@0 159 bool inline_trig(vmIntrinsics::ID id);
duke@0 160 bool inline_trans(vmIntrinsics::ID id);
duke@0 161 bool inline_abs(vmIntrinsics::ID id);
duke@0 162 bool inline_sqrt(vmIntrinsics::ID id);
duke@0 163 bool inline_pow(vmIntrinsics::ID id);
duke@0 164 bool inline_exp(vmIntrinsics::ID id);
duke@0 165 bool inline_min_max(vmIntrinsics::ID id);
duke@0 166 Node* generate_min_max(vmIntrinsics::ID id, Node* x, Node* y);
duke@0 167 // This returns Type::AnyPtr, RawPtr, or OopPtr.
duke@0 168 int classify_unsafe_addr(Node* &base, Node* &offset);
duke@0 169 Node* make_unsafe_address(Node* base, Node* offset);
johnc@2346 170 // Helper for inline_unsafe_access.
johnc@2346 171 // Generates the guards that check whether the result of
johnc@2346 172 // Unsafe.getObject should be recorded in an SATB log buffer.
johnc@2346 173 void insert_g1_pre_barrier(Node* base_oop, Node* offset, Node* pre_val);
duke@0 174 bool inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile);
duke@0 175 bool inline_unsafe_prefetch(bool is_native_ptr, bool is_store, bool is_static);
duke@0 176 bool inline_unsafe_allocate();
duke@0 177 bool inline_unsafe_copyMemory();
duke@0 178 bool inline_native_currentThread();
rbackman@3274 179 #ifdef TRACE_HAVE_INTRINSICS
rbackman@3274 180 bool inline_native_classID();
rbackman@3274 181 bool inline_native_threadID();
rbackman@3274 182 #endif
rbackman@3274 183 bool inline_native_time_funcs(address method, const char* funcName);
duke@0 184 bool inline_native_isInterrupted();
duke@0 185 bool inline_native_Class_query(vmIntrinsics::ID id);
duke@0 186 bool inline_native_subtype_check();
duke@0 187
duke@0 188 bool inline_native_newArray();
duke@0 189 bool inline_native_getLength();
duke@0 190 bool inline_array_copyOf(bool is_copyOfRange);
rasbold@169 191 bool inline_array_equals();
kvn@833 192 void copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array, bool card_mark);
duke@0 193 bool inline_native_clone(bool is_virtual);
duke@0 194 bool inline_native_Reflection_getCallerClass();
duke@0 195 bool inline_native_AtomicLong_get();
duke@0 196 bool inline_native_AtomicLong_attemptUpdate();
duke@0 197 bool is_method_invoke_or_aux_frame(JVMState* jvms);
duke@0 198 // Helper function for inlining native object hash method
duke@0 199 bool inline_native_hashcode(bool is_virtual, bool is_static);
duke@0 200 bool inline_native_getClass();
duke@0 201
duke@0 202 // Helper functions for inlining arraycopy
duke@0 203 bool inline_arraycopy();
duke@0 204 void generate_arraycopy(const TypePtr* adr_type,
duke@0 205 BasicType basic_elem_type,
duke@0 206 Node* src, Node* src_offset,
duke@0 207 Node* dest, Node* dest_offset,
duke@0 208 Node* copy_length,
duke@0 209 bool disjoint_bases = false,
duke@0 210 bool length_never_negative = false,
duke@0 211 RegionNode* slow_region = NULL);
duke@0 212 AllocateArrayNode* tightly_coupled_allocation(Node* ptr,
duke@0 213 RegionNode* slow_region);
duke@0 214 void generate_clear_array(const TypePtr* adr_type,
duke@0 215 Node* dest,
duke@0 216 BasicType basic_elem_type,
duke@0 217 Node* slice_off,
duke@0 218 Node* slice_len,
duke@0 219 Node* slice_end);
duke@0 220 bool generate_block_arraycopy(const TypePtr* adr_type,
duke@0 221 BasicType basic_elem_type,
duke@0 222 AllocateNode* alloc,
duke@0 223 Node* src, Node* src_offset,
duke@0 224 Node* dest, Node* dest_offset,
iveresov@2171 225 Node* dest_size, bool dest_uninitialized);
duke@0 226 void generate_slow_arraycopy(const TypePtr* adr_type,
duke@0 227 Node* src, Node* src_offset,
duke@0 228 Node* dest, Node* dest_offset,
iveresov@2171 229 Node* copy_length, bool dest_uninitialized);
duke@0 230 Node* generate_checkcast_arraycopy(const TypePtr* adr_type,
duke@0 231 Node* dest_elem_klass,
duke@0 232 Node* src, Node* src_offset,
duke@0 233 Node* dest, Node* dest_offset,
iveresov@2171 234 Node* copy_length, bool dest_uninitialized);
duke@0 235 Node* generate_generic_arraycopy(const TypePtr* adr_type,
duke@0 236 Node* src, Node* src_offset,
duke@0 237 Node* dest, Node* dest_offset,
iveresov@2171 238 Node* copy_length, bool dest_uninitialized);
duke@0 239 void generate_unchecked_arraycopy(const TypePtr* adr_type,
duke@0 240 BasicType basic_elem_type,
duke@0 241 bool disjoint_bases,
duke@0 242 Node* src, Node* src_offset,
duke@0 243 Node* dest, Node* dest_offset,
iveresov@2171 244 Node* copy_length, bool dest_uninitialized);
duke@0 245 bool inline_unsafe_CAS(BasicType type);
duke@0 246 bool inline_unsafe_ordered_store(BasicType type);
duke@0 247 bool inline_fp_conversions(vmIntrinsics::ID id);
twisti@775 248 bool inline_numberOfLeadingZeros(vmIntrinsics::ID id);
twisti@775 249 bool inline_numberOfTrailingZeros(vmIntrinsics::ID id);
twisti@643 250 bool inline_bitCount(vmIntrinsics::ID id);
duke@0 251 bool inline_reverseBytes(vmIntrinsics::ID id);
johnc@2346 252
johnc@2346 253 bool inline_reference_get();
duke@0 254 };
duke@0 255
duke@0 256
duke@0 257 //---------------------------make_vm_intrinsic----------------------------
duke@0 258 CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) {
duke@0 259 vmIntrinsics::ID id = m->intrinsic_id();
duke@0 260 assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
duke@0 261
duke@0 262 if (DisableIntrinsic[0] != '\0'
duke@0 263 && strstr(DisableIntrinsic, vmIntrinsics::name_at(id)) != NULL) {
duke@0 264 // disabled by a user request on the command line:
duke@0 265 // example: -XX:DisableIntrinsic=_hashCode,_getClass
duke@0 266 return NULL;
duke@0 267 }
duke@0 268
duke@0 269 if (!m->is_loaded()) {
duke@0 270 // do not attempt to inline unloaded methods
duke@0 271 return NULL;
duke@0 272 }
duke@0 273
duke@0 274 // Only a few intrinsics implement a virtual dispatch.
duke@0 275 // They are expensive calls which are also frequently overridden.
duke@0 276 if (is_virtual) {
duke@0 277 switch (id) {
duke@0 278 case vmIntrinsics::_hashCode:
duke@0 279 case vmIntrinsics::_clone:
duke@0 280 // OK, Object.hashCode and Object.clone intrinsics come in both flavors
duke@0 281 break;
duke@0 282 default:
duke@0 283 return NULL;
duke@0 284 }
duke@0 285 }
duke@0 286
duke@0 287 // -XX:-InlineNatives disables nearly all intrinsics:
duke@0 288 if (!InlineNatives) {
duke@0 289 switch (id) {
duke@0 290 case vmIntrinsics::_indexOf:
duke@0 291 case vmIntrinsics::_compareTo:
cfang@681 292 case vmIntrinsics::_equals:
rasbold@169 293 case vmIntrinsics::_equalsC:
duke@0 294 break; // InlineNatives does not control String.compareTo
duke@0 295 default:
duke@0 296 return NULL;
duke@0 297 }
duke@0 298 }
duke@0 299
duke@0 300 switch (id) {
duke@0 301 case vmIntrinsics::_compareTo:
duke@0 302 if (!SpecialStringCompareTo) return NULL;
duke@0 303 break;
duke@0 304 case vmIntrinsics::_indexOf:
duke@0 305 if (!SpecialStringIndexOf) return NULL;
duke@0 306 break;
cfang@681 307 case vmIntrinsics::_equals:
cfang@681 308 if (!SpecialStringEquals) return NULL;
cfang@681 309 break;
rasbold@169 310 case vmIntrinsics::_equalsC:
rasbold@169 311 if (!SpecialArraysEquals) return NULL;
rasbold@169 312 break;
duke@0 313 case vmIntrinsics::_arraycopy:
duke@0 314 if (!InlineArrayCopy) return NULL;
duke@0 315 break;
duke@0 316 case vmIntrinsics::_copyMemory:
duke@0 317 if (StubRoutines::unsafe_arraycopy() == NULL) return NULL;
duke@0 318 if (!InlineArrayCopy) return NULL;
duke@0 319 break;
duke@0 320 case vmIntrinsics::_hashCode:
duke@0 321 if (!InlineObjectHash) return NULL;
duke@0 322 break;
duke@0 323 case vmIntrinsics::_clone:
duke@0 324 case vmIntrinsics::_copyOf:
duke@0 325 case vmIntrinsics::_copyOfRange:
duke@0 326 if (!InlineObjectCopy) return NULL;
duke@0 327 // These also use the arraycopy intrinsic mechanism:
duke@0 328 if (!InlineArrayCopy) return NULL;
duke@0 329 break;
duke@0 330 case vmIntrinsics::_checkIndex:
duke@0 331 // We do not intrinsify this. The optimizer does fine with it.
duke@0 332 return NULL;
duke@0 333
duke@0 334 case vmIntrinsics::_get_AtomicLong:
duke@0 335 case vmIntrinsics::_attemptUpdate:
duke@0 336 if (!InlineAtomicLong) return NULL;
duke@0 337 break;
duke@0 338
duke@0 339 case vmIntrinsics::_getCallerClass:
duke@0 340 if (!UseNewReflection) return NULL;
duke@0 341 if (!InlineReflectionGetCallerClass) return NULL;
duke@0 342 if (!JDK_Version::is_gte_jdk14x_version()) return NULL;
duke@0 343 break;
duke@0 344
twisti@643 345 case vmIntrinsics::_bitCount_i:
never@3202 346 if (!Matcher::match_rule_supported(Op_PopCountI)) return NULL;
never@3196 347 break;
never@3196 348
twisti@643 349 case vmIntrinsics::_bitCount_l:
never@3202 350 if (!Matcher::match_rule_supported(Op_PopCountL)) return NULL;
never@3196 351 break;
never@3196 352
never@3196 353 case vmIntrinsics::_numberOfLeadingZeros_i:
never@3196 354 if (!Matcher::match_rule_supported(Op_CountLeadingZerosI)) return NULL;
never@3196 355 break;
never@3196 356
never@3196 357 case vmIntrinsics::_numberOfLeadingZeros_l:
never@3196 358 if (!Matcher::match_rule_supported(Op_CountLeadingZerosL)) return NULL;
never@3196 359 break;
never@3196 360
never@3196 361 case vmIntrinsics::_numberOfTrailingZeros_i:
never@3196 362 if (!Matcher::match_rule_supported(Op_CountTrailingZerosI)) return NULL;
never@3196 363 break;
never@3196 364
never@3196 365 case vmIntrinsics::_numberOfTrailingZeros_l:
never@3196 366 if (!Matcher::match_rule_supported(Op_CountTrailingZerosL)) return NULL;
twisti@643 367 break;
twisti@643 368
johnc@2346 369 case vmIntrinsics::_Reference_get:
johnc@2346 370 // It is only when G1 is enabled that we absolutely
johnc@2346 371 // need to use the intrinsic version of Reference.get()
johnc@2346 372 // so that the value in the referent field, if necessary,
johnc@2346 373 // can be registered by the pre-barrier code.
johnc@2346 374 if (!UseG1GC) return NULL;
johnc@2346 375 break;
johnc@2346 376
duke@0 377 default:
jrose@856 378 assert(id <= vmIntrinsics::LAST_COMPILER_INLINE, "caller responsibility");
jrose@856 379 assert(id != vmIntrinsics::_Object_init && id != vmIntrinsics::_invoke, "enum out of order?");
duke@0 380 break;
duke@0 381 }
duke@0 382
duke@0 383 // -XX:-InlineClassNatives disables natives from the Class class.
duke@0 384 // The flag applies to all reflective calls, notably Array.newArray
duke@0 385 // (visible to Java programmers as Array.newInstance).
duke@0 386 if (m->holder()->name() == ciSymbol::java_lang_Class() ||
duke@0 387 m->holder()->name() == ciSymbol::java_lang_reflect_Array()) {
duke@0 388 if (!InlineClassNatives) return NULL;
duke@0 389 }
duke@0 390
duke@0 391 // -XX:-InlineThreadNatives disables natives from the Thread class.
duke@0 392 if (m->holder()->name() == ciSymbol::java_lang_Thread()) {
duke@0 393 if (!InlineThreadNatives) return NULL;
duke@0 394 }
duke@0 395
duke@0 396 // -XX:-InlineMathNatives disables natives from the Math,Float and Double classes.
duke@0 397 if (m->holder()->name() == ciSymbol::java_lang_Math() ||
duke@0 398 m->holder()->name() == ciSymbol::java_lang_Float() ||
duke@0 399 m->holder()->name() == ciSymbol::java_lang_Double()) {
duke@0 400 if (!InlineMathNatives) return NULL;
duke@0 401 }
duke@0 402
duke@0 403 // -XX:-InlineUnsafeOps disables natives from the Unsafe class.
duke@0 404 if (m->holder()->name() == ciSymbol::sun_misc_Unsafe()) {
duke@0 405 if (!InlineUnsafeOps) return NULL;
duke@0 406 }
duke@0 407
duke@0 408 return new LibraryIntrinsic(m, is_virtual, (vmIntrinsics::ID) id);
duke@0 409 }
duke@0 410
duke@0 411 //----------------------register_library_intrinsics-----------------------
duke@0 412 // Initialize this file's data structures, for each Compile instance.
duke@0 413 void Compile::register_library_intrinsics() {
duke@0 414 // Nothing to do here.
duke@0 415 }
duke@0 416
duke@0 417 JVMState* LibraryIntrinsic::generate(JVMState* jvms) {
duke@0 418 LibraryCallKit kit(jvms, this);
duke@0 419 Compile* C = kit.C;
duke@0 420 int nodes = C->unique();
duke@0 421 #ifndef PRODUCT
duke@0 422 if ((PrintIntrinsics || PrintInlining NOT_PRODUCT( || PrintOptoInlining) ) && Verbose) {
duke@0 423 char buf[1000];
duke@0 424 const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf));
duke@0 425 tty->print_cr("Intrinsic %s", str);
duke@0 426 }
duke@0 427 #endif
johnc@2346 428
duke@0 429 if (kit.try_to_inline()) {
duke@0 430 if (PrintIntrinsics || PrintInlining NOT_PRODUCT( || PrintOptoInlining) ) {
twisti@2252 431 CompileTask::print_inlining(kit.callee(), jvms->depth() - 1, kit.bci(), is_virtual() ? "(intrinsic, virtual)" : "(intrinsic)");
duke@0 432 }
duke@0 433 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked);
duke@0 434 if (C->log()) {
duke@0 435 C->log()->elem("intrinsic id='%s'%s nodes='%d'",
duke@0 436 vmIntrinsics::name_at(intrinsic_id()),
duke@0 437 (is_virtual() ? " virtual='1'" : ""),
duke@0 438 C->unique() - nodes);
duke@0 439 }
duke@0 440 return kit.transfer_exceptions_into_jvms();
duke@0 441 }
duke@0 442
never@3196 443 // The intrinsic bailed out
never@3196 444 if (PrintIntrinsics || PrintInlining NOT_PRODUCT( || PrintOptoInlining) ) {
johnc@2346 445 if (jvms->has_method()) {
johnc@2346 446 // Not a root compile.
never@3196 447 const char* msg = is_virtual() ? "failed to inline (intrinsic, virtual)" : "failed to inline (intrinsic)";
never@3196 448 CompileTask::print_inlining(kit.callee(), jvms->depth() - 1, kit.bci(), msg);
johnc@2346 449 } else {
johnc@2346 450 // Root compile
johnc@2346 451 tty->print("Did not generate intrinsic %s%s at bci:%d in",
jrose@856 452 vmIntrinsics::name_at(intrinsic_id()),
jrose@856 453 (is_virtual() ? " (virtual)" : ""), kit.bci());
johnc@2346 454 }
duke@0 455 }
duke@0 456 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed);
duke@0 457 return NULL;
duke@0 458 }
duke@0 459
duke@0 460 bool LibraryCallKit::try_to_inline() {
duke@0 461 // Handle symbolic names for otherwise undistinguished boolean switches:
duke@0 462 const bool is_store = true;
duke@0 463 const bool is_native_ptr = true;
duke@0 464 const bool is_static = true;
duke@0 465
johnc@2346 466 if (!jvms()->has_method()) {
johnc@2346 467 // Root JVMState has a null method.
johnc@2346 468 assert(map()->memory()->Opcode() == Op_Parm, "");
johnc@2346 469 // Insert the memory aliasing node
johnc@2346 470 set_all_memory(reset_memory());
johnc@2346 471 }
johnc@2346 472 assert(merged_memory(), "");
johnc@2346 473
duke@0 474 switch (intrinsic_id()) {
duke@0 475 case vmIntrinsics::_hashCode:
duke@0 476 return inline_native_hashcode(intrinsic()->is_virtual(), !is_static);
duke@0 477 case vmIntrinsics::_identityHashCode:
duke@0 478 return inline_native_hashcode(/*!virtual*/ false, is_static);
duke@0 479 case vmIntrinsics::_getClass:
duke@0 480 return inline_native_getClass();
duke@0 481
duke@0 482 case vmIntrinsics::_dsin:
duke@0 483 case vmIntrinsics::_dcos:
duke@0 484 case vmIntrinsics::_dtan:
duke@0 485 case vmIntrinsics::_dabs:
duke@0 486 case vmIntrinsics::_datan2:
duke@0 487 case vmIntrinsics::_dsqrt:
duke@0 488 case vmIntrinsics::_dexp:
duke@0 489 case vmIntrinsics::_dlog:
duke@0 490 case vmIntrinsics::_dlog10:
duke@0 491 case vmIntrinsics::_dpow:
duke@0 492 return inline_math_native(intrinsic_id());
duke@0 493
duke@0 494 case vmIntrinsics::_min:
duke@0 495 case vmIntrinsics::_max:
duke@0 496 return inline_min_max(intrinsic_id());
duke@0 497
duke@0 498 case vmIntrinsics::_arraycopy:
duke@0 499 return inline_arraycopy();
duke@0 500
duke@0 501 case vmIntrinsics::_compareTo:
duke@0 502 return inline_string_compareTo();
duke@0 503 case vmIntrinsics::_indexOf:
duke@0 504 return inline_string_indexOf();
cfang@681 505 case vmIntrinsics::_equals:
cfang@681 506 return inline_string_equals();
duke@0 507
duke@0 508 case vmIntrinsics::_getObject:
duke@0 509 return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT, false);
duke@0 510 case vmIntrinsics::_getBoolean:
duke@0 511 return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN, false);
duke@0 512 case vmIntrinsics::_getByte:
duke@0 513 return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE, false);
duke@0 514 case vmIntrinsics::_getShort:
duke@0 515 return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT, false);
duke@0 516 case vmIntrinsics::_getChar:
duke@0 517 return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR, false);
duke@0 518 case vmIntrinsics::_getInt:
duke@0 519 return inline_unsafe_access(!is_native_ptr, !is_store, T_INT, false);
duke@0 520 case vmIntrinsics::_getLong:
duke@0 521 return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG, false);
duke@0 522 case vmIntrinsics::_getFloat:
duke@0 523 return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT, false);
duke@0 524 case vmIntrinsics::_getDouble:
duke@0 525 return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE, false);
duke@0 526
duke@0 527 case vmIntrinsics::_putObject:
duke@0 528 return inline_unsafe_access(!is_native_ptr, is_store, T_OBJECT, false);
duke@0 529 case vmIntrinsics::_putBoolean:
duke@0 530 return inline_unsafe_access(!is_native_ptr, is_store, T_BOOLEAN, false);
duke@0 531 case vmIntrinsics::_putByte:
duke@0 532 return inline_unsafe_access(!is_native_ptr, is_store, T_BYTE, false);
duke@0 533 case vmIntrinsics::_putShort:
duke@0 534 return inline_unsafe_access(!is_native_ptr, is_store, T_SHORT, false);
duke@0 535 case vmIntrinsics::_putChar:
duke@0 536 return inline_unsafe_access(!is_native_ptr, is_store, T_CHAR, false);
duke@0 537 case vmIntrinsics::_putInt:
duke@0 538 return inline_unsafe_access(!is_native_ptr, is_store, T_INT, false);
duke@0 539 case vmIntrinsics::_putLong:
duke@0 540 return inline_unsafe_access(!is_native_ptr, is_store, T_LONG, false);
duke@0 541 case vmIntrinsics::_putFloat:
duke@0 542 return inline_unsafe_access(!is_native_ptr, is_store, T_FLOAT, false);
duke@0 543 case vmIntrinsics::_putDouble:
duke@0 544 return inline_unsafe_access(!is_native_ptr, is_store, T_DOUBLE, false);
duke@0 545
duke@0 546 case vmIntrinsics::_getByte_raw:
duke@0 547 return inline_unsafe_access(is_native_ptr, !is_store, T_BYTE, false);
duke@0 548 case vmIntrinsics::_getShort_raw:
duke@0 549 return inline_unsafe_access(is_native_ptr, !is_store, T_SHORT, false);
duke@0 550 case vmIntrinsics::_getChar_raw:
duke@0 551 return inline_unsafe_access(is_native_ptr, !is_store, T_CHAR, false);
duke@0 552 case vmIntrinsics::_getInt_raw:
duke@0 553 return inline_unsafe_access(is_native_ptr, !is_store, T_INT, false);
duke@0 554 case vmIntrinsics::_getLong_raw:
duke@0 555 return inline_unsafe_access(is_native_ptr, !is_store, T_LONG, false);
duke@0 556 case vmIntrinsics::_getFloat_raw:
duke@0 557 return inline_unsafe_access(is_native_ptr, !is_store, T_FLOAT, false);
duke@0 558 case vmIntrinsics::_getDouble_raw:
duke@0 559 return inline_unsafe_access(is_native_ptr, !is_store, T_DOUBLE, false);
duke@0 560 case vmIntrinsics::_getAddress_raw:
duke@0 561 return inline_unsafe_access(is_native_ptr, !is_store, T_ADDRESS, false);
duke@0 562
duke@0 563 case vmIntrinsics::_putByte_raw:
duke@0 564 return inline_unsafe_access(is_native_ptr, is_store, T_BYTE, false);
duke@0 565 case vmIntrinsics::_putShort_raw:
duke@0 566 return inline_unsafe_access(is_native_ptr, is_store, T_SHORT, false);
duke@0 567 case vmIntrinsics::_putChar_raw:
duke@0 568 return inline_unsafe_access(is_native_ptr, is_store, T_CHAR, false);
duke@0 569 case vmIntrinsics::_putInt_raw:
duke@0 570 return inline_unsafe_access(is_native_ptr, is_store, T_INT, false);
duke@0 571 case vmIntrinsics::_putLong_raw:
duke@0 572 return inline_unsafe_access(is_native_ptr, is_store, T_LONG, false);
duke@0 573 case vmIntrinsics::_putFloat_raw:
duke@0 574 return inline_unsafe_access(is_native_ptr, is_store, T_FLOAT, false);
duke@0 575 case vmIntrinsics::_putDouble_raw:
duke@0 576 return inline_unsafe_access(is_native_ptr, is_store, T_DOUBLE, false);
duke@0 577 case vmIntrinsics::_putAddress_raw:
duke@0 578 return inline_unsafe_access(is_native_ptr, is_store, T_ADDRESS, false);
duke@0 579
duke@0 580 case vmIntrinsics::_getObjectVolatile:
duke@0 581 return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT, true);
duke@0 582 case vmIntrinsics::_getBooleanVolatile:
duke@0 583 return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN, true);
duke@0 584 case vmIntrinsics::_getByteVolatile:
duke@0 585 return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE, true);
duke@0 586 case vmIntrinsics::_getShortVolatile:
duke@0 587 return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT, true);
duke@0 588 case vmIntrinsics::_getCharVolatile:
duke@0 589 return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR, true);
duke@0 590 case vmIntrinsics::_getIntVolatile:
duke@0 591 return inline_unsafe_access(!is_native_ptr, !is_store, T_INT, true);
duke@0 592 case vmIntrinsics::_getLongVolatile:
duke@0 593 return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG, true);
duke@0 594 case vmIntrinsics::_getFloatVolatile:
duke@0 595 return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT, true);
duke@0 596 case vmIntrinsics::_getDoubleVolatile:
duke@0 597 return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE, true);
duke@0 598
duke@0 599 case vmIntrinsics::_putObjectVolatile:
duke@0 600 return inline_unsafe_access(!is_native_ptr, is_store, T_OBJECT, true);
duke@0 601 case vmIntrinsics::_putBooleanVolatile:
duke@0 602 return inline_unsafe_access(!is_native_ptr, is_store, T_BOOLEAN, true);
duke@0 603 case vmIntrinsics::_putByteVolatile:
duke@0 604 return inline_unsafe_access(!is_native_ptr, is_store, T_BYTE, true);
duke@0 605 case vmIntrinsics::_putShortVolatile:
duke@0 606 return inline_unsafe_access(!is_native_ptr, is_store, T_SHORT, true);
duke@0 607 case vmIntrinsics::_putCharVolatile:
duke@0 608 return inline_unsafe_access(!is_native_ptr, is_store, T_CHAR, true);
duke@0 609 case vmIntrinsics::_putIntVolatile:
duke@0 610 return inline_unsafe_access(!is_native_ptr, is_store, T_INT, true);
duke@0 611 case vmIntrinsics::_putLongVolatile:
duke@0 612 return inline_unsafe_access(!is_native_ptr, is_store, T_LONG, true);
duke@0 613 case vmIntrinsics::_putFloatVolatile:
duke@0 614 return inline_unsafe_access(!is_native_ptr, is_store, T_FLOAT, true);
duke@0 615 case vmIntrinsics::_putDoubleVolatile:
duke@0 616 return inline_unsafe_access(!is_native_ptr, is_store, T_DOUBLE, true);
duke@0 617
duke@0 618 case vmIntrinsics::_prefetchRead:
duke@0 619 return inline_unsafe_prefetch(!is_native_ptr, !is_store, !is_static);
duke@0 620 case vmIntrinsics::_prefetchWrite:
duke@0 621 return inline_unsafe_prefetch(!is_native_ptr, is_store, !is_static);
duke@0 622 case vmIntrinsics::_prefetchReadStatic:
duke@0 623 return inline_unsafe_prefetch(!is_native_ptr, !is_store, is_static);
duke@0 624 case vmIntrinsics::_prefetchWriteStatic:
duke@0 625 return inline_unsafe_prefetch(!is_native_ptr, is_store, is_static);
duke@0 626
duke@0 627 case vmIntrinsics::_compareAndSwapObject:
duke@0 628 return inline_unsafe_CAS(T_OBJECT);
duke@0 629 case vmIntrinsics::_compareAndSwapInt:
duke@0 630 return inline_unsafe_CAS(T_INT);
duke@0 631 case vmIntrinsics::_compareAndSwapLong:
duke@0 632 return inline_unsafe_CAS(T_LONG);
duke@0 633
duke@0 634 case vmIntrinsics::_putOrderedObject:
duke@0 635 return inline_unsafe_ordered_store(T_OBJECT);
duke@0 636 case vmIntrinsics::_putOrderedInt:
duke@0 637 return inline_unsafe_ordered_store(T_INT);
duke@0 638 case vmIntrinsics::_putOrderedLong:
duke@0 639 return inline_unsafe_ordered_store(T_LONG);
duke@0 640
duke@0 641 case vmIntrinsics::_currentThread:
duke@0 642 return inline_native_currentThread();
duke@0 643 case vmIntrinsics::_isInterrupted:
duke@0 644 return inline_native_isInterrupted();
duke@0 645
rbackman@3274 646 #ifdef TRACE_HAVE_INTRINSICS
rbackman@3274 647 case vmIntrinsics::_classID:
rbackman@3274 648 return inline_native_classID();
rbackman@3274 649 case vmIntrinsics::_threadID:
rbackman@3274 650 return inline_native_threadID();
rbackman@3274 651 case vmIntrinsics::_counterTime:
rbackman@3274 652 return inline_native_time_funcs(CAST_FROM_FN_PTR(address, TRACE_TIME_METHOD), "counterTime");
rbackman@3274 653 #endif
duke@0 654 case vmIntrinsics::_currentTimeMillis:
rbackman@3274 655 return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeMillis), "currentTimeMillis");
duke@0 656 case vmIntrinsics::_nanoTime:
rbackman@3274 657 return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeNanos), "nanoTime");
duke@0 658 case vmIntrinsics::_allocateInstance:
duke@0 659 return inline_unsafe_allocate();
duke@0 660 case vmIntrinsics::_copyMemory:
duke@0 661 return inline_unsafe_copyMemory();
duke@0 662 case vmIntrinsics::_newArray:
duke@0 663 return inline_native_newArray();
duke@0 664 case vmIntrinsics::_getLength:
duke@0 665 return inline_native_getLength();
duke@0 666 case vmIntrinsics::_copyOf:
duke@0 667 return inline_array_copyOf(false);
duke@0 668 case vmIntrinsics::_copyOfRange:
duke@0 669 return inline_array_copyOf(true);
rasbold@169 670 case vmIntrinsics::_equalsC:
rasbold@169 671 return inline_array_equals();
duke@0 672 case vmIntrinsics::_clone:
duke@0 673 return inline_native_clone(intrinsic()->is_virtual());
duke@0 674
duke@0 675 case vmIntrinsics::_isAssignableFrom:
duke@0 676 return inline_native_subtype_check();
duke@0 677
duke@0 678 case vmIntrinsics::_isInstance:
duke@0 679 case vmIntrinsics::_getModifiers:
duke@0 680 case vmIntrinsics::_isInterface:
duke@0 681 case vmIntrinsics::_isArray:
duke@0 682 case vmIntrinsics::_isPrimitive:
duke@0 683 case vmIntrinsics::_getSuperclass:
duke@0 684 case vmIntrinsics::_getComponentType:
duke@0 685 case vmIntrinsics::_getClassAccessFlags:
duke@0 686 return inline_native_Class_query(intrinsic_id());
duke@0 687
duke@0 688 case vmIntrinsics::_floatToRawIntBits:
duke@0 689 case vmIntrinsics::_floatToIntBits:
duke@0 690 case vmIntrinsics::_intBitsToFloat:
duke@0 691 case vmIntrinsics::_doubleToRawLongBits:
duke@0 692 case vmIntrinsics::_doubleToLongBits:
duke@0 693 case vmIntrinsics::_longBitsToDouble:
duke@0 694 return inline_fp_conversions(intrinsic_id());
duke@0 695
twisti@775 696 case vmIntrinsics::_numberOfLeadingZeros_i:
twisti@775 697 case vmIntrinsics::_numberOfLeadingZeros_l:
twisti@775 698 return inline_numberOfLeadingZeros(intrinsic_id());
twisti@775 699
twisti@775 700 case vmIntrinsics::_numberOfTrailingZeros_i:
twisti@775 701 case vmIntrinsics::_numberOfTrailingZeros_l:
twisti@775 702 return inline_numberOfTrailingZeros(intrinsic_id());
twisti@775 703
twisti@643 704 case vmIntrinsics::_bitCount_i:
twisti@643 705 case vmIntrinsics::_bitCount_l:
twisti@643 706 return inline_bitCount(intrinsic_id());
twisti@643 707
duke@0 708 case vmIntrinsics::_reverseBytes_i:
duke@0 709 case vmIntrinsics::_reverseBytes_l:
never@1396 710 case vmIntrinsics::_reverseBytes_s:
never@1396 711 case vmIntrinsics::_reverseBytes_c:
duke@0 712 return inline_reverseBytes((vmIntrinsics::ID) intrinsic_id());
duke@0 713
duke@0 714 case vmIntrinsics::_get_AtomicLong:
duke@0 715 return inline_native_AtomicLong_get();
duke@0 716 case vmIntrinsics::_attemptUpdate:
duke@0 717 return inline_native_AtomicLong_attemptUpdate();
duke@0 718
duke@0 719 case vmIntrinsics::_getCallerClass:
duke@0 720 return inline_native_Reflection_getCallerClass();
duke@0 721
johnc@2346 722 case vmIntrinsics::_Reference_get:
johnc@2346 723 return inline_reference_get();
johnc@2346 724
duke@0 725 default:
duke@0 726 // If you get here, it may be that someone has added a new intrinsic
duke@0 727 // to the list in vmSymbols.hpp without implementing it here.
duke@0 728 #ifndef PRODUCT
duke@0 729 if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) {
duke@0 730 tty->print_cr("*** Warning: Unimplemented intrinsic %s(%d)",
duke@0 731 vmIntrinsics::name_at(intrinsic_id()), intrinsic_id());
duke@0 732 }
duke@0 733 #endif
duke@0 734 return false;
duke@0 735 }
duke@0 736 }
duke@0 737
duke@0 738 //------------------------------push_result------------------------------
duke@0 739 // Helper function for finishing intrinsics.
duke@0 740 void LibraryCallKit::push_result(RegionNode* region, PhiNode* value) {
duke@0 741 record_for_igvn(region);
duke@0 742 set_control(_gvn.transform(region));
duke@0 743 BasicType value_type = value->type()->basic_type();
duke@0 744 push_node(value_type, _gvn.transform(value));
duke@0 745 }
duke@0 746
duke@0 747 //------------------------------generate_guard---------------------------
duke@0 748 // Helper function for generating guarded fast-slow graph structures.
duke@0 749 // The given 'test', if true, guards a slow path. If the test fails
duke@0 750 // then a fast path can be taken. (We generally hope it fails.)
duke@0 751 // In all cases, GraphKit::control() is updated to the fast path.
duke@0 752 // The returned value represents the control for the slow path.
duke@0 753 // The return value is never 'top'; it is either a valid control
duke@0 754 // or NULL if it is obvious that the slow path can never be taken.
duke@0 755 // Also, if region and the slow control are not NULL, the slow edge
duke@0 756 // is appended to the region.
duke@0 757 Node* LibraryCallKit::generate_guard(Node* test, RegionNode* region, float true_prob) {
duke@0 758 if (stopped()) {
duke@0 759 // Already short circuited.
duke@0 760 return NULL;
duke@0 761 }
duke@0 762
duke@0 763 // Build an if node and its projections.
duke@0 764 // If test is true we take the slow path, which we assume is uncommon.
duke@0 765 if (_gvn.type(test) == TypeInt::ZERO) {
duke@0 766 // The slow branch is never taken. No need to build this guard.
duke@0 767 return NULL;
duke@0 768 }
duke@0 769
duke@0 770 IfNode* iff = create_and_map_if(control(), test, true_prob, COUNT_UNKNOWN);
duke@0 771
duke@0 772 Node* if_slow = _gvn.transform( new (C, 1) IfTrueNode(iff) );
duke@0 773 if (if_slow == top()) {
duke@0 774 // The slow branch is never taken. No need to build this guard.
duke@0 775 return NULL;
duke@0 776 }
duke@0 777
duke@0 778 if (region != NULL)
duke@0 779 region->add_req(if_slow);
duke@0 780
duke@0 781 Node* if_fast = _gvn.transform( new (C, 1) IfFalseNode(iff) );
duke@0 782 set_control(if_fast);
duke@0 783
duke@0 784 return if_slow;
duke@0 785 }
duke@0 786
duke@0 787 inline Node* LibraryCallKit::generate_slow_guard(Node* test, RegionNode* region) {
duke@0 788 return generate_guard(test, region, PROB_UNLIKELY_MAG(3));
duke@0 789 }
duke@0 790 inline Node* LibraryCallKit::generate_fair_guard(Node* test, RegionNode* region) {
duke@0 791 return generate_guard(test, region, PROB_FAIR);
duke@0 792 }
duke@0 793
duke@0 794 inline Node* LibraryCallKit::generate_negative_guard(Node* index, RegionNode* region,
duke@0 795 Node* *pos_index) {
duke@0 796 if (stopped())
duke@0 797 return NULL; // already stopped
duke@0 798 if (_gvn.type(index)->higher_equal(TypeInt::POS)) // [0,maxint]
duke@0 799 return NULL; // index is already adequately typed
duke@0 800 Node* cmp_lt = _gvn.transform( new (C, 3) CmpINode(index, intcon(0)) );
duke@0 801 Node* bol_lt = _gvn.transform( new (C, 2) BoolNode(cmp_lt, BoolTest::lt) );
duke@0 802 Node* is_neg = generate_guard(bol_lt, region, PROB_MIN);
duke@0 803 if (is_neg != NULL && pos_index != NULL) {
duke@0 804 // Emulate effect of Parse::adjust_map_after_if.
duke@0 805 Node* ccast = new (C, 2) CastIINode(index, TypeInt::POS);
duke@0 806 ccast->set_req(0, control());
duke@0 807 (*pos_index) = _gvn.transform(ccast);
duke@0 808 }
duke@0 809 return is_neg;
duke@0 810 }
duke@0 811
duke@0 812 inline Node* LibraryCallKit::generate_nonpositive_guard(Node* index, bool never_negative,
duke@0 813 Node* *pos_index) {
duke@0 814 if (stopped())
duke@0 815 return NULL; // already stopped
duke@0 816 if (_gvn.type(index)->higher_equal(TypeInt::POS1)) // [1,maxint]
duke@0 817 return NULL; // index is already adequately typed
duke@0 818 Node* cmp_le = _gvn.transform( new (C, 3) CmpINode(index, intcon(0)) );
duke@0 819 BoolTest::mask le_or_eq = (never_negative ? BoolTest::eq : BoolTest::le);
duke@0 820 Node* bol_le = _gvn.transform( new (C, 2) BoolNode(cmp_le, le_or_eq) );
duke@0 821 Node* is_notp = generate_guard(bol_le, NULL, PROB_MIN);
duke@0 822 if (is_notp != NULL && pos_index != NULL) {
duke@0 823 // Emulate effect of Parse::adjust_map_after_if.
duke@0 824 Node* ccast = new (C, 2) CastIINode(index, TypeInt::POS1);
duke@0 825 ccast->set_req(0, control());
duke@0 826 (*pos_index) = _gvn.transform(ccast);
duke@0 827 }
duke@0 828 return is_notp;
duke@0 829 }
duke@0 830
duke@0 831 // Make sure that 'position' is a valid limit index, in [0..length].
duke@0 832 // There are two equivalent plans for checking this:
duke@0 833 // A. (offset + copyLength) unsigned<= arrayLength
duke@0 834 // B. offset <= (arrayLength - copyLength)
duke@0 835 // We require that all of the values above, except for the sum and
duke@0 836 // difference, are already known to be non-negative.
duke@0 837 // Plan A is robust in the face of overflow, if offset and copyLength
duke@0 838 // are both hugely positive.
duke@0 839 //
duke@0 840 // Plan B is less direct and intuitive, but it does not overflow at
duke@0 841 // all, since the difference of two non-negatives is always
duke@0 842 // representable. Whenever Java methods must perform the equivalent
duke@0 843 // check they generally use Plan B instead of Plan A.
duke@0 844 // For the moment we use Plan A.
duke@0 845 inline Node* LibraryCallKit::generate_limit_guard(Node* offset,
duke@0 846 Node* subseq_length,
duke@0 847 Node* array_length,
duke@0 848 RegionNode* region) {
duke@0 849 if (stopped())
duke@0 850 return NULL; // already stopped
duke@0 851 bool zero_offset = _gvn.type(offset) == TypeInt::ZERO;
kvn@2972 852 if (zero_offset && subseq_length->eqv_uncast(array_length))
duke@0 853 return NULL; // common case of whole-array copy
duke@0 854 Node* last = subseq_length;
duke@0 855 if (!zero_offset) // last += offset
duke@0 856 last = _gvn.transform( new (C, 3) AddINode(last, offset));
duke@0 857 Node* cmp_lt = _gvn.transform( new (C, 3) CmpUNode(array_length, last) );
duke@0 858 Node* bol_lt = _gvn.transform( new (C, 2) BoolNode(cmp_lt, BoolTest::lt) );
duke@0 859 Node* is_over = generate_guard(bol_lt, region, PROB_MIN);
duke@0 860 return is_over;
duke@0 861 }
duke@0 862
duke@0 863
duke@0 864 //--------------------------generate_current_thread--------------------
duke@0 865 Node* LibraryCallKit::generate_current_thread(Node* &tls_output) {
duke@0 866 ciKlass* thread_klass = env()->Thread_klass();
duke@0 867 const Type* thread_type = TypeOopPtr::make_from_klass(thread_klass)->cast_to_ptr_type(TypePtr::NotNull);
duke@0 868 Node* thread = _gvn.transform(new (C, 1) ThreadLocalNode());
duke@0 869 Node* p = basic_plus_adr(top()/*!oop*/, thread, in_bytes(JavaThread::threadObj_offset()));
duke@0 870 Node* threadObj = make_load(NULL, p, thread_type, T_OBJECT);
duke@0 871 tls_output = thread;
duke@0 872 return threadObj;
duke@0 873 }
duke@0 874
duke@0 875
kvn@986 876 //------------------------------make_string_method_node------------------------
kvn@3325 877 // Helper method for String intrinsic functions. This version is called
kvn@3325 878 // with str1 and str2 pointing to String object nodes.
kvn@3325 879 //
kvn@3325 880 Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1, Node* str2) {
kvn@986 881 Node* no_ctrl = NULL;
kvn@986 882
kvn@3325 883 // Get start addr of string
kvn@3325 884 Node* str1_value = load_String_value(no_ctrl, str1);
kvn@3325 885 Node* str1_offset = load_String_offset(no_ctrl, str1);
kvn@986 886 Node* str1_start = array_element_address(str1_value, str1_offset, T_CHAR);
kvn@986 887
kvn@3325 888 // Get length of string 1
kvn@3325 889 Node* str1_len = load_String_length(no_ctrl, str1);
kvn@3325 890
kvn@3325 891 Node* str2_value = load_String_value(no_ctrl, str2);
kvn@3325 892 Node* str2_offset = load_String_offset(no_ctrl, str2);
kvn@986 893 Node* str2_start = array_element_address(str2_value, str2_offset, T_CHAR);
kvn@986 894
kvn@3325 895 Node* str2_len = NULL;
kvn@986 896 Node* result = NULL;
kvn@3325 897
kvn@986 898 switch (opcode) {
kvn@986 899 case Op_StrIndexOf:
kvn@3325 900 // Get length of string 2
kvn@3325 901 str2_len = load_String_length(no_ctrl, str2);
kvn@3325 902
kvn@986 903 result = new (C, 6) StrIndexOfNode(control(), memory(TypeAryPtr::CHARS),
kvn@3325 904 str1_start, str1_len, str2_start, str2_len);
kvn@986 905 break;
kvn@986 906 case Op_StrComp:
kvn@3325 907 // Get length of string 2
kvn@3325 908 str2_len = load_String_length(no_ctrl, str2);
kvn@3325 909
kvn@986 910 result = new (C, 6) StrCompNode(control(), memory(TypeAryPtr::CHARS),
kvn@3325 911 str1_start, str1_len, str2_start, str2_len);
kvn@986 912 break;
kvn@986 913 case Op_StrEquals:
kvn@986 914 result = new (C, 5) StrEqualsNode(control(), memory(TypeAryPtr::CHARS),
kvn@3325 915 str1_start, str2_start, str1_len);
kvn@986 916 break;
kvn@986 917 default:
kvn@986 918 ShouldNotReachHere();
kvn@986 919 return NULL;
kvn@986 920 }
kvn@986 921
kvn@986 922 // All these intrinsics have checks.
kvn@986 923 C->set_has_split_ifs(true); // Has chance for split-if optimization
kvn@986 924
kvn@986 925 return _gvn.transform(result);
kvn@986 926 }
kvn@986 927
kvn@3325 928 // Helper method for String intrinsic functions. This version is called
kvn@3325 929 // with str1 and str2 pointing to char[] nodes, with cnt1 and cnt2 pointing
kvn@3325 930 // to Int nodes containing the lenghts of str1 and str2.
kvn@3325 931 //
kvn@3325 932 Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2) {
kvn@3325 933
kvn@3325 934 Node* result = NULL;
kvn@3325 935 switch (opcode) {
kvn@3325 936 case Op_StrIndexOf:
kvn@3325 937 result = new (C, 6) StrIndexOfNode(control(), memory(TypeAryPtr::CHARS),
kvn@3325 938 str1_start, cnt1, str2_start, cnt2);
kvn@3325 939 break;
kvn@3325 940 case Op_StrComp:
kvn@3325 941 result = new (C, 6) StrCompNode(control(), memory(TypeAryPtr::CHARS),
kvn@3325 942 str1_start, cnt1, str2_start, cnt2);
kvn@3325 943 break;
kvn@3325 944 case Op_StrEquals:
kvn@3325 945 result = new (C, 5) StrEqualsNode(control(), memory(TypeAryPtr::CHARS),
kvn@3325 946 str1_start, str2_start, cnt1);
kvn@3325 947 break;
kvn@3325 948 default:
kvn@3325 949 ShouldNotReachHere();
kvn@3325 950 return NULL;
kvn@3325 951 }
kvn@3325 952
kvn@3325 953 // All these intrinsics have checks.
kvn@3325 954 C->set_has_split_ifs(true); // Has chance for split-if optimization
kvn@3325 955
kvn@3325 956 return _gvn.transform(result);
kvn@3325 957 }
kvn@3325 958
duke@0 959 //------------------------------inline_string_compareTo------------------------
duke@0 960 bool LibraryCallKit::inline_string_compareTo() {
duke@0 961
cfang@681 962 if (!Matcher::has_match_rule(Op_StrComp)) return false;
cfang@681 963
duke@0 964 _sp += 2;
duke@0 965 Node *argument = pop(); // pop non-receiver first: it was pushed second
duke@0 966 Node *receiver = pop();
duke@0 967
duke@0 968 // Null check on self without removing any arguments. The argument
duke@0 969 // null check technically happens in the wrong place, which can lead to
duke@0 970 // invalid stack traces when string compare is inlined into a method
duke@0 971 // which handles NullPointerExceptions.
duke@0 972 _sp += 2;
duke@0 973 receiver = do_null_check(receiver, T_OBJECT);
duke@0 974 argument = do_null_check(argument, T_OBJECT);
duke@0 975 _sp -= 2;
duke@0 976 if (stopped()) {
duke@0 977 return true;
duke@0 978 }
duke@0 979
kvn@3325 980 Node* compare = make_string_method_node(Op_StrComp, receiver, argument);
duke@0 981 push(compare);
duke@0 982 return true;
duke@0 983 }
duke@0 984
cfang@681 985 //------------------------------inline_string_equals------------------------
cfang@681 986 bool LibraryCallKit::inline_string_equals() {
cfang@681 987
cfang@681 988 if (!Matcher::has_match_rule(Op_StrEquals)) return false;
cfang@681 989
jrose@1666 990 int nargs = 2;
jrose@1666 991 _sp += nargs;
cfang@681 992 Node* argument = pop(); // pop non-receiver first: it was pushed second
cfang@681 993 Node* receiver = pop();
cfang@681 994
cfang@681 995 // Null check on self without removing any arguments. The argument
cfang@681 996 // null check technically happens in the wrong place, which can lead to
cfang@681 997 // invalid stack traces when string compare is inlined into a method
cfang@681 998 // which handles NullPointerExceptions.
jrose@1666 999 _sp += nargs;
cfang@681 1000 receiver = do_null_check(receiver, T_OBJECT);
cfang@681 1001 //should not do null check for argument for String.equals(), because spec
cfang@681 1002 //allows to specify NULL as argument.
jrose@1666 1003 _sp -= nargs;
cfang@681 1004
cfang@681 1005 if (stopped()) {
cfang@681 1006 return true;
cfang@681 1007 }
cfang@681 1008
kvn@986 1009 // paths (plus control) merge
kvn@986 1010 RegionNode* region = new (C, 5) RegionNode(5);
kvn@986 1011 Node* phi = new (C, 5) PhiNode(region, TypeInt::BOOL);
kvn@986 1012
kvn@986 1013 // does source == target string?
kvn@986 1014 Node* cmp = _gvn.transform(new (C, 3) CmpPNode(receiver, argument));
kvn@986 1015 Node* bol = _gvn.transform(new (C, 2) BoolNode(cmp, BoolTest::eq));
kvn@986 1016
kvn@986 1017 Node* if_eq = generate_slow_guard(bol, NULL);
kvn@986 1018 if (if_eq != NULL) {
kvn@986 1019 // receiver == argument
kvn@986 1020 phi->init_req(2, intcon(1));
kvn@986 1021 region->init_req(2, if_eq);
kvn@986 1022 }
kvn@986 1023
cfang@681 1024 // get String klass for instanceOf
cfang@681 1025 ciInstanceKlass* klass = env()->String_klass();
cfang@681 1026
kvn@986 1027 if (!stopped()) {
jrose@1666 1028 _sp += nargs; // gen_instanceof might do an uncommon trap
kvn@986 1029 Node* inst = gen_instanceof(argument, makecon(TypeKlassPtr::make(klass)));
jrose@1666 1030 _sp -= nargs;
kvn@986 1031 Node* cmp = _gvn.transform(new (C, 3) CmpINode(inst, intcon(1)));
kvn@986 1032 Node* bol = _gvn.transform(new (C, 2) BoolNode(cmp, BoolTest::ne));
kvn@986 1033
kvn@986 1034 Node* inst_false = generate_guard(bol, NULL, PROB_MIN);
kvn@986 1035 //instanceOf == true, fallthrough
kvn@986 1036
kvn@986 1037 if (inst_false != NULL) {
kvn@986 1038 phi->init_req(3, intcon(0));
kvn@986 1039 region->init_req(3, inst_false);
kvn@986 1040 }
kvn@986 1041 }
cfang@681 1042
kvn@986 1043 if (!stopped()) {
kvn@3325 1044 const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(klass);
kvn@3325 1045
never@1416 1046 // Properly cast the argument to String
never@1416 1047 argument = _gvn.transform(new (C, 2) CheckCastPPNode(control(), argument, string_type));
kvn@2434 1048 // This path is taken only when argument's type is String:NotNull.
kvn@2434 1049 argument = cast_not_null(argument, false);
never@1416 1050
kvn@3325 1051 Node* no_ctrl = NULL;
kvn@3325 1052
kvn@3325 1053 // Get start addr of receiver
kvn@3325 1054 Node* receiver_val = load_String_value(no_ctrl, receiver);
kvn@3325 1055 Node* receiver_offset = load_String_offset(no_ctrl, receiver);
kvn@3325 1056 Node* receiver_start = array_element_address(receiver_val, receiver_offset, T_CHAR);
kvn@3325 1057
kvn@3325 1058 // Get length of receiver
kvn@3325 1059 Node* receiver_cnt = load_String_length(no_ctrl, receiver);
kvn@3325 1060
kvn@3325 1061 // Get start addr of argument
kvn@3325 1062 Node* argument_val = load_String_value(no_ctrl, argument);
kvn@3325 1063 Node* argument_offset = load_String_offset(no_ctrl, argument);
kvn@3325 1064 Node* argument_start = array_element_address(argument_val, argument_offset, T_CHAR);
kvn@3325 1065
kvn@3325 1066 // Get length of argument
kvn@3325 1067 Node* argument_cnt = load_String_length(no_ctrl, argument);
kvn@986 1068
kvn@986 1069 // Check for receiver count != argument count
kvn@986 1070 Node* cmp = _gvn.transform( new(C, 3) CmpINode(receiver_cnt, argument_cnt) );
kvn@986 1071 Node* bol = _gvn.transform( new(C, 2) BoolNode(cmp, BoolTest::ne) );
kvn@986 1072 Node* if_ne = generate_slow_guard(bol, NULL);
kvn@986 1073 if (if_ne != NULL) {
kvn@986 1074 phi->init_req(4, intcon(0));
kvn@986 1075 region->init_req(4, if_ne);
kvn@986 1076 }
kvn@3325 1077
kvn@3325 1078 // Check for count == 0 is done by assembler code for StrEquals.
kvn@3325 1079
kvn@3325 1080 if (!stopped()) {
kvn@3325 1081 Node* equals = make_string_method_node(Op_StrEquals, receiver_start, receiver_cnt, argument_start, argument_cnt);
kvn@3325 1082 phi->init_req(1, equals);
kvn@3325 1083 region->init_req(1, control());
kvn@3325 1084 }
kvn@986 1085 }
cfang@681 1086
cfang@681 1087 // post merge
cfang@681 1088 set_control(_gvn.transform(region));
cfang@681 1089 record_for_igvn(region);
cfang@681 1090
cfang@681 1091 push(_gvn.transform(phi));
cfang@681 1092
cfang@681 1093 return true;
cfang@681 1094 }
cfang@681 1095
rasbold@169 1096 //------------------------------inline_array_equals----------------------------
rasbold@169 1097 bool LibraryCallKit::inline_array_equals() {
rasbold@169 1098
rasbold@174 1099 if (!Matcher::has_match_rule(Op_AryEq)) return false;
rasbold@174 1100
rasbold@169 1101 _sp += 2;
rasbold@169 1102 Node *argument2 = pop();
rasbold@169 1103 Node *argument1 = pop();
rasbold@169 1104
rasbold@169 1105 Node* equals =
kvn@986 1106 _gvn.transform(new (C, 4) AryEqNode(control(), memory(TypeAryPtr::CHARS),
kvn@986 1107 argument1, argument2) );
rasbold@169 1108 push(equals);
rasbold@169 1109 return true;
rasbold@169 1110 }
rasbold@169 1111
duke@0 1112 // Java version of String.indexOf(constant string)
duke@0 1113 // class StringDecl {
duke@0 1114 // StringDecl(char[] ca) {
duke@0 1115 // offset = 0;
duke@0 1116 // count = ca.length;
duke@0 1117 // value = ca;
duke@0 1118 // }
duke@0 1119 // int offset;
duke@0 1120 // int count;
duke@0 1121 // char[] value;
duke@0 1122 // }
duke@0 1123 //
duke@0 1124 // static int string_indexOf_J(StringDecl string_object, char[] target_object,
duke@0 1125 // int targetOffset, int cache_i, int md2) {
duke@0 1126 // int cache = cache_i;
duke@0 1127 // int sourceOffset = string_object.offset;
duke@0 1128 // int sourceCount = string_object.count;
duke@0 1129 // int targetCount = target_object.length;
duke@0 1130 //
duke@0 1131 // int targetCountLess1 = targetCount - 1;
duke@0 1132 // int sourceEnd = sourceOffset + sourceCount - targetCountLess1;
duke@0 1133 //
duke@0 1134 // char[] source = string_object.value;
duke@0 1135 // char[] target = target_object;
duke@0 1136 // int lastChar = target[targetCountLess1];
duke@0 1137 //
duke@0 1138 // outer_loop:
duke@0 1139 // for (int i = sourceOffset; i < sourceEnd; ) {
duke@0 1140 // int src = source[i + targetCountLess1];
duke@0 1141 // if (src == lastChar) {
duke@0 1142 // // With random strings and a 4-character alphabet,
duke@0 1143 // // reverse matching at this point sets up 0.8% fewer
duke@0 1144 // // frames, but (paradoxically) makes 0.3% more probes.
duke@0 1145 // // Since those probes are nearer the lastChar probe,
duke@0 1146 // // there is may be a net D$ win with reverse matching.
duke@0 1147 // // But, reversing loop inhibits unroll of inner loop
duke@0 1148 // // for unknown reason. So, does running outer loop from
duke@0 1149 // // (sourceOffset - targetCountLess1) to (sourceOffset + sourceCount)
duke@0 1150 // for (int j = 0; j < targetCountLess1; j++) {
duke@0 1151 // if (target[targetOffset + j] != source[i+j]) {
duke@0 1152 // if ((cache & (1 << source[i+j])) == 0) {
duke@0 1153 // if (md2 < j+1) {
duke@0 1154 // i += j+1;
duke@0 1155 // continue outer_loop;
duke@0 1156 // }
duke@0 1157 // }
duke@0 1158 // i += md2;
duke@0 1159 // continue outer_loop;
duke@0 1160 // }
duke@0 1161 // }
duke@0 1162 // return i - sourceOffset;
duke@0 1163 // }
duke@0 1164 // if ((cache & (1 << src)) == 0) {
duke@0 1165 // i += targetCountLess1;
duke@0 1166 // } // using "i += targetCount;" and an "else i++;" causes a jump to jump.
duke@0 1167 // i++;
duke@0 1168 // }
duke@0 1169 // return -1;
duke@0 1170 // }
duke@0 1171
duke@0 1172 //------------------------------string_indexOf------------------------
duke@0 1173 Node* LibraryCallKit::string_indexOf(Node* string_object, ciTypeArray* target_array, jint targetOffset_i,
duke@0 1174 jint cache_i, jint md2_i) {
duke@0 1175
duke@0 1176 Node* no_ctrl = NULL;
duke@0 1177 float likely = PROB_LIKELY(0.9);
duke@0 1178 float unlikely = PROB_UNLIKELY(0.9);
duke@0 1179
kvn@2230 1180 const int nargs = 2; // number of arguments to push back for uncommon trap in predicate
kvn@2230 1181
kvn@3325 1182 Node* source = load_String_value(no_ctrl, string_object);
kvn@3325 1183 Node* sourceOffset = load_String_offset(no_ctrl, string_object);
kvn@3325 1184 Node* sourceCount = load_String_length(no_ctrl, string_object);
duke@0 1185
jcoomes@2226 1186 Node* target = _gvn.transform( makecon(TypeOopPtr::make_from_constant(target_array, true)) );
duke@0 1187 jint target_length = target_array->length();
duke@0 1188 const TypeAry* target_array_type = TypeAry::make(TypeInt::CHAR, TypeInt::make(0, target_length, Type::WidenMin));
duke@0 1189 const TypeAryPtr* target_type = TypeAryPtr::make(TypePtr::BotPTR, target_array_type, target_array->klass(), true, Type::OffsetBot);
duke@0 1190
kvn@2291 1191 IdealKit kit(this, false, true);
duke@0 1192 #define __ kit.
duke@0 1193 Node* zero = __ ConI(0);
duke@0 1194 Node* one = __ ConI(1);
duke@0 1195 Node* cache = __ ConI(cache_i);
duke@0 1196 Node* md2 = __ ConI(md2_i);
duke@0 1197 Node* lastChar = __ ConI(target_array->char_at(target_length - 1));
duke@0 1198 Node* targetCount = __ ConI(target_length);
duke@0 1199 Node* targetCountLess1 = __ ConI(target_length - 1);
duke@0 1200 Node* targetOffset = __ ConI(targetOffset_i);
duke@0 1201 Node* sourceEnd = __ SubI(__ AddI(sourceOffset, sourceCount), targetCountLess1);
duke@0 1202
kvn@851 1203 IdealVariable rtn(kit), i(kit), j(kit); __ declarations_done();
duke@0 1204 Node* outer_loop = __ make_label(2 /* goto */);
duke@0 1205 Node* return_ = __ make_label(1);
duke@0 1206
duke@0 1207 __ set(rtn,__ ConI(-1));
kvn@2230 1208 __ loop(this, nargs, i, sourceOffset, BoolTest::lt, sourceEnd); {
duke@0 1209 Node* i2 = __ AddI(__ value(i), targetCountLess1);
duke@0 1210 // pin to prohibit loading of "next iteration" value which may SEGV (rare)
duke@0 1211 Node* src = load_array_element(__ ctrl(), source, i2, TypeAryPtr::CHARS);
duke@0 1212 __ if_then(src, BoolTest::eq, lastChar, unlikely); {
kvn@2230 1213 __ loop(this, nargs, j, zero, BoolTest::lt, targetCountLess1); {
duke@0 1214 Node* tpj = __ AddI(targetOffset, __ value(j));
duke@0 1215 Node* targ = load_array_element(no_ctrl, target, tpj, target_type);
duke@0 1216 Node* ipj = __ AddI(__ value(i), __ value(j));
duke@0 1217 Node* src2 = load_array_element(no_ctrl, source, ipj, TypeAryPtr::CHARS);
duke@0 1218 __ if_then(targ, BoolTest::ne, src2); {
duke@0 1219 __ if_then(__ AndI(cache, __ LShiftI(one, src2)), BoolTest::eq, zero); {
duke@0 1220 __ if_then(md2, BoolTest::lt, __ AddI(__ value(j), one)); {
duke@0 1221 __ increment(i, __ AddI(__ value(j), one));
duke@0 1222 __ goto_(outer_loop);
duke@0 1223 } __ end_if(); __ dead(j);
duke@0 1224 }__ end_if(); __ dead(j);
duke@0 1225 __ increment(i, md2);
duke@0 1226 __ goto_(outer_loop);
duke@0 1227 }__ end_if();
duke@0 1228 __ increment(j, one);
duke@0 1229 }__ end_loop(); __ dead(j);
duke@0 1230 __ set(rtn, __ SubI(__ value(i), sourceOffset)); __ dead(i);
duke@0 1231 __ goto_(return_);
duke@0 1232 }__ end_if();
duke@0 1233 __ if_then(__ AndI(cache, __ LShiftI(one, src)), BoolTest::eq, zero, likely); {
duke@0 1234 __ increment(i, targetCountLess1);
duke@0 1235 }__ end_if();
duke@0 1236 __ increment(i, one);
duke@0 1237 __ bind(outer_loop);
duke@0 1238 }__ end_loop(); __ dead(i);
duke@0 1239 __ bind(return_);
kvn@851 1240
kvn@851 1241 // Final sync IdealKit and GraphKit.
kvn@2291 1242 final_sync(kit);
duke@0 1243 Node* result = __ value(rtn);
duke@0 1244 #undef __
duke@0 1245 C->set_has_loops(true);
duke@0 1246 return result;
duke@0 1247 }
duke@0 1248
duke@0 1249 //------------------------------inline_string_indexOf------------------------
duke@0 1250 bool LibraryCallKit::inline_string_indexOf() {
duke@0 1251
duke@0 1252 _sp += 2;
duke@0 1253 Node *argument = pop(); // pop non-receiver first: it was pushed second
duke@0 1254 Node *receiver = pop();
duke@0 1255
cfang@681 1256 Node* result;
iveresov@1424 1257 // Disable the use of pcmpestri until it can be guaranteed that
iveresov@1424 1258 // the load doesn't cross into the uncommited space.
kvn@2167 1259 if (Matcher::has_match_rule(Op_StrIndexOf) &&
cfang@681 1260 UseSSE42Intrinsics) {
cfang@681 1261 // Generate SSE4.2 version of indexOf
cfang@681 1262 // We currently only have match rules that use SSE4.2
cfang@681 1263
cfang@681 1264 // Null check on self without removing any arguments. The argument
cfang@681 1265 // null check technically happens in the wrong place, which can lead to
cfang@681 1266 // invalid stack traces when string compare is inlined into a method
cfang@681 1267 // which handles NullPointerExceptions.
cfang@681 1268 _sp += 2;
cfang@681 1269 receiver = do_null_check(receiver, T_OBJECT);
cfang@681 1270 argument = do_null_check(argument, T_OBJECT);
cfang@681 1271 _sp -= 2;
cfang@681 1272
cfang@681 1273 if (stopped()) {
cfang@681 1274 return true;
cfang@681 1275 }
cfang@681 1276
kvn@2167 1277 ciInstanceKlass* str_klass = env()->String_klass();
kvn@2167 1278 const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(str_klass);
kvn@2167 1279
kvn@986 1280 // Make the merge point
kvn@2167 1281 RegionNode* result_rgn = new (C, 4) RegionNode(4);
kvn@2167 1282 Node* result_phi = new (C, 4) PhiNode(result_rgn, TypeInt::INT);
kvn@986 1283 Node* no_ctrl = NULL;
kvn@986 1284
kvn@3325 1285 // Get start addr of source string
kvn@3325 1286 Node* source = load_String_value(no_ctrl, receiver);
kvn@3325 1287 Node* source_offset = load_String_offset(no_ctrl, receiver);
kvn@3325 1288 Node* source_start = array_element_address(source, source_offset, T_CHAR);
kvn@3325 1289
kvn@3325 1290 // Get length of source string
kvn@3325 1291 Node* source_cnt = load_String_length(no_ctrl, receiver);
kvn@3325 1292
kvn@3325 1293 // Get start addr of substring
kvn@3325 1294 Node* substr = load_String_value(no_ctrl, argument);
kvn@3325 1295 Node* substr_offset = load_String_offset(no_ctrl, argument);
kvn@3325 1296 Node* substr_start = array_element_address(substr, substr_offset, T_CHAR);
kvn@3325 1297
kvn@3325 1298 // Get length of source string
kvn@3325 1299 Node* substr_cnt = load_String_length(no_ctrl, argument);
kvn@986 1300
kvn@986 1301 // Check for substr count > string count
kvn@986 1302 Node* cmp = _gvn.transform( new(C, 3) CmpINode(substr_cnt, source_cnt) );
kvn@986 1303 Node* bol = _gvn.transform( new(C, 2) BoolNode(cmp, BoolTest::gt) );
kvn@986 1304 Node* if_gt = generate_slow_guard(bol, NULL);
kvn@986 1305 if (if_gt != NULL) {
kvn@986 1306 result_phi->init_req(2, intcon(-1));
kvn@986 1307 result_rgn->init_req(2, if_gt);
kvn@986 1308 }
kvn@986 1309
kvn@986 1310 if (!stopped()) {
kvn@2167 1311 // Check for substr count == 0
kvn@2167 1312 cmp = _gvn.transform( new(C, 3) CmpINode(substr_cnt, intcon(0)) );
kvn@2167 1313 bol = _gvn.transform( new(C, 2) BoolNode(cmp, BoolTest::eq) );
kvn@2167 1314 Node* if_zero = generate_slow_guard(bol, NULL);
kvn@2167 1315 if (if_zero != NULL) {
kvn@2167 1316 result_phi->init_req(3, intcon(0));
kvn@2167 1317 result_rgn->init_req(3, if_zero);
kvn@2167 1318 }
kvn@2167 1319 }
kvn@2167 1320
kvn@2167 1321 if (!stopped()) {
kvn@3325 1322 result = make_string_method_node(Op_StrIndexOf, source_start, source_cnt, substr_start, substr_cnt);
kvn@986 1323 result_phi->init_req(1, result);
kvn@986 1324 result_rgn->init_req(1, control());
kvn@986 1325 }
kvn@986 1326 set_control(_gvn.transform(result_rgn));
kvn@986 1327 record_for_igvn(result_rgn);
kvn@986 1328 result = _gvn.transform(result_phi);
kvn@986 1329
kvn@2167 1330 } else { // Use LibraryCallKit::string_indexOf
kvn@2167 1331 // don't intrinsify if argument isn't a constant string.
cfang@681 1332 if (!argument->is_Con()) {
cfang@681 1333 return false;
cfang@681 1334 }
cfang@681 1335 const TypeOopPtr* str_type = _gvn.type(argument)->isa_oopptr();
cfang@681 1336 if (str_type == NULL) {
cfang@681 1337 return false;
cfang@681 1338 }
cfang@681 1339 ciInstanceKlass* klass = env()->String_klass();
cfang@681 1340 ciObject* str_const = str_type->const_oop();
cfang@681 1341 if (str_const == NULL || str_const->klass() != klass) {
cfang@681 1342 return false;
cfang@681 1343 }
cfang@681 1344 ciInstance* str = str_const->as_instance();
cfang@681 1345 assert(str != NULL, "must be instance");
cfang@681 1346
kvn@3325 1347 ciObject* v = str->field_value_by_offset(java_lang_String::value_offset_in_bytes()).as_object();
cfang@681 1348 ciTypeArray* pat = v->as_type_array(); // pattern (argument) character array
cfang@681 1349
kvn@3325 1350 int o;
kvn@3325 1351 int c;
kvn@3325 1352 if (java_lang_String::has_offset_field()) {
kvn@3325 1353 o = str->field_value_by_offset(java_lang_String::offset_offset_in_bytes()).as_int();
kvn@3325 1354 c = str->field_value_by_offset(java_lang_String::count_offset_in_bytes()).as_int();
kvn@3325 1355 } else {
kvn@3325 1356 o = 0;
kvn@3325 1357 c = pat->length();
kvn@3325 1358 }
kvn@3325 1359
cfang@681 1360 // constant strings have no offset and count == length which
cfang@681 1361 // simplifies the resulting code somewhat so lets optimize for that.
cfang@681 1362 if (o != 0 || c != pat->length()) {
cfang@681 1363 return false;
cfang@681 1364 }
cfang@681 1365
cfang@681 1366 // Null check on self without removing any arguments. The argument
cfang@681 1367 // null check technically happens in the wrong place, which can lead to
cfang@681 1368 // invalid stack traces when string compare is inlined into a method
cfang@681 1369 // which handles NullPointerExceptions.
cfang@681 1370 _sp += 2;
cfang@681 1371 receiver = do_null_check(receiver, T_OBJECT);
cfang@681 1372 // No null check on the argument is needed since it's a constant String oop.
cfang@681 1373 _sp -= 2;
cfang@681 1374 if (stopped()) {
kvn@2167 1375 return true;
cfang@681 1376 }
cfang@681 1377
cfang@681 1378 // The null string as a pattern always returns 0 (match at beginning of string)
cfang@681 1379 if (c == 0) {
cfang@681 1380 push(intcon(0));
cfang@681 1381 return true;
cfang@681 1382 }
cfang@681 1383
cfang@681 1384 // Generate default indexOf
cfang@681 1385 jchar lastChar = pat->char_at(o + (c - 1));
cfang@681 1386 int cache = 0;
cfang@681 1387 int i;
cfang@681 1388 for (i = 0; i < c - 1; i++) {
cfang@681 1389 assert(i < pat->length(), "out of range");
cfang@681 1390 cache |= (1 << (pat->char_at(o + i) & (sizeof(cache) * BitsPerByte - 1)));
cfang@681 1391 }
cfang@681 1392
cfang@681 1393 int md2 = c;
cfang@681 1394 for (i = 0; i < c - 1; i++) {
cfang@681 1395 assert(i < pat->length(), "out of range");
cfang@681 1396 if (pat->char_at(o + i) == lastChar) {
cfang@681 1397 md2 = (c - 1) - i;
cfang@681 1398 }
cfang@681 1399 }
cfang@681 1400
cfang@681 1401 result = string_indexOf(receiver, pat, o, cache, md2);
duke@0 1402 }
cfang@681 1403
duke@0 1404 push(result);
duke@0 1405 return true;
duke@0 1406 }
duke@0 1407
duke@0 1408 //--------------------------pop_math_arg--------------------------------
duke@0 1409 // Pop a double argument to a math function from the stack
duke@0 1410 // rounding it if necessary.
duke@0 1411 Node * LibraryCallKit::pop_math_arg() {
duke@0 1412 Node *arg = pop_pair();
duke@0 1413 if( Matcher::strict_fp_requires_explicit_rounding && UseSSE<=1 )
duke@0 1414 arg = _gvn.transform( new (C, 2) RoundDoubleNode(0, arg) );
duke@0 1415 return arg;
duke@0 1416 }
duke@0 1417
duke@0 1418 //------------------------------inline_trig----------------------------------
duke@0 1419 // Inline sin/cos/tan instructions, if possible. If rounding is required, do
duke@0 1420 // argument reduction which will turn into a fast/slow diamond.
duke@0 1421 bool LibraryCallKit::inline_trig(vmIntrinsics::ID id) {
duke@0 1422 _sp += arg_size(); // restore stack pointer
duke@0 1423 Node* arg = pop_math_arg();
duke@0 1424 Node* trig = NULL;
duke@0 1425
duke@0 1426 switch (id) {
duke@0 1427 case vmIntrinsics::_dsin:
duke@0 1428 trig = _gvn.transform((Node*)new (C, 2) SinDNode(arg));
duke@0 1429 break;
duke@0 1430 case vmIntrinsics::_dcos:
duke@0 1431 trig = _gvn.transform((Node*)new (C, 2) CosDNode(arg));
duke@0 1432 break;
duke@0 1433 case vmIntrinsics::_dtan:
duke@0 1434 trig = _gvn.transform((Node*)new (C, 2) TanDNode(arg));
duke@0 1435 break;
duke@0 1436 default:
duke@0 1437 assert(false, "bad intrinsic was passed in");
duke@0 1438 return false;
duke@0 1439 }
duke@0 1440
duke@0 1441 // Rounding required? Check for argument reduction!
duke@0 1442 if( Matcher::strict_fp_requires_explicit_rounding ) {
duke@0 1443
duke@0 1444 static const double pi_4 = 0.7853981633974483;
duke@0 1445 static const double neg_pi_4 = -0.7853981633974483;
duke@0 1446 // pi/2 in 80-bit extended precision
duke@0 1447 // static const unsigned char pi_2_bits_x[] = {0x35,0xc2,0x68,0x21,0xa2,0xda,0x0f,0xc9,0xff,0x3f,0x00,0x00,0x00,0x00,0x00,0x00};
duke@0 1448 // -pi/2 in 80-bit extended precision
duke@0 1449 // 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};
duke@0 1450 // Cutoff value for using this argument reduction technique
duke@0 1451 //static const double pi_2_minus_epsilon = 1.564660403643354;
duke@0 1452 //static const double neg_pi_2_plus_epsilon = -1.564660403643354;
duke@0 1453
duke@0 1454 // Pseudocode for sin:
duke@0 1455 // if (x <= Math.PI / 4.0) {
duke@0 1456 // if (x >= -Math.PI / 4.0) return fsin(x);
duke@0 1457 // if (x >= -Math.PI / 2.0) return -fcos(x + Math.PI / 2.0);
duke@0 1458 // } else {
duke@0 1459 // if (x <= Math.PI / 2.0) return fcos(x - Math.PI / 2.0);
duke@0 1460 // }
duke@0 1461 // return StrictMath.sin(x);
duke@0 1462
duke@0 1463 // Pseudocode for cos:
duke@0 1464 // if (x <= Math.PI / 4.0) {
duke@0 1465 // if (x >= -Math.PI / 4.0) return fcos(x);
duke@0 1466 // if (x >= -Math.PI / 2.0) return fsin(x + Math.PI / 2.0);
duke@0 1467 // } else {
duke@0 1468 // if (x <= Math.PI / 2.0) return -fsin(x - Math.PI / 2.0);
duke@0 1469 // }
duke@0 1470 // return StrictMath.cos(x);
duke@0 1471
duke@0 1472 // Actually, sticking in an 80-bit Intel value into C2 will be tough; it
duke@0 1473 // requires a special machine instruction to load it. Instead we'll try
duke@0 1474 // the 'easy' case. If we really need the extra range +/- PI/2 we'll
duke@0 1475 // probably do the math inside the SIN encoding.
duke@0 1476
duke@0 1477 // Make the merge point
duke@0 1478 RegionNode *r = new (C, 3) RegionNode(3);
duke@0 1479 Node *phi = new (C, 3) PhiNode(r,Type::DOUBLE);
duke@0 1480
duke@0 1481 // Flatten arg so we need only 1 test
duke@0 1482 Node *abs = _gvn.transform(new (C, 2) AbsDNode(arg));
duke@0 1483 // Node for PI/4 constant
duke@0 1484 Node *pi4 = makecon(TypeD::make(pi_4));
duke@0 1485 // Check PI/4 : abs(arg)
duke@0 1486 Node *cmp = _gvn.transform(new (C, 3) CmpDNode(pi4,abs));
duke@0 1487 // Check: If PI/4 < abs(arg) then go slow
duke@0 1488 Node *bol = _gvn.transform( new (C, 2) BoolNode( cmp, BoolTest::lt ) );
duke@0 1489 // Branch either way
duke@0 1490 IfNode *iff = create_and_xform_if(control(),bol, PROB_STATIC_FREQUENT, COUNT_UNKNOWN);
duke@0 1491 set_control(opt_iff(r,iff));
duke@0 1492
duke@0 1493 // Set fast path result
duke@0 1494 phi->init_req(2,trig);
duke@0 1495
duke@0 1496 // Slow path - non-blocking leaf call
duke@0 1497 Node* call = NULL;
duke@0 1498 switch (id) {
duke@0 1499 case vmIntrinsics::_dsin:
duke@0 1500 call = make_runtime_call(RC_LEAF, OptoRuntime::Math_D_D_Type(),
duke@0 1501 CAST_FROM_FN_PTR(address, SharedRuntime::dsin),
duke@0 1502 "Sin", NULL, arg, top());
duke@0 1503 break;
duke@0 1504 case vmIntrinsics::_dcos:
duke@0 1505 call = make_runtime_call(RC_LEAF, OptoRuntime::Math_D_D_Type(),
duke@0 1506 CAST_FROM_FN_PTR(address, SharedRuntime::dcos),
duke@0 1507 "Cos", NULL, arg, top());
duke@0 1508 break;
duke@0 1509 case vmIntrinsics::_dtan:
duke@0 1510 call = make_runtime_call(RC_LEAF, OptoRuntime::Math_D_D_Type(),
duke@0 1511 CAST_FROM_FN_PTR(address, SharedRuntime::dtan),
duke@0 1512 "Tan", NULL, arg, top());
duke@0 1513 break;
duke@0 1514 }
duke@0 1515 assert(control()->in(0) == call, "");
duke@0 1516 Node* slow_result = _gvn.transform(new (C, 1) ProjNode(call,TypeFunc::Parms));
duke@0 1517 r->init_req(1,control());
duke@0 1518 phi->init_req(1,slow_result);
duke@0 1519
duke@0 1520 // Post-merge
duke@0 1521 set_control(_gvn.transform(r));
duke@0 1522 record_for_igvn(r);
duke@0 1523 trig = _gvn.transform(phi);
duke@0 1524
duke@0 1525 C->set_has_split_ifs(true); // Has chance for split-if optimization
duke@0 1526 }
duke@0 1527 // Push result back on JVM stack
duke@0 1528 push_pair(trig);
duke@0 1529 return true;
duke@0 1530 }
duke@0 1531
duke@0 1532 //------------------------------inline_sqrt-------------------------------------
duke@0 1533 // Inline square root instruction, if possible.
duke@0 1534 bool LibraryCallKit::inline_sqrt(vmIntrinsics::ID id) {
duke@0 1535 assert(id == vmIntrinsics::_dsqrt, "Not square root");
duke@0 1536 _sp += arg_size(); // restore stack pointer
duke@0 1537 push_pair(_gvn.transform(new (C, 2) SqrtDNode(0, pop_math_arg())));
duke@0 1538 return true;
duke@0 1539 }
duke@0 1540
duke@0 1541 //------------------------------inline_abs-------------------------------------
duke@0 1542 // Inline absolute value instruction, if possible.
duke@0 1543 bool LibraryCallKit::inline_abs(vmIntrinsics::ID id) {
duke@0 1544 assert(id == vmIntrinsics::_dabs, "Not absolute value");
duke@0 1545 _sp += arg_size(); // restore stack pointer
duke@0 1546 push_pair(_gvn.transform(new (C, 2) AbsDNode(pop_math_arg())));
duke@0 1547 return true;
duke@0 1548 }
duke@0 1549
duke@0 1550 //------------------------------inline_exp-------------------------------------
duke@0 1551 // Inline exp instructions, if possible. The Intel hardware only misses
duke@0 1552 // really odd corner cases (+/- Infinity). Just uncommon-trap them.
duke@0 1553 bool LibraryCallKit::inline_exp(vmIntrinsics::ID id) {
duke@0 1554 assert(id == vmIntrinsics::_dexp, "Not exp");
duke@0 1555
duke@0 1556 // If this inlining ever returned NaN in the past, we do not intrinsify it
duke@0 1557 // every again. NaN results requires StrictMath.exp handling.
duke@0 1558 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false;
duke@0 1559
duke@0 1560 _sp += arg_size(); // restore stack pointer
duke@0 1561 Node *x = pop_math_arg();
duke@0 1562 Node *result = _gvn.transform(new (C, 2) ExpDNode(0,x));
duke@0 1563
duke@0 1564 //-------------------
duke@0 1565 //result=(result.isNaN())? StrictMath::exp():result;
duke@0 1566 // Check: If isNaN() by checking result!=result? then go to Strict Math
duke@0 1567 Node* cmpisnan = _gvn.transform(new (C, 3) CmpDNode(result,result));
duke@0 1568 // Build the boolean node
duke@0 1569 Node* bolisnum = _gvn.transform( new (C, 2) BoolNode(cmpisnan, BoolTest::eq) );
duke@0 1570
duke@0 1571 { BuildCutout unless(this, bolisnum, PROB_STATIC_FREQUENT);
duke@0 1572 // End the current control-flow path
duke@0 1573 push_pair(x);
duke@0 1574 // Math.exp intrinsic returned a NaN, which requires StrictMath.exp
duke@0 1575 // to handle. Recompile without intrinsifying Math.exp
duke@0 1576 uncommon_trap(Deoptimization::Reason_intrinsic,
duke@0 1577 Deoptimization::Action_make_not_entrant);
duke@0 1578 }
duke@0 1579
duke@0 1580 C->set_has_split_ifs(true); // Has chance for split-if optimization
duke@0 1581
duke@0 1582 push_pair(result);
duke@0 1583
duke@0 1584 return true;
duke@0 1585 }
duke@0 1586
duke@0 1587 //------------------------------inline_pow-------------------------------------
duke@0 1588 // Inline power instructions, if possible.
duke@0 1589 bool LibraryCallKit::inline_pow(vmIntrinsics::ID id) {
duke@0 1590 assert(id == vmIntrinsics::_dpow, "Not pow");
duke@0 1591
duke@0 1592 // If this inlining ever returned NaN in the past, we do not intrinsify it
duke@0 1593 // every again. NaN results requires StrictMath.pow handling.
duke@0 1594 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false;
duke@0 1595
duke@0 1596 // Do not intrinsify on older platforms which lack cmove.
duke@0 1597 if (ConditionalMoveLimit == 0) return false;
duke@0 1598
duke@0 1599 // Pseudocode for pow
duke@0 1600 // if (x <= 0.0) {
duke@0 1601 // if ((double)((int)y)==y) { // if y is int
duke@0 1602 // result = ((1&(int)y)==0)?-DPow(abs(x), y):DPow(abs(x), y)
duke@0 1603 // } else {
duke@0 1604 // result = NaN;
duke@0 1605 // }
duke@0 1606 // } else {
duke@0 1607 // result = DPow(x,y);
duke@0 1608 // }
duke@0 1609 // if (result != result)? {
twisti@605 1610 // uncommon_trap();
duke@0 1611 // }
duke@0 1612 // return result;
duke@0 1613
duke@0 1614 _sp += arg_size(); // restore stack pointer
duke@0 1615 Node* y = pop_math_arg();
duke@0 1616 Node* x = pop_math_arg();
duke@0 1617
duke@0 1618 Node *fast_result = _gvn.transform( new (C, 3) PowDNode(0, x, y) );
duke@0 1619
duke@0 1620 // Short form: if not top-level (i.e., Math.pow but inlining Math.pow
duke@0 1621 // inside of something) then skip the fancy tests and just check for
duke@0 1622 // NaN result.
duke@0 1623 Node *result = NULL;
duke@0 1624 if( jvms()->depth() >= 1 ) {
duke@0 1625 result = fast_result;
duke@0 1626 } else {
duke@0 1627
duke@0 1628 // Set the merge point for If node with condition of (x <= 0.0)
duke@0 1629 // There are four possible paths to region node and phi node
duke@0 1630 RegionNode *r = new (C, 4) RegionNode(4);
duke@0 1631 Node *phi = new (C, 4) PhiNode(r, Type::DOUBLE);
duke@0 1632
duke@0 1633 // Build the first if node: if (x <= 0.0)
duke@0 1634 // Node for 0 constant
duke@0 1635 Node *zeronode = makecon(TypeD::ZERO);
duke@0 1636 // Check x:0
duke@0 1637 Node *cmp = _gvn.transform(new (C, 3) CmpDNode(x, zeronode));
duke@0 1638 // Check: If (x<=0) then go complex path
duke@0 1639 Node *bol1 = _gvn.transform( new (C, 2) BoolNode( cmp, BoolTest::le ) );
duke@0 1640 // Branch either way
duke@0 1641 IfNode *if1 = create_and_xform_if(control(),bol1, PROB_STATIC_INFREQUENT, COUNT_UNKNOWN);
duke@0 1642 Node *opt_test = _gvn.transform(if1);
duke@0 1643 //assert( opt_test->is_If(), "Expect an IfNode");
duke@0 1644 IfNode *opt_if1 = (IfNode*)opt_test;
duke@0 1645 // Fast path taken; set region slot 3
duke@0 1646 Node *fast_taken = _gvn.transform( new (C, 1) IfFalseNode(opt_if1) );
duke@0 1647 r->init_req(3,fast_taken); // Capture fast-control
duke@0 1648
duke@0 1649 // Fast path not-taken, i.e. slow path
duke@0 1650 Node *complex_path = _gvn.transform( new (C, 1) IfTrueNode(opt_if1) );
duke@0 1651
duke@0 1652 // Set fast path result
duke@0 1653 Node *fast_result = _gvn.transform( new (C, 3) PowDNode(0, y, x) );
duke@0 1654 phi->init_req(3, fast_result);
duke@0 1655
duke@0 1656 // Complex path
duke@0 1657 // Build the second if node (if y is int)
duke@0 1658 // Node for (int)y
duke@0 1659 Node *inty = _gvn.transform( new (C, 2) ConvD2INode(y));
duke@0 1660 // Node for (double)((int) y)
duke@0 1661 Node *doubleinty= _gvn.transform( new (C, 2) ConvI2DNode(inty));
duke@0 1662 // Check (double)((int) y) : y
duke@0 1663 Node *cmpinty= _gvn.transform(new (C, 3) CmpDNode(doubleinty, y));
duke@0 1664 // Check if (y isn't int) then go to slow path
duke@0 1665
duke@0 1666 Node *bol2 = _gvn.transform( new (C, 2) BoolNode( cmpinty, BoolTest::ne ) );
twisti@605 1667 // Branch either way
duke@0 1668 IfNode *if2 = create_and_xform_if(complex_path,bol2, PROB_STATIC_INFREQUENT, COUNT_UNKNOWN);
duke@0 1669 Node *slow_path = opt_iff(r,if2); // Set region path 2
duke@0 1670
duke@0 1671 // Calculate DPow(abs(x), y)*(1 & (int)y)
duke@0 1672 // Node for constant 1
duke@0 1673 Node *conone = intcon(1);
duke@0 1674 // 1& (int)y
duke@0 1675 Node *signnode= _gvn.transform( new (C, 3) AndINode(conone, inty) );
duke@0 1676 // zero node
duke@0 1677 Node *conzero = intcon(0);
duke@0 1678 // Check (1&(int)y)==0?
duke@0 1679 Node *cmpeq1 = _gvn.transform(new (C, 3) CmpINode(signnode, conzero));
duke@0 1680 // Check if (1&(int)y)!=0?, if so the result is negative
duke@0 1681 Node *bol3 = _gvn.transform( new (C, 2) BoolNode( cmpeq1, BoolTest::ne ) );
duke@0 1682 // abs(x)
duke@0 1683 Node *absx=_gvn.transform( new (C, 2) AbsDNode(x));
duke@0 1684 // abs(x)^y
duke@0 1685 Node *absxpowy = _gvn.transform( new (C, 3) PowDNode(0, y, absx) );
duke@0 1686 // -abs(x)^y
duke@0 1687 Node *negabsxpowy = _gvn.transform(new (C, 2) NegDNode (absxpowy));
duke@0 1688 // (1&(int)y)==1?-DPow(abs(x), y):DPow(abs(x), y)
duke@0 1689 Node *signresult = _gvn.transform( CMoveNode::make(C, NULL, bol3, absxpowy, negabsxpowy, Type::DOUBLE));
duke@0 1690 // Set complex path fast result
duke@0 1691 phi->init_req(2, signresult);
duke@0 1692
duke@0 1693 static const jlong nan_bits = CONST64(0x7ff8000000000000);
duke@0 1694 Node *slow_result = makecon(TypeD::make(*(double*)&nan_bits)); // return NaN
duke@0 1695 r->init_req(1,slow_path);
duke@0 1696 phi->init_req(1,slow_result);
duke@0 1697
duke@0 1698 // Post merge
duke@0 1699 set_control(_gvn.transform(r));
duke@0 1700 record_for_igvn(r);
duke@0 1701 result=_gvn.transform(phi);
duke@0 1702 }
duke@0 1703
duke@0 1704 //-------------------
duke@0 1705 //result=(result.isNaN())? uncommon_trap():result;
duke@0 1706 // Check: If isNaN() by checking result!=result? then go to Strict Math
duke@0 1707 Node* cmpisnan = _gvn.transform(new (C, 3) CmpDNode(result,result));
duke@0 1708 // Build the boolean node
duke@0 1709 Node* bolisnum = _gvn.transform( new (C, 2) BoolNode(cmpisnan, BoolTest::eq) );
duke@0 1710
duke@0 1711 { BuildCutout unless(this, bolisnum, PROB_STATIC_FREQUENT);
duke@0 1712 // End the current control-flow path
duke@0 1713 push_pair(x);
duke@0 1714 push_pair(y);
duke@0 1715 // Math.pow intrinsic returned a NaN, which requires StrictMath.pow
duke@0 1716 // to handle. Recompile without intrinsifying Math.pow.
duke@0 1717 uncommon_trap(Deoptimization::Reason_intrinsic,
duke@0 1718 Deoptimization::Action_make_not_entrant);
duke@0 1719 }
duke@0 1720
duke@0 1721 C->set_has_split_ifs(true); // Has chance for split-if optimization
duke@0 1722
duke@0 1723 push_pair(result);
duke@0 1724
duke@0 1725 return true;
duke@0 1726 }
duke@0 1727
duke@0 1728 //------------------------------inline_trans-------------------------------------
duke@0 1729 // Inline transcendental instructions, if possible. The Intel hardware gets
duke@0 1730 // these right, no funny corner cases missed.
duke@0 1731 bool LibraryCallKit::inline_trans(vmIntrinsics::ID id) {
duke@0 1732 _sp += arg_size(); // restore stack pointer
duke@0 1733 Node* arg = pop_math_arg();
duke@0 1734 Node* trans = NULL;
duke@0 1735
duke@0 1736 switch (id) {
duke@0 1737 case vmIntrinsics::_dlog:
duke@0 1738 trans = _gvn.transform((Node*)new (C, 2) LogDNode(arg));
duke@0 1739 break;
duke@0 1740 case vmIntrinsics::_dlog10:
duke@0 1741 trans = _gvn.transform((Node*)new (C, 2) Log10DNode(arg));
duke@0 1742 break;
duke@0 1743 default:
duke@0 1744 assert(false, "bad intrinsic was passed in");
duke@0 1745 return false;
duke@0 1746 }
duke@0 1747
duke@0 1748 // Push result back on JVM stack
duke@0 1749 push_pair(trans);
duke@0 1750 return true;
duke@0 1751 }
duke@0 1752
duke@0 1753 //------------------------------runtime_math-----------------------------
duke@0 1754 bool LibraryCallKit::runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName) {
duke@0 1755 Node* a = NULL;
duke@0 1756 Node* b = NULL;
duke@0 1757
duke@0 1758 assert(call_type == OptoRuntime::Math_DD_D_Type() || call_type == OptoRuntime::Math_D_D_Type(),
duke@0 1759 "must be (DD)D or (D)D type");
duke@0 1760
duke@0 1761 // Inputs
duke@0 1762 _sp += arg_size(); // restore stack pointer
duke@0 1763 if (call_type == OptoRuntime::Math_DD_D_Type()) {
duke@0 1764 b = pop_math_arg();
duke@0 1765 }
duke@0 1766 a = pop_math_arg();
duke@0 1767
duke@0 1768 const TypePtr* no_memory_effects = NULL;
duke@0 1769 Node* trig = make_runtime_call(RC_LEAF, call_type, funcAddr, funcName,
duke@0 1770 no_memory_effects,
duke@0 1771 a, top(), b, b ? top() : NULL);
duke@0 1772 Node* value = _gvn.transform(new (C, 1) ProjNode(trig, TypeFunc::Parms+0));
duke@0 1773 #ifdef ASSERT
duke@0 1774 Node* value_top = _gvn.transform(new (C, 1) ProjNode(trig, TypeFunc::Parms+1));
duke@0 1775 assert(value_top == top(), "second value must be top");
duke@0 1776 #endif
duke@0 1777
duke@0 1778 push_pair(value);
duke@0 1779 return true;
duke@0 1780 }
duke@0 1781
duke@0 1782 //------------------------------inline_math_native-----------------------------
duke@0 1783 bool LibraryCallKit::inline_math_native(vmIntrinsics::ID id) {
duke@0 1784 switch (id) {
duke@0 1785 // These intrinsics are not properly supported on all hardware
duke@0 1786 case vmIntrinsics::_dcos: return Matcher::has_match_rule(Op_CosD) ? inline_trig(id) :
duke@0 1787 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dcos), "COS");
duke@0 1788 case vmIntrinsics::_dsin: return Matcher::has_match_rule(Op_SinD) ? inline_trig(id) :
duke@0 1789 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dsin), "SIN");
duke@0 1790 case vmIntrinsics::_dtan: return Matcher::has_match_rule(Op_TanD) ? inline_trig(id) :
duke@0 1791 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dtan), "TAN");
duke@0 1792
duke@0 1793 case vmIntrinsics::_dlog: return Matcher::has_match_rule(Op_LogD) ? inline_trans(id) :
duke@0 1794 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dlog), "LOG");
duke@0 1795 case vmIntrinsics::_dlog10: return Matcher::has_match_rule(Op_Log10D) ? inline_trans(id) :
duke@0 1796 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dlog10), "LOG10");
duke@0 1797
duke@0 1798 // These intrinsics are supported on all hardware
duke@0 1799 case vmIntrinsics::_dsqrt: return Matcher::has_match_rule(Op_SqrtD) ? inline_sqrt(id) : false;
duke@0 1800 case vmIntrinsics::_dabs: return Matcher::has_match_rule(Op_AbsD) ? inline_abs(id) : false;
duke@0 1801
duke@0 1802 case vmIntrinsics::_dexp: return
roland@3352 1803 Matcher::has_match_rule(Op_ExpD) ? inline_exp(id) :
duke@0 1804 runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dexp), "EXP");
duke@0 1805 case vmIntrinsics::_dpow: return
roland@3352 1806 Matcher::has_match_rule(Op_PowD) ? inline_pow(id) :
duke@0 1807 runtime_math(OptoRuntime::Math_DD_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dpow), "POW");
duke@0 1808
duke@0 1809 // These intrinsics are not yet correctly implemented
duke@0 1810 case vmIntrinsics::_datan2:
duke@0 1811 return false;
duke@0 1812
duke@0 1813 default:
duke@0 1814 ShouldNotReachHere();
duke@0 1815 return false;
duke@0 1816 }
duke@0 1817 }
duke@0 1818
duke@0 1819 static bool is_simple_name(Node* n) {
duke@0 1820 return (n->req() == 1 // constant
duke@0 1821 || (n->is_Type() && n->as_Type()->type()->singleton())
duke@0 1822 || n->is_Proj() // parameter or return value
duke@0 1823 || n->is_Phi() // local of some sort
duke@0 1824 );
duke@0 1825 }
duke@0 1826
duke@0 1827 //----------------------------inline_min_max-----------------------------------
duke@0 1828 bool LibraryCallKit::inline_min_max(vmIntrinsics::ID id) {
duke@0 1829 push(generate_min_max(id, argument(0), argument(1)));
duke@0 1830
duke@0 1831 return true;
duke@0 1832 }
duke@0 1833
duke@0 1834 Node*
duke@0 1835 LibraryCallKit::generate_min_max(vmIntrinsics::ID id, Node* x0, Node* y0) {
duke@0 1836 // These are the candidate return value:
duke@0 1837 Node* xvalue = x0;
duke@0 1838 Node* yvalue = y0;
duke@0 1839
duke@0 1840 if (xvalue == yvalue) {
duke@0 1841 return xvalue;
duke@0 1842 }
duke@0 1843
duke@0 1844 bool want_max = (id == vmIntrinsics::_max);
duke@0 1845
duke@0 1846 const TypeInt* txvalue = _gvn.type(xvalue)->isa_int();
duke@0 1847 const TypeInt* tyvalue = _gvn.type(yvalue)->isa_int();
duke@0 1848 if (txvalue == NULL || tyvalue == NULL) return top();
duke@0 1849 // This is not really necessary, but it is consistent with a
duke@0 1850 // hypothetical MaxINode::Value method:
duke@0 1851 int widen = MAX2(txvalue->_widen, tyvalue->_widen);
duke@0 1852
duke@0 1853 // %%% This folding logic should (ideally) be in a different place.
duke@0 1854 // Some should be inside IfNode, and there to be a more reliable
duke@0 1855 // transformation of ?: style patterns into cmoves. We also want
duke@0 1856 // more powerful optimizations around cmove and min/max.
duke@0 1857
duke@0 1858 // Try to find a dominating comparison of these guys.
duke@0 1859 // It can simplify the index computation for Arrays.copyOf
duke@0 1860 // and similar uses of System.arraycopy.
duke@0 1861 // First, compute the normalized version of CmpI(x, y).
duke@0 1862 int cmp_op = Op_CmpI;
duke@0 1863 Node* xkey = xvalue;
duke@0 1864 Node* ykey = yvalue;
duke@0 1865 Node* ideal_cmpxy = _gvn.transform( new(C, 3) CmpINode(xkey, ykey) );
duke@0 1866 if (ideal_cmpxy->is_Cmp()) {
duke@0 1867 // E.g., if we have CmpI(length - offset, count),
duke@0 1868 // it might idealize to CmpI(length, count + offset)
duke@0 1869 cmp_op = ideal_cmpxy->Opcode();
duke@0 1870 xkey = ideal_cmpxy->in(1);
duke@0 1871 ykey = ideal_cmpxy->in(2);
duke@0 1872 }
duke@0 1873
duke@0 1874 // Start by locating any relevant comparisons.
duke@0 1875 Node* start_from = (xkey->outcnt() < ykey->outcnt()) ? xkey : ykey;
duke@0 1876 Node* cmpxy = NULL;
duke@0 1877 Node* cmpyx = NULL;
duke@0 1878 for (DUIterator_Fast kmax, k = start_from->fast_outs(kmax); k < kmax; k++) {
duke@0 1879 Node* cmp = start_from->fast_out(k);
duke@0 1880 if (cmp->outcnt() > 0 && // must have prior uses
duke@0 1881 cmp->in(0) == NULL && // must be context-independent
duke@0 1882 cmp->Opcode() == cmp_op) { // right kind of compare
duke@0 1883 if (cmp->in(1) == xkey && cmp->in(2) == ykey) cmpxy = cmp;
duke@0 1884 if (cmp->in(1) == ykey && cmp->in(2) == xkey) cmpyx = cmp;
duke@0 1885 }
duke@0 1886 }
duke@0 1887
duke@0 1888 const int NCMPS = 2;
duke@0 1889 Node* cmps[NCMPS] = { cmpxy, cmpyx };
duke@0 1890 int cmpn;
duke@0 1891 for (cmpn = 0; cmpn < NCMPS; cmpn++) {
duke@0 1892 if (cmps[cmpn] != NULL) break; // find a result
duke@0 1893 }
duke@0 1894 if (cmpn < NCMPS) {
duke@0 1895 // Look for a dominating test that tells us the min and max.
duke@0 1896 int depth = 0; // Limit search depth for speed
duke@0 1897 Node* dom = control();
duke@0 1898 for (; dom != NULL; dom = IfNode::up_one_dom(dom, true)) {
duke@0 1899 if (++depth >= 100) break;
duke@0 1900 Node* ifproj = dom;
duke@0 1901 if (!ifproj->is_Proj()) continue;
duke@0 1902 Node* iff = ifproj->in(0);
duke@0 1903 if (!iff->is_If()) continue;
duke@0 1904 Node* bol = iff->in(1);
duke@0 1905 if (!bol->is_Bool()) continue;
duke@0 1906 Node* cmp = bol->in(1);
duke@0 1907 if (cmp == NULL) continue;
duke@0 1908 for (cmpn = 0; cmpn < NCMPS; cmpn++)
duke@0 1909 if (cmps[cmpn] == cmp) break;
duke@0 1910 if (cmpn == NCMPS) continue;
duke@0 1911 BoolTest::mask btest = bol->as_Bool()->_test._test;
duke@0 1912 if (ifproj->is_IfFalse()) btest = BoolTest(btest).negate();
duke@0 1913 if (cmp->in(1) == ykey) btest = BoolTest(btest).commute();
duke@0 1914 // At this point, we know that 'x btest y' is true.
duke@0 1915 switch (btest) {
duke@0 1916 case BoolTest::eq:
duke@0 1917 // They are proven equal, so we can collapse the min/max.
duke@0 1918 // Either value is the answer. Choose the simpler.
duke@0 1919 if (is_simple_name(yvalue) && !is_simple_name(xvalue))
duke@0 1920 return yvalue;
duke@0 1921 return xvalue;
duke@0 1922 case BoolTest::lt: // x < y
duke@0 1923 case BoolTest::le: // x <= y
duke@0 1924 return (want_max ? yvalue : xvalue);
duke@0 1925 case BoolTest::gt: // x > y
duke@0 1926 case BoolTest::ge: // x >= y
duke@0 1927 return (want_max ? xvalue : yvalue);
duke@0 1928 }
duke@0 1929 }
duke@0 1930 }
duke@0 1931
duke@0 1932 // We failed to find a dominating test.
duke@0 1933 // Let's pick a test that might GVN with prior tests.
duke@0 1934 Node* best_bol = NULL;
duke@0 1935 BoolTest::mask best_btest = BoolTest::illegal;
duke@0 1936 for (cmpn = 0; cmpn < NCMPS; cmpn++) {
duke@0 1937 Node* cmp = cmps[cmpn];
duke@0 1938 if (cmp == NULL) continue;
duke@0 1939 for (DUIterator_Fast jmax, j = cmp->fast_outs(jmax); j < jmax; j++) {
duke@0 1940 Node* bol = cmp->fast_out(j);
duke@0 1941 if (!bol->is_Bool()) continue;
duke@0 1942 BoolTest::mask btest = bol->as_Bool()->_test._test;
duke@0 1943 if (btest == BoolTest::eq || btest == BoolTest::ne) continue;
duke@0 1944 if (cmp->in(1) == ykey) btest = BoolTest(btest).commute();
duke@0 1945 if (bol->outcnt() > (best_bol == NULL ? 0 : best_bol->outcnt())) {
duke@0 1946 best_bol = bol->as_Bool();
duke@0 1947 best_btest = btest;
duke@0 1948 }
duke@0 1949 }
duke@0 1950 }
duke@0 1951
duke@0 1952 Node* answer_if_true = NULL;
duke@0 1953 Node* answer_if_false = NULL;
duke@0 1954 switch (best_btest) {
duke@0 1955 default:
duke@0 1956 if (cmpxy == NULL)
duke@0 1957 cmpxy = ideal_cmpxy;
duke@0 1958 best_bol = _gvn.transform( new(C, 2) BoolNode(cmpxy, BoolTest::lt) );
duke@0 1959 // and fall through:
duke@0 1960 case BoolTest::lt: // x < y
duke@0 1961 case BoolTest::le: // x <= y
duke@0 1962 answer_if_true = (want_max ? yvalue : xvalue);
duke@0 1963 answer_if_false = (want_max ? xvalue : yvalue);
duke@0 1964 break;
duke@0 1965 case BoolTest::gt: // x > y
duke@0 1966 case BoolTest::ge: // x >= y
duke@0 1967 answer_if_true = (want_max ? xvalue : yvalue);
duke@0 1968 answer_if_false = (want_max ? yvalue : xvalue);
duke@0 1969 break;
duke@0 1970 }
duke@0 1971
duke@0 1972 jint hi, lo;
duke@0 1973 if (want_max) {
duke@0 1974 // We can sharpen the minimum.
duke@0 1975 hi = MAX2(txvalue->_hi, tyvalue->_hi);
duke@0 1976 lo = MAX2(txvalue->_lo, tyvalue->_lo);
duke@0 1977 } else {
duke@0 1978 // We can sharpen the maximum.
duke@0 1979 hi = MIN2(txvalue->_hi, tyvalue->_hi);
duke@0 1980 lo = MIN2(txvalue->_lo, tyvalue->_lo);
duke@0 1981 }
duke@0 1982
duke@0 1983 // Use a flow-free graph structure, to avoid creating excess control edges
duke@0 1984 // which could hinder other optimizations.
duke@0 1985 // Since Math.min/max is often used with arraycopy, we want
duke@0 1986 // tightly_coupled_allocation to be able to see beyond min/max expressions.
duke@0 1987 Node* cmov = CMoveNode::make(C, NULL, best_bol,
duke@0 1988 answer_if_false, answer_if_true,
duke@0 1989 TypeInt::make(lo, hi, widen));
duke@0 1990
duke@0 1991 return _gvn.transform(cmov);
duke@0 1992
duke@0 1993 /*
duke@0 1994 // This is not as desirable as it may seem, since Min and Max
duke@0 1995 // nodes do not have a full set of optimizations.
duke@0 1996 // And they would interfere, anyway, with 'if' optimizations
duke@0 1997 // and with CMoveI canonical forms.
duke@0 1998 switch (id) {
duke@0 1999 case vmIntrinsics::_min:
duke@0 2000 result_val = _gvn.transform(new (C, 3) MinINode(x,y)); break;
duke@0 2001 case vmIntrinsics::_max:
duke@0 2002 result_val = _gvn.transform(new (C, 3) MaxINode(x,y)); break;
duke@0 2003 default:
duke@0 2004 ShouldNotReachHere();
duke@0 2005 }
duke@0 2006 */
duke@0 2007 }
duke@0 2008
duke@0 2009 inline int
duke@0 2010 LibraryCallKit::classify_unsafe_addr(Node* &base, Node* &offset) {
duke@0 2011 const TypePtr* base_type = TypePtr::NULL_PTR;
duke@0 2012 if (base != NULL) base_type = _gvn.type(base)->isa_ptr();
duke@0 2013 if (base_type == NULL) {
duke@0 2014 // Unknown type.
duke@0 2015 return Type::AnyPtr;
duke@0 2016 } else if (base_type == TypePtr::NULL_PTR) {
duke@0 2017 // Since this is a NULL+long form, we have to switch to a rawptr.
duke@0 2018 base = _gvn.transform( new (C, 2) CastX2PNode(offset) );
duke@0 2019 offset = MakeConX(0);
duke@0 2020 return Type::RawPtr;
duke@0 2021 } else if (base_type->base() == Type::RawPtr) {
duke@0 2022 return Type::RawPtr;
duke@0 2023 } else if (base_type->isa_oopptr()) {
duke@0 2024 // Base is never null => always a heap address.
duke@0 2025 if (base_type->ptr() == TypePtr::NotNull) {
duke@0 2026 return Type::OopPtr;
duke@0 2027 }
duke@0 2028 // Offset is small => always a heap address.
duke@0 2029 const TypeX* offset_type = _gvn.type(offset)->isa_intptr_t();
duke@0 2030 if (offset_type != NULL &&
duke@0 2031 base_type->offset() == 0 && // (should always be?)
duke@0 2032 offset_type->_lo >= 0 &&
duke@0 2033 !MacroAssembler::needs_explicit_null_check(offset_type->_hi)) {
duke@0 2034 return Type::OopPtr;
duke@0 2035 }
duke@0 2036 // Otherwise, it might either be oop+off or NULL+addr.
duke@0 2037 return Type::AnyPtr;
duke@0 2038 } else {
duke@0 2039 // No information:
duke@0 2040 return Type::AnyPtr;
duke@0 2041 }
duke@0 2042 }
duke@0 2043
duke@0 2044 inline Node* LibraryCallKit::make_unsafe_address(Node* base, Node* offset) {
duke@0 2045 int kind = classify_unsafe_addr(base, offset);
duke@0 2046 if (kind == Type::RawPtr) {
duke@0 2047 return basic_plus_adr(top(), base, offset);
duke@0 2048 } else {
duke@0 2049 return basic_plus_adr(base, offset);
duke@0 2050 }
duke@0 2051 }
duke@0 2052
twisti@775 2053 //-------------------inline_numberOfLeadingZeros_int/long-----------------------
twisti@775 2054 // inline int Integer.numberOfLeadingZeros(int)
twisti@775 2055 // inline int Long.numberOfLeadingZeros(long)
twisti@775 2056 bool LibraryCallKit::inline_numberOfLeadingZeros(vmIntrinsics::ID id) {
twisti@775 2057 assert(id == vmIntrinsics::_numberOfLeadingZeros_i || id == vmIntrinsics::_numberOfLeadingZeros_l, "not numberOfLeadingZeros");
twisti@775 2058 if (id == vmIntrinsics::_numberOfLeadingZeros_i && !Matcher::match_rule_supported(Op_CountLeadingZerosI)) return false;
twisti@775 2059 if (id == vmIntrinsics::_numberOfLeadingZeros_l && !Matcher::match_rule_supported(Op_CountLeadingZerosL)) return false;
twisti@775 2060 _sp += arg_size(); // restore stack pointer
twisti@775 2061 switch (id) {
twisti@775 2062 case vmIntrinsics::_numberOfLeadingZeros_i:
twisti@775 2063 push(_gvn.transform(new (C, 2) CountLeadingZerosINode(pop())));
twisti@775 2064 break;
twisti@775 2065 case vmIntrinsics::_numberOfLeadingZeros_l:
twisti@775 2066 push(_gvn.transform(new (C, 2) CountLeadingZerosLNode(pop_pair())));
twisti@775 2067 break;
twisti@775 2068 default:
twisti@775 2069 ShouldNotReachHere();
twisti@775 2070 }
twisti@775 2071 return true;
twisti@775 2072 }
twisti@775 2073
twisti@775 2074 //-------------------inline_numberOfTrailingZeros_int/long----------------------
twisti@775 2075 // inline int Integer.numberOfTrailingZeros(int)
twisti@775 2076 // inline int Long.numberOfTrailingZeros(long)
twisti@775 2077 bool LibraryCallKit::inline_numberOfTrailingZeros(vmIntrinsics::ID id) {
twisti@775 2078 assert(id == vmIntrinsics::_numberOfTrailingZeros_i || id == vmIntrinsics::_numberOfTrailingZeros_l, "not numberOfTrailingZeros");
twisti@775 2079 if (id == vmIntrinsics::_numberOfTrailingZeros_i && !Matcher::match_rule_supported(Op_CountTrailingZerosI)) return false;
twisti@775 2080 if (id == vmIntrinsics::_numberOfTrailingZeros_l && !Matcher::match_rule_supported(Op_CountTrailingZerosL)) return false;
twisti@775 2081 _sp += arg_size(); // restore stack pointer
twisti@775 2082 switch (id) {
twisti@775 2083 case vmIntrinsics::_numberOfTrailingZeros_i:
twisti@775 2084 push(_gvn.transform(new (C, 2) CountTrailingZerosINode(pop())));
twisti@775 2085 break;
twisti@775 2086 case vmIntrinsics::_numberOfTrailingZeros_l:
twisti@775 2087 push(_gvn.transform(new (C, 2) CountTrailingZerosLNode(pop_pair())));
twisti@775 2088 break;
twisti@775 2089 default:
twisti@775 2090 ShouldNotReachHere();
twisti@775 2091 }
twisti@775 2092 return true;
twisti@775 2093 }
twisti@775 2094
twisti@643 2095 //----------------------------inline_bitCount_int/long-----------------------
twisti@643 2096 // inline int Integer.bitCount(int)
twisti@643 2097 // inline int Long.bitCount(long)
twisti@643 2098 bool LibraryCallKit::inline_bitCount(vmIntrinsics::ID id) {
twisti@643 2099 assert(id == vmIntrinsics::_bitCount_i || id == vmIntrinsics::_bitCount_l, "not bitCount");
twisti@643 2100 if (id == vmIntrinsics::_bitCount_i && !Matcher::has_match_rule(Op_PopCountI)) return false;
twisti@643 2101 if (id == vmIntrinsics::_bitCount_l && !Matcher::has_match_rule(Op_PopCountL)) return false;
twisti@643 2102 _sp += arg_size(); // restore stack pointer
twisti@643 2103 switch (id) {
twisti@643 2104 case vmIntrinsics::_bitCount_i:
twisti@643 2105 push(_gvn.transform(new (C, 2) PopCountINode(pop())));
twisti@643 2106 break;
twisti@643 2107 case vmIntrinsics::_bitCount_l:
twisti@643 2108 push(_gvn.transform(new (C, 2) PopCountLNode(pop_pair())));
twisti@643 2109 break;
twisti@643 2110 default:
twisti@643 2111 ShouldNotReachHere();
twisti@643 2112 }
twisti@643 2113 return true;
twisti@643 2114 }
twisti@643 2115
never@1396 2116 //----------------------------inline_reverseBytes_int/long/char/short-------------------
twisti@605 2117 // inline Integer.reverseBytes(int)
twisti@605 2118 // inline Long.reverseBytes(long)
never@1396 2119 // inline Character.reverseBytes(char)
never@1396 2120 // inline Short.reverseBytes(short)
duke@0 2121 bool LibraryCallKit::inline_reverseBytes(vmIntrinsics::ID id) {
never@1396 2122 assert(id == vmIntrinsics::_reverseBytes_i || id == vmIntrinsics::_reverseBytes_l ||
never@1396 2123 id == vmIntrinsics::_reverseBytes_c || id == vmIntrinsics::_reverseBytes_s,
never@1396 2124 "not reverse Bytes");
never@1396 2125 if (id == vmIntrinsics::_reverseBytes_i && !Matcher::has_match_rule(Op_ReverseBytesI)) return false;
never@1396 2126 if (id == vmIntrinsics::_reverseBytes_l && !Matcher::has_match_rule(Op_ReverseBytesL)) return false;
never@1396 2127 if (id == vmIntrinsics::_reverseBytes_c && !Matcher::has_match_rule(Op_ReverseBytesUS)) return false;
never@1396 2128 if (id == vmIntrinsics::_reverseBytes_s && !Matcher::has_match_rule(Op_ReverseBytesS)) return false;
duke@0 2129 _sp += arg_size(); // restore stack pointer
duke@0 2130 switch (id) {
duke@0 2131 case vmIntrinsics::_reverseBytes_i:
duke@0 2132 push(_gvn.transform(new (C, 2) ReverseBytesINode(0, pop())));
duke@0 2133 break;
duke@0 2134 case vmIntrinsics::_reverseBytes_l:
duke@0 2135 push_pair(_gvn.transform(new (C, 2) ReverseBytesLNode(0, pop_pair())));
duke@0 2136 break;
never@1396 2137 case vmIntrinsics::_reverseBytes_c:
never@1396 2138 push(_gvn.transform(new (C, 2) ReverseBytesUSNode(0, pop())));
never@1396 2139 break;
never@1396 2140 case vmIntrinsics::_reverseBytes_s:
never@1396 2141 push(_gvn.transform(new (C, 2) ReverseBytesSNode(0, pop())));
never@1396 2142 break;
duke@0 2143 default:
duke@0 2144 ;
duke@0 2145 }
duke@0 2146 return true;
duke@0 2147 }
duke@0 2148
duke@0 2149 //----------------------------inline_unsafe_access----------------------------
duke@0 2150
duke@0 2151 const static BasicType T_ADDRESS_HOLDER = T_LONG;
duke@0 2152
johnc@2346 2153 // Helper that guards and inserts a G1 pre-barrier.
johnc@2346 2154 void LibraryCallKit::insert_g1_pre_barrier(Node* base_oop, Node* offset, Node* pre_val) {
johnc@2346 2155 assert(UseG1GC, "should not call this otherwise");
johnc@2346 2156
johnc@2346 2157 // We could be accessing the referent field of a reference object. If so, when G1
johnc@2346 2158 // is enabled, we need to log the value in the referent field in an SATB buffer.
johnc@2346 2159 // This routine performs some compile time filters and generates suitable
johnc@2346 2160 // runtime filters that guard the pre-barrier code.
johnc@2346 2161
johnc@2346 2162 // Some compile time checks.
johnc@2346 2163
johnc@2346 2164 // If offset is a constant, is it java_lang_ref_Reference::_reference_offset?
johnc@2346 2165 const TypeX* otype = offset->find_intptr_t_type();
johnc@2346 2166 if (otype != NULL && otype->is_con() &&
johnc@2346 2167 otype->get_con() != java_lang_ref_Reference::referent_offset) {
johnc@2346 2168 // Constant offset but not the reference_offset so just return
johnc@2346 2169 return;
johnc@2346 2170 }
johnc@2346 2171
johnc@2346 2172 // We only need to generate the runtime guards for instances.
johnc@2346 2173 const TypeOopPtr* btype = base_oop->bottom_type()->isa_oopptr();
johnc@2346 2174 if (btype != NULL) {
johnc@2346 2175 if (btype->isa_aryptr()) {
johnc@2346 2176 // Array type so nothing to do
johnc@2346 2177 return;
johnc@2346 2178 }
johnc@2346 2179
johnc@2346 2180 const TypeInstPtr* itype = btype->isa_instptr();
johnc@2346 2181 if (itype != NULL) {
johnc@2346 2182 // Can the klass of base_oop be statically determined
johnc@2346 2183 // to be _not_ a sub-class of Reference?
johnc@2346 2184 ciKlass* klass = itype->klass();
johnc@2346 2185 if (klass->is_subtype_of(env()->Reference_klass()) &&
johnc@2346 2186 !env()->Reference_klass()->is_subtype_of(klass)) {
johnc@2346 2187 return;
johnc@2346 2188 }
johnc@2346 2189 }
johnc@2346 2190 }
johnc@2346 2191
johnc@2346 2192 // The compile time filters did not reject base_oop/offset so
johnc@2346 2193 // we need to generate the following runtime filters
johnc@2346 2194 //
johnc@2346 2195 // if (offset == java_lang_ref_Reference::_reference_offset) {
johnc@2346 2196 // if (base != null) {
jiangli@3091 2197 // if (instance_of(base, java.lang.ref.Reference)) {
johnc@2346 2198 // pre_barrier(_, pre_val, ...);
johnc@2346 2199 // }
johnc@2346 2200 // }
johnc@2346 2201 // }
johnc@2346 2202
johnc@2346 2203 float likely = PROB_LIKELY(0.999);
johnc@2346 2204 float unlikely = PROB_UNLIKELY(0.999);
johnc@2346 2205
johnc@2352 2206 IdealKit ideal(this);
johnc@2346 2207 #define __ ideal.
johnc@2346 2208
johnc@2351 2209 Node* referent_off = __ ConX(java_lang_ref_Reference::referent_offset);
johnc@2346 2210
johnc@2346 2211 __ if_then(offset, BoolTest::eq, referent_off, unlikely); {
johnc@2346 2212 __ if_then(base_oop, BoolTest::ne, null(), likely); {
johnc@2346 2213
johnc@2346 2214 // Update graphKit memory and control from IdealKit.
johnc@2352 2215 sync_kit(ideal);
johnc@2346 2216
johnc@2346 2217 Node* ref_klass_con = makecon(TypeKlassPtr::make(env()->Reference_klass()));
johnc@2346 2218 Node* is_instof = gen_instanceof(base_oop, ref_klass_con);
johnc@2346 2219
johnc@2346 2220 // Update IdealKit memory and control from graphKit.
johnc@2352 2221 __ sync_kit(this);
johnc@2346 2222
johnc@2346 2223 Node* one = __ ConI(1);
johnc@2346 2224
johnc@2346 2225 __ if_then(is_instof, BoolTest::eq, one, unlikely); {
johnc@2346 2226
johnc@2346 2227 // Update graphKit from IdeakKit.
johnc@2352 2228 sync_kit(ideal);
johnc@2346 2229
johnc@2346 2230 // Use the pre-barrier to record the value in the referent field
johnc@2346 2231 pre_barrier(false /* do_load */,
johnc@2346 2232 __ ctrl(),
johnc@2355 2233 NULL /* obj */, NULL /* adr */, max_juint /* alias_idx */, NULL /* val */, NULL /* val_type */,
johnc@2346 2234 pre_val /* pre_val */,
johnc@2346 2235 T_OBJECT);
johnc@2346 2236
johnc@2346 2237 // Update IdealKit from graphKit.
johnc@2352 2238 __ sync_kit(this);
johnc@2346 2239
johnc@2346 2240 } __ end_if(); // _ref_type != ref_none
johnc@2346 2241 } __ end_if(); // base != NULL
johnc@2346 2242 } __ end_if(); // offset == referent_offset
johnc@2346 2243
johnc@2346 2244 // Final sync IdealKit and GraphKit.
johnc@2352 2245 final_sync(ideal);
johnc@2346 2246 #undef __
johnc@2346 2247 }
johnc@2346 2248
johnc@2346 2249
duke@0 2250 // Interpret Unsafe.fieldOffset cookies correctly:
duke@0 2251 extern jlong Unsafe_field_offset_to_byte_offset(jlong field_offset);
duke@0 2252
duke@0 2253 bool LibraryCallKit::inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile) {
duke@0 2254 if (callee()->is_static()) return false; // caller must have the capability!
duke@0 2255
duke@0 2256 #ifndef PRODUCT
duke@0 2257 {
duke@0 2258 ResourceMark rm;
duke@0 2259 // Check the signatures.
duke@0 2260 ciSignature* sig = signature();
duke@0 2261 #ifdef ASSERT
duke@0 2262 if (!is_store) {
duke@0 2263 // Object getObject(Object base, int/long offset), etc.
duke@0 2264 BasicType rtype = sig->return_type()->basic_type();
duke@0 2265 if (rtype == T_ADDRESS_HOLDER && callee()->name() == ciSymbol::getAddress_name())
duke@0 2266 rtype = T_ADDRESS; // it is really a C void*
duke@0 2267 assert(rtype == type, "getter must return the expected value");
duke@0 2268 if (!is_native_ptr) {
duke@0 2269 assert(sig->count() == 2, "oop getter has 2 arguments");
duke@0 2270 assert(sig->type_at(0)->basic_type() == T_OBJECT, "getter base is object");
duke@0 2271 assert(sig->type_at(1)->basic_type() == T_LONG, "getter offset is correct");
duke@0 2272 } else {
duke@0 2273 assert(sig->count() == 1, "native getter has 1 argument");
duke@0 2274 assert(sig->type_at(0)->basic_type() == T_LONG, "getter base is long");
duke@0 2275 }
duke@0 2276 } else {
duke@0 2277 // void putObject(Object base, int/long offset, Object x), etc.
duke@0 2278 assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value");
duke@0 2279 if (!is_native_ptr) {
duke@0 2280 assert(sig->count() == 3, "oop putter has 3 arguments");
duke@0 2281 assert(sig->type_at(0)->basic_type() == T_OBJECT, "putter base is object");
duke@0 2282 assert(sig->type_at(1)->basic_type() == T_LONG, "putter offset is correct");
duke@0 2283 } else {
duke@0 2284 assert(sig->count() == 2, "native putter has 2 arguments");
duke@0 2285 assert(sig->type_at(0)->basic_type() == T_LONG, "putter base is long");
duke@0 2286 }
duke@0 2287 BasicType vtype = sig->type_at(sig->count()-1)->basic_type();
duke@0 2288 if (vtype == T_ADDRESS_HOLDER && callee()->name() == ciSymbol::putAddress_name())
duke@0 2289 vtype = T_ADDRESS; // it is really a C void*
duke@0 2290 assert(vtype == type, "putter must accept the expected value");
duke@0 2291 }
duke@0 2292 #endif // ASSERT
duke@0 2293 }
duke@0 2294 #endif //PRODUCT
duke@0 2295
duke@0 2296 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
duke@0 2297
duke@0 2298 int type_words = type2size[ (type == T_ADDRESS) ? T_LONG : type ];
duke@0 2299
duke@0 2300 // Argument words: "this" plus (oop/offset) or (lo/hi) args plus maybe 1 or 2 value words
duke@0 2301 int nargs = 1 + (is_native_ptr ? 2 : 3) + (is_store ? type_words : 0);
duke@0 2302
duke@0 2303 debug_only(int saved_sp = _sp);
duke@0 2304 _sp += nargs;
duke@0 2305
duke@0 2306 Node* val;
duke@0 2307 debug_only(val = (Node*)(uintptr_t)-1);
duke@0 2308
duke@0 2309
duke@0 2310 if (is_store) {
duke@0 2311 // Get the value being stored. (Pop it first; it was pushed last.)
duke@0 2312 switch (type) {
duke@0 2313 case T_DOUBLE:
duke@0 2314 case T_LONG:
duke@0 2315 case T_ADDRESS:
duke@0 2316 val = pop_pair();
duke@0 2317 break;
duke@0 2318 default:
duke@0 2319 val = pop();
duke@0 2320 }
duke@0 2321 }
duke@0 2322
duke@0 2323 // Build address expression. See the code in inline_unsafe_prefetch.
duke@0 2324 Node *adr;
duke@0 2325 Node *heap_base_oop = top();
johnc@2346 2326 Node* offset = top();
johnc@2346 2327
duke@0 2328 if (!is_native_ptr) {
duke@0 2329 // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset
johnc@2346 2330 offset = pop_pair();
duke@0 2331 // The base is either a Java object or a value produced by Unsafe.staticFieldBase
duke@0 2332 Node* base = pop();
duke@0 2333 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
duke@0 2334 // to be plain byte offsets, which are also the same as those accepted
duke@0 2335 // by oopDesc::field_base.
duke@0 2336 assert(Unsafe_field_offset_to_byte_offset(11) == 11,
duke@0 2337 "fieldOffset must be byte-scaled");
duke@0 2338 // 32-bit machines ignore the high half!
duke@0 2339 offset = ConvL2X(offset);
duke@0 2340 adr = make_unsafe_address(base, offset);
duke@0 2341 heap_base_oop = base;
duke@0 2342 } else {
duke@0 2343 Node* ptr = pop_pair();
duke@0 2344 // Adjust Java long to machine word:
duke@0 2345 ptr = ConvL2X(ptr);
duke@0 2346 adr = make_unsafe_address(NULL, ptr);
duke@0 2347 }
duke@0 2348
duke@0 2349 // Pop receiver last: it was pushed first.
duke@0 2350 Node *receiver = pop();
duke@0 2351
duke@0 2352 assert(saved_sp == _sp, "must have correct argument count");
duke@0 2353
duke@0 2354 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
duke@0 2355
duke@0 2356 // First guess at the value type.
duke@0 2357 const Type *value_type = Type::get_const_basic_type(type);
duke@0 2358
duke@0 2359 // Try to categorize the address. If it comes up as TypeJavaPtr::BOTTOM,
duke@0 2360 // there was not enough information to nail it down.
duke@0 2361 Compile::AliasType* alias_type = C->alias_type(adr_type);
duke@0 2362 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
duke@0 2363
duke@0 2364 // We will need memory barriers unless we can determine a unique
duke@0 2365 // alias category for this reference. (Note: If for some reason
duke@0 2366 // the barriers get omitted and the unsafe reference begins to "pollute"
duke@0 2367 // the alias analysis of the rest of the graph, either Compile::can_alias
duke@0 2368 // or Compile::must_alias will throw a diagnostic assert.)
duke@0 2369 bool need_mem_bar = (alias_type->adr_type() == TypeOopPtr::BOTTOM);
duke@0 2370
johnc@2346 2371 // If we are reading the value of the referent field of a Reference
johnc@2346 2372 // object (either by using Unsafe directly or through reflection)
johnc@2346 2373 // then, if G1 is enabled, we need to record the referent in an
johnc@2346 2374 // SATB log buffer using the pre-barrier mechanism.
johnc@2346 2375 bool need_read_barrier = UseG1GC && !is_native_ptr && !is_store &&
johnc@2346 2376 offset != top() && heap_base_oop != top();
johnc@2346 2377
duke@0 2378 if (!is_store && type == T_OBJECT) {
duke@0 2379 // Attempt to infer a sharper value type from the offset and base type.
duke@0 2380 ciKlass* sharpened_klass = NULL;
duke@0 2381
duke@0 2382 // See if it is an instance field, with an object type.
duke@0 2383 if (alias_type->field() != NULL) {
duke@0 2384 assert(!is_native_ptr, "native pointer op cannot use a java address");
duke@0 2385 if (alias_type->field()->type()->is_klass()) {
duke@0 2386 sharpened_klass = alias_type->field()->type()->as_klass();
duke@0 2387 }
duke@0 2388 }
duke@0 2389
duke@0 2390 // See if it is a narrow oop array.
duke@0 2391 if (adr_type->isa_aryptr()) {
twisti@895 2392 if (adr_type->offset() >= objArrayOopDesc::base_offset_in_bytes()) {
duke@0 2393 const TypeOopPtr *elem_type = adr_type->is_aryptr()->elem()->isa_oopptr();
duke@0 2394 if (elem_type != NULL) {
duke@0 2395 sharpened_klass = elem_type->klass();
duke@0 2396 }
duke@0 2397 }
duke@0 2398 }
duke@0 2399
duke@0 2400 if (sharpened_klass != NULL) {
duke@0 2401 const TypeOopPtr* tjp = TypeOopPtr::make_from_klass(sharpened_klass);
duke@0 2402
duke@0 2403 // Sharpen the value type.
duke@0 2404 value_type = tjp;
duke@0 2405
duke@0 2406 #ifndef PRODUCT
duke@0 2407 if (PrintIntrinsics || PrintInlining || PrintOptoInlining) {
duke@0 2408 tty->print(" from base type: "); adr_type->dump();
duke@0 2409 tty->print(" sharpened value: "); value_type->dump();
duke@0 2410 }
duke@0 2411 #endif
duke@0 2412 }
duke@0 2413 }
duke@0 2414
duke@0 2415 // Null check on self without removing any arguments. The argument
duke@0 2416 // null check technically happens in the wrong place, which can lead to
duke@0 2417 // invalid stack traces when the primitive is inlined into a method
duke@0 2418 // which handles NullPointerExceptions.
duke@0 2419 _sp += nargs;
duke@0 2420 do_null_check(receiver, T_OBJECT);
duke@0 2421 _sp -= nargs;
duke@0 2422 if (stopped()) {
duke@0 2423 return true;
duke@0 2424 }
duke@0 2425 // Heap pointers get a null-check from the interpreter,
duke@0 2426 // as a courtesy. However, this is not guaranteed by Unsafe,
duke@0 2427 // and it is not possible to fully distinguish unintended nulls
duke@0 2428 // from intended ones in this API.
duke@0 2429
duke@0 2430 if (is_volatile) {
duke@0 2431 // We need to emit leading and trailing CPU membars (see below) in
duke@0 2432 // addition to memory membars when is_volatile. This is a little
duke@0 2433 // too strong, but avoids the need to insert per-alias-type
duke@0 2434 // volatile membars (for stores; compare Parse::do_put_xxx), which
twisti@605 2435 // we cannot do effectively here because we probably only have a
duke@0 2436 // rough approximation of type.
duke@0 2437 need_mem_bar = true;
duke@0 2438 // For Stores, place a memory ordering barrier now.
duke@0 2439 if (is_store)
duke@0 2440 insert_mem_bar(Op_MemBarRelease);
duke@0 2441 }
duke@0 2442
duke@0 2443 // Memory barrier to prevent normal and 'unsafe' accesses from
duke@0 2444 // bypassing each other. Happens after null checks, so the
duke@0 2445 // exception paths do not take memory state from the memory barrier,
duke@0 2446 // so there's no problems making a strong assert about mixing users
duke@0 2447 // of safe & unsafe memory. Otherwise fails in a CTW of rt.jar
duke@0 2448 // around 5701, class sun/reflect/UnsafeBooleanFieldAccessorImpl.
duke@0 2449 if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder);
duke@0 2450
duke@0 2451 if (!is_store) {
duke@0 2452 Node* p = make_load(control(), adr, value_type, type, adr_type, is_volatile);
duke@0 2453 // load value and push onto stack
duke@0 2454 switch (type) {
duke@0 2455 case T_BOOLEAN:
duke@0 2456 case T_CHAR:
duke@0 2457 case T_BYTE:
duke@0 2458 case T_SHORT:
duke@0 2459 case T_INT:
duke@0 2460 case T_FLOAT:
johnc@2346 2461 push(p);
johnc@2346 2462 break;
duke@0 2463 case T_OBJECT:
johnc@2346 2464 if (need_read_barrier) {
johnc@2346 2465 insert_g1_pre_barrier(heap_base_oop, offset, p);
johnc@2346 2466 }
johnc@2346 2467 push(p);
duke@0 2468 break;
duke@0 2469 case T_ADDRESS:
duke@0 2470 // Cast to an int type.
duke@0 2471 p = _gvn.transform( new (C, 2) CastP2XNode(NULL,p) );
duke@0 2472 p = ConvX2L(p);
duke@0 2473 push_pair(p);
duke@0 2474 break;
duke@0 2475 case T_DOUBLE:
duke@0 2476 case T_LONG:
duke@0 2477 push_pair( p );
duke@0 2478 break;
duke@0 2479 default: ShouldNotReachHere();
duke@0 2480 }
duke@0 2481 } else {
duke@0 2482 // place effect of store into memory
duke@0 2483 switch (type) {
duke@0 2484 case T_DOUBLE:
duke@0 2485 val = dstore_rounding(val);
duke@0 2486 break;
duke@0 2487 case T_ADDRESS:
duke@0 2488 // Repackage the long as a pointer.
duke@0 2489 val = ConvL2X(val);
duke@0 2490 val = _gvn.transform( new (C, 2) CastX2PNode(val) );
duke@0 2491 break;
duke@0 2492 }
duke@0 2493
duke@0 2494 if (type != T_OBJECT ) {
duke@0 2495 (void) store_to_memory(control(), adr, val, type, adr_type, is_volatile);
duke@0 2496 } else {
duke@0 2497 // Possibly an oop being stored to Java heap or native memory
duke@0 2498 if (!TypePtr::NULL_PTR->higher_equal(_gvn.type(heap_base_oop))) {
duke@0 2499 // oop to Java heap.
never@825 2500 (void) store_oop_to_unknown(control(), heap_base_oop, adr, adr_type, val, type);
duke@0 2501 } else {
duke@0 2502 // We can't tell at compile time if we are storing in the Java heap or outside
duke@0 2503 // of it. So we need to emit code to conditionally do the proper type of
duke@0 2504 // store.
duke@0 2505
kvn@2291 2506 IdealKit ideal(this);
kvn@851 2507 #define __ ideal.
duke@0 2508 // QQQ who knows what probability is here??
kvn@851 2509 __ if_then(heap_base_oop, BoolTest::ne, null(), PROB_UNLIKELY(0.999)); {
kvn@851 2510 // Sync IdealKit and graphKit.
kvn@2291 2511 sync_kit(ideal);
kvn@851 2512 Node* st = store_oop_to_unknown(control(), heap_base_oop, adr, adr_type, val, type);
kvn@851 2513 // Update IdealKit memory.
kvn@2291 2514 __ sync_kit(this);
kvn@851 2515 } __ else_(); {
kvn@851 2516 __ store(__ ctrl(), adr, val, type, alias_type->index(), is_volatile);
kvn@851 2517 } __ end_if();
kvn@851 2518 // Final sync IdealKit and GraphKit.
kvn@2291 2519 final_sync(ideal);
kvn@851 2520 #undef __
duke@0 2521 }
duke@0 2522 }
duke@0 2523 }
duke@0 2524
duke@0 2525 if (is_volatile) {
duke@0 2526 if (!is_store)
duke@0 2527 insert_mem_bar(Op_MemBarAcquire);
duke@0 2528 else
duke@0 2529 insert_mem_bar(Op_MemBarVolatile);
duke@0 2530 }
duke@0 2531
duke@0 2532 if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder);
duke@0 2533
duke@0 2534 return true;
duke@0 2535 }
duke@0 2536
duke@0 2537 //----------------------------inline_unsafe_prefetch----------------------------
duke@0 2538
duke@0 2539 bool LibraryCallKit::inline_unsafe_prefetch(bool is_native_ptr, bool is_store, bool is_static) {
duke@0 2540 #ifndef PRODUCT
duke@0 2541 {
duke@0 2542 ResourceMark rm;
duke@0 2543 // Check the signatures.
duke@0 2544 ciSignature* sig = signature();
duke@0 2545 #ifdef ASSERT
duke@0 2546 // Object getObject(Object base, int/long offset), etc.
duke@0 2547 BasicType rtype = sig->return_type()->basic_type();
duke@0 2548 if (!is_native_ptr) {
duke@0 2549 assert(sig->count() == 2, "oop prefetch has 2 arguments");
duke@0 2550 assert(sig->type_at(0)->basic_type() == T_OBJECT, "prefetch base is object");
duke@0 2551 assert(sig->type_at(1)->basic_type() == T_LONG, "prefetcha offset is correct");
duke@0 2552 } else {
duke@0 2553 assert(sig->count() == 1, "native prefetch has 1 argument");
duke@0 2554 assert(sig->type_at(0)->basic_type() == T_LONG, "prefetch base is long");
duke@0 2555 }
duke@0 2556 #endif // ASSERT
duke@0 2557 }
duke@0 2558 #endif // !PRODUCT
duke@0 2559
duke@0 2560 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
duke@0 2561
duke@0 2562 // Argument words: "this" if not static, plus (oop/offset) or (lo/hi) args
duke@0 2563 int nargs = (is_static ? 0 : 1) + (is_native_ptr ? 2 : 3);
duke@0 2564
duke@0 2565 debug_only(int saved_sp = _sp);
duke@0 2566 _sp += nargs;
duke@0 2567
duke@0 2568 // Build address expression. See the code in inline_unsafe_access.
duke@0 2569 Node *adr;
duke@0 2570 if (!is_native_ptr) {
duke@0 2571 // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset
duke@0 2572 Node* offset = pop_pair();
duke@0 2573 // The base is either a Java object or a value produced by Unsafe.staticFieldBase
duke@0 2574 Node* base = pop();
duke@0 2575 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
duke@0 2576 // to be plain byte offsets, which are also the same as those accepted
duke@0 2577 // by oopDesc::field_base.
duke@0 2578 assert(Unsafe_field_offset_to_byte_offset(11) == 11,
duke@0 2579 "fieldOffset must be byte-scaled");
duke@0 2580 // 32-bit machines ignore the high half!
duke@0 2581 offset = ConvL2X(offset);
duke@0 2582 adr = make_unsafe_address(base, offset);
duke@0 2583 } else {
duke@0 2584 Node* ptr = pop_pair();
duke@0 2585 // Adjust Java long to machine word:
duke@0 2586 ptr = ConvL2X(ptr);
duke@0 2587 adr = make_unsafe_address(NULL, ptr);
duke@0 2588 }
duke@0 2589
duke@0 2590 if (is_static) {
duke@0 2591 assert(saved_sp == _sp, "must have correct argument count");
duke@0 2592 } else {
duke@0 2593 // Pop receiver last: it was pushed first.
duke@0 2594 Node *receiver = pop();
duke@0 2595 assert(saved_sp == _sp, "must have correct argument count");
duke@0 2596
duke@0 2597 // Null check on self without removing any arguments. The argument
duke@0 2598 // null check technically happens in the wrong place, which can lead to
duke@0 2599 // invalid stack traces when the primitive is inlined into a method
duke@0 2600 // which handles NullPointerExceptions.
duke@0 2601 _sp += nargs;
duke@0 2602 do_null_check(receiver, T_OBJECT);
duke@0 2603 _sp -= nargs;
duke@0 2604 if (stopped()) {
duke@0 2605 return true;
duke@0 2606 }
duke@0 2607 }
duke@0 2608
duke@0 2609 // Generate the read or write prefetch
duke@0 2610 Node *prefetch;
duke@0 2611 if (is_store) {
duke@0 2612 prefetch = new (C, 3) PrefetchWriteNode(i_o(), adr);
duke@0 2613 } else {
duke@0 2614 prefetch = new (C, 3) PrefetchReadNode(i_o(), adr);
duke@0 2615 }
duke@0 2616 prefetch->init_req(0, control());
duke@0 2617 set_i_o(_gvn.transform(prefetch));
duke@0 2618
duke@0 2619 return true;
duke@0 2620 }
duke@0 2621
duke@0 2622 //----------------------------inline_unsafe_CAS----------------------------
duke@0 2623
duke@0 2624 bool LibraryCallKit::inline_unsafe_CAS(BasicType type) {
duke@0 2625 // This basic scheme here is the same as inline_unsafe_access, but
duke@0 2626 // differs in enough details that combining them would make the code
duke@0 2627 // overly confusing. (This is a true fact! I originally combined
duke@0 2628 // them, but even I was confused by it!) As much code/comments as
duke@0 2629 // possible are retained from inline_unsafe_access though to make
twisti@605 2630 // the correspondences clearer. - dl
duke@0 2631
duke@0 2632 if (callee()->is_static()) return false; // caller must have the capability!
duke@0 2633
duke@0 2634 #ifndef PRODUCT
duke@0 2635 {
duke@0 2636 ResourceMark rm;
duke@0 2637 // Check the signatures.
duke@0 2638 ciSignature* sig = signature();
duke@0 2639 #ifdef ASSERT
duke@0 2640 BasicType rtype = sig->return_type()->basic_type();
duke@0 2641 assert(rtype == T_BOOLEAN, "CAS must return boolean");
duke@0 2642 assert(sig->count() == 4, "CAS has 4 arguments");
duke@0 2643 assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object");
duke@0 2644 assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long");
duke@0 2645 #endif // ASSERT
duke@0 2646 }
duke@0 2647 #endif //PRODUCT
duke@0 2648
duke@0 2649 // number of stack slots per value argument (1 or 2)
duke@0 2650 int type_words = type2size[type];
duke@0 2651
duke@0 2652 // Cannot inline wide CAS on machines that don't support it natively
kvn@29 2653 if (type2aelembytes(type) > BytesPerInt && !VM_Version::supports_cx8())
duke@0 2654 return false;
duke@0 2655
duke@0 2656 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
duke@0 2657
duke@0 2658 // Argument words: "this" plus oop plus offset plus oldvalue plus newvalue;
duke@0 2659 int nargs = 1 + 1 + 2 + type_words + type_words;
duke@0 2660
duke@0 2661 // pop arguments: newval, oldval, offset, base, and receiver
duke@0 2662 debug_only(int saved_sp = _sp);
duke@0 2663 _sp += nargs;
duke@0 2664 Node* newval = (type_words == 1) ? pop() : pop_pair();
duke@0 2665 Node* oldval = (type_words == 1) ? pop() : pop_pair();
duke@0 2666 Node *offset = pop_pair();
duke@0 2667 Node *base = pop();
duke@0 2668 Node *receiver = pop();
duke@0 2669 assert(saved_sp == _sp, "must have correct argument count");
duke@0 2670
duke@0 2671 // Null check receiver.
duke@0 2672 _sp += nargs;
duke@0 2673 do_null_check(receiver, T_OBJECT);
duke@0 2674 _sp -= nargs;
duke@0 2675 if (stopped()) {
duke@0 2676 return true;
duke@0 2677 }
duke@0 2678
duke@0 2679 // Build field offset expression.
duke@0 2680 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
duke@0 2681 // to be plain byte offsets, which are also the same as those accepted
duke@0 2682 // by oopDesc::field_base.
duke@0 2683 assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled");
duke@0 2684 // 32-bit machines ignore the high half of long offsets
duke@0 2685 offset = ConvL2X(offset);
duke@0 2686 Node* adr = make_unsafe_address(base, offset);
duke@0 2687 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
duke@0 2688
duke@0 2689 // (Unlike inline_unsafe_access, there seems no point in trying
duke@0 2690 // to refine types. Just use the coarse types here.
duke@0 2691 const Type *value_type = Type::get_const_basic_type(type);
duke@0 2692 Compile::AliasType* alias_type = C->alias_type(adr_type);
duke@0 2693 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
duke@0 2694 int alias_idx = C->get_alias_index(adr_type);
duke@0 2695
duke@0 2696 // Memory-model-wise, a CAS acts like a little synchronized block,
twisti@605 2697 // so needs barriers on each side. These don't translate into
duke@0 2698 // actual barriers on most machines, but we still need rest of
duke@0 2699 // compiler to respect ordering.
duke@0 2700
duke@0 2701 insert_mem_bar(Op_MemBarRelease);
duke@0 2702 insert_mem_bar(Op_MemBarCPUOrder);
duke@0 2703
duke@0 2704 // 4984716: MemBars must be inserted before this
duke@0 2705 // memory node in order to avoid a false
duke@0 2706 // dependency which will confuse the scheduler.
duke@0 2707 Node *mem = memory(alias_idx);
duke@0 2708
duke@0 2709 // For now, we handle only those cases that actually exist: ints,
duke@0 2710 // longs, and Object. Adding others should be straightforward.
duke@0 2711 Node* cas;
duke@0 2712 switch(type) {
duke@0 2713 case T_INT:
duke@0 2714 cas = _gvn.transform(new (C, 5) CompareAndSwapINode(control(), mem, adr, newval, oldval));
duke@0 2715 break;
duke@0 2716 case T_LONG:
duke@0 2717 cas = _gvn.transform(new (C, 5) CompareAndSwapLNode(control(), mem, adr, newval, oldval));
duke@0 2718 break;
duke@0 2719 case T_OBJECT:
kvn@3086 2720 // Transformation of a value which could be NULL pointer (CastPP #NULL)
kvn@3086 2721 // could be delayed during Parse (for example, in adjust_map_after_if()).
kvn@3086 2722 // Execute transformation here to avoid barrier generation in such case.
kvn@3086 2723 if (_gvn.type(newval) == TypePtr::NULL_PTR)
kvn@3086 2724 newval = _gvn.makecon(TypePtr::NULL_PTR);
kvn@3086 2725
kvn@3086 2726 // Reference stores need a store barrier.
duke@0 2727 // (They don't if CAS fails, but it isn't worth checking.)
johnc@2346 2728 pre_barrier(true /* do_load*/,
johnc@2346 2729 control(), base, adr, alias_idx, newval, value_type->make_oopptr(),
johnc@2346 2730 NULL /* pre_val*/,
johnc@2346 2731 T_OBJECT);
coleenp@113 2732 #ifdef _LP64
kvn@163 2733 if (adr->bottom_type()->is_ptr_to_narrowoop()) {
kvn@221 2734 Node *newval_enc = _gvn.transform(new (C, 2) EncodePNode(newval, newval->bottom_type()->make_narrowoop()));
kvn@221 2735 Node *oldval_enc = _gvn.transform(new (C, 2) EncodePNode(oldval, oldval->bottom_type()->make_narrowoop()));
coleenp@113 2736 cas = _gvn.transform(new (C, 5) CompareAndSwapNNode(control(), mem, adr,
kvn@221 2737 newval_enc, oldval_enc));
coleenp@113 2738 } else
coleenp@113 2739 #endif
kvn@221 2740 {
kvn@221 2741 cas = _gvn.transform(new (C, 5) CompareAndSwapPNode(control(), mem, adr, newval, oldval));
kvn@221 2742 }
duke@0 2743 post_barrier(control(), cas, base, adr, alias_idx, newval, T_OBJECT, true);
duke@0 2744 break;
duke@0 2745 default:
duke@0 2746 ShouldNotReachHere();
duke@0 2747 break;
duke@0 2748 }
duke@0 2749
duke@0 2750 // SCMemProjNodes represent the memory state of CAS. Their main
duke@0 2751 // role is to prevent CAS nodes from being optimized away when their
duke@0 2752 // results aren't used.
duke@0 2753 Node* proj = _gvn.transform( new (C, 1) SCMemProjNode(cas));
duke@0 2754 set_memory(proj, alias_idx);
duke@0 2755
duke@0 2756 // Add the trailing membar surrounding the access
duke@0 2757 insert_mem_bar(Op_MemBarCPUOrder);
duke@0 2758 insert_mem_bar(Op_MemBarAcquire);
duke@0 2759
duke@0 2760 push(cas);
duke@0 2761 return true;
duke@0 2762 }
duke@0 2763
duke@0 2764 bool LibraryCallKit::inline_unsafe_ordered_store(BasicType type) {
duke@0 2765 // This is another variant of inline_unsafe_access, differing in
duke@0 2766 // that it always issues store-store ("release") barrier and ensures
duke@0 2767 // store-atomicity (which only matters for "long").
duke@0 2768
duke@0 2769 if (callee()->is_static()) return false; // caller must have the capability!
duke@0 2770
duke@0 2771 #ifndef PRODUCT
duke@0 2772 {
duke@0 2773 ResourceMark rm;
duke@0 2774 // Check the signatures.
duke@0 2775 ciSignature* sig = signature();
duke@0 2776 #ifdef ASSERT
duke@0 2777 BasicType rtype = sig->return_type()->basic_type();
duke@0 2778 assert(rtype == T_VOID, "must return void");
duke@0 2779 assert(sig->count() == 3, "has 3 arguments");
duke@0 2780 assert(sig->type_at(0)->basic_type() == T_OBJECT, "base is object");
duke@0 2781 assert(sig->type_at(1)->basic_type() == T_LONG, "offset is long");
duke@0 2782 #endif // ASSERT
duke@0 2783 }
duke@0 2784 #endif //PRODUCT
duke@0 2785
duke@0 2786 // number of stack slots per value argument (1 or 2)
duke@0 2787 int type_words = type2size[type];
duke@0 2788
duke@0 2789 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
duke@0 2790
duke@0 2791 // Argument words: "this" plus oop plus offset plus value;
duke@0 2792 int nargs = 1 + 1 + 2 + type_words;
duke@0 2793
duke@0 2794 // pop arguments: val, offset, base, and receiver
duke@0 2795 debug_only(int saved_sp = _sp);
duke@0 2796 _sp += nargs;
duke@0 2797 Node* val = (type_words == 1) ? pop() : pop_pair();
duke@0 2798 Node *offset = pop_pair();
duke@0 2799 Node *base = pop();
duke@0 2800 Node *receiver = pop();
duke@0 2801 assert(saved_sp == _sp, "must have correct argument count");
duke@0 2802
duke@0 2803 // Null check receiver.
duke@0 2804 _sp += nargs;
duke@0 2805 do_null_check(receiver, T_OBJECT);
duke@0 2806 _sp -= nargs;
duke@0 2807 if (stopped()) {
duke@0 2808 return true;
duke@0 2809 }
duke@0 2810
duke@0 2811 // Build field offset expression.
duke@0 2812 assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled");
duke@0 2813 // 32-bit machines ignore the high half of long offsets
duke@0 2814 offset = ConvL2X(offset);
duke@0 2815 Node* adr = make_unsafe_address(base, offset);
duke@0 2816 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
duke@0 2817 const Type *value_type = Type::get_const_basic_type(type);
duke@0 2818 Compile::AliasType* alias_type = C->alias_type(adr_type);
duke@0 2819
duke@0 2820 insert_mem_bar(Op_MemBarRelease);
duke@0 2821 insert_mem_bar(Op_MemBarCPUOrder);
duke@0 2822 // Ensure that the store is atomic for longs:
duke@0 2823 bool require_atomic_access = true;
duke@0 2824 Node* store;
duke@0 2825 if (type == T_OBJECT) // reference stores need a store barrier.
never@825 2826 store = store_oop_to_unknown(control(), base, adr, adr_type, val, type);
duke@0 2827 else {
duke@0 2828 store = store_to_memory(control(), adr, val, type, adr_type, require_atomic_access);
duke@0 2829 }
duke@0 2830 insert_mem_bar(Op_MemBarCPUOrder);
duke@0 2831 return true;
duke@0 2832 }
duke@0 2833
duke@0 2834 bool LibraryCallKit::inline_unsafe_allocate() {
duke@0 2835 if (callee()->is_static()) return false; // caller must have the capability!
duke@0 2836 int nargs = 1 + 1;
duke@0 2837 assert(signature()->size() == nargs-1, "alloc has 1 argument");
duke@0 2838 null_check_receiver(callee()); // check then ignore argument(0)
duke@0 2839 _sp += nargs; // set original stack for use by uncommon_trap
duke@0 2840 Node* cls = do_null_check(argument(1), T_OBJECT);
duke@0 2841 _sp -= nargs;
duke@0 2842 if (stopped()) return true;
duke@0 2843
duke@0 2844 Node* kls = load_klass_from_mirror(cls, false, nargs, NULL, 0);
duke@0 2845 _sp += nargs; // set original stack for use by uncommon_trap
duke@0 2846 kls = do_null_check(kls, T_OBJECT);
duke@0 2847 _sp -= nargs;
duke@0 2848 if (stopped()) return true; // argument was like int.class
duke@0 2849
duke@0 2850 // Note: The argument might still be an illegal value like
duke@0 2851 // Serializable.class or Object[].class. The runtime will handle it.
duke@0 2852 // But we must make an explicit check for initialization.
stefank@2956 2853 Node* insp = basic_plus_adr(kls, in_bytes(instanceKlass::init_state_offset()));
coleenp@2933 2854 // Use T_BOOLEAN for instanceKlass::_init_state so the compiler
coleenp@2933 2855 // can generate code to load it as unsigned byte.
coleenp@2933 2856 Node* inst = make_load(NULL, insp, TypeInt::UBYTE, T_BOOLEAN);
duke@0 2857 Node* bits = intcon(instanceKlass::fully_initialized);
duke@0 2858 Node* test = _gvn.transform( new (C, 3) SubINode(inst, bits) );
duke@0 2859 // The 'test' is non-zero if we need to take a slow path.
duke@0 2860
duke@0 2861 Node* obj = new_instance(kls, test);
duke@0 2862 push(obj);
duke@0 2863
duke@0 2864 return true;
duke@0 2865 }
duke@0 2866
rbackman@3274 2867 #ifdef TRACE_HAVE_INTRINSICS
rbackman@3274 2868 /*
rbackman@3274 2869 * oop -> myklass
rbackman@3274 2870 * myklass->trace_id |= USED
rbackman@3274 2871 * return myklass->trace_id & ~0x3
rbackman@3274 2872 */
rbackman@3274 2873 bool LibraryCallKit::inline_native_classID() {
rbackman@3274 2874 int nargs = 1 + 1;
rbackman@3274 2875 null_check_receiver(callee()); // check then ignore argument(0)
rbackman@3274 2876 _sp += nargs;
rbackman@3274 2877 Node* cls = do_null_check(argument(1), T_OBJECT);
rbackman@3274 2878 _sp -= nargs;
rbackman@3274 2879 Node* kls = load_klass_from_mirror(cls, false, nargs, NULL, 0);
rbackman@3274 2880 _sp += nargs;
rbackman@3274 2881 kls = do_null_check(kls, T_OBJECT);
rbackman@3274 2882 _sp -= nargs;
rbackman@3274 2883 ByteSize offset = TRACE_ID_OFFSET;
rbackman@3274 2884 Node* insp = basic_plus_adr(kls, in_bytes(offset));
rbackman@3274 2885 Node* tvalue = make_load(NULL, insp, TypeLong::LONG, T_LONG);
rbackman@3274 2886 Node* bits = longcon(~0x03l); // ignore bit 0 & 1
rbackman@3274 2887 Node* andl = _gvn.transform(new (C, 3) AndLNode(tvalue, bits));
rbackman@3274 2888 Node* clsused = longcon(0x01l); // set the class bit
rbackman@3274 2889 Node* orl = _gvn.transform(new (C, 3) OrLNode(tvalue, clsused));
rbackman@3274 2890
rbackman@3274 2891 const TypePtr *adr_type = _gvn.type(insp)->isa_ptr();
rbackman@3274 2892 store_to_memory(control(), insp, orl, T_LONG, adr_type);
rbackman@3274 2893 push_pair(andl);
rbackman@3274 2894 return true;
rbackman@3274 2895 }
rbackman@3274 2896
rbackman@3274 2897 bool LibraryCallKit::inline_native_threadID() {
rbackman@3274 2898 Node* tls_ptr = NULL;
rbackman@3274 2899 Node* cur_thr = generate_current_thread(tls_ptr);
rbackman@3274 2900 Node* p = basic_plus_adr(top()/*!oop*/, tls_ptr, in_bytes(JavaThread::osthread_offset()));
rbackman@3274 2901 Node* osthread = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS);
rbackman@3274 2902 p = basic_plus_adr(top()/*!oop*/, osthread, in_bytes(OSThread::thread_id_offset()));
rbackman@3274 2903
rbackman@3274 2904 Node* threadid = NULL;
rbackman@3274 2905 size_t thread_id_size = OSThread::thread_id_size();
rbackman@3274 2906 if (thread_id_size == (size_t) BytesPerLong) {
rbackman@3274 2907 threadid = ConvL2I(make_load(control(), p, TypeLong::LONG, T_LONG));
rbackman@3274 2908 push(threadid);
rbackman@3274 2909 } else if (thread_id_size == (size_t) BytesPerInt) {
rbackman@3274 2910 threadid = make_load(control(), p, TypeInt::INT, T_INT);
rbackman@3274 2911 push(threadid);
rbackman@3274 2912 } else {
rbackman@3274 2913 ShouldNotReachHere();
rbackman@3274 2914 }
rbackman@3274 2915 return true;
rbackman@3274 2916 }
rbackman@3274 2917 #endif
rbackman@3274 2918
duke@0 2919 //------------------------inline_native_time_funcs--------------
duke@0 2920 // inline code for System.currentTimeMillis() and System.nanoTime()
duke@0 2921 // these have the same type and signature
rbackman@3274 2922 bool LibraryCallKit::inline_native_time_funcs(address funcAddr, const char* funcName) {
rbackman@3274 2923 const TypeFunc *tf = OptoRuntime::void_long_Type();
duke@0 2924 const TypePtr* no_memory_effects = NULL;
duke@0 2925 Node* time = make_runtime_call(RC_LEAF, tf, funcAddr, funcName, no_memory_effects);
duke@0 2926 Node* value = _gvn.transform(new (C, 1) ProjNode(time, TypeFunc::Parms+0));
duke@0 2927 #ifdef ASSERT
duke@0 2928 Node* value_top = _gvn.transform(new (C, 1) ProjNode(time, TypeFunc::Parms + 1));
duke@0 2929 assert(value_top == top(), "second value must be top");
duke@0 2930 #endif
duke@0 2931 push_pair(value);
duke@0 2932 return true;
duke@0 2933 }
duke@0 2934
duke@0 2935 //------------------------inline_native_currentThread------------------
duke@0 2936 bool LibraryCallKit::inline_native_currentThread() {
duke@0 2937 Node* junk = NULL;
duke@0 2938 push(generate_current_thread(junk));
duke@0 2939 return true;
duke@0 2940 }
duke@0 2941
duke@0 2942 //------------------------inline_native_isInterrupted------------------
duke@0 2943 bool LibraryCallKit::inline_native_isInterrupted() {
duke@0 2944 const int nargs = 1+1; // receiver + boolean
duke@0 2945 assert(nargs == arg_size(), "sanity");
duke@0 2946 // Add a fast path to t.isInterrupted(clear_int):
duke@0 2947 // (t == Thread.current() && (!TLS._osthread._interrupted || !clear_int))
duke@0 2948 // ? TLS._osthread._interrupted : /*slow path:*/ t.isInterrupted(clear_int)
duke@0 2949 // So, in the common case that the interrupt bit is false,
duke@0 2950 // we avoid making a call into the VM. Even if the interrupt bit
duke@0 2951 // is true, if the clear_int argument is false, we avoid the VM call.
duke@0 2952 // However, if the receiver is not currentThread, we must call the VM,
duke@0 2953 // because there must be some locking done around the operation.
duke@0 2954
duke@0 2955 // We only go to the fast case code if we pass two guards.
duke@0 2956 // Paths which do not pass are accumulated in the slow_region.
duke@0 2957 RegionNode* slow_region = new (C, 1) RegionNode(1);
duke@0 2958 record_for_igvn(slow_region);
duke@0 2959 RegionNode* result_rgn = new (C, 4) RegionNode(1+3); // fast1, fast2, slow
duke@0 2960 PhiNode* result_val = new (C, 4) PhiNode(result_rgn, TypeInt::BOOL);
duke@0 2961 enum { no_int_result_path = 1,
duke@0 2962 no_clear_result_path = 2,
duke@0 2963 slow_result_path = 3
duke@0 2964 };
duke@0 2965
duke@0 2966 // (a) Receiving thread must be the current thread.
duke@0 2967 Node* rec_thr = argument(0);
duke@0 2968 Node* tls_ptr = NULL;
duke@0 2969 Node* cur_thr = generate_current_thread(tls_ptr);
duke@0 2970 Node* cmp_thr = _gvn.transform( new (C, 3) CmpPNode(cur_thr, rec_thr) );
duke@0 2971 Node* bol_thr = _gvn.transform( new (C, 2) BoolNode(cmp_thr, BoolTest::ne) );
duke@0 2972
duke@0 2973 bool known_current_thread = (_gvn.type(bol_thr) == TypeInt::ZERO);
duke@0 2974 if (!known_current_thread)
duke@0 2975 generate_slow_guard(bol_thr, slow_region);
duke@0 2976
duke@0 2977 // (b) Interrupt bit on TLS must be false.
duke@0 2978 Node* p = basic_plus_adr(top()/*!oop*/, tls_ptr, in_bytes(JavaThread::osthread_offset()));
duke@0 2979 Node* osthread = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS);
duke@0 2980 p = basic_plus_adr(top()/*!oop*/, osthread, in_bytes(OSThread::interrupted_offset()));
kvn@787 2981 // Set the control input on the field _interrupted read to prevent it floating up.
kvn@787 2982 Node* int_bit = make_load(control(), p, TypeInt::BOOL, T_INT);
duke@0 2983 Node* cmp_bit = _gvn.transform( new (C, 3) CmpINode(int_bit, intcon(0)) );
duke@0 2984 Node* bol_bit = _gvn.transform( new (C, 2) BoolNode(cmp_bit, BoolTest::ne) );
duke@0 2985
duke@0 2986 IfNode* iff_bit = create_and_map_if(control(), bol_bit, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN);
duke@0 2987
duke@0 2988 // First fast path: if (!TLS._interrupted) return false;
duke@0 2989 Node* false_bit = _gvn.transform( new (C, 1) IfFalseNode(iff_bit) );
duke@0 2990 result_rgn->init_req(no_int_result_path, false_bit);
duke@0 2991 result_val->init_req(no_int_result_path, intcon(0));
duke@0 2992
duke@0 2993 // drop through to next case
duke@0 2994 set_control( _gvn.transform(new (C, 1) IfTrueNode(iff_bit)) );
duke@0 2995
duke@0 2996 // (c) Or, if interrupt bit is set and clear_int is false, use 2nd fast path.
duke@0 2997 Node* clr_arg = argument(1);
duke@0 2998 Node* cmp_arg = _gvn.transform( new (C, 3) CmpINode(clr_arg, intcon(0)) );
duke@0 2999 Node* bol_arg = _gvn.transform( new (C, 2) BoolNode(cmp_arg, BoolTest::ne) );
duke@0 3000 IfNode* iff_arg = create_and_map_if(control(), bol_arg, PROB_FAIR, COUNT_UNKNOWN);
duke@0 3001
duke@0 3002 // Second fast path: ... else if (!clear_int) return true;
duke@0 3003 Node* false_arg = _gvn.transform( new (C, 1) IfFalseNode(iff_arg) );
duke@0 3004 result_rgn->init_req(no_clear_result_path, false_arg);
duke@0 3005 result_val->init_req(no_clear_result_path, intcon(1));
duke@0 3006
duke@0 3007 // drop through to next case
duke@0 3008 set_control( _gvn.transform(new (C, 1) IfTrueNode(iff_arg)) );
duke@0 3009
duke@0 3010 // (d) Otherwise, go to the slow path.
duke@0 3011 slow_region->add_req(control());
duke@0 3012 set_control( _gvn.transform(slow_region) );
duke@0 3013
duke@0 3014 if (stopped()) {
duke@0 3015 // There is no slow path.
duke@0 3016 result_rgn->init_req(slow_result_path, top());
duke@0 3017 result_val->init_req(slow_result_path, top());
duke@0 3018 } else {
duke@0 3019 // non-virtual because it is a private non-static
duke@0 3020 CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_isInterrupted);
duke@0 3021
duke@0 3022 Node* slow_val = set_results_for_java_call(slow_call);
duke@0 3023 // this->control() comes from set_results_for_java_call
duke@0 3024
duke@0 3025 // If we know that the result of the slow call will be true, tell the optimizer!
duke@0 3026 if (known_current_thread) slow_val = intcon(1);
duke@0 3027
duke@0 3028 Node* fast_io = slow_call->in(TypeFunc::I_O);
duke@0 3029 Node* fast_mem = slow_call->in(TypeFunc::Memory);
duke@0 3030 // These two phis are pre-filled with copies of of the fast IO and Memory
duke@0 3031 Node* io_phi = PhiNode::make(result_rgn, fast_io, Type::ABIO);
duke@0 3032 Node* mem_phi = PhiNode::make(result_rgn, fast_mem, Type::MEMORY, TypePtr::BOTTOM);
duke@0 3033
duke@0 3034 result_rgn->init_req(slow_result_path, control());
duke@0 3035 io_phi ->init_req(slow_result_path, i_o());
duke@0 3036 mem_phi ->init_req(slow_result_path, reset_memory());
duke@0 3037 result_val->init_req(slow_result_path, slow_val);
duke@0 3038
duke@0 3039 set_all_memory( _gvn.transform(mem_phi) );
duke@0 3040 set_i_o( _gvn.transform(io_phi) );
duke@0 3041 }
duke@0 3042
duke@0 3043 push_result(result_rgn, result_val);
duke@0 3044 C->set_has_split_ifs(true); // Has chance for split-if optimization
duke@0 3045
duke@0 3046 return true;
duke@0 3047 }
duke@0 3048
duke@0 3049 //---------------------------load_mirror_from_klass----------------------------
duke@0 3050 // Given a klass oop, load its java mirror (a java.lang.Class oop).
duke@0 3051 Node* LibraryCallKit::load_mirror_from_klass(Node* klass) {
stefank@2956 3052 Node* p = basic_plus_adr(klass, in_bytes(Klass::java_mirror_offset()));
duke@0 3053 return make_load(NULL, p, TypeInstPtr::MIRROR, T_OBJECT);
duke@0 3054 }
duke@0 3055
duke@0 3056 //-----------------------load_klass_from_mirror_common-------------------------
duke@0 3057 // Given a java mirror (a java.lang.Class oop), load its corresponding klass oop.
duke@0 3058 // Test the klass oop for null (signifying a primitive Class like Integer.TYPE),
duke@0 3059 // and branch to the given path on the region.
duke@0 3060 // If never_see_null, take an uncommon trap on null, so we can optimistically
duke@0 3061 // compile for the non-null case.
duke@0 3062 // If the region is NULL, force never_see_null = true.
duke@0 3063 Node* LibraryCallKit::load_klass_from_mirror_common(Node* mirror,
duke@0 3064 bool never_see_null,
duke@0 3065 int nargs,
duke@0 3066 RegionNode* region,
duke@0 3067 int null_path,
duke@0 3068 int offset) {
duke@0 3069 if (region == NULL) never_see_null = true;
duke@0 3070 Node* p = basic_plus_adr(mirror, offset);
duke@0 3071 const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL;
kvn@164 3072 Node* kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type) );
duke@0 3073 _sp += nargs; // any deopt will start just before call to enclosing method
duke@0 3074 Node* null_ctl = top();
duke@0 3075 kls = null_check_oop(kls, &null_ctl, never_see_null);
duke@0 3076 if (region != NULL) {
duke@0 3077 // Set region->in(null_path) if the mirror is a primitive (e.g, int.class).
duke@0 3078 region->init_req(null_path, null_ctl);
duke@0 3079 } else {
duke@0 3080 assert(null_ctl == top(), "no loose ends");
duke@0 3081 }
duke@0 3082 _sp -= nargs;
duke@0 3083 return kls;
duke@0 3084 }
duke@0 3085
duke@0 3086 //--------------------(inline_native_Class_query helpers)---------------------
duke@0 3087 // Use this for JVM_ACC_INTERFACE, JVM_ACC_IS_CLONEABLE, JVM_ACC_HAS_FINALIZER.
duke@0 3088 // Fall through if (mods & mask) == bits, take the guard otherwise.
duke@0 3089 Node* LibraryCallKit::generate_access_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) {
duke@0 3090 // Branch around if the given klass has the given modifier bit set.
duke@0 3091 // Like generate_guard, adds a new path onto the region.
stefank@2956 3092 Node* modp = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset()));
duke@0 3093 Node* mods = make_load(NULL, modp, TypeInt::INT, T_INT);
duke@0 3094 Node* mask = intcon(modifier_mask);
duke@0 3095 Node* bits = intcon(modifier_bits);
duke@0 3096 Node* mbit = _gvn.transform( new (C, 3) AndINode(mods, mask) );
duke@0 3097 Node* cmp = _gvn.transform( new (C, 3) CmpINode(mbit, bits) );
duke@0 3098 Node* bol = _gvn.transform( new (C, 2) BoolNode(cmp, BoolTest::ne) );
duke@0 3099 return generate_fair_guard(bol, region);
duke@0 3100 }
duke@0 3101 Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) {
duke@0 3102 return generate_access_flags_guard(kls, JVM_ACC_INTERFACE, 0, region);
duke@0 3103 }
duke@0 3104
duke@0 3105 //-------------------------inline_native_Class_query-------------------
duke@0 3106 bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) {
duke@0 3107 int nargs = 1+0; // just the Class mirror, in most cases
duke@0 3108 const Type* return_type = TypeInt::BOOL;
duke@0 3109 Node* prim_return_value = top(); // what happens if it's a primitive class?
duke@0 3110 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
duke@0 3111 bool expect_prim = false; // most of these guys expect to work on refs
duke@0 3112
duke@0 3113 enum { _normal_path = 1, _prim_path = 2, PATH_LIMIT };
duke@0 3114
duke@0 3115 switch (id) {
duke@0 3116 case vmIntrinsics::_isInstance:
duke@0 3117 nargs = 1+1; // the Class mirror, plus the object getting queried about
duke@0 3118 // nothing is an instance of a primitive type
duke@0 3119 prim_return_value = intcon(0);
duke@0 3120 break;
duke@0 3121 case vmIntrinsics::_getModifiers:
duke@0 3122 prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC);
duke@0 3123 assert(is_power_of_2((int)JVM_ACC_WRITTEN_FLAGS+1), "change next line");
duke@0 3124 return_type = TypeInt::make(0, JVM_ACC_WRITTEN_FLAGS, Type::WidenMin);
duke@0 3125 break;
duke@0 3126 case vmIntrinsics::_isInterface:
duke@0 3127 prim_return_value = intcon(0);
duke@0 3128 break;
duke@0 3129 case vmIntrinsics::_isArray:
duke@0 3130 prim_return_value = intcon(0);
duke@0 3131 expect_prim = true; // cf. ObjectStreamClass.getClassSignature
duke@0 3132 break;
duke@0 3133 case vmIntrinsics::_isPrimitive:
duke@0 3134 prim_return_value = intcon(1);
duke@0 3135 expect_prim = true; // obviously
duke@0 3136 break;
duke@0 3137 case vmIntrinsics::_getSuperclass:
duke@0 3138 prim_return_value = null();
duke@0 3139 return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR);
duke@0 3140 break;
duke@0 3141 case vmIntrinsics::_getComponentType:
duke@0 3142 prim_return_value = null();
duke@0 3143 return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR);
duke@0 3144 break;
duke@0 3145 case vmIntrinsics::_getClassAccessFlags:
duke@0 3146 prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC);
duke@0 3147 return_type = TypeInt::INT; // not bool! 6297094
duke@0 3148 break;
duke@0 3149 default:
duke@0 3150 ShouldNotReachHere();
duke@0 3151 }
duke@0 3152
duke@0 3153 Node* mirror = argument(0);
duke@0 3154 Node* obj = (nargs <= 1)? top(): argument(1);
duke@0 3155
duke@0 3156 const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr();
duke@0 3157 if (mirror_con == NULL) return false; // cannot happen?
duke@0 3158
duke@0 3159 #ifndef PRODUCT
duke@0 3160 if (PrintIntrinsics || PrintInlining || PrintOptoInlining) {
duke@0 3161 ciType* k = mirror_con->java_mirror_type();
duke@0 3162 if (k) {
duke@0 3163 tty->print("Inlining %s on constant Class ", vmIntrinsics::name_at(intrinsic_id()));
duke@0 3164 k->print_name();
duke@0 3165 tty->cr();
duke@0 3166 }
duke@0 3167 }
duke@0 3168 #endif
duke@0 3169
duke@0 3170 // Null-check the mirror, and the mirror's klass ptr (in case it is a primitive).
duke@0 3171 RegionNode* region = new (C, PATH_LIMIT) RegionNode(PATH_LIMIT);
duke@0 3172 record_for_igvn(region);
duke@0 3173 PhiNode* phi = new (C, PATH_LIMIT) PhiNode(region, return_type);
duke@0 3174
duke@0 3175 // The mirror will never be null of Reflection.getClassAccessFlags, however
duke@0 3176 // it may be null for Class.isInstance or Class.getModifiers. Throw a NPE
duke@0 3177 // if it is. See bug 4774291.
duke@0 3178
duke@0 3179 // For Reflection.getClassAccessFlags(), the null check occurs in
duke@0 3180 // the wrong place; see inline_unsafe_access(), above, for a similar
duke@0 3181 // situation.
duke@0 3182 _sp += nargs; // set original stack for use by uncommon_trap
duke@0 3183 mirror = do_null_check(mirror, T_OBJECT);
duke@0 3184 _sp -= nargs;
duke@0 3185 // If mirror or obj is dead, only null-path is taken.
duke@0 3186 if (stopped()) return true;
duke@0 3187
duke@0 3188 if (expect_prim) never_see_null = false; // expect nulls (meaning prims)
duke@0 3189
duke@0 3190 // Now load the mirror's klass metaobject, and null-check it.
duke@0 3191 // Side-effects region with the control path if the klass is null.
duke@0 3192 Node* kls = load_klass_from_mirror(mirror, never_see_null, nargs,
duke@0 3193 region, _prim_path);
duke@0 3194 // If kls is null, we have a primitive mirror.
duke@0 3195 phi->init_req(_prim_path, prim_return_value);
duke@0 3196 if (stopped()) { push_result(region, phi); return true; }
duke@0 3197
duke@0 3198 Node* p; // handy temp
duke@0 3199 Node* null_ctl;
duke@0 3200
duke@0 3201 // Now that we have the non-null klass, we can perform the real query.
duke@0 3202 // For constant classes, the query will constant-fold in LoadNode::Value.
duke@0 3203 Node* query_value = top();
duke@0 3204 switch (id) {
duke@0 3205 case vmIntrinsics::_isInstance:
duke@0 3206 // nothing is an instance of a primitive type
jrose@1666 3207 _sp += nargs; // gen_instanceof might do an uncommon trap
duke@0 3208 query_value = gen_instanceof(obj, kls);
jrose@1666 3209 _sp -= nargs;
duke@0 3210 break;
duke@0 3211
duke@0 3212 case vmIntrinsics::_getModifiers:
stefank@2956 3213 p = basic_plus_adr(kls, in_bytes(Klass::modifier_flags_offset()));
duke@0 3214 query_value = make_load(NULL, p, TypeInt::INT, T_INT);
duke@0 3215 break;
duke@0 3216
duke@0 3217 case vmIntrinsics::_isInterface:
duke@0 3218 // (To verify this code sequence, check the asserts in JVM_IsInterface.)
duke@0 3219 if (generate_interface_guard(kls, region) != NULL)
duke@0 3220 // A guard was added. If the guard is taken, it was an interface.
duke@0 3221 phi->add_req(intcon(1));
duke@0 3222 // If we fall through, it's a plain class.
duke@0 3223 query_value = intcon(0);
duke@0 3224 break;
duke@0 3225
duke@0 3226 case vmIntrinsics::_isArray:
duke@0 3227 // (To verify this code sequence, check the asserts in JVM_IsArrayClass.)
duke@0 3228 if (generate_array_guard(kls, region) != NULL)
duke@0 3229 // A guard was added. If the guard is taken, it was an array.
duke@0 3230 phi->add_req(intcon(1));
duke@0 3231 // If we fall through, it's a plain class.
duke@0 3232 query_value = intcon(0);
duke@0 3233 break;
duke@0 3234
duke@0 3235 case vmIntrinsics::_isPrimitive:
duke@0 3236 query_value = intcon(0); // "normal" path produces false
duke@0 3237 break;
duke@0 3238
duke@0 3239 case vmIntrinsics::_getSuperclass:
duke@0 3240 // The rules here are somewhat unfortunate, but we can still do better
duke@0 3241 // with random logic than with a JNI call.
duke@0 3242 // Interfaces store null or Object as _super, but must report null.
duke@0 3243 // Arrays store an intermediate super as _super, but must report Object.
duke@0 3244 // Other types can report the actual _super.
duke@0 3245 // (To verify this code sequence, check the asserts in JVM_IsInterface.)
duke@0 3246 if (generate_interface_guard(kls, region) != NULL)
duke@0 3247 // A guard was added. If the guard is taken, it was an interface.
duke@0 3248 phi->add_req(null());
duke@0 3249 if (generate_array_guard(kls, region) != NULL)
duke@0 3250 // A guard was added. If the guard is taken, it was an array.
duke@0 3251 phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror())));
duke@0 3252 // If we fall through, it's a plain class. Get its _super.
stefank@2956 3253 p = basic_plus_adr(kls, in_bytes(Klass::super_offset()));
kvn@164 3254 kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeKlassPtr::OBJECT_OR_NULL) );
duke@0 3255 null_ctl = top();
duke@0 3256 kls = null_check_oop(kls, &null_ctl);
duke@0 3257 if (null_ctl != top()) {
duke@0 3258 // If the guard is taken, Object.superClass is null (both klass and mirror).
duke@0 3259 region->add_req(null_ctl);
duke@0 3260 phi ->add_req(null());
duke@0 3261 }
duke@0 3262 if (!stopped()) {
duke@0 3263 query_value = load_mirror_from_klass(kls);
duke@0 3264 }
duke@0 3265 break;
duke@0 3266
duke@0 3267 case vmIntrinsics::_getComponentType:
duke@0 3268 if (generate_array_guard(kls, region) != NULL) {
duke@0 3269 // Be sure to pin the oop load to the guard edge just created:
duke@0 3270 Node* is_array_ctrl = region->in(region->req()-1);
stefank@2956 3271 Node* cma = basic_plus_adr(kls, in_bytes(arrayKlass::component_mirror_offset()));
duke@0 3272 Node* cmo = make_load(is_array_ctrl, cma, TypeInstPtr::MIRROR, T_OBJECT);
duke@0 3273 phi->add_req(cmo);
duke@0 3274 }
duke@0 3275 query_value = null(); // non-array case is null
duke@0 3276 break;
duke@0 3277
duke@0 3278 case vmIntrinsics::_getClassAccessFlags:
stefank@2956 3279 p = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset()));
duke@0 3280 query_value = make_load(NULL, p, TypeInt::INT, T_INT);
duke@0 3281 break;
duke@0 3282
duke@0 3283 default:
duke@0 3284 ShouldNotReachHere();
duke@0 3285 }
duke@0 3286
duke@0 3287 // Fall-through is the normal case of a query to a real class.
duke@0 3288 phi->init_req(1, query_value);
duke@0 3289 region->init_req(1, control());
duke@0 3290
duke@0 3291 push_result(region, phi);
duke@0 3292 C->set_has_split_ifs(true); // Has chance for split-if optimization
duke@0 3293
duke@0 3294 return true;
duke@0 3295 }
duke@0 3296
duke@0 3297 //--------------------------inline_native_subtype_check------------------------
duke@0 3298 // This intrinsic takes the JNI calls out of the heart of
duke@0 3299 // UnsafeFieldAccessorImpl.set, which improves Field.set, readObject, etc.
duke@0 3300 bool LibraryCallKit::inline_native_subtype_check() {
duke@0 3301 int nargs = 1+1; // the Class mirror, plus the other class getting examined
duke@0 3302
duke@0 3303 // Pull both arguments off the stack.
duke@0 3304 Node* args[2]; // two java.lang.Class mirrors: superc, subc
duke@0 3305 args[0] = argument(0);
duke@0 3306 args[1] = argument(1);
duke@0 3307 Node* klasses[2]; // corresponding Klasses: superk, subk
duke@0 3308 klasses[0] = klasses[1] = top();
duke@0 3309
duke@0 3310 enum {
duke@0 3311 // A full decision tree on {superc is prim, subc is prim}:
duke@0 3312 _prim_0_path = 1, // {P,N} => false
duke@0 3313 // {P,P} & superc!=subc => false
duke@0 3314 _prim_same_path, // {P,P} & superc==subc => true
duke@0 3315 _prim_1_path, // {N,P} => false
duke@0 3316 _ref_subtype_path, // {N,N} & subtype check wins => true
duke@0 3317 _both_ref_path, // {N,N} & subtype check loses => false
duke@0 3318 PATH_LIMIT
duke@0 3319 };
duke@0 3320
duke@0 3321 RegionNode* region = new (C, PATH_LIMIT) RegionNode(PATH_LIMIT);
duke@0 3322 Node* phi = new (C, PATH_LIMIT) PhiNode(region, TypeInt::BOOL);
duke@0 3323 record_for_igvn(region);
duke@0 3324
duke@0 3325 const TypePtr* adr_type = TypeRawPtr::BOTTOM; // memory type of loads
duke@0 3326 const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL;
duke@0 3327 int class_klass_offset = java_lang_Class::klass_offset_in_bytes();
duke@0 3328
duke@0 3329 // First null-check both mirrors and load each mirror's klass metaobject.
duke@0 3330 int which_arg;
duke@0 3331 for (which_arg = 0; which_arg <= 1; which_arg++) {
duke@0 3332 Node* arg = args[which_arg];
duke@0 3333 _sp += nargs; // set original stack for use by uncommon_trap
duke@0 3334 arg = do_null_check(arg, T_OBJECT);
duke@0 3335 _sp -= nargs;
duke@0 3336 if (stopped()) break;
duke@0 3337 args[which_arg] = _gvn.transform(arg);
duke@0 3338
duke@0 3339 Node* p = basic_plus_adr(arg, class_klass_offset);
kvn@164 3340 Node* kls = LoadKlassNode::make(_gvn, immutable_memory(), p, adr_type, kls_type);
duke@0 3341 klasses[which_arg] = _gvn.transform(kls);
duke@0 3342 }
duke@0 3343
duke@0 3344 // Having loaded both klasses, test each for null.
duke@0 3345 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
duke@0 3346 for (which_arg = 0; which_arg <= 1; which_arg++) {
duke@0 3347 Node* kls = klasses[which_arg];
duke@0 3348 Node* null_ctl = top();
duke@0 3349 _sp += nargs; // set original stack for use by uncommon_trap
duke@0 3350 kls = null_check_oop(kls, &null_ctl, never_see_null);
duke@0 3351 _sp -= nargs;
duke@0 3352 int prim_path = (which_arg == 0 ? _prim_0_path : _prim_1_path);
duke@0 3353 region->init_req(prim_path, null_ctl);
duke@0 3354 if (stopped()) break;
duke@0 3355 klasses[which_arg] = kls;
duke@0 3356 }
duke@0 3357
duke@0 3358 if (!stopped()) {
duke@0 3359 // now we have two reference types, in klasses[0..1]
duke@0 3360 Node* subk = klasses[1]; // the argument to isAssignableFrom
duke@0 3361 Node* superk = klasses[0]; // the receiver
duke@0 3362 region->set_req(_both_ref_path, gen_subtype_check(subk, superk));
duke@0 3363 // now we have a successful reference subtype check
duke@0 3364 region->set_req(_ref_subtype_path, control());
duke@0 3365 }
duke@0 3366
duke@0 3367 // If both operands are primitive (both klasses null), then
duke@0 3368 // we must return true when they are identical primitives.
duke@0 3369 // It is convenient to test this after the first null klass check.
duke@0 3370 set_control(region->in(_prim_0_path)); // go back to first null check
duke@0 3371 if (!stopped()) {
duke@0 3372 // Since superc is primitive, make a guard for the superc==subc case.
duke@0 3373 Node* cmp_eq = _gvn.transform( new (C, 3) CmpPNode(args[0], args[1]) );
duke@0 3374 Node* bol_eq = _gvn.transform( new (C, 2) BoolNode(cmp_eq, BoolTest::eq) );
duke@0 3375 generate_guard(bol_eq, region, PROB_FAIR);
duke@0 3376 if (region->req() == PATH_LIMIT+1) {
duke@0 3377 // A guard was added. If the added guard is taken, superc==subc.
duke@0 3378 region->swap_edges(PATH_LIMIT, _prim_same_path);
duke@0 3379 region->del_req(PATH_LIMIT);
duke@0 3380 }
duke@0 3381 region->set_req(_prim_0_path, control()); // Not equal after all.
duke@0 3382 }
duke@0 3383
duke@0 3384 // these are the only paths that produce 'true':
duke@0 3385 phi->set_req(_prim_same_path, intcon(1));
duke@0 3386 phi->set_req(_ref_subtype_path, intcon(1));
duke@0 3387
duke@0 3388 // pull together the cases:
duke@0 3389 assert(region->req() == PATH_LIMIT, "sane region");
duke@0 3390 for (uint i = 1; i < region->req(); i++) {
duke@0 3391 Node* ctl = region->in(i);
duke@0 3392 if (ctl == NULL || ctl == top()) {
duke@0 3393 region->set_req(i, top());
duke@0 3394 phi ->set_req(i, top());
duke@0 3395 } else if (phi->in(i) == NULL) {
duke@0 3396 phi->set_req(i, intcon(0)); // all other paths produce 'false'
duke@0 3397 }
duke@0 3398 }
duke@0 3399
duke@0 3400 set_control(_gvn.transform(region));
duke@0 3401 push(_gvn.transform(phi));
duke@0 3402
duke@0 3403 return true;
duke@0 3404 }
duke@0 3405
duke@0 3406 //---------------------generate_array_guard_common------------------------
duke@0 3407 Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region,
duke@0 3408 bool obj_array, bool not_array) {
duke@0 3409 // If obj_array/non_array==false/false:
duke@0 3410 // Branch around if the given klass is in fact an array (either obj or prim).
duke@0 3411 // If obj_array/non_array==false/true:
duke@0 3412 // Branch around if the given klass is not an array klass of any kind.
duke@0 3413 // If obj_array/non_array==true/true:
duke@0 3414 // Branch around if the kls is not an oop array (kls is int[], String, etc.)
duke@0 3415 // If obj_array/non_array==true/false:
duke@0 3416 // Branch around if the kls is an oop array (Object[] or subtype)
duke@0 3417 //
duke@0 3418 // Like generate_guard, adds a new path onto the region.
duke@0 3419 jint layout_con = 0;
duke@0 3420 Node* layout_val = get_layout_helper(kls, layout_con);
duke@0 3421 if (layout_val == NULL) {
duke@0 3422 bool query = (obj_array
duke@0 3423 ? Klass::layout_helper_is_objArray(layout_con)
duke@0 3424 : Klass::layout_helper_is_javaArray(layout_con));
duke@0 3425 if (query == not_array) {
duke@0 3426 return NULL; // never a branch
duke@0 3427 } else { // always a branch
duke@0 3428 Node* always_branch = control();
duke@0 3429 if (region != NULL)
duke@0 3430 region->add_req(always_branch);
duke@0 3431 set_control(top());
duke@0 3432 return always_branch;
duke@0 3433 }
duke@0 3434 }
duke@0 3435 // Now test the correct condition.
duke@0 3436 jint nval = (obj_array
duke@0 3437 ? ((jint)Klass::_lh_array_tag_type_value
duke@0 3438 << Klass::_lh_array_tag_shift)
duke@0 3439 : Klass::_lh_neutral_value);
duke@0 3440 Node* cmp = _gvn.transform( new(C, 3) CmpINode(layout_val, intcon(nval)) );
duke@0 3441 BoolTest::mask btest = BoolTest::lt; // correct for testing is_[obj]array
duke@0 3442 // invert the test if we are looking for a non-array
duke@0 3443 if (not_array) btest = BoolTest(btest).negate();
duke@0 3444 Node* bol = _gvn.transform( new(C, 2) BoolNode(cmp, btest) );
duke@0 3445 return generate_fair_guard(bol, region);
duke@0 3446 }
duke@0 3447
duke@0 3448
duke@0 3449 //-----------------------inline_native_newArray--------------------------
duke@0 3450 bool LibraryCallKit::inline_native_newArray() {
duke@0 3451 int nargs = 2;
duke@0 3452 Node* mirror = argument(0);
duke@0 3453 Node* count_val = argument(1);
duke@0 3454
duke@0 3455 _sp += nargs; // set original stack for use by uncommon_trap
duke@0 3456 mirror = do_null_check(mirror, T_OBJECT);
duke@0 3457 _sp -= nargs;
kvn@163 3458 // If mirror or obj is dead, only null-path is taken.
kvn@163 3459 if (stopped()) return true;
duke@0 3460
duke@0 3461 enum { _normal_path = 1, _slow_path = 2, PATH_LIMIT };
duke@0 3462 RegionNode* result_reg = new(C, PATH_LIMIT) RegionNode(PATH_LIMIT);
duke@0 3463 PhiNode* result_val = new(C, PATH_LIMIT) PhiNode(result_reg,
duke@0 3464 TypeInstPtr::NOTNULL);
duke@0 3465 PhiNode* result_io = new(C, PATH_LIMIT) PhiNode(result_reg, Type::ABIO);
duke@0 3466 PhiNode* result_mem = new(C, PATH_LIMIT) PhiNode(result_reg, Type::MEMORY,
duke@0 3467 TypePtr::BOTTOM);
duke@0 3468
duke@0 3469 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
duke@0 3470 Node* klass_node = load_array_klass_from_mirror(mirror, never_see_null,
duke@0 3471 nargs,
duke@0 3472 result_reg, _slow_path);
duke@0 3473 Node* normal_ctl = control();
duke@0 3474 Node* no_array_ctl = result_reg->in(_slow_path);
duke@0 3475
duke@0 3476 // Generate code for the slow case. We make a call to newArray().
duke@0 3477 set_control(no_array_ctl);
duke@0 3478 if (!stopped()) {
duke@0 3479 // Either the input type is void.class, or else the
duke@0 3480 // array klass has not yet been cached. Either the
duke@0 3481 // ensuing call will throw an exception, or else it
duke@0 3482 // will cache the array klass for next time.
duke@0 3483 PreserveJVMState pjvms(this);
duke@0 3484 CallJavaNode* slow_call = generate_method_call_static(vmIntrinsics::_newArray);
duke@0 3485 Node* slow_result = set_results_for_java_call(slow_call);
duke@0 3486 // this->control() comes from set_results_for_java_call
duke@0 3487 result_reg->set_req(_slow_path, control());
duke@0 3488 result_val->set_req(_slow_path, slow_result);
duke@0 3489 result_io ->set_req(_slow_path, i_o());
duke@0 3490 result_mem->set_req(_slow_path, reset_memory());
duke@0 3491 }
duke@0 3492
duke@0 3493 set_control(normal_ctl);
duke@0 3494 if (!stopped()) {
duke@0 3495 // Normal case: The array type has been cached in the java.lang.Class.
duke@0 3496 // The following call works fine even if the array type is polymorphic.
duke@0 3497 // It could be a dynamic mix of int[], boolean[], Object[], etc.
cfang@730 3498 Node* obj = new_array(klass_node, count_val, nargs);
duke@0 3499 result_reg->init_req(_normal_path, control());
duke@0 3500 result_val->init_req(_normal_path, obj);
duke@0 3501 result_io ->init_req(_normal_path, i_o());
duke@0 3502 result_mem->init_req(_normal_path, reset_memory());
duke@0 3503 }
duke@0 3504
duke@0 3505 // Return the combined state.
duke@0 3506 set_i_o( _gvn.transform(result_io) );
duke@0 3507 set_all_memory( _gvn.transform(result_mem) );
duke@0 3508 push_result(result_reg, result_val);
duke@0 3509 C->set_has_split_ifs(true); // Has chance for split-if optimization
duke@0 3510
duke@0 3511 return true;
duke@0 3512 }
duke@0 3513
duke@0 3514 //----------------------inline_native_getLength--------------------------
duke@0 3515 bool LibraryCallKit::inline_native_getLength() {
duke@0 3516 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false;
duke@0 3517
duke@0 3518 int nargs = 1;
duke@0 3519 Node* array = argument(0);
duke@0 3520
duke@0 3521 _sp += nargs; // set original stack for use by uncommon_trap
duke@0 3522 array = do_null_check(array, T_OBJECT);
duke@0 3523 _sp -= nargs;
duke@0 3524
duke@0 3525 // If array is dead, only null-path is taken.
duke@0 3526 if (stopped()) return true;
duke@0 3527
duke@0 3528 // Deoptimize if it is a non-array.
duke@0 3529 Node* non_array = generate_non_array_guard(load_object_klass(array), NULL);
duke@0 3530
duke@0 3531 if (non_array != NULL) {
duke@0 3532 PreserveJVMState pjvms(this);
duke@0 3533 set_control(non_array);
duke@0 3534 _sp += nargs; // push the arguments back on the stack
duke@0 3535 uncommon_trap(Deoptimization::Reason_intrinsic,
duke@0 3536 Deoptimization::Action_maybe_recompile);
duke@0 3537 }
duke@0 3538
duke@0 3539 // If control is dead, only non-array-path is taken.
duke@0 3540 if (stopped()) return true;
duke@0 3541
duke@0 3542 // The works fine even if the array type is polymorphic.
duke@0 3543 // It could be a dynamic mix of int[], boolean[], Object[], etc.
duke@0 3544 push( load_array_length(array) );
duke@0 3545
duke@0 3546 C->set_has_split_ifs(true); // Has chance for split-if optimization
duke@0 3547
duke@0 3548 return true;
duke@0 3549 }
duke@0 3550
duke@0 3551 //------------------------inline_array_copyOf----------------------------
duke@0 3552 bool LibraryCallKit::inline_array_copyOf(bool is_copyOfRange) {
duke@0 3553 if (too_many_traps(Deoptimization::Reason_intrinsic)) return false;
duke@0 3554
duke@0 3555 // Restore the stack and pop off the arguments.
duke@0 3556 int nargs = 3 + (is_copyOfRange? 1: 0);
duke@0 3557 Node* original = argument(0);
duke@0 3558 Node* start = is_copyOfRange? argument(1): intcon(0);
duke@0 3559 Node* end = is_copyOfRange? argument(2): argument(1);
duke@0 3560 Node* array_type_mirror = is_copyOfRange? argument(3): argument(2);
duke@0 3561
cfang@902 3562 Node* newcopy;
cfang@902 3563
cfang@902 3564 //set the original stack and the reexecute bit for the interpreter to reexecute
cfang@902 3565 //the bytecode that invokes Arrays.copyOf if deoptimization happens
cfang@902 3566 { PreserveReexecuteState preexecs(this);
cfang@902 3567 _sp += nargs;
cfang@902 3568 jvms()->set_should_reexecute(true);
cfang@902 3569
cfang@902 3570 array_type_mirror = do_null_check(array_type_mirror, T_OBJECT);
cfang@902 3571 original = do_null_check(original, T_OBJECT);
cfang@902 3572
cfang@902 3573 // Check if a null path was taken unconditionally.
cfang@902 3574 if (stopped()) return true;
cfang@902 3575
cfang@902 3576 Node* orig_length = load_array_length(original);
cfang@902 3577
cfang@902 3578 Node* klass_node = load_klass_from_mirror(array_type_mirror, false, 0,
cfang@902 3579 NULL, 0);
cfang@902 3580 klass_node = do_null_check(klass_node, T_OBJECT);
<