107 #include <sys/vminfo.h>
108 #include <sys/wait.h>
109
110 // If RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling
111 // getrusage() is prepared to handle the associated failure.
112 #ifndef RUSAGE_THREAD
113 #define RUSAGE_THREAD (1) /* only the calling thread */
114 #endif
115
116 // Add missing declarations (should be in procinfo.h but isn't until AIX 6.1).
117 #if !defined(_AIXVERSION_610)
118 extern "C" {
119 int getthrds64(pid_t ProcessIdentifier,
120 struct thrdentry64* ThreadBuffer,
121 int ThreadSize,
122 tid64_t* IndexPointer,
123 int Count);
124 }
125 #endif
126
127 // Excerpts from systemcfg.h definitions newer than AIX 5.3
128 #ifndef PV_7
129 # define PV_7 0x200000 // Power PC 7
130 # define PV_7_Compat 0x208000 // Power PC 7
131 #endif
132
133 #define MAX_PATH (2 * K)
134
135 // for timer info max values which include all bits
136 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
137 // for multipage initialization error analysis (in 'g_multipage_error')
138 #define ERROR_MP_OS_TOO_OLD 100
139 #define ERROR_MP_EXTSHM_ACTIVE 101
140 #define ERROR_MP_VMGETINFO_FAILED 102
141 #define ERROR_MP_VMGETINFO_CLAIMS_NO_SUPPORT_FOR_64K 103
142
143 // the semantics in this file are thus that codeptr_t is a *real code ptr*
144 // This means that any function taking codeptr_t as arguments will assume
145 // a real codeptr and won't handle function descriptors (eg getFuncName),
146 // whereas functions taking address as args will deal with function
147 // descriptors (eg os::dll_address_to_library_name)
148 typedef unsigned int* codeptr_t;
149
150 // typedefs for stackslots, stack pointers, pointers to op codes
151 typedef unsigned long stackslot_t;
152 typedef stackslot_t* stackptr_t;
153
154 // query dimensions of the stack of the calling thread
155 static void query_stack_dimensions(address* p_stack_base, size_t* p_stack_size);
156
157 // function to check a given stack pointer against given stack limits
158 inline bool is_valid_stackpointer(stackptr_t sp, stackptr_t stack_base, size_t stack_size) {
159 if (((uintptr_t)sp) & 0x7) {
160 return false;
161 }
162 if (sp > stack_base) {
163 return false;
164 }
165 if (sp < (stackptr_t) ((address)stack_base - stack_size)) {
166 return false;
167 }
168 return true;
169 }
170
171 // returns true if function is a valid codepointer
172 inline bool is_valid_codepointer(codeptr_t p) {
173 if (!p) {
174 return false;
175 }
176 if (((uintptr_t)p) & 0x3) {
177 return false;
178 }
179 if (LoadedLibraries::find_for_text_address((address)p) == NULL) {
180 return false;
181 }
182 return true;
183 }
184
185 // macro to check a given stack pointer against given stack limits and to die if test fails
186 #define CHECK_STACK_PTR(sp, stack_base, stack_size) { \
187 guarantee(is_valid_stackpointer((stackptr_t)(sp), (stackptr_t)(stack_base), stack_size), "Stack Pointer Invalid"); \
188 }
189
190 // macro to check the current stack pointer against given stacklimits
191 #define CHECK_CURRENT_STACK_PTR(stack_base, stack_size) { \
192 address sp; \
193 sp = os::current_stack_pointer(); \
194 CHECK_STACK_PTR(sp, stack_base, stack_size); \
195 }
196
197 ////////////////////////////////////////////////////////////////////////////////
198 // global variables (for a description see os_aix.hpp)
199
200 julong os::Aix::_physical_memory = 0;
201 pthread_t os::Aix::_main_thread = ((pthread_t)0);
202 int os::Aix::_page_size = -1;
203 int os::Aix::_on_pase = -1;
204 int os::Aix::_os_version = -1;
205 int os::Aix::_stack_page_size = -1;
206 size_t os::Aix::_shm_default_page_size = -1;
207 int os::Aix::_can_use_64K_pages = -1;
208 int os::Aix::_can_use_16M_pages = -1;
209 int os::Aix::_xpg_sus_mode = -1;
210 int os::Aix::_extshm = -1;
211 int os::Aix::_logical_cpus = -1;
212
213 ////////////////////////////////////////////////////////////////////////////////
214 // local variables
215
216 static int g_multipage_error = -1; // error analysis for multipage initialization
217 static jlong initial_time_count = 0;
218 static int clock_tics_per_sec = 100;
219 static sigset_t check_signal_done; // For diagnostics to print a message once (see run_periodic_checks)
220 static bool check_signals = true;
221 static pid_t _initial_pid = 0;
222 static int SR_signum = SIGUSR2; // Signal used to suspend/resume a thread (must be > SIGSEGV, see 4355769)
223 static sigset_t SR_sigset;
224 static pthread_mutex_t dl_mutex; // Used to protect dlsym() calls */
225
226 julong os::available_memory() {
227 return Aix::available_memory();
228 }
229
230 julong os::Aix::available_memory() {
231 os::Aix::meminfo_t mi;
232 if (os::Aix::get_meminfo(&mi)) {
233 return mi.real_free;
234 } else {
235 return 0xFFFFFFFFFFFFFFFFLL;
236 }
237 }
238
239 julong os::physical_memory() {
240 return Aix::physical_memory();
241 }
242
243 ////////////////////////////////////////////////////////////////////////////////
244 // environment support
245
246 bool os::getenv(const char* name, char* buf, int len) {
247 const char* val = ::getenv(name);
248 if (val != NULL && strlen(val) < (size_t)len) {
249 strcpy(buf, val);
250 return true;
251 }
252 if (len > 0) buf[0] = 0; // return a null string
253 return false;
254 }
255
256
257 // Return true if user is running as root.
258
259 bool os::have_special_privileges() {
260 static bool init = false;
261 static bool privileges = false;
262 if (!init) {
263 privileges = (getuid() != geteuid()) || (getgid() != getegid());
264 init = true;
265 }
266 return privileges;
267 }
268
269 // Helper function, emulates disclaim64 using multiple 32bit disclaims
270 // because we cannot use disclaim64() on AS/400 and old AIX releases.
271 static bool my_disclaim64(char* addr, size_t size) {
272
273 if (size == 0) {
274 return true;
275 }
276
277 // Maximum size 32bit disclaim() accepts. (Theoretically 4GB, but I just do not trust that.)
278 const unsigned int maxDisclaimSize = 0x80000000;
279
280 const unsigned int numFullDisclaimsNeeded = (size / maxDisclaimSize);
281 const unsigned int lastDisclaimSize = (size % maxDisclaimSize);
282
283 char* p = addr;
284
285 for (int i = 0; i < numFullDisclaimsNeeded; i ++) {
286 if (::disclaim(p, maxDisclaimSize, DISCLAIM_ZEROMEM) != 0) {
287 //if (Verbose)
288 fprintf(stderr, "Cannot disclaim %p - %p (errno %d)\n", p, p + maxDisclaimSize, errno);
289 return false;
290 }
291 p += maxDisclaimSize;
292 }
293
294 if (lastDisclaimSize > 0) {
295 if (::disclaim(p, lastDisclaimSize, DISCLAIM_ZEROMEM) != 0) {
296 //if (Verbose)
297 fprintf(stderr, "Cannot disclaim %p - %p (errno %d)\n", p, p + lastDisclaimSize, errno);
298 return false;
299 }
300 }
301
302 return true;
303 }
304
305 // Cpu architecture string
306 #if defined(PPC32)
307 static char cpu_arch[] = "ppc";
308 #elif defined(PPC64)
309 static char cpu_arch[] = "ppc64";
310 #else
311 #error Add appropriate cpu_arch setting
312 #endif
313
314
315 // Given an address, returns the size of the page backing that address.
316 size_t os::Aix::query_pagesize(void* addr) {
317
318 vm_page_info pi;
319 pi.addr = (uint64_t)addr;
320 if (::vmgetinfo(&pi, VM_PAGE_INFO, sizeof(pi)) == 0) {
321 return pi.pagesize;
322 } else {
323 fprintf(stderr, "vmgetinfo failed to retrieve page size for address %p (errno %d).\n", addr, errno);
324 assert(false, "vmgetinfo failed to retrieve page size");
325 return SIZE_4K;
326 }
327
328 }
329
330 // Returns the kernel thread id of the currently running thread.
331 pid_t os::Aix::gettid() {
332 return (pid_t) thread_self();
333 }
334
335 void os::Aix::initialize_system_info() {
336
337 // get the number of online(logical) cpus instead of configured
338 os::_processor_count = sysconf(_SC_NPROCESSORS_ONLN);
339 assert(_processor_count > 0, "_processor_count must be > 0");
340
341 // retrieve total physical storage
342 os::Aix::meminfo_t mi;
343 if (!os::Aix::get_meminfo(&mi)) {
344 fprintf(stderr, "os::Aix::get_meminfo failed.\n"); fflush(stderr);
345 assert(false, "os::Aix::get_meminfo failed.");
346 }
347 _physical_memory = (julong) mi.real_total;
348 }
349
350 // Helper function for tracing page sizes.
351 static const char* describe_pagesize(size_t pagesize) {
352 switch (pagesize) {
353 case SIZE_4K : return "4K";
354 case SIZE_64K: return "64K";
355 case SIZE_16M: return "16M";
356 case SIZE_16G: return "16G";
357 default:
358 assert(false, "surprise");
359 return "??";
360 }
361 }
496 guarantee(_page_size != -1 &&
497 _stack_page_size != -1 &&
498 _can_use_64K_pages != -1 &&
499 _can_use_16M_pages != -1, "Page sizes not properly initialized");
500
501 if (_can_use_64K_pages) {
502 g_multipage_error = 0;
503 }
504
505 if (Verbose) {
506 fprintf(stderr, "Data page size (C-Heap, bss, etc): %s\n", describe_pagesize(data_page_size));
507 fprintf(stderr, "Thread stack page size (pthread): %s\n", describe_pagesize(_stack_page_size));
508 fprintf(stderr, "Default shared memory page size: %s\n", describe_pagesize(_shm_default_page_size));
509 fprintf(stderr, "Can use 64K pages dynamically with shared meory: %s\n", (_can_use_64K_pages ? "yes" :"no"));
510 fprintf(stderr, "Can use 16M pages dynamically with shared memory: %s\n", (_can_use_16M_pages ? "yes" :"no"));
511 fprintf(stderr, "Multipage error details: %d\n", g_multipage_error);
512 }
513
514 } // end os::Aix::query_multipage_support()
515
516 // The code for this method was initially derived from the version in os_linux.cpp.
517 void os::init_system_properties_values() {
518
519 #define DEFAULT_LIBPATH "/usr/lib:/lib"
520 #define EXTENSIONS_DIR "/lib/ext"
521 #define ENDORSED_DIR "/lib/endorsed"
522
523 // Buffer that fits several sprintfs.
524 // Note that the space for the trailing null is provided
525 // by the nulls included by the sizeof operator.
526 const size_t bufsize =
527 MAX3((size_t)MAXPATHLEN, // For dll_dir & friends.
528 (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR), // extensions dir
529 (size_t)MAXPATHLEN + sizeof(ENDORSED_DIR)); // endorsed dir
530 char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
531
532 // sysclasspath, java_home, dll_dir
533 {
534 char *pslash;
535 os::jvm_path(buf, bufsize);
536
593
594 void os::breakpoint() {
595 BREAKPOINT;
596 }
597
598 extern "C" void breakpoint() {
599 // use debugger to set breakpoint here
600 }
601
602 ////////////////////////////////////////////////////////////////////////////////
603 // signal support
604
605 debug_only(static bool signal_sets_initialized = false);
606 static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs;
607
608 bool os::Aix::is_sig_ignored(int sig) {
609 struct sigaction oact;
610 sigaction(sig, (struct sigaction*)NULL, &oact);
611 void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*, oact.sa_sigaction)
612 : CAST_FROM_FN_PTR(void*, oact.sa_handler);
613 if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN))
614 return true;
615 else
616 return false;
617 }
618
619 void os::Aix::signal_sets_init() {
620 // Should also have an assertion stating we are still single-threaded.
621 assert(!signal_sets_initialized, "Already initialized");
622 // Fill in signals that are necessarily unblocked for all threads in
623 // the VM. Currently, we unblock the following signals:
624 // SHUTDOWN{1,2,3}_SIGNAL: for shutdown hooks support (unless over-ridden
625 // by -Xrs (=ReduceSignalUsage));
626 // BREAK_SIGNAL which is unblocked only by the VM thread and blocked by all
627 // other threads. The "ReduceSignalUsage" boolean tells us not to alter
628 // the dispositions or masks wrt these signals.
629 // Programs embedding the VM that want to use the above signals for their
630 // own purposes must, at this time, use the "-Xrs" option to prevent
631 // interference with shutdown hooks and BREAK_SIGNAL thread dumping.
632 // (See bug 4345157, and other related bugs).
633 // In reality, though, unblocking these signals is really a nop, since
634 // these signals are not blocked by default.
635 sigemptyset(&unblocked_sigs);
636 sigemptyset(&allowdebug_blocked_sigs);
770 perfstat_cpu_total_t psct;
771 memset (&psct, '\0', sizeof(psct));
772
773 if (-1 == libperfstat::perfstat_cpu_total(NULL, &psct, sizeof(perfstat_cpu_total_t), 1)) {
774 fprintf(stderr, "perfstat_cpu_total() failed (errno=%d)\n", errno);
775 assert(0, "perfstat_cpu_total() failed");
776 return false;
777 }
778
779 // global cpu information
780 strcpy (pci->description, psct.description);
781 pci->processorHZ = psct.processorHZ;
782 pci->ncpus = psct.ncpus;
783 os::Aix::_logical_cpus = psct.ncpus;
784 for (int i = 0; i < 3; i++) {
785 pci->loadavg[i] = (double) psct.loadavg[i] / (1 << SBITS);
786 }
787
788 // get the processor version from _system_configuration
789 switch (_system_configuration.version) {
790 case PV_7:
791 strcpy(pci->version, "Power PC 7");
792 break;
793 case PV_6_1:
794 strcpy(pci->version, "Power PC 6 DD1.x");
795 break;
796 case PV_6:
797 strcpy(pci->version, "Power PC 6");
798 break;
799 case PV_5:
800 strcpy(pci->version, "Power PC 5");
801 break;
802 case PV_5_2:
803 strcpy(pci->version, "Power PC 5_2");
804 break;
805 case PV_5_3:
806 strcpy(pci->version, "Power PC 5_3");
807 break;
808 case PV_5_Compat:
809 strcpy(pci->version, "PV_5_Compat");
810 break;
811 case PV_6_Compat:
812 strcpy(pci->version, "PV_6_Compat");
813 break;
814 case PV_7_Compat:
815 strcpy(pci->version, "PV_7_Compat");
816 break;
817 default:
818 strcpy(pci->version, "unknown");
819 }
820
821 return true;
822
823 } //end os::Aix::get_cpuinfo
824
825 //////////////////////////////////////////////////////////////////////////////
826 // detecting pthread library
827
828 void os::Aix::libpthread_init() {
829 return;
830 }
831
832 //////////////////////////////////////////////////////////////////////////////
833 // create new thread
834
835 // Thread start routine for all newly created threads
836 static void *java_start(Thread *thread) {
932 } // else fall through:
933 // use VMThreadStackSize if CompilerThreadStackSize is not defined
934 case os::vm_thread:
935 case os::pgc_thread:
936 case os::cgc_thread:
937 case os::watcher_thread:
938 if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K);
939 break;
940 }
941 }
942
943 stack_size = MAX2(stack_size, os::Aix::min_stack_allowed);
944 pthread_attr_setstacksize(&attr, stack_size);
945 } //else let thread_create() pick the default value (96 K on AIX)
946
947 pthread_t tid;
948 int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread);
949
950 pthread_attr_destroy(&attr);
951
952 if (ret != 0) {
953 if (PrintMiscellaneous && (Verbose || WizardMode)) {
954 perror("pthread_create()");
955 }
956 // Need to clean up stuff we've allocated so far
957 thread->set_osthread(NULL);
958 delete osthread;
959 return false;
960 }
961
962 // Store pthread info into the OSThread
963 osthread->set_pthread_id(tid);
964
965 return true;
966 }
967
968 /////////////////////////////////////////////////////////////////////////////
969 // attach existing thread
970
971 // bootstrap the main thread
972 bool os::create_main_thread(JavaThread* thread) {
1093 }
1094 }
1095
1096 jlong os::javaTimeMillis() {
1097 timeval time;
1098 int status = gettimeofday(&time, NULL);
1099 assert(status != -1, "aix error at gettimeofday()");
1100 return jlong(time.tv_sec) * 1000 + jlong(time.tv_usec / 1000);
1101 }
1102
1103 // We need to manually declare mread_real_time,
1104 // because IBM didn't provide a prototype in time.h.
1105 // (they probably only ever tested in C, not C++)
1106 extern "C"
1107 int mread_real_time(timebasestruct_t *t, size_t size_of_timebasestruct_t);
1108
1109 jlong os::javaTimeNanos() {
1110 if (os::Aix::on_pase()) {
1111 Unimplemented();
1112 return 0;
1113 }
1114 else {
1115 // On AIX use the precision of processors real time clock
1116 // or time base registers.
1117 timebasestruct_t time;
1118 int rc;
1119
1120 // If the CPU has a time register, it will be used and
1121 // we have to convert to real time first. After convertion we have following data:
1122 // time.tb_high [seconds since 00:00:00 UTC on 1.1.1970]
1123 // time.tb_low [nanoseconds after the last full second above]
1124 // We better use mread_real_time here instead of read_real_time
1125 // to ensure that we will get a monotonic increasing time.
1126 if (mread_real_time(&time, TIMEBASE_SZ) != RTC_POWER) {
1127 rc = time_base_to_time(&time, TIMEBASE_SZ);
1128 assert(rc != -1, "aix error at time_base_to_time()");
1129 }
1130 return jlong(time.tb_high) * (1000 * 1000 * 1000) + jlong(time.tb_low);
1131 }
1132 }
1133
1134 void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
1142 // Return the real, user, and system times in seconds from an
1143 // arbitrary fixed point in the past.
1144 bool os::getTimesSecs(double* process_real_time,
1145 double* process_user_time,
1146 double* process_system_time) {
1147 struct tms ticks;
1148 clock_t real_ticks = times(&ticks);
1149
1150 if (real_ticks == (clock_t) (-1)) {
1151 return false;
1152 } else {
1153 double ticks_per_second = (double) clock_tics_per_sec;
1154 *process_user_time = ((double) ticks.tms_utime) / ticks_per_second;
1155 *process_system_time = ((double) ticks.tms_stime) / ticks_per_second;
1156 *process_real_time = ((double) real_ticks) / ticks_per_second;
1157
1158 return true;
1159 }
1160 }
1161
1162
1163 char * os::local_time_string(char *buf, size_t buflen) {
1164 struct tm t;
1165 time_t long_time;
1166 time(&long_time);
1167 localtime_r(&long_time, &t);
1168 jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d",
1169 t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
1170 t.tm_hour, t.tm_min, t.tm_sec);
1171 return buf;
1172 }
1173
1174 struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
1175 return localtime_r(clock, res);
1176 }
1177
1178 ////////////////////////////////////////////////////////////////////////////////
1179 // runtime exit support
1180
1181 // Note: os::shutdown() might be called very early during initialization, or
1182 // called from signal handler. Before adding something to os::shutdown(), make
1183 // sure it is async-safe and can handle partially initialized VM.
1184 void os::shutdown() {
1185
1186 // allow PerfMemory to attempt cleanup of any persistent resources
1187 perfMemory_exit();
1188
1189 // needs to remove object in file system
1190 AttachListener::abort();
1191
1192 // flush buffered output, finish log files
1193 ostream_abort();
1194
1195 // Check for abort hook
1196 abort_hook_t abort_hook = Arguments::abort_hook();
1197 if (abort_hook != NULL) {
1198 abort_hook();
1199 }
1200
1201 }
1202
1203 // Note: os::abort() might be called very early during initialization, or
1204 // called from signal handler. Before adding something to os::abort(), make
1205 // sure it is async-safe and can handle partially initialized VM.
1206 void os::abort(bool dump_core) {
1207 os::shutdown();
1208 if (dump_core) {
1209 #ifndef PRODUCT
1210 fdStream out(defaultStream::output_fd());
1211 out.print_raw("Current thread is ");
1212 char buf[16];
1213 jio_snprintf(buf, sizeof(buf), UINTX_FORMAT, os::current_thread_id());
1214 out.print_raw_cr(buf);
1215 out.print_raw_cr("Dumping core ...");
1216 #endif
1217 ::abort(); // dump core
1218 }
1219
1220 ::exit(1);
1221 }
1222
1223 // Die immediately, no exit hook, no abort hook, no cleanup.
1224 void os::die() {
1225 ::abort();
1226 }
1227
1228 // This method is a copy of JDK's sysGetLastErrorString
1229 // from src/solaris/hpi/src/system_md.c
1230
1231 size_t os::lasterror(char *buf, size_t len) {
1232
1233 if (errno == 0) return 0;
1234
1235 const char *s = ::strerror(errno);
1236 size_t n = ::strlen(s);
1237 if (n >= len) {
1238 n = len - 1;
1239 }
1240 ::strncpy(buf, s, n);
1241 buf[n] = '\0';
1242 return n;
1243 }
1244
1245 intx os::current_thread_id() { return (intx)pthread_self(); }
1246 int os::current_process_id() {
1247
1248 // This implementation returns a unique pid, the pid of the
1249 // launcher thread that starts the vm 'process'.
1250
1251 // Under POSIX, getpid() returns the same pid as the
1252 // launcher thread rather than a unique pid per thread.
1253 // Use gettid() if you want the old pre NPTL behaviour.
1254
1255 // if you are looking for the result of a call to getpid() that
1256 // returns a unique pid for the calling thread, then look at the
1257 // OSThread::thread_id() method in osThread_linux.hpp file
1258
1259 return (int)(_initial_pid ? _initial_pid : getpid());
1260 }
1261
1262 // DLL functions
1263
1264 const char* os::dll_file_extension() { return ".so"; }
1265
1362 return p;
1363 } else {
1364 lib = LoadedLibraries::find_for_data_address(p);
1365 if (lib) {
1366 // pointer to data segment, potential function descriptor
1367 address code_entry = (address)(((FunctionDescriptor*)p)->entry());
1368 if (LoadedLibraries::find_for_text_address(code_entry)) {
1369 // Its a function descriptor
1370 return code_entry;
1371 }
1372 }
1373 }
1374 return NULL;
1375 }
1376
1377 bool os::dll_address_to_function_name(address addr, char *buf,
1378 int buflen, int *offset) {
1379 if (offset) {
1380 *offset = -1;
1381 }
1382 if (buf) {
1383 buf[0] = '\0';
1384 }
1385
1386 // Resolve function ptr literals first.
1387 addr = resolve_function_descriptor_to_code_pointer(addr);
1388 if (!addr) {
1389 return false;
1390 }
1391
1392 // Go through Decoder::decode to call getFuncName which reads the name from the traceback table.
1393 return Decoder::decode(addr, buf, buflen, offset);
1394 }
1395
1396 static int getModuleName(codeptr_t pc, // [in] program counter
1397 char* p_name, size_t namelen, // [out] optional: function name
1398 char* p_errmsg, size_t errmsglen // [out] optional: user provided buffer for error messages
1399 ) {
1400
1401 // initialize output parameters
1402 if (p_name && namelen > 0) {
1403 *p_name = '\0';
1404 }
1405 if (p_errmsg && errmsglen > 0) {
1406 *p_errmsg = '\0';
1407 }
1408
1409 const LoadedLibraryModule* const lib = LoadedLibraries::find_for_text_address((address)pc);
1410 if (lib) {
1411 if (p_name && namelen > 0) {
1412 sprintf(p_name, "%.*s", namelen, lib->get_shortname());
1413 }
1414 return 0;
1415 }
1416
1417 if (Verbose) {
1418 fprintf(stderr, "pc outside any module");
1419 }
1420
1421 return -1;
1422
1423 }
1424
1425 bool os::dll_address_to_library_name(address addr, char* buf,
1426 int buflen, int* offset) {
1427 if (offset) {
1428 *offset = -1;
1429 }
1430 if (buf) {
1431 buf[0] = '\0';
1432 }
1433
1434 // Resolve function ptr literals first.
1435 addr = resolve_function_descriptor_to_code_pointer(addr);
1436 if (!addr) {
1437 return false;
1438 }
1439
1440 if (::getModuleName((codeptr_t) addr, buf, buflen, 0, 0) == 0) {
1441 return true;
1442 }
1443 return false;
1444 }
1445
1446 // Loads .dll/.so and in case of error it checks if .dll/.so was built
1447 // for the same architecture as Hotspot is running on
1448 void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
1449
1450 if (ebuf && ebuflen > 0) {
1451 ebuf[0] = '\0';
1452 ebuf[ebuflen - 1] = '\0';
1453 }
1454
1455 if (!filename || strlen(filename) == 0) {
1456 ::strncpy(ebuf, "dll_load: empty filename specified", ebuflen - 1);
1457 return NULL;
1458 }
1459
1460 // RTLD_LAZY is currently not implemented. The dl is loaded immediately with all its dependants.
1461 void * result= ::dlopen(filename, RTLD_LAZY);
1462 if (result != NULL) {
1463 // Reload dll cache. Don't do this in signal handling.
1464 LoadedLibraries::reload();
1465 return result;
1466 } else {
1467 // error analysis when dlopen fails
1590 st->print_cr(" (no more information available)");
1591 }
1592 }
1593
1594 void os::pd_print_cpu_info(outputStream* st) {
1595 // cpu
1596 st->print("CPU:");
1597 st->print("total %d", os::processor_count());
1598 // It's not safe to query number of active processors after crash
1599 // st->print("(active %d)", os::active_processor_count());
1600 st->print(" %s", VM_Version::cpu_features());
1601 st->cr();
1602 }
1603
1604 void os::print_siginfo(outputStream* st, void* siginfo) {
1605 // Use common posix version.
1606 os::Posix::print_siginfo_brief(st, (const siginfo_t*) siginfo);
1607 st->cr();
1608 }
1609
1610
1611 static void print_signal_handler(outputStream* st, int sig,
1612 char* buf, size_t buflen);
1613
1614 void os::print_signal_handlers(outputStream* st, char* buf, size_t buflen) {
1615 st->print_cr("Signal Handlers:");
1616 print_signal_handler(st, SIGSEGV, buf, buflen);
1617 print_signal_handler(st, SIGBUS , buf, buflen);
1618 print_signal_handler(st, SIGFPE , buf, buflen);
1619 print_signal_handler(st, SIGPIPE, buf, buflen);
1620 print_signal_handler(st, SIGXFSZ, buf, buflen);
1621 print_signal_handler(st, SIGILL , buf, buflen);
1622 print_signal_handler(st, INTERRUPT_SIGNAL, buf, buflen);
1623 print_signal_handler(st, SR_signum, buf, buflen);
1624 print_signal_handler(st, SHUTDOWN1_SIGNAL, buf, buflen);
1625 print_signal_handler(st, SHUTDOWN2_SIGNAL , buf, buflen);
1626 print_signal_handler(st, SHUTDOWN3_SIGNAL , buf, buflen);
1627 print_signal_handler(st, BREAK_SIGNAL, buf, buflen);
1628 print_signal_handler(st, SIGTRAP, buf, buflen);
1629 print_signal_handler(st, SIGDANGER, buf, buflen);
1630 }
1631
1632 static char saved_jvm_path[MAXPATHLEN] = {0};
1633
1634 // Find the full path to the current module, libjvm.so or libjvm_g.so
1635 void os::jvm_path(char *buf, jint buflen) {
1636 // Error checking.
1637 if (buflen < MAXPATHLEN) {
1638 assert(false, "must use a large-enough buffer");
1639 buf[0] = '\0';
1640 return;
1641 }
1642 // Lazy resolve the path to current module.
1643 if (saved_jvm_path[0] != 0) {
1644 strcpy(buf, saved_jvm_path);
1645 return;
1646 }
1647
1648 Dl_info dlinfo;
1649 int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo);
1650 assert(ret != 0, "cannot locate libjvm");
1651 char* rp = realpath((char *)dlinfo.dli_fname, buf);
1652 assert(rp != NULL, "error in realpath(): maybe the 'path' argument is too long?");
1653
1654 strncpy(saved_jvm_path, buf, sizeof(saved_jvm_path));
2847 57, // 5 NormPriority
2848 57, // 6
2849
2850 58, // 7
2851 58, // 8
2852 59, // 9 NearMaxPriority
2853
2854 60, // 10 MaxPriority
2855
2856 60 // 11 CriticalPriority
2857 };
2858
2859 OSReturn os::set_native_priority(Thread* thread, int newpri) {
2860 if (!UseThreadPriorities) return OS_OK;
2861 pthread_t thr = thread->osthread()->pthread_id();
2862 int policy = SCHED_OTHER;
2863 struct sched_param param;
2864 param.sched_priority = newpri;
2865 int ret = pthread_setschedparam(thr, policy, ¶m);
2866
2867 if (Verbose) {
2868 if (ret == 0) {
2869 fprintf(stderr, "changed priority of thread %d to %d\n", (int)thr, newpri);
2870 } else {
2871 fprintf(stderr, "Could not changed priority for thread %d to %d (error %d, %s)\n",
2872 (int)thr, newpri, ret, strerror(ret));
2873 }
2874 }
2875 return (ret == 0) ? OS_OK : OS_ERR;
2876 }
2877
2878 OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) {
2879 if (!UseThreadPriorities) {
2880 *priority_ptr = java_to_os_priority[NormPriority];
2881 return OS_OK;
2882 }
2883 pthread_t thr = thread->osthread()->pthread_id();
2884 int policy = SCHED_OTHER;
2885 struct sched_param param;
2886 int ret = pthread_getschedparam(thr, &policy, ¶m);
2887 *priority_ptr = param.sched_priority;
2888
2889 return (ret == 0) ? OS_OK : OS_ERR;
2890 }
2891
2892 // Hint to the underlying OS that a task switch would not be good.
2893 // Void return because it's a hint and can fail.
2894 void os::hint_no_preempt() {}
2974 }
2975
2976 } else if (state == os::SuspendResume::SR_RUNNING) {
2977 // request was cancelled, continue
2978 } else {
2979 ShouldNotReachHere();
2980 }
2981
2982 resume_clear_context(osthread);
2983 } else if (current == os::SuspendResume::SR_RUNNING) {
2984 // request was cancelled, continue
2985 } else if (current == os::SuspendResume::SR_WAKEUP_REQUEST) {
2986 // ignore
2987 } else {
2988 ShouldNotReachHere();
2989 }
2990
2991 errno = old_errno;
2992 }
2993
2994
2995 static int SR_initialize() {
2996 struct sigaction act;
2997 char *s;
2998 // Get signal number to use for suspend/resume
2999 if ((s = ::getenv("_JAVA_SR_SIGNUM")) != 0) {
3000 int sig = ::strtol(s, 0, 10);
3001 if (sig > 0 || sig < NSIG) {
3002 SR_signum = sig;
3003 }
3004 }
3005
3006 assert(SR_signum > SIGSEGV && SR_signum > SIGBUS,
3007 "SR_signum must be greater than max(SIGSEGV, SIGBUS), see 4355769");
3008
3009 sigemptyset(&SR_sigset);
3010 sigaddset(&SR_sigset, SR_signum);
3011
3012 // Set up signal handler for suspend/resume.
3013 act.sa_flags = SA_RESTART|SA_SIGINFO;
3014 act.sa_handler = (void (*)(int)) SR_handler;
3173 ::sigemptyset(&set);
3174 ::sigaddset(&set, SIGILL);
3175 ::sigaddset(&set, SIGBUS);
3176 ::sigaddset(&set, SIGFPE);
3177 ::sigaddset(&set, SIGSEGV);
3178 return set_thread_signal_mask(SIG_UNBLOCK, &set, NULL);
3179 }
3180
3181 // Renamed from 'signalHandler' to avoid collision with other shared libs.
3182 void javaSignalHandler(int sig, siginfo_t* info, void* uc) {
3183 assert(info != NULL && uc != NULL, "it must be old kernel");
3184
3185 // Never leave program error signals blocked;
3186 // on all our platforms they would bring down the process immediately when
3187 // getting raised while being blocked.
3188 unblock_program_error_signals();
3189
3190 JVM_handle_aix_signal(sig, info, uc, true);
3191 }
3192
3193
3194 // This boolean allows users to forward their own non-matching signals
3195 // to JVM_handle_aix_signal, harmlessly.
3196 bool os::Aix::signal_handlers_are_installed = false;
3197
3198 // For signal-chaining
3199 struct sigaction os::Aix::sigact[MAXSIGNUM];
3200 unsigned int os::Aix::sigs = 0;
3201 bool os::Aix::libjsig_is_loaded = false;
3202 typedef struct sigaction *(*get_signal_t)(int);
3203 get_signal_t os::Aix::get_signal_action = NULL;
3204
3205 struct sigaction* os::Aix::get_chained_signal_action(int sig) {
3206 struct sigaction *actp = NULL;
3207
3208 if (libjsig_is_loaded) {
3209 // Retrieve the old signal handler from libjsig
3210 actp = (*get_signal_action)(sig);
3211 }
3212 if (actp == NULL) {
3213 // Retrieve the preinstalled signal handler from jvm
3367 get_signal_action = CAST_TO_FN_PTR(get_signal_t,
3368 dlsym(RTLD_DEFAULT, "JVM_get_signal_action"));
3369 libjsig_is_loaded = true;
3370 assert(UseSignalChaining, "should enable signal-chaining");
3371 }
3372 if (libjsig_is_loaded) {
3373 // Tell libjsig jvm is setting signal handlers
3374 (*begin_signal_setting)();
3375 }
3376
3377 set_signal_handler(SIGSEGV, true);
3378 set_signal_handler(SIGPIPE, true);
3379 set_signal_handler(SIGBUS, true);
3380 set_signal_handler(SIGILL, true);
3381 set_signal_handler(SIGFPE, true);
3382 set_signal_handler(SIGTRAP, true);
3383 set_signal_handler(SIGXFSZ, true);
3384 set_signal_handler(SIGDANGER, true);
3385
3386 if (libjsig_is_loaded) {
3387 // Tell libjsig jvm finishes setting signal handlers
3388 (*end_signal_setting)();
3389 }
3390
3391 // We don't activate signal checker if libjsig is in place, we trust ourselves
3392 // and if UserSignalHandler is installed all bets are off.
3393 // Log that signal checking is off only if -verbose:jni is specified.
3394 if (CheckJNICalls) {
3395 if (libjsig_is_loaded) {
3396 tty->print_cr("Info: libjsig is activated, all active signal checking is disabled");
3397 check_signals = false;
3398 }
3399 if (AllowUserSignalHandlers) {
3400 tty->print_cr("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
3401 check_signals = false;
3402 }
3403 // need to initialize check_signal_done
3404 ::sigemptyset(&check_signal_done);
3405 }
3406 }
3407 }
3408
3409 static const char* get_signal_handler_name(address handler,
3410 char* buf, int buflen) {
3411 int offset;
3412 bool found = os::dll_address_to_library_name(handler, buf, buflen, &offset);
3413 if (found) {
3414 // skip directory names
3415 const char *p1, *p2;
3416 p1 = buf;
3417 size_t len = strlen(os::file_separator());
3418 while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len;
3419 // The way os::dll_address_to_library_name is implemented on Aix
3420 // right now, it always returns -1 for the offset which is not
3421 // terribly informative.
3422 // Will fix that. For now, omit the offset.
3423 jio_snprintf(buf, buflen, "%s", p1);
3457 sa.sa_flags = VMError::get_resetted_sigflags(sig);
3458 }
3459
3460 // Print textual representation of sa_flags.
3461 st->print(", sa_flags=");
3462 os::Posix::print_sa_flags(st, sa.sa_flags);
3463
3464 // Check: is it our handler?
3465 if (handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)javaSignalHandler) ||
3466 handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler)) {
3467 // It is our signal handler.
3468 // Check for flags, reset system-used one!
3469 if ((int)sa.sa_flags != os::Aix::get_our_sigflags(sig)) {
3470 st->print(", flags was changed from " PTR32_FORMAT ", consider using jsig library",
3471 os::Aix::get_our_sigflags(sig));
3472 }
3473 }
3474 st->cr();
3475 }
3476
3477
3478 #define DO_SIGNAL_CHECK(sig) \
3479 if (!sigismember(&check_signal_done, sig)) \
3480 os::Aix::check_signal_handler(sig)
3481
3482 // This method is a periodic task to check for misbehaving JNI applications
3483 // under CheckJNI, we can add any periodic checks here
3484
3485 void os::run_periodic_checks() {
3486
3487 if (check_signals == false) return;
3488
3489 // SEGV and BUS if overridden could potentially prevent
3490 // generation of hs*.log in the event of a crash, debugging
3491 // such a case can be very challenging, so we absolutely
3492 // check the following for a good measure:
3493 DO_SIGNAL_CHECK(SIGSEGV);
3494 DO_SIGNAL_CHECK(SIGILL);
3495 DO_SIGNAL_CHECK(SIGFPE);
3496 DO_SIGNAL_CHECK(SIGBUS);
3497 DO_SIGNAL_CHECK(SIGPIPE);
3518
3519 static os_sigaction_t os_sigaction = NULL;
3520
3521 void os::Aix::check_signal_handler(int sig) {
3522 char buf[O_BUFLEN];
3523 address jvmHandler = NULL;
3524
3525 struct sigaction act;
3526 if (os_sigaction == NULL) {
3527 // only trust the default sigaction, in case it has been interposed
3528 os_sigaction = (os_sigaction_t)dlsym(RTLD_DEFAULT, "sigaction");
3529 if (os_sigaction == NULL) return;
3530 }
3531
3532 os_sigaction(sig, (struct sigaction*)NULL, &act);
3533
3534 address thisHandler = (act.sa_flags & SA_SIGINFO)
3535 ? CAST_FROM_FN_PTR(address, act.sa_sigaction)
3536 : CAST_FROM_FN_PTR(address, act.sa_handler);
3537
3538
3539 switch(sig) {
3540 case SIGSEGV:
3541 case SIGBUS:
3542 case SIGFPE:
3543 case SIGPIPE:
3544 case SIGILL:
3545 case SIGXFSZ:
3546 // Renamed 'signalHandler' to avoid collision with other shared libs.
3547 jvmHandler = CAST_FROM_FN_PTR(address, (sa_sigaction_t)javaSignalHandler);
3548 break;
3549
3550 case SHUTDOWN1_SIGNAL:
3551 case SHUTDOWN2_SIGNAL:
3552 case SHUTDOWN3_SIGNAL:
3553 case BREAK_SIGNAL:
3554 jvmHandler = (address)user_handler();
3555 break;
3556
3557 case INTERRUPT_SIGNAL:
3558 jvmHandler = CAST_FROM_FN_PTR(address, SIG_DFL);
3671 fprintf(stderr, " %s ", describe_pagesize(_page_sizes[i]));
3672 }
3673 fprintf(stderr, ")\n");
3674 }
3675
3676 _initial_pid = getpid();
3677
3678 clock_tics_per_sec = sysconf(_SC_CLK_TCK);
3679
3680 init_random(1234567);
3681
3682 ThreadCritical::initialize();
3683
3684 // Main_thread points to the aboriginal thread.
3685 Aix::_main_thread = pthread_self();
3686
3687 initial_time_count = os::elapsed_counter();
3688 pthread_mutex_init(&dl_mutex, NULL);
3689 }
3690
3691 // this is called _after_ the global arguments have been parsed
3692 jint os::init_2(void) {
3693
3694 if (Verbose) {
3695 fprintf(stderr, "processor count: %d\n", os::_processor_count);
3696 fprintf(stderr, "physical memory: %lu\n", Aix::_physical_memory);
3697 }
3698
3699 // initially build up the loaded dll map
3700 LoadedLibraries::reload();
3701
3702 const int page_size = Aix::page_size();
3703 const int map_size = page_size;
3704
3705 address map_address = (address) MAP_FAILED;
3706 const int prot = PROT_READ;
3707 const int flags = MAP_PRIVATE|MAP_ANONYMOUS;
3708
3709 // use optimized addresses for the polling page,
3710 // e.g. map it to a special 32-bit address.
3711 if (OptimizePollingPageLocation) {
3712 // architecture-specific list of address wishes:
3713 address address_wishes[] = {
3714 // AIX: addresses lower than 0x30000000 don't seem to work on AIX.
3715 // PPC64: all address wishes are non-negative 32 bit values where
3716 // the lower 16 bits are all zero. we can load these addresses
3717 // with a single ppc_lis instruction.
3718 (address) 0x30000000, (address) 0x31000000,
3719 (address) 0x32000000, (address) 0x33000000,
3729 // iterate over the list of address wishes:
3730 for (int i=0; i<address_wishes_length; i++) {
3731 // try to map with current address wish.
3732 // AIX: AIX needs MAP_FIXED if we provide an address and mmap will
3733 // fail if the address is already mapped.
3734 map_address = (address) ::mmap(address_wishes[i] - (ssize_t)page_size,
3735 map_size, prot,
3736 flags | MAP_FIXED,
3737 -1, 0);
3738 if (Verbose) {
3739 fprintf(stderr, "SafePoint Polling Page address: %p (wish) => %p\n",
3740 address_wishes[i], map_address + (ssize_t)page_size);
3741 }
3742
3743 if (map_address + (ssize_t)page_size == address_wishes[i]) {
3744 // map succeeded and map_address is at wished address, exit loop.
3745 break;
3746 }
3747
3748 if (map_address != (address) MAP_FAILED) {
3749 // map succeeded, but polling_page is not at wished address, unmap and continue.
3750 ::munmap(map_address, map_size);
3751 map_address = (address) MAP_FAILED;
3752 }
3753 // map failed, continue loop.
3754 }
3755 } // end OptimizePollingPageLocation
3756
3757 if (map_address == (address) MAP_FAILED) {
3758 map_address = (address) ::mmap(NULL, map_size, prot, flags, -1, 0);
3759 }
3760 guarantee(map_address != MAP_FAILED, "os::init_2: failed to allocate polling page");
3761 os::set_polling_page(map_address);
3762
3763 if (!UseMembar) {
3764 address mem_serialize_page = (address) ::mmap(NULL, Aix::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
3765 guarantee(mem_serialize_page != NULL, "mmap Failed for memory serialize page");
3766 os::set_memory_serialize_page(mem_serialize_page);
3767
3768 #ifndef PRODUCT
3769 if (Verbose && PrintMiscellaneous)
3783 // Check minimum allowable stack size for thread creation and to initialize
3784 // the java system classes, including StackOverflowError - depends on page
3785 // size. Add a page for compiler2 recursion in main thread.
3786 // Add in 2*BytesPerWord times page size to account for VM stack during
3787 // class initialization depending on 32 or 64 bit VM.
3788 os::Aix::min_stack_allowed = MAX2(os::Aix::min_stack_allowed,
3789 (size_t)(StackYellowPages+StackRedPages+StackShadowPages +
3790 2*BytesPerWord COMPILER2_PRESENT(+1)) * Aix::page_size());
3791
3792 size_t threadStackSizeInBytes = ThreadStackSize * K;
3793 if (threadStackSizeInBytes != 0 &&
3794 threadStackSizeInBytes < os::Aix::min_stack_allowed) {
3795 tty->print_cr("\nThe stack size specified is too small, "
3796 "Specify at least %dk",
3797 os::Aix::min_stack_allowed / K);
3798 return JNI_ERR;
3799 }
3800
3801 // Make the stack size a multiple of the page size so that
3802 // the yellow/red zones can be guarded.
3803 // note that this can be 0, if no default stacksize was set
3804 JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes, vm_page_size()));
3805
3806 Aix::libpthread_init();
3807
3808 if (MaxFDLimit) {
3809 // set the number of file descriptors to max. print out error
3810 // if getrlimit/setrlimit fails but continue regardless.
3811 struct rlimit nbr_files;
3812 int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
3813 if (status != 0) {
3814 if (PrintMiscellaneous && (Verbose || WizardMode))
3815 perror("os::init_2 getrlimit failed");
3816 } else {
3817 nbr_files.rlim_cur = nbr_files.rlim_max;
3818 status = setrlimit(RLIMIT_NOFILE, &nbr_files);
3819 if (status != 0) {
3820 if (PrintMiscellaneous && (Verbose || WizardMode))
3821 perror("os::init_2 setrlimit failed");
3822 }
3823 }
4074 // suffering from bug 1085341.
4075 //
4076 // (Yes, the default setting of the close-on-exec flag is a Unix
4077 // design flaw.)
4078 //
4079 // See:
4080 // 1085341: 32-bit stdio routines should support file descriptors >255
4081 // 4843136: (process) pipe file descriptor from Runtime.exec not being closed
4082 // 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
4083 #ifdef FD_CLOEXEC
4084 {
4085 int flags = ::fcntl(fd, F_GETFD);
4086 if (flags != -1)
4087 ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
4088 }
4089 #endif
4090
4091 return fd;
4092 }
4093
4094
4095 // create binary file, rewriting existing file if required
4096 int os::create_binary_file(const char* path, bool rewrite_existing) {
4097 int oflags = O_WRONLY | O_CREAT;
4098 if (!rewrite_existing) {
4099 oflags |= O_EXCL;
4100 }
4101 return ::open64(path, oflags, S_IREAD | S_IWRITE);
4102 }
4103
4104 // return current position of file pointer
4105 jlong os::current_file_offset(int fd) {
4106 return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR);
4107 }
4108
4109 // move file pointer to the specified offset
4110 jlong os::seek_to_file_offset(int fd, jlong offset) {
4111 return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET);
4112 }
4113
4114 // This code originates from JDK's sysAvailable
4134 }
4135 if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) {
4136 return 0;
4137 } else if ((end = ::lseek64(fd, 0L, SEEK_END)) == -1) {
4138 return 0;
4139 } else if (::lseek64(fd, cur, SEEK_SET) == -1) {
4140 return 0;
4141 }
4142 *bytes = end - cur;
4143 return 1;
4144 }
4145
4146 // Map a block of memory.
4147 char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
4148 char *addr, size_t bytes, bool read_only,
4149 bool allow_exec) {
4150 Unimplemented();
4151 return NULL;
4152 }
4153
4154
4155 // Remap a block of memory.
4156 char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset,
4157 char *addr, size_t bytes, bool read_only,
4158 bool allow_exec) {
4159 // same as map_memory() on this OS
4160 return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only,
4161 allow_exec);
4162 }
4163
4164 // Unmap a block of memory.
4165 bool os::pd_unmap_memory(char* addr, size_t bytes) {
4166 return munmap(addr, bytes) == 0;
4167 }
4168
4169 // current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool)
4170 // are used by JVM M&M and JVMTI to get user+sys or user CPU time
4171 // of a thread.
4172 //
4173 // current_thread_cpu_time() and thread_cpu_time(Thread*) returns
4174 // the fast estimate available on the platform.
4182
4183 jlong os::thread_cpu_time(Thread* thread) {
4184 // consistent with what current_thread_cpu_time() returns
4185 const jlong n = os::thread_cpu_time(thread, true /* user + sys */);
4186 assert(n >= 0, "negative CPU time");
4187 return n;
4188 }
4189
4190 jlong os::current_thread_cpu_time(bool user_sys_cpu_time) {
4191 const jlong n = os::thread_cpu_time(Thread::current(), user_sys_cpu_time);
4192 assert(n >= 0, "negative CPU time");
4193 return n;
4194 }
4195
4196 static bool thread_cpu_time_unchecked(Thread* thread, jlong* p_sys_time, jlong* p_user_time) {
4197 bool error = false;
4198
4199 jlong sys_time = 0;
4200 jlong user_time = 0;
4201
4202 // reimplemented using getthrds64().
4203 //
4204 // goes like this:
4205 // For the thread in question, get the kernel thread id. Then get the
4206 // kernel thread statistics using that id.
4207 //
4208 // This only works of course when no pthread scheduling is used,
4209 // ie there is a 1:1 relationship to kernel threads.
4210 // On AIX, see AIXTHREAD_SCOPE variable.
4211
4212 pthread_t pthtid = thread->osthread()->pthread_id();
4213
4214 // retrieve kernel thread id for the pthread:
4215 tid64_t tid = 0;
4216 struct __pthrdsinfo pinfo;
4217 // I just love those otherworldly IBM APIs which force me to hand down
4218 // dummy buffers for stuff I dont care for...
4219 char dummy[1];
4220 int dummy_size = sizeof(dummy);
4221 if (pthread_getthrds_np(&pthtid, PTHRDSINFO_QUERY_TID, &pinfo, sizeof(pinfo),
4222 dummy, &dummy_size) == 0) {
4223 tid = pinfo.__pi_tid;
4224 } else {
4225 tty->print_cr("pthread_getthrds_np failed.");
4226 error = true;
4227 }
4228
4229 // retrieve kernel timing info for that kernel thread
4336 }
4337
4338 bool os::Aix::is_primordial_thread() {
4339 if (pthread_self() == (pthread_t)1) {
4340 return true;
4341 } else {
4342 return false;
4343 }
4344 }
4345
4346 // OS recognitions (PASE/AIX, OS level) call this before calling any
4347 // one of Aix::on_pase(), Aix::os_version() static
4348 void os::Aix::initialize_os_info() {
4349
4350 assert(_on_pase == -1 && _os_version == -1, "already called.");
4351
4352 struct utsname uts;
4353 memset(&uts, 0, sizeof(uts));
4354 strcpy(uts.sysname, "?");
4355 if (::uname(&uts) == -1) {
4356 fprintf(stderr, "uname failed (%d)\n", errno);
4357 guarantee(0, "Could not determine whether we run on AIX or PASE");
4358 } else {
4359 if (Verbose) {
4360 fprintf(stderr,"uname says: sysname \"%s\" version \"%s\" release \"%s\" "
4361 "node \"%s\" machine \"%s\"\n",
4362 uts.sysname, uts.version, uts.release, uts.nodename, uts.machine);
4363 }
4364 const int major = atoi(uts.version);
4365 assert(major > 0, "invalid OS version");
4366 const int minor = atoi(uts.release);
4367 assert(minor > 0, "invalid OS release");
4368 _os_version = (major << 8) | minor;
4369 if (strcmp(uts.sysname, "OS400") == 0) {
4370 Unimplemented();
4371 } else if (strcmp(uts.sysname, "AIX") == 0) {
4372 // We run on AIX. We do not support versions older than AIX 5.3.
4373 _on_pase = 0;
4374 if (_os_version < 0x0503) {
4375 fprintf(stderr, "AIX release older than AIX 5.3 not supported.\n");
4376 assert(false, "AIX release too old.");
4377 } else {
4378 if (Verbose) {
4379 fprintf(stderr, "We run on AIX %d.%d\n", major, minor);
4380 }
4381 }
4382 } else {
4383 assert(false, "unknown OS");
4384 }
4385 }
4386
4387 guarantee(_on_pase != -1 && _os_version, "Could not determine AIX/OS400 release");
4388
4389 } // end: os::Aix::initialize_os_info()
4390
4391 // Scan environment for important settings which might effect the VM.
4392 // Trace out settings. Warn about invalid settings and/or correct them.
4393 //
4394 // Must run after os::Aix::initialue_os_info().
4395 void os::Aix::scan_environment() {
4396
4397 char* p;
4398 int rc;
4399
4400 // Warn explicity if EXTSHM=ON is used. That switch changes how
4401 // System V shared memory behaves. One effect is that page size of
4402 // shared memory cannot be change dynamically, effectivly preventing
4403 // large pages from working.
4404 // This switch was needed on AIX 32bit, but on AIX 64bit the general
4405 // recommendation is (in OSS notes) to switch it off.
4406 p = ::getenv("EXTSHM");
4407 if (Verbose) {
4408 fprintf(stderr, "EXTSHM=%s.\n", p ? p : "<unset>");
4409 }
4410 if (p && strcmp(p, "ON") == 0) {
4411 fprintf(stderr, "Unsupported setting: EXTSHM=ON. Large Page support will be disabled.\n");
4412 _extshm = 1;
4413 } else {
4414 _extshm = 0;
4415 }
4416
4417 // SPEC1170 behaviour: will change the behaviour of a number of POSIX APIs.
4418 // Not tested, not supported.
4419 //
4420 // Note that it might be worth the trouble to test and to require it, if only to
4421 // get useful return codes for mprotect.
4422 //
4423 // Note: Setting XPG_SUS_ENV in the process is too late. Must be set earlier (before
4424 // exec() ? before loading the libjvm ? ....)
4425 p = ::getenv("XPG_SUS_ENV");
4426 if (Verbose) {
4427 fprintf(stderr, "XPG_SUS_ENV=%s.\n", p ? p : "<unset>");
4428 }
4429 if (p && strcmp(p, "ON") == 0) {
4430 _xpg_sus_mode = 1;
4431 fprintf(stderr, "Unsupported setting: XPG_SUS_ENV=ON\n");
4432 // This is not supported. Worst of all, it changes behaviour of mmap MAP_FIXED to
4433 // clobber address ranges. If we ever want to support that, we have to do some
4434 // testing first.
4435 guarantee(false, "XPG_SUS_ENV=ON not supported");
4436 } else {
4437 _xpg_sus_mode = 0;
4438 }
4439
4440 // Switch off AIX internal (pthread) guard pages. This has
4441 // immediate effect for any pthread_create calls which follow.
4442 p = ::getenv("AIXTHREAD_GUARDPAGES");
4443 if (Verbose) {
4444 fprintf(stderr, "AIXTHREAD_GUARDPAGES=%s.\n", p ? p : "<unset>");
4445 fprintf(stderr, "setting AIXTHREAD_GUARDPAGES=0.\n");
4446 }
4447 rc = ::putenv("AIXTHREAD_GUARDPAGES=0");
4448 guarantee(rc == 0, "");
4449
4450 } // end: os::Aix::scan_environment()
4451
4452 // PASE: initialize the libo4 library (AS400 PASE porting library).
4453 void os::Aix::initialize_libo4() {
4454 Unimplemented();
4455 }
4456
4457 // AIX: initialize the libperfstat library (we load this dynamically
4458 // because it is only available on AIX.
4459 void os::Aix::initialize_libperfstat() {
4460
4461 assert(os::Aix::on_aix(), "AIX only");
4462
4463 if (!libperfstat::init()) {
4464 fprintf(stderr, "libperfstat initialization failed.\n");
4465 assert(false, "libperfstat initialization failed");
4466 } else {
4467 if (Verbose) {
4468 fprintf(stderr, "libperfstat initialized.\n");
4469 }
4470 }
4471 } // end: os::Aix::initialize_libperfstat
4472
4473 /////////////////////////////////////////////////////////////////////////////
4474 // thread stack
4475
4476 // function to query the current stack size using pthread_getthrds_np
4477 //
4478 // ! do not change anything here unless you know what you are doing !
4479 static void query_stack_dimensions(address* p_stack_base, size_t* p_stack_size) {
4480
4481 // This only works when invoked on a pthread. As we agreed not to use
4482 // primordial threads anyway, I assert here
4483 guarantee(!os::Aix::is_primordial_thread(), "not allowed on the primordial thread");
4484
4616 static struct timespec* compute_abstime(timespec* abstime, jlong millis) {
4617 if (millis < 0) millis = 0;
4618 struct timeval now;
4619 int status = gettimeofday(&now, NULL);
4620 assert(status == 0, "gettimeofday");
4621 jlong seconds = millis / 1000;
4622 millis %= 1000;
4623 if (seconds > 50000000) { // see man cond_timedwait(3T)
4624 seconds = 50000000;
4625 }
4626 abstime->tv_sec = now.tv_sec + seconds;
4627 long usec = now.tv_usec + millis * 1000;
4628 if (usec >= 1000000) {
4629 abstime->tv_sec += 1;
4630 usec -= 1000000;
4631 }
4632 abstime->tv_nsec = usec * 1000;
4633 return abstime;
4634 }
4635
4636
4637 // Test-and-clear _Event, always leaves _Event set to 0, returns immediately.
4638 // Conceptually TryPark() should be equivalent to park(0).
4639
4640 int os::PlatformEvent::TryPark() {
4641 for (;;) {
4642 const int v = _Event;
4643 guarantee ((v == 0) || (v == 1), "invariant");
4644 if (Atomic::cmpxchg (0, &_Event, v) == v) return v;
4645 }
4646 }
4647
4648 void os::PlatformEvent::park() { // AKA "down()"
4649 // Invariant: Only the thread associated with the Event/PlatformEvent
4650 // may call park().
4651 // TODO: assert that _Assoc != NULL or _Assoc == Self
4652 int v;
4653 for (;;) {
4654 v = _Event;
4655 if (Atomic::cmpxchg (v-1, &_Event, v) == v) break;
4656 }
4855
4856 Thread* thread = Thread::current();
4857 assert(thread->is_Java_thread(), "Must be JavaThread");
4858 JavaThread *jt = (JavaThread *)thread;
4859
4860 // Optional optimization -- avoid state transitions if there's an interrupt pending.
4861 // Check interrupt before trying to wait
4862 if (Thread::is_interrupted(thread, false)) {
4863 return;
4864 }
4865
4866 // Next, demultiplex/decode time arguments
4867 timespec absTime;
4868 if (time < 0 || (isAbsolute && time == 0)) { // don't wait at all
4869 return;
4870 }
4871 if (time > 0) {
4872 unpackTime(&absTime, isAbsolute, time);
4873 }
4874
4875
4876 // Enter safepoint region
4877 // Beware of deadlocks such as 6317397.
4878 // The per-thread Parker:: mutex is a classic leaf-lock.
4879 // In particular a thread must never block on the Threads_lock while
4880 // holding the Parker:: mutex. If safepoints are pending both the
4881 // the ThreadBlockInVM() CTOR and DTOR may grab Threads_lock.
4882 ThreadBlockInVM tbivm(jt);
4883
4884 // Don't wait if cannot get lock since interference arises from
4885 // unblocking. Also. check interrupt before trying wait
4886 if (Thread::is_interrupted(thread, false) || pthread_mutex_trylock(_mutex) != 0) {
4887 return;
4888 }
4889
4890 int status;
4891 if (_counter > 0) { // no wait needed
4892 _counter = 0;
4893 status = pthread_mutex_unlock(_mutex);
4894 assert (status == 0, "invariant");
4895 OrderAccess::fence();
4943 s = _counter;
4944 _counter = 1;
4945 if (s < 1) {
4946 if (WorkAroundNPTLTimedWaitHang) {
4947 status = pthread_cond_signal (_cond);
4948 assert (status == 0, "invariant");
4949 status = pthread_mutex_unlock(_mutex);
4950 assert (status == 0, "invariant");
4951 } else {
4952 status = pthread_mutex_unlock(_mutex);
4953 assert (status == 0, "invariant");
4954 status = pthread_cond_signal (_cond);
4955 assert (status == 0, "invariant");
4956 }
4957 } else {
4958 pthread_mutex_unlock(_mutex);
4959 assert (status == 0, "invariant");
4960 }
4961 }
4962
4963
4964 extern char** environ;
4965
4966 // Run the specified command in a separate process. Return its exit value,
4967 // or -1 on failure (e.g. can't fork a new process).
4968 // Unlike system(), this function can be called from signal handler. It
4969 // doesn't block SIGINT et al.
4970 int os::fork_and_exec(char* cmd) {
4971 char * argv[4] = {"sh", "-c", cmd, NULL};
4972
4973 pid_t pid = fork();
4974
4975 if (pid < 0) {
4976 // fork failed
4977 return -1;
4978
4979 } else if (pid == 0) {
4980 // child process
4981
4982 // try to be consistent with system(), which uses "/usr/bin/sh" on AIX
4983 execve("/usr/bin/sh", argv, environ);
4984
4985 // execve failed
4986 _exit(-1);
4987
4988 } else {
4989 // copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't
4990 // care about the actual exit code, for now.
4991
4992 int status;
4993
4994 // Wait for the child process to exit. This returns immediately if
4995 // the child has already exited. */
4996 while (waitpid(pid, &status, 0) < 0) {
4997 switch (errno) {
4998 case ECHILD: return 0;
4999 case EINTR: break;
5000 default: return -1;
5001 }
5002 }
5003
5004 if (WIFEXITED(status)) {
5005 // The child exited normally; get its exit code.
5006 return WEXITSTATUS(status);
5007 } else if (WIFSIGNALED(status)) {
5008 // The child exited because of a signal
5009 // The best value to return is 0x80 + signal number,
5010 // because that is what all Unix shells do, and because
5011 // it allows callers to distinguish between process exit and
5012 // process death by signal.
5013 return 0x80 + WTERMSIG(status);
5014 } else {
5015 // Unknown exit code; pass it through
5016 return status;
5017 }
5018 }
5019 // Remove warning.
5020 return -1;
5021 }
5022
5023 // is_headless_jre()
5024 //
5025 // Test for the existence of xawt/libmawt.so or libawt_xawt.so
5026 // in order to report if we are running in a headless jre.
5027 //
5028 // Since JDK8 xawt/libmawt.so is moved into the same directory
5029 // as libawt.so, and renamed libawt_xawt.so
5030 bool os::is_headless_jre() {
5031 struct stat statbuf;
5032 char buf[MAXPATHLEN];
5033 char libmawtpath[MAXPATHLEN];
5034 const char *xawtstr = "/xawt/libmawt.so";
5035 const char *new_xawtstr = "/libawt_xawt.so";
5036
5037 char *p;
5038
5039 // Get path to libjvm.so
|
107 #include <sys/vminfo.h>
108 #include <sys/wait.h>
109
110 // If RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling
111 // getrusage() is prepared to handle the associated failure.
112 #ifndef RUSAGE_THREAD
113 #define RUSAGE_THREAD (1) /* only the calling thread */
114 #endif
115
116 // Add missing declarations (should be in procinfo.h but isn't until AIX 6.1).
117 #if !defined(_AIXVERSION_610)
118 extern "C" {
119 int getthrds64(pid_t ProcessIdentifier,
120 struct thrdentry64* ThreadBuffer,
121 int ThreadSize,
122 tid64_t* IndexPointer,
123 int Count);
124 }
125 #endif
126
127 #define MAX_PATH (2 * K)
128
129 // for timer info max values which include all bits
130 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
131 // for multipage initialization error analysis (in 'g_multipage_error')
132 #define ERROR_MP_OS_TOO_OLD 100
133 #define ERROR_MP_EXTSHM_ACTIVE 101
134 #define ERROR_MP_VMGETINFO_FAILED 102
135 #define ERROR_MP_VMGETINFO_CLAIMS_NO_SUPPORT_FOR_64K 103
136
137 // The semantics in this file are thus that codeptr_t is a *real code ptr*.
138 // This means that any function taking codeptr_t as arguments will assume
139 // a real codeptr and won't handle function descriptors (eg getFuncName),
140 // whereas functions taking address as args will deal with function
141 // descriptors (eg os::dll_address_to_library_name).
142 typedef unsigned int* codeptr_t;
143
144 // Typedefs for stackslots, stack pointers, pointers to op codes.
145 typedef unsigned long stackslot_t;
146 typedef stackslot_t* stackptr_t;
147
148 // Excerpts from systemcfg.h definitions newer than AIX 5.3.
149 #ifndef PV_7
150 #define PV_7 0x200000 /* Power PC 7 */
151 #define PV_7_Compat 0x208000 /* Power PC 7 */
152 #endif
153 #ifndef PV_8
154 #define PV_8 0x300000 /* Power PC 8 */
155 #define PV_8_Compat 0x308000 /* Power PC 8 */
156 #endif
157
158 #define trcVerbose(fmt, ...) { /* PPC port */ \
159 if (Verbose) { \
160 fprintf(stderr, fmt, ##__VA_ARGS__); \
161 fputc('\n', stderr); fflush(stderr); \
162 } \
163 }
164 #define trc(fmt, ...) /* PPC port */
165
166 #define ERRBYE(s) { \
167 trcVerbose(s); \
168 return -1; \
169 }
170
171 // query dimensions of the stack of the calling thread
172 static void query_stack_dimensions(address* p_stack_base, size_t* p_stack_size);
173
174 // function to check a given stack pointer against given stack limits
175 inline bool is_valid_stackpointer(stackptr_t sp, stackptr_t stack_base, size_t stack_size) {
176 if (((uintptr_t)sp) & 0x7) {
177 return false;
178 }
179 if (sp > stack_base) {
180 return false;
181 }
182 if (sp < (stackptr_t) ((address)stack_base - stack_size)) {
183 return false;
184 }
185 return true;
186 }
187
188 // returns true if function is a valid codepointer
189 inline bool is_valid_codepointer(codeptr_t p) {
190 if (!p) {
191 return false;
192 }
193 if (((uintptr_t)p) & 0x3) {
194 return false;
195 }
196 if (LoadedLibraries::find_for_text_address((address)p) == NULL) {
197 return false;
198 }
199 return true;
200 }
201
202 // Macro to check a given stack pointer against given stack limits and to die if test fails.
203 #define CHECK_STACK_PTR(sp, stack_base, stack_size) { \
204 guarantee(is_valid_stackpointer((stackptr_t)(sp), (stackptr_t)(stack_base), stack_size), "Stack Pointer Invalid"); \
205 }
206
207 // Macro to check the current stack pointer against given stacklimits.
208 #define CHECK_CURRENT_STACK_PTR(stack_base, stack_size) { \
209 address sp; \
210 sp = os::current_stack_pointer(); \
211 CHECK_STACK_PTR(sp, stack_base, stack_size); \
212 }
213
214 ////////////////////////////////////////////////////////////////////////////////
215 // global variables (for a description see os_aix.hpp)
216
217 julong os::Aix::_physical_memory = 0;
218 pthread_t os::Aix::_main_thread = ((pthread_t)0);
219 int os::Aix::_page_size = -1;
220 int os::Aix::_on_pase = -1;
221 int os::Aix::_os_version = -1;
222 int os::Aix::_stack_page_size = -1;
223 size_t os::Aix::_shm_default_page_size = -1;
224 int os::Aix::_can_use_64K_pages = -1;
225 int os::Aix::_can_use_16M_pages = -1;
226 int os::Aix::_xpg_sus_mode = -1;
227 int os::Aix::_extshm = -1;
228 int os::Aix::_logical_cpus = -1;
229
230 ////////////////////////////////////////////////////////////////////////////////
231 // local variables
232
233 static int g_multipage_error = -1; // error analysis for multipage initialization
234 static jlong initial_time_count = 0;
235 static int clock_tics_per_sec = 100;
236 static sigset_t check_signal_done; // For diagnostics to print a message once (see run_periodic_checks)
237 static bool check_signals = true;
238 static pid_t _initial_pid = 0;
239 static int SR_signum = SIGUSR2; // Signal used to suspend/resume a thread (must be > SIGSEGV, see 4355769)
240 static sigset_t SR_sigset;
241 static pthread_mutex_t dl_mutex; // Used to protect dlsym() calls.
242
243 julong os::available_memory() {
244 return Aix::available_memory();
245 }
246
247 julong os::Aix::available_memory() {
248 os::Aix::meminfo_t mi;
249 if (os::Aix::get_meminfo(&mi)) {
250 return mi.real_free;
251 } else {
252 return 0xFFFFFFFFFFFFFFFFLL;
253 }
254 }
255
256 julong os::physical_memory() {
257 return Aix::physical_memory();
258 }
259
260 ////////////////////////////////////////////////////////////////////////////////
261 // environment support
262
263 bool os::getenv(const char* name, char* buf, int len) {
264 const char* val = ::getenv(name);
265 if (val != NULL && strlen(val) < (size_t)len) {
266 strcpy(buf, val);
267 return true;
268 }
269 if (len > 0) buf[0] = 0; // return a null string
270 return false;
271 }
272
273 // Return true if user is running as root.
274
275 bool os::have_special_privileges() {
276 static bool init = false;
277 static bool privileges = false;
278 if (!init) {
279 privileges = (getuid() != geteuid()) || (getgid() != getegid());
280 init = true;
281 }
282 return privileges;
283 }
284
285 // Helper function, emulates disclaim64 using multiple 32bit disclaims
286 // because we cannot use disclaim64() on AS/400 and old AIX releases.
287 static bool my_disclaim64(char* addr, size_t size) {
288
289 if (size == 0) {
290 return true;
291 }
292
293 // Maximum size 32bit disclaim() accepts. (Theoretically 4GB, but I just do not trust that.)
294 const unsigned int maxDisclaimSize = 0x80000000;
295
296 const unsigned int numFullDisclaimsNeeded = (size / maxDisclaimSize);
297 const unsigned int lastDisclaimSize = (size % maxDisclaimSize);
298
299 char* p = addr;
300
301 for (int i = 0; i < numFullDisclaimsNeeded; i ++) {
302 if (::disclaim(p, maxDisclaimSize, DISCLAIM_ZEROMEM) != 0) {
303 trc("Cannot disclaim %p - %p (errno %d)\n", p, p + maxDisclaimSize, errno);
304 return false;
305 }
306 p += maxDisclaimSize;
307 }
308
309 if (lastDisclaimSize > 0) {
310 if (::disclaim(p, lastDisclaimSize, DISCLAIM_ZEROMEM) != 0) {
311 trc("Cannot disclaim %p - %p (errno %d)\n", p, p + lastDisclaimSize, errno);
312 return false;
313 }
314 }
315
316 return true;
317 }
318
319 // Cpu architecture string
320 #if defined(PPC32)
321 static char cpu_arch[] = "ppc";
322 #elif defined(PPC64)
323 static char cpu_arch[] = "ppc64";
324 #else
325 #error Add appropriate cpu_arch setting
326 #endif
327
328
329 // Given an address, returns the size of the page backing that address.
330 size_t os::Aix::query_pagesize(void* addr) {
331
332 vm_page_info pi;
333 pi.addr = (uint64_t)addr;
334 if (::vmgetinfo(&pi, VM_PAGE_INFO, sizeof(pi)) == 0) {
335 return pi.pagesize;
336 } else {
337 fprintf(stderr, "vmgetinfo failed to retrieve page size for address %p (errno %d).\n", addr, errno);
338 assert(false, "vmgetinfo failed to retrieve page size");
339 return SIZE_4K;
340 }
341
342 }
343
344 // Returns the kernel thread id of the currently running thread.
345 pid_t os::Aix::gettid() {
346 return (pid_t) thread_self();
347 }
348
349 void os::Aix::initialize_system_info() {
350
351 // Get the number of online(logical) cpus instead of configured.
352 os::_processor_count = sysconf(_SC_NPROCESSORS_ONLN);
353 assert(_processor_count > 0, "_processor_count must be > 0");
354
355 // Retrieve total physical storage.
356 os::Aix::meminfo_t mi;
357 if (!os::Aix::get_meminfo(&mi)) {
358 fprintf(stderr, "os::Aix::get_meminfo failed.\n"); fflush(stderr);
359 assert(false, "os::Aix::get_meminfo failed.");
360 }
361 _physical_memory = (julong) mi.real_total;
362 }
363
364 // Helper function for tracing page sizes.
365 static const char* describe_pagesize(size_t pagesize) {
366 switch (pagesize) {
367 case SIZE_4K : return "4K";
368 case SIZE_64K: return "64K";
369 case SIZE_16M: return "16M";
370 case SIZE_16G: return "16G";
371 default:
372 assert(false, "surprise");
373 return "??";
374 }
375 }
510 guarantee(_page_size != -1 &&
511 _stack_page_size != -1 &&
512 _can_use_64K_pages != -1 &&
513 _can_use_16M_pages != -1, "Page sizes not properly initialized");
514
515 if (_can_use_64K_pages) {
516 g_multipage_error = 0;
517 }
518
519 if (Verbose) {
520 fprintf(stderr, "Data page size (C-Heap, bss, etc): %s\n", describe_pagesize(data_page_size));
521 fprintf(stderr, "Thread stack page size (pthread): %s\n", describe_pagesize(_stack_page_size));
522 fprintf(stderr, "Default shared memory page size: %s\n", describe_pagesize(_shm_default_page_size));
523 fprintf(stderr, "Can use 64K pages dynamically with shared meory: %s\n", (_can_use_64K_pages ? "yes" :"no"));
524 fprintf(stderr, "Can use 16M pages dynamically with shared memory: %s\n", (_can_use_16M_pages ? "yes" :"no"));
525 fprintf(stderr, "Multipage error details: %d\n", g_multipage_error);
526 }
527
528 } // end os::Aix::query_multipage_support()
529
530 void os::init_system_properties_values() {
531
532 #define DEFAULT_LIBPATH "/usr/lib:/lib"
533 #define EXTENSIONS_DIR "/lib/ext"
534 #define ENDORSED_DIR "/lib/endorsed"
535
536 // Buffer that fits several sprintfs.
537 // Note that the space for the trailing null is provided
538 // by the nulls included by the sizeof operator.
539 const size_t bufsize =
540 MAX3((size_t)MAXPATHLEN, // For dll_dir & friends.
541 (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR), // extensions dir
542 (size_t)MAXPATHLEN + sizeof(ENDORSED_DIR)); // endorsed dir
543 char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
544
545 // sysclasspath, java_home, dll_dir
546 {
547 char *pslash;
548 os::jvm_path(buf, bufsize);
549
606
607 void os::breakpoint() {
608 BREAKPOINT;
609 }
610
611 extern "C" void breakpoint() {
612 // use debugger to set breakpoint here
613 }
614
615 ////////////////////////////////////////////////////////////////////////////////
616 // signal support
617
618 debug_only(static bool signal_sets_initialized = false);
619 static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs;
620
621 bool os::Aix::is_sig_ignored(int sig) {
622 struct sigaction oact;
623 sigaction(sig, (struct sigaction*)NULL, &oact);
624 void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*, oact.sa_sigaction)
625 : CAST_FROM_FN_PTR(void*, oact.sa_handler);
626 if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) {
627 return true;
628 } else {
629 return false;
630 }
631 }
632
633 void os::Aix::signal_sets_init() {
634 // Should also have an assertion stating we are still single-threaded.
635 assert(!signal_sets_initialized, "Already initialized");
636 // Fill in signals that are necessarily unblocked for all threads in
637 // the VM. Currently, we unblock the following signals:
638 // SHUTDOWN{1,2,3}_SIGNAL: for shutdown hooks support (unless over-ridden
639 // by -Xrs (=ReduceSignalUsage));
640 // BREAK_SIGNAL which is unblocked only by the VM thread and blocked by all
641 // other threads. The "ReduceSignalUsage" boolean tells us not to alter
642 // the dispositions or masks wrt these signals.
643 // Programs embedding the VM that want to use the above signals for their
644 // own purposes must, at this time, use the "-Xrs" option to prevent
645 // interference with shutdown hooks and BREAK_SIGNAL thread dumping.
646 // (See bug 4345157, and other related bugs).
647 // In reality, though, unblocking these signals is really a nop, since
648 // these signals are not blocked by default.
649 sigemptyset(&unblocked_sigs);
650 sigemptyset(&allowdebug_blocked_sigs);
784 perfstat_cpu_total_t psct;
785 memset (&psct, '\0', sizeof(psct));
786
787 if (-1 == libperfstat::perfstat_cpu_total(NULL, &psct, sizeof(perfstat_cpu_total_t), 1)) {
788 fprintf(stderr, "perfstat_cpu_total() failed (errno=%d)\n", errno);
789 assert(0, "perfstat_cpu_total() failed");
790 return false;
791 }
792
793 // global cpu information
794 strcpy (pci->description, psct.description);
795 pci->processorHZ = psct.processorHZ;
796 pci->ncpus = psct.ncpus;
797 os::Aix::_logical_cpus = psct.ncpus;
798 for (int i = 0; i < 3; i++) {
799 pci->loadavg[i] = (double) psct.loadavg[i] / (1 << SBITS);
800 }
801
802 // get the processor version from _system_configuration
803 switch (_system_configuration.version) {
804 case PV_8:
805 strcpy(pci->version, "Power PC 8");
806 break;
807 case PV_7:
808 strcpy(pci->version, "Power PC 7");
809 break;
810 case PV_6_1:
811 strcpy(pci->version, "Power PC 6 DD1.x");
812 break;
813 case PV_6:
814 strcpy(pci->version, "Power PC 6");
815 break;
816 case PV_5:
817 strcpy(pci->version, "Power PC 5");
818 break;
819 case PV_5_2:
820 strcpy(pci->version, "Power PC 5_2");
821 break;
822 case PV_5_3:
823 strcpy(pci->version, "Power PC 5_3");
824 break;
825 case PV_5_Compat:
826 strcpy(pci->version, "PV_5_Compat");
827 break;
828 case PV_6_Compat:
829 strcpy(pci->version, "PV_6_Compat");
830 break;
831 case PV_7_Compat:
832 strcpy(pci->version, "PV_7_Compat");
833 break;
834 case PV_8_Compat:
835 strcpy(pci->version, "PV_8_Compat");
836 break;
837 default:
838 strcpy(pci->version, "unknown");
839 }
840
841 return true;
842
843 } //end os::Aix::get_cpuinfo
844
845 //////////////////////////////////////////////////////////////////////////////
846 // detecting pthread library
847
848 void os::Aix::libpthread_init() {
849 return;
850 }
851
852 //////////////////////////////////////////////////////////////////////////////
853 // create new thread
854
855 // Thread start routine for all newly created threads
856 static void *java_start(Thread *thread) {
952 } // else fall through:
953 // use VMThreadStackSize if CompilerThreadStackSize is not defined
954 case os::vm_thread:
955 case os::pgc_thread:
956 case os::cgc_thread:
957 case os::watcher_thread:
958 if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K);
959 break;
960 }
961 }
962
963 stack_size = MAX2(stack_size, os::Aix::min_stack_allowed);
964 pthread_attr_setstacksize(&attr, stack_size);
965 } //else let thread_create() pick the default value (96 K on AIX)
966
967 pthread_t tid;
968 int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread);
969
970 pthread_attr_destroy(&attr);
971
972 if (ret == 0) {
973 // PPC port traceOsMisc(("Created New Thread : pthread-id %u", tid));
974 } else {
975 if (PrintMiscellaneous && (Verbose || WizardMode)) {
976 perror("pthread_create()");
977 }
978 // Need to clean up stuff we've allocated so far
979 thread->set_osthread(NULL);
980 delete osthread;
981 return false;
982 }
983
984 // Store pthread info into the OSThread
985 osthread->set_pthread_id(tid);
986
987 return true;
988 }
989
990 /////////////////////////////////////////////////////////////////////////////
991 // attach existing thread
992
993 // bootstrap the main thread
994 bool os::create_main_thread(JavaThread* thread) {
1115 }
1116 }
1117
1118 jlong os::javaTimeMillis() {
1119 timeval time;
1120 int status = gettimeofday(&time, NULL);
1121 assert(status != -1, "aix error at gettimeofday()");
1122 return jlong(time.tv_sec) * 1000 + jlong(time.tv_usec / 1000);
1123 }
1124
1125 // We need to manually declare mread_real_time,
1126 // because IBM didn't provide a prototype in time.h.
1127 // (they probably only ever tested in C, not C++)
1128 extern "C"
1129 int mread_real_time(timebasestruct_t *t, size_t size_of_timebasestruct_t);
1130
1131 jlong os::javaTimeNanos() {
1132 if (os::Aix::on_pase()) {
1133 Unimplemented();
1134 return 0;
1135 } else {
1136 // On AIX use the precision of processors real time clock
1137 // or time base registers.
1138 timebasestruct_t time;
1139 int rc;
1140
1141 // If the CPU has a time register, it will be used and
1142 // we have to convert to real time first. After convertion we have following data:
1143 // time.tb_high [seconds since 00:00:00 UTC on 1.1.1970]
1144 // time.tb_low [nanoseconds after the last full second above]
1145 // We better use mread_real_time here instead of read_real_time
1146 // to ensure that we will get a monotonic increasing time.
1147 if (mread_real_time(&time, TIMEBASE_SZ) != RTC_POWER) {
1148 rc = time_base_to_time(&time, TIMEBASE_SZ);
1149 assert(rc != -1, "aix error at time_base_to_time()");
1150 }
1151 return jlong(time.tb_high) * (1000 * 1000 * 1000) + jlong(time.tb_low);
1152 }
1153 }
1154
1155 void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
1163 // Return the real, user, and system times in seconds from an
1164 // arbitrary fixed point in the past.
1165 bool os::getTimesSecs(double* process_real_time,
1166 double* process_user_time,
1167 double* process_system_time) {
1168 struct tms ticks;
1169 clock_t real_ticks = times(&ticks);
1170
1171 if (real_ticks == (clock_t) (-1)) {
1172 return false;
1173 } else {
1174 double ticks_per_second = (double) clock_tics_per_sec;
1175 *process_user_time = ((double) ticks.tms_utime) / ticks_per_second;
1176 *process_system_time = ((double) ticks.tms_stime) / ticks_per_second;
1177 *process_real_time = ((double) real_ticks) / ticks_per_second;
1178
1179 return true;
1180 }
1181 }
1182
1183 char * os::local_time_string(char *buf, size_t buflen) {
1184 struct tm t;
1185 time_t long_time;
1186 time(&long_time);
1187 localtime_r(&long_time, &t);
1188 jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d",
1189 t.tm_year + 1900, t.tm_mon + 1, t.tm_mday,
1190 t.tm_hour, t.tm_min, t.tm_sec);
1191 return buf;
1192 }
1193
1194 struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
1195 return localtime_r(clock, res);
1196 }
1197
1198 ////////////////////////////////////////////////////////////////////////////////
1199 // runtime exit support
1200
1201 // Note: os::shutdown() might be called very early during initialization, or
1202 // called from signal handler. Before adding something to os::shutdown(), make
1203 // sure it is async-safe and can handle partially initialized VM.
1204 void os::shutdown() {
1205
1206 // allow PerfMemory to attempt cleanup of any persistent resources
1207 perfMemory_exit();
1208
1209 // needs to remove object in file system
1210 AttachListener::abort();
1211
1212 // flush buffered output, finish log files
1213 ostream_abort();
1214
1215 // Check for abort hook
1216 abort_hook_t abort_hook = Arguments::abort_hook();
1217 if (abort_hook != NULL) {
1218 abort_hook();
1219 }
1220 }
1221
1222 // Note: os::abort() might be called very early during initialization, or
1223 // called from signal handler. Before adding something to os::abort(), make
1224 // sure it is async-safe and can handle partially initialized VM.
1225 void os::abort(bool dump_core) {
1226 os::shutdown();
1227 if (dump_core) {
1228 #ifndef PRODUCT
1229 fdStream out(defaultStream::output_fd());
1230 out.print_raw("Current thread is ");
1231 char buf[16];
1232 jio_snprintf(buf, sizeof(buf), UINTX_FORMAT, os::current_thread_id());
1233 out.print_raw_cr(buf);
1234 out.print_raw_cr("Dumping core ...");
1235 #endif
1236 ::abort(); // dump core
1237 }
1238
1239 ::exit(1);
1240 }
1241
1242 // Die immediately, no exit hook, no abort hook, no cleanup.
1243 void os::die() {
1244 ::abort();
1245 }
1246
1247 // This method is a copy of JDK's sysGetLastErrorString
1248 // from src/solaris/hpi/src/system_md.c
1249
1250 size_t os::lasterror(char *buf, size_t len) {
1251 if (errno == 0) return 0;
1252
1253 const char *s = ::strerror(errno);
1254 size_t n = ::strlen(s);
1255 if (n >= len) {
1256 n = len - 1;
1257 }
1258 ::strncpy(buf, s, n);
1259 buf[n] = '\0';
1260 return n;
1261 }
1262
1263 intx os::current_thread_id() { return (intx)pthread_self(); }
1264
1265 int os::current_process_id() {
1266
1267 // This implementation returns a unique pid, the pid of the
1268 // launcher thread that starts the vm 'process'.
1269
1270 // Under POSIX, getpid() returns the same pid as the
1271 // launcher thread rather than a unique pid per thread.
1272 // Use gettid() if you want the old pre NPTL behaviour.
1273
1274 // if you are looking for the result of a call to getpid() that
1275 // returns a unique pid for the calling thread, then look at the
1276 // OSThread::thread_id() method in osThread_linux.hpp file
1277
1278 return (int)(_initial_pid ? _initial_pid : getpid());
1279 }
1280
1281 // DLL functions
1282
1283 const char* os::dll_file_extension() { return ".so"; }
1284
1381 return p;
1382 } else {
1383 lib = LoadedLibraries::find_for_data_address(p);
1384 if (lib) {
1385 // pointer to data segment, potential function descriptor
1386 address code_entry = (address)(((FunctionDescriptor*)p)->entry());
1387 if (LoadedLibraries::find_for_text_address(code_entry)) {
1388 // Its a function descriptor
1389 return code_entry;
1390 }
1391 }
1392 }
1393 return NULL;
1394 }
1395
1396 bool os::dll_address_to_function_name(address addr, char *buf,
1397 int buflen, int *offset) {
1398 if (offset) {
1399 *offset = -1;
1400 }
1401 // Buf is not optional, but offset is optional.
1402 assert(buf != NULL, "sanity check");
1403 buf[0] = '\0';
1404
1405 // Resolve function ptr literals first.
1406 addr = resolve_function_descriptor_to_code_pointer(addr);
1407 if (!addr) {
1408 return false;
1409 }
1410
1411 // Go through Decoder::decode to call getFuncName which reads the name from the traceback table.
1412 return Decoder::decode(addr, buf, buflen, offset);
1413 }
1414
1415 static int getModuleName(codeptr_t pc, // [in] program counter
1416 char* p_name, size_t namelen, // [out] optional: function name
1417 char* p_errmsg, size_t errmsglen // [out] optional: user provided buffer for error messages
1418 ) {
1419
1420 // initialize output parameters
1421 if (p_name && namelen > 0) {
1422 *p_name = '\0';
1423 }
1424 if (p_errmsg && errmsglen > 0) {
1425 *p_errmsg = '\0';
1426 }
1427
1428 const LoadedLibraryModule* const lib = LoadedLibraries::find_for_text_address((address)pc);
1429 if (lib) {
1430 if (p_name && namelen > 0) {
1431 sprintf(p_name, "%.*s", namelen, lib->get_shortname());
1432 }
1433 return 0;
1434 }
1435
1436 trcVerbose("pc outside any module");
1437
1438 return -1;
1439 }
1440
1441 bool os::dll_address_to_library_name(address addr, char* buf,
1442 int buflen, int* offset) {
1443 if (offset) {
1444 *offset = -1;
1445 }
1446 // Buf is not optional, but offset is optional.
1447 assert(buf != NULL, "sanity check");
1448 buf[0] = '\0';
1449
1450 // Resolve function ptr literals first.
1451 addr = resolve_function_descriptor_to_code_pointer(addr);
1452 if (!addr) {
1453 return false;
1454 }
1455
1456 if (::getModuleName((codeptr_t) addr, buf, buflen, 0, 0) == 0) {
1457 return true;
1458 }
1459 return false;
1460 }
1461
1462 // Loads .dll/.so and in case of error it checks if .dll/.so was built
1463 // for the same architecture as Hotspot is running on.
1464 void *os::dll_load(const char *filename, char *ebuf, int ebuflen) {
1465
1466 if (ebuf && ebuflen > 0) {
1467 ebuf[0] = '\0';
1468 ebuf[ebuflen - 1] = '\0';
1469 }
1470
1471 if (!filename || strlen(filename) == 0) {
1472 ::strncpy(ebuf, "dll_load: empty filename specified", ebuflen - 1);
1473 return NULL;
1474 }
1475
1476 // RTLD_LAZY is currently not implemented. The dl is loaded immediately with all its dependants.
1477 void * result= ::dlopen(filename, RTLD_LAZY);
1478 if (result != NULL) {
1479 // Reload dll cache. Don't do this in signal handling.
1480 LoadedLibraries::reload();
1481 return result;
1482 } else {
1483 // error analysis when dlopen fails
1606 st->print_cr(" (no more information available)");
1607 }
1608 }
1609
1610 void os::pd_print_cpu_info(outputStream* st) {
1611 // cpu
1612 st->print("CPU:");
1613 st->print("total %d", os::processor_count());
1614 // It's not safe to query number of active processors after crash
1615 // st->print("(active %d)", os::active_processor_count());
1616 st->print(" %s", VM_Version::cpu_features());
1617 st->cr();
1618 }
1619
1620 void os::print_siginfo(outputStream* st, void* siginfo) {
1621 // Use common posix version.
1622 os::Posix::print_siginfo_brief(st, (const siginfo_t*) siginfo);
1623 st->cr();
1624 }
1625
1626 static void print_signal_handler(outputStream* st, int sig,
1627 char* buf, size_t buflen);
1628
1629 void os::print_signal_handlers(outputStream* st, char* buf, size_t buflen) {
1630 st->print_cr("Signal Handlers:");
1631 print_signal_handler(st, SIGSEGV, buf, buflen);
1632 print_signal_handler(st, SIGBUS , buf, buflen);
1633 print_signal_handler(st, SIGFPE , buf, buflen);
1634 print_signal_handler(st, SIGPIPE, buf, buflen);
1635 print_signal_handler(st, SIGXFSZ, buf, buflen);
1636 print_signal_handler(st, SIGILL , buf, buflen);
1637 print_signal_handler(st, INTERRUPT_SIGNAL, buf, buflen);
1638 print_signal_handler(st, SR_signum, buf, buflen);
1639 print_signal_handler(st, SHUTDOWN1_SIGNAL, buf, buflen);
1640 print_signal_handler(st, SHUTDOWN2_SIGNAL , buf, buflen);
1641 print_signal_handler(st, SHUTDOWN3_SIGNAL , buf, buflen);
1642 print_signal_handler(st, BREAK_SIGNAL, buf, buflen);
1643 print_signal_handler(st, SIGTRAP, buf, buflen);
1644 print_signal_handler(st, SIGDANGER, buf, buflen);
1645 }
1646
1647 static char saved_jvm_path[MAXPATHLEN] = {0};
1648
1649 // Find the full path to the current module, libjvm.so.
1650 void os::jvm_path(char *buf, jint buflen) {
1651 // Error checking.
1652 if (buflen < MAXPATHLEN) {
1653 assert(false, "must use a large-enough buffer");
1654 buf[0] = '\0';
1655 return;
1656 }
1657 // Lazy resolve the path to current module.
1658 if (saved_jvm_path[0] != 0) {
1659 strcpy(buf, saved_jvm_path);
1660 return;
1661 }
1662
1663 Dl_info dlinfo;
1664 int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo);
1665 assert(ret != 0, "cannot locate libjvm");
1666 char* rp = realpath((char *)dlinfo.dli_fname, buf);
1667 assert(rp != NULL, "error in realpath(): maybe the 'path' argument is too long?");
1668
1669 strncpy(saved_jvm_path, buf, sizeof(saved_jvm_path));
2862 57, // 5 NormPriority
2863 57, // 6
2864
2865 58, // 7
2866 58, // 8
2867 59, // 9 NearMaxPriority
2868
2869 60, // 10 MaxPriority
2870
2871 60 // 11 CriticalPriority
2872 };
2873
2874 OSReturn os::set_native_priority(Thread* thread, int newpri) {
2875 if (!UseThreadPriorities) return OS_OK;
2876 pthread_t thr = thread->osthread()->pthread_id();
2877 int policy = SCHED_OTHER;
2878 struct sched_param param;
2879 param.sched_priority = newpri;
2880 int ret = pthread_setschedparam(thr, policy, ¶m);
2881
2882 if (ret != 0) {
2883 trcVerbose("Could not change priority for thread %d to %d (error %d, %s)",
2884 (int)thr, newpri, ret, strerror(ret));
2885 }
2886 return (ret == 0) ? OS_OK : OS_ERR;
2887 }
2888
2889 OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) {
2890 if (!UseThreadPriorities) {
2891 *priority_ptr = java_to_os_priority[NormPriority];
2892 return OS_OK;
2893 }
2894 pthread_t thr = thread->osthread()->pthread_id();
2895 int policy = SCHED_OTHER;
2896 struct sched_param param;
2897 int ret = pthread_getschedparam(thr, &policy, ¶m);
2898 *priority_ptr = param.sched_priority;
2899
2900 return (ret == 0) ? OS_OK : OS_ERR;
2901 }
2902
2903 // Hint to the underlying OS that a task switch would not be good.
2904 // Void return because it's a hint and can fail.
2905 void os::hint_no_preempt() {}
2985 }
2986
2987 } else if (state == os::SuspendResume::SR_RUNNING) {
2988 // request was cancelled, continue
2989 } else {
2990 ShouldNotReachHere();
2991 }
2992
2993 resume_clear_context(osthread);
2994 } else if (current == os::SuspendResume::SR_RUNNING) {
2995 // request was cancelled, continue
2996 } else if (current == os::SuspendResume::SR_WAKEUP_REQUEST) {
2997 // ignore
2998 } else {
2999 ShouldNotReachHere();
3000 }
3001
3002 errno = old_errno;
3003 }
3004
3005 static int SR_initialize() {
3006 struct sigaction act;
3007 char *s;
3008 // Get signal number to use for suspend/resume
3009 if ((s = ::getenv("_JAVA_SR_SIGNUM")) != 0) {
3010 int sig = ::strtol(s, 0, 10);
3011 if (sig > 0 || sig < NSIG) {
3012 SR_signum = sig;
3013 }
3014 }
3015
3016 assert(SR_signum > SIGSEGV && SR_signum > SIGBUS,
3017 "SR_signum must be greater than max(SIGSEGV, SIGBUS), see 4355769");
3018
3019 sigemptyset(&SR_sigset);
3020 sigaddset(&SR_sigset, SR_signum);
3021
3022 // Set up signal handler for suspend/resume.
3023 act.sa_flags = SA_RESTART|SA_SIGINFO;
3024 act.sa_handler = (void (*)(int)) SR_handler;
3183 ::sigemptyset(&set);
3184 ::sigaddset(&set, SIGILL);
3185 ::sigaddset(&set, SIGBUS);
3186 ::sigaddset(&set, SIGFPE);
3187 ::sigaddset(&set, SIGSEGV);
3188 return set_thread_signal_mask(SIG_UNBLOCK, &set, NULL);
3189 }
3190
3191 // Renamed from 'signalHandler' to avoid collision with other shared libs.
3192 void javaSignalHandler(int sig, siginfo_t* info, void* uc) {
3193 assert(info != NULL && uc != NULL, "it must be old kernel");
3194
3195 // Never leave program error signals blocked;
3196 // on all our platforms they would bring down the process immediately when
3197 // getting raised while being blocked.
3198 unblock_program_error_signals();
3199
3200 JVM_handle_aix_signal(sig, info, uc, true);
3201 }
3202
3203 // This boolean allows users to forward their own non-matching signals
3204 // to JVM_handle_aix_signal, harmlessly.
3205 bool os::Aix::signal_handlers_are_installed = false;
3206
3207 // For signal-chaining
3208 struct sigaction os::Aix::sigact[MAXSIGNUM];
3209 unsigned int os::Aix::sigs = 0;
3210 bool os::Aix::libjsig_is_loaded = false;
3211 typedef struct sigaction *(*get_signal_t)(int);
3212 get_signal_t os::Aix::get_signal_action = NULL;
3213
3214 struct sigaction* os::Aix::get_chained_signal_action(int sig) {
3215 struct sigaction *actp = NULL;
3216
3217 if (libjsig_is_loaded) {
3218 // Retrieve the old signal handler from libjsig
3219 actp = (*get_signal_action)(sig);
3220 }
3221 if (actp == NULL) {
3222 // Retrieve the preinstalled signal handler from jvm
3376 get_signal_action = CAST_TO_FN_PTR(get_signal_t,
3377 dlsym(RTLD_DEFAULT, "JVM_get_signal_action"));
3378 libjsig_is_loaded = true;
3379 assert(UseSignalChaining, "should enable signal-chaining");
3380 }
3381 if (libjsig_is_loaded) {
3382 // Tell libjsig jvm is setting signal handlers
3383 (*begin_signal_setting)();
3384 }
3385
3386 set_signal_handler(SIGSEGV, true);
3387 set_signal_handler(SIGPIPE, true);
3388 set_signal_handler(SIGBUS, true);
3389 set_signal_handler(SIGILL, true);
3390 set_signal_handler(SIGFPE, true);
3391 set_signal_handler(SIGTRAP, true);
3392 set_signal_handler(SIGXFSZ, true);
3393 set_signal_handler(SIGDANGER, true);
3394
3395 if (libjsig_is_loaded) {
3396 // Tell libjsig jvm finishes setting signal handlers.
3397 (*end_signal_setting)();
3398 }
3399
3400 // We don't activate signal checker if libjsig is in place, we trust ourselves
3401 // and if UserSignalHandler is installed all bets are off.
3402 // Log that signal checking is off only if -verbose:jni is specified.
3403 if (CheckJNICalls) {
3404 if (libjsig_is_loaded) {
3405 tty->print_cr("Info: libjsig is activated, all active signal checking is disabled");
3406 check_signals = false;
3407 }
3408 if (AllowUserSignalHandlers) {
3409 tty->print_cr("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled");
3410 check_signals = false;
3411 }
3412 // Need to initialize check_signal_done.
3413 ::sigemptyset(&check_signal_done);
3414 }
3415 }
3416 }
3417
3418 static const char* get_signal_handler_name(address handler,
3419 char* buf, int buflen) {
3420 int offset;
3421 bool found = os::dll_address_to_library_name(handler, buf, buflen, &offset);
3422 if (found) {
3423 // skip directory names
3424 const char *p1, *p2;
3425 p1 = buf;
3426 size_t len = strlen(os::file_separator());
3427 while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len;
3428 // The way os::dll_address_to_library_name is implemented on Aix
3429 // right now, it always returns -1 for the offset which is not
3430 // terribly informative.
3431 // Will fix that. For now, omit the offset.
3432 jio_snprintf(buf, buflen, "%s", p1);
3466 sa.sa_flags = VMError::get_resetted_sigflags(sig);
3467 }
3468
3469 // Print textual representation of sa_flags.
3470 st->print(", sa_flags=");
3471 os::Posix::print_sa_flags(st, sa.sa_flags);
3472
3473 // Check: is it our handler?
3474 if (handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)javaSignalHandler) ||
3475 handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler)) {
3476 // It is our signal handler.
3477 // Check for flags, reset system-used one!
3478 if ((int)sa.sa_flags != os::Aix::get_our_sigflags(sig)) {
3479 st->print(", flags was changed from " PTR32_FORMAT ", consider using jsig library",
3480 os::Aix::get_our_sigflags(sig));
3481 }
3482 }
3483 st->cr();
3484 }
3485
3486 #define DO_SIGNAL_CHECK(sig) \
3487 if (!sigismember(&check_signal_done, sig)) \
3488 os::Aix::check_signal_handler(sig)
3489
3490 // This method is a periodic task to check for misbehaving JNI applications
3491 // under CheckJNI, we can add any periodic checks here
3492
3493 void os::run_periodic_checks() {
3494
3495 if (check_signals == false) return;
3496
3497 // SEGV and BUS if overridden could potentially prevent
3498 // generation of hs*.log in the event of a crash, debugging
3499 // such a case can be very challenging, so we absolutely
3500 // check the following for a good measure:
3501 DO_SIGNAL_CHECK(SIGSEGV);
3502 DO_SIGNAL_CHECK(SIGILL);
3503 DO_SIGNAL_CHECK(SIGFPE);
3504 DO_SIGNAL_CHECK(SIGBUS);
3505 DO_SIGNAL_CHECK(SIGPIPE);
3526
3527 static os_sigaction_t os_sigaction = NULL;
3528
3529 void os::Aix::check_signal_handler(int sig) {
3530 char buf[O_BUFLEN];
3531 address jvmHandler = NULL;
3532
3533 struct sigaction act;
3534 if (os_sigaction == NULL) {
3535 // only trust the default sigaction, in case it has been interposed
3536 os_sigaction = (os_sigaction_t)dlsym(RTLD_DEFAULT, "sigaction");
3537 if (os_sigaction == NULL) return;
3538 }
3539
3540 os_sigaction(sig, (struct sigaction*)NULL, &act);
3541
3542 address thisHandler = (act.sa_flags & SA_SIGINFO)
3543 ? CAST_FROM_FN_PTR(address, act.sa_sigaction)
3544 : CAST_FROM_FN_PTR(address, act.sa_handler);
3545
3546 switch(sig) {
3547 case SIGSEGV:
3548 case SIGBUS:
3549 case SIGFPE:
3550 case SIGPIPE:
3551 case SIGILL:
3552 case SIGXFSZ:
3553 // Renamed 'signalHandler' to avoid collision with other shared libs.
3554 jvmHandler = CAST_FROM_FN_PTR(address, (sa_sigaction_t)javaSignalHandler);
3555 break;
3556
3557 case SHUTDOWN1_SIGNAL:
3558 case SHUTDOWN2_SIGNAL:
3559 case SHUTDOWN3_SIGNAL:
3560 case BREAK_SIGNAL:
3561 jvmHandler = (address)user_handler();
3562 break;
3563
3564 case INTERRUPT_SIGNAL:
3565 jvmHandler = CAST_FROM_FN_PTR(address, SIG_DFL);
3678 fprintf(stderr, " %s ", describe_pagesize(_page_sizes[i]));
3679 }
3680 fprintf(stderr, ")\n");
3681 }
3682
3683 _initial_pid = getpid();
3684
3685 clock_tics_per_sec = sysconf(_SC_CLK_TCK);
3686
3687 init_random(1234567);
3688
3689 ThreadCritical::initialize();
3690
3691 // Main_thread points to the aboriginal thread.
3692 Aix::_main_thread = pthread_self();
3693
3694 initial_time_count = os::elapsed_counter();
3695 pthread_mutex_init(&dl_mutex, NULL);
3696 }
3697
3698 // This is called _after_ the global arguments have been parsed.
3699 jint os::init_2(void) {
3700
3701 trcVerbose("processor count: %d", os::_processor_count);
3702 trcVerbose("physical memory: %lu", Aix::_physical_memory);
3703
3704 // Initially build up the loaded dll map.
3705 LoadedLibraries::reload();
3706
3707 const int page_size = Aix::page_size();
3708 const int map_size = page_size;
3709
3710 address map_address = (address) MAP_FAILED;
3711 const int prot = PROT_READ;
3712 const int flags = MAP_PRIVATE|MAP_ANONYMOUS;
3713
3714 // use optimized addresses for the polling page,
3715 // e.g. map it to a special 32-bit address.
3716 if (OptimizePollingPageLocation) {
3717 // architecture-specific list of address wishes:
3718 address address_wishes[] = {
3719 // AIX: addresses lower than 0x30000000 don't seem to work on AIX.
3720 // PPC64: all address wishes are non-negative 32 bit values where
3721 // the lower 16 bits are all zero. we can load these addresses
3722 // with a single ppc_lis instruction.
3723 (address) 0x30000000, (address) 0x31000000,
3724 (address) 0x32000000, (address) 0x33000000,
3734 // iterate over the list of address wishes:
3735 for (int i=0; i<address_wishes_length; i++) {
3736 // try to map with current address wish.
3737 // AIX: AIX needs MAP_FIXED if we provide an address and mmap will
3738 // fail if the address is already mapped.
3739 map_address = (address) ::mmap(address_wishes[i] - (ssize_t)page_size,
3740 map_size, prot,
3741 flags | MAP_FIXED,
3742 -1, 0);
3743 if (Verbose) {
3744 fprintf(stderr, "SafePoint Polling Page address: %p (wish) => %p\n",
3745 address_wishes[i], map_address + (ssize_t)page_size);
3746 }
3747
3748 if (map_address + (ssize_t)page_size == address_wishes[i]) {
3749 // map succeeded and map_address is at wished address, exit loop.
3750 break;
3751 }
3752
3753 if (map_address != (address) MAP_FAILED) {
3754 // Map succeeded, but polling_page is not at wished address, unmap and continue.
3755 ::munmap(map_address, map_size);
3756 map_address = (address) MAP_FAILED;
3757 }
3758 // map failed, continue loop.
3759 }
3760 } // end OptimizePollingPageLocation
3761
3762 if (map_address == (address) MAP_FAILED) {
3763 map_address = (address) ::mmap(NULL, map_size, prot, flags, -1, 0);
3764 }
3765 guarantee(map_address != MAP_FAILED, "os::init_2: failed to allocate polling page");
3766 os::set_polling_page(map_address);
3767
3768 if (!UseMembar) {
3769 address mem_serialize_page = (address) ::mmap(NULL, Aix::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
3770 guarantee(mem_serialize_page != NULL, "mmap Failed for memory serialize page");
3771 os::set_memory_serialize_page(mem_serialize_page);
3772
3773 #ifndef PRODUCT
3774 if (Verbose && PrintMiscellaneous)
3788 // Check minimum allowable stack size for thread creation and to initialize
3789 // the java system classes, including StackOverflowError - depends on page
3790 // size. Add a page for compiler2 recursion in main thread.
3791 // Add in 2*BytesPerWord times page size to account for VM stack during
3792 // class initialization depending on 32 or 64 bit VM.
3793 os::Aix::min_stack_allowed = MAX2(os::Aix::min_stack_allowed,
3794 (size_t)(StackYellowPages+StackRedPages+StackShadowPages +
3795 2*BytesPerWord COMPILER2_PRESENT(+1)) * Aix::page_size());
3796
3797 size_t threadStackSizeInBytes = ThreadStackSize * K;
3798 if (threadStackSizeInBytes != 0 &&
3799 threadStackSizeInBytes < os::Aix::min_stack_allowed) {
3800 tty->print_cr("\nThe stack size specified is too small, "
3801 "Specify at least %dk",
3802 os::Aix::min_stack_allowed / K);
3803 return JNI_ERR;
3804 }
3805
3806 // Make the stack size a multiple of the page size so that
3807 // the yellow/red zones can be guarded.
3808 // Note that this can be 0, if no default stacksize was set.
3809 JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes, vm_page_size()));
3810
3811 Aix::libpthread_init();
3812
3813 if (MaxFDLimit) {
3814 // set the number of file descriptors to max. print out error
3815 // if getrlimit/setrlimit fails but continue regardless.
3816 struct rlimit nbr_files;
3817 int status = getrlimit(RLIMIT_NOFILE, &nbr_files);
3818 if (status != 0) {
3819 if (PrintMiscellaneous && (Verbose || WizardMode))
3820 perror("os::init_2 getrlimit failed");
3821 } else {
3822 nbr_files.rlim_cur = nbr_files.rlim_max;
3823 status = setrlimit(RLIMIT_NOFILE, &nbr_files);
3824 if (status != 0) {
3825 if (PrintMiscellaneous && (Verbose || WizardMode))
3826 perror("os::init_2 setrlimit failed");
3827 }
3828 }
4079 // suffering from bug 1085341.
4080 //
4081 // (Yes, the default setting of the close-on-exec flag is a Unix
4082 // design flaw.)
4083 //
4084 // See:
4085 // 1085341: 32-bit stdio routines should support file descriptors >255
4086 // 4843136: (process) pipe file descriptor from Runtime.exec not being closed
4087 // 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9
4088 #ifdef FD_CLOEXEC
4089 {
4090 int flags = ::fcntl(fd, F_GETFD);
4091 if (flags != -1)
4092 ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
4093 }
4094 #endif
4095
4096 return fd;
4097 }
4098
4099 // create binary file, rewriting existing file if required
4100 int os::create_binary_file(const char* path, bool rewrite_existing) {
4101 int oflags = O_WRONLY | O_CREAT;
4102 if (!rewrite_existing) {
4103 oflags |= O_EXCL;
4104 }
4105 return ::open64(path, oflags, S_IREAD | S_IWRITE);
4106 }
4107
4108 // return current position of file pointer
4109 jlong os::current_file_offset(int fd) {
4110 return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR);
4111 }
4112
4113 // move file pointer to the specified offset
4114 jlong os::seek_to_file_offset(int fd, jlong offset) {
4115 return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET);
4116 }
4117
4118 // This code originates from JDK's sysAvailable
4138 }
4139 if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) {
4140 return 0;
4141 } else if ((end = ::lseek64(fd, 0L, SEEK_END)) == -1) {
4142 return 0;
4143 } else if (::lseek64(fd, cur, SEEK_SET) == -1) {
4144 return 0;
4145 }
4146 *bytes = end - cur;
4147 return 1;
4148 }
4149
4150 // Map a block of memory.
4151 char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
4152 char *addr, size_t bytes, bool read_only,
4153 bool allow_exec) {
4154 Unimplemented();
4155 return NULL;
4156 }
4157
4158 // Remap a block of memory.
4159 char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset,
4160 char *addr, size_t bytes, bool read_only,
4161 bool allow_exec) {
4162 // same as map_memory() on this OS
4163 return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only,
4164 allow_exec);
4165 }
4166
4167 // Unmap a block of memory.
4168 bool os::pd_unmap_memory(char* addr, size_t bytes) {
4169 return munmap(addr, bytes) == 0;
4170 }
4171
4172 // current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool)
4173 // are used by JVM M&M and JVMTI to get user+sys or user CPU time
4174 // of a thread.
4175 //
4176 // current_thread_cpu_time() and thread_cpu_time(Thread*) returns
4177 // the fast estimate available on the platform.
4185
4186 jlong os::thread_cpu_time(Thread* thread) {
4187 // consistent with what current_thread_cpu_time() returns
4188 const jlong n = os::thread_cpu_time(thread, true /* user + sys */);
4189 assert(n >= 0, "negative CPU time");
4190 return n;
4191 }
4192
4193 jlong os::current_thread_cpu_time(bool user_sys_cpu_time) {
4194 const jlong n = os::thread_cpu_time(Thread::current(), user_sys_cpu_time);
4195 assert(n >= 0, "negative CPU time");
4196 return n;
4197 }
4198
4199 static bool thread_cpu_time_unchecked(Thread* thread, jlong* p_sys_time, jlong* p_user_time) {
4200 bool error = false;
4201
4202 jlong sys_time = 0;
4203 jlong user_time = 0;
4204
4205 // Reimplemented using getthrds64().
4206 //
4207 // Works like this:
4208 // For the thread in question, get the kernel thread id. Then get the
4209 // kernel thread statistics using that id.
4210 //
4211 // This only works of course when no pthread scheduling is used,
4212 // i.e. there is a 1:1 relationship to kernel threads.
4213 // On AIX, see AIXTHREAD_SCOPE variable.
4214
4215 pthread_t pthtid = thread->osthread()->pthread_id();
4216
4217 // retrieve kernel thread id for the pthread:
4218 tid64_t tid = 0;
4219 struct __pthrdsinfo pinfo;
4220 // I just love those otherworldly IBM APIs which force me to hand down
4221 // dummy buffers for stuff I dont care for...
4222 char dummy[1];
4223 int dummy_size = sizeof(dummy);
4224 if (pthread_getthrds_np(&pthtid, PTHRDSINFO_QUERY_TID, &pinfo, sizeof(pinfo),
4225 dummy, &dummy_size) == 0) {
4226 tid = pinfo.__pi_tid;
4227 } else {
4228 tty->print_cr("pthread_getthrds_np failed.");
4229 error = true;
4230 }
4231
4232 // retrieve kernel timing info for that kernel thread
4339 }
4340
4341 bool os::Aix::is_primordial_thread() {
4342 if (pthread_self() == (pthread_t)1) {
4343 return true;
4344 } else {
4345 return false;
4346 }
4347 }
4348
4349 // OS recognitions (PASE/AIX, OS level) call this before calling any
4350 // one of Aix::on_pase(), Aix::os_version() static
4351 void os::Aix::initialize_os_info() {
4352
4353 assert(_on_pase == -1 && _os_version == -1, "already called.");
4354
4355 struct utsname uts;
4356 memset(&uts, 0, sizeof(uts));
4357 strcpy(uts.sysname, "?");
4358 if (::uname(&uts) == -1) {
4359 trc("uname failed (%d)", errno);
4360 guarantee(0, "Could not determine whether we run on AIX or PASE");
4361 } else {
4362 trcVerbose("uname says: sysname \"%s\" version \"%s\" release \"%s\" "
4363 "node \"%s\" machine \"%s\"\n",
4364 uts.sysname, uts.version, uts.release, uts.nodename, uts.machine);
4365 const int major = atoi(uts.version);
4366 assert(major > 0, "invalid OS version");
4367 const int minor = atoi(uts.release);
4368 assert(minor > 0, "invalid OS release");
4369 _os_version = (major << 8) | minor;
4370 if (strcmp(uts.sysname, "OS400") == 0) {
4371 Unimplemented();
4372 } else if (strcmp(uts.sysname, "AIX") == 0) {
4373 // We run on AIX. We do not support versions older than AIX 5.3.
4374 _on_pase = 0;
4375 if (_os_version < 0x0503) {
4376 trc("AIX release older than AIX 5.3 not supported.");
4377 assert(false, "AIX release too old.");
4378 } else {
4379 trcVerbose("We run on AIX %d.%d\n", major, minor);
4380 }
4381 } else {
4382 assert(false, "unknown OS");
4383 }
4384 }
4385
4386 guarantee(_on_pase != -1 && _os_version, "Could not determine AIX/OS400 release");
4387 } // end: os::Aix::initialize_os_info()
4388
4389 // Scan environment for important settings which might effect the VM.
4390 // Trace out settings. Warn about invalid settings and/or correct them.
4391 //
4392 // Must run after os::Aix::initialue_os_info().
4393 void os::Aix::scan_environment() {
4394
4395 char* p;
4396 int rc;
4397
4398 // Warn explicity if EXTSHM=ON is used. That switch changes how
4399 // System V shared memory behaves. One effect is that page size of
4400 // shared memory cannot be change dynamically, effectivly preventing
4401 // large pages from working.
4402 // This switch was needed on AIX 32bit, but on AIX 64bit the general
4403 // recommendation is (in OSS notes) to switch it off.
4404 p = ::getenv("EXTSHM");
4405 if (Verbose) {
4406 fprintf(stderr, "EXTSHM=%s.\n", p ? p : "<unset>");
4407 }
4408 if (p && strcmp(p, "ON") == 0) {
4409 fprintf(stderr, "Unsupported setting: EXTSHM=ON. Large Page support will be disabled.\n");
4410 _extshm = 1;
4411 } else {
4412 _extshm = 0;
4413 }
4414
4415 // SPEC1170 behaviour: will change the behaviour of a number of POSIX APIs.
4416 // Not tested, not supported.
4417 //
4418 // Note that it might be worth the trouble to test and to require it, if only to
4419 // get useful return codes for mprotect.
4420 //
4421 // Note: Setting XPG_SUS_ENV in the process is too late. Must be set earlier (before
4422 // exec() ? before loading the libjvm ? ....)
4423 p = ::getenv("XPG_SUS_ENV");
4424 trcVerbose("XPG_SUS_ENV=%s.", p ? p : "<unset>");
4425 if (p && strcmp(p, "ON") == 0) {
4426 _xpg_sus_mode = 1;
4427 trc("Unsupported setting: XPG_SUS_ENV=ON");
4428 // This is not supported. Worst of all, it changes behaviour of mmap MAP_FIXED to
4429 // clobber address ranges. If we ever want to support that, we have to do some
4430 // testing first.
4431 guarantee(false, "XPG_SUS_ENV=ON not supported");
4432 } else {
4433 _xpg_sus_mode = 0;
4434 }
4435
4436 // Switch off AIX internal (pthread) guard pages. This has
4437 // immediate effect for any pthread_create calls which follow.
4438 p = ::getenv("AIXTHREAD_GUARDPAGES");
4439 trcVerbose("AIXTHREAD_GUARDPAGES=%s.", p ? p : "<unset>");
4440 rc = ::putenv("AIXTHREAD_GUARDPAGES=0");
4441 guarantee(rc == 0, "");
4442
4443 } // end: os::Aix::scan_environment()
4444
4445 // PASE: initialize the libo4 library (AS400 PASE porting library).
4446 void os::Aix::initialize_libo4() {
4447 Unimplemented();
4448 }
4449
4450 // AIX: initialize the libperfstat library (we load this dynamically
4451 // because it is only available on AIX.
4452 void os::Aix::initialize_libperfstat() {
4453
4454 assert(os::Aix::on_aix(), "AIX only");
4455
4456 if (!libperfstat::init()) {
4457 trc("libperfstat initialization failed.");
4458 assert(false, "libperfstat initialization failed");
4459 } else {
4460 if (Verbose) {
4461 fprintf(stderr, "libperfstat initialized.\n");
4462 }
4463 }
4464 } // end: os::Aix::initialize_libperfstat
4465
4466 /////////////////////////////////////////////////////////////////////////////
4467 // thread stack
4468
4469 // function to query the current stack size using pthread_getthrds_np
4470 //
4471 // ! do not change anything here unless you know what you are doing !
4472 static void query_stack_dimensions(address* p_stack_base, size_t* p_stack_size) {
4473
4474 // This only works when invoked on a pthread. As we agreed not to use
4475 // primordial threads anyway, I assert here
4476 guarantee(!os::Aix::is_primordial_thread(), "not allowed on the primordial thread");
4477
4609 static struct timespec* compute_abstime(timespec* abstime, jlong millis) {
4610 if (millis < 0) millis = 0;
4611 struct timeval now;
4612 int status = gettimeofday(&now, NULL);
4613 assert(status == 0, "gettimeofday");
4614 jlong seconds = millis / 1000;
4615 millis %= 1000;
4616 if (seconds > 50000000) { // see man cond_timedwait(3T)
4617 seconds = 50000000;
4618 }
4619 abstime->tv_sec = now.tv_sec + seconds;
4620 long usec = now.tv_usec + millis * 1000;
4621 if (usec >= 1000000) {
4622 abstime->tv_sec += 1;
4623 usec -= 1000000;
4624 }
4625 abstime->tv_nsec = usec * 1000;
4626 return abstime;
4627 }
4628
4629 // Test-and-clear _Event, always leaves _Event set to 0, returns immediately.
4630 // Conceptually TryPark() should be equivalent to park(0).
4631
4632 int os::PlatformEvent::TryPark() {
4633 for (;;) {
4634 const int v = _Event;
4635 guarantee ((v == 0) || (v == 1), "invariant");
4636 if (Atomic::cmpxchg (0, &_Event, v) == v) return v;
4637 }
4638 }
4639
4640 void os::PlatformEvent::park() { // AKA "down()"
4641 // Invariant: Only the thread associated with the Event/PlatformEvent
4642 // may call park().
4643 // TODO: assert that _Assoc != NULL or _Assoc == Self
4644 int v;
4645 for (;;) {
4646 v = _Event;
4647 if (Atomic::cmpxchg (v-1, &_Event, v) == v) break;
4648 }
4847
4848 Thread* thread = Thread::current();
4849 assert(thread->is_Java_thread(), "Must be JavaThread");
4850 JavaThread *jt = (JavaThread *)thread;
4851
4852 // Optional optimization -- avoid state transitions if there's an interrupt pending.
4853 // Check interrupt before trying to wait
4854 if (Thread::is_interrupted(thread, false)) {
4855 return;
4856 }
4857
4858 // Next, demultiplex/decode time arguments
4859 timespec absTime;
4860 if (time < 0 || (isAbsolute && time == 0)) { // don't wait at all
4861 return;
4862 }
4863 if (time > 0) {
4864 unpackTime(&absTime, isAbsolute, time);
4865 }
4866
4867 // Enter safepoint region
4868 // Beware of deadlocks such as 6317397.
4869 // The per-thread Parker:: mutex is a classic leaf-lock.
4870 // In particular a thread must never block on the Threads_lock while
4871 // holding the Parker:: mutex. If safepoints are pending both the
4872 // the ThreadBlockInVM() CTOR and DTOR may grab Threads_lock.
4873 ThreadBlockInVM tbivm(jt);
4874
4875 // Don't wait if cannot get lock since interference arises from
4876 // unblocking. Also. check interrupt before trying wait
4877 if (Thread::is_interrupted(thread, false) || pthread_mutex_trylock(_mutex) != 0) {
4878 return;
4879 }
4880
4881 int status;
4882 if (_counter > 0) { // no wait needed
4883 _counter = 0;
4884 status = pthread_mutex_unlock(_mutex);
4885 assert (status == 0, "invariant");
4886 OrderAccess::fence();
4934 s = _counter;
4935 _counter = 1;
4936 if (s < 1) {
4937 if (WorkAroundNPTLTimedWaitHang) {
4938 status = pthread_cond_signal (_cond);
4939 assert (status == 0, "invariant");
4940 status = pthread_mutex_unlock(_mutex);
4941 assert (status == 0, "invariant");
4942 } else {
4943 status = pthread_mutex_unlock(_mutex);
4944 assert (status == 0, "invariant");
4945 status = pthread_cond_signal (_cond);
4946 assert (status == 0, "invariant");
4947 }
4948 } else {
4949 pthread_mutex_unlock(_mutex);
4950 assert (status == 0, "invariant");
4951 }
4952 }
4953
4954 extern char** environ;
4955
4956 // Run the specified command in a separate process. Return its exit value,
4957 // or -1 on failure (e.g. can't fork a new process).
4958 // Unlike system(), this function can be called from signal handler. It
4959 // doesn't block SIGINT et al.
4960 int os::fork_and_exec(char* cmd) {
4961 char * argv[4] = {"sh", "-c", cmd, NULL};
4962
4963 pid_t pid = fork();
4964
4965 if (pid < 0) {
4966 // fork failed
4967 return -1;
4968
4969 } else if (pid == 0) {
4970 // child process
4971
4972 // Try to be consistent with system(), which uses "/usr/bin/sh" on AIX.
4973 execve("/usr/bin/sh", argv, environ);
4974
4975 // execve failed
4976 _exit(-1);
4977
4978 } else {
4979 // copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't
4980 // care about the actual exit code, for now.
4981
4982 int status;
4983
4984 // Wait for the child process to exit. This returns immediately if
4985 // the child has already exited. */
4986 while (waitpid(pid, &status, 0) < 0) {
4987 switch (errno) {
4988 case ECHILD: return 0;
4989 case EINTR: break;
4990 default: return -1;
4991 }
4992 }
4993
4994 if (WIFEXITED(status)) {
4995 // The child exited normally; get its exit code.
4996 return WEXITSTATUS(status);
4997 } else if (WIFSIGNALED(status)) {
4998 // The child exited because of a signal.
4999 // The best value to return is 0x80 + signal number,
5000 // because that is what all Unix shells do, and because
5001 // it allows callers to distinguish between process exit and
5002 // process death by signal.
5003 return 0x80 + WTERMSIG(status);
5004 } else {
5005 // Unknown exit code; pass it through.
5006 return status;
5007 }
5008 }
5009 return -1;
5010 }
5011
5012 // is_headless_jre()
5013 //
5014 // Test for the existence of xawt/libmawt.so or libawt_xawt.so
5015 // in order to report if we are running in a headless jre.
5016 //
5017 // Since JDK8 xawt/libmawt.so is moved into the same directory
5018 // as libawt.so, and renamed libawt_xawt.so
5019 bool os::is_headless_jre() {
5020 struct stat statbuf;
5021 char buf[MAXPATHLEN];
5022 char libmawtpath[MAXPATHLEN];
5023 const char *xawtstr = "/xawt/libmawt.so";
5024 const char *new_xawtstr = "/libawt_xawt.so";
5025
5026 char *p;
5027
5028 // Get path to libjvm.so
|