aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Kim Barrett <kbarrett@openjdk.org> 2021-03-26 07:44:22 +0000
committerGravatar Kim Barrett <kbarrett@openjdk.org> 2021-03-26 07:44:22 +0000
commitbb354b9d1c3c70c03d0d5362493f715183d7f1d3 (patch)
tree2dde844309b497139e1452c8ce03cdec48d5b179
parent41657b15ac8322cc109d7f6105873ae388e48ff3 (diff)
downloadjdk-bb354b9d1c3c70c03d0d5362493f715183d7f1d3.tar.gz
jdk-bb354b9d1c3c70c03d0d5362493f715183d7f1d3.zip
8264166: OopStorage should support specifying MEMFLAGS for allocations
Reviewed-by: tschatzl, stefank
-rw-r--r--src/hotspot/share/classfile/stringTable.cpp2
-rw-r--r--src/hotspot/share/gc/shared/oopStorage.cpp28
-rw-r--r--src/hotspot/share/gc/shared/oopStorage.hpp16
-rw-r--r--src/hotspot/share/gc/shared/oopStorage.inline.hpp7
-rw-r--r--src/hotspot/share/gc/shared/oopStorageSet.cpp8
-rw-r--r--src/hotspot/share/gc/shared/oopStorageSet.hpp6
-rw-r--r--src/hotspot/share/jfr/leakprofiler/sampling/objectSampler.cpp2
-rw-r--r--src/hotspot/share/memory/universe.cpp4
-rw-r--r--src/hotspot/share/prims/jvmtiExport.cpp4
-rw-r--r--src/hotspot/share/prims/resolvedMethodTable.cpp4
-rw-r--r--src/hotspot/share/runtime/jniHandles.cpp4
-rw-r--r--src/hotspot/share/runtime/objectMonitor.cpp2
-rw-r--r--src/hotspot/share/runtime/thread.cpp2
-rw-r--r--src/hotspot/share/services/threadService.cpp3
-rw-r--r--test/hotspot/gtest/gc/shared/test_oopStorage.cpp4
-rw-r--r--test/hotspot/gtest/gc/shared/test_oopStorage_parperf.cpp2
16 files changed, 64 insertions, 34 deletions
diff --git a/src/hotspot/share/classfile/stringTable.cpp b/src/hotspot/share/classfile/stringTable.cpp
index 8fe73d6759c..67f05a694bd 100644
--- a/src/hotspot/share/classfile/stringTable.cpp
+++ b/src/hotspot/share/classfile/stringTable.cpp
@@ -210,7 +210,7 @@ void StringTable::create_table() {
log_trace(stringtable)("Start size: " SIZE_FORMAT " (" SIZE_FORMAT ")",
_current_size, start_size_log_2);
_local_table = new StringTableHash(start_size_log_2, END_SIZE, REHASH_LEN);
- _oop_storage = OopStorageSet::create_weak("StringTable Weak");
+ _oop_storage = OopStorageSet::create_weak("StringTable Weak", mtSymbol);
_oop_storage->register_num_dead_callback(&gc_notification);
}
diff --git a/src/hotspot/share/gc/shared/oopStorage.cpp b/src/hotspot/share/gc/shared/oopStorage.cpp
index 45142a0bd75..3fca4651d2a 100644
--- a/src/hotspot/share/gc/shared/oopStorage.cpp
+++ b/src/hotspot/share/gc/shared/oopStorage.cpp
@@ -121,9 +121,11 @@ OopStorage::ActiveArray::~ActiveArray() {
assert(_refcount == 0, "precondition");
}
-OopStorage::ActiveArray* OopStorage::ActiveArray::create(size_t size, AllocFailType alloc_fail) {
+OopStorage::ActiveArray* OopStorage::ActiveArray::create(size_t size,
+ MEMFLAGS memflags,
+ AllocFailType alloc_fail) {
size_t size_in_bytes = blocks_offset() + sizeof(Block*) * size;
- void* mem = NEW_C_HEAP_ARRAY3(char, size_in_bytes, mtGC, CURRENT_PC, alloc_fail);
+ void* mem = NEW_C_HEAP_ARRAY3(char, size_in_bytes, memflags, CURRENT_PC, alloc_fail);
if (mem == NULL) return NULL;
return new (mem) ActiveArray(size);
}
@@ -321,7 +323,7 @@ OopStorage::Block* OopStorage::Block::new_block(const OopStorage* owner) {
// _data must be first member: aligning block => aligning _data.
STATIC_ASSERT(_data_pos == 0);
size_t size_needed = allocation_size();
- void* memory = NEW_C_HEAP_ARRAY_RETURN_NULL(char, size_needed, mtGC);
+ void* memory = NEW_C_HEAP_ARRAY_RETURN_NULL(char, size_needed, owner->memflags());
if (memory == NULL) {
return NULL;
}
@@ -499,7 +501,9 @@ bool OopStorage::expand_active_array() {
size_t new_size = 2 * old_array->size();
log_debug(oopstorage, blocks)("%s: expand active array " SIZE_FORMAT,
name(), new_size);
- ActiveArray* new_array = ActiveArray::create(new_size, AllocFailStrategy::RETURN_NULL);
+ ActiveArray* new_array = ActiveArray::create(new_size,
+ memflags(),
+ AllocFailStrategy::RETURN_NULL);
if (new_array == NULL) return false;
new_array->copy_from(old_array);
replace_active_array(new_array);
@@ -739,9 +743,18 @@ static Mutex* make_oopstorage_mutex(const char* storage_name,
return new PaddedMutex(rank, name, true, Mutex::_safepoint_check_never);
}
-OopStorage::OopStorage(const char* name) :
+void* OopStorage::operator new(size_t size, MEMFLAGS memflags) {
+ assert(size >= sizeof(OopStorage), "precondition");
+ return NEW_C_HEAP_ARRAY(char, size, memflags);
+}
+
+void OopStorage::operator delete(void* obj, MEMFLAGS /* memflags */) {
+ FREE_C_HEAP_ARRAY(char, obj);
+}
+
+OopStorage::OopStorage(const char* name, MEMFLAGS memflags) :
_name(os::strdup(name)),
- _active_array(ActiveArray::create(initial_active_array_size)),
+ _active_array(ActiveArray::create(initial_active_array_size, memflags)),
_allocation_list(),
_deferred_updates(NULL),
_allocation_mutex(make_oopstorage_mutex(name, "alloc", Mutex::oopstorage)),
@@ -749,6 +762,7 @@ OopStorage::OopStorage(const char* name) :
_num_dead_callback(NULL),
_allocation_count(0),
_concurrent_iteration_count(0),
+ _memflags(memflags),
_needs_cleanup(false)
{
_active_array->increment_refcount();
@@ -971,6 +985,8 @@ size_t OopStorage::total_memory_usage() const {
return total_size;
}
+MEMFLAGS OopStorage::memflags() const { return _memflags; }
+
// Parallel iteration support
uint OopStorage::BasicParState::default_estimated_thread_count(bool concurrent) {
diff --git a/src/hotspot/share/gc/shared/oopStorage.hpp b/src/hotspot/share/gc/shared/oopStorage.hpp
index ebcef2faca6..86b9df7d2c1 100644
--- a/src/hotspot/share/gc/shared/oopStorage.hpp
+++ b/src/hotspot/share/gc/shared/oopStorage.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2021, 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
@@ -72,11 +72,14 @@ class outputStream;
// interactions for this protocol. Similarly, see the allocate() function for
// a discussion of allocation.
-class OopStorage : public CHeapObj<mtGC> {
+class OopStorage {
public:
- explicit OopStorage(const char* name);
+ explicit OopStorage(const char* name, MEMFLAGS memflags);
~OopStorage();
+ void* operator new(size_t size, MEMFLAGS memflags);
+ void operator delete(void* obj, MEMFLAGS memflags);
+
// These count and usage accessors are racy unless at a safepoint.
// The number of allocated and not yet released entries.
@@ -89,6 +92,9 @@ public:
// bookkeeping overhead, including this storage object.
size_t total_memory_usage() const;
+ // The memory type for allocations.
+ MEMFLAGS memflags() const;
+
enum EntryStatus {
INVALID_ENTRY,
UNALLOCATED_ENTRY,
@@ -251,6 +257,10 @@ private:
// mutable because this gets set even for const iteration.
mutable int _concurrent_iteration_count;
+ // The memory type for allocations.
+ MEMFLAGS _memflags;
+
+ // Flag indicating this storage object is a candidate for empty block deletion.
volatile bool _needs_cleanup;
bool try_add_block();
diff --git a/src/hotspot/share/gc/shared/oopStorage.inline.hpp b/src/hotspot/share/gc/shared/oopStorage.inline.hpp
index d0b11c4973c..7bb51e7d2c1 100644
--- a/src/hotspot/share/gc/shared/oopStorage.inline.hpp
+++ b/src/hotspot/share/gc/shared/oopStorage.inline.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2021, 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
@@ -26,6 +26,7 @@
#define SHARE_GC_SHARED_OOPSTORAGE_INLINE_HPP
#include "gc/shared/oopStorage.hpp"
+#include "memory/allocation.hpp"
#include "metaprogramming/conditional.hpp"
#include "metaprogramming/isConst.hpp"
#include "oops/oop.hpp"
@@ -57,7 +58,9 @@ class OopStorage::ActiveArray {
Block** block_ptr(size_t index);
public:
- static ActiveArray* create(size_t size, AllocFailType alloc_fail = AllocFailStrategy::EXIT_OOM);
+ static ActiveArray* create(size_t size,
+ MEMFLAGS memflags = mtGC,
+ AllocFailType alloc_fail = AllocFailStrategy::EXIT_OOM);
static void destroy(ActiveArray* ba);
inline Block* at(size_t i) const;
diff --git a/src/hotspot/share/gc/shared/oopStorageSet.cpp b/src/hotspot/share/gc/shared/oopStorageSet.cpp
index d8691b6d74e..d97d8cc7eeb 100644
--- a/src/hotspot/share/gc/shared/oopStorageSet.cpp
+++ b/src/hotspot/share/gc/shared/oopStorageSet.cpp
@@ -31,18 +31,18 @@
OopStorage* OopStorageSet::_storages[all_count] = {};
-OopStorage* OopStorageSet::create_strong(const char* name) {
+OopStorage* OopStorageSet::create_strong(const char* name, MEMFLAGS memflags) {
static uint registered_strong = 0;
assert(registered_strong < strong_count, "More registered strong storages than slots");
- OopStorage* storage = new OopStorage(name);
+ OopStorage* storage = new (memflags) OopStorage(name, memflags);
_storages[strong_start + registered_strong++] = storage;
return storage;
}
-OopStorage* OopStorageSet::create_weak(const char* name) {
+OopStorage* OopStorageSet::create_weak(const char* name, MEMFLAGS memflags) {
static uint registered_weak = 0;
assert(registered_weak < weak_count, "More registered strong storages than slots");
- OopStorage* storage = new OopStorage(name);
+ OopStorage* storage = new (memflags) OopStorage(name, memflags);
_storages[weak_start + registered_weak++] = storage;
return storage;
}
diff --git a/src/hotspot/share/gc/shared/oopStorageSet.hpp b/src/hotspot/share/gc/shared/oopStorageSet.hpp
index 8caba5e9f8e..b832dcf8407 100644
--- a/src/hotspot/share/gc/shared/oopStorageSet.hpp
+++ b/src/hotspot/share/gc/shared/oopStorageSet.hpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2021, 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
@@ -79,8 +79,8 @@ public:
static OopStorage* storage(WeakId id) { return get_storage(id); }
static OopStorage* storage(Id id) { return get_storage(id); }
- static OopStorage* create_strong(const char* name);
- static OopStorage* create_weak(const char* name);
+ static OopStorage* create_strong(const char* name, MEMFLAGS memflags);
+ static OopStorage* create_weak(const char* name, MEMFLAGS memflags);
// Support iteration over the storage objects.
template<typename StorageId> class Range;
diff --git a/src/hotspot/share/jfr/leakprofiler/sampling/objectSampler.cpp b/src/hotspot/share/jfr/leakprofiler/sampling/objectSampler.cpp
index 5443069a656..727a9bbc955 100644
--- a/src/hotspot/share/jfr/leakprofiler/sampling/objectSampler.cpp
+++ b/src/hotspot/share/jfr/leakprofiler/sampling/objectSampler.cpp
@@ -74,7 +74,7 @@ void ObjectSampler::oop_storage_gc_notification(size_t num_dead) {
}
bool ObjectSampler::create_oop_storage() {
- _oop_storage = OopStorageSet::create_weak("Weak JFR Old Object Samples");
+ _oop_storage = OopStorageSet::create_weak("Weak JFR Old Object Samples", mtTracing);
assert(_oop_storage != NULL, "invariant");
_oop_storage->register_num_dead_callback(&oop_storage_gc_notification);
return true;
diff --git a/src/hotspot/share/memory/universe.cpp b/src/hotspot/share/memory/universe.cpp
index 4870f76e020..2d9411fe56e 100644
--- a/src/hotspot/share/memory/universe.cpp
+++ b/src/hotspot/share/memory/universe.cpp
@@ -868,8 +868,8 @@ OopStorage* Universe::vm_global() {
}
void Universe::oopstorage_init() {
- Universe::_vm_global = OopStorageSet::create_strong("VM Global");
- Universe::_vm_weak = OopStorageSet::create_weak("VM Weak");
+ Universe::_vm_global = OopStorageSet::create_strong("VM Global", mtInternal);
+ Universe::_vm_weak = OopStorageSet::create_weak("VM Weak", mtInternal);
}
void universe_oopstorage_init() {
diff --git a/src/hotspot/share/prims/jvmtiExport.cpp b/src/hotspot/share/prims/jvmtiExport.cpp
index e7dba71a8b6..724dbffa277 100644
--- a/src/hotspot/share/prims/jvmtiExport.cpp
+++ b/src/hotspot/share/prims/jvmtiExport.cpp
@@ -699,8 +699,8 @@ OopStorage* JvmtiExport::weak_tag_storage() {
void JvmtiExport::initialize_oop_storage() {
// OopStorage needs to be created early in startup and unconditionally
// because of OopStorageSet static array indices.
- _jvmti_oop_storage = OopStorageSet::create_strong("JVMTI OopStorage");
- _weak_tag_storage = OopStorageSet::create_weak("JVMTI Tag Weak OopStorage");
+ _jvmti_oop_storage = OopStorageSet::create_strong("JVMTI OopStorage", mtServiceability);
+ _weak_tag_storage = OopStorageSet::create_weak("JVMTI Tag Weak OopStorage", mtServiceability);
_weak_tag_storage->register_num_dead_callback(&JvmtiTagMap::gc_notification);
}
diff --git a/src/hotspot/share/prims/resolvedMethodTable.cpp b/src/hotspot/share/prims/resolvedMethodTable.cpp
index b0c16148ca0..5e5761094f1 100644
--- a/src/hotspot/share/prims/resolvedMethodTable.cpp
+++ b/src/hotspot/share/prims/resolvedMethodTable.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2021, 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
@@ -102,7 +102,7 @@ void ResolvedMethodTable::create_table() {
_local_table = new ResolvedMethodTableHash(ResolvedMethodTableSizeLog, END_SIZE, GROW_HINT);
log_trace(membername, table)("Start size: " SIZE_FORMAT " (" SIZE_FORMAT ")",
_current_size, ResolvedMethodTableSizeLog);
- _oop_storage = OopStorageSet::create_weak("ResolvedMethodTable Weak");
+ _oop_storage = OopStorageSet::create_weak("ResolvedMethodTable Weak", mtClass);
_oop_storage->register_num_dead_callback(&gc_notification);
}
diff --git a/src/hotspot/share/runtime/jniHandles.cpp b/src/hotspot/share/runtime/jniHandles.cpp
index 4d7be6b4676..183dbbe7560 100644
--- a/src/hotspot/share/runtime/jniHandles.cpp
+++ b/src/hotspot/share/runtime/jniHandles.cpp
@@ -51,8 +51,8 @@ OopStorage* JNIHandles::_global_handles = NULL;
OopStorage* JNIHandles::_weak_global_handles = NULL;
void jni_handles_init() {
- JNIHandles::_global_handles = OopStorageSet::create_strong("JNI Global");
- JNIHandles::_weak_global_handles = OopStorageSet::create_weak("JNI Weak");
+ JNIHandles::_global_handles = OopStorageSet::create_strong("JNI Global", mtInternal);
+ JNIHandles::_weak_global_handles = OopStorageSet::create_weak("JNI Weak", mtInternal);
}
jobject JNIHandles::make_local(oop obj) {
diff --git a/src/hotspot/share/runtime/objectMonitor.cpp b/src/hotspot/share/runtime/objectMonitor.cpp
index 001f1c63435..d2194e38dd9 100644
--- a/src/hotspot/share/runtime/objectMonitor.cpp
+++ b/src/hotspot/share/runtime/objectMonitor.cpp
@@ -2187,7 +2187,7 @@ void ObjectMonitor::Initialize() {
#undef NEWPERFVARIABLE
}
- _oop_storage = OopStorageSet::create_weak("ObjectSynchronizer Weak");
+ _oop_storage = OopStorageSet::create_weak("ObjectSynchronizer Weak", mtSynchronizer);
DEBUG_ONLY(InitDone = true;)
}
diff --git a/src/hotspot/share/runtime/thread.cpp b/src/hotspot/share/runtime/thread.cpp
index b7007ff09e2..c1ba0515bbc 100644
--- a/src/hotspot/share/runtime/thread.cpp
+++ b/src/hotspot/share/runtime/thread.cpp
@@ -3143,7 +3143,7 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
#endif // INCLUDE_JVMCI
// Initialize OopStorage for threadObj
- _thread_oop_storage = OopStorageSet::create_strong("Thread OopStorage");
+ _thread_oop_storage = OopStorageSet::create_strong("Thread OopStorage", mtThread);
// Attach the main thread to this os thread
JavaThread* main_thread = new JavaThread();
diff --git a/src/hotspot/share/services/threadService.cpp b/src/hotspot/share/services/threadService.cpp
index c0476bba8f2..4cb216e9fbf 100644
--- a/src/hotspot/share/services/threadService.cpp
+++ b/src/hotspot/share/services/threadService.cpp
@@ -105,7 +105,8 @@ void ThreadService::init() {
_thread_allocated_memory_enabled = true; // Always on, so enable it
// Initialize OopStorage for thread stack sampling walking
- _thread_service_storage = OopStorageSet::create_strong("ThreadService OopStorage");
+ _thread_service_storage = OopStorageSet::create_strong("ThreadService OopStorage",
+ mtServiceability);
}
void ThreadService::reset_peak_thread_count() {
diff --git a/test/hotspot/gtest/gc/shared/test_oopStorage.cpp b/test/hotspot/gtest/gc/shared/test_oopStorage.cpp
index 5fdea55980b..f6420fe93f0 100644
--- a/test/hotspot/gtest/gc/shared/test_oopStorage.cpp
+++ b/test/hotspot/gtest/gc/shared/test_oopStorage.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2021, 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
@@ -190,7 +190,7 @@ public:
};
OopStorageTest::OopStorageTest() :
- _storage("Test Storage")
+ _storage("Test Storage", mtGC)
{ }
OopStorageTest::~OopStorageTest() {
diff --git a/test/hotspot/gtest/gc/shared/test_oopStorage_parperf.cpp b/test/hotspot/gtest/gc/shared/test_oopStorage_parperf.cpp
index 31d0c4fcc80..3d35921aa62 100644
--- a/test/hotspot/gtest/gc/shared/test_oopStorage_parperf.cpp
+++ b/test/hotspot/gtest/gc/shared/test_oopStorage_parperf.cpp
@@ -88,7 +88,7 @@ WorkGang* OopStorageParIterPerf::workers() const {
}
OopStorageParIterPerf::OopStorageParIterPerf() :
- _storage("Test Storage")
+ _storage("Test Storage", mtGC)
{
for (size_t i = 0; i < _storage_entries; ++i) {
_entries[i] = _storage.allocate();