summaryrefslogtreecommitdiffstats
path: root/compiler/dex/quick/dex_file_to_method_inliner_map.cc
diff options
context:
space:
mode:
authorVladimir Marko <vmarko@google.com>2013-11-20 12:44:55 +0000
committerVladimir Marko <vmarko@google.com>2013-12-13 14:27:05 +0000
commite13717e796d338b08ea66f6a7e3470ca44de707f (patch)
treeeaa49dccd39c9c3c73b6d1831c930def0c0b14a2 /compiler/dex/quick/dex_file_to_method_inliner_map.cc
parentcf28cbff9f0557dea9ed60358a956859ba1b56aa (diff)
downloadart-e13717e796d338b08ea66f6a7e3470ca44de707f.tar.gz
art-e13717e796d338b08ea66f6a7e3470ca44de707f.tar.bz2
art-e13717e796d338b08ea66f6a7e3470ca44de707f.zip
Per-DexFile locking for inliner initialization.
And clean up lock and compiler driver naming. Change-Id: I1562c7f55c4b0174a36007ba6199360da06169ff
Diffstat (limited to 'compiler/dex/quick/dex_file_to_method_inliner_map.cc')
-rw-r--r--compiler/dex/quick/dex_file_to_method_inliner_map.cc37
1 files changed, 24 insertions, 13 deletions
diff --git a/compiler/dex/quick/dex_file_to_method_inliner_map.cc b/compiler/dex/quick/dex_file_to_method_inliner_map.cc
index 0107ed3ccb..2fec183289 100644
--- a/compiler/dex/quick/dex_file_to_method_inliner_map.cc
+++ b/compiler/dex/quick/dex_file_to_method_inliner_map.cc
@@ -28,7 +28,7 @@
namespace art {
DexFileToMethodInlinerMap::DexFileToMethodInlinerMap()
- : lock_("inline_helper_mutex") {
+ : lock_("DexFileToMethodInlinerMap lock", kDexFileToMethodInlinerMapLock) {
}
DexFileToMethodInlinerMap::~DexFileToMethodInlinerMap() {
@@ -37,26 +37,37 @@ DexFileToMethodInlinerMap::~DexFileToMethodInlinerMap() {
}
}
-const DexFileMethodInliner& DexFileToMethodInlinerMap::GetMethodInliner(const DexFile* dex_file) {
+DexFileMethodInliner* DexFileToMethodInlinerMap::GetMethodInliner(const DexFile* dex_file) {
Thread* self = Thread::Current();
{
- ReaderMutexLock lock(self, lock_);
+ ReaderMutexLock mu(self, lock_);
auto it = inliners_.find(dex_file);
if (it != inliners_.end()) {
- return *it->second;
+ return it->second;
}
}
- WriterMutexLock lock(self, lock_);
- DexFileMethodInliner** inliner = &inliners_[dex_file]; // inserts new entry if not found
- if (*inliner) {
- return **inliner;
+ // We need to acquire our lock_ to modify inliners_ but we want to release it
+ // before we initialize the new inliner. However, we need to acquire the
+ // new inliner's lock_ before we release our lock_ to prevent another thread
+ // from using the uninitialized inliner. This requires explicit calls to
+ // ExclusiveLock()/ExclusiveUnlock() on one of the locks, the other one
+ // can use WriterMutexLock.
+ DexFileMethodInliner* locked_inliner;
+ {
+ WriterMutexLock mu(self, lock_);
+ DexFileMethodInliner** inliner = &inliners_[dex_file]; // inserts new entry if not found
+ if (*inliner) {
+ return *inliner;
+ }
+ *inliner = new DexFileMethodInliner;
+ DCHECK(*inliner != nullptr);
+ locked_inliner = *inliner;
+ locked_inliner->lock_.ExclusiveLock(self); // Acquire inliner's lock_ before releasing lock_.
}
- *inliner = new DexFileMethodInliner();
- DCHECK(*inliner != nullptr);
- // TODO: per-dex file locking for the intrinsics container filling.
- (*inliner)->FindIntrinsics(dex_file);
- return **inliner;
+ locked_inliner->FindIntrinsics(dex_file);
+ locked_inliner->lock_.ExclusiveUnlock(self);
+ return locked_inliner;
}
} // namespace art