diff options
Diffstat (limited to 'runtime/runtime.cc')
| -rw-r--r-- | runtime/runtime.cc | 79 |
1 files changed, 45 insertions, 34 deletions
diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 3bd825b640..8ba098f5d9 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -43,10 +43,14 @@ #include "arch/x86/registers_x86.h" #include "arch/x86_64/quick_method_frame_info_x86_64.h" #include "arch/x86_64/registers_x86_64.h" +#include "asm_support.h" #include "atomic.h" +#include "base/dumpable.h" +#include "base/unix_file/fd_file.h" #include "class_linker.h" #include "debugger.h" #include "elf_file.h" +#include "entrypoints/runtime_asm_entrypoints.h" #include "fault_handler.h" #include "gc/accounting/card_table-inl.h" #include "gc/heap.h" @@ -92,10 +96,9 @@ namespace art { +// If a signal isn't handled properly, enable a handler that attempts to dump the Java stack. static constexpr bool kEnableJavaStackTraceHandler = false; -const char* Runtime::kDefaultInstructionSetFeatures = - STRINGIFY(ART_DEFAULT_INSTRUCTION_SET_FEATURES); -Runtime* Runtime::instance_ = NULL; +Runtime* Runtime::instance_ = nullptr; Runtime::Runtime() : instruction_set_(kNone), @@ -144,10 +147,15 @@ Runtime::Runtime() target_sdk_version_(0), implicit_null_checks_(false), implicit_so_checks_(false), - implicit_suspend_checks_(false) { + implicit_suspend_checks_(false), + is_native_bridge_loaded_(false) { + CheckAsmSupportOffsetsAndSizes(); } Runtime::~Runtime() { + if (is_native_bridge_loaded_) { + UnloadNativeBridge(); + } if (dump_gc_performance_on_shutdown_) { // This can't be called from the Heap destructor below because it // could call RosAlloc::InspectAll() which needs the thread_list @@ -169,9 +177,6 @@ Runtime::~Runtime() { BackgroundMethodSamplingProfiler::Shutdown(); } - // Shutdown the fault manager if it was initialized. - fault_manager.Shutdown(); - Trace::Shutdown(); // Make sure to let the GC complete if it is running. @@ -184,6 +189,10 @@ Runtime::~Runtime() { // Make sure all other non-daemon threads have terminated, and all daemon threads are suspended. delete thread_list_; + + // Shutdown the fault manager if it was initialized. + fault_manager.Shutdown(); + delete monitor_list_; delete monitor_pool_; delete class_linker_; @@ -200,7 +209,7 @@ Runtime::~Runtime() { } struct AbortState { - void Dump(std::ostream& os) { + void Dump(std::ostream& os) const { if (gAborting > 1) { os << "Runtime aborting --- recursively, so no thread-specific detail!\n"; return; @@ -231,7 +240,7 @@ struct AbortState { } // No thread-safety analysis as we do explicitly test for holding the mutator lock. - void DumpThread(std::ostream& os, Thread* self) NO_THREAD_SAFETY_ANALYSIS { + void DumpThread(std::ostream& os, Thread* self) const NO_THREAD_SAFETY_ANALYSIS { DCHECK(Locks::mutator_lock_->IsExclusiveHeld(self) || Locks::mutator_lock_->IsSharedHeld(self)); self->Dump(os); if (self->IsExceptionPending()) { @@ -243,7 +252,7 @@ struct AbortState { } } - void DumpAllThreads(std::ostream& os, Thread* self) { + void DumpAllThreads(std::ostream& os, Thread* self) const { Runtime* runtime = Runtime::Current(); if (runtime != nullptr) { ThreadList* thread_list = runtime->GetThreadList(); @@ -426,12 +435,11 @@ bool Runtime::Start() { return false; } } else { - bool have_native_bridge = !native_bridge_library_filename_.empty(); - if (have_native_bridge) { + if (is_native_bridge_loaded_) { PreInitializeNativeBridge("."); } - DidForkFromZygote(self->GetJniEnv(), have_native_bridge ? NativeBridgeAction::kInitialize : - NativeBridgeAction::kUnload, GetInstructionSetString(kRuntimeISA)); + DidForkFromZygote(self->GetJniEnv(), NativeBridgeAction::kInitialize, + GetInstructionSetString(kRuntimeISA)); } StartDaemonThreads(); @@ -510,14 +518,17 @@ bool Runtime::InitZygote() { void Runtime::DidForkFromZygote(JNIEnv* env, NativeBridgeAction action, const char* isa) { is_zygote_ = false; - switch (action) { - case NativeBridgeAction::kUnload: - UnloadNativeBridge(); - break; + if (is_native_bridge_loaded_) { + switch (action) { + case NativeBridgeAction::kUnload: + UnloadNativeBridge(); + is_native_bridge_loaded_ = false; + break; - case NativeBridgeAction::kInitialize: - InitializeNativeBridge(env, isa); - break; + case NativeBridgeAction::kInitialize: + InitializeNativeBridge(env, isa); + break; + } } // Create the thread pool. @@ -803,7 +814,7 @@ bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized) } } else if (!IsCompiler() || !image_dex2oat_enabled_) { std::vector<std::string> dex_filenames; - Split(boot_class_path_string_, ':', dex_filenames); + Split(boot_class_path_string_, ':', &dex_filenames); std::vector<const DexFile*> boot_class_path; OpenDexFiles(dex_filenames, options->image_, boot_class_path); class_linker_->InitWithoutImage(boot_class_path); @@ -847,14 +858,14 @@ bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized) // Pre-allocate an OutOfMemoryError for the double-OOME case. self->ThrowNewException(ThrowLocation(), "Ljava/lang/OutOfMemoryError;", "OutOfMemoryError thrown while trying to throw OutOfMemoryError; " - "no stack available"); + "no stack trace available"); pre_allocated_OutOfMemoryError_ = GcRoot<mirror::Throwable>(self->GetException(NULL)); self->ClearException(); // Pre-allocate a NoClassDefFoundError for the common case of failing to find a system class // ahead of checking the application's class loader. self->ThrowNewException(ThrowLocation(), "Ljava/lang/NoClassDefFoundError;", - "Class not found using the boot class loader; no stack available"); + "Class not found using the boot class loader; no stack trace available"); pre_allocated_NoClassDefFoundError_ = GcRoot<mirror::Throwable>(self->GetException(NULL)); self->ClearException(); @@ -885,8 +896,7 @@ bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized) // Runtime::Start(): // DidForkFromZygote(kInitialize) -> try to initialize any native bridge given. // No-op wrt native bridge. - native_bridge_library_filename_ = options->native_bridge_library_filename_; - LoadNativeBridge(native_bridge_library_filename_); + is_native_bridge_loaded_ = LoadNativeBridge(options->native_bridge_library_filename_); VLOG(startup) << "Runtime::Init exiting"; return true; @@ -914,7 +924,7 @@ void Runtime::InitNativeMethods() { { std::string mapped_name(StringPrintf(OS_SHARED_LIB_FORMAT_STR, "javacore")); std::string reason; - if (!instance_->java_vm_->LoadNativeLibrary(env, mapped_name, nullptr, &reason)) { + if (!java_vm_->LoadNativeLibrary(env, mapped_name, nullptr, &reason)) { LOG(FATAL) << "LoadNativeLibrary failed for \"" << mapped_name << "\": " << reason; } } @@ -1216,8 +1226,8 @@ mirror::ArtMethod* Runtime::CreateImtConflictMethod() { method->SetEntryPointFromPortableCompiledCode(nullptr); method->SetEntryPointFromQuickCompiledCode(nullptr); } else { - method->SetEntryPointFromPortableCompiledCode(class_linker->GetPortableImtConflictTrampoline()); - method->SetEntryPointFromQuickCompiledCode(class_linker->GetQuickImtConflictTrampoline()); + method->SetEntryPointFromPortableCompiledCode(GetPortableImtConflictStub()); + method->SetEntryPointFromQuickCompiledCode(GetQuickImtConflictStub()); } return method.Get(); } @@ -1236,8 +1246,8 @@ mirror::ArtMethod* Runtime::CreateResolutionMethod() { method->SetEntryPointFromPortableCompiledCode(nullptr); method->SetEntryPointFromQuickCompiledCode(nullptr); } else { - method->SetEntryPointFromPortableCompiledCode(class_linker->GetPortableResolutionTrampoline()); - method->SetEntryPointFromQuickCompiledCode(class_linker->GetQuickResolutionTrampoline()); + method->SetEntryPointFromPortableCompiledCode(GetPortableResolutionStub()); + method->SetEntryPointFromQuickCompiledCode(GetQuickResolutionStub()); } return method.Get(); } @@ -1454,9 +1464,10 @@ void Runtime::AddCurrentRuntimeFeaturesAsDex2OatArguments(std::vector<std::strin instruction_set += GetInstructionSetString(kRuntimeISA); argv->push_back(instruction_set); - std::string features("--instruction-set-features="); - features += GetDefaultInstructionSetFeatures(); - argv->push_back(features); + std::unique_ptr<const InstructionSetFeatures> features(InstructionSetFeatures::FromCppDefines()); + std::string feature_string("--instruction-set-features="); + feature_string += features->GetFeatureString(); + argv->push_back(feature_string); } void Runtime::UpdateProfilerState(int state) { |