hotspot/src/share/vm/runtime/memprofiler.cpp
author phh
Wed, 28 Oct 2009 16:25:51 -0400
changeset 4434 4b41e5b42f81
parent 2105 347008ce7984
child 5403 6b0dd9c75dde
permissions -rw-r--r--
6887571: Increase default heap config sizes Summary: Apply modification of existing server heap size ergo to all collectors except CMS. Reviewed-by: jmasa, ysr, xlu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
2105
347008ce7984 6814575: Update copyright year
xdono
parents: 1889
diff changeset
     2
 * Copyright 1998-2009 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_memprofiler.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// --------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// MemProfilerTask
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
class MemProfilerTask : public PeriodicTask {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  MemProfilerTask(int interval_time) : PeriodicTask(interval_time) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  void task();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
void MemProfilerTask::task() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  // Get thread lock to provide mutual exclusion, and so we can iterate safely over the thread list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  MutexLocker mu(Threads_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  MemProfiler::do_trace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//----------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// Implementation of MemProfiler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
MemProfilerTask* MemProfiler::_task   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
FILE*            MemProfiler::_log_fp = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
bool MemProfiler::is_active() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  return _task != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
void MemProfiler::engage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  const char *log_name = "mprofile.log";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  if (!is_active()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    // Create log file
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    _log_fp = fopen(log_name , "w+");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    if (_log_fp == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      fatal1("MemProfiler: Cannot create log file: %s", log_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    fprintf(_log_fp, "MemProfiler: sizes are in Kb, time is in seconds since startup\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    fprintf(_log_fp, "  time, #thr, #cls,  heap,  heap,  perm,  perm,  code, hndls, rescs, oopmp\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    fprintf(_log_fp, "                     used, total,  used, total, total, total, total, total\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    fprintf(_log_fp, "--------------------------------------------------------------------------\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    _task = new MemProfilerTask(MemProfilingInterval);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    _task->enroll();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
void MemProfiler::disengage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  if (!is_active()) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // Do one last trace at disengage time
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  do_trace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // Close logfile
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  fprintf(_log_fp, "MemProfiler detached\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  fclose(_log_fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // remove MemProfilerTask
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  assert(_task != NULL, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  _task->disenroll();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  delete _task;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  _task = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
void MemProfiler::do_trace() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // Calculate thread local sizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  size_t handles_memory_usage    = VMThread::vm_thread()->handle_area()->size_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  size_t resource_memory_usage   = VMThread::vm_thread()->resource_area()->size_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  JavaThread *cur = Threads::first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  while (cur != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    handles_memory_usage  += cur->handle_area()->size_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    resource_memory_usage += cur->resource_area()->size_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    cur = cur->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // Print trace line in log
1889
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   107
  fprintf(_log_fp, "%6.1f,%5d,%5d," UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ","
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   108
          UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",",
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   109
          os::elapsedTime(),
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   110
          Threads::number_of_threads(),
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   111
          SystemDictionary::number_of_classes(),
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   112
          Universe::heap()->used() / K,
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   113
          Universe::heap()->capacity() / K,
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   114
          Universe::heap()->permanent_used() / HWperKB,
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   115
          Universe::heap()->permanent_capacity() / HWperKB);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
1889
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   117
  fprintf(_log_fp, UINTX_FORMAT_W(6) ",", CodeCache::capacity() / K);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
1889
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   119
  fprintf(_log_fp, UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",%6ld\n",
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   120
          handles_memory_usage / K,
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   121
          resource_memory_usage / K,
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   122
          OopMapCache::memory_usage() / K);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  fflush(_log_fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
#endif