blob: d50be5ac03e8db41b30076eca470282dd832d75b [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
20namespace art {
21
22/**
23 * @class DexCacheArraysLayout
24 * @details This class provides the layout information for the type, method, field and
25 * string arrays for a DexCache with a fixed arrays' layout (such as in the boot image),
26 */
27class DexCacheArraysLayout {
28 public:
29 // Construct an invalid layout.
30 DexCacheArraysLayout()
31 : /* types_offset_ is always 0u */
Mathieu Chartierc7853442015-03-27 14:35:38 -070032 pointer_size_(0u),
Vladimir Marko20f85592015-03-19 10:07:02 +000033 methods_offset_(0u),
34 strings_offset_(0u),
35 fields_offset_(0u),
36 size_(0u) {
37 }
38
39 // Construct a layout for a particular dex file.
Roland Levillain3887c462015-08-12 18:15:42 +010040 DexCacheArraysLayout(size_t pointer_size, const DexFile* dex_file);
Vladimir Marko20f85592015-03-19 10:07:02 +000041
42 bool Valid() const {
43 return Size() != 0u;
44 }
45
46 size_t Size() const {
47 return size_;
48 }
49
Vladimir Marko05792b92015-08-03 11:56:49 +010050 size_t Alignment() const;
51
Vladimir Marko20f85592015-03-19 10:07:02 +000052 size_t TypesOffset() const {
53 return types_offset_;
54 }
55
56 size_t TypeOffset(uint32_t type_idx) const;
57
Mathieu Chartierc7853442015-03-27 14:35:38 -070058 size_t TypesSize(size_t num_elements) const;
59
Vladimir Marko05792b92015-08-03 11:56:49 +010060 size_t TypesAlignment() const;
61
Vladimir Marko20f85592015-03-19 10:07:02 +000062 size_t MethodsOffset() const {
63 return methods_offset_;
64 }
65
66 size_t MethodOffset(uint32_t method_idx) const;
67
Mathieu Chartierc7853442015-03-27 14:35:38 -070068 size_t MethodsSize(size_t num_elements) const;
69
Vladimir Marko05792b92015-08-03 11:56:49 +010070 size_t MethodsAlignment() const;
71
Vladimir Marko20f85592015-03-19 10:07:02 +000072 size_t StringsOffset() const {
73 return strings_offset_;
74 }
75
76 size_t StringOffset(uint32_t string_idx) const;
77
Mathieu Chartierc7853442015-03-27 14:35:38 -070078 size_t StringsSize(size_t num_elements) const;
79
Vladimir Marko05792b92015-08-03 11:56:49 +010080 size_t StringsAlignment() const;
81
Vladimir Marko20f85592015-03-19 10:07:02 +000082 size_t FieldsOffset() const {
83 return fields_offset_;
84 }
85
86 size_t FieldOffset(uint32_t field_idx) const;
87
Mathieu Chartierc7853442015-03-27 14:35:38 -070088 size_t FieldsSize(size_t num_elements) const;
89
Vladimir Marko05792b92015-08-03 11:56:49 +010090 size_t FieldsAlignment() const;
91
Vladimir Marko20f85592015-03-19 10:07:02 +000092 private:
93 static constexpr size_t types_offset_ = 0u;
Mathieu Chartierc7853442015-03-27 14:35:38 -070094 const size_t pointer_size_; // Must be first for construction initialization order.
Vladimir Marko20f85592015-03-19 10:07:02 +000095 const size_t methods_offset_;
96 const size_t strings_offset_;
97 const size_t fields_offset_;
98 const size_t size_;
99
Vladimir Marko05792b92015-08-03 11:56:49 +0100100 static size_t Alignment(size_t pointer_size);
101
Mathieu Chartierc7853442015-03-27 14:35:38 -0700102 static size_t ElementOffset(size_t element_size, uint32_t idx);
Vladimir Marko20f85592015-03-19 10:07:02 +0000103
Mathieu Chartierc7853442015-03-27 14:35:38 -0700104 static size_t ArraySize(size_t element_size, uint32_t num_elements);
Vladimir Marko20f85592015-03-19 10:07:02 +0000105};
106
107} // namespace art
108
Vladimir Marko05792b92015-08-03 11:56:49 +0100109#endif // ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_