1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/opto/library_call.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,6124 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "classfile/systemDictionary.hpp" 1.30 +#include "classfile/vmSymbols.hpp" 1.31 +#include "compiler/compileBroker.hpp" 1.32 +#include "compiler/compileLog.hpp" 1.33 +#include "oops/objArrayKlass.hpp" 1.34 +#include "opto/addnode.hpp" 1.35 +#include "opto/callGenerator.hpp" 1.36 +#include "opto/cfgnode.hpp" 1.37 +#include "opto/idealKit.hpp" 1.38 +#include "opto/mathexactnode.hpp" 1.39 +#include "opto/mulnode.hpp" 1.40 +#include "opto/parse.hpp" 1.41 +#include "opto/runtime.hpp" 1.42 +#include "opto/subnode.hpp" 1.43 +#include "prims/nativeLookup.hpp" 1.44 +#include "runtime/sharedRuntime.hpp" 1.45 +#include "trace/traceMacros.hpp" 1.46 + 1.47 +class LibraryIntrinsic : public InlineCallGenerator { 1.48 + // Extend the set of intrinsics known to the runtime: 1.49 + public: 1.50 + private: 1.51 + bool _is_virtual; 1.52 + bool _is_predicted; 1.53 + bool _does_virtual_dispatch; 1.54 + vmIntrinsics::ID _intrinsic_id; 1.55 + 1.56 + public: 1.57 + LibraryIntrinsic(ciMethod* m, bool is_virtual, bool is_predicted, bool does_virtual_dispatch, vmIntrinsics::ID id) 1.58 + : InlineCallGenerator(m), 1.59 + _is_virtual(is_virtual), 1.60 + _is_predicted(is_predicted), 1.61 + _does_virtual_dispatch(does_virtual_dispatch), 1.62 + _intrinsic_id(id) 1.63 + { 1.64 + } 1.65 + virtual bool is_intrinsic() const { return true; } 1.66 + virtual bool is_virtual() const { return _is_virtual; } 1.67 + virtual bool is_predicted() const { return _is_predicted; } 1.68 + virtual bool does_virtual_dispatch() const { return _does_virtual_dispatch; } 1.69 + virtual JVMState* generate(JVMState* jvms, Parse* parent_parser); 1.70 + virtual Node* generate_predicate(JVMState* jvms); 1.71 + vmIntrinsics::ID intrinsic_id() const { return _intrinsic_id; } 1.72 +}; 1.73 + 1.74 + 1.75 +// Local helper class for LibraryIntrinsic: 1.76 +class LibraryCallKit : public GraphKit { 1.77 + private: 1.78 + LibraryIntrinsic* _intrinsic; // the library intrinsic being called 1.79 + Node* _result; // the result node, if any 1.80 + int _reexecute_sp; // the stack pointer when bytecode needs to be reexecuted 1.81 + 1.82 + const TypeOopPtr* sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type, bool is_native_ptr = false); 1.83 + 1.84 + public: 1.85 + LibraryCallKit(JVMState* jvms, LibraryIntrinsic* intrinsic) 1.86 + : GraphKit(jvms), 1.87 + _intrinsic(intrinsic), 1.88 + _result(NULL) 1.89 + { 1.90 + // Check if this is a root compile. In that case we don't have a caller. 1.91 + if (!jvms->has_method()) { 1.92 + _reexecute_sp = sp(); 1.93 + } else { 1.94 + // Find out how many arguments the interpreter needs when deoptimizing 1.95 + // and save the stack pointer value so it can used by uncommon_trap. 1.96 + // We find the argument count by looking at the declared signature. 1.97 + bool ignored_will_link; 1.98 + ciSignature* declared_signature = NULL; 1.99 + ciMethod* ignored_callee = caller()->get_method_at_bci(bci(), ignored_will_link, &declared_signature); 1.100 + const int nargs = declared_signature->arg_size_for_bc(caller()->java_code_at_bci(bci())); 1.101 + _reexecute_sp = sp() + nargs; // "push" arguments back on stack 1.102 + } 1.103 + } 1.104 + 1.105 + virtual LibraryCallKit* is_LibraryCallKit() const { return (LibraryCallKit*)this; } 1.106 + 1.107 + ciMethod* caller() const { return jvms()->method(); } 1.108 + int bci() const { return jvms()->bci(); } 1.109 + LibraryIntrinsic* intrinsic() const { return _intrinsic; } 1.110 + vmIntrinsics::ID intrinsic_id() const { return _intrinsic->intrinsic_id(); } 1.111 + ciMethod* callee() const { return _intrinsic->method(); } 1.112 + 1.113 + bool try_to_inline(); 1.114 + Node* try_to_predicate(); 1.115 + 1.116 + void push_result() { 1.117 + // Push the result onto the stack. 1.118 + if (!stopped() && result() != NULL) { 1.119 + BasicType bt = result()->bottom_type()->basic_type(); 1.120 + push_node(bt, result()); 1.121 + } 1.122 + } 1.123 + 1.124 + private: 1.125 + void fatal_unexpected_iid(vmIntrinsics::ID iid) { 1.126 + fatal(err_msg_res("unexpected intrinsic %d: %s", iid, vmIntrinsics::name_at(iid))); 1.127 + } 1.128 + 1.129 + void set_result(Node* n) { assert(_result == NULL, "only set once"); _result = n; } 1.130 + void set_result(RegionNode* region, PhiNode* value); 1.131 + Node* result() { return _result; } 1.132 + 1.133 + virtual int reexecute_sp() { return _reexecute_sp; } 1.134 + 1.135 + // Helper functions to inline natives 1.136 + Node* generate_guard(Node* test, RegionNode* region, float true_prob); 1.137 + Node* generate_slow_guard(Node* test, RegionNode* region); 1.138 + Node* generate_fair_guard(Node* test, RegionNode* region); 1.139 + Node* generate_negative_guard(Node* index, RegionNode* region, 1.140 + // resulting CastII of index: 1.141 + Node* *pos_index = NULL); 1.142 + Node* generate_nonpositive_guard(Node* index, bool never_negative, 1.143 + // resulting CastII of index: 1.144 + Node* *pos_index = NULL); 1.145 + Node* generate_limit_guard(Node* offset, Node* subseq_length, 1.146 + Node* array_length, 1.147 + RegionNode* region); 1.148 + Node* generate_current_thread(Node* &tls_output); 1.149 + address basictype2arraycopy(BasicType t, Node *src_offset, Node *dest_offset, 1.150 + bool disjoint_bases, const char* &name, bool dest_uninitialized); 1.151 + Node* load_mirror_from_klass(Node* klass); 1.152 + Node* load_klass_from_mirror_common(Node* mirror, bool never_see_null, 1.153 + RegionNode* region, int null_path, 1.154 + int offset); 1.155 + Node* load_klass_from_mirror(Node* mirror, bool never_see_null, 1.156 + RegionNode* region, int null_path) { 1.157 + int offset = java_lang_Class::klass_offset_in_bytes(); 1.158 + return load_klass_from_mirror_common(mirror, never_see_null, 1.159 + region, null_path, 1.160 + offset); 1.161 + } 1.162 + Node* load_array_klass_from_mirror(Node* mirror, bool never_see_null, 1.163 + RegionNode* region, int null_path) { 1.164 + int offset = java_lang_Class::array_klass_offset_in_bytes(); 1.165 + return load_klass_from_mirror_common(mirror, never_see_null, 1.166 + region, null_path, 1.167 + offset); 1.168 + } 1.169 + Node* generate_access_flags_guard(Node* kls, 1.170 + int modifier_mask, int modifier_bits, 1.171 + RegionNode* region); 1.172 + Node* generate_interface_guard(Node* kls, RegionNode* region); 1.173 + Node* generate_array_guard(Node* kls, RegionNode* region) { 1.174 + return generate_array_guard_common(kls, region, false, false); 1.175 + } 1.176 + Node* generate_non_array_guard(Node* kls, RegionNode* region) { 1.177 + return generate_array_guard_common(kls, region, false, true); 1.178 + } 1.179 + Node* generate_objArray_guard(Node* kls, RegionNode* region) { 1.180 + return generate_array_guard_common(kls, region, true, false); 1.181 + } 1.182 + Node* generate_non_objArray_guard(Node* kls, RegionNode* region) { 1.183 + return generate_array_guard_common(kls, region, true, true); 1.184 + } 1.185 + Node* generate_array_guard_common(Node* kls, RegionNode* region, 1.186 + bool obj_array, bool not_array); 1.187 + Node* generate_virtual_guard(Node* obj_klass, RegionNode* slow_region); 1.188 + CallJavaNode* generate_method_call(vmIntrinsics::ID method_id, 1.189 + bool is_virtual = false, bool is_static = false); 1.190 + CallJavaNode* generate_method_call_static(vmIntrinsics::ID method_id) { 1.191 + return generate_method_call(method_id, false, true); 1.192 + } 1.193 + CallJavaNode* generate_method_call_virtual(vmIntrinsics::ID method_id) { 1.194 + return generate_method_call(method_id, true, false); 1.195 + } 1.196 + Node * load_field_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, bool is_exact, bool is_static); 1.197 + 1.198 + Node* make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2); 1.199 + Node* make_string_method_node(int opcode, Node* str1, Node* str2); 1.200 + bool inline_string_compareTo(); 1.201 + bool inline_string_indexOf(); 1.202 + Node* string_indexOf(Node* string_object, ciTypeArray* target_array, jint offset, jint cache_i, jint md2_i); 1.203 + bool inline_string_equals(); 1.204 + Node* round_double_node(Node* n); 1.205 + bool runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName); 1.206 + bool inline_math_native(vmIntrinsics::ID id); 1.207 + bool inline_trig(vmIntrinsics::ID id); 1.208 + bool inline_math(vmIntrinsics::ID id); 1.209 + template <typename OverflowOp> 1.210 + bool inline_math_overflow(Node* arg1, Node* arg2); 1.211 + void inline_math_mathExact(Node* math, Node* test); 1.212 + bool inline_math_addExactI(bool is_increment); 1.213 + bool inline_math_addExactL(bool is_increment); 1.214 + bool inline_math_multiplyExactI(); 1.215 + bool inline_math_multiplyExactL(); 1.216 + bool inline_math_negateExactI(); 1.217 + bool inline_math_negateExactL(); 1.218 + bool inline_math_subtractExactI(bool is_decrement); 1.219 + bool inline_math_subtractExactL(bool is_decrement); 1.220 + bool inline_exp(); 1.221 + bool inline_pow(); 1.222 + Node* finish_pow_exp(Node* result, Node* x, Node* y, const TypeFunc* call_type, address funcAddr, const char* funcName); 1.223 + bool inline_min_max(vmIntrinsics::ID id); 1.224 + Node* generate_min_max(vmIntrinsics::ID id, Node* x, Node* y); 1.225 + // This returns Type::AnyPtr, RawPtr, or OopPtr. 1.226 + int classify_unsafe_addr(Node* &base, Node* &offset); 1.227 + Node* make_unsafe_address(Node* base, Node* offset); 1.228 + // Helper for inline_unsafe_access. 1.229 + // Generates the guards that check whether the result of 1.230 + // Unsafe.getObject should be recorded in an SATB log buffer. 1.231 + void insert_pre_barrier(Node* base_oop, Node* offset, Node* pre_val, bool need_mem_bar); 1.232 + bool inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile); 1.233 + bool inline_unsafe_prefetch(bool is_native_ptr, bool is_store, bool is_static); 1.234 + static bool klass_needs_init_guard(Node* kls); 1.235 + bool inline_unsafe_allocate(); 1.236 + bool inline_unsafe_copyMemory(); 1.237 + bool inline_native_currentThread(); 1.238 +#ifdef TRACE_HAVE_INTRINSICS 1.239 + bool inline_native_classID(); 1.240 + bool inline_native_threadID(); 1.241 +#endif 1.242 + bool inline_native_time_funcs(address method, const char* funcName); 1.243 + bool inline_native_isInterrupted(); 1.244 + bool inline_native_Class_query(vmIntrinsics::ID id); 1.245 + bool inline_native_subtype_check(); 1.246 + 1.247 + bool inline_native_newArray(); 1.248 + bool inline_native_getLength(); 1.249 + bool inline_array_copyOf(bool is_copyOfRange); 1.250 + bool inline_array_equals(); 1.251 + void copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array, bool card_mark); 1.252 + bool inline_native_clone(bool is_virtual); 1.253 + bool inline_native_Reflection_getCallerClass(); 1.254 + // Helper function for inlining native object hash method 1.255 + bool inline_native_hashcode(bool is_virtual, bool is_static); 1.256 + bool inline_native_getClass(); 1.257 + 1.258 + // Helper functions for inlining arraycopy 1.259 + bool inline_arraycopy(); 1.260 + void generate_arraycopy(const TypePtr* adr_type, 1.261 + BasicType basic_elem_type, 1.262 + Node* src, Node* src_offset, 1.263 + Node* dest, Node* dest_offset, 1.264 + Node* copy_length, 1.265 + bool disjoint_bases = false, 1.266 + bool length_never_negative = false, 1.267 + RegionNode* slow_region = NULL); 1.268 + AllocateArrayNode* tightly_coupled_allocation(Node* ptr, 1.269 + RegionNode* slow_region); 1.270 + void generate_clear_array(const TypePtr* adr_type, 1.271 + Node* dest, 1.272 + BasicType basic_elem_type, 1.273 + Node* slice_off, 1.274 + Node* slice_len, 1.275 + Node* slice_end); 1.276 + bool generate_block_arraycopy(const TypePtr* adr_type, 1.277 + BasicType basic_elem_type, 1.278 + AllocateNode* alloc, 1.279 + Node* src, Node* src_offset, 1.280 + Node* dest, Node* dest_offset, 1.281 + Node* dest_size, bool dest_uninitialized); 1.282 + void generate_slow_arraycopy(const TypePtr* adr_type, 1.283 + Node* src, Node* src_offset, 1.284 + Node* dest, Node* dest_offset, 1.285 + Node* copy_length, bool dest_uninitialized); 1.286 + Node* generate_checkcast_arraycopy(const TypePtr* adr_type, 1.287 + Node* dest_elem_klass, 1.288 + Node* src, Node* src_offset, 1.289 + Node* dest, Node* dest_offset, 1.290 + Node* copy_length, bool dest_uninitialized); 1.291 + Node* generate_generic_arraycopy(const TypePtr* adr_type, 1.292 + Node* src, Node* src_offset, 1.293 + Node* dest, Node* dest_offset, 1.294 + Node* copy_length, bool dest_uninitialized); 1.295 + void generate_unchecked_arraycopy(const TypePtr* adr_type, 1.296 + BasicType basic_elem_type, 1.297 + bool disjoint_bases, 1.298 + Node* src, Node* src_offset, 1.299 + Node* dest, Node* dest_offset, 1.300 + Node* copy_length, bool dest_uninitialized); 1.301 + typedef enum { LS_xadd, LS_xchg, LS_cmpxchg } LoadStoreKind; 1.302 + bool inline_unsafe_load_store(BasicType type, LoadStoreKind kind); 1.303 + bool inline_unsafe_ordered_store(BasicType type); 1.304 + bool inline_unsafe_fence(vmIntrinsics::ID id); 1.305 + bool inline_fp_conversions(vmIntrinsics::ID id); 1.306 + bool inline_number_methods(vmIntrinsics::ID id); 1.307 + bool inline_reference_get(); 1.308 + bool inline_aescrypt_Block(vmIntrinsics::ID id); 1.309 + bool inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id); 1.310 + Node* inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting); 1.311 + Node* get_key_start_from_aescrypt_object(Node* aescrypt_object); 1.312 + Node* get_original_key_start_from_aescrypt_object(Node* aescrypt_object); 1.313 + bool inline_encodeISOArray(); 1.314 + bool inline_updateCRC32(); 1.315 + bool inline_updateBytesCRC32(); 1.316 + bool inline_updateByteBufferCRC32(); 1.317 +}; 1.318 + 1.319 + 1.320 +//---------------------------make_vm_intrinsic---------------------------- 1.321 +CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) { 1.322 + vmIntrinsics::ID id = m->intrinsic_id(); 1.323 + assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 1.324 + 1.325 + if (DisableIntrinsic[0] != '\0' 1.326 + && strstr(DisableIntrinsic, vmIntrinsics::name_at(id)) != NULL) { 1.327 + // disabled by a user request on the command line: 1.328 + // example: -XX:DisableIntrinsic=_hashCode,_getClass 1.329 + return NULL; 1.330 + } 1.331 + 1.332 + if (!m->is_loaded()) { 1.333 + // do not attempt to inline unloaded methods 1.334 + return NULL; 1.335 + } 1.336 + 1.337 + // Only a few intrinsics implement a virtual dispatch. 1.338 + // They are expensive calls which are also frequently overridden. 1.339 + if (is_virtual) { 1.340 + switch (id) { 1.341 + case vmIntrinsics::_hashCode: 1.342 + case vmIntrinsics::_clone: 1.343 + // OK, Object.hashCode and Object.clone intrinsics come in both flavors 1.344 + break; 1.345 + default: 1.346 + return NULL; 1.347 + } 1.348 + } 1.349 + 1.350 + // -XX:-InlineNatives disables nearly all intrinsics: 1.351 + if (!InlineNatives) { 1.352 + switch (id) { 1.353 + case vmIntrinsics::_indexOf: 1.354 + case vmIntrinsics::_compareTo: 1.355 + case vmIntrinsics::_equals: 1.356 + case vmIntrinsics::_equalsC: 1.357 + case vmIntrinsics::_getAndAddInt: 1.358 + case vmIntrinsics::_getAndAddLong: 1.359 + case vmIntrinsics::_getAndSetInt: 1.360 + case vmIntrinsics::_getAndSetLong: 1.361 + case vmIntrinsics::_getAndSetObject: 1.362 + case vmIntrinsics::_loadFence: 1.363 + case vmIntrinsics::_storeFence: 1.364 + case vmIntrinsics::_fullFence: 1.365 + break; // InlineNatives does not control String.compareTo 1.366 + case vmIntrinsics::_Reference_get: 1.367 + break; // InlineNatives does not control Reference.get 1.368 + default: 1.369 + return NULL; 1.370 + } 1.371 + } 1.372 + 1.373 + bool is_predicted = false; 1.374 + bool does_virtual_dispatch = false; 1.375 + 1.376 + switch (id) { 1.377 + case vmIntrinsics::_compareTo: 1.378 + if (!SpecialStringCompareTo) return NULL; 1.379 + if (!Matcher::match_rule_supported(Op_StrComp)) return NULL; 1.380 + break; 1.381 + case vmIntrinsics::_indexOf: 1.382 + if (!SpecialStringIndexOf) return NULL; 1.383 + break; 1.384 + case vmIntrinsics::_equals: 1.385 + if (!SpecialStringEquals) return NULL; 1.386 + if (!Matcher::match_rule_supported(Op_StrEquals)) return NULL; 1.387 + break; 1.388 + case vmIntrinsics::_equalsC: 1.389 + if (!SpecialArraysEquals) return NULL; 1.390 + if (!Matcher::match_rule_supported(Op_AryEq)) return NULL; 1.391 + break; 1.392 + case vmIntrinsics::_arraycopy: 1.393 + if (!InlineArrayCopy) return NULL; 1.394 + break; 1.395 + case vmIntrinsics::_copyMemory: 1.396 + if (StubRoutines::unsafe_arraycopy() == NULL) return NULL; 1.397 + if (!InlineArrayCopy) return NULL; 1.398 + break; 1.399 + case vmIntrinsics::_hashCode: 1.400 + if (!InlineObjectHash) return NULL; 1.401 + does_virtual_dispatch = true; 1.402 + break; 1.403 + case vmIntrinsics::_clone: 1.404 + does_virtual_dispatch = true; 1.405 + case vmIntrinsics::_copyOf: 1.406 + case vmIntrinsics::_copyOfRange: 1.407 + if (!InlineObjectCopy) return NULL; 1.408 + // These also use the arraycopy intrinsic mechanism: 1.409 + if (!InlineArrayCopy) return NULL; 1.410 + break; 1.411 + case vmIntrinsics::_encodeISOArray: 1.412 + if (!SpecialEncodeISOArray) return NULL; 1.413 + if (!Matcher::match_rule_supported(Op_EncodeISOArray)) return NULL; 1.414 + break; 1.415 + case vmIntrinsics::_checkIndex: 1.416 + // We do not intrinsify this. The optimizer does fine with it. 1.417 + return NULL; 1.418 + 1.419 + case vmIntrinsics::_getCallerClass: 1.420 + if (!UseNewReflection) return NULL; 1.421 + if (!InlineReflectionGetCallerClass) return NULL; 1.422 + if (SystemDictionary::reflect_CallerSensitive_klass() == NULL) return NULL; 1.423 + break; 1.424 + 1.425 + case vmIntrinsics::_bitCount_i: 1.426 + if (!Matcher::match_rule_supported(Op_PopCountI)) return NULL; 1.427 + break; 1.428 + 1.429 + case vmIntrinsics::_bitCount_l: 1.430 + if (!Matcher::match_rule_supported(Op_PopCountL)) return NULL; 1.431 + break; 1.432 + 1.433 + case vmIntrinsics::_numberOfLeadingZeros_i: 1.434 + if (!Matcher::match_rule_supported(Op_CountLeadingZerosI)) return NULL; 1.435 + break; 1.436 + 1.437 + case vmIntrinsics::_numberOfLeadingZeros_l: 1.438 + if (!Matcher::match_rule_supported(Op_CountLeadingZerosL)) return NULL; 1.439 + break; 1.440 + 1.441 + case vmIntrinsics::_numberOfTrailingZeros_i: 1.442 + if (!Matcher::match_rule_supported(Op_CountTrailingZerosI)) return NULL; 1.443 + break; 1.444 + 1.445 + case vmIntrinsics::_numberOfTrailingZeros_l: 1.446 + if (!Matcher::match_rule_supported(Op_CountTrailingZerosL)) return NULL; 1.447 + break; 1.448 + 1.449 + case vmIntrinsics::_reverseBytes_c: 1.450 + if (!Matcher::match_rule_supported(Op_ReverseBytesUS)) return NULL; 1.451 + break; 1.452 + case vmIntrinsics::_reverseBytes_s: 1.453 + if (!Matcher::match_rule_supported(Op_ReverseBytesS)) return NULL; 1.454 + break; 1.455 + case vmIntrinsics::_reverseBytes_i: 1.456 + if (!Matcher::match_rule_supported(Op_ReverseBytesI)) return NULL; 1.457 + break; 1.458 + case vmIntrinsics::_reverseBytes_l: 1.459 + if (!Matcher::match_rule_supported(Op_ReverseBytesL)) return NULL; 1.460 + break; 1.461 + 1.462 + case vmIntrinsics::_Reference_get: 1.463 + // Use the intrinsic version of Reference.get() so that the value in 1.464 + // the referent field can be registered by the G1 pre-barrier code. 1.465 + // Also add memory barrier to prevent commoning reads from this field 1.466 + // across safepoint since GC can change it value. 1.467 + break; 1.468 + 1.469 + case vmIntrinsics::_compareAndSwapObject: 1.470 +#ifdef _LP64 1.471 + if (!UseCompressedOops && !Matcher::match_rule_supported(Op_CompareAndSwapP)) return NULL; 1.472 +#endif 1.473 + break; 1.474 + 1.475 + case vmIntrinsics::_compareAndSwapLong: 1.476 + if (!Matcher::match_rule_supported(Op_CompareAndSwapL)) return NULL; 1.477 + break; 1.478 + 1.479 + case vmIntrinsics::_getAndAddInt: 1.480 + if (!Matcher::match_rule_supported(Op_GetAndAddI)) return NULL; 1.481 + break; 1.482 + 1.483 + case vmIntrinsics::_getAndAddLong: 1.484 + if (!Matcher::match_rule_supported(Op_GetAndAddL)) return NULL; 1.485 + break; 1.486 + 1.487 + case vmIntrinsics::_getAndSetInt: 1.488 + if (!Matcher::match_rule_supported(Op_GetAndSetI)) return NULL; 1.489 + break; 1.490 + 1.491 + case vmIntrinsics::_getAndSetLong: 1.492 + if (!Matcher::match_rule_supported(Op_GetAndSetL)) return NULL; 1.493 + break; 1.494 + 1.495 + case vmIntrinsics::_getAndSetObject: 1.496 +#ifdef _LP64 1.497 + if (!UseCompressedOops && !Matcher::match_rule_supported(Op_GetAndSetP)) return NULL; 1.498 + if (UseCompressedOops && !Matcher::match_rule_supported(Op_GetAndSetN)) return NULL; 1.499 + break; 1.500 +#else 1.501 + if (!Matcher::match_rule_supported(Op_GetAndSetP)) return NULL; 1.502 + break; 1.503 +#endif 1.504 + 1.505 + case vmIntrinsics::_aescrypt_encryptBlock: 1.506 + case vmIntrinsics::_aescrypt_decryptBlock: 1.507 + if (!UseAESIntrinsics) return NULL; 1.508 + break; 1.509 + 1.510 + case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 1.511 + case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 1.512 + if (!UseAESIntrinsics) return NULL; 1.513 + // these two require the predicated logic 1.514 + is_predicted = true; 1.515 + break; 1.516 + 1.517 + case vmIntrinsics::_updateCRC32: 1.518 + case vmIntrinsics::_updateBytesCRC32: 1.519 + case vmIntrinsics::_updateByteBufferCRC32: 1.520 + if (!UseCRC32Intrinsics) return NULL; 1.521 + break; 1.522 + 1.523 + case vmIntrinsics::_incrementExactI: 1.524 + case vmIntrinsics::_addExactI: 1.525 + if (!Matcher::match_rule_supported(Op_OverflowAddI) || !UseMathExactIntrinsics) return NULL; 1.526 + break; 1.527 + case vmIntrinsics::_incrementExactL: 1.528 + case vmIntrinsics::_addExactL: 1.529 + if (!Matcher::match_rule_supported(Op_OverflowAddL) || !UseMathExactIntrinsics) return NULL; 1.530 + break; 1.531 + case vmIntrinsics::_decrementExactI: 1.532 + case vmIntrinsics::_subtractExactI: 1.533 + if (!Matcher::match_rule_supported(Op_OverflowSubI) || !UseMathExactIntrinsics) return NULL; 1.534 + break; 1.535 + case vmIntrinsics::_decrementExactL: 1.536 + case vmIntrinsics::_subtractExactL: 1.537 + if (!Matcher::match_rule_supported(Op_OverflowSubL) || !UseMathExactIntrinsics) return NULL; 1.538 + break; 1.539 + case vmIntrinsics::_negateExactI: 1.540 + if (!Matcher::match_rule_supported(Op_OverflowSubI) || !UseMathExactIntrinsics) return NULL; 1.541 + break; 1.542 + case vmIntrinsics::_negateExactL: 1.543 + if (!Matcher::match_rule_supported(Op_OverflowSubL) || !UseMathExactIntrinsics) return NULL; 1.544 + break; 1.545 + case vmIntrinsics::_multiplyExactI: 1.546 + if (!Matcher::match_rule_supported(Op_OverflowMulI) || !UseMathExactIntrinsics) return NULL; 1.547 + break; 1.548 + case vmIntrinsics::_multiplyExactL: 1.549 + if (!Matcher::match_rule_supported(Op_OverflowMulL) || !UseMathExactIntrinsics) return NULL; 1.550 + break; 1.551 + 1.552 + default: 1.553 + assert(id <= vmIntrinsics::LAST_COMPILER_INLINE, "caller responsibility"); 1.554 + assert(id != vmIntrinsics::_Object_init && id != vmIntrinsics::_invoke, "enum out of order?"); 1.555 + break; 1.556 + } 1.557 + 1.558 + // -XX:-InlineClassNatives disables natives from the Class class. 1.559 + // The flag applies to all reflective calls, notably Array.newArray 1.560 + // (visible to Java programmers as Array.newInstance). 1.561 + if (m->holder()->name() == ciSymbol::java_lang_Class() || 1.562 + m->holder()->name() == ciSymbol::java_lang_reflect_Array()) { 1.563 + if (!InlineClassNatives) return NULL; 1.564 + } 1.565 + 1.566 + // -XX:-InlineThreadNatives disables natives from the Thread class. 1.567 + if (m->holder()->name() == ciSymbol::java_lang_Thread()) { 1.568 + if (!InlineThreadNatives) return NULL; 1.569 + } 1.570 + 1.571 + // -XX:-InlineMathNatives disables natives from the Math,Float and Double classes. 1.572 + if (m->holder()->name() == ciSymbol::java_lang_Math() || 1.573 + m->holder()->name() == ciSymbol::java_lang_Float() || 1.574 + m->holder()->name() == ciSymbol::java_lang_Double()) { 1.575 + if (!InlineMathNatives) return NULL; 1.576 + } 1.577 + 1.578 + // -XX:-InlineUnsafeOps disables natives from the Unsafe class. 1.579 + if (m->holder()->name() == ciSymbol::sun_misc_Unsafe()) { 1.580 + if (!InlineUnsafeOps) return NULL; 1.581 + } 1.582 + 1.583 + return new LibraryIntrinsic(m, is_virtual, is_predicted, does_virtual_dispatch, (vmIntrinsics::ID) id); 1.584 +} 1.585 + 1.586 +//----------------------register_library_intrinsics----------------------- 1.587 +// Initialize this file's data structures, for each Compile instance. 1.588 +void Compile::register_library_intrinsics() { 1.589 + // Nothing to do here. 1.590 +} 1.591 + 1.592 +JVMState* LibraryIntrinsic::generate(JVMState* jvms, Parse* parent_parser) { 1.593 + LibraryCallKit kit(jvms, this); 1.594 + Compile* C = kit.C; 1.595 + int nodes = C->unique(); 1.596 +#ifndef PRODUCT 1.597 + if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 1.598 + char buf[1000]; 1.599 + const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf)); 1.600 + tty->print_cr("Intrinsic %s", str); 1.601 + } 1.602 +#endif 1.603 + ciMethod* callee = kit.callee(); 1.604 + const int bci = kit.bci(); 1.605 + 1.606 + // Try to inline the intrinsic. 1.607 + if (kit.try_to_inline()) { 1.608 + if (C->print_intrinsics() || C->print_inlining()) { 1.609 + C->print_inlining(callee, jvms->depth() - 1, bci, is_virtual() ? "(intrinsic, virtual)" : "(intrinsic)"); 1.610 + } 1.611 + C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked); 1.612 + if (C->log()) { 1.613 + C->log()->elem("intrinsic id='%s'%s nodes='%d'", 1.614 + vmIntrinsics::name_at(intrinsic_id()), 1.615 + (is_virtual() ? " virtual='1'" : ""), 1.616 + C->unique() - nodes); 1.617 + } 1.618 + // Push the result from the inlined method onto the stack. 1.619 + kit.push_result(); 1.620 + return kit.transfer_exceptions_into_jvms(); 1.621 + } 1.622 + 1.623 + // The intrinsic bailed out 1.624 + if (C->print_intrinsics() || C->print_inlining()) { 1.625 + if (jvms->has_method()) { 1.626 + // Not a root compile. 1.627 + const char* msg = is_virtual() ? "failed to inline (intrinsic, virtual)" : "failed to inline (intrinsic)"; 1.628 + C->print_inlining(callee, jvms->depth() - 1, bci, msg); 1.629 + } else { 1.630 + // Root compile 1.631 + tty->print("Did not generate intrinsic %s%s at bci:%d in", 1.632 + vmIntrinsics::name_at(intrinsic_id()), 1.633 + (is_virtual() ? " (virtual)" : ""), bci); 1.634 + } 1.635 + } 1.636 + C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed); 1.637 + return NULL; 1.638 +} 1.639 + 1.640 +Node* LibraryIntrinsic::generate_predicate(JVMState* jvms) { 1.641 + LibraryCallKit kit(jvms, this); 1.642 + Compile* C = kit.C; 1.643 + int nodes = C->unique(); 1.644 +#ifndef PRODUCT 1.645 + assert(is_predicted(), "sanity"); 1.646 + if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 1.647 + char buf[1000]; 1.648 + const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf)); 1.649 + tty->print_cr("Predicate for intrinsic %s", str); 1.650 + } 1.651 +#endif 1.652 + ciMethod* callee = kit.callee(); 1.653 + const int bci = kit.bci(); 1.654 + 1.655 + Node* slow_ctl = kit.try_to_predicate(); 1.656 + if (!kit.failing()) { 1.657 + if (C->print_intrinsics() || C->print_inlining()) { 1.658 + C->print_inlining(callee, jvms->depth() - 1, bci, is_virtual() ? "(intrinsic, virtual)" : "(intrinsic)"); 1.659 + } 1.660 + C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked); 1.661 + if (C->log()) { 1.662 + C->log()->elem("predicate_intrinsic id='%s'%s nodes='%d'", 1.663 + vmIntrinsics::name_at(intrinsic_id()), 1.664 + (is_virtual() ? " virtual='1'" : ""), 1.665 + C->unique() - nodes); 1.666 + } 1.667 + return slow_ctl; // Could be NULL if the check folds. 1.668 + } 1.669 + 1.670 + // The intrinsic bailed out 1.671 + if (C->print_intrinsics() || C->print_inlining()) { 1.672 + if (jvms->has_method()) { 1.673 + // Not a root compile. 1.674 + const char* msg = "failed to generate predicate for intrinsic"; 1.675 + C->print_inlining(kit.callee(), jvms->depth() - 1, bci, msg); 1.676 + } else { 1.677 + // Root compile 1.678 + C->print_inlining_stream()->print("Did not generate predicate for intrinsic %s%s at bci:%d in", 1.679 + vmIntrinsics::name_at(intrinsic_id()), 1.680 + (is_virtual() ? " (virtual)" : ""), bci); 1.681 + } 1.682 + } 1.683 + C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed); 1.684 + return NULL; 1.685 +} 1.686 + 1.687 +bool LibraryCallKit::try_to_inline() { 1.688 + // Handle symbolic names for otherwise undistinguished boolean switches: 1.689 + const bool is_store = true; 1.690 + const bool is_native_ptr = true; 1.691 + const bool is_static = true; 1.692 + const bool is_volatile = true; 1.693 + 1.694 + if (!jvms()->has_method()) { 1.695 + // Root JVMState has a null method. 1.696 + assert(map()->memory()->Opcode() == Op_Parm, ""); 1.697 + // Insert the memory aliasing node 1.698 + set_all_memory(reset_memory()); 1.699 + } 1.700 + assert(merged_memory(), ""); 1.701 + 1.702 + 1.703 + switch (intrinsic_id()) { 1.704 + case vmIntrinsics::_hashCode: return inline_native_hashcode(intrinsic()->is_virtual(), !is_static); 1.705 + case vmIntrinsics::_identityHashCode: return inline_native_hashcode(/*!virtual*/ false, is_static); 1.706 + case vmIntrinsics::_getClass: return inline_native_getClass(); 1.707 + 1.708 + case vmIntrinsics::_dsin: 1.709 + case vmIntrinsics::_dcos: 1.710 + case vmIntrinsics::_dtan: 1.711 + case vmIntrinsics::_dabs: 1.712 + case vmIntrinsics::_datan2: 1.713 + case vmIntrinsics::_dsqrt: 1.714 + case vmIntrinsics::_dexp: 1.715 + case vmIntrinsics::_dlog: 1.716 + case vmIntrinsics::_dlog10: 1.717 + case vmIntrinsics::_dpow: return inline_math_native(intrinsic_id()); 1.718 + 1.719 + case vmIntrinsics::_min: 1.720 + case vmIntrinsics::_max: return inline_min_max(intrinsic_id()); 1.721 + 1.722 + case vmIntrinsics::_addExactI: return inline_math_addExactI(false /* add */); 1.723 + case vmIntrinsics::_addExactL: return inline_math_addExactL(false /* add */); 1.724 + case vmIntrinsics::_decrementExactI: return inline_math_subtractExactI(true /* decrement */); 1.725 + case vmIntrinsics::_decrementExactL: return inline_math_subtractExactL(true /* decrement */); 1.726 + case vmIntrinsics::_incrementExactI: return inline_math_addExactI(true /* increment */); 1.727 + case vmIntrinsics::_incrementExactL: return inline_math_addExactL(true /* increment */); 1.728 + case vmIntrinsics::_multiplyExactI: return inline_math_multiplyExactI(); 1.729 + case vmIntrinsics::_multiplyExactL: return inline_math_multiplyExactL(); 1.730 + case vmIntrinsics::_negateExactI: return inline_math_negateExactI(); 1.731 + case vmIntrinsics::_negateExactL: return inline_math_negateExactL(); 1.732 + case vmIntrinsics::_subtractExactI: return inline_math_subtractExactI(false /* subtract */); 1.733 + case vmIntrinsics::_subtractExactL: return inline_math_subtractExactL(false /* subtract */); 1.734 + 1.735 + case vmIntrinsics::_arraycopy: return inline_arraycopy(); 1.736 + 1.737 + case vmIntrinsics::_compareTo: return inline_string_compareTo(); 1.738 + case vmIntrinsics::_indexOf: return inline_string_indexOf(); 1.739 + case vmIntrinsics::_equals: return inline_string_equals(); 1.740 + 1.741 + case vmIntrinsics::_getObject: return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT, !is_volatile); 1.742 + case vmIntrinsics::_getBoolean: return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN, !is_volatile); 1.743 + case vmIntrinsics::_getByte: return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE, !is_volatile); 1.744 + case vmIntrinsics::_getShort: return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT, !is_volatile); 1.745 + case vmIntrinsics::_getChar: return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR, !is_volatile); 1.746 + case vmIntrinsics::_getInt: return inline_unsafe_access(!is_native_ptr, !is_store, T_INT, !is_volatile); 1.747 + case vmIntrinsics::_getLong: return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG, !is_volatile); 1.748 + case vmIntrinsics::_getFloat: return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT, !is_volatile); 1.749 + case vmIntrinsics::_getDouble: return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE, !is_volatile); 1.750 + 1.751 + case vmIntrinsics::_putObject: return inline_unsafe_access(!is_native_ptr, is_store, T_OBJECT, !is_volatile); 1.752 + case vmIntrinsics::_putBoolean: return inline_unsafe_access(!is_native_ptr, is_store, T_BOOLEAN, !is_volatile); 1.753 + case vmIntrinsics::_putByte: return inline_unsafe_access(!is_native_ptr, is_store, T_BYTE, !is_volatile); 1.754 + case vmIntrinsics::_putShort: return inline_unsafe_access(!is_native_ptr, is_store, T_SHORT, !is_volatile); 1.755 + case vmIntrinsics::_putChar: return inline_unsafe_access(!is_native_ptr, is_store, T_CHAR, !is_volatile); 1.756 + case vmIntrinsics::_putInt: return inline_unsafe_access(!is_native_ptr, is_store, T_INT, !is_volatile); 1.757 + case vmIntrinsics::_putLong: return inline_unsafe_access(!is_native_ptr, is_store, T_LONG, !is_volatile); 1.758 + case vmIntrinsics::_putFloat: return inline_unsafe_access(!is_native_ptr, is_store, T_FLOAT, !is_volatile); 1.759 + case vmIntrinsics::_putDouble: return inline_unsafe_access(!is_native_ptr, is_store, T_DOUBLE, !is_volatile); 1.760 + 1.761 + case vmIntrinsics::_getByte_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_BYTE, !is_volatile); 1.762 + case vmIntrinsics::_getShort_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_SHORT, !is_volatile); 1.763 + case vmIntrinsics::_getChar_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_CHAR, !is_volatile); 1.764 + case vmIntrinsics::_getInt_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_INT, !is_volatile); 1.765 + case vmIntrinsics::_getLong_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_LONG, !is_volatile); 1.766 + case vmIntrinsics::_getFloat_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_FLOAT, !is_volatile); 1.767 + case vmIntrinsics::_getDouble_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_DOUBLE, !is_volatile); 1.768 + case vmIntrinsics::_getAddress_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_ADDRESS, !is_volatile); 1.769 + 1.770 + case vmIntrinsics::_putByte_raw: return inline_unsafe_access( is_native_ptr, is_store, T_BYTE, !is_volatile); 1.771 + case vmIntrinsics::_putShort_raw: return inline_unsafe_access( is_native_ptr, is_store, T_SHORT, !is_volatile); 1.772 + case vmIntrinsics::_putChar_raw: return inline_unsafe_access( is_native_ptr, is_store, T_CHAR, !is_volatile); 1.773 + case vmIntrinsics::_putInt_raw: return inline_unsafe_access( is_native_ptr, is_store, T_INT, !is_volatile); 1.774 + case vmIntrinsics::_putLong_raw: return inline_unsafe_access( is_native_ptr, is_store, T_LONG, !is_volatile); 1.775 + case vmIntrinsics::_putFloat_raw: return inline_unsafe_access( is_native_ptr, is_store, T_FLOAT, !is_volatile); 1.776 + case vmIntrinsics::_putDouble_raw: return inline_unsafe_access( is_native_ptr, is_store, T_DOUBLE, !is_volatile); 1.777 + case vmIntrinsics::_putAddress_raw: return inline_unsafe_access( is_native_ptr, is_store, T_ADDRESS, !is_volatile); 1.778 + 1.779 + case vmIntrinsics::_getObjectVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT, is_volatile); 1.780 + case vmIntrinsics::_getBooleanVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN, is_volatile); 1.781 + case vmIntrinsics::_getByteVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE, is_volatile); 1.782 + case vmIntrinsics::_getShortVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT, is_volatile); 1.783 + case vmIntrinsics::_getCharVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR, is_volatile); 1.784 + case vmIntrinsics::_getIntVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_INT, is_volatile); 1.785 + case vmIntrinsics::_getLongVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG, is_volatile); 1.786 + case vmIntrinsics::_getFloatVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT, is_volatile); 1.787 + case vmIntrinsics::_getDoubleVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE, is_volatile); 1.788 + 1.789 + case vmIntrinsics::_putObjectVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_OBJECT, is_volatile); 1.790 + case vmIntrinsics::_putBooleanVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_BOOLEAN, is_volatile); 1.791 + case vmIntrinsics::_putByteVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_BYTE, is_volatile); 1.792 + case vmIntrinsics::_putShortVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_SHORT, is_volatile); 1.793 + case vmIntrinsics::_putCharVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_CHAR, is_volatile); 1.794 + case vmIntrinsics::_putIntVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_INT, is_volatile); 1.795 + case vmIntrinsics::_putLongVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_LONG, is_volatile); 1.796 + case vmIntrinsics::_putFloatVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_FLOAT, is_volatile); 1.797 + case vmIntrinsics::_putDoubleVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_DOUBLE, is_volatile); 1.798 + 1.799 + case vmIntrinsics::_prefetchRead: return inline_unsafe_prefetch(!is_native_ptr, !is_store, !is_static); 1.800 + case vmIntrinsics::_prefetchWrite: return inline_unsafe_prefetch(!is_native_ptr, is_store, !is_static); 1.801 + case vmIntrinsics::_prefetchReadStatic: return inline_unsafe_prefetch(!is_native_ptr, !is_store, is_static); 1.802 + case vmIntrinsics::_prefetchWriteStatic: return inline_unsafe_prefetch(!is_native_ptr, is_store, is_static); 1.803 + 1.804 + case vmIntrinsics::_compareAndSwapObject: return inline_unsafe_load_store(T_OBJECT, LS_cmpxchg); 1.805 + case vmIntrinsics::_compareAndSwapInt: return inline_unsafe_load_store(T_INT, LS_cmpxchg); 1.806 + case vmIntrinsics::_compareAndSwapLong: return inline_unsafe_load_store(T_LONG, LS_cmpxchg); 1.807 + 1.808 + case vmIntrinsics::_putOrderedObject: return inline_unsafe_ordered_store(T_OBJECT); 1.809 + case vmIntrinsics::_putOrderedInt: return inline_unsafe_ordered_store(T_INT); 1.810 + case vmIntrinsics::_putOrderedLong: return inline_unsafe_ordered_store(T_LONG); 1.811 + 1.812 + case vmIntrinsics::_getAndAddInt: return inline_unsafe_load_store(T_INT, LS_xadd); 1.813 + case vmIntrinsics::_getAndAddLong: return inline_unsafe_load_store(T_LONG, LS_xadd); 1.814 + case vmIntrinsics::_getAndSetInt: return inline_unsafe_load_store(T_INT, LS_xchg); 1.815 + case vmIntrinsics::_getAndSetLong: return inline_unsafe_load_store(T_LONG, LS_xchg); 1.816 + case vmIntrinsics::_getAndSetObject: return inline_unsafe_load_store(T_OBJECT, LS_xchg); 1.817 + 1.818 + case vmIntrinsics::_loadFence: 1.819 + case vmIntrinsics::_storeFence: 1.820 + case vmIntrinsics::_fullFence: return inline_unsafe_fence(intrinsic_id()); 1.821 + 1.822 + case vmIntrinsics::_currentThread: return inline_native_currentThread(); 1.823 + case vmIntrinsics::_isInterrupted: return inline_native_isInterrupted(); 1.824 + 1.825 +#ifdef TRACE_HAVE_INTRINSICS 1.826 + case vmIntrinsics::_classID: return inline_native_classID(); 1.827 + case vmIntrinsics::_threadID: return inline_native_threadID(); 1.828 + case vmIntrinsics::_counterTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, TRACE_TIME_METHOD), "counterTime"); 1.829 +#endif 1.830 + case vmIntrinsics::_currentTimeMillis: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeMillis), "currentTimeMillis"); 1.831 + case vmIntrinsics::_nanoTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeNanos), "nanoTime"); 1.832 + case vmIntrinsics::_allocateInstance: return inline_unsafe_allocate(); 1.833 + case vmIntrinsics::_copyMemory: return inline_unsafe_copyMemory(); 1.834 + case vmIntrinsics::_newArray: return inline_native_newArray(); 1.835 + case vmIntrinsics::_getLength: return inline_native_getLength(); 1.836 + case vmIntrinsics::_copyOf: return inline_array_copyOf(false); 1.837 + case vmIntrinsics::_copyOfRange: return inline_array_copyOf(true); 1.838 + case vmIntrinsics::_equalsC: return inline_array_equals(); 1.839 + case vmIntrinsics::_clone: return inline_native_clone(intrinsic()->is_virtual()); 1.840 + 1.841 + case vmIntrinsics::_isAssignableFrom: return inline_native_subtype_check(); 1.842 + 1.843 + case vmIntrinsics::_isInstance: 1.844 + case vmIntrinsics::_getModifiers: 1.845 + case vmIntrinsics::_isInterface: 1.846 + case vmIntrinsics::_isArray: 1.847 + case vmIntrinsics::_isPrimitive: 1.848 + case vmIntrinsics::_getSuperclass: 1.849 + case vmIntrinsics::_getComponentType: 1.850 + case vmIntrinsics::_getClassAccessFlags: return inline_native_Class_query(intrinsic_id()); 1.851 + 1.852 + case vmIntrinsics::_floatToRawIntBits: 1.853 + case vmIntrinsics::_floatToIntBits: 1.854 + case vmIntrinsics::_intBitsToFloat: 1.855 + case vmIntrinsics::_doubleToRawLongBits: 1.856 + case vmIntrinsics::_doubleToLongBits: 1.857 + case vmIntrinsics::_longBitsToDouble: return inline_fp_conversions(intrinsic_id()); 1.858 + 1.859 + case vmIntrinsics::_numberOfLeadingZeros_i: 1.860 + case vmIntrinsics::_numberOfLeadingZeros_l: 1.861 + case vmIntrinsics::_numberOfTrailingZeros_i: 1.862 + case vmIntrinsics::_numberOfTrailingZeros_l: 1.863 + case vmIntrinsics::_bitCount_i: 1.864 + case vmIntrinsics::_bitCount_l: 1.865 + case vmIntrinsics::_reverseBytes_i: 1.866 + case vmIntrinsics::_reverseBytes_l: 1.867 + case vmIntrinsics::_reverseBytes_s: 1.868 + case vmIntrinsics::_reverseBytes_c: return inline_number_methods(intrinsic_id()); 1.869 + 1.870 + case vmIntrinsics::_getCallerClass: return inline_native_Reflection_getCallerClass(); 1.871 + 1.872 + case vmIntrinsics::_Reference_get: return inline_reference_get(); 1.873 + 1.874 + case vmIntrinsics::_aescrypt_encryptBlock: 1.875 + case vmIntrinsics::_aescrypt_decryptBlock: return inline_aescrypt_Block(intrinsic_id()); 1.876 + 1.877 + case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 1.878 + case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 1.879 + return inline_cipherBlockChaining_AESCrypt(intrinsic_id()); 1.880 + 1.881 + case vmIntrinsics::_encodeISOArray: 1.882 + return inline_encodeISOArray(); 1.883 + 1.884 + case vmIntrinsics::_updateCRC32: 1.885 + return inline_updateCRC32(); 1.886 + case vmIntrinsics::_updateBytesCRC32: 1.887 + return inline_updateBytesCRC32(); 1.888 + case vmIntrinsics::_updateByteBufferCRC32: 1.889 + return inline_updateByteBufferCRC32(); 1.890 + 1.891 + default: 1.892 + // If you get here, it may be that someone has added a new intrinsic 1.893 + // to the list in vmSymbols.hpp without implementing it here. 1.894 +#ifndef PRODUCT 1.895 + if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) { 1.896 + tty->print_cr("*** Warning: Unimplemented intrinsic %s(%d)", 1.897 + vmIntrinsics::name_at(intrinsic_id()), intrinsic_id()); 1.898 + } 1.899 +#endif 1.900 + return false; 1.901 + } 1.902 +} 1.903 + 1.904 +Node* LibraryCallKit::try_to_predicate() { 1.905 + if (!jvms()->has_method()) { 1.906 + // Root JVMState has a null method. 1.907 + assert(map()->memory()->Opcode() == Op_Parm, ""); 1.908 + // Insert the memory aliasing node 1.909 + set_all_memory(reset_memory()); 1.910 + } 1.911 + assert(merged_memory(), ""); 1.912 + 1.913 + switch (intrinsic_id()) { 1.914 + case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 1.915 + return inline_cipherBlockChaining_AESCrypt_predicate(false); 1.916 + case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 1.917 + return inline_cipherBlockChaining_AESCrypt_predicate(true); 1.918 + 1.919 + default: 1.920 + // If you get here, it may be that someone has added a new intrinsic 1.921 + // to the list in vmSymbols.hpp without implementing it here. 1.922 +#ifndef PRODUCT 1.923 + if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) { 1.924 + tty->print_cr("*** Warning: Unimplemented predicate for intrinsic %s(%d)", 1.925 + vmIntrinsics::name_at(intrinsic_id()), intrinsic_id()); 1.926 + } 1.927 +#endif 1.928 + Node* slow_ctl = control(); 1.929 + set_control(top()); // No fast path instrinsic 1.930 + return slow_ctl; 1.931 + } 1.932 +} 1.933 + 1.934 +//------------------------------set_result------------------------------- 1.935 +// Helper function for finishing intrinsics. 1.936 +void LibraryCallKit::set_result(RegionNode* region, PhiNode* value) { 1.937 + record_for_igvn(region); 1.938 + set_control(_gvn.transform(region)); 1.939 + set_result( _gvn.transform(value)); 1.940 + assert(value->type()->basic_type() == result()->bottom_type()->basic_type(), "sanity"); 1.941 +} 1.942 + 1.943 +//------------------------------generate_guard--------------------------- 1.944 +// Helper function for generating guarded fast-slow graph structures. 1.945 +// The given 'test', if true, guards a slow path. If the test fails 1.946 +// then a fast path can be taken. (We generally hope it fails.) 1.947 +// In all cases, GraphKit::control() is updated to the fast path. 1.948 +// The returned value represents the control for the slow path. 1.949 +// The return value is never 'top'; it is either a valid control 1.950 +// or NULL if it is obvious that the slow path can never be taken. 1.951 +// Also, if region and the slow control are not NULL, the slow edge 1.952 +// is appended to the region. 1.953 +Node* LibraryCallKit::generate_guard(Node* test, RegionNode* region, float true_prob) { 1.954 + if (stopped()) { 1.955 + // Already short circuited. 1.956 + return NULL; 1.957 + } 1.958 + 1.959 + // Build an if node and its projections. 1.960 + // If test is true we take the slow path, which we assume is uncommon. 1.961 + if (_gvn.type(test) == TypeInt::ZERO) { 1.962 + // The slow branch is never taken. No need to build this guard. 1.963 + return NULL; 1.964 + } 1.965 + 1.966 + IfNode* iff = create_and_map_if(control(), test, true_prob, COUNT_UNKNOWN); 1.967 + 1.968 + Node* if_slow = _gvn.transform(new (C) IfTrueNode(iff)); 1.969 + if (if_slow == top()) { 1.970 + // The slow branch is never taken. No need to build this guard. 1.971 + return NULL; 1.972 + } 1.973 + 1.974 + if (region != NULL) 1.975 + region->add_req(if_slow); 1.976 + 1.977 + Node* if_fast = _gvn.transform(new (C) IfFalseNode(iff)); 1.978 + set_control(if_fast); 1.979 + 1.980 + return if_slow; 1.981 +} 1.982 + 1.983 +inline Node* LibraryCallKit::generate_slow_guard(Node* test, RegionNode* region) { 1.984 + return generate_guard(test, region, PROB_UNLIKELY_MAG(3)); 1.985 +} 1.986 +inline Node* LibraryCallKit::generate_fair_guard(Node* test, RegionNode* region) { 1.987 + return generate_guard(test, region, PROB_FAIR); 1.988 +} 1.989 + 1.990 +inline Node* LibraryCallKit::generate_negative_guard(Node* index, RegionNode* region, 1.991 + Node* *pos_index) { 1.992 + if (stopped()) 1.993 + return NULL; // already stopped 1.994 + if (_gvn.type(index)->higher_equal(TypeInt::POS)) // [0,maxint] 1.995 + return NULL; // index is already adequately typed 1.996 + Node* cmp_lt = _gvn.transform(new (C) CmpINode(index, intcon(0))); 1.997 + Node* bol_lt = _gvn.transform(new (C) BoolNode(cmp_lt, BoolTest::lt)); 1.998 + Node* is_neg = generate_guard(bol_lt, region, PROB_MIN); 1.999 + if (is_neg != NULL && pos_index != NULL) { 1.1000 + // Emulate effect of Parse::adjust_map_after_if. 1.1001 + Node* ccast = new (C) CastIINode(index, TypeInt::POS); 1.1002 + ccast->set_req(0, control()); 1.1003 + (*pos_index) = _gvn.transform(ccast); 1.1004 + } 1.1005 + return is_neg; 1.1006 +} 1.1007 + 1.1008 +inline Node* LibraryCallKit::generate_nonpositive_guard(Node* index, bool never_negative, 1.1009 + Node* *pos_index) { 1.1010 + if (stopped()) 1.1011 + return NULL; // already stopped 1.1012 + if (_gvn.type(index)->higher_equal(TypeInt::POS1)) // [1,maxint] 1.1013 + return NULL; // index is already adequately typed 1.1014 + Node* cmp_le = _gvn.transform(new (C) CmpINode(index, intcon(0))); 1.1015 + BoolTest::mask le_or_eq = (never_negative ? BoolTest::eq : BoolTest::le); 1.1016 + Node* bol_le = _gvn.transform(new (C) BoolNode(cmp_le, le_or_eq)); 1.1017 + Node* is_notp = generate_guard(bol_le, NULL, PROB_MIN); 1.1018 + if (is_notp != NULL && pos_index != NULL) { 1.1019 + // Emulate effect of Parse::adjust_map_after_if. 1.1020 + Node* ccast = new (C) CastIINode(index, TypeInt::POS1); 1.1021 + ccast->set_req(0, control()); 1.1022 + (*pos_index) = _gvn.transform(ccast); 1.1023 + } 1.1024 + return is_notp; 1.1025 +} 1.1026 + 1.1027 +// Make sure that 'position' is a valid limit index, in [0..length]. 1.1028 +// There are two equivalent plans for checking this: 1.1029 +// A. (offset + copyLength) unsigned<= arrayLength 1.1030 +// B. offset <= (arrayLength - copyLength) 1.1031 +// We require that all of the values above, except for the sum and 1.1032 +// difference, are already known to be non-negative. 1.1033 +// Plan A is robust in the face of overflow, if offset and copyLength 1.1034 +// are both hugely positive. 1.1035 +// 1.1036 +// Plan B is less direct and intuitive, but it does not overflow at 1.1037 +// all, since the difference of two non-negatives is always 1.1038 +// representable. Whenever Java methods must perform the equivalent 1.1039 +// check they generally use Plan B instead of Plan A. 1.1040 +// For the moment we use Plan A. 1.1041 +inline Node* LibraryCallKit::generate_limit_guard(Node* offset, 1.1042 + Node* subseq_length, 1.1043 + Node* array_length, 1.1044 + RegionNode* region) { 1.1045 + if (stopped()) 1.1046 + return NULL; // already stopped 1.1047 + bool zero_offset = _gvn.type(offset) == TypeInt::ZERO; 1.1048 + if (zero_offset && subseq_length->eqv_uncast(array_length)) 1.1049 + return NULL; // common case of whole-array copy 1.1050 + Node* last = subseq_length; 1.1051 + if (!zero_offset) // last += offset 1.1052 + last = _gvn.transform(new (C) AddINode(last, offset)); 1.1053 + Node* cmp_lt = _gvn.transform(new (C) CmpUNode(array_length, last)); 1.1054 + Node* bol_lt = _gvn.transform(new (C) BoolNode(cmp_lt, BoolTest::lt)); 1.1055 + Node* is_over = generate_guard(bol_lt, region, PROB_MIN); 1.1056 + return is_over; 1.1057 +} 1.1058 + 1.1059 + 1.1060 +//--------------------------generate_current_thread-------------------- 1.1061 +Node* LibraryCallKit::generate_current_thread(Node* &tls_output) { 1.1062 + ciKlass* thread_klass = env()->Thread_klass(); 1.1063 + const Type* thread_type = TypeOopPtr::make_from_klass(thread_klass)->cast_to_ptr_type(TypePtr::NotNull); 1.1064 + Node* thread = _gvn.transform(new (C) ThreadLocalNode()); 1.1065 + Node* p = basic_plus_adr(top()/*!oop*/, thread, in_bytes(JavaThread::threadObj_offset())); 1.1066 + Node* threadObj = make_load(NULL, p, thread_type, T_OBJECT, MemNode::unordered); 1.1067 + tls_output = thread; 1.1068 + return threadObj; 1.1069 +} 1.1070 + 1.1071 + 1.1072 +//------------------------------make_string_method_node------------------------ 1.1073 +// Helper method for String intrinsic functions. This version is called 1.1074 +// with str1 and str2 pointing to String object nodes. 1.1075 +// 1.1076 +Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1, Node* str2) { 1.1077 + Node* no_ctrl = NULL; 1.1078 + 1.1079 + // Get start addr of string 1.1080 + Node* str1_value = load_String_value(no_ctrl, str1); 1.1081 + Node* str1_offset = load_String_offset(no_ctrl, str1); 1.1082 + Node* str1_start = array_element_address(str1_value, str1_offset, T_CHAR); 1.1083 + 1.1084 + // Get length of string 1 1.1085 + Node* str1_len = load_String_length(no_ctrl, str1); 1.1086 + 1.1087 + Node* str2_value = load_String_value(no_ctrl, str2); 1.1088 + Node* str2_offset = load_String_offset(no_ctrl, str2); 1.1089 + Node* str2_start = array_element_address(str2_value, str2_offset, T_CHAR); 1.1090 + 1.1091 + Node* str2_len = NULL; 1.1092 + Node* result = NULL; 1.1093 + 1.1094 + switch (opcode) { 1.1095 + case Op_StrIndexOf: 1.1096 + // Get length of string 2 1.1097 + str2_len = load_String_length(no_ctrl, str2); 1.1098 + 1.1099 + result = new (C) StrIndexOfNode(control(), memory(TypeAryPtr::CHARS), 1.1100 + str1_start, str1_len, str2_start, str2_len); 1.1101 + break; 1.1102 + case Op_StrComp: 1.1103 + // Get length of string 2 1.1104 + str2_len = load_String_length(no_ctrl, str2); 1.1105 + 1.1106 + result = new (C) StrCompNode(control(), memory(TypeAryPtr::CHARS), 1.1107 + str1_start, str1_len, str2_start, str2_len); 1.1108 + break; 1.1109 + case Op_StrEquals: 1.1110 + result = new (C) StrEqualsNode(control(), memory(TypeAryPtr::CHARS), 1.1111 + str1_start, str2_start, str1_len); 1.1112 + break; 1.1113 + default: 1.1114 + ShouldNotReachHere(); 1.1115 + return NULL; 1.1116 + } 1.1117 + 1.1118 + // All these intrinsics have checks. 1.1119 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.1120 + 1.1121 + return _gvn.transform(result); 1.1122 +} 1.1123 + 1.1124 +// Helper method for String intrinsic functions. This version is called 1.1125 +// with str1 and str2 pointing to char[] nodes, with cnt1 and cnt2 pointing 1.1126 +// to Int nodes containing the lenghts of str1 and str2. 1.1127 +// 1.1128 +Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2) { 1.1129 + Node* result = NULL; 1.1130 + switch (opcode) { 1.1131 + case Op_StrIndexOf: 1.1132 + result = new (C) StrIndexOfNode(control(), memory(TypeAryPtr::CHARS), 1.1133 + str1_start, cnt1, str2_start, cnt2); 1.1134 + break; 1.1135 + case Op_StrComp: 1.1136 + result = new (C) StrCompNode(control(), memory(TypeAryPtr::CHARS), 1.1137 + str1_start, cnt1, str2_start, cnt2); 1.1138 + break; 1.1139 + case Op_StrEquals: 1.1140 + result = new (C) StrEqualsNode(control(), memory(TypeAryPtr::CHARS), 1.1141 + str1_start, str2_start, cnt1); 1.1142 + break; 1.1143 + default: 1.1144 + ShouldNotReachHere(); 1.1145 + return NULL; 1.1146 + } 1.1147 + 1.1148 + // All these intrinsics have checks. 1.1149 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.1150 + 1.1151 + return _gvn.transform(result); 1.1152 +} 1.1153 + 1.1154 +//------------------------------inline_string_compareTo------------------------ 1.1155 +// public int java.lang.String.compareTo(String anotherString); 1.1156 +bool LibraryCallKit::inline_string_compareTo() { 1.1157 + Node* receiver = null_check(argument(0)); 1.1158 + Node* arg = null_check(argument(1)); 1.1159 + if (stopped()) { 1.1160 + return true; 1.1161 + } 1.1162 + set_result(make_string_method_node(Op_StrComp, receiver, arg)); 1.1163 + return true; 1.1164 +} 1.1165 + 1.1166 +//------------------------------inline_string_equals------------------------ 1.1167 +bool LibraryCallKit::inline_string_equals() { 1.1168 + Node* receiver = null_check_receiver(); 1.1169 + // NOTE: Do not null check argument for String.equals() because spec 1.1170 + // allows to specify NULL as argument. 1.1171 + Node* argument = this->argument(1); 1.1172 + if (stopped()) { 1.1173 + return true; 1.1174 + } 1.1175 + 1.1176 + // paths (plus control) merge 1.1177 + RegionNode* region = new (C) RegionNode(5); 1.1178 + Node* phi = new (C) PhiNode(region, TypeInt::BOOL); 1.1179 + 1.1180 + // does source == target string? 1.1181 + Node* cmp = _gvn.transform(new (C) CmpPNode(receiver, argument)); 1.1182 + Node* bol = _gvn.transform(new (C) BoolNode(cmp, BoolTest::eq)); 1.1183 + 1.1184 + Node* if_eq = generate_slow_guard(bol, NULL); 1.1185 + if (if_eq != NULL) { 1.1186 + // receiver == argument 1.1187 + phi->init_req(2, intcon(1)); 1.1188 + region->init_req(2, if_eq); 1.1189 + } 1.1190 + 1.1191 + // get String klass for instanceOf 1.1192 + ciInstanceKlass* klass = env()->String_klass(); 1.1193 + 1.1194 + if (!stopped()) { 1.1195 + Node* inst = gen_instanceof(argument, makecon(TypeKlassPtr::make(klass))); 1.1196 + Node* cmp = _gvn.transform(new (C) CmpINode(inst, intcon(1))); 1.1197 + Node* bol = _gvn.transform(new (C) BoolNode(cmp, BoolTest::ne)); 1.1198 + 1.1199 + Node* inst_false = generate_guard(bol, NULL, PROB_MIN); 1.1200 + //instanceOf == true, fallthrough 1.1201 + 1.1202 + if (inst_false != NULL) { 1.1203 + phi->init_req(3, intcon(0)); 1.1204 + region->init_req(3, inst_false); 1.1205 + } 1.1206 + } 1.1207 + 1.1208 + if (!stopped()) { 1.1209 + const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(klass); 1.1210 + 1.1211 + // Properly cast the argument to String 1.1212 + argument = _gvn.transform(new (C) CheckCastPPNode(control(), argument, string_type)); 1.1213 + // This path is taken only when argument's type is String:NotNull. 1.1214 + argument = cast_not_null(argument, false); 1.1215 + 1.1216 + Node* no_ctrl = NULL; 1.1217 + 1.1218 + // Get start addr of receiver 1.1219 + Node* receiver_val = load_String_value(no_ctrl, receiver); 1.1220 + Node* receiver_offset = load_String_offset(no_ctrl, receiver); 1.1221 + Node* receiver_start = array_element_address(receiver_val, receiver_offset, T_CHAR); 1.1222 + 1.1223 + // Get length of receiver 1.1224 + Node* receiver_cnt = load_String_length(no_ctrl, receiver); 1.1225 + 1.1226 + // Get start addr of argument 1.1227 + Node* argument_val = load_String_value(no_ctrl, argument); 1.1228 + Node* argument_offset = load_String_offset(no_ctrl, argument); 1.1229 + Node* argument_start = array_element_address(argument_val, argument_offset, T_CHAR); 1.1230 + 1.1231 + // Get length of argument 1.1232 + Node* argument_cnt = load_String_length(no_ctrl, argument); 1.1233 + 1.1234 + // Check for receiver count != argument count 1.1235 + Node* cmp = _gvn.transform(new(C) CmpINode(receiver_cnt, argument_cnt)); 1.1236 + Node* bol = _gvn.transform(new(C) BoolNode(cmp, BoolTest::ne)); 1.1237 + Node* if_ne = generate_slow_guard(bol, NULL); 1.1238 + if (if_ne != NULL) { 1.1239 + phi->init_req(4, intcon(0)); 1.1240 + region->init_req(4, if_ne); 1.1241 + } 1.1242 + 1.1243 + // Check for count == 0 is done by assembler code for StrEquals. 1.1244 + 1.1245 + if (!stopped()) { 1.1246 + Node* equals = make_string_method_node(Op_StrEquals, receiver_start, receiver_cnt, argument_start, argument_cnt); 1.1247 + phi->init_req(1, equals); 1.1248 + region->init_req(1, control()); 1.1249 + } 1.1250 + } 1.1251 + 1.1252 + // post merge 1.1253 + set_control(_gvn.transform(region)); 1.1254 + record_for_igvn(region); 1.1255 + 1.1256 + set_result(_gvn.transform(phi)); 1.1257 + return true; 1.1258 +} 1.1259 + 1.1260 +//------------------------------inline_array_equals---------------------------- 1.1261 +bool LibraryCallKit::inline_array_equals() { 1.1262 + Node* arg1 = argument(0); 1.1263 + Node* arg2 = argument(1); 1.1264 + set_result(_gvn.transform(new (C) AryEqNode(control(), memory(TypeAryPtr::CHARS), arg1, arg2))); 1.1265 + return true; 1.1266 +} 1.1267 + 1.1268 +// Java version of String.indexOf(constant string) 1.1269 +// class StringDecl { 1.1270 +// StringDecl(char[] ca) { 1.1271 +// offset = 0; 1.1272 +// count = ca.length; 1.1273 +// value = ca; 1.1274 +// } 1.1275 +// int offset; 1.1276 +// int count; 1.1277 +// char[] value; 1.1278 +// } 1.1279 +// 1.1280 +// static int string_indexOf_J(StringDecl string_object, char[] target_object, 1.1281 +// int targetOffset, int cache_i, int md2) { 1.1282 +// int cache = cache_i; 1.1283 +// int sourceOffset = string_object.offset; 1.1284 +// int sourceCount = string_object.count; 1.1285 +// int targetCount = target_object.length; 1.1286 +// 1.1287 +// int targetCountLess1 = targetCount - 1; 1.1288 +// int sourceEnd = sourceOffset + sourceCount - targetCountLess1; 1.1289 +// 1.1290 +// char[] source = string_object.value; 1.1291 +// char[] target = target_object; 1.1292 +// int lastChar = target[targetCountLess1]; 1.1293 +// 1.1294 +// outer_loop: 1.1295 +// for (int i = sourceOffset; i < sourceEnd; ) { 1.1296 +// int src = source[i + targetCountLess1]; 1.1297 +// if (src == lastChar) { 1.1298 +// // With random strings and a 4-character alphabet, 1.1299 +// // reverse matching at this point sets up 0.8% fewer 1.1300 +// // frames, but (paradoxically) makes 0.3% more probes. 1.1301 +// // Since those probes are nearer the lastChar probe, 1.1302 +// // there is may be a net D$ win with reverse matching. 1.1303 +// // But, reversing loop inhibits unroll of inner loop 1.1304 +// // for unknown reason. So, does running outer loop from 1.1305 +// // (sourceOffset - targetCountLess1) to (sourceOffset + sourceCount) 1.1306 +// for (int j = 0; j < targetCountLess1; j++) { 1.1307 +// if (target[targetOffset + j] != source[i+j]) { 1.1308 +// if ((cache & (1 << source[i+j])) == 0) { 1.1309 +// if (md2 < j+1) { 1.1310 +// i += j+1; 1.1311 +// continue outer_loop; 1.1312 +// } 1.1313 +// } 1.1314 +// i += md2; 1.1315 +// continue outer_loop; 1.1316 +// } 1.1317 +// } 1.1318 +// return i - sourceOffset; 1.1319 +// } 1.1320 +// if ((cache & (1 << src)) == 0) { 1.1321 +// i += targetCountLess1; 1.1322 +// } // using "i += targetCount;" and an "else i++;" causes a jump to jump. 1.1323 +// i++; 1.1324 +// } 1.1325 +// return -1; 1.1326 +// } 1.1327 + 1.1328 +//------------------------------string_indexOf------------------------ 1.1329 +Node* LibraryCallKit::string_indexOf(Node* string_object, ciTypeArray* target_array, jint targetOffset_i, 1.1330 + jint cache_i, jint md2_i) { 1.1331 + 1.1332 + Node* no_ctrl = NULL; 1.1333 + float likely = PROB_LIKELY(0.9); 1.1334 + float unlikely = PROB_UNLIKELY(0.9); 1.1335 + 1.1336 + const int nargs = 0; // no arguments to push back for uncommon trap in predicate 1.1337 + 1.1338 + Node* source = load_String_value(no_ctrl, string_object); 1.1339 + Node* sourceOffset = load_String_offset(no_ctrl, string_object); 1.1340 + Node* sourceCount = load_String_length(no_ctrl, string_object); 1.1341 + 1.1342 + Node* target = _gvn.transform( makecon(TypeOopPtr::make_from_constant(target_array, true))); 1.1343 + jint target_length = target_array->length(); 1.1344 + const TypeAry* target_array_type = TypeAry::make(TypeInt::CHAR, TypeInt::make(0, target_length, Type::WidenMin)); 1.1345 + const TypeAryPtr* target_type = TypeAryPtr::make(TypePtr::BotPTR, target_array_type, target_array->klass(), true, Type::OffsetBot); 1.1346 + 1.1347 + // String.value field is known to be @Stable. 1.1348 + if (UseImplicitStableValues) { 1.1349 + target = cast_array_to_stable(target, target_type); 1.1350 + } 1.1351 + 1.1352 + IdealKit kit(this, false, true); 1.1353 +#define __ kit. 1.1354 + Node* zero = __ ConI(0); 1.1355 + Node* one = __ ConI(1); 1.1356 + Node* cache = __ ConI(cache_i); 1.1357 + Node* md2 = __ ConI(md2_i); 1.1358 + Node* lastChar = __ ConI(target_array->char_at(target_length - 1)); 1.1359 + Node* targetCount = __ ConI(target_length); 1.1360 + Node* targetCountLess1 = __ ConI(target_length - 1); 1.1361 + Node* targetOffset = __ ConI(targetOffset_i); 1.1362 + Node* sourceEnd = __ SubI(__ AddI(sourceOffset, sourceCount), targetCountLess1); 1.1363 + 1.1364 + IdealVariable rtn(kit), i(kit), j(kit); __ declarations_done(); 1.1365 + Node* outer_loop = __ make_label(2 /* goto */); 1.1366 + Node* return_ = __ make_label(1); 1.1367 + 1.1368 + __ set(rtn,__ ConI(-1)); 1.1369 + __ loop(this, nargs, i, sourceOffset, BoolTest::lt, sourceEnd); { 1.1370 + Node* i2 = __ AddI(__ value(i), targetCountLess1); 1.1371 + // pin to prohibit loading of "next iteration" value which may SEGV (rare) 1.1372 + Node* src = load_array_element(__ ctrl(), source, i2, TypeAryPtr::CHARS); 1.1373 + __ if_then(src, BoolTest::eq, lastChar, unlikely); { 1.1374 + __ loop(this, nargs, j, zero, BoolTest::lt, targetCountLess1); { 1.1375 + Node* tpj = __ AddI(targetOffset, __ value(j)); 1.1376 + Node* targ = load_array_element(no_ctrl, target, tpj, target_type); 1.1377 + Node* ipj = __ AddI(__ value(i), __ value(j)); 1.1378 + Node* src2 = load_array_element(no_ctrl, source, ipj, TypeAryPtr::CHARS); 1.1379 + __ if_then(targ, BoolTest::ne, src2); { 1.1380 + __ if_then(__ AndI(cache, __ LShiftI(one, src2)), BoolTest::eq, zero); { 1.1381 + __ if_then(md2, BoolTest::lt, __ AddI(__ value(j), one)); { 1.1382 + __ increment(i, __ AddI(__ value(j), one)); 1.1383 + __ goto_(outer_loop); 1.1384 + } __ end_if(); __ dead(j); 1.1385 + }__ end_if(); __ dead(j); 1.1386 + __ increment(i, md2); 1.1387 + __ goto_(outer_loop); 1.1388 + }__ end_if(); 1.1389 + __ increment(j, one); 1.1390 + }__ end_loop(); __ dead(j); 1.1391 + __ set(rtn, __ SubI(__ value(i), sourceOffset)); __ dead(i); 1.1392 + __ goto_(return_); 1.1393 + }__ end_if(); 1.1394 + __ if_then(__ AndI(cache, __ LShiftI(one, src)), BoolTest::eq, zero, likely); { 1.1395 + __ increment(i, targetCountLess1); 1.1396 + }__ end_if(); 1.1397 + __ increment(i, one); 1.1398 + __ bind(outer_loop); 1.1399 + }__ end_loop(); __ dead(i); 1.1400 + __ bind(return_); 1.1401 + 1.1402 + // Final sync IdealKit and GraphKit. 1.1403 + final_sync(kit); 1.1404 + Node* result = __ value(rtn); 1.1405 +#undef __ 1.1406 + C->set_has_loops(true); 1.1407 + return result; 1.1408 +} 1.1409 + 1.1410 +//------------------------------inline_string_indexOf------------------------ 1.1411 +bool LibraryCallKit::inline_string_indexOf() { 1.1412 + Node* receiver = argument(0); 1.1413 + Node* arg = argument(1); 1.1414 + 1.1415 + Node* result; 1.1416 + // Disable the use of pcmpestri until it can be guaranteed that 1.1417 + // the load doesn't cross into the uncommited space. 1.1418 + if (Matcher::has_match_rule(Op_StrIndexOf) && 1.1419 + UseSSE42Intrinsics) { 1.1420 + // Generate SSE4.2 version of indexOf 1.1421 + // We currently only have match rules that use SSE4.2 1.1422 + 1.1423 + receiver = null_check(receiver); 1.1424 + arg = null_check(arg); 1.1425 + if (stopped()) { 1.1426 + return true; 1.1427 + } 1.1428 + 1.1429 + ciInstanceKlass* str_klass = env()->String_klass(); 1.1430 + const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(str_klass); 1.1431 + 1.1432 + // Make the merge point 1.1433 + RegionNode* result_rgn = new (C) RegionNode(4); 1.1434 + Node* result_phi = new (C) PhiNode(result_rgn, TypeInt::INT); 1.1435 + Node* no_ctrl = NULL; 1.1436 + 1.1437 + // Get start addr of source string 1.1438 + Node* source = load_String_value(no_ctrl, receiver); 1.1439 + Node* source_offset = load_String_offset(no_ctrl, receiver); 1.1440 + Node* source_start = array_element_address(source, source_offset, T_CHAR); 1.1441 + 1.1442 + // Get length of source string 1.1443 + Node* source_cnt = load_String_length(no_ctrl, receiver); 1.1444 + 1.1445 + // Get start addr of substring 1.1446 + Node* substr = load_String_value(no_ctrl, arg); 1.1447 + Node* substr_offset = load_String_offset(no_ctrl, arg); 1.1448 + Node* substr_start = array_element_address(substr, substr_offset, T_CHAR); 1.1449 + 1.1450 + // Get length of source string 1.1451 + Node* substr_cnt = load_String_length(no_ctrl, arg); 1.1452 + 1.1453 + // Check for substr count > string count 1.1454 + Node* cmp = _gvn.transform(new(C) CmpINode(substr_cnt, source_cnt)); 1.1455 + Node* bol = _gvn.transform(new(C) BoolNode(cmp, BoolTest::gt)); 1.1456 + Node* if_gt = generate_slow_guard(bol, NULL); 1.1457 + if (if_gt != NULL) { 1.1458 + result_phi->init_req(2, intcon(-1)); 1.1459 + result_rgn->init_req(2, if_gt); 1.1460 + } 1.1461 + 1.1462 + if (!stopped()) { 1.1463 + // Check for substr count == 0 1.1464 + cmp = _gvn.transform(new(C) CmpINode(substr_cnt, intcon(0))); 1.1465 + bol = _gvn.transform(new(C) BoolNode(cmp, BoolTest::eq)); 1.1466 + Node* if_zero = generate_slow_guard(bol, NULL); 1.1467 + if (if_zero != NULL) { 1.1468 + result_phi->init_req(3, intcon(0)); 1.1469 + result_rgn->init_req(3, if_zero); 1.1470 + } 1.1471 + } 1.1472 + 1.1473 + if (!stopped()) { 1.1474 + result = make_string_method_node(Op_StrIndexOf, source_start, source_cnt, substr_start, substr_cnt); 1.1475 + result_phi->init_req(1, result); 1.1476 + result_rgn->init_req(1, control()); 1.1477 + } 1.1478 + set_control(_gvn.transform(result_rgn)); 1.1479 + record_for_igvn(result_rgn); 1.1480 + result = _gvn.transform(result_phi); 1.1481 + 1.1482 + } else { // Use LibraryCallKit::string_indexOf 1.1483 + // don't intrinsify if argument isn't a constant string. 1.1484 + if (!arg->is_Con()) { 1.1485 + return false; 1.1486 + } 1.1487 + const TypeOopPtr* str_type = _gvn.type(arg)->isa_oopptr(); 1.1488 + if (str_type == NULL) { 1.1489 + return false; 1.1490 + } 1.1491 + ciInstanceKlass* klass = env()->String_klass(); 1.1492 + ciObject* str_const = str_type->const_oop(); 1.1493 + if (str_const == NULL || str_const->klass() != klass) { 1.1494 + return false; 1.1495 + } 1.1496 + ciInstance* str = str_const->as_instance(); 1.1497 + assert(str != NULL, "must be instance"); 1.1498 + 1.1499 + ciObject* v = str->field_value_by_offset(java_lang_String::value_offset_in_bytes()).as_object(); 1.1500 + ciTypeArray* pat = v->as_type_array(); // pattern (argument) character array 1.1501 + 1.1502 + int o; 1.1503 + int c; 1.1504 + if (java_lang_String::has_offset_field()) { 1.1505 + o = str->field_value_by_offset(java_lang_String::offset_offset_in_bytes()).as_int(); 1.1506 + c = str->field_value_by_offset(java_lang_String::count_offset_in_bytes()).as_int(); 1.1507 + } else { 1.1508 + o = 0; 1.1509 + c = pat->length(); 1.1510 + } 1.1511 + 1.1512 + // constant strings have no offset and count == length which 1.1513 + // simplifies the resulting code somewhat so lets optimize for that. 1.1514 + if (o != 0 || c != pat->length()) { 1.1515 + return false; 1.1516 + } 1.1517 + 1.1518 + receiver = null_check(receiver, T_OBJECT); 1.1519 + // NOTE: No null check on the argument is needed since it's a constant String oop. 1.1520 + if (stopped()) { 1.1521 + return true; 1.1522 + } 1.1523 + 1.1524 + // The null string as a pattern always returns 0 (match at beginning of string) 1.1525 + if (c == 0) { 1.1526 + set_result(intcon(0)); 1.1527 + return true; 1.1528 + } 1.1529 + 1.1530 + // Generate default indexOf 1.1531 + jchar lastChar = pat->char_at(o + (c - 1)); 1.1532 + int cache = 0; 1.1533 + int i; 1.1534 + for (i = 0; i < c - 1; i++) { 1.1535 + assert(i < pat->length(), "out of range"); 1.1536 + cache |= (1 << (pat->char_at(o + i) & (sizeof(cache) * BitsPerByte - 1))); 1.1537 + } 1.1538 + 1.1539 + int md2 = c; 1.1540 + for (i = 0; i < c - 1; i++) { 1.1541 + assert(i < pat->length(), "out of range"); 1.1542 + if (pat->char_at(o + i) == lastChar) { 1.1543 + md2 = (c - 1) - i; 1.1544 + } 1.1545 + } 1.1546 + 1.1547 + result = string_indexOf(receiver, pat, o, cache, md2); 1.1548 + } 1.1549 + set_result(result); 1.1550 + return true; 1.1551 +} 1.1552 + 1.1553 +//--------------------------round_double_node-------------------------------- 1.1554 +// Round a double node if necessary. 1.1555 +Node* LibraryCallKit::round_double_node(Node* n) { 1.1556 + if (Matcher::strict_fp_requires_explicit_rounding && UseSSE <= 1) 1.1557 + n = _gvn.transform(new (C) RoundDoubleNode(0, n)); 1.1558 + return n; 1.1559 +} 1.1560 + 1.1561 +//------------------------------inline_math----------------------------------- 1.1562 +// public static double Math.abs(double) 1.1563 +// public static double Math.sqrt(double) 1.1564 +// public static double Math.log(double) 1.1565 +// public static double Math.log10(double) 1.1566 +bool LibraryCallKit::inline_math(vmIntrinsics::ID id) { 1.1567 + Node* arg = round_double_node(argument(0)); 1.1568 + Node* n; 1.1569 + switch (id) { 1.1570 + case vmIntrinsics::_dabs: n = new (C) AbsDNode( arg); break; 1.1571 + case vmIntrinsics::_dsqrt: n = new (C) SqrtDNode(C, control(), arg); break; 1.1572 + case vmIntrinsics::_dlog: n = new (C) LogDNode(C, control(), arg); break; 1.1573 + case vmIntrinsics::_dlog10: n = new (C) Log10DNode(C, control(), arg); break; 1.1574 + default: fatal_unexpected_iid(id); break; 1.1575 + } 1.1576 + set_result(_gvn.transform(n)); 1.1577 + return true; 1.1578 +} 1.1579 + 1.1580 +//------------------------------inline_trig---------------------------------- 1.1581 +// Inline sin/cos/tan instructions, if possible. If rounding is required, do 1.1582 +// argument reduction which will turn into a fast/slow diamond. 1.1583 +bool LibraryCallKit::inline_trig(vmIntrinsics::ID id) { 1.1584 + Node* arg = round_double_node(argument(0)); 1.1585 + Node* n = NULL; 1.1586 + 1.1587 + switch (id) { 1.1588 + case vmIntrinsics::_dsin: n = new (C) SinDNode(C, control(), arg); break; 1.1589 + case vmIntrinsics::_dcos: n = new (C) CosDNode(C, control(), arg); break; 1.1590 + case vmIntrinsics::_dtan: n = new (C) TanDNode(C, control(), arg); break; 1.1591 + default: fatal_unexpected_iid(id); break; 1.1592 + } 1.1593 + n = _gvn.transform(n); 1.1594 + 1.1595 + // Rounding required? Check for argument reduction! 1.1596 + if (Matcher::strict_fp_requires_explicit_rounding) { 1.1597 + static const double pi_4 = 0.7853981633974483; 1.1598 + static const double neg_pi_4 = -0.7853981633974483; 1.1599 + // pi/2 in 80-bit extended precision 1.1600 + // static const unsigned char pi_2_bits_x[] = {0x35,0xc2,0x68,0x21,0xa2,0xda,0x0f,0xc9,0xff,0x3f,0x00,0x00,0x00,0x00,0x00,0x00}; 1.1601 + // -pi/2 in 80-bit extended precision 1.1602 + // static const unsigned char neg_pi_2_bits_x[] = {0x35,0xc2,0x68,0x21,0xa2,0xda,0x0f,0xc9,0xff,0xbf,0x00,0x00,0x00,0x00,0x00,0x00}; 1.1603 + // Cutoff value for using this argument reduction technique 1.1604 + //static const double pi_2_minus_epsilon = 1.564660403643354; 1.1605 + //static const double neg_pi_2_plus_epsilon = -1.564660403643354; 1.1606 + 1.1607 + // Pseudocode for sin: 1.1608 + // if (x <= Math.PI / 4.0) { 1.1609 + // if (x >= -Math.PI / 4.0) return fsin(x); 1.1610 + // if (x >= -Math.PI / 2.0) return -fcos(x + Math.PI / 2.0); 1.1611 + // } else { 1.1612 + // if (x <= Math.PI / 2.0) return fcos(x - Math.PI / 2.0); 1.1613 + // } 1.1614 + // return StrictMath.sin(x); 1.1615 + 1.1616 + // Pseudocode for cos: 1.1617 + // if (x <= Math.PI / 4.0) { 1.1618 + // if (x >= -Math.PI / 4.0) return fcos(x); 1.1619 + // if (x >= -Math.PI / 2.0) return fsin(x + Math.PI / 2.0); 1.1620 + // } else { 1.1621 + // if (x <= Math.PI / 2.0) return -fsin(x - Math.PI / 2.0); 1.1622 + // } 1.1623 + // return StrictMath.cos(x); 1.1624 + 1.1625 + // Actually, sticking in an 80-bit Intel value into C2 will be tough; it 1.1626 + // requires a special machine instruction to load it. Instead we'll try 1.1627 + // the 'easy' case. If we really need the extra range +/- PI/2 we'll 1.1628 + // probably do the math inside the SIN encoding. 1.1629 + 1.1630 + // Make the merge point 1.1631 + RegionNode* r = new (C) RegionNode(3); 1.1632 + Node* phi = new (C) PhiNode(r, Type::DOUBLE); 1.1633 + 1.1634 + // Flatten arg so we need only 1 test 1.1635 + Node *abs = _gvn.transform(new (C) AbsDNode(arg)); 1.1636 + // Node for PI/4 constant 1.1637 + Node *pi4 = makecon(TypeD::make(pi_4)); 1.1638 + // Check PI/4 : abs(arg) 1.1639 + Node *cmp = _gvn.transform(new (C) CmpDNode(pi4,abs)); 1.1640 + // Check: If PI/4 < abs(arg) then go slow 1.1641 + Node *bol = _gvn.transform(new (C) BoolNode( cmp, BoolTest::lt )); 1.1642 + // Branch either way 1.1643 + IfNode *iff = create_and_xform_if(control(),bol, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 1.1644 + set_control(opt_iff(r,iff)); 1.1645 + 1.1646 + // Set fast path result 1.1647 + phi->init_req(2, n); 1.1648 + 1.1649 + // Slow path - non-blocking leaf call 1.1650 + Node* call = NULL; 1.1651 + switch (id) { 1.1652 + case vmIntrinsics::_dsin: 1.1653 + call = make_runtime_call(RC_LEAF, OptoRuntime::Math_D_D_Type(), 1.1654 + CAST_FROM_FN_PTR(address, SharedRuntime::dsin), 1.1655 + "Sin", NULL, arg, top()); 1.1656 + break; 1.1657 + case vmIntrinsics::_dcos: 1.1658 + call = make_runtime_call(RC_LEAF, OptoRuntime::Math_D_D_Type(), 1.1659 + CAST_FROM_FN_PTR(address, SharedRuntime::dcos), 1.1660 + "Cos", NULL, arg, top()); 1.1661 + break; 1.1662 + case vmIntrinsics::_dtan: 1.1663 + call = make_runtime_call(RC_LEAF, OptoRuntime::Math_D_D_Type(), 1.1664 + CAST_FROM_FN_PTR(address, SharedRuntime::dtan), 1.1665 + "Tan", NULL, arg, top()); 1.1666 + break; 1.1667 + } 1.1668 + assert(control()->in(0) == call, ""); 1.1669 + Node* slow_result = _gvn.transform(new (C) ProjNode(call, TypeFunc::Parms)); 1.1670 + r->init_req(1, control()); 1.1671 + phi->init_req(1, slow_result); 1.1672 + 1.1673 + // Post-merge 1.1674 + set_control(_gvn.transform(r)); 1.1675 + record_for_igvn(r); 1.1676 + n = _gvn.transform(phi); 1.1677 + 1.1678 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.1679 + } 1.1680 + set_result(n); 1.1681 + return true; 1.1682 +} 1.1683 + 1.1684 +Node* LibraryCallKit::finish_pow_exp(Node* result, Node* x, Node* y, const TypeFunc* call_type, address funcAddr, const char* funcName) { 1.1685 + //------------------- 1.1686 + //result=(result.isNaN())? funcAddr():result; 1.1687 + // Check: If isNaN() by checking result!=result? then either trap 1.1688 + // or go to runtime 1.1689 + Node* cmpisnan = _gvn.transform(new (C) CmpDNode(result, result)); 1.1690 + // Build the boolean node 1.1691 + Node* bolisnum = _gvn.transform(new (C) BoolNode(cmpisnan, BoolTest::eq)); 1.1692 + 1.1693 + if (!too_many_traps(Deoptimization::Reason_intrinsic)) { 1.1694 + { BuildCutout unless(this, bolisnum, PROB_STATIC_FREQUENT); 1.1695 + // The pow or exp intrinsic returned a NaN, which requires a call 1.1696 + // to the runtime. Recompile with the runtime call. 1.1697 + uncommon_trap(Deoptimization::Reason_intrinsic, 1.1698 + Deoptimization::Action_make_not_entrant); 1.1699 + } 1.1700 + return result; 1.1701 + } else { 1.1702 + // If this inlining ever returned NaN in the past, we compile a call 1.1703 + // to the runtime to properly handle corner cases 1.1704 + 1.1705 + IfNode* iff = create_and_xform_if(control(), bolisnum, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 1.1706 + Node* if_slow = _gvn.transform(new (C) IfFalseNode(iff)); 1.1707 + Node* if_fast = _gvn.transform(new (C) IfTrueNode(iff)); 1.1708 + 1.1709 + if (!if_slow->is_top()) { 1.1710 + RegionNode* result_region = new (C) RegionNode(3); 1.1711 + PhiNode* result_val = new (C) PhiNode(result_region, Type::DOUBLE); 1.1712 + 1.1713 + result_region->init_req(1, if_fast); 1.1714 + result_val->init_req(1, result); 1.1715 + 1.1716 + set_control(if_slow); 1.1717 + 1.1718 + const TypePtr* no_memory_effects = NULL; 1.1719 + Node* rt = make_runtime_call(RC_LEAF, call_type, funcAddr, funcName, 1.1720 + no_memory_effects, 1.1721 + x, top(), y, y ? top() : NULL); 1.1722 + Node* value = _gvn.transform(new (C) ProjNode(rt, TypeFunc::Parms+0)); 1.1723 +#ifdef ASSERT 1.1724 + Node* value_top = _gvn.transform(new (C) ProjNode(rt, TypeFunc::Parms+1)); 1.1725 + assert(value_top == top(), "second value must be top"); 1.1726 +#endif 1.1727 + 1.1728 + result_region->init_req(2, control()); 1.1729 + result_val->init_req(2, value); 1.1730 + set_control(_gvn.transform(result_region)); 1.1731 + return _gvn.transform(result_val); 1.1732 + } else { 1.1733 + return result; 1.1734 + } 1.1735 + } 1.1736 +} 1.1737 + 1.1738 +//------------------------------inline_exp------------------------------------- 1.1739 +// Inline exp instructions, if possible. The Intel hardware only misses 1.1740 +// really odd corner cases (+/- Infinity). Just uncommon-trap them. 1.1741 +bool LibraryCallKit::inline_exp() { 1.1742 + Node* arg = round_double_node(argument(0)); 1.1743 + Node* n = _gvn.transform(new (C) ExpDNode(C, control(), arg)); 1.1744 + 1.1745 + n = finish_pow_exp(n, arg, NULL, OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dexp), "EXP"); 1.1746 + set_result(n); 1.1747 + 1.1748 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.1749 + return true; 1.1750 +} 1.1751 + 1.1752 +//------------------------------inline_pow------------------------------------- 1.1753 +// Inline power instructions, if possible. 1.1754 +bool LibraryCallKit::inline_pow() { 1.1755 + // Pseudocode for pow 1.1756 + // if (y == 2) { 1.1757 + // return x * x; 1.1758 + // } else { 1.1759 + // if (x <= 0.0) { 1.1760 + // long longy = (long)y; 1.1761 + // if ((double)longy == y) { // if y is long 1.1762 + // if (y + 1 == y) longy = 0; // huge number: even 1.1763 + // result = ((1&longy) == 0)?-DPow(abs(x), y):DPow(abs(x), y); 1.1764 + // } else { 1.1765 + // result = NaN; 1.1766 + // } 1.1767 + // } else { 1.1768 + // result = DPow(x,y); 1.1769 + // } 1.1770 + // if (result != result)? { 1.1771 + // result = uncommon_trap() or runtime_call(); 1.1772 + // } 1.1773 + // return result; 1.1774 + // } 1.1775 + 1.1776 + Node* x = round_double_node(argument(0)); 1.1777 + Node* y = round_double_node(argument(2)); 1.1778 + 1.1779 + Node* result = NULL; 1.1780 + 1.1781 + Node* const_two_node = makecon(TypeD::make(2.0)); 1.1782 + Node* cmp_node = _gvn.transform(new (C) CmpDNode(y, const_two_node)); 1.1783 + Node* bool_node = _gvn.transform(new (C) BoolNode(cmp_node, BoolTest::eq)); 1.1784 + IfNode* if_node = create_and_xform_if(control(), bool_node, PROB_STATIC_INFREQUENT, COUNT_UNKNOWN); 1.1785 + Node* if_true = _gvn.transform(new (C) IfTrueNode(if_node)); 1.1786 + Node* if_false = _gvn.transform(new (C) IfFalseNode(if_node)); 1.1787 + 1.1788 + RegionNode* region_node = new (C) RegionNode(3); 1.1789 + region_node->init_req(1, if_true); 1.1790 + 1.1791 + Node* phi_node = new (C) PhiNode(region_node, Type::DOUBLE); 1.1792 + // special case for x^y where y == 2, we can convert it to x * x 1.1793 + phi_node->init_req(1, _gvn.transform(new (C) MulDNode(x, x))); 1.1794 + 1.1795 + // set control to if_false since we will now process the false branch 1.1796 + set_control(if_false); 1.1797 + 1.1798 + if (!too_many_traps(Deoptimization::Reason_intrinsic)) { 1.1799 + // Short form: skip the fancy tests and just check for NaN result. 1.1800 + result = _gvn.transform(new (C) PowDNode(C, control(), x, y)); 1.1801 + } else { 1.1802 + // If this inlining ever returned NaN in the past, include all 1.1803 + // checks + call to the runtime. 1.1804 + 1.1805 + // Set the merge point for If node with condition of (x <= 0.0) 1.1806 + // There are four possible paths to region node and phi node 1.1807 + RegionNode *r = new (C) RegionNode(4); 1.1808 + Node *phi = new (C) PhiNode(r, Type::DOUBLE); 1.1809 + 1.1810 + // Build the first if node: if (x <= 0.0) 1.1811 + // Node for 0 constant 1.1812 + Node *zeronode = makecon(TypeD::ZERO); 1.1813 + // Check x:0 1.1814 + Node *cmp = _gvn.transform(new (C) CmpDNode(x, zeronode)); 1.1815 + // Check: If (x<=0) then go complex path 1.1816 + Node *bol1 = _gvn.transform(new (C) BoolNode( cmp, BoolTest::le )); 1.1817 + // Branch either way 1.1818 + IfNode *if1 = create_and_xform_if(control(),bol1, PROB_STATIC_INFREQUENT, COUNT_UNKNOWN); 1.1819 + // Fast path taken; set region slot 3 1.1820 + Node *fast_taken = _gvn.transform(new (C) IfFalseNode(if1)); 1.1821 + r->init_req(3,fast_taken); // Capture fast-control 1.1822 + 1.1823 + // Fast path not-taken, i.e. slow path 1.1824 + Node *complex_path = _gvn.transform(new (C) IfTrueNode(if1)); 1.1825 + 1.1826 + // Set fast path result 1.1827 + Node *fast_result = _gvn.transform(new (C) PowDNode(C, control(), x, y)); 1.1828 + phi->init_req(3, fast_result); 1.1829 + 1.1830 + // Complex path 1.1831 + // Build the second if node (if y is long) 1.1832 + // Node for (long)y 1.1833 + Node *longy = _gvn.transform(new (C) ConvD2LNode(y)); 1.1834 + // Node for (double)((long) y) 1.1835 + Node *doublelongy= _gvn.transform(new (C) ConvL2DNode(longy)); 1.1836 + // Check (double)((long) y) : y 1.1837 + Node *cmplongy= _gvn.transform(new (C) CmpDNode(doublelongy, y)); 1.1838 + // Check if (y isn't long) then go to slow path 1.1839 + 1.1840 + Node *bol2 = _gvn.transform(new (C) BoolNode( cmplongy, BoolTest::ne )); 1.1841 + // Branch either way 1.1842 + IfNode *if2 = create_and_xform_if(complex_path,bol2, PROB_STATIC_INFREQUENT, COUNT_UNKNOWN); 1.1843 + Node* ylong_path = _gvn.transform(new (C) IfFalseNode(if2)); 1.1844 + 1.1845 + Node *slow_path = _gvn.transform(new (C) IfTrueNode(if2)); 1.1846 + 1.1847 + // Calculate DPow(abs(x), y)*(1 & (long)y) 1.1848 + // Node for constant 1 1.1849 + Node *conone = longcon(1); 1.1850 + // 1& (long)y 1.1851 + Node *signnode= _gvn.transform(new (C) AndLNode(conone, longy)); 1.1852 + 1.1853 + // A huge number is always even. Detect a huge number by checking 1.1854 + // if y + 1 == y and set integer to be tested for parity to 0. 1.1855 + // Required for corner case: 1.1856 + // (long)9.223372036854776E18 = max_jlong 1.1857 + // (double)(long)9.223372036854776E18 = 9.223372036854776E18 1.1858 + // max_jlong is odd but 9.223372036854776E18 is even 1.1859 + Node* yplus1 = _gvn.transform(new (C) AddDNode(y, makecon(TypeD::make(1)))); 1.1860 + Node *cmpyplus1= _gvn.transform(new (C) CmpDNode(yplus1, y)); 1.1861 + Node *bolyplus1 = _gvn.transform(new (C) BoolNode( cmpyplus1, BoolTest::eq )); 1.1862 + Node* correctedsign = NULL; 1.1863 + if (ConditionalMoveLimit != 0) { 1.1864 + correctedsign = _gvn.transform( CMoveNode::make(C, NULL, bolyplus1, signnode, longcon(0), TypeLong::LONG)); 1.1865 + } else { 1.1866 + IfNode *ifyplus1 = create_and_xform_if(ylong_path,bolyplus1, PROB_FAIR, COUNT_UNKNOWN); 1.1867 + RegionNode *r = new (C) RegionNode(3); 1.1868 + Node *phi = new (C) PhiNode(r, TypeLong::LONG); 1.1869 + r->init_req(1, _gvn.transform(new (C) IfFalseNode(ifyplus1))); 1.1870 + r->init_req(2, _gvn.transform(new (C) IfTrueNode(ifyplus1))); 1.1871 + phi->init_req(1, signnode); 1.1872 + phi->init_req(2, longcon(0)); 1.1873 + correctedsign = _gvn.transform(phi); 1.1874 + ylong_path = _gvn.transform(r); 1.1875 + record_for_igvn(r); 1.1876 + } 1.1877 + 1.1878 + // zero node 1.1879 + Node *conzero = longcon(0); 1.1880 + // Check (1&(long)y)==0? 1.1881 + Node *cmpeq1 = _gvn.transform(new (C) CmpLNode(correctedsign, conzero)); 1.1882 + // Check if (1&(long)y)!=0?, if so the result is negative 1.1883 + Node *bol3 = _gvn.transform(new (C) BoolNode( cmpeq1, BoolTest::ne )); 1.1884 + // abs(x) 1.1885 + Node *absx=_gvn.transform(new (C) AbsDNode(x)); 1.1886 + // abs(x)^y 1.1887 + Node *absxpowy = _gvn.transform(new (C) PowDNode(C, control(), absx, y)); 1.1888 + // -abs(x)^y 1.1889 + Node *negabsxpowy = _gvn.transform(new (C) NegDNode (absxpowy)); 1.1890 + // (1&(long)y)==1?-DPow(abs(x), y):DPow(abs(x), y) 1.1891 + Node *signresult = NULL; 1.1892 + if (ConditionalMoveLimit != 0) { 1.1893 + signresult = _gvn.transform( CMoveNode::make(C, NULL, bol3, absxpowy, negabsxpowy, Type::DOUBLE)); 1.1894 + } else { 1.1895 + IfNode *ifyeven = create_and_xform_if(ylong_path,bol3, PROB_FAIR, COUNT_UNKNOWN); 1.1896 + RegionNode *r = new (C) RegionNode(3); 1.1897 + Node *phi = new (C) PhiNode(r, Type::DOUBLE); 1.1898 + r->init_req(1, _gvn.transform(new (C) IfFalseNode(ifyeven))); 1.1899 + r->init_req(2, _gvn.transform(new (C) IfTrueNode(ifyeven))); 1.1900 + phi->init_req(1, absxpowy); 1.1901 + phi->init_req(2, negabsxpowy); 1.1902 + signresult = _gvn.transform(phi); 1.1903 + ylong_path = _gvn.transform(r); 1.1904 + record_for_igvn(r); 1.1905 + } 1.1906 + // Set complex path fast result 1.1907 + r->init_req(2, ylong_path); 1.1908 + phi->init_req(2, signresult); 1.1909 + 1.1910 + static const jlong nan_bits = CONST64(0x7ff8000000000000); 1.1911 + Node *slow_result = makecon(TypeD::make(*(double*)&nan_bits)); // return NaN 1.1912 + r->init_req(1,slow_path); 1.1913 + phi->init_req(1,slow_result); 1.1914 + 1.1915 + // Post merge 1.1916 + set_control(_gvn.transform(r)); 1.1917 + record_for_igvn(r); 1.1918 + result = _gvn.transform(phi); 1.1919 + } 1.1920 + 1.1921 + result = finish_pow_exp(result, x, y, OptoRuntime::Math_DD_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dpow), "POW"); 1.1922 + 1.1923 + // control from finish_pow_exp is now input to the region node 1.1924 + region_node->set_req(2, control()); 1.1925 + // the result from finish_pow_exp is now input to the phi node 1.1926 + phi_node->init_req(2, result); 1.1927 + set_control(_gvn.transform(region_node)); 1.1928 + record_for_igvn(region_node); 1.1929 + set_result(_gvn.transform(phi_node)); 1.1930 + 1.1931 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.1932 + return true; 1.1933 +} 1.1934 + 1.1935 +//------------------------------runtime_math----------------------------- 1.1936 +bool LibraryCallKit::runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName) { 1.1937 + assert(call_type == OptoRuntime::Math_DD_D_Type() || call_type == OptoRuntime::Math_D_D_Type(), 1.1938 + "must be (DD)D or (D)D type"); 1.1939 + 1.1940 + // Inputs 1.1941 + Node* a = round_double_node(argument(0)); 1.1942 + Node* b = (call_type == OptoRuntime::Math_DD_D_Type()) ? round_double_node(argument(2)) : NULL; 1.1943 + 1.1944 + const TypePtr* no_memory_effects = NULL; 1.1945 + Node* trig = make_runtime_call(RC_LEAF, call_type, funcAddr, funcName, 1.1946 + no_memory_effects, 1.1947 + a, top(), b, b ? top() : NULL); 1.1948 + Node* value = _gvn.transform(new (C) ProjNode(trig, TypeFunc::Parms+0)); 1.1949 +#ifdef ASSERT 1.1950 + Node* value_top = _gvn.transform(new (C) ProjNode(trig, TypeFunc::Parms+1)); 1.1951 + assert(value_top == top(), "second value must be top"); 1.1952 +#endif 1.1953 + 1.1954 + set_result(value); 1.1955 + return true; 1.1956 +} 1.1957 + 1.1958 +//------------------------------inline_math_native----------------------------- 1.1959 +bool LibraryCallKit::inline_math_native(vmIntrinsics::ID id) { 1.1960 +#define FN_PTR(f) CAST_FROM_FN_PTR(address, f) 1.1961 + switch (id) { 1.1962 + // These intrinsics are not properly supported on all hardware 1.1963 + case vmIntrinsics::_dcos: return Matcher::has_match_rule(Op_CosD) ? inline_trig(id) : 1.1964 + runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dcos), "COS"); 1.1965 + case vmIntrinsics::_dsin: return Matcher::has_match_rule(Op_SinD) ? inline_trig(id) : 1.1966 + runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dsin), "SIN"); 1.1967 + case vmIntrinsics::_dtan: return Matcher::has_match_rule(Op_TanD) ? inline_trig(id) : 1.1968 + runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dtan), "TAN"); 1.1969 + 1.1970 + case vmIntrinsics::_dlog: return Matcher::has_match_rule(Op_LogD) ? inline_math(id) : 1.1971 + runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dlog), "LOG"); 1.1972 + case vmIntrinsics::_dlog10: return Matcher::has_match_rule(Op_Log10D) ? inline_math(id) : 1.1973 + runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dlog10), "LOG10"); 1.1974 + 1.1975 + // These intrinsics are supported on all hardware 1.1976 + case vmIntrinsics::_dsqrt: return Matcher::match_rule_supported(Op_SqrtD) ? inline_math(id) : false; 1.1977 + case vmIntrinsics::_dabs: return Matcher::has_match_rule(Op_AbsD) ? inline_math(id) : false; 1.1978 + 1.1979 + case vmIntrinsics::_dexp: return Matcher::has_match_rule(Op_ExpD) ? inline_exp() : 1.1980 + runtime_math(OptoRuntime::Math_D_D_Type(), FN_PTR(SharedRuntime::dexp), "EXP"); 1.1981 + case vmIntrinsics::_dpow: return Matcher::has_match_rule(Op_PowD) ? inline_pow() : 1.1982 + runtime_math(OptoRuntime::Math_DD_D_Type(), FN_PTR(SharedRuntime::dpow), "POW"); 1.1983 +#undef FN_PTR 1.1984 + 1.1985 + // These intrinsics are not yet correctly implemented 1.1986 + case vmIntrinsics::_datan2: 1.1987 + return false; 1.1988 + 1.1989 + default: 1.1990 + fatal_unexpected_iid(id); 1.1991 + return false; 1.1992 + } 1.1993 +} 1.1994 + 1.1995 +static bool is_simple_name(Node* n) { 1.1996 + return (n->req() == 1 // constant 1.1997 + || (n->is_Type() && n->as_Type()->type()->singleton()) 1.1998 + || n->is_Proj() // parameter or return value 1.1999 + || n->is_Phi() // local of some sort 1.2000 + ); 1.2001 +} 1.2002 + 1.2003 +//----------------------------inline_min_max----------------------------------- 1.2004 +bool LibraryCallKit::inline_min_max(vmIntrinsics::ID id) { 1.2005 + set_result(generate_min_max(id, argument(0), argument(1))); 1.2006 + return true; 1.2007 +} 1.2008 + 1.2009 +void LibraryCallKit::inline_math_mathExact(Node* math, Node *test) { 1.2010 + Node* bol = _gvn.transform( new (C) BoolNode(test, BoolTest::overflow) ); 1.2011 + IfNode* check = create_and_map_if(control(), bol, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN); 1.2012 + Node* fast_path = _gvn.transform( new (C) IfFalseNode(check)); 1.2013 + Node* slow_path = _gvn.transform( new (C) IfTrueNode(check) ); 1.2014 + 1.2015 + { 1.2016 + PreserveJVMState pjvms(this); 1.2017 + PreserveReexecuteState preexecs(this); 1.2018 + jvms()->set_should_reexecute(true); 1.2019 + 1.2020 + set_control(slow_path); 1.2021 + set_i_o(i_o()); 1.2022 + 1.2023 + uncommon_trap(Deoptimization::Reason_intrinsic, 1.2024 + Deoptimization::Action_none); 1.2025 + } 1.2026 + 1.2027 + set_control(fast_path); 1.2028 + set_result(math); 1.2029 +} 1.2030 + 1.2031 +template <typename OverflowOp> 1.2032 +bool LibraryCallKit::inline_math_overflow(Node* arg1, Node* arg2) { 1.2033 + typedef typename OverflowOp::MathOp MathOp; 1.2034 + 1.2035 + MathOp* mathOp = new(C) MathOp(arg1, arg2); 1.2036 + Node* operation = _gvn.transform( mathOp ); 1.2037 + Node* ofcheck = _gvn.transform( new(C) OverflowOp(arg1, arg2) ); 1.2038 + inline_math_mathExact(operation, ofcheck); 1.2039 + return true; 1.2040 +} 1.2041 + 1.2042 +bool LibraryCallKit::inline_math_addExactI(bool is_increment) { 1.2043 + return inline_math_overflow<OverflowAddINode>(argument(0), is_increment ? intcon(1) : argument(1)); 1.2044 +} 1.2045 + 1.2046 +bool LibraryCallKit::inline_math_addExactL(bool is_increment) { 1.2047 + return inline_math_overflow<OverflowAddLNode>(argument(0), is_increment ? longcon(1) : argument(2)); 1.2048 +} 1.2049 + 1.2050 +bool LibraryCallKit::inline_math_subtractExactI(bool is_decrement) { 1.2051 + return inline_math_overflow<OverflowSubINode>(argument(0), is_decrement ? intcon(1) : argument(1)); 1.2052 +} 1.2053 + 1.2054 +bool LibraryCallKit::inline_math_subtractExactL(bool is_decrement) { 1.2055 + return inline_math_overflow<OverflowSubLNode>(argument(0), is_decrement ? longcon(1) : argument(2)); 1.2056 +} 1.2057 + 1.2058 +bool LibraryCallKit::inline_math_negateExactI() { 1.2059 + return inline_math_overflow<OverflowSubINode>(intcon(0), argument(0)); 1.2060 +} 1.2061 + 1.2062 +bool LibraryCallKit::inline_math_negateExactL() { 1.2063 + return inline_math_overflow<OverflowSubLNode>(longcon(0), argument(0)); 1.2064 +} 1.2065 + 1.2066 +bool LibraryCallKit::inline_math_multiplyExactI() { 1.2067 + return inline_math_overflow<OverflowMulINode>(argument(0), argument(1)); 1.2068 +} 1.2069 + 1.2070 +bool LibraryCallKit::inline_math_multiplyExactL() { 1.2071 + return inline_math_overflow<OverflowMulLNode>(argument(0), argument(2)); 1.2072 +} 1.2073 + 1.2074 +Node* 1.2075 +LibraryCallKit::generate_min_max(vmIntrinsics::ID id, Node* x0, Node* y0) { 1.2076 + // These are the candidate return value: 1.2077 + Node* xvalue = x0; 1.2078 + Node* yvalue = y0; 1.2079 + 1.2080 + if (xvalue == yvalue) { 1.2081 + return xvalue; 1.2082 + } 1.2083 + 1.2084 + bool want_max = (id == vmIntrinsics::_max); 1.2085 + 1.2086 + const TypeInt* txvalue = _gvn.type(xvalue)->isa_int(); 1.2087 + const TypeInt* tyvalue = _gvn.type(yvalue)->isa_int(); 1.2088 + if (txvalue == NULL || tyvalue == NULL) return top(); 1.2089 + // This is not really necessary, but it is consistent with a 1.2090 + // hypothetical MaxINode::Value method: 1.2091 + int widen = MAX2(txvalue->_widen, tyvalue->_widen); 1.2092 + 1.2093 + // %%% This folding logic should (ideally) be in a different place. 1.2094 + // Some should be inside IfNode, and there to be a more reliable 1.2095 + // transformation of ?: style patterns into cmoves. We also want 1.2096 + // more powerful optimizations around cmove and min/max. 1.2097 + 1.2098 + // Try to find a dominating comparison of these guys. 1.2099 + // It can simplify the index computation for Arrays.copyOf 1.2100 + // and similar uses of System.arraycopy. 1.2101 + // First, compute the normalized version of CmpI(x, y). 1.2102 + int cmp_op = Op_CmpI; 1.2103 + Node* xkey = xvalue; 1.2104 + Node* ykey = yvalue; 1.2105 + Node* ideal_cmpxy = _gvn.transform(new(C) CmpINode(xkey, ykey)); 1.2106 + if (ideal_cmpxy->is_Cmp()) { 1.2107 + // E.g., if we have CmpI(length - offset, count), 1.2108 + // it might idealize to CmpI(length, count + offset) 1.2109 + cmp_op = ideal_cmpxy->Opcode(); 1.2110 + xkey = ideal_cmpxy->in(1); 1.2111 + ykey = ideal_cmpxy->in(2); 1.2112 + } 1.2113 + 1.2114 + // Start by locating any relevant comparisons. 1.2115 + Node* start_from = (xkey->outcnt() < ykey->outcnt()) ? xkey : ykey; 1.2116 + Node* cmpxy = NULL; 1.2117 + Node* cmpyx = NULL; 1.2118 + for (DUIterator_Fast kmax, k = start_from->fast_outs(kmax); k < kmax; k++) { 1.2119 + Node* cmp = start_from->fast_out(k); 1.2120 + if (cmp->outcnt() > 0 && // must have prior uses 1.2121 + cmp->in(0) == NULL && // must be context-independent 1.2122 + cmp->Opcode() == cmp_op) { // right kind of compare 1.2123 + if (cmp->in(1) == xkey && cmp->in(2) == ykey) cmpxy = cmp; 1.2124 + if (cmp->in(1) == ykey && cmp->in(2) == xkey) cmpyx = cmp; 1.2125 + } 1.2126 + } 1.2127 + 1.2128 + const int NCMPS = 2; 1.2129 + Node* cmps[NCMPS] = { cmpxy, cmpyx }; 1.2130 + int cmpn; 1.2131 + for (cmpn = 0; cmpn < NCMPS; cmpn++) { 1.2132 + if (cmps[cmpn] != NULL) break; // find a result 1.2133 + } 1.2134 + if (cmpn < NCMPS) { 1.2135 + // Look for a dominating test that tells us the min and max. 1.2136 + int depth = 0; // Limit search depth for speed 1.2137 + Node* dom = control(); 1.2138 + for (; dom != NULL; dom = IfNode::up_one_dom(dom, true)) { 1.2139 + if (++depth >= 100) break; 1.2140 + Node* ifproj = dom; 1.2141 + if (!ifproj->is_Proj()) continue; 1.2142 + Node* iff = ifproj->in(0); 1.2143 + if (!iff->is_If()) continue; 1.2144 + Node* bol = iff->in(1); 1.2145 + if (!bol->is_Bool()) continue; 1.2146 + Node* cmp = bol->in(1); 1.2147 + if (cmp == NULL) continue; 1.2148 + for (cmpn = 0; cmpn < NCMPS; cmpn++) 1.2149 + if (cmps[cmpn] == cmp) break; 1.2150 + if (cmpn == NCMPS) continue; 1.2151 + BoolTest::mask btest = bol->as_Bool()->_test._test; 1.2152 + if (ifproj->is_IfFalse()) btest = BoolTest(btest).negate(); 1.2153 + if (cmp->in(1) == ykey) btest = BoolTest(btest).commute(); 1.2154 + // At this point, we know that 'x btest y' is true. 1.2155 + switch (btest) { 1.2156 + case BoolTest::eq: 1.2157 + // They are proven equal, so we can collapse the min/max. 1.2158 + // Either value is the answer. Choose the simpler. 1.2159 + if (is_simple_name(yvalue) && !is_simple_name(xvalue)) 1.2160 + return yvalue; 1.2161 + return xvalue; 1.2162 + case BoolTest::lt: // x < y 1.2163 + case BoolTest::le: // x <= y 1.2164 + return (want_max ? yvalue : xvalue); 1.2165 + case BoolTest::gt: // x > y 1.2166 + case BoolTest::ge: // x >= y 1.2167 + return (want_max ? xvalue : yvalue); 1.2168 + } 1.2169 + } 1.2170 + } 1.2171 + 1.2172 + // We failed to find a dominating test. 1.2173 + // Let's pick a test that might GVN with prior tests. 1.2174 + Node* best_bol = NULL; 1.2175 + BoolTest::mask best_btest = BoolTest::illegal; 1.2176 + for (cmpn = 0; cmpn < NCMPS; cmpn++) { 1.2177 + Node* cmp = cmps[cmpn]; 1.2178 + if (cmp == NULL) continue; 1.2179 + for (DUIterator_Fast jmax, j = cmp->fast_outs(jmax); j < jmax; j++) { 1.2180 + Node* bol = cmp->fast_out(j); 1.2181 + if (!bol->is_Bool()) continue; 1.2182 + BoolTest::mask btest = bol->as_Bool()->_test._test; 1.2183 + if (btest == BoolTest::eq || btest == BoolTest::ne) continue; 1.2184 + if (cmp->in(1) == ykey) btest = BoolTest(btest).commute(); 1.2185 + if (bol->outcnt() > (best_bol == NULL ? 0 : best_bol->outcnt())) { 1.2186 + best_bol = bol->as_Bool(); 1.2187 + best_btest = btest; 1.2188 + } 1.2189 + } 1.2190 + } 1.2191 + 1.2192 + Node* answer_if_true = NULL; 1.2193 + Node* answer_if_false = NULL; 1.2194 + switch (best_btest) { 1.2195 + default: 1.2196 + if (cmpxy == NULL) 1.2197 + cmpxy = ideal_cmpxy; 1.2198 + best_bol = _gvn.transform(new(C) BoolNode(cmpxy, BoolTest::lt)); 1.2199 + // and fall through: 1.2200 + case BoolTest::lt: // x < y 1.2201 + case BoolTest::le: // x <= y 1.2202 + answer_if_true = (want_max ? yvalue : xvalue); 1.2203 + answer_if_false = (want_max ? xvalue : yvalue); 1.2204 + break; 1.2205 + case BoolTest::gt: // x > y 1.2206 + case BoolTest::ge: // x >= y 1.2207 + answer_if_true = (want_max ? xvalue : yvalue); 1.2208 + answer_if_false = (want_max ? yvalue : xvalue); 1.2209 + break; 1.2210 + } 1.2211 + 1.2212 + jint hi, lo; 1.2213 + if (want_max) { 1.2214 + // We can sharpen the minimum. 1.2215 + hi = MAX2(txvalue->_hi, tyvalue->_hi); 1.2216 + lo = MAX2(txvalue->_lo, tyvalue->_lo); 1.2217 + } else { 1.2218 + // We can sharpen the maximum. 1.2219 + hi = MIN2(txvalue->_hi, tyvalue->_hi); 1.2220 + lo = MIN2(txvalue->_lo, tyvalue->_lo); 1.2221 + } 1.2222 + 1.2223 + // Use a flow-free graph structure, to avoid creating excess control edges 1.2224 + // which could hinder other optimizations. 1.2225 + // Since Math.min/max is often used with arraycopy, we want 1.2226 + // tightly_coupled_allocation to be able to see beyond min/max expressions. 1.2227 + Node* cmov = CMoveNode::make(C, NULL, best_bol, 1.2228 + answer_if_false, answer_if_true, 1.2229 + TypeInt::make(lo, hi, widen)); 1.2230 + 1.2231 + return _gvn.transform(cmov); 1.2232 + 1.2233 + /* 1.2234 + // This is not as desirable as it may seem, since Min and Max 1.2235 + // nodes do not have a full set of optimizations. 1.2236 + // And they would interfere, anyway, with 'if' optimizations 1.2237 + // and with CMoveI canonical forms. 1.2238 + switch (id) { 1.2239 + case vmIntrinsics::_min: 1.2240 + result_val = _gvn.transform(new (C, 3) MinINode(x,y)); break; 1.2241 + case vmIntrinsics::_max: 1.2242 + result_val = _gvn.transform(new (C, 3) MaxINode(x,y)); break; 1.2243 + default: 1.2244 + ShouldNotReachHere(); 1.2245 + } 1.2246 + */ 1.2247 +} 1.2248 + 1.2249 +inline int 1.2250 +LibraryCallKit::classify_unsafe_addr(Node* &base, Node* &offset) { 1.2251 + const TypePtr* base_type = TypePtr::NULL_PTR; 1.2252 + if (base != NULL) base_type = _gvn.type(base)->isa_ptr(); 1.2253 + if (base_type == NULL) { 1.2254 + // Unknown type. 1.2255 + return Type::AnyPtr; 1.2256 + } else if (base_type == TypePtr::NULL_PTR) { 1.2257 + // Since this is a NULL+long form, we have to switch to a rawptr. 1.2258 + base = _gvn.transform(new (C) CastX2PNode(offset)); 1.2259 + offset = MakeConX(0); 1.2260 + return Type::RawPtr; 1.2261 + } else if (base_type->base() == Type::RawPtr) { 1.2262 + return Type::RawPtr; 1.2263 + } else if (base_type->isa_oopptr()) { 1.2264 + // Base is never null => always a heap address. 1.2265 + if (base_type->ptr() == TypePtr::NotNull) { 1.2266 + return Type::OopPtr; 1.2267 + } 1.2268 + // Offset is small => always a heap address. 1.2269 + const TypeX* offset_type = _gvn.type(offset)->isa_intptr_t(); 1.2270 + if (offset_type != NULL && 1.2271 + base_type->offset() == 0 && // (should always be?) 1.2272 + offset_type->_lo >= 0 && 1.2273 + !MacroAssembler::needs_explicit_null_check(offset_type->_hi)) { 1.2274 + return Type::OopPtr; 1.2275 + } 1.2276 + // Otherwise, it might either be oop+off or NULL+addr. 1.2277 + return Type::AnyPtr; 1.2278 + } else { 1.2279 + // No information: 1.2280 + return Type::AnyPtr; 1.2281 + } 1.2282 +} 1.2283 + 1.2284 +inline Node* LibraryCallKit::make_unsafe_address(Node* base, Node* offset) { 1.2285 + int kind = classify_unsafe_addr(base, offset); 1.2286 + if (kind == Type::RawPtr) { 1.2287 + return basic_plus_adr(top(), base, offset); 1.2288 + } else { 1.2289 + return basic_plus_adr(base, offset); 1.2290 + } 1.2291 +} 1.2292 + 1.2293 +//--------------------------inline_number_methods----------------------------- 1.2294 +// inline int Integer.numberOfLeadingZeros(int) 1.2295 +// inline int Long.numberOfLeadingZeros(long) 1.2296 +// 1.2297 +// inline int Integer.numberOfTrailingZeros(int) 1.2298 +// inline int Long.numberOfTrailingZeros(long) 1.2299 +// 1.2300 +// inline int Integer.bitCount(int) 1.2301 +// inline int Long.bitCount(long) 1.2302 +// 1.2303 +// inline char Character.reverseBytes(char) 1.2304 +// inline short Short.reverseBytes(short) 1.2305 +// inline int Integer.reverseBytes(int) 1.2306 +// inline long Long.reverseBytes(long) 1.2307 +bool LibraryCallKit::inline_number_methods(vmIntrinsics::ID id) { 1.2308 + Node* arg = argument(0); 1.2309 + Node* n; 1.2310 + switch (id) { 1.2311 + case vmIntrinsics::_numberOfLeadingZeros_i: n = new (C) CountLeadingZerosINode( arg); break; 1.2312 + case vmIntrinsics::_numberOfLeadingZeros_l: n = new (C) CountLeadingZerosLNode( arg); break; 1.2313 + case vmIntrinsics::_numberOfTrailingZeros_i: n = new (C) CountTrailingZerosINode(arg); break; 1.2314 + case vmIntrinsics::_numberOfTrailingZeros_l: n = new (C) CountTrailingZerosLNode(arg); break; 1.2315 + case vmIntrinsics::_bitCount_i: n = new (C) PopCountINode( arg); break; 1.2316 + case vmIntrinsics::_bitCount_l: n = new (C) PopCountLNode( arg); break; 1.2317 + case vmIntrinsics::_reverseBytes_c: n = new (C) ReverseBytesUSNode(0, arg); break; 1.2318 + case vmIntrinsics::_reverseBytes_s: n = new (C) ReverseBytesSNode( 0, arg); break; 1.2319 + case vmIntrinsics::_reverseBytes_i: n = new (C) ReverseBytesINode( 0, arg); break; 1.2320 + case vmIntrinsics::_reverseBytes_l: n = new (C) ReverseBytesLNode( 0, arg); break; 1.2321 + default: fatal_unexpected_iid(id); break; 1.2322 + } 1.2323 + set_result(_gvn.transform(n)); 1.2324 + return true; 1.2325 +} 1.2326 + 1.2327 +//----------------------------inline_unsafe_access---------------------------- 1.2328 + 1.2329 +const static BasicType T_ADDRESS_HOLDER = T_LONG; 1.2330 + 1.2331 +// Helper that guards and inserts a pre-barrier. 1.2332 +void LibraryCallKit::insert_pre_barrier(Node* base_oop, Node* offset, 1.2333 + Node* pre_val, bool need_mem_bar) { 1.2334 + // We could be accessing the referent field of a reference object. If so, when G1 1.2335 + // is enabled, we need to log the value in the referent field in an SATB buffer. 1.2336 + // This routine performs some compile time filters and generates suitable 1.2337 + // runtime filters that guard the pre-barrier code. 1.2338 + // Also add memory barrier for non volatile load from the referent field 1.2339 + // to prevent commoning of loads across safepoint. 1.2340 + if (!UseG1GC && !need_mem_bar) 1.2341 + return; 1.2342 + 1.2343 + // Some compile time checks. 1.2344 + 1.2345 + // If offset is a constant, is it java_lang_ref_Reference::_reference_offset? 1.2346 + const TypeX* otype = offset->find_intptr_t_type(); 1.2347 + if (otype != NULL && otype->is_con() && 1.2348 + otype->get_con() != java_lang_ref_Reference::referent_offset) { 1.2349 + // Constant offset but not the reference_offset so just return 1.2350 + return; 1.2351 + } 1.2352 + 1.2353 + // We only need to generate the runtime guards for instances. 1.2354 + const TypeOopPtr* btype = base_oop->bottom_type()->isa_oopptr(); 1.2355 + if (btype != NULL) { 1.2356 + if (btype->isa_aryptr()) { 1.2357 + // Array type so nothing to do 1.2358 + return; 1.2359 + } 1.2360 + 1.2361 + const TypeInstPtr* itype = btype->isa_instptr(); 1.2362 + if (itype != NULL) { 1.2363 + // Can the klass of base_oop be statically determined to be 1.2364 + // _not_ a sub-class of Reference and _not_ Object? 1.2365 + ciKlass* klass = itype->klass(); 1.2366 + if ( klass->is_loaded() && 1.2367 + !klass->is_subtype_of(env()->Reference_klass()) && 1.2368 + !env()->Object_klass()->is_subtype_of(klass)) { 1.2369 + return; 1.2370 + } 1.2371 + } 1.2372 + } 1.2373 + 1.2374 + // The compile time filters did not reject base_oop/offset so 1.2375 + // we need to generate the following runtime filters 1.2376 + // 1.2377 + // if (offset == java_lang_ref_Reference::_reference_offset) { 1.2378 + // if (instance_of(base, java.lang.ref.Reference)) { 1.2379 + // pre_barrier(_, pre_val, ...); 1.2380 + // } 1.2381 + // } 1.2382 + 1.2383 + float likely = PROB_LIKELY( 0.999); 1.2384 + float unlikely = PROB_UNLIKELY(0.999); 1.2385 + 1.2386 + IdealKit ideal(this); 1.2387 +#define __ ideal. 1.2388 + 1.2389 + Node* referent_off = __ ConX(java_lang_ref_Reference::referent_offset); 1.2390 + 1.2391 + __ if_then(offset, BoolTest::eq, referent_off, unlikely); { 1.2392 + // Update graphKit memory and control from IdealKit. 1.2393 + sync_kit(ideal); 1.2394 + 1.2395 + Node* ref_klass_con = makecon(TypeKlassPtr::make(env()->Reference_klass())); 1.2396 + Node* is_instof = gen_instanceof(base_oop, ref_klass_con); 1.2397 + 1.2398 + // Update IdealKit memory and control from graphKit. 1.2399 + __ sync_kit(this); 1.2400 + 1.2401 + Node* one = __ ConI(1); 1.2402 + // is_instof == 0 if base_oop == NULL 1.2403 + __ if_then(is_instof, BoolTest::eq, one, unlikely); { 1.2404 + 1.2405 + // Update graphKit from IdeakKit. 1.2406 + sync_kit(ideal); 1.2407 + 1.2408 + // Use the pre-barrier to record the value in the referent field 1.2409 + pre_barrier(false /* do_load */, 1.2410 + __ ctrl(), 1.2411 + NULL /* obj */, NULL /* adr */, max_juint /* alias_idx */, NULL /* val */, NULL /* val_type */, 1.2412 + pre_val /* pre_val */, 1.2413 + T_OBJECT); 1.2414 + if (need_mem_bar) { 1.2415 + // Add memory barrier to prevent commoning reads from this field 1.2416 + // across safepoint since GC can change its value. 1.2417 + insert_mem_bar(Op_MemBarCPUOrder); 1.2418 + } 1.2419 + // Update IdealKit from graphKit. 1.2420 + __ sync_kit(this); 1.2421 + 1.2422 + } __ end_if(); // _ref_type != ref_none 1.2423 + } __ end_if(); // offset == referent_offset 1.2424 + 1.2425 + // Final sync IdealKit and GraphKit. 1.2426 + final_sync(ideal); 1.2427 +#undef __ 1.2428 +} 1.2429 + 1.2430 + 1.2431 +// Interpret Unsafe.fieldOffset cookies correctly: 1.2432 +extern jlong Unsafe_field_offset_to_byte_offset(jlong field_offset); 1.2433 + 1.2434 +const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type, bool is_native_ptr) { 1.2435 + // Attempt to infer a sharper value type from the offset and base type. 1.2436 + ciKlass* sharpened_klass = NULL; 1.2437 + 1.2438 + // See if it is an instance field, with an object type. 1.2439 + if (alias_type->field() != NULL) { 1.2440 + assert(!is_native_ptr, "native pointer op cannot use a java address"); 1.2441 + if (alias_type->field()->type()->is_klass()) { 1.2442 + sharpened_klass = alias_type->field()->type()->as_klass(); 1.2443 + } 1.2444 + } 1.2445 + 1.2446 + // See if it is a narrow oop array. 1.2447 + if (adr_type->isa_aryptr()) { 1.2448 + if (adr_type->offset() >= objArrayOopDesc::base_offset_in_bytes()) { 1.2449 + const TypeOopPtr *elem_type = adr_type->is_aryptr()->elem()->isa_oopptr(); 1.2450 + if (elem_type != NULL) { 1.2451 + sharpened_klass = elem_type->klass(); 1.2452 + } 1.2453 + } 1.2454 + } 1.2455 + 1.2456 + // The sharpened class might be unloaded if there is no class loader 1.2457 + // contraint in place. 1.2458 + if (sharpened_klass != NULL && sharpened_klass->is_loaded()) { 1.2459 + const TypeOopPtr* tjp = TypeOopPtr::make_from_klass(sharpened_klass); 1.2460 + 1.2461 +#ifndef PRODUCT 1.2462 + if (C->print_intrinsics() || C->print_inlining()) { 1.2463 + tty->print(" from base type: "); adr_type->dump(); 1.2464 + tty->print(" sharpened value: "); tjp->dump(); 1.2465 + } 1.2466 +#endif 1.2467 + // Sharpen the value type. 1.2468 + return tjp; 1.2469 + } 1.2470 + return NULL; 1.2471 +} 1.2472 + 1.2473 +bool LibraryCallKit::inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile) { 1.2474 + if (callee()->is_static()) return false; // caller must have the capability! 1.2475 + 1.2476 +#ifndef PRODUCT 1.2477 + { 1.2478 + ResourceMark rm; 1.2479 + // Check the signatures. 1.2480 + ciSignature* sig = callee()->signature(); 1.2481 +#ifdef ASSERT 1.2482 + if (!is_store) { 1.2483 + // Object getObject(Object base, int/long offset), etc. 1.2484 + BasicType rtype = sig->return_type()->basic_type(); 1.2485 + if (rtype == T_ADDRESS_HOLDER && callee()->name() == ciSymbol::getAddress_name()) 1.2486 + rtype = T_ADDRESS; // it is really a C void* 1.2487 + assert(rtype == type, "getter must return the expected value"); 1.2488 + if (!is_native_ptr) { 1.2489 + assert(sig->count() == 2, "oop getter has 2 arguments"); 1.2490 + assert(sig->type_at(0)->basic_type() == T_OBJECT, "getter base is object"); 1.2491 + assert(sig->type_at(1)->basic_type() == T_LONG, "getter offset is correct"); 1.2492 + } else { 1.2493 + assert(sig->count() == 1, "native getter has 1 argument"); 1.2494 + assert(sig->type_at(0)->basic_type() == T_LONG, "getter base is long"); 1.2495 + } 1.2496 + } else { 1.2497 + // void putObject(Object base, int/long offset, Object x), etc. 1.2498 + assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value"); 1.2499 + if (!is_native_ptr) { 1.2500 + assert(sig->count() == 3, "oop putter has 3 arguments"); 1.2501 + assert(sig->type_at(0)->basic_type() == T_OBJECT, "putter base is object"); 1.2502 + assert(sig->type_at(1)->basic_type() == T_LONG, "putter offset is correct"); 1.2503 + } else { 1.2504 + assert(sig->count() == 2, "native putter has 2 arguments"); 1.2505 + assert(sig->type_at(0)->basic_type() == T_LONG, "putter base is long"); 1.2506 + } 1.2507 + BasicType vtype = sig->type_at(sig->count()-1)->basic_type(); 1.2508 + if (vtype == T_ADDRESS_HOLDER && callee()->name() == ciSymbol::putAddress_name()) 1.2509 + vtype = T_ADDRESS; // it is really a C void* 1.2510 + assert(vtype == type, "putter must accept the expected value"); 1.2511 + } 1.2512 +#endif // ASSERT 1.2513 + } 1.2514 +#endif //PRODUCT 1.2515 + 1.2516 + C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 1.2517 + 1.2518 + Node* receiver = argument(0); // type: oop 1.2519 + 1.2520 + // Build address expression. See the code in inline_unsafe_prefetch. 1.2521 + Node* adr; 1.2522 + Node* heap_base_oop = top(); 1.2523 + Node* offset = top(); 1.2524 + Node* val; 1.2525 + 1.2526 + if (!is_native_ptr) { 1.2527 + // The base is either a Java object or a value produced by Unsafe.staticFieldBase 1.2528 + Node* base = argument(1); // type: oop 1.2529 + // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset 1.2530 + offset = argument(2); // type: long 1.2531 + // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 1.2532 + // to be plain byte offsets, which are also the same as those accepted 1.2533 + // by oopDesc::field_base. 1.2534 + assert(Unsafe_field_offset_to_byte_offset(11) == 11, 1.2535 + "fieldOffset must be byte-scaled"); 1.2536 + // 32-bit machines ignore the high half! 1.2537 + offset = ConvL2X(offset); 1.2538 + adr = make_unsafe_address(base, offset); 1.2539 + heap_base_oop = base; 1.2540 + val = is_store ? argument(4) : NULL; 1.2541 + } else { 1.2542 + Node* ptr = argument(1); // type: long 1.2543 + ptr = ConvL2X(ptr); // adjust Java long to machine word 1.2544 + adr = make_unsafe_address(NULL, ptr); 1.2545 + val = is_store ? argument(3) : NULL; 1.2546 + } 1.2547 + 1.2548 + const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); 1.2549 + 1.2550 + // First guess at the value type. 1.2551 + const Type *value_type = Type::get_const_basic_type(type); 1.2552 + 1.2553 + // Try to categorize the address. If it comes up as TypeJavaPtr::BOTTOM, 1.2554 + // there was not enough information to nail it down. 1.2555 + Compile::AliasType* alias_type = C->alias_type(adr_type); 1.2556 + assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here"); 1.2557 + 1.2558 + // We will need memory barriers unless we can determine a unique 1.2559 + // alias category for this reference. (Note: If for some reason 1.2560 + // the barriers get omitted and the unsafe reference begins to "pollute" 1.2561 + // the alias analysis of the rest of the graph, either Compile::can_alias 1.2562 + // or Compile::must_alias will throw a diagnostic assert.) 1.2563 + bool need_mem_bar = (alias_type->adr_type() == TypeOopPtr::BOTTOM); 1.2564 + 1.2565 + // If we are reading the value of the referent field of a Reference 1.2566 + // object (either by using Unsafe directly or through reflection) 1.2567 + // then, if G1 is enabled, we need to record the referent in an 1.2568 + // SATB log buffer using the pre-barrier mechanism. 1.2569 + // Also we need to add memory barrier to prevent commoning reads 1.2570 + // from this field across safepoint since GC can change its value. 1.2571 + bool need_read_barrier = !is_native_ptr && !is_store && 1.2572 + offset != top() && heap_base_oop != top(); 1.2573 + 1.2574 + if (!is_store && type == T_OBJECT) { 1.2575 + const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type, is_native_ptr); 1.2576 + if (tjp != NULL) { 1.2577 + value_type = tjp; 1.2578 + } 1.2579 + } 1.2580 + 1.2581 + receiver = null_check(receiver); 1.2582 + if (stopped()) { 1.2583 + return true; 1.2584 + } 1.2585 + // Heap pointers get a null-check from the interpreter, 1.2586 + // as a courtesy. However, this is not guaranteed by Unsafe, 1.2587 + // and it is not possible to fully distinguish unintended nulls 1.2588 + // from intended ones in this API. 1.2589 + 1.2590 + if (is_volatile) { 1.2591 + // We need to emit leading and trailing CPU membars (see below) in 1.2592 + // addition to memory membars when is_volatile. This is a little 1.2593 + // too strong, but avoids the need to insert per-alias-type 1.2594 + // volatile membars (for stores; compare Parse::do_put_xxx), which 1.2595 + // we cannot do effectively here because we probably only have a 1.2596 + // rough approximation of type. 1.2597 + need_mem_bar = true; 1.2598 + // For Stores, place a memory ordering barrier now. 1.2599 + if (is_store) { 1.2600 + insert_mem_bar(Op_MemBarRelease); 1.2601 + } else { 1.2602 + if (support_IRIW_for_not_multiple_copy_atomic_cpu) { 1.2603 + insert_mem_bar(Op_MemBarVolatile); 1.2604 + } 1.2605 + } 1.2606 + } 1.2607 + 1.2608 + // Memory barrier to prevent normal and 'unsafe' accesses from 1.2609 + // bypassing each other. Happens after null checks, so the 1.2610 + // exception paths do not take memory state from the memory barrier, 1.2611 + // so there's no problems making a strong assert about mixing users 1.2612 + // of safe & unsafe memory. Otherwise fails in a CTW of rt.jar 1.2613 + // around 5701, class sun/reflect/UnsafeBooleanFieldAccessorImpl. 1.2614 + if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder); 1.2615 + 1.2616 + if (!is_store) { 1.2617 + Node* p = make_load(control(), adr, value_type, type, adr_type, MemNode::unordered, is_volatile); 1.2618 + // load value 1.2619 + switch (type) { 1.2620 + case T_BOOLEAN: 1.2621 + case T_CHAR: 1.2622 + case T_BYTE: 1.2623 + case T_SHORT: 1.2624 + case T_INT: 1.2625 + case T_LONG: 1.2626 + case T_FLOAT: 1.2627 + case T_DOUBLE: 1.2628 + break; 1.2629 + case T_OBJECT: 1.2630 + if (need_read_barrier) { 1.2631 + insert_pre_barrier(heap_base_oop, offset, p, !(is_volatile || need_mem_bar)); 1.2632 + } 1.2633 + break; 1.2634 + case T_ADDRESS: 1.2635 + // Cast to an int type. 1.2636 + p = _gvn.transform(new (C) CastP2XNode(NULL, p)); 1.2637 + p = ConvX2UL(p); 1.2638 + break; 1.2639 + default: 1.2640 + fatal(err_msg_res("unexpected type %d: %s", type, type2name(type))); 1.2641 + break; 1.2642 + } 1.2643 + // The load node has the control of the preceding MemBarCPUOrder. All 1.2644 + // following nodes will have the control of the MemBarCPUOrder inserted at 1.2645 + // the end of this method. So, pushing the load onto the stack at a later 1.2646 + // point is fine. 1.2647 + set_result(p); 1.2648 + } else { 1.2649 + // place effect of store into memory 1.2650 + switch (type) { 1.2651 + case T_DOUBLE: 1.2652 + val = dstore_rounding(val); 1.2653 + break; 1.2654 + case T_ADDRESS: 1.2655 + // Repackage the long as a pointer. 1.2656 + val = ConvL2X(val); 1.2657 + val = _gvn.transform(new (C) CastX2PNode(val)); 1.2658 + break; 1.2659 + } 1.2660 + 1.2661 + MemNode::MemOrd mo = is_volatile ? MemNode::release : MemNode::unordered; 1.2662 + if (type != T_OBJECT ) { 1.2663 + (void) store_to_memory(control(), adr, val, type, adr_type, mo, is_volatile); 1.2664 + } else { 1.2665 + // Possibly an oop being stored to Java heap or native memory 1.2666 + if (!TypePtr::NULL_PTR->higher_equal(_gvn.type(heap_base_oop))) { 1.2667 + // oop to Java heap. 1.2668 + (void) store_oop_to_unknown(control(), heap_base_oop, adr, adr_type, val, type, mo); 1.2669 + } else { 1.2670 + // We can't tell at compile time if we are storing in the Java heap or outside 1.2671 + // of it. So we need to emit code to conditionally do the proper type of 1.2672 + // store. 1.2673 + 1.2674 + IdealKit ideal(this); 1.2675 +#define __ ideal. 1.2676 + // QQQ who knows what probability is here?? 1.2677 + __ if_then(heap_base_oop, BoolTest::ne, null(), PROB_UNLIKELY(0.999)); { 1.2678 + // Sync IdealKit and graphKit. 1.2679 + sync_kit(ideal); 1.2680 + Node* st = store_oop_to_unknown(control(), heap_base_oop, adr, adr_type, val, type, mo); 1.2681 + // Update IdealKit memory. 1.2682 + __ sync_kit(this); 1.2683 + } __ else_(); { 1.2684 + __ store(__ ctrl(), adr, val, type, alias_type->index(), mo, is_volatile); 1.2685 + } __ end_if(); 1.2686 + // Final sync IdealKit and GraphKit. 1.2687 + final_sync(ideal); 1.2688 +#undef __ 1.2689 + } 1.2690 + } 1.2691 + } 1.2692 + 1.2693 + if (is_volatile) { 1.2694 + if (!is_store) { 1.2695 + insert_mem_bar(Op_MemBarAcquire); 1.2696 + } else { 1.2697 + if (!support_IRIW_for_not_multiple_copy_atomic_cpu) { 1.2698 + insert_mem_bar(Op_MemBarVolatile); 1.2699 + } 1.2700 + } 1.2701 + } 1.2702 + 1.2703 + if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder); 1.2704 + 1.2705 + return true; 1.2706 +} 1.2707 + 1.2708 +//----------------------------inline_unsafe_prefetch---------------------------- 1.2709 + 1.2710 +bool LibraryCallKit::inline_unsafe_prefetch(bool is_native_ptr, bool is_store, bool is_static) { 1.2711 +#ifndef PRODUCT 1.2712 + { 1.2713 + ResourceMark rm; 1.2714 + // Check the signatures. 1.2715 + ciSignature* sig = callee()->signature(); 1.2716 +#ifdef ASSERT 1.2717 + // Object getObject(Object base, int/long offset), etc. 1.2718 + BasicType rtype = sig->return_type()->basic_type(); 1.2719 + if (!is_native_ptr) { 1.2720 + assert(sig->count() == 2, "oop prefetch has 2 arguments"); 1.2721 + assert(sig->type_at(0)->basic_type() == T_OBJECT, "prefetch base is object"); 1.2722 + assert(sig->type_at(1)->basic_type() == T_LONG, "prefetcha offset is correct"); 1.2723 + } else { 1.2724 + assert(sig->count() == 1, "native prefetch has 1 argument"); 1.2725 + assert(sig->type_at(0)->basic_type() == T_LONG, "prefetch base is long"); 1.2726 + } 1.2727 +#endif // ASSERT 1.2728 + } 1.2729 +#endif // !PRODUCT 1.2730 + 1.2731 + C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 1.2732 + 1.2733 + const int idx = is_static ? 0 : 1; 1.2734 + if (!is_static) { 1.2735 + null_check_receiver(); 1.2736 + if (stopped()) { 1.2737 + return true; 1.2738 + } 1.2739 + } 1.2740 + 1.2741 + // Build address expression. See the code in inline_unsafe_access. 1.2742 + Node *adr; 1.2743 + if (!is_native_ptr) { 1.2744 + // The base is either a Java object or a value produced by Unsafe.staticFieldBase 1.2745 + Node* base = argument(idx + 0); // type: oop 1.2746 + // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset 1.2747 + Node* offset = argument(idx + 1); // type: long 1.2748 + // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 1.2749 + // to be plain byte offsets, which are also the same as those accepted 1.2750 + // by oopDesc::field_base. 1.2751 + assert(Unsafe_field_offset_to_byte_offset(11) == 11, 1.2752 + "fieldOffset must be byte-scaled"); 1.2753 + // 32-bit machines ignore the high half! 1.2754 + offset = ConvL2X(offset); 1.2755 + adr = make_unsafe_address(base, offset); 1.2756 + } else { 1.2757 + Node* ptr = argument(idx + 0); // type: long 1.2758 + ptr = ConvL2X(ptr); // adjust Java long to machine word 1.2759 + adr = make_unsafe_address(NULL, ptr); 1.2760 + } 1.2761 + 1.2762 + // Generate the read or write prefetch 1.2763 + Node *prefetch; 1.2764 + if (is_store) { 1.2765 + prefetch = new (C) PrefetchWriteNode(i_o(), adr); 1.2766 + } else { 1.2767 + prefetch = new (C) PrefetchReadNode(i_o(), adr); 1.2768 + } 1.2769 + prefetch->init_req(0, control()); 1.2770 + set_i_o(_gvn.transform(prefetch)); 1.2771 + 1.2772 + return true; 1.2773 +} 1.2774 + 1.2775 +//----------------------------inline_unsafe_load_store---------------------------- 1.2776 +// This method serves a couple of different customers (depending on LoadStoreKind): 1.2777 +// 1.2778 +// LS_cmpxchg: 1.2779 +// public final native boolean compareAndSwapObject(Object o, long offset, Object expected, Object x); 1.2780 +// public final native boolean compareAndSwapInt( Object o, long offset, int expected, int x); 1.2781 +// public final native boolean compareAndSwapLong( Object o, long offset, long expected, long x); 1.2782 +// 1.2783 +// LS_xadd: 1.2784 +// public int getAndAddInt( Object o, long offset, int delta) 1.2785 +// public long getAndAddLong(Object o, long offset, long delta) 1.2786 +// 1.2787 +// LS_xchg: 1.2788 +// int getAndSet(Object o, long offset, int newValue) 1.2789 +// long getAndSet(Object o, long offset, long newValue) 1.2790 +// Object getAndSet(Object o, long offset, Object newValue) 1.2791 +// 1.2792 +bool LibraryCallKit::inline_unsafe_load_store(BasicType type, LoadStoreKind kind) { 1.2793 + // This basic scheme here is the same as inline_unsafe_access, but 1.2794 + // differs in enough details that combining them would make the code 1.2795 + // overly confusing. (This is a true fact! I originally combined 1.2796 + // them, but even I was confused by it!) As much code/comments as 1.2797 + // possible are retained from inline_unsafe_access though to make 1.2798 + // the correspondences clearer. - dl 1.2799 + 1.2800 + if (callee()->is_static()) return false; // caller must have the capability! 1.2801 + 1.2802 +#ifndef PRODUCT 1.2803 + BasicType rtype; 1.2804 + { 1.2805 + ResourceMark rm; 1.2806 + // Check the signatures. 1.2807 + ciSignature* sig = callee()->signature(); 1.2808 + rtype = sig->return_type()->basic_type(); 1.2809 + if (kind == LS_xadd || kind == LS_xchg) { 1.2810 + // Check the signatures. 1.2811 +#ifdef ASSERT 1.2812 + assert(rtype == type, "get and set must return the expected type"); 1.2813 + assert(sig->count() == 3, "get and set has 3 arguments"); 1.2814 + assert(sig->type_at(0)->basic_type() == T_OBJECT, "get and set base is object"); 1.2815 + assert(sig->type_at(1)->basic_type() == T_LONG, "get and set offset is long"); 1.2816 + assert(sig->type_at(2)->basic_type() == type, "get and set must take expected type as new value/delta"); 1.2817 +#endif // ASSERT 1.2818 + } else if (kind == LS_cmpxchg) { 1.2819 + // Check the signatures. 1.2820 +#ifdef ASSERT 1.2821 + assert(rtype == T_BOOLEAN, "CAS must return boolean"); 1.2822 + assert(sig->count() == 4, "CAS has 4 arguments"); 1.2823 + assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object"); 1.2824 + assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long"); 1.2825 +#endif // ASSERT 1.2826 + } else { 1.2827 + ShouldNotReachHere(); 1.2828 + } 1.2829 + } 1.2830 +#endif //PRODUCT 1.2831 + 1.2832 + C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 1.2833 + 1.2834 + // Get arguments: 1.2835 + Node* receiver = NULL; 1.2836 + Node* base = NULL; 1.2837 + Node* offset = NULL; 1.2838 + Node* oldval = NULL; 1.2839 + Node* newval = NULL; 1.2840 + if (kind == LS_cmpxchg) { 1.2841 + const bool two_slot_type = type2size[type] == 2; 1.2842 + receiver = argument(0); // type: oop 1.2843 + base = argument(1); // type: oop 1.2844 + offset = argument(2); // type: long 1.2845 + oldval = argument(4); // type: oop, int, or long 1.2846 + newval = argument(two_slot_type ? 6 : 5); // type: oop, int, or long 1.2847 + } else if (kind == LS_xadd || kind == LS_xchg){ 1.2848 + receiver = argument(0); // type: oop 1.2849 + base = argument(1); // type: oop 1.2850 + offset = argument(2); // type: long 1.2851 + oldval = NULL; 1.2852 + newval = argument(4); // type: oop, int, or long 1.2853 + } 1.2854 + 1.2855 + // Null check receiver. 1.2856 + receiver = null_check(receiver); 1.2857 + if (stopped()) { 1.2858 + return true; 1.2859 + } 1.2860 + 1.2861 + // Build field offset expression. 1.2862 + // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 1.2863 + // to be plain byte offsets, which are also the same as those accepted 1.2864 + // by oopDesc::field_base. 1.2865 + assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled"); 1.2866 + // 32-bit machines ignore the high half of long offsets 1.2867 + offset = ConvL2X(offset); 1.2868 + Node* adr = make_unsafe_address(base, offset); 1.2869 + const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); 1.2870 + 1.2871 + // For CAS, unlike inline_unsafe_access, there seems no point in 1.2872 + // trying to refine types. Just use the coarse types here. 1.2873 + const Type *value_type = Type::get_const_basic_type(type); 1.2874 + Compile::AliasType* alias_type = C->alias_type(adr_type); 1.2875 + assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here"); 1.2876 + 1.2877 + if (kind == LS_xchg && type == T_OBJECT) { 1.2878 + const TypeOopPtr* tjp = sharpen_unsafe_type(alias_type, adr_type); 1.2879 + if (tjp != NULL) { 1.2880 + value_type = tjp; 1.2881 + } 1.2882 + } 1.2883 + 1.2884 + int alias_idx = C->get_alias_index(adr_type); 1.2885 + 1.2886 + // Memory-model-wise, a LoadStore acts like a little synchronized 1.2887 + // block, so needs barriers on each side. These don't translate 1.2888 + // into actual barriers on most machines, but we still need rest of 1.2889 + // compiler to respect ordering. 1.2890 + 1.2891 + insert_mem_bar(Op_MemBarRelease); 1.2892 + insert_mem_bar(Op_MemBarCPUOrder); 1.2893 + 1.2894 + // 4984716: MemBars must be inserted before this 1.2895 + // memory node in order to avoid a false 1.2896 + // dependency which will confuse the scheduler. 1.2897 + Node *mem = memory(alias_idx); 1.2898 + 1.2899 + // For now, we handle only those cases that actually exist: ints, 1.2900 + // longs, and Object. Adding others should be straightforward. 1.2901 + Node* load_store; 1.2902 + switch(type) { 1.2903 + case T_INT: 1.2904 + if (kind == LS_xadd) { 1.2905 + load_store = _gvn.transform(new (C) GetAndAddINode(control(), mem, adr, newval, adr_type)); 1.2906 + } else if (kind == LS_xchg) { 1.2907 + load_store = _gvn.transform(new (C) GetAndSetINode(control(), mem, adr, newval, adr_type)); 1.2908 + } else if (kind == LS_cmpxchg) { 1.2909 + load_store = _gvn.transform(new (C) CompareAndSwapINode(control(), mem, adr, newval, oldval)); 1.2910 + } else { 1.2911 + ShouldNotReachHere(); 1.2912 + } 1.2913 + break; 1.2914 + case T_LONG: 1.2915 + if (kind == LS_xadd) { 1.2916 + load_store = _gvn.transform(new (C) GetAndAddLNode(control(), mem, adr, newval, adr_type)); 1.2917 + } else if (kind == LS_xchg) { 1.2918 + load_store = _gvn.transform(new (C) GetAndSetLNode(control(), mem, adr, newval, adr_type)); 1.2919 + } else if (kind == LS_cmpxchg) { 1.2920 + load_store = _gvn.transform(new (C) CompareAndSwapLNode(control(), mem, adr, newval, oldval)); 1.2921 + } else { 1.2922 + ShouldNotReachHere(); 1.2923 + } 1.2924 + break; 1.2925 + case T_OBJECT: 1.2926 + // Transformation of a value which could be NULL pointer (CastPP #NULL) 1.2927 + // could be delayed during Parse (for example, in adjust_map_after_if()). 1.2928 + // Execute transformation here to avoid barrier generation in such case. 1.2929 + if (_gvn.type(newval) == TypePtr::NULL_PTR) 1.2930 + newval = _gvn.makecon(TypePtr::NULL_PTR); 1.2931 + 1.2932 + // Reference stores need a store barrier. 1.2933 + if (kind == LS_xchg) { 1.2934 + // If pre-barrier must execute before the oop store, old value will require do_load here. 1.2935 + if (!can_move_pre_barrier()) { 1.2936 + pre_barrier(true /* do_load*/, 1.2937 + control(), base, adr, alias_idx, newval, value_type->make_oopptr(), 1.2938 + NULL /* pre_val*/, 1.2939 + T_OBJECT); 1.2940 + } // Else move pre_barrier to use load_store value, see below. 1.2941 + } else if (kind == LS_cmpxchg) { 1.2942 + // Same as for newval above: 1.2943 + if (_gvn.type(oldval) == TypePtr::NULL_PTR) { 1.2944 + oldval = _gvn.makecon(TypePtr::NULL_PTR); 1.2945 + } 1.2946 + // The only known value which might get overwritten is oldval. 1.2947 + pre_barrier(false /* do_load */, 1.2948 + control(), NULL, NULL, max_juint, NULL, NULL, 1.2949 + oldval /* pre_val */, 1.2950 + T_OBJECT); 1.2951 + } else { 1.2952 + ShouldNotReachHere(); 1.2953 + } 1.2954 + 1.2955 +#ifdef _LP64 1.2956 + if (adr->bottom_type()->is_ptr_to_narrowoop()) { 1.2957 + Node *newval_enc = _gvn.transform(new (C) EncodePNode(newval, newval->bottom_type()->make_narrowoop())); 1.2958 + if (kind == LS_xchg) { 1.2959 + load_store = _gvn.transform(new (C) GetAndSetNNode(control(), mem, adr, 1.2960 + newval_enc, adr_type, value_type->make_narrowoop())); 1.2961 + } else { 1.2962 + assert(kind == LS_cmpxchg, "wrong LoadStore operation"); 1.2963 + Node *oldval_enc = _gvn.transform(new (C) EncodePNode(oldval, oldval->bottom_type()->make_narrowoop())); 1.2964 + load_store = _gvn.transform(new (C) CompareAndSwapNNode(control(), mem, adr, 1.2965 + newval_enc, oldval_enc)); 1.2966 + } 1.2967 + } else 1.2968 +#endif 1.2969 + { 1.2970 + if (kind == LS_xchg) { 1.2971 + load_store = _gvn.transform(new (C) GetAndSetPNode(control(), mem, adr, newval, adr_type, value_type->is_oopptr())); 1.2972 + } else { 1.2973 + assert(kind == LS_cmpxchg, "wrong LoadStore operation"); 1.2974 + load_store = _gvn.transform(new (C) CompareAndSwapPNode(control(), mem, adr, newval, oldval)); 1.2975 + } 1.2976 + } 1.2977 + post_barrier(control(), load_store, base, adr, alias_idx, newval, T_OBJECT, true); 1.2978 + break; 1.2979 + default: 1.2980 + fatal(err_msg_res("unexpected type %d: %s", type, type2name(type))); 1.2981 + break; 1.2982 + } 1.2983 + 1.2984 + // SCMemProjNodes represent the memory state of a LoadStore. Their 1.2985 + // main role is to prevent LoadStore nodes from being optimized away 1.2986 + // when their results aren't used. 1.2987 + Node* proj = _gvn.transform(new (C) SCMemProjNode(load_store)); 1.2988 + set_memory(proj, alias_idx); 1.2989 + 1.2990 + if (type == T_OBJECT && kind == LS_xchg) { 1.2991 +#ifdef _LP64 1.2992 + if (adr->bottom_type()->is_ptr_to_narrowoop()) { 1.2993 + load_store = _gvn.transform(new (C) DecodeNNode(load_store, load_store->get_ptr_type())); 1.2994 + } 1.2995 +#endif 1.2996 + if (can_move_pre_barrier()) { 1.2997 + // Don't need to load pre_val. The old value is returned by load_store. 1.2998 + // The pre_barrier can execute after the xchg as long as no safepoint 1.2999 + // gets inserted between them. 1.3000 + pre_barrier(false /* do_load */, 1.3001 + control(), NULL, NULL, max_juint, NULL, NULL, 1.3002 + load_store /* pre_val */, 1.3003 + T_OBJECT); 1.3004 + } 1.3005 + } 1.3006 + 1.3007 + // Add the trailing membar surrounding the access 1.3008 + insert_mem_bar(Op_MemBarCPUOrder); 1.3009 + insert_mem_bar(Op_MemBarAcquire); 1.3010 + 1.3011 + assert(type2size[load_store->bottom_type()->basic_type()] == type2size[rtype], "result type should match"); 1.3012 + set_result(load_store); 1.3013 + return true; 1.3014 +} 1.3015 + 1.3016 +//----------------------------inline_unsafe_ordered_store---------------------- 1.3017 +// public native void sun.misc.Unsafe.putOrderedObject(Object o, long offset, Object x); 1.3018 +// public native void sun.misc.Unsafe.putOrderedInt(Object o, long offset, int x); 1.3019 +// public native void sun.misc.Unsafe.putOrderedLong(Object o, long offset, long x); 1.3020 +bool LibraryCallKit::inline_unsafe_ordered_store(BasicType type) { 1.3021 + // This is another variant of inline_unsafe_access, differing in 1.3022 + // that it always issues store-store ("release") barrier and ensures 1.3023 + // store-atomicity (which only matters for "long"). 1.3024 + 1.3025 + if (callee()->is_static()) return false; // caller must have the capability! 1.3026 + 1.3027 +#ifndef PRODUCT 1.3028 + { 1.3029 + ResourceMark rm; 1.3030 + // Check the signatures. 1.3031 + ciSignature* sig = callee()->signature(); 1.3032 +#ifdef ASSERT 1.3033 + BasicType rtype = sig->return_type()->basic_type(); 1.3034 + assert(rtype == T_VOID, "must return void"); 1.3035 + assert(sig->count() == 3, "has 3 arguments"); 1.3036 + assert(sig->type_at(0)->basic_type() == T_OBJECT, "base is object"); 1.3037 + assert(sig->type_at(1)->basic_type() == T_LONG, "offset is long"); 1.3038 +#endif // ASSERT 1.3039 + } 1.3040 +#endif //PRODUCT 1.3041 + 1.3042 + C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 1.3043 + 1.3044 + // Get arguments: 1.3045 + Node* receiver = argument(0); // type: oop 1.3046 + Node* base = argument(1); // type: oop 1.3047 + Node* offset = argument(2); // type: long 1.3048 + Node* val = argument(4); // type: oop, int, or long 1.3049 + 1.3050 + // Null check receiver. 1.3051 + receiver = null_check(receiver); 1.3052 + if (stopped()) { 1.3053 + return true; 1.3054 + } 1.3055 + 1.3056 + // Build field offset expression. 1.3057 + assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled"); 1.3058 + // 32-bit machines ignore the high half of long offsets 1.3059 + offset = ConvL2X(offset); 1.3060 + Node* adr = make_unsafe_address(base, offset); 1.3061 + const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); 1.3062 + const Type *value_type = Type::get_const_basic_type(type); 1.3063 + Compile::AliasType* alias_type = C->alias_type(adr_type); 1.3064 + 1.3065 + insert_mem_bar(Op_MemBarRelease); 1.3066 + insert_mem_bar(Op_MemBarCPUOrder); 1.3067 + // Ensure that the store is atomic for longs: 1.3068 + const bool require_atomic_access = true; 1.3069 + Node* store; 1.3070 + if (type == T_OBJECT) // reference stores need a store barrier. 1.3071 + store = store_oop_to_unknown(control(), base, adr, adr_type, val, type, MemNode::release); 1.3072 + else { 1.3073 + store = store_to_memory(control(), adr, val, type, adr_type, MemNode::release, require_atomic_access); 1.3074 + } 1.3075 + insert_mem_bar(Op_MemBarCPUOrder); 1.3076 + return true; 1.3077 +} 1.3078 + 1.3079 +bool LibraryCallKit::inline_unsafe_fence(vmIntrinsics::ID id) { 1.3080 + // Regardless of form, don't allow previous ld/st to move down, 1.3081 + // then issue acquire, release, or volatile mem_bar. 1.3082 + insert_mem_bar(Op_MemBarCPUOrder); 1.3083 + switch(id) { 1.3084 + case vmIntrinsics::_loadFence: 1.3085 + insert_mem_bar(Op_LoadFence); 1.3086 + return true; 1.3087 + case vmIntrinsics::_storeFence: 1.3088 + insert_mem_bar(Op_StoreFence); 1.3089 + return true; 1.3090 + case vmIntrinsics::_fullFence: 1.3091 + insert_mem_bar(Op_MemBarVolatile); 1.3092 + return true; 1.3093 + default: 1.3094 + fatal_unexpected_iid(id); 1.3095 + return false; 1.3096 + } 1.3097 +} 1.3098 + 1.3099 +bool LibraryCallKit::klass_needs_init_guard(Node* kls) { 1.3100 + if (!kls->is_Con()) { 1.3101 + return true; 1.3102 + } 1.3103 + const TypeKlassPtr* klsptr = kls->bottom_type()->isa_klassptr(); 1.3104 + if (klsptr == NULL) { 1.3105 + return true; 1.3106 + } 1.3107 + ciInstanceKlass* ik = klsptr->klass()->as_instance_klass(); 1.3108 + // don't need a guard for a klass that is already initialized 1.3109 + return !ik->is_initialized(); 1.3110 +} 1.3111 + 1.3112 +//----------------------------inline_unsafe_allocate--------------------------- 1.3113 +// public native Object sun.misc.Unsafe.allocateInstance(Class<?> cls); 1.3114 +bool LibraryCallKit::inline_unsafe_allocate() { 1.3115 + if (callee()->is_static()) return false; // caller must have the capability! 1.3116 + 1.3117 + null_check_receiver(); // null-check, then ignore 1.3118 + Node* cls = null_check(argument(1)); 1.3119 + if (stopped()) return true; 1.3120 + 1.3121 + Node* kls = load_klass_from_mirror(cls, false, NULL, 0); 1.3122 + kls = null_check(kls); 1.3123 + if (stopped()) return true; // argument was like int.class 1.3124 + 1.3125 + Node* test = NULL; 1.3126 + if (LibraryCallKit::klass_needs_init_guard(kls)) { 1.3127 + // Note: The argument might still be an illegal value like 1.3128 + // Serializable.class or Object[].class. The runtime will handle it. 1.3129 + // But we must make an explicit check for initialization. 1.3130 + Node* insp = basic_plus_adr(kls, in_bytes(InstanceKlass::init_state_offset())); 1.3131 + // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler 1.3132 + // can generate code to load it as unsigned byte. 1.3133 + Node* inst = make_load(NULL, insp, TypeInt::UBYTE, T_BOOLEAN, MemNode::unordered); 1.3134 + Node* bits = intcon(InstanceKlass::fully_initialized); 1.3135 + test = _gvn.transform(new (C) SubINode(inst, bits)); 1.3136 + // The 'test' is non-zero if we need to take a slow path. 1.3137 + } 1.3138 + 1.3139 + Node* obj = new_instance(kls, test); 1.3140 + set_result(obj); 1.3141 + return true; 1.3142 +} 1.3143 + 1.3144 +#ifdef TRACE_HAVE_INTRINSICS 1.3145 +/* 1.3146 + * oop -> myklass 1.3147 + * myklass->trace_id |= USED 1.3148 + * return myklass->trace_id & ~0x3 1.3149 + */ 1.3150 +bool LibraryCallKit::inline_native_classID() { 1.3151 + null_check_receiver(); // null-check, then ignore 1.3152 + Node* cls = null_check(argument(1), T_OBJECT); 1.3153 + Node* kls = load_klass_from_mirror(cls, false, NULL, 0); 1.3154 + kls = null_check(kls, T_OBJECT); 1.3155 + ByteSize offset = TRACE_ID_OFFSET; 1.3156 + Node* insp = basic_plus_adr(kls, in_bytes(offset)); 1.3157 + Node* tvalue = make_load(NULL, insp, TypeLong::LONG, T_LONG, MemNode::unordered); 1.3158 + Node* bits = longcon(~0x03l); // ignore bit 0 & 1 1.3159 + Node* andl = _gvn.transform(new (C) AndLNode(tvalue, bits)); 1.3160 + Node* clsused = longcon(0x01l); // set the class bit 1.3161 + Node* orl = _gvn.transform(new (C) OrLNode(tvalue, clsused)); 1.3162 + 1.3163 + const TypePtr *adr_type = _gvn.type(insp)->isa_ptr(); 1.3164 + store_to_memory(control(), insp, orl, T_LONG, adr_type, MemNode::unordered); 1.3165 + set_result(andl); 1.3166 + return true; 1.3167 +} 1.3168 + 1.3169 +bool LibraryCallKit::inline_native_threadID() { 1.3170 + Node* tls_ptr = NULL; 1.3171 + Node* cur_thr = generate_current_thread(tls_ptr); 1.3172 + Node* p = basic_plus_adr(top()/*!oop*/, tls_ptr, in_bytes(JavaThread::osthread_offset())); 1.3173 + Node* osthread = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered); 1.3174 + p = basic_plus_adr(top()/*!oop*/, osthread, in_bytes(OSThread::thread_id_offset())); 1.3175 + 1.3176 + Node* threadid = NULL; 1.3177 + size_t thread_id_size = OSThread::thread_id_size(); 1.3178 + if (thread_id_size == (size_t) BytesPerLong) { 1.3179 + threadid = ConvL2I(make_load(control(), p, TypeLong::LONG, T_LONG, MemNode::unordered)); 1.3180 + } else if (thread_id_size == (size_t) BytesPerInt) { 1.3181 + threadid = make_load(control(), p, TypeInt::INT, T_INT, MemNode::unordered); 1.3182 + } else { 1.3183 + ShouldNotReachHere(); 1.3184 + } 1.3185 + set_result(threadid); 1.3186 + return true; 1.3187 +} 1.3188 +#endif 1.3189 + 1.3190 +//------------------------inline_native_time_funcs-------------- 1.3191 +// inline code for System.currentTimeMillis() and System.nanoTime() 1.3192 +// these have the same type and signature 1.3193 +bool LibraryCallKit::inline_native_time_funcs(address funcAddr, const char* funcName) { 1.3194 + const TypeFunc* tf = OptoRuntime::void_long_Type(); 1.3195 + const TypePtr* no_memory_effects = NULL; 1.3196 + Node* time = make_runtime_call(RC_LEAF, tf, funcAddr, funcName, no_memory_effects); 1.3197 + Node* value = _gvn.transform(new (C) ProjNode(time, TypeFunc::Parms+0)); 1.3198 +#ifdef ASSERT 1.3199 + Node* value_top = _gvn.transform(new (C) ProjNode(time, TypeFunc::Parms+1)); 1.3200 + assert(value_top == top(), "second value must be top"); 1.3201 +#endif 1.3202 + set_result(value); 1.3203 + return true; 1.3204 +} 1.3205 + 1.3206 +//------------------------inline_native_currentThread------------------ 1.3207 +bool LibraryCallKit::inline_native_currentThread() { 1.3208 + Node* junk = NULL; 1.3209 + set_result(generate_current_thread(junk)); 1.3210 + return true; 1.3211 +} 1.3212 + 1.3213 +//------------------------inline_native_isInterrupted------------------ 1.3214 +// private native boolean java.lang.Thread.isInterrupted(boolean ClearInterrupted); 1.3215 +bool LibraryCallKit::inline_native_isInterrupted() { 1.3216 + // Add a fast path to t.isInterrupted(clear_int): 1.3217 + // (t == Thread.current() && 1.3218 + // (!TLS._osthread._interrupted || WINDOWS_ONLY(false) NOT_WINDOWS(!clear_int))) 1.3219 + // ? TLS._osthread._interrupted : /*slow path:*/ t.isInterrupted(clear_int) 1.3220 + // So, in the common case that the interrupt bit is false, 1.3221 + // we avoid making a call into the VM. Even if the interrupt bit 1.3222 + // is true, if the clear_int argument is false, we avoid the VM call. 1.3223 + // However, if the receiver is not currentThread, we must call the VM, 1.3224 + // because there must be some locking done around the operation. 1.3225 + 1.3226 + // We only go to the fast case code if we pass two guards. 1.3227 + // Paths which do not pass are accumulated in the slow_region. 1.3228 + 1.3229 + enum { 1.3230 + no_int_result_path = 1, // t == Thread.current() && !TLS._osthread._interrupted 1.3231 + no_clear_result_path = 2, // t == Thread.current() && TLS._osthread._interrupted && !clear_int 1.3232 + slow_result_path = 3, // slow path: t.isInterrupted(clear_int) 1.3233 + PATH_LIMIT 1.3234 + }; 1.3235 + 1.3236 + // Ensure that it's not possible to move the load of TLS._osthread._interrupted flag 1.3237 + // out of the function. 1.3238 + insert_mem_bar(Op_MemBarCPUOrder); 1.3239 + 1.3240 + RegionNode* result_rgn = new (C) RegionNode(PATH_LIMIT); 1.3241 + PhiNode* result_val = new (C) PhiNode(result_rgn, TypeInt::BOOL); 1.3242 + 1.3243 + RegionNode* slow_region = new (C) RegionNode(1); 1.3244 + record_for_igvn(slow_region); 1.3245 + 1.3246 + // (a) Receiving thread must be the current thread. 1.3247 + Node* rec_thr = argument(0); 1.3248 + Node* tls_ptr = NULL; 1.3249 + Node* cur_thr = generate_current_thread(tls_ptr); 1.3250 + Node* cmp_thr = _gvn.transform(new (C) CmpPNode(cur_thr, rec_thr)); 1.3251 + Node* bol_thr = _gvn.transform(new (C) BoolNode(cmp_thr, BoolTest::ne)); 1.3252 + 1.3253 + generate_slow_guard(bol_thr, slow_region); 1.3254 + 1.3255 + // (b) Interrupt bit on TLS must be false. 1.3256 + Node* p = basic_plus_adr(top()/*!oop*/, tls_ptr, in_bytes(JavaThread::osthread_offset())); 1.3257 + Node* osthread = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS, MemNode::unordered); 1.3258 + p = basic_plus_adr(top()/*!oop*/, osthread, in_bytes(OSThread::interrupted_offset())); 1.3259 + 1.3260 + // Set the control input on the field _interrupted read to prevent it floating up. 1.3261 + Node* int_bit = make_load(control(), p, TypeInt::BOOL, T_INT, MemNode::unordered); 1.3262 + Node* cmp_bit = _gvn.transform(new (C) CmpINode(int_bit, intcon(0))); 1.3263 + Node* bol_bit = _gvn.transform(new (C) BoolNode(cmp_bit, BoolTest::ne)); 1.3264 + 1.3265 + IfNode* iff_bit = create_and_map_if(control(), bol_bit, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN); 1.3266 + 1.3267 + // First fast path: if (!TLS._interrupted) return false; 1.3268 + Node* false_bit = _gvn.transform(new (C) IfFalseNode(iff_bit)); 1.3269 + result_rgn->init_req(no_int_result_path, false_bit); 1.3270 + result_val->init_req(no_int_result_path, intcon(0)); 1.3271 + 1.3272 + // drop through to next case 1.3273 + set_control( _gvn.transform(new (C) IfTrueNode(iff_bit))); 1.3274 + 1.3275 +#ifndef TARGET_OS_FAMILY_windows 1.3276 + // (c) Or, if interrupt bit is set and clear_int is false, use 2nd fast path. 1.3277 + Node* clr_arg = argument(1); 1.3278 + Node* cmp_arg = _gvn.transform(new (C) CmpINode(clr_arg, intcon(0))); 1.3279 + Node* bol_arg = _gvn.transform(new (C) BoolNode(cmp_arg, BoolTest::ne)); 1.3280 + IfNode* iff_arg = create_and_map_if(control(), bol_arg, PROB_FAIR, COUNT_UNKNOWN); 1.3281 + 1.3282 + // Second fast path: ... else if (!clear_int) return true; 1.3283 + Node* false_arg = _gvn.transform(new (C) IfFalseNode(iff_arg)); 1.3284 + result_rgn->init_req(no_clear_result_path, false_arg); 1.3285 + result_val->init_req(no_clear_result_path, intcon(1)); 1.3286 + 1.3287 + // drop through to next case 1.3288 + set_control( _gvn.transform(new (C) IfTrueNode(iff_arg))); 1.3289 +#else 1.3290 + // To return true on Windows you must read the _interrupted field 1.3291 + // and check the the event state i.e. take the slow path. 1.3292 +#endif // TARGET_OS_FAMILY_windows 1.3293 + 1.3294 + // (d) Otherwise, go to the slow path. 1.3295 + slow_region->add_req(control()); 1.3296 + set_control( _gvn.transform(slow_region)); 1.3297 + 1.3298 + if (stopped()) { 1.3299 + // There is no slow path. 1.3300 + result_rgn->init_req(slow_result_path, top()); 1.3301 + result_val->init_req(slow_result_path, top()); 1.3302 + } else { 1.3303 + // non-virtual because it is a private non-static 1.3304 + CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_isInterrupted); 1.3305 + 1.3306 + Node* slow_val = set_results_for_java_call(slow_call); 1.3307 + // this->control() comes from set_results_for_java_call 1.3308 + 1.3309 + Node* fast_io = slow_call->in(TypeFunc::I_O); 1.3310 + Node* fast_mem = slow_call->in(TypeFunc::Memory); 1.3311 + 1.3312 + // These two phis are pre-filled with copies of of the fast IO and Memory 1.3313 + PhiNode* result_mem = PhiNode::make(result_rgn, fast_mem, Type::MEMORY, TypePtr::BOTTOM); 1.3314 + PhiNode* result_io = PhiNode::make(result_rgn, fast_io, Type::ABIO); 1.3315 + 1.3316 + result_rgn->init_req(slow_result_path, control()); 1.3317 + result_io ->init_req(slow_result_path, i_o()); 1.3318 + result_mem->init_req(slow_result_path, reset_memory()); 1.3319 + result_val->init_req(slow_result_path, slow_val); 1.3320 + 1.3321 + set_all_memory(_gvn.transform(result_mem)); 1.3322 + set_i_o( _gvn.transform(result_io)); 1.3323 + } 1.3324 + 1.3325 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.3326 + set_result(result_rgn, result_val); 1.3327 + return true; 1.3328 +} 1.3329 + 1.3330 +//---------------------------load_mirror_from_klass---------------------------- 1.3331 +// Given a klass oop, load its java mirror (a java.lang.Class oop). 1.3332 +Node* LibraryCallKit::load_mirror_from_klass(Node* klass) { 1.3333 + Node* p = basic_plus_adr(klass, in_bytes(Klass::java_mirror_offset())); 1.3334 + return make_load(NULL, p, TypeInstPtr::MIRROR, T_OBJECT, MemNode::unordered); 1.3335 +} 1.3336 + 1.3337 +//-----------------------load_klass_from_mirror_common------------------------- 1.3338 +// Given a java mirror (a java.lang.Class oop), load its corresponding klass oop. 1.3339 +// Test the klass oop for null (signifying a primitive Class like Integer.TYPE), 1.3340 +// and branch to the given path on the region. 1.3341 +// If never_see_null, take an uncommon trap on null, so we can optimistically 1.3342 +// compile for the non-null case. 1.3343 +// If the region is NULL, force never_see_null = true. 1.3344 +Node* LibraryCallKit::load_klass_from_mirror_common(Node* mirror, 1.3345 + bool never_see_null, 1.3346 + RegionNode* region, 1.3347 + int null_path, 1.3348 + int offset) { 1.3349 + if (region == NULL) never_see_null = true; 1.3350 + Node* p = basic_plus_adr(mirror, offset); 1.3351 + const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL; 1.3352 + Node* kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type)); 1.3353 + Node* null_ctl = top(); 1.3354 + kls = null_check_oop(kls, &null_ctl, never_see_null); 1.3355 + if (region != NULL) { 1.3356 + // Set region->in(null_path) if the mirror is a primitive (e.g, int.class). 1.3357 + region->init_req(null_path, null_ctl); 1.3358 + } else { 1.3359 + assert(null_ctl == top(), "no loose ends"); 1.3360 + } 1.3361 + return kls; 1.3362 +} 1.3363 + 1.3364 +//--------------------(inline_native_Class_query helpers)--------------------- 1.3365 +// Use this for JVM_ACC_INTERFACE, JVM_ACC_IS_CLONEABLE, JVM_ACC_HAS_FINALIZER. 1.3366 +// Fall through if (mods & mask) == bits, take the guard otherwise. 1.3367 +Node* LibraryCallKit::generate_access_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) { 1.3368 + // Branch around if the given klass has the given modifier bit set. 1.3369 + // Like generate_guard, adds a new path onto the region. 1.3370 + Node* modp = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset())); 1.3371 + Node* mods = make_load(NULL, modp, TypeInt::INT, T_INT, MemNode::unordered); 1.3372 + Node* mask = intcon(modifier_mask); 1.3373 + Node* bits = intcon(modifier_bits); 1.3374 + Node* mbit = _gvn.transform(new (C) AndINode(mods, mask)); 1.3375 + Node* cmp = _gvn.transform(new (C) CmpINode(mbit, bits)); 1.3376 + Node* bol = _gvn.transform(new (C) BoolNode(cmp, BoolTest::ne)); 1.3377 + return generate_fair_guard(bol, region); 1.3378 +} 1.3379 +Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) { 1.3380 + return generate_access_flags_guard(kls, JVM_ACC_INTERFACE, 0, region); 1.3381 +} 1.3382 + 1.3383 +//-------------------------inline_native_Class_query------------------- 1.3384 +bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) { 1.3385 + const Type* return_type = TypeInt::BOOL; 1.3386 + Node* prim_return_value = top(); // what happens if it's a primitive class? 1.3387 + bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 1.3388 + bool expect_prim = false; // most of these guys expect to work on refs 1.3389 + 1.3390 + enum { _normal_path = 1, _prim_path = 2, PATH_LIMIT }; 1.3391 + 1.3392 + Node* mirror = argument(0); 1.3393 + Node* obj = top(); 1.3394 + 1.3395 + switch (id) { 1.3396 + case vmIntrinsics::_isInstance: 1.3397 + // nothing is an instance of a primitive type 1.3398 + prim_return_value = intcon(0); 1.3399 + obj = argument(1); 1.3400 + break; 1.3401 + case vmIntrinsics::_getModifiers: 1.3402 + prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC); 1.3403 + assert(is_power_of_2((int)JVM_ACC_WRITTEN_FLAGS+1), "change next line"); 1.3404 + return_type = TypeInt::make(0, JVM_ACC_WRITTEN_FLAGS, Type::WidenMin); 1.3405 + break; 1.3406 + case vmIntrinsics::_isInterface: 1.3407 + prim_return_value = intcon(0); 1.3408 + break; 1.3409 + case vmIntrinsics::_isArray: 1.3410 + prim_return_value = intcon(0); 1.3411 + expect_prim = true; // cf. ObjectStreamClass.getClassSignature 1.3412 + break; 1.3413 + case vmIntrinsics::_isPrimitive: 1.3414 + prim_return_value = intcon(1); 1.3415 + expect_prim = true; // obviously 1.3416 + break; 1.3417 + case vmIntrinsics::_getSuperclass: 1.3418 + prim_return_value = null(); 1.3419 + return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR); 1.3420 + break; 1.3421 + case vmIntrinsics::_getComponentType: 1.3422 + prim_return_value = null(); 1.3423 + return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR); 1.3424 + break; 1.3425 + case vmIntrinsics::_getClassAccessFlags: 1.3426 + prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC); 1.3427 + return_type = TypeInt::INT; // not bool! 6297094 1.3428 + break; 1.3429 + default: 1.3430 + fatal_unexpected_iid(id); 1.3431 + break; 1.3432 + } 1.3433 + 1.3434 + const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr(); 1.3435 + if (mirror_con == NULL) return false; // cannot happen? 1.3436 + 1.3437 +#ifndef PRODUCT 1.3438 + if (C->print_intrinsics() || C->print_inlining()) { 1.3439 + ciType* k = mirror_con->java_mirror_type(); 1.3440 + if (k) { 1.3441 + tty->print("Inlining %s on constant Class ", vmIntrinsics::name_at(intrinsic_id())); 1.3442 + k->print_name(); 1.3443 + tty->cr(); 1.3444 + } 1.3445 + } 1.3446 +#endif 1.3447 + 1.3448 + // Null-check the mirror, and the mirror's klass ptr (in case it is a primitive). 1.3449 + RegionNode* region = new (C) RegionNode(PATH_LIMIT); 1.3450 + record_for_igvn(region); 1.3451 + PhiNode* phi = new (C) PhiNode(region, return_type); 1.3452 + 1.3453 + // The mirror will never be null of Reflection.getClassAccessFlags, however 1.3454 + // it may be null for Class.isInstance or Class.getModifiers. Throw a NPE 1.3455 + // if it is. See bug 4774291. 1.3456 + 1.3457 + // For Reflection.getClassAccessFlags(), the null check occurs in 1.3458 + // the wrong place; see inline_unsafe_access(), above, for a similar 1.3459 + // situation. 1.3460 + mirror = null_check(mirror); 1.3461 + // If mirror or obj is dead, only null-path is taken. 1.3462 + if (stopped()) return true; 1.3463 + 1.3464 + if (expect_prim) never_see_null = false; // expect nulls (meaning prims) 1.3465 + 1.3466 + // Now load the mirror's klass metaobject, and null-check it. 1.3467 + // Side-effects region with the control path if the klass is null. 1.3468 + Node* kls = load_klass_from_mirror(mirror, never_see_null, region, _prim_path); 1.3469 + // If kls is null, we have a primitive mirror. 1.3470 + phi->init_req(_prim_path, prim_return_value); 1.3471 + if (stopped()) { set_result(region, phi); return true; } 1.3472 + bool safe_for_replace = (region->in(_prim_path) == top()); 1.3473 + 1.3474 + Node* p; // handy temp 1.3475 + Node* null_ctl; 1.3476 + 1.3477 + // Now that we have the non-null klass, we can perform the real query. 1.3478 + // For constant classes, the query will constant-fold in LoadNode::Value. 1.3479 + Node* query_value = top(); 1.3480 + switch (id) { 1.3481 + case vmIntrinsics::_isInstance: 1.3482 + // nothing is an instance of a primitive type 1.3483 + query_value = gen_instanceof(obj, kls, safe_for_replace); 1.3484 + break; 1.3485 + 1.3486 + case vmIntrinsics::_getModifiers: 1.3487 + p = basic_plus_adr(kls, in_bytes(Klass::modifier_flags_offset())); 1.3488 + query_value = make_load(NULL, p, TypeInt::INT, T_INT, MemNode::unordered); 1.3489 + break; 1.3490 + 1.3491 + case vmIntrinsics::_isInterface: 1.3492 + // (To verify this code sequence, check the asserts in JVM_IsInterface.) 1.3493 + if (generate_interface_guard(kls, region) != NULL) 1.3494 + // A guard was added. If the guard is taken, it was an interface. 1.3495 + phi->add_req(intcon(1)); 1.3496 + // If we fall through, it's a plain class. 1.3497 + query_value = intcon(0); 1.3498 + break; 1.3499 + 1.3500 + case vmIntrinsics::_isArray: 1.3501 + // (To verify this code sequence, check the asserts in JVM_IsArrayClass.) 1.3502 + if (generate_array_guard(kls, region) != NULL) 1.3503 + // A guard was added. If the guard is taken, it was an array. 1.3504 + phi->add_req(intcon(1)); 1.3505 + // If we fall through, it's a plain class. 1.3506 + query_value = intcon(0); 1.3507 + break; 1.3508 + 1.3509 + case vmIntrinsics::_isPrimitive: 1.3510 + query_value = intcon(0); // "normal" path produces false 1.3511 + break; 1.3512 + 1.3513 + case vmIntrinsics::_getSuperclass: 1.3514 + // The rules here are somewhat unfortunate, but we can still do better 1.3515 + // with random logic than with a JNI call. 1.3516 + // Interfaces store null or Object as _super, but must report null. 1.3517 + // Arrays store an intermediate super as _super, but must report Object. 1.3518 + // Other types can report the actual _super. 1.3519 + // (To verify this code sequence, check the asserts in JVM_IsInterface.) 1.3520 + if (generate_interface_guard(kls, region) != NULL) 1.3521 + // A guard was added. If the guard is taken, it was an interface. 1.3522 + phi->add_req(null()); 1.3523 + if (generate_array_guard(kls, region) != NULL) 1.3524 + // A guard was added. If the guard is taken, it was an array. 1.3525 + phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror()))); 1.3526 + // If we fall through, it's a plain class. Get its _super. 1.3527 + p = basic_plus_adr(kls, in_bytes(Klass::super_offset())); 1.3528 + kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeKlassPtr::OBJECT_OR_NULL)); 1.3529 + null_ctl = top(); 1.3530 + kls = null_check_oop(kls, &null_ctl); 1.3531 + if (null_ctl != top()) { 1.3532 + // If the guard is taken, Object.superClass is null (both klass and mirror). 1.3533 + region->add_req(null_ctl); 1.3534 + phi ->add_req(null()); 1.3535 + } 1.3536 + if (!stopped()) { 1.3537 + query_value = load_mirror_from_klass(kls); 1.3538 + } 1.3539 + break; 1.3540 + 1.3541 + case vmIntrinsics::_getComponentType: 1.3542 + if (generate_array_guard(kls, region) != NULL) { 1.3543 + // Be sure to pin the oop load to the guard edge just created: 1.3544 + Node* is_array_ctrl = region->in(region->req()-1); 1.3545 + Node* cma = basic_plus_adr(kls, in_bytes(ArrayKlass::component_mirror_offset())); 1.3546 + Node* cmo = make_load(is_array_ctrl, cma, TypeInstPtr::MIRROR, T_OBJECT, MemNode::unordered); 1.3547 + phi->add_req(cmo); 1.3548 + } 1.3549 + query_value = null(); // non-array case is null 1.3550 + break; 1.3551 + 1.3552 + case vmIntrinsics::_getClassAccessFlags: 1.3553 + p = basic_plus_adr(kls, in_bytes(Klass::access_flags_offset())); 1.3554 + query_value = make_load(NULL, p, TypeInt::INT, T_INT, MemNode::unordered); 1.3555 + break; 1.3556 + 1.3557 + default: 1.3558 + fatal_unexpected_iid(id); 1.3559 + break; 1.3560 + } 1.3561 + 1.3562 + // Fall-through is the normal case of a query to a real class. 1.3563 + phi->init_req(1, query_value); 1.3564 + region->init_req(1, control()); 1.3565 + 1.3566 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.3567 + set_result(region, phi); 1.3568 + return true; 1.3569 +} 1.3570 + 1.3571 +//--------------------------inline_native_subtype_check------------------------ 1.3572 +// This intrinsic takes the JNI calls out of the heart of 1.3573 +// UnsafeFieldAccessorImpl.set, which improves Field.set, readObject, etc. 1.3574 +bool LibraryCallKit::inline_native_subtype_check() { 1.3575 + // Pull both arguments off the stack. 1.3576 + Node* args[2]; // two java.lang.Class mirrors: superc, subc 1.3577 + args[0] = argument(0); 1.3578 + args[1] = argument(1); 1.3579 + Node* klasses[2]; // corresponding Klasses: superk, subk 1.3580 + klasses[0] = klasses[1] = top(); 1.3581 + 1.3582 + enum { 1.3583 + // A full decision tree on {superc is prim, subc is prim}: 1.3584 + _prim_0_path = 1, // {P,N} => false 1.3585 + // {P,P} & superc!=subc => false 1.3586 + _prim_same_path, // {P,P} & superc==subc => true 1.3587 + _prim_1_path, // {N,P} => false 1.3588 + _ref_subtype_path, // {N,N} & subtype check wins => true 1.3589 + _both_ref_path, // {N,N} & subtype check loses => false 1.3590 + PATH_LIMIT 1.3591 + }; 1.3592 + 1.3593 + RegionNode* region = new (C) RegionNode(PATH_LIMIT); 1.3594 + Node* phi = new (C) PhiNode(region, TypeInt::BOOL); 1.3595 + record_for_igvn(region); 1.3596 + 1.3597 + const TypePtr* adr_type = TypeRawPtr::BOTTOM; // memory type of loads 1.3598 + const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL; 1.3599 + int class_klass_offset = java_lang_Class::klass_offset_in_bytes(); 1.3600 + 1.3601 + // First null-check both mirrors and load each mirror's klass metaobject. 1.3602 + int which_arg; 1.3603 + for (which_arg = 0; which_arg <= 1; which_arg++) { 1.3604 + Node* arg = args[which_arg]; 1.3605 + arg = null_check(arg); 1.3606 + if (stopped()) break; 1.3607 + args[which_arg] = arg; 1.3608 + 1.3609 + Node* p = basic_plus_adr(arg, class_klass_offset); 1.3610 + Node* kls = LoadKlassNode::make(_gvn, immutable_memory(), p, adr_type, kls_type); 1.3611 + klasses[which_arg] = _gvn.transform(kls); 1.3612 + } 1.3613 + 1.3614 + // Having loaded both klasses, test each for null. 1.3615 + bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 1.3616 + for (which_arg = 0; which_arg <= 1; which_arg++) { 1.3617 + Node* kls = klasses[which_arg]; 1.3618 + Node* null_ctl = top(); 1.3619 + kls = null_check_oop(kls, &null_ctl, never_see_null); 1.3620 + int prim_path = (which_arg == 0 ? _prim_0_path : _prim_1_path); 1.3621 + region->init_req(prim_path, null_ctl); 1.3622 + if (stopped()) break; 1.3623 + klasses[which_arg] = kls; 1.3624 + } 1.3625 + 1.3626 + if (!stopped()) { 1.3627 + // now we have two reference types, in klasses[0..1] 1.3628 + Node* subk = klasses[1]; // the argument to isAssignableFrom 1.3629 + Node* superk = klasses[0]; // the receiver 1.3630 + region->set_req(_both_ref_path, gen_subtype_check(subk, superk)); 1.3631 + // now we have a successful reference subtype check 1.3632 + region->set_req(_ref_subtype_path, control()); 1.3633 + } 1.3634 + 1.3635 + // If both operands are primitive (both klasses null), then 1.3636 + // we must return true when they are identical primitives. 1.3637 + // It is convenient to test this after the first null klass check. 1.3638 + set_control(region->in(_prim_0_path)); // go back to first null check 1.3639 + if (!stopped()) { 1.3640 + // Since superc is primitive, make a guard for the superc==subc case. 1.3641 + Node* cmp_eq = _gvn.transform(new (C) CmpPNode(args[0], args[1])); 1.3642 + Node* bol_eq = _gvn.transform(new (C) BoolNode(cmp_eq, BoolTest::eq)); 1.3643 + generate_guard(bol_eq, region, PROB_FAIR); 1.3644 + if (region->req() == PATH_LIMIT+1) { 1.3645 + // A guard was added. If the added guard is taken, superc==subc. 1.3646 + region->swap_edges(PATH_LIMIT, _prim_same_path); 1.3647 + region->del_req(PATH_LIMIT); 1.3648 + } 1.3649 + region->set_req(_prim_0_path, control()); // Not equal after all. 1.3650 + } 1.3651 + 1.3652 + // these are the only paths that produce 'true': 1.3653 + phi->set_req(_prim_same_path, intcon(1)); 1.3654 + phi->set_req(_ref_subtype_path, intcon(1)); 1.3655 + 1.3656 + // pull together the cases: 1.3657 + assert(region->req() == PATH_LIMIT, "sane region"); 1.3658 + for (uint i = 1; i < region->req(); i++) { 1.3659 + Node* ctl = region->in(i); 1.3660 + if (ctl == NULL || ctl == top()) { 1.3661 + region->set_req(i, top()); 1.3662 + phi ->set_req(i, top()); 1.3663 + } else if (phi->in(i) == NULL) { 1.3664 + phi->set_req(i, intcon(0)); // all other paths produce 'false' 1.3665 + } 1.3666 + } 1.3667 + 1.3668 + set_control(_gvn.transform(region)); 1.3669 + set_result(_gvn.transform(phi)); 1.3670 + return true; 1.3671 +} 1.3672 + 1.3673 +//---------------------generate_array_guard_common------------------------ 1.3674 +Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region, 1.3675 + bool obj_array, bool not_array) { 1.3676 + // If obj_array/non_array==false/false: 1.3677 + // Branch around if the given klass is in fact an array (either obj or prim). 1.3678 + // If obj_array/non_array==false/true: 1.3679 + // Branch around if the given klass is not an array klass of any kind. 1.3680 + // If obj_array/non_array==true/true: 1.3681 + // Branch around if the kls is not an oop array (kls is int[], String, etc.) 1.3682 + // If obj_array/non_array==true/false: 1.3683 + // Branch around if the kls is an oop array (Object[] or subtype) 1.3684 + // 1.3685 + // Like generate_guard, adds a new path onto the region. 1.3686 + jint layout_con = 0; 1.3687 + Node* layout_val = get_layout_helper(kls, layout_con); 1.3688 + if (layout_val == NULL) { 1.3689 + bool query = (obj_array 1.3690 + ? Klass::layout_helper_is_objArray(layout_con) 1.3691 + : Klass::layout_helper_is_array(layout_con)); 1.3692 + if (query == not_array) { 1.3693 + return NULL; // never a branch 1.3694 + } else { // always a branch 1.3695 + Node* always_branch = control(); 1.3696 + if (region != NULL) 1.3697 + region->add_req(always_branch); 1.3698 + set_control(top()); 1.3699 + return always_branch; 1.3700 + } 1.3701 + } 1.3702 + // Now test the correct condition. 1.3703 + jint nval = (obj_array 1.3704 + ? ((jint)Klass::_lh_array_tag_type_value 1.3705 + << Klass::_lh_array_tag_shift) 1.3706 + : Klass::_lh_neutral_value); 1.3707 + Node* cmp = _gvn.transform(new(C) CmpINode(layout_val, intcon(nval))); 1.3708 + BoolTest::mask btest = BoolTest::lt; // correct for testing is_[obj]array 1.3709 + // invert the test if we are looking for a non-array 1.3710 + if (not_array) btest = BoolTest(btest).negate(); 1.3711 + Node* bol = _gvn.transform(new(C) BoolNode(cmp, btest)); 1.3712 + return generate_fair_guard(bol, region); 1.3713 +} 1.3714 + 1.3715 + 1.3716 +//-----------------------inline_native_newArray-------------------------- 1.3717 +// private static native Object java.lang.reflect.newArray(Class<?> componentType, int length); 1.3718 +bool LibraryCallKit::inline_native_newArray() { 1.3719 + Node* mirror = argument(0); 1.3720 + Node* count_val = argument(1); 1.3721 + 1.3722 + mirror = null_check(mirror); 1.3723 + // If mirror or obj is dead, only null-path is taken. 1.3724 + if (stopped()) return true; 1.3725 + 1.3726 + enum { _normal_path = 1, _slow_path = 2, PATH_LIMIT }; 1.3727 + RegionNode* result_reg = new(C) RegionNode(PATH_LIMIT); 1.3728 + PhiNode* result_val = new(C) PhiNode(result_reg, 1.3729 + TypeInstPtr::NOTNULL); 1.3730 + PhiNode* result_io = new(C) PhiNode(result_reg, Type::ABIO); 1.3731 + PhiNode* result_mem = new(C) PhiNode(result_reg, Type::MEMORY, 1.3732 + TypePtr::BOTTOM); 1.3733 + 1.3734 + bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 1.3735 + Node* klass_node = load_array_klass_from_mirror(mirror, never_see_null, 1.3736 + result_reg, _slow_path); 1.3737 + Node* normal_ctl = control(); 1.3738 + Node* no_array_ctl = result_reg->in(_slow_path); 1.3739 + 1.3740 + // Generate code for the slow case. We make a call to newArray(). 1.3741 + set_control(no_array_ctl); 1.3742 + if (!stopped()) { 1.3743 + // Either the input type is void.class, or else the 1.3744 + // array klass has not yet been cached. Either the 1.3745 + // ensuing call will throw an exception, or else it 1.3746 + // will cache the array klass for next time. 1.3747 + PreserveJVMState pjvms(this); 1.3748 + CallJavaNode* slow_call = generate_method_call_static(vmIntrinsics::_newArray); 1.3749 + Node* slow_result = set_results_for_java_call(slow_call); 1.3750 + // this->control() comes from set_results_for_java_call 1.3751 + result_reg->set_req(_slow_path, control()); 1.3752 + result_val->set_req(_slow_path, slow_result); 1.3753 + result_io ->set_req(_slow_path, i_o()); 1.3754 + result_mem->set_req(_slow_path, reset_memory()); 1.3755 + } 1.3756 + 1.3757 + set_control(normal_ctl); 1.3758 + if (!stopped()) { 1.3759 + // Normal case: The array type has been cached in the java.lang.Class. 1.3760 + // The following call works fine even if the array type is polymorphic. 1.3761 + // It could be a dynamic mix of int[], boolean[], Object[], etc. 1.3762 + Node* obj = new_array(klass_node, count_val, 0); // no arguments to push 1.3763 + result_reg->init_req(_normal_path, control()); 1.3764 + result_val->init_req(_normal_path, obj); 1.3765 + result_io ->init_req(_normal_path, i_o()); 1.3766 + result_mem->init_req(_normal_path, reset_memory()); 1.3767 + } 1.3768 + 1.3769 + // Return the combined state. 1.3770 + set_i_o( _gvn.transform(result_io) ); 1.3771 + set_all_memory( _gvn.transform(result_mem)); 1.3772 + 1.3773 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.3774 + set_result(result_reg, result_val); 1.3775 + return true; 1.3776 +} 1.3777 + 1.3778 +//----------------------inline_native_getLength-------------------------- 1.3779 +// public static native int java.lang.reflect.Array.getLength(Object array); 1.3780 +bool LibraryCallKit::inline_native_getLength() { 1.3781 + if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 1.3782 + 1.3783 + Node* array = null_check(argument(0)); 1.3784 + // If array is dead, only null-path is taken. 1.3785 + if (stopped()) return true; 1.3786 + 1.3787 + // Deoptimize if it is a non-array. 1.3788 + Node* non_array = generate_non_array_guard(load_object_klass(array), NULL); 1.3789 + 1.3790 + if (non_array != NULL) { 1.3791 + PreserveJVMState pjvms(this); 1.3792 + set_control(non_array); 1.3793 + uncommon_trap(Deoptimization::Reason_intrinsic, 1.3794 + Deoptimization::Action_maybe_recompile); 1.3795 + } 1.3796 + 1.3797 + // If control is dead, only non-array-path is taken. 1.3798 + if (stopped()) return true; 1.3799 + 1.3800 + // The works fine even if the array type is polymorphic. 1.3801 + // It could be a dynamic mix of int[], boolean[], Object[], etc. 1.3802 + Node* result = load_array_length(array); 1.3803 + 1.3804 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.3805 + set_result(result); 1.3806 + return true; 1.3807 +} 1.3808 + 1.3809 +//------------------------inline_array_copyOf---------------------------- 1.3810 +// public static <T,U> T[] java.util.Arrays.copyOf( U[] original, int newLength, Class<? extends T[]> newType); 1.3811 +// public static <T,U> T[] java.util.Arrays.copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType); 1.3812 +bool LibraryCallKit::inline_array_copyOf(bool is_copyOfRange) { 1.3813 + if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 1.3814 + 1.3815 + // Get the arguments. 1.3816 + Node* original = argument(0); 1.3817 + Node* start = is_copyOfRange? argument(1): intcon(0); 1.3818 + Node* end = is_copyOfRange? argument(2): argument(1); 1.3819 + Node* array_type_mirror = is_copyOfRange? argument(3): argument(2); 1.3820 + 1.3821 + Node* newcopy; 1.3822 + 1.3823 + // Set the original stack and the reexecute bit for the interpreter to reexecute 1.3824 + // the bytecode that invokes Arrays.copyOf if deoptimization happens. 1.3825 + { PreserveReexecuteState preexecs(this); 1.3826 + jvms()->set_should_reexecute(true); 1.3827 + 1.3828 + array_type_mirror = null_check(array_type_mirror); 1.3829 + original = null_check(original); 1.3830 + 1.3831 + // Check if a null path was taken unconditionally. 1.3832 + if (stopped()) return true; 1.3833 + 1.3834 + Node* orig_length = load_array_length(original); 1.3835 + 1.3836 + Node* klass_node = load_klass_from_mirror(array_type_mirror, false, NULL, 0); 1.3837 + klass_node = null_check(klass_node); 1.3838 + 1.3839 + RegionNode* bailout = new (C) RegionNode(1); 1.3840 + record_for_igvn(bailout); 1.3841 + 1.3842 + // Despite the generic type of Arrays.copyOf, the mirror might be int, int[], etc. 1.3843 + // Bail out if that is so. 1.3844 + Node* not_objArray = generate_non_objArray_guard(klass_node, bailout); 1.3845 + if (not_objArray != NULL) { 1.3846 + // Improve the klass node's type from the new optimistic assumption: 1.3847 + ciKlass* ak = ciArrayKlass::make(env()->Object_klass()); 1.3848 + const Type* akls = TypeKlassPtr::make(TypePtr::NotNull, ak, 0/*offset*/); 1.3849 + Node* cast = new (C) CastPPNode(klass_node, akls); 1.3850 + cast->init_req(0, control()); 1.3851 + klass_node = _gvn.transform(cast); 1.3852 + } 1.3853 + 1.3854 + // Bail out if either start or end is negative. 1.3855 + generate_negative_guard(start, bailout, &start); 1.3856 + generate_negative_guard(end, bailout, &end); 1.3857 + 1.3858 + Node* length = end; 1.3859 + if (_gvn.type(start) != TypeInt::ZERO) { 1.3860 + length = _gvn.transform(new (C) SubINode(end, start)); 1.3861 + } 1.3862 + 1.3863 + // Bail out if length is negative. 1.3864 + // Without this the new_array would throw 1.3865 + // NegativeArraySizeException but IllegalArgumentException is what 1.3866 + // should be thrown 1.3867 + generate_negative_guard(length, bailout, &length); 1.3868 + 1.3869 + if (bailout->req() > 1) { 1.3870 + PreserveJVMState pjvms(this); 1.3871 + set_control(_gvn.transform(bailout)); 1.3872 + uncommon_trap(Deoptimization::Reason_intrinsic, 1.3873 + Deoptimization::Action_maybe_recompile); 1.3874 + } 1.3875 + 1.3876 + if (!stopped()) { 1.3877 + // How many elements will we copy from the original? 1.3878 + // The answer is MinI(orig_length - start, length). 1.3879 + Node* orig_tail = _gvn.transform(new (C) SubINode(orig_length, start)); 1.3880 + Node* moved = generate_min_max(vmIntrinsics::_min, orig_tail, length); 1.3881 + 1.3882 + newcopy = new_array(klass_node, length, 0); // no argments to push 1.3883 + 1.3884 + // Generate a direct call to the right arraycopy function(s). 1.3885 + // We know the copy is disjoint but we might not know if the 1.3886 + // oop stores need checking. 1.3887 + // Extreme case: Arrays.copyOf((Integer[])x, 10, String[].class). 1.3888 + // This will fail a store-check if x contains any non-nulls. 1.3889 + bool disjoint_bases = true; 1.3890 + // if start > orig_length then the length of the copy may be 1.3891 + // negative. 1.3892 + bool length_never_negative = !is_copyOfRange; 1.3893 + generate_arraycopy(TypeAryPtr::OOPS, T_OBJECT, 1.3894 + original, start, newcopy, intcon(0), moved, 1.3895 + disjoint_bases, length_never_negative); 1.3896 + } 1.3897 + } // original reexecute is set back here 1.3898 + 1.3899 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.3900 + if (!stopped()) { 1.3901 + set_result(newcopy); 1.3902 + } 1.3903 + return true; 1.3904 +} 1.3905 + 1.3906 + 1.3907 +//----------------------generate_virtual_guard--------------------------- 1.3908 +// Helper for hashCode and clone. Peeks inside the vtable to avoid a call. 1.3909 +Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass, 1.3910 + RegionNode* slow_region) { 1.3911 + ciMethod* method = callee(); 1.3912 + int vtable_index = method->vtable_index(); 1.3913 + assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, 1.3914 + err_msg_res("bad index %d", vtable_index)); 1.3915 + // Get the Method* out of the appropriate vtable entry. 1.3916 + int entry_offset = (InstanceKlass::vtable_start_offset() + 1.3917 + vtable_index*vtableEntry::size()) * wordSize + 1.3918 + vtableEntry::method_offset_in_bytes(); 1.3919 + Node* entry_addr = basic_plus_adr(obj_klass, entry_offset); 1.3920 + Node* target_call = make_load(NULL, entry_addr, TypePtr::NOTNULL, T_ADDRESS, MemNode::unordered); 1.3921 + 1.3922 + // Compare the target method with the expected method (e.g., Object.hashCode). 1.3923 + const TypePtr* native_call_addr = TypeMetadataPtr::make(method); 1.3924 + 1.3925 + Node* native_call = makecon(native_call_addr); 1.3926 + Node* chk_native = _gvn.transform(new(C) CmpPNode(target_call, native_call)); 1.3927 + Node* test_native = _gvn.transform(new(C) BoolNode(chk_native, BoolTest::ne)); 1.3928 + 1.3929 + return generate_slow_guard(test_native, slow_region); 1.3930 +} 1.3931 + 1.3932 +//-----------------------generate_method_call---------------------------- 1.3933 +// Use generate_method_call to make a slow-call to the real 1.3934 +// method if the fast path fails. An alternative would be to 1.3935 +// use a stub like OptoRuntime::slow_arraycopy_Java. 1.3936 +// This only works for expanding the current library call, 1.3937 +// not another intrinsic. (E.g., don't use this for making an 1.3938 +// arraycopy call inside of the copyOf intrinsic.) 1.3939 +CallJavaNode* 1.3940 +LibraryCallKit::generate_method_call(vmIntrinsics::ID method_id, bool is_virtual, bool is_static) { 1.3941 + // When compiling the intrinsic method itself, do not use this technique. 1.3942 + guarantee(callee() != C->method(), "cannot make slow-call to self"); 1.3943 + 1.3944 + ciMethod* method = callee(); 1.3945 + // ensure the JVMS we have will be correct for this call 1.3946 + guarantee(method_id == method->intrinsic_id(), "must match"); 1.3947 + 1.3948 + const TypeFunc* tf = TypeFunc::make(method); 1.3949 + CallJavaNode* slow_call; 1.3950 + if (is_static) { 1.3951 + assert(!is_virtual, ""); 1.3952 + slow_call = new(C) CallStaticJavaNode(C, tf, 1.3953 + SharedRuntime::get_resolve_static_call_stub(), 1.3954 + method, bci()); 1.3955 + } else if (is_virtual) { 1.3956 + null_check_receiver(); 1.3957 + int vtable_index = Method::invalid_vtable_index; 1.3958 + if (UseInlineCaches) { 1.3959 + // Suppress the vtable call 1.3960 + } else { 1.3961 + // hashCode and clone are not a miranda methods, 1.3962 + // so the vtable index is fixed. 1.3963 + // No need to use the linkResolver to get it. 1.3964 + vtable_index = method->vtable_index(); 1.3965 + assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, 1.3966 + err_msg_res("bad index %d", vtable_index)); 1.3967 + } 1.3968 + slow_call = new(C) CallDynamicJavaNode(tf, 1.3969 + SharedRuntime::get_resolve_virtual_call_stub(), 1.3970 + method, vtable_index, bci()); 1.3971 + } else { // neither virtual nor static: opt_virtual 1.3972 + null_check_receiver(); 1.3973 + slow_call = new(C) CallStaticJavaNode(C, tf, 1.3974 + SharedRuntime::get_resolve_opt_virtual_call_stub(), 1.3975 + method, bci()); 1.3976 + slow_call->set_optimized_virtual(true); 1.3977 + } 1.3978 + set_arguments_for_java_call(slow_call); 1.3979 + set_edges_for_java_call(slow_call); 1.3980 + return slow_call; 1.3981 +} 1.3982 + 1.3983 + 1.3984 +/** 1.3985 + * Build special case code for calls to hashCode on an object. This call may 1.3986 + * be virtual (invokevirtual) or bound (invokespecial). For each case we generate 1.3987 + * slightly different code. 1.3988 + */ 1.3989 +bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) { 1.3990 + assert(is_static == callee()->is_static(), "correct intrinsic selection"); 1.3991 + assert(!(is_virtual && is_static), "either virtual, special, or static"); 1.3992 + 1.3993 + enum { _slow_path = 1, _fast_path, _null_path, PATH_LIMIT }; 1.3994 + 1.3995 + RegionNode* result_reg = new(C) RegionNode(PATH_LIMIT); 1.3996 + PhiNode* result_val = new(C) PhiNode(result_reg, TypeInt::INT); 1.3997 + PhiNode* result_io = new(C) PhiNode(result_reg, Type::ABIO); 1.3998 + PhiNode* result_mem = new(C) PhiNode(result_reg, Type::MEMORY, TypePtr::BOTTOM); 1.3999 + Node* obj = NULL; 1.4000 + if (!is_static) { 1.4001 + // Check for hashing null object 1.4002 + obj = null_check_receiver(); 1.4003 + if (stopped()) return true; // unconditionally null 1.4004 + result_reg->init_req(_null_path, top()); 1.4005 + result_val->init_req(_null_path, top()); 1.4006 + } else { 1.4007 + // Do a null check, and return zero if null. 1.4008 + // System.identityHashCode(null) == 0 1.4009 + obj = argument(0); 1.4010 + Node* null_ctl = top(); 1.4011 + obj = null_check_oop(obj, &null_ctl); 1.4012 + result_reg->init_req(_null_path, null_ctl); 1.4013 + result_val->init_req(_null_path, _gvn.intcon(0)); 1.4014 + } 1.4015 + 1.4016 + // Unconditionally null? Then return right away. 1.4017 + if (stopped()) { 1.4018 + set_control( result_reg->in(_null_path)); 1.4019 + if (!stopped()) 1.4020 + set_result(result_val->in(_null_path)); 1.4021 + return true; 1.4022 + } 1.4023 + 1.4024 + // We only go to the fast case code if we pass a number of guards. The 1.4025 + // paths which do not pass are accumulated in the slow_region. 1.4026 + RegionNode* slow_region = new (C) RegionNode(1); 1.4027 + record_for_igvn(slow_region); 1.4028 + 1.4029 + // If this is a virtual call, we generate a funny guard. We pull out 1.4030 + // the vtable entry corresponding to hashCode() from the target object. 1.4031 + // If the target method which we are calling happens to be the native 1.4032 + // Object hashCode() method, we pass the guard. We do not need this 1.4033 + // guard for non-virtual calls -- the caller is known to be the native 1.4034 + // Object hashCode(). 1.4035 + if (is_virtual) { 1.4036 + // After null check, get the object's klass. 1.4037 + Node* obj_klass = load_object_klass(obj); 1.4038 + generate_virtual_guard(obj_klass, slow_region); 1.4039 + } 1.4040 + 1.4041 + // Get the header out of the object, use LoadMarkNode when available 1.4042 + Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes()); 1.4043 + // The control of the load must be NULL. Otherwise, the load can move before 1.4044 + // the null check after castPP removal. 1.4045 + Node* no_ctrl = NULL; 1.4046 + Node* header = make_load(no_ctrl, header_addr, TypeX_X, TypeX_X->basic_type(), MemNode::unordered); 1.4047 + 1.4048 + // Test the header to see if it is unlocked. 1.4049 + Node* lock_mask = _gvn.MakeConX(markOopDesc::biased_lock_mask_in_place); 1.4050 + Node* lmasked_header = _gvn.transform(new (C) AndXNode(header, lock_mask)); 1.4051 + Node* unlocked_val = _gvn.MakeConX(markOopDesc::unlocked_value); 1.4052 + Node* chk_unlocked = _gvn.transform(new (C) CmpXNode( lmasked_header, unlocked_val)); 1.4053 + Node* test_unlocked = _gvn.transform(new (C) BoolNode( chk_unlocked, BoolTest::ne)); 1.4054 + 1.4055 + generate_slow_guard(test_unlocked, slow_region); 1.4056 + 1.4057 + // Get the hash value and check to see that it has been properly assigned. 1.4058 + // We depend on hash_mask being at most 32 bits and avoid the use of 1.4059 + // hash_mask_in_place because it could be larger than 32 bits in a 64-bit 1.4060 + // vm: see markOop.hpp. 1.4061 + Node* hash_mask = _gvn.intcon(markOopDesc::hash_mask); 1.4062 + Node* hash_shift = _gvn.intcon(markOopDesc::hash_shift); 1.4063 + Node* hshifted_header= _gvn.transform(new (C) URShiftXNode(header, hash_shift)); 1.4064 + // This hack lets the hash bits live anywhere in the mark object now, as long 1.4065 + // as the shift drops the relevant bits into the low 32 bits. Note that 1.4066 + // Java spec says that HashCode is an int so there's no point in capturing 1.4067 + // an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build). 1.4068 + hshifted_header = ConvX2I(hshifted_header); 1.4069 + Node* hash_val = _gvn.transform(new (C) AndINode(hshifted_header, hash_mask)); 1.4070 + 1.4071 + Node* no_hash_val = _gvn.intcon(markOopDesc::no_hash); 1.4072 + Node* chk_assigned = _gvn.transform(new (C) CmpINode( hash_val, no_hash_val)); 1.4073 + Node* test_assigned = _gvn.transform(new (C) BoolNode( chk_assigned, BoolTest::eq)); 1.4074 + 1.4075 + generate_slow_guard(test_assigned, slow_region); 1.4076 + 1.4077 + Node* init_mem = reset_memory(); 1.4078 + // fill in the rest of the null path: 1.4079 + result_io ->init_req(_null_path, i_o()); 1.4080 + result_mem->init_req(_null_path, init_mem); 1.4081 + 1.4082 + result_val->init_req(_fast_path, hash_val); 1.4083 + result_reg->init_req(_fast_path, control()); 1.4084 + result_io ->init_req(_fast_path, i_o()); 1.4085 + result_mem->init_req(_fast_path, init_mem); 1.4086 + 1.4087 + // Generate code for the slow case. We make a call to hashCode(). 1.4088 + set_control(_gvn.transform(slow_region)); 1.4089 + if (!stopped()) { 1.4090 + // No need for PreserveJVMState, because we're using up the present state. 1.4091 + set_all_memory(init_mem); 1.4092 + vmIntrinsics::ID hashCode_id = is_static ? vmIntrinsics::_identityHashCode : vmIntrinsics::_hashCode; 1.4093 + CallJavaNode* slow_call = generate_method_call(hashCode_id, is_virtual, is_static); 1.4094 + Node* slow_result = set_results_for_java_call(slow_call); 1.4095 + // this->control() comes from set_results_for_java_call 1.4096 + result_reg->init_req(_slow_path, control()); 1.4097 + result_val->init_req(_slow_path, slow_result); 1.4098 + result_io ->set_req(_slow_path, i_o()); 1.4099 + result_mem ->set_req(_slow_path, reset_memory()); 1.4100 + } 1.4101 + 1.4102 + // Return the combined state. 1.4103 + set_i_o( _gvn.transform(result_io) ); 1.4104 + set_all_memory( _gvn.transform(result_mem)); 1.4105 + 1.4106 + set_result(result_reg, result_val); 1.4107 + return true; 1.4108 +} 1.4109 + 1.4110 +//---------------------------inline_native_getClass---------------------------- 1.4111 +// public final native Class<?> java.lang.Object.getClass(); 1.4112 +// 1.4113 +// Build special case code for calls to getClass on an object. 1.4114 +bool LibraryCallKit::inline_native_getClass() { 1.4115 + Node* obj = null_check_receiver(); 1.4116 + if (stopped()) return true; 1.4117 + set_result(load_mirror_from_klass(load_object_klass(obj))); 1.4118 + return true; 1.4119 +} 1.4120 + 1.4121 +//-----------------inline_native_Reflection_getCallerClass--------------------- 1.4122 +// public static native Class<?> sun.reflect.Reflection.getCallerClass(); 1.4123 +// 1.4124 +// In the presence of deep enough inlining, getCallerClass() becomes a no-op. 1.4125 +// 1.4126 +// NOTE: This code must perform the same logic as JVM_GetCallerClass 1.4127 +// in that it must skip particular security frames and checks for 1.4128 +// caller sensitive methods. 1.4129 +bool LibraryCallKit::inline_native_Reflection_getCallerClass() { 1.4130 +#ifndef PRODUCT 1.4131 + if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 1.4132 + tty->print_cr("Attempting to inline sun.reflect.Reflection.getCallerClass"); 1.4133 + } 1.4134 +#endif 1.4135 + 1.4136 + if (!jvms()->has_method()) { 1.4137 +#ifndef PRODUCT 1.4138 + if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 1.4139 + tty->print_cr(" Bailing out because intrinsic was inlined at top level"); 1.4140 + } 1.4141 +#endif 1.4142 + return false; 1.4143 + } 1.4144 + 1.4145 + // Walk back up the JVM state to find the caller at the required 1.4146 + // depth. 1.4147 + JVMState* caller_jvms = jvms(); 1.4148 + 1.4149 + // Cf. JVM_GetCallerClass 1.4150 + // NOTE: Start the loop at depth 1 because the current JVM state does 1.4151 + // not include the Reflection.getCallerClass() frame. 1.4152 + for (int n = 1; caller_jvms != NULL; caller_jvms = caller_jvms->caller(), n++) { 1.4153 + ciMethod* m = caller_jvms->method(); 1.4154 + switch (n) { 1.4155 + case 0: 1.4156 + fatal("current JVM state does not include the Reflection.getCallerClass frame"); 1.4157 + break; 1.4158 + case 1: 1.4159 + // Frame 0 and 1 must be caller sensitive (see JVM_GetCallerClass). 1.4160 + if (!m->caller_sensitive()) { 1.4161 +#ifndef PRODUCT 1.4162 + if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 1.4163 + tty->print_cr(" Bailing out: CallerSensitive annotation expected at frame %d", n); 1.4164 + } 1.4165 +#endif 1.4166 + return false; // bail-out; let JVM_GetCallerClass do the work 1.4167 + } 1.4168 + break; 1.4169 + default: 1.4170 + if (!m->is_ignored_by_security_stack_walk()) { 1.4171 + // We have reached the desired frame; return the holder class. 1.4172 + // Acquire method holder as java.lang.Class and push as constant. 1.4173 + ciInstanceKlass* caller_klass = caller_jvms->method()->holder(); 1.4174 + ciInstance* caller_mirror = caller_klass->java_mirror(); 1.4175 + set_result(makecon(TypeInstPtr::make(caller_mirror))); 1.4176 + 1.4177 +#ifndef PRODUCT 1.4178 + if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 1.4179 + tty->print_cr(" Succeeded: caller = %d) %s.%s, JVMS depth = %d", n, caller_klass->name()->as_utf8(), caller_jvms->method()->name()->as_utf8(), jvms()->depth()); 1.4180 + tty->print_cr(" JVM state at this point:"); 1.4181 + for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) { 1.4182 + ciMethod* m = jvms()->of_depth(i)->method(); 1.4183 + tty->print_cr(" %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8()); 1.4184 + } 1.4185 + } 1.4186 +#endif 1.4187 + return true; 1.4188 + } 1.4189 + break; 1.4190 + } 1.4191 + } 1.4192 + 1.4193 +#ifndef PRODUCT 1.4194 + if ((C->print_intrinsics() || C->print_inlining()) && Verbose) { 1.4195 + tty->print_cr(" Bailing out because caller depth exceeded inlining depth = %d", jvms()->depth()); 1.4196 + tty->print_cr(" JVM state at this point:"); 1.4197 + for (int i = jvms()->depth(), n = 1; i >= 1; i--, n++) { 1.4198 + ciMethod* m = jvms()->of_depth(i)->method(); 1.4199 + tty->print_cr(" %d) %s.%s", n, m->holder()->name()->as_utf8(), m->name()->as_utf8()); 1.4200 + } 1.4201 + } 1.4202 +#endif 1.4203 + 1.4204 + return false; // bail-out; let JVM_GetCallerClass do the work 1.4205 +} 1.4206 + 1.4207 +bool LibraryCallKit::inline_fp_conversions(vmIntrinsics::ID id) { 1.4208 + Node* arg = argument(0); 1.4209 + Node* result; 1.4210 + 1.4211 + switch (id) { 1.4212 + case vmIntrinsics::_floatToRawIntBits: result = new (C) MoveF2INode(arg); break; 1.4213 + case vmIntrinsics::_intBitsToFloat: result = new (C) MoveI2FNode(arg); break; 1.4214 + case vmIntrinsics::_doubleToRawLongBits: result = new (C) MoveD2LNode(arg); break; 1.4215 + case vmIntrinsics::_longBitsToDouble: result = new (C) MoveL2DNode(arg); break; 1.4216 + 1.4217 + case vmIntrinsics::_doubleToLongBits: { 1.4218 + // two paths (plus control) merge in a wood 1.4219 + RegionNode *r = new (C) RegionNode(3); 1.4220 + Node *phi = new (C) PhiNode(r, TypeLong::LONG); 1.4221 + 1.4222 + Node *cmpisnan = _gvn.transform(new (C) CmpDNode(arg, arg)); 1.4223 + // Build the boolean node 1.4224 + Node *bolisnan = _gvn.transform(new (C) BoolNode(cmpisnan, BoolTest::ne)); 1.4225 + 1.4226 + // Branch either way. 1.4227 + // NaN case is less traveled, which makes all the difference. 1.4228 + IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 1.4229 + Node *opt_isnan = _gvn.transform(ifisnan); 1.4230 + assert( opt_isnan->is_If(), "Expect an IfNode"); 1.4231 + IfNode *opt_ifisnan = (IfNode*)opt_isnan; 1.4232 + Node *iftrue = _gvn.transform(new (C) IfTrueNode(opt_ifisnan)); 1.4233 + 1.4234 + set_control(iftrue); 1.4235 + 1.4236 + static const jlong nan_bits = CONST64(0x7ff8000000000000); 1.4237 + Node *slow_result = longcon(nan_bits); // return NaN 1.4238 + phi->init_req(1, _gvn.transform( slow_result )); 1.4239 + r->init_req(1, iftrue); 1.4240 + 1.4241 + // Else fall through 1.4242 + Node *iffalse = _gvn.transform(new (C) IfFalseNode(opt_ifisnan)); 1.4243 + set_control(iffalse); 1.4244 + 1.4245 + phi->init_req(2, _gvn.transform(new (C) MoveD2LNode(arg))); 1.4246 + r->init_req(2, iffalse); 1.4247 + 1.4248 + // Post merge 1.4249 + set_control(_gvn.transform(r)); 1.4250 + record_for_igvn(r); 1.4251 + 1.4252 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.4253 + result = phi; 1.4254 + assert(result->bottom_type()->isa_long(), "must be"); 1.4255 + break; 1.4256 + } 1.4257 + 1.4258 + case vmIntrinsics::_floatToIntBits: { 1.4259 + // two paths (plus control) merge in a wood 1.4260 + RegionNode *r = new (C) RegionNode(3); 1.4261 + Node *phi = new (C) PhiNode(r, TypeInt::INT); 1.4262 + 1.4263 + Node *cmpisnan = _gvn.transform(new (C) CmpFNode(arg, arg)); 1.4264 + // Build the boolean node 1.4265 + Node *bolisnan = _gvn.transform(new (C) BoolNode(cmpisnan, BoolTest::ne)); 1.4266 + 1.4267 + // Branch either way. 1.4268 + // NaN case is less traveled, which makes all the difference. 1.4269 + IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 1.4270 + Node *opt_isnan = _gvn.transform(ifisnan); 1.4271 + assert( opt_isnan->is_If(), "Expect an IfNode"); 1.4272 + IfNode *opt_ifisnan = (IfNode*)opt_isnan; 1.4273 + Node *iftrue = _gvn.transform(new (C) IfTrueNode(opt_ifisnan)); 1.4274 + 1.4275 + set_control(iftrue); 1.4276 + 1.4277 + static const jint nan_bits = 0x7fc00000; 1.4278 + Node *slow_result = makecon(TypeInt::make(nan_bits)); // return NaN 1.4279 + phi->init_req(1, _gvn.transform( slow_result )); 1.4280 + r->init_req(1, iftrue); 1.4281 + 1.4282 + // Else fall through 1.4283 + Node *iffalse = _gvn.transform(new (C) IfFalseNode(opt_ifisnan)); 1.4284 + set_control(iffalse); 1.4285 + 1.4286 + phi->init_req(2, _gvn.transform(new (C) MoveF2INode(arg))); 1.4287 + r->init_req(2, iffalse); 1.4288 + 1.4289 + // Post merge 1.4290 + set_control(_gvn.transform(r)); 1.4291 + record_for_igvn(r); 1.4292 + 1.4293 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.4294 + result = phi; 1.4295 + assert(result->bottom_type()->isa_int(), "must be"); 1.4296 + break; 1.4297 + } 1.4298 + 1.4299 + default: 1.4300 + fatal_unexpected_iid(id); 1.4301 + break; 1.4302 + } 1.4303 + set_result(_gvn.transform(result)); 1.4304 + return true; 1.4305 +} 1.4306 + 1.4307 +#ifdef _LP64 1.4308 +#define XTOP ,top() /*additional argument*/ 1.4309 +#else //_LP64 1.4310 +#define XTOP /*no additional argument*/ 1.4311 +#endif //_LP64 1.4312 + 1.4313 +//----------------------inline_unsafe_copyMemory------------------------- 1.4314 +// public native void sun.misc.Unsafe.copyMemory(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes); 1.4315 +bool LibraryCallKit::inline_unsafe_copyMemory() { 1.4316 + if (callee()->is_static()) return false; // caller must have the capability! 1.4317 + null_check_receiver(); // null-check receiver 1.4318 + if (stopped()) return true; 1.4319 + 1.4320 + C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 1.4321 + 1.4322 + Node* src_ptr = argument(1); // type: oop 1.4323 + Node* src_off = ConvL2X(argument(2)); // type: long 1.4324 + Node* dst_ptr = argument(4); // type: oop 1.4325 + Node* dst_off = ConvL2X(argument(5)); // type: long 1.4326 + Node* size = ConvL2X(argument(7)); // type: long 1.4327 + 1.4328 + assert(Unsafe_field_offset_to_byte_offset(11) == 11, 1.4329 + "fieldOffset must be byte-scaled"); 1.4330 + 1.4331 + Node* src = make_unsafe_address(src_ptr, src_off); 1.4332 + Node* dst = make_unsafe_address(dst_ptr, dst_off); 1.4333 + 1.4334 + // Conservatively insert a memory barrier on all memory slices. 1.4335 + // Do not let writes of the copy source or destination float below the copy. 1.4336 + insert_mem_bar(Op_MemBarCPUOrder); 1.4337 + 1.4338 + // Call it. Note that the length argument is not scaled. 1.4339 + make_runtime_call(RC_LEAF|RC_NO_FP, 1.4340 + OptoRuntime::fast_arraycopy_Type(), 1.4341 + StubRoutines::unsafe_arraycopy(), 1.4342 + "unsafe_arraycopy", 1.4343 + TypeRawPtr::BOTTOM, 1.4344 + src, dst, size XTOP); 1.4345 + 1.4346 + // Do not let reads of the copy destination float above the copy. 1.4347 + insert_mem_bar(Op_MemBarCPUOrder); 1.4348 + 1.4349 + return true; 1.4350 +} 1.4351 + 1.4352 +//------------------------clone_coping----------------------------------- 1.4353 +// Helper function for inline_native_clone. 1.4354 +void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array, bool card_mark) { 1.4355 + assert(obj_size != NULL, ""); 1.4356 + Node* raw_obj = alloc_obj->in(1); 1.4357 + assert(alloc_obj->is_CheckCastPP() && raw_obj->is_Proj() && raw_obj->in(0)->is_Allocate(), ""); 1.4358 + 1.4359 + AllocateNode* alloc = NULL; 1.4360 + if (ReduceBulkZeroing) { 1.4361 + // We will be completely responsible for initializing this object - 1.4362 + // mark Initialize node as complete. 1.4363 + alloc = AllocateNode::Ideal_allocation(alloc_obj, &_gvn); 1.4364 + // The object was just allocated - there should be no any stores! 1.4365 + guarantee(alloc != NULL && alloc->maybe_set_complete(&_gvn), ""); 1.4366 + // Mark as complete_with_arraycopy so that on AllocateNode 1.4367 + // expansion, we know this AllocateNode is initialized by an array 1.4368 + // copy and a StoreStore barrier exists after the array copy. 1.4369 + alloc->initialization()->set_complete_with_arraycopy(); 1.4370 + } 1.4371 + 1.4372 + // Copy the fastest available way. 1.4373 + // TODO: generate fields copies for small objects instead. 1.4374 + Node* src = obj; 1.4375 + Node* dest = alloc_obj; 1.4376 + Node* size = _gvn.transform(obj_size); 1.4377 + 1.4378 + // Exclude the header but include array length to copy by 8 bytes words. 1.4379 + // Can't use base_offset_in_bytes(bt) since basic type is unknown. 1.4380 + int base_off = is_array ? arrayOopDesc::length_offset_in_bytes() : 1.4381 + instanceOopDesc::base_offset_in_bytes(); 1.4382 + // base_off: 1.4383 + // 8 - 32-bit VM 1.4384 + // 12 - 64-bit VM, compressed klass 1.4385 + // 16 - 64-bit VM, normal klass 1.4386 + if (base_off % BytesPerLong != 0) { 1.4387 + assert(UseCompressedClassPointers, ""); 1.4388 + if (is_array) { 1.4389 + // Exclude length to copy by 8 bytes words. 1.4390 + base_off += sizeof(int); 1.4391 + } else { 1.4392 + // Include klass to copy by 8 bytes words. 1.4393 + base_off = instanceOopDesc::klass_offset_in_bytes(); 1.4394 + } 1.4395 + assert(base_off % BytesPerLong == 0, "expect 8 bytes alignment"); 1.4396 + } 1.4397 + src = basic_plus_adr(src, base_off); 1.4398 + dest = basic_plus_adr(dest, base_off); 1.4399 + 1.4400 + // Compute the length also, if needed: 1.4401 + Node* countx = size; 1.4402 + countx = _gvn.transform(new (C) SubXNode(countx, MakeConX(base_off))); 1.4403 + countx = _gvn.transform(new (C) URShiftXNode(countx, intcon(LogBytesPerLong) )); 1.4404 + 1.4405 + const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM; 1.4406 + bool disjoint_bases = true; 1.4407 + generate_unchecked_arraycopy(raw_adr_type, T_LONG, disjoint_bases, 1.4408 + src, NULL, dest, NULL, countx, 1.4409 + /*dest_uninitialized*/true); 1.4410 + 1.4411 + // If necessary, emit some card marks afterwards. (Non-arrays only.) 1.4412 + if (card_mark) { 1.4413 + assert(!is_array, ""); 1.4414 + // Put in store barrier for any and all oops we are sticking 1.4415 + // into this object. (We could avoid this if we could prove 1.4416 + // that the object type contains no oop fields at all.) 1.4417 + Node* no_particular_value = NULL; 1.4418 + Node* no_particular_field = NULL; 1.4419 + int raw_adr_idx = Compile::AliasIdxRaw; 1.4420 + post_barrier(control(), 1.4421 + memory(raw_adr_type), 1.4422 + alloc_obj, 1.4423 + no_particular_field, 1.4424 + raw_adr_idx, 1.4425 + no_particular_value, 1.4426 + T_OBJECT, 1.4427 + false); 1.4428 + } 1.4429 + 1.4430 + // Do not let reads from the cloned object float above the arraycopy. 1.4431 + if (alloc != NULL) { 1.4432 + // Do not let stores that initialize this object be reordered with 1.4433 + // a subsequent store that would make this object accessible by 1.4434 + // other threads. 1.4435 + // Record what AllocateNode this StoreStore protects so that 1.4436 + // escape analysis can go from the MemBarStoreStoreNode to the 1.4437 + // AllocateNode and eliminate the MemBarStoreStoreNode if possible 1.4438 + // based on the escape status of the AllocateNode. 1.4439 + insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out(AllocateNode::RawAddress)); 1.4440 + } else { 1.4441 + insert_mem_bar(Op_MemBarCPUOrder); 1.4442 + } 1.4443 +} 1.4444 + 1.4445 +//------------------------inline_native_clone---------------------------- 1.4446 +// protected native Object java.lang.Object.clone(); 1.4447 +// 1.4448 +// Here are the simple edge cases: 1.4449 +// null receiver => normal trap 1.4450 +// virtual and clone was overridden => slow path to out-of-line clone 1.4451 +// not cloneable or finalizer => slow path to out-of-line Object.clone 1.4452 +// 1.4453 +// The general case has two steps, allocation and copying. 1.4454 +// Allocation has two cases, and uses GraphKit::new_instance or new_array. 1.4455 +// 1.4456 +// Copying also has two cases, oop arrays and everything else. 1.4457 +// Oop arrays use arrayof_oop_arraycopy (same as System.arraycopy). 1.4458 +// Everything else uses the tight inline loop supplied by CopyArrayNode. 1.4459 +// 1.4460 +// These steps fold up nicely if and when the cloned object's klass 1.4461 +// can be sharply typed as an object array, a type array, or an instance. 1.4462 +// 1.4463 +bool LibraryCallKit::inline_native_clone(bool is_virtual) { 1.4464 + PhiNode* result_val; 1.4465 + 1.4466 + // Set the reexecute bit for the interpreter to reexecute 1.4467 + // the bytecode that invokes Object.clone if deoptimization happens. 1.4468 + { PreserveReexecuteState preexecs(this); 1.4469 + jvms()->set_should_reexecute(true); 1.4470 + 1.4471 + Node* obj = null_check_receiver(); 1.4472 + if (stopped()) return true; 1.4473 + 1.4474 + Node* obj_klass = load_object_klass(obj); 1.4475 + const TypeKlassPtr* tklass = _gvn.type(obj_klass)->isa_klassptr(); 1.4476 + const TypeOopPtr* toop = ((tklass != NULL) 1.4477 + ? tklass->as_instance_type() 1.4478 + : TypeInstPtr::NOTNULL); 1.4479 + 1.4480 + // Conservatively insert a memory barrier on all memory slices. 1.4481 + // Do not let writes into the original float below the clone. 1.4482 + insert_mem_bar(Op_MemBarCPUOrder); 1.4483 + 1.4484 + // paths into result_reg: 1.4485 + enum { 1.4486 + _slow_path = 1, // out-of-line call to clone method (virtual or not) 1.4487 + _objArray_path, // plain array allocation, plus arrayof_oop_arraycopy 1.4488 + _array_path, // plain array allocation, plus arrayof_long_arraycopy 1.4489 + _instance_path, // plain instance allocation, plus arrayof_long_arraycopy 1.4490 + PATH_LIMIT 1.4491 + }; 1.4492 + RegionNode* result_reg = new(C) RegionNode(PATH_LIMIT); 1.4493 + result_val = new(C) PhiNode(result_reg, 1.4494 + TypeInstPtr::NOTNULL); 1.4495 + PhiNode* result_i_o = new(C) PhiNode(result_reg, Type::ABIO); 1.4496 + PhiNode* result_mem = new(C) PhiNode(result_reg, Type::MEMORY, 1.4497 + TypePtr::BOTTOM); 1.4498 + record_for_igvn(result_reg); 1.4499 + 1.4500 + const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM; 1.4501 + int raw_adr_idx = Compile::AliasIdxRaw; 1.4502 + 1.4503 + Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)NULL); 1.4504 + if (array_ctl != NULL) { 1.4505 + // It's an array. 1.4506 + PreserveJVMState pjvms(this); 1.4507 + set_control(array_ctl); 1.4508 + Node* obj_length = load_array_length(obj); 1.4509 + Node* obj_size = NULL; 1.4510 + Node* alloc_obj = new_array(obj_klass, obj_length, 0, &obj_size); // no arguments to push 1.4511 + 1.4512 + if (!use_ReduceInitialCardMarks()) { 1.4513 + // If it is an oop array, it requires very special treatment, 1.4514 + // because card marking is required on each card of the array. 1.4515 + Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)NULL); 1.4516 + if (is_obja != NULL) { 1.4517 + PreserveJVMState pjvms2(this); 1.4518 + set_control(is_obja); 1.4519 + // Generate a direct call to the right arraycopy function(s). 1.4520 + bool disjoint_bases = true; 1.4521 + bool length_never_negative = true; 1.4522 + generate_arraycopy(TypeAryPtr::OOPS, T_OBJECT, 1.4523 + obj, intcon(0), alloc_obj, intcon(0), 1.4524 + obj_length, 1.4525 + disjoint_bases, length_never_negative); 1.4526 + result_reg->init_req(_objArray_path, control()); 1.4527 + result_val->init_req(_objArray_path, alloc_obj); 1.4528 + result_i_o ->set_req(_objArray_path, i_o()); 1.4529 + result_mem ->set_req(_objArray_path, reset_memory()); 1.4530 + } 1.4531 + } 1.4532 + // Otherwise, there are no card marks to worry about. 1.4533 + // (We can dispense with card marks if we know the allocation 1.4534 + // comes out of eden (TLAB)... In fact, ReduceInitialCardMarks 1.4535 + // causes the non-eden paths to take compensating steps to 1.4536 + // simulate a fresh allocation, so that no further 1.4537 + // card marks are required in compiled code to initialize 1.4538 + // the object.) 1.4539 + 1.4540 + if (!stopped()) { 1.4541 + copy_to_clone(obj, alloc_obj, obj_size, true, false); 1.4542 + 1.4543 + // Present the results of the copy. 1.4544 + result_reg->init_req(_array_path, control()); 1.4545 + result_val->init_req(_array_path, alloc_obj); 1.4546 + result_i_o ->set_req(_array_path, i_o()); 1.4547 + result_mem ->set_req(_array_path, reset_memory()); 1.4548 + } 1.4549 + } 1.4550 + 1.4551 + // We only go to the instance fast case code if we pass a number of guards. 1.4552 + // The paths which do not pass are accumulated in the slow_region. 1.4553 + RegionNode* slow_region = new (C) RegionNode(1); 1.4554 + record_for_igvn(slow_region); 1.4555 + if (!stopped()) { 1.4556 + // It's an instance (we did array above). Make the slow-path tests. 1.4557 + // If this is a virtual call, we generate a funny guard. We grab 1.4558 + // the vtable entry corresponding to clone() from the target object. 1.4559 + // If the target method which we are calling happens to be the 1.4560 + // Object clone() method, we pass the guard. We do not need this 1.4561 + // guard for non-virtual calls; the caller is known to be the native 1.4562 + // Object clone(). 1.4563 + if (is_virtual) { 1.4564 + generate_virtual_guard(obj_klass, slow_region); 1.4565 + } 1.4566 + 1.4567 + // The object must be cloneable and must not have a finalizer. 1.4568 + // Both of these conditions may be checked in a single test. 1.4569 + // We could optimize the cloneable test further, but we don't care. 1.4570 + generate_access_flags_guard(obj_klass, 1.4571 + // Test both conditions: 1.4572 + JVM_ACC_IS_CLONEABLE | JVM_ACC_HAS_FINALIZER, 1.4573 + // Must be cloneable but not finalizer: 1.4574 + JVM_ACC_IS_CLONEABLE, 1.4575 + slow_region); 1.4576 + } 1.4577 + 1.4578 + if (!stopped()) { 1.4579 + // It's an instance, and it passed the slow-path tests. 1.4580 + PreserveJVMState pjvms(this); 1.4581 + Node* obj_size = NULL; 1.4582 + // Need to deoptimize on exception from allocation since Object.clone intrinsic 1.4583 + // is reexecuted if deoptimization occurs and there could be problems when merging 1.4584 + // exception state between multiple Object.clone versions (reexecute=true vs reexecute=false). 1.4585 + Node* alloc_obj = new_instance(obj_klass, NULL, &obj_size, /*deoptimize_on_exception=*/true); 1.4586 + 1.4587 + copy_to_clone(obj, alloc_obj, obj_size, false, !use_ReduceInitialCardMarks()); 1.4588 + 1.4589 + // Present the results of the slow call. 1.4590 + result_reg->init_req(_instance_path, control()); 1.4591 + result_val->init_req(_instance_path, alloc_obj); 1.4592 + result_i_o ->set_req(_instance_path, i_o()); 1.4593 + result_mem ->set_req(_instance_path, reset_memory()); 1.4594 + } 1.4595 + 1.4596 + // Generate code for the slow case. We make a call to clone(). 1.4597 + set_control(_gvn.transform(slow_region)); 1.4598 + if (!stopped()) { 1.4599 + PreserveJVMState pjvms(this); 1.4600 + CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_clone, is_virtual); 1.4601 + Node* slow_result = set_results_for_java_call(slow_call); 1.4602 + // this->control() comes from set_results_for_java_call 1.4603 + result_reg->init_req(_slow_path, control()); 1.4604 + result_val->init_req(_slow_path, slow_result); 1.4605 + result_i_o ->set_req(_slow_path, i_o()); 1.4606 + result_mem ->set_req(_slow_path, reset_memory()); 1.4607 + } 1.4608 + 1.4609 + // Return the combined state. 1.4610 + set_control( _gvn.transform(result_reg)); 1.4611 + set_i_o( _gvn.transform(result_i_o)); 1.4612 + set_all_memory( _gvn.transform(result_mem)); 1.4613 + } // original reexecute is set back here 1.4614 + 1.4615 + set_result(_gvn.transform(result_val)); 1.4616 + return true; 1.4617 +} 1.4618 + 1.4619 +//------------------------------basictype2arraycopy---------------------------- 1.4620 +address LibraryCallKit::basictype2arraycopy(BasicType t, 1.4621 + Node* src_offset, 1.4622 + Node* dest_offset, 1.4623 + bool disjoint_bases, 1.4624 + const char* &name, 1.4625 + bool dest_uninitialized) { 1.4626 + const TypeInt* src_offset_inttype = gvn().find_int_type(src_offset);; 1.4627 + const TypeInt* dest_offset_inttype = gvn().find_int_type(dest_offset);; 1.4628 + 1.4629 + bool aligned = false; 1.4630 + bool disjoint = disjoint_bases; 1.4631 + 1.4632 + // if the offsets are the same, we can treat the memory regions as 1.4633 + // disjoint, because either the memory regions are in different arrays, 1.4634 + // or they are identical (which we can treat as disjoint.) We can also 1.4635 + // treat a copy with a destination index less that the source index 1.4636 + // as disjoint since a low->high copy will work correctly in this case. 1.4637 + if (src_offset_inttype != NULL && src_offset_inttype->is_con() && 1.4638 + dest_offset_inttype != NULL && dest_offset_inttype->is_con()) { 1.4639 + // both indices are constants 1.4640 + int s_offs = src_offset_inttype->get_con(); 1.4641 + int d_offs = dest_offset_inttype->get_con(); 1.4642 + int element_size = type2aelembytes(t); 1.4643 + aligned = ((arrayOopDesc::base_offset_in_bytes(t) + s_offs * element_size) % HeapWordSize == 0) && 1.4644 + ((arrayOopDesc::base_offset_in_bytes(t) + d_offs * element_size) % HeapWordSize == 0); 1.4645 + if (s_offs >= d_offs) disjoint = true; 1.4646 + } else if (src_offset == dest_offset && src_offset != NULL) { 1.4647 + // This can occur if the offsets are identical non-constants. 1.4648 + disjoint = true; 1.4649 + } 1.4650 + 1.4651 + return StubRoutines::select_arraycopy_function(t, aligned, disjoint, name, dest_uninitialized); 1.4652 +} 1.4653 + 1.4654 + 1.4655 +//------------------------------inline_arraycopy----------------------- 1.4656 +// public static native void java.lang.System.arraycopy(Object src, int srcPos, 1.4657 +// Object dest, int destPos, 1.4658 +// int length); 1.4659 +bool LibraryCallKit::inline_arraycopy() { 1.4660 + // Get the arguments. 1.4661 + Node* src = argument(0); // type: oop 1.4662 + Node* src_offset = argument(1); // type: int 1.4663 + Node* dest = argument(2); // type: oop 1.4664 + Node* dest_offset = argument(3); // type: int 1.4665 + Node* length = argument(4); // type: int 1.4666 + 1.4667 + // Compile time checks. If any of these checks cannot be verified at compile time, 1.4668 + // we do not make a fast path for this call. Instead, we let the call remain as it 1.4669 + // is. The checks we choose to mandate at compile time are: 1.4670 + // 1.4671 + // (1) src and dest are arrays. 1.4672 + const Type* src_type = src->Value(&_gvn); 1.4673 + const Type* dest_type = dest->Value(&_gvn); 1.4674 + const TypeAryPtr* top_src = src_type->isa_aryptr(); 1.4675 + const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 1.4676 + 1.4677 + // Do we have the type of src? 1.4678 + bool has_src = (top_src != NULL && top_src->klass() != NULL); 1.4679 + // Do we have the type of dest? 1.4680 + bool has_dest = (top_dest != NULL && top_dest->klass() != NULL); 1.4681 + // Is the type for src from speculation? 1.4682 + bool src_spec = false; 1.4683 + // Is the type for dest from speculation? 1.4684 + bool dest_spec = false; 1.4685 + 1.4686 + if (!has_src || !has_dest) { 1.4687 + // We don't have sufficient type information, let's see if 1.4688 + // speculative types can help. We need to have types for both src 1.4689 + // and dest so that it pays off. 1.4690 + 1.4691 + // Do we already have or could we have type information for src 1.4692 + bool could_have_src = has_src; 1.4693 + // Do we already have or could we have type information for dest 1.4694 + bool could_have_dest = has_dest; 1.4695 + 1.4696 + ciKlass* src_k = NULL; 1.4697 + if (!has_src) { 1.4698 + src_k = src_type->speculative_type(); 1.4699 + if (src_k != NULL && src_k->is_array_klass()) { 1.4700 + could_have_src = true; 1.4701 + } 1.4702 + } 1.4703 + 1.4704 + ciKlass* dest_k = NULL; 1.4705 + if (!has_dest) { 1.4706 + dest_k = dest_type->speculative_type(); 1.4707 + if (dest_k != NULL && dest_k->is_array_klass()) { 1.4708 + could_have_dest = true; 1.4709 + } 1.4710 + } 1.4711 + 1.4712 + if (could_have_src && could_have_dest) { 1.4713 + // This is going to pay off so emit the required guards 1.4714 + if (!has_src) { 1.4715 + src = maybe_cast_profiled_obj(src, src_k); 1.4716 + src_type = _gvn.type(src); 1.4717 + top_src = src_type->isa_aryptr(); 1.4718 + has_src = (top_src != NULL && top_src->klass() != NULL); 1.4719 + src_spec = true; 1.4720 + } 1.4721 + if (!has_dest) { 1.4722 + dest = maybe_cast_profiled_obj(dest, dest_k); 1.4723 + dest_type = _gvn.type(dest); 1.4724 + top_dest = dest_type->isa_aryptr(); 1.4725 + has_dest = (top_dest != NULL && top_dest->klass() != NULL); 1.4726 + dest_spec = true; 1.4727 + } 1.4728 + } 1.4729 + } 1.4730 + 1.4731 + if (!has_src || !has_dest) { 1.4732 + // Conservatively insert a memory barrier on all memory slices. 1.4733 + // Do not let writes into the source float below the arraycopy. 1.4734 + insert_mem_bar(Op_MemBarCPUOrder); 1.4735 + 1.4736 + // Call StubRoutines::generic_arraycopy stub. 1.4737 + generate_arraycopy(TypeRawPtr::BOTTOM, T_CONFLICT, 1.4738 + src, src_offset, dest, dest_offset, length); 1.4739 + 1.4740 + // Do not let reads from the destination float above the arraycopy. 1.4741 + // Since we cannot type the arrays, we don't know which slices 1.4742 + // might be affected. We could restrict this barrier only to those 1.4743 + // memory slices which pertain to array elements--but don't bother. 1.4744 + if (!InsertMemBarAfterArraycopy) 1.4745 + // (If InsertMemBarAfterArraycopy, there is already one in place.) 1.4746 + insert_mem_bar(Op_MemBarCPUOrder); 1.4747 + return true; 1.4748 + } 1.4749 + 1.4750 + // (2) src and dest arrays must have elements of the same BasicType 1.4751 + // Figure out the size and type of the elements we will be copying. 1.4752 + BasicType src_elem = top_src->klass()->as_array_klass()->element_type()->basic_type(); 1.4753 + BasicType dest_elem = top_dest->klass()->as_array_klass()->element_type()->basic_type(); 1.4754 + if (src_elem == T_ARRAY) src_elem = T_OBJECT; 1.4755 + if (dest_elem == T_ARRAY) dest_elem = T_OBJECT; 1.4756 + 1.4757 + if (src_elem != dest_elem || dest_elem == T_VOID) { 1.4758 + // The component types are not the same or are not recognized. Punt. 1.4759 + // (But, avoid the native method wrapper to JVM_ArrayCopy.) 1.4760 + generate_slow_arraycopy(TypePtr::BOTTOM, 1.4761 + src, src_offset, dest, dest_offset, length, 1.4762 + /*dest_uninitialized*/false); 1.4763 + return true; 1.4764 + } 1.4765 + 1.4766 + if (src_elem == T_OBJECT) { 1.4767 + // If both arrays are object arrays then having the exact types 1.4768 + // for both will remove the need for a subtype check at runtime 1.4769 + // before the call and may make it possible to pick a faster copy 1.4770 + // routine (without a subtype check on every element) 1.4771 + // Do we have the exact type of src? 1.4772 + bool could_have_src = src_spec; 1.4773 + // Do we have the exact type of dest? 1.4774 + bool could_have_dest = dest_spec; 1.4775 + ciKlass* src_k = top_src->klass(); 1.4776 + ciKlass* dest_k = top_dest->klass(); 1.4777 + if (!src_spec) { 1.4778 + src_k = src_type->speculative_type(); 1.4779 + if (src_k != NULL && src_k->is_array_klass()) { 1.4780 + could_have_src = true; 1.4781 + } 1.4782 + } 1.4783 + if (!dest_spec) { 1.4784 + dest_k = dest_type->speculative_type(); 1.4785 + if (dest_k != NULL && dest_k->is_array_klass()) { 1.4786 + could_have_dest = true; 1.4787 + } 1.4788 + } 1.4789 + if (could_have_src && could_have_dest) { 1.4790 + // If we can have both exact types, emit the missing guards 1.4791 + if (could_have_src && !src_spec) { 1.4792 + src = maybe_cast_profiled_obj(src, src_k); 1.4793 + } 1.4794 + if (could_have_dest && !dest_spec) { 1.4795 + dest = maybe_cast_profiled_obj(dest, dest_k); 1.4796 + } 1.4797 + } 1.4798 + } 1.4799 + 1.4800 + //--------------------------------------------------------------------------- 1.4801 + // We will make a fast path for this call to arraycopy. 1.4802 + 1.4803 + // We have the following tests left to perform: 1.4804 + // 1.4805 + // (3) src and dest must not be null. 1.4806 + // (4) src_offset must not be negative. 1.4807 + // (5) dest_offset must not be negative. 1.4808 + // (6) length must not be negative. 1.4809 + // (7) src_offset + length must not exceed length of src. 1.4810 + // (8) dest_offset + length must not exceed length of dest. 1.4811 + // (9) each element of an oop array must be assignable 1.4812 + 1.4813 + RegionNode* slow_region = new (C) RegionNode(1); 1.4814 + record_for_igvn(slow_region); 1.4815 + 1.4816 + // (3) operands must not be null 1.4817 + // We currently perform our null checks with the null_check routine. 1.4818 + // This means that the null exceptions will be reported in the caller 1.4819 + // rather than (correctly) reported inside of the native arraycopy call. 1.4820 + // This should be corrected, given time. We do our null check with the 1.4821 + // stack pointer restored. 1.4822 + src = null_check(src, T_ARRAY); 1.4823 + dest = null_check(dest, T_ARRAY); 1.4824 + 1.4825 + // (4) src_offset must not be negative. 1.4826 + generate_negative_guard(src_offset, slow_region); 1.4827 + 1.4828 + // (5) dest_offset must not be negative. 1.4829 + generate_negative_guard(dest_offset, slow_region); 1.4830 + 1.4831 + // (6) length must not be negative (moved to generate_arraycopy()). 1.4832 + // generate_negative_guard(length, slow_region); 1.4833 + 1.4834 + // (7) src_offset + length must not exceed length of src. 1.4835 + generate_limit_guard(src_offset, length, 1.4836 + load_array_length(src), 1.4837 + slow_region); 1.4838 + 1.4839 + // (8) dest_offset + length must not exceed length of dest. 1.4840 + generate_limit_guard(dest_offset, length, 1.4841 + load_array_length(dest), 1.4842 + slow_region); 1.4843 + 1.4844 + // (9) each element of an oop array must be assignable 1.4845 + // The generate_arraycopy subroutine checks this. 1.4846 + 1.4847 + // This is where the memory effects are placed: 1.4848 + const TypePtr* adr_type = TypeAryPtr::get_array_body_type(dest_elem); 1.4849 + generate_arraycopy(adr_type, dest_elem, 1.4850 + src, src_offset, dest, dest_offset, length, 1.4851 + false, false, slow_region); 1.4852 + 1.4853 + return true; 1.4854 +} 1.4855 + 1.4856 +//-----------------------------generate_arraycopy---------------------- 1.4857 +// Generate an optimized call to arraycopy. 1.4858 +// Caller must guard against non-arrays. 1.4859 +// Caller must determine a common array basic-type for both arrays. 1.4860 +// Caller must validate offsets against array bounds. 1.4861 +// The slow_region has already collected guard failure paths 1.4862 +// (such as out of bounds length or non-conformable array types). 1.4863 +// The generated code has this shape, in general: 1.4864 +// 1.4865 +// if (length == 0) return // via zero_path 1.4866 +// slowval = -1 1.4867 +// if (types unknown) { 1.4868 +// slowval = call generic copy loop 1.4869 +// if (slowval == 0) return // via checked_path 1.4870 +// } else if (indexes in bounds) { 1.4871 +// if ((is object array) && !(array type check)) { 1.4872 +// slowval = call checked copy loop 1.4873 +// if (slowval == 0) return // via checked_path 1.4874 +// } else { 1.4875 +// call bulk copy loop 1.4876 +// return // via fast_path 1.4877 +// } 1.4878 +// } 1.4879 +// // adjust params for remaining work: 1.4880 +// if (slowval != -1) { 1.4881 +// n = -1^slowval; src_offset += n; dest_offset += n; length -= n 1.4882 +// } 1.4883 +// slow_region: 1.4884 +// call slow arraycopy(src, src_offset, dest, dest_offset, length) 1.4885 +// return // via slow_call_path 1.4886 +// 1.4887 +// This routine is used from several intrinsics: System.arraycopy, 1.4888 +// Object.clone (the array subcase), and Arrays.copyOf[Range]. 1.4889 +// 1.4890 +void 1.4891 +LibraryCallKit::generate_arraycopy(const TypePtr* adr_type, 1.4892 + BasicType basic_elem_type, 1.4893 + Node* src, Node* src_offset, 1.4894 + Node* dest, Node* dest_offset, 1.4895 + Node* copy_length, 1.4896 + bool disjoint_bases, 1.4897 + bool length_never_negative, 1.4898 + RegionNode* slow_region) { 1.4899 + 1.4900 + if (slow_region == NULL) { 1.4901 + slow_region = new(C) RegionNode(1); 1.4902 + record_for_igvn(slow_region); 1.4903 + } 1.4904 + 1.4905 + Node* original_dest = dest; 1.4906 + AllocateArrayNode* alloc = NULL; // used for zeroing, if needed 1.4907 + bool dest_uninitialized = false; 1.4908 + 1.4909 + // See if this is the initialization of a newly-allocated array. 1.4910 + // If so, we will take responsibility here for initializing it to zero. 1.4911 + // (Note: Because tightly_coupled_allocation performs checks on the 1.4912 + // out-edges of the dest, we need to avoid making derived pointers 1.4913 + // from it until we have checked its uses.) 1.4914 + if (ReduceBulkZeroing 1.4915 + && !ZeroTLAB // pointless if already zeroed 1.4916 + && basic_elem_type != T_CONFLICT // avoid corner case 1.4917 + && !src->eqv_uncast(dest) 1.4918 + && ((alloc = tightly_coupled_allocation(dest, slow_region)) 1.4919 + != NULL) 1.4920 + && _gvn.find_int_con(alloc->in(AllocateNode::ALength), 1) > 0 1.4921 + && alloc->maybe_set_complete(&_gvn)) { 1.4922 + // "You break it, you buy it." 1.4923 + InitializeNode* init = alloc->initialization(); 1.4924 + assert(init->is_complete(), "we just did this"); 1.4925 + init->set_complete_with_arraycopy(); 1.4926 + assert(dest->is_CheckCastPP(), "sanity"); 1.4927 + assert(dest->in(0)->in(0) == init, "dest pinned"); 1.4928 + adr_type = TypeRawPtr::BOTTOM; // all initializations are into raw memory 1.4929 + // From this point on, every exit path is responsible for 1.4930 + // initializing any non-copied parts of the object to zero. 1.4931 + // Also, if this flag is set we make sure that arraycopy interacts properly 1.4932 + // with G1, eliding pre-barriers. See CR 6627983. 1.4933 + dest_uninitialized = true; 1.4934 + } else { 1.4935 + // No zeroing elimination here. 1.4936 + alloc = NULL; 1.4937 + //original_dest = dest; 1.4938 + //dest_uninitialized = false; 1.4939 + } 1.4940 + 1.4941 + // Results are placed here: 1.4942 + enum { fast_path = 1, // normal void-returning assembly stub 1.4943 + checked_path = 2, // special assembly stub with cleanup 1.4944 + slow_call_path = 3, // something went wrong; call the VM 1.4945 + zero_path = 4, // bypass when length of copy is zero 1.4946 + bcopy_path = 5, // copy primitive array by 64-bit blocks 1.4947 + PATH_LIMIT = 6 1.4948 + }; 1.4949 + RegionNode* result_region = new(C) RegionNode(PATH_LIMIT); 1.4950 + PhiNode* result_i_o = new(C) PhiNode(result_region, Type::ABIO); 1.4951 + PhiNode* result_memory = new(C) PhiNode(result_region, Type::MEMORY, adr_type); 1.4952 + record_for_igvn(result_region); 1.4953 + _gvn.set_type_bottom(result_i_o); 1.4954 + _gvn.set_type_bottom(result_memory); 1.4955 + assert(adr_type != TypePtr::BOTTOM, "must be RawMem or a T[] slice"); 1.4956 + 1.4957 + // The slow_control path: 1.4958 + Node* slow_control; 1.4959 + Node* slow_i_o = i_o(); 1.4960 + Node* slow_mem = memory(adr_type); 1.4961 + debug_only(slow_control = (Node*) badAddress); 1.4962 + 1.4963 + // Checked control path: 1.4964 + Node* checked_control = top(); 1.4965 + Node* checked_mem = NULL; 1.4966 + Node* checked_i_o = NULL; 1.4967 + Node* checked_value = NULL; 1.4968 + 1.4969 + if (basic_elem_type == T_CONFLICT) { 1.4970 + assert(!dest_uninitialized, ""); 1.4971 + Node* cv = generate_generic_arraycopy(adr_type, 1.4972 + src, src_offset, dest, dest_offset, 1.4973 + copy_length, dest_uninitialized); 1.4974 + if (cv == NULL) cv = intcon(-1); // failure (no stub available) 1.4975 + checked_control = control(); 1.4976 + checked_i_o = i_o(); 1.4977 + checked_mem = memory(adr_type); 1.4978 + checked_value = cv; 1.4979 + set_control(top()); // no fast path 1.4980 + } 1.4981 + 1.4982 + Node* not_pos = generate_nonpositive_guard(copy_length, length_never_negative); 1.4983 + if (not_pos != NULL) { 1.4984 + PreserveJVMState pjvms(this); 1.4985 + set_control(not_pos); 1.4986 + 1.4987 + // (6) length must not be negative. 1.4988 + if (!length_never_negative) { 1.4989 + generate_negative_guard(copy_length, slow_region); 1.4990 + } 1.4991 + 1.4992 + // copy_length is 0. 1.4993 + if (!stopped() && dest_uninitialized) { 1.4994 + Node* dest_length = alloc->in(AllocateNode::ALength); 1.4995 + if (copy_length->eqv_uncast(dest_length) 1.4996 + || _gvn.find_int_con(dest_length, 1) <= 0) { 1.4997 + // There is no zeroing to do. No need for a secondary raw memory barrier. 1.4998 + } else { 1.4999 + // Clear the whole thing since there are no source elements to copy. 1.5000 + generate_clear_array(adr_type, dest, basic_elem_type, 1.5001 + intcon(0), NULL, 1.5002 + alloc->in(AllocateNode::AllocSize)); 1.5003 + // Use a secondary InitializeNode as raw memory barrier. 1.5004 + // Currently it is needed only on this path since other 1.5005 + // paths have stub or runtime calls as raw memory barriers. 1.5006 + InitializeNode* init = insert_mem_bar_volatile(Op_Initialize, 1.5007 + Compile::AliasIdxRaw, 1.5008 + top())->as_Initialize(); 1.5009 + init->set_complete(&_gvn); // (there is no corresponding AllocateNode) 1.5010 + } 1.5011 + } 1.5012 + 1.5013 + // Present the results of the fast call. 1.5014 + result_region->init_req(zero_path, control()); 1.5015 + result_i_o ->init_req(zero_path, i_o()); 1.5016 + result_memory->init_req(zero_path, memory(adr_type)); 1.5017 + } 1.5018 + 1.5019 + if (!stopped() && dest_uninitialized) { 1.5020 + // We have to initialize the *uncopied* part of the array to zero. 1.5021 + // The copy destination is the slice dest[off..off+len]. The other slices 1.5022 + // are dest_head = dest[0..off] and dest_tail = dest[off+len..dest.length]. 1.5023 + Node* dest_size = alloc->in(AllocateNode::AllocSize); 1.5024 + Node* dest_length = alloc->in(AllocateNode::ALength); 1.5025 + Node* dest_tail = _gvn.transform(new(C) AddINode(dest_offset, 1.5026 + copy_length)); 1.5027 + 1.5028 + // If there is a head section that needs zeroing, do it now. 1.5029 + if (find_int_con(dest_offset, -1) != 0) { 1.5030 + generate_clear_array(adr_type, dest, basic_elem_type, 1.5031 + intcon(0), dest_offset, 1.5032 + NULL); 1.5033 + } 1.5034 + 1.5035 + // Next, perform a dynamic check on the tail length. 1.5036 + // It is often zero, and we can win big if we prove this. 1.5037 + // There are two wins: Avoid generating the ClearArray 1.5038 + // with its attendant messy index arithmetic, and upgrade 1.5039 + // the copy to a more hardware-friendly word size of 64 bits. 1.5040 + Node* tail_ctl = NULL; 1.5041 + if (!stopped() && !dest_tail->eqv_uncast(dest_length)) { 1.5042 + Node* cmp_lt = _gvn.transform(new(C) CmpINode(dest_tail, dest_length)); 1.5043 + Node* bol_lt = _gvn.transform(new(C) BoolNode(cmp_lt, BoolTest::lt)); 1.5044 + tail_ctl = generate_slow_guard(bol_lt, NULL); 1.5045 + assert(tail_ctl != NULL || !stopped(), "must be an outcome"); 1.5046 + } 1.5047 + 1.5048 + // At this point, let's assume there is no tail. 1.5049 + if (!stopped() && alloc != NULL && basic_elem_type != T_OBJECT) { 1.5050 + // There is no tail. Try an upgrade to a 64-bit copy. 1.5051 + bool didit = false; 1.5052 + { PreserveJVMState pjvms(this); 1.5053 + didit = generate_block_arraycopy(adr_type, basic_elem_type, alloc, 1.5054 + src, src_offset, dest, dest_offset, 1.5055 + dest_size, dest_uninitialized); 1.5056 + if (didit) { 1.5057 + // Present the results of the block-copying fast call. 1.5058 + result_region->init_req(bcopy_path, control()); 1.5059 + result_i_o ->init_req(bcopy_path, i_o()); 1.5060 + result_memory->init_req(bcopy_path, memory(adr_type)); 1.5061 + } 1.5062 + } 1.5063 + if (didit) 1.5064 + set_control(top()); // no regular fast path 1.5065 + } 1.5066 + 1.5067 + // Clear the tail, if any. 1.5068 + if (tail_ctl != NULL) { 1.5069 + Node* notail_ctl = stopped() ? NULL : control(); 1.5070 + set_control(tail_ctl); 1.5071 + if (notail_ctl == NULL) { 1.5072 + generate_clear_array(adr_type, dest, basic_elem_type, 1.5073 + dest_tail, NULL, 1.5074 + dest_size); 1.5075 + } else { 1.5076 + // Make a local merge. 1.5077 + Node* done_ctl = new(C) RegionNode(3); 1.5078 + Node* done_mem = new(C) PhiNode(done_ctl, Type::MEMORY, adr_type); 1.5079 + done_ctl->init_req(1, notail_ctl); 1.5080 + done_mem->init_req(1, memory(adr_type)); 1.5081 + generate_clear_array(adr_type, dest, basic_elem_type, 1.5082 + dest_tail, NULL, 1.5083 + dest_size); 1.5084 + done_ctl->init_req(2, control()); 1.5085 + done_mem->init_req(2, memory(adr_type)); 1.5086 + set_control( _gvn.transform(done_ctl)); 1.5087 + set_memory( _gvn.transform(done_mem), adr_type ); 1.5088 + } 1.5089 + } 1.5090 + } 1.5091 + 1.5092 + BasicType copy_type = basic_elem_type; 1.5093 + assert(basic_elem_type != T_ARRAY, "caller must fix this"); 1.5094 + if (!stopped() && copy_type == T_OBJECT) { 1.5095 + // If src and dest have compatible element types, we can copy bits. 1.5096 + // Types S[] and D[] are compatible if D is a supertype of S. 1.5097 + // 1.5098 + // If they are not, we will use checked_oop_disjoint_arraycopy, 1.5099 + // which performs a fast optimistic per-oop check, and backs off 1.5100 + // further to JVM_ArrayCopy on the first per-oop check that fails. 1.5101 + // (Actually, we don't move raw bits only; the GC requires card marks.) 1.5102 + 1.5103 + // Get the Klass* for both src and dest 1.5104 + Node* src_klass = load_object_klass(src); 1.5105 + Node* dest_klass = load_object_klass(dest); 1.5106 + 1.5107 + // Generate the subtype check. 1.5108 + // This might fold up statically, or then again it might not. 1.5109 + // 1.5110 + // Non-static example: Copying List<String>.elements to a new String[]. 1.5111 + // The backing store for a List<String> is always an Object[], 1.5112 + // but its elements are always type String, if the generic types 1.5113 + // are correct at the source level. 1.5114 + // 1.5115 + // Test S[] against D[], not S against D, because (probably) 1.5116 + // the secondary supertype cache is less busy for S[] than S. 1.5117 + // This usually only matters when D is an interface. 1.5118 + Node* not_subtype_ctrl = gen_subtype_check(src_klass, dest_klass); 1.5119 + // Plug failing path into checked_oop_disjoint_arraycopy 1.5120 + if (not_subtype_ctrl != top()) { 1.5121 + PreserveJVMState pjvms(this); 1.5122 + set_control(not_subtype_ctrl); 1.5123 + // (At this point we can assume disjoint_bases, since types differ.) 1.5124 + int ek_offset = in_bytes(ObjArrayKlass::element_klass_offset()); 1.5125 + Node* p1 = basic_plus_adr(dest_klass, ek_offset); 1.5126 + Node* n1 = LoadKlassNode::make(_gvn, immutable_memory(), p1, TypeRawPtr::BOTTOM); 1.5127 + Node* dest_elem_klass = _gvn.transform(n1); 1.5128 + Node* cv = generate_checkcast_arraycopy(adr_type, 1.5129 + dest_elem_klass, 1.5130 + src, src_offset, dest, dest_offset, 1.5131 + ConvI2X(copy_length), dest_uninitialized); 1.5132 + if (cv == NULL) cv = intcon(-1); // failure (no stub available) 1.5133 + checked_control = control(); 1.5134 + checked_i_o = i_o(); 1.5135 + checked_mem = memory(adr_type); 1.5136 + checked_value = cv; 1.5137 + } 1.5138 + // At this point we know we do not need type checks on oop stores. 1.5139 + 1.5140 + // Let's see if we need card marks: 1.5141 + if (alloc != NULL && use_ReduceInitialCardMarks()) { 1.5142 + // If we do not need card marks, copy using the jint or jlong stub. 1.5143 + copy_type = LP64_ONLY(UseCompressedOops ? T_INT : T_LONG) NOT_LP64(T_INT); 1.5144 + assert(type2aelembytes(basic_elem_type) == type2aelembytes(copy_type), 1.5145 + "sizes agree"); 1.5146 + } 1.5147 + } 1.5148 + 1.5149 + if (!stopped()) { 1.5150 + // Generate the fast path, if possible. 1.5151 + PreserveJVMState pjvms(this); 1.5152 + generate_unchecked_arraycopy(adr_type, copy_type, disjoint_bases, 1.5153 + src, src_offset, dest, dest_offset, 1.5154 + ConvI2X(copy_length), dest_uninitialized); 1.5155 + 1.5156 + // Present the results of the fast call. 1.5157 + result_region->init_req(fast_path, control()); 1.5158 + result_i_o ->init_req(fast_path, i_o()); 1.5159 + result_memory->init_req(fast_path, memory(adr_type)); 1.5160 + } 1.5161 + 1.5162 + // Here are all the slow paths up to this point, in one bundle: 1.5163 + slow_control = top(); 1.5164 + if (slow_region != NULL) 1.5165 + slow_control = _gvn.transform(slow_region); 1.5166 + DEBUG_ONLY(slow_region = (RegionNode*)badAddress); 1.5167 + 1.5168 + set_control(checked_control); 1.5169 + if (!stopped()) { 1.5170 + // Clean up after the checked call. 1.5171 + // The returned value is either 0 or -1^K, 1.5172 + // where K = number of partially transferred array elements. 1.5173 + Node* cmp = _gvn.transform(new(C) CmpINode(checked_value, intcon(0))); 1.5174 + Node* bol = _gvn.transform(new(C) BoolNode(cmp, BoolTest::eq)); 1.5175 + IfNode* iff = create_and_map_if(control(), bol, PROB_MAX, COUNT_UNKNOWN); 1.5176 + 1.5177 + // If it is 0, we are done, so transfer to the end. 1.5178 + Node* checks_done = _gvn.transform(new(C) IfTrueNode(iff)); 1.5179 + result_region->init_req(checked_path, checks_done); 1.5180 + result_i_o ->init_req(checked_path, checked_i_o); 1.5181 + result_memory->init_req(checked_path, checked_mem); 1.5182 + 1.5183 + // If it is not zero, merge into the slow call. 1.5184 + set_control( _gvn.transform(new(C) IfFalseNode(iff) )); 1.5185 + RegionNode* slow_reg2 = new(C) RegionNode(3); 1.5186 + PhiNode* slow_i_o2 = new(C) PhiNode(slow_reg2, Type::ABIO); 1.5187 + PhiNode* slow_mem2 = new(C) PhiNode(slow_reg2, Type::MEMORY, adr_type); 1.5188 + record_for_igvn(slow_reg2); 1.5189 + slow_reg2 ->init_req(1, slow_control); 1.5190 + slow_i_o2 ->init_req(1, slow_i_o); 1.5191 + slow_mem2 ->init_req(1, slow_mem); 1.5192 + slow_reg2 ->init_req(2, control()); 1.5193 + slow_i_o2 ->init_req(2, checked_i_o); 1.5194 + slow_mem2 ->init_req(2, checked_mem); 1.5195 + 1.5196 + slow_control = _gvn.transform(slow_reg2); 1.5197 + slow_i_o = _gvn.transform(slow_i_o2); 1.5198 + slow_mem = _gvn.transform(slow_mem2); 1.5199 + 1.5200 + if (alloc != NULL) { 1.5201 + // We'll restart from the very beginning, after zeroing the whole thing. 1.5202 + // This can cause double writes, but that's OK since dest is brand new. 1.5203 + // So we ignore the low 31 bits of the value returned from the stub. 1.5204 + } else { 1.5205 + // We must continue the copy exactly where it failed, or else 1.5206 + // another thread might see the wrong number of writes to dest. 1.5207 + Node* checked_offset = _gvn.transform(new(C) XorINode(checked_value, intcon(-1))); 1.5208 + Node* slow_offset = new(C) PhiNode(slow_reg2, TypeInt::INT); 1.5209 + slow_offset->init_req(1, intcon(0)); 1.5210 + slow_offset->init_req(2, checked_offset); 1.5211 + slow_offset = _gvn.transform(slow_offset); 1.5212 + 1.5213 + // Adjust the arguments by the conditionally incoming offset. 1.5214 + Node* src_off_plus = _gvn.transform(new(C) AddINode(src_offset, slow_offset)); 1.5215 + Node* dest_off_plus = _gvn.transform(new(C) AddINode(dest_offset, slow_offset)); 1.5216 + Node* length_minus = _gvn.transform(new(C) SubINode(copy_length, slow_offset)); 1.5217 + 1.5218 + // Tweak the node variables to adjust the code produced below: 1.5219 + src_offset = src_off_plus; 1.5220 + dest_offset = dest_off_plus; 1.5221 + copy_length = length_minus; 1.5222 + } 1.5223 + } 1.5224 + 1.5225 + set_control(slow_control); 1.5226 + if (!stopped()) { 1.5227 + // Generate the slow path, if needed. 1.5228 + PreserveJVMState pjvms(this); // replace_in_map may trash the map 1.5229 + 1.5230 + set_memory(slow_mem, adr_type); 1.5231 + set_i_o(slow_i_o); 1.5232 + 1.5233 + if (dest_uninitialized) { 1.5234 + generate_clear_array(adr_type, dest, basic_elem_type, 1.5235 + intcon(0), NULL, 1.5236 + alloc->in(AllocateNode::AllocSize)); 1.5237 + } 1.5238 + 1.5239 + generate_slow_arraycopy(adr_type, 1.5240 + src, src_offset, dest, dest_offset, 1.5241 + copy_length, /*dest_uninitialized*/false); 1.5242 + 1.5243 + result_region->init_req(slow_call_path, control()); 1.5244 + result_i_o ->init_req(slow_call_path, i_o()); 1.5245 + result_memory->init_req(slow_call_path, memory(adr_type)); 1.5246 + } 1.5247 + 1.5248 + // Remove unused edges. 1.5249 + for (uint i = 1; i < result_region->req(); i++) { 1.5250 + if (result_region->in(i) == NULL) 1.5251 + result_region->init_req(i, top()); 1.5252 + } 1.5253 + 1.5254 + // Finished; return the combined state. 1.5255 + set_control( _gvn.transform(result_region)); 1.5256 + set_i_o( _gvn.transform(result_i_o) ); 1.5257 + set_memory( _gvn.transform(result_memory), adr_type ); 1.5258 + 1.5259 + // The memory edges above are precise in order to model effects around 1.5260 + // array copies accurately to allow value numbering of field loads around 1.5261 + // arraycopy. Such field loads, both before and after, are common in Java 1.5262 + // collections and similar classes involving header/array data structures. 1.5263 + // 1.5264 + // But with low number of register or when some registers are used or killed 1.5265 + // by arraycopy calls it causes registers spilling on stack. See 6544710. 1.5266 + // The next memory barrier is added to avoid it. If the arraycopy can be 1.5267 + // optimized away (which it can, sometimes) then we can manually remove 1.5268 + // the membar also. 1.5269 + // 1.5270 + // Do not let reads from the cloned object float above the arraycopy. 1.5271 + if (alloc != NULL) { 1.5272 + // Do not let stores that initialize this object be reordered with 1.5273 + // a subsequent store that would make this object accessible by 1.5274 + // other threads. 1.5275 + // Record what AllocateNode this StoreStore protects so that 1.5276 + // escape analysis can go from the MemBarStoreStoreNode to the 1.5277 + // AllocateNode and eliminate the MemBarStoreStoreNode if possible 1.5278 + // based on the escape status of the AllocateNode. 1.5279 + insert_mem_bar(Op_MemBarStoreStore, alloc->proj_out(AllocateNode::RawAddress)); 1.5280 + } else if (InsertMemBarAfterArraycopy) 1.5281 + insert_mem_bar(Op_MemBarCPUOrder); 1.5282 +} 1.5283 + 1.5284 + 1.5285 +// Helper function which determines if an arraycopy immediately follows 1.5286 +// an allocation, with no intervening tests or other escapes for the object. 1.5287 +AllocateArrayNode* 1.5288 +LibraryCallKit::tightly_coupled_allocation(Node* ptr, 1.5289 + RegionNode* slow_region) { 1.5290 + if (stopped()) return NULL; // no fast path 1.5291 + if (C->AliasLevel() == 0) return NULL; // no MergeMems around 1.5292 + 1.5293 + AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(ptr, &_gvn); 1.5294 + if (alloc == NULL) return NULL; 1.5295 + 1.5296 + Node* rawmem = memory(Compile::AliasIdxRaw); 1.5297 + // Is the allocation's memory state untouched? 1.5298 + if (!(rawmem->is_Proj() && rawmem->in(0)->is_Initialize())) { 1.5299 + // Bail out if there have been raw-memory effects since the allocation. 1.5300 + // (Example: There might have been a call or safepoint.) 1.5301 + return NULL; 1.5302 + } 1.5303 + rawmem = rawmem->in(0)->as_Initialize()->memory(Compile::AliasIdxRaw); 1.5304 + if (!(rawmem->is_Proj() && rawmem->in(0) == alloc)) { 1.5305 + return NULL; 1.5306 + } 1.5307 + 1.5308 + // There must be no unexpected observers of this allocation. 1.5309 + for (DUIterator_Fast imax, i = ptr->fast_outs(imax); i < imax; i++) { 1.5310 + Node* obs = ptr->fast_out(i); 1.5311 + if (obs != this->map()) { 1.5312 + return NULL; 1.5313 + } 1.5314 + } 1.5315 + 1.5316 + // This arraycopy must unconditionally follow the allocation of the ptr. 1.5317 + Node* alloc_ctl = ptr->in(0); 1.5318 + assert(just_allocated_object(alloc_ctl) == ptr, "most recent allo"); 1.5319 + 1.5320 + Node* ctl = control(); 1.5321 + while (ctl != alloc_ctl) { 1.5322 + // There may be guards which feed into the slow_region. 1.5323 + // Any other control flow means that we might not get a chance 1.5324 + // to finish initializing the allocated object. 1.5325 + if ((ctl->is_IfFalse() || ctl->is_IfTrue()) && ctl->in(0)->is_If()) { 1.5326 + IfNode* iff = ctl->in(0)->as_If(); 1.5327 + Node* not_ctl = iff->proj_out(1 - ctl->as_Proj()->_con); 1.5328 + assert(not_ctl != NULL && not_ctl != ctl, "found alternate"); 1.5329 + if (slow_region != NULL && slow_region->find_edge(not_ctl) >= 1) { 1.5330 + ctl = iff->in(0); // This test feeds the known slow_region. 1.5331 + continue; 1.5332 + } 1.5333 + // One more try: Various low-level checks bottom out in 1.5334 + // uncommon traps. If the debug-info of the trap omits 1.5335 + // any reference to the allocation, as we've already 1.5336 + // observed, then there can be no objection to the trap. 1.5337 + bool found_trap = false; 1.5338 + for (DUIterator_Fast jmax, j = not_ctl->fast_outs(jmax); j < jmax; j++) { 1.5339 + Node* obs = not_ctl->fast_out(j); 1.5340 + if (obs->in(0) == not_ctl && obs->is_Call() && 1.5341 + (obs->as_Call()->entry_point() == SharedRuntime::uncommon_trap_blob()->entry_point())) { 1.5342 + found_trap = true; break; 1.5343 + } 1.5344 + } 1.5345 + if (found_trap) { 1.5346 + ctl = iff->in(0); // This test feeds a harmless uncommon trap. 1.5347 + continue; 1.5348 + } 1.5349 + } 1.5350 + return NULL; 1.5351 + } 1.5352 + 1.5353 + // If we get this far, we have an allocation which immediately 1.5354 + // precedes the arraycopy, and we can take over zeroing the new object. 1.5355 + // The arraycopy will finish the initialization, and provide 1.5356 + // a new control state to which we will anchor the destination pointer. 1.5357 + 1.5358 + return alloc; 1.5359 +} 1.5360 + 1.5361 +// Helper for initialization of arrays, creating a ClearArray. 1.5362 +// It writes zero bits in [start..end), within the body of an array object. 1.5363 +// The memory effects are all chained onto the 'adr_type' alias category. 1.5364 +// 1.5365 +// Since the object is otherwise uninitialized, we are free 1.5366 +// to put a little "slop" around the edges of the cleared area, 1.5367 +// as long as it does not go back into the array's header, 1.5368 +// or beyond the array end within the heap. 1.5369 +// 1.5370 +// The lower edge can be rounded down to the nearest jint and the 1.5371 +// upper edge can be rounded up to the nearest MinObjAlignmentInBytes. 1.5372 +// 1.5373 +// Arguments: 1.5374 +// adr_type memory slice where writes are generated 1.5375 +// dest oop of the destination array 1.5376 +// basic_elem_type element type of the destination 1.5377 +// slice_idx array index of first element to store 1.5378 +// slice_len number of elements to store (or NULL) 1.5379 +// dest_size total size in bytes of the array object 1.5380 +// 1.5381 +// Exactly one of slice_len or dest_size must be non-NULL. 1.5382 +// If dest_size is non-NULL, zeroing extends to the end of the object. 1.5383 +// If slice_len is non-NULL, the slice_idx value must be a constant. 1.5384 +void 1.5385 +LibraryCallKit::generate_clear_array(const TypePtr* adr_type, 1.5386 + Node* dest, 1.5387 + BasicType basic_elem_type, 1.5388 + Node* slice_idx, 1.5389 + Node* slice_len, 1.5390 + Node* dest_size) { 1.5391 + // one or the other but not both of slice_len and dest_size: 1.5392 + assert((slice_len != NULL? 1: 0) + (dest_size != NULL? 1: 0) == 1, ""); 1.5393 + if (slice_len == NULL) slice_len = top(); 1.5394 + if (dest_size == NULL) dest_size = top(); 1.5395 + 1.5396 + // operate on this memory slice: 1.5397 + Node* mem = memory(adr_type); // memory slice to operate on 1.5398 + 1.5399 + // scaling and rounding of indexes: 1.5400 + int scale = exact_log2(type2aelembytes(basic_elem_type)); 1.5401 + int abase = arrayOopDesc::base_offset_in_bytes(basic_elem_type); 1.5402 + int clear_low = (-1 << scale) & (BytesPerInt - 1); 1.5403 + int bump_bit = (-1 << scale) & BytesPerInt; 1.5404 + 1.5405 + // determine constant starts and ends 1.5406 + const intptr_t BIG_NEG = -128; 1.5407 + assert(BIG_NEG + 2*abase < 0, "neg enough"); 1.5408 + intptr_t slice_idx_con = (intptr_t) find_int_con(slice_idx, BIG_NEG); 1.5409 + intptr_t slice_len_con = (intptr_t) find_int_con(slice_len, BIG_NEG); 1.5410 + if (slice_len_con == 0) { 1.5411 + return; // nothing to do here 1.5412 + } 1.5413 + intptr_t start_con = (abase + (slice_idx_con << scale)) & ~clear_low; 1.5414 + intptr_t end_con = find_intptr_t_con(dest_size, -1); 1.5415 + if (slice_idx_con >= 0 && slice_len_con >= 0) { 1.5416 + assert(end_con < 0, "not two cons"); 1.5417 + end_con = round_to(abase + ((slice_idx_con + slice_len_con) << scale), 1.5418 + BytesPerLong); 1.5419 + } 1.5420 + 1.5421 + if (start_con >= 0 && end_con >= 0) { 1.5422 + // Constant start and end. Simple. 1.5423 + mem = ClearArrayNode::clear_memory(control(), mem, dest, 1.5424 + start_con, end_con, &_gvn); 1.5425 + } else if (start_con >= 0 && dest_size != top()) { 1.5426 + // Constant start, pre-rounded end after the tail of the array. 1.5427 + Node* end = dest_size; 1.5428 + mem = ClearArrayNode::clear_memory(control(), mem, dest, 1.5429 + start_con, end, &_gvn); 1.5430 + } else if (start_con >= 0 && slice_len != top()) { 1.5431 + // Constant start, non-constant end. End needs rounding up. 1.5432 + // End offset = round_up(abase + ((slice_idx_con + slice_len) << scale), 8) 1.5433 + intptr_t end_base = abase + (slice_idx_con << scale); 1.5434 + int end_round = (-1 << scale) & (BytesPerLong - 1); 1.5435 + Node* end = ConvI2X(slice_len); 1.5436 + if (scale != 0) 1.5437 + end = _gvn.transform(new(C) LShiftXNode(end, intcon(scale) )); 1.5438 + end_base += end_round; 1.5439 + end = _gvn.transform(new(C) AddXNode(end, MakeConX(end_base))); 1.5440 + end = _gvn.transform(new(C) AndXNode(end, MakeConX(~end_round))); 1.5441 + mem = ClearArrayNode::clear_memory(control(), mem, dest, 1.5442 + start_con, end, &_gvn); 1.5443 + } else if (start_con < 0 && dest_size != top()) { 1.5444 + // Non-constant start, pre-rounded end after the tail of the array. 1.5445 + // This is almost certainly a "round-to-end" operation. 1.5446 + Node* start = slice_idx; 1.5447 + start = ConvI2X(start); 1.5448 + if (scale != 0) 1.5449 + start = _gvn.transform(new(C) LShiftXNode( start, intcon(scale) )); 1.5450 + start = _gvn.transform(new(C) AddXNode(start, MakeConX(abase))); 1.5451 + if ((bump_bit | clear_low) != 0) { 1.5452 + int to_clear = (bump_bit | clear_low); 1.5453 + // Align up mod 8, then store a jint zero unconditionally 1.5454 + // just before the mod-8 boundary. 1.5455 + if (((abase + bump_bit) & ~to_clear) - bump_bit 1.5456 + < arrayOopDesc::length_offset_in_bytes() + BytesPerInt) { 1.5457 + bump_bit = 0; 1.5458 + assert((abase & to_clear) == 0, "array base must be long-aligned"); 1.5459 + } else { 1.5460 + // Bump 'start' up to (or past) the next jint boundary: 1.5461 + start = _gvn.transform(new(C) AddXNode(start, MakeConX(bump_bit))); 1.5462 + assert((abase & clear_low) == 0, "array base must be int-aligned"); 1.5463 + } 1.5464 + // Round bumped 'start' down to jlong boundary in body of array. 1.5465 + start = _gvn.transform(new(C) AndXNode(start, MakeConX(~to_clear))); 1.5466 + if (bump_bit != 0) { 1.5467 + // Store a zero to the immediately preceding jint: 1.5468 + Node* x1 = _gvn.transform(new(C) AddXNode(start, MakeConX(-bump_bit))); 1.5469 + Node* p1 = basic_plus_adr(dest, x1); 1.5470 + mem = StoreNode::make(_gvn, control(), mem, p1, adr_type, intcon(0), T_INT, MemNode::unordered); 1.5471 + mem = _gvn.transform(mem); 1.5472 + } 1.5473 + } 1.5474 + Node* end = dest_size; // pre-rounded 1.5475 + mem = ClearArrayNode::clear_memory(control(), mem, dest, 1.5476 + start, end, &_gvn); 1.5477 + } else { 1.5478 + // Non-constant start, unrounded non-constant end. 1.5479 + // (Nobody zeroes a random midsection of an array using this routine.) 1.5480 + ShouldNotReachHere(); // fix caller 1.5481 + } 1.5482 + 1.5483 + // Done. 1.5484 + set_memory(mem, adr_type); 1.5485 +} 1.5486 + 1.5487 + 1.5488 +bool 1.5489 +LibraryCallKit::generate_block_arraycopy(const TypePtr* adr_type, 1.5490 + BasicType basic_elem_type, 1.5491 + AllocateNode* alloc, 1.5492 + Node* src, Node* src_offset, 1.5493 + Node* dest, Node* dest_offset, 1.5494 + Node* dest_size, bool dest_uninitialized) { 1.5495 + // See if there is an advantage from block transfer. 1.5496 + int scale = exact_log2(type2aelembytes(basic_elem_type)); 1.5497 + if (scale >= LogBytesPerLong) 1.5498 + return false; // it is already a block transfer 1.5499 + 1.5500 + // Look at the alignment of the starting offsets. 1.5501 + int abase = arrayOopDesc::base_offset_in_bytes(basic_elem_type); 1.5502 + 1.5503 + intptr_t src_off_con = (intptr_t) find_int_con(src_offset, -1); 1.5504 + intptr_t dest_off_con = (intptr_t) find_int_con(dest_offset, -1); 1.5505 + if (src_off_con < 0 || dest_off_con < 0) 1.5506 + // At present, we can only understand constants. 1.5507 + return false; 1.5508 + 1.5509 + intptr_t src_off = abase + (src_off_con << scale); 1.5510 + intptr_t dest_off = abase + (dest_off_con << scale); 1.5511 + 1.5512 + if (((src_off | dest_off) & (BytesPerLong-1)) != 0) { 1.5513 + // Non-aligned; too bad. 1.5514 + // One more chance: Pick off an initial 32-bit word. 1.5515 + // This is a common case, since abase can be odd mod 8. 1.5516 + if (((src_off | dest_off) & (BytesPerLong-1)) == BytesPerInt && 1.5517 + ((src_off ^ dest_off) & (BytesPerLong-1)) == 0) { 1.5518 + Node* sptr = basic_plus_adr(src, src_off); 1.5519 + Node* dptr = basic_plus_adr(dest, dest_off); 1.5520 + Node* sval = make_load(control(), sptr, TypeInt::INT, T_INT, adr_type, MemNode::unordered); 1.5521 + store_to_memory(control(), dptr, sval, T_INT, adr_type, MemNode::unordered); 1.5522 + src_off += BytesPerInt; 1.5523 + dest_off += BytesPerInt; 1.5524 + } else { 1.5525 + return false; 1.5526 + } 1.5527 + } 1.5528 + assert(src_off % BytesPerLong == 0, ""); 1.5529 + assert(dest_off % BytesPerLong == 0, ""); 1.5530 + 1.5531 + // Do this copy by giant steps. 1.5532 + Node* sptr = basic_plus_adr(src, src_off); 1.5533 + Node* dptr = basic_plus_adr(dest, dest_off); 1.5534 + Node* countx = dest_size; 1.5535 + countx = _gvn.transform(new (C) SubXNode(countx, MakeConX(dest_off))); 1.5536 + countx = _gvn.transform(new (C) URShiftXNode(countx, intcon(LogBytesPerLong))); 1.5537 + 1.5538 + bool disjoint_bases = true; // since alloc != NULL 1.5539 + generate_unchecked_arraycopy(adr_type, T_LONG, disjoint_bases, 1.5540 + sptr, NULL, dptr, NULL, countx, dest_uninitialized); 1.5541 + 1.5542 + return true; 1.5543 +} 1.5544 + 1.5545 + 1.5546 +// Helper function; generates code for the slow case. 1.5547 +// We make a call to a runtime method which emulates the native method, 1.5548 +// but without the native wrapper overhead. 1.5549 +void 1.5550 +LibraryCallKit::generate_slow_arraycopy(const TypePtr* adr_type, 1.5551 + Node* src, Node* src_offset, 1.5552 + Node* dest, Node* dest_offset, 1.5553 + Node* copy_length, bool dest_uninitialized) { 1.5554 + assert(!dest_uninitialized, "Invariant"); 1.5555 + Node* call = make_runtime_call(RC_NO_LEAF | RC_UNCOMMON, 1.5556 + OptoRuntime::slow_arraycopy_Type(), 1.5557 + OptoRuntime::slow_arraycopy_Java(), 1.5558 + "slow_arraycopy", adr_type, 1.5559 + src, src_offset, dest, dest_offset, 1.5560 + copy_length); 1.5561 + 1.5562 + // Handle exceptions thrown by this fellow: 1.5563 + make_slow_call_ex(call, env()->Throwable_klass(), false); 1.5564 +} 1.5565 + 1.5566 +// Helper function; generates code for cases requiring runtime checks. 1.5567 +Node* 1.5568 +LibraryCallKit::generate_checkcast_arraycopy(const TypePtr* adr_type, 1.5569 + Node* dest_elem_klass, 1.5570 + Node* src, Node* src_offset, 1.5571 + Node* dest, Node* dest_offset, 1.5572 + Node* copy_length, bool dest_uninitialized) { 1.5573 + if (stopped()) return NULL; 1.5574 + 1.5575 + address copyfunc_addr = StubRoutines::checkcast_arraycopy(dest_uninitialized); 1.5576 + if (copyfunc_addr == NULL) { // Stub was not generated, go slow path. 1.5577 + return NULL; 1.5578 + } 1.5579 + 1.5580 + // Pick out the parameters required to perform a store-check 1.5581 + // for the target array. This is an optimistic check. It will 1.5582 + // look in each non-null element's class, at the desired klass's 1.5583 + // super_check_offset, for the desired klass. 1.5584 + int sco_offset = in_bytes(Klass::super_check_offset_offset()); 1.5585 + Node* p3 = basic_plus_adr(dest_elem_klass, sco_offset); 1.5586 + Node* n3 = new(C) LoadINode(NULL, memory(p3), p3, _gvn.type(p3)->is_ptr(), TypeInt::INT, MemNode::unordered); 1.5587 + Node* check_offset = ConvI2X(_gvn.transform(n3)); 1.5588 + Node* check_value = dest_elem_klass; 1.5589 + 1.5590 + Node* src_start = array_element_address(src, src_offset, T_OBJECT); 1.5591 + Node* dest_start = array_element_address(dest, dest_offset, T_OBJECT); 1.5592 + 1.5593 + // (We know the arrays are never conjoint, because their types differ.) 1.5594 + Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 1.5595 + OptoRuntime::checkcast_arraycopy_Type(), 1.5596 + copyfunc_addr, "checkcast_arraycopy", adr_type, 1.5597 + // five arguments, of which two are 1.5598 + // intptr_t (jlong in LP64) 1.5599 + src_start, dest_start, 1.5600 + copy_length XTOP, 1.5601 + check_offset XTOP, 1.5602 + check_value); 1.5603 + 1.5604 + return _gvn.transform(new (C) ProjNode(call, TypeFunc::Parms)); 1.5605 +} 1.5606 + 1.5607 + 1.5608 +// Helper function; generates code for cases requiring runtime checks. 1.5609 +Node* 1.5610 +LibraryCallKit::generate_generic_arraycopy(const TypePtr* adr_type, 1.5611 + Node* src, Node* src_offset, 1.5612 + Node* dest, Node* dest_offset, 1.5613 + Node* copy_length, bool dest_uninitialized) { 1.5614 + assert(!dest_uninitialized, "Invariant"); 1.5615 + if (stopped()) return NULL; 1.5616 + address copyfunc_addr = StubRoutines::generic_arraycopy(); 1.5617 + if (copyfunc_addr == NULL) { // Stub was not generated, go slow path. 1.5618 + return NULL; 1.5619 + } 1.5620 + 1.5621 + Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 1.5622 + OptoRuntime::generic_arraycopy_Type(), 1.5623 + copyfunc_addr, "generic_arraycopy", adr_type, 1.5624 + src, src_offset, dest, dest_offset, copy_length); 1.5625 + 1.5626 + return _gvn.transform(new (C) ProjNode(call, TypeFunc::Parms)); 1.5627 +} 1.5628 + 1.5629 +// Helper function; generates the fast out-of-line call to an arraycopy stub. 1.5630 +void 1.5631 +LibraryCallKit::generate_unchecked_arraycopy(const TypePtr* adr_type, 1.5632 + BasicType basic_elem_type, 1.5633 + bool disjoint_bases, 1.5634 + Node* src, Node* src_offset, 1.5635 + Node* dest, Node* dest_offset, 1.5636 + Node* copy_length, bool dest_uninitialized) { 1.5637 + if (stopped()) return; // nothing to do 1.5638 + 1.5639 + Node* src_start = src; 1.5640 + Node* dest_start = dest; 1.5641 + if (src_offset != NULL || dest_offset != NULL) { 1.5642 + assert(src_offset != NULL && dest_offset != NULL, ""); 1.5643 + src_start = array_element_address(src, src_offset, basic_elem_type); 1.5644 + dest_start = array_element_address(dest, dest_offset, basic_elem_type); 1.5645 + } 1.5646 + 1.5647 + // Figure out which arraycopy runtime method to call. 1.5648 + const char* copyfunc_name = "arraycopy"; 1.5649 + address copyfunc_addr = 1.5650 + basictype2arraycopy(basic_elem_type, src_offset, dest_offset, 1.5651 + disjoint_bases, copyfunc_name, dest_uninitialized); 1.5652 + 1.5653 + // Call it. Note that the count_ix value is not scaled to a byte-size. 1.5654 + make_runtime_call(RC_LEAF|RC_NO_FP, 1.5655 + OptoRuntime::fast_arraycopy_Type(), 1.5656 + copyfunc_addr, copyfunc_name, adr_type, 1.5657 + src_start, dest_start, copy_length XTOP); 1.5658 +} 1.5659 + 1.5660 +//-------------inline_encodeISOArray----------------------------------- 1.5661 +// encode char[] to byte[] in ISO_8859_1 1.5662 +bool LibraryCallKit::inline_encodeISOArray() { 1.5663 + assert(callee()->signature()->size() == 5, "encodeISOArray has 5 parameters"); 1.5664 + // no receiver since it is static method 1.5665 + Node *src = argument(0); 1.5666 + Node *src_offset = argument(1); 1.5667 + Node *dst = argument(2); 1.5668 + Node *dst_offset = argument(3); 1.5669 + Node *length = argument(4); 1.5670 + 1.5671 + const Type* src_type = src->Value(&_gvn); 1.5672 + const Type* dst_type = dst->Value(&_gvn); 1.5673 + const TypeAryPtr* top_src = src_type->isa_aryptr(); 1.5674 + const TypeAryPtr* top_dest = dst_type->isa_aryptr(); 1.5675 + if (top_src == NULL || top_src->klass() == NULL || 1.5676 + top_dest == NULL || top_dest->klass() == NULL) { 1.5677 + // failed array check 1.5678 + return false; 1.5679 + } 1.5680 + 1.5681 + // Figure out the size and type of the elements we will be copying. 1.5682 + BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 1.5683 + BasicType dst_elem = dst_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 1.5684 + if (src_elem != T_CHAR || dst_elem != T_BYTE) { 1.5685 + return false; 1.5686 + } 1.5687 + Node* src_start = array_element_address(src, src_offset, src_elem); 1.5688 + Node* dst_start = array_element_address(dst, dst_offset, dst_elem); 1.5689 + // 'src_start' points to src array + scaled offset 1.5690 + // 'dst_start' points to dst array + scaled offset 1.5691 + 1.5692 + const TypeAryPtr* mtype = TypeAryPtr::BYTES; 1.5693 + Node* enc = new (C) EncodeISOArrayNode(control(), memory(mtype), src_start, dst_start, length); 1.5694 + enc = _gvn.transform(enc); 1.5695 + Node* res_mem = _gvn.transform(new (C) SCMemProjNode(enc)); 1.5696 + set_memory(res_mem, mtype); 1.5697 + set_result(enc); 1.5698 + return true; 1.5699 +} 1.5700 + 1.5701 +/** 1.5702 + * Calculate CRC32 for byte. 1.5703 + * int java.util.zip.CRC32.update(int crc, int b) 1.5704 + */ 1.5705 +bool LibraryCallKit::inline_updateCRC32() { 1.5706 + assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support"); 1.5707 + assert(callee()->signature()->size() == 2, "update has 2 parameters"); 1.5708 + // no receiver since it is static method 1.5709 + Node* crc = argument(0); // type: int 1.5710 + Node* b = argument(1); // type: int 1.5711 + 1.5712 + /* 1.5713 + * int c = ~ crc; 1.5714 + * b = timesXtoThe32[(b ^ c) & 0xFF]; 1.5715 + * b = b ^ (c >>> 8); 1.5716 + * crc = ~b; 1.5717 + */ 1.5718 + 1.5719 + Node* M1 = intcon(-1); 1.5720 + crc = _gvn.transform(new (C) XorINode(crc, M1)); 1.5721 + Node* result = _gvn.transform(new (C) XorINode(crc, b)); 1.5722 + result = _gvn.transform(new (C) AndINode(result, intcon(0xFF))); 1.5723 + 1.5724 + Node* base = makecon(TypeRawPtr::make(StubRoutines::crc_table_addr())); 1.5725 + Node* offset = _gvn.transform(new (C) LShiftINode(result, intcon(0x2))); 1.5726 + Node* adr = basic_plus_adr(top(), base, ConvI2X(offset)); 1.5727 + result = make_load(control(), adr, TypeInt::INT, T_INT, MemNode::unordered); 1.5728 + 1.5729 + crc = _gvn.transform(new (C) URShiftINode(crc, intcon(8))); 1.5730 + result = _gvn.transform(new (C) XorINode(crc, result)); 1.5731 + result = _gvn.transform(new (C) XorINode(result, M1)); 1.5732 + set_result(result); 1.5733 + return true; 1.5734 +} 1.5735 + 1.5736 +/** 1.5737 + * Calculate CRC32 for byte[] array. 1.5738 + * int java.util.zip.CRC32.updateBytes(int crc, byte[] buf, int off, int len) 1.5739 + */ 1.5740 +bool LibraryCallKit::inline_updateBytesCRC32() { 1.5741 + assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support"); 1.5742 + assert(callee()->signature()->size() == 4, "updateBytes has 4 parameters"); 1.5743 + // no receiver since it is static method 1.5744 + Node* crc = argument(0); // type: int 1.5745 + Node* src = argument(1); // type: oop 1.5746 + Node* offset = argument(2); // type: int 1.5747 + Node* length = argument(3); // type: int 1.5748 + 1.5749 + const Type* src_type = src->Value(&_gvn); 1.5750 + const TypeAryPtr* top_src = src_type->isa_aryptr(); 1.5751 + if (top_src == NULL || top_src->klass() == NULL) { 1.5752 + // failed array check 1.5753 + return false; 1.5754 + } 1.5755 + 1.5756 + // Figure out the size and type of the elements we will be copying. 1.5757 + BasicType src_elem = src_type->isa_aryptr()->klass()->as_array_klass()->element_type()->basic_type(); 1.5758 + if (src_elem != T_BYTE) { 1.5759 + return false; 1.5760 + } 1.5761 + 1.5762 + // 'src_start' points to src array + scaled offset 1.5763 + Node* src_start = array_element_address(src, offset, src_elem); 1.5764 + 1.5765 + // We assume that range check is done by caller. 1.5766 + // TODO: generate range check (offset+length < src.length) in debug VM. 1.5767 + 1.5768 + // Call the stub. 1.5769 + address stubAddr = StubRoutines::updateBytesCRC32(); 1.5770 + const char *stubName = "updateBytesCRC32"; 1.5771 + 1.5772 + Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(), 1.5773 + stubAddr, stubName, TypePtr::BOTTOM, 1.5774 + crc, src_start, length); 1.5775 + Node* result = _gvn.transform(new (C) ProjNode(call, TypeFunc::Parms)); 1.5776 + set_result(result); 1.5777 + return true; 1.5778 +} 1.5779 + 1.5780 +/** 1.5781 + * Calculate CRC32 for ByteBuffer. 1.5782 + * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len) 1.5783 + */ 1.5784 +bool LibraryCallKit::inline_updateByteBufferCRC32() { 1.5785 + assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support"); 1.5786 + assert(callee()->signature()->size() == 5, "updateByteBuffer has 4 parameters and one is long"); 1.5787 + // no receiver since it is static method 1.5788 + Node* crc = argument(0); // type: int 1.5789 + Node* src = argument(1); // type: long 1.5790 + Node* offset = argument(3); // type: int 1.5791 + Node* length = argument(4); // type: int 1.5792 + 1.5793 + src = ConvL2X(src); // adjust Java long to machine word 1.5794 + Node* base = _gvn.transform(new (C) CastX2PNode(src)); 1.5795 + offset = ConvI2X(offset); 1.5796 + 1.5797 + // 'src_start' points to src array + scaled offset 1.5798 + Node* src_start = basic_plus_adr(top(), base, offset); 1.5799 + 1.5800 + // Call the stub. 1.5801 + address stubAddr = StubRoutines::updateBytesCRC32(); 1.5802 + const char *stubName = "updateBytesCRC32"; 1.5803 + 1.5804 + Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::updateBytesCRC32_Type(), 1.5805 + stubAddr, stubName, TypePtr::BOTTOM, 1.5806 + crc, src_start, length); 1.5807 + Node* result = _gvn.transform(new (C) ProjNode(call, TypeFunc::Parms)); 1.5808 + set_result(result); 1.5809 + return true; 1.5810 +} 1.5811 + 1.5812 +//----------------------------inline_reference_get---------------------------- 1.5813 +// public T java.lang.ref.Reference.get(); 1.5814 +bool LibraryCallKit::inline_reference_get() { 1.5815 + const int referent_offset = java_lang_ref_Reference::referent_offset; 1.5816 + guarantee(referent_offset > 0, "should have already been set"); 1.5817 + 1.5818 + // Get the argument: 1.5819 + Node* reference_obj = null_check_receiver(); 1.5820 + if (stopped()) return true; 1.5821 + 1.5822 + Node* adr = basic_plus_adr(reference_obj, reference_obj, referent_offset); 1.5823 + 1.5824 + ciInstanceKlass* klass = env()->Object_klass(); 1.5825 + const TypeOopPtr* object_type = TypeOopPtr::make_from_klass(klass); 1.5826 + 1.5827 + Node* no_ctrl = NULL; 1.5828 + Node* result = make_load(no_ctrl, adr, object_type, T_OBJECT, MemNode::unordered); 1.5829 + 1.5830 + // Use the pre-barrier to record the value in the referent field 1.5831 + pre_barrier(false /* do_load */, 1.5832 + control(), 1.5833 + NULL /* obj */, NULL /* adr */, max_juint /* alias_idx */, NULL /* val */, NULL /* val_type */, 1.5834 + result /* pre_val */, 1.5835 + T_OBJECT); 1.5836 + 1.5837 + // Add memory barrier to prevent commoning reads from this field 1.5838 + // across safepoint since GC can change its value. 1.5839 + insert_mem_bar(Op_MemBarCPUOrder); 1.5840 + 1.5841 + set_result(result); 1.5842 + return true; 1.5843 +} 1.5844 + 1.5845 + 1.5846 +Node * LibraryCallKit::load_field_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, 1.5847 + bool is_exact=true, bool is_static=false) { 1.5848 + 1.5849 + const TypeInstPtr* tinst = _gvn.type(fromObj)->isa_instptr(); 1.5850 + assert(tinst != NULL, "obj is null"); 1.5851 + assert(tinst->klass()->is_loaded(), "obj is not loaded"); 1.5852 + assert(!is_exact || tinst->klass_is_exact(), "klass not exact"); 1.5853 + 1.5854 + ciField* field = tinst->klass()->as_instance_klass()->get_field_by_name(ciSymbol::make(fieldName), 1.5855 + ciSymbol::make(fieldTypeString), 1.5856 + is_static); 1.5857 + if (field == NULL) return (Node *) NULL; 1.5858 + assert (field != NULL, "undefined field"); 1.5859 + 1.5860 + // Next code copied from Parse::do_get_xxx(): 1.5861 + 1.5862 + // Compute address and memory type. 1.5863 + int offset = field->offset_in_bytes(); 1.5864 + bool is_vol = field->is_volatile(); 1.5865 + ciType* field_klass = field->type(); 1.5866 + assert(field_klass->is_loaded(), "should be loaded"); 1.5867 + const TypePtr* adr_type = C->alias_type(field)->adr_type(); 1.5868 + Node *adr = basic_plus_adr(fromObj, fromObj, offset); 1.5869 + BasicType bt = field->layout_type(); 1.5870 + 1.5871 + // Build the resultant type of the load 1.5872 + const Type *type = TypeOopPtr::make_from_klass(field_klass->as_klass()); 1.5873 + 1.5874 + // Build the load. 1.5875 + Node* loadedField = make_load(NULL, adr, type, bt, adr_type, MemNode::unordered, is_vol); 1.5876 + return loadedField; 1.5877 +} 1.5878 + 1.5879 + 1.5880 +//------------------------------inline_aescrypt_Block----------------------- 1.5881 +bool LibraryCallKit::inline_aescrypt_Block(vmIntrinsics::ID id) { 1.5882 + address stubAddr; 1.5883 + const char *stubName; 1.5884 + assert(UseAES, "need AES instruction support"); 1.5885 + 1.5886 + switch(id) { 1.5887 + case vmIntrinsics::_aescrypt_encryptBlock: 1.5888 + stubAddr = StubRoutines::aescrypt_encryptBlock(); 1.5889 + stubName = "aescrypt_encryptBlock"; 1.5890 + break; 1.5891 + case vmIntrinsics::_aescrypt_decryptBlock: 1.5892 + stubAddr = StubRoutines::aescrypt_decryptBlock(); 1.5893 + stubName = "aescrypt_decryptBlock"; 1.5894 + break; 1.5895 + } 1.5896 + if (stubAddr == NULL) return false; 1.5897 + 1.5898 + Node* aescrypt_object = argument(0); 1.5899 + Node* src = argument(1); 1.5900 + Node* src_offset = argument(2); 1.5901 + Node* dest = argument(3); 1.5902 + Node* dest_offset = argument(4); 1.5903 + 1.5904 + // (1) src and dest are arrays. 1.5905 + const Type* src_type = src->Value(&_gvn); 1.5906 + const Type* dest_type = dest->Value(&_gvn); 1.5907 + const TypeAryPtr* top_src = src_type->isa_aryptr(); 1.5908 + const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 1.5909 + assert (top_src != NULL && top_src->klass() != NULL && top_dest != NULL && top_dest->klass() != NULL, "args are strange"); 1.5910 + 1.5911 + // for the quick and dirty code we will skip all the checks. 1.5912 + // we are just trying to get the call to be generated. 1.5913 + Node* src_start = src; 1.5914 + Node* dest_start = dest; 1.5915 + if (src_offset != NULL || dest_offset != NULL) { 1.5916 + assert(src_offset != NULL && dest_offset != NULL, ""); 1.5917 + src_start = array_element_address(src, src_offset, T_BYTE); 1.5918 + dest_start = array_element_address(dest, dest_offset, T_BYTE); 1.5919 + } 1.5920 + 1.5921 + // now need to get the start of its expanded key array 1.5922 + // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 1.5923 + Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 1.5924 + if (k_start == NULL) return false; 1.5925 + 1.5926 + if (Matcher::pass_original_key_for_aes()) { 1.5927 + // on SPARC we need to pass the original key since key expansion needs to happen in intrinsics due to 1.5928 + // compatibility issues between Java key expansion and SPARC crypto instructions 1.5929 + Node* original_k_start = get_original_key_start_from_aescrypt_object(aescrypt_object); 1.5930 + if (original_k_start == NULL) return false; 1.5931 + 1.5932 + // Call the stub. 1.5933 + make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::aescrypt_block_Type(), 1.5934 + stubAddr, stubName, TypePtr::BOTTOM, 1.5935 + src_start, dest_start, k_start, original_k_start); 1.5936 + } else { 1.5937 + // Call the stub. 1.5938 + make_runtime_call(RC_LEAF|RC_NO_FP, OptoRuntime::aescrypt_block_Type(), 1.5939 + stubAddr, stubName, TypePtr::BOTTOM, 1.5940 + src_start, dest_start, k_start); 1.5941 + } 1.5942 + 1.5943 + return true; 1.5944 +} 1.5945 + 1.5946 +//------------------------------inline_cipherBlockChaining_AESCrypt----------------------- 1.5947 +bool LibraryCallKit::inline_cipherBlockChaining_AESCrypt(vmIntrinsics::ID id) { 1.5948 + address stubAddr; 1.5949 + const char *stubName; 1.5950 + 1.5951 + assert(UseAES, "need AES instruction support"); 1.5952 + 1.5953 + switch(id) { 1.5954 + case vmIntrinsics::_cipherBlockChaining_encryptAESCrypt: 1.5955 + stubAddr = StubRoutines::cipherBlockChaining_encryptAESCrypt(); 1.5956 + stubName = "cipherBlockChaining_encryptAESCrypt"; 1.5957 + break; 1.5958 + case vmIntrinsics::_cipherBlockChaining_decryptAESCrypt: 1.5959 + stubAddr = StubRoutines::cipherBlockChaining_decryptAESCrypt(); 1.5960 + stubName = "cipherBlockChaining_decryptAESCrypt"; 1.5961 + break; 1.5962 + } 1.5963 + if (stubAddr == NULL) return false; 1.5964 + 1.5965 + Node* cipherBlockChaining_object = argument(0); 1.5966 + Node* src = argument(1); 1.5967 + Node* src_offset = argument(2); 1.5968 + Node* len = argument(3); 1.5969 + Node* dest = argument(4); 1.5970 + Node* dest_offset = argument(5); 1.5971 + 1.5972 + // (1) src and dest are arrays. 1.5973 + const Type* src_type = src->Value(&_gvn); 1.5974 + const Type* dest_type = dest->Value(&_gvn); 1.5975 + const TypeAryPtr* top_src = src_type->isa_aryptr(); 1.5976 + const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 1.5977 + assert (top_src != NULL && top_src->klass() != NULL 1.5978 + && top_dest != NULL && top_dest->klass() != NULL, "args are strange"); 1.5979 + 1.5980 + // checks are the responsibility of the caller 1.5981 + Node* src_start = src; 1.5982 + Node* dest_start = dest; 1.5983 + if (src_offset != NULL || dest_offset != NULL) { 1.5984 + assert(src_offset != NULL && dest_offset != NULL, ""); 1.5985 + src_start = array_element_address(src, src_offset, T_BYTE); 1.5986 + dest_start = array_element_address(dest, dest_offset, T_BYTE); 1.5987 + } 1.5988 + 1.5989 + // if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object 1.5990 + // (because of the predicated logic executed earlier). 1.5991 + // so we cast it here safely. 1.5992 + // this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java 1.5993 + 1.5994 + Node* embeddedCipherObj = load_field_from_object(cipherBlockChaining_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false); 1.5995 + if (embeddedCipherObj == NULL) return false; 1.5996 + 1.5997 + // cast it to what we know it will be at runtime 1.5998 + const TypeInstPtr* tinst = _gvn.type(cipherBlockChaining_object)->isa_instptr(); 1.5999 + assert(tinst != NULL, "CBC obj is null"); 1.6000 + assert(tinst->klass()->is_loaded(), "CBC obj is not loaded"); 1.6001 + ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 1.6002 + if (!klass_AESCrypt->is_loaded()) return false; 1.6003 + 1.6004 + ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 1.6005 + const TypeKlassPtr* aklass = TypeKlassPtr::make(instklass_AESCrypt); 1.6006 + const TypeOopPtr* xtype = aklass->as_instance_type(); 1.6007 + Node* aescrypt_object = new(C) CheckCastPPNode(control(), embeddedCipherObj, xtype); 1.6008 + aescrypt_object = _gvn.transform(aescrypt_object); 1.6009 + 1.6010 + // we need to get the start of the aescrypt_object's expanded key array 1.6011 + Node* k_start = get_key_start_from_aescrypt_object(aescrypt_object); 1.6012 + if (k_start == NULL) return false; 1.6013 + 1.6014 + // similarly, get the start address of the r vector 1.6015 + Node* objRvec = load_field_from_object(cipherBlockChaining_object, "r", "[B", /*is_exact*/ false); 1.6016 + if (objRvec == NULL) return false; 1.6017 + Node* r_start = array_element_address(objRvec, intcon(0), T_BYTE); 1.6018 + 1.6019 + Node* cbcCrypt; 1.6020 + if (Matcher::pass_original_key_for_aes()) { 1.6021 + // on SPARC we need to pass the original key since key expansion needs to happen in intrinsics due to 1.6022 + // compatibility issues between Java key expansion and SPARC crypto instructions 1.6023 + Node* original_k_start = get_original_key_start_from_aescrypt_object(aescrypt_object); 1.6024 + if (original_k_start == NULL) return false; 1.6025 + 1.6026 + // Call the stub, passing src_start, dest_start, k_start, r_start, src_len and original_k_start 1.6027 + cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 1.6028 + OptoRuntime::cipherBlockChaining_aescrypt_Type(), 1.6029 + stubAddr, stubName, TypePtr::BOTTOM, 1.6030 + src_start, dest_start, k_start, r_start, len, original_k_start); 1.6031 + } else { 1.6032 + // Call the stub, passing src_start, dest_start, k_start, r_start and src_len 1.6033 + cbcCrypt = make_runtime_call(RC_LEAF|RC_NO_FP, 1.6034 + OptoRuntime::cipherBlockChaining_aescrypt_Type(), 1.6035 + stubAddr, stubName, TypePtr::BOTTOM, 1.6036 + src_start, dest_start, k_start, r_start, len); 1.6037 + } 1.6038 + 1.6039 + // return cipher length (int) 1.6040 + Node* retvalue = _gvn.transform(new (C) ProjNode(cbcCrypt, TypeFunc::Parms)); 1.6041 + set_result(retvalue); 1.6042 + return true; 1.6043 +} 1.6044 + 1.6045 +//------------------------------get_key_start_from_aescrypt_object----------------------- 1.6046 +Node * LibraryCallKit::get_key_start_from_aescrypt_object(Node *aescrypt_object) { 1.6047 + Node* objAESCryptKey = load_field_from_object(aescrypt_object, "K", "[I", /*is_exact*/ false); 1.6048 + assert (objAESCryptKey != NULL, "wrong version of com.sun.crypto.provider.AESCrypt"); 1.6049 + if (objAESCryptKey == NULL) return (Node *) NULL; 1.6050 + 1.6051 + // now have the array, need to get the start address of the K array 1.6052 + Node* k_start = array_element_address(objAESCryptKey, intcon(0), T_INT); 1.6053 + return k_start; 1.6054 +} 1.6055 + 1.6056 +//------------------------------get_original_key_start_from_aescrypt_object----------------------- 1.6057 +Node * LibraryCallKit::get_original_key_start_from_aescrypt_object(Node *aescrypt_object) { 1.6058 + Node* objAESCryptKey = load_field_from_object(aescrypt_object, "lastKey", "[B", /*is_exact*/ false); 1.6059 + assert (objAESCryptKey != NULL, "wrong version of com.sun.crypto.provider.AESCrypt"); 1.6060 + if (objAESCryptKey == NULL) return (Node *) NULL; 1.6061 + 1.6062 + // now have the array, need to get the start address of the lastKey array 1.6063 + Node* original_k_start = array_element_address(objAESCryptKey, intcon(0), T_BYTE); 1.6064 + return original_k_start; 1.6065 +} 1.6066 + 1.6067 +//----------------------------inline_cipherBlockChaining_AESCrypt_predicate---------------------------- 1.6068 +// Return node representing slow path of predicate check. 1.6069 +// the pseudo code we want to emulate with this predicate is: 1.6070 +// for encryption: 1.6071 +// if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath 1.6072 +// for decryption: 1.6073 +// if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath 1.6074 +// note cipher==plain is more conservative than the original java code but that's OK 1.6075 +// 1.6076 +Node* LibraryCallKit::inline_cipherBlockChaining_AESCrypt_predicate(bool decrypting) { 1.6077 + // First, check receiver for NULL since it is virtual method. 1.6078 + Node* objCBC = argument(0); 1.6079 + objCBC = null_check(objCBC); 1.6080 + 1.6081 + if (stopped()) return NULL; // Always NULL 1.6082 + 1.6083 + // Load embeddedCipher field of CipherBlockChaining object. 1.6084 + Node* embeddedCipherObj = load_field_from_object(objCBC, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false); 1.6085 + 1.6086 + // get AESCrypt klass for instanceOf check 1.6087 + // AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point 1.6088 + // will have same classloader as CipherBlockChaining object 1.6089 + const TypeInstPtr* tinst = _gvn.type(objCBC)->isa_instptr(); 1.6090 + assert(tinst != NULL, "CBCobj is null"); 1.6091 + assert(tinst->klass()->is_loaded(), "CBCobj is not loaded"); 1.6092 + 1.6093 + // we want to do an instanceof comparison against the AESCrypt class 1.6094 + ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt")); 1.6095 + if (!klass_AESCrypt->is_loaded()) { 1.6096 + // if AESCrypt is not even loaded, we never take the intrinsic fast path 1.6097 + Node* ctrl = control(); 1.6098 + set_control(top()); // no regular fast path 1.6099 + return ctrl; 1.6100 + } 1.6101 + ciInstanceKlass* instklass_AESCrypt = klass_AESCrypt->as_instance_klass(); 1.6102 + 1.6103 + Node* instof = gen_instanceof(embeddedCipherObj, makecon(TypeKlassPtr::make(instklass_AESCrypt))); 1.6104 + Node* cmp_instof = _gvn.transform(new (C) CmpINode(instof, intcon(1))); 1.6105 + Node* bool_instof = _gvn.transform(new (C) BoolNode(cmp_instof, BoolTest::ne)); 1.6106 + 1.6107 + Node* instof_false = generate_guard(bool_instof, NULL, PROB_MIN); 1.6108 + 1.6109 + // for encryption, we are done 1.6110 + if (!decrypting) 1.6111 + return instof_false; // even if it is NULL 1.6112 + 1.6113 + // for decryption, we need to add a further check to avoid 1.6114 + // taking the intrinsic path when cipher and plain are the same 1.6115 + // see the original java code for why. 1.6116 + RegionNode* region = new(C) RegionNode(3); 1.6117 + region->init_req(1, instof_false); 1.6118 + Node* src = argument(1); 1.6119 + Node* dest = argument(4); 1.6120 + Node* cmp_src_dest = _gvn.transform(new (C) CmpPNode(src, dest)); 1.6121 + Node* bool_src_dest = _gvn.transform(new (C) BoolNode(cmp_src_dest, BoolTest::eq)); 1.6122 + Node* src_dest_conjoint = generate_guard(bool_src_dest, NULL, PROB_MIN); 1.6123 + region->init_req(2, src_dest_conjoint); 1.6124 + 1.6125 + record_for_igvn(region); 1.6126 + return _gvn.transform(region); 1.6127 +}