Class BypassSyntheticClassLoader
- All Implemented Interfaces:
IClassLoader, SummaryClassShellLoader
The intention is that there be (at most) one such classloader in a given class hierarchy, and that it be referenced using the "Synthetic" classloader reference. Furthermore, it is required that this synthetic loader be a child loader of the Primordial, Extension and Application loaders.
This special classloader has some interactions with the hierarchy for, while the classes it loads are normal-seeming IClass objects, unlike the other loaders, its set of classes is not fixed, causing special cases in code that caches hierarchy data. Also note that this causes the getNumberfClasses and iterateAllClasses methods to behave differently for those of other classloaders.
Code that wants to introduce synthetic classes uses the registerClass method, giving it an Atom which is the class name, and an IClass which is the class to load. Since the synthetic loader must be a child of the others, it would be very bad to use an existing name for a new synthetic class.
Class lookup works just as for any other classloader.
- Author:
- Julian Dolby (dolby@us.ibm.com)
-
Constructor Summary
ConstructorsConstructorDescriptionBypassSyntheticClassLoader(ClassLoaderReference me, IClassLoader parent, StringFilter exclusions, IClassHierarchy cha) Don't change my signature! ClassLoaderFactoryImpl calls me by reflection! yuck. -
Method Summary
Modifier and TypeMethodDescriptiondefineSummaryClassShell(TypeName name, TypeName superName) Register a shellIClassfor a summary-modeled type, so that classes loaded by this loader can resolve it as a superclass.defineSummaryClassShell(TypeName name, TypeName superName, Collection<MethodSummary> methods) Register a shellIClassthat also exposes the given method summaries as its own declared methods, so that a walk of the shell (e.g.getName()intintReturn the ClassLoaderReference for this class loader.getSourceFileName(IClass klass) getSourceFileName(IMethod method, int offset) voidInitialize internal data structures.lookupClass(TypeName className) Find and return the IClass defined by this class loader that corresponds to the given class name.voidregisterClass(TypeName className, IClass theClass) Register the existence of a new synthetic classvoidremoveAll(Collection<IClass> toRemove) blow away references to any classes in the settoString()
-
Constructor Details
-
BypassSyntheticClassLoader
public BypassSyntheticClassLoader(ClassLoaderReference me, IClassLoader parent, StringFilter exclusions, IClassHierarchy cha) Don't change my signature! ClassLoaderFactoryImpl calls me by reflection! yuck.- Parameters:
me- the name of this class loaderparent- its parentexclusions- classes to ignorecha- governing class hierarchy
-
-
Method Details
-
toString
-
lookupClass
Description copied from interface:IClassLoaderFind and return the IClass defined by this class loader that corresponds to the given class name.- Specified by:
lookupClassin interfaceIClassLoader- Parameters:
className- name of the class- Returns:
- the IClass defined by this class loader that corresponds to the given class name, or null if not found.
-
registerClass
-
defineSummaryClassShell
Description copied from interface:SummaryClassShellLoaderRegister a shellIClassfor a summary-modeled type, so that classes loaded by this loader can resolve it as a superclass.Idempotent: if a class is already registered under
name, it is returned unchanged.- Specified by:
defineSummaryClassShellin interfaceSummaryClassShellLoader- Parameters:
name- the type to register a shell forsuperName- the shell's superclass, ornullfor this loader's language root type- Returns:
- the registered (or pre-existing) class
-
defineSummaryClassShell
public IClass defineSummaryClassShell(TypeName name, TypeName superName, Collection<MethodSummary> methods) Description copied from interface:SummaryClassShellLoaderRegister a shellIClassthat also exposes the given method summaries as its own declared methods, so that a walk of the shell (e.g. when resolving an inherited method on a subclass) finds them. The method bodies are still bound late by the usual bypass mechanism; only the declarations need to exist on the shell.The default implementation ignores
methodsand delegates toSummaryClassShellLoader.defineSummaryClassShell(TypeName, TypeName); implementations whose shells can carry methods (such as theBypassSyntheticClassLoader) override this.- Specified by:
defineSummaryClassShellin interfaceSummaryClassShellLoader- Parameters:
name- the type to register a shell forsuperName- the shell's superclass, ornullfor this loader's language root typemethods- summaries for the methods the shell should declare- Returns:
- the registered (or pre-existing) class
-
getReference
Return the ClassLoaderReference for this class loader.- Specified by:
getReferencein interfaceIClassLoader- Returns:
- ClassLoaderReference
-
iterateAllClasses
- Specified by:
iterateAllClassesin interfaceIClassLoader- Returns:
- an Iterator of all classes loaded by this loader
-
getNumberOfClasses
public int getNumberOfClasses()- Specified by:
getNumberOfClassesin interfaceIClassLoader- Returns:
- the number of classes in scope to be loaded by this loader
-
getName
- Specified by:
getNamein interfaceIClassLoader- Returns:
- the unique name that identifies this class loader.
-
getLanguage
- Specified by:
getLanguagein interfaceIClassLoader- Returns:
- the unique name that identifies the programming language from which this class loader loads code.
-
getNumberOfMethods
public int getNumberOfMethods()- Specified by:
getNumberOfMethodsin interfaceIClassLoader
-
getSourceFileName
- Specified by:
getSourceFileNamein interfaceIClassLoader- Parameters:
klass- the class for which information is desired.- Returns:
- name of source file corresponding to the class, or null if not available
-
getParent
- Specified by:
getParentin interfaceIClassLoader- Returns:
- the parent IClassLoader, if any, or null
-
init
Description copied from interface:IClassLoaderInitialize internal data structures.- Specified by:
initin interfaceIClassLoader- Throws:
IOException
-
removeAll
Description copied from interface:IClassLoaderblow away references to any classes in the set- Specified by:
removeAllin interfaceIClassLoader- Parameters:
toRemove- Collection<IClass>
-
getSource
- Specified by:
getSourcein interfaceIClassLoader- Returns:
- input stream representing the source file for a class, or null if not available
-
getInstructionFactory
- Specified by:
getInstructionFactoryin interfaceIClassLoader
-
getSource
- Specified by:
getSourcein interfaceIClassLoader- Parameters:
method- The method for which information is desiredoffset- an offset into the bytecode of the given method.- Returns:
- input stream representing the source file for a given bytecode index of a given method, or null if not available
-
getSourceFileName
- Specified by:
getSourceFileNamein interfaceIClassLoader- Parameters:
method- The method for which information is desiredoffset- an offset into the bytecode of the given method.- Returns:
- name of the source file corresponding to the given offset in the given method. Note that this api allows a single method to arise from multiple source files, which is deliberate as it can happen in some languages.
-