vmruntime.c
来自「linux下建立JAVA虚拟机的源码KAFFE」· C语言 代码 · 共 103 行
C
103 行
/* src/native/vm/VMRuntime.c - java/lang/VMRuntime Copyright (C) 1996-2005 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 Copyright (C) 2005 Dalibor Topic This file was taken from CACAO. More information on CACAO project is available at http://www.cacaojvm.org 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Contact: cacao@complang.tuwien.ac.at Authors: Roman Obermaiser Changes: Joseph Wenninger Christian Thalinger Dalibor Topic*/#include "config.h"#include <stdlib.h>#if defined(HAVE_UNISTD_H)#include <unistd.h>#endif#if defined(HAVE_SYS_SYSINFO_H)#include <sys/sysinfo.h>#endif#if defined(HAVE_MACH_MACH_H)# include <mach/mach.h>#endif#include "jni.h"/* * Class: java_lang_Runtime * Method: availableProcessors * Signature: ()I */JNIEXPORT jint JNICALLJava_java_lang_VMRuntime_availableProcessors(JNIEnv *env UNUSED, jclass clazz UNUSED){#if defined(HAVE_GET_NPROCS_CONF) return get_nprocs_conf();#elif defined(_SC_NPROC_ONLN) return (jint) sysconf(_SC_NPROC_ONLN);#elif defined(_SC_NPROCESSORS_ONLN) return (jint) 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 (jint) 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 (jint) hinfo.avail_cpus;#else return 1;#endif}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?