2 * Copyright (C) 2015 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.
19 #include "art_method.h"
20 #include "gc_root-inl.h"
21 #include "mirror/class-inl.h"
22 #include "mirror/object-inl.h"
27 GcRoot<Class> Method::static_class_;
28 GcRoot<Class> Method::array_class_;
29 GcRoot<Class> Constructor::static_class_;
30 GcRoot<Class> Constructor::array_class_;
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);
38 void Method::ResetClass() {
39 CHECK(!static_class_.IsNull());
40 static_class_ = GcRoot<Class>(nullptr);
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);
49 void Method::ResetArrayClass() {
50 CHECK(!array_class_.IsNull());
51 array_class_ = GcRoot<Class>(nullptr);
54 template <PointerSize kPointerSize, bool kTransactionActive>
55 Method* Method::CreateFromArtMethod(Thread* self, ArtMethod* method) {
56 DCHECK(!method->IsConstructor()) << method->PrettyMethod();
57 ObjPtr<Method> ret = ObjPtr<Method>::DownCast(StaticClass()->AllocObject(self));
58 if (LIKELY(ret != nullptr)) {
59 ObjPtr<Executable>(ret)->
60 CreateFromArtMethod<kPointerSize, kTransactionActive>(method);
65 template Method* Method::CreateFromArtMethod<PointerSize::k32, false>(Thread* self,
67 template Method* Method::CreateFromArtMethod<PointerSize::k32, true>(Thread* self,
69 template Method* Method::CreateFromArtMethod<PointerSize::k64, false>(Thread* self,
71 template Method* Method::CreateFromArtMethod<PointerSize::k64, true>(Thread* self,
74 void Method::VisitRoots(RootVisitor* visitor) {
75 static_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
76 array_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
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);
85 void Constructor::ResetClass() {
86 CHECK(!static_class_.IsNull());
87 static_class_ = GcRoot<Class>(nullptr);
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);
96 void Constructor::ResetArrayClass() {
97 CHECK(!array_class_.IsNull());
98 array_class_ = GcRoot<Class>(nullptr);
101 void Constructor::VisitRoots(RootVisitor* visitor) {
102 static_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
103 array_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
106 template <PointerSize kPointerSize, bool kTransactionActive>
107 Constructor* Constructor::CreateFromArtMethod(Thread* self, ArtMethod* method) {
108 DCHECK(method->IsConstructor()) << method->PrettyMethod();
109 ObjPtr<Constructor> ret = ObjPtr<Constructor>::DownCast(StaticClass()->AllocObject(self));
110 if (LIKELY(ret != nullptr)) {
111 ObjPtr<Executable>(ret)->
112 CreateFromArtMethod<kPointerSize, kTransactionActive>(method);
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);
126 } // namespace mirror