src/share/vm/runtime/perfMemory.cpp

Fri, 11 Apr 2014 12:29:24 +0200

author
pliden
date
Fri, 11 Apr 2014 12:29:24 +0200
changeset 6906
581e70386ec9
parent 6680
78bbf4d43a14
child 6876
710a3c8b516e
child 6911
ce8f6bb717c9
permissions
-rw-r--r--

8039147: Cleanup SuspendibleThreadSet
Reviewed-by: brutisso, tschatzl, mgerdin

duke@435 1 /*
hseigel@6227 2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "memory/allocation.inline.hpp"
stefank@2314 27 #include "runtime/arguments.hpp"
stefank@2314 28 #include "runtime/java.hpp"
stefank@2314 29 #include "runtime/mutex.hpp"
stefank@2314 30 #include "runtime/mutexLocker.hpp"
stefank@2314 31 #include "runtime/os.hpp"
stefank@2314 32 #include "runtime/perfData.hpp"
stefank@2314 33 #include "runtime/perfMemory.hpp"
stefank@2314 34 #include "runtime/statSampler.hpp"
stefank@2314 35 #include "utilities/globalDefinitions.hpp"
duke@435 36
drchase@6680 37 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
drchase@6680 38
kvn@869 39 // Prefix of performance data file.
kvn@869 40 const char PERFDATA_NAME[] = "hsperfdata";
kvn@869 41
kvn@869 42 // Add 1 for the '_' character between PERFDATA_NAME and pid. The '\0' terminating
kvn@869 43 // character will be included in the sizeof(PERFDATA_NAME) operation.
kvn@869 44 static const size_t PERFDATA_FILENAME_LEN = sizeof(PERFDATA_NAME) +
kvn@869 45 UINT_CHARS + 1;
kvn@869 46
duke@435 47 char* PerfMemory::_start = NULL;
duke@435 48 char* PerfMemory::_end = NULL;
duke@435 49 char* PerfMemory::_top = NULL;
duke@435 50 size_t PerfMemory::_capacity = 0;
duke@435 51 jint PerfMemory::_initialized = false;
duke@435 52 PerfDataPrologue* PerfMemory::_prologue = NULL;
duke@435 53
duke@435 54 void perfMemory_init() {
duke@435 55
duke@435 56 if (!UsePerfData) return;
duke@435 57
duke@435 58 PerfMemory::initialize();
duke@435 59 }
duke@435 60
duke@435 61 void perfMemory_exit() {
duke@435 62
duke@435 63 if (!UsePerfData) return;
duke@435 64 if (!PerfMemory::is_initialized()) return;
duke@435 65
duke@435 66 // if the StatSampler is active, then we don't want to remove
duke@435 67 // resources it may be dependent on. Typically, the StatSampler
duke@435 68 // is disengaged from the watcher thread when this method is called,
duke@435 69 // but it is not disengaged if this method is invoked during a
duke@435 70 // VM abort.
duke@435 71 //
duke@435 72 if (!StatSampler::is_active())
duke@435 73 PerfDataManager::destroy();
duke@435 74
duke@435 75 // remove the persistent external resources, if any. this method
duke@435 76 // does not unmap or invalidate any virtual memory allocated during
duke@435 77 // initialization.
duke@435 78 //
duke@435 79 PerfMemory::destroy();
duke@435 80 }
duke@435 81
duke@435 82 void PerfMemory::initialize() {
duke@435 83
duke@435 84 if (_prologue != NULL)
duke@435 85 // initialization already performed
duke@435 86 return;
duke@435 87
duke@435 88 size_t capacity = align_size_up(PerfDataMemorySize,
duke@435 89 os::vm_allocation_granularity());
duke@435 90
duke@435 91 if (PerfTraceMemOps) {
duke@435 92 tty->print("PerfDataMemorySize = " SIZE_FORMAT ","
duke@435 93 " os::vm_allocation_granularity = " SIZE_FORMAT ","
duke@435 94 " adjusted size = " SIZE_FORMAT "\n",
duke@435 95 PerfDataMemorySize,
duke@435 96 os::vm_allocation_granularity(),
duke@435 97 capacity);
duke@435 98 }
duke@435 99
duke@435 100 // allocate PerfData memory region
duke@435 101 create_memory_region(capacity);
duke@435 102
duke@435 103 if (_start == NULL) {
duke@435 104
duke@435 105 // the PerfMemory region could not be created as desired. Rather
duke@435 106 // than terminating the JVM, we revert to creating the instrumentation
duke@435 107 // on the C heap. When running in this mode, external monitoring
duke@435 108 // clients cannot attach to and monitor this JVM.
duke@435 109 //
duke@435 110 // the warning is issued only in debug mode in order to avoid
duke@435 111 // additional output to the stdout or stderr output streams.
duke@435 112 //
duke@435 113 if (PrintMiscellaneous && Verbose) {
duke@435 114 warning("Could not create PerfData Memory region, reverting to malloc");
duke@435 115 }
duke@435 116
zgu@3900 117 _prologue = NEW_C_HEAP_OBJ(PerfDataPrologue, mtInternal);
duke@435 118 }
duke@435 119 else {
duke@435 120
duke@435 121 // the PerfMemory region was created as expected.
duke@435 122
duke@435 123 if (PerfTraceMemOps) {
duke@435 124 tty->print("PerfMemory created: address = " INTPTR_FORMAT ","
duke@435 125 " size = " SIZE_FORMAT "\n",
duke@435 126 (void*)_start,
duke@435 127 _capacity);
duke@435 128 }
duke@435 129
duke@435 130 _prologue = (PerfDataPrologue *)_start;
duke@435 131 _end = _start + _capacity;
duke@435 132 _top = _start + sizeof(PerfDataPrologue);
duke@435 133 }
duke@435 134
duke@435 135 assert(_prologue != NULL, "prologue pointer must be initialized");
duke@435 136
duke@435 137 #ifdef VM_LITTLE_ENDIAN
duke@435 138 _prologue->magic = (jint)0xc0c0feca;
duke@435 139 _prologue->byte_order = PERFDATA_LITTLE_ENDIAN;
duke@435 140 #else
duke@435 141 _prologue->magic = (jint)0xcafec0c0;
duke@435 142 _prologue->byte_order = PERFDATA_BIG_ENDIAN;
duke@435 143 #endif
duke@435 144
duke@435 145 _prologue->major_version = PERFDATA_MAJOR_VERSION;
duke@435 146 _prologue->minor_version = PERFDATA_MINOR_VERSION;
duke@435 147 _prologue->accessible = 0;
duke@435 148
duke@435 149 _prologue->entry_offset = sizeof(PerfDataPrologue);
duke@435 150 _prologue->num_entries = 0;
duke@435 151 _prologue->used = 0;
duke@435 152 _prologue->overflow = 0;
duke@435 153 _prologue->mod_time_stamp = 0;
duke@435 154
duke@435 155 OrderAccess::release_store(&_initialized, 1);
duke@435 156 }
duke@435 157
duke@435 158 void PerfMemory::destroy() {
duke@435 159
hseigel@6227 160 if (_prologue == NULL) return;
duke@435 161
duke@435 162 if (_start != NULL && _prologue->overflow != 0) {
duke@435 163
duke@435 164 // This state indicates that the contiguous memory region exists and
duke@435 165 // that it wasn't large enough to hold all the counters. In this case,
duke@435 166 // we output a warning message to the user on exit if the -XX:+Verbose
duke@435 167 // flag is set (a debug only flag). External monitoring tools can detect
duke@435 168 // this condition by monitoring the _prologue->overflow word.
duke@435 169 //
duke@435 170 // There are two tunables that can help resolve this issue:
duke@435 171 // - increase the size of the PerfMemory with -XX:PerfDataMemorySize=<n>
duke@435 172 // - decrease the maximum string constant length with
duke@435 173 // -XX:PerfMaxStringConstLength=<n>
duke@435 174 //
duke@435 175 if (PrintMiscellaneous && Verbose) {
duke@435 176 warning("PerfMemory Overflow Occurred.\n"
duke@435 177 "\tCapacity = " SIZE_FORMAT " bytes"
duke@435 178 " Used = " SIZE_FORMAT " bytes"
duke@435 179 " Overflow = " INT32_FORMAT " bytes"
duke@435 180 "\n\tUse -XX:PerfDataMemorySize=<size> to specify larger size.",
duke@435 181 PerfMemory::capacity(),
duke@435 182 PerfMemory::used(),
duke@435 183 _prologue->overflow);
duke@435 184 }
duke@435 185 }
duke@435 186
duke@435 187 if (_start != NULL) {
duke@435 188
duke@435 189 // this state indicates that the contiguous memory region was successfully
duke@435 190 // and that persistent resources may need to be cleaned up. This is
duke@435 191 // expected to be the typical condition.
duke@435 192 //
duke@435 193 delete_memory_region();
duke@435 194 }
duke@435 195
duke@435 196 _start = NULL;
duke@435 197 _end = NULL;
duke@435 198 _top = NULL;
duke@435 199 _prologue = NULL;
duke@435 200 _capacity = 0;
duke@435 201 }
duke@435 202
duke@435 203 // allocate an aligned block of memory from the PerfData memory
duke@435 204 // region. This method assumes that the PerfData memory region
duke@435 205 // was aligned on a double word boundary when created.
duke@435 206 //
duke@435 207 char* PerfMemory::alloc(size_t size) {
duke@435 208
duke@435 209 if (!UsePerfData) return NULL;
duke@435 210
duke@435 211 MutexLocker ml(PerfDataMemAlloc_lock);
duke@435 212
duke@435 213 assert(_prologue != NULL, "called before initialization");
duke@435 214
duke@435 215 // check that there is enough memory for this request
duke@435 216 if ((_top + size) >= _end) {
duke@435 217
duke@435 218 _prologue->overflow += (jint)size;
duke@435 219
duke@435 220 return NULL;
duke@435 221 }
duke@435 222
duke@435 223 char* result = _top;
duke@435 224
duke@435 225 _top += size;
duke@435 226
duke@435 227 assert(contains(result), "PerfData memory pointer out of range");
duke@435 228
duke@435 229 _prologue->used = (jint)used();
duke@435 230 _prologue->num_entries = _prologue->num_entries + 1;
duke@435 231
duke@435 232 return result;
duke@435 233 }
duke@435 234
duke@435 235 void PerfMemory::mark_updated() {
duke@435 236 if (!UsePerfData) return;
duke@435 237
duke@435 238 _prologue->mod_time_stamp = os::elapsed_counter();
duke@435 239 }
duke@435 240
duke@435 241 // Returns the complete path including the file name of performance data file.
duke@435 242 // Caller is expected to release the allocated memory.
duke@435 243 char* PerfMemory::get_perfdata_file_path() {
duke@435 244 char* dest_file = NULL;
duke@435 245
duke@435 246 if (PerfDataSaveFile != NULL) {
duke@435 247 // dest_file_name stores the validated file name if file_name
duke@435 248 // contains %p which will be replaced by pid.
zgu@3900 249 dest_file = NEW_C_HEAP_ARRAY(char, JVM_MAXPATHLEN, mtInternal);
duke@435 250 if(!Arguments::copy_expand_pid(PerfDataSaveFile, strlen(PerfDataSaveFile),
duke@435 251 dest_file, JVM_MAXPATHLEN)) {
zgu@3900 252 FREE_C_HEAP_ARRAY(char, dest_file, mtInternal);
duke@435 253 if (PrintMiscellaneous && Verbose) {
duke@435 254 warning("Invalid performance data file path name specified, "\
duke@435 255 "fall back to a default name");
duke@435 256 }
duke@435 257 } else {
duke@435 258 return dest_file;
duke@435 259 }
duke@435 260 }
duke@435 261 // create the name of the file for retaining the instrumentation memory.
zgu@3900 262 dest_file = NEW_C_HEAP_ARRAY(char, PERFDATA_FILENAME_LEN, mtInternal);
duke@435 263 jio_snprintf(dest_file, PERFDATA_FILENAME_LEN,
duke@435 264 "%s_%d", PERFDATA_NAME, os::current_process_id());
duke@435 265
duke@435 266 return dest_file;
duke@435 267 }

mercurial