1 /*
   2  * Copyright (c) 1998, 2018, 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) :
  77   _name(name),
  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   _strings(CodeStrings()),
  84   _oop_maps(oop_maps),
  85   _caller_must_gc_arguments(caller_must_gc_arguments),
  86   _code_begin(layout.code_begin()),
  87   _code_end(layout.code_end()),
  88   _data_end(layout.data_end()),
  89   _relocation_begin(layout.relocation_begin()),
  90   _relocation_end(layout.relocation_end()),
  91   _content_begin(layout.content_begin()),
  92   _type(type)
  93 {
  94   assert(is_aligned(layout.size(),            oopSize), "unaligned size");
  95   assert(is_aligned(layout.header_size(),     oopSize), "unaligned size");
  96   assert(is_aligned(layout.relocation_size(), oopSize), "unaligned size");
  97   assert(layout.code_end() == layout.content_end(), "must be the same - see code_end()");
  98 #ifdef COMPILER1
  99   // probably wrong for tiered
 100   assert(_frame_size >= -1, "must use frame size or -1 for runtime stubs");
 101 #endif // COMPILER1
 102 }
 103 
 104 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) :
 105   _name(name),
 106   _size(layout.size()),
 107   _header_size(layout.header_size()),
 108   _frame_complete_offset(frame_complete_offset),
 109   _data_offset(layout.data_offset()),
 110   _frame_size(frame_size),
 111   _strings(CodeStrings()),
 112   _caller_must_gc_arguments(caller_must_gc_arguments),
 113   _code_begin(layout.code_begin()),
 114   _code_end(layout.code_end()),
 115   _data_end(layout.data_end()),
 116   _relocation_begin(layout.relocation_begin()),
 117   _relocation_end(layout.relocation_end()),
 118   _content_begin(layout.content_begin()),
 119   _type(type)
 120 {
 121   assert(is_aligned(_size,        oopSize), "unaligned size");
 122   assert(is_aligned(_header_size, oopSize), "unaligned size");
 123   assert(_data_offset <= _size, "codeBlob is too small");
 124   assert(layout.code_end() == layout.content_end(), "must be the same - see code_end()");
 125 
 126   set_oop_maps(oop_maps);
 127 #ifdef COMPILER1
 128   // probably wrong for tiered
 129   assert(_frame_size >= -1, "must use frame size or -1 for runtime stubs");
 130 #endif // COMPILER1
 131 }
 132 
 133 
 134 // Creates a simple CodeBlob. Sets up the size of the different regions.
 135 RuntimeBlob::RuntimeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size)
 136   : CodeBlob(name, compiler_none, CodeBlobLayout((address) this, size, header_size, locs_size, size), frame_complete, 0, NULL, false /* caller_must_gc_arguments */)
 137 {
 138   assert(is_aligned(locs_size, oopSize), "unaligned size");
 139 }
 140 
 141 
 142 // Creates a RuntimeBlob from a CodeBuffer
 143 // and copy code and relocation info.
 144 RuntimeBlob::RuntimeBlob(
 145   const char* name,
 146   CodeBuffer* cb,
 147   int         header_size,
 148   int         size,
 149   int         frame_complete,
 150   int         frame_size,
 151   OopMapSet*  oop_maps,
 152   bool        caller_must_gc_arguments
 153 ) : CodeBlob(name, compiler_none, CodeBlobLayout((address) this, size, header_size, cb), cb, frame_complete, frame_size, oop_maps, caller_must_gc_arguments) {
 154   cb->copy_code_and_locs_to(this);
 155 }
 156 
 157 void CodeBlob::flush() {
 158   if (_oop_maps) {
 159     FREE_C_HEAP_ARRAY(unsigned char, _oop_maps);
 160     _oop_maps = NULL;
 161   }
 162   _strings.free();
 163 }
 164 
 165 void CodeBlob::set_oop_maps(OopMapSet* p) {
 166   // Danger Will Robinson! This method allocates a big
 167   // chunk of memory, its your job to free it.
 168   if (p != NULL) {
 169     _oop_maps = ImmutableOopMapSet::build_from(p);
 170   } else {
 171     _oop_maps = NULL;
 172   }
 173 }
 174 
 175 
 176 void RuntimeBlob::trace_new_stub(RuntimeBlob* stub, const char* name1, const char* name2) {
 177   // Do not hold the CodeCache lock during name formatting.
 178   assert(!CodeCache_lock->owned_by_self(), "release CodeCache before registering the stub");
 179 
 180   if (stub != NULL) {
 181     char stub_id[256];
 182     assert(strlen(name1) + strlen(name2) < sizeof(stub_id), "");
 183     jio_snprintf(stub_id, sizeof(stub_id), "%s%s", name1, name2);
 184     if (PrintStubCode) {
 185       ttyLocker ttyl;
 186       tty->print_cr("Decoding %s " INTPTR_FORMAT, stub_id, (intptr_t) stub);
 187       Disassembler::decode(stub->code_begin(), stub->code_end());
 188       tty->cr();
 189     }
 190     Forte::register_stub(stub_id, stub->code_begin(), stub->code_end());
 191 
 192     if (JvmtiExport::should_post_dynamic_code_generated()) {
 193       const char* stub_name = name2;
 194       if (name2[0] == '\0')  stub_name = name1;
 195       JvmtiExport::post_dynamic_code_generated(stub_name, stub->code_begin(), stub->code_end());
 196     }
 197   }
 198 
 199   // Track memory usage statistic after releasing CodeCache_lock
 200   MemoryService::track_code_cache_memory_usage();
 201 }
 202 
 203 const ImmutableOopMap* CodeBlob::oop_map_for_return_address(address return_address) {
 204   assert(_oop_maps != NULL, "nope");
 205   return _oop_maps->find_map_at_offset((intptr_t) return_address - (intptr_t) code_begin());
 206 }
 207 
 208 void CodeBlob::print_code() {
 209   ResourceMark m;
 210   Disassembler::decode(this, tty);
 211 }
 212 
 213 //----------------------------------------------------------------------------------------------------
 214 // Implementation of BufferBlob
 215 
 216 
 217 BufferBlob::BufferBlob(const char* name, int size)
 218 : RuntimeBlob(name, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, /*locs_size:*/ 0)
 219 {}
 220 
 221 BufferBlob* BufferBlob::create(const char* name, int buffer_size) {
 222   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 223 
 224   BufferBlob* blob = NULL;
 225   unsigned int size = sizeof(BufferBlob);
 226   // align the size to CodeEntryAlignment
 227   size = CodeBlob::align_code_offset(size);
 228   size += align_up(buffer_size, oopSize);
 229   assert(name != NULL, "must provide a name");
 230   {
 231     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 232     blob = new (size) BufferBlob(name, size);
 233   }
 234   // Track memory usage statistic after releasing CodeCache_lock
 235   MemoryService::track_code_cache_memory_usage();
 236 
 237   return blob;
 238 }
 239 
 240 
 241 BufferBlob::BufferBlob(const char* name, int size, CodeBuffer* cb)
 242   : RuntimeBlob(name, cb, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, 0, NULL)
 243 {}
 244 
 245 BufferBlob* BufferBlob::create(const char* name, CodeBuffer* cb) {
 246   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 247 
 248   BufferBlob* blob = NULL;
 249   unsigned int size = CodeBlob::allocation_size(cb, sizeof(BufferBlob));
 250   assert(name != NULL, "must provide a name");
 251   {
 252     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 253     blob = new (size) BufferBlob(name, size, cb);
 254   }
 255   // Track memory usage statistic after releasing CodeCache_lock
 256   MemoryService::track_code_cache_memory_usage();
 257 
 258   return blob;
 259 }
 260 
 261 void* BufferBlob::operator new(size_t s, unsigned size) throw() {
 262   return CodeCache::allocate(size, CodeBlobType::NonNMethod);
 263 }
 264 
 265 void BufferBlob::free(BufferBlob *blob) {
 266   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 267   blob->flush();
 268   {
 269     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 270     CodeCache::free((RuntimeBlob*)blob);
 271   }
 272   // Track memory usage statistic after releasing CodeCache_lock
 273   MemoryService::track_code_cache_memory_usage();
 274 }
 275 
 276 
 277 //----------------------------------------------------------------------------------------------------
 278 // Implementation of AdapterBlob
 279 
 280 AdapterBlob::AdapterBlob(int size, CodeBuffer* cb) :
 281   BufferBlob("I2C/C2I adapters", size, cb) {
 282   CodeCache::commit(this);
 283 }
 284 
 285 AdapterBlob* AdapterBlob::create(CodeBuffer* cb) {
 286   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 287 
 288   AdapterBlob* blob = NULL;
 289   unsigned int size = CodeBlob::allocation_size(cb, sizeof(AdapterBlob));
 290   {
 291     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 292     blob = new (size) AdapterBlob(size, cb);
 293   }
 294   // Track memory usage statistic after releasing CodeCache_lock
 295   MemoryService::track_code_cache_memory_usage();
 296 
 297   return blob;
 298 }
 299 
 300 VtableBlob::VtableBlob(const char* name, int size) :
 301   BufferBlob(name, size) {
 302 }
 303 
 304 VtableBlob* VtableBlob::create(const char* name, int buffer_size) {
 305   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 306 
 307   VtableBlob* blob = NULL;
 308   unsigned int size = sizeof(VtableBlob);
 309   // align the size to CodeEntryAlignment
 310   size = align_code_offset(size);
 311   size += align_up(buffer_size, oopSize);
 312   assert(name != NULL, "must provide a name");
 313   {
 314     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 315     blob = new (size) VtableBlob(name, size);
 316   }
 317   // Track memory usage statistic after releasing CodeCache_lock
 318   MemoryService::track_code_cache_memory_usage();
 319 
 320   return blob;
 321 }
 322 
 323 //----------------------------------------------------------------------------------------------------
 324 // Implementation of MethodHandlesAdapterBlob
 325 
 326 MethodHandlesAdapterBlob* MethodHandlesAdapterBlob::create(int buffer_size) {
 327   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 328 
 329   MethodHandlesAdapterBlob* blob = NULL;
 330   unsigned int size = sizeof(MethodHandlesAdapterBlob);
 331   // align the size to CodeEntryAlignment
 332   size = CodeBlob::align_code_offset(size);
 333   size += align_up(buffer_size, oopSize);
 334   {
 335     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 336     blob = new (size) MethodHandlesAdapterBlob(size);
 337     if (blob == NULL) {
 338       vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "CodeCache: no room for method handle adapter blob");
 339     }
 340   }
 341   // Track memory usage statistic after releasing CodeCache_lock
 342   MemoryService::track_code_cache_memory_usage();
 343 
 344   return blob;
 345 }
 346 
 347 //----------------------------------------------------------------------------------------------------
 348 // Implementation of RuntimeStub
 349 
 350 RuntimeStub::RuntimeStub(
 351   const char* name,
 352   CodeBuffer* cb,
 353   int         size,
 354   int         frame_complete,
 355   int         frame_size,
 356   OopMapSet*  oop_maps,
 357   bool        caller_must_gc_arguments
 358 )
 359 : RuntimeBlob(name, cb, sizeof(RuntimeStub), size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments)
 360 {
 361 }
 362 
 363 RuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name,
 364                                            CodeBuffer* cb,
 365                                            int frame_complete,
 366                                            int frame_size,
 367                                            OopMapSet* oop_maps,
 368                                            bool caller_must_gc_arguments)
 369 {
 370   RuntimeStub* stub = NULL;
 371   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 372   {
 373     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 374     unsigned int size = CodeBlob::allocation_size(cb, sizeof(RuntimeStub));
 375     stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments);
 376   }
 377 
 378   trace_new_stub(stub, "RuntimeStub - ", stub_name);
 379 
 380   return stub;
 381 }
 382 
 383 
 384 void* RuntimeStub::operator new(size_t s, unsigned size) throw() {
 385   void* p = CodeCache::allocate(size, CodeBlobType::NonNMethod);
 386   if (!p) fatal("Initial size of CodeCache is too small");
 387   return p;
 388 }
 389 
 390 // operator new shared by all singletons:
 391 void* SingletonBlob::operator new(size_t s, unsigned size) throw() {
 392   void* p = CodeCache::allocate(size, CodeBlobType::NonNMethod);
 393   if (!p) fatal("Initial size of CodeCache is too small");
 394   return p;
 395 }
 396 
 397 
 398 //----------------------------------------------------------------------------------------------------
 399 // Implementation of DeoptimizationBlob
 400 
 401 DeoptimizationBlob::DeoptimizationBlob(
 402   CodeBuffer* cb,
 403   int         size,
 404   OopMapSet*  oop_maps,
 405   int         unpack_offset,
 406   int         unpack_with_exception_offset,
 407   int         unpack_with_reexecution_offset,
 408   int         frame_size
 409 )
 410 : SingletonBlob("DeoptimizationBlob", cb, sizeof(DeoptimizationBlob), size, frame_size, oop_maps)
 411 {
 412   _unpack_offset           = unpack_offset;
 413   _unpack_with_exception   = unpack_with_exception_offset;
 414   _unpack_with_reexecution = unpack_with_reexecution_offset;
 415 #ifdef COMPILER1
 416   _unpack_with_exception_in_tls   = -1;
 417 #endif
 418 }
 419 
 420 
 421 DeoptimizationBlob* DeoptimizationBlob::create(
 422   CodeBuffer* cb,
 423   OopMapSet*  oop_maps,
 424   int        unpack_offset,
 425   int        unpack_with_exception_offset,
 426   int        unpack_with_reexecution_offset,
 427   int        frame_size)
 428 {
 429   DeoptimizationBlob* blob = NULL;
 430   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 431   {
 432     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 433     unsigned int size = CodeBlob::allocation_size(cb, sizeof(DeoptimizationBlob));
 434     blob = new (size) DeoptimizationBlob(cb,
 435                                          size,
 436                                          oop_maps,
 437                                          unpack_offset,
 438                                          unpack_with_exception_offset,
 439                                          unpack_with_reexecution_offset,
 440                                          frame_size);
 441   }
 442 
 443   trace_new_stub(blob, "DeoptimizationBlob");
 444 
 445   return blob;
 446 }
 447 
 448 
 449 //----------------------------------------------------------------------------------------------------
 450 // Implementation of UncommonTrapBlob
 451 
 452 #ifdef COMPILER2
 453 UncommonTrapBlob::UncommonTrapBlob(
 454   CodeBuffer* cb,
 455   int         size,
 456   OopMapSet*  oop_maps,
 457   int         frame_size
 458 )
 459 : SingletonBlob("UncommonTrapBlob", cb, sizeof(UncommonTrapBlob), size, frame_size, oop_maps)
 460 {}
 461 
 462 
 463 UncommonTrapBlob* UncommonTrapBlob::create(
 464   CodeBuffer* cb,
 465   OopMapSet*  oop_maps,
 466   int        frame_size)
 467 {
 468   UncommonTrapBlob* blob = NULL;
 469   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 470   {
 471     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 472     unsigned int size = CodeBlob::allocation_size(cb, sizeof(UncommonTrapBlob));
 473     blob = new (size) UncommonTrapBlob(cb, size, oop_maps, frame_size);
 474   }
 475 
 476   trace_new_stub(blob, "UncommonTrapBlob");
 477 
 478   return blob;
 479 }
 480 
 481 
 482 #endif // COMPILER2
 483 
 484 
 485 //----------------------------------------------------------------------------------------------------
 486 // Implementation of ExceptionBlob
 487 
 488 #ifdef COMPILER2
 489 ExceptionBlob::ExceptionBlob(
 490   CodeBuffer* cb,
 491   int         size,
 492   OopMapSet*  oop_maps,
 493   int         frame_size
 494 )
 495 : SingletonBlob("ExceptionBlob", cb, sizeof(ExceptionBlob), size, frame_size, oop_maps)
 496 {}
 497 
 498 
 499 ExceptionBlob* ExceptionBlob::create(
 500   CodeBuffer* cb,
 501   OopMapSet*  oop_maps,
 502   int         frame_size)
 503 {
 504   ExceptionBlob* blob = NULL;
 505   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 506   {
 507     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 508     unsigned int size = CodeBlob::allocation_size(cb, sizeof(ExceptionBlob));
 509     blob = new (size) ExceptionBlob(cb, size, oop_maps, frame_size);
 510   }
 511 
 512   trace_new_stub(blob, "ExceptionBlob");
 513 
 514   return blob;
 515 }
 516 
 517 
 518 #endif // COMPILER2
 519 
 520 
 521 //----------------------------------------------------------------------------------------------------
 522 // Implementation of SafepointBlob
 523 
 524 SafepointBlob::SafepointBlob(
 525   CodeBuffer* cb,
 526   int         size,
 527   OopMapSet*  oop_maps,
 528   int         frame_size
 529 )
 530 : SingletonBlob("SafepointBlob", cb, sizeof(SafepointBlob), size, frame_size, oop_maps)
 531 {}
 532 
 533 
 534 SafepointBlob* SafepointBlob::create(
 535   CodeBuffer* cb,
 536   OopMapSet*  oop_maps,
 537   int         frame_size)
 538 {
 539   SafepointBlob* blob = NULL;
 540   ThreadInVMfromUnknown __tiv;  // get to VM state in case we block on CodeCache_lock
 541   {
 542     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 543     unsigned int size = CodeBlob::allocation_size(cb, sizeof(SafepointBlob));
 544     blob = new (size) SafepointBlob(cb, size, oop_maps, frame_size);
 545   }
 546 
 547   trace_new_stub(blob, "SafepointBlob");
 548 
 549   return blob;
 550 }
 551 
 552 
 553 //----------------------------------------------------------------------------------------------------
 554 // Verification and printing
 555 
 556 void CodeBlob::print_on(outputStream* st) const {
 557   st->print_cr("[CodeBlob (" INTPTR_FORMAT ")]", p2i(this));
 558   st->print_cr("Framesize: %d", _frame_size);
 559 }
 560 
 561 void CodeBlob::print_value_on(outputStream* st) const {
 562   st->print_cr("[CodeBlob]");
 563 }
 564 
 565 void CodeBlob::dump_for_addr(address addr, outputStream* st, bool verbose) const {
 566   if (is_buffer_blob()) {
 567     // the interpreter is generated into a buffer blob
 568     InterpreterCodelet* i = Interpreter::codelet_containing(addr);
 569     if (i != NULL) {
 570       st->print_cr(INTPTR_FORMAT " is at code_begin+%d in an Interpreter codelet", p2i(addr), (int)(addr - i->code_begin()));
 571       i->print_on(st);
 572       return;
 573     }
 574     if (Interpreter::contains(addr)) {
 575       st->print_cr(INTPTR_FORMAT " is pointing into interpreter code"
 576                    " (not bytecode specific)", p2i(addr));
 577       return;
 578     }
 579     //
 580     if (AdapterHandlerLibrary::contains(this)) {
 581       st->print_cr(INTPTR_FORMAT " is at code_begin+%d in an AdapterHandler", p2i(addr), (int)(addr - code_begin()));
 582       AdapterHandlerLibrary::print_handler_on(st, this);
 583     }
 584     // the stubroutines are generated into a buffer blob
 585     StubCodeDesc* d = StubCodeDesc::desc_for(addr);
 586     if (d != NULL) {
 587       st->print_cr(INTPTR_FORMAT " is at begin+%d in a stub", p2i(addr), (int)(addr - d->begin()));
 588       d->print_on(st);
 589       st->cr();
 590       return;
 591     }
 592     if (StubRoutines::contains(addr)) {
 593       st->print_cr(INTPTR_FORMAT " is pointing to an (unnamed) stub routine", p2i(addr));
 594       return;
 595     }
 596     // the InlineCacheBuffer is using stubs generated into a buffer blob
 597     if (InlineCacheBuffer::contains(addr)) {
 598       st->print_cr(INTPTR_FORMAT " is pointing into InlineCacheBuffer", p2i(addr));
 599       return;
 600     }
 601     VtableStub* v = VtableStubs::stub_containing(addr);
 602     if (v != NULL) {
 603       st->print_cr(INTPTR_FORMAT " is at entry_point+%d in a vtable stub", p2i(addr), (int)(addr - v->entry_point()));
 604       v->print_on(st);
 605       st->cr();
 606       return;
 607     }
 608   }
 609   if (is_nmethod()) {
 610     nmethod* nm = (nmethod*)this;
 611     ResourceMark rm;
 612     st->print(INTPTR_FORMAT " is at entry_point+%d in (nmethod*)" INTPTR_FORMAT,
 613               p2i(addr), (int)(addr - nm->entry_point()), p2i(nm));
 614     if (verbose) {
 615       st->print(" for ");
 616       nm->method()->print_value_on(st);
 617     }
 618     st->cr();
 619     nm->print_nmethod(verbose);
 620     return;
 621   }
 622   st->print_cr(INTPTR_FORMAT " is at code_begin+%d in ", p2i(addr), (int)(addr - code_begin()));
 623   print_on(st);
 624 }
 625 
 626 void RuntimeBlob::verify() {
 627   ShouldNotReachHere();
 628 }
 629 
 630 void BufferBlob::verify() {
 631   // unimplemented
 632 }
 633 
 634 void BufferBlob::print_on(outputStream* st) const {
 635   RuntimeBlob::print_on(st);
 636   print_value_on(st);
 637 }
 638 
 639 void BufferBlob::print_value_on(outputStream* st) const {
 640   st->print_cr("BufferBlob (" INTPTR_FORMAT  ") used for %s", p2i(this), name());
 641 }
 642 
 643 void RuntimeStub::verify() {
 644   // unimplemented
 645 }
 646 
 647 void RuntimeStub::print_on(outputStream* st) const {
 648   ttyLocker ttyl;
 649   RuntimeBlob::print_on(st);
 650   st->print("Runtime Stub (" INTPTR_FORMAT "): ", p2i(this));
 651   st->print_cr("%s", name());
 652   Disassembler::decode((RuntimeBlob*)this, st);
 653 }
 654 
 655 void RuntimeStub::print_value_on(outputStream* st) const {
 656   st->print("RuntimeStub (" INTPTR_FORMAT "): ", p2i(this)); st->print("%s", name());
 657 }
 658 
 659 void SingletonBlob::verify() {
 660   // unimplemented
 661 }
 662 
 663 void SingletonBlob::print_on(outputStream* st) const {
 664   ttyLocker ttyl;
 665   RuntimeBlob::print_on(st);
 666   st->print_cr("%s", name());
 667   Disassembler::decode((RuntimeBlob*)this, st);
 668 }
 669 
 670 void SingletonBlob::print_value_on(outputStream* st) const {
 671   st->print_cr("%s", name());
 672 }
 673 
 674 void DeoptimizationBlob::print_value_on(outputStream* st) const {
 675   st->print_cr("Deoptimization (frame not available)");
 676 }