blob: 7d02ce35d84ab4a3fc24d653d26644cc63ca3b21 [file] [log] [blame]
Vladimir Marko20f85592015-03-19 10:07:02 +00001/*
2 * Copyright (C) 2015 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_COMPILER_UTILS_DEX_CACHE_ARRAYS_LAYOUT_INL_H_
18#define ART_COMPILER_UTILS_DEX_CACHE_ARRAYS_LAYOUT_INL_H_
19
20#include "dex_cache_arrays_layout.h"
21
22#include "base/logging.h"
23#include "globals.h"
24#include "mirror/array-inl.h"
25#include "primitive.h"
26#include "utils.h"
27
28namespace mirror {
29class ArtField;
30class ArtMethod;
31class Class;
32class String;
33} // namespace mirror
34
35namespace art {
36
37inline DexCacheArraysLayout::DexCacheArraysLayout(const DexFile* dex_file)
38 : /* types_offset_ is always 0u */
39 methods_offset_(types_offset_ + ArraySize<mirror::Class>(dex_file->NumTypeIds())),
40 strings_offset_(methods_offset_ + ArraySize<mirror::ArtMethod>(dex_file->NumMethodIds())),
41 fields_offset_(strings_offset_ + ArraySize<mirror::String>(dex_file->NumStringIds())),
42 size_(fields_offset_ + ArraySize<mirror::ArtField>(dex_file->NumFieldIds())) {
43}
44
45inline size_t DexCacheArraysLayout::TypeOffset(uint32_t type_idx) const {
46 return types_offset_ + ElementOffset<mirror::Class>(type_idx);
47}
48
49inline size_t DexCacheArraysLayout::MethodOffset(uint32_t method_idx) const {
50 return methods_offset_ + ElementOffset<mirror::ArtMethod>(method_idx);
51}
52
53inline size_t DexCacheArraysLayout::StringOffset(uint32_t string_idx) const {
54 return strings_offset_ + ElementOffset<mirror::String>(string_idx);
55}
56
57inline size_t DexCacheArraysLayout::FieldOffset(uint32_t field_idx) const {
58 return fields_offset_ + ElementOffset<mirror::ArtField>(field_idx);
59}
60
61template <typename MirrorType>
62inline size_t DexCacheArraysLayout::ElementOffset(uint32_t idx) {
63 return mirror::Array::DataOffset(sizeof(mirror::HeapReference<MirrorType>)).Uint32Value() +
64 sizeof(mirror::HeapReference<MirrorType>) * idx;
65}
66
67template <typename MirrorType>
68inline size_t DexCacheArraysLayout::ArraySize(uint32_t num_elements) {
69 size_t array_size = mirror::ComputeArraySize(
70 num_elements, ComponentSizeShiftWidth<sizeof(mirror::HeapReference<MirrorType>)>());
71 DCHECK_NE(array_size, 0u); // No overflow expected for dex cache arrays.
72 return RoundUp(array_size, kObjectAlignment);
73}
74
75} // namespace art
76
77#endif // ART_COMPILER_UTILS_DEX_CACHE_ARRAYS_LAYOUT_INL_H_