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 | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 25 | #include "read_barrier-inl.h" |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 26 | |
Mathieu Chartier | 4a26f17 | 2016-01-26 14:26:18 -0800 | [diff] [blame] | 27 | namespace art { |
| 28 | |
| 29 | template <ReadBarrierOption kReadBarrierOption> |
| 30 | inline 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 | |
| 35 | template <ReadBarrierOption kReadBarrierOption> |
| 36 | inline 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 Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 50 | template <typename Visitor> |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 51 | inline void ImageHeader::VisitPackedImTables(const Visitor& visitor, |
| 52 | uint8_t* base, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 53 | PointerSize pointer_size) const { |
Vladimir Marko | cd87c3e | 2017-09-05 13:11:57 +0100 | [diff] [blame] | 54 | const ImageSection& section = GetImTablesSection(); |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 55 | 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 | |
| 68 | template <typename Visitor> |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 69 | inline void ImageHeader::VisitPackedImtConflictTables(const Visitor& visitor, |
| 70 | uint8_t* base, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 71 | PointerSize pointer_size) const { |
Vladimir Marko | cd87c3e | 2017-09-05 13:11:57 +0100 | [diff] [blame] | 72 | const ImageSection& section = GetIMTConflictTablesSection(); |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 73 | 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 Chartier | 4a26f17 | 2016-01-26 14:26:18 -0800 | [diff] [blame] | 82 | } // namespace art |
| 83 | |
| 84 | #endif // ART_RUNTIME_IMAGE_INL_H_ |