Graph for lambda expression
Krystal Mok
rednaxelafx at gmail.com
Mon Mar 31 17:58:24 UTC 2014
Hi Juan,
Out of total ignorance of Graal and Sumatra, this looks like you're hitting
a class initialization issue. If a class has not been initialized at the
time Graal compiles a method, then any use of that class will result in a
Deopt in Graal.
If you create an instance of Tuple1 before the stream.map(), it'll ensure
the Tuple1 class is initialized. You use other means to force
initialization of Tuple1, too, e.g. Class.forName(Tuple1.getName()). Try it
and see if it works the same. If it works, then it should be it.
BTW, new Tuple1<>[] will NOT force initialization of the Tuple1 class.
- Kris
On Mon, Mar 31, 2014 at 10:41 AM, Juan Jose Fumero <juan.fumero at ed.ac.uk>
wrote:
> 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