summaryrefslogtreecommitdiffstats
path: root/runtime/runtime.cc
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2015-04-22 13:56:20 -0700
committerMathieu Chartier <mathieuc@google.com>2015-06-02 09:21:27 -0700
commit3d21bdf8894e780d349c481e5c9e29fe1556051c (patch)
tree61a5231f36c0dabd73457fec81df103462a05aff /runtime/runtime.cc
parent71f0a8a123fa27bdc857a98afebbaf0ed09dac15 (diff)
downloadart-3d21bdf8894e780d349c481e5c9e29fe1556051c.zip
art-3d21bdf8894e780d349c481e5c9e29fe1556051c.tar.gz
art-3d21bdf8894e780d349c481e5c9e29fe1556051c.tar.bz2
Move mirror::ArtMethod to native
Optimizing + quick tests are passing, devices boot. TODO: Test and fix bugs in mips64. Saves 16 bytes per most ArtMethod, 7.5MB reduction in system PSS. Some of the savings are from removal of virtual methods and direct methods object arrays. Bug: 19264997 (cherry picked from commit e401d146407d61eeb99f8d6176b2ac13c4df1e33) Change-Id: I622469a0cfa0e7082a2119f3d6a9491eb61e3f3d Fix some ArtMethod related bugs Added root visiting for runtime methods, not currently required since the GcRoots in these methods are null. Added missing GetInterfaceMethodIfProxy in GetMethodLine, fixes --trace run-tests 005, 044. Fixed optimizing compiler bug where we used a normal stack location instead of double on ARM64, this fixes the debuggable tests. TODO: Fix JDWP tests. Bug: 19264997 Change-Id: I7c55f69c61d1b45351fd0dc7185ffe5efad82bd3 ART: Fix casts for 64-bit pointers on 32-bit compiler. Bug: 19264997 Change-Id: Ief45cdd4bae5a43fc8bfdfa7cf744e2c57529457 Fix JDWP tests after ArtMethod change Fixes Throwable::GetStackDepth for exception event detection after internal stack trace representation change. Adds missing ArtMethod::GetInterfaceMethodIfProxy call in case of proxy method. Bug: 19264997 Change-Id: I363e293796848c3ec491c963813f62d868da44d2 Fix accidental IMT and root marking regression Was always using the conflict trampoline. Also included fix for regression in GC time caused by extra roots. Most of the regression was IMT. Fixed bug in DumpGcPerformanceInfo where we would get SIGABRT due to detached thread. EvaluateAndApplyChanges: From ~2500 -> ~1980 GC time: 8.2s -> 7.2s due to 1s less of MarkConcurrentRoots Bug: 19264997 Change-Id: I4333e80a8268c2ed1284f87f25b9f113d4f2c7e0 Fix bogus image test assert Previously we were comparing the size of the non moving space to size of the image file. Now we properly compare the size of the image space against the size of the image file. Bug: 19264997 Change-Id: I7359f1f73ae3df60c5147245935a24431c04808a [MIPS64] Fix art_quick_invoke_stub argument offsets. ArtMethod reference's size got bigger, so we need to move other args and leave enough space for ArtMethod* and 'this' pointer. This fixes mips64 boot. Bug: 19264997 Change-Id: I47198d5f39a4caab30b3b77479d5eedaad5006ab
Diffstat (limited to 'runtime/runtime.cc')
-rw-r--r--runtime/runtime.cc126
1 files changed, 59 insertions, 67 deletions
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 2618661..65ea77a 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -49,6 +49,7 @@
#include "arch/x86_64/quick_method_frame_info_x86_64.h"
#include "arch/x86_64/registers_x86_64.h"
#include "art_field-inl.h"
+#include "art_method-inl.h"
#include "asm_support.h"
#include "atomic.h"
#include "base/arena_allocator.h"
@@ -73,7 +74,6 @@
#include "jni_internal.h"
#include "linear_alloc.h"
#include "mirror/array.h"
-#include "mirror/art_method-inl.h"
#include "mirror/class-inl.h"
#include "mirror/class_loader.h"
#include "mirror/field.h"
@@ -189,6 +189,7 @@ Runtime::Runtime()
is_native_bridge_loaded_(false),
zygote_max_failed_boots_(0) {
CheckAsmSupportOffsetsAndSizes();
+ std::fill(callee_save_methods_, callee_save_methods_ + arraysize(callee_save_methods_), 0u);
}
Runtime::~Runtime() {
@@ -425,20 +426,20 @@ static jobject CreateSystemClassLoader(Runtime* runtime) {
ScopedObjectAccess soa(Thread::Current());
ClassLinker* cl = Runtime::Current()->GetClassLinker();
+ auto pointer_size = cl->GetImagePointerSize();
StackHandleScope<2> hs(soa.Self());
Handle<mirror::Class> class_loader_class(
hs.NewHandle(soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_ClassLoader)));
CHECK(cl->EnsureInitialized(soa.Self(), class_loader_class, true, true));
- mirror::ArtMethod* getSystemClassLoader =
- class_loader_class->FindDirectMethod("getSystemClassLoader", "()Ljava/lang/ClassLoader;");
+ ArtMethod* getSystemClassLoader = class_loader_class->FindDirectMethod(
+ "getSystemClassLoader", "()Ljava/lang/ClassLoader;", pointer_size);
CHECK(getSystemClassLoader != nullptr);
JValue result = InvokeWithJValues(soa, nullptr, soa.EncodeMethod(getSystemClassLoader), nullptr);
JNIEnv* env = soa.Self()->GetJniEnv();
- ScopedLocalRef<jobject> system_class_loader(env,
- soa.AddLocalReference<jobject>(result.GetL()));
+ ScopedLocalRef<jobject> system_class_loader(env, soa.AddLocalReference<jobject>(result.GetL()));
CHECK(system_class_loader.get() != nullptr);
soa.Self()->SetClassLoaderOverride(system_class_loader.get());
@@ -867,18 +868,17 @@ bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized)
}
jit_options_.reset(jit::JitOptions::CreateFromRuntimeArguments(runtime_options));
- bool use_jit = jit_options_->UseJIT();
if (IsAotCompiler()) {
// If we are already the compiler at this point, we must be dex2oat. Don't create the jit in
// this case.
// If runtime_options doesn't have UseJIT set to true then CreateFromRuntimeArguments returns
// null and we don't create the jit.
- use_jit = false;
+ jit_options_->SetUseJIT(false);
}
// Use MemMap arena pool for jit, malloc otherwise. Malloc arenas are faster to allocate but
// can't be trimmed as easily.
- const bool use_malloc = !use_jit;
+ const bool use_malloc = IsAotCompiler();
arena_pool_.reset(new ArenaPool(use_malloc, false));
if (IsCompiler() && Is64BitInstructionSet(kRuntimeISA)) {
// 4gb, no malloc. Explanation in header.
@@ -1089,6 +1089,7 @@ bool Runtime::Init(const RuntimeOptions& raw_options, bool ignore_unrecognized)
}
VLOG(startup) << "Runtime::Init exiting";
+
return true;
}
@@ -1311,7 +1312,6 @@ mirror::Throwable* Runtime::GetPreAllocatedNoClassDefFoundError() {
void Runtime::VisitConstantRoots(RootVisitor* visitor) {
// Visit the classes held as static in mirror classes, these can be visited concurrently and only
// need to be visited once per GC since they never change.
- mirror::ArtMethod::VisitRoots(visitor);
mirror::Class::VisitRoots(visitor);
mirror::Constructor::VisitRoots(visitor);
mirror::Reference::VisitRoots(visitor);
@@ -1329,6 +1329,24 @@ void Runtime::VisitConstantRoots(RootVisitor* visitor) {
mirror::PrimitiveArray<int32_t>::VisitRoots(visitor); // IntArray
mirror::PrimitiveArray<int64_t>::VisitRoots(visitor); // LongArray
mirror::PrimitiveArray<int16_t>::VisitRoots(visitor); // ShortArray
+ // Visiting the roots of these ArtMethods is not currently required since all the GcRoots are
+ // null.
+ BufferedRootVisitor<16> buffered_visitor(visitor, RootInfo(kRootVMInternal));
+ if (HasResolutionMethod()) {
+ resolution_method_->VisitRoots(buffered_visitor);
+ }
+ if (HasImtConflictMethod()) {
+ imt_conflict_method_->VisitRoots(buffered_visitor);
+ }
+ if (imt_unimplemented_method_ != nullptr) {
+ imt_unimplemented_method_->VisitRoots(buffered_visitor);
+ }
+ for (size_t i = 0; i < kLastCalleeSaveType; ++i) {
+ auto* m = reinterpret_cast<ArtMethod*>(callee_save_methods_[i]);
+ if (m != nullptr) {
+ m->VisitRoots(buffered_visitor);
+ }
+ }
}
void Runtime::VisitConcurrentRoots(RootVisitor* visitor, VisitRootFlags flags) {
@@ -1350,17 +1368,9 @@ void Runtime::VisitNonThreadRoots(RootVisitor* visitor) {
java_vm_->VisitRoots(visitor);
sentinel_.VisitRootIfNonNull(visitor, RootInfo(kRootVMInternal));
pre_allocated_OutOfMemoryError_.VisitRootIfNonNull(visitor, RootInfo(kRootVMInternal));
- resolution_method_.VisitRoot(visitor, RootInfo(kRootVMInternal));
pre_allocated_NoClassDefFoundError_.VisitRootIfNonNull(visitor, RootInfo(kRootVMInternal));
- imt_conflict_method_.VisitRootIfNonNull(visitor, RootInfo(kRootVMInternal));
- imt_unimplemented_method_.VisitRootIfNonNull(visitor, RootInfo(kRootVMInternal));
- default_imt_.VisitRootIfNonNull(visitor, RootInfo(kRootVMInternal));
- for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
- callee_save_methods_[i].VisitRootIfNonNull(visitor, RootInfo(kRootVMInternal));
- }
verifier::MethodVerifier::VisitStaticRoots(visitor);
VisitTransactionRoots(visitor);
- instrumentation_.VisitRoots(visitor);
}
void Runtime::VisitNonConcurrentRoots(RootVisitor* visitor) {
@@ -1399,73 +1409,43 @@ void Runtime::VisitImageRoots(RootVisitor* visitor) {
}
}
-mirror::ObjectArray<mirror::ArtMethod>* Runtime::CreateDefaultImt(ClassLinker* cl) {
- Thread* self = Thread::Current();
- StackHandleScope<1> hs(self);
- Handle<mirror::ObjectArray<mirror::ArtMethod>> imtable(
- hs.NewHandle(cl->AllocArtMethodArray(self, 64)));
- mirror::ArtMethod* imt_conflict_method = Runtime::Current()->GetImtConflictMethod();
- for (size_t i = 0; i < static_cast<size_t>(imtable->GetLength()); i++) {
- imtable->Set<false>(i, imt_conflict_method);
- }
- return imtable.Get();
-}
-
-mirror::ArtMethod* Runtime::CreateImtConflictMethod() {
- Thread* self = Thread::Current();
- Runtime* runtime = Runtime::Current();
- ClassLinker* class_linker = runtime->GetClassLinker();
- StackHandleScope<1> hs(self);
- Handle<mirror::ArtMethod> method(hs.NewHandle(class_linker->AllocArtMethod(self)));
- method->SetDeclaringClass(mirror::ArtMethod::GetJavaLangReflectArtMethod());
- // TODO: use a special method for imt conflict method saves.
- method->SetDexMethodIndex(DexFile::kDexNoIndex);
+ArtMethod* Runtime::CreateImtConflictMethod() {
+ auto* method = Runtime::Current()->GetClassLinker()->CreateRuntimeMethod();
// When compiling, the code pointer will get set later when the image is loaded.
- if (runtime->IsAotCompiler()) {
+ if (IsAotCompiler()) {
size_t pointer_size = GetInstructionSetPointerSize(instruction_set_);
method->SetEntryPointFromQuickCompiledCodePtrSize(nullptr, pointer_size);
} else {
method->SetEntryPointFromQuickCompiledCode(GetQuickImtConflictStub());
}
- return method.Get();
+ return method;
}
-void Runtime::SetImtConflictMethod(mirror::ArtMethod* method) {
- imt_conflict_method_ = GcRoot<mirror::ArtMethod>(method);
+void Runtime::SetImtConflictMethod(ArtMethod* method) {
+ CHECK(method != nullptr);
+ CHECK(method->IsRuntimeMethod());
+ imt_conflict_method_ = method;
}
-mirror::ArtMethod* Runtime::CreateResolutionMethod() {
- Thread* self = Thread::Current();
- Runtime* runtime = Runtime::Current();
- ClassLinker* class_linker = runtime->GetClassLinker();
- StackHandleScope<1> hs(self);
- Handle<mirror::ArtMethod> method(hs.NewHandle(class_linker->AllocArtMethod(self)));
- method->SetDeclaringClass(mirror::ArtMethod::GetJavaLangReflectArtMethod());
- // TODO: use a special method for resolution method saves
- method->SetDexMethodIndex(DexFile::kDexNoIndex);
+ArtMethod* Runtime::CreateResolutionMethod() {
+ auto* method = Runtime::Current()->GetClassLinker()->CreateRuntimeMethod();
// When compiling, the code pointer will get set later when the image is loaded.
- if (runtime->IsAotCompiler()) {
+ if (IsAotCompiler()) {
size_t pointer_size = GetInstructionSetPointerSize(instruction_set_);
method->SetEntryPointFromQuickCompiledCodePtrSize(nullptr, pointer_size);
} else {
method->SetEntryPointFromQuickCompiledCode(GetQuickResolutionStub());
}
- return method.Get();
+ return method;
}
-mirror::ArtMethod* Runtime::CreateCalleeSaveMethod() {
- Thread* self = Thread::Current();
- Runtime* runtime = Runtime::Current();
- ClassLinker* class_linker = runtime->GetClassLinker();
- StackHandleScope<1> hs(self);
- Handle<mirror::ArtMethod> method(hs.NewHandle(class_linker->AllocArtMethod(self)));
- method->SetDeclaringClass(mirror::ArtMethod::GetJavaLangReflectArtMethod());
- // TODO: use a special method for callee saves
- method->SetDexMethodIndex(DexFile::kDexNoIndex);
+ArtMethod* Runtime::CreateCalleeSaveMethod() {
+ auto* method = Runtime::Current()->GetClassLinker()->CreateRuntimeMethod();
size_t pointer_size = GetInstructionSetPointerSize(instruction_set_);
method->SetEntryPointFromQuickCompiledCodePtrSize(nullptr, pointer_size);
DCHECK_NE(instruction_set_, kNone);
- return method.Get();
+ DCHECK(method->IsRuntimeMethod());
+ return method;
}
void Runtime::DisallowNewSystemWeaks() {
@@ -1525,15 +1505,16 @@ void Runtime::SetInstructionSet(InstructionSet instruction_set) {
}
}
-void Runtime::SetCalleeSaveMethod(mirror::ArtMethod* method, CalleeSaveType type) {
+void Runtime::SetCalleeSaveMethod(ArtMethod* method, CalleeSaveType type) {
DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastCalleeSaveType));
- callee_save_methods_[type] = GcRoot<mirror::ArtMethod>(method);
+ CHECK(method != nullptr);
+ callee_save_methods_[type] = reinterpret_cast<uintptr_t>(method);
}
void Runtime::StartProfiler(const char* profile_output_filename) {
profile_output_filename_ = profile_output_filename;
profiler_started_ =
- BackgroundMethodSamplingProfiler::Start(profile_output_filename_, profiler_options_);
+ BackgroundMethodSamplingProfiler::Start(profile_output_filename_, profiler_options_);
}
// Transaction support.
@@ -1550,7 +1531,6 @@ void Runtime::ExitTransactionMode() {
preinitialization_transaction_ = nullptr;
}
-
bool Runtime::IsTransactionAborted() const {
if (!IsActiveTransaction()) {
return false;
@@ -1709,4 +1689,16 @@ bool Runtime::IsCompilingBootImage() const {
return IsCompiler() && compiler_callbacks_->IsBootImage();
}
+void Runtime::SetResolutionMethod(ArtMethod* method) {
+ CHECK(method != nullptr);
+ CHECK(method->IsRuntimeMethod()) << method;
+ resolution_method_ = method;
+}
+
+void Runtime::SetImtUnimplementedMethod(ArtMethod* method) {
+ CHECK(method != nullptr);
+ CHECK(method->IsRuntimeMethod());
+ imt_unimplemented_method_ = method;
+}
+
} // namespace art