Skip to content

Commit

Permalink
amend arm64 specific code for weak JNI handles
Browse files Browse the repository at this point in the history
  • Loading branch information
Xin Liu authored and alvdavi committed Jul 13, 2019
1 parent 2fbb40d commit 54dce35
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/hotspot/src/cpu/aarch64/vm/jniFastGetField_aarch64.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, Red Hat Inc.
* Copyright (c) 2004, 2010, Oracle and/or its affiliates.
* All rights reserved.
Expand Down Expand Up @@ -82,6 +83,11 @@ address JNI_FastGetField::generate_fast_get_int_field0(BasicType type) {
__ eor(robj, robj, rcounter); // obj, since
// robj ^ rcounter ^ rcounter == robj
// robj is address dependent on rcounter.

// If mask changes we need to ensure that the inverse is still encodable as an immediate
STATIC_ASSERT(JNIHandles::weak_tag_mask == 1);
__ andr(robj, robj, ~JNIHandles::weak_tag_mask);

__ ldr(robj, Address(robj, 0)); // *obj
__ lsr(roffset, c_rarg2, 2); // offset

Expand Down
31 changes: 25 additions & 6 deletions src/hotspot/src/cpu/aarch64/vm/sharedRuntime_aarch64.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, Red Hat Inc.
* Copyright (c) 2003, 2012, Oracle and/or its affiliates.
* All rights reserved.
Expand Down Expand Up @@ -2050,13 +2051,31 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,

__ reset_last_Java_frame(false);

// Unpack oop result
// Unbox oop result, e.g. JNIHandles::resolve result.
if (ret_type == T_OBJECT || ret_type == T_ARRAY) {
Label L;
__ cbz(r0, L);
__ ldr(r0, Address(r0, 0));
__ bind(L);
__ verify_oop(r0);
Label done, not_weak;
__ cbz(r0, done); // Use NULL as-is.
STATIC_ASSERT(JNIHandles::weak_tag_mask == 1u);
__ tbz(r0, 0, not_weak); // Test for jweak tag.
// Resolve jweak.
__ ldr(r0, Address(r0, -JNIHandles::weak_tag_value));
__ verify_oop(r0);
#if INCLUDE_ALL_GCS
if (UseG1GC) {
__ g1_write_barrier_pre(noreg /* obj */,
r0 /* pre_val */,
rthread /* thread */,
rscratch1 /* tmp */,
true /* tosca_live */,
true /* expand_call */);
}
#endif // INCLUDE_ALL_GCS
__ b(done);
__ bind(not_weak);
// Resolve (untagged) jobject.
__ ldr(r0, Address(r0, 0));
__ verify_oop(r0);
__ bind(done);
}

if (!is_critical_native) {
Expand Down
26 changes: 23 additions & 3 deletions src/hotspot/src/cpu/aarch64/vm/templateInterpreter_aarch64.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, Red Hat Inc.
* Copyright (c) 2003, 2011, Oracle and/or its affiliates.
* All rights reserved.
Expand Down Expand Up @@ -1194,13 +1195,32 @@ address InterpreterGenerator::generate_native_entry(bool synchronized) {
// and result handler will pick it up

{
Label no_oop, store_result;
Label no_oop, not_weak, store_result;
__ adr(t, ExternalAddress(AbstractInterpreter::result_handler(T_OBJECT)));
__ cmp(t, result_handler);
__ br(Assembler::NE, no_oop);
// retrieve result
// Unbox oop result, e.g. JNIHandles::resolve result.
__ pop(ltos);
__ cbz(r0, store_result);
__ cbz(r0, store_result); // Use NULL as-is.
STATIC_ASSERT(JNIHandles::weak_tag_mask == 1u);
__ tbz(r0, 0, not_weak); // Test for jweak tag.
// Resolve jweak.
__ ldr(r0, Address(r0, -JNIHandles::weak_tag_value));
#if INCLUDE_ALL_GCS
if (UseG1GC) {
__ enter(); // Barrier may call runtime.
__ g1_write_barrier_pre(noreg /* obj */,
r0 /* pre_val */,
rthread /* thread */,
t /* tmp */,
true /* tosca_live */,
true /* expand_call */);
__ leave();
}
#endif // INCLUDE_ALL_GCS
__ b(store_result);
__ bind(not_weak);
// Resolve (untagged) jobject.
__ ldr(r0, Address(r0, 0));
__ bind(store_result);
__ str(r0, Address(rfp, frame::interpreter_frame_oop_temp_offset*wordSize));
Expand Down

0 comments on commit 54dce35

Please sign in to comment.