Bug 58669 - does not detect all cpu cores/threads
does not detect all cpu cores/threads
Status: ASSIGNED
Product: gcc
Classification: Unclassified
Component: java
4.8.1
: P3 normal
: ---
Assigned To: Andrew John Hughes
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-10-09 15:54 UTC by Folkert van Heusden
Modified: 2013-10-18 01:17 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-10-09 00:00:00


Attachments
example code (133 bytes, text/plain)
2013-10-09 15:54 UTC, Folkert van Heusden
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Folkert van Heusden 2013-10-09 15:54:00 UTC
Created attachment 30970 [details]
example code

When a java program compiled with gcj asks how many processing units are in the system, it always returns 1.

folkert@belle:~$ cat test2.java
class test2 {
        public static void main(String [] args) {
                System.out.println("" + Runtime.getRuntime().availableProcessors());
        }
}
folkert@belle:~$ javac test2.java
folkert@belle:~$ java test2
12
folkert@belle:~$ gcj --main=test2 test2.java
folkert@belle:~$ ./a.out
1
Comment 1 Andrew John Hughes 2013-10-09 16:27:34 UTC
jint
java::lang::Runtime::availableProcessors (void)
{
  // FIXME: find the real value.                                                                                                
  return 1;
}

:)
Comment 2 Andrew John Hughes 2013-10-09 16:35:18 UTC
This is easily fixed with sysconf(_SC_NPROCESSORS_ONLN);
Comment 3 Folkert van Heusden 2013-10-09 16:36:10 UTC
Did some googling and with appropriate #ifdefs it should be at least on linux possible to retrieve this value:

sysconf(_SC_NPROCESSORS_ONLN);

If that function can't figure it out, it will return '1' which is somewhat sensible.

On http://stackoverflow.com/questions/150355/programmatically-find-the-number-of-cores-on-a-machine I found a whole list of implementations for windows, *bsd, macos, aix, well I think all relevant platforms.
Also http://stackoverflow.com/questions/4586405/get-number-of-cpus-in-linux-using-c gives some ideas.

If there's any further help I can do; let me know.
Comment 4 Andrew John Hughes 2013-10-09 18:36:10 UTC
Yes, I just said that above.  I'll propose a patch when I get chance.
Comment 5 Andrew John Hughes 2013-10-09 18:36:38 UTC
Thanks for reporting this.  I'll let you know when a fix is committed.
Comment 6 Andrew John Hughes 2013-10-18 01:17:09 UTC
http://gcc.gnu.org/ml/java-patches/2013-q4/msg00000.html