h2jvm
Safe HaskellNone
LanguageGHC2021

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

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

Instances details
Show BasicBlock Source # 
Instance details

Defined in H2JVM.Analyse.StackMap

Eq BasicBlock Source # 
Instance details

Defined in H2JVM.Analyse.StackMap

data Frame Source #

Represents the JVM frame state at a particular program point.

Constructors

Frame 

Fields

  • locals :: [LocalVariable]

    The local variable slots

  • stack :: [StackEntry]

    The operand stack, with the top of stack at the head

Instances

Instances details
Show Frame Source # 
Instance details

Defined in H2JVM.Analyse.StackMap

Methods

showsPrec :: Int -> Frame -> ShowS #

show :: Frame -> String #

showList :: [Frame] -> ShowS #

Eq Frame Source # 
Instance details

Defined in H2JVM.Analyse.StackMap

Methods

(==) :: Frame -> Frame -> Bool #

(/=) :: Frame -> Frame -> Bool #

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

Instances details
Show LocalVariable Source # 
Instance details

Defined in H2JVM.Analyse.StackMap

Eq LocalVariable Source # 
Instance details

Defined in H2JVM.Analyse.StackMap

Pretty LocalVariable Source # 
Instance details

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).