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 | |
| 17 | #ifndef ART_COMPILER_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_ |
| 18 | #define ART_COMPILER_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_ |
| 19 | |
| 20 | namespace 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 | */ |
| 27 | class DexCacheArraysLayout { |
| 28 | public: |
| 29 | // Construct an invalid layout. |
| 30 | DexCacheArraysLayout() |
| 31 | : /* types_offset_ is always 0u */ |
| 32 | methods_offset_(0u), |
| 33 | strings_offset_(0u), |
| 34 | fields_offset_(0u), |
| 35 | size_(0u) { |
| 36 | } |
| 37 | |
| 38 | // Construct a layout for a particular dex file. |
| 39 | explicit DexCacheArraysLayout(const DexFile* dex_file); |
| 40 | |
| 41 | bool Valid() const { |
| 42 | return Size() != 0u; |
| 43 | } |
| 44 | |
| 45 | size_t Size() const { |
| 46 | return size_; |
| 47 | } |
| 48 | |
| 49 | size_t TypesOffset() const { |
| 50 | return types_offset_; |
| 51 | } |
| 52 | |
| 53 | size_t TypeOffset(uint32_t type_idx) const; |
| 54 | |
| 55 | size_t MethodsOffset() const { |
| 56 | return methods_offset_; |
| 57 | } |
| 58 | |
| 59 | size_t MethodOffset(uint32_t method_idx) const; |
| 60 | |
| 61 | size_t StringsOffset() const { |
| 62 | return strings_offset_; |
| 63 | } |
| 64 | |
| 65 | size_t StringOffset(uint32_t string_idx) const; |
| 66 | |
| 67 | size_t FieldsOffset() const { |
| 68 | return fields_offset_; |
| 69 | } |
| 70 | |
| 71 | size_t FieldOffset(uint32_t field_idx) const; |
| 72 | |
| 73 | private: |
| 74 | static constexpr size_t types_offset_ = 0u; |
| 75 | const size_t methods_offset_; |
| 76 | const size_t strings_offset_; |
| 77 | const size_t fields_offset_; |
| 78 | const size_t size_; |
| 79 | |
| 80 | template <typename MirrorType> |
| 81 | static size_t ElementOffset(uint32_t idx); |
| 82 | |
| 83 | template <typename MirrorType> |
| 84 | static size_t ArraySize(uint32_t num_elements); |
| 85 | }; |
| 86 | |
| 87 | } // namespace art |
| 88 | |
| 89 | #endif // ART_COMPILER_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_ |