1 /* 2 * Copyright (c) 1998, 2025, 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 #ifndef SHARE_CODE_CODEBLOB_HPP 26 #define SHARE_CODE_CODEBLOB_HPP 27 28 #include "asm/codeBuffer.hpp" 29 #include "code/aotCodeCache.hpp" 30 #include "compiler/compilerDefinitions.hpp" 31 #include "compiler/oopMap.hpp" 32 #include "runtime/javaFrameAnchor.hpp" 33 #include "runtime/frame.hpp" 34 #include "runtime/handles.hpp" 35 #include "utilities/align.hpp" 36 #include "utilities/macros.hpp" 37 38 class ImmutableOopMap; 39 class ImmutableOopMapSet; 40 class JNIHandleBlock; 41 class OopMapSet; 42 43 // CodeBlob Types 44 // Used in the CodeCache to assign CodeBlobs to different CodeHeaps 45 enum class CodeBlobType { 46 MethodNonProfiled = 0, // Execution level 1 and 4 (non-profiled) nmethods (including native nmethods) 47 MethodProfiled = 1, // Execution level 2 and 3 (profiled) nmethods 48 NonNMethod = 2, // Non-nmethods like Buffers, Adapters and Runtime Stubs 49 All = 3, // All types (No code cache segmentation) 50 NumTypes = 4 // Number of CodeBlobTypes 51 }; 52 53 // CodeBlob - superclass for all entries in the CodeCache. 54 // 55 // Subtypes are: 56 // nmethod : JIT Compiled Java methods 57 // RuntimeBlob : Non-compiled method code; generated glue code 58 // BufferBlob : Used for non-relocatable code such as interpreter, stubroutines, etc. 59 // AdapterBlob : Used to hold C2I/I2C adapters 60 // VtableBlob : Used for holding vtable chunks 61 // MethodHandlesAdapterBlob : Used to hold MethodHandles adapters 62 // RuntimeStub : Call to VM runtime methods 63 // SingletonBlob : Super-class for all blobs that exist in only one instance 64 // DeoptimizationBlob : Used for deoptimization 65 // SafepointBlob : Used to handle illegal instruction exceptions 66 // ExceptionBlob : Used for stack unrolling 67 // UncommonTrapBlob : Used to handle uncommon traps 68 // UpcallStub : Used for upcalls from native code 69 // 70 // 71 // Layout in the CodeCache: 72 // - header 73 // - content space 74 // - instruction space 75 // Outside of the CodeCache: 76 // - mutable_data 77 // - relocation info 78 // - additional data for subclasses 79 80 enum class CodeBlobKind : u1 { 81 None, 82 Nmethod, 83 Buffer, 84 Adapter, 85 Vtable, 86 MHAdapter, 87 RuntimeStub, 88 Deoptimization, 89 Safepoint, 90 #ifdef COMPILER2 91 Exception, 92 UncommonTrap, 93 #endif 94 Upcall, 95 Number_Of_Kinds 96 }; 97 98 class UpcallStub; // for as_upcall_stub() 99 class RuntimeStub; // for as_runtime_stub() 100 class JavaFrameAnchor; // for UpcallStub::jfa_for_frame 101 class AdapterBlob; 102 class ExceptionBlob; 103 104 class CodeBlob { 105 friend class VMStructs; 106 friend class JVMCIVMStructs; 107 108 private: 109 void restore_mutable_data(address reloc_data); 110 111 protected: 112 // order fields from large to small to minimize padding between fields 113 ImmutableOopMapSet* _oop_maps; // OopMap for this CodeBlob 114 const char* _name; 115 address _mutable_data; 116 117 int _size; // total size of CodeBlob in bytes 118 int _relocation_size; // size of relocation (could be bigger than 64Kb) 119 int _content_offset; // offset to where content region begins (this includes consts, insts, stubs) 120 int _code_offset; // offset to where instructions region begins (this includes insts, stubs) 121 int _data_offset; // offset to where data region begins 122 int _frame_size; // size of stack frame in words (NOT slots. On x64 these are 64bit words) 123 int _mutable_data_size; 124 125 S390_ONLY(int _ctable_offset;) 126 127 uint16_t _header_size; // size of header (depends on subclass) 128 int16_t _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have 129 // not finished setting up their frame. Beware of pc's in 130 // that range. There is a similar range(s) on returns 131 // which we don't detect. 132 133 CodeBlobKind _kind; // Kind of this code blob 134 135 bool _caller_must_gc_arguments; 136 137 #ifndef PRODUCT 138 AsmRemarks _asm_remarks; 139 DbgStrings _dbg_strings; 140 #endif 141 142 void print_on_impl(outputStream* st) const; 143 void print_value_on_impl(outputStream* st) const; 144 145 class Vptr { 146 public: 147 virtual void print_on(const CodeBlob* instance, outputStream* st) const = 0; 148 virtual void print_value_on(const CodeBlob* instance, outputStream* st) const = 0; 149 virtual void prepare_for_archiving(CodeBlob* instance) const { 150 instance->prepare_for_archiving_impl(); 151 }; 152 virtual void post_restore(CodeBlob* instance) const { 153 instance->post_restore_impl(); 154 }; 155 }; 156 157 static const Vptr* vptr(CodeBlobKind kind); 158 const Vptr* vptr() const; 159 160 CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size, 161 int16_t frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments, 162 int mutable_data_size); 163 164 // Simple CodeBlob used for simple BufferBlob. 165 CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size); 166 167 168 void operator delete(void* p) { } 169 170 void prepare_for_archiving_impl(); 171 void post_restore_impl(); 172 173 public: 174 175 ~CodeBlob() { 176 assert(_oop_maps == nullptr || AOTCodeCache::is_address_in_aot_cache((address)_oop_maps), "Not flushed"); 177 } 178 179 // Returns the space needed for CodeBlob 180 static unsigned int allocation_size(CodeBuffer* cb, int header_size); 181 static unsigned int align_code_offset(int offset); 182 183 // Deletion 184 void purge(); 185 186 // Typing 187 bool is_nmethod() const { return _kind == CodeBlobKind::Nmethod; } 188 bool is_buffer_blob() const { return _kind == CodeBlobKind::Buffer; } 189 bool is_runtime_stub() const { return _kind == CodeBlobKind::RuntimeStub; } 190 bool is_deoptimization_stub() const { return _kind == CodeBlobKind::Deoptimization; } 191 #ifdef COMPILER2 192 bool is_uncommon_trap_stub() const { return _kind == CodeBlobKind::UncommonTrap; } 193 bool is_exception_stub() const { return _kind == CodeBlobKind::Exception; } 194 #else 195 bool is_uncommon_trap_stub() const { return false; } 196 bool is_exception_stub() const { return false; } 197 #endif 198 bool is_safepoint_stub() const { return _kind == CodeBlobKind::Safepoint; } 199 bool is_adapter_blob() const { return _kind == CodeBlobKind::Adapter; } 200 bool is_vtable_blob() const { return _kind == CodeBlobKind::Vtable; } 201 bool is_method_handles_adapter_blob() const { return _kind == CodeBlobKind::MHAdapter; } 202 bool is_upcall_stub() const { return _kind == CodeBlobKind::Upcall; } 203 204 // Casting 205 nmethod* as_nmethod_or_null() const { return is_nmethod() ? (nmethod*) this : nullptr; } 206 nmethod* as_nmethod() const { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; } 207 CodeBlob* as_codeblob() const { return (CodeBlob*) this; } 208 AdapterBlob* as_adapter_blob() const { assert(is_adapter_blob(), "must be adapter blob"); return (AdapterBlob*) this; } 209 ExceptionBlob* as_exception_blob() const { assert(is_exception_stub(), "must be exception stub"); return (ExceptionBlob*) this; } 210 UpcallStub* as_upcall_stub() const { assert(is_upcall_stub(), "must be upcall stub"); return (UpcallStub*) this; } 211 RuntimeStub* as_runtime_stub() const { assert(is_runtime_stub(), "must be runtime blob"); return (RuntimeStub*) this; } 212 213 // Boundaries 214 address header_begin() const { return (address) this; } 215 address header_end() const { return ((address) this) + _header_size; } 216 address content_begin() const { return (address) header_begin() + _content_offset; } 217 address content_end() const { return (address) header_begin() + _data_offset; } 218 address code_begin() const { return (address) header_begin() + _code_offset; } 219 address code_end() const { return (address) header_begin() + _data_offset; } 220 address data_begin() const { return (address) header_begin() + _data_offset; } 221 address data_end() const { return (address) header_begin() + _size; } 222 address blob_end() const { return (address) header_begin() + _size; } 223 // code_end == content_end is true for all types of blobs for now, it is also checked in the constructor 224 225 int mutable_data_size() const { return _mutable_data_size; } 226 address mutable_data_begin() const { return _mutable_data; } 227 address mutable_data_end() const { return _mutable_data + _mutable_data_size; } 228 229 relocInfo* relocation_begin() const { return (relocInfo*)_mutable_data; } 230 relocInfo* relocation_end() const { return (relocInfo*)((address)relocation_begin() + _relocation_size); } 231 232 // Offsets 233 int content_offset() const { return _content_offset; } 234 int code_offset() const { return _code_offset; } 235 236 // This field holds the beginning of the const section in the old code buffer. 237 // It is needed to fix relocations of pc-relative loads when resizing the 238 // the constant pool or moving it. 239 S390_ONLY(address ctable_begin() const { return header_begin() + _ctable_offset; }) 240 void set_ctable_begin(address ctable) { S390_ONLY(_ctable_offset = ctable - header_begin();) } 241 242 // Sizes 243 int size() const { return _size; } 244 int header_size() const { return _header_size; } 245 int relocation_size() const { return pointer_delta_as_int((address) relocation_end(), (address) relocation_begin()); } 246 int content_size() const { return pointer_delta_as_int(content_end(), content_begin()); } 247 int code_size() const { return pointer_delta_as_int(code_end(), code_begin()); } 248 249 // Only used from CodeCache::free_unused_tail() after the Interpreter blob was trimmed 250 void adjust_size(size_t used) { 251 _size = (int)used; 252 _data_offset = _size; 253 } 254 255 // Containment 256 bool blob_contains(address addr) const { return header_begin() <= addr && addr < blob_end(); } 257 bool code_contains(address addr) const { return code_begin() <= addr && addr < code_end(); } 258 bool contains(address addr) const { return content_begin() <= addr && addr < content_end(); } 259 bool is_frame_complete_at(address addr) const { return _frame_complete_offset != CodeOffsets::frame_never_safe && 260 code_contains(addr) && addr >= code_begin() + _frame_complete_offset; } 261 int frame_complete_offset() const { return _frame_complete_offset; } 262 263 // OopMap for frame 264 ImmutableOopMapSet* oop_maps() const { return _oop_maps; } 265 void set_oop_maps(OopMapSet* p); 266 void set_oop_maps(ImmutableOopMapSet* p) { _oop_maps = p; } 267 268 const ImmutableOopMap* oop_map_for_slot(int slot, address return_address) const; 269 const ImmutableOopMap* oop_map_for_return_address(address return_address) const; 270 271 // Frame support. Sizes are in word units. 272 int frame_size() const { return _frame_size; } 273 void set_frame_size(int size) { _frame_size = size; } 274 275 // Returns true, if the next frame is responsible for GC'ing oops passed as arguments 276 bool caller_must_gc_arguments(JavaThread* thread) const { return _caller_must_gc_arguments; } 277 278 // Naming 279 const char* name() const { return _name; } 280 void set_name(const char* name) { _name = name; } 281 282 // Debugging 283 void verify(); 284 void print() const; 285 void print_on(outputStream* st) const; 286 void print_value_on(outputStream* st) const; 287 288 void dump_for_addr(address addr, outputStream* st, bool verbose) const; 289 void print_code_on(outputStream* st); 290 291 // Print to stream, any comments associated with offset. 292 void print_block_comment(outputStream* stream, address block_begin) const; 293 294 #ifndef PRODUCT 295 AsmRemarks &asm_remarks() { return _asm_remarks; } 296 DbgStrings &dbg_strings() { return _dbg_strings; } 297 298 void use_remarks(AsmRemarks &remarks) { _asm_remarks.share(remarks); } 299 void use_strings(DbgStrings &strings) { _dbg_strings.share(strings); } 300 #endif 301 302 void copy_to(address buffer) { 303 memcpy(buffer, this, this->size()); 304 } 305 306 // methods to archive a blob into AOT code cache 307 void prepare_for_archiving(); 308 static void archive_blob(CodeBlob* blob, address archive_buffer); 309 310 // methods to restore a blob from AOT code cache into the CodeCache 311 void post_restore(); 312 CodeBlob* restore(address code_cache_buffer, const char* name, address archived_reloc_data, ImmutableOopMapSet* archived_oop_maps); 313 static CodeBlob* create(CodeBlob* archived_blob, const char* name, address archived_reloc_data, ImmutableOopMapSet* archived_oop_maps); 314 }; 315 316 //---------------------------------------------------------------------------------------------------- 317 // RuntimeBlob: used for non-compiled method code (adapters, stubs, blobs) 318 319 class RuntimeBlob : public CodeBlob { 320 friend class VMStructs; 321 public: 322 323 // Creation 324 // a) simple CodeBlob 325 RuntimeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size) 326 : CodeBlob(name, kind, size, header_size) 327 {} 328 329 // b) full CodeBlob 330 // frame_complete is the offset from the beginning of the instructions 331 // to where the frame setup (from stackwalk viewpoint) is complete. 332 RuntimeBlob( 333 const char* name, 334 CodeBlobKind kind, 335 CodeBuffer* cb, 336 int size, 337 uint16_t header_size, 338 int16_t frame_complete, 339 int frame_size, 340 OopMapSet* oop_maps, 341 bool caller_must_gc_arguments = false 342 ); 343 344 static void free(RuntimeBlob* blob); 345 346 // Deal with Disassembler, VTune, Forte, JvmtiExport, MemoryService. 347 static void trace_new_stub(RuntimeBlob* blob, const char* name1, const char* name2 = ""); 348 349 class Vptr : public CodeBlob::Vptr { 350 }; 351 }; 352 353 class WhiteBox; 354 //---------------------------------------------------------------------------------------------------- 355 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc. 356 357 class BufferBlob: public RuntimeBlob { 358 friend class VMStructs; 359 friend class AdapterBlob; 360 friend class VtableBlob; 361 friend class MethodHandlesAdapterBlob; 362 friend class UpcallStub; 363 friend class WhiteBox; 364 365 private: 366 // Creation support 367 BufferBlob(const char* name, CodeBlobKind kind, int size); 368 BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size); 369 370 void* operator new(size_t s, unsigned size) throw(); 371 372 public: 373 // Creation 374 static BufferBlob* create(const char* name, uint buffer_size); 375 static BufferBlob* create(const char* name, CodeBuffer* cb); 376 377 static void free(BufferBlob* buf); 378 379 void print_on_impl(outputStream* st) const; 380 void print_value_on_impl(outputStream* st) const; 381 382 class Vptr : public RuntimeBlob::Vptr { 383 void print_on(const CodeBlob* instance, outputStream* st) const override { 384 ((const BufferBlob*)instance)->print_on_impl(st); 385 } 386 void print_value_on(const CodeBlob* instance, outputStream* st) const override { 387 ((const BufferBlob*)instance)->print_value_on_impl(st); 388 } 389 }; 390 391 static const Vptr _vpntr; 392 }; 393 394 395 //---------------------------------------------------------------------------------------------------- 396 // AdapterBlob: used to hold C2I/I2C adapters 397 398 class AdapterBlob: public BufferBlob { 399 private: 400 AdapterBlob(int size, CodeBuffer* cb); 401 402 public: 403 // Creation 404 static AdapterBlob* create(CodeBuffer* cb); 405 }; 406 407 //--------------------------------------------------------------------------------------------------- 408 class VtableBlob: public BufferBlob { 409 private: 410 VtableBlob(const char*, int); 411 412 void* operator new(size_t s, unsigned size) throw(); 413 414 public: 415 // Creation 416 static VtableBlob* create(const char* name, int buffer_size); 417 }; 418 419 //---------------------------------------------------------------------------------------------------- 420 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters 421 422 class MethodHandlesAdapterBlob: public BufferBlob { 423 private: 424 MethodHandlesAdapterBlob(int size): BufferBlob("MethodHandles adapters", CodeBlobKind::MHAdapter, size) {} 425 426 public: 427 // Creation 428 static MethodHandlesAdapterBlob* create(int buffer_size); 429 }; 430 431 432 //---------------------------------------------------------------------------------------------------- 433 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine 434 435 class RuntimeStub: public RuntimeBlob { 436 friend class VMStructs; 437 private: 438 // Creation support 439 RuntimeStub( 440 const char* name, 441 CodeBuffer* cb, 442 int size, 443 int16_t frame_complete, 444 int frame_size, 445 OopMapSet* oop_maps, 446 bool caller_must_gc_arguments 447 ); 448 449 void* operator new(size_t s, unsigned size) throw(); 450 451 public: 452 // Creation 453 static RuntimeStub* new_runtime_stub( 454 const char* stub_name, 455 CodeBuffer* cb, 456 int16_t frame_complete, 457 int frame_size, 458 OopMapSet* oop_maps, 459 bool caller_must_gc_arguments, 460 bool alloc_fail_is_fatal=true 461 ); 462 463 static void free(RuntimeStub* stub) { RuntimeBlob::free(stub); } 464 465 address entry_point() const { return code_begin(); } 466 467 void print_on_impl(outputStream* st) const; 468 void print_value_on_impl(outputStream* st) const; 469 470 class Vptr : public RuntimeBlob::Vptr { 471 void print_on(const CodeBlob* instance, outputStream* st) const override { 472 instance->as_runtime_stub()->print_on_impl(st); 473 } 474 void print_value_on(const CodeBlob* instance, outputStream* st) const override { 475 instance->as_runtime_stub()->print_value_on_impl(st); 476 } 477 }; 478 479 static const Vptr _vpntr; 480 }; 481 482 483 //---------------------------------------------------------------------------------------------------- 484 // Super-class for all blobs that exist in only one instance. Implements default behaviour. 485 486 class SingletonBlob: public RuntimeBlob { 487 friend class VMStructs; 488 489 protected: 490 void* operator new(size_t s, unsigned size, bool alloc_fail_is_fatal=true) throw(); 491 492 public: 493 SingletonBlob( 494 const char* name, 495 CodeBlobKind kind, 496 CodeBuffer* cb, 497 int size, 498 uint16_t header_size, 499 int frame_size, 500 OopMapSet* oop_maps 501 ) 502 : RuntimeBlob(name, kind, cb, size, header_size, CodeOffsets::frame_never_safe, frame_size, oop_maps) 503 {}; 504 505 address entry_point() { return code_begin(); } 506 507 void print_on_impl(outputStream* st) const; 508 void print_value_on_impl(outputStream* st) const; 509 510 class Vptr : public RuntimeBlob::Vptr { 511 void print_on(const CodeBlob* instance, outputStream* st) const override { 512 ((const SingletonBlob*)instance)->print_on_impl(st); 513 } 514 void print_value_on(const CodeBlob* instance, outputStream* st) const override { 515 ((const SingletonBlob*)instance)->print_value_on_impl(st); 516 } 517 }; 518 519 static const Vptr _vpntr; 520 }; 521 522 523 //---------------------------------------------------------------------------------------------------- 524 // DeoptimizationBlob 525 526 class DeoptimizationBlob: public SingletonBlob { 527 friend class VMStructs; 528 friend class JVMCIVMStructs; 529 private: 530 int _unpack_offset; 531 int _unpack_with_exception; 532 int _unpack_with_reexecution; 533 534 int _unpack_with_exception_in_tls; 535 536 #if INCLUDE_JVMCI 537 // Offsets when JVMCI calls uncommon_trap. 538 int _uncommon_trap_offset; 539 int _implicit_exception_uncommon_trap_offset; 540 #endif 541 542 // Creation support 543 DeoptimizationBlob( 544 CodeBuffer* cb, 545 int size, 546 OopMapSet* oop_maps, 547 int unpack_offset, 548 int unpack_with_exception_offset, 549 int unpack_with_reexecution_offset, 550 int frame_size 551 ); 552 553 public: 554 // Creation 555 static DeoptimizationBlob* create( 556 CodeBuffer* cb, 557 OopMapSet* oop_maps, 558 int unpack_offset, 559 int unpack_with_exception_offset, 560 int unpack_with_reexecution_offset, 561 int frame_size 562 ); 563 564 address unpack() const { return code_begin() + _unpack_offset; } 565 address unpack_with_exception() const { return code_begin() + _unpack_with_exception; } 566 address unpack_with_reexecution() const { return code_begin() + _unpack_with_reexecution; } 567 568 // Alternate entry point for C1 where the exception and issuing pc 569 // are in JavaThread::_exception_oop and JavaThread::_exception_pc 570 // instead of being in registers. This is needed because C1 doesn't 571 // model exception paths in a way that keeps these registers free so 572 // there may be live values in those registers during deopt. 573 void set_unpack_with_exception_in_tls_offset(int offset) { 574 _unpack_with_exception_in_tls = offset; 575 assert(code_contains(code_begin() + _unpack_with_exception_in_tls), "must be PC inside codeblob"); 576 } 577 address unpack_with_exception_in_tls() const { return code_begin() + _unpack_with_exception_in_tls; } 578 579 #if INCLUDE_JVMCI 580 // Offsets when JVMCI calls uncommon_trap. 581 void set_uncommon_trap_offset(int offset) { 582 _uncommon_trap_offset = offset; 583 assert(contains(code_begin() + _uncommon_trap_offset), "must be PC inside codeblob"); 584 } 585 address uncommon_trap() const { return code_begin() + _uncommon_trap_offset; } 586 587 void set_implicit_exception_uncommon_trap_offset(int offset) { 588 _implicit_exception_uncommon_trap_offset = offset; 589 assert(contains(code_begin() + _implicit_exception_uncommon_trap_offset), "must be PC inside codeblob"); 590 } 591 address implicit_exception_uncommon_trap() const { return code_begin() + _implicit_exception_uncommon_trap_offset; } 592 #endif // INCLUDE_JVMCI 593 594 void print_value_on_impl(outputStream* st) const; 595 596 class Vptr : public SingletonBlob::Vptr { 597 void print_value_on(const CodeBlob* instance, outputStream* st) const override { 598 ((const DeoptimizationBlob*)instance)->print_value_on_impl(st); 599 } 600 }; 601 602 static const Vptr _vpntr; 603 }; 604 605 606 //---------------------------------------------------------------------------------------------------- 607 // UncommonTrapBlob (currently only used by Compiler 2) 608 609 #ifdef COMPILER2 610 611 class UncommonTrapBlob: public SingletonBlob { 612 friend class VMStructs; 613 private: 614 // Creation support 615 UncommonTrapBlob( 616 CodeBuffer* cb, 617 int size, 618 OopMapSet* oop_maps, 619 int frame_size 620 ); 621 622 public: 623 // Creation 624 static UncommonTrapBlob* create( 625 CodeBuffer* cb, 626 OopMapSet* oop_maps, 627 int frame_size 628 ); 629 }; 630 631 632 //---------------------------------------------------------------------------------------------------- 633 // ExceptionBlob: used for exception unwinding in compiled code (currently only used by Compiler 2) 634 635 class ExceptionBlob: public SingletonBlob { 636 friend class VMStructs; 637 private: 638 // Creation support 639 ExceptionBlob( 640 CodeBuffer* cb, 641 int size, 642 OopMapSet* oop_maps, 643 int frame_size 644 ); 645 646 public: 647 // Creation 648 static ExceptionBlob* create( 649 CodeBuffer* cb, 650 OopMapSet* oop_maps, 651 int frame_size 652 ); 653 654 void post_restore_impl() { 655 trace_new_stub(this, "ExceptionBlob"); 656 } 657 658 class Vptr : public SingletonBlob::Vptr { 659 void post_restore(CodeBlob* instance) const override { 660 ((ExceptionBlob*)instance)->post_restore_impl(); 661 } 662 }; 663 664 static const Vptr _vpntr; 665 }; 666 #endif // COMPILER2 667 668 669 //---------------------------------------------------------------------------------------------------- 670 // SafepointBlob: handles illegal_instruction exceptions during a safepoint 671 672 class SafepointBlob: public SingletonBlob { 673 friend class VMStructs; 674 private: 675 // Creation support 676 SafepointBlob( 677 CodeBuffer* cb, 678 int size, 679 OopMapSet* oop_maps, 680 int frame_size 681 ); 682 683 public: 684 // Creation 685 static SafepointBlob* create( 686 CodeBuffer* cb, 687 OopMapSet* oop_maps, 688 int frame_size 689 ); 690 }; 691 692 //---------------------------------------------------------------------------------------------------- 693 694 class UpcallLinker; 695 696 // A (Panama) upcall stub. Not used by JNI. 697 class UpcallStub: public RuntimeBlob { 698 friend class VMStructs; 699 friend class UpcallLinker; 700 private: 701 jobject _receiver; 702 ByteSize _frame_data_offset; 703 704 UpcallStub(const char* name, CodeBuffer* cb, int size, jobject receiver, ByteSize frame_data_offset); 705 706 void* operator new(size_t s, unsigned size) throw(); 707 708 struct FrameData { 709 JavaFrameAnchor jfa; 710 JavaThread* thread; 711 JNIHandleBlock* old_handles; 712 JNIHandleBlock* new_handles; 713 }; 714 715 // defined in frame_ARCH.cpp 716 FrameData* frame_data_for_frame(const frame& frame) const; 717 public: 718 // Creation 719 static UpcallStub* create(const char* name, CodeBuffer* cb, jobject receiver, ByteSize frame_data_offset); 720 721 static void free(UpcallStub* blob); 722 723 jobject receiver() { return _receiver; } 724 725 JavaFrameAnchor* jfa_for_frame(const frame& frame) const; 726 727 // GC support 728 void oops_do(OopClosure* f, const frame& frame); 729 730 void print_on_impl(outputStream* st) const; 731 void print_value_on_impl(outputStream* st) const; 732 733 class Vptr : public RuntimeBlob::Vptr { 734 void print_on(const CodeBlob* instance, outputStream* st) const override { 735 instance->as_upcall_stub()->print_on_impl(st); 736 } 737 void print_value_on(const CodeBlob* instance, outputStream* st) const override { 738 instance->as_upcall_stub()->print_value_on_impl(st); 739 } 740 }; 741 742 static const Vptr _vpntr; 743 }; 744 745 #endif // SHARE_CODE_CODEBLOB_HPP