Skip to content

Commit

Permalink
Use less granular lock on class creation to avoid dead-lock on recurs…
Browse files Browse the repository at this point in the history
…ive types
  • Loading branch information
raphw committed Jan 23, 2017
1 parent b4dcfdb commit b11d341
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Expand Up @@ -45,8 +45,8 @@ apply from: 'gradle/root/version.gradle'
apply from: "gradle/java-library.gradle"

dependencies {
compile 'net.bytebuddy:byte-buddy:1.6.4'
compile 'net.bytebuddy:byte-buddy-agent:1.6.4'
compile 'net.bytebuddy:byte-buddy:1.6.5'
compile 'net.bytebuddy:byte-buddy-agent:1.6.5'

provided "junit:junit:4.12", "org.hamcrest:hamcrest-core:1.3"
compile "org.objenesis:objenesis:2.5"
Expand Down
Expand Up @@ -13,6 +13,8 @@

class TypeCachingBytecodeGenerator extends ReferenceQueue<ClassLoader> implements BytecodeGenerator {

private final Object BOOTSTRAP_LOCK = new Object();

private final BytecodeGenerator bytecodeGenerator;

private final TypeCache<SerializationFeatureKey> typeCache;
Expand All @@ -26,15 +28,15 @@ public TypeCachingBytecodeGenerator(BytecodeGenerator bytecodeGenerator, boolean
@Override
public <T> Class<T> mockClass(final MockFeatures<T> params) {
try {

return (Class<T>) typeCache.findOrInsert(params.mockedType.getClassLoader(),
new SerializationFeatureKey(params.mockedType, params.interfaces, params.serializableMode),
new Callable<Class<?>>() {
@Override
public Class<?> call() throws Exception {
return bytecodeGenerator.mockClass(params);
}
}, params.mockedType);
ClassLoader classLoader = params.mockedType.getClassLoader();
return (Class<T>) typeCache.findOrInsert(classLoader,
new SerializationFeatureKey(params.mockedType, params.interfaces, params.serializableMode),
new Callable<Class<?>>() {
@Override
public Class<?> call() throws Exception {
return bytecodeGenerator.mockClass(params);
}
}, classLoader == null ? BOOTSTRAP_LOCK : classLoader);
} catch (IllegalArgumentException exception) {
Throwable cause = exception.getCause();
if (cause instanceof RuntimeException) {
Expand Down
2 changes: 1 addition & 1 deletion subprojects/android/android.gradle
Expand Up @@ -11,7 +11,7 @@ apply from: "$rootDir/gradle/java-library.gradle"

dependencies {
compile project.rootProject
compile "net.bytebuddy:byte-buddy-android:1.6.4"
compile "net.bytebuddy:byte-buddy-android:1.6.5"
}

apply from: "$rootDir/gradle/publishable-java-library.gradle"
Expand Down

0 comments on commit b11d341

Please sign in to comment.