aboutsummaryrefslogtreecommitdiff
path: root/agent
diff options
context:
space:
mode:
authorkvn <none@none>2013-11-05 17:38:04 -0800
committerkvn <none@none>2013-11-05 17:38:04 -0800
commit448e4a8ada27f95b604d56572b7e061c157e9d8c (patch)
treee778fc8f1c06b8cb3026363cdadc62db28edb0ca /agent
parent2d51488e378df0299af1d7b786a931129899c81a (diff)
parent9d58089aaab0379ed221bae24a808871374f626b (diff)
downloadjdk8u_hotspot-448e4a8ada27f95b604d56572b7e061c157e9d8c.tar.gz
Merge
Diffstat (limited to 'agent')
-rw-r--r--agent/src/os/bsd/ps_core.c160
-rw-r--r--agent/src/os/bsd/ps_proc.c3
-rw-r--r--agent/src/os/linux/LinuxDebuggerLocal.c3
-rw-r--r--agent/src/os/linux/ps_core.c868
-rw-r--r--agent/src/os/linux/ps_proc.c2
-rw-r--r--agent/src/os/linux/salibelf.c1
-rw-r--r--agent/src/os/linux/symtab.c2
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java2
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/asm/Disassembler.java7
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java2
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/gc_implementation/g1/G1HeapRegionTable.java119
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/gc_implementation/g1/HeapRegionSeq.java47
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/memory/ProtectionDomainCacheEntry.java56
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/memory/ProtectionDomainEntry.java12
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/memory/SymbolTable.java6
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/oops/ConstMethod.java47
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java9
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java33
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/ClassLoaderStats.java3
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java3
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/FlagDumper.java3
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/HeapDumper.java3
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java27
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/JInfo.java3
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/JMap.java7
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/JSnap.java3
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/JStack.java3
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/ObjectHistogram.java3
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/PMap.java3
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/PStack.java3
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/StackTrace.java3
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/SysPropsDumper.java3
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java35
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassDump.java3
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/soql/JSDB.java3
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/tools/soql/SOQL.java3
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/utilities/AbstractHeapGraphWriter.java8
-rw-r--r--agent/src/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java136
38 files changed, 1017 insertions, 620 deletions
diff --git a/agent/src/os/bsd/ps_core.c b/agent/src/os/bsd/ps_core.c
index bb1191cc2..6e4c65ed4 100644
--- a/agent/src/os/bsd/ps_core.c
+++ b/agent/src/os/bsd/ps_core.c
@@ -44,6 +44,7 @@
// close all file descriptors
static void close_files(struct ps_prochandle* ph) {
lib_info* lib = NULL;
+
// close core file descriptor
if (ph->core->core_fd >= 0)
close(ph->core->core_fd);
@@ -149,8 +150,7 @@ static map_info* add_class_share_map_info(struct ps_prochandle* ph, off_t offset
// Return the map_info for the given virtual address. We keep a sorted
// array of pointers in ph->map_array, so we can binary search.
-static map_info* core_lookup(struct ps_prochandle *ph, uintptr_t addr)
-{
+static map_info* core_lookup(struct ps_prochandle *ph, uintptr_t addr) {
int mid, lo = 0, hi = ph->core->num_maps - 1;
map_info *mp;
@@ -230,9 +230,9 @@ struct FileMapHeader {
size_t _used; // for setting space top on read
// 4991491 NOTICE These are C++ bool's in filemap.hpp and must match up with
- // the C type matching the C++ bool type on any given platform. For
- // Hotspot on BSD we assume the corresponding C type is char but
- // licensees on BSD versions may need to adjust the type of these fields.
+ // the C type matching the C++ bool type on any given platform.
+ // We assume the corresponding C type is char but licensees
+ // may need to adjust the type of these fields.
char _read_only; // read only space?
char _allow_exec; // executable code in space?
@@ -286,10 +286,12 @@ static bool read_string(struct ps_prochandle* ph, uintptr_t addr, char* buf, siz
#define USE_SHARED_SPACES_SYM "_UseSharedSpaces"
// mangled name of Arguments::SharedArchivePath
#define SHARED_ARCHIVE_PATH_SYM "_ZN9Arguments17SharedArchivePathE"
+#define LIBJVM_NAME "/libjvm.dylib"
#else
#define USE_SHARED_SPACES_SYM "UseSharedSpaces"
// mangled name of Arguments::SharedArchivePath
#define SHARED_ARCHIVE_PATH_SYM "__ZN9Arguments17SharedArchivePathE"
+#define LIBJVM_NAME "/libjvm.so"
#endif // __APPLE_
static bool init_classsharing_workaround(struct ps_prochandle* ph) {
@@ -300,12 +302,7 @@ static bool init_classsharing_workaround(struct ps_prochandle* ph) {
// we are iterating over shared objects from the core dump. look for
// libjvm.so.
const char *jvm_name = 0;
-#ifdef __APPLE__
- if ((jvm_name = strstr(lib->name, "/libjvm.dylib")) != 0)
-#else
- if ((jvm_name = strstr(lib->name, "/libjvm.so")) != 0)
-#endif // __APPLE__
- {
+ if ((jvm_name = strstr(lib->name, LIBJVM_NAME)) != 0) {
char classes_jsa[PATH_MAX];
struct FileMapHeader header;
int fd = -1;
@@ -399,8 +396,8 @@ static bool init_classsharing_workaround(struct ps_prochandle* ph) {
}
}
return true;
- }
- lib = lib->next;
+ }
+ lib = lib->next;
}
return true;
}
@@ -432,8 +429,8 @@ static bool sort_map_array(struct ps_prochandle* ph) {
// allocate map_array
map_info** array;
if ( (array = (map_info**) malloc(sizeof(map_info*) * num_maps)) == NULL) {
- print_debug("can't allocate memory for map array\n");
- return false;
+ print_debug("can't allocate memory for map array\n");
+ return false;
}
// add maps to array
@@ -450,7 +447,7 @@ static bool sort_map_array(struct ps_prochandle* ph) {
ph->core->map_array = array;
// sort the map_info array by base virtual address.
qsort(ph->core->map_array, ph->core->num_maps, sizeof (map_info*),
- core_cmp_mapping);
+ core_cmp_mapping);
// print map
if (is_debug()) {
@@ -458,7 +455,7 @@ static bool sort_map_array(struct ps_prochandle* ph) {
print_debug("---- sorted virtual address map ----\n");
for (j = 0; j < ph->core->num_maps; j++) {
print_debug("base = 0x%lx\tsize = %d\n", ph->core->map_array[j]->vaddr,
- ph->core->map_array[j]->memsz);
+ ph->core->map_array[j]->memsz);
}
}
@@ -1091,9 +1088,9 @@ static bool core_handle_note(struct ps_prochandle* ph, ELF_PHDR* note_phdr) {
notep->n_type, notep->n_descsz);
if (notep->n_type == NT_PRSTATUS) {
- if (core_handle_prstatus(ph, descdata, notep->n_descsz) != true) {
- return false;
- }
+ if (core_handle_prstatus(ph, descdata, notep->n_descsz) != true) {
+ return false;
+ }
}
p = descdata + ROUNDUP(notep->n_descsz, 4);
}
@@ -1121,7 +1118,7 @@ static bool read_core_segments(struct ps_prochandle* ph, ELF_EHDR* core_ehdr) {
* contains a set of saved /proc structures), and PT_LOAD (which
* represents a memory mapping from the process's address space).
*
- * Difference b/w Solaris PT_NOTE and BSD PT_NOTE:
+ * Difference b/w Solaris PT_NOTE and Linux/BSD PT_NOTE:
*
* In Solaris there are two PT_NOTE segments the first PT_NOTE (if present)
* contains /proc structs in the pre-2.6 unstructured /proc format. the last
@@ -1167,32 +1164,61 @@ err:
// read segments of a shared object
static bool read_lib_segments(struct ps_prochandle* ph, int lib_fd, ELF_EHDR* lib_ehdr, uintptr_t lib_base) {
- int i = 0;
- ELF_PHDR* phbuf;
- ELF_PHDR* lib_php = NULL;
+ int i = 0;
+ ELF_PHDR* phbuf;
+ ELF_PHDR* lib_php = NULL;
- if ((phbuf = read_program_header_table(lib_fd, lib_ehdr)) == NULL)
- return false;
+ int page_size=sysconf(_SC_PAGE_SIZE);
- // we want to process only PT_LOAD segments that are not writable.
- // 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)
- goto err;
+ if ((phbuf = read_program_header_table(lib_fd, lib_ehdr)) == NULL) {
+ return false;
+ }
+
+ // we want to process only PT_LOAD segments that are not writable.
+ // 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)) {
+
+ uintptr_t target_vaddr = lib_php->p_vaddr + lib_base;
+ map_info *existing_map = core_lookup(ph, target_vaddr);
+
+ if (existing_map == NULL){
+ if (add_map_info(ph, lib_fd, lib_php->p_offset,
+ target_vaddr, lib_php->p_filesz) == NULL) {
+ goto err;
+ }
+ } else {
+ if ((existing_map->memsz != page_size) &&
+ (existing_map->fd != lib_fd) &&
+ (existing_map->memsz != lib_php->p_filesz)){
+
+ print_debug("address conflict @ 0x%lx (size = %ld, flags = %d\n)",
+ target_vaddr, lib_php->p_filesz, lib_php->p_flags);
+ goto err;
+ }
+
+ /* replace PT_LOAD segment with library segment */
+ print_debug("overwrote with new address mapping (memsz %ld -> %ld)\n",
+ existing_map->memsz, lib_php->p_filesz);
+
+ existing_map->fd = lib_fd;
+ existing_map->offset = lib_php->p_offset;
+ existing_map->memsz = lib_php->p_filesz;
}
- lib_php++;
- }
+ }
- free(phbuf);
- return true;
+ lib_php++;
+ }
+
+ free(phbuf);
+ return true;
err:
- free(phbuf);
- return false;
+ free(phbuf);
+ return false;
}
-// process segments from interpreter (ld-elf.so.1)
+// process segments from interpreter (ld.so or ld-linux.so or ld-elf.so)
static bool read_interp_segments(struct ps_prochandle* ph) {
ELF_EHDR interp_ehdr;
@@ -1303,32 +1329,34 @@ static bool read_shared_lib_info(struct ps_prochandle* ph) {
debug_base = dyn.d_un.d_ptr;
// at debug_base we have struct r_debug. This has first link map in r_map field
if (ps_pread(ph, (psaddr_t) debug_base + FIRST_LINK_MAP_OFFSET,
- &first_link_map_addr, sizeof(uintptr_t)) != PS_OK) {
+ &first_link_map_addr, sizeof(uintptr_t)) != PS_OK) {
print_debug("can't read first link map address\n");
return false;
}
// read ld_base address from struct r_debug
- // XXX: There is no r_ldbase member on BSD
- /*
+#if 0 // There is no r_ldbase member on BSD
if (ps_pread(ph, (psaddr_t) debug_base + LD_BASE_OFFSET, &ld_base_addr,
sizeof(uintptr_t)) != PS_OK) {
print_debug("can't read ld base address\n");
return false;
}
ph->core->ld_base_addr = ld_base_addr;
- */
+#else
ph->core->ld_base_addr = 0;
+#endif
print_debug("interpreter base address is 0x%lx\n", ld_base_addr);
- // now read segments from interp (i.e ld-elf.so.1)
- if (read_interp_segments(ph) != true)
+ // now read segments from interp (i.e ld.so or ld-linux.so or ld-elf.so)
+ if (read_interp_segments(ph) != true) {
return false;
+ }
// after adding interpreter (ld.so) mappings sort again
- if (sort_map_array(ph) != true)
+ if (sort_map_array(ph) != true) {
return false;
+ }
print_debug("first link map is at 0x%lx\n", first_link_map_addr);
@@ -1380,8 +1408,9 @@ static bool read_shared_lib_info(struct ps_prochandle* ph) {
add_lib_info_fd(ph, lib_name, lib_fd, lib_base);
// Map info is added for the library (lib_name) so
// we need to re-sort it before calling the p_pdread.
- if (sort_map_array(ph) != true)
+ if (sort_map_array(ph) != true) {
return false;
+ }
} else {
print_debug("can't read ELF header for shared object %s\n", lib_name);
close(lib_fd);
@@ -1392,7 +1421,7 @@ static bool read_shared_lib_info(struct ps_prochandle* ph) {
// read next link_map address
if (ps_pread(ph, (psaddr_t) link_map_addr + LINK_MAP_NEXT_OFFSET,
- &link_map_addr, sizeof(uintptr_t)) != PS_OK) {
+ &link_map_addr, sizeof(uintptr_t)) != PS_OK) {
print_debug("can't read next link in link_map\n");
return false;
}
@@ -1408,7 +1437,7 @@ struct ps_prochandle* Pgrab_core(const char* exec_file, const char* core_file) {
struct ps_prochandle* ph = (struct ps_prochandle*) calloc(1, sizeof(struct ps_prochandle));
if (ph == NULL) {
- print_debug("cant allocate ps_prochandle\n");
+ print_debug("can't allocate ps_prochandle\n");
return NULL;
}
@@ -1444,38 +1473,45 @@ struct ps_prochandle* Pgrab_core(const char* exec_file, const char* core_file) {
}
if (read_elf_header(ph->core->exec_fd, &exec_ehdr) != true || exec_ehdr.e_type != ET_EXEC) {
- print_debug("executable file is not a valid ELF ET_EXEC file\n");
- goto err;
+ print_debug("executable file is not a valid ELF ET_EXEC file\n");
+ goto err;
}
// process core file segments
- if (read_core_segments(ph, &core_ehdr) != true)
- goto err;
+ if (read_core_segments(ph, &core_ehdr) != true) {
+ goto err;
+ }
// process exec file segments
- if (read_exec_segments(ph, &exec_ehdr) != true)
- goto err;
+ if (read_exec_segments(ph, &exec_ehdr) != true) {
+ goto err;
+ }
// exec file is also treated like a shared object for symbol search
if (add_lib_info_fd(ph, exec_file, ph->core->exec_fd,
- (uintptr_t)0 + find_base_address(ph->core->exec_fd, &exec_ehdr)) == NULL)
- goto err;
+ (uintptr_t)0 + find_base_address(ph->core->exec_fd, &exec_ehdr)) == NULL) {
+ goto err;
+ }
// allocate and sort maps into map_array, we need to do this
// here because read_shared_lib_info needs to read from debuggee
// address space
- if (sort_map_array(ph) != true)
+ if (sort_map_array(ph) != true) {
goto err;
+ }
- if (read_shared_lib_info(ph) != true)
+ if (read_shared_lib_info(ph) != true) {
goto err;
+ }
// sort again because we have added more mappings from shared objects
- if (sort_map_array(ph) != true)
+ if (sort_map_array(ph) != true) {
goto err;
+ }
- if (init_classsharing_workaround(ph) != true)
+ if (init_classsharing_workaround(ph) != true) {
goto err;
+ }
print_debug("Leave Pgrab_core\n");
return ph;
diff --git a/agent/src/os/bsd/ps_proc.c b/agent/src/os/bsd/ps_proc.c
index cf4a5d71d..53cafe1f4 100644
--- a/agent/src/os/bsd/ps_proc.c
+++ b/agent/src/os/bsd/ps_proc.c
@@ -131,7 +131,7 @@ static bool process_get_lwp_info(struct ps_prochandle *ph, lwpid_t lwp_id, void
static bool ptrace_continue(pid_t pid, int signal) {
// pass the signal to the process so we don't swallow it
- if (ptrace(PTRACE_CONT, pid, NULL, signal) < 0) {
+ if (ptrace(PT_CONTINUE, pid, NULL, signal) < 0) {
print_debug("ptrace(PTRACE_CONT, ..) failed for %d\n", pid);
return false;
}
@@ -434,7 +434,6 @@ static ps_prochandle_ops process_ops = {
// attach to the process. One and only one exposed stuff
struct ps_prochandle* Pgrab(pid_t pid) {
struct ps_prochandle* ph = NULL;
- thread_info* thr = NULL;
if ( (ph = (struct ps_prochandle*) calloc(1, sizeof(struct ps_prochandle))) == NULL) {
print_debug("can't allocate memory for ps_prochandle\n");
diff --git a/agent/src/os/linux/LinuxDebuggerLocal.c b/agent/src/os/linux/LinuxDebuggerLocal.c
index 17f607e0a..0d3960f7a 100644
--- a/agent/src/os/linux/LinuxDebuggerLocal.c
+++ b/agent/src/os/linux/LinuxDebuggerLocal.c
@@ -29,6 +29,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <stdlib.h>
#include <string.h>
#include <limits.h>
@@ -80,7 +81,7 @@ JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_linux_LinuxDebuggerLocal_in
(JNIEnv *env, jclass cls) {
jclass listClass;
- if (init_libproc(getenv("LIBSAPROC_DEBUG")) != true) {
+ if (init_libproc(getenv("LIBSAPROC_DEBUG") != NULL) != true) {
THROW_NEW_DEBUGGER_EXCEPTION("can't initialize libproc");
}
diff --git a/agent/src/os/linux/ps_core.c b/agent/src/os/linux/ps_core.c
index 85abab802..268fc2ad1 100644
--- a/agent/src/os/linux/ps_core.c
+++ b/agent/src/os/linux/ps_core.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -41,155 +41,158 @@
// ps_prochandle cleanup helper functions
// close all file descriptors
-static void close_elf_files(struct ps_prochandle* ph) {
- lib_info* lib = NULL;
-
- // close core file descriptor
- if (ph->core->core_fd >= 0)
- close(ph->core->core_fd);
-
- // close exec file descriptor
- if (ph->core->exec_fd >= 0)
- close(ph->core->exec_fd);
-
- // close interp file descriptor
- if (ph->core->interp_fd >= 0)
- close(ph->core->interp_fd);
-
- // close class share archive file
- if (ph->core->classes_jsa_fd >= 0)
- close(ph->core->classes_jsa_fd);
-
- // close all library file descriptors
- lib = ph->libs;
- while (lib) {
- int fd = lib->fd;
- if (fd >= 0 && fd != ph->core->exec_fd) close(fd);
- lib = lib->next;
- }
+static void close_files(struct ps_prochandle* ph) {
+ lib_info* lib = NULL;
+
+ // close core file descriptor
+ if (ph->core->core_fd >= 0)
+ close(ph->core->core_fd);
+
+ // close exec file descriptor
+ if (ph->core->exec_fd >= 0)
+ close(ph->core->exec_fd);
+
+ // close interp file descriptor
+ if (ph->core->interp_fd >= 0)
+ close(ph->core->interp_fd);
+
+ // close class share archive file
+ if (ph->core->classes_jsa_fd >= 0)
+ close(ph->core->classes_jsa_fd);
+
+ // close all library file descriptors
+ lib = ph->libs;
+ while (lib) {
+ int fd = lib->fd;
+ if (fd >= 0 && fd != ph->core->exec_fd) {
+ close(fd);
+ }
+ lib = lib->next;
+ }
}
// clean all map_info stuff
static void destroy_map_info(struct ps_prochandle* ph) {
map_info* map = ph->core->maps;
while (map) {
- map_info* next = map->next;
- free(map);
- map = next;
+ map_info* next = map->next;
+ free(map);
+ map = next;
}
if (ph->core->map_array) {
- free(ph->core->map_array);
+ free(ph->core->map_array);
}
// Part of the class sharing workaround
map = ph->core->class_share_maps;
while (map) {
- map_info* next = map->next;
- free(map);
- map = next;
+ map_info* next = map->next;
+ free(map);
+ map = next;
}
}
// ps_prochandle operations
static void core_release(struct ps_prochandle* ph) {
- if (ph->core) {
- close_elf_files(ph);
- destroy_map_info(ph);
- free(ph->core);
- }
+ if (ph->core) {
+ close_files(ph);
+ destroy_map_info(ph);
+ free(ph->core);
+ }
}
static map_info* allocate_init_map(int fd, off_t offset, uintptr_t vaddr, size_t memsz) {
- map_info* map;
- if ( (map = (map_info*) calloc(1, sizeof(map_info))) == NULL) {
- print_debug("can't allocate memory for map_info\n");
- return NULL;
- }
+ map_info* map;
+ if ( (map = (map_info*) calloc(1, sizeof(map_info))) == NULL) {
+ print_debug("can't allocate memory for map_info\n");
+ return NULL;
+ }
- // initialize map
- map->fd = fd;
- map->offset = offset;
- map->vaddr = vaddr;
- map->memsz = memsz;
- return map;
+ // initialize map
+ map->fd = fd;
+ map->offset = offset;
+ map->vaddr = vaddr;
+ map->memsz = memsz;
+ return map;
}
// add map info with given fd, offset, vaddr and memsz
static map_info* add_map_info(struct ps_prochandle* ph, int fd, off_t offset,
uintptr_t vaddr, size_t memsz) {
- map_info* map;
- if ((map = allocate_init_map(fd, offset, vaddr, memsz)) == NULL) {
- return NULL;
- }
+ map_info* map;
+ if ((map = allocate_init_map(fd, offset, vaddr, memsz)) == NULL) {
+ return NULL;
+ }
- // add this to map list
- map->next = ph->core->maps;
- ph->core->maps = map;
- ph->core->num_maps++;
+ // add this to map list
+ map->next = ph->core->maps;
+ ph->core->maps = map;
+ ph->core->num_maps++;
- return map;
+ return map;
}
// Part of the class sharing workaround
-static void add_class_share_map_info(struct ps_prochandle* ph, off_t offset,
+static map_info* add_class_share_map_info(struct ps_prochandle* ph, off_t offset,
uintptr_t vaddr, size_t memsz) {
- map_info* map;
- if ((map = allocate_init_map(ph->core->classes_jsa_fd,
- offset, vaddr, memsz)) == NULL) {
- return;
- }
+ map_info* map;
+ if ((map = allocate_init_map(ph->core->classes_jsa_fd,
+ offset, vaddr, memsz)) == NULL) {
+ return NULL;
+ }
- map->next = ph->core->class_share_maps;
- ph->core->class_share_maps = map;
+ map->next = ph->core->class_share_maps;
+ ph->core->class_share_maps = map;
+ return map;
}
// Return the map_info for the given virtual address. We keep a sorted
// array of pointers in ph->map_array, so we can binary search.
-static map_info* core_lookup(struct ps_prochandle *ph, uintptr_t addr)
-{
- int mid, lo = 0, hi = ph->core->num_maps - 1;
- map_info *mp;
-
- while (hi - lo > 1) {
- mid = (lo + hi) / 2;
- if (addr >= ph->core->map_array[mid]->vaddr)
- lo = mid;
- else
- hi = mid;
- }
+static map_info* core_lookup(struct ps_prochandle *ph, uintptr_t addr) {
+ int mid, lo = 0, hi = ph->core->num_maps - 1;
+ map_info *mp;
+
+ while (hi - lo > 1) {
+ mid = (lo + hi) / 2;
+ if (addr >= ph->core->map_array[mid]->vaddr) {
+ lo = mid;
+ } else {
+ hi = mid;
+ }
+ }
- if (addr < ph->core->map_array[hi]->vaddr)
- mp = ph->core->map_array[lo];
- else
- mp = ph->core->map_array[hi];
+ if (addr < ph->core->map_array[hi]->vaddr) {
+ mp = ph->core->map_array[lo];
+ } else {
+ mp = ph->core->map_array[hi];
+ }
- if (addr >= mp->vaddr && addr < mp->vaddr + mp->memsz)
- return (mp);
+ if (addr >= mp->vaddr && addr < mp->vaddr + mp->memsz) {
+ return (mp);
+ }
- // Part of the class sharing workaround
- // Unfortunately, we have no way of detecting -Xshare state.
- // Check out the share maps atlast, if we don't find anywhere.
- // This is done this way so to avoid reading share pages
- // ahead of other normal maps. For eg. with -Xshare:off we don't
- // want to prefer class sharing data to data from core.
- mp = ph->core->class_share_maps;
- if (mp) {
- print_debug("can't locate map_info at 0x%lx, trying class share maps\n",
- addr);
- }
- while (mp) {
- if (addr >= mp->vaddr && addr < mp->vaddr + mp->memsz) {
- print_debug("located map_info at 0x%lx from class share maps\n",
- addr);
- return (mp);
- }
- mp = mp->next;
- }
+ // Part of the class sharing workaround
+ // Unfortunately, we have no way of detecting -Xshare state.
+ // Check out the share maps atlast, if we don't find anywhere.
+ // This is done this way so to avoid reading share pages
+ // ahead of other normal maps. For eg. with -Xshare:off we don't
+ // want to prefer class sharing data to data from core.
+ mp = ph->core->class_share_maps;
+ if (mp) {
+ print_debug("can't locate map_info at 0x%lx, trying class share maps\n", addr);
+ }
+ while (mp) {
+ if (addr >= mp->vaddr && addr < mp->vaddr + mp->memsz) {
+ print_debug("located map_info at 0x%lx from class share maps\n", addr);
+ return (mp);
+ }
+ mp = mp->next;
+ }
- print_debug("can't locate map_info at 0x%lx\n", addr);
- return (NULL);
+ print_debug("can't locate map_info at 0x%lx\n", addr);
+ return (NULL);
}
//---------------------------------------------------------------
@@ -226,9 +229,9 @@ struct FileMapHeader {
size_t _used; // for setting space top on read
// 4991491 NOTICE These are C++ bool's in filemap.hpp and must match up with
- // the C type matching the C++ bool type on any given platform. For
- // Hotspot on Linux we assume the corresponding C type is char but
- // licensees on Linux versions may need to adjust the type of these fields.
+ // the C type matching the C++ bool type on any given platform.
+ // We assume the corresponding C type is char but licensees
+ // may need to adjust the type of these fields.
char _read_only; // read only space?
char _allow_exec; // executable code in space?
@@ -238,154 +241,159 @@ struct FileMapHeader {
};
static bool read_jboolean(struct ps_prochandle* ph, uintptr_t addr, jboolean* pvalue) {
- jboolean i;
- if (ps_pdread(ph, (psaddr_t) addr, &i, sizeof(i)) == PS_OK) {
- *pvalue = i;
- return true;
- } else {
- return false;
- }
+ jboolean i;
+ if (ps_pdread(ph, (psaddr_t) addr, &i, sizeof(i)) == PS_OK) {
+ *pvalue = i;
+ return true;
+ } else {
+ return false;
+ }
}
static bool read_pointer(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* pvalue) {
- uintptr_t uip;
- if (ps_pdread(ph, (psaddr_t) addr, &uip, sizeof(uip)) == PS_OK) {
- *pvalue = uip;
- return true;
- } else {
- return false;
- }
+ uintptr_t uip;
+ if (ps_pdread(ph, (psaddr_t) addr, (char *)&uip, sizeof(uip)) == PS_OK) {
+ *pvalue = uip;
+ return true;
+ } else {
+ return false;
+ }
}
// used to read strings from debuggee
static bool read_string(struct ps_prochandle* ph, uintptr_t addr, char* buf, size_t size) {
- size_t i = 0;
- char c = ' ';
+ size_t i = 0;
+ char c = ' ';
- while (c != '\0') {
- if (ps_pdread(ph, (psaddr_t) addr, &c, sizeof(char)) != PS_OK)
- return false;
- if (i < size - 1)
- buf[i] = c;
- else // smaller buffer
- return false;
- i++; addr++;
- }
+ while (c != '\0') {
+ if (ps_pdread(ph, (psaddr_t) addr, &c, sizeof(char)) != PS_OK) {
+ return false;
+ }
+ if (i < size - 1) {
+ buf[i] = c;
+ } else {
+ // smaller buffer
+ return false;
+ }
+ i++; addr++;
+ }
- buf[i] = '\0';
- return true;
+ buf[i] = '\0';
+ return true;
}
#define USE_SHARED_SPACES_SYM "UseSharedSpaces"
// mangled name of Arguments::SharedArchivePath
#define SHARED_ARCHIVE_PATH_SYM "_ZN9Arguments17SharedArchivePathE"
+#define LIBJVM_NAME "/libjvm.so"
static bool init_classsharing_workaround(struct ps_prochandle* ph) {
- lib_info* lib = ph->libs;
- while (lib != NULL) {
- // we are iterating over shared objects from the core dump. look for
- // libjvm.so.
- const char *jvm_name = 0;
- if ((jvm_name = strstr(lib->name, "/libjvm.so")) != 0) {
- char classes_jsa[PATH_MAX];
- struct FileMapHeader header;
- size_t n = 0;
- int fd = -1, m = 0;
- uintptr_t base = 0, useSharedSpacesAddr = 0;
- uintptr_t sharedArchivePathAddrAddr = 0, sharedArchivePathAddr = 0;
- jboolean useSharedSpaces = 0;
- map_info* mi = 0;
-
- memset(classes_jsa, 0, sizeof(classes_jsa));
- jvm_name = lib->name;
- useSharedSpacesAddr = lookup_symbol(ph, jvm_name, USE_SHARED_SPACES_SYM);
- if (useSharedSpacesAddr == 0) {
- print_debug("can't lookup 'UseSharedSpaces' flag\n");
- return false;
- }
+ lib_info* lib = ph->libs;
+ while (lib != NULL) {
+ // we are iterating over shared objects from the core dump. look for
+ // libjvm.so.
+ const char *jvm_name = 0;
+ if ((jvm_name = strstr(lib->name, LIBJVM_NAME)) != 0) {
+ char classes_jsa[PATH_MAX];
+ struct FileMapHeader header;
+ int fd = -1;
+ int m = 0;
+ size_t n = 0;
+ uintptr_t base = 0, useSharedSpacesAddr = 0;
+ uintptr_t sharedArchivePathAddrAddr = 0, sharedArchivePathAddr = 0;
+ jboolean useSharedSpaces = 0;
+ map_info* mi = 0;
+
+ memset(classes_jsa, 0, sizeof(classes_jsa));
+ jvm_name = lib->name;
+ useSharedSpacesAddr = lookup_symbol(ph, jvm_name, USE_SHARED_SPACES_SYM);
+ if (useSharedSpacesAddr == 0) {
+ print_debug("can't lookup 'UseSharedSpaces' flag\n");
+ return false;
+ }
- // Hotspot vm types are not exported to build this library. So
- // using equivalent type jboolean to read the value of
- // UseSharedSpaces which is same as hotspot type "bool".
- if (read_jboolean(ph, useSharedSpacesAddr, &useSharedSpaces) != true) {
- print_debug("can't read the value of 'UseSharedSpaces' flag\n");
- return false;
- }
+ // Hotspot vm types are not exported to build this library. So
+ // using equivalent type jboolean to read the value of
+ // UseSharedSpaces which is same as hotspot type "bool".
+ if (read_jboolean(ph, useSharedSpacesAddr, &useSharedSpaces) != true) {
+ print_debug("can't read the value of 'UseSharedSpaces' flag\n");
+ return false;
+ }
- if ((int)useSharedSpaces == 0) {
- print_debug("UseSharedSpaces is false, assuming -Xshare:off!\n");
- return true;
- }
+ if ((int)useSharedSpaces == 0) {
+ print_debug("UseSharedSpaces is false, assuming -Xshare:off!\n");
+ return true;
+ }
- sharedArchivePathAddrAddr = lookup_symbol(ph, jvm_name, SHARED_ARCHIVE_PATH_SYM);
- if (sharedArchivePathAddrAddr == 0) {
- print_debug("can't lookup shared archive path symbol\n");
- return false;
- }
+ sharedArchivePathAddrAddr = lookup_symbol(ph, jvm_name, SHARED_ARCHIVE_PATH_SYM);
+ if (sharedArchivePathAddrAddr == 0) {
+ print_debug("can't lookup shared archive path symbol\n");
+ return false;
+ }
- if (read_pointer(ph, sharedArchivePathAddrAddr, &sharedArchivePathAddr) != true) {
- print_debug("can't read shared archive path pointer\n");
- return false;
- }
+ if (read_pointer(ph, sharedArchivePathAddrAddr, &sharedArchivePathAddr) != true) {
+ print_debug("can't read shared archive path pointer\n");
+ return false;
+ }
- if (read_string(ph, sharedArchivePathAddr, classes_jsa, sizeof(classes_jsa)) != true) {
- print_debug("can't read shared archive path value\n");
- return false;
- }
+ if (read_string(ph, sharedArchivePathAddr, classes_jsa, sizeof(classes_jsa)) != true) {
+ print_debug("can't read shared archive path value\n");
+ return false;
+ }
- print_debug("looking for %s\n", classes_jsa);
- // open the class sharing archive file
- fd = pathmap_open(classes_jsa);
- if (fd < 0) {
- print_debug("can't open %s!\n", classes_jsa);
- ph->core->classes_jsa_fd = -1;
- return false;
- } else {
- print_debug("opened %s\n", classes_jsa);
- }
+ print_debug("looking for %s\n", classes_jsa);
+ // open the class sharing archive file
+ fd = pathmap_open(classes_jsa);
+ if (fd < 0) {
+ print_debug("can't open %s!\n", classes_jsa);
+ ph->core->classes_jsa_fd = -1;
+ return false;
+ } else {
+ print_debug("opened %s\n", classes_jsa);
+ }
- // read FileMapHeader from the file
- memset(&header, 0, sizeof(struct FileMapHeader));
- if ((n = read(fd, &header, sizeof(struct FileMapHeader)))
- != sizeof(struct FileMapHeader)) {
- print_debug("can't read shared archive file map header from %s\n", classes_jsa);
- close(fd);
- return false;
- }
+ // read FileMapHeader from the file
+ memset(&header, 0, sizeof(struct FileMapHeader));
+ if ((n = read(fd, &header, sizeof(struct FileMapHeader)))
+ != sizeof(struct FileMapHeader)) {
+ print_debug("can't read shared archive file map header from %s\n", classes_jsa);
+ close(fd);
+ return false;
+ }
- // check file magic
- if (header._magic != 0xf00baba2) {
- print_debug("%s has bad shared archive file magic number 0x%x, expecing 0xf00baba2\n",
- classes_jsa, header._magic);
- close(fd);
- return false;
- }
+ // check file magic
+ if (header._magic != 0xf00baba2) {
+ print_debug("%s has bad shared archive file magic number 0x%x, expecing 0xf00baba2\n",
+ classes_jsa, header._magic);
+ close(fd);
+ return false;
+ }
- // check version
- if (header._version != CURRENT_ARCHIVE_VERSION) {
- print_debug("%s has wrong shared archive file version %d, expecting %d\n",
- classes_jsa, header._version, CURRENT_ARCHIVE_VERSION);
- close(fd);
- return false;
- }
+ // check version
+ if (header._version != CURRENT_ARCHIVE_VERSION) {
+ print_debug("%s has wrong shared archive file version %d, expecting %d\n",
+ classes_jsa, header._version, CURRENT_ARCHIVE_VERSION);
+ close(fd);
+ return false;
+ }
- ph->core->classes_jsa_fd = fd;
- // add read-only maps from classes.jsa to the list of maps
- for (m = 0; m < NUM_SHARED_MAPS; m++) {
- if (header._space[m]._read_only) {
- base = (uintptr_t) header._space[m]._base;
- // no need to worry about the fractional pages at-the-end.
- // possible fractional pages are handled by core_read_data.
- add_class_share_map_info(ph, (off_t) header._space[m]._file_offset,
- base, (size_t) header._space[m]._used);
- print_debug("added a share archive map at 0x%lx\n", base);
- }
- }
- return true;
+ ph->core->classes_jsa_fd = fd;
+ // add read-only maps from classes.jsa to the list of maps
+ for (m = 0; m < NUM_SHARED_MAPS; m++) {
+ if (header._space[m]._read_only) {
+ base = (uintptr_t) header._space[m]._base;
+ // no need to worry about the fractional pages at-the-end.
+ // possible fractional pages are handled by core_read_data.
+ add_class_share_map_info(ph, (off_t) header._space[m]._file_offset,
+ base, (size_t) header._space[m]._used);
+ print_debug("added a share archive map at 0x%lx\n", base);
+ }
}
- lib = lib->next;
+ return true;
}
- return true;
+ lib = lib->next;
+ }
+ return true;
}
@@ -396,54 +404,58 @@ static bool init_classsharing_workaround(struct ps_prochandle* ph) {
// callback for sorting the array of map_info pointers.
static int core_cmp_mapping(const void *lhsp, const void *rhsp)
{
- const map_info *lhs = *((const map_info **)lhsp);
- const map_info *rhs = *((const map_info **)rhsp);
+ const map_info *lhs = *((const map_info **)lhsp);
+ const map_info *rhs = *((const map_info **)rhsp);
- if (lhs->vaddr == rhs->vaddr)
- return (0);
+ if (lhs->vaddr == rhs->vaddr) {
+ return (0);
+ }
- return (lhs->vaddr < rhs->vaddr ? -1 : 1);
+ return (lhs->vaddr < rhs->vaddr ? -1 : 1);
}
// we sort map_info by starting virtual address so that we can do
// binary search to read from an address.
static bool sort_map_array(struct ps_prochandle* ph) {
- size_t num_maps = ph->core->num_maps;
- map_info* map = ph->core->maps;
- int i = 0;
+ size_t num_maps = ph->core->num_maps;
+ map_info* map = ph->core->maps;
+ int i = 0;
- // allocate map_array
- map_info** array;
- if ( (array = (map_info**) malloc(sizeof(map_info*) * num_maps)) == NULL) {
- print_debug("can't allocate memory for map array\n");
- return false;
- }
+ // allocate map_array
+ map_info** array;
+ if ( (array = (map_info**) malloc(sizeof(map_info*) * num_maps)) == NULL) {
+ print_debug("can't allocate memory for map array\n");
+ return false;
+ }
- // add maps to array
- while (map) {
- array[i] = map;
- i++;
- map = map->next;
- }
+ // add maps to array
+ while (map) {
+ array[i] = map;
+ i++;
+ map = map->next;
+ }
- // sort is called twice. If this is second time, clear map array
- if (ph->core->map_array) free(ph->core->map_array);
- ph->core->map_array = array;
- // sort the map_info array by base virtual address.
- qsort(ph->core->map_array, ph->core->num_maps, sizeof (map_info*),
- core_cmp_mapping);
+ // sort is called twice. If this is second time, clear map array
+ if (ph->core->map_array) {
+ free(ph->core->map_array);
+ }
- // print map
- if (is_debug()) {
- int j = 0;
- print_debug("---- sorted virtual address map ----\n");
- for (j = 0; j < ph->core->num_maps; j++) {
- print_debug("base = 0x%lx\tsize = %zu\n", ph->core->map_array[j]->vaddr,
- ph->core->map_array[j]->memsz);
- }
- }
+ ph->core->map_array = array;
+ // sort the map_info array by base virtual address.
+ qsort(ph->core->map_array, ph->core->num_maps, sizeof (map_info*),
+ core_cmp_mapping);
+
+ // print map
+ if (is_debug()) {
+ int j = 0;
+ print_debug("---- sorted virtual address map ----\n");
+ for (j = 0; j < ph->core->num_maps; j++) {
+ print_debug("base = 0x%lx\tsize = %zu\n", ph->core->map_array[j]->vaddr,
+ ph->core->map_array[j]->memsz);
+ }
+ }
- return true;
+ return true;
}
#ifndef MIN
@@ -460,16 +472,18 @@ static bool core_read_data(struct ps_prochandle* ph, uintptr_t addr, char *buf,
off_t off;
int fd;
- if (mp == NULL)
+ if (mp == NULL) {
break; /* No mapping for this address */
+ }
fd = mp->fd;
mapoff = addr - mp->vaddr;
len = MIN(resid, mp->memsz - mapoff);
off = mp->offset + mapoff;
- if ((len = pread(fd, buf, len, off)) <= 0)
+ if ((len = pread(fd, buf, len, off)) <= 0) {
break;
+ }
resid -= len;
addr += len;
@@ -625,8 +639,9 @@ static bool core_handle_note(struct ps_prochandle* ph, ELF_PHDR* note_phdr) {
notep->n_type, notep->n_descsz);
if (notep->n_type == NT_PRSTATUS) {
- if (core_handle_prstatus(ph, descdata, notep->n_descsz) != true)
- return false;
+ if (core_handle_prstatus(ph, descdata, notep->n_descsz) != true) {
+ return false;
+ }
}
p = descdata + ROUNDUP(notep->n_descsz, 4);
}
@@ -654,7 +669,7 @@ static bool read_core_segments(struct ps_prochandle* ph, ELF_EHDR* core_ehdr) {
* contains a set of saved /proc structures), and PT_LOAD (which
* represents a memory mapping from the process's address space).
*
- * Difference b/w Solaris PT_NOTE and Linux PT_NOTE:
+ * Difference b/w Solaris PT_NOTE and Linux/BSD PT_NOTE:
*
* In Solaris there are two PT_NOTE segments the first PT_NOTE (if present)
* contains /proc structs in the pre-2.6 unstructured /proc format. the last
@@ -674,7 +689,9 @@ static bool read_core_segments(struct ps_prochandle* ph, ELF_EHDR* core_ehdr) {
for (core_php = phbuf, i = 0; i < core_ehdr->e_phnum; i++) {
switch (core_php->p_type) {
case PT_NOTE:
- if (core_handle_note(ph, core_php) != true) goto err;
+ if (core_handle_note(ph, core_php) != true) {
+ goto err;
+ }
break;
case PT_LOAD: {
@@ -698,29 +715,61 @@ err:
// read segments of a shared object
static bool read_lib_segments(struct ps_prochandle* ph, int lib_fd, ELF_EHDR* lib_ehdr, uintptr_t lib_base) {
- int i = 0;
- ELF_PHDR* phbuf;
- ELF_PHDR* lib_php = NULL;
+ int i = 0;
+ ELF_PHDR* phbuf;
+ ELF_PHDR* lib_php = NULL;
- if ((phbuf = read_program_header_table(lib_fd, lib_ehdr)) == NULL)
- return false;
+ int page_size = sysconf(_SC_PAGE_SIZE);
- // we want to process only PT_LOAD segments that are not writable.
- // 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)
- goto err;
+ if ((phbuf = read_program_header_table(lib_fd, lib_ehdr)) == NULL) {
+ return false;
+ }
+
+ // we want to process only PT_LOAD segments that are not writable.
+ // 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)) {
+
+ uintptr_t target_vaddr = lib_php->p_vaddr + lib_base;
+ map_info *existing_map = core_lookup(ph, target_vaddr);
+
+ if (existing_map == NULL){
+ if (add_map_info(ph, lib_fd, lib_php->p_offset,
+ target_vaddr, lib_php->p_memsz) == NULL) {
+ goto err;
+ }
+ } else {
+ // Coredump stores value of p_memsz elf field
+ // rounded up to page boundary.
+
+ if ((existing_map->memsz != page_size) &&
+ (existing_map->fd != lib_fd) &&
+ (ROUNDUP(existing_map->memsz, page_size) != ROUNDUP(lib_php->p_memsz, page_size))) {
+
+ print_debug("address conflict @ 0x%lx (existing map size = %ld, size = %ld, flags = %d)\n",
+ target_vaddr, existing_map->memsz, lib_php->p_memsz, lib_php->p_flags);
+ goto err;
+ }
+
+ /* replace PT_LOAD segment with library segment */
+ print_debug("overwrote with new address mapping (memsz %ld -> %ld)\n",
+ existing_map->memsz, ROUNDUP(lib_php->p_memsz, page_size));
+
+ existing_map->fd = lib_fd;
+ existing_map->offset = lib_php->p_offset;
+ existing_map->memsz = ROUNDUP(lib_php->p_memsz, page_size);
}
- lib_php++;
- }
+ }
- free(phbuf);
- return true;
+ lib_php++;
+ }
+
+ free(phbuf);
+ return true;
err:
- free(phbuf);
- return false;
+ free(phbuf);
+ return false;
}
// process segments from interpreter (ld.so or ld-linux.so)
@@ -803,60 +852,62 @@ err:
// read shared library info from runtime linker's data structures.
// This work is done by librtlb_db in Solaris
static bool read_shared_lib_info(struct ps_prochandle* ph) {
- uintptr_t addr = ph->core->dynamic_addr;
- uintptr_t debug_base;
- uintptr_t first_link_map_addr;
- uintptr_t ld_base_addr;
- uintptr_t link_map_addr;
- uintptr_t lib_base_diff;
- uintptr_t lib_base;
- uintptr_t lib_name_addr;
- char lib_name[BUF_SIZE];
- ELF_DYN dyn;
- ELF_EHDR elf_ehdr;
- int lib_fd;
-
- // _DYNAMIC has information of the form
- // [tag] [data] [tag] [data] .....
- // Both tag and data are pointer sized.
- // We look for dynamic info with DT_DEBUG. This has shared object info.
- // refer to struct r_debug in link.h
-
- dyn.d_tag = DT_NULL;
- while (dyn.d_tag != DT_DEBUG) {
- if (ps_pdread(ph, (psaddr_t) addr, &dyn, sizeof(ELF_DYN)) != PS_OK) {
- print_debug("can't read debug info from _DYNAMIC\n");
- return false;
- }
- addr += sizeof(ELF_DYN);
- }
+ uintptr_t addr = ph->core->dynamic_addr;
+ uintptr_t debug_base;
+ uintptr_t first_link_map_addr;
+ uintptr_t ld_base_addr;
+ uintptr_t link_map_addr;
+ uintptr_t lib_base_diff;
+ uintptr_t lib_base;
+ uintptr_t lib_name_addr;
+ char lib_name[BUF_SIZE];
+ ELF_DYN dyn;
+ ELF_EHDR elf_ehdr;
+ int lib_fd;
+
+ // _DYNAMIC has information of the form
+ // [tag] [data] [tag] [data] .....
+ // Both tag and data are pointer sized.
+ // We look for dynamic info with DT_DEBUG. This has shared object info.
+ // refer to struct r_debug in link.h
+
+ dyn.d_tag = DT_NULL;
+ while (dyn.d_tag != DT_DEBUG) {
+ if (ps_pdread(ph, (psaddr_t) addr, &dyn, sizeof(ELF_DYN)) != PS_OK) {
+ print_debug("can't read debug info from _DYNAMIC\n");
+ return false;
+ }
+ addr += sizeof(ELF_DYN);
+ }
- // we have got Dyn entry with DT_DEBUG
- debug_base = dyn.d_un.d_ptr;
- // at debug_base we have struct r_debug. This has first link map in r_map field
- if (ps_pdread(ph, (psaddr_t) debug_base + FIRST_LINK_MAP_OFFSET,
+ // we have got Dyn entry with DT_DEBUG
+ debug_base = dyn.d_un.d_ptr;
+ // at debug_base we have struct r_debug. This has first link map in r_map field
+ if (ps_pdread(ph, (psaddr_t) debug_base + FIRST_LINK_MAP_OFFSET,
&first_link_map_addr, sizeof(uintptr_t)) != PS_OK) {
- print_debug("can't read first link map address\n");
- return false;
- }
+ print_debug("can't read first link map address\n");
+ return false;
+ }
- // read ld_base address from struct r_debug
- if (ps_pdread(ph, (psaddr_t) debug_base + LD_BASE_OFFSET, &ld_base_addr,
+ // read ld_base address from struct r_debug
+ if (ps_pdread(ph, (psaddr_t) debug_base + LD_BASE_OFFSET, &ld_base_addr,
sizeof(uintptr_t)) != PS_OK) {
- print_debug("can't read ld base address\n");
- return false;
- }
- ph->core->ld_base_addr = ld_base_addr;
+ print_debug("can't read ld base address\n");
+ return false;
+ }
+ ph->core->ld_base_addr = ld_base_addr;
- print_debug("interpreter base address is 0x%lx\n", ld_base_addr);
+ print_debug("interpreter base address is 0x%lx\n", ld_base_addr);
- // now read segments from interp (i.e ld.so or ld-linux.so)
- if (read_interp_segments(ph) != true)
+ // now read segments from interp (i.e ld.so or ld-linux.so or ld-elf.so)
+ if (read_interp_segments(ph) != true) {
return false;
+ }
- // after adding interpreter (ld.so) mappings sort again
- if (sort_map_array(ph) != true)
- return false;
+ // after adding interpreter (ld.so) mappings sort again
+ if (sort_map_array(ph) != true) {
+ return false;
+ }
print_debug("first link map is at 0x%lx\n", first_link_map_addr);
@@ -921,95 +972,102 @@ static bool read_shared_lib_info(struct ps_prochandle* ph) {
}
}
- // read next link_map address
- if (ps_pdread(ph, (psaddr_t) link_map_addr + LINK_MAP_NEXT_OFFSET,
- &link_map_addr, sizeof(uintptr_t)) != PS_OK) {
- print_debug("can't read next link in link_map\n");
- return false;
- }
- }
+ // read next link_map address
+ if (ps_pdread(ph, (psaddr_t) link_map_addr + LINK_MAP_NEXT_OFFSET,
+ &link_map_addr, sizeof(uintptr_t)) != PS_OK) {
+ print_debug("can't read next link in link_map\n");
+ return false;
+ }
+ }
- return true;
+ return true;
}
// the one and only one exposed stuff from this file
struct ps_prochandle* Pgrab_core(const char* exec_file, const char* core_file) {
- ELF_EHDR core_ehdr;
- ELF_EHDR exec_ehdr;
- ELF_EHDR lib_ehdr;
-
- struct ps_prochandle* ph = (struct ps_prochandle*) calloc(1, sizeof(struct ps_prochandle));
- if (ph == NULL) {
- print_debug("can't allocate ps_prochandle\n");
- return NULL;
- }
+ ELF_EHDR core_ehdr;
+ ELF_EHDR exec_ehdr;
+ ELF_EHDR lib_ehdr;
+
+ struct ps_prochandle* ph = (struct ps_prochandle*) calloc(1, sizeof(struct ps_prochandle));
+ if (ph == NULL) {
+ print_debug("can't allocate ps_prochandle\n");
+ return NULL;
+ }
- if ((ph->core = (struct core_data*) calloc(1, sizeof(struct core_data))) == NULL) {
- free(ph);
- print_debug("can't allocate ps_prochandle\n");
- return NULL;
- }
+ if ((ph->core = (struct core_data*) calloc(1, sizeof(struct core_data))) == NULL) {
+ free(ph);
+ print_debug("can't allocate ps_prochandle\n");
+ return NULL;
+ }
- // initialize ph
- ph->ops = &core_ops;
- ph->core->core_fd = -1;
- ph->core->exec_fd = -1;
- ph->core->interp_fd = -1;
+ // initialize ph
+ ph->ops = &core_ops;
+ ph->core->core_fd = -1;
+ ph->core->exec_fd = -1;
+ ph->core->interp_fd = -1;
- // open the core file
- if ((ph->core->core_fd = open(core_file, O_RDONLY)) < 0) {
- print_debug("can't open core file\n");
- goto err;
- }
+ // open the core file
+ if ((ph->core->core_fd = open(core_file, O_RDONLY)) < 0) {
+ print_debug("can't open core file\n");
+ goto err;
+ }
- // read core file ELF header
- if (read_elf_header(ph->core->core_fd, &core_ehdr) != true || core_ehdr.e_type != ET_CORE) {
- print_debug("core file is not a valid ELF ET_CORE file\n");
- goto err;
- }
+ // read core file ELF header
+ if (read_elf_header(ph->core->core_fd, &core_ehdr) != true || core_ehdr.e_type != ET_CORE) {
+ print_debug("core file is not a valid ELF ET_CORE file\n");
+ goto err;
+ }
- if ((ph->core->exec_fd = open(exec_file, O_RDONLY)) < 0) {
- print_debug("can't open executable file\n");
- goto err;
- }
+ if ((ph->core->exec_fd = open(exec_file, O_RDONLY)) < 0) {
+ print_debug("can't open executable file\n");
+ goto err;
+ }
- if (read_elf_header(ph->core->exec_fd, &exec_ehdr) != true || exec_ehdr.e_type != ET_EXEC) {
- print_debug("executable file is not a valid ELF ET_EXEC file\n");
- goto err;
- }
+ if (read_elf_header(ph->core->exec_fd, &exec_ehdr) != true || exec_ehdr.e_type != ET_EXEC) {
+ print_debug("executable file is not a valid ELF ET_EXEC file\n");
+ goto err;
+ }
- // process core file segments
- if (read_core_segments(ph, &core_ehdr) != true)
- goto err;
+ // process core file segments
+ if (read_core_segments(ph, &core_ehdr) != true) {
+ goto err;
+ }
- // process exec file segments
- if (read_exec_segments(ph, &exec_ehdr) != true)
- goto err;
+ // process exec file segments
+ if (read_exec_segments(ph, &exec_ehdr) != true) {
+ goto err;
+ }
- // exec file is also treated like a shared object for symbol search
- if (add_lib_info_fd(ph, exec_file, ph->core->exec_fd,
- (uintptr_t)0 + find_base_address(ph->core->exec_fd, &exec_ehdr)) == NULL)
- goto err;
+ // exec file is also treated like a shared object for symbol search
+ if (add_lib_info_fd(ph, exec_file, ph->core->exec_fd,
+ (uintptr_t)0 + find_base_address(ph->core->exec_fd, &exec_ehdr)) == NULL) {
+ goto err;
+ }
- // allocate and sort maps into map_array, we need to do this
- // here because read_shared_lib_info needs to read from debuggee
- // address space
- if (sort_map_array(ph) != true)
- goto err;
+ // allocate and sort maps into map_array, we need to do this
+ // here because read_shared_lib_info needs to read from debuggee
+ // address space
+ if (sort_map_array(ph) != true) {
+ goto err;
+ }
- if (read_shared_lib_info(ph) != true)
- goto err;
+ if (read_shared_lib_info(ph) != true) {
+ goto err;
+ }
- // sort again because we have added more mappings from shared objects
- if (sort_map_array(ph) != true)
- goto err;
+ // sort again because we have added more mappings from shared objects
+ if (sort_map_array(ph) != true) {
+ goto err;
+ }
- if (init_classsharing_workaround(ph) != true)
- goto err;
+ if (init_classsharing_workaround(ph) != true) {
+ goto err;
+ }
- return ph;
+ return ph;
err:
- Prelease(ph);
- return NULL;
+ Prelease(ph);
+ return NULL;
}
diff --git a/agent/src/os/linux/ps_proc.c b/agent/src/os/linux/ps_proc.c
index 61f08692c..61923a255 100644
--- a/agent/src/os/linux/ps_proc.c
+++ b/agent/src/os/linux/ps_proc.c
@@ -27,6 +27,8 @@
#include <string.h>
#include <signal.h>
#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include <sys/ptrace.h>
#include "libproc_impl.h"
diff --git a/agent/src/os/linux/salibelf.c b/agent/src/os/linux/salibelf.c
index 9634da8be..4c860a0fe 100644
--- a/agent/src/os/linux/salibelf.c
+++ b/agent/src/os/linux/salibelf.c
@@ -25,6 +25,7 @@
#include "salibelf.h"
#include <stdlib.h>
#include <unistd.h>
+#include <string.h>
extern void print_debug(const char*,...);
diff --git a/agent/src/os/linux/symtab.c b/agent/src/os/linux/symtab.c
index bea59e378..f9fc33f14 100644
--- a/agent/src/os/linux/symtab.c
+++ b/agent/src/os/linux/symtab.c
@@ -305,7 +305,7 @@ static struct symtab* build_symtab_from_build_id(Elf64_Nhdr *note)
unsigned char *bytes
= (unsigned char*)(note+1) + note->n_namesz;
- unsigned char *filename
+ char *filename
= (build_id_to_debug_filename (note->n_descsz, bytes));
fd = pathmap_open(filename);
diff --git a/agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java b/agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java
index 1840caf93..354f0b906 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/CommandProcessor.java
@@ -1213,6 +1213,7 @@ public class CommandProcessor {
}
HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase();
if (t.countTokens() == 1) {
+ String name = t.nextToken();
out.println("intConstant " + name + " " + db.lookupIntConstant(name));
} else if (t.countTokens() == 0) {
Iterator i = db.getIntConstants();
@@ -1235,6 +1236,7 @@ public class CommandProcessor {
}
HotSpotTypeDataBase db = (HotSpotTypeDataBase)agent.getTypeDataBase();
if (t.countTokens() == 1) {
+ String name = t.nextToken();
out.println("longConstant " + name + " " + db.lookupLongConstant(name));
} else if (t.countTokens() == 0) {
Iterator i = db.getLongConstants();
diff --git a/agent/src/share/classes/sun/jvm/hotspot/asm/Disassembler.java b/agent/src/share/classes/sun/jvm/hotspot/asm/Disassembler.java
index f6a279dee..9d351cb09 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/asm/Disassembler.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/asm/Disassembler.java
@@ -67,6 +67,13 @@ public class Disassembler {
String libname = "hsdis";
String arch = System.getProperty("os.arch");
if (os.lastIndexOf("Windows", 0) != -1) {
+ if (arch.equals("x86")) {
+ libname += "-i386";
+ } else if (arch.equals("amd64")) {
+ libname += "-amd64";
+ } else {
+ libname += "-" + arch;
+ }
path.append(sep + "bin" + sep);
libname += ".dll";
} else if (os.lastIndexOf("SunOS", 0) != -1) {
diff --git a/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java
index d1b56881f..f25d50ff2 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java
@@ -81,7 +81,7 @@ class BsdAddress implements Address {
public Address getCompKlassAddressAt(long offset)
throws UnalignedAddressException, UnmappedAddressException {
- return debugger.readCompOopAddress(addr + offset);
+ return debugger.readCompKlassAddress(addr + offset);
}
//
diff --git a/agent/src/share/classes/sun/jvm/hotspot/gc_implementation/g1/G1HeapRegionTable.java b/agent/src/share/classes/sun/jvm/hotspot/gc_implementation/g1/G1HeapRegionTable.java
new file mode 100644
index 000000000..11657ce31
--- /dev/null
+++ b/agent/src/share/classes/sun/jvm/hotspot/gc_implementation/g1/G1HeapRegionTable.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.gc_implementation.g1;
+
+import java.util.Iterator;
+import java.util.Observable;
+import java.util.Observer;
+
+import sun.jvm.hotspot.debugger.Address;
+import sun.jvm.hotspot.runtime.VM;
+import sun.jvm.hotspot.runtime.VMObject;
+import sun.jvm.hotspot.runtime.VMObjectFactory;
+import sun.jvm.hotspot.types.AddressField;
+import sun.jvm.hotspot.types.CIntegerField;
+import sun.jvm.hotspot.types.Type;
+import sun.jvm.hotspot.types.TypeDataBase;
+
+// Mirror class for G1HeapRegionTable. It's essentially an index -> HeapRegion map.
+
+public class G1HeapRegionTable extends VMObject {
+ // HeapRegion** _base;
+ static private AddressField baseField;
+ // uint _length;
+ static private CIntegerField lengthField;
+ // HeapRegion** _biased_base
+ static private AddressField biasedBaseField;
+ // size_t _bias
+ static private CIntegerField biasField;
+ // uint _shift_by
+ static private CIntegerField shiftByField;
+
+ static {
+ VM.registerVMInitializedObserver(new Observer() {
+ public void update(Observable o, Object data) {
+ initialize(VM.getVM().getTypeDataBase());
+ }
+ });
+ }
+
+ static private synchronized void initialize(TypeDataBase db) {
+ Type type = db.lookupType("G1HeapRegionTable");
+
+ baseField = type.getAddressField("_base");
+ lengthField = type.getCIntegerField("_length");
+ biasedBaseField = type.getAddressField("_biased_base");
+ biasField = type.getCIntegerField("_bias");
+ shiftByField = type.getCIntegerField("_shift_by");
+ }
+
+ private HeapRegion at(long index) {
+ Address arrayAddr = baseField.getValue(addr);
+ // Offset of &_base[index]
+ long offset = index * VM.getVM().getAddressSize();
+ Address regionAddr = arrayAddr.getAddressAt(offset);
+ return (HeapRegion) VMObjectFactory.newObject(HeapRegion.class,
+ regionAddr);
+ }
+
+ public long length() {
+ return lengthField.getValue(addr);
+ }
+
+ public long bias() {
+ return biasField.getValue(addr);
+ }
+
+ public long shiftBy() {
+ return shiftByField.getValue(addr);
+ }
+
+ private class HeapRegionIterator implements Iterator<HeapRegion> {
+ private long index;
+ private long length;
+
+ @Override
+ public boolean hasNext() { return index < length; }
+
+ @Override
+ public HeapRegion next() { return at(index++); }
+
+ @Override
+ public void remove() { /* not supported */ }
+
+ HeapRegionIterator(Address addr) {
+ index = 0;
+ length = length();
+ }
+ }
+
+ public Iterator<HeapRegion> heapRegionIterator() {
+ return new HeapRegionIterator(addr);
+ }
+
+ public G1HeapRegionTable(Address addr) {
+ super(addr);
+ }
+}
diff --git a/agent/src/share/classes/sun/jvm/hotspot/gc_implementation/g1/HeapRegionSeq.java b/agent/src/share/classes/sun/jvm/hotspot/gc_implementation/g1/HeapRegionSeq.java
index 5bd7f443d..f8b47abed 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/gc_implementation/g1/HeapRegionSeq.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/gc_implementation/g1/HeapRegionSeq.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -37,13 +37,11 @@ import sun.jvm.hotspot.types.CIntegerField;
import sun.jvm.hotspot.types.Type;
import sun.jvm.hotspot.types.TypeDataBase;
-// Mirror class for HeapRegionSeq. It's essentially an index -> HeapRegion map.
+// Mirror class for HeapRegionSeq. It essentially encapsulates the G1HeapRegionTable.
public class HeapRegionSeq extends VMObject {
- // HeapRegion** _regions;
- static private AddressField regionsField;
- // uint _length;
- static private CIntegerField lengthField;
+ // G1HeapRegionTable _regions
+ static private long regionsFieldOffset;
static {
VM.registerVMInitializedObserver(new Observer() {
@@ -56,44 +54,21 @@ public class HeapRegionSeq extends VMObject {
static private synchronized void initialize(TypeDataBase db) {
Type type = db.lookupType("HeapRegionSeq");
- regionsField = type.getAddressField("_regions");
- lengthField = type.getCIntegerField("_length");
+ regionsFieldOffset = type.getField("_regions").getOffset();
}
- private HeapRegion at(long index) {
- Address arrayAddr = regionsField.getValue(addr);
- // Offset of &_region[index]
- long offset = index * VM.getVM().getAddressSize();
- Address regionAddr = arrayAddr.getAddressAt(offset);
- return (HeapRegion) VMObjectFactory.newObject(HeapRegion.class,
- regionAddr);
+ private G1HeapRegionTable regions() {
+ Address regionsAddr = addr.addOffsetTo(regionsFieldOffset);
+ return (G1HeapRegionTable) VMObjectFactory.newObject(G1HeapRegionTable.class,
+ regionsAddr);
}
public long length() {
- return lengthField.getValue(addr);
- }
-
- private class HeapRegionIterator implements Iterator<HeapRegion> {
- private long index;
- private long length;
-
- @Override
- public boolean hasNext() { return index < length; }
-
- @Override
- public HeapRegion next() { return at(index++); }
-
- @Override
- public void remove() { /* not supported */ }
-
- HeapRegionIterator(Address addr) {
- index = 0;
- length = length();
- }
+ return regions().length();
}
public Iterator<HeapRegion> heapRegionIterator() {
- return new HeapRegionIterator(addr);
+ return regions().heapRegionIterator();
}
public HeapRegionSeq(Address addr) {
diff --git a/agent/src/share/classes/sun/jvm/hotspot/memory/ProtectionDomainCacheEntry.java b/agent/src/share/classes/sun/jvm/hotspot/memory/ProtectionDomainCacheEntry.java
new file mode 100644
index 000000000..2c9e736ec
--- /dev/null
+++ b/agent/src/share/classes/sun/jvm/hotspot/memory/ProtectionDomainCacheEntry.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot.memory;
+
+import java.util.*;
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.oops.*;
+import sun.jvm.hotspot.runtime.*;
+import sun.jvm.hotspot.types.*;
+
+public class ProtectionDomainCacheEntry extends VMObject {
+ private static sun.jvm.hotspot.types.OopField protectionDomainField;
+
+ static {
+ VM.registerVMInitializedObserver(new Observer() {
+ public void update(Observable o, Object data) {
+ initialize(VM.getVM().getTypeDataBase());
+ }
+ });
+ }
+
+ private static synchronized void initialize(TypeDataBase db) {
+ Type type = db.lookupType("ProtectionDomainCacheEntry");
+ protectionDomainField = type.getOopField("_literal");
+ }
+
+ public ProtectionDomainCacheEntry(Address addr) {
+ super(addr);
+ }
+
+ public Oop protectionDomain() {
+ return VM.getVM().getObjectHeap().newOop(protectionDomainField.getValue(addr));
+ }
+}
diff --git a/agent/src/share/classes/sun/jvm/hotspot/memory/ProtectionDomainEntry.java b/agent/src/share/classes/sun/jvm/hotspot/memory/ProtectionDomainEntry.java
index de2da04f9..27aa4e9f4 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/memory/ProtectionDomainEntry.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/memory/ProtectionDomainEntry.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -32,7 +32,7 @@ import sun.jvm.hotspot.types.*;
public class ProtectionDomainEntry extends VMObject {
private static AddressField nextField;
- private static sun.jvm.hotspot.types.OopField protectionDomainField;
+ private static AddressField pdCacheField;
static {
VM.registerVMInitializedObserver(new Observer() {
@@ -46,7 +46,7 @@ public class ProtectionDomainEntry extends VMObject {
Type type = db.lookupType("ProtectionDomainEntry");
nextField = type.getAddressField("_next");
- protectionDomainField = type.getOopField("_protection_domain");
+ pdCacheField = type.getAddressField("_pd_cache");
}
public ProtectionDomainEntry(Address addr) {
@@ -54,10 +54,12 @@ public class ProtectionDomainEntry extends VMObject {
}
public ProtectionDomainEntry next() {
- return (ProtectionDomainEntry) VMObjectFactory.newObject(ProtectionDomainEntry.class, addr);
+ return (ProtectionDomainEntry) VMObjectFactory.newObject(ProtectionDomainEntry.class, nextField.getValue(addr));
}
public Oop protectionDomain() {
- return VM.getVM().getObjectHeap().newOop(protectionDomainField.getValue(addr));
+ ProtectionDomainCacheEntry pd_cache = (ProtectionDomainCacheEntry)
+ VMObjectFactory.newObject(ProtectionDomainCacheEntry.class, pdCacheField.getValue(addr));
+ return pd_cache.protectionDomain();
}
}
diff --git a/agent/src/share/classes/sun/jvm/hotspot/memory/SymbolTable.java b/agent/src/share/classes/sun/jvm/hotspot/memory/SymbolTable.java
index 1c0a67681..3069cf6b3 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/memory/SymbolTable.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/memory/SymbolTable.java
@@ -44,12 +44,10 @@ public class SymbolTable extends sun.jvm.hotspot.utilities.Hashtable {
private static synchronized void initialize(TypeDataBase db) {
Type type = db.lookupType("SymbolTable");
theTableField = type.getAddressField("_the_table");
- symbolTableSize = db.lookupIntConstant("SymbolTable::symbol_table_size").intValue();
}
// Fields
private static AddressField theTableField;
- private static int symbolTableSize;
// Accessors
public static SymbolTable getTheTable() {
@@ -57,10 +55,6 @@ public class SymbolTable extends sun.jvm.hotspot.utilities.Hashtable {
return (SymbolTable) VMObjectFactory.newObject(SymbolTable.class, tmp);
}
- public static int getSymbolTableSize() {
- return symbolTableSize;
- }
-
public SymbolTable(Address addr) {
super(addr);
}
diff --git a/agent/src/share/classes/sun/jvm/hotspot/oops/ConstMethod.java b/agent/src/share/classes/sun/jvm/hotspot/oops/ConstMethod.java
index 3d0a370cd..585581fef 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/oops/ConstMethod.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/oops/ConstMethod.java
@@ -51,6 +51,7 @@ public class ConstMethod extends VMObject {
private static int HAS_GENERIC_SIGNATURE;
private static int HAS_METHOD_ANNOTATIONS;
private static int HAS_PARAMETER_ANNOTATIONS;
+ private static int HAS_METHOD_PARAMETERS;
private static int HAS_DEFAULT_ANNOTATIONS;
private static int HAS_TYPE_ANNOTATIONS;
@@ -70,6 +71,7 @@ public class ConstMethod extends VMObject {
HAS_GENERIC_SIGNATURE = db.lookupIntConstant("ConstMethod::_has_generic_signature").intValue();
HAS_METHOD_ANNOTATIONS = db.lookupIntConstant("ConstMethod::_has_method_annotations").intValue();
HAS_PARAMETER_ANNOTATIONS = db.lookupIntConstant("ConstMethod::_has_parameter_annotations").intValue();
+ HAS_METHOD_PARAMETERS = db.lookupIntConstant("ConstMethod::_has_method_parameters").intValue();
HAS_DEFAULT_ANNOTATIONS = db.lookupIntConstant("ConstMethod::_has_default_annotations").intValue();
HAS_TYPE_ANNOTATIONS = db.lookupIntConstant("ConstMethod::_has_type_annotations").intValue();
@@ -85,6 +87,9 @@ public class ConstMethod extends VMObject {
// start of byte code
bytecodeOffset = type.getSize();
+ type = db.lookupType("MethodParametersElement");
+ methodParametersElementSize = type.getSize();
+
type = db.lookupType("CheckedExceptionElement");
checkedExceptionElementSize = type.getSize();
@@ -113,7 +118,7 @@ public class ConstMethod extends VMObject {
// start of bytecode
private static long bytecodeOffset;
-
+ private static long methodParametersElementSize;
private static long checkedExceptionElementSize;
private static long localVariableTableElementSize;
private static long exceptionTableElementSize;
@@ -387,6 +392,10 @@ public class ConstMethod extends VMObject {
return ret;
}
+ private boolean hasMethodParameters() {
+ return (getFlags() & HAS_METHOD_PARAMETERS) != 0;
+ }
+
private boolean hasGenericSignature() {
return (getFlags() & HAS_GENERIC_SIGNATURE) != 0;
}
@@ -442,11 +451,41 @@ public class ConstMethod extends VMObject {
return offsetOfLastU2Element();
}
- private long offsetOfCheckedExceptionsLength() {
+ private long offsetOfMethodParametersLength() {
+ if (Assert.ASSERTS_ENABLED) {
+ Assert.that(hasMethodParameters(), "should only be called if table is present");
+ }
return hasGenericSignature() ? offsetOfLastU2Element() - sizeofShort :
offsetOfLastU2Element();
}
+ private int getMethodParametersLength() {
+ if (hasMethodParameters())
+ return (int) getAddress().getCIntegerAt(offsetOfMethodParametersLength(), 2, true);
+ else
+ return 0;
+ }
+
+ // Offset of start of checked exceptions
+ private long offsetOfMethodParameters() {
+ long offset = offsetOfMethodParametersLength();
+ long length = getMethodParametersLength();
+ if (Assert.ASSERTS_ENABLED) {
+ Assert.that(length > 0, "should only be called if method parameter information is present");
+ }
+ offset -= length * methodParametersElementSize;
+ return offset;
+ }
+
+ private long offsetOfCheckedExceptionsLength() {
+ if (hasMethodParameters())
+ return offsetOfMethodParameters() - sizeofShort;
+ else {
+ return hasGenericSignature() ? offsetOfLastU2Element() - sizeofShort :
+ offsetOfLastU2Element();
+ }
+ }
+
private int getCheckedExceptionsLength() {
if (hasCheckedExceptions()) {
return (int) getAddress().getCIntegerAt(offsetOfCheckedExceptionsLength(), 2, true);
@@ -496,6 +535,8 @@ public class ConstMethod extends VMObject {
return offsetOfExceptionTable() - sizeofShort;
} else if (hasCheckedExceptions()) {
return offsetOfCheckedExceptions() - sizeofShort;
+ } else if (hasMethodParameters()) {
+ return offsetOfMethodParameters() - sizeofShort;
} else {
return hasGenericSignature() ? offsetOfLastU2Element() - sizeofShort :
offsetOfLastU2Element();
@@ -526,6 +567,8 @@ public class ConstMethod extends VMObject {
}
if (hasCheckedExceptions()) {
return offsetOfCheckedExceptions() - sizeofShort;
+ } else if (hasMethodParameters()) {
+ return offsetOfMethodParameters() - sizeofShort;
} else {
return hasGenericSignature() ? offsetOfLastU2Element() - sizeofShort :
offsetOfLastU2Element();
diff --git a/agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java b/agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java
index 1cc2c8d91..01104f595 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java
@@ -354,9 +354,16 @@ public class InstanceKlass extends Klass {
public boolean getIsMarkedDependent() { return isMarkedDependent.getValue(this) != 0; }
public long getVtableLen() { return vtableLen.getValue(this); }
public long getItableLen() { return itableLen.getValue(this); }
- public Symbol getGenericSignature() { return getConstants().getSymbolAt(genericSignatureIndex.getValue(this)); }
public long majorVersion() { return majorVersion.getValue(this); }
public long minorVersion() { return minorVersion.getValue(this); }
+ public Symbol getGenericSignature() {
+ long index = genericSignatureIndex.getValue(this);
+ if (index != 0) {
+ return getConstants().getSymbolAt(index);
+ } else {
+ return null;
+ }
+ }
// "size helper" == instance size in words
public long getSizeHelper() {
diff --git a/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java b/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java
index f84da894a..8088a4999 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/runtime/VM.java
@@ -134,15 +134,13 @@ public class VM {
private String type;
private String name;
private Address addr;
- private String kind;
- private int origin;
+ private int flags;
- private Flag(String type, String name, Address addr, String kind, int origin) {
+ private Flag(String type, String name, Address addr, int flags) {
this.type = type;
this.name = name;
this.addr = addr;
- this.kind = kind;
- this.origin = origin;
+ this.flags = flags;
}
public String getType() {
@@ -157,12 +155,8 @@ public class VM {
return addr;
}
- public String getKind() {
- return kind;
- }
-
public int getOrigin() {
- return origin;
+ return flags & 0xF; // XXX can we get the mask bits from somewhere?
}
public boolean isBool() {
@@ -173,8 +167,7 @@ public class VM {
if (Assert.ASSERTS_ENABLED) {
Assert.that(isBool(), "not a bool flag!");
}
- return addr.getCIntegerAt(0, boolType.getSize(), boolType.isUnsigned())
- != 0;
+ return addr.getCIntegerAt(0, boolType.getSize(), boolType.isUnsigned()) != 0;
}
public boolean isIntx() {
@@ -792,7 +785,7 @@ public class VM {
public boolean isCompressedKlassPointersEnabled() {
if (compressedKlassPointersEnabled == null) {
- Flag flag = getCommandLineFlag("UseCompressedKlassPointers");
+ Flag flag = getCommandLineFlag("UseCompressedClassPointers");
compressedKlassPointersEnabled = (flag == null) ? Boolean.FALSE:
(flag.getBool()? Boolean.TRUE: Boolean.FALSE);
}
@@ -843,11 +836,10 @@ public class VM {
Address flagAddr = flagType.getAddressField("flags").getValue();
- AddressField typeFld = flagType.getAddressField("type");
- AddressField nameFld = flagType.getAddressField("name");
- AddressField addrFld = flagType.getAddressField("addr");
- AddressField kindFld = flagType.getAddressField("kind");
- CIntField originFld = new CIntField(flagType.getCIntegerField("origin"), 0);
+ AddressField typeFld = flagType.getAddressField("_type");
+ AddressField nameFld = flagType.getAddressField("_name");
+ AddressField addrFld = flagType.getAddressField("_addr");
+ CIntField flagsFld = new CIntField(flagType.getCIntegerField("_flags"), 0);
long flagSize = flagType.getSize(); // sizeof(Flag)
@@ -856,9 +848,8 @@ public class VM {
String type = CStringUtilities.getString(typeFld.getValue(flagAddr));
String name = CStringUtilities.getString(nameFld.getValue(flagAddr));
Address addr = addrFld.getValue(flagAddr);
- String kind = CStringUtilities.getString(kindFld.getValue(flagAddr));
- int origin = (int)originFld.getValue(flagAddr);
- commandLineFlags[f] = new Flag(type, name, addr, kind, origin);
+ int flags = (int)flagsFld.getValue(flagAddr);
+ commandLineFlags[f] = new Flag(type, name, addr, flags);
flagAddr = flagAddr.addOffsetTo(flagSize);
}
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/ClassLoaderStats.java b/agent/src/share/classes/sun/jvm/hotspot/tools/ClassLoaderStats.java
index eeda376b1..d2ea2db85 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/ClassLoaderStats.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/ClassLoaderStats.java
@@ -51,8 +51,7 @@ public class ClassLoaderStats extends Tool {
public static void main(String[] args) {
ClassLoaderStats cls = new ClassLoaderStats();
- cls.start(args);
- cls.stop();
+ cls.execute(args);
}
private static class ClassData {
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java b/agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java
index ed707b9ee..2a8ca2cfb 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java
@@ -54,8 +54,7 @@ public class FinalizerInfo extends Tool {
public static void main(String[] args) {
FinalizerInfo finfo = new FinalizerInfo();
- finfo.start(args);
- finfo.stop();
+ finfo.execute(args);
}
public void run() {
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/FlagDumper.java b/agent/src/share/classes/sun/jvm/hotspot/tools/FlagDumper.java
index c8db6d6b0..37fa4c83c 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/FlagDumper.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/FlagDumper.java
@@ -54,7 +54,6 @@ public class FlagDumper extends Tool {
public static void main(String[] args) {
FlagDumper fd = new FlagDumper();
- fd.start(args);
- fd.stop();
+ fd.execute(args);
}
}
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/HeapDumper.java b/agent/src/share/classes/sun/jvm/hotspot/tools/HeapDumper.java
index c5af0ed00..e2da202ac 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/HeapDumper.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/HeapDumper.java
@@ -80,8 +80,7 @@ public class HeapDumper extends Tool {
}
HeapDumper dumper = new HeapDumper(file);
- dumper.start(args);
- dumper.stop();
+ dumper.execute(args);
}
}
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java b/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java
index a0123dd4c..f87457c3c 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java
@@ -46,8 +46,7 @@ public class HeapSummary extends Tool {
public static void main(String[] args) {
HeapSummary hs = new HeapSummary();
- hs.start(args);
- hs.stop();
+ hs.execute(args);
}
public void run() {
@@ -66,18 +65,18 @@ public class HeapSummary extends Tool {
printGCAlgorithm(flagMap);
System.out.println();
System.out.println("Heap Configuration:");
- printValue("MinHeapFreeRatio = ", getFlagValue("MinHeapFreeRatio", flagMap));
- printValue("MaxHeapFreeRatio = ", getFlagValue("MaxHeapFreeRatio", flagMap));
- printValMB("MaxHeapSize = ", getFlagValue("MaxHeapSize", flagMap));
- printValMB("NewSize = ", getFlagValue("NewSize", flagMap));
- printValMB("MaxNewSize = ", getFlagValue("MaxNewSize", flagMap));
- printValMB("OldSize = ", getFlagValue("OldSize", flagMap));
- printValue("NewRatio = ", getFlagValue("NewRatio", flagMap));
- printValue("SurvivorRatio = ", getFlagValue("SurvivorRatio", flagMap));
- printValMB("MetaspaceSize = ", getFlagValue("MetaspaceSize", flagMap));
- printValMB("ClassMetaspaceSize = ", getFlagValue("ClassMetaspaceSize", flagMap));
- printValMB("MaxMetaspaceSize = ", getFlagValue("MaxMetaspaceSize", flagMap));
- printValMB("G1HeapRegionSize = ", HeapRegion.grainBytes());
+ printValue("MinHeapFreeRatio = ", getFlagValue("MinHeapFreeRatio", flagMap));
+ printValue("MaxHeapFreeRatio = ", getFlagValue("MaxHeapFreeRatio", flagMap));
+ printValMB("MaxHeapSize = ", getFlagValue("MaxHeapSize", flagMap));
+ printValMB("NewSize = ", getFlagValue("NewSize", flagMap));
+ printValMB("MaxNewSize = ", getFlagValue("MaxNewSize", flagMap));
+ printValMB("OldSize = ", getFlagValue("OldSize", flagMap));
+ printValue("NewRatio = ", getFlagValue("NewRatio", flagMap));
+ printValue("SurvivorRatio = ", getFlagValue("SurvivorRatio", flagMap));
+ printValMB("MetaspaceSize = ", getFlagValue("MetaspaceSize", flagMap));
+ printValMB("CompressedClassSpaceSize = ", getFlagValue("CompressedClassSpaceSize", flagMap));
+ printValMB("MaxMetaspaceSize = ", getFlagValue("MaxMetaspaceSize", flagMap));
+ printValMB("G1HeapRegionSize = ", HeapRegion.grainBytes());
System.out.println();
System.out.println("Heap Usage:");
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/JInfo.java b/agent/src/share/classes/sun/jvm/hotspot/tools/JInfo.java
index f24524207..6f9cd0f41 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/JInfo.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/JInfo.java
@@ -134,8 +134,7 @@ public class JInfo extends Tool {
}
JInfo jinfo = new JInfo(mode);
- jinfo.start(args);
- jinfo.stop();
+ jinfo.execute(args);
}
private void printVMFlags() {
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/JMap.java b/agent/src/share/classes/sun/jvm/hotspot/tools/JMap.java
index f6f3c0741..847eac194 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/JMap.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/JMap.java
@@ -136,7 +136,9 @@ public class JMap extends Tool {
mode = MODE_HEAP_GRAPH_GXL;
} else {
System.err.println("unknown heap format:" + format);
- return;
+
+ // Exit with error status
+ System.exit(1);
}
} else {
copyArgs = false;
@@ -153,8 +155,7 @@ public class JMap extends Tool {
}
JMap jmap = new JMap(mode);
- jmap.start(args);
- jmap.stop();
+ jmap.execute(args);
}
public boolean writeHeapHprofBin(String fileName) {
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/JSnap.java b/agent/src/share/classes/sun/jvm/hotspot/tools/JSnap.java
index 9301f1059..c2e5ed52f 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/JSnap.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/JSnap.java
@@ -64,7 +64,6 @@ public class JSnap extends Tool {
public static void main(String[] args) {
JSnap js = new JSnap();
- js.start(args);
- js.stop();
+ js.execute(args);
}
}
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/JStack.java b/agent/src/share/classes/sun/jvm/hotspot/tools/JStack.java
index 7cbe8f4d9..52fb6654e 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/JStack.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/JStack.java
@@ -89,8 +89,7 @@ public class JStack extends Tool {
}
JStack jstack = new JStack(mixedMode, concurrentLocks);
- jstack.start(args);
- jstack.stop();
+ jstack.execute(args);
}
private boolean mixedMode;
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/ObjectHistogram.java b/agent/src/share/classes/sun/jvm/hotspot/tools/ObjectHistogram.java
index 168202eec..6c6c555ba 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/ObjectHistogram.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/ObjectHistogram.java
@@ -61,7 +61,6 @@ public class ObjectHistogram extends Tool {
public static void main(String[] args) {
ObjectHistogram oh = new ObjectHistogram();
- oh.start(args);
- oh.stop();
+ oh.execute(args);
}
}
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/PMap.java b/agent/src/share/classes/sun/jvm/hotspot/tools/PMap.java
index 2a2341309..e18aa76cf 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/PMap.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/PMap.java
@@ -69,7 +69,6 @@ public class PMap extends Tool {
public static void main(String[] args) throws Exception {
PMap t = new PMap();
- t.start(args);
- t.stop();
+ t.execute(args);
}
}
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/PStack.java b/agent/src/share/classes/sun/jvm/hotspot/tools/PStack.java
index 7f10612b3..c4e7b5c7b 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/PStack.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/PStack.java
@@ -182,8 +182,7 @@ public class PStack extends Tool {
public static void main(String[] args) throws Exception {
PStack t = new PStack();
- t.start(args);
- t.stop();
+ t.execute(args);
}
// -- Internals only below this point
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/StackTrace.java b/agent/src/share/classes/sun/jvm/hotspot/tools/StackTrace.java
index eb0cc88d1..bbb0b081b 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/StackTrace.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/StackTrace.java
@@ -137,8 +137,7 @@ public class StackTrace extends Tool {
public static void main(String[] args) {
StackTrace st = new StackTrace();
- st.start(args);
- st.stop();
+ st.execute(args);
}
private boolean verbose;
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/SysPropsDumper.java b/agent/src/share/classes/sun/jvm/hotspot/tools/SysPropsDumper.java
index d601fef44..014655740 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/SysPropsDumper.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/SysPropsDumper.java
@@ -58,7 +58,6 @@ public class SysPropsDumper extends Tool {
public static void main(String[] args) {
SysPropsDumper pd = new SysPropsDumper();
- pd.start(args);
- pd.stop();
+ pd.execute(args);
}
}
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java b/agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java
index 3021801c9..19cfb349d 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java
@@ -26,6 +26,7 @@ package sun.jvm.hotspot.tools;
import java.io.PrintStream;
import java.util.Hashtable;
+
import sun.jvm.hotspot.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.debugger.*;
@@ -105,26 +106,44 @@ public abstract class Tool implements Runnable {
public static void main(String[] args) {
<derived class> obj = new <derived class>;
- obj.start(args);
+ obj.execute(args);
}
*/
- protected void stop() {
+ protected void execute(String[] args) {
+ int returnStatus = 1;
+
+ try {
+ returnStatus = start(args);
+ } finally {
+ stop();
+ }
+
+ // Exit with 0 or 1
+ System.exit(returnStatus);
+ }
+
+ public void stop() {
if (agent != null) {
agent.detach();
}
}
- protected void start(String[] args) {
+ private int start(String[] args) {
+
if ((args.length < 1) || (args.length > 2)) {
usage();
- return;
+ return 1;
}
// Attempt to handle -h or -help or some invalid flag
- if (args[0].startsWith("-")) {
+ if (args[0].startsWith("-h")) {
+ usage();
+ return 0;
+ } else if (args[0].startsWith("-")) {
usage();
+ return 1;
}
PrintStream err = System.err;
@@ -154,6 +173,7 @@ public abstract class Tool implements Runnable {
default:
usage();
+ return 1;
}
agent = new HotSpotAgent();
@@ -191,15 +211,16 @@ public abstract class Tool implements Runnable {
break;
}
if (e.getMessage() != null) {
- err.print(e.getMessage());
+ err.println(e.getMessage());
e.printStackTrace();
}
err.println();
- return;
+ return 1;
}
err.println("Debugger attached successfully.");
startInternal();
+ return 0;
}
// When using an existing JVMDebugger.
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassDump.java b/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassDump.java
index afd7f9865..98300c1d6 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassDump.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassDump.java
@@ -177,7 +177,6 @@ public class ClassDump extends Tool {
public static void main(String[] args) {
ClassDump cd = new ClassDump();
- cd.start(args);
- cd.stop();
+ cd.execute(args);
}
}
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/soql/JSDB.java b/agent/src/share/classes/sun/jvm/hotspot/tools/soql/JSDB.java
index 09874af17..db6dc3393 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/soql/JSDB.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/soql/JSDB.java
@@ -42,8 +42,7 @@ public class JSDB extends Tool {
public static void main(String[] args) {
JSDB jsdb = new JSDB();
- jsdb.start(args);
- jsdb.stop();
+ jsdb.execute(args);
}
public void run() {
diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/soql/SOQL.java b/agent/src/share/classes/sun/jvm/hotspot/tools/soql/SOQL.java
index b3054b90b..67f5ed1e9 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/soql/SOQL.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/soql/SOQL.java
@@ -40,8 +40,7 @@ import sun.jvm.hotspot.utilities.soql.*;
public class SOQL extends Tool {
public static void main(String[] args) {
SOQL soql = new SOQL();
- soql.start(args);
- soql.stop();
+ soql.execute(args);
}
public SOQL() {
diff --git a/agent/src/share/classes/sun/jvm/hotspot/utilities/AbstractHeapGraphWriter.java b/agent/src/share/classes/sun/jvm/hotspot/utilities/AbstractHeapGraphWriter.java
index a2d271c58..382d2477b 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/utilities/AbstractHeapGraphWriter.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/utilities/AbstractHeapGraphWriter.java
@@ -59,6 +59,7 @@ public abstract class AbstractHeapGraphWriter implements HeapGraphWriter {
public boolean doObj(Oop oop) {
try {
+ writeHeapRecordPrologue();
if (oop instanceof TypeArray) {
writePrimitiveArray((TypeArray)oop);
} else if (oop instanceof ObjArray) {
@@ -97,6 +98,7 @@ public abstract class AbstractHeapGraphWriter implements HeapGraphWriter {
// not-a-Java-visible oop
writeInternalObject(oop);
}
+ writeHeapRecordEpilogue();
} catch (IOException exp) {
throw new RuntimeException(exp);
}
@@ -416,6 +418,12 @@ public abstract class AbstractHeapGraphWriter implements HeapGraphWriter {
protected void writeHeapFooter() throws IOException {
}
+ protected void writeHeapRecordPrologue() throws IOException {
+ }
+
+ protected void writeHeapRecordEpilogue() throws IOException {
+ }
+
// HeapVisitor, OopVisitor methods can't throw any non-runtime
// exception. But, derived class write methods (which are called
// from visitor callbacks) may throw IOException. Hence, we throw
diff --git a/agent/src/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java b/agent/src/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java
index 65299721f..6f66723db 100644
--- a/agent/src/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java
+++ b/agent/src/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java
@@ -44,7 +44,7 @@ import sun.jvm.hotspot.runtime.*;
* WARNING: This format is still under development, and is subject to
* change without notice.
*
- * header "JAVA PROFILE 1.0.1" (0-terminated)
+ * header "JAVA PROFILE 1.0.1" or "JAVA PROFILE 1.0.2" (0-terminated)
* u4 size of identifiers. Identifiers are used to represent
* UTF8 strings, objects, stack traces, etc. They usually
* have the same size as host pointers. For example, on
@@ -292,11 +292,34 @@ import sun.jvm.hotspot.runtime.*;
* 0x00000002: cpu sampling on/off
* u2 stack trace depth
*
+ *
+ * When the header is "JAVA PROFILE 1.0.2" a heap dump can optionally
+ * be generated as a sequence of heap dump segments. This sequence is
+ * terminated by an end record. The additional tags allowed by format
+ * "JAVA PROFILE 1.0.2" are:
+ *
+ * HPROF_HEAP_DUMP_SEGMENT denote a heap dump segment
+ *
+ * [heap dump sub-records]*
+ * The same sub-record types allowed by HPROF_HEAP_DUMP
+ *
+ * HPROF_HEAP_DUMP_END denotes the end of a heap dump
+ *
*/
public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
+
+ // The heap size threshold used to determine if segmented format
+ // ("JAVA PROFILE 1.0.2") should be used.
+ private static final long HPROF_SEGMENTED_HEAP_DUMP_THRESHOLD = 2L * 0x40000000;
+
+ // The approximate size of a heap segment. Used to calculate when to create
+ // a new segment.
+ private static final long HPROF_SEGMENTED_HEAP_DUMP_SEGMENT_SIZE = 1L * 0x40000000;
+
// hprof binary file header
- private static final String HPROF_HEADER = "JAVA PROFILE 1.0.1";
+ private static final String HPROF_HEADER_1_0_1 = "JAVA PROFILE 1.0.1";
+ private static final String HPROF_HEADER_1_0_2 = "JAVA PROFILE 1.0.2";
// constants in enum HprofTag
private static final int HPROF_UTF8 = 0x01;
@@ -312,6 +335,10 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
private static final int HPROF_CPU_SAMPLES = 0x0D;
private static final int HPROF_CONTROL_SETTINGS = 0x0E;
+ // 1.0.2 record types
+ private static final int HPROF_HEAP_DUMP_SEGMENT = 0x1C;
+ private static final int HPROF_HEAP_DUMP_END = 0x2C;
+
// Heap dump constants
// constants in enum HprofGcTag
private static final int HPROF_GC_ROOT_UNKNOWN = 0xFF;
@@ -352,11 +379,9 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
private static final int JVM_SIGNATURE_ARRAY = '[';
private static final int JVM_SIGNATURE_CLASS = 'L';
-
public synchronized void write(String fileName) throws IOException {
// open file stream and create buffered data output stream
- FileOutputStream fos = new FileOutputStream(fileName);
- FileChannel chn = fos.getChannel();
+ fos = new FileOutputStream(fileName);
out = new DataOutputStream(new BufferedOutputStream(fos));
VM vm = VM.getVM();
@@ -385,6 +410,9 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
FLOAT_SIZE = objectHeap.getFloatSize();
DOUBLE_SIZE = objectHeap.getDoubleSize();
+ // Check weather we should dump the heap as segments
+ useSegmentedHeapDump = vm.getUniverse().heap().used() > HPROF_SEGMENTED_HEAP_DUMP_THRESHOLD;
+
// hprof bin format header
writeFileHeader();
@@ -394,38 +422,87 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
// hprof UTF-8 symbols section
writeSymbols();
+
// HPROF_LOAD_CLASS records for all classes
writeClasses();
- // write heap data now
- out.writeByte((byte)HPROF_HEAP_DUMP);
- out.writeInt(0); // relative timestamp
-
- // remember position of dump length, we will fixup
- // length later - hprof format requires length.
- out.flush();
- long dumpStart = chn.position();
-
- // write dummy length of 0 and we'll fix it later.
- out.writeInt(0);
-
// write CLASS_DUMP records
writeClassDumpRecords();
// this will write heap data into the buffer stream
super.write();
+ // flush buffer stream.
+ out.flush();
+
+ // Fill in final length
+ fillInHeapRecordLength();
+
+ if (useSegmentedHeapDump) {
+ // Write heap segment-end record
+ out.writeByte((byte) HPROF_HEAP_DUMP_END);
+ out.writeInt(0);
+ out.writeInt(0);
+ }
+
// flush buffer stream and throw it.
out.flush();
out = null;
+ // close the file stream
+ fos.close();
+ }
+
+ @Override
+ protected void writeHeapRecordPrologue() throws IOException {
+ if (currentSegmentStart == 0) {
+ // write heap data header, depending on heap size use segmented heap
+ // format
+ out.writeByte((byte) (useSegmentedHeapDump ? HPROF_HEAP_DUMP_SEGMENT
+ : HPROF_HEAP_DUMP));
+ out.writeInt(0);
+
+ // remember position of dump length, we will fixup
+ // length later - hprof format requires length.
+ out.flush();
+ currentSegmentStart = fos.getChannel().position();
+
+ // write dummy length of 0 and we'll fix it later.
+ out.writeInt(0);
+ }
+ }
+
+ @Override
+ protected void writeHeapRecordEpilogue() throws IOException {
+ if (useSegmentedHeapDump) {
+ out.flush();
+ if ((fos.getChannel().position() - currentSegmentStart - 4) >= HPROF_SEGMENTED_HEAP_DUMP_SEGMENT_SIZE) {
+ fillInHeapRecordLength();
+ currentSegmentStart = 0;
+ }
+ }
+ }
+
+ private void fillInHeapRecordLength() throws IOException {
+
// now get current position to calculate length
- long dumpEnd = chn.position();
+ long dumpEnd = fos.getChannel().position();
+
// calculate length of heap data
- int dumpLen = (int) (dumpEnd - dumpStart - 4);
+ long dumpLenLong = (dumpEnd - currentSegmentStart - 4L);
+
+ // Check length boundary, overflow could happen but is _very_ unlikely
+ if(dumpLenLong >= (4L * 0x40000000)){
+ throw new RuntimeException("Heap segment size overflow.");
+ }
+
+ // Save the current position
+ long currentPosition = fos.getChannel().position();
// seek the position to write length
- chn.position(dumpStart);
+ fos.getChannel().position(currentSegmentStart);
+
+ int dumpLen = (int) dumpLenLong;
// write length as integer
fos.write((dumpLen >>> 24) & 0xFF);
@@ -433,8 +510,8 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
fos.write((dumpLen >>> 8) & 0xFF);
fos.write((dumpLen >>> 0) & 0xFF);
- // close the file stream
- fos.close();
+ //Reset to previous current position
+ fos.getChannel().position(currentPosition);
}
private void writeClassDumpRecords() throws IOException {
@@ -443,7 +520,9 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
sysDict.allClassesDo(new SystemDictionary.ClassVisitor() {
public void visit(Klass k) {
try {
+ writeHeapRecordPrologue();
writeClassDumpRecord(k);
+ writeHeapRecordEpilogue();
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -884,7 +963,12 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
// writes hprof binary file header
private void writeFileHeader() throws IOException {
// version string
- out.writeBytes(HPROF_HEADER);
+ if(useSegmentedHeapDump) {
+ out.writeBytes(HPROF_HEADER_1_0_2);
+ }
+ else {
+ out.writeBytes(HPROF_HEADER_1_0_1);
+ }
out.writeByte((byte)'\0');
// write identifier size. we use pointers as identifiers.
@@ -976,6 +1060,7 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
private static final int EMPTY_FRAME_DEPTH = -1;
private DataOutputStream out;
+ private FileOutputStream fos;
private Debugger dbg;
private ObjectHeap objectHeap;
private SymbolTable symTbl;
@@ -983,6 +1068,10 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
// oopSize of the debuggee
private int OBJ_ID_SIZE;
+ // Added for hprof file format 1.0.2 support
+ private boolean useSegmentedHeapDump;
+ private long currentSegmentStart;
+
private long BOOLEAN_BASE_OFFSET;
private long BYTE_BASE_OFFSET;
private long CHAR_BASE_OFFSET;
@@ -1005,6 +1094,7 @@ public class HeapHprofBinWriter extends AbstractHeapGraphWriter {
private static class ClassData {
int instSize;
List fields;
+
ClassData(int instSize, List fields) {
this.instSize = instSize;
this.fields = fields;