duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved. |
| 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 |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 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 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 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 | |
| 70 | |
| 71 | /* Compute physical memory by asking the OS */ |
| 72 | uint64_t |
| 73 | physical_memory(void) { |
| 74 | const uint64_t pages = (uint64_t) sysconf(_SC_PHYS_PAGES); |
| 75 | const uint64_t page_size = (uint64_t) sysconf(_SC_PAGESIZE); |
| 76 | const uint64_t result = pages * page_size; |
| 77 | # define UINT64_FORMAT "%" PRIu64 |
| 78 | |
| 79 | JLI_TraceLauncher("pages: " UINT64_FORMAT |
| 80 | " page_size: " UINT64_FORMAT |
| 81 | " physical memory: " UINT64_FORMAT " (%.3fGB)\n", |
| 82 | pages, page_size, result, result / (double) GB); |
| 83 | return result; |
| 84 | } |