src/share/vm/runtime/perfMemory.hpp

Fri, 08 Oct 2010 09:29:09 -0700

author
jcoomes
date
Fri, 08 Oct 2010 09:29:09 -0700
changeset 2198
0715f0cf171d
parent 1907
c18cbe5936b8
child 2314
f95d63e2154a
permissions
-rw-r--r--

Merge

duke@435 1 /*
trims@1907 2 * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 /*
duke@435 26 * PerfData Version Constants
duke@435 27 * - Major Version - change whenever the structure of PerfDataEntry changes
duke@435 28 * - Minor Version - change whenever the data within the PerfDataEntry
duke@435 29 * structure changes. for example, new unit or variability
duke@435 30 * values are added or new PerfData subtypes are added.
duke@435 31 */
duke@435 32 #define PERFDATA_MAJOR_VERSION 2
duke@435 33 #define PERFDATA_MINOR_VERSION 0
duke@435 34
duke@435 35 /* Byte order of the PerfData memory region. The byte order is exposed in
duke@435 36 * the PerfData memory region as the data in the memory region may have
duke@435 37 * been generated by a little endian JVM implementation. Tracking the byte
duke@435 38 * order in the PerfData memory region allows Java applications to adapt
duke@435 39 * to the native byte order for monitoring purposes. This indicator is
duke@435 40 * also useful when a snapshot of the PerfData memory region is shipped
duke@435 41 * to a machine with a native byte order different from that of the
duke@435 42 * originating machine.
duke@435 43 */
duke@435 44 #define PERFDATA_BIG_ENDIAN 0
duke@435 45 #define PERFDATA_LITTLE_ENDIAN 1
duke@435 46
duke@435 47 /*
duke@435 48 * The PerfDataPrologue structure is known by the PerfDataBuffer Java class
duke@435 49 * libraries that read the PerfData memory region. The size and the position
duke@435 50 * of the fields must be changed along with their counterparts in the
duke@435 51 * PerfDataBuffer Java class. The first four bytes of this structure
duke@435 52 * should never change, or compatibility problems between the monitoring
duke@435 53 * applications and Hotspot VMs will result. The reserved fields are
duke@435 54 * available for future enhancements.
duke@435 55 */
duke@435 56 typedef struct {
duke@435 57 jint magic; // magic number - 0xcafec0c0
duke@435 58 jbyte byte_order; // byte order of the buffer
duke@435 59 jbyte major_version; // major and minor version numbers
duke@435 60 jbyte minor_version;
duke@435 61 jbyte accessible; // ready to access
duke@435 62 jint used; // number of PerfData memory bytes used
duke@435 63 jint overflow; // number of bytes of overflow
duke@435 64 jlong mod_time_stamp; // time stamp of last structural modification
duke@435 65 jint entry_offset; // offset of the first PerfDataEntry
duke@435 66 jint num_entries; // number of allocated PerfData entries
duke@435 67 } PerfDataPrologue;
duke@435 68
duke@435 69 /* The PerfDataEntry structure defines the fixed portion of an entry
duke@435 70 * in the PerfData memory region. The PerfDataBuffer Java libraries
duke@435 71 * are aware of this structure and need to be changed when this
duke@435 72 * structure changes.
duke@435 73 */
duke@435 74 typedef struct {
duke@435 75
duke@435 76 jint entry_length; // entry length in bytes
duke@435 77 jint name_offset; // offset of the data item name
duke@435 78 jint vector_length; // length of the vector. If 0, then scalar
duke@435 79 jbyte data_type; // type of the data item -
duke@435 80 // 'B','Z','J','I','S','C','D','F','V','L','['
duke@435 81 jbyte flags; // flags indicating misc attributes
duke@435 82 jbyte data_units; // unit of measure for the data type
duke@435 83 jbyte data_variability; // variability classification of data type
duke@435 84 jint data_offset; // offset of the data item
duke@435 85
duke@435 86 /*
duke@435 87 body of PerfData memory entry is variable length
duke@435 88
duke@435 89 jbyte[name_length] data_name; // name of the data item
duke@435 90 jbyte[pad_length] data_pad; // alignment of data item
duke@435 91 j<data_type>[data_length] data_item; // array of appropriate types.
duke@435 92 // data_length is > 1 only when the
duke@435 93 // data_type is T_ARRAY.
duke@435 94 */
duke@435 95 } PerfDataEntry;
duke@435 96
duke@435 97 // Prefix of performance data file.
kvn@869 98 extern const char PERFDATA_NAME[];
duke@435 99
duke@435 100 // UINT_CHARS contains the number of characters holding a process id
duke@435 101 // (i.e. pid). pid is defined as unsigned "int" so the maximum possible pid value
duke@435 102 // would be 2^32 - 1 (4294967295) which can be represented as a 10 characters
duke@435 103 // string.
duke@435 104 static const size_t UINT_CHARS = 10;
duke@435 105
duke@435 106 /* the PerfMemory class manages creation, destruction,
duke@435 107 * and allocation of the PerfData region.
duke@435 108 */
duke@435 109 class PerfMemory : AllStatic {
duke@435 110 friend class VMStructs;
duke@435 111 private:
duke@435 112 static char* _start;
duke@435 113 static char* _end;
duke@435 114 static char* _top;
duke@435 115 static size_t _capacity;
duke@435 116 static PerfDataPrologue* _prologue;
duke@435 117 static jint _initialized;
duke@435 118
duke@435 119 static void create_memory_region(size_t sizep);
duke@435 120 static void delete_memory_region();
duke@435 121
duke@435 122 public:
duke@435 123 enum PerfMemoryMode {
duke@435 124 PERF_MODE_RO = 0,
duke@435 125 PERF_MODE_RW = 1
duke@435 126 };
duke@435 127
duke@435 128 static char* alloc(size_t size);
duke@435 129 static char* start() { return _start; }
duke@435 130 static char* end() { return _end; }
duke@435 131 static size_t used() { return (size_t) (_top - _start); }
duke@435 132 static size_t capacity() { return _capacity; }
duke@435 133 static bool is_initialized() { return _initialized != 0; }
duke@435 134 static bool contains(char* addr) {
duke@435 135 return ((_start != NULL) && (addr >= _start) && (addr < _end));
duke@435 136 }
duke@435 137 static void mark_updated();
duke@435 138
duke@435 139 // methods for attaching to and detaching from the PerfData
duke@435 140 // memory segment of another JVM process on the same system.
duke@435 141 static void attach(const char* user, int vmid, PerfMemoryMode mode,
duke@435 142 char** addrp, size_t* size, TRAPS);
duke@435 143 static void detach(char* addr, size_t bytes, TRAPS);
duke@435 144
duke@435 145 static void initialize();
duke@435 146 static void destroy();
duke@435 147 static void set_accessible(bool value) {
duke@435 148 if (UsePerfData) {
duke@435 149 _prologue->accessible = value;
duke@435 150 }
duke@435 151 }
duke@435 152
duke@435 153 // filename of backing store or NULL if none.
duke@435 154 static char* backing_store_filename();
duke@435 155
duke@435 156 // returns the complete file path of hsperfdata.
duke@435 157 // the caller is expected to free the allocated memory.
duke@435 158 static char* get_perfdata_file_path();
duke@435 159 };
duke@435 160
duke@435 161 void perfMemory_init();
duke@435 162 void perfMemory_exit();

mercurial