APIdia Launch Partner
Top Description Inners Methods
java.lang.classfile

public Interface ClassHierarchyResolver

Known Direct Implementers
jdk.internal.classfile.impl.ClassHierarchyImpl.CachedClassHierarchyResolver, jdk.internal.classfile.impl.ClassHierarchyImpl.ResourceParsingClassHierarchyResolver, jdk.internal.classfile.impl.ClassHierarchyImpl.StaticClassHierarchyResolver, jdk.internal.classfile.impl.ClassHierarchyImpl.ClassLoadingClassHierarchyResolver
Annotations
@FunctionalInterface
Imports
java.io.IOException, .InputStream, .UncheckedIOException, java.lang.classfile.ClassFile.StackMapsOption, java.lang.classfile.attribute.StackMapTableAttribute, java.lang.constant.ClassDesc, java.lang.invoke.MethodHandles, java.util.Collection, .HashMap, .Map, java.util.function.Function, .Supplier, jdk.internal.classfile.impl.ClassHierarchyImpl, .ClassHierarchyImpl.ClassLoadingClassHierarchyResolver, .ClassHierarchyImpl.StaticClassHierarchyResolver, .Util

Provides class hierarchy information for stack maps generation and verification. A class hierarchy resolver must be able to process all classes and interfaces encountered during these workloads.
Since
24
Java Virtual Machine Specification
4.10.1.2 Verification Type System
See Also
ClassFile.ClassHierarchyResolverOption, StackMapTableAttribute

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ClassHierarchyResolver.ClassHierarchyInfo

Information about a resolved class.

Method Summary

Modifier and TypeMethod and Description
public default ClassHierarchyResolver

Returns:

a ClassHierarchyResolver that caches class hierarchy information from this resolver
cached
(Supplier<Map<ClassDesc, ClassHierarchyResolver.ClassHierarchyInfo>>
the factory for the cache
cacheFactory
)

Returns a ClassHierarchyResolver that caches class hierarchy information from this resolver.

public default ClassHierarchyResolver

Returns:

a ClassHierarchyResolver that caches class hierarchy information from this resolver
cached
()

Returns a ClassHierarchyResolver that caches class hierarchy information from this resolver.

public static ClassHierarchyResolver

Returns:

the default instance of ClassHierarchyResolver that gets ClassHierarchyInfo from system class loader with reflection
defaultResolver
()

Returns the default instance of ClassHierarchyResolver that gets ClassHierarchyInfo from system class loader with reflection.

public ClassHierarchyResolver.ClassHierarchyInfo

Returns:

the ClassHierarchyInfo for a given class name, or null if the name is unknown to the resolver
getClassInfo
(ClassDesc
descriptor of the class
classDesc
)

Returns the ClassHierarchyInfo for a given class name, or null if the name is unknown to the resolver.

public static ClassHierarchyResolver

Returns:

a ClassHierarchyResolver that extracts class hierarchy information from collections of class hierarchy metadata
of
(Collection<ClassDesc>
a collection of classes known to be interfaces
interfaces
,
Map<ClassDesc, ClassDesc>
a map from classes to their super classes
classToSuperClass
)

Returns a ClassHierarchyResolver that extracts class hierarchy information from collections of class hierarchy metadata.

public static ClassHierarchyResolver

Returns:

a ClassHierarchyResolver that extracts class hierarchy information via classes loaded by a class loader with reflection
ofClassLoading
(ClassLoader
the class loader
loader
)

Returns a ClassHierarchyResolver that extracts class hierarchy information via classes loaded by a class loader with reflection.

public static ClassHierarchyResolver

Returns:

a ClassHierarchyResolver that extracts class hierarchy information via classes accessible to a MethodHandles.Lookup with reflection
ofClassLoading
(MethodHandles.Lookup
the lookup, must be able to access classes to resolve
lookup
)

Returns a ClassHierarchyResolver that extracts class hierarchy information via classes accessible to a MethodHandles.Lookup with reflection.

public static ClassHierarchyResolver

Returns:

a ClassHierarchyResolver that extracts class hierarchy information from class files returned by a mapping function
ofResourceParsing
(Function<ClassDesc, InputStream>
maps class descriptors to class file input streams
classStreamResolver
)

Returns a ClassHierarchyResolver that extracts class hierarchy information from class files returned by a mapping function.

public static ClassHierarchyResolver

Returns:

a ClassHierarchyResolver that extracts class hierarchy information from class files located by a class loader
ofResourceParsing
(ClassLoader
the class loader, to find class files
loader
)

Returns a ClassHierarchyResolver that extracts class hierarchy information from class files located by a class loader.

public default ClassHierarchyResolver

Returns:

the chained resolver
orElse
(ClassHierarchyResolver
the other resolver
other
)

Chains this ClassHierarchyResolver with another to be consulted if this resolver does not know about the specified class.

Method Detail

cachedback to summary
public default ClassHierarchyResolver cached(Supplier<Map<ClassDesc, ClassHierarchyResolver.ClassHierarchyInfo>> cacheFactory)

Returns a ClassHierarchyResolver that caches class hierarchy information from this resolver. The returned resolver will not update if the query results from this resolver changed over time. The thread safety of the returned resolver depends on the thread safety of the map returned by the cacheFactory.

Implementation Specification

The default implementation returns a resolver holding an instance of the cache map provided by the cacheFactory. It looks up in the cache map, or if a class name has not yet been queried, queries this resolver and caches the result, including a null that indicates unknown class names. The cache map may refuse null keys and values.

Parameters
cacheFactory:Supplier<Map<ClassDesc, ClassHierarchyResolver.ClassHierarchyInfo>>

the factory for the cache

Returns:ClassHierarchyResolver

a ClassHierarchyResolver that caches class hierarchy information from this resolver

cachedback to summary
public default ClassHierarchyResolver cached()

Returns a ClassHierarchyResolver that caches class hierarchy information from this resolver. The returned resolver will not update if the query results from this resolver changed over time. The returned resolver is not thread-safe.

MethodHandles.Lookup lookup = MethodHandles.lookup(); ClassHierarchyResolver resolver = ClassHierarchyResolver.ofClassLoading(lookup).cached();
MethodHandles.Lookup lookup = ...;
ClassHierarchyResolver resolver = ClassHierarchyResolver.ofClassLoading(lookup).cached();

Implementation Specification

The default implementation calls cached(Supplier) with HashMap supplier as cacheFactory.

Returns:ClassHierarchyResolver

a ClassHierarchyResolver that caches class hierarchy information from this resolver

defaultResolverback to summary
public static ClassHierarchyResolver defaultResolver()

Returns the default instance of ClassHierarchyResolver that gets ClassHierarchyInfo from system class loader with reflection. This default instance cannot load classes from other class loaders, such as the caller's class loader; it also loads the system classes if they are not yet loaded, which makes it unsuitable for instrumentation.

Returns:ClassHierarchyResolver

the default instance of ClassHierarchyResolver that gets ClassHierarchyInfo from system class loader with reflection

getClassInfoback to summary
public ClassHierarchyResolver.ClassHierarchyInfo getClassInfo(ClassDesc classDesc)

Returns the ClassHierarchyInfo for a given class name, or null if the name is unknown to the resolver.

This method is called by the Class-File API to obtain the hierarchy information of a class or interface; users should not call this method. The symbolic descriptor passed by the Class-File API always represents a class or interface.

Parameters
classDesc:ClassDesc

descriptor of the class

Returns:ClassHierarchyResolver.ClassHierarchyInfo

the ClassHierarchyInfo for a given class name, or null if the name is unknown to the resolver

Exceptions
IllegalArgumentException:
if a class shouldn't be queried for hierarchy, such as when it is inaccessible
ofback to summary
public static ClassHierarchyResolver of(Collection<ClassDesc> interfaces, Map<ClassDesc, ClassDesc> classToSuperClass)

Returns a ClassHierarchyResolver that extracts class hierarchy information from collections of class hierarchy metadata.

Parameters
interfaces:Collection<ClassDesc>

a collection of classes known to be interfaces

classToSuperClass:Map<ClassDesc, ClassDesc>

a map from classes to their super classes

Returns:ClassHierarchyResolver

a ClassHierarchyResolver that extracts class hierarchy information from collections of class hierarchy metadata

ofClassLoadingback to summary
public static ClassHierarchyResolver ofClassLoading(ClassLoader loader)

Returns a ClassHierarchyResolver that extracts class hierarchy information via classes loaded by a class loader with reflection.

Parameters
loader:ClassLoader

the class loader

Returns:ClassHierarchyResolver

a ClassHierarchyResolver that extracts class hierarchy information via classes loaded by a class loader with reflection

ofClassLoadingback to summary
public static ClassHierarchyResolver ofClassLoading(MethodHandles.Lookup lookup)

Returns a ClassHierarchyResolver that extracts class hierarchy information via classes accessible to a MethodHandles.Lookup with reflection. If the class resolved is inaccessible to the given lookup, getClassInfo(ClassDesc) throws IllegalArgumentException instead of returning null.

Parameters
lookup:MethodHandles.Lookup

the lookup, must be able to access classes to resolve

Returns:ClassHierarchyResolver

a ClassHierarchyResolver that extracts class hierarchy information via classes accessible to a MethodHandles.Lookup with reflection

ofResourceParsingback to summary
public static ClassHierarchyResolver ofResourceParsing(Function<ClassDesc, InputStream> classStreamResolver)

Returns a ClassHierarchyResolver that extracts class hierarchy information from class files returned by a mapping function. The mapping function should return null if it cannot provide a class file for a class name. Any IOException from the provided input stream is rethrown as an UncheckedIOException in getClassInfo(ClassDesc).

Parameters
classStreamResolver:Function<ClassDesc, InputStream>

maps class descriptors to class file input streams

Returns:ClassHierarchyResolver

a ClassHierarchyResolver that extracts class hierarchy information from class files returned by a mapping function

ofResourceParsingback to summary
public static ClassHierarchyResolver ofResourceParsing(ClassLoader loader)

Returns a ClassHierarchyResolver that extracts class hierarchy information from class files located by a class loader.

Parameters
loader:ClassLoader

the class loader, to find class files

Returns:ClassHierarchyResolver

a ClassHierarchyResolver that extracts class hierarchy information from class files located by a class loader

orElseback to summary
public default ClassHierarchyResolver orElse(ClassHierarchyResolver other)

Chains this ClassHierarchyResolver with another to be consulted if this resolver does not know about the specified class.

Implementation Specification

The default implementation returns resolver implemented to query other resolver in case this resolver returns null.

Parameters
other:ClassHierarchyResolver

the other resolver

Returns:ClassHierarchyResolver

the chained resolver

java.lang.classfile back to summary

public sealed Interface ClassHierarchyResolver.ClassHierarchyInfo

permits ClassHierarchyInfoImpl
Known Direct Implementers
jdk.internal.classfile.impl.ClassHierarchyImpl.ClassHierarchyInfoImpl

Information about a resolved class.
Since
24

Method Summary

Modifier and TypeMethod and Description
public static ClassHierarchyResolver.ClassHierarchyInfo

Returns:

the info indicating the super class
ofClass
(ClassDesc
descriptor of the super class, may be null
superClass
)

Indicates that a class is a declared class, with the specific given super class.

public static ClassHierarchyResolver.ClassHierarchyInfo

Returns:

the info indicating an interface
ofInterface
()

Indicates that a class is an interface.

Method Detail

ofClassback to summary
public static ClassHierarchyResolver.ClassHierarchyInfo ofClass(ClassDesc superClass)

Indicates that a class is a declared class, with the specific given super class.

Parameters
superClass:ClassDesc

descriptor of the super class, may be null

Returns:ClassHierarchyResolver.ClassHierarchyInfo

the info indicating the super class

See Also
Superclass
ofInterfaceback to summary
public static ClassHierarchyResolver.ClassHierarchyInfo ofInterface()

Indicates that a class is an interface.

Returns:ClassHierarchyResolver.ClassHierarchyInfo

the info indicating an interface