ART: Use try-lock for interface marking
Use ObjectTryLock for the performance optimization to help code
that uses classes for locks.
Bug: 72204414
Test: art/test/testrunner/testrunner.py -b --host -t 170
Change-Id: Ic00de7bc15cb7e8369ff7c68cefcb3375f9df140
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index c667fe2..2a80e3c 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -4977,8 +4977,14 @@
// interface since we can still avoid the traversal. This is purely a performance optimization.
if (result) {
// TODO This should be done in a better way
- ObjectLock<mirror::Class> lock(self, iface);
- iface->SetRecursivelyInitialized();
+ // Note: Use a try-lock to avoid blocking when someone else is holding the lock on this
+ // interface. It is bad (Java) style, but not impossible. Marking the recursive
+ // initialization is a performance optimization (to avoid another idempotent visit
+ // for other implementing classes/interfaces), and can be revisited later.
+ ObjectTryLock<mirror::Class> lock(self, iface);
+ if (lock.Acquired()) {
+ iface->SetRecursivelyInitialized();
+ }
}
return result;
}