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 | |
Vladimir Marko | 09d0943 | 2015-09-08 13:47:48 +0100 | [diff] [blame] | 20 | #include "dex_file.h" |
| 21 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 22 | namespace art { |
| 23 | |
| 24 | /** |
| 25 | * @class DexCacheArraysLayout |
| 26 | * @details This class provides the layout information for the type, method, field and |
| 27 | * string arrays for a DexCache with a fixed arrays' layout (such as in the boot image), |
| 28 | */ |
| 29 | class DexCacheArraysLayout { |
| 30 | public: |
| 31 | // Construct an invalid layout. |
| 32 | DexCacheArraysLayout() |
| 33 | : /* types_offset_ is always 0u */ |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 34 | pointer_size_(kRuntimePointerSize), |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 35 | methods_offset_(0u), |
| 36 | strings_offset_(0u), |
| 37 | fields_offset_(0u), |
| 38 | size_(0u) { |
| 39 | } |
| 40 | |
Vladimir Marko | 09d0943 | 2015-09-08 13:47:48 +0100 | [diff] [blame] | 41 | // Construct a layout for a particular dex file header. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 42 | DexCacheArraysLayout(PointerSize pointer_size, const DexFile::Header& header); |
Vladimir Marko | 09d0943 | 2015-09-08 13:47:48 +0100 | [diff] [blame] | 43 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 44 | // Construct a layout for a particular dex file. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 45 | DexCacheArraysLayout(PointerSize pointer_size, const DexFile* dex_file); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 46 | |
| 47 | bool Valid() const { |
| 48 | return Size() != 0u; |
| 49 | } |
| 50 | |
| 51 | size_t Size() const { |
| 52 | return size_; |
| 53 | } |
| 54 | |
Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 55 | static constexpr size_t Alignment(); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 56 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 57 | size_t TypesOffset() const { |
| 58 | return types_offset_; |
| 59 | } |
| 60 | |
| 61 | size_t TypeOffset(uint32_t type_idx) const; |
| 62 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 63 | size_t TypesSize(size_t num_elements) const; |
| 64 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 65 | size_t TypesAlignment() const; |
| 66 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 67 | size_t MethodsOffset() const { |
| 68 | return methods_offset_; |
| 69 | } |
| 70 | |
| 71 | size_t MethodOffset(uint32_t method_idx) const; |
| 72 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 73 | size_t MethodsSize(size_t num_elements) const; |
| 74 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 75 | size_t MethodsAlignment() const; |
| 76 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 77 | size_t StringsOffset() const { |
| 78 | return strings_offset_; |
| 79 | } |
| 80 | |
| 81 | size_t StringOffset(uint32_t string_idx) const; |
| 82 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 83 | size_t StringsSize(size_t num_elements) const; |
| 84 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 85 | size_t StringsAlignment() const; |
| 86 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 87 | size_t FieldsOffset() const { |
| 88 | return fields_offset_; |
| 89 | } |
| 90 | |
| 91 | size_t FieldOffset(uint32_t field_idx) const; |
| 92 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 93 | size_t FieldsSize(size_t num_elements) const; |
| 94 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 95 | size_t FieldsAlignment() const; |
| 96 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 97 | private: |
| 98 | static constexpr size_t types_offset_ = 0u; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 99 | const PointerSize pointer_size_; // Must be first for construction initialization order. |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 100 | const size_t methods_offset_; |
| 101 | const size_t strings_offset_; |
| 102 | const size_t fields_offset_; |
| 103 | const size_t size_; |
| 104 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 105 | static size_t Alignment(PointerSize pointer_size); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 106 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 107 | static size_t ElementOffset(PointerSize element_size, uint32_t idx); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 108 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 109 | static size_t ArraySize(PointerSize element_size, uint32_t num_elements); |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | } // namespace art |
| 113 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 114 | #endif // ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_ |