8221732: Introduce CollectedHeap::hash_oop()

Reviewed-by: kbarrett, tschatzl, stefank
This commit is contained in:
Per Lidén 2019-04-02 10:04:25 +02:00
parent a7dd794beb
commit a5cec7fe04
7 changed files with 24 additions and 12 deletions

View File

@ -575,3 +575,8 @@ void CollectedHeap::deduplicate_string(oop str) {
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);
}

View File

@ -239,6 +239,8 @@ class CollectedHeap : public CHeapObj<mtInternal> {
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;

View File

@ -110,6 +110,10 @@ bool ZCollectedHeap::is_in(const void* p) const {
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);

View File

@ -73,6 +73,8 @@ public:
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,

View File

@ -103,6 +103,7 @@ public:
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;

View File

@ -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 @@ inline ReferenceDiscoverer* ZHeap::reference_discoverer() {
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);

View File

@ -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 @@ class JvmtiTagHashmap : public CHeapObj<mtInternal> {
// 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)