Hi,

I've tried attach a corefile with jstack. However, I couldn't.

I guess that this problem is caused by incorrect address mapping of 
libsaproc.so .
I've made a patch which is attached this email. And I've been able to get 
correct thread stack with jstack.

So, I'd like to contribute this patch, and I'd like to backport to JDK6/7 .
Could you help me?


------ details ------

I got these messages then I ran jstack with LIBSAPROC_DEBUG environment 
variable:

/*************************/

  :

libsaproc DEBUG: reading library 
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.1.x86_64/jre/lib/amd64/server/libjvm.so @ 
0x7f53b455a000 [ 0x7f53b455a000 ]
libsaproc DEBUG: ---- sorted virtual address map ----

  :

libsaproc DEBUG: base = 0x7f53b455a000  size = 9993772
libsaproc DEBUG: base = 0x7f53b455a000  size = 4096

  :

libsaproc DEBUG: can't locate map_info at 0x7f53b4dbe000
libsaproc DEBUG: core read failed for 4096 byte(s) @ 0x7f53b4dbe000 (4096 more 
bytes)

  :

/*************************/

libsaproc.so tries to read libjvm.so library address, and it is duplicated.
I read Linux kernel source code of function of core dump, and I found these 
comment:

source code: kernel-3.2.1-3.fc16.src.rpm (Fedora16 x86_64)
in fs/binfmt_elf.c: static unsigned long vma_dump_size(struct vm_area_struct 
*vma, unsigned long mm_flags)
----------------------
        /*
         * If this looks like the beginning of a DSO or executable mapping,
         * check for an ELF header.  If we find one, dump the first page to
         * aid in determining what was mapped here.
         */
----------------------

In fact, core image has executable load section which size is 1 page(0x1000)
----------------------
  LOAD           0x0000000005173000 0x00007f53b455a000 0x0000000000000000
                 0x0000000000001000 0x0000000000988000  R E    1000
----------------------

So, we must think these case when we attach core image.
I modified "read_lib_segments()" in hotspot/agent/src/os/linux/ps_core.c to 
overwrite
correct address in shared library .


Please check it.

Thanks,
Yasumasa

diff -r 6edfe6e42a68 agent/src/os/linux/ps_core.c
--- a/agent/src/os/linux/ps_core.c      Thu Jan 26 18:23:17 2012 -0800
+++ b/agent/src/os/linux/ps_core.c      Tue Jan 31 18:43:42 2012 +0900
@@ -30,6 +30,7 @@
 #include <stddef.h>
 #include <elf.h>
 #include <link.h>
+#include <sys/user.h>
 #include "libproc_impl.h"
 #include "salibelf.h"
 
@@ -711,9 +712,35 @@
    // i.e., text segments. The read/write/exec (data) segments would
    // have been already added from core file segments.
    for (lib_php = phbuf, i = 0; i < lib_ehdr->e_phnum; i++) {
+
       if ((lib_php->p_type == PT_LOAD) && !(lib_php->p_flags & PF_W) && 
(lib_php->p_filesz != 0)) {
-         if (add_map_info(ph, lib_fd, lib_php->p_offset, lib_php->p_vaddr + 
lib_base, lib_php->p_filesz) == NULL)
+        uintptr_t  target_vaddr = lib_php->p_vaddr + lib_base;
+        map_info *existed_map = core_lookup(ph, target_vaddr);
+
+        if(existed_map == NULL){
+          if(add_map_info(ph, lib_fd, lib_php->p_offset,
+                               target_vaddr, lib_php->p_filesz) == NULL)
             goto err;
+        }
+        else{
+
+          if((existed_map->memsz != PAGE_SIZE) &&
+                   (existed_map->fd != lib_fd) &&
+                   (existed_map->memsz != lib_php->p_filesz)){
+            print_debug("address confliction @ 0x%lx (size = %ld, flags = 
%d\n)",
+                              target_vaddr, lib_php->p_filesz, 
lib_php->p_flags);
+
+            goto err;
+          }
+
+          /* replace PT_LOAD segment to library segment */
+          print_debug("overwrite to new address mapping (memsz %ld -> %ld)\n",
+                                          existed_map->memsz, 
lib_php->p_filesz);
+          existed_map->fd     = lib_fd;
+          existed_map->offset = lib_php->p_offset;
+          existed_map->memsz  = lib_php->p_filesz;
+        }
+
       }
       lib_php++;
    }

Reply via email to