Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/vm/code/nmethod.cpp
          +++ new/src/share/vm/code/nmethod.cpp
↓ open down ↓ 20 lines elided ↑ open up ↑
  21   21   * questions.
  22   22   *
  23   23   */
  24   24  
  25   25  #include "precompiled.hpp"
  26   26  #include "code/codeCache.hpp"
  27   27  #include "code/compiledIC.hpp"
  28   28  #include "code/nmethod.hpp"
  29   29  #include "code/scopeDesc.hpp"
  30   30  #include "compiler/abstractCompiler.hpp"
       31 +#include "compiler/compileBroker.hpp"
  31   32  #include "compiler/compileLog.hpp"
  32   33  #include "compiler/compilerOracle.hpp"
  33   34  #include "compiler/disassembler.hpp"
  34   35  #include "interpreter/bytecode.hpp"
  35   36  #include "oops/methodDataOop.hpp"
  36   37  #include "prims/jvmtiRedefineClassesTrace.hpp"
  37   38  #include "prims/jvmtiImpl.hpp"
  38   39  #include "runtime/sharedRuntime.hpp"
  39   40  #include "runtime/sweeper.hpp"
  40   41  #include "utilities/dtrace.hpp"
↓ open down ↓ 421 lines elided ↑ open up ↑
 462  463    _saved_nmethod_link      = NULL;
 463  464    _compiler                = NULL;
 464  465  
 465  466  #ifdef HAVE_DTRACE_H
 466  467    _trap_offset             = 0;
 467  468  #endif // def HAVE_DTRACE_H
 468  469  }
 469  470  
 470  471  
 471  472  nmethod* nmethod::new_native_nmethod(methodHandle method,
      473 +  int compile_id,
 472  474    CodeBuffer *code_buffer,
 473  475    int vep_offset,
 474  476    int frame_complete,
 475  477    int frame_size,
 476  478    ByteSize basic_lock_owner_sp_offset,
 477  479    ByteSize basic_lock_sp_offset,
 478  480    OopMapSet* oop_maps) {
 479  481    // create nmethod
 480  482    nmethod* nm = NULL;
 481  483    {
 482  484      MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 483  485      int native_nmethod_size = allocation_size(code_buffer, sizeof(nmethod));
 484  486      CodeOffsets offsets;
 485  487      offsets.set_value(CodeOffsets::Verified_Entry, vep_offset);
 486  488      offsets.set_value(CodeOffsets::Frame_Complete, frame_complete);
 487  489      nm = new (native_nmethod_size)
 488      -      nmethod(method(), native_nmethod_size, &offsets,
      490 +      nmethod(method(), native_nmethod_size, compile_id, &offsets,
 489  491                code_buffer, frame_size,
 490  492                basic_lock_owner_sp_offset, basic_lock_sp_offset,
 491  493                oop_maps);
 492  494      NOT_PRODUCT(if (nm != NULL)  nmethod_stats.note_native_nmethod(nm));
 493  495      if (PrintAssembly && nm != NULL)
 494  496        Disassembler::decode(nm);
 495  497    }
 496  498    // verify nmethod
 497  499    debug_only(if (nm) nm->verify();) // might block
 498  500  
↓ open down ↓ 104 lines elided ↑ open up ↑
 603  605  
 604  606    // done
 605  607    return nm;
 606  608  }
 607  609  
 608  610  
 609  611  // For native wrappers
 610  612  nmethod::nmethod(
 611  613    methodOop method,
 612  614    int nmethod_size,
      615 +  int compile_id,
 613  616    CodeOffsets* offsets,
 614  617    CodeBuffer* code_buffer,
 615  618    int frame_size,
 616  619    ByteSize basic_lock_owner_sp_offset,
 617  620    ByteSize basic_lock_sp_offset,
 618  621    OopMapSet* oop_maps )
 619  622    : CodeBlob("native nmethod", code_buffer, sizeof(nmethod),
 620  623               nmethod_size, offsets->value(CodeOffsets::Frame_Complete), frame_size, oop_maps),
 621  624    _native_receiver_sp_offset(basic_lock_owner_sp_offset),
 622  625    _native_basic_lock_sp_offset(basic_lock_sp_offset)
↓ open down ↓ 14 lines elided ↑ open up ↑
 637  640  
 638  641      _consts_offset           = data_offset();
 639  642      _stub_offset             = data_offset();
 640  643      _oops_offset             = data_offset();
 641  644      _scopes_data_offset      = _oops_offset          + round_to(code_buffer->total_oop_size(), oopSize);
 642  645      _scopes_pcs_offset       = _scopes_data_offset;
 643  646      _dependencies_offset     = _scopes_pcs_offset;
 644  647      _handler_table_offset    = _dependencies_offset;
 645  648      _nul_chk_table_offset    = _handler_table_offset;
 646  649      _nmethod_end_offset      = _nul_chk_table_offset;
 647      -    _compile_id              = 0;  // default
      650 +    _compile_id              = compile_id;
 648  651      _comp_level              = CompLevel_none;
 649  652      _entry_point             = code_begin()          + offsets->value(CodeOffsets::Entry);
 650  653      _verified_entry_point    = code_begin()          + offsets->value(CodeOffsets::Verified_Entry);
 651  654      _osr_entry_point         = NULL;
 652  655      _exception_cache         = NULL;
 653  656      _pc_desc_cache.reset_to(NULL);
 654  657  
 655  658      code_buffer->copy_oops_to(this);
 656  659      if (ScavengeRootsInCode && detect_scavenge_root_oops()) {
 657  660        CodeCache::add_scavenge_root_nmethod(this);
↓ open down ↓ 265 lines elided ↑ open up ↑
 923  926  
 924  927      xtty->method(method());
 925  928      xtty->stamp();
 926  929      xtty->end_elem();
 927  930    }
 928  931  }
 929  932  
 930  933  #undef LOG_OFFSET
 931  934  
 932  935  
 933      -void nmethod::print_compilation(outputStream *st, const char *method_name, const char *title,
 934      -                                methodOop method, bool is_blocking, int compile_id, int bci, int comp_level) {
 935      -  bool is_synchronized = false, has_xhandler = false, is_native = false;
 936      -  int code_size = -1;
 937      -  if (method != NULL) {
 938      -    is_synchronized = method->is_synchronized();
 939      -    has_xhandler    = method->has_exception_handler();
 940      -    is_native       = method->is_native();
 941      -    code_size       = method->code_size();
 942      -  }
 943      -  // print compilation number
 944      -  st->print("%7d %3d", (int)tty->time_stamp().milliseconds(), compile_id);
 945      -
 946      -  // print method attributes
 947      -  const bool is_osr = bci != InvocationEntryBci;
 948      -  const char blocking_char  = is_blocking     ? 'b' : ' ';
 949      -  const char compile_type   = is_osr          ? '%' : ' ';
 950      -  const char sync_char      = is_synchronized ? 's' : ' ';
 951      -  const char exception_char = has_xhandler    ? '!' : ' ';
 952      -  const char native_char    = is_native       ? 'n' : ' ';
 953      -  st->print("%c%c%c%c%c ", compile_type, sync_char, exception_char, blocking_char, native_char);
 954      -  if (TieredCompilation) {
 955      -    st->print("%d ", comp_level);
 956      -  }
 957      -
 958      -  // print optional title
 959      -  bool do_nl = false;
 960      -  if (title != NULL) {
 961      -    int tlen = (int) strlen(title);
 962      -    bool do_nl = false;
 963      -    if (tlen > 0 && title[tlen-1] == '\n') { tlen--; do_nl = true; }
 964      -    st->print("%.*s", tlen, title);
 965      -  } else {
 966      -    do_nl = true;
 967      -  }
 968      -
 969      -  // print method name string if given
 970      -  if (method_name != NULL) {
 971      -    st->print(method_name);
 972      -  } else {
 973      -    // otherwise as the method to print itself
 974      -    if (method != NULL && !Universe::heap()->is_gc_active()) {
 975      -      method->print_short_name(st);
 976      -    } else {
 977      -      st->print("(method)");
 978      -    }
 979      -  }
 980      -
 981      -  if (method != NULL) {
 982      -    // print osr_bci if any
 983      -    if (is_osr) st->print(" @ %d", bci);
 984      -    // print method size
 985      -    st->print(" (%d bytes)", code_size);
 986      -  }
 987      -  if (do_nl) st->cr();
 988      -}
 989      -
 990  936  // Print out more verbose output usually for a newly created nmethod.
 991      -void nmethod::print_on(outputStream* st, const char* title) const {
      937 +void nmethod::print_on(outputStream* st, const char* msg) const {
 992  938    if (st != NULL) {
 993  939      ttyLocker ttyl;
 994      -    print_compilation(st, /*method_name*/NULL, title,
 995      -                      method(), /*is_blocking*/false,
 996      -                      compile_id(),
 997      -                      is_osr_method() ? osr_entry_bci() : InvocationEntryBci,
 998      -                      comp_level());
      940 +    CompileTask::print_compilation(st, this, msg);
 999  941      if (WizardMode) st->print(" (" INTPTR_FORMAT ")", this);
1000  942    }
1001  943  }
1002  944  
1003  945  
1004  946  void nmethod::print_nmethod(bool printmethod) {
1005  947    ttyLocker ttyl;  // keep the following output all in one block
1006  948    if (xtty != NULL) {
1007  949      xtty->begin_head("print_nmethod");
1008  950      xtty->stamp();
↓ open down ↓ 293 lines elided ↑ open up ↑
1302 1244          xtty->begin_elem("make_not_entrant thread='" UINTX_FORMAT "'%s",
1303 1245                           os::current_thread_id(),
1304 1246                           (_state == zombie ? " zombie='1'" : ""));
1305 1247        }
1306 1248        log_identity(xtty);
1307 1249        xtty->stamp();
1308 1250        xtty->end_elem();
1309 1251      }
1310 1252    }
1311 1253    if (PrintCompilation && _state != unloaded) {
1312      -    print_on(tty, _state == zombie ? "made zombie " : "made not entrant ");
1313      -    tty->cr();
     1254 +    print_on(tty, _state == zombie ? "made zombie" : "made not entrant");
1314 1255    }
1315 1256  }
1316 1257  
1317 1258  // Common functionality for both make_not_entrant and make_zombie
1318 1259  bool nmethod::make_not_entrant_or_zombie(unsigned int state) {
1319 1260    assert(state == zombie || state == not_entrant, "must be zombie or not_entrant");
1320 1261    assert(!is_zombie(), "should not already be a zombie");
1321 1262  
1322 1263    // Make sure neither the nmethod nor the method is flushed in case of a safepoint in code below.
1323 1264    nmethodLocker nml(this);
↓ open down ↓ 485 lines elided ↑ open up ↑
1809 1750        nmethod* observed_mark_nmethods = _oops_do_mark_nmethods;
1810 1751        for (;;) {
1811 1752          nmethod* required_mark_nmethods = observed_mark_nmethods;
1812 1753          _oops_do_mark_link = required_mark_nmethods;
1813 1754          observed_mark_nmethods = (nmethod*)
1814 1755            Atomic::cmpxchg_ptr(this, &_oops_do_mark_nmethods, required_mark_nmethods);
1815 1756          if (observed_mark_nmethods == required_mark_nmethods)
1816 1757            break;
1817 1758        }
1818 1759        // Mark was clear when we first saw this guy.
1819      -      NOT_PRODUCT(if (TraceScavenge)  print_on(tty, "oops_do, mark\n"));
     1760 +      NOT_PRODUCT(if (TraceScavenge)  print_on(tty, "oops_do, mark"));
1820 1761        return false;
1821 1762      }
1822 1763    }
1823 1764    // On fall through, another racing thread marked this nmethod before we did.
1824 1765    return true;
1825 1766  }
1826 1767  
1827 1768  void nmethod::oops_do_marking_prologue() {
1828 1769    NOT_PRODUCT(if (TraceScavenge)  tty->print_cr("[oops_do_marking_prologue"));
1829 1770    assert(_oops_do_mark_nmethods == NULL, "must not call oops_do_marking_prologue twice in a row");
↓ open down ↓ 4 lines elided ↑ open up ↑
1834 1775  }
1835 1776  
1836 1777  void nmethod::oops_do_marking_epilogue() {
1837 1778    assert(_oops_do_mark_nmethods != NULL, "must not call oops_do_marking_epilogue twice in a row");
1838 1779    nmethod* cur = _oops_do_mark_nmethods;
1839 1780    while (cur != NMETHOD_SENTINEL) {
1840 1781      assert(cur != NULL, "not NULL-terminated");
1841 1782      nmethod* next = cur->_oops_do_mark_link;
1842 1783      cur->_oops_do_mark_link = NULL;
1843 1784      cur->fix_oop_relocations();
1844      -    NOT_PRODUCT(if (TraceScavenge)  cur->print_on(tty, "oops_do, unmark\n"));
     1785 +    NOT_PRODUCT(if (TraceScavenge)  cur->print_on(tty, "oops_do, unmark"));
1845 1786      cur = next;
1846 1787    }
1847 1788    void* required = _oops_do_mark_nmethods;
1848 1789    void* observed = Atomic::cmpxchg_ptr(NULL, &_oops_do_mark_nmethods, required);
1849 1790    guarantee(observed == required, "no races in this sequential code");
1850 1791    NOT_PRODUCT(if (TraceScavenge)  tty->print_cr("oops_do_marking_epilogue]"));
1851 1792  }
1852 1793  
1853 1794  class DetectScavengeRoot: public OopClosure {
1854 1795    bool     _detected_scavenge_root;
↓ open down ↓ 534 lines elided ↑ open up ↑
2389 2330  }
2390 2331  
2391 2332  #endif // PRODUCT
2392 2333  
2393 2334  // Printing operations
2394 2335  
2395 2336  void nmethod::print() const {
2396 2337    ResourceMark rm;
2397 2338    ttyLocker ttyl;   // keep the following output all in one block
2398 2339  
2399      -  tty->print("Compiled ");
     2340 +  tty->print("Compiled method ");
2400 2341  
2401 2342    if (is_compiled_by_c1()) {
2402 2343      tty->print("(c1) ");
2403 2344    } else if (is_compiled_by_c2()) {
2404 2345      tty->print("(c2) ");
2405 2346    } else if (is_compiled_by_shark()) {
2406 2347      tty->print("(shark) ");
2407 2348    } else {
2408 2349      tty->print("(nm) ");
2409 2350    }
2410 2351  
2411      -  print_on(tty, "nmethod");
2412      -  tty->cr();
     2352 +  print_on(tty, NULL);
     2353 +
2413 2354    if (WizardMode) {
2414 2355      tty->print("((nmethod*) "INTPTR_FORMAT ") ", this);
2415 2356      tty->print(" for method " INTPTR_FORMAT , (address)method());
2416 2357      tty->print(" { ");
2417 2358      if (is_in_use())      tty->print("in_use ");
2418 2359      if (is_not_entrant()) tty->print("not_entrant ");
2419 2360      if (is_zombie())      tty->print("zombie ");
2420 2361      if (is_unloaded())    tty->print("unloaded ");
2421 2362      if (on_scavenge_root_list())  tty->print("scavenge_root ");
2422 2363      tty->print_cr("}:");
↓ open down ↓ 366 lines elided ↑ open up ↑
2789 2730    if (cont_offset != 0) {
2790 2731      st->move_to(column);
2791 2732      st->print("; implicit exception: dispatches to " INTPTR_FORMAT, code_begin() + cont_offset);
2792 2733    }
2793 2734  
2794 2735  }
2795 2736  
2796 2737  #ifndef PRODUCT
2797 2738  
2798 2739  void nmethod::print_value_on(outputStream* st) const {
2799      -  print_on(st, "nmethod");
     2740 +  st->print("nmethod");
     2741 +  print_on(st, NULL);
2800 2742  }
2801 2743  
2802 2744  void nmethod::print_calls(outputStream* st) {
2803 2745    RelocIterator iter(this);
2804 2746    while (iter.next()) {
2805 2747      switch (iter.type()) {
2806 2748      case relocInfo::virtual_call_type:
2807 2749      case relocInfo::opt_virtual_call_type: {
2808 2750        VerifyMutexLocker mc(CompiledIC_lock);
2809 2751        CompiledIC_at(iter.reloc())->print();
↓ open down ↓ 30 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX