Interface CodeStackTracker
- All Superinterfaces:
ClassFileTransformPREVIEW<CodeTransformPREVIEW,,CodeElementPREVIEW, CodeBuilderPREVIEW> CodeTransformPREVIEW
CodeStackTracker is a preview API of the Java platform.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
CodeStackTrackerPREVIEW is a CodeTransformPREVIEW tracking stack content
and calculating max stack size.
Sample use:
var stackTracker = CodeStackTracker.of();
codeBuilder.transforming(stackTracker, trackedBuilder -> {
trackedBuilder.aload(0);
trackedBuilder.lconst_0();
trackedBuilder.ifThen(...);
...
var stack = stackTracker.stack().get();
int maxStack = stackTracker.maxStackSize().get();
});
- Since:
- 22
-
Field Summary
Fields declared in interface java.lang.classfile.CodeTransformPREVIEW
ACCEPT_ALL -
Method Summary
Modifier and TypeMethodDescriptionReturns tracked max stack size.static CodeStackTrackerPREVIEWCreates new instance ofCodeStackTrackerPREVIEW initialized with provided stack items.stack()Methods declared in interface java.lang.classfile.ClassFileTransformPREVIEW
accept, atEnd, atStartMethods declared in interface java.lang.classfile.CodeTransformPREVIEW
andThen
-
Method Details
-
of
Creates new instance ofCodeStackTrackerPREVIEW initialized with provided stack items.- Parameters:
initialStack- initial stack content- Returns:
- new instance of
CodeStackTrackerPREVIEW
-
stack
Optional<Collection<TypeKindPREVIEW>> stack()Returns Collection of TypeKindPREVIEW representing current stack. Returns an empty Optional when the Stack content is unknown (right afterxRETURN, ATHROW, GOTO, GOTO_W, LOOKUPSWITCH, TABLESWITCHinstructions).Temporary unknown stack content can be recovered by binding of a LabelPREVIEW used as target of a branch instruction from existing code with known stack (forward branch target), or by binding of a LabelPREVIEW defining an exception handler (exception handler code start).
- Returns:
- actual stack content, or an empty Optional if unknown
-
maxStackSize
-
CodeStackTrackerwhen preview features are enabled.