Skip to content

Commit 04278e6

Browse files
committed
8301564: Non-C-heap allocated ResourceHashtable keys and values must have trivial destructor
Reviewed-by: coleenp, jvernee
1 parent b00b70c commit 04278e6

File tree

6 files changed

+21
-7
lines changed

6 files changed

+21
-7
lines changed

src/hotspot/cpu/aarch64/codeBuffer_aarch64.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void CodeBuffer::share_trampoline_for(address dest, int caller_offset) {
3030
if (_shared_trampoline_requests == nullptr) {
3131
constexpr unsigned init_size = 8;
3232
constexpr unsigned max_size = 256;
33-
_shared_trampoline_requests = new SharedTrampolineRequests(init_size, max_size);
33+
_shared_trampoline_requests = new (mtCompiler)SharedTrampolineRequests(init_size, max_size);
3434
}
3535

3636
bool created;

src/hotspot/cpu/riscv/codeBuffer_riscv.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void CodeBuffer::share_trampoline_for(address dest, int caller_offset) {
3232
if (_shared_trampoline_requests == nullptr) {
3333
constexpr unsigned init_size = 8;
3434
constexpr unsigned max_size = 256;
35-
_shared_trampoline_requests = new SharedTrampolineRequests(init_size, max_size);
35+
_shared_trampoline_requests = new (mtCompiler)SharedTrampolineRequests(init_size, max_size);
3636
}
3737

3838
bool created;

src/hotspot/share/asm/codeBuffer.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -138,6 +138,10 @@ CodeBuffer::~CodeBuffer() {
138138
delete cb->_overflow_arena;
139139
}
140140

141+
if (_shared_trampoline_requests != nullptr) {
142+
delete _shared_trampoline_requests;
143+
}
144+
141145
NOT_PRODUCT(clear_strings());
142146
}
143147

src/hotspot/share/asm/codeBuffer.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -403,7 +403,7 @@ class CodeBuffer: public StackObj DEBUG_ONLY(COMMA private Scrubber) {
403403
};
404404

405405
typedef LinkedListImpl<int> Offsets;
406-
typedef ResizeableResourceHashtable<address, Offsets> SharedTrampolineRequests;
406+
typedef ResizeableResourceHashtable<address, Offsets, AnyObj::C_HEAP, mtCompiler> SharedTrampolineRequests;
407407

408408
private:
409409
enum {

src/hotspot/share/classfile/classLoaderStats.hpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class ClassLoaderStatsClosure : public CLDClosure {
112112
}
113113

114114
typedef ResourceHashtable<oop, ClassLoaderStats,
115-
256, AnyObj::RESOURCE_AREA, mtInternal,
115+
256, AnyObj::C_HEAP, mtStatistics,
116116
ClassLoaderStatsClosure::oop_hash> StatsTable;
117117

118118
outputStream* _out;
@@ -125,13 +125,17 @@ class ClassLoaderStatsClosure : public CLDClosure {
125125
public:
126126
ClassLoaderStatsClosure(outputStream* out) :
127127
_out(out),
128-
_stats(new StatsTable()),
128+
_stats(new (mtStatistics)StatsTable()),
129129
_total_loaders(0),
130130
_total_classes(0),
131131
_total_chunk_sz(0),
132132
_total_block_sz(0) {
133133
}
134134

135+
~ClassLoaderStatsClosure() {
136+
delete _stats;
137+
}
138+
135139
virtual void do_cld(ClassLoaderData* cld);
136140
virtual bool do_entry(oop const& key, ClassLoaderStats const& cls);
137141
void print();

src/hotspot/share/utilities/resourceHash.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "utilities/numberSeq.hpp"
3131
#include "utilities/tableStatistics.hpp"
3232

33+
#include <type_traits>
34+
3335
template<typename K, typename V>
3436
class ResourceHashtableNode : public AnyObj {
3537
public:
@@ -55,6 +57,10 @@ template<
5557
bool (*EQUALS)(K const&, K const&)
5658
>
5759
class ResourceHashtableBase : public STORAGE {
60+
static_assert(ALLOC_TYPE == AnyObj::C_HEAP || std::is_trivially_destructible<K>::value,
61+
"Destructor for K is only called with C_HEAP");
62+
static_assert(ALLOC_TYPE == AnyObj::C_HEAP || std::is_trivially_destructible<V>::value,
63+
"Destructor for V is only called with C_HEAP");
5864
using Node = ResourceHashtableNode<K, V>;
5965
private:
6066
int _number_of_entries;

0 commit comments

Comments
 (0)