/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "classfile/systemDictionary.hpp"
#include "classfile/vmSymbols.hpp"
#include "compiler/compileBroker.hpp"
#include "compiler/compileLog.hpp"
#include "oops/objArrayKlass.hpp"
#include "opto/addnode.hpp"
#include "opto/callGenerator.hpp"
#include "opto/cfgnode.hpp"
#include "opto/idealKit.hpp"
#include "opto/mulnode.hpp"
#include "opto/runtime.hpp"
#include "opto/subnode.hpp"
#include "prims/nativeLookup.hpp"
#include "runtime/sharedRuntime.hpp"
#include "trace/traceMacros.hpp"
// Extend the set of intrinsics known to the runtime:
public:
private:
bool _is_virtual;
bool _is_predicted;
public:
: InlineCallGenerator(m),
{
}
virtual bool is_intrinsic() const { return true; }
};
// Local helper class for LibraryIntrinsic:
private:
const TypeOopPtr* sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type, bool is_native_ptr = false);
public:
{
// Check if this is a root compile. In that case we don't have a caller.
if (!jvms->has_method()) {
_reexecute_sp = sp();
} else {
// Find out how many arguments the interpreter needs when deoptimizing
// and save the stack pointer value so it can used by uncommon_trap.
// We find the argument count by looking at the declared signature.
bool ignored_will_link;
ciMethod* ignored_callee = caller()->get_method_at_bci(bci(), ignored_will_link, &declared_signature);
}
}
bool try_to_inline();
Node* try_to_predicate();
void push_result() {
// Push the result onto the stack.
}
}
private:
}
// Helper functions to inline natives
// resulting CastII of index:
// resulting CastII of index:
RegionNode* region);
int offset);
offset);
}
offset);
}
int modifier_mask, int modifier_bits,
RegionNode* region);
}
}
}
}
bool is_virtual = false, bool is_static = false);
return generate_method_call(method_id, false, true);
}
return generate_method_call(method_id, true, false);
}
Node * load_field_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString, bool is_exact, bool is_static);
Node* make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2);
bool inline_string_compareTo();
bool inline_string_indexOf();
Node* string_indexOf(Node* string_object, ciTypeArray* target_array, jint offset, jint cache_i, jint md2_i);
bool inline_string_equals();
bool inline_exp();
bool inline_pow();
void finish_pow_exp(Node* result, Node* x, Node* y, const TypeFunc* call_type, address funcAddr, const char* funcName);
// This returns Type::AnyPtr, RawPtr, or OopPtr.
// Helper for inline_unsafe_access.
// Generates the guards that check whether the result of
// Unsafe.getObject should be recorded in an SATB log buffer.
bool inline_unsafe_allocate();
bool inline_unsafe_copyMemory();
bool inline_native_currentThread();
#ifdef TRACE_HAVE_INTRINSICS
bool inline_native_classID();
bool inline_native_threadID();
#endif
bool inline_native_isInterrupted();
bool inline_native_subtype_check();
bool inline_native_newArray();
bool inline_native_getLength();
bool inline_array_copyOf(bool is_copyOfRange);
bool inline_array_equals();
bool inline_native_clone(bool is_virtual);
// Helper function for inlining native object hash method
bool inline_native_getClass();
// Helper functions for inlining arraycopy
bool inline_arraycopy();
bool disjoint_bases = false,
bool length_never_negative = false,
bool disjoint_bases,
bool inline_reference_get();
};
//---------------------------make_vm_intrinsic----------------------------
if (DisableIntrinsic[0] != '\0'
// disabled by a user request on the command line:
// example: -XX:DisableIntrinsic=_hashCode,_getClass
return NULL;
}
if (!m->is_loaded()) {
// do not attempt to inline unloaded methods
return NULL;
}
// Only a few intrinsics implement a virtual dispatch.
// They are expensive calls which are also frequently overridden.
if (is_virtual) {
switch (id) {
case vmIntrinsics::_hashCode:
case vmIntrinsics::_clone:
break;
default:
return NULL;
}
}
// -XX:-InlineNatives disables nearly all intrinsics:
if (!InlineNatives) {
switch (id) {
case vmIntrinsics::_indexOf:
case vmIntrinsics::_compareTo:
case vmIntrinsics::_equals:
case vmIntrinsics::_equalsC:
case vmIntrinsics::_getAndAddInt:
case vmIntrinsics::_getAndAddLong:
case vmIntrinsics::_getAndSetInt:
case vmIntrinsics::_getAndSetLong:
case vmIntrinsics::_getAndSetObject:
break; // InlineNatives does not control String.compareTo
case vmIntrinsics::_Reference_get:
break; // InlineNatives does not control Reference.get
default:
return NULL;
}
}
bool is_predicted = false;
switch (id) {
case vmIntrinsics::_compareTo:
if (!SpecialStringCompareTo) return NULL;
break;
case vmIntrinsics::_indexOf:
if (!SpecialStringIndexOf) return NULL;
break;
case vmIntrinsics::_equals:
if (!SpecialStringEquals) return NULL;
break;
case vmIntrinsics::_equalsC:
if (!SpecialArraysEquals) return NULL;
break;
case vmIntrinsics::_arraycopy:
if (!InlineArrayCopy) return NULL;
break;
case vmIntrinsics::_copyMemory:
if (!InlineArrayCopy) return NULL;
break;
case vmIntrinsics::_hashCode:
if (!InlineObjectHash) return NULL;
break;
case vmIntrinsics::_clone:
case vmIntrinsics::_copyOf:
case vmIntrinsics::_copyOfRange:
if (!InlineObjectCopy) return NULL;
// These also use the arraycopy intrinsic mechanism:
if (!InlineArrayCopy) return NULL;
break;
case vmIntrinsics::_checkIndex:
// We do not intrinsify this. The optimizer does fine with it.
return NULL;
case vmIntrinsics::_getCallerClass:
if (!UseNewReflection) return NULL;
if (!InlineReflectionGetCallerClass) return NULL;
break;
case vmIntrinsics::_bitCount_i:
break;
case vmIntrinsics::_bitCount_l:
break;
break;
break;
break;
break;
case vmIntrinsics::_reverseBytes_c:
break;
case vmIntrinsics::_reverseBytes_s:
break;
case vmIntrinsics::_reverseBytes_i:
break;
case vmIntrinsics::_reverseBytes_l:
break;
case vmIntrinsics::_Reference_get:
// Use the intrinsic version of Reference.get() so that the value in
// the referent field can be registered by the G1 pre-barrier code.
// Also add memory barrier to prevent commoning reads from this field
// across safepoint since GC can change it value.
break;
#ifdef _LP64
#endif
break;
case vmIntrinsics::_compareAndSwapLong:
break;
case vmIntrinsics::_getAndAddInt:
break;
case vmIntrinsics::_getAndAddLong:
break;
case vmIntrinsics::_getAndSetInt:
break;
case vmIntrinsics::_getAndSetLong:
break;
case vmIntrinsics::_getAndSetObject:
#ifdef _LP64
break;
#else
break;
#endif
if (!UseAESIntrinsics) return NULL;
break;
if (!UseAESIntrinsics) return NULL;
// these two require the predicated logic
is_predicted = true;
break;
default:
break;
}
// -XX:-InlineClassNatives disables natives from the Class class.
// The flag applies to all reflective calls, notably Array.newArray
// (visible to Java programmers as Array.newInstance).
if (!InlineClassNatives) return NULL;
}
// -XX:-InlineThreadNatives disables natives from the Thread class.
if (!InlineThreadNatives) return NULL;
}
// -XX:-InlineMathNatives disables natives from the Math,Float and Double classes.
if (!InlineMathNatives) return NULL;
}
// -XX:-InlineUnsafeOps disables natives from the Unsafe class.
if (!InlineUnsafeOps) return NULL;
}
}
//----------------------register_library_intrinsics-----------------------
// Initialize this file's data structures, for each Compile instance.
// Nothing to do here.
}
#ifndef PRODUCT
}
#endif
// Try to inline the intrinsic.
if (kit.try_to_inline()) {
C->print_inlining(callee, jvms->depth() - 1, bci, is_virtual() ? "(intrinsic, virtual)" : "(intrinsic)");
}
if (C->log()) {
}
// Push the result from the inlined method onto the stack.
kit.push_result();
return kit.transfer_exceptions_into_jvms();
}
// The intrinsic bailed out
if (jvms->has_method()) {
// Not a root compile.
const char* msg = is_virtual() ? "failed to inline (intrinsic, virtual)" : "failed to inline (intrinsic)";
} else {
// Root compile
}
}
return NULL;
}
#ifndef PRODUCT
}
#endif
C->print_inlining(callee, jvms->depth() - 1, bci, is_virtual() ? "(intrinsic, virtual)" : "(intrinsic)");
}
if (C->log()) {
}
return slow_ctl; // Could be NULL if the check folds.
}
// The intrinsic bailed out
if (jvms->has_method()) {
// Not a root compile.
} else {
// Root compile
}
}
return NULL;
}
// Handle symbolic names for otherwise undistinguished boolean switches:
const bool is_store = true;
const bool is_native_ptr = true;
const bool is_static = true;
const bool is_volatile = true;
if (!jvms()->has_method()) {
// Root JVMState has a null method.
// Insert the memory aliasing node
}
switch (intrinsic_id()) {
case vmIntrinsics::_dsin:
case vmIntrinsics::_dcos:
case vmIntrinsics::_dtan:
case vmIntrinsics::_dabs:
case vmIntrinsics::_datan2:
case vmIntrinsics::_dsqrt:
case vmIntrinsics::_dexp:
case vmIntrinsics::_dlog:
case vmIntrinsics::_dlog10:
case vmIntrinsics::_min:
case vmIntrinsics::_getObject: return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT, !is_volatile);
case vmIntrinsics::_getBoolean: return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN, !is_volatile);
case vmIntrinsics::_getByte: return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE, !is_volatile);
case vmIntrinsics::_getShort: return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT, !is_volatile);
case vmIntrinsics::_getChar: return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR, !is_volatile);
case vmIntrinsics::_getInt: return inline_unsafe_access(!is_native_ptr, !is_store, T_INT, !is_volatile);
case vmIntrinsics::_getLong: return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG, !is_volatile);
case vmIntrinsics::_getFloat: return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT, !is_volatile);
case vmIntrinsics::_getDouble: return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE, !is_volatile);
case vmIntrinsics::_putObject: return inline_unsafe_access(!is_native_ptr, is_store, T_OBJECT, !is_volatile);
case vmIntrinsics::_putBoolean: return inline_unsafe_access(!is_native_ptr, is_store, T_BOOLEAN, !is_volatile);
case vmIntrinsics::_putByte: return inline_unsafe_access(!is_native_ptr, is_store, T_BYTE, !is_volatile);
case vmIntrinsics::_putShort: return inline_unsafe_access(!is_native_ptr, is_store, T_SHORT, !is_volatile);
case vmIntrinsics::_putChar: return inline_unsafe_access(!is_native_ptr, is_store, T_CHAR, !is_volatile);
case vmIntrinsics::_putInt: return inline_unsafe_access(!is_native_ptr, is_store, T_INT, !is_volatile);
case vmIntrinsics::_putLong: return inline_unsafe_access(!is_native_ptr, is_store, T_LONG, !is_volatile);
case vmIntrinsics::_putFloat: return inline_unsafe_access(!is_native_ptr, is_store, T_FLOAT, !is_volatile);
case vmIntrinsics::_putDouble: return inline_unsafe_access(!is_native_ptr, is_store, T_DOUBLE, !is_volatile);
case vmIntrinsics::_getByte_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_BYTE, !is_volatile);
case vmIntrinsics::_getShort_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_SHORT, !is_volatile);
case vmIntrinsics::_getChar_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_CHAR, !is_volatile);
case vmIntrinsics::_getInt_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_INT, !is_volatile);
case vmIntrinsics::_getLong_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_LONG, !is_volatile);
case vmIntrinsics::_getFloat_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_FLOAT, !is_volatile);
case vmIntrinsics::_getDouble_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_DOUBLE, !is_volatile);
case vmIntrinsics::_getAddress_raw: return inline_unsafe_access( is_native_ptr, !is_store, T_ADDRESS, !is_volatile);
case vmIntrinsics::_putByte_raw: return inline_unsafe_access( is_native_ptr, is_store, T_BYTE, !is_volatile);
case vmIntrinsics::_putShort_raw: return inline_unsafe_access( is_native_ptr, is_store, T_SHORT, !is_volatile);
case vmIntrinsics::_putChar_raw: return inline_unsafe_access( is_native_ptr, is_store, T_CHAR, !is_volatile);
case vmIntrinsics::_putInt_raw: return inline_unsafe_access( is_native_ptr, is_store, T_INT, !is_volatile);
case vmIntrinsics::_putLong_raw: return inline_unsafe_access( is_native_ptr, is_store, T_LONG, !is_volatile);
case vmIntrinsics::_putFloat_raw: return inline_unsafe_access( is_native_ptr, is_store, T_FLOAT, !is_volatile);
case vmIntrinsics::_putDouble_raw: return inline_unsafe_access( is_native_ptr, is_store, T_DOUBLE, !is_volatile);
case vmIntrinsics::_putAddress_raw: return inline_unsafe_access( is_native_ptr, is_store, T_ADDRESS, !is_volatile);
case vmIntrinsics::_getObjectVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_OBJECT, is_volatile);
case vmIntrinsics::_getBooleanVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_BOOLEAN, is_volatile);
case vmIntrinsics::_getByteVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_BYTE, is_volatile);
case vmIntrinsics::_getShortVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_SHORT, is_volatile);
case vmIntrinsics::_getCharVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_CHAR, is_volatile);
case vmIntrinsics::_getIntVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_INT, is_volatile);
case vmIntrinsics::_getLongVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_LONG, is_volatile);
case vmIntrinsics::_getFloatVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_FLOAT, is_volatile);
case vmIntrinsics::_getDoubleVolatile: return inline_unsafe_access(!is_native_ptr, !is_store, T_DOUBLE, is_volatile);
case vmIntrinsics::_putObjectVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_OBJECT, is_volatile);
case vmIntrinsics::_putBooleanVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_BOOLEAN, is_volatile);
case vmIntrinsics::_putByteVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_BYTE, is_volatile);
case vmIntrinsics::_putShortVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_SHORT, is_volatile);
case vmIntrinsics::_putCharVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_CHAR, is_volatile);
case vmIntrinsics::_putIntVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_INT, is_volatile);
case vmIntrinsics::_putLongVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_LONG, is_volatile);
case vmIntrinsics::_putFloatVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_FLOAT, is_volatile);
case vmIntrinsics::_putDoubleVolatile: return inline_unsafe_access(!is_native_ptr, is_store, T_DOUBLE, is_volatile);
case vmIntrinsics::_prefetchRead: return inline_unsafe_prefetch(!is_native_ptr, !is_store, !is_static);
case vmIntrinsics::_prefetchWrite: return inline_unsafe_prefetch(!is_native_ptr, is_store, !is_static);
case vmIntrinsics::_prefetchReadStatic: return inline_unsafe_prefetch(!is_native_ptr, !is_store, is_static);
case vmIntrinsics::_prefetchWriteStatic: return inline_unsafe_prefetch(!is_native_ptr, is_store, is_static);
#ifdef TRACE_HAVE_INTRINSICS
case vmIntrinsics::_counterTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, TRACE_TIME_METHOD), "counterTime");
#endif
case vmIntrinsics::_currentTimeMillis: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeMillis), "currentTimeMillis");
case vmIntrinsics::_nanoTime: return inline_native_time_funcs(CAST_FROM_FN_PTR(address, os::javaTimeNanos), "nanoTime");
case vmIntrinsics::_isInstance:
case vmIntrinsics::_getModifiers:
case vmIntrinsics::_isInterface:
case vmIntrinsics::_isArray:
case vmIntrinsics::_isPrimitive:
case vmIntrinsics::_getSuperclass:
case vmIntrinsics::_getComponentType:
case vmIntrinsics::_floatToRawIntBits:
case vmIntrinsics::_floatToIntBits:
case vmIntrinsics::_intBitsToFloat:
case vmIntrinsics::_doubleToRawLongBits:
case vmIntrinsics::_doubleToLongBits:
case vmIntrinsics::_bitCount_i:
case vmIntrinsics::_bitCount_l:
case vmIntrinsics::_reverseBytes_i:
case vmIntrinsics::_reverseBytes_l:
case vmIntrinsics::_reverseBytes_s:
return inline_cipherBlockChaining_AESCrypt(intrinsic_id());
default:
// If you get here, it may be that someone has added a new intrinsic
// to the list in vmSymbols.hpp without implementing it here.
#ifndef PRODUCT
}
#endif
return false;
}
}
if (!jvms()->has_method()) {
// Root JVMState has a null method.
// Insert the memory aliasing node
}
switch (intrinsic_id()) {
return inline_cipherBlockChaining_AESCrypt_predicate(false);
return inline_cipherBlockChaining_AESCrypt_predicate(true);
default:
// If you get here, it may be that someone has added a new intrinsic
// to the list in vmSymbols.hpp without implementing it here.
#ifndef PRODUCT
}
#endif
return slow_ctl;
}
}
//------------------------------set_result-------------------------------
// Helper function for finishing intrinsics.
}
//------------------------------generate_guard---------------------------
// Helper function for generating guarded fast-slow graph structures.
// The given 'test', if true, guards a slow path. If the test fails
// then a fast path can be taken. (We generally hope it fails.)
// In all cases, GraphKit::control() is updated to the fast path.
// The returned value represents the control for the slow path.
// The return value is never 'top'; it is either a valid control
// or NULL if it is obvious that the slow path can never be taken.
// Also, if region and the slow control are not NULL, the slow edge
// is appended to the region.
if (stopped()) {
// Already short circuited.
return NULL;
}
// Build an if node and its projections.
// If test is true we take the slow path, which we assume is uncommon.
// The slow branch is never taken. No need to build this guard.
return NULL;
}
// The slow branch is never taken. No need to build this guard.
return NULL;
}
return if_slow;
}
}
}
if (stopped())
return NULL; // already stopped
return NULL; // index is already adequately typed
// Emulate effect of Parse::adjust_map_after_if.
}
return is_neg;
}
if (stopped())
return NULL; // already stopped
return NULL; // index is already adequately typed
// Emulate effect of Parse::adjust_map_after_if.
}
return is_notp;
}
// Make sure that 'position' is a valid limit index, in [0..length].
// There are two equivalent plans for checking this:
// A. (offset + copyLength) unsigned<= arrayLength
// B. offset <= (arrayLength - copyLength)
// We require that all of the values above, except for the sum and
// difference, are already known to be non-negative.
// Plan A is robust in the face of overflow, if offset and copyLength
// are both hugely positive.
//
// Plan B is less direct and intuitive, but it does not overflow at
// all, since the difference of two non-negatives is always
// representable. Whenever Java methods must perform the equivalent
// check they generally use Plan B instead of Plan A.
// For the moment we use Plan A.
RegionNode* region) {
if (stopped())
return NULL; // already stopped
return NULL; // common case of whole-array copy
if (!zero_offset) // last += offset
return is_over;
}
//--------------------------generate_current_thread--------------------
const Type* thread_type = TypeOopPtr::make_from_klass(thread_klass)->cast_to_ptr_type(TypePtr::NotNull);
tls_output = thread;
return threadObj;
}
//------------------------------make_string_method_node------------------------
// Helper method for String intrinsic functions. This version is called
// with str1 and str2 pointing to String object nodes.
//
// Get start addr of string
// Get length of string 1
switch (opcode) {
case Op_StrIndexOf:
// Get length of string 2
break;
case Op_StrComp:
// Get length of string 2
break;
case Op_StrEquals:
break;
default:
return NULL;
}
// All these intrinsics have checks.
C->set_has_split_ifs(true); // Has chance for split-if optimization
}
// Helper method for String intrinsic functions. This version is called
// with str1 and str2 pointing to char[] nodes, with cnt1 and cnt2 pointing
// to Int nodes containing the lenghts of str1 and str2.
//
Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2) {
switch (opcode) {
case Op_StrIndexOf:
break;
case Op_StrComp:
break;
case Op_StrEquals:
break;
default:
return NULL;
}
// All these intrinsics have checks.
C->set_has_split_ifs(true); // Has chance for split-if optimization
}
//------------------------------inline_string_compareTo------------------------
// public int java.lang.String.compareTo(String anotherString);
if (stopped()) {
return true;
}
return true;
}
//------------------------------inline_string_equals------------------------
// NOTE: Do not null check argument for String.equals() because spec
// allows to specify NULL as argument.
if (stopped()) {
return true;
}
// paths (plus control) merge
// does source == target string?
// receiver == argument
}
// get String klass for instanceOf
if (!stopped()) {
//instanceOf == true, fallthrough
if (inst_false != NULL) {
}
}
if (!stopped()) {
// Properly cast the argument to String
// This path is taken only when argument's type is String:NotNull.
// Get start addr of receiver
// Get length of receiver
// Get start addr of argument
// Get length of argument
// Check for receiver count != argument count
}
// Check for count == 0 is done by assembler code for StrEquals.
if (!stopped()) {
Node* equals = make_string_method_node(Op_StrEquals, receiver_start, receiver_cnt, argument_start, argument_cnt);
}
}
// post merge
return true;
}
//------------------------------inline_array_equals----------------------------
return true;
}
// Java version of String.indexOf(constant string)
// class StringDecl {
// StringDecl(char[] ca) {
// offset = 0;
// count = ca.length;
// value = ca;
// }
// int offset;
// int count;
// char[] value;
// }
//
// static int string_indexOf_J(StringDecl string_object, char[] target_object,
// int targetOffset, int cache_i, int md2) {
// int cache = cache_i;
// int sourceOffset = string_object.offset;
// int sourceCount = string_object.count;
// int targetCount = target_object.length;
//
// int targetCountLess1 = targetCount - 1;
// int sourceEnd = sourceOffset + sourceCount - targetCountLess1;
//
// char[] source = string_object.value;
// char[] target = target_object;
// int lastChar = target[targetCountLess1];
//
// outer_loop:
// for (int i = sourceOffset; i < sourceEnd; ) {
// int src = source[i + targetCountLess1];
// if (src == lastChar) {
// // With random strings and a 4-character alphabet,
// // reverse matching at this point sets up 0.8% fewer
// // frames, but (paradoxically) makes 0.3% more probes.
// // Since those probes are nearer the lastChar probe,
// // there is may be a net D$ win with reverse matching.
// // But, reversing loop inhibits unroll of inner loop
// // for unknown reason. So, does running outer loop from
// // (sourceOffset - targetCountLess1) to (sourceOffset + sourceCount)
// for (int j = 0; j < targetCountLess1; j++) {
// if (target[targetOffset + j] != source[i+j]) {
// if ((cache & (1 << source[i+j])) == 0) {
// if (md2 < j+1) {
// i += j+1;
// continue outer_loop;
// }
// }
// i += md2;
// continue outer_loop;
// }
// }
// return i - sourceOffset;
// }
// if ((cache & (1 << src)) == 0) {
// i += targetCountLess1;
// } // using "i += targetCount;" and an "else i++;" causes a jump to jump.
// i++;
// }
// return -1;
// }
//------------------------------string_indexOf------------------------
Node* LibraryCallKit::string_indexOf(Node* string_object, ciTypeArray* target_array, jint targetOffset_i,
const TypeAry* target_array_type = TypeAry::make(TypeInt::CHAR, TypeInt::make(0, target_length, Type::WidenMin));
const TypeAryPtr* target_type = TypeAryPtr::make(TypePtr::BotPTR, target_array_type, target_array->klass(), true, Type::OffsetBot);
// pin to prohibit loading of "next iteration" value which may SEGV (rare)
// Final sync IdealKit and GraphKit.
C->set_has_loops(true);
return result;
}
//------------------------------inline_string_indexOf------------------------
// Disable the use of pcmpestri until it can be guaranteed that
// the load doesn't cross into the uncommited space.
// Generate SSE4.2 version of indexOf
// We currently only have match rules that use SSE4.2
if (stopped()) {
return true;
}
// Make the merge point
// Get start addr of source string
// Get length of source string
// Get start addr of substring
// Get length of source string
// Check for substr count > string count
}
if (!stopped()) {
// Check for substr count == 0
}
}
if (!stopped()) {
result = make_string_method_node(Op_StrIndexOf, source_start, source_cnt, substr_start, substr_cnt);
}
} else { // Use LibraryCallKit::string_indexOf
// don't intrinsify if argument isn't a constant string.
return false;
}
return false;
}
return false;
}
int o;
int c;
if (java_lang_String::has_offset_field()) {
} else {
o = 0;
}
// constant strings have no offset and count == length which
// simplifies the resulting code somewhat so lets optimize for that.
return false;
}
// NOTE: No null check on the argument is needed since it's a constant String oop.
if (stopped()) {
return true;
}
// The null string as a pattern always returns 0 (match at beginning of string)
if (c == 0) {
set_result(intcon(0));
return true;
}
// Generate default indexOf
int cache = 0;
int i;
for (i = 0; i < c - 1; i++) {
}
int md2 = c;
for (i = 0; i < c - 1; i++) {
md2 = (c - 1) - i;
}
}
}
return true;
}
//--------------------------round_double_node--------------------------------
// Round a double node if necessary.
return n;
}
//------------------------------inline_math-----------------------------------
// public static double Math.abs(double)
// public static double Math.sqrt(double)
// public static double Math.log(double)
// public static double Math.log10(double)
Node* n;
switch (id) {
default: fatal_unexpected_iid(id); break;
}
return true;
}
//------------------------------inline_trig----------------------------------
switch (id) {
default: fatal_unexpected_iid(id); break;
}
// Rounding required? Check for argument reduction!
// pi/2 in 80-bit extended precision
// static const unsigned char pi_2_bits_x[] = {0x35,0xc2,0x68,0x21,0xa2,0xda,0x0f,0xc9,0xff,0x3f,0x00,0x00,0x00,0x00,0x00,0x00};
// -pi/2 in 80-bit extended precision
// 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};
// Cutoff value for using this argument reduction technique
//static const double pi_2_minus_epsilon = 1.564660403643354;
//static const double neg_pi_2_plus_epsilon = -1.564660403643354;
// Pseudocode for sin:
// if (x <= Math.PI / 4.0) {
// if (x >= -Math.PI / 4.0) return fsin(x);
// if (x >= -Math.PI / 2.0) return -fcos(x + Math.PI / 2.0);
// } else {
// if (x <= Math.PI / 2.0) return fcos(x - Math.PI / 2.0);
// }
// return StrictMath.sin(x);
// Pseudocode for cos:
// if (x <= Math.PI / 4.0) {
// if (x >= -Math.PI / 4.0) return fcos(x);
// if (x >= -Math.PI / 2.0) return fsin(x + Math.PI / 2.0);
// } else {
// if (x <= Math.PI / 2.0) return -fsin(x - Math.PI / 2.0);
// }
// return StrictMath.cos(x);
// Actually, sticking in an 80-bit Intel value into C2 will be tough; it
// requires a special machine instruction to load it. Instead we'll try
// the 'easy' case. If we really need the extra range +/- PI/2 we'll
// probably do the math inside the SIN encoding.
// Make the merge point
// Flatten arg so we need only 1 test
// Node for PI/4 constant
// Check PI/4 : abs(arg)
// Check: If PI/4 < abs(arg) then go slow
// Branch either way
// Set fast path result
// Slow path - non-blocking leaf call
switch (id) {
case vmIntrinsics::_dsin:
break;
case vmIntrinsics::_dcos:
break;
case vmIntrinsics::_dtan:
break;
}
// Post-merge
record_for_igvn(r);
C->set_has_split_ifs(true); // Has chance for split-if optimization
}
set_result(n);
return true;
}
void LibraryCallKit::finish_pow_exp(Node* result, Node* x, Node* y, const TypeFunc* call_type, address funcAddr, const char* funcName) {
//-------------------
//result=(result.isNaN())? funcAddr():result;
// Check: If isNaN() by checking result!=result? then either trap
// or go to runtime
// Build the boolean node
// The pow or exp intrinsic returned a NaN, which requires a call
// to the runtime. Recompile with the runtime call.
}
} else {
// If this inlining ever returned NaN in the past, we compile a call
// to the runtime to properly handle corner cases
#ifdef ASSERT
#endif
} else {
}
}
}
//------------------------------inline_exp-------------------------------------
// Inline exp instructions, if possible. The Intel hardware only misses
// really odd corner cases (+/- Infinity). Just uncommon-trap them.
finish_pow_exp(n, arg, NULL, OptoRuntime::Math_D_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dexp), "EXP");
C->set_has_split_ifs(true); // Has chance for split-if optimization
return true;
}
//------------------------------inline_pow-------------------------------------
// Inline power instructions, if possible.
// Pseudocode for pow
// if (x <= 0.0) {
// long longy = (long)y;
// if ((double)longy == y) { // if y is long
// if (y + 1 == y) longy = 0; // huge number: even
// result = ((1&longy) == 0)?-DPow(abs(x), y):DPow(abs(x), y);
// } else {
// result = NaN;
// }
// } else {
// result = DPow(x,y);
// }
// if (result != result)? {
// result = uncommon_trap() or runtime_call();
// }
// return result;
// Short form: skip the fancy tests and just check for NaN result.
} else {
// If this inlining ever returned NaN in the past, include all
// checks + call to the runtime.
// Set the merge point for If node with condition of (x <= 0.0)
// There are four possible paths to region node and phi node
// Build the first if node: if (x <= 0.0)
// Node for 0 constant
// Check x:0
// Check: If (x<=0) then go complex path
// Branch either way
// Fast path taken; set region slot 3
// Fast path not-taken, i.e. slow path
// Set fast path result
// Complex path
// Build the second if node (if y is long)
// Node for (long)y
// Node for (double)((long) y)
// Check (double)((long) y) : y
// Check if (y isn't long) then go to slow path
// Branch either way
// Calculate DPow(abs(x), y)*(1 & (long)y)
// Node for constant 1
// 1& (long)y
// A huge number is always even. Detect a huge number by checking
// if y + 1 == y and set integer to be tested for parity to 0.
// Required for corner case:
// (long)9.223372036854776E18 = max_jlong
// (double)(long)9.223372036854776E18 = 9.223372036854776E18
// max_jlong is odd but 9.223372036854776E18 is even
if (ConditionalMoveLimit != 0) {
correctedsign = _gvn.transform( CMoveNode::make(C, NULL, bolyplus1, signnode, longcon(0), TypeLong::LONG));
} else {
record_for_igvn(r);
}
// zero node
// Check (1&(long)y)==0?
// Check if (1&(long)y)!=0?, if so the result is negative
// abs(x)
// abs(x)^y
// -abs(x)^y
// (1&(long)y)==1?-DPow(abs(x), y):DPow(abs(x), y)
if (ConditionalMoveLimit != 0) {
} else {
record_for_igvn(r);
}
// Set complex path fast result
// Post merge
record_for_igvn(r);
}
finish_pow_exp(result, x, y, OptoRuntime::Math_DD_D_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::dpow), "POW");
C->set_has_split_ifs(true); // Has chance for split-if optimization
return true;
}
//------------------------------runtime_math-----------------------------
bool LibraryCallKit::runtime_math(const TypeFunc* call_type, address funcAddr, const char* funcName) {
"must be (DD)D or (D)D type");
// Inputs
#ifdef ASSERT
#endif
return true;
}
//------------------------------inline_math_native-----------------------------
switch (id) {
// These intrinsics are not properly supported on all hardware
// These intrinsics are supported on all hardware
// These intrinsics are not yet correctly implemented
case vmIntrinsics::_datan2:
return false;
default:
return false;
}
}
|| n->is_Proj() // parameter or return value
|| n->is_Phi() // local of some sort
);
}
//----------------------------inline_min_max-----------------------------------
return true;
}
Node*
// These are the candidate return value:
return xvalue;
}
// This is not really necessary, but it is consistent with a
// hypothetical MaxINode::Value method:
// %%% This folding logic should (ideally) be in a different place.
// Some should be inside IfNode, and there to be a more reliable
// transformation of ?: style patterns into cmoves. We also want
// Try to find a dominating comparison of these guys.
// It can simplify the index computation for Arrays.copyOf
// and similar uses of System.arraycopy.
// First, compute the normalized version of CmpI(x, y).
if (ideal_cmpxy->is_Cmp()) {
// E.g., if we have CmpI(length - offset, count),
// it might idealize to CmpI(length, count + offset)
}
// Start by locating any relevant comparisons.
}
}
int cmpn;
}
// Look for a dominating test that tells us the min and max.
if (++depth >= 100) break;
// At this point, we know that 'x btest y' is true.
switch (btest) {
// Either value is the answer. Choose the simpler.
return yvalue;
return xvalue;
}
}
}
// We failed to find a dominating test.
// Let's pick a test that might GVN with prior tests.
best_btest = btest;
}
}
}
switch (best_btest) {
default:
cmpxy = ideal_cmpxy;
// and fall through:
break;
break;
}
if (want_max) {
// We can sharpen the minimum.
} else {
// We can sharpen the maximum.
}
// Use a flow-free graph structure, to avoid creating excess control edges
// which could hinder other optimizations.
/*
// This is not as desirable as it may seem, since Min and Max
// nodes do not have a full set of optimizations.
// And they would interfere, anyway, with 'if' optimizations
// and with CMoveI canonical forms.
switch (id) {
case vmIntrinsics::_min:
result_val = _gvn.transform(new (C, 3) MinINode(x,y)); break;
case vmIntrinsics::_max:
result_val = _gvn.transform(new (C, 3) MaxINode(x,y)); break;
default:
ShouldNotReachHere();
}
*/
}
inline int
// Unknown type.
// Since this is a NULL+long form, we have to switch to a rawptr.
} else if (base_type->isa_oopptr()) {
// Base is never null => always a heap address.
}
// Offset is small => always a heap address.
if (offset_type != NULL &&
offset_type->_lo >= 0 &&
}
// Otherwise, it might either be oop+off or NULL+addr.
} else {
// No information:
}
}
} else {
}
}
//--------------------------inline_number_methods-----------------------------
// inline int Integer.numberOfLeadingZeros(int)
// inline int Long.numberOfLeadingZeros(long)
//
// inline int Integer.numberOfTrailingZeros(int)
// inline int Long.numberOfTrailingZeros(long)
//
// inline int Integer.bitCount(int)
// inline int Long.bitCount(long)
//
// inline char Character.reverseBytes(char)
// inline short Short.reverseBytes(short)
// inline int Integer.reverseBytes(int)
// inline long Long.reverseBytes(long)
Node* n;
switch (id) {
default: fatal_unexpected_iid(id); break;
}
return true;
}
//----------------------------inline_unsafe_access----------------------------
// Helper that guards and inserts a pre-barrier.
// We could be accessing the referent field of a reference object. If so, when G1
// is enabled, we need to log the value in the referent field in an SATB buffer.
// This routine performs some compile time filters and generates suitable
// runtime filters that guard the pre-barrier code.
// Also add memory barrier for non volatile load from the referent field
// to prevent commoning of loads across safepoint.
if (!UseG1GC && !need_mem_bar)
return;
// Some compile time checks.
// If offset is a constant, is it java_lang_ref_Reference::_reference_offset?
// Constant offset but not the reference_offset so just return
return;
}
// We only need to generate the runtime guards for instances.
if (btype->isa_aryptr()) {
// Array type so nothing to do
return;
}
// Can the klass of base_oop be statically determined to be
// _not_ a sub-class of Reference and _not_ Object?
return;
}
}
}
// we need to generate the following runtime filters
//
// if (offset == java_lang_ref_Reference::_reference_offset) {
// if (instance_of(base, java.lang.ref.Reference)) {
// pre_barrier(_, pre_val, ...);
// }
// }
// Update graphKit memory and control from IdealKit.
// Update IdealKit memory and control from graphKit.
// is_instof == 0 if base_oop == NULL
// Update graphKit from IdeakKit.
// Use the pre-barrier to record the value in the referent field
pre_barrier(false /* do_load */,
pre_val /* pre_val */,
T_OBJECT);
if (need_mem_bar) {
// Add memory barrier to prevent commoning reads from this field
// across safepoint since GC can change its value.
}
// Update IdealKit from graphKit.
// Final sync IdealKit and GraphKit.
}
// Interpret Unsafe.fieldOffset cookies correctly:
const TypeOopPtr* LibraryCallKit::sharpen_unsafe_type(Compile::AliasType* alias_type, const TypePtr *adr_type, bool is_native_ptr) {
// Attempt to infer a sharper value type from the offset and base type.
// See if it is an instance field, with an object type.
}
}
// See if it is a narrow oop array.
if (adr_type->isa_aryptr()) {
}
}
}
// The sharpened class might be unloaded if there is no class loader
// contraint in place.
#ifndef PRODUCT
}
#endif
// Sharpen the value type.
return tjp;
}
return NULL;
}
bool LibraryCallKit::inline_unsafe_access(bool is_native_ptr, bool is_store, BasicType type, bool is_volatile) {
#ifndef PRODUCT
{
// Check the signatures.
#ifdef ASSERT
if (!is_store) {
if (!is_native_ptr) {
} else {
}
} else {
if (!is_native_ptr) {
} else {
}
}
#endif // ASSERT
}
#endif //PRODUCT
C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
// Build address expression. See the code in inline_unsafe_prefetch.
if (!is_native_ptr) {
// The base is either a Java object or a value produced by Unsafe.staticFieldBase
// The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset
// We currently rely on the cookies produced by Unsafe.xxxFieldOffset
// to be plain byte offsets, which are also the same as those accepted
// by oopDesc::field_base.
"fieldOffset must be byte-scaled");
// 32-bit machines ignore the high half!
} else {
}
// First guess at the value type.
// Try to categorize the address. If it comes up as TypeJavaPtr::BOTTOM,
// there was not enough information to nail it down.
// We will need memory barriers unless we can determine a unique
// alias category for this reference. (Note: If for some reason
// the barriers get omitted and the unsafe reference begins to "pollute"
// the alias analysis of the rest of the graph, either Compile::can_alias
// or Compile::must_alias will throw a diagnostic assert.)
// If we are reading the value of the referent field of a Reference
// object (either by using Unsafe directly or through reflection)
// then, if G1 is enabled, we need to record the referent in an
// SATB log buffer using the pre-barrier mechanism.
// Also we need to add memory barrier to prevent commoning reads
// from this field across safepoint since GC can change its value.
value_type = tjp;
}
}
if (stopped()) {
return true;
}
// Heap pointers get a null-check from the interpreter,
// as a courtesy. However, this is not guaranteed by Unsafe,
// and it is not possible to fully distinguish unintended nulls
// from intended ones in this API.
if (is_volatile) {
// We need to emit leading and trailing CPU membars (see below) in
// addition to memory membars when is_volatile. This is a little
// too strong, but avoids the need to insert per-alias-type
// volatile membars (for stores; compare Parse::do_put_xxx), which
// we cannot do effectively here because we probably only have a
// rough approximation of type.
need_mem_bar = true;
// For Stores, place a memory ordering barrier now.
if (is_store)
}
// Memory barrier to prevent normal and 'unsafe' accesses from
// bypassing each other. Happens after null checks, so the
// exception paths do not take memory state from the memory barrier,
// so there's no problems making a strong assert about mixing users
// of safe & unsafe memory. Otherwise fails in a CTW of rt.jar
// around 5701, class sun/reflect/UnsafeBooleanFieldAccessorImpl.
if (!is_store) {
// load value
switch (type) {
case T_BOOLEAN:
case T_CHAR:
case T_BYTE:
case T_SHORT:
case T_INT:
case T_LONG:
case T_FLOAT:
case T_DOUBLE:
break;
case T_OBJECT:
if (need_read_barrier) {
}
break;
case T_ADDRESS:
// Cast to an int type.
p = ConvX2L(p);
break;
default:
break;
}
// The load node has the control of the preceding MemBarCPUOrder. All
// following nodes will have the control of the MemBarCPUOrder inserted at
// the end of this method. So, pushing the load onto the stack at a later
// point is fine.
set_result(p);
} else {
// place effect of store into memory
switch (type) {
case T_DOUBLE:
break;
case T_ADDRESS:
// Repackage the long as a pointer.
break;
}
} else {
// Possibly an oop being stored to Java heap or native memory
// oop to Java heap.
} else {
// We can't tell at compile time if we are storing in the Java heap or outside
// of it. So we need to emit code to conditionally do the proper type of
// store.
// QQQ who knows what probability is here??
// Sync IdealKit and graphKit.
// Update IdealKit memory.
// Final sync IdealKit and GraphKit.
}
}
}
if (is_volatile) {
if (!is_store)
else
}
return true;
}
//----------------------------inline_unsafe_prefetch----------------------------
#ifndef PRODUCT
{
// Check the signatures.
#ifdef ASSERT
if (!is_native_ptr) {
} else {
}
#endif // ASSERT
}
#endif // !PRODUCT
C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
if (!is_static) {
if (stopped()) {
return true;
}
}
// Build address expression. See the code in inline_unsafe_access.
if (!is_native_ptr) {
// The base is either a Java object or a value produced by Unsafe.staticFieldBase
// The offset is a value produced by Unsafe.staticFieldOffset or Unsafe.objectFieldOffset
// We currently rely on the cookies produced by Unsafe.xxxFieldOffset
// to be plain byte offsets, which are also the same as those accepted
// by oopDesc::field_base.
"fieldOffset must be byte-scaled");
// 32-bit machines ignore the high half!
} else {
}
// Generate the read or write prefetch
if (is_store) {
} else {
}
return true;
}
//----------------------------inline_unsafe_load_store----------------------------
// This method serves a couple of different customers (depending on LoadStoreKind):
//
// LS_cmpxchg:
// public final native boolean compareAndSwapObject(Object o, long offset, Object expected, Object x);
// public final native boolean compareAndSwapInt( Object o, long offset, int expected, int x);
// public final native boolean compareAndSwapLong( Object o, long offset, long expected, long x);
//
// LS_xadd:
// public int getAndAddInt( Object o, long offset, int delta)
// public long getAndAddLong(Object o, long offset, long delta)
//
// LS_xchg:
// int getAndSet(Object o, long offset, int newValue)
// long getAndSet(Object o, long offset, long newValue)
// Object getAndSet(Object o, long offset, Object newValue)
//
// This basic scheme here is the same as inline_unsafe_access, but
// differs in enough details that combining them would make the code
// overly confusing. (This is a true fact! I originally combined
// possible are retained from inline_unsafe_access though to make
// the correspondences clearer. - dl
#ifndef PRODUCT
{
// Check the signatures.
// Check the signatures.
#ifdef ASSERT
assert(sig->type_at(2)->basic_type() == type, "get and set must take expected type as new value/delta");
#endif // ASSERT
} else if (kind == LS_cmpxchg) {
// Check the signatures.
#ifdef ASSERT
#endif // ASSERT
} else {
}
}
#endif //PRODUCT
C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
// Get arguments:
if (kind == LS_cmpxchg) {
}
// Null check receiver.
if (stopped()) {
return true;
}
// Build field offset expression.
// We currently rely on the cookies produced by Unsafe.xxxFieldOffset
// to be plain byte offsets, which are also the same as those accepted
// by oopDesc::field_base.
// 32-bit machines ignore the high half of long offsets
// For CAS, unlike inline_unsafe_access, there seems no point in
// trying to refine types. Just use the coarse types here.
value_type = tjp;
}
}
// Memory-model-wise, a LoadStore acts like a little synchronized
// block, so needs barriers on each side. These don't translate
// into actual barriers on most machines, but we still need rest of
// compiler to respect ordering.
// 4984716: MemBars must be inserted before this
// memory node in order to avoid a false
// dependency which will confuse the scheduler.
// For now, we handle only those cases that actually exist: ints,
// longs, and Object. Adding others should be straightforward.
switch(type) {
case T_INT:
} else if (kind == LS_cmpxchg) {
} else {
}
break;
case T_LONG:
} else if (kind == LS_cmpxchg) {
} else {
}
break;
case T_OBJECT:
// Transformation of a value which could be NULL pointer (CastPP #NULL)
// could be delayed during Parse (for example, in adjust_map_after_if()).
// Execute transformation here to avoid barrier generation in such case.
// Reference stores need a store barrier.
pre_barrier(true /* do_load*/,
NULL /* pre_val*/,
T_OBJECT);
#ifdef _LP64
Node *newval_enc = _gvn.transform(new (C) EncodePNode(newval, newval->bottom_type()->make_narrowoop()));
} else {
Node *oldval_enc = _gvn.transform(new (C) EncodePNode(oldval, oldval->bottom_type()->make_narrowoop()));
newval_enc, oldval_enc));
}
} else
#endif
{
load_store = _gvn.transform(new (C) GetAndSetPNode(control(), mem, adr, newval, adr_type, value_type->is_oopptr()));
} else {
}
}
break;
default:
break;
}
// SCMemProjNodes represent the memory state of a LoadStore. Their
// main role is to prevent LoadStore nodes from being optimized away
// when their results aren't used.
// Add the trailing membar surrounding the access
#ifdef _LP64
}
#endif
assert(type2size[load_store->bottom_type()->basic_type()] == type2size[rtype], "result type should match");
return true;
}
//----------------------------inline_unsafe_ordered_store----------------------
// public native void sun.misc.Unsafe.putOrderedObject(Object o, long offset, Object x);
// public native void sun.misc.Unsafe.putOrderedInt(Object o, long offset, int x);
// public native void sun.misc.Unsafe.putOrderedLong(Object o, long offset, long x);
// This is another variant of inline_unsafe_access, differing in
// that it always issues store-store ("release") barrier and ensures
// store-atomicity (which only matters for "long").
#ifndef PRODUCT
{
// Check the signatures.
#ifdef ASSERT
#endif // ASSERT
}
#endif //PRODUCT
C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
// Get arguments:
// Null check receiver.
if (stopped()) {
return true;
}
// Build field offset expression.
// 32-bit machines ignore the high half of long offsets
// Ensure that the store is atomic for longs:
const bool require_atomic_access = true;
else {
}
return true;
}
//----------------------------inline_unsafe_allocate---------------------------
// public native Object sun.mics.Unsafe.allocateInstance(Class<?> cls);
null_check_receiver(); // null-check, then ignore
if (stopped()) return true;
// Note: The argument might still be an illegal value like
// Serializable.class or Object[].class. The runtime will handle it.
// But we must make an explicit check for initialization.
// Use T_BOOLEAN for instanceKlass::_init_state so the compiler
// can generate code to load it as unsigned byte.
// The 'test' is non-zero if we need to take a slow path.
return true;
}
#ifdef TRACE_HAVE_INTRINSICS
/*
* oop -> myklass
* myklass->trace_id |= USED
* return myklass->trace_id & ~0x3
*/
null_check_receiver(); // null-check, then ignore
return true;
}
} else {
}
return true;
}
#endif
//------------------------inline_native_time_funcs--------------
// inline code for System.currentTimeMillis() and System.nanoTime()
// these have the same type and signature
#ifdef ASSERT
#endif
return true;
}
//------------------------inline_native_currentThread------------------
return true;
}
//------------------------inline_native_isInterrupted------------------
// private native boolean java.lang.Thread.isInterrupted(boolean ClearInterrupted);
// Add a fast path to t.isInterrupted(clear_int):
// (t == Thread.current() && (!TLS._osthread._interrupted || !clear_int))
// ? TLS._osthread._interrupted : /*slow path:*/ t.isInterrupted(clear_int)
// So, in the common case that the interrupt bit is false,
// we avoid making a call into the VM. Even if the interrupt bit
// is true, if the clear_int argument is false, we avoid the VM call.
// However, if the receiver is not currentThread, we must call the VM,
// because there must be some locking done around the operation.
// We only go to the fast case code if we pass two guards.
// Paths which do not pass are accumulated in the slow_region.
enum {
};
// Ensure that it's not possible to move the load of TLS._osthread._interrupted flag
// out of the function.
// (a) Receiving thread must be the current thread.
// (b) Interrupt bit on TLS must be false.
// Set the control input on the field _interrupted read to prevent it floating up.
// First fast path: if (!TLS._interrupted) return false;
// drop through to next case
// (c) Or, if interrupt bit is set and clear_int is false, use 2nd fast path.
// Second fast path: ... else if (!clear_int) return true;
// drop through to next case
// (d) Otherwise, go to the slow path.
if (stopped()) {
// There is no slow path.
} else {
// non-virtual because it is a private non-static
// this->control() comes from set_results_for_java_call
// These two phis are pre-filled with copies of of the fast IO and Memory
}
C->set_has_split_ifs(true); // Has chance for split-if optimization
return true;
}
//---------------------------load_mirror_from_klass----------------------------
// Given a klass oop, load its java mirror (a java.lang.Class oop).
}
//-----------------------load_klass_from_mirror_common-------------------------
// Given a java mirror (a java.lang.Class oop), load its corresponding klass oop.
// Test the klass oop for null (signifying a primitive Class like Integer.TYPE),
// and branch to the given path on the region.
// If never_see_null, take an uncommon trap on null, so we can optimistically
// compile for the non-null case.
// If the region is NULL, force never_see_null = true.
bool never_see_null,
int null_path,
int offset) {
Node* kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, kls_type) );
// Set region->in(null_path) if the mirror is a primitive (e.g, int.class).
} else {
}
return kls;
}
//--------------------(inline_native_Class_query helpers)---------------------
// Use this for JVM_ACC_INTERFACE, JVM_ACC_IS_CLONEABLE, JVM_ACC_HAS_FINALIZER.
// Fall through if (mods & mask) == bits, take the guard otherwise.
Node* LibraryCallKit::generate_access_flags_guard(Node* kls, int modifier_mask, int modifier_bits, RegionNode* region) {
// Branch around if the given klass has the given modifier bit set.
// Like generate_guard, adds a new path onto the region.
}
}
//-------------------------inline_native_Class_query-------------------
switch (id) {
case vmIntrinsics::_isInstance:
// nothing is an instance of a primitive type
prim_return_value = intcon(0);
break;
case vmIntrinsics::_getModifiers:
break;
case vmIntrinsics::_isInterface:
prim_return_value = intcon(0);
break;
case vmIntrinsics::_isArray:
prim_return_value = intcon(0);
expect_prim = true; // cf. ObjectStreamClass.getClassSignature
break;
case vmIntrinsics::_isPrimitive:
expect_prim = true; // obviously
break;
case vmIntrinsics::_getSuperclass:
prim_return_value = null();
break;
case vmIntrinsics::_getComponentType:
prim_return_value = null();
break;
case vmIntrinsics::_getClassAccessFlags:
break;
default:
break;
}
#ifndef PRODUCT
if (k) {
k->print_name();
}
}
#endif
// Null-check the mirror, and the mirror's klass ptr (in case it is a primitive).
// The mirror will never be null of Reflection.getClassAccessFlags, however
// it may be null for Class.isInstance or Class.getModifiers. Throw a NPE
// if it is. See bug 4774291.
// For Reflection.getClassAccessFlags(), the null check occurs in
// the wrong place; see inline_unsafe_access(), above, for a similar
// situation.
// If mirror or obj is dead, only null-path is taken.
if (stopped()) return true;
// Now load the mirror's klass metaobject, and null-check it.
// Side-effects region with the control path if the klass is null.
// If kls is null, we have a primitive mirror.
Node* p; // handy temp
// Now that we have the non-null klass, we can perform the real query.
// For constant classes, the query will constant-fold in LoadNode::Value.
switch (id) {
case vmIntrinsics::_isInstance:
// nothing is an instance of a primitive type
break;
case vmIntrinsics::_getModifiers:
break;
case vmIntrinsics::_isInterface:
// (To verify this code sequence, check the asserts in JVM_IsInterface.)
// A guard was added. If the guard is taken, it was an interface.
// If we fall through, it's a plain class.
query_value = intcon(0);
break;
case vmIntrinsics::_isArray:
// (To verify this code sequence, check the asserts in JVM_IsArrayClass.)
// A guard was added. If the guard is taken, it was an array.
// If we fall through, it's a plain class.
query_value = intcon(0);
break;
case vmIntrinsics::_isPrimitive:
break;
case vmIntrinsics::_getSuperclass:
// The rules here are somewhat unfortunate, but we can still do better
// with random logic than with a JNI call.
// Interfaces store null or Object as _super, but must report null.
// Arrays store an intermediate super as _super, but must report Object.
// Other types can report the actual _super.
// (To verify this code sequence, check the asserts in JVM_IsInterface.)
// A guard was added. If the guard is taken, it was an interface.
// A guard was added. If the guard is taken, it was an array.
// If we fall through, it's a plain class. Get its _super.
kls = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeRawPtr::BOTTOM, TypeKlassPtr::OBJECT_OR_NULL) );
// If the guard is taken, Object.superClass is null (both klass and mirror).
}
if (!stopped()) {
}
break;
case vmIntrinsics::_getComponentType:
// Be sure to pin the oop load to the guard edge just created:
}
break;
case vmIntrinsics::_getClassAccessFlags:
break;
default:
break;
}
// Fall-through is the normal case of a query to a real class.
C->set_has_split_ifs(true); // Has chance for split-if optimization
return true;
}
//--------------------------inline_native_subtype_check------------------------
// This intrinsic takes the JNI calls out of the heart of
// UnsafeFieldAccessorImpl.set, which improves Field.set, readObject, etc.
// Pull both arguments off the stack.
enum {
// A full decision tree on {superc is prim, subc is prim}:
// {P,P} & superc!=subc => false
};
// First null-check both mirrors and load each mirror's klass metaobject.
int which_arg;
if (stopped()) break;
}
// Having loaded both klasses, test each for null.
if (stopped()) break;
}
if (!stopped()) {
// now we have two reference types, in klasses[0..1]
// now we have a successful reference subtype check
}
// If both operands are primitive (both klasses null), then
// we must return true when they are identical primitives.
// It is convenient to test this after the first null klass check.
if (!stopped()) {
// Since superc is primitive, make a guard for the superc==subc case.
// A guard was added. If the added guard is taken, superc==subc.
}
}
// these are the only paths that produce 'true':
// pull together the cases:
}
}
return true;
}
//---------------------generate_array_guard_common------------------------
// Branch around if the given klass is in fact an array (either obj or prim).
// Branch around if the given klass is not an array klass of any kind.
// Branch around if the kls is not an oop array (kls is int[], String, etc.)
// Branch around if the kls is an oop array (Object[] or subtype)
//
// Like generate_guard, adds a new path onto the region.
if (layout_val == NULL) {
return NULL; // never a branch
} else { // always a branch
set_control(top());
return always_branch;
}
}
// Now test the correct condition.
<< Klass::_lh_array_tag_shift)
: Klass::_lh_neutral_value);
// invert the test if we are looking for a non-array
}
//-----------------------inline_native_newArray--------------------------
// private static native Object java.lang.reflect.newArray(Class<?> componentType, int length);
// If mirror or obj is dead, only null-path is taken.
if (stopped()) return true;
// Generate code for the slow case. We make a call to newArray().
if (!stopped()) {
// Either the input type is void.class, or else the
// array klass has not yet been cached. Either the
// ensuing call will throw an exception, or else it
// will cache the array klass for next time.
PreserveJVMState pjvms(this);
// this->control() comes from set_results_for_java_call
}
if (!stopped()) {
// Normal case: The array type has been cached in the java.lang.Class.
// The following call works fine even if the array type is polymorphic.
// It could be a dynamic mix of int[], boolean[], Object[], etc.
}
// Return the combined state.
C->set_has_split_ifs(true); // Has chance for split-if optimization
return true;
}
//----------------------inline_native_getLength--------------------------
// public static native int java.lang.reflect.Array.getLength(Object array);
// If array is dead, only null-path is taken.
if (stopped()) return true;
// Deoptimize if it is a non-array.
PreserveJVMState pjvms(this);
}
// If control is dead, only non-array-path is taken.
if (stopped()) return true;
// The works fine even if the array type is polymorphic.
// It could be a dynamic mix of int[], boolean[], Object[], etc.
C->set_has_split_ifs(true); // Has chance for split-if optimization
return true;
}
//------------------------inline_array_copyOf----------------------------
// public static <T,U> T[] java.util.Arrays.copyOf( U[] original, int newLength, Class<? extends T[]> newType);
// public static <T,U> T[] java.util.Arrays.copyOfRange(U[] original, int from, int to, Class<? extends T[]> newType);
// Get the arguments.
// Set the original stack and the reexecute bit for the interpreter to reexecute
// the bytecode that invokes Arrays.copyOf if deoptimization happens.
{ PreserveReexecuteState preexecs(this);
jvms()->set_should_reexecute(true);
// Check if a null path was taken unconditionally.
if (stopped()) return true;
// Despite the generic type of Arrays.copyOf, the mirror might be int, int[], etc.
// Bail out if that is so.
if (not_objArray != NULL) {
// Improve the klass node's type from the new optimistic assumption:
}
// Bail out if either start or end is negative.
}
// Bail out if length is negative.
// Without this the new_array would throw
// NegativeArraySizeException but IllegalArgumentException is what
// should be thrown
PreserveJVMState pjvms(this);
}
if (!stopped()) {
// How many elements will we copy from the original?
// The answer is MinI(orig_length - start, length).
// Generate a direct call to the right arraycopy function(s).
// We know the copy is disjoint but we might not know if the
// oop stores need checking.
// Extreme case: Arrays.copyOf((Integer[])x, 10, String[].class).
// This will fail a store-check if x contains any non-nulls.
bool disjoint_bases = true;
// if start > orig_length then the length of the copy may be
// negative.
}
} // original reexecute is set back here
C->set_has_split_ifs(true); // Has chance for split-if optimization
if (!stopped()) {
}
return true;
}
//----------------------generate_virtual_guard---------------------------
// Helper for hashCode and clone. Peeks inside the vtable to avoid a call.
// Get the methodOop out of the appropriate vtable entry.
// Compare the target method with the expected method (e.g., Object.hashCode).
}
//-----------------------generate_method_call----------------------------
// Use generate_method_call to make a slow-call to the real
// method if the fast path fails. An alternative would be to
// use a stub like OptoRuntime::slow_arraycopy_Java.
// This only works for expanding the current library call,
// not another intrinsic. (E.g., don't use this for making an
// arraycopy call inside of the copyOf intrinsic.)
// When compiling the intrinsic method itself, do not use this technique.
// ensure the JVMS we have will be correct for this call
if (is_static) {
} else if (is_virtual) {
if (UseInlineCaches) {
// Suppress the vtable call
} else {
// hashCode and clone are not a miranda methods,
// so the vtable index is fixed.
// No need to use the linkResolver to get it.
}
} else { // neither virtual nor static: opt_virtual
slow_call->set_optimized_virtual(true);
}
return slow_call;
}
//------------------------------inline_native_hashcode--------------------
// Build special case code for calls to hashCode on an object.
if (!is_static) {
// Check for hashing null object
obj = null_check_receiver();
if (stopped()) return true; // unconditionally null
} else {
// Do a null check, and return zero if null.
// System.identityHashCode(null) == 0
}
// Unconditionally null? Then return right away.
if (stopped()) {
if (!stopped())
return true;
}
// After null check, get the object's klass.
// This call may be virtual (invokevirtual) or bound (invokespecial).
// For each case we generate slightly different code.
// We only go to the fast case code if we pass a number of guards. The
// paths which do not pass are accumulated in the slow_region.
// If this is a virtual call, we generate a funny guard. We pull out
// the vtable entry corresponding to hashCode() from the target object.
// If the target method which we are calling happens to be the native
// Object hashCode() method, we pass the guard. We do not need this
// guard for non-virtual calls -- the caller is known to be the native
// Object hashCode().
if (is_virtual) {
}
// Get the header out of the object, use LoadMarkNode when available
// Test the header to see if it is unlocked.
// Get the hash value and check to see that it has been properly assigned.
// We depend on hash_mask being at most 32 bits and avoid the use of
// hash_mask_in_place because it could be larger than 32 bits in a 64-bit
// vm: see markOop.hpp.
// This hack lets the hash bits live anywhere in the mark object now, as long
// as the shift drops the relevant bits into the low 32 bits. Note that
// Java spec says that HashCode is an int so there's no point in capturing
// an 'X'-sized hashcode (32 in 32-bit build or 64 in 64-bit build).
// fill in the rest of the null path:
// Generate code for the slow case. We make a call to hashCode().
if (!stopped()) {
// No need for PreserveJVMState, because we're using up the present state.
vmIntrinsics::ID hashCode_id = is_static ? vmIntrinsics::_identityHashCode : vmIntrinsics::_hashCode;
// this->control() comes from set_results_for_java_call
}
// Return the combined state.
return true;
}
//---------------------------inline_native_getClass----------------------------
// public final native Class<?> java.lang.Object.getClass();
//
// Build special case code for calls to getClass on an object.
if (stopped()) return true;
return true;
}
//-----------------inline_native_Reflection_getCallerClass---------------------
// public static native Class<?> sun.reflect.Reflection.getCallerClass(int realFramesToSkip);
//
// In the presence of deep enough inlining, getCallerClass() becomes a no-op.
//
// NOTE that this code must perform the same logic as
// vframeStream::security_get_caller_frame in that it must skip
// Method.invoke() and auxiliary frames.
#ifndef PRODUCT
}
#endif
// The depth value must be a constant in order for the runtime call
// to be eliminated.
#ifndef PRODUCT
}
#endif
return false;
}
// Note that the JVM state at this point does not include the
// getCallerClass() frame which we are trying to inline. The
// semantics of getCallerClass(), however, are that the "first"
// frame is the getCallerClass() frame, so we subtract one from the
// requested depth before continuing. We don't inline requests of
// getCallerClass(0).
if (caller_depth < 0) {
#ifndef PRODUCT
}
#endif
return false;
}
if (!jvms()->has_method()) {
#ifndef PRODUCT
}
#endif
return false;
}
// Walk back up the JVM state to find the caller at the required
// depth. NOTE that this code must perform the same logic as
// vframeStream::security_get_caller_frame in that it must skip
// Method.invoke() and auxiliary frames. Note also that depth is
// 1-based (1 is the bottom of the inlining).
if (inlining_depth > 0) {
caller_jvms = jvms();
do {
// The following if-tests should be performed in this order
// Skip a Method.invoke() or auxiliary frame
} else if (caller_depth > 0) {
// Skip real frame
--caller_depth;
} else {
// We're done: reached desired caller after skipping.
break;
}
} while (inlining_depth > 0);
}
if (inlining_depth == 0) {
#ifndef PRODUCT
tty->print_cr(" Bailing out because caller depth (%d) exceeded inlining depth (%d)", caller_depth_type->get_con(), _depth);
for (int i = _depth; i >= 1; i--) {
}
}
#endif
return false; // Reached end of inlining
}
// Acquire method holder as java.lang.Class
// Push this as a constant
#ifndef PRODUCT
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);
for (int i = _depth; i >= 1; i--) {
}
}
#endif
return true;
}
// Helper routine for above
// Is this the Method.invoke method itself?
return true;
// Is this a helper, defined somewhere underneath MethodAccessorImpl.
if (k->is_instance_klass()) {
return true;
}
}
}
if (method->is_method_handle_intrinsic() ||
// This is an internal adapter frame from the MethodHandleCompiler -- skip it
return true;
}
return false;
}
switch (id) {
case vmIntrinsics::_doubleToLongBits: {
// two paths (plus control) merge in a wood
// Build the boolean node
// Branch either way.
// NaN case is less traveled, which makes all the difference.
// Else fall through
// Post merge
record_for_igvn(r);
C->set_has_split_ifs(true); // Has chance for split-if optimization
break;
}
case vmIntrinsics::_floatToIntBits: {
// two paths (plus control) merge in a wood
// Build the boolean node
// Branch either way.
// NaN case is less traveled, which makes all the difference.
// Else fall through
// Post merge
record_for_igvn(r);
C->set_has_split_ifs(true); // Has chance for split-if optimization
break;
}
default:
break;
}
return true;
}
#ifdef _LP64
#else //_LP64
#endif //_LP64
//----------------------inline_unsafe_copyMemory-------------------------
// public native void sun.misc.Unsafe.copyMemory(Object srcBase, long srcOffset, Object destBase, long destOffset, long bytes);
null_check_receiver(); // null-check receiver
if (stopped()) return true;
C->set_has_unsafe_access(true); // Mark eventual nmethod as "unsafe".
"fieldOffset must be byte-scaled");
// Conservatively insert a memory barrier on all memory slices.
// Do not let writes of the copy source or destination float below the copy.
// Call it. Note that the length argument is not scaled.
"unsafe_arraycopy",
// Do not let reads of the copy destination float above the copy.
return true;
}
//------------------------clone_coping-----------------------------------
// Helper function for inline_native_clone.
void LibraryCallKit::copy_to_clone(Node* obj, Node* alloc_obj, Node* obj_size, bool is_array, bool card_mark) {
if (ReduceBulkZeroing) {
// We will be completely responsible for initializing this object -
// mark Initialize node as complete.
// The object was just allocated - there should be no any stores!
// Mark as complete_with_arraycopy so that on AllocateNode
// expansion, we know this AllocateNode is initialized by an array
// copy and a StoreStore barrier exists after the array copy.
}
// Copy the fastest available way.
// TODO: generate fields copies for small objects instead.
// Exclude the header but include array length to copy by 8 bytes words.
// Can't use base_offset_in_bytes(bt) since basic type is unknown.
// base_off:
// 8 - 32-bit VM
// 12 - 64-bit VM, compressed oops
// 16 - 64-bit VM, normal oops
if (base_off % BytesPerLong != 0) {
if (is_array) {
// Exclude length to copy by 8 bytes words.
base_off += sizeof(int);
} else {
// Include klass to copy by 8 bytes words.
}
}
// Compute the length also, if needed:
bool disjoint_bases = true;
/*dest_uninitialized*/true);
// If necessary, emit some card marks afterwards. (Non-arrays only.)
if (card_mark) {
// Put in store barrier for any and all oops we are sticking
// into this object. (We could avoid this if we could prove
// that the object type contains no oop fields at all.)
false);
}
// Do not let reads from the cloned object float above the arraycopy.
// Do not let stores that initialize this object be reordered with
// a subsequent store that would make this object accessible by
// other threads.
// Record what AllocateNode this StoreStore protects so that
// escape analysis can go from the MemBarStoreStoreNode to the
// AllocateNode and eliminate the MemBarStoreStoreNode if possible
// based on the escape status of the AllocateNode.
} else {
}
}
//------------------------inline_native_clone----------------------------
// protected native Object java.lang.Object.clone();
//
// Here are the simple edge cases:
// null receiver => normal trap
// virtual and clone was overridden => slow path to out-of-line clone
// not cloneable or finalizer => slow path to out-of-line Object.clone
//
// The general case has two steps, allocation and copying.
// Allocation has two cases, and uses GraphKit::new_instance or new_array.
//
// Copying also has two cases, oop arrays and everything else.
// Oop arrays use arrayof_oop_arraycopy (same as System.arraycopy).
// Everything else uses the tight inline loop supplied by CopyArrayNode.
//
// These steps fold up nicely if and when the cloned object's klass
// can be sharply typed as an object array, a type array, or an instance.
//
// Set the reexecute bit for the interpreter to reexecute
// the bytecode that invokes Object.clone if deoptimization happens.
{ PreserveReexecuteState preexecs(this);
jvms()->set_should_reexecute(true);
if (stopped()) return true;
? tklass->as_instance_type()
: TypeInstPtr::NOTNULL);
// Conservatively insert a memory barrier on all memory slices.
// Do not let writes into the original float below the clone.
// paths into result_reg:
enum {
};
// It's an array.
PreserveJVMState pjvms(this);
if (!use_ReduceInitialCardMarks()) {
// If it is an oop array, it requires very special treatment,
// because card marking is required on each card of the array.
PreserveJVMState pjvms2(this);
// Generate a direct call to the right arraycopy function(s).
bool disjoint_bases = true;
bool length_never_negative = true;
}
}
// Otherwise, there are no card marks to worry about.
// (We can dispense with card marks if we know the allocation
// comes out of eden (TLAB)... In fact, ReduceInitialCardMarks
// causes the non-eden paths to take compensating steps to
// simulate a fresh allocation, so that no further
// card marks are required in compiled code to initialize
// the object.)
if (!stopped()) {
// Present the results of the copy.
}
}
// We only go to the instance fast case code if we pass a number of guards.
// The paths which do not pass are accumulated in the slow_region.
if (!stopped()) {
// It's an instance (we did array above). Make the slow-path tests.
// If this is a virtual call, we generate a funny guard. We grab
// the vtable entry corresponding to clone() from the target object.
// If the target method which we are calling happens to be the
// Object clone() method, we pass the guard. We do not need this
// guard for non-virtual calls; the caller is known to be the native
// Object clone().
if (is_virtual) {
}
// The object must be cloneable and must not have a finalizer.
// Both of these conditions may be checked in a single test.
// We could optimize the cloneable test further, but we don't care.
// Test both conditions:
// Must be cloneable but not finalizer:
}
if (!stopped()) {
// It's an instance, and it passed the slow-path tests.
PreserveJVMState pjvms(this);
// Present the results of the slow call.
}
// Generate code for the slow case. We make a call to clone().
if (!stopped()) {
PreserveJVMState pjvms(this);
// this->control() comes from set_results_for_java_call
}
// Return the combined state.
} // original reexecute is set back here
return true;
}
//------------------------------basictype2arraycopy----------------------------
bool disjoint_bases,
const char* &name,
bool dest_uninitialized) {
bool aligned = false;
// if the offsets are the same, we can treat the memory regions as
// disjoint, because either the memory regions are in different arrays,
// or they are identical (which we can treat as disjoint.) We can also
// treat a copy with a destination index less that the source index
// as disjoint since a low->high copy will work correctly in this case.
// both indices are constants
// This can occur if the offsets are identical non-constants.
disjoint = true;
}
}
//------------------------------inline_arraycopy-----------------------
// public static native void java.lang.System.arraycopy(Object src, int srcPos,
// Object dest, int destPos,
// int length);
// Get the arguments.
// Compile time checks. If any of these checks cannot be verified at compile time,
// we do not make a fast path for this call. Instead, we let the call remain as it
// is. The checks we choose to mandate at compile time are:
//
// (1) src and dest are arrays.
// Conservatively insert a memory barrier on all memory slices.
// Do not let writes into the source float below the arraycopy.
// Call StubRoutines::generic_arraycopy stub.
// Do not let reads from the destination float above the arraycopy.
// Since we cannot type the arrays, we don't know which slices
// might be affected. We could restrict this barrier only to those
// memory slices which pertain to array elements--but don't bother.
// (If InsertMemBarAfterArraycopy, there is already one in place.)
return true;
}
// (2) src and dest arrays must have elements of the same BasicType
// Figure out the size and type of the elements we will be copying.
// The component types are not the same or are not recognized. Punt.
// (But, avoid the native method wrapper to JVM_ArrayCopy.)
/*dest_uninitialized*/false);
return true;
}
//---------------------------------------------------------------------------
// We will make a fast path for this call to arraycopy.
// We have the following tests left to perform:
//
// (3) src and dest must not be null.
// (4) src_offset must not be negative.
// (5) dest_offset must not be negative.
// (6) length must not be negative.
// (7) src_offset + length must not exceed length of src.
// (8) dest_offset + length must not exceed length of dest.
// (9) each element of an oop array must be assignable
// (3) operands must not be null
// We currently perform our null checks with the null_check routine.
// This means that the null exceptions will be reported in the caller
// rather than (correctly) reported inside of the native arraycopy call.
// This should be corrected, given time. We do our null check with the
// stack pointer restored.
// (4) src_offset must not be negative.
// (5) dest_offset must not be negative.
// (6) length must not be negative (moved to generate_arraycopy()).
// generate_negative_guard(length, slow_region);
// (7) src_offset + length must not exceed length of src.
// (8) dest_offset + length must not exceed length of dest.
// (9) each element of an oop array must be assignable
// The generate_arraycopy subroutine checks this.
// This is where the memory effects are placed:
false, false, slow_region);
return true;
}
//-----------------------------generate_arraycopy----------------------
// Generate an optimized call to arraycopy.
// Caller must guard against non-arrays.
// Caller must determine a common array basic-type for both arrays.
// Caller must validate offsets against array bounds.
// The slow_region has already collected guard failure paths
// (such as out of bounds length or non-conformable array types).
// The generated code has this shape, in general:
//
// if (length == 0) return // via zero_path
// slowval = -1
// if (types unknown) {
// slowval = call generic copy loop
// if (slowval == 0) return // via checked_path
// } else if (indexes in bounds) {
// if ((is object array) && !(array type check)) {
// slowval = call checked copy loop
// if (slowval == 0) return // via checked_path
// } else {
// call bulk copy loop
// return // via fast_path
// }
// }
// // adjust params for remaining work:
// if (slowval != -1) {
// n = -1^slowval; src_offset += n; dest_offset += n; length -= n
// }
// slow_region:
// call slow arraycopy(src, src_offset, dest, dest_offset, length)
// return // via slow_call_path
//
// This routine is used from several intrinsics: System.arraycopy,
//
void
bool disjoint_bases,
bool length_never_negative,
if (slow_region == NULL) {
}
bool dest_uninitialized = false;
// See if this is the initialization of a newly-allocated array.
// If so, we will take responsibility here for initializing it to zero.
// (Note: Because tightly_coupled_allocation performs checks on the
// out-edges of the dest, we need to avoid making derived pointers
// from it until we have checked its uses.)
&& !ZeroTLAB // pointless if already zeroed
!= NULL)
// "You break it, you buy it."
// From this point on, every exit path is responsible for
// initializing any non-copied parts of the object to zero.
// Also, if this flag is set we make sure that arraycopy interacts properly
// with G1, eliding pre-barriers. See CR 6627983.
dest_uninitialized = true;
} else {
// No zeroing elimination here.
//original_dest = dest;
//dest_uninitialized = false;
}
// Results are placed here:
};
// The slow_control path:
// Checked control path:
if (basic_elem_type == T_CONFLICT) {
checked_control = control();
checked_i_o = i_o();
checked_value = cv;
}
PreserveJVMState pjvms(this);
// (6) length must not be negative.
if (!length_never_negative) {
}
// copy_length is 0.
if (!stopped() && dest_uninitialized) {
// There is no zeroing to do. No need for a secondary raw memory barrier.
} else {
// Clear the whole thing since there are no source elements to copy.
// Use a secondary InitializeNode as raw memory barrier.
// Currently it is needed only on this path since other
// paths have stub or runtime calls as raw memory barriers.
top())->as_Initialize();
}
}
// Present the results of the fast call.
}
if (!stopped() && dest_uninitialized) {
// We have to initialize the *uncopied* part of the array to zero.
// The copy destination is the slice dest[off..off+len]. The other slices
// are dest_head = dest[0..off] and dest_tail = dest[off+len..dest.length].
copy_length) );
// If there is a head section that needs zeroing, do it now.
intcon(0), dest_offset,
NULL);
}
// Next, perform a dynamic check on the tail length.
// It is often zero, and we can win big if we prove this.
// There are two wins: Avoid generating the ClearArray
// with its attendant messy index arithmetic, and upgrade
// the copy to a more hardware-friendly word size of 64 bits.
}
// At this point, let's assume there is no tail.
// There is no tail. Try an upgrade to a 64-bit copy.
bool didit = false;
{ PreserveJVMState pjvms(this);
if (didit) {
// Present the results of the block-copying fast call.
}
}
if (didit)
}
// Clear the tail, if any.
if (notail_ctl == NULL) {
} else {
// Make a local merge.
}
}
}
// If src and dest have compatible element types, we can copy bits.
// Types S[] and D[] are compatible if D is a supertype of S.
//
// If they are not, we will use checked_oop_disjoint_arraycopy,
// which performs a fast optimistic per-oop check, and backs off
// further to JVM_ArrayCopy on the first per-oop check that fails.
// (Actually, we don't move raw bits only; the GC requires card marks.)
// Get the klassOop for both src and dest
// Generate the subtype check.
// This might fold up statically, or then again it might not.
//
// Non-static example: Copying List<String>.elements to a new String[].
// The backing store for a List<String> is always an Object[],
// but its elements are always type String, if the generic types
// are correct at the source level.
//
// Test S[] against D[], not S against D, because (probably)
// the secondary supertype cache is less busy for S[] than S.
// This usually only matters when D is an interface.
// Plug failing path into checked_oop_disjoint_arraycopy
if (not_subtype_ctrl != top()) {
PreserveJVMState pjvms(this);
// (At this point we can assume disjoint_bases, since types differ.)
checked_control = control();
checked_i_o = i_o();
checked_value = cv;
}
// At this point we know we do not need type checks on oop stores.
// Let's see if we need card marks:
// If we do not need card marks, copy using the jint or jlong stub.
"sizes agree");
}
}
if (!stopped()) {
// Generate the fast path, if possible.
PreserveJVMState pjvms(this);
// Present the results of the fast call.
}
// Here are all the slow paths up to this point, in one bundle:
slow_control = top();
if (slow_region != NULL)
if (!stopped()) {
// Clean up after the checked call.
// The returned value is either 0 or -1^K,
// where K = number of partially transferred array elements.
// If it is 0, we are done, so transfer to the end.
// If it is not zero, merge into the slow call.
// We'll restart from the very beginning, after zeroing the whole thing.
// This can cause double writes, but that's OK since dest is brand new.
// So we ignore the low 31 bits of the value returned from the stub.
} else {
// We must continue the copy exactly where it failed, or else
// another thread might see the wrong number of writes to dest.
// Adjust the arguments by the conditionally incoming offset.
// Tweak the node variables to adjust the code produced below:
}
}
if (!stopped()) {
// Generate the slow path, if needed.
if (dest_uninitialized) {
}
copy_length, /*dest_uninitialized*/false);
}
// Remove unused edges.
}
// Finished; return the combined state.
// The memory edges above are precise in order to model effects around
// array copies accurately to allow value numbering of field loads around
// arraycopy. Such field loads, both before and after, are common in Java
//
// But with low number of register or when some registers are used or killed
// by arraycopy calls it causes registers spilling on stack. See 6544710.
// The next memory barrier is added to avoid it. If the arraycopy can be
// optimized away (which it can, sometimes) then we can manually remove
// the membar also.
//
// Do not let reads from the cloned object float above the arraycopy.
// Do not let stores that initialize this object be reordered with
// a subsequent store that would make this object accessible by
// other threads.
// Record what AllocateNode this StoreStore protects so that
// escape analysis can go from the MemBarStoreStoreNode to the
// AllocateNode and eliminate the MemBarStoreStoreNode if possible
// based on the escape status of the AllocateNode.
} else if (InsertMemBarAfterArraycopy)
}
// Helper function which determines if an arraycopy immediately follows
// an allocation, with no intervening tests or other escapes for the object.
// Is the allocation's memory state untouched?
// Bail out if there have been raw-memory effects since the allocation.
// (Example: There might have been a call or safepoint.)
return NULL;
}
return NULL;
}
// There must be no unexpected observers of this allocation.
return NULL;
}
}
// This arraycopy must unconditionally follow the allocation of the ptr.
// There may be guards which feed into the slow_region.
// Any other control flow means that we might not get a chance
// to finish initializing the allocated object.
continue;
}
// One more try: Various low-level checks bottom out in
// uncommon traps. If the debug-info of the trap omits
// any reference to the allocation, as we've already
// observed, then there can be no objection to the trap.
bool found_trap = false;
found_trap = true; break;
}
}
if (found_trap) {
continue;
}
}
return NULL;
}
// If we get this far, we have an allocation which immediately
// precedes the arraycopy, and we can take over zeroing the new object.
// The arraycopy will finish the initialization, and provide
// a new control state to which we will anchor the destination pointer.
return alloc;
}
// Helper for initialization of arrays, creating a ClearArray.
// It writes zero bits in [start..end), within the body of an array object.
// The memory effects are all chained onto the 'adr_type' alias category.
//
// Since the object is otherwise uninitialized, we are free
// to put a little "slop" around the edges of the cleared area,
// as long as it does not go back into the array's header,
// or beyond the array end within the heap.
//
// The lower edge can be rounded down to the nearest jint and the
// upper edge can be rounded up to the nearest MinObjAlignmentInBytes.
//
// Arguments:
// adr_type memory slice where writes are generated
// dest oop of the destination array
// basic_elem_type element type of the destination
// slice_idx array index of first element to store
// slice_len number of elements to store (or NULL)
// dest_size total size in bytes of the array object
//
// Exactly one of slice_len or dest_size must be non-NULL.
// If dest_size is non-NULL, zeroing extends to the end of the object.
// If slice_len is non-NULL, the slice_idx value must be a constant.
void
// one or the other but not both of slice_len and dest_size:
// operate on this memory slice:
// scaling and rounding of indexes:
// determine constant starts and ends
if (slice_len_con == 0) {
return; // nothing to do here
}
if (slice_idx_con >= 0 && slice_len_con >= 0) {
}
// Constant start and end. Simple.
// Constant start, pre-rounded end after the tail of the array.
// Constant start, non-constant end. End needs rounding up.
// End offset = round_up(abase + ((slice_idx_con + slice_len) << scale), 8)
if (scale != 0)
// Non-constant start, pre-rounded end after the tail of the array.
// This is almost certainly a "round-to-end" operation.
if (scale != 0)
// Align up mod 8, then store a jint zero unconditionally
// just before the mod-8 boundary.
bump_bit = 0;
} else {
// Bump 'start' up to (or past) the next jint boundary:
}
// Round bumped 'start' down to jlong boundary in body of array.
if (bump_bit != 0) {
// Store a zero to the immediately preceding jint:
}
}
} else {
// Non-constant start, unrounded non-constant end.
// (Nobody zeroes a random midsection of an array using this routine.)
ShouldNotReachHere(); // fix caller
}
// Done.
}
bool
// See if there is an advantage from block transfer.
if (scale >= LogBytesPerLong)
return false; // it is already a block transfer
// Look at the alignment of the starting offsets.
if (src_off_con < 0 || dest_off_con < 0)
// At present, we can only understand constants.
return false;
// Non-aligned; too bad.
// One more chance: Pick off an initial 32-bit word.
// This is a common case, since abase can be odd mod 8.
src_off += BytesPerInt;
dest_off += BytesPerInt;
} else {
return false;
}
}
// Do this copy by giant steps.
return true;
}
// Helper function; generates code for the slow case.
// We make a call to a runtime method which emulates the native method,
// but without the native wrapper overhead.
void
"slow_arraycopy", adr_type,
// Handle exceptions thrown by this fellow:
}
// Helper function; generates code for cases requiring runtime checks.
Node*
return NULL;
}
// Pick out the parameters required to perform a store-check
// for the target array. This is an optimistic check. It will
// look in each non-null element's class, at the desired klass's
// super_check_offset, for the desired klass.
// (We know the arrays are never conjoint, because their types differ.)
// five arguments, of which two are
// intptr_t (jlong in LP64)
}
// Helper function; generates code for cases requiring runtime checks.
Node*
return NULL;
}
}
// Helper function; generates the fast out-of-line call to an arraycopy stub.
void
bool disjoint_bases,
if (stopped()) return; // nothing to do
}
// Figure out which arraycopy runtime method to call.
// Call it. Note that the count_ix value is not scaled to a byte-size.
}
//----------------------------inline_reference_get----------------------------
// public T java.lang.ref.Reference.get();
// Get the argument:
if (stopped()) return true;
// Use the pre-barrier to record the value in the referent field
pre_barrier(false /* do_load */,
control(),
result /* pre_val */,
T_OBJECT);
// Add memory barrier to prevent commoning reads from this field
// across safepoint since GC can change its value.
return true;
}
Node * LibraryCallKit::load_field_from_object(Node * fromObj, const char * fieldName, const char * fieldTypeString,
// Next code copied from Parse::do_get_xxx():
// Compute address and memory type.
// Build the resultant type of the load
// Build the load.
return loadedField;
}
//------------------------------inline_aescrypt_Block-----------------------
const char *stubName;
switch(id) {
stubName = "aescrypt_encryptBlock";
break;
stubName = "aescrypt_decryptBlock";
break;
}
// (1) src and dest are arrays.
assert (top_src != NULL && top_src->klass() != NULL && top_dest != NULL && top_dest->klass() != NULL, "args are strange");
// for the quick and dirty code we will skip all the checks.
// we are just trying to get the call to be generated.
}
// now need to get the start of its expanded key array
// this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
// Call the stub.
return true;
}
//------------------------------inline_cipherBlockChaining_AESCrypt-----------------------
const char *stubName;
switch(id) {
stubName = "cipherBlockChaining_encryptAESCrypt";
break;
stubName = "cipherBlockChaining_decryptAESCrypt";
break;
}
// (1) src and dest are arrays.
// checks are the responsibility of the caller
}
// if we are in this set of code, we "know" the embeddedCipher is an AESCrypt object
// (because of the predicated logic executed earlier).
// so we cast it here safely.
// this requires a newer class file that has this array as littleEndian ints, otherwise we revert to java
Node* embeddedCipherObj = load_field_from_object(cipherBlockChaining_object, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false);
if (embeddedCipherObj == NULL) return false;
// cast it to what we know it will be at runtime
ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt"));
if (!klass_AESCrypt->is_loaded()) return false;
// we need to get the start of the aescrypt_object's expanded key array
// similarly, get the start address of the r vector
// Call the stub, passing src_start, dest_start, k_start, r_start and src_len
// return is void so no result needs to be pushed
return true;
}
//------------------------------get_key_start_from_aescrypt_object-----------------------
// now have the array, need to get the start address of the K array
return k_start;
}
//----------------------------inline_cipherBlockChaining_AESCrypt_predicate----------------------------
// Return node representing slow path of predicate check.
// the pseudo code we want to emulate with this predicate is:
// for encryption:
// if (embeddedCipherObj instanceof AESCrypt) do_intrinsic, else do_javapath
// for decryption:
// if ((embeddedCipherObj instanceof AESCrypt) && (cipher!=plain)) do_intrinsic, else do_javapath
// note cipher==plain is more conservative than the original java code but that's OK
//
// First, check receiver for NULL since it is virtual method.
// Load embeddedCipher field of CipherBlockChaining object.
Node* embeddedCipherObj = load_field_from_object(objCBC, "embeddedCipher", "Lcom/sun/crypto/provider/SymmetricCipher;", /*is_exact*/ false);
// get AESCrypt klass for instanceOf check
// AESCrypt might not be loaded yet if some other SymmetricCipher got us to this compile point
// will have same classloader as CipherBlockChaining object
// we want to do an instanceof comparison against the AESCrypt class
ciKlass* klass_AESCrypt = tinst->klass()->as_instance_klass()->find_klass(ciSymbol::make("com/sun/crypto/provider/AESCrypt"));
if (!klass_AESCrypt->is_loaded()) {
// if AESCrypt is not even loaded, we never take the intrinsic fast path
return ctrl;
}
// for encryption, we are done
if (!decrypting)
return instof_false; // even if it is NULL
// for decryption, we need to add a further check to avoid
// taking the intrinsic path when cipher and plain are the same
// see the original java code for why.
}