Mercurial > hg > graal-compiler
comparison src/share/vm/services/memPtr.hpp @ 6882:716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
Summary: Enhanced virtual memory tracking to track committed regions as well as reserved regions, so NMT now can generate virtual memory map.
Reviewed-by: acorn, coleenp
author | zgu |
---|---|
date | Fri, 19 Oct 2012 21:40:07 -0400 |
parents | e5bf1c79ed5b |
children | 69ad7823b1ca |
comparison
equal
deleted
inserted
replaced
6879:8ebcedb7604d | 6882:716c64bda5ba |
---|---|
289 | 289 |
290 // if this record is a tagging record of a virtual memory block | 290 // if this record is a tagging record of a virtual memory block |
291 inline bool is_type_tagging_record() const { | 291 inline bool is_type_tagging_record() const { |
292 return is_virtual_memory_type_record(_flags); | 292 return is_virtual_memory_type_record(_flags); |
293 } | 293 } |
294 | |
295 // if the two memory pointer records actually represent the same | |
296 // memory block | |
297 inline bool is_same_region(const MemPointerRecord* other) const { | |
298 return (addr() == other->addr() && size() == other->size()); | |
299 } | |
300 | |
301 // if this memory region fully contains another one | |
302 inline bool contains_region(const MemPointerRecord* other) const { | |
303 return contains_region(other->addr(), other->size()); | |
304 } | |
305 | |
306 // if this memory region fully contains specified memory range | |
307 inline bool contains_region(address add, size_t sz) const { | |
308 return (addr() <= add && addr() + size() >= add + sz); | |
309 } | |
310 | |
311 inline bool contains_address(address add) const { | |
312 return (addr() <= add && addr() + size() > add); | |
313 } | |
294 }; | 314 }; |
295 | 315 |
296 // MemPointerRecordEx also records callsite pc, from where | 316 // MemPointerRecordEx also records callsite pc, from where |
297 // the memory block is allocated | 317 // the memory block is allocated |
298 class MemPointerRecordEx : public MemPointerRecord { | 318 class MemPointerRecordEx : public MemPointerRecord { |
319 MemPointerRecord::operator=(*mp); | 339 MemPointerRecord::operator=(*mp); |
320 _pc = 0; | 340 _pc = 0; |
321 } | 341 } |
322 }; | 342 }; |
323 | 343 |
324 // a virtual memory region | 344 // a virtual memory region. The region can represent a reserved |
345 // virtual memory region or a committed memory region | |
325 class VMMemRegion : public MemPointerRecord { | 346 class VMMemRegion : public MemPointerRecord { |
326 private: | |
327 // committed size | |
328 size_t _committed_size; | |
329 | |
330 public: | 347 public: |
331 VMMemRegion(): _committed_size(0) { } | 348 VMMemRegion() { } |
332 | 349 |
333 void init(const MemPointerRecord* mp) { | 350 void init(const MemPointerRecord* mp) { |
334 assert(mp->is_vm_pointer(), "not virtual memory pointer"); | 351 assert(mp->is_vm_pointer(), "Sanity check"); |
335 _addr = mp->addr(); | 352 _addr = mp->addr(); |
336 if (mp->is_commit_record() || mp->is_uncommit_record()) { | |
337 _committed_size = mp->size(); | |
338 set_size(_committed_size); | |
339 } else { | |
340 set_size(mp->size()); | 353 set_size(mp->size()); |
341 _committed_size = 0; | |
342 } | |
343 set_flags(mp->flags()); | 354 set_flags(mp->flags()); |
344 } | 355 } |
345 | 356 |
346 VMMemRegion& operator=(const VMMemRegion& other) { | 357 VMMemRegion& operator=(const VMMemRegion& other) { |
347 MemPointerRecord::operator=(other); | 358 MemPointerRecord::operator=(other); |
348 _committed_size = other.committed_size(); | |
349 return *this; | 359 return *this; |
350 } | 360 } |
351 | 361 |
352 inline bool is_reserve_record() const { | 362 inline bool is_reserved_region() const { |
353 return is_virtual_memory_reserve_record(flags()); | 363 return is_allocation_record(); |
354 } | 364 } |
355 | 365 |
356 inline bool is_release_record() const { | 366 inline bool is_committed_region() const { |
357 return is_virtual_memory_release_record(flags()); | 367 return is_commit_record(); |
358 } | 368 } |
359 | |
360 // resize reserved VM range | |
361 inline void set_reserved_size(size_t new_size) { | |
362 assert(new_size >= committed_size(), "resize"); | |
363 set_size(new_size); | |
364 } | |
365 | |
366 inline void commit(size_t size) { | |
367 _committed_size += size; | |
368 } | |
369 | |
370 inline void uncommit(size_t size) { | |
371 if (_committed_size >= size) { | |
372 _committed_size -= size; | |
373 } else { | |
374 _committed_size = 0; | |
375 } | |
376 } | |
377 | |
378 /* | |
379 * if this virtual memory range covers whole range of | |
380 * the other VMMemRegion | |
381 */ | |
382 bool contains(const VMMemRegion* mr) const; | |
383 | 369 |
384 /* base address of this virtual memory range */ | 370 /* base address of this virtual memory range */ |
385 inline address base() const { | 371 inline address base() const { |
386 return addr(); | 372 return addr(); |
387 } | 373 } |
389 /* tag this virtual memory range to the specified memory type */ | 375 /* tag this virtual memory range to the specified memory type */ |
390 inline void tag(MEMFLAGS f) { | 376 inline void tag(MEMFLAGS f) { |
391 set_flags(flags() | (f & mt_masks)); | 377 set_flags(flags() | (f & mt_masks)); |
392 } | 378 } |
393 | 379 |
394 // release part of memory range | 380 // expand this region to also cover specified range. |
395 inline void partial_release(address add, size_t sz) { | 381 // The range has to be on either end of the memory region. |
396 assert(add >= addr() && add < addr() + size(), "not valid address"); | 382 void expand_region(address addr, size_t sz) { |
397 // for now, it can partially release from the both ends, | 383 if (addr < base()) { |
398 // but not in the middle | 384 assert(addr + sz == base(), "Sanity check"); |
385 _addr = addr; | |
386 set_size(size() + sz); | |
387 } else { | |
388 assert(base() + size() == addr, "Sanity check"); | |
389 set_size(size() + sz); | |
390 } | |
391 } | |
392 | |
393 // exclude the specified address range from this region. | |
394 // The excluded memory range has to be on either end of this memory | |
395 // region. | |
396 inline void exclude_region(address add, size_t sz) { | |
397 assert(is_reserved_region() || is_committed_region(), "Sanity check"); | |
398 assert(addr() != NULL && size() != 0, "Sanity check"); | |
399 assert(add >= addr() && add < addr() + size(), "Sanity check"); | |
399 assert(add == addr() || (add + sz) == (addr() + size()), | 400 assert(add == addr() || (add + sz) == (addr() + size()), |
400 "release in the middle"); | 401 "exclude in the middle"); |
401 if (add == addr()) { | 402 if (add == addr()) { |
402 set_addr(add + sz); | 403 set_addr(add + sz); |
403 set_size(size() - sz); | 404 set_size(size() - sz); |
404 } else { | 405 } else { |
405 set_size(size() - sz); | 406 set_size(size() - sz); |
406 } | 407 } |
407 } | 408 } |
408 | |
409 // the committed size of the virtual memory block | |
410 inline size_t committed_size() const { | |
411 return _committed_size; | |
412 } | |
413 | |
414 // the reserved size of the virtual memory block | |
415 inline size_t reserved_size() const { | |
416 return size(); | |
417 } | |
418 }; | 409 }; |
419 | 410 |
420 class VMMemRegionEx : public VMMemRegion { | 411 class VMMemRegionEx : public VMMemRegion { |
421 private: | 412 private: |
422 jint _seq; // sequence number | 413 jint _seq; // sequence number |