Wednesday, June 25, 2008

multianewarray byte instruction in Jato

I think, multianewarray instruction was the most tough one that I have confronted so far while working on Jato. But with the help of Pekka Enberg, finally I was able to creep out of the abyss.

Initially , I assumed (very naively) that the counts for multianewarray instruction would be pushed in expression stack as EXPR_VALUE expressions. But then, Pekka pointed out that it does not work for every situation. For example, it will break in the following code :
   public int[][] newArray(int x, int y) {
return new int[x][y];

The better way would be, as Pekka suggested, to 'abuse' the EXPR_ARG. That is , converting each count expression to argument expression, so that instruction selector can automatically push appropriate values on the stack.

So in multianewarrray byte code handler, what I do is, after popping dimension values from the expression stack, wrap each expression into EXPR_ARGS. Then, in instruction selection and code emission phase, as all the count values are already pushed on stack, all I need to do is, make a call to array allocation function in jamvm.

Easy as pie , when you are in right track !

No comments: