blob: 7bf9c5b24c87c61660033f0bb032a22db926d06f [file] [log] [blame]
Narayan Kamathafa48272016-08-03 12:46:58 +01001/*
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 Kamath9823e782016-08-03 12:46:58 +010023#include "method_handles.h"
Narayan Kamathafa48272016-08-03 12:46:58 +010024#include "method_type.h"
25
26namespace art {
27
28struct MethodHandleImplOffsets;
29
30namespace mirror {
31
32// C++ mirror of java.lang.invoke.MethodHandle
33class 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
Orion Hodson3d617ac2016-10-19 14:00:46 +010039 ArtField* GetTargetField() REQUIRES_SHARED(Locks::mutator_lock_) {
40 return reinterpret_cast<ArtField*>(
41 GetField64(OFFSET_OF_OBJECT_MEMBER(MethodHandle, art_field_or_method_)));
42 }
43
Narayan Kamathafa48272016-08-03 12:46:58 +010044 ArtMethod* GetTargetMethod() REQUIRES_SHARED(Locks::mutator_lock_) {
45 return reinterpret_cast<ArtMethod*>(
46 GetField64(OFFSET_OF_OBJECT_MEMBER(MethodHandle, art_field_or_method_)));
47 }
48
Narayan Kamath9823e782016-08-03 12:46:58 +010049 MethodHandleKind GetHandleKind() REQUIRES_SHARED(Locks::mutator_lock_) {
50 const int32_t handle_kind = GetField32(OFFSET_OF_OBJECT_MEMBER(MethodHandle, handle_kind_));
51
52 DCHECK(handle_kind >= 0 && handle_kind <= MethodHandleKind::kLastValidKind);
53 return static_cast<MethodHandleKind>(handle_kind);
54 }
55
Narayan Kamathafa48272016-08-03 12:46:58 +010056 private:
57 HeapReference<mirror::Object> as_type_cache_;
58 HeapReference<mirror::MethodType> method_type_;
59 uint64_t art_field_or_method_;
60 uint32_t handle_kind_;
61
62 private:
63 static MemberOffset AsTypeCacheOffset() {
64 return MemberOffset(OFFSETOF_MEMBER(MethodHandle, as_type_cache_));
65 }
66 static MemberOffset MethodTypeOffset() {
67 return MemberOffset(OFFSETOF_MEMBER(MethodHandle, method_type_));
68 }
69 static MemberOffset ArtFieldOrMethodOffset() {
70 return MemberOffset(OFFSETOF_MEMBER(MethodHandle, art_field_or_method_));
71 }
72 static MemberOffset HandleKindOffset() {
73 return MemberOffset(OFFSETOF_MEMBER(MethodHandle, handle_kind_));
74 }
75
76 friend struct art::MethodHandleImplOffsets; // for verifying offset information
77 DISALLOW_IMPLICIT_CONSTRUCTORS(MethodHandle);
78};
79
80// C++ mirror of java.lang.invoke.MethodHandleImpl
81class MANAGED MethodHandleImpl : public MethodHandle {
82 public:
83 static mirror::Class* StaticClass() REQUIRES_SHARED(Locks::mutator_lock_) {
84 return static_class_.Read();
85 }
86
87 static void SetClass(Class* klass) REQUIRES_SHARED(Locks::mutator_lock_);
88 static void ResetClass() REQUIRES_SHARED(Locks::mutator_lock_);
89 static void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_);
90
91 private:
92 static GcRoot<mirror::Class> static_class_; // java.lang.invoke.MethodHandleImpl.class
93
94 friend struct art::MethodHandleImplOffsets; // for verifying offset information
95 DISALLOW_IMPLICIT_CONSTRUCTORS(MethodHandleImpl);
96};
97
98} // namespace mirror
99} // namespace art
100
101#endif // ART_RUNTIME_MIRROR_METHOD_HANDLE_IMPL_H_