perfMemory.cpp revision 1879
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "memory/allocation.inline.hpp"
#include "runtime/arguments.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/perfData.hpp"
#include "runtime/perfMemory.hpp"
#include "runtime/statSampler.hpp"
#include "utilities/globalDefinitions.hpp"
// Prefix of performance data file.
const char PERFDATA_NAME[] = "hsperfdata";
// Add 1 for the '_' character between PERFDATA_NAME and pid. The '\0' terminating
// character will be included in the sizeof(PERFDATA_NAME) operation.
UINT_CHARS + 1;
void perfMemory_init() {
if (!UsePerfData) return;
PerfMemory::initialize();
}
void perfMemory_exit() {
if (!UsePerfData) return;
if (!PerfMemory::is_initialized()) return;
// if the StatSampler is active, then we don't want to remove
// resources it may be dependent on. Typically, the StatSampler
// is disengaged from the watcher thread when this method is called,
// but it is not disengaged if this method is invoked during a
// VM abort.
//
if (!StatSampler::is_active())
// remove the persistent external resources, if any. this method
// does not unmap or invalidate any virtual memory allocated during
// initialization.
//
PerfMemory::destroy();
}
void PerfMemory::initialize() {
// initialization already performed
return;
if (PerfTraceMemOps) {
capacity);
}
// allocate PerfData memory region
// the PerfMemory region could not be created as desired. Rather
// than terminating the JVM, we revert to creating the instrumentation
// on the C heap. When running in this mode, external monitoring
// clients cannot attach to and monitor this JVM.
//
// the warning is issued only in debug mode in order to avoid
// additional output to the stdout or stderr output streams.
//
if (PrintMiscellaneous && Verbose) {
warning("Could not create PerfData Memory region, reverting to malloc");
}
}
else {
// the PerfMemory region was created as expected.
if (PerfTraceMemOps) {
(void*)_start,
}
}
#ifdef VM_LITTLE_ENDIAN
#else
#endif
_prologue->accessible = 0;
_prologue->num_entries = 0;
_prologue->mod_time_stamp = 0;
}
void PerfMemory::destroy() {
// This state indicates that the contiguous memory region exists and
// that it wasn't large enough to hold all the counters. In this case,
// we output a warning message to the user on exit if the -XX:+Verbose
// flag is set (a debug only flag). External monitoring tools can detect
// this condition by monitoring the _prologue->overflow word.
//
// There are two tunables that can help resolve this issue:
// - increase the size of the PerfMemory with -XX:PerfDataMemorySize=<n>
// - decrease the maximum string constant length with
// -XX:PerfMaxStringConstLength=<n>
//
if (PrintMiscellaneous && Verbose) {
warning("PerfMemory Overflow Occurred.\n"
"\n\tUse -XX:PerfDataMemorySize=<size> to specify larger size.",
PerfMemory::capacity(),
PerfMemory::used(),
}
}
// this state indicates that the contiguous memory region was successfully
// and that persistent resources may need to be cleaned up. This is
// expected to be the typical condition.
//
}
_capacity = 0;
}
// allocate an aligned block of memory from the PerfData memory
// region. This method assumes that the PerfData memory region
// was aligned on a double word boundary when created.
//
if (!UsePerfData) return NULL;
// check that there is enough memory for this request
return NULL;
}
return result;
}
void PerfMemory::mark_updated() {
if (!UsePerfData) return;
}
// Returns the complete path including the file name of performance data file.
// Caller is expected to release the allocated memory.
char* PerfMemory::get_perfdata_file_path() {
if (PerfDataSaveFile != NULL) {
// dest_file_name stores the validated file name if file_name
// contains %p which will be replaced by pid.
dest_file, JVM_MAXPATHLEN)) {
FREE_C_HEAP_ARRAY(char, dest_file);
if (PrintMiscellaneous && Verbose) {
warning("Invalid performance data file path name specified, "\
"fall back to a default name");
}
} else {
return dest_file;
}
}
// create the name of the file for retaining the instrumentation memory.
return dest_file;
}