From 54dce35f6025093995f5cb7d14e5c32941ba6004 Mon Sep 17 00:00:00 2001 From: Xin Liu Date: Sat, 13 Jul 2019 16:16:56 -0700 Subject: [PATCH] amend arm64 specific code for weak JNI handles --- .../aarch64/vm/jniFastGetField_aarch64.cpp | 6 ++++ .../cpu/aarch64/vm/sharedRuntime_aarch64.cpp | 31 +++++++++++++++---- .../vm/templateInterpreter_aarch64.cpp | 26 ++++++++++++++-- 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/src/hotspot/src/cpu/aarch64/vm/jniFastGetField_aarch64.cpp b/src/hotspot/src/cpu/aarch64/vm/jniFastGetField_aarch64.cpp index d3c56f65538..ab0204addf3 100644 --- a/src/hotspot/src/cpu/aarch64/vm/jniFastGetField_aarch64.cpp +++ b/src/hotspot/src/cpu/aarch64/vm/jniFastGetField_aarch64.cpp @@ -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. @@ -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 diff --git a/src/hotspot/src/cpu/aarch64/vm/sharedRuntime_aarch64.cpp b/src/hotspot/src/cpu/aarch64/vm/sharedRuntime_aarch64.cpp index 7a5ae55cc38..b8f7a830456 100644 --- a/src/hotspot/src/cpu/aarch64/vm/sharedRuntime_aarch64.cpp +++ b/src/hotspot/src/cpu/aarch64/vm/sharedRuntime_aarch64.cpp @@ -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. @@ -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) { diff --git a/src/hotspot/src/cpu/aarch64/vm/templateInterpreter_aarch64.cpp b/src/hotspot/src/cpu/aarch64/vm/templateInterpreter_aarch64.cpp index 5361527bcca..75f5d775d83 100644 --- a/src/hotspot/src/cpu/aarch64/vm/templateInterpreter_aarch64.cpp +++ b/src/hotspot/src/cpu/aarch64/vm/templateInterpreter_aarch64.cpp @@ -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. @@ -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));