* src/native/vm/gnu/java_lang_VMRuntime.c (vm/system.h): Added.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Mon, 1 Oct 2007 12:54:33 +0000 (14:54 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Mon, 1 Oct 2007 12:54:33 +0000 (14:54 +0200)
(availableProcessors): Use system_processors_online.

* src/vm/Makefile.am (libvm_la_SOURCES): Added system.[ch].

* src/vm/system.c: New file.
* src/vm/system.h: Likewise.

src/native/vm/gnu/java_lang_VMRuntime.c
src/vm/Makefile.am
src/vm/system.c [new file with mode: 0644]
src/vm/system.h [new file with mode: 0644]

index b17cb4a2359476efe2d3f55372f934e48f09dd90..098e183d56b52bbe3353f67a9da92af2f3719236 100644 (file)
 #include "vm/builtin.h"
 #include "vm/exceptions.h"
 #include "vm/stringlocal.h"
+#include "vm/system.h"
 #include "vm/vm.h"
 
 #include "vmcore/utf8.h"
 
 
-/* this should work on BSD */
-/*
-#if defined(__DARWIN__)
-#include <sys/sysctl.h>
-#endif
-*/
-
-
 /* native methods implemented by this file ************************************/
 
 static JNINativeMethod methods[] = {
@@ -229,42 +222,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMRuntime_traceMethodCalls(JNIEnv *env, jc
  */
 JNIEXPORT int32_t JNICALL Java_java_lang_VMRuntime_availableProcessors(JNIEnv *env, jclass clazz)
 {
-#if defined(_SC_NPROC_ONLN)
-       return (int32_t) sysconf(_SC_NPROC_ONLN);
-
-#elif defined(_SC_NPROCESSORS_ONLN)
-       return (int32_t) sysconf(_SC_NPROCESSORS_ONLN);
-
-#elif defined(__DARWIN__)
-       /* this should work in BSD */
-       /*
-       int ncpu, mib[2], rc;
-       size_t len;
-
-       mib[0] = CTL_HW;
-       mib[1] = HW_NCPU;
-       len = sizeof(ncpu);
-       rc = sysctl(mib, 2, &ncpu, &len, NULL, 0);
-
-       return (int32_t) ncpu;
-       */
-
-       host_basic_info_data_t hinfo;
-       mach_msg_type_number_t hinfo_count = HOST_BASIC_INFO_COUNT;
-       kern_return_t rc;
-
-       rc = host_info(mach_host_self(), HOST_BASIC_INFO,
-                                  (host_info_t) &hinfo, &hinfo_count);
-       if (rc != KERN_SUCCESS) {
-               return -1;
-       }
-
-    return (int32_t) hinfo.avail_cpus;
-
-#else
-       return 1;
-#endif
+       return system_processors_online();
 }
 
 
index bdc79e4f8426bc0833e0ea80d2aa1d6f401bc296..26b98a95ecf420b986e102b679d31f7e1ebd27c2 100644 (file)
@@ -71,6 +71,8 @@ libvm_la_SOURCES = \
        signallocal.h \
        string.c \
        stringlocal.h \
+       system.c \
+       system.h \
        vm.c \
        vm.h
 
diff --git a/src/vm/system.c b/src/vm/system.c
new file mode 100644 (file)
index 0000000..1298f0f
--- /dev/null
@@ -0,0 +1,108 @@
+/* src/vm/system.c - system (OS) functions
+
+   Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
+   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+   J. Wenninger, Institut f. Computersprachen - TU Wien
+
+   This file is part of CACAO.
+
+   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.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+#include <unistd.h>
+
+/* this should work on BSD */
+/*
+#if defined(__DARWIN__)
+#include <sys/sysctl.h>
+#endif
+*/
+
+
+/* system_processors_online ****************************************************
+
+   Returns the number of online processors in the system.
+
+   RETURN:
+       online processor count
+
+*******************************************************************************/
+
+int system_processors_online(void)
+{
+#if defined(_SC_NPROC_ONLN)
+
+       return (int) sysconf(_SC_NPROC_ONLN);
+
+#elif defined(_SC_NPROCESSORS_ONLN)
+
+       return (int) sysconf(_SC_NPROCESSORS_ONLN);
+
+#elif defined(__DARWIN__)
+
+       /* this should work in BSD */
+       /*
+       int ncpu, mib[2], rc;
+       size_t len;
+
+       mib[0] = CTL_HW;
+       mib[1] = HW_NCPU;
+       len = sizeof(ncpu);
+       rc = sysctl(mib, 2, &ncpu, &len, NULL, 0);
+
+       return (int32_t) ncpu;
+       */
+
+       host_basic_info_data_t hinfo;
+       mach_msg_type_number_t hinfo_count = HOST_BASIC_INFO_COUNT;
+       kern_return_t rc;
+
+       rc = host_info(mach_host_self(), HOST_BASIC_INFO,
+                                  (host_info_t) &hinfo, &hinfo_count);
+       if (rc != KERN_SUCCESS) {
+               return -1;
+       }
+
+    return (int) hinfo.avail_cpus;
+
+#else
+
+       return 1;
+
+#endif
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
diff --git a/src/vm/system.h b/src/vm/system.h
new file mode 100644 (file)
index 0000000..0d052da
--- /dev/null
@@ -0,0 +1,55 @@
+/* src/vm/system.h - system (OS) functions
+
+   Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
+   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+   J. Wenninger, Institut f. Computersprachen - TU Wien
+
+   This file is part of CACAO.
+
+   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.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+*/
+
+
+#ifndef _VM_SYSTEM_H
+#define _VM_SYSTEM_H
+
+#include "config.h"
+
+#include <stdint.h>
+
+
+/* function prototypes ********************************************************/
+
+int system_processors_online(void);
+
+#endif /* _VM_SYSTEM_H */
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */