Graph for lambda expression

Juan Jose Fumero juan.fumero at ed.ac.uk
Mon Mar 31 17:41:25 UTC 2014


Hello, 
   
   I am working with some transformations in the lambda graph. I am
trying to create a new object in the lambda expression and return it.
The input of the lambda expression, let say, is the type A and the
return type is different (type B). The thing is I get different graphs
if I declare and create at least one object of type B before the
lambda. 

Here is a little testcase. 

     7	package com.gpu.stream.test;
     8	
     9	public class TestCase {
    10	    
    11	    public static void main(String []args) {
    12	        
    13	        Tuple1<Integer>[] tuple1 = new Tuple1[N];
    14	        // tuple1[0] = new Tuple1<>();    // --> here
    15	        
    16	        Stream<Integer> streamTuple1 = new Stream();
    17	        tuple1 = stream.map(
    18	             x -> {
    19	                    int i = x;
    20	                    Tuple1<Integer> t1 = new Tuple1<>();
    21	                    t1._1(x);
    22	                    return t1;
    23	           }).run(v1);
    24	    }
    25	}


Stream is a method which receives a Function<T,R> in jdk8. The input of
this function is an Integer and the output should be a Tuple1 object
created in the lambda expression. 

The class Tuple1 class is very simple: 

     7	package com.gpu.stream.test;
     8	public class Tuple1<T> {
     9	        public T _1;
    10	  
    11	        public T _1() {
    12	            return this._1;
    13	        }
    14	     
    15	        public void _1(T _1) {
    16	            this._1 = _1;
    17	        }
    18	    }


If I run the program TestCase and print the graph (note the line 14 is
commented), I get the following graph for the lambda expression:


0|StartNode
1|Parameter(0)
2|FrameState at 0
3|Deopt
4|IsNull
5|GuardingPi

I expected at least the NewInstanceNode and the ReturnNode. If I
uncomment the line 14 in TestCase, the graph is the following:

0|StartNode
1|Parameter(0)
2|FrameState at 0
3|NewInstance
4|Return
5|IsNull
6|GuardingPi
7|StoreField#_1
8|FrameState at 5
9|FrameState at 15


In this case I would say the graph is correct. It contains the
NewInstanceNode, ReturnNode and StoreFieldNodes. 


Is this the right behaviour? Why I need to create at least one object? 


Note: I am calling to the optimisations in Graal like Inlining, but if I
do not call to the optimisations, the result is the same. 


Any idea?

Thanks
Juanjo


-- 
PhD Student
University of Edinburgh


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



More information about the graal-dev mailing list