Narayan Kamath | afa4827 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 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 | #ifndef ART_RUNTIME_MIRROR_METHOD_HANDLE_IMPL_H_ |
| 18 | #define ART_RUNTIME_MIRROR_METHOD_HANDLE_IMPL_H_ |
| 19 | |
| 20 | #include "class.h" |
| 21 | #include "gc_root.h" |
| 22 | #include "object.h" |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 23 | #include "method_handles.h" |
Narayan Kamath | afa4827 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 24 | #include "method_type.h" |
| 25 | |
| 26 | namespace art { |
| 27 | |
| 28 | struct MethodHandleImplOffsets; |
| 29 | |
| 30 | namespace mirror { |
| 31 | |
| 32 | // C++ mirror of java.lang.invoke.MethodHandle |
| 33 | class MANAGED MethodHandle : public Object { |
| 34 | public: |
| 35 | mirror::MethodType* GetMethodType() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 36 | return GetFieldObject<mirror::MethodType>(OFFSET_OF_OBJECT_MEMBER(MethodHandle, method_type_)); |
| 37 | } |
| 38 | |
Narayan Kamath | 0a8485e | 2016-11-02 18:47:11 +0000 | [diff] [blame] | 39 | mirror::MethodType* GetNominalType() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 40 | return GetFieldObject<mirror::MethodType>(OFFSET_OF_OBJECT_MEMBER(MethodHandle, nominal_type_)); |
| 41 | } |
| 42 | |
Orion Hodson | 3d617ac | 2016-10-19 14:00:46 +0100 | [diff] [blame] | 43 | ArtField* GetTargetField() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 44 | return reinterpret_cast<ArtField*>( |
| 45 | GetField64(OFFSET_OF_OBJECT_MEMBER(MethodHandle, art_field_or_method_))); |
| 46 | } |
| 47 | |
Narayan Kamath | afa4827 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 48 | ArtMethod* GetTargetMethod() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 49 | return reinterpret_cast<ArtMethod*>( |
| 50 | GetField64(OFFSET_OF_OBJECT_MEMBER(MethodHandle, art_field_or_method_))); |
| 51 | } |
| 52 | |
Narayan Kamath | 9823e78 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 53 | MethodHandleKind GetHandleKind() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 54 | const int32_t handle_kind = GetField32(OFFSET_OF_OBJECT_MEMBER(MethodHandle, handle_kind_)); |
| 55 | |
| 56 | DCHECK(handle_kind >= 0 && handle_kind <= MethodHandleKind::kLastValidKind); |
| 57 | return static_cast<MethodHandleKind>(handle_kind); |
| 58 | } |
| 59 | |
Orion Hodson | cfa325e | 2016-10-13 10:25:54 +0100 | [diff] [blame] | 60 | static mirror::Class* StaticClass() REQUIRES_SHARED(Locks::mutator_lock_); |
| 61 | |
Narayan Kamath | afa4827 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 62 | private: |
Narayan Kamath | 0a8485e | 2016-11-02 18:47:11 +0000 | [diff] [blame] | 63 | HeapReference<mirror::MethodType> nominal_type_; |
Narayan Kamath | afa4827 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 64 | HeapReference<mirror::MethodType> method_type_; |
| 65 | uint64_t art_field_or_method_; |
| 66 | uint32_t handle_kind_; |
| 67 | |
| 68 | private: |
Narayan Kamath | 0a8485e | 2016-11-02 18:47:11 +0000 | [diff] [blame] | 69 | static MemberOffset NominalTypeOffset() { |
| 70 | return MemberOffset(OFFSETOF_MEMBER(MethodHandle, nominal_type_)); |
Narayan Kamath | afa4827 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 71 | } |
| 72 | static MemberOffset MethodTypeOffset() { |
| 73 | return MemberOffset(OFFSETOF_MEMBER(MethodHandle, method_type_)); |
| 74 | } |
| 75 | static MemberOffset ArtFieldOrMethodOffset() { |
| 76 | return MemberOffset(OFFSETOF_MEMBER(MethodHandle, art_field_or_method_)); |
| 77 | } |
| 78 | static MemberOffset HandleKindOffset() { |
| 79 | return MemberOffset(OFFSETOF_MEMBER(MethodHandle, handle_kind_)); |
| 80 | } |
| 81 | |
| 82 | friend struct art::MethodHandleImplOffsets; // for verifying offset information |
| 83 | DISALLOW_IMPLICIT_CONSTRUCTORS(MethodHandle); |
| 84 | }; |
| 85 | |
| 86 | // C++ mirror of java.lang.invoke.MethodHandleImpl |
| 87 | class MANAGED MethodHandleImpl : public MethodHandle { |
| 88 | public: |
| 89 | static mirror::Class* StaticClass() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 90 | return static_class_.Read(); |
| 91 | } |
| 92 | |
| 93 | static void SetClass(Class* klass) REQUIRES_SHARED(Locks::mutator_lock_); |
| 94 | static void ResetClass() REQUIRES_SHARED(Locks::mutator_lock_); |
| 95 | static void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_); |
| 96 | |
| 97 | private: |
| 98 | static GcRoot<mirror::Class> static_class_; // java.lang.invoke.MethodHandleImpl.class |
| 99 | |
| 100 | friend struct art::MethodHandleImplOffsets; // for verifying offset information |
| 101 | DISALLOW_IMPLICIT_CONSTRUCTORS(MethodHandleImpl); |
| 102 | }; |
| 103 | |
| 104 | } // namespace mirror |
| 105 | } // namespace art |
| 106 | |
| 107 | #endif // ART_RUNTIME_MIRROR_METHOD_HANDLE_IMPL_H_ |