| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
H2JVM.Analyse.StackMap
Description
Generate a stack map table for a method. This process MUST run last in the high level stage, modifications to the code after this point will invalidate the stack map table and cause invalid class files to be generated.
Synopsis
- calculateStackMapFrames :: HasCallStack => QualifiedClassName -> [MethodAccessFlag] -> MethodDescriptor -> NonEmpty Instruction -> Either StackMapError ([StackMapFrame], Int, Int)
- data BasicBlock = BasicBlock {
- index :: Int
- instructions :: [Instruction]
- start :: Maybe Label
- end :: Maybe Label
- data Frame = Frame {
- locals :: [LocalVariable]
- stack :: [StackEntry]
- data LocalVariable
- analyseBlockDiff :: HasCallStack => Frame -> BasicBlock -> Either StackMapError Frame
- diffFrames :: Frame -> Frame -> Label -> StackMapFrame
- splitIntoBasicBlocks :: HasCallStack => NonEmpty Instruction -> NonEmpty BasicBlock
- topFrame :: QualifiedClassName -> [MethodAccessFlag] -> MethodDescriptor -> Frame
- data StackMapError
Documentation
calculateStackMapFrames Source #
Arguments
| :: HasCallStack | |
| => QualifiedClassName | The class containing this method |
| -> [MethodAccessFlag] | Method access flags (to determine if static) |
| -> MethodDescriptor | The method descriptor |
| -> NonEmpty Instruction | The method's instruction list |
| -> Either StackMapError ([StackMapFrame], Int, Int) | (stack map frames, max stack, max locals) |
Calculate the stack map frames for a method's bytecode. This function works by first splitting the code into basic blocks, then computing the frame state at the start of each block using a dataflow analysis, and finally generating the stack map frames by comparing the frame states at block entries.
data BasicBlock Source #
A basic block is a sequence of instructions with a single entry and exit point. Control flow only enters at the beginning and exits at the end.
Constructors
| BasicBlock | |
Fields
| |
Instances
| Show BasicBlock Source # | |
Defined in H2JVM.Analyse.StackMap Methods showsPrec :: Int -> BasicBlock -> ShowS # show :: BasicBlock -> String # showList :: [BasicBlock] -> ShowS # | |
| Eq BasicBlock Source # | |
Defined in H2JVM.Analyse.StackMap | |
Represents the JVM frame state at a particular program point.
Constructors
| Frame | |
Fields
| |
data LocalVariable Source #
Represents the type of a local variable slot in the stack frame
Constructors
| Uninitialised | The slot has not been initialised or contains an unusable value |
| LocalVariable FieldType | The slot contains a value of the given type |
Instances
| Show LocalVariable Source # | |
Defined in H2JVM.Analyse.StackMap Methods showsPrec :: Int -> LocalVariable -> ShowS # show :: LocalVariable -> String # showList :: [LocalVariable] -> ShowS # | |
| Eq LocalVariable Source # | |
Defined in H2JVM.Analyse.StackMap Methods (==) :: LocalVariable -> LocalVariable -> Bool # (/=) :: LocalVariable -> LocalVariable -> Bool # | |
| Pretty LocalVariable Source # | |
Defined in H2JVM.Analyse.StackMap | |
analyseBlockDiff :: HasCallStack => Frame -> BasicBlock -> Either StackMapError Frame Source #
Compute the frame state after executing all instructions in a basic block.
diffFrames :: Frame -> Frame -> Label -> StackMapFrame Source #
Compute the delta between two frames to produce a StackMapFrame
splitIntoBasicBlocks :: HasCallStack => NonEmpty Instruction -> NonEmpty BasicBlock Source #
Split a list of instructions into basic blocks, by splitting at labels and branch instructions.
topFrame :: QualifiedClassName -> [MethodAccessFlag] -> MethodDescriptor -> Frame Source #
Compute the initial frame state at method entry (the "top frame"), based on the method descriptor and access flags (static vs instance).
data StackMapError Source #
Constructors
| StackUnderflow Instruction | |
| InvalidStackState Instruction [StackEntry] (Maybe Text) | |
| LocalIndexOutOfBounds Instruction U2 Frame BasicBlock | |
| IncompatibleFrameMerge Frame Frame | |
| MissingBlockFrame Int |
Instances
| Show StackMapError Source # | |
Defined in H2JVM.Analyse.StackMap Methods showsPrec :: Int -> StackMapError -> ShowS # show :: StackMapError -> String # showList :: [StackMapError] -> ShowS # | |