Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Mathieu Chartier | dbddc22 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_TYPE_REFERENCE_H_ |
| 18 | #define ART_RUNTIME_TYPE_REFERENCE_H_ |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include "base/logging.h" |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 23 | #include "dex_file_types.h" |
Mathieu Chartier | dc00f18 | 2016-07-14 10:10:44 -0700 | [diff] [blame] | 24 | #include "string_reference.h" |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 25 | |
| 26 | namespace art { |
| 27 | |
| 28 | class DexFile; |
| 29 | |
| 30 | // A type is located by its DexFile and the string_ids_ table index into that DexFile. |
| 31 | struct TypeReference { |
Mathieu Chartier | dbddc22 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 32 | TypeReference(const DexFile* file = nullptr, dex::TypeIndex index = dex::TypeIndex()) |
| 33 | : dex_file(file), |
| 34 | type_index(index) {} |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 35 | |
| 36 | const DexFile* dex_file; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 37 | dex::TypeIndex type_index; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 38 | }; |
| 39 | |
Mathieu Chartier | 2f79455 | 2017-06-19 10:58:08 -0700 | [diff] [blame] | 40 | struct TypeReferenceComparator { |
| 41 | bool operator()(TypeReference mr1, TypeReference mr2) const { |
| 42 | if (mr1.dex_file != mr2.dex_file) { |
| 43 | return mr1.dex_file < mr2.dex_file; |
| 44 | } |
| 45 | return mr1.type_index < mr2.type_index; |
| 46 | } |
| 47 | }; |
| 48 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 49 | // Compare the actual referenced type names. Used for type reference deduplication. |
| 50 | struct TypeReferenceValueComparator { |
| 51 | bool operator()(TypeReference tr1, TypeReference tr2) const { |
| 52 | // Note that we want to deduplicate identical boot image types even if they are |
| 53 | // referenced by different dex files, so we simply compare the descriptors. |
| 54 | StringReference sr1(tr1.dex_file, tr1.dex_file->GetTypeId(tr1.type_index).descriptor_idx_); |
| 55 | StringReference sr2(tr2.dex_file, tr2.dex_file->GetTypeId(tr2.type_index).descriptor_idx_); |
| 56 | return StringReferenceValueComparator()(sr1, sr2); |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | } // namespace art |
| 61 | |
Mathieu Chartier | dbddc22 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 62 | #endif // ART_RUNTIME_TYPE_REFERENCE_H_ |