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 "class_root.h"
21 #include "mirror/class-alloc-inl.h"
22 #include "mirror/object-inl.h"
23 #include "obj_ptr-inl.h"
24 
25 namespace art {
26 namespace mirror {
27 
28 template <PointerSize kPointerSize, bool kTransactionActive>
CreateFromArtMethod(Thread * self,ArtMethod * method)29 ObjPtr<Method> Method::CreateFromArtMethod(Thread* self, ArtMethod* method) {
30   DCHECK(!method->IsConstructor()) << method->PrettyMethod();
31   ObjPtr<Method> ret = ObjPtr<Method>::DownCast(GetClassRoot<Method>()->AllocObject(self));
32   if (LIKELY(ret != nullptr)) {
33     ret->Executable::CreateFromArtMethod<kPointerSize, kTransactionActive>(method);
34   }
35   return ret;
36 }
37 
38 template ObjPtr<Method> Method::CreateFromArtMethod<PointerSize::k32, false>(
39     Thread* self, ArtMethod* method);
40 template ObjPtr<Method> Method::CreateFromArtMethod<PointerSize::k32, true>(
41     Thread* self, ArtMethod* method);
42 template ObjPtr<Method> Method::CreateFromArtMethod<PointerSize::k64, false>(
43     Thread* self, ArtMethod* method);
44 template ObjPtr<Method> Method::CreateFromArtMethod<PointerSize::k64, true>(
45     Thread* self, ArtMethod* method);
46 
47 template <PointerSize kPointerSize, bool kTransactionActive>
CreateFromArtMethod(Thread * self,ArtMethod * method)48 ObjPtr<Constructor> Constructor::CreateFromArtMethod(Thread* self, ArtMethod* method) {
49   DCHECK(method->IsConstructor()) << method->PrettyMethod();
50   ObjPtr<Constructor> ret =
51       ObjPtr<Constructor>::DownCast(GetClassRoot<Constructor>()->AllocObject(self));
52   if (LIKELY(ret != nullptr)) {
53     ret->Executable::CreateFromArtMethod<kPointerSize, kTransactionActive>(method);
54   }
55   return ret;
56 }
57 
58 template ObjPtr<Constructor> Constructor::CreateFromArtMethod<PointerSize::k32, false>(
59     Thread* self, ArtMethod* method);
60 template ObjPtr<Constructor> Constructor::CreateFromArtMethod<PointerSize::k32, true>(
61     Thread* self, ArtMethod* method);
62 template ObjPtr<Constructor> Constructor::CreateFromArtMethod<PointerSize::k64, false>(
63     Thread* self, ArtMethod* method);
64 template ObjPtr<Constructor> Constructor::CreateFromArtMethod<PointerSize::k64, true>(
65     Thread* self, ArtMethod* method);
66 
67 }  // namespace mirror
68 }  // namespace art
69