Package org.apache.uima.cas.impl
Class FSClassRegistry
java.lang.Object
org.apache.uima.cas.impl.FSClassRegistry
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 ClassesModifier and TypeClassDescriptionprivate static class
(package private) static class
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
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
FieldsModifier and TypeFieldDescriptionprivate static final MethodType
The callsite has the return type, followed by capture argumentsprivate static final WeakIdentityMap
<ClassLoader, Map<String, Class<? extends TOP>>> private static final WeakIdentityMap
<ClassLoader, Map<String, FSClassRegistry.JCasClassInfo>> 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 final WeakIdentityMap
<ClassLoader, StackTraceElement[]> private static final WeakIdentityMap
<ClassLoader, UIMAClassLoader> private static final MethodHandles.Lookup
private static ThreadLocal
<List<FSClassRegistry.ErrorReport>> private static final MethodType
private static final MethodType
(package private) static final boolean
(package private) static final boolean
private static final FSClassRegistry.JCasClassInfo[]
precomputed generators for built-in types These instances are shared for all type systems Key = index = typecode(package private) static final String
private static final List
<MethodHandle> a cache for constant int method handlesprivate static final URL[]
(package private) static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
add2errors
(ThreadLocal<List<FSClassRegistry.ErrorReport>> errors, Exception e) private static void
add2errors
(ThreadLocal<List<FSClassRegistry.ErrorReport>> errors, Exception e, boolean doThrow) private static void
checkConformance
(Class<?> clazz, TypeSystemImpl tsi, TypeImpl ti, Map<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
private static void
checkConformance
(TypeSystemImpl ts, TypeImpl ti, Map<String, FSClassRegistry.JCasClassInfo> type2jcci) (package private) static int
private static boolean
compare_C_T
(Class<?> clazz, TypeImpl ti) private static FsGenerator3
createGenerator
(Class<?> jcasClass, MethodHandles.Lookup lookup) Return a Functional Interface for a generator for creating instances of a type.private static FSClassRegistry.JCasClassInfo
createJCasClassInfo
(Class<? extends TOP> jcasClass, TypeImpl ti, int jcasType, 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 sofacreateJCasClassInfo
(TypeImpl ti, ClassLoader cl, MethodHandles.Lookup lookup) (package private) static Map
<String, FSClassRegistry.JCasClassInfo> get_className_to_jcci
(ClassLoader cl, boolean is_pear) private static String
getAllSuperclassNames
(Class<?> clazz) private static String
(package private) static MethodHandle
getConstantIntMethodHandle
(int i) (package private) static FsGenerator3[]
getGeneratorsForClassLoader
(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, Map<String, FSClassRegistry.JCasClassInfo> t2jcci, boolean isPear, ClassLoader cl, FsGenerator3[] r, TypeSystemImpl tsi) private static FSClassRegistry.JCasClassFeatureInfo[]
getJCasClassFeatureInfo
(Class<?> jcasClass) (package private) static MethodHandles.Lookup
getLookup
(ClassLoader cl) getOrCreateJCasClassInfo
(TypeImpl ti, ClassLoader cl, Map<String, FSClassRegistry.JCasClassInfo> type2jcci, 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, ClassLoader cl, Map<String, FSClassRegistry.JCasClassInfo> type2jcci, ArrayList<MutableCallSite> callSites_toSync) private static void
loadJCasForTSandClassLoader
(TypeSystemImpl ts, boolean isDoUserJCasLoading, ClassLoader cl, Map<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, ClassLoader cl, Map<String, FSClassRegistry.JCasClassInfo> type2jcci, MethodHandles.Lookup lookup) private static void
maybeLoadJCasAndSubtypes
(TypeSystemImpl tsi, TypeImpl ti, FSClassRegistry.JCasClassInfo copyDownDefault_jcasClassInfo, ClassLoader cl, Map<String, FSClassRegistry.JCasClassInfo> type2jcci, ArrayList<MutableCallSite> callSites_toSync, MethodHandles.Lookup lookup) Called for all the types, including the built-ins, but the built-ins have already been set up by the caller.maybeLoadLocalJCas
(TypeImpl ti, ClassLoader cl) Called to load (if possible) a corresponding JCas class for a UIMA type.private static void
private static void
setTypeFromJCasIDforBuiltIns
(FSClassRegistry.JCasClassInfo jcci, TypeSystemImpl tsi, int typeCode) static void
For internal use only!private static void
updateOrValidateAllCallSitesForJCasClass
(Class<? extends TOP> clazz, TypeImpl type, ArrayList<MutableCallSite> callSites_toSync) Called once when the JCasClassInfo is created.private static void
Changed https://issues.apache.org/jira/browse/UIMA-5660 to allow insertions of extra types/ classes into the superchain.
-
Field Details
-
RECORD_JCAS_CLASSLOADERS
- See Also:
-
IS_RECORD_JCAS_CLASSLOADERS
static final boolean IS_RECORD_JCAS_CLASSLOADERS -
LOG_JCAS_CLASSLOADERS_ON_SHUTDOWN
- See Also:
-
IS_LOG_JCAS_CLASSLOADERS_ON_SHUTDOWN
static final boolean IS_LOG_JCAS_CLASSLOADERS_ON_SHUTDOWN -
defaultLookup
-
findConstructorJCasCoverType
-
callsiteFsGenerator
The callsite has the return type, followed by capture arguments -
fsGeneratorType
-
jcasClassesInfoForBuiltins
precomputed generators for built-in types These instances are shared for all type systems Key = index = typecode -
methodHandlesForInt
a cache for constant int method handles -
cl_to_type2JCas
private static final WeakIdentityMap<ClassLoader,Map<String, cl_to_type2JCasFSClassRegistry.JCasClassInfo>> 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
-
cl_to_spiJCas
-
cl_to_uimaCl
-
errorSet
-
NO_URLS
-
-
Constructor Details
-
FSClassRegistry
public FSClassRegistry()
-
-
Method Details
-
clToType2JCasSize
static int clToType2JCasSize() -
loadBuiltins
private static void loadBuiltins(TypeImpl ti, ClassLoader cl, Map<String, FSClassRegistry.JCasClassInfo> type2jcci, ArrayList<MutableCallSite> callSites_toSync) -
loadJCasForTSandClassLoader
private static void loadJCasForTSandClassLoader(TypeSystemImpl ts, boolean isDoUserJCasLoading, ClassLoader cl, Map<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, ClassLoader cl, Map<String, FSClassRegistry.JCasClassInfo> type2jcci, ArrayList<MutableCallSite> callSites_toSync, 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, ClassLoader cl, Map<String, FSClassRegistry.JCasClassInfo> type2jcci, 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, ClassLoader cl, Map<String, FSClassRegistry.JCasClassInfo> type2jcci, MethodHandles.Lookup lookup) -
createJCasClassInfo
public static FSClassRegistry.JCasClassInfo createJCasClassInfo(TypeImpl ti, ClassLoader cl, MethodHandles.Lookup lookup) -
compare_C_T
-
validateSuperClass
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:
ti
- -clazz
- The JCas class, always below TOP
-
getAllSuperclassNames
-
getAllSuperTypeNames
-
maybeLoadLocalJCas
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
-
getConstantIntMethodHandle
-
createGenerator
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(Class<? extends TOP> jcasClass, TypeImpl ti, int jcasType, 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
-
checkConformance
-
checkConformance
private static void checkConformance(TypeSystemImpl ts, TypeImpl ti, Map<String, FSClassRegistry.JCasClassInfo> type2jcci) -
checkConformance
private static void checkConformance(Class<?> clazz, TypeSystemImpl tsi, TypeImpl ti, Map<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
-
add2errors
private static void add2errors(ThreadLocal<List<FSClassRegistry.ErrorReport>> errors, Exception e, boolean doThrow) -
reportErrors
private static void reportErrors() -
getGeneratorsForClassLoader
static FsGenerator3[] getGeneratorsForClassLoader(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, Map<String, FSClassRegistry.JCasClassInfo> t2jcci, boolean isPear, ClassLoader cl, FsGenerator3[] r, TypeSystemImpl tsi) -
isAllNull
-
updateOrValidateAllCallSitesForJCasClass
private static void updateOrValidateAllCallSitesForJCasClass(Class<? extends TOP> clazz, TypeImpl type, ArrayList<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
For internal use only! -
log_registered_classloaders
For internal use only! -
get_className_to_jcci
static Map<String,FSClassRegistry.JCasClassInfo> get_className_to_jcci(ClassLoader cl, boolean is_pear) -
getLookup
-