Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2015 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.h" |
| 18 | |
| 19 | #include "mirror/art_method.h" |
| 20 | #include "mirror/object-inl.h" |
| 21 | |
| 22 | namespace art { |
| 23 | namespace mirror { |
| 24 | |
| 25 | GcRoot<Class> Method::static_class_; |
| 26 | GcRoot<Class> Method::array_class_; |
| 27 | GcRoot<Class> Constructor::static_class_; |
| 28 | GcRoot<Class> Constructor::array_class_; |
| 29 | |
| 30 | void Method::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 Method::ResetClass() { |
| 37 | CHECK(!static_class_.IsNull()); |
| 38 | static_class_ = GcRoot<Class>(nullptr); |
| 39 | } |
| 40 | |
| 41 | void Method::SetArrayClass(Class* klass) { |
| 42 | CHECK(array_class_.IsNull()) << array_class_.Read() << " " << klass; |
| 43 | CHECK(klass != nullptr); |
| 44 | array_class_ = GcRoot<Class>(klass); |
| 45 | } |
| 46 | |
| 47 | void Method::ResetArrayClass() { |
| 48 | CHECK(!array_class_.IsNull()); |
| 49 | array_class_ = GcRoot<Class>(nullptr); |
| 50 | } |
| 51 | |
| 52 | Method* Method::CreateFromArtMethod(Thread* self, mirror::ArtMethod* method) { |
| 53 | DCHECK(!method->IsConstructor()) << PrettyMethod(method); |
| 54 | auto* ret = down_cast<Method*>(StaticClass()->AllocObject(self)); |
| 55 | if (LIKELY(ret != nullptr)) { |
| 56 | static_cast<AbstractMethod*>(ret)->CreateFromArtMethod(method); |
| 57 | } |
| 58 | return ret; |
| 59 | } |
| 60 | |
| 61 | void Method::VisitRoots(RootVisitor* visitor) { |
| 62 | static_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass)); |
| 63 | array_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass)); |
| 64 | } |
| 65 | |
| 66 | void Constructor::SetClass(Class* klass) { |
| 67 | CHECK(static_class_.IsNull()) << static_class_.Read() << " " << klass; |
| 68 | CHECK(klass != nullptr); |
| 69 | static_class_ = GcRoot<Class>(klass); |
| 70 | } |
| 71 | |
| 72 | void Constructor::ResetClass() { |
| 73 | CHECK(!static_class_.IsNull()); |
| 74 | static_class_ = GcRoot<Class>(nullptr); |
| 75 | } |
| 76 | |
| 77 | void Constructor::SetArrayClass(Class* klass) { |
| 78 | CHECK(array_class_.IsNull()) << array_class_.Read() << " " << klass; |
| 79 | CHECK(klass != nullptr); |
| 80 | array_class_ = GcRoot<Class>(klass); |
| 81 | } |
| 82 | |
| 83 | void Constructor::ResetArrayClass() { |
| 84 | CHECK(!array_class_.IsNull()); |
| 85 | array_class_ = GcRoot<Class>(nullptr); |
| 86 | } |
| 87 | |
| 88 | void Constructor::VisitRoots(RootVisitor* visitor) { |
| 89 | static_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass)); |
| 90 | array_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass)); |
| 91 | } |
| 92 | |
| 93 | Constructor* Constructor::CreateFromArtMethod(Thread* self, mirror::ArtMethod* method) { |
| 94 | DCHECK(method->IsConstructor()) << PrettyMethod(method); |
| 95 | auto* ret = down_cast<Constructor*>(StaticClass()->AllocObject(self)); |
| 96 | if (LIKELY(ret != nullptr)) { |
| 97 | static_cast<AbstractMethod*>(ret)->CreateFromArtMethod(method); |
| 98 | } |
| 99 | return ret; |
| 100 | } |
| 101 | |
| 102 | } // namespace mirror |
| 103 | } // namespace art |