blob: 80c12cb6427b766215f859b2bb0aa448ed99b190 [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:
29 DexCacheResolvedClasses(const std::string& dex_location, uint32_t location_checksum)
30 : dex_location_(dex_location),
31 location_checksum_(location_checksum) {}
32
33 // Only compare the key elements, ignore the resolved classes.
34 int Compare(const DexCacheResolvedClasses& other) const {
35 if (location_checksum_ != other.location_checksum_) {
36 return static_cast<int>(location_checksum_ - other.location_checksum_);
37 }
38 return dex_location_.compare(other.dex_location_);
39 }
40
41 template <class InputIt>
42 void AddClasses(InputIt begin, InputIt end) const {
43 classes_.insert(begin, end);
44 }
45
46 const std::string& GetDexLocation() const {
47 return dex_location_;
48 }
49
50 uint32_t GetLocationChecksum() const {
51 return location_checksum_;
52 }
53
54 const std::unordered_set<uint16_t>& GetClasses() const {
55 return classes_;
56 }
57
58 private:
59 const std::string dex_location_;
60 const uint32_t location_checksum_;
61 // Array of resolved class def indexes.
62 mutable std::unordered_set<uint16_t> classes_;
63};
64
65inline bool operator<(const DexCacheResolvedClasses& a, const DexCacheResolvedClasses& b) {
66 return a.Compare(b) < 0;
67}
68
69} // namespace art
70
71#endif // ART_RUNTIME_DEX_CACHE_RESOLVED_CLASSES_H_