blob: 377a3749a6a1c104dfcf3eb6d1ec2077be8e4ea9 [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
Vladimir Marko05792b92015-08-03 11:56:49 +010017#ifndef ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_
18#define ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_
Vladimir Marko20f85592015-03-19 10:07:02 +000019
Vladimir Marko09d09432015-09-08 13:47:48 +010020#include "dex_file.h"
Andreas Gampea5b09a62016-11-17 15:21:22 -080021#include "dex_file_types.h"
Vladimir Marko09d09432015-09-08 13:47:48 +010022
Vladimir Marko20f85592015-03-19 10:07:02 +000023namespace art {
24
25/**
26 * @class DexCacheArraysLayout
27 * @details This class provides the layout information for the type, method, field and
28 * string arrays for a DexCache with a fixed arrays' layout (such as in the boot image),
29 */
30class DexCacheArraysLayout {
31 public:
32 // Construct an invalid layout.
33 DexCacheArraysLayout()
34 : /* types_offset_ is always 0u */
Andreas Gampe542451c2016-07-26 09:02:02 -070035 pointer_size_(kRuntimePointerSize),
Vladimir Marko20f85592015-03-19 10:07:02 +000036 methods_offset_(0u),
37 strings_offset_(0u),
38 fields_offset_(0u),
Narayan Kamath25352fc2016-08-03 12:46:58 +010039 method_types_offset_(0u),
Orion Hodsonc069a302017-01-18 09:23:12 +000040 call_sites_offset_(0u),
Vladimir Marko20f85592015-03-19 10:07:02 +000041 size_(0u) {
42 }
43
Vladimir Marko09d09432015-09-08 13:47:48 +010044 // Construct a layout for a particular dex file header.
Orion Hodsonc069a302017-01-18 09:23:12 +000045 DexCacheArraysLayout(PointerSize pointer_size,
46 const DexFile::Header& header,
47 uint32_t num_call_sites);
Vladimir Marko09d09432015-09-08 13:47:48 +010048
Vladimir Marko20f85592015-03-19 10:07:02 +000049 // Construct a layout for a particular dex file.
Andreas Gampe542451c2016-07-26 09:02:02 -070050 DexCacheArraysLayout(PointerSize pointer_size, const DexFile* dex_file);
Vladimir Marko20f85592015-03-19 10:07:02 +000051
52 bool Valid() const {
53 return Size() != 0u;
54 }
55
56 size_t Size() const {
57 return size_;
58 }
59
Vladimir Markof44d36c2017-03-14 14:18:46 +000060 size_t Alignment() const;
61
62 static constexpr size_t Alignment(PointerSize pointer_size);
Vladimir Marko05792b92015-08-03 11:56:49 +010063
Vladimir Marko20f85592015-03-19 10:07:02 +000064 size_t TypesOffset() const {
65 return types_offset_;
66 }
67
Andreas Gampea5b09a62016-11-17 15:21:22 -080068 size_t TypeOffset(dex::TypeIndex type_idx) const;
Vladimir Marko20f85592015-03-19 10:07:02 +000069
Mathieu Chartierc7853442015-03-27 14:35:38 -070070 size_t TypesSize(size_t num_elements) const;
71
Vladimir Marko05792b92015-08-03 11:56:49 +010072 size_t TypesAlignment() const;
73
Vladimir Marko20f85592015-03-19 10:07:02 +000074 size_t MethodsOffset() const {
75 return methods_offset_;
76 }
77
78 size_t MethodOffset(uint32_t method_idx) const;
79
Mathieu Chartierc7853442015-03-27 14:35:38 -070080 size_t MethodsSize(size_t num_elements) const;
81
Vladimir Marko05792b92015-08-03 11:56:49 +010082 size_t MethodsAlignment() const;
83
Vladimir Marko20f85592015-03-19 10:07:02 +000084 size_t StringsOffset() const {
85 return strings_offset_;
86 }
87
88 size_t StringOffset(uint32_t string_idx) const;
89
Mathieu Chartierc7853442015-03-27 14:35:38 -070090 size_t StringsSize(size_t num_elements) const;
91
Vladimir Marko05792b92015-08-03 11:56:49 +010092 size_t StringsAlignment() const;
93
Vladimir Marko20f85592015-03-19 10:07:02 +000094 size_t FieldsOffset() const {
95 return fields_offset_;
96 }
97
98 size_t FieldOffset(uint32_t field_idx) const;
99
Mathieu Chartierc7853442015-03-27 14:35:38 -0700100 size_t FieldsSize(size_t num_elements) const;
101
Vladimir Marko05792b92015-08-03 11:56:49 +0100102 size_t FieldsAlignment() const;
103
Narayan Kamath25352fc2016-08-03 12:46:58 +0100104 size_t MethodTypesOffset() const {
105 return method_types_offset_;
106 }
107
Narayan Kamath25352fc2016-08-03 12:46:58 +0100108 size_t MethodTypesSize(size_t num_elements) const;
109
110 size_t MethodTypesAlignment() const;
111
Orion Hodsonc069a302017-01-18 09:23:12 +0000112 size_t CallSitesOffset() const {
113 return call_sites_offset_;
114 }
115
116 size_t CallSitesSize(size_t num_elements) const;
117
118 size_t CallSitesAlignment() const;
119
Vladimir Marko20f85592015-03-19 10:07:02 +0000120 private:
121 static constexpr size_t types_offset_ = 0u;
Andreas Gampe542451c2016-07-26 09:02:02 -0700122 const PointerSize pointer_size_; // Must be first for construction initialization order.
Vladimir Marko20f85592015-03-19 10:07:02 +0000123 const size_t methods_offset_;
124 const size_t strings_offset_;
125 const size_t fields_offset_;
Narayan Kamath25352fc2016-08-03 12:46:58 +0100126 const size_t method_types_offset_;
Orion Hodsonc069a302017-01-18 09:23:12 +0000127 const size_t call_sites_offset_;
Vladimir Marko20f85592015-03-19 10:07:02 +0000128 const size_t size_;
129
Andreas Gampe542451c2016-07-26 09:02:02 -0700130 static size_t ElementOffset(PointerSize element_size, uint32_t idx);
Vladimir Marko20f85592015-03-19 10:07:02 +0000131
Andreas Gampe542451c2016-07-26 09:02:02 -0700132 static size_t ArraySize(PointerSize element_size, uint32_t num_elements);
Vladimir Marko20f85592015-03-19 10:07:02 +0000133};
134
135} // namespace art
136
Vladimir Marko05792b92015-08-03 11:56:49 +0100137#endif // ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_