src/share/vm/services/memRecorder.cpp

Print this page
rev 3901 : JDK-8005012: Add WB APIs to better support NMT testing
Summary:


  38 
  39   MemPointerRecord* itr_next = (MemPointerRecord*)_itr.next();
  40 
  41   // don't collapse virtual memory records
  42   while (itr_next != NULL && !itr_cur->is_vm_pointer() &&
  43     !itr_next->is_vm_pointer() &&
  44     same_kind(itr_cur, itr_next)) {
  45     itr_cur = itr_next;
  46     itr_next = (MemPointerRecord*)_itr.next();
  47   }
  48 
  49   return itr_cur;
  50 }
  51 
  52 
  53 volatile jint MemRecorder::_instance_count = 0;
  54 
  55 MemRecorder::MemRecorder() {
  56   assert(MemTracker::is_on(), "Native memory tracking is off");
  57   Atomic::inc(&_instance_count);
  58   debug_only(set_generation();)
  59 
  60   if (MemTracker::track_callsite()) {
  61     _pointer_records = new (std::nothrow)FixedSizeMemPointerArray<SeqMemPointerRecordEx,
  62         DEFAULT_RECORDER_PTR_ARRAY_SIZE>();
  63   } else {
  64     _pointer_records = new (std::nothrow)FixedSizeMemPointerArray<SeqMemPointerRecord,
  65         DEFAULT_RECORDER_PTR_ARRAY_SIZE>();
  66   }
  67   _next = NULL;
  68 
  69 
  70   if (_pointer_records != NULL) {
  71     // recode itself
  72     record((address)this, (MemPointerRecord::malloc_tag()|mtNMT|otNMTRecorder),
  73         sizeof(MemRecorder), CALLER_PC);
  74     record((address)_pointer_records, (MemPointerRecord::malloc_tag()|mtNMT|otNMTRecorder),
  75         _pointer_records->instance_size(),CURRENT_PC);
  76   }
  77 }
  78 


 131 
 132   if (MemTracker::track_callsite()) {
 133     SeqMemPointerRecordEx ap(p, flags, size, pc);
 134     debug_only(check_dup_seq(ap.seq());)
 135     return _pointer_records->append(&ap);
 136   } else {
 137     SeqMemPointerRecord ap(p, flags, size);
 138     debug_only(check_dup_seq(ap.seq());)
 139     return _pointer_records->append(&ap);
 140   }
 141 }
 142 
 143   // iterator for alloc pointers
 144 SequencedRecordIterator MemRecorder::pointer_itr() {
 145   assert(_pointer_records != NULL, "just check");
 146   _pointer_records->sort((FN_SORT)sort_record_fn);
 147   return SequencedRecordIterator(_pointer_records);
 148 }
 149 
 150 
 151 #ifdef ASSERT
 152 void MemRecorder::set_generation() {
 153   _generation = SequenceGenerator::current_generation();
 154 }


 155 
 156 void MemRecorder::check_dup_seq(jint seq) const {
 157   MemPointerArrayIteratorImpl itr(_pointer_records);
 158   MemPointerRecord* rc = (MemPointerRecord*)itr.current();
 159   while (rc != NULL) {
 160     assert(rc->seq() != seq, "dup seq");
 161     rc = (MemPointerRecord*)itr.next();
 162   }
 163 }
 164 
 165 #endif


  38 
  39   MemPointerRecord* itr_next = (MemPointerRecord*)_itr.next();
  40 
  41   // don't collapse virtual memory records
  42   while (itr_next != NULL && !itr_cur->is_vm_pointer() &&
  43     !itr_next->is_vm_pointer() &&
  44     same_kind(itr_cur, itr_next)) {
  45     itr_cur = itr_next;
  46     itr_next = (MemPointerRecord*)_itr.next();
  47   }
  48 
  49   return itr_cur;
  50 }
  51 
  52 
  53 volatile jint MemRecorder::_instance_count = 0;
  54 
  55 MemRecorder::MemRecorder() {
  56   assert(MemTracker::is_on(), "Native memory tracking is off");
  57   Atomic::inc(&_instance_count);
  58   set_generation();
  59 
  60   if (MemTracker::track_callsite()) {
  61     _pointer_records = new (std::nothrow)FixedSizeMemPointerArray<SeqMemPointerRecordEx,
  62         DEFAULT_RECORDER_PTR_ARRAY_SIZE>();
  63   } else {
  64     _pointer_records = new (std::nothrow)FixedSizeMemPointerArray<SeqMemPointerRecord,
  65         DEFAULT_RECORDER_PTR_ARRAY_SIZE>();
  66   }
  67   _next = NULL;
  68 
  69 
  70   if (_pointer_records != NULL) {
  71     // recode itself
  72     record((address)this, (MemPointerRecord::malloc_tag()|mtNMT|otNMTRecorder),
  73         sizeof(MemRecorder), CALLER_PC);
  74     record((address)_pointer_records, (MemPointerRecord::malloc_tag()|mtNMT|otNMTRecorder),
  75         _pointer_records->instance_size(),CURRENT_PC);
  76   }
  77 }
  78 


 131 
 132   if (MemTracker::track_callsite()) {
 133     SeqMemPointerRecordEx ap(p, flags, size, pc);
 134     debug_only(check_dup_seq(ap.seq());)
 135     return _pointer_records->append(&ap);
 136   } else {
 137     SeqMemPointerRecord ap(p, flags, size);
 138     debug_only(check_dup_seq(ap.seq());)
 139     return _pointer_records->append(&ap);
 140   }
 141 }
 142 
 143   // iterator for alloc pointers
 144 SequencedRecordIterator MemRecorder::pointer_itr() {
 145   assert(_pointer_records != NULL, "just check");
 146   _pointer_records->sort((FN_SORT)sort_record_fn);
 147   return SequencedRecordIterator(_pointer_records);
 148 }
 149 
 150 

 151 void MemRecorder::set_generation() {
 152   _generation = SequenceGenerator::current_generation();
 153 }
 154 
 155 #ifdef ASSERT
 156 
 157 void MemRecorder::check_dup_seq(jint seq) const {
 158   MemPointerArrayIteratorImpl itr(_pointer_records);
 159   MemPointerRecord* rc = (MemPointerRecord*)itr.current();
 160   while (rc != NULL) {
 161     assert(rc->seq() != seq, "dup seq");
 162     rc = (MemPointerRecord*)itr.next();
 163   }
 164 }
 165 
 166 #endif