| Narayan Kamath | afa4827 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 1 | /* |
| 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 | #include "method_handle_impl.h" |
| 18 | |
| 19 | #include "class-inl.h" |
| 20 | #include "gc_root-inl.h" |
| 21 | |
| 22 | namespace art { |
| 23 | namespace mirror { |
| 24 | |
| Orion Hodson | cfa325e | 2016-10-13 10:25:54 +0100 | [diff] [blame] | 25 | mirror::Class* MethodHandle::StaticClass() { |
| 26 | mirror::Class* klass = MethodHandleImpl::StaticClass()->GetSuperClass(); |
| 27 | DCHECK(klass->DescriptorEquals("Ljava/lang/invoke/MethodHandle;")); |
| 28 | return klass; |
| 29 | } |
| 30 | |
| Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame^] | 31 | void MethodHandle::Initialize(uintptr_t art_field_or_method, |
| 32 | Kind kind, |
| 33 | Handle<MethodType> method_type) |
| 34 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 35 | CHECK(!Runtime::Current()->IsActiveTransaction()); |
| 36 | SetFieldObject<false>(CachedSpreadInvokerOffset(), nullptr); |
| 37 | SetFieldObject<false>(NominalTypeOffset(), nullptr); |
| 38 | SetFieldObject<false>(MethodTypeOffset(), method_type.Get()); |
| 39 | SetField32<false>(HandleKindOffset(), static_cast<uint32_t>(kind)); |
| 40 | SetField64<false>(ArtFieldOrMethodOffset(), art_field_or_method); |
| 41 | } |
| 42 | |
| Narayan Kamath | afa4827 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 43 | GcRoot<mirror::Class> MethodHandleImpl::static_class_; |
| 44 | |
| 45 | void MethodHandleImpl::SetClass(Class* klass) { |
| 46 | CHECK(static_class_.IsNull()) << static_class_.Read() << " " << klass; |
| 47 | CHECK(klass != nullptr); |
| 48 | static_class_ = GcRoot<Class>(klass); |
| 49 | } |
| 50 | |
| 51 | void MethodHandleImpl::ResetClass() { |
| 52 | CHECK(!static_class_.IsNull()); |
| 53 | static_class_ = GcRoot<Class>(nullptr); |
| 54 | } |
| 55 | |
| 56 | void MethodHandleImpl::VisitRoots(RootVisitor* visitor) { |
| 57 | static_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass)); |
| 58 | } |
| 59 | |
| Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame^] | 60 | mirror::MethodHandleImpl* MethodHandleImpl::Create(Thread* const self, |
| 61 | uintptr_t art_field_or_method, |
| 62 | MethodHandle::Kind kind, |
| 63 | Handle<MethodType> method_type) |
| 64 | REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_) { |
| 65 | StackHandleScope<1> hs(self); |
| 66 | Handle<mirror::MethodHandleImpl> mh( |
| 67 | hs.NewHandle(ObjPtr<MethodHandleImpl>::DownCast(StaticClass()->AllocObject(self)))); |
| 68 | mh->Initialize(art_field_or_method, kind, method_type); |
| 69 | return mh.Get(); |
| 70 | } |
| 71 | |
| Narayan Kamath | afa4827 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 72 | } // namespace mirror |
| 73 | } // namespace art |