001: /*
002: * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.jvmstat.perfdata.monitor.v1_0;
027:
028: import sun.jvmstat.monitor.*;
029: import sun.jvmstat.perfdata.monitor.*;
030: import java.nio.*;
031:
032: /**
033: * Class representing the 1.0 version of the HotSpot PerfData instrumentation
034: * buffer header.
035: * <p>
036: * The PerfDataBufferPrologue2_0 class supports parsing of the version
037: * specific portions of the PerfDataPrologue C structure:
038: * <pre>
039: * typedef struct {
040: * ... // handled by superclass
041: * jint used; // number of PerfData memory bytes used
042: * jint overflow; // number of bytes of overflow
043: * jlong mod_time_stamp; // time stamp of the last structural modification
044: * } PerfDataPrologue
045: * </pre>
046: *
047: * @author Brian Doherty
048: * @version 1.8, 05/05/07
049: * @since 1.5
050: */
051: public class PerfDataBufferPrologue extends
052: AbstractPerfDataBufferPrologue {
053:
054: private static final int SUPPORTED_MAJOR_VERSION = 1;
055: private static final int SUPPORTED_MINOR_VERSION = 0;
056:
057: /*
058: * the following constants must match the field offsets and sizes
059: * in the PerfDataPrologue structure in perfMemory.hpp
060: */
061: final static int PERFDATA_PROLOG_USED_OFFSET = 8;
062: final static int PERFDATA_PROLOG_USED_SIZE = 4; // sizeof(int)
063: final static int PERFDATA_PROLOG_OVERFLOW_OFFSET = 12;
064: final static int PERFDATA_PROLOG_OVERFLOW_SIZE = 4; // sizeof(int)
065: final static int PERFDATA_PROLOG_MODTIMESTAMP_OFFSET = 16;
066: final static int PERFDATA_PROLOG_MODTIMESTAMP_SIZE = 8; // sizeof(long)
067: final static int PERFDATA_PROLOG_SIZE = 24; // sizeof(struct PerfDataProlog)
068:
069: // counter names for prologue psuedo counters
070: final static String PERFDATA_BUFFER_SIZE_NAME = "sun.perfdata.size";
071: final static String PERFDATA_BUFFER_USED_NAME = "sun.perfdata.used";
072: final static String PERFDATA_OVERFLOW_NAME = "sun.perfdata.overflow";
073: final static String PERFDATA_MODTIMESTAMP_NAME = "sun.perfdata.timestamp";
074:
075: /**
076: * Create an instance of PerfDataBufferPrologue from the given
077: * ByteBuffer object.
078: *
079: * @param byteBuffer the buffer containing the binary header data
080: */
081: public PerfDataBufferPrologue(ByteBuffer byteBuffer)
082: throws MonitorException {
083: super (byteBuffer);
084: assert ((getMajorVersion() == 1) && (getMinorVersion() == 0));
085: }
086:
087: /**
088: * {@inheritDoc}
089: */
090: public boolean supportsAccessible() {
091: return false;
092: }
093:
094: /**
095: * {@inheritDoc}
096: */
097: public boolean isAccessible() {
098: return true;
099: }
100:
101: /**
102: * Get the utilization of the instrumentation memory buffer.
103: *
104: * @return int - the utilization of the buffer
105: */
106: public int getUsed() {
107: byteBuffer.position(PERFDATA_PROLOG_USED_OFFSET);
108: return byteBuffer.getInt();
109: }
110:
111: /**
112: * Get the size of the instrumentation memory buffer.
113: *
114: * @return int - the size of the buffer
115: */
116: public int getBufferSize() {
117: return byteBuffer.capacity();
118: }
119:
120: /**
121: * Get the buffer overflow amount. This value is non-zero if the
122: * HotSpot JVM has overflowed the instrumentation memory buffer.
123: * The target JVM can be restarted with -XX:PerfDataMemSize=X to
124: * create a larger memory buffer.
125: *
126: * @return int - the size of the buffer
127: */
128: public int getOverflow() {
129: byteBuffer.position(PERFDATA_PROLOG_OVERFLOW_OFFSET);
130: return byteBuffer.getInt();
131: }
132:
133: /**
134: * Get the time of last modification for the instrumentation
135: * memory buffer. This method returns the time, as ticks since the
136: * start of the target JVM, of the last structural modification to
137: * the instrumentation buffer. Structural modifications correspond to
138: * the addition or deletion of instrumentation objects. Updates to
139: * counter values are not structural modifications.
140: */
141: public long getModificationTimeStamp() {
142: byteBuffer.position(PERFDATA_PROLOG_MODTIMESTAMP_OFFSET);
143: return byteBuffer.getLong();
144: }
145:
146: /**
147: * {@inheritDoc}
148: */
149: public int getSize() {
150: return PERFDATA_PROLOG_SIZE; // sizeof(struct PerfDataProlog)
151: }
152:
153: /**
154: * Return an IntBuffer that accesses the used value. This is used
155: * to create a Monitor object for this value.
156: *
157: * @return IntBuffer - a ByteBuffer that accesses the used value
158: * in the instrumentation buffer header.
159: * @see #getUsed()
160: */
161: public IntBuffer usedBuffer() {
162: byteBuffer.position(PERFDATA_PROLOG_USED_OFFSET);
163: IntBuffer ib = byteBuffer.asIntBuffer();
164: ib.limit(1);
165: return ib;
166: }
167:
168: /**
169: * Return an IntBuffer that accesses the size value. This is used
170: * to create a Monitor object for this value.
171: *
172: * @return IntBuffer - a ByteBuffer that accesses the size value
173: * in the instrumentation buffer header.
174: * @see #getBufferSize()
175: */
176: public IntBuffer sizeBuffer() {
177: IntBuffer ib = IntBuffer.allocate(1);
178: ib.put(byteBuffer.capacity());
179: return ib;
180: }
181:
182: /**
183: * Return an IntBuffer that accesses the overflow value. This is used
184: * to create a Monitor object for this value.
185: *
186: * @return IntBuffer - a ByteBuffer that accesses the overflow value
187: * in the instrumentation buffer header.
188: * @see #getOverflow()
189: */
190: public IntBuffer overflowBuffer() {
191: byteBuffer.position(PERFDATA_PROLOG_OVERFLOW_OFFSET);
192: IntBuffer ib = byteBuffer.asIntBuffer();
193: ib.limit(1);
194: return ib;
195: }
196:
197: /**
198: * Return an LongBuffer that accesses the modification timestamp value.
199: * This is used* to create a Monitor object for this value.
200: *
201: * @return LongBuffer - a ByteBuffer that accesses the modification time
202: * stamp value in the instrumentation buffer header.
203: * @see #getModificationTimeStamp()
204: */
205: public LongBuffer modificationTimeStampBuffer() {
206: byteBuffer.position(PERFDATA_PROLOG_MODTIMESTAMP_OFFSET);
207: LongBuffer lb = byteBuffer.asLongBuffer();
208: lb.limit(1);
209: return lb;
210: }
211: }
|