blob: 7d4b23a8dd2f2d47dd86558b0f1dfbe9c5d693cd [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"
Andreas Gampea5b09a62016-11-17 15:21:22 -080021#include "dex_file_types.h"
Vladimir Marko09d09432015-09-08 13:47:48 +010022
Vladimir Marko20f85592015-03-19 10:07:02 +000023namespace 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 */
30class DexCacheArraysLayout {
31 public:
32 // Construct an invalid layout.
33 DexCacheArraysLayout()
34 : /* types_offset_ is always 0u */
Andreas Gampe542451c2016-07-26 09:02:02 -070035 pointer_size_(kRuntimePointerSize),
Vladimir Marko20f85592015-03-19 10:07:02 +000036 methods_offset_(0u),
37 strings_offset_(0u),
38 fields_offset_(0u),
Narayan Kamath25352fc2016-08-03 12:46:58 +010039 method_types_offset_(0u),
Vladimir Marko20f85592015-03-19 10:07:02 +000040 size_(0u) {
41 }
42
Vladimir Marko09d09432015-09-08 13:47:48 +010043 // Construct a layout for a particular dex file header.
Andreas Gampe542451c2016-07-26 09:02:02 -070044 DexCacheArraysLayout(PointerSize pointer_size, const DexFile::Header& header);
Vladimir Marko09d09432015-09-08 13:47:48 +010045
Vladimir Marko20f85592015-03-19 10:07:02 +000046 // Construct a layout for a particular dex file.
Andreas Gampe542451c2016-07-26 09:02:02 -070047 DexCacheArraysLayout(PointerSize pointer_size, const DexFile* dex_file);
Vladimir Marko20f85592015-03-19 10:07:02 +000048
49 bool Valid() const {
50 return Size() != 0u;
51 }
52
53 size_t Size() const {
54 return size_;
55 }
56
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -070057 static constexpr size_t Alignment();
Vladimir Marko05792b92015-08-03 11:56:49 +010058
Vladimir Marko20f85592015-03-19 10:07:02 +000059 size_t TypesOffset() const {
60 return types_offset_;
61 }
62
Andreas Gampea5b09a62016-11-17 15:21:22 -080063 size_t TypeOffset(dex::TypeIndex type_idx) const;
Vladimir Marko20f85592015-03-19 10:07:02 +000064
Mathieu Chartierc7853442015-03-27 14:35:38 -070065 size_t TypesSize(size_t num_elements) const;
66
Vladimir Marko05792b92015-08-03 11:56:49 +010067 size_t TypesAlignment() const;
68
Vladimir Marko20f85592015-03-19 10:07:02 +000069 size_t MethodsOffset() const {
70 return methods_offset_;
71 }
72
73 size_t MethodOffset(uint32_t method_idx) const;
74
Mathieu Chartierc7853442015-03-27 14:35:38 -070075 size_t MethodsSize(size_t num_elements) const;
76
Vladimir Marko05792b92015-08-03 11:56:49 +010077 size_t MethodsAlignment() const;
78
Vladimir Marko20f85592015-03-19 10:07:02 +000079 size_t StringsOffset() const {
80 return strings_offset_;
81 }
82
83 size_t StringOffset(uint32_t string_idx) const;
84
Mathieu Chartierc7853442015-03-27 14:35:38 -070085 size_t StringsSize(size_t num_elements) const;
86
Vladimir Marko05792b92015-08-03 11:56:49 +010087 size_t StringsAlignment() const;
88
Vladimir Marko20f85592015-03-19 10:07:02 +000089 size_t FieldsOffset() const {
90 return fields_offset_;
91 }
92
93 size_t FieldOffset(uint32_t field_idx) const;
94
Mathieu Chartierc7853442015-03-27 14:35:38 -070095 size_t FieldsSize(size_t num_elements) const;
96
Vladimir Marko05792b92015-08-03 11:56:49 +010097 size_t FieldsAlignment() const;
98
Narayan Kamath25352fc2016-08-03 12:46:58 +010099 size_t MethodTypesOffset() const {
100 return method_types_offset_;
101 }
102
Narayan Kamath25352fc2016-08-03 12:46:58 +0100103 size_t MethodTypesSize(size_t num_elements) const;
104
105 size_t MethodTypesAlignment() const;
106
Vladimir Marko20f85592015-03-19 10:07:02 +0000107 private:
108 static constexpr size_t types_offset_ = 0u;
Andreas Gampe542451c2016-07-26 09:02:02 -0700109 const PointerSize pointer_size_; // Must be first for construction initialization order.
Vladimir Marko20f85592015-03-19 10:07:02 +0000110 const size_t methods_offset_;
111 const size_t strings_offset_;
112 const size_t fields_offset_;
Narayan Kamath25352fc2016-08-03 12:46:58 +0100113 const size_t method_types_offset_;
Vladimir Marko20f85592015-03-19 10:07:02 +0000114 const size_t size_;
115
Andreas Gampe542451c2016-07-26 09:02:02 -0700116 static size_t Alignment(PointerSize pointer_size);
Vladimir Marko05792b92015-08-03 11:56:49 +0100117
Andreas Gampe542451c2016-07-26 09:02:02 -0700118 static size_t ElementOffset(PointerSize element_size, uint32_t idx);
Vladimir Marko20f85592015-03-19 10:07:02 +0000119
Andreas Gampe542451c2016-07-26 09:02:02 -0700120 static size_t ArraySize(PointerSize element_size, uint32_t num_elements);
Vladimir Marko20f85592015-03-19 10:07:02 +0000121};
122
123} // namespace art
124
Vladimir Marko05792b92015-08-03 11:56:49 +0100125#endif // ART_RUNTIME_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_