src/share/vm/code/codeBlob.cpp

changeset 2895
167b70ff3abc
parent 2708
1d1603768966
child 3900
d2a62e0f25eb
equal deleted inserted replaced
2894:d4c1fbc3de95 2895:167b70ff3abc
150 _oop_maps = NULL; 150 _oop_maps = NULL;
151 } 151 }
152 } 152 }
153 153
154 154
155 void CodeBlob::trace_new_stub(CodeBlob* stub, const char* name1, const char* name2) {
156 // Do not hold the CodeCache lock during name formatting.
157 assert(!CodeCache_lock->owned_by_self(), "release CodeCache before registering the stub");
158
159 if (stub != NULL) {
160 char stub_id[256];
161 assert(strlen(name1) + strlen(name2) < sizeof(stub_id), "");
162 jio_snprintf(stub_id, sizeof(stub_id), "%s%s", name1, name2);
163 if (PrintStubCode) {
164 tty->print_cr("Decoding %s " INTPTR_FORMAT, stub_id, (intptr_t) stub);
165 Disassembler::decode(stub->code_begin(), stub->code_end());
166 }
167 Forte::register_stub(stub_id, stub->code_begin(), stub->code_end());
168
169 if (JvmtiExport::should_post_dynamic_code_generated()) {
170 const char* stub_name = name2;
171 if (name2[0] == '\0') stub_name = name1;
172 JvmtiExport::post_dynamic_code_generated(stub_name, stub->code_begin(), stub->code_end());
173 }
174 }
175
176 // Track memory usage statistic after releasing CodeCache_lock
177 MemoryService::track_code_cache_memory_usage();
178 }
179
180
155 void CodeBlob::flush() { 181 void CodeBlob::flush() {
156 if (_oop_maps) { 182 if (_oop_maps) {
157 FREE_C_HEAP_ARRAY(unsigned char, _oop_maps); 183 FREE_C_HEAP_ARRAY(unsigned char, _oop_maps);
158 _oop_maps = NULL; 184 _oop_maps = NULL;
159 } 185 }
310 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 336 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
311 unsigned int size = allocation_size(cb, sizeof(RuntimeStub)); 337 unsigned int size = allocation_size(cb, sizeof(RuntimeStub));
312 stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments); 338 stub = new (size) RuntimeStub(stub_name, cb, size, frame_complete, frame_size, oop_maps, caller_must_gc_arguments);
313 } 339 }
314 340
315 // Do not hold the CodeCache lock during name formatting. 341 trace_new_stub(stub, "RuntimeStub - ", stub_name);
316 if (stub != NULL) {
317 char stub_id[256];
318 jio_snprintf(stub_id, sizeof(stub_id), "RuntimeStub - %s", stub_name);
319 if (PrintStubCode) {
320 tty->print_cr("Decoding %s " INTPTR_FORMAT, stub_id, stub);
321 Disassembler::decode(stub->code_begin(), stub->code_end());
322 }
323 Forte::register_stub(stub_id, stub->code_begin(), stub->code_end());
324
325 if (JvmtiExport::should_post_dynamic_code_generated()) {
326 JvmtiExport::post_dynamic_code_generated(stub_name, stub->code_begin(), stub->code_end());
327 }
328 }
329
330 // Track memory usage statistic after releasing CodeCache_lock
331 MemoryService::track_code_cache_memory_usage();
332 342
333 return stub; 343 return stub;
334 } 344 }
335 345
336 346
337 void* RuntimeStub::operator new(size_t s, unsigned size) { 347 void* RuntimeStub::operator new(size_t s, unsigned size) {
338 void* p = CodeCache::allocate(size); 348 void* p = CodeCache::allocate(size);
339 if (!p) fatal("Initial size of CodeCache is too small"); 349 if (!p) fatal("Initial size of CodeCache is too small");
340 return p; 350 return p;
351 }
352
353 // operator new shared by all singletons:
354 void* SingletonBlob::operator new(size_t s, unsigned size) {
355 void* p = CodeCache::allocate(size);
356 if (!p) fatal("Initial size of CodeCache is too small");
357 return p;
358 }
359
360
361 //----------------------------------------------------------------------------------------------------
362 // Implementation of RicochetBlob
363
364 RicochetBlob::RicochetBlob(
365 CodeBuffer* cb,
366 int size,
367 int bounce_offset,
368 int exception_offset,
369 int frame_size
370 )
371 : SingletonBlob("RicochetBlob", cb, sizeof(RicochetBlob), size, frame_size, (OopMapSet*) NULL)
372 {
373 _bounce_offset = bounce_offset;
374 _exception_offset = exception_offset;
375 }
376
377
378 RicochetBlob* RicochetBlob::create(
379 CodeBuffer* cb,
380 int bounce_offset,
381 int exception_offset,
382 int frame_size)
383 {
384 RicochetBlob* blob = NULL;
385 ThreadInVMfromUnknown __tiv; // get to VM state in case we block on CodeCache_lock
386 {
387 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
388 unsigned int size = allocation_size(cb, sizeof(RicochetBlob));
389 blob = new (size) RicochetBlob(cb, size, bounce_offset, exception_offset, frame_size);
390 }
391
392 trace_new_stub(blob, "RicochetBlob");
393
394 return blob;
341 } 395 }
342 396
343 397
344 //---------------------------------------------------------------------------------------------------- 398 //----------------------------------------------------------------------------------------------------
345 // Implementation of DeoptimizationBlob 399 // Implementation of DeoptimizationBlob
384 unpack_with_exception_offset, 438 unpack_with_exception_offset,
385 unpack_with_reexecution_offset, 439 unpack_with_reexecution_offset,
386 frame_size); 440 frame_size);
387 } 441 }
388 442
389 // Do not hold the CodeCache lock during name formatting. 443 trace_new_stub(blob, "DeoptimizationBlob");
390 if (blob != NULL) { 444
391 char blob_id[256]; 445 return blob;
392 jio_snprintf(blob_id, sizeof(blob_id), "DeoptimizationBlob@" PTR_FORMAT, blob->code_begin()); 446 }
393 if (PrintStubCode) { 447
394 tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob);
395 Disassembler::decode(blob->code_begin(), blob->code_end());
396 }
397 Forte::register_stub(blob_id, blob->code_begin(), blob->code_end());
398
399 if (JvmtiExport::should_post_dynamic_code_generated()) {
400 JvmtiExport::post_dynamic_code_generated("DeoptimizationBlob", blob->code_begin(), blob->code_end());
401 }
402 }
403
404 // Track memory usage statistic after releasing CodeCache_lock
405 MemoryService::track_code_cache_memory_usage();
406
407 return blob;
408 }
409
410
411 void* DeoptimizationBlob::operator new(size_t s, unsigned size) {
412 void* p = CodeCache::allocate(size);
413 if (!p) fatal("Initial size of CodeCache is too small");
414 return p;
415 }
416 448
417 //---------------------------------------------------------------------------------------------------- 449 //----------------------------------------------------------------------------------------------------
418 // Implementation of UncommonTrapBlob 450 // Implementation of UncommonTrapBlob
419 451
420 #ifdef COMPILER2 452 #ifdef COMPILER2
439 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 471 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
440 unsigned int size = allocation_size(cb, sizeof(UncommonTrapBlob)); 472 unsigned int size = allocation_size(cb, sizeof(UncommonTrapBlob));
441 blob = new (size) UncommonTrapBlob(cb, size, oop_maps, frame_size); 473 blob = new (size) UncommonTrapBlob(cb, size, oop_maps, frame_size);
442 } 474 }
443 475
444 // Do not hold the CodeCache lock during name formatting. 476 trace_new_stub(blob, "UncommonTrapBlob");
445 if (blob != NULL) { 477
446 char blob_id[256]; 478 return blob;
447 jio_snprintf(blob_id, sizeof(blob_id), "UncommonTrapBlob@" PTR_FORMAT, blob->code_begin()); 479 }
448 if (PrintStubCode) { 480
449 tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob); 481
450 Disassembler::decode(blob->code_begin(), blob->code_end());
451 }
452 Forte::register_stub(blob_id, blob->code_begin(), blob->code_end());
453
454 if (JvmtiExport::should_post_dynamic_code_generated()) {
455 JvmtiExport::post_dynamic_code_generated("UncommonTrapBlob", blob->code_begin(), blob->code_end());
456 }
457 }
458
459 // Track memory usage statistic after releasing CodeCache_lock
460 MemoryService::track_code_cache_memory_usage();
461
462 return blob;
463 }
464
465
466 void* UncommonTrapBlob::operator new(size_t s, unsigned size) {
467 void* p = CodeCache::allocate(size);
468 if (!p) fatal("Initial size of CodeCache is too small");
469 return p;
470 }
471 #endif // COMPILER2 482 #endif // COMPILER2
472 483
473 484
474 //---------------------------------------------------------------------------------------------------- 485 //----------------------------------------------------------------------------------------------------
475 // Implementation of ExceptionBlob 486 // Implementation of ExceptionBlob
496 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 507 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
497 unsigned int size = allocation_size(cb, sizeof(ExceptionBlob)); 508 unsigned int size = allocation_size(cb, sizeof(ExceptionBlob));
498 blob = new (size) ExceptionBlob(cb, size, oop_maps, frame_size); 509 blob = new (size) ExceptionBlob(cb, size, oop_maps, frame_size);
499 } 510 }
500 511
501 // We do not need to hold the CodeCache lock during name formatting 512 trace_new_stub(blob, "ExceptionBlob");
502 if (blob != NULL) { 513
503 char blob_id[256]; 514 return blob;
504 jio_snprintf(blob_id, sizeof(blob_id), "ExceptionBlob@" PTR_FORMAT, blob->code_begin()); 515 }
505 if (PrintStubCode) { 516
506 tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob); 517
507 Disassembler::decode(blob->code_begin(), blob->code_end());
508 }
509 Forte::register_stub(blob_id, blob->code_begin(), blob->code_end());
510
511 if (JvmtiExport::should_post_dynamic_code_generated()) {
512 JvmtiExport::post_dynamic_code_generated("ExceptionBlob", blob->code_begin(), blob->code_end());
513 }
514 }
515
516 // Track memory usage statistic after releasing CodeCache_lock
517 MemoryService::track_code_cache_memory_usage();
518
519 return blob;
520 }
521
522
523 void* ExceptionBlob::operator new(size_t s, unsigned size) {
524 void* p = CodeCache::allocate(size);
525 if (!p) fatal("Initial size of CodeCache is too small");
526 return p;
527 }
528 #endif // COMPILER2 518 #endif // COMPILER2
529 519
530 520
531 //---------------------------------------------------------------------------------------------------- 521 //----------------------------------------------------------------------------------------------------
532 // Implementation of SafepointBlob 522 // Implementation of SafepointBlob
552 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 542 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
553 unsigned int size = allocation_size(cb, sizeof(SafepointBlob)); 543 unsigned int size = allocation_size(cb, sizeof(SafepointBlob));
554 blob = new (size) SafepointBlob(cb, size, oop_maps, frame_size); 544 blob = new (size) SafepointBlob(cb, size, oop_maps, frame_size);
555 } 545 }
556 546
557 // We do not need to hold the CodeCache lock during name formatting. 547 trace_new_stub(blob, "SafepointBlob");
558 if (blob != NULL) { 548
559 char blob_id[256]; 549 return blob;
560 jio_snprintf(blob_id, sizeof(blob_id), "SafepointBlob@" PTR_FORMAT, blob->code_begin());
561 if (PrintStubCode) {
562 tty->print_cr("Decoding %s " INTPTR_FORMAT, blob_id, blob);
563 Disassembler::decode(blob->code_begin(), blob->code_end());
564 }
565 Forte::register_stub(blob_id, blob->code_begin(), blob->code_end());
566
567 if (JvmtiExport::should_post_dynamic_code_generated()) {
568 JvmtiExport::post_dynamic_code_generated("SafepointBlob", blob->code_begin(), blob->code_end());
569 }
570 }
571
572 // Track memory usage statistic after releasing CodeCache_lock
573 MemoryService::track_code_cache_memory_usage();
574
575 return blob;
576 }
577
578
579 void* SafepointBlob::operator new(size_t s, unsigned size) {
580 void* p = CodeCache::allocate(size);
581 if (!p) fatal("Initial size of CodeCache is too small");
582 return p;
583 } 550 }
584 551
585 552
586 //---------------------------------------------------------------------------------------------------- 553 //----------------------------------------------------------------------------------------------------
587 // Verification and printing 554 // Verification and printing

mercurial