1 /* 2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "code/codeCache.hpp" 27 #include "code/compiledIC.hpp" 28 #include "code/dependencies.hpp" 29 #include "code/nativeInst.hpp" 30 #include "code/nmethod.hpp" 31 #include "code/scopeDesc.hpp" 32 #include "compiler/abstractCompiler.hpp" 33 #include "compiler/compileBroker.hpp" 34 #include "compiler/compileLog.hpp" 35 #include "compiler/compilerDirectives.hpp" 36 #include "compiler/directivesParser.hpp" 37 #include "compiler/disassembler.hpp" 38 #include "interpreter/bytecode.hpp" 39 #include "logging/log.hpp" 40 #include "memory/resourceArea.hpp" 41 #include "oops/methodData.hpp" 42 #include "oops/oop.inline.hpp" 43 #include "prims/jvm.h" 44 #include "prims/jvmtiImpl.hpp" 45 #include "runtime/atomic.hpp" 46 #include "runtime/orderAccess.inline.hpp" 47 #include "runtime/os.hpp" 48 #include "runtime/sharedRuntime.hpp" 49 #include "runtime/sweeper.hpp" 50 #include "utilities/align.hpp" 51 #include "utilities/dtrace.hpp" 52 #include "utilities/events.hpp" 53 #include "utilities/resourceHash.hpp" 54 #include "utilities/xmlstream.hpp" 55 #ifdef SHARK 56 #include "shark/sharkCompiler.hpp" 57 #endif 58 #if INCLUDE_JVMCI 59 #include "jvmci/jvmciJavaClasses.hpp" 60 #endif 61 62 #ifdef DTRACE_ENABLED 63 64 // Only bother with this argument setup if dtrace is available 65 66 #define DTRACE_METHOD_UNLOAD_PROBE(method) \ 67 { \ 68 Method* m = (method); \ 69 if (m != NULL) { \ 70 Symbol* klass_name = m->klass_name(); \ 71 Symbol* name = m->name(); \ 72 Symbol* signature = m->signature(); \ 73 HOTSPOT_COMPILED_METHOD_UNLOAD( \ 74 (char *) klass_name->bytes(), klass_name->utf8_length(), \ 75 (char *) name->bytes(), name->utf8_length(), \ 76 (char *) signature->bytes(), signature->utf8_length()); \ 77 } \ 78 } 79 80 #else // ndef DTRACE_ENABLED 81 82 #define DTRACE_METHOD_UNLOAD_PROBE(method) 83 84 #endif 85 86 //--------------------------------------------------------------------------------- 87 // NMethod statistics 88 // They are printed under various flags, including: 89 // PrintC1Statistics, PrintOptoStatistics, LogVMOutput, and LogCompilation. 90 // (In the latter two cases, they like other stats are printed to the log only.) 91 92 #ifndef PRODUCT 93 // These variables are put into one block to reduce relocations 94 // and make it simpler to print from the debugger. 95 struct java_nmethod_stats_struct { 96 int nmethod_count; 97 int total_size; 98 int relocation_size; 99 int consts_size; 100 int insts_size; 101 int stub_size; 102 int scopes_data_size; 103 int scopes_pcs_size; 104 int dependencies_size; 105 int handler_table_size; 106 int nul_chk_table_size; 107 int oops_size; 108 int metadata_size; 109 110 void note_nmethod(nmethod* nm) { 111 nmethod_count += 1; 112 total_size += nm->size(); 113 relocation_size += nm->relocation_size(); 114 consts_size += nm->consts_size(); 115 insts_size += nm->insts_size(); 116 stub_size += nm->stub_size(); 117 oops_size += nm->oops_size(); 118 metadata_size += nm->metadata_size(); 119 scopes_data_size += nm->scopes_data_size(); 120 scopes_pcs_size += nm->scopes_pcs_size(); 121 dependencies_size += nm->dependencies_size(); 122 handler_table_size += nm->handler_table_size(); 123 nul_chk_table_size += nm->nul_chk_table_size(); 124 } 125 void print_nmethod_stats(const char* name) { 126 if (nmethod_count == 0) return; 127 tty->print_cr("Statistics for %d bytecoded nmethods for %s:", nmethod_count, name); 128 if (total_size != 0) tty->print_cr(" total in heap = %d", total_size); 129 if (nmethod_count != 0) tty->print_cr(" header = " SIZE_FORMAT, nmethod_count * sizeof(nmethod)); 130 if (relocation_size != 0) tty->print_cr(" relocation = %d", relocation_size); 131 if (consts_size != 0) tty->print_cr(" constants = %d", consts_size); 132 if (insts_size != 0) tty->print_cr(" main code = %d", insts_size); 133 if (stub_size != 0) tty->print_cr(" stub code = %d", stub_size); 134 if (oops_size != 0) tty->print_cr(" oops = %d", oops_size); 135 if (metadata_size != 0) tty->print_cr(" metadata = %d", metadata_size); 136 if (scopes_data_size != 0) tty->print_cr(" scopes data = %d", scopes_data_size); 137 if (scopes_pcs_size != 0) tty->print_cr(" scopes pcs = %d", scopes_pcs_size); 138 if (dependencies_size != 0) tty->print_cr(" dependencies = %d", dependencies_size); 139 if (handler_table_size != 0) tty->print_cr(" handler table = %d", handler_table_size); 140 if (nul_chk_table_size != 0) tty->print_cr(" nul chk table = %d", nul_chk_table_size); 141 } 142 }; 143 144 struct native_nmethod_stats_struct { 145 int native_nmethod_count; 146 int native_total_size; 147 int native_relocation_size; 148 int native_insts_size; 149 int native_oops_size; 150 int native_metadata_size; 151 void note_native_nmethod(nmethod* nm) { 152 native_nmethod_count += 1; 153 native_total_size += nm->size(); 154 native_relocation_size += nm->relocation_size(); 155 native_insts_size += nm->insts_size(); 156 native_oops_size += nm->oops_size(); 157 native_metadata_size += nm->metadata_size(); 158 } 159 void print_native_nmethod_stats() { 160 if (native_nmethod_count == 0) return; 161 tty->print_cr("Statistics for %d native nmethods:", native_nmethod_count); 162 if (native_total_size != 0) tty->print_cr(" N. total size = %d", native_total_size); 163 if (native_relocation_size != 0) tty->print_cr(" N. relocation = %d", native_relocation_size); 164 if (native_insts_size != 0) tty->print_cr(" N. main code = %d", native_insts_size); 165 if (native_oops_size != 0) tty->print_cr(" N. oops = %d", native_oops_size); 166 if (native_metadata_size != 0) tty->print_cr(" N. metadata = %d", native_metadata_size); 167 } 168 }; 169 170 struct pc_nmethod_stats_struct { 171 int pc_desc_resets; // number of resets (= number of caches) 172 int pc_desc_queries; // queries to nmethod::find_pc_desc 173 int pc_desc_approx; // number of those which have approximate true 174 int pc_desc_repeats; // number of _pc_descs[0] hits 175 int pc_desc_hits; // number of LRU cache hits 176 int pc_desc_tests; // total number of PcDesc examinations 177 int pc_desc_searches; // total number of quasi-binary search steps 178 int pc_desc_adds; // number of LUR cache insertions 179 180 void print_pc_stats() { 181 tty->print_cr("PcDesc Statistics: %d queries, %.2f comparisons per query", 182 pc_desc_queries, 183 (double)(pc_desc_tests + pc_desc_searches) 184 / pc_desc_queries); 185 tty->print_cr(" caches=%d queries=%d/%d, hits=%d+%d, tests=%d+%d, adds=%d", 186 pc_desc_resets, 187 pc_desc_queries, pc_desc_approx, 188 pc_desc_repeats, pc_desc_hits, 189 pc_desc_tests, pc_desc_searches, pc_desc_adds); 190 } 191 }; 192 193 #ifdef COMPILER1 194 static java_nmethod_stats_struct c1_java_nmethod_stats; 195 #endif 196 #ifdef COMPILER2 197 static java_nmethod_stats_struct c2_java_nmethod_stats; 198 #endif 199 #if INCLUDE_JVMCI 200 static java_nmethod_stats_struct jvmci_java_nmethod_stats; 201 #endif 202 #ifdef SHARK 203 static java_nmethod_stats_struct shark_java_nmethod_stats; 204 #endif 205 static java_nmethod_stats_struct unknown_java_nmethod_stats; 206 207 static native_nmethod_stats_struct native_nmethod_stats; 208 static pc_nmethod_stats_struct pc_nmethod_stats; 209 210 static void note_java_nmethod(nmethod* nm) { 211 #ifdef COMPILER1 212 if (nm->is_compiled_by_c1()) { 213 c1_java_nmethod_stats.note_nmethod(nm); 214 } else 215 #endif 216 #ifdef COMPILER2 217 if (nm->is_compiled_by_c2()) { 218 c2_java_nmethod_stats.note_nmethod(nm); 219 } else 220 #endif 221 #if INCLUDE_JVMCI 222 if (nm->is_compiled_by_jvmci()) { 223 jvmci_java_nmethod_stats.note_nmethod(nm); 224 } else 225 #endif 226 #ifdef SHARK 227 if (nm->is_compiled_by_shark()) { 228 shark_java_nmethod_stats.note_nmethod(nm); 229 } else 230 #endif 231 { 232 unknown_java_nmethod_stats.note_nmethod(nm); 233 } 234 } 235 #endif // !PRODUCT 236 237 //--------------------------------------------------------------------------------- 238 239 240 ExceptionCache::ExceptionCache(Handle exception, address pc, address handler) { 241 assert(pc != NULL, "Must be non null"); 242 assert(exception.not_null(), "Must be non null"); 243 assert(handler != NULL, "Must be non null"); 244 245 _count = 0; 246 _exception_type = exception->klass(); 247 _next = NULL; 248 249 add_address_and_handler(pc,handler); 250 } 251 252 253 address ExceptionCache::match(Handle exception, address pc) { 254 assert(pc != NULL,"Must be non null"); 255 assert(exception.not_null(),"Must be non null"); 256 if (exception->klass() == exception_type()) { 257 return (test_address(pc)); 258 } 259 260 return NULL; 261 } 262 263 264 bool ExceptionCache::match_exception_with_space(Handle exception) { 265 assert(exception.not_null(),"Must be non null"); 266 if (exception->klass() == exception_type() && count() < cache_size) { 267 return true; 268 } 269 return false; 270 } 271 272 273 address ExceptionCache::test_address(address addr) { 274 int limit = count(); 275 for (int i = 0; i < limit; i++) { 276 if (pc_at(i) == addr) { 277 return handler_at(i); 278 } 279 } 280 return NULL; 281 } 282 283 284 bool ExceptionCache::add_address_and_handler(address addr, address handler) { 285 if (test_address(addr) == handler) return true; 286 287 int index = count(); 288 if (index < cache_size) { 289 set_pc_at(index, addr); 290 set_handler_at(index, handler); 291 increment_count(); 292 return true; 293 } 294 return false; 295 } 296 297 //----------------------------------------------------------------------------- 298 299 300 // Helper used by both find_pc_desc methods. 301 static inline bool match_desc(PcDesc* pc, int pc_offset, bool approximate) { 302 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_tests); 303 if (!approximate) 304 return pc->pc_offset() == pc_offset; 305 else 306 return (pc-1)->pc_offset() < pc_offset && pc_offset <= pc->pc_offset(); 307 } 308 309 void PcDescCache::reset_to(PcDesc* initial_pc_desc) { 310 if (initial_pc_desc == NULL) { 311 _pc_descs[0] = NULL; // native method; no PcDescs at all 312 return; 313 } 314 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_resets); 315 // reset the cache by filling it with benign (non-null) values 316 assert(initial_pc_desc->pc_offset() < 0, "must be sentinel"); 317 for (int i = 0; i < cache_size; i++) 318 _pc_descs[i] = initial_pc_desc; 319 } 320 321 PcDesc* PcDescCache::find_pc_desc(int pc_offset, bool approximate) { 322 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_queries); 323 NOT_PRODUCT(if (approximate) ++pc_nmethod_stats.pc_desc_approx); 324 325 // Note: one might think that caching the most recently 326 // read value separately would be a win, but one would be 327 // wrong. When many threads are updating it, the cache 328 // line it's in would bounce between caches, negating 329 // any benefit. 330 331 // In order to prevent race conditions do not load cache elements 332 // repeatedly, but use a local copy: 333 PcDesc* res; 334 335 // Step one: Check the most recently added value. 336 res = _pc_descs[0]; 337 if (res == NULL) return NULL; // native method; no PcDescs at all 338 if (match_desc(res, pc_offset, approximate)) { 339 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_repeats); 340 return res; 341 } 342 343 // Step two: Check the rest of the LRU cache. 344 for (int i = 1; i < cache_size; ++i) { 345 res = _pc_descs[i]; 346 if (res->pc_offset() < 0) break; // optimization: skip empty cache 347 if (match_desc(res, pc_offset, approximate)) { 348 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_hits); 349 return res; 350 } 351 } 352 353 // Report failure. 354 return NULL; 355 } 356 357 void PcDescCache::add_pc_desc(PcDesc* pc_desc) { 358 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_adds); 359 // Update the LRU cache by shifting pc_desc forward. 360 for (int i = 0; i < cache_size; i++) { 361 PcDesc* next = _pc_descs[i]; 362 _pc_descs[i] = pc_desc; 363 pc_desc = next; 364 } 365 } 366 367 // adjust pcs_size so that it is a multiple of both oopSize and 368 // sizeof(PcDesc) (assumes that if sizeof(PcDesc) is not a multiple 369 // of oopSize, then 2*sizeof(PcDesc) is) 370 static int adjust_pcs_size(int pcs_size) { 371 int nsize = align_up(pcs_size, oopSize); 372 if ((nsize % sizeof(PcDesc)) != 0) { 373 nsize = pcs_size + sizeof(PcDesc); 374 } 375 assert((nsize % oopSize) == 0, "correct alignment"); 376 return nsize; 377 } 378 379 380 int nmethod::total_size() const { 381 return 382 consts_size() + 383 insts_size() + 384 stub_size() + 385 scopes_data_size() + 386 scopes_pcs_size() + 387 handler_table_size() + 388 nul_chk_table_size(); 389 } 390 391 const char* nmethod::compile_kind() const { 392 if (is_osr_method()) return "osr"; 393 if (method() != NULL && is_native_method()) return "c2n"; 394 return NULL; 395 } 396 397 // Fill in default values for various flag fields 398 void nmethod::init_defaults() { 399 _state = in_use; 400 _has_flushed_dependencies = 0; 401 _lock_count = 0; 402 _stack_traversal_mark = 0; 403 _unload_reported = false; // jvmti state 404 _is_far_code = false; // nmethods are located in CodeCache 405 406 #ifdef ASSERT 407 _oops_are_stale = false; 408 #endif 409 410 _oops_do_mark_link = NULL; 411 _jmethod_id = NULL; 412 _osr_link = NULL; 413 _unloading_next = NULL; 414 _scavenge_root_link = NULL; 415 _scavenge_root_state = 0; 416 #if INCLUDE_RTM_OPT 417 _rtm_state = NoRTM; 418 #endif 419 #if INCLUDE_JVMCI 420 _jvmci_installed_code = NULL; 421 _speculation_log = NULL; 422 #endif 423 } 424 425 nmethod* nmethod::new_native_nmethod(const methodHandle& method, 426 int compile_id, 427 CodeBuffer *code_buffer, 428 int vep_offset, 429 int frame_complete, 430 int frame_size, 431 ByteSize basic_lock_owner_sp_offset, 432 ByteSize basic_lock_sp_offset, 433 OopMapSet* oop_maps) { 434 code_buffer->finalize_oop_references(method); 435 // create nmethod 436 nmethod* nm = NULL; 437 { 438 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 439 int native_nmethod_size = CodeBlob::allocation_size(code_buffer, sizeof(nmethod)); 440 CodeOffsets offsets; 441 offsets.set_value(CodeOffsets::Verified_Entry, vep_offset); 442 offsets.set_value(CodeOffsets::Frame_Complete, frame_complete); 443 nm = new (native_nmethod_size, CompLevel_none) nmethod(method(), compiler_none, native_nmethod_size, 444 compile_id, &offsets, 445 code_buffer, frame_size, 446 basic_lock_owner_sp_offset, 447 basic_lock_sp_offset, oop_maps); 448 NOT_PRODUCT(if (nm != NULL) native_nmethod_stats.note_native_nmethod(nm)); 449 } 450 // verify nmethod 451 debug_only(if (nm) nm->verify();) // might block 452 453 if (nm != NULL) { 454 nm->log_new_nmethod(); 455 } 456 457 return nm; 458 } 459 460 nmethod* nmethod::new_nmethod(const methodHandle& method, 461 int compile_id, 462 int entry_bci, 463 CodeOffsets* offsets, 464 int orig_pc_offset, 465 DebugInformationRecorder* debug_info, 466 Dependencies* dependencies, 467 CodeBuffer* code_buffer, int frame_size, 468 OopMapSet* oop_maps, 469 ExceptionHandlerTable* handler_table, 470 ImplicitExceptionTable* nul_chk_table, 471 AbstractCompiler* compiler, 472 int comp_level 473 #if INCLUDE_JVMCI 474 , Handle installed_code, 475 Handle speculationLog 476 #endif 477 ) 478 { 479 assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR"); 480 code_buffer->finalize_oop_references(method); 481 // create nmethod 482 nmethod* nm = NULL; 483 { MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 484 int nmethod_size = 485 CodeBlob::allocation_size(code_buffer, sizeof(nmethod)) 486 + adjust_pcs_size(debug_info->pcs_size()) 487 + align_up((int)dependencies->size_in_bytes(), oopSize) 488 + align_up(handler_table->size_in_bytes() , oopSize) 489 + align_up(nul_chk_table->size_in_bytes() , oopSize) 490 + align_up(debug_info->data_size() , oopSize); 491 492 nm = new (nmethod_size, comp_level) 493 nmethod(method(), compiler->type(), nmethod_size, compile_id, entry_bci, offsets, 494 orig_pc_offset, debug_info, dependencies, code_buffer, frame_size, 495 oop_maps, 496 handler_table, 497 nul_chk_table, 498 compiler, 499 comp_level 500 #if INCLUDE_JVMCI 501 , installed_code, 502 speculationLog 503 #endif 504 ); 505 506 if (nm != NULL) { 507 // To make dependency checking during class loading fast, record 508 // the nmethod dependencies in the classes it is dependent on. 509 // This allows the dependency checking code to simply walk the 510 // class hierarchy above the loaded class, checking only nmethods 511 // which are dependent on those classes. The slow way is to 512 // check every nmethod for dependencies which makes it linear in 513 // the number of methods compiled. For applications with a lot 514 // classes the slow way is too slow. 515 for (Dependencies::DepStream deps(nm); deps.next(); ) { 516 if (deps.type() == Dependencies::call_site_target_value) { 517 // CallSite dependencies are managed on per-CallSite instance basis. 518 oop call_site = deps.argument_oop(0); 519 MethodHandles::add_dependent_nmethod(call_site, nm); 520 } else { 521 Klass* klass = deps.context_type(); 522 if (klass == NULL) { 523 continue; // ignore things like evol_method 524 } 525 // record this nmethod as dependent on this klass 526 InstanceKlass::cast(klass)->add_dependent_nmethod(nm); 527 } 528 } 529 NOT_PRODUCT(if (nm != NULL) note_java_nmethod(nm)); 530 } 531 } 532 // Do verification and logging outside CodeCache_lock. 533 if (nm != NULL) { 534 // Safepoints in nmethod::verify aren't allowed because nm hasn't been installed yet. 535 DEBUG_ONLY(nm->verify();) 536 nm->log_new_nmethod(); 537 } 538 return nm; 539 } 540 541 // For native wrappers 542 nmethod::nmethod( 543 Method* method, 544 CompilerType type, 545 int nmethod_size, 546 int compile_id, 547 CodeOffsets* offsets, 548 CodeBuffer* code_buffer, 549 int frame_size, 550 ByteSize basic_lock_owner_sp_offset, 551 ByteSize basic_lock_sp_offset, 552 OopMapSet* oop_maps ) 553 : CompiledMethod(method, "native nmethod", type, nmethod_size, sizeof(nmethod), code_buffer, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps, false), 554 _native_receiver_sp_offset(basic_lock_owner_sp_offset), 555 _native_basic_lock_sp_offset(basic_lock_sp_offset) 556 { 557 { 558 int scopes_data_offset = 0; 559 int deoptimize_offset = 0; 560 int deoptimize_mh_offset = 0; 561 562 debug_only(NoSafepointVerifier nsv;) 563 assert_locked_or_safepoint(CodeCache_lock); 564 565 init_defaults(); 566 _entry_bci = InvocationEntryBci; 567 // We have no exception handler or deopt handler make the 568 // values something that will never match a pc like the nmethod vtable entry 569 _exception_offset = 0; 570 _orig_pc_offset = 0; 571 572 _consts_offset = data_offset(); 573 _stub_offset = data_offset(); 574 _oops_offset = data_offset(); 575 _metadata_offset = _oops_offset + align_up(code_buffer->total_oop_size(), oopSize); 576 scopes_data_offset = _metadata_offset + align_up(code_buffer->total_metadata_size(), wordSize); 577 _scopes_pcs_offset = scopes_data_offset; 578 _dependencies_offset = _scopes_pcs_offset; 579 _handler_table_offset = _dependencies_offset; 580 _nul_chk_table_offset = _handler_table_offset; 581 _nmethod_end_offset = _nul_chk_table_offset; 582 _compile_id = compile_id; 583 _comp_level = CompLevel_none; 584 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); 585 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); 586 _osr_entry_point = NULL; 587 _exception_cache = NULL; 588 _pc_desc_container.reset_to(NULL); 589 _hotness_counter = NMethodSweeper::hotness_counter_reset_val(); 590 591 _scopes_data_begin = (address) this + scopes_data_offset; 592 _deopt_handler_begin = (address) this + deoptimize_offset; 593 _deopt_mh_handler_begin = (address) this + deoptimize_mh_offset; 594 595 code_buffer->copy_code_and_locs_to(this); 596 code_buffer->copy_values_to(this); 597 if (ScavengeRootsInCode) { 598 Universe::heap()->register_nmethod(this); 599 } 600 debug_only(Universe::heap()->verify_nmethod_roots(this)); 601 CodeCache::commit(this); 602 } 603 604 if (PrintNativeNMethods || PrintDebugInfo || PrintRelocations || PrintDependencies) { 605 ttyLocker ttyl; // keep the following output all in one block 606 // This output goes directly to the tty, not the compiler log. 607 // To enable tools to match it up with the compilation activity, 608 // be sure to tag this tty output with the compile ID. 609 if (xtty != NULL) { 610 xtty->begin_head("print_native_nmethod"); 611 xtty->method(_method); 612 xtty->stamp(); 613 xtty->end_head(" address='" INTPTR_FORMAT "'", (intptr_t) this); 614 } 615 // print the header part first 616 print(); 617 // then print the requested information 618 if (PrintNativeNMethods) { 619 print_code(); 620 if (oop_maps != NULL) { 621 oop_maps->print(); 622 } 623 } 624 if (PrintRelocations) { 625 print_relocations(); 626 } 627 if (xtty != NULL) { 628 xtty->tail("print_native_nmethod"); 629 } 630 } 631 } 632 633 void* nmethod::operator new(size_t size, int nmethod_size, int comp_level) throw () { 634 return CodeCache::allocate(nmethod_size, CodeCache::get_code_blob_type(comp_level)); 635 } 636 637 nmethod::nmethod( 638 Method* method, 639 CompilerType type, 640 int nmethod_size, 641 int compile_id, 642 int entry_bci, 643 CodeOffsets* offsets, 644 int orig_pc_offset, 645 DebugInformationRecorder* debug_info, 646 Dependencies* dependencies, 647 CodeBuffer *code_buffer, 648 int frame_size, 649 OopMapSet* oop_maps, 650 ExceptionHandlerTable* handler_table, 651 ImplicitExceptionTable* nul_chk_table, 652 AbstractCompiler* compiler, 653 int comp_level 654 #if INCLUDE_JVMCI 655 , Handle installed_code, 656 Handle speculation_log 657 #endif 658 ) 659 : CompiledMethod(method, "nmethod", type, nmethod_size, sizeof(nmethod), code_buffer, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps, false), 660 _native_receiver_sp_offset(in_ByteSize(-1)), 661 _native_basic_lock_sp_offset(in_ByteSize(-1)) 662 { 663 assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR"); 664 { 665 debug_only(NoSafepointVerifier nsv;) 666 assert_locked_or_safepoint(CodeCache_lock); 667 668 _deopt_handler_begin = (address) this; 669 _deopt_mh_handler_begin = (address) this; 670 671 init_defaults(); 672 _entry_bci = entry_bci; 673 _compile_id = compile_id; 674 _comp_level = comp_level; 675 _orig_pc_offset = orig_pc_offset; 676 _hotness_counter = NMethodSweeper::hotness_counter_reset_val(); 677 678 // Section offsets 679 _consts_offset = content_offset() + code_buffer->total_offset_of(code_buffer->consts()); 680 _stub_offset = content_offset() + code_buffer->total_offset_of(code_buffer->stubs()); 681 set_ctable_begin(header_begin() + _consts_offset); 682 683 #if INCLUDE_JVMCI 684 _jvmci_installed_code = installed_code(); 685 _speculation_log = (instanceOop)speculation_log(); 686 687 if (compiler->is_jvmci()) { 688 // JVMCI might not produce any stub sections 689 if (offsets->value(CodeOffsets::Exceptions) != -1) { 690 _exception_offset = code_offset() + offsets->value(CodeOffsets::Exceptions); 691 } else { 692 _exception_offset = -1; 693 } 694 if (offsets->value(CodeOffsets::Deopt) != -1) { 695 _deopt_handler_begin = (address) this + code_offset() + offsets->value(CodeOffsets::Deopt); 696 } else { 697 _deopt_handler_begin = NULL; 698 } 699 if (offsets->value(CodeOffsets::DeoptMH) != -1) { 700 _deopt_mh_handler_begin = (address) this + code_offset() + offsets->value(CodeOffsets::DeoptMH); 701 } else { 702 _deopt_mh_handler_begin = NULL; 703 } 704 } else { 705 #endif 706 // Exception handler and deopt handler are in the stub section 707 assert(offsets->value(CodeOffsets::Exceptions) != -1, "must be set"); 708 assert(offsets->value(CodeOffsets::Deopt ) != -1, "must be set"); 709 710 _exception_offset = _stub_offset + offsets->value(CodeOffsets::Exceptions); 711 _deopt_handler_begin = (address) this + _stub_offset + offsets->value(CodeOffsets::Deopt); 712 if (offsets->value(CodeOffsets::DeoptMH) != -1) { 713 _deopt_mh_handler_begin = (address) this + _stub_offset + offsets->value(CodeOffsets::DeoptMH); 714 } else { 715 _deopt_mh_handler_begin = NULL; 716 #if INCLUDE_JVMCI 717 } 718 #endif 719 } 720 if (offsets->value(CodeOffsets::UnwindHandler) != -1) { 721 _unwind_handler_offset = code_offset() + offsets->value(CodeOffsets::UnwindHandler); 722 } else { 723 _unwind_handler_offset = -1; 724 } 725 726 _oops_offset = data_offset(); 727 _metadata_offset = _oops_offset + align_up(code_buffer->total_oop_size(), oopSize); 728 int scopes_data_offset = _metadata_offset + align_up(code_buffer->total_metadata_size(), wordSize); 729 730 _scopes_pcs_offset = scopes_data_offset + align_up(debug_info->data_size (), oopSize); 731 _dependencies_offset = _scopes_pcs_offset + adjust_pcs_size(debug_info->pcs_size()); 732 _handler_table_offset = _dependencies_offset + align_up((int)dependencies->size_in_bytes (), oopSize); 733 _nul_chk_table_offset = _handler_table_offset + align_up(handler_table->size_in_bytes(), oopSize); 734 _nmethod_end_offset = _nul_chk_table_offset + align_up(nul_chk_table->size_in_bytes(), oopSize); 735 _entry_point = code_begin() + offsets->value(CodeOffsets::Entry); 736 _verified_entry_point = code_begin() + offsets->value(CodeOffsets::Verified_Entry); 737 _osr_entry_point = code_begin() + offsets->value(CodeOffsets::OSR_Entry); 738 _exception_cache = NULL; 739 740 _scopes_data_begin = (address) this + scopes_data_offset; 741 742 _pc_desc_container.reset_to(scopes_pcs_begin()); 743 744 code_buffer->copy_code_and_locs_to(this); 745 // Copy contents of ScopeDescRecorder to nmethod 746 code_buffer->copy_values_to(this); 747 debug_info->copy_to(this); 748 dependencies->copy_to(this); 749 if (ScavengeRootsInCode) { 750 Universe::heap()->register_nmethod(this); 751 } 752 debug_only(Universe::heap()->verify_nmethod_roots(this)); 753 754 CodeCache::commit(this); 755 756 // Copy contents of ExceptionHandlerTable to nmethod 757 handler_table->copy_to(this); 758 nul_chk_table->copy_to(this); 759 760 // we use the information of entry points to find out if a method is 761 // static or non static 762 assert(compiler->is_c2() || compiler->is_jvmci() || 763 _method->is_static() == (entry_point() == _verified_entry_point), 764 " entry points must be same for static methods and vice versa"); 765 } 766 } 767 768 // Print a short set of xml attributes to identify this nmethod. The 769 // output should be embedded in some other element. 770 void nmethod::log_identity(xmlStream* log) const { 771 log->print(" compile_id='%d'", compile_id()); 772 const char* nm_kind = compile_kind(); 773 if (nm_kind != NULL) log->print(" compile_kind='%s'", nm_kind); 774 log->print(" compiler='%s'", compiler_name()); 775 if (TieredCompilation) { 776 log->print(" level='%d'", comp_level()); 777 } 778 } 779 780 781 #define LOG_OFFSET(log, name) \ 782 if (p2i(name##_end()) - p2i(name##_begin())) \ 783 log->print(" " XSTR(name) "_offset='" INTX_FORMAT "'" , \ 784 p2i(name##_begin()) - p2i(this)) 785 786 787 void nmethod::log_new_nmethod() const { 788 if (LogCompilation && xtty != NULL) { 789 ttyLocker ttyl; 790 HandleMark hm; 791 xtty->begin_elem("nmethod"); 792 log_identity(xtty); 793 xtty->print(" entry='" INTPTR_FORMAT "' size='%d'", p2i(code_begin()), size()); 794 xtty->print(" address='" INTPTR_FORMAT "'", p2i(this)); 795 796 LOG_OFFSET(xtty, relocation); 797 LOG_OFFSET(xtty, consts); 798 LOG_OFFSET(xtty, insts); 799 LOG_OFFSET(xtty, stub); 800 LOG_OFFSET(xtty, scopes_data); 801 LOG_OFFSET(xtty, scopes_pcs); 802 LOG_OFFSET(xtty, dependencies); 803 LOG_OFFSET(xtty, handler_table); 804 LOG_OFFSET(xtty, nul_chk_table); 805 LOG_OFFSET(xtty, oops); 806 LOG_OFFSET(xtty, metadata); 807 808 xtty->method(method()); 809 xtty->stamp(); 810 xtty->end_elem(); 811 } 812 } 813 814 #undef LOG_OFFSET 815 816 817 // Print out more verbose output usually for a newly created nmethod. 818 void nmethod::print_on(outputStream* st, const char* msg) const { 819 if (st != NULL) { 820 ttyLocker ttyl; 821 if (WizardMode) { 822 CompileTask::print(st, this, msg, /*short_form:*/ true); 823 st->print_cr(" (" INTPTR_FORMAT ")", p2i(this)); 824 } else { 825 CompileTask::print(st, this, msg, /*short_form:*/ false); 826 } 827 } 828 } 829 830 void nmethod::maybe_print_nmethod(DirectiveSet* directive) { 831 bool printnmethods = directive->PrintAssemblyOption || directive->PrintNMethodsOption; 832 if (printnmethods || PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers) { 833 print_nmethod(printnmethods); 834 } 835 } 836 837 void nmethod::print_nmethod(bool printmethod) { 838 ttyLocker ttyl; // keep the following output all in one block 839 if (xtty != NULL) { 840 xtty->begin_head("print_nmethod"); 841 xtty->stamp(); 842 xtty->end_head(); 843 } 844 // print the header part first 845 print(); 846 // then print the requested information 847 if (printmethod) { 848 print_code(); 849 print_pcs(); 850 if (oop_maps()) { 851 oop_maps()->print(); 852 } 853 } 854 if (printmethod || PrintDebugInfo || CompilerOracle::has_option_string(_method, "PrintDebugInfo")) { 855 print_scopes(); 856 } 857 if (printmethod || PrintRelocations || CompilerOracle::has_option_string(_method, "PrintRelocations")) { 858 print_relocations(); 859 } 860 if (printmethod || PrintDependencies || CompilerOracle::has_option_string(_method, "PrintDependencies")) { 861 print_dependencies(); 862 } 863 if (printmethod || PrintExceptionHandlers) { 864 print_handler_table(); 865 print_nul_chk_table(); 866 } 867 if (printmethod) { 868 print_recorded_oops(); 869 print_recorded_metadata(); 870 } 871 if (xtty != NULL) { 872 xtty->tail("print_nmethod"); 873 } 874 } 875 876 877 // Promote one word from an assembly-time handle to a live embedded oop. 878 inline void nmethod::initialize_immediate_oop(oop* dest, jobject handle) { 879 if (handle == NULL || 880 // As a special case, IC oops are initialized to 1 or -1. 881 handle == (jobject) Universe::non_oop_word()) { 882 (*dest) = (oop) handle; 883 } else { 884 (*dest) = JNIHandles::resolve_non_null(handle); 885 } 886 } 887 888 889 // Have to have the same name because it's called by a template 890 void nmethod::copy_values(GrowableArray<jobject>* array) { 891 int length = array->length(); 892 assert((address)(oops_begin() + length) <= (address)oops_end(), "oops big enough"); 893 oop* dest = oops_begin(); 894 for (int index = 0 ; index < length; index++) { 895 initialize_immediate_oop(&dest[index], array->at(index)); 896 } 897 898 // Now we can fix up all the oops in the code. We need to do this 899 // in the code because the assembler uses jobjects as placeholders. 900 // The code and relocations have already been initialized by the 901 // CodeBlob constructor, so it is valid even at this early point to 902 // iterate over relocations and patch the code. 903 fix_oop_relocations(NULL, NULL, /*initialize_immediates=*/ true); 904 } 905 906 void nmethod::copy_values(GrowableArray<Metadata*>* array) { 907 int length = array->length(); 908 assert((address)(metadata_begin() + length) <= (address)metadata_end(), "big enough"); 909 Metadata** dest = metadata_begin(); 910 for (int index = 0 ; index < length; index++) { 911 dest[index] = array->at(index); 912 } 913 } 914 915 void nmethod::fix_oop_relocations(address begin, address end, bool initialize_immediates) { 916 // re-patch all oop-bearing instructions, just in case some oops moved 917 RelocIterator iter(this, begin, end); 918 while (iter.next()) { 919 if (iter.type() == relocInfo::oop_type) { 920 oop_Relocation* reloc = iter.oop_reloc(); 921 if (initialize_immediates && reloc->oop_is_immediate()) { 922 oop* dest = reloc->oop_addr(); 923 initialize_immediate_oop(dest, (jobject) *dest); 924 } 925 // Refresh the oop-related bits of this instruction. 926 reloc->fix_oop_relocation(); 927 } else if (iter.type() == relocInfo::metadata_type) { 928 metadata_Relocation* reloc = iter.metadata_reloc(); 929 reloc->fix_metadata_relocation(); 930 } 931 } 932 } 933 934 935 void nmethod::verify_clean_inline_caches() { 936 assert_locked_or_safepoint(CompiledIC_lock); 937 938 // If the method is not entrant or zombie then a JMP is plastered over the 939 // first few bytes. If an oop in the old code was there, that oop 940 // should not get GC'd. Skip the first few bytes of oops on 941 // not-entrant methods. 942 address low_boundary = verified_entry_point(); 943 if (!is_in_use()) { 944 low_boundary += NativeJump::instruction_size; 945 // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump. 946 // This means that the low_boundary is going to be a little too high. 947 // This shouldn't matter, since oops of non-entrant methods are never used. 948 // In fact, why are we bothering to look at oops in a non-entrant method?? 949 } 950 951 ResourceMark rm; 952 RelocIterator iter(this, low_boundary); 953 while(iter.next()) { 954 switch(iter.type()) { 955 case relocInfo::virtual_call_type: 956 case relocInfo::opt_virtual_call_type: { 957 CompiledIC *ic = CompiledIC_at(&iter); 958 // Ok, to lookup references to zombies here 959 CodeBlob *cb = CodeCache::find_blob_unsafe(ic->ic_destination()); 960 nmethod* nm = cb->as_nmethod_or_null(); 961 if( nm != NULL ) { 962 // Verify that inline caches pointing to both zombie and not_entrant methods are clean 963 if (!nm->is_in_use() || (nm->method()->code() != nm)) { 964 assert(ic->is_clean(), "IC should be clean"); 965 } 966 } 967 break; 968 } 969 case relocInfo::static_call_type: { 970 CompiledStaticCall *csc = compiledStaticCall_at(iter.reloc()); 971 CodeBlob *cb = CodeCache::find_blob_unsafe(csc->destination()); 972 nmethod* nm = cb->as_nmethod_or_null(); 973 if( nm != NULL ) { 974 // Verify that inline caches pointing to both zombie and not_entrant methods are clean 975 if (!nm->is_in_use() || (nm->method()->code() != nm)) { 976 assert(csc->is_clean(), "IC should be clean"); 977 } 978 } 979 break; 980 } 981 default: 982 break; 983 } 984 } 985 } 986 987 // This is a private interface with the sweeper. 988 void nmethod::mark_as_seen_on_stack() { 989 assert(is_alive(), "Must be an alive method"); 990 // Set the traversal mark to ensure that the sweeper does 2 991 // cleaning passes before moving to zombie. 992 set_stack_traversal_mark(NMethodSweeper::traversal_count()); 993 } 994 995 // Tell if a non-entrant method can be converted to a zombie (i.e., 996 // there are no activations on the stack, not in use by the VM, 997 // and not in use by the ServiceThread) 998 bool nmethod::can_convert_to_zombie() { 999 assert(is_not_entrant(), "must be a non-entrant method"); 1000 1001 // Since the nmethod sweeper only does partial sweep the sweeper's traversal 1002 // count can be greater than the stack traversal count before it hits the 1003 // nmethod for the second time. 1004 return stack_traversal_mark()+1 < NMethodSweeper::traversal_count() && 1005 !is_locked_by_vm(); 1006 } 1007 1008 void nmethod::inc_decompile_count() { 1009 if (!is_compiled_by_c2() && !is_compiled_by_jvmci()) return; 1010 // Could be gated by ProfileTraps, but do not bother... 1011 Method* m = method(); 1012 if (m == NULL) return; 1013 MethodData* mdo = m->method_data(); 1014 if (mdo == NULL) return; 1015 // There is a benign race here. See comments in methodData.hpp. 1016 mdo->inc_decompile_count(); 1017 } 1018 1019 void nmethod::make_unloaded(BoolObjectClosure* is_alive, oop cause) { 1020 1021 post_compiled_method_unload(); 1022 1023 // Since this nmethod is being unloaded, make sure that dependencies 1024 // recorded in instanceKlasses get flushed and pass non-NULL closure to 1025 // indicate that this work is being done during a GC. 1026 assert(Universe::heap()->is_gc_active(), "should only be called during gc"); 1027 assert(is_alive != NULL, "Should be non-NULL"); 1028 // A non-NULL is_alive closure indicates that this is being called during GC. 1029 flush_dependencies(is_alive); 1030 1031 // Break cycle between nmethod & method 1032 if (log_is_enabled(Trace, class, unload)) { 1033 outputStream* log = Log(class, unload)::trace_stream(); 1034 log->print_cr("making nmethod " INTPTR_FORMAT 1035 " unloadable, Method*(" INTPTR_FORMAT 1036 "), cause(" INTPTR_FORMAT ")", 1037 p2i(this), p2i(_method), p2i(cause)); 1038 if (!Universe::heap()->is_gc_active()) 1039 cause->klass()->print_on(log); 1040 } 1041 // Unlink the osr method, so we do not look this up again 1042 if (is_osr_method()) { 1043 // Invalidate the osr nmethod only once 1044 if (is_in_use()) { 1045 invalidate_osr_method(); 1046 } 1047 #ifdef ASSERT 1048 if (method() != NULL) { 1049 // Make sure osr nmethod is invalidated, i.e. not on the list 1050 bool found = method()->method_holder()->remove_osr_nmethod(this); 1051 assert(!found, "osr nmethod should have been invalidated"); 1052 } 1053 #endif 1054 } 1055 1056 // If _method is already NULL the Method* is about to be unloaded, 1057 // so we don't have to break the cycle. Note that it is possible to 1058 // have the Method* live here, in case we unload the nmethod because 1059 // it is pointing to some oop (other than the Method*) being unloaded. 1060 if (_method != NULL) { 1061 // OSR methods point to the Method*, but the Method* does not 1062 // point back! 1063 if (_method->code() == this) { 1064 _method->clear_code(); // Break a cycle 1065 } 1066 _method = NULL; // Clear the method of this dead nmethod 1067 } 1068 1069 // Make the class unloaded - i.e., change state and notify sweeper 1070 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); 1071 if (is_in_use()) { 1072 // Transitioning directly from live to unloaded -- so 1073 // we need to force a cache clean-up; remember this 1074 // for later on. 1075 CodeCache::set_needs_cache_clean(true); 1076 } 1077 1078 // Unregister must be done before the state change 1079 Universe::heap()->unregister_nmethod(this); 1080 1081 _state = unloaded; 1082 1083 // Log the unloading. 1084 log_state_change(); 1085 1086 #if INCLUDE_JVMCI 1087 // The method can only be unloaded after the pointer to the installed code 1088 // Java wrapper is no longer alive. Here we need to clear out this weak 1089 // reference to the dead object. Nulling out the reference has to happen 1090 // after the method is unregistered since the original value may be still 1091 // tracked by the rset. 1092 maybe_invalidate_installed_code(); 1093 // Clear these out after the nmethod has been unregistered and any 1094 // updates to the InstalledCode instance have been performed. 1095 _jvmci_installed_code = NULL; 1096 _speculation_log = NULL; 1097 #endif 1098 1099 // The Method* is gone at this point 1100 assert(_method == NULL, "Tautology"); 1101 1102 set_osr_link(NULL); 1103 NMethodSweeper::report_state_change(this); 1104 } 1105 1106 void nmethod::invalidate_osr_method() { 1107 assert(_entry_bci != InvocationEntryBci, "wrong kind of nmethod"); 1108 // Remove from list of active nmethods 1109 if (method() != NULL) { 1110 method()->method_holder()->remove_osr_nmethod(this); 1111 } 1112 } 1113 1114 void nmethod::log_state_change() const { 1115 if (LogCompilation) { 1116 if (xtty != NULL) { 1117 ttyLocker ttyl; // keep the following output all in one block 1118 if (_state == unloaded) { 1119 xtty->begin_elem("make_unloaded thread='" UINTX_FORMAT "'", 1120 os::current_thread_id()); 1121 } else { 1122 xtty->begin_elem("make_not_entrant thread='" UINTX_FORMAT "'%s", 1123 os::current_thread_id(), 1124 (_state == zombie ? " zombie='1'" : "")); 1125 } 1126 log_identity(xtty); 1127 xtty->stamp(); 1128 xtty->end_elem(); 1129 } 1130 } 1131 1132 const char *state_msg = _state == zombie ? "made zombie" : "made not entrant"; 1133 CompileTask::print_ul(this, state_msg); 1134 if (PrintCompilation && _state != unloaded) { 1135 print_on(tty, state_msg); 1136 } 1137 } 1138 1139 /** 1140 * Common functionality for both make_not_entrant and make_zombie 1141 */ 1142 bool nmethod::make_not_entrant_or_zombie(unsigned int state) { 1143 assert(state == zombie || state == not_entrant, "must be zombie or not_entrant"); 1144 assert(!is_zombie(), "should not already be a zombie"); 1145 1146 if (_state == state) { 1147 // Avoid taking the lock if already in required state. 1148 // This is safe from races because the state is an end-state, 1149 // which the nmethod cannot back out of once entered. 1150 // No need for fencing either. 1151 return false; 1152 } 1153 1154 // Make sure neither the nmethod nor the method is flushed in case of a safepoint in code below. 1155 nmethodLocker nml(this); 1156 methodHandle the_method(method()); 1157 NoSafepointVerifier nsv; 1158 1159 // during patching, depending on the nmethod state we must notify the GC that 1160 // code has been unloaded, unregistering it. We cannot do this right while 1161 // holding the Patching_lock because we need to use the CodeCache_lock. This 1162 // would be prone to deadlocks. 1163 // This flag is used to remember whether we need to later lock and unregister. 1164 bool nmethod_needs_unregister = false; 1165 1166 { 1167 // invalidate osr nmethod before acquiring the patching lock since 1168 // they both acquire leaf locks and we don't want a deadlock. 1169 // This logic is equivalent to the logic below for patching the 1170 // verified entry point of regular methods. We check that the 1171 // nmethod is in use to ensure that it is invalidated only once. 1172 if (is_osr_method() && is_in_use()) { 1173 // this effectively makes the osr nmethod not entrant 1174 invalidate_osr_method(); 1175 } 1176 1177 // Enter critical section. Does not block for safepoint. 1178 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); 1179 1180 if (_state == state) { 1181 // another thread already performed this transition so nothing 1182 // to do, but return false to indicate this. 1183 return false; 1184 } 1185 1186 // The caller can be calling the method statically or through an inline 1187 // cache call. 1188 if (!is_osr_method() && !is_not_entrant()) { 1189 NativeJump::patch_verified_entry(entry_point(), verified_entry_point(), 1190 SharedRuntime::get_handle_wrong_method_stub()); 1191 } 1192 1193 if (is_in_use() && update_recompile_counts()) { 1194 // It's a true state change, so mark the method as decompiled. 1195 // Do it only for transition from alive. 1196 inc_decompile_count(); 1197 } 1198 1199 // If the state is becoming a zombie, signal to unregister the nmethod with 1200 // the heap. 1201 // This nmethod may have already been unloaded during a full GC. 1202 if ((state == zombie) && !is_unloaded()) { 1203 nmethod_needs_unregister = true; 1204 } 1205 1206 // Must happen before state change. Otherwise we have a race condition in 1207 // nmethod::can_not_entrant_be_converted(). I.e., a method can immediately 1208 // transition its state from 'not_entrant' to 'zombie' without having to wait 1209 // for stack scanning. 1210 if (state == not_entrant) { 1211 mark_as_seen_on_stack(); 1212 OrderAccess::storestore(); 1213 } 1214 1215 // Change state 1216 _state = state; 1217 1218 // Log the transition once 1219 log_state_change(); 1220 1221 // Invalidate while holding the patching lock 1222 JVMCI_ONLY(maybe_invalidate_installed_code()); 1223 1224 // Remove nmethod from method. 1225 // We need to check if both the _code and _from_compiled_code_entry_point 1226 // refer to this nmethod because there is a race in setting these two fields 1227 // in Method* as seen in bugid 4947125. 1228 // If the vep() points to the zombie nmethod, the memory for the nmethod 1229 // could be flushed and the compiler and vtable stubs could still call 1230 // through it. 1231 if (method() != NULL && (method()->code() == this || 1232 method()->from_compiled_entry() == verified_entry_point())) { 1233 HandleMark hm; 1234 method()->clear_code(false /* already owns Patching_lock */); 1235 } 1236 } // leave critical region under Patching_lock 1237 1238 #ifdef ASSERT 1239 if (is_osr_method() && method() != NULL) { 1240 // Make sure osr nmethod is invalidated, i.e. not on the list 1241 bool found = method()->method_holder()->remove_osr_nmethod(this); 1242 assert(!found, "osr nmethod should have been invalidated"); 1243 } 1244 #endif 1245 1246 // When the nmethod becomes zombie it is no longer alive so the 1247 // dependencies must be flushed. nmethods in the not_entrant 1248 // state will be flushed later when the transition to zombie 1249 // happens or they get unloaded. 1250 if (state == zombie) { 1251 { 1252 // Flushing dependencies must be done before any possible 1253 // safepoint can sneak in, otherwise the oops used by the 1254 // dependency logic could have become stale. 1255 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1256 if (nmethod_needs_unregister) { 1257 Universe::heap()->unregister_nmethod(this); 1258 #ifdef JVMCI 1259 _jvmci_installed_code = NULL; 1260 _speculation_log = NULL; 1261 #endif 1262 } 1263 flush_dependencies(NULL); 1264 } 1265 1266 // zombie only - if a JVMTI agent has enabled the CompiledMethodUnload 1267 // event and it hasn't already been reported for this nmethod then 1268 // report it now. The event may have been reported earlier if the GC 1269 // marked it for unloading). JvmtiDeferredEventQueue support means 1270 // we no longer go to a safepoint here. 1271 post_compiled_method_unload(); 1272 1273 #ifdef ASSERT 1274 // It's no longer safe to access the oops section since zombie 1275 // nmethods aren't scanned for GC. 1276 _oops_are_stale = true; 1277 #endif 1278 // the Method may be reclaimed by class unloading now that the 1279 // nmethod is in zombie state 1280 set_method(NULL); 1281 } else { 1282 assert(state == not_entrant, "other cases may need to be handled differently"); 1283 } 1284 1285 if (TraceCreateZombies) { 1286 ResourceMark m; 1287 tty->print_cr("nmethod <" INTPTR_FORMAT "> %s code made %s", p2i(this), this->method() ? this->method()->name_and_sig_as_C_string() : "null", (state == not_entrant) ? "not entrant" : "zombie"); 1288 } 1289 1290 NMethodSweeper::report_state_change(this); 1291 return true; 1292 } 1293 1294 void nmethod::flush() { 1295 // Note that there are no valid oops in the nmethod anymore. 1296 assert(!is_osr_method() || is_unloaded() || is_zombie(), 1297 "osr nmethod must be unloaded or zombie before flushing"); 1298 assert(is_zombie() || is_osr_method(), "must be a zombie method"); 1299 assert (!is_locked_by_vm(), "locked methods shouldn't be flushed"); 1300 assert_locked_or_safepoint(CodeCache_lock); 1301 1302 // completely deallocate this method 1303 Events::log(JavaThread::current(), "flushing nmethod " INTPTR_FORMAT, p2i(this)); 1304 if (PrintMethodFlushing) { 1305 tty->print_cr("*flushing %s nmethod %3d/" INTPTR_FORMAT ". Live blobs:" UINT32_FORMAT 1306 "/Free CodeCache:" SIZE_FORMAT "Kb", 1307 is_osr_method() ? "osr" : "",_compile_id, p2i(this), CodeCache::blob_count(), 1308 CodeCache::unallocated_capacity(CodeCache::get_code_blob_type(this))/1024); 1309 } 1310 1311 // We need to deallocate any ExceptionCache data. 1312 // Note that we do not need to grab the nmethod lock for this, it 1313 // better be thread safe if we're disposing of it! 1314 ExceptionCache* ec = exception_cache(); 1315 set_exception_cache(NULL); 1316 while(ec != NULL) { 1317 ExceptionCache* next = ec->next(); 1318 delete ec; 1319 ec = next; 1320 } 1321 1322 if (on_scavenge_root_list()) { 1323 CodeCache::drop_scavenge_root_nmethod(this); 1324 } 1325 1326 #ifdef SHARK 1327 ((SharkCompiler *) compiler())->free_compiled_method(insts_begin()); 1328 #endif // SHARK 1329 1330 CodeBlob::flush(); 1331 CodeCache::free(this); 1332 } 1333 1334 // 1335 // Notify all classes this nmethod is dependent on that it is no 1336 // longer dependent. This should only be called in two situations. 1337 // First, when a nmethod transitions to a zombie all dependents need 1338 // to be clear. Since zombification happens at a safepoint there's no 1339 // synchronization issues. The second place is a little more tricky. 1340 // During phase 1 of mark sweep class unloading may happen and as a 1341 // result some nmethods may get unloaded. In this case the flushing 1342 // of dependencies must happen during phase 1 since after GC any 1343 // dependencies in the unloaded nmethod won't be updated, so 1344 // traversing the dependency information in unsafe. In that case this 1345 // function is called with a non-NULL argument and this function only 1346 // notifies instanceKlasses that are reachable 1347 1348 void nmethod::flush_dependencies(BoolObjectClosure* is_alive) { 1349 assert_locked_or_safepoint(CodeCache_lock); 1350 assert(Universe::heap()->is_gc_active() == (is_alive != NULL), 1351 "is_alive is non-NULL if and only if we are called during GC"); 1352 if (!has_flushed_dependencies()) { 1353 set_has_flushed_dependencies(); 1354 for (Dependencies::DepStream deps(this); deps.next(); ) { 1355 if (deps.type() == Dependencies::call_site_target_value) { 1356 // CallSite dependencies are managed on per-CallSite instance basis. 1357 oop call_site = deps.argument_oop(0); 1358 MethodHandles::remove_dependent_nmethod(call_site, this); 1359 } else { 1360 Klass* klass = deps.context_type(); 1361 if (klass == NULL) { 1362 continue; // ignore things like evol_method 1363 } 1364 // During GC the is_alive closure is non-NULL, and is used to 1365 // determine liveness of dependees that need to be updated. 1366 if (is_alive == NULL || klass->is_loader_alive(is_alive)) { 1367 // The GC defers deletion of this entry, since there might be multiple threads 1368 // iterating over the _dependencies graph. Other call paths are single-threaded 1369 // and may delete it immediately. 1370 bool delete_immediately = is_alive == NULL; 1371 InstanceKlass::cast(klass)->remove_dependent_nmethod(this, delete_immediately); 1372 } 1373 } 1374 } 1375 } 1376 } 1377 1378 1379 // If this oop is not live, the nmethod can be unloaded. 1380 bool nmethod::can_unload(BoolObjectClosure* is_alive, oop* root, bool unloading_occurred) { 1381 assert(root != NULL, "just checking"); 1382 oop obj = *root; 1383 if (obj == NULL || is_alive->do_object_b(obj)) { 1384 return false; 1385 } 1386 1387 // If ScavengeRootsInCode is true, an nmethod might be unloaded 1388 // simply because one of its constant oops has gone dead. 1389 // No actual classes need to be unloaded in order for this to occur. 1390 assert(unloading_occurred || ScavengeRootsInCode, "Inconsistency in unloading"); 1391 make_unloaded(is_alive, obj); 1392 return true; 1393 } 1394 1395 // ------------------------------------------------------------------ 1396 // post_compiled_method_load_event 1397 // new method for install_code() path 1398 // Transfer information from compilation to jvmti 1399 void nmethod::post_compiled_method_load_event() { 1400 1401 Method* moop = method(); 1402 HOTSPOT_COMPILED_METHOD_LOAD( 1403 (char *) moop->klass_name()->bytes(), 1404 moop->klass_name()->utf8_length(), 1405 (char *) moop->name()->bytes(), 1406 moop->name()->utf8_length(), 1407 (char *) moop->signature()->bytes(), 1408 moop->signature()->utf8_length(), 1409 insts_begin(), insts_size()); 1410 1411 if (JvmtiExport::should_post_compiled_method_load() || 1412 JvmtiExport::should_post_compiled_method_unload()) { 1413 get_and_cache_jmethod_id(); 1414 } 1415 1416 if (JvmtiExport::should_post_compiled_method_load()) { 1417 // Let the Service thread (which is a real Java thread) post the event 1418 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); 1419 JvmtiDeferredEventQueue::enqueue( 1420 JvmtiDeferredEvent::compiled_method_load_event(this)); 1421 } 1422 } 1423 1424 jmethodID nmethod::get_and_cache_jmethod_id() { 1425 if (_jmethod_id == NULL) { 1426 // Cache the jmethod_id since it can no longer be looked up once the 1427 // method itself has been marked for unloading. 1428 _jmethod_id = method()->jmethod_id(); 1429 } 1430 return _jmethod_id; 1431 } 1432 1433 void nmethod::post_compiled_method_unload() { 1434 if (unload_reported()) { 1435 // During unloading we transition to unloaded and then to zombie 1436 // and the unloading is reported during the first transition. 1437 return; 1438 } 1439 1440 assert(_method != NULL && !is_unloaded(), "just checking"); 1441 DTRACE_METHOD_UNLOAD_PROBE(method()); 1442 1443 // If a JVMTI agent has enabled the CompiledMethodUnload event then 1444 // post the event. Sometime later this nmethod will be made a zombie 1445 // by the sweeper but the Method* will not be valid at that point. 1446 // If the _jmethod_id is null then no load event was ever requested 1447 // so don't bother posting the unload. The main reason for this is 1448 // that the jmethodID is a weak reference to the Method* so if 1449 // it's being unloaded there's no way to look it up since the weak 1450 // ref will have been cleared. 1451 if (_jmethod_id != NULL && JvmtiExport::should_post_compiled_method_unload()) { 1452 assert(!unload_reported(), "already unloaded"); 1453 JvmtiDeferredEvent event = 1454 JvmtiDeferredEvent::compiled_method_unload_event(this, 1455 _jmethod_id, insts_begin()); 1456 MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag); 1457 JvmtiDeferredEventQueue::enqueue(event); 1458 } 1459 1460 // The JVMTI CompiledMethodUnload event can be enabled or disabled at 1461 // any time. As the nmethod is being unloaded now we mark it has 1462 // having the unload event reported - this will ensure that we don't 1463 // attempt to report the event in the unlikely scenario where the 1464 // event is enabled at the time the nmethod is made a zombie. 1465 set_unload_reported(); 1466 } 1467 1468 bool nmethod::unload_if_dead_at(RelocIterator* iter_at_oop, BoolObjectClosure *is_alive, bool unloading_occurred) { 1469 assert(iter_at_oop->type() == relocInfo::oop_type, "Wrong relocation type"); 1470 1471 oop_Relocation* r = iter_at_oop->oop_reloc(); 1472 // Traverse those oops directly embedded in the code. 1473 // Other oops (oop_index>0) are seen as part of scopes_oops. 1474 assert(1 == (r->oop_is_immediate()) + 1475 (r->oop_addr() >= oops_begin() && r->oop_addr() < oops_end()), 1476 "oop must be found in exactly one place"); 1477 if (r->oop_is_immediate() && r->oop_value() != NULL) { 1478 // Unload this nmethod if the oop is dead. 1479 if (can_unload(is_alive, r->oop_addr(), unloading_occurred)) { 1480 return true;; 1481 } 1482 } 1483 1484 return false; 1485 } 1486 1487 bool nmethod::do_unloading_scopes(BoolObjectClosure* is_alive, bool unloading_occurred) { 1488 // Scopes 1489 for (oop* p = oops_begin(); p < oops_end(); p++) { 1490 if (*p == Universe::non_oop_word()) continue; // skip non-oops 1491 if (can_unload(is_alive, p, unloading_occurred)) { 1492 return true; 1493 } 1494 } 1495 return false; 1496 } 1497 1498 bool nmethod::do_unloading_oops(address low_boundary, BoolObjectClosure* is_alive, bool unloading_occurred) { 1499 // Compiled code 1500 { 1501 RelocIterator iter(this, low_boundary); 1502 while (iter.next()) { 1503 if (iter.type() == relocInfo::oop_type) { 1504 if (unload_if_dead_at(&iter, is_alive, unloading_occurred)) { 1505 return true; 1506 } 1507 } 1508 } 1509 } 1510 1511 return do_unloading_scopes(is_alive, unloading_occurred); 1512 } 1513 1514 #if INCLUDE_JVMCI 1515 bool nmethod::do_unloading_jvmci(BoolObjectClosure* is_alive, bool unloading_occurred) { 1516 bool is_unloaded = false; 1517 // Follow JVMCI method 1518 BarrierSet* bs = Universe::heap()->barrier_set(); 1519 if (_jvmci_installed_code != NULL) { 1520 if (_jvmci_installed_code->is_a(HotSpotNmethod::klass()) && HotSpotNmethod::isDefault(_jvmci_installed_code)) { 1521 if (!is_alive->do_object_b(_jvmci_installed_code)) { 1522 clear_jvmci_installed_code(); 1523 } 1524 } else { 1525 if (can_unload(is_alive, (oop*)&_jvmci_installed_code, unloading_occurred)) { 1526 return true; 1527 } 1528 } 1529 } 1530 1531 if (_speculation_log != NULL) { 1532 if (!is_alive->do_object_b(_speculation_log)) { 1533 bs->write_ref_nmethod_pre(&_speculation_log, this); 1534 _speculation_log = NULL; 1535 bs->write_ref_nmethod_post(&_speculation_log, this); 1536 } 1537 } 1538 return is_unloaded; 1539 } 1540 #endif 1541 1542 // Iterate over metadata calling this function. Used by RedefineClasses 1543 void nmethod::metadata_do(void f(Metadata*)) { 1544 address low_boundary = verified_entry_point(); 1545 if (is_not_entrant()) { 1546 low_boundary += NativeJump::instruction_size; 1547 // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump. 1548 // (See comment above.) 1549 } 1550 { 1551 // Visit all immediate references that are embedded in the instruction stream. 1552 RelocIterator iter(this, low_boundary); 1553 while (iter.next()) { 1554 if (iter.type() == relocInfo::metadata_type ) { 1555 metadata_Relocation* r = iter.metadata_reloc(); 1556 // In this metadata, we must only follow those metadatas directly embedded in 1557 // the code. Other metadatas (oop_index>0) are seen as part of 1558 // the metadata section below. 1559 assert(1 == (r->metadata_is_immediate()) + 1560 (r->metadata_addr() >= metadata_begin() && r->metadata_addr() < metadata_end()), 1561 "metadata must be found in exactly one place"); 1562 if (r->metadata_is_immediate() && r->metadata_value() != NULL) { 1563 Metadata* md = r->metadata_value(); 1564 if (md != _method) f(md); 1565 } 1566 } else if (iter.type() == relocInfo::virtual_call_type) { 1567 // Check compiledIC holders associated with this nmethod 1568 CompiledIC *ic = CompiledIC_at(&iter); 1569 if (ic->is_icholder_call()) { 1570 CompiledICHolder* cichk = ic->cached_icholder(); 1571 f(cichk->holder_method()); 1572 f(cichk->holder_klass()); 1573 } else { 1574 Metadata* ic_oop = ic->cached_metadata(); 1575 if (ic_oop != NULL) { 1576 f(ic_oop); 1577 } 1578 } 1579 } 1580 } 1581 } 1582 1583 // Visit the metadata section 1584 for (Metadata** p = metadata_begin(); p < metadata_end(); p++) { 1585 if (*p == Universe::non_oop_word() || *p == NULL) continue; // skip non-oops 1586 Metadata* md = *p; 1587 f(md); 1588 } 1589 1590 // Visit metadata not embedded in the other places. 1591 if (_method != NULL) f(_method); 1592 } 1593 1594 void nmethod::oops_do(OopClosure* f, bool allow_zombie) { 1595 // make sure the oops ready to receive visitors 1596 assert(allow_zombie || !is_zombie(), "should not call follow on zombie nmethod"); 1597 assert(!is_unloaded(), "should not call follow on unloaded nmethod"); 1598 1599 // If the method is not entrant or zombie then a JMP is plastered over the 1600 // first few bytes. If an oop in the old code was there, that oop 1601 // should not get GC'd. Skip the first few bytes of oops on 1602 // not-entrant methods. 1603 address low_boundary = verified_entry_point(); 1604 if (is_not_entrant()) { 1605 low_boundary += NativeJump::instruction_size; 1606 // %%% Note: On SPARC we patch only a 4-byte trap, not a full NativeJump. 1607 // (See comment above.) 1608 } 1609 1610 #if INCLUDE_JVMCI 1611 if (_jvmci_installed_code != NULL) { 1612 f->do_oop((oop*) &_jvmci_installed_code); 1613 } 1614 if (_speculation_log != NULL) { 1615 f->do_oop((oop*) &_speculation_log); 1616 } 1617 #endif 1618 1619 RelocIterator iter(this, low_boundary); 1620 1621 while (iter.next()) { 1622 if (iter.type() == relocInfo::oop_type ) { 1623 oop_Relocation* r = iter.oop_reloc(); 1624 // In this loop, we must only follow those oops directly embedded in 1625 // the code. Other oops (oop_index>0) are seen as part of scopes_oops. 1626 assert(1 == (r->oop_is_immediate()) + 1627 (r->oop_addr() >= oops_begin() && r->oop_addr() < oops_end()), 1628 "oop must be found in exactly one place"); 1629 if (r->oop_is_immediate() && r->oop_value() != NULL) { 1630 f->do_oop(r->oop_addr()); 1631 } 1632 } 1633 } 1634 1635 // Scopes 1636 // This includes oop constants not inlined in the code stream. 1637 for (oop* p = oops_begin(); p < oops_end(); p++) { 1638 if (*p == Universe::non_oop_word()) continue; // skip non-oops 1639 f->do_oop(p); 1640 } 1641 } 1642 1643 #define NMETHOD_SENTINEL ((nmethod*)badAddress) 1644 1645 nmethod* volatile nmethod::_oops_do_mark_nmethods; 1646 1647 // An nmethod is "marked" if its _mark_link is set non-null. 1648 // Even if it is the end of the linked list, it will have a non-null link value, 1649 // as long as it is on the list. 1650 // This code must be MP safe, because it is used from parallel GC passes. 1651 bool nmethod::test_set_oops_do_mark() { 1652 assert(nmethod::oops_do_marking_is_active(), "oops_do_marking_prologue must be called"); 1653 nmethod* observed_mark_link = _oops_do_mark_link; 1654 if (observed_mark_link == NULL) { 1655 // Claim this nmethod for this thread to mark. 1656 observed_mark_link = (nmethod*) 1657 Atomic::cmpxchg_ptr(NMETHOD_SENTINEL, &_oops_do_mark_link, NULL); 1658 if (observed_mark_link == NULL) { 1659 1660 // Atomically append this nmethod (now claimed) to the head of the list: 1661 nmethod* observed_mark_nmethods = _oops_do_mark_nmethods; 1662 for (;;) { 1663 nmethod* required_mark_nmethods = observed_mark_nmethods; 1664 _oops_do_mark_link = required_mark_nmethods; 1665 observed_mark_nmethods = (nmethod*) 1666 Atomic::cmpxchg_ptr(this, &_oops_do_mark_nmethods, required_mark_nmethods); 1667 if (observed_mark_nmethods == required_mark_nmethods) 1668 break; 1669 } 1670 // Mark was clear when we first saw this guy. 1671 if (TraceScavenge) { print_on(tty, "oops_do, mark"); } 1672 return false; 1673 } 1674 } 1675 // On fall through, another racing thread marked this nmethod before we did. 1676 return true; 1677 } 1678 1679 void nmethod::oops_do_marking_prologue() { 1680 if (TraceScavenge) { tty->print_cr("[oops_do_marking_prologue"); } 1681 assert(_oops_do_mark_nmethods == NULL, "must not call oops_do_marking_prologue twice in a row"); 1682 // We use cmpxchg_ptr instead of regular assignment here because the user 1683 // may fork a bunch of threads, and we need them all to see the same state. 1684 void* observed = Atomic::cmpxchg_ptr(NMETHOD_SENTINEL, &_oops_do_mark_nmethods, NULL); 1685 guarantee(observed == NULL, "no races in this sequential code"); 1686 } 1687 1688 void nmethod::oops_do_marking_epilogue() { 1689 assert(_oops_do_mark_nmethods != NULL, "must not call oops_do_marking_epilogue twice in a row"); 1690 nmethod* cur = _oops_do_mark_nmethods; 1691 while (cur != NMETHOD_SENTINEL) { 1692 assert(cur != NULL, "not NULL-terminated"); 1693 nmethod* next = cur->_oops_do_mark_link; 1694 cur->_oops_do_mark_link = NULL; 1695 DEBUG_ONLY(cur->verify_oop_relocations()); 1696 NOT_PRODUCT(if (TraceScavenge) cur->print_on(tty, "oops_do, unmark")); 1697 cur = next; 1698 } 1699 void* required = _oops_do_mark_nmethods; 1700 void* observed = Atomic::cmpxchg_ptr(NULL, &_oops_do_mark_nmethods, required); 1701 guarantee(observed == required, "no races in this sequential code"); 1702 if (TraceScavenge) { tty->print_cr("oops_do_marking_epilogue]"); } 1703 } 1704 1705 class DetectScavengeRoot: public OopClosure { 1706 bool _detected_scavenge_root; 1707 public: 1708 DetectScavengeRoot() : _detected_scavenge_root(false) 1709 { NOT_PRODUCT(_print_nm = NULL); } 1710 bool detected_scavenge_root() { return _detected_scavenge_root; } 1711 virtual void do_oop(oop* p) { 1712 if ((*p) != NULL && (*p)->is_scavengable()) { 1713 NOT_PRODUCT(maybe_print(p)); 1714 _detected_scavenge_root = true; 1715 } 1716 } 1717 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } 1718 1719 #ifndef PRODUCT 1720 nmethod* _print_nm; 1721 void maybe_print(oop* p) { 1722 if (_print_nm == NULL) return; 1723 if (!_detected_scavenge_root) _print_nm->print_on(tty, "new scavenge root"); 1724 tty->print_cr("" PTR_FORMAT "[offset=%d] detected scavengable oop " PTR_FORMAT " (found at " PTR_FORMAT ")", 1725 p2i(_print_nm), (int)((intptr_t)p - (intptr_t)_print_nm), 1726 p2i(*p), p2i(p)); 1727 (*p)->print(); 1728 } 1729 #endif //PRODUCT 1730 }; 1731 1732 bool nmethod::detect_scavenge_root_oops() { 1733 DetectScavengeRoot detect_scavenge_root; 1734 NOT_PRODUCT(if (TraceScavenge) detect_scavenge_root._print_nm = this); 1735 oops_do(&detect_scavenge_root); 1736 return detect_scavenge_root.detected_scavenge_root(); 1737 } 1738 1739 inline bool includes(void* p, void* from, void* to) { 1740 return from <= p && p < to; 1741 } 1742 1743 1744 void nmethod::copy_scopes_pcs(PcDesc* pcs, int count) { 1745 assert(count >= 2, "must be sentinel values, at least"); 1746 1747 #ifdef ASSERT 1748 // must be sorted and unique; we do a binary search in find_pc_desc() 1749 int prev_offset = pcs[0].pc_offset(); 1750 assert(prev_offset == PcDesc::lower_offset_limit, 1751 "must start with a sentinel"); 1752 for (int i = 1; i < count; i++) { 1753 int this_offset = pcs[i].pc_offset(); 1754 assert(this_offset > prev_offset, "offsets must be sorted"); 1755 prev_offset = this_offset; 1756 } 1757 assert(prev_offset == PcDesc::upper_offset_limit, 1758 "must end with a sentinel"); 1759 #endif //ASSERT 1760 1761 // Search for MethodHandle invokes and tag the nmethod. 1762 for (int i = 0; i < count; i++) { 1763 if (pcs[i].is_method_handle_invoke()) { 1764 set_has_method_handle_invokes(true); 1765 break; 1766 } 1767 } 1768 assert(has_method_handle_invokes() == (_deopt_mh_handler_begin != NULL), "must have deopt mh handler"); 1769 1770 int size = count * sizeof(PcDesc); 1771 assert(scopes_pcs_size() >= size, "oob"); 1772 memcpy(scopes_pcs_begin(), pcs, size); 1773 1774 // Adjust the final sentinel downward. 1775 PcDesc* last_pc = &scopes_pcs_begin()[count-1]; 1776 assert(last_pc->pc_offset() == PcDesc::upper_offset_limit, "sanity"); 1777 last_pc->set_pc_offset(content_size() + 1); 1778 for (; last_pc + 1 < scopes_pcs_end(); last_pc += 1) { 1779 // Fill any rounding gaps with copies of the last record. 1780 last_pc[1] = last_pc[0]; 1781 } 1782 // The following assert could fail if sizeof(PcDesc) is not 1783 // an integral multiple of oopSize (the rounding term). 1784 // If it fails, change the logic to always allocate a multiple 1785 // of sizeof(PcDesc), and fill unused words with copies of *last_pc. 1786 assert(last_pc + 1 == scopes_pcs_end(), "must match exactly"); 1787 } 1788 1789 void nmethod::copy_scopes_data(u_char* buffer, int size) { 1790 assert(scopes_data_size() >= size, "oob"); 1791 memcpy(scopes_data_begin(), buffer, size); 1792 } 1793 1794 #ifdef ASSERT 1795 static PcDesc* linear_search(const PcDescSearch& search, int pc_offset, bool approximate) { 1796 PcDesc* lower = search.scopes_pcs_begin(); 1797 PcDesc* upper = search.scopes_pcs_end(); 1798 lower += 1; // exclude initial sentinel 1799 PcDesc* res = NULL; 1800 for (PcDesc* p = lower; p < upper; p++) { 1801 NOT_PRODUCT(--pc_nmethod_stats.pc_desc_tests); // don't count this call to match_desc 1802 if (match_desc(p, pc_offset, approximate)) { 1803 if (res == NULL) 1804 res = p; 1805 else 1806 res = (PcDesc*) badAddress; 1807 } 1808 } 1809 return res; 1810 } 1811 #endif 1812 1813 1814 // Finds a PcDesc with real-pc equal to "pc" 1815 PcDesc* PcDescContainer::find_pc_desc_internal(address pc, bool approximate, const PcDescSearch& search) { 1816 address base_address = search.code_begin(); 1817 if ((pc < base_address) || 1818 (pc - base_address) >= (ptrdiff_t) PcDesc::upper_offset_limit) { 1819 return NULL; // PC is wildly out of range 1820 } 1821 int pc_offset = (int) (pc - base_address); 1822 1823 // Check the PcDesc cache if it contains the desired PcDesc 1824 // (This as an almost 100% hit rate.) 1825 PcDesc* res = _pc_desc_cache.find_pc_desc(pc_offset, approximate); 1826 if (res != NULL) { 1827 assert(res == linear_search(search, pc_offset, approximate), "cache ok"); 1828 return res; 1829 } 1830 1831 // Fallback algorithm: quasi-linear search for the PcDesc 1832 // Find the last pc_offset less than the given offset. 1833 // The successor must be the required match, if there is a match at all. 1834 // (Use a fixed radix to avoid expensive affine pointer arithmetic.) 1835 PcDesc* lower = search.scopes_pcs_begin(); 1836 PcDesc* upper = search.scopes_pcs_end(); 1837 upper -= 1; // exclude final sentinel 1838 if (lower >= upper) return NULL; // native method; no PcDescs at all 1839 1840 #define assert_LU_OK \ 1841 /* invariant on lower..upper during the following search: */ \ 1842 assert(lower->pc_offset() < pc_offset, "sanity"); \ 1843 assert(upper->pc_offset() >= pc_offset, "sanity") 1844 assert_LU_OK; 1845 1846 // Use the last successful return as a split point. 1847 PcDesc* mid = _pc_desc_cache.last_pc_desc(); 1848 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_searches); 1849 if (mid->pc_offset() < pc_offset) { 1850 lower = mid; 1851 } else { 1852 upper = mid; 1853 } 1854 1855 // Take giant steps at first (4096, then 256, then 16, then 1) 1856 const int LOG2_RADIX = 4 /*smaller steps in debug mode:*/ debug_only(-1); 1857 const int RADIX = (1 << LOG2_RADIX); 1858 for (int step = (1 << (LOG2_RADIX*3)); step > 1; step >>= LOG2_RADIX) { 1859 while ((mid = lower + step) < upper) { 1860 assert_LU_OK; 1861 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_searches); 1862 if (mid->pc_offset() < pc_offset) { 1863 lower = mid; 1864 } else { 1865 upper = mid; 1866 break; 1867 } 1868 } 1869 assert_LU_OK; 1870 } 1871 1872 // Sneak up on the value with a linear search of length ~16. 1873 while (true) { 1874 assert_LU_OK; 1875 mid = lower + 1; 1876 NOT_PRODUCT(++pc_nmethod_stats.pc_desc_searches); 1877 if (mid->pc_offset() < pc_offset) { 1878 lower = mid; 1879 } else { 1880 upper = mid; 1881 break; 1882 } 1883 } 1884 #undef assert_LU_OK 1885 1886 if (match_desc(upper, pc_offset, approximate)) { 1887 assert(upper == linear_search(search, pc_offset, approximate), "search ok"); 1888 _pc_desc_cache.add_pc_desc(upper); 1889 return upper; 1890 } else { 1891 assert(NULL == linear_search(search, pc_offset, approximate), "search ok"); 1892 return NULL; 1893 } 1894 } 1895 1896 1897 void nmethod::check_all_dependencies(DepChange& changes) { 1898 // Checked dependencies are allocated into this ResourceMark 1899 ResourceMark rm; 1900 1901 // Turn off dependency tracing while actually testing dependencies. 1902 NOT_PRODUCT( FlagSetting fs(TraceDependencies, false) ); 1903 1904 typedef ResourceHashtable<DependencySignature, int, &DependencySignature::hash, 1905 &DependencySignature::equals, 11027> DepTable; 1906 1907 DepTable* table = new DepTable(); 1908 1909 // Iterate over live nmethods and check dependencies of all nmethods that are not 1910 // marked for deoptimization. A particular dependency is only checked once. 1911 NMethodIterator iter; 1912 while(iter.next()) { 1913 nmethod* nm = iter.method(); 1914 // Only notify for live nmethods 1915 if (nm->is_alive() && !nm->is_marked_for_deoptimization()) { 1916 for (Dependencies::DepStream deps(nm); deps.next(); ) { 1917 // Construct abstraction of a dependency. 1918 DependencySignature* current_sig = new DependencySignature(deps); 1919 1920 // Determine if dependency is already checked. table->put(...) returns 1921 // 'true' if the dependency is added (i.e., was not in the hashtable). 1922 if (table->put(*current_sig, 1)) { 1923 if (deps.check_dependency() != NULL) { 1924 // Dependency checking failed. Print out information about the failed 1925 // dependency and finally fail with an assert. We can fail here, since 1926 // dependency checking is never done in a product build. 1927 tty->print_cr("Failed dependency:"); 1928 changes.print(); 1929 nm->print(); 1930 nm->print_dependencies(); 1931 assert(false, "Should have been marked for deoptimization"); 1932 } 1933 } 1934 } 1935 } 1936 } 1937 } 1938 1939 bool nmethod::check_dependency_on(DepChange& changes) { 1940 // What has happened: 1941 // 1) a new class dependee has been added 1942 // 2) dependee and all its super classes have been marked 1943 bool found_check = false; // set true if we are upset 1944 for (Dependencies::DepStream deps(this); deps.next(); ) { 1945 // Evaluate only relevant dependencies. 1946 if (deps.spot_check_dependency_at(changes) != NULL) { 1947 found_check = true; 1948 NOT_DEBUG(break); 1949 } 1950 } 1951 return found_check; 1952 } 1953 1954 bool nmethod::is_evol_dependent_on(Klass* dependee) { 1955 InstanceKlass *dependee_ik = InstanceKlass::cast(dependee); 1956 Array<Method*>* dependee_methods = dependee_ik->methods(); 1957 for (Dependencies::DepStream deps(this); deps.next(); ) { 1958 if (deps.type() == Dependencies::evol_method) { 1959 Method* method = deps.method_argument(0); 1960 for (int j = 0; j < dependee_methods->length(); j++) { 1961 if (dependee_methods->at(j) == method) { 1962 if (log_is_enabled(Debug, redefine, class, nmethod)) { 1963 ResourceMark rm; 1964 log_debug(redefine, class, nmethod) 1965 ("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)", 1966 _method->method_holder()->external_name(), 1967 _method->name()->as_C_string(), 1968 _method->signature()->as_C_string(), 1969 compile_id(), 1970 method->method_holder()->external_name(), 1971 method->name()->as_C_string(), 1972 method->signature()->as_C_string()); 1973 } 1974 if (TraceDependencies || LogCompilation) 1975 deps.log_dependency(dependee); 1976 return true; 1977 } 1978 } 1979 } 1980 } 1981 return false; 1982 } 1983 1984 // Called from mark_for_deoptimization, when dependee is invalidated. 1985 bool nmethod::is_dependent_on_method(Method* dependee) { 1986 for (Dependencies::DepStream deps(this); deps.next(); ) { 1987 if (deps.type() != Dependencies::evol_method) 1988 continue; 1989 Method* method = deps.method_argument(0); 1990 if (method == dependee) return true; 1991 } 1992 return false; 1993 } 1994 1995 1996 bool nmethod::is_patchable_at(address instr_addr) { 1997 assert(insts_contains(instr_addr), "wrong nmethod used"); 1998 if (is_zombie()) { 1999 // a zombie may never be patched 2000 return false; 2001 } 2002 return true; 2003 } 2004 2005 2006 address nmethod::continuation_for_implicit_exception(address pc) { 2007 // Exception happened outside inline-cache check code => we are inside 2008 // an active nmethod => use cpc to determine a return address 2009 int exception_offset = pc - code_begin(); 2010 int cont_offset = ImplicitExceptionTable(this).at( exception_offset ); 2011 #ifdef ASSERT 2012 if (cont_offset == 0) { 2013 Thread* thread = Thread::current(); 2014 ResetNoHandleMark rnm; // Might be called from LEAF/QUICK ENTRY 2015 HandleMark hm(thread); 2016 ResourceMark rm(thread); 2017 CodeBlob* cb = CodeCache::find_blob(pc); 2018 assert(cb != NULL && cb == this, ""); 2019 ttyLocker ttyl; 2020 tty->print_cr("implicit exception happened at " INTPTR_FORMAT, p2i(pc)); 2021 print(); 2022 method()->print_codes(); 2023 print_code(); 2024 print_pcs(); 2025 } 2026 #endif 2027 if (cont_offset == 0) { 2028 // Let the normal error handling report the exception 2029 return NULL; 2030 } 2031 return code_begin() + cont_offset; 2032 } 2033 2034 2035 2036 void nmethod_init() { 2037 // make sure you didn't forget to adjust the filler fields 2038 assert(sizeof(nmethod) % oopSize == 0, "nmethod size must be multiple of a word"); 2039 } 2040 2041 2042 //------------------------------------------------------------------------------------------- 2043 2044 2045 // QQQ might we make this work from a frame?? 2046 nmethodLocker::nmethodLocker(address pc) { 2047 CodeBlob* cb = CodeCache::find_blob(pc); 2048 guarantee(cb != NULL && cb->is_compiled(), "bad pc for a nmethod found"); 2049 _nm = cb->as_compiled_method(); 2050 lock_nmethod(_nm); 2051 } 2052 2053 // Only JvmtiDeferredEvent::compiled_method_unload_event() 2054 // should pass zombie_ok == true. 2055 void nmethodLocker::lock_nmethod(CompiledMethod* cm, bool zombie_ok) { 2056 if (cm == NULL) return; 2057 if (cm->is_aot()) return; // FIXME: Revisit once _lock_count is added to aot_method 2058 nmethod* nm = cm->as_nmethod(); 2059 Atomic::inc(&nm->_lock_count); 2060 assert(zombie_ok || !nm->is_zombie(), "cannot lock a zombie method"); 2061 } 2062 2063 void nmethodLocker::unlock_nmethod(CompiledMethod* cm) { 2064 if (cm == NULL) return; 2065 if (cm->is_aot()) return; // FIXME: Revisit once _lock_count is added to aot_method 2066 nmethod* nm = cm->as_nmethod(); 2067 Atomic::dec(&nm->_lock_count); 2068 assert(nm->_lock_count >= 0, "unmatched nmethod lock/unlock"); 2069 } 2070 2071 2072 // ----------------------------------------------------------------------------- 2073 // Verification 2074 2075 class VerifyOopsClosure: public OopClosure { 2076 nmethod* _nm; 2077 bool _ok; 2078 public: 2079 VerifyOopsClosure(nmethod* nm) : _nm(nm), _ok(true) { } 2080 bool ok() { return _ok; } 2081 virtual void do_oop(oop* p) { 2082 if ((*p) == NULL || (*p)->is_oop()) return; 2083 if (_ok) { 2084 _nm->print_nmethod(true); 2085 _ok = false; 2086 } 2087 tty->print_cr("*** non-oop " PTR_FORMAT " found at " PTR_FORMAT " (offset %d)", 2088 p2i(*p), p2i(p), (int)((intptr_t)p - (intptr_t)_nm)); 2089 } 2090 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } 2091 }; 2092 2093 void nmethod::verify() { 2094 2095 // Hmm. OSR methods can be deopted but not marked as zombie or not_entrant 2096 // seems odd. 2097 2098 if (is_zombie() || is_not_entrant() || is_unloaded()) 2099 return; 2100 2101 // Make sure all the entry points are correctly aligned for patching. 2102 NativeJump::check_verified_entry_alignment(entry_point(), verified_entry_point()); 2103 2104 // assert(method()->is_oop(), "must be valid"); 2105 2106 ResourceMark rm; 2107 2108 if (!CodeCache::contains(this)) { 2109 fatal("nmethod at " INTPTR_FORMAT " not in zone", p2i(this)); 2110 } 2111 2112 if(is_native_method() ) 2113 return; 2114 2115 nmethod* nm = CodeCache::find_nmethod(verified_entry_point()); 2116 if (nm != this) { 2117 fatal("findNMethod did not find this nmethod (" INTPTR_FORMAT ")", p2i(this)); 2118 } 2119 2120 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) { 2121 if (! p->verify(this)) { 2122 tty->print_cr("\t\tin nmethod at " INTPTR_FORMAT " (pcs)", p2i(this)); 2123 } 2124 } 2125 2126 VerifyOopsClosure voc(this); 2127 oops_do(&voc); 2128 assert(voc.ok(), "embedded oops must be OK"); 2129 Universe::heap()->verify_nmethod_roots(this); 2130 2131 verify_scopes(); 2132 } 2133 2134 2135 void nmethod::verify_interrupt_point(address call_site) { 2136 // Verify IC only when nmethod installation is finished. 2137 bool is_installed = (method()->code() == this) // nmethod is in state 'in_use' and installed 2138 || !this->is_in_use(); // nmethod is installed, but not in 'in_use' state 2139 if (is_installed) { 2140 Thread *cur = Thread::current(); 2141 if (CompiledIC_lock->owner() == cur || 2142 ((cur->is_VM_thread() || cur->is_ConcurrentGC_thread()) && 2143 SafepointSynchronize::is_at_safepoint())) { 2144 CompiledIC_at(this, call_site); 2145 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); 2146 } else { 2147 MutexLocker ml_verify (CompiledIC_lock); 2148 CompiledIC_at(this, call_site); 2149 } 2150 } 2151 2152 PcDesc* pd = pc_desc_at(nativeCall_at(call_site)->return_address()); 2153 assert(pd != NULL, "PcDesc must exist"); 2154 for (ScopeDesc* sd = new ScopeDesc(this, pd->scope_decode_offset(), 2155 pd->obj_decode_offset(), pd->should_reexecute(), pd->rethrow_exception(), 2156 pd->return_oop()); 2157 !sd->is_top(); sd = sd->sender()) { 2158 sd->verify(); 2159 } 2160 } 2161 2162 void nmethod::verify_scopes() { 2163 if( !method() ) return; // Runtime stubs have no scope 2164 if (method()->is_native()) return; // Ignore stub methods. 2165 // iterate through all interrupt point 2166 // and verify the debug information is valid. 2167 RelocIterator iter((nmethod*)this); 2168 while (iter.next()) { 2169 address stub = NULL; 2170 switch (iter.type()) { 2171 case relocInfo::virtual_call_type: 2172 verify_interrupt_point(iter.addr()); 2173 break; 2174 case relocInfo::opt_virtual_call_type: 2175 stub = iter.opt_virtual_call_reloc()->static_stub(false); 2176 verify_interrupt_point(iter.addr()); 2177 break; 2178 case relocInfo::static_call_type: 2179 stub = iter.static_call_reloc()->static_stub(false); 2180 //verify_interrupt_point(iter.addr()); 2181 break; 2182 case relocInfo::runtime_call_type: 2183 case relocInfo::runtime_call_w_cp_type: { 2184 address destination = iter.reloc()->value(); 2185 // Right now there is no way to find out which entries support 2186 // an interrupt point. It would be nice if we had this 2187 // information in a table. 2188 break; 2189 } 2190 default: 2191 break; 2192 } 2193 assert(stub == NULL || stub_contains(stub), "static call stub outside stub section"); 2194 } 2195 } 2196 2197 2198 // ----------------------------------------------------------------------------- 2199 // Non-product code 2200 #ifndef PRODUCT 2201 2202 class DebugScavengeRoot: public OopClosure { 2203 nmethod* _nm; 2204 bool _ok; 2205 public: 2206 DebugScavengeRoot(nmethod* nm) : _nm(nm), _ok(true) { } 2207 bool ok() { return _ok; } 2208 virtual void do_oop(oop* p) { 2209 if ((*p) == NULL || !(*p)->is_scavengable()) return; 2210 if (_ok) { 2211 _nm->print_nmethod(true); 2212 _ok = false; 2213 } 2214 tty->print_cr("*** scavengable oop " PTR_FORMAT " found at " PTR_FORMAT " (offset %d)", 2215 p2i(*p), p2i(p), (int)((intptr_t)p - (intptr_t)_nm)); 2216 (*p)->print(); 2217 } 2218 virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } 2219 }; 2220 2221 void nmethod::verify_scavenge_root_oops() { 2222 if (!on_scavenge_root_list()) { 2223 // Actually look inside, to verify the claim that it's clean. 2224 DebugScavengeRoot debug_scavenge_root(this); 2225 oops_do(&debug_scavenge_root); 2226 if (!debug_scavenge_root.ok()) 2227 fatal("found an unadvertised bad scavengable oop in the code cache"); 2228 } 2229 assert(scavenge_root_not_marked(), ""); 2230 } 2231 2232 #endif // PRODUCT 2233 2234 // Printing operations 2235 2236 void nmethod::print() const { 2237 ResourceMark rm; 2238 ttyLocker ttyl; // keep the following output all in one block 2239 2240 tty->print("Compiled method "); 2241 2242 if (is_compiled_by_c1()) { 2243 tty->print("(c1) "); 2244 } else if (is_compiled_by_c2()) { 2245 tty->print("(c2) "); 2246 } else if (is_compiled_by_shark()) { 2247 tty->print("(shark) "); 2248 } else if (is_compiled_by_jvmci()) { 2249 tty->print("(JVMCI) "); 2250 } else { 2251 tty->print("(nm) "); 2252 } 2253 2254 print_on(tty, NULL); 2255 2256 if (WizardMode) { 2257 tty->print("((nmethod*) " INTPTR_FORMAT ") ", p2i(this)); 2258 tty->print(" for method " INTPTR_FORMAT , p2i(method())); 2259 tty->print(" { "); 2260 tty->print_cr("%s ", state()); 2261 if (on_scavenge_root_list()) tty->print("scavenge_root "); 2262 tty->print_cr("}:"); 2263 } 2264 if (size () > 0) tty->print_cr(" total in heap [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2265 p2i(this), 2266 p2i(this) + size(), 2267 size()); 2268 if (relocation_size () > 0) tty->print_cr(" relocation [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2269 p2i(relocation_begin()), 2270 p2i(relocation_end()), 2271 relocation_size()); 2272 if (consts_size () > 0) tty->print_cr(" constants [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2273 p2i(consts_begin()), 2274 p2i(consts_end()), 2275 consts_size()); 2276 if (insts_size () > 0) tty->print_cr(" main code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2277 p2i(insts_begin()), 2278 p2i(insts_end()), 2279 insts_size()); 2280 if (stub_size () > 0) tty->print_cr(" stub code [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2281 p2i(stub_begin()), 2282 p2i(stub_end()), 2283 stub_size()); 2284 if (oops_size () > 0) tty->print_cr(" oops [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2285 p2i(oops_begin()), 2286 p2i(oops_end()), 2287 oops_size()); 2288 if (metadata_size () > 0) tty->print_cr(" metadata [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2289 p2i(metadata_begin()), 2290 p2i(metadata_end()), 2291 metadata_size()); 2292 if (scopes_data_size () > 0) tty->print_cr(" scopes data [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2293 p2i(scopes_data_begin()), 2294 p2i(scopes_data_end()), 2295 scopes_data_size()); 2296 if (scopes_pcs_size () > 0) tty->print_cr(" scopes pcs [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2297 p2i(scopes_pcs_begin()), 2298 p2i(scopes_pcs_end()), 2299 scopes_pcs_size()); 2300 if (dependencies_size () > 0) tty->print_cr(" dependencies [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2301 p2i(dependencies_begin()), 2302 p2i(dependencies_end()), 2303 dependencies_size()); 2304 if (handler_table_size() > 0) tty->print_cr(" handler table [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2305 p2i(handler_table_begin()), 2306 p2i(handler_table_end()), 2307 handler_table_size()); 2308 if (nul_chk_table_size() > 0) tty->print_cr(" nul chk table [" INTPTR_FORMAT "," INTPTR_FORMAT "] = %d", 2309 p2i(nul_chk_table_begin()), 2310 p2i(nul_chk_table_end()), 2311 nul_chk_table_size()); 2312 } 2313 2314 #ifndef PRODUCT 2315 2316 void nmethod::print_scopes() { 2317 // Find the first pc desc for all scopes in the code and print it. 2318 ResourceMark rm; 2319 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) { 2320 if (p->scope_decode_offset() == DebugInformationRecorder::serialized_null) 2321 continue; 2322 2323 ScopeDesc* sd = scope_desc_at(p->real_pc(this)); 2324 while (sd != NULL) { 2325 sd->print_on(tty, p); 2326 sd = sd->sender(); 2327 } 2328 } 2329 } 2330 2331 void nmethod::print_dependencies() { 2332 ResourceMark rm; 2333 ttyLocker ttyl; // keep the following output all in one block 2334 tty->print_cr("Dependencies:"); 2335 for (Dependencies::DepStream deps(this); deps.next(); ) { 2336 deps.print_dependency(); 2337 Klass* ctxk = deps.context_type(); 2338 if (ctxk != NULL) { 2339 if (ctxk->is_instance_klass() && InstanceKlass::cast(ctxk)->is_dependent_nmethod(this)) { 2340 tty->print_cr(" [nmethod<=klass]%s", ctxk->external_name()); 2341 } 2342 } 2343 deps.log_dependency(); // put it into the xml log also 2344 } 2345 } 2346 2347 2348 void nmethod::print_relocations() { 2349 ResourceMark m; // in case methods get printed via the debugger 2350 tty->print_cr("relocations:"); 2351 RelocIterator iter(this); 2352 iter.print(); 2353 } 2354 2355 2356 void nmethod::print_pcs() { 2357 ResourceMark m; // in case methods get printed via debugger 2358 tty->print_cr("pc-bytecode offsets:"); 2359 for (PcDesc* p = scopes_pcs_begin(); p < scopes_pcs_end(); p++) { 2360 p->print(this); 2361 } 2362 } 2363 2364 void nmethod::print_recorded_oops() { 2365 tty->print_cr("Recorded oops:"); 2366 for (int i = 0; i < oops_count(); i++) { 2367 oop o = oop_at(i); 2368 tty->print("#%3d: " INTPTR_FORMAT " ", i, p2i(o)); 2369 if (o == (oop)Universe::non_oop_word()) { 2370 tty->print("non-oop word"); 2371 } else { 2372 o->print_value(); 2373 } 2374 tty->cr(); 2375 } 2376 } 2377 2378 void nmethod::print_recorded_metadata() { 2379 tty->print_cr("Recorded metadata:"); 2380 for (int i = 0; i < metadata_count(); i++) { 2381 Metadata* m = metadata_at(i); 2382 tty->print("#%3d: " INTPTR_FORMAT " ", i, p2i(m)); 2383 if (m == (Metadata*)Universe::non_oop_word()) { 2384 tty->print("non-metadata word"); 2385 } else { 2386 m->print_value_on_maybe_null(tty); 2387 } 2388 tty->cr(); 2389 } 2390 } 2391 2392 #endif // PRODUCT 2393 2394 const char* nmethod::reloc_string_for(u_char* begin, u_char* end) { 2395 RelocIterator iter(this, begin, end); 2396 bool have_one = false; 2397 while (iter.next()) { 2398 have_one = true; 2399 switch (iter.type()) { 2400 case relocInfo::none: return "no_reloc"; 2401 case relocInfo::oop_type: { 2402 stringStream st; 2403 oop_Relocation* r = iter.oop_reloc(); 2404 oop obj = r->oop_value(); 2405 st.print("oop("); 2406 if (obj == NULL) st.print("NULL"); 2407 else obj->print_value_on(&st); 2408 st.print(")"); 2409 return st.as_string(); 2410 } 2411 case relocInfo::metadata_type: { 2412 stringStream st; 2413 metadata_Relocation* r = iter.metadata_reloc(); 2414 Metadata* obj = r->metadata_value(); 2415 st.print("metadata("); 2416 if (obj == NULL) st.print("NULL"); 2417 else obj->print_value_on(&st); 2418 st.print(")"); 2419 return st.as_string(); 2420 } 2421 case relocInfo::runtime_call_type: 2422 case relocInfo::runtime_call_w_cp_type: { 2423 stringStream st; 2424 st.print("runtime_call"); 2425 CallRelocation* r = (CallRelocation*)iter.reloc(); 2426 address dest = r->destination(); 2427 CodeBlob* cb = CodeCache::find_blob(dest); 2428 if (cb != NULL) { 2429 st.print(" %s", cb->name()); 2430 } else { 2431 ResourceMark rm; 2432 const int buflen = 1024; 2433 char* buf = NEW_RESOURCE_ARRAY(char, buflen); 2434 int offset; 2435 if (os::dll_address_to_function_name(dest, buf, buflen, &offset)) { 2436 st.print(" %s", buf); 2437 if (offset != 0) { 2438 st.print("+%d", offset); 2439 } 2440 } 2441 } 2442 return st.as_string(); 2443 } 2444 case relocInfo::virtual_call_type: { 2445 stringStream st; 2446 st.print_raw("virtual_call"); 2447 virtual_call_Relocation* r = iter.virtual_call_reloc(); 2448 Method* m = r->method_value(); 2449 if (m != NULL) { 2450 assert(m->is_method(), ""); 2451 m->print_short_name(&st); 2452 } 2453 return st.as_string(); 2454 } 2455 case relocInfo::opt_virtual_call_type: { 2456 stringStream st; 2457 st.print_raw("optimized virtual_call"); 2458 opt_virtual_call_Relocation* r = iter.opt_virtual_call_reloc(); 2459 Method* m = r->method_value(); 2460 if (m != NULL) { 2461 assert(m->is_method(), ""); 2462 m->print_short_name(&st); 2463 } 2464 return st.as_string(); 2465 } 2466 case relocInfo::static_call_type: { 2467 stringStream st; 2468 st.print_raw("static_call"); 2469 static_call_Relocation* r = iter.static_call_reloc(); 2470 Method* m = r->method_value(); 2471 if (m != NULL) { 2472 assert(m->is_method(), ""); 2473 m->print_short_name(&st); 2474 } 2475 return st.as_string(); 2476 } 2477 case relocInfo::static_stub_type: return "static_stub"; 2478 case relocInfo::external_word_type: return "external_word"; 2479 case relocInfo::internal_word_type: return "internal_word"; 2480 case relocInfo::section_word_type: return "section_word"; 2481 case relocInfo::poll_type: return "poll"; 2482 case relocInfo::poll_return_type: return "poll_return"; 2483 case relocInfo::type_mask: return "type_bit_mask"; 2484 2485 default: 2486 break; 2487 } 2488 } 2489 return have_one ? "other" : NULL; 2490 } 2491 2492 // Return a the last scope in (begin..end] 2493 ScopeDesc* nmethod::scope_desc_in(address begin, address end) { 2494 PcDesc* p = pc_desc_near(begin+1); 2495 if (p != NULL && p->real_pc(this) <= end) { 2496 return new ScopeDesc(this, p->scope_decode_offset(), 2497 p->obj_decode_offset(), p->should_reexecute(), p->rethrow_exception(), 2498 p->return_oop()); 2499 } 2500 return NULL; 2501 } 2502 2503 void nmethod::print_nmethod_labels(outputStream* stream, address block_begin) const { 2504 if (block_begin == entry_point()) stream->print_cr("[Entry Point]"); 2505 if (block_begin == verified_entry_point()) stream->print_cr("[Verified Entry Point]"); 2506 if (JVMCI_ONLY(_exception_offset >= 0 &&) block_begin == exception_begin()) stream->print_cr("[Exception Handler]"); 2507 if (block_begin == stub_begin()) stream->print_cr("[Stub Code]"); 2508 if (JVMCI_ONLY(_deopt_handler_begin != NULL &&) block_begin == deopt_handler_begin()) stream->print_cr("[Deopt Handler Code]"); 2509 2510 if (has_method_handle_invokes()) 2511 if (block_begin == deopt_mh_handler_begin()) stream->print_cr("[Deopt MH Handler Code]"); 2512 2513 if (block_begin == consts_begin()) stream->print_cr("[Constants]"); 2514 2515 if (block_begin == entry_point()) { 2516 methodHandle m = method(); 2517 if (m.not_null()) { 2518 stream->print(" # "); 2519 m->print_value_on(stream); 2520 stream->cr(); 2521 } 2522 if (m.not_null() && !is_osr_method()) { 2523 ResourceMark rm; 2524 int sizeargs = m->size_of_parameters(); 2525 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs); 2526 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs); 2527 { 2528 int sig_index = 0; 2529 if (!m->is_static()) 2530 sig_bt[sig_index++] = T_OBJECT; // 'this' 2531 for (SignatureStream ss(m->signature()); !ss.at_return_type(); ss.next()) { 2532 BasicType t = ss.type(); 2533 sig_bt[sig_index++] = t; 2534 if (type2size[t] == 2) { 2535 sig_bt[sig_index++] = T_VOID; 2536 } else { 2537 assert(type2size[t] == 1, "size is 1 or 2"); 2538 } 2539 } 2540 assert(sig_index == sizeargs, ""); 2541 } 2542 const char* spname = "sp"; // make arch-specific? 2543 intptr_t out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs, false); 2544 int stack_slot_offset = this->frame_size() * wordSize; 2545 int tab1 = 14, tab2 = 24; 2546 int sig_index = 0; 2547 int arg_index = (m->is_static() ? 0 : -1); 2548 bool did_old_sp = false; 2549 for (SignatureStream ss(m->signature()); !ss.at_return_type(); ) { 2550 bool at_this = (arg_index == -1); 2551 bool at_old_sp = false; 2552 BasicType t = (at_this ? T_OBJECT : ss.type()); 2553 assert(t == sig_bt[sig_index], "sigs in sync"); 2554 if (at_this) 2555 stream->print(" # this: "); 2556 else 2557 stream->print(" # parm%d: ", arg_index); 2558 stream->move_to(tab1); 2559 VMReg fst = regs[sig_index].first(); 2560 VMReg snd = regs[sig_index].second(); 2561 if (fst->is_reg()) { 2562 stream->print("%s", fst->name()); 2563 if (snd->is_valid()) { 2564 stream->print(":%s", snd->name()); 2565 } 2566 } else if (fst->is_stack()) { 2567 int offset = fst->reg2stack() * VMRegImpl::stack_slot_size + stack_slot_offset; 2568 if (offset == stack_slot_offset) at_old_sp = true; 2569 stream->print("[%s+0x%x]", spname, offset); 2570 } else { 2571 stream->print("reg%d:%d??", (int)(intptr_t)fst, (int)(intptr_t)snd); 2572 } 2573 stream->print(" "); 2574 stream->move_to(tab2); 2575 stream->print("= "); 2576 if (at_this) { 2577 m->method_holder()->print_value_on(stream); 2578 } else { 2579 bool did_name = false; 2580 if (!at_this && ss.is_object()) { 2581 Symbol* name = ss.as_symbol_or_null(); 2582 if (name != NULL) { 2583 name->print_value_on(stream); 2584 did_name = true; 2585 } 2586 } 2587 if (!did_name) 2588 stream->print("%s", type2name(t)); 2589 } 2590 if (at_old_sp) { 2591 stream->print(" (%s of caller)", spname); 2592 did_old_sp = true; 2593 } 2594 stream->cr(); 2595 sig_index += type2size[t]; 2596 arg_index += 1; 2597 if (!at_this) ss.next(); 2598 } 2599 if (!did_old_sp) { 2600 stream->print(" # "); 2601 stream->move_to(tab1); 2602 stream->print("[%s+0x%x]", spname, stack_slot_offset); 2603 stream->print(" (%s of caller)", spname); 2604 stream->cr(); 2605 } 2606 } 2607 } 2608 } 2609 2610 void nmethod::print_code_comment_on(outputStream* st, int column, u_char* begin, u_char* end) { 2611 // First, find an oopmap in (begin, end]. 2612 // We use the odd half-closed interval so that oop maps and scope descs 2613 // which are tied to the byte after a call are printed with the call itself. 2614 address base = code_begin(); 2615 ImmutableOopMapSet* oms = oop_maps(); 2616 if (oms != NULL) { 2617 for (int i = 0, imax = oms->count(); i < imax; i++) { 2618 const ImmutableOopMapPair* pair = oms->pair_at(i); 2619 const ImmutableOopMap* om = pair->get_from(oms); 2620 address pc = base + pair->pc_offset(); 2621 if (pc > begin) { 2622 if (pc <= end) { 2623 st->move_to(column); 2624 st->print("; "); 2625 om->print_on(st); 2626 } 2627 break; 2628 } 2629 } 2630 } 2631 2632 // Print any debug info present at this pc. 2633 ScopeDesc* sd = scope_desc_in(begin, end); 2634 if (sd != NULL) { 2635 st->move_to(column); 2636 if (sd->bci() == SynchronizationEntryBCI) { 2637 st->print(";*synchronization entry"); 2638 } else { 2639 if (sd->method() == NULL) { 2640 st->print("method is NULL"); 2641 } else if (sd->method()->is_native()) { 2642 st->print("method is native"); 2643 } else { 2644 Bytecodes::Code bc = sd->method()->java_code_at(sd->bci()); 2645 st->print(";*%s", Bytecodes::name(bc)); 2646 switch (bc) { 2647 case Bytecodes::_invokevirtual: 2648 case Bytecodes::_invokespecial: 2649 case Bytecodes::_invokestatic: 2650 case Bytecodes::_invokeinterface: 2651 { 2652 Bytecode_invoke invoke(sd->method(), sd->bci()); 2653 st->print(" "); 2654 if (invoke.name() != NULL) 2655 invoke.name()->print_symbol_on(st); 2656 else 2657 st->print("<UNKNOWN>"); 2658 break; 2659 } 2660 case Bytecodes::_getfield: 2661 case Bytecodes::_putfield: 2662 case Bytecodes::_getstatic: 2663 case Bytecodes::_putstatic: 2664 { 2665 Bytecode_field field(sd->method(), sd->bci()); 2666 st->print(" "); 2667 if (field.name() != NULL) 2668 field.name()->print_symbol_on(st); 2669 else 2670 st->print("<UNKNOWN>"); 2671 } 2672 default: 2673 break; 2674 } 2675 } 2676 st->print(" {reexecute=%d rethrow=%d return_oop=%d}", sd->should_reexecute(), sd->rethrow_exception(), sd->return_oop()); 2677 } 2678 2679 // Print all scopes 2680 for (;sd != NULL; sd = sd->sender()) { 2681 st->move_to(column); 2682 st->print("; -"); 2683 if (sd->method() == NULL) { 2684 st->print("method is NULL"); 2685 } else { 2686 sd->method()->print_short_name(st); 2687 } 2688 int lineno = sd->method()->line_number_from_bci(sd->bci()); 2689 if (lineno != -1) { 2690 st->print("@%d (line %d)", sd->bci(), lineno); 2691 } else { 2692 st->print("@%d", sd->bci()); 2693 } 2694 st->cr(); 2695 } 2696 } 2697 2698 // Print relocation information 2699 const char* str = reloc_string_for(begin, end); 2700 if (str != NULL) { 2701 if (sd != NULL) st->cr(); 2702 st->move_to(column); 2703 st->print("; {%s}", str); 2704 } 2705 int cont_offset = ImplicitExceptionTable(this).at(begin - code_begin()); 2706 if (cont_offset != 0) { 2707 st->move_to(column); 2708 st->print("; implicit exception: dispatches to " INTPTR_FORMAT, p2i(code_begin() + cont_offset)); 2709 } 2710 2711 } 2712 2713 class DirectNativeCallWrapper: public NativeCallWrapper { 2714 private: 2715 NativeCall* _call; 2716 2717 public: 2718 DirectNativeCallWrapper(NativeCall* call) : _call(call) {} 2719 2720 virtual address destination() const { return _call->destination(); } 2721 virtual address instruction_address() const { return _call->instruction_address(); } 2722 virtual address next_instruction_address() const { return _call->next_instruction_address(); } 2723 virtual address return_address() const { return _call->return_address(); } 2724 2725 virtual address get_resolve_call_stub(bool is_optimized) const { 2726 if (is_optimized) { 2727 return SharedRuntime::get_resolve_opt_virtual_call_stub(); 2728 } 2729 return SharedRuntime::get_resolve_virtual_call_stub(); 2730 } 2731 2732 virtual void set_destination_mt_safe(address dest) { 2733 #if INCLUDE_AOT 2734 if (UseAOT) { 2735 CodeBlob* callee = CodeCache::find_blob(dest); 2736 CompiledMethod* cm = callee->as_compiled_method_or_null(); 2737 if (cm != NULL && cm->is_far_code()) { 2738 // Temporary fix, see JDK-8143106 2739 CompiledDirectStaticCall* csc = CompiledDirectStaticCall::at(instruction_address()); 2740 csc->set_to_far(methodHandle(cm->method()), dest); 2741 return; 2742 } 2743 } 2744 #endif 2745 _call->set_destination_mt_safe(dest); 2746 } 2747 2748 virtual void set_to_interpreted(const methodHandle& method, CompiledICInfo& info) { 2749 CompiledDirectStaticCall* csc = CompiledDirectStaticCall::at(instruction_address()); 2750 #if INCLUDE_AOT 2751 if (info.to_aot()) { 2752 csc->set_to_far(method, info.entry()); 2753 } else 2754 #endif 2755 { 2756 csc->set_to_interpreted(method, info.entry()); 2757 } 2758 } 2759 2760 virtual void verify() const { 2761 // make sure code pattern is actually a call imm32 instruction 2762 _call->verify(); 2763 if (os::is_MP()) { 2764 _call->verify_alignment(); 2765 } 2766 } 2767 2768 virtual void verify_resolve_call(address dest) const { 2769 CodeBlob* db = CodeCache::find_blob_unsafe(dest); 2770 assert(!db->is_adapter_blob(), "must use stub!"); 2771 } 2772 2773 virtual bool is_call_to_interpreted(address dest) const { 2774 CodeBlob* cb = CodeCache::find_blob(_call->instruction_address()); 2775 return cb->contains(dest); 2776 } 2777 2778 virtual bool is_safe_for_patching() const { return false; } 2779 2780 virtual NativeInstruction* get_load_instruction(virtual_call_Relocation* r) const { 2781 return nativeMovConstReg_at(r->cached_value()); 2782 } 2783 2784 virtual void *get_data(NativeInstruction* instruction) const { 2785 return (void*)((NativeMovConstReg*) instruction)->data(); 2786 } 2787 2788 virtual void set_data(NativeInstruction* instruction, intptr_t data) { 2789 ((NativeMovConstReg*) instruction)->set_data(data); 2790 } 2791 }; 2792 2793 NativeCallWrapper* nmethod::call_wrapper_at(address call) const { 2794 return new DirectNativeCallWrapper((NativeCall*) call); 2795 } 2796 2797 NativeCallWrapper* nmethod::call_wrapper_before(address return_pc) const { 2798 return new DirectNativeCallWrapper(nativeCall_before(return_pc)); 2799 } 2800 2801 address nmethod::call_instruction_address(address pc) const { 2802 if (NativeCall::is_call_before(pc)) { 2803 NativeCall *ncall = nativeCall_before(pc); 2804 return ncall->instruction_address(); 2805 } 2806 return NULL; 2807 } 2808 2809 CompiledStaticCall* nmethod::compiledStaticCall_at(Relocation* call_site) const { 2810 return CompiledDirectStaticCall::at(call_site); 2811 } 2812 2813 CompiledStaticCall* nmethod::compiledStaticCall_at(address call_site) const { 2814 return CompiledDirectStaticCall::at(call_site); 2815 } 2816 2817 CompiledStaticCall* nmethod::compiledStaticCall_before(address return_addr) const { 2818 return CompiledDirectStaticCall::before(return_addr); 2819 } 2820 2821 #ifndef PRODUCT 2822 2823 void nmethod::print_value_on(outputStream* st) const { 2824 st->print("nmethod"); 2825 print_on(st, NULL); 2826 } 2827 2828 void nmethod::print_calls(outputStream* st) { 2829 RelocIterator iter(this); 2830 while (iter.next()) { 2831 switch (iter.type()) { 2832 case relocInfo::virtual_call_type: 2833 case relocInfo::opt_virtual_call_type: { 2834 VerifyMutexLocker mc(CompiledIC_lock); 2835 CompiledIC_at(&iter)->print(); 2836 break; 2837 } 2838 case relocInfo::static_call_type: 2839 st->print_cr("Static call at " INTPTR_FORMAT, p2i(iter.reloc()->addr())); 2840 CompiledDirectStaticCall::at(iter.reloc())->print(); 2841 break; 2842 default: 2843 break; 2844 } 2845 } 2846 } 2847 2848 void nmethod::print_handler_table() { 2849 ExceptionHandlerTable(this).print(); 2850 } 2851 2852 void nmethod::print_nul_chk_table() { 2853 ImplicitExceptionTable(this).print(code_begin()); 2854 } 2855 2856 void nmethod::print_statistics() { 2857 ttyLocker ttyl; 2858 if (xtty != NULL) xtty->head("statistics type='nmethod'"); 2859 native_nmethod_stats.print_native_nmethod_stats(); 2860 #ifdef COMPILER1 2861 c1_java_nmethod_stats.print_nmethod_stats("C1"); 2862 #endif 2863 #ifdef COMPILER2 2864 c2_java_nmethod_stats.print_nmethod_stats("C2"); 2865 #endif 2866 #if INCLUDE_JVMCI 2867 jvmci_java_nmethod_stats.print_nmethod_stats("JVMCI"); 2868 #endif 2869 #ifdef SHARK 2870 shark_java_nmethod_stats.print_nmethod_stats("Shark"); 2871 #endif 2872 unknown_java_nmethod_stats.print_nmethod_stats("Unknown"); 2873 DebugInformationRecorder::print_statistics(); 2874 #ifndef PRODUCT 2875 pc_nmethod_stats.print_pc_stats(); 2876 #endif 2877 Dependencies::print_statistics(); 2878 if (xtty != NULL) xtty->tail("statistics"); 2879 } 2880 2881 #endif // !PRODUCT 2882 2883 #if INCLUDE_JVMCI 2884 void nmethod::clear_jvmci_installed_code() { 2885 // write_ref_method_pre/post can only be safely called at a 2886 // safepoint or while holding the CodeCache_lock 2887 assert(CodeCache_lock->is_locked() || 2888 SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency"); 2889 if (_jvmci_installed_code != NULL) { 2890 // This must be done carefully to maintain nmethod remembered sets properly 2891 BarrierSet* bs = Universe::heap()->barrier_set(); 2892 bs->write_ref_nmethod_pre(&_jvmci_installed_code, this); 2893 _jvmci_installed_code = NULL; 2894 bs->write_ref_nmethod_post(&_jvmci_installed_code, this); 2895 } 2896 } 2897 2898 void nmethod::maybe_invalidate_installed_code() { 2899 assert(Patching_lock->is_locked() || 2900 SafepointSynchronize::is_at_safepoint(), "should be performed under a lock for consistency"); 2901 oop installed_code = jvmci_installed_code(); 2902 if (installed_code != NULL) { 2903 nmethod* nm = (nmethod*)InstalledCode::address(installed_code); 2904 if (nm == NULL || nm != this) { 2905 // The link has been broken or the InstalledCode instance is 2906 // associated with another nmethod so do nothing. 2907 return; 2908 } 2909 if (!is_alive()) { 2910 // Break the link between nmethod and InstalledCode such that the nmethod 2911 // can subsequently be flushed safely. The link must be maintained while 2912 // the method could have live activations since invalidateInstalledCode 2913 // might want to invalidate all existing activations. 2914 InstalledCode::set_address(installed_code, 0); 2915 InstalledCode::set_entryPoint(installed_code, 0); 2916 } else if (is_not_entrant()) { 2917 // Remove the entry point so any invocation will fail but keep 2918 // the address link around that so that existing activations can 2919 // be invalidated. 2920 InstalledCode::set_entryPoint(installed_code, 0); 2921 } 2922 } 2923 } 2924 2925 void nmethod::invalidate_installed_code(Handle installedCode, TRAPS) { 2926 if (installedCode() == NULL) { 2927 THROW(vmSymbols::java_lang_NullPointerException()); 2928 } 2929 jlong nativeMethod = InstalledCode::address(installedCode); 2930 nmethod* nm = (nmethod*)nativeMethod; 2931 if (nm == NULL) { 2932 // Nothing to do 2933 return; 2934 } 2935 2936 nmethodLocker nml(nm); 2937 #ifdef ASSERT 2938 { 2939 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); 2940 // This relationship can only be checked safely under a lock 2941 assert(nm == NULL || !nm->is_alive() || nm->jvmci_installed_code() == installedCode(), "sanity check"); 2942 } 2943 #endif 2944 2945 if (nm->is_alive()) { 2946 // The nmethod state machinery maintains the link between the 2947 // HotSpotInstalledCode and nmethod* so as long as the nmethod appears to be 2948 // alive assume there is work to do and deoptimize the nmethod. 2949 nm->mark_for_deoptimization(); 2950 VM_Deoptimize op; 2951 VMThread::execute(&op); 2952 } 2953 2954 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag); 2955 // Check that it's still associated with the same nmethod and break 2956 // the link if it is. 2957 if (InstalledCode::address(installedCode) == nativeMethod) { 2958 InstalledCode::set_address(installedCode, 0); 2959 } 2960 } 2961 2962 char* nmethod::jvmci_installed_code_name(char* buf, size_t buflen) { 2963 if (!this->is_compiled_by_jvmci()) { 2964 return NULL; 2965 } 2966 oop installedCode = this->jvmci_installed_code(); 2967 if (installedCode != NULL) { 2968 oop installedCodeName = NULL; 2969 if (installedCode->is_a(InstalledCode::klass())) { 2970 installedCodeName = InstalledCode::name(installedCode); 2971 } 2972 if (installedCodeName != NULL) { 2973 return java_lang_String::as_utf8_string(installedCodeName, buf, (int)buflen); 2974 } else { 2975 jio_snprintf(buf, buflen, "null"); 2976 return buf; 2977 } 2978 } 2979 jio_snprintf(buf, buflen, "noInstalledCode"); 2980 return buf; 2981 } 2982 #endif