jdk/src/solaris/bin/ergo.c
author pchelko
Wed, 23 Apr 2014 17:56:05 +0400
changeset 24529 c580bcb3aabc
parent 8768 4e98f3b11578
permissions -rw-r--r--
8027148: SystemFlavorMap.getNativesForFlavor returns list of native formats in incorrect order Reviewed-by: anthony, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
8768
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
     2
 * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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
8768
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    70
#ifdef USE_GENERIC_ERGO
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    71
/* Ask the OS how many processors there are. */
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    72
static unsigned long
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    73
physical_processors(void) {
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    74
  const unsigned long sys_processors = sysconf(_SC_NPROCESSORS_CONF);
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    75
  JLI_TraceLauncher("sysconf(_SC_NPROCESSORS_CONF): %lu\n", sys_processors);
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    76
  return sys_processors;
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    77
}
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    78
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    79
jboolean
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    80
ServerClassMachineImpl(void) {
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    81
  jboolean            result            = JNI_FALSE;
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    82
  /* How big is a server class machine? */
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    83
  const unsigned long server_processors = 2UL;
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    84
  const uint64_t      server_memory     = 2UL * GB;
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    85
  const uint64_t      actual_memory     = physical_memory();
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    86
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    87
  /* Is this a server class machine? */
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    88
  if (actual_memory >= server_memory) {
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    89
    const unsigned long actual_processors = physical_processors();
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    90
    if (actual_processors >= server_processors) {
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    91
      result = JNI_TRUE;
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    92
    }
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    93
  }
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    94
  JLI_TraceLauncher("unix_" LIBARCHNAME "_ServerClassMachine: %s\n",
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    95
           (result == JNI_TRUE ? "JNI_TRUE" : "JNI_FALSE"));
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    96
  return result;
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    97
}
4e98f3b11578 7022370: Launcher ergonomics should provide simple default implementation
dholmes
parents: 5506
diff changeset
    98
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
/* Compute physical memory by asking the OS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
uint64_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
physical_memory(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  const uint64_t pages     = (uint64_t) sysconf(_SC_PHYS_PAGES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  const uint64_t page_size = (uint64_t) sysconf(_SC_PAGESIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
  const uint64_t result    = pages * page_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
# define UINT64_FORMAT "%" PRIu64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
  JLI_TraceLauncher("pages: " UINT64_FORMAT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
          "  page_size: " UINT64_FORMAT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
          "  physical memory: " UINT64_FORMAT " (%.3fGB)\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
           pages, page_size, result, result / (double) GB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
  return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
}