Package org.mockito.internal.debugging
Class LocationImpl
- java.lang.Object
-
- org.mockito.internal.debugging.LocationImpl
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
LocationImpl.MetadataShim
private static class
LocationImpl.SerializableShim
-
Field Summary
Fields Modifier and Type Field Description private static int
BUFFER_SIZE
This is an unfortunate buffer.private static StackTraceCleaner
CLEANER
private static java.util.function.Predicate<StackTraceCleaner.StackFrameMetadata>
cleanerIsIn
private static int
FRAMES_TO_SKIP
private static java.lang.String
PREFIX
private static long
serialVersionUID
private StackTraceCleaner.StackFrameMetadata
sfm
private java.lang.String
stackTraceLine
private static java.util.function.Function<java.lang.StackTraceElement,StackTraceCleaner.StackFrameMetadata>
toStackFrameMetadata
In Java, allocating lambdas is cheap, but not free.private static java.lang.String
UNEXPECTED_ERROR_SUFFIX
-
Constructor Summary
Constructors Constructor Description LocationImpl(boolean isInline)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static int
framesToSkip()
In order to trigger the stack walker, we create some reflective frames.java.lang.String
getSourceFile()
Source file of this locationprivate static StackTraceCleaner.StackFrameMetadata
getStackFrame(boolean isInline)
private static java.lang.String
noStackTraceFailureMessage()
private java.lang.String
stackTraceLine()
java.lang.String
toString()
Human readable location in the source code, seeInvocation.getLocation()
private static boolean
usingDefaultStackTraceCleaner()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
UNEXPECTED_ERROR_SUFFIX
private static final java.lang.String UNEXPECTED_ERROR_SUFFIX
- See Also:
- Constant Field Values
-
BUFFER_SIZE
private static final int BUFFER_SIZE
This is an unfortunate buffer. Inside StackWalker, a buffer is created, which is resized by doubling. The resizing also allocates a tonne of StackFrame elements. If we traverse more than BUFFER_SIZE elements, the resulting resize can significantly affect the overall cost of the operation. If we traverse fewer than this number, we are inefficient. Empirically, 16 is enough stack frames for a simple stub+call operation to succeed without resizing, as measured on Java 11.- See Also:
- Constant Field Values
-
PREFIX
private static final java.lang.String PREFIX
- See Also:
- Constant Field Values
-
CLEANER
private static final StackTraceCleaner CLEANER
-
toStackFrameMetadata
private static final java.util.function.Function<java.lang.StackTraceElement,StackTraceCleaner.StackFrameMetadata> toStackFrameMetadata
In Java, allocating lambdas is cheap, but not free. stream.map(this::doSomething) will allocate a Function object each time the function is called (although not per element). By assigning these Functions and Predicates to variables, we can avoid the memory allocation.
-
cleanerIsIn
private static final java.util.function.Predicate<StackTraceCleaner.StackFrameMetadata> cleanerIsIn
-
FRAMES_TO_SKIP
private static final int FRAMES_TO_SKIP
-
sfm
private final StackTraceCleaner.StackFrameMetadata sfm
-
stackTraceLine
private volatile java.lang.String stackTraceLine
-
-
Method Detail
-
getSourceFile
public java.lang.String getSourceFile()
Description copied from interface:Location
Source file of this location- Specified by:
getSourceFile
in interfaceLocation
- Returns:
- source file
-
toString
public java.lang.String toString()
Description copied from interface:Location
Human readable location in the source code, seeInvocation.getLocation()
-
stackTraceLine
private java.lang.String stackTraceLine()
-
getStackFrame
private static StackTraceCleaner.StackFrameMetadata getStackFrame(boolean isInline)
-
usingDefaultStackTraceCleaner
private static boolean usingDefaultStackTraceCleaner()
-
noStackTraceFailureMessage
private static java.lang.String noStackTraceFailureMessage()
-
framesToSkip
private static int framesToSkip()
In order to trigger the stack walker, we create some reflective frames. These need to be skipped so as to ensure there are no non-Mockito frames at the top of the stack trace.
-
-