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 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
| 20 | #include "gc_root-inl.h" |
| 21 | #include "mirror/class-inl.h" |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 22 | #include "mirror/object-inl.h" |
| 23 | |
| 24 | namespace art { |
| 25 | namespace mirror { |
| 26 | |
| 27 | GcRoot<Class> Method::static_class_; |
| 28 | GcRoot<Class> Method::array_class_; |
| 29 | GcRoot<Class> Constructor::static_class_; |
| 30 | GcRoot<Class> Constructor::array_class_; |
| 31 | |
| 32 | void Method::SetClass(Class* klass) { |
| 33 | CHECK(static_class_.IsNull()) << static_class_.Read() << " " << klass; |
| 34 | CHECK(klass != nullptr); |
| 35 | static_class_ = GcRoot<Class>(klass); |
| 36 | } |
| 37 | |
| 38 | void Method::ResetClass() { |
| 39 | CHECK(!static_class_.IsNull()); |
| 40 | static_class_ = GcRoot<Class>(nullptr); |
| 41 | } |
| 42 | |
| 43 | void Method::SetArrayClass(Class* klass) { |
| 44 | CHECK(array_class_.IsNull()) << array_class_.Read() << " " << klass; |
| 45 | CHECK(klass != nullptr); |
| 46 | array_class_ = GcRoot<Class>(klass); |
| 47 | } |
| 48 | |
| 49 | void Method::ResetArrayClass() { |
| 50 | CHECK(!array_class_.IsNull()); |
| 51 | array_class_ = GcRoot<Class>(nullptr); |
| 52 | } |
| 53 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 54 | template <PointerSize kPointerSize, bool kTransactionActive> |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 55 | Method* Method::CreateFromArtMethod(Thread* self, ArtMethod* method) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 56 | DCHECK(!method->IsConstructor()) << method->PrettyMethod(); |
Mathieu Chartier | 28bd2e4 | 2016-10-04 13:54:57 -0700 | [diff] [blame] | 57 | ObjPtr<Method> ret = ObjPtr<Method>::DownCast(StaticClass()->AllocObject(self)); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 58 | if (LIKELY(ret != nullptr)) { |
Mathieu Chartier | 28bd2e4 | 2016-10-04 13:54:57 -0700 | [diff] [blame] | 59 | ObjPtr<Executable>(ret)-> |
Andreas Gampe | e01e364 | 2016-07-25 13:06:04 -0700 | [diff] [blame] | 60 | CreateFromArtMethod<kPointerSize, kTransactionActive>(method); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 61 | } |
Mathieu Chartier | 28bd2e4 | 2016-10-04 13:54:57 -0700 | [diff] [blame] | 62 | return ret.Ptr(); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 65 | template Method* Method::CreateFromArtMethod<PointerSize::k32, false>(Thread* self, |
| 66 | ArtMethod* method); |
| 67 | template Method* Method::CreateFromArtMethod<PointerSize::k32, true>(Thread* self, |
| 68 | ArtMethod* method); |
| 69 | template Method* Method::CreateFromArtMethod<PointerSize::k64, false>(Thread* self, |
| 70 | ArtMethod* method); |
| 71 | template Method* Method::CreateFromArtMethod<PointerSize::k64, true>(Thread* self, |
| 72 | ArtMethod* method); |
Andreas Gampe | bc4d218 | 2016-02-22 10:03:12 -0800 | [diff] [blame] | 73 | |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 74 | void Method::VisitRoots(RootVisitor* visitor) { |
| 75 | static_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass)); |
| 76 | array_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass)); |
| 77 | } |
| 78 | |
| 79 | void Constructor::SetClass(Class* klass) { |
| 80 | CHECK(static_class_.IsNull()) << static_class_.Read() << " " << klass; |
| 81 | CHECK(klass != nullptr); |
| 82 | static_class_ = GcRoot<Class>(klass); |
| 83 | } |
| 84 | |
| 85 | void Constructor::ResetClass() { |
| 86 | CHECK(!static_class_.IsNull()); |
| 87 | static_class_ = GcRoot<Class>(nullptr); |
| 88 | } |
| 89 | |
| 90 | void Constructor::SetArrayClass(Class* klass) { |
| 91 | CHECK(array_class_.IsNull()) << array_class_.Read() << " " << klass; |
| 92 | CHECK(klass != nullptr); |
| 93 | array_class_ = GcRoot<Class>(klass); |
| 94 | } |
| 95 | |
| 96 | void Constructor::ResetArrayClass() { |
| 97 | CHECK(!array_class_.IsNull()); |
| 98 | array_class_ = GcRoot<Class>(nullptr); |
| 99 | } |
| 100 | |
| 101 | void Constructor::VisitRoots(RootVisitor* visitor) { |
| 102 | static_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass)); |
| 103 | array_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass)); |
| 104 | } |
| 105 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 106 | template <PointerSize kPointerSize, bool kTransactionActive> |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 107 | Constructor* Constructor::CreateFromArtMethod(Thread* self, ArtMethod* method) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 108 | DCHECK(method->IsConstructor()) << method->PrettyMethod(); |
Mathieu Chartier | 28bd2e4 | 2016-10-04 13:54:57 -0700 | [diff] [blame] | 109 | ObjPtr<Constructor> ret = ObjPtr<Constructor>::DownCast(StaticClass()->AllocObject(self)); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 110 | if (LIKELY(ret != nullptr)) { |
Mathieu Chartier | 28bd2e4 | 2016-10-04 13:54:57 -0700 | [diff] [blame] | 111 | ObjPtr<Executable>(ret)-> |
Andreas Gampe | e01e364 | 2016-07-25 13:06:04 -0700 | [diff] [blame] | 112 | CreateFromArtMethod<kPointerSize, kTransactionActive>(method); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 113 | } |
Mathieu Chartier | 28bd2e4 | 2016-10-04 13:54:57 -0700 | [diff] [blame] | 114 | return ret.Ptr(); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 117 | template Constructor* Constructor::CreateFromArtMethod<PointerSize::k32, false>( |
| 118 | Thread* self, ArtMethod* method); |
| 119 | template Constructor* Constructor::CreateFromArtMethod<PointerSize::k32, true>( |
| 120 | Thread* self, ArtMethod* method); |
| 121 | template Constructor* Constructor::CreateFromArtMethod<PointerSize::k64, false>( |
| 122 | Thread* self, ArtMethod* method); |
| 123 | template Constructor* Constructor::CreateFromArtMethod<PointerSize::k64, true>( |
| 124 | Thread* self, ArtMethod* method); |
Andreas Gampe | 6039e56 | 2016-04-05 18:18:43 -0700 | [diff] [blame] | 125 | |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 126 | } // namespace mirror |
| 127 | } // namespace art |