src/share/vm/code/nmethod.cpp

Print this page
rev 4338 : imported patch JDK-8009026


 485   _trap_offset             = 0;
 486 #endif // def HAVE_DTRACE_H
 487 }
 488 
 489 
 490 nmethod* nmethod::new_native_nmethod(methodHandle method,
 491   int compile_id,
 492   CodeBuffer *code_buffer,
 493   int vep_offset,
 494   int frame_complete,
 495   int frame_size,
 496   ByteSize basic_lock_owner_sp_offset,
 497   ByteSize basic_lock_sp_offset,
 498   OopMapSet* oop_maps) {
 499   code_buffer->finalize_oop_references(method);
 500   // create nmethod
 501   nmethod* nm = NULL;
 502   {
 503     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 504     int native_nmethod_size = allocation_size(code_buffer, sizeof(nmethod));


 505     CodeOffsets offsets;
 506     offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
 507     offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
 508     nm = new (native_nmethod_size)
 509       nmethod(method(), native_nmethod_size, compile_id, &offsets,
 510               code_buffer, frame_size,
 511               basic_lock_owner_sp_offset, basic_lock_sp_offset,
 512               oop_maps);
 513     NOT_PRODUCT(if (nm != NULL)  nmethod_stats.note_native_nmethod(nm));
 514     if (PrintAssembly && nm != NULL)
 515       Disassembler::decode(nm);
 516   }
 517   // verify nmethod
 518   debug_only(if (nm) nm->verify();) // might block
 519 
 520   if (nm != NULL) {
 521     nm->log_new_nmethod();
 522   }
 523 
 524   return nm;
 525 }
 526 
 527 #ifdef HAVE_DTRACE_H
 528 nmethod* nmethod::new_dtrace_nmethod(methodHandle method,
 529                                      CodeBuffer *code_buffer,
 530                                      int vep_offset,
 531                                      int trap_offset,
 532                                      int frame_complete,
 533                                      int frame_size) {
 534   code_buffer->finalize_oop_references(method);
 535   // create nmethod
 536   nmethod* nm = NULL;
 537   {
 538     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 539     int nmethod_size = allocation_size(code_buffer, sizeof(nmethod));


 540     CodeOffsets offsets;
 541     offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
 542     offsets.set_value(CodeOffsets::Dtrace_trap, trap_offset);
 543     offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
 544 
 545     nm = new (nmethod_size) nmethod(method(), nmethod_size, &offsets, code_buffer, frame_size);
 546 
 547     NOT_PRODUCT(if (nm != NULL)  nmethod_stats.note_nmethod(nm));
 548     if (PrintAssembly && nm != NULL)
 549       Disassembler::decode(nm);
 550   }
 551   // verify nmethod
 552   debug_only(if (nm) nm->verify();) // might block
 553 
 554   if (nm != NULL) {
 555     nm->log_new_nmethod();
 556   }
 557 
 558   return nm;
 559 }


 570   CodeBuffer* code_buffer, int frame_size,
 571   OopMapSet* oop_maps,
 572   ExceptionHandlerTable* handler_table,
 573   ImplicitExceptionTable* nul_chk_table,
 574   AbstractCompiler* compiler,
 575   int comp_level
 576 )
 577 {
 578   assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR");
 579   code_buffer->finalize_oop_references(method);
 580   // create nmethod
 581   nmethod* nm = NULL;
 582   { MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 583     int nmethod_size =
 584       allocation_size(code_buffer, sizeof(nmethod))
 585       + adjust_pcs_size(debug_info->pcs_size())
 586       + round_to(dependencies->size_in_bytes() , oopSize)
 587       + round_to(handler_table->size_in_bytes(), oopSize)
 588       + round_to(nul_chk_table->size_in_bytes(), oopSize)
 589       + round_to(debug_info->data_size()       , oopSize);


 590     nm = new (nmethod_size)
 591       nmethod(method(), nmethod_size, compile_id, entry_bci, offsets,
 592               orig_pc_offset, debug_info, dependencies, code_buffer, frame_size,
 593               oop_maps,
 594               handler_table,
 595               nul_chk_table,
 596               compiler,
 597               comp_level);
 598     if (nm != NULL) {
 599       // To make dependency checking during class loading fast, record
 600       // the nmethod dependencies in the classes it is dependent on.
 601       // This allows the dependency checking code to simply walk the
 602       // class hierarchy above the loaded class, checking only nmethods
 603       // which are dependent on those classes.  The slow way is to
 604       // check every nmethod for dependencies which makes it linear in
 605       // the number of methods compiled.  For applications with a lot
 606       // classes the slow way is too slow.
 607       for (Dependencies::DepStream deps(nm); deps.next(); ) {
 608         Klass* klass = deps.context_type();
 609         if (klass == NULL)  continue;  // ignore things like evol_method


 776       xtty->stamp();
 777       xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
 778     }
 779     // print the header part first
 780     print();
 781     // then print the requested information
 782     if (PrintNMethods) {
 783       print_code();
 784     }
 785     if (PrintRelocations) {
 786       print_relocations();
 787     }
 788     if (xtty != NULL) {
 789       xtty->tail("print_dtrace_nmethod");
 790     }
 791   }
 792 }
 793 #endif // def HAVE_DTRACE_H
 794 
 795 void* nmethod::operator new(size_t size, int nmethod_size) {
 796   // Always leave some room in the CodeCache for I2C/C2I adapters
 797   if (CodeCache::largest_free_block() < CodeCacheMinimumFreeSpace) return NULL;
 798   return CodeCache::allocate(nmethod_size);
 799 }
 800 
 801 
 802 nmethod::nmethod(
 803   Method* method,
 804   int nmethod_size,
 805   int compile_id,
 806   int entry_bci,
 807   CodeOffsets* offsets,
 808   int orig_pc_offset,
 809   DebugInformationRecorder* debug_info,
 810   Dependencies* dependencies,
 811   CodeBuffer *code_buffer,
 812   int frame_size,
 813   OopMapSet* oop_maps,
 814   ExceptionHandlerTable* handler_table,
 815   ImplicitExceptionTable* nul_chk_table,
 816   AbstractCompiler* compiler,
 817   int comp_level
 818   )




 485   _trap_offset             = 0;
 486 #endif // def HAVE_DTRACE_H
 487 }
 488 
 489 
 490 nmethod* nmethod::new_native_nmethod(methodHandle method,
 491   int compile_id,
 492   CodeBuffer *code_buffer,
 493   int vep_offset,
 494   int frame_complete,
 495   int frame_size,
 496   ByteSize basic_lock_owner_sp_offset,
 497   ByteSize basic_lock_sp_offset,
 498   OopMapSet* oop_maps) {
 499   code_buffer->finalize_oop_references(method);
 500   // create nmethod
 501   nmethod* nm = NULL;
 502   {
 503     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 504     int native_nmethod_size = allocation_size(code_buffer, sizeof(nmethod));
 505     guarantee(CodeCache::largest_free_block() > (CodeCacheMinimumFreeSpace + native_nmethod_size),
 506               "insufficient space for native method");
 507     CodeOffsets offsets;
 508     offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
 509     offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
 510     nm = new (native_nmethod_size)
 511       nmethod(method(), native_nmethod_size, compile_id, &offsets,
 512               code_buffer, frame_size,
 513               basic_lock_owner_sp_offset, basic_lock_sp_offset,
 514               oop_maps);
 515     NOT_PRODUCT(if (nm != NULL)  nmethod_stats.note_native_nmethod(nm));
 516     if (PrintAssembly && nm != NULL)
 517       Disassembler::decode(nm);
 518   }
 519   // verify nmethod
 520   debug_only(if (nm) nm->verify();) // might block
 521 
 522   if (nm != NULL) {
 523     nm->log_new_nmethod();
 524   }
 525 
 526   return nm;
 527 }
 528 
 529 #ifdef HAVE_DTRACE_H
 530 nmethod* nmethod::new_dtrace_nmethod(methodHandle method,
 531                                      CodeBuffer *code_buffer,
 532                                      int vep_offset,
 533                                      int trap_offset,
 534                                      int frame_complete,
 535                                      int frame_size) {
 536   code_buffer->finalize_oop_references(method);
 537   // create nmethod
 538   nmethod* nm = NULL;
 539   {
 540     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 541     int nmethod_size = allocation_size(code_buffer, sizeof(nmethod));
 542     guarantee(CodeCache::largest_free_block() > (CodeCacheMinimumFreeSpace + nmethod_size),
 543               "insufficient space for dtrace method");
 544     CodeOffsets offsets;
 545     offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
 546     offsets.set_value(CodeOffsets::Dtrace_trap, trap_offset);
 547     offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
 548 
 549     nm = new (nmethod_size) nmethod(method(), nmethod_size, &offsets, code_buffer, frame_size);
 550 
 551     NOT_PRODUCT(if (nm != NULL)  nmethod_stats.note_nmethod(nm));
 552     if (PrintAssembly && nm != NULL)
 553       Disassembler::decode(nm);
 554   }
 555   // verify nmethod
 556   debug_only(if (nm) nm->verify();) // might block
 557 
 558   if (nm != NULL) {
 559     nm->log_new_nmethod();
 560   }
 561 
 562   return nm;
 563 }


 574   CodeBuffer* code_buffer, int frame_size,
 575   OopMapSet* oop_maps,
 576   ExceptionHandlerTable* handler_table,
 577   ImplicitExceptionTable* nul_chk_table,
 578   AbstractCompiler* compiler,
 579   int comp_level
 580 )
 581 {
 582   assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR");
 583   code_buffer->finalize_oop_references(method);
 584   // create nmethod
 585   nmethod* nm = NULL;
 586   { MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 587     int nmethod_size =
 588       allocation_size(code_buffer, sizeof(nmethod))
 589       + adjust_pcs_size(debug_info->pcs_size())
 590       + round_to(dependencies->size_in_bytes() , oopSize)
 591       + round_to(handler_table->size_in_bytes(), oopSize)
 592       + round_to(nul_chk_table->size_in_bytes(), oopSize)
 593       + round_to(debug_info->data_size()       , oopSize);
 594     guarantee(CodeCache::largest_free_block() > (CodeCacheMinimumFreeSpace + nmethod_size),
 595               "insufficient space for nmethod");
 596     nm = new (nmethod_size)
 597       nmethod(method(), nmethod_size, compile_id, entry_bci, offsets,
 598               orig_pc_offset, debug_info, dependencies, code_buffer, frame_size,
 599               oop_maps,
 600               handler_table,
 601               nul_chk_table,
 602               compiler,
 603               comp_level);
 604     if (nm != NULL) {
 605       // To make dependency checking during class loading fast, record
 606       // the nmethod dependencies in the classes it is dependent on.
 607       // This allows the dependency checking code to simply walk the
 608       // class hierarchy above the loaded class, checking only nmethods
 609       // which are dependent on those classes.  The slow way is to
 610       // check every nmethod for dependencies which makes it linear in
 611       // the number of methods compiled.  For applications with a lot
 612       // classes the slow way is too slow.
 613       for (Dependencies::DepStream deps(nm); deps.next(); ) {
 614         Klass* klass = deps.context_type();
 615         if (klass == NULL)  continue;  // ignore things like evol_method


 782       xtty->stamp();
 783       xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this);
 784     }
 785     // print the header part first
 786     print();
 787     // then print the requested information
 788     if (PrintNMethods) {
 789       print_code();
 790     }
 791     if (PrintRelocations) {
 792       print_relocations();
 793     }
 794     if (xtty != NULL) {
 795       xtty->tail("print_dtrace_nmethod");
 796     }
 797   }
 798 }
 799 #endif // def HAVE_DTRACE_H
 800 
 801 void* nmethod::operator new(size_t size, int nmethod_size) {
 802   void*  alloc = CodeCache::allocate(nmethod_size);
 803   guarantee(alloc != NULL, "CodeCache should have enough space");
 804   return alloc;
 805 }
 806 
 807 
 808 nmethod::nmethod(
 809   Method* method,
 810   int nmethod_size,
 811   int compile_id,
 812   int entry_bci,
 813   CodeOffsets* offsets,
 814   int orig_pc_offset,
 815   DebugInformationRecorder* debug_info,
 816   Dependencies* dependencies,
 817   CodeBuffer *code_buffer,
 818   int frame_size,
 819   OopMapSet* oop_maps,
 820   ExceptionHandlerTable* handler_table,
 821   ImplicitExceptionTable* nul_chk_table,
 822   AbstractCompiler* compiler,
 823   int comp_level
 824   )