1 /*
   2  * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "code/codeBlob.hpp"
  28 #include "code/codeCache.hpp"
  29 #include "code/icBuffer.hpp"
  30 #include "code/relocInfo.hpp"
  31 #include "code/vtableStubs.hpp"
  32 #include "compiler/disassembler.hpp"
  33 #include "interpreter/bytecode.hpp"
  34 #include "interpreter/interpreter.hpp"
  35 #include "memory/allocation.inline.hpp"
  36 #include "memory/heap.hpp"
  37 #include "memory/resourceArea.hpp"
  38 #include "oops/oop.inline.hpp"
  39 #include "prims/forte.hpp"
  40 #include "runtime/handles.inline.hpp"
  41 #include "runtime/interfaceSupport.inline.hpp"
  42 #include "runtime/mutexLocker.hpp"
  43 #include "runtime/safepoint.hpp"
  44 #include "runtime/sharedRuntime.hpp"
  45 #include "runtime/vframe.hpp"
  46 #include "services/memoryService.hpp"
  47 #include "utilities/align.hpp"
  48 #ifdef COMPILER1
  49 #include "c1/c1_Runtime1.hpp"
  50 #endif
  51 
  52 const char* CodeBlob::compiler_name() const {
  53   return compilertype2name(_type);
  54 }
  55 
  56 unsigned int CodeBlob::align_code_offset(int offset) {
  57   // align the size to CodeEntryAlignment
  58   return
  59     ((offset + (int)CodeHeap::header_size() + (CodeEntryAlignment-1)) & ~(CodeEntryAlignment-1))
  60     - (int)CodeHeap::header_size();
  61 }
  62 
  63 
  64 // This must be consistent with the CodeBlob constructor's layout actions.
  65 unsigned int CodeBlob::allocation_size(CodeBuffer* cb, int header_size) {
  66   unsigned int size = header_size;
  67   size += align_up(cb->total_relocation_size(), oopSize);
  68   // align the size to CodeEntryAlignment
  69   size = align_code_offset(size);
  70   size += align_up(cb->total_content_size(), oopSize);
  71   size += align_up(cb->total_oop_size(), oopSize);
  72   size += align_up(cb->total_metadata_size(), oopSize);
  73   return size;
  74 }
  75 
  76 CodeBlob::CodeBlob(const char* name, CompilerType type, const CodeBlobLayout& layout, int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments, bool compiled) :
  77   _type(type),
  78   _size(layout.size()),
  79   _header_size(layout.header_size()),
  80   _frame_complete_offset(frame_complete_offset),
  81   _data_offset(layout.data_offset()),
  82   _frame_size(frame_size),
  83   _code_begin(layout.code_begin()),
  84   _code_end(layout.code_end()),
  85   _content_begin(layout.content_begin()),
  86   _data_end(layout.data_end()),
  87   _relocation_begin(layout.relocation_begin()),
  88   _relocation_end(layout.relocation_end()),
  89   _is_compiled(compiled),
  90   _oop_maps(oop_maps),
  91   _caller_must_gc_arguments(caller_must_gc_arguments),
  92   _strings(CodeStrings()),
  93   _name(name)
  94 {
  95   assert(is_aligned(layout.size(),            oopSize), "unaligned size");
  96   assert(is_aligned(layout.header_size(),     oopSize), "unaligned size");
  97   assert(is_aligned(layout.relocation_size(), oopSize), "unaligned size");
  98   assert(layout.code_end() == layout.content_end(), "must be the same - see code_end()");
  99 #ifdef COMPILER1
 100   // probably wrong for tiered
 101   assert(_frame_size >= -1, "must use frame size or -1 for runtime stubs");
 102 #endif // COMPILER1
 103 }
 104 
 105 CodeBlob::CodeBlob(const char* name, CompilerType type, const CodeBlobLayout& layout, CodeBuffer* cb, int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments, bool compiled) :
 106   _type(type),
 107   _size(layout.size()),
 108   _header_size(layout.header_size()),
 109   _frame_complete_offset(frame_complete_offset),
 110   _data_offset(layout.data_offset()),
 111   _frame_size(frame_size),
 112   _code_begin(layout.code_begin()),
 113   _code_end(layout.code_end()),
 114   _content_begin(layout.content_begin()),
 115   _data_end(layout.data_end()),
 116   _relocation_begin(layout.relocation_begin()),
 117   _relocation_end(layout.relocation_end()),
 118   _is_compiled(compiled),
 119   _caller_must_gc_arguments(caller_must_gc_arguments),
 120   _strings(CodeStrings()),
 121   _name(name)
 122 {
 123   assert(is_aligned(_size,        oopSize), "unaligned size");
 124   assert(is_aligned(_header_size, oopSize), "unaligned size");
 125   assert(_data_offset <= _size, "codeBlob is too small");
 126   assert(layout.code_end() == layout.content_end(), "must be the same - see code_end()");
 127 
 128   set_oop_maps(oop_maps);
 129 #ifdef COMPILER1
 130   // probably wrong for tiered
 131   assert(_frame_size >= -1, "must use frame size or -1 for runtime stubs");
 132 #endif // COMPILER1
 133 }
 134 
 135 
 136 // Creates a simple CodeBlob. Sets up the size of the different regions.
 137 RuntimeBlob::RuntimeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size)
 138   : CodeBlob(name, compiler_none, CodeBlobLayout((address) this, size, header_size, locs_size, size), frame_complete, 0, NULL, false /* caller_must_gc_arguments */)
 139 {
 140   assert(is_aligned(locs_size, oopSize), "unaligned size");
 141 }
 142 
 143 
 144 // Creates a RuntimeBlob from a CodeBuffer
 145 // and copy code and relocation info.
 146 RuntimeBlob::RuntimeBlob(
 147   const char* name,
 148   CodeBuffer* cb,
 149   int         header_size,
 150   int         size,
 151   int         frame_complete,
 152   int         frame_size,
 153   OopMapSet*  oop_maps,
 154   bool        caller_must_gc_arguments
 155 ) : CodeBlob(name, compiler_none, CodeBlobLayout((address) this, size, header_size, cb), cb, frame_complete, frame_size, oop_maps, caller_must_gc_arguments) {
 156   cb->copy_code_and_locs_to(this);
 157 }
 158 
 159 void CodeBlob::flush() {
 160   if (_oop_maps) {
 161     FREE_C_HEAP_ARRAY(unsigned char, _oop_maps);
 162     _oop_maps = NULL;
 163   }
 164   _strings.free();
 165 }
 166 
 167 void CodeBlob::set_oop_maps(OopMapSet* p) {
 168   // Danger Will Robinson! This method allocates a big
 169   // chunk of memory, its your job to free it.
 170   if (p != NULL) {
 171     _oop_maps = ImmutableOopMapSet::build_from(p);
 172   } else {
 173     _oop_maps = NULL;
 174   }
 175 }
 176 
 177 
 178 void RuntimeBlob::trace_new_stub(RuntimeBlob* stub, const char* name1, const char* name2) {
 179   // Do not hold the CodeCache lock during name formatting.
 180   assert(!CodeCache_lock->owned_by_self(), "release CodeCache before registering the stub");
 181 
 182   if (stub != NULL) {
 183     char stub_id[256];
 184     assert(strlen(name1) + strlen(name2) < sizeof(stub_id), "");
 185     jio_snprintf(stub_id, sizeof(stub_id), "%s%s", name1, name2);
 186     if (PrintStubCode) {
 187       ttyLocker ttyl;
 188       tty->print_cr("- - - [BEGIN] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
 189       tty->print_cr("Decoding %s " INTPTR_FORMAT, stub_id, (intptr_t) stub);
 190       Disassembler::decode(stub->code_begin(), stub->code_end(), tty);
 191       if ((stub->oop_maps() != NULL) && AbstractDisassembler::show_structs()) {
 192         tty->print_cr("- - - [OOP MAPS]- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
 193         stub->oop_maps()->print();
 194       }
 195       tty->print_cr("- - - [END] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
 196       tty->cr();
 197     }
 198     Forte::register_stub(stub_id, stub->code_begin(), stub->code_end());
 199 
 200     if (JvmtiExport::should_post_dynamic_code_generated()) {
 201       const char* stub_name = name2;
 202       if (name2[0] == '\0')  stub_name = name1;
 203       JvmtiExport::post_dynamic_code_generated(stub_name, stub->code_begin(), stub->code_end());
 204     }
 205   }
 206 
 207   // Track memory usage statistic after releasing CodeCache_lock
 208   MemoryService::track_code_cache_memory_usage();
 209 }
 210 
 211 const ImmutableOopMap* CodeBlob::oop_map_for_return_address(address return_address) const {
 212   assert(_oop_maps != NULL, "nope");
 213   return _oop_maps->find_map_at_offset((intptr_t) return_address - (intptr_t) code_begin());
 214 }
 215 
 216 void CodeBlob::print_code() {
 217   ResourceMark m;
 218   Disassembler::decode(this, tty);
 219 }
 220 
 221 //----------------------------------------------------------------------------------------------------
 222 // Implementation of BufferBlob
 223 
 224 
 225 BufferBlob::BufferBlob(const char* name, int size)
 226 : RuntimeBlob(name, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, /*locs_size:*/ 0)
 227 {}
 228 
 229 BufferBlob* BufferBlob::create(const char* name, int buffer_size) {
 230   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 231 
 232   BufferBlob* blob = NULL;
 233   unsigned int size = sizeof(BufferBlob);
 234   // align the size to CodeEntryAlignment
 235   size = CodeBlob::align_code_offset(size);
 236   size += align_up(buffer_size, oopSize);
 237   assert(name != NULL, "must provide a name");
 238   {
 239     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 240     blob = new (size) BufferBlob(name, size);
 241   }
 242   // Track memory usage statistic after releasing CodeCache_lock
 243   MemoryService::track_code_cache_memory_usage();
 244 
 245   return blob;
 246 }
 247 
 248 
 249 BufferBlob::BufferBlob(const char* name, int size, CodeBuffer* cb)
 250   : RuntimeBlob(name, cb, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, 0, NULL)
 251 {}
 252 
 253 BufferBlob* BufferBlob::create(const char* name, CodeBuffer* cb) {
 254   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 255 
 256   BufferBlob* blob = NULL;
 257   unsigned int size = CodeBlob::allocation_size(cb, sizeof(BufferBlob));
 258   assert(name != NULL, "must provide a name");
 259   {
 260     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 261     blob = new (size) BufferBlob(name, size, cb);
 262   }
 263   // Track memory usage statistic after releasing CodeCache_lock
 264   MemoryService::track_code_cache_memory_usage();
 265 
 266   return blob;
 267 }
 268 
 269 void* BufferBlob::operator new(size_t s, unsigned size) throw() {
 270   return CodeCache::allocate(size, CodeBlobType::NonNMethod);
 271 }
 272 
 273 void BufferBlob::free(BufferBlob *blob) {
 274   assert(blob != NULL, "caller must check for NULL");
 275   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 276   blob->flush();
 277   {
 278     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 279     CodeCache::free((RuntimeBlob*)blob);
 280   }
 281   // Track memory usage statistic after releasing CodeCache_lock
 282   MemoryService::track_code_cache_memory_usage();
 283 }
 284 
 285 
 286 //----------------------------------------------------------------------------------------------------
 287 // Implementation of AdapterBlob
 288 
 289 AdapterBlob::AdapterBlob(int size, CodeBuffer* cb) :
 290   BufferBlob("I2C/C2I adapters", size, cb) {
 291   CodeCache::commit(this);
 292 }
 293 
 294 AdapterBlob* AdapterBlob::create(CodeBuffer* cb) {
 295   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 296 
 297   AdapterBlob* blob = NULL;
 298   unsigned int size = CodeBlob::allocation_size(cb, sizeof(AdapterBlob));
 299   {
 300     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 301     blob = new (size) AdapterBlob(size, cb);
 302   }
 303   // Track memory usage statistic after releasing CodeCache_lock
 304   MemoryService::track_code_cache_memory_usage();
 305 
 306   return blob;
 307 }
 308 
 309 VtableBlob::VtableBlob(const char* name, int size) :
 310   BufferBlob(name, size) {
 311 }
 312 
 313 VtableBlob* VtableBlob::create(const char* name, int buffer_size) {
 314   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 315 
 316   VtableBlob* blob = NULL;
 317   unsigned int size = sizeof(VtableBlob);
 318   // align the size to CodeEntryAlignment
 319   size = align_code_offset(size);
 320   size += align_up(buffer_size, oopSize);
 321   assert(name != NULL, "must provide a name");
 322   {
 323     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 324     blob = new (size) VtableBlob(name, size);
 325   }
 326   // Track memory usage statistic after releasing CodeCache_lock
 327   MemoryService::track_code_cache_memory_usage();
 328 
 329   return blob;
 330 }
 331 
 332 //----------------------------------------------------------------------------------------------------
 333 // Implementation of MethodHandlesAdapterBlob
 334 
 335 MethodHandlesAdapterBlob* MethodHandlesAdapterBlob::create(int buffer_size) {
 336   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 337 
 338   MethodHandlesAdapterBlob* blob = NULL;
 339   unsigned int size = sizeof(MethodHandlesAdapterBlob);
 340   // align the size to CodeEntryAlignment
 341   size = CodeBlob::align_code_offset(size);
 342   size += align_up(buffer_size, oopSize);
 343   {
 344     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 345     blob = new (size) MethodHandlesAdapterBlob(size);
 346     if (blob == NULL) {
 347       vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "CodeCache: no room for method handle adapter blob");
 348     }
 349   }
 350   // Track memory usage statistic after releasing CodeCache_lock
 351   MemoryService::track_code_cache_memory_usage();
 352 
 353   return blob;
 354 }
 355 
 356 //----------------------------------------------------------------------------------------------------
 357 // Implementation of RuntimeStub
 358 
 359 RuntimeStub::RuntimeStub(
 360   const char* name,
 361   CodeBuffer* cb,
 362   int         size,
 363   int         frame_complete,
 364   int         frame_size,
 365   OopMapSet*  oop_maps,
 366   bool        caller_must_gc_arguments
 367 )
 368 : RuntimeBlob(name, cb, sizeof(RuntimeStub), size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments)
 369 {
 370 }
 371 
 372 RuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name,
 373                                            CodeBuffer* cb,
 374                                            int frame_complete,
 375                                            int frame_size,
 376                                            OopMapSet* oop_maps,
 377                                            bool caller_must_gc_arguments)
 378 {
 379   RuntimeStub* stub = NULL;
 380   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 381   {
 382     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 383     unsigned int size = CodeBlob::allocation_size(cb, sizeof(RuntimeStub));
 384     stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments);
 385   }
 386 
 387   trace_new_stub(stub, "RuntimeStub - ", stub_name);
 388 
 389   return stub;
 390 }
 391 
 392 
 393 void* RuntimeStub::operator new(size_t s, unsigned size) throw() {
 394   void* p = CodeCache::allocate(size, CodeBlobType::NonNMethod);
 395   if (!p) fatal("Initial size of CodeCache is too small");
 396   return p;
 397 }
 398 
 399 // operator new shared by all singletons:
 400 void* SingletonBlob::operator new(size_t s, unsigned size) throw() {
 401   void* p = CodeCache::allocate(size, CodeBlobType::NonNMethod);
 402   if (!p) fatal("Initial size of CodeCache is too small");
 403   return p;
 404 }
 405 
 406 
 407 //----------------------------------------------------------------------------------------------------
 408 // Implementation of DeoptimizationBlob
 409 
 410 DeoptimizationBlob::DeoptimizationBlob(
 411   CodeBuffer* cb,
 412   int         size,
 413   OopMapSet*  oop_maps,
 414   int         unpack_offset,
 415   int         unpack_with_exception_offset,
 416   int         unpack_with_reexecution_offset,
 417   int         frame_size
 418 )
 419 : SingletonBlob("DeoptimizationBlob", cb, sizeof(DeoptimizationBlob), size, frame_size, oop_maps)
 420 {
 421   _unpack_offset           = unpack_offset;
 422   _unpack_with_exception   = unpack_with_exception_offset;
 423   _unpack_with_reexecution = unpack_with_reexecution_offset;
 424 #ifdef COMPILER1
 425   _unpack_with_exception_in_tls   = -1;
 426 #endif
 427 }
 428 
 429 
 430 DeoptimizationBlob* DeoptimizationBlob::create(
 431   CodeBuffer* cb,
 432   OopMapSet*  oop_maps,
 433   int        unpack_offset,
 434   int        unpack_with_exception_offset,
 435   int        unpack_with_reexecution_offset,
 436   int        frame_size)
 437 {
 438   DeoptimizationBlob* blob = NULL;
 439   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 440   {
 441     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 442     unsigned int size = CodeBlob::allocation_size(cb, sizeof(DeoptimizationBlob));
 443     blob = new (size) DeoptimizationBlob(cb,
 444                                          size,
 445                                          oop_maps,
 446                                          unpack_offset,
 447                                          unpack_with_exception_offset,
 448                                          unpack_with_reexecution_offset,
 449                                          frame_size);
 450   }
 451 
 452   trace_new_stub(blob, "DeoptimizationBlob");
 453 
 454   return blob;
 455 }
 456 
 457 
 458 //----------------------------------------------------------------------------------------------------
 459 // Implementation of UncommonTrapBlob
 460 
 461 #ifdef COMPILER2
 462 UncommonTrapBlob::UncommonTrapBlob(
 463   CodeBuffer* cb,
 464   int         size,
 465   OopMapSet*  oop_maps,
 466   int         frame_size
 467 )
 468 : SingletonBlob("UncommonTrapBlob", cb, sizeof(UncommonTrapBlob), size, frame_size, oop_maps)
 469 {}
 470 
 471 
 472 UncommonTrapBlob* UncommonTrapBlob::create(
 473   CodeBuffer* cb,
 474   OopMapSet*  oop_maps,
 475   int        frame_size)
 476 {
 477   UncommonTrapBlob* blob = NULL;
 478   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 479   {
 480     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 481     unsigned int size = CodeBlob::allocation_size(cb, sizeof(UncommonTrapBlob));
 482     blob = new (size) UncommonTrapBlob(cb, size, oop_maps, frame_size);
 483   }
 484 
 485   trace_new_stub(blob, "UncommonTrapBlob");
 486 
 487   return blob;
 488 }
 489 
 490 
 491 #endif // COMPILER2
 492 
 493 
 494 //----------------------------------------------------------------------------------------------------
 495 // Implementation of ExceptionBlob
 496 
 497 #ifdef COMPILER2
 498 ExceptionBlob::ExceptionBlob(
 499   CodeBuffer* cb,
 500   int         size,
 501   OopMapSet*  oop_maps,
 502   int         frame_size
 503 )
 504 : SingletonBlob("ExceptionBlob", cb, sizeof(ExceptionBlob), size, frame_size, oop_maps)
 505 {}
 506 
 507 
 508 ExceptionBlob* ExceptionBlob::create(
 509   CodeBuffer* cb,
 510   OopMapSet*  oop_maps,
 511   int         frame_size)
 512 {
 513   ExceptionBlob* blob = NULL;
 514   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 515   {
 516     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 517     unsigned int size = CodeBlob::allocation_size(cb, sizeof(ExceptionBlob));
 518     blob = new (size) ExceptionBlob(cb, size, oop_maps, frame_size);
 519   }
 520 
 521   trace_new_stub(blob, "ExceptionBlob");
 522 
 523   return blob;
 524 }
 525 
 526 
 527 #endif // COMPILER2
 528 
 529 
 530 //----------------------------------------------------------------------------------------------------
 531 // Implementation of SafepointBlob
 532 
 533 SafepointBlob::SafepointBlob(
 534   CodeBuffer* cb,
 535   int         size,
 536   OopMapSet*  oop_maps,
 537   int         frame_size
 538 )
 539 : SingletonBlob("SafepointBlob", cb, sizeof(SafepointBlob), size, frame_size, oop_maps)
 540 {}
 541 
 542 
 543 SafepointBlob* SafepointBlob::create(
 544   CodeBuffer* cb,
 545   OopMapSet*  oop_maps,
 546   int         frame_size)
 547 {
 548   SafepointBlob* blob = NULL;
 549   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 550   {
 551     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 552     unsigned int size = CodeBlob::allocation_size(cb, sizeof(SafepointBlob));
 553     blob = new (size) SafepointBlob(cb, size, oop_maps, frame_size);
 554   }
 555 
 556   trace_new_stub(blob, "SafepointBlob");
 557 
 558   return blob;
 559 }
 560 
 561 
 562 //----------------------------------------------------------------------------------------------------
 563 // Verification and printing
 564 
 565 void CodeBlob::print_on(outputStream* st) const {
 566   st->print_cr("[CodeBlob (" INTPTR_FORMAT ")]", p2i(this));
 567   st->print_cr("Framesize: %d", _frame_size);
 568 }
 569 
 570 void CodeBlob::print() const { print_on(tty); }
 571 
 572 void CodeBlob::print_value_on(outputStream* st) const {
 573   st->print_cr("[CodeBlob]");
 574 }
 575 
 576 void CodeBlob::dump_for_addr(address addr, outputStream* st, bool verbose) const {
 577   if (is_buffer_blob()) {
 578     // the interpreter is generated into a buffer blob
 579     InterpreterCodelet* i = Interpreter::codelet_containing(addr);
 580     if (i != NULL) {
 581       st->print_cr(INTPTR_FORMAT " is at code_begin+%d in an Interpreter codelet", p2i(addr), (int)(addr - i->code_begin()));
 582       i->print_on(st);
 583       return;
 584     }
 585     if (Interpreter::contains(addr)) {
 586       st->print_cr(INTPTR_FORMAT " is pointing into interpreter code"
 587                    " (not bytecode specific)", p2i(addr));
 588       return;
 589     }
 590     //
 591     if (AdapterHandlerLibrary::contains(this)) {
 592       st->print_cr(INTPTR_FORMAT " is at code_begin+%d in an AdapterHandler", p2i(addr), (int)(addr - code_begin()));
 593       AdapterHandlerLibrary::print_handler_on(st, this);
 594     }
 595     // the stubroutines are generated into a buffer blob
 596     StubCodeDesc* d = StubCodeDesc::desc_for(addr);
 597     if (d != NULL) {
 598       st->print_cr(INTPTR_FORMAT " is at begin+%d in a stub", p2i(addr), (int)(addr - d->begin()));
 599       d->print_on(st);
 600       st->cr();
 601       return;
 602     }
 603     if (StubRoutines::contains(addr)) {
 604       st->print_cr(INTPTR_FORMAT " is pointing to an (unnamed) stub routine", p2i(addr));
 605       return;
 606     }
 607     // the InlineCacheBuffer is using stubs generated into a buffer blob
 608     if (InlineCacheBuffer::contains(addr)) {
 609       st->print_cr(INTPTR_FORMAT " is pointing into InlineCacheBuffer", p2i(addr));
 610       return;
 611     }
 612     VtableStub* v = VtableStubs::stub_containing(addr);
 613     if (v != NULL) {
 614       st->print_cr(INTPTR_FORMAT " is at entry_point+%d in a vtable stub", p2i(addr), (int)(addr - v->entry_point()));
 615       v->print_on(st);
 616       st->cr();
 617       return;
 618     }
 619   }
 620   if (is_nmethod()) {
 621     nmethod* nm = (nmethod*)this;
 622     ResourceMark rm;
 623     st->print(INTPTR_FORMAT " is at entry_point+%d in (nmethod*)" INTPTR_FORMAT,
 624               p2i(addr), (int)(addr - nm->entry_point()), p2i(nm));
 625     if (verbose) {
 626       st->print(" for ");
 627       nm->method()->print_value_on(st);
 628     }
 629     st->cr();
 630     nm->print_nmethod(verbose);
 631     return;
 632   }
 633   st->print_cr(INTPTR_FORMAT " is at code_begin+%d in ", p2i(addr), (int)(addr - code_begin()));
 634   print_on(st);
 635 }
 636 
 637 void RuntimeBlob::verify() {
 638   ShouldNotReachHere();
 639 }
 640 
 641 void BufferBlob::verify() {
 642   // unimplemented
 643 }
 644 
 645 void BufferBlob::print_on(outputStream* st) const {
 646   RuntimeBlob::print_on(st);
 647   print_value_on(st);
 648 }
 649 
 650 void BufferBlob::print_value_on(outputStream* st) const {
 651   st->print_cr("BufferBlob (" INTPTR_FORMAT  ") used for %s", p2i(this), name());
 652 }
 653 
 654 void RuntimeStub::verify() {
 655   // unimplemented
 656 }
 657 
 658 void RuntimeStub::print_on(outputStream* st) const {
 659   ttyLocker ttyl;
 660   RuntimeBlob::print_on(st);
 661   st->print("Runtime Stub (" INTPTR_FORMAT "): ", p2i(this));
 662   st->print_cr("%s", name());
 663   Disassembler::decode((RuntimeBlob*)this, st);
 664 }
 665 
 666 void RuntimeStub::print_value_on(outputStream* st) const {
 667   st->print("RuntimeStub (" INTPTR_FORMAT "): ", p2i(this)); st->print("%s", name());
 668 }
 669 
 670 void SingletonBlob::verify() {
 671   // unimplemented
 672 }
 673 
 674 void SingletonBlob::print_on(outputStream* st) const {
 675   ttyLocker ttyl;
 676   RuntimeBlob::print_on(st);
 677   st->print_cr("%s", name());
 678   Disassembler::decode((RuntimeBlob*)this, st);
 679 }
 680 
 681 void SingletonBlob::print_value_on(outputStream* st) const {
 682   st->print_cr("%s", name());
 683 }
 684 
 685 void DeoptimizationBlob::print_value_on(outputStream* st) const {
 686   st->print_cr("Deoptimization (frame not available)");
 687 }