com.google.inject.internal

Class BytecodeGen



  • public final class BytecodeGen
    extends Object
    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 private 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.

    Author:
    mcculls@gmail.com (Stuart McCulloch), jessewilson@google.com (Jesse Wilson)
    • Constructor Detail

      • BytecodeGen

        public BytecodeGen()
    • Method Detail

      • getClassLoader

        public static ClassLoader getClassLoader(Class<?> type)
        Returns the class loader to host generated classes for type.

Copyright © 2006-2015 Google, Inc.. All Rights Reserved.