RFR(XS): JDK-8214272: Don't use memset to initialize arrays of MemoryUsage in memoryManager.cpp

Aleksey Shipilev shade at redhat.com
Tue Nov 27 14:00:10 UTC 2018


On 11/27/18 2:51 PM, Dmitry Chuyko wrote:
> rfe: https://bugs.openjdk.java.net/browse/JDK-8214272
> webrev: http://cr.openjdk.java.net/~dchuyko/8214272/webrev.00/

Ummmm. Aren't you leaking memory by calling "new" without "delete"?

Consider this instead:

diff -r a554db76b2e9 src/hotspot/share/services/memoryManager.cpp
--- a/src/hotspot/share/services/memoryManager.cpp      Fri Nov 23 11:22:31 2018 +0100
+++ b/src/hotspot/share/services/memoryManager.cpp      Tue Nov 27 14:56:09 2018 +0100
@@ -169,7 +169,8 @@
   _start_time = 0L;
   _end_time = 0L;
-  size_t len = _usage_array_size * sizeof(MemoryUsage);
-  memset(_before_gc_usage_array, 0, len);
-  memset(_after_gc_usage_array, 0, len);
+  for (int i = 0; i < _usage_array_size; i++) {
+    _before_gc_usage_array[i] = MemoryUsage();
+    _after_gc_usage_array[i]  = MemoryUsage();
+  }
 }

See, for example:
 https://bugs.openjdk.java.net/browse/JDK-8213745

-Aleksey

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://mail.openjdk.java.net/pipermail/hotspot-gc-dev/attachments/20181127/8ee09294/signature.asc>


More information about the hotspot-gc-dev mailing list