src/hotspot/share/runtime/perfMemory.cpp
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 46625 hotspot/src/share/vm/runtime/perfMemory.cpp@edefffab74e2
child 47669 e362049c1cb8
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46405
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 33148
diff changeset
     2
 * Copyright (c) 2001, 2017, 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: 1623
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1623
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: 1623
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"
46405
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 33148
diff changeset
    26
#include "logging/log.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/allocation.inline.hpp"
46560
388aa8d67c80 8181449: Fix debug.hpp / globalDefinitions.hpp dependency inversion
kbarrett
parents: 46405
diff changeset
    28
#include "prims/jvm.h"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "runtime/arguments.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "runtime/mutex.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/mutexLocker.hpp"
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 22198
diff changeset
    33
#include "runtime/orderAccess.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "runtime/os.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "runtime/perfData.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#include "runtime/perfMemory.hpp"
32614
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
    37
#include "runtime/safepoint.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    38
#include "runtime/statSampler.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    39
#include "utilities/align.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    40
#include "utilities/globalDefinitions.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
1553
fc10c169d15d 6772413: code cleanup
kvn
parents: 1
diff changeset
    42
// Prefix of performance data file.
fc10c169d15d 6772413: code cleanup
kvn
parents: 1
diff changeset
    43
const char               PERFDATA_NAME[] = "hsperfdata";
fc10c169d15d 6772413: code cleanup
kvn
parents: 1
diff changeset
    44
fc10c169d15d 6772413: code cleanup
kvn
parents: 1
diff changeset
    45
// Add 1 for the '_' character between PERFDATA_NAME and pid. The '\0' terminating
fc10c169d15d 6772413: code cleanup
kvn
parents: 1
diff changeset
    46
// character will be included in the sizeof(PERFDATA_NAME) operation.
fc10c169d15d 6772413: code cleanup
kvn
parents: 1
diff changeset
    47
static const size_t PERFDATA_FILENAME_LEN = sizeof(PERFDATA_NAME) +
fc10c169d15d 6772413: code cleanup
kvn
parents: 1
diff changeset
    48
                                            UINT_CHARS + 1;
fc10c169d15d 6772413: code cleanup
kvn
parents: 1
diff changeset
    49
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
char*                    PerfMemory::_start = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
char*                    PerfMemory::_end = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
char*                    PerfMemory::_top = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
size_t                   PerfMemory::_capacity = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
jint                     PerfMemory::_initialized = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
PerfDataPrologue*        PerfMemory::_prologue = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
void perfMemory_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  if (!UsePerfData) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  PerfMemory::initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
void perfMemory_exit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  if (!UsePerfData) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  if (!PerfMemory::is_initialized()) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
32614
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
    69
  // Only destroy PerfData objects if we're at a safepoint and the
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
    70
  // StatSampler is not active. Otherwise, we risk removing PerfData
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
    71
  // objects that are currently being used by running JavaThreads
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
    72
  // or the StatSampler. This method is invoked while we are not at
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
    73
  // a safepoint during a VM abort so leaving the PerfData objects
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
    74
  // around may also help diagnose the failure. In rare cases,
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
    75
  // PerfData objects are used in parallel with a safepoint. See
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
    76
  // the work around in PerfDataManager::destroy().
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  //
32614
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
    78
  if (SafepointSynchronize::is_at_safepoint() && !StatSampler::is_active()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    PerfDataManager::destroy();
32614
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
    80
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
32614
b7b2407bc7e5 8049304: race between VM_Exit and _sync_FutileWakeups->inc()
dcubed
parents: 27880
diff changeset
    82
  // Remove the persistent external resources, if any. This method
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // does not unmap or invalidate any virtual memory allocated during
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // initialization.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  PerfMemory::destroy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
void PerfMemory::initialize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  if (_prologue != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    // initialization already performed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46560
diff changeset
    95
  size_t capacity = align_up(PerfDataMemorySize,
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46560
diff changeset
    96
                             os::vm_allocation_granularity());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
46405
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 33148
diff changeset
    98
  log_debug(perf, memops)("PerfDataMemorySize = " SIZE_FORMAT ","
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 33148
diff changeset
    99
                          " os::vm_allocation_granularity = %d,"
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 33148
diff changeset
   100
                          " adjusted size = " SIZE_FORMAT "\n",
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 33148
diff changeset
   101
                          PerfDataMemorySize,
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 33148
diff changeset
   102
                          os::vm_allocation_granularity(),
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 33148
diff changeset
   103
                          capacity);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // allocate PerfData memory region
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  create_memory_region(capacity);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  if (_start == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    // the PerfMemory region could not be created as desired. Rather
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    // than terminating the JVM, we revert to creating the instrumentation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    // on the C heap. When running in this mode, external monitoring
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    // clients cannot attach to and monitor this JVM.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    // the warning is issued only in debug mode in order to avoid
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    // additional output to the stdout or stderr output streams.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    if (PrintMiscellaneous && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      warning("Could not create PerfData Memory region, reverting to malloc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   122
    _prologue = NEW_C_HEAP_OBJ(PerfDataPrologue, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    // the PerfMemory region was created as expected.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
46405
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 33148
diff changeset
   128
    log_debug(perf, memops)("PerfMemory created: address = " INTPTR_FORMAT ","
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 33148
diff changeset
   129
                            " size = " SIZE_FORMAT "\n",
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 33148
diff changeset
   130
                            p2i(_start),
17ab5460b2cb 8168122: Update logging in perfMemory to Unified Logging
rprotacio
parents: 33148
diff changeset
   131
                            _capacity);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    _prologue = (PerfDataPrologue *)_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    _end = _start + _capacity;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    _top = _start + sizeof(PerfDataPrologue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  assert(_prologue != NULL, "prologue pointer must be initialized");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
#ifdef VM_LITTLE_ENDIAN
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  _prologue->magic = (jint)0xc0c0feca;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  _prologue->byte_order = PERFDATA_LITTLE_ENDIAN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  _prologue->magic = (jint)0xcafec0c0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  _prologue->byte_order = PERFDATA_BIG_ENDIAN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  _prologue->major_version = PERFDATA_MAJOR_VERSION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  _prologue->minor_version = PERFDATA_MINOR_VERSION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  _prologue->accessible = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  _prologue->entry_offset = sizeof(PerfDataPrologue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  _prologue->num_entries = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  _prologue->used = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  _prologue->overflow = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  _prologue->mod_time_stamp = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  OrderAccess::release_store(&_initialized, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
void PerfMemory::destroy() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
22198
ab9e76f5a36c 8030955: assert(_prologue != NULL) failed: prologue pointer must be initialized
hseigel
parents: 13963
diff changeset
   163
  if (_prologue == NULL) return;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  if (_start != NULL && _prologue->overflow != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    // This state indicates that the contiguous memory region exists and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    // that it wasn't large enough to hold all the counters. In this case,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    // we output a warning message to the user on exit if the -XX:+Verbose
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    // flag is set (a debug only flag). External monitoring tools can detect
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    // this condition by monitoring the _prologue->overflow word.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    // There are two tunables that can help resolve this issue:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    //   - increase the size of the PerfMemory with -XX:PerfDataMemorySize=<n>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    //   - decrease the maximum string constant length with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    //     -XX:PerfMaxStringConstLength=<n>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    if (PrintMiscellaneous && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      warning("PerfMemory Overflow Occurred.\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
              "\tCapacity = " SIZE_FORMAT " bytes"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
              "  Used = " SIZE_FORMAT " bytes"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
              "  Overflow = " INT32_FORMAT " bytes"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
              "\n\tUse -XX:PerfDataMemorySize=<size> to specify larger size.",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
              PerfMemory::capacity(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
              PerfMemory::used(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
              _prologue->overflow);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  if (_start != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    // this state indicates that the contiguous memory region was successfully
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    // and that persistent resources may need to be cleaned up. This is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    // expected to be the typical condition.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    delete_memory_region();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  _start = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  _end = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  _top = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  _prologue = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  _capacity = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
// allocate an aligned block of memory from the PerfData memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
// region. This method assumes that the PerfData memory region
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
// was aligned on a double word boundary when created.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
char* PerfMemory::alloc(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  if (!UsePerfData) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  MutexLocker ml(PerfDataMemAlloc_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  assert(_prologue != NULL, "called before initialization");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  // check that there is enough memory for this request
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  if ((_top + size) >= _end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    _prologue->overflow += (jint)size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  char* result = _top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  _top += size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  assert(contains(result), "PerfData memory pointer out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  _prologue->used = (jint)used();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  _prologue->num_entries = _prologue->num_entries + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
void PerfMemory::mark_updated() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  if (!UsePerfData) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  _prologue->mod_time_stamp = os::elapsed_counter();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
// Returns the complete path including the file name of performance data file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
// Caller is expected to release the allocated memory.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
char* PerfMemory::get_perfdata_file_path() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  char* dest_file = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  if (PerfDataSaveFile != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    // dest_file_name stores the validated file name if file_name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    // contains %p which will be replaced by pid.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   252
    dest_file = NEW_C_HEAP_ARRAY(char, JVM_MAXPATHLEN, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    if(!Arguments::copy_expand_pid(PerfDataSaveFile, strlen(PerfDataSaveFile),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
                                   dest_file, JVM_MAXPATHLEN)) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 24424
diff changeset
   255
      FREE_C_HEAP_ARRAY(char, dest_file);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
      if (PrintMiscellaneous && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
        warning("Invalid performance data file path name specified, "\
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
                "fall back to a default name");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      return dest_file;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // create the name of the file for retaining the instrumentation memory.
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   265
  dest_file = NEW_C_HEAP_ARRAY(char, PERFDATA_FILENAME_LEN, mtInternal);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  jio_snprintf(dest_file, PERFDATA_FILENAME_LEN,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
               "%s_%d", PERFDATA_NAME, os::current_process_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  return dest_file;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
}