For each variable which is used in the closure method add a field in the class
public class Main {
public static void main(String[] args) {
final String str = "Hello";
final Integer i = 5;
Lambda la = new Lambda() {
public void closure() {
System.out.println(str);
System.out.println(i);
}
};
System.out.println(str);
System.out.println(i);
la.closure();
}
}
adjust WriteFields: creates for each entry in stash a new field (optional: only fields which are really needed)
Bytecode
lambdas vector which contains the created lambdas
method to get the lambdas and one to check if given lambda was created by the code
add method get_local_variable_stash
add new field lambda_code which indicates that these bytecode is inside a lambda function
if flag is set variable push and pop methods should use field not the stash (fields are added in lambda_classfile_writer)
add local variable stash map which indicates/contains for the given lambda the current variables
backend
create lambdas classfiles inside the for loop of the bytecode generation (much faster)
adjust lambda_classfile creation method
add to the lambda_classfile_writer constantpool the names of local_variable_stash as field entries
types should be java/lang/Object ( object ref indicates later the right obj.)
For each variable which is used in the closure method add a field in the class
Main disas:
Main anonymous class $1