APIdia Launch Partner
Top Description Fields Constructors Methods
java.lang.runtime

public final Class ObjectMethods

extends Object
Class Inheritance
Imports
java.lang.classfile.ClassFile, .ClassHierarchyResolver, .Opcode, java.lang.constant.ClassDesc, .MethodTypeDesc, java.lang.invoke.ConstantCallSite, .MethodHandle, .MethodHandles, .MethodType, .StringConcatFactory, .TypeDescriptor, java.lang.reflect.Modifier, java.util.ArrayList, .Arrays, .HashMap, .List, .Objects

Bootstrap methods for state-driven implementations of core methods, including Object#equals(Object), Object#hashCode(), and Object#toString(). These methods may be used, for example, by Java compiler implementations to implement the bodies of Object methods for record classes.
Since
16

Field Summary

Modifier and TypeField and Description
private static final MethodHandle
private static final MethodHandle
private static final MethodHandle
private static final MethodHandle
private static final MethodHandle
private static final MethodHandle
private static final int
private static final MethodType
private static final MethodType
private static final MethodTypeDesc
private static final MethodTypeDesc
private static final MethodHandle
private static final HashMap<Class<?>, MethodHandle>
private static final HashMap<Class<?>, MethodHandle>
private static final MethodHandle
private static final MethodHandle

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Object

Returns:

a call site if invoked by indy, or a method handle if invoked by a condy
bootstrap
(MethodHandles.Lookup
the full-privilege lookup context of the caller
lookup
,
String
the name of the method to generate, which must be one of "equals", "hashCode", or "toString"
methodName
,
TypeDescriptor
a MethodType corresponding the descriptor type for the method, which must correspond to the descriptor for the corresponding Object method, if linking an invokedynamic call site, or the constant MethodHandle.class, if linking a dynamic constant
type
,
Class<?>
the record class hosting the record components
recordClass
,
String
the list of component names, joined into a string separated by ";", or the empty string if there are no components. This parameter is ignored if the methodName parameter is "equals" or "hashCode"
names
,
MethodHandle...
method handles for the accessor methods for the components
getters
)

Bootstrap method to generate the Object#equals(Object), Object#hashCode(), and Object#toString() methods, based on a description of the component names and accessor methods, for either invokedynamic call sites or dynamic constant pool entries.

private static boolean
private static boolean
eq(byte a, byte b)

private static boolean
eq(short a, short b)

private static boolean
eq(char a, char b)

private static boolean
eq(int a, int b)

private static boolean
eq(long a, long b)

private static boolean
eq(float a, float b)

private static boolean
eq(double a, double b)

private static boolean
eq(boolean a, boolean b)

private static MethodHandle
equalator(MethodHandles.Lookup lookup, Class<?> clazz)

Get the method handle for combining two values of a given type

private static int
hashCombiner(int x, int y)

private static MethodHandle
hasher(MethodHandles.Lookup lookup, Class<?> clazz)

Get the hasher for a value of a given type

private static boolean
private static MethodHandle

Returns:

the method handle
makeEquals
(MethodHandles.Lookup lookup, Class<?>
the data class
receiverClass
,
List<MethodHandle>
the list of getters
getters
)

Generates a method handle for the equals method for a given data class

private static MethodHandle

Returns:

the method handle
makeHashCode
(MethodHandles.Lookup lookup, Class<?>
the data class
receiverClass
,
List<MethodHandle>
the list of getters
getters
)

Generates a method handle for the hashCode method for a given data class

private static MethodHandle

Returns:

the method handle
makeToString
(MethodHandles.Lookup lookup, Class<?>
the data class
receiverClass
,
MethodHandle[]
the list of getters
getters
,
List<String>
the names
names
)

Generates a method handle for the toString method for a given data class

private static String
specializerClassName(Class<?> targetClass, String kind)

private static List<List<MethodHandle>>

Returns:

chunks that won't surpass the maximum number of slots StringConcatFactory::makeConcatWithConstants can chew
split
(MethodHandle[]
the current getters
getters
)

Chops the getters into smaller chunks according to the maximum number of slots StringConcatFactory::makeConcatWithConstants can chew

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CLASS_IS_INSTANCEback to summary
private static final MethodHandle CLASS_IS_INSTANCE
FALSEback to summary
private static final MethodHandle FALSE
HASH_COMBINERback to summary
private static final MethodHandle HASH_COMBINER
IS_ARG0_NULLback to summary
private static final MethodHandle IS_ARG0_NULL
IS_ARG1_NULLback to summary
private static final MethodHandle IS_ARG1_NULL
IS_NULLback to summary
private static final MethodHandle IS_NULL
MAX_STRING_CONCAT_SLOTSback to summary
private static final int MAX_STRING_CONCAT_SLOTS
MT_INTback to summary
private static final MethodType MT_INT
MT_OBJECT_BOOLEANback to summary
private static final MethodType MT_OBJECT_BOOLEAN
MTD_INTback to summary
private static final MethodTypeDesc MTD_INT
MTD_OBJECT_BOOLEANback to summary
private static final MethodTypeDesc MTD_OBJECT_BOOLEAN
OBJECT_EQback to summary
private static final MethodHandle OBJECT_EQ
primitiveEqualsback to summary
private static final HashMap<Class<?>, MethodHandle> primitiveEquals
primitiveHashersback to summary
private static final HashMap<Class<?>, MethodHandle> primitiveHashers
TRUEback to summary
private static final MethodHandle TRUE
ZEROback to summary
private static final MethodHandle ZERO

Constructor Detail

ObjectMethodsback to summary
private ObjectMethods()

Method Detail

bootstrapback to summary
public static Object bootstrap(MethodHandles.Lookup lookup, String methodName, TypeDescriptor type, Class<?> recordClass, String names, MethodHandle... getters) throws Throwable

Bootstrap method to generate the Object#equals(Object), Object#hashCode(), and Object#toString() methods, based on a description of the component names and accessor methods, for either invokedynamic call sites or dynamic constant pool entries. For more detail on the semantics of the generated methods see the specification of java.lang.Record#equals(Object), java.lang.Record#hashCode() and java.lang.Record#toString().

Parameters
lookup:MethodHandles.Lookup

the full-privilege lookup context of the caller

methodName:String

the name of the method to generate, which must be one of "equals", "hashCode", or "toString"

type:TypeDescriptor

a MethodType corresponding the descriptor type for the method, which must correspond to the descriptor for the corresponding Object method, if linking an invokedynamic call site, or the constant MethodHandle.class, if linking a dynamic constant

recordClass:Class<?>

the record class hosting the record components

names:String

the list of component names, joined into a string separated by ";", or the empty string if there are no components. This parameter is ignored if the methodName parameter is "equals" or "hashCode"

getters:MethodHandle[]

method handles for the accessor methods for the components

Returns:Object

a call site if invoked by indy, or a method handle if invoked by a condy

Exceptions
Throwable:
if any exception is thrown during call site construction
IllegalArgumentException:
if the bootstrap arguments are invalid or inconsistent
eqback to summary
private static boolean eq(Object a, Object b)
eqback to summary
private static boolean eq(byte a, byte b)
eqback to summary
private static boolean eq(short a, short b)
eqback to summary
private static boolean eq(char a, char b)
eqback to summary
private static boolean eq(int a, int b)
eqback to summary
private static boolean eq(long a, long b)
eqback to summary
private static boolean eq(float a, float b)
eqback to summary
private static boolean eq(double a, double b)
eqback to summary
private static boolean eq(boolean a, boolean b)
equalatorback to summary
private static MethodHandle equalator(MethodHandles.Lookup lookup, Class<?> clazz) throws Throwable

Get the method handle for combining two values of a given type

hashCombinerback to summary
private static int hashCombiner(int x, int y)
hasherback to summary
private static MethodHandle hasher(MethodHandles.Lookup lookup, Class<?> clazz) throws Throwable

Get the hasher for a value of a given type

isMonomorphicback to summary
private static boolean isMonomorphic(Class<?> type)
makeEqualsback to summary
private static MethodHandle makeEquals(MethodHandles.Lookup lookup, Class<?> receiverClass, List<MethodHandle> getters) throws Throwable

Generates a method handle for the equals method for a given data class

Parameters
receiverClass:Class<?>

the data class

getters:List<MethodHandle>

the list of getters

Returns:MethodHandle

the method handle

makeHashCodeback to summary
private static MethodHandle makeHashCode(MethodHandles.Lookup lookup, Class<?> receiverClass, List<MethodHandle> getters) throws Throwable

Generates a method handle for the hashCode method for a given data class

Parameters
receiverClass:Class<?>

the data class

getters:List<MethodHandle>

the list of getters

Returns:MethodHandle

the method handle

makeToStringback to summary
private static MethodHandle makeToString(MethodHandles.Lookup lookup, Class<?> receiverClass, MethodHandle[] getters, List<String> names)

Generates a method handle for the toString method for a given data class

Parameters
receiverClass:Class<?>

the data class

getters:MethodHandle[]

the list of getters

names:List<String>

the names

Returns:MethodHandle

the method handle

specializerClassNameback to summary
private static String specializerClassName(Class<?> targetClass, String kind)
splitback to summary
private static List<List<MethodHandle>> split(MethodHandle[] getters)

Chops the getters into smaller chunks according to the maximum number of slots StringConcatFactory::makeConcatWithConstants can chew

Parameters
getters:MethodHandle[]

the current getters

Returns:List<List<MethodHandle>>

chunks that won't surpass the maximum number of slots StringConcatFactory::makeConcatWithConstants can chew