src/hotspot/share/runtime/memprofiler.cpp
author stefank
Fri, 04 May 2018 11:41:35 +0200
changeset 49982 9042ffe5b7fe
parent 48884 7e17b00dc245
child 51959 db0c3952de52
permissions -rw-r--r--
8200729: Conditional compilation of GCs Reviewed-by: ehelin, coleenp, kvn, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
48884
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
     2
 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. 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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5403
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5403
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5403
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
48884
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
    26
#include "classfile/classLoaderData.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "code/codeCache.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 14583
diff changeset
    29
#include "gc/shared/collectedHeap.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "interpreter/oopMapCache.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/jniHandles.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "runtime/memprofiler.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "runtime/mutexLocker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "runtime/os.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#include "runtime/task.hpp"
14583
d70ee55535f4 8003935: Simplify the needed includes for using Thread::current()
stefank
parents: 13728
diff changeset
    38
#include "runtime/thread.inline.hpp"
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47216
diff changeset
    39
#include "runtime/threadSMR.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    40
#include "runtime/vmThread.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// --------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// MemProfilerTask
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
class MemProfilerTask : public PeriodicTask {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  MemProfilerTask(int interval_time) : PeriodicTask(interval_time) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  void task();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
void MemProfilerTask::task() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  MemProfiler::do_trace();
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
//----------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
// Implementation of MemProfiler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
MemProfilerTask* MemProfiler::_task   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
FILE*            MemProfiler::_log_fp = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
bool MemProfiler::is_active() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  return _task != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
void MemProfiler::engage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  const char *log_name = "mprofile.log";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  if (!is_active()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    // Create log file
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    _log_fp = fopen(log_name , "w+");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    if (_log_fp == NULL) {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
    77
      fatal("MemProfiler: Cannot create log file: %s", log_name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    fprintf(_log_fp, "MemProfiler: sizes are in Kb, time is in seconds since startup\n\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    fprintf(_log_fp, "  time, #thr, #cls,  heap,  heap,  perm,  perm,  code, hndls, rescs, oopmp\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    fprintf(_log_fp, "                     used, total,  used, total, total, total, total, total\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    fprintf(_log_fp, "--------------------------------------------------------------------------\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    _task = new MemProfilerTask(MemProfilingInterval);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    _task->enroll();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
void MemProfiler::disengage() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  if (!is_active()) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // Do one last trace at disengage time
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  do_trace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // Close logfile
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  fprintf(_log_fp, "MemProfiler detached\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  fclose(_log_fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // remove MemProfilerTask
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  assert(_task != NULL, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  _task->disenroll();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  delete _task;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  _task = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
void MemProfiler::do_trace() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // Calculate thread local sizes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  size_t handles_memory_usage    = VMThread::vm_thread()->handle_area()->size_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  size_t resource_memory_usage   = VMThread::vm_thread()->resource_area()->size_in_bytes();
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47216
diff changeset
   111
  {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47216
diff changeset
   112
    JavaThreadIteratorWithHandle jtiwh;
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47216
diff changeset
   113
    for (; JavaThread *cur = jtiwh.next(); ) {
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47216
diff changeset
   114
      handles_memory_usage  += cur->handle_area()->size_in_bytes();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47216
diff changeset
   115
      resource_memory_usage += cur->resource_area()->size_in_bytes();
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47216
diff changeset
   116
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47216
diff changeset
   118
    // Print trace line in log
48884
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   119
    fprintf(_log_fp, "%6.1f,%5d," SIZE_FORMAT_W(5) "," UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",",
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47216
diff changeset
   120
            os::elapsedTime(),
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47216
diff changeset
   121
            jtiwh.length(),
48884
7e17b00dc245 8196923: [REDO] NMT: Report array class count in NMT summary
zgu
parents: 48874
diff changeset
   122
            ClassLoaderDataGraph::num_instance_classes(),
48105
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47216
diff changeset
   123
            Universe::heap()->used() / K,
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47216
diff changeset
   124
            Universe::heap()->capacity() / K);
8d15b1369c7a 8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents: 47216
diff changeset
   125
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
1889
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   127
  fprintf(_log_fp, UINTX_FORMAT_W(6) ",", CodeCache::capacity() / K);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
1889
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   129
  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
   130
          handles_memory_usage / K,
24b003a6fe46 6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents: 1
diff changeset
   131
          resource_memory_usage / K,
46996
9cbcd7082efe 8186042: Optimize OopMapCache lookup
coleenp
parents: 46729
diff changeset
   132
          0L);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  fflush(_log_fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
#endif