Another approach to variable promotion

3 views
Skip to first unread message

aviad.in...@gmail.com

unread,
Aug 25, 2007, 1:48:29 AM8/25/07
to Infomancers-Yielder
Even though I would have preferred to promote the variable itself, I
could always promote the slot containing it in the frame. That way,
each time the slot itself is accessed, it will be changed so that a
slot-member is accessed.

aviad.in...@gmail.com

unread,
Aug 25, 2007, 1:59:51 AM8/25/07
to Infomancers-Yielder
Okay, after a little consideration of the matter I remember why I
haven't done this in the first place. The problem is that a slot can
be used for a multiple amount of types - It can be used once for a
local variable of type int, and later on for a local variable of type
String (using a ref). Using the visitLocalVariable, I could get the
scope of each slot for each type. Without it, how can it be
calculated?

aviad.in...@gmail.com

unread,
Aug 25, 2007, 2:02:17 AM8/25/07
to Infomancers-Yielder
I suppose an easy solution would be to make all slot members as Object
types, and then box and unbox all the primitive local variables - but
that would be fugly as hell...

Anyone with a better idea?

mikeb01

unread,
Aug 28, 2007, 12:54:42 PM8/28/07
to Infomancers-Yielder
This blow up for me with the following exception:

java.lang.ClassFormatError: Field "slot$1" in class com/infomancers/
tests/YielderTests$1 has illegal signature "Ljava/lang/Object"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:
124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at com.infomancers.tests.YielderTests.array(YielderTests.java:23)

Would it be possible to determine the type of the variable based on
the type of instruction that stores the variable. E.g. astore -
object reference, istore - integer value.

Mike.

aviad.in...@gmail.com

unread,
Aug 28, 2007, 3:36:32 PM8/28/07
to Infomancers-Yielder
I didn't finish writing the code. The IntelliJ license expired as I
was writing it - I am waiting for the renewal license which should be
with me tomorrow. Technical issues...

You can read my post about the problems of determining the type of the
slot, but to be brief, the slot is an interchangeable 4 bytes
container. It can be used for anything, and in different scopes it can
be used for different types - That's why I originally used the
debugging information, since it contained the type for the slot at a
selected scope.

At the time I didn't realise it was the debugging information I was
using, though. It makes sense now that I think back to it. So, as I
said - I can't determine the type of the slot from the operations done
on it. I can, for optimisation's sake, try to determine it by scanning
all the uses of the slot along a code segment and try to use a
primitive if its only used for that primitive type - but I prefer to
do optimisations after I get the yielder back to work, even on non-
debug code.

aviad.in...@gmail.com

unread,
Aug 29, 2007, 5:22:49 PM8/29/07
to Infomancers-Yielder
So, I've implemented the idea I had of autoboxing primitives into a
slots member.

This actually works great, except for anything to do with arrays.

Take for example the "arraySize" test. The yielder method is:

int[] l = arr;
yieldReturn(l.length);

Which needs to be translated to:

slot$1 = arr;
yieldReturn(((int[])slot$1).length);

But how can I infer that slot$1 is an array at any given time? I
couldn't think of a way, so I don't at the moment. Which causes the
following bytecode:

ALOAD 0
GETFIELD slot$1
ARRAYLENGTH

Which throws the VeryifyError of "Expecting to find array on stack" -
the loaded item into the stack needs to first be cast using a
CHECKCAST operator - but cast to what?

I'm too tired for this today. I'll try to resolve this tomorrow - But
in the meantime, see if the current version works for you without
debugging information (unless you're using arrays!)


On Aug 28, 7:54 pm, mikeb01 <mike...@gmail.com> wrote:

aviad.in...@gmail.com

unread,
Aug 30, 2007, 12:20:18 AM8/30/07
to Infomancers-Yielder
I guess I could use the java.lang.reflect.Array class instead of
ARRAYLENGTH, xALOAD and xASTORE.

aviad.in...@gmail.com

unread,
Aug 30, 2007, 12:28:42 AM8/30/07
to Infomancers-Yielder
On this matter, luckily the operand stack looks the same for xALOAD
and for the Array.getX methods, and the same for xASTORE and the
Array.setX methods.

aviad.in...@gmail.com

unread,
Aug 30, 2007, 1:00:07 AM8/30/07
to Infomancers-Yielder
Alright, it worked!

Get the latest trunk, it should be working without debugging
information. However, it is using the autoboxing method, and there is
still a minor bug with arrays of objects (Object[] or multidimensional
arrays). I'll fix it later today.

On Aug 30, 7:20 am, aviad.infomanc...@gmail.com wrote:

aviad.in...@gmail.com

unread,
Aug 30, 2007, 4:35:42 AM8/30/07
to Infomancers-Yielder
Now objects and multidimensional arrays work as well.

mikeb01

unread,
Aug 30, 2007, 1:24:10 PM8/30/07
to Infomancers-Yielder
I am still getting exceptions from the unit tests when debug is
disabled.

java.util.NoSuchElementException
at java.util.LinkedList.remove(LinkedList.java:788)
at java.util.LinkedList.removeLast(LinkedList.java:144)
at com.infomancers.collections.yield.asm.LocalVariableMapper
$MyMethodAdapter.visitVarInsn(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at
com.infomancers.collections.yield.asm.YielderTransformer.transform(Unknown
Source)

Mike.

aviad.in...@gmail.com

unread,
Aug 30, 2007, 4:03:02 PM8/30/07
to Infomancers-Yielder
That shouldn't be happening. Are you using the "=debug" flag when
launching the java agent (in the "-javaagent:" parameter?)

aviad.in...@gmail.com

unread,
Aug 30, 2007, 4:11:17 PM8/30/07
to Infomancers-Yielder
Try to use the new binary: http://code.google.com/p/infomancers-collections/downloads/list

On Aug 30, 8:24 pm, mikeb01 <mike...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages