dex_file_to_method_inliner_map.cc revision e4a50ee34695a9d90cf03fbb1e8afd1e434f6ee1
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#include "dex/quick/arm/arm_dex_file_method_inliner.h" 26#include "dex/quick/mips/mips_dex_file_method_inliner.h" 27#include "dex/quick/x86/x86_dex_file_method_inliner.h" 28 29#include "dex_file_to_method_inliner_map.h" 30 31namespace art { 32 33DexFileToMethodInlinerMap::DexFileToMethodInlinerMap(const CompilerDriver* compiler) 34 : compiler_(compiler), 35 mutex_("inline_helper_mutex") { 36} 37 38DexFileToMethodInlinerMap::~DexFileToMethodInlinerMap() { 39 for (auto& entry : inliners_) { 40 delete entry.second; 41 } 42} 43 44const DexFileMethodInliner& DexFileToMethodInlinerMap::GetMethodInliner(const DexFile* dex_file) { 45 Thread* self = Thread::Current(); 46 { 47 ReaderMutexLock lock(self, mutex_); 48 auto it = inliners_.find(dex_file); 49 if (it != inliners_.end()) { 50 return *it->second; 51 } 52 } 53 54 WriterMutexLock lock(self, mutex_); 55 DexFileMethodInliner** inliner = &inliners_[dex_file]; // inserts new entry if not found 56 if (*inliner) { 57 return **inliner; 58 } 59 switch (compiler_->GetInstructionSet()) { 60 case kThumb2: 61 *inliner = new ArmDexFileMethodInliner; 62 break; 63 case kX86: 64 *inliner = new X86DexFileMethodInliner; 65 break; 66 case kMips: 67 *inliner = new MipsDexFileMethodInliner; 68 break; 69 default: 70 LOG(FATAL) << "Unexpected instruction set: " << compiler_->GetInstructionSet(); 71 } 72 DCHECK(*inliner != nullptr); 73 // TODO: per-dex file locking for the intrinsics container filling. 74 (*inliner)->FindIntrinsics(dex_file); 75 return **inliner; 76} 77 78} // namespace art 79