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

Zhengyu Gu zgu at redhat.com
Tue Nov 27 15:24:46 UTC 2018



On 11/27/18 9:00 AM, Aleksey Shipilev wrote:
> 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"?

No, this is placement "new", which constructs object from existing memory.

https://www.geeksforgeeks.org/placement-new-operator-cpp/

-Zhengyu

> 
> 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
> 


More information about the hotspot-gc-dev mailing list