blob: 935a1b6705bad97cbf92e6a30d923c23c1477c04 [file] [log] [blame]
Mathieu Chartier4a26f172016-01-26 14:26:18 -08001/*
2 * Copyright (C) 2016 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#ifndef ART_RUNTIME_IMAGE_INL_H_
18#define ART_RUNTIME_IMAGE_INL_H_
19
20#include "image.h"
21
Mathieu Chartiere42888f2016-04-14 10:49:19 -070022#include "art_method.h"
Andreas Gampe75a7db62016-09-26 12:04:26 -070023#include "imt_conflict_table.h"
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +000024#include "imtable.h"
Vladimir Marko3a21e382016-09-02 12:38:38 +010025#include "read_barrier-inl.h"
Mathieu Chartiere42888f2016-04-14 10:49:19 -070026
Mathieu Chartier4a26f172016-01-26 14:26:18 -080027namespace art {
28
29template <ReadBarrierOption kReadBarrierOption>
30inline mirror::Object* ImageHeader::GetImageRoot(ImageRoot image_root) const {
31 mirror::ObjectArray<mirror::Object>* image_roots = GetImageRoots<kReadBarrierOption>();
32 return image_roots->Get<kVerifyNone, kReadBarrierOption>(static_cast<int32_t>(image_root));
33}
34
35template <ReadBarrierOption kReadBarrierOption>
36inline mirror::ObjectArray<mirror::Object>* ImageHeader::GetImageRoots() const {
37 // Need a read barrier as it's not visited during root scan.
38 // Pass in the address of the local variable to the read barrier
39 // rather than image_roots_ because it won't move (asserted below)
40 // and it's a const member.
41 mirror::ObjectArray<mirror::Object>* image_roots =
42 reinterpret_cast<mirror::ObjectArray<mirror::Object>*>(image_roots_);
43 mirror::ObjectArray<mirror::Object>* result =
44 ReadBarrier::BarrierForRoot<mirror::ObjectArray<mirror::Object>, kReadBarrierOption>(
45 &image_roots);
46 DCHECK_EQ(image_roots, result);
47 return image_roots;
48}
49
Mathieu Chartiere42888f2016-04-14 10:49:19 -070050template <typename Visitor>
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +000051inline void ImageHeader::VisitPackedImTables(const Visitor& visitor,
52 uint8_t* base,
Andreas Gampe542451c2016-07-26 09:02:02 -070053 PointerSize pointer_size) const {
Vladimir Markocd87c3e2017-09-05 13:11:57 +010054 const ImageSection& section = GetImTablesSection();
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +000055 for (size_t pos = 0; pos < section.Size();) {
56 ImTable* imt = reinterpret_cast<ImTable*>(base + section.Offset() + pos);
57 for (size_t i = 0; i < ImTable::kSize; ++i) {
58 ArtMethod* orig = imt->Get(i, pointer_size);
59 ArtMethod* updated = visitor(orig);
60 if (updated != orig) {
61 imt->Set(i, updated, pointer_size);
62 }
63 }
64 pos += ImTable::SizeInBytes(pointer_size);
65 }
66}
67
68template <typename Visitor>
Mathieu Chartiere42888f2016-04-14 10:49:19 -070069inline void ImageHeader::VisitPackedImtConflictTables(const Visitor& visitor,
70 uint8_t* base,
Andreas Gampe542451c2016-07-26 09:02:02 -070071 PointerSize pointer_size) const {
Vladimir Markocd87c3e2017-09-05 13:11:57 +010072 const ImageSection& section = GetIMTConflictTablesSection();
Mathieu Chartiere42888f2016-04-14 10:49:19 -070073 for (size_t pos = 0; pos < section.Size(); ) {
74 auto* table = reinterpret_cast<ImtConflictTable*>(base + section.Offset() + pos);
75 table->Visit([&visitor](const std::pair<ArtMethod*, ArtMethod*>& methods) {
76 return std::make_pair(visitor(methods.first), visitor(methods.second));
77 }, pointer_size);
78 pos += table->ComputeSize(pointer_size);
79 }
80}
81
Mathieu Chartier4a26f172016-01-26 14:26:18 -080082} // namespace art
83
84#endif // ART_RUNTIME_IMAGE_INL_H_