1784 // Emit the deopt handler code.
1785 _code_offsets.set_value(CodeOffsets::Deopt, HandlerImpl::emit_deopt_handler(masm));
1786 }
1787
1788 // One last check for failed CodeBuffer::expand:
1789 if ((masm->code()->blob() == nullptr) || (!CompileBroker::should_compile_new_jobs())) {
1790 C->record_failure("CodeCache is full");
1791 return;
1792 }
1793
1794 #if defined(SUPPORT_ABSTRACT_ASSEMBLY) || defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_OPTO_ASSEMBLY)
1795 if (C->print_assembly()) {
1796 tty->cr();
1797 tty->print_cr("============================= C2-compiled nmethod ==============================");
1798 }
1799 #endif
1800
1801 #if defined(SUPPORT_OPTO_ASSEMBLY)
1802 // Dump the assembly code, including basic-block numbers
1803 if (C->print_assembly()) {
1804 ttyLocker ttyl; // keep the following output all in one block
1805 if (!VMThread::should_terminate()) { // test this under the tty lock
1806 // print_metadata and dump_asm may safepoint which makes us loose the ttylock.
1807 // We call them first and write to a stringStream, then we retake the lock to
1808 // make sure the end tag is coherent, and that xmlStream->pop_tag is done thread safe.
1809 ResourceMark rm;
1810 stringStream method_metadata_str;
1811 if (C->method() != nullptr) {
1812 C->method()->print_metadata(&method_metadata_str);
1813 }
1814 stringStream dump_asm_str;
1815 dump_asm_on(&dump_asm_str, node_offsets, node_offset_limit);
1816
1817 NoSafepointVerifier nsv;
1818 ttyLocker ttyl2;
1819 // This output goes directly to the tty, not the compiler log.
1820 // To enable tools to match it up with the compilation activity,
1821 // be sure to tag this tty output with the compile ID.
1822 if (xtty != nullptr) {
1823 xtty->head("opto_assembly compile_id='%d'%s", C->compile_id(),
1824 C->is_osr_compilation() ? " compile_kind='osr'" : "");
1825 }
1826 if (C->method() != nullptr) {
1827 tty->print_cr("----------------------- MetaData before Compile_id = %d ------------------------", C->compile_id());
1828 tty->print_raw(method_metadata_str.freeze());
1829 } else if (C->stub_name() != nullptr) {
1830 tty->print_cr("----------------------------- RuntimeStub %s -------------------------------", C->stub_name());
1831 }
1832 tty->cr();
1833 tty->print_cr("------------------------ OptoAssembly for Compile_id = %d -----------------------", C->compile_id());
1834 tty->print_raw(dump_asm_str.freeze());
1835 tty->print_cr("--------------------------------------------------------------------------------");
1836 if (xtty != nullptr) {
1837 xtty->tail("opto_assembly");
1838 }
1839 }
1840 }
1841 #endif
1842 }
1843
1844 void PhaseOutput::FillExceptionTables(uint cnt, uint *call_returns, uint *inct_starts, Label *blk_labels) {
1845 _inc_table.set_size(cnt);
1846
1847 uint inct_cnt = 0;
1848 for (uint i = 0; i < C->cfg()->number_of_blocks(); i++) {
1849 Block* block = C->cfg()->get_block(i);
1850 Node *n = nullptr;
1851 int j;
1852
1853 // Find the branch; ignore trailing NOPs.
3136 masm.bind(fakeL);
3137 if (is_branch) {
3138 n->as_MachBranch()->save_label(&saveL, &save_bnum);
3139 n->as_MachBranch()->label_set(&fakeL, 0);
3140 }
3141 n->emit(&masm, C->regalloc());
3142
3143 // Emitting into the scratch buffer should not fail
3144 assert(!C->failing_internal() || C->failure_is_artificial(), "Must not have pending failure. Reason is: %s", C->failure_reason());
3145
3146 if (is_branch) // Restore label.
3147 n->as_MachBranch()->label_set(saveL, save_bnum);
3148
3149 // End scratch_emit_size section.
3150 set_in_scratch_emit_size(false);
3151
3152 return buf.insts_size();
3153 }
3154
3155 void PhaseOutput::install() {
3156 if (!C->should_install_code()) {
3157 return;
3158 } else if (C->stub_function() != nullptr) {
3159 install_stub(C->stub_name());
3160 } else {
3161 install_code(C->method(),
3162 C->entry_bci(),
3163 CompileBroker::compiler2(),
3164 C->has_unsafe_access(),
3165 SharedRuntime::is_wide_vector(C->max_vector_size()));
3166 }
3167 }
3168
3169 void PhaseOutput::install_code(ciMethod* target,
3170 int entry_bci,
3171 AbstractCompiler* compiler,
3172 bool has_unsafe_access,
3173 bool has_wide_vectors) {
3174 // Check if we want to skip execution of all compiled code.
3175 {
3176 #ifndef PRODUCT
3177 if (OptoNoExecute) {
3178 C->record_method_not_compilable("+OptoNoExecute"); // Flag as failed
3179 return;
3180 }
3181 #endif
3182 Compile::TracePhase tp(_t_registerMethod);
3183
3188 if (!target->is_static()) {
3189 // The UEP of an nmethod ensures that the VEP is padded. However, the padding of the UEP is placed
3190 // before the inline cache check, so we don't have to execute any nop instructions when dispatching
3191 // through the UEP, yet we can ensure that the VEP is aligned appropriately.
3192 _code_offsets.set_value(CodeOffsets::Entry, _first_block_size - MacroAssembler::ic_check_size());
3193 }
3194 _code_offsets.set_value(CodeOffsets::Verified_Entry, _first_block_size);
3195 _code_offsets.set_value(CodeOffsets::OSR_Entry, 0);
3196 }
3197
3198 C->env()->register_method(target,
3199 entry_bci,
3200 &_code_offsets,
3201 _orig_pc_slot_offset_in_bytes,
3202 code_buffer(),
3203 frame_size_in_words(),
3204 oop_map_set(),
3205 &_handler_table,
3206 inc_table(),
3207 compiler,
3208 has_unsafe_access,
3209 SharedRuntime::is_wide_vector(C->max_vector_size()),
3210 C->has_monitors(),
3211 C->has_scoped_access(),
3212 0);
3213
3214 if (C->log() != nullptr) { // Print code cache state into compiler log
3215 C->log()->code_cache_state();
3216 }
3217 }
3218 }
3219 void PhaseOutput::install_stub(const char* stub_name) {
3220 // Entry point will be accessed using stub_entry_point();
3221 if (code_buffer() == nullptr) {
3222 Matcher::soft_match_failure();
3223 } else {
3224 if (PrintAssembly && (WizardMode || Verbose))
3225 tty->print_cr("### Stub::%s", stub_name);
3226
3227 if (!C->failing()) {
3228 assert(C->fixed_slots() == 0, "no fixed slots used for runtime stubs");
3229
3230 // Make the NMethod
3231 // For now we mark the frame as never safe for profile stackwalking
3232 RuntimeStub *rs = RuntimeStub::new_runtime_stub(stub_name,
3233 code_buffer(),
3234 CodeOffsets::frame_never_safe,
3235 // _code_offsets.value(CodeOffsets::Frame_Complete),
3236 frame_size_in_words(),
|
1784 // Emit the deopt handler code.
1785 _code_offsets.set_value(CodeOffsets::Deopt, HandlerImpl::emit_deopt_handler(masm));
1786 }
1787
1788 // One last check for failed CodeBuffer::expand:
1789 if ((masm->code()->blob() == nullptr) || (!CompileBroker::should_compile_new_jobs())) {
1790 C->record_failure("CodeCache is full");
1791 return;
1792 }
1793
1794 #if defined(SUPPORT_ABSTRACT_ASSEMBLY) || defined(SUPPORT_ASSEMBLY) || defined(SUPPORT_OPTO_ASSEMBLY)
1795 if (C->print_assembly()) {
1796 tty->cr();
1797 tty->print_cr("============================= C2-compiled nmethod ==============================");
1798 }
1799 #endif
1800
1801 #if defined(SUPPORT_OPTO_ASSEMBLY)
1802 // Dump the assembly code, including basic-block numbers
1803 if (C->print_assembly()) {
1804 if (!VMThread::should_terminate()) {
1805 ResourceMark rm;
1806 stringStream method_metadata_str;
1807 if (C->method() != nullptr) {
1808 C->method()->print_metadata(&method_metadata_str);
1809 }
1810 stringStream dump_asm_str;
1811 dump_asm_on(&dump_asm_str, node_offsets, node_offset_limit);
1812
1813 // Make sure the end tag is coherent, and that xmlStream->pop_tag is done thread safe.
1814 NoSafepointVerifier nsv;
1815 ttyLocker ttyl;
1816 // This output goes directly to the tty, not the compiler log.
1817 // To enable tools to match it up with the compilation activity,
1818 // be sure to tag this tty output with the compile ID.
1819 if (xtty != nullptr) {
1820 xtty->head("opto_assembly compile_id='%d'%s", C->compile_id(),
1821 C->is_osr_compilation() ? " compile_kind='osr'" :
1822 (C->for_preload() ? " compile_kind='AP'" : ""));
1823 }
1824 const char* is_aot = C->env()->is_aot_compile() ? (C->for_preload() ? "(AP) " : "(A) -") : "-----";
1825 if (C->method() != nullptr) {
1826 tty->print_cr("----------------------- MetaData before Compile_id = %d %s-------------------", C->compile_id(), is_aot);
1827 tty->print_raw(method_metadata_str.freeze());
1828 } else if (C->stub_name() != nullptr) {
1829 tty->print_cr("----------------------------- RuntimeStub %s -------------------------------", C->stub_name());
1830 }
1831 tty->cr();
1832 tty->print_cr("------------------------ OptoAssembly for Compile_id = %d %s------------------", C->compile_id(), is_aot);
1833 tty->print_raw(dump_asm_str.freeze());
1834 tty->print_cr("--------------------------------------------------------------------------------");
1835 if (xtty != nullptr) {
1836 xtty->tail("opto_assembly");
1837 }
1838 }
1839 }
1840 #endif
1841 }
1842
1843 void PhaseOutput::FillExceptionTables(uint cnt, uint *call_returns, uint *inct_starts, Label *blk_labels) {
1844 _inc_table.set_size(cnt);
1845
1846 uint inct_cnt = 0;
1847 for (uint i = 0; i < C->cfg()->number_of_blocks(); i++) {
1848 Block* block = C->cfg()->get_block(i);
1849 Node *n = nullptr;
1850 int j;
1851
1852 // Find the branch; ignore trailing NOPs.
3135 masm.bind(fakeL);
3136 if (is_branch) {
3137 n->as_MachBranch()->save_label(&saveL, &save_bnum);
3138 n->as_MachBranch()->label_set(&fakeL, 0);
3139 }
3140 n->emit(&masm, C->regalloc());
3141
3142 // Emitting into the scratch buffer should not fail
3143 assert(!C->failing_internal() || C->failure_is_artificial(), "Must not have pending failure. Reason is: %s", C->failure_reason());
3144
3145 if (is_branch) // Restore label.
3146 n->as_MachBranch()->label_set(saveL, save_bnum);
3147
3148 // End scratch_emit_size section.
3149 set_in_scratch_emit_size(false);
3150
3151 return buf.insts_size();
3152 }
3153
3154 void PhaseOutput::install() {
3155 if (C->should_install_code() && C->stub_function() != nullptr) {
3156 install_stub(C->stub_name());
3157 } else {
3158 install_code(C->method(),
3159 C->entry_bci(),
3160 CompilerThread::current()->compiler(),
3161 C->has_unsafe_access(),
3162 SharedRuntime::is_wide_vector(C->max_vector_size()));
3163 }
3164 }
3165
3166 void PhaseOutput::install_code(ciMethod* target,
3167 int entry_bci,
3168 AbstractCompiler* compiler,
3169 bool has_unsafe_access,
3170 bool has_wide_vectors) {
3171 // Check if we want to skip execution of all compiled code.
3172 {
3173 #ifndef PRODUCT
3174 if (OptoNoExecute) {
3175 C->record_method_not_compilable("+OptoNoExecute"); // Flag as failed
3176 return;
3177 }
3178 #endif
3179 Compile::TracePhase tp(_t_registerMethod);
3180
3185 if (!target->is_static()) {
3186 // The UEP of an nmethod ensures that the VEP is padded. However, the padding of the UEP is placed
3187 // before the inline cache check, so we don't have to execute any nop instructions when dispatching
3188 // through the UEP, yet we can ensure that the VEP is aligned appropriately.
3189 _code_offsets.set_value(CodeOffsets::Entry, _first_block_size - MacroAssembler::ic_check_size());
3190 }
3191 _code_offsets.set_value(CodeOffsets::Verified_Entry, _first_block_size);
3192 _code_offsets.set_value(CodeOffsets::OSR_Entry, 0);
3193 }
3194
3195 C->env()->register_method(target,
3196 entry_bci,
3197 &_code_offsets,
3198 _orig_pc_slot_offset_in_bytes,
3199 code_buffer(),
3200 frame_size_in_words(),
3201 oop_map_set(),
3202 &_handler_table,
3203 inc_table(),
3204 compiler,
3205 C->has_clinit_barriers(),
3206 C->for_preload(),
3207 has_unsafe_access,
3208 SharedRuntime::is_wide_vector(C->max_vector_size()),
3209 C->has_monitors(),
3210 C->has_scoped_access(),
3211 0,
3212 C->should_install_code());
3213
3214 if (C->log() != nullptr) { // Print code cache state into compiler log
3215 C->log()->code_cache_state();
3216 }
3217 assert(!C->has_clinit_barriers() || C->for_preload(), "class init barriers should be only in preload code");
3218 }
3219 }
3220 void PhaseOutput::install_stub(const char* stub_name) {
3221 // Entry point will be accessed using stub_entry_point();
3222 if (code_buffer() == nullptr) {
3223 Matcher::soft_match_failure();
3224 } else {
3225 if (PrintAssembly && (WizardMode || Verbose))
3226 tty->print_cr("### Stub::%s", stub_name);
3227
3228 if (!C->failing()) {
3229 assert(C->fixed_slots() == 0, "no fixed slots used for runtime stubs");
3230
3231 // Make the NMethod
3232 // For now we mark the frame as never safe for profile stackwalking
3233 RuntimeStub *rs = RuntimeStub::new_runtime_stub(stub_name,
3234 code_buffer(),
3235 CodeOffsets::frame_never_safe,
3236 // _code_offsets.value(CodeOffsets::Frame_Complete),
3237 frame_size_in_words(),
|