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