annotate src/hotspot/share/opto/library_call.cpp @ 54022:ff399127078a

8217561: X86: Add floating-point Math.min/max intrinsics Summary: Implementation taking care of +/-0.0 and NaN which uses a specific pattern for reductions Reviewed-by: aph, kvn, neliasso, sviswanathan, adinn Contributed-by: Jatin Bhateja <jatin.bhateja@intel.com>
author bsrbnd
date Thu, 07 Mar 2019 15:27:42 +0100
parents 28aa41c4165b
children 744dc9c33676
rev   line source
duke@1 1 /*
bsrbnd@54022 2 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
trims@5547 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@5547 20 * or visit www.oracle.com if you need additional information or have any
trims@5547 21 * questions.
duke@1 22 *
duke@1 23 */
duke@1 24
stefank@7397 25 #include "precompiled.hpp"
goetz@25715 26 #include "asm/macroAssembler.hpp"
coleenp@49449 27 #include "ci/ciUtilities.inline.hpp"
stefank@7397 28 #include "classfile/systemDictionary.hpp"
stefank@7397 29 #include "classfile/vmSymbols.hpp"
twisti@8872 30 #include "compiler/compileBroker.hpp"
stefank@7397 31 #include "compiler/compileLog.hpp"
glaubitz@50399 32 #include "gc/shared/barrierSet.hpp"
glaubitz@50399 33 #include "jfr/support/jfrIntrinsics.hpp"
jprovino@37248 34 #include "memory/resourceArea.hpp"
stefank@7397 35 #include "oops/objArrayKlass.hpp"
stefank@7397 36 #include "opto/addnode.hpp"
roland@29337 37 #include "opto/arraycopynode.hpp"
zmajo@31962 38 #include "opto/c2compiler.hpp"
stefank@7397 39 #include "opto/callGenerator.hpp"
morris@23528 40 #include "opto/castnode.hpp"
stefank@7397 41 #include "opto/cfgnode.hpp"
morris@23528 42 #include "opto/convertnode.hpp"
morris@23528 43 #include "opto/countbitsnode.hpp"
morris@23528 44 #include "opto/intrinsicnode.hpp"
stefank@7397 45 #include "opto/idealKit.hpp"
rbackman@20289 46 #include "opto/mathexactnode.hpp"
morris@23528 47 #include "opto/movenode.hpp"
stefank@7397 48 #include "opto/mulnode.hpp"
morris@23528 49 #include "opto/narrowptrnode.hpp"
vlivanov@28912 50 #include "opto/opaquenode.hpp"
stefank@7397 51 #include "opto/parse.hpp"
stefank@7397 52 #include "opto/runtime.hpp"
roland@46525 53 #include "opto/rootnode.hpp"
stefank@7397 54 #include "opto/subnode.hpp"
stefank@7397 55 #include "prims/nativeLookup.hpp"
mikael@36551 56 #include "prims/unsafe.hpp"
dcubed@50083 57 #include "runtime/objectMonitor.hpp"
stefank@7397 58 #include "runtime/sharedRuntime.hpp"
egahlin@50113 59 #include "utilities/macros.hpp"
egahlin@50113 60
duke@1 61
duke@1 62 class LibraryIntrinsic : public InlineCallGenerator {
duke@1 63 // Extend the set of intrinsics known to the runtime:
duke@1 64 public:
duke@1 65 private:
duke@1 66 bool _is_virtual;
shade@20296 67 bool _does_virtual_dispatch;
kvn@24948 68 int8_t _predicates_count; // Intrinsic is predicated by several conditions
kvn@24948 69 int8_t _last_predicate; // Last generated predicate
duke@1 70 vmIntrinsics::ID _intrinsic_id;
duke@1 71
duke@1 72 public:
kvn@24948 73 LibraryIntrinsic(ciMethod* m, bool is_virtual, int predicates_count, bool does_virtual_dispatch, vmIntrinsics::ID id)
duke@1 74 : InlineCallGenerator(m),
duke@1 75 _is_virtual(is_virtual),
shade@20296 76 _does_virtual_dispatch(does_virtual_dispatch),
kvn@24948 77 _predicates_count((int8_t)predicates_count),
kvn@24948 78 _last_predicate((int8_t)-1),
duke@1 79 _intrinsic_id(id)
duke@1 80 {
duke@1 81 }
duke@1 82 virtual bool is_intrinsic() const { return true; }
duke@1 83 virtual bool is_virtual() const { return _is_virtual; }
kvn@24948 84 virtual bool is_predicated() const { return _predicates_count > 0; }
kvn@24948 85 virtual int predicates_count() const { return _predicates_count; }
shade@20296 86 virtual bool does_virtual_dispatch() const { return _does_virtual_dispatch; }
roland@24946 87 virtual JVMState* generate(JVMState* jvms);
kvn@24948 88 virtual Node* generate_predicate(JVMState* jvms, int predicate);
duke@1 89 vmIntrinsics::ID intrinsic_id() const { return _intrinsic_id; }
duke@1 90 };
duke@1 91
duke@1 92
duke@1 93 // Local helper class for LibraryIntrinsic:
duke@1 94 class LibraryCallKit : public GraphKit {
duke@1 95 private:
twisti@14621 96 LibraryIntrinsic* _intrinsic; // the library intrinsic being called
twisti@14621 97 Node* _result; // the result node, if any
twisti@14621 98 int _reexecute_sp; // the stack pointer when bytecode needs to be reexecuted
duke@1 99
mikael@38211 100 const TypeOopPtr* sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type);
roland@13886 101
duke@1 102 public:
twisti@14621 103 LibraryCallKit(JVMState* jvms, LibraryIntrinsic* intrinsic)
twisti@14621 104 : GraphKit(jvms),
twisti@14621 105 _intrinsic(intrinsic),
twisti@14621 106 _result(NULL)
duke@1 107 {
twisti@14627 108 // Check if this is a root compile. In that case we don't have a caller.
twisti@14627 109 if (!jvms->has_method()) {
twisti@14627 110 _reexecute_sp = sp();
twisti@14627 111 } else {
twisti@14627 112 // Find out how many arguments the interpreter needs when deoptimizing
twisti@14627 113 // and save the stack pointer value so it can used by uncommon_trap.
twisti@14627 114 // We find the argument count by looking at the declared signature.
twisti@14627 115 bool ignored_will_link;
twisti@14627 116 ciSignature* declared_signature = NULL;
twisti@14627 117 ciMethod* ignored_callee = caller()->get_method_at_bci(bci(), ignored_will_link, &declared_signature);
twisti@14627 118 const int nargs = declared_signature->arg_size_for_bc(caller()->java_code_at_bci(bci()));
twisti@14627 119 _reexecute_sp = sp() + nargs; // "push" arguments back on stack
twisti@14627 120 }
duke@1 121 }
duke@1 122
twisti@14621 123 virtual LibraryCallKit* is_LibraryCallKit() const { return (LibraryCallKit*)this; }
twisti@14621 124
duke@1 125 ciMethod* caller() const { return jvms()->method(); }
duke@1 126 int bci() const { return jvms()->bci(); }
duke@1 127 LibraryIntrinsic* intrinsic() const { return _intrinsic; }
duke@1 128 vmIntrinsics::ID intrinsic_id() const { return _intrinsic->intrinsic_id(); }
duke@1 129 ciMethod* callee() const { return _intrinsic->method(); }
duke@1 130
kvn@24948 131 bool try_to_inline(int predicate);
kvn@24948 132 Node* try_to_predicate(int predicate);
duke@1 133
twisti@14621 134 void push_result() {
twisti@14621 135 // Push the result onto the stack.
twisti@14621 136 if (!stopped() && result() != NULL) {
twisti@14621 137 BasicType bt = result()->bottom_type()->basic_type();
twisti@14621 138 push_node(bt, result());
twisti@14621 139 }
twisti@14621 140 }
twisti@14621 141
twisti@14621 142 private:
twisti@14621 143 void fatal_unexpected_iid(vmIntrinsics::ID iid) {
david@33105 144 fatal("unexpected intrinsic %d: %s", iid, vmIntrinsics::name_at(iid));
twisti@14621 145 }
twisti@14621 146
twisti@14621 147 void set_result(Node* n) { assert(_result == NULL, "only set once"); _result = n; }
twisti@14621 148 void set_result(RegionNode* region, PhiNode* value);
twisti@14621 149 Node* result() { return _result; }
twisti@14621 150
twisti@14621 151 virtual int reexecute_sp() { return _reexecute_sp; }
twisti@14621 152
duke@1 153 // Helper functions to inline natives
duke@1 154 Node* generate_guard(Node* test, RegionNode* region, float true_prob);
duke@1 155 Node* generate_slow_guard(Node* test, RegionNode* region);
duke@1 156 Node* generate_fair_guard(Node* test, RegionNode* region);
duke@1 157 Node* generate_negative_guard(Node* index, RegionNode* region,
duke@1 158 // resulting CastII of index:
duke@1 159 Node* *pos_index = NULL);
duke@1 160 Node* generate_limit_guard(Node* offset, Node* subseq_length,
duke@1 161 Node* array_length,
duke@1 162 RegionNode* region);
thartmann@34499 163 void generate_string_range_check(Node* array, Node* offset,
thartmann@34499 164 Node* length, bool char_count);
duke@1 165 Node* generate_current_thread(Node* &tls_output);
duke@1 166 Node* load_mirror_from_klass(Node* klass);
duke@1 167 Node* load_klass_from_mirror_common(Node* mirror, bool never_see_null,
duke@1 168 RegionNode* region, int null_path,
duke@1 169 int offset);
twisti@14621 170 Node* load_klass_from_mirror(Node* mirror, bool never_see_null,
duke@1 171 RegionNode* region, int null_path) {
duke@1 172 int offset = java_lang_Class::klass_offset_in_bytes();
twisti@14621 173 return load_klass_from_mirror_common(mirror, never_see_null,
duke@1 174 region, null_path,
duke@1 175 offset);
duke@1 176 }
duke@1 177 Node* load_array_klass_from_mirror(Node* mirror, bool never_see_null,
duke@1 178 RegionNode* region, int null_path) {
duke@1 179 int offset = java_lang_Class::array_klass_offset_in_bytes();
twisti@14621 180 return load_klass_from_mirror_common(mirror, never_see_null,
duke@1 181 region, null_path,
duke@1 182 offset);
duke@1 183 }
duke@1 184 Node* generate_access_flags_guard(Node* kls,
duke@1 185 int modifier_mask, int modifier_bits,
duke@1 186 RegionNode* region);
duke@1 187 Node* generate_interface_guard(Node* kls, RegionNode* region);
duke@1 188 Node* generate_array_guard(Node* kls, RegionNode* region) {
duke@1 189 return generate_array_guard_common(kls, region, false, false);
duke@1 190 }
duke@1 191 Node* generate_non_array_guard(Node* kls, RegionNode* region) {
duke@1 192 return generate_array_guard_common(kls, region, false, true);
duke@1 193 }
duke@1 194 Node* generate_objArray_guard(Node* kls, RegionNode* region) {
duke@1 195 return generate_array_guard_common(kls, region, true, false);
duke@1 196 }
duke@1 197 Node* generate_non_objArray_guard(Node* kls, RegionNode* region) {
duke@1 198 return generate_array_guard_common(kls, region, true, true);
duke@1 199 }
duke@1 200 Node* generate_array_guard_common(Node* kls, RegionNode* region,
duke@1 201 bool obj_array, bool not_array);
duke@1 202 Node* generate_virtual_guard(Node* obj_klass, RegionNode* slow_region);
duke@1 203 CallJavaNode* generate_method_call(vmIntrinsics::ID method_id,
duke@1 204 bool is_virtual = false, bool is_static = false);
duke@1 205 CallJavaNode* generate_method_call_static(vmIntrinsics::ID method_id) {
duke@1 206 return generate_method_call(method_id, false, true);
duke@1 207 }
duke@1 208 CallJavaNode* generate_method_call_virtual(vmIntrinsics::ID method_id) {
duke@1 209 return generate_method_call(method_id, true, false);
duke@1 210 }
kvn@31515 211 Node * load_field_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, bool is_exact, bool is_static, ciInstanceKlass * fromKls);
kvn@35154 212 Node * field_address_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, bool is_exact, bool is_static, ciInstanceKlass * fromKls);
duke@1 213
thartmann@33628 214 Node* make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2, StrIntrinsicNode::ArgEnc ae);
thartmann@33628 215 bool inline_string_compareTo(StrIntrinsicNode::ArgEnc ae);
thartmann@33628 216 bool inline_string_indexOf(StrIntrinsicNode::ArgEnc ae);
thartmann@33628 217 bool inline_string_indexOfI(StrIntrinsicNode::ArgEnc ae);
thartmann@34499 218 Node* make_indexOf_node(Node* src_start, Node* src_count, Node* tgt_start, Node* tgt_count,
thartmann@34499 219 RegionNode* region, Node* phi, StrIntrinsicNode::ArgEnc ae);
thartmann@33628 220 bool inline_string_indexOfChar();
thartmann@33628 221 bool inline_string_equals(StrIntrinsicNode::ArgEnc ae);
thartmann@33628 222 bool inline_string_toBytesU();
thartmann@33628 223 bool inline_string_getCharsU();
thartmann@33628 224 bool inline_string_copy(bool compress);
thartmann@33628 225 bool inline_string_char_access(bool is_store);
twisti@14621 226 Node* round_double_node(Node* n);
duke@1 227 bool runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName);
duke@1 228 bool inline_math_native(vmIntrinsics::ID id);
twisti@14621 229 bool inline_math(vmIntrinsics::ID id);
rbackman@22911 230 template <typename OverflowOp>
rbackman@22911 231 bool inline_math_overflow(Node* arg1, Node* arg2);
rbackman@22911 232 void inline_math_mathExact(Node* math, Node* test);
rbackman@21105 233 bool inline_math_addExactI(bool is_increment);
rbackman@21105 234 bool inline_math_addExactL(bool is_increment);
rbackman@21105 235 bool inline_math_multiplyExactI();
rbackman@21105 236 bool inline_math_multiplyExactL();
dpochepk@47587 237 bool inline_math_multiplyHigh();
rbackman@21105 238 bool inline_math_negateExactI();
rbackman@21105 239 bool inline_math_negateExactL();
rbackman@21105 240 bool inline_math_subtractExactI(bool is_decrement);
rbackman@21105 241 bool inline_math_subtractExactL(bool is_decrement);
duke@1 242 bool inline_min_max(vmIntrinsics::ID id);
dcubed@31856 243 bool inline_notify(vmIntrinsics::ID id);
duke@1 244 Node* generate_min_max(vmIntrinsics::ID id, Node* x, Node* y);
duke@1 245 // This returns Type::AnyPtr, RawPtr, or OopPtr.
roland@46525 246 int classify_unsafe_addr(Node* &base, Node* &offset, BasicType type);
rkennke@51850 247 Node* make_unsafe_address(Node*& base, Node* offset, DecoratorSet decorators, BasicType type = T_ILLEGAL, bool can_cast = false);
shade@36316 248
shade@36316 249 typedef enum { Relaxed, Opaque, Volatile, Acquire, Release } AccessKind;
eosterlund@50180 250 DecoratorSet mo_decorator_for_access_kind(AccessKind kind);
mikael@38211 251 bool inline_unsafe_access(bool is_store, BasicType type, AccessKind kind, bool is_unaligned);
rbackman@19337 252 static bool klass_needs_init_guard(Node* kls);
duke@1 253 bool inline_unsafe_allocate();
shade@36553 254 bool inline_unsafe_newArray(bool uninitialized);
duke@1 255 bool inline_unsafe_copyMemory();
duke@1 256 bool inline_native_currentThread();
mgronlun@36384 257
rbackman@12377 258 bool inline_native_time_funcs(address method, const char* funcName);
egahlin@50113 259 #ifdef JFR_HAVE_INTRINSICS
rehn@40899 260 bool inline_native_classID();
egahlin@50113 261 bool inline_native_getEventWriter();
rehn@40899 262 #endif
duke@1 263 bool inline_native_isInterrupted();
duke@1 264 bool inline_native_Class_query(vmIntrinsics::ID id);
duke@1 265 bool inline_native_subtype_check();
duke@1 266 bool inline_native_getLength();
duke@1 267 bool inline_array_copyOf(bool is_copyOfRange);
thartmann@33628 268 bool inline_array_equals(StrIntrinsicNode::ArgEnc ae);
psandoz@38240 269 bool inline_preconditions_checkIndex();
eosterlund@50180 270 void copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array);
duke@1 271 bool inline_native_clone(bool is_virtual);
duke@1 272 bool inline_native_Reflection_getCallerClass();
duke@1 273 // Helper function for inlining native object hash method
duke@1 274 bool inline_native_hashcode(bool is_virtual, bool is_static);
duke@1 275 bool inline_native_getClass();
duke@1 276
duke@1 277 // Helper functions for inlining arraycopy
duke@1 278 bool inline_arraycopy();
duke@1 279 AllocateArrayNode* tightly_coupled_allocation(Node* ptr,
duke@1 280 RegionNode* slow_region);
roland@30185 281 JVMState* arraycopy_restore_alloc_state(AllocateArrayNode* alloc, int& saved_reexecute_sp);
roland@43963 282 void arraycopy_move_allocation_here(AllocateArrayNode* alloc, Node* dest, JVMState* saved_jvms, int saved_reexecute_sp,
roland@43963 283 uint new_idx);
roland@30185 284
shade@36316 285 typedef enum { LS_get_add, LS_get_set, LS_cmp_swap, LS_cmp_swap_weak, LS_cmp_exchange } LoadStoreKind;
shade@36316 286 bool inline_unsafe_load_store(BasicType type, LoadStoreKind kind, AccessKind access_kind);
kvn@14832 287 bool inline_unsafe_fence(vmIntrinsics::ID id);
ikrylov@38017 288 bool inline_onspinwait();
duke@1 289 bool inline_fp_conversions(vmIntrinsics::ID id);
twisti@14621 290 bool inline_number_methods(vmIntrinsics::ID id);
johnc@9176 291 bool inline_reference_get();
kvn@27450 292 bool inline_Class_cast();
kvn@14132 293 bool inline_aescrypt_Block(vmIntrinsics::ID id);
kvn@14132 294 bool inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id);
kvn@35154 295 bool inline_counterMode_AESCrypt(vmIntrinsics::ID id);
kvn@14132 296 Node* inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting);
kvn@35154 297 Node* inline_counterMode_AESCrypt_predicate();
kvn@14132 298 Node* get_key_start_from_aescrypt_object(Node* aescrypt_object);
kvn@22505 299 Node* get_original_key_start_from_aescrypt_object(Node* aescrypt_object);
ascarpino@31404 300 bool inline_ghash_processBlocks();
kvn@50860 301 bool inline_base64_encodeBlock();
kvn@24953 302 bool inline_sha_implCompress(vmIntrinsics::ID id);
kvn@24953 303 bool inline_digestBase_implCompressMB(int predicate);
kvn@24953 304 bool inline_sha_implCompressMB(Node* digestBaseObj, ciInstanceKlass* instklass_SHA,
kvn@24953 305 bool long_state, address stubAddr, const char *stubName,
kvn@24953 306 Node* src_start, Node* ofs, Node* limit);
kvn@24953 307 Node* get_state_from_sha_object(Node *sha_object);
kvn@24953 308 Node* get_state_from_sha5_object(Node *sha_object);
kvn@24953 309 Node* inline_digestBase_implCompressMB_predicate(int predicate);
kvn@15242 310 bool inline_encodeISOArray();
drchase@18507 311 bool inline_updateCRC32();
drchase@18507 312 bool inline_updateBytesCRC32();
drchase@18507 313 bool inline_updateByteBufferCRC32();
kvn@31515 314 Node* get_table_from_crc32c_class(ciInstanceKlass *crc32c_class);
kvn@31515 315 bool inline_updateBytesCRC32C();
kvn@31515 316 bool inline_updateDirectByteBufferCRC32C();
kvn@32581 317 bool inline_updateBytesAdler32();
kvn@32581 318 bool inline_updateByteBufferAdler32();
kvn@26434 319 bool inline_multiplyToLen();
thartmann@33628 320 bool inline_hasNegatives();
kvn@31129 321 bool inline_squareToLen();
kvn@31129 322 bool inline_mulAdd();
aph@31583 323 bool inline_montgomeryMultiply();
aph@31583 324 bool inline_montgomerySquare();
kvn@35110 325 bool inline_vectorizedMismatch();
vdeshpande@41323 326 bool inline_fma(vmIntrinsics::ID id);
mhorie@52979 327 bool inline_character_compare(vmIntrinsics::ID id);
pli@53041 328 bool inline_fp_min_max(vmIntrinsics::ID id);
vlivanov@28912 329
vlivanov@28912 330 bool inline_profileBoolean();
vlivanov@30189 331 bool inline_isCompileConstant();
vdeshpande@48371 332 void clear_upper_avx() {
vdeshpande@48371 333 #ifdef X86
vdeshpande@48371 334 if (UseAVX >= 2) {
vdeshpande@48371 335 C->set_clear_upper_avx(true);
vdeshpande@48371 336 }
vdeshpande@48371 337 #endif
vdeshpande@48371 338 }
duke@1 339 };
duke@1 340
duke@1 341 //---------------------------make_vm_intrinsic----------------------------
duke@1 342 CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) {
duke@1 343 vmIntrinsics::ID id = m->intrinsic_id();
duke@1 344 assert(id != vmIntrinsics::_none, "must be a VM intrinsic");
duke@1 345
zmajo@31962 346 if (!m->is_loaded()) {
zmajo@31962 347 // Do not attempt to inline unloaded methods.
duke@1 348 return NULL;
duke@1 349 }
duke@1 350
zmajo@31962 351 C2Compiler* compiler = (C2Compiler*)CompileBroker::compiler(CompLevel_full_optimization);
zmajo@31962 352 bool is_available = false;
zmajo@31962 353
zmajo@31962 354 {
zmajo@31962 355 // For calling is_intrinsic_supported and is_intrinsic_disabled_by_flag
zmajo@31962 356 // the compiler must transition to '_thread_in_vm' state because both
zmajo@31962 357 // methods access VM-internal data.
zmajo@31962 358 VM_ENTRY_MARK;
zmajo@31962 359 methodHandle mh(THREAD, m->get_Method());
rraghavan@46375 360 is_available = compiler != NULL && compiler->is_intrinsic_supported(mh, is_virtual) &&
neliasso@33451 361 !C->directive()->is_intrinsic_disabled(mh) &&
neliasso@33451 362 !vmIntrinsics::is_disabled_by_flags(mh);
neliasso@33451 363
zmajo@31962 364 }
zmajo@31962 365
zmajo@31962 366 if (is_available) {
jrose@3273 367 assert(id <= vmIntrinsics::LAST_COMPILER_INLINE, "caller responsibility");
jrose@3273 368 assert(id != vmIntrinsics::_Object_init && id != vmIntrinsics::_invoke, "enum out of order?");
zmajo@31962 369 return new LibraryIntrinsic(m, is_virtual,
zmajo@31962 370 vmIntrinsics::predicates_needed(id),
zmajo@31962 371 vmIntrinsics::does_virtual_dispatch(id),
zmajo@31962 372 (vmIntrinsics::ID) id);
zmajo@31962 373 } else {
zmajo@31962 374 return NULL;
zmajo@31962 375 }
duke@1 376 }
duke@1 377
duke@1 378 //----------------------register_library_intrinsics-----------------------
duke@1 379 // Initialize this file's data structures, for each Compile instance.
duke@1 380 void Compile::register_library_intrinsics() {
duke@1 381 // Nothing to do here.
duke@1 382 }
duke@1 383
roland@24946 384 JVMState* LibraryIntrinsic::generate(JVMState* jvms) {
duke@1 385 LibraryCallKit kit(jvms, this);
duke@1 386 Compile* C = kit.C;
duke@1 387 int nodes = C->unique();
duke@1 388 #ifndef PRODUCT
kvn@20073 389 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
duke@1 390 char buf[1000];
duke@1 391 const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf));
duke@1 392 tty->print_cr("Intrinsic %s", str);
duke@1 393 }
duke@1 394 #endif
twisti@14621 395 ciMethod* callee = kit.callee();
twisti@14621 396 const int bci = kit.bci();
twisti@14621 397
twisti@14621 398 // Try to inline the intrinsic.
zmajo@31587 399 if ((CheckIntrinsics ? callee->intrinsic_candidate() : true) &&
zmajo@31587 400 kit.try_to_inline(_last_predicate)) {
ysuenaga@46270 401 const char *inline_msg = is_virtual() ? "(intrinsic, virtual)"
ysuenaga@46270 402 : "(intrinsic)";
ysuenaga@46270 403 CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, inline_msg);
kvn@20073 404 if (C->print_intrinsics() || C->print_inlining()) {
ysuenaga@46270 405 C->print_inlining(callee, jvms->depth() - 1, bci, inline_msg);
duke@1 406 }
duke@1 407 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked);
duke@1 408 if (C->log()) {
duke@1 409 C->log()->elem("intrinsic id='%s'%s nodes='%d'",
duke@1 410 vmIntrinsics::name_at(intrinsic_id()),
duke@1 411 (is_virtual() ? " virtual='1'" : ""),
duke@1 412 C->unique() - nodes);
duke@1 413 }
twisti@14621 414 // Push the result from the inlined method onto the stack.
twisti@14621 415 kit.push_result();
roland@23846 416 C->print_inlining_update(this);
duke@1 417 return kit.transfer_exceptions_into_jvms();
duke@1 418 }
duke@1 419
never@12107 420 // The intrinsic bailed out
ysuenaga@46270 421 if (jvms->has_method()) {
ysuenaga@46270 422 // Not a root compile.
ysuenaga@46270 423 const char* msg;
ysuenaga@46270 424 if (callee->intrinsic_candidate()) {
ysuenaga@46270 425 msg = is_virtual() ? "failed to inline (intrinsic, virtual)" : "failed to inline (intrinsic)";
ysuenaga@46270 426 } else {
ysuenaga@46270 427 msg = is_virtual() ? "failed to inline (intrinsic, virtual), method not annotated"
ysuenaga@46270 428 : "failed to inline (intrinsic), method not annotated";
ysuenaga@46270 429 }
ysuenaga@46270 430 CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, msg);
ysuenaga@46270 431 if (C->print_intrinsics() || C->print_inlining()) {
roland@14828 432 C->print_inlining(callee, jvms->depth() - 1, bci, msg);
ysuenaga@46270 433 }
ysuenaga@46270 434 } else {
ysuenaga@46270 435 // Root compile
ysuenaga@46270 436 ResourceMark rm;
ysuenaga@46270 437 stringStream msg_stream;
ysuenaga@46270 438 msg_stream.print("Did not generate intrinsic %s%s at bci:%d in",
ysuenaga@46270 439 vmIntrinsics::name_at(intrinsic_id()),
ysuenaga@46270 440 is_virtual() ? " (virtual)" : "", bci);
ysuenaga@46270 441 const char *msg = msg_stream.as_string();
ysuenaga@46270 442 log_debug(jit, inlining)("%s", msg);
ysuenaga@46270 443 if (C->print_intrinsics() || C->print_inlining()) {
ysuenaga@46270 444 tty->print("%s", msg);
johnc@9176 445 }
duke@1 446 }
duke@1 447 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed);
roland@23846 448 C->print_inlining_update(this);
duke@1 449 return NULL;
duke@1 450 }
duke@1 451
kvn@24948 452 Node* LibraryIntrinsic::generate_predicate(JVMState* jvms, int predicate) {
kvn@14132 453 LibraryCallKit kit(jvms, this);
kvn@14132 454 Compile* C = kit.C;
kvn@14132 455 int nodes = C->unique();
kvn@24948 456 _last_predicate = predicate;
kvn@14132 457 #ifndef PRODUCT
kvn@24948 458 assert(is_predicated() && predicate < predicates_count(), "sanity");
kvn@20073 459 if ((C->print_intrinsics() || C->print_inlining()) && Verbose) {
kvn@14132 460 char buf[1000];
kvn@14132 461 const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf));
kvn@14132 462 tty->print_cr("Predicate for intrinsic %s", str);
kvn@14132 463 }
kvn@14132 464 #endif
twisti@14621 465 ciMethod* callee = kit.callee();
twisti@14621 466 const int bci = kit.bci();
kvn@14132 467
kvn@24948 468 Node* slow_ctl = kit.try_to_predicate(predicate);
kvn@14132 469 if (!kit.failing()) {
ysuenaga@46270 470 const char *inline_msg = is_virtual() ? "(intrinsic, virtual, predicate)"
ysuenaga@46270 471 : "(intrinsic, predicate)";
ysuenaga@46270 472 CompileTask::print_inlining_ul(callee, jvms->depth() - 1, bci, inline_msg);
kvn@20073 473 if (C->print_intrinsics() || C->print_inlining()) {
ysuenaga@46270 474 C->print_inlining(callee, jvms->depth() - 1, bci, inline_msg);
twisti@14621 475 }
twisti@14621 476 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked);
kvn@14132 477 if (C->log()) {
kvn@14132 478 C->log()->elem("predicate_intrinsic id='%s'%s nodes='%d'",
kvn@14132 479 vmIntrinsics::name_at(intrinsic_id()),
kvn@14132 480 (is_virtual() ? " virtual='1'" : ""),
kvn@14132 481 C->unique() - nodes);
kvn@14132 482 }
kvn@14132 483 return slow_ctl; // Could be NULL if the check folds.
kvn@14132 484 }
kvn@14132 485
kvn@14132 486 // The intrinsic bailed out
ysuenaga@46270 487 if (jvms->has_method()) {
ysuenaga@46270 488 // Not a root compile.
ysuenaga@46270 489 const char* msg = "failed to generate predicate for intrinsic";
ysuenaga@46270 490 CompileTask::print_inlining_ul(kit.callee(), jvms->depth() - 1, bci, msg);
ysuenaga@46270 491 if (C->print_intrinsics() || C->print_inlining()) {
roland@14828 492 C->print_inlining(kit.callee(), jvms->depth() - 1, bci, msg);
ysuenaga@46270 493 }
ysuenaga@46270 494 } else {
ysuenaga@46270 495 // Root compile
ysuenaga@46270 496 ResourceMark rm;
ysuenaga@46270 497 stringStream msg_stream;
ysuenaga@46270 498 msg_stream.print("Did not generate intrinsic %s%s at bci:%d in",
ysuenaga@46270 499 vmIntrinsics::name_at(intrinsic_id()),
ysuenaga@46270 500 is_virtual() ? " (virtual)" : "", bci);
ysuenaga@46270 501 const char *msg = msg_stream.as_string();
ysuenaga@46270 502 log_debug(jit, inlining)("%s", msg);
ysuenaga@46270 503 if (C->print_intrinsics() || C->print_inlining()) {
ysuenaga@46270 504 C->print_inlining_stream()->print("%s", msg);
kvn@14132 505 }
kvn@14132 506 }
kvn@14132 507 C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed);
kvn@14132 508 return NULL;
kvn@14132 509 }
kvn@14132 510
kvn@24948 511 bool LibraryCallKit::try_to_inline(int predicate) {
duke@1 512 // Handle symbolic names for otherwise undistinguished boolean switches:
duke@1 513 const bool is_store = true;
thartmann@33628 514 const bool is_compress = true;
duke@1 515 const bool is_static = true;
twisti@14621 516 const bool is_volatile = true;
duke@1 517
johnc@9176 518 if (!jvms()->has_method()) {
johnc@9176 519 // Root JVMState has a null method.
johnc@9176 520 assert(map()->memory()->Opcode() == Op_Parm, "");
johnc@9176 521 // Insert the memory aliasing node
johnc@9176 522 set_all_memory(reset_memory());
johnc@9176 523 }
johnc@9176 524 assert(merged_memory(), "");
johnc@9176 525
twisti@14621 526
duke@1 527 switch (intrinsic_id()) {
twisti@14621 528 case vmIntrinsics::_hashCode: return inline_native_hashcode(intrinsic()->is_virtual(), !is_static);
twisti@14621 529 case vmIntrinsics::_identityHashCode: return inline_native_hashcode(/*!virtual*/ false, is_static);
twisti@14621 530 case vmIntrinsics::_getClass: return inline_native_getClass();
duke@1 531
duke@1 532 case vmIntrinsics::_dsin:
duke@1 533 case vmIntrinsics::_dcos:
duke@1 534 case vmIntrinsics::_dtan:
duke@1 535 case vmIntrinsics::_dabs:
duke@1 536 case vmIntrinsics::_datan2:
duke@1 537 case vmIntrinsics::_dsqrt:
duke@1 538 case vmIntrinsics::_dexp:
duke@1 539 case vmIntrinsics::_dlog:
duke@1 540 case vmIntrinsics::_dlog10:
twisti@14621 541 case vmIntrinsics::_dpow: return inline_math_native(intrinsic_id());
duke@1 542
duke@1 543 case vmIntrinsics::_min:
twisti@14621 544 case vmIntrinsics::_max: return inline_min_max(intrinsic_id());
twisti@14621 545
dcubed@31856 546 case vmIntrinsics::_notify:
dcubed@31856 547 case vmIntrinsics::_notifyAll:
mikael@51860 548 return inline_notify(intrinsic_id());
dcubed@31856 549
rbackman@21105 550 case vmIntrinsics::_addExactI: return inline_math_addExactI(false /* add */);
rbackman@21105 551 case vmIntrinsics::_addExactL: return inline_math_addExactL(false /* add */);
rbackman@21105 552 case vmIntrinsics::_decrementExactI: return inline_math_subtractExactI(true /* decrement */);
rbackman@21105 553 case vmIntrinsics::_decrementExactL: return inline_math_subtractExactL(true /* decrement */);
rbackman@21105 554 case vmIntrinsics::_incrementExactI: return inline_math_addExactI(true /* increment */);
rbackman@21105 555 case vmIntrinsics::_incrementExactL: return inline_math_addExactL(true /* increment */);
rbackman@21105 556 case vmIntrinsics::_multiplyExactI: return inline_math_multiplyExactI();
rbackman@21105 557 case vmIntrinsics::_multiplyExactL: return inline_math_multiplyExactL();
dpochepk@47587 558 case vmIntrinsics::_multiplyHigh: return inline_math_multiplyHigh();
rbackman@21105 559 case vmIntrinsics::_negateExactI: return inline_math_negateExactI();
rbackman@21105 560 case vmIntrinsics::_negateExactL: return inline_math_negateExactL();
rbackman@21105 561 case vmIntrinsics::_subtractExactI: return inline_math_subtractExactI(false /* subtract */);
rbackman@21105 562 case vmIntrinsics::_subtractExactL: return inline_math_subtractExactL(false /* subtract */);
rbackman@20289 563
twisti@14621 564 case vmIntrinsics::_arraycopy: return inline_arraycopy();
twisti@14621 565
thartmann@33628 566 case vmIntrinsics::_compareToL: return inline_string_compareTo(StrIntrinsicNode::LL);
thartmann@33628 567 case vmIntrinsics::_compareToU: return inline_string_compareTo(StrIntrinsicNode::UU);
thartmann@33628 568 case vmIntrinsics::_compareToLU: return inline_string_compareTo(StrIntrinsicNode::LU);
thartmann@33628 569 case vmIntrinsics::_compareToUL: return inline_string_compareTo(StrIntrinsicNode::UL);
thartmann@33628 570
thartmann@33628 571 case vmIntrinsics::_indexOfL: return inline_string_indexOf(StrIntrinsicNode::LL);
thartmann@33628 572 case vmIntrinsics::_indexOfU: return inline_string_indexOf(StrIntrinsicNode::UU);
thartmann@33628 573 case vmIntrinsics::_indexOfUL: return inline_string_indexOf(StrIntrinsicNode::UL);
thartmann@33628 574 case vmIntrinsics::_indexOfIL: return inline_string_indexOfI(StrIntrinsicNode::LL);
thartmann@33628 575 case vmIntrinsics::_indexOfIU: return inline_string_indexOfI(StrIntrinsicNode::UU);
thartmann@33628 576 case vmIntrinsics::_indexOfIUL: return inline_string_indexOfI(StrIntrinsicNode::UL);
thartmann@33628 577 case vmIntrinsics::_indexOfU_char: return inline_string_indexOfChar();
thartmann@33628 578
thartmann@33628 579 case vmIntrinsics::_equalsL: return inline_string_equals(StrIntrinsicNode::LL);
thartmann@33628 580 case vmIntrinsics::_equalsU: return inline_string_equals(StrIntrinsicNode::UU);
thartmann@33628 581
thartmann@33628 582 case vmIntrinsics::_toBytesStringU: return inline_string_toBytesU();
thartmann@33628 583 case vmIntrinsics::_getCharsStringU: return inline_string_getCharsU();
thartmann@33628 584 case vmIntrinsics::_getCharStringU: return inline_string_char_access(!is_store);
thartmann@33628 585 case vmIntrinsics::_putCharStringU: return inline_string_char_access( is_store);
thartmann@33628 586
thartmann@33628 587 case vmIntrinsics::_compressStringC:
thartmann@33628 588 case vmIntrinsics::_compressStringB: return inline_string_copy( is_compress);
thartmann@33628 589 case vmIntrinsics::_inflateStringC:
thartmann@33628 590 case vmIntrinsics::_inflateStringB: return inline_string_copy(!is_compress);
twisti@14621 591
mchung@52220 592 case vmIntrinsics::_getReference: return inline_unsafe_access(!is_store, T_OBJECT, Relaxed, false);
mikael@38211 593 case vmIntrinsics::_getBoolean: return inline_unsafe_access(!is_store, T_BOOLEAN, Relaxed, false);
mikael@38211 594 case vmIntrinsics::_getByte: return inline_unsafe_access(!is_store, T_BYTE, Relaxed, false);
mikael@38211 595 case vmIntrinsics::_getShort: return inline_unsafe_access(!is_store, T_SHORT, Relaxed, false);
mikael@38211 596 case vmIntrinsics::_getChar: return inline_unsafe_access(!is_store, T_CHAR, Relaxed, false);
mikael@38211 597 case vmIntrinsics::_getInt: return inline_unsafe_access(!is_store, T_INT, Relaxed, false);
mikael@38211 598 case vmIntrinsics::_getLong: return inline_unsafe_access(!is_store, T_LONG, Relaxed, false);
mikael@38211 599 case vmIntrinsics::_getFloat: return inline_unsafe_access(!is_store, T_FLOAT, Relaxed, false);
mikael@38211 600 case vmIntrinsics::_getDouble: return inline_unsafe_access(!is_store, T_DOUBLE, Relaxed, false);
mikael@38211 601
mchung@52220 602 case vmIntrinsics::_putReference: return inline_unsafe_access( is_store, T_OBJECT, Relaxed, false);
mikael@38211 603 case vmIntrinsics::_putBoolean: return inline_unsafe_access( is_store, T_BOOLEAN, Relaxed, false);
mikael@38211 604 case vmIntrinsics::_putByte: return inline_unsafe_access( is_store, T_BYTE, Relaxed, false);
mikael@38211 605 case vmIntrinsics::_putShort: return inline_unsafe_access( is_store, T_SHORT, Relaxed, false);
mikael@38211 606 case vmIntrinsics::_putChar: return inline_unsafe_access( is_store, T_CHAR, Relaxed, false);
mikael@38211 607 case vmIntrinsics::_putInt: return inline_unsafe_access( is_store, T_INT, Relaxed, false);
mikael@38211 608 case vmIntrinsics::_putLong: return inline_unsafe_access( is_store, T_LONG, Relaxed, false);
mikael@38211 609 case vmIntrinsics::_putFloat: return inline_unsafe_access( is_store, T_FLOAT, Relaxed, false);
mikael@38211 610 case vmIntrinsics::_putDouble: return inline_unsafe_access( is_store, T_DOUBLE, Relaxed, false);
mikael@38211 611
mchung@52220 612 case vmIntrinsics::_getReferenceVolatile: return inline_unsafe_access(!is_store, T_OBJECT, Volatile, false);
mikael@38211 613 case vmIntrinsics::_getBooleanVolatile: return inline_unsafe_access(!is_store, T_BOOLEAN, Volatile, false);
mikael@38211 614 case vmIntrinsics::_getByteVolatile: return inline_unsafe_access(!is_store, T_BYTE, Volatile, false);
mikael@38211 615 case vmIntrinsics::_getShortVolatile: return inline_unsafe_access(!is_store, T_SHORT, Volatile, false);
mikael@38211 616 case vmIntrinsics::_getCharVolatile: return inline_unsafe_access(!is_store, T_CHAR, Volatile, false);
mikael@38211 617 case vmIntrinsics::_getIntVolatile: return inline_unsafe_access(!is_store, T_INT, Volatile, false);
mikael@38211 618 case vmIntrinsics::_getLongVolatile: return inline_unsafe_access(!is_store, T_LONG, Volatile, false);
mikael@38211 619 case vmIntrinsics::_getFloatVolatile: return inline_unsafe_access(!is_store, T_FLOAT, Volatile, false);
mikael@38211 620 case vmIntrinsics::_getDoubleVolatile: return inline_unsafe_access(!is_store, T_DOUBLE, Volatile, false);
mikael@38211 621
mchung@52220 622 case vmIntrinsics::_putReferenceVolatile: return inline_unsafe_access( is_store, T_OBJECT, Volatile, false);
mikael@38211 623 case vmIntrinsics::_putBooleanVolatile: return inline_unsafe_access( is_store, T_BOOLEAN, Volatile, false);
mikael@38211 624 case vmIntrinsics::_putByteVolatile: return inline_unsafe_access( is_store, T_BYTE, Volatile, false);
mikael@38211 625 case vmIntrinsics::_putShortVolatile: return inline_unsafe_access( is_store, T_SHORT, Volatile, false);
mikael@38211 626 case vmIntrinsics::_putCharVolatile: return inline_unsafe_access( is_store, T_CHAR, Volatile, false);
mikael@38211 627 case vmIntrinsics::_putIntVolatile: return inline_unsafe_access( is_store, T_INT, Volatile, false);
mikael@38211 628 case vmIntrinsics::_putLongVolatile: return inline_unsafe_access( is_store, T_LONG, Volatile, false);
mikael@38211 629 case vmIntrinsics::_putFloatVolatile: return inline_unsafe_access( is_store, T_FLOAT, Volatile, false);
mikael@38211 630 case vmIntrinsics::_putDoubleVolatile: return inline_unsafe_access( is_store, T_DOUBLE, Volatile, false);
mikael@38211 631
mikael@38211 632 case vmIntrinsics::_getShortUnaligned: return inline_unsafe_access(!is_store, T_SHORT, Relaxed, true);
mikael@38211 633 case vmIntrinsics::_getCharUnaligned: return inline_unsafe_access(!is_store, T_CHAR, Relaxed, true);
mikael@38211 634 case vmIntrinsics::_getIntUnaligned: return inline_unsafe_access(!is_store, T_INT, Relaxed, true);
mikael@38211 635 case vmIntrinsics::_getLongUnaligned: return inline_unsafe_access(!is_store, T_LONG, Relaxed, true);
mikael@38211 636
mikael@38211 637 case vmIntrinsics::_putShortUnaligned: return inline_unsafe_access( is_store, T_SHORT, Relaxed, true);
mikael@38211 638 case vmIntrinsics::_putCharUnaligned: return inline_unsafe_access( is_store, T_CHAR, Relaxed, true);
mikael@38211 639 case vmIntrinsics::_putIntUnaligned: return inline_unsafe_access( is_store, T_INT, Relaxed, true);
mikael@38211 640 case vmIntrinsics::_putLongUnaligned: return inline_unsafe_access( is_store, T_LONG, Relaxed, true);
mikael@38211 641
mchung@52220 642 case vmIntrinsics::_getReferenceAcquire: return inline_unsafe_access(!is_store, T_OBJECT, Acquire, false);
mikael@38211 643 case vmIntrinsics::_getBooleanAcquire: return inline_unsafe_access(!is_store, T_BOOLEAN, Acquire, false);
mikael@38211 644 case vmIntrinsics::_getByteAcquire: return inline_unsafe_access(!is_store, T_BYTE, Acquire, false);
mikael@38211 645 case vmIntrinsics::_getShortAcquire: return inline_unsafe_access(!is_store, T_SHORT, Acquire, false);
mikael@38211 646 case vmIntrinsics::_getCharAcquire: return inline_unsafe_access(!is_store, T_CHAR, Acquire, false);
mikael@38211 647 case vmIntrinsics::_getIntAcquire: return inline_unsafe_access(!is_store, T_INT, Acquire, false);
mikael@38211 648 case vmIntrinsics::_getLongAcquire: return inline_unsafe_access(!is_store, T_LONG, Acquire, false);
mikael@38211 649 case vmIntrinsics::_getFloatAcquire: return inline_unsafe_access(!is_store, T_FLOAT, Acquire, false);
mikael@38211 650 case vmIntrinsics::_getDoubleAcquire: return inline_unsafe_access(!is_store, T_DOUBLE, Acquire, false);
mikael@38211 651
mchung@52220 652 case vmIntrinsics::_putReferenceRelease: return inline_unsafe_access( is_store, T_OBJECT, Release, false);
mikael@38211 653 case vmIntrinsics::_putBooleanRelease: return inline_unsafe_access( is_store, T_BOOLEAN, Release, false);
mikael@38211 654 case vmIntrinsics::_putByteRelease: return inline_unsafe_access( is_store, T_BYTE, Release, false);
mikael@38211 655 case vmIntrinsics::_putShortRelease: return inline_unsafe_access( is_store, T_SHORT, Release, false);
mikael@38211 656 case vmIntrinsics::_putCharRelease: return inline_unsafe_access( is_store, T_CHAR, Release, false);
mikael@38211 657 case vmIntrinsics::_putIntRelease: return inline_unsafe_access( is_store, T_INT, Release, false);
mikael@38211 658 case vmIntrinsics::_putLongRelease: return inline_unsafe_access( is_store, T_LONG, Release, false);
mikael@38211 659 case vmIntrinsics::_putFloatRelease: return inline_unsafe_access( is_store, T_FLOAT, Release, false);
mikael@38211 660 case vmIntrinsics::_putDoubleRelease: return inline_unsafe_access( is_store, T_DOUBLE, Release, false);
mikael@38211 661
mchung@52220 662 case vmIntrinsics::_getReferenceOpaque: return inline_unsafe_access(!is_store, T_OBJECT, Opaque, false);
mikael@38211 663 case vmIntrinsics::_getBooleanOpaque: return inline_unsafe_access(!is_store, T_BOOLEAN, Opaque, false);
mikael@38211 664 case vmIntrinsics::_getByteOpaque: return inline_unsafe_access(!is_store, T_BYTE, Opaque, false);
mikael@38211 665 case vmIntrinsics::_getShortOpaque: return inline_unsafe_access(!is_store, T_SHORT, Opaque, false);
mikael@38211 666 case vmIntrinsics::_getCharOpaque: return inline_unsafe_access(!is_store, T_CHAR, Opaque, false);
mikael@38211 667 case vmIntrinsics::_getIntOpaque: return inline_unsafe_access(!is_store, T_INT, Opaque, false);
mikael@38211 668 case vmIntrinsics::_getLongOpaque: return inline_unsafe_access(!is_store, T_LONG, Opaque, false);
mikael@38211 669 case vmIntrinsics::_getFloatOpaque: return inline_unsafe_access(!is_store, T_FLOAT, Opaque, false);
mikael@38211 670 case vmIntrinsics::_getDoubleOpaque: return inline_unsafe_access(!is_store, T_DOUBLE, Opaque, false);
mikael@38211 671
mchung@52220 672 case vmIntrinsics::_putReferenceOpaque: return inline_unsafe_access( is_store, T_OBJECT, Opaque, false);
mikael@38211 673 case vmIntrinsics::_putBooleanOpaque: return inline_unsafe_access( is_store, T_BOOLEAN, Opaque, false);
mikael@38211 674 case vmIntrinsics::_putByteOpaque: return inline_unsafe_access( is_store, T_BYTE, Opaque, false);
mikael@38211 675 case vmIntrinsics::_putShortOpaque: return inline_unsafe_access( is_store, T_SHORT, Opaque, false);
mikael@38211 676 case vmIntrinsics::_putCharOpaque: return inline_unsafe_access( is_store, T_CHAR, Opaque, false);
mikael@38211 677 case vmIntrinsics::_putIntOpaque: return inline_unsafe_access( is_store, T_INT, Opaque, false);
mikael@38211 678 case vmIntrinsics::_putLongOpaque: return inline_unsafe_access( is_store, T_LONG, Opaque, false);
mikael@38211 679 case vmIntrinsics::_putFloatOpaque: return inline_unsafe_access( is_store, T_FLOAT, Opaque, false);
mikael@38211 680 case vmIntrinsics::_putDoubleOpaque: return inline_unsafe_access( is_store, T_DOUBLE, Opaque, false);
shade@36316 681
mchung@52220 682 case vmIntrinsics::_compareAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap, Volatile);
mchung@52220 683 case vmIntrinsics::_compareAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap, Volatile);
mchung@52220 684 case vmIntrinsics::_compareAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap, Volatile);
mchung@52220 685 case vmIntrinsics::_compareAndSetInt: return inline_unsafe_load_store(T_INT, LS_cmp_swap, Volatile);
mchung@52220 686 case vmIntrinsics::_compareAndSetLong: return inline_unsafe_load_store(T_LONG, LS_cmp_swap, Volatile);
mchung@52220 687
mchung@52220 688 case vmIntrinsics::_weakCompareAndSetReferencePlain: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Relaxed);
mchung@52220 689 case vmIntrinsics::_weakCompareAndSetReferenceAcquire: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Acquire);
mchung@52220 690 case vmIntrinsics::_weakCompareAndSetReferenceRelease: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Release);
mchung@52220 691 case vmIntrinsics::_weakCompareAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_swap_weak, Volatile);
mchung@52220 692 case vmIntrinsics::_weakCompareAndSetBytePlain: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Relaxed);
mchung@52220 693 case vmIntrinsics::_weakCompareAndSetByteAcquire: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Acquire);
mchung@52220 694 case vmIntrinsics::_weakCompareAndSetByteRelease: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Release);
mchung@52220 695 case vmIntrinsics::_weakCompareAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_swap_weak, Volatile);
mchung@52220 696 case vmIntrinsics::_weakCompareAndSetShortPlain: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Relaxed);
mchung@52220 697 case vmIntrinsics::_weakCompareAndSetShortAcquire: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Acquire);
mchung@52220 698 case vmIntrinsics::_weakCompareAndSetShortRelease: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Release);
mchung@52220 699 case vmIntrinsics::_weakCompareAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_swap_weak, Volatile);
mchung@52220 700 case vmIntrinsics::_weakCompareAndSetIntPlain: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Relaxed);
mchung@52220 701 case vmIntrinsics::_weakCompareAndSetIntAcquire: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Acquire);
mchung@52220 702 case vmIntrinsics::_weakCompareAndSetIntRelease: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Release);
mchung@52220 703 case vmIntrinsics::_weakCompareAndSetInt: return inline_unsafe_load_store(T_INT, LS_cmp_swap_weak, Volatile);
mchung@52220 704 case vmIntrinsics::_weakCompareAndSetLongPlain: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Relaxed);
mchung@52220 705 case vmIntrinsics::_weakCompareAndSetLongAcquire: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Acquire);
mchung@52220 706 case vmIntrinsics::_weakCompareAndSetLongRelease: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Release);
mchung@52220 707 case vmIntrinsics::_weakCompareAndSetLong: return inline_unsafe_load_store(T_LONG, LS_cmp_swap_weak, Volatile);
mchung@52220 708
mchung@52220 709 case vmIntrinsics::_compareAndExchangeReference: return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange, Volatile);
mchung@52220 710 case vmIntrinsics::_compareAndExchangeReferenceAcquire: return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange, Acquire);
mchung@52220 711 case vmIntrinsics::_compareAndExchangeReferenceRelease: return inline_unsafe_load_store(T_OBJECT, LS_cmp_exchange, Release);
mchung@52220 712 case vmIntrinsics::_compareAndExchangeByte: return inline_unsafe_load_store(T_BYTE, LS_cmp_exchange, Volatile);
mchung@52220 713 case vmIntrinsics::_compareAndExchangeByteAcquire: return inline_unsafe_load_store(T_BYTE, LS_cmp_exchange, Acquire);
mchung@52220 714 case vmIntrinsics::_compareAndExchangeByteRelease: return inline_unsafe_load_store(T_BYTE, LS_cmp_exchange, Release);
mchung@52220 715 case vmIntrinsics::_compareAndExchangeShort: return inline_unsafe_load_store(T_SHORT, LS_cmp_exchange, Volatile);
mchung@52220 716 case vmIntrinsics::_compareAndExchangeShortAcquire: return inline_unsafe_load_store(T_SHORT, LS_cmp_exchange, Acquire);
mchung@52220 717 case vmIntrinsics::_compareAndExchangeShortRelease: return inline_unsafe_load_store(T_SHORT, LS_cmp_exchange, Release);
mchung@52220 718 case vmIntrinsics::_compareAndExchangeInt: return inline_unsafe_load_store(T_INT, LS_cmp_exchange, Volatile);
mchung@52220 719 case vmIntrinsics::_compareAndExchangeIntAcquire: return inline_unsafe_load_store(T_INT, LS_cmp_exchange, Acquire);
mchung@52220 720 case vmIntrinsics::_compareAndExchangeIntRelease: return inline_unsafe_load_store(T_INT, LS_cmp_exchange, Release);
mchung@52220 721 case vmIntrinsics::_compareAndExchangeLong: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Volatile);
mchung@52220 722 case vmIntrinsics::_compareAndExchangeLongAcquire: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Acquire);
mchung@52220 723 case vmIntrinsics::_compareAndExchangeLongRelease: return inline_unsafe_load_store(T_LONG, LS_cmp_exchange, Release);
shade@36316 724
shade@39419 725 case vmIntrinsics::_getAndAddByte: return inline_unsafe_load_store(T_BYTE, LS_get_add, Volatile);
shade@39419 726 case vmIntrinsics::_getAndAddShort: return inline_unsafe_load_store(T_SHORT, LS_get_add, Volatile);
shade@36316 727 case vmIntrinsics::_getAndAddInt: return inline_unsafe_load_store(T_INT, LS_get_add, Volatile);
shade@36316 728 case vmIntrinsics::_getAndAddLong: return inline_unsafe_load_store(T_LONG, LS_get_add, Volatile);
shade@39419 729
shade@39419 730 case vmIntrinsics::_getAndSetByte: return inline_unsafe_load_store(T_BYTE, LS_get_set, Volatile);
shade@39419 731 case vmIntrinsics::_getAndSetShort: return inline_unsafe_load_store(T_SHORT, LS_get_set, Volatile);
shade@36316 732 case vmIntrinsics::_getAndSetInt: return inline_unsafe_load_store(T_INT, LS_get_set, Volatile);
shade@36316 733 case vmIntrinsics::_getAndSetLong: return inline_unsafe_load_store(T_LONG, LS_get_set, Volatile);
mchung@52220 734 case vmIntrinsics::_getAndSetReference: return inline_unsafe_load_store(T_OBJECT, LS_get_set, Volatile);
twisti@14621 735
kvn@14832 736 case vmIntrinsics::_loadFence:
kvn@14832 737 case vmIntrinsics::_storeFence:
kvn@14832 738 case vmIntrinsics::_fullFence: return inline_unsafe_fence(intrinsic_id());
kvn@14832 739
ikrylov@38017 740 case vmIntrinsics::_onSpinWait: return inline_onspinwait();
ikrylov@38017 741
twisti@14621 742 case vmIntrinsics::_currentThread: return inline_native_currentThread();
twisti@14621 743 case vmIntrinsics::_isInterrupted: return inline_native_isInterrupted();
duke@1 744
egahlin@50113 745 #ifdef JFR_HAVE_INTRINSICS
egahlin@50113 746 case vmIntrinsics::_counterTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, JFR_TIME_FUNCTION), "counterTime");
rehn@40899 747 case vmIntrinsics::_getClassId: return inline_native_classID();
egahlin@50113 748 case vmIntrinsics::_getEventWriter: return inline_native_getEventWriter();
rbackman@12377 749 #endif
twisti@14621 750 case vmIntrinsics::_currentTimeMillis: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeMillis), "currentTimeMillis");
twisti@14621 751 case vmIntrinsics::_nanoTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeNanos), "nanoTime");
twisti@14621 752 case vmIntrinsics::_allocateInstance: return inline_unsafe_allocate();
twisti@14621 753 case vmIntrinsics::_copyMemory: return inline_unsafe_copyMemory();
twisti@14621 754 case vmIntrinsics::_getLength: return inline_native_getLength();
twisti@14621 755 case vmIntrinsics::_copyOf: return inline_array_copyOf(false);
twisti@14621 756 case vmIntrinsics::_copyOfRange: return inline_array_copyOf(true);
thartmann@33628 757 case vmIntrinsics::_equalsB: return inline_array_equals(StrIntrinsicNode::LL);
thartmann@33628 758 case vmIntrinsics::_equalsC: return inline_array_equals(StrIntrinsicNode::UU);
psandoz@38240 759 case vmIntrinsics::_Preconditions_checkIndex: return inline_preconditions_checkIndex();
twisti@14621 760 case vmIntrinsics::_clone: return inline_native_clone(intrinsic()->is_virtual());
twisti@14621 761
shade@36553 762 case vmIntrinsics::_allocateUninitializedArray: return inline_unsafe_newArray(true);
shade@36553 763 case vmIntrinsics::_newArray: return inline_unsafe_newArray(false);
shade@36553 764
twisti@14621 765 case vmIntrinsics::_isAssignableFrom: return inline_native_subtype_check();
duke@1 766
duke@1 767 case vmIntrinsics::_isInstance:
duke@1 768 case vmIntrinsics::_getModifiers:
duke@1 769 case vmIntrinsics::_isInterface:
duke@1 770 case vmIntrinsics::_isArray:
duke@1 771 case vmIntrinsics::_isPrimitive:
duke@1 772 case vmIntrinsics::_getSuperclass:
twisti@14621 773 case vmIntrinsics::_getClassAccessFlags: return inline_native_Class_query(intrinsic_id());
duke@1 774
duke@1 775 case vmIntrinsics::_floatToRawIntBits:
duke@1 776 case vmIntrinsics::_floatToIntBits:
duke@1 777 case vmIntrinsics::_intBitsToFloat:
duke@1 778 case vmIntrinsics::_doubleToRawLongBits:
duke@1 779 case vmIntrinsics::_doubleToLongBits:
twisti@14621 780 case vmIntrinsics::_longBitsToDouble: return inline_fp_conversions(intrinsic_id());
duke@1 781
twisti@2862 782 case vmIntrinsics::_numberOfLeadingZeros_i:
twisti@2862 783 case vmIntrinsics::_numberOfLeadingZeros_l:
twisti@2862 784 case vmIntrinsics::_numberOfTrailingZeros_i:
twisti@2862 785 case vmIntrinsics::_numberOfTrailingZeros_l:
twisti@2255 786 case vmIntrinsics::_bitCount_i:
twisti@2255 787 case vmIntrinsics::_bitCount_l:
duke@1 788 case vmIntrinsics::_reverseBytes_i:
duke@1 789 case vmIntrinsics::_reverseBytes_l:
never@5352 790 case vmIntrinsics::_reverseBytes_s:
twisti@14621 791 case vmIntrinsics::_reverseBytes_c: return inline_number_methods(intrinsic_id());
twisti@14621 792
twisti@14621 793 case vmIntrinsics::_getCallerClass: return inline_native_Reflection_getCallerClass();
twisti@14621 794
twisti@14621 795 case vmIntrinsics::_Reference_get: return inline_reference_get();
johnc@9176 796
kvn@27450 797 case vmIntrinsics::_Class_cast: return inline_Class_cast();
kvn@27450 798
kvn@14132 799 case vmIntrinsics::_aescrypt_encryptBlock:
twisti@14621 800 case vmIntrinsics::_aescrypt_decryptBlock: return inline_aescrypt_Block(intrinsic_id());
kvn@14132 801
kvn@14132 802 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
kvn@14132 803 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
kvn@14132 804 return inline_cipherBlockChaining_AESCrypt(intrinsic_id());
kvn@14132 805
kvn@35154 806 case vmIntrinsics::_counterMode_AESCrypt:
kvn@35154 807 return inline_counterMode_AESCrypt(intrinsic_id());
kvn@35154 808
kvn@24953 809 case vmIntrinsics::_sha_implCompress:
kvn@24953 810 case vmIntrinsics::_sha2_implCompress:
kvn@24953 811 case vmIntrinsics::_sha5_implCompress:
kvn@24953 812 return inline_sha_implCompress(intrinsic_id());
kvn@24953 813
kvn@24953 814 case vmIntrinsics::_digestBase_implCompressMB:
kvn@24953 815 return inline_digestBase_implCompressMB(predicate);
kvn@24953 816
kvn@26434 817 case vmIntrinsics::_multiplyToLen:
kvn@26434 818 return inline_multiplyToLen();
kvn@26434 819
kvn@31129 820 case vmIntrinsics::_squareToLen:
kvn@31129 821 return inline_squareToLen();
kvn@31129 822
kvn@31129 823 case vmIntrinsics::_mulAdd:
kvn@31129 824 return inline_mulAdd();
kvn@31129 825
aph@31583 826 case vmIntrinsics::_montgomeryMultiply:
aph@31583 827 return inline_montgomeryMultiply();
aph@31583 828 case vmIntrinsics::_montgomerySquare:
aph@31583 829 return inline_montgomerySquare();
aph@31583 830
kvn@35110 831 case vmIntrinsics::_vectorizedMismatch:
kvn@35110 832 return inline_vectorizedMismatch();
kvn@35110 833
ascarpino@31404 834 case vmIntrinsics::_ghash_processBlocks:
ascarpino@31404 835 return inline_ghash_processBlocks();
kvn@50860 836 case vmIntrinsics::_base64_encodeBlock:
kvn@50860 837 return inline_base64_encodeBlock();
ascarpino@31404 838
kvn@15242 839 case vmIntrinsics::_encodeISOArray:
thartmann@33628 840 case vmIntrinsics::_encodeByteISOArray:
kvn@15242 841 return inline_encodeISOArray();
kvn@15242 842
drchase@18507 843 case vmIntrinsics::_updateCRC32:
drchase@18507 844 return inline_updateCRC32();
drchase@18507 845 case vmIntrinsics::_updateBytesCRC32:
drchase@18507 846 return inline_updateBytesCRC32();
drchase@18507 847 case vmIntrinsics::_updateByteBufferCRC32:
drchase@18507 848 return inline_updateByteBufferCRC32();
drchase@18507 849
kvn@31515 850 case vmIntrinsics::_updateBytesCRC32C:
kvn@31515 851 return inline_updateBytesCRC32C();
kvn@31515 852 case vmIntrinsics::_updateDirectByteBufferCRC32C:
kvn@31515 853 return inline_updateDirectByteBufferCRC32C();
kvn@31515 854
kvn@32581 855 case vmIntrinsics::_updateBytesAdler32:
kvn@32581 856 return inline_updateBytesAdler32();
kvn@32581 857 case vmIntrinsics::_updateByteBufferAdler32:
kvn@32581 858 return inline_updateByteBufferAdler32();
kvn@32581 859
vlivanov@28912 860 case vmIntrinsics::_profileBoolean:
vlivanov@28912 861 return inline_profileBoolean();
vlivanov@30189 862 case vmIntrinsics::_isCompileConstant:
vlivanov@30189 863 return inline_isCompileConstant();
vlivanov@28912 864
thartmann@33628 865 case vmIntrinsics::_hasNegatives:
thartmann@33628 866 return inline_hasNegatives();
thartmann@33628 867
vdeshpande@41323 868 case vmIntrinsics::_fmaD:
vdeshpande@41323 869 case vmIntrinsics::_fmaF:
vdeshpande@41323 870 return inline_fma(intrinsic_id());
vdeshpande@41323 871
mhorie@52979 872 case vmIntrinsics::_isDigit:
mhorie@52979 873 case vmIntrinsics::_isLowerCase:
mhorie@52979 874 case vmIntrinsics::_isUpperCase:
mhorie@52979 875 case vmIntrinsics::_isWhitespace:
mhorie@52979 876 return inline_character_compare(intrinsic_id());
mhorie@52979 877
pli@53041 878 case vmIntrinsics::_maxF:
pli@53041 879 case vmIntrinsics::_minF:
pli@53041 880 case vmIntrinsics::_maxD:
pli@53041 881 case vmIntrinsics::_minD:
pli@53041 882 return inline_fp_min_max(intrinsic_id());
pli@53041 883
duke@1 884 default:
duke@1 885 // If you get here, it may be that someone has added a new intrinsic
duke@1 886 // to the list in vmSymbols.hpp without implementing it here.
duke@1 887 #ifndef PRODUCT
duke@1 888 if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) {
duke@1 889 tty->print_cr("*** Warning: Unimplemented intrinsic %s(%d)",
duke@1 890 vmIntrinsics::name_at(intrinsic_id()), intrinsic_id());
duke@1 891 }
duke@1 892 #endif
duke@1 893 return false;
duke@1 894 }
duke@1 895 }
duke@1 896
kvn@24948 897 Node* LibraryCallKit::try_to_predicate(int predicate) {
kvn@14132 898 if (!jvms()->has_method()) {
kvn@14132 899 // Root JVMState has a null method.
kvn@14132 900 assert(map()->memory()->Opcode() == Op_Parm, "");
kvn@14132 901 // Insert the memory aliasing node
kvn@14132 902 set_all_memory(reset_memory());
kvn@14132 903 }
kvn@14132 904 assert(merged_memory(), "");
kvn@14132 905
kvn@14132 906 switch (intrinsic_id()) {
kvn@14132 907 case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt:
kvn@14132 908 return inline_cipherBlockChaining_AESCrypt_predicate(false);
kvn@14132 909 case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt:
kvn@14132 910 return inline_cipherBlockChaining_AESCrypt_predicate(true);
kvn@35154 911 case vmIntrinsics::_counterMode_AESCrypt:
kvn@35154 912 return inline_counterMode_AESCrypt_predicate();
kvn@24953 913 case vmIntrinsics::_digestBase_implCompressMB:
kvn@24953 914 return inline_digestBase_implCompressMB_predicate(predicate);
kvn@14132 915
kvn@14132 916 default:
kvn@14132 917 // If you get here, it may be that someone has added a new intrinsic
kvn@14132 918 // to the list in vmSymbols.hpp without implementing it here.
kvn@14132 919 #ifndef PRODUCT
kvn@14132 920 if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) {
kvn@14132 921 tty->print_cr("*** Warning: Unimplemented predicate for intrinsic %s(%d)",
kvn@14132 922 vmIntrinsics::name_at(intrinsic_id()), intrinsic_id());
kvn@14132 923 }
kvn@14132 924 #endif
kvn@14132 925 Node* slow_ctl = control();
kvn@14132 926 set_control(top()); // No fast path instrinsic
kvn@14132 927 return slow_ctl;
kvn@14132 928 }
kvn@14132 929 }
kvn@14132 930
twisti@14621 931 //------------------------------set_result-------------------------------
duke@1 932 // Helper function for finishing intrinsics.
twisti@14621 933 void LibraryCallKit::set_result(RegionNode* region, PhiNode* value) {
duke@1 934 record_for_igvn(region);
duke@1 935 set_control(_gvn.transform(region));
twisti@14621 936 set_result( _gvn.transform(value));
twisti@14621 937 assert(value->type()->basic_type() == result()->bottom_type()->basic_type(), "sanity");
duke@1 938 }
duke@1 939
duke@1 940 //------------------------------generate_guard---------------------------
duke@1 941 // Helper function for generating guarded fast-slow graph structures.
duke@1 942 // The given 'test', if true, guards a slow path. If the test fails
duke@1 943 // then a fast path can be taken. (We generally hope it fails.)
duke@1 944 // In all cases, GraphKit::control() is updated to the fast path.
duke@1 945 // The returned value represents the control for the slow path.
duke@1 946 // The return value is never 'top'; it is either a valid control
duke@1 947 // or NULL if it is obvious that the slow path can never be taken.
duke@1 948 // Also, if region and the slow control are not NULL, the slow edge
duke@1 949 // is appended to the region.
duke@1 950 Node* LibraryCallKit::generate_guard(Node* test, RegionNode* region, float true_prob) {
duke@1 951 if (stopped()) {
duke@1 952 // Already short circuited.
duke@1 953 return NULL;
duke@1 954 }
duke@1 955
duke@1 956 // Build an if node and its projections.
duke@1 957 // If test is true we take the slow path, which we assume is uncommon.
duke@1 958 if (_gvn.type(test) == TypeInt::ZERO) {
duke@1 959 // The slow branch is never taken. No need to build this guard.
duke@1 960 return NULL;
duke@1 961 }
duke@1 962
duke@1 963 IfNode* iff = create_and_map_if(control(), test, true_prob, COUNT_UNKNOWN);
duke@1 964
thartmann@24923 965 Node* if_slow = _gvn.transform(new IfTrueNode(iff));
duke@1 966 if (if_slow == top()) {
duke@1 967 // The slow branch is never taken. No need to build this guard.
duke@1 968 return NULL;
duke@1 969 }
duke@1 970
duke@1 971 if (region != NULL)
duke@1 972 region->add_req(if_slow);
duke@1 973
thartmann@24923 974 Node* if_fast = _gvn.transform(new IfFalseNode(iff));
duke@1 975 set_control(if_fast);
duke@1 976
duke@1 977 return if_slow;
duke@1 978 }
duke@1 979
duke@1 980 inline Node* LibraryCallKit::generate_slow_guard(Node* test, RegionNode* region) {
duke@1 981 return generate_guard(test, region, PROB_UNLIKELY_MAG(3));
duke@1 982 }
duke@1 983 inline Node* LibraryCallKit::generate_fair_guard(Node* test, RegionNode* region) {
duke@1 984 return generate_guard(test, region, PROB_FAIR);
duke@1 985 }
duke@1 986
duke@1 987 inline Node* LibraryCallKit::generate_negative_guard(Node* index, RegionNode* region,
duke@1 988 Node* *pos_index) {
duke@1 989 if (stopped())
duke@1 990 return NULL; // already stopped
duke@1 991 if (_gvn.type(index)->higher_equal(TypeInt::POS)) // [0,maxint]
duke@1 992 return NULL; // index is already adequately typed
thartmann@24923 993 Node* cmp_lt = _gvn.transform(new CmpINode(index, intcon(0)));
thartmann@24923 994 Node* bol_lt = _gvn.transform(new BoolNode(cmp_lt, BoolTest::lt));
duke@1 995 Node* is_neg = generate_guard(bol_lt, region, PROB_MIN);
duke@1 996 if (is_neg != NULL && pos_index != NULL) {
duke@1 997 // Emulate effect of Parse::adjust_map_after_if.
thartmann@24923 998 Node* ccast = new CastIINode(index, TypeInt::POS);
duke@1 999 ccast->set_req(0, control());
duke@1 1000 (*pos_index) = _gvn.transform(ccast);
duke@1 1001 }
duke@1 1002 return is_neg;
duke@1 1003 }
duke@1 1004
duke@1 1005 // Make sure that 'position' is a valid limit index, in [0..length].
duke@1 1006 // There are two equivalent plans for checking this:
duke@1 1007 // A. (offset + copyLength) unsigned<= arrayLength
duke@1 1008 // B. offset <= (arrayLength - copyLength)
duke@1 1009 // We require that all of the values above, except for the sum and
duke@1 1010 // difference, are already known to be non-negative.
duke@1 1011 // Plan A is robust in the face of overflow, if offset and copyLength
duke@1 1012 // are both hugely positive.
duke@1 1013 //
duke@1 1014 // Plan B is less direct and intuitive, but it does not overflow at
duke@1 1015 // all, since the difference of two non-negatives is always
duke@1 1016 // representable. Whenever Java methods must perform the equivalent
duke@1 1017 // check they generally use Plan B instead of Plan A.
duke@1 1018 // For the moment we use Plan A.
duke@1 1019 inline Node* LibraryCallKit::generate_limit_guard(Node* offset,
duke@1 1020 Node* subseq_length,
duke@1 1021 Node* array_length,
duke@1 1022 RegionNode* region) {
duke@1 1023 if (stopped())
duke@1 1024 return NULL; // already stopped
duke@1 1025 bool zero_offset = _gvn.type(offset) == TypeInt::ZERO;
kvn@11446 1026 if (zero_offset && subseq_length->eqv_uncast(array_length))
duke@1 1027 return NULL; // common case of whole-array copy
duke@1 1028 Node* last = subseq_length;
duke@1 1029 if (!zero_offset) // last += offset
thartmann@24923 1030 last = _gvn.transform(new AddINode(last, offset));
thartmann@24923 1031 Node* cmp_lt = _gvn.transform(new CmpUNode(array_length, last));
thartmann@24923 1032 Node* bol_lt = _gvn.transform(new BoolNode(cmp_lt, BoolTest::lt));
duke@1 1033 Node* is_over = generate_guard(bol_lt, region, PROB_MIN);
duke@1 1034 return is_over;
duke@1 1035 }
duke@1 1036
thartmann@34499 1037 // Emit range checks for the given String.value byte array
thartmann@34499 1038 void LibraryCallKit::generate_string_range_check(Node* array, Node* offset, Node* count, bool char_count) {
thartmann@34499 1039 if (stopped()) {
thartmann@34499 1040 return; // already stopped
thartmann@34499 1041 }
thartmann@34499 1042 RegionNode* bailout = new RegionNode(1);
thartmann@34499 1043 record_for_igvn(bailout);
thartmann@34499 1044 if (char_count) {
thartmann@34499 1045 // Convert char count to byte count
thartmann@34499 1046 count = _gvn.transform(new LShiftINode(count, intcon(1)));
thartmann@34499 1047 }
thartmann@34499 1048
thartmann@34499 1049 // Offset and count must not be negative
thartmann@34499 1050 generate_negative_guard(offset, bailout);
thartmann@34499 1051 generate_negative_guard(count, bailout);
thartmann@34499 1052 // Offset + count must not exceed length of array
thartmann@34499 1053 generate_limit_guard(offset, count, load_array_length(array), bailout);
thartmann@34499 1054
thartmann@34499 1055 if (bailout->req() > 1) {
thartmann@34499 1056 PreserveJVMState pjvms(this);
thartmann@34499 1057 set_control(_gvn.transform(bailout));
thartmann@34499 1058 uncommon_trap(Deoptimization::Reason_intrinsic,
thartmann@34499 1059 Deoptimization::Action_maybe_recompile);
thartmann@34499 1060 }
thartmann@34499 1061 }
duke@1 1062
duke@1 1063 //--------------------------generate_current_thread--------------------
duke@1 1064 Node* LibraryCallKit::generate_current_thread(Node* &tls_output) {
duke@1 1065 ciKlass* thread_klass = env()->Thread_klass();
duke@1 1066 const Type* thread_type = TypeOopPtr::make_from_klass(thread_klass)->cast_to_ptr_type(TypePtr::NotNull);
thartmann@24923 1067 Node* thread = _gvn.transform(new ThreadLocalNode());
duke@1 1068 Node* p = basic_plus_adr(top()/*!oop*/, thread, in_bytes(JavaThread::threadObj_offset()));
goetz@22845 1069 Node* threadObj = make_load(NULL, p, thread_type, T_OBJECT, MemNode::unordered);
duke@1 1070 tls_output = thread;
duke@1 1071 return threadObj;
duke@1 1072 }
duke@1 1073
duke@1 1074
kvn@3905 1075 //------------------------------make_string_method_node------------------------
thartmann@33628 1076 // Helper method for String intrinsic functions. This version is called with
thartmann@33628 1077 // str1 and str2 pointing to byte[] nodes containing Latin1 or UTF16 encoded
thartmann@33628 1078 // characters (depending on 'is_byte'). cnt1 and cnt2 are pointing to Int nodes
thartmann@33628 1079 // containing the lengths of str1 and str2.
thartmann@33628 1080 Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2, StrIntrinsicNode::ArgEnc ae) {
kvn@3905 1081 Node* result = NULL;
kvn@3905 1082 switch (opcode) {
kvn@3905 1083 case Op_StrIndexOf:
thartmann@33628 1084 result = new StrIndexOfNode(control(), memory(TypeAryPtr::BYTES),
thartmann@33628 1085 str1_start, cnt1, str2_start, cnt2, ae);
kvn@3905 1086 break;
kvn@3905 1087 case Op_StrComp:
thartmann@33628 1088 result = new StrCompNode(control(), memory(TypeAryPtr::BYTES),
thartmann@33628 1089 str1_start, cnt1, str2_start, cnt2, ae);
kvn@3905 1090 break;
kvn@3905 1091 case Op_StrEquals:
simonis@35581 1092 // We already know that cnt1 == cnt2 here (checked in 'inline_string_equals').
simonis@35581 1093 // Use the constant length if there is one because optimized match rule may exist.
thartmann@33628 1094 result = new StrEqualsNode(control(), memory(TypeAryPtr::BYTES),
simonis@35581 1095 str1_start, str2_start, cnt2->is_Con() ? cnt2 : cnt1, ae);
kvn@3905 1096 break;
kvn@3905 1097 default:
kvn@3905 1098 ShouldNotReachHere();
kvn@3905 1099 return NULL;
kvn@3905 1100 }
kvn@3905 1101
kvn@3905 1102 // All these intrinsics have checks.
kvn@3905 1103 C->set_has_split_ifs(true); // Has chance for split-if optimization
vdeshpande@48371 1104 clear_upper_avx();
kvn@3905 1105
kvn@3905 1106 return _gvn.transform(result);
kvn@3905 1107 }
kvn@3905 1108
duke@1 1109 //------------------------------inline_string_compareTo------------------------
thartmann@33628 1110 bool LibraryCallKit::inline_string_compareTo(StrIntrinsicNode::ArgEnc ae) {
thartmann@33628 1111 Node* arg1 = argument(0);
thartmann@33628 1112 Node* arg2 = argument(1);
thartmann@33628 1113
roland@51483 1114 arg1 = must_be_not_null(arg1, true);
roland@51483 1115 arg2 = must_be_not_null(arg2, true);
roland@51483 1116
rkennke@51705 1117 arg1 = access_resolve(arg1, ACCESS_READ);
rkennke@51705 1118 arg2 = access_resolve(arg2, ACCESS_READ);
rkennke@51705 1119
thartmann@33628 1120 // Get start addr and length of first argument
thartmann@33628 1121 Node* arg1_start = array_element_address(arg1, intcon(0), T_BYTE);
thartmann@33628 1122 Node* arg1_cnt = load_array_length(arg1);
thartmann@33628 1123
thartmann@33628 1124 // Get start addr and length of second argument
thartmann@33628 1125 Node* arg2_start = array_element_address(arg2, intcon(0), T_BYTE);
thartmann@33628 1126 Node* arg2_cnt = load_array_length(arg2);
thartmann@33628 1127
thartmann@33628 1128 Node* result = make_string_method_node(Op_StrComp, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae);
thartmann@33628 1129 set_result(result);
duke@1 1130 return true;
duke@1 1131 }
duke@1 1132
cfang@2348 1133 //------------------------------inline_string_equals------------------------
thartmann@33628 1134 bool LibraryCallKit::inline_string_equals(StrIntrinsicNode::ArgEnc ae) {
thartmann@33628 1135 Node* arg1 = argument(0);
thartmann@33628 1136 Node* arg2 = argument(1);
cfang@2348 1137
kvn@3905 1138 // paths (plus control) merge
thartmann@33628 1139 RegionNode* region = new RegionNode(3);
thartmann@24923 1140 Node* phi = new PhiNode(region, TypeInt::BOOL);
kvn@3905 1141
kvn@3905 1142 if (!stopped()) {
roland@51483 1143
roland@51483 1144 arg1 = must_be_not_null(arg1, true);
roland@51483 1145 arg2 = must_be_not_null(arg2, true);
roland@51483 1146
rkennke@51705 1147 arg1 = access_resolve(arg1, ACCESS_READ);
rkennke@51705 1148 arg2 = access_resolve(arg2, ACCESS_READ);
rkennke@51705 1149
thartmann@33628 1150 // Get start addr and length of first argument
thartmann@33628 1151 Node* arg1_start = array_element_address(arg1, intcon(0), T_BYTE);
thartmann@33628 1152 Node* arg1_cnt = load_array_length(arg1);
thartmann@33628 1153
thartmann@33628 1154 // Get start addr and length of second argument
thartmann@33628 1155 Node* arg2_start = array_element_address(arg2, intcon(0), T_BYTE);
thartmann@33628 1156 Node* arg2_cnt = load_array_length(arg2);
thartmann@33628 1157
thartmann@33628 1158 // Check for arg1_cnt != arg2_cnt
thartmann@33628 1159 Node* cmp = _gvn.transform(new CmpINode(arg1_cnt, arg2_cnt));
thartmann@24923 1160 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne));
kvn@3905 1161 Node* if_ne = generate_slow_guard(bol, NULL);
kvn@3905 1162 if (if_ne != NULL) {
thartmann@33628 1163 phi->init_req(2, intcon(0));
thartmann@33628 1164 region->init_req(2, if_ne);
kvn@3905 1165 }
kvn@12623 1166
kvn@12623 1167 // Check for count == 0 is done by assembler code for StrEquals.
kvn@12623 1168
kvn@12623 1169 if (!stopped()) {
thartmann@33628 1170 Node* equals = make_string_method_node(Op_StrEquals, arg1_start, arg1_cnt, arg2_start, arg2_cnt, ae);
kvn@12623 1171 phi->init_req(1, equals);
kvn@12623 1172 region->init_req(1, control());
kvn@12623 1173 }
kvn@3905 1174 }
cfang@2348 1175
cfang@2348 1176 // post merge
cfang@2348 1177 set_control(_gvn.transform(region));
cfang@2348 1178 record_for_igvn(region);
cfang@2348 1179
twisti@14621 1180 set_result(_gvn.transform(phi));
cfang@2348 1181 return true;
cfang@2348 1182 }
cfang@2348 1183
rasbold@595 1184 //------------------------------inline_array_equals----------------------------
thartmann@33628 1185 bool LibraryCallKit::inline_array_equals(StrIntrinsicNode::ArgEnc ae) {
thartmann@33628 1186 assert(ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::LL, "unsupported array types");
twisti@14621 1187 Node* arg1 = argument(0);
twisti@14621 1188 Node* arg2 = argument(1);
thartmann@33628 1189
rkennke@51705 1190 arg1 = access_resolve(arg1, ACCESS_READ);
rkennke@51705 1191 arg2 = access_resolve(arg2, ACCESS_READ);
rkennke@51705 1192
thartmann@33628 1193 const TypeAryPtr* mtype = (ae == StrIntrinsicNode::UU) ? TypeAryPtr::CHARS : TypeAryPtr::BYTES;
thartmann@33628 1194 set_result(_gvn.transform(new AryEqNode(control(), memory(mtype), arg1, arg2, ae)));
vdeshpande@48371 1195 clear_upper_avx();
vdeshpande@48371 1196
rasbold@595 1197 return true;
rasbold@595 1198 }
rasbold@595 1199
thartmann@33628 1200 //------------------------------inline_hasNegatives------------------------------
thartmann@33628 1201 bool LibraryCallKit::inline_hasNegatives() {
thartmann@34499 1202 if (too_many_traps(Deoptimization::Reason_intrinsic)) {
thartmann@34499 1203 return false;
thartmann@34499 1204 }
thartmann@33628 1205
thartmann@33628 1206 assert(callee()->signature()->size() == 3, "hasNegatives has 3 parameters");
thartmann@33628 1207 // no receiver since it is static method
thartmann@33628 1208 Node* ba = argument(0);
thartmann@33628 1209 Node* offset = argument(1);
thartmann@33628 1210 Node* len = argument(2);
thartmann@33628 1211
roland@51483 1212 ba = must_be_not_null(ba, true);
roland@51483 1213
thartmann@34499 1214 // Range checks
thartmann@34499 1215 generate_string_range_check(ba, offset, len, false);
thartmann@34499 1216 if (stopped()) {
thartmann@34499 1217 return true;
thartmann@34499 1218 }
rkennke@51705 1219 ba = access_resolve(ba, ACCESS_READ);
thartmann@34499 1220 Node* ba_start = array_element_address(ba, offset, T_BYTE);
thartmann@34499 1221 Node* result = new HasNegativesNode(control(), memory(TypeAryPtr::BYTES), ba_start, len);
thartmann@34499 1222 set_result(_gvn.transform(result));
thartmann@33628 1223 return true;
duke@1 1224 }
duke@1 1225
psandoz@38240 1226 bool LibraryCallKit::inline_preconditions_checkIndex() {
roland@34180 1227 Node* index = argument(0);
roland@34180 1228 Node* length = argument(1);
roland@34180 1229 if (too_many_traps(Deoptimization::Reason_intrinsic) || too_many_traps(Deoptimization::Reason_range_check)) {
roland@34180 1230 return false;
roland@34180 1231 }
roland@34180 1232
roland@34180 1233 Node* len_pos_cmp = _gvn.transform(new CmpINode(length, intcon(0)));
roland@34180 1234 Node* len_pos_bol = _gvn.transform(new BoolNode(len_pos_cmp, BoolTest::ge));
roland@34180 1235
roland@34180 1236 {
roland@34180 1237 BuildCutout unless(this, len_pos_bol, PROB_MAX);
roland@34180 1238 uncommon_trap(Deoptimization::Reason_intrinsic,
roland@34180 1239 Deoptimization::Action_make_not_entrant);
roland@34180 1240 }
roland@34180 1241
roland@34180 1242 if (stopped()) {
roland@34180 1243 return false;
roland@34180 1244 }
roland@34180 1245
roland@34180 1246 Node* rc_cmp = _gvn.transform(new CmpUNode(index, length));
roland@34180 1247 BoolTest::mask btest = BoolTest::lt;
roland@34180 1248 Node* rc_bool = _gvn.transform(new BoolNode(rc_cmp, btest));
roland@34180 1249 RangeCheckNode* rc = new RangeCheckNode(control(), rc_bool, PROB_MAX, COUNT_UNKNOWN);
roland@34180 1250 _gvn.set_type(rc, rc->Value(&_gvn));
roland@34180 1251 if (!rc_bool->is_Con()) {
roland@34180 1252 record_for_igvn(rc);
roland@34180 1253 }
roland@34180 1254 set_control(_gvn.transform(new IfTrueNode(rc)));
roland@34180 1255 {
roland@34180 1256 PreserveJVMState pjvms(this);
roland@34180 1257 set_control(_gvn.transform(new IfFalseNode(rc)));
roland@34180 1258 uncommon_trap(Deoptimization::Reason_range_check,
roland@34180 1259 Deoptimization::Action_make_not_entrant);
roland@34180 1260 }
roland@34180 1261
roland@34180 1262 if (stopped()) {
roland@34180 1263 return false;
roland@34180 1264 }
roland@34180 1265
roland@34180 1266 Node* result = new CastIINode(index, TypeInt::make(0, _gvn.type(length)->is_int()->_hi, Type::WidenMax));
roland@34180 1267 result->set_req(0, control());
roland@34180 1268 result = _gvn.transform(result);
roland@34180 1269 set_result(result);
roland@34180 1270 replace_in_map(index, result);
vdeshpande@48371 1271 clear_upper_avx();
roland@34180 1272 return true;
roland@34180 1273 }
roland@34180 1274
duke@1 1275 //------------------------------inline_string_indexOf------------------------
thartmann@33628 1276 bool LibraryCallKit::inline_string_indexOf(StrIntrinsicNode::ArgEnc ae) {
simonis@35581 1277 if (!Matcher::match_rule_supported(Op_StrIndexOf)) {
thartmann@33628 1278 return false;
thartmann@33628 1279 }
thartmann@33628 1280 Node* src = argument(0);
thartmann@33628 1281 Node* tgt = argument(1);
thartmann@33628 1282
thartmann@33628 1283 // Make the merge point
thartmann@33628 1284 RegionNode* result_rgn = new RegionNode(4);
thartmann@33628 1285 Node* result_phi = new PhiNode(result_rgn, TypeInt::INT);
thartmann@33628 1286
roland@51483 1287 src = must_be_not_null(src, true);
roland@51483 1288 tgt = must_be_not_null(tgt, true);
roland@51483 1289
rkennke@51705 1290 src = access_resolve(src, ACCESS_READ);
rkennke@51705 1291 tgt = access_resolve(tgt, ACCESS_READ);
rkennke@51705 1292
thartmann@33628 1293 // Get start addr and length of source string
thartmann@33628 1294 Node* src_start = array_element_address(src, intcon(0), T_BYTE);
thartmann@33628 1295 Node* src_count = load_array_length(src);
thartmann@33628 1296
thartmann@33628 1297 // Get start addr and length of substring
thartmann@33628 1298 Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE);
thartmann@33628 1299 Node* tgt_count = load_array_length(tgt);
thartmann@33628 1300
thartmann@33628 1301 if (ae == StrIntrinsicNode::UU || ae == StrIntrinsicNode::UL) {
thartmann@33628 1302 // Divide src size by 2 if String is UTF16 encoded
thartmann@33628 1303 src_count = _gvn.transform(new RShiftINode(src_count, intcon(1)));
thartmann@33628 1304 }
thartmann@33628 1305 if (ae == StrIntrinsicNode::UU) {
thartmann@33628 1306 // Divide substring size by 2 if String is UTF16 encoded
thartmann@33628 1307 tgt_count = _gvn.transform(new RShiftINode(tgt_count, intcon(1)));
thartmann@33628 1308 }
thartmann@33628 1309
thartmann@34499 1310 Node* result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count, result_rgn, result_phi, ae);
thartmann@34499 1311 if (result != NULL) {
thartmann@34499 1312 result_phi->init_req(3, result);
thartmann@34499 1313 result_rgn->init_req(3, control());
thartmann@34499 1314 }
thartmann@34499 1315 set_control(_gvn.transform(result_rgn));
thartmann@34499 1316 record_for_igvn(result_rgn);
thartmann@34499 1317 set_result(_gvn.transform(result_phi));
thartmann@34499 1318
thartmann@34499 1319 return true;
thartmann@34499 1320 }
thartmann@34499 1321
thartmann@34499 1322 //-----------------------------inline_string_indexOf-----------------------
thartmann@34499 1323 bool LibraryCallKit::inline_string_indexOfI(StrIntrinsicNode::ArgEnc ae) {
thartmann@34499 1324 if (too_many_traps(Deoptimization::Reason_intrinsic)) {
thartmann@34499 1325 return false;
thartmann@34499 1326 }
simonis@35581 1327 if (!Matcher::match_rule_supported(Op_StrIndexOf)) {
thartmann@34499 1328 return false;
thartmann@34499 1329 }
thartmann@34499 1330 assert(callee()->signature()->size() == 5, "String.indexOf() has 5 arguments");
thartmann@34499 1331 Node* src = argument(0); // byte[]
thartmann@34499 1332 Node* src_count = argument(1); // char count
thartmann@34499 1333 Node* tgt = argument(2); // byte[]
thartmann@34499 1334 Node* tgt_count = argument(3); // char count
thartmann@34499 1335 Node* from_index = argument(4); // char index
thartmann@34499 1336
roland@51483 1337 src = must_be_not_null(src, true);
roland@51483 1338 tgt = must_be_not_null(tgt, true);
roland@51483 1339
rkennke@51705 1340 src = access_resolve(src, ACCESS_READ);
rkennke@51705 1341 tgt = access_resolve(tgt, ACCESS_READ);
rkennke@51705 1342
thartmann@34499 1343 // Multiply byte array index by 2 if String is UTF16 encoded
thartmann@34499 1344 Node* src_offset = (ae == StrIntrinsicNode::LL) ? from_index : _gvn.transform(new LShiftINode(from_index, intcon(1)));
thartmann@34499 1345 src_count = _gvn.transform(new SubINode(src_count, from_index));
thartmann@34499 1346 Node* src_start = array_element_address(src, src_offset, T_BYTE);
thartmann@34499 1347 Node* tgt_start = array_element_address(tgt, intcon(0), T_BYTE);
thartmann@34499 1348
thartmann@34499 1349 // Range checks
thartmann@34499 1350 generate_string_range_check(src, src_offset, src_count, ae != StrIntrinsicNode::LL);
thartmann@34499 1351 generate_string_range_check(tgt, intcon(0), tgt_count, ae == StrIntrinsicNode::UU);
thartmann@34499 1352 if (stopped()) {
thartmann@34499 1353 return true;
thartmann@34499 1354 }
thartmann@34499 1355
thartmann@34499 1356 RegionNode* region = new RegionNode(5);
thartmann@34499 1357 Node* phi = new PhiNode(region, TypeInt::INT);
thartmann@34499 1358
thartmann@34499 1359 Node* result = make_indexOf_node(src_start, src_count, tgt_start, tgt_count, region, phi, ae);
thartmann@34499 1360 if (result != NULL) {
thartmann@34499 1361 // The result is index relative to from_index if substring was found, -1 otherwise.
thartmann@34499 1362 // Generate code which will fold into cmove.
thartmann@34499 1363 Node* cmp = _gvn.transform(new CmpINode(result, intcon(0)));
thartmann@34499 1364 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::lt));
thartmann@34499 1365
thartmann@34499 1366 Node* if_lt = generate_slow_guard(bol, NULL);
thartmann@34499 1367 if (if_lt != NULL) {
thartmann@34499 1368 // result == -1
thartmann@34499 1369 phi->init_req(3, result);
thartmann@34499 1370 region->init_req(3, if_lt);
thartmann@34499 1371 }
thartmann@34499 1372 if (!stopped()) {
thartmann@34499 1373 result = _gvn.transform(new AddINode(result, from_index));
thartmann@34499 1374 phi->init_req(4, result);
thartmann@34499 1375 region->init_req(4, control());
thartmann@34499 1376 }
thartmann@34499 1377 }
thartmann@34499 1378
thartmann@34499 1379 set_control(_gvn.transform(region));
thartmann@34499 1380 record_for_igvn(region);
thartmann@34499 1381 set_result(_gvn.transform(phi));
vdeshpande@48371 1382 clear_upper_avx();
thartmann@34499 1383
thartmann@34499 1384 return true;
thartmann@34499 1385 }
thartmann@34499 1386
thartmann@34499 1387 // Create StrIndexOfNode with fast path checks
thartmann@34499 1388 Node* LibraryCallKit::make_indexOf_node(Node* src_start, Node* src_count, Node* tgt_start, Node* tgt_count,
thartmann@34499 1389 RegionNode* region, Node* phi, StrIntrinsicNode::ArgEnc ae) {
thartmann@33628 1390 // Check for substr count > string count
thartmann@33628 1391 Node* cmp = _gvn.transform(new CmpINode(tgt_count, src_count));
thartmann@33628 1392 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::gt));
thartmann@33628 1393 Node* if_gt = generate_slow_guard(bol, NULL);
thartmann@33628 1394 if (if_gt != NULL) {
thartmann@34499 1395 phi->init_req(1, intcon(-1));
thartmann@34499 1396 region->init_req(1, if_gt);
thartmann@34499 1397 }
thartmann@33628 1398 if (!stopped()) {
thartmann@33628 1399 // Check for substr count == 0
thartmann@33628 1400 cmp = _gvn.transform(new CmpINode(tgt_count, intcon(0)));
thartmann@33628 1401 bol = _gvn.transform(new BoolNode(cmp, BoolTest::eq));
thartmann@33628 1402 Node* if_zero = generate_slow_guard(bol, NULL);
thartmann@33628 1403 if (if_zero != NULL) {
thartmann@34499 1404 phi->init_req(2, intcon(0));
thartmann@34499 1405 region->init_req(2, if_zero);
cfang@2348 1406 }
thartmann@33628 1407 }
thartmann@33628 1408 if (!stopped()) {
thartmann@34499 1409 return make_string_method_node(Op_StrIndexOf, src_start, src_count, tgt_start, tgt_count, ae);
thartmann@34499 1410 }
thartmann@34499 1411 return NULL;
thartmann@33628 1412 }
thartmann@33628 1413
thartmann@33628 1414 //-----------------------------inline_string_indexOfChar-----------------------
thartmann@33628 1415 bool LibraryCallKit::inline_string_indexOfChar() {
thartmann@34499 1416 if (too_many_traps(Deoptimization::Reason_intrinsic)) {
thartmann@34499 1417 return false;
thartmann@34499 1418 }
simonis@35581 1419 if (!Matcher::match_rule_supported(Op_StrIndexOfChar)) {
thartmann@33628 1420 return false;
thartmann@33628 1421 }
thartmann@33628 1422 assert(callee()->signature()->size() == 4, "String.indexOfChar() has 4 arguments");
thartmann@33628 1423 Node* src = argument(0); // byte[]
thartmann@33628 1424 Node* tgt = argument(1); // tgt is int ch
thartmann@33628 1425 Node* from_index = argument(2);
thartmann@33628 1426 Node* max = argument(3);
thartmann@33628 1427
roland@51483 1428 src = must_be_not_null(src, true);
rkennke@51705 1429 src = access_resolve(src, ACCESS_READ);
roland@51483 1430
thartmann@33628 1431 Node* src_offset = _gvn.transform(new LShiftINode(from_index, intcon(1)));
thartmann@33628 1432 Node* src_start = array_element_address(src, src_offset, T_BYTE);
thartmann@33628 1433 Node* src_count = _gvn.transform(new SubINode(max, from_index));
thartmann@33628 1434
thartmann@34499 1435 // Range checks
thartmann@34499 1436 generate_string_range_check(src, src_offset, src_count, true);
thartmann@34499 1437 if (stopped()) {
thartmann@34499 1438 return true;
thartmann@34499 1439 }
thartmann@34499 1440
thartmann@33628 1441 RegionNode* region = new RegionNode(3);
thartmann@33628 1442 Node* phi = new PhiNode(region, TypeInt::INT);
thartmann@33628 1443
thartmann@33628 1444 Node* result = new StrIndexOfCharNode(control(), memory(TypeAryPtr::BYTES), src_start, src_count, tgt, StrIntrinsicNode::none);
thartmann@33628 1445 C->set_has_split_ifs(true); // Has chance for split-if optimization
thartmann@33628 1446 _gvn.transform(result);
thartmann@33628 1447
thartmann@33628 1448 Node* cmp = _gvn.transform(new CmpINode(result, intcon(0)));
thartmann@33628 1449 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::lt));
thartmann@33628 1450
thartmann@33628 1451 Node* if_lt = generate_slow_guard(bol, NULL);
thartmann@33628 1452 if (if_lt != NULL) {
thartmann@33628 1453 // result == -1
thartmann@33628 1454 phi->init_req(2, result);
thartmann@33628 1455 region->init_req(2, if_lt);
thartmann@33628 1456 }
thartmann@33628 1457 if (!stopped()) {
thartmann@33628 1458 result = _gvn.transform(new AddINode(result, from_index));
thartmann@33628 1459 phi->init_req(1, result);
thartmann@33628 1460 region->init_req(1, control());
thartmann@33628 1461 }
thartmann@33628 1462 set_control(_gvn.transform(region));
thartmann@33628 1463 record_for_igvn(region);
thartmann@33628 1464 set_result(_gvn.transform(phi));
thartmann@33628 1465
thartmann@33628 1466 return true;
thartmann@33628 1467 }
thartmann@33628 1468 //---------------------------inline_string_copy---------------------
thartmann@33628 1469 // compressIt == true --> generate a compressed copy operation (compress char[]/byte[] to byte[])
thartmann@33628 1470 // int StringUTF16.compress(char[] src, int srcOff, byte[] dst, int dstOff, int len)
thartmann@33628 1471 // int StringUTF16.compress(byte[] src, int srcOff, byte[] dst, int dstOff, int len)
thartmann@33628 1472 // compressIt == false --> generate an inflated copy operation (inflate byte[] to char[]/byte[])
thartmann@33628 1473 // void StringLatin1.inflate(byte[] src, int srcOff, char[] dst, int dstOff, int len)
thartmann@33628 1474 // void StringLatin1.inflate(byte[] src, int srcOff, byte[] dst, int dstOff, int len)
thartmann@33628 1475 bool LibraryCallKit::inline_string_copy(bool compress) {
thartmann@34499 1476 if (too_many_traps(Deoptimization::Reason_intrinsic)) {
thartmann@34499 1477 return false;
thartmann@34499 1478 }
thartmann@33628 1479 int nargs = 5; // 2 oops, 3 ints
thartmann@33628 1480 assert(callee()->signature()->size() == nargs, "string copy has 5 arguments");
thartmann@33628 1481
thartmann@33628 1482 Node* src = argument(0);
thartmann@33628 1483 Node* src_offset = argument(1);
thartmann@33628 1484 Node* dst = argument(2);
thartmann@33628 1485 Node* dst_offset = argument(3);
thartmann@33628 1486 Node* length = argument(4);
thartmann@33628 1487
thartmann@33628 1488 // Check for allocation before we add nodes that would confuse
thartmann@33628 1489 // tightly_coupled_allocation()
thartmann@33628 1490 AllocateArrayNode* alloc = tightly_coupled_allocation(dst, NULL);
thartmann@33628 1491
thartmann@33628 1492 // Figure out the size and type of the elements we will be copying.
thartmann@33628 1493 const Type* src_type = src->Value(&_gvn);
thartmann@33628 1494 const Type* dst_type = dst->Value(&_gvn);
thartmann@33628 1495 BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
thartmann@33628 1496 BasicType dst_elem = dst_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type();
thartmann@33628 1497 assert((compress && dst_elem == T_BYTE && (src_elem == T_BYTE || src_elem == T_CHAR)) ||
thartmann@33628 1498 (!compress && src_elem == T_BYTE && (dst_elem == T_BYTE || dst_elem == T_CHAR)),
thartmann@33628 1499 "Unsupported array types for inline_string_copy");
thartmann@33628 1500
roland@51483 1501 src = must_be_not_null(src, true);
roland@51483 1502 dst = must_be_not_null(dst, true);
roland@51483 1503
thartmann@40045 1504 // Convert char[] offsets to byte[] offsets
thartmann@40045 1505 bool convert_src = (compress && src_elem == T_BYTE);
thartmann@40045 1506 bool convert_dst = (!compress && dst_elem == T_BYTE);
thartmann@40045 1507 if (convert_src) {
thartmann@40045 1508 src_offset = _gvn.transform(new LShiftINode(src_offset, intcon(1)));
thartmann@40045 1509 } else if (convert_dst) {
thartmann@40045 1510 dst_offset = _gvn.transform(new LShiftINode(dst_offset, intcon(1)));
thartmann@40045 1511 }
thartmann@40045 1512
thartmann@34499 1513 // Range checks
thartmann@40045 1514 generate_string_range_check(src, src_offset, length, convert_src);
thartmann@40045 1515 generate_string_range_check(dst, dst_offset, length, convert_dst);
thartmann@34499 1516 if (stopped()) {
thartmann@34499 1517 return true;
thartmann@34499 1518 }
thartmann@34499 1519
rkennke@51705 1520 src = access_resolve(src, ACCESS_READ);
rkennke@51705 1521 dst = access_resolve(dst, ACCESS_WRITE);
rkennke@51705 1522
thartmann@33628 1523 Node* src_start = array_element_address(src, src_offset, src_elem);
thartmann@33628 1524 Node* dst_start = array_element_address(dst, dst_offset, dst_elem);
thartmann@33628 1525 // 'src_start' points to src array + scaled offset
thartmann@33628 1526 // 'dst_start' points to dst array + scaled offset
neliasso@33639 1527 Node* count = NULL;
thartmann@33628 1528 if (compress) {
thartmann@35573 1529 count = compress_string(src_start, TypeAryPtr::get_array_body_type(src_elem), dst_start, length);
thartmann@33628 1530 } else {
thartmann@35573 1531 inflate_string(src_start, dst_start, TypeAryPtr::get_array_body_type(dst_elem), length);
thartmann@33628 1532 }
thartmann@33628 1533
thartmann@33628 1534 if (alloc != NULL) {
thartmann@33628 1535 if (alloc->maybe_set_complete(&_gvn)) {
thartmann@33628 1536 // "You break it, you buy it."
thartmann@33628 1537 InitializeNode* init = alloc->initialization();
thartmann@33628 1538 assert(init->is_complete(), "we just did this");
thartmann@33628 1539 init->set_complete_with_arraycopy();
thartmann@33628 1540 assert(dst->is_CheckCastPP(), "sanity");
thartmann@33628 1541 assert(dst->in(0)->in(0) == init, "dest pinned");
kvn@3905 1542 }
thartmann@33628 1543 // Do not let stores that initialize this object be reordered with
thartmann@33628 1544 // a subsequent store that would make this object accessible by
thartmann@33628 1545 // other threads.
thartmann@33628 1546 // Record what AllocateNode this StoreStore protects so that
thartmann@33628 1547 // escape analysis can go from the MemBarStoreStoreNode to the
thartmann@33628 1548 // AllocateNode and eliminate the MemBarStoreStoreNode if possible
thartmann@33628 1549 // based on the escape status of the AllocateNode.
dlong@48595 1550 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress));
thartmann@33628 1551 }
thartmann@33628 1552 if (compress) {
thartmann@33628 1553 set_result(_gvn.transform(count));
thartmann@33628 1554 }
vdeshpande@48371 1555 clear_upper_avx();
vdeshpande@48371 1556
thartmann@33628 1557 return true;
thartmann@33628 1558 }
thartmann@33628 1559
thartmann@33628 1560 #ifdef _LP64
thartmann@33628 1561 #define XTOP ,top() /*additional argument*/
thartmann@33628 1562 #else //_LP64
thartmann@33628 1563 #define XTOP /*no additional argument*/
thartmann@33628 1564 #endif //_LP64
thartmann@33628 1565
thartmann@33628 1566 //------------------------inline_string_toBytesU--------------------------
thartmann@33628 1567 // public static byte[] StringUTF16.toBytes(char[] value, int off, int len)
thartmann@33628 1568 bool LibraryCallKit::inline_string_toBytesU() {
thartmann@34499 1569 if (too_many_traps(Deoptimization::Reason_intrinsic)) {
thartmann@34499 1570 return false;
thartmann@34499 1571 }
thartmann@33628 1572 // Get the arguments.
thartmann@33628 1573 Node* value = argument(0);
thartmann@33628 1574 Node* offset = argument(1);
thartmann@33628 1575 Node* length = argument(2);
thartmann@33628 1576
thartmann@33628 1577 Node* newcopy = NULL;
thartmann@33628 1578
thartmann@33628 1579 // Set the original stack and the reexecute bit for the interpreter to reexecute
thartmann@33628 1580 // the bytecode that invokes StringUTF16.toBytes() if deoptimization happens.
thartmann@33628 1581 { PreserveReexecuteState preexecs(this);
thartmann@33628 1582 jvms()->set_should_reexecute(true);
thartmann@33628 1583
thartmann@33628 1584 // Check if a null path was taken unconditionally.
thartmann@33628 1585 value = null_check(value);
thartmann@33628 1586
thartmann@33628 1587 RegionNode* bailout = new RegionNode(1);
thartmann@33628 1588 record_for_igvn(bailout);
thartmann@33628 1589
thartmann@34499 1590 // Range checks
thartmann@34499 1591 generate_negative_guard(offset, bailout);
thartmann@34499 1592 generate_negative_guard(length, bailout);
thartmann@34499 1593 generate_limit_guard(offset, length, load_array_length(value), bailout);
thartmann@33628 1594 // Make sure that resulting byte[] length does not overflow Integer.MAX_VALUE
thartmann@33628 1595 generate_limit_guard(length, intcon(0), intcon(max_jint/2), bailout);
thartmann@33628 1596
thartmann@33628 1597 if (bailout->req() > 1) {
thartmann@33628 1598 PreserveJVMState pjvms(this);
thartmann@33628 1599 set_control(_gvn.transform(bailout));
thartmann@33628 1600 uncommon_trap(Deoptimization::Reason_intrinsic,
thartmann@33628 1601 Deoptimization::Action_maybe_recompile);
thartmann@33628 1602 }
thartmann@34499 1603 if (stopped()) {
thartmann@34499 1604 return true;
thartmann@34499 1605 }
thartmann@33628 1606
thartmann@33628 1607 Node* size = _gvn.transform(new LShiftINode(length, intcon(1)));
thartmann@33628 1608 Node* klass_node = makecon(TypeKlassPtr::make(ciTypeArrayKlass::make(T_BYTE)));
thartmann@33628 1609 newcopy = new_array(klass_node, size, 0); // no arguments to push
thartmann@33628 1610 AllocateArrayNode* alloc = tightly_coupled_allocation(newcopy, NULL);
thartmann@33628 1611
thartmann@33628 1612 // Calculate starting addresses.
rkennke@51705 1613 value = access_resolve(value, ACCESS_READ);
thartmann@33628 1614 Node* src_start = array_element_address(value, offset, T_CHAR);
thartmann@33628 1615 Node* dst_start = basic_plus_adr(newcopy, arrayOopDesc::base_offset_in_bytes(T_BYTE));
thartmann@33628 1616
thartmann@33628 1617 // Check if src array address is aligned to HeapWordSize (dst is always aligned)
thartmann@33628 1618 const TypeInt* toffset = gvn().type(offset)->is_int();
thartmann@33628 1619 bool aligned = toffset->is_con() && ((toffset->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0);
thartmann@33628 1620
thartmann@33628 1621 // Figure out which arraycopy runtime method to call (disjoint, uninitialized).
thartmann@33628 1622 const char* copyfunc_name = "arraycopy";
thartmann@33628 1623 address copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true);
thartmann@33628 1624 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
thartmann@33628 1625 OptoRuntime::fast_arraycopy_Type(),
thartmann@33628 1626 copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM,
thartmann@33628 1627 src_start, dst_start, ConvI2X(length) XTOP);
thartmann@33628 1628 // Do not let reads from the cloned object float above the arraycopy.
thartmann@33628 1629 if (alloc != NULL) {
thartmann@33628 1630 if (alloc->maybe_set_complete(&_gvn)) {
thartmann@33628 1631 // "You break it, you buy it."
thartmann@33628 1632 InitializeNode* init = alloc->initialization();
thartmann@33628 1633 assert(init->is_complete(), "we just did this");
thartmann@33628 1634 init->set_complete_with_arraycopy();
thartmann@33628 1635 assert(newcopy->is_CheckCastPP(), "sanity");
thartmann@33628 1636 assert(newcopy->in(0)->in(0) == init, "dest pinned");
kvn@8494 1637 }
thartmann@33628 1638 // Do not let stores that initialize this object be reordered with
thartmann@33628 1639 // a subsequent store that would make this object accessible by
thartmann@33628 1640 // other threads.
thartmann@33628 1641 // Record what AllocateNode this StoreStore protects so that
thartmann@33628 1642 // escape analysis can go from the MemBarStoreStoreNode to the
thartmann@33628 1643 // AllocateNode and eliminate the MemBarStoreStoreNode if possible
thartmann@33628 1644 // based on the escape status of the AllocateNode.
dlong@48595 1645 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress));
thartmann@33628 1646 } else {
thartmann@33628 1647 insert_mem_bar(Op_MemBarCPUOrder);
kvn@8494 1648 }
thartmann@33628 1649 } // original reexecute is set back here
thartmann@33628 1650
thartmann@33628 1651 C->set_has_split_ifs(true); // Has chance for split-if optimization
thartmann@33628 1652 if (!stopped()) {
thartmann@33628 1653 set_result(newcopy);
thartmann@33628 1654 }
vdeshpande@48371 1655 clear_upper_avx();
vdeshpande@48371 1656
thartmann@33628 1657 return true;
thartmann@33628 1658 }
thartmann@33628 1659
thartmann@33628 1660 //------------------------inline_string_getCharsU--------------------------
thartmann@34499 1661 // public void StringUTF16.getChars(byte[] src, int srcBegin, int srcEnd, char dst[], int dstBegin)
thartmann@33628 1662 bool LibraryCallKit::inline_string_getCharsU() {
thartmann@34499 1663 if (too_many_traps(Deoptimization::Reason_intrinsic)) {
thartmann@34499 1664 return false;
thartmann@34499 1665 }
thartmann@33628 1666
thartmann@33628 1667 // Get the arguments.
thartmann@34499 1668 Node* src = argument(0);
thartmann@33628 1669 Node* src_begin = argument(1);
thartmann@33628 1670 Node* src_end = argument(2); // exclusive offset (i < src_end)
thartmann@33628 1671 Node* dst = argument(3);
thartmann@33628 1672 Node* dst_begin = argument(4);
thartmann@33628 1673
thartmann@33628 1674 // Check for allocation before we add nodes that would confuse
thartmann@33628 1675 // tightly_coupled_allocation()
thartmann@33628 1676 AllocateArrayNode* alloc = tightly_coupled_allocation(dst, NULL);
thartmann@33628 1677
thartmann@33628 1678 // Check if a null path was taken unconditionally.
thartmann@34499 1679 src = null_check(src);
thartmann@33628 1680 dst = null_check(dst);
thartmann@33628 1681 if (stopped()) {
thartmann@33628 1682 return true;
thartmann@33628 1683 }
thartmann@33628 1684
thartmann@33628 1685 // Get length and convert char[] offset to byte[] offset
thartmann@33628 1686 Node* length = _gvn.transform(new SubINode(src_end, src_begin));
thartmann@33628 1687 src_begin = _gvn.transform(new LShiftINode(src_begin, intcon(1)));
thartmann@33628 1688
thartmann@34499 1689 // Range checks
thartmann@34499 1690 generate_string_range_check(src, src_begin, length, true);
thartmann@34499 1691 generate_string_range_check(dst, dst_begin, length, false);
thartmann@34499 1692 if (stopped()) {
thartmann@34499 1693 return true;
thartmann@34499 1694 }
thartmann@34499 1695
thartmann@33628 1696 if (!stopped()) {
rkennke@51705 1697 src = access_resolve(src, ACCESS_READ);
rkennke@51850 1698 dst = access_resolve(dst, ACCESS_WRITE);
rkennke@51705 1699
thartmann@33628 1700 // Calculate starting addresses.
thartmann@34499 1701 Node* src_start = array_element_address(src, src_begin, T_BYTE);
thartmann@33628 1702 Node* dst_start = array_element_address(dst, dst_begin, T_CHAR);
thartmann@33628 1703
thartmann@33628 1704 // Check if array addresses are aligned to HeapWordSize
thartmann@33628 1705 const TypeInt* tsrc = gvn().type(src_begin)->is_int();
thartmann@33628 1706 const TypeInt* tdst = gvn().type(dst_begin)->is_int();
thartmann@33628 1707 bool aligned = tsrc->is_con() && ((tsrc->get_con() * type2aelembytes(T_BYTE)) % HeapWordSize == 0) &&
thartmann@33628 1708 tdst->is_con() && ((tdst->get_con() * type2aelembytes(T_CHAR)) % HeapWordSize == 0);
thartmann@33628 1709
thartmann@33628 1710 // Figure out which arraycopy runtime method to call (disjoint, uninitialized).
thartmann@33628 1711 const char* copyfunc_name = "arraycopy";
thartmann@33628 1712 address copyfunc_addr = StubRoutines::select_arraycopy_function(T_CHAR, aligned, true, copyfunc_name, true);
thartmann@33628 1713 Node* call = make_runtime_call(RC_LEAF|RC_NO_FP,
thartmann@33628 1714 OptoRuntime::fast_arraycopy_Type(),
thartmann@33628 1715 copyfunc_addr, copyfunc_name, TypeRawPtr::BOTTOM,
thartmann@33628 1716 src_start, dst_start, ConvI2X(length) XTOP);
thartmann@33628 1717 // Do not let reads from the cloned object float above the arraycopy.
thartmann@33628 1718 if (alloc != NULL) {
thartmann@33628 1719 if (alloc->maybe_set_complete(&_gvn)) {
thartmann@33628 1720 // "You break it, you buy it."
thartmann@33628 1721 InitializeNode* init = alloc->initialization();
thartmann@33628 1722 assert(init->is_complete(), "we just did this");
thartmann@33628 1723 init->set_complete_with_arraycopy();
thartmann@33628 1724 assert(dst->is_CheckCastPP(), "sanity");
thartmann@33628 1725 assert(dst->in(0)->in(0) == init, "dest pinned");
thartmann@33628 1726 }
thartmann@33628 1727 // Do not let stores that initialize this object be reordered with
thartmann@33628 1728 // a subsequent store that would make this object accessible by
thartmann@33628 1729 // other threads.
thartmann@33628 1730 // Record what AllocateNode this StoreStore protects so that
thartmann@33628 1731 // escape analysis can go from the MemBarStoreStoreNode to the
thartmann@33628 1732 // AllocateNode and eliminate the MemBarStoreStoreNode if possible
thartmann@33628 1733 // based on the escape status of the AllocateNode.
dlong@48595 1734 insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out_or_null(AllocateNode::RawAddress));
thartmann@33628 1735 } else {
thartmann@33628 1736 insert_mem_bar(Op_MemBarCPUOrder);
kvn@3905 1737 }
thartmann@33628 1738 }
thartmann@33628 1739
thartmann@33628 1740 C->set_has_split_ifs(true); // Has chance for split-if optimization
thartmann@33628 1741 return true;
thartmann@33628 1742 }
thartmann@33628 1743
thartmann@33628 1744 //----------------------inline_string_char_access----------------------------
thartmann@33628 1745 // Store/Load char to/from byte[] array.
thartmann@33628 1746 // static void StringUTF16.putChar(byte[] val, int index, int c)
thartmann@33628 1747 // static char StringUTF16.getChar(byte[] val, int index)
thartmann@33628 1748 bool LibraryCallKit::inline_string_char_access(bool is_store) {
thartmann@33628 1749 Node* value = argument(0);
thartmann@33628 1750 Node* index = argument(1);
thartmann@33628 1751 Node* ch = is_store ? argument(2) : NULL;
thartmann@33628 1752
thartmann@33628 1753 // This intrinsic accesses byte[] array as char[] array. Computing the offsets
thartmann@33628 1754 // correctly requires matched array shapes.
thartmann@33628 1755 assert (arrayOopDesc::base_offset_in_bytes(T_CHAR) == arrayOopDesc::base_offset_in_bytes(T_BYTE),
thartmann@33628 1756 "sanity: byte[] and char[] bases agree");
thartmann@33628 1757 assert (type2aelembytes(T_CHAR) == type2aelembytes(T_BYTE)*2,
thartmann@33628 1758 "sanity: byte[] and char[] scales agree");
thartmann@33628 1759
shade@36314 1760 // Bail when getChar over constants is requested: constant folding would
shade@36314 1761 // reject folding mismatched char access over byte[]. A normal inlining for getChar
shade@36314 1762 // Java method would constant fold nicely instead.
shade@36314 1763 if (!is_store && value->is_Con() && index->is_Con()) {
shade@36314 1764 return false;
shade@36314 1765 }
shade@36314 1766
roland@51483 1767 value = must_be_not_null(value, true);
rkennke@51705 1768 value = access_resolve(value, is_store ? ACCESS_WRITE : ACCESS_READ);
roland@51483 1769
thartmann@33628 1770 Node* adr = array_element_address(value, index, T_CHAR);
dlong@44634 1771 if (adr->is_top()) {
dlong@44634 1772 return false;
dlong@44634 1773 }
thartmann@33628 1774 if (is_store) {
roland@51880 1775 access_store_at(value, adr, TypeAryPtr::BYTES, ch, TypeInt::CHAR, T_CHAR, IN_HEAP | MO_UNORDERED | C2_MISMATCHED);
thartmann@33628 1776 } else {
roland@51880 1777 ch = access_load_at(value, adr, TypeAryPtr::BYTES, TypeInt::CHAR, T_CHAR, IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD);
thartmann@33628 1778 set_result(ch);
thartmann@33628 1779 }
duke@1 1780 return true;
duke@1 1781 }
duke@1 1782
twisti@14621 1783 //--------------------------round_double_node--------------------------------
twisti@14621 1784 // Round a double node if necessary.
twisti@14621 1785 Node* LibraryCallKit::round_double_node(Node* n) {
twisti@14621 1786 if (Matcher::strict_fp_requires_explicit_rounding && UseSSE <= 1)
thartmann@24923 1787 n = _gvn.transform(new RoundDoubleNode(0, n));
twisti@14621 1788 return n;
twisti@14621 1789 }
twisti@14621 1790
twisti@14621 1791 //------------------------------inline_math-----------------------------------
twisti@14621 1792 // public static double Math.abs(double)
twisti@14621 1793 // public static double Math.sqrt(double)
twisti@14621 1794 // public static double Math.log(double)
twisti@14621 1795 // public static double Math.log10(double)
twisti@14621 1796 bool LibraryCallKit::inline_math(vmIntrinsics::ID id) {
twisti@14621 1797 Node* arg = round_double_node(argument(0));
goetz@33589 1798 Node* n = NULL;
twisti@14621 1799 switch (id) {
thartmann@24923 1800 case vmIntrinsics::_dabs: n = new AbsDNode( arg); break;
thartmann@24923 1801 case vmIntrinsics::_dsqrt: n = new SqrtDNode(C, control(), arg); break;
twisti@14621 1802 default: fatal_unexpected_iid(id); break;
twisti@14621 1803 }
twisti@14621 1804 set_result(_gvn.transform(n));
twisti@14621 1805 return true;
duke@1 1806 }
duke@1 1807
duke@1 1808 //------------------------------runtime_math-----------------------------
duke@1 1809 bool LibraryCallKit::runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName) {
duke@1 1810 assert(call_type == OptoRuntime::Math_DD_D_Type() || call_type == OptoRuntime::Math_D_D_Type(),
duke@1 1811 "must be (DD)D or (D)D type");
duke@1 1812
duke@1 1813 // Inputs
twisti@14621 1814 Node* a = round_double_node(argument(0));
twisti@14621 1815 Node* b = (call_type == OptoRuntime::Math_DD_D_Type()) ? round_double_node(argument(2)) : NULL;
duke@1 1816
duke@1 1817 const TypePtr* no_memory_effects = NULL;
duke@1 1818 Node* trig = make_runtime_call(RC_LEAF, call_type, funcAddr, funcName,
duke@1 1819 no_memory_effects,
duke@1 1820 a, top(), b, b ? top() : NULL);
thartmann@24923 1821 Node* value = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+0));
duke@1 1822 #ifdef ASSERT
thartmann@24923 1823 Node* value_top = _gvn.transform(new ProjNode(trig, TypeFunc::Parms+1));
duke@1 1824 assert(value_top == top(), "second value must be top");
duke@1 1825 #endif
duke@1 1826
twisti@14621 1827 set_result(value);
duke@1 1828 return true;
duke@1 1829 }
duke@1 1830
duke@1 1831 //------------------------------inline_math_native-----------------------------
duke@1 1832 bool LibraryCallKit::inline_math_native(vmIntrinsics::ID id) {
twisti@14621 1833 #define FN_PTR(f) CAST_FROM_FN_PTR(address, f)
duke@1 1834 switch (id) {
duke@1 1835 // These intrinsics are not properly supported on all hardware
vdeshpande@35540 1836 case vmIntrinsics::_dsin:
vdeshpande@35540 1837 return StubRoutines::dsin() != NULL ?
vdeshpande@35540 1838 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dsin(), "dsin") :
vdeshpande@35540 1839 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dsin), "SIN");
vdeshpande@35540 1840 case vmIntrinsics::_dcos:
vdeshpande@35540 1841 return StubRoutines::dcos() != NULL ?
vdeshpande@35540 1842 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dcos(), "dcos") :
vdeshpande@35540 1843 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dcos), "COS");
vdeshpande@38018 1844 case vmIntrinsics::_dtan:
vdeshpande@38018 1845 return StubRoutines::dtan() != NULL ?
vdeshpande@38018 1846 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dtan(), "dtan") :
vdeshpande@38018 1847 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dtan), "TAN");
iveresov@33465 1848 case vmIntrinsics::_dlog:
iveresov@33465 1849 return StubRoutines::dlog() != NULL ?
vdeshpande@35540 1850 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dlog(), "dlog") :
vdeshpande@35540 1851 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dlog), "LOG");
vdeshpande@38018 1852 case vmIntrinsics::_dlog10:
vdeshpande@38018 1853 return StubRoutines::dlog10() != NULL ?
vdeshpande@38018 1854 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dlog10(), "dlog10") :
vdeshpande@38018 1855 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dlog10), "LOG10");
duke@1 1856
duke@1 1857 // These intrinsics are supported on all hardware
goetz@22879 1858 case vmIntrinsics::_dsqrt: return Matcher::match_rule_supported(Op_SqrtD) ? inline_math(id) : false;
twisti@14621 1859 case vmIntrinsics::_dabs: return Matcher::has_match_rule(Op_AbsD) ? inline_math(id) : false;
twisti@14621 1860
iveresov@33089 1861 case vmIntrinsics::_dexp:
enevill@33172 1862 return StubRoutines::dexp() != NULL ?
enevill@33172 1863 runtime_math(OptoRuntime::Math_D_D_Type(), StubRoutines::dexp(), "dexp") :
enevill@33172 1864 runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dexp), "EXP");
vlivanov@48396 1865 case vmIntrinsics::_dpow: {
vlivanov@48396 1866 Node* exp = round_double_node(argument(2));
vlivanov@48396 1867 const TypeD* d = _gvn.type(exp)->isa_double_constant();
vlivanov@48396 1868 if (d != NULL && d->getd() == 2.0) {
vlivanov@48396 1869 // Special case: pow(x, 2.0) => x * x
vlivanov@48396 1870 Node* base = round_double_node(argument(0));
vlivanov@48396 1871 set_result(_gvn.transform(new MulDNode(base, base)));
vlivanov@48396 1872 return true;
vlivanov@48396 1873 }
dpochepk@51409 1874 return StubRoutines::dpow() != NULL ?
vlivanov@48396 1875 runtime_math(OptoRuntime::Math_DD_D_Type(), StubRoutines::dpow(), "dpow") :
kvn@35146 1876 runtime_math(OptoRuntime::Math_DD_D_Type(), FN_PTR(SharedRuntime::dpow), "POW");
vlivanov@48396 1877 }
twisti@14621 1878 #undef FN_PTR
duke@1 1879
duke@1 1880 // These intrinsics are not yet correctly implemented
duke@1 1881 case vmIntrinsics::_datan2:
duke@1 1882 return false;
duke@1 1883
duke@1 1884 default:
twisti@14621 1885 fatal_unexpected_iid(id);
duke@1 1886 return false;
duke@1 1887 }
duke@1 1888 }
duke@1 1889
duke@1 1890 static bool is_simple_name(Node* n) {
duke@1 1891 return (n->req() == 1 // constant
duke@1 1892 || (n->is_Type() && n->as_Type()->type()->singleton())
duke@1 1893 || n->is_Proj() // parameter or return value
duke@1 1894 || n->is_Phi() // local of some sort
duke@1 1895 );
duke@1 1896 }
duke@1 1897
dcubed@31856 1898 //----------------------------inline_notify-----------------------------------*
dcubed@31856 1899 bool LibraryCallKit::inline_notify(vmIntrinsics::ID id) {
dcubed@31856 1900 const TypeFunc* ftype = OptoRuntime::monitor_notify_Type();
dcubed@31856 1901 address func;
dcubed@31856 1902 if (id == vmIntrinsics::_notify) {
dcubed@31856 1903 func = OptoRuntime::monitor_notify_Java();
dcubed@31856 1904 } else {
dcubed@31856 1905 func = OptoRuntime::monitor_notifyAll_Java();
dcubed@31856 1906 }
dcubed@31856 1907 Node* call = make_runtime_call(RC_NO_LEAF, ftype, func, NULL, TypeRawPtr::BOTTOM, argument(0));
dcubed@31856 1908 make_slow_call_ex(call, env()->Throwable_klass(), false);
dcubed@31856 1909 return true;
dcubed@31856 1910 }
dcubed@31856 1911
dcubed@31856 1912
duke@1 1913 //----------------------------inline_min_max-----------------------------------
duke@1 1914 bool LibraryCallKit::inline_min_max(vmIntrinsics::ID id) {
twisti@14621 1915 set_result(generate_min_max(id, argument(0), argument(1)));
duke@1 1916 return true;
duke@1 1917 }
duke@1 1918
rbackman@22911 1919 void LibraryCallKit::inline_math_mathExact(Node* math, Node *test) {
thartmann@24923 1920 Node* bol = _gvn.transform( new BoolNode(test, BoolTest::overflow) );
rbackman@20289 1921 IfNode* check = create_and_map_if(control(), bol, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN);
thartmann@24923 1922 Node* fast_path = _gvn.transform( new IfFalseNode(check));
thartmann@24923 1923 Node* slow_path = _gvn.transform( new IfTrueNode(check) );
rbackman@20289 1924
rbackman@20289 1925 {
rbackman@20289 1926 PreserveJVMState pjvms(this);
rbackman@20289 1927 PreserveReexecuteState preexecs(this);
rbackman@20289 1928 jvms()->set_should_reexecute(true);
rbackman@20289 1929
rbackman@20289 1930 set_control(slow_path);
rbackman@20289 1931 set_i_o(i_o());
rbackman@20289 1932
rbackman@20289 1933 uncommon_trap(Deoptimization::Reason_intrinsic,
rbackman@20289 1934 Deoptimization::Action_none);
rbackman@20289 1935 }
rbackman@20289 1936
rbackman@20289 1937 set_control(fast_path);
rbackman@22911 1938 set_result(math);
rbackman@21105 1939 }
rbackman@21105 1940
rbackman@22911 1941 template <typename OverflowOp>
rbackman@22911 1942 bool LibraryCallKit::inline_math_overflow(Node* arg1, Node* arg2) {
rbackman@22911 1943 typedef typename OverflowOp::MathOp MathOp;
rbackman@22911 1944
thartmann@24923 1945 MathOp* mathOp = new MathOp(arg1, arg2);
rbackman@22911 1946 Node* operation = _gvn.transform( mathOp );
thartmann@24923 1947 Node* ofcheck = _gvn.transform( new OverflowOp(arg1, arg2) );
rbackman@22911 1948 inline_math_mathExact(operation, ofcheck);
rbackman@20289 1949 return true;
rbackman@20289 1950 }
rbackman@20289 1951
rbackman@22911 1952 bool LibraryCallKit::inline_math_addExactI(bool is_increment) {
rbackman@22911 1953 return inline_math_overflow<OverflowAddINode>(argument(0), is_increment ? intcon(1) : argument(1));
rbackman@22911 1954 }
rbackman@22911 1955
rbackman@21105 1956 bool LibraryCallKit::inline_math_addExactL(bool is_increment) {
rbackman@22911 1957 return inline_math_overflow<OverflowAddLNode>(argument(0), is_increment ? longcon(1) : argument(2));
rbackman@21105 1958 }
rbackman@21105 1959
rbackman@21105 1960 bool LibraryCallKit::inline_math_subtractExactI(bool is_decrement) {
rbackman@22911 1961 return inline_math_overflow<OverflowSubINode>(argument(0), is_decrement ? intcon(1) : argument(1));
rbackman@21105 1962 }
rbackman@21105 1963
rbackman@21105 1964 bool LibraryCallKit::inline_math_subtractExactL(bool is_decrement) {
rbackman@22911 1965 return inline_math_overflow<OverflowSubLNode>(argument(0), is_decrement ? longcon(1) : argument(2));
rbackman@21105 1966 }
rbackman@21105 1967
rbackman@21105 1968 bool LibraryCallKit::inline_math_negateExactI() {
rbackman@22911 1969 return inline_math_overflow<OverflowSubINode>(intcon(0), argument(0));
rbackman@21105 1970 }
rbackman@21105 1971
rbackman@21105 1972 bool LibraryCallKit::inline_math_negateExactL() {
rbackman@22911 1973 return inline_math_overflow<OverflowSubLNode>(longcon(0), argument(0));
rbackman@21105 1974 }
rbackman@21105 1975
rbackman@21105 1976 bool LibraryCallKit::inline_math_multiplyExactI() {
rbackman@22911 1977 return inline_math_overflow<OverflowMulINode>(argument(0), argument(1));
rbackman@21105 1978 }
rbackman@21105 1979
rbackman@21105 1980 bool LibraryCallKit::inline_math_multiplyExactL() {
rbackman@22911 1981 return inline_math_overflow<OverflowMulLNode>(argument(0), argument(2));
rbackman@20289 1982 }
rbackman@20289 1983
dpochepk@47587 1984 bool LibraryCallKit::inline_math_multiplyHigh() {
dpochepk@47587 1985 set_result(_gvn.transform(new MulHiLNode(argument(0), argument(2))));
dpochepk@47587 1986 return true;
dpochepk@47587 1987 }
dpochepk@47587 1988
duke@1 1989 Node*
duke@1 1990 LibraryCallKit::generate_min_max(vmIntrinsics::ID id, Node* x0, Node* y0) {
duke@1 1991 // These are the candidate return value:
duke@1 1992 Node* xvalue = x0;
duke@1 1993 Node* yvalue = y0;
duke@1 1994
duke@1 1995 if (xvalue == yvalue) {
duke@1 1996 return xvalue;
duke@1 1997 }
duke@1 1998
duke@1 1999 bool want_max = (id == vmIntrinsics::_max);
duke@1 2000
duke@1 2001 const TypeInt* txvalue = _gvn.type(xvalue)->isa_int();
duke@1 2002 const TypeInt* tyvalue = _gvn.type(yvalue)->isa_int();
duke@1 2003 if (txvalue == NULL || tyvalue == NULL) return top();
duke@1 2004 // This is not really necessary, but it is consistent with a
duke@1 2005 // hypothetical MaxINode::Value method:
duke@1 2006 int widen = MAX2(txvalue->_widen, tyvalue->_widen);
duke@1 2007
duke@1 2008 // %%% This folding logic should (ideally) be in a different place.
duke@1 2009 // Some should be inside IfNode, and there to be a more reliable
duke@1 2010 // transformation of ?: style patterns into cmoves. We also want
duke@1 2011 // more powerful optimizations around cmove and min/max.
duke@1 2012
duke@1 2013 // Try to find a dominating comparison of these guys.
duke@1 2014 // It can simplify the index computation for Arrays.copyOf
duke@1 2015 // and similar uses of System.arraycopy.
duke@1 2016 // First, compute the normalized version of CmpI(x, y).
duke@1 2017 int cmp_op = Op_CmpI;
duke@1 2018 Node* xkey = xvalue;
duke@1 2019 Node* ykey = yvalue;
thartmann@24923 2020 Node* ideal_cmpxy = _gvn.transform(new CmpINode(xkey, ykey));
duke@1 2021 if (ideal_cmpxy->is_Cmp()) {
duke@1 2022 // E.g., if we have CmpI(length - offset, count),
duke@1 2023 // it might idealize to CmpI(length, count + offset)
duke@1 2024 cmp_op = ideal_cmpxy->Opcode();
duke@1 2025 xkey = ideal_cmpxy->in(1);
duke@1 2026 ykey = ideal_cmpxy->in(2);
duke@1 2027 }
duke@1 2028
duke@1 2029 // Start by locating any relevant comparisons.
duke@1 2030 Node* start_from = (xkey->outcnt() < ykey->outcnt()) ? xkey : ykey;
duke@1 2031 Node* cmpxy = NULL;
duke@1 2032 Node* cmpyx = NULL;
duke@1 2033 for (DUIterator_Fast kmax, k = start_from->fast_outs(kmax); k < kmax; k++) {
duke@1 2034 Node* cmp = start_from->fast_out(k);
duke@1 2035 if (cmp->outcnt() > 0 && // must have prior uses
duke@1 2036 cmp->in(0) == NULL && // must be context-independent
duke@1 2037 cmp->Opcode() == cmp_op) { // right kind of compare
duke@1 2038 if (cmp->in(1) == xkey && cmp->in(2) == ykey) cmpxy = cmp;
duke@1 2039 if (cmp->in(1) == ykey && cmp->in(2) == xkey) cmpyx = cmp;
duke@1 2040 }
duke@1 2041 }
duke@1 2042
duke@1 2043 const int NCMPS = 2;
duke@1 2044 Node* cmps[NCMPS] = { cmpxy, cmpyx };
duke@1 2045 int cmpn;
duke@1 2046 for (cmpn = 0; cmpn < NCMPS; cmpn++) {
duke@1 2047 if (cmps[cmpn] != NULL) break; // find a result
duke@1 2048 }
duke@1 2049 if (cmpn < NCMPS) {
duke@1 2050 // Look for a dominating test that tells us the min and max.
duke@1 2051 int depth = 0; // Limit search depth for speed
duke@1 2052 Node* dom = control();
duke@1 2053 for (; dom != NULL; dom = IfNode::up_one_dom(dom, true)) {
duke@1 2054 if (++depth >= 100) break;
duke@1 2055 Node* ifproj = dom;
duke@1 2056 if (!ifproj->is_Proj()) continue;
duke@1 2057 Node* iff = ifproj->in(0);
duke@1 2058 if (!iff->is_If()) continue;
duke@1 2059 Node* bol = iff->in(1);
duke@1 2060 if (!bol->is_Bool()) continue;
duke@1 2061 Node* cmp = bol->in(1);
duke@1 2062 if (cmp == NULL) continue;
duke@1 2063 for (cmpn = 0; cmpn < NCMPS; cmpn++)
duke@1 2064 if (cmps[cmpn] == cmp) break;
duke@1 2065 if (cmpn == NCMPS) continue;
duke@1 2066 BoolTest::mask btest = bol->as_Bool()->_test._test;
duke@1 2067 if (ifproj->is_IfFalse()) btest = BoolTest(btest).negate();
duke@1 2068 if (cmp->in(1) == ykey) btest = BoolTest(btest).commute();
duke@1 2069 // At this point, we know that 'x btest y' is true.
duke@1 2070 switch (btest) {
duke@1 2071 case BoolTest::eq:
duke@1 2072 // They are proven equal, so we can collapse the min/max.
duke@1 2073 // Either value is the answer. Choose the simpler.
duke@1 2074 if (is_simple_name(yvalue) && !is_simple_name(xvalue))
duke@1 2075 return yvalue;
duke@1 2076 return xvalue;
duke@1 2077 case BoolTest::lt: // x < y
duke@1 2078 case BoolTest::le: // x <= y
duke@1 2079 return (want_max ? yvalue : xvalue);
duke@1 2080 case BoolTest::gt: // x > y
duke@1 2081 case BoolTest::ge: // x >= y
duke@1 2082 return (want_max ? xvalue : yvalue);
jwilhelm@46630 2083 default:
jwilhelm@46630 2084 break;
duke@1 2085 }
duke@1 2086 }
duke@1 2087 }
duke@1 2088
duke@1 2089 // We failed to find a dominating test.
duke@1 2090 // Let's pick a test that might GVN with prior tests.
duke@1 2091 Node* best_bol = NULL;
duke@1 2092 BoolTest::mask best_btest = BoolTest::illegal;
duke@1 2093 for (cmpn = 0; cmpn < NCMPS; cmpn++) {
duke@1 2094 Node* cmp = cmps[cmpn];
duke@1 2095 if (cmp == NULL) continue;
duke@1 2096 for (DUIterator_Fast jmax, j = cmp->fast_outs(jmax); j < jmax; j++) {
duke@1 2097 Node* bol = cmp->fast_out(j);
duke@1 2098 if (!bol->is_Bool()) continue;
duke@1 2099 BoolTest::mask btest = bol->as_Bool()->_test._test;
duke@1 2100 if (btest == BoolTest::eq || btest == BoolTest::ne) continue;
duke@1 2101 if (cmp->in(1) == ykey) btest = BoolTest(btest).commute();
duke@1 2102 if (bol->outcnt() > (best_bol == NULL ? 0 : best_bol->outcnt())) {
duke@1 2103 best_bol = bol->as_Bool();
duke@1 2104 best_btest = btest;
duke@1 2105 }
duke@1 2106 }
duke@1 2107 }
duke@1 2108
duke@1 2109 Node* answer_if_true = NULL;
duke@1 2110 Node* answer_if_false = NULL;
duke@1 2111 switch (best_btest) {
duke@1 2112 default:
duke@1 2113 if (cmpxy == NULL)
duke@1 2114 cmpxy = ideal_cmpxy;
thartmann@24923 2115 best_bol = _gvn.transform(new BoolNode(cmpxy, BoolTest::lt));
duke@1 2116 // and fall through:
duke@1 2117 case BoolTest::lt: // x < y
duke@1 2118 case BoolTest::le: // x <= y
duke@1 2119 answer_if_true = (want_max ? yvalue : xvalue);
duke@1 2120 answer_if_false = (want_max ? xvalue : yvalue);
duke@1 2121 break;
duke@1 2122 case BoolTest::gt: // x > y
duke@1 2123 case BoolTest::ge: // x >= y
duke@1 2124 answer_if_true = (want_max ? xvalue : yvalue);
duke@1 2125 answer_if_false = (want_max ? yvalue : xvalue);
duke@1 2126 break;
duke@1 2127 }
duke@1 2128
duke@1 2129 jint hi, lo;
duke@1 2130 if (want_max) {
duke@1 2131 // We can sharpen the minimum.
duke@1 2132 hi = MAX2(txvalue->_hi, tyvalue->_hi);
duke@1 2133 lo = MAX2(txvalue->_lo, tyvalue->_lo);
duke@1 2134 } else {
duke@1 2135 // We can sharpen the maximum.
duke@1 2136 hi = MIN2(txvalue->_hi, tyvalue->_hi);
duke@1 2137 lo = MIN2(txvalue->_lo, tyvalue->_lo);
duke@1 2138 }
duke@1 2139
duke@1 2140 // Use a flow-free graph structure, to avoid creating excess control edges
duke@1 2141 // which could hinder other optimizations.
duke@1 2142 // Since Math.min/max is often used with arraycopy, we want
duke@1 2143 // tightly_coupled_allocation to be able to see beyond min/max expressions.
thartmann@25930 2144 Node* cmov = CMoveNode::make(NULL, best_bol,
duke@1 2145 answer_if_false, answer_if_true,
duke@1 2146 TypeInt::make(lo, hi, widen));
duke@1 2147
duke@1 2148 return _gvn.transform(cmov);
duke@1 2149
duke@1 2150 /*
duke@1 2151 // This is not as desirable as it may seem, since Min and Max
duke@1 2152 // nodes do not have a full set of optimizations.
duke@1 2153 // And they would interfere, anyway, with 'if' optimizations
duke@1 2154 // and with CMoveI canonical forms.
duke@1 2155 switch (id) {
duke@1 2156 case vmIntrinsics::_min:
duke@1 2157 result_val = _gvn.transform(new (C, 3) MinINode(x,y)); break;
duke@1 2158 case vmIntrinsics::_max:
duke@1 2159 result_val = _gvn.transform(new (C, 3) MaxINode(x,y)); break;
duke@1 2160 default:
duke@1 2161 ShouldNotReachHere();
duke@1 2162 }
duke@1 2163 */
duke@1 2164 }
duke@1 2165
duke@1 2166 inline int
roland@46525 2167 LibraryCallKit::classify_unsafe_addr(Node* &base, Node* &offset, BasicType type) {
duke@1 2168 const TypePtr* base_type = TypePtr::NULL_PTR;
duke@1 2169 if (base != NULL) base_type = _gvn.type(base)->isa_ptr();
duke@1 2170 if (base_type == NULL) {
duke@1 2171 // Unknown type.
duke@1 2172 return Type::AnyPtr;
duke@1 2173 } else if (base_type == TypePtr::NULL_PTR) {
duke@1 2174 // Since this is a NULL+long form, we have to switch to a rawptr.
thartmann@24923 2175 base = _gvn.transform(new CastX2PNode(offset));
duke@1 2176 offset = MakeConX(0);
duke@1 2177 return Type::RawPtr;
duke@1 2178 } else if (base_type->base() == Type::RawPtr) {
duke@1 2179 return Type::RawPtr;
duke@1 2180 } else if (base_type->isa_oopptr()) {
duke@1 2181 // Base is never null => always a heap address.
roland@46525 2182 if (!TypePtr::NULL_PTR->higher_equal(base_type)) {
duke@1 2183 return Type::OopPtr;
duke@1 2184 }
duke@1 2185 // Offset is small => always a heap address.
duke@1 2186 const TypeX* offset_type = _gvn.type(offset)->isa_intptr_t();
duke@1 2187 if (offset_type != NULL &&
duke@1 2188 base_type->offset() == 0 && // (should always be?)
duke@1 2189 offset_type->_lo >= 0 &&
duke@1 2190 !MacroAssembler::needs_explicit_null_check(offset_type->_hi)) {
duke@1 2191 return Type::OopPtr;
roland@46525 2192 } else if (type == T_OBJECT) {
roland@46525 2193 // off heap access to an oop doesn't make any sense. Has to be on
roland@46525 2194 // heap.
roland@46525 2195 return Type::OopPtr;
duke@1 2196 }
duke@1 2197 // Otherwise, it might either be oop+off or NULL+addr.
duke@1 2198 return Type::AnyPtr;
duke@1 2199 } else {
duke@1 2200 // No information:
duke@1 2201 return Type::AnyPtr;
duke@1 2202 }
duke@1 2203 }
duke@1 2204
rkennke@51850 2205 inline Node* LibraryCallKit::make_unsafe_address(Node*& base, Node* offset, DecoratorSet decorators, BasicType type, bool can_cast) {
roland@46525 2206 Node* uncasted_base = base;
roland@46525 2207 int kind = classify_unsafe_addr(uncasted_base, offset, type);
duke@1 2208 if (kind == Type::RawPtr) {
roland@46525 2209 return basic_plus_adr(top(), uncasted_base, offset);
roland@46525 2210 } else if (kind == Type::AnyPtr) {
roland@46525 2211 assert(base == uncasted_base, "unexpected base change");
roland@46542 2212 if (can_cast) {
roland@46542 2213 if (!_gvn.type(base)->speculative_maybe_null() &&
roland@46542 2214 !too_many_traps(Deoptimization::Reason_speculate_null_check)) {
roland@46542 2215 // According to profiling, this access is always on
roland@46542 2216 // heap. Casting the base to not null and thus avoiding membars
roland@46542 2217 // around the access should allow better optimizations
roland@46542 2218 Node* null_ctl = top();
roland@46542 2219 base = null_check_oop(base, &null_ctl, true, true, true);
roland@46542 2220 assert(null_ctl->is_top(), "no null control here");
roland@46542 2221 return basic_plus_adr(base, offset);
roland@46542 2222 } else if (_gvn.type(base)->speculative_always_null() &&
roland@46542 2223 !too_many_traps(Deoptimization::Reason_speculate_null_assert)) {
roland@46542 2224 // According to profiling, this access is always off
roland@46542 2225 // heap.
roland@46542 2226 base = null_assert(base);
roland@46542 2227 Node* raw_base = _gvn.transform(new CastX2PNode(offset));
roland@46542 2228 offset = MakeConX(0);
roland@46542 2229 return basic_plus_adr(top(), raw_base, offset);
roland@46542 2230 }
roland@46542 2231 }
roland@46525 2232 // We don't know if it's an on heap or off heap access. Fall back
roland@46525 2233 // to raw memory access.
rkennke@51850 2234 base = access_resolve(base, decorators);
roland@46525 2235 Node* raw = _gvn.transform(new CheckCastPPNode(control(), base, TypeRawPtr::BOTTOM));
roland@46525 2236 return basic_plus_adr(top(), raw, offset);
duke@1 2237 } else {
roland@46525 2238 assert(base == uncasted_base, "unexpected base change");
roland@46525 2239 // We know it's an on heap access so base can't be null
roland@46525 2240 if (TypePtr::NULL_PTR->higher_equal(_gvn.type(base))) {
roland@46525 2241 base = must_be_not_null(base, true);
roland@46525 2242 }
duke@1 2243 return basic_plus_adr(base, offset);
duke@1 2244 }
duke@1 2245 }
duke@1 2246
twisti@14621 2247 //--------------------------inline_number_methods-----------------------------
twisti@14621 2248 // inline int Integer.numberOfLeadingZeros(int)
twisti@14621 2249 // inline int Long.numberOfLeadingZeros(long)
twisti@14621 2250 //
twisti@14621 2251 // inline int Integer.numberOfTrailingZeros(int)
twisti@14621 2252 // inline int Long.numberOfTrailingZeros(long)
twisti@14621 2253 //
twisti@14621 2254 // inline int Integer.bitCount(int)
twisti@14621 2255 // inline int Long.bitCount(long)
twisti@14621 2256 //
twisti@14621 2257 // inline char Character.reverseBytes(char)
twisti@14621 2258 // inline short Short.reverseBytes(short)
twisti@14621 2259 // inline int Integer.reverseBytes(int)
twisti@14621 2260 // inline long Long.reverseBytes(long)
twisti@14621 2261 bool LibraryCallKit::inline_number_methods(vmIntrinsics::ID id) {
twisti@14621 2262 Node* arg = argument(0);
goetz@33589 2263 Node* n = NULL;
twisti@2862 2264 switch (id) {
thartmann@24923 2265 case vmIntrinsics::_numberOfLeadingZeros_i: n = new CountLeadingZerosINode( arg); break;
thartmann@24923 2266 case vmIntrinsics::_numberOfLeadingZeros_l: n = new CountLeadingZerosLNode( arg); break;
thartmann@24923 2267 case vmIntrinsics::_numberOfTrailingZeros_i: n = new CountTrailingZerosINode(arg); break;
thartmann@24923 2268 case vmIntrinsics::_numberOfTrailingZeros_l: n = new CountTrailingZerosLNode(arg); break;
thartmann@24923 2269 case vmIntrinsics::_bitCount_i: n = new PopCountINode( arg); break;
thartmann@24923 2270 case vmIntrinsics::_bitCount_l: n = new PopCountLNode( arg); break;
thartmann@24923 2271 case vmIntrinsics::_reverseBytes_c: n = new ReverseBytesUSNode(0, arg); break;
thartmann@24923 2272 case vmIntrinsics::_reverseBytes_s: n = new ReverseBytesSNode( 0, arg); break;
thartmann@24923 2273 case vmIntrinsics::_reverseBytes_i: n = new ReverseBytesINode( 0, arg); break;
thartmann@24923 2274 case vmIntrinsics::_reverseBytes_l: n = new ReverseBytesLNode( 0, arg); break;
twisti@14621 2275 default: fatal_unexpected_iid(id); break;
twisti@2862 2276 }
twisti@14621 2277 set_result(_gvn.transform(n));
twisti@2862 2278 return true;
twisti@2862 2279 }
twisti@2862 2280
duke@1 2281 //----------------------------inline_unsafe_access----------------------------
duke@1 2282
mikael@38211 2283 const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type) {
roland@13886 2284 // Attempt to infer a sharper value type from the offset and base type.
roland@13886 2285 ciKlass* sharpened_klass = NULL;
roland@13886 2286
roland@13886 2287 // See if it is an instance field, with an object type.
roland@13886 2288 if (alias_type->field() != NULL) {
roland@13886 2289 if (alias_type->field()->type()->is_klass()) {
roland@13886 2290 sharpened_klass = alias_type->field()->type()->as_klass();
roland@13886 2291 }
roland@13886 2292 }
roland@13886 2293
roland@13886 2294 // See if it is a narrow oop array.
roland@13886 2295 if (adr_type->isa_aryptr()) {
roland@13886 2296 if (adr_type->offset() >= objArrayOopDesc::base_offset_in_bytes()) {
roland@13886 2297 const TypeOopPtr *elem_type = adr_type->is_aryptr()->elem()->isa_oopptr();
roland@13886 2298 if (elem_type != NULL) {
roland@13886 2299 sharpened_klass = elem_type->klass();
roland@13886 2300 }
roland@13886 2301 }
roland@13886 2302 }
roland@13886 2303
twisti@13968 2304 // The sharpened class might be unloaded if there is no class loader
twisti@13968 2305 // contraint in place.
twisti@13968 2306 if (sharpened_klass != NULL && sharpened_klass->is_loaded()) {
roland@13886 2307 const TypeOopPtr* tjp = TypeOopPtr::make_from_klass(sharpened_klass);
roland@13886 2308
roland@13886 2309 #ifndef PRODUCT
kvn@20073 2310 if (C->print_intrinsics() || C->print_inlining()) {
vlivanov@40881 2311 tty->print(" from base type: "); adr_type->dump(); tty->cr();
vlivanov@40881 2312 tty->print(" sharpened value: "); tjp->dump(); tty->cr();
roland@13886 2313 }
roland@13886 2314 #endif
roland@13886 2315 // Sharpen the value type.
roland@13886 2316 return tjp;
roland@13886 2317 }
roland@13886 2318 return NULL;
roland@13886 2319 }
roland@13886 2320
eosterlund@50180 2321 DecoratorSet LibraryCallKit::mo_decorator_for_access_kind(AccessKind kind) {
eosterlund@50180 2322 switch (kind) {
eosterlund@50180 2323 case Relaxed:
eosterlund@50180 2324 return MO_UNORDERED;
eosterlund@50180 2325 case Opaque:
eosterlund@50180 2326 return MO_RELAXED;
eosterlund@50180 2327 case Acquire:
eosterlund@50180 2328 return MO_ACQUIRE;
eosterlund@50180 2329 case Release:
eosterlund@50180 2330 return MO_RELEASE;
eosterlund@50180 2331 case Volatile:
eosterlund@50180 2332 return MO_SEQ_CST;
eosterlund@50180 2333 default:
eosterlund@50180 2334 ShouldNotReachHere();
eosterlund@50180 2335 return 0;
eosterlund@50180 2336 }
eosterlund@50180 2337 }
eosterlund@50180 2338
mikael@38211 2339 bool LibraryCallKit::inline_unsafe_access(bool is_store, const BasicType type, const AccessKind kind, const bool unaligned) {
duke@1 2340 if (callee()->is_static()) return false; // caller must have the capability!
eosterlund@50180 2341 DecoratorSet decorators = C2_UNSAFE_ACCESS;
shade@36316 2342 guarantee(!is_store || kind != Acquire, "Acquire accesses can be produced only for loads");
shade@36316 2343 guarantee( is_store || kind != Release, "Release accesses can be produced only for stores");
vlivanov@38131 2344 assert(type != T_OBJECT || !unaligned, "unaligned access not supported with object type");
duke@1 2345
eosterlund@50180 2346 if (type == T_OBJECT || type == T_ARRAY) {
eosterlund@50180 2347 decorators |= ON_UNKNOWN_OOP_REF;
eosterlund@50180 2348 }
eosterlund@50180 2349
eosterlund@50180 2350 if (unaligned) {
eosterlund@50180 2351 decorators |= C2_UNALIGNED;
eosterlund@50180 2352 }
eosterlund@50180 2353
duke@1 2354 #ifndef PRODUCT
duke@1 2355 {
duke@1 2356 ResourceMark rm;
duke@1 2357 // Check the signatures.
twisti@14621 2358 ciSignature* sig = callee()->signature();
duke@1 2359 #ifdef ASSERT
duke@1 2360 if (!is_store) {
mchung@52220 2361 // Object getReference(Object base, int/long offset), etc.
duke@1 2362 BasicType rtype = sig->return_type()->basic_type();
duke@1 2363 assert(rtype == type, "getter must return the expected value");
mikael@38211 2364 assert(sig->count() == 2, "oop getter has 2 arguments");
mikael@38211 2365 assert(sig->type_at(0)->basic_type() == T_OBJECT, "getter base is object");
mikael@38211 2366 assert(sig->type_at(1)->basic_type() == T_LONG, "getter offset is correct");
duke@1 2367 } else {
mchung@52220 2368 // void putReference(Object base, int/long offset, Object x), etc.
duke@1 2369 assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value");
mikael@38211 2370 assert(sig->count() == 3, "oop putter has 3 arguments");
mikael@38211 2371 assert(sig->type_at(0)->basic_type() == T_OBJECT, "putter base is object");
mikael@38211 2372 assert(sig->type_at(1)->basic_type() == T_LONG, "putter offset is correct");
duke@1 2373 BasicType vtype = sig->type_at(sig->count()-1)->basic_type();
duke@1 2374 assert(vtype == type, "putter must accept the expected value");
duke@1 2375 }
duke@1 2376 #endif // ASSERT
duke@1 2377 }
duke@1 2378 #endif //PRODUCT
duke@1 2379
duke@1 2380 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
duke@1 2381
twisti@14621 2382 Node* receiver = argument(0); // type: oop
twisti@14621 2383
psandoz@28954 2384 // Build address expression.
twisti@14621 2385 Node* adr;
twisti@14621 2386 Node* heap_base_oop = top();
twisti@14621 2387 Node* offset = top();
duke@1 2388 Node* val;
johnc@9176 2389
mikael@38211 2390 // The base is either a Java object or a value produced by Unsafe.staticFieldBase
mikael@38211 2391 Node* base = argument(1); // type: oop
mikael@38211 2392 // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset
mikael@38211 2393 offset = argument(2); // type: long
mikael@38211 2394 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
mikael@38211 2395 // to be plain byte offsets, which are also the same as those accepted
eosterlund@49041 2396 // by oopDesc::field_addr.
mikael@38211 2397 assert(Unsafe_field_offset_to_byte_offset(11) == 11,
mikael@38211 2398 "fieldOffset must be byte-scaled");
mikael@38211 2399 // 32-bit machines ignore the high half!
mikael@38211 2400 offset = ConvL2X(offset);
rkennke@51850 2401 adr = make_unsafe_address(base, offset, is_store ? ACCESS_WRITE : ACCESS_READ, type, kind == Relaxed);
roland@46542 2402
mikael@38211 2403 if (_gvn.type(base)->isa_ptr() != TypePtr::NULL_PTR) {
duke@1 2404 heap_base_oop = base;
vlivanov@40881 2405 } else if (type == T_OBJECT) {
vlivanov@40881 2406 return false; // off-heap oop accesses are not supported
mikael@38211 2407 }
vlivanov@40880 2408
vlivanov@40880 2409 // Can base be NULL? Otherwise, always on-heap access.
vlivanov@40880 2410 bool can_access_non_heap = TypePtr::NULL_PTR->higher_equal(_gvn.type(heap_base_oop));
vlivanov@40880 2411
eosterlund@50180 2412 if (!can_access_non_heap) {
eosterlund@50180 2413 decorators |= IN_HEAP;
eosterlund@50180 2414 }
eosterlund@50180 2415
mikael@38211 2416 val = is_store ? argument(4) : NULL;
duke@1 2417
duke@1 2418 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
duke@1 2419
vlivanov@40880 2420 // Try to categorize the address.
duke@1 2421 Compile::AliasType* alias_type = C->alias_type(adr_type);
duke@1 2422 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
duke@1 2423
vlivanov@40880 2424 if (alias_type->adr_type() == TypeInstPtr::KLASS ||
vlivanov@40880 2425 alias_type->adr_type() == TypeAryPtr::RANGE) {
vlivanov@40880 2426 return false; // not supported
vlivanov@39718 2427 }
vlivanov@39718 2428
vlivanov@38131 2429 bool mismatched = false;
vlivanov@38131 2430 BasicType bt = alias_type->basic_type();
vlivanov@38131 2431 if (bt != T_ILLEGAL) {
vlivanov@40880 2432 assert(alias_type->adr_type()->is_oopptr(), "should be on-heap access");
vlivanov@38131 2433 if (bt == T_BYTE && adr_type->isa_aryptr()) {
vlivanov@38131 2434 // Alias type doesn't differentiate between byte[] and boolean[]).
vlivanov@38131 2435 // Use address type to get the element type.
vlivanov@38131 2436 bt = adr_type->is_aryptr()->elem()->array_element_basic_type();
vlivanov@38131 2437 }
vlivanov@38131 2438 if (bt == T_ARRAY || bt == T_NARROWOOP) {
mchung@52220 2439 // accessing an array field with getReference is not a mismatch
vlivanov@38131 2440 bt = T_OBJECT;
vlivanov@38131 2441 }
vlivanov@38131 2442 if ((bt == T_OBJECT) != (type == T_OBJECT)) {
vlivanov@38131 2443 // Don't intrinsify mismatched object accesses
vlivanov@38131 2444 return false;
vlivanov@38131 2445 }
vlivanov@38131 2446 mismatched = (bt != type);
vlivanov@40880 2447 } else if (alias_type->adr_type()->isa_oopptr()) {
vlivanov@40047 2448 mismatched = true; // conservatively mark all "wide" on-heap accesses as mismatched
vlivanov@38131 2449 }
vlivanov@38131 2450
vlivanov@40880 2451 assert(!mismatched || alias_type->adr_type()->is_oopptr(), "off-heap access can't be mismatched");
vlivanov@40880 2452
eosterlund@50180 2453 if (mismatched) {
eosterlund@50180 2454 decorators |= C2_MISMATCHED;
eosterlund@50180 2455 }
eosterlund@50180 2456
vlivanov@38131 2457 // First guess at the value type.
vlivanov@38131 2458 const Type *value_type = Type::get_const_basic_type(type);
vlivanov@38131 2459
shade@36316 2460 // Figure out the memory ordering.
eosterlund@50180 2461 decorators |= mo_decorator_for_access_kind(kind);
johnc@9176 2462
duke@1 2463 if (!is_store && type == T_OBJECT) {
mikael@38211 2464 const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type);
roland@13886 2465 if (tjp != NULL) {
duke@1 2466 value_type = tjp;
duke@1 2467 }
duke@1 2468 }
duke@1 2469
twisti@14621 2470 receiver = null_check(receiver);
duke@1 2471 if (stopped()) {
duke@1 2472 return true;
duke@1 2473 }
duke@1 2474 // Heap pointers get a null-check from the interpreter,
duke@1 2475 // as a courtesy. However, this is not guaranteed by Unsafe,
duke@1 2476 // and it is not possible to fully distinguish unintended nulls
duke@1 2477 // from intended ones in this API.
duke@1 2478
roland@34157 2479 if (!is_store) {
vlivanov@31857 2480 Node* p = NULL;
vlivanov@31857 2481 // Try to constant fold a load from a constant field
vlivanov@31857 2482 ciField* field = alias_type->field();
vlivanov@38030 2483 if (heap_base_oop != top() && field != NULL && field->is_constant() && !mismatched) {
vlivanov@31857 2484 // final or stable field
vlivanov@38030 2485 p = make_constant_from_field(field, heap_base_oop);
vlivanov@31857 2486 }
eosterlund@50180 2487
eosterlund@50180 2488 if (p == NULL) { // Could not constant fold the load
eosterlund@50180 2489 p = access_load_at(heap_base_oop, adr, adr_type, value_type, type, decorators);
eosterlund@50180 2490 // Normalize the value returned by getBoolean in the following cases
eosterlund@50180 2491 if (type == T_BOOLEAN &&
eosterlund@50180 2492 (mismatched ||
eosterlund@50180 2493 heap_base_oop == top() || // - heap_base_oop is NULL or
eosterlund@50180 2494 (can_access_non_heap && field == NULL)) // - heap_base_oop is potentially NULL
eosterlund@50180 2495 // and the unsafe access is made to large offset
eosterlund@50180 2496 // (i.e., larger than the maximum offset necessary for any
eosterlund@50180 2497 // field access)
zmajo@41052 2498 ) {
zmajo@41052 2499 IdealKit ideal = IdealKit(this);
zmajo@41052 2500 #define __ ideal.
zmajo@41052 2501 IdealVariable normalized_result(ideal);
zmajo@41052 2502 __ declarations_done();
zmajo@41052 2503 __ set(normalized_result, p);
zmajo@41052 2504 __ if_then(p, BoolTest::ne, ideal.ConI(0));
zmajo@41052 2505 __ set(normalized_result, ideal.ConI(1));
zmajo@41052 2506 ideal.end_if();
zmajo@41052 2507 final_sync(ideal);
zmajo@41052 2508 p = __ value(normalized_result);
zmajo@41052 2509 #undef __
zmajo@41052 2510 }
eosterlund@50180 2511 }
eosterlund@50180 2512 if (type == T_ADDRESS) {
eosterlund@50180 2513 p = gvn().transform(new CastP2XNode(NULL, p));
eosterlund@50180 2514 p = ConvX2UL(p);
duke@1 2515 }
twisti@14621 2516 // The load node has the control of the preceding MemBarCPUOrder. All
twisti@14621 2517 // following nodes will have the control of the MemBarCPUOrder inserted at
twisti@14621 2518 // the end of this method. So, pushing the load onto the stack at a later
twisti@14621 2519 // point is fine.
twisti@14621 2520 set_result(p);
duke@1 2521 } else {
eosterlund@50180 2522 if (bt == T_ADDRESS) {
duke@1 2523 // Repackage the long as a pointer.
duke@1 2524 val = ConvL2X(val);
eosterlund@50180 2525 val = gvn().transform(new CastX2PNode(val));
duke@1 2526 }
roland@51880 2527 access_store_at(heap_base_oop, adr, adr_type, val, value_type, type, decorators);
eosterlund@50180 2528 }
duke@1 2529
duke@1 2530 return true;
duke@1 2531 }
duke@1 2532
roland@13886 2533 //----------------------------inline_unsafe_load_store----------------------------
twisti@14621 2534 // This method serves a couple of different customers (depending on LoadStoreKind):
twisti@14621 2535 //
shade@36316 2536 // LS_cmp_swap:
twisti@14621 2537 //
mchung@52220 2538 // boolean compareAndSetReference(Object o, long offset, Object expected, Object x);
psandoz@45514 2539 // boolean compareAndSetInt( Object o, long offset, int expected, int x);
psandoz@45514 2540 // boolean compareAndSetLong( Object o, long offset, long expected, long x);
twisti@14621 2541 //
shade@36316 2542 // LS_cmp_swap_weak:
shade@36316 2543 //
mchung@52220 2544 // boolean weakCompareAndSetReference( Object o, long offset, Object expected, Object x);
mchung@52220 2545 // boolean weakCompareAndSetReferencePlain( Object o, long offset, Object expected, Object x);
mchung@52220 2546 // boolean weakCompareAndSetReferenceAcquire(Object o, long offset, Object expected, Object x);
mchung@52220 2547 // boolean weakCompareAndSetReferenceRelease(Object o, long offset, Object expected, Object x);
shade@36316 2548 //
psandoz@45514 2549 // boolean weakCompareAndSetInt( Object o, long offset, int expected, int x);
psandoz@45514 2550 // boolean weakCompareAndSetIntPlain( Object o, long offset, int expected, int x);
psandoz@45514 2551 // boolean weakCompareAndSetIntAcquire( Object o, long offset, int expected, int x);
psandoz@45514 2552 // boolean weakCompareAndSetIntRelease( Object o, long offset, int expected, int x);
shade@36316 2553 //
psandoz@45514 2554 // boolean weakCompareAndSetLong( Object o, long offset, long expected, long x);
psandoz@45514 2555 // boolean weakCompareAndSetLongPlain( Object o, long offset, long expected, long x);
psandoz@45514 2556 // boolean weakCompareAndSetLongAcquire( Object o, long offset, long expected, long x);
psandoz@45514 2557 // boolean weakCompareAndSetLongRelease( Object o, long offset, long expected, long x);
shade@36316 2558 //
shade@36316 2559 // LS_cmp_exchange:
shade@36316 2560 //
mchung@52220 2561 // Object compareAndExchangeReferenceVolatile(Object o, long offset, Object expected, Object x);
mchung@52220 2562 // Object compareAndExchangeReferenceAcquire( Object o, long offset, Object expected, Object x);
mchung@52220 2563 // Object compareAndExchangeReferenceRelease( Object o, long offset, Object expected, Object x);
shade@36316 2564 //
shade@36316 2565 // Object compareAndExchangeIntVolatile( Object o, long offset, Object expected, Object x);
shade@36316 2566 // Object compareAndExchangeIntAcquire( Object o, long offset, Object expected, Object x);
shade@36316 2567 // Object compareAndExchangeIntRelease( Object o, long offset, Object expected, Object x);
shade@36316 2568 //
shade@36316 2569 // Object compareAndExchangeLongVolatile( Object o, long offset, Object expected, Object x);
shade@36316 2570 // Object compareAndExchangeLongAcquire( Object o, long offset, Object expected, Object x);
shade@36316 2571 // Object compareAndExchangeLongRelease( Object o, long offset, Object expected, Object x);
shade@36316 2572 //
shade@36316 2573 // LS_get_add:
shade@36316 2574 //
shade@36316 2575 // int getAndAddInt( Object o, long offset, int delta)
shade@36316 2576 // long getAndAddLong(Object o, long offset, long delta)
shade@36316 2577 //
shade@36316 2578 // LS_get_set:
shade@36316 2579 //
twisti@14621 2580 // int getAndSet(Object o, long offset, int newValue)
twisti@14621 2581 // long getAndSet(Object o, long offset, long newValue)
twisti@14621 2582 // Object getAndSet(Object o, long offset, Object newValue)
twisti@14621 2583 //
shade@36316 2584 bool LibraryCallKit::inline_unsafe_load_store(const BasicType type, const LoadStoreKind kind, const AccessKind access_kind) {
duke@1 2585 // This basic scheme here is the same as inline_unsafe_access, but
duke@1 2586 // differs in enough details that combining them would make the code
duke@1 2587 // overly confusing. (This is a true fact! I originally combined
duke@1 2588 // them, but even I was confused by it!) As much code/comments as
duke@1 2589 // possible are retained from inline_unsafe_access though to make
twisti@2131 2590 // the correspondences clearer. - dl
duke@1 2591
duke@1 2592 if (callee()->is_static()) return false; // caller must have the capability!
duke@1 2593
eosterlund@50180 2594 DecoratorSet decorators = C2_UNSAFE_ACCESS;
eosterlund@50180 2595 decorators |= mo_decorator_for_access_kind(access_kind);
eosterlund@50180 2596
duke@1 2597 #ifndef PRODUCT
roland@13886 2598 BasicType rtype;
duke@1 2599 {
duke@1 2600 ResourceMark rm;
twisti@14621 2601 // Check the signatures.
twisti@14621 2602 ciSignature* sig = callee()->signature();
roland@13886 2603 rtype = sig->return_type()->basic_type();
shade@36316 2604 switch(kind) {
shade@36316 2605 case LS_get_add:
shade@36316 2606 case LS_get_set: {
roland@13886 2607 // Check the signatures.
duke@1 2608 #ifdef ASSERT
roland@13886 2609 assert(rtype == type, "get and set must return the expected type");
roland@13886 2610 assert(sig->count() == 3, "get and set has 3 arguments");
roland@13886 2611 assert(sig->type_at(0)->basic_type() == T_OBJECT, "get and set base is object");
roland@13886 2612 assert(sig->type_at(1)->basic_type() == T_LONG, "get and set offset is long");
roland@13886 2613 assert(sig->type_at(2)->basic_type() == type, "get and set must take expected type as new value/delta");
mdoerr@38685 2614 assert(access_kind == Volatile, "mo is not passed to intrinsic nodes in current implementation");
duke@1 2615 #endif // ASSERT
shade@36316 2616 break;
shade@36316 2617 }
shade@36316 2618 case LS_cmp_swap:
shade@36316 2619 case LS_cmp_swap_weak: {
roland@13886 2620 // Check the signatures.
roland@13886 2621 #ifdef ASSERT
roland@13886 2622 assert(rtype == T_BOOLEAN, "CAS must return boolean");
roland@13886 2623 assert(sig->count() == 4, "CAS has 4 arguments");
roland@13886 2624 assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object");
roland@13886 2625 assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long");
roland@13886 2626 #endif // ASSERT
shade@36316 2627 break;
shade@36316 2628 }
shade@36316 2629 case LS_cmp_exchange: {
shade@36316 2630 // Check the signatures.
shade@36316 2631 #ifdef ASSERT
shade@36316 2632 assert(rtype == type, "CAS must return the expected type");
shade@36316 2633 assert(sig->count() == 4, "CAS has 4 arguments");
shade@36316 2634 assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object");
shade@36316 2635 assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long");
shade@36316 2636 #endif // ASSERT
shade@36316 2637 break;
shade@36316 2638 }
shade@36316 2639 default:
shade@36316 2640 ShouldNotReachHere();
roland@13886 2641 }
duke@1 2642 }
duke@1 2643 #endif //PRODUCT
duke@1 2644
duke@1 2645 C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
duke@1 2646
twisti@14621 2647 // Get arguments:
twisti@14621 2648 Node* receiver = NULL;
twisti@14621 2649 Node* base = NULL;
twisti@14621 2650 Node* offset = NULL;
twisti@14621 2651 Node* oldval = NULL;
twisti@14621 2652 Node* newval = NULL;
shade@36316 2653 switch(kind) {
shade@36316 2654 case LS_cmp_swap:
shade@36316 2655 case LS_cmp_swap_weak:
shade@36316 2656 case LS_cmp_exchange: {
shade@36316 2657 const bool two_slot_type = type2size[type] == 2;
shade@36316 2658 receiver = argument(0); // type: oop
shade@36316 2659 base = argument(1); // type: oop
shade@36316 2660 offset = argument(2); // type: long
shade@36316 2661 oldval = argument(4); // type: oop, int, or long
shade@36316 2662 newval = argument(two_slot_type ? 6 : 5); // type: oop, int, or long
shade@36316 2663 break;
shade@36316 2664 }
shade@36316 2665 case LS_get_add:
shade@36316 2666 case LS_get_set: {
shade@36316 2667 receiver = argument(0); // type: oop
shade@36316 2668 base = argument(1); // type: oop
shade@36316 2669 offset = argument(2); // type: long
shade@36316 2670 oldval = NULL;
shade@36316 2671 newval = argument(4); // type: oop, int, or long
shade@36316 2672 break;
shade@36316 2673 }
shade@36316 2674 default:
shade@36316 2675 ShouldNotReachHere();
twisti@14621 2676 }
twisti@14621 2677
duke@1 2678 // Build field offset expression.
duke@1 2679 // We currently rely on the cookies produced by Unsafe.xxxFieldOffset
duke@1 2680 // to be plain byte offsets, which are also the same as those accepted
eosterlund@49041 2681 // by oopDesc::field_addr.
duke@1 2682 assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled");
duke@1 2683 // 32-bit machines ignore the high half of long offsets
duke@1 2684 offset = ConvL2X(offset);
rkennke@51850 2685 Node* adr = make_unsafe_address(base, offset, ACCESS_WRITE | ACCESS_READ, type, false);
duke@1 2686 const TypePtr *adr_type = _gvn.type(adr)->isa_ptr();
duke@1 2687
vlivanov@38131 2688 Compile::AliasType* alias_type = C->alias_type(adr_type);
vlivanov@38131 2689 BasicType bt = alias_type->basic_type();
vlivanov@38131 2690 if (bt != T_ILLEGAL &&
vlivanov@38131 2691 ((bt == T_OBJECT || bt == T_ARRAY) != (type == T_OBJECT))) {
vlivanov@38131 2692 // Don't intrinsify mismatched object accesses.
vlivanov@38131 2693 return false;
vlivanov@38131 2694 }
vlivanov@38131 2695
roland@13886 2696 // For CAS, unlike inline_unsafe_access, there seems no point in
roland@13886 2697 // trying to refine types. Just use the coarse types here.
vlivanov@38131 2698 assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here");
duke@1 2699 const Type *value_type = Type::get_const_basic_type(type);
roland@13886 2700
shade@36316 2701 switch (kind) {
shade@36316 2702 case LS_get_set:
shade@36316 2703 case LS_cmp_exchange: {
shade@36316 2704 if (type == T_OBJECT) {
shade@36316 2705 const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type);
shade@36316 2706 if (tjp != NULL) {
shade@36316 2707 value_type = tjp;
shade@36316 2708 }
shade@36316 2709 }
shade@36316 2710 break;
roland@13886 2711 }
shade@36316 2712 case LS_cmp_swap:
shade@36316 2713 case LS_cmp_swap_weak:
shade@36316 2714 case LS_get_add:
shade@36316 2715 break;
shade@36316 2716 default:
shade@36316 2717 ShouldNotReachHere();
roland@13886 2718 }
roland@13886 2719
vlivanov@39718 2720 // Null check receiver.
vlivanov@39718 2721 receiver = null_check(receiver);
vlivanov@39718 2722 if (stopped()) {
vlivanov@39718 2723 return true;
vlivanov@39718 2724 }
vlivanov@39718 2725
duke@1 2726 int alias_idx = C->get_alias_index(adr_type);
duke@1 2727
eosterlund@50180 2728 if (type == T_OBJECT || type == T_ARRAY) {
eosterlund@50180 2729 decorators |= IN_HEAP | ON_UNKNOWN_OOP_REF;
eosterlund@50180 2730
kvn@11724 2731 // Transformation of a value which could be NULL pointer (CastPP #NULL)
kvn@11724 2732 // could be delayed during Parse (for example, in adjust_map_after_if()).
kvn@11724 2733 // Execute transformation here to avoid barrier generation in such case.
kvn@11724 2734 if (_gvn.type(newval) == TypePtr::NULL_PTR)
kvn@11724 2735 newval = _gvn.makecon(TypePtr::NULL_PTR);
kvn@11724 2736
eosterlund@50180 2737 if (oldval != NULL && _gvn.type(oldval) == TypePtr::NULL_PTR) {
eosterlund@50180 2738 // Refine the value to a null constant, when it is known to be null
eosterlund@50180 2739 oldval = _gvn.makecon(TypePtr::NULL_PTR);
kvn@19719 2740 }
eosterlund@50180 2741 }
eosterlund@50180 2742
eosterlund@50180 2743 Node* result = NULL;
eosterlund@50180 2744 switch (kind) {
eosterlund@50180 2745 case LS_cmp_exchange: {
roland@51880 2746 result = access_atomic_cmpxchg_val_at(base, adr, adr_type, alias_idx,
eosterlund@50180 2747 oldval, newval, value_type, type, decorators);
eosterlund@50180 2748 break;
shade@36316 2749 }
eosterlund@50180 2750 case LS_cmp_swap_weak:
eosterlund@50180 2751 decorators |= C2_WEAK_CMPXCHG;
eosterlund@50180 2752 case LS_cmp_swap: {
roland@51880 2753 result = access_atomic_cmpxchg_bool_at(base, adr, adr_type, alias_idx,
eosterlund@50180 2754 oldval, newval, value_type, type, decorators);
eosterlund@50180 2755 break;
shade@32369 2756 }
eosterlund@50180 2757 case LS_get_set: {
roland@51880 2758 result = access_atomic_xchg_at(base, adr, adr_type, alias_idx,
eosterlund@50180 2759 newval, value_type, type, decorators);
eosterlund@50180 2760 break;
kvn@19719 2761 }
eosterlund@50180 2762 case LS_get_add: {
roland@51880 2763 result = access_atomic_add_at(base, adr, adr_type, alias_idx,
eosterlund@50180 2764 newval, value_type, type, decorators);
eosterlund@50180 2765 break;
kvn@19719 2766 }
shade@36316 2767 default:
shade@36316 2768 ShouldNotReachHere();
shade@36316 2769 }
duke@1 2770
eosterlund@50180 2771 assert(type2size[result->bottom_type()->basic_type()] == type2size[rtype], "result type should match");
eosterlund@50180 2772 set_result(result);
duke@1 2773 return true;
duke@1 2774 }
duke@1 2775
kvn@14832 2776 bool LibraryCallKit::inline_unsafe_fence(vmIntrinsics::ID id) {
kvn@14832 2777 // Regardless of form, don't allow previous ld/st to move down,
kvn@14832 2778 // then issue acquire, release, or volatile mem_bar.
kvn@14832 2779 insert_mem_bar(Op_MemBarCPUOrder);
kvn@14832 2780 switch(id) {
kvn@14832 2781 case vmIntrinsics::_loadFence:
goetz@22855 2782 insert_mem_bar(Op_LoadFence);
kvn@14832 2783 return true;
kvn@14832 2784 case vmIntrinsics::_storeFence:
goetz@22855 2785 insert_mem_bar(Op_StoreFence);
kvn@14832 2786 return true;
kvn@14832 2787 case vmIntrinsics::_fullFence:
kvn@14832 2788 insert_mem_bar(Op_MemBarVolatile);
kvn@14832 2789 return true;
kvn@14832 2790 default:
kvn@14832 2791 fatal_unexpected_iid(id);
kvn@14832 2792 return false;
kvn@14832 2793 }
kvn@14832 2794 }
kvn@14832 2795
ikrylov@38017 2796 bool LibraryCallKit::inline_onspinwait() {
ikrylov@38017 2797 insert_mem_bar(Op_OnSpinWait);
ikrylov@38017 2798 return true;
ikrylov@38017 2799 }
ikrylov@38017 2800
rbackman@19337 2801 bool LibraryCallKit::klass_needs_init_guard(Node* kls) {
rbackman@19337 2802 if (!kls->is_Con()) {
rbackman@19337 2803 return true;
rbackman@19337 2804 }
rbackman@19337 2805 const TypeKlassPtr* klsptr = kls->bottom_type()->isa_klassptr();
rbackman@19337 2806 if (klsptr == NULL) {
rbackman@19337 2807 return true;
rbackman@19337 2808 }
rbackman@19337 2809 ciInstanceKlass* ik = klsptr->klass()->as_instance_klass();
rbackman@19337 2810 // don't need a guard for a klass that is already initialized
rbackman@19337 2811 return !ik->is_initialized();
rbackman@19337 2812 }
rbackman@19337 2813
twisti@14621 2814 //----------------------------inline_unsafe_allocate---------------------------
chegar@33606 2815 // public native Object Unsafe.allocateInstance(Class<?> cls);
duke@1 2816 bool LibraryCallKit::inline_unsafe_allocate() {
duke@1 2817 if (callee()->is_static()) return false; // caller must have the capability!
twisti@14621 2818
twisti@14621 2819 null_check_receiver(); // null-check, then ignore
twisti@14621 2820 Node* cls = null_check(argument(1));
duke@1 2821 if (stopped()) return true;
duke@1 2822
twisti@14621 2823 Node* kls = load_klass_from_mirror(cls, false, NULL, 0);
twisti@14621 2824 kls = null_check(kls);
duke@1 2825 if (stopped()) return true; // argument was like int.class
duke@1 2826
rbackman@19337 2827 Node* test = NULL;
rbackman@19337 2828 if (LibraryCallKit::klass_needs_init_guard(kls)) {
rbackman@19337 2829 // Note: The argument might still be an illegal value like
rbackman@19337 2830 // Serializable.class or Object[].class. The runtime will handle it.
rbackman@19337 2831 // But we must make an explicit check for initialization.
rbackman@19337 2832 Node* insp = basic_plus_adr(kls, in_bytes(InstanceKlass::init_state_offset()));
rbackman@19337 2833 // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler
rbackman@19337 2834 // can generate code to load it as unsigned byte.
goetz@22845 2835 Node* inst = make_load(NULL, insp, TypeInt::UBYTE, T_BOOLEAN, MemNode::unordered);
rbackman@19337 2836 Node* bits = intcon(InstanceKlass::fully_initialized);
thartmann@24923 2837 test = _gvn.transform(new SubINode(inst, bits));
rbackman@19337 2838 // The 'test' is non-zero if we need to take a slow path.
rbackman@19337 2839 }
duke@1 2840
duke@1 2841 Node* obj = new_instance(kls, test);
twisti@14621 2842 set_result(obj);
duke@1 2843 return true;
duke@1 2844 }
duke@1 2845
duke@1 2846 //------------------------inline_native_time_funcs--------------
duke@1 2847 // inline code for System.currentTimeMillis() and System.nanoTime()
duke@1 2848 // these have the same type and signature
rbackman@12377 2849 bool LibraryCallKit::inline_native_time_funcs(address funcAddr, const char* funcName) {
twisti@14621 2850 const TypeFunc* tf = OptoRuntime::void_long_Type();
duke@1 2851 const TypePtr* no_memory_effects = NULL;
duke@1 2852 Node* time = make_runtime_call(RC_LEAF, tf, funcAddr, funcName, no_memory_effects);
thartmann@24923 2853 Node* value = _gvn.transform(new ProjNode(time, TypeFunc::Parms+0));
duke@1 2854 #ifdef ASSERT
thartmann@24923 2855 Node* value_top = _gvn.transform(new ProjNode(time, TypeFunc::Parms+1));
duke@1 2856 assert(value_top == top(), "second value must be top");
duke@1 2857 #endif
twisti@14621 2858 set_result(value);
duke@1 2859 return true;
duke@1 2860 }
duke@1 2861
egahlin@50113 2862 #ifdef JFR_HAVE_INTRINSICS
rehn@40899 2863
rehn@40899 2864 /*
rehn@40899 2865 * oop -> myklass
rehn@40899 2866 * myklass->trace_id |= USED
rehn@40899 2867 * return myklass->trace_id & ~0x3
rehn@40899 2868 */
rehn@40899 2869 bool LibraryCallKit::inline_native_classID() {
rehn@40899 2870 Node* cls = null_check(argument(0), T_OBJECT);
rehn@40899 2871 Node* kls = load_klass_from_mirror(cls, false, NULL, 0);
rehn@40899 2872 kls = null_check(kls, T_OBJECT);
rehn@40899 2873
egahlin@50113 2874 ByteSize offset = KLASS_TRACE_ID_OFFSET;
rehn@40899 2875 Node* insp = basic_plus_adr(kls, in_bytes(offset));
rehn@40899 2876 Node* tvalue = make_load(NULL, insp, TypeLong::LONG, T_LONG, MemNode::unordered);
rehn@40899 2877
rehn@40899 2878 Node* clsused = longcon(0x01l); // set the class bit
rehn@40899 2879 Node* orl = _gvn.transform(new OrLNode(tvalue, clsused));
rehn@40899 2880 const TypePtr *adr_type = _gvn.type(insp)->isa_ptr();
rehn@40899 2881 store_to_memory(control(), insp, orl, T_LONG, adr_type, MemNode::unordered);
rehn@40899 2882
rehn@40899 2883 #ifdef TRACE_ID_META_BITS
rehn@40899 2884 Node* mbits = longcon(~TRACE_ID_META_BITS);
rehn@40899 2885 tvalue = _gvn.transform(new AndLNode(tvalue, mbits));
rehn@40899 2886 #endif
egahlin@50113 2887 #ifdef TRACE_ID_SHIFT
egahlin@50113 2888 Node* cbits = intcon(TRACE_ID_SHIFT);
rehn@40899 2889 tvalue = _gvn.transform(new URShiftLNode(tvalue, cbits));
rehn@40899 2890 #endif
rehn@40899 2891
rehn@40899 2892 set_result(tvalue);
rehn@40899 2893 return true;
rehn@40899 2894
rehn@40899 2895 }
rehn@40899 2896
egahlin@50113 2897 bool LibraryCallKit::inline_native_getEventWriter() {
mgronlun@42037 2898 Node* tls_ptr = _gvn.transform(new ThreadLocalNode());
mgronlun@42037 2899
mgronlun@42037 2900 Node* jobj_ptr = basic_plus_adr(top(), tls_ptr,
eosterlund@51643 2901 in_bytes(THREAD_LOCAL_WRITER_OFFSET_JFR));
mgronlun@42037 2902
mgronlun@42037 2903 Node* jobj = make_load(control(), jobj_ptr, TypeRawPtr::BOTTOM, T_ADDRESS, MemNode::unordered);
mgronlun@42037 2904
mgronlun@42037 2905 Node* jobj_cmp_null = _gvn.transform( new CmpPNode(jobj, null()) );
mgronlun@42037 2906 Node* test_jobj_eq_null = _gvn.transform( new BoolNode(jobj_cmp_null, BoolTest::eq) );
mgronlun@42037 2907
mgronlun@42037 2908 IfNode* iff_jobj_null =
mgronlun@42069 2909 create_and_map_if(control(), test_jobj_eq_null, PROB_MIN, COUNT_UNKNOWN);
mgronlun@42069 2910
mgronlun@42069 2911 enum { _normal_path = 1,
mgronlun@42069 2912 _null_path = 2,
mgronlun@42069 2913 PATH_LIMIT };
mgronlun@42037 2914
mgronlun@42037 2915 RegionNode* result_rgn = new RegionNode(PATH_LIMIT);
eosterlund@51643 2916 PhiNode* result_val = new PhiNode(result_rgn, TypeInstPtr::BOTTOM);
mgronlun@42069 2917
mgronlun@42069 2918 Node* jobj_is_null = _gvn.transform(new IfTrueNode(iff_jobj_null));
mgronlun@42037 2919 result_rgn->init_req(_null_path, jobj_is_null);
mgronlun@42037 2920 result_val->init_req(_null_path, null());
mgronlun@42037 2921
mgronlun@42069 2922 Node* jobj_is_not_null = _gvn.transform(new IfFalseNode(iff_jobj_null));
eosterlund@51643 2923 set_control(jobj_is_not_null);
eosterlund@51643 2924 Node* res = access_load(jobj, TypeInstPtr::NOTNULL, T_OBJECT,
eosterlund@51643 2925 IN_NATIVE | C2_CONTROL_DEPENDENT_LOAD);
eosterlund@51643 2926 result_rgn->init_req(_normal_path, control());
mgronlun@42037 2927 result_val->init_req(_normal_path, res);
mgronlun@42037 2928
mgronlun@42037 2929 set_result(result_rgn, result_val);
mgronlun@42037 2930
mgronlun@42037 2931 return true;
mgronlun@42037 2932 }
mgronlun@42037 2933
egahlin@50113 2934 #endif // JFR_HAVE_INTRINSICS
rehn@40899 2935
duke@1 2936 //------------------------inline_native_currentThread------------------
duke@1 2937 bool LibraryCallKit::inline_native_currentThread() {
duke@1 2938 Node* junk = NULL;
twisti@14621 2939 set_result(generate_current_thread(junk));
duke@1 2940 return true;
duke@1 2941 }
duke@1 2942
duke@1 2943 //------------------------inline_native_isInterrupted------------------
twisti@14621 2944 // private native boolean java.lang.Thread.isInterrupted(boolean ClearInterrupted);
duke@1 2945 bool LibraryCallKit::inline_native_isInterrupted() {
duke@1 2946 // Add a fast path to t.isInterrupted(clear_int):
dsamersoff@23181 2947 // (t == Thread.current() &&
dsamersoff@23181 2948 // (!TLS._osthread._interrupted || WINDOWS_ONLY(false) NOT_WINDOWS(!clear_int)))
duke@1 2949 // ? TLS._osthread._interrupted : /*slow path:*/ t.isInterrupted(clear_int)
duke@1 2950 // So, in the common case that the interrupt bit is false,
duke@1 2951 // we avoid making a call into the VM. Even if the interrupt bit
duke@1 2952 // is true, if the clear_int argument is false, we avoid the VM call.
duke@1 2953 // However, if the receiver is not currentThread, we must call the VM,
duke@1 2954 // because there must be some locking done around the operation.
duke@1 2955
duke@1 2956 // We only go to the fast case code if we pass two guards.
duke@1 2957 // Paths which do not pass are accumulated in the slow_region.
vlivanov@14829 2958
vlivanov@14829 2959 enum {
vlivanov@14829 2960 no_int_result_path = 1, // t == Thread.current() && !TLS._osthread._interrupted
vlivanov@14829 2961 no_clear_result_path = 2, // t == Thread.current() && TLS._osthread._interrupted && !clear_int
vlivanov@14829 2962 slow_result_path = 3, // slow path: t.isInterrupted(clear_int)
vlivanov@14829 2963 PATH_LIMIT
vlivanov@14829 2964 };
vlivanov@14829 2965
vlivanov@14829 2966 // Ensure that it's not possible to move the load of TLS._osthread._interrupted flag
vlivanov@14829 2967 // out of the function.
vlivanov@14829 2968 insert_mem_bar(Op_MemBarCPUOrder);
vlivanov@14829 2969
thartmann@24923 2970 RegionNode* result_rgn = new RegionNode(PATH_LIMIT);
thartmann@24923 2971 PhiNode* result_val = new PhiNode(result_rgn, TypeInt::BOOL);
thartmann@24923 2972
thartmann@24923 2973 RegionNode* slow_region = new RegionNode(1);
duke@1 2974 record_for_igvn(slow_region);
duke@1 2975
duke@1 2976 // (a) Receiving thread must be the current thread.
duke@1 2977 Node* rec_thr = argument(0);
duke@1 2978 Node* tls_ptr = NULL;
duke@1 2979 Node* cur_thr = generate_current_thread(tls_ptr);
rkennke@51850 2980
rkennke@51850 2981 // Resolve oops to stable for CmpP below.
rkennke@51850 2982 cur_thr = access_resolve(cur_thr, 0);
rkennke@51850 2983 rec_thr = access_resolve(rec_thr, 0);
rkennke@51850 2984
thartmann@24923 2985 Node* cmp_thr = _gvn.transform(new CmpPNode(cur_thr, rec_thr));
thartmann@24923 2986 Node* bol_thr = _gvn.transform(new BoolNode(cmp_thr, BoolTest::ne));
duke@1 2987
vlivanov@14829 2988 generate_slow_guard(bol_thr, slow_region);
duke@1 2989
duke@1 2990 // (b) Interrupt bit on TLS must be false.
duke@1 2991 Node* p = basic_plus_adr(top()/*!oop*/, tls_ptr, in_bytes(JavaThread::osthread_offset()));
goetz@22845 2992 Node* osthread = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered);
duke@1 2993 p = basic_plus_adr(top()/*!oop*/, osthread, in_bytes(OSThread::interrupted_offset()));
vlivanov@14829 2994
kvn@2874 2995 // Set the control input on the field _interrupted read to prevent it floating up.
goetz@22845 2996 Node* int_bit = make_load(control(), p, TypeInt::BOOL, T_INT, MemNode::unordered);
thartmann@24923 2997 Node* cmp_bit = _gvn.transform(new CmpINode(int_bit, intcon(0)));
thartmann@24923 2998 Node* bol_bit = _gvn.transform(new BoolNode(cmp_bit, BoolTest::ne));
duke@1 2999
duke@1 3000 IfNode* iff_bit = create_and_map_if(control(), bol_bit, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN);
duke@1 3001
duke@1 3002 // First fast path: if (!TLS._interrupted) return false;
thartmann@24923 3003 Node* false_bit = _gvn.transform(new IfFalseNode(iff_bit));
duke@1 3004 result_rgn->init_req(no_int_result_path, false_bit);
duke@1 3005 result_val->init_req(no_int_result_path, intcon(0));
duke@1 3006
duke@1 3007 // drop through to next case
thartmann@24923 3008 set_control( _gvn.transform(new IfTrueNode(iff_bit)));
duke@1 3009
goetz@40010 3010 #ifndef _WINDOWS
duke@1 3011 // (c) Or, if interrupt bit is set and clear_int is false, use 2nd fast path.
duke@1 3012 Node* clr_arg = argument(1);
thartmann@24923 3013 Node* cmp_arg = _gvn.transform(new CmpINode(clr_arg, intcon(0)));
thartmann@24923 3014 Node* bol_arg = _gvn.transform(new BoolNode(cmp_arg, BoolTest::ne));
duke@1 3015 IfNode* iff_arg = create_and_map_if(control(), bol_arg, PROB_FAIR, COUNT_UNKNOWN);
duke@1 3016
duke@1 3017 // Second fast path: ... else if (!clear_int) return true;
thartmann@24923 3018 Node* false_arg = _gvn.transform(new IfFalseNode(iff_arg));
duke@1 3019 result_rgn->init_req(no_clear_result_path, false_arg);
duke@1 3020 result_val->init_req(no_clear_result_path, intcon(1));
duke@1 3021
duke@1 3022 // drop through to next case
thartmann@24923 3023 set_control( _gvn.transform(new IfTrueNode(iff_arg)));
dsamersoff@23181 3024 #else
dsamersoff@23181 3025 // To return true on Windows you must read the _interrupted field
zmajo@35548 3026 // and check the event state i.e. take the slow path.
goetz@40010 3027 #endif // _WINDOWS
duke@1 3028
duke@1 3029 // (d) Otherwise, go to the slow path.
duke@1 3030 slow_region->add_req(control());
drchase@18507 3031 set_control( _gvn.transform(slow_region));
duke@1 3032
duke@1 3033 if (stopped()) {
duke@1 3034 // There is no slow path.
duke@1 3035 result_rgn->init_req(slow_result_path, top());
duke@1 3036 result_val->init_req(slow_result_path, top());
duke@1 3037 } else {
duke@1 3038 // non-virtual because it is a private non-static
duke@1 3039 CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_isInterrupted);
duke@1 3040
duke@1 3041 Node* slow_val = set_results_for_java_call(slow_call);
duke@1 3042 // this->control() comes from set_results_for_java_call
duke@1 3043
duke@1 3044 Node* fast_io = slow_call->in(TypeFunc::I_O);
duke@1 3045 Node* fast_mem = slow_call->in(TypeFunc::Memory);
vlivanov@14829 3046
duke@1 3047 // These two phis are pre-filled with copies of of the fast IO and Memory
vlivanov@14829 3048 PhiNode* result_mem = PhiNode::make(result_rgn, fast_mem, Type::MEMORY, TypePtr::BOTTOM);
vlivanov@14829 3049 PhiNode* result_io = PhiNode::make(result_rgn, fast_io, Type::ABIO);
duke@1 3050
duke@1 3051 result_rgn->init_req(slow_result_path, control());
vlivanov@14829 3052 result_io ->init_req(slow_result_path, i_o());
vlivanov@14829 3053 result_mem->init_req(slow_result_path, reset_memory());
duke@1 3054 result_val->init_req(slow_result_path, slow_val);
duke@1 3055
vlivanov@14829 3056 set_all_memory(_gvn.transform(result_mem));
vlivanov@14829 3057 set_i_o( _gvn.transform(result_io));
duke@1 3058 }
duke@1 3059
duke@1 3060 C->set_has_split_ifs(true); // Has chance for split-if optimization
twisti@14621 3061 set_result(result_rgn, result_val);
duke@1 3062 return true;
duke@1 3063 }
duke@1 3064
duke@1 3065 //---------------------------load_mirror_from_klass----------------------------
duke@1 3066 // Given a klass oop, load its java mirror (a java.lang.Class oop).
duke@1 3067 Node* LibraryCallKit::load_mirror_from_klass(Node* klass) {
stefank@11430 3068 Node* p = basic_plus_adr(klass, in_bytes(Klass::java_mirror_offset()));
coleenp@47580 3069 Node* load = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered);
coleenp@49816 3070 // mirror = ((OopHandle)mirror)->resolve();
eosterlund@51485 3071 return access_load(load, TypeInstPtr::MIRROR, T_OBJECT, IN_NATIVE);
duke@1 3072 }
duke@1 3073
duke@1 3074 //-----------------------load_klass_from_mirror_common-------------------------
duke@1 3075 // Given a java mirror (a java.lang.Class oop), load its corresponding klass oop.
duke@1 3076 // Test the klass oop for null (signifying a primitive Class like Integer.TYPE),
duke@1 3077 // and branch to the given path on the region.
duke@1 3078 // If never_see_null, take an uncommon trap on null, so we can optimistically
duke@1 3079 // compile for the non-null case.
duke@1 3080 // If the region is NULL, force never_see_null = true.
duke@1 3081 Node* LibraryCallKit::load_klass_from_mirror_common(Node* mirror,
duke@1 3082 bool never_see_null,
duke@1 3083 RegionNode* region,
duke@1 3084 int null_path,
duke@1 3085 int offset) {
duke@1 3086 if (region == NULL) never_see_null = true;
duke@1 3087 Node* p = basic_plus_adr(mirror, offset);
duke@1 3088 const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL;
zmajo@27637 3089 Node* kls = _gvn.transform(LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type));
duke@1 3090 Node* null_ctl = top();
duke@1 3091 kls = null_check_oop(kls, &null_ctl, never_see_null);
duke@1 3092 if (region != NULL) {
duke@1 3093 // Set region->in(null_path) if the mirror is a primitive (e.g, int.class).
duke@1 3094 region->init_req(null_path, null_ctl);
duke@1 3095 } else {
duke@1 3096 assert(null_ctl == top(), "no loose ends");
duke@1 3097 }
duke@1 3098 return kls;
duke@1 3099 }
duke@1 3100
duke@1 3101 //--------------------(inline_native_Class_query helpers)---------------------
vlivanov@35544 3102 // Use this for JVM_ACC_INTERFACE, JVM_ACC_IS_CLONEABLE_FAST, JVM_ACC_HAS_FINALIZER.
duke@1 3103 // Fall through if (mods & mask) == bits, take the guard otherwise.
duke@1 3104 Node* LibraryCallKit::generate_access_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) {
duke@1 3105 // Branch around if the given klass has the given modifier bit set.
duke@1 3106 // Like generate_guard, adds a new path onto the region.
stefank@11430 3107 Node* modp = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset()));
goetz@22845 3108 Node* mods = make_load(NULL, modp, TypeInt::INT, T_INT, MemNode::unordered);
duke@1 3109 Node* mask = intcon(modifier_mask);
duke@1 3110 Node* bits = intcon(modifier_bits);
thartmann@24923 3111 Node* mbit = _gvn.transform(new AndINode(mods, mask));
thartmann@24923 3112 Node* cmp = _gvn.transform(new CmpINode(mbit, bits));
thartmann@24923 3113 Node* bol = _gvn.transform(new BoolNode(cmp, BoolTest::ne));
duke@1 3114 return generate_fair_guard(bol, region);
duke@1 3115 }
duke@1 3116 Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) {
duke@1 3117 return generate_access_flags_guard(kls, JVM_ACC_INTERFACE, 0, region);
duke@1 3118 }
duke@1 3119
duke@1 3120 //-------------------------inline_native_Class_query-------------------
duke@1 3121 bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) {
duke@1 3122 const Type* return_type = TypeInt::BOOL;
duke@1 3123 Node* prim_return_value = top(); // what happens if it's a primitive class?
duke@1 3124 bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check);
duke@1 3125 bool expect_prim = false; // most of these guys expect to work on refs
duke@1 3126
duke@1 3127 enum { _normal_path = 1, _prim_path = 2, PATH_LIMIT };
duke@1 3128
twisti@14621 3129 Node* mirror = argument(0);
twisti@14621 3130 Node* obj = top();
twisti@14621 3131
duke@1 3132 switch (id) {
duke@1 3133 case vmIntrinsics::_isInstance:
duke@1 3134 // nothing is an instance of a primitive type
duke@1 3135 prim_return_value = intcon(0);
twisti@14621 3136 obj = argument(1);
duke@1 3137 break;
duke@1 3138 case vmIntrinsics::_getModifiers:
duke@1 3139 prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC);
duke@1 3140 assert(is_power_of_2((int)JVM_ACC_WRITTEN_FLAGS+1), "change next line");
duke@1 3141 return_type = TypeInt::make(0, JVM_ACC_WRITTEN_FLAGS, Type::WidenMin);
duke@1 3142 break;
duke@1 3143 case vmIntrinsics::_isInterface:
duke@1 3144 prim_return_value = intcon(0);
duke@1 3145 break;
duke@1 3146 case vmIntrinsics::_isArray:
duke@1 3147 prim_return_value = intcon(0);
duke@1 3148 expect_prim = true; // cf. ObjectStreamClass.getClassSignature
duke@1 3149 break;
duke@1 3150 case vmIntrinsics::_isPrimitive:
duke@1 3151 prim_return_value = intcon(1);
duke@1 3152 expect_prim = true; // obviously
duke@1 3153 break;
duke@1 3154 case vmIntrinsics::_getSuperclass:
duke@1 3155 prim_return_value = null();
duke@1 3156 return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR);
duke@1 3157 break;
duke@1 3158 case vmIntrinsics::_getClassAccessFlags:
duke@1 3159 prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC);
duke@1 3160 return_type = TypeInt::INT; // not bool! 6297094
duke@1 3161 break;
duke@1 3162 default:
twisti@14621 3163 fatal_unexpected_iid(id);
twisti@14621 3164 break;
duke@1 3165 }
duke@1 3166
duke@1 3167 const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr();
duke@1 3168 if (mirror_con == NULL) return false; // cannot happen?
duke@1 3169
duke@1 3170 #ifndef PRODUCT
kvn@20073 3171 if (C->print_intrinsics() || C->print_inlining()) {
duke@1 3172 ciType* k = mirror_con->java_mirror_type();
duke@1 3173 if (k) {
duke@1 3174 tty->print("Inlining %s on constant Class ", vmIntrinsics::name_at(intrinsic_id()));
duke@1 3175 k->print_name();
duke@1 3176 tty->cr();
duke@1 3177 }
duke@1 3178 }
duke@1 3179 #endif
duke@1 3180
duke@1 3181 // Null-check the mirror, and the mirror's klass ptr (in case it is a primitive).
thartmann@24923 3182 RegionNode* region = new RegionNode(PATH_LIMIT);
duke@1 3183 record_for_igvn(region);
thartmann@24923 3184 PhiNode* phi = new PhiNode(region, return_type);
duke@1 3185
duke@1 3186 // The mirror will never be null of Reflection.getClassAccessFlags, however
duke@1 3187 // it may be null for Class.isInstance or Class.getModifiers. Throw a NPE
duke@1 3188 // if it is. See bug 4774291.
duke@1 3189
duke@1 3190 // For Reflection.getClassAccessFlags(), the null check occurs in
duke@1 3191 // the wrong place; see inline_unsafe_access(), above, for a similar
duke@1 3192 // situation.
twisti@14621 3193 mirror = null_check(mirror);
duke@1 3194 // If mirror or obj is dead, only null-path is taken.
duke@1 3195 if (stopped()) return true;
duke@1 3196
duke@1 3197 if (expect_prim) never_see_null = false; // expect nulls (meaning prims)
duke@1 3198
duke@1 3199 // Now load the mirror's klass metaobject, and null-check it.
duke@1 3200 // Side-effects region with the control path if the klass is null.
twisti@14621 3201 Node* kls = load_klass_from_mirror(mirror, never_see_null, region, _prim_path);
duke@1 3202 // If kls is null, we have a primitive mirror.
duke@1 3203 phi->init_req(_prim_path, prim_return_value);
twisti@14621 3204 if (stopped()) { set_result(region, phi); return true; }
roland@21099 3205 bool safe_for_replace = (region->in(_prim_path) == top());
duke@1 3206
duke@1 3207 Node* p; // handy temp
duke@1 3208 Node* null_ctl;
duke@1 3209
duke@1 3210 // Now that we have the non-null klass, we can perform the real query.
duke@1 3211 // For constant classes, the query will constant-fold in LoadNode::Value.
duke@1 3212 Node* query_value = top();
duke@1 3213 switch (id) {
duke@1 3214 case vmIntrinsics::_isInstance:
duke@1 3215 // nothing is an instance of a primitive type
roland@21099 3216 query_value = gen_instanceof(obj, kls, safe_for_replace);
duke@1 3217 break;
duke@1 3218
duke@1 3219 case vmIntrinsics::_getModifiers:
stefank@11430 3220 p = basic_plus_adr(kls, in_bytes(Klass::modifier_flags_offset()));
goetz@22845 3221 query_value = make_load(NULL, p, TypeInt::INT, T_INT, MemNode::unordered);
duke@1 3222 break;
duke@1 3223
duke@1 3224 case vmIntrinsics::_isInterface:
duke@1 3225 // (To verify this code sequence, check the asserts in JVM_IsInterface.)
duke@1 3226 if (generate_interface_guard(kls, region) != NULL)
duke@1 3227 // A guard was added. If the guard is taken, it was an interface.
duke@1 3228 phi->add_req(intcon(1));
duke@1 3229 // If we fall through, it's a plain class.
duke@1 3230 query_value = intcon(0);
duke@1 3231 break;
duke@1 3232
duke@1 3233 case vmIntrinsics::_isArray:
duke@1 3234 // (To verify this code sequence, check the asserts in JVM_IsArrayClass.)
duke@1 3235 if (generate_array_guard(kls, region) != NULL)
duke@1 3236 // A guard was added. If the guard is taken, it was an array.
duke@1 3237 phi->add_req(intcon(1));
duke@1 3238 // If we fall through, it's a plain class.
duke@1 3239 query_value = intcon(0);
duke@1 3240 break;
duke@1 3241
duke@1 3242 case vmIntrinsics::_isPrimitive:
duke@1 3243 query_value = intcon(0); // "normal" path produces false
duke@1 3244 break;
duke@1 3245
duke@1 3246 case vmIntrinsics::_getSuperclass:
duke@1 3247 // The rules here are somewhat unfortunate, but we can still do better
duke@1 3248 // with random logic than with a JNI call.
duke@1 3249 // Interfaces store null or Object as _super, but must report null.
duke@1 3250 // Arrays store an intermediate super as _super, but must report Object.
duke@1 3251 // Other types can report the actual _super.
duke@1 3252 // (To verify this code sequence, check the asserts in JVM_IsInterface.)
duke@1 3253 if (generate_interface_guard(kls, region) != NULL)
duke@1 3254 // A guard was added. If the guard is taken, it was an interface.
duke@1 3255 phi->add_req(null());
duke@1 3256 if (generate_array_guard(kls, region) != NULL)
duke@1 3257 // A guard was added. If the guard is taken, it was an array.
duke@1 3258 phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror())));
duke@1 3259 // If we fall through, it's a plain class. Get its _super.
stefank@11430 3260 p = basic_plus_adr(kls, in_bytes(Klass::super_offset()));
zmajo@27637 3261 kls = _gvn.transform(LoadKlassNode::make(_gvn, NULL, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeKlassPtr::OBJECT_OR_NULL));
duke@1 3262 null_ctl = top();
duke@1 3263 kls = null_check_oop(kls, &null_ctl);
duke@1 3264 if (null_ctl != top()) {
duke@1 3265 // If the guard is taken, Object.superClass is null (both klass and mirror).
duke@1 3266 region->add_req(null_ctl);
duke@1 3267 phi ->add_req(null());