Skip to content
Java bytecode type inference and stack map computation using BCEL
Java
Branch: master
Clone or download
Latest commit 86b26e1 Sep 23, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.settings First commit from pre-Java 9 project Sep 23, 2019
lib First commit from pre-Java 9 project Sep 23, 2019
src Addec ompyright notice Sep 23, 2019
.classpath First commit from pre-Java 9 project Sep 23, 2019
.gitignore First commit from pre-Java 9 project Sep 23, 2019
.project First commit from pre-Java 9 project Sep 23, 2019
LICENSE Added LICENSE Sep 23, 2019
README.md Update README.md Sep 23, 2019
build.xml Addec ompyright notice Sep 23, 2019

README.md

BCEL Utils

BCEL utilities for inferring types in Java bytecode and for recomputing stack maps for a method. A stack map is compulsory from Java bytecode version 50 and higher. It specifies types at specific program points, ie., at targets of jumps. Compilers generate code with stack map tables, but code instrumentation might invalidate them. These utilities allow one to recompute stack map tables after code instrumentation with the BCEL library for bytecode instrumentation.

Type Inference

Given a BCEL MethodGen named m, this library allows one to infer the types at each of its instruction by computing

TypeInferrer inferrer = new TypeInferrer(m);

Types at each instruction handle ih in m can then be accessed by using an intuitive API, as in the following example:

Types types = inferrer.getTypesAt(ih);
int stackHeight = types.stackHeight();
int localsCount = types.localsCount();
Type top = types.getStack(stackHeight - 1);
Type local0 = types.getLocal(0);

Stack-Map Inference

Given a BCEL MethodGen named m (with or without a stack map), this library allows one to infer a new stack map for m by computing

Optional<StackMap> = new StackMapInferrer(m).getStackMap();

The result is Optional since not all methods need a stack map.

Stack-Map Recomputation

Given a BCEL MethodGen named m (with or without a stack map), this library allows one to modify m by removing its old stack map (if any) and adding a new inferred stack map for it (if needed), by computing:

StackMapReplacer.replace(m);
You can’t perform that action at this time.