8221732: Introduce CollectedHeap::hash_oop()
Reviewed-by: kbarrett, tschatzl, stefank
--- a/src/hotspot/share/gc/shared/collectedHeap.cpp Tue Apr 02 10:04:25 2019 +0200
+++ b/src/hotspot/share/gc/shared/collectedHeap.cpp Tue Apr 02 10:04:25 2019 +0200
@@ -575,3 +575,8 @@
size_t CollectedHeap::obj_size(oop obj) const {
return obj->size();
}
+
+uint32_t CollectedHeap::hash_oop(oop obj) const {
+ const uintptr_t addr = cast_from_oop<uintptr_t>(obj);
+ return static_cast<uint32_t>(addr >> LogMinObjAlignment);
+}
--- a/src/hotspot/share/gc/shared/collectedHeap.hpp Tue Apr 02 10:04:25 2019 +0200
+++ b/src/hotspot/share/gc/shared/collectedHeap.hpp Tue Apr 02 10:04:25 2019 +0200
@@ -239,6 +239,8 @@
DEBUG_ONLY(bool is_in_or_null(const void* p) const { return p == NULL || is_in(p); })
+ virtual uint32_t hash_oop(oop obj) const;
+
void set_gc_cause(GCCause::Cause v) {
if (UsePerfData) {
_gc_lastcause = _gc_cause;
--- a/src/hotspot/share/gc/z/zCollectedHeap.cpp Tue Apr 02 10:04:25 2019 +0200
+++ b/src/hotspot/share/gc/z/zCollectedHeap.cpp Tue Apr 02 10:04:25 2019 +0200
@@ -110,6 +110,10 @@
return is_in_reserved(p) && _heap.is_in((uintptr_t)p);
}
+uint32_t ZCollectedHeap::hash_oop(oop obj) const {
+ return _heap.hash_oop(obj);
+}
+
HeapWord* ZCollectedHeap::allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size) {
const size_t size_in_bytes = ZUtils::words_to_bytes(align_object_size(requested_size));
const uintptr_t addr = _heap.alloc_tlab(size_in_bytes);
--- a/src/hotspot/share/gc/z/zCollectedHeap.hpp Tue Apr 02 10:04:25 2019 +0200
+++ b/src/hotspot/share/gc/z/zCollectedHeap.hpp Tue Apr 02 10:04:25 2019 +0200
@@ -73,6 +73,8 @@
virtual bool is_maximal_no_gc() const;
virtual bool is_in(const void* p) const;
+ virtual uint32_t hash_oop(oop obj) const;
+
virtual HeapWord* mem_allocate(size_t size, bool* gc_overhead_limit_was_exceeded);
virtual MetaWord* satisfy_failed_metadata_allocation(ClassLoaderData* loader_data,
size_t size,
--- a/src/hotspot/share/gc/z/zHeap.hpp Tue Apr 02 10:04:25 2019 +0200
+++ b/src/hotspot/share/gc/z/zHeap.hpp Tue Apr 02 10:04:25 2019 +0200
@@ -103,6 +103,7 @@
size_t unsafe_max_tlab_alloc() const;
bool is_in(uintptr_t addr) const;
+ uint32_t hash_oop(oop obj) const;
// Block
uintptr_t block_start(uintptr_t addr) const;
--- a/src/hotspot/share/gc/z/zHeap.inline.hpp Tue Apr 02 10:04:25 2019 +0200
+++ b/src/hotspot/share/gc/z/zHeap.inline.hpp Tue Apr 02 10:04:25 2019 +0200
@@ -27,6 +27,7 @@
#include "gc/z/zAddress.inline.hpp"
#include "gc/z/zForwarding.inline.hpp"
#include "gc/z/zForwardingTable.inline.hpp"
+#include "gc/z/zHash.inline.hpp"
#include "gc/z/zHeap.hpp"
#include "gc/z/zMark.inline.hpp"
#include "gc/z/zOop.inline.hpp"
@@ -44,6 +45,11 @@
return &_reference_processor;
}
+inline uint32_t ZHeap::hash_oop(oop obj) const {
+ const uintptr_t offset = ZAddress::offset(ZOop::to_address(obj));
+ return ZHash::address_to_uint32(offset);
+}
+
inline bool ZHeap::is_object_live(uintptr_t addr) const {
ZPage* page = _page_table.get(addr);
return page->is_object_live(addr);
--- a/src/hotspot/share/prims/jvmtiTagMap.cpp Tue Apr 02 10:04:25 2019 +0200
+++ b/src/hotspot/share/prims/jvmtiTagMap.cpp Tue Apr 02 10:04:25 2019 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -181,17 +181,9 @@
// hash a given key (oop) with the specified size
static unsigned int hash(oop key, int size) {
- ZGC_ONLY(assert(ZAddressMetadataShift >= sizeof(unsigned int) * BitsPerByte, "cast removes the metadata bits");)
-
- // shift right to get better distribution (as these bits will be zero
- // with aligned addresses)
- key = Access<>::resolve(key);
- unsigned int addr = (unsigned int)(cast_from_oop<intptr_t>(key));
-#ifdef _LP64
- return (addr >> 3) % size;
-#else
- return (addr >> 2) % size;
-#endif
+ const oop obj = Access<>::resolve(key);
+ const unsigned int hash = Universe::heap()->hash_oop(obj);
+ return hash % size;
}
// hash a given key (oop)