blob: bebdf0dbfe5d11029a35d40a6e33e598d0c47992 [file] [log] [blame]
Mathieu Chartier8913fc12015-12-09 16:38:30 -08001/*
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_DEX_CACHE_RESOLVED_CLASSES_H_
18#define ART_RUNTIME_DEX_CACHE_RESOLVED_CLASSES_H_
19
20#include <string>
21#include <unordered_set>
22#include <vector>
23
Andreas Gampea5b09a62016-11-17 15:21:22 -080024#include "dex_file_types.h"
25
Mathieu Chartier8913fc12015-12-09 16:38:30 -080026namespace art {
27
28// Data structure for passing around which classes belonging to a dex cache / dex file are resolved.
29class DexCacheResolvedClasses {
30 public:
Mathieu Chartier9275af62016-04-29 12:03:56 -070031 DexCacheResolvedClasses(const std::string& dex_location,
32 const std::string& base_location,
33 uint32_t location_checksum)
Mathieu Chartier8913fc12015-12-09 16:38:30 -080034 : dex_location_(dex_location),
Mathieu Chartier9275af62016-04-29 12:03:56 -070035 base_location_(base_location),
Mathieu Chartier8913fc12015-12-09 16:38:30 -080036 location_checksum_(location_checksum) {}
37
38 // Only compare the key elements, ignore the resolved classes.
39 int Compare(const DexCacheResolvedClasses& other) const {
40 if (location_checksum_ != other.location_checksum_) {
41 return static_cast<int>(location_checksum_ - other.location_checksum_);
42 }
Mathieu Chartier9275af62016-04-29 12:03:56 -070043 // Don't need to compare base_location_ since dex_location_ has more info.
Mathieu Chartier8913fc12015-12-09 16:38:30 -080044 return dex_location_.compare(other.dex_location_);
45 }
46
Vladimir Marko21300532017-01-24 18:06:55 +000047 bool AddClass(dex::TypeIndex index) const {
48 return classes_.insert(index).second;
49 }
50
Mathieu Chartier8913fc12015-12-09 16:38:30 -080051 template <class InputIt>
52 void AddClasses(InputIt begin, InputIt end) const {
53 classes_.insert(begin, end);
54 }
55
56 const std::string& GetDexLocation() const {
57 return dex_location_;
58 }
59
Mathieu Chartier9275af62016-04-29 12:03:56 -070060 const std::string& GetBaseLocation() const {
61 return base_location_;
62 }
63
Mathieu Chartier8913fc12015-12-09 16:38:30 -080064 uint32_t GetLocationChecksum() const {
65 return location_checksum_;
66 }
67
Andreas Gampea5b09a62016-11-17 15:21:22 -080068 const std::unordered_set<dex::TypeIndex>& GetClasses() const {
Mathieu Chartier8913fc12015-12-09 16:38:30 -080069 return classes_;
70 }
71
72 private:
73 const std::string dex_location_;
Mathieu Chartier9275af62016-04-29 12:03:56 -070074 const std::string base_location_;
Mathieu Chartier8913fc12015-12-09 16:38:30 -080075 const uint32_t location_checksum_;
76 // Array of resolved class def indexes.
Andreas Gampea5b09a62016-11-17 15:21:22 -080077 mutable std::unordered_set<dex::TypeIndex> classes_;
Mathieu Chartier8913fc12015-12-09 16:38:30 -080078};
79
80inline bool operator<(const DexCacheResolvedClasses& a, const DexCacheResolvedClasses& b) {
81 return a.Compare(b) < 0;
82}
83
84} // namespace art
85
86#endif // ART_RUNTIME_DEX_CACHE_RESOLVED_CLASSES_H_