Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/bin/ergo.c
32285 views
/*1* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/* This file houses the common methods for VM ergonomics the platforms26* are split into ergo_sparc and ergo_x86, and they could be split more27* in the future if required. The following comments are not entirely28* true after bifurcation of the platform specific files.29*/3031/*32* The following methods (down to ServerClassMachine()) answer33* the question about whether a machine is a "server-class"34* machine. A server-class machine is loosely defined as one35* with 2 or more processors and 2 gigabytes or more physical36* memory. The definition of a processor is a physical package,37* not a hyperthreaded chip masquerading as a multi-processor.38* The definition of memory is also somewhat fuzzy, since x8639* machines seem not to report all the memory in their DIMMs, we40* think because of memory mapping of graphics cards, etc.41*42* This code is somewhat more confused with #ifdef's than we'd43* like because this file is used by both Solaris and Linux44* platforms, and so needs to be parameterized for SPARC and45* i586 hardware. The other Linux platforms (amd64 and ia64)46* don't even ask this question, because they only come with47* server JVMs.48*/4950#include "ergo.h"5152/* Dispatch to the platform-specific definition of "server-class" */53jboolean54ServerClassMachine(void) {55jboolean result;56switch(GetErgoPolicy()) {57case NEVER_SERVER_CLASS:58return JNI_FALSE;59case ALWAYS_SERVER_CLASS:60return JNI_TRUE;61default:62result = ServerClassMachineImpl();63JLI_TraceLauncher("ServerClassMachine: returns default value of %s\n",64(result == JNI_TRUE ? "true" : "false"));65return result;66}67}6869#ifdef USE_GENERIC_ERGO70/* Ask the OS how many processors there are. */71static unsigned long72physical_processors(void) {73const unsigned long sys_processors = sysconf(_SC_NPROCESSORS_CONF);74JLI_TraceLauncher("sysconf(_SC_NPROCESSORS_CONF): %lu\n", sys_processors);75return sys_processors;76}7778jboolean79ServerClassMachineImpl(void) {80jboolean result = JNI_FALSE;81/* How big is a server class machine? */82const unsigned long server_processors = 2UL;83const uint64_t server_memory = 2UL * GB;84const uint64_t actual_memory = physical_memory();8586/* Is this a server class machine? */87if (actual_memory >= server_memory) {88const unsigned long actual_processors = physical_processors();89if (actual_processors >= server_processors) {90result = JNI_TRUE;91}92}93JLI_TraceLauncher("unix_" LIBARCHNAME "_ServerClassMachine: %s\n",94(result == JNI_TRUE ? "JNI_TRUE" : "JNI_FALSE"));95return result;96}97#endif9899/* Compute physical memory by asking the OS */100uint64_t101physical_memory(void) {102const uint64_t pages = (uint64_t) sysconf(_SC_PHYS_PAGES);103const uint64_t page_size = (uint64_t) sysconf(_SC_PAGESIZE);104const uint64_t result = pages * page_size;105# define UINT64_FORMAT "%" PRIu64106107JLI_TraceLauncher("pages: " UINT64_FORMAT108" page_size: " UINT64_FORMAT109" physical memory: " UINT64_FORMAT " (%.3fGB)\n",110pages, page_size, result, result / (double) GB);111return result;112}113114115