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 22 #include "art_method.h" 23 #include "imtable.h" 24 25 namespace art { 26 27 template <ReadBarrierOption kReadBarrierOption> 28 inline 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 33 template <ReadBarrierOption kReadBarrierOption> 34 inline 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 48 template <typename Visitor> 49 inline 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 66 template <typename Visitor> 67 inline 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 80 } // namespace art 81 82 #endif // ART_RUNTIME_IMAGE_INL_H_ 83