• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
Create(Thread * const self,Handle<Field> field,MethodHandle::Kind kind,Handle<MethodType> method_type)61 ObjPtr<mirror::MethodHandleImpl> MethodHandleImpl::Create(Thread* const self,
62                                                           Handle<Field> field,
63                                                           MethodHandle::Kind kind,
64                                                           Handle<MethodType> method_type)
65     REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_) {
66   StackHandleScope<1> hs(self);
67   Handle<mirror::MethodHandleImpl> mh(hs.NewHandle(ObjPtr<MethodHandleImpl>::DownCast(
68       WellKnownClasses::java_lang_invoke_MethodHandleImpl_fieldInit->NewObject<'L', 'I', 'L'>(
69           self, field, static_cast<uint32_t>(kind), method_type))));
70 
71   return mh.Get();
72 }
73 
VisitTarget(ReflectiveValueVisitor * v)74 void MethodHandle::VisitTarget(ReflectiveValueVisitor* v) {
75   void* target = GetTargetField();
76   void* result;
77   HeapReflectiveSourceInfo hrsi(kSourceJavaLangInvokeMethodHandle, this);
78   if (GetHandleKind() < kFirstAccessorKind) {
79     result = v->VisitMethod(GetTargetMethod(), hrsi);
80   } else {
81     result = v->VisitField(GetTargetField(), hrsi);
82   }
83   if (result != target) {
84     SetField64<false>(ArtFieldOrMethodOffset(), reinterpret_cast<uintptr_t>(result));
85   }
86 }
87 
88 
89 }  // namespace mirror
90 }  // namespace art
91