Bug 58669 - does not detect all cpu cores/threads
Summary: does not detect all cpu cores/threads
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 4.8.1
: P3 normal
Target Milestone: ---
Assignee: Andrew John Hughes
Depends on:
Reported: 2013-10-09 15:54 UTC by Folkert van Heusden
Modified: 2016-09-30 22:48 UTC (History)
2 users (show)

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

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

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
folkert@belle:~$ gcj --main=test2 test2.java
folkert@belle:~$ ./a.out
Comment 1 Andrew John Hughes 2013-10-09 16:27:34 UTC
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:


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
Comment 7 Andrew Pinski 2016-09-30 22:48:28 UTC
Closing as won't fix as the Java front-end has been removed from the trunk.