diff options
author | Brian Carlstrom <bdc@google.com> | 2013-08-29 09:36:15 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2013-08-29 09:45:43 -0700 |
commit | e0948e13d5a4552e6a2728087573c07961e4a4f9 (patch) | |
tree | 6162dd8b5e4f05c00f5414e10d1b1ab6fba61a0d /compiler/dex/dex_to_dex_compiler.cc | |
parent | a7d56cf5e0fe6da41969f6dd841aef0d73f09d93 (diff) | |
download | android_art-e0948e13d5a4552e6a2728087573c07961e4a4f9.tar.gz android_art-e0948e13d5a4552e6a2728087573c07961e4a4f9.tar.bz2 android_art-e0948e13d5a4552e6a2728087573c07961e4a4f9.zip |
Make DexFiles opened from files readonly by default, but writable during dex2oat
Bug: 9618388
Change-Id: I83f2e16ee8446a79a94a84971146d807bb0c9ee0
Diffstat (limited to 'compiler/dex/dex_to_dex_compiler.cc')
-rw-r--r-- | compiler/dex/dex_to_dex_compiler.cc | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/compiler/dex/dex_to_dex_compiler.cc b/compiler/dex/dex_to_dex_compiler.cc index a0e2c1e9aa..a392f829f6 100644 --- a/compiler/dex/dex_to_dex_compiler.cc +++ b/compiler/dex/dex_to_dex_compiler.cc @@ -95,55 +95,6 @@ class DexCompiler { DISALLOW_COPY_AND_ASSIGN(DexCompiler); }; -// Ensures write access to a part of DEX file. -// -// If a DEX file is read-only, it modifies its protection (mprotect) so it allows -// write access to the part of DEX file defined by an address and a length. -// In this case, it also takes the DexFile::modification_lock to prevent from -// concurrent protection modification from a parallel DEX-to-DEX compilation on -// the same DEX file. -// When the instance is destroyed, it recovers original protection and releases -// the lock. -// TODO: as this scoped class is similar to a MutexLock we should use annotalysis -// to capture the locking behavior. -class ScopedDexWriteAccess { - public: - ScopedDexWriteAccess(DexFile& dex_file, Instruction* inst, - size_t length) - : dex_file_(dex_file), - address_(reinterpret_cast<uint8_t*>(inst)), - length_(length), - is_read_only_(dex_file_.IsReadOnly()) { - if (is_read_only_) { - // We need to enable DEX write access. To avoid concurrent DEX write access - // modification, we take the DexFile::modification_lock before. - dex_file_.GetModificationLock().ExclusiveLock(Thread::Current()); - bool success = dex_file_.EnableWrite(address_, length_); - DCHECK(success) << "Failed to enable DEX write access"; - } - } - - ~ScopedDexWriteAccess() { - DCHECK_EQ(is_read_only_, dex_file_.IsReadOnly()); - if (is_read_only_) { - bool success = dex_file_.DisableWrite(address_, length_); - DCHECK(success) << "Failed to disable DEX write access"; - // Now we recovered original read-only protection, we can release the - // DexFile::modification_lock. - dex_file_.GetModificationLock().ExclusiveUnlock(Thread::Current()); - } - } - - private: - DexFile& dex_file_; - // TODO: make address_ const. - uint8_t* address_; - const size_t length_; - const bool is_read_only_; - - DISALLOW_COPY_AND_ASSIGN(ScopedDexWriteAccess); -}; - void DexCompiler::Compile() { DCHECK_GE(dex_to_dex_compilation_level_, kRequired); const DexFile::CodeItem* code_item = unit_.GetCodeItem(); @@ -223,7 +174,6 @@ void DexCompiler::CompileReturnVoid(Instruction* inst, uint32_t dex_pc) { << " by " << Instruction::Name(Instruction::RETURN_VOID_BARRIER) << " at dex pc " << StringPrintf("0x%x", dex_pc) << " in method " << PrettyMethod(unit_.GetDexMethodIndex(), GetDexFile(), true); - ScopedDexWriteAccess sdwa(GetModifiableDexFile(), inst, 2u); inst->SetOpcode(Instruction::RETURN_VOID_BARRIER); } @@ -246,7 +196,6 @@ Instruction* DexCompiler::CompileCheckCast(Instruction* inst, uint32_t dex_pc) { << StringPrintf("0x%x", dex_pc) << " in method " << PrettyMethod(unit_.GetDexMethodIndex(), GetDexFile(), true); // We are modifying 4 consecutive bytes. - ScopedDexWriteAccess sdwa(GetModifiableDexFile(), inst, 4u); inst->SetOpcode(Instruction::NOP); inst->SetVRegA_10x(0u); // keep compliant with verifier. // Get to next instruction which is the second half of check-cast and replace @@ -277,7 +226,6 @@ void DexCompiler::CompileInstanceFieldAccess(Instruction* inst, << " at dex pc " << StringPrintf("0x%x", dex_pc) << " in method " << PrettyMethod(unit_.GetDexMethodIndex(), GetDexFile(), true); // We are modifying 4 consecutive bytes. - ScopedDexWriteAccess sdwa(GetModifiableDexFile(), inst, 4u); inst->SetOpcode(new_opcode); // Replace field index by field offset. inst->SetVRegC_22c(static_cast<uint16_t>(field_offset)); @@ -313,7 +261,6 @@ void DexCompiler::CompileInvokeVirtual(Instruction* inst, << " at dex pc " << StringPrintf("0x%x", dex_pc) << " in method " << PrettyMethod(unit_.GetDexMethodIndex(), GetDexFile(), true); // We are modifying 4 consecutive bytes. - ScopedDexWriteAccess sdwa(GetModifiableDexFile(), inst, 4u); inst->SetOpcode(new_opcode); // Replace method index by vtable index. if (is_range) { |