2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "method_handles_lookup.h"
20 #include "gc_root-inl.h"
21 #include "object-inl.h"
22 #include "handle_scope.h"
23 #include "modifiers.h"
28 GcRoot<mirror::Class> MethodHandlesLookup::static_class_;
30 void MethodHandlesLookup::SetClass(Class* klass) {
31 CHECK(static_class_.IsNull()) << static_class_.Read() << " " << klass;
32 CHECK(klass != nullptr);
33 static_class_ = GcRoot<Class>(klass);
36 void MethodHandlesLookup::ResetClass() {
37 CHECK(!static_class_.IsNull());
38 static_class_ = GcRoot<Class>(nullptr);
41 void MethodHandlesLookup::VisitRoots(RootVisitor* visitor) {
42 static_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
45 MethodHandlesLookup* MethodHandlesLookup::Create(Thread* const self, Handle<Class> lookup_class)
46 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_) {
47 static constexpr uint32_t kAllModes = kAccPublic | kAccPrivate | kAccProtected | kAccStatic;
49 StackHandleScope<1> hs(self);
50 Handle<MethodHandlesLookup> mhl(
51 hs.NewHandle(ObjPtr<MethodHandlesLookup>::DownCast(StaticClass()->AllocObject(self))));
52 mhl->SetFieldObject<false>(LookupClassOffset(), lookup_class.Get());
53 mhl->SetField32<false>(AllowedModesOffset(), kAllModes);