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