1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/opto/library_call.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,4921 @@ 1.4 +/* 1.5 + * Copyright 1999-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "incls/_precompiled.incl" 1.29 +#include "incls/_library_call.cpp.incl" 1.30 + 1.31 +class LibraryIntrinsic : public InlineCallGenerator { 1.32 + // Extend the set of intrinsics known to the runtime: 1.33 + public: 1.34 + private: 1.35 + bool _is_virtual; 1.36 + vmIntrinsics::ID _intrinsic_id; 1.37 + 1.38 + public: 1.39 + LibraryIntrinsic(ciMethod* m, bool is_virtual, vmIntrinsics::ID id) 1.40 + : InlineCallGenerator(m), 1.41 + _is_virtual(is_virtual), 1.42 + _intrinsic_id(id) 1.43 + { 1.44 + } 1.45 + virtual bool is_intrinsic() const { return true; } 1.46 + virtual bool is_virtual() const { return _is_virtual; } 1.47 + virtual JVMState* generate(JVMState* jvms); 1.48 + vmIntrinsics::ID intrinsic_id() const { return _intrinsic_id; } 1.49 +}; 1.50 + 1.51 + 1.52 +// Local helper class for LibraryIntrinsic: 1.53 +class LibraryCallKit : public GraphKit { 1.54 + private: 1.55 + LibraryIntrinsic* _intrinsic; // the library intrinsic being called 1.56 + 1.57 + public: 1.58 + LibraryCallKit(JVMState* caller, LibraryIntrinsic* intrinsic) 1.59 + : GraphKit(caller), 1.60 + _intrinsic(intrinsic) 1.61 + { 1.62 + } 1.63 + 1.64 + ciMethod* caller() const { return jvms()->method(); } 1.65 + int bci() const { return jvms()->bci(); } 1.66 + LibraryIntrinsic* intrinsic() const { return _intrinsic; } 1.67 + vmIntrinsics::ID intrinsic_id() const { return _intrinsic->intrinsic_id(); } 1.68 + ciMethod* callee() const { return _intrinsic->method(); } 1.69 + ciSignature* signature() const { return callee()->signature(); } 1.70 + int arg_size() const { return callee()->arg_size(); } 1.71 + 1.72 + bool try_to_inline(); 1.73 + 1.74 + // Helper functions to inline natives 1.75 + void push_result(RegionNode* region, PhiNode* value); 1.76 + Node* generate_guard(Node* test, RegionNode* region, float true_prob); 1.77 + Node* generate_slow_guard(Node* test, RegionNode* region); 1.78 + Node* generate_fair_guard(Node* test, RegionNode* region); 1.79 + Node* generate_negative_guard(Node* index, RegionNode* region, 1.80 + // resulting CastII of index: 1.81 + Node* *pos_index = NULL); 1.82 + Node* generate_nonpositive_guard(Node* index, bool never_negative, 1.83 + // resulting CastII of index: 1.84 + Node* *pos_index = NULL); 1.85 + Node* generate_limit_guard(Node* offset, Node* subseq_length, 1.86 + Node* array_length, 1.87 + RegionNode* region); 1.88 + Node* generate_current_thread(Node* &tls_output); 1.89 + address basictype2arraycopy(BasicType t, Node *src_offset, Node *dest_offset, 1.90 + bool disjoint_bases, const char* &name); 1.91 + Node* load_mirror_from_klass(Node* klass); 1.92 + Node* load_klass_from_mirror_common(Node* mirror, bool never_see_null, 1.93 + int nargs, 1.94 + RegionNode* region, int null_path, 1.95 + int offset); 1.96 + Node* load_klass_from_mirror(Node* mirror, bool never_see_null, int nargs, 1.97 + RegionNode* region, int null_path) { 1.98 + int offset = java_lang_Class::klass_offset_in_bytes(); 1.99 + return load_klass_from_mirror_common(mirror, never_see_null, nargs, 1.100 + region, null_path, 1.101 + offset); 1.102 + } 1.103 + Node* load_array_klass_from_mirror(Node* mirror, bool never_see_null, 1.104 + int nargs, 1.105 + RegionNode* region, int null_path) { 1.106 + int offset = java_lang_Class::array_klass_offset_in_bytes(); 1.107 + return load_klass_from_mirror_common(mirror, never_see_null, nargs, 1.108 + region, null_path, 1.109 + offset); 1.110 + } 1.111 + Node* generate_access_flags_guard(Node* kls, 1.112 + int modifier_mask, int modifier_bits, 1.113 + RegionNode* region); 1.114 + Node* generate_interface_guard(Node* kls, RegionNode* region); 1.115 + Node* generate_array_guard(Node* kls, RegionNode* region) { 1.116 + return generate_array_guard_common(kls, region, false, false); 1.117 + } 1.118 + Node* generate_non_array_guard(Node* kls, RegionNode* region) { 1.119 + return generate_array_guard_common(kls, region, false, true); 1.120 + } 1.121 + Node* generate_objArray_guard(Node* kls, RegionNode* region) { 1.122 + return generate_array_guard_common(kls, region, true, false); 1.123 + } 1.124 + Node* generate_non_objArray_guard(Node* kls, RegionNode* region) { 1.125 + return generate_array_guard_common(kls, region, true, true); 1.126 + } 1.127 + Node* generate_array_guard_common(Node* kls, RegionNode* region, 1.128 + bool obj_array, bool not_array); 1.129 + Node* generate_virtual_guard(Node* obj_klass, RegionNode* slow_region); 1.130 + CallJavaNode* generate_method_call(vmIntrinsics::ID method_id, 1.131 + bool is_virtual = false, bool is_static = false); 1.132 + CallJavaNode* generate_method_call_static(vmIntrinsics::ID method_id) { 1.133 + return generate_method_call(method_id, false, true); 1.134 + } 1.135 + CallJavaNode* generate_method_call_virtual(vmIntrinsics::ID method_id) { 1.136 + return generate_method_call(method_id, true, false); 1.137 + } 1.138 + 1.139 + bool inline_string_compareTo(); 1.140 + bool inline_string_indexOf(); 1.141 + Node* string_indexOf(Node* string_object, ciTypeArray* target_array, jint offset, jint cache_i, jint md2_i); 1.142 + Node* pop_math_arg(); 1.143 + bool runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName); 1.144 + bool inline_math_native(vmIntrinsics::ID id); 1.145 + bool inline_trig(vmIntrinsics::ID id); 1.146 + bool inline_trans(vmIntrinsics::ID id); 1.147 + bool inline_abs(vmIntrinsics::ID id); 1.148 + bool inline_sqrt(vmIntrinsics::ID id); 1.149 + bool inline_pow(vmIntrinsics::ID id); 1.150 + bool inline_exp(vmIntrinsics::ID id); 1.151 + bool inline_min_max(vmIntrinsics::ID id); 1.152 + Node* generate_min_max(vmIntrinsics::ID id, Node* x, Node* y); 1.153 + // This returns Type::AnyPtr, RawPtr, or OopPtr. 1.154 + int classify_unsafe_addr(Node* &base, Node* &offset); 1.155 + Node* make_unsafe_address(Node* base, Node* offset); 1.156 + bool inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile); 1.157 + bool inline_unsafe_prefetch(bool is_native_ptr, bool is_store, bool is_static); 1.158 + bool inline_unsafe_allocate(); 1.159 + bool inline_unsafe_copyMemory(); 1.160 + bool inline_native_currentThread(); 1.161 + bool inline_native_time_funcs(bool isNano); 1.162 + bool inline_native_isInterrupted(); 1.163 + bool inline_native_Class_query(vmIntrinsics::ID id); 1.164 + bool inline_native_subtype_check(); 1.165 + 1.166 + bool inline_native_newArray(); 1.167 + bool inline_native_getLength(); 1.168 + bool inline_array_copyOf(bool is_copyOfRange); 1.169 + bool inline_native_clone(bool is_virtual); 1.170 + bool inline_native_Reflection_getCallerClass(); 1.171 + bool inline_native_AtomicLong_get(); 1.172 + bool inline_native_AtomicLong_attemptUpdate(); 1.173 + bool is_method_invoke_or_aux_frame(JVMState* jvms); 1.174 + // Helper function for inlining native object hash method 1.175 + bool inline_native_hashcode(bool is_virtual, bool is_static); 1.176 + bool inline_native_getClass(); 1.177 + 1.178 + // Helper functions for inlining arraycopy 1.179 + bool inline_arraycopy(); 1.180 + void generate_arraycopy(const TypePtr* adr_type, 1.181 + BasicType basic_elem_type, 1.182 + Node* src, Node* src_offset, 1.183 + Node* dest, Node* dest_offset, 1.184 + Node* copy_length, 1.185 + int nargs, // arguments on stack for debug info 1.186 + bool disjoint_bases = false, 1.187 + bool length_never_negative = false, 1.188 + RegionNode* slow_region = NULL); 1.189 + AllocateArrayNode* tightly_coupled_allocation(Node* ptr, 1.190 + RegionNode* slow_region); 1.191 + void generate_clear_array(const TypePtr* adr_type, 1.192 + Node* dest, 1.193 + BasicType basic_elem_type, 1.194 + Node* slice_off, 1.195 + Node* slice_len, 1.196 + Node* slice_end); 1.197 + bool generate_block_arraycopy(const TypePtr* adr_type, 1.198 + BasicType basic_elem_type, 1.199 + AllocateNode* alloc, 1.200 + Node* src, Node* src_offset, 1.201 + Node* dest, Node* dest_offset, 1.202 + Node* dest_size); 1.203 + void generate_slow_arraycopy(const TypePtr* adr_type, 1.204 + Node* src, Node* src_offset, 1.205 + Node* dest, Node* dest_offset, 1.206 + Node* copy_length, 1.207 + int nargs); 1.208 + Node* generate_checkcast_arraycopy(const TypePtr* adr_type, 1.209 + Node* dest_elem_klass, 1.210 + Node* src, Node* src_offset, 1.211 + Node* dest, Node* dest_offset, 1.212 + Node* copy_length, int nargs); 1.213 + Node* generate_generic_arraycopy(const TypePtr* adr_type, 1.214 + Node* src, Node* src_offset, 1.215 + Node* dest, Node* dest_offset, 1.216 + Node* copy_length, int nargs); 1.217 + void generate_unchecked_arraycopy(const TypePtr* adr_type, 1.218 + BasicType basic_elem_type, 1.219 + bool disjoint_bases, 1.220 + Node* src, Node* src_offset, 1.221 + Node* dest, Node* dest_offset, 1.222 + Node* copy_length); 1.223 + bool inline_unsafe_CAS(BasicType type); 1.224 + bool inline_unsafe_ordered_store(BasicType type); 1.225 + bool inline_fp_conversions(vmIntrinsics::ID id); 1.226 + bool inline_reverseBytes(vmIntrinsics::ID id); 1.227 +}; 1.228 + 1.229 + 1.230 +//---------------------------make_vm_intrinsic---------------------------- 1.231 +CallGenerator* Compile::make_vm_intrinsic(ciMethod* m, bool is_virtual) { 1.232 + vmIntrinsics::ID id = m->intrinsic_id(); 1.233 + assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); 1.234 + 1.235 + if (DisableIntrinsic[0] != '\0' 1.236 + && strstr(DisableIntrinsic, vmIntrinsics::name_at(id)) != NULL) { 1.237 + // disabled by a user request on the command line: 1.238 + // example: -XX:DisableIntrinsic=_hashCode,_getClass 1.239 + return NULL; 1.240 + } 1.241 + 1.242 + if (!m->is_loaded()) { 1.243 + // do not attempt to inline unloaded methods 1.244 + return NULL; 1.245 + } 1.246 + 1.247 + // Only a few intrinsics implement a virtual dispatch. 1.248 + // They are expensive calls which are also frequently overridden. 1.249 + if (is_virtual) { 1.250 + switch (id) { 1.251 + case vmIntrinsics::_hashCode: 1.252 + case vmIntrinsics::_clone: 1.253 + // OK, Object.hashCode and Object.clone intrinsics come in both flavors 1.254 + break; 1.255 + default: 1.256 + return NULL; 1.257 + } 1.258 + } 1.259 + 1.260 + // -XX:-InlineNatives disables nearly all intrinsics: 1.261 + if (!InlineNatives) { 1.262 + switch (id) { 1.263 + case vmIntrinsics::_indexOf: 1.264 + case vmIntrinsics::_compareTo: 1.265 + break; // InlineNatives does not control String.compareTo 1.266 + default: 1.267 + return NULL; 1.268 + } 1.269 + } 1.270 + 1.271 + switch (id) { 1.272 + case vmIntrinsics::_compareTo: 1.273 + if (!SpecialStringCompareTo) return NULL; 1.274 + break; 1.275 + case vmIntrinsics::_indexOf: 1.276 + if (!SpecialStringIndexOf) return NULL; 1.277 + break; 1.278 + case vmIntrinsics::_arraycopy: 1.279 + if (!InlineArrayCopy) return NULL; 1.280 + break; 1.281 + case vmIntrinsics::_copyMemory: 1.282 + if (StubRoutines::unsafe_arraycopy() == NULL) return NULL; 1.283 + if (!InlineArrayCopy) return NULL; 1.284 + break; 1.285 + case vmIntrinsics::_hashCode: 1.286 + if (!InlineObjectHash) return NULL; 1.287 + break; 1.288 + case vmIntrinsics::_clone: 1.289 + case vmIntrinsics::_copyOf: 1.290 + case vmIntrinsics::_copyOfRange: 1.291 + if (!InlineObjectCopy) return NULL; 1.292 + // These also use the arraycopy intrinsic mechanism: 1.293 + if (!InlineArrayCopy) return NULL; 1.294 + break; 1.295 + case vmIntrinsics::_checkIndex: 1.296 + // We do not intrinsify this. The optimizer does fine with it. 1.297 + return NULL; 1.298 + 1.299 + case vmIntrinsics::_get_AtomicLong: 1.300 + case vmIntrinsics::_attemptUpdate: 1.301 + if (!InlineAtomicLong) return NULL; 1.302 + break; 1.303 + 1.304 + case vmIntrinsics::_Object_init: 1.305 + case vmIntrinsics::_invoke: 1.306 + // We do not intrinsify these; they are marked for other purposes. 1.307 + return NULL; 1.308 + 1.309 + case vmIntrinsics::_getCallerClass: 1.310 + if (!UseNewReflection) return NULL; 1.311 + if (!InlineReflectionGetCallerClass) return NULL; 1.312 + if (!JDK_Version::is_gte_jdk14x_version()) return NULL; 1.313 + break; 1.314 + 1.315 + default: 1.316 + break; 1.317 + } 1.318 + 1.319 + // -XX:-InlineClassNatives disables natives from the Class class. 1.320 + // The flag applies to all reflective calls, notably Array.newArray 1.321 + // (visible to Java programmers as Array.newInstance). 1.322 + if (m->holder()->name() == ciSymbol::java_lang_Class() || 1.323 + m->holder()->name() == ciSymbol::java_lang_reflect_Array()) { 1.324 + if (!InlineClassNatives) return NULL; 1.325 + } 1.326 + 1.327 + // -XX:-InlineThreadNatives disables natives from the Thread class. 1.328 + if (m->holder()->name() == ciSymbol::java_lang_Thread()) { 1.329 + if (!InlineThreadNatives) return NULL; 1.330 + } 1.331 + 1.332 + // -XX:-InlineMathNatives disables natives from the Math,Float and Double classes. 1.333 + if (m->holder()->name() == ciSymbol::java_lang_Math() || 1.334 + m->holder()->name() == ciSymbol::java_lang_Float() || 1.335 + m->holder()->name() == ciSymbol::java_lang_Double()) { 1.336 + if (!InlineMathNatives) return NULL; 1.337 + } 1.338 + 1.339 + // -XX:-InlineUnsafeOps disables natives from the Unsafe class. 1.340 + if (m->holder()->name() == ciSymbol::sun_misc_Unsafe()) { 1.341 + if (!InlineUnsafeOps) return NULL; 1.342 + } 1.343 + 1.344 + return new LibraryIntrinsic(m, is_virtual, (vmIntrinsics::ID) id); 1.345 +} 1.346 + 1.347 +//----------------------register_library_intrinsics----------------------- 1.348 +// Initialize this file's data structures, for each Compile instance. 1.349 +void Compile::register_library_intrinsics() { 1.350 + // Nothing to do here. 1.351 +} 1.352 + 1.353 +JVMState* LibraryIntrinsic::generate(JVMState* jvms) { 1.354 + LibraryCallKit kit(jvms, this); 1.355 + Compile* C = kit.C; 1.356 + int nodes = C->unique(); 1.357 +#ifndef PRODUCT 1.358 + if ((PrintIntrinsics || PrintInlining NOT_PRODUCT( || PrintOptoInlining) ) && Verbose) { 1.359 + char buf[1000]; 1.360 + const char* str = vmIntrinsics::short_name_as_C_string(intrinsic_id(), buf, sizeof(buf)); 1.361 + tty->print_cr("Intrinsic %s", str); 1.362 + } 1.363 +#endif 1.364 + if (kit.try_to_inline()) { 1.365 + if (PrintIntrinsics || PrintInlining NOT_PRODUCT( || PrintOptoInlining) ) { 1.366 + tty->print("Inlining intrinsic %s%s at bci:%d in", 1.367 + vmIntrinsics::name_at(intrinsic_id()), 1.368 + (is_virtual() ? " (virtual)" : ""), kit.bci()); 1.369 + kit.caller()->print_short_name(tty); 1.370 + tty->print_cr(" (%d bytes)", kit.caller()->code_size()); 1.371 + } 1.372 + C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_worked); 1.373 + if (C->log()) { 1.374 + C->log()->elem("intrinsic id='%s'%s nodes='%d'", 1.375 + vmIntrinsics::name_at(intrinsic_id()), 1.376 + (is_virtual() ? " virtual='1'" : ""), 1.377 + C->unique() - nodes); 1.378 + } 1.379 + return kit.transfer_exceptions_into_jvms(); 1.380 + } 1.381 + 1.382 + if (PrintIntrinsics) { 1.383 + switch (intrinsic_id()) { 1.384 + case vmIntrinsics::_invoke: 1.385 + case vmIntrinsics::_Object_init: 1.386 + // We do not expect to inline these, so do not produce any noise about them. 1.387 + break; 1.388 + default: 1.389 + tty->print("Did not inline intrinsic %s%s at bci:%d in", 1.390 + vmIntrinsics::name_at(intrinsic_id()), 1.391 + (is_virtual() ? " (virtual)" : ""), kit.bci()); 1.392 + kit.caller()->print_short_name(tty); 1.393 + tty->print_cr(" (%d bytes)", kit.caller()->code_size()); 1.394 + } 1.395 + } 1.396 + C->gather_intrinsic_statistics(intrinsic_id(), is_virtual(), Compile::_intrinsic_failed); 1.397 + return NULL; 1.398 +} 1.399 + 1.400 +bool LibraryCallKit::try_to_inline() { 1.401 + // Handle symbolic names for otherwise undistinguished boolean switches: 1.402 + const bool is_store = true; 1.403 + const bool is_native_ptr = true; 1.404 + const bool is_static = true; 1.405 + 1.406 + switch (intrinsic_id()) { 1.407 + case vmIntrinsics::_hashCode: 1.408 + return inline_native_hashcode(intrinsic()->is_virtual(), !is_static); 1.409 + case vmIntrinsics::_identityHashCode: 1.410 + return inline_native_hashcode(/*!virtual*/ false, is_static); 1.411 + case vmIntrinsics::_getClass: 1.412 + return inline_native_getClass(); 1.413 + 1.414 + case vmIntrinsics::_dsin: 1.415 + case vmIntrinsics::_dcos: 1.416 + case vmIntrinsics::_dtan: 1.417 + case vmIntrinsics::_dabs: 1.418 + case vmIntrinsics::_datan2: 1.419 + case vmIntrinsics::_dsqrt: 1.420 + case vmIntrinsics::_dexp: 1.421 + case vmIntrinsics::_dlog: 1.422 + case vmIntrinsics::_dlog10: 1.423 + case vmIntrinsics::_dpow: 1.424 + return inline_math_native(intrinsic_id()); 1.425 + 1.426 + case vmIntrinsics::_min: 1.427 + case vmIntrinsics::_max: 1.428 + return inline_min_max(intrinsic_id()); 1.429 + 1.430 + case vmIntrinsics::_arraycopy: 1.431 + return inline_arraycopy(); 1.432 + 1.433 + case vmIntrinsics::_compareTo: 1.434 + return inline_string_compareTo(); 1.435 + case vmIntrinsics::_indexOf: 1.436 + return inline_string_indexOf(); 1.437 + 1.438 + case vmIntrinsics::_getObject: 1.439 + return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT, false); 1.440 + case vmIntrinsics::_getBoolean: 1.441 + return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN, false); 1.442 + case vmIntrinsics::_getByte: 1.443 + return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE, false); 1.444 + case vmIntrinsics::_getShort: 1.445 + return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT, false); 1.446 + case vmIntrinsics::_getChar: 1.447 + return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR, false); 1.448 + case vmIntrinsics::_getInt: 1.449 + return inline_unsafe_access(!is_native_ptr, !is_store, T_INT, false); 1.450 + case vmIntrinsics::_getLong: 1.451 + return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG, false); 1.452 + case vmIntrinsics::_getFloat: 1.453 + return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT, false); 1.454 + case vmIntrinsics::_getDouble: 1.455 + return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE, false); 1.456 + 1.457 + case vmIntrinsics::_putObject: 1.458 + return inline_unsafe_access(!is_native_ptr, is_store, T_OBJECT, false); 1.459 + case vmIntrinsics::_putBoolean: 1.460 + return inline_unsafe_access(!is_native_ptr, is_store, T_BOOLEAN, false); 1.461 + case vmIntrinsics::_putByte: 1.462 + return inline_unsafe_access(!is_native_ptr, is_store, T_BYTE, false); 1.463 + case vmIntrinsics::_putShort: 1.464 + return inline_unsafe_access(!is_native_ptr, is_store, T_SHORT, false); 1.465 + case vmIntrinsics::_putChar: 1.466 + return inline_unsafe_access(!is_native_ptr, is_store, T_CHAR, false); 1.467 + case vmIntrinsics::_putInt: 1.468 + return inline_unsafe_access(!is_native_ptr, is_store, T_INT, false); 1.469 + case vmIntrinsics::_putLong: 1.470 + return inline_unsafe_access(!is_native_ptr, is_store, T_LONG, false); 1.471 + case vmIntrinsics::_putFloat: 1.472 + return inline_unsafe_access(!is_native_ptr, is_store, T_FLOAT, false); 1.473 + case vmIntrinsics::_putDouble: 1.474 + return inline_unsafe_access(!is_native_ptr, is_store, T_DOUBLE, false); 1.475 + 1.476 + case vmIntrinsics::_getByte_raw: 1.477 + return inline_unsafe_access(is_native_ptr, !is_store, T_BYTE, false); 1.478 + case vmIntrinsics::_getShort_raw: 1.479 + return inline_unsafe_access(is_native_ptr, !is_store, T_SHORT, false); 1.480 + case vmIntrinsics::_getChar_raw: 1.481 + return inline_unsafe_access(is_native_ptr, !is_store, T_CHAR, false); 1.482 + case vmIntrinsics::_getInt_raw: 1.483 + return inline_unsafe_access(is_native_ptr, !is_store, T_INT, false); 1.484 + case vmIntrinsics::_getLong_raw: 1.485 + return inline_unsafe_access(is_native_ptr, !is_store, T_LONG, false); 1.486 + case vmIntrinsics::_getFloat_raw: 1.487 + return inline_unsafe_access(is_native_ptr, !is_store, T_FLOAT, false); 1.488 + case vmIntrinsics::_getDouble_raw: 1.489 + return inline_unsafe_access(is_native_ptr, !is_store, T_DOUBLE, false); 1.490 + case vmIntrinsics::_getAddress_raw: 1.491 + return inline_unsafe_access(is_native_ptr, !is_store, T_ADDRESS, false); 1.492 + 1.493 + case vmIntrinsics::_putByte_raw: 1.494 + return inline_unsafe_access(is_native_ptr, is_store, T_BYTE, false); 1.495 + case vmIntrinsics::_putShort_raw: 1.496 + return inline_unsafe_access(is_native_ptr, is_store, T_SHORT, false); 1.497 + case vmIntrinsics::_putChar_raw: 1.498 + return inline_unsafe_access(is_native_ptr, is_store, T_CHAR, false); 1.499 + case vmIntrinsics::_putInt_raw: 1.500 + return inline_unsafe_access(is_native_ptr, is_store, T_INT, false); 1.501 + case vmIntrinsics::_putLong_raw: 1.502 + return inline_unsafe_access(is_native_ptr, is_store, T_LONG, false); 1.503 + case vmIntrinsics::_putFloat_raw: 1.504 + return inline_unsafe_access(is_native_ptr, is_store, T_FLOAT, false); 1.505 + case vmIntrinsics::_putDouble_raw: 1.506 + return inline_unsafe_access(is_native_ptr, is_store, T_DOUBLE, false); 1.507 + case vmIntrinsics::_putAddress_raw: 1.508 + return inline_unsafe_access(is_native_ptr, is_store, T_ADDRESS, false); 1.509 + 1.510 + case vmIntrinsics::_getObjectVolatile: 1.511 + return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT, true); 1.512 + case vmIntrinsics::_getBooleanVolatile: 1.513 + return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN, true); 1.514 + case vmIntrinsics::_getByteVolatile: 1.515 + return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE, true); 1.516 + case vmIntrinsics::_getShortVolatile: 1.517 + return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT, true); 1.518 + case vmIntrinsics::_getCharVolatile: 1.519 + return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR, true); 1.520 + case vmIntrinsics::_getIntVolatile: 1.521 + return inline_unsafe_access(!is_native_ptr, !is_store, T_INT, true); 1.522 + case vmIntrinsics::_getLongVolatile: 1.523 + return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG, true); 1.524 + case vmIntrinsics::_getFloatVolatile: 1.525 + return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT, true); 1.526 + case vmIntrinsics::_getDoubleVolatile: 1.527 + return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE, true); 1.528 + 1.529 + case vmIntrinsics::_putObjectVolatile: 1.530 + return inline_unsafe_access(!is_native_ptr, is_store, T_OBJECT, true); 1.531 + case vmIntrinsics::_putBooleanVolatile: 1.532 + return inline_unsafe_access(!is_native_ptr, is_store, T_BOOLEAN, true); 1.533 + case vmIntrinsics::_putByteVolatile: 1.534 + return inline_unsafe_access(!is_native_ptr, is_store, T_BYTE, true); 1.535 + case vmIntrinsics::_putShortVolatile: 1.536 + return inline_unsafe_access(!is_native_ptr, is_store, T_SHORT, true); 1.537 + case vmIntrinsics::_putCharVolatile: 1.538 + return inline_unsafe_access(!is_native_ptr, is_store, T_CHAR, true); 1.539 + case vmIntrinsics::_putIntVolatile: 1.540 + return inline_unsafe_access(!is_native_ptr, is_store, T_INT, true); 1.541 + case vmIntrinsics::_putLongVolatile: 1.542 + return inline_unsafe_access(!is_native_ptr, is_store, T_LONG, true); 1.543 + case vmIntrinsics::_putFloatVolatile: 1.544 + return inline_unsafe_access(!is_native_ptr, is_store, T_FLOAT, true); 1.545 + case vmIntrinsics::_putDoubleVolatile: 1.546 + return inline_unsafe_access(!is_native_ptr, is_store, T_DOUBLE, true); 1.547 + 1.548 + case vmIntrinsics::_prefetchRead: 1.549 + return inline_unsafe_prefetch(!is_native_ptr, !is_store, !is_static); 1.550 + case vmIntrinsics::_prefetchWrite: 1.551 + return inline_unsafe_prefetch(!is_native_ptr, is_store, !is_static); 1.552 + case vmIntrinsics::_prefetchReadStatic: 1.553 + return inline_unsafe_prefetch(!is_native_ptr, !is_store, is_static); 1.554 + case vmIntrinsics::_prefetchWriteStatic: 1.555 + return inline_unsafe_prefetch(!is_native_ptr, is_store, is_static); 1.556 + 1.557 + case vmIntrinsics::_compareAndSwapObject: 1.558 + return inline_unsafe_CAS(T_OBJECT); 1.559 + case vmIntrinsics::_compareAndSwapInt: 1.560 + return inline_unsafe_CAS(T_INT); 1.561 + case vmIntrinsics::_compareAndSwapLong: 1.562 + return inline_unsafe_CAS(T_LONG); 1.563 + 1.564 + case vmIntrinsics::_putOrderedObject: 1.565 + return inline_unsafe_ordered_store(T_OBJECT); 1.566 + case vmIntrinsics::_putOrderedInt: 1.567 + return inline_unsafe_ordered_store(T_INT); 1.568 + case vmIntrinsics::_putOrderedLong: 1.569 + return inline_unsafe_ordered_store(T_LONG); 1.570 + 1.571 + case vmIntrinsics::_currentThread: 1.572 + return inline_native_currentThread(); 1.573 + case vmIntrinsics::_isInterrupted: 1.574 + return inline_native_isInterrupted(); 1.575 + 1.576 + case vmIntrinsics::_currentTimeMillis: 1.577 + return inline_native_time_funcs(false); 1.578 + case vmIntrinsics::_nanoTime: 1.579 + return inline_native_time_funcs(true); 1.580 + case vmIntrinsics::_allocateInstance: 1.581 + return inline_unsafe_allocate(); 1.582 + case vmIntrinsics::_copyMemory: 1.583 + return inline_unsafe_copyMemory(); 1.584 + case vmIntrinsics::_newArray: 1.585 + return inline_native_newArray(); 1.586 + case vmIntrinsics::_getLength: 1.587 + return inline_native_getLength(); 1.588 + case vmIntrinsics::_copyOf: 1.589 + return inline_array_copyOf(false); 1.590 + case vmIntrinsics::_copyOfRange: 1.591 + return inline_array_copyOf(true); 1.592 + case vmIntrinsics::_clone: 1.593 + return inline_native_clone(intrinsic()->is_virtual()); 1.594 + 1.595 + case vmIntrinsics::_isAssignableFrom: 1.596 + return inline_native_subtype_check(); 1.597 + 1.598 + case vmIntrinsics::_isInstance: 1.599 + case vmIntrinsics::_getModifiers: 1.600 + case vmIntrinsics::_isInterface: 1.601 + case vmIntrinsics::_isArray: 1.602 + case vmIntrinsics::_isPrimitive: 1.603 + case vmIntrinsics::_getSuperclass: 1.604 + case vmIntrinsics::_getComponentType: 1.605 + case vmIntrinsics::_getClassAccessFlags: 1.606 + return inline_native_Class_query(intrinsic_id()); 1.607 + 1.608 + case vmIntrinsics::_floatToRawIntBits: 1.609 + case vmIntrinsics::_floatToIntBits: 1.610 + case vmIntrinsics::_intBitsToFloat: 1.611 + case vmIntrinsics::_doubleToRawLongBits: 1.612 + case vmIntrinsics::_doubleToLongBits: 1.613 + case vmIntrinsics::_longBitsToDouble: 1.614 + return inline_fp_conversions(intrinsic_id()); 1.615 + 1.616 + case vmIntrinsics::_reverseBytes_i: 1.617 + case vmIntrinsics::_reverseBytes_l: 1.618 + return inline_reverseBytes((vmIntrinsics::ID) intrinsic_id()); 1.619 + 1.620 + case vmIntrinsics::_get_AtomicLong: 1.621 + return inline_native_AtomicLong_get(); 1.622 + case vmIntrinsics::_attemptUpdate: 1.623 + return inline_native_AtomicLong_attemptUpdate(); 1.624 + 1.625 + case vmIntrinsics::_getCallerClass: 1.626 + return inline_native_Reflection_getCallerClass(); 1.627 + 1.628 + default: 1.629 + // If you get here, it may be that someone has added a new intrinsic 1.630 + // to the list in vmSymbols.hpp without implementing it here. 1.631 +#ifndef PRODUCT 1.632 + if ((PrintMiscellaneous && (Verbose || WizardMode)) || PrintOpto) { 1.633 + tty->print_cr("*** Warning: Unimplemented intrinsic %s(%d)", 1.634 + vmIntrinsics::name_at(intrinsic_id()), intrinsic_id()); 1.635 + } 1.636 +#endif 1.637 + return false; 1.638 + } 1.639 +} 1.640 + 1.641 +//------------------------------push_result------------------------------ 1.642 +// Helper function for finishing intrinsics. 1.643 +void LibraryCallKit::push_result(RegionNode* region, PhiNode* value) { 1.644 + record_for_igvn(region); 1.645 + set_control(_gvn.transform(region)); 1.646 + BasicType value_type = value->type()->basic_type(); 1.647 + push_node(value_type, _gvn.transform(value)); 1.648 +} 1.649 + 1.650 +//------------------------------generate_guard--------------------------- 1.651 +// Helper function for generating guarded fast-slow graph structures. 1.652 +// The given 'test', if true, guards a slow path. If the test fails 1.653 +// then a fast path can be taken. (We generally hope it fails.) 1.654 +// In all cases, GraphKit::control() is updated to the fast path. 1.655 +// The returned value represents the control for the slow path. 1.656 +// The return value is never 'top'; it is either a valid control 1.657 +// or NULL if it is obvious that the slow path can never be taken. 1.658 +// Also, if region and the slow control are not NULL, the slow edge 1.659 +// is appended to the region. 1.660 +Node* LibraryCallKit::generate_guard(Node* test, RegionNode* region, float true_prob) { 1.661 + if (stopped()) { 1.662 + // Already short circuited. 1.663 + return NULL; 1.664 + } 1.665 + 1.666 + // Build an if node and its projections. 1.667 + // If test is true we take the slow path, which we assume is uncommon. 1.668 + if (_gvn.type(test) == TypeInt::ZERO) { 1.669 + // The slow branch is never taken. No need to build this guard. 1.670 + return NULL; 1.671 + } 1.672 + 1.673 + IfNode* iff = create_and_map_if(control(), test, true_prob, COUNT_UNKNOWN); 1.674 + 1.675 + Node* if_slow = _gvn.transform( new (C, 1) IfTrueNode(iff) ); 1.676 + if (if_slow == top()) { 1.677 + // The slow branch is never taken. No need to build this guard. 1.678 + return NULL; 1.679 + } 1.680 + 1.681 + if (region != NULL) 1.682 + region->add_req(if_slow); 1.683 + 1.684 + Node* if_fast = _gvn.transform( new (C, 1) IfFalseNode(iff) ); 1.685 + set_control(if_fast); 1.686 + 1.687 + return if_slow; 1.688 +} 1.689 + 1.690 +inline Node* LibraryCallKit::generate_slow_guard(Node* test, RegionNode* region) { 1.691 + return generate_guard(test, region, PROB_UNLIKELY_MAG(3)); 1.692 +} 1.693 +inline Node* LibraryCallKit::generate_fair_guard(Node* test, RegionNode* region) { 1.694 + return generate_guard(test, region, PROB_FAIR); 1.695 +} 1.696 + 1.697 +inline Node* LibraryCallKit::generate_negative_guard(Node* index, RegionNode* region, 1.698 + Node* *pos_index) { 1.699 + if (stopped()) 1.700 + return NULL; // already stopped 1.701 + if (_gvn.type(index)->higher_equal(TypeInt::POS)) // [0,maxint] 1.702 + return NULL; // index is already adequately typed 1.703 + Node* cmp_lt = _gvn.transform( new (C, 3) CmpINode(index, intcon(0)) ); 1.704 + Node* bol_lt = _gvn.transform( new (C, 2) BoolNode(cmp_lt, BoolTest::lt) ); 1.705 + Node* is_neg = generate_guard(bol_lt, region, PROB_MIN); 1.706 + if (is_neg != NULL && pos_index != NULL) { 1.707 + // Emulate effect of Parse::adjust_map_after_if. 1.708 + Node* ccast = new (C, 2) CastIINode(index, TypeInt::POS); 1.709 + ccast->set_req(0, control()); 1.710 + (*pos_index) = _gvn.transform(ccast); 1.711 + } 1.712 + return is_neg; 1.713 +} 1.714 + 1.715 +inline Node* LibraryCallKit::generate_nonpositive_guard(Node* index, bool never_negative, 1.716 + Node* *pos_index) { 1.717 + if (stopped()) 1.718 + return NULL; // already stopped 1.719 + if (_gvn.type(index)->higher_equal(TypeInt::POS1)) // [1,maxint] 1.720 + return NULL; // index is already adequately typed 1.721 + Node* cmp_le = _gvn.transform( new (C, 3) CmpINode(index, intcon(0)) ); 1.722 + BoolTest::mask le_or_eq = (never_negative ? BoolTest::eq : BoolTest::le); 1.723 + Node* bol_le = _gvn.transform( new (C, 2) BoolNode(cmp_le, le_or_eq) ); 1.724 + Node* is_notp = generate_guard(bol_le, NULL, PROB_MIN); 1.725 + if (is_notp != NULL && pos_index != NULL) { 1.726 + // Emulate effect of Parse::adjust_map_after_if. 1.727 + Node* ccast = new (C, 2) CastIINode(index, TypeInt::POS1); 1.728 + ccast->set_req(0, control()); 1.729 + (*pos_index) = _gvn.transform(ccast); 1.730 + } 1.731 + return is_notp; 1.732 +} 1.733 + 1.734 +// Make sure that 'position' is a valid limit index, in [0..length]. 1.735 +// There are two equivalent plans for checking this: 1.736 +// A. (offset + copyLength) unsigned<= arrayLength 1.737 +// B. offset <= (arrayLength - copyLength) 1.738 +// We require that all of the values above, except for the sum and 1.739 +// difference, are already known to be non-negative. 1.740 +// Plan A is robust in the face of overflow, if offset and copyLength 1.741 +// are both hugely positive. 1.742 +// 1.743 +// Plan B is less direct and intuitive, but it does not overflow at 1.744 +// all, since the difference of two non-negatives is always 1.745 +// representable. Whenever Java methods must perform the equivalent 1.746 +// check they generally use Plan B instead of Plan A. 1.747 +// For the moment we use Plan A. 1.748 +inline Node* LibraryCallKit::generate_limit_guard(Node* offset, 1.749 + Node* subseq_length, 1.750 + Node* array_length, 1.751 + RegionNode* region) { 1.752 + if (stopped()) 1.753 + return NULL; // already stopped 1.754 + bool zero_offset = _gvn.type(offset) == TypeInt::ZERO; 1.755 + if (zero_offset && _gvn.eqv_uncast(subseq_length, array_length)) 1.756 + return NULL; // common case of whole-array copy 1.757 + Node* last = subseq_length; 1.758 + if (!zero_offset) // last += offset 1.759 + last = _gvn.transform( new (C, 3) AddINode(last, offset)); 1.760 + Node* cmp_lt = _gvn.transform( new (C, 3) CmpUNode(array_length, last) ); 1.761 + Node* bol_lt = _gvn.transform( new (C, 2) BoolNode(cmp_lt, BoolTest::lt) ); 1.762 + Node* is_over = generate_guard(bol_lt, region, PROB_MIN); 1.763 + return is_over; 1.764 +} 1.765 + 1.766 + 1.767 +//--------------------------generate_current_thread-------------------- 1.768 +Node* LibraryCallKit::generate_current_thread(Node* &tls_output) { 1.769 + ciKlass* thread_klass = env()->Thread_klass(); 1.770 + const Type* thread_type = TypeOopPtr::make_from_klass(thread_klass)->cast_to_ptr_type(TypePtr::NotNull); 1.771 + Node* thread = _gvn.transform(new (C, 1) ThreadLocalNode()); 1.772 + Node* p = basic_plus_adr(top()/*!oop*/, thread, in_bytes(JavaThread::threadObj_offset())); 1.773 + Node* threadObj = make_load(NULL, p, thread_type, T_OBJECT); 1.774 + tls_output = thread; 1.775 + return threadObj; 1.776 +} 1.777 + 1.778 + 1.779 +//------------------------------inline_string_compareTo------------------------ 1.780 +bool LibraryCallKit::inline_string_compareTo() { 1.781 + 1.782 + const int value_offset = java_lang_String::value_offset_in_bytes(); 1.783 + const int count_offset = java_lang_String::count_offset_in_bytes(); 1.784 + const int offset_offset = java_lang_String::offset_offset_in_bytes(); 1.785 + 1.786 + _sp += 2; 1.787 + Node *argument = pop(); // pop non-receiver first: it was pushed second 1.788 + Node *receiver = pop(); 1.789 + 1.790 + // Null check on self without removing any arguments. The argument 1.791 + // null check technically happens in the wrong place, which can lead to 1.792 + // invalid stack traces when string compare is inlined into a method 1.793 + // which handles NullPointerExceptions. 1.794 + _sp += 2; 1.795 + receiver = do_null_check(receiver, T_OBJECT); 1.796 + argument = do_null_check(argument, T_OBJECT); 1.797 + _sp -= 2; 1.798 + if (stopped()) { 1.799 + return true; 1.800 + } 1.801 + 1.802 + ciInstanceKlass* klass = env()->String_klass(); 1.803 + const TypeInstPtr* string_type = 1.804 + TypeInstPtr::make(TypePtr::BotPTR, klass, false, NULL, 0); 1.805 + 1.806 + Node* compare = 1.807 + _gvn.transform(new (C, 7) StrCompNode( 1.808 + control(), 1.809 + memory(TypeAryPtr::CHARS), 1.810 + memory(string_type->add_offset(value_offset)), 1.811 + memory(string_type->add_offset(count_offset)), 1.812 + memory(string_type->add_offset(offset_offset)), 1.813 + receiver, 1.814 + argument)); 1.815 + push(compare); 1.816 + return true; 1.817 +} 1.818 + 1.819 +// Java version of String.indexOf(constant string) 1.820 +// class StringDecl { 1.821 +// StringDecl(char[] ca) { 1.822 +// offset = 0; 1.823 +// count = ca.length; 1.824 +// value = ca; 1.825 +// } 1.826 +// int offset; 1.827 +// int count; 1.828 +// char[] value; 1.829 +// } 1.830 +// 1.831 +// static int string_indexOf_J(StringDecl string_object, char[] target_object, 1.832 +// int targetOffset, int cache_i, int md2) { 1.833 +// int cache = cache_i; 1.834 +// int sourceOffset = string_object.offset; 1.835 +// int sourceCount = string_object.count; 1.836 +// int targetCount = target_object.length; 1.837 +// 1.838 +// int targetCountLess1 = targetCount - 1; 1.839 +// int sourceEnd = sourceOffset + sourceCount - targetCountLess1; 1.840 +// 1.841 +// char[] source = string_object.value; 1.842 +// char[] target = target_object; 1.843 +// int lastChar = target[targetCountLess1]; 1.844 +// 1.845 +// outer_loop: 1.846 +// for (int i = sourceOffset; i < sourceEnd; ) { 1.847 +// int src = source[i + targetCountLess1]; 1.848 +// if (src == lastChar) { 1.849 +// // With random strings and a 4-character alphabet, 1.850 +// // reverse matching at this point sets up 0.8% fewer 1.851 +// // frames, but (paradoxically) makes 0.3% more probes. 1.852 +// // Since those probes are nearer the lastChar probe, 1.853 +// // there is may be a net D$ win with reverse matching. 1.854 +// // But, reversing loop inhibits unroll of inner loop 1.855 +// // for unknown reason. So, does running outer loop from 1.856 +// // (sourceOffset - targetCountLess1) to (sourceOffset + sourceCount) 1.857 +// for (int j = 0; j < targetCountLess1; j++) { 1.858 +// if (target[targetOffset + j] != source[i+j]) { 1.859 +// if ((cache & (1 << source[i+j])) == 0) { 1.860 +// if (md2 < j+1) { 1.861 +// i += j+1; 1.862 +// continue outer_loop; 1.863 +// } 1.864 +// } 1.865 +// i += md2; 1.866 +// continue outer_loop; 1.867 +// } 1.868 +// } 1.869 +// return i - sourceOffset; 1.870 +// } 1.871 +// if ((cache & (1 << src)) == 0) { 1.872 +// i += targetCountLess1; 1.873 +// } // using "i += targetCount;" and an "else i++;" causes a jump to jump. 1.874 +// i++; 1.875 +// } 1.876 +// return -1; 1.877 +// } 1.878 + 1.879 +//------------------------------string_indexOf------------------------ 1.880 +Node* LibraryCallKit::string_indexOf(Node* string_object, ciTypeArray* target_array, jint targetOffset_i, 1.881 + jint cache_i, jint md2_i) { 1.882 + 1.883 + Node* no_ctrl = NULL; 1.884 + float likely = PROB_LIKELY(0.9); 1.885 + float unlikely = PROB_UNLIKELY(0.9); 1.886 + 1.887 + const int value_offset = java_lang_String::value_offset_in_bytes(); 1.888 + const int count_offset = java_lang_String::count_offset_in_bytes(); 1.889 + const int offset_offset = java_lang_String::offset_offset_in_bytes(); 1.890 + 1.891 + ciInstanceKlass* klass = env()->String_klass(); 1.892 + const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::BotPTR, klass, false, NULL, 0); 1.893 + const TypeAryPtr* source_type = TypeAryPtr::make(TypePtr::NotNull, TypeAry::make(TypeInt::CHAR,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, 0); 1.894 + 1.895 + Node* sourceOffseta = basic_plus_adr(string_object, string_object, offset_offset); 1.896 + Node* sourceOffset = make_load(no_ctrl, sourceOffseta, TypeInt::INT, T_INT, string_type->add_offset(offset_offset)); 1.897 + Node* sourceCounta = basic_plus_adr(string_object, string_object, count_offset); 1.898 + Node* sourceCount = make_load(no_ctrl, sourceCounta, TypeInt::INT, T_INT, string_type->add_offset(count_offset)); 1.899 + Node* sourcea = basic_plus_adr(string_object, string_object, value_offset); 1.900 + Node* source = make_load(no_ctrl, sourcea, source_type, T_OBJECT, string_type->add_offset(value_offset)); 1.901 + 1.902 + Node* target = _gvn.transform(ConPNode::make(C, target_array)); 1.903 + jint target_length = target_array->length(); 1.904 + const TypeAry* target_array_type = TypeAry::make(TypeInt::CHAR, TypeInt::make(0, target_length, Type::WidenMin)); 1.905 + const TypeAryPtr* target_type = TypeAryPtr::make(TypePtr::BotPTR, target_array_type, target_array->klass(), true, Type::OffsetBot); 1.906 + 1.907 + IdealKit kit(gvn(), control(), merged_memory()); 1.908 +#define __ kit. 1.909 + Node* zero = __ ConI(0); 1.910 + Node* one = __ ConI(1); 1.911 + Node* cache = __ ConI(cache_i); 1.912 + Node* md2 = __ ConI(md2_i); 1.913 + Node* lastChar = __ ConI(target_array->char_at(target_length - 1)); 1.914 + Node* targetCount = __ ConI(target_length); 1.915 + Node* targetCountLess1 = __ ConI(target_length - 1); 1.916 + Node* targetOffset = __ ConI(targetOffset_i); 1.917 + Node* sourceEnd = __ SubI(__ AddI(sourceOffset, sourceCount), targetCountLess1); 1.918 + 1.919 + IdealVariable rtn(kit), i(kit), j(kit); __ declares_done(); 1.920 + Node* outer_loop = __ make_label(2 /* goto */); 1.921 + Node* return_ = __ make_label(1); 1.922 + 1.923 + __ set(rtn,__ ConI(-1)); 1.924 + __ loop(i, sourceOffset, BoolTest::lt, sourceEnd); { 1.925 + Node* i2 = __ AddI(__ value(i), targetCountLess1); 1.926 + // pin to prohibit loading of "next iteration" value which may SEGV (rare) 1.927 + Node* src = load_array_element(__ ctrl(), source, i2, TypeAryPtr::CHARS); 1.928 + __ if_then(src, BoolTest::eq, lastChar, unlikely); { 1.929 + __ loop(j, zero, BoolTest::lt, targetCountLess1); { 1.930 + Node* tpj = __ AddI(targetOffset, __ value(j)); 1.931 + Node* targ = load_array_element(no_ctrl, target, tpj, target_type); 1.932 + Node* ipj = __ AddI(__ value(i), __ value(j)); 1.933 + Node* src2 = load_array_element(no_ctrl, source, ipj, TypeAryPtr::CHARS); 1.934 + __ if_then(targ, BoolTest::ne, src2); { 1.935 + __ if_then(__ AndI(cache, __ LShiftI(one, src2)), BoolTest::eq, zero); { 1.936 + __ if_then(md2, BoolTest::lt, __ AddI(__ value(j), one)); { 1.937 + __ increment(i, __ AddI(__ value(j), one)); 1.938 + __ goto_(outer_loop); 1.939 + } __ end_if(); __ dead(j); 1.940 + }__ end_if(); __ dead(j); 1.941 + __ increment(i, md2); 1.942 + __ goto_(outer_loop); 1.943 + }__ end_if(); 1.944 + __ increment(j, one); 1.945 + }__ end_loop(); __ dead(j); 1.946 + __ set(rtn, __ SubI(__ value(i), sourceOffset)); __ dead(i); 1.947 + __ goto_(return_); 1.948 + }__ end_if(); 1.949 + __ if_then(__ AndI(cache, __ LShiftI(one, src)), BoolTest::eq, zero, likely); { 1.950 + __ increment(i, targetCountLess1); 1.951 + }__ end_if(); 1.952 + __ increment(i, one); 1.953 + __ bind(outer_loop); 1.954 + }__ end_loop(); __ dead(i); 1.955 + __ bind(return_); 1.956 + __ drain_delay_transform(); 1.957 + 1.958 + set_control(__ ctrl()); 1.959 + Node* result = __ value(rtn); 1.960 +#undef __ 1.961 + C->set_has_loops(true); 1.962 + return result; 1.963 +} 1.964 + 1.965 + 1.966 +//------------------------------inline_string_indexOf------------------------ 1.967 +bool LibraryCallKit::inline_string_indexOf() { 1.968 + 1.969 + _sp += 2; 1.970 + Node *argument = pop(); // pop non-receiver first: it was pushed second 1.971 + Node *receiver = pop(); 1.972 + 1.973 + // don't intrinsify is argument isn't a constant string. 1.974 + if (!argument->is_Con()) { 1.975 + return false; 1.976 + } 1.977 + const TypeOopPtr* str_type = _gvn.type(argument)->isa_oopptr(); 1.978 + if (str_type == NULL) { 1.979 + return false; 1.980 + } 1.981 + ciInstanceKlass* klass = env()->String_klass(); 1.982 + ciObject* str_const = str_type->const_oop(); 1.983 + if (str_const == NULL || str_const->klass() != klass) { 1.984 + return false; 1.985 + } 1.986 + ciInstance* str = str_const->as_instance(); 1.987 + assert(str != NULL, "must be instance"); 1.988 + 1.989 + const int value_offset = java_lang_String::value_offset_in_bytes(); 1.990 + const int count_offset = java_lang_String::count_offset_in_bytes(); 1.991 + const int offset_offset = java_lang_String::offset_offset_in_bytes(); 1.992 + 1.993 + ciObject* v = str->field_value_by_offset(value_offset).as_object(); 1.994 + int o = str->field_value_by_offset(offset_offset).as_int(); 1.995 + int c = str->field_value_by_offset(count_offset).as_int(); 1.996 + ciTypeArray* pat = v->as_type_array(); // pattern (argument) character array 1.997 + 1.998 + // constant strings have no offset and count == length which 1.999 + // simplifies the resulting code somewhat so lets optimize for that. 1.1000 + if (o != 0 || c != pat->length()) { 1.1001 + return false; 1.1002 + } 1.1003 + 1.1004 + // Null check on self without removing any arguments. The argument 1.1005 + // null check technically happens in the wrong place, which can lead to 1.1006 + // invalid stack traces when string compare is inlined into a method 1.1007 + // which handles NullPointerExceptions. 1.1008 + _sp += 2; 1.1009 + receiver = do_null_check(receiver, T_OBJECT); 1.1010 + // No null check on the argument is needed since it's a constant String oop. 1.1011 + _sp -= 2; 1.1012 + if (stopped()) { 1.1013 + return true; 1.1014 + } 1.1015 + 1.1016 + // The null string as a pattern always returns 0 (match at beginning of string) 1.1017 + if (c == 0) { 1.1018 + push(intcon(0)); 1.1019 + return true; 1.1020 + } 1.1021 + 1.1022 + jchar lastChar = pat->char_at(o + (c - 1)); 1.1023 + int cache = 0; 1.1024 + int i; 1.1025 + for (i = 0; i < c - 1; i++) { 1.1026 + assert(i < pat->length(), "out of range"); 1.1027 + cache |= (1 << (pat->char_at(o + i) & (sizeof(cache) * BitsPerByte - 1))); 1.1028 + } 1.1029 + 1.1030 + int md2 = c; 1.1031 + for (i = 0; i < c - 1; i++) { 1.1032 + assert(i < pat->length(), "out of range"); 1.1033 + if (pat->char_at(o + i) == lastChar) { 1.1034 + md2 = (c - 1) - i; 1.1035 + } 1.1036 + } 1.1037 + 1.1038 + Node* result = string_indexOf(receiver, pat, o, cache, md2); 1.1039 + push(result); 1.1040 + return true; 1.1041 +} 1.1042 + 1.1043 +//--------------------------pop_math_arg-------------------------------- 1.1044 +// Pop a double argument to a math function from the stack 1.1045 +// rounding it if necessary. 1.1046 +Node * LibraryCallKit::pop_math_arg() { 1.1047 + Node *arg = pop_pair(); 1.1048 + if( Matcher::strict_fp_requires_explicit_rounding && UseSSE<=1 ) 1.1049 + arg = _gvn.transform( new (C, 2) RoundDoubleNode(0, arg) ); 1.1050 + return arg; 1.1051 +} 1.1052 + 1.1053 +//------------------------------inline_trig---------------------------------- 1.1054 +// Inline sin/cos/tan instructions, if possible. If rounding is required, do 1.1055 +// argument reduction which will turn into a fast/slow diamond. 1.1056 +bool LibraryCallKit::inline_trig(vmIntrinsics::ID id) { 1.1057 + _sp += arg_size(); // restore stack pointer 1.1058 + Node* arg = pop_math_arg(); 1.1059 + Node* trig = NULL; 1.1060 + 1.1061 + switch (id) { 1.1062 + case vmIntrinsics::_dsin: 1.1063 + trig = _gvn.transform((Node*)new (C, 2) SinDNode(arg)); 1.1064 + break; 1.1065 + case vmIntrinsics::_dcos: 1.1066 + trig = _gvn.transform((Node*)new (C, 2) CosDNode(arg)); 1.1067 + break; 1.1068 + case vmIntrinsics::_dtan: 1.1069 + trig = _gvn.transform((Node*)new (C, 2) TanDNode(arg)); 1.1070 + break; 1.1071 + default: 1.1072 + assert(false, "bad intrinsic was passed in"); 1.1073 + return false; 1.1074 + } 1.1075 + 1.1076 + // Rounding required? Check for argument reduction! 1.1077 + if( Matcher::strict_fp_requires_explicit_rounding ) { 1.1078 + 1.1079 + static const double pi_4 = 0.7853981633974483; 1.1080 + static const double neg_pi_4 = -0.7853981633974483; 1.1081 + // pi/2 in 80-bit extended precision 1.1082 + // 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.1083 + // -pi/2 in 80-bit extended precision 1.1084 + // 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.1085 + // Cutoff value for using this argument reduction technique 1.1086 + //static const double pi_2_minus_epsilon = 1.564660403643354; 1.1087 + //static const double neg_pi_2_plus_epsilon = -1.564660403643354; 1.1088 + 1.1089 + // Pseudocode for sin: 1.1090 + // if (x <= Math.PI / 4.0) { 1.1091 + // if (x >= -Math.PI / 4.0) return fsin(x); 1.1092 + // if (x >= -Math.PI / 2.0) return -fcos(x + Math.PI / 2.0); 1.1093 + // } else { 1.1094 + // if (x <= Math.PI / 2.0) return fcos(x - Math.PI / 2.0); 1.1095 + // } 1.1096 + // return StrictMath.sin(x); 1.1097 + 1.1098 + // Pseudocode for cos: 1.1099 + // if (x <= Math.PI / 4.0) { 1.1100 + // if (x >= -Math.PI / 4.0) return fcos(x); 1.1101 + // if (x >= -Math.PI / 2.0) return fsin(x + Math.PI / 2.0); 1.1102 + // } else { 1.1103 + // if (x <= Math.PI / 2.0) return -fsin(x - Math.PI / 2.0); 1.1104 + // } 1.1105 + // return StrictMath.cos(x); 1.1106 + 1.1107 + // Actually, sticking in an 80-bit Intel value into C2 will be tough; it 1.1108 + // requires a special machine instruction to load it. Instead we'll try 1.1109 + // the 'easy' case. If we really need the extra range +/- PI/2 we'll 1.1110 + // probably do the math inside the SIN encoding. 1.1111 + 1.1112 + // Make the merge point 1.1113 + RegionNode *r = new (C, 3) RegionNode(3); 1.1114 + Node *phi = new (C, 3) PhiNode(r,Type::DOUBLE); 1.1115 + 1.1116 + // Flatten arg so we need only 1 test 1.1117 + Node *abs = _gvn.transform(new (C, 2) AbsDNode(arg)); 1.1118 + // Node for PI/4 constant 1.1119 + Node *pi4 = makecon(TypeD::make(pi_4)); 1.1120 + // Check PI/4 : abs(arg) 1.1121 + Node *cmp = _gvn.transform(new (C, 3) CmpDNode(pi4,abs)); 1.1122 + // Check: If PI/4 < abs(arg) then go slow 1.1123 + Node *bol = _gvn.transform( new (C, 2) BoolNode( cmp, BoolTest::lt ) ); 1.1124 + // Branch either way 1.1125 + IfNode *iff = create_and_xform_if(control(),bol, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 1.1126 + set_control(opt_iff(r,iff)); 1.1127 + 1.1128 + // Set fast path result 1.1129 + phi->init_req(2,trig); 1.1130 + 1.1131 + // Slow path - non-blocking leaf call 1.1132 + Node* call = NULL; 1.1133 + switch (id) { 1.1134 + case vmIntrinsics::_dsin: 1.1135 + call = make_runtime_call(RC_LEAF, OptoRuntime::Math_D_D_Type(), 1.1136 + CAST_FROM_FN_PTR(address, SharedRuntime::dsin), 1.1137 + "Sin", NULL, arg, top()); 1.1138 + break; 1.1139 + case vmIntrinsics::_dcos: 1.1140 + call = make_runtime_call(RC_LEAF, OptoRuntime::Math_D_D_Type(), 1.1141 + CAST_FROM_FN_PTR(address, SharedRuntime::dcos), 1.1142 + "Cos", NULL, arg, top()); 1.1143 + break; 1.1144 + case vmIntrinsics::_dtan: 1.1145 + call = make_runtime_call(RC_LEAF, OptoRuntime::Math_D_D_Type(), 1.1146 + CAST_FROM_FN_PTR(address, SharedRuntime::dtan), 1.1147 + "Tan", NULL, arg, top()); 1.1148 + break; 1.1149 + } 1.1150 + assert(control()->in(0) == call, ""); 1.1151 + Node* slow_result = _gvn.transform(new (C, 1) ProjNode(call,TypeFunc::Parms)); 1.1152 + r->init_req(1,control()); 1.1153 + phi->init_req(1,slow_result); 1.1154 + 1.1155 + // Post-merge 1.1156 + set_control(_gvn.transform(r)); 1.1157 + record_for_igvn(r); 1.1158 + trig = _gvn.transform(phi); 1.1159 + 1.1160 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.1161 + } 1.1162 + // Push result back on JVM stack 1.1163 + push_pair(trig); 1.1164 + return true; 1.1165 +} 1.1166 + 1.1167 +//------------------------------inline_sqrt------------------------------------- 1.1168 +// Inline square root instruction, if possible. 1.1169 +bool LibraryCallKit::inline_sqrt(vmIntrinsics::ID id) { 1.1170 + assert(id == vmIntrinsics::_dsqrt, "Not square root"); 1.1171 + _sp += arg_size(); // restore stack pointer 1.1172 + push_pair(_gvn.transform(new (C, 2) SqrtDNode(0, pop_math_arg()))); 1.1173 + return true; 1.1174 +} 1.1175 + 1.1176 +//------------------------------inline_abs------------------------------------- 1.1177 +// Inline absolute value instruction, if possible. 1.1178 +bool LibraryCallKit::inline_abs(vmIntrinsics::ID id) { 1.1179 + assert(id == vmIntrinsics::_dabs, "Not absolute value"); 1.1180 + _sp += arg_size(); // restore stack pointer 1.1181 + push_pair(_gvn.transform(new (C, 2) AbsDNode(pop_math_arg()))); 1.1182 + return true; 1.1183 +} 1.1184 + 1.1185 +//------------------------------inline_exp------------------------------------- 1.1186 +// Inline exp instructions, if possible. The Intel hardware only misses 1.1187 +// really odd corner cases (+/- Infinity). Just uncommon-trap them. 1.1188 +bool LibraryCallKit::inline_exp(vmIntrinsics::ID id) { 1.1189 + assert(id == vmIntrinsics::_dexp, "Not exp"); 1.1190 + 1.1191 + // If this inlining ever returned NaN in the past, we do not intrinsify it 1.1192 + // every again. NaN results requires StrictMath.exp handling. 1.1193 + if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 1.1194 + 1.1195 + // Do not intrinsify on older platforms which lack cmove. 1.1196 + if (ConditionalMoveLimit == 0) return false; 1.1197 + 1.1198 + _sp += arg_size(); // restore stack pointer 1.1199 + Node *x = pop_math_arg(); 1.1200 + Node *result = _gvn.transform(new (C, 2) ExpDNode(0,x)); 1.1201 + 1.1202 + //------------------- 1.1203 + //result=(result.isNaN())? StrictMath::exp():result; 1.1204 + // Check: If isNaN() by checking result!=result? then go to Strict Math 1.1205 + Node* cmpisnan = _gvn.transform(new (C, 3) CmpDNode(result,result)); 1.1206 + // Build the boolean node 1.1207 + Node* bolisnum = _gvn.transform( new (C, 2) BoolNode(cmpisnan, BoolTest::eq) ); 1.1208 + 1.1209 + { BuildCutout unless(this, bolisnum, PROB_STATIC_FREQUENT); 1.1210 + // End the current control-flow path 1.1211 + push_pair(x); 1.1212 + // Math.exp intrinsic returned a NaN, which requires StrictMath.exp 1.1213 + // to handle. Recompile without intrinsifying Math.exp 1.1214 + uncommon_trap(Deoptimization::Reason_intrinsic, 1.1215 + Deoptimization::Action_make_not_entrant); 1.1216 + } 1.1217 + 1.1218 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.1219 + 1.1220 + push_pair(result); 1.1221 + 1.1222 + return true; 1.1223 +} 1.1224 + 1.1225 +//------------------------------inline_pow------------------------------------- 1.1226 +// Inline power instructions, if possible. 1.1227 +bool LibraryCallKit::inline_pow(vmIntrinsics::ID id) { 1.1228 + assert(id == vmIntrinsics::_dpow, "Not pow"); 1.1229 + 1.1230 + // If this inlining ever returned NaN in the past, we do not intrinsify it 1.1231 + // every again. NaN results requires StrictMath.pow handling. 1.1232 + if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 1.1233 + 1.1234 + // Do not intrinsify on older platforms which lack cmove. 1.1235 + if (ConditionalMoveLimit == 0) return false; 1.1236 + 1.1237 + // Pseudocode for pow 1.1238 + // if (x <= 0.0) { 1.1239 + // if ((double)((int)y)==y) { // if y is int 1.1240 + // result = ((1&(int)y)==0)?-DPow(abs(x), y):DPow(abs(x), y) 1.1241 + // } else { 1.1242 + // result = NaN; 1.1243 + // } 1.1244 + // } else { 1.1245 + // result = DPow(x,y); 1.1246 + // } 1.1247 + // if (result != result)? { 1.1248 + // ucommon_trap(); 1.1249 + // } 1.1250 + // return result; 1.1251 + 1.1252 + _sp += arg_size(); // restore stack pointer 1.1253 + Node* y = pop_math_arg(); 1.1254 + Node* x = pop_math_arg(); 1.1255 + 1.1256 + Node *fast_result = _gvn.transform( new (C, 3) PowDNode(0, x, y) ); 1.1257 + 1.1258 + // Short form: if not top-level (i.e., Math.pow but inlining Math.pow 1.1259 + // inside of something) then skip the fancy tests and just check for 1.1260 + // NaN result. 1.1261 + Node *result = NULL; 1.1262 + if( jvms()->depth() >= 1 ) { 1.1263 + result = fast_result; 1.1264 + } else { 1.1265 + 1.1266 + // Set the merge point for If node with condition of (x <= 0.0) 1.1267 + // There are four possible paths to region node and phi node 1.1268 + RegionNode *r = new (C, 4) RegionNode(4); 1.1269 + Node *phi = new (C, 4) PhiNode(r, Type::DOUBLE); 1.1270 + 1.1271 + // Build the first if node: if (x <= 0.0) 1.1272 + // Node for 0 constant 1.1273 + Node *zeronode = makecon(TypeD::ZERO); 1.1274 + // Check x:0 1.1275 + Node *cmp = _gvn.transform(new (C, 3) CmpDNode(x, zeronode)); 1.1276 + // Check: If (x<=0) then go complex path 1.1277 + Node *bol1 = _gvn.transform( new (C, 2) BoolNode( cmp, BoolTest::le ) ); 1.1278 + // Branch either way 1.1279 + IfNode *if1 = create_and_xform_if(control(),bol1, PROB_STATIC_INFREQUENT, COUNT_UNKNOWN); 1.1280 + Node *opt_test = _gvn.transform(if1); 1.1281 + //assert( opt_test->is_If(), "Expect an IfNode"); 1.1282 + IfNode *opt_if1 = (IfNode*)opt_test; 1.1283 + // Fast path taken; set region slot 3 1.1284 + Node *fast_taken = _gvn.transform( new (C, 1) IfFalseNode(opt_if1) ); 1.1285 + r->init_req(3,fast_taken); // Capture fast-control 1.1286 + 1.1287 + // Fast path not-taken, i.e. slow path 1.1288 + Node *complex_path = _gvn.transform( new (C, 1) IfTrueNode(opt_if1) ); 1.1289 + 1.1290 + // Set fast path result 1.1291 + Node *fast_result = _gvn.transform( new (C, 3) PowDNode(0, y, x) ); 1.1292 + phi->init_req(3, fast_result); 1.1293 + 1.1294 + // Complex path 1.1295 + // Build the second if node (if y is int) 1.1296 + // Node for (int)y 1.1297 + Node *inty = _gvn.transform( new (C, 2) ConvD2INode(y)); 1.1298 + // Node for (double)((int) y) 1.1299 + Node *doubleinty= _gvn.transform( new (C, 2) ConvI2DNode(inty)); 1.1300 + // Check (double)((int) y) : y 1.1301 + Node *cmpinty= _gvn.transform(new (C, 3) CmpDNode(doubleinty, y)); 1.1302 + // Check if (y isn't int) then go to slow path 1.1303 + 1.1304 + Node *bol2 = _gvn.transform( new (C, 2) BoolNode( cmpinty, BoolTest::ne ) ); 1.1305 + // Branch eith way 1.1306 + IfNode *if2 = create_and_xform_if(complex_path,bol2, PROB_STATIC_INFREQUENT, COUNT_UNKNOWN); 1.1307 + Node *slow_path = opt_iff(r,if2); // Set region path 2 1.1308 + 1.1309 + // Calculate DPow(abs(x), y)*(1 & (int)y) 1.1310 + // Node for constant 1 1.1311 + Node *conone = intcon(1); 1.1312 + // 1& (int)y 1.1313 + Node *signnode= _gvn.transform( new (C, 3) AndINode(conone, inty) ); 1.1314 + // zero node 1.1315 + Node *conzero = intcon(0); 1.1316 + // Check (1&(int)y)==0? 1.1317 + Node *cmpeq1 = _gvn.transform(new (C, 3) CmpINode(signnode, conzero)); 1.1318 + // Check if (1&(int)y)!=0?, if so the result is negative 1.1319 + Node *bol3 = _gvn.transform( new (C, 2) BoolNode( cmpeq1, BoolTest::ne ) ); 1.1320 + // abs(x) 1.1321 + Node *absx=_gvn.transform( new (C, 2) AbsDNode(x)); 1.1322 + // abs(x)^y 1.1323 + Node *absxpowy = _gvn.transform( new (C, 3) PowDNode(0, y, absx) ); 1.1324 + // -abs(x)^y 1.1325 + Node *negabsxpowy = _gvn.transform(new (C, 2) NegDNode (absxpowy)); 1.1326 + // (1&(int)y)==1?-DPow(abs(x), y):DPow(abs(x), y) 1.1327 + Node *signresult = _gvn.transform( CMoveNode::make(C, NULL, bol3, absxpowy, negabsxpowy, Type::DOUBLE)); 1.1328 + // Set complex path fast result 1.1329 + phi->init_req(2, signresult); 1.1330 + 1.1331 + static const jlong nan_bits = CONST64(0x7ff8000000000000); 1.1332 + Node *slow_result = makecon(TypeD::make(*(double*)&nan_bits)); // return NaN 1.1333 + r->init_req(1,slow_path); 1.1334 + phi->init_req(1,slow_result); 1.1335 + 1.1336 + // Post merge 1.1337 + set_control(_gvn.transform(r)); 1.1338 + record_for_igvn(r); 1.1339 + result=_gvn.transform(phi); 1.1340 + } 1.1341 + 1.1342 + //------------------- 1.1343 + //result=(result.isNaN())? uncommon_trap():result; 1.1344 + // Check: If isNaN() by checking result!=result? then go to Strict Math 1.1345 + Node* cmpisnan = _gvn.transform(new (C, 3) CmpDNode(result,result)); 1.1346 + // Build the boolean node 1.1347 + Node* bolisnum = _gvn.transform( new (C, 2) BoolNode(cmpisnan, BoolTest::eq) ); 1.1348 + 1.1349 + { BuildCutout unless(this, bolisnum, PROB_STATIC_FREQUENT); 1.1350 + // End the current control-flow path 1.1351 + push_pair(x); 1.1352 + push_pair(y); 1.1353 + // Math.pow intrinsic returned a NaN, which requires StrictMath.pow 1.1354 + // to handle. Recompile without intrinsifying Math.pow. 1.1355 + uncommon_trap(Deoptimization::Reason_intrinsic, 1.1356 + Deoptimization::Action_make_not_entrant); 1.1357 + } 1.1358 + 1.1359 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.1360 + 1.1361 + push_pair(result); 1.1362 + 1.1363 + return true; 1.1364 +} 1.1365 + 1.1366 +//------------------------------inline_trans------------------------------------- 1.1367 +// Inline transcendental instructions, if possible. The Intel hardware gets 1.1368 +// these right, no funny corner cases missed. 1.1369 +bool LibraryCallKit::inline_trans(vmIntrinsics::ID id) { 1.1370 + _sp += arg_size(); // restore stack pointer 1.1371 + Node* arg = pop_math_arg(); 1.1372 + Node* trans = NULL; 1.1373 + 1.1374 + switch (id) { 1.1375 + case vmIntrinsics::_dlog: 1.1376 + trans = _gvn.transform((Node*)new (C, 2) LogDNode(arg)); 1.1377 + break; 1.1378 + case vmIntrinsics::_dlog10: 1.1379 + trans = _gvn.transform((Node*)new (C, 2) Log10DNode(arg)); 1.1380 + break; 1.1381 + default: 1.1382 + assert(false, "bad intrinsic was passed in"); 1.1383 + return false; 1.1384 + } 1.1385 + 1.1386 + // Push result back on JVM stack 1.1387 + push_pair(trans); 1.1388 + return true; 1.1389 +} 1.1390 + 1.1391 +//------------------------------runtime_math----------------------------- 1.1392 +bool LibraryCallKit::runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName) { 1.1393 + Node* a = NULL; 1.1394 + Node* b = NULL; 1.1395 + 1.1396 + assert(call_type == OptoRuntime::Math_DD_D_Type() || call_type == OptoRuntime::Math_D_D_Type(), 1.1397 + "must be (DD)D or (D)D type"); 1.1398 + 1.1399 + // Inputs 1.1400 + _sp += arg_size(); // restore stack pointer 1.1401 + if (call_type == OptoRuntime::Math_DD_D_Type()) { 1.1402 + b = pop_math_arg(); 1.1403 + } 1.1404 + a = pop_math_arg(); 1.1405 + 1.1406 + const TypePtr* no_memory_effects = NULL; 1.1407 + Node* trig = make_runtime_call(RC_LEAF, call_type, funcAddr, funcName, 1.1408 + no_memory_effects, 1.1409 + a, top(), b, b ? top() : NULL); 1.1410 + Node* value = _gvn.transform(new (C, 1) ProjNode(trig, TypeFunc::Parms+0)); 1.1411 +#ifdef ASSERT 1.1412 + Node* value_top = _gvn.transform(new (C, 1) ProjNode(trig, TypeFunc::Parms+1)); 1.1413 + assert(value_top == top(), "second value must be top"); 1.1414 +#endif 1.1415 + 1.1416 + push_pair(value); 1.1417 + return true; 1.1418 +} 1.1419 + 1.1420 +//------------------------------inline_math_native----------------------------- 1.1421 +bool LibraryCallKit::inline_math_native(vmIntrinsics::ID id) { 1.1422 + switch (id) { 1.1423 + // These intrinsics are not properly supported on all hardware 1.1424 + case vmIntrinsics::_dcos: return Matcher::has_match_rule(Op_CosD) ? inline_trig(id) : 1.1425 + runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dcos), "COS"); 1.1426 + case vmIntrinsics::_dsin: return Matcher::has_match_rule(Op_SinD) ? inline_trig(id) : 1.1427 + runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dsin), "SIN"); 1.1428 + case vmIntrinsics::_dtan: return Matcher::has_match_rule(Op_TanD) ? inline_trig(id) : 1.1429 + runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dtan), "TAN"); 1.1430 + 1.1431 + case vmIntrinsics::_dlog: return Matcher::has_match_rule(Op_LogD) ? inline_trans(id) : 1.1432 + runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dlog), "LOG"); 1.1433 + case vmIntrinsics::_dlog10: return Matcher::has_match_rule(Op_Log10D) ? inline_trans(id) : 1.1434 + runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dlog10), "LOG10"); 1.1435 + 1.1436 + // These intrinsics are supported on all hardware 1.1437 + case vmIntrinsics::_dsqrt: return Matcher::has_match_rule(Op_SqrtD) ? inline_sqrt(id) : false; 1.1438 + case vmIntrinsics::_dabs: return Matcher::has_match_rule(Op_AbsD) ? inline_abs(id) : false; 1.1439 + 1.1440 + // These intrinsics don't work on X86. The ad implementation doesn't 1.1441 + // handle NaN's properly. Instead of returning infinity, the ad 1.1442 + // implementation returns a NaN on overflow. See bug: 6304089 1.1443 + // Once the ad implementations are fixed, change the code below 1.1444 + // to match the intrinsics above 1.1445 + 1.1446 + case vmIntrinsics::_dexp: return 1.1447 + runtime_math(OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dexp), "EXP"); 1.1448 + case vmIntrinsics::_dpow: return 1.1449 + runtime_math(OptoRuntime::Math_DD_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dpow), "POW"); 1.1450 + 1.1451 + // These intrinsics are not yet correctly implemented 1.1452 + case vmIntrinsics::_datan2: 1.1453 + return false; 1.1454 + 1.1455 + default: 1.1456 + ShouldNotReachHere(); 1.1457 + return false; 1.1458 + } 1.1459 +} 1.1460 + 1.1461 +static bool is_simple_name(Node* n) { 1.1462 + return (n->req() == 1 // constant 1.1463 + || (n->is_Type() && n->as_Type()->type()->singleton()) 1.1464 + || n->is_Proj() // parameter or return value 1.1465 + || n->is_Phi() // local of some sort 1.1466 + ); 1.1467 +} 1.1468 + 1.1469 +//----------------------------inline_min_max----------------------------------- 1.1470 +bool LibraryCallKit::inline_min_max(vmIntrinsics::ID id) { 1.1471 + push(generate_min_max(id, argument(0), argument(1))); 1.1472 + 1.1473 + return true; 1.1474 +} 1.1475 + 1.1476 +Node* 1.1477 +LibraryCallKit::generate_min_max(vmIntrinsics::ID id, Node* x0, Node* y0) { 1.1478 + // These are the candidate return value: 1.1479 + Node* xvalue = x0; 1.1480 + Node* yvalue = y0; 1.1481 + 1.1482 + if (xvalue == yvalue) { 1.1483 + return xvalue; 1.1484 + } 1.1485 + 1.1486 + bool want_max = (id == vmIntrinsics::_max); 1.1487 + 1.1488 + const TypeInt* txvalue = _gvn.type(xvalue)->isa_int(); 1.1489 + const TypeInt* tyvalue = _gvn.type(yvalue)->isa_int(); 1.1490 + if (txvalue == NULL || tyvalue == NULL) return top(); 1.1491 + // This is not really necessary, but it is consistent with a 1.1492 + // hypothetical MaxINode::Value method: 1.1493 + int widen = MAX2(txvalue->_widen, tyvalue->_widen); 1.1494 + 1.1495 + // %%% This folding logic should (ideally) be in a different place. 1.1496 + // Some should be inside IfNode, and there to be a more reliable 1.1497 + // transformation of ?: style patterns into cmoves. We also want 1.1498 + // more powerful optimizations around cmove and min/max. 1.1499 + 1.1500 + // Try to find a dominating comparison of these guys. 1.1501 + // It can simplify the index computation for Arrays.copyOf 1.1502 + // and similar uses of System.arraycopy. 1.1503 + // First, compute the normalized version of CmpI(x, y). 1.1504 + int cmp_op = Op_CmpI; 1.1505 + Node* xkey = xvalue; 1.1506 + Node* ykey = yvalue; 1.1507 + Node* ideal_cmpxy = _gvn.transform( new(C, 3) CmpINode(xkey, ykey) ); 1.1508 + if (ideal_cmpxy->is_Cmp()) { 1.1509 + // E.g., if we have CmpI(length - offset, count), 1.1510 + // it might idealize to CmpI(length, count + offset) 1.1511 + cmp_op = ideal_cmpxy->Opcode(); 1.1512 + xkey = ideal_cmpxy->in(1); 1.1513 + ykey = ideal_cmpxy->in(2); 1.1514 + } 1.1515 + 1.1516 + // Start by locating any relevant comparisons. 1.1517 + Node* start_from = (xkey->outcnt() < ykey->outcnt()) ? xkey : ykey; 1.1518 + Node* cmpxy = NULL; 1.1519 + Node* cmpyx = NULL; 1.1520 + for (DUIterator_Fast kmax, k = start_from->fast_outs(kmax); k < kmax; k++) { 1.1521 + Node* cmp = start_from->fast_out(k); 1.1522 + if (cmp->outcnt() > 0 && // must have prior uses 1.1523 + cmp->in(0) == NULL && // must be context-independent 1.1524 + cmp->Opcode() == cmp_op) { // right kind of compare 1.1525 + if (cmp->in(1) == xkey && cmp->in(2) == ykey) cmpxy = cmp; 1.1526 + if (cmp->in(1) == ykey && cmp->in(2) == xkey) cmpyx = cmp; 1.1527 + } 1.1528 + } 1.1529 + 1.1530 + const int NCMPS = 2; 1.1531 + Node* cmps[NCMPS] = { cmpxy, cmpyx }; 1.1532 + int cmpn; 1.1533 + for (cmpn = 0; cmpn < NCMPS; cmpn++) { 1.1534 + if (cmps[cmpn] != NULL) break; // find a result 1.1535 + } 1.1536 + if (cmpn < NCMPS) { 1.1537 + // Look for a dominating test that tells us the min and max. 1.1538 + int depth = 0; // Limit search depth for speed 1.1539 + Node* dom = control(); 1.1540 + for (; dom != NULL; dom = IfNode::up_one_dom(dom, true)) { 1.1541 + if (++depth >= 100) break; 1.1542 + Node* ifproj = dom; 1.1543 + if (!ifproj->is_Proj()) continue; 1.1544 + Node* iff = ifproj->in(0); 1.1545 + if (!iff->is_If()) continue; 1.1546 + Node* bol = iff->in(1); 1.1547 + if (!bol->is_Bool()) continue; 1.1548 + Node* cmp = bol->in(1); 1.1549 + if (cmp == NULL) continue; 1.1550 + for (cmpn = 0; cmpn < NCMPS; cmpn++) 1.1551 + if (cmps[cmpn] == cmp) break; 1.1552 + if (cmpn == NCMPS) continue; 1.1553 + BoolTest::mask btest = bol->as_Bool()->_test._test; 1.1554 + if (ifproj->is_IfFalse()) btest = BoolTest(btest).negate(); 1.1555 + if (cmp->in(1) == ykey) btest = BoolTest(btest).commute(); 1.1556 + // At this point, we know that 'x btest y' is true. 1.1557 + switch (btest) { 1.1558 + case BoolTest::eq: 1.1559 + // They are proven equal, so we can collapse the min/max. 1.1560 + // Either value is the answer. Choose the simpler. 1.1561 + if (is_simple_name(yvalue) && !is_simple_name(xvalue)) 1.1562 + return yvalue; 1.1563 + return xvalue; 1.1564 + case BoolTest::lt: // x < y 1.1565 + case BoolTest::le: // x <= y 1.1566 + return (want_max ? yvalue : xvalue); 1.1567 + case BoolTest::gt: // x > y 1.1568 + case BoolTest::ge: // x >= y 1.1569 + return (want_max ? xvalue : yvalue); 1.1570 + } 1.1571 + } 1.1572 + } 1.1573 + 1.1574 + // We failed to find a dominating test. 1.1575 + // Let's pick a test that might GVN with prior tests. 1.1576 + Node* best_bol = NULL; 1.1577 + BoolTest::mask best_btest = BoolTest::illegal; 1.1578 + for (cmpn = 0; cmpn < NCMPS; cmpn++) { 1.1579 + Node* cmp = cmps[cmpn]; 1.1580 + if (cmp == NULL) continue; 1.1581 + for (DUIterator_Fast jmax, j = cmp->fast_outs(jmax); j < jmax; j++) { 1.1582 + Node* bol = cmp->fast_out(j); 1.1583 + if (!bol->is_Bool()) continue; 1.1584 + BoolTest::mask btest = bol->as_Bool()->_test._test; 1.1585 + if (btest == BoolTest::eq || btest == BoolTest::ne) continue; 1.1586 + if (cmp->in(1) == ykey) btest = BoolTest(btest).commute(); 1.1587 + if (bol->outcnt() > (best_bol == NULL ? 0 : best_bol->outcnt())) { 1.1588 + best_bol = bol->as_Bool(); 1.1589 + best_btest = btest; 1.1590 + } 1.1591 + } 1.1592 + } 1.1593 + 1.1594 + Node* answer_if_true = NULL; 1.1595 + Node* answer_if_false = NULL; 1.1596 + switch (best_btest) { 1.1597 + default: 1.1598 + if (cmpxy == NULL) 1.1599 + cmpxy = ideal_cmpxy; 1.1600 + best_bol = _gvn.transform( new(C, 2) BoolNode(cmpxy, BoolTest::lt) ); 1.1601 + // and fall through: 1.1602 + case BoolTest::lt: // x < y 1.1603 + case BoolTest::le: // x <= y 1.1604 + answer_if_true = (want_max ? yvalue : xvalue); 1.1605 + answer_if_false = (want_max ? xvalue : yvalue); 1.1606 + break; 1.1607 + case BoolTest::gt: // x > y 1.1608 + case BoolTest::ge: // x >= y 1.1609 + answer_if_true = (want_max ? xvalue : yvalue); 1.1610 + answer_if_false = (want_max ? yvalue : xvalue); 1.1611 + break; 1.1612 + } 1.1613 + 1.1614 + jint hi, lo; 1.1615 + if (want_max) { 1.1616 + // We can sharpen the minimum. 1.1617 + hi = MAX2(txvalue->_hi, tyvalue->_hi); 1.1618 + lo = MAX2(txvalue->_lo, tyvalue->_lo); 1.1619 + } else { 1.1620 + // We can sharpen the maximum. 1.1621 + hi = MIN2(txvalue->_hi, tyvalue->_hi); 1.1622 + lo = MIN2(txvalue->_lo, tyvalue->_lo); 1.1623 + } 1.1624 + 1.1625 + // Use a flow-free graph structure, to avoid creating excess control edges 1.1626 + // which could hinder other optimizations. 1.1627 + // Since Math.min/max is often used with arraycopy, we want 1.1628 + // tightly_coupled_allocation to be able to see beyond min/max expressions. 1.1629 + Node* cmov = CMoveNode::make(C, NULL, best_bol, 1.1630 + answer_if_false, answer_if_true, 1.1631 + TypeInt::make(lo, hi, widen)); 1.1632 + 1.1633 + return _gvn.transform(cmov); 1.1634 + 1.1635 + /* 1.1636 + // This is not as desirable as it may seem, since Min and Max 1.1637 + // nodes do not have a full set of optimizations. 1.1638 + // And they would interfere, anyway, with 'if' optimizations 1.1639 + // and with CMoveI canonical forms. 1.1640 + switch (id) { 1.1641 + case vmIntrinsics::_min: 1.1642 + result_val = _gvn.transform(new (C, 3) MinINode(x,y)); break; 1.1643 + case vmIntrinsics::_max: 1.1644 + result_val = _gvn.transform(new (C, 3) MaxINode(x,y)); break; 1.1645 + default: 1.1646 + ShouldNotReachHere(); 1.1647 + } 1.1648 + */ 1.1649 +} 1.1650 + 1.1651 +inline int 1.1652 +LibraryCallKit::classify_unsafe_addr(Node* &base, Node* &offset) { 1.1653 + const TypePtr* base_type = TypePtr::NULL_PTR; 1.1654 + if (base != NULL) base_type = _gvn.type(base)->isa_ptr(); 1.1655 + if (base_type == NULL) { 1.1656 + // Unknown type. 1.1657 + return Type::AnyPtr; 1.1658 + } else if (base_type == TypePtr::NULL_PTR) { 1.1659 + // Since this is a NULL+long form, we have to switch to a rawptr. 1.1660 + base = _gvn.transform( new (C, 2) CastX2PNode(offset) ); 1.1661 + offset = MakeConX(0); 1.1662 + return Type::RawPtr; 1.1663 + } else if (base_type->base() == Type::RawPtr) { 1.1664 + return Type::RawPtr; 1.1665 + } else if (base_type->isa_oopptr()) { 1.1666 + // Base is never null => always a heap address. 1.1667 + if (base_type->ptr() == TypePtr::NotNull) { 1.1668 + return Type::OopPtr; 1.1669 + } 1.1670 + // Offset is small => always a heap address. 1.1671 + const TypeX* offset_type = _gvn.type(offset)->isa_intptr_t(); 1.1672 + if (offset_type != NULL && 1.1673 + base_type->offset() == 0 && // (should always be?) 1.1674 + offset_type->_lo >= 0 && 1.1675 + !MacroAssembler::needs_explicit_null_check(offset_type->_hi)) { 1.1676 + return Type::OopPtr; 1.1677 + } 1.1678 + // Otherwise, it might either be oop+off or NULL+addr. 1.1679 + return Type::AnyPtr; 1.1680 + } else { 1.1681 + // No information: 1.1682 + return Type::AnyPtr; 1.1683 + } 1.1684 +} 1.1685 + 1.1686 +inline Node* LibraryCallKit::make_unsafe_address(Node* base, Node* offset) { 1.1687 + int kind = classify_unsafe_addr(base, offset); 1.1688 + if (kind == Type::RawPtr) { 1.1689 + return basic_plus_adr(top(), base, offset); 1.1690 + } else { 1.1691 + return basic_plus_adr(base, offset); 1.1692 + } 1.1693 +} 1.1694 + 1.1695 +//----------------------------inline_reverseBytes_int/long------------------- 1.1696 +// inline Int.reverseBytes(int) 1.1697 +// inline Long.reverseByes(long) 1.1698 +bool LibraryCallKit::inline_reverseBytes(vmIntrinsics::ID id) { 1.1699 + assert(id == vmIntrinsics::_reverseBytes_i || id == vmIntrinsics::_reverseBytes_l, "not reverse Bytes"); 1.1700 + if (id == vmIntrinsics::_reverseBytes_i && !Matcher::has_match_rule(Op_ReverseBytesI)) return false; 1.1701 + if (id == vmIntrinsics::_reverseBytes_l && !Matcher::has_match_rule(Op_ReverseBytesL)) return false; 1.1702 + _sp += arg_size(); // restore stack pointer 1.1703 + switch (id) { 1.1704 + case vmIntrinsics::_reverseBytes_i: 1.1705 + push(_gvn.transform(new (C, 2) ReverseBytesINode(0, pop()))); 1.1706 + break; 1.1707 + case vmIntrinsics::_reverseBytes_l: 1.1708 + push_pair(_gvn.transform(new (C, 2) ReverseBytesLNode(0, pop_pair()))); 1.1709 + break; 1.1710 + default: 1.1711 + ; 1.1712 + } 1.1713 + return true; 1.1714 +} 1.1715 + 1.1716 +//----------------------------inline_unsafe_access---------------------------- 1.1717 + 1.1718 +const static BasicType T_ADDRESS_HOLDER = T_LONG; 1.1719 + 1.1720 +// Interpret Unsafe.fieldOffset cookies correctly: 1.1721 +extern jlong Unsafe_field_offset_to_byte_offset(jlong field_offset); 1.1722 + 1.1723 +bool LibraryCallKit::inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile) { 1.1724 + if (callee()->is_static()) return false; // caller must have the capability! 1.1725 + 1.1726 +#ifndef PRODUCT 1.1727 + { 1.1728 + ResourceMark rm; 1.1729 + // Check the signatures. 1.1730 + ciSignature* sig = signature(); 1.1731 +#ifdef ASSERT 1.1732 + if (!is_store) { 1.1733 + // Object getObject(Object base, int/long offset), etc. 1.1734 + BasicType rtype = sig->return_type()->basic_type(); 1.1735 + if (rtype == T_ADDRESS_HOLDER && callee()->name() == ciSymbol::getAddress_name()) 1.1736 + rtype = T_ADDRESS; // it is really a C void* 1.1737 + assert(rtype == type, "getter must return the expected value"); 1.1738 + if (!is_native_ptr) { 1.1739 + assert(sig->count() == 2, "oop getter has 2 arguments"); 1.1740 + assert(sig->type_at(0)->basic_type() == T_OBJECT, "getter base is object"); 1.1741 + assert(sig->type_at(1)->basic_type() == T_LONG, "getter offset is correct"); 1.1742 + } else { 1.1743 + assert(sig->count() == 1, "native getter has 1 argument"); 1.1744 + assert(sig->type_at(0)->basic_type() == T_LONG, "getter base is long"); 1.1745 + } 1.1746 + } else { 1.1747 + // void putObject(Object base, int/long offset, Object x), etc. 1.1748 + assert(sig->return_type()->basic_type() == T_VOID, "putter must not return a value"); 1.1749 + if (!is_native_ptr) { 1.1750 + assert(sig->count() == 3, "oop putter has 3 arguments"); 1.1751 + assert(sig->type_at(0)->basic_type() == T_OBJECT, "putter base is object"); 1.1752 + assert(sig->type_at(1)->basic_type() == T_LONG, "putter offset is correct"); 1.1753 + } else { 1.1754 + assert(sig->count() == 2, "native putter has 2 arguments"); 1.1755 + assert(sig->type_at(0)->basic_type() == T_LONG, "putter base is long"); 1.1756 + } 1.1757 + BasicType vtype = sig->type_at(sig->count()-1)->basic_type(); 1.1758 + if (vtype == T_ADDRESS_HOLDER && callee()->name() == ciSymbol::putAddress_name()) 1.1759 + vtype = T_ADDRESS; // it is really a C void* 1.1760 + assert(vtype == type, "putter must accept the expected value"); 1.1761 + } 1.1762 +#endif // ASSERT 1.1763 + } 1.1764 +#endif //PRODUCT 1.1765 + 1.1766 + C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 1.1767 + 1.1768 + int type_words = type2size[ (type == T_ADDRESS) ? T_LONG : type ]; 1.1769 + 1.1770 + // Argument words: "this" plus (oop/offset) or (lo/hi) args plus maybe 1 or 2 value words 1.1771 + int nargs = 1 + (is_native_ptr ? 2 : 3) + (is_store ? type_words : 0); 1.1772 + 1.1773 + debug_only(int saved_sp = _sp); 1.1774 + _sp += nargs; 1.1775 + 1.1776 + Node* val; 1.1777 + debug_only(val = (Node*)(uintptr_t)-1); 1.1778 + 1.1779 + 1.1780 + if (is_store) { 1.1781 + // Get the value being stored. (Pop it first; it was pushed last.) 1.1782 + switch (type) { 1.1783 + case T_DOUBLE: 1.1784 + case T_LONG: 1.1785 + case T_ADDRESS: 1.1786 + val = pop_pair(); 1.1787 + break; 1.1788 + default: 1.1789 + val = pop(); 1.1790 + } 1.1791 + } 1.1792 + 1.1793 + // Build address expression. See the code in inline_unsafe_prefetch. 1.1794 + Node *adr; 1.1795 + Node *heap_base_oop = top(); 1.1796 + if (!is_native_ptr) { 1.1797 + // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset 1.1798 + Node* offset = pop_pair(); 1.1799 + // The base is either a Java object or a value produced by Unsafe.staticFieldBase 1.1800 + Node* base = pop(); 1.1801 + // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 1.1802 + // to be plain byte offsets, which are also the same as those accepted 1.1803 + // by oopDesc::field_base. 1.1804 + assert(Unsafe_field_offset_to_byte_offset(11) == 11, 1.1805 + "fieldOffset must be byte-scaled"); 1.1806 + // 32-bit machines ignore the high half! 1.1807 + offset = ConvL2X(offset); 1.1808 + adr = make_unsafe_address(base, offset); 1.1809 + heap_base_oop = base; 1.1810 + } else { 1.1811 + Node* ptr = pop_pair(); 1.1812 + // Adjust Java long to machine word: 1.1813 + ptr = ConvL2X(ptr); 1.1814 + adr = make_unsafe_address(NULL, ptr); 1.1815 + } 1.1816 + 1.1817 + // Pop receiver last: it was pushed first. 1.1818 + Node *receiver = pop(); 1.1819 + 1.1820 + assert(saved_sp == _sp, "must have correct argument count"); 1.1821 + 1.1822 + const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); 1.1823 + 1.1824 + // First guess at the value type. 1.1825 + const Type *value_type = Type::get_const_basic_type(type); 1.1826 + 1.1827 + // Try to categorize the address. If it comes up as TypeJavaPtr::BOTTOM, 1.1828 + // there was not enough information to nail it down. 1.1829 + Compile::AliasType* alias_type = C->alias_type(adr_type); 1.1830 + assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here"); 1.1831 + 1.1832 + // We will need memory barriers unless we can determine a unique 1.1833 + // alias category for this reference. (Note: If for some reason 1.1834 + // the barriers get omitted and the unsafe reference begins to "pollute" 1.1835 + // the alias analysis of the rest of the graph, either Compile::can_alias 1.1836 + // or Compile::must_alias will throw a diagnostic assert.) 1.1837 + bool need_mem_bar = (alias_type->adr_type() == TypeOopPtr::BOTTOM); 1.1838 + 1.1839 + if (!is_store && type == T_OBJECT) { 1.1840 + // Attempt to infer a sharper value type from the offset and base type. 1.1841 + ciKlass* sharpened_klass = NULL; 1.1842 + 1.1843 + // See if it is an instance field, with an object type. 1.1844 + if (alias_type->field() != NULL) { 1.1845 + assert(!is_native_ptr, "native pointer op cannot use a java address"); 1.1846 + if (alias_type->field()->type()->is_klass()) { 1.1847 + sharpened_klass = alias_type->field()->type()->as_klass(); 1.1848 + } 1.1849 + } 1.1850 + 1.1851 + // See if it is a narrow oop array. 1.1852 + if (adr_type->isa_aryptr()) { 1.1853 + if (adr_type->offset() >= objArrayOopDesc::header_size() * wordSize) { 1.1854 + const TypeOopPtr *elem_type = adr_type->is_aryptr()->elem()->isa_oopptr(); 1.1855 + if (elem_type != NULL) { 1.1856 + sharpened_klass = elem_type->klass(); 1.1857 + } 1.1858 + } 1.1859 + } 1.1860 + 1.1861 + if (sharpened_klass != NULL) { 1.1862 + const TypeOopPtr* tjp = TypeOopPtr::make_from_klass(sharpened_klass); 1.1863 + 1.1864 + // Sharpen the value type. 1.1865 + value_type = tjp; 1.1866 + 1.1867 +#ifndef PRODUCT 1.1868 + if (PrintIntrinsics || PrintInlining || PrintOptoInlining) { 1.1869 + tty->print(" from base type: "); adr_type->dump(); 1.1870 + tty->print(" sharpened value: "); value_type->dump(); 1.1871 + } 1.1872 +#endif 1.1873 + } 1.1874 + } 1.1875 + 1.1876 + // Null check on self without removing any arguments. The argument 1.1877 + // null check technically happens in the wrong place, which can lead to 1.1878 + // invalid stack traces when the primitive is inlined into a method 1.1879 + // which handles NullPointerExceptions. 1.1880 + _sp += nargs; 1.1881 + do_null_check(receiver, T_OBJECT); 1.1882 + _sp -= nargs; 1.1883 + if (stopped()) { 1.1884 + return true; 1.1885 + } 1.1886 + // Heap pointers get a null-check from the interpreter, 1.1887 + // as a courtesy. However, this is not guaranteed by Unsafe, 1.1888 + // and it is not possible to fully distinguish unintended nulls 1.1889 + // from intended ones in this API. 1.1890 + 1.1891 + if (is_volatile) { 1.1892 + // We need to emit leading and trailing CPU membars (see below) in 1.1893 + // addition to memory membars when is_volatile. This is a little 1.1894 + // too strong, but avoids the need to insert per-alias-type 1.1895 + // volatile membars (for stores; compare Parse::do_put_xxx), which 1.1896 + // we cannot do effctively here because we probably only have a 1.1897 + // rough approximation of type. 1.1898 + need_mem_bar = true; 1.1899 + // For Stores, place a memory ordering barrier now. 1.1900 + if (is_store) 1.1901 + insert_mem_bar(Op_MemBarRelease); 1.1902 + } 1.1903 + 1.1904 + // Memory barrier to prevent normal and 'unsafe' accesses from 1.1905 + // bypassing each other. Happens after null checks, so the 1.1906 + // exception paths do not take memory state from the memory barrier, 1.1907 + // so there's no problems making a strong assert about mixing users 1.1908 + // of safe & unsafe memory. Otherwise fails in a CTW of rt.jar 1.1909 + // around 5701, class sun/reflect/UnsafeBooleanFieldAccessorImpl. 1.1910 + if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder); 1.1911 + 1.1912 + if (!is_store) { 1.1913 + Node* p = make_load(control(), adr, value_type, type, adr_type, is_volatile); 1.1914 + // load value and push onto stack 1.1915 + switch (type) { 1.1916 + case T_BOOLEAN: 1.1917 + case T_CHAR: 1.1918 + case T_BYTE: 1.1919 + case T_SHORT: 1.1920 + case T_INT: 1.1921 + case T_FLOAT: 1.1922 + case T_OBJECT: 1.1923 + push( p ); 1.1924 + break; 1.1925 + case T_ADDRESS: 1.1926 + // Cast to an int type. 1.1927 + p = _gvn.transform( new (C, 2) CastP2XNode(NULL,p) ); 1.1928 + p = ConvX2L(p); 1.1929 + push_pair(p); 1.1930 + break; 1.1931 + case T_DOUBLE: 1.1932 + case T_LONG: 1.1933 + push_pair( p ); 1.1934 + break; 1.1935 + default: ShouldNotReachHere(); 1.1936 + } 1.1937 + } else { 1.1938 + // place effect of store into memory 1.1939 + switch (type) { 1.1940 + case T_DOUBLE: 1.1941 + val = dstore_rounding(val); 1.1942 + break; 1.1943 + case T_ADDRESS: 1.1944 + // Repackage the long as a pointer. 1.1945 + val = ConvL2X(val); 1.1946 + val = _gvn.transform( new (C, 2) CastX2PNode(val) ); 1.1947 + break; 1.1948 + } 1.1949 + 1.1950 + if (type != T_OBJECT ) { 1.1951 + (void) store_to_memory(control(), adr, val, type, adr_type, is_volatile); 1.1952 + } else { 1.1953 + // Possibly an oop being stored to Java heap or native memory 1.1954 + if (!TypePtr::NULL_PTR->higher_equal(_gvn.type(heap_base_oop))) { 1.1955 + // oop to Java heap. 1.1956 + (void) store_oop_to_unknown(control(), heap_base_oop, adr, adr_type, val, val->bottom_type(), type); 1.1957 + } else { 1.1958 + 1.1959 + // We can't tell at compile time if we are storing in the Java heap or outside 1.1960 + // of it. So we need to emit code to conditionally do the proper type of 1.1961 + // store. 1.1962 + 1.1963 + IdealKit kit(gvn(), control(), merged_memory()); 1.1964 + kit.declares_done(); 1.1965 + // QQQ who knows what probability is here?? 1.1966 + kit.if_then(heap_base_oop, BoolTest::ne, null(), PROB_UNLIKELY(0.999)); { 1.1967 + (void) store_oop_to_unknown(control(), heap_base_oop, adr, adr_type, val, val->bottom_type(), type); 1.1968 + } kit.else_(); { 1.1969 + (void) store_to_memory(control(), adr, val, type, adr_type, is_volatile); 1.1970 + } kit.end_if(); 1.1971 + } 1.1972 + } 1.1973 + } 1.1974 + 1.1975 + if (is_volatile) { 1.1976 + if (!is_store) 1.1977 + insert_mem_bar(Op_MemBarAcquire); 1.1978 + else 1.1979 + insert_mem_bar(Op_MemBarVolatile); 1.1980 + } 1.1981 + 1.1982 + if (need_mem_bar) insert_mem_bar(Op_MemBarCPUOrder); 1.1983 + 1.1984 + return true; 1.1985 +} 1.1986 + 1.1987 +//----------------------------inline_unsafe_prefetch---------------------------- 1.1988 + 1.1989 +bool LibraryCallKit::inline_unsafe_prefetch(bool is_native_ptr, bool is_store, bool is_static) { 1.1990 +#ifndef PRODUCT 1.1991 + { 1.1992 + ResourceMark rm; 1.1993 + // Check the signatures. 1.1994 + ciSignature* sig = signature(); 1.1995 +#ifdef ASSERT 1.1996 + // Object getObject(Object base, int/long offset), etc. 1.1997 + BasicType rtype = sig->return_type()->basic_type(); 1.1998 + if (!is_native_ptr) { 1.1999 + assert(sig->count() == 2, "oop prefetch has 2 arguments"); 1.2000 + assert(sig->type_at(0)->basic_type() == T_OBJECT, "prefetch base is object"); 1.2001 + assert(sig->type_at(1)->basic_type() == T_LONG, "prefetcha offset is correct"); 1.2002 + } else { 1.2003 + assert(sig->count() == 1, "native prefetch has 1 argument"); 1.2004 + assert(sig->type_at(0)->basic_type() == T_LONG, "prefetch base is long"); 1.2005 + } 1.2006 +#endif // ASSERT 1.2007 + } 1.2008 +#endif // !PRODUCT 1.2009 + 1.2010 + C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 1.2011 + 1.2012 + // Argument words: "this" if not static, plus (oop/offset) or (lo/hi) args 1.2013 + int nargs = (is_static ? 0 : 1) + (is_native_ptr ? 2 : 3); 1.2014 + 1.2015 + debug_only(int saved_sp = _sp); 1.2016 + _sp += nargs; 1.2017 + 1.2018 + // Build address expression. See the code in inline_unsafe_access. 1.2019 + Node *adr; 1.2020 + if (!is_native_ptr) { 1.2021 + // The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset 1.2022 + Node* offset = pop_pair(); 1.2023 + // The base is either a Java object or a value produced by Unsafe.staticFieldBase 1.2024 + Node* base = pop(); 1.2025 + // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 1.2026 + // to be plain byte offsets, which are also the same as those accepted 1.2027 + // by oopDesc::field_base. 1.2028 + assert(Unsafe_field_offset_to_byte_offset(11) == 11, 1.2029 + "fieldOffset must be byte-scaled"); 1.2030 + // 32-bit machines ignore the high half! 1.2031 + offset = ConvL2X(offset); 1.2032 + adr = make_unsafe_address(base, offset); 1.2033 + } else { 1.2034 + Node* ptr = pop_pair(); 1.2035 + // Adjust Java long to machine word: 1.2036 + ptr = ConvL2X(ptr); 1.2037 + adr = make_unsafe_address(NULL, ptr); 1.2038 + } 1.2039 + 1.2040 + if (is_static) { 1.2041 + assert(saved_sp == _sp, "must have correct argument count"); 1.2042 + } else { 1.2043 + // Pop receiver last: it was pushed first. 1.2044 + Node *receiver = pop(); 1.2045 + assert(saved_sp == _sp, "must have correct argument count"); 1.2046 + 1.2047 + // Null check on self without removing any arguments. The argument 1.2048 + // null check technically happens in the wrong place, which can lead to 1.2049 + // invalid stack traces when the primitive is inlined into a method 1.2050 + // which handles NullPointerExceptions. 1.2051 + _sp += nargs; 1.2052 + do_null_check(receiver, T_OBJECT); 1.2053 + _sp -= nargs; 1.2054 + if (stopped()) { 1.2055 + return true; 1.2056 + } 1.2057 + } 1.2058 + 1.2059 + // Generate the read or write prefetch 1.2060 + Node *prefetch; 1.2061 + if (is_store) { 1.2062 + prefetch = new (C, 3) PrefetchWriteNode(i_o(), adr); 1.2063 + } else { 1.2064 + prefetch = new (C, 3) PrefetchReadNode(i_o(), adr); 1.2065 + } 1.2066 + prefetch->init_req(0, control()); 1.2067 + set_i_o(_gvn.transform(prefetch)); 1.2068 + 1.2069 + return true; 1.2070 +} 1.2071 + 1.2072 +//----------------------------inline_unsafe_CAS---------------------------- 1.2073 + 1.2074 +bool LibraryCallKit::inline_unsafe_CAS(BasicType type) { 1.2075 + // This basic scheme here is the same as inline_unsafe_access, but 1.2076 + // differs in enough details that combining them would make the code 1.2077 + // overly confusing. (This is a true fact! I originally combined 1.2078 + // them, but even I was confused by it!) As much code/comments as 1.2079 + // possible are retained from inline_unsafe_access though to make 1.2080 + // the correspondances clearer. - dl 1.2081 + 1.2082 + if (callee()->is_static()) return false; // caller must have the capability! 1.2083 + 1.2084 +#ifndef PRODUCT 1.2085 + { 1.2086 + ResourceMark rm; 1.2087 + // Check the signatures. 1.2088 + ciSignature* sig = signature(); 1.2089 +#ifdef ASSERT 1.2090 + BasicType rtype = sig->return_type()->basic_type(); 1.2091 + assert(rtype == T_BOOLEAN, "CAS must return boolean"); 1.2092 + assert(sig->count() == 4, "CAS has 4 arguments"); 1.2093 + assert(sig->type_at(0)->basic_type() == T_OBJECT, "CAS base is object"); 1.2094 + assert(sig->type_at(1)->basic_type() == T_LONG, "CAS offset is long"); 1.2095 +#endif // ASSERT 1.2096 + } 1.2097 +#endif //PRODUCT 1.2098 + 1.2099 + // number of stack slots per value argument (1 or 2) 1.2100 + int type_words = type2size[type]; 1.2101 + 1.2102 + // Cannot inline wide CAS on machines that don't support it natively 1.2103 + if (type2aelembytes[type] > BytesPerInt && !VM_Version::supports_cx8()) 1.2104 + return false; 1.2105 + 1.2106 + C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 1.2107 + 1.2108 + // Argument words: "this" plus oop plus offset plus oldvalue plus newvalue; 1.2109 + int nargs = 1 + 1 + 2 + type_words + type_words; 1.2110 + 1.2111 + // pop arguments: newval, oldval, offset, base, and receiver 1.2112 + debug_only(int saved_sp = _sp); 1.2113 + _sp += nargs; 1.2114 + Node* newval = (type_words == 1) ? pop() : pop_pair(); 1.2115 + Node* oldval = (type_words == 1) ? pop() : pop_pair(); 1.2116 + Node *offset = pop_pair(); 1.2117 + Node *base = pop(); 1.2118 + Node *receiver = pop(); 1.2119 + assert(saved_sp == _sp, "must have correct argument count"); 1.2120 + 1.2121 + // Null check receiver. 1.2122 + _sp += nargs; 1.2123 + do_null_check(receiver, T_OBJECT); 1.2124 + _sp -= nargs; 1.2125 + if (stopped()) { 1.2126 + return true; 1.2127 + } 1.2128 + 1.2129 + // Build field offset expression. 1.2130 + // We currently rely on the cookies produced by Unsafe.xxxFieldOffset 1.2131 + // to be plain byte offsets, which are also the same as those accepted 1.2132 + // by oopDesc::field_base. 1.2133 + assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled"); 1.2134 + // 32-bit machines ignore the high half of long offsets 1.2135 + offset = ConvL2X(offset); 1.2136 + Node* adr = make_unsafe_address(base, offset); 1.2137 + const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); 1.2138 + 1.2139 + // (Unlike inline_unsafe_access, there seems no point in trying 1.2140 + // to refine types. Just use the coarse types here. 1.2141 + const Type *value_type = Type::get_const_basic_type(type); 1.2142 + Compile::AliasType* alias_type = C->alias_type(adr_type); 1.2143 + assert(alias_type->index() != Compile::AliasIdxBot, "no bare pointers here"); 1.2144 + int alias_idx = C->get_alias_index(adr_type); 1.2145 + 1.2146 + // Memory-model-wise, a CAS acts like a little synchronized block, 1.2147 + // so needs barriers on each side. These don't't translate into 1.2148 + // actual barriers on most machines, but we still need rest of 1.2149 + // compiler to respect ordering. 1.2150 + 1.2151 + insert_mem_bar(Op_MemBarRelease); 1.2152 + insert_mem_bar(Op_MemBarCPUOrder); 1.2153 + 1.2154 + // 4984716: MemBars must be inserted before this 1.2155 + // memory node in order to avoid a false 1.2156 + // dependency which will confuse the scheduler. 1.2157 + Node *mem = memory(alias_idx); 1.2158 + 1.2159 + // For now, we handle only those cases that actually exist: ints, 1.2160 + // longs, and Object. Adding others should be straightforward. 1.2161 + Node* cas; 1.2162 + switch(type) { 1.2163 + case T_INT: 1.2164 + cas = _gvn.transform(new (C, 5) CompareAndSwapINode(control(), mem, adr, newval, oldval)); 1.2165 + break; 1.2166 + case T_LONG: 1.2167 + cas = _gvn.transform(new (C, 5) CompareAndSwapLNode(control(), mem, adr, newval, oldval)); 1.2168 + break; 1.2169 + case T_OBJECT: 1.2170 + // reference stores need a store barrier. 1.2171 + // (They don't if CAS fails, but it isn't worth checking.) 1.2172 + pre_barrier(control(), base, adr, alias_idx, newval, value_type, T_OBJECT); 1.2173 + cas = _gvn.transform(new (C, 5) CompareAndSwapPNode(control(), mem, adr, newval, oldval)); 1.2174 + post_barrier(control(), cas, base, adr, alias_idx, newval, T_OBJECT, true); 1.2175 + break; 1.2176 + default: 1.2177 + ShouldNotReachHere(); 1.2178 + break; 1.2179 + } 1.2180 + 1.2181 + // SCMemProjNodes represent the memory state of CAS. Their main 1.2182 + // role is to prevent CAS nodes from being optimized away when their 1.2183 + // results aren't used. 1.2184 + Node* proj = _gvn.transform( new (C, 1) SCMemProjNode(cas)); 1.2185 + set_memory(proj, alias_idx); 1.2186 + 1.2187 + // Add the trailing membar surrounding the access 1.2188 + insert_mem_bar(Op_MemBarCPUOrder); 1.2189 + insert_mem_bar(Op_MemBarAcquire); 1.2190 + 1.2191 + push(cas); 1.2192 + return true; 1.2193 +} 1.2194 + 1.2195 +bool LibraryCallKit::inline_unsafe_ordered_store(BasicType type) { 1.2196 + // This is another variant of inline_unsafe_access, differing in 1.2197 + // that it always issues store-store ("release") barrier and ensures 1.2198 + // store-atomicity (which only matters for "long"). 1.2199 + 1.2200 + if (callee()->is_static()) return false; // caller must have the capability! 1.2201 + 1.2202 +#ifndef PRODUCT 1.2203 + { 1.2204 + ResourceMark rm; 1.2205 + // Check the signatures. 1.2206 + ciSignature* sig = signature(); 1.2207 +#ifdef ASSERT 1.2208 + BasicType rtype = sig->return_type()->basic_type(); 1.2209 + assert(rtype == T_VOID, "must return void"); 1.2210 + assert(sig->count() == 3, "has 3 arguments"); 1.2211 + assert(sig->type_at(0)->basic_type() == T_OBJECT, "base is object"); 1.2212 + assert(sig->type_at(1)->basic_type() == T_LONG, "offset is long"); 1.2213 +#endif // ASSERT 1.2214 + } 1.2215 +#endif //PRODUCT 1.2216 + 1.2217 + // number of stack slots per value argument (1 or 2) 1.2218 + int type_words = type2size[type]; 1.2219 + 1.2220 + C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 1.2221 + 1.2222 + // Argument words: "this" plus oop plus offset plus value; 1.2223 + int nargs = 1 + 1 + 2 + type_words; 1.2224 + 1.2225 + // pop arguments: val, offset, base, and receiver 1.2226 + debug_only(int saved_sp = _sp); 1.2227 + _sp += nargs; 1.2228 + Node* val = (type_words == 1) ? pop() : pop_pair(); 1.2229 + Node *offset = pop_pair(); 1.2230 + Node *base = pop(); 1.2231 + Node *receiver = pop(); 1.2232 + assert(saved_sp == _sp, "must have correct argument count"); 1.2233 + 1.2234 + // Null check receiver. 1.2235 + _sp += nargs; 1.2236 + do_null_check(receiver, T_OBJECT); 1.2237 + _sp -= nargs; 1.2238 + if (stopped()) { 1.2239 + return true; 1.2240 + } 1.2241 + 1.2242 + // Build field offset expression. 1.2243 + assert(Unsafe_field_offset_to_byte_offset(11) == 11, "fieldOffset must be byte-scaled"); 1.2244 + // 32-bit machines ignore the high half of long offsets 1.2245 + offset = ConvL2X(offset); 1.2246 + Node* adr = make_unsafe_address(base, offset); 1.2247 + const TypePtr *adr_type = _gvn.type(adr)->isa_ptr(); 1.2248 + const Type *value_type = Type::get_const_basic_type(type); 1.2249 + Compile::AliasType* alias_type = C->alias_type(adr_type); 1.2250 + 1.2251 + insert_mem_bar(Op_MemBarRelease); 1.2252 + insert_mem_bar(Op_MemBarCPUOrder); 1.2253 + // Ensure that the store is atomic for longs: 1.2254 + bool require_atomic_access = true; 1.2255 + Node* store; 1.2256 + if (type == T_OBJECT) // reference stores need a store barrier. 1.2257 + store = store_oop_to_unknown(control(), base, adr, adr_type, val, value_type, type); 1.2258 + else { 1.2259 + store = store_to_memory(control(), adr, val, type, adr_type, require_atomic_access); 1.2260 + } 1.2261 + insert_mem_bar(Op_MemBarCPUOrder); 1.2262 + return true; 1.2263 +} 1.2264 + 1.2265 +bool LibraryCallKit::inline_unsafe_allocate() { 1.2266 + if (callee()->is_static()) return false; // caller must have the capability! 1.2267 + int nargs = 1 + 1; 1.2268 + assert(signature()->size() == nargs-1, "alloc has 1 argument"); 1.2269 + null_check_receiver(callee()); // check then ignore argument(0) 1.2270 + _sp += nargs; // set original stack for use by uncommon_trap 1.2271 + Node* cls = do_null_check(argument(1), T_OBJECT); 1.2272 + _sp -= nargs; 1.2273 + if (stopped()) return true; 1.2274 + 1.2275 + Node* kls = load_klass_from_mirror(cls, false, nargs, NULL, 0); 1.2276 + _sp += nargs; // set original stack for use by uncommon_trap 1.2277 + kls = do_null_check(kls, T_OBJECT); 1.2278 + _sp -= nargs; 1.2279 + if (stopped()) return true; // argument was like int.class 1.2280 + 1.2281 + // Note: The argument might still be an illegal value like 1.2282 + // Serializable.class or Object[].class. The runtime will handle it. 1.2283 + // But we must make an explicit check for initialization. 1.2284 + Node* insp = basic_plus_adr(kls, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc)); 1.2285 + Node* inst = make_load(NULL, insp, TypeInt::INT, T_INT); 1.2286 + Node* bits = intcon(instanceKlass::fully_initialized); 1.2287 + Node* test = _gvn.transform( new (C, 3) SubINode(inst, bits) ); 1.2288 + // The 'test' is non-zero if we need to take a slow path. 1.2289 + 1.2290 + Node* obj = new_instance(kls, test); 1.2291 + push(obj); 1.2292 + 1.2293 + return true; 1.2294 +} 1.2295 + 1.2296 +//------------------------inline_native_time_funcs-------------- 1.2297 +// inline code for System.currentTimeMillis() and System.nanoTime() 1.2298 +// these have the same type and signature 1.2299 +bool LibraryCallKit::inline_native_time_funcs(bool isNano) { 1.2300 + address funcAddr = isNano ? CAST_FROM_FN_PTR(address, os::javaTimeNanos) : 1.2301 + CAST_FROM_FN_PTR(address, os::javaTimeMillis); 1.2302 + const char * funcName = isNano ? "nanoTime" : "currentTimeMillis"; 1.2303 + const TypeFunc *tf = OptoRuntime::current_time_millis_Type(); 1.2304 + const TypePtr* no_memory_effects = NULL; 1.2305 + Node* time = make_runtime_call(RC_LEAF, tf, funcAddr, funcName, no_memory_effects); 1.2306 + Node* value = _gvn.transform(new (C, 1) ProjNode(time, TypeFunc::Parms+0)); 1.2307 +#ifdef ASSERT 1.2308 + Node* value_top = _gvn.transform(new (C, 1) ProjNode(time, TypeFunc::Parms + 1)); 1.2309 + assert(value_top == top(), "second value must be top"); 1.2310 +#endif 1.2311 + push_pair(value); 1.2312 + return true; 1.2313 +} 1.2314 + 1.2315 +//------------------------inline_native_currentThread------------------ 1.2316 +bool LibraryCallKit::inline_native_currentThread() { 1.2317 + Node* junk = NULL; 1.2318 + push(generate_current_thread(junk)); 1.2319 + return true; 1.2320 +} 1.2321 + 1.2322 +//------------------------inline_native_isInterrupted------------------ 1.2323 +bool LibraryCallKit::inline_native_isInterrupted() { 1.2324 + const int nargs = 1+1; // receiver + boolean 1.2325 + assert(nargs == arg_size(), "sanity"); 1.2326 + // Add a fast path to t.isInterrupted(clear_int): 1.2327 + // (t == Thread.current() && (!TLS._osthread._interrupted || !clear_int)) 1.2328 + // ? TLS._osthread._interrupted : /*slow path:*/ t.isInterrupted(clear_int) 1.2329 + // So, in the common case that the interrupt bit is false, 1.2330 + // we avoid making a call into the VM. Even if the interrupt bit 1.2331 + // is true, if the clear_int argument is false, we avoid the VM call. 1.2332 + // However, if the receiver is not currentThread, we must call the VM, 1.2333 + // because there must be some locking done around the operation. 1.2334 + 1.2335 + // We only go to the fast case code if we pass two guards. 1.2336 + // Paths which do not pass are accumulated in the slow_region. 1.2337 + RegionNode* slow_region = new (C, 1) RegionNode(1); 1.2338 + record_for_igvn(slow_region); 1.2339 + RegionNode* result_rgn = new (C, 4) RegionNode(1+3); // fast1, fast2, slow 1.2340 + PhiNode* result_val = new (C, 4) PhiNode(result_rgn, TypeInt::BOOL); 1.2341 + enum { no_int_result_path = 1, 1.2342 + no_clear_result_path = 2, 1.2343 + slow_result_path = 3 1.2344 + }; 1.2345 + 1.2346 + // (a) Receiving thread must be the current thread. 1.2347 + Node* rec_thr = argument(0); 1.2348 + Node* tls_ptr = NULL; 1.2349 + Node* cur_thr = generate_current_thread(tls_ptr); 1.2350 + Node* cmp_thr = _gvn.transform( new (C, 3) CmpPNode(cur_thr, rec_thr) ); 1.2351 + Node* bol_thr = _gvn.transform( new (C, 2) BoolNode(cmp_thr, BoolTest::ne) ); 1.2352 + 1.2353 + bool known_current_thread = (_gvn.type(bol_thr) == TypeInt::ZERO); 1.2354 + if (!known_current_thread) 1.2355 + generate_slow_guard(bol_thr, slow_region); 1.2356 + 1.2357 + // (b) Interrupt bit on TLS must be false. 1.2358 + Node* p = basic_plus_adr(top()/*!oop*/, tls_ptr, in_bytes(JavaThread::osthread_offset())); 1.2359 + Node* osthread = make_load(NULL, p, TypeRawPtr::NOTNULL, T_ADDRESS); 1.2360 + p = basic_plus_adr(top()/*!oop*/, osthread, in_bytes(OSThread::interrupted_offset())); 1.2361 + Node* int_bit = make_load(NULL, p, TypeInt::BOOL, T_INT); 1.2362 + Node* cmp_bit = _gvn.transform( new (C, 3) CmpINode(int_bit, intcon(0)) ); 1.2363 + Node* bol_bit = _gvn.transform( new (C, 2) BoolNode(cmp_bit, BoolTest::ne) ); 1.2364 + 1.2365 + IfNode* iff_bit = create_and_map_if(control(), bol_bit, PROB_UNLIKELY_MAG(3), COUNT_UNKNOWN); 1.2366 + 1.2367 + // First fast path: if (!TLS._interrupted) return false; 1.2368 + Node* false_bit = _gvn.transform( new (C, 1) IfFalseNode(iff_bit) ); 1.2369 + result_rgn->init_req(no_int_result_path, false_bit); 1.2370 + result_val->init_req(no_int_result_path, intcon(0)); 1.2371 + 1.2372 + // drop through to next case 1.2373 + set_control( _gvn.transform(new (C, 1) IfTrueNode(iff_bit)) ); 1.2374 + 1.2375 + // (c) Or, if interrupt bit is set and clear_int is false, use 2nd fast path. 1.2376 + Node* clr_arg = argument(1); 1.2377 + Node* cmp_arg = _gvn.transform( new (C, 3) CmpINode(clr_arg, intcon(0)) ); 1.2378 + Node* bol_arg = _gvn.transform( new (C, 2) BoolNode(cmp_arg, BoolTest::ne) ); 1.2379 + IfNode* iff_arg = create_and_map_if(control(), bol_arg, PROB_FAIR, COUNT_UNKNOWN); 1.2380 + 1.2381 + // Second fast path: ... else if (!clear_int) return true; 1.2382 + Node* false_arg = _gvn.transform( new (C, 1) IfFalseNode(iff_arg) ); 1.2383 + result_rgn->init_req(no_clear_result_path, false_arg); 1.2384 + result_val->init_req(no_clear_result_path, intcon(1)); 1.2385 + 1.2386 + // drop through to next case 1.2387 + set_control( _gvn.transform(new (C, 1) IfTrueNode(iff_arg)) ); 1.2388 + 1.2389 + // (d) Otherwise, go to the slow path. 1.2390 + slow_region->add_req(control()); 1.2391 + set_control( _gvn.transform(slow_region) ); 1.2392 + 1.2393 + if (stopped()) { 1.2394 + // There is no slow path. 1.2395 + result_rgn->init_req(slow_result_path, top()); 1.2396 + result_val->init_req(slow_result_path, top()); 1.2397 + } else { 1.2398 + // non-virtual because it is a private non-static 1.2399 + CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_isInterrupted); 1.2400 + 1.2401 + Node* slow_val = set_results_for_java_call(slow_call); 1.2402 + // this->control() comes from set_results_for_java_call 1.2403 + 1.2404 + // If we know that the result of the slow call will be true, tell the optimizer! 1.2405 + if (known_current_thread) slow_val = intcon(1); 1.2406 + 1.2407 + Node* fast_io = slow_call->in(TypeFunc::I_O); 1.2408 + Node* fast_mem = slow_call->in(TypeFunc::Memory); 1.2409 + // These two phis are pre-filled with copies of of the fast IO and Memory 1.2410 + Node* io_phi = PhiNode::make(result_rgn, fast_io, Type::ABIO); 1.2411 + Node* mem_phi = PhiNode::make(result_rgn, fast_mem, Type::MEMORY, TypePtr::BOTTOM); 1.2412 + 1.2413 + result_rgn->init_req(slow_result_path, control()); 1.2414 + io_phi ->init_req(slow_result_path, i_o()); 1.2415 + mem_phi ->init_req(slow_result_path, reset_memory()); 1.2416 + result_val->init_req(slow_result_path, slow_val); 1.2417 + 1.2418 + set_all_memory( _gvn.transform(mem_phi) ); 1.2419 + set_i_o( _gvn.transform(io_phi) ); 1.2420 + } 1.2421 + 1.2422 + push_result(result_rgn, result_val); 1.2423 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.2424 + 1.2425 + return true; 1.2426 +} 1.2427 + 1.2428 +//---------------------------load_mirror_from_klass---------------------------- 1.2429 +// Given a klass oop, load its java mirror (a java.lang.Class oop). 1.2430 +Node* LibraryCallKit::load_mirror_from_klass(Node* klass) { 1.2431 + Node* p = basic_plus_adr(klass, Klass::java_mirror_offset_in_bytes() + sizeof(oopDesc)); 1.2432 + return make_load(NULL, p, TypeInstPtr::MIRROR, T_OBJECT); 1.2433 +} 1.2434 + 1.2435 +//-----------------------load_klass_from_mirror_common------------------------- 1.2436 +// Given a java mirror (a java.lang.Class oop), load its corresponding klass oop. 1.2437 +// Test the klass oop for null (signifying a primitive Class like Integer.TYPE), 1.2438 +// and branch to the given path on the region. 1.2439 +// If never_see_null, take an uncommon trap on null, so we can optimistically 1.2440 +// compile for the non-null case. 1.2441 +// If the region is NULL, force never_see_null = true. 1.2442 +Node* LibraryCallKit::load_klass_from_mirror_common(Node* mirror, 1.2443 + bool never_see_null, 1.2444 + int nargs, 1.2445 + RegionNode* region, 1.2446 + int null_path, 1.2447 + int offset) { 1.2448 + if (region == NULL) never_see_null = true; 1.2449 + Node* p = basic_plus_adr(mirror, offset); 1.2450 + const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL; 1.2451 + Node* kls = _gvn.transform(new (C, 3) LoadKlassNode(0, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type)); 1.2452 + _sp += nargs; // any deopt will start just before call to enclosing method 1.2453 + Node* null_ctl = top(); 1.2454 + kls = null_check_oop(kls, &null_ctl, never_see_null); 1.2455 + if (region != NULL) { 1.2456 + // Set region->in(null_path) if the mirror is a primitive (e.g, int.class). 1.2457 + region->init_req(null_path, null_ctl); 1.2458 + } else { 1.2459 + assert(null_ctl == top(), "no loose ends"); 1.2460 + } 1.2461 + _sp -= nargs; 1.2462 + return kls; 1.2463 +} 1.2464 + 1.2465 +//--------------------(inline_native_Class_query helpers)--------------------- 1.2466 +// Use this for JVM_ACC_INTERFACE, JVM_ACC_IS_CLONEABLE, JVM_ACC_HAS_FINALIZER. 1.2467 +// Fall through if (mods & mask) == bits, take the guard otherwise. 1.2468 +Node* LibraryCallKit::generate_access_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) { 1.2469 + // Branch around if the given klass has the given modifier bit set. 1.2470 + // Like generate_guard, adds a new path onto the region. 1.2471 + Node* modp = basic_plus_adr(kls, Klass::access_flags_offset_in_bytes() + sizeof(oopDesc)); 1.2472 + Node* mods = make_load(NULL, modp, TypeInt::INT, T_INT); 1.2473 + Node* mask = intcon(modifier_mask); 1.2474 + Node* bits = intcon(modifier_bits); 1.2475 + Node* mbit = _gvn.transform( new (C, 3) AndINode(mods, mask) ); 1.2476 + Node* cmp = _gvn.transform( new (C, 3) CmpINode(mbit, bits) ); 1.2477 + Node* bol = _gvn.transform( new (C, 2) BoolNode(cmp, BoolTest::ne) ); 1.2478 + return generate_fair_guard(bol, region); 1.2479 +} 1.2480 +Node* LibraryCallKit::generate_interface_guard(Node* kls, RegionNode* region) { 1.2481 + return generate_access_flags_guard(kls, JVM_ACC_INTERFACE, 0, region); 1.2482 +} 1.2483 + 1.2484 +//-------------------------inline_native_Class_query------------------- 1.2485 +bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) { 1.2486 + int nargs = 1+0; // just the Class mirror, in most cases 1.2487 + const Type* return_type = TypeInt::BOOL; 1.2488 + Node* prim_return_value = top(); // what happens if it's a primitive class? 1.2489 + bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 1.2490 + bool expect_prim = false; // most of these guys expect to work on refs 1.2491 + 1.2492 + enum { _normal_path = 1, _prim_path = 2, PATH_LIMIT }; 1.2493 + 1.2494 + switch (id) { 1.2495 + case vmIntrinsics::_isInstance: 1.2496 + nargs = 1+1; // the Class mirror, plus the object getting queried about 1.2497 + // nothing is an instance of a primitive type 1.2498 + prim_return_value = intcon(0); 1.2499 + break; 1.2500 + case vmIntrinsics::_getModifiers: 1.2501 + prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC); 1.2502 + assert(is_power_of_2((int)JVM_ACC_WRITTEN_FLAGS+1), "change next line"); 1.2503 + return_type = TypeInt::make(0, JVM_ACC_WRITTEN_FLAGS, Type::WidenMin); 1.2504 + break; 1.2505 + case vmIntrinsics::_isInterface: 1.2506 + prim_return_value = intcon(0); 1.2507 + break; 1.2508 + case vmIntrinsics::_isArray: 1.2509 + prim_return_value = intcon(0); 1.2510 + expect_prim = true; // cf. ObjectStreamClass.getClassSignature 1.2511 + break; 1.2512 + case vmIntrinsics::_isPrimitive: 1.2513 + prim_return_value = intcon(1); 1.2514 + expect_prim = true; // obviously 1.2515 + break; 1.2516 + case vmIntrinsics::_getSuperclass: 1.2517 + prim_return_value = null(); 1.2518 + return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR); 1.2519 + break; 1.2520 + case vmIntrinsics::_getComponentType: 1.2521 + prim_return_value = null(); 1.2522 + return_type = TypeInstPtr::MIRROR->cast_to_ptr_type(TypePtr::BotPTR); 1.2523 + break; 1.2524 + case vmIntrinsics::_getClassAccessFlags: 1.2525 + prim_return_value = intcon(JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC); 1.2526 + return_type = TypeInt::INT; // not bool! 6297094 1.2527 + break; 1.2528 + default: 1.2529 + ShouldNotReachHere(); 1.2530 + } 1.2531 + 1.2532 + Node* mirror = argument(0); 1.2533 + Node* obj = (nargs <= 1)? top(): argument(1); 1.2534 + 1.2535 + const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr(); 1.2536 + if (mirror_con == NULL) return false; // cannot happen? 1.2537 + 1.2538 +#ifndef PRODUCT 1.2539 + if (PrintIntrinsics || PrintInlining || PrintOptoInlining) { 1.2540 + ciType* k = mirror_con->java_mirror_type(); 1.2541 + if (k) { 1.2542 + tty->print("Inlining %s on constant Class ", vmIntrinsics::name_at(intrinsic_id())); 1.2543 + k->print_name(); 1.2544 + tty->cr(); 1.2545 + } 1.2546 + } 1.2547 +#endif 1.2548 + 1.2549 + // Null-check the mirror, and the mirror's klass ptr (in case it is a primitive). 1.2550 + RegionNode* region = new (C, PATH_LIMIT) RegionNode(PATH_LIMIT); 1.2551 + record_for_igvn(region); 1.2552 + PhiNode* phi = new (C, PATH_LIMIT) PhiNode(region, return_type); 1.2553 + 1.2554 + // The mirror will never be null of Reflection.getClassAccessFlags, however 1.2555 + // it may be null for Class.isInstance or Class.getModifiers. Throw a NPE 1.2556 + // if it is. See bug 4774291. 1.2557 + 1.2558 + // For Reflection.getClassAccessFlags(), the null check occurs in 1.2559 + // the wrong place; see inline_unsafe_access(), above, for a similar 1.2560 + // situation. 1.2561 + _sp += nargs; // set original stack for use by uncommon_trap 1.2562 + mirror = do_null_check(mirror, T_OBJECT); 1.2563 + _sp -= nargs; 1.2564 + // If mirror or obj is dead, only null-path is taken. 1.2565 + if (stopped()) return true; 1.2566 + 1.2567 + if (expect_prim) never_see_null = false; // expect nulls (meaning prims) 1.2568 + 1.2569 + // Now load the mirror's klass metaobject, and null-check it. 1.2570 + // Side-effects region with the control path if the klass is null. 1.2571 + Node* kls = load_klass_from_mirror(mirror, never_see_null, nargs, 1.2572 + region, _prim_path); 1.2573 + // If kls is null, we have a primitive mirror. 1.2574 + phi->init_req(_prim_path, prim_return_value); 1.2575 + if (stopped()) { push_result(region, phi); return true; } 1.2576 + 1.2577 + Node* p; // handy temp 1.2578 + Node* null_ctl; 1.2579 + 1.2580 + // Now that we have the non-null klass, we can perform the real query. 1.2581 + // For constant classes, the query will constant-fold in LoadNode::Value. 1.2582 + Node* query_value = top(); 1.2583 + switch (id) { 1.2584 + case vmIntrinsics::_isInstance: 1.2585 + // nothing is an instance of a primitive type 1.2586 + query_value = gen_instanceof(obj, kls); 1.2587 + break; 1.2588 + 1.2589 + case vmIntrinsics::_getModifiers: 1.2590 + p = basic_plus_adr(kls, Klass::modifier_flags_offset_in_bytes() + sizeof(oopDesc)); 1.2591 + query_value = make_load(NULL, p, TypeInt::INT, T_INT); 1.2592 + break; 1.2593 + 1.2594 + case vmIntrinsics::_isInterface: 1.2595 + // (To verify this code sequence, check the asserts in JVM_IsInterface.) 1.2596 + if (generate_interface_guard(kls, region) != NULL) 1.2597 + // A guard was added. If the guard is taken, it was an interface. 1.2598 + phi->add_req(intcon(1)); 1.2599 + // If we fall through, it's a plain class. 1.2600 + query_value = intcon(0); 1.2601 + break; 1.2602 + 1.2603 + case vmIntrinsics::_isArray: 1.2604 + // (To verify this code sequence, check the asserts in JVM_IsArrayClass.) 1.2605 + if (generate_array_guard(kls, region) != NULL) 1.2606 + // A guard was added. If the guard is taken, it was an array. 1.2607 + phi->add_req(intcon(1)); 1.2608 + // If we fall through, it's a plain class. 1.2609 + query_value = intcon(0); 1.2610 + break; 1.2611 + 1.2612 + case vmIntrinsics::_isPrimitive: 1.2613 + query_value = intcon(0); // "normal" path produces false 1.2614 + break; 1.2615 + 1.2616 + case vmIntrinsics::_getSuperclass: 1.2617 + // The rules here are somewhat unfortunate, but we can still do better 1.2618 + // with random logic than with a JNI call. 1.2619 + // Interfaces store null or Object as _super, but must report null. 1.2620 + // Arrays store an intermediate super as _super, but must report Object. 1.2621 + // Other types can report the actual _super. 1.2622 + // (To verify this code sequence, check the asserts in JVM_IsInterface.) 1.2623 + if (generate_interface_guard(kls, region) != NULL) 1.2624 + // A guard was added. If the guard is taken, it was an interface. 1.2625 + phi->add_req(null()); 1.2626 + if (generate_array_guard(kls, region) != NULL) 1.2627 + // A guard was added. If the guard is taken, it was an array. 1.2628 + phi->add_req(makecon(TypeInstPtr::make(env()->Object_klass()->java_mirror()))); 1.2629 + // If we fall through, it's a plain class. Get its _super. 1.2630 + p = basic_plus_adr(kls, Klass::super_offset_in_bytes() + sizeof(oopDesc)); 1.2631 + kls = _gvn.transform(new (C, 3) LoadKlassNode(0, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeKlassPtr::OBJECT_OR_NULL)); 1.2632 + null_ctl = top(); 1.2633 + kls = null_check_oop(kls, &null_ctl); 1.2634 + if (null_ctl != top()) { 1.2635 + // If the guard is taken, Object.superClass is null (both klass and mirror). 1.2636 + region->add_req(null_ctl); 1.2637 + phi ->add_req(null()); 1.2638 + } 1.2639 + if (!stopped()) { 1.2640 + query_value = load_mirror_from_klass(kls); 1.2641 + } 1.2642 + break; 1.2643 + 1.2644 + case vmIntrinsics::_getComponentType: 1.2645 + if (generate_array_guard(kls, region) != NULL) { 1.2646 + // Be sure to pin the oop load to the guard edge just created: 1.2647 + Node* is_array_ctrl = region->in(region->req()-1); 1.2648 + Node* cma = basic_plus_adr(kls, in_bytes(arrayKlass::component_mirror_offset()) + sizeof(oopDesc)); 1.2649 + Node* cmo = make_load(is_array_ctrl, cma, TypeInstPtr::MIRROR, T_OBJECT); 1.2650 + phi->add_req(cmo); 1.2651 + } 1.2652 + query_value = null(); // non-array case is null 1.2653 + break; 1.2654 + 1.2655 + case vmIntrinsics::_getClassAccessFlags: 1.2656 + p = basic_plus_adr(kls, Klass::access_flags_offset_in_bytes() + sizeof(oopDesc)); 1.2657 + query_value = make_load(NULL, p, TypeInt::INT, T_INT); 1.2658 + break; 1.2659 + 1.2660 + default: 1.2661 + ShouldNotReachHere(); 1.2662 + } 1.2663 + 1.2664 + // Fall-through is the normal case of a query to a real class. 1.2665 + phi->init_req(1, query_value); 1.2666 + region->init_req(1, control()); 1.2667 + 1.2668 + push_result(region, phi); 1.2669 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.2670 + 1.2671 + return true; 1.2672 +} 1.2673 + 1.2674 +//--------------------------inline_native_subtype_check------------------------ 1.2675 +// This intrinsic takes the JNI calls out of the heart of 1.2676 +// UnsafeFieldAccessorImpl.set, which improves Field.set, readObject, etc. 1.2677 +bool LibraryCallKit::inline_native_subtype_check() { 1.2678 + int nargs = 1+1; // the Class mirror, plus the other class getting examined 1.2679 + 1.2680 + // Pull both arguments off the stack. 1.2681 + Node* args[2]; // two java.lang.Class mirrors: superc, subc 1.2682 + args[0] = argument(0); 1.2683 + args[1] = argument(1); 1.2684 + Node* klasses[2]; // corresponding Klasses: superk, subk 1.2685 + klasses[0] = klasses[1] = top(); 1.2686 + 1.2687 + enum { 1.2688 + // A full decision tree on {superc is prim, subc is prim}: 1.2689 + _prim_0_path = 1, // {P,N} => false 1.2690 + // {P,P} & superc!=subc => false 1.2691 + _prim_same_path, // {P,P} & superc==subc => true 1.2692 + _prim_1_path, // {N,P} => false 1.2693 + _ref_subtype_path, // {N,N} & subtype check wins => true 1.2694 + _both_ref_path, // {N,N} & subtype check loses => false 1.2695 + PATH_LIMIT 1.2696 + }; 1.2697 + 1.2698 + RegionNode* region = new (C, PATH_LIMIT) RegionNode(PATH_LIMIT); 1.2699 + Node* phi = new (C, PATH_LIMIT) PhiNode(region, TypeInt::BOOL); 1.2700 + record_for_igvn(region); 1.2701 + 1.2702 + const TypePtr* adr_type = TypeRawPtr::BOTTOM; // memory type of loads 1.2703 + const TypeKlassPtr* kls_type = TypeKlassPtr::OBJECT_OR_NULL; 1.2704 + int class_klass_offset = java_lang_Class::klass_offset_in_bytes(); 1.2705 + 1.2706 + // First null-check both mirrors and load each mirror's klass metaobject. 1.2707 + int which_arg; 1.2708 + for (which_arg = 0; which_arg <= 1; which_arg++) { 1.2709 + Node* arg = args[which_arg]; 1.2710 + _sp += nargs; // set original stack for use by uncommon_trap 1.2711 + arg = do_null_check(arg, T_OBJECT); 1.2712 + _sp -= nargs; 1.2713 + if (stopped()) break; 1.2714 + args[which_arg] = _gvn.transform(arg); 1.2715 + 1.2716 + Node* p = basic_plus_adr(arg, class_klass_offset); 1.2717 + Node* kls = new (C, 3) LoadKlassNode(0, immutable_memory(), p, adr_type, kls_type); 1.2718 + klasses[which_arg] = _gvn.transform(kls); 1.2719 + } 1.2720 + 1.2721 + // Having loaded both klasses, test each for null. 1.2722 + bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 1.2723 + for (which_arg = 0; which_arg <= 1; which_arg++) { 1.2724 + Node* kls = klasses[which_arg]; 1.2725 + Node* null_ctl = top(); 1.2726 + _sp += nargs; // set original stack for use by uncommon_trap 1.2727 + kls = null_check_oop(kls, &null_ctl, never_see_null); 1.2728 + _sp -= nargs; 1.2729 + int prim_path = (which_arg == 0 ? _prim_0_path : _prim_1_path); 1.2730 + region->init_req(prim_path, null_ctl); 1.2731 + if (stopped()) break; 1.2732 + klasses[which_arg] = kls; 1.2733 + } 1.2734 + 1.2735 + if (!stopped()) { 1.2736 + // now we have two reference types, in klasses[0..1] 1.2737 + Node* subk = klasses[1]; // the argument to isAssignableFrom 1.2738 + Node* superk = klasses[0]; // the receiver 1.2739 + region->set_req(_both_ref_path, gen_subtype_check(subk, superk)); 1.2740 + // now we have a successful reference subtype check 1.2741 + region->set_req(_ref_subtype_path, control()); 1.2742 + } 1.2743 + 1.2744 + // If both operands are primitive (both klasses null), then 1.2745 + // we must return true when they are identical primitives. 1.2746 + // It is convenient to test this after the first null klass check. 1.2747 + set_control(region->in(_prim_0_path)); // go back to first null check 1.2748 + if (!stopped()) { 1.2749 + // Since superc is primitive, make a guard for the superc==subc case. 1.2750 + Node* cmp_eq = _gvn.transform( new (C, 3) CmpPNode(args[0], args[1]) ); 1.2751 + Node* bol_eq = _gvn.transform( new (C, 2) BoolNode(cmp_eq, BoolTest::eq) ); 1.2752 + generate_guard(bol_eq, region, PROB_FAIR); 1.2753 + if (region->req() == PATH_LIMIT+1) { 1.2754 + // A guard was added. If the added guard is taken, superc==subc. 1.2755 + region->swap_edges(PATH_LIMIT, _prim_same_path); 1.2756 + region->del_req(PATH_LIMIT); 1.2757 + } 1.2758 + region->set_req(_prim_0_path, control()); // Not equal after all. 1.2759 + } 1.2760 + 1.2761 + // these are the only paths that produce 'true': 1.2762 + phi->set_req(_prim_same_path, intcon(1)); 1.2763 + phi->set_req(_ref_subtype_path, intcon(1)); 1.2764 + 1.2765 + // pull together the cases: 1.2766 + assert(region->req() == PATH_LIMIT, "sane region"); 1.2767 + for (uint i = 1; i < region->req(); i++) { 1.2768 + Node* ctl = region->in(i); 1.2769 + if (ctl == NULL || ctl == top()) { 1.2770 + region->set_req(i, top()); 1.2771 + phi ->set_req(i, top()); 1.2772 + } else if (phi->in(i) == NULL) { 1.2773 + phi->set_req(i, intcon(0)); // all other paths produce 'false' 1.2774 + } 1.2775 + } 1.2776 + 1.2777 + set_control(_gvn.transform(region)); 1.2778 + push(_gvn.transform(phi)); 1.2779 + 1.2780 + return true; 1.2781 +} 1.2782 + 1.2783 +//---------------------generate_array_guard_common------------------------ 1.2784 +Node* LibraryCallKit::generate_array_guard_common(Node* kls, RegionNode* region, 1.2785 + bool obj_array, bool not_array) { 1.2786 + // If obj_array/non_array==false/false: 1.2787 + // Branch around if the given klass is in fact an array (either obj or prim). 1.2788 + // If obj_array/non_array==false/true: 1.2789 + // Branch around if the given klass is not an array klass of any kind. 1.2790 + // If obj_array/non_array==true/true: 1.2791 + // Branch around if the kls is not an oop array (kls is int[], String, etc.) 1.2792 + // If obj_array/non_array==true/false: 1.2793 + // Branch around if the kls is an oop array (Object[] or subtype) 1.2794 + // 1.2795 + // Like generate_guard, adds a new path onto the region. 1.2796 + jint layout_con = 0; 1.2797 + Node* layout_val = get_layout_helper(kls, layout_con); 1.2798 + if (layout_val == NULL) { 1.2799 + bool query = (obj_array 1.2800 + ? Klass::layout_helper_is_objArray(layout_con) 1.2801 + : Klass::layout_helper_is_javaArray(layout_con)); 1.2802 + if (query == not_array) { 1.2803 + return NULL; // never a branch 1.2804 + } else { // always a branch 1.2805 + Node* always_branch = control(); 1.2806 + if (region != NULL) 1.2807 + region->add_req(always_branch); 1.2808 + set_control(top()); 1.2809 + return always_branch; 1.2810 + } 1.2811 + } 1.2812 + // Now test the correct condition. 1.2813 + jint nval = (obj_array 1.2814 + ? ((jint)Klass::_lh_array_tag_type_value 1.2815 + << Klass::_lh_array_tag_shift) 1.2816 + : Klass::_lh_neutral_value); 1.2817 + Node* cmp = _gvn.transform( new(C, 3) CmpINode(layout_val, intcon(nval)) ); 1.2818 + BoolTest::mask btest = BoolTest::lt; // correct for testing is_[obj]array 1.2819 + // invert the test if we are looking for a non-array 1.2820 + if (not_array) btest = BoolTest(btest).negate(); 1.2821 + Node* bol = _gvn.transform( new(C, 2) BoolNode(cmp, btest) ); 1.2822 + return generate_fair_guard(bol, region); 1.2823 +} 1.2824 + 1.2825 + 1.2826 +//-----------------------inline_native_newArray-------------------------- 1.2827 +bool LibraryCallKit::inline_native_newArray() { 1.2828 + int nargs = 2; 1.2829 + Node* mirror = argument(0); 1.2830 + Node* count_val = argument(1); 1.2831 + 1.2832 + _sp += nargs; // set original stack for use by uncommon_trap 1.2833 + mirror = do_null_check(mirror, T_OBJECT); 1.2834 + _sp -= nargs; 1.2835 + 1.2836 + enum { _normal_path = 1, _slow_path = 2, PATH_LIMIT }; 1.2837 + RegionNode* result_reg = new(C, PATH_LIMIT) RegionNode(PATH_LIMIT); 1.2838 + PhiNode* result_val = new(C, PATH_LIMIT) PhiNode(result_reg, 1.2839 + TypeInstPtr::NOTNULL); 1.2840 + PhiNode* result_io = new(C, PATH_LIMIT) PhiNode(result_reg, Type::ABIO); 1.2841 + PhiNode* result_mem = new(C, PATH_LIMIT) PhiNode(result_reg, Type::MEMORY, 1.2842 + TypePtr::BOTTOM); 1.2843 + 1.2844 + bool never_see_null = !too_many_traps(Deoptimization::Reason_null_check); 1.2845 + Node* klass_node = load_array_klass_from_mirror(mirror, never_see_null, 1.2846 + nargs, 1.2847 + result_reg, _slow_path); 1.2848 + Node* normal_ctl = control(); 1.2849 + Node* no_array_ctl = result_reg->in(_slow_path); 1.2850 + 1.2851 + // Generate code for the slow case. We make a call to newArray(). 1.2852 + set_control(no_array_ctl); 1.2853 + if (!stopped()) { 1.2854 + // Either the input type is void.class, or else the 1.2855 + // array klass has not yet been cached. Either the 1.2856 + // ensuing call will throw an exception, or else it 1.2857 + // will cache the array klass for next time. 1.2858 + PreserveJVMState pjvms(this); 1.2859 + CallJavaNode* slow_call = generate_method_call_static(vmIntrinsics::_newArray); 1.2860 + Node* slow_result = set_results_for_java_call(slow_call); 1.2861 + // this->control() comes from set_results_for_java_call 1.2862 + result_reg->set_req(_slow_path, control()); 1.2863 + result_val->set_req(_slow_path, slow_result); 1.2864 + result_io ->set_req(_slow_path, i_o()); 1.2865 + result_mem->set_req(_slow_path, reset_memory()); 1.2866 + } 1.2867 + 1.2868 + set_control(normal_ctl); 1.2869 + if (!stopped()) { 1.2870 + // Normal case: The array type has been cached in the java.lang.Class. 1.2871 + // The following call works fine even if the array type is polymorphic. 1.2872 + // It could be a dynamic mix of int[], boolean[], Object[], etc. 1.2873 + _sp += nargs; // set original stack for use by uncommon_trap 1.2874 + Node* obj = new_array(klass_node, count_val); 1.2875 + _sp -= nargs; 1.2876 + result_reg->init_req(_normal_path, control()); 1.2877 + result_val->init_req(_normal_path, obj); 1.2878 + result_io ->init_req(_normal_path, i_o()); 1.2879 + result_mem->init_req(_normal_path, reset_memory()); 1.2880 + } 1.2881 + 1.2882 + // Return the combined state. 1.2883 + set_i_o( _gvn.transform(result_io) ); 1.2884 + set_all_memory( _gvn.transform(result_mem) ); 1.2885 + push_result(result_reg, result_val); 1.2886 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.2887 + 1.2888 + return true; 1.2889 +} 1.2890 + 1.2891 +//----------------------inline_native_getLength-------------------------- 1.2892 +bool LibraryCallKit::inline_native_getLength() { 1.2893 + if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 1.2894 + 1.2895 + int nargs = 1; 1.2896 + Node* array = argument(0); 1.2897 + 1.2898 + _sp += nargs; // set original stack for use by uncommon_trap 1.2899 + array = do_null_check(array, T_OBJECT); 1.2900 + _sp -= nargs; 1.2901 + 1.2902 + // If array is dead, only null-path is taken. 1.2903 + if (stopped()) return true; 1.2904 + 1.2905 + // Deoptimize if it is a non-array. 1.2906 + Node* non_array = generate_non_array_guard(load_object_klass(array), NULL); 1.2907 + 1.2908 + if (non_array != NULL) { 1.2909 + PreserveJVMState pjvms(this); 1.2910 + set_control(non_array); 1.2911 + _sp += nargs; // push the arguments back on the stack 1.2912 + uncommon_trap(Deoptimization::Reason_intrinsic, 1.2913 + Deoptimization::Action_maybe_recompile); 1.2914 + } 1.2915 + 1.2916 + // If control is dead, only non-array-path is taken. 1.2917 + if (stopped()) return true; 1.2918 + 1.2919 + // The works fine even if the array type is polymorphic. 1.2920 + // It could be a dynamic mix of int[], boolean[], Object[], etc. 1.2921 + push( load_array_length(array) ); 1.2922 + 1.2923 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.2924 + 1.2925 + return true; 1.2926 +} 1.2927 + 1.2928 +//------------------------inline_array_copyOf---------------------------- 1.2929 +bool LibraryCallKit::inline_array_copyOf(bool is_copyOfRange) { 1.2930 + if (too_many_traps(Deoptimization::Reason_intrinsic)) return false; 1.2931 + 1.2932 + // Restore the stack and pop off the arguments. 1.2933 + int nargs = 3 + (is_copyOfRange? 1: 0); 1.2934 + Node* original = argument(0); 1.2935 + Node* start = is_copyOfRange? argument(1): intcon(0); 1.2936 + Node* end = is_copyOfRange? argument(2): argument(1); 1.2937 + Node* array_type_mirror = is_copyOfRange? argument(3): argument(2); 1.2938 + 1.2939 + _sp += nargs; // set original stack for use by uncommon_trap 1.2940 + array_type_mirror = do_null_check(array_type_mirror, T_OBJECT); 1.2941 + original = do_null_check(original, T_OBJECT); 1.2942 + _sp -= nargs; 1.2943 + 1.2944 + // Check if a null path was taken unconditionally. 1.2945 + if (stopped()) return true; 1.2946 + 1.2947 + Node* orig_length = load_array_length(original); 1.2948 + 1.2949 + Node* klass_node = load_klass_from_mirror(array_type_mirror, false, nargs, 1.2950 + NULL, 0); 1.2951 + _sp += nargs; // set original stack for use by uncommon_trap 1.2952 + klass_node = do_null_check(klass_node, T_OBJECT); 1.2953 + _sp -= nargs; 1.2954 + 1.2955 + RegionNode* bailout = new (C, 1) RegionNode(1); 1.2956 + record_for_igvn(bailout); 1.2957 + 1.2958 + // Despite the generic type of Arrays.copyOf, the mirror might be int, int[], etc. 1.2959 + // Bail out if that is so. 1.2960 + Node* not_objArray = generate_non_objArray_guard(klass_node, bailout); 1.2961 + if (not_objArray != NULL) { 1.2962 + // Improve the klass node's type from the new optimistic assumption: 1.2963 + ciKlass* ak = ciArrayKlass::make(env()->Object_klass()); 1.2964 + const Type* akls = TypeKlassPtr::make(TypePtr::NotNull, ak, 0/*offset*/); 1.2965 + Node* cast = new (C, 2) CastPPNode(klass_node, akls); 1.2966 + cast->init_req(0, control()); 1.2967 + klass_node = _gvn.transform(cast); 1.2968 + } 1.2969 + 1.2970 + // Bail out if either start or end is negative. 1.2971 + generate_negative_guard(start, bailout, &start); 1.2972 + generate_negative_guard(end, bailout, &end); 1.2973 + 1.2974 + Node* length = end; 1.2975 + if (_gvn.type(start) != TypeInt::ZERO) { 1.2976 + length = _gvn.transform( new (C, 3) SubINode(end, start) ); 1.2977 + } 1.2978 + 1.2979 + // Bail out if length is negative. 1.2980 + // ...Not needed, since the new_array will throw the right exception. 1.2981 + //generate_negative_guard(length, bailout, &length); 1.2982 + 1.2983 + if (bailout->req() > 1) { 1.2984 + PreserveJVMState pjvms(this); 1.2985 + set_control( _gvn.transform(bailout) ); 1.2986 + _sp += nargs; // push the arguments back on the stack 1.2987 + uncommon_trap(Deoptimization::Reason_intrinsic, 1.2988 + Deoptimization::Action_maybe_recompile); 1.2989 + } 1.2990 + 1.2991 + if (!stopped()) { 1.2992 + // How many elements will we copy from the original? 1.2993 + // The answer is MinI(orig_length - start, length). 1.2994 + Node* orig_tail = _gvn.transform( new(C, 3) SubINode(orig_length, start) ); 1.2995 + Node* moved = generate_min_max(vmIntrinsics::_min, orig_tail, length); 1.2996 + 1.2997 + _sp += nargs; // set original stack for use by uncommon_trap 1.2998 + Node* newcopy = new_array(klass_node, length); 1.2999 + _sp -= nargs; 1.3000 + 1.3001 + // Generate a direct call to the right arraycopy function(s). 1.3002 + // We know the copy is disjoint but we might not know if the 1.3003 + // oop stores need checking. 1.3004 + // Extreme case: Arrays.copyOf((Integer[])x, 10, String[].class). 1.3005 + // This will fail a store-check if x contains any non-nulls. 1.3006 + bool disjoint_bases = true; 1.3007 + bool length_never_negative = true; 1.3008 + generate_arraycopy(TypeAryPtr::OOPS, T_OBJECT, 1.3009 + original, start, newcopy, intcon(0), moved, 1.3010 + nargs, disjoint_bases, length_never_negative); 1.3011 + 1.3012 + push(newcopy); 1.3013 + } 1.3014 + 1.3015 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.3016 + 1.3017 + return true; 1.3018 +} 1.3019 + 1.3020 + 1.3021 +//----------------------generate_virtual_guard--------------------------- 1.3022 +// Helper for hashCode and clone. Peeks inside the vtable to avoid a call. 1.3023 +Node* LibraryCallKit::generate_virtual_guard(Node* obj_klass, 1.3024 + RegionNode* slow_region) { 1.3025 + ciMethod* method = callee(); 1.3026 + int vtable_index = method->vtable_index(); 1.3027 + // Get the methodOop out of the appropriate vtable entry. 1.3028 + int entry_offset = (instanceKlass::vtable_start_offset() + 1.3029 + vtable_index*vtableEntry::size()) * wordSize + 1.3030 + vtableEntry::method_offset_in_bytes(); 1.3031 + Node* entry_addr = basic_plus_adr(obj_klass, entry_offset); 1.3032 + Node* target_call = make_load(NULL, entry_addr, TypeInstPtr::NOTNULL, T_OBJECT); 1.3033 + 1.3034 + // Compare the target method with the expected method (e.g., Object.hashCode). 1.3035 + const TypeInstPtr* native_call_addr = TypeInstPtr::make(method); 1.3036 + 1.3037 + Node* native_call = makecon(native_call_addr); 1.3038 + Node* chk_native = _gvn.transform( new(C, 3) CmpPNode(target_call, native_call) ); 1.3039 + Node* test_native = _gvn.transform( new(C, 2) BoolNode(chk_native, BoolTest::ne) ); 1.3040 + 1.3041 + return generate_slow_guard(test_native, slow_region); 1.3042 +} 1.3043 + 1.3044 +//-----------------------generate_method_call---------------------------- 1.3045 +// Use generate_method_call to make a slow-call to the real 1.3046 +// method if the fast path fails. An alternative would be to 1.3047 +// use a stub like OptoRuntime::slow_arraycopy_Java. 1.3048 +// This only works for expanding the current library call, 1.3049 +// not another intrinsic. (E.g., don't use this for making an 1.3050 +// arraycopy call inside of the copyOf intrinsic.) 1.3051 +CallJavaNode* 1.3052 +LibraryCallKit::generate_method_call(vmIntrinsics::ID method_id, bool is_virtual, bool is_static) { 1.3053 + // When compiling the intrinsic method itself, do not use this technique. 1.3054 + guarantee(callee() != C->method(), "cannot make slow-call to self"); 1.3055 + 1.3056 + ciMethod* method = callee(); 1.3057 + // ensure the JVMS we have will be correct for this call 1.3058 + guarantee(method_id == method->intrinsic_id(), "must match"); 1.3059 + 1.3060 + const TypeFunc* tf = TypeFunc::make(method); 1.3061 + int tfdc = tf->domain()->cnt(); 1.3062 + CallJavaNode* slow_call; 1.3063 + if (is_static) { 1.3064 + assert(!is_virtual, ""); 1.3065 + slow_call = new(C, tfdc) CallStaticJavaNode(tf, 1.3066 + SharedRuntime::get_resolve_static_call_stub(), 1.3067 + method, bci()); 1.3068 + } else if (is_virtual) { 1.3069 + null_check_receiver(method); 1.3070 + int vtable_index = methodOopDesc::invalid_vtable_index; 1.3071 + if (UseInlineCaches) { 1.3072 + // Suppress the vtable call 1.3073 + } else { 1.3074 + // hashCode and clone are not a miranda methods, 1.3075 + // so the vtable index is fixed. 1.3076 + // No need to use the linkResolver to get it. 1.3077 + vtable_index = method->vtable_index(); 1.3078 + } 1.3079 + slow_call = new(C, tfdc) CallDynamicJavaNode(tf, 1.3080 + SharedRuntime::get_resolve_virtual_call_stub(), 1.3081 + method, vtable_index, bci()); 1.3082 + } else { // neither virtual nor static: opt_virtual 1.3083 + null_check_receiver(method); 1.3084 + slow_call = new(C, tfdc) CallStaticJavaNode(tf, 1.3085 + SharedRuntime::get_resolve_opt_virtual_call_stub(), 1.3086 + method, bci()); 1.3087 + slow_call->set_optimized_virtual(true); 1.3088 + } 1.3089 + set_arguments_for_java_call(slow_call); 1.3090 + set_edges_for_java_call(slow_call); 1.3091 + return slow_call; 1.3092 +} 1.3093 + 1.3094 + 1.3095 +//------------------------------inline_native_hashcode-------------------- 1.3096 +// Build special case code for calls to hashCode on an object. 1.3097 +bool LibraryCallKit::inline_native_hashcode(bool is_virtual, bool is_static) { 1.3098 + assert(is_static == callee()->is_static(), "correct intrinsic selection"); 1.3099 + assert(!(is_virtual && is_static), "either virtual, special, or static"); 1.3100 + 1.3101 + enum { _slow_path = 1, _fast_path, _null_path, PATH_LIMIT }; 1.3102 + 1.3103 + RegionNode* result_reg = new(C, PATH_LIMIT) RegionNode(PATH_LIMIT); 1.3104 + PhiNode* result_val = new(C, PATH_LIMIT) PhiNode(result_reg, 1.3105 + TypeInt::INT); 1.3106 + PhiNode* result_io = new(C, PATH_LIMIT) PhiNode(result_reg, Type::ABIO); 1.3107 + PhiNode* result_mem = new(C, PATH_LIMIT) PhiNode(result_reg, Type::MEMORY, 1.3108 + TypePtr::BOTTOM); 1.3109 + Node* obj = NULL; 1.3110 + if (!is_static) { 1.3111 + // Check for hashing null object 1.3112 + obj = null_check_receiver(callee()); 1.3113 + if (stopped()) return true; // unconditionally null 1.3114 + result_reg->init_req(_null_path, top()); 1.3115 + result_val->init_req(_null_path, top()); 1.3116 + } else { 1.3117 + // Do a null check, and return zero if null. 1.3118 + // System.identityHashCode(null) == 0 1.3119 + obj = argument(0); 1.3120 + Node* null_ctl = top(); 1.3121 + obj = null_check_oop(obj, &null_ctl); 1.3122 + result_reg->init_req(_null_path, null_ctl); 1.3123 + result_val->init_req(_null_path, _gvn.intcon(0)); 1.3124 + } 1.3125 + 1.3126 + // Unconditionally null? Then return right away. 1.3127 + if (stopped()) { 1.3128 + set_control( result_reg->in(_null_path) ); 1.3129 + if (!stopped()) 1.3130 + push( result_val ->in(_null_path) ); 1.3131 + return true; 1.3132 + } 1.3133 + 1.3134 + // After null check, get the object's klass. 1.3135 + Node* obj_klass = load_object_klass(obj); 1.3136 + 1.3137 + // This call may be virtual (invokevirtual) or bound (invokespecial). 1.3138 + // For each case we generate slightly different code. 1.3139 + 1.3140 + // We only go to the fast case code if we pass a number of guards. The 1.3141 + // paths which do not pass are accumulated in the slow_region. 1.3142 + RegionNode* slow_region = new (C, 1) RegionNode(1); 1.3143 + record_for_igvn(slow_region); 1.3144 + 1.3145 + // If this is a virtual call, we generate a funny guard. We pull out 1.3146 + // the vtable entry corresponding to hashCode() from the target object. 1.3147 + // If the target method which we are calling happens to be the native 1.3148 + // Object hashCode() method, we pass the guard. We do not need this 1.3149 + // guard for non-virtual calls -- the caller is known to be the native 1.3150 + // Object hashCode(). 1.3151 + if (is_virtual) { 1.3152 + generate_virtual_guard(obj_klass, slow_region); 1.3153 + } 1.3154 + 1.3155 + // Get the header out of the object, use LoadMarkNode when available 1.3156 + Node* header_addr = basic_plus_adr(obj, oopDesc::mark_offset_in_bytes()); 1.3157 + Node* header = make_load(NULL, header_addr, TypeRawPtr::BOTTOM, T_ADDRESS); 1.3158 + header = _gvn.transform( new (C, 2) CastP2XNode(NULL, header) ); 1.3159 + 1.3160 + // Test the header to see if it is unlocked. 1.3161 + Node *lock_mask = _gvn.MakeConX(markOopDesc::biased_lock_mask_in_place); 1.3162 + Node *lmasked_header = _gvn.transform( new (C, 3) AndXNode(header, lock_mask) ); 1.3163 + Node *unlocked_val = _gvn.MakeConX(markOopDesc::unlocked_value); 1.3164 + Node *chk_unlocked = _gvn.transform( new (C, 3) CmpXNode( lmasked_header, unlocked_val)); 1.3165 + Node *test_unlocked = _gvn.transform( new (C, 2) BoolNode( chk_unlocked, BoolTest::ne) ); 1.3166 + 1.3167 + generate_slow_guard(test_unlocked, slow_region); 1.3168 + 1.3169 + // Get the hash value and check to see that it has been properly assigned. 1.3170 + // We depend on hash_mask being at most 32 bits and avoid the use of 1.3171 + // hash_mask_in_place because it could be larger than 32 bits in a 64-bit 1.3172 + // vm: see markOop.hpp. 1.3173 + Node *hash_mask = _gvn.intcon(markOopDesc::hash_mask); 1.3174 + Node *hash_shift = _gvn.intcon(markOopDesc::hash_shift); 1.3175 + Node *hshifted_header= _gvn.transform( new (C, 3) URShiftXNode(header, hash_shift) ); 1.3176 + // This hack lets the hash bits live anywhere in the mark object now, as long 1.3177 + // as the shift drops the relevent bits into the low 32 bits. Note that 1.3178 + // Java spec says that HashCode is an int so there's no point in capturing 1.3179 + // an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build). 1.3180 + hshifted_header = ConvX2I(hshifted_header); 1.3181 + Node *hash_val = _gvn.transform( new (C, 3) AndINode(hshifted_header, hash_mask) ); 1.3182 + 1.3183 + Node *no_hash_val = _gvn.intcon(markOopDesc::no_hash); 1.3184 + Node *chk_assigned = _gvn.transform( new (C, 3) CmpINode( hash_val, no_hash_val)); 1.3185 + Node *test_assigned = _gvn.transform( new (C, 2) BoolNode( chk_assigned, BoolTest::eq) ); 1.3186 + 1.3187 + generate_slow_guard(test_assigned, slow_region); 1.3188 + 1.3189 + Node* init_mem = reset_memory(); 1.3190 + // fill in the rest of the null path: 1.3191 + result_io ->init_req(_null_path, i_o()); 1.3192 + result_mem->init_req(_null_path, init_mem); 1.3193 + 1.3194 + result_val->init_req(_fast_path, hash_val); 1.3195 + result_reg->init_req(_fast_path, control()); 1.3196 + result_io ->init_req(_fast_path, i_o()); 1.3197 + result_mem->init_req(_fast_path, init_mem); 1.3198 + 1.3199 + // Generate code for the slow case. We make a call to hashCode(). 1.3200 + set_control(_gvn.transform(slow_region)); 1.3201 + if (!stopped()) { 1.3202 + // No need for PreserveJVMState, because we're using up the present state. 1.3203 + set_all_memory(init_mem); 1.3204 + vmIntrinsics::ID hashCode_id = vmIntrinsics::_hashCode; 1.3205 + if (is_static) hashCode_id = vmIntrinsics::_identityHashCode; 1.3206 + CallJavaNode* slow_call = generate_method_call(hashCode_id, is_virtual, is_static); 1.3207 + Node* slow_result = set_results_for_java_call(slow_call); 1.3208 + // this->control() comes from set_results_for_java_call 1.3209 + result_reg->init_req(_slow_path, control()); 1.3210 + result_val->init_req(_slow_path, slow_result); 1.3211 + result_io ->set_req(_slow_path, i_o()); 1.3212 + result_mem ->set_req(_slow_path, reset_memory()); 1.3213 + } 1.3214 + 1.3215 + // Return the combined state. 1.3216 + set_i_o( _gvn.transform(result_io) ); 1.3217 + set_all_memory( _gvn.transform(result_mem) ); 1.3218 + push_result(result_reg, result_val); 1.3219 + 1.3220 + return true; 1.3221 +} 1.3222 + 1.3223 +//---------------------------inline_native_getClass---------------------------- 1.3224 +// Build special case code for calls to hashCode on an object. 1.3225 +bool LibraryCallKit::inline_native_getClass() { 1.3226 + Node* obj = null_check_receiver(callee()); 1.3227 + if (stopped()) return true; 1.3228 + push( load_mirror_from_klass(load_object_klass(obj)) ); 1.3229 + return true; 1.3230 +} 1.3231 + 1.3232 +//-----------------inline_native_Reflection_getCallerClass--------------------- 1.3233 +// In the presence of deep enough inlining, getCallerClass() becomes a no-op. 1.3234 +// 1.3235 +// NOTE that this code must perform the same logic as 1.3236 +// vframeStream::security_get_caller_frame in that it must skip 1.3237 +// Method.invoke() and auxiliary frames. 1.3238 + 1.3239 + 1.3240 + 1.3241 + 1.3242 +bool LibraryCallKit::inline_native_Reflection_getCallerClass() { 1.3243 + ciMethod* method = callee(); 1.3244 + 1.3245 +#ifndef PRODUCT 1.3246 + if ((PrintIntrinsics || PrintInlining || PrintOptoInlining) && Verbose) { 1.3247 + tty->print_cr("Attempting to inline sun.reflect.Reflection.getCallerClass"); 1.3248 + } 1.3249 +#endif 1.3250 + 1.3251 + debug_only(int saved_sp = _sp); 1.3252 + 1.3253 + // Argument words: (int depth) 1.3254 + int nargs = 1; 1.3255 + 1.3256 + _sp += nargs; 1.3257 + Node* caller_depth_node = pop(); 1.3258 + 1.3259 + assert(saved_sp == _sp, "must have correct argument count"); 1.3260 + 1.3261 + // The depth value must be a constant in order for the runtime call 1.3262 + // to be eliminated. 1.3263 + const TypeInt* caller_depth_type = _gvn.type(caller_depth_node)->isa_int(); 1.3264 + if (caller_depth_type == NULL || !caller_depth_type->is_con()) { 1.3265 +#ifndef PRODUCT 1.3266 + if ((PrintIntrinsics || PrintInlining || PrintOptoInlining) && Verbose) { 1.3267 + tty->print_cr(" Bailing out because caller depth was not a constant"); 1.3268 + } 1.3269 +#endif 1.3270 + return false; 1.3271 + } 1.3272 + // Note that the JVM state at this point does not include the 1.3273 + // getCallerClass() frame which we are trying to inline. The 1.3274 + // semantics of getCallerClass(), however, are that the "first" 1.3275 + // frame is the getCallerClass() frame, so we subtract one from the 1.3276 + // requested depth before continuing. We don't inline requests of 1.3277 + // getCallerClass(0). 1.3278 + int caller_depth = caller_depth_type->get_con() - 1; 1.3279 + if (caller_depth < 0) { 1.3280 +#ifndef PRODUCT 1.3281 + if ((PrintIntrinsics || PrintInlining || PrintOptoInlining) && Verbose) { 1.3282 + tty->print_cr(" Bailing out because caller depth was %d", caller_depth); 1.3283 + } 1.3284 +#endif 1.3285 + return false; 1.3286 + } 1.3287 + 1.3288 + if (!jvms()->has_method()) { 1.3289 +#ifndef PRODUCT 1.3290 + if ((PrintIntrinsics || PrintInlining || PrintOptoInlining) && Verbose) { 1.3291 + tty->print_cr(" Bailing out because intrinsic was inlined at top level"); 1.3292 + } 1.3293 +#endif 1.3294 + return false; 1.3295 + } 1.3296 + int _depth = jvms()->depth(); // cache call chain depth 1.3297 + 1.3298 + // Walk back up the JVM state to find the caller at the required 1.3299 + // depth. NOTE that this code must perform the same logic as 1.3300 + // vframeStream::security_get_caller_frame in that it must skip 1.3301 + // Method.invoke() and auxiliary frames. Note also that depth is 1.3302 + // 1-based (1 is the bottom of the inlining). 1.3303 + int inlining_depth = _depth; 1.3304 + JVMState* caller_jvms = NULL; 1.3305 + 1.3306 + if (inlining_depth > 0) { 1.3307 + caller_jvms = jvms(); 1.3308 + assert(caller_jvms = jvms()->of_depth(inlining_depth), "inlining_depth == our depth"); 1.3309 + do { 1.3310 + // The following if-tests should be performed in this order 1.3311 + if (is_method_invoke_or_aux_frame(caller_jvms)) { 1.3312 + // Skip a Method.invoke() or auxiliary frame 1.3313 + } else if (caller_depth > 0) { 1.3314 + // Skip real frame 1.3315 + --caller_depth; 1.3316 + } else { 1.3317 + // We're done: reached desired caller after skipping. 1.3318 + break; 1.3319 + } 1.3320 + caller_jvms = caller_jvms->caller(); 1.3321 + --inlining_depth; 1.3322 + } while (inlining_depth > 0); 1.3323 + } 1.3324 + 1.3325 + if (inlining_depth == 0) { 1.3326 +#ifndef PRODUCT 1.3327 + if ((PrintIntrinsics || PrintInlining || PrintOptoInlining) && Verbose) { 1.3328 + tty->print_cr(" Bailing out because caller depth (%d) exceeded inlining depth (%d)", caller_depth_type->get_con(), _depth); 1.3329 + tty->print_cr(" JVM state at this point:"); 1.3330 + for (int i = _depth; i >= 1; i--) { 1.3331 + tty->print_cr(" %d) %s", i, jvms()->of_depth(i)->method()->name()->as_utf8()); 1.3332 + } 1.3333 + } 1.3334 +#endif 1.3335 + return false; // Reached end of inlining 1.3336 + } 1.3337 + 1.3338 + // Acquire method holder as java.lang.Class 1.3339 + ciInstanceKlass* caller_klass = caller_jvms->method()->holder(); 1.3340 + ciInstance* caller_mirror = caller_klass->java_mirror(); 1.3341 + // Push this as a constant 1.3342 + push(makecon(TypeInstPtr::make(caller_mirror))); 1.3343 +#ifndef PRODUCT 1.3344 + if ((PrintIntrinsics || PrintInlining || PrintOptoInlining) && Verbose) { 1.3345 + tty->print_cr(" Succeeded: caller = %s.%s, caller depth = %d, depth = %d", caller_klass->name()->as_utf8(), caller_jvms->method()->name()->as_utf8(), caller_depth_type->get_con(), _depth); 1.3346 + tty->print_cr(" JVM state at this point:"); 1.3347 + for (int i = _depth; i >= 1; i--) { 1.3348 + tty->print_cr(" %d) %s", i, jvms()->of_depth(i)->method()->name()->as_utf8()); 1.3349 + } 1.3350 + } 1.3351 +#endif 1.3352 + return true; 1.3353 +} 1.3354 + 1.3355 +// Helper routine for above 1.3356 +bool LibraryCallKit::is_method_invoke_or_aux_frame(JVMState* jvms) { 1.3357 + // Is this the Method.invoke method itself? 1.3358 + if (jvms->method()->intrinsic_id() == vmIntrinsics::_invoke) 1.3359 + return true; 1.3360 + 1.3361 + // Is this a helper, defined somewhere underneath MethodAccessorImpl. 1.3362 + ciKlass* k = jvms->method()->holder(); 1.3363 + if (k->is_instance_klass()) { 1.3364 + ciInstanceKlass* ik = k->as_instance_klass(); 1.3365 + for (; ik != NULL; ik = ik->super()) { 1.3366 + if (ik->name() == ciSymbol::sun_reflect_MethodAccessorImpl() && 1.3367 + ik == env()->find_system_klass(ik->name())) { 1.3368 + return true; 1.3369 + } 1.3370 + } 1.3371 + } 1.3372 + 1.3373 + return false; 1.3374 +} 1.3375 + 1.3376 +static int value_field_offset = -1; // offset of the "value" field of AtomicLongCSImpl. This is needed by 1.3377 + // inline_native_AtomicLong_attemptUpdate() but it has no way of 1.3378 + // computing it since there is no lookup field by name function in the 1.3379 + // CI interface. This is computed and set by inline_native_AtomicLong_get(). 1.3380 + // Using a static variable here is safe even if we have multiple compilation 1.3381 + // threads because the offset is constant. At worst the same offset will be 1.3382 + // computed and stored multiple 1.3383 + 1.3384 +bool LibraryCallKit::inline_native_AtomicLong_get() { 1.3385 + // Restore the stack and pop off the argument 1.3386 + _sp+=1; 1.3387 + Node *obj = pop(); 1.3388 + 1.3389 + // get the offset of the "value" field. Since the CI interfaces 1.3390 + // does not provide a way to look up a field by name, we scan the bytecodes 1.3391 + // to get the field index. We expect the first 2 instructions of the method 1.3392 + // to be: 1.3393 + // 0 aload_0 1.3394 + // 1 getfield "value" 1.3395 + ciMethod* method = callee(); 1.3396 + if (value_field_offset == -1) 1.3397 + { 1.3398 + ciField* value_field; 1.3399 + ciBytecodeStream iter(method); 1.3400 + Bytecodes::Code bc = iter.next(); 1.3401 + 1.3402 + if ((bc != Bytecodes::_aload_0) && 1.3403 + ((bc != Bytecodes::_aload) || (iter.get_index() != 0))) 1.3404 + return false; 1.3405 + bc = iter.next(); 1.3406 + if (bc != Bytecodes::_getfield) 1.3407 + return false; 1.3408 + bool ignore; 1.3409 + value_field = iter.get_field(ignore); 1.3410 + value_field_offset = value_field->offset_in_bytes(); 1.3411 + } 1.3412 + 1.3413 + // Null check without removing any arguments. 1.3414 + _sp++; 1.3415 + obj = do_null_check(obj, T_OBJECT); 1.3416 + _sp--; 1.3417 + // Check for locking null object 1.3418 + if (stopped()) return true; 1.3419 + 1.3420 + Node *adr = basic_plus_adr(obj, obj, value_field_offset); 1.3421 + const TypePtr *adr_type = _gvn.type(adr)->is_ptr(); 1.3422 + int alias_idx = C->get_alias_index(adr_type); 1.3423 + 1.3424 + Node *result = _gvn.transform(new (C, 3) LoadLLockedNode(control(), memory(alias_idx), adr)); 1.3425 + 1.3426 + push_pair(result); 1.3427 + 1.3428 + return true; 1.3429 +} 1.3430 + 1.3431 +bool LibraryCallKit::inline_native_AtomicLong_attemptUpdate() { 1.3432 + // Restore the stack and pop off the arguments 1.3433 + _sp+=5; 1.3434 + Node *newVal = pop_pair(); 1.3435 + Node *oldVal = pop_pair(); 1.3436 + Node *obj = pop(); 1.3437 + 1.3438 + // we need the offset of the "value" field which was computed when 1.3439 + // inlining the get() method. Give up if we don't have it. 1.3440 + if (value_field_offset == -1) 1.3441 + return false; 1.3442 + 1.3443 + // Null check without removing any arguments. 1.3444 + _sp+=5; 1.3445 + obj = do_null_check(obj, T_OBJECT); 1.3446 + _sp-=5; 1.3447 + // Check for locking null object 1.3448 + if (stopped()) return true; 1.3449 + 1.3450 + Node *adr = basic_plus_adr(obj, obj, value_field_offset); 1.3451 + const TypePtr *adr_type = _gvn.type(adr)->is_ptr(); 1.3452 + int alias_idx = C->get_alias_index(adr_type); 1.3453 + 1.3454 + Node *result = _gvn.transform(new (C, 5) StoreLConditionalNode(control(), memory(alias_idx), adr, newVal, oldVal)); 1.3455 + Node *store_proj = _gvn.transform( new (C, 1) SCMemProjNode(result)); 1.3456 + set_memory(store_proj, alias_idx); 1.3457 + 1.3458 + push(result); 1.3459 + return true; 1.3460 +} 1.3461 + 1.3462 +bool LibraryCallKit::inline_fp_conversions(vmIntrinsics::ID id) { 1.3463 + // restore the arguments 1.3464 + _sp += arg_size(); 1.3465 + 1.3466 + switch (id) { 1.3467 + case vmIntrinsics::_floatToRawIntBits: 1.3468 + push(_gvn.transform( new (C, 2) MoveF2INode(pop()))); 1.3469 + break; 1.3470 + 1.3471 + case vmIntrinsics::_intBitsToFloat: 1.3472 + push(_gvn.transform( new (C, 2) MoveI2FNode(pop()))); 1.3473 + break; 1.3474 + 1.3475 + case vmIntrinsics::_doubleToRawLongBits: 1.3476 + push_pair(_gvn.transform( new (C, 2) MoveD2LNode(pop_pair()))); 1.3477 + break; 1.3478 + 1.3479 + case vmIntrinsics::_longBitsToDouble: 1.3480 + push_pair(_gvn.transform( new (C, 2) MoveL2DNode(pop_pair()))); 1.3481 + break; 1.3482 + 1.3483 + case vmIntrinsics::_doubleToLongBits: { 1.3484 + Node* value = pop_pair(); 1.3485 + 1.3486 + // two paths (plus control) merge in a wood 1.3487 + RegionNode *r = new (C, 3) RegionNode(3); 1.3488 + Node *phi = new (C, 3) PhiNode(r, TypeLong::LONG); 1.3489 + 1.3490 + Node *cmpisnan = _gvn.transform( new (C, 3) CmpDNode(value, value)); 1.3491 + // Build the boolean node 1.3492 + Node *bolisnan = _gvn.transform( new (C, 2) BoolNode( cmpisnan, BoolTest::ne ) ); 1.3493 + 1.3494 + // Branch either way. 1.3495 + // NaN case is less traveled, which makes all the difference. 1.3496 + IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 1.3497 + Node *opt_isnan = _gvn.transform(ifisnan); 1.3498 + assert( opt_isnan->is_If(), "Expect an IfNode"); 1.3499 + IfNode *opt_ifisnan = (IfNode*)opt_isnan; 1.3500 + Node *iftrue = _gvn.transform( new (C, 1) IfTrueNode(opt_ifisnan) ); 1.3501 + 1.3502 + set_control(iftrue); 1.3503 + 1.3504 + static const jlong nan_bits = CONST64(0x7ff8000000000000); 1.3505 + Node *slow_result = longcon(nan_bits); // return NaN 1.3506 + phi->init_req(1, _gvn.transform( slow_result )); 1.3507 + r->init_req(1, iftrue); 1.3508 + 1.3509 + // Else fall through 1.3510 + Node *iffalse = _gvn.transform( new (C, 1) IfFalseNode(opt_ifisnan) ); 1.3511 + set_control(iffalse); 1.3512 + 1.3513 + phi->init_req(2, _gvn.transform( new (C, 2) MoveD2LNode(value))); 1.3514 + r->init_req(2, iffalse); 1.3515 + 1.3516 + // Post merge 1.3517 + set_control(_gvn.transform(r)); 1.3518 + record_for_igvn(r); 1.3519 + 1.3520 + Node* result = _gvn.transform(phi); 1.3521 + assert(result->bottom_type()->isa_long(), "must be"); 1.3522 + push_pair(result); 1.3523 + 1.3524 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.3525 + 1.3526 + break; 1.3527 + } 1.3528 + 1.3529 + case vmIntrinsics::_floatToIntBits: { 1.3530 + Node* value = pop(); 1.3531 + 1.3532 + // two paths (plus control) merge in a wood 1.3533 + RegionNode *r = new (C, 3) RegionNode(3); 1.3534 + Node *phi = new (C, 3) PhiNode(r, TypeInt::INT); 1.3535 + 1.3536 + Node *cmpisnan = _gvn.transform( new (C, 3) CmpFNode(value, value)); 1.3537 + // Build the boolean node 1.3538 + Node *bolisnan = _gvn.transform( new (C, 2) BoolNode( cmpisnan, BoolTest::ne ) ); 1.3539 + 1.3540 + // Branch either way. 1.3541 + // NaN case is less traveled, which makes all the difference. 1.3542 + IfNode *ifisnan = create_and_xform_if(control(), bolisnan, PROB_STATIC_FREQUENT, COUNT_UNKNOWN); 1.3543 + Node *opt_isnan = _gvn.transform(ifisnan); 1.3544 + assert( opt_isnan->is_If(), "Expect an IfNode"); 1.3545 + IfNode *opt_ifisnan = (IfNode*)opt_isnan; 1.3546 + Node *iftrue = _gvn.transform( new (C, 1) IfTrueNode(opt_ifisnan) ); 1.3547 + 1.3548 + set_control(iftrue); 1.3549 + 1.3550 + static const jint nan_bits = 0x7fc00000; 1.3551 + Node *slow_result = makecon(TypeInt::make(nan_bits)); // return NaN 1.3552 + phi->init_req(1, _gvn.transform( slow_result )); 1.3553 + r->init_req(1, iftrue); 1.3554 + 1.3555 + // Else fall through 1.3556 + Node *iffalse = _gvn.transform( new (C, 1) IfFalseNode(opt_ifisnan) ); 1.3557 + set_control(iffalse); 1.3558 + 1.3559 + phi->init_req(2, _gvn.transform( new (C, 2) MoveF2INode(value))); 1.3560 + r->init_req(2, iffalse); 1.3561 + 1.3562 + // Post merge 1.3563 + set_control(_gvn.transform(r)); 1.3564 + record_for_igvn(r); 1.3565 + 1.3566 + Node* result = _gvn.transform(phi); 1.3567 + assert(result->bottom_type()->isa_int(), "must be"); 1.3568 + push(result); 1.3569 + 1.3570 + C->set_has_split_ifs(true); // Has chance for split-if optimization 1.3571 + 1.3572 + break; 1.3573 + } 1.3574 + 1.3575 + default: 1.3576 + ShouldNotReachHere(); 1.3577 + } 1.3578 + 1.3579 + return true; 1.3580 +} 1.3581 + 1.3582 +#ifdef _LP64 1.3583 +#define XTOP ,top() /*additional argument*/ 1.3584 +#else //_LP64 1.3585 +#define XTOP /*no additional argument*/ 1.3586 +#endif //_LP64 1.3587 + 1.3588 +//----------------------inline_unsafe_copyMemory------------------------- 1.3589 +bool LibraryCallKit::inline_unsafe_copyMemory() { 1.3590 + if (callee()->is_static()) return false; // caller must have the capability! 1.3591 + int nargs = 1 + 5 + 3; // 5 args: (src: ptr,off, dst: ptr,off, size) 1.3592 + assert(signature()->size() == nargs-1, "copy has 5 arguments"); 1.3593 + null_check_receiver(callee()); // check then ignore argument(0) 1.3594 + if (stopped()) return true; 1.3595 + 1.3596 + C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe". 1.3597 + 1.3598 + Node* src_ptr = argument(1); 1.3599 + Node* src_off = ConvL2X(argument(2)); 1.3600 + assert(argument(3)->is_top(), "2nd half of long"); 1.3601 + Node* dst_ptr = argument(4); 1.3602 + Node* dst_off = ConvL2X(argument(5)); 1.3603 + assert(argument(6)->is_top(), "2nd half of long"); 1.3604 + Node* size = ConvL2X(argument(7)); 1.3605 + assert(argument(8)->is_top(), "2nd half of long"); 1.3606 + 1.3607 + assert(Unsafe_field_offset_to_byte_offset(11) == 11, 1.3608 + "fieldOffset must be byte-scaled"); 1.3609 + 1.3610 + Node* src = make_unsafe_address(src_ptr, src_off); 1.3611 + Node* dst = make_unsafe_address(dst_ptr, dst_off); 1.3612 + 1.3613 + // Conservatively insert a memory barrier on all memory slices. 1.3614 + // Do not let writes of the copy source or destination float below the copy. 1.3615 + insert_mem_bar(Op_MemBarCPUOrder); 1.3616 + 1.3617 + // Call it. Note that the length argument is not scaled. 1.3618 + make_runtime_call(RC_LEAF|RC_NO_FP, 1.3619 + OptoRuntime::fast_arraycopy_Type(), 1.3620 + StubRoutines::unsafe_arraycopy(), 1.3621 + "unsafe_arraycopy", 1.3622 + TypeRawPtr::BOTTOM, 1.3623 + src, dst, size XTOP); 1.3624 + 1.3625 + // Do not let reads of the copy destination float above the copy. 1.3626 + insert_mem_bar(Op_MemBarCPUOrder); 1.3627 + 1.3628 + return true; 1.3629 +} 1.3630 + 1.3631 + 1.3632 +//------------------------inline_native_clone---------------------------- 1.3633 +// Here are the simple edge cases: 1.3634 +// null receiver => normal trap 1.3635 +// virtual and clone was overridden => slow path to out-of-line clone 1.3636 +// not cloneable or finalizer => slow path to out-of-line Object.clone 1.3637 +// 1.3638 +// The general case has two steps, allocation and copying. 1.3639 +// Allocation has two cases, and uses GraphKit::new_instance or new_array. 1.3640 +// 1.3641 +// Copying also has two cases, oop arrays and everything else. 1.3642 +// Oop arrays use arrayof_oop_arraycopy (same as System.arraycopy). 1.3643 +// Everything else uses the tight inline loop supplied by CopyArrayNode. 1.3644 +// 1.3645 +// These steps fold up nicely if and when the cloned object's klass 1.3646 +// can be sharply typed as an object array, a type array, or an instance. 1.3647 +// 1.3648 +bool LibraryCallKit::inline_native_clone(bool is_virtual) { 1.3649 + int nargs = 1; 1.3650 + Node* obj = null_check_receiver(callee()); 1.3651 + if (stopped()) return true; 1.3652 + Node* obj_klass = load_object_klass(obj); 1.3653 + const TypeKlassPtr* tklass = _gvn.type(obj_klass)->isa_klassptr(); 1.3654 + const TypeOopPtr* toop = ((tklass != NULL) 1.3655 + ? tklass->as_instance_type() 1.3656 + : TypeInstPtr::NOTNULL); 1.3657 + 1.3658 + // Conservatively insert a memory barrier on all memory slices. 1.3659 + // Do not let writes into the original float below the clone. 1.3660 + insert_mem_bar(Op_MemBarCPUOrder); 1.3661 + 1.3662 + // paths into result_reg: 1.3663 + enum { 1.3664 + _slow_path = 1, // out-of-line call to clone method (virtual or not) 1.3665 + _objArray_path, // plain allocation, plus arrayof_oop_arraycopy 1.3666 + _fast_path, // plain allocation, plus a CopyArray operation 1.3667 + PATH_LIMIT 1.3668 + }; 1.3669 + RegionNode* result_reg = new(C, PATH_LIMIT) RegionNode(PATH_LIMIT); 1.3670 + PhiNode* result_val = new(C, PATH_LIMIT) PhiNode(result_reg, 1.3671 + TypeInstPtr::NOTNULL); 1.3672 + PhiNode* result_i_o = new(C, PATH_LIMIT) PhiNode(result_reg, Type::ABIO); 1.3673 + PhiNode* result_mem = new(C, PATH_LIMIT) PhiNode(result_reg, Type::MEMORY, 1.3674 + TypePtr::BOTTOM); 1.3675 + record_for_igvn(result_reg); 1.3676 + 1.3677 + const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM; 1.3678 + int raw_adr_idx = Compile::AliasIdxRaw; 1.3679 + const bool raw_mem_only = true; 1.3680 + 1.3681 + // paths into alloc_reg (on the fast path, just before the CopyArray): 1.3682 + enum { _typeArray_alloc = 1, _instance_alloc, ALLOC_LIMIT }; 1.3683 + RegionNode* alloc_reg = new(C, ALLOC_LIMIT) RegionNode(ALLOC_LIMIT); 1.3684 + PhiNode* alloc_val = new(C, ALLOC_LIMIT) PhiNode(alloc_reg, raw_adr_type); 1.3685 + PhiNode* alloc_siz = new(C, ALLOC_LIMIT) PhiNode(alloc_reg, TypeX_X); 1.3686 + PhiNode* alloc_i_o = new(C, ALLOC_LIMIT) PhiNode(alloc_reg, Type::ABIO); 1.3687 + PhiNode* alloc_mem = new(C, ALLOC_LIMIT) PhiNode(alloc_reg, Type::MEMORY, 1.3688 + raw_adr_type); 1.3689 + record_for_igvn(alloc_reg); 1.3690 + 1.3691 + bool card_mark = false; // (see below) 1.3692 + 1.3693 + Node* array_ctl = generate_array_guard(obj_klass, (RegionNode*)NULL); 1.3694 + if (array_ctl != NULL) { 1.3695 + // It's an array. 1.3696 + PreserveJVMState pjvms(this); 1.3697 + set_control(array_ctl); 1.3698 + Node* obj_length = load_array_length(obj); 1.3699 + Node* obj_size = NULL; 1.3700 + _sp += nargs; // set original stack for use by uncommon_trap 1.3701 + Node* alloc_obj = new_array(obj_klass, obj_length, 1.3702 + raw_mem_only, &obj_size); 1.3703 + _sp -= nargs; 1.3704 + assert(obj_size != NULL, ""); 1.3705 + Node* raw_obj = alloc_obj->in(1); 1.3706 + assert(raw_obj->is_Proj() && raw_obj->in(0)->is_Allocate(), ""); 1.3707 + if (ReduceBulkZeroing) { 1.3708 + AllocateNode* alloc = AllocateNode::Ideal_allocation(alloc_obj, &_gvn); 1.3709 + if (alloc != NULL) { 1.3710 + // We will be completely responsible for initializing this object. 1.3711 + alloc->maybe_set_complete(&_gvn); 1.3712 + } 1.3713 + } 1.3714 + 1.3715 + if (!use_ReduceInitialCardMarks()) { 1.3716 + // If it is an oop array, it requires very special treatment, 1.3717 + // because card marking is required on each card of the array. 1.3718 + Node* is_obja = generate_objArray_guard(obj_klass, (RegionNode*)NULL); 1.3719 + if (is_obja != NULL) { 1.3720 + PreserveJVMState pjvms2(this); 1.3721 + set_control(is_obja); 1.3722 + // Generate a direct call to the right arraycopy function(s). 1.3723 + bool disjoint_bases = true; 1.3724 + bool length_never_negative = true; 1.3725 + generate_arraycopy(TypeAryPtr::OOPS, T_OBJECT, 1.3726 + obj, intcon(0), alloc_obj, intcon(0), 1.3727 + obj_length, nargs, 1.3728 + disjoint_bases, length_never_negative); 1.3729 + result_reg->init_req(_objArray_path, control()); 1.3730 + result_val->init_req(_objArray_path, alloc_obj); 1.3731 + result_i_o ->set_req(_objArray_path, i_o()); 1.3732 + result_mem ->set_req(_objArray_path, reset_memory()); 1.3733 + } 1.3734 + } 1.3735 + // We can dispense with card marks if we know the allocation 1.3736 + // comes out of eden (TLAB)... In fact, ReduceInitialCardMarks 1.3737 + // causes the non-eden paths to simulate a fresh allocation, 1.3738 + // insofar that no further card marks are required to initialize 1.3739 + // the object. 1.3740 + 1.3741 + // Otherwise, there are no card marks to worry about. 1.3742 + alloc_val->init_req(_typeArray_alloc, raw_obj); 1.3743 + alloc_siz->init_req(_typeArray_alloc, obj_size); 1.3744 + alloc_reg->init_req(_typeArray_alloc, control()); 1.3745 + alloc_i_o->init_req(_typeArray_alloc, i_o()); 1.3746 + alloc_mem->init_req(_typeArray_alloc, memory(raw_adr_type)); 1.3747 + } 1.3748 + 1.3749 + // We only go to the fast case code if we pass a number of guards. 1.3750 + // The paths which do not pass are accumulated in the slow_region. 1.3751 + RegionNode* slow_region = new (C, 1) RegionNode(1); 1.3752 + record_for_igvn(slow_region); 1.3753 + if (!stopped()) { 1.3754 + // It's an instance. Make the slow-path tests. 1.3755 + // If this is a virtual call, we generate a funny guard. We grab 1.3756 + // the vtable entry corresponding to clone() from the target object. 1.3757 + // If the target method which we are calling happens to be the 1.3758 + // Object clone() method, we pass the guard. We do not need this 1.3759 + // guard for non-virtual calls; the caller is known to be the native 1.3760 + // Object clone(). 1.3761 + if (is_virtual) { 1.3762 + generate_virtual_guard(obj_klass, slow_region); 1.3763 + } 1.3764 + 1.3765 + // The object must be cloneable and must not have a finalizer. 1.3766 + // Both of these conditions may be checked in a single test. 1.3767 + // We could optimize the cloneable test further, but we don't care. 1.3768 + generate_access_flags_guard(obj_klass, 1.3769 + // Test both conditions: 1.3770 + JVM_ACC_IS_CLONEABLE | JVM_ACC_HAS_FINALIZER, 1.3771 + // Must be cloneable but not finalizer: 1.3772 + JVM_ACC_IS_CLONEABLE, 1.3773 + slow_region); 1.3774 + } 1.3775 + 1.3776 + if (!stopped()) { 1.3777 + // It's an instance, and it passed the slow-path tests. 1.3778 + PreserveJVMState pjvms(this); 1.3779 + Node* obj_size = NULL; 1.3780 + Node* alloc_obj = new_instance(obj_klass, NULL, raw_mem_only, &obj_size); 1.3781 + assert(obj_size != NULL, ""); 1.3782 + Node* raw_obj = alloc_obj->in(1); 1.3783 + assert(raw_obj->is_Proj() && raw_obj->in(0)->is_Allocate(), ""); 1.3784 + if (ReduceBulkZeroing) { 1.3785 + AllocateNode* alloc = AllocateNode::Ideal_allocation(alloc_obj, &_gvn); 1.3786 + if (alloc != NULL && !alloc->maybe_set_complete(&_gvn)) 1.3787 + alloc = NULL; 1.3788 + } 1.3789 + if (!use_ReduceInitialCardMarks()) { 1.3790 + // Put in store barrier for any and all oops we are sticking 1.3791 + // into this object. (We could avoid this if we could prove 1.3792 + // that the object type contains no oop fields at all.) 1.3793 + card_mark = true; 1.3794 + } 1.3795 + alloc_val->init_req(_instance_alloc, raw_obj); 1.3796 + alloc_siz->init_req(_instance_alloc, obj_size); 1.3797 + alloc_reg->init_req(_instance_alloc, control()); 1.3798 + alloc_i_o->init_req(_instance_alloc, i_o()); 1.3799 + alloc_mem->init_req(_instance_alloc, memory(raw_adr_type)); 1.3800 + } 1.3801 + 1.3802 + // Generate code for the slow case. We make a call to clone(). 1.3803 + set_control(_gvn.transform(slow_region)); 1.3804 + if (!stopped()) { 1.3805 + PreserveJVMState pjvms(this); 1.3806 + CallJavaNode* slow_call = generate_method_call(vmIntrinsics::_clone, is_virtual); 1.3807 + Node* slow_result = set_results_for_java_call(slow_call); 1.3808 + // this->control() comes from set_results_for_java_call 1.3809 + result_reg->init_req(_slow_path, control()); 1.3810 + result_val->init_req(_slow_path, slow_result); 1.3811 + result_i_o ->set_req(_slow_path, i_o()); 1.3812 + result_mem ->set_req(_slow_path, reset_memory()); 1.3813 + } 1.3814 + 1.3815 + // The object is allocated, as an array and/or an instance. Now copy it. 1.3816 + set_control( _gvn.transform(alloc_reg) ); 1.3817 + set_i_o( _gvn.transform(alloc_i_o) ); 1.3818 + set_memory( _gvn.transform(alloc_mem), raw_adr_type ); 1.3819 + Node* raw_obj = _gvn.transform(alloc_val); 1.3820 + 1.3821 + if (!stopped()) { 1.3822 + // Copy the fastest available way. 1.3823 + // (No need for PreserveJVMState, since we're using it all up now.) 1.3824 + Node* src = obj; 1.3825 + Node* dest = raw_obj; 1.3826 + Node* end = dest; 1.3827 + Node* size = _gvn.transform(alloc_siz); 1.3828 + 1.3829 + // Exclude the header. 1.3830 + int base_off = sizeof(oopDesc); 1.3831 + src = basic_plus_adr(src, base_off); 1.3832 + dest = basic_plus_adr(dest, base_off); 1.3833 + end = basic_plus_adr(end, size); 1.3834 + 1.3835 + // Compute the length also, if needed: 1.3836 + Node* countx = size; 1.3837 + countx = _gvn.transform( new (C, 3) SubXNode(countx, MakeConX(base_off)) ); 1.3838 + countx = _gvn.transform( new (C, 3) URShiftXNode(countx, intcon(LogBytesPerLong) )); 1.3839 + 1.3840 + // Select an appropriate instruction to initialize the range. 1.3841 + // The CopyArray instruction (if supported) can be optimized 1.3842 + // into a discrete set of scalar loads and stores. 1.3843 + bool disjoint_bases = true; 1.3844 + generate_unchecked_arraycopy(raw_adr_type, T_LONG, disjoint_bases, 1.3845 + src, NULL, dest, NULL, countx); 1.3846 + 1.3847 + // Now that the object is properly initialized, type it as an oop. 1.3848 + // Use a secondary InitializeNode memory barrier. 1.3849 + InitializeNode* init = insert_mem_bar_volatile(Op_Initialize, raw_adr_idx, 1.3850 + raw_obj)->as_Initialize(); 1.3851 + init->set_complete(&_gvn); // (there is no corresponding AllocateNode) 1.3852 + Node* new_obj = new(C, 2) CheckCastPPNode(control(), raw_obj, 1.3853 + TypeInstPtr::NOTNULL); 1.3854 + new_obj = _gvn.transform(new_obj); 1.3855 + 1.3856 + // If necessary, emit some card marks afterwards. (Non-arrays only.) 1.3857 + if (card_mark) { 1.3858 + Node* no_particular_value = NULL; 1.3859 + Node* no_particular_field = NULL; 1.3860 + post_barrier(control(), 1.3861 + memory(raw_adr_type), 1.3862 + new_obj, 1.3863 + no_particular_field, 1.3864 + raw_adr_idx, 1.3865 + no_particular_value, 1.3866 + T_OBJECT, 1.3867 + false); 1.3868 + } 1.3869 + // Present the results of the slow call. 1.3870 + result_reg->init_req(_fast_path, control()); 1.3871 + result_val->init_req(_fast_path, new_obj); 1.3872 + result_i_o ->set_req(_fast_path, i_o()); 1.3873 + result_mem ->set_req(_fast_path, reset_memory()); 1.3874 + } 1.3875 + 1.3876 + // Return the combined state. 1.3877 + set_control( _gvn.transform(result_reg) ); 1.3878 + set_i_o( _gvn.transform(result_i_o) ); 1.3879 + set_all_memory( _gvn.transform(result_mem) ); 1.3880 + 1.3881 + // Cast the result to a sharper type, since we know what clone does. 1.3882 + Node* new_obj = _gvn.transform(result_val); 1.3883 + Node* cast = new (C, 2) CheckCastPPNode(control(), new_obj, toop); 1.3884 + push(_gvn.transform(cast)); 1.3885 + 1.3886 + return true; 1.3887 +} 1.3888 + 1.3889 + 1.3890 +// constants for computing the copy function 1.3891 +enum { 1.3892 + COPYFUNC_UNALIGNED = 0, 1.3893 + COPYFUNC_ALIGNED = 1, // src, dest aligned to HeapWordSize 1.3894 + COPYFUNC_CONJOINT = 0, 1.3895 + COPYFUNC_DISJOINT = 2 // src != dest, or transfer can descend 1.3896 +}; 1.3897 + 1.3898 +// Note: The condition "disjoint" applies also for overlapping copies 1.3899 +// where an descending copy is permitted (i.e., dest_offset <= src_offset). 1.3900 +static address 1.3901 +select_arraycopy_function(BasicType t, bool aligned, bool disjoint, const char* &name) { 1.3902 + int selector = 1.3903 + (aligned ? COPYFUNC_ALIGNED : COPYFUNC_UNALIGNED) + 1.3904 + (disjoint ? COPYFUNC_DISJOINT : COPYFUNC_CONJOINT); 1.3905 + 1.3906 +#define RETURN_STUB(xxx_arraycopy) { \ 1.3907 + name = #xxx_arraycopy; \ 1.3908 + return StubRoutines::xxx_arraycopy(); } 1.3909 + 1.3910 + switch (t) { 1.3911 + case T_BYTE: 1.3912 + case T_BOOLEAN: 1.3913 + switch (selector) { 1.3914 + case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jbyte_arraycopy); 1.3915 + case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jbyte_arraycopy); 1.3916 + case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jbyte_disjoint_arraycopy); 1.3917 + case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jbyte_disjoint_arraycopy); 1.3918 + } 1.3919 + case T_CHAR: 1.3920 + case T_SHORT: 1.3921 + switch (selector) { 1.3922 + case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jshort_arraycopy); 1.3923 + case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jshort_arraycopy); 1.3924 + case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jshort_disjoint_arraycopy); 1.3925 + case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jshort_disjoint_arraycopy); 1.3926 + } 1.3927 + case T_INT: 1.3928 + case T_FLOAT: 1.3929 + switch (selector) { 1.3930 + case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jint_arraycopy); 1.3931 + case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jint_arraycopy); 1.3932 + case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jint_disjoint_arraycopy); 1.3933 + case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jint_disjoint_arraycopy); 1.3934 + } 1.3935 + case T_DOUBLE: 1.3936 + case T_LONG: 1.3937 + switch (selector) { 1.3938 + case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jlong_arraycopy); 1.3939 + case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jlong_arraycopy); 1.3940 + case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(jlong_disjoint_arraycopy); 1.3941 + case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_jlong_disjoint_arraycopy); 1.3942 + } 1.3943 + case T_ARRAY: 1.3944 + case T_OBJECT: 1.3945 + switch (selector) { 1.3946 + case COPYFUNC_CONJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(oop_arraycopy); 1.3947 + case COPYFUNC_CONJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_oop_arraycopy); 1.3948 + case COPYFUNC_DISJOINT | COPYFUNC_UNALIGNED: RETURN_STUB(oop_disjoint_arraycopy); 1.3949 + case COPYFUNC_DISJOINT | COPYFUNC_ALIGNED: RETURN_STUB(arrayof_oop_disjoint_arraycopy); 1.3950 + } 1.3951 + default: 1.3952 + ShouldNotReachHere(); 1.3953 + return NULL; 1.3954 + } 1.3955 + 1.3956 +#undef RETURN_STUB 1.3957 +} 1.3958 + 1.3959 +//------------------------------basictype2arraycopy---------------------------- 1.3960 +address LibraryCallKit::basictype2arraycopy(BasicType t, 1.3961 + Node* src_offset, 1.3962 + Node* dest_offset, 1.3963 + bool disjoint_bases, 1.3964 + const char* &name) { 1.3965 + const TypeInt* src_offset_inttype = gvn().find_int_type(src_offset);; 1.3966 + const TypeInt* dest_offset_inttype = gvn().find_int_type(dest_offset);; 1.3967 + 1.3968 + bool aligned = false; 1.3969 + bool disjoint = disjoint_bases; 1.3970 + 1.3971 + // if the offsets are the same, we can treat the memory regions as 1.3972 + // disjoint, because either the memory regions are in different arrays, 1.3973 + // or they are identical (which we can treat as disjoint.) We can also 1.3974 + // treat a copy with a destination index less that the source index 1.3975 + // as disjoint since a low->high copy will work correctly in this case. 1.3976 + if (src_offset_inttype != NULL && src_offset_inttype->is_con() && 1.3977 + dest_offset_inttype != NULL && dest_offset_inttype->is_con()) { 1.3978 + // both indices are constants 1.3979 + int s_offs = src_offset_inttype->get_con(); 1.3980 + int d_offs = dest_offset_inttype->get_con(); 1.3981 + int element_size = type2aelembytes[t]; 1.3982 + aligned = ((arrayOopDesc::base_offset_in_bytes(t) + s_offs * element_size) % HeapWordSize == 0) && 1.3983 + ((arrayOopDesc::base_offset_in_bytes(t) + d_offs * element_size) % HeapWordSize == 0); 1.3984 + if (s_offs >= d_offs) disjoint = true; 1.3985 + } else if (src_offset == dest_offset && src_offset != NULL) { 1.3986 + // This can occur if the offsets are identical non-constants. 1.3987 + disjoint = true; 1.3988 + } 1.3989 + 1.3990 + return select_arraycopy_function(t, aligned, disjoint, name); 1.3991 +} 1.3992 + 1.3993 + 1.3994 +//------------------------------inline_arraycopy----------------------- 1.3995 +bool LibraryCallKit::inline_arraycopy() { 1.3996 + // Restore the stack and pop off the arguments. 1.3997 + int nargs = 5; // 2 oops, 3 ints, no size_t or long 1.3998 + assert(callee()->signature()->size() == nargs, "copy has 5 arguments"); 1.3999 + 1.4000 + Node *src = argument(0); 1.4001 + Node *src_offset = argument(1); 1.4002 + Node *dest = argument(2); 1.4003 + Node *dest_offset = argument(3); 1.4004 + Node *length = argument(4); 1.4005 + 1.4006 + // Compile time checks. If any of these checks cannot be verified at compile time, 1.4007 + // we do not make a fast path for this call. Instead, we let the call remain as it 1.4008 + // is. The checks we choose to mandate at compile time are: 1.4009 + // 1.4010 + // (1) src and dest are arrays. 1.4011 + const Type* src_type = src->Value(&_gvn); 1.4012 + const Type* dest_type = dest->Value(&_gvn); 1.4013 + const TypeAryPtr* top_src = src_type->isa_aryptr(); 1.4014 + const TypeAryPtr* top_dest = dest_type->isa_aryptr(); 1.4015 + if (top_src == NULL || top_src->klass() == NULL || 1.4016 + top_dest == NULL || top_dest->klass() == NULL) { 1.4017 + // Conservatively insert a memory barrier on all memory slices. 1.4018 + // Do not let writes into the source float below the arraycopy. 1.4019 + insert_mem_bar(Op_MemBarCPUOrder); 1.4020 + 1.4021 + // Call StubRoutines::generic_arraycopy stub. 1.4022 + generate_arraycopy(TypeRawPtr::BOTTOM, T_CONFLICT, 1.4023 + src, src_offset, dest, dest_offset, length, 1.4024 + nargs); 1.4025 + 1.4026 + // Do not let reads from the destination float above the arraycopy. 1.4027 + // Since we cannot type the arrays, we don't know which slices 1.4028 + // might be affected. We could restrict this barrier only to those 1.4029 + // memory slices which pertain to array elements--but don't bother. 1.4030 + if (!InsertMemBarAfterArraycopy) 1.4031 + // (If InsertMemBarAfterArraycopy, there is already one in place.) 1.4032 + insert_mem_bar(Op_MemBarCPUOrder); 1.4033 + return true; 1.4034 + } 1.4035 + 1.4036 + // (2) src and dest arrays must have elements of the same BasicType 1.4037 + // Figure out the size and type of the elements we will be copying. 1.4038 + BasicType src_elem = top_src->klass()->as_array_klass()->element_type()->basic_type(); 1.4039 + BasicType dest_elem = top_dest->klass()->as_array_klass()->element_type()->basic_type(); 1.4040 + if (src_elem == T_ARRAY) src_elem = T_OBJECT; 1.4041 + if (dest_elem == T_ARRAY) dest_elem = T_OBJECT; 1.4042 + 1.4043 + if (src_elem != dest_elem || dest_elem == T_VOID) { 1.4044 + // The component types are not the same or are not recognized. Punt. 1.4045 + // (But, avoid the native method wrapper to JVM_ArrayCopy.) 1.4046 + generate_slow_arraycopy(TypePtr::BOTTOM, 1.4047 + src, src_offset, dest, dest_offset, length, 1.4048 + nargs); 1.4049 + return true; 1.4050 + } 1.4051 + 1.4052 + //--------------------------------------------------------------------------- 1.4053 + // We will make a fast path for this call to arraycopy. 1.4054 + 1.4055 + // We have the following tests left to perform: 1.4056 + // 1.4057 + // (3) src and dest must not be null. 1.4058 + // (4) src_offset must not be negative. 1.4059 + // (5) dest_offset must not be negative. 1.4060 + // (6) length must not be negative. 1.4061 + // (7) src_offset + length must not exceed length of src. 1.4062 + // (8) dest_offset + length must not exceed length of dest. 1.4063 + // (9) each element of an oop array must be assignable 1.4064 + 1.4065 + RegionNode* slow_region = new (C, 1) RegionNode(1); 1.4066 + record_for_igvn(slow_region); 1.4067 + 1.4068 + // (3) operands must not be null 1.4069 + // We currently perform our null checks with the do_null_check routine. 1.4070 + // This means that the null exceptions will be reported in the caller 1.4071 + // rather than (correctly) reported inside of the native arraycopy call. 1.4072 + // This should be corrected, given time. We do our null check with the 1.4073 + // stack pointer restored. 1.4074 + _sp += nargs; 1.4075 + src = do_null_check(src, T_ARRAY); 1.4076 + dest = do_null_check(dest, T_ARRAY); 1.4077 + _sp -= nargs; 1.4078 + 1.4079 + // (4) src_offset must not be negative. 1.4080 + generate_negative_guard(src_offset, slow_region); 1.4081 + 1.4082 + // (5) dest_offset must not be negative. 1.4083 + generate_negative_guard(dest_offset, slow_region); 1.4084 + 1.4085 + // (6) length must not be negative (moved to generate_arraycopy()). 1.4086 + // generate_negative_guard(length, slow_region); 1.4087 + 1.4088 + // (7) src_offset + length must not exceed length of src. 1.4089 + generate_limit_guard(src_offset, length, 1.4090 + load_array_length(src), 1.4091 + slow_region); 1.4092 + 1.4093 + // (8) dest_offset + length must not exceed length of dest. 1.4094 + generate_limit_guard(dest_offset, length, 1.4095 + load_array_length(dest), 1.4096 + slow_region); 1.4097 + 1.4098 + // (9) each element of an oop array must be assignable 1.4099 + // The generate_arraycopy subroutine checks this. 1.4100 + 1.4101 + // This is where the memory effects are placed: 1.4102 + const TypePtr* adr_type = TypeAryPtr::get_array_body_type(dest_elem); 1.4103 + generate_arraycopy(adr_type, dest_elem, 1.4104 + src, src_offset, dest, dest_offset, length, 1.4105 + nargs, false, false, slow_region); 1.4106 + 1.4107 + return true; 1.4108 +} 1.4109 + 1.4110 +//-----------------------------generate_arraycopy---------------------- 1.4111 +// Generate an optimized call to arraycopy. 1.4112 +// Caller must guard against non-arrays. 1.4113 +// Caller must determine a common array basic-type for both arrays. 1.4114 +// Caller must validate offsets against array bounds. 1.4115 +// The slow_region has already collected guard failure paths 1.4116 +// (such as out of bounds length or non-conformable array types). 1.4117 +// The generated code has this shape, in general: 1.4118 +// 1.4119 +// if (length == 0) return // via zero_path 1.4120 +// slowval = -1 1.4121 +// if (types unknown) { 1.4122 +// slowval = call generic copy loop 1.4123 +// if (slowval == 0) return // via checked_path 1.4124 +// } else if (indexes in bounds) { 1.4125 +// if ((is object array) && !(array type check)) { 1.4126 +// slowval = call checked copy loop 1.4127 +// if (slowval == 0) return // via checked_path 1.4128 +// } else { 1.4129 +// call bulk copy loop 1.4130 +// return // via fast_path 1.4131 +// } 1.4132 +// } 1.4133 +// // adjust params for remaining work: 1.4134 +// if (slowval != -1) { 1.4135 +// n = -1^slowval; src_offset += n; dest_offset += n; length -= n 1.4136 +// } 1.4137 +// slow_region: 1.4138 +// call slow arraycopy(src, src_offset, dest, dest_offset, length) 1.4139 +// return // via slow_call_path 1.4140 +// 1.4141 +// This routine is used from several intrinsics: System.arraycopy, 1.4142 +// Object.clone (the array subcase), and Arrays.copyOf[Range]. 1.4143 +// 1.4144 +void 1.4145 +LibraryCallKit::generate_arraycopy(const TypePtr* adr_type, 1.4146 + BasicType basic_elem_type, 1.4147 + Node* src, Node* src_offset, 1.4148 + Node* dest, Node* dest_offset, 1.4149 + Node* copy_length, 1.4150 + int nargs, 1.4151 + bool disjoint_bases, 1.4152 + bool length_never_negative, 1.4153 + RegionNode* slow_region) { 1.4154 + 1.4155 + if (slow_region == NULL) { 1.4156 + slow_region = new(C,1) RegionNode(1); 1.4157 + record_for_igvn(slow_region); 1.4158 + } 1.4159 + 1.4160 + Node* original_dest = dest; 1.4161 + AllocateArrayNode* alloc = NULL; // used for zeroing, if needed 1.4162 + Node* raw_dest = NULL; // used before zeroing, if needed 1.4163 + bool must_clear_dest = false; 1.4164 + 1.4165 + // See if this is the initialization of a newly-allocated array. 1.4166 + // If so, we will take responsibility here for initializing it to zero. 1.4167 + // (Note: Because tightly_coupled_allocation performs checks on the 1.4168 + // out-edges of the dest, we need to avoid making derived pointers 1.4169 + // from it until we have checked its uses.) 1.4170 + if (ReduceBulkZeroing 1.4171 + && !ZeroTLAB // pointless if already zeroed 1.4172 + && basic_elem_type != T_CONFLICT // avoid corner case 1.4173 + && !_gvn.eqv_uncast(src, dest) 1.4174 + && ((alloc = tightly_coupled_allocation(dest, slow_region)) 1.4175 + != NULL) 1.4176 + && alloc->maybe_set_complete(&_gvn)) { 1.4177 + // "You break it, you buy it." 1.4178 + InitializeNode* init = alloc->initialization(); 1.4179 + assert(init->is_complete(), "we just did this"); 1.4180 + assert(dest->Opcode() == Op_CheckCastPP, "sanity"); 1.4181 + assert(dest->in(0)->in(0) == init, "dest pinned"); 1.4182 + raw_dest = dest->in(1); // grab the raw pointer! 1.4183 + original_dest = dest; 1.4184 + dest = raw_dest; 1.4185 + adr_type = TypeRawPtr::BOTTOM; // all initializations are into raw memory 1.4186 + // Decouple the original InitializeNode, turning it into a simple membar. 1.4187 + // We will build a new one at the end of this routine. 1.4188 + init->set_req(InitializeNode::RawAddress, top()); 1.4189 + // From this point on, every exit path is responsible for 1.4190 + // initializing any non-copied parts of the object to zero. 1.4191 + must_clear_dest = true; 1.4192 + } else { 1.4193 + // No zeroing elimination here. 1.4194 + alloc = NULL; 1.4195 + //original_dest = dest; 1.4196 + //must_clear_dest = false; 1.4197 + } 1.4198 + 1.4199 + // Results are placed here: 1.4200 + enum { fast_path = 1, // normal void-returning assembly stub 1.4201 + checked_path = 2, // special assembly stub with cleanup 1.4202 + slow_call_path = 3, // something went wrong; call the VM 1.4203 + zero_path = 4, // bypass when length of copy is zero 1.4204 + bcopy_path = 5, // copy primitive array by 64-bit blocks 1.4205 + PATH_LIMIT = 6 1.4206 + }; 1.4207 + RegionNode* result_region = new(C, PATH_LIMIT) RegionNode(PATH_LIMIT); 1.4208 + PhiNode* result_i_o = new(C, PATH_LIMIT) PhiNode(result_region, Type::ABIO); 1.4209 + PhiNode* result_memory = new(C, PATH_LIMIT) PhiNode(result_region, Type::MEMORY, adr_type); 1.4210 + record_for_igvn(result_region); 1.4211 + _gvn.set_type_bottom(result_i_o); 1.4212 + _gvn.set_type_bottom(result_memory); 1.4213 + assert(adr_type != TypePtr::BOTTOM, "must be RawMem or a T[] slice"); 1.4214 + 1.4215 + // The slow_control path: 1.4216 + Node* slow_control; 1.4217 + Node* slow_i_o = i_o(); 1.4218 + Node* slow_mem = memory(adr_type); 1.4219 + debug_only(slow_control = (Node*) badAddress); 1.4220 + 1.4221 + // Checked control path: 1.4222 + Node* checked_control = top(); 1.4223 + Node* checked_mem = NULL; 1.4224 + Node* checked_i_o = NULL; 1.4225 + Node* checked_value = NULL; 1.4226 + 1.4227 + if (basic_elem_type == T_CONFLICT) { 1.4228 + assert(!must_clear_dest, ""); 1.4229 + Node* cv = generate_generic_arraycopy(adr_type, 1.4230 + src, src_offset, dest, dest_offset, 1.4231 + copy_length, nargs); 1.4232 + if (cv == NULL) cv = intcon(-1); // failure (no stub available) 1.4233 + checked_control = control(); 1.4234 + checked_i_o = i_o(); 1.4235 + checked_mem = memory(adr_type); 1.4236 + checked_value = cv; 1.4237 + set_control(top()); // no fast path 1.4238 + } 1.4239 + 1.4240 + Node* not_pos = generate_nonpositive_guard(copy_length, length_never_negative); 1.4241 + if (not_pos != NULL) { 1.4242 + PreserveJVMState pjvms(this); 1.4243 + set_control(not_pos); 1.4244 + 1.4245 + // (6) length must not be negative. 1.4246 + if (!length_never_negative) { 1.4247 + generate_negative_guard(copy_length, slow_region); 1.4248 + } 1.4249 + 1.4250 + if (!stopped() && must_clear_dest) { 1.4251 + Node* dest_length = alloc->in(AllocateNode::ALength); 1.4252 + if (_gvn.eqv_uncast(copy_length, dest_length) 1.4253 + || _gvn.find_int_con(dest_length, 1) <= 0) { 1.4254 + // There is no zeroing to do. 1.4255 + } else { 1.4256 + // Clear the whole thing since there are no source elements to copy. 1.4257 + generate_clear_array(adr_type, dest, basic_elem_type, 1.4258 + intcon(0), NULL, 1.4259 + alloc->in(AllocateNode::AllocSize)); 1.4260 + } 1.4261 + } 1.4262 + 1.4263 + // Present the results of the fast call. 1.4264 + result_region->init_req(zero_path, control()); 1.4265 + result_i_o ->init_req(zero_path, i_o()); 1.4266 + result_memory->init_req(zero_path, memory(adr_type)); 1.4267 + } 1.4268 + 1.4269 + if (!stopped() && must_clear_dest) { 1.4270 + // We have to initialize the *uncopied* part of the array to zero. 1.4271 + // The copy destination is the slice dest[off..off+len]. The other slices 1.4272 + // are dest_head = dest[0..off] and dest_tail = dest[off+len..dest.length]. 1.4273 + Node* dest_size = alloc->in(AllocateNode::AllocSize); 1.4274 + Node* dest_length = alloc->in(AllocateNode::ALength); 1.4275 + Node* dest_tail = _gvn.transform( new(C,3) AddINode(dest_offset, 1.4276 + copy_length) ); 1.4277 + 1.4278 + // If there is a head section that needs zeroing, do it now. 1.4279 + if (find_int_con(dest_offset, -1) != 0) { 1.4280 + generate_clear_array(adr_type, dest, basic_elem_type, 1.4281 + intcon(0), dest_offset, 1.4282 + NULL); 1.4283 + } 1.4284 + 1.4285 + // Next, perform a dynamic check on the tail length. 1.4286 + // It is often zero, and we can win big if we prove this. 1.4287 + // There are two wins: Avoid generating the ClearArray 1.4288 + // with its attendant messy index arithmetic, and upgrade 1.4289 + // the copy to a more hardware-friendly word size of 64 bits. 1.4290 + Node* tail_ctl = NULL; 1.4291 + if (!stopped() && !_gvn.eqv_uncast(dest_tail, dest_length)) { 1.4292 + Node* cmp_lt = _gvn.transform( new(C,3) CmpINode(dest_tail, dest_length) ); 1.4293 + Node* bol_lt = _gvn.transform( new(C,2) BoolNode(cmp_lt, BoolTest::lt) ); 1.4294 + tail_ctl = generate_slow_guard(bol_lt, NULL); 1.4295 + assert(tail_ctl != NULL || !stopped(), "must be an outcome"); 1.4296 + } 1.4297 + 1.4298 + // At this point, let's assume there is no tail. 1.4299 + if (!stopped() && alloc != NULL && basic_elem_type != T_OBJECT) { 1.4300 + // There is no tail. Try an upgrade to a 64-bit copy. 1.4301 + bool didit = false; 1.4302 + { PreserveJVMState pjvms(this); 1.4303 + didit = generate_block_arraycopy(adr_type, basic_elem_type, alloc, 1.4304 + src, src_offset, dest, dest_offset, 1.4305 + dest_size); 1.4306 + if (didit) { 1.4307 + // Present the results of the block-copying fast call. 1.4308 + result_region->init_req(bcopy_path, control()); 1.4309 + result_i_o ->init_req(bcopy_path, i_o()); 1.4310 + result_memory->init_req(bcopy_path, memory(adr_type)); 1.4311 + } 1.4312 + } 1.4313 + if (didit) 1.4314 + set_control(top()); // no regular fast path 1.4315 + } 1.4316 + 1.4317 + // Clear the tail, if any. 1.4318 + if (tail_ctl != NULL) { 1.4319 + Node* notail_ctl = stopped() ? NULL : control(); 1.4320 + set_control(tail_ctl); 1.4321 + if (notail_ctl == NULL) { 1.4322 + generate_clear_array(adr_type, dest, basic_elem_type, 1.4323 + dest_tail, NULL, 1.4324 + dest_size); 1.4325 + } else { 1.4326 + // Make a local merge. 1.4327 + Node* done_ctl = new(C,3) RegionNode(3); 1.4328 + Node* done_mem = new(C,3) PhiNode(done_ctl, Type::MEMORY, adr_type); 1.4329 + done_ctl->init_req(1, notail_ctl); 1.4330 + done_mem->init_req(1, memory(adr_type)); 1.4331 + generate_clear_array(adr_type, dest, basic_elem_type, 1.4332 + dest_tail, NULL, 1.4333 + dest_size); 1.4334 + done_ctl->init_req(2, control()); 1.4335 + done_mem->init_req(2, memory(adr_type)); 1.4336 + set_control( _gvn.transform(done_ctl) ); 1.4337 + set_memory( _gvn.transform(done_mem), adr_type ); 1.4338 + } 1.4339 + } 1.4340 + } 1.4341 + 1.4342 + BasicType copy_type = basic_elem_type; 1.4343 + assert(basic_elem_type != T_ARRAY, "caller must fix this"); 1.4344 + if (!stopped() && copy_type == T_OBJECT) { 1.4345 + // If src and dest have compatible element types, we can copy bits. 1.4346 + // Types S[] and D[] are compatible if D is a supertype of S. 1.4347 + // 1.4348 + // If they are not, we will use checked_oop_disjoint_arraycopy, 1.4349 + // which performs a fast optimistic per-oop check, and backs off 1.4350 + // further to JVM_ArrayCopy on the first per-oop check that fails. 1.4351 + // (Actually, we don't move raw bits only; the GC requires card marks.) 1.4352 + 1.4353 + // Get the klassOop for both src and dest 1.4354 + Node* src_klass = load_object_klass(src); 1.4355 + Node* dest_klass = load_object_klass(dest); 1.4356 + 1.4357 + // Generate the subtype check. 1.4358 + // This might fold up statically, or then again it might not. 1.4359 + // 1.4360 + // Non-static example: Copying List<String>.elements to a new String[]. 1.4361 + // The backing store for a List<String> is always an Object[], 1.4362 + // but its elements are always type String, if the generic types 1.4363 + // are correct at the source level. 1.4364 + // 1.4365 + // Test S[] against D[], not S against D, because (probably) 1.4366 + // the secondary supertype cache is less busy for S[] than S. 1.4367 + // This usually only matters when D is an interface. 1.4368 + Node* not_subtype_ctrl = gen_subtype_check(src_klass, dest_klass); 1.4369 + // Plug failing path into checked_oop_disjoint_arraycopy 1.4370 + if (not_subtype_ctrl != top()) { 1.4371 + PreserveJVMState pjvms(this); 1.4372 + set_control(not_subtype_ctrl); 1.4373 + // (At this point we can assume disjoint_bases, since types differ.) 1.4374 + int ek_offset = objArrayKlass::element_klass_offset_in_bytes() + sizeof(oopDesc); 1.4375 + Node* p1 = basic_plus_adr(dest_klass, ek_offset); 1.4376 + Node* n1 = new (C, 3) LoadKlassNode(0, immutable_memory(), p1, TypeRawPtr::BOTTOM); 1.4377 + Node* dest_elem_klass = _gvn.transform(n1); 1.4378 + Node* cv = generate_checkcast_arraycopy(adr_type, 1.4379 + dest_elem_klass, 1.4380 + src, src_offset, dest, dest_offset, 1.4381 + copy_length, 1.4382 + nargs); 1.4383 + if (cv == NULL) cv = intcon(-1); // failure (no stub available) 1.4384 + checked_control = control(); 1.4385 + checked_i_o = i_o(); 1.4386 + checked_mem = memory(adr_type); 1.4387 + checked_value = cv; 1.4388 + } 1.4389 + // At this point we know we do not need type checks on oop stores. 1.4390 + 1.4391 + // Let's see if we need card marks: 1.4392 + if (alloc != NULL && use_ReduceInitialCardMarks()) { 1.4393 + // If we do not need card marks, copy using the jint or jlong stub. 1.4394 + copy_type = LP64_ONLY(T_LONG) NOT_LP64(T_INT); 1.4395 + assert(type2aelembytes[basic_elem_type] == type2aelembytes[copy_type], 1.4396 + "sizes agree"); 1.4397 + } 1.4398 + } 1.4399 + 1.4400 + if (!stopped()) { 1.4401 + // Generate the fast path, if possible. 1.4402 + PreserveJVMState pjvms(this); 1.4403 + generate_unchecked_arraycopy(adr_type, copy_type, disjoint_bases, 1.4404 + src, src_offset, dest, dest_offset, 1.4405 + ConvI2X(copy_length)); 1.4406 + 1.4407 + // Present the results of the fast call. 1.4408 + result_region->init_req(fast_path, control()); 1.4409 + result_i_o ->init_req(fast_path, i_o()); 1.4410 + result_memory->init_req(fast_path, memory(adr_type)); 1.4411 + } 1.4412 + 1.4413 + // Here are all the slow paths up to this point, in one bundle: 1.4414 + slow_control = top(); 1.4415 + if (slow_region != NULL) 1.4416 + slow_control = _gvn.transform(slow_region); 1.4417 + debug_only(slow_region = (RegionNode*)badAddress); 1.4418 + 1.4419 + set_control(checked_control); 1.4420 + if (!stopped()) { 1.4421 + // Clean up after the checked call. 1.4422 + // The returned value is either 0 or -1^K, 1.4423 + // where K = number of partially transferred array elements. 1.4424 + Node* cmp = _gvn.transform( new(C, 3) CmpINode(checked_value, intcon(0)) ); 1.4425 + Node* bol = _gvn.transform( new(C, 2) BoolNode(cmp, BoolTest::eq) ); 1.4426 + IfNode* iff = create_and_map_if(control(), bol, PROB_MAX, COUNT_UNKNOWN); 1.4427 + 1.4428 + // If it is 0, we are done, so transfer to the end. 1.4429 + Node* checks_done = _gvn.transform( new(C, 1) IfTrueNode(iff) ); 1.4430 + result_region->init_req(checked_path, checks_done); 1.4431 + result_i_o ->init_req(checked_path, checked_i_o); 1.4432 + result_memory->init_req(checked_path, checked_mem); 1.4433 + 1.4434 + // If it is not zero, merge into the slow call. 1.4435 + set_control( _gvn.transform( new(C, 1) IfFalseNode(iff) )); 1.4436 + RegionNode* slow_reg2 = new(C, 3) RegionNode(3); 1.4437 + PhiNode* slow_i_o2 = new(C, 3) PhiNode(slow_reg2, Type::ABIO); 1.4438 + PhiNode* slow_mem2 = new(C, 3) PhiNode(slow_reg2, Type::MEMORY, adr_type); 1.4439 + record_for_igvn(slow_reg2); 1.4440 + slow_reg2 ->init_req(1, slow_control); 1.4441 + slow_i_o2 ->init_req(1, slow_i_o); 1.4442 + slow_mem2 ->init_req(1, slow_mem); 1.4443 + slow_reg2 ->init_req(2, control()); 1.4444 + slow_i_o2 ->init_req(2, i_o()); 1.4445 + slow_mem2 ->init_req(2, memory(adr_type)); 1.4446 + 1.4447 + slow_control = _gvn.transform(slow_reg2); 1.4448 + slow_i_o = _gvn.transform(slow_i_o2); 1.4449 + slow_mem = _gvn.transform(slow_mem2); 1.4450 + 1.4451 + if (alloc != NULL) { 1.4452 + // We'll restart from the very beginning, after zeroing the whole thing. 1.4453 + // This can cause double writes, but that's OK since dest is brand new. 1.4454 + // So we ignore the low 31 bits of the value returned from the stub. 1.4455 + } else { 1.4456 + // We must continue the copy exactly where it failed, or else 1.4457 + // another thread might see the wrong number of writes to dest. 1.4458 + Node* checked_offset = _gvn.transform( new(C, 3) XorINode(checked_value, intcon(-1)) ); 1.4459 + Node* slow_offset = new(C, 3) PhiNode(slow_reg2, TypeInt::INT); 1.4460 + slow_offset->init_req(1, intcon(0)); 1.4461 + slow_offset->init_req(2, checked_offset); 1.4462 + slow_offset = _gvn.transform(slow_offset); 1.4463 + 1.4464 + // Adjust the arguments by the conditionally incoming offset. 1.4465 + Node* src_off_plus = _gvn.transform( new(C, 3) AddINode(src_offset, slow_offset) ); 1.4466 + Node* dest_off_plus = _gvn.transform( new(C, 3) AddINode(dest_offset, slow_offset) ); 1.4467 + Node* length_minus = _gvn.transform( new(C, 3) SubINode(copy_length, slow_offset) ); 1.4468 + 1.4469 + // Tweak the node variables to adjust the code produced below: 1.4470 + src_offset = src_off_plus; 1.4471 + dest_offset = dest_off_plus; 1.4472 + copy_length = length_minus; 1.4473 + } 1.4474 + } 1.4475 + 1.4476 + set_control(slow_control); 1.4477 + if (!stopped()) { 1.4478 + // Generate the slow path, if needed. 1.4479 + PreserveJVMState pjvms(this); // replace_in_map may trash the map 1.4480 + 1.4481 + set_memory(slow_mem, adr_type); 1.4482 + set_i_o(slow_i_o); 1.4483 + 1.4484 + if (must_clear_dest) { 1.4485 + generate_clear_array(adr_type, dest, basic_elem_type, 1.4486 + intcon(0), NULL, 1.4487 + alloc->in(AllocateNode::AllocSize)); 1.4488 + } 1.4489 + 1.4490 + if (dest != original_dest) { 1.4491 + // Promote from rawptr to oop, so it looks right in the call's GC map. 1.4492 + dest = _gvn.transform( new(C,2) CheckCastPPNode(control(), dest, 1.4493 + TypeInstPtr::NOTNULL) ); 1.4494 + 1.4495 + // Edit the call's debug-info to avoid referring to original_dest. 1.4496 + // (The problem with original_dest is that it isn't ready until 1.4497 + // after the InitializeNode completes, but this stuff is before.) 1.4498 + // Substitute in the locally valid dest_oop. 1.4499 + replace_in_map(original_dest, dest); 1.4500 + } 1.4501 + 1.4502 + generate_slow_arraycopy(adr_type, 1.4503 + src, src_offset, dest, dest_offset, 1.4504 + copy_length, nargs); 1.4505 + 1.4506 + result_region->init_req(slow_call_path, control()); 1.4507 + result_i_o ->init_req(slow_call_path, i_o()); 1.4508 + result_memory->init_req(slow_call_path, memory(adr_type)); 1.4509 + } 1.4510 + 1.4511 + // Remove unused edges. 1.4512 + for (uint i = 1; i < result_region->req(); i++) { 1.4513 + if (result_region->in(i) == NULL) 1.4514 + result_region->init_req(i, top()); 1.4515 + } 1.4516 + 1.4517 + // Finished; return the combined state. 1.4518 + set_control( _gvn.transform(result_region) ); 1.4519 + set_i_o( _gvn.transform(result_i_o) ); 1.4520 + set_memory( _gvn.transform(result_memory), adr_type ); 1.4521 + 1.4522 + if (dest != original_dest) { 1.4523 + // Pin the "finished" array node after the arraycopy/zeroing operations. 1.4524 + // Use a secondary InitializeNode memory barrier. 1.4525 + InitializeNode* init = insert_mem_bar_volatile(Op_Initialize, 1.4526 + Compile::AliasIdxRaw, 1.4527 + raw_dest)->as_Initialize(); 1.4528 + init->set_complete(&_gvn); // (there is no corresponding AllocateNode) 1.4529 + _gvn.hash_delete(original_dest); 1.4530 + original_dest->set_req(0, control()); 1.4531 + _gvn.hash_find_insert(original_dest); // put back into GVN table 1.4532 + } 1.4533 + 1.4534 + // The memory edges above are precise in order to model effects around 1.4535 + // array copyies accurately to allow value numbering of field loads around 1.4536 + // arraycopy. Such field loads, both before and after, are common in Java 1.4537 + // collections and similar classes involving header/array data structures. 1.4538 + // 1.4539 + // But with low number of register or when some registers are used or killed 1.4540 + // by arraycopy calls it causes registers spilling on stack. See 6544710. 1.4541 + // The next memory barrier is added to avoid it. If the arraycopy can be 1.4542 + // optimized away (which it can, sometimes) then we can manually remove 1.4543 + // the membar also. 1.4544 + if (InsertMemBarAfterArraycopy) 1.4545 + insert_mem_bar(Op_MemBarCPUOrder); 1.4546 +} 1.4547 + 1.4548 + 1.4549 +// Helper function which determines if an arraycopy immediately follows 1.4550 +// an allocation, with no intervening tests or other escapes for the object. 1.4551 +AllocateArrayNode* 1.4552 +LibraryCallKit::tightly_coupled_allocation(Node* ptr, 1.4553 + RegionNode* slow_region) { 1.4554 + if (stopped()) return NULL; // no fast path 1.4555 + if (C->AliasLevel() == 0) return NULL; // no MergeMems around 1.4556 + 1.4557 + AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(ptr, &_gvn); 1.4558 + if (alloc == NULL) return NULL; 1.4559 + 1.4560 + Node* rawmem = memory(Compile::AliasIdxRaw); 1.4561 + // Is the allocation's memory state untouched? 1.4562 + if (!(rawmem->is_Proj() && rawmem->in(0)->is_Initialize())) { 1.4563 + // Bail out if there have been raw-memory effects since the allocation. 1.4564 + // (Example: There might have been a call or safepoint.) 1.4565 + return NULL; 1.4566 + } 1.4567 + rawmem = rawmem->in(0)->as_Initialize()->memory(Compile::AliasIdxRaw); 1.4568 + if (!(rawmem->is_Proj() && rawmem->in(0) == alloc)) { 1.4569 + return NULL; 1.4570 + } 1.4571 + 1.4572 + // There must be no unexpected observers of this allocation. 1.4573 + for (DUIterator_Fast imax, i = ptr->fast_outs(imax); i < imax; i++) { 1.4574 + Node* obs = ptr->fast_out(i); 1.4575 + if (obs != this->map()) { 1.4576 + return NULL; 1.4577 + } 1.4578 + } 1.4579 + 1.4580 + // This arraycopy must unconditionally follow the allocation of the ptr. 1.4581 + Node* alloc_ctl = ptr->in(0); 1.4582 + assert(just_allocated_object(alloc_ctl) == ptr, "most recent allo"); 1.4583 + 1.4584 + Node* ctl = control(); 1.4585 + while (ctl != alloc_ctl) { 1.4586 + // There may be guards which feed into the slow_region. 1.4587 + // Any other control flow means that we might not get a chance 1.4588 + // to finish initializing the allocated object. 1.4589 + if ((ctl->is_IfFalse() || ctl->is_IfTrue()) && ctl->in(0)->is_If()) { 1.4590 + IfNode* iff = ctl->in(0)->as_If(); 1.4591 + Node* not_ctl = iff->proj_out(1 - ctl->as_Proj()->_con); 1.4592 + assert(not_ctl != NULL && not_ctl != ctl, "found alternate"); 1.4593 + if (slow_region != NULL && slow_region->find_edge(not_ctl) >= 1) { 1.4594 + ctl = iff->in(0); // This test feeds the known slow_region. 1.4595 + continue; 1.4596 + } 1.4597 + // One more try: Various low-level checks bottom out in 1.4598 + // uncommon traps. If the debug-info of the trap omits 1.4599 + // any reference to the allocation, as we've already 1.4600 + // observed, then there can be no objection to the trap. 1.4601 + bool found_trap = false; 1.4602 + for (DUIterator_Fast jmax, j = not_ctl->fast_outs(jmax); j < jmax; j++) { 1.4603 + Node* obs = not_ctl->fast_out(j); 1.4604 + if (obs->in(0) == not_ctl && obs->is_Call() && 1.4605 + (obs->as_Call()->entry_point() == 1.4606 + SharedRuntime::uncommon_trap_blob()->instructions_begin())) { 1.4607 + found_trap = true; break; 1.4608 + } 1.4609 + } 1.4610 + if (found_trap) { 1.4611 + ctl = iff->in(0); // This test feeds a harmless uncommon trap. 1.4612 + continue; 1.4613 + } 1.4614 + } 1.4615 + return NULL; 1.4616 + } 1.4617 + 1.4618 + // If we get this far, we have an allocation which immediately 1.4619 + // precedes the arraycopy, and we can take over zeroing the new object. 1.4620 + // The arraycopy will finish the initialization, and provide 1.4621 + // a new control state to which we will anchor the destination pointer. 1.4622 + 1.4623 + return alloc; 1.4624 +} 1.4625 + 1.4626 +// Helper for initialization of arrays, creating a ClearArray. 1.4627 +// It writes zero bits in [start..end), within the body of an array object. 1.4628 +// The memory effects are all chained onto the 'adr_type' alias category. 1.4629 +// 1.4630 +// Since the object is otherwise uninitialized, we are free 1.4631 +// to put a little "slop" around the edges of the cleared area, 1.4632 +// as long as it does not go back into the array's header, 1.4633 +// or beyond the array end within the heap. 1.4634 +// 1.4635 +// The lower edge can be rounded down to the nearest jint and the 1.4636 +// upper edge can be rounded up to the nearest MinObjAlignmentInBytes. 1.4637 +// 1.4638 +// Arguments: 1.4639 +// adr_type memory slice where writes are generated 1.4640 +// dest oop of the destination array 1.4641 +// basic_elem_type element type of the destination 1.4642 +// slice_idx array index of first element to store 1.4643 +// slice_len number of elements to store (or NULL) 1.4644 +// dest_size total size in bytes of the array object 1.4645 +// 1.4646 +// Exactly one of slice_len or dest_size must be non-NULL. 1.4647 +// If dest_size is non-NULL, zeroing extends to the end of the object. 1.4648 +// If slice_len is non-NULL, the slice_idx value must be a constant. 1.4649 +void 1.4650 +LibraryCallKit::generate_clear_array(const TypePtr* adr_type, 1.4651 + Node* dest, 1.4652 + BasicType basic_elem_type, 1.4653 + Node* slice_idx, 1.4654 + Node* slice_len, 1.4655 + Node* dest_size) { 1.4656 + // one or the other but not both of slice_len and dest_size: 1.4657 + assert((slice_len != NULL? 1: 0) + (dest_size != NULL? 1: 0) == 1, ""); 1.4658 + if (slice_len == NULL) slice_len = top(); 1.4659 + if (dest_size == NULL) dest_size = top(); 1.4660 + 1.4661 + // operate on this memory slice: 1.4662 + Node* mem = memory(adr_type); // memory slice to operate on 1.4663 + 1.4664 + // scaling and rounding of indexes: 1.4665 + int scale = exact_log2(type2aelembytes[basic_elem_type]); 1.4666 + int abase = arrayOopDesc::base_offset_in_bytes(basic_elem_type); 1.4667 + int clear_low = (-1 << scale) & (BytesPerInt - 1); 1.4668 + int bump_bit = (-1 << scale) & BytesPerInt; 1.4669 + 1.4670 + // determine constant starts and ends 1.4671 + const intptr_t BIG_NEG = -128; 1.4672 + assert(BIG_NEG + 2*abase < 0, "neg enough"); 1.4673 + intptr_t slice_idx_con = (intptr_t) find_int_con(slice_idx, BIG_NEG); 1.4674 + intptr_t slice_len_con = (intptr_t) find_int_con(slice_len, BIG_NEG); 1.4675 + if (slice_len_con == 0) { 1.4676 + return; // nothing to do here 1.4677 + } 1.4678 + intptr_t start_con = (abase + (slice_idx_con << scale)) & ~clear_low; 1.4679 + intptr_t end_con = find_intptr_t_con(dest_size, -1); 1.4680 + if (slice_idx_con >= 0 && slice_len_con >= 0) { 1.4681 + assert(end_con < 0, "not two cons"); 1.4682 + end_con = round_to(abase + ((slice_idx_con + slice_len_con) << scale), 1.4683 + BytesPerLong); 1.4684 + } 1.4685 + 1.4686 + if (start_con >= 0 && end_con >= 0) { 1.4687 + // Constant start and end. Simple. 1.4688 + mem = ClearArrayNode::clear_memory(control(), mem, dest, 1.4689 + start_con, end_con, &_gvn); 1.4690 + } else if (start_con >= 0 && dest_size != top()) { 1.4691 + // Constant start, pre-rounded end after the tail of the array. 1.4692 + Node* end = dest_size; 1.4693 + mem = ClearArrayNode::clear_memory(control(), mem, dest, 1.4694 + start_con, end, &_gvn); 1.4695 + } else if (start_con >= 0 && slice_len != top()) { 1.4696 + // Constant start, non-constant end. End needs rounding up. 1.4697 + // End offset = round_up(abase + ((slice_idx_con + slice_len) << scale), 8) 1.4698 + intptr_t end_base = abase + (slice_idx_con << scale); 1.4699 + int end_round = (-1 << scale) & (BytesPerLong - 1); 1.4700 + Node* end = ConvI2X(slice_len); 1.4701 + if (scale != 0) 1.4702 + end = _gvn.transform( new(C,3) LShiftXNode(end, intcon(scale) )); 1.4703 + end_base += end_round; 1.4704 + end = _gvn.transform( new(C,3) AddXNode(end, MakeConX(end_base)) ); 1.4705 + end = _gvn.transform( new(C,3) AndXNode(end, MakeConX(~end_round)) ); 1.4706 + mem = ClearArrayNode::clear_memory(control(), mem, dest, 1.4707 + start_con, end, &_gvn); 1.4708 + } else if (start_con < 0 && dest_size != top()) { 1.4709 + // Non-constant start, pre-rounded end after the tail of the array. 1.4710 + // This is almost certainly a "round-to-end" operation. 1.4711 + Node* start = slice_idx; 1.4712 + start = ConvI2X(start); 1.4713 + if (scale != 0) 1.4714 + start = _gvn.transform( new(C,3) LShiftXNode( start, intcon(scale) )); 1.4715 + start = _gvn.transform( new(C,3) AddXNode(start, MakeConX(abase)) ); 1.4716 + if ((bump_bit | clear_low) != 0) { 1.4717 + int to_clear = (bump_bit | clear_low); 1.4718 + // Align up mod 8, then store a jint zero unconditionally 1.4719 + // just before the mod-8 boundary. 1.4720 + // This would only fail if the first array element were immediately 1.4721 + // after the length field, and were also at an even offset mod 8. 1.4722 + assert(((abase + bump_bit) & ~to_clear) - BytesPerInt 1.4723 + >= arrayOopDesc::length_offset_in_bytes() + BytesPerInt, 1.4724 + "store must not trash length field"); 1.4725 + 1.4726 + // Bump 'start' up to (or past) the next jint boundary: 1.4727 + start = _gvn.transform( new(C,3) AddXNode(start, MakeConX(bump_bit)) ); 1.4728 + // Round bumped 'start' down to jlong boundary in body of array. 1.4729 + start = _gvn.transform( new(C,3) AndXNode(start, MakeConX(~to_clear)) ); 1.4730 + // Store a zero to the immediately preceding jint: 1.4731 + Node* x1 = _gvn.transform( new(C,3) AddXNode(start, MakeConX(-BytesPerInt)) ); 1.4732 + Node* p1 = basic_plus_adr(dest, x1); 1.4733 + mem = StoreNode::make(C, control(), mem, p1, adr_type, intcon(0), T_INT); 1.4734 + mem = _gvn.transform(mem); 1.4735 + } 1.4736 + 1.4737 + Node* end = dest_size; // pre-rounded 1.4738 + mem = ClearArrayNode::clear_memory(control(), mem, dest, 1.4739 + start, end, &_gvn); 1.4740 + } else { 1.4741 + // Non-constant start, unrounded non-constant end. 1.4742 + // (Nobody zeroes a random midsection of an array using this routine.) 1.4743 + ShouldNotReachHere(); // fix caller 1.4744 + } 1.4745 + 1.4746 + // Done. 1.4747 + set_memory(mem, adr_type); 1.4748 +} 1.4749 + 1.4750 + 1.4751 +bool 1.4752 +LibraryCallKit::generate_block_arraycopy(const TypePtr* adr_type, 1.4753 + BasicType basic_elem_type, 1.4754 + AllocateNode* alloc, 1.4755 + Node* src, Node* src_offset, 1.4756 + Node* dest, Node* dest_offset, 1.4757 + Node* dest_size) { 1.4758 + // See if there is an advantage from block transfer. 1.4759 + int scale = exact_log2(type2aelembytes[basic_elem_type]); 1.4760 + if (scale >= LogBytesPerLong) 1.4761 + return false; // it is already a block transfer 1.4762 + 1.4763 + // Look at the alignment of the starting offsets. 1.4764 + int abase = arrayOopDesc::base_offset_in_bytes(basic_elem_type); 1.4765 + const intptr_t BIG_NEG = -128; 1.4766 + assert(BIG_NEG + 2*abase < 0, "neg enough"); 1.4767 + 1.4768 + intptr_t src_off = abase + ((intptr_t) find_int_con(src_offset, -1) << scale); 1.4769 + intptr_t dest_off = abase + ((intptr_t) find_int_con(dest_offset, -1) << scale); 1.4770 + if (src_off < 0 || dest_off < 0) 1.4771 + // At present, we can only understand constants. 1.4772 + return false; 1.4773 + 1.4774 + if (((src_off | dest_off) & (BytesPerLong-1)) != 0) { 1.4775 + // Non-aligned; too bad. 1.4776 + // One more chance: Pick off an initial 32-bit word. 1.4777 + // This is a common case, since abase can be odd mod 8. 1.4778 + if (((src_off | dest_off) & (BytesPerLong-1)) == BytesPerInt && 1.4779 + ((src_off ^ dest_off) & (BytesPerLong-1)) == 0) { 1.4780 + Node* sptr = basic_plus_adr(src, src_off); 1.4781 + Node* dptr = basic_plus_adr(dest, dest_off); 1.4782 + Node* sval = make_load(control(), sptr, TypeInt::INT, T_INT, adr_type); 1.4783 + store_to_memory(control(), dptr, sval, T_INT, adr_type); 1.4784 + src_off += BytesPerInt; 1.4785 + dest_off += BytesPerInt; 1.4786 + } else { 1.4787 + return false; 1.4788 + } 1.4789 + } 1.4790 + assert(src_off % BytesPerLong == 0, ""); 1.4791 + assert(dest_off % BytesPerLong == 0, ""); 1.4792 + 1.4793 + // Do this copy by giant steps. 1.4794 + Node* sptr = basic_plus_adr(src, src_off); 1.4795 + Node* dptr = basic_plus_adr(dest, dest_off); 1.4796 + Node* countx = dest_size; 1.4797 + countx = _gvn.transform( new (C, 3) SubXNode(countx, MakeConX(dest_off)) ); 1.4798 + countx = _gvn.transform( new (C, 3) URShiftXNode(countx, intcon(LogBytesPerLong)) ); 1.4799 + 1.4800 + bool disjoint_bases = true; // since alloc != NULL 1.4801 + generate_unchecked_arraycopy(adr_type, T_LONG, disjoint_bases, 1.4802 + sptr, NULL, dptr, NULL, countx); 1.4803 + 1.4804 + return true; 1.4805 +} 1.4806 + 1.4807 + 1.4808 +// Helper function; generates code for the slow case. 1.4809 +// We make a call to a runtime method which emulates the native method, 1.4810 +// but without the native wrapper overhead. 1.4811 +void 1.4812 +LibraryCallKit::generate_slow_arraycopy(const TypePtr* adr_type, 1.4813 + Node* src, Node* src_offset, 1.4814 + Node* dest, Node* dest_offset, 1.4815 + Node* copy_length, 1.4816 + int nargs) { 1.4817 + _sp += nargs; // any deopt will start just before call to enclosing method 1.4818 + Node* call = make_runtime_call(RC_NO_LEAF | RC_UNCOMMON, 1.4819 + OptoRuntime::slow_arraycopy_Type(), 1.4820 + OptoRuntime::slow_arraycopy_Java(), 1.4821 + "slow_arraycopy", adr_type, 1.4822 + src, src_offset, dest, dest_offset, 1.4823 + copy_length); 1.4824 + _sp -= nargs; 1.4825 + 1.4826 + // Handle exceptions thrown by this fellow: 1.4827 + make_slow_call_ex(call, env()->Throwable_klass(), false); 1.4828 +} 1.4829 + 1.4830 +// Helper function; generates code for cases requiring runtime checks. 1.4831 +Node* 1.4832 +LibraryCallKit::generate_checkcast_arraycopy(const TypePtr* adr_type, 1.4833 + Node* dest_elem_klass, 1.4834 + Node* src, Node* src_offset, 1.4835 + Node* dest, Node* dest_offset, 1.4836 + Node* copy_length, 1.4837 + int nargs) { 1.4838 + if (stopped()) return NULL; 1.4839 + 1.4840 + address copyfunc_addr = StubRoutines::checkcast_arraycopy(); 1.4841 + if (copyfunc_addr == NULL) { // Stub was not generated, go slow path. 1.4842 + return NULL; 1.4843 + } 1.4844 + 1.4845 + // Pick out the parameters required to perform a store-check 1.4846 + // for the target array. This is an optimistic check. It will 1.4847 + // look in each non-null element's class, at the desired klass's 1.4848 + // super_check_offset, for the desired klass. 1.4849 + int sco_offset = Klass::super_check_offset_offset_in_bytes() + sizeof(oopDesc); 1.4850 + Node* p3 = basic_plus_adr(dest_elem_klass, sco_offset); 1.4851 + Node* n3 = new(C, 3) LoadINode(NULL, immutable_memory(), p3, TypeRawPtr::BOTTOM); 1.4852 + Node* check_offset = _gvn.transform(n3); 1.4853 + Node* check_value = dest_elem_klass; 1.4854 + 1.4855 + Node* src_start = array_element_address(src, src_offset, T_OBJECT); 1.4856 + Node* dest_start = array_element_address(dest, dest_offset, T_OBJECT); 1.4857 + 1.4858 + // (We know the arrays are never conjoint, because their types differ.) 1.4859 + Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 1.4860 + OptoRuntime::checkcast_arraycopy_Type(), 1.4861 + copyfunc_addr, "checkcast_arraycopy", adr_type, 1.4862 + // five arguments, of which two are 1.4863 + // intptr_t (jlong in LP64) 1.4864 + src_start, dest_start, 1.4865 + copy_length XTOP, 1.4866 + check_offset XTOP, 1.4867 + check_value); 1.4868 + 1.4869 + return _gvn.transform(new (C, 1) ProjNode(call, TypeFunc::Parms)); 1.4870 +} 1.4871 + 1.4872 + 1.4873 +// Helper function; generates code for cases requiring runtime checks. 1.4874 +Node* 1.4875 +LibraryCallKit::generate_generic_arraycopy(const TypePtr* adr_type, 1.4876 + Node* src, Node* src_offset, 1.4877 + Node* dest, Node* dest_offset, 1.4878 + Node* copy_length, 1.4879 + int nargs) { 1.4880 + if (stopped()) return NULL; 1.4881 + 1.4882 + address copyfunc_addr = StubRoutines::generic_arraycopy(); 1.4883 + if (copyfunc_addr == NULL) { // Stub was not generated, go slow path. 1.4884 + return NULL; 1.4885 + } 1.4886 + 1.4887 + Node* call = make_runtime_call(RC_LEAF|RC_NO_FP, 1.4888 + OptoRuntime::generic_arraycopy_Type(), 1.4889 + copyfunc_addr, "generic_arraycopy", adr_type, 1.4890 + src, src_offset, dest, dest_offset, copy_length); 1.4891 + 1.4892 + return _gvn.transform(new (C, 1) ProjNode(call, TypeFunc::Parms)); 1.4893 +} 1.4894 + 1.4895 +// Helper function; generates the fast out-of-line call to an arraycopy stub. 1.4896 +void 1.4897 +LibraryCallKit::generate_unchecked_arraycopy(const TypePtr* adr_type, 1.4898 + BasicType basic_elem_type, 1.4899 + bool disjoint_bases, 1.4900 + Node* src, Node* src_offset, 1.4901 + Node* dest, Node* dest_offset, 1.4902 + Node* copy_length) { 1.4903 + if (stopped()) return; // nothing to do 1.4904 + 1.4905 + Node* src_start = src; 1.4906 + Node* dest_start = dest; 1.4907 + if (src_offset != NULL || dest_offset != NULL) { 1.4908 + assert(src_offset != NULL && dest_offset != NULL, ""); 1.4909 + src_start = array_element_address(src, src_offset, basic_elem_type); 1.4910 + dest_start = array_element_address(dest, dest_offset, basic_elem_type); 1.4911 + } 1.4912 + 1.4913 + // Figure out which arraycopy runtime method to call. 1.4914 + const char* copyfunc_name = "arraycopy"; 1.4915 + address copyfunc_addr = 1.4916 + basictype2arraycopy(basic_elem_type, src_offset, dest_offset, 1.4917 + disjoint_bases, copyfunc_name); 1.4918 + 1.4919 + // Call it. Note that the count_ix value is not scaled to a byte-size. 1.4920 + make_runtime_call(RC_LEAF|RC_NO_FP, 1.4921 + OptoRuntime::fast_arraycopy_Type(), 1.4922 + copyfunc_addr, copyfunc_name, adr_type, 1.4923 + src_start, dest_start, copy_length XTOP); 1.4924 +}