APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.perf

public final Class Perf

extends Object
Class Inheritance
Imports
java.nio.ByteBuffer, java.io.IOException, sun.nio.cs.UTF_8, jdk.internal.ref.CleanerFactory

The Perf class provides the ability to attach to an instrumentation buffer maintained by a Java virtual machine. The instrumentation buffer may be for the Java virtual machine running the methods of this class or it may be for another Java virtual machine on the same system.

In addition, this class provides methods to create instrumentation objects in the instrumentation buffer for the Java virtual machine that is running these methods. It also contains methods for acquiring the value of a platform specific high resolution clock for time stamp and interval measurement purposes.

Author
Brian Doherty
Since
1.4.2
See Also
getPerf, java.nio.ByteBuffer

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static Perf

Constructor Summary

AccessConstructor and Description
private
Perf()

Method Summary

Modifier and TypeMethod and Description
public ByteBuffer

Returns:

ByteBuffer a direct allocated byte buffer
attach
(int
an integer that uniquely identifies the target local Java virtual machine.
lvmid
)

Attach to the instrumentation buffer for the specified Java virtual machine.

private native ByteBuffer

Returns:

ByteBuffer a direct allocated byte buffer
attach0
(int
an integer that uniquely identifies the target local Java virtual machine.
lvmid
)

Native method to perform the implementation specific attach mechanism.

public native ByteBuffer

Returns:

ByteBuffer a direct allocated byte buffer that allows write access to a native memory location containing a long value. see sun.misc.perf.Variability see sun.misc.perf.Units
createByteArray
(String
the name of this entry.
name
,
int
the variability characteristic for this entry.
variability
,
int
the units for this entry.
units
,
byte[]
the initial value for this entry.
value
,
int
the maximum length of this byte array.
maxLength
)

Create a byte vector entry in the instrumentation buffer with the given variability characteristic, units, and initial value.

public native ByteBuffer

Returns:

ByteBuffer a direct allocated ByteBuffer object that allows write access to a native memory location containing a long value. see sun.misc.perf.Variability see sun.misc.perf.Units
createLong
(String
the name of this entry.
name
,
int
the variability characteristic for this entry.
variability
,
int
the units for this entry.
units
,
long
the initial value for this entry.
value
)

Create a long scalar entry in the instrumentation buffer with the given variability characteristic, units, and initial value.

public ByteBuffer

Returns:

ByteBuffer a direct allocated ByteBuffer that allows write access to a native memory location containing a long value. see sun.misc.perf.Variability see sun.misc.perf.Units
createString
(String
the name of this entry.
name
,
int
the variability characteristic for this entry.
variability
,
int
the units for this entry.
units
,
String
the initial value for this entry.
value
,
int
the maximum string length for this string instrument.
maxLength
)

Create a String entry in the instrumentation buffer with the given variability characteristic, units, and initial value.

public ByteBuffer

Returns:

ByteBuffer a direct allocated ByteBuffer that allows write access to a native memory location containing a long value. see sun.misc.perf.Variability see sun.misc.perf.Units
createString
(String
the name of this entry.
name
,
int
the variability characteristic for this entry.
variability
,
int
the units for this entry.
units
,
String
the initial value for this entry.
value
)

Create a String entry in the instrumentation buffer with the given variability characteristic, units, and initial value.

private native void
detach(ByteBuffer
A direct allocated byte buffer created by the attach method.
bb
)

Native method to perform the implementation specific detach mechanism.

public static Perf

Returns:

A reference to the singleton Perf instance.
getPerf
()

Return a reference to the singleton Perf instance.

public native long

Returns:

the number of ticks of machine dependent resolution since the start of the Java virtual machine.
highResCounter
()

Return the value of the High Resolution Counter.

public native long

Returns:

the frequency of the High Resolution Counter.
highResFrequency
()

Returns the frequency of the High Resolution Counter, in ticks per second.

private static native void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

instanceback to summary
private static Perf instance

Constructor Detail

Perfback to summary
private Perf()

Method Detail

attachback to summary
public ByteBuffer attach(int lvmid) throws IOException

Attach to the instrumentation buffer for the specified Java virtual machine.

This method will attach to the instrumentation buffer for the specified virtual machine. It returns a ByteBuffer object that is initialized to access the instrumentation buffer for the indicated Java virtual machine. The lvmid parameter is a integer value that uniquely identifies the target local Java virtual machine. It is typically, but not necessarily, the process id of the target Java virtual machine.

If the lvmid identifies a Java virtual machine different from the one running this method, then the coherency characteristics of the buffer are implementation dependent. Implementations that do not support named, coherent, shared memory may return a ByteBuffer object that contains only a snap shot of the data in the instrumentation buffer. Implementations that support named, coherent, shared memory, may return a ByteBuffer object that will be changing dynamically over time as the target Java virtual machine updates its mapping of this buffer.

If the lvmid is 0 or equal to the actual lvmid for the Java virtual machine running this method, then the returned ByteBuffer object will always be coherent and dynamically changing.

Parameters
lvmid:int

an integer that uniquely identifies the target local Java virtual machine.

Returns:ByteBuffer

ByteBuffer a direct allocated byte buffer

Exceptions
IOException:
An I/O error occurred while trying to acquire the instrumentation buffer.
IllegalArgumentException:
The lvmid was invalid.
OutOfMemoryError:
The instrumentation buffer could not be mapped into the virtual machine's address space.
See Also
java.nio.ByteBuffer
attach0back to summary
private native ByteBuffer attach0(int lvmid) throws IOException

Native method to perform the implementation specific attach mechanism.

The implementation of this method may return distinct or identical ByteBuffer objects for two distinct calls requesting attachment to the same Java virtual machine.

For the Sun HotSpot JVM, two distinct calls to attach to the same target Java virtual machine will result in two distinct ByteBuffer objects returned by this method. This may change in a future release.

Parameters
lvmid:int

an integer that uniquely identifies the target local Java virtual machine.

Returns:ByteBuffer

ByteBuffer a direct allocated byte buffer

Exceptions
IOException:
An I/O error occurred while trying to acquire the instrumentation buffer.
IllegalArgumentException:
The lvmid was invalid.
OutOfMemoryError:
The instrumentation buffer could not be mapped into the virtual machine's address space.
createByteArrayback to summary
public native ByteBuffer createByteArray(String name, int variability, int units, byte[] value, int maxLength)

Create a byte vector entry in the instrumentation buffer with the given variability characteristic, units, and initial value.

The maxLength parameter limits the size of the byte array instrument such that the initial or subsequent updates beyond this length are silently ignored. No special handling of truncated updates is provided.

The underlying implementation may further limit the length of the length of the initial or subsequent value.

Access to the instrument is provided through the returned ByteBuffer object.

Parameters
name:String

the name of this entry.

variability:int

the variability characteristic for this entry.

units:int

the units for this entry.

value:byte[]

the initial value for this entry.

maxLength:int

the maximum length of this byte array.

Returns:ByteBuffer

ByteBuffer a direct allocated byte buffer that allows write access to a native memory location containing a long value. see sun.misc.perf.Variability see sun.misc.perf.Units

See Also
java.nio.ByteBuffer
createLongback to summary
public native ByteBuffer createLong(String name, int variability, int units, long value)

Create a long scalar entry in the instrumentation buffer with the given variability characteristic, units, and initial value.

Access to the instrument is provided through the returned ByteBuffer object. Typically, this object should be wrapped with LongBuffer view object.

Parameters
name:String

the name of this entry.

variability:int

the variability characteristic for this entry.

units:int

the units for this entry.

value:long

the initial value for this entry.

Returns:ByteBuffer

ByteBuffer a direct allocated ByteBuffer object that allows write access to a native memory location containing a long value. see sun.misc.perf.Variability see sun.misc.perf.Units

See Also
java.nio.ByteBuffer
createStringback to summary
public ByteBuffer createString(String name, int variability, int units, String value, int maxLength)

Create a String entry in the instrumentation buffer with the given variability characteristic, units, and initial value.

The maximum length of the String stored in this string instrument is given in by maxLength parameter. Updates to this instrument with String values with lengths greater than maxLength will be truncated to maxLength. The truncated value will be terminated by a null character.

The underlying implementation may further limit the length of the value, but will continue to preserve the null terminator.

Access to the instrument is provided through the returned ByteBuffer object.

Parameters
name:String

the name of this entry.

variability:int

the variability characteristic for this entry.

units:int

the units for this entry.

value:String

the initial value for this entry.

maxLength:int

the maximum string length for this string instrument.

Returns:ByteBuffer

ByteBuffer a direct allocated ByteBuffer that allows write access to a native memory location containing a long value. see sun.misc.perf.Variability see sun.misc.perf.Units

See Also
java.nio.ByteBuffer
createStringback to summary
public ByteBuffer createString(String name, int variability, int units, String value)

Create a String entry in the instrumentation buffer with the given variability characteristic, units, and initial value.

The maximum length of the String stored in this string instrument is implied by the length of the value parameter. Subsequent updates to the value of this instrument will be truncated to this implied maximum length. The truncated value will be terminated by a null character.

The underlying implementation may further limit the length of the initial or subsequent value, but will continue to preserve the null terminator.

Access to the instrument is provided through the returned ByteBuffer object.

Parameters
name:String

the name of this entry.

variability:int

the variability characteristic for this entry.

units:int

the units for this entry.

value:String

the initial value for this entry.

Returns:ByteBuffer

ByteBuffer a direct allocated ByteBuffer that allows write access to a native memory location containing a long value. see sun.misc.perf.Variability see sun.misc.perf.Units

See Also
java.nio.ByteBuffer
detachback to summary
private native void detach(ByteBuffer bb)

Native method to perform the implementation specific detach mechanism.

If this method is passed a ByteBuffer object that is not created by the attach method, then the results of this method are undefined, with unpredictable and potentially damaging effects to the Java virtual machine. To prevent accidental or malicious use of this method, all native ByteBuffer created by the attach method are managed internally as PhantomReferences and resources are freed by the system.

If this method is passed a ByteBuffer object created by the attach method with a lvmid for the Java virtual machine running this method (lvmid=0, for example), then the detach request is silently ignored.

Parameters
bb:ByteBuffer

A direct allocated byte buffer created by the attach method.

See Also
java.nio.ByteBuffer, attach
getPerfback to summary
public static Perf getPerf()

Return a reference to the singleton Perf instance.

The getPerf() method returns the singleton instance of the Perf class. The returned object provides the caller with the capability for accessing the instrumentation buffer for this or another local Java virtual machine.

Access to the returned Perf object should be protected by its caller and not passed on to untrusted code. This object can be used to attach to the instrumentation buffer provided by this Java virtual machine or for those of other Java virtual machines running on the same system. The instrumentation buffer may contain senstitive information. API's built on top of this interface may want to provide finer grained access control to the contents of individual instrumentation objects contained within the buffer.

Returns:Perf

A reference to the singleton Perf instance.

See Also
attach
highResCounterback to summary
public native long highResCounter()

Return the value of the High Resolution Counter. The High Resolution Counter returns the number of ticks since since the start of the Java virtual machine. The resolution of the counter is machine dependent and can be determined from the value return by the highResFrequency method.

Returns:long

the number of ticks of machine dependent resolution since the start of the Java virtual machine.

See Also
highResFrequency, java.lang.System#currentTimeMillis()
highResFrequencyback to summary
public native long highResFrequency()

Returns the frequency of the High Resolution Counter, in ticks per second. This value can be used to convert the value of the High Resolution Counter, as returned from a call to the highResCounter method, into the number of seconds since the start of the Java virtual machine.

Returns:long

the frequency of the High Resolution Counter.

See Also
highResCounter
registerNativesback to summary
private static native void registerNatives()
jdk.internal.perf back to summary

private Class Perf.CleanerAction

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Field Summary

Modifier and TypeField and Description
private final ByteBuffer
private final Perf

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bbback to summary
private final ByteBuffer bb
perfback to summary
private final Perf perf

Constructor Detail

CleanerActionback to summary
pack-priv CleanerAction(Perf perf, ByteBuffer bb)

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.