Class TypeCachingBytecodeGenerator
java.lang.Object
java.lang.ref.ReferenceQueue<ClassLoader>
org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator
- All Implemented Interfaces:
BytecodeGenerator
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BytecodeGenerator
private static final int
The mask to use to mask out theTypeCachingBytecodeGenerator.MockitoMockKey.hashCode()
to find thecacheLocks
.private static final int
The size of thecacheLocks
.private final TypeCachingBytecodeGenerator.TypeCachingLock[]
This array containsTypeCachingBytecodeGenerator.TypeCachingLock
instances, which are used as java monitor locks forTypeCache.findOrInsert(ClassLoader, Object, Callable, Object)
.private final ReadWriteLock
private final net.bytebuddy.TypeCache
<TypeCachingBytecodeGenerator.MockitoMockKey> -
Constructor Summary
ConstructorsConstructorDescriptionTypeCachingBytecodeGenerator
(BytecodeGenerator bytecodeGenerator, boolean weak) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Returns aTypeCachingBytecodeGenerator.TypeCachingLock
, which locks theTypeCache.findOrInsert(ClassLoader, Object, Callable, Object)
.<T> Class
<T> mockClass
(MockFeatures<T> params) void
mockClassConstruction
(Class<?> type) void
mockClassStatic
(Class<?> type) Methods inherited from class java.lang.ref.ReferenceQueue
poll, remove, remove
-
Field Details
-
CACHE_LOCK_SIZE
private static final int CACHE_LOCK_SIZEThe size of thecacheLocks
.Caution: This must match the
CACHE_LOCK_MASK
.- See Also:
-
CACHE_LOCK_MASK
private static final int CACHE_LOCK_MASKThe mask to use to mask out theTypeCachingBytecodeGenerator.MockitoMockKey.hashCode()
to find thecacheLocks
.Caution: this must match the bits of the
CACHE_LOCK_SIZE
.- See Also:
-
bytecodeGenerator
-
typeCache
-
lock
-
cacheLocks
This array containsTypeCachingBytecodeGenerator.TypeCachingLock
instances, which are used as java monitor locks forTypeCache.findOrInsert(ClassLoader, Object, Callable, Object)
. The locks spread the lock to acquire over multiple locks instead of using a single lockBOOTSTRAP_LOCK
for allTypeCachingBytecodeGenerator.MockitoMockKey
.Note: We can't simply use the mockedType class lock as a lock, because the
TypeCachingBytecodeGenerator.MockitoMockKey
, will be the same for different mockTypes + interfaces.#3035: Excessive locking in TypeCachingBytecodeGenerator#BOOTSTRAP_LOCK
-
-
Constructor Details
-
TypeCachingBytecodeGenerator
-
-
Method Details
-
mockClass
- Specified by:
mockClass
in interfaceBytecodeGenerator
-
getCacheLockForKey
private TypeCachingBytecodeGenerator.TypeCachingLock getCacheLockForKey(TypeCachingBytecodeGenerator.MockitoMockKey key) Returns aTypeCachingBytecodeGenerator.TypeCachingLock
, which locks theTypeCache.findOrInsert(ClassLoader, Object, Callable, Object)
.- Parameters:
key
- the key to lock- Returns:
- the
TypeCachingBytecodeGenerator.TypeCachingLock
to use to lock theTypeCache
-
mockClassStatic
- Specified by:
mockClassStatic
in interfaceBytecodeGenerator
-
mockClassConstruction
- Specified by:
mockClassConstruction
in interfaceBytecodeGenerator
-
clearAllCaches
public void clearAllCaches()- Specified by:
clearAllCaches
in interfaceBytecodeGenerator
-