Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 1 | /* |
| 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 Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_ |
| 18 | #define ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_ |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 19 | |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 20 | #include "dex/dex_file.h" |
| 21 | #include "dex/dex_file_types.h" |
Vladimir Marko | 09d0943 | 2015-09-08 13:47:48 +0100 | [diff] [blame] | 22 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 23 | namespace 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 | */ |
| 30 | class DexCacheArraysLayout { |
| 31 | public: |
| 32 | // Construct an invalid layout. |
| 33 | DexCacheArraysLayout() |
| 34 | : /* types_offset_ is always 0u */ |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 35 | pointer_size_(kRuntimePointerSize), |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 36 | methods_offset_(0u), |
| 37 | strings_offset_(0u), |
| 38 | fields_offset_(0u), |
Narayan Kamath | 25352fc | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 39 | method_types_offset_(0u), |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 40 | call_sites_offset_(0u), |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 41 | size_(0u) { |
| 42 | } |
| 43 | |
Vladimir Marko | 09d0943 | 2015-09-08 13:47:48 +0100 | [diff] [blame] | 44 | // Construct a layout for a particular dex file header. |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 45 | DexCacheArraysLayout(PointerSize pointer_size, |
| 46 | const DexFile::Header& header, |
| 47 | uint32_t num_call_sites); |
Vladimir Marko | 09d0943 | 2015-09-08 13:47:48 +0100 | [diff] [blame] | 48 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 49 | // Construct a layout for a particular dex file. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 50 | DexCacheArraysLayout(PointerSize pointer_size, const DexFile* dex_file); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 51 | |
| 52 | bool Valid() const { |
| 53 | return Size() != 0u; |
| 54 | } |
| 55 | |
| 56 | size_t Size() const { |
| 57 | return size_; |
| 58 | } |
| 59 | |
Vladimir Marko | f44d36c | 2017-03-14 14:18:46 +0000 | [diff] [blame] | 60 | size_t Alignment() const; |
| 61 | |
| 62 | static constexpr size_t Alignment(PointerSize pointer_size); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 63 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 64 | size_t TypesOffset() const { |
| 65 | return types_offset_; |
| 66 | } |
| 67 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 68 | size_t TypeOffset(dex::TypeIndex type_idx) const; |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 69 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 70 | size_t TypesSize(size_t num_elements) const; |
| 71 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 72 | size_t TypesAlignment() const; |
| 73 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 74 | size_t MethodsOffset() const { |
| 75 | return methods_offset_; |
| 76 | } |
| 77 | |
| 78 | size_t MethodOffset(uint32_t method_idx) const; |
| 79 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 80 | size_t MethodsSize(size_t num_elements) const; |
| 81 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 82 | size_t MethodsAlignment() const; |
| 83 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 84 | size_t StringsOffset() const { |
| 85 | return strings_offset_; |
| 86 | } |
| 87 | |
| 88 | size_t StringOffset(uint32_t string_idx) const; |
| 89 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 90 | size_t StringsSize(size_t num_elements) const; |
| 91 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 92 | size_t StringsAlignment() const; |
| 93 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 94 | size_t FieldsOffset() const { |
| 95 | return fields_offset_; |
| 96 | } |
| 97 | |
| 98 | size_t FieldOffset(uint32_t field_idx) const; |
| 99 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 100 | size_t FieldsSize(size_t num_elements) const; |
| 101 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 102 | size_t FieldsAlignment() const; |
| 103 | |
Narayan Kamath | 25352fc | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 104 | size_t MethodTypesOffset() const { |
| 105 | return method_types_offset_; |
| 106 | } |
| 107 | |
Narayan Kamath | 25352fc | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 108 | size_t MethodTypesSize(size_t num_elements) const; |
| 109 | |
| 110 | size_t MethodTypesAlignment() const; |
| 111 | |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 112 | 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 Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 120 | private: |
| 121 | static constexpr size_t types_offset_ = 0u; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 122 | const PointerSize pointer_size_; // Must be first for construction initialization order. |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 123 | const size_t methods_offset_; |
| 124 | const size_t strings_offset_; |
| 125 | const size_t fields_offset_; |
Narayan Kamath | 25352fc | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 126 | const size_t method_types_offset_; |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 127 | const size_t call_sites_offset_; |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 128 | const size_t size_; |
| 129 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 130 | static size_t ElementOffset(PointerSize element_size, uint32_t idx); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 131 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 132 | static size_t ArraySize(PointerSize element_size, uint32_t num_elements); |
Vladimir Marko | 07bfbac | 2017-07-06 14:55:02 +0100 | [diff] [blame] | 133 | static size_t PairArraySize(PointerSize element_size, uint32_t num_elements); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | } // namespace art |
| 137 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 138 | #endif // ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_ |