System.out.printf not working under jamvm on SBC

Supporting Java SE version 7 and up
richfiddler11
Phidgeteer!
Posts: 55
Joined: Mon May 24, 2010 2:05 pm
Contact:

System.out.printf not working under jamvm on SBC

Postby richfiddler11 » Wed Jul 07, 2010 8:10 am

Hi,

I can't seem to get System.out.printf() working with jamvm on the SBC (latest firmware). This sample program

Code: Select all

package helloworldapp;
public class Main {
    public static void main(String[] args) {
       System.out.println("pi = " + Math.PI);
       System.out.printf ("pi = %5.3f%n", Math.PI);
    }
}


outputs this with Sun JVM 1.60 on x86/Linux (as expected):

Code: Select all

pi = 3.141592653589793
pi = 3.142


but on the SBC with jamvm I just get

Code: Select all

pi = 3.141592653589793
pi =


Any ideas?

Here's the jamvm version info:

Code: Select all

# jamvm -version
java version "1.5.0"
JamVM version 1.5.1
Copyright (C) 2003-2008 Robert Lougher <rob@lougher.org.uk>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2,
or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

Build information:

Execution Engine: direct-threaded interpreter with stack-caching
Compiled with: gcc 4.3.4

Boot Library Path: /usr/lib/classpath
Boot Class Path: /usr/share/jamvm/classes.zip:/usr/share/classpath/glibj.zip

richfiddler11
Phidgeteer!
Posts: 55
Joined: Mon May 24, 2010 2:05 pm
Contact:

Re: System.out.printf not working under jamvm on SBC

Postby richfiddler11 » Thu Jul 08, 2010 1:40 am

I went back and tested this with the 1.0.4 full image from phidgets.com (vs. the one I built myself) and confirmed that the problem still exists with your binaries.

The loss of System.out.printf() itself isn't a showstopper, but it concerns me as to whether there are any other latent jamvm problems.

RBBT
Phidgeteer!
Posts: 90
Joined: Sun Nov 15, 2009 2:16 pm
Location: Lower Bavaria (Germany)
Contact:

Re: System.out.printf not working under jamvm on SBC

Postby RBBT » Thu Jul 08, 2010 6:14 am

Best Regards from Lower Bavaria
RBBT
http://www.robobuam.de/

richfiddler11
Phidgeteer!
Posts: 55
Joined: Mon May 24, 2010 2:05 pm
Contact:

Re: System.out.printf not working under jamvm on SBC

Postby richfiddler11 » Thu Jul 08, 2010 9:21 am

Hi,

Thanks, I re-read the post very carefully and the subsequent links (jamvm.sourceforge.net, etc) but am not seeing anything helpful other than gnu classpath doesn't provide 100% compatibility with Sun's libraries.

If you're saying that gnu classpath doesn't support System.out.printf() then programs calling it should fail to compile, right? This simply doesn't work as expected.

It seems to be an arm-specific bug somewhere between jamvm and gnu classpath, but hard to say who is at fault and how to fix it.

I was hoping the phidgets folks might at least make a comment on this.

Thanks,

Rich

RBBT
Phidgeteer!
Posts: 90
Joined: Sun Nov 15, 2009 2:16 pm
Location: Lower Bavaria (Germany)
Contact:

Re: System.out.printf not working under jamvm on SBC

Postby RBBT » Thu Jul 08, 2010 10:48 am

richfiddler11 wrote:
If you're saying that gnu classpath doesn't support System.out.printf() then programs calling it should fail to compile, right? This simply doesn't work as expected.


You're right.
Best Regards from Lower Bavaria
RBBT
http://www.robobuam.de/

richfiddler11
Phidgeteer!
Posts: 55
Joined: Mon May 24, 2010 2:05 pm
Contact:

Re: System.out.printf not working under jamvm on SBC

Postby richfiddler11 » Thu Jul 08, 2010 12:45 pm

It looks like formatting might be broken in general with jamvm/gnu classpath on the SBC.

I tried a Scanner test to read a double -- works fine on sun jvm 1.6/x86 Linux, but throws an exception on jamvm on the SBC

The jamvm project bugtracker suggests that this may be a gnu classpath bug, see
http://sourceforge.net/tracker/index.php?func=detail&aid=1185350&group_id=75148&atid=543058

Quote from Robert Lougher, the jamvm developer, pulled from this link:
Yes, it is the same problem as bug 1283728.

The problem is the double->string conversion code which is
part of GNU Classpath. This assumes pure-endianness
(basically everything but ARM fpa). It breaks on the mixed-
endianness of ARM fpa.

This means arithmetic, etc. using ARM fpa is correct, as it is
internal to the VM, but printing is broken. You can confirm
this by doing some arithmetic using doubles, and then
printing the result after converting it to an int (or long)
after
multiplying up (e.g (int)(0.5*10) -> 5).

There is a bug already raised with GNU Classpath. Closing as not a bug
in JamVM...



Here's my test case:

Code: Select all

package formattest;
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
       String s1 = new String("25.5");
       Scanner sc = new Scanner(s1);
       double d = sc.nextDouble();
       System.out.println("Scanner read " + s1 + " as the double " + d);
    }
}


Here's the exception trace:

Code: Select all

# jamvm -jar formatTest.jar
java.lang.reflect.InvocationTargetException
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:367)
   at jamvm.java.lang.JarLauncher.main(JarLauncher.java:50)
Caused by: java.lang.IllegalArgumentException: arg type mismatch
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:367)
   at gnu.java.util.regex.RETokenNamedProperty$JavaCategoryHandler.includes(RETokenNamedProperty.java:397)
   at gnu.java.util.regex.RETokenNamedProperty.matchOneChar(RETokenNamedProperty.java:135)
   at gnu.java.util.regex.RETokenNamedProperty.findFixedLengthMatches(RETokenNamedProperty.java:162)
   at gnu.java.util.regex.RETokenRepeated.findMatchFixedLength(RETokenRepeated.java:560)
   at gnu.java.util.regex.RETokenRepeated.findMatch(RETokenRepeated.java:174)
   at gnu.java.util.regex.RETokenRepeated.match(RETokenRepeated.java:501)
   at gnu.java.util.regex.RE.match(RE.java:2101)
   at gnu.java.util.regex.RE.getMatchImpl(RE.java:2200)
   at gnu.java.util.regex.RE.getMatch(RE.java:2173)
   at gnu.java.util.regex.RE.getMatch(RE.java:2154)
   at java.util.regex.Matcher.find(Matcher.java:200)
   at java.util.Scanner.myCoreNext(Scanner.java:1630)
   at java.util.Scanner.myPrepareForNext(Scanner.java:2182)
   at java.util.Scanner.myNextDouble(Scanner.java:2032)
   at java.util.Scanner.nextDouble(Scanner.java:1082)
   at formattest.Main.main(Main.java:10)
   at java.lang.reflect.Method.invokeNative(Native Method)
   ...2 more

User avatar
Patrick
Lead Developer
Posts: 3109
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: System.out.printf not working under jamvm on SBC

Postby Patrick » Thu Jul 08, 2010 1:22 pm

Interesting. If it's a bug in classpath, is there a patch somewhere? It would be easy to add a patch in the buildroot - many packages are patched specifically for ARM / PhidgetSBC.

-Patrick

richfiddler11
Phidgeteer!
Posts: 55
Joined: Mon May 24, 2010 2:05 pm
Contact:

Re: System.out.printf not working under jamvm on SBC

Postby richfiddler11 » Thu Jul 08, 2010 2:23 pm

Hi Patrick,

Yeah, good question! I wish I could find it!

I can't find the gnu classpath issue Robert L. says is raised in the gnu classpath bug tracker. http://gcc.gnu.org/bugzilla/query.cgi?product=classpath

Here's the other jamvm issue that was closed as a problem with classpath:
http://sourceforge.net/tracker/?func=detail&aid=1283728&group_id=75148&atid=543058

Questions for you:

1) did System.out.printf(), Scanner.nextDouble(), etc. work OK with jamvm on phidgets full 1.0.3 firmware?
2) is there any chance that jamvm and/or classpath is not configured correctly for the new EABI?

It makes me suspicious that a floating-point related issue arises when changing the floating point ABI.

[Edit] So I went back and flashed my SBC to firmware 1.0.3 and formatting is broken just the same as 1.0.4, so I don't think it's anything to do with the EABI.


Return to “Java”

Who is online

Users browsing this forum: No registered users and 0 guests