codeBlob.cpp revision 2273:1d1603768966
1215976Sjmallett/* 2232812Sjmallett * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. 3215976Sjmallett * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4215976Sjmallett * 5215976Sjmallett * This code is free software; you can redistribute it and/or modify it 6215976Sjmallett * under the terms of the GNU General Public License version 2 only, as 7215976Sjmallett * published by the Free Software Foundation. 8215976Sjmallett * 9215976Sjmallett * This code is distributed in the hope that it will be useful, but WITHOUT 10215976Sjmallett * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11215976Sjmallett * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12215976Sjmallett * version 2 for more details (a copy is included in the LICENSE file that 13215976Sjmallett * accompanied this code). 14215976Sjmallett * 15215976Sjmallett * You should have received a copy of the GNU General Public License version 16215976Sjmallett * 2 along with this work; if not, write to the Free Software Foundation, 17215976Sjmallett * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18232812Sjmallett * 19215976Sjmallett * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20215976Sjmallett * or visit www.oracle.com if you need additional information or have any 21215976Sjmallett * questions. 22215976Sjmallett * 23215976Sjmallett */ 24215976Sjmallett 25215976Sjmallett#include "precompiled.hpp" 26215976Sjmallett#include "code/codeBlob.hpp" 27215976Sjmallett#include "code/codeCache.hpp" 28215976Sjmallett#include "code/relocInfo.hpp" 29232812Sjmallett#include "compiler/disassembler.hpp" 30215976Sjmallett#include "interpreter/bytecode.hpp" 31215976Sjmallett#include "memory/allocation.inline.hpp" 32215976Sjmallett#include "memory/heap.hpp" 33215976Sjmallett#include "oops/oop.inline.hpp" 34215976Sjmallett#include "prims/forte.hpp" 35215976Sjmallett#include "runtime/handles.inline.hpp" 36215976Sjmallett#include "runtime/interfaceSupport.hpp" 37215976Sjmallett#include "runtime/mutexLocker.hpp" 38215976Sjmallett#include "runtime/safepoint.hpp" 39215976Sjmallett#include "runtime/sharedRuntime.hpp" 40215976Sjmallett#include "runtime/vframe.hpp" 41215976Sjmallett#include "services/memoryService.hpp" 42215976Sjmallett#ifdef TARGET_ARCH_x86 43215976Sjmallett# include "nativeInst_x86.hpp" 44215976Sjmallett#endif 45215976Sjmallett#ifdef TARGET_ARCH_sparc 46215976Sjmallett# include "nativeInst_sparc.hpp" 47215976Sjmallett#endif 48215976Sjmallett#ifdef TARGET_ARCH_zero 49215976Sjmallett# include "nativeInst_zero.hpp" 50215976Sjmallett#endif 51215976Sjmallett#ifdef TARGET_ARCH_arm 52232812Sjmallett# include "nativeInst_arm.hpp" 53232812Sjmallett#endif 54215976Sjmallett#ifdef TARGET_ARCH_ppc 55215976Sjmallett# include "nativeInst_ppc.hpp" 56215976Sjmallett#endif 57215976Sjmallett#ifdef COMPILER1 58215976Sjmallett#include "c1/c1_Runtime1.hpp" 59215976Sjmallett#endif 60215976Sjmallett 61232812Sjmallettunsigned int align_code_offset(int offset) { 62232812Sjmallett // align the size to CodeEntryAlignment 63232812Sjmallett return 64232812Sjmallett ((offset + (int)CodeHeap::header_size() + (CodeEntryAlignment-1)) & ~(CodeEntryAlignment-1)) 65232812Sjmallett - (int)CodeHeap::header_size(); 66215976Sjmallett} 67215976Sjmallett 68215976Sjmallett 69215976Sjmallett// This must be consistent with the CodeBlob constructor's layout actions. 70215976Sjmallettunsigned int CodeBlob::allocation_size(CodeBuffer* cb, int header_size) { 71215976Sjmallett unsigned int size = header_size; 72215976Sjmallett size += round_to(cb->total_relocation_size(), oopSize); 73215976Sjmallett // align the size to CodeEntryAlignment 74215976Sjmallett size = align_code_offset(size); 75215976Sjmallett size += round_to(cb->total_content_size(), oopSize); 76215976Sjmallett size += round_to(cb->total_oop_size(), oopSize); 77215976Sjmallett return size; 78232812Sjmallett} 79232812Sjmallett 80232812Sjmallett 81232812Sjmallett// Creates a simple CodeBlob. Sets up the size of the different regions. 82232812SjmallettCodeBlob::CodeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size) { 83215976Sjmallett assert(size == round_to(size, oopSize), "unaligned size"); 84215976Sjmallett assert(locs_size == round_to(locs_size, oopSize), "unaligned size"); 85215976Sjmallett assert(header_size == round_to(header_size, oopSize), "unaligned size"); 86215976Sjmallett assert(!UseRelocIndex, "no space allocated for reloc index yet"); 87215976Sjmallett 88215976Sjmallett // Note: If UseRelocIndex is enabled, there needs to be (at least) one 89215976Sjmallett // extra word for the relocation information, containing the reloc 90215976Sjmallett // index table length. Unfortunately, the reloc index table imple- 91215976Sjmallett // mentation is not easily understandable and thus it is not clear 92215976Sjmallett // what exactly the format is supposed to be. For now, we just turn 93215976Sjmallett // off the use of this table (gri 7/6/2000). 94215976Sjmallett 95232812Sjmallett _name = name; 96232812Sjmallett _size = size; 97232812Sjmallett _frame_complete_offset = frame_complete; 98232812Sjmallett _header_size = header_size; 99232812Sjmallett _relocation_size = locs_size; 100215976Sjmallett _content_offset = align_code_offset(header_size + _relocation_size); 101215976Sjmallett _code_offset = _content_offset; 102215976Sjmallett _data_offset = size; 103215976Sjmallett _frame_size = 0; 104215976Sjmallett set_oop_maps(NULL); 105215976Sjmallett} 106215976Sjmallett 107215976Sjmallett 108215976Sjmallett// Creates a CodeBlob from a CodeBuffer. Sets up the size of the different regions, 109215976Sjmallett// and copy code and relocation info. 110215976SjmallettCodeBlob::CodeBlob( 111215976Sjmallett const char* name, 112232812Sjmallett CodeBuffer* cb, 113232812Sjmallett int header_size, 114232812Sjmallett int size, 115232812Sjmallett int frame_complete, 116232812Sjmallett int frame_size, 117215976Sjmallett OopMapSet* oop_maps 118215976Sjmallett) { 119215976Sjmallett assert(size == round_to(size, oopSize), "unaligned size"); 120215976Sjmallett assert(header_size == round_to(header_size, oopSize), "unaligned size"); 121215976Sjmallett 122215976Sjmallett _name = name; 123215976Sjmallett _size = size; 124215976Sjmallett _frame_complete_offset = frame_complete; 125215976Sjmallett _header_size = header_size; 126215976Sjmallett _relocation_size = round_to(cb->total_relocation_size(), oopSize); 127215976Sjmallett _content_offset = align_code_offset(header_size + _relocation_size); 128215976Sjmallett _code_offset = _content_offset + cb->total_offset_of(cb->insts()); 129232812Sjmallett _data_offset = _content_offset + round_to(cb->total_content_size(), oopSize); 130232812Sjmallett assert(_data_offset <= size, "codeBlob is too small"); 131232812Sjmallett 132232812Sjmallett cb->copy_code_and_locs_to(this); 133232812Sjmallett set_oop_maps(oop_maps); 134215976Sjmallett _frame_size = frame_size; 135215976Sjmallett#ifdef COMPILER1 136215976Sjmallett // probably wrong for tiered 137215976Sjmallett assert(_frame_size >= -1, "must use frame size or -1 for runtime stubs"); 138215976Sjmallett#endif // COMPILER1 139215976Sjmallett} 140215976Sjmallett 141215976Sjmallett 142215976Sjmallettvoid CodeBlob::set_oop_maps(OopMapSet* p) { 143215976Sjmallett // Danger Will Robinson! This method allocates a big 144215976Sjmallett // chunk of memory, its your job to free it. 145215976Sjmallett if (p != NULL) { 146232812Sjmallett // We need to allocate a chunk big enough to hold the OopMapSet and all of its OopMaps 147232812Sjmallett _oop_maps = (OopMapSet* )NEW_C_HEAP_ARRAY(unsigned char, p->heap_size()); 148232812Sjmallett p->copy_to((address)_oop_maps); 149232812Sjmallett } else { 150232812Sjmallett _oop_maps = NULL; 151215976Sjmallett } 152215976Sjmallett} 153215976Sjmallett 154215976Sjmallett 155215976Sjmallettvoid CodeBlob::flush() { 156215976Sjmallett if (_oop_maps) { 157215976Sjmallett FREE_C_HEAP_ARRAY(unsigned char, _oop_maps); 158215976Sjmallett _oop_maps = NULL; 159215976Sjmallett } 160215976Sjmallett _comments.free(); 161215976Sjmallett} 162215976Sjmallett 163232812Sjmallett 164232812SjmallettOopMap* CodeBlob::oop_map_for_return_address(address return_address) { 165232812Sjmallett assert(oop_maps() != NULL, "nope"); 166232812Sjmallett return oop_maps()->find_map_at_offset((intptr_t) return_address - (intptr_t) code_begin()); 167232812Sjmallett} 168215976Sjmallett 169215976Sjmallett 170215976Sjmallett//---------------------------------------------------------------------------------------------------- 171215976Sjmallett// Implementation of BufferBlob 172215976Sjmallett 173215976Sjmallett 174215976SjmallettBufferBlob::BufferBlob(const char* name, int size) 175215976Sjmallett: CodeBlob(name, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, /*locs_size:*/ 0) 176215976Sjmallett{} 177215976Sjmallett 178215976SjmallettBufferBlob* BufferBlob::create(const char* name, int buffer_size) { 179215976Sjmallett ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 180232812Sjmallett 181232812Sjmallett BufferBlob* blob = NULL; 182232812Sjmallett unsigned int size = sizeof(BufferBlob); 183232812Sjmallett // align the size to CodeEntryAlignment 184232812Sjmallett size = align_code_offset(size); 185215976Sjmallett size += round_to(buffer_size, oopSize); 186215976Sjmallett assert(name != NULL, "must provide a name"); 187215976Sjmallett { 188215976Sjmallett MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 189215976Sjmallett blob = new (size) BufferBlob(name, size); 190215976Sjmallett } 191215976Sjmallett // Track memory usage statistic after releasing CodeCache_lock 192215976Sjmallett MemoryService::track_code_cache_memory_usage(); 193215976Sjmallett 194215976Sjmallett return blob; 195215976Sjmallett} 196215976Sjmallett 197232812Sjmallett 198232812SjmallettBufferBlob::BufferBlob(const char* name, int size, CodeBuffer* cb) 199232812Sjmallett : CodeBlob(name, cb, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, 0, NULL) 200232812Sjmallett{} 201232812Sjmallett 202215976SjmallettBufferBlob* BufferBlob::create(const char* name, CodeBuffer* cb) { 203215976Sjmallett ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 204215976Sjmallett 205215976Sjmallett BufferBlob* blob = NULL; 206215976Sjmallett unsigned int size = allocation_size(cb, sizeof(BufferBlob)); 207215976Sjmallett assert(name != NULL, "must provide a name"); 208215976Sjmallett { 209215976Sjmallett MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 210215976Sjmallett blob = new (size) BufferBlob(name, size, cb); 211215976Sjmallett } 212215976Sjmallett // Track memory usage statistic after releasing CodeCache_lock 213215976Sjmallett MemoryService::track_code_cache_memory_usage(); 214232812Sjmallett 215232812Sjmallett return blob; 216232812Sjmallett} 217232812Sjmallett 218232812Sjmallett 219215976Sjmallettvoid* BufferBlob::operator new(size_t s, unsigned size) { 220215976Sjmallett void* p = CodeCache::allocate(size); 221215976Sjmallett return p; 222215976Sjmallett} 223215976Sjmallett 224215976Sjmallett 225215976Sjmallettvoid BufferBlob::free( BufferBlob *blob ) { 226215976Sjmallett ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 227215976Sjmallett { 228215976Sjmallett MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 229215976Sjmallett CodeCache::free((CodeBlob*)blob); 230215976Sjmallett } 231232812Sjmallett // Track memory usage statistic after releasing CodeCache_lock 232232812Sjmallett MemoryService::track_code_cache_memory_usage(); 233232812Sjmallett} 234232812Sjmallett 235232812Sjmallett 236215976Sjmallett//---------------------------------------------------------------------------------------------------- 237215976Sjmallett// Implementation of AdapterBlob 238215976Sjmallett 239215976SjmallettAdapterBlob::AdapterBlob(int size, CodeBuffer* cb) : 240215976Sjmallett BufferBlob("I2C/C2I adapters", size, cb) { 241215976Sjmallett CodeCache::commit(this); 242215976Sjmallett} 243215976Sjmallett 244215976SjmallettAdapterBlob* AdapterBlob::create(CodeBuffer* cb) { 245215976Sjmallett ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 246215976Sjmallett 247215976Sjmallett AdapterBlob* blob = NULL; 248232812Sjmallett unsigned int size = allocation_size(cb, sizeof(AdapterBlob)); 249232812Sjmallett { 250232812Sjmallett MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 251232812Sjmallett blob = new (size) AdapterBlob(size, cb); 252232812Sjmallett } 253215976Sjmallett // Track memory usage statistic after releasing CodeCache_lock 254215976Sjmallett MemoryService::track_code_cache_memory_usage(); 255215976Sjmallett 256215976Sjmallett return blob; 257215976Sjmallett} 258215976Sjmallett 259215976Sjmallett 260215976Sjmallett//---------------------------------------------------------------------------------------------------- 261215976Sjmallett// Implementation of MethodHandlesAdapterBlob 262215976Sjmallett 263215976SjmallettMethodHandlesAdapterBlob* MethodHandlesAdapterBlob::create(int buffer_size) { 264215976Sjmallett ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 265232812Sjmallett 266232812Sjmallett MethodHandlesAdapterBlob* blob = NULL; 267232812Sjmallett unsigned int size = sizeof(MethodHandlesAdapterBlob); 268232812Sjmallett // align the size to CodeEntryAlignment 269232812Sjmallett size = align_code_offset(size); 270215976Sjmallett size += round_to(buffer_size, oopSize); 271215976Sjmallett { 272215976Sjmallett MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 273215976Sjmallett blob = new (size) MethodHandlesAdapterBlob(size); 274215976Sjmallett } 275215976Sjmallett // Track memory usage statistic after releasing CodeCache_lock 276215976Sjmallett MemoryService::track_code_cache_memory_usage(); 277215976Sjmallett 278215976Sjmallett return blob; 279215976Sjmallett} 280215976Sjmallett 281215976Sjmallett 282232812Sjmallett//---------------------------------------------------------------------------------------------------- 283232812Sjmallett// Implementation of RuntimeStub 284232812Sjmallett 285232812SjmallettRuntimeStub::RuntimeStub( 286232812Sjmallett const char* name, 287215976Sjmallett CodeBuffer* cb, 288215976Sjmallett int size, 289215976Sjmallett int frame_complete, 290215976Sjmallett int frame_size, 291215976Sjmallett OopMapSet* oop_maps, 292215976Sjmallett bool caller_must_gc_arguments 293215976Sjmallett) 294215976Sjmallett: CodeBlob(name, cb, sizeof(RuntimeStub), size, frame_complete, frame_size, oop_maps) 295215976Sjmallett{ 296215976Sjmallett _caller_must_gc_arguments = caller_must_gc_arguments; 297215976Sjmallett} 298215976Sjmallett 299232812Sjmallett 300232812SjmallettRuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name, 301232812Sjmallett CodeBuffer* cb, 302232812Sjmallett int frame_complete, 303232812Sjmallett int frame_size, 304215976Sjmallett OopMapSet* oop_maps, 305215976Sjmallett bool caller_must_gc_arguments) 306215976Sjmallett{ 307215976Sjmallett RuntimeStub* stub = NULL; 308215976Sjmallett ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 309215976Sjmallett { 310215976Sjmallett MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 311215976Sjmallett unsigned int size = allocation_size(cb, sizeof(RuntimeStub)); 312215976Sjmallett stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments); 313215976Sjmallett } 314215976Sjmallett 315215976Sjmallett // Do not hold the CodeCache lock during name formatting. 316232812Sjmallett if (stub != NULL) { 317232812Sjmallett char stub_id[256]; 318232812Sjmallett jio_snprintf(stub_id, sizeof(stub_id), "RuntimeStub - %s", stub_name); 319232812Sjmallett if (PrintStubCode) { 320232812Sjmallett tty->print_cr("Decoding %s " INTPTR_FORMAT, stub_id, stub); 321215976Sjmallett Disassembler::decode(stub->code_begin(), stub->code_end()); 322215976Sjmallett } 323215976Sjmallett Forte::register_stub(stub_id, stub->code_begin(), stub->code_end()); 324215976Sjmallett 325215976Sjmallett if (JvmtiExport::should_post_dynamic_code_generated()) { 326215976Sjmallett JvmtiExport::post_dynamic_code_generated(stub_name, stub->code_begin(), stub->code_end()); 327215976Sjmallett } 328215976Sjmallett } 329215976Sjmallett 330215976Sjmallett // Track memory usage statistic after releasing CodeCache_lock 331215976Sjmallett MemoryService::track_code_cache_memory_usage(); 332215976Sjmallett 333232812Sjmallett return stub; 334232812Sjmallett} 335232812Sjmallett 336232812Sjmallett 337232812Sjmallettvoid* RuntimeStub::operator new(size_t s, unsigned size) { 338215976Sjmallett void* p = CodeCache::allocate(size); 339215976Sjmallett if (!p) fatal("Initial size of CodeCache is too small"); 340215976Sjmallett return p; 341215976Sjmallett} 342215976Sjmallett 343215976Sjmallett 344215976Sjmallett//---------------------------------------------------------------------------------------------------- 345215976Sjmallett// Implementation of DeoptimizationBlob 346215976Sjmallett 347215976SjmallettDeoptimizationBlob::DeoptimizationBlob( 348215976Sjmallett CodeBuffer* cb, 349215976Sjmallett int size, 350232812Sjmallett OopMapSet* oop_maps, 351232812Sjmallett int unpack_offset, 352232812Sjmallett int unpack_with_exception_offset, 353232812Sjmallett int unpack_with_reexecution_offset, 354232812Sjmallett int frame_size 355215976Sjmallett) 356215976Sjmallett: SingletonBlob("DeoptimizationBlob", cb, sizeof(DeoptimizationBlob), size, frame_size, oop_maps) 357215976Sjmallett{ 358215976Sjmallett _unpack_offset = unpack_offset; 359215976Sjmallett _unpack_with_exception = unpack_with_exception_offset; 360215976Sjmallett _unpack_with_reexecution = unpack_with_reexecution_offset; 361215976Sjmallett#ifdef COMPILER1 362215976Sjmallett _unpack_with_exception_in_tls = -1; 363215976Sjmallett#endif 364215976Sjmallett} 365215976Sjmallett 366215976Sjmallett 367232812SjmallettDeoptimizationBlob* DeoptimizationBlob::create( 368232812Sjmallett CodeBuffer* cb, 369232812Sjmallett OopMapSet* oop_maps, 370232812Sjmallett int unpack_offset, 371232812Sjmallett int unpack_with_exception_offset, 372215976Sjmallett int unpack_with_reexecution_offset, 373215976Sjmallett int frame_size) 374215976Sjmallett{ 375215976Sjmallett DeoptimizationBlob* blob = NULL; 376215976Sjmallett ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 377215976Sjmallett { 378215976Sjmallett MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 379215976Sjmallett unsigned int size = allocation_size(cb, sizeof(DeoptimizationBlob)); 380215976Sjmallett blob = new (size) DeoptimizationBlob(cb, 381215976Sjmallett size, 382215976Sjmallett oop_maps, 383215976Sjmallett unpack_offset, 384232812Sjmallett unpack_with_exception_offset, 385232812Sjmallett unpack_with_reexecution_offset, 386232812Sjmallett frame_size); 387232812Sjmallett } 388232812Sjmallett 389215976Sjmallett // Do not hold the CodeCache lock during name formatting. 390215976Sjmallett if (blob != NULL) { 391215976Sjmallett char blob_id[256]; 392215976Sjmallett jio_snprintf(blob_id, sizeof(blob_id), "DeoptimizationBlob@" PTR_FORMAT, blob->code_begin()); 393215976Sjmallett if (PrintStubCode) { 394215976Sjmallett tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob); 395215976Sjmallett Disassembler::decode(blob->code_begin(), blob->code_end()); 396215976Sjmallett } 397215976Sjmallett Forte::register_stub(blob_id, blob->code_begin(), blob->code_end()); 398215976Sjmallett 399215976Sjmallett if (JvmtiExport::should_post_dynamic_code_generated()) { 400215976Sjmallett JvmtiExport::post_dynamic_code_generated("DeoptimizationBlob", blob->code_begin(), blob->code_end()); 401232812Sjmallett } 402232812Sjmallett } 403232812Sjmallett 404232812Sjmallett // Track memory usage statistic after releasing CodeCache_lock 405232812Sjmallett MemoryService::track_code_cache_memory_usage(); 406215976Sjmallett 407215976Sjmallett return blob; 408215976Sjmallett} 409215976Sjmallett 410215976Sjmallett 411215976Sjmallettvoid* DeoptimizationBlob::operator new(size_t s, unsigned size) { 412215976Sjmallett void* p = CodeCache::allocate(size); 413215976Sjmallett if (!p) fatal("Initial size of CodeCache is too small"); 414215976Sjmallett return p; 415215976Sjmallett} 416215976Sjmallett 417215976Sjmallett//---------------------------------------------------------------------------------------------------- 418232812Sjmallett// Implementation of UncommonTrapBlob 419232812Sjmallett 420232812Sjmallett#ifdef COMPILER2 421232812SjmallettUncommonTrapBlob::UncommonTrapBlob( 422232812Sjmallett CodeBuffer* cb, 423215976Sjmallett int size, 424215976Sjmallett OopMapSet* oop_maps, 425215976Sjmallett int frame_size 426215976Sjmallett) 427215976Sjmallett: SingletonBlob("UncommonTrapBlob", cb, sizeof(UncommonTrapBlob), size, frame_size, oop_maps) 428215976Sjmallett{} 429215976Sjmallett 430215976Sjmallett 431215976SjmallettUncommonTrapBlob* UncommonTrapBlob::create( 432215976Sjmallett CodeBuffer* cb, 433215976Sjmallett OopMapSet* oop_maps, 434215976Sjmallett int frame_size) 435232812Sjmallett{ 436232812Sjmallett UncommonTrapBlob* blob = NULL; 437232812Sjmallett ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 438232812Sjmallett { 439232812Sjmallett MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 440215976Sjmallett unsigned int size = allocation_size(cb, sizeof(UncommonTrapBlob)); 441215976Sjmallett blob = new (size) UncommonTrapBlob(cb, size, oop_maps, frame_size); 442215976Sjmallett } 443215976Sjmallett 444215976Sjmallett // Do not hold the CodeCache lock during name formatting. 445215976Sjmallett if (blob != NULL) { 446215976Sjmallett char blob_id[256]; 447215976Sjmallett jio_snprintf(blob_id, sizeof(blob_id), "UncommonTrapBlob@" PTR_FORMAT, blob->code_begin()); 448215976Sjmallett if (PrintStubCode) { 449215976Sjmallett tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob); 450215976Sjmallett Disassembler::decode(blob->code_begin(), blob->code_end()); 451215976Sjmallett } 452232812Sjmallett Forte::register_stub(blob_id, blob->code_begin(), blob->code_end()); 453232812Sjmallett 454232812Sjmallett if (JvmtiExport::should_post_dynamic_code_generated()) { 455232812Sjmallett JvmtiExport::post_dynamic_code_generated("UncommonTrapBlob", blob->code_begin(), blob->code_end()); 456232812Sjmallett } 457215976Sjmallett } 458215976Sjmallett 459215976Sjmallett // Track memory usage statistic after releasing CodeCache_lock 460215976Sjmallett MemoryService::track_code_cache_memory_usage(); 461215976Sjmallett 462215976Sjmallett return blob; 463215976Sjmallett} 464215976Sjmallett 465215976Sjmallett 466215976Sjmallettvoid* UncommonTrapBlob::operator new(size_t s, unsigned size) { 467215976Sjmallett void* p = CodeCache::allocate(size); 468215976Sjmallett if (!p) fatal("Initial size of CodeCache is too small"); 469232812Sjmallett return p; 470232812Sjmallett} 471232812Sjmallett#endif // COMPILER2 472232812Sjmallett 473232812Sjmallett 474215976Sjmallett//---------------------------------------------------------------------------------------------------- 475215976Sjmallett// Implementation of ExceptionBlob 476215976Sjmallett 477215976Sjmallett#ifdef COMPILER2 478215976SjmallettExceptionBlob::ExceptionBlob( 479215976Sjmallett CodeBuffer* cb, 480215976Sjmallett int size, 481215976Sjmallett OopMapSet* oop_maps, 482215976Sjmallett int frame_size 483215976Sjmallett) 484215976Sjmallett: SingletonBlob("ExceptionBlob", cb, sizeof(ExceptionBlob), size, frame_size, oop_maps) 485215976Sjmallett{} 486232812Sjmallett 487232812Sjmallett 488232812SjmallettExceptionBlob* ExceptionBlob::create( 489232812Sjmallett CodeBuffer* cb, 490232812Sjmallett OopMapSet* oop_maps, 491215976Sjmallett int frame_size) 492215976Sjmallett{ 493215976Sjmallett ExceptionBlob* blob = NULL; 494215976Sjmallett ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 495215976Sjmallett { 496215976Sjmallett MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 497215976Sjmallett unsigned int size = allocation_size(cb, sizeof(ExceptionBlob)); 498215976Sjmallett blob = new (size) ExceptionBlob(cb, size, oop_maps, frame_size); 499215976Sjmallett } 500215976Sjmallett 501215976Sjmallett // We do not need to hold the CodeCache lock during name formatting 502215976Sjmallett if (blob != NULL) { 503232812Sjmallett char blob_id[256]; 504232812Sjmallett jio_snprintf(blob_id, sizeof(blob_id), "ExceptionBlob@" PTR_FORMAT, blob->code_begin()); 505232812Sjmallett if (PrintStubCode) { 506232812Sjmallett tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob); 507232812Sjmallett Disassembler::decode(blob->code_begin(), blob->code_end()); 508215976Sjmallett } 509215976Sjmallett Forte::register_stub(blob_id, blob->code_begin(), blob->code_end()); 510215976Sjmallett 511215976Sjmallett if (JvmtiExport::should_post_dynamic_code_generated()) { 512215976Sjmallett JvmtiExport::post_dynamic_code_generated("ExceptionBlob", blob->code_begin(), blob->code_end()); 513215976Sjmallett } 514215976Sjmallett } 515215976Sjmallett 516215976Sjmallett // Track memory usage statistic after releasing CodeCache_lock 517215976Sjmallett MemoryService::track_code_cache_memory_usage(); 518215976Sjmallett 519215976Sjmallett return blob; 520232812Sjmallett} 521232812Sjmallett 522232812Sjmallett 523232812Sjmallettvoid* ExceptionBlob::operator new(size_t s, unsigned size) { 524232812Sjmallett void* p = CodeCache::allocate(size); 525215976Sjmallett if (!p) fatal("Initial size of CodeCache is too small"); 526215976Sjmallett return p; 527215976Sjmallett} 528215976Sjmallett#endif // COMPILER2 529215976Sjmallett 530215976Sjmallett 531215976Sjmallett//---------------------------------------------------------------------------------------------------- 532215976Sjmallett// Implementation of SafepointBlob 533215976Sjmallett 534215976SjmallettSafepointBlob::SafepointBlob( 535215976Sjmallett CodeBuffer* cb, 536215976Sjmallett int size, 537232812Sjmallett OopMapSet* oop_maps, 538232812Sjmallett int frame_size 539232812Sjmallett) 540232812Sjmallett: SingletonBlob("SafepointBlob", cb, sizeof(SafepointBlob), size, frame_size, oop_maps) 541232812Sjmallett{} 542215976Sjmallett 543215976Sjmallett 544215976SjmallettSafepointBlob* SafepointBlob::create( 545215976Sjmallett CodeBuffer* cb, 546215976Sjmallett OopMapSet* oop_maps, 547215976Sjmallett int frame_size) 548215976Sjmallett{ 549215976Sjmallett SafepointBlob* blob = NULL; 550215976Sjmallett ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 551215976Sjmallett { 552215976Sjmallett MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 553215976Sjmallett unsigned int size = allocation_size(cb, sizeof(SafepointBlob)); 554232812Sjmallett blob = new (size) SafepointBlob(cb, size, oop_maps, frame_size); 555232812Sjmallett } 556232812Sjmallett 557232812Sjmallett // We do not need to hold the CodeCache lock during name formatting. 558232812Sjmallett if (blob != NULL) { 559215976Sjmallett char blob_id[256]; 560215976Sjmallett jio_snprintf(blob_id, sizeof(blob_id), "SafepointBlob@" PTR_FORMAT, blob->code_begin()); 561215976Sjmallett if (PrintStubCode) { 562215976Sjmallett tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob); 563215976Sjmallett Disassembler::decode(blob->code_begin(), blob->code_end()); 564215976Sjmallett } 565215976Sjmallett Forte::register_stub(blob_id, blob->code_begin(), blob->code_end()); 566215976Sjmallett 567215976Sjmallett if (JvmtiExport::should_post_dynamic_code_generated()) { 568215976Sjmallett JvmtiExport::post_dynamic_code_generated("SafepointBlob", blob->code_begin(), blob->code_end()); 569215976Sjmallett } 570215976Sjmallett } 571232812Sjmallett 572232812Sjmallett // Track memory usage statistic after releasing CodeCache_lock 573232812Sjmallett MemoryService::track_code_cache_memory_usage(); 574232812Sjmallett 575232812Sjmallett return blob; 576215976Sjmallett} 577215976Sjmallett 578215976Sjmallett 579215976Sjmallettvoid* SafepointBlob::operator new(size_t s, unsigned size) { 580215976Sjmallett void* p = CodeCache::allocate(size); 581215976Sjmallett if (!p) fatal("Initial size of CodeCache is too small"); 582215976Sjmallett return p; 583215976Sjmallett} 584215976Sjmallett 585215976Sjmallett 586215976Sjmallett//---------------------------------------------------------------------------------------------------- 587215976Sjmallett// Verification and printing 588232812Sjmallett 589232812Sjmallettvoid CodeBlob::verify() { 590232812Sjmallett ShouldNotReachHere(); 591232812Sjmallett} 592232812Sjmallett 593215976Sjmallettvoid CodeBlob::print_on(outputStream* st) const { 594215976Sjmallett st->print_cr("[CodeBlob (" INTPTR_FORMAT ")]", this); 595215976Sjmallett st->print_cr("Framesize: %d", _frame_size); 596215976Sjmallett} 597215976Sjmallett 598215976Sjmallettvoid CodeBlob::print_value_on(outputStream* st) const { 599215976Sjmallett st->print_cr("[CodeBlob]"); 600215976Sjmallett} 601215976Sjmallett 602215976Sjmallettvoid BufferBlob::verify() { 603215976Sjmallett // unimplemented 604215976Sjmallett} 605232812Sjmallett 606232812Sjmallettvoid BufferBlob::print_on(outputStream* st) const { 607232812Sjmallett CodeBlob::print_on(st); 608232812Sjmallett print_value_on(st); 609232812Sjmallett} 610215976Sjmallett 611215976Sjmallettvoid BufferBlob::print_value_on(outputStream* st) const { 612215976Sjmallett st->print_cr("BufferBlob (" INTPTR_FORMAT ") used for %s", this, name()); 613215976Sjmallett} 614215976Sjmallett 615215976Sjmallettvoid RuntimeStub::verify() { 616215976Sjmallett // unimplemented 617215976Sjmallett} 618215976Sjmallett 619215976Sjmallettvoid RuntimeStub::print_on(outputStream* st) const { 620215976Sjmallett CodeBlob::print_on(st); 621215976Sjmallett st->print("Runtime Stub (" INTPTR_FORMAT "): ", this); 622232812Sjmallett st->print_cr(name()); 623232812Sjmallett Disassembler::decode((CodeBlob*)this, st); 624232812Sjmallett} 625232812Sjmallett 626232812Sjmallettvoid RuntimeStub::print_value_on(outputStream* st) const { 627215976Sjmallett st->print("RuntimeStub (" INTPTR_FORMAT "): ", this); st->print(name()); 628215976Sjmallett} 629215976Sjmallett 630215976Sjmallettvoid SingletonBlob::verify() { 631215976Sjmallett // unimplemented 632215976Sjmallett} 633215976Sjmallett 634215976Sjmallettvoid SingletonBlob::print_on(outputStream* st) const { 635215976Sjmallett CodeBlob::print_on(st); 636215976Sjmallett st->print_cr(name()); 637215976Sjmallett Disassembler::decode((CodeBlob*)this, st); 638215976Sjmallett} 639232812Sjmallett 640232812Sjmallettvoid SingletonBlob::print_value_on(outputStream* st) const { 641232812Sjmallett st->print_cr(name()); 642232812Sjmallett} 643232812Sjmallett 644215976Sjmallettvoid DeoptimizationBlob::print_value_on(outputStream* st) const { 645215976Sjmallett st->print_cr("Deoptimization (frame not available)"); 646215976Sjmallett} 647215976Sjmallett