blob: 33ebd817d1d903bb4fc700f7def5d615e7f57aa6 [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
Mathieu Chartiere401d142015-04-22 13:56:20 -070017#include "art_method-inl.h"
Neil Fuller0e844392016-09-08 13:43:31 +010018#include "executable.h"
Mathieu Chartierfc58af42015-04-16 18:00:39 -070019
20namespace art {
21namespace mirror {
22
Andreas Gampe542451c2016-07-26 09:02:02 -070023template <PointerSize kPointerSize, bool kTransactionActive>
Neil Fuller0e844392016-09-08 13:43:31 +010024bool Executable::CreateFromArtMethod(ArtMethod* method) {
Andreas Gampee01e3642016-07-25 13:06:04 -070025 auto* interface_method = method->GetInterfaceMethodIfProxy(kPointerSize);
Andreas Gampebc4d2182016-02-22 10:03:12 -080026 SetArtMethod<kTransactionActive>(method);
27 SetFieldObject<kTransactionActive>(DeclaringClassOffset(), method->GetDeclaringClass());
28 SetFieldObject<kTransactionActive>(
Mathieu Chartierfc58af42015-04-16 18:00:39 -070029 DeclaringClassOfOverriddenMethodOffset(), interface_method->GetDeclaringClass());
Andreas Gampebc4d2182016-02-22 10:03:12 -080030 SetField32<kTransactionActive>(AccessFlagsOffset(), method->GetAccessFlags());
31 SetField32<kTransactionActive>(DexMethodIndexOffset(), method->GetDexMethodIndex());
Mathieu Chartierfc58af42015-04-16 18:00:39 -070032 return true;
33}
34
Neil Fuller0e844392016-09-08 13:43:31 +010035template bool Executable::CreateFromArtMethod<PointerSize::k32, false>(
Andreas Gampe542451c2016-07-26 09:02:02 -070036 ArtMethod* method);
Neil Fuller0e844392016-09-08 13:43:31 +010037template bool Executable::CreateFromArtMethod<PointerSize::k32, true>(
Andreas Gampe542451c2016-07-26 09:02:02 -070038 ArtMethod* method);
Neil Fuller0e844392016-09-08 13:43:31 +010039template bool Executable::CreateFromArtMethod<PointerSize::k64, false>(
Andreas Gampe542451c2016-07-26 09:02:02 -070040 ArtMethod* method);
Neil Fuller0e844392016-09-08 13:43:31 +010041template bool Executable::CreateFromArtMethod<PointerSize::k64, true>(
Andreas Gampe542451c2016-07-26 09:02:02 -070042 ArtMethod* method);
Andreas Gampebc4d2182016-02-22 10:03:12 -080043
Neil Fuller0e844392016-09-08 13:43:31 +010044ArtMethod* Executable::GetArtMethod() {
Mathieu Chartiere401d142015-04-22 13:56:20 -070045 return reinterpret_cast<ArtMethod*>(GetField64(ArtMethodOffset()));
46}
47
Andreas Gampebc4d2182016-02-22 10:03:12 -080048template <bool kTransactionActive>
Neil Fuller0e844392016-09-08 13:43:31 +010049void Executable::SetArtMethod(ArtMethod* method) {
Andreas Gampebc4d2182016-02-22 10:03:12 -080050 SetField64<kTransactionActive>(ArtMethodOffset(), reinterpret_cast<uint64_t>(method));
Mathieu Chartierfc58af42015-04-16 18:00:39 -070051}
52
Neil Fuller0e844392016-09-08 13:43:31 +010053template void Executable::SetArtMethod<false>(ArtMethod* method);
54template void Executable::SetArtMethod<true>(ArtMethod* method);
Andreas Gampebc4d2182016-02-22 10:03:12 -080055
Neil Fuller0e844392016-09-08 13:43:31 +010056mirror::Class* Executable::GetDeclaringClass() {
Mathieu Chartierfc58af42015-04-16 18:00:39 -070057 return GetFieldObject<mirror::Class>(DeclaringClassOffset());
58}
59
60} // namespace mirror
61} // namespace art