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 classprivate static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BytecodeGeneratorprivate static final intThe mask to use to mask out theTypeCachingBytecodeGenerator.MockitoMockKey.hashCode()to find thecacheLocks.private static final intThe size of thecacheLocks.private final TypeCachingBytecodeGenerator.TypeCachingLock[]This array containsTypeCachingBytecodeGenerator.TypeCachingLockinstances, which are used as java monitor locks forTypeCache.findOrInsert(ClassLoader, Object, Callable, Object).private final ReadWriteLockprivate final net.bytebuddy.TypeCache<TypeCachingBytecodeGenerator.MockitoMockKey> -
Constructor Summary
ConstructorsConstructorDescriptionTypeCachingBytecodeGenerator(BytecodeGenerator bytecodeGenerator, boolean weak) -
Method Summary
Modifier and TypeMethodDescriptionvoidReturns aTypeCachingBytecodeGenerator.TypeCachingLock, which locks theTypeCache.findOrInsert(ClassLoader, Object, Callable, Object).<T> Class<T> mockClass(MockFeatures<T> params) voidmockClassConstruction(Class<?> type) voidmockClassStatic(Class<?> type) Methods inherited from class 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.TypeCachingLockinstances, 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_LOCKfor 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:
mockClassin 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.TypeCachingLockto use to lock theTypeCache
-
mockClassStatic
- Specified by:
mockClassStaticin interfaceBytecodeGenerator
-
mockClassConstruction
- Specified by:
mockClassConstructionin interfaceBytecodeGenerator
-
clearAllCaches
public void clearAllCaches()- Specified by:
clearAllCachesin interfaceBytecodeGenerator
-