Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (C) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.inject.internal;
import static com.google.inject.internal.InternalFlags.getCustomClassLoadingOption;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.inject.internal.InternalFlags.CustomClassLoadingOption;
import java.lang.reflect.Constructor;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Utility methods for runtime code generation and class loading. We use this stuff for {@link
* net.sf.cglib.reflect.FastClass faster reflection}, {@link net.sf.cglib.proxy.Enhancer 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.
*
*
* @author [email protected] (Stuart McCulloch)
* @author [email protected] (Jesse Wilson)
*/
public final class BytecodeGen {
static final Logger logger = Logger.getLogger(BytecodeGen.class.getName());
static final ClassLoader GUICE_CLASS_LOADER = canonicalize(BytecodeGen.class.getClassLoader());
// initialization-on-demand...
private static class SystemBridgeHolder {
static final BridgeClassLoader SYSTEM_BRIDGE = new BridgeClassLoader();
}
/** ie. "com.google.inject.internal" */
static final String GUICE_INTERNAL_PACKAGE
= BytecodeGen.class.getName().replaceFirst("\\.internal\\..*$", ".internal");
/*if[AOP]*/
/** either "net.sf.cglib", or "com.google.inject.internal.cglib" */
static final String CGLIB_PACKAGE
= net.sf.cglib.proxy.Enhancer.class.getName().replaceFirst("\\.cglib\\..*$", ".cglib");
static final net.sf.cglib.core.NamingPolicy FASTCLASS_NAMING_POLICY
= new net.sf.cglib.core.DefaultNamingPolicy() {
@Override protected String getTag() {
return "ByGuice";
}
@Override
public String getClassName(String prefix, String source, Object key,
net.sf.cglib.core.Predicate names) {
// we explicitly set the source here to "FastClass" so that our jarjar renaming
// to $FastClass doesn't leak into the class names. if we did not do this,
// classes would end up looking like $$$FastClassByGuice$$, with the extra $
// at the front.
return super.getClassName(prefix, "FastClass", key, names);
}
};
static final net.sf.cglib.core.NamingPolicy ENHANCER_NAMING_POLICY
= new net.sf.cglib.core.DefaultNamingPolicy() {
@Override
protected String getTag() {
return "ByGuice";
}
@Override
public String getClassName(String prefix, String source, Object key,
net.sf.cglib.core.Predicate names) {
// we explicitly set the source here to "Enhancer" so that our jarjar renaming
// to $Enhancer doesn't leak into the class names. if we did not do this,
// classes would end up looking like $$$EnhancerByGuice$$, with the extra $
// at the front.
return super.getClassName(prefix, "Enhancer", key, names);
}
};
/*end[AOP]*/
/*if[NO_AOP]
private static final String CGLIB_PACKAGE = " "; // any string that's illegal in a package name
end[NO_AOP]*/
/**
* Weak cache of bridge class loaders that make the Guice implementation
* classes visible to various code-generated proxies of client classes.
*/
private static final LoadingCache CLASS_LOADER_CACHE;
static {
CacheBuilder