< prev index next >

src/os/linux/vm/os_linux.cpp

Print this page
rev 11179 : 8140594: Various minor code improvements (compiler)
Reviewed-by: thartmann


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 }


6062   return strlen(buffer);
6063 }
6064 
6065 bool os::start_debugging(char *buf, int buflen) {
6066   int len = (int)strlen(buf);
6067   char *p = &buf[len];
6068 
6069   jio_snprintf(p, buflen-len,
6070              "\n\n"
6071              "Do you want to debug the problem?\n\n"
6072              "To debug, run 'gdb /proc/%d/exe %d'; then switch to thread " UINTX_FORMAT " (" INTPTR_FORMAT ")\n"
6073              "Enter 'yes' to launch gdb automatically (PATH must include gdb)\n"
6074              "Otherwise, press RETURN to abort...",
6075              os::current_process_id(), os::current_process_id(),
6076              os::current_thread_id(), os::current_thread_id());
6077 
6078   bool yes = os::message_box("Unexpected Error", buf);
6079 
6080   if (yes) {
6081     // yes, user asked VM to launch debugger
6082     jio_snprintf(buf, sizeof(buf), "gdb /proc/%d/exe %d",
6083                      os::current_process_id(), os::current_process_id());
6084 
6085     os::fork_and_exec(buf);
6086     yes = false;
6087   }
6088   return yes;
6089 }
6090 
6091 static inline struct timespec get_mtime(const char* filename) {
6092   struct stat st;
6093   int ret = os::stat(filename, &st);
6094   assert(ret == 0, "failed to stat() file '%s': %s", filename, strerror(errno));
6095   return st.st_mtim;
6096 }
6097 
6098 int os::compare_file_modified_times(const char* file1, const char* file2) {
6099   struct timespec filetime1 = get_mtime(file1);
6100   struct timespec filetime2 = get_mtime(file2);
6101   int diff = filetime1.tv_sec - filetime2.tv_sec;
6102   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 }


6063   return strlen(buffer);
6064 }
6065 
6066 bool os::start_debugging(char *buf, int buflen) {
6067   int len = (int)strlen(buf);
6068   char *p = &buf[len];
6069 
6070   jio_snprintf(p, buflen-len,
6071                "\n\n"
6072                "Do you want to debug the problem?\n\n"
6073                "To debug, run 'gdb /proc/%d/exe %d'; then switch to thread " UINTX_FORMAT " (" INTPTR_FORMAT ")\n"
6074                "Enter 'yes' to launch gdb automatically (PATH must include gdb)\n"
6075                "Otherwise, press RETURN to abort...",
6076                os::current_process_id(), os::current_process_id(),
6077                os::current_thread_id(), os::current_thread_id());
6078 
6079   bool yes = os::message_box("Unexpected Error", buf);
6080 
6081   if (yes) {
6082     // yes, user asked VM to launch debugger
6083     jio_snprintf(buf, sizeof(char)*buflen, "gdb /proc/%d/exe %d",
6084                  os::current_process_id(), os::current_process_id());
6085 
6086     os::fork_and_exec(buf);
6087     yes = false;
6088   }
6089   return yes;
6090 }
6091 
6092 static inline struct timespec get_mtime(const char* filename) {
6093   struct stat st;
6094   int ret = os::stat(filename, &st);
6095   assert(ret == 0, "failed to stat() file '%s': %s", filename, strerror(errno));
6096   return st.st_mtim;
6097 }
6098 
6099 int os::compare_file_modified_times(const char* file1, const char* file2) {
6100   struct timespec filetime1 = get_mtime(file1);
6101   struct timespec filetime2 = get_mtime(file2);
6102   int diff = filetime1.tv_sec - filetime2.tv_sec;
6103   if (diff == 0) {


< prev index next >