From: Markus H. <ma...@ti...> - 2009-11-19 09:48:59
Attachments:
smime.p7s
|
Hi, I have the following java code: if(args==null){ System.out.println(1); }else{ try{ System.out.println(2); } catch(Exception e){ System.out.println(3); } } It gets converted to the following ObjectiveC code (only relevant part here) if (_op1.o != [NSNull null]) goto label0; _op1.o = [java_lang_System _GET_out]; _stack[_sp++].o = _op1.o; _stack[_sp++].i = 1; _sp -= 2; [((java_io_PrintStream*) _stack[_sp].o) println___int:_stack[_sp + 1].i]; goto label1; @try { label0:; _op1.o = [java_lang_System _GET_out]; _stack[_sp++].o = _op1.o; _stack[_sp++].i = 2; _sp -= 2; [((java_io_PrintStream*) _stack[_sp].o) println___int:_stack[_sp + 1].i]; } @catch (java_lang_Exception* _ex) { _stack[_sp++].o = _ex; goto label7; } This code crashes. The label0 is inside the try and the code jumps into it from the outside. This seems not to be allowed in ObjectiveC. if I move the label0:; before the try manually, it works. The xsl would need to be changed, so that if there is a jvm:label directly after a jvm:catch, they have to be swapped. I tried but wasn't able to do this myself. Don't know if it has any side effects, too :/ Markus |
From: Arno P. <ar...@pu...> - 2009-11-19 13:02:47
|
that is a known bug. Flow control in the JVM is represented by absolute jumps which we simply map to gotos in Objective-C. Exceptions sometimes cause the problems you are experiencing. We have discussed for a long time to convert the stack machine to register machine that would also reverse engineer flow control by removing the gotos. This is no easy matter and is further down on our to-do list. In the meantime you can probably get around the problem by inserting a dummy statement just before the try. Something like: } else { int x = 42; try { Arno Markus Heberling wrote: > Hi, > > I have the following java code: > > if(args==null){ > System.out.println(1); > }else{ > try{ > System.out.println(2); > > } catch(Exception e){ > System.out.println(3); > > } > } > > It gets converted to the following ObjectiveC code (only relevant part here) > > if (_op1.o != [NSNull null]) goto label0; > _op1.o = [java_lang_System _GET_out]; > _stack[_sp++].o = _op1.o; > _stack[_sp++].i = 1; > _sp -= 2; > [((java_io_PrintStream*) _stack[_sp].o) println___int:_stack[_sp + 1].i]; > goto label1; > @try { > label0:; > _op1.o = [java_lang_System _GET_out]; > _stack[_sp++].o = _op1.o; > _stack[_sp++].i = 2; > _sp -= 2; > [((java_io_PrintStream*) _stack[_sp].o) println___int:_stack[_sp + 1].i]; > } @catch (java_lang_Exception* _ex) { > _stack[_sp++].o = _ex; > goto label7; > } > > This code crashes. The label0 is inside the try and the code jumps into it from the outside. This seems not to be allowed in ObjectiveC. if I move the label0:; before the try manually, it works. The xsl would need to be changed, so that if there is a jvm:label directly after a jvm:catch, they have to be swapped. I tried but wasn't able to do this myself. Don't know if it has any side effects, too :/ > > Markus > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > > > ------------------------------------------------------------------------ > > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users |
From: Markus H. <ma...@ti...> - 2009-11-19 16:31:50
Attachments:
smime.p7s
|
Hi, Unfortunatly I can't change the code. I'm porting microemulator over and don't want to enforce this in all MIDlets that would be converted with it. I have tried a bit more and have now this solution: <xsl:template match="jvm:catch"> <xsl:choose> <xsl:when test="./*[1][@id]"> <xsl:text> label</xsl:text> <xsl:value-of select="./jvm:label[1]/@id"/> <xsl:text>:; </xsl:text> </xsl:when> </xsl:choose> <xsl:text> @try { </xsl:text> <xsl:choose> <xsl:when test="./*[1][@id]"> <xsl:apply-templates select="./*[position()>1]"/> </xsl:when> <xsl:otherwise> <xsl:apply-templates/> </xsl:otherwise> </xsl:choose> <xsl:text> } @catch (</xsl:text> <xsl:value-of select="vm:fixname(@type)"/> <xsl:text>* _ex) { _stack[_sp++].o = _ex; goto label</xsl:text> <xsl:value-of select="@using"/> <xsl:text>; } </xsl:text> </xsl:template> This works fine for me and puts the labelX:; before the @try, if it finds one diretly after it. Does this make any sense? I don't know if his could have any sideeffects, but for me its working at least. Markus Am 19.11.2009 um 14:02 schrieb Arno Puder: > > that is a known bug. Flow control in the JVM is represented by absolute jumps which we simply map to gotos in Objective-C. Exceptions sometimes cause the problems you are experiencing. We have discussed for a long time to convert the stack machine to register machine that would also reverse engineer flow control by removing the gotos. This is no easy matter and is further down on our to-do list. In the meantime you can probably get around the problem by inserting a dummy statement just before the try. Something like: > > } else { > int x = 42; > try { > > Arno > > > Markus Heberling wrote: >> Hi, >> I have the following java code: >> if(args==null){ >> System.out.println(1); >> }else{ >> try{ >> System.out.println(2); >> } catch(Exception e){ >> System.out.println(3); >> } >> } >> It gets converted to the following ObjectiveC code (only relevant part here) >> if (_op1.o != [NSNull null]) goto label0; >> _op1.o = [java_lang_System _GET_out]; >> _stack[_sp++].o = _op1.o; >> _stack[_sp++].i = 1; >> _sp -= 2; >> [((java_io_PrintStream*) _stack[_sp].o) println___int:_stack[_sp + 1].i]; >> goto label1; >> @try { >> label0:; >> _op1.o = [java_lang_System _GET_out]; >> _stack[_sp++].o = _op1.o; >> _stack[_sp++].i = 2; >> _sp -= 2; >> [((java_io_PrintStream*) _stack[_sp].o) println___int:_stack[_sp + 1].i]; >> } @catch (java_lang_Exception* _ex) { >> _stack[_sp++].o = _ex; >> goto label7; >> } >> This code crashes. The label0 is inside the try and the code jumps into it from the outside. This seems not to be allowed in ObjectiveC. if I move the label0:; before the try manually, it works. The xsl would need to be changed, so that if there is a jvm:label directly after a jvm:catch, they have to be swapped. I tried but wasn't able to do this myself. Don't know if it has any side effects, too :/ >> Markus >> ------------------------------------------------------------------------ >> ------------------------------------------------------------------------------ >> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with >> Crystal Reports now. http://p.sf.net/sfu/bobj-july >> ------------------------------------------------------------------------ >> _______________________________________________ >> xmlvm-users mailing list >> xml...@li... >> https://lists.sourceforge.net/lists/listinfo/xmlvm-users |
From: Gergely K. <ger...@ma...> - 2009-11-20 09:12:05
|
Hi, Would it makes sense to add DEX, the Android bytecode format as a new "source language" to xmlvm? Since it is already designed to execute on a register machine, it might be easier to implement. Best Regards, Gergely 2009/11/19 Arno Puder <ar...@pu...> > > that is a known bug. Flow control in the JVM is represented by absolute > jumps which we simply map to gotos in Objective-C. Exceptions sometimes > cause the problems you are experiencing. We have discussed for a long > time to convert the stack machine to register machine that would also > reverse engineer flow control by removing the gotos. This is no easy > matter and is further down on our to-do list. In the meantime you can > probably get around the problem by inserting a dummy statement just > before the try. Something like: > > } else { > int x = 42; > try { > > Arno > > > Markus Heberling wrote: > > Hi, > > > > I have the following java code: > > > > if(args==null){ > > System.out.println(1); > > }else{ > > try{ > > System.out.println(2); > > > > } catch(Exception e){ > > System.out.println(3); > > > > } > > } > > > > It gets converted to the following ObjectiveC code (only relevant part > here) > > > > if (_op1.o != [NSNull null]) goto label0; > > _op1.o = [java_lang_System _GET_out]; > > _stack[_sp++].o = _op1.o; > > _stack[_sp++].i = 1; > > _sp -= 2; > > [((java_io_PrintStream*) _stack[_sp].o) println___int:_stack[_sp + > 1].i]; > > goto label1; > > @try { > > label0:; > > _op1.o = [java_lang_System _GET_out]; > > _stack[_sp++].o = _op1.o; > > _stack[_sp++].i = 2; > > _sp -= 2; > > [((java_io_PrintStream*) _stack[_sp].o) println___int:_stack[_sp + > 1].i]; > > } @catch (java_lang_Exception* _ex) { > > _stack[_sp++].o = _ex; > > goto label7; > > } > > > > This code crashes. The label0 is inside the try and the code jumps into > it from the outside. This seems not to be allowed in ObjectiveC. if I move > the label0:; before the try manually, it works. The xsl would need to be > changed, so that if there is a jvm:label directly after a jvm:catch, they > have to be swapped. I tried but wasn't able to do this myself. Don't know if > it has any side effects, too :/ > > > > Markus > > > > > > ------------------------------------------------------------------------ > > > > > ------------------------------------------------------------------------------ > > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 > 30-Day > > trial. Simplify your report design, integration and deployment - and > focus on > > what you do best, core application coding. Discover what's new with > > Crystal Reports now. http://p.sf.net/sfu/bobj-july > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > xmlvm-users mailing list > > xml...@li... > > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus > on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > -- Kis Gergely MattaKis Consulting Email: ger...@ma... Web: http://www.mattakis.com Phone: +36 70 408 1723 |
From: Arno P. <ar...@pu...> - 2009-11-20 09:23:32
|
Remember that we use JVM instructions as a canonical representation within XMLVM. We can convert CLR and YARV (Ruby byte code) to JVM instructions. It would be nice if we could transform this canonical representation of JVM instructions to something like DEX instructions. The result would be an XML document representing a register-based version of the stack-based program. Remember that XMLVM has various backends and we already have a prototype that emits JavaScript for the Palm Pre. We would need this XML representation of register-machine instructions for all the code generating backends of XMLVM. I don't know if DEX offers any libraries with which we can do this. Another byte code optimization framework that might be suitable for such a task is Soot: http://www.sable.mcgill.ca/soot/ Either way, no small feat... Arno Gergely Kis wrote: > Hi, > > Would it makes sense to add DEX, the Android bytecode format as a new > "source language" to xmlvm? > Since it is already designed to execute on a register machine, it might > be easier to implement. > > Best Regards, > Gergely > > 2009/11/19 Arno Puder <ar...@pu... <mailto:ar...@pu...>> > > > that is a known bug. Flow control in the JVM is represented by absolute > jumps which we simply map to gotos in Objective-C. Exceptions sometimes > cause the problems you are experiencing. We have discussed for a long > time to convert the stack machine to register machine that would also > reverse engineer flow control by removing the gotos. This is no easy > matter and is further down on our to-do list. In the meantime you can > probably get around the problem by inserting a dummy statement just > before the try. Something like: > > } else { > int x = 42; > try { > > Arno > > > Markus Heberling wrote: > > Hi, > > > > I have the following java code: > > > > if(args==null){ > > System.out.println(1); > > }else{ > > try{ > > System.out.println(2); > > > > } catch(Exception e){ > > System.out.println(3); > > > > } > > } > > > > It gets converted to the following ObjectiveC code (only relevant > part here) > > > > if (_op1.o != [NSNull null]) goto label0; > > _op1.o = [java_lang_System _GET_out]; > > _stack[_sp++].o = _op1.o; > > _stack[_sp++].i = 1; > > _sp -= 2; > > [((java_io_PrintStream*) _stack[_sp].o) > println___int:_stack[_sp + 1].i]; > > goto label1; > > @try { > > label0:; > > _op1.o = [java_lang_System _GET_out]; > > _stack[_sp++].o = _op1.o; > > _stack[_sp++].i = 2; > > _sp -= 2; > > [((java_io_PrintStream*) _stack[_sp].o) > println___int:_stack[_sp + 1].i]; > > } @catch (java_lang_Exception* _ex) { > > _stack[_sp++].o = _ex; > > goto label7; > > } > > > > This code crashes. The label0 is inside the try and the code > jumps into it from the outside. This seems not to be allowed in > ObjectiveC. if I move the label0:; before the try manually, it > works. The xsl would need to be changed, so that if there is a > jvm:label directly after a jvm:catch, they have to be swapped. I > tried but wasn't able to do this myself. Don't know if it has any > side effects, too :/ > > > > Markus > > > > > > > ------------------------------------------------------------------------ > > > > > ------------------------------------------------------------------------------ > > Let Crystal Reports handle the reporting - Free Crystal Reports > 2008 30-Day > > trial. Simplify your report design, integration and deployment - > and focus on > > what you do best, core application coding. Discover what's new with > > Crystal Reports now. http://p.sf.net/sfu/bobj-july > > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > xmlvm-users mailing list > > xml...@li... > <mailto:xml...@li...> > > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 > 30-Day > trial. Simplify your report design, integration and deployment - and > focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > xmlvm-users mailing list > xml...@li... > <mailto:xml...@li...> > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > > > > > -- > Kis Gergely > MattaKis Consulting > Email: ger...@ma... <mailto:ger...@ma...> > Web: http://www.mattakis.com > Phone: +36 70 408 1723 > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > > > ------------------------------------------------------------------------ > > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users |