diff options
| author | 2015-04-22 13:56:20 -0700 | |
|---|---|---|
| committer | 2015-06-02 09:21:27 -0700 | |
| commit | 3d21bdf8894e780d349c481e5c9e29fe1556051c (patch) | |
| tree | 61a5231f36c0dabd73457fec81df103462a05aff /runtime/native/java_lang_Class.cc | |
| parent | 71f0a8a123fa27bdc857a98afebbaf0ed09dac15 (diff) | |
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/native/java_lang_Class.cc')
| -rw-r--r-- | runtime/native/java_lang_Class.cc | 175 |
1 files changed, 73 insertions, 102 deletions
diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc index 795a0eadca..94024ef4b2 100644 --- a/runtime/native/java_lang_Class.cc +++ b/runtime/native/java_lang_Class.cc @@ -273,7 +273,7 @@ static jobject Class_getDeclaredConstructorInternal( return nullptr; } -static ALWAYS_INLINE inline bool MethodMatchesConstructor(mirror::ArtMethod* m, bool public_only) +static ALWAYS_INLINE inline bool MethodMatchesConstructor(ArtMethod* m, bool public_only) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { DCHECK(m != nullptr); return (!public_only || m->IsPublic()) && !m->IsStatic() && m->IsConstructor(); @@ -283,14 +283,11 @@ static jobjectArray Class_getDeclaredConstructorsInternal( JNIEnv* env, jobject javaThis, jboolean publicOnly) { ScopedFastNativeObjectAccess soa(env); auto* klass = DecodeClass(soa, javaThis); - StackHandleScope<2> hs(soa.Self()); - auto h_direct_methods = hs.NewHandle(klass->GetDirectMethods()); + StackHandleScope<1> hs(soa.Self()); size_t constructor_count = 0; - auto count = h_direct_methods.Get() != nullptr ? h_direct_methods->GetLength() : 0u; // Two pass approach for speed. - for (size_t i = 0; i < count; ++i) { - constructor_count += MethodMatchesConstructor(h_direct_methods->GetWithoutChecks(i), - publicOnly != JNI_FALSE) ? 1u : 0u; + for (auto& m : klass->GetDirectMethods(sizeof(void*))) { + constructor_count += MethodMatchesConstructor(&m, publicOnly != JNI_FALSE) ? 1u : 0u; } auto h_constructors = hs.NewHandle(mirror::ObjectArray<mirror::Constructor>::Alloc( soa.Self(), mirror::Constructor::ArrayClass(), constructor_count)); @@ -299,12 +296,11 @@ static jobjectArray Class_getDeclaredConstructorsInternal( return nullptr; } constructor_count = 0; - for (size_t i = 0; i < count; ++i) { - auto* method = h_direct_methods->GetWithoutChecks(i); - if (MethodMatchesConstructor(method, publicOnly != JNI_FALSE)) { - auto* constructor = mirror::Constructor::CreateFromArtMethod(soa.Self(), method); + for (auto& m : klass->GetDirectMethods(sizeof(void*))) { + if (MethodMatchesConstructor(&m, publicOnly != JNI_FALSE)) { + auto* constructor = mirror::Constructor::CreateFromArtMethod(soa.Self(), &m); if (UNLIKELY(constructor == nullptr)) { - soa.Self()->AssertPendingException(); + soa.Self()->AssertPendingOOMException(); return nullptr; } h_constructors->SetWithoutChecks<false>(constructor_count++, constructor); @@ -323,7 +319,7 @@ static jobject Class_getDeclaredMethodInternal(JNIEnv* env, jobject javaThis, // were synthesized by the runtime. constexpr uint32_t kSkipModifiers = kAccMiranda | kAccSynthetic; ScopedFastNativeObjectAccess soa(env); - StackHandleScope<5> hs(soa.Self()); + StackHandleScope<4> hs(soa.Self()); auto h_method_name = hs.NewHandle(soa.Decode<mirror::String*>(name)); if (UNLIKELY(h_method_name.Get() == nullptr)) { ThrowNullPointerException("name == null"); @@ -331,60 +327,49 @@ static jobject Class_getDeclaredMethodInternal(JNIEnv* env, jobject javaThis, } auto h_args = hs.NewHandle(soa.Decode<mirror::ObjectArray<mirror::Class>*>(args)); auto* klass = DecodeClass(soa, javaThis); - mirror::ArtMethod* result = nullptr; - auto* virtual_methods = klass->GetVirtualMethods(); - if (virtual_methods != nullptr) { - auto h_virtual_methods = hs.NewHandle(virtual_methods); - for (size_t i = 0, count = virtual_methods->GetLength(); i < count; ++i) { - auto* m = h_virtual_methods->GetWithoutChecks(i); - auto* np_method = m->GetInterfaceMethodIfProxy(); + ArtMethod* result = nullptr; + for (auto& m : klass->GetVirtualMethods(sizeof(void*))) { + auto* np_method = m.GetInterfaceMethodIfProxy(sizeof(void*)); + // May cause thread suspension. + mirror::String* np_name = np_method->GetNameAsString(soa.Self()); + if (!np_name->Equals(h_method_name.Get()) || !np_method->EqualParameters(h_args)) { + if (UNLIKELY(soa.Self()->IsExceptionPending())) { + return nullptr; + } + continue; + } + auto modifiers = m.GetAccessFlags(); + if ((modifiers & kSkipModifiers) == 0) { + return soa.AddLocalReference<jobject>(mirror::Method::CreateFromArtMethod(soa.Self(), &m)); + } + if ((modifiers & kAccMiranda) == 0) { + result = &m; // Remember as potential result if it's not a miranda method. + } + } + if (result == nullptr) { + for (auto& m : klass->GetDirectMethods(sizeof(void*))) { + auto modifiers = m.GetAccessFlags(); + if ((modifiers & kAccConstructor) != 0) { + continue; + } + auto* np_method = m.GetInterfaceMethodIfProxy(sizeof(void*)); // May cause thread suspension. mirror::String* np_name = np_method->GetNameAsString(soa.Self()); + if (np_name == nullptr) { + soa.Self()->AssertPendingException(); + return nullptr; + } if (!np_name->Equals(h_method_name.Get()) || !np_method->EqualParameters(h_args)) { if (UNLIKELY(soa.Self()->IsExceptionPending())) { return nullptr; } continue; } - auto modifiers = m->GetAccessFlags(); if ((modifiers & kSkipModifiers) == 0) { - return soa.AddLocalReference<jobject>(mirror::Method::CreateFromArtMethod(soa.Self(), m)); - } - if ((modifiers & kAccMiranda) == 0) { - result = m; // Remember as potential result if it's not a miranda method. - } - } - } - if (result == nullptr) { - auto* direct_methods = klass->GetDirectMethods(); - if (direct_methods != nullptr) { - auto h_direct_methods = hs.NewHandle(direct_methods); - for (size_t i = 0, count = direct_methods->GetLength(); i < count; ++i) { - auto* m = h_direct_methods->GetWithoutChecks(i); - auto modifiers = m->GetAccessFlags(); - if ((modifiers & kAccConstructor) != 0) { - continue; - } - auto* np_method = m->GetInterfaceMethodIfProxy(); - // May cause thread suspension. - mirror::String* np_name = np_method ->GetNameAsString(soa.Self()); - if (np_name == nullptr) { - soa.Self()->AssertPendingException(); - return nullptr; - } - if (!np_name->Equals(h_method_name.Get()) || !np_method->EqualParameters(h_args)) { - if (UNLIKELY(soa.Self()->IsExceptionPending())) { - return nullptr; - } - continue; - } - if ((modifiers & kSkipModifiers) == 0) { - return soa.AddLocalReference<jobject>(mirror::Method::CreateFromArtMethod( - soa.Self(), m)); - } - // Direct methods cannot be miranda methods, so this potential result must be synthetic. - result = m; + return soa.AddLocalReference<jobject>(mirror::Method::CreateFromArtMethod(soa.Self(), &m)); } + // Direct methods cannot be miranda methods, so this potential result must be synthetic. + result = &m; } } return result != nullptr ? @@ -395,64 +380,50 @@ static jobject Class_getDeclaredMethodInternal(JNIEnv* env, jobject javaThis, static jobjectArray Class_getDeclaredMethodsUnchecked(JNIEnv* env, jobject javaThis, jboolean publicOnly) { ScopedFastNativeObjectAccess soa(env); - StackHandleScope<5> hs(soa.Self()); + StackHandleScope<3> hs(soa.Self()); auto* klass = DecodeClass(soa, javaThis); - auto virtual_methods = hs.NewHandle(klass->GetVirtualMethods()); - auto direct_methods = hs.NewHandle(klass->GetDirectMethods()); size_t num_methods = 0; - if (virtual_methods.Get() != nullptr) { - for (size_t i = 0, count = virtual_methods->GetLength(); i < count; ++i) { - auto* m = virtual_methods->GetWithoutChecks(i); - auto modifiers = m->GetAccessFlags(); - if ((publicOnly == JNI_FALSE || (modifiers & kAccPublic) != 0) && - (modifiers & kAccMiranda) == 0) { - ++num_methods; - } + for (auto& m : klass->GetVirtualMethods(sizeof(void*))) { + auto modifiers = m.GetAccessFlags(); + if ((publicOnly == JNI_FALSE || (modifiers & kAccPublic) != 0) && + (modifiers & kAccMiranda) == 0) { + ++num_methods; } } - if (direct_methods.Get() != nullptr) { - for (size_t i = 0, count = direct_methods->GetLength(); i < count; ++i) { - auto* m = direct_methods->GetWithoutChecks(i); - auto modifiers = m->GetAccessFlags(); - // Add non-constructor direct/static methods. - if ((publicOnly == JNI_FALSE || (modifiers & kAccPublic) != 0) && - (modifiers & kAccConstructor) == 0) { - ++num_methods; - } + for (auto& m : klass->GetDirectMethods(sizeof(void*))) { + auto modifiers = m.GetAccessFlags(); + // Add non-constructor direct/static methods. + if ((publicOnly == JNI_FALSE || (modifiers & kAccPublic) != 0) && + (modifiers & kAccConstructor) == 0) { + ++num_methods; } } auto ret = hs.NewHandle(mirror::ObjectArray<mirror::Method>::Alloc( soa.Self(), mirror::Method::ArrayClass(), num_methods)); num_methods = 0; - if (virtual_methods.Get() != nullptr) { - for (size_t i = 0, count = virtual_methods->GetLength(); i < count; ++i) { - auto* m = virtual_methods->GetWithoutChecks(i); - auto modifiers = m->GetAccessFlags(); - if ((publicOnly == JNI_FALSE || (modifiers & kAccPublic) != 0) && - (modifiers & kAccMiranda) == 0) { - auto* method = mirror::Method::CreateFromArtMethod(soa.Self(), m); - if (method == nullptr) { - soa.Self()->AssertPendingException(); - return nullptr; - } - ret->SetWithoutChecks<false>(num_methods++, method); + for (auto& m : klass->GetVirtualMethods(sizeof(void*))) { + auto modifiers = m.GetAccessFlags(); + if ((publicOnly == JNI_FALSE || (modifiers & kAccPublic) != 0) && + (modifiers & kAccMiranda) == 0) { + auto* method = mirror::Method::CreateFromArtMethod(soa.Self(), &m); + if (method == nullptr) { + soa.Self()->AssertPendingException(); + return nullptr; } + ret->SetWithoutChecks<false>(num_methods++, method); } } - if (direct_methods.Get() != nullptr) { - for (size_t i = 0, count = direct_methods->GetLength(); i < count; ++i) { - auto* m = direct_methods->GetWithoutChecks(i); - auto modifiers = m->GetAccessFlags(); - // Add non-constructor direct/static methods. - if ((publicOnly == JNI_FALSE || (modifiers & kAccPublic) != 0) && - (modifiers & kAccConstructor) == 0) { - auto* method = mirror::Method::CreateFromArtMethod(soa.Self(), m); - if (method == nullptr) { - soa.Self()->AssertPendingException(); - return nullptr; - } - ret->SetWithoutChecks<false>(num_methods++, method); + for (auto& m : klass->GetDirectMethods(sizeof(void*))) { + auto modifiers = m.GetAccessFlags(); + // Add non-constructor direct/static methods. + if ((publicOnly == JNI_FALSE || (modifiers & kAccPublic) != 0) && + (modifiers & kAccConstructor) == 0) { + auto* method = mirror::Method::CreateFromArtMethod(soa.Self(), &m); + if (method == nullptr) { + soa.Self()->AssertPendingException(); + return nullptr; } + ret->SetWithoutChecks<false>(num_methods++, method); } } return soa.AddLocalReference<jobjectArray>(ret.Get()); |