(Un)instrumenting requires the instrumenting lock, which must be
acquired before the mutator lock. As the plugin can be called both
with and without the lock held, be careful. For simplicity, acquire
the lock (potentially) and immediately suspend.
Bug:
31684277
Test: m test-art-host
Change-Id: Ia6cee2cbe90f13f5543bdfea815d469b28a0f8f4
#include "mirror/object.h"
#include "runtime.h"
#include "ScopedLocalRef.h"
+#include "scoped_thread_state_change-inl.h"
+#include "thread-inl.h"
namespace openjdkjvmti {
};
static void SetupObjectAllocationTracking(art::gc::AllocationListener* listener, bool enable) {
+ // We must not hold the mutator lock here, but if we're in FastJNI, for example, we might. For
+ // now, do a workaround: (possibly) acquire and release.
+ art::ScopedObjectAccess soa(art::Thread::Current());
+ art::ScopedThreadSuspension sts(soa.Self(), art::ThreadState::kSuspended);
if (enable) {
art::Runtime::Current()->GetHeap()->SetAllocationListener(listener);
} else {