diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/Android.bp | 3 | ||||
-rw-r--r-- | compiler/art_standalone_compiler_tests.xml | 1 | ||||
-rw-r--r-- | compiler/common_compiler_test.cc | 1 | ||||
-rw-r--r-- | compiler/utils/atomic_dex_ref_map-inl.h | 150 | ||||
-rw-r--r-- | compiler/utils/atomic_dex_ref_map.h | 86 | ||||
-rw-r--r-- | compiler/utils/atomic_dex_ref_map_test.cc | 75 | ||||
-rw-r--r-- | compiler/utils/dedupe_set-inl.h | 275 | ||||
-rw-r--r-- | compiler/utils/dedupe_set.h | 64 | ||||
-rw-r--r-- | compiler/utils/dedupe_set_test.cc | 92 |
9 files changed, 0 insertions, 747 deletions
diff --git a/compiler/Android.bp b/compiler/Android.bp index ef56e7f3ad..73994f7d95 100644 --- a/compiler/Android.bp +++ b/compiler/Android.bp @@ -438,7 +438,6 @@ art_cc_defaults { name: "art_compiler_tests_defaults", device_common_data: [ ":art-gtest-jars-ExceptionHandle", - ":art-gtest-jars-Interfaces", ":art-gtest-jars-Main", ":art-gtest-jars-MyClassNatives", ], @@ -489,8 +488,6 @@ art_cc_defaults { "optimizing/stack_map_test.cc", "optimizing/superblock_cloner_test.cc", "optimizing/suspend_check_test.cc", - "utils/atomic_dex_ref_map_test.cc", - "utils/dedupe_set_test.cc", "optimizing/codegen_test.cc", "optimizing/instruction_simplifier_test.cc", diff --git a/compiler/art_standalone_compiler_tests.xml b/compiler/art_standalone_compiler_tests.xml index c2065dd766..813a6f10d0 100644 --- a/compiler/art_standalone_compiler_tests.xml +++ b/compiler/art_standalone_compiler_tests.xml @@ -26,7 +26,6 @@ <target_preparer class="com.android.compatibility.common.tradefed.targetprep.FilePusher"> <option name="cleanup" value="true" /> <option name="push" value="art-gtest-jars-ExceptionHandle.jar->/data/local/tmp/art_standalone_compiler_tests/art-gtest-jars-ExceptionHandle.jar" /> - <option name="push" value="art-gtest-jars-Interfaces.jar->/data/local/tmp/art_standalone_compiler_tests/art-gtest-jars-Interfaces.jar" /> <option name="push" value="art-gtest-jars-Main.jar->/data/local/tmp/art_standalone_compiler_tests/art-gtest-jars-Main.jar" /> <option name="push" value="art-gtest-jars-MyClassNatives.jar->/data/local/tmp/art_standalone_compiler_tests/art-gtest-jars-MyClassNatives.jar" /> </target_preparer> diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc index 26800637fa..e54c85f747 100644 --- a/compiler/common_compiler_test.cc +++ b/compiler/common_compiler_test.cc @@ -41,7 +41,6 @@ #include "oat/oat_quick_method_header.h" #include "scoped_thread_state_change-inl.h" #include "thread-current-inl.h" -#include "utils/atomic_dex_ref_map-inl.h" namespace art HIDDEN { diff --git a/compiler/utils/atomic_dex_ref_map-inl.h b/compiler/utils/atomic_dex_ref_map-inl.h deleted file mode 100644 index 653d21b3ea..0000000000 --- a/compiler/utils/atomic_dex_ref_map-inl.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ART_COMPILER_UTILS_ATOMIC_DEX_REF_MAP_INL_H_ -#define ART_COMPILER_UTILS_ATOMIC_DEX_REF_MAP_INL_H_ - -#include "atomic_dex_ref_map.h" - -#include <type_traits> - -#include "base/macros.h" -#include "dex/class_reference.h" -#include "dex/dex_file-inl.h" -#include "dex/method_reference.h" -#include "dex/type_reference.h" - -namespace art HIDDEN { - -template <typename DexFileReferenceType, typename Value> -inline size_t AtomicDexRefMap<DexFileReferenceType, Value>::NumberOfDexIndices( - const DexFile* dex_file) { - // TODO: Use specialization for this? Not sure if worth it. - static_assert(std::is_same<DexFileReferenceType, MethodReference>::value || - std::is_same<DexFileReferenceType, ClassReference>::value || - std::is_same<DexFileReferenceType, TypeReference>::value, - "invalid index type"); - if (std::is_same<DexFileReferenceType, MethodReference>::value) { - return dex_file->NumMethodIds(); - } - if (std::is_same<DexFileReferenceType, ClassReference>::value) { - return dex_file->NumClassDefs(); - } - if (std::is_same<DexFileReferenceType, TypeReference>::value) { - return dex_file->NumTypeIds(); - } -} - -template <typename DexFileReferenceType, typename Value> -inline typename AtomicDexRefMap<DexFileReferenceType, Value>::InsertResult - AtomicDexRefMap<DexFileReferenceType, Value>::Insert(const DexFileReferenceType& ref, - const Value& expected, - const Value& desired) { - ElementArray* const array = GetArray(ref.dex_file); - if (array == nullptr) { - return kInsertResultInvalidDexFile; - } - DCHECK_LT(ref.index, array->size()); - return (*array)[ref.index].CompareAndSetStrongSequentiallyConsistent(expected, desired) - ? kInsertResultSuccess - : kInsertResultCASFailure; -} - -template <typename DexFileReferenceType, typename Value> -inline bool AtomicDexRefMap<DexFileReferenceType, Value>::Get(const DexFileReferenceType& ref, - Value* out) const { - const ElementArray* const array = GetArray(ref.dex_file); - if (array == nullptr) { - return false; - } - *out = (*array)[ref.index].load(std::memory_order_relaxed); - return true; -} - -template <typename DexFileReferenceType, typename Value> -inline bool AtomicDexRefMap<DexFileReferenceType, Value>::Remove(const DexFileReferenceType& ref, - Value* out) { - ElementArray* const array = GetArray(ref.dex_file); - if (array == nullptr) { - return false; - } - *out = (*array)[ref.index].exchange(nullptr, std::memory_order_seq_cst); - return true; -} - -template <typename DexFileReferenceType, typename Value> -inline void AtomicDexRefMap<DexFileReferenceType, Value>::AddDexFile(const DexFile* dex_file) { - arrays_.Put(dex_file, std::move(ElementArray(NumberOfDexIndices(dex_file)))); -} - -template <typename DexFileReferenceType, typename Value> -inline void AtomicDexRefMap<DexFileReferenceType, Value>::AddDexFiles( - const std::vector<const DexFile*>& dex_files) { - for (const DexFile* dex_file : dex_files) { - if (!HaveDexFile(dex_file)) { - AddDexFile(dex_file); - } - } -} - -template <typename DexFileReferenceType, typename Value> -inline typename AtomicDexRefMap<DexFileReferenceType, Value>::ElementArray* - AtomicDexRefMap<DexFileReferenceType, Value>::GetArray(const DexFile* dex_file) { - auto it = arrays_.find(dex_file); - return (it != arrays_.end()) ? &it->second : nullptr; -} - -template <typename DexFileReferenceType, typename Value> -inline const typename AtomicDexRefMap<DexFileReferenceType, Value>::ElementArray* - AtomicDexRefMap<DexFileReferenceType, Value>::GetArray(const DexFile* dex_file) const { - auto it = arrays_.find(dex_file); - return (it != arrays_.end()) ? &it->second : nullptr; -} - -template <typename DexFileReferenceType, typename Value> template <typename Visitor> -inline void AtomicDexRefMap<DexFileReferenceType, Value>::Visit(const Visitor& visitor) { - for (auto& pair : arrays_) { - const DexFile* dex_file = pair.first; - const ElementArray& elements = pair.second; - for (size_t i = 0; i < elements.size(); ++i) { - visitor(DexFileReference(dex_file, i), elements[i].load(std::memory_order_relaxed)); - } - } -} - -template <typename DexFileReferenceType, typename Value> -inline void AtomicDexRefMap<DexFileReferenceType, Value>::ClearEntries() { - for (auto& it : arrays_) { - for (auto& element : it.second) { - element.store(nullptr, std::memory_order_relaxed); - } - } -} - -template <typename DexFileReferenceType, typename Value> -inline std::vector<const DexFile*> AtomicDexRefMap<DexFileReferenceType, Value>::GetDexFiles() - const { - std::vector<const DexFile*> result; - result.reserve(arrays_.size()); - for (auto& it : arrays_) { - result.push_back(it.first); - } - return result; -} - -} // namespace art - -#endif // ART_COMPILER_UTILS_ATOMIC_DEX_REF_MAP_INL_H_ diff --git a/compiler/utils/atomic_dex_ref_map.h b/compiler/utils/atomic_dex_ref_map.h deleted file mode 100644 index b10fef50c5..0000000000 --- a/compiler/utils/atomic_dex_ref_map.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ART_COMPILER_UTILS_ATOMIC_DEX_REF_MAP_H_ -#define ART_COMPILER_UTILS_ATOMIC_DEX_REF_MAP_H_ - -#include "base/atomic.h" -#include "base/dchecked_vector.h" -#include "base/macros.h" -#include "base/safe_map.h" -#include "dex/dex_file_reference.h" - -namespace art HIDDEN { - -class DexFile; - -// Used by CompilerCallbacks to track verification information from the Runtime. -template <typename DexFileReferenceType, typename Value> -class AtomicDexRefMap { - public: - AtomicDexRefMap() {} - ~AtomicDexRefMap() {} - - // Atomically swap the element in if the existing value matches expected. - enum InsertResult { - kInsertResultInvalidDexFile, - kInsertResultCASFailure, - kInsertResultSuccess, - }; - InsertResult Insert(const DexFileReferenceType& ref, - const Value& expected, - const Value& desired); - - // Retreive an item, returns false if the dex file is not added. - bool Get(const DexFileReferenceType& ref, Value* out) const; - - // Remove an item and return the existing value. Returns false if the dex file is not added. - bool Remove(const DexFileReferenceType& ref, Value* out); - - // Dex files must be added before method references belonging to them can be used as keys. Not - // thread safe. - void AddDexFile(const DexFile* dex_file); - void AddDexFiles(const std::vector<const DexFile*>& dex_files); - - // Return a vector of all dex files which were added to the map. - std::vector<const DexFile*> GetDexFiles() const; - - bool HaveDexFile(const DexFile* dex_file) const { - return arrays_.find(dex_file) != arrays_.end(); - } - - // Visit all of the dex files and elements. - template <typename Visitor> - void Visit(const Visitor& visitor); - - void ClearEntries(); - - private: - // Verified methods. The method array is fixed to avoid needing a lock to extend it. - using ElementArray = dchecked_vector<Atomic<Value>>; - using DexFileArrays = SafeMap<const DexFile*, ElementArray>; - - const ElementArray* GetArray(const DexFile* dex_file) const; - ElementArray* GetArray(const DexFile* dex_file); - - static size_t NumberOfDexIndices(const DexFile* dex_file); - - DexFileArrays arrays_; -}; - -} // namespace art - -#endif // ART_COMPILER_UTILS_ATOMIC_DEX_REF_MAP_H_ diff --git a/compiler/utils/atomic_dex_ref_map_test.cc b/compiler/utils/atomic_dex_ref_map_test.cc deleted file mode 100644 index 329735b796..0000000000 --- a/compiler/utils/atomic_dex_ref_map_test.cc +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "atomic_dex_ref_map-inl.h" - -#include <memory> - -#include "base/macros.h" -#include "common_runtime_test.h" -#include "dex/dex_file-inl.h" -#include "dex/method_reference.h" -#include "scoped_thread_state_change-inl.h" - -namespace art HIDDEN { - -class AtomicDexRefMapTest : public CommonRuntimeTest {}; - -TEST_F(AtomicDexRefMapTest, RunTests) { - ScopedObjectAccess soa(Thread::Current()); - std::unique_ptr<const DexFile> dex(OpenTestDexFile("Interfaces")); - ASSERT_TRUE(dex != nullptr); - using Map = AtomicDexRefMap<MethodReference, int>; - Map map; - int value = 123; - // Error case: Not already inserted. - EXPECT_FALSE(map.Get(MethodReference(dex.get(), 1), &value)); - EXPECT_FALSE(map.HaveDexFile(dex.get())); - // Error case: Dex file not registered. - EXPECT_TRUE(map.Insert(MethodReference(dex.get(), 1), 0, 1) == Map::kInsertResultInvalidDexFile); - map.AddDexFile(dex.get()); - EXPECT_TRUE(map.HaveDexFile(dex.get())); - std::vector<const DexFile*> registered_dex_files = map.GetDexFiles(); - EXPECT_EQ(1u, registered_dex_files.size()); - EXPECT_TRUE(registered_dex_files[0] == dex.get()); - EXPECT_GT(dex->NumMethodIds(), 10u); - // After we have added the get should succeed but return the default value. - EXPECT_TRUE(map.Get(MethodReference(dex.get(), 1), &value)); - EXPECT_EQ(value, 0); - // Actually insert an item and make sure we can retreive it. - static const int kInsertValue = 44; - EXPECT_TRUE(map.Insert(MethodReference(dex.get(), 1), 0, kInsertValue) == - Map::kInsertResultSuccess); - EXPECT_TRUE(map.Get(MethodReference(dex.get(), 1), &value)); - EXPECT_EQ(value, kInsertValue); - static const int kInsertValue2 = 123; - EXPECT_TRUE(map.Insert(MethodReference(dex.get(), 2), 0, kInsertValue2) == - Map::kInsertResultSuccess); - EXPECT_TRUE(map.Get(MethodReference(dex.get(), 1), &value)); - EXPECT_EQ(value, kInsertValue); - EXPECT_TRUE(map.Get(MethodReference(dex.get(), 2), &value)); - EXPECT_EQ(value, kInsertValue2); - // Error case: Incorrect expected value for CAS. - EXPECT_TRUE(map.Insert(MethodReference(dex.get(), 1), 0, kInsertValue + 1) == - Map::kInsertResultCASFailure); - // Correctly overwrite the value and verify. - EXPECT_TRUE(map.Insert(MethodReference(dex.get(), 1), kInsertValue, kInsertValue + 1) == - Map::kInsertResultSuccess); - EXPECT_TRUE(map.Get(MethodReference(dex.get(), 1), &value)); - EXPECT_EQ(value, kInsertValue + 1); -} - -} // namespace art diff --git a/compiler/utils/dedupe_set-inl.h b/compiler/utils/dedupe_set-inl.h deleted file mode 100644 index db744c53f7..0000000000 --- a/compiler/utils/dedupe_set-inl.h +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ART_COMPILER_UTILS_DEDUPE_SET_INL_H_ -#define ART_COMPILER_UTILS_DEDUPE_SET_INL_H_ - -#include "dedupe_set.h" - -#include <inttypes.h> - -#include <algorithm> -#include <unordered_map> - -#include "android-base/stringprintf.h" - -#include "base/hash_set.h" -#include "base/macros.h" -#include "base/mutex.h" -#include "base/stl_util.h" -#include "base/time_utils.h" - -namespace art HIDDEN { - -template <typename InKey, - typename StoreKey, - typename Alloc, - typename HashType, - typename HashFunc, - HashType kShard> -struct DedupeSet<InKey, StoreKey, Alloc, HashType, HashFunc, kShard>::Stats { - size_t collision_sum = 0u; - size_t collision_max = 0u; - size_t total_probe_distance = 0u; - size_t total_size = 0u; -}; - -template <typename InKey, - typename StoreKey, - typename Alloc, - typename HashType, - typename HashFunc, - HashType kShard> -class DedupeSet<InKey, StoreKey, Alloc, HashType, HashFunc, kShard>::Shard { - public: - Shard(const Alloc& alloc, const std::string& lock_name) - : alloc_(alloc), - lock_name_(lock_name), - lock_(lock_name_.c_str()), - keys_() { - } - - ~Shard() { - for (const HashedKey<StoreKey>& key : keys_) { - DCHECK(key.Key() != nullptr); - alloc_.Destroy(key.Key()); - } - } - - const StoreKey* Add(Thread* self, size_t hash, const InKey& in_key) REQUIRES(!lock_) { - MutexLock lock(self, lock_); - HashedKey<InKey> hashed_in_key(hash, &in_key); - auto it = keys_.find(hashed_in_key); - if (it != keys_.end()) { - DCHECK(it->Key() != nullptr); - return it->Key(); - } - const StoreKey* store_key = alloc_.Copy(in_key); - keys_.insert(HashedKey<StoreKey> { hash, store_key }); - return store_key; - } - - size_t Size(Thread* self) { - MutexLock lock(self, lock_); - return keys_.size(); - } - - void UpdateStats(Thread* self, Stats* global_stats) REQUIRES(!lock_) { - // HashSet<> doesn't keep entries ordered by hash, so we actually allocate memory - // for bookkeeping while collecting the stats. - std::unordered_map<HashType, size_t> stats; - { - MutexLock lock(self, lock_); - // Note: The total_probe_distance will be updated with the current state. - // It may have been higher before a re-hash. - global_stats->total_probe_distance += keys_.TotalProbeDistance(); - global_stats->total_size += keys_.size(); - for (const HashedKey<StoreKey>& key : keys_) { - auto it = stats.find(key.Hash()); - if (it == stats.end()) { - stats.insert({key.Hash(), 1u}); - } else { - ++it->second; - } - } - } - for (const auto& entry : stats) { - size_t number_of_entries = entry.second; - if (number_of_entries > 1u) { - global_stats->collision_sum += number_of_entries - 1u; - global_stats->collision_max = std::max(global_stats->collision_max, number_of_entries); - } - } - } - - private: - template <typename T> - class HashedKey { - public: - HashedKey() : hash_(0u), key_(nullptr) { } - HashedKey(size_t hash, const T* key) : hash_(hash), key_(key) { } - - size_t Hash() const { - return hash_; - } - - const T* Key() const { - return key_; - } - - bool IsEmpty() const { - return Key() == nullptr; - } - - void MakeEmpty() { - key_ = nullptr; - } - - private: - size_t hash_; - const T* key_; - }; - - class ShardEmptyFn { - public: - bool IsEmpty(const HashedKey<StoreKey>& key) const { - return key.IsEmpty(); - } - - void MakeEmpty(HashedKey<StoreKey>& key) { - key.MakeEmpty(); - } - }; - - struct ShardHashFn { - template <typename T> - size_t operator()(const HashedKey<T>& key) const { - return key.Hash(); - } - }; - - struct ShardPred { - typename std::enable_if<!std::is_same<StoreKey, InKey>::value, bool>::type - operator()(const HashedKey<StoreKey>& lhs, const HashedKey<StoreKey>& rhs) const { - DCHECK(lhs.Key() != nullptr); - DCHECK(rhs.Key() != nullptr); - // Rehashing: stored keys are already deduplicated, so we can simply compare key pointers. - return lhs.Key() == rhs.Key(); - } - - template <typename LeftT, typename RightT> - bool operator()(const HashedKey<LeftT>& lhs, const HashedKey<RightT>& rhs) const { - DCHECK(lhs.Key() != nullptr); - DCHECK(rhs.Key() != nullptr); - return lhs.Hash() == rhs.Hash() && - lhs.Key()->size() == rhs.Key()->size() && - std::equal(lhs.Key()->begin(), lhs.Key()->end(), rhs.Key()->begin()); - } - }; - - Alloc alloc_; - const std::string lock_name_; - Mutex lock_; - HashSet<HashedKey<StoreKey>, ShardEmptyFn, ShardHashFn, ShardPred> keys_ GUARDED_BY(lock_); -}; - -template <typename InKey, - typename StoreKey, - typename Alloc, - typename HashType, - typename HashFunc, - HashType kShard> -const StoreKey* DedupeSet<InKey, StoreKey, Alloc, HashType, HashFunc, kShard>::Add( - Thread* self, const InKey& key) { - uint64_t hash_start; - if (kIsDebugBuild) { - hash_start = NanoTime(); - } - HashType raw_hash = HashFunc()(key); - if (kIsDebugBuild) { - uint64_t hash_end = NanoTime(); - hash_time_ += hash_end - hash_start; - } - HashType shard_hash = raw_hash / kShard; - HashType shard_bin = raw_hash % kShard; - return shards_[shard_bin]->Add(self, shard_hash, key); -} - -template <typename InKey, - typename StoreKey, - typename Alloc, - typename HashType, - typename HashFunc, - HashType kShard> -DedupeSet<InKey, StoreKey, Alloc, HashType, HashFunc, kShard>::DedupeSet(const char* set_name, - const Alloc& alloc) - : hash_time_(0) { - for (HashType i = 0; i < kShard; ++i) { - std::ostringstream oss; - oss << set_name << " lock " << i; - shards_[i].reset(new Shard(alloc, oss.str())); - } -} - -template <typename InKey, - typename StoreKey, - typename Alloc, - typename HashType, - typename HashFunc, - HashType kShard> -DedupeSet<InKey, StoreKey, Alloc, HashType, HashFunc, kShard>::~DedupeSet() { - // Everything done by member destructors. -} - -template <typename InKey, - typename StoreKey, - typename Alloc, - typename HashType, - typename HashFunc, - HashType kShard> -size_t DedupeSet<InKey, StoreKey, Alloc, HashType, HashFunc, kShard>::Size(Thread* self) const { - size_t result = 0u; - for (const auto& shard : shards_) { - result += shard->Size(self); - } - return result; -} - -template <typename InKey, - typename StoreKey, - typename Alloc, - typename HashType, - typename HashFunc, - HashType kShard> -std::string DedupeSet<InKey, StoreKey, Alloc, HashType, HashFunc, kShard>::DumpStats( - Thread* self) const { - Stats stats; - for (HashType shard = 0; shard < kShard; ++shard) { - shards_[shard]->UpdateStats(self, &stats); - } - return android::base::StringPrintf("%zu collisions, %zu max hash collisions, " - "%zu/%zu probe distance, %" PRIu64 " ns hash time", - stats.collision_sum, - stats.collision_max, - stats.total_probe_distance, - stats.total_size, - hash_time_); -} - - -} // namespace art - -#endif // ART_COMPILER_UTILS_DEDUPE_SET_INL_H_ diff --git a/compiler/utils/dedupe_set.h b/compiler/utils/dedupe_set.h deleted file mode 100644 index 42db8e3ca0..0000000000 --- a/compiler/utils/dedupe_set.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ART_COMPILER_UTILS_DEDUPE_SET_H_ -#define ART_COMPILER_UTILS_DEDUPE_SET_H_ - -#include <stdint.h> -#include <memory> -#include <string> - -#include "base/macros.h" - -namespace art HIDDEN { - -class Thread; - -// A set of Keys that support a HashFunc returning HashType. Used to find duplicates of Key in the -// Add method. The data-structure is thread-safe through the use of internal locks, it also -// supports the lock being sharded. -template <typename InKey, - typename StoreKey, - typename Alloc, - typename HashType, - typename HashFunc, - HashType kShard = 1> -class DedupeSet { - public: - // Add a new key to the dedupe set if not present. Return the equivalent deduplicated stored key. - const StoreKey* Add(Thread* self, const InKey& key); - - DedupeSet(const char* set_name, const Alloc& alloc); - - ~DedupeSet(); - - size_t Size(Thread* self) const; - - std::string DumpStats(Thread* self) const; - - private: - struct Stats; - class Shard; - - std::unique_ptr<Shard> shards_[kShard]; - uint64_t hash_time_; - - DISALLOW_COPY_AND_ASSIGN(DedupeSet); -}; - -} // namespace art - -#endif // ART_COMPILER_UTILS_DEDUPE_SET_H_ diff --git a/compiler/utils/dedupe_set_test.cc b/compiler/utils/dedupe_set_test.cc deleted file mode 100644 index 89385e7c82..0000000000 --- a/compiler/utils/dedupe_set_test.cc +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "dedupe_set.h" - -#include <algorithm> -#include <cstdio> -#include <vector> - -#include "base/array_ref.h" -#include "base/macros.h" -#include "dedupe_set-inl.h" -#include "gtest/gtest.h" -#include "thread-current-inl.h" - -namespace art HIDDEN { - -class DedupeSetTestHashFunc { - public: - size_t operator()(const ArrayRef<const uint8_t>& array) const { - size_t hash = 0; - for (uint8_t c : array) { - hash += c; - hash += hash << 10; - hash += hash >> 6; - } - return hash; - } -}; - -class DedupeSetTestAlloc { - public: - const std::vector<uint8_t>* Copy(const ArrayRef<const uint8_t>& src) { - return new std::vector<uint8_t>(src.begin(), src.end()); - } - - void Destroy(const std::vector<uint8_t>* key) { - delete key; - } -}; - -TEST(DedupeSetTest, Test) { - Thread* self = Thread::Current(); - DedupeSetTestAlloc alloc; - DedupeSet<ArrayRef<const uint8_t>, - std::vector<uint8_t>, - DedupeSetTestAlloc, - size_t, - DedupeSetTestHashFunc> deduplicator("test", alloc); - const std::vector<uint8_t>* array1; - { - uint8_t raw_test1[] = { 10u, 20u, 30u, 45u }; - ArrayRef<const uint8_t> test1(raw_test1); - array1 = deduplicator.Add(self, test1); - ASSERT_NE(array1, nullptr); - ASSERT_TRUE(std::equal(test1.begin(), test1.end(), array1->begin())); - } - - const std::vector<uint8_t>* array2; - { - uint8_t raw_test2[] = { 10u, 20u, 30u, 45u }; - ArrayRef<const uint8_t> test2(raw_test2); - array2 = deduplicator.Add(self, test2); - ASSERT_EQ(array2, array1); - ASSERT_TRUE(std::equal(test2.begin(), test2.end(), array2->begin())); - } - - const std::vector<uint8_t>* array3; - { - uint8_t raw_test3[] = { 10u, 22u, 30u, 47u }; - ArrayRef<const uint8_t> test3(raw_test3); - array3 = deduplicator.Add(self, test3); - ASSERT_NE(array3, nullptr); - ASSERT_NE(array3, array1); - ASSERT_TRUE(std::equal(test3.begin(), test3.end(), array3->begin())); - } -} - -} // namespace art |