< prev index next >

src/hotspot/share/jvmci/jvmciCodeInstaller.cpp

Print this page




 545   metadata.set_oop_recorder(recorder);
 546 
 547   // Get instructions and constants CodeSections early because we need it.
 548   _instructions = buffer.insts();
 549   _constants = buffer.consts();
 550   buffer.set_immutable_PIC(_immutable_pic_compilation);
 551 
 552   initialize_fields(target, compiled_code, JVMCI_CHECK_OK);
 553   JVMCI::CodeInstallResult result = initialize_buffer(buffer, false, JVMCI_CHECK_OK);
 554   if (result != JVMCI::ok) {
 555     return result;
 556   }
 557 
 558   _debug_recorder->pcs_size(); // create the sentinel record
 559 
 560   assert(_debug_recorder->pcs_length() >= 2, "must be at least 2");
 561 
 562   metadata.set_pc_desc(_debug_recorder->pcs(), _debug_recorder->pcs_length());
 563   metadata.set_scopes(_debug_recorder->stream()->buffer(), _debug_recorder->data_size());
 564   metadata.set_exception_table(&_exception_handler_table);

 565 
 566   RelocBuffer* reloc_buffer = metadata.get_reloc_buffer();
 567 
 568   reloc_buffer->ensure_size(buffer.total_relocation_size());
 569   size_t size = (size_t) buffer.copy_relocations_to(reloc_buffer->begin(), (CodeBuffer::csize_t) reloc_buffer->size(), true);
 570   reloc_buffer->set_size(size);
 571   return JVMCI::ok;
 572 }
 573 #endif // INCLUDE_AOT
 574 
 575 // constructor used to create a method
 576 JVMCI::CodeInstallResult CodeInstaller::install(JVMCICompiler* compiler,
 577     JVMCIObject target,
 578     JVMCIObject compiled_code,
 579     CodeBlob*& cb,
 580     JVMCIObject installed_code,
 581     FailedSpeculation** failed_speculations,
 582     char* speculations,
 583     int speculations_len,
 584     JVMCI_TRAPS) {


 620     if (compile_state != NULL) {
 621       jvmci_env()->set_compile_state(compile_state);
 622     }
 623 
 624     methodHandle method = jvmci_env()->asMethod(jvmci_env()->get_HotSpotCompiledNmethod_method(compiled_code));
 625     jint entry_bci = jvmci_env()->get_HotSpotCompiledNmethod_entryBCI(compiled_code);
 626     bool has_unsafe_access = jvmci_env()->get_HotSpotCompiledNmethod_hasUnsafeAccess(compiled_code) == JNI_TRUE;
 627     jint id = jvmci_env()->get_HotSpotCompiledNmethod_id(compiled_code);
 628     if (id == -1) {
 629       // Make sure a valid compile_id is associated with every compile
 630       id = CompileBroker::assign_compile_id_unlocked(Thread::current(), method, entry_bci);
 631       jvmci_env()->set_HotSpotCompiledNmethod_id(compiled_code, id);
 632     }
 633     if (!jvmci_env()->isa_HotSpotNmethod(installed_code)) {
 634       JVMCI_THROW_MSG_(IllegalArgumentException, "InstalledCode object must be a HotSpotNmethod when installing a HotSpotCompiledNmethod", JVMCI::ok);
 635     }
 636 
 637     JVMCIObject mirror = installed_code;
 638     nmethod* nm = NULL;
 639     result = runtime()->register_method(jvmci_env(), method, nm, entry_bci, &_offsets, _orig_pc_offset, &buffer,
 640                                         stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table,
 641                                         compiler, _debug_recorder, _dependencies, id,
 642                                         has_unsafe_access, _has_wide_vector, compiled_code, mirror,
 643                                         failed_speculations, speculations, speculations_len);
 644     cb = nm->as_codeblob_or_null();
 645     if (nm != NULL && compile_state == NULL) {
 646       DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, compiler);
 647       bool printnmethods = directive->PrintAssemblyOption || directive->PrintNMethodsOption;
 648       if (!printnmethods && (PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers)) {
 649         nm->print_nmethod(printnmethods);
 650       }
 651       DirectivesStack::release(directive);
 652     }
 653   }
 654 
 655   if (cb != NULL) {
 656     // Make sure the pre-calculated constants section size was correct.
 657     guarantee((cb->code_begin() - cb->content_begin()) >= _constants_size, "%d < %d", (int)(cb->code_begin() - cb->content_begin()), _constants_size);
 658   }
 659   return result;
 660 }


 852     JVMCIObject site = JVMCIENV->get_object_at(sites, i);
 853     if (site.is_null()) {
 854       JVMCI_THROW_(NullPointerException, JVMCI::ok);
 855     }
 856 
 857     jint pc_offset = jvmci_env()->get_site_Site_pcOffset(site);
 858 
 859     if (jvmci_env()->isa_site_Call(site)) {
 860       TRACE_jvmci_4("call at %i", pc_offset);
 861       site_Call(buffer, pc_offset, site, JVMCI_CHECK_OK);
 862     } else if (jvmci_env()->isa_site_Infopoint(site)) {
 863       // three reasons for infopoints denote actual safepoints
 864       JVMCIObject reason = jvmci_env()->get_site_Infopoint_reason(site);
 865       if (JVMCIENV->equals(reason, jvmci_env()->get_site_InfopointReason_SAFEPOINT()) ||
 866           JVMCIENV->equals(reason, jvmci_env()->get_site_InfopointReason_CALL()) ||
 867           JVMCIENV->equals(reason, jvmci_env()->get_site_InfopointReason_IMPLICIT_EXCEPTION())) {
 868         TRACE_jvmci_4("safepoint at %i", pc_offset);
 869         site_Safepoint(buffer, pc_offset, site, JVMCI_CHECK_OK);
 870         if (_orig_pc_offset < 0) {
 871           JVMCI_ERROR_OK("method contains safepoint, but has no deopt rescue slot");




 872         }
 873       } else {
 874         TRACE_jvmci_4("infopoint at %i", pc_offset);
 875         site_Infopoint(buffer, pc_offset, site, JVMCI_CHECK_OK);
 876       }
 877     } else if (jvmci_env()->isa_site_DataPatch(site)) {
 878       TRACE_jvmci_4("datapatch at %i", pc_offset);
 879       site_DataPatch(buffer, pc_offset, site, JVMCI_CHECK_OK);
 880     } else if (jvmci_env()->isa_site_Mark(site)) {
 881       TRACE_jvmci_4("mark at %i", pc_offset);
 882       site_Mark(buffer, pc_offset, site, JVMCI_CHECK_OK);
 883     } else if (jvmci_env()->isa_site_ExceptionHandler(site)) {
 884       TRACE_jvmci_4("exceptionhandler at %i", pc_offset);
 885       site_ExceptionHandler(pc_offset, site);
 886     } else {
 887       JVMCI_ERROR_OK("unexpected site subclass: %s", jvmci_env()->klass_name(site));
 888     }
 889     last_pc_offset = pc_offset;
 890 
 891     JavaThread* thread = JavaThread::current();




 545   metadata.set_oop_recorder(recorder);
 546 
 547   // Get instructions and constants CodeSections early because we need it.
 548   _instructions = buffer.insts();
 549   _constants = buffer.consts();
 550   buffer.set_immutable_PIC(_immutable_pic_compilation);
 551 
 552   initialize_fields(target, compiled_code, JVMCI_CHECK_OK);
 553   JVMCI::CodeInstallResult result = initialize_buffer(buffer, false, JVMCI_CHECK_OK);
 554   if (result != JVMCI::ok) {
 555     return result;
 556   }
 557 
 558   _debug_recorder->pcs_size(); // create the sentinel record
 559 
 560   assert(_debug_recorder->pcs_length() >= 2, "must be at least 2");
 561 
 562   metadata.set_pc_desc(_debug_recorder->pcs(), _debug_recorder->pcs_length());
 563   metadata.set_scopes(_debug_recorder->stream()->buffer(), _debug_recorder->data_size());
 564   metadata.set_exception_table(&_exception_handler_table);
 565   metadata.set_implicit_exception_table(&_implicit_exception_table);
 566 
 567   RelocBuffer* reloc_buffer = metadata.get_reloc_buffer();
 568 
 569   reloc_buffer->ensure_size(buffer.total_relocation_size());
 570   size_t size = (size_t) buffer.copy_relocations_to(reloc_buffer->begin(), (CodeBuffer::csize_t) reloc_buffer->size(), true);
 571   reloc_buffer->set_size(size);
 572   return JVMCI::ok;
 573 }
 574 #endif // INCLUDE_AOT
 575 
 576 // constructor used to create a method
 577 JVMCI::CodeInstallResult CodeInstaller::install(JVMCICompiler* compiler,
 578     JVMCIObject target,
 579     JVMCIObject compiled_code,
 580     CodeBlob*& cb,
 581     JVMCIObject installed_code,
 582     FailedSpeculation** failed_speculations,
 583     char* speculations,
 584     int speculations_len,
 585     JVMCI_TRAPS) {


 621     if (compile_state != NULL) {
 622       jvmci_env()->set_compile_state(compile_state);
 623     }
 624 
 625     methodHandle method = jvmci_env()->asMethod(jvmci_env()->get_HotSpotCompiledNmethod_method(compiled_code));
 626     jint entry_bci = jvmci_env()->get_HotSpotCompiledNmethod_entryBCI(compiled_code);
 627     bool has_unsafe_access = jvmci_env()->get_HotSpotCompiledNmethod_hasUnsafeAccess(compiled_code) == JNI_TRUE;
 628     jint id = jvmci_env()->get_HotSpotCompiledNmethod_id(compiled_code);
 629     if (id == -1) {
 630       // Make sure a valid compile_id is associated with every compile
 631       id = CompileBroker::assign_compile_id_unlocked(Thread::current(), method, entry_bci);
 632       jvmci_env()->set_HotSpotCompiledNmethod_id(compiled_code, id);
 633     }
 634     if (!jvmci_env()->isa_HotSpotNmethod(installed_code)) {
 635       JVMCI_THROW_MSG_(IllegalArgumentException, "InstalledCode object must be a HotSpotNmethod when installing a HotSpotCompiledNmethod", JVMCI::ok);
 636     }
 637 
 638     JVMCIObject mirror = installed_code;
 639     nmethod* nm = NULL;
 640     result = runtime()->register_method(jvmci_env(), method, nm, entry_bci, &_offsets, _orig_pc_offset, &buffer,
 641                                         stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, &_implicit_exception_table,
 642                                         compiler, _debug_recorder, _dependencies, id,
 643                                         has_unsafe_access, _has_wide_vector, compiled_code, mirror,
 644                                         failed_speculations, speculations, speculations_len);
 645     cb = nm->as_codeblob_or_null();
 646     if (nm != NULL && compile_state == NULL) {
 647       DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, compiler);
 648       bool printnmethods = directive->PrintAssemblyOption || directive->PrintNMethodsOption;
 649       if (!printnmethods && (PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers)) {
 650         nm->print_nmethod(printnmethods);
 651       }
 652       DirectivesStack::release(directive);
 653     }
 654   }
 655 
 656   if (cb != NULL) {
 657     // Make sure the pre-calculated constants section size was correct.
 658     guarantee((cb->code_begin() - cb->content_begin()) >= _constants_size, "%d < %d", (int)(cb->code_begin() - cb->content_begin()), _constants_size);
 659   }
 660   return result;
 661 }


 853     JVMCIObject site = JVMCIENV->get_object_at(sites, i);
 854     if (site.is_null()) {
 855       JVMCI_THROW_(NullPointerException, JVMCI::ok);
 856     }
 857 
 858     jint pc_offset = jvmci_env()->get_site_Site_pcOffset(site);
 859 
 860     if (jvmci_env()->isa_site_Call(site)) {
 861       TRACE_jvmci_4("call at %i", pc_offset);
 862       site_Call(buffer, pc_offset, site, JVMCI_CHECK_OK);
 863     } else if (jvmci_env()->isa_site_Infopoint(site)) {
 864       // three reasons for infopoints denote actual safepoints
 865       JVMCIObject reason = jvmci_env()->get_site_Infopoint_reason(site);
 866       if (JVMCIENV->equals(reason, jvmci_env()->get_site_InfopointReason_SAFEPOINT()) ||
 867           JVMCIENV->equals(reason, jvmci_env()->get_site_InfopointReason_CALL()) ||
 868           JVMCIENV->equals(reason, jvmci_env()->get_site_InfopointReason_IMPLICIT_EXCEPTION())) {
 869         TRACE_jvmci_4("safepoint at %i", pc_offset);
 870         site_Safepoint(buffer, pc_offset, site, JVMCI_CHECK_OK);
 871         if (_orig_pc_offset < 0) {
 872           JVMCI_ERROR_OK("method contains safepoint, but has no deopt rescue slot");
 873         }
 874         if (JVMCIENV->equals(reason, jvmci_env()->get_site_InfopointReason_IMPLICIT_EXCEPTION())) {
 875           TRACE_jvmci_4("implicit exception at %i", pc_offset);
 876           _implicit_exception_table.add_deoptimize(pc_offset);
 877         }
 878       } else {
 879         TRACE_jvmci_4("infopoint at %i", pc_offset);
 880         site_Infopoint(buffer, pc_offset, site, JVMCI_CHECK_OK);
 881       }
 882     } else if (jvmci_env()->isa_site_DataPatch(site)) {
 883       TRACE_jvmci_4("datapatch at %i", pc_offset);
 884       site_DataPatch(buffer, pc_offset, site, JVMCI_CHECK_OK);
 885     } else if (jvmci_env()->isa_site_Mark(site)) {
 886       TRACE_jvmci_4("mark at %i", pc_offset);
 887       site_Mark(buffer, pc_offset, site, JVMCI_CHECK_OK);
 888     } else if (jvmci_env()->isa_site_ExceptionHandler(site)) {
 889       TRACE_jvmci_4("exceptionhandler at %i", pc_offset);
 890       site_ExceptionHandler(pc_offset, site);
 891     } else {
 892       JVMCI_ERROR_OK("unexpected site subclass: %s", jvmci_env()->klass_name(site));
 893     }
 894     last_pc_offset = pc_offset;
 895 
 896     JavaThread* thread = JavaThread::current();


< prev index next >