src/share/vm/services/memSnapshot.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/services

src/share/vm/services/memSnapshot.cpp

Print this page




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "runtime/mutexLocker.hpp"
  27 #include "utilities/decoder.hpp"
  28 #include "services/memBaseline.hpp"
  29 #include "services/memPtr.hpp"
  30 #include "services/memPtrArray.hpp"
  31 #include "services/memSnapshot.hpp"
  32 #include "services/memTracker.hpp"
  33 































































  34 
  35 bool VMMemPointerIterator::insert_record(MemPointerRecord* rec) {
  36   VMMemRegionEx new_rec;
  37   assert(rec->is_allocation_record() || rec->is_commit_record(),
  38     "Sanity check");
  39   if (MemTracker::track_callsite()) {
  40     new_rec.init((MemPointerRecordEx*)rec);
  41   } else {
  42     new_rec.init(rec);
  43   }
  44   return insert(&new_rec);
  45 }
  46 
  47 bool VMMemPointerIterator::insert_record_after(MemPointerRecord* rec) {
  48   VMMemRegionEx new_rec;
  49   assert(rec->is_allocation_record() || rec->is_commit_record(),
  50     "Sanity check");
  51   if (MemTracker::track_callsite()) {
  52     new_rec.init((MemPointerRecordEx*)rec);
  53   } else {


  56   return insert_after(&new_rec);
  57 }
  58 
  59 // we don't consolidate reserved regions, since they may be categorized
  60 // in different types.
  61 bool VMMemPointerIterator::add_reserved_region(MemPointerRecord* rec) {
  62   assert(rec->is_allocation_record(), "Sanity check");
  63   VMMemRegion* cur = (VMMemRegion*)current();
  64 
  65   // we don't have anything yet
  66   if (cur == NULL) {
  67     return insert_record(rec);
  68   }
  69 
  70   assert(cur->is_reserved_region(), "Sanity check");
  71   // duplicated records
  72   if (cur->is_same_region(rec)) {
  73     return true;
  74   }
  75   assert(cur->base() > rec->addr(), "Just check: locate()");
  76   assert(rec->addr() + rec->size() <= cur->base(), "Can not overlap");
  77   return insert_record(rec);
  78 }
  79 
  80 // we do consolidate committed regions
  81 bool VMMemPointerIterator::add_committed_region(MemPointerRecord* rec) {
  82   assert(rec->is_commit_record(), "Sanity check");
  83   VMMemRegion* cur;
  84   cur = (VMMemRegion*)current();
  85   assert(cur->is_reserved_region() && cur->contains_region(rec),
  86     "Sanity check");
  87 
  88   // thread's native stack is always marked as "committed", ignore
  89   // the "commit" operation for creating stack guard pages
  90   if (FLAGS_TO_MEMORY_TYPE(cur->flags()) == mtThreadStack &&
  91       FLAGS_TO_MEMORY_TYPE(rec->flags()) != mtThreadStack) {
  92     return true;
  93   }
  94 
  95   cur = (VMMemRegion*)next();
  96   while (cur != NULL && cur->is_committed_region()) {

  97     // duplicated commit records
  98     if(cur->contains_region(rec)) {
  99       return true;
 100     }
 101     if (cur->base() > rec->addr()) {
 102       // committed regions can not overlap
 103       assert(rec->addr() + rec->size() <= cur->base(), "Can not overlap");
 104       if (rec->addr() + rec->size() == cur->base()) {
 105         cur->expand_region(rec->addr(), rec->size());
 106         return true;
 107       } else {
 108         return insert_record(rec);
 109       }
 110     } else if (cur->base() + cur->size() == rec->addr()) {
 111       cur->expand_region(rec->addr(), rec->size());





 112       VMMemRegion* next_reg = (VMMemRegion*)next();
 113       // see if we can consolidate next committed region
 114       if (next_reg != NULL && next_reg->is_committed_region() &&
 115         next_reg->base() == cur->base() + cur->size()) {
 116           cur->expand_region(next_reg->base(), next_reg->size());

 117           remove();
 118       }
 119       return true;



 120     }
 121     cur = (VMMemRegion*)next();
 122   }
 123   return insert_record(rec);
 124 }
 125 
 126 bool VMMemPointerIterator::remove_uncommitted_region(MemPointerRecord* rec) {
 127   assert(rec->is_uncommit_record(), "sanity check");
 128   VMMemRegion* cur;
 129   cur = (VMMemRegion*)current();
 130   assert(cur->is_reserved_region() && cur->contains_region(rec),
 131     "Sanity check");
 132   // thread's native stack is always marked as "committed", ignore
 133   // the "commit" operation for creating stack guard pages
 134   if (FLAGS_TO_MEMORY_TYPE(cur->flags()) == mtThreadStack &&
 135       FLAGS_TO_MEMORY_TYPE(rec->flags()) != mtThreadStack) {
 136     return true;
 137   }
 138 
 139   cur = (VMMemRegion*)next();
 140   while (cur != NULL && cur->is_committed_region()) {
 141     // region already uncommitted, must be due to duplicated record




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "runtime/mutexLocker.hpp"
  27 #include "utilities/decoder.hpp"
  28 #include "services/memBaseline.hpp"
  29 #include "services/memPtr.hpp"
  30 #include "services/memPtrArray.hpp"
  31 #include "services/memSnapshot.hpp"
  32 #include "services/memTracker.hpp"
  33 
  34 #ifdef ASSERT
  35 
  36 void decode_pointer_record(MemPointerRecord* rec) {
  37   tty->print("Pointer: [" PTR_FORMAT " - " PTR_FORMAT  "] size = %d bytes", rec->addr(),
  38     rec->addr() + rec->size(), (int)rec->size());
  39   tty->print(" type = %s", MemBaseline::type2name(FLAGS_TO_MEMORY_TYPE(rec->flags())));
  40   if (rec->is_vm_pointer()) {
  41     if (rec->is_allocation_record()) {
  42       tty->print_cr(" (reserve)");
  43     } else if (rec->is_commit_record()) {
  44       tty->print_cr(" (commit)");
  45     } else if (rec->is_uncommit_record()) {
  46       tty->print_cr(" (uncommit)");
  47     } else if (rec->is_deallocation_record()) {
  48       tty->print_cr(" (release)");
  49     } else {
  50       tty->print_cr(" (tag)");
  51     }
  52   } else {
  53     if (rec->is_arena_size_record()) {
  54       tty->print_cr(" (arena size)");
  55     } else if (rec->is_allocation_record()) {
  56       tty->print_cr(" (malloc)");
  57     } else {
  58       tty->print_cr(" (free)");
  59     }
  60   }
  61   if (MemTracker::track_callsite()) {
  62     char buf[1024];
  63     address pc = ((MemPointerRecordEx*)rec)->pc();
  64     if (pc != NULL && os::dll_address_to_function_name(pc, buf, sizeof(buf), NULL)) {
  65       tty->print_cr("\tfrom %s", buf);
  66     } else {
  67       tty->print_cr("\tcould not decode pc = " PTR_FORMAT "", pc);
  68     }
  69   }
  70 }
  71 
  72 void decode_vm_region_record(VMMemRegion* rec) {
  73   tty->print("VM Region [" PTR_FORMAT " - " PTR_FORMAT "]", rec->addr(),
  74     rec->addr() + rec->size());
  75   tty->print(" type = %s", MemBaseline::type2name(FLAGS_TO_MEMORY_TYPE(rec->flags())));
  76   if (rec->is_allocation_record()) {
  77     tty->print_cr(" (reserved)");
  78   } else if (rec->is_commit_record()) {
  79     tty->print_cr(" (committed)");
  80   } else {
  81     ShouldNotReachHere();
  82   }
  83   if (MemTracker::track_callsite()) {
  84     char buf[1024];
  85     address pc = ((VMMemRegionEx*)rec)->pc();
  86     if (pc != NULL && os::dll_address_to_function_name(pc, buf, sizeof(buf), NULL)) {
  87       tty->print_cr("\tfrom %s", buf);
  88     } else {
  89       tty->print_cr("\tcould not decode pc = " PTR_FORMAT "", pc);
  90     }
  91 
  92   }
  93 }
  94 
  95 #endif
  96 
  97 
  98 bool VMMemPointerIterator::insert_record(MemPointerRecord* rec) {
  99   VMMemRegionEx new_rec;
 100   assert(rec->is_allocation_record() || rec->is_commit_record(),
 101     "Sanity check");
 102   if (MemTracker::track_callsite()) {
 103     new_rec.init((MemPointerRecordEx*)rec);
 104   } else {
 105     new_rec.init(rec);
 106   }
 107   return insert(&new_rec);
 108 }
 109 
 110 bool VMMemPointerIterator::insert_record_after(MemPointerRecord* rec) {
 111   VMMemRegionEx new_rec;
 112   assert(rec->is_allocation_record() || rec->is_commit_record(),
 113     "Sanity check");
 114   if (MemTracker::track_callsite()) {
 115     new_rec.init((MemPointerRecordEx*)rec);
 116   } else {


 119   return insert_after(&new_rec);
 120 }
 121 
 122 // we don't consolidate reserved regions, since they may be categorized
 123 // in different types.
 124 bool VMMemPointerIterator::add_reserved_region(MemPointerRecord* rec) {
 125   assert(rec->is_allocation_record(), "Sanity check");
 126   VMMemRegion* cur = (VMMemRegion*)current();
 127 
 128   // we don't have anything yet
 129   if (cur == NULL) {
 130     return insert_record(rec);
 131   }
 132 
 133   assert(cur->is_reserved_region(), "Sanity check");
 134   // duplicated records
 135   if (cur->is_same_region(rec)) {
 136     return true;
 137   }
 138   assert(cur->base() > rec->addr(), "Just check: locate()");
 139   assert(!cur->overlaps_region(rec), "overlapping reserved regions");
 140   return insert_record(rec);
 141 }
 142 
 143 // we do consolidate committed regions
 144 bool VMMemPointerIterator::add_committed_region(MemPointerRecord* rec) {
 145   assert(rec->is_commit_record(), "Sanity check");
 146   VMMemRegion* reserved_rgn = (VMMemRegion*)current();
 147   assert(reserved_rgn->is_reserved_region() && reserved_rgn->contains_region(rec),

 148     "Sanity check");
 149 
 150   // thread's native stack is always marked as "committed", ignore
 151   // the "commit" operation for creating stack guard pages
 152   if (FLAGS_TO_MEMORY_TYPE(reserved_rgn->flags()) == mtThreadStack &&
 153       FLAGS_TO_MEMORY_TYPE(rec->flags()) != mtThreadStack) {
 154     return true;
 155   }
 156 
 157   // if the reserved region has any committed regions
 158   VMMemRegion* committed_rgn  = (VMMemRegion*)next();
 159   while (committed_rgn != NULL && committed_rgn->is_committed_region()) {
 160     // duplicated commit records
 161     if(committed_rgn->contains_region(rec)) {
 162       return true;
 163     } else if (committed_rgn->overlaps_region(rec)) {
 164       // overlaps front part
 165       if (rec->addr() < committed_rgn->addr()) {
 166         committed_rgn->expand_region(rec->addr(),
 167           committed_rgn->addr() - rec->addr());
 168       } else {
 169         // overlaps tail part
 170         address committed_rgn_end = committed_rgn->addr() + 
 171               committed_rgn->size();
 172         assert(committed_rgn_end < rec->addr() + rec->size(),
 173              "overlap tail part");
 174         committed_rgn->expand_region(committed_rgn_end,
 175           (rec->addr() + rec->size()) - committed_rgn_end);
 176       }
 177     } else if (committed_rgn->base() + committed_rgn->size() == rec->addr()) {
 178       // adjunct each other 
 179       committed_rgn->expand_region(rec->addr(), rec->size());
 180       VMMemRegion* next_reg = (VMMemRegion*)next();
 181       // see if we can consolidate next committed region
 182       if (next_reg != NULL && next_reg->is_committed_region() &&
 183         next_reg->base() == committed_rgn->base() + committed_rgn->size()) {
 184           committed_rgn->expand_region(next_reg->base(), next_reg->size());
 185           // delete merged region 
 186           remove();
 187       }
 188       return true;
 189     } else if (committed_rgn->base() > rec->addr()) {
 190       // found the location, insert this committed region
 191       return insert_record(rec);
 192     }
 193     committed_rgn = (VMMemRegion*)next();
 194   }
 195   return insert_record(rec);
 196 }
 197 
 198 bool VMMemPointerIterator::remove_uncommitted_region(MemPointerRecord* rec) {
 199   assert(rec->is_uncommit_record(), "sanity check");
 200   VMMemRegion* cur;
 201   cur = (VMMemRegion*)current();
 202   assert(cur->is_reserved_region() && cur->contains_region(rec),
 203     "Sanity check");
 204   // thread's native stack is always marked as "committed", ignore
 205   // the "commit" operation for creating stack guard pages
 206   if (FLAGS_TO_MEMORY_TYPE(cur->flags()) == mtThreadStack &&
 207       FLAGS_TO_MEMORY_TYPE(rec->flags()) != mtThreadStack) {
 208     return true;
 209   }
 210 
 211   cur = (VMMemRegion*)next();
 212   while (cur != NULL && cur->is_committed_region()) {
 213     // region already uncommitted, must be due to duplicated record


src/share/vm/services/memSnapshot.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File