Migrated attachment for Guice issue 288, comment 17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: com/google/inject/internal/StackTraceElements.java | |
=================================================================== | |
--- com/google/inject/internal/StackTraceElements.java (revision 1149) | |
+++ com/google/inject/internal/StackTraceElements.java (working copy) | |
@@ -19,7 +19,6 @@ | |
import java.io.IOException; | |
import java.lang.reflect.Constructor; | |
import java.lang.reflect.Member; | |
-import java.util.Map; | |
/** | |
* Creates stack trace elements for members. | |
@@ -28,19 +27,6 @@ | |
*/ | |
public class StackTraceElements { | |
- /*if[AOP]*/ | |
- static final Map<Class<?>, LineNumbers> lineNumbersCache = new MapMaker().weakKeys().softValues() | |
- .makeComputingMap(new Function<Class<?>, LineNumbers>() { | |
- public LineNumbers apply(Class<?> key) { | |
- try { | |
- return new LineNumbers(key); | |
- } | |
- catch (IOException e) { | |
- throw new RuntimeException(e); | |
- } | |
- } | |
- }); | |
- /*end[AOP]*/ | |
public static Object forMember(Member member) { | |
if (member == null) { | |
@@ -50,7 +36,13 @@ | |
Class declaringClass = member.getDeclaringClass(); | |
/*if[AOP]*/ | |
- LineNumbers lineNumbers = lineNumbersCache.get(declaringClass); | |
+ LineNumbers lineNumbers = null; | |
+ try { | |
+ lineNumbers = new LineNumbers(declaringClass); | |
+ } | |
+ catch (IOException e) { | |
+ throw new RuntimeException(e); | |
+ } | |
String fileName = lineNumbers.getSource(); | |
Integer lineNumberOrNull = lineNumbers.getLineNumber(member); | |
int lineNumber = lineNumberOrNull == null ? lineNumbers.getFirstLine() : lineNumberOrNull; | |
@@ -67,7 +59,13 @@ | |
public static Object forType(Class<?> implementation) { | |
/*if[AOP]*/ | |
- LineNumbers lineNumbers = lineNumbersCache.get(implementation); | |
+ LineNumbers lineNumbers = null; | |
+ try { | |
+ lineNumbers = new LineNumbers(implementation); | |
+ } | |
+ catch (IOException e) { | |
+ throw new RuntimeException(e); | |
+ } | |
int lineNumber = lineNumbers.getFirstLine(); | |
String fileName = lineNumbers.getSource(); | |
/*end[AOP]*/ | |
Index: com/google/inject/internal/BytecodeGen.java | |
=================================================================== | |
--- com/google/inject/internal/BytecodeGen.java (revision 1149) | |
+++ com/google/inject/internal/BytecodeGen.java (working copy) | |
@@ -23,7 +23,6 @@ | |
import java.lang.reflect.Modifier; | |
import java.security.AccessController; | |
import java.security.PrivilegedAction; | |
-import java.util.Map; | |
import java.util.logging.Logger; | |
/** | |
@@ -81,26 +80,10 @@ | |
private static final String CGLIB_PACKAGE = " "; // any string that's illegal in a package name | |
end[NO_AOP]*/ | |
- /** Use "-Dguice.custom.loader=false" to disable custom classloading. */ | |
+ /** Use "-Dguice.custom.loader=true" to enable custom bridge classloading. */ | |
static final boolean HOOK_ENABLED | |
- = "true".equals(System.getProperty("guice.custom.loader", "true")); | |
+ = "true".equals(System.getProperty("guice.custom.loader", "false")); | |
- /** | |
- * Weak cache of bridge class loaders that make the Guice implementation | |
- * classes visible to various code-generated proxies of client classes. | |
- */ | |
- private static final Map<ClassLoader, ClassLoader> CLASS_LOADER_CACHE | |
- = new MapMaker().weakKeys().weakValues().makeComputingMap( | |
- new Function<ClassLoader, ClassLoader>() { | |
- public ClassLoader apply(final @Nullable ClassLoader typeClassLoader) { | |
- logger.fine("Creating a bridge ClassLoader for " + typeClassLoader); | |
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { | |
- public ClassLoader run() { | |
- return new BridgeClassLoader(typeClassLoader); | |
- } | |
- }); | |
- } | |
- }); | |
/** | |
* For class loaders, {@code null}, is always an alias to the | |
@@ -146,7 +129,13 @@ | |
} | |
if (HOOK_ENABLED && Visibility.forType(type) == Visibility.PUBLIC) { | |
- return CLASS_LOADER_CACHE.get(delegate); | |
+ logger.fine("Creating a bridge ClassLoader for " + delegate); | |
+ final ClassLoader finalDelegate = delegate; | |
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { | |
+ public ClassLoader run() { | |
+ return new BridgeClassLoader(finalDelegate); | |
+ } | |
+ }); | |
} | |
return delegate; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment