blob: cd0557a235ab0574191005be567c4ac6993ae774 [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"
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +000023#include "imtable.h"
Mathieu Chartiere42888f2016-04-14 10:49:19 -070024
Mathieu Chartier4a26f172016-01-26 14:26:18 -080025namespace art {
26
27template <ReadBarrierOption kReadBarrierOption>
28inline mirror::Object* ImageHeader::GetImageRoot(ImageRoot image_root) const {
29 mirror::ObjectArray<mirror::Object>* image_roots = GetImageRoots<kReadBarrierOption>();
30 return image_roots->Get<kVerifyNone, kReadBarrierOption>(static_cast<int32_t>(image_root));
31}
32
33template <ReadBarrierOption kReadBarrierOption>
34inline mirror::ObjectArray<mirror::Object>* ImageHeader::GetImageRoots() const {
35 // Need a read barrier as it's not visited during root scan.
36 // Pass in the address of the local variable to the read barrier
37 // rather than image_roots_ because it won't move (asserted below)
38 // and it's a const member.
39 mirror::ObjectArray<mirror::Object>* image_roots =
40 reinterpret_cast<mirror::ObjectArray<mirror::Object>*>(image_roots_);
41 mirror::ObjectArray<mirror::Object>* result =
42 ReadBarrier::BarrierForRoot<mirror::ObjectArray<mirror::Object>, kReadBarrierOption>(
43 &image_roots);
44 DCHECK_EQ(image_roots, result);
45 return image_roots;
46}
47
Mathieu Chartiere42888f2016-04-14 10:49:19 -070048template <typename Visitor>
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +000049inline void ImageHeader::VisitPackedImTables(const Visitor& visitor,
50 uint8_t* base,
51 size_t pointer_size) const {
52 const ImageSection& section = GetImageSection(kSectionImTables);
53 for (size_t pos = 0; pos < section.Size();) {
54 ImTable* imt = reinterpret_cast<ImTable*>(base + section.Offset() + pos);
55 for (size_t i = 0; i < ImTable::kSize; ++i) {
56 ArtMethod* orig = imt->Get(i, pointer_size);
57 ArtMethod* updated = visitor(orig);
58 if (updated != orig) {
59 imt->Set(i, updated, pointer_size);
60 }
61 }
62 pos += ImTable::SizeInBytes(pointer_size);
63 }
64}
65
66template <typename Visitor>
Mathieu Chartiere42888f2016-04-14 10:49:19 -070067inline void ImageHeader::VisitPackedImtConflictTables(const Visitor& visitor,
68 uint8_t* base,
69 size_t pointer_size) const {
70 const ImageSection& section = GetImageSection(kSectionIMTConflictTables);
71 for (size_t pos = 0; pos < section.Size(); ) {
72 auto* table = reinterpret_cast<ImtConflictTable*>(base + section.Offset() + pos);
73 table->Visit([&visitor](const std::pair<ArtMethod*, ArtMethod*>& methods) {
74 return std::make_pair(visitor(methods.first), visitor(methods.second));
75 }, pointer_size);
76 pos += table->ComputeSize(pointer_size);
77 }
78}
79
Mathieu Chartier4a26f172016-01-26 14:26:18 -080080} // namespace art
81
82#endif // ART_RUNTIME_IMAGE_INL_H_