8225681: vmTestbase/nsk/jvmti/RedefineClasses/StressRedefine fails due a) MT-unsafe modification of inline cache
Summary: allow old methods in CompiledStaticDirectCall::set_to_interpreted
Reviewed-by: sspitsyn, eosterlund
--- a/src/hotspot/cpu/aarch64/compiledIC_aarch64.cpp Tue Oct 08 09:39:10 2019 -0700
+++ b/src/hotspot/cpu/aarch64/compiledIC_aarch64.cpp Tue Oct 08 13:18:40 2019 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2018, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -162,16 +162,12 @@
// Creation also verifies the object.
NativeMovConstReg* method_holder
= nativeMovConstReg_at(stub + NativeInstruction::instruction_size);
-#ifndef PRODUCT
- NativeGeneralJump* jump = nativeGeneralJump_at(method_holder->next_instruction_address());
- // read the value once
- volatile intptr_t data = method_holder->data();
- assert(data == 0 || data == (intptr_t)callee(),
- "a) MT-unsafe modification of inline cache");
- assert(data == 0 || jump->jump_destination() == entry,
- "b) MT-unsafe modification of inline cache");
+#ifdef ASSERT
+ NativeGeneralJump* jump = nativeGeneralJump_at(method_holder->next_instruction_address());
+ verify_mt_safe(callee, entry, method_holder, jump);
#endif
+
// Update stub.
method_holder->set_data((intptr_t)callee());
NativeGeneralJump::insert_unconditional(method_holder->next_instruction_address(), entry);
--- a/src/hotspot/cpu/arm/compiledIC_arm.cpp Tue Oct 08 09:39:10 2019 -0700
+++ b/src/hotspot/cpu/arm/compiledIC_arm.cpp Tue Oct 08 13:18:40 2019 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2019, 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
@@ -115,16 +115,7 @@
// Creation also verifies the object.
NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
-
-#ifdef ASSERT
- // read the value once
- volatile intptr_t data = method_holder->data();
- volatile address destination = jump->jump_destination();
- assert(data == 0 || data == (intptr_t)callee(),
- "a) MT-unsafe modification of inline cache");
- assert(destination == (address)-1 || destination == entry,
- "b) MT-unsafe modification of inline cache");
-#endif
+ verify_mt_safe(callee, entry, method_holder, jump);
// Update stub.
method_holder->set_data((intptr_t)callee());
--- a/src/hotspot/cpu/ppc/compiledIC_ppc.cpp Tue Oct 08 09:39:10 2019 -0700
+++ b/src/hotspot/cpu/ppc/compiledIC_ppc.cpp Tue Oct 08 13:18:40 2019 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2015 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -178,15 +178,7 @@
NativeMovConstReg* method_holder = nativeMovConstReg_at(stub + IC_pos_in_java_to_interp_stub);
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
-#ifdef ASSERT
- // read the value once
- volatile intptr_t data = method_holder->data();
- volatile address destination = jump->jump_destination();
- assert(data == 0 || data == (intptr_t)callee(),
- "a) MT-unsafe modification of inline cache");
- assert(destination == (address)-1 || destination == entry,
- "b) MT-unsafe modification of inline cache");
-#endif
+ verify_mt_safe(callee, entry, method_holder, jump);
// Update stub.
method_holder->set_data((intptr_t)callee());
--- a/src/hotspot/cpu/s390/compiledIC_s390.cpp Tue Oct 08 09:39:10 2019 -0700
+++ b/src/hotspot/cpu/s390/compiledIC_s390.cpp Tue Oct 08 13:18:40 2019 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -104,19 +104,7 @@
// Creation also verifies the object.
NativeMovConstReg* method_holder = nativeMovConstReg_at(stub + NativeCall::get_IC_pos_in_java_to_interp_stub());
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
-
-#ifdef ASSERT
- // A generated lambda form might be deleted from the Lambdaform
- // cache in MethodTypeForm. If a jit compiled lambdaform method
- // becomes not entrant and the cache access returns null, the new
- // resolve will lead to a new generated LambdaForm.
- volatile intptr_t data = method_holder->data();
- volatile address destination = jump->jump_destination();
- assert(data == 0 || data == (intptr_t)callee() || callee->is_compiled_lambda_form(),
- "a) MT-unsafe modification of inline cache");
- assert(destination == (address)-1 || destination == entry,
- "b) MT-unsafe modification of inline cache");
-#endif
+ verify_mt_safe(callee, entry, method_holder, jump);
// Update stub.
method_holder->set_data((intptr_t)callee(), relocInfo::metadata_type);
--- a/src/hotspot/cpu/sparc/compiledIC_sparc.cpp Tue Oct 08 09:39:10 2019 -0700
+++ b/src/hotspot/cpu/sparc/compiledIC_sparc.cpp Tue Oct 08 13:18:40 2019 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2019, 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
@@ -104,16 +104,7 @@
// Creation also verifies the object.
NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
-
-#ifdef ASSERT
- // read the value once
- volatile intptr_t data = method_holder->data();
- volatile address destination = jump->jump_destination();
- assert(data == 0 || data == (intptr_t)callee(),
- "a) MT-unsafe modification of inline cache");
- assert(destination == (address)-1 || destination == entry,
- "b) MT-unsafe modification of inline cache");
-#endif
+ verify_mt_safe(callee, entry, method_holder, jump);
// Update stub.
method_holder->set_data((intptr_t)callee());
--- a/src/hotspot/cpu/x86/compiledIC_x86.cpp Tue Oct 08 09:39:10 2019 -0700
+++ b/src/hotspot/cpu/x86/compiledIC_x86.cpp Tue Oct 08 13:18:40 2019 -0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2019, 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
@@ -157,16 +157,7 @@
// Creation also verifies the object.
NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
-
-#ifdef ASSERT
- Method* old_method = reinterpret_cast<Method*>(method_holder->data());
- address destination = jump->jump_destination();
- assert(old_method == NULL || old_method == callee() ||
- !old_method->method_holder()->is_loader_alive(),
- "a) MT-unsafe modification of inline cache");
- assert(destination == (address)-1 || destination == entry,
- "b) MT-unsafe modification of inline cache");
-#endif
+ verify_mt_safe(callee, entry, method_holder, jump);
// Update stub.
method_holder->set_data((intptr_t)callee());
--- a/src/hotspot/share/code/compiledIC.cpp Tue Oct 08 09:39:10 2019 -0700
+++ b/src/hotspot/share/code/compiledIC.cpp Tue Oct 08 13:18:40 2019 -0400
@@ -741,4 +741,22 @@
tty->cr();
}
+void CompiledDirectStaticCall::verify_mt_safe(const methodHandle& callee, address entry,
+ NativeMovConstReg* method_holder,
+ NativeJump* jump) {
+ // A generated lambda form might be deleted from the Lambdaform
+ // cache in MethodTypeForm. If a jit compiled lambdaform method
+ // becomes not entrant and the cache access returns null, the new
+ // resolve will lead to a new generated LambdaForm.
+ Method* old_method = reinterpret_cast<Method*>(method_holder->data());
+ assert(old_method == NULL || old_method == callee() ||
+ callee->is_compiled_lambda_form() ||
+ !old_method->method_holder()->is_loader_alive() ||
+ old_method->is_old(), // may be race patching deoptimized nmethod due to redefinition.
+ "a) MT-unsafe modification of inline cache");
+
+ address destination = jump->jump_destination();
+ assert(destination == (address)-1 || destination == entry,
+ "b) MT-unsafe modification of inline cache");
+}
#endif // !PRODUCT
--- a/src/hotspot/share/code/compiledIC.hpp Tue Oct 08 09:39:10 2019 -0700
+++ b/src/hotspot/share/code/compiledIC.hpp Tue Oct 08 13:18:40 2019 -0400
@@ -402,6 +402,9 @@
// Also used by CompiledIC
void set_to_interpreted(const methodHandle& callee, address entry);
+ void verify_mt_safe(const methodHandle& callee, address entry,
+ NativeMovConstReg* method_holder,
+ NativeJump* jump) PRODUCT_RETURN;
#if INCLUDE_AOT
void set_to_far(const methodHandle& callee, address entry);
#endif