blob: ed677ed3f43c1eff1318546f364d9543f9445c2a [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
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -070060 static constexpr size_t Alignment();
Vladimir Marko05792b92015-08-03 11:56:49 +010061
Vladimir Marko20f85592015-03-19 10:07:02 +000062 size_t TypesOffset() const {
63 return types_offset_;
64 }
65
Andreas Gampea5b09a62016-11-17 15:21:22 -080066 size_t TypeOffset(dex::TypeIndex type_idx) const;
Vladimir Marko20f85592015-03-19 10:07:02 +000067
Mathieu Chartierc7853442015-03-27 14:35:38 -070068 size_t TypesSize(size_t num_elements) const;
69
Vladimir Marko05792b92015-08-03 11:56:49 +010070 size_t TypesAlignment() const;
71
Vladimir Marko20f85592015-03-19 10:07:02 +000072 size_t MethodsOffset() const {
73 return methods_offset_;
74 }
75
76 size_t MethodOffset(uint32_t method_idx) const;
77
Mathieu Chartierc7853442015-03-27 14:35:38 -070078 size_t MethodsSize(size_t num_elements) const;
79
Vladimir Marko05792b92015-08-03 11:56:49 +010080 size_t MethodsAlignment() const;
81
Vladimir Marko20f85592015-03-19 10:07:02 +000082 size_t StringsOffset() const {
83 return strings_offset_;
84 }
85
86 size_t StringOffset(uint32_t string_idx) const;
87
Mathieu Chartierc7853442015-03-27 14:35:38 -070088 size_t StringsSize(size_t num_elements) const;
89
Vladimir Marko05792b92015-08-03 11:56:49 +010090 size_t StringsAlignment() const;
91
Vladimir Marko20f85592015-03-19 10:07:02 +000092 size_t FieldsOffset() const {
93 return fields_offset_;
94 }
95
96 size_t FieldOffset(uint32_t field_idx) const;
97
Mathieu Chartierc7853442015-03-27 14:35:38 -070098 size_t FieldsSize(size_t num_elements) const;
99
Vladimir Marko05792b92015-08-03 11:56:49 +0100100 size_t FieldsAlignment() const;
101
Narayan Kamath25352fc2016-08-03 12:46:58 +0100102 size_t MethodTypesOffset() const {
103 return method_types_offset_;
104 }
105
Narayan Kamath25352fc2016-08-03 12:46:58 +0100106 size_t MethodTypesSize(size_t num_elements) const;
107
108 size_t MethodTypesAlignment() const;
109
Orion Hodsonc069a302017-01-18 09:23:12 +0000110 size_t CallSitesOffset() const {
111 return call_sites_offset_;
112 }
113
114 size_t CallSitesSize(size_t num_elements) const;
115
116 size_t CallSitesAlignment() const;
117
Vladimir Marko20f85592015-03-19 10:07:02 +0000118 private:
119 static constexpr size_t types_offset_ = 0u;
Andreas Gampe542451c2016-07-26 09:02:02 -0700120 const PointerSize pointer_size_; // Must be first for construction initialization order.
Vladimir Marko20f85592015-03-19 10:07:02 +0000121 const size_t methods_offset_;
122 const size_t strings_offset_;
123 const size_t fields_offset_;
Narayan Kamath25352fc2016-08-03 12:46:58 +0100124 const size_t method_types_offset_;
Orion Hodsonc069a302017-01-18 09:23:12 +0000125 const size_t call_sites_offset_;
Vladimir Marko20f85592015-03-19 10:07:02 +0000126 const size_t size_;
127
Andreas Gampe542451c2016-07-26 09:02:02 -0700128 static size_t Alignment(PointerSize pointer_size);
Vladimir Marko05792b92015-08-03 11:56:49 +0100129
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_