src/share/vm/code/codeBlob.cpp

Thu, 08 Jul 2010 14:29:44 -0700

author
never
date
Thu, 08 Jul 2010 14:29:44 -0700
changeset 1999
2a47bd84841f
parent 1934
e9ff18c4ace7
child 2018
7139e81efd2d
permissions
-rw-r--r--

6965184: possible races in make_not_entrant_or_zombie
Reviewed-by: kvn

duke@435 1 /*
trims@1907 2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_codeBlob.cpp.incl"
duke@435 27
duke@435 28 unsigned int align_code_offset(int offset) {
duke@435 29 // align the size to CodeEntryAlignment
duke@435 30 return
duke@435 31 ((offset + (int)CodeHeap::header_size() + (CodeEntryAlignment-1)) & ~(CodeEntryAlignment-1))
duke@435 32 - (int)CodeHeap::header_size();
duke@435 33 }
duke@435 34
duke@435 35
duke@435 36 // This must be consistent with the CodeBlob constructor's layout actions.
duke@435 37 unsigned int CodeBlob::allocation_size(CodeBuffer* cb, int header_size) {
duke@435 38 unsigned int size = header_size;
duke@435 39 size += round_to(cb->total_relocation_size(), oopSize);
duke@435 40 // align the size to CodeEntryAlignment
duke@435 41 size = align_code_offset(size);
duke@435 42 size += round_to(cb->total_code_size(), oopSize);
duke@435 43 size += round_to(cb->total_oop_size(), oopSize);
duke@435 44 return size;
duke@435 45 }
duke@435 46
duke@435 47
duke@435 48 // Creates a simple CodeBlob. Sets up the size of the different regions.
duke@435 49 CodeBlob::CodeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size) {
duke@435 50 assert(size == round_to(size, oopSize), "unaligned size");
duke@435 51 assert(locs_size == round_to(locs_size, oopSize), "unaligned size");
duke@435 52 assert(header_size == round_to(header_size, oopSize), "unaligned size");
duke@435 53 assert(!UseRelocIndex, "no space allocated for reloc index yet");
duke@435 54
duke@435 55 // Note: If UseRelocIndex is enabled, there needs to be (at least) one
duke@435 56 // extra word for the relocation information, containing the reloc
duke@435 57 // index table length. Unfortunately, the reloc index table imple-
duke@435 58 // mentation is not easily understandable and thus it is not clear
duke@435 59 // what exactly the format is supposed to be. For now, we just turn
duke@435 60 // off the use of this table (gri 7/6/2000).
duke@435 61
duke@435 62 _name = name;
duke@435 63 _size = size;
duke@435 64 _frame_complete_offset = frame_complete;
duke@435 65 _header_size = header_size;
duke@435 66 _relocation_size = locs_size;
duke@435 67 _instructions_offset = align_code_offset(header_size + locs_size);
duke@435 68 _data_offset = size;
duke@435 69 _frame_size = 0;
duke@435 70 set_oop_maps(NULL);
duke@435 71 }
duke@435 72
duke@435 73
duke@435 74 // Creates a CodeBlob from a CodeBuffer. Sets up the size of the different regions,
duke@435 75 // and copy code and relocation info.
duke@435 76 CodeBlob::CodeBlob(
duke@435 77 const char* name,
duke@435 78 CodeBuffer* cb,
duke@435 79 int header_size,
duke@435 80 int size,
duke@435 81 int frame_complete,
duke@435 82 int frame_size,
duke@435 83 OopMapSet* oop_maps
duke@435 84 ) {
duke@435 85 assert(size == round_to(size, oopSize), "unaligned size");
duke@435 86 assert(header_size == round_to(header_size, oopSize), "unaligned size");
duke@435 87
duke@435 88 _name = name;
duke@435 89 _size = size;
duke@435 90 _frame_complete_offset = frame_complete;
duke@435 91 _header_size = header_size;
duke@435 92 _relocation_size = round_to(cb->total_relocation_size(), oopSize);
duke@435 93 _instructions_offset = align_code_offset(header_size + _relocation_size);
duke@435 94 _data_offset = _instructions_offset + round_to(cb->total_code_size(), oopSize);
duke@435 95 assert(_data_offset <= size, "codeBlob is too small");
duke@435 96
duke@435 97 cb->copy_code_and_locs_to(this);
duke@435 98 set_oop_maps(oop_maps);
duke@435 99 _frame_size = frame_size;
duke@435 100 #ifdef COMPILER1
duke@435 101 // probably wrong for tiered
duke@435 102 assert(_frame_size >= -1, "must use frame size or -1 for runtime stubs");
duke@435 103 #endif // COMPILER1
duke@435 104 }
duke@435 105
duke@435 106
duke@435 107 void CodeBlob::set_oop_maps(OopMapSet* p) {
duke@435 108 // Danger Will Robinson! This method allocates a big
duke@435 109 // chunk of memory, its your job to free it.
duke@435 110 if (p != NULL) {
duke@435 111 // We need to allocate a chunk big enough to hold the OopMapSet and all of its OopMaps
duke@435 112 _oop_maps = (OopMapSet* )NEW_C_HEAP_ARRAY(unsigned char, p->heap_size());
duke@435 113 p->copy_to((address)_oop_maps);
duke@435 114 } else {
duke@435 115 _oop_maps = NULL;
duke@435 116 }
duke@435 117 }
duke@435 118
duke@435 119
duke@435 120 void CodeBlob::flush() {
duke@435 121 if (_oop_maps) {
duke@435 122 FREE_C_HEAP_ARRAY(unsigned char, _oop_maps);
duke@435 123 _oop_maps = NULL;
duke@435 124 }
duke@435 125 _comments.free();
duke@435 126 }
duke@435 127
duke@435 128
duke@435 129 OopMap* CodeBlob::oop_map_for_return_address(address return_address) {
duke@435 130 address pc = return_address ;
duke@435 131 assert (oop_maps() != NULL, "nope");
duke@435 132 return oop_maps()->find_map_at_offset ((intptr_t) pc - (intptr_t) instructions_begin());
duke@435 133 }
duke@435 134
duke@435 135
duke@435 136 //----------------------------------------------------------------------------------------------------
duke@435 137 // Implementation of BufferBlob
duke@435 138
duke@435 139
duke@435 140 BufferBlob::BufferBlob(const char* name, int size)
duke@435 141 : CodeBlob(name, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, /*locs_size:*/ 0)
duke@435 142 {}
duke@435 143
duke@435 144 BufferBlob* BufferBlob::create(const char* name, int buffer_size) {
duke@435 145 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 146
duke@435 147 BufferBlob* blob = NULL;
duke@435 148 unsigned int size = sizeof(BufferBlob);
duke@435 149 // align the size to CodeEntryAlignment
duke@435 150 size = align_code_offset(size);
duke@435 151 size += round_to(buffer_size, oopSize);
duke@435 152 assert(name != NULL, "must provide a name");
duke@435 153 {
duke@435 154 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 155 blob = new (size) BufferBlob(name, size);
duke@435 156 }
duke@435 157 // Track memory usage statistic after releasing CodeCache_lock
duke@435 158 MemoryService::track_code_cache_memory_usage();
duke@435 159
duke@435 160 return blob;
duke@435 161 }
duke@435 162
duke@435 163
duke@435 164 BufferBlob::BufferBlob(const char* name, int size, CodeBuffer* cb)
duke@435 165 : CodeBlob(name, cb, sizeof(BufferBlob), size, CodeOffsets::frame_never_safe, 0, NULL)
duke@435 166 {}
duke@435 167
duke@435 168 BufferBlob* BufferBlob::create(const char* name, CodeBuffer* cb) {
duke@435 169 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 170
duke@435 171 BufferBlob* blob = NULL;
duke@435 172 unsigned int size = allocation_size(cb, sizeof(BufferBlob));
duke@435 173 assert(name != NULL, "must provide a name");
duke@435 174 {
duke@435 175 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 176 blob = new (size) BufferBlob(name, size, cb);
duke@435 177 }
duke@435 178 // Track memory usage statistic after releasing CodeCache_lock
duke@435 179 MemoryService::track_code_cache_memory_usage();
duke@435 180
duke@435 181 return blob;
duke@435 182 }
duke@435 183
duke@435 184
duke@435 185 void* BufferBlob::operator new(size_t s, unsigned size) {
duke@435 186 void* p = CodeCache::allocate(size);
duke@435 187 return p;
duke@435 188 }
duke@435 189
duke@435 190
duke@435 191 void BufferBlob::free( BufferBlob *blob ) {
duke@435 192 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 193 {
duke@435 194 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 195 CodeCache::free((CodeBlob*)blob);
duke@435 196 }
duke@435 197 // Track memory usage statistic after releasing CodeCache_lock
duke@435 198 MemoryService::track_code_cache_memory_usage();
duke@435 199 }
duke@435 200
twisti@1734 201
twisti@1734 202 //----------------------------------------------------------------------------------------------------
twisti@1734 203 // Implementation of AdapterBlob
twisti@1734 204
twisti@1734 205 AdapterBlob* AdapterBlob::create(CodeBuffer* cb) {
twisti@1734 206 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
twisti@1734 207
twisti@1734 208 AdapterBlob* blob = NULL;
twisti@1734 209 unsigned int size = allocation_size(cb, sizeof(AdapterBlob));
twisti@1734 210 {
twisti@1734 211 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
twisti@1734 212 blob = new (size) AdapterBlob(size, cb);
never@1999 213 CodeCache::commit(blob);
twisti@1734 214 }
twisti@1734 215 // Track memory usage statistic after releasing CodeCache_lock
twisti@1734 216 MemoryService::track_code_cache_memory_usage();
twisti@1734 217
twisti@1734 218 return blob;
duke@435 219 }
duke@435 220
twisti@1734 221
twisti@1734 222 //----------------------------------------------------------------------------------------------------
twisti@1734 223 // Implementation of MethodHandlesAdapterBlob
twisti@1734 224
twisti@1734 225 MethodHandlesAdapterBlob* MethodHandlesAdapterBlob::create(int buffer_size) {
twisti@1734 226 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
twisti@1734 227
twisti@1734 228 MethodHandlesAdapterBlob* blob = NULL;
twisti@1734 229 unsigned int size = sizeof(MethodHandlesAdapterBlob);
twisti@1734 230 // align the size to CodeEntryAlignment
twisti@1734 231 size = align_code_offset(size);
twisti@1734 232 size += round_to(buffer_size, oopSize);
twisti@1734 233 {
twisti@1734 234 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
twisti@1734 235 blob = new (size) MethodHandlesAdapterBlob(size);
twisti@1734 236 }
twisti@1734 237 // Track memory usage statistic after releasing CodeCache_lock
twisti@1734 238 MemoryService::track_code_cache_memory_usage();
twisti@1734 239
twisti@1734 240 return blob;
twisti@1734 241 }
twisti@1734 242
twisti@1734 243
duke@435 244 //----------------------------------------------------------------------------------------------------
duke@435 245 // Implementation of RuntimeStub
duke@435 246
duke@435 247 RuntimeStub::RuntimeStub(
duke@435 248 const char* name,
duke@435 249 CodeBuffer* cb,
duke@435 250 int size,
duke@435 251 int frame_complete,
duke@435 252 int frame_size,
duke@435 253 OopMapSet* oop_maps,
duke@435 254 bool caller_must_gc_arguments
duke@435 255 )
duke@435 256 : CodeBlob(name, cb, sizeof(RuntimeStub), size, frame_complete, frame_size, oop_maps)
duke@435 257 {
duke@435 258 _caller_must_gc_arguments = caller_must_gc_arguments;
duke@435 259 }
duke@435 260
duke@435 261
duke@435 262 RuntimeStub* RuntimeStub::new_runtime_stub(const char* stub_name,
duke@435 263 CodeBuffer* cb,
duke@435 264 int frame_complete,
duke@435 265 int frame_size,
duke@435 266 OopMapSet* oop_maps,
duke@435 267 bool caller_must_gc_arguments)
duke@435 268 {
duke@435 269 RuntimeStub* stub = NULL;
duke@435 270 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 271 {
duke@435 272 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 273 unsigned int size = allocation_size(cb, sizeof(RuntimeStub));
duke@435 274 stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments);
duke@435 275 }
duke@435 276
duke@435 277 // Do not hold the CodeCache lock during name formatting.
duke@435 278 if (stub != NULL) {
duke@435 279 char stub_id[256];
duke@435 280 jio_snprintf(stub_id, sizeof(stub_id), "RuntimeStub - %s", stub_name);
duke@435 281 if (PrintStubCode) {
duke@435 282 tty->print_cr("Decoding %s " INTPTR_FORMAT, stub_id, stub);
duke@435 283 Disassembler::decode(stub->instructions_begin(), stub->instructions_end());
duke@435 284 }
duke@435 285 Forte::register_stub(stub_id, stub->instructions_begin(), stub->instructions_end());
duke@435 286
duke@435 287 if (JvmtiExport::should_post_dynamic_code_generated()) {
duke@435 288 JvmtiExport::post_dynamic_code_generated(stub_name, stub->instructions_begin(), stub->instructions_end());
duke@435 289 }
duke@435 290 }
duke@435 291
duke@435 292 // Track memory usage statistic after releasing CodeCache_lock
duke@435 293 MemoryService::track_code_cache_memory_usage();
duke@435 294
duke@435 295 return stub;
duke@435 296 }
duke@435 297
duke@435 298
duke@435 299 void* RuntimeStub::operator new(size_t s, unsigned size) {
duke@435 300 void* p = CodeCache::allocate(size);
duke@435 301 if (!p) fatal("Initial size of CodeCache is too small");
duke@435 302 return p;
duke@435 303 }
duke@435 304
duke@435 305
duke@435 306 //----------------------------------------------------------------------------------------------------
duke@435 307 // Implementation of DeoptimizationBlob
duke@435 308
duke@435 309 DeoptimizationBlob::DeoptimizationBlob(
duke@435 310 CodeBuffer* cb,
duke@435 311 int size,
duke@435 312 OopMapSet* oop_maps,
duke@435 313 int unpack_offset,
duke@435 314 int unpack_with_exception_offset,
duke@435 315 int unpack_with_reexecution_offset,
duke@435 316 int frame_size
duke@435 317 )
duke@435 318 : SingletonBlob("DeoptimizationBlob", cb, sizeof(DeoptimizationBlob), size, frame_size, oop_maps)
duke@435 319 {
duke@435 320 _unpack_offset = unpack_offset;
duke@435 321 _unpack_with_exception = unpack_with_exception_offset;
duke@435 322 _unpack_with_reexecution = unpack_with_reexecution_offset;
duke@435 323 #ifdef COMPILER1
duke@435 324 _unpack_with_exception_in_tls = -1;
duke@435 325 #endif
duke@435 326 }
duke@435 327
duke@435 328
duke@435 329 DeoptimizationBlob* DeoptimizationBlob::create(
duke@435 330 CodeBuffer* cb,
duke@435 331 OopMapSet* oop_maps,
duke@435 332 int unpack_offset,
duke@435 333 int unpack_with_exception_offset,
duke@435 334 int unpack_with_reexecution_offset,
duke@435 335 int frame_size)
duke@435 336 {
duke@435 337 DeoptimizationBlob* blob = NULL;
duke@435 338 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 339 {
duke@435 340 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 341 unsigned int size = allocation_size(cb, sizeof(DeoptimizationBlob));
duke@435 342 blob = new (size) DeoptimizationBlob(cb,
duke@435 343 size,
duke@435 344 oop_maps,
duke@435 345 unpack_offset,
duke@435 346 unpack_with_exception_offset,
duke@435 347 unpack_with_reexecution_offset,
duke@435 348 frame_size);
duke@435 349 }
duke@435 350
duke@435 351 // Do not hold the CodeCache lock during name formatting.
duke@435 352 if (blob != NULL) {
duke@435 353 char blob_id[256];
duke@435 354 jio_snprintf(blob_id, sizeof(blob_id), "DeoptimizationBlob@" PTR_FORMAT, blob->instructions_begin());
duke@435 355 if (PrintStubCode) {
duke@435 356 tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob);
duke@435 357 Disassembler::decode(blob->instructions_begin(), blob->instructions_end());
duke@435 358 }
duke@435 359 Forte::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end());
duke@435 360
duke@435 361 if (JvmtiExport::should_post_dynamic_code_generated()) {
duke@435 362 JvmtiExport::post_dynamic_code_generated("DeoptimizationBlob",
duke@435 363 blob->instructions_begin(),
duke@435 364 blob->instructions_end());
duke@435 365 }
duke@435 366 }
duke@435 367
duke@435 368 // Track memory usage statistic after releasing CodeCache_lock
duke@435 369 MemoryService::track_code_cache_memory_usage();
duke@435 370
duke@435 371 return blob;
duke@435 372 }
duke@435 373
duke@435 374
duke@435 375 void* DeoptimizationBlob::operator new(size_t s, unsigned size) {
duke@435 376 void* p = CodeCache::allocate(size);
duke@435 377 if (!p) fatal("Initial size of CodeCache is too small");
duke@435 378 return p;
duke@435 379 }
duke@435 380
duke@435 381 //----------------------------------------------------------------------------------------------------
duke@435 382 // Implementation of UncommonTrapBlob
duke@435 383
duke@435 384 #ifdef COMPILER2
duke@435 385 UncommonTrapBlob::UncommonTrapBlob(
duke@435 386 CodeBuffer* cb,
duke@435 387 int size,
duke@435 388 OopMapSet* oop_maps,
duke@435 389 int frame_size
duke@435 390 )
duke@435 391 : SingletonBlob("UncommonTrapBlob", cb, sizeof(UncommonTrapBlob), size, frame_size, oop_maps)
duke@435 392 {}
duke@435 393
duke@435 394
duke@435 395 UncommonTrapBlob* UncommonTrapBlob::create(
duke@435 396 CodeBuffer* cb,
duke@435 397 OopMapSet* oop_maps,
duke@435 398 int frame_size)
duke@435 399 {
duke@435 400 UncommonTrapBlob* blob = NULL;
duke@435 401 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 402 {
duke@435 403 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 404 unsigned int size = allocation_size(cb, sizeof(UncommonTrapBlob));
duke@435 405 blob = new (size) UncommonTrapBlob(cb, size, oop_maps, frame_size);
duke@435 406 }
duke@435 407
duke@435 408 // Do not hold the CodeCache lock during name formatting.
duke@435 409 if (blob != NULL) {
duke@435 410 char blob_id[256];
duke@435 411 jio_snprintf(blob_id, sizeof(blob_id), "UncommonTrapBlob@" PTR_FORMAT, blob->instructions_begin());
duke@435 412 if (PrintStubCode) {
duke@435 413 tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob);
duke@435 414 Disassembler::decode(blob->instructions_begin(), blob->instructions_end());
duke@435 415 }
duke@435 416 Forte::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end());
duke@435 417
duke@435 418 if (JvmtiExport::should_post_dynamic_code_generated()) {
duke@435 419 JvmtiExport::post_dynamic_code_generated("UncommonTrapBlob",
duke@435 420 blob->instructions_begin(),
duke@435 421 blob->instructions_end());
duke@435 422 }
duke@435 423 }
duke@435 424
duke@435 425 // Track memory usage statistic after releasing CodeCache_lock
duke@435 426 MemoryService::track_code_cache_memory_usage();
duke@435 427
duke@435 428 return blob;
duke@435 429 }
duke@435 430
duke@435 431
duke@435 432 void* UncommonTrapBlob::operator new(size_t s, unsigned size) {
duke@435 433 void* p = CodeCache::allocate(size);
duke@435 434 if (!p) fatal("Initial size of CodeCache is too small");
duke@435 435 return p;
duke@435 436 }
duke@435 437 #endif // COMPILER2
duke@435 438
duke@435 439
duke@435 440 //----------------------------------------------------------------------------------------------------
duke@435 441 // Implementation of ExceptionBlob
duke@435 442
duke@435 443 #ifdef COMPILER2
duke@435 444 ExceptionBlob::ExceptionBlob(
duke@435 445 CodeBuffer* cb,
duke@435 446 int size,
duke@435 447 OopMapSet* oop_maps,
duke@435 448 int frame_size
duke@435 449 )
duke@435 450 : SingletonBlob("ExceptionBlob", cb, sizeof(ExceptionBlob), size, frame_size, oop_maps)
duke@435 451 {}
duke@435 452
duke@435 453
duke@435 454 ExceptionBlob* ExceptionBlob::create(
duke@435 455 CodeBuffer* cb,
duke@435 456 OopMapSet* oop_maps,
duke@435 457 int frame_size)
duke@435 458 {
duke@435 459 ExceptionBlob* blob = NULL;
duke@435 460 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 461 {
duke@435 462 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 463 unsigned int size = allocation_size(cb, sizeof(ExceptionBlob));
duke@435 464 blob = new (size) ExceptionBlob(cb, size, oop_maps, frame_size);
duke@435 465 }
duke@435 466
duke@435 467 // We do not need to hold the CodeCache lock during name formatting
duke@435 468 if (blob != NULL) {
duke@435 469 char blob_id[256];
duke@435 470 jio_snprintf(blob_id, sizeof(blob_id), "ExceptionBlob@" PTR_FORMAT, blob->instructions_begin());
duke@435 471 if (PrintStubCode) {
duke@435 472 tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob);
duke@435 473 Disassembler::decode(blob->instructions_begin(), blob->instructions_end());
duke@435 474 }
duke@435 475 Forte::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end());
duke@435 476
duke@435 477 if (JvmtiExport::should_post_dynamic_code_generated()) {
duke@435 478 JvmtiExport::post_dynamic_code_generated("ExceptionBlob",
duke@435 479 blob->instructions_begin(),
duke@435 480 blob->instructions_end());
duke@435 481 }
duke@435 482 }
duke@435 483
duke@435 484 // Track memory usage statistic after releasing CodeCache_lock
duke@435 485 MemoryService::track_code_cache_memory_usage();
duke@435 486
duke@435 487 return blob;
duke@435 488 }
duke@435 489
duke@435 490
duke@435 491 void* ExceptionBlob::operator new(size_t s, unsigned size) {
duke@435 492 void* p = CodeCache::allocate(size);
duke@435 493 if (!p) fatal("Initial size of CodeCache is too small");
duke@435 494 return p;
duke@435 495 }
duke@435 496 #endif // COMPILER2
duke@435 497
duke@435 498
duke@435 499 //----------------------------------------------------------------------------------------------------
duke@435 500 // Implementation of SafepointBlob
duke@435 501
duke@435 502 SafepointBlob::SafepointBlob(
duke@435 503 CodeBuffer* cb,
duke@435 504 int size,
duke@435 505 OopMapSet* oop_maps,
duke@435 506 int frame_size
duke@435 507 )
duke@435 508 : SingletonBlob("SafepointBlob", cb, sizeof(SafepointBlob), size, frame_size, oop_maps)
duke@435 509 {}
duke@435 510
duke@435 511
duke@435 512 SafepointBlob* SafepointBlob::create(
duke@435 513 CodeBuffer* cb,
duke@435 514 OopMapSet* oop_maps,
duke@435 515 int frame_size)
duke@435 516 {
duke@435 517 SafepointBlob* blob = NULL;
duke@435 518 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
duke@435 519 {
duke@435 520 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@435 521 unsigned int size = allocation_size(cb, sizeof(SafepointBlob));
duke@435 522 blob = new (size) SafepointBlob(cb, size, oop_maps, frame_size);
duke@435 523 }
duke@435 524
duke@435 525 // We do not need to hold the CodeCache lock during name formatting.
duke@435 526 if (blob != NULL) {
duke@435 527 char blob_id[256];
duke@435 528 jio_snprintf(blob_id, sizeof(blob_id), "SafepointBlob@" PTR_FORMAT, blob->instructions_begin());
duke@435 529 if (PrintStubCode) {
duke@435 530 tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob);
duke@435 531 Disassembler::decode(blob->instructions_begin(), blob->instructions_end());
duke@435 532 }
duke@435 533 Forte::register_stub(blob_id, blob->instructions_begin(), blob->instructions_end());
duke@435 534
duke@435 535 if (JvmtiExport::should_post_dynamic_code_generated()) {
duke@435 536 JvmtiExport::post_dynamic_code_generated("SafepointBlob",
duke@435 537 blob->instructions_begin(),
duke@435 538 blob->instructions_end());
duke@435 539 }
duke@435 540 }
duke@435 541
duke@435 542 // Track memory usage statistic after releasing CodeCache_lock
duke@435 543 MemoryService::track_code_cache_memory_usage();
duke@435 544
duke@435 545 return blob;
duke@435 546 }
duke@435 547
duke@435 548
duke@435 549 void* SafepointBlob::operator new(size_t s, unsigned size) {
duke@435 550 void* p = CodeCache::allocate(size);
duke@435 551 if (!p) fatal("Initial size of CodeCache is too small");
duke@435 552 return p;
duke@435 553 }
duke@435 554
duke@435 555
duke@435 556 //----------------------------------------------------------------------------------------------------
duke@435 557 // Verification and printing
duke@435 558
duke@435 559 void CodeBlob::verify() {
duke@435 560 ShouldNotReachHere();
duke@435 561 }
duke@435 562
duke@435 563 #ifndef PRODUCT
duke@435 564
duke@435 565 void CodeBlob::print() const {
duke@435 566 tty->print_cr("[CodeBlob (" INTPTR_FORMAT ")]", this);
duke@435 567 tty->print_cr("Framesize: %d", _frame_size);
duke@435 568 }
duke@435 569
duke@435 570
duke@435 571 void CodeBlob::print_value_on(outputStream* st) const {
duke@435 572 st->print_cr("[CodeBlob]");
duke@435 573 }
duke@435 574
duke@435 575 #endif
duke@435 576
duke@435 577 void BufferBlob::verify() {
duke@435 578 // unimplemented
duke@435 579 }
duke@435 580
duke@435 581 #ifndef PRODUCT
duke@435 582
duke@435 583 void BufferBlob::print() const {
duke@435 584 CodeBlob::print();
duke@435 585 print_value_on(tty);
duke@435 586 }
duke@435 587
duke@435 588
duke@435 589 void BufferBlob::print_value_on(outputStream* st) const {
duke@435 590 st->print_cr("BufferBlob (" INTPTR_FORMAT ") used for %s", this, name());
duke@435 591 }
duke@435 592
duke@435 593
duke@435 594 #endif
duke@435 595
duke@435 596 void RuntimeStub::verify() {
duke@435 597 // unimplemented
duke@435 598 }
duke@435 599
duke@435 600 #ifndef PRODUCT
duke@435 601
duke@435 602 void RuntimeStub::print() const {
duke@435 603 CodeBlob::print();
duke@435 604 tty->print("Runtime Stub (" INTPTR_FORMAT "): ", this);
duke@435 605 tty->print_cr(name());
duke@435 606 Disassembler::decode((CodeBlob*)this);
duke@435 607 }
duke@435 608
duke@435 609
duke@435 610 void RuntimeStub::print_value_on(outputStream* st) const {
duke@435 611 st->print("RuntimeStub (" INTPTR_FORMAT "): ", this); st->print(name());
duke@435 612 }
duke@435 613
duke@435 614 #endif
duke@435 615
duke@435 616 void SingletonBlob::verify() {
duke@435 617 // unimplemented
duke@435 618 }
duke@435 619
duke@435 620 #ifndef PRODUCT
duke@435 621
duke@435 622 void SingletonBlob::print() const {
duke@435 623 CodeBlob::print();
duke@435 624 tty->print_cr(name());
duke@435 625 Disassembler::decode((CodeBlob*)this);
duke@435 626 }
duke@435 627
duke@435 628
duke@435 629 void SingletonBlob::print_value_on(outputStream* st) const {
duke@435 630 st->print_cr(name());
duke@435 631 }
duke@435 632
duke@435 633 void DeoptimizationBlob::print_value_on(outputStream* st) const {
duke@435 634 st->print_cr("Deoptimization (frame not available)");
duke@435 635 }
duke@435 636
duke@435 637 #endif // PRODUCT

mercurial