1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/code/codeBlob.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,703 @@ 1.4 +/* 1.5 + * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +# include "incls/_precompiled.incl" 1.29 +# include "incls/_codeBlob.cpp.incl" 1.30 + 1.31 +unsigned int align_code_offset(int offset) { 1.32 + // align the size to CodeEntryAlignment 1.33 + return 1.34 + ((offset + (int)CodeHeap::header_size() + (CodeEntryAlignment-1)) & ~(CodeEntryAlignment-1)) 1.35 + - (int)CodeHeap::header_size(); 1.36 +} 1.37 + 1.38 + 1.39 +// This must be consistent with the CodeBlob constructor's layout actions. 1.40 +unsigned int CodeBlob::allocation_size(CodeBuffer* cb, int header_size) { 1.41 + unsigned int size = header_size; 1.42 + size += round_to(cb->total_relocation_size(), oopSize); 1.43 + // align the size to CodeEntryAlignment 1.44 + size = align_code_offset(size); 1.45 + size += round_to(cb->total_code_size(), oopSize); 1.46 + size += round_to(cb->total_oop_size(), oopSize); 1.47 + return size; 1.48 +} 1.49 + 1.50 + 1.51 +// Creates a simple CodeBlob. Sets up the size of the different regions. 1.52 +CodeBlob::CodeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size) { 1.53 + assert(size == round_to(size, oopSize), "unaligned size"); 1.54 + assert(locs_size == round_to(locs_size, oopSize), "unaligned size"); 1.55 + assert(header_size == round_to(header_size, oopSize), "unaligned size"); 1.56 + assert(!UseRelocIndex, "no space allocated for reloc index yet"); 1.57 + 1.58 + // Note: If UseRelocIndex is enabled, there needs to be (at least) one 1.59 + // extra word for the relocation information, containing the reloc 1.60 + // index table length. Unfortunately, the reloc index table imple- 1.61 + // mentation is not easily understandable and thus it is not clear 1.62 + // what exactly the format is supposed to be. For now, we just turn 1.63 + // off the use of this table (gri 7/6/2000). 1.64 + 1.65 + _name = name; 1.66 + _size = size; 1.67 + _frame_complete_offset = frame_complete; 1.68 + _header_size = header_size; 1.69 + _relocation_size = locs_size; 1.70 + _instructions_offset = align_code_offset(header_size + locs_size); 1.71 + _data_offset = size; 1.72 + _oops_offset = size; 1.73 + _oops_length = 0; 1.74 + _frame_size = 0; 1.75 + set_oop_maps(NULL); 1.76 +} 1.77 + 1.78 + 1.79 +// Creates a CodeBlob from a CodeBuffer. Sets up the size of the different regions, 1.80 +// and copy code and relocation info. 1.81 +CodeBlob::CodeBlob( 1.82 + const char* name, 1.83 + CodeBuffer* cb, 1.84 + int header_size, 1.85 + int size, 1.86 + int frame_complete, 1.87 + int frame_size, 1.88 + OopMapSet* oop_maps 1.89 +) { 1.90 + assert(size == round_to(size, oopSize), "unaligned size"); 1.91 + assert(header_size == round_to(header_size, oopSize), "unaligned size"); 1.92 + 1.93 + _name = name; 1.94 + _size = size; 1.95 + _frame_complete_offset = frame_complete; 1.96 + _header_size = header_size; 1.97 + _relocation_size = round_to(cb->total_relocation_size(), oopSize); 1.98 + _instructions_offset = align_code_offset(header_size + _relocation_size); 1.99 + _data_offset = _instructions_offset + round_to(cb->total_code_size(), oopSize); 1.100 + _oops_offset = _size - round_to(cb->total_oop_size(), oopSize); 1.101 + _oops_length = 0; // temporary, until the copy_oops handshake 1.102 + assert(_oops_offset >= _data_offset, "codeBlob is too small"); 1.103 + assert(_data_offset <= size, "codeBlob is too small"); 1.104 + 1.105 + cb->copy_code_and_locs_to(this); 1.106 + set_oop_maps(oop_maps); 1.107 + _frame_size = frame_size; 1.108 +#ifdef COMPILER1 1.109 + // probably wrong for tiered 1.110 + assert(_frame_size >= -1, "must use frame size or -1 for runtime stubs"); 1.111 +#endif // COMPILER1 1.112 +} 1.113 + 1.114 + 1.115 +void CodeBlob::set_oop_maps(OopMapSet* p) { 1.116 + // Danger Will Robinson! This method allocates a big 1.117 + // chunk of memory, its your job to free it. 1.118 + if (p != NULL) { 1.119 + // We need to allocate a chunk big enough to hold the OopMapSet and all of its OopMaps 1.120 + _oop_maps = (OopMapSet* )NEW_C_HEAP_ARRAY(unsigned char, p->heap_size()); 1.121 + p->copy_to((address)_oop_maps); 1.122 + } else { 1.123 + _oop_maps = NULL; 1.124 + } 1.125 +} 1.126 + 1.127 + 1.128 +void CodeBlob::flush() { 1.129 + if (_oop_maps) { 1.130 + FREE_C_HEAP_ARRAY(unsigned char, _oop_maps); 1.131 + _oop_maps = NULL; 1.132 + } 1.133 + _comments.free(); 1.134 +} 1.135 + 1.136 + 1.137 +// Promote one word from an assembly-time handle to a live embedded oop. 1.138 +inline void CodeBlob::initialize_immediate_oop(oop* dest, jobject handle) { 1.139 + if (handle == NULL || 1.140 + // As a special case, IC oops are initialized to 1 or -1. 1.141 + handle == (jobject) Universe::non_oop_word()) { 1.142 + (*dest) = (oop)handle; 1.143 + } else { 1.144 + (*dest) = JNIHandles::resolve_non_null(handle); 1.145 + } 1.146 +} 1.147 + 1.148 + 1.149 +void CodeBlob::copy_oops(GrowableArray<jobject>* array) { 1.150 + assert(_oops_length == 0, "do this handshake just once, please"); 1.151 + int length = array->length(); 1.152 + assert((address)(oops_begin() + length) <= data_end(), "oops big enough"); 1.153 + oop* dest = oops_begin(); 1.154 + for (int index = 0 ; index < length; index++) { 1.155 + initialize_immediate_oop(&dest[index], array->at(index)); 1.156 + } 1.157 + _oops_length = length; 1.158 + 1.159 + // Now we can fix up all the oops in the code. 1.160 + // We need to do this in the code because 1.161 + // the assembler uses jobjects as placeholders. 1.162 + // The code and relocations have already been 1.163 + // initialized by the CodeBlob constructor, 1.164 + // so it is valid even at this early point to 1.165 + // iterate over relocations and patch the code. 1.166 + fix_oop_relocations(NULL, NULL, /*initialize_immediates=*/ true); 1.167 +} 1.168 + 1.169 + 1.170 +relocInfo::relocType CodeBlob::reloc_type_for_address(address pc) { 1.171 + RelocIterator iter(this, pc, pc+1); 1.172 + while (iter.next()) { 1.173 + return (relocInfo::relocType) iter.type(); 1.174 + } 1.175 + // No relocation info found for pc 1.176 + ShouldNotReachHere(); 1.177 + return relocInfo::none; // dummy return value 1.178 +} 1.179 + 1.180 + 1.181 +bool CodeBlob::is_at_poll_return(address pc) { 1.182 + RelocIterator iter(this, pc, pc+1); 1.183 + while (iter.next()) { 1.184 + if (iter.type() == relocInfo::poll_return_type) 1.185 + return true; 1.186 + } 1.187 + return false; 1.188 +} 1.189 + 1.190 + 1.191 +bool CodeBlob::is_at_poll_or_poll_return(address pc) { 1.192 + RelocIterator iter(this, pc, pc+1); 1.193 + while (iter.next()) { 1.194 + relocInfo::relocType t = iter.type(); 1.195 + if (t == relocInfo::poll_return_type || t == relocInfo::poll_type) 1.196 + return true; 1.197 + } 1.198 + return false; 1.199 +} 1.200 + 1.201 + 1.202 +void CodeBlob::fix_oop_relocations(address begin, address end, 1.203 + bool initialize_immediates) { 1.204 + // re-patch all oop-bearing instructions, just in case some oops moved 1.205 + RelocIterator iter(this, begin, end); 1.206 + while (iter.next()) { 1.207 + if (iter.type() == relocInfo::oop_type) { 1.208 + oop_Relocation* reloc = iter.oop_reloc(); 1.209 + if (initialize_immediates && reloc->oop_is_immediate()) { 1.210 + oop* dest = reloc->oop_addr(); 1.211 + initialize_immediate_oop(dest, (jobject) *dest); 1.212 + } 1.213 + // Refresh the oop-related bits of this instruction. 1.214 + reloc->fix_oop_relocation(); 1.215 + } 1.216 + 1.217 + // There must not be any interfering patches or breakpoints. 1.218 + assert(!(iter.type() == relocInfo::breakpoint_type 1.219 + && iter.breakpoint_reloc()->active()), 1.220 + "no active breakpoint"); 1.221 + } 1.222 +} 1.223 + 1.224 +void CodeBlob::do_unloading(BoolObjectClosure* is_alive, 1.225 + OopClosure* keep_alive, 1.226 + bool unloading_occurred) { 1.227 + ShouldNotReachHere(); 1.228 +} 1.229 + 1.230 +OopMap* CodeBlob::oop_map_for_return_address(address return_address) { 1.231 + address pc = return_address ; 1.232 + assert (oop_maps() != NULL, "nope"); 1.233 + return oop_maps()->find_map_at_offset ((intptr_t) pc - (intptr_t) instructions_begin()); 1.234 +} 1.235 + 1.236 + 1.237 +//---------------------------------------------------------------------------------------------------- 1.238 +// Implementation of BufferBlob 1.239 + 1.240 + 1.241 +BufferBlob::BufferBlob(const char* name, int size) 1.242 +: CodeBlob(name, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, /*locs_size:*/ 0) 1.243 +{} 1.244 + 1.245 +BufferBlob* BufferBlob::create(const char* name, int buffer_size) { 1.246 + ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 1.247 + 1.248 + BufferBlob* blob = NULL; 1.249 + unsigned int size = sizeof(BufferBlob); 1.250 + // align the size to CodeEntryAlignment 1.251 + size = align_code_offset(size); 1.252 + size += round_to(buffer_size, oopSize); 1.253 + assert(name != NULL, "must provide a name"); 1.254 + { 1.255 + 1.256 + MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1.257 + blob = new (size) BufferBlob(name, size); 1.258 + } 1.259 + // Track memory usage statistic after releasing CodeCache_lock 1.260 + MemoryService::track_code_cache_memory_usage(); 1.261 + 1.262 + return blob; 1.263 +} 1.264 + 1.265 + 1.266 +BufferBlob::BufferBlob(const char* name, int size, CodeBuffer* cb) 1.267 + : CodeBlob(name, cb, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, 0, NULL) 1.268 +{} 1.269 + 1.270 +BufferBlob* BufferBlob::create(const char* name, CodeBuffer* cb) { 1.271 + ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 1.272 + 1.273 + BufferBlob* blob = NULL; 1.274 + unsigned int size = allocation_size(cb, sizeof(BufferBlob)); 1.275 + assert(name != NULL, "must provide a name"); 1.276 + { 1.277 + 1.278 + MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1.279 + blob = new (size) BufferBlob(name, size, cb); 1.280 + } 1.281 + // Track memory usage statistic after releasing CodeCache_lock 1.282 + MemoryService::track_code_cache_memory_usage(); 1.283 + 1.284 + return blob; 1.285 +} 1.286 + 1.287 + 1.288 +void* BufferBlob::operator new(size_t s, unsigned size) { 1.289 + void* p = CodeCache::allocate(size); 1.290 + return p; 1.291 +} 1.292 + 1.293 + 1.294 +void BufferBlob::free( BufferBlob *blob ) { 1.295 + ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 1.296 + { 1.297 + MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1.298 + CodeCache::free((CodeBlob*)blob); 1.299 + } 1.300 + // Track memory usage statistic after releasing CodeCache_lock 1.301 + MemoryService::track_code_cache_memory_usage(); 1.302 +} 1.303 + 1.304 +bool BufferBlob::is_adapter_blob() const { 1.305 + return (strcmp(AdapterHandlerEntry::name, name()) == 0); 1.306 +} 1.307 + 1.308 +//---------------------------------------------------------------------------------------------------- 1.309 +// Implementation of RuntimeStub 1.310 + 1.311 +RuntimeStub::RuntimeStub( 1.312 + const char* name, 1.313 + CodeBuffer* cb, 1.314 + int size, 1.315 + int frame_complete, 1.316 + int frame_size, 1.317 + OopMapSet* oop_maps, 1.318 + bool caller_must_gc_arguments 1.319 +) 1.320 +: CodeBlob(name, cb, sizeof(RuntimeStub), size, frame_complete, frame_size, oop_maps) 1.321 +{ 1.322 + _caller_must_gc_arguments = caller_must_gc_arguments; 1.323 +} 1.324 + 1.325 + 1.326 +RuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name, 1.327 + CodeBuffer* cb, 1.328 + int frame_complete, 1.329 + int frame_size, 1.330 + OopMapSet* oop_maps, 1.331 + bool caller_must_gc_arguments) 1.332 +{ 1.333 + RuntimeStub* stub = NULL; 1.334 + ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 1.335 + { 1.336 + MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1.337 + unsigned int size = allocation_size(cb, sizeof(RuntimeStub)); 1.338 + stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments); 1.339 + } 1.340 + 1.341 + // Do not hold the CodeCache lock during name formatting. 1.342 + if (stub != NULL) { 1.343 + char stub_id[256]; 1.344 + jio_snprintf(stub_id, sizeof(stub_id), "RuntimeStub - %s", stub_name); 1.345 + if (PrintStubCode) { 1.346 + tty->print_cr("Decoding %s " INTPTR_FORMAT, stub_id, stub); 1.347 + Disassembler::decode(stub->instructions_begin(), stub->instructions_end()); 1.348 + } 1.349 + VTune::register_stub(stub_id, stub->instructions_begin(), stub->instructions_end()); 1.350 + Forte::register_stub(stub_id, stub->instructions_begin(), stub->instructions_end()); 1.351 + 1.352 + if (JvmtiExport::should_post_dynamic_code_generated()) { 1.353 + JvmtiExport::post_dynamic_code_generated(stub_name, stub->instructions_begin(), stub->instructions_end()); 1.354 + } 1.355 + } 1.356 + 1.357 + // Track memory usage statistic after releasing CodeCache_lock 1.358 + MemoryService::track_code_cache_memory_usage(); 1.359 + 1.360 + return stub; 1.361 +} 1.362 + 1.363 + 1.364 +void* RuntimeStub::operator new(size_t s, unsigned size) { 1.365 + void* p = CodeCache::allocate(size); 1.366 + if (!p) fatal("Initial size of CodeCache is too small"); 1.367 + return p; 1.368 +} 1.369 + 1.370 + 1.371 +//---------------------------------------------------------------------------------------------------- 1.372 +// Implementation of DeoptimizationBlob 1.373 + 1.374 +DeoptimizationBlob::DeoptimizationBlob( 1.375 + CodeBuffer* cb, 1.376 + int size, 1.377 + OopMapSet* oop_maps, 1.378 + int unpack_offset, 1.379 + int unpack_with_exception_offset, 1.380 + int unpack_with_reexecution_offset, 1.381 + int frame_size 1.382 +) 1.383 +: SingletonBlob("DeoptimizationBlob", cb, sizeof(DeoptimizationBlob), size, frame_size, oop_maps) 1.384 +{ 1.385 + _unpack_offset = unpack_offset; 1.386 + _unpack_with_exception = unpack_with_exception_offset; 1.387 + _unpack_with_reexecution = unpack_with_reexecution_offset; 1.388 +#ifdef COMPILER1 1.389 + _unpack_with_exception_in_tls = -1; 1.390 +#endif 1.391 +} 1.392 + 1.393 + 1.394 +DeoptimizationBlob* DeoptimizationBlob::create( 1.395 + CodeBuffer* cb, 1.396 + OopMapSet* oop_maps, 1.397 + int unpack_offset, 1.398 + int unpack_with_exception_offset, 1.399 + int unpack_with_reexecution_offset, 1.400 + int frame_size) 1.401 +{ 1.402 + DeoptimizationBlob* blob = NULL; 1.403 + ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 1.404 + { 1.405 + MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1.406 + unsigned int size = allocation_size(cb, sizeof(DeoptimizationBlob)); 1.407 + blob = new (size) DeoptimizationBlob(cb, 1.408 + size, 1.409 + oop_maps, 1.410 + unpack_offset, 1.411 + unpack_with_exception_offset, 1.412 + unpack_with_reexecution_offset, 1.413 + frame_size); 1.414 + } 1.415 + 1.416 + // Do not hold the CodeCache lock during name formatting. 1.417 + if (blob != NULL) { 1.418 + char blob_id[256]; 1.419 + jio_snprintf(blob_id, sizeof(blob_id), "DeoptimizationBlob@" PTR_FORMAT, blob->instructions_begin()); 1.420 + if (PrintStubCode) { 1.421 + tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob); 1.422 + Disassembler::decode(blob->instructions_begin(), blob->instructions_end()); 1.423 + } 1.424 + VTune::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); 1.425 + Forte::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); 1.426 + 1.427 + if (JvmtiExport::should_post_dynamic_code_generated()) { 1.428 + JvmtiExport::post_dynamic_code_generated("DeoptimizationBlob", 1.429 + blob->instructions_begin(), 1.430 + blob->instructions_end()); 1.431 + } 1.432 + } 1.433 + 1.434 + // Track memory usage statistic after releasing CodeCache_lock 1.435 + MemoryService::track_code_cache_memory_usage(); 1.436 + 1.437 + return blob; 1.438 +} 1.439 + 1.440 + 1.441 +void* DeoptimizationBlob::operator new(size_t s, unsigned size) { 1.442 + void* p = CodeCache::allocate(size); 1.443 + if (!p) fatal("Initial size of CodeCache is too small"); 1.444 + return p; 1.445 +} 1.446 + 1.447 +//---------------------------------------------------------------------------------------------------- 1.448 +// Implementation of UncommonTrapBlob 1.449 + 1.450 +#ifdef COMPILER2 1.451 +UncommonTrapBlob::UncommonTrapBlob( 1.452 + CodeBuffer* cb, 1.453 + int size, 1.454 + OopMapSet* oop_maps, 1.455 + int frame_size 1.456 +) 1.457 +: SingletonBlob("UncommonTrapBlob", cb, sizeof(UncommonTrapBlob), size, frame_size, oop_maps) 1.458 +{} 1.459 + 1.460 + 1.461 +UncommonTrapBlob* UncommonTrapBlob::create( 1.462 + CodeBuffer* cb, 1.463 + OopMapSet* oop_maps, 1.464 + int frame_size) 1.465 +{ 1.466 + UncommonTrapBlob* blob = NULL; 1.467 + ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 1.468 + { 1.469 + MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1.470 + unsigned int size = allocation_size(cb, sizeof(UncommonTrapBlob)); 1.471 + blob = new (size) UncommonTrapBlob(cb, size, oop_maps, frame_size); 1.472 + } 1.473 + 1.474 + // Do not hold the CodeCache lock during name formatting. 1.475 + if (blob != NULL) { 1.476 + char blob_id[256]; 1.477 + jio_snprintf(blob_id, sizeof(blob_id), "UncommonTrapBlob@" PTR_FORMAT, blob->instructions_begin()); 1.478 + if (PrintStubCode) { 1.479 + tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob); 1.480 + Disassembler::decode(blob->instructions_begin(), blob->instructions_end()); 1.481 + } 1.482 + VTune::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); 1.483 + Forte::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); 1.484 + 1.485 + if (JvmtiExport::should_post_dynamic_code_generated()) { 1.486 + JvmtiExport::post_dynamic_code_generated("UncommonTrapBlob", 1.487 + blob->instructions_begin(), 1.488 + blob->instructions_end()); 1.489 + } 1.490 + } 1.491 + 1.492 + // Track memory usage statistic after releasing CodeCache_lock 1.493 + MemoryService::track_code_cache_memory_usage(); 1.494 + 1.495 + return blob; 1.496 +} 1.497 + 1.498 + 1.499 +void* UncommonTrapBlob::operator new(size_t s, unsigned size) { 1.500 + void* p = CodeCache::allocate(size); 1.501 + if (!p) fatal("Initial size of CodeCache is too small"); 1.502 + return p; 1.503 +} 1.504 +#endif // COMPILER2 1.505 + 1.506 + 1.507 +//---------------------------------------------------------------------------------------------------- 1.508 +// Implementation of ExceptionBlob 1.509 + 1.510 +#ifdef COMPILER2 1.511 +ExceptionBlob::ExceptionBlob( 1.512 + CodeBuffer* cb, 1.513 + int size, 1.514 + OopMapSet* oop_maps, 1.515 + int frame_size 1.516 +) 1.517 +: SingletonBlob("ExceptionBlob", cb, sizeof(ExceptionBlob), size, frame_size, oop_maps) 1.518 +{} 1.519 + 1.520 + 1.521 +ExceptionBlob* ExceptionBlob::create( 1.522 + CodeBuffer* cb, 1.523 + OopMapSet* oop_maps, 1.524 + int frame_size) 1.525 +{ 1.526 + ExceptionBlob* blob = NULL; 1.527 + ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 1.528 + { 1.529 + MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1.530 + unsigned int size = allocation_size(cb, sizeof(ExceptionBlob)); 1.531 + blob = new (size) ExceptionBlob(cb, size, oop_maps, frame_size); 1.532 + } 1.533 + 1.534 + // We do not need to hold the CodeCache lock during name formatting 1.535 + if (blob != NULL) { 1.536 + char blob_id[256]; 1.537 + jio_snprintf(blob_id, sizeof(blob_id), "ExceptionBlob@" PTR_FORMAT, blob->instructions_begin()); 1.538 + if (PrintStubCode) { 1.539 + tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob); 1.540 + Disassembler::decode(blob->instructions_begin(), blob->instructions_end()); 1.541 + } 1.542 + VTune::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); 1.543 + Forte::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); 1.544 + 1.545 + if (JvmtiExport::should_post_dynamic_code_generated()) { 1.546 + JvmtiExport::post_dynamic_code_generated("ExceptionBlob", 1.547 + blob->instructions_begin(), 1.548 + blob->instructions_end()); 1.549 + } 1.550 + } 1.551 + 1.552 + // Track memory usage statistic after releasing CodeCache_lock 1.553 + MemoryService::track_code_cache_memory_usage(); 1.554 + 1.555 + return blob; 1.556 +} 1.557 + 1.558 + 1.559 +void* ExceptionBlob::operator new(size_t s, unsigned size) { 1.560 + void* p = CodeCache::allocate(size); 1.561 + if (!p) fatal("Initial size of CodeCache is too small"); 1.562 + return p; 1.563 +} 1.564 +#endif // COMPILER2 1.565 + 1.566 + 1.567 +//---------------------------------------------------------------------------------------------------- 1.568 +// Implementation of SafepointBlob 1.569 + 1.570 +SafepointBlob::SafepointBlob( 1.571 + CodeBuffer* cb, 1.572 + int size, 1.573 + OopMapSet* oop_maps, 1.574 + int frame_size 1.575 +) 1.576 +: SingletonBlob("SafepointBlob", cb, sizeof(SafepointBlob), size, frame_size, oop_maps) 1.577 +{} 1.578 + 1.579 + 1.580 +SafepointBlob* SafepointBlob::create( 1.581 + CodeBuffer* cb, 1.582 + OopMapSet* oop_maps, 1.583 + int frame_size) 1.584 +{ 1.585 + SafepointBlob* blob = NULL; 1.586 + ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock 1.587 + { 1.588 + MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1.589 + unsigned int size = allocation_size(cb, sizeof(SafepointBlob)); 1.590 + blob = new (size) SafepointBlob(cb, size, oop_maps, frame_size); 1.591 + } 1.592 + 1.593 + // We do not need to hold the CodeCache lock during name formatting. 1.594 + if (blob != NULL) { 1.595 + char blob_id[256]; 1.596 + jio_snprintf(blob_id, sizeof(blob_id), "SafepointBlob@" PTR_FORMAT, blob->instructions_begin()); 1.597 + if (PrintStubCode) { 1.598 + tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob); 1.599 + Disassembler::decode(blob->instructions_begin(), blob->instructions_end()); 1.600 + } 1.601 + VTune::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); 1.602 + Forte::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end()); 1.603 + 1.604 + if (JvmtiExport::should_post_dynamic_code_generated()) { 1.605 + JvmtiExport::post_dynamic_code_generated("SafepointBlob", 1.606 + blob->instructions_begin(), 1.607 + blob->instructions_end()); 1.608 + } 1.609 + } 1.610 + 1.611 + // Track memory usage statistic after releasing CodeCache_lock 1.612 + MemoryService::track_code_cache_memory_usage(); 1.613 + 1.614 + return blob; 1.615 +} 1.616 + 1.617 + 1.618 +void* SafepointBlob::operator new(size_t s, unsigned size) { 1.619 + void* p = CodeCache::allocate(size); 1.620 + if (!p) fatal("Initial size of CodeCache is too small"); 1.621 + return p; 1.622 +} 1.623 + 1.624 + 1.625 +//---------------------------------------------------------------------------------------------------- 1.626 +// Verification and printing 1.627 + 1.628 +void CodeBlob::verify() { 1.629 + ShouldNotReachHere(); 1.630 +} 1.631 + 1.632 +#ifndef PRODUCT 1.633 + 1.634 +void CodeBlob::print() const { 1.635 + tty->print_cr("[CodeBlob (" INTPTR_FORMAT ")]", this); 1.636 + tty->print_cr("Framesize: %d", _frame_size); 1.637 +} 1.638 + 1.639 + 1.640 +void CodeBlob::print_value_on(outputStream* st) const { 1.641 + st->print_cr("[CodeBlob]"); 1.642 +} 1.643 + 1.644 +#endif 1.645 + 1.646 +void BufferBlob::verify() { 1.647 + // unimplemented 1.648 +} 1.649 + 1.650 +#ifndef PRODUCT 1.651 + 1.652 +void BufferBlob::print() const { 1.653 + CodeBlob::print(); 1.654 + print_value_on(tty); 1.655 +} 1.656 + 1.657 + 1.658 +void BufferBlob::print_value_on(outputStream* st) const { 1.659 + st->print_cr("BufferBlob (" INTPTR_FORMAT ") used for %s", this, name()); 1.660 +} 1.661 + 1.662 + 1.663 +#endif 1.664 + 1.665 +void RuntimeStub::verify() { 1.666 + // unimplemented 1.667 +} 1.668 + 1.669 +#ifndef PRODUCT 1.670 + 1.671 +void RuntimeStub::print() const { 1.672 + CodeBlob::print(); 1.673 + tty->print("Runtime Stub (" INTPTR_FORMAT "): ", this); 1.674 + tty->print_cr(name()); 1.675 + Disassembler::decode((CodeBlob*)this); 1.676 +} 1.677 + 1.678 + 1.679 +void RuntimeStub::print_value_on(outputStream* st) const { 1.680 + st->print("RuntimeStub (" INTPTR_FORMAT "): ", this); st->print(name()); 1.681 +} 1.682 + 1.683 +#endif 1.684 + 1.685 +void SingletonBlob::verify() { 1.686 + // unimplemented 1.687 +} 1.688 + 1.689 +#ifndef PRODUCT 1.690 + 1.691 +void SingletonBlob::print() const { 1.692 + CodeBlob::print(); 1.693 + tty->print_cr(name()); 1.694 + Disassembler::decode((CodeBlob*)this); 1.695 +} 1.696 + 1.697 + 1.698 +void SingletonBlob::print_value_on(outputStream* st) const { 1.699 + st->print_cr(name()); 1.700 +} 1.701 + 1.702 +void DeoptimizationBlob::print_value_on(outputStream* st) const { 1.703 + st->print_cr("Deoptimization (frame not available)"); 1.704 +} 1.705 + 1.706 +#endif // PRODUCT