Jochen Theodorou wrote:
Alessio Stalla wrote:
On Thu, Oct 7, 2010 at 7:44 PM, Jochen Theodorou <[email protected]>
wrote:
[...]
How did you try to reproduce the problem in Java? What does javac
produce for your code? I remember having a vaguely similar problem,
but it involved reflection and private inner classes, and you don't
seem to be using any of those.
I did not try to insert the constructor call as of yet. I mostly tried
variants of the groovy code in Java, one time forced the CHECKCAST call,
since I thought this is the culprit. but no success.
javac produces:
NEW G4410JavaStringProducer
DUP
INVOKESPECIAL G4410JavaStringProducer.<init> ()V
ASTORE 2
I tried it now with this Java code:
CallSite[] csa = (new CallSiteArray(X.class,new String[1])).array;
Object tmp = csa[0].callConstructor(G4410JavaStringProducer.class);
tmp = ScriptBytecodeAdapter.castToType(tmp,
G4410JavaStringProducer.class);
G4410JavaStringProducer jsp = (G4410JavaStringProducer) tmp;
which is roughly what Groovy produces transfered to Java and this works
without problem. The generated bytecode for this is:
ALOAD 2
ICONST_0
AALOAD
LDC Lgroovy/bugs/G4410JavaStringProducer;.class
INVOKEINTERFACE
org/codehaus/groovy/runtime/callsite/CallSite.callConstructor
(Ljava/lang/Object;)Ljava/lang/Object;
ASTORE 3
ALOAD 3
LDC Lgroovy/bugs/G4410JavaStringProducer;.class
INVOKESTATIC org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType
(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
ASTORE 3
ALOAD 3
CHECKCAST groovy/bugs/G4410JavaStringProducer
ASTORE 4
for a direct compare here again the code from groovy:
ALOAD 1
LDC 3
AALOAD
INVOKESTATIC
groovy/bugs/test.$get$$class$groovy$bugs$G4410JavaStringProducer
()Ljava/lang/Class;
INVOKEINTERFACE
org/codehaus/groovy/runtime/callsite/CallSite.callConstructor
(Ljava/lang/Object;)Ljava/lang/Object;
ASTORE 5
ALOAD 5
INVOKESTATIC
groovy/bugs/test.$get$$class$groovy$bugs$G4410JavaStringProducer
()Ljava/lang/Class;
INVOKESTATIC org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType
(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
CHECKCAST groovy/bugs/G4410JavaStringProducer
ASTORE 6
apart from some obvious differences in the register numbers, one time
storing the result, the other time not the biggest difference is the
call to
groovy/bugs/test.$get$$class$groovy$bugs$G4410JavaStringProducer()
instead of the LDC, which is because groovy does here atm no generate
java5 bytecode.
oh, and the Java version has class name X, in Groovy it is test ;)
bye Jochen
--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/
--
You received this message because you are subscribed to the Google Groups "JVM
Languages" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jvm-languages?hl=en.