summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/instrumentation.cc11
-rw-r--r--runtime/instrumentation.h4
-rw-r--r--runtime/jit/jit_code_cache.cc4
3 files changed, 18 insertions, 1 deletions
diff --git a/runtime/instrumentation.cc b/runtime/instrumentation.cc
index 4524448916..2101f6837b 100644
--- a/runtime/instrumentation.cc
+++ b/runtime/instrumentation.cc
@@ -776,6 +776,17 @@ void Instrumentation::UpdateMethodsCodeImpl(ArtMethod* method, const void* quick
UpdateEntrypoints(method, new_quick_code);
}
+void Instrumentation::UpdateNativeMethodsCodeToJitCode(ArtMethod* method, const void* quick_code) {
+ // We don't do any read barrier on `method`'s declaring class in this code, as the JIT might
+ // enter here on a soon-to-be deleted ArtMethod. Updating the entrypoint is OK though, as
+ // the ArtMethod is still in memory.
+ const void* new_quick_code = quick_code;
+ if (UNLIKELY(instrumentation_stubs_installed_) && entry_exit_stubs_installed_) {
+ new_quick_code = GetQuickInstrumentationEntryPoint();
+ }
+ UpdateEntrypoints(method, new_quick_code);
+}
+
void Instrumentation::UpdateMethodsCode(ArtMethod* method, const void* quick_code) {
DCHECK(method->GetDeclaringClass()->IsResolved());
UpdateMethodsCodeImpl(method, quick_code);
diff --git a/runtime/instrumentation.h b/runtime/instrumentation.h
index da63152d10..46b3f8d85f 100644
--- a/runtime/instrumentation.h
+++ b/runtime/instrumentation.h
@@ -280,6 +280,10 @@ class Instrumentation {
void UpdateMethodsCode(ArtMethod* method, const void* quick_code)
REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_);
+ // Update the code of a native method to a JITed stub.
+ void UpdateNativeMethodsCodeToJitCode(ArtMethod* method, const void* quick_code)
+ REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_);
+
// Update the code of a method to the interpreter respecting any installed stubs from debugger.
void UpdateMethodsCodeToInterpreterEntryPoint(ArtMethod* method)
REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!deoptimized_methods_lock_);
diff --git a/runtime/jit/jit_code_cache.cc b/runtime/jit/jit_code_cache.cc
index 3d3e61b233..7f0447732e 100644
--- a/runtime/jit/jit_code_cache.cc
+++ b/runtime/jit/jit_code_cache.cc
@@ -1699,7 +1699,9 @@ bool JitCodeCache::NotifyCompilationOf(ArtMethod* method, Thread* self, bool osr
// can avoid a few expensive GenericJNI calls.
instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
for (ArtMethod* m : data->GetMethods()) {
- instrumentation->UpdateMethodsCode(m, entrypoint);
+ // Call the dedicated method instead of the more generic UpdateMethodsCode, because
+ // `m` might be in the process of being deleted.
+ instrumentation->UpdateNativeMethodsCodeToJitCode(m, entrypoint);
}
if (collection_in_progress_) {
GetLiveBitmap()->AtomicTestAndSet(FromCodeToAllocation(data->GetCode()));