diff options
author | 2024-09-25 16:20:11 +0100 | |
---|---|---|
committer | 2024-10-22 11:44:32 +0000 | |
commit | 72f6bb93a33b224bd85320bbcd231f5bbf8bff5a (patch) | |
tree | 0c97cb79b36fe41b07188b43e584cb1ada6cc8b2 | |
parent | 88f65e236865ccade279316f710c51784e56c452 (diff) |
Implement Executable::GetParameterTypesInternal in UnstartedRuntime.
Needed to build mapping from String constructors to StringFactory
methods at MethodHandles initialization time.
Bug: 297147201
Test: ./art/test/testrunner/testrunner.py --host --64 -b
Change-Id: I8bb312d34745b3b9b73e3be3213ceb4e2c2c5fb2
-rw-r--r-- | runtime/interpreter/unstarted_runtime.cc | 41 | ||||
-rw-r--r-- | runtime/interpreter/unstarted_runtime_list.h | 1 | ||||
-rw-r--r-- | runtime/method_handles.cc | 9 |
3 files changed, 45 insertions, 6 deletions
diff --git a/runtime/interpreter/unstarted_runtime.cc b/runtime/interpreter/unstarted_runtime.cc index 0478efe0e5..db4ff095ef 100644 --- a/runtime/interpreter/unstarted_runtime.cc +++ b/runtime/interpreter/unstarted_runtime.cc @@ -755,6 +755,47 @@ void UnstartedRuntime::UnstartedConstructorNewInstance0( } } +void UnstartedRuntime::UnstartedJNIExecutableGetParameterTypesInternal( + Thread* self, ArtMethod*, mirror::Object* receiver, uint32_t*, JValue* result) { + StackHandleScope<3> hs(self); + ScopedObjectAccessUnchecked soa(self); + Handle<mirror::Executable> executable(hs.NewHandle( + reinterpret_cast<mirror::Executable*>(receiver))); + if (executable == nullptr) { + AbortTransactionOrFail(self, "Receiver can't be null in GetParameterTypesInternal"); + } + + ArtMethod* method = executable->GetArtMethod(); + const dex::TypeList* params = method->GetParameterTypeList(); + if (params == nullptr) { + result->SetL(nullptr); + return; + } + + const uint32_t num_params = params->Size(); + + ObjPtr<mirror::Class> class_array_class = GetClassRoot<mirror::ObjectArray<mirror::Class>>(); + Handle<mirror::ObjectArray<mirror::Class>> ptypes = hs.NewHandle( + mirror::ObjectArray<mirror::Class>::Alloc(soa.Self(), class_array_class, num_params)); + if (ptypes.IsNull()) { + AbortTransactionOrFail(self, "Could not allocate array of mirror::Class"); + return; + } + + MutableHandle<mirror::Class> param(hs.NewHandle<mirror::Class>(nullptr)); + for (uint32_t i = 0; i < num_params; ++i) { + const dex::TypeIndex type_idx = params->GetTypeItem(i).type_idx_; + param.Assign(Runtime::Current()->GetClassLinker()->ResolveType(type_idx, method)); + if (param.Get() == nullptr) { + AbortTransactionOrFail(self, "Could not resolve type"); + return; + } + ptypes->SetWithoutChecks<false>(i, param.Get()); + } + + result->SetL(ptypes.Get()); +} + void UnstartedRuntime::UnstartedVmClassLoaderFindLoadedClass( Thread* self, ShadowFrame* shadow_frame, JValue* result, size_t arg_offset) { ObjPtr<mirror::String> class_name = shadow_frame->GetVRegReference(arg_offset + 1)->AsString(); diff --git a/runtime/interpreter/unstarted_runtime_list.h b/runtime/interpreter/unstarted_runtime_list.h index 429fa93485..55e30e9007 100644 --- a/runtime/interpreter/unstarted_runtime_list.h +++ b/runtime/interpreter/unstarted_runtime_list.h @@ -102,6 +102,7 @@ V(AtomicLongVMSupportsCS8, "Ljava/util/concurrent/atomic/AtomicLong;", "VMSupportsCS8", "()Z") \ V(ClassGetNameNative, "Ljava/lang/Class;", "getNameNative", "()Ljava/lang/String;") \ V(DoubleLongBitsToDouble, "Ljava/lang/Double;", "longBitsToDouble", "(J)D") \ + V(ExecutableGetParameterTypesInternal, "Ljava/lang/reflect/Executable;", "getParameterTypesInternal", "()[Ljava/lang/Class;") \ V(FloatFloatToRawIntBits, "Ljava/lang/Float;", "floatToRawIntBits", "(F)I") \ V(FloatIntBitsToFloat, "Ljava/lang/Float;", "intBitsToFloat", "(I)F") \ V(ObjectInternalClone, "Ljava/lang/Object;", "internalClone", "()Ljava/lang/Object;") \ diff --git a/runtime/method_handles.cc b/runtime/method_handles.cc index c4e4d206a4..a91348ae63 100644 --- a/runtime/method_handles.cc +++ b/runtime/method_handles.cc @@ -463,12 +463,9 @@ ArtMethod* RefineTargetMethod(Thread* self, target_method, kRuntimePointerSize); } } else if (handle_kind == mirror::MethodHandle::Kind::kInvokeDirect) { - // String constructors are a special case, they are replaced with - // StringFactory methods. - if (target_method->IsStringConstructor()) { - DCHECK(handle_type->GetRType()->IsStringClass()); - return WellKnownClasses::StringInitToStringFactory(target_method); - } + // String constructors are replaced with static StringFactory methods when a MethodHandle + // object is created. + DCHECK(!target_method->IsStringConstructor()); } else if (handle_kind == mirror::MethodHandle::Kind::kInvokeSuper) { // Note that we're not dynamically dispatching on the type of the receiver // here. We use the static type of the "receiver" object that we've |