Merge
This commit is contained in:
commit
223668aab4
@ -15318,6 +15318,124 @@ instruct vmul2D(vecX dst, vecX src1, vecX src2)
|
||||
ins_pipe(pipe_class_default);
|
||||
%}
|
||||
|
||||
// --------------------------------- MLA --------------------------------------
|
||||
|
||||
instruct vmla4S(vecD dst, vecD src1, vecD src2)
|
||||
%{
|
||||
predicate(n->as_Vector()->length() == 2 ||
|
||||
n->as_Vector()->length() == 4);
|
||||
match(Set dst (AddVS dst (MulVS src1 src2)));
|
||||
ins_cost(INSN_COST);
|
||||
format %{ "mlav $dst,$src1,$src2\t# vector (4H)" %}
|
||||
ins_encode %{
|
||||
__ mlav(as_FloatRegister($dst$$reg), __ T4H,
|
||||
as_FloatRegister($src1$$reg),
|
||||
as_FloatRegister($src2$$reg));
|
||||
%}
|
||||
ins_pipe(pipe_class_default);
|
||||
%}
|
||||
|
||||
instruct vmla8S(vecX dst, vecX src1, vecX src2)
|
||||
%{
|
||||
predicate(n->as_Vector()->length() == 8);
|
||||
match(Set dst (AddVS dst (MulVS src1 src2)));
|
||||
ins_cost(INSN_COST);
|
||||
format %{ "mlav $dst,$src1,$src2\t# vector (8H)" %}
|
||||
ins_encode %{
|
||||
__ mlav(as_FloatRegister($dst$$reg), __ T8H,
|
||||
as_FloatRegister($src1$$reg),
|
||||
as_FloatRegister($src2$$reg));
|
||||
%}
|
||||
ins_pipe(pipe_class_default);
|
||||
%}
|
||||
|
||||
instruct vmla2I(vecD dst, vecD src1, vecD src2)
|
||||
%{
|
||||
predicate(n->as_Vector()->length() == 2);
|
||||
match(Set dst (AddVI dst (MulVI src1 src2)));
|
||||
ins_cost(INSN_COST);
|
||||
format %{ "mlav $dst,$src1,$src2\t# vector (2S)" %}
|
||||
ins_encode %{
|
||||
__ mlav(as_FloatRegister($dst$$reg), __ T2S,
|
||||
as_FloatRegister($src1$$reg),
|
||||
as_FloatRegister($src2$$reg));
|
||||
%}
|
||||
ins_pipe(pipe_class_default);
|
||||
%}
|
||||
|
||||
instruct vmla4I(vecX dst, vecX src1, vecX src2)
|
||||
%{
|
||||
predicate(n->as_Vector()->length() == 4);
|
||||
match(Set dst (AddVI dst (MulVI src1 src2)));
|
||||
ins_cost(INSN_COST);
|
||||
format %{ "mlav $dst,$src1,$src2\t# vector (4S)" %}
|
||||
ins_encode %{
|
||||
__ mlav(as_FloatRegister($dst$$reg), __ T4S,
|
||||
as_FloatRegister($src1$$reg),
|
||||
as_FloatRegister($src2$$reg));
|
||||
%}
|
||||
ins_pipe(pipe_class_default);
|
||||
%}
|
||||
|
||||
// --------------------------------- MLS --------------------------------------
|
||||
|
||||
instruct vmls4S(vecD dst, vecD src1, vecD src2)
|
||||
%{
|
||||
predicate(n->as_Vector()->length() == 2 ||
|
||||
n->as_Vector()->length() == 4);
|
||||
match(Set dst (SubVS dst (MulVS src1 src2)));
|
||||
ins_cost(INSN_COST);
|
||||
format %{ "mlsv $dst,$src1,$src2\t# vector (4H)" %}
|
||||
ins_encode %{
|
||||
__ mlsv(as_FloatRegister($dst$$reg), __ T4H,
|
||||
as_FloatRegister($src1$$reg),
|
||||
as_FloatRegister($src2$$reg));
|
||||
%}
|
||||
ins_pipe(pipe_class_default);
|
||||
%}
|
||||
|
||||
instruct vmls8S(vecX dst, vecX src1, vecX src2)
|
||||
%{
|
||||
predicate(n->as_Vector()->length() == 8);
|
||||
match(Set dst (SubVS dst (MulVS src1 src2)));
|
||||
ins_cost(INSN_COST);
|
||||
format %{ "mlsv $dst,$src1,$src2\t# vector (8H)" %}
|
||||
ins_encode %{
|
||||
__ mlsv(as_FloatRegister($dst$$reg), __ T8H,
|
||||
as_FloatRegister($src1$$reg),
|
||||
as_FloatRegister($src2$$reg));
|
||||
%}
|
||||
ins_pipe(pipe_class_default);
|
||||
%}
|
||||
|
||||
instruct vmls2I(vecD dst, vecD src1, vecD src2)
|
||||
%{
|
||||
predicate(n->as_Vector()->length() == 2);
|
||||
match(Set dst (SubVI dst (MulVI src1 src2)));
|
||||
ins_cost(INSN_COST);
|
||||
format %{ "mlsv $dst,$src1,$src2\t# vector (2S)" %}
|
||||
ins_encode %{
|
||||
__ mlsv(as_FloatRegister($dst$$reg), __ T2S,
|
||||
as_FloatRegister($src1$$reg),
|
||||
as_FloatRegister($src2$$reg));
|
||||
%}
|
||||
ins_pipe(pipe_class_default);
|
||||
%}
|
||||
|
||||
instruct vmls4I(vecX dst, vecX src1, vecX src2)
|
||||
%{
|
||||
predicate(n->as_Vector()->length() == 4);
|
||||
match(Set dst (SubVI dst (MulVI src1 src2)));
|
||||
ins_cost(INSN_COST);
|
||||
format %{ "mlsv $dst,$src1,$src2\t# vector (4S)" %}
|
||||
ins_encode %{
|
||||
__ mlsv(as_FloatRegister($dst$$reg), __ T4S,
|
||||
as_FloatRegister($src1$$reg),
|
||||
as_FloatRegister($src2$$reg));
|
||||
%}
|
||||
ins_pipe(pipe_class_default);
|
||||
%}
|
||||
|
||||
// --------------------------------- DIV --------------------------------------
|
||||
|
||||
instruct vdiv2F(vecD dst, vecD src1, vecD src2)
|
||||
|
@ -2041,6 +2041,8 @@ public:
|
||||
INSN(addv, 0, 0b100001);
|
||||
INSN(subv, 1, 0b100001);
|
||||
INSN(mulv, 0, 0b100111);
|
||||
INSN(mlav, 0, 0b100101);
|
||||
INSN(mlsv, 1, 0b100101);
|
||||
INSN(sshl, 0, 0b010001);
|
||||
INSN(ushl, 1, 0b010001);
|
||||
|
||||
|
@ -175,9 +175,6 @@ define_pd_global(bool, PreserveFramePointer, false);
|
||||
"Use RTM Xend instead of Xabort when lock busy") \
|
||||
\
|
||||
/* assembler */ \
|
||||
product(bool, Use486InstrsOnly, false, \
|
||||
"Use 80486 Compliant instruction subset") \
|
||||
\
|
||||
product(bool, UseCountLeadingZerosInstruction, false, \
|
||||
"Use count leading zeros instruction") \
|
||||
\
|
||||
|
@ -473,23 +473,21 @@ void VM_Version::get_processor_features() {
|
||||
// i486 internal cache is both I&D and has a 16-byte line size
|
||||
_L1_data_cache_line_size = 16;
|
||||
|
||||
if (!Use486InstrsOnly) {
|
||||
// Get raw processor info
|
||||
// Get raw processor info
|
||||
|
||||
get_cpu_info_stub(&_cpuid_info);
|
||||
get_cpu_info_stub(&_cpuid_info);
|
||||
|
||||
assert_is_initialized();
|
||||
_cpu = extended_cpu_family();
|
||||
_model = extended_cpu_model();
|
||||
_stepping = cpu_stepping();
|
||||
assert_is_initialized();
|
||||
_cpu = extended_cpu_family();
|
||||
_model = extended_cpu_model();
|
||||
_stepping = cpu_stepping();
|
||||
|
||||
if (cpu_family() > 4) { // it supports CPUID
|
||||
_cpuFeatures = feature_flags();
|
||||
// Logical processors are only available on P4s and above,
|
||||
// and only if hyperthreading is available.
|
||||
_logical_processors_per_package = logical_processor_count();
|
||||
_L1_data_cache_line_size = L1_line_size();
|
||||
}
|
||||
if (cpu_family() > 4) { // it supports CPUID
|
||||
_cpuFeatures = feature_flags();
|
||||
// Logical processors are only available on P4s and above,
|
||||
// and only if hyperthreading is available.
|
||||
_logical_processors_per_package = logical_processor_count();
|
||||
_L1_data_cache_line_size = L1_line_size();
|
||||
}
|
||||
|
||||
_supports_cx8 = supports_cmpxchg8();
|
||||
|
@ -29,7 +29,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation functions as an alias for the java.lang.invoke.Stable annotation within JVMCI
|
||||
* This annotation functions as an alias for the jdk.internal.vm.annotation.Stable annotation within JVMCI
|
||||
* code. It is specially recognized during class file parsing in the same way as that annotation.
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
|
@ -22,6 +22,8 @@
|
||||
*/
|
||||
package jdk.vm.ci.inittimer;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* A facility for timing a step in the runtime initialization sequence. This is independent from all
|
||||
* other JVMCI code so as to not perturb the initialization sequence. It is enabled by setting the
|
||||
@ -32,18 +34,26 @@ public final class InitTimer implements AutoCloseable {
|
||||
final long start;
|
||||
|
||||
private InitTimer(String name) {
|
||||
int n = nesting.getAndIncrement();
|
||||
if (n == 0) {
|
||||
initializingThread = Thread.currentThread();
|
||||
System.out.println("INITIALIZING THREAD: " + initializingThread);
|
||||
} else {
|
||||
assert Thread.currentThread() == initializingThread : Thread.currentThread() + " != " + initializingThread;
|
||||
}
|
||||
this.name = name;
|
||||
this.start = System.currentTimeMillis();
|
||||
System.out.println("START: " + SPACES.substring(0, timerDepth * 2) + name);
|
||||
assert Thread.currentThread() == initializingThread : Thread.currentThread() + " != " + initializingThread;
|
||||
timerDepth++;
|
||||
System.out.println("START: " + SPACES.substring(0, n * 2) + name);
|
||||
}
|
||||
|
||||
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "only the initializing thread accesses this field")
|
||||
public void close() {
|
||||
final long end = System.currentTimeMillis();
|
||||
timerDepth--;
|
||||
System.out.println(" DONE: " + SPACES.substring(0, timerDepth * 2) + name + " [" + (end - start) + " ms]");
|
||||
int n = nesting.decrementAndGet();
|
||||
System.out.println(" DONE: " + SPACES.substring(0, n * 2) + name + " [" + (end - start) + " ms]");
|
||||
if (n == 0) {
|
||||
initializingThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static InitTimer timer(String name) {
|
||||
@ -59,19 +69,11 @@ public final class InitTimer implements AutoCloseable {
|
||||
*/
|
||||
private static final boolean ENABLED = Boolean.getBoolean("jvmci.inittimer") || Boolean.getBoolean("jvmci.runtime.TimeInit");
|
||||
|
||||
public static int timerDepth = 0;
|
||||
public static final AtomicInteger nesting = ENABLED ? new AtomicInteger() : null;
|
||||
public static final String SPACES = " ";
|
||||
|
||||
/**
|
||||
* Used to assert the invariant that all initialization happens on the same thread.
|
||||
* Used to assert the invariant that all related initialization happens on the same thread.
|
||||
*/
|
||||
public static final Thread initializingThread;
|
||||
static {
|
||||
if (ENABLED) {
|
||||
initializingThread = Thread.currentThread();
|
||||
System.out.println("INITIALIZING THREAD: " + initializingThread);
|
||||
} else {
|
||||
initializingThread = null;
|
||||
}
|
||||
}
|
||||
public static Thread initializingThread;
|
||||
}
|
||||
|
@ -579,11 +579,8 @@ void ComputeLinearScanOrder::count_edges(BlockBegin* cur, BlockBegin* parent) {
|
||||
assert(is_visited(cur), "block must be visisted when block is active");
|
||||
assert(parent != NULL, "must have parent");
|
||||
|
||||
cur->set(BlockBegin::linear_scan_loop_header_flag);
|
||||
cur->set(BlockBegin::backward_branch_target_flag);
|
||||
|
||||
parent->set(BlockBegin::linear_scan_loop_end_flag);
|
||||
|
||||
// When a loop header is also the start of an exception handler, then the backward branch is
|
||||
// an exception edge. Because such edges are usually critical edges which cannot be split, the
|
||||
// loop must be excluded here from processing.
|
||||
@ -592,6 +589,10 @@ void ComputeLinearScanOrder::count_edges(BlockBegin* cur, BlockBegin* parent) {
|
||||
_iterative_dominators = true;
|
||||
return;
|
||||
}
|
||||
|
||||
cur->set(BlockBegin::linear_scan_loop_header_flag);
|
||||
parent->set(BlockBegin::linear_scan_loop_end_flag);
|
||||
|
||||
assert(parent->number_of_sux() == 1 && parent->sux_at(0) == cur,
|
||||
"loop end blocks must have one successor (critical edges are split)");
|
||||
|
||||
|
@ -3055,13 +3055,16 @@ void LIRGenerator::do_IfOp(IfOp* x) {
|
||||
__ cmove(lir_cond(x->cond()), t_val.result(), f_val.result(), reg, as_BasicType(x->x()->type()));
|
||||
}
|
||||
|
||||
void LIRGenerator::do_RuntimeCall(address routine, int expected_arguments, Intrinsic* x) {
|
||||
assert(x->number_of_arguments() == expected_arguments, "wrong type");
|
||||
LIR_Opr reg = result_register_for(x->type());
|
||||
__ call_runtime_leaf(routine, getThreadTemp(),
|
||||
reg, new LIR_OprList());
|
||||
LIR_Opr result = rlock_result(x);
|
||||
__ move(reg, result);
|
||||
void LIRGenerator::do_RuntimeCall(address routine, Intrinsic* x) {
|
||||
assert(x->number_of_arguments() == 0, "wrong type");
|
||||
// Enforce computation of _reserved_argument_area_size which is required on some platforms.
|
||||
BasicTypeList signature;
|
||||
CallingConvention* cc = frame_map()->c_calling_convention(&signature);
|
||||
LIR_Opr reg = result_register_for(x->type());
|
||||
__ call_runtime_leaf(routine, getThreadTemp(),
|
||||
reg, new LIR_OprList());
|
||||
LIR_Opr result = rlock_result(x);
|
||||
__ move(reg, result);
|
||||
}
|
||||
|
||||
#ifdef TRACE_HAVE_INTRINSICS
|
||||
@ -3115,16 +3118,16 @@ void LIRGenerator::do_Intrinsic(Intrinsic* x) {
|
||||
case vmIntrinsics::_threadID: do_ThreadIDIntrinsic(x); break;
|
||||
case vmIntrinsics::_classID: do_ClassIDIntrinsic(x); break;
|
||||
case vmIntrinsics::_counterTime:
|
||||
do_RuntimeCall(CAST_FROM_FN_PTR(address, TRACE_TIME_METHOD), 0, x);
|
||||
do_RuntimeCall(CAST_FROM_FN_PTR(address, TRACE_TIME_METHOD), x);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case vmIntrinsics::_currentTimeMillis:
|
||||
do_RuntimeCall(CAST_FROM_FN_PTR(address, os::javaTimeMillis), 0, x);
|
||||
do_RuntimeCall(CAST_FROM_FN_PTR(address, os::javaTimeMillis), x);
|
||||
break;
|
||||
|
||||
case vmIntrinsics::_nanoTime:
|
||||
do_RuntimeCall(CAST_FROM_FN_PTR(address, os::javaTimeNanos), 0, x);
|
||||
do_RuntimeCall(CAST_FROM_FN_PTR(address, os::javaTimeNanos), x);
|
||||
break;
|
||||
|
||||
case vmIntrinsics::_Object_init: do_RegisterFinalizer(x); break;
|
||||
|
@ -439,7 +439,7 @@ class LIRGenerator: public InstructionVisitor, public BlockClosure {
|
||||
SwitchRangeArray* create_lookup_ranges(LookupSwitch* x);
|
||||
void do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux);
|
||||
|
||||
void do_RuntimeCall(address routine, int expected_arguments, Intrinsic* x);
|
||||
void do_RuntimeCall(address routine, Intrinsic* x);
|
||||
#ifdef TRACE_HAVE_INTRINSICS
|
||||
void do_ThreadIDIntrinsic(Intrinsic* x);
|
||||
void do_ClassIDIntrinsic(Intrinsic* x);
|
||||
|
@ -1733,11 +1733,11 @@ ClassFileParser::AnnotationCollector::annotation_index(ClassLoaderData* loader_d
|
||||
if (_location != _in_method) break; // only allow for methods
|
||||
if (!privileged) break; // only allow in privileged code
|
||||
return _method_CallerSensitive;
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_ForceInline_signature):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ForceInline_signature):
|
||||
if (_location != _in_method) break; // only allow for methods
|
||||
if (!privileged) break; // only allow in privileged code
|
||||
return _method_ForceInline;
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_DontInline_signature):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_DontInline_signature):
|
||||
if (_location != _in_method) break; // only allow for methods
|
||||
if (!privileged) break; // only allow in privileged code
|
||||
return _method_DontInline;
|
||||
@ -1763,7 +1763,7 @@ ClassFileParser::AnnotationCollector::annotation_index(ClassLoaderData* loader_d
|
||||
if (!privileged) break; // only allow in privileged code
|
||||
return _field_Stable;
|
||||
#endif
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_Stable_signature):
|
||||
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Stable_signature):
|
||||
if (_location != _in_field) break; // only allow for fields
|
||||
if (!privileged) break; // only allow in privileged code
|
||||
return _field_Stable;
|
||||
|
@ -268,6 +268,9 @@
|
||||
\
|
||||
/* Intrinsic Annotation (JDK 9 and above) */ \
|
||||
template(jdk_internal_HotSpotIntrinsicCandidate_signature, "Ljdk/internal/HotSpotIntrinsicCandidate;") \
|
||||
template(jdk_internal_vm_annotation_ForceInline_signature, "Ljdk/internal/vm/annotation/ForceInline;") \
|
||||
template(jdk_internal_vm_annotation_DontInline_signature, "Ljdk/internal/vm/annotation/DontInline;") \
|
||||
template(jdk_internal_vm_annotation_Stable_signature, "Ljdk/internal/vm/annotation/Stable;") \
|
||||
\
|
||||
/* Support for JSR 292 & invokedynamic (JDK 1.7 and above) */ \
|
||||
template(java_lang_invoke_CallSite, "java/lang/invoke/CallSite") \
|
||||
@ -286,10 +289,7 @@
|
||||
template(java_lang_invoke_MethodHandleNatives, "java/lang/invoke/MethodHandleNatives") \
|
||||
template(java_lang_invoke_MethodHandleNatives_CallSiteContext, "java/lang/invoke/MethodHandleNatives$CallSiteContext") \
|
||||
template(java_lang_invoke_LambdaForm, "java/lang/invoke/LambdaForm") \
|
||||
template(java_lang_invoke_ForceInline_signature, "Ljava/lang/invoke/ForceInline;") \
|
||||
template(java_lang_invoke_DontInline_signature, "Ljava/lang/invoke/DontInline;") \
|
||||
template(java_lang_invoke_InjectedProfile_signature, "Ljava/lang/invoke/InjectedProfile;") \
|
||||
template(java_lang_invoke_Stable_signature, "Ljava/lang/invoke/Stable;") \
|
||||
template(java_lang_invoke_LambdaForm_Compiled_signature, "Ljava/lang/invoke/LambdaForm$Compiled;") \
|
||||
template(java_lang_invoke_LambdaForm_Hidden_signature, "Ljava/lang/invoke/LambdaForm$Hidden;") \
|
||||
template(java_lang_invoke_MethodHandleNatives_CallSiteContext_signature, "Ljava/lang/invoke/MethodHandleNatives$CallSiteContext;") \
|
||||
|
@ -2332,11 +2332,22 @@ bool nmethod::detect_scavenge_root_oops() {
|
||||
void nmethod::preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) {
|
||||
#ifndef SHARK
|
||||
if (method() != NULL && !method()->is_native()) {
|
||||
SimpleScopeDesc ssd(this, fr.pc());
|
||||
address pc = fr.pc();
|
||||
SimpleScopeDesc ssd(this, pc);
|
||||
Bytecode_invoke call(ssd.method(), ssd.bci());
|
||||
bool has_receiver = call.has_receiver();
|
||||
bool has_appendix = call.has_appendix();
|
||||
Symbol* signature = call.signature();
|
||||
|
||||
// The method attached by JIT-compilers should be used, if present.
|
||||
// Bytecode can be inaccurate in such case.
|
||||
Method* callee = attached_method_before_pc(pc);
|
||||
if (callee != NULL) {
|
||||
has_receiver = !(callee->access_flags().is_static());
|
||||
has_appendix = false;
|
||||
signature = callee->signature();
|
||||
}
|
||||
|
||||
fr.oops_compiled_arguments_do(signature, has_receiver, has_appendix, reg_map, f);
|
||||
}
|
||||
#endif // !SHARK
|
||||
@ -3526,3 +3537,11 @@ Method* nmethod::attached_method(address call_instr) {
|
||||
return NULL; // not found
|
||||
}
|
||||
|
||||
Method* nmethod::attached_method_before_pc(address pc) {
|
||||
if (NativeCall::is_call_before(pc)) {
|
||||
NativeCall* ncall = nativeCall_before(pc);
|
||||
return attached_method(ncall->instruction_address());
|
||||
}
|
||||
return NULL; // not a call
|
||||
}
|
||||
|
||||
|
@ -512,6 +512,7 @@ class nmethod : public CodeBlob {
|
||||
void copy_values(GrowableArray<Metadata*>* metadata);
|
||||
|
||||
Method* attached_method(address call_pc);
|
||||
Method* attached_method_before_pc(address pc);
|
||||
|
||||
// Relocation support
|
||||
private:
|
||||
|
@ -379,11 +379,12 @@ bool DirectivesParser::set_option(JSON_TYPE t, JSON_VAL* v) {
|
||||
|
||||
const char* error_msg = NULL;
|
||||
if (current_directiveset == NULL) {
|
||||
if (!current_directive->_c1_store->parse_and_add_inline(s, error_msg)) {
|
||||
assert (error_msg != NULL, "Must have valid error message");
|
||||
error(VALUE_ERROR, "Method pattern error: %s", error_msg);
|
||||
}
|
||||
if (!current_directive->_c2_store->parse_and_add_inline(s, error_msg)) {
|
||||
if (current_directive->_c1_store->parse_and_add_inline(s, error_msg)) {
|
||||
if (!current_directive->_c2_store->parse_and_add_inline(s, error_msg)) {
|
||||
assert (error_msg != NULL, "Must have valid error message");
|
||||
error(VALUE_ERROR, "Method pattern error: %s", error_msg);
|
||||
}
|
||||
} else {
|
||||
assert (error_msg != NULL, "Must have valid error message");
|
||||
error(VALUE_ERROR, "Method pattern error: %s", error_msg);
|
||||
}
|
||||
|
@ -1818,10 +1818,9 @@ void PhaseIdealLoop::replace_parallel_iv(IdealLoopTree *loop) {
|
||||
}
|
||||
|
||||
void IdealLoopTree::remove_safepoints(PhaseIdealLoop* phase, bool keep_one) {
|
||||
// Look for a safepoint on the idom-path.
|
||||
Node* keep = NULL;
|
||||
if (keep_one) {
|
||||
// Keep one if possible
|
||||
// Look for a safepoint on the idom-path.
|
||||
for (Node* i = tail(); i != _head; i = phase->idom(i)) {
|
||||
if (i->Opcode() == Op_SafePoint && phase->get_loop(i) == this) {
|
||||
keep = i;
|
||||
@ -1830,9 +1829,14 @@ void IdealLoopTree::remove_safepoints(PhaseIdealLoop* phase, bool keep_one) {
|
||||
}
|
||||
}
|
||||
|
||||
// Don't remove any safepoints if it is requested to keep a single safepoint and
|
||||
// no safepoint was found on idom-path. It is not safe to remove any safepoint
|
||||
// in this case since there's no safepoint dominating all paths in the loop body.
|
||||
bool prune = !keep_one || keep != NULL;
|
||||
|
||||
// Delete other safepoints in this loop.
|
||||
Node_List* sfpts = _safepts;
|
||||
if (sfpts != NULL) {
|
||||
if (prune && sfpts != NULL) {
|
||||
assert(keep == NULL || keep->Opcode() == Op_SafePoint, "not safepoint");
|
||||
for (uint i = 0; i < sfpts->size(); i++) {
|
||||
Node* n = sfpts->at(i);
|
||||
@ -1925,6 +1929,15 @@ void IdealLoopTree::dump_head( ) const {
|
||||
if (cl->is_main_loop()) tty->print(" main");
|
||||
if (cl->is_post_loop()) tty->print(" post");
|
||||
}
|
||||
if (_has_call) tty->print(" has_call");
|
||||
if (_has_sfpt) tty->print(" has_sfpt");
|
||||
if (_rce_candidate) tty->print(" rce");
|
||||
if (_safepts != NULL && _safepts->size() > 0) {
|
||||
tty->print(" sfpts={"); _safepts->dump_simple(); tty->print(" }");
|
||||
}
|
||||
if (_required_safept != NULL && _required_safept->size() > 0) {
|
||||
tty->print(" req={"); _required_safept->dump_simple(); tty->print(" }");
|
||||
}
|
||||
tty->cr();
|
||||
}
|
||||
|
||||
|
@ -2365,6 +2365,17 @@ void Node_List::dump() const {
|
||||
#endif
|
||||
}
|
||||
|
||||
void Node_List::dump_simple() const {
|
||||
#ifndef PRODUCT
|
||||
for( uint i = 0; i < _cnt; i++ )
|
||||
if( _nodes[i] ) {
|
||||
tty->print(" %d", _nodes[i]->_idx);
|
||||
} else {
|
||||
tty->print(" NULL");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
//------------------------------remove-----------------------------------------
|
||||
void Unique_Node_List::remove( Node *n ) {
|
||||
|
@ -1442,6 +1442,7 @@ public:
|
||||
void clear() { _cnt = 0; Node_Array::clear(); } // retain storage
|
||||
uint size() const { return _cnt; }
|
||||
void dump() const;
|
||||
void dump_simple() const;
|
||||
};
|
||||
|
||||
//------------------------------Unique_Node_List-------------------------------
|
||||
|
@ -107,7 +107,8 @@ char* NativeLookup::long_jni_name(const methodHandle& method) {
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void JNICALL JVM_RegisterUnsafeMethods(JNIEnv *env, jclass unsafecls);
|
||||
void JNICALL JVM_RegisterJDKInternalMiscUnsafeMethods(JNIEnv *env, jclass unsafecls);
|
||||
void JNICALL JVM_RegisterSunMiscUnsafeMethods(JNIEnv *env, jclass unsafecls);
|
||||
void JNICALL JVM_RegisterMethodHandleMethods(JNIEnv *env, jclass unsafecls);
|
||||
void JNICALL JVM_RegisterPerfMethods(JNIEnv *env, jclass perfclass);
|
||||
void JNICALL JVM_RegisterWhiteBoxMethods(JNIEnv *env, jclass wbclass);
|
||||
@ -121,8 +122,8 @@ extern "C" {
|
||||
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
|
||||
|
||||
static JNINativeMethod lookup_special_native_methods[] = {
|
||||
{ CC"Java_jdk_internal_misc_Unsafe_registerNatives", NULL, FN_PTR(JVM_RegisterUnsafeMethods) },
|
||||
{ CC"Java_sun_misc_Unsafe_registerNatives", NULL, FN_PTR(JVM_RegisterUnsafeMethods) },
|
||||
{ CC"Java_jdk_internal_misc_Unsafe_registerNatives", NULL, FN_PTR(JVM_RegisterJDKInternalMiscUnsafeMethods) },
|
||||
{ CC"Java_sun_misc_Unsafe_registerNatives", NULL, FN_PTR(JVM_RegisterSunMiscUnsafeMethods) },
|
||||
{ CC"Java_java_lang_invoke_MethodHandleNatives_registerNatives", NULL, FN_PTR(JVM_RegisterMethodHandleMethods) },
|
||||
{ CC"Java_sun_misc_Perf_registerNatives", NULL, FN_PTR(JVM_RegisterPerfMethods) },
|
||||
{ CC"Java_sun_hotspot_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) },
|
||||
|
@ -1227,8 +1227,76 @@ UNSAFE_END
|
||||
{CC "put" #Byte, CC "(" ADR#B ")V", FN_PTR(Unsafe_SetNative##Byte)}
|
||||
|
||||
|
||||
static JNINativeMethod sun_misc_Unsafe_methods[] = {
|
||||
{CC "getObject", CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetObject)},
|
||||
{CC "putObject", CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetObject)},
|
||||
{CC "getObjectVolatile",CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetObjectVolatile)},
|
||||
{CC "putObjectVolatile",CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetObjectVolatile)},
|
||||
|
||||
static JNINativeMethod methods[] = {
|
||||
{CC "getUncompressedObject", CC "(" ADR ")" OBJ, FN_PTR(Unsafe_GetUncompressedObject)},
|
||||
{CC "getJavaMirror", CC "(" ADR ")" CLS, FN_PTR(Unsafe_GetJavaMirror)},
|
||||
{CC "getKlassPointer", CC "(" OBJ ")" ADR, FN_PTR(Unsafe_GetKlassPointer)},
|
||||
|
||||
DECLARE_GETPUTOOP(Boolean, Z),
|
||||
DECLARE_GETPUTOOP(Byte, B),
|
||||
DECLARE_GETPUTOOP(Short, S),
|
||||
DECLARE_GETPUTOOP(Char, C),
|
||||
DECLARE_GETPUTOOP(Int, I),
|
||||
DECLARE_GETPUTOOP(Long, J),
|
||||
DECLARE_GETPUTOOP(Float, F),
|
||||
DECLARE_GETPUTOOP(Double, D),
|
||||
|
||||
DECLARE_GETPUTNATIVE(Byte, B),
|
||||
DECLARE_GETPUTNATIVE(Short, S),
|
||||
DECLARE_GETPUTNATIVE(Char, C),
|
||||
DECLARE_GETPUTNATIVE(Int, I),
|
||||
DECLARE_GETPUTNATIVE(Long, J),
|
||||
DECLARE_GETPUTNATIVE(Float, F),
|
||||
DECLARE_GETPUTNATIVE(Double, D),
|
||||
|
||||
{CC "getAddress", CC "(" ADR ")" ADR, FN_PTR(Unsafe_GetNativeAddress)},
|
||||
{CC "putAddress", CC "(" ADR "" ADR ")V", FN_PTR(Unsafe_SetNativeAddress)},
|
||||
|
||||
{CC "allocateMemory", CC "(J)" ADR, FN_PTR(Unsafe_AllocateMemory)},
|
||||
{CC "reallocateMemory", CC "(" ADR "J)" ADR, FN_PTR(Unsafe_ReallocateMemory)},
|
||||
{CC "freeMemory", CC "(" ADR ")V", FN_PTR(Unsafe_FreeMemory)},
|
||||
|
||||
{CC "objectFieldOffset", CC "(" FLD ")J", FN_PTR(Unsafe_ObjectFieldOffset)},
|
||||
{CC "staticFieldOffset", CC "(" FLD ")J", FN_PTR(Unsafe_StaticFieldOffset)},
|
||||
{CC "staticFieldBase", CC "(" FLD ")" OBJ, FN_PTR(Unsafe_StaticFieldBaseFromField)},
|
||||
{CC "ensureClassInitialized",CC "(" CLS ")V", FN_PTR(Unsafe_EnsureClassInitialized)},
|
||||
{CC "arrayBaseOffset", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayBaseOffset)},
|
||||
{CC "arrayIndexScale", CC "(" CLS ")I", FN_PTR(Unsafe_ArrayIndexScale)},
|
||||
{CC "addressSize", CC "()I", FN_PTR(Unsafe_AddressSize)},
|
||||
{CC "pageSize", CC "()I", FN_PTR(Unsafe_PageSize)},
|
||||
|
||||
{CC "defineClass", CC "(" DC_Args ")" CLS, FN_PTR(Unsafe_DefineClass)},
|
||||
{CC "allocateInstance", CC "(" CLS ")" OBJ, FN_PTR(Unsafe_AllocateInstance)},
|
||||
{CC "throwException", CC "(" THR ")V", FN_PTR(Unsafe_ThrowException)},
|
||||
{CC "compareAndSwapObject", CC "(" OBJ "J" OBJ "" OBJ ")Z", FN_PTR(Unsafe_CompareAndSwapObject)},
|
||||
{CC "compareAndSwapInt", CC "(" OBJ "J""I""I"")Z", FN_PTR(Unsafe_CompareAndSwapInt)},
|
||||
{CC "compareAndSwapLong", CC "(" OBJ "J""J""J"")Z", FN_PTR(Unsafe_CompareAndSwapLong)},
|
||||
{CC "putOrderedObject", CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetOrderedObject)},
|
||||
{CC "putOrderedInt", CC "(" OBJ "JI)V", FN_PTR(Unsafe_SetOrderedInt)},
|
||||
{CC "putOrderedLong", CC "(" OBJ "JJ)V", FN_PTR(Unsafe_SetOrderedLong)},
|
||||
{CC "park", CC "(ZJ)V", FN_PTR(Unsafe_Park)},
|
||||
{CC "unpark", CC "(" OBJ ")V", FN_PTR(Unsafe_Unpark)},
|
||||
|
||||
{CC "getLoadAverage", CC "([DI)I", FN_PTR(Unsafe_Loadavg)},
|
||||
|
||||
{CC "copyMemory", CC "(" OBJ "J" OBJ "JJ)V", FN_PTR(Unsafe_CopyMemory)},
|
||||
{CC "setMemory", CC "(" OBJ "JJB)V", FN_PTR(Unsafe_SetMemory)},
|
||||
|
||||
{CC "defineAnonymousClass", CC "(" DAC_Args ")" CLS, FN_PTR(Unsafe_DefineAnonymousClass)},
|
||||
|
||||
{CC "shouldBeInitialized",CC "(" CLS ")Z", FN_PTR(Unsafe_ShouldBeInitialized)},
|
||||
|
||||
{CC "loadFence", CC "()V", FN_PTR(Unsafe_LoadFence)},
|
||||
{CC "storeFence", CC "()V", FN_PTR(Unsafe_StoreFence)},
|
||||
{CC "fullFence", CC "()V", FN_PTR(Unsafe_FullFence)},
|
||||
};
|
||||
|
||||
static JNINativeMethod jdk_internal_misc_Unsafe_methods[] = {
|
||||
{CC "getObject", CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetObject)},
|
||||
{CC "putObject", CC "(" OBJ "J" OBJ ")V", FN_PTR(Unsafe_SetObject)},
|
||||
{CC "getObjectVolatile",CC "(" OBJ "J)" OBJ "", FN_PTR(Unsafe_GetObjectVolatile)},
|
||||
@ -1316,17 +1384,27 @@ static JNINativeMethod methods[] = {
|
||||
#undef DECLARE_GETPUTNATIVE
|
||||
|
||||
|
||||
// This one function is exported, used by NativeLookup.
|
||||
// These two functions are exported, used by NativeLookup.
|
||||
// The Unsafe_xxx functions above are called only from the interpreter.
|
||||
// The optimizer looks at names and signatures to recognize
|
||||
// individual functions.
|
||||
|
||||
JVM_ENTRY(void, JVM_RegisterUnsafeMethods(JNIEnv *env, jclass unsafeclass))
|
||||
UnsafeWrapper("JVM_RegisterUnsafeMethods");
|
||||
JVM_ENTRY(void, JVM_RegisterSunMiscUnsafeMethods(JNIEnv *env, jclass unsafeclass))
|
||||
UnsafeWrapper("JVM_RegisterSunMiscUnsafeMethods");
|
||||
{
|
||||
ThreadToNativeFromVM ttnfv(thread);
|
||||
|
||||
int ok = env->RegisterNatives(unsafeclass, methods, sizeof(methods)/sizeof(JNINativeMethod));
|
||||
guarantee(ok == 0, "register unsafe natives");
|
||||
int ok = env->RegisterNatives(unsafeclass, sun_misc_Unsafe_methods, sizeof(sun_misc_Unsafe_methods)/sizeof(JNINativeMethod));
|
||||
guarantee(ok == 0, "register sun.misc.Unsafe natives");
|
||||
}
|
||||
JVM_END
|
||||
|
||||
JVM_ENTRY(void, JVM_RegisterJDKInternalMiscUnsafeMethods(JNIEnv *env, jclass unsafeclass))
|
||||
UnsafeWrapper("JVM_RegisterJDKInternalMiscUnsafeMethods");
|
||||
{
|
||||
ThreadToNativeFromVM ttnfv(thread);
|
||||
|
||||
int ok = env->RegisterNatives(unsafeclass, jdk_internal_misc_Unsafe_methods, sizeof(jdk_internal_misc_Unsafe_methods)/sizeof(JNINativeMethod));
|
||||
guarantee(ok == 0, "register jdk.internal.misc.Unsafe natives");
|
||||
}
|
||||
JVM_END
|
||||
|
@ -1078,10 +1078,7 @@ methodHandle SharedRuntime::extract_attached_method(vframeStream& vfst) {
|
||||
address pc = vfst.frame_pc();
|
||||
{ // Get call instruction under lock because another thread may be busy patching it.
|
||||
MutexLockerEx ml_patch(Patching_lock, Mutex::_no_safepoint_check_flag);
|
||||
if (NativeCall::is_call_before(pc)) {
|
||||
NativeCall* ncall = nativeCall_before(pc);
|
||||
return caller_nm->attached_method(ncall->instruction_address());
|
||||
}
|
||||
return caller_nm->attached_method_before_pc(pc);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
* compiler.testlibrary.CompilerUtils compiler.compilercontrol.share.actions.*
|
||||
* @run main ClassFileInstaller sun.hotspot.WhiteBox
|
||||
* sun.hotspot.WhiteBox$WhiteBoxPermission
|
||||
* @run main/othervm compiler.compilercontrol.commands.ExcludeTest
|
||||
* @run main/othervm compiler.compilercontrol.commandfile.ExcludeTest
|
||||
*/
|
||||
|
||||
package compiler.compilercontrol.commandfile;
|
||||
|
@ -24,7 +24,6 @@
|
||||
/*
|
||||
* @test
|
||||
* @bug 8137167
|
||||
* @ignore 8140667
|
||||
* @summary Randomly generates valid commands with random types
|
||||
* @library /testlibrary /../../test/lib /compiler/testlibrary ../share /
|
||||
* @build RandomValidCommandsTest pool.sub.* pool.subpack.* sun.hotspot.WhiteBox
|
||||
|
@ -33,6 +33,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
@ -48,38 +49,12 @@ public abstract class AbstractCommandBuilder
|
||||
@Override
|
||||
public void add(CompileCommand command) {
|
||||
compileCommands.add(command);
|
||||
CommandStateBuilder.getInstance().add(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Executable, State> getStates() {
|
||||
Map<Executable, State> states = new HashMap<>();
|
||||
for (CompileCommand compileCommand : compileCommands) {
|
||||
if (compileCommand.isValid()) {
|
||||
CompileCommand cc = new CompileCommand(compileCommand.command,
|
||||
compileCommand.methodDescriptor,
|
||||
/* CompileCommand option and file doesn't support
|
||||
compiler setting */
|
||||
null,
|
||||
compileCommand.type);
|
||||
MethodDescriptor md = cc.methodDescriptor;
|
||||
for (Pair<Executable, Callable<?>> pair: METHODS) {
|
||||
Executable exec = pair.first;
|
||||
State state = states.getOrDefault(exec, new State());
|
||||
MethodDescriptor execDesc = new MethodDescriptor(exec);
|
||||
// if executable matches regex then apply the state
|
||||
if (execDesc.getCanonicalString().matches(md.getRegexp())) {
|
||||
state.apply(cc);
|
||||
} else {
|
||||
if (cc.command == Command.COMPILEONLY) {
|
||||
state.setC1Compilable(false);
|
||||
state.setC2Compilable(false);
|
||||
}
|
||||
}
|
||||
states.put(exec, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
return states;
|
||||
return CommandStateBuilder.getInstance().getStates();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -89,7 +64,102 @@ public abstract class AbstractCommandBuilder
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
// CompileCommand ignores invalid items
|
||||
// -XX:CompileCommand(File) ignores invalid items
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is an internal class used to build states for commands given from
|
||||
* options and a file. As all commands are added into a single set in
|
||||
* CompilerOracle, we need a class that builds states in the same manner
|
||||
*/
|
||||
private static class CommandStateBuilder {
|
||||
private static final CommandStateBuilder INSTANCE
|
||||
= new CommandStateBuilder();
|
||||
private final List<CompileCommand> optionCommands = new ArrayList<>();
|
||||
private final List<CompileCommand> fileCommands = new ArrayList<>();
|
||||
|
||||
private CommandStateBuilder() { }
|
||||
|
||||
public static CommandStateBuilder getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void add(CompileCommand command) {
|
||||
switch (command.type) {
|
||||
case OPTION:
|
||||
optionCommands.add(command);
|
||||
break;
|
||||
case FILE:
|
||||
fileCommands.add(command);
|
||||
break;
|
||||
default:
|
||||
throw new Error("TESTBUG: wrong type: " + command.type);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Executable, State> getStates() {
|
||||
List<CompileCommand> commandList = new ArrayList<>();
|
||||
commandList.addAll(optionCommands);
|
||||
commandList.addAll(fileCommands);
|
||||
Map<Executable, State> states = new HashMap<>();
|
||||
for (Pair<Executable, Callable<?>> pair : METHODS) {
|
||||
Executable exec = pair.first;
|
||||
State state = getState(commandList, states, exec);
|
||||
states.put(exec, state);
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
private State getState(List<CompileCommand> commandList,
|
||||
Map<Executable, State> states, Executable exec) {
|
||||
State state = states.getOrDefault(exec, new State());
|
||||
MethodDescriptor execDesc = new MethodDescriptor(exec);
|
||||
for (CompileCommand compileCommand : commandList) {
|
||||
if (compileCommand.isValid()) {
|
||||
// Create a copy without compiler set
|
||||
CompileCommand cc = new CompileCommand(
|
||||
compileCommand.command,
|
||||
compileCommand.methodDescriptor,
|
||||
/* CompileCommand option and file doesn't support
|
||||
compiler setting */
|
||||
null,
|
||||
compileCommand.type);
|
||||
MethodDescriptor md = cc.methodDescriptor;
|
||||
// if executable matches regex then apply the state
|
||||
if (execDesc.getCanonicalString().matches(md.getRegexp())) {
|
||||
if (cc.command == Command.COMPILEONLY
|
||||
&& !state.isCompilable()) {
|
||||
/* if the method was already excluded it will not
|
||||
be compilable again */
|
||||
} else {
|
||||
state.apply(cc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set compilation states for methods that don't match
|
||||
* any compileonly command. Such methods should be excluded
|
||||
* from compilation
|
||||
*/
|
||||
for (CompileCommand compileCommand : commandList) {
|
||||
if (compileCommand.isValid()
|
||||
&& (compileCommand.command == Command.COMPILEONLY)) {
|
||||
MethodDescriptor md = compileCommand.methodDescriptor;
|
||||
if (!execDesc.getCanonicalString().matches(md.getRegexp())
|
||||
&& (state.getCompilableOptional(
|
||||
// no matter C1, C2 or both
|
||||
Scenario.Compiler.C2).isPresent())) {
|
||||
/* compileonly excludes only methods that haven't been
|
||||
already set to be compilable or excluded */
|
||||
state.setC1Compilable(false);
|
||||
state.setC2Compilable(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,6 +135,10 @@ public class State {
|
||||
+ "\nprint_inline " + printInline;
|
||||
}
|
||||
|
||||
public Optional<Boolean> getCompilableOptional(Scenario.Compiler compiler) {
|
||||
return compile[compiler.ordinal()];
|
||||
}
|
||||
|
||||
public boolean isC1Compilable() {
|
||||
return compile[Scenario.Compiler.C1.ordinal()].orElse(true);
|
||||
}
|
||||
|
@ -22,7 +22,6 @@
|
||||
*/
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Agent {
|
||||
|
@ -24,8 +24,8 @@
|
||||
/*
|
||||
* @test
|
||||
* @bug 8072008
|
||||
* @library /testlibrary /../../test/lib
|
||||
* @build GCTest NonInlinedReinvoker
|
||||
* @library /testlibrary /test/lib
|
||||
* @compile GCTest.java NonInlinedReinvoker.java
|
||||
* @run main ClassFileInstaller sun.hotspot.WhiteBox
|
||||
* sun.hotspot.WhiteBox$WhiteBoxPermission
|
||||
* java.lang.invoke.GCTest
|
||||
@ -40,7 +40,8 @@
|
||||
package java.lang.invoke;
|
||||
|
||||
import sun.hotspot.WhiteBox;
|
||||
|
||||
import jdk.internal.vm.annotation.DontInline;
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
import java.lang.ref.*;
|
||||
import static jdk.test.lib.Asserts.*;
|
||||
|
||||
|
@ -24,8 +24,8 @@
|
||||
/*
|
||||
* @test
|
||||
* @bug 8072008
|
||||
* @library /testlibrary /../../test/lib
|
||||
* @build InvokeTest NonInlinedReinvoker
|
||||
* @library /testlibrary /test/lib
|
||||
* @compile InvokeTest.java NonInlinedReinvoker.java
|
||||
* @run main ClassFileInstaller sun.hotspot.WhiteBox
|
||||
* sun.hotspot.WhiteBox$WhiteBoxPermission
|
||||
* java.lang.invoke.InvokeTest
|
||||
@ -43,6 +43,7 @@
|
||||
package java.lang.invoke;
|
||||
|
||||
import sun.hotspot.WhiteBox;
|
||||
import jdk.internal.vm.annotation.DontInline;
|
||||
import static jdk.test.lib.Asserts.*;
|
||||
|
||||
public class InvokeTest {
|
||||
@ -73,23 +74,23 @@ public class InvokeTest {
|
||||
}
|
||||
|
||||
static class T implements I {
|
||||
@DontInline public Class<?> f1() { if (doDeopt) WB.deoptimize(); return T.class; }
|
||||
@DontInline public static Class<?> f2() { if (doDeopt) WB.deoptimize(); return T.class; }
|
||||
@DontInline private Class<?> f4() { if (doDeopt) WB.deoptimize(); return T.class; }
|
||||
@DontInline public Class<?> f1() { if (doDeopt) WB.deoptimizeAll(); return T.class; }
|
||||
@DontInline public static Class<?> f2() { if (doDeopt) WB.deoptimizeAll(); return T.class; }
|
||||
@DontInline private Class<?> f4() { if (doDeopt) WB.deoptimizeAll(); return T.class; }
|
||||
}
|
||||
|
||||
static class P1 extends T {
|
||||
@DontInline public Class<?> f1() { if (doDeopt) WB.deoptimize(); return P1.class; }
|
||||
@DontInline public Class<?> f3() { if (doDeopt) WB.deoptimize(); return P1.class; }
|
||||
@DontInline public Class<?> f1() { if (doDeopt) WB.deoptimizeAll(); return P1.class; }
|
||||
@DontInline public Class<?> f3() { if (doDeopt) WB.deoptimizeAll(); return P1.class; }
|
||||
}
|
||||
|
||||
static class P2 extends T {
|
||||
@DontInline public Class<?> f1() { if (doDeopt) WB.deoptimize(); return P2.class; }
|
||||
@DontInline public Class<?> f3() { if (doDeopt) WB.deoptimize(); return P2.class; }
|
||||
@DontInline public Class<?> f1() { if (doDeopt) WB.deoptimizeAll(); return P2.class; }
|
||||
@DontInline public Class<?> f3() { if (doDeopt) WB.deoptimizeAll(); return P2.class; }
|
||||
}
|
||||
|
||||
static interface I {
|
||||
@DontInline default Class<?> f3() { if (doDeopt) WB.deoptimize(); return I.class; }
|
||||
@DontInline default Class<?> f3() { if (doDeopt) WB.deoptimizeAll(); return I.class; }
|
||||
}
|
||||
|
||||
@DontInline
|
||||
|
@ -24,8 +24,8 @@
|
||||
/*
|
||||
* @test
|
||||
* @bug 8072008
|
||||
* @library /testlibrary /../../test/lib
|
||||
* @build RedefineTest Agent
|
||||
* @library /testlibrary /test/lib
|
||||
* @compile -XDignore.symbol.file RedefineTest.java Agent.java
|
||||
* @run main ClassFileInstaller sun.hotspot.WhiteBox
|
||||
* sun.hotspot.WhiteBox$WhiteBoxPermission
|
||||
* java.lang.invoke.RedefineTest
|
||||
@ -42,9 +42,8 @@ package java.lang.invoke;
|
||||
|
||||
import sun.hotspot.WhiteBox;
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
import jdk.internal.org.objectweb.asm.*;
|
||||
|
||||
import jdk.internal.vm.annotation.DontInline;
|
||||
import java.lang.instrument.ClassDefinition;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
|
||||
@ -73,7 +72,7 @@ public class RedefineTest {
|
||||
cw.visit(52, ACC_PUBLIC | ACC_SUPER, NAME, null, "java/lang/Object", null);
|
||||
{
|
||||
mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "f", "()I", null, null);
|
||||
mv.visitAnnotation("Ljava/lang/invoke/DontInline;", true);
|
||||
mv.visitAnnotation("Ljdk/internal/vm/annotation/DontInline;", true);
|
||||
mv.visitCode();
|
||||
mv.visitLdcInsn(r);
|
||||
mv.visitInsn(IRETURN);
|
||||
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
super public class TestRangeCheckExceptionHandlerLoop
|
||||
version 51:0
|
||||
{
|
||||
|
||||
|
||||
public Method "<init>":"()V"
|
||||
stack 1 locals 1
|
||||
{
|
||||
aload_0;
|
||||
invokespecial Method java/lang/Object."<init>":"()V";
|
||||
return;
|
||||
}
|
||||
|
||||
/* This method has an irreducible loop, with 2 entries, one is the exception handler
|
||||
|
||||
static void test(boolean flag, int[] array, Exception exception) throws Exception {
|
||||
int i = 0;
|
||||
if (flag) {
|
||||
try {
|
||||
throw exception;
|
||||
} catch(Exception e) {
|
||||
array[i] = 0;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (i < 10) {
|
||||
throw exception; // caught by exception handler above as well
|
||||
}
|
||||
}
|
||||
*/
|
||||
public static Method test:"(Z[ILjava/lang/Exception;)V"
|
||||
throws java/lang/Exception
|
||||
stack 3 locals 5
|
||||
{
|
||||
iconst_0;
|
||||
istore_3;
|
||||
iload_0;
|
||||
ifeq L17;
|
||||
try t0;
|
||||
aload_2;
|
||||
athrow;
|
||||
endtry t0;
|
||||
catch t0 java/lang/Exception;
|
||||
catch t1 java/lang/Exception;
|
||||
stack_frame_type full;
|
||||
locals_map int, class "[I", class java/lang/Exception, int;
|
||||
stack_map class java/lang/Exception;
|
||||
astore 4;
|
||||
aload_1;
|
||||
iload_3;
|
||||
iconst_0;
|
||||
iastore;
|
||||
iinc 3, 1;
|
||||
L17: stack_frame_type same;
|
||||
iload_3;
|
||||
bipush 10;
|
||||
if_icmpge L25;
|
||||
try t1;
|
||||
aload_2;
|
||||
athrow;
|
||||
endtry t1;
|
||||
L25: stack_frame_type same;
|
||||
return;
|
||||
}
|
||||
} // end Class TestRangeCheckExceptionHandlerLoop
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8134883
|
||||
* @summary C1's range check elimination breaks with a non-natural loop that an exception handler as one entry
|
||||
* @compile TestRangeCheckExceptionHandlerLoop.jasm
|
||||
* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestRangeCheckExceptionHandlerLoopMain
|
||||
*/
|
||||
|
||||
public class TestRangeCheckExceptionHandlerLoopMain {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Exception exception = new Exception();
|
||||
int[] array = new int[10];
|
||||
for (int i = 0; i < 20000; i++) {
|
||||
TestRangeCheckExceptionHandlerLoop.test(false, array, exception);
|
||||
}
|
||||
}
|
||||
}
|
@ -82,6 +82,8 @@
|
||||
*/
|
||||
package java.lang.invoke;
|
||||
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class TestStableBoolean {
|
||||
|
@ -82,6 +82,8 @@
|
||||
*/
|
||||
package java.lang.invoke;
|
||||
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class TestStableByte {
|
||||
|
@ -82,6 +82,8 @@
|
||||
*/
|
||||
package java.lang.invoke;
|
||||
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class TestStableChar {
|
||||
|
@ -82,6 +82,8 @@
|
||||
*/
|
||||
package java.lang.invoke;
|
||||
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class TestStableDouble {
|
||||
|
@ -82,6 +82,8 @@
|
||||
*/
|
||||
package java.lang.invoke;
|
||||
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class TestStableFloat {
|
||||
|
@ -82,6 +82,8 @@
|
||||
*/
|
||||
package java.lang.invoke;
|
||||
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class TestStableInt {
|
||||
|
@ -82,6 +82,8 @@
|
||||
*/
|
||||
package java.lang.invoke;
|
||||
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class TestStableLong {
|
||||
|
@ -36,6 +36,8 @@
|
||||
*/
|
||||
package java.lang.invoke;
|
||||
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class TestStableMemoryBarrier {
|
||||
|
@ -83,6 +83,8 @@
|
||||
*/
|
||||
package java.lang.invoke;
|
||||
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class TestStableObject {
|
||||
|
@ -82,6 +82,8 @@
|
||||
*/
|
||||
package java.lang.invoke;
|
||||
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class TestStableShort {
|
||||
|
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for boolean
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @run testng/othervm -Diters=100 -Xint JdkInternalMiscUnsafeAccessTestBoolean
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestBoolean
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation JdkInternalMiscUnsafeAccessTestBoolean
|
||||
* @run testng/othervm -Diters=20000 JdkInternalMiscUnsafeAccessTestBoolean
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class JdkInternalMiscUnsafeAccessTestBoolean {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final jdk.internal.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = JdkInternalMiscUnsafeAccessTestBoolean.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = JdkInternalMiscUnsafeAccessTestBoolean.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(boolean[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(boolean[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static boolean static_v;
|
||||
|
||||
boolean v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
JdkInternalMiscUnsafeAccessTestBoolean t = new JdkInternalMiscUnsafeAccessTestBoolean();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
boolean[] array = new boolean[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putBoolean(base, offset, true);
|
||||
boolean x = UNSAFE.getBoolean(base, offset);
|
||||
assertEquals(x, true, "set boolean value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putBooleanVolatile(base, offset, false);
|
||||
boolean x = UNSAFE.getBooleanVolatile(base, offset);
|
||||
assertEquals(x, false, "putVolatile boolean value");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for byte
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @run testng/othervm -Diters=100 -Xint JdkInternalMiscUnsafeAccessTestByte
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestByte
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation JdkInternalMiscUnsafeAccessTestByte
|
||||
* @run testng/othervm -Diters=20000 JdkInternalMiscUnsafeAccessTestByte
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class JdkInternalMiscUnsafeAccessTestByte {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final jdk.internal.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = JdkInternalMiscUnsafeAccessTestByte.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = JdkInternalMiscUnsafeAccessTestByte.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(byte[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(byte[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static byte static_v;
|
||||
|
||||
byte v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
JdkInternalMiscUnsafeAccessTestByte t = new JdkInternalMiscUnsafeAccessTestByte();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
byte[] array = new byte[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeap() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeapDirect() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess((((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putByte(base, offset, (byte)1);
|
||||
byte x = UNSAFE.getByte(base, offset);
|
||||
assertEquals(x, (byte)1, "set byte value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putByteVolatile(base, offset, (byte)2);
|
||||
byte x = UNSAFE.getByteVolatile(base, offset);
|
||||
assertEquals(x, (byte)2, "putVolatile byte value");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void testAccess(long address) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putByte(address, (byte)1);
|
||||
byte x = UNSAFE.getByte(address);
|
||||
assertEquals(x, (byte)1, "set byte value");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for char
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @run testng/othervm -Diters=100 -Xint JdkInternalMiscUnsafeAccessTestChar
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestChar
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation JdkInternalMiscUnsafeAccessTestChar
|
||||
* @run testng/othervm -Diters=20000 JdkInternalMiscUnsafeAccessTestChar
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class JdkInternalMiscUnsafeAccessTestChar {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final jdk.internal.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = JdkInternalMiscUnsafeAccessTestChar.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = JdkInternalMiscUnsafeAccessTestChar.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(char[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(char[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static char static_v;
|
||||
|
||||
char v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
JdkInternalMiscUnsafeAccessTestChar t = new JdkInternalMiscUnsafeAccessTestChar();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
char[] array = new char[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeap() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeapDirect() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess((((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putChar(base, offset, 'a');
|
||||
char x = UNSAFE.getChar(base, offset);
|
||||
assertEquals(x, 'a', "set char value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putCharVolatile(base, offset, 'b');
|
||||
char x = UNSAFE.getCharVolatile(base, offset);
|
||||
assertEquals(x, 'b', "putVolatile char value");
|
||||
}
|
||||
|
||||
|
||||
// Unaligned
|
||||
{
|
||||
UNSAFE.putCharUnaligned(base, offset, 'b');
|
||||
char x = UNSAFE.getCharUnaligned(base, offset);
|
||||
assertEquals(x, 'b', "putUnaligned char value");
|
||||
}
|
||||
|
||||
{
|
||||
UNSAFE.putCharUnaligned(base, offset, 'a', true);
|
||||
char x = UNSAFE.getCharUnaligned(base, offset, true);
|
||||
assertEquals(x, 'a', "putUnaligned big endian char value");
|
||||
}
|
||||
|
||||
{
|
||||
UNSAFE.putCharUnaligned(base, offset, 'b', false);
|
||||
char x = UNSAFE.getCharUnaligned(base, offset, false);
|
||||
assertEquals(x, 'b', "putUnaligned little endian char value");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void testAccess(long address) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putChar(address, 'a');
|
||||
char x = UNSAFE.getChar(address);
|
||||
assertEquals(x, 'a', "set char value");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for double
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @run testng/othervm -Diters=100 -Xint JdkInternalMiscUnsafeAccessTestDouble
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestDouble
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation JdkInternalMiscUnsafeAccessTestDouble
|
||||
* @run testng/othervm -Diters=20000 JdkInternalMiscUnsafeAccessTestDouble
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class JdkInternalMiscUnsafeAccessTestDouble {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final jdk.internal.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = JdkInternalMiscUnsafeAccessTestDouble.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = JdkInternalMiscUnsafeAccessTestDouble.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(double[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(double[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static double static_v;
|
||||
|
||||
double v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
JdkInternalMiscUnsafeAccessTestDouble t = new JdkInternalMiscUnsafeAccessTestDouble();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
double[] array = new double[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeap() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeapDirect() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess((((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putDouble(base, offset, 1.0d);
|
||||
double x = UNSAFE.getDouble(base, offset);
|
||||
assertEquals(x, 1.0d, "set double value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putDoubleVolatile(base, offset, 2.0d);
|
||||
double x = UNSAFE.getDoubleVolatile(base, offset);
|
||||
assertEquals(x, 2.0d, "putVolatile double value");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void testAccess(long address) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putDouble(address, 1.0d);
|
||||
double x = UNSAFE.getDouble(address);
|
||||
assertEquals(x, 1.0d, "set double value");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for float
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @run testng/othervm -Diters=100 -Xint JdkInternalMiscUnsafeAccessTestFloat
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestFloat
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation JdkInternalMiscUnsafeAccessTestFloat
|
||||
* @run testng/othervm -Diters=20000 JdkInternalMiscUnsafeAccessTestFloat
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class JdkInternalMiscUnsafeAccessTestFloat {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final jdk.internal.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = JdkInternalMiscUnsafeAccessTestFloat.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = JdkInternalMiscUnsafeAccessTestFloat.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(float[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(float[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static float static_v;
|
||||
|
||||
float v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
JdkInternalMiscUnsafeAccessTestFloat t = new JdkInternalMiscUnsafeAccessTestFloat();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
float[] array = new float[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeap() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeapDirect() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess((((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putFloat(base, offset, 1.0f);
|
||||
float x = UNSAFE.getFloat(base, offset);
|
||||
assertEquals(x, 1.0f, "set float value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putFloatVolatile(base, offset, 2.0f);
|
||||
float x = UNSAFE.getFloatVolatile(base, offset);
|
||||
assertEquals(x, 2.0f, "putVolatile float value");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void testAccess(long address) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putFloat(address, 1.0f);
|
||||
float x = UNSAFE.getFloat(address);
|
||||
assertEquals(x, 1.0f, "set float value");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for int
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @run testng/othervm -Diters=100 -Xint JdkInternalMiscUnsafeAccessTestInt
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestInt
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation JdkInternalMiscUnsafeAccessTestInt
|
||||
* @run testng/othervm -Diters=20000 JdkInternalMiscUnsafeAccessTestInt
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class JdkInternalMiscUnsafeAccessTestInt {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final jdk.internal.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = JdkInternalMiscUnsafeAccessTestInt.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = JdkInternalMiscUnsafeAccessTestInt.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(int[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(int[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static int static_v;
|
||||
|
||||
int v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
JdkInternalMiscUnsafeAccessTestInt t = new JdkInternalMiscUnsafeAccessTestInt();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
int[] array = new int[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeap() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeapDirect() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess((((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putInt(base, offset, 1);
|
||||
int x = UNSAFE.getInt(base, offset);
|
||||
assertEquals(x, 1, "set int value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putIntVolatile(base, offset, 2);
|
||||
int x = UNSAFE.getIntVolatile(base, offset);
|
||||
assertEquals(x, 2, "putVolatile int value");
|
||||
}
|
||||
|
||||
// Lazy
|
||||
{
|
||||
UNSAFE.putOrderedInt(base, offset, 1);
|
||||
int x = UNSAFE.getIntVolatile(base, offset);
|
||||
assertEquals(x, 1, "putRelease int value");
|
||||
}
|
||||
|
||||
// Unaligned
|
||||
{
|
||||
UNSAFE.putIntUnaligned(base, offset, 2);
|
||||
int x = UNSAFE.getIntUnaligned(base, offset);
|
||||
assertEquals(x, 2, "putUnaligned int value");
|
||||
}
|
||||
|
||||
{
|
||||
UNSAFE.putIntUnaligned(base, offset, 1, true);
|
||||
int x = UNSAFE.getIntUnaligned(base, offset, true);
|
||||
assertEquals(x, 1, "putUnaligned big endian int value");
|
||||
}
|
||||
|
||||
{
|
||||
UNSAFE.putIntUnaligned(base, offset, 2, false);
|
||||
int x = UNSAFE.getIntUnaligned(base, offset, false);
|
||||
assertEquals(x, 2, "putUnaligned little endian int value");
|
||||
}
|
||||
|
||||
UNSAFE.putInt(base, offset, 1);
|
||||
|
||||
// Compare
|
||||
{
|
||||
boolean r = UNSAFE.compareAndSwapInt(base, offset, 1, 2);
|
||||
assertEquals(r, true, "success compareAndSwap int");
|
||||
int x = UNSAFE.getInt(base, offset);
|
||||
assertEquals(x, 2, "success compareAndSwap int value");
|
||||
}
|
||||
|
||||
{
|
||||
boolean r = UNSAFE.compareAndSwapInt(base, offset, 1, 3);
|
||||
assertEquals(r, false, "failing compareAndSwap int");
|
||||
int x = UNSAFE.getInt(base, offset);
|
||||
assertEquals(x, 2, "failing compareAndSwap int value");
|
||||
}
|
||||
|
||||
// Compare set and get
|
||||
{
|
||||
int o = UNSAFE.getAndSetInt(base, offset, 1);
|
||||
assertEquals(o, 2, "getAndSet int");
|
||||
int x = UNSAFE.getInt(base, offset);
|
||||
assertEquals(x, 1, "getAndSet int value");
|
||||
}
|
||||
|
||||
UNSAFE.putInt(base, offset, 1);
|
||||
|
||||
// get and add, add and get
|
||||
{
|
||||
int o = UNSAFE.getAndAddInt(base, offset, 2);
|
||||
assertEquals(o, 1, "getAndAdd int");
|
||||
int x = UNSAFE.getInt(base, offset);
|
||||
assertEquals(x, 1 + 2, "weakCompareAndSwapRelease int");
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(long address) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putInt(address, 1);
|
||||
int x = UNSAFE.getInt(address);
|
||||
assertEquals(x, 1, "set int value");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for long
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @run testng/othervm -Diters=100 -Xint JdkInternalMiscUnsafeAccessTestLong
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestLong
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation JdkInternalMiscUnsafeAccessTestLong
|
||||
* @run testng/othervm -Diters=20000 JdkInternalMiscUnsafeAccessTestLong
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class JdkInternalMiscUnsafeAccessTestLong {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final jdk.internal.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = JdkInternalMiscUnsafeAccessTestLong.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = JdkInternalMiscUnsafeAccessTestLong.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(long[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(long[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static long static_v;
|
||||
|
||||
long v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
JdkInternalMiscUnsafeAccessTestLong t = new JdkInternalMiscUnsafeAccessTestLong();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
long[] array = new long[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeap() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeapDirect() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess((((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putLong(base, offset, 1L);
|
||||
long x = UNSAFE.getLong(base, offset);
|
||||
assertEquals(x, 1L, "set long value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putLongVolatile(base, offset, 2L);
|
||||
long x = UNSAFE.getLongVolatile(base, offset);
|
||||
assertEquals(x, 2L, "putVolatile long value");
|
||||
}
|
||||
|
||||
// Lazy
|
||||
{
|
||||
UNSAFE.putOrderedLong(base, offset, 1L);
|
||||
long x = UNSAFE.getLongVolatile(base, offset);
|
||||
assertEquals(x, 1L, "putRelease long value");
|
||||
}
|
||||
|
||||
// Unaligned
|
||||
{
|
||||
UNSAFE.putLongUnaligned(base, offset, 2L);
|
||||
long x = UNSAFE.getLongUnaligned(base, offset);
|
||||
assertEquals(x, 2L, "putUnaligned long value");
|
||||
}
|
||||
|
||||
{
|
||||
UNSAFE.putLongUnaligned(base, offset, 1L, true);
|
||||
long x = UNSAFE.getLongUnaligned(base, offset, true);
|
||||
assertEquals(x, 1L, "putUnaligned big endian long value");
|
||||
}
|
||||
|
||||
{
|
||||
UNSAFE.putLongUnaligned(base, offset, 2L, false);
|
||||
long x = UNSAFE.getLongUnaligned(base, offset, false);
|
||||
assertEquals(x, 2L, "putUnaligned little endian long value");
|
||||
}
|
||||
|
||||
UNSAFE.putLong(base, offset, 1L);
|
||||
|
||||
// Compare
|
||||
{
|
||||
boolean r = UNSAFE.compareAndSwapLong(base, offset, 1L, 2L);
|
||||
assertEquals(r, true, "success compareAndSwap long");
|
||||
long x = UNSAFE.getLong(base, offset);
|
||||
assertEquals(x, 2L, "success compareAndSwap long value");
|
||||
}
|
||||
|
||||
{
|
||||
boolean r = UNSAFE.compareAndSwapLong(base, offset, 1L, 3L);
|
||||
assertEquals(r, false, "failing compareAndSwap long");
|
||||
long x = UNSAFE.getLong(base, offset);
|
||||
assertEquals(x, 2L, "failing compareAndSwap long value");
|
||||
}
|
||||
|
||||
// Compare set and get
|
||||
{
|
||||
long o = UNSAFE.getAndSetLong(base, offset, 1L);
|
||||
assertEquals(o, 2L, "getAndSet long");
|
||||
long x = UNSAFE.getLong(base, offset);
|
||||
assertEquals(x, 1L, "getAndSet long value");
|
||||
}
|
||||
|
||||
UNSAFE.putLong(base, offset, 1L);
|
||||
|
||||
// get and add, add and get
|
||||
{
|
||||
long o = UNSAFE.getAndAddLong(base, offset, 2L);
|
||||
assertEquals(o, 1L, "getAndAdd long");
|
||||
long x = UNSAFE.getLong(base, offset);
|
||||
assertEquals(x, 1L + 2L, "weakCompareAndSwapRelease long");
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(long address) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putLong(address, 1L);
|
||||
long x = UNSAFE.getLong(address);
|
||||
assertEquals(x, 1L, "set long value");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for Object
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @run testng/othervm -Diters=100 -Xint JdkInternalMiscUnsafeAccessTestObject
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestObject
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation JdkInternalMiscUnsafeAccessTestObject
|
||||
* @run testng/othervm -Diters=20000 JdkInternalMiscUnsafeAccessTestObject
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class JdkInternalMiscUnsafeAccessTestObject {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final jdk.internal.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = JdkInternalMiscUnsafeAccessTestObject.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = JdkInternalMiscUnsafeAccessTestObject.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(Object[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(Object[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static Object static_v;
|
||||
|
||||
Object v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
JdkInternalMiscUnsafeAccessTestObject t = new JdkInternalMiscUnsafeAccessTestObject();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
Object[] array = new Object[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putObject(base, offset, "foo");
|
||||
Object x = UNSAFE.getObject(base, offset);
|
||||
assertEquals(x, "foo", "set Object value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putObjectVolatile(base, offset, "bar");
|
||||
Object x = UNSAFE.getObjectVolatile(base, offset);
|
||||
assertEquals(x, "bar", "putVolatile Object value");
|
||||
}
|
||||
|
||||
// Lazy
|
||||
{
|
||||
UNSAFE.putOrderedObject(base, offset, "foo");
|
||||
Object x = UNSAFE.getObjectVolatile(base, offset);
|
||||
assertEquals(x, "foo", "putRelease Object value");
|
||||
}
|
||||
|
||||
|
||||
UNSAFE.putObject(base, offset, "foo");
|
||||
|
||||
// Compare
|
||||
{
|
||||
boolean r = UNSAFE.compareAndSwapObject(base, offset, "foo", "bar");
|
||||
assertEquals(r, true, "success compareAndSwap Object");
|
||||
Object x = UNSAFE.getObject(base, offset);
|
||||
assertEquals(x, "bar", "success compareAndSwap Object value");
|
||||
}
|
||||
|
||||
{
|
||||
boolean r = UNSAFE.compareAndSwapObject(base, offset, "foo", "baz");
|
||||
assertEquals(r, false, "failing compareAndSwap Object");
|
||||
Object x = UNSAFE.getObject(base, offset);
|
||||
assertEquals(x, "bar", "failing compareAndSwap Object value");
|
||||
}
|
||||
|
||||
// Compare set and get
|
||||
{
|
||||
Object o = UNSAFE.getAndSetObject(base, offset, "foo");
|
||||
assertEquals(o, "bar", "getAndSet Object");
|
||||
Object x = UNSAFE.getObject(base, offset);
|
||||
assertEquals(x, "foo", "getAndSet Object value");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for short
|
||||
* @modules java.base/jdk.internal.misc
|
||||
* @run testng/othervm -Diters=100 -Xint JdkInternalMiscUnsafeAccessTestShort
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 JdkInternalMiscUnsafeAccessTestShort
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation JdkInternalMiscUnsafeAccessTestShort
|
||||
* @run testng/othervm -Diters=20000 JdkInternalMiscUnsafeAccessTestShort
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class JdkInternalMiscUnsafeAccessTestShort {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final jdk.internal.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = jdk.internal.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (jdk.internal.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = JdkInternalMiscUnsafeAccessTestShort.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = JdkInternalMiscUnsafeAccessTestShort.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(short[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(short[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static short static_v;
|
||||
|
||||
short v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
JdkInternalMiscUnsafeAccessTestShort t = new JdkInternalMiscUnsafeAccessTestShort();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
short[] array = new short[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeap() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeapDirect() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess((((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putShort(base, offset, (short)1);
|
||||
short x = UNSAFE.getShort(base, offset);
|
||||
assertEquals(x, (short)1, "set short value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putShortVolatile(base, offset, (short)2);
|
||||
short x = UNSAFE.getShortVolatile(base, offset);
|
||||
assertEquals(x, (short)2, "putVolatile short value");
|
||||
}
|
||||
|
||||
|
||||
// Unaligned
|
||||
{
|
||||
UNSAFE.putShortUnaligned(base, offset, (short)2);
|
||||
short x = UNSAFE.getShortUnaligned(base, offset);
|
||||
assertEquals(x, (short)2, "putUnaligned short value");
|
||||
}
|
||||
|
||||
{
|
||||
UNSAFE.putShortUnaligned(base, offset, (short)1, true);
|
||||
short x = UNSAFE.getShortUnaligned(base, offset, true);
|
||||
assertEquals(x, (short)1, "putUnaligned big endian short value");
|
||||
}
|
||||
|
||||
{
|
||||
UNSAFE.putShortUnaligned(base, offset, (short)2, false);
|
||||
short x = UNSAFE.getShortUnaligned(base, offset, false);
|
||||
assertEquals(x, (short)2, "putUnaligned little endian short value");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void testAccess(long address) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putShort(address, (short)1);
|
||||
short x = UNSAFE.getShort(address);
|
||||
assertEquals(x, (short)1, "set short value");
|
||||
}
|
||||
}
|
||||
}
|
135
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestBoolean.java
Normal file
135
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestBoolean.java
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for boolean
|
||||
* @modules java.base/sun.misc
|
||||
* @run testng/othervm -Diters=100 -Xint SunMiscUnsafeAccessTestBoolean
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 SunMiscUnsafeAccessTestBoolean
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation SunMiscUnsafeAccessTestBoolean
|
||||
* @run testng/othervm -Diters=20000 SunMiscUnsafeAccessTestBoolean
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class SunMiscUnsafeAccessTestBoolean {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final sun.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (sun.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = SunMiscUnsafeAccessTestBoolean.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = SunMiscUnsafeAccessTestBoolean.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(boolean[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(boolean[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static boolean static_v;
|
||||
|
||||
boolean v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
SunMiscUnsafeAccessTestBoolean t = new SunMiscUnsafeAccessTestBoolean();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
boolean[] array = new boolean[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putBoolean(base, offset, true);
|
||||
boolean x = UNSAFE.getBoolean(base, offset);
|
||||
assertEquals(x, true, "set boolean value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putBooleanVolatile(base, offset, false);
|
||||
boolean x = UNSAFE.getBooleanVolatile(base, offset);
|
||||
assertEquals(x, false, "putVolatile boolean value");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
172
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestByte.java
Normal file
172
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestByte.java
Normal file
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for byte
|
||||
* @modules java.base/sun.misc
|
||||
* @run testng/othervm -Diters=100 -Xint SunMiscUnsafeAccessTestByte
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 SunMiscUnsafeAccessTestByte
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation SunMiscUnsafeAccessTestByte
|
||||
* @run testng/othervm -Diters=20000 SunMiscUnsafeAccessTestByte
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class SunMiscUnsafeAccessTestByte {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final sun.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (sun.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = SunMiscUnsafeAccessTestByte.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = SunMiscUnsafeAccessTestByte.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(byte[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(byte[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static byte static_v;
|
||||
|
||||
byte v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
SunMiscUnsafeAccessTestByte t = new SunMiscUnsafeAccessTestByte();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
byte[] array = new byte[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeap() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeapDirect() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess((((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putByte(base, offset, (byte)1);
|
||||
byte x = UNSAFE.getByte(base, offset);
|
||||
assertEquals(x, (byte)1, "set byte value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putByteVolatile(base, offset, (byte)2);
|
||||
byte x = UNSAFE.getByteVolatile(base, offset);
|
||||
assertEquals(x, (byte)2, "putVolatile byte value");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void testAccess(long address) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putByte(address, (byte)1);
|
||||
byte x = UNSAFE.getByte(address);
|
||||
assertEquals(x, (byte)1, "set byte value");
|
||||
}
|
||||
}
|
||||
}
|
172
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestChar.java
Normal file
172
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestChar.java
Normal file
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for char
|
||||
* @modules java.base/sun.misc
|
||||
* @run testng/othervm -Diters=100 -Xint SunMiscUnsafeAccessTestChar
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 SunMiscUnsafeAccessTestChar
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation SunMiscUnsafeAccessTestChar
|
||||
* @run testng/othervm -Diters=20000 SunMiscUnsafeAccessTestChar
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class SunMiscUnsafeAccessTestChar {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final sun.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (sun.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = SunMiscUnsafeAccessTestChar.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = SunMiscUnsafeAccessTestChar.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(char[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(char[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static char static_v;
|
||||
|
||||
char v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
SunMiscUnsafeAccessTestChar t = new SunMiscUnsafeAccessTestChar();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
char[] array = new char[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeap() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeapDirect() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess((((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putChar(base, offset, 'a');
|
||||
char x = UNSAFE.getChar(base, offset);
|
||||
assertEquals(x, 'a', "set char value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putCharVolatile(base, offset, 'b');
|
||||
char x = UNSAFE.getCharVolatile(base, offset);
|
||||
assertEquals(x, 'b', "putVolatile char value");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void testAccess(long address) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putChar(address, 'a');
|
||||
char x = UNSAFE.getChar(address);
|
||||
assertEquals(x, 'a', "set char value");
|
||||
}
|
||||
}
|
||||
}
|
172
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestDouble.java
Normal file
172
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestDouble.java
Normal file
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for double
|
||||
* @modules java.base/sun.misc
|
||||
* @run testng/othervm -Diters=100 -Xint SunMiscUnsafeAccessTestDouble
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 SunMiscUnsafeAccessTestDouble
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation SunMiscUnsafeAccessTestDouble
|
||||
* @run testng/othervm -Diters=20000 SunMiscUnsafeAccessTestDouble
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class SunMiscUnsafeAccessTestDouble {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final sun.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (sun.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = SunMiscUnsafeAccessTestDouble.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = SunMiscUnsafeAccessTestDouble.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(double[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(double[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static double static_v;
|
||||
|
||||
double v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
SunMiscUnsafeAccessTestDouble t = new SunMiscUnsafeAccessTestDouble();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
double[] array = new double[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeap() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeapDirect() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess((((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putDouble(base, offset, 1.0d);
|
||||
double x = UNSAFE.getDouble(base, offset);
|
||||
assertEquals(x, 1.0d, "set double value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putDoubleVolatile(base, offset, 2.0d);
|
||||
double x = UNSAFE.getDoubleVolatile(base, offset);
|
||||
assertEquals(x, 2.0d, "putVolatile double value");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void testAccess(long address) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putDouble(address, 1.0d);
|
||||
double x = UNSAFE.getDouble(address);
|
||||
assertEquals(x, 1.0d, "set double value");
|
||||
}
|
||||
}
|
||||
}
|
172
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestFloat.java
Normal file
172
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestFloat.java
Normal file
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for float
|
||||
* @modules java.base/sun.misc
|
||||
* @run testng/othervm -Diters=100 -Xint SunMiscUnsafeAccessTestFloat
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 SunMiscUnsafeAccessTestFloat
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation SunMiscUnsafeAccessTestFloat
|
||||
* @run testng/othervm -Diters=20000 SunMiscUnsafeAccessTestFloat
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class SunMiscUnsafeAccessTestFloat {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final sun.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (sun.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = SunMiscUnsafeAccessTestFloat.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = SunMiscUnsafeAccessTestFloat.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(float[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(float[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static float static_v;
|
||||
|
||||
float v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
SunMiscUnsafeAccessTestFloat t = new SunMiscUnsafeAccessTestFloat();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
float[] array = new float[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeap() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeapDirect() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess((((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putFloat(base, offset, 1.0f);
|
||||
float x = UNSAFE.getFloat(base, offset);
|
||||
assertEquals(x, 1.0f, "set float value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putFloatVolatile(base, offset, 2.0f);
|
||||
float x = UNSAFE.getFloatVolatile(base, offset);
|
||||
assertEquals(x, 2.0f, "putVolatile float value");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void testAccess(long address) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putFloat(address, 1.0f);
|
||||
float x = UNSAFE.getFloat(address);
|
||||
assertEquals(x, 1.0f, "set float value");
|
||||
}
|
||||
}
|
||||
}
|
211
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestInt.java
Normal file
211
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestInt.java
Normal file
@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for int
|
||||
* @modules java.base/sun.misc
|
||||
* @run testng/othervm -Diters=100 -Xint SunMiscUnsafeAccessTestInt
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 SunMiscUnsafeAccessTestInt
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation SunMiscUnsafeAccessTestInt
|
||||
* @run testng/othervm -Diters=20000 SunMiscUnsafeAccessTestInt
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class SunMiscUnsafeAccessTestInt {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final sun.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (sun.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = SunMiscUnsafeAccessTestInt.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = SunMiscUnsafeAccessTestInt.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(int[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(int[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static int static_v;
|
||||
|
||||
int v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
SunMiscUnsafeAccessTestInt t = new SunMiscUnsafeAccessTestInt();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
int[] array = new int[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeap() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeapDirect() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess((((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putInt(base, offset, 1);
|
||||
int x = UNSAFE.getInt(base, offset);
|
||||
assertEquals(x, 1, "set int value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putIntVolatile(base, offset, 2);
|
||||
int x = UNSAFE.getIntVolatile(base, offset);
|
||||
assertEquals(x, 2, "putVolatile int value");
|
||||
}
|
||||
|
||||
// Lazy
|
||||
{
|
||||
UNSAFE.putOrderedInt(base, offset, 1);
|
||||
int x = UNSAFE.getIntVolatile(base, offset);
|
||||
assertEquals(x, 1, "putRelease int value");
|
||||
}
|
||||
|
||||
|
||||
UNSAFE.putInt(base, offset, 1);
|
||||
|
||||
// Compare
|
||||
{
|
||||
boolean r = UNSAFE.compareAndSwapInt(base, offset, 1, 2);
|
||||
assertEquals(r, true, "success compareAndSwap int");
|
||||
int x = UNSAFE.getInt(base, offset);
|
||||
assertEquals(x, 2, "success compareAndSwap int value");
|
||||
}
|
||||
|
||||
{
|
||||
boolean r = UNSAFE.compareAndSwapInt(base, offset, 1, 3);
|
||||
assertEquals(r, false, "failing compareAndSwap int");
|
||||
int x = UNSAFE.getInt(base, offset);
|
||||
assertEquals(x, 2, "failing compareAndSwap int value");
|
||||
}
|
||||
|
||||
// Compare set and get
|
||||
{
|
||||
int o = UNSAFE.getAndSetInt(base, offset, 1);
|
||||
assertEquals(o, 2, "getAndSet int");
|
||||
int x = UNSAFE.getInt(base, offset);
|
||||
assertEquals(x, 1, "getAndSet int value");
|
||||
}
|
||||
|
||||
UNSAFE.putInt(base, offset, 1);
|
||||
|
||||
// get and add, add and get
|
||||
{
|
||||
int o = UNSAFE.getAndAddInt(base, offset, 2);
|
||||
assertEquals(o, 1, "getAndAdd int");
|
||||
int x = UNSAFE.getInt(base, offset);
|
||||
assertEquals(x, 1 + 2, "weakCompareAndSwapRelease int");
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(long address) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putInt(address, 1);
|
||||
int x = UNSAFE.getInt(address);
|
||||
assertEquals(x, 1, "set int value");
|
||||
}
|
||||
}
|
||||
}
|
211
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestLong.java
Normal file
211
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestLong.java
Normal file
@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for long
|
||||
* @modules java.base/sun.misc
|
||||
* @run testng/othervm -Diters=100 -Xint SunMiscUnsafeAccessTestLong
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 SunMiscUnsafeAccessTestLong
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation SunMiscUnsafeAccessTestLong
|
||||
* @run testng/othervm -Diters=20000 SunMiscUnsafeAccessTestLong
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class SunMiscUnsafeAccessTestLong {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final sun.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (sun.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = SunMiscUnsafeAccessTestLong.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = SunMiscUnsafeAccessTestLong.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(long[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(long[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static long static_v;
|
||||
|
||||
long v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
SunMiscUnsafeAccessTestLong t = new SunMiscUnsafeAccessTestLong();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
long[] array = new long[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeap() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeapDirect() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess((((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putLong(base, offset, 1L);
|
||||
long x = UNSAFE.getLong(base, offset);
|
||||
assertEquals(x, 1L, "set long value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putLongVolatile(base, offset, 2L);
|
||||
long x = UNSAFE.getLongVolatile(base, offset);
|
||||
assertEquals(x, 2L, "putVolatile long value");
|
||||
}
|
||||
|
||||
// Lazy
|
||||
{
|
||||
UNSAFE.putOrderedLong(base, offset, 1L);
|
||||
long x = UNSAFE.getLongVolatile(base, offset);
|
||||
assertEquals(x, 1L, "putRelease long value");
|
||||
}
|
||||
|
||||
|
||||
UNSAFE.putLong(base, offset, 1L);
|
||||
|
||||
// Compare
|
||||
{
|
||||
boolean r = UNSAFE.compareAndSwapLong(base, offset, 1L, 2L);
|
||||
assertEquals(r, true, "success compareAndSwap long");
|
||||
long x = UNSAFE.getLong(base, offset);
|
||||
assertEquals(x, 2L, "success compareAndSwap long value");
|
||||
}
|
||||
|
||||
{
|
||||
boolean r = UNSAFE.compareAndSwapLong(base, offset, 1L, 3L);
|
||||
assertEquals(r, false, "failing compareAndSwap long");
|
||||
long x = UNSAFE.getLong(base, offset);
|
||||
assertEquals(x, 2L, "failing compareAndSwap long value");
|
||||
}
|
||||
|
||||
// Compare set and get
|
||||
{
|
||||
long o = UNSAFE.getAndSetLong(base, offset, 1L);
|
||||
assertEquals(o, 2L, "getAndSet long");
|
||||
long x = UNSAFE.getLong(base, offset);
|
||||
assertEquals(x, 1L, "getAndSet long value");
|
||||
}
|
||||
|
||||
UNSAFE.putLong(base, offset, 1L);
|
||||
|
||||
// get and add, add and get
|
||||
{
|
||||
long o = UNSAFE.getAndAddLong(base, offset, 2L);
|
||||
assertEquals(o, 1L, "getAndAdd long");
|
||||
long x = UNSAFE.getLong(base, offset);
|
||||
assertEquals(x, 1L + 2L, "weakCompareAndSwapRelease long");
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(long address) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putLong(address, 1L);
|
||||
long x = UNSAFE.getLong(address);
|
||||
assertEquals(x, 1L, "set long value");
|
||||
}
|
||||
}
|
||||
}
|
165
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestObject.java
Normal file
165
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestObject.java
Normal file
@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for Object
|
||||
* @modules java.base/sun.misc
|
||||
* @run testng/othervm -Diters=100 -Xint SunMiscUnsafeAccessTestObject
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 SunMiscUnsafeAccessTestObject
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation SunMiscUnsafeAccessTestObject
|
||||
* @run testng/othervm -Diters=20000 SunMiscUnsafeAccessTestObject
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class SunMiscUnsafeAccessTestObject {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final sun.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (sun.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = SunMiscUnsafeAccessTestObject.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = SunMiscUnsafeAccessTestObject.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(Object[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(Object[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static Object static_v;
|
||||
|
||||
Object v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
SunMiscUnsafeAccessTestObject t = new SunMiscUnsafeAccessTestObject();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
Object[] array = new Object[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putObject(base, offset, "foo");
|
||||
Object x = UNSAFE.getObject(base, offset);
|
||||
assertEquals(x, "foo", "set Object value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putObjectVolatile(base, offset, "bar");
|
||||
Object x = UNSAFE.getObjectVolatile(base, offset);
|
||||
assertEquals(x, "bar", "putVolatile Object value");
|
||||
}
|
||||
|
||||
// Lazy
|
||||
{
|
||||
UNSAFE.putOrderedObject(base, offset, "foo");
|
||||
Object x = UNSAFE.getObjectVolatile(base, offset);
|
||||
assertEquals(x, "foo", "putRelease Object value");
|
||||
}
|
||||
|
||||
|
||||
UNSAFE.putObject(base, offset, "foo");
|
||||
|
||||
// Compare
|
||||
{
|
||||
boolean r = UNSAFE.compareAndSwapObject(base, offset, "foo", "bar");
|
||||
assertEquals(r, true, "success compareAndSwap Object");
|
||||
Object x = UNSAFE.getObject(base, offset);
|
||||
assertEquals(x, "bar", "success compareAndSwap Object value");
|
||||
}
|
||||
|
||||
{
|
||||
boolean r = UNSAFE.compareAndSwapObject(base, offset, "foo", "baz");
|
||||
assertEquals(r, false, "failing compareAndSwap Object");
|
||||
Object x = UNSAFE.getObject(base, offset);
|
||||
assertEquals(x, "bar", "failing compareAndSwap Object value");
|
||||
}
|
||||
|
||||
// Compare set and get
|
||||
{
|
||||
Object o = UNSAFE.getAndSetObject(base, offset, "foo");
|
||||
assertEquals(o, "bar", "getAndSet Object");
|
||||
Object x = UNSAFE.getObject(base, offset);
|
||||
assertEquals(x, "foo", "getAndSet Object value");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
172
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestShort.java
Normal file
172
hotspot/test/compiler/unsafe/SunMiscUnsafeAccessTestShort.java
Normal file
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for short
|
||||
* @modules java.base/sun.misc
|
||||
* @run testng/othervm -Diters=100 -Xint SunMiscUnsafeAccessTestShort
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 SunMiscUnsafeAccessTestShort
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation SunMiscUnsafeAccessTestShort
|
||||
* @run testng/othervm -Diters=20000 SunMiscUnsafeAccessTestShort
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class SunMiscUnsafeAccessTestShort {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final sun.misc.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = (sun.misc.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = SunMiscUnsafeAccessTestShort.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = SunMiscUnsafeAccessTestShort.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset(short[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale(short[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static short static_v;
|
||||
|
||||
short v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
SunMiscUnsafeAccessTestShort t = new SunMiscUnsafeAccessTestShort();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
short[] array = new short[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeap() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeapDirect() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess((((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putShort(base, offset, (short)1);
|
||||
short x = UNSAFE.getShort(base, offset);
|
||||
assertEquals(x, (short)1, "set short value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.putShortVolatile(base, offset, (short)2);
|
||||
short x = UNSAFE.getShortVolatile(base, offset);
|
||||
assertEquals(x, (short)2, "putVolatile short value");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void testAccess(long address) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.putShort(address, (short)1);
|
||||
short x = UNSAFE.getShort(address);
|
||||
assertEquals(x, (short)1, "set short value");
|
||||
}
|
||||
}
|
||||
}
|
@ -40,10 +40,16 @@
|
||||
*/
|
||||
package java.lang.invoke;
|
||||
|
||||
import jdk.internal.org.objectweb.asm.*;
|
||||
import jdk.test.lib.Asserts;
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.internal.vm.annotation.DontInline;
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
import jdk.internal.org.objectweb.asm.ClassWriter;
|
||||
import jdk.internal.org.objectweb.asm.FieldVisitor;
|
||||
import jdk.internal.org.objectweb.asm.MethodVisitor;
|
||||
import jdk.internal.org.objectweb.asm.Opcodes;
|
||||
import jdk.internal.org.objectweb.asm.Type;
|
||||
import jdk.test.lib.Asserts;
|
||||
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
||||
|
||||
public class UnsafeGetConstantField {
|
||||
|
247
hotspot/test/compiler/unsafe/X-UnsafeAccessTest.java.template
Normal file
247
hotspot/test/compiler/unsafe/X-UnsafeAccessTest.java.template
Normal file
@ -0,0 +1,247 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8143628
|
||||
* @summary Test unsafe access for $type$
|
||||
* @modules java.base/$package$
|
||||
* @run testng/othervm -Diters=100 -Xint $Qualifier$UnsafeAccessTest$Type$
|
||||
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 $Qualifier$UnsafeAccessTest$Type$
|
||||
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation $Qualifier$UnsafeAccessTest$Type$
|
||||
* @run testng/othervm -Diters=20000 $Qualifier$UnsafeAccessTest$Type$
|
||||
*/
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class $Qualifier$UnsafeAccessTest$Type$ {
|
||||
static final int ITERS = Integer.getInteger("iters", 1);
|
||||
|
||||
static final $package$.Unsafe UNSAFE;
|
||||
|
||||
static final long V_OFFSET;
|
||||
|
||||
static final Object STATIC_V_BASE;
|
||||
|
||||
static final long STATIC_V_OFFSET;
|
||||
|
||||
static int ARRAY_OFFSET;
|
||||
|
||||
static int ARRAY_SHIFT;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = $package$.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
UNSAFE = ($package$.Unsafe) f.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to get Unsafe instance.", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field staticVField = $Qualifier$UnsafeAccessTest$Type$.class.getDeclaredField("static_v");
|
||||
STATIC_V_BASE = UNSAFE.staticFieldBase(staticVField);
|
||||
STATIC_V_OFFSET = UNSAFE.staticFieldOffset(staticVField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Field vField = $Qualifier$UnsafeAccessTest$Type$.class.getDeclaredField("v");
|
||||
V_OFFSET = UNSAFE.objectFieldOffset(vField);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ARRAY_OFFSET = UNSAFE.arrayBaseOffset($type$[].class);
|
||||
int ascale = UNSAFE.arrayIndexScale($type$[].class);
|
||||
ARRAY_SHIFT = 31 - Integer.numberOfLeadingZeros(ascale);
|
||||
}
|
||||
|
||||
static $type$ static_v;
|
||||
|
||||
$type$ v;
|
||||
|
||||
@Test
|
||||
public void testFieldInstance() {
|
||||
$Qualifier$UnsafeAccessTest$Type$ t = new $Qualifier$UnsafeAccessTest$Type$();
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(t, V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldStatic() {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
testAccess(STATIC_V_BASE, STATIC_V_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArray() {
|
||||
$type$[] array = new $type$[10];
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
testAccess(array, (((long) i) << ARRAY_SHIFT) + ARRAY_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if[!Object]
|
||||
#if[!boolean]
|
||||
@Test
|
||||
public void testArrayOffHeap() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess(null, (((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayOffHeapDirect() {
|
||||
int size = 10;
|
||||
long address = UNSAFE.allocateMemory(size << ARRAY_SHIFT);
|
||||
try {
|
||||
for (int c = 0; c < ITERS; c++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
testAccess((((long) i) << ARRAY_SHIFT) + address);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
UNSAFE.freeMemory(address);
|
||||
}
|
||||
}
|
||||
#end[!boolean]
|
||||
#end[!Object]
|
||||
|
||||
static void testAccess(Object base, long offset) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.put$Type$(base, offset, $value1$);
|
||||
$type$ x = UNSAFE.get$Type$(base, offset);
|
||||
assertEquals(x, $value1$, "set $type$ value");
|
||||
}
|
||||
|
||||
// Volatile
|
||||
{
|
||||
UNSAFE.put$Type$Volatile(base, offset, $value2$);
|
||||
$type$ x = UNSAFE.get$Type$Volatile(base, offset);
|
||||
assertEquals(x, $value2$, "putVolatile $type$ value");
|
||||
}
|
||||
|
||||
#if[Ordered]
|
||||
// Lazy
|
||||
{
|
||||
UNSAFE.putOrdered$Type$(base, offset, $value1$);
|
||||
$type$ x = UNSAFE.get$Type$Volatile(base, offset);
|
||||
assertEquals(x, $value1$, "putRelease $type$ value");
|
||||
}
|
||||
#end[Ordered]
|
||||
|
||||
#if[JdkInternalMisc]
|
||||
#if[Unaligned]
|
||||
// Unaligned
|
||||
{
|
||||
UNSAFE.put$Type$Unaligned(base, offset, $value2$);
|
||||
$type$ x = UNSAFE.get$Type$Unaligned(base, offset);
|
||||
assertEquals(x, $value2$, "putUnaligned $type$ value");
|
||||
}
|
||||
|
||||
{
|
||||
UNSAFE.put$Type$Unaligned(base, offset, $value1$, true);
|
||||
$type$ x = UNSAFE.get$Type$Unaligned(base, offset, true);
|
||||
assertEquals(x, $value1$, "putUnaligned big endian $type$ value");
|
||||
}
|
||||
|
||||
{
|
||||
UNSAFE.put$Type$Unaligned(base, offset, $value2$, false);
|
||||
$type$ x = UNSAFE.get$Type$Unaligned(base, offset, false);
|
||||
assertEquals(x, $value2$, "putUnaligned little endian $type$ value");
|
||||
}
|
||||
#end[Unaligned]
|
||||
#end[JdkInternalMisc]
|
||||
|
||||
#if[CAS]
|
||||
UNSAFE.put$Type$(base, offset, $value1$);
|
||||
|
||||
// Compare
|
||||
{
|
||||
boolean r = UNSAFE.compareAndSwap$Type$(base, offset, $value1$, $value2$);
|
||||
assertEquals(r, true, "success compareAndSwap $type$");
|
||||
$type$ x = UNSAFE.get$Type$(base, offset);
|
||||
assertEquals(x, $value2$, "success compareAndSwap $type$ value");
|
||||
}
|
||||
|
||||
{
|
||||
boolean r = UNSAFE.compareAndSwap$Type$(base, offset, $value1$, $value3$);
|
||||
assertEquals(r, false, "failing compareAndSwap $type$");
|
||||
$type$ x = UNSAFE.get$Type$(base, offset);
|
||||
assertEquals(x, $value2$, "failing compareAndSwap $type$ value");
|
||||
}
|
||||
|
||||
// Compare set and get
|
||||
{
|
||||
$type$ o = UNSAFE.getAndSet$Type$(base, offset, $value1$);
|
||||
assertEquals(o, $value2$, "getAndSet $type$");
|
||||
$type$ x = UNSAFE.get$Type$(base, offset);
|
||||
assertEquals(x, $value1$, "getAndSet $type$ value");
|
||||
}
|
||||
#end[CAS]
|
||||
|
||||
#if[AtomicAdd]
|
||||
UNSAFE.put$Type$(base, offset, $value1$);
|
||||
|
||||
// get and add, add and get
|
||||
{
|
||||
$type$ o = UNSAFE.getAndAdd$Type$(base, offset, $value2$);
|
||||
assertEquals(o, $value1$, "getAndAdd $type$");
|
||||
$type$ x = UNSAFE.get$Type$(base, offset);
|
||||
assertEquals(x, $value1$ + $value2$, "weakCompareAndSwapRelease $type$");
|
||||
}
|
||||
#end[AtomicAdd]
|
||||
}
|
||||
|
||||
#if[!Object]
|
||||
#if[!boolean]
|
||||
static void testAccess(long address) {
|
||||
// Plain
|
||||
{
|
||||
UNSAFE.put$Type$(address, $value1$);
|
||||
$type$ x = UNSAFE.get$Type$(address);
|
||||
assertEquals(x, $value1$, "set $type$ value");
|
||||
}
|
||||
}
|
||||
#end[!boolean]
|
||||
#end[!Object]
|
||||
}
|
119
hotspot/test/compiler/unsafe/generate-unsafe-access-tests.sh
Normal file
119
hotspot/test/compiler/unsafe/generate-unsafe-access-tests.sh
Normal file
@ -0,0 +1,119 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# 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.
|
||||
#
|
||||
|
||||
javac -d . ../../../../jdk/make/src/classes/build/tools/spp/Spp.java
|
||||
|
||||
SPP=build.tools.spp.Spp
|
||||
|
||||
# Generates unsafe access tests for objects and all primitive types
|
||||
# $1 = package name to Unsafe, sun.misc | jdk.internal.misc
|
||||
# $2 = test class qualifier name, SunMisc | JdkInternalMisc
|
||||
function generate {
|
||||
package=$1
|
||||
Qualifier=$2
|
||||
|
||||
for type in boolean byte short char int long float double Object
|
||||
do
|
||||
Type="$(tr '[:lower:]' '[:upper:]' <<< ${type:0:1})${type:1}"
|
||||
args="-K$type -Dtype=$type -DType=$Type"
|
||||
|
||||
case $type in
|
||||
Object|int|long)
|
||||
args="$args -KCAS -KOrdered"
|
||||
;;
|
||||
esac
|
||||
|
||||
case $type in
|
||||
int|long)
|
||||
args="$args -KAtomicAdd"
|
||||
;;
|
||||
esac
|
||||
|
||||
case $type in
|
||||
short|char|int|long)
|
||||
args="$args -KUnaligned"
|
||||
;;
|
||||
esac
|
||||
|
||||
case $type in
|
||||
boolean)
|
||||
value1=true
|
||||
value2=false
|
||||
value3=false
|
||||
;;
|
||||
byte)
|
||||
value1=(byte)1
|
||||
value2=(byte)2
|
||||
value3=(byte)3
|
||||
;;
|
||||
short)
|
||||
value1=(short)1
|
||||
value2=(short)2
|
||||
value3=(short)3
|
||||
;;
|
||||
char)
|
||||
value1=\'a\'
|
||||
value2=\'b\'
|
||||
value3=\'c\'
|
||||
;;
|
||||
int)
|
||||
value1=1
|
||||
value2=2
|
||||
value3=3
|
||||
;;
|
||||
long)
|
||||
value1=1L
|
||||
value2=2L
|
||||
value3=3L
|
||||
;;
|
||||
float)
|
||||
value1=1.0f
|
||||
value2=2.0f
|
||||
value3=3.0f
|
||||
;;
|
||||
double)
|
||||
value1=1.0d
|
||||
value2=2.0d
|
||||
value3=3.0d
|
||||
;;
|
||||
Object)
|
||||
value1=\"foo\"
|
||||
value2=\"bar\"
|
||||
value3=\"baz\"
|
||||
;;
|
||||
esac
|
||||
|
||||
args="$args -Dvalue1=$value1 -Dvalue2=$value2 -Dvalue3=$value3"
|
||||
|
||||
echo $args
|
||||
java $SPP -nel -K$Qualifier -Dpackage=$package -DQualifier=$Qualifier \
|
||||
$args < X-UnsafeAccessTest.java.template > ${Qualifier}UnsafeAccessTest${Type}.java
|
||||
done
|
||||
}
|
||||
|
||||
generate sun.misc SunMisc
|
||||
generate jdk.internal.misc JdkInternalMisc
|
||||
|
||||
rm -fr build
|
Loading…
x
Reference in New Issue
Block a user