--- old/src/cpu/aarch64/vm/jniFastGetField_aarch64.cpp 2017-02-23 13:57:08.201894304 +0100 +++ new/src/cpu/aarch64/vm/jniFastGetField_aarch64.cpp 2017-02-23 13:57:08.101895289 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, Red Hat Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -83,6 +83,8 @@ // 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 --- old/src/cpu/arm/vm/jniFastGetField_arm.cpp 2017-02-23 13:57:08.669889694 +0100 +++ new/src/cpu/arm/vm/jniFastGetField_arm.cpp 2017-02-23 13:57:08.573890640 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2017, 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 @@ -119,10 +119,12 @@ __ ldr_s32(Rsafept_cnt, Address(Rsafepoint_counter_addr)); __ tbnz(Rsafept_cnt, 0, slow_case); -#ifndef AARCH64 - __ bic(R1, R1, JNIHandles::weak_tag_mask); -#else +#ifdef AARCH64 + // If mask changes we need to ensure that the inverse is still encodable as an immediate + STATIC_ASSERT(JNIHandles::weak_tag_mask == 1); __ andr(R1, R1, ~JNIHandles::weak_tag_mask); +#else + __ bic(R1, R1, JNIHandles::weak_tag_mask); #endif if (os::is_MP()) { --- old/src/cpu/sparc/vm/jniFastGetField_sparc.cpp 2017-02-23 13:57:09.161884847 +0100 +++ new/src/cpu/sparc/vm/jniFastGetField_sparc.cpp 2017-02-23 13:57:09.057885871 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2017, 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 --- old/src/cpu/x86/vm/jniFastGetField_x86_32.cpp 2017-02-23 13:57:09.621880316 +0100 +++ new/src/cpu/x86/vm/jniFastGetField_x86_32.cpp 2017-02-23 13:57:09.525881261 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2017, 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 @@ -86,9 +86,7 @@ } __ movptr(rax, Address(rsp, 3*wordSize)); // jfieldID - const intptr_t inverted_jweak_mask = ~static_cast(JNIHandles::weak_tag_mask); - assert(inverted_jweak_mask == -2, "Otherwise check this code"); - __ andl(rdx, inverted_jweak_mask); // mask is subject to sign-extension + __ clear_jweak_tag(rdx); __ movptr(rdx, Address(rdx, 0)); // *obj __ shrptr (rax, 2); // offset @@ -208,9 +206,7 @@ } __ movptr(rsi, Address(rsp, 4*wordSize)); // jfieldID - const intptr_t inverted_jweak_mask = ~static_cast(JNIHandles::weak_tag_mask); - assert(inverted_jweak_mask == -2, "Otherwise check this code"); - __ andl(rdx, inverted_jweak_mask); // mask is subject to sign-extension + __ clear_jweak_tag(rdx); __ movptr(rdx, Address(rdx, 0)); // *obj __ shrptr(rsi, 2); // offset @@ -302,9 +298,7 @@ } __ movptr(rax, Address(rsp, 3*wordSize)); // jfieldID - const intptr_t inverted_jweak_mask = ~static_cast(JNIHandles::weak_tag_mask); - assert(inverted_jweak_mask == -2, "Otherwise check this code"); - __ andl(rdx, inverted_jweak_mask); // mask is subject to sign-extension + __ clear_jweak_tag(rdx); __ movptr(rdx, Address(rdx, 0)); // *obj __ shrptr(rax, 2); // offset --- old/src/cpu/x86/vm/jniFastGetField_x86_64.cpp 2017-02-23 13:57:10.081875784 +0100 +++ new/src/cpu/x86/vm/jniFastGetField_x86_64.cpp 2017-02-23 13:57:09.985876730 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2017, 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 @@ -81,10 +81,7 @@ // robj is data dependent on rcounter. } - const intptr_t inverted_jweak_mask = ~static_cast(JNIHandles::weak_tag_mask); - const int32_t truncated_mask = static_cast(inverted_jweak_mask); - assert(truncated_mask == -2, "Otherwise check this code"); - __ andq(robj, truncated_mask); // mask is subject to sign-extension + __ clear_jweak_tag(robj); __ movptr(robj, Address(robj, 0)); // *obj __ mov (roffset, c_rarg2); @@ -185,10 +182,7 @@ // robj is data dependent on rcounter. } - const intptr_t inverted_jweak_mask = ~static_cast(JNIHandles::weak_tag_mask); - const int32_t truncated_mask = static_cast(inverted_jweak_mask); - assert(truncated_mask == -2, "Otherwise check this code"); - __ andq(robj, truncated_mask); // mask is subject to sign-extension + __ clear_jweak_tag(robj); __ movptr(robj, Address(robj, 0)); // *obj __ mov (roffset, c_rarg2); --- old/src/cpu/x86/vm/macroAssembler_x86.cpp 2017-02-23 13:57:10.553871135 +0100 +++ new/src/cpu/x86/vm/macroAssembler_x86.cpp 2017-02-23 13:57:10.453872120 +0100 @@ -5159,6 +5159,13 @@ bind(done); } +void MacroAssembler::clear_jweak_tag(Register possibly_jweak) { + const int32_t inverted_jweak_mask = ~static_cast(JNIHandles::weak_tag_mask); + STATIC_ASSERT(inverted_jweak_mask == -2); // otherwise check this code + // The inverted mask is sign-extended + andptr(possibly_jweak, inverted_jweak_mask); +} + ////////////////////////////////////////////////////////////////////////////////// #if INCLUDE_ALL_GCS --- old/src/cpu/x86/vm/macroAssembler_x86.hpp 2017-02-23 13:57:11.077865973 +0100 +++ new/src/cpu/x86/vm/macroAssembler_x86.hpp 2017-02-23 13:57:10.981866919 +0100 @@ -298,6 +298,7 @@ void store_check(Register obj, Address dst); // same as above, dst is exact store location (reg. is destroyed) void resolve_jobject(Register value, Register thread, Register tmp); + void clear_jweak_tag(Register possibly_jweak); #if INCLUDE_ALL_GCS --- old/test/runtime/jni/CallWithJNIWeak/libCallWithJNIWeak.c 2017-02-23 13:57:11.545861363 +0100 +++ new/test/runtime/jni/CallWithJNIWeak/libCallWithJNIWeak.c 2017-02-23 13:57:11.449862309 +0100 @@ -48,12 +48,13 @@ jfieldID id_l = (*env)->GetFieldID(env, this_class, "l", "Ljava/lang/Object;"); jvalue v; -#define CHECK(variable, expected) \ - do { if ((variable) != (expected)) { \ - (*env)->ThrowNew(env, exception, #variable" != " #expected); \ - return; \ - } \ -} while(0); +#define CHECK(variable, expected) \ + do { \ + if ((variable) != (expected)) { \ + (*env)->ThrowNew(env, exception, #variable" != " #expected); \ + return; \ + } \ + } while(0) v.i = (*env)->GetIntField(env, self, id_i); CHECK(v.i, 1);