blob: 81530bb13074e7474549e167856e76095651c541 [file] [log] [blame]
Mathieu Chartierfc58af42015-04-16 18:00:39 -07001/*
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
22namespace art {
23namespace mirror {
24
25GcRoot<Class> Method::static_class_;
26GcRoot<Class> Method::array_class_;
27GcRoot<Class> Constructor::static_class_;
28GcRoot<Class> Constructor::array_class_;
29
30void 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
36void Method::ResetClass() {
37 CHECK(!static_class_.IsNull());
38 static_class_ = GcRoot<Class>(nullptr);
39}
40
41void 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
47void Method::ResetArrayClass() {
48 CHECK(!array_class_.IsNull());
49 array_class_ = GcRoot<Class>(nullptr);
50}
51
52Method* 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
61void Method::VisitRoots(RootVisitor* visitor) {
62 static_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
63 array_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
64}
65
66void 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
72void Constructor::ResetClass() {
73 CHECK(!static_class_.IsNull());
74 static_class_ = GcRoot<Class>(nullptr);
75}
76
77void 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
83void Constructor::ResetArrayClass() {
84 CHECK(!array_class_.IsNull());
85 array_class_ = GcRoot<Class>(nullptr);
86}
87
88void Constructor::VisitRoots(RootVisitor* visitor) {
89 static_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
90 array_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
91}
92
93Constructor* 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