perfMemory.hpp revision 1879:f95d63e2154a
11539Srgrimes/* 21539Srgrimes * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. 31539Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41539Srgrimes * 51539Srgrimes * This code is free software; you can redistribute it and/or modify it 61539Srgrimes * under the terms of the GNU General Public License version 2 only, as 71539Srgrimes * published by the Free Software Foundation. 81539Srgrimes * 91539Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT 101539Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 111539Srgrimes * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 121539Srgrimes * version 2 for more details (a copy is included in the LICENSE file that 131539Srgrimes * accompanied this code). 141539Srgrimes * 151539Srgrimes * You should have received a copy of the GNU General Public License version 161539Srgrimes * 2 along with this work; if not, write to the Free Software Foundation, 171539Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 181539Srgrimes * 191539Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 201539Srgrimes * or visit www.oracle.com if you need additional information or have any 211539Srgrimes * questions. 221539Srgrimes * 231539Srgrimes */ 241539Srgrimes 251539Srgrimes#ifndef SHARE_VM_RUNTIME_PERFMEMORY_HPP 261539Srgrimes#define SHARE_VM_RUNTIME_PERFMEMORY_HPP 271539Srgrimes 281539Srgrimes#include "utilities/exceptions.hpp" 291539Srgrimes 301539Srgrimes/* 311539Srgrimes * PerfData Version Constants 321539Srgrimes * - Major Version - change whenever the structure of PerfDataEntry changes 331539Srgrimes * - Minor Version - change whenever the data within the PerfDataEntry 341539Srgrimes * structure changes. for example, new unit or variability 351539Srgrimes * values are added or new PerfData subtypes are added. 3623655Speter */ 3750473Speter#define PERFDATA_MAJOR_VERSION 2 381539Srgrimes#define PERFDATA_MINOR_VERSION 0 391539Srgrimes 401539Srgrimes/* Byte order of the PerfData memory region. The byte order is exposed in 411539Srgrimes * the PerfData memory region as the data in the memory region may have 421539Srgrimes * been generated by a little endian JVM implementation. Tracking the byte 431539Srgrimes * order in the PerfData memory region allows Java applications to adapt 4424897Sbde * to the native byte order for monitoring purposes. This indicator is 451539Srgrimes * also useful when a snapshot of the PerfData memory region is shipped 461539Srgrimes * to a machine with a native byte order different from that of the 471539Srgrimes * originating machine. 481539Srgrimes */ 491539Srgrimes#define PERFDATA_BIG_ENDIAN 0 501539Srgrimes#define PERFDATA_LITTLE_ENDIAN 1 511539Srgrimes 521539Srgrimes/* 531539Srgrimes * The PerfDataPrologue structure is known by the PerfDataBuffer Java class 541539Srgrimes * libraries that read the PerfData memory region. The size and the position 5524897Sbde * of the fields must be changed along with their counterparts in the 561539Srgrimes * PerfDataBuffer Java class. The first four bytes of this structure 571539Srgrimes * should never change, or compatibility problems between the monitoring 581539Srgrimes * applications and Hotspot VMs will result. The reserved fields are 591539Srgrimes * available for future enhancements. 601539Srgrimes */ 611539Srgrimestypedef struct { 621539Srgrimes jint magic; // magic number - 0xcafec0c0 631539Srgrimes jbyte byte_order; // byte order of the buffer 641539Srgrimes jbyte major_version; // major and minor version numbers 651539Srgrimes jbyte minor_version; 661539Srgrimes jbyte accessible; // ready to access 671539Srgrimes jint used; // number of PerfData memory bytes used 681539Srgrimes jint overflow; // number of bytes of overflow 691539Srgrimes jlong mod_time_stamp; // time stamp of last structural modification 701539Srgrimes jint entry_offset; // offset of the first PerfDataEntry 7172372Sdeischen jint num_entries; // number of allocated PerfData entries 7272372Sdeischen} PerfDataPrologue; 731539Srgrimes 741539Srgrimes/* The PerfDataEntry structure defines the fixed portion of an entry 751539Srgrimes * in the PerfData memory region. The PerfDataBuffer Java libraries 761539Srgrimes * are aware of this structure and need to be changed when this 771539Srgrimes * structure changes. 781539Srgrimes */ 791539Srgrimestypedef struct { 801539Srgrimes 811539Srgrimes jint entry_length; // entry length in bytes 821539Srgrimes jint name_offset; // offset of the data item name 831539Srgrimes jint vector_length; // length of the vector. If 0, then scalar 841539Srgrimes jbyte data_type; // type of the data item - 851539Srgrimes // 'B','Z','J','I','S','C','D','F','V','L','[' 861539Srgrimes jbyte flags; // flags indicating misc attributes 871539Srgrimes jbyte data_units; // unit of measure for the data type 881539Srgrimes jbyte data_variability; // variability classification of data type 891539Srgrimes jint data_offset; // offset of the data item 901539Srgrimes 911539Srgrimes/* 921539Srgrimes body of PerfData memory entry is variable length 931539Srgrimes 941539Srgrimes jbyte[name_length] data_name; // name of the data item 951539Srgrimes jbyte[pad_length] data_pad; // alignment of data item 961539Srgrimes j<data_type>[data_length] data_item; // array of appropriate types. 971539Srgrimes // data_length is > 1 only when the 981539Srgrimes // data_type is T_ARRAY. 991539Srgrimes*/ 1001539Srgrimes} PerfDataEntry; 1011539Srgrimes 1021539Srgrimes// Prefix of performance data file. 1031539Srgrimesextern const char PERFDATA_NAME[]; 1041539Srgrimes 1051539Srgrimes// UINT_CHARS contains the number of characters holding a process id 1061539Srgrimes// (i.e. pid). pid is defined as unsigned "int" so the maximum possible pid value 1071539Srgrimes// would be 2^32 - 1 (4294967295) which can be represented as a 10 characters 1081539Srgrimes// string. 1091539Srgrimesstatic const size_t UINT_CHARS = 10; 1101539Srgrimes 1111539Srgrimes/* the PerfMemory class manages creation, destruction, 1121539Srgrimes * and allocation of the PerfData region. 1131539Srgrimes */ 1141539Srgrimesclass PerfMemory : AllStatic { 1151539Srgrimes friend class VMStructs; 1161539Srgrimes private: 1171539Srgrimes static char* _start; 1181539Srgrimes static char* _end; 1191539Srgrimes static char* _top; 1201539Srgrimes static size_t _capacity; 1211539Srgrimes static PerfDataPrologue* _prologue; 1221539Srgrimes static jint _initialized; 1231539Srgrimes 1241539Srgrimes static void create_memory_region(size_t sizep); 1251539Srgrimes static void delete_memory_region(); 1261539Srgrimes 1271539Srgrimes public: 1281539Srgrimes enum PerfMemoryMode { 1291539Srgrimes PERF_MODE_RO = 0, 13072372Sdeischen PERF_MODE_RW = 1 1311539Srgrimes }; 1321539Srgrimes 1331539Srgrimes static char* alloc(size_t size); 1341539Srgrimes static char* start() { return _start; } 1351539Srgrimes static char* end() { return _end; } 1361539Srgrimes static size_t used() { return (size_t) (_top - _start); } 1371539Srgrimes static size_t capacity() { return _capacity; } 1381539Srgrimes static bool is_initialized() { return _initialized != 0; } 1391539Srgrimes static bool contains(char* addr) { 1401539Srgrimes return ((_start != NULL) && (addr >= _start) && (addr < _end)); 1411539Srgrimes } 1421539Srgrimes static void mark_updated(); 1431539Srgrimes 1441539Srgrimes // methods for attaching to and detaching from the PerfData 1451539Srgrimes // memory segment of another JVM process on the same system. 1461539Srgrimes static void attach(const char* user, int vmid, PerfMemoryMode mode, 1471539Srgrimes char** addrp, size_t* size, TRAPS); 14813771Smpp static void detach(char* addr, size_t bytes, TRAPS); 14913771Smpp 1501539Srgrimes static void initialize(); 1511539Srgrimes static void destroy(); 15237489Speter static void set_accessible(bool value) { 15372372Sdeischen if (UsePerfData) { 1541539Srgrimes _prologue->accessible = value; 1551539Srgrimes } 1561539Srgrimes } 1571539Srgrimes 1581539Srgrimes // filename of backing store or NULL if none. 1591539Srgrimes static char* backing_store_filename(); 1601539Srgrimes 1611539Srgrimes // returns the complete file path of hsperfdata. 1621539Srgrimes // the caller is expected to free the allocated memory. 1631539Srgrimes static char* get_perfdata_file_path(); 1641539Srgrimes}; 1651539Srgrimes 1661539Srgrimesvoid perfMemory_init(); 1671539Srgrimesvoid perfMemory_exit(); 1681539Srgrimes 1691539Srgrimes#endif // SHARE_VM_RUNTIME_PERFMEMORY_HPP 1701539Srgrimes