blob: 3cc70e1b85ec097fae9a42d241c2293a92e90b27 [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
Mathieu Chartiere401d142015-04-22 13:56:20 -070019#include "art_method.h"
20#include "gc_root-inl.h"
21#include "mirror/class-inl.h"
Mathieu Chartierfc58af42015-04-16 18:00:39 -070022#include "mirror/object-inl.h"
23
24namespace art {
25namespace mirror {
26
27GcRoot<Class> Method::static_class_;
28GcRoot<Class> Method::array_class_;
29GcRoot<Class> Constructor::static_class_;
30GcRoot<Class> Constructor::array_class_;
31
32void 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
38void Method::ResetClass() {
39 CHECK(!static_class_.IsNull());
40 static_class_ = GcRoot<Class>(nullptr);
41}
42
43void 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
49void Method::ResetArrayClass() {
50 CHECK(!array_class_.IsNull());
51 array_class_ = GcRoot<Class>(nullptr);
52}
53
Andreas Gampee01e3642016-07-25 13:06:04 -070054template <size_t kPointerSize, bool kTransactionActive>
Mathieu Chartiere401d142015-04-22 13:56:20 -070055Method* Method::CreateFromArtMethod(Thread* self, ArtMethod* method) {
Mathieu Chartierfc58af42015-04-16 18:00:39 -070056 DCHECK(!method->IsConstructor()) << PrettyMethod(method);
57 auto* ret = down_cast<Method*>(StaticClass()->AllocObject(self));
58 if (LIKELY(ret != nullptr)) {
Andreas Gampee01e3642016-07-25 13:06:04 -070059 static_cast<AbstractMethod*>(ret)->
60 CreateFromArtMethod<kPointerSize, kTransactionActive>(method);
Mathieu Chartierfc58af42015-04-16 18:00:39 -070061 }
62 return ret;
63}
64
Andreas Gampee01e3642016-07-25 13:06:04 -070065template Method* Method::CreateFromArtMethod<4U, false>(Thread* self, ArtMethod* method);
66template Method* Method::CreateFromArtMethod<4U, true>(Thread* self, ArtMethod* method);
67template Method* Method::CreateFromArtMethod<8U, false>(Thread* self, ArtMethod* method);
68template Method* Method::CreateFromArtMethod<8U, true>(Thread* self, ArtMethod* method);
Andreas Gampebc4d2182016-02-22 10:03:12 -080069
Mathieu Chartierfc58af42015-04-16 18:00:39 -070070void Method::VisitRoots(RootVisitor* visitor) {
71 static_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
72 array_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
73}
74
75void Constructor::SetClass(Class* klass) {
76 CHECK(static_class_.IsNull()) << static_class_.Read() << " " << klass;
77 CHECK(klass != nullptr);
78 static_class_ = GcRoot<Class>(klass);
79}
80
81void Constructor::ResetClass() {
82 CHECK(!static_class_.IsNull());
83 static_class_ = GcRoot<Class>(nullptr);
84}
85
86void Constructor::SetArrayClass(Class* klass) {
87 CHECK(array_class_.IsNull()) << array_class_.Read() << " " << klass;
88 CHECK(klass != nullptr);
89 array_class_ = GcRoot<Class>(klass);
90}
91
92void Constructor::ResetArrayClass() {
93 CHECK(!array_class_.IsNull());
94 array_class_ = GcRoot<Class>(nullptr);
95}
96
97void Constructor::VisitRoots(RootVisitor* visitor) {
98 static_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
99 array_class_.VisitRootIfNonNull(visitor, RootInfo(kRootStickyClass));
100}
101
Andreas Gampee01e3642016-07-25 13:06:04 -0700102template <size_t kPointerSize, bool kTransactionActive>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700103Constructor* Constructor::CreateFromArtMethod(Thread* self, ArtMethod* method) {
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700104 DCHECK(method->IsConstructor()) << PrettyMethod(method);
105 auto* ret = down_cast<Constructor*>(StaticClass()->AllocObject(self));
106 if (LIKELY(ret != nullptr)) {
Andreas Gampee01e3642016-07-25 13:06:04 -0700107 static_cast<AbstractMethod*>(ret)->
108 CreateFromArtMethod<kPointerSize, kTransactionActive>(method);
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700109 }
110 return ret;
111}
112
Andreas Gampee01e3642016-07-25 13:06:04 -0700113template Constructor* Constructor::CreateFromArtMethod<4U, false>(Thread* self, ArtMethod* method);
114template Constructor* Constructor::CreateFromArtMethod<4U, true>(Thread* self, ArtMethod* method);
115template Constructor* Constructor::CreateFromArtMethod<8U, false>(Thread* self, ArtMethod* method);
116template Constructor* Constructor::CreateFromArtMethod<8U, true>(Thread* self, ArtMethod* method);
Andreas Gampe6039e562016-04-05 18:18:43 -0700117
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700118} // namespace mirror
119} // namespace art