1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "method_handle_impl-inl.h"
18
19 #include "art_method-alloc-inl.h"
20 #include "class-alloc-inl.h"
21 #include "class_root-inl.h"
22
23 #include "well_known_classes.h"
24
25 namespace art HIDDEN {
26 namespace mirror {
27
GetReturnTypeDescriptor(const char * invoke_method_name)28 const char* MethodHandle::GetReturnTypeDescriptor(const char* invoke_method_name) {
29 if (strcmp(invoke_method_name, "invoke") == 0 || strcmp(invoke_method_name, "invokeExact") == 0) {
30 return "Ljava/lang/Object;";
31 } else {
32 return nullptr;
33 }
34 }
35
Initialize(uintptr_t art_field_or_method,Kind kind,Handle<MethodType> method_type)36 void MethodHandle::Initialize(uintptr_t art_field_or_method,
37 Kind kind,
38 Handle<MethodType> method_type)
39 REQUIRES_SHARED(Locks::mutator_lock_) {
40 CHECK(!Runtime::Current()->IsActiveTransaction());
41 SetFieldObject<false>(CachedSpreadInvokerOffset(), nullptr);
42 SetFieldObject<false>(MethodTypeOffset(), method_type.Get());
43 SetFieldObject<false>(AsTypeCacheOffset(), nullptr);
44 SetField32<false>(HandleKindOffset(), static_cast<uint32_t>(kind));
45 SetField64<false>(ArtFieldOrMethodOffset(), art_field_or_method);
46 }
47
Create(Thread * const self,uintptr_t art_field_or_method,MethodHandle::Kind kind,Handle<MethodType> method_type)48 ObjPtr<mirror::MethodHandleImpl> MethodHandleImpl::Create(Thread* const self,
49 uintptr_t art_field_or_method,
50 MethodHandle::Kind kind,
51 Handle<MethodType> method_type)
52 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_) {
53 StackHandleScope<1> hs(self);
54 Handle<mirror::MethodHandleImpl> mh(hs.NewHandle(ObjPtr<MethodHandleImpl>::DownCast(
55 WellKnownClasses::java_lang_invoke_MethodHandleImpl_init->NewObject<'J', 'I', 'L'>(
56 self, art_field_or_method, static_cast<uint32_t>(kind), method_type))));
57
58 return mh.Get();
59 }
60
VisitTarget(ReflectiveValueVisitor * v)61 void MethodHandle::VisitTarget(ReflectiveValueVisitor* v) {
62 void* target = GetTargetField();
63 void* result;
64 HeapReflectiveSourceInfo hrsi(kSourceJavaLangInvokeMethodHandle, this);
65 if (GetHandleKind() < kFirstAccessorKind) {
66 result = v->VisitMethod(GetTargetMethod(), hrsi);
67 } else {
68 result = v->VisitField(GetTargetField(), hrsi);
69 }
70 if (result != target) {
71 SetField64<false>(ArtFieldOrMethodOffset(), reinterpret_cast<uintptr_t>(result));
72 }
73 }
74
75
76 } // namespace mirror
77 } // namespace art
78