< prev index next >

src/hotspot/share/runtime/memprofiler.cpp

Print this page
rev 47862 : imported patch 10.07.open.rebase_20171110.dcubed
rev 47866 : robinw CR: Fix some inefficient code, update some comments, fix some indents, and add some 'const' specifiers.


  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 "classfile/systemDictionary.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "gc/shared/collectedHeap.inline.hpp"
  29 #include "gc/shared/generation.hpp"
  30 #include "interpreter/oopMapCache.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "runtime/handles.inline.hpp"
  33 #include "runtime/jniHandles.hpp"
  34 #include "runtime/memprofiler.hpp"
  35 #include "runtime/mutexLocker.hpp"
  36 #include "runtime/os.hpp"
  37 #include "runtime/task.hpp"
  38 #include "runtime/thread.inline.hpp"

  39 #include "runtime/vmThread.hpp"
  40 
  41 #ifndef PRODUCT
  42 
  43 // --------------------------------------------------------
  44 // MemProfilerTask
  45 
  46 class MemProfilerTask : public PeriodicTask {
  47  public:
  48   MemProfilerTask(int interval_time) : PeriodicTask(interval_time) {}
  49   void task();
  50 };
  51 
  52 
  53 void MemProfilerTask::task() {
  54   // Get thread lock to provide mutual exclusion, and so we can iterate safely over the thread list.
  55   MutexLocker mu(Threads_lock);
  56   MemProfiler::do_trace();
  57 }
  58 
  59 
  60 //----------------------------------------------------------
  61 // Implementation of MemProfiler
  62 
  63 MemProfilerTask* MemProfiler::_task   = NULL;
  64 FILE*            MemProfiler::_log_fp = NULL;
  65 
  66 
  67 bool MemProfiler::is_active() {
  68   return _task != NULL;
  69 }
  70 
  71 
  72 void MemProfiler::engage() {
  73   const char *log_name = "mprofile.log";
  74   if (!is_active()) {
  75     // Create log file


  92   if (!is_active()) return;
  93   // Do one last trace at disengage time
  94   do_trace();
  95 
  96   // Close logfile
  97   fprintf(_log_fp, "MemProfiler detached\n");
  98   fclose(_log_fp);
  99 
 100   // remove MemProfilerTask
 101   assert(_task != NULL, "sanity check");
 102   _task->disenroll();
 103   delete _task;
 104   _task = NULL;
 105 }
 106 
 107 
 108 void MemProfiler::do_trace() {
 109   // Calculate thread local sizes
 110   size_t handles_memory_usage    = VMThread::vm_thread()->handle_area()->size_in_bytes();
 111   size_t resource_memory_usage   = VMThread::vm_thread()->resource_area()->size_in_bytes();
 112   JavaThread *cur = Threads::first();
 113   while (cur != NULL) {

 114     handles_memory_usage  += cur->handle_area()->size_in_bytes();
 115     resource_memory_usage += cur->resource_area()->size_in_bytes();
 116     cur = cur->next();
 117   }
 118 
 119   // Print trace line in log
 120   fprintf(_log_fp, "%6.1f,%5d,%5d," UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",",
 121           os::elapsedTime(),
 122           Threads::number_of_threads(),
 123           InstanceKlass::number_of_instance_classes(),
 124           Universe::heap()->used() / K,
 125           Universe::heap()->capacity() / K);

 126 
 127   fprintf(_log_fp, UINTX_FORMAT_W(6) ",", CodeCache::capacity() / K);
 128 
 129   fprintf(_log_fp, UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",%6ld\n",
 130           handles_memory_usage / K,
 131           resource_memory_usage / K,
 132           0L);
 133   fflush(_log_fp);
 134 }
 135 
 136 #endif


  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 "classfile/systemDictionary.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "gc/shared/collectedHeap.inline.hpp"
  29 #include "gc/shared/generation.hpp"
  30 #include "interpreter/oopMapCache.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "runtime/handles.inline.hpp"
  33 #include "runtime/jniHandles.hpp"
  34 #include "runtime/memprofiler.hpp"
  35 #include "runtime/mutexLocker.hpp"
  36 #include "runtime/os.hpp"
  37 #include "runtime/task.hpp"
  38 #include "runtime/thread.inline.hpp"
  39 #include "runtime/threadSMR.hpp"
  40 #include "runtime/vmThread.hpp"
  41 
  42 #ifndef PRODUCT
  43 
  44 // --------------------------------------------------------
  45 // MemProfilerTask
  46 
  47 class MemProfilerTask : public PeriodicTask {
  48  public:
  49   MemProfilerTask(int interval_time) : PeriodicTask(interval_time) {}
  50   void task();
  51 };
  52 
  53 
  54 void MemProfilerTask::task() {


  55   MemProfiler::do_trace();
  56 }
  57 
  58 
  59 //----------------------------------------------------------
  60 // Implementation of MemProfiler
  61 
  62 MemProfilerTask* MemProfiler::_task   = NULL;
  63 FILE*            MemProfiler::_log_fp = NULL;
  64 
  65 
  66 bool MemProfiler::is_active() {
  67   return _task != NULL;
  68 }
  69 
  70 
  71 void MemProfiler::engage() {
  72   const char *log_name = "mprofile.log";
  73   if (!is_active()) {
  74     // Create log file


  91   if (!is_active()) return;
  92   // Do one last trace at disengage time
  93   do_trace();
  94 
  95   // Close logfile
  96   fprintf(_log_fp, "MemProfiler detached\n");
  97   fclose(_log_fp);
  98 
  99   // remove MemProfilerTask
 100   assert(_task != NULL, "sanity check");
 101   _task->disenroll();
 102   delete _task;
 103   _task = NULL;
 104 }
 105 
 106 
 107 void MemProfiler::do_trace() {
 108   // Calculate thread local sizes
 109   size_t handles_memory_usage    = VMThread::vm_thread()->handle_area()->size_in_bytes();
 110   size_t resource_memory_usage   = VMThread::vm_thread()->resource_area()->size_in_bytes();
 111   {
 112     JavaThreadIteratorWithHandle jtiwh;
 113     for (; JavaThread *cur = jtiwh.next(); ) {
 114       handles_memory_usage  += cur->handle_area()->size_in_bytes();
 115       resource_memory_usage += cur->resource_area()->size_in_bytes();

 116     }
 117 
 118     // Print trace line in log
 119     fprintf(_log_fp, "%6.1f,%5d,%5d," UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",",
 120             os::elapsedTime(),
 121             jtiwh.length(),
 122             InstanceKlass::number_of_instance_classes(),
 123             Universe::heap()->used() / K,
 124             Universe::heap()->capacity() / K);
 125   }
 126 
 127   fprintf(_log_fp, UINTX_FORMAT_W(6) ",", CodeCache::capacity() / K);
 128 
 129   fprintf(_log_fp, UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",%6ld\n",
 130           handles_memory_usage / K,
 131           resource_memory_usage / K,
 132           0L);
 133   fflush(_log_fp);
 134 }
 135 
 136 #endif
< prev index next >