blob: dd8d45e66f9ca1d09d8e63f269e5840c875441c0 [file] [log] [blame]
Orion Hodsonc069a302017-01-18 09:23:12 +00001/*
2 * Copyright (C) 2017 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_HANDLES_LOOKUP_H_
18#define ART_RUNTIME_MIRROR_METHOD_HANDLES_LOOKUP_H_
19
Orion Hodsonc069a302017-01-18 09:23:12 +000020#include "gc_root.h"
Orion Hodsonc069a302017-01-18 09:23:12 +000021#include "handle.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070022#include "obj_ptr.h"
23#include "object.h"
Orion Hodsonc069a302017-01-18 09:23:12 +000024#include "utils.h"
25
26namespace art {
27
28struct MethodHandlesLookupOffsets;
29class RootVisitor;
30
31namespace mirror {
32
Orion Hodsonf8db2c32017-07-07 20:07:12 +010033class MethodHandle;
34class MethodType;
35
Orion Hodsonc069a302017-01-18 09:23:12 +000036// C++ mirror of java.lang.invoke.MethodHandles.Lookup
37class MANAGED MethodHandlesLookup : public Object {
38 public:
39 static mirror::MethodHandlesLookup* Create(Thread* const self,
40 Handle<Class> lookup_class)
41 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
42
43 static mirror::Class* StaticClass() REQUIRES_SHARED(Locks::mutator_lock_) {
44 return static_class_.Read();
45 }
46
47 static void SetClass(Class* klass) REQUIRES_SHARED(Locks::mutator_lock_);
48 static void ResetClass() REQUIRES_SHARED(Locks::mutator_lock_);
49 static void VisitRoots(RootVisitor* visitor) REQUIRES_SHARED(Locks::mutator_lock_);
50
Orion Hodsonf8db2c32017-07-07 20:07:12 +010051 // Returns the result of java.lang.invoke.MethodHandles.lookup().
52 static mirror::MethodHandlesLookup* GetDefault(Thread* const self)
53 REQUIRES_SHARED(Locks::mutator_lock_);
54
55 // Find constructor using java.lang.invoke.MethodHandles$Lookup.findConstructor().
56 mirror::MethodHandle* FindConstructor(Thread* const self,
57 Handle<Class> klass,
58 Handle<MethodType> method_type)
59 REQUIRES_SHARED(Locks::mutator_lock_);
60
Orion Hodsonc069a302017-01-18 09:23:12 +000061 private:
62 static MemberOffset AllowedModesOffset() {
63 return MemberOffset(OFFSETOF_MEMBER(MethodHandlesLookup, allowed_modes_));
64 }
65
66 static MemberOffset LookupClassOffset() {
67 return MemberOffset(OFFSETOF_MEMBER(MethodHandlesLookup, lookup_class_));
68 }
69
70 HeapReference<mirror::Class> lookup_class_;
71
72 int32_t allowed_modes_;
73
74 static GcRoot<mirror::Class> static_class_; // java.lang.invoke.MethodHandles.Lookup.class
75
76 friend struct art::MethodHandlesLookupOffsets; // for verifying offset information
77 DISALLOW_IMPLICIT_CONSTRUCTORS(MethodHandlesLookup);
78};
79
80} // namespace mirror
81} // namespace art
82
83#endif // ART_RUNTIME_MIRROR_METHOD_HANDLES_LOOKUP_H_