Skip to content

Commit

Permalink
8301564: Non-C-heap allocated ResourceHashtable keys and values must …
Browse files Browse the repository at this point in the history
…have trivial destructor

Reviewed-by: coleenp, jvernee
  • Loading branch information
iklam committed Feb 2, 2023
1 parent b00b70c commit 04278e6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/codeBuffer_aarch64.cpp
Expand Up @@ -30,7 +30,7 @@ void CodeBuffer::share_trampoline_for(address dest, int caller_offset) {
if (_shared_trampoline_requests == nullptr) {
constexpr unsigned init_size = 8;
constexpr unsigned max_size = 256;
_shared_trampoline_requests = new SharedTrampolineRequests(init_size, max_size);
_shared_trampoline_requests = new (mtCompiler)SharedTrampolineRequests(init_size, max_size);
}

bool created;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/codeBuffer_riscv.cpp
Expand Up @@ -32,7 +32,7 @@ void CodeBuffer::share_trampoline_for(address dest, int caller_offset) {
if (_shared_trampoline_requests == nullptr) {
constexpr unsigned init_size = 8;
constexpr unsigned max_size = 256;
_shared_trampoline_requests = new SharedTrampolineRequests(init_size, max_size);
_shared_trampoline_requests = new (mtCompiler)SharedTrampolineRequests(init_size, max_size);
}

bool created;
Expand Down
6 changes: 5 additions & 1 deletion src/hotspot/share/asm/codeBuffer.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, 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
Expand Down Expand Up @@ -138,6 +138,10 @@ CodeBuffer::~CodeBuffer() {
delete cb->_overflow_arena;
}

if (_shared_trampoline_requests != nullptr) {
delete _shared_trampoline_requests;
}

NOT_PRODUCT(clear_strings());
}

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/asm/codeBuffer.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, 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
Expand Down Expand Up @@ -403,7 +403,7 @@ class CodeBuffer: public StackObj DEBUG_ONLY(COMMA private Scrubber) {
};

typedef LinkedListImpl<int> Offsets;
typedef ResizeableResourceHashtable<address, Offsets> SharedTrampolineRequests;
typedef ResizeableResourceHashtable<address, Offsets, AnyObj::C_HEAP, mtCompiler> SharedTrampolineRequests;

private:
enum {
Expand Down
8 changes: 6 additions & 2 deletions src/hotspot/share/classfile/classLoaderStats.hpp
Expand Up @@ -112,7 +112,7 @@ class ClassLoaderStatsClosure : public CLDClosure {
}

typedef ResourceHashtable<oop, ClassLoaderStats,
256, AnyObj::RESOURCE_AREA, mtInternal,
256, AnyObj::C_HEAP, mtStatistics,
ClassLoaderStatsClosure::oop_hash> StatsTable;

outputStream* _out;
Expand All @@ -125,13 +125,17 @@ class ClassLoaderStatsClosure : public CLDClosure {
public:
ClassLoaderStatsClosure(outputStream* out) :
_out(out),
_stats(new StatsTable()),
_stats(new (mtStatistics)StatsTable()),
_total_loaders(0),
_total_classes(0),
_total_chunk_sz(0),
_total_block_sz(0) {
}

~ClassLoaderStatsClosure() {
delete _stats;
}

virtual void do_cld(ClassLoaderData* cld);
virtual bool do_entry(oop const& key, ClassLoaderStats const& cls);
void print();
Expand Down
6 changes: 6 additions & 0 deletions src/hotspot/share/utilities/resourceHash.hpp
Expand Up @@ -30,6 +30,8 @@
#include "utilities/numberSeq.hpp"
#include "utilities/tableStatistics.hpp"

#include <type_traits>

template<typename K, typename V>
class ResourceHashtableNode : public AnyObj {
public:
Expand All @@ -55,6 +57,10 @@ template<
bool (*EQUALS)(K const&, K const&)
>
class ResourceHashtableBase : public STORAGE {
static_assert(ALLOC_TYPE == AnyObj::C_HEAP || std::is_trivially_destructible<K>::value,
"Destructor for K is only called with C_HEAP");
static_assert(ALLOC_TYPE == AnyObj::C_HEAP || std::is_trivially_destructible<V>::value,
"Destructor for V is only called with C_HEAP");
using Node = ResourceHashtableNode<K, V>;
private:
int _number_of_entries;
Expand Down

1 comment on commit 04278e6

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.