From 37a872e85d6a46a083f38feb54a75994c6278ab5 Mon Sep 17 00:00:00 2001 From: tstuefe Date: Tue, 25 Jun 2024 15:25:44 +0200 Subject: [PATCH 1/3] start --- src/hotspot/share/interpreter/oopMapCache.cpp | 4 ---- src/hotspot/share/interpreter/oopMapCache.hpp | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/hotspot/share/interpreter/oopMapCache.cpp b/src/hotspot/share/interpreter/oopMapCache.cpp index 7b60e4869e368..2f9e70cb3d038 100644 --- a/src/hotspot/share/interpreter/oopMapCache.cpp +++ b/src/hotspot/share/interpreter/oopMapCache.cpp @@ -445,17 +445,13 @@ inline unsigned int OopMapCache::hash_value_for(const methodHandle& method, int OopMapCacheEntry* volatile OopMapCache::_old_entries = nullptr; OopMapCache::OopMapCache() { - _array = NEW_C_HEAP_ARRAY(OopMapCacheEntry*, _size, mtClass); for(int i = 0; i < _size; i++) _array[i] = nullptr; } OopMapCache::~OopMapCache() { - assert(_array != nullptr, "sanity check"); // Deallocate oop maps that are allocated out-of-line flush(); - // Deallocate array - FREE_C_HEAP_ARRAY(OopMapCacheEntry*, _array); } OopMapCacheEntry* OopMapCache::entry_at(int i) const { diff --git a/src/hotspot/share/interpreter/oopMapCache.hpp b/src/hotspot/share/interpreter/oopMapCache.hpp index 46c85f6e87985..f7d4936bee11a 100644 --- a/src/hotspot/share/interpreter/oopMapCache.hpp +++ b/src/hotspot/share/interpreter/oopMapCache.hpp @@ -156,7 +156,7 @@ class OopMapCache : public CHeapObj { _probe_depth = 3 // probe depth in case of collisions }; - OopMapCacheEntry* volatile * _array; + OopMapCacheEntry* volatile _array[_size]; unsigned int hash_value_for(const methodHandle& method, int bci) const; OopMapCacheEntry* entry_at(int i) const; From bb4272114226585ad26462135d1aea4725c88e5a Mon Sep 17 00:00:00 2001 From: tstuefe Date: Tue, 25 Jun 2024 15:27:12 +0200 Subject: [PATCH 2/3] copyrights --- src/hotspot/share/interpreter/oopMapCache.cpp | 2 +- src/hotspot/share/interpreter/oopMapCache.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/interpreter/oopMapCache.cpp b/src/hotspot/share/interpreter/oopMapCache.cpp index 2f9e70cb3d038..a0def33eda6bc 100644 --- a/src/hotspot/share/interpreter/oopMapCache.cpp +++ b/src/hotspot/share/interpreter/oopMapCache.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, 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 diff --git a/src/hotspot/share/interpreter/oopMapCache.hpp b/src/hotspot/share/interpreter/oopMapCache.hpp index f7d4936bee11a..08150251fc4e5 100644 --- a/src/hotspot/share/interpreter/oopMapCache.hpp +++ b/src/hotspot/share/interpreter/oopMapCache.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, 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 From 0bb70c064798942746a1f2126740b258837920a0 Mon Sep 17 00:00:00 2001 From: tstuefe Date: Thu, 27 Jun 2024 08:29:22 +0200 Subject: [PATCH 3/3] review feedback --- src/hotspot/share/interpreter/oopMapCache.cpp | 14 +++++++------- src/hotspot/share/interpreter/oopMapCache.hpp | 7 +++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/hotspot/share/interpreter/oopMapCache.cpp b/src/hotspot/share/interpreter/oopMapCache.cpp index a0def33eda6bc..a10f8c439eaa4 100644 --- a/src/hotspot/share/interpreter/oopMapCache.cpp +++ b/src/hotspot/share/interpreter/oopMapCache.cpp @@ -445,7 +445,7 @@ inline unsigned int OopMapCache::hash_value_for(const methodHandle& method, int OopMapCacheEntry* volatile OopMapCache::_old_entries = nullptr; OopMapCache::OopMapCache() { - for(int i = 0; i < _size; i++) _array[i] = nullptr; + for(int i = 0; i < size; i++) _array[i] = nullptr; } @@ -455,15 +455,15 @@ OopMapCache::~OopMapCache() { } OopMapCacheEntry* OopMapCache::entry_at(int i) const { - return Atomic::load_acquire(&(_array[i % _size])); + return Atomic::load_acquire(&(_array[i % size])); } bool OopMapCache::put_at(int i, OopMapCacheEntry* entry, OopMapCacheEntry* old) { - return Atomic::cmpxchg(&_array[i % _size], old, entry) == old; + return Atomic::cmpxchg(&_array[i % size], old, entry) == old; } void OopMapCache::flush() { - for (int i = 0; i < _size; i++) { + for (int i = 0; i < size; i++) { OopMapCacheEntry* entry = _array[i]; if (entry != nullptr) { _array[i] = nullptr; // no barrier, only called in OopMapCache destructor @@ -474,7 +474,7 @@ void OopMapCache::flush() { void OopMapCache::flush_obsolete_entries() { assert(SafepointSynchronize::is_at_safepoint(), "called by RedefineClasses in a safepoint"); - for (int i = 0; i < _size; i++) { + for (int i = 0; i < size; i++) { OopMapCacheEntry* entry = _array[i]; if (entry != nullptr && !entry->is_empty() && entry->method()->is_old()) { // Cache entry is occupied by an old redefined method and we don't want @@ -509,7 +509,7 @@ void OopMapCache::lookup(const methodHandle& method, // Need a critical section to avoid race against concurrent reclamation. { GlobalCounter::CriticalSection cs(Thread::current()); - for (int i = 0; i < _probe_depth; i++) { + for (int i = 0; i < probe_depth; i++) { OopMapCacheEntry *entry = entry_at(probe + i); if (entry != nullptr && !entry->is_empty() && entry->match(method, bci)) { entry_for->resource_copy(entry); @@ -538,7 +538,7 @@ void OopMapCache::lookup(const methodHandle& method, } // First search for an empty slot - for (int i = 0; i < _probe_depth; i++) { + for (int i = 0; i < probe_depth; i++) { OopMapCacheEntry* entry = entry_at(probe + i); if (entry == nullptr) { if (put_at(probe + i, tmp, nullptr)) { diff --git a/src/hotspot/share/interpreter/oopMapCache.hpp b/src/hotspot/share/interpreter/oopMapCache.hpp index 08150251fc4e5..a3f5c395f589a 100644 --- a/src/hotspot/share/interpreter/oopMapCache.hpp +++ b/src/hotspot/share/interpreter/oopMapCache.hpp @@ -152,11 +152,10 @@ class InterpreterOopMap: ResourceObj { class OopMapCache : public CHeapObj { static OopMapCacheEntry* volatile _old_entries; private: - enum { _size = 32, // Use fixed size for now - _probe_depth = 3 // probe depth in case of collisions - }; + static constexpr int size = 32; // Use fixed size for now + static constexpr int probe_depth = 3; // probe depth in case of collisions - OopMapCacheEntry* volatile _array[_size]; + OopMapCacheEntry* volatile _array[size]; unsigned int hash_value_for(const methodHandle& method, int bci) const; OopMapCacheEntry* entry_at(int i) const;