http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58669

Testing:

$ /usr/lib/jvm/icedtea-6/bin/java TestProcessors
Processors: 8

$ /usr/lib/jvm/gcj-jdk/bin/java -version
java version "1.5.0"
gij (GNU libgcj) version 4.8.1
$ /usr/lib/jvm/gcj-jdk/bin/java TestProcessors
Processors: 1

$ /home/andrew/build/gcj/bin/gij -version
java version "1.5.0"
gij (GNU libgcj) version 4.9.0 20131013 (experimental) [trunk revision 203508]
$ /home/andrew/build/gcj/bin/gij TestProcessors
Processors: 8

ChangeLog:

2013-10-12  Andrew John Hughes  <gnu.and...@member.fsf.org>

        * java/lang/natRuntime.cc:
        (availableProcessors()): Implement.
        Fixes PR gcc/58669.

Ok for trunk and 4.8?
-- 
Andrew :)

Free Java Software Engineer
Red Hat, Inc. (http://www.redhat.com)

PGP Key: 248BDC07 (https://keys.indymedia.org/)
Fingerprint = EC5A 1F5E C0AD 1D15 8F1F  8F91 3B96 A578 248B DC07
Index: libjava/java/lang/natRuntime.cc
===================================================================
--- libjava/java/lang/natRuntime.cc	(revision 203508)
+++ libjava/java/lang/natRuntime.cc	(working copy)
@@ -48,6 +48,10 @@
 #include <langinfo.h>
 #endif
 
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
 
 
 #ifdef USE_LTDL
@@ -303,8 +307,15 @@
 jint
 java::lang::Runtime::availableProcessors (void)
 {
-  // FIXME: find the real value.
-  return 1;
+  long procs = -1;
+
+#ifdef HAVE_UNISTD_H
+  procs = sysconf(_SC_NPROCESSORS_ONLN);
+#endif
+
+  if (procs == -1)
+    return 1;
+  return (jint) procs;
 }
 
 jstring

Attachment: signature.asc
Description: Digital signature

Reply via email to