1 /* |
1 /* |
2 * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
208 return (addr == base() && sz == size()); |
208 return (addr == base() && sz == size()); |
209 } |
209 } |
210 |
210 |
211 |
211 |
212 inline bool overlap_region(address addr, size_t sz) const { |
212 inline bool overlap_region(address addr, size_t sz) const { |
|
213 assert(sz > 0, "Invalid size"); |
|
214 assert(size() > 0, "Invalid size"); |
213 VirtualMemoryRegion rgn(addr, sz); |
215 VirtualMemoryRegion rgn(addr, sz); |
214 return contain_address(addr) || |
216 return contain_address(addr) || |
215 contain_address(addr + sz - 1) || |
217 contain_address(addr + sz - 1) || |
216 rgn.contain_address(base()) || |
218 rgn.contain_address(base()) || |
217 rgn.contain_address(end() - 1); |
219 rgn.contain_address(end() - 1); |
293 _committed_regions; |
295 _committed_regions; |
294 |
296 |
295 NativeCallStack _stack; |
297 NativeCallStack _stack; |
296 MEMFLAGS _flag; |
298 MEMFLAGS _flag; |
297 |
299 |
298 bool _all_committed; |
|
299 |
|
300 public: |
300 public: |
301 ReservedMemoryRegion(address base, size_t size, const NativeCallStack& stack, |
301 ReservedMemoryRegion(address base, size_t size, const NativeCallStack& stack, |
302 MEMFLAGS flag = mtNone) : |
302 MEMFLAGS flag = mtNone) : |
303 VirtualMemoryRegion(base, size), _stack(stack), _flag(flag), |
303 VirtualMemoryRegion(base, size), _stack(stack), _flag(flag) { } |
304 _all_committed(false) { } |
|
305 |
304 |
306 |
305 |
307 ReservedMemoryRegion(address base, size_t size) : |
306 ReservedMemoryRegion(address base, size_t size) : |
308 VirtualMemoryRegion(base, size), _stack(NativeCallStack::EMPTY_STACK), _flag(mtNone), |
307 VirtualMemoryRegion(base, size), _stack(NativeCallStack::EMPTY_STACK), _flag(mtNone) { } |
309 _all_committed(false) { } |
|
310 |
308 |
311 // Copy constructor |
309 // Copy constructor |
312 ReservedMemoryRegion(const ReservedMemoryRegion& rr) : |
310 ReservedMemoryRegion(const ReservedMemoryRegion& rr) : |
313 VirtualMemoryRegion(rr.base(), rr.size()) { |
311 VirtualMemoryRegion(rr.base(), rr.size()) { |
314 *this = rr; |
312 *this = rr; |
345 |
343 |
346 // move committed regions that higher than specified address to |
344 // move committed regions that higher than specified address to |
347 // the new region |
345 // the new region |
348 void move_committed_regions(address addr, ReservedMemoryRegion& rgn); |
346 void move_committed_regions(address addr, ReservedMemoryRegion& rgn); |
349 |
347 |
350 inline bool all_committed() const { return _all_committed; } |
|
351 void set_all_committed(bool b); |
|
352 |
|
353 CommittedRegionIterator iterate_committed_regions() const { |
348 CommittedRegionIterator iterate_committed_regions() const { |
354 return CommittedRegionIterator(_committed_regions.head()); |
349 return CommittedRegionIterator(_committed_regions.head()); |
355 } |
350 } |
356 |
351 |
357 ReservedMemoryRegion& operator= (const ReservedMemoryRegion& other) { |
352 ReservedMemoryRegion& operator= (const ReservedMemoryRegion& other) { |
358 set_base(other.base()); |
353 set_base(other.base()); |
359 set_size(other.size()); |
354 set_size(other.size()); |
360 |
355 |
361 _stack = *other.call_stack(); |
356 _stack = *other.call_stack(); |
362 _flag = other.flag(); |
357 _flag = other.flag(); |
363 _all_committed = other.all_committed(); |
358 |
364 if (other.all_committed()) { |
359 CommittedRegionIterator itr = other.iterate_committed_regions(); |
365 set_all_committed(true); |
360 const CommittedMemoryRegion* rgn = itr.next(); |
366 } else { |
361 while (rgn != NULL) { |
367 CommittedRegionIterator itr = other.iterate_committed_regions(); |
362 _committed_regions.add(*rgn); |
368 const CommittedMemoryRegion* rgn = itr.next(); |
363 rgn = itr.next(); |
369 while (rgn != NULL) { |
364 } |
370 _committed_regions.add(*rgn); |
365 |
371 rgn = itr.next(); |
|
372 } |
|
373 } |
|
374 return *this; |
366 return *this; |
375 } |
367 } |
376 |
368 |
377 private: |
369 private: |
378 // The committed region contains the uncommitted region, subtract the uncommitted |
370 // The committed region contains the uncommitted region, subtract the uncommitted |
394 virtual bool do_allocation_site(const ReservedMemoryRegion* rgn) { return false; } |
386 virtual bool do_allocation_site(const ReservedMemoryRegion* rgn) { return false; } |
395 }; |
387 }; |
396 |
388 |
397 // Main class called from MemTracker to track virtual memory allocations, commits and releases. |
389 // Main class called from MemTracker to track virtual memory allocations, commits and releases. |
398 class VirtualMemoryTracker : AllStatic { |
390 class VirtualMemoryTracker : AllStatic { |
|
391 friend class VirtualMemoryTrackerTest; |
|
392 |
399 public: |
393 public: |
400 static bool initialize(NMT_TrackingLevel level); |
394 static bool initialize(NMT_TrackingLevel level); |
401 |
395 |
402 // Late phase initialization |
396 // Late phase initialization |
403 static bool late_initialize(NMT_TrackingLevel level); |
397 static bool late_initialize(NMT_TrackingLevel level); |
404 |
398 |
405 static bool add_reserved_region (address base_addr, size_t size, const NativeCallStack& stack, |
399 static bool add_reserved_region (address base_addr, size_t size, const NativeCallStack& stack, MEMFLAGS flag = mtNone); |
406 MEMFLAGS flag = mtNone, bool all_committed = false); |
|
407 |
400 |
408 static bool add_committed_region (address base_addr, size_t size, const NativeCallStack& stack); |
401 static bool add_committed_region (address base_addr, size_t size, const NativeCallStack& stack); |
409 static bool remove_uncommitted_region (address base_addr, size_t size); |
402 static bool remove_uncommitted_region (address base_addr, size_t size); |
410 static bool remove_released_region (address base_addr, size_t size); |
403 static bool remove_released_region (address base_addr, size_t size); |
411 static void set_reserved_region_type (address addr, MEMFLAGS flag); |
404 static void set_reserved_region_type (address addr, MEMFLAGS flag); |