Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/hotspot/os/aix/os_aix.cpp
64441 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
ResourceMark rm;
818
pthread_t tid = 0;
819
820
if (ret == 0) {
821
int limit = 3;
822
do {
823
ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
824
} while (ret == EAGAIN && limit-- > 0);
825
}
826
827
if (ret == 0) {
828
char buf[64];
829
log_info(os, thread)("Thread \"%s\" started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
830
thread->name(), (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
831
} else {
832
char buf[64];
833
log_warning(os, thread)("Failed to start thread \"%s\" - pthread_create failed (%d=%s) for attributes: %s.",
834
thread->name(), ret, os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
835
// Log some OS information which might explain why creating the thread failed.
836
log_info(os, thread)("Number of threads approx. running in the VM: %d", Threads::number_of_threads());
837
LogStream st(Log(os, thread)::info());
838
os::Posix::print_rlimit_info(&st);
839
os::print_memory_info(&st);
840
}
841
842
pthread_attr_destroy(&attr);
843
844
if (ret != 0) {
845
// Need to clean up stuff we've allocated so far.
846
thread->set_osthread(NULL);
847
delete osthread;
848
return false;
849
}
850
851
// OSThread::thread_id is the pthread id.
852
osthread->set_thread_id(tid);
853
854
return true;
855
}
856
857
/////////////////////////////////////////////////////////////////////////////
858
// attach existing thread
859
860
// bootstrap the main thread
861
bool os::create_main_thread(JavaThread* thread) {
862
assert(os::Aix::_main_thread == pthread_self(), "should be called inside main thread");
863
return create_attached_thread(thread);
864
}
865
866
bool os::create_attached_thread(JavaThread* thread) {
867
#ifdef ASSERT
868
thread->verify_not_published();
869
#endif
870
871
// Allocate the OSThread object
872
OSThread* osthread = new OSThread(NULL, NULL);
873
874
if (osthread == NULL) {
875
return false;
876
}
877
878
const pthread_t pthread_id = ::pthread_self();
879
const tid_t kernel_thread_id = ::thread_self();
880
881
// OSThread::thread_id is the pthread id.
882
osthread->set_thread_id(pthread_id);
883
884
// .. but keep kernel thread id too for diagnostics
885
osthread->set_kernel_thread_id(kernel_thread_id);
886
887
// initialize floating point control register
888
os::Aix::init_thread_fpu_state();
889
890
// Initial thread state is RUNNABLE
891
osthread->set_state(RUNNABLE);
892
893
thread->set_osthread(osthread);
894
895
if (UseNUMA) {
896
int lgrp_id = os::numa_get_group_id();
897
if (lgrp_id != -1) {
898
thread->set_lgrp_id(lgrp_id);
899
}
900
}
901
902
// initialize signal mask for this thread
903
// and save the caller's signal mask
904
PosixSignals::hotspot_sigmask(thread);
905
906
log_info(os, thread)("Thread attached (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
907
os::current_thread_id(), (uintx) kernel_thread_id);
908
909
return true;
910
}
911
912
void os::pd_start_thread(Thread* thread) {
913
int status = pthread_continue_np(thread->osthread()->pthread_id());
914
assert(status == 0, "thr_continue failed");
915
}
916
917
// Free OS resources related to the OSThread
918
void os::free_thread(OSThread* osthread) {
919
assert(osthread != NULL, "osthread not set");
920
921
// We are told to free resources of the argument thread,
922
// but we can only really operate on the current thread.
923
assert(Thread::current()->osthread() == osthread,
924
"os::free_thread but not current thread");
925
926
// Restore caller's signal mask
927
sigset_t sigmask = osthread->caller_sigmask();
928
pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
929
930
delete osthread;
931
}
932
933
////////////////////////////////////////////////////////////////////////////////
934
// time support
935
936
// Time since start-up in seconds to a fine granularity.
937
double os::elapsedTime() {
938
return ((double)os::elapsed_counter()) / os::elapsed_frequency(); // nanosecond resolution
939
}
940
941
jlong os::elapsed_counter() {
942
return javaTimeNanos() - initial_time_count;
943
}
944
945
jlong os::elapsed_frequency() {
946
return NANOSECS_PER_SEC; // nanosecond resolution
947
}
948
949
bool os::supports_vtime() { return true; }
950
951
double os::elapsedVTime() {
952
struct rusage usage;
953
int retval = getrusage(RUSAGE_THREAD, &usage);
954
if (retval == 0) {
955
return usage.ru_utime.tv_sec + usage.ru_stime.tv_sec + (usage.ru_utime.tv_usec + usage.ru_stime.tv_usec) / (1000.0 * 1000);
956
} else {
957
// better than nothing, but not much
958
return elapsedTime();
959
}
960
}
961
962
// We use mread_real_time here.
963
// On AIX: If the CPU has a time register, the result will be RTC_POWER and
964
// it has to be converted to real time. AIX documentations suggests to do
965
// this unconditionally, so we do it.
966
//
967
// See: https://www.ibm.com/support/knowledgecenter/ssw_aix_61/com.ibm.aix.basetrf2/read_real_time.htm
968
//
969
// On PASE: mread_real_time will always return RTC_POWER_PC data, so no
970
// conversion is necessary. However, mread_real_time will not return
971
// monotonic results but merely matches read_real_time. So we need a tweak
972
// to ensure monotonic results.
973
//
974
// For PASE no public documentation exists, just word by IBM
975
jlong os::javaTimeNanos() {
976
timebasestruct_t time;
977
int rc = mread_real_time(&time, TIMEBASE_SZ);
978
if (os::Aix::on_pase()) {
979
assert(rc == RTC_POWER, "expected time format RTC_POWER from mread_real_time in PASE");
980
jlong now = jlong(time.tb_high) * NANOSECS_PER_SEC + jlong(time.tb_low);
981
jlong prev = max_real_time;
982
if (now <= prev) {
983
return prev; // same or retrograde time;
984
}
985
jlong obsv = Atomic::cmpxchg(&max_real_time, prev, now);
986
assert(obsv >= prev, "invariant"); // Monotonicity
987
// If the CAS succeeded then we're done and return "now".
988
// If the CAS failed and the observed value "obsv" is >= now then
989
// we should return "obsv". If the CAS failed and now > obsv > prv then
990
// some other thread raced this thread and installed a new value, in which case
991
// we could either (a) retry the entire operation, (b) retry trying to install now
992
// or (c) just return obsv. We use (c). No loop is required although in some cases
993
// we might discard a higher "now" value in deference to a slightly lower but freshly
994
// installed obsv value. That's entirely benign -- it admits no new orderings compared
995
// to (a) or (b) -- and greatly reduces coherence traffic.
996
// We might also condition (c) on the magnitude of the delta between obsv and now.
997
// Avoiding excessive CAS operations to hot RW locations is critical.
998
// See https://blogs.oracle.com/dave/entry/cas_and_cache_trivia_invalidate
999
return (prev == obsv) ? now : obsv;
1000
} else {
1001
if (rc != RTC_POWER) {
1002
rc = time_base_to_time(&time, TIMEBASE_SZ);
1003
assert(rc != -1, "error calling time_base_to_time()");
1004
}
1005
return jlong(time.tb_high) * NANOSECS_PER_SEC + jlong(time.tb_low);
1006
}
1007
}
1008
1009
void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
1010
info_ptr->max_value = ALL_64_BITS;
1011
// mread_real_time() is monotonic (see 'os::javaTimeNanos()')
1012
info_ptr->may_skip_backward = false;
1013
info_ptr->may_skip_forward = false;
1014
info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time
1015
}
1016
1017
// Return the real, user, and system times in seconds from an
1018
// arbitrary fixed point in the past.
1019
bool os::getTimesSecs(double* process_real_time,
1020
double* process_user_time,
1021
double* process_system_time) {
1022
struct tms ticks;
1023
clock_t real_ticks = times(&ticks);
1024
1025
if (real_ticks == (clock_t) (-1)) {
1026
return false;
1027
} else {
1028
double ticks_per_second = (double) clock_tics_per_sec;
1029
*process_user_time = ((double) ticks.tms_utime) / ticks_per_second;
1030
*process_system_time = ((double) ticks.tms_stime) / ticks_per_second;
1031
*process_real_time = ((double) real_ticks) / ticks_per_second;
1032
1033
return true;
1034
}
1035
}
1036
1037
char * os::local_time_string(char *buf, size_t buflen) {
1038
struct tm t;
1039
time_t long_time;
1040
time(&long_time);
1041
localtime_r(&long_time, &t);
1042
jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d",
1043
t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
1044
t.tm_hour, t.tm_min, t.tm_sec);
1045
return buf;
1046
}
1047
1048
struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
1049
return localtime_r(clock, res);
1050
}
1051
1052
intx os::current_thread_id() {
1053
return (intx)pthread_self();
1054
}
1055
1056
int os::current_process_id() {
1057
return getpid();
1058
}
1059
1060
// DLL functions
1061
1062
const char* os::dll_file_extension() { return ".so"; }
1063
1064
// This must be hard coded because it's the system's temporary
1065
// directory not the java application's temp directory, ala java.io.tmpdir.
1066
const char* os::get_temp_directory() { return "/tmp"; }
1067
1068
// Check if addr is inside libjvm.so.
1069
bool os::address_is_in_vm(address addr) {
1070
1071
// Input could be a real pc or a function pointer literal. The latter
1072
// would be a function descriptor residing in the data segment of a module.
1073
loaded_module_t lm;
1074
if (LoadedLibraries::find_for_text_address(addr, &lm) != NULL) {
1075
return lm.is_in_vm;
1076
} else if (LoadedLibraries::find_for_data_address(addr, &lm) != NULL) {
1077
return lm.is_in_vm;
1078
} else {
1079
return false;
1080
}
1081
1082
}
1083
1084
// Resolve an AIX function descriptor literal to a code pointer.
1085
// If the input is a valid code pointer to a text segment of a loaded module,
1086
// it is returned unchanged.
1087
// If the input is a valid AIX function descriptor, it is resolved to the
1088
// code entry point.
1089
// If the input is neither a valid function descriptor nor a valid code pointer,
1090
// NULL is returned.
1091
static address resolve_function_descriptor_to_code_pointer(address p) {
1092
1093
if (LoadedLibraries::find_for_text_address(p, NULL) != NULL) {
1094
// It is a real code pointer.
1095
return p;
1096
} else if (LoadedLibraries::find_for_data_address(p, NULL) != NULL) {
1097
// Pointer to data segment, potential function descriptor.
1098
address code_entry = (address)(((FunctionDescriptor*)p)->entry());
1099
if (LoadedLibraries::find_for_text_address(code_entry, NULL) != NULL) {
1100
// It is a function descriptor.
1101
return code_entry;
1102
}
1103
}
1104
1105
return NULL;
1106
}
1107
1108
bool os::dll_address_to_function_name(address addr, char *buf,
1109
int buflen, int *offset,
1110
bool demangle) {
1111
if (offset) {
1112
*offset = -1;
1113
}
1114
// Buf is not optional, but offset is optional.
1115
assert(buf != NULL, "sanity check");
1116
buf[0] = '\0';
1117
1118
// Resolve function ptr literals first.
1119
addr = resolve_function_descriptor_to_code_pointer(addr);
1120
if (!addr) {
1121
return false;
1122
}
1123
1124
return AixSymbols::get_function_name(addr, buf, buflen, offset, NULL, demangle);
1125
}
1126
1127
bool os::dll_address_to_library_name(address addr, char* buf,
1128
int buflen, int* offset) {
1129
if (offset) {
1130
*offset = -1;
1131
}
1132
// Buf is not optional, but offset is optional.
1133
assert(buf != NULL, "sanity check");
1134
buf[0] = '\0';
1135
1136
// Resolve function ptr literals first.
1137
addr = resolve_function_descriptor_to_code_pointer(addr);
1138
if (!addr) {
1139
return false;
1140
}
1141
1142
return AixSymbols::get_module_name(addr, buf, buflen);
1143
}
1144
1145
// Loads .dll/.so and in case of error it checks if .dll/.so was built
1146
// for the same architecture as Hotspot is running on.
1147
void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
1148
1149
log_info(os)("attempting shared library load of %s", filename);
1150
1151
if (ebuf && ebuflen > 0) {
1152
ebuf[0] = '\0';
1153
ebuf[ebuflen - 1] = '\0';
1154
}
1155
1156
if (!filename || strlen(filename) == 0) {
1157
::strncpy(ebuf, "dll_load: empty filename specified", ebuflen - 1);
1158
return NULL;
1159
}
1160
1161
// RTLD_LAZY is currently not implemented. The dl is loaded immediately with all its dependants.
1162
void * result= ::dlopen(filename, RTLD_LAZY);
1163
if (result != NULL) {
1164
Events::log_dll_message(NULL, "Loaded shared library %s", filename);
1165
// Reload dll cache. Don't do this in signal handling.
1166
LoadedLibraries::reload();
1167
log_info(os)("shared library load of %s was successful", filename);
1168
return result;
1169
} else {
1170
// error analysis when dlopen fails
1171
const char* error_report = ::dlerror();
1172
if (error_report == NULL) {
1173
error_report = "dlerror returned no error description";
1174
}
1175
if (ebuf != NULL && ebuflen > 0) {
1176
snprintf(ebuf, ebuflen - 1, "%s, LIBPATH=%s, LD_LIBRARY_PATH=%s : %s",
1177
filename, ::getenv("LIBPATH"), ::getenv("LD_LIBRARY_PATH"), error_report);
1178
}
1179
Events::log_dll_message(NULL, "Loading shared library %s failed, %s", filename, error_report);
1180
log_info(os)("shared library load of %s failed, %s", filename, error_report);
1181
}
1182
return NULL;
1183
}
1184
1185
void os::print_dll_info(outputStream *st) {
1186
st->print_cr("Dynamic libraries:");
1187
LoadedLibraries::print(st);
1188
}
1189
1190
void os::get_summary_os_info(char* buf, size_t buflen) {
1191
// There might be something more readable than uname results for AIX.
1192
struct utsname name;
1193
uname(&name);
1194
snprintf(buf, buflen, "%s %s", name.release, name.version);
1195
}
1196
1197
int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) {
1198
// Not yet implemented.
1199
return 0;
1200
}
1201
1202
void os::print_os_info_brief(outputStream* st) {
1203
uint32_t ver = os::Aix::os_version();
1204
st->print_cr("AIX kernel version %u.%u.%u.%u",
1205
(ver >> 24) & 0xFF, (ver >> 16) & 0xFF, (ver >> 8) & 0xFF, ver & 0xFF);
1206
1207
os::Posix::print_uname_info(st);
1208
1209
// Linux uses print_libversion_info(st); here.
1210
}
1211
1212
void os::print_os_info(outputStream* st) {
1213
st->print_cr("OS:");
1214
1215
os::Posix::print_uname_info(st);
1216
1217
uint32_t ver = os::Aix::os_version();
1218
st->print_cr("AIX kernel version %u.%u.%u.%u",
1219
(ver >> 24) & 0xFF, (ver >> 16) & 0xFF, (ver >> 8) & 0xFF, ver & 0xFF);
1220
1221
os::Posix::print_uptime_info(st);
1222
1223
os::Posix::print_rlimit_info(st);
1224
1225
os::Posix::print_load_average(st);
1226
1227
// _SC_THREAD_THREADS_MAX is the maximum number of threads within a process.
1228
long tmax = sysconf(_SC_THREAD_THREADS_MAX);
1229
st->print_cr("maximum #threads within a process:%ld", tmax);
1230
1231
// print wpar info
1232
libperfstat::wparinfo_t wi;
1233
if (libperfstat::get_wparinfo(&wi)) {
1234
st->print_cr("wpar info");
1235
st->print_cr("name: %s", wi.name);
1236
st->print_cr("id: %d", wi.wpar_id);
1237
st->print_cr("type: %s", (wi.app_wpar ? "application" : "system"));
1238
}
1239
1240
VM_Version::print_platform_virtualization_info(st);
1241
}
1242
1243
void os::print_memory_info(outputStream* st) {
1244
1245
st->print_cr("Memory:");
1246
1247
st->print_cr(" Base page size (sysconf _SC_PAGESIZE): %s",
1248
describe_pagesize(g_multipage_support.pagesize));
1249
st->print_cr(" Data page size (C-Heap, bss, etc): %s",
1250
describe_pagesize(g_multipage_support.datapsize));
1251
st->print_cr(" Text page size: %s",
1252
describe_pagesize(g_multipage_support.textpsize));
1253
st->print_cr(" Thread stack page size (pthread): %s",
1254
describe_pagesize(g_multipage_support.pthr_stack_pagesize));
1255
st->print_cr(" Default shared memory page size: %s",
1256
describe_pagesize(g_multipage_support.shmpsize));
1257
st->print_cr(" Can use 64K pages dynamically with shared memory: %s",
1258
(g_multipage_support.can_use_64K_pages ? "yes" :"no"));
1259
st->print_cr(" Can use 16M pages dynamically with shared memory: %s",
1260
(g_multipage_support.can_use_16M_pages ? "yes" :"no"));
1261
st->print_cr(" Multipage error: %d",
1262
g_multipage_support.error);
1263
st->cr();
1264
st->print_cr(" os::vm_page_size: %s", describe_pagesize(os::vm_page_size()));
1265
1266
// print out LDR_CNTRL because it affects the default page sizes
1267
const char* const ldr_cntrl = ::getenv("LDR_CNTRL");
1268
st->print_cr(" LDR_CNTRL=%s.", ldr_cntrl ? ldr_cntrl : "<unset>");
1269
1270
// Print out EXTSHM because it is an unsupported setting.
1271
const char* const extshm = ::getenv("EXTSHM");
1272
st->print_cr(" EXTSHM=%s.", extshm ? extshm : "<unset>");
1273
if ( (strcmp(extshm, "on") == 0) || (strcmp(extshm, "ON") == 0) ) {
1274
st->print_cr(" *** Unsupported! Please remove EXTSHM from your environment! ***");
1275
}
1276
1277
// Print out AIXTHREAD_GUARDPAGES because it affects the size of pthread stacks.
1278
const char* const aixthread_guardpages = ::getenv("AIXTHREAD_GUARDPAGES");
1279
st->print_cr(" AIXTHREAD_GUARDPAGES=%s.",
1280
aixthread_guardpages ? aixthread_guardpages : "<unset>");
1281
st->cr();
1282
1283
os::Aix::meminfo_t mi;
1284
if (os::Aix::get_meminfo(&mi)) {
1285
if (os::Aix::on_aix()) {
1286
st->print_cr("physical total : " SIZE_FORMAT, mi.real_total);
1287
st->print_cr("physical free : " SIZE_FORMAT, mi.real_free);
1288
st->print_cr("swap total : " SIZE_FORMAT, mi.pgsp_total);
1289
st->print_cr("swap free : " SIZE_FORMAT, mi.pgsp_free);
1290
} else {
1291
// PASE - Numbers are result of QWCRSSTS; they mean:
1292
// real_total: Sum of all system pools
1293
// real_free: always 0
1294
// pgsp_total: we take the size of the system ASP
1295
// pgsp_free: size of system ASP times percentage of system ASP unused
1296
st->print_cr("physical total : " SIZE_FORMAT, mi.real_total);
1297
st->print_cr("system asp total : " SIZE_FORMAT, mi.pgsp_total);
1298
st->print_cr("%% system asp used : %.2f",
1299
mi.pgsp_total ? (100.0f * (mi.pgsp_total - mi.pgsp_free) / mi.pgsp_total) : -1.0f);
1300
}
1301
}
1302
st->cr();
1303
1304
// Print program break.
1305
st->print_cr("Program break at VM startup: " PTR_FORMAT ".", p2i(g_brk_at_startup));
1306
address brk_now = (address)::sbrk(0);
1307
if (brk_now != (address)-1) {
1308
st->print_cr("Program break now : " PTR_FORMAT " (distance: " SIZE_FORMAT "k).",
1309
p2i(brk_now), (size_t)((brk_now - g_brk_at_startup) / K));
1310
}
1311
st->print_cr("MaxExpectedDataSegmentSize : " SIZE_FORMAT "k.", MaxExpectedDataSegmentSize / K);
1312
st->cr();
1313
1314
// Print segments allocated with os::reserve_memory.
1315
st->print_cr("internal virtual memory regions used by vm:");
1316
vmembk_print_on(st);
1317
}
1318
1319
// Get a string for the cpuinfo that is a summary of the cpu type
1320
void os::get_summary_cpu_info(char* buf, size_t buflen) {
1321
// read _system_configuration.version
1322
switch (_system_configuration.version) {
1323
case PV_9:
1324
strncpy(buf, "Power PC 9", buflen);
1325
break;
1326
case PV_8:
1327
strncpy(buf, "Power PC 8", buflen);
1328
break;
1329
case PV_7:
1330
strncpy(buf, "Power PC 7", buflen);
1331
break;
1332
case PV_6_1:
1333
strncpy(buf, "Power PC 6 DD1.x", buflen);
1334
break;
1335
case PV_6:
1336
strncpy(buf, "Power PC 6", buflen);
1337
break;
1338
case PV_5:
1339
strncpy(buf, "Power PC 5", buflen);
1340
break;
1341
case PV_5_2:
1342
strncpy(buf, "Power PC 5_2", buflen);
1343
break;
1344
case PV_5_3:
1345
strncpy(buf, "Power PC 5_3", buflen);
1346
break;
1347
case PV_5_Compat:
1348
strncpy(buf, "PV_5_Compat", buflen);
1349
break;
1350
case PV_6_Compat:
1351
strncpy(buf, "PV_6_Compat", buflen);
1352
break;
1353
case PV_7_Compat:
1354
strncpy(buf, "PV_7_Compat", buflen);
1355
break;
1356
case PV_8_Compat:
1357
strncpy(buf, "PV_8_Compat", buflen);
1358
break;
1359
case PV_9_Compat:
1360
strncpy(buf, "PV_9_Compat", buflen);
1361
break;
1362
default:
1363
strncpy(buf, "unknown", buflen);
1364
}
1365
}
1366
1367
void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) {
1368
// Nothing to do beyond of what os::print_cpu_info() does.
1369
}
1370
1371
static char saved_jvm_path[MAXPATHLEN] = {0};
1372
1373
// Find the full path to the current module, libjvm.so.
1374
void os::jvm_path(char *buf, jint buflen) {
1375
// Error checking.
1376
if (buflen < MAXPATHLEN) {
1377
assert(false, "must use a large-enough buffer");
1378
buf[0] = '\0';
1379
return;
1380
}
1381
// Lazy resolve the path to current module.
1382
if (saved_jvm_path[0] != 0) {
1383
strcpy(buf, saved_jvm_path);
1384
return;
1385
}
1386
1387
Dl_info dlinfo;
1388
int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo);
1389
assert(ret != 0, "cannot locate libjvm");
1390
char* rp = os::Posix::realpath((char *)dlinfo.dli_fname, buf, buflen);
1391
assert(rp != NULL, "error in realpath(): maybe the 'path' argument is too long?");
1392
1393
if (Arguments::sun_java_launcher_is_altjvm()) {
1394
// Support for the java launcher's '-XXaltjvm=<path>' option. Typical
1395
// value for buf is "<JAVA_HOME>/jre/lib/<vmtype>/libjvm.so".
1396
// If "/jre/lib/" appears at the right place in the string, then
1397
// assume we are installed in a JDK and we're done. Otherwise, check
1398
// for a JAVA_HOME environment variable and fix up the path so it
1399
// looks like libjvm.so is installed there (append a fake suffix
1400
// hotspot/libjvm.so).
1401
const char *p = buf + strlen(buf) - 1;
1402
for (int count = 0; p > buf && count < 4; ++count) {
1403
for (--p; p > buf && *p != '/'; --p)
1404
/* empty */ ;
1405
}
1406
1407
if (strncmp(p, "/jre/lib/", 9) != 0) {
1408
// Look for JAVA_HOME in the environment.
1409
char* java_home_var = ::getenv("JAVA_HOME");
1410
if (java_home_var != NULL && java_home_var[0] != 0) {
1411
char* jrelib_p;
1412
int len;
1413
1414
// Check the current module name "libjvm.so".
1415
p = strrchr(buf, '/');
1416
if (p == NULL) {
1417
return;
1418
}
1419
assert(strstr(p, "/libjvm") == p, "invalid library name");
1420
1421
rp = os::Posix::realpath(java_home_var, buf, buflen);
1422
if (rp == NULL) {
1423
return;
1424
}
1425
1426
// determine if this is a legacy image or modules image
1427
// modules image doesn't have "jre" subdirectory
1428
len = strlen(buf);
1429
assert(len < buflen, "Ran out of buffer room");
1430
jrelib_p = buf + len;
1431
snprintf(jrelib_p, buflen-len, "/jre/lib");
1432
if (0 != access(buf, F_OK)) {
1433
snprintf(jrelib_p, buflen-len, "/lib");
1434
}
1435
1436
if (0 == access(buf, F_OK)) {
1437
// Use current module name "libjvm.so"
1438
len = strlen(buf);
1439
snprintf(buf + len, buflen-len, "/hotspot/libjvm.so");
1440
} else {
1441
// Go back to path of .so
1442
rp = os::Posix::realpath((char *)dlinfo.dli_fname, buf, buflen);
1443
if (rp == NULL) {
1444
return;
1445
}
1446
}
1447
}
1448
}
1449
}
1450
1451
strncpy(saved_jvm_path, buf, sizeof(saved_jvm_path));
1452
saved_jvm_path[sizeof(saved_jvm_path) - 1] = '\0';
1453
}
1454
1455
void os::print_jni_name_prefix_on(outputStream* st, int args_size) {
1456
// no prefix required, not even "_"
1457
}
1458
1459
void os::print_jni_name_suffix_on(outputStream* st, int args_size) {
1460
// no suffix required
1461
}
1462
1463
////////////////////////////////////////////////////////////////////////////////
1464
// Virtual Memory
1465
1466
// We need to keep small simple bookkeeping for os::reserve_memory and friends.
1467
1468
#define VMEM_MAPPED 1
1469
#define VMEM_SHMATED 2
1470
1471
struct vmembk_t {
1472
int type; // 1 - mmap, 2 - shmat
1473
char* addr;
1474
size_t size; // Real size, may be larger than usersize.
1475
size_t pagesize; // page size of area
1476
vmembk_t* next;
1477
1478
bool contains_addr(char* p) const {
1479
return p >= addr && p < (addr + size);
1480
}
1481
1482
bool contains_range(char* p, size_t s) const {
1483
return contains_addr(p) && contains_addr(p + s - 1);
1484
}
1485
1486
void print_on(outputStream* os) const {
1487
os->print("[" PTR_FORMAT " - " PTR_FORMAT "] (" UINTX_FORMAT
1488
" bytes, %d %s pages), %s",
1489
addr, addr + size - 1, size, size / pagesize, describe_pagesize(pagesize),
1490
(type == VMEM_SHMATED ? "shmat" : "mmap")
1491
);
1492
}
1493
1494
// Check that range is a sub range of memory block (or equal to memory block);
1495
// also check that range is fully page aligned to the page size if the block.
1496
void assert_is_valid_subrange(char* p, size_t s) const {
1497
if (!contains_range(p, s)) {
1498
trcVerbose("[" PTR_FORMAT " - " PTR_FORMAT "] is not a sub "
1499
"range of [" PTR_FORMAT " - " PTR_FORMAT "].",
1500
p2i(p), p2i(p + s), p2i(addr), p2i(addr + size));
1501
guarantee0(false);
1502
}
1503
if (!is_aligned_to(p, pagesize) || !is_aligned_to(p + s, pagesize)) {
1504
trcVerbose("range [" PTR_FORMAT " - " PTR_FORMAT "] is not"
1505
" aligned to pagesize (%lu)", p2i(p), p2i(p + s), (unsigned long) pagesize);
1506
guarantee0(false);
1507
}
1508
}
1509
};
1510
1511
static struct {
1512
vmembk_t* first;
1513
MiscUtils::CritSect cs;
1514
} vmem;
1515
1516
static void vmembk_add(char* addr, size_t size, size_t pagesize, int type) {
1517
vmembk_t* p = (vmembk_t*) ::malloc(sizeof(vmembk_t));
1518
assert0(p);
1519
if (p) {
1520
MiscUtils::AutoCritSect lck(&vmem.cs);
1521
p->addr = addr; p->size = size;
1522
p->pagesize = pagesize;
1523
p->type = type;
1524
p->next = vmem.first;
1525
vmem.first = p;
1526
}
1527
}
1528
1529
static vmembk_t* vmembk_find(char* addr) {
1530
MiscUtils::AutoCritSect lck(&vmem.cs);
1531
for (vmembk_t* p = vmem.first; p; p = p->next) {
1532
if (p->addr <= addr && (p->addr + p->size) > addr) {
1533
return p;
1534
}
1535
}
1536
return NULL;
1537
}
1538
1539
static void vmembk_remove(vmembk_t* p0) {
1540
MiscUtils::AutoCritSect lck(&vmem.cs);
1541
assert0(p0);
1542
assert0(vmem.first); // List should not be empty.
1543
for (vmembk_t** pp = &(vmem.first); *pp; pp = &((*pp)->next)) {
1544
if (*pp == p0) {
1545
*pp = p0->next;
1546
::free(p0);
1547
return;
1548
}
1549
}
1550
assert0(false); // Not found?
1551
}
1552
1553
static void vmembk_print_on(outputStream* os) {
1554
MiscUtils::AutoCritSect lck(&vmem.cs);
1555
for (vmembk_t* vmi = vmem.first; vmi; vmi = vmi->next) {
1556
vmi->print_on(os);
1557
os->cr();
1558
}
1559
}
1560
1561
// Reserve and attach a section of System V memory.
1562
// If <requested_addr> is not NULL, function will attempt to attach the memory at the given
1563
// address. Failing that, it will attach the memory anywhere.
1564
// If <requested_addr> is NULL, function will attach the memory anywhere.
1565
static char* reserve_shmated_memory (size_t bytes, char* requested_addr) {
1566
1567
trcVerbose("reserve_shmated_memory " UINTX_FORMAT " bytes, wishaddress "
1568
PTR_FORMAT "...", bytes, p2i(requested_addr));
1569
1570
// We must prevent anyone from attaching too close to the
1571
// BRK because that may cause malloc OOM.
1572
if (requested_addr != NULL && is_close_to_brk((address)requested_addr)) {
1573
trcVerbose("Wish address " PTR_FORMAT " is too close to the BRK segment.", p2i(requested_addr));
1574
// Since we treat an attach to the wrong address as an error later anyway,
1575
// we return NULL here
1576
return NULL;
1577
}
1578
1579
// For old AS/400's (V5R4 and older) we should not even be here - System V shared memory is not
1580
// really supported (max size 4GB), so reserve_mmapped_memory should have been used instead.
1581
if (os::Aix::on_pase_V5R4_or_older()) {
1582
ShouldNotReachHere();
1583
}
1584
1585
// Align size of shm up to 64K to avoid errors if we later try to change the page size.
1586
const size_t size = align_up(bytes, 64*K);
1587
1588
// Reserve the shared segment.
1589
int shmid = shmget(IPC_PRIVATE, size, IPC_CREAT | S_IRUSR | S_IWUSR);
1590
if (shmid == -1) {
1591
trcVerbose("shmget(.., " UINTX_FORMAT ", ..) failed (errno: %d).", size, errno);
1592
return NULL;
1593
}
1594
1595
// Important note:
1596
// It is very important that we, upon leaving this function, do not leave a shm segment alive.
1597
// We must right after attaching it remove it from the system. System V shm segments are global and
1598
// survive the process.
1599
// So, from here on: Do not assert, do not return, until we have called shmctl(IPC_RMID) (A).
1600
1601
struct shmid_ds shmbuf;
1602
memset(&shmbuf, 0, sizeof(shmbuf));
1603
shmbuf.shm_pagesize = 64*K;
1604
if (shmctl(shmid, SHM_PAGESIZE, &shmbuf) != 0) {
1605
trcVerbose("Failed to set page size (need " UINTX_FORMAT " 64K pages) - shmctl failed with %d.",
1606
size / (64*K), errno);
1607
// I want to know if this ever happens.
1608
assert(false, "failed to set page size for shmat");
1609
}
1610
1611
// Now attach the shared segment.
1612
// Note that I attach with SHM_RND - which means that the requested address is rounded down, if
1613
// needed, to the next lowest segment boundary. Otherwise the attach would fail if the address
1614
// were not a segment boundary.
1615
char* const addr = (char*) shmat(shmid, requested_addr, SHM_RND);
1616
const int errno_shmat = errno;
1617
1618
// (A) Right after shmat and before handing shmat errors delete the shm segment.
1619
if (::shmctl(shmid, IPC_RMID, NULL) == -1) {
1620
trcVerbose("shmctl(%u, IPC_RMID) failed (%d)\n", shmid, errno);
1621
assert(false, "failed to remove shared memory segment!");
1622
}
1623
1624
// Handle shmat error. If we failed to attach, just return.
1625
if (addr == (char*)-1) {
1626
trcVerbose("Failed to attach segment at " PTR_FORMAT " (%d).", p2i(requested_addr), errno_shmat);
1627
return NULL;
1628
}
1629
1630
// Just for info: query the real page size. In case setting the page size did not
1631
// work (see above), the system may have given us something other then 4K (LDR_CNTRL).
1632
const size_t real_pagesize = os::Aix::query_pagesize(addr);
1633
if (real_pagesize != shmbuf.shm_pagesize) {
1634
trcVerbose("pagesize is, surprisingly, " SIZE_FORMAT, real_pagesize);
1635
}
1636
1637
if (addr) {
1638
trcVerbose("shm-allocated " PTR_FORMAT " .. " PTR_FORMAT " (" UINTX_FORMAT " bytes, " UINTX_FORMAT " %s pages)",
1639
p2i(addr), p2i(addr + size - 1), size, size/real_pagesize, describe_pagesize(real_pagesize));
1640
} else {
1641
if (requested_addr != NULL) {
1642
trcVerbose("failed to shm-allocate " UINTX_FORMAT " bytes at with address " PTR_FORMAT ".", size, p2i(requested_addr));
1643
} else {
1644
trcVerbose("failed to shm-allocate " UINTX_FORMAT " bytes at any address.", size);
1645
}
1646
}
1647
1648
// book-keeping
1649
vmembk_add(addr, size, real_pagesize, VMEM_SHMATED);
1650
assert0(is_aligned_to(addr, os::vm_page_size()));
1651
1652
return addr;
1653
}
1654
1655
static bool release_shmated_memory(char* addr, size_t size) {
1656
1657
trcVerbose("release_shmated_memory [" PTR_FORMAT " - " PTR_FORMAT "].",
1658
p2i(addr), p2i(addr + size - 1));
1659
1660
bool rc = false;
1661
1662
// TODO: is there a way to verify shm size without doing bookkeeping?
1663
if (::shmdt(addr) != 0) {
1664
trcVerbose("error (%d).", errno);
1665
} else {
1666
trcVerbose("ok.");
1667
rc = true;
1668
}
1669
return rc;
1670
}
1671
1672
static bool uncommit_shmated_memory(char* addr, size_t size) {
1673
trcVerbose("uncommit_shmated_memory [" PTR_FORMAT " - " PTR_FORMAT "].",
1674
p2i(addr), p2i(addr + size - 1));
1675
1676
const bool rc = my_disclaim64(addr, size);
1677
1678
if (!rc) {
1679
trcVerbose("my_disclaim64(" PTR_FORMAT ", " UINTX_FORMAT ") failed.\n", p2i(addr), size);
1680
return false;
1681
}
1682
return true;
1683
}
1684
1685
//////////////////////////////// mmap-based routines /////////////////////////////////
1686
1687
// Reserve memory via mmap.
1688
// If <requested_addr> is given, an attempt is made to attach at the given address.
1689
// Failing that, memory is allocated at any address.
1690
static char* reserve_mmaped_memory(size_t bytes, char* requested_addr) {
1691
trcVerbose("reserve_mmaped_memory " UINTX_FORMAT " bytes, wishaddress " PTR_FORMAT "...",
1692
bytes, p2i(requested_addr));
1693
1694
if (requested_addr && !is_aligned_to(requested_addr, os::vm_page_size()) != 0) {
1695
trcVerbose("Wish address " PTR_FORMAT " not aligned to page boundary.", p2i(requested_addr));
1696
return NULL;
1697
}
1698
1699
// We must prevent anyone from attaching too close to the
1700
// BRK because that may cause malloc OOM.
1701
if (requested_addr != NULL && is_close_to_brk((address)requested_addr)) {
1702
trcVerbose("Wish address " PTR_FORMAT " is too close to the BRK segment.", p2i(requested_addr));
1703
// Since we treat an attach to the wrong address as an error later anyway,
1704
// we return NULL here
1705
return NULL;
1706
}
1707
1708
// In 64K mode, we lie and claim the global page size (os::vm_page_size()) is 64K
1709
// (complicated story). This mostly works just fine since 64K is a multiple of the
1710
// actual 4K lowest page size. Only at a few seams light shines thru, e.g. when
1711
// calling mmap. mmap will return memory aligned to the lowest pages size - 4K -
1712
// so we must make sure - transparently - that the caller only ever sees 64K
1713
// aligned mapping start addresses.
1714
const size_t alignment = os::vm_page_size();
1715
1716
// Size shall always be a multiple of os::vm_page_size (esp. in 64K mode).
1717
const size_t size = align_up(bytes, os::vm_page_size());
1718
1719
// alignment: Allocate memory large enough to include an aligned range of the right size and
1720
// cut off the leading and trailing waste pages.
1721
assert0(alignment != 0 && is_aligned_to(alignment, os::vm_page_size())); // see above
1722
const size_t extra_size = size + alignment;
1723
1724
// Note: MAP_SHARED (instead of MAP_PRIVATE) needed to be able to
1725
// later use msync(MS_INVALIDATE) (see os::uncommit_memory).
1726
int flags = MAP_ANONYMOUS | MAP_SHARED;
1727
1728
// MAP_FIXED is needed to enforce requested_addr - manpage is vague about what
1729
// it means if wishaddress is given but MAP_FIXED is not set.
1730
//
1731
// Important! Behaviour differs depending on whether SPEC1170 mode is active or not.
1732
// SPEC1170 mode active: behaviour like POSIX, MAP_FIXED will clobber existing mappings.
1733
// SPEC1170 mode not active: behaviour, unlike POSIX, is that no existing mappings will
1734
// get clobbered.
1735
if (requested_addr != NULL) {
1736
if (!os::Aix::xpg_sus_mode()) { // not SPEC1170 Behaviour
1737
flags |= MAP_FIXED;
1738
}
1739
}
1740
1741
char* addr = (char*)::mmap(requested_addr, extra_size,
1742
PROT_READ|PROT_WRITE|PROT_EXEC, flags, -1, 0);
1743
1744
if (addr == MAP_FAILED) {
1745
trcVerbose("mmap(" PTR_FORMAT ", " UINTX_FORMAT ", ..) failed (%d)", p2i(requested_addr), size, errno);
1746
return NULL;
1747
} else if (requested_addr != NULL && addr != requested_addr) {
1748
trcVerbose("mmap(" PTR_FORMAT ", " UINTX_FORMAT ", ..) succeeded, but at a different address than requested (" PTR_FORMAT "), will unmap",
1749
p2i(requested_addr), size, p2i(addr));
1750
::munmap(addr, extra_size);
1751
return NULL;
1752
}
1753
1754
// Handle alignment.
1755
char* const addr_aligned = align_up(addr, alignment);
1756
const size_t waste_pre = addr_aligned - addr;
1757
char* const addr_aligned_end = addr_aligned + size;
1758
const size_t waste_post = extra_size - waste_pre - size;
1759
if (waste_pre > 0) {
1760
::munmap(addr, waste_pre);
1761
}
1762
if (waste_post > 0) {
1763
::munmap(addr_aligned_end, waste_post);
1764
}
1765
addr = addr_aligned;
1766
1767
trcVerbose("mmap-allocated " PTR_FORMAT " .. " PTR_FORMAT " (" UINTX_FORMAT " bytes)",
1768
p2i(addr), p2i(addr + bytes), bytes);
1769
1770
// bookkeeping
1771
vmembk_add(addr, size, 4*K, VMEM_MAPPED);
1772
1773
// Test alignment, see above.
1774
assert0(is_aligned_to(addr, os::vm_page_size()));
1775
1776
return addr;
1777
}
1778
1779
static bool release_mmaped_memory(char* addr, size_t size) {
1780
assert0(is_aligned_to(addr, os::vm_page_size()));
1781
assert0(is_aligned_to(size, os::vm_page_size()));
1782
1783
trcVerbose("release_mmaped_memory [" PTR_FORMAT " - " PTR_FORMAT "].",
1784
p2i(addr), p2i(addr + size - 1));
1785
bool rc = false;
1786
1787
if (::munmap(addr, size) != 0) {
1788
trcVerbose("failed (%d)\n", errno);
1789
rc = false;
1790
} else {
1791
trcVerbose("ok.");
1792
rc = true;
1793
}
1794
1795
return rc;
1796
}
1797
1798
static bool uncommit_mmaped_memory(char* addr, size_t size) {
1799
1800
assert0(is_aligned_to(addr, os::vm_page_size()));
1801
assert0(is_aligned_to(size, os::vm_page_size()));
1802
1803
trcVerbose("uncommit_mmaped_memory [" PTR_FORMAT " - " PTR_FORMAT "].",
1804
p2i(addr), p2i(addr + size - 1));
1805
bool rc = false;
1806
1807
// Uncommit mmap memory with msync MS_INVALIDATE.
1808
if (::msync(addr, size, MS_INVALIDATE) != 0) {
1809
trcVerbose("failed (%d)\n", errno);
1810
rc = false;
1811
} else {
1812
trcVerbose("ok.");
1813
rc = true;
1814
}
1815
1816
return rc;
1817
}
1818
1819
int os::vm_page_size() {
1820
// Seems redundant as all get out.
1821
assert(os::Aix::page_size() != -1, "must call os::init");
1822
return os::Aix::page_size();
1823
}
1824
1825
// Aix allocates memory by pages.
1826
int os::vm_allocation_granularity() {
1827
assert(os::Aix::page_size() != -1, "must call os::init");
1828
return os::Aix::page_size();
1829
}
1830
1831
#ifdef PRODUCT
1832
static void warn_fail_commit_memory(char* addr, size_t size, bool exec,
1833
int err) {
1834
warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
1835
", %d) failed; error='%s' (errno=%d)", p2i(addr), size, exec,
1836
os::errno_name(err), err);
1837
}
1838
#endif
1839
1840
void os::pd_commit_memory_or_exit(char* addr, size_t size, bool exec,
1841
const char* mesg) {
1842
assert(mesg != NULL, "mesg must be specified");
1843
if (!pd_commit_memory(addr, size, exec)) {
1844
// Add extra info in product mode for vm_exit_out_of_memory():
1845
PRODUCT_ONLY(warn_fail_commit_memory(addr, size, exec, errno);)
1846
vm_exit_out_of_memory(size, OOM_MMAP_ERROR, "%s", mesg);
1847
}
1848
}
1849
1850
bool os::pd_commit_memory(char* addr, size_t size, bool exec) {
1851
1852
assert(is_aligned_to(addr, os::vm_page_size()),
1853
"addr " PTR_FORMAT " not aligned to vm_page_size (" PTR_FORMAT ")",
1854
p2i(addr), os::vm_page_size());
1855
assert(is_aligned_to(size, os::vm_page_size()),
1856
"size " PTR_FORMAT " not aligned to vm_page_size (" PTR_FORMAT ")",
1857
size, os::vm_page_size());
1858
1859
vmembk_t* const vmi = vmembk_find(addr);
1860
guarantee0(vmi);
1861
vmi->assert_is_valid_subrange(addr, size);
1862
1863
trcVerbose("commit_memory [" PTR_FORMAT " - " PTR_FORMAT "].", p2i(addr), p2i(addr + size - 1));
1864
1865
if (UseExplicitCommit) {
1866
// AIX commits memory on touch. So, touch all pages to be committed.
1867
for (char* p = addr; p < (addr + size); p += 4*K) {
1868
*p = '\0';
1869
}
1870
}
1871
1872
return true;
1873
}
1874
1875
bool os::pd_commit_memory(char* addr, size_t size, size_t alignment_hint, bool exec) {
1876
return pd_commit_memory(addr, size, exec);
1877
}
1878
1879
void os::pd_commit_memory_or_exit(char* addr, size_t size,
1880
size_t alignment_hint, bool exec,
1881
const char* mesg) {
1882
// Alignment_hint is ignored on this OS.
1883
pd_commit_memory_or_exit(addr, size, exec, mesg);
1884
}
1885
1886
bool os::pd_uncommit_memory(char* addr, size_t size, bool exec) {
1887
assert(is_aligned_to(addr, os::vm_page_size()),
1888
"addr " PTR_FORMAT " not aligned to vm_page_size (" PTR_FORMAT ")",
1889
p2i(addr), os::vm_page_size());
1890
assert(is_aligned_to(size, os::vm_page_size()),
1891
"size " PTR_FORMAT " not aligned to vm_page_size (" PTR_FORMAT ")",
1892
size, os::vm_page_size());
1893
1894
// Dynamically do different things for mmap/shmat.
1895
const vmembk_t* const vmi = vmembk_find(addr);
1896
guarantee0(vmi);
1897
vmi->assert_is_valid_subrange(addr, size);
1898
1899
if (vmi->type == VMEM_SHMATED) {
1900
return uncommit_shmated_memory(addr, size);
1901
} else {
1902
return uncommit_mmaped_memory(addr, size);
1903
}
1904
}
1905
1906
bool os::pd_create_stack_guard_pages(char* addr, size_t size) {
1907
// Do not call this; no need to commit stack pages on AIX.
1908
ShouldNotReachHere();
1909
return true;
1910
}
1911
1912
bool os::remove_stack_guard_pages(char* addr, size_t size) {
1913
// Do not call this; no need to commit stack pages on AIX.
1914
ShouldNotReachHere();
1915
return true;
1916
}
1917
1918
void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) {
1919
}
1920
1921
void os::pd_free_memory(char *addr, size_t bytes, size_t alignment_hint) {
1922
}
1923
1924
void os::numa_make_global(char *addr, size_t bytes) {
1925
}
1926
1927
void os::numa_make_local(char *addr, size_t bytes, int lgrp_hint) {
1928
}
1929
1930
bool os::numa_topology_changed() {
1931
return false;
1932
}
1933
1934
size_t os::numa_get_groups_num() {
1935
return 1;
1936
}
1937
1938
int os::numa_get_group_id() {
1939
return 0;
1940
}
1941
1942
size_t os::numa_get_leaf_groups(int *ids, size_t size) {
1943
if (size > 0) {
1944
ids[0] = 0;
1945
return 1;
1946
}
1947
return 0;
1948
}
1949
1950
int os::numa_get_group_id_for_address(const void* address) {
1951
return 0;
1952
}
1953
1954
bool os::get_page_info(char *start, page_info* info) {
1955
return false;
1956
}
1957
1958
char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) {
1959
return end;
1960
}
1961
1962
// Reserves and attaches a shared memory segment.
1963
char* os::pd_reserve_memory(size_t bytes, bool exec) {
1964
// Always round to os::vm_page_size(), which may be larger than 4K.
1965
bytes = align_up(bytes, os::vm_page_size());
1966
1967
// In 4K mode always use mmap.
1968
// In 64K mode allocate small sizes with mmap, large ones with 64K shmatted.
1969
if (os::vm_page_size() == 4*K) {
1970
return reserve_mmaped_memory(bytes, NULL /* requested_addr */);
1971
} else {
1972
if (bytes >= Use64KPagesThreshold) {
1973
return reserve_shmated_memory(bytes, NULL /* requested_addr */);
1974
} else {
1975
return reserve_mmaped_memory(bytes, NULL /* requested_addr */);
1976
}
1977
}
1978
}
1979
1980
bool os::pd_release_memory(char* addr, size_t size) {
1981
1982
// Dynamically do different things for mmap/shmat.
1983
vmembk_t* const vmi = vmembk_find(addr);
1984
guarantee0(vmi);
1985
vmi->assert_is_valid_subrange(addr, size);
1986
1987
// Always round to os::vm_page_size(), which may be larger than 4K.
1988
size = align_up(size, os::vm_page_size());
1989
addr = align_up(addr, os::vm_page_size());
1990
1991
bool rc = false;
1992
bool remove_bookkeeping = false;
1993
if (vmi->type == VMEM_SHMATED) {
1994
// For shmatted memory, we do:
1995
// - If user wants to release the whole range, release the memory (shmdt).
1996
// - If user only wants to release a partial range, uncommit (disclaim) that
1997
// range. That way, at least, we do not use memory anymore (bust still page
1998
// table space).
1999
if (addr == vmi->addr && size == vmi->size) {
2000
rc = release_shmated_memory(addr, size);
2001
remove_bookkeeping = true;
2002
} else {
2003
rc = uncommit_shmated_memory(addr, size);
2004
}
2005
} else {
2006
// In mmap-mode:
2007
// - If the user wants to release the full range, we do that and remove the mapping.
2008
// - If the user wants to release part of the range, we release that part, but need
2009
// to adjust bookkeeping.
2010
assert(is_aligned(size, 4 * K), "Sanity");
2011
rc = release_mmaped_memory(addr, size);
2012
if (addr == vmi->addr && size == vmi->size) {
2013
remove_bookkeeping = true;
2014
} else {
2015
if (addr == vmi->addr && size < vmi->size) {
2016
// Chopped from head
2017
vmi->addr += size;
2018
vmi->size -= size;
2019
} else if (addr + size == vmi->addr + vmi->size) {
2020
// Chopped from tail
2021
vmi->size -= size;
2022
} else {
2023
// releasing a mapping in the middle of the original mapping:
2024
// For now we forbid this, since this is an invalid scenario
2025
// (the bookkeeping is easy enough to fix if needed but there
2026
// is no use case for it; any occurrence is likely an error.
2027
ShouldNotReachHere();
2028
}
2029
}
2030
}
2031
2032
// update bookkeeping
2033
if (rc && remove_bookkeeping) {
2034
vmembk_remove(vmi);
2035
}
2036
2037
return rc;
2038
}
2039
2040
static bool checked_mprotect(char* addr, size_t size, int prot) {
2041
2042
// Little problem here: if SPEC1170 behaviour is off, mprotect() on AIX will
2043
// not tell me if protection failed when trying to protect an un-protectable range.
2044
//
2045
// This means if the memory was allocated using shmget/shmat, protection wont work
2046
// but mprotect will still return 0:
2047
//
2048
// See http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/mprotect.htm
2049
2050
Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
2051
bool rc = ::mprotect(addr, size, prot) == 0 ? true : false;
2052
2053
if (!rc) {
2054
const char* const s_errno = os::errno_name(errno);
2055
warning("mprotect(" PTR_FORMAT "-" PTR_FORMAT ", 0x%X) failed (%s).", addr, addr + size, prot, s_errno);
2056
return false;
2057
}
2058
2059
// mprotect success check
2060
//
2061
// Mprotect said it changed the protection but can I believe it?
2062
//
2063
// To be sure I need to check the protection afterwards. Try to
2064
// read from protected memory and check whether that causes a segfault.
2065
//
2066
if (!os::Aix::xpg_sus_mode()) {
2067
2068
if (CanUseSafeFetch32()) {
2069
2070
const bool read_protected =
2071
(SafeFetch32((int*)addr, 0x12345678) == 0x12345678 &&
2072
SafeFetch32((int*)addr, 0x76543210) == 0x76543210) ? true : false;
2073
2074
if (prot & PROT_READ) {
2075
rc = !read_protected;
2076
} else {
2077
rc = read_protected;
2078
}
2079
2080
if (!rc) {
2081
if (os::Aix::on_pase()) {
2082
// There is an issue on older PASE systems where mprotect() will return success but the
2083
// memory will not be protected.
2084
// This has nothing to do with the problem of using mproect() on SPEC1170 incompatible
2085
// machines; we only see it rarely, when using mprotect() to protect the guard page of
2086
// a stack. It is an OS error.
2087
//
2088
// A valid strategy is just to try again. This usually works. :-/
2089
2090
::usleep(1000);
2091
Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
2092
if (::mprotect(addr, size, prot) == 0) {
2093
const bool read_protected_2 =
2094
(SafeFetch32((int*)addr, 0x12345678) == 0x12345678 &&
2095
SafeFetch32((int*)addr, 0x76543210) == 0x76543210) ? true : false;
2096
rc = true;
2097
}
2098
}
2099
}
2100
}
2101
}
2102
2103
assert(rc == true, "mprotect failed.");
2104
2105
return rc;
2106
}
2107
2108
// Set protections specified
2109
bool os::protect_memory(char* addr, size_t size, ProtType prot, bool is_committed) {
2110
unsigned int p = 0;
2111
switch (prot) {
2112
case MEM_PROT_NONE: p = PROT_NONE; break;
2113
case MEM_PROT_READ: p = PROT_READ; break;
2114
case MEM_PROT_RW: p = PROT_READ|PROT_WRITE; break;
2115
case MEM_PROT_RWX: p = PROT_READ|PROT_WRITE|PROT_EXEC; break;
2116
default:
2117
ShouldNotReachHere();
2118
}
2119
// is_committed is unused.
2120
return checked_mprotect(addr, size, p);
2121
}
2122
2123
bool os::guard_memory(char* addr, size_t size) {
2124
return checked_mprotect(addr, size, PROT_NONE);
2125
}
2126
2127
bool os::unguard_memory(char* addr, size_t size) {
2128
return checked_mprotect(addr, size, PROT_READ|PROT_WRITE|PROT_EXEC);
2129
}
2130
2131
// Large page support
2132
2133
static size_t _large_page_size = 0;
2134
2135
// Enable large page support if OS allows that.
2136
void os::large_page_init() {
2137
return; // Nothing to do. See query_multipage_support and friends.
2138
}
2139
2140
char* os::pd_reserve_memory_special(size_t bytes, size_t alignment, size_t page_size, char* req_addr, bool exec) {
2141
fatal("os::reserve_memory_special should not be called on AIX.");
2142
return NULL;
2143
}
2144
2145
bool os::pd_release_memory_special(char* base, size_t bytes) {
2146
fatal("os::release_memory_special should not be called on AIX.");
2147
return false;
2148
}
2149
2150
size_t os::large_page_size() {
2151
return _large_page_size;
2152
}
2153
2154
bool os::can_commit_large_page_memory() {
2155
// Does not matter, we do not support huge pages.
2156
return false;
2157
}
2158
2159
bool os::can_execute_large_page_memory() {
2160
// Does not matter, we do not support huge pages.
2161
return false;
2162
}
2163
2164
char* os::pd_attempt_map_memory_to_file_at(char* requested_addr, size_t bytes, int file_desc) {
2165
assert(file_desc >= 0, "file_desc is not valid");
2166
char* result = NULL;
2167
2168
// Always round to os::vm_page_size(), which may be larger than 4K.
2169
bytes = align_up(bytes, os::vm_page_size());
2170
result = reserve_mmaped_memory(bytes, requested_addr);
2171
2172
if (result != NULL) {
2173
if (replace_existing_mapping_with_file_mapping(result, bytes, file_desc) == NULL) {
2174
vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory"));
2175
}
2176
}
2177
return result;
2178
}
2179
2180
// Reserve memory at an arbitrary address, only if that area is
2181
// available (and not reserved for something else).
2182
char* os::pd_attempt_reserve_memory_at(char* requested_addr, size_t bytes, bool exec) {
2183
char* addr = NULL;
2184
2185
// Always round to os::vm_page_size(), which may be larger than 4K.
2186
bytes = align_up(bytes, os::vm_page_size());
2187
2188
// In 4K mode always use mmap.
2189
// In 64K mode allocate small sizes with mmap, large ones with 64K shmatted.
2190
if (os::vm_page_size() == 4*K) {
2191
return reserve_mmaped_memory(bytes, requested_addr);
2192
} else {
2193
if (bytes >= Use64KPagesThreshold) {
2194
return reserve_shmated_memory(bytes, requested_addr);
2195
} else {
2196
return reserve_mmaped_memory(bytes, requested_addr);
2197
}
2198
}
2199
2200
return addr;
2201
}
2202
2203
// Used to convert frequent JVM_Yield() to nops
2204
bool os::dont_yield() {
2205
return DontYieldALot;
2206
}
2207
2208
void os::naked_yield() {
2209
sched_yield();
2210
}
2211
2212
////////////////////////////////////////////////////////////////////////////////
2213
// thread priority support
2214
2215
// From AIX manpage to pthread_setschedparam
2216
// (see: http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?
2217
// topic=/com.ibm.aix.basetechref/doc/basetrf1/pthread_setschedparam.htm):
2218
//
2219
// "If schedpolicy is SCHED_OTHER, then sched_priority must be in the
2220
// range from 40 to 80, where 40 is the least favored priority and 80
2221
// is the most favored."
2222
//
2223
// (Actually, I doubt this even has an impact on AIX, as we do kernel
2224
// scheduling there; however, this still leaves iSeries.)
2225
//
2226
// We use the same values for AIX and PASE.
2227
int os::java_to_os_priority[CriticalPriority + 1] = {
2228
54, // 0 Entry should never be used
2229
2230
55, // 1 MinPriority
2231
55, // 2
2232
56, // 3
2233
2234
56, // 4
2235
57, // 5 NormPriority
2236
57, // 6
2237
2238
58, // 7
2239
58, // 8
2240
59, // 9 NearMaxPriority
2241
2242
60, // 10 MaxPriority
2243
2244
60 // 11 CriticalPriority
2245
};
2246
2247
static int prio_init() {
2248
if (ThreadPriorityPolicy == 1) {
2249
if (geteuid() != 0) {
2250
if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy) && !FLAG_IS_JIMAGE_RESOURCE(ThreadPriorityPolicy)) {
2251
warning("-XX:ThreadPriorityPolicy=1 may require system level permission, " \
2252
"e.g., being the root user. If the necessary permission is not " \
2253
"possessed, changes to priority will be silently ignored.");
2254
}
2255
}
2256
}
2257
if (UseCriticalJavaThreadPriority) {
2258
os::java_to_os_priority[MaxPriority] = os::java_to_os_priority[CriticalPriority];
2259
}
2260
return 0;
2261
}
2262
2263
OSReturn os::set_native_priority(Thread* thread, int newpri) {
2264
if (!UseThreadPriorities || ThreadPriorityPolicy == 0) return OS_OK;
2265
pthread_t thr = thread->osthread()->pthread_id();
2266
int policy = SCHED_OTHER;
2267
struct sched_param param;
2268
param.sched_priority = newpri;
2269
int ret = pthread_setschedparam(thr, policy, &param);
2270
2271
if (ret != 0) {
2272
trcVerbose("Could not change priority for thread %d to %d (error %d, %s)",
2273
(int)thr, newpri, ret, os::errno_name(ret));
2274
}
2275
return (ret == 0) ? OS_OK : OS_ERR;
2276
}
2277
2278
OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) {
2279
if (!UseThreadPriorities || ThreadPriorityPolicy == 0) {
2280
*priority_ptr = java_to_os_priority[NormPriority];
2281
return OS_OK;
2282
}
2283
pthread_t thr = thread->osthread()->pthread_id();
2284
int policy = SCHED_OTHER;
2285
struct sched_param param;
2286
int ret = pthread_getschedparam(thr, &policy, &param);
2287
*priority_ptr = param.sched_priority;
2288
2289
return (ret == 0) ? OS_OK : OS_ERR;
2290
}
2291
2292
// To install functions for atexit system call
2293
extern "C" {
2294
static void perfMemory_exit_helper() {
2295
perfMemory_exit();
2296
}
2297
}
2298
2299
// This is called _before_ the most of global arguments have been parsed.
2300
void os::init(void) {
2301
// This is basic, we want to know if that ever changes.
2302
// (Shared memory boundary is supposed to be a 256M aligned.)
2303
assert(SHMLBA == ((uint64_t)0x10000000ULL)/*256M*/, "unexpected");
2304
2305
// Record process break at startup.
2306
g_brk_at_startup = (address) ::sbrk(0);
2307
assert(g_brk_at_startup != (address) -1, "sbrk failed");
2308
2309
// First off, we need to know whether we run on AIX or PASE, and
2310
// the OS level we run on.
2311
os::Aix::initialize_os_info();
2312
2313
// Scan environment (SPEC1170 behaviour, etc).
2314
os::Aix::scan_environment();
2315
2316
// Probe multipage support.
2317
query_multipage_support();
2318
2319
// Act like we only have one page size by eliminating corner cases which
2320
// we did not support very well anyway.
2321
// We have two input conditions:
2322
// 1) Data segment page size. This is controlled by linker setting (datapsize) on the
2323
// launcher, and/or by LDR_CNTRL environment variable. The latter overrules the linker
2324
// setting.
2325
// Data segment page size is important for us because it defines the thread stack page
2326
// size, which is needed for guard page handling, stack banging etc.
2327
// 2) The ability to allocate 64k pages dynamically. If this is a given, java heap can
2328
// and should be allocated with 64k pages.
2329
//
2330
// So, we do the following:
2331
// LDR_CNTRL can_use_64K_pages_dynamically what we do remarks
2332
// 4K no 4K old systems (aix 5.2, as/400 v5r4) or new systems with AME activated
2333
// 4k yes 64k (treat 4k stacks as 64k) different loader than java and standard settings
2334
// 64k no --- AIX 5.2 ? ---
2335
// 64k yes 64k new systems and standard java loader (we set datapsize=64k when linking)
2336
2337
// We explicitly leave no option to change page size, because only upgrading would work,
2338
// not downgrading (if stack page size is 64k you cannot pretend its 4k).
2339
2340
if (g_multipage_support.datapsize == 4*K) {
2341
// datapsize = 4K. Data segment, thread stacks are 4K paged.
2342
if (g_multipage_support.can_use_64K_pages) {
2343
// .. but we are able to use 64K pages dynamically.
2344
// This would be typical for java launchers which are not linked
2345
// with datapsize=64K (like, any other launcher but our own).
2346
//
2347
// In this case it would be smart to allocate the java heap with 64K
2348
// to get the performance benefit, and to fake 64k pages for the
2349
// data segment (when dealing with thread stacks).
2350
//
2351
// However, leave a possibility to downgrade to 4K, using
2352
// -XX:-Use64KPages.
2353
if (Use64KPages) {
2354
trcVerbose("64K page mode (faked for data segment)");
2355
Aix::_page_size = 64*K;
2356
} else {
2357
trcVerbose("4K page mode (Use64KPages=off)");
2358
Aix::_page_size = 4*K;
2359
}
2360
} else {
2361
// .. and not able to allocate 64k pages dynamically. Here, just
2362
// fall back to 4K paged mode and use mmap for everything.
2363
trcVerbose("4K page mode");
2364
Aix::_page_size = 4*K;
2365
FLAG_SET_ERGO(Use64KPages, false);
2366
}
2367
} else {
2368
// datapsize = 64k. Data segment, thread stacks are 64k paged.
2369
// This normally means that we can allocate 64k pages dynamically.
2370
// (There is one special case where this may be false: EXTSHM=on.
2371
// but we decided to not support that mode).
2372
assert0(g_multipage_support.can_use_64K_pages);
2373
Aix::_page_size = 64*K;
2374
trcVerbose("64K page mode");
2375
FLAG_SET_ERGO(Use64KPages, true);
2376
}
2377
2378
// For now UseLargePages is just ignored.
2379
FLAG_SET_ERGO(UseLargePages, false);
2380
_page_sizes.add(Aix::_page_size);
2381
2382
// debug trace
2383
trcVerbose("os::vm_page_size %s", describe_pagesize(os::vm_page_size()));
2384
2385
// Next, we need to initialize libo4 and libperfstat libraries.
2386
if (os::Aix::on_pase()) {
2387
os::Aix::initialize_libo4();
2388
} else {
2389
os::Aix::initialize_libperfstat();
2390
}
2391
2392
// Reset the perfstat information provided by ODM.
2393
if (os::Aix::on_aix()) {
2394
libperfstat::perfstat_reset();
2395
}
2396
2397
// Now initialze basic system properties. Note that for some of the values we
2398
// need libperfstat etc.
2399
os::Aix::initialize_system_info();
2400
2401
clock_tics_per_sec = sysconf(_SC_CLK_TCK);
2402
2403
// _main_thread points to the thread that created/loaded the JVM.
2404
Aix::_main_thread = pthread_self();
2405
2406
initial_time_count = javaTimeNanos();
2407
2408
os::Posix::init();
2409
}
2410
2411
// This is called _after_ the global arguments have been parsed.
2412
jint os::init_2(void) {
2413
2414
// This could be set after os::Posix::init() but all platforms
2415
// have to set it the same so we have to mirror Solaris.
2416
DEBUG_ONLY(os::set_mutex_init_done();)
2417
2418
os::Posix::init_2();
2419
2420
if (os::Aix::on_pase()) {
2421
trcVerbose("Running on PASE.");
2422
} else {
2423
trcVerbose("Running on AIX (not PASE).");
2424
}
2425
2426
trcVerbose("processor count: %d", os::_processor_count);
2427
trcVerbose("physical memory: %lu", Aix::_physical_memory);
2428
2429
// Initially build up the loaded dll map.
2430
LoadedLibraries::reload();
2431
if (Verbose) {
2432
trcVerbose("Loaded Libraries: ");
2433
LoadedLibraries::print(tty);
2434
}
2435
2436
if (PosixSignals::init() == JNI_ERR) {
2437
return JNI_ERR;
2438
}
2439
2440
// Check and sets minimum stack sizes against command line options
2441
if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
2442
return JNI_ERR;
2443
}
2444
2445
// Not supported.
2446
FLAG_SET_ERGO(UseNUMA, false);
2447
FLAG_SET_ERGO(UseNUMAInterleaving, false);
2448
2449
if (MaxFDLimit) {
2450
// Set the number of file descriptors to max. print out error
2451
// if getrlimit/setrlimit fails but continue regardless.
2452
struct rlimit nbr_files;
2453
int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
2454
if (status != 0) {
2455
log_info(os)("os::init_2 getrlimit failed: %s", os::strerror(errno));
2456
} else {
2457
nbr_files.rlim_cur = nbr_files.rlim_max;
2458
status = setrlimit(RLIMIT_NOFILE, &nbr_files);
2459
if (status != 0) {
2460
log_info(os)("os::init_2 setrlimit failed: %s", os::strerror(errno));
2461
}
2462
}
2463
}
2464
2465
if (PerfAllowAtExitRegistration) {
2466
// Only register atexit functions if PerfAllowAtExitRegistration is set.
2467
// At exit functions can be delayed until process exit time, which
2468
// can be problematic for embedded VM situations. Embedded VMs should
2469
// call DestroyJavaVM() to assure that VM resources are released.
2470
2471
// Note: perfMemory_exit_helper atexit function may be removed in
2472
// the future if the appropriate cleanup code can be added to the
2473
// VM_Exit VMOperation's doit method.
2474
if (atexit(perfMemory_exit_helper) != 0) {
2475
warning("os::init_2 atexit(perfMemory_exit_helper) failed");
2476
}
2477
}
2478
2479
// initialize thread priority policy
2480
prio_init();
2481
2482
return JNI_OK;
2483
}
2484
2485
int os::active_processor_count() {
2486
// User has overridden the number of active processors
2487
if (ActiveProcessorCount > 0) {
2488
log_trace(os)("active_processor_count: "
2489
"active processor count set by user : %d",
2490
ActiveProcessorCount);
2491
return ActiveProcessorCount;
2492
}
2493
2494
int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
2495
assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check");
2496
return online_cpus;
2497
}
2498
2499
void os::set_native_thread_name(const char *name) {
2500
// Not yet implemented.
2501
return;
2502
}
2503
2504
bool os::bind_to_processor(uint processor_id) {
2505
// Not yet implemented.
2506
return false;
2507
}
2508
2509
////////////////////////////////////////////////////////////////////////////////
2510
// debug support
2511
2512
bool os::find(address addr, outputStream* st) {
2513
2514
st->print(PTR_FORMAT ": ", addr);
2515
2516
loaded_module_t lm;
2517
if (LoadedLibraries::find_for_text_address(addr, &lm) != NULL ||
2518
LoadedLibraries::find_for_data_address(addr, &lm) != NULL) {
2519
st->print_cr("%s", lm.path);
2520
return true;
2521
}
2522
2523
return false;
2524
}
2525
2526
////////////////////////////////////////////////////////////////////////////////
2527
// misc
2528
2529
// This does not do anything on Aix. This is basically a hook for being
2530
// able to use structured exception handling (thread-local exception filters)
2531
// on, e.g., Win32.
2532
void
2533
os::os_exception_wrapper(java_call_t f, JavaValue* value, const methodHandle& method,
2534
JavaCallArguments* args, JavaThread* thread) {
2535
f(value, method, args, thread);
2536
}
2537
2538
void os::print_statistics() {
2539
}
2540
2541
bool os::message_box(const char* title, const char* message) {
2542
int i;
2543
fdStream err(defaultStream::error_fd());
2544
for (i = 0; i < 78; i++) err.print_raw("=");
2545
err.cr();
2546
err.print_raw_cr(title);
2547
for (i = 0; i < 78; i++) err.print_raw("-");
2548
err.cr();
2549
err.print_raw_cr(message);
2550
for (i = 0; i < 78; i++) err.print_raw("=");
2551
err.cr();
2552
2553
char buf[16];
2554
// Prevent process from exiting upon "read error" without consuming all CPU
2555
while (::read(0, buf, sizeof(buf)) <= 0) { ::sleep(100); }
2556
2557
return buf[0] == 'y' || buf[0] == 'Y';
2558
}
2559
2560
// This code originates from JDK's sysOpen and open64_w
2561
// from src/solaris/hpi/src/system_md.c
2562
2563
int os::open(const char *path, int oflag, int mode) {
2564
2565
if (strlen(path) > MAX_PATH - 1) {
2566
errno = ENAMETOOLONG;
2567
return -1;
2568
}
2569
// AIX 7.X now supports O_CLOEXEC too, like modern Linux; but we have to be careful, see
2570
// IV90804: OPENING A FILE IN AFS WITH O_CLOEXEC FAILS WITH AN EINVAL ERROR APPLIES TO AIX 7100-04 17/04/14 PTF PECHANGE
2571
int oflag_with_o_cloexec = oflag | O_CLOEXEC;
2572
2573
int fd = ::open64(path, oflag_with_o_cloexec, mode);
2574
if (fd == -1) {
2575
// we might fail in the open call when O_CLOEXEC is set, so try again without (see IV90804)
2576
fd = ::open64(path, oflag, mode);
2577
if (fd == -1) {
2578
return -1;
2579
}
2580
}
2581
2582
// If the open succeeded, the file might still be a directory.
2583
{
2584
struct stat64 buf64;
2585
int ret = ::fstat64(fd, &buf64);
2586
int st_mode = buf64.st_mode;
2587
2588
if (ret != -1) {
2589
if ((st_mode & S_IFMT) == S_IFDIR) {
2590
errno = EISDIR;
2591
::close(fd);
2592
return -1;
2593
}
2594
} else {
2595
::close(fd);
2596
return -1;
2597
}
2598
}
2599
2600
// All file descriptors that are opened in the JVM and not
2601
// specifically destined for a subprocess should have the
2602
// close-on-exec flag set. If we don't set it, then careless 3rd
2603
// party native code might fork and exec without closing all
2604
// appropriate file descriptors (e.g. as we do in closeDescriptors in
2605
// UNIXProcess.c), and this in turn might:
2606
//
2607
// - cause end-of-file to fail to be detected on some file
2608
// descriptors, resulting in mysterious hangs, or
2609
//
2610
// - might cause an fopen in the subprocess to fail on a system
2611
// suffering from bug 1085341.
2612
2613
// Validate that the use of the O_CLOEXEC flag on open above worked.
2614
static sig_atomic_t O_CLOEXEC_is_known_to_work = 0;
2615
if (O_CLOEXEC_is_known_to_work == 0) {
2616
int flags = ::fcntl(fd, F_GETFD);
2617
if (flags != -1) {
2618
if ((flags & FD_CLOEXEC) != 0) {
2619
O_CLOEXEC_is_known_to_work = 1;
2620
} else { // it does not work
2621
::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
2622
O_CLOEXEC_is_known_to_work = -1;
2623
}
2624
}
2625
} else if (O_CLOEXEC_is_known_to_work == -1) {
2626
int flags = ::fcntl(fd, F_GETFD);
2627
if (flags != -1) {
2628
::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
2629
}
2630
}
2631
2632
return fd;
2633
}
2634
2635
// create binary file, rewriting existing file if required
2636
int os::create_binary_file(const char* path, bool rewrite_existing) {
2637
int oflags = O_WRONLY | O_CREAT;
2638
oflags |= rewrite_existing ? O_TRUNC : O_EXCL;
2639
return ::open64(path, oflags, S_IREAD | S_IWRITE);
2640
}
2641
2642
// return current position of file pointer
2643
jlong os::current_file_offset(int fd) {
2644
return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR);
2645
}
2646
2647
// move file pointer to the specified offset
2648
jlong os::seek_to_file_offset(int fd, jlong offset) {
2649
return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET);
2650
}
2651
2652
// This code originates from JDK's sysAvailable
2653
// from src/solaris/hpi/src/native_threads/src/sys_api_td.c
2654
2655
int os::available(int fd, jlong *bytes) {
2656
jlong cur, end;
2657
int mode;
2658
struct stat64 buf64;
2659
2660
if (::fstat64(fd, &buf64) >= 0) {
2661
mode = buf64.st_mode;
2662
if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
2663
int n;
2664
if (::ioctl(fd, FIONREAD, &n) >= 0) {
2665
*bytes = n;
2666
return 1;
2667
}
2668
}
2669
}
2670
if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) {
2671
return 0;
2672
} else if ((end = ::lseek64(fd, 0L, SEEK_END)) == -1) {
2673
return 0;
2674
} else if (::lseek64(fd, cur, SEEK_SET) == -1) {
2675
return 0;
2676
}
2677
*bytes = end - cur;
2678
return 1;
2679
}
2680
2681
// Map a block of memory.
2682
char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
2683
char *addr, size_t bytes, bool read_only,
2684
bool allow_exec) {
2685
int prot;
2686
int flags = MAP_PRIVATE;
2687
2688
if (read_only) {
2689
prot = PROT_READ;
2690
flags = MAP_SHARED;
2691
} else {
2692
prot = PROT_READ | PROT_WRITE;
2693
flags = MAP_PRIVATE;
2694
}
2695
2696
if (allow_exec) {
2697
prot |= PROT_EXEC;
2698
}
2699
2700
if (addr != NULL) {
2701
flags |= MAP_FIXED;
2702
}
2703
2704
// Allow anonymous mappings if 'fd' is -1.
2705
if (fd == -1) {
2706
flags |= MAP_ANONYMOUS;
2707
}
2708
2709
char* mapped_address = (char*)::mmap(addr, (size_t)bytes, prot, flags,
2710
fd, file_offset);
2711
if (mapped_address == MAP_FAILED) {
2712
return NULL;
2713
}
2714
return mapped_address;
2715
}
2716
2717
// Remap a block of memory.
2718
char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset,
2719
char *addr, size_t bytes, bool read_only,
2720
bool allow_exec) {
2721
// same as map_memory() on this OS
2722
return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only,
2723
allow_exec);
2724
}
2725
2726
// Unmap a block of memory.
2727
bool os::pd_unmap_memory(char* addr, size_t bytes) {
2728
return munmap(addr, bytes) == 0;
2729
}
2730
2731
// current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool)
2732
// are used by JVM M&M and JVMTI to get user+sys or user CPU time
2733
// of a thread.
2734
//
2735
// current_thread_cpu_time() and thread_cpu_time(Thread*) returns
2736
// the fast estimate available on the platform.
2737
2738
jlong os::current_thread_cpu_time() {
2739
// return user + sys since the cost is the same
2740
const jlong n = os::thread_cpu_time(Thread::current(), true /* user + sys */);
2741
assert(n >= 0, "negative CPU time");
2742
return n;
2743
}
2744
2745
jlong os::thread_cpu_time(Thread* thread) {
2746
// consistent with what current_thread_cpu_time() returns
2747
const jlong n = os::thread_cpu_time(thread, true /* user + sys */);
2748
assert(n >= 0, "negative CPU time");
2749
return n;
2750
}
2751
2752
jlong os::current_thread_cpu_time(bool user_sys_cpu_time) {
2753
const jlong n = os::thread_cpu_time(Thread::current(), user_sys_cpu_time);
2754
assert(n >= 0, "negative CPU time");
2755
return n;
2756
}
2757
2758
static bool thread_cpu_time_unchecked(Thread* thread, jlong* p_sys_time, jlong* p_user_time) {
2759
bool error = false;
2760
2761
jlong sys_time = 0;
2762
jlong user_time = 0;
2763
2764
// Reimplemented using getthrds64().
2765
//
2766
// Works like this:
2767
// For the thread in question, get the kernel thread id. Then get the
2768
// kernel thread statistics using that id.
2769
//
2770
// This only works of course when no pthread scheduling is used,
2771
// i.e. there is a 1:1 relationship to kernel threads.
2772
// On AIX, see AIXTHREAD_SCOPE variable.
2773
2774
pthread_t pthtid = thread->osthread()->pthread_id();
2775
2776
// retrieve kernel thread id for the pthread:
2777
tid64_t tid = 0;
2778
struct __pthrdsinfo pinfo;
2779
// I just love those otherworldly IBM APIs which force me to hand down
2780
// dummy buffers for stuff I dont care for...
2781
char dummy[1];
2782
int dummy_size = sizeof(dummy);
2783
if (pthread_getthrds_np(&pthtid, PTHRDSINFO_QUERY_TID, &pinfo, sizeof(pinfo),
2784
dummy, &dummy_size) == 0) {
2785
tid = pinfo.__pi_tid;
2786
} else {
2787
tty->print_cr("pthread_getthrds_np failed.");
2788
error = true;
2789
}
2790
2791
// retrieve kernel timing info for that kernel thread
2792
if (!error) {
2793
struct thrdentry64 thrdentry;
2794
if (getthrds64(getpid(), &thrdentry, sizeof(thrdentry), &tid, 1) == 1) {
2795
sys_time = thrdentry.ti_ru.ru_stime.tv_sec * 1000000000LL + thrdentry.ti_ru.ru_stime.tv_usec * 1000LL;
2796
user_time = thrdentry.ti_ru.ru_utime.tv_sec * 1000000000LL + thrdentry.ti_ru.ru_utime.tv_usec * 1000LL;
2797
} else {
2798
tty->print_cr("pthread_getthrds_np failed.");
2799
error = true;
2800
}
2801
}
2802
2803
if (p_sys_time) {
2804
*p_sys_time = sys_time;
2805
}
2806
2807
if (p_user_time) {
2808
*p_user_time = user_time;
2809
}
2810
2811
if (error) {
2812
return false;
2813
}
2814
2815
return true;
2816
}
2817
2818
jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
2819
jlong sys_time;
2820
jlong user_time;
2821
2822
if (!thread_cpu_time_unchecked(thread, &sys_time, &user_time)) {
2823
return -1;
2824
}
2825
2826
return user_sys_cpu_time ? sys_time + user_time : user_time;
2827
}
2828
2829
void os::current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
2830
info_ptr->max_value = ALL_64_BITS; // will not wrap in less than 64 bits
2831
info_ptr->may_skip_backward = false; // elapsed time not wall time
2832
info_ptr->may_skip_forward = false; // elapsed time not wall time
2833
info_ptr->kind = JVMTI_TIMER_TOTAL_CPU; // user+system time is returned
2834
}
2835
2836
void os::thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
2837
info_ptr->max_value = ALL_64_BITS; // will not wrap in less than 64 bits
2838
info_ptr->may_skip_backward = false; // elapsed time not wall time
2839
info_ptr->may_skip_forward = false; // elapsed time not wall time
2840
info_ptr->kind = JVMTI_TIMER_TOTAL_CPU; // user+system time is returned
2841
}
2842
2843
bool os::is_thread_cpu_time_supported() {
2844
return true;
2845
}
2846
2847
// System loadavg support. Returns -1 if load average cannot be obtained.
2848
// For now just return the system wide load average (no processor sets).
2849
int os::loadavg(double values[], int nelem) {
2850
2851
guarantee(nelem >= 0 && nelem <= 3, "argument error");
2852
guarantee(values, "argument error");
2853
2854
if (os::Aix::on_pase()) {
2855
2856
// AS/400 PASE: use libo4 porting library
2857
double v[3] = { 0.0, 0.0, 0.0 };
2858
2859
if (libo4::get_load_avg(v, v + 1, v + 2)) {
2860
for (int i = 0; i < nelem; i ++) {
2861
values[i] = v[i];
2862
}
2863
return nelem;
2864
} else {
2865
return -1;
2866
}
2867
2868
} else {
2869
2870
// AIX: use libperfstat
2871
libperfstat::cpuinfo_t ci;
2872
if (libperfstat::get_cpuinfo(&ci)) {
2873
for (int i = 0; i < nelem; i++) {
2874
values[i] = ci.loadavg[i];
2875
}
2876
} else {
2877
return -1;
2878
}
2879
return nelem;
2880
}
2881
}
2882
2883
void os::pause() {
2884
char filename[MAX_PATH];
2885
if (PauseAtStartupFile && PauseAtStartupFile[0]) {
2886
jio_snprintf(filename, MAX_PATH, "%s", PauseAtStartupFile);
2887
} else {
2888
jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id());
2889
}
2890
2891
int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
2892
if (fd != -1) {
2893
struct stat buf;
2894
::close(fd);
2895
while (::stat(filename, &buf) == 0) {
2896
(void)::poll(NULL, 0, 100);
2897
}
2898
} else {
2899
trcVerbose("Could not open pause file '%s', continuing immediately.", filename);
2900
}
2901
}
2902
2903
bool os::is_primordial_thread(void) {
2904
if (pthread_self() == (pthread_t)1) {
2905
return true;
2906
} else {
2907
return false;
2908
}
2909
}
2910
2911
// OS recognitions (PASE/AIX, OS level) call this before calling any
2912
// one of Aix::on_pase(), Aix::os_version() static
2913
void os::Aix::initialize_os_info() {
2914
2915
assert(_on_pase == -1 && _os_version == 0, "already called.");
2916
2917
struct utsname uts;
2918
memset(&uts, 0, sizeof(uts));
2919
strcpy(uts.sysname, "?");
2920
if (::uname(&uts) == -1) {
2921
trcVerbose("uname failed (%d)", errno);
2922
guarantee(0, "Could not determine whether we run on AIX or PASE");
2923
} else {
2924
trcVerbose("uname says: sysname \"%s\" version \"%s\" release \"%s\" "
2925
"node \"%s\" machine \"%s\"\n",
2926
uts.sysname, uts.version, uts.release, uts.nodename, uts.machine);
2927
const int major = atoi(uts.version);
2928
assert(major > 0, "invalid OS version");
2929
const int minor = atoi(uts.release);
2930
assert(minor > 0, "invalid OS release");
2931
_os_version = (major << 24) | (minor << 16);
2932
char ver_str[20] = {0};
2933
const char* name_str = "unknown OS";
2934
if (strcmp(uts.sysname, "OS400") == 0) {
2935
// We run on AS/400 PASE. We do not support versions older than V5R4M0.
2936
_on_pase = 1;
2937
if (os_version_short() < 0x0504) {
2938
trcVerbose("OS/400 releases older than V5R4M0 not supported.");
2939
assert(false, "OS/400 release too old.");
2940
}
2941
name_str = "OS/400 (pase)";
2942
jio_snprintf(ver_str, sizeof(ver_str), "%u.%u", major, minor);
2943
} else if (strcmp(uts.sysname, "AIX") == 0) {
2944
// We run on AIX. We do not support versions older than AIX 7.1.
2945
_on_pase = 0;
2946
// Determine detailed AIX version: Version, Release, Modification, Fix Level.
2947
odmWrapper::determine_os_kernel_version(&_os_version);
2948
if (os_version_short() < 0x0701) {
2949
trcVerbose("AIX releases older than AIX 7.1 are not supported.");
2950
assert(false, "AIX release too old.");
2951
}
2952
name_str = "AIX";
2953
jio_snprintf(ver_str, sizeof(ver_str), "%u.%u.%u.%u",
2954
major, minor, (_os_version >> 8) & 0xFF, _os_version & 0xFF);
2955
} else {
2956
assert(false, "%s", name_str);
2957
}
2958
trcVerbose("We run on %s %s", name_str, ver_str);
2959
}
2960
2961
guarantee(_on_pase != -1 && _os_version, "Could not determine AIX/OS400 release");
2962
} // end: os::Aix::initialize_os_info()
2963
2964
// Scan environment for important settings which might effect the VM.
2965
// Trace out settings. Warn about invalid settings and/or correct them.
2966
//
2967
// Must run after os::Aix::initialue_os_info().
2968
void os::Aix::scan_environment() {
2969
2970
char* p;
2971
int rc;
2972
2973
// Warn explicity if EXTSHM=ON is used. That switch changes how
2974
// System V shared memory behaves. One effect is that page size of
2975
// shared memory cannot be change dynamically, effectivly preventing
2976
// large pages from working.
2977
// This switch was needed on AIX 32bit, but on AIX 64bit the general
2978
// recommendation is (in OSS notes) to switch it off.
2979
p = ::getenv("EXTSHM");
2980
trcVerbose("EXTSHM=%s.", p ? p : "<unset>");
2981
if (p && strcasecmp(p, "ON") == 0) {
2982
_extshm = 1;
2983
trcVerbose("*** Unsupported mode! Please remove EXTSHM from your environment! ***");
2984
if (!AllowExtshm) {
2985
// We allow under certain conditions the user to continue. However, we want this
2986
// to be a fatal error by default. On certain AIX systems, leaving EXTSHM=ON means
2987
// that the VM is not able to allocate 64k pages for the heap.
2988
// We do not want to run with reduced performance.
2989
vm_exit_during_initialization("EXTSHM is ON. Please remove EXTSHM from your environment.");
2990
}
2991
} else {
2992
_extshm = 0;
2993
}
2994
2995
// SPEC1170 behaviour: will change the behaviour of a number of POSIX APIs.
2996
// Not tested, not supported.
2997
//
2998
// Note that it might be worth the trouble to test and to require it, if only to
2999
// get useful return codes for mprotect.
3000
//
3001
// Note: Setting XPG_SUS_ENV in the process is too late. Must be set earlier (before
3002
// exec() ? before loading the libjvm ? ....)
3003
p = ::getenv("XPG_SUS_ENV");
3004
trcVerbose("XPG_SUS_ENV=%s.", p ? p : "<unset>");
3005
if (p && strcmp(p, "ON") == 0) {
3006
_xpg_sus_mode = 1;
3007
trcVerbose("Unsupported setting: XPG_SUS_ENV=ON");
3008
// This is not supported. Worst of all, it changes behaviour of mmap MAP_FIXED to
3009
// clobber address ranges. If we ever want to support that, we have to do some
3010
// testing first.
3011
guarantee(false, "XPG_SUS_ENV=ON not supported");
3012
} else {
3013
_xpg_sus_mode = 0;
3014
}
3015
3016
if (os::Aix::on_pase()) {
3017
p = ::getenv("QIBM_MULTI_THREADED");
3018
trcVerbose("QIBM_MULTI_THREADED=%s.", p ? p : "<unset>");
3019
}
3020
3021
p = ::getenv("LDR_CNTRL");
3022
trcVerbose("LDR_CNTRL=%s.", p ? p : "<unset>");
3023
if (os::Aix::on_pase() && os::Aix::os_version_short() == 0x0701) {
3024
if (p && ::strstr(p, "TEXTPSIZE")) {
3025
trcVerbose("*** WARNING - LDR_CNTRL contains TEXTPSIZE. "
3026
"you may experience hangs or crashes on OS/400 V7R1.");
3027
}
3028
}
3029
3030
p = ::getenv("AIXTHREAD_GUARDPAGES");
3031
trcVerbose("AIXTHREAD_GUARDPAGES=%s.", p ? p : "<unset>");
3032
3033
} // end: os::Aix::scan_environment()
3034
3035
// PASE: initialize the libo4 library (PASE porting library).
3036
void os::Aix::initialize_libo4() {
3037
guarantee(os::Aix::on_pase(), "OS/400 only.");
3038
if (!libo4::init()) {
3039
trcVerbose("libo4 initialization failed.");
3040
assert(false, "libo4 initialization failed");
3041
} else {
3042
trcVerbose("libo4 initialized.");
3043
}
3044
}
3045
3046
// AIX: initialize the libperfstat library.
3047
void os::Aix::initialize_libperfstat() {
3048
assert(os::Aix::on_aix(), "AIX only");
3049
if (!libperfstat::init()) {
3050
trcVerbose("libperfstat initialization failed.");
3051
assert(false, "libperfstat initialization failed");
3052
} else {
3053
trcVerbose("libperfstat initialized.");
3054
}
3055
}
3056
3057
/////////////////////////////////////////////////////////////////////////////
3058
// thread stack
3059
3060
// Get the current stack base from the OS (actually, the pthread library).
3061
// Note: usually not page aligned.
3062
address os::current_stack_base() {
3063
AixMisc::stackbounds_t bounds;
3064
bool rc = AixMisc::query_stack_bounds_for_current_thread(&bounds);
3065
guarantee(rc, "Unable to retrieve stack bounds.");
3066
return bounds.base;
3067
}
3068
3069
// Get the current stack size from the OS (actually, the pthread library).
3070
// Returned size is such that (base - size) is always aligned to page size.
3071
size_t os::current_stack_size() {
3072
AixMisc::stackbounds_t bounds;
3073
bool rc = AixMisc::query_stack_bounds_for_current_thread(&bounds);
3074
guarantee(rc, "Unable to retrieve stack bounds.");
3075
// Align the returned stack size such that the stack low address
3076
// is aligned to page size (Note: base is usually not and we do not care).
3077
// We need to do this because caller code will assume stack low address is
3078
// page aligned and will place guard pages without checking.
3079
address low = bounds.base - bounds.size;
3080
address low_aligned = (address)align_up(low, os::vm_page_size());
3081
size_t s = bounds.base - low_aligned;
3082
return s;
3083
}
3084
3085
// Get the default path to the core file
3086
// Returns the length of the string
3087
int os::get_core_path(char* buffer, size_t bufferSize) {
3088
const char* p = get_current_directory(buffer, bufferSize);
3089
3090
if (p == NULL) {
3091
assert(p != NULL, "failed to get current directory");
3092
return 0;
3093
}
3094
3095
jio_snprintf(buffer, bufferSize, "%s/core or core.%d",
3096
p, current_process_id());
3097
3098
return strlen(buffer);
3099
}
3100
3101
bool os::start_debugging(char *buf, int buflen) {
3102
int len = (int)strlen(buf);
3103
char *p = &buf[len];
3104
3105
jio_snprintf(p, buflen -len,
3106
"\n\n"
3107
"Do you want to debug the problem?\n\n"
3108
"To debug, run 'dbx -a %d'; then switch to thread tid " INTX_FORMAT ", k-tid " INTX_FORMAT "\n"
3109
"Enter 'yes' to launch dbx automatically (PATH must include dbx)\n"
3110
"Otherwise, press RETURN to abort...",
3111
os::current_process_id(),
3112
os::current_thread_id(), thread_self());
3113
3114
bool yes = os::message_box("Unexpected Error", buf);
3115
3116
if (yes) {
3117
// yes, user asked VM to launch debugger
3118
jio_snprintf(buf, buflen, "dbx -a %d", os::current_process_id());
3119
3120
os::fork_and_exec(buf);
3121
yes = false;
3122
}
3123
return yes;
3124
}
3125
3126
static inline time_t get_mtime(const char* filename) {
3127
struct stat st;
3128
int ret = os::stat(filename, &st);
3129
assert(ret == 0, "failed to stat() file '%s': %s", filename, os::strerror(errno));
3130
return st.st_mtime;
3131
}
3132
3133
int os::compare_file_modified_times(const char* file1, const char* file2) {
3134
time_t t1 = get_mtime(file1);
3135
time_t t2 = get_mtime(file2);
3136
return t1 - t2;
3137
}
3138
3139
bool os::supports_map_sync() {
3140
return false;
3141
}
3142
3143
void os::print_memory_mappings(char* addr, size_t bytes, outputStream* st) {}
3144
3145