1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2018 SAP SE. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "code/codeHeapState.hpp"
  28 #include "compiler/compileBroker.hpp"
  29 #include "runtime/sweeper.hpp"
  30 
  31 // -------------------------
  32 // |  General Description  |
  33 // -------------------------
  34 // The CodeHeap state analytics are divided in two parts.
  35 // The first part examines the entire CodeHeap and aggregates all
  36 // information that is believed useful/important.
  37 //
  38 // Aggregation condenses the information of a piece of the CodeHeap
  39 // (4096 bytes by default) into an analysis granule. These granules
  40 // contain enough detail to gain initial insight while keeping the
  41 // internal sttructure sizes in check.
  42 //
  43 // The CodeHeap is a living thing. Therefore, the aggregate is collected
  44 // under the CodeCache_lock. The subsequent print steps are only locked
  45 // against concurrent aggregations. That keeps the impact on
  46 // "normal operation" (JIT compiler and sweeper activity) to a minimum.
  47 //
  48 // The second part, which consists of several, independent steps,
  49 // prints the previously collected information with emphasis on
  50 // various aspects.
  51 //
  52 // Data collection and printing is done on an "on request" basis.
  53 // While no request is being processed, there is no impact on performance.
  54 // The CodeHeap state analytics do have some memory footprint.
  55 // The "aggregate" step allocates some data structures to hold the aggregated
  56 // information for later output. These data structures live until they are
  57 // explicitly discarded (function "discard") or until the VM terminates.
  58 // There is one exception: the function "all" does not leave any data
  59 // structures allocated.
  60 //
  61 // Requests for real-time, on-the-fly analysis can be issued via
  62 //   jcmd <pid> Compiler.CodeHeap_Analytics [<function>] [<granularity>]
  63 //
  64 // If you are (only) interested in how the CodeHeap looks like after running
  65 // a sample workload, you can use the command line option
  66 //   -Xlog:codecache=Trace
  67 //
  68 // To see the CodeHeap state in case of a "CodeCache full" condition, start the
  69 // VM with the
  70 //   -Xlog:codecache=Debug
  71 // command line option. It will produce output only for the first time the
  72 // condition is recognized.
  73 //
  74 // Both command line option variants produce output identical to the jcmd function
  75 //   jcmd <pid> Compiler.CodeHeap_Analytics all 4096
  76 // ---------------------------------------------------------------------------------
  77 
  78 // With this declaration macro, it is possible to switch between
  79 //  - direct output into an argument-passed outputStream and
  80 //  - buffered output into a bufferedStream with subsequent flush
  81 //    of the filled buffer to the outputStream.
  82 #define USE_STRINGSTREAM
  83 #define HEX32_FORMAT  "0x%x"  // just a helper format string used below multiple times
  84 //
  85 // Writing to a bufferedStream buffer first has a significant advantage:
  86 // It uses noticeably less cpu cycles and reduces (when wirting to a
  87 // network file) the required bandwidth by at least a factor of ten.
  88 // That clearly makes up for the increased code complexity.
  89 #if defined(USE_STRINGSTREAM)
  90 #define STRINGSTREAM_DECL(_anyst, _outst)                 \
  91     /* _anyst  name of the stream as used in the code */  \
  92     /* _outst  stream where final output will go to   */  \
  93     ResourceMark rm;                                      \
  94     bufferedStream   _sstobj = bufferedStream(4*K);       \
  95     bufferedStream*  _sstbuf = &_sstobj;                  \
  96     outputStream*    _outbuf = _outst;                    \
  97     bufferedStream*  _anyst  = &_sstobj; /* any stream. Use this to just print - no buffer flush.  */
  98 
  99 #define STRINGSTREAM_FLUSH(termString)                    \
 100     _sstbuf->print("%s", termString);                     \
 101     _outbuf->print("%s", _sstbuf->as_string());           \
 102     _sstbuf->reset();
 103 
 104 #define STRINGSTREAM_FLUSH_LOCKED(termString)             \
 105     { ttyLocker ttyl;/* keep this output block together */\
 106       STRINGSTREAM_FLUSH(termString)                      \
 107     }
 108 #else
 109 #define STRINGSTREAM_DECL(_anyst, _outst)                 \
 110     outputStream*  _outbuf = _outst;                      \
 111     outputStream*  _anyst  = _outst;   /* any stream. Use this to just print - no buffer flush.  */
 112 
 113 #define STRINGSTREAM_FLUSH(termString)                    \
 114     _outbuf->print("%s", termString);
 115 
 116 #define STRINGSTREAM_FLUSH_LOCKED(termString)             \
 117     _outbuf->print("%s", termString);
 118 #endif
 119 
 120 const char  blobTypeChar[] = {' ', 'C', 'N', 'I', 'X', 'Z', 'U', 'R', '?', 'D', 'T', 'E', 'S', 'A', 'M', 'B', 'L' };
 121 const char* blobTypeName[] = {"noType"
 122                              ,     "nMethod (under construction)"
 123                              ,          "nMethod (active)"
 124                              ,               "nMethod (inactive)"
 125                              ,                    "nMethod (deopt)"
 126                              ,                         "nMethod (zombie)"
 127                              ,                              "nMethod (unloaded)"
 128                              ,                                   "runtime stub"
 129                              ,                                        "ricochet stub"
 130                              ,                                             "deopt stub"
 131                              ,                                                  "uncommon trap stub"
 132                              ,                                                       "exception stub"
 133                              ,                                                            "safepoint stub"
 134                              ,                                                                 "adapter blob"
 135                              ,                                                                      "MH adapter blob"
 136                              ,                                                                           "buffer blob"
 137                              ,                                                                                "lastType"
 138                              };
 139 const char* compTypeName[] = { "none", "c1", "c2", "jvmci" };
 140 
 141 // Be prepared for ten different CodeHeap segments. Should be enough for a few years.
 142 const  unsigned int        nSizeDistElements = 31;  // logarithmic range growth, max size: 2**32
 143 const  unsigned int        maxTopSizeBlocks  = 50;
 144 const  unsigned int        tsbStopper        = 2 * maxTopSizeBlocks;
 145 const  unsigned int        maxHeaps          = 10;
 146 static unsigned int        nHeaps            = 0;
 147 static struct CodeHeapStat CodeHeapStatArray[maxHeaps];
 148 
 149 // static struct StatElement *StatArray      = NULL;
 150 static StatElement* StatArray             = NULL;
 151 static int          log2_seg_size         = 0;
 152 static size_t       seg_size              = 0;
 153 static size_t       alloc_granules        = 0;
 154 static size_t       granule_size          = 0;
 155 static bool         segment_granules      = false;
 156 static unsigned int nBlocks_t1            = 0;  // counting "in_use" nmethods only.
 157 static unsigned int nBlocks_t2            = 0;  // counting "in_use" nmethods only.
 158 static unsigned int nBlocks_alive         = 0;  // counting "not_used" and "not_entrant" nmethods only.
 159 static unsigned int nBlocks_dead          = 0;  // counting "zombie" and "unloaded" methods only.
 160 static unsigned int nBlocks_inconstr      = 0;  // counting "inconstruction" nmethods only. This is a transient state.
 161 static unsigned int nBlocks_unloaded      = 0;  // counting "unloaded" nmethods only. This is a transient state.
 162 static unsigned int nBlocks_stub          = 0;
 163 
 164 static struct FreeBlk*          FreeArray = NULL;
 165 static unsigned int      alloc_freeBlocks = 0;
 166 
 167 static struct TopSizeBlk*    TopSizeArray = NULL;
 168 static unsigned int   alloc_topSizeBlocks = 0;
 169 static unsigned int    used_topSizeBlocks = 0;
 170 
 171 static struct SizeDistributionElement*  SizeDistributionArray = NULL;
 172 
 173 // nMethod temperature (hotness) indicators.
 174 static int                     avgTemp    = 0;
 175 static int                     maxTemp    = 0;
 176 static int                     minTemp    = 0;
 177 
 178 static unsigned int  latest_compilation_id   = 0;
 179 static volatile bool initialization_complete = false;
 180 
 181 const char* CodeHeapState::get_heapName(CodeHeap* heap) {
 182   if (SegmentedCodeCache) {
 183     return heap->name();
 184   } else {
 185     return "CodeHeap";
 186   }
 187 }
 188 
 189 // returns the index for the heap being processed.
 190 unsigned int CodeHeapState::findHeapIndex(outputStream* out, const char* heapName) {
 191   if (heapName == NULL) {
 192     return maxHeaps;
 193   }
 194   if (SegmentedCodeCache) {
 195     // Search for a pre-existing entry. If found, return that index.
 196     for (unsigned int i = 0; i < nHeaps; i++) {
 197       if (CodeHeapStatArray[i].heapName != NULL && strcmp(heapName, CodeHeapStatArray[i].heapName) == 0) {
 198         return i;
 199       }
 200     }
 201 
 202     // check if there are more code heap segments than we can handle.
 203     if (nHeaps == maxHeaps) {
 204       out->print_cr("Too many heap segments for current limit(%d).", maxHeaps);
 205       return maxHeaps;
 206     }
 207 
 208     // allocate new slot in StatArray.
 209     CodeHeapStatArray[nHeaps].heapName = heapName;
 210     return nHeaps++;
 211   } else {
 212     nHeaps = 1;
 213     CodeHeapStatArray[0].heapName = heapName;
 214     return 0; // This is the default index if CodeCache is not segmented.
 215   }
 216 }
 217 
 218 void CodeHeapState::get_HeapStatGlobals(outputStream* out, const char* heapName) {
 219   unsigned int ix = findHeapIndex(out, heapName);
 220   if (ix < maxHeaps) {
 221     StatArray             = CodeHeapStatArray[ix].StatArray;
 222     seg_size              = CodeHeapStatArray[ix].segment_size;
 223     log2_seg_size         = seg_size == 0 ? 0 : exact_log2(seg_size);
 224     alloc_granules        = CodeHeapStatArray[ix].alloc_granules;
 225     granule_size          = CodeHeapStatArray[ix].granule_size;
 226     segment_granules      = CodeHeapStatArray[ix].segment_granules;
 227     nBlocks_t1            = CodeHeapStatArray[ix].nBlocks_t1;
 228     nBlocks_t2            = CodeHeapStatArray[ix].nBlocks_t2;
 229     nBlocks_alive         = CodeHeapStatArray[ix].nBlocks_alive;
 230     nBlocks_dead          = CodeHeapStatArray[ix].nBlocks_dead;
 231     nBlocks_inconstr      = CodeHeapStatArray[ix].nBlocks_inconstr;
 232     nBlocks_unloaded      = CodeHeapStatArray[ix].nBlocks_unloaded;
 233     nBlocks_stub          = CodeHeapStatArray[ix].nBlocks_stub;
 234     FreeArray             = CodeHeapStatArray[ix].FreeArray;
 235     alloc_freeBlocks      = CodeHeapStatArray[ix].alloc_freeBlocks;
 236     TopSizeArray          = CodeHeapStatArray[ix].TopSizeArray;
 237     alloc_topSizeBlocks   = CodeHeapStatArray[ix].alloc_topSizeBlocks;
 238     used_topSizeBlocks    = CodeHeapStatArray[ix].used_topSizeBlocks;
 239     SizeDistributionArray = CodeHeapStatArray[ix].SizeDistributionArray;
 240     avgTemp               = CodeHeapStatArray[ix].avgTemp;
 241     maxTemp               = CodeHeapStatArray[ix].maxTemp;
 242     minTemp               = CodeHeapStatArray[ix].minTemp;
 243   } else {
 244     StatArray             = NULL;
 245     seg_size              = 0;
 246     log2_seg_size         = 0;
 247     alloc_granules        = 0;
 248     granule_size          = 0;
 249     segment_granules      = false;
 250     nBlocks_t1            = 0;
 251     nBlocks_t2            = 0;
 252     nBlocks_alive         = 0;
 253     nBlocks_dead          = 0;
 254     nBlocks_inconstr      = 0;
 255     nBlocks_unloaded      = 0;
 256     nBlocks_stub          = 0;
 257     FreeArray             = NULL;
 258     alloc_freeBlocks      = 0;
 259     TopSizeArray          = NULL;
 260     alloc_topSizeBlocks   = 0;
 261     used_topSizeBlocks    = 0;
 262     SizeDistributionArray = NULL;
 263     avgTemp               = 0;
 264     maxTemp               = 0;
 265     minTemp               = 0;
 266   }
 267 }
 268 
 269 void CodeHeapState::set_HeapStatGlobals(outputStream* out, const char* heapName) {
 270   unsigned int ix = findHeapIndex(out, heapName);
 271   if (ix < maxHeaps) {
 272     CodeHeapStatArray[ix].StatArray             = StatArray;
 273     CodeHeapStatArray[ix].segment_size          = seg_size;
 274     CodeHeapStatArray[ix].alloc_granules        = alloc_granules;
 275     CodeHeapStatArray[ix].granule_size          = granule_size;
 276     CodeHeapStatArray[ix].segment_granules      = segment_granules;
 277     CodeHeapStatArray[ix].nBlocks_t1            = nBlocks_t1;
 278     CodeHeapStatArray[ix].nBlocks_t2            = nBlocks_t2;
 279     CodeHeapStatArray[ix].nBlocks_alive         = nBlocks_alive;
 280     CodeHeapStatArray[ix].nBlocks_dead          = nBlocks_dead;
 281     CodeHeapStatArray[ix].nBlocks_inconstr      = nBlocks_inconstr;
 282     CodeHeapStatArray[ix].nBlocks_unloaded      = nBlocks_unloaded;
 283     CodeHeapStatArray[ix].nBlocks_stub          = nBlocks_stub;
 284     CodeHeapStatArray[ix].FreeArray             = FreeArray;
 285     CodeHeapStatArray[ix].alloc_freeBlocks      = alloc_freeBlocks;
 286     CodeHeapStatArray[ix].TopSizeArray          = TopSizeArray;
 287     CodeHeapStatArray[ix].alloc_topSizeBlocks   = alloc_topSizeBlocks;
 288     CodeHeapStatArray[ix].used_topSizeBlocks    = used_topSizeBlocks;
 289     CodeHeapStatArray[ix].SizeDistributionArray = SizeDistributionArray;
 290     CodeHeapStatArray[ix].avgTemp               = avgTemp;
 291     CodeHeapStatArray[ix].maxTemp               = maxTemp;
 292     CodeHeapStatArray[ix].minTemp               = minTemp;
 293   }
 294 }
 295 
 296 //---<  get a new statistics array  >---
 297 void CodeHeapState::prepare_StatArray(outputStream* out, size_t nElem, size_t granularity, const char* heapName) {
 298   if (StatArray == NULL) {
 299     StatArray      = new StatElement[nElem];
 300     //---<  reset some counts  >---
 301     alloc_granules = nElem;
 302     granule_size   = granularity;
 303   }
 304 
 305   if (StatArray == NULL) {
 306     //---<  just do nothing if allocation failed  >---
 307     out->print_cr("Statistics could not be collected for %s, probably out of memory.", heapName);
 308     out->print_cr("Current granularity is " SIZE_FORMAT " bytes. Try a coarser granularity.", granularity);
 309     alloc_granules = 0;
 310     granule_size   = 0;
 311   } else {
 312     //---<  initialize statistics array  >---
 313     memset((void*)StatArray, 0, nElem*sizeof(StatElement));
 314   }
 315 }
 316 
 317 //---<  get a new free block array  >---
 318 void CodeHeapState::prepare_FreeArray(outputStream* out, unsigned int nElem, const char* heapName) {
 319   if (FreeArray == NULL) {
 320     FreeArray      = new FreeBlk[nElem];
 321     //---<  reset some counts  >---
 322     alloc_freeBlocks = nElem;
 323   }
 324 
 325   if (FreeArray == NULL) {
 326     //---<  just do nothing if allocation failed  >---
 327     out->print_cr("Free space analysis cannot be done for %s, probably out of memory.", heapName);
 328     alloc_freeBlocks = 0;
 329   } else {
 330     //---<  initialize free block array  >---
 331     memset((void*)FreeArray, 0, alloc_freeBlocks*sizeof(FreeBlk));
 332   }
 333 }
 334 
 335 //---<  get a new TopSizeArray  >---
 336 void CodeHeapState::prepare_TopSizeArray(outputStream* out, unsigned int nElem, const char* heapName) {
 337   if (TopSizeArray == NULL) {
 338     TopSizeArray   = new TopSizeBlk[nElem];
 339     //---<  reset some counts  >---
 340     alloc_topSizeBlocks = nElem;
 341     used_topSizeBlocks  = 0;
 342   }
 343 
 344   if (TopSizeArray == NULL) {
 345     //---<  just do nothing if allocation failed  >---
 346     out->print_cr("Top-%d list of largest CodeHeap blocks can not be collected for %s, probably out of memory.", nElem, heapName);
 347     alloc_topSizeBlocks = 0;
 348   } else {
 349     //---<  initialize TopSizeArray  >---
 350     memset((void*)TopSizeArray, 0, nElem*sizeof(TopSizeBlk));
 351     used_topSizeBlocks  = 0;
 352   }
 353 }
 354 
 355 //---<  get a new SizeDistributionArray  >---
 356 void CodeHeapState::prepare_SizeDistArray(outputStream* out, unsigned int nElem, const char* heapName) {
 357   if (SizeDistributionArray == NULL) {
 358     SizeDistributionArray = new SizeDistributionElement[nElem];
 359   }
 360 
 361   if (SizeDistributionArray == NULL) {
 362     //---<  just do nothing if allocation failed  >---
 363     out->print_cr("Size distribution can not be collected for %s, probably out of memory.", heapName);
 364   } else {
 365     //---<  initialize SizeDistArray  >---
 366     memset((void*)SizeDistributionArray, 0, nElem*sizeof(SizeDistributionElement));
 367     // Logarithmic range growth. First range starts at _segment_size.
 368     SizeDistributionArray[log2_seg_size-1].rangeEnd = 1U;
 369     for (unsigned int i = log2_seg_size; i < nElem; i++) {
 370       SizeDistributionArray[i].rangeStart = 1U << (i     - log2_seg_size);
 371       SizeDistributionArray[i].rangeEnd   = 1U << ((i+1) - log2_seg_size);
 372     }
 373   }
 374 }
 375 
 376 //---<  get a new SizeDistributionArray  >---
 377 void CodeHeapState::update_SizeDistArray(outputStream* out, unsigned int len) {
 378   if (SizeDistributionArray != NULL) {
 379     for (unsigned int i = log2_seg_size-1; i < nSizeDistElements; i++) {
 380       if ((SizeDistributionArray[i].rangeStart <= len) && (len < SizeDistributionArray[i].rangeEnd)) {
 381         SizeDistributionArray[i].lenSum += len;
 382         SizeDistributionArray[i].count++;
 383         break;
 384       }
 385     }
 386   }
 387 }
 388 
 389 void CodeHeapState::discard_StatArray(outputStream* out) {
 390   if (StatArray != NULL) {
 391     delete StatArray;
 392     StatArray        = NULL;
 393     alloc_granules   = 0;
 394     granule_size     = 0;
 395   }
 396 }
 397 
 398 void CodeHeapState::discard_FreeArray(outputStream* out) {
 399   if (FreeArray != NULL) {
 400     delete[] FreeArray;
 401     FreeArray        = NULL;
 402     alloc_freeBlocks = 0;
 403   }
 404 }
 405 
 406 void CodeHeapState::discard_TopSizeArray(outputStream* out) {
 407   if (TopSizeArray != NULL) {
 408     delete[] TopSizeArray;
 409     TopSizeArray        = NULL;
 410     alloc_topSizeBlocks = 0;
 411     used_topSizeBlocks  = 0;
 412   }
 413 }
 414 
 415 void CodeHeapState::discard_SizeDistArray(outputStream* out) {
 416   if (SizeDistributionArray != NULL) {
 417     delete[] SizeDistributionArray;
 418     SizeDistributionArray = NULL;
 419   }
 420 }
 421 
 422 // Discard all allocated internal data structures.
 423 // This should be done after an analysis session is completed.
 424 void CodeHeapState::discard(outputStream* out, CodeHeap* heap) {
 425   if (!initialization_complete) {
 426     return;
 427   }
 428 
 429   if (nHeaps > 0) {
 430     for (unsigned int ix = 0; ix < nHeaps; ix++) {
 431       get_HeapStatGlobals(out, CodeHeapStatArray[ix].heapName);
 432       discard_StatArray(out);
 433       discard_FreeArray(out);
 434       discard_TopSizeArray(out);
 435       discard_SizeDistArray(out);
 436       set_HeapStatGlobals(out, CodeHeapStatArray[ix].heapName);
 437       CodeHeapStatArray[ix].heapName = NULL;
 438     }
 439     nHeaps = 0;
 440   }
 441 }
 442 
 443 void CodeHeapState::aggregate(outputStream* out, CodeHeap* heap, const char* granularity_request) {
 444   unsigned int nBlocks_free    = 0;
 445   unsigned int nBlocks_used    = 0;
 446   unsigned int nBlocks_zomb    = 0;
 447   unsigned int nBlocks_disconn = 0;
 448   unsigned int nBlocks_notentr = 0;
 449 
 450   //---<  max & min of TopSizeArray  >---
 451   //  it is sufficient to have these sizes as 32bit unsigned ints.
 452   //  The CodeHeap is limited in size to 4GB. Furthermore, the sizes
 453   //  are stored in _segment_size units, scaling them down by a factor of 64 (at least).
 454   unsigned int  currMax          = 0;
 455   unsigned int  currMin          = 0;
 456   unsigned int  currMin_ix       = 0;
 457   unsigned long total_iterations = 0;
 458 
 459   bool  done             = false;
 460   const int min_granules = 256;
 461   const int max_granules = 512*K; // limits analyzable CodeHeap (with segment_granules) to 32M..128M
 462                                   // results in StatArray size of 20M (= max_granules * 40 Bytes per element)
 463                                   // For a 1GB CodeHeap, the granule size must be at least 2kB to not violate the max_granles limit.
 464   const char* heapName   = get_heapName(heap);
 465   STRINGSTREAM_DECL(ast, out)
 466 
 467   if (!initialization_complete) {
 468     memset(CodeHeapStatArray, 0, sizeof(CodeHeapStatArray));
 469     initialization_complete = true;
 470 
 471     printBox(ast, '=', "C O D E   H E A P   A N A L Y S I S   (general remarks)", NULL);
 472     ast->print_cr("   The code heap analysis function provides deep insights into\n"
 473                   "   the inner workings and the internal state of the Java VM's\n"
 474                   "   code cache - the place where all the JVM generated machine\n"
 475                   "   code is stored.\n"
 476                   "   \n"
 477                   "   This function is designed and provided for support engineers\n"
 478                   "   to help them understand and solve issues in customer systems.\n"
 479                   "   It is not intended for use and interpretation by other persons.\n"
 480                   "   \n");
 481     STRINGSTREAM_FLUSH("")
 482   }
 483   get_HeapStatGlobals(out, heapName);
 484 
 485 
 486   // Since we are (and must be) analyzing the CodeHeap contents under the CodeCache_lock,
 487   // all heap information is "constant" and can be safely extracted/calculated before we
 488   // enter the while() loop. Actually, the loop will only be iterated once.
 489   char*  low_bound     = heap->low_boundary();
 490   size_t size          = heap->capacity();
 491   size_t res_size      = heap->max_capacity();
 492   seg_size             = heap->segment_size();
 493   log2_seg_size        = seg_size == 0 ? 0 : exact_log2(seg_size);  // This is a global static value.
 494 
 495   if (seg_size == 0) {
 496     printBox(ast, '-', "Heap not fully initialized yet, segment size is zero for segment ", heapName);
 497     STRINGSTREAM_FLUSH("")
 498     return;
 499   }
 500 
 501   // Calculate granularity of analysis (and output).
 502   //   The CodeHeap is managed (allocated) in segments (units) of CodeCacheSegmentSize.
 503   //   The CodeHeap can become fairly large, in particular in productive real-life systems.
 504   //
 505   //   It is often neither feasible nor desirable to aggregate the data with the highest possible
 506   //   level of detail, i.e. inspecting and printing each segment on its own.
 507   //
 508   //   The granularity parameter allows to specify the level of detail available in the analysis.
 509   //   It must be a positive multiple of the segment size and should be selected such that enough
 510   //   detail is provided while, at the same time, the printed output does not explode.
 511   //
 512   //   By manipulating the granularity value, we enforce that at least min_granules units
 513   //   of analysis are available. We also enforce an upper limit of max_granules units to
 514   //   keep the amount of allocated storage in check.
 515   //
 516   //   Finally, we adjust the granularity such that each granule covers at most 64k-1 segments.
 517   //   This is necessary to prevent an unsigned short overflow while accumulating space information.
 518   //
 519   size_t granularity = strtol(granularity_request, NULL, 0);
 520   if (granularity > size) {
 521     granularity = size;
 522   }
 523   if (size/granularity < min_granules) {
 524     granularity = size/min_granules;                                   // at least min_granules granules
 525   }
 526   granularity = granularity & (~(seg_size - 1));                       // must be multiple of seg_size
 527   if (granularity < seg_size) {
 528     granularity = seg_size;                                            // must be at least seg_size
 529   }
 530   if (size/granularity > max_granules) {
 531     granularity = size/max_granules;                                   // at most max_granules granules
 532   }
 533   granularity = granularity & (~(seg_size - 1));                       // must be multiple of seg_size
 534   if (granularity>>log2_seg_size >= (1L<<sizeof(unsigned short)*8)) {
 535     granularity = ((1L<<(sizeof(unsigned short)*8))-1)<<log2_seg_size; // Limit: (64k-1) * seg_size
 536   }
 537   segment_granules = granularity == seg_size;
 538   size_t granules  = (size + (granularity-1))/granularity;
 539 
 540   printBox(ast, '=', "C O D E   H E A P   A N A L Y S I S   (used blocks) for segment ", heapName);
 541   ast->print_cr("   The aggregate step takes an aggregated snapshot of the CodeHeap.\n"
 542                 "   Subsequent print functions create their output based on this snapshot.\n"
 543                 "   The CodeHeap is a living thing, and every effort has been made for the\n"
 544                 "   collected data to be consistent. Only the method names and signatures\n"
 545                 "   are retrieved at print time. That may lead to rare cases where the\n"
 546                 "   name of a method is no longer available, e.g. because it was unloaded.\n");
 547   ast->print_cr("   CodeHeap committed size " SIZE_FORMAT "K (" SIZE_FORMAT "M), reserved size " SIZE_FORMAT "K (" SIZE_FORMAT "M), %d%% occupied.",
 548                 size/(size_t)K, size/(size_t)M, res_size/(size_t)K, res_size/(size_t)M, (unsigned int)(100.0*size/res_size));
 549   ast->print_cr("   CodeHeap allocation segment size is " SIZE_FORMAT " bytes. This is the smallest possible granularity.", seg_size);
 550   ast->print_cr("   CodeHeap (committed part) is mapped to " SIZE_FORMAT " granules of size " SIZE_FORMAT " bytes.", granules, granularity);
 551   ast->print_cr("   Each granule takes " SIZE_FORMAT " bytes of C heap, that is " SIZE_FORMAT "K in total for statistics data.", sizeof(StatElement), (sizeof(StatElement)*granules)/(size_t)K);
 552   ast->print_cr("   The number of granules is limited to %dk, requiring a granules size of at least %d bytes for a 1GB heap.", (unsigned int)(max_granules/K), (unsigned int)(G/max_granules));
 553   STRINGSTREAM_FLUSH("\n")
 554 
 555 
 556   while (!done) {
 557     //---<  reset counters with every aggregation  >---
 558     nBlocks_t1       = 0;
 559     nBlocks_t2       = 0;
 560     nBlocks_alive    = 0;
 561     nBlocks_dead     = 0;
 562     nBlocks_inconstr = 0;
 563     nBlocks_unloaded = 0;
 564     nBlocks_stub     = 0;
 565 
 566     nBlocks_free     = 0;
 567     nBlocks_used     = 0;
 568     nBlocks_zomb     = 0;
 569     nBlocks_disconn  = 0;
 570     nBlocks_notentr  = 0;
 571 
 572     //---<  discard old arrays if size does not match  >---
 573     if (granules != alloc_granules) {
 574       discard_StatArray(out);
 575       discard_TopSizeArray(out);
 576     }
 577 
 578     //---<  allocate arrays if they don't yet exist, initialize  >---
 579     prepare_StatArray(out, granules, granularity, heapName);
 580     if (StatArray == NULL) {
 581       set_HeapStatGlobals(out, heapName);
 582       return;
 583     }
 584     prepare_TopSizeArray(out, maxTopSizeBlocks, heapName);
 585     prepare_SizeDistArray(out, nSizeDistElements, heapName);
 586 
 587     latest_compilation_id = CompileBroker::get_compilation_id();
 588     unsigned int highest_compilation_id = 0;
 589     size_t       usedSpace     = 0;
 590     size_t       t1Space       = 0;
 591     size_t       t2Space       = 0;
 592     size_t       aliveSpace    = 0;
 593     size_t       disconnSpace  = 0;
 594     size_t       notentrSpace  = 0;
 595     size_t       deadSpace     = 0;
 596     size_t       inconstrSpace = 0;
 597     size_t       unloadedSpace = 0;
 598     size_t       stubSpace     = 0;
 599     size_t       freeSpace     = 0;
 600     size_t       maxFreeSize   = 0;
 601     HeapBlock*   maxFreeBlock  = NULL;
 602     bool         insane        = false;
 603 
 604     int64_t hotnessAccumulator = 0;
 605     unsigned int n_methods     = 0;
 606     avgTemp       = 0;
 607     minTemp       = (int)(res_size > M ? (res_size/M)*2 : 1);
 608     maxTemp       = -minTemp;
 609 
 610     for (HeapBlock *h = heap->first_block(); h != NULL && !insane; h = heap->next_block(h)) {
 611       unsigned int hb_len     = (unsigned int)h->length();  // despite being size_t, length can never overflow an unsigned int.
 612       size_t       hb_bytelen = ((size_t)hb_len)<<log2_seg_size;
 613       unsigned int ix_beg     = (unsigned int)(((char*)h-low_bound)/granule_size);
 614       unsigned int ix_end     = (unsigned int)(((char*)h-low_bound+(hb_bytelen-1))/granule_size);
 615       unsigned int compile_id = 0;
 616       CompLevel    comp_lvl   = CompLevel_none;
 617       compType     cType      = noComp;
 618       blobType     cbType     = noType;
 619 
 620       //---<  some sanity checks  >---
 621       // Do not assert here, just check, print error message and return.
 622       // This is a diagnostic function. It is not supposed to tear down the VM.
 623       if ((char*)h <  low_bound) {
 624         insane = true; ast->print_cr("Sanity check: HeapBlock @%p below low bound (%p)", (char*)h, low_bound);
 625       }
 626       if ((char*)h >  (low_bound + res_size)) {
 627         insane = true; ast->print_cr("Sanity check: HeapBlock @%p outside reserved range (%p)", (char*)h, low_bound + res_size);
 628       }
 629       if ((char*)h >  (low_bound + size)) {
 630         insane = true; ast->print_cr("Sanity check: HeapBlock @%p outside used range (%p)", (char*)h, low_bound + size);
 631       }
 632       if (ix_end   >= granules) {
 633         insane = true; ast->print_cr("Sanity check: end index (%d) out of bounds (" SIZE_FORMAT ")", ix_end, granules);
 634       }
 635       if (size     != heap->capacity()) {
 636         insane = true; ast->print_cr("Sanity check: code heap capacity has changed (" SIZE_FORMAT "K to " SIZE_FORMAT "K)", size/(size_t)K, heap->capacity()/(size_t)K);
 637       }
 638       if (ix_beg   >  ix_end) {
 639         insane = true; ast->print_cr("Sanity check: end index (%d) lower than begin index (%d)", ix_end, ix_beg);
 640       }
 641       if (insane) {
 642         STRINGSTREAM_FLUSH("")
 643         continue;
 644       }
 645 
 646       if (h->free()) {
 647         nBlocks_free++;
 648         freeSpace    += hb_bytelen;
 649         if (hb_bytelen > maxFreeSize) {
 650           maxFreeSize   = hb_bytelen;
 651           maxFreeBlock  = h;
 652         }
 653       } else {
 654         update_SizeDistArray(out, hb_len);
 655         nBlocks_used++;
 656         usedSpace    += hb_bytelen;
 657         CodeBlob* cb  = (CodeBlob*)heap->find_start(h);
 658         if (cb != NULL) {
 659           cbType = get_cbType(cb);
 660           if (cb->is_nmethod()) {
 661             compile_id = ((nmethod*)cb)->compile_id();
 662             comp_lvl   = (CompLevel)((nmethod*)cb)->comp_level();
 663             if (((nmethod*)cb)->is_compiled_by_c1()) {
 664               cType = c1;
 665             }
 666             if (((nmethod*)cb)->is_compiled_by_c2()) {
 667               cType = c2;
 668             }
 669             if (((nmethod*)cb)->is_compiled_by_jvmci()) {
 670               cType = jvmci;
 671             }
 672             switch (cbType) {
 673               case nMethod_inuse: { // only for executable methods!!!
 674                 // space for these cbs is accounted for later.
 675                 int temperature = ((nmethod*)cb)->hotness_counter();
 676                 hotnessAccumulator += temperature;
 677                 n_methods++;
 678                 maxTemp = (temperature > maxTemp) ? temperature : maxTemp;
 679                 minTemp = (temperature < minTemp) ? temperature : minTemp;
 680                 break;
 681               }
 682               case nMethod_notused:
 683                 nBlocks_alive++;
 684                 nBlocks_disconn++;
 685                 aliveSpace     += hb_bytelen;
 686                 disconnSpace   += hb_bytelen;
 687                 break;
 688               case nMethod_notentrant:  // equivalent to nMethod_alive
 689                 nBlocks_alive++;
 690                 nBlocks_notentr++;
 691                 aliveSpace     += hb_bytelen;
 692                 notentrSpace   += hb_bytelen;
 693                 break;
 694               case nMethod_unloaded:
 695                 nBlocks_unloaded++;
 696                 unloadedSpace  += hb_bytelen;
 697                 break;
 698               case nMethod_dead:
 699                 nBlocks_dead++;
 700                 deadSpace      += hb_bytelen;
 701                 break;
 702               case nMethod_inconstruction:
 703                 nBlocks_inconstr++;
 704                 inconstrSpace  += hb_bytelen;
 705                 break;
 706               default:
 707                 break;
 708             }
 709           }
 710 
 711           //------------------------------------------
 712           //---<  register block in TopSizeArray  >---
 713           //------------------------------------------
 714           if (alloc_topSizeBlocks > 0) {
 715             if (used_topSizeBlocks == 0) {
 716               TopSizeArray[0].start    = h;
 717               TopSizeArray[0].len      = hb_len;
 718               TopSizeArray[0].index    = tsbStopper;
 719               TopSizeArray[0].compiler = cType;
 720               TopSizeArray[0].level    = comp_lvl;
 721               TopSizeArray[0].type     = cbType;
 722               currMax    = hb_len;
 723               currMin    = hb_len;
 724               currMin_ix = 0;
 725               used_topSizeBlocks++;
 726             // This check roughly cuts 5000 iterations (JVM98, mixed, dbg, termination stats):
 727             } else if ((used_topSizeBlocks < alloc_topSizeBlocks) && (hb_len < currMin)) {
 728               //---<  all blocks in list are larger, but there is room left in array  >---
 729               TopSizeArray[currMin_ix].index = used_topSizeBlocks;
 730               TopSizeArray[used_topSizeBlocks].start    = h;
 731               TopSizeArray[used_topSizeBlocks].len      = hb_len;
 732               TopSizeArray[used_topSizeBlocks].index    = tsbStopper;
 733               TopSizeArray[used_topSizeBlocks].compiler = cType;
 734               TopSizeArray[used_topSizeBlocks].level    = comp_lvl;
 735               TopSizeArray[used_topSizeBlocks].type     = cbType;
 736               currMin    = hb_len;
 737               currMin_ix = used_topSizeBlocks;
 738               used_topSizeBlocks++;
 739             } else {
 740               // This check cuts total_iterations by a factor of 6 (JVM98, mixed, dbg, termination stats):
 741               //   We don't need to search the list if we know beforehand that the current block size is
 742               //   smaller than the currently recorded minimum and there is no free entry left in the list.
 743               if (!((used_topSizeBlocks == alloc_topSizeBlocks) && (hb_len <= currMin))) {
 744                 if (currMax < hb_len) {
 745                   currMax = hb_len;
 746                 }
 747                 unsigned int i;
 748                 unsigned int prev_i  = tsbStopper;
 749                 unsigned int limit_i =  0;
 750                 for (i = 0; i != tsbStopper; i = TopSizeArray[i].index) {
 751                   if (limit_i++ >= alloc_topSizeBlocks) {
 752                     insane = true; break; // emergency exit
 753                   }
 754                   if (i >= used_topSizeBlocks)  {
 755                     insane = true; break; // emergency exit
 756                   }
 757                   total_iterations++;
 758                   if (TopSizeArray[i].len < hb_len) {
 759                     //---<  We want to insert here, element <i> is smaller than the current one  >---
 760                     if (used_topSizeBlocks < alloc_topSizeBlocks) { // still room for a new entry to insert
 761                       // old entry gets moved to the next free element of the array.
 762                       // That's necessary to keep the entry for the largest block at index 0.
 763                       // This move might cause the current minimum to be moved to another place
 764                       if (i == currMin_ix) {
 765                         assert(TopSizeArray[i].len == currMin, "sort error");
 766                         currMin_ix = used_topSizeBlocks;
 767                       }
 768                       memcpy((void*)&TopSizeArray[used_topSizeBlocks], (void*)&TopSizeArray[i], sizeof(TopSizeBlk));
 769                       TopSizeArray[i].start    = h;
 770                       TopSizeArray[i].len      = hb_len;
 771                       TopSizeArray[i].index    = used_topSizeBlocks;
 772                       TopSizeArray[i].compiler = cType;
 773                       TopSizeArray[i].level    = comp_lvl;
 774                       TopSizeArray[i].type     = cbType;
 775                       used_topSizeBlocks++;
 776                     } else { // no room for new entries, current block replaces entry for smallest block
 777                       //---<  Find last entry (entry for smallest remembered block)  >---
 778                       unsigned int      j  = i;
 779                       unsigned int prev_j  = tsbStopper;
 780                       unsigned int limit_j = 0;
 781                       while (TopSizeArray[j].index != tsbStopper) {
 782                         if (limit_j++ >= alloc_topSizeBlocks) {
 783                           insane = true; break; // emergency exit
 784                         }
 785                         if (j >= used_topSizeBlocks)  {
 786                           insane = true; break; // emergency exit
 787                         }
 788                         total_iterations++;
 789                         prev_j = j;
 790                         j      = TopSizeArray[j].index;
 791                       }
 792                       if (!insane) {
 793                         if (prev_j == tsbStopper) {
 794                           //---<  Above while loop did not iterate, we already are the min entry  >---
 795                           //---<  We have to just replace the smallest entry                      >---
 796                           currMin    = hb_len;
 797                           currMin_ix = j;
 798                           TopSizeArray[j].start    = h;
 799                           TopSizeArray[j].len      = hb_len;
 800                           TopSizeArray[j].index    = tsbStopper; // already set!!
 801                           TopSizeArray[j].compiler = cType;
 802                           TopSizeArray[j].level    = comp_lvl;
 803                           TopSizeArray[j].type     = cbType;
 804                         } else {
 805                           //---<  second-smallest entry is now smallest  >---
 806                           TopSizeArray[prev_j].index = tsbStopper;
 807                           currMin    = TopSizeArray[prev_j].len;
 808                           currMin_ix = prev_j;
 809                           //---<  smallest entry gets overwritten  >---
 810                           memcpy((void*)&TopSizeArray[j], (void*)&TopSizeArray[i], sizeof(TopSizeBlk));
 811                           TopSizeArray[i].start    = h;
 812                           TopSizeArray[i].len      = hb_len;
 813                           TopSizeArray[i].index    = j;
 814                           TopSizeArray[i].compiler = cType;
 815                           TopSizeArray[i].level    = comp_lvl;
 816                           TopSizeArray[i].type     = cbType;
 817                         }
 818                       } // insane
 819                     }
 820                     break;
 821                   }
 822                   prev_i = i;
 823                 }
 824                 if (insane) {
 825                   // Note: regular analysis could probably continue by resetting "insane" flag.
 826                   out->print_cr("Possible loop in TopSizeBlocks list detected. Analysis aborted.");
 827                   discard_TopSizeArray(out);
 828                 }
 829               }
 830             }
 831           }
 832           //----------------------------------------------
 833           //---<  END register block in TopSizeArray  >---
 834           //----------------------------------------------
 835         } else {
 836           nBlocks_zomb++;
 837         }
 838 
 839         if (ix_beg == ix_end) {
 840           StatArray[ix_beg].type = cbType;
 841           switch (cbType) {
 842             case nMethod_inuse:
 843               highest_compilation_id = (highest_compilation_id >= compile_id) ? highest_compilation_id : compile_id;
 844               if (comp_lvl < CompLevel_full_optimization) {
 845                 nBlocks_t1++;
 846                 t1Space   += hb_bytelen;
 847                 StatArray[ix_beg].t1_count++;
 848                 StatArray[ix_beg].t1_space += (unsigned short)hb_len;
 849                 StatArray[ix_beg].t1_age    = StatArray[ix_beg].t1_age < compile_id ? compile_id : StatArray[ix_beg].t1_age;
 850               } else {
 851                 nBlocks_t2++;
 852                 t2Space   += hb_bytelen;
 853                 StatArray[ix_beg].t2_count++;
 854                 StatArray[ix_beg].t2_space += (unsigned short)hb_len;
 855                 StatArray[ix_beg].t2_age    = StatArray[ix_beg].t2_age < compile_id ? compile_id : StatArray[ix_beg].t2_age;
 856               }
 857               StatArray[ix_beg].level     = comp_lvl;
 858               StatArray[ix_beg].compiler  = cType;
 859               break;
 860             case nMethod_inconstruction: // let's count "in construction" nmethods here.
 861             case nMethod_alive:
 862               StatArray[ix_beg].tx_count++;
 863               StatArray[ix_beg].tx_space += (unsigned short)hb_len;
 864               StatArray[ix_beg].tx_age    = StatArray[ix_beg].tx_age < compile_id ? compile_id : StatArray[ix_beg].tx_age;
 865               StatArray[ix_beg].level     = comp_lvl;
 866               StatArray[ix_beg].compiler  = cType;
 867               break;
 868             case nMethod_dead:
 869             case nMethod_unloaded:
 870               StatArray[ix_beg].dead_count++;
 871               StatArray[ix_beg].dead_space += (unsigned short)hb_len;
 872               break;
 873             default:
 874               // must be a stub, if it's not a dead or alive nMethod
 875               nBlocks_stub++;
 876               stubSpace   += hb_bytelen;
 877               StatArray[ix_beg].stub_count++;
 878               StatArray[ix_beg].stub_space += (unsigned short)hb_len;
 879               break;
 880           }
 881         } else {
 882           unsigned int beg_space = (unsigned int)(granule_size - ((char*)h - low_bound - ix_beg*granule_size));
 883           unsigned int end_space = (unsigned int)(hb_bytelen - beg_space - (ix_end-ix_beg-1)*granule_size);
 884           beg_space = beg_space>>log2_seg_size;  // store in units of _segment_size
 885           end_space = end_space>>log2_seg_size;  // store in units of _segment_size
 886           StatArray[ix_beg].type = cbType;
 887           StatArray[ix_end].type = cbType;
 888           switch (cbType) {
 889             case nMethod_inuse:
 890               highest_compilation_id = (highest_compilation_id >= compile_id) ? highest_compilation_id : compile_id;
 891               if (comp_lvl < CompLevel_full_optimization) {
 892                 nBlocks_t1++;
 893                 t1Space   += hb_bytelen;
 894                 StatArray[ix_beg].t1_count++;
 895                 StatArray[ix_beg].t1_space += (unsigned short)beg_space;
 896                 StatArray[ix_beg].t1_age    = StatArray[ix_beg].t1_age < compile_id ? compile_id : StatArray[ix_beg].t1_age;
 897 
 898                 StatArray[ix_end].t1_count++;
 899                 StatArray[ix_end].t1_space += (unsigned short)end_space;
 900                 StatArray[ix_end].t1_age    = StatArray[ix_end].t1_age < compile_id ? compile_id : StatArray[ix_end].t1_age;
 901               } else {
 902                 nBlocks_t2++;
 903                 t2Space   += hb_bytelen;
 904                 StatArray[ix_beg].t2_count++;
 905                 StatArray[ix_beg].t2_space += (unsigned short)beg_space;
 906                 StatArray[ix_beg].t2_age    = StatArray[ix_beg].t2_age < compile_id ? compile_id : StatArray[ix_beg].t2_age;
 907 
 908                 StatArray[ix_end].t2_count++;
 909                 StatArray[ix_end].t2_space += (unsigned short)end_space;
 910                 StatArray[ix_end].t2_age    = StatArray[ix_end].t2_age < compile_id ? compile_id : StatArray[ix_end].t2_age;
 911               }
 912               StatArray[ix_beg].level     = comp_lvl;
 913               StatArray[ix_beg].compiler  = cType;
 914               StatArray[ix_end].level     = comp_lvl;
 915               StatArray[ix_end].compiler  = cType;
 916               break;
 917             case nMethod_inconstruction: // let's count "in construction" nmethods here.
 918             case nMethod_alive:
 919               StatArray[ix_beg].tx_count++;
 920               StatArray[ix_beg].tx_space += (unsigned short)beg_space;
 921               StatArray[ix_beg].tx_age    = StatArray[ix_beg].tx_age < compile_id ? compile_id : StatArray[ix_beg].tx_age;
 922 
 923               StatArray[ix_end].tx_count++;
 924               StatArray[ix_end].tx_space += (unsigned short)end_space;
 925               StatArray[ix_end].tx_age    = StatArray[ix_end].tx_age < compile_id ? compile_id : StatArray[ix_end].tx_age;
 926 
 927               StatArray[ix_beg].level     = comp_lvl;
 928               StatArray[ix_beg].compiler  = cType;
 929               StatArray[ix_end].level     = comp_lvl;
 930               StatArray[ix_end].compiler  = cType;
 931               break;
 932             case nMethod_dead:
 933             case nMethod_unloaded:
 934               StatArray[ix_beg].dead_count++;
 935               StatArray[ix_beg].dead_space += (unsigned short)beg_space;
 936               StatArray[ix_end].dead_count++;
 937               StatArray[ix_end].dead_space += (unsigned short)end_space;
 938               break;
 939             default:
 940               // must be a stub, if it's not a dead or alive nMethod
 941               nBlocks_stub++;
 942               stubSpace   += hb_bytelen;
 943               StatArray[ix_beg].stub_count++;
 944               StatArray[ix_beg].stub_space += (unsigned short)beg_space;
 945               StatArray[ix_end].stub_count++;
 946               StatArray[ix_end].stub_space += (unsigned short)end_space;
 947               break;
 948           }
 949           for (unsigned int ix = ix_beg+1; ix < ix_end; ix++) {
 950             StatArray[ix].type = cbType;
 951             switch (cbType) {
 952               case nMethod_inuse:
 953                 if (comp_lvl < CompLevel_full_optimization) {
 954                   StatArray[ix].t1_count++;
 955                   StatArray[ix].t1_space += (unsigned short)(granule_size>>log2_seg_size);
 956                   StatArray[ix].t1_age    = StatArray[ix].t1_age < compile_id ? compile_id : StatArray[ix].t1_age;
 957                 } else {
 958                   StatArray[ix].t2_count++;
 959                   StatArray[ix].t2_space += (unsigned short)(granule_size>>log2_seg_size);
 960                   StatArray[ix].t2_age    = StatArray[ix].t2_age < compile_id ? compile_id : StatArray[ix].t2_age;
 961                 }
 962                 StatArray[ix].level     = comp_lvl;
 963                 StatArray[ix].compiler  = cType;
 964                 break;
 965               case nMethod_inconstruction: // let's count "in construction" nmethods here.
 966               case nMethod_alive:
 967                 StatArray[ix].tx_count++;
 968                 StatArray[ix].tx_space += (unsigned short)(granule_size>>log2_seg_size);
 969                 StatArray[ix].tx_age    = StatArray[ix].tx_age < compile_id ? compile_id : StatArray[ix].tx_age;
 970                 StatArray[ix].level     = comp_lvl;
 971                 StatArray[ix].compiler  = cType;
 972                 break;
 973               case nMethod_dead:
 974               case nMethod_unloaded:
 975                 StatArray[ix].dead_count++;
 976                 StatArray[ix].dead_space += (unsigned short)(granule_size>>log2_seg_size);
 977                 break;
 978               default:
 979                 // must be a stub, if it's not a dead or alive nMethod
 980                 StatArray[ix].stub_count++;
 981                 StatArray[ix].stub_space += (unsigned short)(granule_size>>log2_seg_size);
 982                 break;
 983             }
 984           }
 985         }
 986       }
 987     }
 988     done = true;
 989 
 990     if (!insane) {
 991       // There is a risk for this block (because it contains many print statements) to get
 992       // interspersed with print data from other threads. We take this risk intentionally.
 993       // Getting stalled waiting for tty_lock while holding the CodeCache_lock is not desirable.
 994       printBox(ast, '-', "Global CodeHeap statistics for segment ", heapName);
 995       ast->print_cr("freeSpace        = " SIZE_FORMAT_W(8) "k, nBlocks_free     = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", freeSpace/(size_t)K,     nBlocks_free,     (100.0*freeSpace)/size,     (100.0*freeSpace)/res_size);
 996       ast->print_cr("usedSpace        = " SIZE_FORMAT_W(8) "k, nBlocks_used     = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", usedSpace/(size_t)K,     nBlocks_used,     (100.0*usedSpace)/size,     (100.0*usedSpace)/res_size);
 997       ast->print_cr("  Tier1 Space    = " SIZE_FORMAT_W(8) "k, nBlocks_t1       = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", t1Space/(size_t)K,       nBlocks_t1,       (100.0*t1Space)/size,       (100.0*t1Space)/res_size);
 998       ast->print_cr("  Tier2 Space    = " SIZE_FORMAT_W(8) "k, nBlocks_t2       = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", t2Space/(size_t)K,       nBlocks_t2,       (100.0*t2Space)/size,       (100.0*t2Space)/res_size);
 999       ast->print_cr("  Alive Space    = " SIZE_FORMAT_W(8) "k, nBlocks_alive    = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", aliveSpace/(size_t)K,    nBlocks_alive,    (100.0*aliveSpace)/size,    (100.0*aliveSpace)/res_size);
1000       ast->print_cr("    disconnected = " SIZE_FORMAT_W(8) "k, nBlocks_disconn  = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", disconnSpace/(size_t)K,  nBlocks_disconn,  (100.0*disconnSpace)/size,  (100.0*disconnSpace)/res_size);
1001       ast->print_cr("    not entrant  = " SIZE_FORMAT_W(8) "k, nBlocks_notentr  = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", notentrSpace/(size_t)K,  nBlocks_notentr,  (100.0*notentrSpace)/size,  (100.0*notentrSpace)/res_size);
1002       ast->print_cr("  inconstrSpace  = " SIZE_FORMAT_W(8) "k, nBlocks_inconstr = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", inconstrSpace/(size_t)K, nBlocks_inconstr, (100.0*inconstrSpace)/size, (100.0*inconstrSpace)/res_size);
1003       ast->print_cr("  unloadedSpace  = " SIZE_FORMAT_W(8) "k, nBlocks_unloaded = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", unloadedSpace/(size_t)K, nBlocks_unloaded, (100.0*unloadedSpace)/size, (100.0*unloadedSpace)/res_size);
1004       ast->print_cr("  deadSpace      = " SIZE_FORMAT_W(8) "k, nBlocks_dead     = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", deadSpace/(size_t)K,     nBlocks_dead,     (100.0*deadSpace)/size,     (100.0*deadSpace)/res_size);
1005       ast->print_cr("  stubSpace      = " SIZE_FORMAT_W(8) "k, nBlocks_stub     = %6d, %10.3f%% of capacity, %10.3f%% of max_capacity", stubSpace/(size_t)K,     nBlocks_stub,     (100.0*stubSpace)/size,     (100.0*stubSpace)/res_size);
1006       ast->print_cr("ZombieBlocks     = %8d. These are HeapBlocks which could not be identified as CodeBlobs.", nBlocks_zomb);
1007       ast->cr();
1008       ast->print_cr("Segment start          = " INTPTR_FORMAT ", used space      = " SIZE_FORMAT_W(8)"k", p2i(low_bound), size/K);
1009       ast->print_cr("Segment end (used)     = " INTPTR_FORMAT ", remaining space = " SIZE_FORMAT_W(8)"k", p2i(low_bound) + size, (res_size - size)/K);
1010       ast->print_cr("Segment end (reserved) = " INTPTR_FORMAT ", reserved space  = " SIZE_FORMAT_W(8)"k", p2i(low_bound) + res_size, res_size/K);
1011       ast->cr();
1012       ast->print_cr("latest allocated compilation id = %d", latest_compilation_id);
1013       ast->print_cr("highest observed compilation id = %d", highest_compilation_id);
1014       ast->print_cr("Building TopSizeList iterations = %ld", total_iterations);
1015       ast->cr();
1016 
1017       int             reset_val = NMethodSweeper::hotness_counter_reset_val();
1018       double reverse_free_ratio = (res_size > size) ? (double)res_size/(double)(res_size-size) : (double)res_size;
1019       printBox(ast, '-', "Method hotness information at time of this analysis", NULL);
1020       ast->print_cr("Highest possible method temperature:          %12d", reset_val);
1021       ast->print_cr("Threshold for method to be considered 'cold': %12.3f", -reset_val + reverse_free_ratio * NmethodSweepActivity);
1022       if (n_methods > 0) {
1023         avgTemp = hotnessAccumulator/n_methods;
1024         ast->print_cr("min. hotness = %6d", minTemp);
1025         ast->print_cr("avg. hotness = %6d", avgTemp);
1026         ast->print_cr("max. hotness = %6d", maxTemp);
1027       } else {
1028         avgTemp = 0;
1029         ast->print_cr("No hotness data available");
1030       }
1031       STRINGSTREAM_FLUSH("\n")
1032 
1033       // This loop is intentionally printing directly to "out".
1034       out->print("Verifying collected data...");
1035       size_t granule_segs = granule_size>>log2_seg_size;
1036       for (unsigned int ix = 0; ix < granules; ix++) {
1037         if (StatArray[ix].t1_count   > granule_segs) {
1038           out->print_cr("t1_count[%d]   = %d", ix, StatArray[ix].t1_count);
1039         }
1040         if (StatArray[ix].t2_count   > granule_segs) {
1041           out->print_cr("t2_count[%d]   = %d", ix, StatArray[ix].t2_count);
1042         }
1043         if (StatArray[ix].tx_count   > granule_segs) {
1044           out->print_cr("tx_count[%d]   = %d", ix, StatArray[ix].tx_count);
1045         }
1046         if (StatArray[ix].stub_count > granule_segs) {
1047           out->print_cr("stub_count[%d] = %d", ix, StatArray[ix].stub_count);
1048         }
1049         if (StatArray[ix].dead_count > granule_segs) {
1050           out->print_cr("dead_count[%d] = %d", ix, StatArray[ix].dead_count);
1051         }
1052         if (StatArray[ix].t1_space   > granule_segs) {
1053           out->print_cr("t1_space[%d]   = %d", ix, StatArray[ix].t1_space);
1054         }
1055         if (StatArray[ix].t2_space   > granule_segs) {
1056           out->print_cr("t2_space[%d]   = %d", ix, StatArray[ix].t2_space);
1057         }
1058         if (StatArray[ix].tx_space   > granule_segs) {
1059           out->print_cr("tx_space[%d]   = %d", ix, StatArray[ix].tx_space);
1060         }
1061         if (StatArray[ix].stub_space > granule_segs) {
1062           out->print_cr("stub_space[%d] = %d", ix, StatArray[ix].stub_space);
1063         }
1064         if (StatArray[ix].dead_space > granule_segs) {
1065           out->print_cr("dead_space[%d] = %d", ix, StatArray[ix].dead_space);
1066         }
1067         //   this cast is awful! I need it because NT/Intel reports a signed/unsigned mismatch.
1068         if ((size_t)(StatArray[ix].t1_count+StatArray[ix].t2_count+StatArray[ix].tx_count+StatArray[ix].stub_count+StatArray[ix].dead_count) > granule_segs) {
1069           out->print_cr("t1_count[%d] = %d, t2_count[%d] = %d, tx_count[%d] = %d, stub_count[%d] = %d", ix, StatArray[ix].t1_count, ix, StatArray[ix].t2_count, ix, StatArray[ix].tx_count, ix, StatArray[ix].stub_count);
1070         }
1071         if ((size_t)(StatArray[ix].t1_space+StatArray[ix].t2_space+StatArray[ix].tx_space+StatArray[ix].stub_space+StatArray[ix].dead_space) > granule_segs) {
1072           out->print_cr("t1_space[%d] = %d, t2_space[%d] = %d, tx_space[%d] = %d, stub_space[%d] = %d", ix, StatArray[ix].t1_space, ix, StatArray[ix].t2_space, ix, StatArray[ix].tx_space, ix, StatArray[ix].stub_space);
1073         }
1074       }
1075 
1076       // This loop is intentionally printing directly to "out".
1077       if (used_topSizeBlocks > 0) {
1078         unsigned int j = 0;
1079         if (TopSizeArray[0].len != currMax) {
1080           out->print_cr("currMax(%d) differs from TopSizeArray[0].len(%d)", currMax, TopSizeArray[0].len);
1081         }
1082         for (unsigned int i = 0; (TopSizeArray[i].index != tsbStopper) && (j++ < alloc_topSizeBlocks); i = TopSizeArray[i].index) {
1083           if (TopSizeArray[i].len < TopSizeArray[TopSizeArray[i].index].len) {
1084             out->print_cr("sort error at index %d: %d !>= %d", i, TopSizeArray[i].len, TopSizeArray[TopSizeArray[i].index].len);
1085           }
1086         }
1087         if (j >= alloc_topSizeBlocks) {
1088           out->print_cr("Possible loop in TopSizeArray chaining!\n  allocBlocks = %d, usedBlocks = %d", alloc_topSizeBlocks, used_topSizeBlocks);
1089           for (unsigned int i = 0; i < alloc_topSizeBlocks; i++) {
1090             out->print_cr("  TopSizeArray[%d].index = %d, len = %d", i, TopSizeArray[i].index, TopSizeArray[i].len);
1091           }
1092         }
1093       }
1094       out->print_cr("...done\n\n");
1095     } else {
1096       // insane heap state detected. Analysis data incomplete. Just throw it away.
1097       discard_StatArray(out);
1098       discard_TopSizeArray(out);
1099     }
1100   }
1101 
1102 
1103   done        = false;
1104   while (!done && (nBlocks_free > 0)) {
1105 
1106     printBox(ast, '=', "C O D E   H E A P   A N A L Y S I S   (free blocks) for segment ", heapName);
1107     ast->print_cr("   The aggregate step collects information about all free blocks in CodeHeap.\n"
1108                   "   Subsequent print functions create their output based on this snapshot.\n");
1109     ast->print_cr("   Free space in %s is distributed over %d free blocks.", heapName, nBlocks_free);
1110     ast->print_cr("   Each free block takes " SIZE_FORMAT " bytes of C heap for statistics data, that is " SIZE_FORMAT "K in total.", sizeof(FreeBlk), (sizeof(FreeBlk)*nBlocks_free)/K);
1111     STRINGSTREAM_FLUSH("\n")
1112 
1113     //----------------------------------------
1114     //--  Prepare the FreeArray of FreeBlks --
1115     //----------------------------------------
1116 
1117     //---< discard old array if size does not match  >---
1118     if (nBlocks_free != alloc_freeBlocks) {
1119       discard_FreeArray(out);
1120     }
1121 
1122     prepare_FreeArray(out, nBlocks_free, heapName);
1123     if (FreeArray == NULL) {
1124       done = true;
1125       continue;
1126     }
1127 
1128     //----------------------------------------
1129     //--  Collect all FreeBlks in FreeArray --
1130     //----------------------------------------
1131 
1132     unsigned int ix = 0;
1133     FreeBlock* cur  = heap->freelist();
1134 
1135     while (cur != NULL) {
1136       if (ix < alloc_freeBlocks) { // don't index out of bounds if _freelist has more blocks than anticipated
1137         FreeArray[ix].start = cur;
1138         FreeArray[ix].len   = (unsigned int)(cur->length()<<log2_seg_size);
1139         FreeArray[ix].index = ix;
1140       }
1141       cur  = cur->link();
1142       ix++;
1143     }
1144     if (ix != alloc_freeBlocks) {
1145       ast->print_cr("Free block count mismatch. Expected %d free blocks, but found %d.", alloc_freeBlocks, ix);
1146       ast->print_cr("I will update the counter and retry data collection");
1147       STRINGSTREAM_FLUSH("\n")
1148       nBlocks_free = ix;
1149       continue;
1150     }
1151     done = true;
1152   }
1153 
1154   if (!done || (nBlocks_free == 0)) {
1155     if (nBlocks_free == 0) {
1156       printBox(ast, '-', "no free blocks found in ", heapName);
1157     } else if (!done) {
1158       ast->print_cr("Free block count mismatch could not be resolved.");
1159       ast->print_cr("Try to run \"aggregate\" function to update counters");
1160     }
1161     STRINGSTREAM_FLUSH("")
1162 
1163     //---< discard old array and update global values  >---
1164     discard_FreeArray(out);
1165     set_HeapStatGlobals(out, heapName);
1166     return;
1167   }
1168 
1169   //---<  calculate and fill remaining fields  >---
1170   if (FreeArray != NULL) {
1171     // This loop is intentionally printing directly to "out".
1172     for (unsigned int ix = 0; ix < alloc_freeBlocks-1; ix++) {
1173       size_t lenSum = 0;
1174       FreeArray[ix].gap = (unsigned int)((address)FreeArray[ix+1].start - ((address)FreeArray[ix].start + FreeArray[ix].len));
1175       for (HeapBlock *h = heap->next_block(FreeArray[ix].start); (h != NULL) && (h != FreeArray[ix+1].start); h = heap->next_block(h)) {
1176         CodeBlob *cb  = (CodeBlob*)(heap->find_start(h));
1177         if ((cb != NULL) && !cb->is_nmethod()) {
1178           FreeArray[ix].stubs_in_gap = true;
1179         }
1180         FreeArray[ix].n_gapBlocks++;
1181         lenSum += h->length()<<log2_seg_size;
1182         if (((address)h < ((address)FreeArray[ix].start+FreeArray[ix].len)) || (h >= FreeArray[ix+1].start)) {
1183           out->print_cr("unsorted occupied CodeHeap block found @ %p, gap interval [%p, %p)", h, (address)FreeArray[ix].start+FreeArray[ix].len, FreeArray[ix+1].start);
1184         }
1185       }
1186       if (lenSum != FreeArray[ix].gap) {
1187         out->print_cr("Length mismatch for gap between FreeBlk[%d] and FreeBlk[%d]. Calculated: %d, accumulated: %d.", ix, ix+1, FreeArray[ix].gap, (unsigned int)lenSum);
1188       }
1189     }
1190   }
1191   set_HeapStatGlobals(out, heapName);
1192 
1193   printBox(ast, '=', "C O D E   H E A P   A N A L Y S I S   C O M P L E T E   for segment ", heapName);
1194   STRINGSTREAM_FLUSH("\n")
1195 }
1196 
1197 
1198 void CodeHeapState::print_usedSpace(outputStream* out, CodeHeap* heap) {
1199   if (!initialization_complete) {
1200     return;
1201   }
1202 
1203   const char* heapName   = get_heapName(heap);
1204   get_HeapStatGlobals(out, heapName);
1205 
1206   if ((StatArray == NULL) || (TopSizeArray == NULL) || (used_topSizeBlocks == 0)) {
1207     return;
1208   }
1209   STRINGSTREAM_DECL(ast, out)
1210 
1211   {
1212     printBox(ast, '=', "U S E D   S P A C E   S T A T I S T I C S   for ", heapName);
1213     ast->print_cr("Note: The Top%d list of the largest used blocks associates method names\n"
1214                   "      and other identifying information with the block size data.\n"
1215                   "\n"
1216                   "      Method names are dynamically retrieved from the code cache at print time.\n"
1217                   "      Due to the living nature of the code cache and because the CodeCache_lock\n"
1218                   "      is not continuously held, the displayed name might be wrong or no name\n"
1219                   "      might be found at all. The likelihood for that to happen increases\n"
1220                   "      over time passed between analysis and print step.\n", used_topSizeBlocks);
1221     STRINGSTREAM_FLUSH_LOCKED("\n")
1222   }
1223 
1224   //----------------------------
1225   //--  Print Top Used Blocks --
1226   //----------------------------
1227   {
1228     char*     low_bound = heap->low_boundary();
1229 
1230     printBox(ast, '-', "Largest Used Blocks in ", heapName);
1231     print_blobType_legend(ast);
1232 
1233     ast->fill_to(51);
1234     ast->print("%4s", "blob");
1235     ast->fill_to(56);
1236     ast->print("%9s", "compiler");
1237     ast->fill_to(66);
1238     ast->print_cr("%6s", "method");
1239     ast->print_cr("%18s %13s %17s %4s %9s  %5s %s",      "Addr(module)      ", "offset", "size", "type", " type lvl", " temp", "Name");
1240     STRINGSTREAM_FLUSH_LOCKED("")
1241 
1242     //---<  print Top Ten Used Blocks  >---
1243     if (used_topSizeBlocks > 0) {
1244       unsigned int printed_topSizeBlocks = 0;
1245       for (unsigned int i = 0; i != tsbStopper; i = TopSizeArray[i].index) {
1246         printed_topSizeBlocks++;
1247         CodeBlob*   this_blob = (CodeBlob*)(heap->find_start(TopSizeArray[i].start));
1248         nmethod*           nm = NULL;
1249         const char* blob_name = "unnamed blob";
1250         if (this_blob != NULL) {
1251           blob_name = this_blob->name();
1252           nm        = this_blob->as_nmethod_or_null();
1253           //---<  blob address  >---
1254           ast->print(INTPTR_FORMAT, p2i(this_blob));
1255           ast->fill_to(19);
1256           //---<  blob offset from CodeHeap begin  >---
1257           ast->print("(+" PTR32_FORMAT ")", (unsigned int)((char*)this_blob-low_bound));
1258           ast->fill_to(33);
1259         } else {
1260           //---<  block address  >---
1261           ast->print(INTPTR_FORMAT, p2i(TopSizeArray[i].start));
1262           ast->fill_to(19);
1263           //---<  block offset from CodeHeap begin  >---
1264           ast->print("(+" PTR32_FORMAT ")", (unsigned int)((char*)TopSizeArray[i].start-low_bound));
1265           ast->fill_to(33);
1266         }
1267 
1268 
1269         //---<  print size, name, and signature (for nMethods)  >---
1270         if ((nm != NULL) && (nm->method() != NULL)) {
1271           ResourceMark rm;
1272           //---<  nMethod size in hex  >---
1273           unsigned int total_size = nm->total_size();
1274           ast->print(PTR32_FORMAT, total_size);
1275           ast->print("(" SIZE_FORMAT_W(4) "K)", total_size/K);
1276           ast->fill_to(51);
1277           ast->print("  %c", blobTypeChar[TopSizeArray[i].type]);
1278           //---<  compiler information  >---
1279           ast->fill_to(56);
1280           ast->print("%5s %3d", compTypeName[TopSizeArray[i].compiler], TopSizeArray[i].level);
1281           //---<  method temperature  >---
1282           ast->fill_to(67);
1283           ast->print("%5d", nm->hotness_counter());
1284           //---<  name and signature  >---
1285           ast->fill_to(67+6);
1286           if (nm->is_in_use())        {blob_name = nm->method()->name_and_sig_as_C_string(); }
1287           if (nm->is_not_entrant())   {blob_name = nm->method()->name_and_sig_as_C_string(); }
1288           if (nm->is_not_installed()) {ast->print("%s", " not (yet) installed method "); }
1289           if (nm->is_zombie())        {ast->print("%s", " zombie method "); }
1290           ast->print("%s", blob_name);
1291         } else {
1292           //---<  block size in hex  >---
1293           ast->print(PTR32_FORMAT, (unsigned int)(TopSizeArray[i].len<<log2_seg_size));
1294           ast->print("(" SIZE_FORMAT_W(4) "K)", (TopSizeArray[i].len<<log2_seg_size)/K);
1295           //---<  no compiler information  >---
1296           ast->fill_to(56);
1297           //---<  name and signature  >---
1298           ast->fill_to(67+6);
1299           ast->print("%s", blob_name);
1300         }
1301         STRINGSTREAM_FLUSH_LOCKED("\n")
1302       }
1303       if (used_topSizeBlocks != printed_topSizeBlocks) {
1304         ast->print_cr("used blocks: %d, printed blocks: %d", used_topSizeBlocks, printed_topSizeBlocks);
1305         STRINGSTREAM_FLUSH("")
1306         for (unsigned int i = 0; i < alloc_topSizeBlocks; i++) {
1307           ast->print_cr("  TopSizeArray[%d].index = %d, len = %d", i, TopSizeArray[i].index, TopSizeArray[i].len);
1308           STRINGSTREAM_FLUSH("")
1309         }
1310       }
1311       STRINGSTREAM_FLUSH_LOCKED("\n\n")
1312     }
1313   }
1314 
1315   //-----------------------------
1316   //--  Print Usage Histogram  --
1317   //-----------------------------
1318 
1319   if (SizeDistributionArray != NULL) {
1320     unsigned long total_count = 0;
1321     unsigned long total_size  = 0;
1322     const unsigned long pctFactor = 200;
1323 
1324     for (unsigned int i = 0; i < nSizeDistElements; i++) {
1325       total_count += SizeDistributionArray[i].count;
1326       total_size  += SizeDistributionArray[i].lenSum;
1327     }
1328 
1329     if ((total_count > 0) && (total_size > 0)) {
1330       printBox(ast, '-', "Block count histogram for ", heapName);
1331       ast->print_cr("Note: The histogram indicates how many blocks (as a percentage\n"
1332                     "      of all blocks) have a size in the given range.\n"
1333                     "      %ld characters are printed per percentage point.\n", pctFactor/100);
1334       ast->print_cr("total size   of all blocks: %7ldM", (total_size<<log2_seg_size)/M);
1335       ast->print_cr("total number of all blocks: %7ld\n", total_count);
1336       STRINGSTREAM_FLUSH_LOCKED("")
1337 
1338       ast->print_cr("[Size Range)------avg.-size-+----count-+");
1339       for (unsigned int i = 0; i < nSizeDistElements; i++) {
1340         if (SizeDistributionArray[i].rangeStart<<log2_seg_size < K) {
1341           ast->print("[" SIZE_FORMAT_W(5) " .." SIZE_FORMAT_W(5) " ): "
1342                     ,(size_t)(SizeDistributionArray[i].rangeStart<<log2_seg_size)
1343                     ,(size_t)(SizeDistributionArray[i].rangeEnd<<log2_seg_size)
1344                     );
1345         } else if (SizeDistributionArray[i].rangeStart<<log2_seg_size < M) {
1346           ast->print("[" SIZE_FORMAT_W(5) "K.." SIZE_FORMAT_W(5) "K): "
1347                     ,(SizeDistributionArray[i].rangeStart<<log2_seg_size)/K
1348                     ,(SizeDistributionArray[i].rangeEnd<<log2_seg_size)/K
1349                     );
1350         } else {
1351           ast->print("[" SIZE_FORMAT_W(5) "M.." SIZE_FORMAT_W(5) "M): "
1352                     ,(SizeDistributionArray[i].rangeStart<<log2_seg_size)/M
1353                     ,(SizeDistributionArray[i].rangeEnd<<log2_seg_size)/M
1354                     );
1355         }
1356         ast->print(" %8d | %8d |",
1357                    SizeDistributionArray[i].count > 0 ? (SizeDistributionArray[i].lenSum<<log2_seg_size)/SizeDistributionArray[i].count : 0,
1358                    SizeDistributionArray[i].count);
1359 
1360         unsigned int percent = pctFactor*SizeDistributionArray[i].count/total_count;
1361         for (unsigned int j = 1; j <= percent; j++) {
1362           ast->print("%c", (j%((pctFactor/100)*10) == 0) ? ('0'+j/(((unsigned int)pctFactor/100)*10)) : '*');
1363         }
1364         ast->cr();
1365       }
1366       ast->print_cr("----------------------------+----------+\n\n");
1367       STRINGSTREAM_FLUSH_LOCKED("\n")
1368 
1369       printBox(ast, '-', "Contribution per size range to total size for ", heapName);
1370       ast->print_cr("Note: The histogram indicates how much space (as a percentage of all\n"
1371                     "      occupied space) is used by the blocks in the given size range.\n"
1372                     "      %ld characters are printed per percentage point.\n", pctFactor/100);
1373       ast->print_cr("total size   of all blocks: %7ldM", (total_size<<log2_seg_size)/M);
1374       ast->print_cr("total number of all blocks: %7ld\n", total_count);
1375       STRINGSTREAM_FLUSH_LOCKED("")
1376 
1377       ast->print_cr("[Size Range)------avg.-size-+----count-+");
1378       for (unsigned int i = 0; i < nSizeDistElements; i++) {
1379         if (SizeDistributionArray[i].rangeStart<<log2_seg_size < K) {
1380           ast->print("[" SIZE_FORMAT_W(5) " .." SIZE_FORMAT_W(5) " ): "
1381                     ,(size_t)(SizeDistributionArray[i].rangeStart<<log2_seg_size)
1382                     ,(size_t)(SizeDistributionArray[i].rangeEnd<<log2_seg_size)
1383                     );
1384         } else if (SizeDistributionArray[i].rangeStart<<log2_seg_size < M) {
1385           ast->print("[" SIZE_FORMAT_W(5) "K.." SIZE_FORMAT_W(5) "K): "
1386                     ,(SizeDistributionArray[i].rangeStart<<log2_seg_size)/K
1387                     ,(SizeDistributionArray[i].rangeEnd<<log2_seg_size)/K
1388                     );
1389         } else {
1390           ast->print("[" SIZE_FORMAT_W(5) "M.." SIZE_FORMAT_W(5) "M): "
1391                     ,(SizeDistributionArray[i].rangeStart<<log2_seg_size)/M
1392                     ,(SizeDistributionArray[i].rangeEnd<<log2_seg_size)/M
1393                     );
1394         }
1395         ast->print(" %8d | %8d |",
1396                    SizeDistributionArray[i].count > 0 ? (SizeDistributionArray[i].lenSum<<log2_seg_size)/SizeDistributionArray[i].count : 0,
1397                    SizeDistributionArray[i].count);
1398 
1399         unsigned int percent = pctFactor*(unsigned long)SizeDistributionArray[i].lenSum/total_size;
1400         for (unsigned int j = 1; j <= percent; j++) {
1401           ast->print("%c", (j%((pctFactor/100)*10) == 0) ? ('0'+j/(((unsigned int)pctFactor/100)*10)) : '*');
1402         }
1403         ast->cr();
1404       }
1405       ast->print_cr("----------------------------+----------+");
1406       STRINGSTREAM_FLUSH_LOCKED("\n\n\n")
1407     }
1408   }
1409 }
1410 
1411 
1412 void CodeHeapState::print_freeSpace(outputStream* out, CodeHeap* heap) {
1413   if (!initialization_complete) {
1414     return;
1415   }
1416 
1417   const char* heapName   = get_heapName(heap);
1418   get_HeapStatGlobals(out, heapName);
1419 
1420   if ((StatArray == NULL) || (FreeArray == NULL) || (alloc_granules == 0)) {
1421     return;
1422   }
1423   STRINGSTREAM_DECL(ast, out)
1424 
1425   {
1426     printBox(ast, '=', "F R E E   S P A C E   S T A T I S T I C S   for ", heapName);
1427     ast->print_cr("Note: in this context, a gap is the occupied space between two free blocks.\n"
1428                   "      Those gaps are of interest if there is a chance that they become\n"
1429                   "      unoccupied, e.g. by class unloading. Then, the two adjacent free\n"
1430                   "      blocks, together with the now unoccupied space, form a new, large\n"
1431                   "      free block.");
1432     STRINGSTREAM_FLUSH_LOCKED("\n")
1433   }
1434 
1435   {
1436     printBox(ast, '-', "List of all Free Blocks in ", heapName);
1437     STRINGSTREAM_FLUSH_LOCKED("")
1438 
1439     unsigned int ix = 0;
1440     for (ix = 0; ix < alloc_freeBlocks-1; ix++) {
1441       ast->print(INTPTR_FORMAT ": Len[%4d] = " HEX32_FORMAT ",", p2i(FreeArray[ix].start), ix, FreeArray[ix].len);
1442       ast->fill_to(38);
1443       ast->print("Gap[%4d..%4d]: " HEX32_FORMAT " bytes,", ix, ix+1, FreeArray[ix].gap);
1444       ast->fill_to(71);
1445       ast->print("block count: %6d", FreeArray[ix].n_gapBlocks);
1446       if (FreeArray[ix].stubs_in_gap) {
1447         ast->print(" !! permanent gap, contains stubs and/or blobs !!");
1448       }
1449       STRINGSTREAM_FLUSH_LOCKED("\n")
1450     }
1451     ast->print_cr(INTPTR_FORMAT ": Len[%4d] = " HEX32_FORMAT, p2i(FreeArray[ix].start), ix, FreeArray[ix].len);
1452     STRINGSTREAM_FLUSH_LOCKED("\n\n")
1453   }
1454 
1455 
1456   //-----------------------------------------
1457   //--  Find and Print Top Ten Free Blocks --
1458   //-----------------------------------------
1459 
1460   //---<  find Top Ten Free Blocks  >---
1461   const unsigned int nTop = 10;
1462   unsigned int  currMax10 = 0;
1463   struct FreeBlk* FreeTopTen[nTop];
1464   memset(FreeTopTen, 0, sizeof(FreeTopTen));
1465 
1466   for (unsigned int ix = 0; ix < alloc_freeBlocks; ix++) {
1467     if (FreeArray[ix].len > currMax10) {  // larger than the ten largest found so far
1468       unsigned int currSize = FreeArray[ix].len;
1469 
1470       unsigned int iy;
1471       for (iy = 0; iy < nTop && FreeTopTen[iy] != NULL; iy++) {
1472         if (FreeTopTen[iy]->len < currSize) {
1473           for (unsigned int iz = nTop-1; iz > iy; iz--) { // make room to insert new free block
1474             FreeTopTen[iz] = FreeTopTen[iz-1];
1475           }
1476           FreeTopTen[iy] = &FreeArray[ix];        // insert new free block
1477           if (FreeTopTen[nTop-1] != NULL) {
1478             currMax10 = FreeTopTen[nTop-1]->len;
1479           }
1480           break; // done with this, check next free block
1481         }
1482       }
1483       if (iy >= nTop) {
1484         ast->print_cr("Internal logic error. New Max10 = %d detected, but could not be merged. Old Max10 = %d",
1485                       currSize, currMax10);
1486         continue;
1487       }
1488       if (FreeTopTen[iy] == NULL) {
1489         FreeTopTen[iy] = &FreeArray[ix];
1490         if (iy == (nTop-1)) {
1491           currMax10 = currSize;
1492         }
1493       }
1494     }
1495   }
1496   STRINGSTREAM_FLUSH_LOCKED("")
1497 
1498   {
1499     printBox(ast, '-', "Top Ten Free Blocks in ", heapName);
1500 
1501     //---<  print Top Ten Free Blocks  >---
1502     for (unsigned int iy = 0; (iy < nTop) && (FreeTopTen[iy] != NULL); iy++) {
1503       ast->print("Pos %3d: Block %4d - size " HEX32_FORMAT ",", iy+1, FreeTopTen[iy]->index, FreeTopTen[iy]->len);
1504       ast->fill_to(39);
1505       if (FreeTopTen[iy]->index == (alloc_freeBlocks-1)) {
1506         ast->print("last free block in list.");
1507       } else {
1508         ast->print("Gap (to next) " HEX32_FORMAT ",", FreeTopTen[iy]->gap);
1509         ast->fill_to(63);
1510         ast->print("#blocks (in gap) %d", FreeTopTen[iy]->n_gapBlocks);
1511       }
1512       ast->cr();
1513     }
1514     STRINGSTREAM_FLUSH_LOCKED("\n\n")
1515   }
1516 
1517 
1518   //--------------------------------------------------------
1519   //--  Find and Print Top Ten Free-Occupied-Free Triples --
1520   //--------------------------------------------------------
1521 
1522   //---<  find and print Top Ten Triples (Free-Occupied-Free)  >---
1523   currMax10 = 0;
1524   struct FreeBlk  *FreeTopTenTriple[nTop];
1525   memset(FreeTopTenTriple, 0, sizeof(FreeTopTenTriple));
1526 
1527   for (unsigned int ix = 0; ix < alloc_freeBlocks-1; ix++) {
1528     // If there are stubs in the gap, this gap will never become completely free.
1529     // The triple will thus never merge to one free block.
1530     unsigned int lenTriple  = FreeArray[ix].len + (FreeArray[ix].stubs_in_gap ? 0 : FreeArray[ix].gap + FreeArray[ix+1].len);
1531     FreeArray[ix].len = lenTriple;
1532     if (lenTriple > currMax10) {  // larger than the ten largest found so far
1533 
1534       unsigned int iy;
1535       for (iy = 0; (iy < nTop) && (FreeTopTenTriple[iy] != NULL); iy++) {
1536         if (FreeTopTenTriple[iy]->len < lenTriple) {
1537           for (unsigned int iz = nTop-1; iz > iy; iz--) {
1538             FreeTopTenTriple[iz] = FreeTopTenTriple[iz-1];
1539           }
1540           FreeTopTenTriple[iy] = &FreeArray[ix];
1541           if (FreeTopTenTriple[nTop-1] != NULL) {
1542             currMax10 = FreeTopTenTriple[nTop-1]->len;
1543           }
1544           break;
1545         }
1546       }
1547       if (iy == nTop) {
1548         ast->print_cr("Internal logic error. New Max10 = %d detected, but could not be merged. Old Max10 = %d",
1549                       lenTriple, currMax10);
1550         continue;
1551       }
1552       if (FreeTopTenTriple[iy] == NULL) {
1553         FreeTopTenTriple[iy] = &FreeArray[ix];
1554         if (iy == (nTop-1)) {
1555           currMax10 = lenTriple;
1556         }
1557       }
1558     }
1559   }
1560   STRINGSTREAM_FLUSH_LOCKED("")
1561 
1562   {
1563     printBox(ast, '-', "Top Ten Free-Occupied-Free Triples in ", heapName);
1564     ast->print_cr("  Use this information to judge how likely it is that a large(r) free block\n"
1565                   "  might get created by code cache sweeping.\n"
1566                   "  If all the occupied blocks can be swept, the three free blocks will be\n"
1567                   "  merged into one (much larger) free block. That would reduce free space\n"
1568                   "  fragmentation.\n");
1569 
1570     //---<  print Top Ten Free-Occupied-Free Triples  >---
1571     for (unsigned int iy = 0; (iy < nTop) && (FreeTopTenTriple[iy] != NULL); iy++) {
1572       ast->print("Pos %3d: Block %4d - size " HEX32_FORMAT ",", iy+1, FreeTopTenTriple[iy]->index, FreeTopTenTriple[iy]->len);
1573       ast->fill_to(39);
1574       ast->print("Gap (to next) " HEX32_FORMAT ",", FreeTopTenTriple[iy]->gap);
1575       ast->fill_to(63);
1576       ast->print("#blocks (in gap) %d", FreeTopTenTriple[iy]->n_gapBlocks);
1577       ast->cr();
1578     }
1579     STRINGSTREAM_FLUSH_LOCKED("\n\n")
1580   }
1581 }
1582 
1583 
1584 void CodeHeapState::print_count(outputStream* out, CodeHeap* heap) {
1585   if (!initialization_complete) {
1586     return;
1587   }
1588 
1589   const char* heapName   = get_heapName(heap);
1590   get_HeapStatGlobals(out, heapName);
1591 
1592   if ((StatArray == NULL) || (alloc_granules == 0)) {
1593     return;
1594   }
1595   STRINGSTREAM_DECL(ast, out)
1596 
1597   unsigned int granules_per_line = 32;
1598   char*        low_bound         = heap->low_boundary();
1599 
1600   {
1601     printBox(ast, '=', "B L O C K   C O U N T S   for ", heapName);
1602     ast->print_cr("  Each granule contains an individual number of heap blocks. Large blocks\n"
1603                   "  may span multiple granules and are counted for each granule they touch.\n");
1604     if (segment_granules) {
1605       ast->print_cr("  You have selected granule size to be as small as segment size.\n"
1606                     "  As a result, each granule contains exactly one block (or a part of one block)\n"
1607                     "  or is displayed as empty (' ') if it's BlobType does not match the selection.\n"
1608                     "  Occupied granules show their BlobType character, see legend.\n");
1609       print_blobType_legend(ast);
1610     }
1611     STRINGSTREAM_FLUSH_LOCKED("")
1612   }
1613 
1614   {
1615     if (segment_granules) {
1616       printBox(ast, '-', "Total (all types) count for granule size == segment size", NULL);
1617       STRINGSTREAM_FLUSH_LOCKED("")
1618 
1619       granules_per_line = 128;
1620       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1621         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1622         print_blobType_single(ast, StatArray[ix].type);
1623       }
1624     } else {
1625       printBox(ast, '-', "Total (all tiers) count, 0x1..0xf. '*' indicates >= 16 blocks, ' ' indicates empty", NULL);
1626       STRINGSTREAM_FLUSH_LOCKED("")
1627 
1628       granules_per_line = 128;
1629       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1630         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1631         unsigned int count = StatArray[ix].t1_count   + StatArray[ix].t2_count   + StatArray[ix].tx_count
1632                            + StatArray[ix].stub_count + StatArray[ix].dead_count;
1633         print_count_single(ast, count);
1634       }
1635     }
1636     STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
1637   }
1638 
1639   {
1640     if (nBlocks_t1 > 0) {
1641       printBox(ast, '-', "Tier1 nMethod count only, 0x1..0xf. '*' indicates >= 16 blocks, ' ' indicates empty", NULL);
1642       STRINGSTREAM_FLUSH_LOCKED("")
1643 
1644       granules_per_line = 128;
1645       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1646         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1647         if (segment_granules && StatArray[ix].t1_count > 0) {
1648           print_blobType_single(ast, StatArray[ix].type);
1649         } else {
1650           print_count_single(ast, StatArray[ix].t1_count);
1651         }
1652       }
1653       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
1654     } else {
1655       ast->print("No Tier1 nMethods found in CodeHeap.");
1656       STRINGSTREAM_FLUSH_LOCKED("\n\n\n")
1657     }
1658   }
1659 
1660   {
1661     if (nBlocks_t2 > 0) {
1662       printBox(ast, '-', "Tier2 nMethod count only, 0x1..0xf. '*' indicates >= 16 blocks, ' ' indicates empty", NULL);
1663       STRINGSTREAM_FLUSH_LOCKED("")
1664 
1665       granules_per_line = 128;
1666       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1667         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1668         if (segment_granules && StatArray[ix].t2_count > 0) {
1669           print_blobType_single(ast, StatArray[ix].type);
1670         } else {
1671           print_count_single(ast, StatArray[ix].t2_count);
1672         }
1673       }
1674       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
1675     } else {
1676       ast->print("No Tier2 nMethods found in CodeHeap.");
1677       STRINGSTREAM_FLUSH_LOCKED("\n\n\n")
1678     }
1679   }
1680 
1681   {
1682     if (nBlocks_alive > 0) {
1683       printBox(ast, '-', "not_used/not_entrant/not_installed nMethod count only, 0x1..0xf. '*' indicates >= 16 blocks, ' ' indicates empty", NULL);
1684       STRINGSTREAM_FLUSH_LOCKED("")
1685 
1686       granules_per_line = 128;
1687       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1688         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1689         if (segment_granules && StatArray[ix].tx_count > 0) {
1690           print_blobType_single(ast, StatArray[ix].type);
1691         } else {
1692           print_count_single(ast, StatArray[ix].tx_count);
1693         }
1694       }
1695       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
1696     } else {
1697       ast->print("No not_used/not_entrant nMethods found in CodeHeap.");
1698       STRINGSTREAM_FLUSH_LOCKED("\n\n\n")
1699     }
1700   }
1701 
1702   {
1703     if (nBlocks_stub > 0) {
1704       printBox(ast, '-', "Stub & Blob count only, 0x1..0xf. '*' indicates >= 16 blocks, ' ' indicates empty", NULL);
1705       STRINGSTREAM_FLUSH_LOCKED("")
1706 
1707       granules_per_line = 128;
1708       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1709         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1710         if (segment_granules && StatArray[ix].stub_count > 0) {
1711           print_blobType_single(ast, StatArray[ix].type);
1712         } else {
1713           print_count_single(ast, StatArray[ix].stub_count);
1714         }
1715       }
1716       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
1717     } else {
1718       ast->print("No Stubs and Blobs found in CodeHeap.");
1719       STRINGSTREAM_FLUSH_LOCKED("\n\n\n")
1720     }
1721   }
1722 
1723   {
1724     if (nBlocks_dead > 0) {
1725       printBox(ast, '-', "Dead nMethod count only, 0x1..0xf. '*' indicates >= 16 blocks, ' ' indicates empty", NULL);
1726       STRINGSTREAM_FLUSH_LOCKED("")
1727 
1728       granules_per_line = 128;
1729       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1730         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1731         if (segment_granules && StatArray[ix].dead_count > 0) {
1732           print_blobType_single(ast, StatArray[ix].type);
1733         } else {
1734           print_count_single(ast, StatArray[ix].dead_count);
1735         }
1736       }
1737       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
1738     } else {
1739       ast->print("No dead nMethods found in CodeHeap.");
1740       STRINGSTREAM_FLUSH_LOCKED("\n\n\n")
1741     }
1742   }
1743 
1744   {
1745     if (!segment_granules) { // Prevent totally redundant printouts
1746       printBox(ast, '-', "Count by tier (combined, no dead blocks): <#t1>:<#t2>:<#s>, 0x0..0xf. '*' indicates >= 16 blocks", NULL);
1747       STRINGSTREAM_FLUSH_LOCKED("")
1748 
1749       granules_per_line = 24;
1750       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1751         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1752 
1753         print_count_single(ast, StatArray[ix].t1_count);
1754         ast->print(":");
1755         print_count_single(ast, StatArray[ix].t2_count);
1756         ast->print(":");
1757         if (segment_granules && StatArray[ix].stub_count > 0) {
1758           print_blobType_single(ast, StatArray[ix].type);
1759         } else {
1760           print_count_single(ast, StatArray[ix].stub_count);
1761         }
1762         ast->print(" ");
1763       }
1764       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
1765     }
1766   }
1767 }
1768 
1769 
1770 void CodeHeapState::print_space(outputStream* out, CodeHeap* heap) {
1771   if (!initialization_complete) {
1772     return;
1773   }
1774 
1775   const char* heapName   = get_heapName(heap);
1776   get_HeapStatGlobals(out, heapName);
1777 
1778   if ((StatArray == NULL) || (alloc_granules == 0)) {
1779     return;
1780   }
1781   STRINGSTREAM_DECL(ast, out)
1782 
1783   unsigned int granules_per_line = 32;
1784   char*        low_bound         = heap->low_boundary();
1785 
1786   {
1787     printBox(ast, '=', "S P A C E   U S A G E  &  F R A G M E N T A T I O N   for ", heapName);
1788     ast->print_cr("  The heap space covered by one granule is occupied to a various extend.\n"
1789                   "  The granule occupancy is displayed by one decimal digit per granule.\n");
1790     if (segment_granules) {
1791       ast->print_cr("  You have selected granule size to be as small as segment size.\n"
1792                     "  As a result, each granule contains exactly one block (or a part of one block)\n"
1793                     "  or is displayed as empty (' ') if it's BlobType does not match the selection.\n"
1794                     "  Occupied granules show their BlobType character, see legend.\n");
1795       print_blobType_legend(ast);
1796     } else {
1797       ast->print_cr("  These digits represent a fill percentage range (see legend).\n");
1798       print_space_legend(ast);
1799     }
1800     STRINGSTREAM_FLUSH_LOCKED("")
1801   }
1802 
1803   {
1804     if (segment_granules) {
1805       printBox(ast, '-', "Total (all types) space consumption for granule size == segment size", NULL);
1806       STRINGSTREAM_FLUSH_LOCKED("")
1807 
1808       granules_per_line = 128;
1809       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1810         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1811         print_blobType_single(ast, StatArray[ix].type);
1812       }
1813     } else {
1814       printBox(ast, '-', "Total (all types) space consumption. ' ' indicates empty, '*' indicates full.", NULL);
1815       STRINGSTREAM_FLUSH_LOCKED("")
1816 
1817       granules_per_line = 128;
1818       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1819         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1820         unsigned int space    = StatArray[ix].t1_space   + StatArray[ix].t2_space  + StatArray[ix].tx_space
1821                               + StatArray[ix].stub_space + StatArray[ix].dead_space;
1822         print_space_single(ast, space);
1823       }
1824     }
1825     STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
1826   }
1827 
1828   {
1829     if (nBlocks_t1 > 0) {
1830       printBox(ast, '-', "Tier1 space consumption. ' ' indicates empty, '*' indicates full", NULL);
1831       STRINGSTREAM_FLUSH_LOCKED("")
1832 
1833       granules_per_line = 128;
1834       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1835         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1836         if (segment_granules && StatArray[ix].t1_space > 0) {
1837           print_blobType_single(ast, StatArray[ix].type);
1838         } else {
1839           print_space_single(ast, StatArray[ix].t1_space);
1840         }
1841       }
1842       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
1843     } else {
1844       ast->print("No Tier1 nMethods found in CodeHeap.");
1845       STRINGSTREAM_FLUSH_LOCKED("\n\n\n")
1846     }
1847   }
1848 
1849   {
1850     if (nBlocks_t2 > 0) {
1851       printBox(ast, '-', "Tier2 space consumption. ' ' indicates empty, '*' indicates full", NULL);
1852       STRINGSTREAM_FLUSH_LOCKED("")
1853 
1854       granules_per_line = 128;
1855       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1856         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1857         if (segment_granules && StatArray[ix].t2_space > 0) {
1858           print_blobType_single(ast, StatArray[ix].type);
1859         } else {
1860           print_space_single(ast, StatArray[ix].t2_space);
1861         }
1862       }
1863       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
1864     } else {
1865       ast->print("No Tier2 nMethods found in CodeHeap.");
1866       STRINGSTREAM_FLUSH_LOCKED("\n\n\n")
1867     }
1868   }
1869 
1870   {
1871     if (nBlocks_alive > 0) {
1872       printBox(ast, '-', "not_used/not_entrant/not_installed space consumption. ' ' indicates empty, '*' indicates full", NULL);
1873 
1874       granules_per_line = 128;
1875       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1876         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1877         if (segment_granules && StatArray[ix].tx_space > 0) {
1878           print_blobType_single(ast, StatArray[ix].type);
1879         } else {
1880           print_space_single(ast, StatArray[ix].tx_space);
1881         }
1882       }
1883       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
1884     } else {
1885       ast->print("No Tier2 nMethods found in CodeHeap.");
1886       STRINGSTREAM_FLUSH_LOCKED("\n\n\n")
1887     }
1888   }
1889 
1890   {
1891     if (nBlocks_stub > 0) {
1892       printBox(ast, '-', "Stub and Blob space consumption. ' ' indicates empty, '*' indicates full", NULL);
1893       STRINGSTREAM_FLUSH_LOCKED("")
1894 
1895       granules_per_line = 128;
1896       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1897         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1898         if (segment_granules && StatArray[ix].stub_space > 0) {
1899           print_blobType_single(ast, StatArray[ix].type);
1900         } else {
1901           print_space_single(ast, StatArray[ix].stub_space);
1902         }
1903       }
1904       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
1905     } else {
1906       ast->print("No Stubs and Blobs found in CodeHeap.");
1907       STRINGSTREAM_FLUSH_LOCKED("\n\n\n")
1908     }
1909   }
1910 
1911   {
1912     if (nBlocks_dead > 0) {
1913       printBox(ast, '-', "Dead space consumption. ' ' indicates empty, '*' indicates full", NULL);
1914       STRINGSTREAM_FLUSH_LOCKED("")
1915 
1916       granules_per_line = 128;
1917       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1918         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1919         print_space_single(ast, StatArray[ix].dead_space);
1920       }
1921       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
1922     } else {
1923       ast->print("No dead nMethods found in CodeHeap.");
1924       STRINGSTREAM_FLUSH_LOCKED("\n\n\n")
1925     }
1926   }
1927 
1928   {
1929     if (!segment_granules) { // Prevent totally redundant printouts
1930       printBox(ast, '-', "Space consumption by tier (combined): <t1%>:<t2%>:<s%>. ' ' indicates empty, '*' indicates full", NULL);
1931       STRINGSTREAM_FLUSH_LOCKED("")
1932 
1933       granules_per_line = 24;
1934       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1935         print_line_delim(out, ast, low_bound, ix, granules_per_line);
1936 
1937         if (segment_granules && StatArray[ix].t1_space > 0) {
1938           print_blobType_single(ast, StatArray[ix].type);
1939         } else {
1940           print_space_single(ast, StatArray[ix].t1_space);
1941         }
1942         ast->print(":");
1943         if (segment_granules && StatArray[ix].t2_space > 0) {
1944           print_blobType_single(ast, StatArray[ix].type);
1945         } else {
1946           print_space_single(ast, StatArray[ix].t2_space);
1947         }
1948         ast->print(":");
1949         if (segment_granules && StatArray[ix].stub_space > 0) {
1950           print_blobType_single(ast, StatArray[ix].type);
1951         } else {
1952           print_space_single(ast, StatArray[ix].stub_space);
1953         }
1954         ast->print(" ");
1955       }
1956       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
1957     }
1958   }
1959 }
1960 
1961 void CodeHeapState::print_age(outputStream* out, CodeHeap* heap) {
1962   if (!initialization_complete) {
1963     return;
1964   }
1965 
1966   const char* heapName   = get_heapName(heap);
1967   get_HeapStatGlobals(out, heapName);
1968 
1969   if ((StatArray == NULL) || (alloc_granules == 0)) {
1970     return;
1971   }
1972   STRINGSTREAM_DECL(ast, out)
1973 
1974   unsigned int granules_per_line = 32;
1975   char*        low_bound         = heap->low_boundary();
1976 
1977   {
1978     printBox(ast, '=', "M E T H O D   A G E   by CompileID for ", heapName);
1979     ast->print_cr("  The age of a compiled method in the CodeHeap is not available as a\n"
1980                   "  time stamp. Instead, a relative age is deducted from the method's compilation ID.\n"
1981                   "  Age information is available for tier1 and tier2 methods only. There is no\n"
1982                   "  age information for stubs and blobs, because they have no compilation ID assigned.\n"
1983                   "  Information for the youngest method (highest ID) in the granule is printed.\n"
1984                   "  Refer to the legend to learn how method age is mapped to the displayed digit.");
1985     print_age_legend(ast);
1986     STRINGSTREAM_FLUSH_LOCKED("")
1987   }
1988 
1989   {
1990     printBox(ast, '-', "Age distribution. '0' indicates youngest 1/256, '8': oldest half, ' ': no age information", NULL);
1991     STRINGSTREAM_FLUSH_LOCKED("")
1992 
1993     granules_per_line = 128;
1994     for (unsigned int ix = 0; ix < alloc_granules; ix++) {
1995       print_line_delim(out, ast, low_bound, ix, granules_per_line);
1996       unsigned int age1      = StatArray[ix].t1_age;
1997       unsigned int age2      = StatArray[ix].t2_age;
1998       unsigned int agex      = StatArray[ix].tx_age;
1999       unsigned int age       = age1 > age2 ? age1 : age2;
2000       age       = age > agex ? age : agex;
2001       print_age_single(ast, age);
2002     }
2003     STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
2004   }
2005 
2006   {
2007     if (nBlocks_t1 > 0) {
2008       printBox(ast, '-', "Tier1 age distribution. '0' indicates youngest 1/256, '8': oldest half, ' ': no age information", NULL);
2009       STRINGSTREAM_FLUSH_LOCKED("")
2010 
2011       granules_per_line = 128;
2012       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
2013         print_line_delim(out, ast, low_bound, ix, granules_per_line);
2014         print_age_single(ast, StatArray[ix].t1_age);
2015       }
2016       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
2017     } else {
2018       ast->print("No Tier1 nMethods found in CodeHeap.");
2019       STRINGSTREAM_FLUSH_LOCKED("\n\n\n")
2020     }
2021   }
2022 
2023   {
2024     if (nBlocks_t2 > 0) {
2025       printBox(ast, '-', "Tier2 age distribution. '0' indicates youngest 1/256, '8': oldest half, ' ': no age information", NULL);
2026       STRINGSTREAM_FLUSH_LOCKED("")
2027 
2028       granules_per_line = 128;
2029       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
2030         print_line_delim(out, ast, low_bound, ix, granules_per_line);
2031         print_age_single(ast, StatArray[ix].t2_age);
2032       }
2033       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
2034     } else {
2035       ast->print("No Tier2 nMethods found in CodeHeap.");
2036       STRINGSTREAM_FLUSH_LOCKED("\n\n\n")
2037     }
2038   }
2039 
2040   {
2041     if (nBlocks_alive > 0) {
2042       printBox(ast, '-', "not_used/not_entrant/not_installed age distribution. '0' indicates youngest 1/256, '8': oldest half, ' ': no age information", NULL);
2043       STRINGSTREAM_FLUSH_LOCKED("")
2044 
2045       granules_per_line = 128;
2046       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
2047         print_line_delim(out, ast, low_bound, ix, granules_per_line);
2048         print_age_single(ast, StatArray[ix].tx_age);
2049       }
2050       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
2051     } else {
2052       ast->print("No Tier2 nMethods found in CodeHeap.");
2053       STRINGSTREAM_FLUSH_LOCKED("\n\n\n")
2054     }
2055   }
2056 
2057   {
2058     if (!segment_granules) { // Prevent totally redundant printouts
2059       printBox(ast, '-', "age distribution by tier <a1>:<a2>. '0' indicates youngest 1/256, '8': oldest half, ' ': no age information", NULL);
2060       STRINGSTREAM_FLUSH_LOCKED("")
2061 
2062       granules_per_line = 32;
2063       for (unsigned int ix = 0; ix < alloc_granules; ix++) {
2064         print_line_delim(out, ast, low_bound, ix, granules_per_line);
2065         print_age_single(ast, StatArray[ix].t1_age);
2066         ast->print(":");
2067         print_age_single(ast, StatArray[ix].t2_age);
2068         ast->print(" ");
2069       }
2070       STRINGSTREAM_FLUSH_LOCKED("|\n\n\n")
2071     }
2072   }
2073 }
2074 
2075 
2076 void CodeHeapState::print_names(outputStream* out, CodeHeap* heap) {
2077   if (!initialization_complete) {
2078     return;
2079   }
2080 
2081   const char* heapName   = get_heapName(heap);
2082   get_HeapStatGlobals(out, heapName);
2083 
2084   if ((StatArray == NULL) || (alloc_granules == 0)) {
2085     return;
2086   }
2087   STRINGSTREAM_DECL(ast, out)
2088 
2089   unsigned int granules_per_line  = 128;
2090   char*        low_bound          = heap->low_boundary();
2091   CodeBlob*    last_blob          = NULL;
2092   bool         name_in_addr_range = true;
2093 
2094   //---<  print at least 128K per block (i.e. between headers)  >---
2095   if (granules_per_line*granule_size < 128*K) {
2096     granules_per_line = (unsigned int)((128*K)/granule_size);
2097   }
2098 
2099   printBox(ast, '=', "M E T H O D   N A M E S   for ", heapName);
2100   ast->print_cr("  Method names are dynamically retrieved from the code cache at print time.\n"
2101                 "  Due to the living nature of the code heap and because the CodeCache_lock\n"
2102                 "  is not continuously held, the displayed name might be wrong or no name\n"
2103                 "  might be found at all. The likelihood for that to happen increases\n"
2104                 "  over time passed between aggregtion and print steps.\n");
2105   STRINGSTREAM_FLUSH_LOCKED("")
2106 
2107   for (unsigned int ix = 0; ix < alloc_granules; ix++) {
2108     //---<  print a new blob on a new line  >---
2109     if (ix%granules_per_line == 0) {
2110       if (!name_in_addr_range) {
2111         ast->print_cr("No methods, blobs, or stubs found in this address range");
2112       }
2113       name_in_addr_range = false;
2114 
2115       size_t end_ix = (ix+granules_per_line <= alloc_granules) ? ix+granules_per_line : alloc_granules;
2116       ast->cr();
2117       ast->print_cr("--------------------------------------------------------------------");
2118       ast->print_cr("Address range [" INTPTR_FORMAT "," INTPTR_FORMAT "), " SIZE_FORMAT "k", p2i(low_bound+ix*granule_size), p2i(low_bound + end_ix*granule_size), (end_ix - ix)*granule_size/(size_t)K);
2119       ast->print_cr("--------------------------------------------------------------------");
2120       STRINGSTREAM_FLUSH_LOCKED("")
2121     }
2122     // Only check granule if it contains at least one blob.
2123     unsigned int nBlobs  = StatArray[ix].t1_count   + StatArray[ix].t2_count + StatArray[ix].tx_count +
2124                            StatArray[ix].stub_count + StatArray[ix].dead_count;
2125     if (nBlobs > 0 ) {
2126     for (unsigned int is = 0; is < granule_size; is+=(unsigned int)seg_size) {
2127       // heap->find_start() is safe. Only working with _segmap. Returns NULL or void*. Returned CodeBlob may be uninitialized.
2128       CodeBlob* this_blob = (CodeBlob *)(heap->find_start(low_bound+ix*granule_size+is));
2129       bool blob_initialized = (this_blob != NULL) && (this_blob->header_size() >= 0) && (this_blob->relocation_size() >= 0) &&
2130                               ((address)this_blob + this_blob->header_size() == (address)(this_blob->relocation_begin())) &&
2131                               ((address)this_blob + CodeBlob::align_code_offset(this_blob->header_size() + this_blob->relocation_size()) == (address)(this_blob->content_begin())) &&
2132                               os::is_readable_pointer((address)(this_blob->relocation_begin())) &&
2133                               os::is_readable_pointer(this_blob->content_begin());
2134       // blob could have been flushed, freed, and merged.
2135       // this_blob < last_blob is an indicator for that.
2136       if (blob_initialized && (this_blob > last_blob)) {
2137         last_blob          = this_blob;
2138 
2139         //---<  get type and name  >---
2140         blobType       cbType = noType;
2141         if (segment_granules) {
2142           cbType = (blobType)StatArray[ix].type;
2143         } else {
2144           cbType = get_cbType(this_blob);
2145         }
2146         // this_blob->name() could return NULL if no name was given to CTOR. Inlined, maybe invisible on stack
2147         const char* blob_name = this_blob->name();
2148         if ((blob_name == NULL) || !os::is_readable_pointer(blob_name)) {
2149           blob_name = "<unavailable>";
2150         }
2151 
2152         //---<  print table header for new print range  >---
2153         if (!name_in_addr_range) {
2154           name_in_addr_range = true;
2155           ast->fill_to(51);
2156           ast->print("%9s", "compiler");
2157           ast->fill_to(61);
2158           ast->print_cr("%6s", "method");
2159           ast->print_cr("%18s %13s %17s %9s  %5s %18s  %s", "Addr(module)      ", "offset", "size", " type lvl", " temp", "blobType          ", "Name");
2160           STRINGSTREAM_FLUSH_LOCKED("")
2161         }
2162 
2163         //---<  print line prefix (address and offset from CodeHeap start)  >---
2164         ast->print(INTPTR_FORMAT, p2i(this_blob));
2165         ast->fill_to(19);
2166         ast->print("(+" PTR32_FORMAT ")", (unsigned int)((char*)this_blob-low_bound));
2167         ast->fill_to(33);
2168 
2169         // this_blob->as_nmethod_or_null() is safe. Inlined, maybe invisible on stack.
2170         nmethod*    nm     = this_blob->as_nmethod_or_null();
2171         if (CompiledMethod::nmethod_access_is_safe(nm)) {
2172           Method* method = nm->method();
2173           ResourceMark rm;
2174           //---<  collect all data to locals as quickly as possible  >---
2175           unsigned int total_size = nm->total_size();
2176           int          hotness    = nm->hotness_counter();
2177           bool         get_name   = (cbType == nMethod_inuse) || (cbType == nMethod_notused);
2178           //---<  nMethod size in hex  >---
2179           ast->print(PTR32_FORMAT, total_size);
2180           ast->print("(" SIZE_FORMAT_W(4) "K)", total_size/K);
2181           //---<  compiler information  >---
2182           ast->fill_to(51);
2183           ast->print("%5s %3d", compTypeName[StatArray[ix].compiler], StatArray[ix].level);
2184           //---<  method temperature  >---
2185           ast->fill_to(62);
2186           ast->print("%5d", hotness);
2187           //---<  name and signature  >---
2188           ast->fill_to(62+6);
2189           ast->print("%s", blobTypeName[cbType]);
2190           ast->fill_to(82+6);
2191           if (cbType == nMethod_dead) {
2192             ast->print("%14s", " zombie method");
2193           }
2194 
2195           if (get_name) {
2196             Symbol* methName  = method->name();
2197             const char*   methNameS = (methName == NULL) ? NULL : methName->as_C_string();
2198             methNameS = (methNameS == NULL) ? "<method name unavailable>" : methNameS;
2199             Symbol* methSig   = method->signature();
2200             const char*   methSigS  = (methSig  == NULL) ? NULL : methSig->as_C_string();
2201             methSigS  = (methSigS  == NULL) ? "<method signature unavailable>" : methSigS;
2202             ast->print("%s", methNameS);
2203             ast->print("%s", methSigS);
2204           } else {
2205             ast->print("%s", blob_name);
2206           }
2207         } else {
2208           ast->fill_to(62+6);
2209           ast->print("%s", blobTypeName[cbType]);
2210           ast->fill_to(82+6);
2211           ast->print("%s", blob_name);
2212         }
2213         STRINGSTREAM_FLUSH_LOCKED("\n")
2214       } else if (!blob_initialized && (this_blob != last_blob) && (this_blob != NULL)) {
2215         last_blob          = this_blob;
2216         STRINGSTREAM_FLUSH_LOCKED("\n")
2217       }
2218     }
2219     } // nBlobs > 0
2220   }
2221   STRINGSTREAM_FLUSH_LOCKED("\n\n")
2222 }
2223 
2224 
2225 void CodeHeapState::printBox(outputStream* ast, const char border, const char* text1, const char* text2) {
2226   unsigned int lineLen = 1 + 2 + 2 + 1;
2227   char edge, frame;
2228 
2229   if (text1 != NULL) {
2230     lineLen += (unsigned int)strlen(text1); // text1 is much shorter than MAX_INT chars.
2231   }
2232   if (text2 != NULL) {
2233     lineLen += (unsigned int)strlen(text2); // text2 is much shorter than MAX_INT chars.
2234   }
2235   if (border == '-') {
2236     edge  = '+';
2237     frame = '|';
2238   } else {
2239     edge  = border;
2240     frame = border;
2241   }
2242 
2243   ast->print("%c", edge);
2244   for (unsigned int i = 0; i < lineLen-2; i++) {
2245     ast->print("%c", border);
2246   }
2247   ast->print_cr("%c", edge);
2248 
2249   ast->print("%c  ", frame);
2250   if (text1 != NULL) {
2251     ast->print("%s", text1);
2252   }
2253   if (text2 != NULL) {
2254     ast->print("%s", text2);
2255   }
2256   ast->print_cr("  %c", frame);
2257 
2258   ast->print("%c", edge);
2259   for (unsigned int i = 0; i < lineLen-2; i++) {
2260     ast->print("%c", border);
2261   }
2262   ast->print_cr("%c", edge);
2263 }
2264 
2265 void CodeHeapState::print_blobType_legend(outputStream* out) {
2266   out->cr();
2267   printBox(out, '-', "Block types used in the following CodeHeap dump", NULL);
2268   for (int type = noType; type < lastType; type += 1) {
2269     out->print_cr("  %c - %s", blobTypeChar[type], blobTypeName[type]);
2270   }
2271   out->print_cr("  -----------------------------------------------------");
2272   out->cr();
2273 }
2274 
2275 void CodeHeapState::print_space_legend(outputStream* out) {
2276   unsigned int indicator = 0;
2277   unsigned int age_range = 256;
2278   unsigned int range_beg = latest_compilation_id;
2279   out->cr();
2280   printBox(out, '-', "Space ranges, based on granule occupancy", NULL);
2281   out->print_cr("    -   0%% == occupancy");
2282   for (int i=0; i<=9; i++) {
2283     out->print_cr("  %d - %3d%% < occupancy < %3d%%", i, 10*i, 10*(i+1));
2284   }
2285   out->print_cr("  * - 100%% == occupancy");
2286   out->print_cr("  ----------------------------------------------");
2287   out->cr();
2288 }
2289 
2290 void CodeHeapState::print_age_legend(outputStream* out) {
2291   unsigned int indicator = 0;
2292   unsigned int age_range = 256;
2293   unsigned int range_beg = latest_compilation_id;
2294   out->cr();
2295   printBox(out, '-', "Age ranges, based on compilation id", NULL);
2296   while (age_range > 0) {
2297     out->print_cr("  %d - %6d to %6d", indicator, range_beg, latest_compilation_id - latest_compilation_id/age_range);
2298     range_beg = latest_compilation_id - latest_compilation_id/age_range;
2299     age_range /= 2;
2300     indicator += 1;
2301   }
2302   out->print_cr("  -----------------------------------------");
2303   out->cr();
2304 }
2305 
2306 void CodeHeapState::print_blobType_single(outputStream* out, u2 /* blobType */ type) {
2307   out->print("%c", blobTypeChar[type]);
2308 }
2309 
2310 void CodeHeapState::print_count_single(outputStream* out, unsigned short count) {
2311   if (count >= 16)    out->print("*");
2312   else if (count > 0) out->print("%1.1x", count);
2313   else                out->print(" ");
2314 }
2315 
2316 void CodeHeapState::print_space_single(outputStream* out, unsigned short space) {
2317   size_t  space_in_bytes = ((unsigned int)space)<<log2_seg_size;
2318   char    fraction       = (space == 0) ? ' ' : (space_in_bytes >= granule_size-1) ? '*' : char('0'+10*space_in_bytes/granule_size);
2319   out->print("%c", fraction);
2320 }
2321 
2322 void CodeHeapState::print_age_single(outputStream* out, unsigned int age) {
2323   unsigned int indicator = 0;
2324   unsigned int age_range = 256;
2325   if (age > 0) {
2326     while ((age_range > 0) && (latest_compilation_id-age > latest_compilation_id/age_range)) {
2327       age_range /= 2;
2328       indicator += 1;
2329     }
2330     out->print("%c", char('0'+indicator));
2331   } else {
2332     out->print(" ");
2333   }
2334 }
2335 
2336 void CodeHeapState::print_line_delim(outputStream* out, outputStream* ast, char* low_bound, unsigned int ix, unsigned int gpl) {
2337   if (ix % gpl == 0) {
2338     if (ix > 0) {
2339       ast->print("|");
2340     }
2341     ast->cr();
2342     assert(out == ast, "must use the same stream!");
2343 
2344     ast->print(INTPTR_FORMAT, p2i(low_bound + ix*granule_size));
2345     ast->fill_to(19);
2346     ast->print("(+" PTR32_FORMAT "): |", (unsigned int)(ix*granule_size));
2347   }
2348 }
2349 
2350 void CodeHeapState::print_line_delim(outputStream* out, bufferedStream* ast, char* low_bound, unsigned int ix, unsigned int gpl) {
2351   assert(out != ast, "must not use the same stream!");
2352   if (ix % gpl == 0) {
2353     if (ix > 0) {
2354       ast->print("|");
2355     }
2356     ast->cr();
2357 
2358     { // can't use STRINGSTREAM_FLUSH_LOCKED("") here.
2359       ttyLocker ttyl;
2360       out->print("%s", ast->as_string());
2361       ast->reset();
2362     }
2363 
2364     ast->print(INTPTR_FORMAT, p2i(low_bound + ix*granule_size));
2365     ast->fill_to(19);
2366     ast->print("(+" PTR32_FORMAT "): |", (unsigned int)(ix*granule_size));
2367   }
2368 }
2369 
2370 CodeHeapState::blobType CodeHeapState::get_cbType(CodeBlob* cb) {
2371   if ((cb != NULL) && os::is_readable_pointer(cb)) {
2372     if (cb->is_runtime_stub())                return runtimeStub;
2373     if (cb->is_deoptimization_stub())         return deoptimizationStub;
2374     if (cb->is_uncommon_trap_stub())          return uncommonTrapStub;
2375     if (cb->is_exception_stub())              return exceptionStub;
2376     if (cb->is_safepoint_stub())              return safepointStub;
2377     if (cb->is_adapter_blob())                return adapterBlob;
2378     if (cb->is_method_handles_adapter_blob()) return mh_adapterBlob;
2379     if (cb->is_buffer_blob())                 return bufferBlob;
2380 
2381     nmethod*  nm = cb->as_nmethod_or_null();
2382     if (nm != NULL) { // no is_readable check required, nm = (nmethod*)cb.
2383       if (nm->is_not_installed()) return nMethod_inconstruction;
2384       if (nm->is_zombie())        return nMethod_dead;
2385       if (nm->is_unloaded())      return nMethod_unloaded;
2386       if (nm->is_in_use())        return nMethod_inuse;
2387       if (nm->is_alive() && !(nm->is_not_entrant()))   return nMethod_notused;
2388       if (nm->is_alive())         return nMethod_alive;
2389       return nMethod_dead;
2390     }
2391   }
2392   return noType;
2393 }