author | pchelko |
Wed, 23 Apr 2014 17:56:05 +0400 | |
changeset 24529 | c580bcb3aabc |
parent 8768 | 4e98f3b11578 |
permissions | -rw-r--r-- |
2 | 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 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 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 |
||
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 | 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 |
} |