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 17 #ifndef ART_RUNTIME_TYPE_REFERENCE_H_ 18 #define ART_RUNTIME_TYPE_REFERENCE_H_ 19 20 #include <stdint.h> 21 22 #include "base/logging.h" 23 #include "dex_file_types.h" 24 #include "string_reference.h" 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 { 32 TypeReference(const DexFile* file = nullptr, dex::TypeIndex index = dex::TypeIndex()) 33 : dex_file(file), 34 type_index(index) {} 35 36 const DexFile* dex_file; 37 dex::TypeIndex type_index; 38 }; 39 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 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 62 #endif // ART_RUNTIME_TYPE_REFERENCE_H_ 63