summaryrefslogtreecommitdiff
path: root/runtime/class_linker.cc
diff options
context:
space:
mode:
author Andreas Gampe <agampe@google.com> 2018-03-02 17:54:22 -0800
committer Andreas Gampe <agampe@google.com> 2018-03-05 17:20:22 -0800
commitc4af33fa1ff7e0c42f02613fa1a879e4613aaad7 (patch)
treea6c794a721e23bb771b035debe4cc6302dde90f4 /runtime/class_linker.cc
parent63354d1597b8db8db2f9fb887fcf8de6e98acb70 (diff)
ART: Use try-lock for interface marking
Use ObjectTryLock for the performance optimization to help code that uses classes for locks. (cherry picked from commit 976b298a4e2d9e79983c1b131093de1a27163bf5) Bug: 72204414 Test: art/test/testrunner/testrunner.py -b --host -t 170 Merged-In: Ic00de7bc15cb7e8369ff7c68cefcb3375f9df140 Change-Id: Ic00de7bc15cb7e8369ff7c68cefcb3375f9df140
Diffstat (limited to 'runtime/class_linker.cc')
-rw-r--r--runtime/class_linker.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index c667fe2f30..2a80e3c609 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -4977,8 +4977,14 @@ bool ClassLinker::InitializeDefaultInterfaceRecursive(Thread* self,
// 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;
}