Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/os/aix/os_aix.cpp
40930 views
1
/*
2
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2012, 2020 SAP SE. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*
24
*/
25
26
// According to the AIX OS doc #pragma alloca must be used
27
// with C++ compiler before referencing the function alloca()
28
#pragma alloca
29
30
// no precompiled headers
31
#include "jvm.h"
32
#include "classfile/vmSymbols.hpp"
33
#include "code/icBuffer.hpp"
34
#include "code/vtableStubs.hpp"
35
#include "compiler/compileBroker.hpp"
36
#include "interpreter/interpreter.hpp"
37
#include "jvmtifiles/jvmti.h"
38
#include "logging/log.hpp"
39
#include "logging/logStream.hpp"
40
#include "libo4.hpp"
41
#include "libperfstat_aix.hpp"
42
#include "libodm_aix.hpp"
43
#include "loadlib_aix.hpp"
44
#include "memory/allocation.inline.hpp"
45
#include "misc_aix.hpp"
46
#include "oops/oop.inline.hpp"
47
#include "os_aix.inline.hpp"
48
#include "os_share_aix.hpp"
49
#include "porting_aix.hpp"
50
#include "prims/jniFastGetField.hpp"
51
#include "prims/jvm_misc.hpp"
52
#include "runtime/arguments.hpp"
53
#include "runtime/atomic.hpp"
54
#include "runtime/globals.hpp"
55
#include "runtime/globals_extension.hpp"
56
#include "runtime/interfaceSupport.inline.hpp"
57
#include "runtime/java.hpp"
58
#include "runtime/javaCalls.hpp"
59
#include "runtime/mutexLocker.hpp"
60
#include "runtime/objectMonitor.hpp"
61
#include "runtime/os.hpp"
62
#include "runtime/osThread.hpp"
63
#include "runtime/perfMemory.hpp"
64
#include "runtime/safefetch.inline.hpp"
65
#include "runtime/sharedRuntime.hpp"
66
#include "runtime/statSampler.hpp"
67
#include "runtime/thread.inline.hpp"
68
#include "runtime/threadCritical.hpp"
69
#include "runtime/timer.hpp"
70
#include "runtime/vm_version.hpp"
71
#include "services/attachListener.hpp"
72
#include "services/runtimeService.hpp"
73
#include "signals_posix.hpp"
74
#include "utilities/align.hpp"
75
#include "utilities/decoder.hpp"
76
#include "utilities/defaultStream.hpp"
77
#include "utilities/events.hpp"
78
#include "utilities/growableArray.hpp"
79
#include "utilities/vmError.hpp"
80
81
// put OS-includes here (sorted alphabetically)
82
#include <errno.h>
83
#include <fcntl.h>
84
#include <inttypes.h>
85
#include <poll.h>
86
#include <procinfo.h>
87
#include <pthread.h>
88
#include <pwd.h>
89
#include <semaphore.h>
90
#include <signal.h>
91
#include <stdint.h>
92
#include <stdio.h>
93
#include <string.h>
94
#include <unistd.h>
95
#include <sys/ioctl.h>
96
#include <sys/ipc.h>
97
#include <sys/mman.h>
98
#include <sys/resource.h>
99
#include <sys/select.h>
100
#include <sys/shm.h>
101
#include <sys/socket.h>
102
#include <sys/stat.h>
103
#include <sys/sysinfo.h>
104
#include <sys/systemcfg.h>
105
#include <sys/time.h>
106
#include <sys/times.h>
107
#include <sys/types.h>
108
#include <sys/utsname.h>
109
#include <sys/vminfo.h>
110
111
// Missing prototypes for various system APIs.
112
extern "C"
113
int mread_real_time(timebasestruct_t *t, size_t size_of_timebasestruct_t);
114
115
#if !defined(_AIXVERSION_610)
116
extern "C" int getthrds64(pid_t, struct thrdentry64*, int, tid64_t*, int);
117
extern "C" int getprocs64(procentry64*, int, fdsinfo*, int, pid_t*, int);
118
extern "C" int getargs(procsinfo*, int, char*, int);
119
#endif
120
121
#define MAX_PATH (2 * K)
122
123
// for timer info max values which include all bits
124
#define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
125
// for multipage initialization error analysis (in 'g_multipage_error')
126
#define ERROR_MP_OS_TOO_OLD 100
127
#define ERROR_MP_EXTSHM_ACTIVE 101
128
#define ERROR_MP_VMGETINFO_FAILED 102
129
#define ERROR_MP_VMGETINFO_CLAIMS_NO_SUPPORT_FOR_64K 103
130
131
// excerpts from systemcfg.h that might be missing on older os levels
132
#ifndef PV_7
133
#define PV_7 0x200000 /* Power PC 7 */
134
#endif
135
#ifndef PV_7_Compat
136
#define PV_7_Compat 0x208000 /* Power PC 7 */
137
#endif
138
#ifndef PV_8
139
#define PV_8 0x300000 /* Power PC 8 */
140
#endif
141
#ifndef PV_8_Compat
142
#define PV_8_Compat 0x308000 /* Power PC 8 */
143
#endif
144
#ifndef PV_9
145
#define PV_9 0x400000 /* Power PC 9 */
146
#endif
147
#ifndef PV_9_Compat
148
#define PV_9_Compat 0x408000 /* Power PC 9 */
149
#endif
150
151
152
static address resolve_function_descriptor_to_code_pointer(address p);
153
154
static void vmembk_print_on(outputStream* os);
155
156
////////////////////////////////////////////////////////////////////////////////
157
// global variables (for a description see os_aix.hpp)
158
159
julong os::Aix::_physical_memory = 0;
160
161
pthread_t os::Aix::_main_thread = ((pthread_t)0);
162
int os::Aix::_page_size = -1;
163
164
// -1 = uninitialized, 0 if AIX, 1 if OS/400 pase
165
int os::Aix::_on_pase = -1;
166
167
// 0 = uninitialized, otherwise 32 bit number:
168
// 0xVVRRTTSS
169
// VV - major version
170
// RR - minor version
171
// TT - tech level, if known, 0 otherwise
172
// SS - service pack, if known, 0 otherwise
173
uint32_t os::Aix::_os_version = 0;
174
175
// -1 = uninitialized, 0 - no, 1 - yes
176
int os::Aix::_xpg_sus_mode = -1;
177
178
// -1 = uninitialized, 0 - no, 1 - yes
179
int os::Aix::_extshm = -1;
180
181
////////////////////////////////////////////////////////////////////////////////
182
// local variables
183
184
static volatile jlong max_real_time = 0;
185
static jlong initial_time_count = 0;
186
static int clock_tics_per_sec = 100;
187
188
// Process break recorded at startup.
189
static address g_brk_at_startup = NULL;
190
191
// This describes the state of multipage support of the underlying
192
// OS. Note that this is of no interest to the outsize world and
193
// therefore should not be defined in AIX class.
194
//
195
// AIX supports four different page sizes - 4K, 64K, 16MB, 16GB. The
196
// latter two (16M "large" resp. 16G "huge" pages) require special
197
// setup and are normally not available.
198
//
199
// AIX supports multiple page sizes per process, for:
200
// - Stack (of the primordial thread, so not relevant for us)
201
// - Data - data, bss, heap, for us also pthread stacks
202
// - Text - text code
203
// - shared memory
204
//
205
// Default page sizes can be set via linker options (-bdatapsize, -bstacksize, ...)
206
// and via environment variable LDR_CNTRL (DATAPSIZE, STACKPSIZE, ...).
207
//
208
// For shared memory, page size can be set dynamically via
209
// shmctl(). Different shared memory regions can have different page
210
// sizes.
211
//
212
// More information can be found at AIBM info center:
213
// http://publib.boulder.ibm.com/infocenter/aix/v6r1/index.jsp?topic=/com.ibm.aix.prftungd/doc/prftungd/multiple_page_size_app_support.htm
214
//
215
static struct {
216
size_t pagesize; // sysconf _SC_PAGESIZE (4K)
217
size_t datapsize; // default data page size (LDR_CNTRL DATAPSIZE)
218
size_t shmpsize; // default shared memory page size (LDR_CNTRL SHMPSIZE)
219
size_t pthr_stack_pagesize; // stack page size of pthread threads
220
size_t textpsize; // default text page size (LDR_CNTRL STACKPSIZE)
221
bool can_use_64K_pages; // True if we can alloc 64K pages dynamically with Sys V shm.
222
bool can_use_16M_pages; // True if we can alloc 16M pages dynamically with Sys V shm.
223
int error; // Error describing if something went wrong at multipage init.
224
} g_multipage_support = {
225
(size_t) -1,
226
(size_t) -1,
227
(size_t) -1,
228
(size_t) -1,
229
(size_t) -1,
230
false, false,
231
0
232
};
233
234
// We must not accidentally allocate memory close to the BRK - even if
235
// that would work - because then we prevent the BRK segment from
236
// growing which may result in a malloc OOM even though there is
237
// enough memory. The problem only arises if we shmat() or mmap() at
238
// a specific wish address, e.g. to place the heap in a
239
// compressed-oops-friendly way.
240
static bool is_close_to_brk(address a) {
241
assert0(g_brk_at_startup != NULL);
242
if (a >= g_brk_at_startup &&
243
a < (g_brk_at_startup + MaxExpectedDataSegmentSize)) {
244
return true;
245
}
246
return false;
247
}
248
249
julong os::available_memory() {
250
return Aix::available_memory();
251
}
252
253
julong os::Aix::available_memory() {
254
// Avoid expensive API call here, as returned value will always be null.
255
if (os::Aix::on_pase()) {
256
return 0x0LL;
257
}
258
os::Aix::meminfo_t mi;
259
if (os::Aix::get_meminfo(&mi)) {
260
return mi.real_free;
261
} else {
262
return ULONG_MAX;
263
}
264
}
265
266
julong os::physical_memory() {
267
return Aix::physical_memory();
268
}
269
270
// Return true if user is running as root.
271
272
bool os::have_special_privileges() {
273
static bool init = false;
274
static bool privileges = false;
275
if (!init) {
276
privileges = (getuid() != geteuid()) || (getgid() != getegid());
277
init = true;
278
}
279
return privileges;
280
}
281
282
// Helper function, emulates disclaim64 using multiple 32bit disclaims
283
// because we cannot use disclaim64() on AS/400 and old AIX releases.
284
static bool my_disclaim64(char* addr, size_t size) {
285
286
if (size == 0) {
287
return true;
288
}
289
290
// Maximum size 32bit disclaim() accepts. (Theoretically 4GB, but I just do not trust that.)
291
const unsigned int maxDisclaimSize = 0x40000000;
292
293
const unsigned int numFullDisclaimsNeeded = (size / maxDisclaimSize);
294
const unsigned int lastDisclaimSize = (size % maxDisclaimSize);
295
296
char* p = addr;
297
298
for (int i = 0; i < numFullDisclaimsNeeded; i ++) {
299
if (::disclaim(p, maxDisclaimSize, DISCLAIM_ZEROMEM) != 0) {
300
trcVerbose("Cannot disclaim %p - %p (errno %d)\n", p, p + maxDisclaimSize, errno);
301
return false;
302
}
303
p += maxDisclaimSize;
304
}
305
306
if (lastDisclaimSize > 0) {
307
if (::disclaim(p, lastDisclaimSize, DISCLAIM_ZEROMEM) != 0) {
308
trcVerbose("Cannot disclaim %p - %p (errno %d)\n", p, p + lastDisclaimSize, errno);
309
return false;
310
}
311
}
312
313
return true;
314
}
315
316
// Cpu architecture string
317
#if defined(PPC32)
318
static char cpu_arch[] = "ppc";
319
#elif defined(PPC64)
320
static char cpu_arch[] = "ppc64";
321
#else
322
#error Add appropriate cpu_arch setting
323
#endif
324
325
// Wrap the function "vmgetinfo" which is not available on older OS releases.
326
static int checked_vmgetinfo(void *out, int command, int arg) {
327
if (os::Aix::on_pase() && os::Aix::os_version_short() < 0x0601) {
328
guarantee(false, "cannot call vmgetinfo on AS/400 older than V6R1");
329
}
330
return ::vmgetinfo(out, command, arg);
331
}
332
333
// Given an address, returns the size of the page backing that address.
334
size_t os::Aix::query_pagesize(void* addr) {
335
336
if (os::Aix::on_pase() && os::Aix::os_version_short() < 0x0601) {
337
// AS/400 older than V6R1: no vmgetinfo here, default to 4K
338
return 4*K;
339
}
340
341
vm_page_info pi;
342
pi.addr = (uint64_t)addr;
343
if (checked_vmgetinfo(&pi, VM_PAGE_INFO, sizeof(pi)) == 0) {
344
return pi.pagesize;
345
} else {
346
assert(false, "vmgetinfo failed to retrieve page size");
347
return 4*K;
348
}
349
}
350
351
void os::Aix::initialize_system_info() {
352
353
// Get the number of online(logical) cpus instead of configured.
354
os::_processor_count = sysconf(_SC_NPROCESSORS_ONLN);
355
assert(_processor_count > 0, "_processor_count must be > 0");
356
357
// Retrieve total physical storage.
358
os::Aix::meminfo_t mi;
359
if (!os::Aix::get_meminfo(&mi)) {
360
assert(false, "os::Aix::get_meminfo failed.");
361
}
362
_physical_memory = (julong) mi.real_total;
363
}
364
365
// Helper function for tracing page sizes.
366
static const char* describe_pagesize(size_t pagesize) {
367
switch (pagesize) {
368
case 4*K : return "4K";
369
case 64*K: return "64K";
370
case 16*M: return "16M";
371
case 16*G: return "16G";
372
default:
373
assert(false, "surprise");
374
return "??";
375
}
376
}
377
378
// Probe OS for multipage support.
379
// Will fill the global g_multipage_support structure.
380
// Must be called before calling os::large_page_init().
381
static void query_multipage_support() {
382
383
guarantee(g_multipage_support.pagesize == -1,
384
"do not call twice");
385
386
g_multipage_support.pagesize = ::sysconf(_SC_PAGESIZE);
387
388
// This really would surprise me.
389
assert(g_multipage_support.pagesize == 4*K, "surprise!");
390
391
// Query default data page size (default page size for C-Heap, pthread stacks and .bss).
392
// Default data page size is defined either by linker options (-bdatapsize)
393
// or by environment variable LDR_CNTRL (suboption DATAPSIZE). If none is given,
394
// default should be 4K.
395
{
396
void* p = ::malloc(16*M);
397
g_multipage_support.datapsize = os::Aix::query_pagesize(p);
398
::free(p);
399
}
400
401
// Query default shm page size (LDR_CNTRL SHMPSIZE).
402
// Note that this is pure curiosity. We do not rely on default page size but set
403
// our own page size after allocated.
404
{
405
const int shmid = ::shmget(IPC_PRIVATE, 1, IPC_CREAT | S_IRUSR | S_IWUSR);
406
guarantee(shmid != -1, "shmget failed");
407
void* p = ::shmat(shmid, NULL, 0);
408
::shmctl(shmid, IPC_RMID, NULL);
409
guarantee(p != (void*) -1, "shmat failed");
410
g_multipage_support.shmpsize = os::Aix::query_pagesize(p);
411
::shmdt(p);
412
}
413
414
// Before querying the stack page size, make sure we are not running as primordial
415
// thread (because primordial thread's stack may have different page size than
416
// pthread thread stacks). Running a VM on the primordial thread won't work for a
417
// number of reasons so we may just as well guarantee it here.
418
guarantee0(!os::is_primordial_thread());
419
420
// Query pthread stack page size. Should be the same as data page size because
421
// pthread stacks are allocated from C-Heap.
422
{
423
int dummy = 0;
424
g_multipage_support.pthr_stack_pagesize = os::Aix::query_pagesize(&dummy);
425
}
426
427
// Query default text page size (LDR_CNTRL TEXTPSIZE).
428
{
429
address any_function =
430
resolve_function_descriptor_to_code_pointer((address)describe_pagesize);
431
g_multipage_support.textpsize = os::Aix::query_pagesize(any_function);
432
}
433
434
// Now probe for support of 64K pages and 16M pages.
435
436
// Before OS/400 V6R1, there is no support for pages other than 4K.
437
if (os::Aix::on_pase_V5R4_or_older()) {
438
trcVerbose("OS/400 < V6R1 - no large page support.");
439
g_multipage_support.error = ERROR_MP_OS_TOO_OLD;
440
goto query_multipage_support_end;
441
}
442
443
// Now check which page sizes the OS claims it supports, and of those, which actually can be used.
444
{
445
const int MAX_PAGE_SIZES = 4;
446
psize_t sizes[MAX_PAGE_SIZES];
447
const int num_psizes = checked_vmgetinfo(sizes, VMINFO_GETPSIZES, MAX_PAGE_SIZES);
448
if (num_psizes == -1) {
449
trcVerbose("vmgetinfo(VMINFO_GETPSIZES) failed (errno: %d)", errno);
450
trcVerbose("disabling multipage support.");
451
g_multipage_support.error = ERROR_MP_VMGETINFO_FAILED;
452
goto query_multipage_support_end;
453
}
454
guarantee(num_psizes > 0, "vmgetinfo(.., VMINFO_GETPSIZES, ...) failed.");
455
assert(num_psizes <= MAX_PAGE_SIZES, "Surprise! more than 4 page sizes?");
456
trcVerbose("vmgetinfo(.., VMINFO_GETPSIZES, ...) returns %d supported page sizes: ", num_psizes);
457
for (int i = 0; i < num_psizes; i ++) {
458
trcVerbose(" %s ", describe_pagesize(sizes[i]));
459
}
460
461
// Can we use 64K, 16M pages?
462
for (int i = 0; i < num_psizes; i ++) {
463
const size_t pagesize = sizes[i];
464
if (pagesize != 64*K && pagesize != 16*M) {
465
continue;
466
}
467
bool can_use = false;
468
trcVerbose("Probing support for %s pages...", describe_pagesize(pagesize));
469
const int shmid = ::shmget(IPC_PRIVATE, pagesize,
470
IPC_CREAT | S_IRUSR | S_IWUSR);
471
guarantee0(shmid != -1); // Should always work.
472
// Try to set pagesize.
473
struct shmid_ds shm_buf = { 0 };
474
shm_buf.shm_pagesize = pagesize;
475
if (::shmctl(shmid, SHM_PAGESIZE, &shm_buf) != 0) {
476
const int en = errno;
477
::shmctl(shmid, IPC_RMID, NULL); // As early as possible!
478
trcVerbose("shmctl(SHM_PAGESIZE) failed with errno=%d", errno);
479
} else {
480
// Attach and double check pageisze.
481
void* p = ::shmat(shmid, NULL, 0);
482
::shmctl(shmid, IPC_RMID, NULL); // As early as possible!
483
guarantee0(p != (void*) -1); // Should always work.
484
const size_t real_pagesize = os::Aix::query_pagesize(p);
485
if (real_pagesize != pagesize) {
486
trcVerbose("real page size (" SIZE_FORMAT_HEX ") differs.", real_pagesize);
487
} else {
488
can_use = true;
489
}
490
::shmdt(p);
491
}
492
trcVerbose("Can use: %s", (can_use ? "yes" : "no"));
493
if (pagesize == 64*K) {
494
g_multipage_support.can_use_64K_pages = can_use;
495
} else if (pagesize == 16*M) {
496
g_multipage_support.can_use_16M_pages = can_use;
497
}
498
}
499
500
} // end: check which pages can be used for shared memory
501
502
query_multipage_support_end:
503
504
trcVerbose("base page size (sysconf _SC_PAGESIZE): %s",
505
describe_pagesize(g_multipage_support.pagesize));
506
trcVerbose("Data page size (C-Heap, bss, etc): %s",
507
describe_pagesize(g_multipage_support.datapsize));
508
trcVerbose("Text page size: %s",
509
describe_pagesize(g_multipage_support.textpsize));
510
trcVerbose("Thread stack page size (pthread): %s",
511
describe_pagesize(g_multipage_support.pthr_stack_pagesize));
512
trcVerbose("Default shared memory page size: %s",
513
describe_pagesize(g_multipage_support.shmpsize));
514
trcVerbose("Can use 64K pages dynamically with shared memory: %s",
515
(g_multipage_support.can_use_64K_pages ? "yes" :"no"));
516
trcVerbose("Can use 16M pages dynamically with shared memory: %s",
517
(g_multipage_support.can_use_16M_pages ? "yes" :"no"));
518
trcVerbose("Multipage error details: %d",
519
g_multipage_support.error);
520
521
// sanity checks
522
assert0(g_multipage_support.pagesize == 4*K);
523
assert0(g_multipage_support.datapsize == 4*K || g_multipage_support.datapsize == 64*K);
524
assert0(g_multipage_support.textpsize == 4*K || g_multipage_support.textpsize == 64*K);
525
assert0(g_multipage_support.pthr_stack_pagesize == g_multipage_support.datapsize);
526
assert0(g_multipage_support.shmpsize == 4*K || g_multipage_support.shmpsize == 64*K);
527
528
}
529
530
void os::init_system_properties_values() {
531
532
#ifndef OVERRIDE_LIBPATH
533
#define DEFAULT_LIBPATH "/lib:/usr/lib"
534
#else
535
#define DEFAULT_LIBPATH OVERRIDE_LIBPATH
536
#endif
537
#define EXTENSIONS_DIR "/lib/ext"
538
539
// Buffer that fits several sprintfs.
540
// Note that the space for the trailing null is provided
541
// by the nulls included by the sizeof operator.
542
const size_t bufsize =
543
MAX2((size_t)MAXPATHLEN, // For dll_dir & friends.
544
(size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR)); // extensions dir
545
char *buf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
546
547
// sysclasspath, java_home, dll_dir
548
{
549
char *pslash;
550
os::jvm_path(buf, bufsize);
551
552
// Found the full path to libjvm.so.
553
// Now cut the path to <java_home>/jre if we can.
554
pslash = strrchr(buf, '/');
555
if (pslash != NULL) {
556
*pslash = '\0'; // Get rid of /libjvm.so.
557
}
558
pslash = strrchr(buf, '/');
559
if (pslash != NULL) {
560
*pslash = '\0'; // Get rid of /{client|server|hotspot}.
561
}
562
Arguments::set_dll_dir(buf);
563
564
if (pslash != NULL) {
565
pslash = strrchr(buf, '/');
566
if (pslash != NULL) {
567
*pslash = '\0'; // Get rid of /lib.
568
}
569
}
570
Arguments::set_java_home(buf);
571
if (!set_boot_path('/', ':')) {
572
vm_exit_during_initialization("Failed setting boot class path.", NULL);
573
}
574
}
575
576
// Where to look for native libraries.
577
578
// On Aix we get the user setting of LIBPATH.
579
// Eventually, all the library path setting will be done here.
580
// Get the user setting of LIBPATH.
581
const char *v = ::getenv("LIBPATH");
582
const char *v_colon = ":";
583
if (v == NULL) { v = ""; v_colon = ""; }
584
585
// Concatenate user and invariant part of ld_library_path.
586
// That's +1 for the colon and +1 for the trailing '\0'.
587
char *ld_library_path = NEW_C_HEAP_ARRAY(char, strlen(v) + 1 + sizeof(DEFAULT_LIBPATH) + 1, mtInternal);
588
sprintf(ld_library_path, "%s%s" DEFAULT_LIBPATH, v, v_colon);
589
Arguments::set_library_path(ld_library_path);
590
FREE_C_HEAP_ARRAY(char, ld_library_path);
591
592
// Extensions directories.
593
sprintf(buf, "%s" EXTENSIONS_DIR, Arguments::get_java_home());
594
Arguments::set_ext_dirs(buf);
595
596
FREE_C_HEAP_ARRAY(char, buf);
597
598
#undef DEFAULT_LIBPATH
599
#undef EXTENSIONS_DIR
600
}
601
602
////////////////////////////////////////////////////////////////////////////////
603
// breakpoint support
604
605
void os::breakpoint() {
606
BREAKPOINT;
607
}
608
609
extern "C" void breakpoint() {
610
// use debugger to set breakpoint here
611
}
612
613
// retrieve memory information.
614
// Returns false if something went wrong;
615
// content of pmi undefined in this case.
616
bool os::Aix::get_meminfo(meminfo_t* pmi) {
617
618
assert(pmi, "get_meminfo: invalid parameter");
619
620
memset(pmi, 0, sizeof(meminfo_t));
621
622
if (os::Aix::on_pase()) {
623
// On PASE, use the libo4 porting library.
624
625
unsigned long long virt_total = 0;
626
unsigned long long real_total = 0;
627
unsigned long long real_free = 0;
628
unsigned long long pgsp_total = 0;
629
unsigned long long pgsp_free = 0;
630
if (libo4::get_memory_info(&virt_total, &real_total, &real_free, &pgsp_total, &pgsp_free)) {
631
pmi->virt_total = virt_total;
632
pmi->real_total = real_total;
633
pmi->real_free = real_free;
634
pmi->pgsp_total = pgsp_total;
635
pmi->pgsp_free = pgsp_free;
636
return true;
637
}
638
return false;
639
640
} else {
641
642
// On AIX, I use the (dynamically loaded) perfstat library to retrieve memory statistics
643
// See:
644
// http://publib.boulder.ibm.com/infocenter/systems/index.jsp
645
// ?topic=/com.ibm.aix.basetechref/doc/basetrf1/perfstat_memtot.htm
646
// http://publib.boulder.ibm.com/infocenter/systems/index.jsp
647
// ?topic=/com.ibm.aix.files/doc/aixfiles/libperfstat.h.htm
648
649
perfstat_memory_total_t psmt;
650
memset (&psmt, '\0', sizeof(psmt));
651
const int rc = libperfstat::perfstat_memory_total(NULL, &psmt, sizeof(psmt), 1);
652
if (rc == -1) {
653
trcVerbose("perfstat_memory_total() failed (errno=%d)", errno);
654
assert(0, "perfstat_memory_total() failed");
655
return false;
656
}
657
658
assert(rc == 1, "perfstat_memory_total() - weird return code");
659
660
// excerpt from
661
// http://publib.boulder.ibm.com/infocenter/systems/index.jsp
662
// ?topic=/com.ibm.aix.files/doc/aixfiles/libperfstat.h.htm
663
// The fields of perfstat_memory_total_t:
664
// u_longlong_t virt_total Total virtual memory (in 4 KB pages).
665
// u_longlong_t real_total Total real memory (in 4 KB pages).
666
// u_longlong_t real_free Free real memory (in 4 KB pages).
667
// u_longlong_t pgsp_total Total paging space (in 4 KB pages).
668
// u_longlong_t pgsp_free Free paging space (in 4 KB pages).
669
670
pmi->virt_total = psmt.virt_total * 4096;
671
pmi->real_total = psmt.real_total * 4096;
672
pmi->real_free = psmt.real_free * 4096;
673
pmi->pgsp_total = psmt.pgsp_total * 4096;
674
pmi->pgsp_free = psmt.pgsp_free * 4096;
675
676
return true;
677
678
}
679
} // end os::Aix::get_meminfo
680
681
//////////////////////////////////////////////////////////////////////////////
682
// create new thread
683
684
// Thread start routine for all newly created threads
685
static void *thread_native_entry(Thread *thread) {
686
687
thread->record_stack_base_and_size();
688
689
const pthread_t pthread_id = ::pthread_self();
690
const tid_t kernel_thread_id = ::thread_self();
691
692
LogTarget(Info, os, thread) lt;
693
if (lt.is_enabled()) {
694
address low_address = thread->stack_end();
695
address high_address = thread->stack_base();
696
lt.print("Thread is alive (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT
697
", stack [" PTR_FORMAT " - " PTR_FORMAT " (" SIZE_FORMAT "k using %uk pages)).",
698
os::current_thread_id(), (uintx) kernel_thread_id, low_address, high_address,
699
(high_address - low_address) / K, os::Aix::query_pagesize(low_address) / K);
700
}
701
702
// Normally, pthread stacks on AIX live in the data segment (are allocated with malloc()
703
// by the pthread library). In rare cases, this may not be the case, e.g. when third-party
704
// tools hook pthread_create(). In this case, we may run into problems establishing
705
// guard pages on those stacks, because the stacks may reside in memory which is not
706
// protectable (shmated).
707
if (thread->stack_base() > ::sbrk(0)) {
708
log_warning(os, thread)("Thread stack not in data segment.");
709
}
710
711
// Try to randomize the cache line index of hot stack frames.
712
// This helps when threads of the same stack traces evict each other's
713
// cache lines. The threads can be either from the same JVM instance, or
714
// from different JVM instances. The benefit is especially true for
715
// processors with hyperthreading technology.
716
717
static int counter = 0;
718
int pid = os::current_process_id();
719
alloca(((pid ^ counter++) & 7) * 128);
720
721
thread->initialize_thread_current();
722
723
OSThread* osthread = thread->osthread();
724
725
// Thread_id is pthread id.
726
osthread->set_thread_id(pthread_id);
727
728
// .. but keep kernel thread id too for diagnostics
729
osthread->set_kernel_thread_id(kernel_thread_id);
730
731
// Initialize signal mask for this thread.
732
PosixSignals::hotspot_sigmask(thread);
733
734
// Initialize floating point control register.
735
os::Aix::init_thread_fpu_state();
736
737
assert(osthread->get_state() == RUNNABLE, "invalid os thread state");
738
739
// Call one more level start routine.
740
thread->call_run();
741
742
// Note: at this point the thread object may already have deleted itself.
743
// Prevent dereferencing it from here on out.
744
thread = NULL;
745
746
log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
747
os::current_thread_id(), (uintx) kernel_thread_id);
748
749
return 0;
750
}
751
752
bool os::create_thread(Thread* thread, ThreadType thr_type,
753
size_t req_stack_size) {
754
755
assert(thread->osthread() == NULL, "caller responsible");
756
757
// Allocate the OSThread object.
758
OSThread* osthread = new OSThread(NULL, NULL);
759
if (osthread == NULL) {
760
return false;
761
}
762
763
// Set the correct thread state.
764
osthread->set_thread_type(thr_type);
765
766
// Initial state is ALLOCATED but not INITIALIZED
767
osthread->set_state(ALLOCATED);
768
769
thread->set_osthread(osthread);
770
771
// Init thread attributes.
772
pthread_attr_t attr;
773
pthread_attr_init(&attr);
774
guarantee(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0, "???");
775
776
// Make sure we run in 1:1 kernel-user-thread mode.
777
if (os::Aix::on_aix()) {
778
guarantee(pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM) == 0, "???");
779
guarantee(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) == 0, "???");
780
}
781
782
// Start in suspended state, and in os::thread_start, wake the thread up.
783
guarantee(pthread_attr_setsuspendstate_np(&attr, PTHREAD_CREATE_SUSPENDED_NP) == 0, "???");
784
785
// Calculate stack size if it's not specified by caller.
786
size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);
787
788
// JDK-8187028: It was observed that on some configurations (4K backed thread stacks)
789
// the real thread stack size may be smaller than the requested stack size, by as much as 64K.
790
// This very much looks like a pthread lib error. As a workaround, increase the stack size
791
// by 64K for small thread stacks (arbitrarily choosen to be < 4MB)
792
if (stack_size < 4096 * K) {
793
stack_size += 64 * K;
794
}
795
796
// On Aix, pthread_attr_setstacksize fails with huge values and leaves the
797
// thread size in attr unchanged. If this is the minimal stack size as set
798
// by pthread_attr_init this leads to crashes after thread creation. E.g. the
799
// guard pages might not fit on the tiny stack created.
800
int ret = pthread_attr_setstacksize(&attr, stack_size);
801
if (ret != 0) {
802
log_warning(os, thread)("The %sthread stack size specified is invalid: " SIZE_FORMAT "k",
803
(thr_type == compiler_thread) ? "compiler " : ((thr_type == java_thread) ? "" : "VM "),
804
stack_size / K);
805
thread->set_osthread(NULL);
806
delete osthread;
807
return false;
808
}
809
810
// Save some cycles and a page by disabling OS guard pages where we have our own
811
// VM guard pages (in java threads). For other threads, keep system default guard
812
// pages in place.
813
if (thr_type == java_thread || thr_type == compiler_thread) {
814
ret = pthread_attr_setguardsize(&attr, 0);
815
}
816
817
pthread_t tid = 0;
818
if (ret == 0) {
819
ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
820
}
821
822
if (ret == 0) {
823
char buf[64];
824
log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
825
(uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
826
} else {
827
char buf[64];
828
log_warning(os, thread)("Failed to start thread - pthread_create failed (%d=%s) for attributes: %s.",
829
ret, os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
830
// Log some OS information which might explain why creating the thread failed.
831
log_info(os, thread)("Number of threads approx. running in the VM: %d", Threads::number_of_threads());
832
LogStream st(Log(os, thread)::info());
833
os::Posix::print_rlimit_info(&st);
834
os::print_memory_info(&st);
835
}
836
837
pthread_attr_destroy(&attr);
838
839
if (ret != 0) {
840
// Need to clean up stuff we've allocated so far.
841
thread->set_osthread(NULL);
842
delete osthread;
843
return false;
844
}
845
846
// OSThread::thread_id is the pthread id.
847
osthread->set_thread_id(tid);
848
849
return true;
850
}
851
852
/////////////////////////////////////////////////////////////////////////////
853
// attach existing thread
854
855
// bootstrap the main thread
856
bool os::create_main_thread(JavaThread* thread) {
857
assert(os::Aix::_main_thread == pthread_self(), "should be called inside main thread");
858
return create_attached_thread(thread);
859
}
860
861
bool os::create_attached_thread(JavaThread* thread) {
862
#ifdef ASSERT
863
thread->verify_not_published();
864
#endif
865
866
// Allocate the OSThread object
867
OSThread* osthread = new OSThread(NULL, NULL);
868
869
if (osthread == NULL) {
870
return false;
871
}
872
873
const pthread_t pthread_id = ::pthread_self();
874
const tid_t kernel_thread_id = ::thread_self();
875
876
// OSThread::thread_id is the pthread id.
877
osthread->set_thread_id(pthread_id);
878
879
// .. but keep kernel thread id too for diagnostics
880
osthread->set_kernel_thread_id(kernel_thread_id);
881
882
// initialize floating point control register
883
os::Aix::init_thread_fpu_state();
884
885
// Initial thread state is RUNNABLE
886
osthread->set_state(RUNNABLE);
887
888
thread->set_osthread(osthread);
889
890
if (UseNUMA) {
891
int lgrp_id = os::numa_get_group_id();
892
if (lgrp_id != -1) {
893
thread->set_lgrp_id(lgrp_id);
894
}
895
}
896
897
// initialize signal mask for this thread
898
// and save the caller's signal mask
899
PosixSignals::hotspot_sigmask(thread);
900
901
log_info(os, thread)("Thread attached (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
902
os::current_thread_id(), (uintx) kernel_thread_id);
903
904
return true;
905
}
906
907
void os::pd_start_thread(Thread* thread) {
908
int status = pthread_continue_np(thread->osthread()->pthread_id());
909
assert(status == 0, "thr_continue failed");
910
}
911
912
// Free OS resources related to the OSThread
913
void os::free_thread(OSThread* osthread) {
914
assert(osthread != NULL, "osthread not set");
915
916
// We are told to free resources of the argument thread,
917
// but we can only really operate on the current thread.
918
assert(Thread::current()->osthread() == osthread,
919
"os::free_thread but not current thread");
920
921
// Restore caller's signal mask
922
sigset_t sigmask = osthread->caller_sigmask();
923
pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
924
925
delete osthread;
926
}
927
928
////////////////////////////////////////////////////////////////////////////////
929
// time support
930
931
// Time since start-up in seconds to a fine granularity.
932
double os::elapsedTime() {
933
return ((double)os::elapsed_counter()) / os::elapsed_frequency(); // nanosecond resolution
934
}
935
936
jlong os::elapsed_counter() {
937
return javaTimeNanos() - initial_time_count;
938
}
939
940
jlong os::elapsed_frequency() {
941
return NANOSECS_PER_SEC; // nanosecond resolution
942
}
943
944
bool os::supports_vtime() { return true; }
945
946
double os::elapsedVTime() {
947
struct rusage usage;
948
int retval = getrusage(RUSAGE_THREAD, &usage);
949
if (retval == 0) {
950
return usage.ru_utime.tv_sec + usage.ru_stime.tv_sec + (usage.ru_utime.tv_usec + usage.ru_stime.tv_usec) / (1000.0 * 1000);
951
} else {
952
// better than nothing, but not much
953
return elapsedTime();
954
}
955
}
956
957
// We use mread_real_time here.
958
// On AIX: If the CPU has a time register, the result will be RTC_POWER and
959
// it has to be converted to real time. AIX documentations suggests to do
960
// this unconditionally, so we do it.
961
//
962
// See: https://www.ibm.com/support/knowledgecenter/ssw_aix_61/com.ibm.aix.basetrf2/read_real_time.htm
963
//
964
// On PASE: mread_real_time will always return RTC_POWER_PC data, so no
965
// conversion is necessary. However, mread_real_time will not return
966
// monotonic results but merely matches read_real_time. So we need a tweak
967
// to ensure monotonic results.
968
//
969
// For PASE no public documentation exists, just word by IBM
970
jlong os::javaTimeNanos() {
971
timebasestruct_t time;
972
int rc = mread_real_time(&time, TIMEBASE_SZ);
973
if (os::Aix::on_pase()) {
974
assert(rc == RTC_POWER, "expected time format RTC_POWER from mread_real_time in PASE");
975
jlong now = jlong(time.tb_high) * NANOSECS_PER_SEC + jlong(time.tb_low);
976
jlong prev = max_real_time;
977
if (now <= prev) {
978
return prev; // same or retrograde time;
979
}
980
jlong obsv = Atomic::cmpxchg(&max_real_time, prev, now);
981
assert(obsv >= prev, "invariant"); // Monotonicity
982
// If the CAS succeeded then we're done and return "now".
983
// If the CAS failed and the observed value "obsv" is >= now then
984
// we should return "obsv". If the CAS failed and now > obsv > prv then
985
// some other thread raced this thread and installed a new value, in which case
986
// we could either (a) retry the entire operation, (b) retry trying to install now
987
// or (c) just return obsv. We use (c). No loop is required although in some cases
988
// we might discard a higher "now" value in deference to a slightly lower but freshly
989
// installed obsv value. That's entirely benign -- it admits no new orderings compared
990
// to (a) or (b) -- and greatly reduces coherence traffic.
991
// We might also condition (c) on the magnitude of the delta between obsv and now.
992
// Avoiding excessive CAS operations to hot RW locations is critical.
993
// See https://blogs.oracle.com/dave/entry/cas_and_cache_trivia_invalidate
994
return (prev == obsv) ? now : obsv;
995
} else {
996
if (rc != RTC_POWER) {
997
rc = time_base_to_time(&time, TIMEBASE_SZ);
998
assert(rc != -1, "error calling time_base_to_time()");
999
}
1000
return jlong(time.tb_high) * NANOSECS_PER_SEC + jlong(time.tb_low);
1001
}
1002
}
1003
1004
void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
1005
info_ptr->max_value = ALL_64_BITS;
1006
// mread_real_time() is monotonic (see 'os::javaTimeNanos()')
1007
info_ptr->may_skip_backward = false;
1008
info_ptr->may_skip_forward = false;
1009
info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time
1010
}
1011
1012
// Return the real, user, and system times in seconds from an
1013
// arbitrary fixed point in the past.
1014
bool os::getTimesSecs(double* process_real_time,
1015
double* process_user_time,
1016
double* process_system_time) {
1017
struct tms ticks;
1018
clock_t real_ticks = times(&ticks);
1019
1020
if (real_ticks == (clock_t) (-1)) {
1021
return false;
1022
} else {
1023
double ticks_per_second = (double) clock_tics_per_sec;
1024
*process_user_time = ((double) ticks.tms_utime) / ticks_per_second;
1025
*process_system_time = ((double) ticks.tms_stime) / ticks_per_second;
1026
*process_real_time = ((double) real_ticks) / ticks_per_second;
1027
1028
return true;
1029
}
1030
}
1031
1032
char * os::local_time_string(char *buf, size_t buflen) {
1033
struct tm t;
1034
time_t long_time;
1035
time(&long_time);
1036
localtime_r(&long_time, &t);
1037
jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d",
1038
t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
1039
t.tm_hour, t.tm_min, t.tm_sec);
1040
return buf;
1041
}
1042
1043
struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
1044
return localtime_r(clock, res);
1045
}
1046
1047
intx os::current_thread_id() {
1048
return (intx)pthread_self();
1049
}
1050
1051
int os::current_process_id() {
1052
return getpid();
1053
}
1054
1055
// DLL functions
1056
1057
const char* os::dll_file_extension() { return ".so"; }
1058
1059
// This must be hard coded because it's the system's temporary
1060
// directory not the java application's temp directory, ala java.io.tmpdir.
1061
const char* os::get_temp_directory() { return "/tmp"; }
1062
1063
// Check if addr is inside libjvm.so.
1064
bool os::address_is_in_vm(address addr) {
1065
1066
// Input could be a real pc or a function pointer literal. The latter
1067
// would be a function descriptor residing in the data segment of a module.
1068
loaded_module_t lm;
1069
if (LoadedLibraries::find_for_text_address(addr, &lm) != NULL) {
1070
return lm.is_in_vm;
1071
} else if (LoadedLibraries::find_for_data_address(addr, &lm) != NULL) {
1072
return lm.is_in_vm;
1073
} else {
1074
return false;
1075
}
1076
1077
}
1078
1079
// Resolve an AIX function descriptor literal to a code pointer.
1080
// If the input is a valid code pointer to a text segment of a loaded module,
1081
// it is returned unchanged.
1082
// If the input is a valid AIX function descriptor, it is resolved to the
1083
// code entry point.
1084
// If the input is neither a valid function descriptor nor a valid code pointer,
1085
// NULL is returned.
1086
static address resolve_function_descriptor_to_code_pointer(address p) {
1087
1088
if (LoadedLibraries::find_for_text_address(p, NULL) != NULL) {
1089
// It is a real code pointer.
1090
return p;
1091
} else if (LoadedLibraries::find_for_data_address(p, NULL) != NULL) {
1092
// Pointer to data segment, potential function descriptor.
1093
address code_entry = (address)(((FunctionDescriptor*)p)->entry());
1094
if (LoadedLibraries::find_for_text_address(code_entry, NULL) != NULL) {
1095
// It is a function descriptor.
1096
return code_entry;
1097
}
1098
}
1099
1100
return NULL;
1101
}
1102
1103
bool os::dll_address_to_function_name(address addr, char *buf,
1104
int buflen, int *offset,
1105
bool demangle) {
1106
if (offset) {
1107
*offset = -1;
1108
}
1109
// Buf is not optional, but offset is optional.
1110
assert(buf != NULL, "sanity check");
1111
buf[0] = '\0';
1112
1113
// Resolve function ptr literals first.
1114
addr = resolve_function_descriptor_to_code_pointer(addr);
1115
if (!addr) {
1116
return false;
1117
}
1118
1119
return AixSymbols::get_function_name(addr, buf, buflen, offset, NULL, demangle);
1120
}
1121
1122
bool os::dll_address_to_library_name(address addr, char* buf,
1123
int buflen, int* offset) {
1124
if (offset) {
1125
*offset = -1;
1126
}
1127
// Buf is not optional, but offset is optional.
1128
assert(buf != NULL, "sanity check");
1129
buf[0] = '\0';
1130
1131
// Resolve function ptr literals first.
1132
addr = resolve_function_descriptor_to_code_pointer(addr);
1133
if (!addr) {
1134
return false;
1135
}
1136
1137
return AixSymbols::get_module_name(addr, buf, buflen);
1138
}
1139
1140
// Loads .dll/.so and in case of error it checks if .dll/.so was built
1141
// for the same architecture as Hotspot is running on.
1142
void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
1143
1144
log_info(os)("attempting shared library load of %s", filename);
1145
1146
if (ebuf && ebuflen > 0) {
1147
ebuf[0] = '\0';
1148
ebuf[ebuflen - 1] = '\0';
1149
}
1150
1151
if (!filename || strlen(filename) == 0) {
1152
::strncpy(ebuf, "dll_load: empty filename specified", ebuflen - 1);
1153
return NULL;
1154
}
1155
1156
// RTLD_LAZY is currently not implemented. The dl is loaded immediately with all its dependants.
1157
void * result= ::dlopen(filename, RTLD_LAZY);
1158
if (result != NULL) {
1159
Events::log(NULL, "Loaded shared library %s", filename);
1160
// Reload dll cache. Don't do this in signal handling.
1161
LoadedLibraries::reload();
1162
log_info(os)("shared library load of %s was successful", filename);
1163
return result;
1164
} else {
1165
// error analysis when dlopen fails
1166
const char* error_report = ::dlerror();
1167
if (error_report == NULL) {
1168
error_report = "dlerror returned no error description";
1169
}
1170
if (ebuf != NULL && ebuflen > 0) {
1171
snprintf(ebuf, ebuflen - 1, "%s, LIBPATH=%s, LD_LIBRARY_PATH=%s : %s",
1172
filename, ::getenv("LIBPATH"), ::getenv("LD_LIBRARY_PATH"), error_report);
1173
}
1174
Events::log(NULL, "Loading shared library %s failed, %s", filename, error_report);
1175
log_info(os)("shared library load of %s failed, %s", filename, error_report);
1176
}
1177
return NULL;
1178
}
1179
1180
void* os::dll_lookup(void* handle, const char* name) {
1181
void* res = dlsym(handle, name);
1182
return res;
1183
}
1184
1185
void* os::get_default_process_handle() {
1186
return (void*)::dlopen(NULL, RTLD_LAZY);
1187
}
1188
1189
void os::print_dll_info(outputStream *st) {
1190
st->print_cr("Dynamic libraries:");
1191
LoadedLibraries::print(st);
1192
}
1193
1194
void os::get_summary_os_info(char* buf, size_t buflen) {
1195
// There might be something more readable than uname results for AIX.
1196
struct utsname name;
1197
uname(&name);
1198
snprintf(buf, buflen, "%s %s", name.release, name.version);
1199
}
1200
1201
int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) {
1202
// Not yet implemented.
1203
return 0;
1204
}
1205
1206
void os::print_os_info_brief(outputStream* st) {
1207
uint32_t ver = os::Aix::os_version();
1208
st->print_cr("AIX kernel version %u.%u.%u.%u",
1209
(ver >> 24) & 0xFF, (ver >> 16) & 0xFF, (ver >> 8) & 0xFF, ver & 0xFF);
1210
1211
os::Posix::print_uname_info(st);
1212
1213
// Linux uses print_libversion_info(st); here.
1214
}
1215
1216
void os::print_os_info(outputStream* st) {
1217
st->print_cr("OS:");
1218
1219
os::Posix::print_uname_info(st);
1220
1221
uint32_t ver = os::Aix::os_version();
1222
st->print_cr("AIX kernel version %u.%u.%u.%u",
1223
(ver >> 24) & 0xFF, (ver >> 16) & 0xFF, (ver >> 8) & 0xFF, ver & 0xFF);
1224
1225
os::Posix::print_uptime_info(st);
1226
1227
os::Posix::print_rlimit_info(st);
1228
1229
os::Posix::print_load_average(st);
1230
1231
// _SC_THREAD_THREADS_MAX is the maximum number of threads within a process.
1232
long tmax = sysconf(_SC_THREAD_THREADS_MAX);
1233
st->print_cr("maximum #threads within a process:%ld", tmax);
1234
1235
// print wpar info
1236
libperfstat::wparinfo_t wi;
1237
if (libperfstat::get_wparinfo(&wi)) {
1238
st->print_cr("wpar info");
1239
st->print_cr("name: %s", wi.name);
1240
st->print_cr("id: %d", wi.wpar_id);
1241
st->print_cr("type: %s", (wi.app_wpar ? "application" : "system"));
1242
}
1243
1244
VM_Version::print_platform_virtualization_info(st);
1245
}
1246
1247
void os::print_memory_info(outputStream* st) {
1248
1249
st->print_cr("Memory:");
1250
1251
st->print_cr(" Base page size (sysconf _SC_PAGESIZE): %s",
1252
describe_pagesize(g_multipage_support.pagesize));
1253
st->print_cr(" Data page size (C-Heap, bss, etc): %s",
1254
describe_pagesize(g_multipage_support.datapsize));
1255
st->print_cr(" Text page size: %s",
1256
describe_pagesize(g_multipage_support.textpsize));
1257
st->print_cr(" Thread stack page size (pthread): %s",
1258
describe_pagesize(g_multipage_support.pthr_stack_pagesize));
1259
st->print_cr(" Default shared memory page size: %s",
1260
describe_pagesize(g_multipage_support.shmpsize));
1261
st->print_cr(" Can use 64K pages dynamically with shared memory: %s",
1262
(g_multipage_support.can_use_64K_pages ? "yes" :"no"));
1263
st->print_cr(" Can use 16M pages dynamically with shared memory: %s",
1264
(g_multipage_support.can_use_16M_pages ? "yes" :"no"));
1265
st->print_cr(" Multipage error: %d",
1266
g_multipage_support.error);
1267
st->cr();
1268
st->print_cr(" os::vm_page_size: %s", describe_pagesize(os::vm_page_size()));
1269
1270
// print out LDR_CNTRL because it affects the default page sizes
1271
const char* const ldr_cntrl = ::getenv("LDR_CNTRL");
1272
st->print_cr(" LDR_CNTRL=%s.", ldr_cntrl ? ldr_cntrl : "<unset>");
1273
1274
// Print out EXTSHM because it is an unsupported setting.
1275
const char* const extshm = ::getenv("EXTSHM");
1276
st->print_cr(" EXTSHM=%s.", extshm ? extshm : "<unset>");
1277
if ( (strcmp(extshm, "on") == 0) || (strcmp(extshm, "ON") == 0) ) {
1278
st->print_cr(" *** Unsupported! Please remove EXTSHM from your environment! ***");
1279
}
1280
1281
// Print out AIXTHREAD_GUARDPAGES because it affects the size of pthread stacks.
1282
const char* const aixthread_guardpages = ::getenv("AIXTHREAD_GUARDPAGES");
1283
st->print_cr(" AIXTHREAD_GUARDPAGES=%s.",
1284
aixthread_guardpages ? aixthread_guardpages : "<unset>");
1285
st->cr();
1286
1287
os::Aix::meminfo_t mi;
1288
if (os::Aix::get_meminfo(&mi)) {
1289
if (os::Aix::on_aix()) {
1290
st->print_cr("physical total : " SIZE_FORMAT, mi.real_total);
1291
st->print_cr("physical free : " SIZE_FORMAT, mi.real_free);
1292
st->print_cr("swap total : " SIZE_FORMAT, mi.pgsp_total);
1293
st->print_cr("swap free : " SIZE_FORMAT, mi.pgsp_free);
1294
} else {
1295
// PASE - Numbers are result of QWCRSSTS; they mean:
1296
// real_total: Sum of all system pools
1297
// real_free: always 0
1298
// pgsp_total: we take the size of the system ASP
1299
// pgsp_free: size of system ASP times percentage of system ASP unused
1300
st->print_cr("physical total : " SIZE_FORMAT, mi.real_total);
1301
st->print_cr("system asp total : " SIZE_FORMAT, mi.pgsp_total);
1302
st->print_cr("%% system asp used : %.2f",
1303
mi.pgsp_total ? (100.0f * (mi.pgsp_total - mi.pgsp_free) / mi.pgsp_total) : -1.0f);
1304
}
1305
}
1306
st->cr();
1307
1308
// Print program break.
1309
st->print_cr("Program break at VM startup: " PTR_FORMAT ".", p2i(g_brk_at_startup));
1310
address brk_now = (address)::sbrk(0);
1311
if (brk_now != (address)-1) {
1312
st->print_cr("Program break now : " PTR_FORMAT " (distance: " SIZE_FORMAT "k).",
1313
p2i(brk_now), (size_t)((brk_now - g_brk_at_startup) / K));
1314
}
1315
st->print_cr("MaxExpectedDataSegmentSize : " SIZE_FORMAT "k.", MaxExpectedDataSegmentSize / K);
1316
st->cr();
1317
1318
// Print segments allocated with os::reserve_memory.
1319
st->print_cr("internal virtual memory regions used by vm:");
1320
vmembk_print_on(st);
1321
}
1322
1323
// Get a string for the cpuinfo that is a summary of the cpu type
1324
void os::get_summary_cpu_info(char* buf, size_t buflen) {
1325
// read _system_configuration.version
1326
switch (_system_configuration.version) {
1327
case PV_9:
1328
strncpy(buf, "Power PC 9", buflen);
1329
break;
1330
case PV_8:
1331
strncpy(buf, "Power PC 8", buflen);
1332
break;
1333
case PV_7:
1334
strncpy(buf, "Power PC 7", buflen);
1335
break;
1336
case PV_6_1:
1337
strncpy(buf, "Power PC 6 DD1.x", buflen);
1338
break;
1339
case PV_6:
1340
strncpy(buf, "Power PC 6", buflen);
1341
break;
1342
case PV_5:
1343
strncpy(buf, "Power PC 5", buflen);
1344
break;
1345
case PV_5_2:
1346
strncpy(buf, "Power PC 5_2", buflen);
1347
break;
1348
case PV_5_3:
1349
strncpy(buf, "Power PC 5_3", buflen);
1350
break;
1351
case PV_5_Compat:
1352
strncpy(buf, "PV_5_Compat", buflen);
1353
break;
1354
case PV_6_Compat:
1355
strncpy(buf, "PV_6_Compat", buflen);
1356
break;
1357
case PV_7_Compat:
1358
strncpy(buf, "PV_7_Compat", buflen);
1359
break;
1360
case PV_8_Compat:
1361
strncpy(buf, "PV_8_Compat", buflen);
1362
break;
1363
case PV_9_Compat:
1364
strncpy(buf, "PV_9_Compat", buflen);
1365
break;
1366
default:
1367
strncpy(buf, "unknown", buflen);
1368
}
1369
}
1370
1371
void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) {
1372
// Nothing to do beyond of what os::print_cpu_info() does.
1373
}
1374
1375
static char saved_jvm_path[MAXPATHLEN] = {0};
1376
1377
// Find the full path to the current module, libjvm.so.
1378
void os::jvm_path(char *buf, jint buflen) {
1379
// Error checking.
1380
if (buflen < MAXPATHLEN) {
1381
assert(false, "must use a large-enough buffer");
1382
buf[0] = '\0';
1383
return;
1384
}
1385
// Lazy resolve the path to current module.
1386
if (saved_jvm_path[0] != 0) {
1387
strcpy(buf, saved_jvm_path);
1388
return;
1389
}
1390
1391
Dl_info dlinfo;
1392
int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo);
1393
assert(ret != 0, "cannot locate libjvm");
1394
char* rp = os::Posix::realpath((char *)dlinfo.dli_fname, buf, buflen);
1395
assert(rp != NULL, "error in realpath(): maybe the 'path' argument is too long?");
1396
1397
if (Arguments::sun_java_launcher_is_altjvm()) {
1398
// Support for the java launcher's '-XXaltjvm=<path>' option. Typical
1399
// value for buf is "<JAVA_HOME>/jre/lib/<vmtype>/libjvm.so".
1400
// If "/jre/lib/" appears at the right place in the string, then
1401
// assume we are installed in a JDK and we're done. Otherwise, check
1402
// for a JAVA_HOME environment variable and fix up the path so it
1403
// looks like libjvm.so is installed there (append a fake suffix
1404
// hotspot/libjvm.so).
1405
const char *p = buf + strlen(buf) - 1;
1406
for (int count = 0; p > buf && count < 4; ++count) {
1407
for (--p; p > buf && *p != '/'; --p)
1408
/* empty */ ;
1409
}
1410
1411
if (strncmp(p, "/jre/lib/", 9) != 0) {
1412
// Look for JAVA_HOME in the environment.
1413
char* java_home_var = ::getenv("JAVA_HOME");
1414
if (java_home_var != NULL && java_home_var[0] != 0) {
1415
char* jrelib_p;
1416
int len;
1417
1418
// Check the current module name "libjvm.so".
1419
p = strrchr(buf, '/');
1420
if (p == NULL) {
1421
return;
1422
}
1423
assert(strstr(p, "/libjvm") == p, "invalid library name");
1424
1425
rp = os::Posix::realpath(java_home_var, buf, buflen);
1426
if (rp == NULL) {
1427
return;
1428
}
1429
1430
// determine if this is a legacy image or modules image
1431
// modules image doesn't have "jre" subdirectory
1432
len = strlen(buf);
1433
assert(len < buflen, "Ran out of buffer room");
1434
jrelib_p = buf + len;
1435
snprintf(jrelib_p, buflen-len, "/jre/lib");
1436
if (0 != access(buf, F_OK)) {
1437
snprintf(jrelib_p, buflen-len, "/lib");
1438
}
1439
1440
if (0 == access(buf, F_OK)) {
1441
// Use current module name "libjvm.so"
1442
len = strlen(buf);
1443
snprintf(buf + len, buflen-len, "/hotspot/libjvm.so");
1444
} else {
1445
// Go back to path of .so
1446
rp = os::Posix::realpath((char *)dlinfo.dli_fname, buf, buflen);
1447
if (rp == NULL) {
1448
return;
1449
}
1450
}
1451
}
1452
}
1453
}
1454
1455
strncpy(saved_jvm_path, buf, sizeof(saved_jvm_path));
1456
saved_jvm_path[sizeof(saved_jvm_path) - 1] = '\0';
1457
}
1458
1459
void os::print_jni_name_prefix_on(outputStream* st, int args_size) {
1460
// no prefix required, not even "_"
1461
}
1462
1463
void os::print_jni_name_suffix_on(outputStream* st, int args_size) {
1464
// no suffix required
1465
}
1466
1467
////////////////////////////////////////////////////////////////////////////////
1468
// Virtual Memory
1469
1470
// We need to keep small simple bookkeeping for os::reserve_memory and friends.
1471
1472
#define VMEM_MAPPED 1
1473
#define VMEM_SHMATED 2
1474
1475
struct vmembk_t {
1476
int type; // 1 - mmap, 2 - shmat
1477
char* addr;
1478
size_t size; // Real size, may be larger than usersize.
1479
size_t pagesize; // page size of area
1480
vmembk_t* next;
1481
1482
bool contains_addr(char* p) const {
1483
return p >= addr && p < (addr + size);
1484
}
1485
1486
bool contains_range(char* p, size_t s) const {
1487
return contains_addr(p) && contains_addr(p + s - 1);
1488
}
1489
1490
void print_on(outputStream* os) const {
1491
os->print("[" PTR_FORMAT " - " PTR_FORMAT "] (" UINTX_FORMAT
1492
" bytes, %d %s pages), %s",
1493
addr, addr + size - 1, size, size / pagesize, describe_pagesize(pagesize),
1494
(type == VMEM_SHMATED ? "shmat" : "mmap")
1495
);
1496
}
1497
1498
// Check that range is a sub range of memory block (or equal to memory block);
1499
// also check that range is fully page aligned to the page size if the block.
1500
void assert_is_valid_subrange(char* p, size_t s) const {
1501
if (!contains_range(p, s)) {
1502
trcVerbose("[" PTR_FORMAT " - " PTR_FORMAT "] is not a sub "
1503
"range of [" PTR_FORMAT " - " PTR_FORMAT "].",
1504
p2i(p), p2i(p + s), p2i(addr), p2i(addr + size));
1505
guarantee0(false);
1506
}
1507
if (!is_aligned_to(p, pagesize) || !is_aligned_to(p + s, pagesize)) {
1508
trcVerbose("range [" PTR_FORMAT " - " PTR_FORMAT "] is not"
1509
" aligned to pagesize (%lu)", p2i(p), p2i(p + s), (unsigned long) pagesize);
1510
guarantee0(false);
1511
}
1512
}
1513
};
1514
1515
static struct {
1516
vmembk_t* first;
1517
MiscUtils::CritSect cs;
1518
} vmem;
1519
1520
static void vmembk_add(char* addr, size_t size, size_t pagesize, int type) {
1521
vmembk_t* p = (vmembk_t*) ::malloc(sizeof(vmembk_t));
1522
assert0(p);
1523
if (p) {
1524
MiscUtils::AutoCritSect lck(&vmem.cs);
1525
p->addr = addr; p->size = size;
1526
p->pagesize = pagesize;
1527
p->type = type;
1528
p->next = vmem.first;
1529
vmem.first = p;
1530
}
1531
}
1532
1533
static vmembk_t* vmembk_find(char* addr) {
1534
MiscUtils::AutoCritSect lck(&vmem.cs);
1535
for (vmembk_t* p = vmem.first; p; p = p->next) {
1536
if (p->addr <= addr && (p->addr + p->size) > addr) {
1537
return p;
1538
}
1539
}
1540
return NULL;
1541
}
1542
1543
static void vmembk_remove(vmembk_t* p0) {
1544
MiscUtils::AutoCritSect lck(&vmem.cs);
1545
assert0(p0);
1546
assert0(vmem.first); // List should not be empty.
1547
for (vmembk_t** pp = &(vmem.first); *pp; pp = &((*pp)->next)) {
1548
if (*pp == p0) {
1549
*pp = p0->next;
1550
::free(p0);
1551
return;
1552
}
1553
}
1554
assert0(false); // Not found?
1555
}
1556
1557
static void vmembk_print_on(outputStream* os) {
1558
MiscUtils::AutoCritSect lck(&vmem.cs);
1559
for (vmembk_t* vmi = vmem.first; vmi; vmi = vmi->next) {
1560
vmi->print_on(os);
1561
os->cr();
1562
}
1563
}
1564
1565
// Reserve and attach a section of System V memory.
1566
// If <requested_addr> is not NULL, function will attempt to attach the memory at the given
1567
// address. Failing that, it will attach the memory anywhere.
1568
// If <requested_addr> is NULL, function will attach the memory anywhere.
1569
static char* reserve_shmated_memory (size_t bytes, char* requested_addr) {
1570
1571
trcVerbose("reserve_shmated_memory " UINTX_FORMAT " bytes, wishaddress "
1572
PTR_FORMAT "...", bytes, p2i(requested_addr));
1573
1574
// We must prevent anyone from attaching too close to the
1575
// BRK because that may cause malloc OOM.
1576
if (requested_addr != NULL && is_close_to_brk((address)requested_addr)) {
1577
trcVerbose("Wish address " PTR_FORMAT " is too close to the BRK segment.", p2i(requested_addr));
1578
// Since we treat an attach to the wrong address as an error later anyway,
1579
// we return NULL here
1580
return NULL;
1581
}
1582
1583
// For old AS/400's (V5R4 and older) we should not even be here - System V shared memory is not
1584
// really supported (max size 4GB), so reserve_mmapped_memory should have been used instead.
1585
if (os::Aix::on_pase_V5R4_or_older()) {
1586
ShouldNotReachHere();
1587
}
1588
1589
// Align size of shm up to 64K to avoid errors if we later try to change the page size.
1590
const size_t size = align_up(bytes, 64*K);
1591
1592
// Reserve the shared segment.
1593
int shmid = shmget(IPC_PRIVATE, size, IPC_CREAT | S_IRUSR | S_IWUSR);
1594
if (shmid == -1) {
1595
trcVerbose("shmget(.., " UINTX_FORMAT ", ..) failed (errno: %d).", size, errno);
1596
return NULL;
1597
}
1598
1599
// Important note:
1600
// It is very important that we, upon leaving this function, do not leave a shm segment alive.
1601
// We must right after attaching it remove it from the system. System V shm segments are global and
1602
// survive the process.
1603
// So, from here on: Do not assert, do not return, until we have called shmctl(IPC_RMID) (A).
1604
1605
struct shmid_ds shmbuf;
1606
memset(&shmbuf, 0, sizeof(shmbuf));
1607
shmbuf.shm_pagesize = 64*K;
1608
if (shmctl(shmid, SHM_PAGESIZE, &shmbuf) != 0) {
1609
trcVerbose("Failed to set page size (need " UINTX_FORMAT " 64K pages) - shmctl failed with %d.",
1610
size / (64*K), errno);
1611
// I want to know if this ever happens.
1612
assert(false, "failed to set page size for shmat");
1613
}
1614
1615
// Now attach the shared segment.
1616
// Note that I attach with SHM_RND - which means that the requested address is rounded down, if
1617
// needed, to the next lowest segment boundary. Otherwise the attach would fail if the address
1618
// were not a segment boundary.
1619
char* const addr = (char*) shmat(shmid, requested_addr, SHM_RND);
1620
const int errno_shmat = errno;
1621
1622
// (A) Right after shmat and before handing shmat errors delete the shm segment.
1623
if (::shmctl(shmid, IPC_RMID, NULL) == -1) {
1624
trcVerbose("shmctl(%u, IPC_RMID) failed (%d)\n", shmid, errno);
1625
assert(false, "failed to remove shared memory segment!");
1626
}
1627
1628
// Handle shmat error. If we failed to attach, just return.
1629
if (addr == (char*)-1) {
1630
trcVerbose("Failed to attach segment at " PTR_FORMAT " (%d).", p2i(requested_addr), errno_shmat);
1631
return NULL;
1632
}
1633
1634
// Just for info: query the real page size. In case setting the page size did not
1635
// work (see above), the system may have given us something other then 4K (LDR_CNTRL).
1636
const size_t real_pagesize = os::Aix::query_pagesize(addr);
1637
if (real_pagesize != shmbuf.shm_pagesize) {
1638
trcVerbose("pagesize is, surprisingly, " SIZE_FORMAT, real_pagesize);
1639
}
1640
1641
if (addr) {
1642
trcVerbose("shm-allocated " PTR_FORMAT " .. " PTR_FORMAT " (" UINTX_FORMAT " bytes, " UINTX_FORMAT " %s pages)",
1643
p2i(addr), p2i(addr + size - 1), size, size/real_pagesize, describe_pagesize(real_pagesize));
1644
} else {
1645
if (requested_addr != NULL) {
1646
trcVerbose("failed to shm-allocate " UINTX_FORMAT " bytes at with address " PTR_FORMAT ".", size, p2i(requested_addr));
1647
} else {
1648
trcVerbose("failed to shm-allocate " UINTX_FORMAT " bytes at any address.", size);
1649
}
1650
}
1651
1652
// book-keeping
1653
vmembk_add(addr, size, real_pagesize, VMEM_SHMATED);
1654
assert0(is_aligned_to(addr, os::vm_page_size()));
1655
1656
return addr;
1657
}
1658
1659
static bool release_shmated_memory(char* addr, size_t size) {
1660
1661
trcVerbose("release_shmated_memory [" PTR_FORMAT " - " PTR_FORMAT "].",
1662
p2i(addr), p2i(addr + size - 1));
1663
1664
bool rc = false;
1665
1666
// TODO: is there a way to verify shm size without doing bookkeeping?
1667
if (::shmdt(addr) != 0) {
1668
trcVerbose("error (%d).", errno);
1669
} else {
1670
trcVerbose("ok.");
1671
rc = true;
1672
}
1673
return rc;
1674
}
1675
1676
static bool uncommit_shmated_memory(char* addr, size_t size) {
1677
trcVerbose("uncommit_shmated_memory [" PTR_FORMAT " - " PTR_FORMAT "].",
1678
p2i(addr), p2i(addr + size - 1));
1679
1680
const bool rc = my_disclaim64(addr, size);
1681
1682
if (!rc) {
1683
trcVerbose("my_disclaim64(" PTR_FORMAT ", " UINTX_FORMAT ") failed.\n", p2i(addr), size);
1684
return false;
1685
}
1686
return true;
1687
}
1688
1689
//////////////////////////////// mmap-based routines /////////////////////////////////
1690
1691
// Reserve memory via mmap.
1692
// If <requested_addr> is given, an attempt is made to attach at the given address.
1693
// Failing that, memory is allocated at any address.
1694
static char* reserve_mmaped_memory(size_t bytes, char* requested_addr) {
1695
trcVerbose("reserve_mmaped_memory " UINTX_FORMAT " bytes, wishaddress " PTR_FORMAT "...",
1696
bytes, p2i(requested_addr));
1697
1698
if (requested_addr && !is_aligned_to(requested_addr, os::vm_page_size()) != 0) {
1699
trcVerbose("Wish address " PTR_FORMAT " not aligned to page boundary.", p2i(requested_addr));
1700
return NULL;
1701
}
1702
1703
// We must prevent anyone from attaching too close to the
1704
// BRK because that may cause malloc OOM.
1705
if (requested_addr != NULL && is_close_to_brk((address)requested_addr)) {
1706
trcVerbose("Wish address " PTR_FORMAT " is too close to the BRK segment.", p2i(requested_addr));
1707
// Since we treat an attach to the wrong address as an error later anyway,
1708
// we return NULL here
1709
return NULL;
1710
}
1711
1712
// In 64K mode, we lie and claim the global page size (os::vm_page_size()) is 64K
1713
// (complicated story). This mostly works just fine since 64K is a multiple of the
1714
// actual 4K lowest page size. Only at a few seams light shines thru, e.g. when
1715
// calling mmap. mmap will return memory aligned to the lowest pages size - 4K -
1716
// so we must make sure - transparently - that the caller only ever sees 64K
1717
// aligned mapping start addresses.
1718
const size_t alignment = os::vm_page_size();
1719
1720
// Size shall always be a multiple of os::vm_page_size (esp. in 64K mode).
1721
const size_t size = align_up(bytes, os::vm_page_size());
1722
1723
// alignment: Allocate memory large enough to include an aligned range of the right size and
1724
// cut off the leading and trailing waste pages.
1725
assert0(alignment != 0 && is_aligned_to(alignment, os::vm_page_size())); // see above
1726
const size_t extra_size = size + alignment;
1727
1728
// Note: MAP_SHARED (instead of MAP_PRIVATE) needed to be able to
1729
// later use msync(MS_INVALIDATE) (see os::uncommit_memory).
1730
int flags = MAP_ANONYMOUS | MAP_SHARED;
1731
1732
// MAP_FIXED is needed to enforce requested_addr - manpage is vague about what
1733
// it means if wishaddress is given but MAP_FIXED is not set.
1734
//
1735
// Important! Behaviour differs depending on whether SPEC1170 mode is active or not.
1736
// SPEC1170 mode active: behaviour like POSIX, MAP_FIXED will clobber existing mappings.
1737
// SPEC1170 mode not active: behaviour, unlike POSIX, is that no existing mappings will
1738
// get clobbered.
1739
if (requested_addr != NULL) {
1740
if (!os::Aix::xpg_sus_mode()) { // not SPEC1170 Behaviour
1741
flags |= MAP_FIXED;
1742
}
1743
}
1744
1745
char* addr = (char*)::mmap(requested_addr, extra_size,
1746
PROT_READ|PROT_WRITE|PROT_EXEC, flags, -1, 0);
1747
1748
if (addr == MAP_FAILED) {
1749
trcVerbose("mmap(" PTR_FORMAT ", " UINTX_FORMAT ", ..) failed (%d)", p2i(requested_addr), size, errno);
1750
return NULL;
1751
} else if (requested_addr != NULL && addr != requested_addr) {
1752
trcVerbose("mmap(" PTR_FORMAT ", " UINTX_FORMAT ", ..) succeeded, but at a different address than requested (" PTR_FORMAT "), will unmap",
1753
p2i(requested_addr), size, p2i(addr));
1754
::munmap(addr, extra_size);
1755
return NULL;
1756
}
1757
1758
// Handle alignment.
1759
char* const addr_aligned = align_up(addr, alignment);
1760
const size_t waste_pre = addr_aligned - addr;
1761
char* const addr_aligned_end = addr_aligned + size;
1762
const size_t waste_post = extra_size - waste_pre - size;
1763
if (waste_pre > 0) {
1764
::munmap(addr, waste_pre);
1765
}
1766
if (waste_post > 0) {
1767
::munmap(addr_aligned_end, waste_post);
1768
}
1769
addr = addr_aligned;
1770
1771
trcVerbose("mmap-allocated " PTR_FORMAT " .. " PTR_FORMAT " (" UINTX_FORMAT " bytes)",
1772
p2i(addr), p2i(addr + bytes), bytes);
1773
1774
// bookkeeping
1775
vmembk_add(addr, size, 4*K, VMEM_MAPPED);
1776
1777
// Test alignment, see above.
1778
assert0(is_aligned_to(addr, os::vm_page_size()));
1779
1780
return addr;
1781
}
1782
1783
static bool release_mmaped_memory(char* addr, size_t size) {
1784
assert0(is_aligned_to(addr, os::vm_page_size()));
1785
assert0(is_aligned_to(size, os::vm_page_size()));
1786
1787
trcVerbose("release_mmaped_memory [" PTR_FORMAT " - " PTR_FORMAT "].",
1788
p2i(addr), p2i(addr + size - 1));
1789
bool rc = false;
1790
1791
if (::munmap(addr, size) != 0) {
1792
trcVerbose("failed (%d)\n", errno);
1793
rc = false;
1794
} else {
1795
trcVerbose("ok.");
1796
rc = true;
1797
}
1798
1799
return rc;
1800
}
1801
1802
static bool uncommit_mmaped_memory(char* addr, size_t size) {
1803
1804
assert0(is_aligned_to(addr, os::vm_page_size()));
1805
assert0(is_aligned_to(size, os::vm_page_size()));
1806
1807
trcVerbose("uncommit_mmaped_memory [" PTR_FORMAT " - " PTR_FORMAT "].",
1808
p2i(addr), p2i(addr + size - 1));
1809
bool rc = false;
1810
1811
// Uncommit mmap memory with msync MS_INVALIDATE.
1812
if (::msync(addr, size, MS_INVALIDATE) != 0) {
1813
trcVerbose("failed (%d)\n", errno);
1814
rc = false;
1815
} else {
1816
trcVerbose("ok.");
1817
rc = true;
1818
}
1819
1820
return rc;
1821
}
1822
1823
int os::vm_page_size() {
1824
// Seems redundant as all get out.
1825
assert(os::Aix::page_size() != -1, "must call os::init");
1826
return os::Aix::page_size();
1827
}
1828
1829
// Aix allocates memory by pages.
1830
int os::vm_allocation_granularity() {
1831
assert(os::Aix::page_size() != -1, "must call os::init");
1832
return os::Aix::page_size();
1833
}
1834
1835
#ifdef PRODUCT
1836
static void warn_fail_commit_memory(char* addr, size_t size, bool exec,
1837
int err) {
1838
warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
1839
", %d) failed; error='%s' (errno=%d)", p2i(addr), size, exec,
1840
os::errno_name(err), err);
1841
}
1842
#endif
1843
1844
void os::pd_commit_memory_or_exit(char* addr, size_t size, bool exec,
1845
const char* mesg) {
1846
assert(mesg != NULL, "mesg must be specified");
1847
if (!pd_commit_memory(addr, size, exec)) {
1848
// Add extra info in product mode for vm_exit_out_of_memory():
1849
PRODUCT_ONLY(warn_fail_commit_memory(addr, size, exec, errno);)
1850
vm_exit_out_of_memory(size, OOM_MMAP_ERROR, "%s", mesg);
1851
}
1852
}
1853
1854
bool os::pd_commit_memory(char* addr, size_t size, bool exec) {
1855
1856
assert(is_aligned_to(addr, os::vm_page_size()),
1857
"addr " PTR_FORMAT " not aligned to vm_page_size (" PTR_FORMAT ")",
1858
p2i(addr), os::vm_page_size());
1859
assert(is_aligned_to(size, os::vm_page_size()),
1860
"size " PTR_FORMAT " not aligned to vm_page_size (" PTR_FORMAT ")",
1861
size, os::vm_page_size());
1862
1863
vmembk_t* const vmi = vmembk_find(addr);
1864
guarantee0(vmi);
1865
vmi->assert_is_valid_subrange(addr, size);
1866
1867
trcVerbose("commit_memory [" PTR_FORMAT " - " PTR_FORMAT "].", p2i(addr), p2i(addr + size - 1));
1868
1869
if (UseExplicitCommit) {
1870
// AIX commits memory on touch. So, touch all pages to be committed.
1871
for (char* p = addr; p < (addr + size); p += 4*K) {
1872
*p = '\0';
1873
}
1874
}
1875
1876
return true;
1877
}
1878
1879
bool os::pd_commit_memory(char* addr, size_t size, size_t alignment_hint, bool exec) {
1880
return pd_commit_memory(addr, size, exec);
1881
}
1882
1883
void os::pd_commit_memory_or_exit(char* addr, size_t size,
1884
size_t alignment_hint, bool exec,
1885
const char* mesg) {
1886
// Alignment_hint is ignored on this OS.
1887
pd_commit_memory_or_exit(addr, size, exec, mesg);
1888
}
1889
1890
bool os::pd_uncommit_memory(char* addr, size_t size, bool exec) {
1891
assert(is_aligned_to(addr, os::vm_page_size()),
1892
"addr " PTR_FORMAT " not aligned to vm_page_size (" PTR_FORMAT ")",
1893
p2i(addr), os::vm_page_size());
1894
assert(is_aligned_to(size, os::vm_page_size()),
1895
"size " PTR_FORMAT " not aligned to vm_page_size (" PTR_FORMAT ")",
1896
size, os::vm_page_size());
1897
1898
// Dynamically do different things for mmap/shmat.
1899
const vmembk_t* const vmi = vmembk_find(addr);
1900
guarantee0(vmi);
1901
vmi->assert_is_valid_subrange(addr, size);
1902
1903
if (vmi->type == VMEM_SHMATED) {
1904
return uncommit_shmated_memory(addr, size);
1905
} else {
1906
return uncommit_mmaped_memory(addr, size);
1907
}
1908
}
1909
1910
bool os::pd_create_stack_guard_pages(char* addr, size_t size) {
1911
// Do not call this; no need to commit stack pages on AIX.
1912
ShouldNotReachHere();
1913
return true;
1914
}
1915
1916
bool os::remove_stack_guard_pages(char* addr, size_t size) {
1917
// Do not call this; no need to commit stack pages on AIX.
1918
ShouldNotReachHere();
1919
return true;
1920
}
1921
1922
void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
1923
}
1924
1925
void os::pd_free_memory(char *addr, size_t bytes, size_t alignment_hint) {
1926
}
1927
1928
void os::numa_make_global(char *addr, size_t bytes) {
1929
}
1930
1931
void os::numa_make_local(char *addr, size_t bytes, int lgrp_hint) {
1932
}
1933
1934
bool os::numa_topology_changed() {
1935
return false;
1936
}
1937
1938
size_t os::numa_get_groups_num() {
1939
return 1;
1940
}
1941
1942
int os::numa_get_group_id() {
1943
return 0;
1944
}
1945
1946
size_t os::numa_get_leaf_groups(int *ids, size_t size) {
1947
if (size > 0) {
1948
ids[0] = 0;
1949
return 1;
1950
}
1951
return 0;
1952
}
1953
1954
int os::numa_get_group_id_for_address(const void* address) {
1955
return 0;
1956
}
1957
1958
bool os::get_page_info(char *start, page_info* info) {
1959
return false;
1960
}
1961
1962
char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) {
1963
return end;
1964
}
1965
1966
// Reserves and attaches a shared memory segment.
1967
char* os::pd_reserve_memory(size_t bytes, bool exec) {
1968
// Always round to os::vm_page_size(), which may be larger than 4K.
1969
bytes = align_up(bytes, os::vm_page_size());
1970
1971
// In 4K mode always use mmap.
1972
// In 64K mode allocate small sizes with mmap, large ones with 64K shmatted.
1973
if (os::vm_page_size() == 4*K) {
1974
return reserve_mmaped_memory(bytes, NULL /* requested_addr */);
1975
} else {
1976
if (bytes >= Use64KPagesThreshold) {
1977
return reserve_shmated_memory(bytes, NULL /* requested_addr */);
1978
} else {
1979
return reserve_mmaped_memory(bytes, NULL /* requested_addr */);
1980
}
1981
}
1982
}
1983
1984
bool os::pd_release_memory(char* addr, size_t size) {
1985
1986
// Dynamically do different things for mmap/shmat.
1987
vmembk_t* const vmi = vmembk_find(addr);
1988
guarantee0(vmi);
1989
vmi->assert_is_valid_subrange(addr, size);
1990
1991
// Always round to os::vm_page_size(), which may be larger than 4K.
1992
size = align_up(size, os::vm_page_size());
1993
addr = align_up(addr, os::vm_page_size());
1994
1995
bool rc = false;
1996
bool remove_bookkeeping = false;
1997
if (vmi->type == VMEM_SHMATED) {
1998
// For shmatted memory, we do:
1999
// - If user wants to release the whole range, release the memory (shmdt).
2000
// - If user only wants to release a partial range, uncommit (disclaim) that
2001
// range. That way, at least, we do not use memory anymore (bust still page
2002
// table space).
2003
if (addr == vmi->addr && size == vmi->size) {
2004
rc = release_shmated_memory(addr, size);
2005
remove_bookkeeping = true;
2006
} else {
2007
rc = uncommit_shmated_memory(addr, size);
2008
}
2009
} else {
2010
// In mmap-mode:
2011
// - If the user wants to release the full range, we do that and remove the mapping.
2012
// - If the user wants to release part of the range, we release that part, but need
2013
// to adjust bookkeeping.
2014
assert(is_aligned(size, 4 * K), "Sanity");
2015
rc = release_mmaped_memory(addr, size);
2016
if (addr == vmi->addr && size == vmi->size) {
2017
remove_bookkeeping = true;
2018
} else {
2019
if (addr == vmi->addr && size < vmi->size) {
2020
// Chopped from head
2021
vmi->addr += size;
2022
vmi->size -= size;
2023
} else if (addr + size == vmi->addr + vmi->size) {
2024
// Chopped from tail
2025
vmi->size -= size;
2026
} else {
2027
// releasing a mapping in the middle of the original mapping:
2028
// For now we forbid this, since this is an invalid scenario
2029
// (the bookkeeping is easy enough to fix if needed but there
2030
// is no use case for it; any occurrence is likely an error.
2031
ShouldNotReachHere();
2032
}
2033
}
2034
}
2035
2036
// update bookkeeping
2037
if (rc && remove_bookkeeping) {
2038
vmembk_remove(vmi);
2039
}
2040
2041
return rc;
2042
}
2043
2044
static bool checked_mprotect(char* addr, size_t size, int prot) {
2045
2046
// Little problem here: if SPEC1170 behaviour is off, mprotect() on AIX will
2047
// not tell me if protection failed when trying to protect an un-protectable range.
2048
//
2049
// This means if the memory was allocated using shmget/shmat, protection wont work
2050
// but mprotect will still return 0:
2051
//
2052
// See http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/mprotect.htm
2053
2054
Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
2055
bool rc = ::mprotect(addr, size, prot) == 0 ? true : false;
2056
2057
if (!rc) {
2058
const char* const s_errno = os::errno_name(errno);
2059
warning("mprotect(" PTR_FORMAT "-" PTR_FORMAT ", 0x%X) failed (%s).", addr, addr + size, prot, s_errno);
2060
return false;
2061
}
2062
2063
// mprotect success check
2064
//
2065
// Mprotect said it changed the protection but can I believe it?
2066
//
2067
// To be sure I need to check the protection afterwards. Try to
2068
// read from protected memory and check whether that causes a segfault.
2069
//
2070
if (!os::Aix::xpg_sus_mode()) {
2071
2072
if (CanUseSafeFetch32()) {
2073
2074
const bool read_protected =
2075
(SafeFetch32((int*)addr, 0x12345678) == 0x12345678 &&
2076
SafeFetch32((int*)addr, 0x76543210) == 0x76543210) ? true : false;
2077
2078
if (prot & PROT_READ) {
2079
rc = !read_protected;
2080
} else {
2081
rc = read_protected;
2082
}
2083
2084
if (!rc) {
2085
if (os::Aix::on_pase()) {
2086
// There is an issue on older PASE systems where mprotect() will return success but the
2087
// memory will not be protected.
2088
// This has nothing to do with the problem of using mproect() on SPEC1170 incompatible
2089
// machines; we only see it rarely, when using mprotect() to protect the guard page of
2090
// a stack. It is an OS error.
2091
//
2092
// A valid strategy is just to try again. This usually works. :-/
2093
2094
::usleep(1000);
2095
Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
2096
if (::mprotect(addr, size, prot) == 0) {
2097
const bool read_protected_2 =
2098
(SafeFetch32((int*)addr, 0x12345678) == 0x12345678 &&
2099
SafeFetch32((int*)addr, 0x76543210) == 0x76543210) ? true : false;
2100
rc = true;
2101
}
2102
}
2103
}
2104
}
2105
}
2106
2107
assert(rc == true, "mprotect failed.");
2108
2109
return rc;
2110
}
2111
2112
// Set protections specified
2113
bool os::protect_memory(char* addr, size_t size, ProtType prot, bool is_committed) {
2114
unsigned int p = 0;
2115
switch (prot) {
2116
case MEM_PROT_NONE: p = PROT_NONE; break;
2117
case MEM_PROT_READ: p = PROT_READ; break;
2118
case MEM_PROT_RW: p = PROT_READ|PROT_WRITE; break;
2119
case MEM_PROT_RWX: p = PROT_READ|PROT_WRITE|PROT_EXEC; break;
2120
default:
2121
ShouldNotReachHere();
2122
}
2123
// is_committed is unused.
2124
return checked_mprotect(addr, size, p);
2125
}
2126
2127
bool os::guard_memory(char* addr, size_t size) {
2128
return checked_mprotect(addr, size, PROT_NONE);
2129
}
2130
2131
bool os::unguard_memory(char* addr, size_t size) {
2132
return checked_mprotect(addr, size, PROT_READ|PROT_WRITE|PROT_EXEC);
2133
}
2134
2135
// Large page support
2136
2137
static size_t _large_page_size = 0;
2138
2139
// Enable large page support if OS allows that.
2140
void os::large_page_init() {
2141
return; // Nothing to do. See query_multipage_support and friends.
2142
}
2143
2144
char* os::pd_reserve_memory_special(size_t bytes, size_t alignment, size_t page_size, char* req_addr, bool exec) {
2145
fatal("os::reserve_memory_special should not be called on AIX.");
2146
return NULL;
2147
}
2148
2149
bool os::pd_release_memory_special(char* base, size_t bytes) {
2150
fatal("os::release_memory_special should not be called on AIX.");
2151
return false;
2152
}
2153
2154
size_t os::large_page_size() {
2155
return _large_page_size;
2156
}
2157
2158
bool os::can_commit_large_page_memory() {
2159
// Does not matter, we do not support huge pages.
2160
return false;
2161
}
2162
2163
bool os::can_execute_large_page_memory() {
2164
// Does not matter, we do not support huge pages.
2165
return false;
2166
}
2167
2168
char* os::pd_attempt_map_memory_to_file_at(char* requested_addr, size_t bytes, int file_desc) {
2169
assert(file_desc >= 0, "file_desc is not valid");
2170
char* result = NULL;
2171
2172
// Always round to os::vm_page_size(), which may be larger than 4K.
2173
bytes = align_up(bytes, os::vm_page_size());
2174
result = reserve_mmaped_memory(bytes, requested_addr);
2175
2176
if (result != NULL) {
2177
if (replace_existing_mapping_with_file_mapping(result, bytes, file_desc) == NULL) {
2178
vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory"));
2179
}
2180
}
2181
return result;
2182
}
2183
2184
// Reserve memory at an arbitrary address, only if that area is
2185
// available (and not reserved for something else).
2186
char* os::pd_attempt_reserve_memory_at(char* requested_addr, size_t bytes, bool exec) {
2187
char* addr = NULL;
2188
2189
// Always round to os::vm_page_size(), which may be larger than 4K.
2190
bytes = align_up(bytes, os::vm_page_size());
2191
2192
// In 4K mode always use mmap.
2193
// In 64K mode allocate small sizes with mmap, large ones with 64K shmatted.
2194
if (os::vm_page_size() == 4*K) {
2195
return reserve_mmaped_memory(bytes, requested_addr);
2196
} else {
2197
if (bytes >= Use64KPagesThreshold) {
2198
return reserve_shmated_memory(bytes, requested_addr);
2199
} else {
2200
return reserve_mmaped_memory(bytes, requested_addr);
2201
}
2202
}
2203
2204
return addr;
2205
}
2206
2207
// Sleep forever; naked call to OS-specific sleep; use with CAUTION
2208
void os::infinite_sleep() {
2209
while (true) { // sleep forever ...
2210
::sleep(100); // ... 100 seconds at a time
2211
}
2212
}
2213
2214
// Used to convert frequent JVM_Yield() to nops
2215
bool os::dont_yield() {
2216
return DontYieldALot;
2217
}
2218
2219
void os::naked_yield() {
2220
sched_yield();
2221
}
2222
2223
////////////////////////////////////////////////////////////////////////////////
2224
// thread priority support
2225
2226
// From AIX manpage to pthread_setschedparam
2227
// (see: http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?
2228
// topic=/com.ibm.aix.basetechref/doc/basetrf1/pthread_setschedparam.htm):
2229
//
2230
// "If schedpolicy is SCHED_OTHER, then sched_priority must be in the
2231
// range from 40 to 80, where 40 is the least favored priority and 80
2232
// is the most favored."
2233
//
2234
// (Actually, I doubt this even has an impact on AIX, as we do kernel
2235
// scheduling there; however, this still leaves iSeries.)
2236
//
2237
// We use the same values for AIX and PASE.
2238
int os::java_to_os_priority[CriticalPriority + 1] = {
2239
54, // 0 Entry should never be used
2240
2241
55, // 1 MinPriority
2242
55, // 2
2243
56, // 3
2244
2245
56, // 4
2246
57, // 5 NormPriority
2247
57, // 6
2248
2249
58, // 7
2250
58, // 8
2251
59, // 9 NearMaxPriority
2252
2253
60, // 10 MaxPriority
2254
2255
60 // 11 CriticalPriority
2256
};
2257
2258
static int prio_init() {
2259
if (ThreadPriorityPolicy == 1) {
2260
if (geteuid() != 0) {
2261
if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy) && !FLAG_IS_JIMAGE_RESOURCE(ThreadPriorityPolicy)) {
2262
warning("-XX:ThreadPriorityPolicy=1 may require system level permission, " \
2263
"e.g., being the root user. If the necessary permission is not " \
2264
"possessed, changes to priority will be silently ignored.");
2265
}
2266
}
2267
}
2268
if (UseCriticalJavaThreadPriority) {
2269
os::java_to_os_priority[MaxPriority] = os::java_to_os_priority[CriticalPriority];
2270
}
2271
return 0;
2272
}
2273
2274
OSReturn os::set_native_priority(Thread* thread, int newpri) {
2275
if (!UseThreadPriorities || ThreadPriorityPolicy == 0) return OS_OK;
2276
pthread_t thr = thread->osthread()->pthread_id();
2277
int policy = SCHED_OTHER;
2278
struct sched_param param;
2279
param.sched_priority = newpri;
2280
int ret = pthread_setschedparam(thr, policy, &param);
2281
2282
if (ret != 0) {
2283
trcVerbose("Could not change priority for thread %d to %d (error %d, %s)",
2284
(int)thr, newpri, ret, os::errno_name(ret));
2285
}
2286
return (ret == 0) ? OS_OK : OS_ERR;
2287
}
2288
2289
OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) {
2290
if (!UseThreadPriorities || ThreadPriorityPolicy == 0) {
2291
*priority_ptr = java_to_os_priority[NormPriority];
2292
return OS_OK;
2293
}
2294
pthread_t thr = thread->osthread()->pthread_id();
2295
int policy = SCHED_OTHER;
2296
struct sched_param param;
2297
int ret = pthread_getschedparam(thr, &policy, &param);
2298
*priority_ptr = param.sched_priority;
2299
2300
return (ret == 0) ? OS_OK : OS_ERR;
2301
}
2302
2303
// To install functions for atexit system call
2304
extern "C" {
2305
static void perfMemory_exit_helper() {
2306
perfMemory_exit();
2307
}
2308
}
2309
2310
// This is called _before_ the most of global arguments have been parsed.
2311
void os::init(void) {
2312
// This is basic, we want to know if that ever changes.
2313
// (Shared memory boundary is supposed to be a 256M aligned.)
2314
assert(SHMLBA == ((uint64_t)0x10000000ULL)/*256M*/, "unexpected");
2315
2316
// Record process break at startup.
2317
g_brk_at_startup = (address) ::sbrk(0);
2318
assert(g_brk_at_startup != (address) -1, "sbrk failed");
2319
2320
// First off, we need to know whether we run on AIX or PASE, and
2321
// the OS level we run on.
2322
os::Aix::initialize_os_info();
2323
2324
// Scan environment (SPEC1170 behaviour, etc).
2325
os::Aix::scan_environment();
2326
2327
// Probe multipage support.
2328
query_multipage_support();
2329
2330
// Act like we only have one page size by eliminating corner cases which
2331
// we did not support very well anyway.
2332
// We have two input conditions:
2333
// 1) Data segment page size. This is controlled by linker setting (datapsize) on the
2334
// launcher, and/or by LDR_CNTRL environment variable. The latter overrules the linker
2335
// setting.
2336
// Data segment page size is important for us because it defines the thread stack page
2337
// size, which is needed for guard page handling, stack banging etc.
2338
// 2) The ability to allocate 64k pages dynamically. If this is a given, java heap can
2339
// and should be allocated with 64k pages.
2340
//
2341
// So, we do the following:
2342
// LDR_CNTRL can_use_64K_pages_dynamically what we do remarks
2343
// 4K no 4K old systems (aix 5.2, as/400 v5r4) or new systems with AME activated
2344
// 4k yes 64k (treat 4k stacks as 64k) different loader than java and standard settings
2345
// 64k no --- AIX 5.2 ? ---
2346
// 64k yes 64k new systems and standard java loader (we set datapsize=64k when linking)
2347
2348
// We explicitly leave no option to change page size, because only upgrading would work,
2349
// not downgrading (if stack page size is 64k you cannot pretend its 4k).
2350
2351
if (g_multipage_support.datapsize == 4*K) {
2352
// datapsize = 4K. Data segment, thread stacks are 4K paged.
2353
if (g_multipage_support.can_use_64K_pages) {
2354
// .. but we are able to use 64K pages dynamically.
2355
// This would be typical for java launchers which are not linked
2356
// with datapsize=64K (like, any other launcher but our own).
2357
//
2358
// In this case it would be smart to allocate the java heap with 64K
2359
// to get the performance benefit, and to fake 64k pages for the
2360
// data segment (when dealing with thread stacks).
2361
//
2362
// However, leave a possibility to downgrade to 4K, using
2363
// -XX:-Use64KPages.
2364
if (Use64KPages) {
2365
trcVerbose("64K page mode (faked for data segment)");
2366
Aix::_page_size = 64*K;
2367
} else {
2368
trcVerbose("4K page mode (Use64KPages=off)");
2369
Aix::_page_size = 4*K;
2370
}
2371
} else {
2372
// .. and not able to allocate 64k pages dynamically. Here, just
2373
// fall back to 4K paged mode and use mmap for everything.
2374
trcVerbose("4K page mode");
2375
Aix::_page_size = 4*K;
2376
FLAG_SET_ERGO(Use64KPages, false);
2377
}
2378
} else {
2379
// datapsize = 64k. Data segment, thread stacks are 64k paged.
2380
// This normally means that we can allocate 64k pages dynamically.
2381
// (There is one special case where this may be false: EXTSHM=on.
2382
// but we decided to not support that mode).
2383
assert0(g_multipage_support.can_use_64K_pages);
2384
Aix::_page_size = 64*K;
2385
trcVerbose("64K page mode");
2386
FLAG_SET_ERGO(Use64KPages, true);
2387
}
2388
2389
// For now UseLargePages is just ignored.
2390
FLAG_SET_ERGO(UseLargePages, false);
2391
_page_sizes.add(Aix::_page_size);
2392
2393
// debug trace
2394
trcVerbose("os::vm_page_size %s", describe_pagesize(os::vm_page_size()));
2395
2396
// Next, we need to initialize libo4 and libperfstat libraries.
2397
if (os::Aix::on_pase()) {
2398
os::Aix::initialize_libo4();
2399
} else {
2400
os::Aix::initialize_libperfstat();
2401
}
2402
2403
// Reset the perfstat information provided by ODM.
2404
if (os::Aix::on_aix()) {
2405
libperfstat::perfstat_reset();
2406
}
2407
2408
// Now initialze basic system properties. Note that for some of the values we
2409
// need libperfstat etc.
2410
os::Aix::initialize_system_info();
2411
2412
clock_tics_per_sec = sysconf(_SC_CLK_TCK);
2413
2414
// _main_thread points to the thread that created/loaded the JVM.
2415
Aix::_main_thread = pthread_self();
2416
2417
initial_time_count = javaTimeNanos();
2418
2419
os::Posix::init();
2420
}
2421
2422
// This is called _after_ the global arguments have been parsed.
2423
jint os::init_2(void) {
2424
2425
// This could be set after os::Posix::init() but all platforms
2426
// have to set it the same so we have to mirror Solaris.
2427
DEBUG_ONLY(os::set_mutex_init_done();)
2428
2429
os::Posix::init_2();
2430
2431
if (os::Aix::on_pase()) {
2432
trcVerbose("Running on PASE.");
2433
} else {
2434
trcVerbose("Running on AIX (not PASE).");
2435
}
2436
2437
trcVerbose("processor count: %d", os::_processor_count);
2438
trcVerbose("physical memory: %lu", Aix::_physical_memory);
2439
2440
// Initially build up the loaded dll map.
2441
LoadedLibraries::reload();
2442
if (Verbose) {
2443
trcVerbose("Loaded Libraries: ");
2444
LoadedLibraries::print(tty);
2445
}
2446
2447
if (PosixSignals::init() == JNI_ERR) {
2448
return JNI_ERR;
2449
}
2450
2451
// Check and sets minimum stack sizes against command line options
2452
if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
2453
return JNI_ERR;
2454
}
2455
2456
// Not supported.
2457
FLAG_SET_ERGO(UseNUMA, false);
2458
FLAG_SET_ERGO(UseNUMAInterleaving, false);
2459
2460
if (MaxFDLimit) {
2461
// Set the number of file descriptors to max. print out error
2462
// if getrlimit/setrlimit fails but continue regardless.
2463
struct rlimit nbr_files;
2464
int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
2465
if (status != 0) {
2466
log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
2467
} else {
2468
nbr_files.rlim_cur = nbr_files.rlim_max;
2469
status = setrlimit(RLIMIT_NOFILE, &nbr_files);
2470
if (status != 0) {
2471
log_info(os)("os::init_2 setrlimit failed: %s", os::strerror(errno));
2472
}
2473
}
2474
}
2475
2476
if (PerfAllowAtExitRegistration) {
2477
// Only register atexit functions if PerfAllowAtExitRegistration is set.
2478
// At exit functions can be delayed until process exit time, which
2479
// can be problematic for embedded VM situations. Embedded VMs should
2480
// call DestroyJavaVM() to assure that VM resources are released.
2481
2482
// Note: perfMemory_exit_helper atexit function may be removed in
2483
// the future if the appropriate cleanup code can be added to the
2484
// VM_Exit VMOperation's doit method.
2485
if (atexit(perfMemory_exit_helper) != 0) {
2486
warning("os::init_2 atexit(perfMemory_exit_helper) failed");
2487
}
2488
}
2489
2490
// initialize thread priority policy
2491
prio_init();
2492
2493
return JNI_OK;
2494
}
2495
2496
int os::active_processor_count() {
2497
// User has overridden the number of active processors
2498
if (ActiveProcessorCount > 0) {
2499
log_trace(os)("active_processor_count: "
2500
"active processor count set by user : %d",
2501
ActiveProcessorCount);
2502
return ActiveProcessorCount;
2503
}
2504
2505
int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
2506
assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check");
2507
return online_cpus;
2508
}
2509
2510
void os::set_native_thread_name(const char *name) {
2511
// Not yet implemented.
2512
return;
2513
}
2514
2515
bool os::bind_to_processor(uint processor_id) {
2516
// Not yet implemented.
2517
return false;
2518
}
2519
2520
////////////////////////////////////////////////////////////////////////////////
2521
// debug support
2522
2523
bool os::find(address addr, outputStream* st) {
2524
2525
st->print(PTR_FORMAT ": ", addr);
2526
2527
loaded_module_t lm;
2528
if (LoadedLibraries::find_for_text_address(addr, &lm) != NULL ||
2529
LoadedLibraries::find_for_data_address(addr, &lm) != NULL) {
2530
st->print_cr("%s", lm.path);
2531
return true;
2532
}
2533
2534
return false;
2535
}
2536
2537
////////////////////////////////////////////////////////////////////////////////
2538
// misc
2539
2540
// This does not do anything on Aix. This is basically a hook for being
2541
// able to use structured exception handling (thread-local exception filters)
2542
// on, e.g., Win32.
2543
void
2544
os::os_exception_wrapper(java_call_t f, JavaValue* value, const methodHandle& method,
2545
JavaCallArguments* args, JavaThread* thread) {
2546
f(value, method, args, thread);
2547
}
2548
2549
void os::print_statistics() {
2550
}
2551
2552
bool os::message_box(const char* title, const char* message) {
2553
int i;
2554
fdStream err(defaultStream::error_fd());
2555
for (i = 0; i < 78; i++) err.print_raw("=");
2556
err.cr();
2557
err.print_raw_cr(title);
2558
for (i = 0; i < 78; i++) err.print_raw("-");
2559
err.cr();
2560
err.print_raw_cr(message);
2561
for (i = 0; i < 78; i++) err.print_raw("=");
2562
err.cr();
2563
2564
char buf[16];
2565
// Prevent process from exiting upon "read error" without consuming all CPU
2566
while (::read(0, buf, sizeof(buf)) <= 0) { ::sleep(100); }
2567
2568
return buf[0] == 'y' || buf[0] == 'Y';
2569
}
2570
2571
// Is a (classpath) directory empty?
2572
bool os::dir_is_empty(const char* path) {
2573
DIR *dir = NULL;
2574
struct dirent *ptr;
2575
2576
dir = opendir(path);
2577
if (dir == NULL) return true;
2578
2579
/* Scan the directory */
2580
bool result = true;
2581
while (result && (ptr = readdir(dir)) != NULL) {
2582
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) {
2583
result = false;
2584
}
2585
}
2586
closedir(dir);
2587
return result;
2588
}
2589
2590
// This code originates from JDK's sysOpen and open64_w
2591
// from src/solaris/hpi/src/system_md.c
2592
2593
int os::open(const char *path, int oflag, int mode) {
2594
2595
if (strlen(path) > MAX_PATH - 1) {
2596
errno = ENAMETOOLONG;
2597
return -1;
2598
}
2599
// AIX 7.X now supports O_CLOEXEC too, like modern Linux; but we have to be careful, see
2600
// IV90804: OPENING A FILE IN AFS WITH O_CLOEXEC FAILS WITH AN EINVAL ERROR APPLIES TO AIX 7100-04 17/04/14 PTF PECHANGE
2601
int oflag_with_o_cloexec = oflag | O_CLOEXEC;
2602
2603
int fd = ::open64(path, oflag_with_o_cloexec, mode);
2604
if (fd == -1) {
2605
// we might fail in the open call when O_CLOEXEC is set, so try again without (see IV90804)
2606
fd = ::open64(path, oflag, mode);
2607
if (fd == -1) {
2608
return -1;
2609
}
2610
}
2611
2612
// If the open succeeded, the file might still be a directory.
2613
{
2614
struct stat64 buf64;
2615
int ret = ::fstat64(fd, &buf64);
2616
int st_mode = buf64.st_mode;
2617
2618
if (ret != -1) {
2619
if ((st_mode & S_IFMT) == S_IFDIR) {
2620
errno = EISDIR;
2621
::close(fd);
2622
return -1;
2623
}
2624
} else {
2625
::close(fd);
2626
return -1;
2627
}
2628
}
2629
2630
// All file descriptors that are opened in the JVM and not
2631
// specifically destined for a subprocess should have the
2632
// close-on-exec flag set. If we don't set it, then careless 3rd
2633
// party native code might fork and exec without closing all
2634
// appropriate file descriptors (e.g. as we do in closeDescriptors in
2635
// UNIXProcess.c), and this in turn might:
2636
//
2637
// - cause end-of-file to fail to be detected on some file
2638
// descriptors, resulting in mysterious hangs, or
2639
//
2640
// - might cause an fopen in the subprocess to fail on a system
2641
// suffering from bug 1085341.
2642
2643
// Validate that the use of the O_CLOEXEC flag on open above worked.
2644
static sig_atomic_t O_CLOEXEC_is_known_to_work = 0;
2645
if (O_CLOEXEC_is_known_to_work == 0) {
2646
int flags = ::fcntl(fd, F_GETFD);
2647
if (flags != -1) {
2648
if ((flags & FD_CLOEXEC) != 0) {
2649
O_CLOEXEC_is_known_to_work = 1;
2650
} else { // it does not work
2651
::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
2652
O_CLOEXEC_is_known_to_work = -1;
2653
}
2654
}
2655
} else if (O_CLOEXEC_is_known_to_work == -1) {
2656
int flags = ::fcntl(fd, F_GETFD);
2657
if (flags != -1) {
2658
::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
2659
}
2660
}
2661
2662
return fd;
2663
}
2664
2665
// create binary file, rewriting existing file if required
2666
int os::create_binary_file(const char* path, bool rewrite_existing) {
2667
int oflags = O_WRONLY | O_CREAT;
2668
if (!rewrite_existing) {
2669
oflags |= O_EXCL;
2670
}
2671
return ::open64(path, oflags, S_IREAD | S_IWRITE);
2672
}
2673
2674
// return current position of file pointer
2675
jlong os::current_file_offset(int fd) {
2676
return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR);
2677
}
2678
2679
// move file pointer to the specified offset
2680
jlong os::seek_to_file_offset(int fd, jlong offset) {
2681
return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET);
2682
}
2683
2684
// This code originates from JDK's sysAvailable
2685
// from src/solaris/hpi/src/native_threads/src/sys_api_td.c
2686
2687
int os::available(int fd, jlong *bytes) {
2688
jlong cur, end;
2689
int mode;
2690
struct stat64 buf64;
2691
2692
if (::fstat64(fd, &buf64) >= 0) {
2693
mode = buf64.st_mode;
2694
if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
2695
int n;
2696
if (::ioctl(fd, FIONREAD, &n) >= 0) {
2697
*bytes = n;
2698
return 1;
2699
}
2700
}
2701
}
2702
if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) {
2703
return 0;
2704
} else if ((end = ::lseek64(fd, 0L, SEEK_END)) == -1) {
2705
return 0;
2706
} else if (::lseek64(fd, cur, SEEK_SET) == -1) {
2707
return 0;
2708
}
2709
*bytes = end - cur;
2710
return 1;
2711
}
2712
2713
// Map a block of memory.
2714
char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
2715
char *addr, size_t bytes, bool read_only,
2716
bool allow_exec) {
2717
int prot;
2718
int flags = MAP_PRIVATE;
2719
2720
if (read_only) {
2721
prot = PROT_READ;
2722
flags = MAP_SHARED;
2723
} else {
2724
prot = PROT_READ | PROT_WRITE;
2725
flags = MAP_PRIVATE;
2726
}
2727
2728
if (allow_exec) {
2729
prot |= PROT_EXEC;
2730
}
2731
2732
if (addr != NULL) {
2733
flags |= MAP_FIXED;
2734
}
2735
2736
// Allow anonymous mappings if 'fd' is -1.
2737
if (fd == -1) {
2738
flags |= MAP_ANONYMOUS;
2739
}
2740
2741
char* mapped_address = (char*)::mmap(addr, (size_t)bytes, prot, flags,
2742
fd, file_offset);
2743
if (mapped_address == MAP_FAILED) {
2744
return NULL;
2745
}
2746
return mapped_address;
2747
}
2748
2749
// Remap a block of memory.
2750
char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset,
2751
char *addr, size_t bytes, bool read_only,
2752
bool allow_exec) {
2753
// same as map_memory() on this OS
2754
return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only,
2755
allow_exec);
2756
}
2757
2758
// Unmap a block of memory.
2759
bool os::pd_unmap_memory(char* addr, size_t bytes) {
2760
return munmap(addr, bytes) == 0;
2761
}
2762
2763
// current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool)
2764
// are used by JVM M&M and JVMTI to get user+sys or user CPU time
2765
// of a thread.
2766
//
2767
// current_thread_cpu_time() and thread_cpu_time(Thread*) returns
2768
// the fast estimate available on the platform.
2769
2770
jlong os::current_thread_cpu_time() {
2771
// return user + sys since the cost is the same
2772
const jlong n = os::thread_cpu_time(Thread::current(), true /* user + sys */);
2773
assert(n >= 0, "negative CPU time");
2774
return n;
2775
}
2776
2777
jlong os::thread_cpu_time(Thread* thread) {
2778
// consistent with what current_thread_cpu_time() returns
2779
const jlong n = os::thread_cpu_time(thread, true /* user + sys */);
2780
assert(n >= 0, "negative CPU time");
2781
return n;
2782
}
2783
2784
jlong os::current_thread_cpu_time(bool user_sys_cpu_time) {
2785
const jlong n = os::thread_cpu_time(Thread::current(), user_sys_cpu_time);
2786
assert(n >= 0, "negative CPU time");
2787
return n;
2788
}
2789
2790
static bool thread_cpu_time_unchecked(Thread* thread, jlong* p_sys_time, jlong* p_user_time) {
2791
bool error = false;
2792
2793
jlong sys_time = 0;
2794
jlong user_time = 0;
2795
2796
// Reimplemented using getthrds64().
2797
//
2798
// Works like this:
2799
// For the thread in question, get the kernel thread id. Then get the
2800
// kernel thread statistics using that id.
2801
//
2802
// This only works of course when no pthread scheduling is used,
2803
// i.e. there is a 1:1 relationship to kernel threads.
2804
// On AIX, see AIXTHREAD_SCOPE variable.
2805
2806
pthread_t pthtid = thread->osthread()->pthread_id();
2807
2808
// retrieve kernel thread id for the pthread:
2809
tid64_t tid = 0;
2810
struct __pthrdsinfo pinfo;
2811
// I just love those otherworldly IBM APIs which force me to hand down
2812
// dummy buffers for stuff I dont care for...
2813
char dummy[1];
2814
int dummy_size = sizeof(dummy);
2815
if (pthread_getthrds_np(&pthtid, PTHRDSINFO_QUERY_TID, &pinfo, sizeof(pinfo),
2816
dummy, &dummy_size) == 0) {
2817
tid = pinfo.__pi_tid;
2818
} else {
2819
tty->print_cr("pthread_getthrds_np failed.");
2820
error = true;
2821
}
2822
2823
// retrieve kernel timing info for that kernel thread
2824
if (!error) {
2825
struct thrdentry64 thrdentry;
2826
if (getthrds64(getpid(), &thrdentry, sizeof(thrdentry), &tid, 1) == 1) {
2827
sys_time = thrdentry.ti_ru.ru_stime.tv_sec * 1000000000LL + thrdentry.ti_ru.ru_stime.tv_usec * 1000LL;
2828
user_time = thrdentry.ti_ru.ru_utime.tv_sec * 1000000000LL + thrdentry.ti_ru.ru_utime.tv_usec * 1000LL;
2829
} else {
2830
tty->print_cr("pthread_getthrds_np failed.");
2831
error = true;
2832
}
2833
}
2834
2835
if (p_sys_time) {
2836
*p_sys_time = sys_time;
2837
}
2838
2839
if (p_user_time) {
2840
*p_user_time = user_time;
2841
}
2842
2843
if (error) {
2844
return false;
2845
}
2846
2847
return true;
2848
}
2849
2850
jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
2851
jlong sys_time;
2852
jlong user_time;
2853
2854
if (!thread_cpu_time_unchecked(thread, &sys_time, &user_time)) {
2855
return -1;
2856
}
2857
2858
return user_sys_cpu_time ? sys_time + user_time : user_time;
2859
}
2860
2861
void os::current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
2862
info_ptr->max_value = ALL_64_BITS; // will not wrap in less than 64 bits
2863
info_ptr->may_skip_backward = false; // elapsed time not wall time
2864
info_ptr->may_skip_forward = false; // elapsed time not wall time
2865
info_ptr->kind = JVMTI_TIMER_TOTAL_CPU; // user+system time is returned
2866
}
2867
2868
void os::thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
2869
info_ptr->max_value = ALL_64_BITS; // will not wrap in less than 64 bits
2870
info_ptr->may_skip_backward = false; // elapsed time not wall time
2871
info_ptr->may_skip_forward = false; // elapsed time not wall time
2872
info_ptr->kind = JVMTI_TIMER_TOTAL_CPU; // user+system time is returned
2873
}
2874
2875
bool os::is_thread_cpu_time_supported() {
2876
return true;
2877
}
2878
2879
// System loadavg support. Returns -1 if load average cannot be obtained.
2880
// For now just return the system wide load average (no processor sets).
2881
int os::loadavg(double values[], int nelem) {
2882
2883
guarantee(nelem >= 0 && nelem <= 3, "argument error");
2884
guarantee(values, "argument error");
2885
2886
if (os::Aix::on_pase()) {
2887
2888
// AS/400 PASE: use libo4 porting library
2889
double v[3] = { 0.0, 0.0, 0.0 };
2890
2891
if (libo4::get_load_avg(v, v + 1, v + 2)) {
2892
for (int i = 0; i < nelem; i ++) {
2893
values[i] = v[i];
2894
}
2895
return nelem;
2896
} else {
2897
return -1;
2898
}
2899
2900
} else {
2901
2902
// AIX: use libperfstat
2903
libperfstat::cpuinfo_t ci;
2904
if (libperfstat::get_cpuinfo(&ci)) {
2905
for (int i = 0; i < nelem; i++) {
2906
values[i] = ci.loadavg[i];
2907
}
2908
} else {
2909
return -1;
2910
}
2911
return nelem;
2912
}
2913
}
2914
2915
void os::pause() {
2916
char filename[MAX_PATH];
2917
if (PauseAtStartupFile && PauseAtStartupFile[0]) {
2918
jio_snprintf(filename, MAX_PATH, "%s", PauseAtStartupFile);
2919
} else {
2920
jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id());
2921
}
2922
2923
int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
2924
if (fd != -1) {
2925
struct stat buf;
2926
::close(fd);
2927
while (::stat(filename, &buf) == 0) {
2928
(void)::poll(NULL, 0, 100);
2929
}
2930
} else {
2931
trcVerbose("Could not open pause file '%s', continuing immediately.", filename);
2932
}
2933
}
2934
2935
bool os::is_primordial_thread(void) {
2936
if (pthread_self() == (pthread_t)1) {
2937
return true;
2938
} else {
2939
return false;
2940
}
2941
}
2942
2943
// OS recognitions (PASE/AIX, OS level) call this before calling any
2944
// one of Aix::on_pase(), Aix::os_version() static
2945
void os::Aix::initialize_os_info() {
2946
2947
assert(_on_pase == -1 && _os_version == 0, "already called.");
2948
2949
struct utsname uts;
2950
memset(&uts, 0, sizeof(uts));
2951
strcpy(uts.sysname, "?");
2952
if (::uname(&uts) == -1) {
2953
trcVerbose("uname failed (%d)", errno);
2954
guarantee(0, "Could not determine whether we run on AIX or PASE");
2955
} else {
2956
trcVerbose("uname says: sysname \"%s\" version \"%s\" release \"%s\" "
2957
"node \"%s\" machine \"%s\"\n",
2958
uts.sysname, uts.version, uts.release, uts.nodename, uts.machine);
2959
const int major = atoi(uts.version);
2960
assert(major > 0, "invalid OS version");
2961
const int minor = atoi(uts.release);
2962
assert(minor > 0, "invalid OS release");
2963
_os_version = (major << 24) | (minor << 16);
2964
char ver_str[20] = {0};
2965
const char* name_str = "unknown OS";
2966
if (strcmp(uts.sysname, "OS400") == 0) {
2967
// We run on AS/400 PASE. We do not support versions older than V5R4M0.
2968
_on_pase = 1;
2969
if (os_version_short() < 0x0504) {
2970
trcVerbose("OS/400 releases older than V5R4M0 not supported.");
2971
assert(false, "OS/400 release too old.");
2972
}
2973
name_str = "OS/400 (pase)";
2974
jio_snprintf(ver_str, sizeof(ver_str), "%u.%u", major, minor);
2975
} else if (strcmp(uts.sysname, "AIX") == 0) {
2976
// We run on AIX. We do not support versions older than AIX 7.1.
2977
_on_pase = 0;
2978
// Determine detailed AIX version: Version, Release, Modification, Fix Level.
2979
odmWrapper::determine_os_kernel_version(&_os_version);
2980
if (os_version_short() < 0x0701) {
2981
trcVerbose("AIX releases older than AIX 7.1 are not supported.");
2982
assert(false, "AIX release too old.");
2983
}
2984
name_str = "AIX";
2985
jio_snprintf(ver_str, sizeof(ver_str), "%u.%u.%u.%u",
2986
major, minor, (_os_version >> 8) & 0xFF, _os_version & 0xFF);
2987
} else {
2988
assert(false, "%s", name_str);
2989
}
2990
trcVerbose("We run on %s %s", name_str, ver_str);
2991
}
2992
2993
guarantee(_on_pase != -1 && _os_version, "Could not determine AIX/OS400 release");
2994
} // end: os::Aix::initialize_os_info()
2995
2996
// Scan environment for important settings which might effect the VM.
2997
// Trace out settings. Warn about invalid settings and/or correct them.
2998
//
2999
// Must run after os::Aix::initialue_os_info().
3000
void os::Aix::scan_environment() {
3001
3002
char* p;
3003
int rc;
3004
3005
// Warn explicity if EXTSHM=ON is used. That switch changes how
3006
// System V shared memory behaves. One effect is that page size of
3007
// shared memory cannot be change dynamically, effectivly preventing
3008
// large pages from working.
3009
// This switch was needed on AIX 32bit, but on AIX 64bit the general
3010
// recommendation is (in OSS notes) to switch it off.
3011
p = ::getenv("EXTSHM");
3012
trcVerbose("EXTSHM=%s.", p ? p : "<unset>");
3013
if (p && strcasecmp(p, "ON") == 0) {
3014
_extshm = 1;
3015
trcVerbose("*** Unsupported mode! Please remove EXTSHM from your environment! ***");
3016
if (!AllowExtshm) {
3017
// We allow under certain conditions the user to continue. However, we want this
3018
// to be a fatal error by default. On certain AIX systems, leaving EXTSHM=ON means
3019
// that the VM is not able to allocate 64k pages for the heap.
3020
// We do not want to run with reduced performance.
3021
vm_exit_during_initialization("EXTSHM is ON. Please remove EXTSHM from your environment.");
3022
}
3023
} else {
3024
_extshm = 0;
3025
}
3026
3027
// SPEC1170 behaviour: will change the behaviour of a number of POSIX APIs.
3028
// Not tested, not supported.
3029
//
3030
// Note that it might be worth the trouble to test and to require it, if only to
3031
// get useful return codes for mprotect.
3032
//
3033
// Note: Setting XPG_SUS_ENV in the process is too late. Must be set earlier (before
3034
// exec() ? before loading the libjvm ? ....)
3035
p = ::getenv("XPG_SUS_ENV");
3036
trcVerbose("XPG_SUS_ENV=%s.", p ? p : "<unset>");
3037
if (p && strcmp(p, "ON") == 0) {
3038
_xpg_sus_mode = 1;
3039
trcVerbose("Unsupported setting: XPG_SUS_ENV=ON");
3040
// This is not supported. Worst of all, it changes behaviour of mmap MAP_FIXED to
3041
// clobber address ranges. If we ever want to support that, we have to do some
3042
// testing first.
3043
guarantee(false, "XPG_SUS_ENV=ON not supported");
3044
} else {
3045
_xpg_sus_mode = 0;
3046
}
3047
3048
if (os::Aix::on_pase()) {
3049
p = ::getenv("QIBM_MULTI_THREADED");
3050
trcVerbose("QIBM_MULTI_THREADED=%s.", p ? p : "<unset>");
3051
}
3052
3053
p = ::getenv("LDR_CNTRL");
3054
trcVerbose("LDR_CNTRL=%s.", p ? p : "<unset>");
3055
if (os::Aix::on_pase() && os::Aix::os_version_short() == 0x0701) {
3056
if (p && ::strstr(p, "TEXTPSIZE")) {
3057
trcVerbose("*** WARNING - LDR_CNTRL contains TEXTPSIZE. "
3058
"you may experience hangs or crashes on OS/400 V7R1.");
3059
}
3060
}
3061
3062
p = ::getenv("AIXTHREAD_GUARDPAGES");
3063
trcVerbose("AIXTHREAD_GUARDPAGES=%s.", p ? p : "<unset>");
3064
3065
} // end: os::Aix::scan_environment()
3066
3067
// PASE: initialize the libo4 library (PASE porting library).
3068
void os::Aix::initialize_libo4() {
3069
guarantee(os::Aix::on_pase(), "OS/400 only.");
3070
if (!libo4::init()) {
3071
trcVerbose("libo4 initialization failed.");
3072
assert(false, "libo4 initialization failed");
3073
} else {
3074
trcVerbose("libo4 initialized.");
3075
}
3076
}
3077
3078
// AIX: initialize the libperfstat library.
3079
void os::Aix::initialize_libperfstat() {
3080
assert(os::Aix::on_aix(), "AIX only");
3081
if (!libperfstat::init()) {
3082
trcVerbose("libperfstat initialization failed.");
3083
assert(false, "libperfstat initialization failed");
3084
} else {
3085
trcVerbose("libperfstat initialized.");
3086
}
3087
}
3088
3089
/////////////////////////////////////////////////////////////////////////////
3090
// thread stack
3091
3092
// Get the current stack base from the OS (actually, the pthread library).
3093
// Note: usually not page aligned.
3094
address os::current_stack_base() {
3095
AixMisc::stackbounds_t bounds;
3096
bool rc = AixMisc::query_stack_bounds_for_current_thread(&bounds);
3097
guarantee(rc, "Unable to retrieve stack bounds.");
3098
return bounds.base;
3099
}
3100
3101
// Get the current stack size from the OS (actually, the pthread library).
3102
// Returned size is such that (base - size) is always aligned to page size.
3103
size_t os::current_stack_size() {
3104
AixMisc::stackbounds_t bounds;
3105
bool rc = AixMisc::query_stack_bounds_for_current_thread(&bounds);
3106
guarantee(rc, "Unable to retrieve stack bounds.");
3107
// Align the returned stack size such that the stack low address
3108
// is aligned to page size (Note: base is usually not and we do not care).
3109
// We need to do this because caller code will assume stack low address is
3110
// page aligned and will place guard pages without checking.
3111
address low = bounds.base - bounds.size;
3112
address low_aligned = (address)align_up(low, os::vm_page_size());
3113
size_t s = bounds.base - low_aligned;
3114
return s;
3115
}
3116
3117
// Get the default path to the core file
3118
// Returns the length of the string
3119
int os::get_core_path(char* buffer, size_t bufferSize) {
3120
const char* p = get_current_directory(buffer, bufferSize);
3121
3122
if (p == NULL) {
3123
assert(p != NULL, "failed to get current directory");
3124
return 0;
3125
}
3126
3127
jio_snprintf(buffer, bufferSize, "%s/core or core.%d",
3128
p, current_process_id());
3129
3130
return strlen(buffer);
3131
}
3132
3133
bool os::start_debugging(char *buf, int buflen) {
3134
int len = (int)strlen(buf);
3135
char *p = &buf[len];
3136
3137
jio_snprintf(p, buflen -len,
3138
"\n\n"
3139
"Do you want to debug the problem?\n\n"
3140
"To debug, run 'dbx -a %d'; then switch to thread tid " INTX_FORMAT ", k-tid " INTX_FORMAT "\n"
3141
"Enter 'yes' to launch dbx automatically (PATH must include dbx)\n"
3142
"Otherwise, press RETURN to abort...",
3143
os::current_process_id(),
3144
os::current_thread_id(), thread_self());
3145
3146
bool yes = os::message_box("Unexpected Error", buf);
3147
3148
if (yes) {
3149
// yes, user asked VM to launch debugger
3150
jio_snprintf(buf, buflen, "dbx -a %d", os::current_process_id());
3151
3152
os::fork_and_exec(buf);
3153
yes = false;
3154
}
3155
return yes;
3156
}
3157
3158
static inline time_t get_mtime(const char* filename) {
3159
struct stat st;
3160
int ret = os::stat(filename, &st);
3161
assert(ret == 0, "failed to stat() file '%s': %s", filename, os::strerror(errno));
3162
return st.st_mtime;
3163
}
3164
3165
int os::compare_file_modified_times(const char* file1, const char* file2) {
3166
time_t t1 = get_mtime(file1);
3167
time_t t2 = get_mtime(file2);
3168
return t1 - t2;
3169
}
3170
3171
bool os::supports_map_sync() {
3172
return false;
3173
}
3174
3175
void os::print_memory_mappings(char* addr, size_t bytes, outputStream* st) {}
3176
3177