src/share/vm/runtime/perfMemory.cpp

Fri, 24 Jun 2016 17:12:13 +0800

author
aoqi<aoqi@loongson.cn>
date
Fri, 24 Jun 2016 17:12:13 +0800
changeset 25
873fd82b133d
parent 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

[Code Reorganization] Removed GC related modifications made by Loongson, for example, UseOldNUMA.

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

mercurial