Mathieu Chartier | 4a26f17 | 2016-01-26 14:26:18 -0800 | [diff] [blame] | 1 | /* |
| 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 Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 22 | #include "art_method.h" |
Andreas Gampe | 75a7db6 | 2016-09-26 12:04:26 -0700 | [diff] [blame] | 23 | #include "imt_conflict_table.h" |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 24 | #include "imtable.h" |
Vladimir Marko | 6834d34 | 2018-05-25 13:12:09 +0100 | [diff] [blame] | 25 | #include "mirror/object_array-inl.h" |
Vladimir Marko | c13fbd8 | 2018-06-04 16:16:28 +0100 | [diff] [blame] | 26 | #include "obj_ptr-inl.h" |
Vladimir Marko | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 27 | #include "read_barrier-inl.h" |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 28 | |
Mathieu Chartier | 4a26f17 | 2016-01-26 14:26:18 -0800 | [diff] [blame] | 29 | namespace art { |
| 30 | |
| 31 | template <ReadBarrierOption kReadBarrierOption> |
Vladimir Marko | c13fbd8 | 2018-06-04 16:16:28 +0100 | [diff] [blame] | 32 | inline ObjPtr<mirror::Object> ImageHeader::GetImageRoot(ImageRoot image_root) const { |
| 33 | ObjPtr<mirror::ObjectArray<mirror::Object>> image_roots = GetImageRoots<kReadBarrierOption>(); |
Mathieu Chartier | 4a26f17 | 2016-01-26 14:26:18 -0800 | [diff] [blame] | 34 | return image_roots->Get<kVerifyNone, kReadBarrierOption>(static_cast<int32_t>(image_root)); |
| 35 | } |
| 36 | |
| 37 | template <ReadBarrierOption kReadBarrierOption> |
Vladimir Marko | c13fbd8 | 2018-06-04 16:16:28 +0100 | [diff] [blame] | 38 | inline ObjPtr<mirror::ObjectArray<mirror::Object>> ImageHeader::GetImageRoots() const { |
Mathieu Chartier | 4a26f17 | 2016-01-26 14:26:18 -0800 | [diff] [blame] | 39 | // 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 | |
Mathieu Chartier | 9d5956a | 2019-03-22 11:29:08 -0700 | [diff] [blame] | 52 | template <typename Visitor> |
| 53 | inline void ImageHeader::VisitPackedArtFields(const Visitor& visitor, uint8_t* base) const { |
Vladimir Marko | 4df2d80 | 2018-09-27 16:42:44 +0000 | [diff] [blame] | 54 | const ImageSection& fields = GetFieldsSection(); |
Vladimir Marko | afe14eb | 2018-10-01 12:11:14 +0100 | [diff] [blame] | 55 | for (size_t pos = 0u; pos < fields.Size(); ) { |
Vladimir Marko | 4df2d80 | 2018-09-27 16:42:44 +0000 | [diff] [blame] | 56 | auto* array = reinterpret_cast<LengthPrefixedArray<ArtField>*>(base + fields.Offset() + pos); |
Vladimir Marko | afe14eb | 2018-10-01 12:11:14 +0100 | [diff] [blame] | 57 | for (size_t i = 0u; i < array->size(); ++i) { |
Mathieu Chartier | 9d5956a | 2019-03-22 11:29:08 -0700 | [diff] [blame] | 58 | visitor(array->At(i, sizeof(ArtField))); |
Vladimir Marko | 4df2d80 | 2018-09-27 16:42:44 +0000 | [diff] [blame] | 59 | } |
| 60 | pos += array->ComputeSize(array->size()); |
| 61 | } |
| 62 | } |
| 63 | |
Mathieu Chartier | 9d5956a | 2019-03-22 11:29:08 -0700 | [diff] [blame] | 64 | template <typename Visitor> |
| 65 | inline void ImageHeader::VisitPackedArtMethods(const Visitor& visitor, |
| 66 | uint8_t* base, |
| 67 | PointerSize pointer_size) const { |
Vladimir Marko | 4df2d80 | 2018-09-27 16:42:44 +0000 | [diff] [blame] | 68 | const size_t method_alignment = ArtMethod::Alignment(pointer_size); |
| 69 | const size_t method_size = ArtMethod::Size(pointer_size); |
| 70 | const ImageSection& methods = GetMethodsSection(); |
Vladimir Marko | afe14eb | 2018-10-01 12:11:14 +0100 | [diff] [blame] | 71 | for (size_t pos = 0u; pos < methods.Size(); ) { |
Vladimir Marko | 4df2d80 | 2018-09-27 16:42:44 +0000 | [diff] [blame] | 72 | auto* array = reinterpret_cast<LengthPrefixedArray<ArtMethod>*>(base + methods.Offset() + pos); |
Vladimir Marko | afe14eb | 2018-10-01 12:11:14 +0100 | [diff] [blame] | 73 | for (size_t i = 0u; i < array->size(); ++i) { |
Mathieu Chartier | 9d5956a | 2019-03-22 11:29:08 -0700 | [diff] [blame] | 74 | visitor(array->At(i, method_size, method_alignment)); |
Vladimir Marko | 4df2d80 | 2018-09-27 16:42:44 +0000 | [diff] [blame] | 75 | } |
| 76 | pos += array->ComputeSize(array->size(), method_size, method_alignment); |
| 77 | } |
| 78 | const ImageSection& runtime_methods = GetRuntimeMethodsSection(); |
Vladimir Marko | afe14eb | 2018-10-01 12:11:14 +0100 | [diff] [blame] | 79 | for (size_t pos = 0u; pos < runtime_methods.Size(); ) { |
Vladimir Marko | 4df2d80 | 2018-09-27 16:42:44 +0000 | [diff] [blame] | 80 | auto* method = reinterpret_cast<ArtMethod*>(base + runtime_methods.Offset() + pos); |
Mathieu Chartier | 9d5956a | 2019-03-22 11:29:08 -0700 | [diff] [blame] | 81 | visitor(*method); |
Vladimir Marko | 4df2d80 | 2018-09-27 16:42:44 +0000 | [diff] [blame] | 82 | pos += method_size; |
| 83 | } |
| 84 | } |
| 85 | |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 86 | template <typename Visitor> |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 87 | inline void ImageHeader::VisitPackedImTables(const Visitor& visitor, |
| 88 | uint8_t* base, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 89 | PointerSize pointer_size) const { |
Vladimir Marko | cd87c3e | 2017-09-05 13:11:57 +0100 | [diff] [blame] | 90 | const ImageSection& section = GetImTablesSection(); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 91 | for (size_t pos = 0; pos < section.Size();) { |
| 92 | ImTable* imt = reinterpret_cast<ImTable*>(base + section.Offset() + pos); |
| 93 | for (size_t i = 0; i < ImTable::kSize; ++i) { |
| 94 | ArtMethod* orig = imt->Get(i, pointer_size); |
| 95 | ArtMethod* updated = visitor(orig); |
| 96 | if (updated != orig) { |
| 97 | imt->Set(i, updated, pointer_size); |
| 98 | } |
| 99 | } |
| 100 | pos += ImTable::SizeInBytes(pointer_size); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | template <typename Visitor> |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 105 | inline void ImageHeader::VisitPackedImtConflictTables(const Visitor& visitor, |
| 106 | uint8_t* base, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 107 | PointerSize pointer_size) const { |
Vladimir Marko | cd87c3e | 2017-09-05 13:11:57 +0100 | [diff] [blame] | 108 | const ImageSection& section = GetIMTConflictTablesSection(); |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 109 | for (size_t pos = 0; pos < section.Size(); ) { |
| 110 | auto* table = reinterpret_cast<ImtConflictTable*>(base + section.Offset() + pos); |
| 111 | table->Visit([&visitor](const std::pair<ArtMethod*, ArtMethod*>& methods) { |
| 112 | return std::make_pair(visitor(methods.first), visitor(methods.second)); |
| 113 | }, pointer_size); |
| 114 | pos += table->ComputeSize(pointer_size); |
| 115 | } |
| 116 | } |
| 117 | |
Mathieu Chartier | 4a26f17 | 2016-01-26 14:26:18 -0800 | [diff] [blame] | 118 | } // namespace art |
| 119 | |
| 120 | #endif // ART_RUNTIME_IMAGE_INL_H_ |