blob: b4dce583e13266b58e2b7dbc17fa1e5ba34c0381 [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 "abstract_method.h"
18
Mathieu Chartiere401d142015-04-22 13:56:20 -070019#include "art_method-inl.h"
Mathieu Chartierfc58af42015-04-16 18:00:39 -070020
21namespace art {
22namespace mirror {
23
Andreas Gampe542451c2016-07-26 09:02:02 -070024template <PointerSize kPointerSize, bool kTransactionActive>
Mathieu Chartiere401d142015-04-22 13:56:20 -070025bool AbstractMethod::CreateFromArtMethod(ArtMethod* method) {
Andreas Gampee01e3642016-07-25 13:06:04 -070026 auto* interface_method = method->GetInterfaceMethodIfProxy(kPointerSize);
Andreas Gampebc4d2182016-02-22 10:03:12 -080027 SetArtMethod<kTransactionActive>(method);
28 SetFieldObject<kTransactionActive>(DeclaringClassOffset(), method->GetDeclaringClass());
29 SetFieldObject<kTransactionActive>(
Mathieu Chartierfc58af42015-04-16 18:00:39 -070030 DeclaringClassOfOverriddenMethodOffset(), interface_method->GetDeclaringClass());
Andreas Gampebc4d2182016-02-22 10:03:12 -080031 SetField32<kTransactionActive>(AccessFlagsOffset(), method->GetAccessFlags());
32 SetField32<kTransactionActive>(DexMethodIndexOffset(), method->GetDexMethodIndex());
Mathieu Chartierfc58af42015-04-16 18:00:39 -070033 return true;
34}
35
Andreas Gampe542451c2016-07-26 09:02:02 -070036template bool AbstractMethod::CreateFromArtMethod<PointerSize::k32, false>(
37 ArtMethod* method);
38template bool AbstractMethod::CreateFromArtMethod<PointerSize::k32, true>(
39 ArtMethod* method);
40template bool AbstractMethod::CreateFromArtMethod<PointerSize::k64, false>(
41 ArtMethod* method);
42template bool AbstractMethod::CreateFromArtMethod<PointerSize::k64, true>(
43 ArtMethod* method);
Andreas Gampebc4d2182016-02-22 10:03:12 -080044
Mathieu Chartiere401d142015-04-22 13:56:20 -070045ArtMethod* AbstractMethod::GetArtMethod() {
46 return reinterpret_cast<ArtMethod*>(GetField64(ArtMethodOffset()));
47}
48
Andreas Gampebc4d2182016-02-22 10:03:12 -080049template <bool kTransactionActive>
Mathieu Chartiere401d142015-04-22 13:56:20 -070050void AbstractMethod::SetArtMethod(ArtMethod* method) {
Andreas Gampebc4d2182016-02-22 10:03:12 -080051 SetField64<kTransactionActive>(ArtMethodOffset(), reinterpret_cast<uint64_t>(method));
Mathieu Chartierfc58af42015-04-16 18:00:39 -070052}
53
Andreas Gampebc4d2182016-02-22 10:03:12 -080054template void AbstractMethod::SetArtMethod<false>(ArtMethod* method);
55template void AbstractMethod::SetArtMethod<true>(ArtMethod* method);
56
Mathieu Chartierfc58af42015-04-16 18:00:39 -070057mirror::Class* AbstractMethod::GetDeclaringClass() {
58 return GetFieldObject<mirror::Class>(DeclaringClassOffset());
59}
60
61} // namespace mirror
62} // namespace art