Consolidate updating of reflective Field/Method references
Previously we used several different visitors to update Field &
Method references for structural redefinition. We also did not visit
or update JVMTI based references.
This consolidates all the visitors to a single
Runtime::VisitReflectiveTargets function with a single
ReflectiveTargetVisitor type. This simplifies the code around
structural redefinition and ensures that the reflective value holders
are in charge of the actual replacement.
Support was also added for walking internal openjdkjvmti references
for things like field-read/modification events.
Test: ./test.py --host
Bug: 134162467
Change-Id: Ic5fc1db7db0a30f947a1a67259dc024e149ebd57
diff --git a/runtime/runtime_callbacks.h b/runtime/runtime_callbacks.h
index fe7bb0c..7111ba0 100644
--- a/runtime/runtime_callbacks.h
+++ b/runtime/runtime_callbacks.h
@@ -44,6 +44,7 @@
class Monitor;
class ReaderWriterMutex;
class ThreadLifecycleCallback;
+class ReflectiveValueVisitor;
// Note: RuntimeCallbacks uses the mutator lock to synchronize the callback lists. A thread must
// hold the exclusive lock to add or remove a listener. A thread must hold the shared lock
@@ -156,6 +157,17 @@
virtual bool MethodNeedsDebugVersion(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_) = 0;
};
+// Callback to let something request to be notified when reflective objects are being visited and
+// updated to update any bare ArtMethod/ArtField pointers it might have.
+class ReflectiveValueVisitCallback {
+ public:
+ virtual ~ReflectiveValueVisitCallback() {}
+
+ // Called when something visits all reflective values with the update visitor.
+ virtual void VisitReflectiveTargets(ReflectiveValueVisitor* visitor)
+ REQUIRES(Locks::mutator_lock_) = 0;
+};
+
class RuntimeCallbacks {
public:
RuntimeCallbacks();
@@ -257,6 +269,13 @@
void RemoveDebuggerControlCallback(DebuggerControlCallback* cb)
REQUIRES_SHARED(Locks::mutator_lock_);
+ void VisitReflectiveTargets(ReflectiveValueVisitor* visitor) REQUIRES(Locks::mutator_lock_);
+
+ void AddReflectiveValueVisitCallback(ReflectiveValueVisitCallback* cb)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+ void RemoveReflectiveValueVisitCallback(ReflectiveValueVisitCallback* cb)
+ REQUIRES_SHARED(Locks::mutator_lock_);
+
private:
std::unique_ptr<ReaderWriterMutex> callback_lock_ BOTTOM_MUTEX_ACQUIRED_AFTER;
@@ -280,6 +299,8 @@
GUARDED_BY(callback_lock_);
std::vector<DebuggerControlCallback*> debugger_control_callbacks_
GUARDED_BY(callback_lock_);
+ std::vector<ReflectiveValueVisitCallback*> reflective_value_visit_callbacks_
+ GUARDED_BY(callback_lock_);
};
} // namespace art