blob: 3baa0612f6dcec0a3511dcf136cbcaea122b9e37 [file] [log] [blame]
Mathieu Chartier193bad92013-08-29 18:46:00 -07001/*
2 * Copyright (C) 2013 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_COMPILER_UTILS_DEDUPE_SET_H_
18#define ART_COMPILER_UTILS_DEDUPE_SET_H_
19
Vladimir Marko35831e82015-09-11 11:59:18 +010020#include <stdint.h>
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070021#include <memory>
Ian Rogersd133b972013-09-05 11:01:30 -070022#include <string>
Mathieu Chartier193bad92013-08-29 18:46:00 -070023
Vladimir Marko35831e82015-09-11 11:59:18 +010024#include "base/macros.h"
Mathieu Chartier193bad92013-08-29 18:46:00 -070025
26namespace art {
27
Vladimir Marko35831e82015-09-11 11:59:18 +010028class Thread;
29
Ian Rogersd133b972013-09-05 11:01:30 -070030// A set of Keys that support a HashFunc returning HashType. Used to find duplicates of Key in the
31// Add method. The data-structure is thread-safe through the use of internal locks, it also
32// supports the lock being sharded.
Vladimir Marko35831e82015-09-11 11:59:18 +010033template <typename InKey,
34 typename StoreKey,
35 typename Alloc,
36 typename HashType,
37 typename HashFunc,
Andreas Gampee21dc3d2014-12-08 16:59:43 -080038 HashType kShard = 1>
Mathieu Chartier193bad92013-08-29 18:46:00 -070039class DedupeSet {
Mathieu Chartier193bad92013-08-29 18:46:00 -070040 public:
Vladimir Marko35831e82015-09-11 11:59:18 +010041 // Add a new key to the dedupe set if not present. Return the equivalent deduplicated stored key.
42 const StoreKey* Add(Thread* self, const InKey& key);
Mathieu Chartier193bad92013-08-29 18:46:00 -070043
Vladimir Marko35831e82015-09-11 11:59:18 +010044 DedupeSet(const char* set_name, const Alloc& alloc);
Mathieu Chartier193bad92013-08-29 18:46:00 -070045
Vladimir Marko35831e82015-09-11 11:59:18 +010046 ~DedupeSet();
Mathieu Chartier193bad92013-08-29 18:46:00 -070047
Vladimir Marko35831e82015-09-11 11:59:18 +010048 std::string DumpStats(Thread* self) const;
Andreas Gampee21dc3d2014-12-08 16:59:43 -080049
Mathieu Chartier193bad92013-08-29 18:46:00 -070050 private:
Vladimir Marko35831e82015-09-11 11:59:18 +010051 struct Stats;
52 class Shard;
Andreas Gampee21dc3d2014-12-08 16:59:43 -080053
Vladimir Marko35831e82015-09-11 11:59:18 +010054 std::unique_ptr<Shard> shards_[kShard];
Andreas Gampee21dc3d2014-12-08 16:59:43 -080055 uint64_t hash_time_;
Ian Rogersd133b972013-09-05 11:01:30 -070056
Mathieu Chartier193bad92013-08-29 18:46:00 -070057 DISALLOW_COPY_AND_ASSIGN(DedupeSet);
58};
59
60} // namespace art
61
62#endif // ART_COMPILER_UTILS_DEDUPE_SET_H_