src/hotspot/share/compiler/compileBroker.cpp
changeset 49611 973c9504178e
parent 49594 898ef81cbc0e
child 49618 c5b066caefba
equal deleted inserted replaced
49610:6790b1077a3f 49611:973c9504178e
    26 #include "jvm.h"
    26 #include "jvm.h"
    27 #include "classfile/symbolTable.hpp"
    27 #include "classfile/symbolTable.hpp"
    28 #include "classfile/systemDictionary.hpp"
    28 #include "classfile/systemDictionary.hpp"
    29 #include "classfile/vmSymbols.hpp"
    29 #include "classfile/vmSymbols.hpp"
    30 #include "code/codeCache.hpp"
    30 #include "code/codeCache.hpp"
       
    31 #include "code/codeHeapState.hpp"
    31 #include "code/dependencyContext.hpp"
    32 #include "code/dependencyContext.hpp"
    32 #include "compiler/compileBroker.hpp"
    33 #include "compiler/compileBroker.hpp"
    33 #include "compiler/compileLog.hpp"
    34 #include "compiler/compileLog.hpp"
    34 #include "compiler/compilerOracle.hpp"
    35 #include "compiler/compilerOracle.hpp"
    35 #include "compiler/directivesParser.hpp"
    36 #include "compiler/directivesParser.hpp"
  2422       tty->print_cr("Last parse:  %d+++(%d) %s",
  2423       tty->print_cr("Last parse:  %d+++(%d) %s",
  2423                     _compilation_id, _last_compile_level, _last_method_compiled);
  2424                     _compilation_id, _last_compile_level, _last_method_compiled);
  2424     }
  2425     }
  2425   }
  2426   }
  2426 }
  2427 }
       
  2428 
       
  2429 // Print general/accumulated JIT information.
       
  2430 void CompileBroker::print_info(outputStream *out) {
       
  2431   if (out == NULL) out = tty;
       
  2432   out->cr();
       
  2433   out->print_cr("======================");
       
  2434   out->print_cr("   General JIT info   ");
       
  2435   out->print_cr("======================");
       
  2436   out->cr();
       
  2437   out->print_cr("            JIT is : %7s",     should_compile_new_jobs() ? "on" : "off");
       
  2438   out->print_cr("  Compiler threads : %7d",     (int)CICompilerCount);
       
  2439   out->cr();
       
  2440   out->print_cr("CodeCache overview");
       
  2441   out->print_cr("--------------------------------------------------------");
       
  2442   out->cr();
       
  2443   out->print_cr("         Reserved size : " SIZE_FORMAT_W(7) " KB", CodeCache::max_capacity() / K);
       
  2444   out->print_cr("        Committed size : " SIZE_FORMAT_W(7) " KB", CodeCache::capacity() / K);
       
  2445   out->print_cr("  Unallocated capacity : " SIZE_FORMAT_W(7) " KB", CodeCache::unallocated_capacity() / K);
       
  2446   out->cr();
       
  2447 
       
  2448   out->cr();
       
  2449   out->print_cr("CodeCache cleaning overview");
       
  2450   out->print_cr("--------------------------------------------------------");
       
  2451   out->cr();
       
  2452   NMethodSweeper::print(out);
       
  2453   out->print_cr("--------------------------------------------------------");
       
  2454   out->cr();
       
  2455 }
       
  2456 
       
  2457 // Note: tty_lock must not be held upon entry to this function.
       
  2458 //       Print functions called from herein do "micro-locking" on tty_lock.
       
  2459 //       That's a tradeoff which keeps together important blocks of output.
       
  2460 //       At the same time, continuous tty_lock hold time is kept in check,
       
  2461 //       preventing concurrently printing threads from stalling a long time.
       
  2462 void CompileBroker::print_heapinfo(outputStream* out, const char* function, const char* granularity) {
       
  2463   TimeStamp ts_total;
       
  2464   TimeStamp ts;
       
  2465 
       
  2466   bool allFun = !strcmp(function, "all");
       
  2467   bool aggregate = !strcmp(function, "aggregate") || !strcmp(function, "analyze") || allFun;
       
  2468   bool usedSpace = !strcmp(function, "UsedSpace") || allFun;
       
  2469   bool freeSpace = !strcmp(function, "FreeSpace") || allFun;
       
  2470   bool methodCount = !strcmp(function, "MethodCount") || allFun;
       
  2471   bool methodSpace = !strcmp(function, "MethodSpace") || allFun;
       
  2472   bool methodAge = !strcmp(function, "MethodAge") || allFun;
       
  2473   bool methodNames = !strcmp(function, "MethodNames") || allFun;
       
  2474   bool discard = !strcmp(function, "discard") || allFun;
       
  2475 
       
  2476   if (out == NULL) {
       
  2477     out = tty;
       
  2478   }
       
  2479 
       
  2480   if (!(aggregate || usedSpace || freeSpace || methodCount || methodSpace || methodAge || methodNames || discard)) {
       
  2481     out->print_cr("\n__ CodeHeapStateAnalytics: Function %s is not supported", function);
       
  2482     out->cr();
       
  2483     return;
       
  2484   }
       
  2485 
       
  2486   ts_total.update(); // record starting point
       
  2487 
       
  2488   if (aggregate) {
       
  2489     print_info(out);
       
  2490   }
       
  2491 
       
  2492   // We hold the CodeHeapStateAnalytics_lock all the time, from here until we leave this function.
       
  2493   // That helps us getting a consistent view on the CodeHeap, at least for the "all" function.
       
  2494   // When we request individual parts of the analysis via the jcmd interface, it is possible
       
  2495   // that in between another thread (another jcmd user or the vm running into CodeCache OOM)
       
  2496   // updated the aggregated data. That's a tolerable tradeoff because we can't hold a lock
       
  2497   // across user interaction.
       
  2498   ts.update(); // record starting point
       
  2499   MutexLockerEx mu1(CodeHeapStateAnalytics_lock, Mutex::_no_safepoint_check_flag);
       
  2500   out->cr();
       
  2501   out->print_cr("__ CodeHeapStateAnalytics lock wait took %10.3f seconds _________", ts.seconds());
       
  2502   out->cr();
       
  2503 
       
  2504   if (aggregate) {
       
  2505     // It is sufficient to hold the CodeCache_lock only for the aggregate step.
       
  2506     // All other functions operate on aggregated data - except MethodNames, but that should be safe.
       
  2507     // The separate CodeHeapStateAnalytics_lock protects the printing functions against
       
  2508     // concurrent aggregate steps. Acquire this lock before acquiring the CodeCache_lock.
       
  2509     // CodeHeapStateAnalytics_lock could be held by a concurrent thread for a long time,
       
  2510     // leading to an unnecessarily long hold time of the CodeCache_lock.
       
  2511     ts.update(); // record starting point
       
  2512     MutexLockerEx mu2(CodeCache_lock, Mutex::_no_safepoint_check_flag);
       
  2513     out->cr();
       
  2514     out->print_cr("__ CodeCache lock wait took %10.3f seconds _________", ts.seconds());
       
  2515     out->cr();
       
  2516 
       
  2517     ts.update(); // record starting point
       
  2518     CodeCache::aggregate(out, granularity);
       
  2519     out->cr();
       
  2520     out->print_cr("__ CodeCache lock hold took %10.3f seconds _________", ts.seconds());
       
  2521     out->cr();
       
  2522   }
       
  2523 
       
  2524   if (usedSpace) CodeCache::print_usedSpace(out);
       
  2525   if (freeSpace) CodeCache::print_freeSpace(out);
       
  2526   if (methodCount) CodeCache::print_count(out);
       
  2527   if (methodSpace) CodeCache::print_space(out);
       
  2528   if (methodAge) CodeCache::print_age(out);
       
  2529   if (methodNames) CodeCache::print_names(out);
       
  2530   if (discard) CodeCache::discard(out);
       
  2531 
       
  2532   out->cr();
       
  2533   out->print_cr("__ CodeHeapStateAnalytics total duration %10.3f seconds _________", ts_total.seconds());
       
  2534   out->cr();
       
  2535 }