summaryrefslogtreecommitdiff
path: root/runtime/intern_table.h
diff options
context:
space:
mode:
author Alexey Grebenkin <a.grebenkin@partner.samsung.com> 2016-12-02 17:44:54 +0300
committer Artem Udovichenko <artem.u@samsung.com> 2016-12-20 16:53:03 +0300
commit21f2364f11a709c7c22320588abe2adc91c69b6a (patch)
tree9c0404499b37dcf5cae6d982b6e65c925e57f772 /runtime/intern_table.h
parent06ce6d4359ed897f1d1b39be4e748f0c4f3ca2ff (diff)
Fix incorrect string hash value extension during cross-compilation.
Previouly, having a 32-bit Android device and a 64-bit host to compile boot.oat could lead to an interning table be fulfilled using one hash function and be worked with using another hash function (which is caused by sign extension). Target case is any string with a negative .GetHashCode(). Test: test-art-host-gtest-intern_table_test Change-Id: I3f417e1ac990ef681f0651160292130e9b3632f0
Diffstat (limited to 'runtime/intern_table.h')
-rw-r--r--runtime/intern_table.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/runtime/intern_table.h b/runtime/intern_table.h
index f661d9ffe5..68454fbfd4 100644
--- a/runtime/intern_table.h
+++ b/runtime/intern_table.h
@@ -163,7 +163,11 @@ class InternTable {
NO_THREAD_SAFETY_ANALYSIS;
// Utf8String can be used for lookup.
- std::size_t operator()(const Utf8String& key) const { return key.GetHash(); }
+ std::size_t operator()(const Utf8String& key) const {
+ // A cast to prevent undesired sign extension.
+ return static_cast<uint32_t>(key.GetHash());
+ }
+
bool operator()(const GcRoot<mirror::String>& a, const Utf8String& b) const
NO_THREAD_SAFETY_ANALYSIS;
};
@@ -217,6 +221,8 @@ class InternTable {
// We call AddNewTable when we create the zygote to reduce private dirty pages caused by
// modifying the zygote intern table. The back of table is modified when strings are interned.
std::vector<UnorderedSet> tables_;
+
+ ART_FRIEND_TEST(InternTableTest, CrossHash);
};
// Insert if non null, otherwise return null. Must be called holding the mutator lock.
@@ -276,6 +282,7 @@ class InternTable {
gc::WeakRootState weak_root_state_ GUARDED_BY(Locks::intern_table_lock_);
friend class Transaction;
+ ART_FRIEND_TEST(InternTableTest, CrossHash);
DISALLOW_COPY_AND_ASSIGN(InternTable);
};