Interface ClassHierarchyResolver
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
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.
- See Java Virtual Machine Specification:
-
4.10.1.2 Verification Type System
- Since:
- 24
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceInformation about a resolved class. -
Method Summary
Modifier and TypeMethodDescriptiondefault ClassHierarchyResolvercached()Returns aClassHierarchyResolverthat caches class hierarchy information from this resolver.default ClassHierarchyResolvercached(Supplier<Map<ClassDesc, ClassHierarchyResolver.ClassHierarchyInfo>> cacheFactory) Returns aClassHierarchyResolverthat caches class hierarchy information from this resolver.static ClassHierarchyResolverReturns the default instance ofClassHierarchyResolverthat getsClassHierarchyResolver.ClassHierarchyInfofrom system class loader with reflection.getClassInfo(ClassDesc classDesc) Returns theClassHierarchyInfofor a given class name, ornullif the name is unknown to the resolver.static ClassHierarchyResolverReturns aClassHierarchyResolverthat extracts class hierarchy information from collections of class hierarchy metadata.static ClassHierarchyResolverofClassLoading(ClassLoader loader) Returns aClassHierarchyResolverthat extracts class hierarchy information via classes loaded by a class loader with reflection.static ClassHierarchyResolverofClassLoading(MethodHandles.Lookup lookup) Returns aClassHierarchyResolverthat extracts class hierarchy information via classes accessible to aMethodHandles.Lookupwith reflection.static ClassHierarchyResolverofResourceParsing(ClassLoader loader) Returns aClassHierarchyResolverthat extracts class hierarchy information fromclassfiles located by a class loader.static ClassHierarchyResolverofResourceParsing(Function<ClassDesc, InputStream> classStreamResolver) Returns aClassHierarchyResolverthat extracts class hierarchy information fromclassfiles returned by a mapping function.default ClassHierarchyResolverorElse(ClassHierarchyResolver other) Chains thisClassHierarchyResolverwith another to be consulted if this resolver does not know about the specified class.
-
Method Details
-
defaultResolver
Returns the default instance ofClassHierarchyResolverthat getsClassHierarchyResolver.ClassHierarchyInfofrom 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:
- the default instance of
ClassHierarchyResolverthat getsClassHierarchyResolver.ClassHierarchyInfofrom system class loader with reflection
-
getClassInfo
Returns theClassHierarchyInfofor a given class name, ornullif 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- descriptor of the class- Returns:
- the
ClassHierarchyInfofor a given class name, ornullif the name is unknown to the resolver - Throws:
IllegalArgumentException- if a class shouldn't be queried for hierarchy, such as when it is inaccessible
-
orElse
Chains thisClassHierarchyResolverwith another to be consulted if this resolver does not know about the specified class.- Implementation Requirements:
- The default implementation returns resolver implemented to query
otherresolver in case this resolver returnsnull. - Parameters:
other- the other resolver- Returns:
- the chained resolver
-
cached
default ClassHierarchyResolver cached(Supplier<Map<ClassDesc, ClassHierarchyResolver.ClassHierarchyInfo>> cacheFactory) Returns aClassHierarchyResolverthat 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 thecacheFactory.- Implementation Requirements:
- 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 anullthat indicates unknown class names. The cache map may refusenullkeys and values. - Parameters:
cacheFactory- the factory for the cache- Returns:
- a
ClassHierarchyResolverthat caches class hierarchy information from this resolver
-
cached
Returns aClassHierarchyResolverthat 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 = ...; ClassHierarchyResolver resolver = ClassHierarchyResolver.ofClassLoading(lookup).cached();- Implementation Requirements:
- The default implementation calls
cached(Supplier)withHashMapsupplier ascacheFactory. - Returns:
- a
ClassHierarchyResolverthat caches class hierarchy information from this resolver
-
ofResourceParsing
static ClassHierarchyResolver ofResourceParsing(Function<ClassDesc, InputStream> classStreamResolver) Returns aClassHierarchyResolverthat extracts class hierarchy information fromclassfiles returned by a mapping function. The mapping function should returnnullif it cannot provide aclassfile for a class name. AnyIOExceptionfrom the provided input stream is rethrown as anUncheckedIOExceptioningetClassInfo(ClassDesc).- Parameters:
classStreamResolver- maps class descriptors toclassfile input streams- Returns:
- a
ClassHierarchyResolverthat extracts class hierarchy information fromclassfiles returned by a mapping function
-
ofResourceParsing
Returns aClassHierarchyResolverthat extracts class hierarchy information fromclassfiles located by a class loader.- Parameters:
loader- the class loader, to find class files- Returns:
- a
ClassHierarchyResolverthat extracts class hierarchy information fromclassfiles located by a class loader
-
of
static ClassHierarchyResolver of(Collection<ClassDesc> interfaces, Map<ClassDesc, ClassDesc> classToSuperClass) Returns aClassHierarchyResolverthat extracts class hierarchy information from collections of class hierarchy metadata.- Parameters:
interfaces- a collection of classes known to be interfacesclassToSuperClass- a map from classes to their super classes- Returns:
- a
ClassHierarchyResolverthat extracts class hierarchy information from collections of class hierarchy metadata
-
ofClassLoading
Returns aClassHierarchyResolverthat extracts class hierarchy information via classes loaded by a class loader with reflection.- Parameters:
loader- the class loader- Returns:
- a
ClassHierarchyResolverthat extracts class hierarchy information via classes loaded by a class loader with reflection
-
ofClassLoading
Returns aClassHierarchyResolverthat extracts class hierarchy information via classes accessible to aMethodHandles.Lookupwith reflection. If the class resolved is inaccessible to the given lookup,getClassInfo(ClassDesc)throwsIllegalArgumentExceptioninstead of returningnull.- Parameters:
lookup- the lookup, must be able to access classes to resolve- Returns:
- a
ClassHierarchyResolverthat extracts class hierarchy information via classes accessible to aMethodHandles.Lookupwith reflection
-