Skip to content

Commit 28c6300

Browse files
author
Thomas Schatzl
committedFeb 18, 2020
8238999: Remove MemRegion custom new/delete operator overloads
Reviewed-by: kbarrett, jiangli, iklam
1 parent 301a2e1 commit 28c6300

File tree

5 files changed

+18
-48
lines changed

5 files changed

+18
-48
lines changed
 

‎src/hotspot/share/gc/g1/g1ConcurrentMark.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,20 +261,15 @@ void G1CMMarkStack::set_empty() {
261261
}
262262

263263
G1CMRootMemRegions::G1CMRootMemRegions(uint const max_regions) :
264-
_root_regions(NULL),
264+
_root_regions(MemRegion::create_array(max_regions, mtGC)),
265265
_max_regions(max_regions),
266266
_num_root_regions(0),
267267
_claimed_root_regions(0),
268268
_scan_in_progress(false),
269-
_should_abort(false) {
270-
_root_regions = new MemRegion[_max_regions];
271-
if (_root_regions == NULL) {
272-
vm_exit_during_initialization("Could not allocate root MemRegion set.");
273-
}
274-
}
269+
_should_abort(false) { }
275270

276271
G1CMRootMemRegions::~G1CMRootMemRegions() {
277-
delete[] _root_regions;
272+
FREE_C_HEAP_ARRAY(MemRegion, _root_regions);
278273
}
279274

280275
void G1CMRootMemRegions::reset() {

‎src/hotspot/share/gc/shared/cardTable.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,19 @@ CardTable::CardTable(MemRegion whole_heap, bool conc_scan) :
5151
_byte_map(NULL),
5252
_byte_map_base(NULL),
5353
_cur_covered_regions(0),
54-
_covered(NULL),
55-
_committed(NULL),
54+
_covered(MemRegion::create_array(_max_covered_regions, mtGC)),
55+
_committed(MemRegion::create_array(_max_covered_regions, mtGC)),
5656
_guard_region()
5757
{
5858
assert((uintptr_t(_whole_heap.start()) & (card_size - 1)) == 0, "heap must start at card boundary");
5959
assert((uintptr_t(_whole_heap.end()) & (card_size - 1)) == 0, "heap must end at card boundary");
6060

6161
assert(card_size <= 512, "card_size must be less than 512"); // why?
62-
63-
_covered = new MemRegion[_max_covered_regions];
64-
if (_covered == NULL) {
65-
vm_exit_during_initialization("Could not allocate card table covered region set.");
66-
}
6762
}
6863

6964
CardTable::~CardTable() {
70-
if (_covered) {
71-
delete[] _covered;
72-
_covered = NULL;
73-
}
74-
if (_committed) {
75-
delete[] _committed;
76-
_committed = NULL;
77-
}
65+
FREE_C_HEAP_ARRAY(MemRegion, _covered);
66+
FREE_C_HEAP_ARRAY(MemRegion, _committed);
7867
}
7968

8069
void CardTable::initialize() {
@@ -87,10 +76,6 @@ void CardTable::initialize() {
8776
HeapWord* high_bound = _whole_heap.end();
8877

8978
_cur_covered_regions = 0;
90-
_committed = new MemRegion[_max_covered_regions];
91-
if (_committed == NULL) {
92-
vm_exit_during_initialization("Could not allocate card table committed region set.");
93-
}
9479

9580
const size_t rs_align = _page_size == (size_t) os::vm_page_size() ? 0 :
9681
MAX2(_page_size, (size_t) os::vm_allocation_granularity());

‎src/hotspot/share/memory/filemap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ void FileMapInfo::map_heap_regions() {
17471747

17481748
bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first,
17491749
int max, int* num, bool is_open_archive) {
1750-
MemRegion * regions = new MemRegion[max];
1750+
MemRegion* regions = MemRegion::create_array(max, mtInternal);
17511751
FileMapRegion* si;
17521752
int region_num = 0;
17531753

‎src/hotspot/share/memory/memRegion.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2020, 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
@@ -102,19 +102,10 @@ MemRegion MemRegion::minus(const MemRegion mr2) const {
102102
return MemRegion();
103103
}
104104

105-
void* MemRegion::operator new(size_t size) throw() {
106-
return (address)AllocateHeap(size, mtGC, CURRENT_PC,
107-
AllocFailStrategy::RETURN_NULL);
108-
}
109-
110-
void* MemRegion::operator new [](size_t size) throw() {
111-
return (address)AllocateHeap(size, mtGC, CURRENT_PC,
112-
AllocFailStrategy::RETURN_NULL);
113-
}
114-
void MemRegion::operator delete(void* p) {
115-
FreeHeap(p);
116-
}
117-
118-
void MemRegion::operator delete [](void* p) {
119-
FreeHeap(p);
105+
MemRegion* MemRegion::create_array(uint length, MEMFLAGS flags) {
106+
MemRegion* result = NEW_C_HEAP_ARRAY(MemRegion, length, flags);
107+
for (uint i = 0; i < length; i++) {
108+
::new (&result[i]) MemRegion();
109+
}
110+
return result;
120111
}

‎src/hotspot/share/memory/memRegion.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,9 @@ class MemRegion {
9292
size_t word_size() const { return _word_size; }
9393

9494
bool is_empty() const { return word_size() == 0; }
95-
void* operator new(size_t size) throw();
96-
void* operator new [](size_t size) throw();
97-
void operator delete(void* p);
98-
void operator delete [](void* p);
95+
96+
// Creates and initializes an array of MemRegions of the given length.
97+
static MemRegion* create_array(uint length, MEMFLAGS flags);
9998
};
10099

101100
// For iteration over MemRegion's.

0 commit comments

Comments
 (0)
Please sign in to comment.