dex_file_to_method_inliner_map.cc revision 867a2b35e67ddcbec089964e8f3cd9a827186e48
1/* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include <algorithm> 18#include <utility> 19#include "thread.h" 20#include "thread-inl.h" 21#include "base/mutex.h" 22#include "base/mutex-inl.h" 23#include "base/logging.h" 24#include "driver/compiler_driver.h" 25 26#include "dex_file_to_method_inliner_map.h" 27 28namespace art { 29 30DexFileToMethodInlinerMap::DexFileToMethodInlinerMap() 31 : lock_("inline_helper_mutex") { 32} 33 34DexFileToMethodInlinerMap::~DexFileToMethodInlinerMap() { 35 for (auto& entry : inliners_) { 36 delete entry.second; 37 } 38} 39 40const DexFileMethodInliner& DexFileToMethodInlinerMap::GetMethodInliner(const DexFile* dex_file) { 41 Thread* self = Thread::Current(); 42 { 43 ReaderMutexLock lock(self, lock_); 44 auto it = inliners_.find(dex_file); 45 if (it != inliners_.end()) { 46 return *it->second; 47 } 48 } 49 50 WriterMutexLock lock(self, lock_); 51 DexFileMethodInliner** inliner = &inliners_[dex_file]; // inserts new entry if not found 52 if (*inliner) { 53 return **inliner; 54 } 55 *inliner = new DexFileMethodInliner(); 56 DCHECK(*inliner != nullptr); 57 // TODO: per-dex file locking for the intrinsics container filling. 58 (*inliner)->FindIntrinsics(dex_file); 59 return **inliner; 60} 61 62} // namespace art 63