Class BridgeBase
java.lang.Object
org.glassfish.pfl.basic.reflection.BridgeBase
- Direct Known Subclasses:
Bridge
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long
This constant differs from all results that will ever be returned fromobjectFieldOffset(java.lang.reflect.Field)
.private final sun.misc.Unsafe
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionClass
<?> defineClass
(Class<?> anchorClass, String className, byte[] classBytes) Defines a new class from bytecode.Class
<?> defineClass
(String className, byte[] classBytes, ClassLoader classLoader, ProtectionDomain protectionDomain) Deprecated.will not work in Java 11 or later.final void
ensureClassInitialized
(Class<?> cl) Ensure that the class has been initialized.final boolean
getBoolean
(Object o, long offset) final byte
final char
final double
final float
final int
Fetches a field element within the given objecto
at the given offset.abstract ClassLoader
Obtain the latest user defined ClassLoader from the call stack.final long
final <T> T
final short
abstract boolean
Returns true if the given class defines a static initializer method, false otherwise.abstract <T> Constructor
<?> Return a constructor that can be used to create an instance of the class for externalization.abstract <T> Constructor
<T> newConstructorForSerialization
(Class<T> aClass) Return a no-arg constructor for the specified class, based on the default constructor for its nearest non-serializable base class.abstract <T> Constructor
<T> newConstructorForSerialization
(Class<T> aClass, Constructor<?> cons) Return a no-arg constructor for the specified class which invokes the specified constructor.abstract OptionalDataException
newOptionalDataExceptionForSerialization
(boolean bool) Return a new OptionalDataException instance.final long
Returns the offset of a non-static field, which can be passed into the set...final void
putBoolean
(Object o, long offset, boolean x) final void
final void
final void
final void
final void
Stores a value into a given Java field.final void
final void
final void
abstract MethodHandle
readObjectForSerialization
(Class<?> cl) Returns a method handle to allow invocation of the specified class's readObject method.abstract MethodHandle
readResolveForSerialization
(Class<?> cl) Returns a method handle to allow invocation of the specified class's readResolve method.final long
final void
Throw the exception.toAccessibleField
(Field field, Class callingClass) Returns the specified field after calling setAccessible, if it is accessible from the specified class.toAccessibleMethod
(Method method, Class callingClass) Returns the specified method after calling setAccessible, if it is accessible from the specified class.abstract MethodHandle
writeObjectForSerialization
(Class<?> cl) Returns a method handle to allow invocation of the specified class's writeObject method.abstract MethodHandle
Returns a method handle to allow invocation of the specified class's writeReplace method.
-
Field Details
-
INVALID_FIELD_OFFSET
public static final long INVALID_FIELD_OFFSETThis constant differs from all results that will ever be returned fromobjectFieldOffset(java.lang.reflect.Field)
.- See Also:
-
unsafe
private final sun.misc.Unsafe unsafe
-
-
Constructor Details
-
BridgeBase
public BridgeBase()
-
-
Method Details
-
getInt
Fetches a field element within the given objecto
at the given offset. The result is undefined unless the offset was obtained fromobjectFieldOffset(java.lang.reflect.Field)
on theField
of some Java field and the object referred to byo
is of a class compatible with that field's class.- Parameters:
o
- Java heap object in which the field from which the offset was obtained residesoffset
- indication of where the field resides in a Java heap object- Returns:
- the value fetched from the indicated Java field
- Throws:
RuntimeException
- No defined exceptions are thrown, not evenNullPointerException
-
putInt
Stores a value into a given Java field.The first two parameters are interpreted exactly as with
getInt(Object, long)
to refer to a specific Java field. The given value is stored into that field.The field must be of the same type as the method parameter
x
.- Parameters:
o
- Java heap object in which the field resides, if any, else nulloffset
- indication of where the field resides in a Java heap object.x
- the value to store into the indicated Java field- Throws:
RuntimeException
- No defined exceptions are thrown, not evenNullPointerException
-
getObject
- See Also:
-
putObject
- See Also:
-
getBoolean
- See Also:
-
putBoolean
- See Also:
-
getByte
- See Also:
-
putByte
- See Also:
-
getShort
- See Also:
-
putShort
- See Also:
-
getChar
- See Also:
-
putChar
- See Also:
-
getLong
- See Also:
-
putLong
- See Also:
-
getFloat
- See Also:
-
putFloat
- See Also:
-
getDouble
- See Also:
-
putDouble
- See Also:
-
objectFieldOffset
Returns the offset of a non-static field, which can be passed into the set... or get... methods.- See Also:
-
staticFieldOffset
-
throwException
Throw the exception. The exception may be an undeclared checked exception. -
defineClass
@Deprecated public Class<?> defineClass(String className, byte[] classBytes, ClassLoader classLoader, ProtectionDomain protectionDomain) Deprecated.will not work in Java 11 or later. UsedefineClass(Class, String, byte[])
insteadDefines a class is a specified classloader.- Parameters:
className
- the name of the classclassBytes
- the byte code for the classclassLoader
- the classloader in which it is to be definedprotectionDomain
- the domain in which the class should be defined
-
defineClass
Defines a new class from bytecode. The class will be defined in the classloader and package associated with a specified 'anchor class'.- Parameters:
anchorClass
- the class from which the package and classloader of the new class are to be taken.className
- the name of the class to defineclassBytes
- the bytes used to define the class- Returns:
- a new instantiable class, in the package and classloader of the anchor class.
-
ensureClassInitialized
Ensure that the class has been initialized.- Parameters:
cl
- the class to ensure is initialized
-
getLatestUserDefinedLoader
Obtain the latest user defined ClassLoader from the call stack. This is required by the RMI-IIOP specification. -
newConstructorForExternalization
Return a constructor that can be used to create an instance of the class for externalization.- Parameters:
cl
- the class
-
newConstructorForSerialization
public abstract <T> Constructor<T> newConstructorForSerialization(Class<T> aClass, Constructor<?> cons) Return a no-arg constructor for the specified class which invokes the specified constructor.- Parameters:
aClass
- the class for which a constructor should be returned.cons
- the default constructor on which to model the new constructor.
-
newConstructorForSerialization
Return a no-arg constructor for the specified class, based on the default constructor for its nearest non-serializable base class.- Parameters:
aClass
- the class for which a constructor should be returned.
-
hasStaticInitializerForSerialization
Returns true if the given class defines a static initializer method, false otherwise. -
writeObjectForSerialization
public abstract MethodHandle writeObjectForSerialization(Class<?> cl) throws NoSuchMethodException, IllegalAccessException Returns a method handle to allow invocation of the specified class's writeObject method.- Parameters:
cl
- the class containing the method- Throws:
NoSuchMethodException
IllegalAccessException
-
readObjectForSerialization
public abstract MethodHandle readObjectForSerialization(Class<?> cl) throws NoSuchMethodException, IllegalAccessException Returns a method handle to allow invocation of the specified class's readObject method.- Parameters:
cl
- the class containing the method- Throws:
NoSuchMethodException
IllegalAccessException
-
readResolveForSerialization
Returns a method handle to allow invocation of the specified class's readResolve method.- Parameters:
cl
- the class containing the method
-
writeReplaceForSerialization
Returns a method handle to allow invocation of the specified class's writeReplace method.- Parameters:
cl
- the class containing the method
-
newOptionalDataExceptionForSerialization
Return a new OptionalDataException instance.- Returns:
- a new OptionalDataException instance
-
toAccessibleField
Returns the specified field after calling setAccessible, if it is accessible from the specified class.- Parameters:
field
- the field to make accessiblecallingClass
- the class which wants to access it.- Returns:
- the original field, rendered accessible, or null.
-
toAccessibleMethod
Returns the specified method after calling setAccessible, if it is accessible from the specified class.- Parameters:
method
- the method to make accessiblecallingClass
- the class which wants to access it.- Returns:
- the original method, rendered accessible, or null.
-