diff options
| author | 2012-03-06 17:26:37 -0800 | |
|---|---|---|
| committer | 2012-03-06 21:53:05 -0800 | |
| commit | 63deaad18853e55097761e47a9eedd12eb0c1e58 (patch) | |
| tree | 4eb14783cac63b87c7985409a8f8d70ebceaa4e5 /src/compiler_llvm/compiler_llvm.cc | |
| parent | adb8c67f6d87a160d4e3a8afea7cb93f6c14568b (diff) | |
Fix memory corruption due to premature llvm_shutdown().
Under LLVM, multiple compiler-related gtests randomly crashes from time
to time, because common_test.h has code to new multiple compiler
instances. Multiple CompilerLLVM instances may cause crash if one
shuts down LLVM prematurely.
This fix uses static class member. Destructor is where we shut
down LLVM.
Change-Id: Ied371794af7ca9eb2c9fe6b278fd779a61a4a753
Diffstat (limited to 'src/compiler_llvm/compiler_llvm.cc')
| -rw-r--r-- | src/compiler_llvm/compiler_llvm.cc | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/compiler_llvm/compiler_llvm.cc b/src/compiler_llvm/compiler_llvm.cc index b2a6d28315..6646b196ca 100644 --- a/src/compiler_llvm/compiler_llvm.cc +++ b/src/compiler_llvm/compiler_llvm.cc @@ -41,11 +41,10 @@ extern llvm::cl::opt<bool> EnableARMLongCalls; // ARMISelLowering.cpp, however, it is not in the llvm namespace. -namespace { - -pthread_once_t llvm_initialized = PTHREAD_ONCE_INIT; +namespace art { +namespace compiler_llvm { -void InitializeLLVM() { +CompilerLLVM::LLVMInitializer::LLVMInitializer() { // NOTE: Uncomment following line to show the time consumption of LLVM passes //llvm::TimePassesIsEnabled = true; @@ -76,11 +75,13 @@ void InitializeLLVM() { llvm::llvm_start_multithreaded(); } -} // anonymous namespace - +CompilerLLVM::LLVMInitializer::~LLVMInitializer() { + llvm::llvm_shutdown(); +} -namespace art { -namespace compiler_llvm { +// Singleton. Otherwise, multiple CompilerLLVM instances may cause crashes if +// one shuts down prematurely. +CompilerLLVM::LLVMInitializer CompilerLLVM::llvm_initialize_guard; llvm::Module* makeLLVMModuleContents(llvm::Module* module); @@ -89,20 +90,15 @@ llvm::Module* makeLLVMModuleContents(llvm::Module* module); CompilerLLVM::CompilerLLVM(Compiler* compiler, InstructionSet insn_set) : compiler_(compiler), compiler_lock_("llvm_compiler_lock"), insn_set_(insn_set), curr_cunit_(NULL) { - - // Initialize LLVM libraries - pthread_once(&llvm_initialized, InitializeLLVM); } CompilerLLVM::~CompilerLLVM() { STLDeleteElements(&cunits_); - llvm::llvm_shutdown(); } void CompilerLLVM::EnsureCompilationUnit() { - DCHECK_NE(llvm_initialized, PTHREAD_ONCE_INIT); compiler_lock_.AssertHeld(); if (curr_cunit_ != NULL) { |