perfMemory.hpp revision 434
5612N/A/*
5612N/A * Copyright 2001-2006 Sun Microsystems, Inc. All Rights Reserved.
5612N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5612N/A *
5612N/A * This code is free software; you can redistribute it and/or modify it
5612N/A * under the terms of the GNU General Public License version 2 only, as
5612N/A * published by the Free Software Foundation.
5612N/A *
5612N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5612N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5612N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5612N/A * version 2 for more details (a copy is included in the LICENSE file that
5612N/A * accompanied this code).
5612N/A *
5612N/A * You should have received a copy of the GNU General Public License version
5612N/A * 2 along with this work; if not, write to the Free Software Foundation,
5612N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5612N/A *
5612N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
5612N/A * CA 95054 USA or visit www.sun.com if you need additional information or
5612N/A * have any questions.
5612N/A *
5612N/A */
5612N/A
5612N/A/*
5612N/A * PerfData Version Constants
5612N/A * - Major Version - change whenever the structure of PerfDataEntry changes
5612N/A * - Minor Version - change whenever the data within the PerfDataEntry
5612N/A * structure changes. for example, new unit or variability
4103N/A * values are added or new PerfData subtypes are added.
5612N/A */
4103N/A#define PERFDATA_MAJOR_VERSION 2
5615N/A#define PERFDATA_MINOR_VERSION 0
5615N/A
4103N/A/* Byte order of the PerfData memory region. The byte order is exposed in
5615N/A * the PerfData memory region as the data in the memory region may have
5612N/A * been generated by a little endian JVM implementation. Tracking the byte
5615N/A * order in the PerfData memory region allows Java applications to adapt
4103N/A * to the native byte order for monitoring purposes. This indicator is
5615N/A * also useful when a snapshot of the PerfData memory region is shipped
4103N/A * to a machine with a native byte order different from that of the
4103N/A * originating machine.
5615N/A */
4103N/A#define PERFDATA_BIG_ENDIAN 0
5615N/A#define PERFDATA_LITTLE_ENDIAN 1
5615N/A
5615N/A/*
4103N/A * The PerfDataPrologue structure is known by the PerfDataBuffer Java class
4103N/A * libraries that read the PerfData memory region. The size and the position
5615N/A * of the fields must be changed along with their counterparts in the
5615N/A * PerfDataBuffer Java class. The first four bytes of this structure
5615N/A * should never change, or compatibility problems between the monitoring
4103N/A * applications and Hotspot VMs will result. The reserved fields are
4103N/A * available for future enhancements.
5615N/A */
5615N/Atypedef struct {
5615N/A jint magic; // magic number - 0xcafec0c0
5612N/A jbyte byte_order; // byte order of the buffer
4103N/A jbyte major_version; // major and minor version numbers
5615N/A jbyte minor_version;
5615N/A jbyte accessible; // ready to access
5615N/A jint used; // number of PerfData memory bytes used
4103N/A jint overflow; // number of bytes of overflow
4103N/A jlong mod_time_stamp; // time stamp of last structural modification
5615N/A jint entry_offset; // offset of the first PerfDataEntry
5615N/A jint num_entries; // number of allocated PerfData entries
5615N/A} PerfDataPrologue;
4103N/A
4103N/A/* The PerfDataEntry structure defines the fixed portion of an entry
4103N/A * in the PerfData memory region. The PerfDataBuffer Java libraries
4103N/A * are aware of this structure and need to be changed when this
5615N/A * structure changes.
4103N/A */
5615N/Atypedef struct {
4103N/A
5615N/A jint entry_length; // entry length in bytes
5615N/A jint name_offset; // offset of the data item name
5615N/A jint vector_length; // length of the vector. If 0, then scalar
4103N/A jbyte data_type; // type of the data item -
5612N/A // 'B','Z','J','I','S','C','D','F','V','L','['
4103N/A jbyte flags; // flags indicating misc attributes
4103N/A jbyte data_units; // unit of measure for the data type
5615N/A jbyte data_variability; // variability classification of data type
5615N/A jint data_offset; // offset of the data item
5615N/A
4103N/A/*
5615N/A body of PerfData memory entry is variable length
4103N/A
4103N/A jbyte[name_length] data_name; // name of the data item
4103N/A jbyte[pad_length] data_pad; // alignment of data item
4103N/A j<data_type>[data_length] data_item; // array of appropriate types.
4103N/A // data_length is > 1 only when the
5612N/A // data_type is T_ARRAY.
5612N/A*/
4103N/A} PerfDataEntry;
4103N/A
4103N/A// Prefix of performance data file.
4103N/Aextern const char PERFDATA_NAME[];
4103N/A
5615N/A// UINT_CHARS contains the number of characters holding a process id
5615N/A// (i.e. pid). pid is defined as unsigned "int" so the maximum possible pid value
5615N/A// would be 2^32 - 1 (4294967295) which can be represented as a 10 characters
5615N/A// string.
5615N/Astatic const size_t UINT_CHARS = 10;
5615N/A
5615N/A/* the PerfMemory class manages creation, destruction,
5615N/A * and allocation of the PerfData region.
5615N/A */
5615N/Aclass PerfMemory : AllStatic {
5615N/A friend class VMStructs;
5615N/A private:
5615N/A static char* _start;
5615N/A static char* _end;
5615N/A static char* _top;
5615N/A static size_t _capacity;
5615N/A static PerfDataPrologue* _prologue;
5615N/A static jint _initialized;
5615N/A
5615N/A static void create_memory_region(size_t sizep);
5615N/A static void delete_memory_region();
5615N/A
4103N/A public:
enum PerfMemoryMode {
PERF_MODE_RO = 0,
PERF_MODE_RW = 1
};
static char* alloc(size_t size);
static char* start() { return _start; }
static char* end() { return _end; }
static size_t used() { return (size_t) (_top - _start); }
static size_t capacity() { return _capacity; }
static bool is_initialized() { return _initialized != 0; }
static bool contains(char* addr) {
return ((_start != NULL) && (addr >= _start) && (addr < _end));
}
static void mark_updated();
// methods for attaching to and detaching from the PerfData
// memory segment of another JVM process on the same system.
static void attach(const char* user, int vmid, PerfMemoryMode mode,
char** addrp, size_t* size, TRAPS);
static void detach(char* addr, size_t bytes, TRAPS);
static void initialize();
static void destroy();
static void set_accessible(bool value) {
if (UsePerfData) {
_prologue->accessible = value;
}
}
// filename of backing store or NULL if none.
static char* backing_store_filename();
// returns the complete file path of hsperfdata.
// the caller is expected to free the allocated memory.
static char* get_perfdata_file_path();
};
void perfMemory_init();
void perfMemory_exit();