blob: e222b46ef7c3225e818b2fa5b09dc46bbd1eb40b [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"
21
Vladimir Marko20f85592015-03-19 10:07:02 +000022namespace 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 */
29class DexCacheArraysLayout {
30 public:
31 // Construct an invalid layout.
32 DexCacheArraysLayout()
33 : /* types_offset_ is always 0u */
Andreas Gampe542451c2016-07-26 09:02:02 -070034 pointer_size_(kRuntimePointerSize),
Vladimir Marko20f85592015-03-19 10:07:02 +000035 methods_offset_(0u),
36 strings_offset_(0u),
37 fields_offset_(0u),
Narayan Kamath25352fc2016-08-03 12:46:58 +010038 method_types_offset_(0u),
Vladimir Marko20f85592015-03-19 10:07:02 +000039 size_(0u) {
40 }
41
Vladimir Marko09d09432015-09-08 13:47:48 +010042 // Construct a layout for a particular dex file header.
Andreas Gampe542451c2016-07-26 09:02:02 -070043 DexCacheArraysLayout(PointerSize pointer_size, const DexFile::Header& header);
Vladimir Marko09d09432015-09-08 13:47:48 +010044
Vladimir Marko20f85592015-03-19 10:07:02 +000045 // Construct a layout for a particular dex file.
Andreas Gampe542451c2016-07-26 09:02:02 -070046 DexCacheArraysLayout(PointerSize pointer_size, const DexFile* dex_file);
Vladimir Marko20f85592015-03-19 10:07:02 +000047
48 bool Valid() const {
49 return Size() != 0u;
50 }
51
52 size_t Size() const {
53 return size_;
54 }
55
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -070056 static constexpr size_t Alignment();
Vladimir Marko05792b92015-08-03 11:56:49 +010057
Vladimir Marko20f85592015-03-19 10:07:02 +000058 size_t TypesOffset() const {
59 return types_offset_;
60 }
61
62 size_t TypeOffset(uint32_t type_idx) const;
63
Mathieu Chartierc7853442015-03-27 14:35:38 -070064 size_t TypesSize(size_t num_elements) const;
65
Vladimir Marko05792b92015-08-03 11:56:49 +010066 size_t TypesAlignment() const;
67
Vladimir Marko20f85592015-03-19 10:07:02 +000068 size_t MethodsOffset() const {
69 return methods_offset_;
70 }
71
72 size_t MethodOffset(uint32_t method_idx) const;
73
Mathieu Chartierc7853442015-03-27 14:35:38 -070074 size_t MethodsSize(size_t num_elements) const;
75
Vladimir Marko05792b92015-08-03 11:56:49 +010076 size_t MethodsAlignment() const;
77
Vladimir Marko20f85592015-03-19 10:07:02 +000078 size_t StringsOffset() const {
79 return strings_offset_;
80 }
81
82 size_t StringOffset(uint32_t string_idx) const;
83
Mathieu Chartierc7853442015-03-27 14:35:38 -070084 size_t StringsSize(size_t num_elements) const;
85
Vladimir Marko05792b92015-08-03 11:56:49 +010086 size_t StringsAlignment() const;
87
Vladimir Marko20f85592015-03-19 10:07:02 +000088 size_t FieldsOffset() const {
89 return fields_offset_;
90 }
91
92 size_t FieldOffset(uint32_t field_idx) const;
93
Mathieu Chartierc7853442015-03-27 14:35:38 -070094 size_t FieldsSize(size_t num_elements) const;
95
Vladimir Marko05792b92015-08-03 11:56:49 +010096 size_t FieldsAlignment() const;
97
Narayan Kamath25352fc2016-08-03 12:46:58 +010098 size_t MethodTypesOffset() const {
99 return method_types_offset_;
100 }
101
102 size_t MethodTypeOffset(uint32_t method_type_idx) const;
103
104 size_t MethodTypesSize(size_t num_elements) const;
105
106 size_t MethodTypesAlignment() const;
107
Vladimir Marko20f85592015-03-19 10:07:02 +0000108 private:
109 static constexpr size_t types_offset_ = 0u;
Andreas Gampe542451c2016-07-26 09:02:02 -0700110 const PointerSize pointer_size_; // Must be first for construction initialization order.
Vladimir Marko20f85592015-03-19 10:07:02 +0000111 const size_t methods_offset_;
112 const size_t strings_offset_;
113 const size_t fields_offset_;
Narayan Kamath25352fc2016-08-03 12:46:58 +0100114 const size_t method_types_offset_;
Vladimir Marko20f85592015-03-19 10:07:02 +0000115 const size_t size_;
116
Andreas Gampe542451c2016-07-26 09:02:02 -0700117 static size_t Alignment(PointerSize pointer_size);
Vladimir Marko05792b92015-08-03 11:56:49 +0100118
Andreas Gampe542451c2016-07-26 09:02:02 -0700119 static size_t ElementOffset(PointerSize element_size, uint32_t idx);
Vladimir Marko20f85592015-03-19 10:07:02 +0000120
Andreas Gampe542451c2016-07-26 09:02:02 -0700121 static size_t ArraySize(PointerSize element_size, uint32_t num_elements);
Vladimir Marko20f85592015-03-19 10:07:02 +0000122};
123
124} // namespace art
125
Vladimir Marko05792b92015-08-03 11:56:49 +0100126#endif // ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_