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 | |
| 22 | namespace art { |
| 23 | |
| 24 | template <ReadBarrierOption kReadBarrierOption> |
| 25 | inline mirror::Object* ImageHeader::GetImageRoot(ImageRoot image_root) const { |
| 26 | mirror::ObjectArray<mirror::Object>* image_roots = GetImageRoots<kReadBarrierOption>(); |
| 27 | return image_roots->Get<kVerifyNone, kReadBarrierOption>(static_cast<int32_t>(image_root)); |
| 28 | } |
| 29 | |
| 30 | template <ReadBarrierOption kReadBarrierOption> |
| 31 | inline mirror::ObjectArray<mirror::Object>* ImageHeader::GetImageRoots() const { |
| 32 | // Need a read barrier as it's not visited during root scan. |
| 33 | // Pass in the address of the local variable to the read barrier |
| 34 | // rather than image_roots_ because it won't move (asserted below) |
| 35 | // and it's a const member. |
| 36 | mirror::ObjectArray<mirror::Object>* image_roots = |
| 37 | reinterpret_cast<mirror::ObjectArray<mirror::Object>*>(image_roots_); |
| 38 | mirror::ObjectArray<mirror::Object>* result = |
| 39 | ReadBarrier::BarrierForRoot<mirror::ObjectArray<mirror::Object>, kReadBarrierOption>( |
| 40 | &image_roots); |
| 41 | DCHECK_EQ(image_roots, result); |
| 42 | return image_roots; |
| 43 | } |
| 44 | |
| 45 | } // namespace art |
| 46 | |
| 47 | #endif // ART_RUNTIME_IMAGE_INL_H_ |