blob: a0aae3cdb4b7fde757aff36fc9cc7b262b630b38 [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"
23#include "method_type.h"
24
25namespace art {
26
27struct MethodHandleImplOffsets;
28
29namespace mirror {
30
31// C++ mirror of java.lang.invoke.MethodHandle
32class MANAGED MethodHandle : public Object {
33 public:
34 mirror::MethodType* GetMethodType() REQUIRES_SHARED(Locks::mutator_lock_) {
35 return GetFieldObject<mirror::MethodType>(OFFSET_OF_OBJECT_MEMBER(MethodHandle, method_type_));
36 }
37
38 ArtMethod* GetTargetMethod() REQUIRES_SHARED(Locks::mutator_lock_) {
39 return reinterpret_cast<ArtMethod*>(
40 GetField64(OFFSET_OF_OBJECT_MEMBER(MethodHandle, art_field_or_method_)));
41 }
42
43 private:
44 HeapReference<mirror::Object> as_type_cache_;
45 HeapReference<mirror::MethodType> method_type_;
46 uint64_t art_field_or_method_;
47 uint32_t handle_kind_;
48
49 private:
50 static MemberOffset AsTypeCacheOffset() {
51 return MemberOffset(OFFSETOF_MEMBER(MethodHandle, as_type_cache_));
52 }
53 static MemberOffset MethodTypeOffset() {
54 return MemberOffset(OFFSETOF_MEMBER(MethodHandle, method_type_));
55 }
56 static MemberOffset ArtFieldOrMethodOffset() {
57 return MemberOffset(OFFSETOF_MEMBER(MethodHandle, art_field_or_method_));
58 }
59 static MemberOffset HandleKindOffset() {
60 return MemberOffset(OFFSETOF_MEMBER(MethodHandle, handle_kind_));
61 }
62
63 friend struct art::MethodHandleImplOffsets; // for verifying offset information
64 DISALLOW_IMPLICIT_CONSTRUCTORS(MethodHandle);
65};
66
67// C++ mirror of java.lang.invoke.MethodHandleImpl
68class MANAGED MethodHandleImpl : public MethodHandle {
69 public:
70 static mirror::Class* StaticClass() REQUIRES_SHARED(Locks::mutator_lock_) {
71 return static_class_.Read();
72 }
73
74 static void SetClass(Class* klass) REQUIRES_SHARED(Locks::mutator_lock_);
75 static void ResetClass() REQUIRES_SHARED(Locks::mutator_lock_);
76 static void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_);
77
78 private:
79 static GcRoot<mirror::Class> static_class_; // java.lang.invoke.MethodHandleImpl.class
80
81 friend struct art::MethodHandleImplOffsets; // for verifying offset information
82 DISALLOW_IMPLICIT_CONSTRUCTORS(MethodHandleImpl);
83};
84
85} // namespace mirror
86} // namespace art
87
88#endif // ART_RUNTIME_MIRROR_METHOD_HANDLE_IMPL_H_