blob: 0febbedf03651e6f336369b3a5137e1f66450a0f [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
24namespace art {
25
26// Data structure for passing around which classes belonging to a dex cache / dex file are resolved.
27class DexCacheResolvedClasses {
28 public:
Mathieu Chartier9275af62016-04-29 12:03:56 -070029 DexCacheResolvedClasses(const std::string& dex_location,
30 const std::string& base_location,
31 uint32_t location_checksum)
Mathieu Chartier8913fc12015-12-09 16:38:30 -080032 : dex_location_(dex_location),
Mathieu Chartier9275af62016-04-29 12:03:56 -070033 base_location_(base_location),
Mathieu Chartier8913fc12015-12-09 16:38:30 -080034 location_checksum_(location_checksum) {}
35
36 // Only compare the key elements, ignore the resolved classes.
37 int Compare(const DexCacheResolvedClasses& other) const {
38 if (location_checksum_ != other.location_checksum_) {
39 return static_cast<int>(location_checksum_ - other.location_checksum_);
40 }
Mathieu Chartier9275af62016-04-29 12:03:56 -070041 // Don't need to compare base_location_ since dex_location_ has more info.
Mathieu Chartier8913fc12015-12-09 16:38:30 -080042 return dex_location_.compare(other.dex_location_);
43 }
44
45 template <class InputIt>
46 void AddClasses(InputIt begin, InputIt end) const {
47 classes_.insert(begin, end);
48 }
49
50 const std::string& GetDexLocation() const {
51 return dex_location_;
52 }
53
Mathieu Chartier9275af62016-04-29 12:03:56 -070054 const std::string& GetBaseLocation() const {
55 return base_location_;
56 }
57
Mathieu Chartier8913fc12015-12-09 16:38:30 -080058 uint32_t GetLocationChecksum() const {
59 return location_checksum_;
60 }
61
62 const std::unordered_set<uint16_t>& GetClasses() const {
63 return classes_;
64 }
65
66 private:
67 const std::string dex_location_;
Mathieu Chartier9275af62016-04-29 12:03:56 -070068 const std::string base_location_;
Mathieu Chartier8913fc12015-12-09 16:38:30 -080069 const uint32_t location_checksum_;
70 // Array of resolved class def indexes.
71 mutable std::unordered_set<uint16_t> classes_;
72};
73
74inline bool operator<(const DexCacheResolvedClasses& a, const DexCacheResolvedClasses& b) {
75 return a.Compare(b) < 0;
76}
77
78} // namespace art
79
80#endif // ART_RUNTIME_DEX_CACHE_RESOLVED_CLASSES_H_