blob: 8f98ea11ba475c95345629b6be7f5584fd0f7cb5 [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
17#ifndef ART_COMPILER_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_
18#define ART_COMPILER_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_
19
20namespace 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 */
27class DexCacheArraysLayout {
28 public:
29 // Construct an invalid layout.
30 DexCacheArraysLayout()
31 : /* types_offset_ is always 0u */
Mathieu Chartierc7853442015-03-27 14:35:38 -070032 pointer_size_(0u),
Vladimir Marko20f85592015-03-19 10:07:02 +000033 methods_offset_(0u),
34 strings_offset_(0u),
35 fields_offset_(0u),
36 size_(0u) {
37 }
38
39 // Construct a layout for a particular dex file.
Mathieu Chartierc7853442015-03-27 14:35:38 -070040 explicit DexCacheArraysLayout(size_t pointer_size, const DexFile* dex_file);
Vladimir Marko20f85592015-03-19 10:07:02 +000041
42 bool Valid() const {
43 return Size() != 0u;
44 }
45
46 size_t Size() const {
47 return size_;
48 }
49
50 size_t TypesOffset() const {
51 return types_offset_;
52 }
53
54 size_t TypeOffset(uint32_t type_idx) const;
55
Mathieu Chartierc7853442015-03-27 14:35:38 -070056 size_t TypesSize(size_t num_elements) const;
57
Vladimir Marko20f85592015-03-19 10:07:02 +000058 size_t MethodsOffset() const {
59 return methods_offset_;
60 }
61
62 size_t MethodOffset(uint32_t method_idx) const;
63
Mathieu Chartierc7853442015-03-27 14:35:38 -070064 size_t MethodsSize(size_t num_elements) const;
65
Vladimir Marko20f85592015-03-19 10:07:02 +000066 size_t StringsOffset() const {
67 return strings_offset_;
68 }
69
70 size_t StringOffset(uint32_t string_idx) const;
71
Mathieu Chartierc7853442015-03-27 14:35:38 -070072 size_t StringsSize(size_t num_elements) const;
73
Vladimir Marko20f85592015-03-19 10:07:02 +000074 size_t FieldsOffset() const {
75 return fields_offset_;
76 }
77
78 size_t FieldOffset(uint32_t field_idx) const;
79
Mathieu Chartierc7853442015-03-27 14:35:38 -070080 size_t FieldsSize(size_t num_elements) const;
81
Vladimir Marko20f85592015-03-19 10:07:02 +000082 private:
83 static constexpr size_t types_offset_ = 0u;
Mathieu Chartierc7853442015-03-27 14:35:38 -070084 const size_t pointer_size_; // Must be first for construction initialization order.
Vladimir Marko20f85592015-03-19 10:07:02 +000085 const size_t methods_offset_;
86 const size_t strings_offset_;
87 const size_t fields_offset_;
88 const size_t size_;
89
Mathieu Chartierc7853442015-03-27 14:35:38 -070090 static size_t ElementOffset(size_t element_size, uint32_t idx);
Vladimir Marko20f85592015-03-19 10:07:02 +000091
Mathieu Chartierc7853442015-03-27 14:35:38 -070092 static size_t ArraySize(size_t element_size, uint32_t num_elements);
Vladimir Marko20f85592015-03-19 10:07:02 +000093};
94
95} // namespace art
96
97#endif // ART_COMPILER_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_