duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 1 | /* |
dholmes | 0700ded | 2011-03-09 19:52:48 -0500 | [diff] [blame] | 2 | * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair | 2283b9d | 2010-05-25 15:58:33 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. Oracle designates this |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair | 2283b9d | 2010-05-25 15:58:33 -0700 | [diff] [blame] | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
ohair | 2283b9d | 2010-05-25 15:58:33 -0700 | [diff] [blame] | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | * or visit www.oracle.com if you need additional information or have any |
| 23 | * questions. |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | /* This file houses the common methods for VM ergonomics the platforms |
| 27 | * are split into ergo_sparc and ergo_x86, and they could be split more |
| 28 | * in the future if required. The following comments are not entirely |
| 29 | * true after bifurcation of the platform specific files. |
| 30 | */ |
| 31 | |
| 32 | /* |
| 33 | * The following methods (down to ServerClassMachine()) answer |
| 34 | * the question about whether a machine is a "server-class" |
| 35 | * machine. A server-class machine is loosely defined as one |
| 36 | * with 2 or more processors and 2 gigabytes or more physical |
| 37 | * memory. The definition of a processor is a physical package, |
| 38 | * not a hyperthreaded chip masquerading as a multi-processor. |
| 39 | * The definition of memory is also somewhat fuzzy, since x86 |
| 40 | * machines seem not to report all the memory in their DIMMs, we |
| 41 | * think because of memory mapping of graphics cards, etc. |
| 42 | * |
| 43 | * This code is somewhat more confused with #ifdef's than we'd |
| 44 | * like because this file is used by both Solaris and Linux |
| 45 | * platforms, and so needs to be parameterized for SPARC and |
| 46 | * i586 hardware. The other Linux platforms (amd64 and ia64) |
| 47 | * don't even ask this question, because they only come with |
| 48 | * server JVMs. |
| 49 | */ |
| 50 | |
| 51 | #include "ergo.h" |
| 52 | |
| 53 | /* Dispatch to the platform-specific definition of "server-class" */ |
| 54 | jboolean |
| 55 | ServerClassMachine(void) { |
| 56 | jboolean result; |
| 57 | switch(GetErgoPolicy()) { |
| 58 | case NEVER_SERVER_CLASS: |
| 59 | return JNI_FALSE; |
| 60 | case ALWAYS_SERVER_CLASS: |
| 61 | return JNI_TRUE; |
| 62 | default: |
| 63 | result = ServerClassMachineImpl(); |
| 64 | JLI_TraceLauncher("ServerClassMachine: returns default value of %s\n", |
| 65 | (result == JNI_TRUE ? "true" : "false")); |
| 66 | return result; |
| 67 | } |
| 68 | } |
| 69 | |
dholmes | 0700ded | 2011-03-09 19:52:48 -0500 | [diff] [blame] | 70 | #ifdef USE_GENERIC_ERGO |
| 71 | /* Ask the OS how many processors there are. */ |
| 72 | static unsigned long |
| 73 | physical_processors(void) { |
| 74 | const unsigned long sys_processors = sysconf(_SC_NPROCESSORS_CONF); |
| 75 | JLI_TraceLauncher("sysconf(_SC_NPROCESSORS_CONF): %lu\n", sys_processors); |
| 76 | return sys_processors; |
| 77 | } |
| 78 | |
| 79 | jboolean |
| 80 | ServerClassMachineImpl(void) { |
| 81 | jboolean result = JNI_FALSE; |
| 82 | /* How big is a server class machine? */ |
| 83 | const unsigned long server_processors = 2UL; |
| 84 | const uint64_t server_memory = 2UL * GB; |
| 85 | const uint64_t actual_memory = physical_memory(); |
| 86 | |
| 87 | /* Is this a server class machine? */ |
| 88 | if (actual_memory >= server_memory) { |
| 89 | const unsigned long actual_processors = physical_processors(); |
| 90 | if (actual_processors >= server_processors) { |
| 91 | result = JNI_TRUE; |
| 92 | } |
| 93 | } |
| 94 | JLI_TraceLauncher("unix_" LIBARCHNAME "_ServerClassMachine: %s\n", |
| 95 | (result == JNI_TRUE ? "JNI_TRUE" : "JNI_FALSE")); |
| 96 | return result; |
| 97 | } |
| 98 | #endif |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 99 | |
| 100 | /* Compute physical memory by asking the OS */ |
| 101 | uint64_t |
| 102 | physical_memory(void) { |
| 103 | const uint64_t pages = (uint64_t) sysconf(_SC_PHYS_PAGES); |
| 104 | const uint64_t page_size = (uint64_t) sysconf(_SC_PAGESIZE); |
| 105 | const uint64_t result = pages * page_size; |
| 106 | # define UINT64_FORMAT "%" PRIu64 |
| 107 | |
| 108 | JLI_TraceLauncher("pages: " UINT64_FORMAT |
| 109 | " page_size: " UINT64_FORMAT |
| 110 | " physical memory: " UINT64_FORMAT " (%.3fGB)\n", |
| 111 | pages, page_size, result, result / (double) GB); |
| 112 | return result; |
| 113 | } |