/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Abstraction representing the HotSpot PerfData instrumentation buffer
* header. This class represents only the fixed portion of the header.
* Version specific classes represent the portion of the header that
* may change from release to release.
* <p>
* The PerfDataBufferProlog class supports parsing of the following
* C structure:
* <pre>
* typedef struct {
* jint magic; // magic number - 0xcafec0c0
* jbyte byte_order; // byte order of the buffer
* jbyte major_version; // major and minor version numbers
* jbyte minor_version;
* jbyte reserved_byte1; // reserved - see concrete implementations for
* // possible definition.
* ... // remainder is handled by the subclasses.
* } PerfDataPrologue
* </pre>
*
* @author Brian Doherty
* @since 1.5
*/
public abstract class AbstractPerfDataBufferPrologue {
/*
* the following constants must match the field offsets and sizes
* in the PerfDataPrologue structure in perfMemory.hpp
*/
// these constants should match their #define counterparts in perfMemory.hpp
// names for counters that expose the prolog fields
"sun.perfdata.majorVersion";
"sun.perfdata.minorVersion";
/**
* Construct a PerfDataBufferPrologue instance.
*
* @param byteBuffer buffer containing the instrumentation data
*/
throws MonitorException {
// the magic number is always stored in big-endian format
if (getMagic() != PERFDATA_MAGIC) {
throw new MonitorVersionException(
}
// set the byte order
}
/**
* Get the magic number.
*
* @return int - the magic number
*/
public int getMagic() {
// the magic number is always stored in big-endian format
// get the magic number
// restore the byte order
return magic;
}
/**
* Get the byte order.
*
* @return int - the byte order of the instrumentation buffer
*/
// byte order field is byte order independent
if (byte_order == PERFDATA_BIG_ENDIAN) {
return ByteOrder.BIG_ENDIAN;
} else {
return ByteOrder.LITTLE_ENDIAN;
}
}
/**
* Get the major version.
*
* @return int - the major version
*/
public int getMajorVersion() {
// major version field is byte order independent
return (int)byteBuffer.get();
}
/**
* Get the minor version.
*
* @return int - the minor version
*/
public int getMinorVersion() {
// minor version field is byte order independent
return (int)byteBuffer.get();
}
/**
* Get the accessible flag. If supported, it indicates that the shared
* memory region is sufficiently initialized for client acccess.
*
* @return boolean - the initialized status
* @see #supportsAccessible()
*/
public abstract boolean isAccessible();
/**
* Test if the accessible flag is supported by this version of
* the PerfDataBufferPrologue. Although not an abstract method, this
* method should be overridden by version specific subclasses.
*
* @return boolean - the initialized flag support status.
* @see #isAccessible()
*/
public abstract boolean supportsAccessible();
/**
* Get the size of the header portion of the instrumentation buffer.
*
* @return int - the size of the header
*/
public int getSize() {
return PERFDATA_PROLOG_SIZE; // sizeof(struct PerfDataProlog)
}
/**
* Return an IntBuffer that accesses the major version number.
* This is used to create a Monitor object for this value.
*
* @return IntBuffer - a ByteBuffer that accesses the major version number
* in the instrumentation buffer header.
*/
int[] holder = new int[1];
return ib;
}
/**
* Return an IntBuffer that accesses the minor version number.
* This is used to create a Monitor object for this value.
*
* @return IntBuffer - a ByteBuffer that accesses the minor version number
* in the instrumentation buffer header.
*/
int[] holder = new int[1];
return ib;
}
/**
* Get the magic number from the given byteBuffer.
*
* @return int - the magic number
*/
// save buffer state
// the magic number is always stored in big-endian format
// restore buffer state.
return magic;
}
/**
* Get the major version number from the given ByteBuffer.
*
* @return int - the major version
*/
// save buffer state
// restore buffer state.
return major;
}
/**
* Get the minor version number from the given ByteBuffer.
*
* @return int - the minor version
*/
// save buffer state
// restore buffer state.
return minor;
}
/**
* Get the byte order for the given ByteBuffer.
*
* @return int - the byte order of the instrumentation buffer
*/
// save buffer state
// restore buffer state.
return order;
}
}