< prev index next >

src/os/bsd/vm/os_bsd.cpp

Print this page




1546 #endif // !__APPLE__
1547 
1548 void* os::get_default_process_handle() {
1549 #ifdef __APPLE__
1550   // MacOS X needs to use RTLD_FIRST instead of RTLD_LAZY
1551   // to avoid finding unexpected symbols on second (or later)
1552   // loads of a library.
1553   return (void*)::dlopen(NULL, RTLD_FIRST);
1554 #else
1555   return (void*)::dlopen(NULL, RTLD_LAZY);
1556 #endif
1557 }
1558 
1559 // XXX: Do we need a lock around this as per Linux?
1560 void* os::dll_lookup(void* handle, const char* name) {
1561   return dlsym(handle, name);
1562 }
1563 
1564 int _print_dll_info_cb(const char * name, address base_address, address top_address, void * param) {
1565   outputStream * out = (outputStream *) param;
1566   out->print_cr(PTR_FORMAT " \t%s", base_address, name);
1567   return 0;
1568 }
1569 
1570 void os::print_dll_info(outputStream *st) {
1571   st->print_cr("Dynamic libraries:");
1572   if (get_loaded_modules_info(_print_dll_info_cb, (void *)st)) {
1573     st->print_cr("Error: Cannot print dynamic libraries.");
1574   }
1575 }
1576 
1577 int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) {
1578 #ifdef RTLD_DI_LINKMAP
1579   Dl_info dli;
1580   void *handle;
1581   Link_map *map;
1582   Link_map *p;
1583 
1584   if (dladdr(CAST_FROM_FN_PTR(void *, os::print_dll_info), &dli) == 0 ||
1585       dli.dli_fname == NULL) {
1586     return 1;


2100   unlink(buf);
2101 
2102   int fd = ::open(buf, O_CREAT | O_RDWR, S_IRWXU);
2103 
2104   if (fd != -1) {
2105     off_t rv = ::lseek(fd, size-2, SEEK_SET);
2106     if (rv != (off_t)-1) {
2107       if (::write(fd, "", 1) == 1) {
2108         mmap(base, size,
2109              PROT_READ|PROT_WRITE|PROT_EXEC,
2110              MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0);
2111       }
2112     }
2113     ::close(fd);
2114     unlink(buf);
2115   }
2116 }
2117 
2118 static void warn_fail_commit_memory(char* addr, size_t size, bool exec,
2119                                     int err) {
2120   warning("INFO: os::commit_memory(" PTR_FORMAT ", " SIZE_FORMAT
2121           ", %d) failed; error='%s' (errno=%d)", addr, size, exec,
2122           os::errno_name(err), err);
2123 }
2124 
2125 // NOTE: Bsd kernel does not really reserve the pages for us.
2126 //       All it does is to check if there are enough free pages
2127 //       left at the time of mmap(). This could be a potential
2128 //       problem.
2129 bool os::pd_commit_memory(char* addr, size_t size, bool exec) {
2130   int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
2131 #ifdef __OpenBSD__
2132   // XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
2133   if (::mprotect(addr, size, prot) == 0) {
2134     return true;
2135   }
2136 #else
2137   uintptr_t res = (uintptr_t) ::mmap(addr, size, prot,
2138                                      MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
2139   if (res != (uintptr_t) MAP_FAILED) {
2140     return true;
2141   }


3612 
3613 // Suspends the target using the signal mechanism and then grabs the PC before
3614 // resuming the target. Used by the flat-profiler only
3615 ExtendedPC os::get_thread_pc(Thread* thread) {
3616   // Make sure that it is called by the watcher for the VMThread
3617   assert(Thread::current()->is_Watcher_thread(), "Must be watcher");
3618   assert(thread->is_VM_thread(), "Can only be called for VMThread");
3619 
3620   PcFetcher fetcher(thread);
3621   fetcher.run();
3622   return fetcher.result();
3623 }
3624 
3625 ////////////////////////////////////////////////////////////////////////////////
3626 // debug support
3627 
3628 bool os::find(address addr, outputStream* st) {
3629   Dl_info dlinfo;
3630   memset(&dlinfo, 0, sizeof(dlinfo));
3631   if (dladdr(addr, &dlinfo) != 0) {
3632     st->print(PTR_FORMAT ": ", addr);
3633     if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
3634       st->print("%s+%#x", dlinfo.dli_sname,
3635                 addr - (intptr_t)dlinfo.dli_saddr);
3636     } else if (dlinfo.dli_fbase != NULL) {
3637       st->print("<offset %#x>", addr - (intptr_t)dlinfo.dli_fbase);
3638     } else {
3639       st->print("<absolute address>");
3640     }
3641     if (dlinfo.dli_fname != NULL) {
3642       st->print(" in %s", dlinfo.dli_fname);
3643     }
3644     if (dlinfo.dli_fbase != NULL) {
3645       st->print(" at " PTR_FORMAT, dlinfo.dli_fbase);
3646     }
3647     st->cr();
3648 
3649     if (Verbose) {
3650       // decode some bytes around the PC
3651       address begin = clamp_address_in_page(addr-40, addr, os::vm_page_size());
3652       address end   = clamp_address_in_page(addr+40, addr, os::vm_page_size());
3653       address       lowest = (address) dlinfo.dli_sname;
3654       if (!lowest)  lowest = (address) dlinfo.dli_fbase;
3655       if (begin < lowest)  begin = lowest;
3656       Dl_info dlinfo2;
3657       if (dladdr(end, &dlinfo2) != 0 && dlinfo2.dli_saddr != dlinfo.dli_saddr
3658           && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin) {
3659         end = (address) dlinfo2.dli_saddr;
3660       }
3661       Disassembler::decode(begin, end, st);
3662     }
3663     return true;
3664   }
3665   return false;




1546 #endif // !__APPLE__
1547 
1548 void* os::get_default_process_handle() {
1549 #ifdef __APPLE__
1550   // MacOS X needs to use RTLD_FIRST instead of RTLD_LAZY
1551   // to avoid finding unexpected symbols on second (or later)
1552   // loads of a library.
1553   return (void*)::dlopen(NULL, RTLD_FIRST);
1554 #else
1555   return (void*)::dlopen(NULL, RTLD_LAZY);
1556 #endif
1557 }
1558 
1559 // XXX: Do we need a lock around this as per Linux?
1560 void* os::dll_lookup(void* handle, const char* name) {
1561   return dlsym(handle, name);
1562 }
1563 
1564 int _print_dll_info_cb(const char * name, address base_address, address top_address, void * param) {
1565   outputStream * out = (outputStream *) param;
1566   out->print_cr(INTPTR_FORMAT " \t%s", (intptr_t)base_address, name);
1567   return 0;
1568 }
1569 
1570 void os::print_dll_info(outputStream *st) {
1571   st->print_cr("Dynamic libraries:");
1572   if (get_loaded_modules_info(_print_dll_info_cb, (void *)st)) {
1573     st->print_cr("Error: Cannot print dynamic libraries.");
1574   }
1575 }
1576 
1577 int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) {
1578 #ifdef RTLD_DI_LINKMAP
1579   Dl_info dli;
1580   void *handle;
1581   Link_map *map;
1582   Link_map *p;
1583 
1584   if (dladdr(CAST_FROM_FN_PTR(void *, os::print_dll_info), &dli) == 0 ||
1585       dli.dli_fname == NULL) {
1586     return 1;


2100   unlink(buf);
2101 
2102   int fd = ::open(buf, O_CREAT | O_RDWR, S_IRWXU);
2103 
2104   if (fd != -1) {
2105     off_t rv = ::lseek(fd, size-2, SEEK_SET);
2106     if (rv != (off_t)-1) {
2107       if (::write(fd, "", 1) == 1) {
2108         mmap(base, size,
2109              PROT_READ|PROT_WRITE|PROT_EXEC,
2110              MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0);
2111       }
2112     }
2113     ::close(fd);
2114     unlink(buf);
2115   }
2116 }
2117 
2118 static void warn_fail_commit_memory(char* addr, size_t size, bool exec,
2119                                     int err) {
2120   warning("INFO: os::commit_memory(" INTPTR_FORMAT ", " SIZE_FORMAT
2121           ", %d) failed; error='%s' (errno=%d)", (intptr_t)addr, size, exec,
2122            os::errno_name(err), err);
2123 }
2124 
2125 // NOTE: Bsd kernel does not really reserve the pages for us.
2126 //       All it does is to check if there are enough free pages
2127 //       left at the time of mmap(). This could be a potential
2128 //       problem.
2129 bool os::pd_commit_memory(char* addr, size_t size, bool exec) {
2130   int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
2131 #ifdef __OpenBSD__
2132   // XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
2133   if (::mprotect(addr, size, prot) == 0) {
2134     return true;
2135   }
2136 #else
2137   uintptr_t res = (uintptr_t) ::mmap(addr, size, prot,
2138                                      MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
2139   if (res != (uintptr_t) MAP_FAILED) {
2140     return true;
2141   }


3612 
3613 // Suspends the target using the signal mechanism and then grabs the PC before
3614 // resuming the target. Used by the flat-profiler only
3615 ExtendedPC os::get_thread_pc(Thread* thread) {
3616   // Make sure that it is called by the watcher for the VMThread
3617   assert(Thread::current()->is_Watcher_thread(), "Must be watcher");
3618   assert(thread->is_VM_thread(), "Can only be called for VMThread");
3619 
3620   PcFetcher fetcher(thread);
3621   fetcher.run();
3622   return fetcher.result();
3623 }
3624 
3625 ////////////////////////////////////////////////////////////////////////////////
3626 // debug support
3627 
3628 bool os::find(address addr, outputStream* st) {
3629   Dl_info dlinfo;
3630   memset(&dlinfo, 0, sizeof(dlinfo));
3631   if (dladdr(addr, &dlinfo) != 0) {
3632     st->print(INTPTR_FORMAT ": ", (intptr_t)addr);
3633     if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
3634       st->print("%s+%#x", dlinfo.dli_sname,
3635                 (uint)((uintptr_t)addr - (uintptr_t)dlinfo.dli_saddr));
3636     } else if (dlinfo.dli_fbase != NULL) {
3637       st->print("<offset %#x>", (uint)((uintptr_t)addr - (uintptr_t)dlinfo.dli_fbase));
3638     } else {
3639       st->print("<absolute address>");
3640     }
3641     if (dlinfo.dli_fname != NULL) {
3642       st->print(" in %s", dlinfo.dli_fname);
3643     }
3644     if (dlinfo.dli_fbase != NULL) {
3645       st->print(" at " INTPTR_FORMAT, (intptr_t)dlinfo.dli_fbase);
3646     }
3647     st->cr();
3648 
3649     if (Verbose) {
3650       // decode some bytes around the PC
3651       address begin = clamp_address_in_page(addr-40, addr, os::vm_page_size());
3652       address end   = clamp_address_in_page(addr+40, addr, os::vm_page_size());
3653       address       lowest = (address) dlinfo.dli_sname;
3654       if (!lowest)  lowest = (address) dlinfo.dli_fbase;
3655       if (begin < lowest)  begin = lowest;
3656       Dl_info dlinfo2;
3657       if (dladdr(end, &dlinfo2) != 0 && dlinfo2.dli_saddr != dlinfo.dli_saddr
3658           && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin) {
3659         end = (address) dlinfo2.dli_saddr;
3660       }
3661       Disassembler::decode(begin, end, st);
3662     }
3663     return true;
3664   }
3665   return false;


< prev index next >