From 1a102189c1782e003f27e95ce093e854408767f3 Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Tue, 2 Dec 2014 17:49:19 -0800 Subject: Remove MethodHelper. Move use as a shorty processor to only use in portable. Move GetNumberOfReferenceArgsWithoutReceiver to mirror::ArtMethod. Change-Id: I7ded3d05315c84bce4ab19cb330ef74289da4bb3 --- .../portable/portable_trampoline_entrypoints.cc | 70 +++++++++++-- runtime/method_helper.h | 111 --------------------- runtime/mirror/art_method.cc | 19 +++- runtime/reflection.h | 1 - 4 files changed, 77 insertions(+), 124 deletions(-) delete mode 100644 runtime/method_helper.h diff --git a/runtime/entrypoints/portable/portable_trampoline_entrypoints.cc b/runtime/entrypoints/portable/portable_trampoline_entrypoints.cc index 0a56956..2a2771f 100644 --- a/runtime/entrypoints/portable/portable_trampoline_entrypoints.cc +++ b/runtime/entrypoints/portable/portable_trampoline_entrypoints.cc @@ -21,13 +21,62 @@ #include "entrypoints/entrypoint_utils-inl.h" #include "entrypoints/runtime_asm_entrypoints.h" #include "interpreter/interpreter.h" -#include "method_helper.h" #include "mirror/art_method-inl.h" #include "mirror/object-inl.h" #include "scoped_thread_state_change.h" namespace art { +class ShortyHelper { + public: + ShortyHelper(const char* shorty, uint32_t shorty_len, bool is_static) + : shorty_(shorty), shorty_len_(shorty_len), is_static_(is_static) { + } + + const char* GetShorty() const { + return shorty_; + } + + uint32_t GetShortyLength() const { + return shorty_len_; + } + + size_t NumArgs() const { + // "1 +" because the first in Args is the receiver. + // "- 1" because we don't count the return type. + return (is_static_ ? 0 : 1) + GetShortyLength() - 1; + } + + // Get the primitive type associated with the given parameter. + Primitive::Type GetParamPrimitiveType(size_t param) const { + CHECK_LT(param, NumArgs()); + if (is_static_) { + param++; // 0th argument must skip return value at start of the shorty. + } else if (param == 0) { + return Primitive::kPrimNot; + } + return Primitive::GetType(shorty_[param]); + } + + // Is the specified parameter a long or double, where parameter 0 is 'this' for instance methods. + bool IsParamALongOrDouble(size_t param) const { + Primitive::Type type = GetParamPrimitiveType(param); + return type == Primitive::kPrimLong || type == Primitive::kPrimDouble; + } + + // Is the specified parameter a reference, where parameter 0 is 'this' for instance methods. + bool IsParamAReference(size_t param) const { + return GetParamPrimitiveType(param) == Primitive::kPrimNot; + } + + private: + const char* const shorty_; + const uint32_t shorty_len_; + const bool is_static_; + + DISALLOW_COPY_AND_ASSIGN(ShortyHelper); +}; + // Visits the arguments as saved to the stack by a Runtime::kRefAndArgs callee save frame. class PortableArgumentVisitor { public: @@ -61,7 +110,7 @@ class PortableArgumentVisitor { #define PORTABLE_STACK_ARG_SKIP 0 #endif - PortableArgumentVisitor(MethodHelper& caller_mh, mirror::ArtMethod** sp) + PortableArgumentVisitor(ShortyHelper& caller_mh, mirror::ArtMethod** sp) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) : caller_mh_(caller_mh), args_in_regs_(ComputeArgsInRegs(caller_mh)), @@ -120,7 +169,7 @@ class PortableArgumentVisitor { } private: - static size_t ComputeArgsInRegs(MethodHelper& mh) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { + static size_t ComputeArgsInRegs(ShortyHelper& mh) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { #if (defined(__i386__)) UNUSED(mh); return 0; @@ -137,7 +186,7 @@ class PortableArgumentVisitor { return args_in_regs; #endif } - MethodHelper& caller_mh_; + ShortyHelper& caller_mh_; const size_t args_in_regs_; const size_t num_params_; uint8_t* const reg_args_; @@ -150,7 +199,7 @@ class PortableArgumentVisitor { // Visits arguments on the stack placing them into the shadow frame. class BuildPortableShadowFrameVisitor : public PortableArgumentVisitor { public: - BuildPortableShadowFrameVisitor(MethodHelper& caller_mh, mirror::ArtMethod** sp, + BuildPortableShadowFrameVisitor(ShortyHelper& caller_mh, mirror::ArtMethod** sp, ShadowFrame& sf, size_t first_arg_reg) : PortableArgumentVisitor(caller_mh, sp), sf_(sf), cur_reg_(first_arg_reg) { } virtual void Visit() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { @@ -199,7 +248,9 @@ extern "C" uint64_t artPortableToInterpreterBridge(mirror::ArtMethod* method, Th } else { const char* old_cause = self->StartAssertNoThreadSuspension("Building interpreter shadow frame"); StackHandleScope<2> hs(self); - MethodHelper mh(hs.NewHandle(method)); + uint32_t shorty_len; + const char* shorty = method->GetShorty(&shorty_len); + ShortyHelper mh(shorty, shorty_len, method->IsStatic()); const DexFile::CodeItem* code_item = method->GetCodeItem(); uint16_t num_regs = code_item->registers_size_; void* memory = alloca(ShadowFrame::ComputeSize(num_regs)); @@ -236,7 +287,7 @@ extern "C" uint64_t artPortableToInterpreterBridge(mirror::ArtMethod* method, Th // to jobjects. class BuildPortableArgumentVisitor : public PortableArgumentVisitor { public: - BuildPortableArgumentVisitor(MethodHelper& caller_mh, mirror::ArtMethod** sp, + BuildPortableArgumentVisitor(ShortyHelper& caller_mh, mirror::ArtMethod** sp, ScopedObjectAccessUnchecked& soa, std::vector& args) : PortableArgumentVisitor(caller_mh, sp), soa_(soa), args_(args) {} @@ -295,8 +346,9 @@ extern "C" uint64_t artPortableProxyInvokeHandler(mirror::ArtMethod* proxy_metho jobject rcvr_jobj = soa.AddLocalReference(receiver); // Placing arguments into args vector and remove the receiver. - StackHandleScope<1> hs(self); - MethodHelper proxy_mh(hs.NewHandle(proxy_method)); + uint32_t shorty_len; + const char* shorty = proxy_method->GetShorty(&shorty_len); + ShortyHelper proxy_mh(shorty, shorty_len, false); std::vector args; BuildPortableArgumentVisitor local_ref_visitor(proxy_mh, sp, soa, args); local_ref_visitor.VisitArguments(); diff --git a/runtime/method_helper.h b/runtime/method_helper.h deleted file mode 100644 index d21bf5c..0000000 --- a/runtime/method_helper.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ART_RUNTIME_METHOD_HELPER_H_ -#define ART_RUNTIME_METHOD_HELPER_H_ - -#include "base/macros.h" -#include "handle.h" -#include "mirror/art_method.h" -#include "primitive.h" - -namespace art { - -class MethodHelper { - public: - explicit MethodHelper(Handle m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) - : method_(m), shorty_(nullptr), shorty_len_(0) { - } - - mirror::ArtMethod* GetMethod() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - return method_->GetInterfaceMethodIfProxy(); - } - - // GetMethod() != Get() for proxy methods. - mirror::ArtMethod* Get() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - return method_.Get(); - } - - const char* GetShorty() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - const char* result = shorty_; - if (result == nullptr) { - result = method_->GetShorty(&shorty_len_); - shorty_ = result; - } - return result; - } - - uint32_t GetShortyLength() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - if (shorty_ == nullptr) { - GetShorty(); - } - return shorty_len_; - } - - // Counts the number of references in the parameter list of the corresponding method. - // Note: Thus does _not_ include "this" for non-static methods. - uint32_t GetNumberOfReferenceArgsWithoutReceiver() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - const char* shorty = GetShorty(); - uint32_t refs = 0; - for (uint32_t i = 1; i < shorty_len_ ; ++i) { - if (shorty[i] == 'L') { - refs++; - } - } - - return refs; - } - - size_t NumArgs() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - // "1 +" because the first in Args is the receiver. - // "- 1" because we don't count the return type. - return (method_->IsStatic() ? 0 : 1) + GetShortyLength() - 1; - } - - // Get the primitive type associated with the given parameter. - Primitive::Type GetParamPrimitiveType(size_t param) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - CHECK_LT(param, NumArgs()); - if (GetMethod()->IsStatic()) { - param++; // 0th argument must skip return value at start of the shorty - } else if (param == 0) { - return Primitive::kPrimNot; - } - return Primitive::GetType(GetShorty()[param]); - } - - // Is the specified parameter a long or double, where parameter 0 is 'this' for instance methods. - bool IsParamALongOrDouble(size_t param) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - Primitive::Type type = GetParamPrimitiveType(param); - return type == Primitive::kPrimLong || type == Primitive::kPrimDouble; - } - - // Is the specified parameter a reference, where parameter 0 is 'this' for instance methods. - bool IsParamAReference(size_t param) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - return GetParamPrimitiveType(param) == Primitive::kPrimNot; - } - - private: - Handle method_; - - const char* shorty_; - uint32_t shorty_len_; - - DISALLOW_COPY_AND_ASSIGN(MethodHelper); -}; - -} // namespace art - -#endif // ART_RUNTIME_METHOD_HELPER_H_ diff --git a/runtime/mirror/art_method.cc b/runtime/mirror/art_method.cc index 6350bd9..1729686 100644 --- a/runtime/mirror/art_method.cc +++ b/runtime/mirror/art_method.cc @@ -29,7 +29,6 @@ #include "interpreter/interpreter.h" #include "jni_internal.h" #include "mapping_table.h" -#include "method_helper.h" #include "object_array-inl.h" #include "object_array.h" #include "object-inl.h" @@ -469,6 +468,21 @@ void ArtMethod::Invoke(Thread* self, uint32_t* args, uint32_t args_size, JValue* self->PopManagedStackFragment(fragment); } +// Counts the number of references in the parameter list of the corresponding method. +// Note: Thus does _not_ include "this" for non-static methods. +static uint32_t GetNumberOfReferenceArgsWithoutReceiver(ArtMethod* method) + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { + uint32_t shorty_len; + const char* shorty = method->GetShorty(&shorty_len); + uint32_t refs = 0; + for (uint32_t i = 1; i < shorty_len ; ++i) { + if (shorty[i] == 'L') { + refs++; + } + } + return refs; +} + QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo() { if (UNLIKELY(IsPortableCompiled())) { // Portable compiled dex bytecode or jni stub. @@ -511,8 +525,7 @@ QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo() { // Generic JNI frame. DCHECK(IsNative()); StackHandleScope<1> hs(Thread::Current()); - uint32_t handle_refs = - MethodHelper(hs.NewHandle(this)).GetNumberOfReferenceArgsWithoutReceiver() + 1; + uint32_t handle_refs = GetNumberOfReferenceArgsWithoutReceiver(this) + 1; size_t scope_size = HandleScope::SizeOf(handle_refs); QuickMethodFrameInfo callee_info = runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs); diff --git a/runtime/reflection.h b/runtime/reflection.h index 1764774..1a64871 100644 --- a/runtime/reflection.h +++ b/runtime/reflection.h @@ -29,7 +29,6 @@ namespace mirror { class Object; } // namespace mirror union JValue; -class MethodHelper; class ScopedObjectAccessAlreadyRunnable; class ShadowFrame; class ThrowLocation; -- cgit v1.1