src/share/vm/runtime/perfMemory.cpp

Fri, 28 Mar 2014 10:12:48 -0700

author
vlivanov
date
Fri, 28 Mar 2014 10:12:48 -0700
changeset 6527
f47fa50d9b9c
parent 6227
2604e2767d2c
child 6680
78bbf4d43a14
permissions
-rw-r--r--

8035887: VM crashes trying to force inlining the recursive call
Reviewed-by: kvn, twisti

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
kvn@869 37 // Prefix of performance data file.
kvn@869 38 const char PERFDATA_NAME[] = "hsperfdata";
kvn@869 39
kvn@869 40 // Add 1 for the '_' character between PERFDATA_NAME and pid. The '\0' terminating
kvn@869 41 // character will be included in the sizeof(PERFDATA_NAME) operation.
kvn@869 42 static const size_t PERFDATA_FILENAME_LEN = sizeof(PERFDATA_NAME) +
kvn@869 43 UINT_CHARS + 1;
kvn@869 44
duke@435 45 char* PerfMemory::_start = NULL;
duke@435 46 char* PerfMemory::_end = NULL;
duke@435 47 char* PerfMemory::_top = NULL;
duke@435 48 size_t PerfMemory::_capacity = 0;
duke@435 49 jint PerfMemory::_initialized = false;
duke@435 50 PerfDataPrologue* PerfMemory::_prologue = NULL;
duke@435 51
duke@435 52 void perfMemory_init() {
duke@435 53
duke@435 54 if (!UsePerfData) return;
duke@435 55
duke@435 56 PerfMemory::initialize();
duke@435 57 }
duke@435 58
duke@435 59 void perfMemory_exit() {
duke@435 60
duke@435 61 if (!UsePerfData) return;
duke@435 62 if (!PerfMemory::is_initialized()) return;
duke@435 63
duke@435 64 // if the StatSampler is active, then we don't want to remove
duke@435 65 // resources it may be dependent on. Typically, the StatSampler
duke@435 66 // is disengaged from the watcher thread when this method is called,
duke@435 67 // but it is not disengaged if this method is invoked during a
duke@435 68 // VM abort.
duke@435 69 //
duke@435 70 if (!StatSampler::is_active())
duke@435 71 PerfDataManager::destroy();
duke@435 72
duke@435 73 // remove the persistent external resources, if any. this method
duke@435 74 // does not unmap or invalidate any virtual memory allocated during
duke@435 75 // initialization.
duke@435 76 //
duke@435 77 PerfMemory::destroy();
duke@435 78 }
duke@435 79
duke@435 80 void PerfMemory::initialize() {
duke@435 81
duke@435 82 if (_prologue != NULL)
duke@435 83 // initialization already performed
duke@435 84 return;
duke@435 85
duke@435 86 size_t capacity = align_size_up(PerfDataMemorySize,
duke@435 87 os::vm_allocation_granularity());
duke@435 88
duke@435 89 if (PerfTraceMemOps) {
duke@435 90 tty->print("PerfDataMemorySize = " SIZE_FORMAT ","
duke@435 91 " os::vm_allocation_granularity = " SIZE_FORMAT ","
duke@435 92 " adjusted size = " SIZE_FORMAT "\n",
duke@435 93 PerfDataMemorySize,
duke@435 94 os::vm_allocation_granularity(),
duke@435 95 capacity);
duke@435 96 }
duke@435 97
duke@435 98 // allocate PerfData memory region
duke@435 99 create_memory_region(capacity);
duke@435 100
duke@435 101 if (_start == NULL) {
duke@435 102
duke@435 103 // the PerfMemory region could not be created as desired. Rather
duke@435 104 // than terminating the JVM, we revert to creating the instrumentation
duke@435 105 // on the C heap. When running in this mode, external monitoring
duke@435 106 // clients cannot attach to and monitor this JVM.
duke@435 107 //
duke@435 108 // the warning is issued only in debug mode in order to avoid
duke@435 109 // additional output to the stdout or stderr output streams.
duke@435 110 //
duke@435 111 if (PrintMiscellaneous && Verbose) {
duke@435 112 warning("Could not create PerfData Memory region, reverting to malloc");
duke@435 113 }
duke@435 114
zgu@3900 115 _prologue = NEW_C_HEAP_OBJ(PerfDataPrologue, mtInternal);
duke@435 116 }
duke@435 117 else {
duke@435 118
duke@435 119 // the PerfMemory region was created as expected.
duke@435 120
duke@435 121 if (PerfTraceMemOps) {
duke@435 122 tty->print("PerfMemory created: address = " INTPTR_FORMAT ","
duke@435 123 " size = " SIZE_FORMAT "\n",
duke@435 124 (void*)_start,
duke@435 125 _capacity);
duke@435 126 }
duke@435 127
duke@435 128 _prologue = (PerfDataPrologue *)_start;
duke@435 129 _end = _start + _capacity;
duke@435 130 _top = _start + sizeof(PerfDataPrologue);
duke@435 131 }
duke@435 132
duke@435 133 assert(_prologue != NULL, "prologue pointer must be initialized");
duke@435 134
duke@435 135 #ifdef VM_LITTLE_ENDIAN
duke@435 136 _prologue->magic = (jint)0xc0c0feca;
duke@435 137 _prologue->byte_order = PERFDATA_LITTLE_ENDIAN;
duke@435 138 #else
duke@435 139 _prologue->magic = (jint)0xcafec0c0;
duke@435 140 _prologue->byte_order = PERFDATA_BIG_ENDIAN;
duke@435 141 #endif
duke@435 142
duke@435 143 _prologue->major_version = PERFDATA_MAJOR_VERSION;
duke@435 144 _prologue->minor_version = PERFDATA_MINOR_VERSION;
duke@435 145 _prologue->accessible = 0;
duke@435 146
duke@435 147 _prologue->entry_offset = sizeof(PerfDataPrologue);
duke@435 148 _prologue->num_entries = 0;
duke@435 149 _prologue->used = 0;
duke@435 150 _prologue->overflow = 0;
duke@435 151 _prologue->mod_time_stamp = 0;
duke@435 152
duke@435 153 OrderAccess::release_store(&_initialized, 1);
duke@435 154 }
duke@435 155
duke@435 156 void PerfMemory::destroy() {
duke@435 157
hseigel@6227 158 if (_prologue == NULL) return;
duke@435 159
duke@435 160 if (_start != NULL && _prologue->overflow != 0) {
duke@435 161
duke@435 162 // This state indicates that the contiguous memory region exists and
duke@435 163 // that it wasn't large enough to hold all the counters. In this case,
duke@435 164 // we output a warning message to the user on exit if the -XX:+Verbose
duke@435 165 // flag is set (a debug only flag). External monitoring tools can detect
duke@435 166 // this condition by monitoring the _prologue->overflow word.
duke@435 167 //
duke@435 168 // There are two tunables that can help resolve this issue:
duke@435 169 // - increase the size of the PerfMemory with -XX:PerfDataMemorySize=<n>
duke@435 170 // - decrease the maximum string constant length with
duke@435 171 // -XX:PerfMaxStringConstLength=<n>
duke@435 172 //
duke@435 173 if (PrintMiscellaneous && Verbose) {
duke@435 174 warning("PerfMemory Overflow Occurred.\n"
duke@435 175 "\tCapacity = " SIZE_FORMAT " bytes"
duke@435 176 " Used = " SIZE_FORMAT " bytes"
duke@435 177 " Overflow = " INT32_FORMAT " bytes"
duke@435 178 "\n\tUse -XX:PerfDataMemorySize=<size> to specify larger size.",
duke@435 179 PerfMemory::capacity(),
duke@435 180 PerfMemory::used(),
duke@435 181 _prologue->overflow);
duke@435 182 }
duke@435 183 }
duke@435 184
duke@435 185 if (_start != NULL) {
duke@435 186
duke@435 187 // this state indicates that the contiguous memory region was successfully
duke@435 188 // and that persistent resources may need to be cleaned up. This is
duke@435 189 // expected to be the typical condition.
duke@435 190 //
duke@435 191 delete_memory_region();
duke@435 192 }
duke@435 193
duke@435 194 _start = NULL;
duke@435 195 _end = NULL;
duke@435 196 _top = NULL;
duke@435 197 _prologue = NULL;
duke@435 198 _capacity = 0;
duke@435 199 }
duke@435 200
duke@435 201 // allocate an aligned block of memory from the PerfData memory
duke@435 202 // region. This method assumes that the PerfData memory region
duke@435 203 // was aligned on a double word boundary when created.
duke@435 204 //
duke@435 205 char* PerfMemory::alloc(size_t size) {
duke@435 206
duke@435 207 if (!UsePerfData) return NULL;
duke@435 208
duke@435 209 MutexLocker ml(PerfDataMemAlloc_lock);
duke@435 210
duke@435 211 assert(_prologue != NULL, "called before initialization");
duke@435 212
duke@435 213 // check that there is enough memory for this request
duke@435 214 if ((_top + size) >= _end) {
duke@435 215
duke@435 216 _prologue->overflow += (jint)size;
duke@435 217
duke@435 218 return NULL;
duke@435 219 }
duke@435 220
duke@435 221 char* result = _top;
duke@435 222
duke@435 223 _top += size;
duke@435 224
duke@435 225 assert(contains(result), "PerfData memory pointer out of range");
duke@435 226
duke@435 227 _prologue->used = (jint)used();
duke@435 228 _prologue->num_entries = _prologue->num_entries + 1;
duke@435 229
duke@435 230 return result;
duke@435 231 }
duke@435 232
duke@435 233 void PerfMemory::mark_updated() {
duke@435 234 if (!UsePerfData) return;
duke@435 235
duke@435 236 _prologue->mod_time_stamp = os::elapsed_counter();
duke@435 237 }
duke@435 238
duke@435 239 // Returns the complete path including the file name of performance data file.
duke@435 240 // Caller is expected to release the allocated memory.
duke@435 241 char* PerfMemory::get_perfdata_file_path() {
duke@435 242 char* dest_file = NULL;
duke@435 243
duke@435 244 if (PerfDataSaveFile != NULL) {
duke@435 245 // dest_file_name stores the validated file name if file_name
duke@435 246 // contains %p which will be replaced by pid.
zgu@3900 247 dest_file = NEW_C_HEAP_ARRAY(char, JVM_MAXPATHLEN, mtInternal);
duke@435 248 if(!Arguments::copy_expand_pid(PerfDataSaveFile, strlen(PerfDataSaveFile),
duke@435 249 dest_file, JVM_MAXPATHLEN)) {
zgu@3900 250 FREE_C_HEAP_ARRAY(char, dest_file, mtInternal);
duke@435 251 if (PrintMiscellaneous && Verbose) {
duke@435 252 warning("Invalid performance data file path name specified, "\
duke@435 253 "fall back to a default name");
duke@435 254 }
duke@435 255 } else {
duke@435 256 return dest_file;
duke@435 257 }
duke@435 258 }
duke@435 259 // create the name of the file for retaining the instrumentation memory.
zgu@3900 260 dest_file = NEW_C_HEAP_ARRAY(char, PERFDATA_FILENAME_LEN, mtInternal);
duke@435 261 jio_snprintf(dest_file, PERFDATA_FILENAME_LEN,
duke@435 262 "%s_%d", PERFDATA_NAME, os::current_process_id());
duke@435 263
duke@435 264 return dest_file;
duke@435 265 }

mercurial