Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 1 | /* |
| 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 | #include "method_handles_lookup.h" |
| 18 | |
| 19 | #include "class.h" |
| 20 | #include "gc_root-inl.h" |
| 21 | #include "object-inl.h" |
| 22 | #include "handle_scope.h" |
| 23 | #include "modifiers.h" |
| 24 | |
| 25 | namespace art { |
| 26 | namespace mirror { |
| 27 | |
| 28 | GcRoot<mirror::Class> MethodHandlesLookup::static_class_; |
| 29 | |
| 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); |
| 34 | } |
| 35 | |
| 36 | void MethodHandlesLookup::ResetClass() { |
| 37 | CHECK(!static_class_.IsNull()); |
| 38 | static_class_ = GcRoot<Class>(nullptr); |
| 39 | } |
| 40 | |
| 41 | void MethodHandlesLookup::VisitRoots(RootVisitor* visitor) { |
| 42 | static_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass)); |
| 43 | } |
| 44 | |
| 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; |
| 48 | |
| 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); |
| 54 | return mhl.Get(); |
| 55 | } |
| 56 | |
| 57 | } // namespace mirror |
| 58 | } // namespace art |