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
24namespace art {
25
26template <ReadBarrierOption kReadBarrierOption>
27inline mirror::Object* ImageHeader::GetImageRoot(ImageRoot image_root) const {
28  mirror::ObjectArray<mirror::Object>* image_roots = GetImageRoots<kReadBarrierOption>();
29  return image_roots->Get<kVerifyNone, kReadBarrierOption>(static_cast<int32_t>(image_root));
30}
31
32template <ReadBarrierOption kReadBarrierOption>
33inline mirror::ObjectArray<mirror::Object>* ImageHeader::GetImageRoots() const {
34  // Need a read barrier as it's not visited during root scan.
35  // Pass in the address of the local variable to the read barrier
36  // rather than image_roots_ because it won't move (asserted below)
37  // and it's a const member.
38  mirror::ObjectArray<mirror::Object>* image_roots =
39      reinterpret_cast<mirror::ObjectArray<mirror::Object>*>(image_roots_);
40  mirror::ObjectArray<mirror::Object>* result =
41      ReadBarrier::BarrierForRoot<mirror::ObjectArray<mirror::Object>, kReadBarrierOption>(
42          &image_roots);
43  DCHECK_EQ(image_roots, result);
44  return image_roots;
45}
46
47template <typename Visitor>
48inline void ImageHeader::VisitPackedImtConflictTables(const Visitor& visitor,
49                                                      uint8_t* base,
50                                                      size_t pointer_size) const {
51  const ImageSection& section = GetImageSection(kSectionIMTConflictTables);
52  for (size_t pos = 0; pos < section.Size(); ) {
53    auto* table = reinterpret_cast<ImtConflictTable*>(base + section.Offset() + pos);
54    table->Visit([&visitor](const std::pair<ArtMethod*, ArtMethod*>& methods) {
55      return std::make_pair(visitor(methods.first), visitor(methods.second));
56    }, pointer_size);
57    pos += table->ComputeSize(pointer_size);
58  }
59}
60
61}  // namespace art
62
63#endif  // ART_RUNTIME_IMAGE_INL_H_
64