src/share/vm/runtime/perfMemory.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/runtime/perfMemory.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,169 @@
     1.4 +/*
     1.5 + * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_RUNTIME_PERFMEMORY_HPP
    1.29 +#define SHARE_VM_RUNTIME_PERFMEMORY_HPP
    1.30 +
    1.31 +#include "utilities/exceptions.hpp"
    1.32 +
    1.33 +/*
    1.34 + * PerfData Version Constants
    1.35 + *   - Major Version - change whenever the structure of PerfDataEntry changes
    1.36 + *   - Minor Version - change whenever the data within the PerfDataEntry
    1.37 + *                     structure changes. for example, new unit or variability
    1.38 + *                     values are added or new PerfData subtypes are added.
    1.39 + */
    1.40 +#define PERFDATA_MAJOR_VERSION 2
    1.41 +#define PERFDATA_MINOR_VERSION 0
    1.42 +
    1.43 +/* Byte order of the PerfData memory region. The byte order is exposed in
    1.44 + * the PerfData memory region as the data in the memory region may have
    1.45 + * been generated by a little endian JVM implementation. Tracking the byte
    1.46 + * order in the PerfData memory region allows Java applications to adapt
    1.47 + * to the native byte order for monitoring purposes. This indicator is
    1.48 + * also useful when a snapshot of the PerfData memory region is shipped
    1.49 + * to a machine with a native byte order different from that of the
    1.50 + * originating machine.
    1.51 + */
    1.52 +#define PERFDATA_BIG_ENDIAN     0
    1.53 +#define PERFDATA_LITTLE_ENDIAN  1
    1.54 +
    1.55 +/*
    1.56 + * The PerfDataPrologue structure is known by the PerfDataBuffer Java class
    1.57 + * libraries that read the PerfData memory region. The size and the position
    1.58 + * of the fields must be changed along with their counterparts in the
    1.59 + * PerfDataBuffer Java class. The first four bytes of this structure
    1.60 + * should never change, or compatibility problems between the monitoring
    1.61 + * applications and Hotspot VMs will result. The reserved fields are
    1.62 + * available for future enhancements.
    1.63 + */
    1.64 +typedef struct {
    1.65 +  jint   magic;              // magic number - 0xcafec0c0
    1.66 +  jbyte  byte_order;         // byte order of the buffer
    1.67 +  jbyte  major_version;      // major and minor version numbers
    1.68 +  jbyte  minor_version;
    1.69 +  jbyte  accessible;         // ready to access
    1.70 +  jint   used;               // number of PerfData memory bytes used
    1.71 +  jint   overflow;           // number of bytes of overflow
    1.72 +  jlong  mod_time_stamp;     // time stamp of last structural modification
    1.73 +  jint   entry_offset;       // offset of the first PerfDataEntry
    1.74 +  jint   num_entries;        // number of allocated PerfData entries
    1.75 +} PerfDataPrologue;
    1.76 +
    1.77 +/* The PerfDataEntry structure defines the fixed portion of an entry
    1.78 + * in the PerfData memory region. The PerfDataBuffer Java libraries
    1.79 + * are aware of this structure and need to be changed when this
    1.80 + * structure changes.
    1.81 + */
    1.82 +typedef struct {
    1.83 +
    1.84 +  jint entry_length;      // entry length in bytes
    1.85 +  jint name_offset;       // offset of the data item name
    1.86 +  jint vector_length;     // length of the vector. If 0, then scalar
    1.87 +  jbyte data_type;        // type of the data item -
    1.88 +                          // 'B','Z','J','I','S','C','D','F','V','L','['
    1.89 +  jbyte flags;            // flags indicating misc attributes
    1.90 +  jbyte data_units;       // unit of measure for the data type
    1.91 +  jbyte data_variability; // variability classification of data type
    1.92 +  jint  data_offset;      // offset of the data item
    1.93 +
    1.94 +/*
    1.95 +  body of PerfData memory entry is variable length
    1.96 +
    1.97 +  jbyte[name_length] data_name;        // name of the data item
    1.98 +  jbyte[pad_length] data_pad;          // alignment of data item
    1.99 +  j<data_type>[data_length] data_item; // array of appropriate types.
   1.100 +                                       // data_length is > 1 only when the
   1.101 +                                       // data_type is T_ARRAY.
   1.102 +*/
   1.103 +} PerfDataEntry;
   1.104 +
   1.105 +// Prefix of performance data file.
   1.106 +extern const char PERFDATA_NAME[];
   1.107 +
   1.108 +// UINT_CHARS contains the number of characters holding a process id
   1.109 +// (i.e. pid). pid is defined as unsigned "int" so the maximum possible pid value
   1.110 +// would be 2^32 - 1 (4294967295) which can be represented as a 10 characters
   1.111 +// string.
   1.112 +static const size_t UINT_CHARS = 10;
   1.113 +
   1.114 +/* the PerfMemory class manages creation, destruction,
   1.115 + * and allocation of the PerfData region.
   1.116 + */
   1.117 +class PerfMemory : AllStatic {
   1.118 +    friend class VMStructs;
   1.119 +  private:
   1.120 +    static char*  _start;
   1.121 +    static char*  _end;
   1.122 +    static char*  _top;
   1.123 +    static size_t _capacity;
   1.124 +    static PerfDataPrologue*  _prologue;
   1.125 +    static jint   _initialized;
   1.126 +
   1.127 +    static void create_memory_region(size_t sizep);
   1.128 +    static void delete_memory_region();
   1.129 +
   1.130 +  public:
   1.131 +    enum PerfMemoryMode {
   1.132 +      PERF_MODE_RO = 0,
   1.133 +      PERF_MODE_RW = 1
   1.134 +    };
   1.135 +
   1.136 +    static char* alloc(size_t size);
   1.137 +    static char* start() { return _start; }
   1.138 +    static char* end() { return _end; }
   1.139 +    static size_t used() { return (size_t) (_top - _start); }
   1.140 +    static size_t capacity() { return _capacity; }
   1.141 +    static bool is_initialized() { return _initialized != 0; }
   1.142 +    static bool contains(char* addr) {
   1.143 +      return ((_start != NULL) && (addr >= _start) && (addr < _end));
   1.144 +    }
   1.145 +    static void mark_updated();
   1.146 +
   1.147 +    // methods for attaching to and detaching from the PerfData
   1.148 +    // memory segment of another JVM process on the same system.
   1.149 +    static void attach(const char* user, int vmid, PerfMemoryMode mode,
   1.150 +                       char** addrp, size_t* size, TRAPS);
   1.151 +    static void detach(char* addr, size_t bytes, TRAPS);
   1.152 +
   1.153 +    static void initialize();
   1.154 +    static void destroy();
   1.155 +    static void set_accessible(bool value) {
   1.156 +      if (UsePerfData) {
   1.157 +        _prologue->accessible = value;
   1.158 +      }
   1.159 +    }
   1.160 +
   1.161 +    // filename of backing store or NULL if none.
   1.162 +    static char* backing_store_filename();
   1.163 +
   1.164 +    // returns the complete file path of hsperfdata.
   1.165 +    // the caller is expected to free the allocated memory.
   1.166 +    static char* get_perfdata_file_path();
   1.167 +};
   1.168 +
   1.169 +void perfMemory_init();
   1.170 +void perfMemory_exit();
   1.171 +
   1.172 +#endif // SHARE_VM_RUNTIME_PERFMEMORY_HPP

mercurial