Package org.apache.uima.cas.impl
Class FSClassRegistry
- java.lang.Object
-
- org.apache.uima.cas.impl.FSClassRegistry
-
public abstract class FSClassRegistry extends java.lang.Object
There is one **class** instance of this per UIMA core class loader. The class loader is the loader for the UIMA core classes, not any UIMA extension class loader - **Builtin** JCas Types are loaded and shared among all type systems, once, when this class is loaded. There are no instances of this class. - The type system impl instances at commit time initialize parts of their Impl from data in this class - Some of the data kept in this class in static values, is constructed when the type system is committed The class instance is shared - by multiple type systems - by multiple CASes (in a CAS pool, for instance, when these CASes are sharing the same type system). - by all views of those CASes. - by multiple different pipelines, built using the same merged type system instance - by non-built-in JCas classes, loaded under possibly different extension class loaders PEAR support Multiple PEAR contexts can be used. - hierarchy (each is parent of kind below -- UIMA core class loader (built-ins, not redefinable by user JCas classes) --- a new limitation of UIMA V3 to allow sharing of built-in JCas classes, which also have custom impl, and don't fit the model used for PEAR Trampolines -- outer (non Pear) class loader (optional, known as base extension class loader) --- possible multiple, for different AE pipelines -- Within PEAR class loader - when running within a PEAR, operations which return Feature Structures potentially return JCas instances of classes loaded from the Pear's class loader. - These instances share the same int[] and Object[] and _typeImpl and _casView refs with the outer class loader's FS Timing / life cycle Built-in classes loaded and initialized at first type system commit time. non-pear classes loaded and initialized at type system commit time (if not already loaded) - special checks for conformability if some types loaded later, due to requirements for computing feature offsets at load time pear classes loaded and initialized at first entry to Pear, for a given type system and class loader. At typeSystemCommit time, this class is created and initialized: - The built-in JCas types are loaded - The user-defined non-PEAR JCas classes are loaded (not lazy, but eager), provided the type system is a new one. (If the type system is "equal" to an existing committed one, that one is used instead). -- User classes defined with the name of UIMA types, but which are not JCas definitions, are not used as JCas types. This permits uses cases where users define a class which (perhaps at a later integration time) has the same name as a UIMA type, but is not a JCas class. -- These classes, once loaded, remain loaded because of Java's design, unless the ClassLoader used to load them is Garbage Collected. --- The ClassLoader used is the CAS's JCasClassLoader, set from the UIMA Extension class loader if specified. Assigning slots for features: - each type being loaded runs static final initializers to set for (a subset of) all features the offset in the int or ref storage arrays for those values. - These call a static method in JCasRegistry: register[Int/Ref]Feature, which assigns the next available slot via accessing/updating a thread local instance of TypeSystemImpl.SlotAllocate.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FSClassRegistry.ErrorReport
(package private) static class
FSClassRegistry.JCasClassFeatureInfo
Information about all features this JCas class defines Used to expand the type system when the JCas defines more features than the type system declares.static class
FSClassRegistry.JCasClassInfo
One instance per JCas class defined for it, per class loader - per class loader, because different JCas class definitions for the same name are possible, per class loader Kept in maps, per class loader.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.invoke.MethodType
callsiteFsGenerator
The callsite has the return type, followed by capture argumentsprivate static WeakIdentityMap<java.lang.ClassLoader,java.util.Map<java.lang.String,java.lang.Class<? extends TOP>>>
cl_to_spiJCas
private static WeakIdentityMap<java.lang.ClassLoader,java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo>>
cl_to_type2JCas
Map from class loaders used to load JCas Classes, both PEAR and non-Pear cases, to JCasClassInfo for that loaded JCas class instance.private static WeakIdentityMap<java.lang.ClassLoader,java.lang.StackTraceElement[]>
cl_to_type2JCasStacks
private static WeakIdentityMap<java.lang.ClassLoader,UIMAClassLoader>
cl_to_uimaCl
private static java.lang.invoke.MethodHandles.Lookup
defaultLookup
private static java.lang.ThreadLocal<java.util.List<FSClassRegistry.ErrorReport>>
errorSet
private static java.lang.invoke.MethodType
findConstructorJCasCoverType
private static java.lang.invoke.MethodType
fsGeneratorType
(package private) static boolean
IS_LOG_JCAS_CLASSLOADERS_ON_SHUTDOWN
(package private) static boolean
IS_RECORD_JCAS_CLASSLOADERS
private static FSClassRegistry.JCasClassInfo[]
jcasClassesInfoForBuiltins
precomputed generators for built-in types These instances are shared for all type systems Key = index = typecode(package private) static java.lang.String
LOG_JCAS_CLASSLOADERS_ON_SHUTDOWN
private static java.util.List<java.lang.invoke.MethodHandle>
methodHandlesForInt
a cache for constant int method handlesprivate static java.net.URL[]
NO_URLS
(package private) static java.lang.String
RECORD_JCAS_CLASSLOADERS
-
Constructor Summary
Constructors Constructor Description FSClassRegistry()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static void
add2errors(java.lang.ThreadLocal<java.util.List<FSClassRegistry.ErrorReport>> errors, java.lang.Exception e)
private static void
add2errors(java.lang.ThreadLocal<java.util.List<FSClassRegistry.ErrorReport>> errors, java.lang.Exception e, boolean doThrow)
private static void
checkConformance(java.lang.Class<?> clazz, TypeSystemImpl tsi, TypeImpl ti, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> type2jcci)
Inner check Never called for "built-ins", or for uima types not having a JCas loaded class Checks that a JCas class definition conforms to the current type in the current type system.(package private) static void
checkConformance(java.lang.ClassLoader cl, TypeSystemImpl ts)
private static void
checkConformance(TypeSystemImpl ts, TypeImpl ti, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> type2jcci)
(package private) static int
clToType2JCasSize()
private static boolean
compare_C_T(java.lang.Class<?> clazz, TypeImpl ti)
private static FsGenerator3
createGenerator(java.lang.Class<?> jcasClass, java.lang.invoke.MethodHandles.Lookup lookup)
Return a Functional Interface for a generator for creating instances of a type.private static FSClassRegistry.JCasClassInfo
createJCasClassInfo(java.lang.Class<? extends TOP> jcasClass, TypeImpl ti, int jcasType, java.lang.invoke.MethodHandles.Lookup lookup)
Called after succeeding at loading, once per load for an exact matching JCas Class - class was already checked to insure is of proper type for JCas - skips creating-generator-for-Sofa - since "new Sofa(...)" is not a valid way to create a sofastatic FSClassRegistry.JCasClassInfo
createJCasClassInfo(TypeImpl ti, java.lang.ClassLoader cl, java.lang.invoke.MethodHandles.Lookup lookup)
(package private) static java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo>
get_className_to_jcci(java.lang.ClassLoader cl, boolean is_pear)
private static java.lang.String
getAllSuperclassNames(java.lang.Class<?> clazz)
private static java.lang.String
getAllSuperTypeNames(TypeImpl ti)
(package private) static java.lang.invoke.MethodHandle
getConstantIntMethodHandle(int i)
(package private) static FsGenerator3[]
getGeneratorsForClassLoader(java.lang.ClassLoader cl, boolean isPear, TypeSystemImpl tsi)
called infrequently to set up cache Only called when a type system has not had generators for a particular class loader.private static void
getGeneratorsForTypeAndSubtypes(TypeImpl ti, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> t2jcci, boolean isPear, java.lang.ClassLoader cl, FsGenerator3[] r, TypeSystemImpl tsi)
private static FSClassRegistry.JCasClassFeatureInfo[]
getJCasClassFeatureInfo(java.lang.Class<?> jcasClass)
(package private) static java.lang.invoke.MethodHandles.Lookup
getLookup(java.lang.ClassLoader cl)
static FSClassRegistry.JCasClassInfo
getOrCreateJCasClassInfo(TypeImpl ti, java.lang.ClassLoader cl, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> type2jcci, java.lang.invoke.MethodHandles.Lookup lookup)
For a particular type name, get the JCasClassInfo - by fetching the cached value - by loading the class - return null if no JCas class for this name only called for non-Pear callersprivate static boolean
isAllNull(FsGenerator3[] r)
private static void
loadBuiltins(TypeImpl ti, java.lang.ClassLoader cl, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> type2jcci, java.util.ArrayList<java.lang.invoke.MutableCallSite> callSites_toSync)
(package private) static java.util.Map<java.lang.String,java.lang.Class<? extends TOP>>
loadJCasClassesFromSPI(java.lang.ClassLoader cl)
private static void
loadJCasForTSandClassLoader(TypeSystemImpl ts, boolean isDoUserJCasLoading, java.lang.ClassLoader cl, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> type2jcci)
Load JCas types for some combination of class loader and type system Some of these classes may have already been loaded for this type system Some of these classes may have already been loaded (perhaps for another type system)static void
log_registered_classloaders(Level aLogLevel)
For internal use only!(package private) static FSClassRegistry.JCasClassInfo
maybeCreateJCasClassInfo(TypeImpl ti, java.lang.ClassLoader cl, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> type2jcci, java.lang.invoke.MethodHandles.Lookup lookup)
private static void
maybeLoadJCasAndSubtypes(TypeSystemImpl tsi, TypeImpl ti, FSClassRegistry.JCasClassInfo copyDownDefault_jcasClassInfo, java.lang.ClassLoader cl, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> type2jcci, java.util.ArrayList<java.lang.invoke.MutableCallSite> callSites_toSync, java.lang.invoke.MethodHandles.Lookup lookup)
Called for all the types, including the built-ins, but the built-ins have already been set up by the caller.private static java.lang.Class<? extends TOP>
maybeLoadLocalJCas(TypeImpl ti, java.lang.ClassLoader cl)
Called to load (if possible) a corresponding JCas class for a UIMA type.private static void
reportErrors()
private static void
setTypeFromJCasIDforBuiltIns(FSClassRegistry.JCasClassInfo jcci, TypeSystemImpl tsi, int typeCode)
static void
unregister_jcci_classloader(java.lang.ClassLoader cl)
For internal use only!private static void
updateOrValidateAllCallSitesForJCasClass(java.lang.Class<? extends TOP> clazz, TypeImpl type, java.util.ArrayList<java.lang.invoke.MutableCallSite> callSites_toSync)
Called once when the JCasClassInfo is created.private static void
validateSuperClass(FSClassRegistry.JCasClassInfo jcci, TypeImpl ti)
Changed https://issues.apache.org/jira/browse/UIMA-5660 to allow insertions of extra types/ classes into the superchain.
-
-
-
Field Detail
-
RECORD_JCAS_CLASSLOADERS
static final java.lang.String RECORD_JCAS_CLASSLOADERS
- See Also:
- Constant Field Values
-
IS_RECORD_JCAS_CLASSLOADERS
static final boolean IS_RECORD_JCAS_CLASSLOADERS
-
LOG_JCAS_CLASSLOADERS_ON_SHUTDOWN
static final java.lang.String LOG_JCAS_CLASSLOADERS_ON_SHUTDOWN
- See Also:
- Constant Field Values
-
IS_LOG_JCAS_CLASSLOADERS_ON_SHUTDOWN
static final boolean IS_LOG_JCAS_CLASSLOADERS_ON_SHUTDOWN
-
defaultLookup
private static final java.lang.invoke.MethodHandles.Lookup defaultLookup
-
findConstructorJCasCoverType
private static final java.lang.invoke.MethodType findConstructorJCasCoverType
-
callsiteFsGenerator
private static final java.lang.invoke.MethodType callsiteFsGenerator
The callsite has the return type, followed by capture arguments
-
fsGeneratorType
private static final java.lang.invoke.MethodType fsGeneratorType
-
jcasClassesInfoForBuiltins
private static final FSClassRegistry.JCasClassInfo[] jcasClassesInfoForBuiltins
precomputed generators for built-in types These instances are shared for all type systems Key = index = typecode
-
methodHandlesForInt
private static final java.util.List<java.lang.invoke.MethodHandle> methodHandlesForInt
a cache for constant int method handles
-
cl_to_type2JCas
private static final WeakIdentityMap<java.lang.ClassLoader,java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo>> cl_to_type2JCas
Map from class loaders used to load JCas Classes, both PEAR and non-Pear cases, to JCasClassInfo for that loaded JCas class instance. key is the class loader value is a plain HashMapmap from string form of typenames to JCasClassInfo corresponding to the JCas class covering that type (which may be a supertype of the type name). Key is JCas fully qualified name (not UIMA type name). Is a String, since different type systems may use the same JCas classes. value is the JCasClassInfo for that class - this may be for that actual JCas class, if one exists for that UIMA type name - or it is null, signalling that there is no JCas for this type, and a supertype should be used Cache of FsGenerator[]s kept in TypeSystemImpl instance, since it depends on type codes. Current FsGenerator[] kept in CASImpl shared view data, switched as needed for PEARs.NOTE: Access this map in a thread-safe way only via
get_className_to_jcci(java.lang.ClassLoader, boolean)
which synchronizes on the map object.
-
cl_to_type2JCasStacks
private static final WeakIdentityMap<java.lang.ClassLoader,java.lang.StackTraceElement[]> cl_to_type2JCasStacks
-
cl_to_spiJCas
private static final WeakIdentityMap<java.lang.ClassLoader,java.util.Map<java.lang.String,java.lang.Class<? extends TOP>>> cl_to_spiJCas
-
cl_to_uimaCl
private static final WeakIdentityMap<java.lang.ClassLoader,UIMAClassLoader> cl_to_uimaCl
-
errorSet
private static java.lang.ThreadLocal<java.util.List<FSClassRegistry.ErrorReport>> errorSet
-
NO_URLS
private static final java.net.URL[] NO_URLS
-
-
Method Detail
-
clToType2JCasSize
static int clToType2JCasSize()
-
loadBuiltins
private static void loadBuiltins(TypeImpl ti, java.lang.ClassLoader cl, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> type2jcci, java.util.ArrayList<java.lang.invoke.MutableCallSite> callSites_toSync)
-
loadJCasForTSandClassLoader
private static void loadJCasForTSandClassLoader(TypeSystemImpl ts, boolean isDoUserJCasLoading, java.lang.ClassLoader cl, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> type2jcci)
Load JCas types for some combination of class loader and type system Some of these classes may have already been loaded for this type system Some of these classes may have already been loaded (perhaps for another type system)- Parameters:
ts
- the type systemisDoUserJCasLoading
- always true, left in for experimentation in the future with dynamic generation of JCas classescl
- the class loader. For Pears, is the pear class loader
-
setTypeFromJCasIDforBuiltIns
private static void setTypeFromJCasIDforBuiltIns(FSClassRegistry.JCasClassInfo jcci, TypeSystemImpl tsi, int typeCode)
-
maybeLoadJCasAndSubtypes
private static void maybeLoadJCasAndSubtypes(TypeSystemImpl tsi, TypeImpl ti, FSClassRegistry.JCasClassInfo copyDownDefault_jcasClassInfo, java.lang.ClassLoader cl, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> type2jcci, java.util.ArrayList<java.lang.invoke.MutableCallSite> callSites_toSync, java.lang.invoke.MethodHandles.Lookup lookup)
Called for all the types, including the built-ins, but the built-ins have already been set up by the caller. Saves the results in two places type system independent spot: JCasClassInfo instance indexed by JCasClassName type system spot: the JCasIndexID -> type table in the type system Looks up by classname to see if there is an associated JCas class for this type. - all types of that name (perhaps from different loaded type systems) will share that one JCas class - copyDowns are excluded from this requirement - because there are no JCas class definitions for this type (in that case).- Parameters:
tsi
- the type systemti
- the type to processcopyDownDefault_jcasClassInfo
-cl
- the loader used to load, and to save the results under the key of the class loader the resultstype2JCas
- map holding the results of loading JCas classes
-
getOrCreateJCasClassInfo
public static FSClassRegistry.JCasClassInfo getOrCreateJCasClassInfo(TypeImpl ti, java.lang.ClassLoader cl, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> type2jcci, java.lang.invoke.MethodHandles.Lookup lookup)
For a particular type name, get the JCasClassInfo - by fetching the cached value - by loading the class - return null if no JCas class for this name only called for non-Pear callers- Parameters:
ti
- -cl
- -type2jcci
- -lookup
- -- Returns:
- - jcci or null, if no JCas class for this type was able to be loaded
-
maybeCreateJCasClassInfo
static FSClassRegistry.JCasClassInfo maybeCreateJCasClassInfo(TypeImpl ti, java.lang.ClassLoader cl, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> type2jcci, java.lang.invoke.MethodHandles.Lookup lookup)
-
createJCasClassInfo
public static FSClassRegistry.JCasClassInfo createJCasClassInfo(TypeImpl ti, java.lang.ClassLoader cl, java.lang.invoke.MethodHandles.Lookup lookup)
-
compare_C_T
private static boolean compare_C_T(java.lang.Class<?> clazz, TypeImpl ti)
-
validateSuperClass
private static void validateSuperClass(FSClassRegistry.JCasClassInfo jcci, TypeImpl ti)
Changed https://issues.apache.org/jira/browse/UIMA-5660 to allow insertions of extra types/ classes into the superchain. verify that the supertype class chain matches the type- Parameters:
clazz
- The JCas class, always below TOPti
- -
-
getAllSuperclassNames
private static java.lang.String getAllSuperclassNames(java.lang.Class<?> clazz)
-
getAllSuperTypeNames
private static java.lang.String getAllSuperTypeNames(TypeImpl ti)
-
maybeLoadLocalJCas
private static java.lang.Class<? extends TOP> maybeLoadLocalJCas(TypeImpl ti, java.lang.ClassLoader cl)
Called to load (if possible) a corresponding JCas class for a UIMA type. Called at Class Init time for built-in types Called at TypeSystemCommit for non-built-in types Runs the static initializers in the loaded JCas classes - doing resolve Synchronization: done outside this class- Parameters:
cl
- the class loader to use- Returns:
- the loaded / resolved class
-
loadJCasClassesFromSPI
static java.util.Map<java.lang.String,java.lang.Class<? extends TOP>> loadJCasClassesFromSPI(java.lang.ClassLoader cl)
-
getConstantIntMethodHandle
static java.lang.invoke.MethodHandle getConstantIntMethodHandle(int i)
-
createGenerator
private static FsGenerator3 createGenerator(java.lang.Class<?> jcasClass, java.lang.invoke.MethodHandles.Lookup lookup)
Return a Functional Interface for a generator for creating instances of a type. Function takes a casImpl arg, and returning an instance of the JCas type.- Parameters:
jcasClass
- the class of the JCas type to constructtypeImpl
- the UIMA type- Returns:
- a Functional Interface whose createFS method takes a casImpl and when subsequently invoked, returns a new instance of the class
-
createJCasClassInfo
private static FSClassRegistry.JCasClassInfo createJCasClassInfo(java.lang.Class<? extends TOP> jcasClass, TypeImpl ti, int jcasType, java.lang.invoke.MethodHandles.Lookup lookup)
Called after succeeding at loading, once per load for an exact matching JCas Class - class was already checked to insure is of proper type for JCas - skips creating-generator-for-Sofa - since "new Sofa(...)" is not a valid way to create a sofa- Parameters:
jcasClass
- the JCas class that corresponds to the typeti
- the type- Returns:
- the info for this JCas that is shared across all type systems under this class loader
-
getJCasClassFeatureInfo
private static FSClassRegistry.JCasClassFeatureInfo[] getJCasClassFeatureInfo(java.lang.Class<?> jcasClass)
-
checkConformance
static void checkConformance(java.lang.ClassLoader cl, TypeSystemImpl ts)
-
checkConformance
private static void checkConformance(TypeSystemImpl ts, TypeImpl ti, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> type2jcci)
-
checkConformance
private static void checkConformance(java.lang.Class<?> clazz, TypeSystemImpl tsi, TypeImpl ti, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> type2jcci)
Inner check Never called for "built-ins", or for uima types not having a JCas loaded class Checks that a JCas class definition conforms to the current type in the current type system. Checks that the superclass chain contains some match to the super type chain. Checks that the return value for the getters for features matches the feature's range. Checks that static _FC_xxx values from the JCas class == the adjusted feature offsets in the type system- Parameters:
clazz
- - the JCas class to checktsi
- -ti
- -
-
add2errors
private static void add2errors(java.lang.ThreadLocal<java.util.List<FSClassRegistry.ErrorReport>> errors, java.lang.Exception e)
-
add2errors
private static void add2errors(java.lang.ThreadLocal<java.util.List<FSClassRegistry.ErrorReport>> errors, java.lang.Exception e, boolean doThrow)
-
reportErrors
private static void reportErrors()
-
getGeneratorsForClassLoader
static FsGenerator3[] getGeneratorsForClassLoader(java.lang.ClassLoader cl, boolean isPear, TypeSystemImpl tsi)
called infrequently to set up cache Only called when a type system has not had generators for a particular class loader. For PEAR generators: Populates only for those classes the PEAR has overriding implementations - other entries are null; this serves as a boolean indicator that no pear override exists for that type and therefore no trampoline is needed- Parameters:
cl
- identifies which set of jcas cover classesisPear
- true for pear casetsi
- the type system being used- Returns:
- the generators for that set, as an array indexed by type code
-
getGeneratorsForTypeAndSubtypes
private static void getGeneratorsForTypeAndSubtypes(TypeImpl ti, java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> t2jcci, boolean isPear, java.lang.ClassLoader cl, FsGenerator3[] r, TypeSystemImpl tsi)
-
isAllNull
private static boolean isAllNull(FsGenerator3[] r)
-
updateOrValidateAllCallSitesForJCasClass
private static void updateOrValidateAllCallSitesForJCasClass(java.lang.Class<? extends TOP> clazz, TypeImpl type, java.util.ArrayList<java.lang.invoke.MutableCallSite> callSites_toSync)
Called once when the JCasClassInfo is created. Once set, the offsets are never changed (although they could be...) New type systems are checked for conformance to existing settings in the JCas class. Type System types are augmented by features defined in the JCas but missing in the type, before this routine is called. Iterate over all fields named _FC_ followed by a feature name. If that feature doesn't exist in this type system - skip init, will cause runtime error if used Else, set the callSite's method Handle to one that returns the int constant for type system's offset of that feature. If already set, check that the offset didn't change.- Parameters:
clazz
- -type
- -
-
unregister_jcci_classloader
public static void unregister_jcci_classloader(java.lang.ClassLoader cl)
For internal use only!
-
log_registered_classloaders
public static void log_registered_classloaders(Level aLogLevel)
For internal use only!
-
get_className_to_jcci
static java.util.Map<java.lang.String,FSClassRegistry.JCasClassInfo> get_className_to_jcci(java.lang.ClassLoader cl, boolean is_pear)
-
getLookup
static java.lang.invoke.MethodHandles.Lookup getLookup(java.lang.ClassLoader cl)
-
-