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