public final class BytecodeGen
extends java.lang.Object
faster reflection
, method
interceptors
and to proxy circular dependencies.
When loading classes, we need to be careful of:
OSGi
use class loader boundaries
to enforce modularity at runtime.
For each generated class, there's multiple class loaders involved:
Modifier and Type | Class and Description |
---|---|
private static class |
BytecodeGen.BridgeClassLoader
Loader for Guice-generated classes.
|
private static class |
BytecodeGen.SystemBridgeHolder |
static class |
BytecodeGen.Visibility
The required visibility of a user's class from a Guice-generated class.
|
Modifier and Type | Field and Description |
---|---|
(package private) static java.lang.String |
CGLIB_PACKAGE
either "net.sf.cglib", or "com.google.inject.internal.cglib"
|
private static com.google.common.cache.LoadingCache<java.lang.ClassLoader,java.lang.ClassLoader> |
CLASS_LOADER_CACHE
Weak cache of bridge class loaders that make the Guice implementation
classes visible to various code-generated proxies of client classes.
|
(package private) static net.sf.cglib.core.NamingPolicy |
ENHANCER_NAMING_POLICY |
(package private) static net.sf.cglib.core.NamingPolicy |
FASTCLASS_NAMING_POLICY |
(package private) static java.lang.ClassLoader |
GUICE_CLASS_LOADER |
(package private) static java.lang.String |
GUICE_INTERNAL_PACKAGE
ie.
|
(package private) static java.util.logging.Logger |
logger |
Constructor and Description |
---|
BytecodeGen() |
Modifier and Type | Method and Description |
---|---|
private static java.lang.ClassLoader |
canonicalize(java.lang.ClassLoader classLoader)
Attempts to canonicalize null references to the system class loader.
|
static java.lang.ClassLoader |
getClassLoader(java.lang.Class<?> type)
Returns the class loader to host generated classes for
type . |
private static java.lang.ClassLoader |
getClassLoader(java.lang.Class<?> type,
java.lang.ClassLoader delegate) |
private static boolean |
hasSameVersionOfCglib(java.lang.ClassLoader classLoader)
Returns true if the types classloader has the same version of cglib that BytecodeGen has.
|
private static boolean |
isPubliclyCallable(java.lang.reflect.Member member)
Returns true if the member can be called by a fast class generated in a different classloader.
|
static net.sf.cglib.proxy.Enhancer |
newEnhancer(java.lang.Class<?> type,
BytecodeGen.Visibility visibility) |
static net.sf.cglib.reflect.FastClass |
newFastClassForMember(java.lang.Class<?> type,
java.lang.reflect.Member member)
Returns a FastClass proxy for invoking the given member or
null if access rules
disallow it. |
static net.sf.cglib.reflect.FastClass |
newFastClassForMember(java.lang.reflect.Member member)
Returns a FastClass proxy for invoking the given member or
null if access rules
disallow it. |
static final java.util.logging.Logger logger
static final java.lang.ClassLoader GUICE_CLASS_LOADER
static final java.lang.String GUICE_INTERNAL_PACKAGE
static final java.lang.String CGLIB_PACKAGE
static final net.sf.cglib.core.NamingPolicy FASTCLASS_NAMING_POLICY
static final net.sf.cglib.core.NamingPolicy ENHANCER_NAMING_POLICY
private static final com.google.common.cache.LoadingCache<java.lang.ClassLoader,java.lang.ClassLoader> CLASS_LOADER_CACHE
private static java.lang.ClassLoader canonicalize(java.lang.ClassLoader classLoader)
public static java.lang.ClassLoader getClassLoader(java.lang.Class<?> type)
type
.private static java.lang.ClassLoader getClassLoader(java.lang.Class<?> type, java.lang.ClassLoader delegate)
public static net.sf.cglib.reflect.FastClass newFastClassForMember(java.lang.reflect.Member member)
null
if access rules
disallow it.for a full description
public static net.sf.cglib.reflect.FastClass newFastClassForMember(java.lang.Class<?> type, java.lang.reflect.Member member)
null
if access rules
disallow it.
FastClass works by generating a type in the same package as the target type
. This
may or may not work depending on the access level of the class/member. It breaks down into the
following cases depending on accessibility:
BytecodeGen.BridgeClassLoader
which ensures there are no versioning issues.
FastClass
as we do. This
may be violated when running in OSGI bundles.
private static boolean hasSameVersionOfCglib(java.lang.ClassLoader classLoader)
private static boolean isPubliclyCallable(java.lang.reflect.Member member)
public static net.sf.cglib.proxy.Enhancer newEnhancer(java.lang.Class<?> type, BytecodeGen.Visibility visibility)