blob: c44019dde351e7327ca89fe364e46af165670fd3 [file] [log] [blame]
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01001/*
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 Chartierdbddc222017-05-24 12:04:13 -070017#ifndef ART_RUNTIME_TYPE_REFERENCE_H_
18#define ART_RUNTIME_TYPE_REFERENCE_H_
Vladimir Markodbb7f5b2016-03-30 13:23:58 +010019
20#include <stdint.h>
21
22#include "base/logging.h"
Andreas Gampea5b09a62016-11-17 15:21:22 -080023#include "dex_file_types.h"
Mathieu Chartierdc00f182016-07-14 10:10:44 -070024#include "string_reference.h"
Vladimir Markodbb7f5b2016-03-30 13:23:58 +010025
26namespace art {
27
28class DexFile;
29
30// A type is located by its DexFile and the string_ids_ table index into that DexFile.
31struct TypeReference {
Mathieu Chartierdbddc222017-05-24 12:04:13 -070032 TypeReference(const DexFile* file = nullptr, dex::TypeIndex index = dex::TypeIndex())
33 : dex_file(file),
34 type_index(index) {}
Vladimir Markodbb7f5b2016-03-30 13:23:58 +010035
36 const DexFile* dex_file;
Andreas Gampea5b09a62016-11-17 15:21:22 -080037 dex::TypeIndex type_index;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +010038};
39
Mathieu Chartier2f794552017-06-19 10:58:08 -070040struct 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 Markodbb7f5b2016-03-30 13:23:58 +010049// Compare the actual referenced type names. Used for type reference deduplication.
50struct 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 Chartierdbddc222017-05-24 12:04:13 -070062#endif // ART_RUNTIME_TYPE_REFERENCE_H_