Capture scope variables into Lambdas

Juan Fumero juan.fumero at
Tue May 24 13:10:27 UTC 2016

Hi all, 
   I would like to do capture variables in lambda expression with

I used to do it with Reflection as follow: 

 public void testScopeWithReflection() 
    throws IllegalArgumentException, IllegalAccessException {

    final int[] a = new int[]{100, 200, 300};

    Function<Integer, Double> lambdaFunction = (x -> x + 2.0 + a[0]);

    Field[] declaredFields =
    Object scoped = null;
    for (int i = 0; i < declaredFields.length; i++) {
        scoped = declaredFields[i].get(lambdaFunction);
    assertTrue(scoped instanceof int[]);
    assertEquals(a, scoped);

So the output I get is the variables I introduce into the lambda. 
What I would like to do is the same but from the GraalIR instead. 
I do not have the "lambdaFunction.getClass()" in the part of the
compiler I am writing now, only the GraalIR. 

Is it possible to do it in the GraalIR level? Any idea? For each 
variable I introduce in the scope,  I can see a new ParameterNode in
the GraalIR. I can get the type, but I also want the value.

Here a unittest: 

Many thanks


The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

More information about the graal-dev mailing list