< prev index next >

src/os/linux/vm/os_linux.cpp

Print this page
rev 10979 : 8140594: Various minor code improvements (compiler)


1896   }
1897 
1898   return result;
1899 }
1900 
1901 void* os::dll_lookup(void* handle, const char* name) {
1902   void* res = dlsym(handle, name);
1903   return res;
1904 }
1905 
1906 void* os::get_default_process_handle() {
1907   return (void*)::dlopen(NULL, RTLD_LAZY);
1908 }
1909 
1910 static bool _print_ascii_file(const char* filename, outputStream* st) {
1911   int fd = ::open(filename, O_RDONLY);
1912   if (fd == -1) {
1913     return false;
1914   }
1915 
1916   char buf[32];
1917   int bytes;
1918   while ((bytes = ::read(fd, buf, sizeof(buf))) > 0) {

1919     st->print_raw(buf, bytes);
1920   }
1921 
1922   ::close(fd);
1923 
1924   return true;
1925 }
1926 
1927 void os::print_dll_info(outputStream *st) {
1928   st->print_cr("Dynamic libraries:");
1929 
1930   char fname[32];
1931   pid_t pid = os::Linux::gettid();
1932 
1933   jio_snprintf(fname, sizeof(fname), "/proc/%d/maps", pid);
1934 
1935   if (!_print_ascii_file(fname, st)) {
1936     st->print("Can not get library information for pid = %d\n", pid);
1937   }
1938 }


5982   return strlen(buffer);
5983 }
5984 
5985 bool os::start_debugging(char *buf, int buflen) {
5986   int len = (int)strlen(buf);
5987   char *p = &buf[len];
5988 
5989   jio_snprintf(p, buflen-len,
5990              "\n\n"
5991              "Do you want to debug the problem?\n\n"
5992              "To debug, run 'gdb /proc/%d/exe %d'; then switch to thread " UINTX_FORMAT " (" INTPTR_FORMAT ")\n"
5993              "Enter 'yes' to launch gdb automatically (PATH must include gdb)\n"
5994              "Otherwise, press RETURN to abort...",
5995              os::current_process_id(), os::current_process_id(),
5996              os::current_thread_id(), os::current_thread_id());
5997 
5998   bool yes = os::message_box("Unexpected Error", buf);
5999 
6000   if (yes) {
6001     // yes, user asked VM to launch debugger
6002     jio_snprintf(buf, sizeof(buf), "gdb /proc/%d/exe %d",
6003                      os::current_process_id(), os::current_process_id());
6004 
6005     os::fork_and_exec(buf);
6006     yes = false;
6007   }
6008   return yes;
6009 }
6010 
6011 static inline struct timespec get_mtime(const char* filename) {
6012   struct stat st;
6013   int ret = os::stat(filename, &st);
6014   assert(ret == 0, "failed to stat() file '%s': %s", filename, strerror(errno));
6015   return st.st_mtim;
6016 }
6017 
6018 int os::compare_file_modified_times(const char* file1, const char* file2) {
6019   struct timespec filetime1 = get_mtime(file1);
6020   struct timespec filetime2 = get_mtime(file2);
6021   int diff = filetime1.tv_sec - filetime2.tv_sec;
6022   if (diff == 0) {




1896   }
1897 
1898   return result;
1899 }
1900 
1901 void* os::dll_lookup(void* handle, const char* name) {
1902   void* res = dlsym(handle, name);
1903   return res;
1904 }
1905 
1906 void* os::get_default_process_handle() {
1907   return (void*)::dlopen(NULL, RTLD_LAZY);
1908 }
1909 
1910 static bool _print_ascii_file(const char* filename, outputStream* st) {
1911   int fd = ::open(filename, O_RDONLY);
1912   if (fd == -1) {
1913     return false;
1914   }
1915 
1916   char buf[33];
1917   int bytes;
1918   buf[32] = '\0';
1919   while ((bytes = ::read(fd, buf, sizeof(buf)-1)) > 0) {
1920     st->print_raw(buf, bytes);
1921   }
1922 
1923   ::close(fd);
1924 
1925   return true;
1926 }
1927 
1928 void os::print_dll_info(outputStream *st) {
1929   st->print_cr("Dynamic libraries:");
1930 
1931   char fname[32];
1932   pid_t pid = os::Linux::gettid();
1933 
1934   jio_snprintf(fname, sizeof(fname), "/proc/%d/maps", pid);
1935 
1936   if (!_print_ascii_file(fname, st)) {
1937     st->print("Can not get library information for pid = %d\n", pid);
1938   }
1939 }


5983   return strlen(buffer);
5984 }
5985 
5986 bool os::start_debugging(char *buf, int buflen) {
5987   int len = (int)strlen(buf);
5988   char *p = &buf[len];
5989 
5990   jio_snprintf(p, buflen-len,
5991              "\n\n"
5992              "Do you want to debug the problem?\n\n"
5993              "To debug, run 'gdb /proc/%d/exe %d'; then switch to thread " UINTX_FORMAT " (" INTPTR_FORMAT ")\n"
5994              "Enter 'yes' to launch gdb automatically (PATH must include gdb)\n"
5995              "Otherwise, press RETURN to abort...",
5996              os::current_process_id(), os::current_process_id(),
5997              os::current_thread_id(), os::current_thread_id());
5998 
5999   bool yes = os::message_box("Unexpected Error", buf);
6000 
6001   if (yes) {
6002     // yes, user asked VM to launch debugger
6003     jio_snprintf(buf, sizeof(char)*buflen, "gdb /proc/%d/exe %d",
6004                      os::current_process_id(), os::current_process_id());
6005 
6006     os::fork_and_exec(buf);
6007     yes = false;
6008   }
6009   return yes;
6010 }
6011 
6012 static inline struct timespec get_mtime(const char* filename) {
6013   struct stat st;
6014   int ret = os::stat(filename, &st);
6015   assert(ret == 0, "failed to stat() file '%s': %s", filename, strerror(errno));
6016   return st.st_mtim;
6017 }
6018 
6019 int os::compare_file_modified_times(const char* file1, const char* file2) {
6020   struct timespec filetime1 = get_mtime(file1);
6021   struct timespec filetime2 = get_mtime(file2);
6022   int diff = filetime1.tv_sec - filetime2.tv_sec;
6023   if (diff == 0) {


< prev index next >