blob: 9fde669a49c145b853ab4d226ce9b7fe4203e6b0 [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 Marko6834d342018-05-25 13:12:09 +010025#include "mirror/object_array-inl.h"
Vladimir Markoc13fbd82018-06-04 16:16:28 +010026#include "obj_ptr-inl.h"
Vladimir Marko3a21e382016-09-02 12:38:38 +010027#include "read_barrier-inl.h"
Mathieu Chartiere42888f2016-04-14 10:49:19 -070028
Mathieu Chartier4a26f172016-01-26 14:26:18 -080029namespace art {
30
31template <ReadBarrierOption kReadBarrierOption>
Vladimir Markoc13fbd82018-06-04 16:16:28 +010032inline ObjPtr<mirror::Object> ImageHeader::GetImageRoot(ImageRoot image_root) const {
33 ObjPtr<mirror::ObjectArray<mirror::Object>> image_roots = GetImageRoots<kReadBarrierOption>();
Mathieu Chartier4a26f172016-01-26 14:26:18 -080034 return image_roots->Get<kVerifyNone, kReadBarrierOption>(static_cast<int32_t>(image_root));
35}
36
37template <ReadBarrierOption kReadBarrierOption>
Vladimir Markoc13fbd82018-06-04 16:16:28 +010038inline ObjPtr<mirror::ObjectArray<mirror::Object>> ImageHeader::GetImageRoots() const {
Mathieu Chartier4a26f172016-01-26 14:26:18 -080039 // Need a read barrier as it's not visited during root scan.
40 // Pass in the address of the local variable to the read barrier
41 // rather than image_roots_ because it won't move (asserted below)
42 // and it's a const member.
43 mirror::ObjectArray<mirror::Object>* image_roots =
44 reinterpret_cast<mirror::ObjectArray<mirror::Object>*>(image_roots_);
45 mirror::ObjectArray<mirror::Object>* result =
46 ReadBarrier::BarrierForRoot<mirror::ObjectArray<mirror::Object>, kReadBarrierOption>(
47 &image_roots);
48 DCHECK_EQ(image_roots, result);
49 return image_roots;
50}
51
Vladimir Marko4df2d802018-09-27 16:42:44 +000052inline void ImageHeader::VisitPackedArtFields(ArtFieldVisitor* visitor, uint8_t* base) const {
53 const ImageSection& fields = GetFieldsSection();
54 for (size_t pos = 0; pos < fields.Size(); ) {
55 auto* array = reinterpret_cast<LengthPrefixedArray<ArtField>*>(base + fields.Offset() + pos);
56 for (size_t i = 0; i < array->size(); ++i) {
57 visitor->Visit(&array->At(i, sizeof(ArtField)));
58 }
59 pos += array->ComputeSize(array->size());
60 }
61}
62
63inline void ImageHeader::VisitPackedArtMethods(ArtMethodVisitor* visitor,
64 uint8_t* base,
65 PointerSize pointer_size) const {
66 const size_t method_alignment = ArtMethod::Alignment(pointer_size);
67 const size_t method_size = ArtMethod::Size(pointer_size);
68 const ImageSection& methods = GetMethodsSection();
69 for (size_t pos = 0; pos < methods.Size(); ) {
70 auto* array = reinterpret_cast<LengthPrefixedArray<ArtMethod>*>(base + methods.Offset() + pos);
71 for (size_t i = 0; i < array->size(); ++i) {
72 visitor->Visit(&array->At(i, method_size, method_alignment));
73 }
74 pos += array->ComputeSize(array->size(), method_size, method_alignment);
75 }
76 const ImageSection& runtime_methods = GetRuntimeMethodsSection();
77 for (size_t pos = 0; pos < runtime_methods.Size(); ) {
78 auto* method = reinterpret_cast<ArtMethod*>(base + runtime_methods.Offset() + pos);
79 visitor->Visit(method);
80 pos += method_size;
81 }
82}
83
Mathieu Chartiere42888f2016-04-14 10:49:19 -070084template <typename Visitor>
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +000085inline void ImageHeader::VisitPackedImTables(const Visitor& visitor,
86 uint8_t* base,
Andreas Gampe542451c2016-07-26 09:02:02 -070087 PointerSize pointer_size) const {
Vladimir Markocd87c3e2017-09-05 13:11:57 +010088 const ImageSection& section = GetImTablesSection();
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +000089 for (size_t pos = 0; pos < section.Size();) {
90 ImTable* imt = reinterpret_cast<ImTable*>(base + section.Offset() + pos);
91 for (size_t i = 0; i < ImTable::kSize; ++i) {
92 ArtMethod* orig = imt->Get(i, pointer_size);
93 ArtMethod* updated = visitor(orig);
94 if (updated != orig) {
95 imt->Set(i, updated, pointer_size);
96 }
97 }
98 pos += ImTable::SizeInBytes(pointer_size);
99 }
100}
101
102template <typename Visitor>
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700103inline void ImageHeader::VisitPackedImtConflictTables(const Visitor& visitor,
104 uint8_t* base,
Andreas Gampe542451c2016-07-26 09:02:02 -0700105 PointerSize pointer_size) const {
Vladimir Markocd87c3e2017-09-05 13:11:57 +0100106 const ImageSection& section = GetIMTConflictTablesSection();
Mathieu Chartiere42888f2016-04-14 10:49:19 -0700107 for (size_t pos = 0; pos < section.Size(); ) {
108 auto* table = reinterpret_cast<ImtConflictTable*>(base + section.Offset() + pos);
109 table->Visit([&visitor](const std::pair<ArtMethod*, ArtMethod*>& methods) {
110 return std::make_pair(visitor(methods.first), visitor(methods.second));
111 }, pointer_size);
112 pos += table->ComputeSize(pointer_size);
113 }
114}
115
Mathieu Chartier4a26f172016-01-26 14:26:18 -0800116} // namespace art
117
118#endif // ART_RUNTIME_IMAGE_INL_H_