changeset 58084:26cdbd64d461

8238999: Remove MemRegion custom new/delete operator overloads Reviewed-by: kbarrett, jiangli, iklam
author tschatzl
date Tue, 18 Feb 2020 10:59:38 +0100
parents 8124177833ec
children 7d73b376f5d2
files src/hotspot/share/gc/g1/g1ConcurrentMark.cpp src/hotspot/share/gc/shared/cardTable.cpp src/hotspot/share/memory/filemap.cpp src/hotspot/share/memory/memRegion.cpp src/hotspot/share/memory/memRegion.hpp
diffstat 5 files changed, 18 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp	Tue Feb 18 09:42:30 2020 +0000
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.cpp	Tue Feb 18 10:59:38 2020 +0100
@@ -261,20 +261,15 @@
 }
 
 G1CMRootMemRegions::G1CMRootMemRegions(uint const max_regions) :
-    _root_regions(NULL),
+    _root_regions(MemRegion::create_array(max_regions, mtGC)),
     _max_regions(max_regions),
     _num_root_regions(0),
     _claimed_root_regions(0),
     _scan_in_progress(false),
-    _should_abort(false) {
-  _root_regions = new MemRegion[_max_regions];
-  if (_root_regions == NULL) {
-    vm_exit_during_initialization("Could not allocate root MemRegion set.");
-  }
-}
+    _should_abort(false) { }
 
 G1CMRootMemRegions::~G1CMRootMemRegions() {
-  delete[] _root_regions;
+  FREE_C_HEAP_ARRAY(MemRegion, _root_regions);
 }
 
 void G1CMRootMemRegions::reset() {
--- a/src/hotspot/share/gc/shared/cardTable.cpp	Tue Feb 18 09:42:30 2020 +0000
+++ b/src/hotspot/share/gc/shared/cardTable.cpp	Tue Feb 18 10:59:38 2020 +0100
@@ -51,30 +51,19 @@
   _byte_map(NULL),
   _byte_map_base(NULL),
   _cur_covered_regions(0),
-  _covered(NULL),
-  _committed(NULL),
+  _covered(MemRegion::create_array(_max_covered_regions, mtGC)),
+  _committed(MemRegion::create_array(_max_covered_regions, mtGC)),
   _guard_region()
 {
   assert((uintptr_t(_whole_heap.start())  & (card_size - 1))  == 0, "heap must start at card boundary");
   assert((uintptr_t(_whole_heap.end()) & (card_size - 1))  == 0, "heap must end at card boundary");
 
   assert(card_size <= 512, "card_size must be less than 512"); // why?
-
-  _covered = new MemRegion[_max_covered_regions];
-  if (_covered == NULL) {
-    vm_exit_during_initialization("Could not allocate card table covered region set.");
-  }
 }
 
 CardTable::~CardTable() {
-  if (_covered) {
-    delete[] _covered;
-    _covered = NULL;
-  }
-  if (_committed) {
-    delete[] _committed;
-    _committed = NULL;
-  }
+  FREE_C_HEAP_ARRAY(MemRegion, _covered);
+  FREE_C_HEAP_ARRAY(MemRegion, _committed);
 }
 
 void CardTable::initialize() {
@@ -87,10 +76,6 @@
   HeapWord* high_bound = _whole_heap.end();
 
   _cur_covered_regions = 0;
-  _committed = new MemRegion[_max_covered_regions];
-  if (_committed == NULL) {
-    vm_exit_during_initialization("Could not allocate card table committed region set.");
-  }
 
   const size_t rs_align = _page_size == (size_t) os::vm_page_size() ? 0 :
     MAX2(_page_size, (size_t) os::vm_allocation_granularity());
--- a/src/hotspot/share/memory/filemap.cpp	Tue Feb 18 09:42:30 2020 +0000
+++ b/src/hotspot/share/memory/filemap.cpp	Tue Feb 18 10:59:38 2020 +0100
@@ -1747,7 +1747,7 @@
 
 bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first,
                                 int max, int* num, bool is_open_archive) {
-  MemRegion * regions = new MemRegion[max];
+  MemRegion* regions = MemRegion::create_array(max, mtInternal);
   FileMapRegion* si;
   int region_num = 0;
 
--- a/src/hotspot/share/memory/memRegion.cpp	Tue Feb 18 09:42:30 2020 +0000
+++ b/src/hotspot/share/memory/memRegion.cpp	Tue Feb 18 10:59:38 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2020, 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,19 +102,10 @@
   return MemRegion();
 }
 
-void* MemRegion::operator new(size_t size) throw() {
-  return (address)AllocateHeap(size, mtGC, CURRENT_PC,
-    AllocFailStrategy::RETURN_NULL);
+MemRegion* MemRegion::create_array(uint length, MEMFLAGS flags) {
+  MemRegion* result = NEW_C_HEAP_ARRAY(MemRegion, length, flags);
+  for (uint i = 0; i < length; i++) {
+    ::new (&result[i]) MemRegion();
+  }
+  return result;
 }
-
-void* MemRegion::operator new [](size_t size) throw() {
-  return (address)AllocateHeap(size, mtGC, CURRENT_PC,
-    AllocFailStrategy::RETURN_NULL);
-}
-void  MemRegion::operator delete(void* p) {
-  FreeHeap(p);
-}
-
-void  MemRegion::operator delete [](void* p) {
-  FreeHeap(p);
-}
--- a/src/hotspot/share/memory/memRegion.hpp	Tue Feb 18 09:42:30 2020 +0000
+++ b/src/hotspot/share/memory/memRegion.hpp	Tue Feb 18 10:59:38 2020 +0100
@@ -92,10 +92,9 @@
   size_t word_size() const { return _word_size; }
 
   bool is_empty() const { return word_size() == 0; }
-  void* operator new(size_t size) throw();
-  void* operator new [](size_t size) throw();
-  void  operator delete(void* p);
-  void  operator delete [](void* p);
+
+  // Creates and initializes an array of MemRegions of the given length.
+  static MemRegion* create_array(uint length, MEMFLAGS flags);
 };
 
 // For iteration over MemRegion's.