< 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   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 }


 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();
 897     if (SafepointMechanism::should_block(thread)) {


 976     case Bytecodes::_invokestatic:
 977       return false;
 978     default:
 979       return true;
 980     }
 981   return true;
 982 }
 983 
 984 GrowableArray<ScopeValue*>* CodeInstaller::record_virtual_objects(JVMCIObject debug_info, JVMCI_TRAPS) {
 985   JVMCIObjectArray virtualObjects = jvmci_env()->get_DebugInfo_virtualObjectMapping(debug_info);
 986   if (virtualObjects.is_null()) {
 987     return NULL;
 988   }
 989   GrowableArray<ScopeValue*>* objects = new GrowableArray<ScopeValue*>(JVMCIENV->get_length(virtualObjects), JVMCIENV->get_length(virtualObjects), NULL);
 990   // Create the unique ObjectValues
 991   for (int i = 0; i < JVMCIENV->get_length(virtualObjects); i++) {
 992     // HandleMark hm(THREAD);
 993     JVMCIObject value = JVMCIENV->get_object_at(virtualObjects, i);
 994     int id = jvmci_env()->get_VirtualObject_id(value);
 995     JVMCIObject type = jvmci_env()->get_VirtualObject_type(value);
 996     bool is_auto_box = jvmci_env()->get_VirtualObject_isAutoBox(value);
 997     Klass* klass = jvmci_env()->asKlass(type);
 998     oop javaMirror = klass->java_mirror();
 999     ScopeValue *klass_sv = new ConstantOopWriteValue(JNIHandles::make_local(Thread::current(), javaMirror));
1000     ObjectValue* sv = is_auto_box ? new AutoBoxObjectValue(id, klass_sv) : new ObjectValue(id, klass_sv);
1001     if (id < 0 || id >= objects->length()) {
1002       JVMCI_ERROR_NULL("virtual object id %d out of bounds", id);
1003     }
1004     if (objects->at(id) != NULL) {
1005       JVMCI_ERROR_NULL("duplicate virtual object id %d", id);
1006     }
1007     objects->at_put(id, sv);
1008   }
1009   // All the values which could be referenced by the VirtualObjects
1010   // exist, so now describe all the VirtualObjects themselves.
1011   for (int i = 0; i < JVMCIENV->get_length(virtualObjects); i++) {
1012     // HandleMark hm(THREAD);
1013     JVMCIObject value = JVMCIENV->get_object_at(virtualObjects, i);
1014     int id = jvmci_env()->get_VirtualObject_id(value);
1015     record_object_value(objects->at(id)->as_ObjectValue(), value, objects, JVMCI_CHECK_NULL);
1016   }
1017   _debug_recorder->dump_object_pool(objects);
1018   return objects;
1019 }
1020 




 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 }


 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();
 892     if (SafepointMechanism::should_block(thread)) {


 971     case Bytecodes::_invokestatic:
 972       return false;
 973     default:
 974       return true;
 975     }
 976   return true;
 977 }
 978 
 979 GrowableArray<ScopeValue*>* CodeInstaller::record_virtual_objects(JVMCIObject debug_info, JVMCI_TRAPS) {
 980   JVMCIObjectArray virtualObjects = jvmci_env()->get_DebugInfo_virtualObjectMapping(debug_info);
 981   if (virtualObjects.is_null()) {
 982     return NULL;
 983   }
 984   GrowableArray<ScopeValue*>* objects = new GrowableArray<ScopeValue*>(JVMCIENV->get_length(virtualObjects), JVMCIENV->get_length(virtualObjects), NULL);
 985   // Create the unique ObjectValues
 986   for (int i = 0; i < JVMCIENV->get_length(virtualObjects); i++) {
 987     // HandleMark hm(THREAD);
 988     JVMCIObject value = JVMCIENV->get_object_at(virtualObjects, i);
 989     int id = jvmci_env()->get_VirtualObject_id(value);
 990     JVMCIObject type = jvmci_env()->get_VirtualObject_type(value);

 991     Klass* klass = jvmci_env()->asKlass(type);
 992     oop javaMirror = klass->java_mirror();
 993     ObjectValue* sv = new ObjectValue(id, new ConstantOopWriteValue(JNIHandles::make_local(Thread::current(), javaMirror)));

 994     if (id < 0 || id >= objects->length()) {
 995       JVMCI_ERROR_NULL("virtual object id %d out of bounds", id);
 996     }
 997     if (objects->at(id) != NULL) {
 998       JVMCI_ERROR_NULL("duplicate virtual object id %d", id);
 999     }
1000     objects->at_put(id, sv);
1001   }
1002   // All the values which could be referenced by the VirtualObjects
1003   // exist, so now describe all the VirtualObjects themselves.
1004   for (int i = 0; i < JVMCIENV->get_length(virtualObjects); i++) {
1005     // HandleMark hm(THREAD);
1006     JVMCIObject value = JVMCIENV->get_object_at(virtualObjects, i);
1007     int id = jvmci_env()->get_VirtualObject_id(value);
1008     record_object_value(objects->at(id)->as_ObjectValue(), value, objects, JVMCI_CHECK_NULL);
1009   }
1010   _debug_recorder->dump_object_pool(objects);
1011   return objects;
1012 }
1013 


< prev index next >