OSDN Git Service

Merge "Fix return value of AtomicMethodRefMap::Get()"
[android-x86/art.git] / runtime / mirror / method.cc
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 "art_method.h"
20 #include "gc_root-inl.h"
21 #include "mirror/class-inl.h"
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
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);
61   }
62   return ret.Ptr();
63 }
64
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);
73
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
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);
113   }
114   return ret.Ptr();
115 }
116
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);
125
126 }  // namespace mirror
127 }  // namespace art