1583 return NULL; 1584 } 1585 #endif // !__APPLE__ 1586 1587 void* os::get_default_process_handle() { 1588 #ifdef __APPLE__ 1589 // MacOS X needs to use RTLD_FIRST instead of RTLD_LAZY 1590 // to avoid finding unexpected symbols on second (or later) 1591 // loads of a library. 1592 return (void*)::dlopen(NULL, RTLD_FIRST); 1593 #else 1594 return (void*)::dlopen(NULL, RTLD_LAZY); 1595 #endif 1596 } 1597 1598 // XXX: Do we need a lock around this as per Linux? 1599 void* os::dll_lookup(void* handle, const char* name) { 1600 return dlsym(handle, name); 1601 } 1602 1603 1604 static bool _print_ascii_file(const char* filename, outputStream* st) { 1605 int fd = ::open(filename, O_RDONLY); 1606 if (fd == -1) { 1607 return false; 1608 } 1609 1610 char buf[32]; 1611 int bytes; 1612 while ((bytes = ::read(fd, buf, sizeof(buf))) > 0) { 1613 st->print_raw(buf, bytes); 1614 } 1615 1616 ::close(fd); 1617 1618 return true; 1619 } 1620 1621 int _print_dll_info_cb(const char * name, address base_address, address top_address, void * param) { 1622 outputStream * out = (outputStream *) param; 1623 out->print_cr(PTR_FORMAT " \t%s", base_address, name); 1624 return 0; 1625 } 1626 1627 void os::print_dll_info(outputStream *st) { 1628 st->print_cr("Dynamic libraries:"); 1629 if (get_loaded_modules_info(_print_dll_info_cb, (void *)st)) { 1630 st->print_cr("Error: Cannot print dynamic libraries."); 1631 } 1632 } 1633 1634 int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) { 1635 #ifdef RTLD_DI_LINKMAP 1636 Dl_info dli; 1637 void *handle; 1638 Link_map *map; 1639 Link_map *p; 1640 1661 dlclose(handle); 1662 return 1; 1663 } 1664 map = map->l_next; 1665 } 1666 1667 dlclose(handle); 1668 #elif defined(__APPLE__) 1669 for (uint32_t i = 1; i < _dyld_image_count(); i++) { 1670 // Value for top_address is returned as 0 since we don't have any information about module size 1671 if (callback(_dyld_get_image_name(i), (address)_dyld_get_image_header(i), (address)0, param)) { 1672 return 1; 1673 } 1674 } 1675 return 0; 1676 #else 1677 return 1; 1678 #endif 1679 } 1680 1681 void os::print_os_info_brief(outputStream* st) { 1682 st->print("Bsd"); 1683 1684 os::Posix::print_uname_info(st); 1685 } 1686 1687 void os::print_os_info(outputStream* st) { 1688 st->print("OS:"); 1689 st->print("Bsd"); 1690 1691 os::Posix::print_uname_info(st); 1692 1693 os::Posix::print_rlimit_info(st); 1694 1695 os::Posix::print_load_average(st); 1696 } 1697 1698 void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) { 1699 // Nothing to do for now. 1700 } 1701 1702 void os::print_memory_info(outputStream* st) { 1703 1704 st->print("Memory:"); 1705 st->print(" %dk page", os::vm_page_size()>>10); 1706 1707 st->print(", physical " UINT64_FORMAT "k", 1708 os::physical_memory() >> 10); 1709 st->print("(" UINT64_FORMAT "k free)", 1710 os::available_memory() >> 10); 1711 st->cr(); 1712 1713 // meminfo 1714 st->print("\n/proc/meminfo:\n"); 1715 _print_ascii_file("/proc/meminfo", st); 1716 st->cr(); 1717 } 1718 1719 void os::print_siginfo(outputStream* st, void* siginfo) { 1720 const siginfo_t* si = (const siginfo_t*)siginfo; 1721 1722 os::Posix::print_siginfo_brief(st, si); 1723 1724 if (si && (si->si_signo == SIGBUS || si->si_signo == SIGSEGV) && 1725 UseSharedSpaces) { 1726 FileMapInfo* mapinfo = FileMapInfo::current_info(); 1727 if (mapinfo->is_in_shared_space(si->si_addr)) { 1728 st->print("\n\nError accessing class data sharing archive." \ 1729 " Mapped file inaccessible during execution, " \ 1730 " possible disk/network problem."); 1731 } 1732 } 1733 st->cr(); 1734 } 1735 | 1583 return NULL; 1584 } 1585 #endif // !__APPLE__ 1586 1587 void* os::get_default_process_handle() { 1588 #ifdef __APPLE__ 1589 // MacOS X needs to use RTLD_FIRST instead of RTLD_LAZY 1590 // to avoid finding unexpected symbols on second (or later) 1591 // loads of a library. 1592 return (void*)::dlopen(NULL, RTLD_FIRST); 1593 #else 1594 return (void*)::dlopen(NULL, RTLD_LAZY); 1595 #endif 1596 } 1597 1598 // XXX: Do we need a lock around this as per Linux? 1599 void* os::dll_lookup(void* handle, const char* name) { 1600 return dlsym(handle, name); 1601 } 1602 1603 int _print_dll_info_cb(const char * name, address base_address, address top_address, void * param) { 1604 outputStream * out = (outputStream *) param; 1605 out->print_cr(PTR_FORMAT " \t%s", base_address, name); 1606 return 0; 1607 } 1608 1609 void os::print_dll_info(outputStream *st) { 1610 st->print_cr("Dynamic libraries:"); 1611 if (get_loaded_modules_info(_print_dll_info_cb, (void *)st)) { 1612 st->print_cr("Error: Cannot print dynamic libraries."); 1613 } 1614 } 1615 1616 int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) { 1617 #ifdef RTLD_DI_LINKMAP 1618 Dl_info dli; 1619 void *handle; 1620 Link_map *map; 1621 Link_map *p; 1622 1643 dlclose(handle); 1644 return 1; 1645 } 1646 map = map->l_next; 1647 } 1648 1649 dlclose(handle); 1650 #elif defined(__APPLE__) 1651 for (uint32_t i = 1; i < _dyld_image_count(); i++) { 1652 // Value for top_address is returned as 0 since we don't have any information about module size 1653 if (callback(_dyld_get_image_name(i), (address)_dyld_get_image_header(i), (address)0, param)) { 1654 return 1; 1655 } 1656 } 1657 return 0; 1658 #else 1659 return 1; 1660 #endif 1661 } 1662 1663 void os::get_summary_os_info(char* buf, size_t buflen) { 1664 // These buffers are small because we want this to be brief 1665 // and not use a lot of stack while generating the hs_err file. 1666 char os[100]; 1667 size_t size = sizeof(os); 1668 int mib_kern[] = { CTL_KERN, KERN_OSTYPE }; 1669 if (sysctl(mib_kern, 2, os, &size, NULL, 0) < 0) { 1670 #ifdef __APPLE__ 1671 strncpy(os, "Darwin", sizeof(os)); 1672 #elif __OpenBSD__ 1673 strncpy(os, "OpenBSD", sizeof(os)); 1674 #else 1675 strncpy(os, "BSD", sizeof(os)); 1676 #endif 1677 } 1678 1679 char release[100]; 1680 size = sizeof(release); 1681 int mib_release[] = { CTL_KERN, KERN_OSRELEASE }; 1682 if (sysctl(mib_release, 2, release, &size, NULL, 0) < 0) { 1683 // if error, leave blank 1684 strncpy(release, "", sizeof(release)); 1685 } 1686 snprintf(buf, buflen, "%s %s", os, release); 1687 } 1688 1689 void os::print_os_info_brief(outputStream* st) { 1690 os::Posix::print_uname_info(st); 1691 } 1692 1693 void os::print_os_info(outputStream* st) { 1694 st->print("OS:"); 1695 1696 os::Posix::print_uname_info(st); 1697 1698 os::Posix::print_rlimit_info(st); 1699 1700 os::Posix::print_load_average(st); 1701 } 1702 1703 void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) { 1704 // Nothing to do for now. 1705 } 1706 1707 void os::get_summary_cpu_info(char* buf, size_t buflen) { 1708 unsigned int mhz; 1709 size_t size = sizeof(mhz); 1710 int mib[] = { CTL_HW, HW_CPU_FREQ }; 1711 if (sysctl(mib, 2, &mhz, &size, NULL, 0) < 0) { 1712 mhz = 0; 1713 } 1714 mhz /= 1000000; // reported in millions 1715 1716 char model[100]; 1717 size = sizeof(model); 1718 int mib_model[] = { CTL_HW, HW_MODEL }; 1719 if (sysctl(mib_model, 2, model, &size, NULL, 0) < 0) { 1720 strncpy(model, cpu_arch, sizeof(model)); 1721 } 1722 1723 char machine[100]; 1724 size = sizeof(machine); 1725 int mib_machine[] = { CTL_HW, HW_MACHINE }; 1726 if (sysctl(mib_machine, 2, machine, &size, NULL, 0) < 0) { 1727 strncpy(machine, "", sizeof(machine)); 1728 } 1729 1730 if (mhz != 0) { 1731 snprintf(buf, buflen, "%s %s %d MHz", model, machine, mhz); 1732 } else { 1733 // Don't report zero MHz 1734 snprintf(buf, buflen, "%s %s", model, machine); 1735 } 1736 } 1737 1738 void os::print_memory_info(outputStream* st) { 1739 1740 st->print("Memory:"); 1741 st->print(" %dk page", os::vm_page_size()>>10); 1742 1743 st->print(", physical " UINT64_FORMAT "k", 1744 os::physical_memory() >> 10); 1745 st->print("(" UINT64_FORMAT "k free)", 1746 os::available_memory() >> 10); 1747 st->cr(); 1748 } 1749 1750 void os::print_siginfo(outputStream* st, void* siginfo) { 1751 const siginfo_t* si = (const siginfo_t*)siginfo; 1752 1753 os::Posix::print_siginfo_brief(st, si); 1754 1755 if (si && (si->si_signo == SIGBUS || si->si_signo == SIGSEGV) && 1756 UseSharedSpaces) { 1757 FileMapInfo* mapinfo = FileMapInfo::current_info(); 1758 if (mapinfo->is_in_shared_space(si->si_addr)) { 1759 st->print("\n\nError accessing class data sharing archive." \ 1760 " Mapped file inaccessible during execution, " \ 1761 " possible disk/network problem."); 1762 } 1763 } 1764 st->cr(); 1765 } 1766 |