Package com.google.inject.internal
Class BytecodeGen
java.lang.Object
com.google.inject.internal.BytecodeGen
Utility methods for runtime code generation and class loading. We use this stuff for
faster reflection
, method
interceptors
and to proxy circular dependencies.
When loading classes, we need to be careful of:
- Memory leaks. Generated classes need to be garbage collected in long-lived applications. Once an injector and any instances it created can be garbage collected, the corresponding generated classes should be collectable.
- Visibility. Containers like
OSGi
use class loader boundaries to enforce modularity at runtime.
For each generated class, there's multiple class loaders involved:
- The related class's class loader. Every generated class services exactly one user-supplied class. This class loader must be used to access members with protected and package visibility.
- Guice's class loader.
- Our bridge class loader. This is a child of the user's class loader. It selectively delegates to either the user's class loader (for user classes) or the Guice class loader (for internal classes that are used by the generated classes). This class loader that owns the classes generated by Guice.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Loader for Guice-generated classes.private static class
static enum
The required visibility of a user's class from a Guice-generated class. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
private static final com.google.common.cache.LoadingCache<ClassLoader,
ClassLoader> Weak cache of bridge class loaders that make the Guice implementation classes visible to various code-generated proxies of client classes.(package private) static final ClassLoader
(package private) static final String
ie.(package private) static final Logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static ClassLoader
canonicalize
(ClassLoader classLoader) Attempts to canonicalize null references to the system class loader.static ClassLoader
getClassLoader
(Class<?> type) Returns the class loader to host generated classes fortype
.private static ClassLoader
getClassLoader
(Class<?> type, ClassLoader delegate)
-
Field Details
-
logger
-
GUICE_CLASS_LOADER
-
GUICE_INTERNAL_PACKAGE
ie. "com.google.inject.internal" -
CGLIB_PACKAGE
- See Also:
-
CLASS_LOADER_CACHE
private static final com.google.common.cache.LoadingCache<ClassLoader,ClassLoader> CLASS_LOADER_CACHEWeak cache of bridge class loaders that make the Guice implementation classes visible to various code-generated proxies of client classes.
-
-
Constructor Details
-
BytecodeGen
public BytecodeGen()
-
-
Method Details
-
canonicalize
Attempts to canonicalize null references to the system class loader. May return null if for some reason the system loader is unavailable. -
getClassLoader
Returns the class loader to host generated classes fortype
. -
getClassLoader
-