jdk/src/solaris/bin/ergo.c
author mikejwre
Thu, 03 Dec 2009 12:52:46 -0800
changeset 4400 6f7b7cb74a72
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Added tag jdk7-b77 for changeset a9713976af74
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/* This file houses the common methods for VM ergonomics the platforms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * are split into ergo_sparc and ergo_x86, and they could be split more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * in the future if required. The following comments are not entirely
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * true after bifurcation of the platform specific files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * The following methods (down to ServerClassMachine()) answer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * the question about whether a machine is a "server-class"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * machine.  A server-class machine is loosely defined as one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * with 2 or more processors and 2 gigabytes or more physical
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * memory.  The definition of a processor is a physical package,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * not a hyperthreaded chip masquerading as a multi-processor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The definition of memory is also somewhat fuzzy, since x86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * machines seem not to report all the memory in their DIMMs, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * think because of memory mapping of graphics cards, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This code is somewhat more confused with #ifdef's than we'd
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * like because this file is used by both Solaris and Linux
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * platforms, and so needs to be parameterized for SPARC and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * i586 hardware.  The other Linux platforms (amd64 and ia64)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * don't even ask this question, because they only come with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * server JVMs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#include "ergo.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/* Dispatch to the platform-specific definition of "server-class" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
ServerClassMachine(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  jboolean result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  switch(GetErgoPolicy()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    case NEVER_SERVER_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
      return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    case ALWAYS_SERVER_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
      return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
      result = ServerClassMachineImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
      JLI_TraceLauncher("ServerClassMachine: returns default value of %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
           (result == JNI_TRUE ? "true" : "false"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
      return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
/* Compute physical memory by asking the OS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
uint64_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
physical_memory(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  const uint64_t pages     = (uint64_t) sysconf(_SC_PHYS_PAGES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  const uint64_t page_size = (uint64_t) sysconf(_SC_PAGESIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  const uint64_t result    = pages * page_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
# define UINT64_FORMAT "%" PRIu64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  JLI_TraceLauncher("pages: " UINT64_FORMAT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
          "  page_size: " UINT64_FORMAT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
          "  physical memory: " UINT64_FORMAT " (%.3fGB)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
           pages, page_size, result, result / (double) GB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
}