From da0a69edb24122d3d35ce1483c5ab94de919d714 Mon Sep 17 00:00:00 2001 From: Richard Uhler Date: Tue, 11 Oct 2016 15:06:38 +0100 Subject: Return error message if IndirectReferenceTable construction fails. Previously if there was an error when constructing the IndirectReferenceTable, the error message was lost. Now expose and include the error message when throwing an exception related to failures to construct the IndirectReferenceTable. The error message is propagated through JVMEnvExt, JavaVMExt, and Runtime::Init as well. Bug: 32013594 Test: Added new 151-OpenFileLimit runtest. Test: m test-art-host, m test-art-target Change-Id: I3692f6928c9570358571bce634569d6f14cdeb05 --- runtime/java_vm_ext.cc | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'runtime/java_vm_ext.cc') diff --git a/runtime/java_vm_ext.cc b/runtime/java_vm_ext.cc index 99edb7c569..eec1903dd2 100644 --- a/runtime/java_vm_ext.cc +++ b/runtime/java_vm_ext.cc @@ -411,7 +411,9 @@ const JNIInvokeInterface gJniInvokeInterface = { JII::AttachCurrentThreadAsDaemon }; -JavaVMExt::JavaVMExt(Runtime* runtime, const RuntimeArgumentMap& runtime_options) +JavaVMExt::JavaVMExt(Runtime* runtime, + const RuntimeArgumentMap& runtime_options, + std::string* error_msg) : runtime_(runtime), check_jni_abort_hook_(nullptr), check_jni_abort_hook_data_(nullptr), @@ -420,10 +422,10 @@ JavaVMExt::JavaVMExt(Runtime* runtime, const RuntimeArgumentMap& runtime_options tracing_enabled_(runtime_options.Exists(RuntimeArgumentMap::JniTrace) || VLOG_IS_ON(third_party_jni)), trace_(runtime_options.GetOrDefault(RuntimeArgumentMap::JniTrace)), - globals_(kGlobalsMax, kGlobal), + globals_(kGlobalsMax, kGlobal, error_msg), libraries_(new Libraries), unchecked_functions_(&gJniInvokeInterface), - weak_globals_(kWeakGlobalsMax, kWeakGlobal), + weak_globals_(kWeakGlobalsMax, kWeakGlobal, error_msg), allow_accessing_weak_globals_(true), weak_globals_add_condition_("weak globals add condition", (CHECK(Locks::jni_weak_globals_lock_ != nullptr), @@ -436,6 +438,19 @@ JavaVMExt::JavaVMExt(Runtime* runtime, const RuntimeArgumentMap& runtime_options JavaVMExt::~JavaVMExt() { } +// Checking "globals" and "weak_globals" usually requires locks, but we +// don't need the locks to check for validity when constructing the +// object. Use NO_THREAD_SAFETY_ANALYSIS for this. +std::unique_ptr JavaVMExt::Create(Runtime* runtime, + const RuntimeArgumentMap& runtime_options, + std::string* error_msg) NO_THREAD_SAFETY_ANALYSIS { + std::unique_ptr java_vm(new JavaVMExt(runtime, runtime_options, error_msg)); + if (java_vm && java_vm->globals_.IsValid() && java_vm->weak_globals_.IsValid()) { + return java_vm; + } + return nullptr; +} + jint JavaVMExt::HandleGetEnv(/*out*/void** env, jint version) { for (GetEnvHook hook : env_hooks_) { jint res = hook(this, env, version); -- cgit v1.2.3-59-g8ed1b