changeset 3067:7e508fbcb950 jdk7u4-b01

Merge
author jcoomes
date Thu, 27 Oct 2011 12:21:43 -0700
parents 92be6a664a86 4538caeef7b6
children b6d9d5bbea50
files .hgtags make/hotspot_version make/templates/bsd-header src/cpu/x86/vm/vm_version_x86.cpp src/os/windows/vm/os_windows.cpp src/share/vm/prims/methodHandleWalk.cpp
diffstat 444 files changed, 38710 insertions(+), 1890 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Oct 26 12:43:05 2011 -0700
+++ b/.hgignore	Thu Oct 27 12:21:43 2011 -0700
@@ -6,3 +6,4 @@
 ^src/share/tools/IdealGraphVisualizer/build/
 ^src/share/tools/IdealGraphVisualizer/dist/
 ^.hgtip
+.DS_Store
--- a/.hgtags	Wed Oct 26 12:43:05 2011 -0700
+++ b/.hgtags	Thu Oct 27 12:21:43 2011 -0700
@@ -188,6 +188,8 @@
 3a2fb61165dfc72e398179a2796d740c8da5b8c0 jdk8-b03
 0fa3ace511fe98fe948e751531f3e2b7c60c8376 jdk8-b04
 dce7d24674f4d0bed00de24f00119057fdce7cfb jdk8-b05
+0db80d8e77fccddf5e6fa49963226b54ac7d0f62 jdk8-b06
+3f0cf875af83f55ec5e1a5cea80455315f9322a2 jdk8-b07
 0cc8a70952c368e06de2adab1f2649a408f5e577 hs22-b01
 7c29742c41b44fb0cd5a13c7ac8834f3f2ca649e hs22-b02
 3a2fb61165dfc72e398179a2796d740c8da5b8c0 hs22-b03
@@ -199,3 +201,9 @@
 513a84dd0f8b56dc0836b4e0bdd5dd0a778fc634 hs22-b05
 650d15d8f37255d3b805aa00c5bd1c30984b203d hs22-b06
 8035e71ac3f6c8a453f7e9483e7144731388b14e jdk7u2-b08
+da883b9e6d3788057f9577e72712998ed82c9b7e hs23-b01
+49ed7eacfd16616166ff066493143889741097af jdk8-b08
+7c20d272643f47195478708eff593a9cce40fec4 jdk8-b09
+e4f412d2b75d2c797acff965aa2c420e3d358f09 hs23-b02
+d815de2e85e511b7deab2a83cf80c0224d011da9 jdk8-b10
+4d3850d9d326ac3a9bee2d867727e954322d014e hs23-b03
--- a/agent/make/Makefile	Wed Oct 26 12:43:05 2011 -0700
+++ b/agent/make/Makefile	Thu Oct 27 12:21:43 2011 -0700
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2000, 2011, 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
@@ -53,6 +53,9 @@
 sun.jvm.hotspot.compiler \
 sun.jvm.hotspot.debugger \
 sun.jvm.hotspot.debugger.amd64 \
+sun.jvm.hotspot.debugger.bsd \
+sun.jvm.hotspot.debugger.bsd.amd64 \
+sun.jvm.hotspot.debugger.bsd.x86 \
 sun.jvm.hotspot.debugger.cdbg \
 sun.jvm.hotspot.debugger.cdbg.basic \
 sun.jvm.hotspot.debugger.cdbg.basic.amd64 \
@@ -81,6 +84,7 @@
 sun.jvm.hotspot.debugger.windbg.x86 \
 sun.jvm.hotspot.debugger.x86 \
 sun.jvm.hotspot.gc_implementation \
+sun.jvm.hotspot.gc_implementation.g1 \
 sun.jvm.hotspot.gc_implementation.parallelScavenge \
 sun.jvm.hotspot.gc_implementation.shared \
 sun.jvm.hotspot.gc_interface \
@@ -93,6 +97,9 @@
 sun.jvm.hotspot.prims \
 sun.jvm.hotspot.runtime \
 sun.jvm.hotspot.runtime.amd64 \
+sun.jvm.hotspot.runtime.bsd \
+sun.jvm.hotspot.runtime.bsd_amd64 \
+sun.jvm.hotspot.runtime.bsd_x86 \
 sun.jvm.hotspot.runtime.ia64 \
 sun.jvm.hotspot.runtime.linux \
 sun.jvm.hotspot.runtime.linux_amd64 \
@@ -143,6 +150,9 @@
 sun/jvm/hotspot/compiler/*.java \
 sun/jvm/hotspot/debugger/*.java \
 sun/jvm/hotspot/debugger/amd64/*.java \
+sun/jvm/hotspot/debugger/bsd/*.java \
+sun/jvm/hotspot/debugger/bsd/amd64/*.java \
+sun/jvm/hotspot/debugger/bsd/x86/*.java \
 sun/jvm/hotspot/debugger/cdbg/*.java \
 sun/jvm/hotspot/debugger/cdbg/basic/*.java \
 sun/jvm/hotspot/debugger/cdbg/basic/amd64/*.java \
@@ -167,6 +177,9 @@
 sun/jvm/hotspot/debugger/windbg/ia64/*.java \
 sun/jvm/hotspot/debugger/windbg/x86/*.java \
 sun/jvm/hotspot/debugger/x86/*.java \
+sun/jvm/hotspot/gc_implementation/g1/*.java \
+sun/jvm/hotspot/gc_implementation/parallelScavenge/*.java \
+sun/jvm/hotspot/gc_implementation/shared/*.java \
 sun/jvm/hotspot/interpreter/*.java \
 sun/jvm/hotspot/jdi/*.java \
 sun/jvm/hotspot/livejvm/*.java \
@@ -176,6 +189,9 @@
 sun/jvm/hotspot/prims/*.java \
 sun/jvm/hotspot/runtime/*.java \
 sun/jvm/hotspot/runtime/amd64/*.java \
+sun/jvm/hotspot/runtime/bsd/*.java \
+sun/jvm/hotspot/runtime/bsd_amd64/*.java \
+sun/jvm/hotspot/runtime/bsd_x86/*.java \
 sun/jvm/hotspot/runtime/ia64/*.java \
 sun/jvm/hotspot/runtime/linux/*.java \
 sun/jvm/hotspot/runtime/linux_amd64/*.java \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/BsdDebuggerLocal.c	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,413 @@
+/*
+ * Copyright (c) 2002, 2007, 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.
+ *
+ */
+
+#include <stdlib.h>
+#include <jni.h>
+#include "libproc.h"
+
+#if defined(x86_64) && !defined(amd64)
+#define amd64 1
+#endif
+
+#ifdef i386
+#include "sun_jvm_hotspot_debugger_x86_X86ThreadContext.h"
+#endif
+
+#ifdef amd64
+#include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h"
+#endif
+
+#if defined(sparc) || defined(sparcv9)
+#include "sun_jvm_hotspot_debugger_sparc_SPARCThreadContext.h"
+#endif
+
+static jfieldID p_ps_prochandle_ID = 0;
+static jfieldID threadList_ID = 0;
+static jfieldID loadObjectList_ID = 0;
+
+static jmethodID createClosestSymbol_ID = 0;
+static jmethodID createLoadObject_ID = 0;
+static jmethodID getThreadForThreadId_ID = 0;
+static jmethodID listAdd_ID = 0;
+
+#define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; }
+#define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;}
+#define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; }
+#define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;}
+
+static void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) {
+  (*env)->ThrowNew(env, (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"), errMsg);
+}
+
+static struct ps_prochandle* get_proc_handle(JNIEnv* env, jobject this_obj) {
+  jlong ptr = (*env)->GetLongField(env, this_obj, p_ps_prochandle_ID);
+  return (struct ps_prochandle*)(intptr_t)ptr;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    init0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0
+  (JNIEnv *env, jclass cls) {
+  jclass listClass;
+
+  if (init_libproc(getenv("LIBSAPROC_DEBUG") != NULL) != true) {
+     THROW_NEW_DEBUGGER_EXCEPTION("can't initialize libproc");
+  }
+
+  // fields we use
+  p_ps_prochandle_ID = (*env)->GetFieldID(env, cls, "p_ps_prochandle", "J");
+  CHECK_EXCEPTION;
+  threadList_ID = (*env)->GetFieldID(env, cls, "threadList", "Ljava/util/List;");
+  CHECK_EXCEPTION;
+  loadObjectList_ID = (*env)->GetFieldID(env, cls, "loadObjectList", "Ljava/util/List;");
+  CHECK_EXCEPTION;
+
+  // methods we use
+  createClosestSymbol_ID = (*env)->GetMethodID(env, cls, "createClosestSymbol",
+                    "(Ljava/lang/String;J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;");
+  CHECK_EXCEPTION;
+  createLoadObject_ID = (*env)->GetMethodID(env, cls, "createLoadObject",
+                    "(Ljava/lang/String;JJ)Lsun/jvm/hotspot/debugger/cdbg/LoadObject;");
+  CHECK_EXCEPTION;
+  getThreadForThreadId_ID = (*env)->GetMethodID(env, cls, "getThreadForThreadId",
+                                                     "(J)Lsun/jvm/hotspot/debugger/ThreadProxy;");
+  CHECK_EXCEPTION;
+  // java.util.List method we call
+  listClass = (*env)->FindClass(env, "java/util/List");
+  CHECK_EXCEPTION;
+  listAdd_ID = (*env)->GetMethodID(env, listClass, "add", "(Ljava/lang/Object;)Z");
+  CHECK_EXCEPTION;
+}
+
+JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getAddressSize
+  (JNIEnv *env, jclass cls)
+{
+#ifdef _LP64
+ return 8;
+#else
+ return 4;
+#endif
+
+}
+
+
+static void fillThreadsAndLoadObjects(JNIEnv* env, jobject this_obj, struct ps_prochandle* ph) {
+  int n = 0, i = 0;
+
+  // add threads
+  n = get_num_threads(ph);
+  for (i = 0; i < n; i++) {
+    jobject thread;
+    jobject threadList;
+    lwpid_t lwpid;
+
+    lwpid = get_lwp_id(ph, i);
+    thread = (*env)->CallObjectMethod(env, this_obj, getThreadForThreadId_ID,
+                                      (jlong)lwpid);
+    CHECK_EXCEPTION;
+    threadList = (*env)->GetObjectField(env, this_obj, threadList_ID);
+    CHECK_EXCEPTION;
+    (*env)->CallBooleanMethod(env, threadList, listAdd_ID, thread);
+    CHECK_EXCEPTION;
+  }
+
+  // add load objects
+  n = get_num_libs(ph);
+  for (i = 0; i < n; i++) {
+     uintptr_t base;
+     const char* name;
+     jobject loadObject;
+     jobject loadObjectList;
+
+     base = get_lib_base(ph, i);
+     name = get_lib_name(ph, i);
+     loadObject = (*env)->CallObjectMethod(env, this_obj, createLoadObject_ID,
+                                   (*env)->NewStringUTF(env, name), (jlong)0, (jlong)base);
+     CHECK_EXCEPTION;
+     loadObjectList = (*env)->GetObjectField(env, this_obj, loadObjectList_ID);
+     CHECK_EXCEPTION;
+     (*env)->CallBooleanMethod(env, loadObjectList, listAdd_ID, loadObject);
+     CHECK_EXCEPTION;
+  }
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    attach0
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I
+  (JNIEnv *env, jobject this_obj, jint jpid) {
+
+  struct ps_prochandle* ph;
+  if ( (ph = Pgrab(jpid)) == NULL) {
+    THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process");
+  }
+  (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
+  fillThreadsAndLoadObjects(env, this_obj, ph);
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    attach0
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
+  (JNIEnv *env, jobject this_obj, jstring execName, jstring coreName) {
+  const char *execName_cstr;
+  const char *coreName_cstr;
+  jboolean isCopy;
+  struct ps_prochandle* ph;
+
+  execName_cstr = (*env)->GetStringUTFChars(env, execName, &isCopy);
+  CHECK_EXCEPTION;
+  coreName_cstr = (*env)->GetStringUTFChars(env, coreName, &isCopy);
+  CHECK_EXCEPTION;
+
+  if ( (ph = Pgrab_core(execName_cstr, coreName_cstr)) == NULL) {
+    (*env)->ReleaseStringUTFChars(env, execName, execName_cstr);
+    (*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr);
+    THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the core file");
+  }
+  (*env)->SetLongField(env, this_obj, p_ps_prochandle_ID, (jlong)(intptr_t)ph);
+  (*env)->ReleaseStringUTFChars(env, execName, execName_cstr);
+  (*env)->ReleaseStringUTFChars(env, coreName, coreName_cstr);
+  fillThreadsAndLoadObjects(env, this_obj, ph);
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    detach0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0
+  (JNIEnv *env, jobject this_obj) {
+  struct ps_prochandle* ph = get_proc_handle(env, this_obj);
+  if (ph != NULL) {
+     Prelease(ph);
+  }
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    lookupByName0
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0
+  (JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) {
+  const char *objectName_cstr, *symbolName_cstr;
+  jlong addr;
+  jboolean isCopy;
+  struct ps_prochandle* ph = get_proc_handle(env, this_obj);
+
+  objectName_cstr = NULL;
+  if (objectName != NULL) {
+    objectName_cstr = (*env)->GetStringUTFChars(env, objectName, &isCopy);
+    CHECK_EXCEPTION_(0);
+  }
+  symbolName_cstr = (*env)->GetStringUTFChars(env, symbolName, &isCopy);
+  CHECK_EXCEPTION_(0);
+
+  addr = (jlong) lookup_symbol(ph, objectName_cstr, symbolName_cstr);
+
+  if (objectName_cstr != NULL) {
+    (*env)->ReleaseStringUTFChars(env, objectName, objectName_cstr);
+  }
+  (*env)->ReleaseStringUTFChars(env, symbolName, symbolName_cstr);
+  return addr;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    lookupByAddress0
+ * Signature: (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;
+ */
+JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByAddress0
+  (JNIEnv *env, jobject this_obj, jlong addr) {
+  uintptr_t offset;
+  const char* sym = NULL;
+
+  struct ps_prochandle* ph = get_proc_handle(env, this_obj);
+  sym = symbol_for_pc(ph, (uintptr_t) addr, &offset);
+  if (sym == NULL) return 0;
+  return (*env)->CallObjectMethod(env, this_obj, createClosestSymbol_ID,
+                          (*env)->NewStringUTF(env, sym), (jlong)offset);
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    readBytesFromProcess0
+ * Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
+ */
+JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0
+  (JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) {
+
+  jboolean isCopy;
+  jbyteArray array;
+  jbyte *bufPtr;
+  ps_err_e err;
+
+  array = (*env)->NewByteArray(env, numBytes);
+  CHECK_EXCEPTION_(0);
+  bufPtr = (*env)->GetByteArrayElements(env, array, &isCopy);
+  CHECK_EXCEPTION_(0);
+
+  err = ps_pread(get_proc_handle(env, this_obj), (psaddr_t) (uintptr_t)addr, bufPtr, numBytes);
+  (*env)->ReleaseByteArrayElements(env, array, bufPtr, 0);
+  return (err == PS_OK)? array : 0;
+}
+
+JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0
+  (JNIEnv *env, jobject this_obj, jint lwp_id) {
+
+  struct reg gregs;
+  jboolean isCopy;
+  jlongArray array;
+  jlong *regs;
+
+  struct ps_prochandle* ph = get_proc_handle(env, this_obj);
+  if (get_lwp_regs(ph, lwp_id, &gregs) != true) {
+     THROW_NEW_DEBUGGER_EXCEPTION_("get_thread_regs failed for a lwp", 0);
+  }
+
+#undef NPRGREG
+#ifdef i386
+#define NPRGREG sun_jvm_hotspot_debugger_x86_X86ThreadContext_NPRGREG
+#endif
+#ifdef ia64
+#define NPRGREG IA64_REG_COUNT
+#endif
+#ifdef amd64
+#define NPRGREG sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_NPRGREG
+#endif
+#if defined(sparc) || defined(sparcv9)
+#define NPRGREG sun_jvm_hotspot_debugger_sparc_SPARCThreadContext_NPRGREG
+#endif
+
+  array = (*env)->NewLongArray(env, NPRGREG);
+  CHECK_EXCEPTION_(0);
+  regs = (*env)->GetLongArrayElements(env, array, &isCopy);
+
+#undef REG_INDEX
+
+#ifdef i386
+#define REG_INDEX(reg) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##reg
+
+  regs[REG_INDEX(GS)]  = (uintptr_t) gregs.r_gs;
+  regs[REG_INDEX(FS)]  = (uintptr_t) gregs.r_fs;
+  regs[REG_INDEX(ES)]  = (uintptr_t) gregs.r_es;
+  regs[REG_INDEX(DS)]  = (uintptr_t) gregs.r_ds;
+  regs[REG_INDEX(EDI)] = (uintptr_t) gregs.r_edi;
+  regs[REG_INDEX(ESI)] = (uintptr_t) gregs.r_esi;
+  regs[REG_INDEX(FP)] = (uintptr_t) gregs.r_ebp;
+  regs[REG_INDEX(SP)] = (uintptr_t) gregs.r_isp;
+  regs[REG_INDEX(EBX)] = (uintptr_t) gregs.r_ebx;
+  regs[REG_INDEX(EDX)] = (uintptr_t) gregs.r_edx;
+  regs[REG_INDEX(ECX)] = (uintptr_t) gregs.r_ecx;
+  regs[REG_INDEX(EAX)] = (uintptr_t) gregs.r_eax;
+  regs[REG_INDEX(PC)] = (uintptr_t) gregs.r_eip;
+  regs[REG_INDEX(CS)]  = (uintptr_t) gregs.r_cs;
+  regs[REG_INDEX(SS)]  = (uintptr_t) gregs.r_ss;
+
+#endif /* i386 */
+
+#if ia64
+  regs = (*env)->GetLongArrayElements(env, array, &isCopy);
+  int i;
+  for (i = 0; i < NPRGREG; i++ ) {
+    regs[i] = 0xDEADDEAD;
+  }
+#endif /* ia64 */
+
+#ifdef amd64
+#define REG_INDEX(reg) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##reg
+
+  regs[REG_INDEX(R15)] = gregs.r_r15;
+  regs[REG_INDEX(R14)] = gregs.r_r14;
+  regs[REG_INDEX(R13)] = gregs.r_r13;
+  regs[REG_INDEX(R12)] = gregs.r_r12;
+  regs[REG_INDEX(RBP)] = gregs.r_rbp;
+  regs[REG_INDEX(RBX)] = gregs.r_rbx;
+  regs[REG_INDEX(R11)] = gregs.r_r11;
+  regs[REG_INDEX(R10)] = gregs.r_r10;
+  regs[REG_INDEX(R9)] = gregs.r_r9;
+  regs[REG_INDEX(R8)] = gregs.r_r8;
+  regs[REG_INDEX(RAX)] = gregs.r_rax;
+  regs[REG_INDEX(RCX)] = gregs.r_rcx;
+  regs[REG_INDEX(RDX)] = gregs.r_rdx;
+  regs[REG_INDEX(RSI)] = gregs.r_rsi;
+  regs[REG_INDEX(RDI)] = gregs.r_rdi;
+  regs[REG_INDEX(RIP)] = gregs.r_rip;
+  regs[REG_INDEX(CS)] = gregs.r_cs;
+  regs[REG_INDEX(RSP)] = gregs.r_rsp;
+  regs[REG_INDEX(SS)] = gregs.r_ss;
+//  regs[REG_INDEX(FSBASE)] = gregs.fs_base;
+//  regs[REG_INDEX(GSBASE)] = gregs.gs_base;
+//  regs[REG_INDEX(DS)] = gregs.ds;
+//  regs[REG_INDEX(ES)] = gregs.es;
+//  regs[REG_INDEX(FS)] = gregs.fs;
+//  regs[REG_INDEX(GS)] = gregs.gs;
+
+#endif /* amd64 */
+
+#if defined(sparc) || defined(sparcv9)
+
+#define REG_INDEX(reg) sun_jvm_hotspot_debugger_sparc_SPARCThreadContext_##reg
+
+#ifdef _LP64
+  regs[REG_INDEX(R_PSR)] = gregs.tstate;
+  regs[REG_INDEX(R_PC)]  = gregs.tpc;
+  regs[REG_INDEX(R_nPC)] = gregs.tnpc;
+  regs[REG_INDEX(R_Y)]   = gregs.y;
+#else
+  regs[REG_INDEX(R_PSR)] = gregs.psr;
+  regs[REG_INDEX(R_PC)]  = gregs.pc;
+  regs[REG_INDEX(R_nPC)] = gregs.npc;
+  regs[REG_INDEX(R_Y)]   = gregs.y;
+#endif
+  regs[REG_INDEX(R_G0)]  =            0 ;
+  regs[REG_INDEX(R_G1)]  = gregs.u_regs[0];
+  regs[REG_INDEX(R_G2)]  = gregs.u_regs[1];
+  regs[REG_INDEX(R_G3)]  = gregs.u_regs[2];
+  regs[REG_INDEX(R_G4)]  = gregs.u_regs[3];
+  regs[REG_INDEX(R_G5)]  = gregs.u_regs[4];
+  regs[REG_INDEX(R_G6)]  = gregs.u_regs[5];
+  regs[REG_INDEX(R_G7)]  = gregs.u_regs[6];
+  regs[REG_INDEX(R_O0)]  = gregs.u_regs[7];
+  regs[REG_INDEX(R_O1)]  = gregs.u_regs[8];
+  regs[REG_INDEX(R_O2)]  = gregs.u_regs[ 9];
+  regs[REG_INDEX(R_O3)]  = gregs.u_regs[10];
+  regs[REG_INDEX(R_O4)]  = gregs.u_regs[11];
+  regs[REG_INDEX(R_O5)]  = gregs.u_regs[12];
+  regs[REG_INDEX(R_O6)]  = gregs.u_regs[13];
+  regs[REG_INDEX(R_O7)]  = gregs.u_regs[14];
+#endif /* sparc */
+
+
+  (*env)->ReleaseLongArrayElements(env, array, regs, JNI_COMMIT);
+  return array;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/MacosxDebuggerLocal.m	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,406 @@
+/*
+ * Copyright (c) 2002, 2007, 2011, 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.
+ *
+ */
+
+#include <objc/objc-runtime.h>
+#import <Foundation/Foundation.h>
+#import <JavaNativeFoundation/JavaNativeFoundation.h>
+
+#include <JavaVM/jni.h>
+
+#import <mach/mach.h>
+#import <mach/mach_types.h>
+#import <sys/sysctl.h>
+#import <stdlib.h>
+
+jboolean debug = JNI_FALSE;
+
+static jfieldID symbolicatorID = 0; // set in _init0
+static jfieldID taskID = 0; // set in _init0
+
+static void putSymbolicator(JNIEnv *env, jobject this_obj, id symbolicator) {
+  (*env)->SetLongField(env, this_obj, symbolicatorID, (jlong)(intptr_t)symbolicator);
+}
+
+static id getSymbolicator(JNIEnv *env, jobject this_obj) {
+  jlong ptr = (*env)->GetLongField(env, this_obj, symbolicatorID);
+  return (id)(intptr_t)ptr;
+}
+
+static void putTask(JNIEnv *env, jobject this_obj, task_t task) {
+  (*env)->SetLongField(env, this_obj, taskID, (jlong)task);
+}
+
+static task_t getTask(JNIEnv *env, jobject this_obj) {
+  jlong ptr = (*env)->GetLongField(env, this_obj, taskID);
+  return (task_t)ptr;
+}
+
+#define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; }
+#define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;}
+#define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; }
+#define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;}
+
+static void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) {
+  (*env)->ThrowNew(env, (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"), errMsg);
+}
+
+#if defined(__i386__)
+    #define hsdb_thread_state_t     x86_thread_state32_t
+    #define hsdb_float_state_t      x86_float_state32_t
+    #define HSDB_THREAD_STATE       x86_THREAD_STATE32
+    #define HSDB_FLOAT_STATE        x86_FLOAT_STATE32
+    #define HSDB_THREAD_STATE_COUNT x86_THREAD_STATE32_COUNT
+    #define HSDB_FLOAT_STATE_COUNT  x86_FLOAT_STATE32_COUNT
+#elif defined(__x86_64__)
+    #define hsdb_thread_state_t     x86_thread_state64_t
+    #define hsdb_float_state_t      x86_float_state64_t
+    #define HSDB_THREAD_STATE       x86_THREAD_STATE64
+    #define HSDB_FLOAT_STATE        x86_FLOAT_STATE64
+    #define HSDB_THREAD_STATE_COUNT x86_THREAD_STATE64_COUNT
+    #define HSDB_FLOAT_STATE_COUNT  x86_FLOAT_STATE64_COUNT
+#else
+    #error "Unsupported architecture"
+#endif
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    init0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0(JNIEnv *env, jclass cls) {
+  symbolicatorID = (*env)->GetFieldID(env, cls, "symbolicator", "J");
+  taskID = (*env)->GetFieldID(env, cls, "task", "J");
+  CHECK_EXCEPTION;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    lookupByName0
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0(JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) {
+  jlong address = 0;
+
+JNF_COCOA_ENTER(env);
+  NSString *symbolNameString = JNFJavaToNSString(env, symbolName);
+
+  if (debug) {
+    printf("lookupInProcess called for %s\n", [symbolNameString UTF8String]);
+  }
+
+  id symbolicator = getSymbolicator(env, this_obj);
+  if (symbolicator != nil) {
+    uint64_t (*dynamicCall)(id, SEL, NSString *) = (uint64_t (*)(id, SEL, NSString *))&objc_msgSend;
+    address = (jlong) dynamicCall(symbolicator, @selector(addressForSymbol:), symbolNameString);
+  }
+
+  if (debug) {
+    printf("address of symbol %s = %llx\n", [symbolNameString UTF8String], address);
+  }
+JNF_COCOA_EXIT(env);
+
+  return address;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    readBytesFromProcess0
+ * Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
+ */
+JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0(JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) {
+  if (debug) printf("readBytesFromProcess called. addr = %llx numBytes = %lld\n", addr, numBytes);
+
+  // must allocate storage instead of using former parameter buf
+  jboolean isCopy;
+  jbyteArray array;
+  jbyte *bufPtr;
+
+  array = (*env)->NewByteArray(env, numBytes);
+  CHECK_EXCEPTION_(0);
+
+  unsigned long alignedAddress;
+  unsigned long alignedLength;
+  kern_return_t result;
+  vm_offset_t *pages;
+  int *mapped;
+  long pageCount;
+  uint byteCount;
+  int i;
+  unsigned long remaining;
+
+  alignedAddress = trunc_page(addr);
+  if (addr != alignedAddress) {
+    alignedLength += addr - alignedAddress;
+  }
+  alignedLength = round_page(numBytes);
+  pageCount = alignedLength/vm_page_size;
+
+  // Allocate storage for pages and flags.
+  pages = malloc(pageCount * sizeof(vm_offset_t));
+  mapped = calloc(pageCount, sizeof(int));
+
+  task_t gTask = getTask(env, this_obj);
+  // Try to read each of the pages.
+  for (i = 0; i < pageCount; i++) {
+    result = vm_read(gTask, alignedAddress + i*vm_page_size, vm_page_size, 
+		     &pages[i], &byteCount);
+    mapped[i] = (result == KERN_SUCCESS); 
+    // assume all failures are unmapped pages
+  }
+
+  if (debug) fprintf(stderr, "%ld pages\n", pageCount);
+	
+  remaining = numBytes;
+	
+  for (i = 0; i < pageCount; i++) {
+    unsigned long len = vm_page_size;
+    unsigned long start = 0;
+
+    if (i == 0) {
+      start = addr - alignedAddress;
+      len = vm_page_size - start;
+    }
+
+    if (i == (pageCount - 1)) {
+      len = remaining;
+    }
+
+    if (mapped[i]) {
+      if (debug) fprintf(stderr, "page %d mapped (len %ld start %ld)\n", i, len, start);
+      (*env)->SetByteArrayRegion(env, array, 0, len, ((jbyte *) pages[i] + start));
+      vm_deallocate(mach_task_self(), pages[i], vm_page_size);
+    }
+
+    remaining -= len;
+  }
+
+  free (pages);
+  free (mapped);
+  return array;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal
+ * Method:    getThreadIntegerRegisterSet0
+ * Signature: (I)[J
+ */
+JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0(JNIEnv *env, jobject this_obj, jint lwp_id) {
+  if (debug)
+    printf("getThreadRegisterSet0 called\n");
+
+  kern_return_t result;
+  thread_t tid;
+  mach_msg_type_number_t count = HSDB_THREAD_STATE_COUNT;
+  hsdb_thread_state_t state;
+  unsigned int *r;
+  int i;
+  jlongArray registerArray;
+  jlong *primitiveArray;
+
+  tid = lwp_id;
+
+  result = thread_get_state(tid, HSDB_THREAD_STATE, (thread_state_t)&state, &count);
+
+  if (result != KERN_SUCCESS) {
+    if (debug)
+      printf("getregs: thread_get_state(%d) failed (%d)\n", tid, result);
+    return NULL;
+  }
+
+  // 40 32-bit registers on ppc, 16 on x86. 
+  // Output order is the same as the order in the ppc_thread_state/i386_thread_state struct.
+#if defined(__i386__)
+	r = (unsigned int *)&state;
+	registerArray = (*env)->NewLongArray(env, 8);
+	primitiveArray = (*env)->GetLongArrayElements(env, registerArray, NULL);
+	primitiveArray[0] = r[0];  // eax
+	primitiveArray[1] = r[2];  // ecx
+	primitiveArray[2] = r[3];  // edx
+	primitiveArray[3] = r[1];  // ebx
+	primitiveArray[4] = r[7];  // esp
+	primitiveArray[5] = r[6];  // ebp
+	primitiveArray[6] = r[5];  // esi
+	primitiveArray[7] = r[4];  // edi
+	(*env)->ReleaseLongArrayElements(env, registerArray, primitiveArray, 0);
+#elif defined(__x86_64__)
+	/* From AMD64ThreadContext.java
+	   public static final int R15 = 0;
+	   public static final int R14 = 1;
+	   public static final int R13 = 2;
+	   public static final int R12 = 3;
+	   public static final int R11 = 4;
+	   public static final int R10 = 5;
+	   public static final int R9  = 6;
+	   public static final int R8  = 7;
+	   public static final int RDI = 8;
+	   public static final int RSI = 9;
+	   public static final int RBP = 10;
+	   public static final int RBX = 11;
+	   public static final int RDX = 12;
+	   public static final int RCX = 13;
+	   public static final int RAX = 14;
+	   public static final int TRAPNO = 15;
+	   public static final int ERR = 16;
+	   public static final int RIP = 17;
+	   public static final int CS = 18;
+	   public static final int RFL = 19;
+	   public static final int RSP = 20;
+	   public static final int SS = 21;
+	   public static final int FS = 22;
+	   public static final int GS = 23;
+	   public static final int ES = 24;
+	   public static final int DS = 25;
+	   public static final int FSBASE = 26;
+	   public static final int GSBASE = 27;
+	 */
+	// 64 bit
+	if (debug) printf("Getting threads for a 64-bit process\n");
+	registerArray = (*env)->NewLongArray(env, 28);
+	primitiveArray = (*env)->GetLongArrayElements(env, registerArray, NULL);
+
+	primitiveArray[0] = state.__r15;
+	primitiveArray[1] = state.__r14;
+	primitiveArray[2] = state.__r13;
+	primitiveArray[3] = state.__r12;
+	primitiveArray[4] = state.__r11;
+	primitiveArray[5] = state.__r10;
+	primitiveArray[6] = state.__r9;
+	primitiveArray[7] = state.__r8;
+	primitiveArray[8] = state.__rdi;
+	primitiveArray[9] = state.__rsi;
+	primitiveArray[10] = state.__rbp;
+	primitiveArray[11] = state.__rbx;
+	primitiveArray[12] = state.__rdx;
+	primitiveArray[13] = state.__rcx;
+	primitiveArray[14] = state.__rax;
+	primitiveArray[15] = 0;             // trapno ?
+	primitiveArray[16] = 0;             // err ?
+	primitiveArray[17] = state.__rip;
+	primitiveArray[18] = state.__cs;
+	primitiveArray[19] = state.__rflags;
+	primitiveArray[20] = state.__rsp;
+	primitiveArray[21] = 0;            // We don't have SS
+	primitiveArray[22] = state.__fs;
+	primitiveArray[23] = state.__gs;
+	primitiveArray[24] = 0;
+	primitiveArray[25] = 0;
+	primitiveArray[26] = 0;
+	primitiveArray[27] = 0;
+
+	if (debug) printf("set registers\n");
+
+	(*env)->ReleaseLongArrayElements(env, registerArray, primitiveArray, 0);
+#else
+#error Unsupported architecture
+#endif
+
+  return registerArray;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal
+ * Method:    translateTID0
+ * Signature: (I)I
+ */
+JNIEXPORT jint JNICALL
+Java_sun_jvm_hotspot_debugger_macosx_MacOSXDebuggerLocal_translateTID0(JNIEnv *env, jobject this_obj, jint tid) {
+  if (debug)
+    printf("translateTID0 called on tid = 0x%x\n", (int)tid);
+
+  kern_return_t result;
+  thread_t foreign_tid, usable_tid;
+  mach_msg_type_name_t type;
+    
+  foreign_tid = tid;
+    
+  task_t gTask = getTask(env, this_obj);
+  result = mach_port_extract_right(gTask, foreign_tid, 
+				   MACH_MSG_TYPE_COPY_SEND, 
+				   &usable_tid, &type);
+  if (result != KERN_SUCCESS)
+    return -1;
+    
+  if (debug)
+    printf("translateTID0: 0x%x -> 0x%x\n", foreign_tid, usable_tid);
+    
+  return (jint) usable_tid;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    attach0
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I(JNIEnv *env, jobject this_obj, jint jpid) {
+JNF_COCOA_ENTER(env);
+  if (getenv("JAVA_SAPROC_DEBUG") != NULL)
+    debug = JNI_TRUE;
+  else
+    debug = JNI_FALSE;
+  if (debug) printf("attach0 called for jpid=%d\n", (int)jpid);
+
+  kern_return_t result;
+  task_t gTask = 0;
+  result = task_for_pid(mach_task_self(), jpid, &gTask);
+  if (result != KERN_SUCCESS) {
+    fprintf(stderr, "attach: task_for_pid(%d) failed (%d)\n", (int)jpid, result);
+    THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process");
+  }
+  putTask(env, this_obj, gTask);
+
+  id symbolicator = nil;
+  id jrsSymbolicator = objc_lookUpClass("JRSSymbolicator");
+  if (jrsSymbolicator != nil) {
+    id (*dynamicCall)(id, SEL, pid_t) = (id (*)(id, SEL, pid_t))&objc_msgSend;
+    symbolicator = dynamicCall(jrsSymbolicator, @selector(symbolicatorForPid:), (pid_t)jpid);
+  }
+  if (symbolicator != nil) {
+    CFRetain(symbolicator); // pin symbolicator while in java heap
+  }
+
+  putSymbolicator(env, this_obj, symbolicator);
+  if (symbolicator == nil) {
+    THROW_NEW_DEBUGGER_EXCEPTION("Can't attach symbolicator to the process");
+  }
+
+JNF_COCOA_EXIT(env);
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    detach0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0(JNIEnv *env, jobject this_obj) {
+JNF_COCOA_ENTER(env);
+  if (debug) printf("detach0 called\n");
+
+  task_t gTask = getTask(env, this_obj);
+  mach_port_deallocate(mach_task_self(), gTask);
+  id symbolicator = getSymbolicator(env, this_obj);
+  if (symbolicator != nil) {
+    CFRelease(symbolicator);
+  }
+JNF_COCOA_EXIT(env);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/Makefile	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,77 @@
+#
+# Copyright (c) 2002, 2009, 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.
+#  
+#
+
+ARCH := $(shell if ([ `uname -m` = "ia64" ])  ; then echo ia64 ; elif ([ `uname -m` = "amd64" ]) ; then echo amd64; elif ([ `uname -m` = "sparc64" ]) ; then echo sparc; else echo i386 ; fi )
+GCC      = gcc
+
+JAVAH    = ${JAVA_HOME}/bin/javah
+
+SOURCES  = salibelf.c   \
+        symtab.c        \
+	libproc_impl.c  \
+	ps_proc.c       \
+	ps_core.c       \
+	BsdDebuggerLocal.c
+
+INCLUDES = -I${JAVA_HOME}/include -I${JAVA_HOME}/include/$(shell uname -s | tr "[:upper:]" "[:lower:]")
+
+OBJS     = $(SOURCES:.c=.o)
+
+LIBS     = -lutil -lthread_db
+
+CFLAGS   = -c -fPIC -g -Wall -D_ALLBSD_SOURCE -D_GNU_SOURCE -D$(ARCH) $(INCLUDES)
+
+LIBSA = $(ARCH)/libsaproc.so
+
+all: $(LIBSA)
+
+BsdDebuggerLocal.o: BsdDebuggerLocal.c
+	$(JAVAH) -jni -classpath ../../../../../build/bsd-i586/hotspot/outputdir/bsd_i486_compiler2/generated/saclasses  \
+		sun.jvm.hotspot.debugger.x86.X86ThreadContext \
+		sun.jvm.hotspot.debugger.amd64.AMD64ThreadContext
+	$(GCC) $(CFLAGS) $<
+
+.c.obj:
+	$(GCC) $(CFLAGS)
+
+ifndef LDNOMAP
+  LFLAGS_LIBSA = -Xlinker --version-script=mapfile
+endif
+
+$(LIBSA): $(OBJS) mapfile
+	if [ ! -d $(ARCH) ] ; then mkdir $(ARCH) ; fi
+	$(GCC) -shared $(LFLAGS_LIBSA) -o $(LIBSA) $(OBJS) $(LIBS)
+
+test.o: $(LIBSA) test.c
+	$(GCC) -c -o test.o -g -D_GNU_SOURCE -D$(ARCH) $(INCLUDES) test.c
+
+test: test.o
+	$(GCC) -o test test.o -L$(ARCH) -lsaproc $(LIBS)
+
+clean:
+	rm -f $(LIBSA)
+	rm -f $(OBJS)
+	rm -f test.o
+	-rmdir $(ARCH)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/StubDebuggerLocal.c	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2009, 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.
+ *
+ */
+
+#include <stdlib.h>
+#include <jni.h>
+
+#define CHECK_EXCEPTION_(value) if ((*env)->ExceptionOccurred(env)) { return value; }
+#define CHECK_EXCEPTION if ((*env)->ExceptionOccurred(env)) { return;}
+#define THROW_NEW_DEBUGGER_EXCEPTION_(str, value) { throw_new_debugger_exception(env, str); return value; }
+#define THROW_NEW_DEBUGGER_EXCEPTION(str) { throw_new_debugger_exception(env, str); return;}
+
+static void throw_new_debugger_exception(JNIEnv* env, const char* errMsg) {
+  (*env)->ThrowNew(env, (*env)->FindClass(env, "sun/jvm/hotspot/debugger/DebuggerException"), errMsg);
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    init0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0
+  (JNIEnv *env, jclass cls) {
+}
+
+JNIEXPORT jint JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getAddressSize
+  (JNIEnv *env, jclass cls)
+{
+#ifdef _LP64
+ return 8;
+#else
+ return 4;
+#endif
+
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    attach0
+ * Signature: (I)V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I
+  (JNIEnv *env, jobject this_obj, jint jpid) {
+
+  THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the process");
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    attach0
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
+  (JNIEnv *env, jobject this_obj, jstring execName, jstring coreName) {
+  THROW_NEW_DEBUGGER_EXCEPTION("Can't attach to the core file");
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    detach0
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0
+  (JNIEnv *env, jobject this_obj) {
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    lookupByName0
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0
+  (JNIEnv *env, jobject this_obj, jstring objectName, jstring symbolName) {
+  return 0;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    lookupByAddress0
+ * Signature: (J)Lsun/jvm/hotspot/debugger/cdbg/ClosestSymbol;
+ */
+JNIEXPORT jobject JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByAddress0
+  (JNIEnv *env, jobject this_obj, jlong addr) {
+  return 0;
+}
+
+/*
+ * Class:     sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal
+ * Method:    readBytesFromProcess0
+ * Signature: (JJ)Lsun/jvm/hotspot/debugger/ReadResult;
+ */
+JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0
+  (JNIEnv *env, jobject this_obj, jlong addr, jlong numBytes) {
+  return 0;
+}
+
+JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0
+  (JNIEnv *env, jobject this_obj, jint lwp_id) {
+  return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/elfmacros.h	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2003, 2006, 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.
+ *
+ */
+
+#ifndef _ELFMACROS_H_
+#define _ELFMACROS_H_
+
+#define ELF_NHDR        Elf_Note
+
+#if defined(_LP64)
+#define ELF_EHDR        Elf64_Ehdr
+#define ELF_SHDR        Elf64_Shdr
+#define ELF_PHDR        Elf64_Phdr
+#define ELF_SYM         Elf64_Sym
+#define ELF_DYN         Elf64_Dyn
+#define ELF_ADDR        Elf64_Addr
+
+#ifndef ELF_ST_TYPE
+#define ELF_ST_TYPE     ELF64_ST_TYPE
+#endif
+
+#else
+
+#define ELF_EHDR        Elf32_Ehdr
+#define ELF_SHDR        Elf32_Shdr
+#define ELF_PHDR        Elf32_Phdr
+#define ELF_SYM         Elf32_Sym
+#define ELF_DYN         Elf32_Dyn
+#define ELF_ADDR        Elf32_Addr
+
+#ifndef ELF_ST_TYPE
+#define ELF_ST_TYPE     ELF32_ST_TYPE
+#endif
+
+#endif
+
+
+#endif /* _ELFMACROS_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/libproc.h	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2003, 2007, 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.
+ *
+ */
+
+#ifndef _LIBPROC_H_
+#define _LIBPROC_H_
+
+#include <unistd.h>
+#include <stdint.h>
+#include <machine/reg.h>
+#include <proc_service.h>
+
+#if defined(sparc) || defined(sparcv9)
+/*
+  If _LP64 is defined ptrace.h should be taken from /usr/include/asm-sparc64
+  otherwise it should be from /usr/include/asm-sparc
+  These two files define pt_regs structure differently
+*/
+#ifdef _LP64
+#include "asm-sparc64/ptrace.h"
+#else
+#include "asm-sparc/ptrace.h"
+#endif
+
+#endif //sparc or sparcv9
+
+/************************************************************************************
+
+0. This is very minimal subset of Solaris libproc just enough for current application.
+Please note that the bulk of the functionality is from proc_service interface. This
+adds Pgrab__ and some missing stuff. We hide the difference b/w live process and core
+file by this interface.
+
+1. pthread_id is unique. We store this in OSThread::_pthread_id in JVM code.
+
+2. All threads see the same pid when they call getpid().
+We used to save the result of ::getpid() call in OSThread::_thread_id.
+Because gettid returns actual pid of thread (lwp id), this is
+unique again. We therefore use OSThread::_thread_id as unique identifier.
+
+3. There is a unique LWP id under both thread libraries. libthread_db  maps pthread_id
+to its underlying lwp_id under both the thread libraries. thread_info.lwp_id stores
+lwp_id of the thread. The lwp id is nothing but the actual pid of clone'd processes. But
+unfortunately libthread_db does not work very well for core dumps. So, we get pthread_id
+only for processes. For core dumps, we don't use libthread_db at all (like gdb).
+
+4. ptrace operates on this LWP id under both the thread libraries. When we say 'pid' for
+ptrace call, we refer to lwp_id of the thread.
+
+5. for core file, we parse ELF files and read data from them. For processes we  use
+combination of ptrace and /proc calls.
+
+*************************************************************************************/
+
+// This C bool type must be int for compatibility with BSD calls and
+// it would be a mistake to equivalence it to C++ bool on many platforms
+
+typedef int bool;
+#define true  1
+#define false 0
+
+struct ps_prochandle;
+
+// attach to a process
+struct ps_prochandle* Pgrab(pid_t pid);
+
+// attach to a core dump
+struct ps_prochandle* Pgrab_core(const char* execfile, const char* corefile);
+
+// release a process or core
+void Prelease(struct ps_prochandle* ph);
+
+// functions not directly available in Solaris libproc
+
+// initialize libproc (call this only once per app)
+// pass true to make library verbose
+bool init_libproc(bool verbose);
+
+// get number of threads
+int get_num_threads(struct ps_prochandle* ph);
+
+// get lwp_id of n'th thread
+lwpid_t get_lwp_id(struct ps_prochandle* ph, int index);
+
+// get regs for a given lwp
+bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lid, struct reg* regs);
+
+// get number of shared objects
+int get_num_libs(struct ps_prochandle* ph);
+
+// get name of n'th lib
+const char* get_lib_name(struct ps_prochandle* ph, int index);
+
+// get base of lib
+uintptr_t get_lib_base(struct ps_prochandle* ph, int index);
+
+// returns true if given library is found in lib list
+bool find_lib(struct ps_prochandle* ph, const char *lib_name);
+
+// symbol lookup
+uintptr_t lookup_symbol(struct ps_prochandle* ph,  const char* object_name,
+                       const char* sym_name);
+
+// address->nearest symbol lookup. return NULL for no symbol
+const char* symbol_for_pc(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* poffset);
+
+#endif //__LIBPROC_H_
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/libproc_impl.c	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,452 @@
+/*
+ * Copyright (c) 2003, 2010, 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.
+ *
+ */
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <thread_db.h>
+#include "libproc_impl.h"
+
+static const char* alt_root = NULL;
+static int alt_root_len = -1;
+
+#define SA_ALTROOT "SA_ALTROOT"
+
+static void init_alt_root() {
+   if (alt_root_len == -1) {
+      alt_root = getenv(SA_ALTROOT);
+      if (alt_root) {
+         alt_root_len = strlen(alt_root);
+      } else {
+         alt_root_len = 0;
+      }
+   }
+}
+
+int pathmap_open(const char* name) {
+   int fd;
+   char alt_path[PATH_MAX + 1];
+
+   init_alt_root();
+   fd = open(name, O_RDONLY);
+   if (fd >= 0) {
+      return fd;
+   }
+
+   if (alt_root_len > 0) {
+      strcpy(alt_path, alt_root);
+      strcat(alt_path, name);
+      fd = open(alt_path, O_RDONLY);
+      if (fd >= 0) {
+         print_debug("path %s substituted for %s\n", alt_path, name);
+         return fd;
+      }
+
+      if (strrchr(name, '/')) {
+         strcpy(alt_path, alt_root);
+         strcat(alt_path, strrchr(name, '/'));
+         fd = open(alt_path, O_RDONLY);
+         if (fd >= 0) {
+            print_debug("path %s substituted for %s\n", alt_path, name);
+            return fd;
+         }
+      }
+   }
+
+   return -1;
+}
+
+static bool _libsaproc_debug;
+
+void print_debug(const char* format,...) {
+   if (_libsaproc_debug) {
+     va_list alist;
+
+     va_start(alist, format);
+     fputs("libsaproc DEBUG: ", stderr);
+     vfprintf(stderr, format, alist);
+     va_end(alist);
+   }
+}
+
+bool is_debug() {
+   return _libsaproc_debug;
+}
+
+// initialize libproc
+bool init_libproc(bool debug) {
+   // init debug mode
+   _libsaproc_debug = debug;
+
+   // initialize the thread_db library
+   if (td_init() != TD_OK) {
+     print_debug("libthread_db's td_init failed\n");
+     return false;
+   }
+
+   return true;
+}
+
+static void destroy_lib_info(struct ps_prochandle* ph) {
+   lib_info* lib = ph->libs;
+   while (lib) {
+     lib_info *next = lib->next;
+     if (lib->symtab) {
+        destroy_symtab(lib->symtab);
+     }
+     free(lib);
+     lib = next;
+   }
+}
+
+static void destroy_thread_info(struct ps_prochandle* ph) {
+   thread_info* thr = ph->threads;
+   while (thr) {
+     thread_info *next = thr->next;
+     free(thr);
+     thr = next;
+   }
+}
+
+// ps_prochandle cleanup
+
+// ps_prochandle cleanup
+void Prelease(struct ps_prochandle* ph) {
+   // do the "derived class" clean-up first
+   ph->ops->release(ph);
+   destroy_lib_info(ph);
+   destroy_thread_info(ph);
+   free(ph);
+}
+
+lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base) {
+   return add_lib_info_fd(ph, libname, -1, base);
+}
+
+lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd, uintptr_t base) {
+   lib_info* newlib;
+
+   if ( (newlib = (lib_info*) calloc(1, sizeof(struct lib_info))) == NULL) {
+      print_debug("can't allocate memory for lib_info\n");
+      return NULL;
+   }
+
+   strncpy(newlib->name, libname, sizeof(newlib->name));
+   newlib->base = base;
+
+   if (fd == -1) {
+      if ( (newlib->fd = pathmap_open(newlib->name)) < 0) {
+         print_debug("can't open shared object %s\n", newlib->name);
+         free(newlib);
+         return NULL;
+      }
+   } else {
+      newlib->fd = fd;
+   }
+
+   // check whether we have got an ELF file. /proc/<pid>/map
+   // gives out all file mappings and not just shared objects
+   if (is_elf_file(newlib->fd) == false) {
+      close(newlib->fd);
+      free(newlib);
+      return NULL;
+   }
+
+   newlib->symtab = build_symtab(newlib->fd);
+   if (newlib->symtab == NULL) {
+      print_debug("symbol table build failed for %s\n", newlib->name);
+   }
+   else {
+      print_debug("built symbol table for %s\n", newlib->name);
+   }
+
+   // even if symbol table building fails, we add the lib_info.
+   // This is because we may need to read from the ELF file for core file
+   // address read functionality. lookup_symbol checks for NULL symtab.
+   if (ph->libs) {
+      ph->lib_tail->next = newlib;
+      ph->lib_tail = newlib;
+   }  else {
+      ph->libs = ph->lib_tail = newlib;
+   }
+   ph->num_libs++;
+
+   return newlib;
+}
+
+// lookup for a specific symbol
+uintptr_t lookup_symbol(struct ps_prochandle* ph,  const char* object_name,
+                       const char* sym_name) {
+   // ignore object_name. search in all libraries
+   // FIXME: what should we do with object_name?? The library names are obtained
+   // by parsing /proc/<pid>/maps, which may not be the same as object_name.
+   // What we need is a utility to map object_name to real file name, something
+   // dlopen() does by looking at LD_LIBRARY_PATH and /etc/ld.so.cache. For
+   // now, we just ignore object_name and do a global search for the symbol.
+
+   lib_info* lib = ph->libs;
+   while (lib) {
+      if (lib->symtab) {
+         uintptr_t res = search_symbol(lib->symtab, lib->base, sym_name, NULL);
+         if (res) return res;
+      }
+      lib = lib->next;
+   }
+
+   print_debug("lookup failed for symbol '%s' in obj '%s'\n",
+                          sym_name, object_name);
+   return (uintptr_t) NULL;
+}
+
+
+const char* symbol_for_pc(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* poffset) {
+   const char* res = NULL;
+   lib_info* lib = ph->libs;
+   while (lib) {
+      if (lib->symtab && addr >= lib->base) {
+         res = nearest_symbol(lib->symtab, addr - lib->base, poffset);
+         if (res) return res;
+      }
+      lib = lib->next;
+   }
+   return NULL;
+}
+
+// add a thread to ps_prochandle
+thread_info* add_thread_info(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id) {
+   thread_info* newthr;
+   if ( (newthr = (thread_info*) calloc(1, sizeof(thread_info))) == NULL) {
+      print_debug("can't allocate memory for thread_info\n");
+      return NULL;
+   }
+
+   // initialize thread info
+   newthr->pthread_id = pthread_id;
+   newthr->lwp_id = lwp_id;
+
+   // add new thread to the list
+   newthr->next = ph->threads;
+   ph->threads = newthr;
+   ph->num_threads++;
+   return newthr;
+}
+
+
+// struct used for client data from thread_db callback
+struct thread_db_client_data {
+   struct ps_prochandle* ph;
+   thread_info_callback callback;
+};
+
+// callback function for libthread_db
+static int thread_db_callback(const td_thrhandle_t *th_p, void *data) {
+  struct thread_db_client_data* ptr = (struct thread_db_client_data*) data;
+  td_thrinfo_t ti;
+  td_err_e err;
+
+  memset(&ti, 0, sizeof(ti));
+  err = td_thr_get_info(th_p, &ti);
+  if (err != TD_OK) {
+    print_debug("libthread_db : td_thr_get_info failed, can't get thread info\n");
+    return err;
+  }
+
+  print_debug("thread_db : pthread %d (lwp %d)\n", ti.ti_tid, ti.ti_lid);
+
+  if (ptr->callback(ptr->ph, (pthread_t)ti.ti_tid, ti.ti_lid) != true)
+    return TD_ERR;
+
+  return TD_OK;
+}
+
+// read thread_info using libthread_db
+bool read_thread_info(struct ps_prochandle* ph, thread_info_callback cb) {
+  struct thread_db_client_data mydata;
+  td_thragent_t* thread_agent = NULL;
+  if (td_ta_new(ph, &thread_agent) != TD_OK) {
+     print_debug("can't create libthread_db agent\n");
+     return false;
+  }
+
+  mydata.ph = ph;
+  mydata.callback = cb;
+
+  // we use libthread_db iterator to iterate thru list of threads.
+  if (td_ta_thr_iter(thread_agent, thread_db_callback, &mydata,
+                 TD_THR_ANY_STATE, TD_THR_LOWEST_PRIORITY,
+                 TD_SIGNO_MASK, TD_THR_ANY_USER_FLAGS) != TD_OK) {
+     td_ta_delete(thread_agent);
+     return false;
+  }
+
+  // delete thread agent
+  td_ta_delete(thread_agent);
+  return true;
+}
+
+
+// get number of threads
+int get_num_threads(struct ps_prochandle* ph) {
+   return ph->num_threads;
+}
+
+// get lwp_id of n'th thread
+lwpid_t get_lwp_id(struct ps_prochandle* ph, int index) {
+   int count = 0;
+   thread_info* thr = ph->threads;
+   while (thr) {
+      if (count == index) {
+         return thr->lwp_id;
+      }
+      count++;
+      thr = thr->next;
+   }
+   return -1;
+}
+
+// get regs for a given lwp
+bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lwp_id, struct reg* regs) {
+  return ph->ops->get_lwp_regs(ph, lwp_id, regs);
+}
+
+// get number of shared objects
+int get_num_libs(struct ps_prochandle* ph) {
+   return ph->num_libs;
+}
+
+// get name of n'th solib
+const char* get_lib_name(struct ps_prochandle* ph, int index) {
+   int count = 0;
+   lib_info* lib = ph->libs;
+   while (lib) {
+      if (count == index) {
+         return lib->name;
+      }
+      count++;
+      lib = lib->next;
+   }
+   return NULL;
+}
+
+// get base address of a lib
+uintptr_t get_lib_base(struct ps_prochandle* ph, int index) {
+   int count = 0;
+   lib_info* lib = ph->libs;
+   while (lib) {
+      if (count == index) {
+         return lib->base;
+      }
+      count++;
+      lib = lib->next;
+   }
+   return (uintptr_t)NULL;
+}
+
+bool find_lib(struct ps_prochandle* ph, const char *lib_name) {
+  lib_info *p = ph->libs;
+  while (p) {
+    if (strcmp(p->name, lib_name) == 0) {
+      return true;
+    }
+    p = p->next;
+  }
+  return false;
+}
+
+//--------------------------------------------------------------------------
+// proc service functions
+
+// ps_pglobal_lookup() looks up the symbol sym_name in the symbol table
+// of the load object object_name in the target process identified by ph.
+// It returns the symbol's value as an address in the target process in
+// *sym_addr.
+
+ps_err_e ps_pglobal_lookup(struct ps_prochandle *ph, const char *object_name,
+                    const char *sym_name, psaddr_t *sym_addr) {
+  *sym_addr = (psaddr_t) lookup_symbol(ph, object_name, sym_name);
+  return (*sym_addr ? PS_OK : PS_NOSYM);
+}
+
+// read "size" bytes info "buf" from address "addr"
+ps_err_e ps_pread(struct ps_prochandle *ph, psaddr_t  addr,
+                  void *buf, size_t size) {
+  return ph->ops->p_pread(ph, (uintptr_t) addr, buf, size)? PS_OK: PS_ERR;
+}
+
+// write "size" bytes of data to debuggee at address "addr"
+ps_err_e ps_pwrite(struct ps_prochandle *ph, psaddr_t addr,
+                   const void *buf, size_t size) {
+  return ph->ops->p_pwrite(ph, (uintptr_t)addr, buf, size)? PS_OK: PS_ERR;
+}
+
+// fill in ptrace_lwpinfo for lid
+ps_err_e ps_linfo(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo) {
+  return ph->ops->get_lwp_info(ph, lwp_id, linfo)? PS_OK: PS_ERR;
+}
+
+// needed for when libthread_db is compiled with TD_DEBUG defined
+void
+ps_plog (const char *format, ...)
+{
+  va_list alist;
+
+  va_start(alist, format);
+  vfprintf(stderr, format, alist);
+  va_end(alist);
+}
+
+// ------------------------------------------------------------------------
+// Functions below this point are not yet implemented. They are here only
+// to make the linker happy.
+
+ps_err_e ps_lsetfpregs(struct ps_prochandle *ph, lwpid_t lid, const prfpregset_t *fpregs) {
+  print_debug("ps_lsetfpregs not implemented\n");
+  return PS_OK;
+}
+
+ps_err_e ps_lsetregs(struct ps_prochandle *ph, lwpid_t lid, const prgregset_t gregset) {
+  print_debug("ps_lsetregs not implemented\n");
+  return PS_OK;
+}
+
+ps_err_e  ps_lgetfpregs(struct  ps_prochandle  *ph,  lwpid_t lid, prfpregset_t *fpregs) {
+  print_debug("ps_lgetfpregs not implemented\n");
+  return PS_OK;
+}
+
+ps_err_e ps_lgetregs(struct ps_prochandle *ph, lwpid_t lid, prgregset_t gregset) {
+  print_debug("ps_lgetfpregs not implemented\n");
+  return PS_OK;
+}
+
+ps_err_e ps_lstop(struct ps_prochandle *ph, lwpid_t lid) {
+  print_debug("ps_lstop not implemented\n");
+  return PS_OK;
+}
+
+ps_err_e ps_pcontinue(struct ps_prochandle *ph) {
+  print_debug("ps_pcontinue not implemented\n");
+  return PS_OK;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/libproc_impl.h	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2003, 2005, 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.
+ *
+ */
+
+#ifndef _LIBPROC_IMPL_H_
+#define _LIBPROC_IMPL_H_
+
+#include <unistd.h>
+#include <limits.h>
+#include "libproc.h"
+#include "symtab.h"
+
+// data structures in this file mimic those of Solaris 8.0 - libproc's Pcontrol.h
+
+#define BUF_SIZE     (PATH_MAX + NAME_MAX + 1)
+
+// list of shared objects
+typedef struct lib_info {
+  char             name[BUF_SIZE];
+  uintptr_t        base;
+  struct symtab*   symtab;
+  int              fd;        // file descriptor for lib
+  struct lib_info* next;
+} lib_info;
+
+// list of threads
+typedef struct thread_info {
+   lwpid_t                  lwp_id;
+   pthread_t                pthread_id; // not used cores, always -1
+   struct reg               regs;       // not for process, core uses for caching regset
+   struct thread_info*      next;
+} thread_info;
+
+// list of virtual memory maps
+typedef struct map_info {
+   int              fd;       // file descriptor
+   off_t            offset;   // file offset of this mapping
+   uintptr_t        vaddr;    // starting virtual address
+   size_t           memsz;    // size of the mapping
+   struct map_info* next;
+} map_info;
+
+// vtable for ps_prochandle
+typedef struct ps_prochandle_ops {
+   // "derived class" clean-up
+   void (*release)(struct ps_prochandle* ph);
+   // read from debuggee
+   bool (*p_pread)(struct ps_prochandle *ph,
+            uintptr_t addr, char *buf, size_t size);
+   // write into debuggee
+   bool (*p_pwrite)(struct ps_prochandle *ph,
+            uintptr_t addr, const char *buf , size_t size);
+   // get integer regset of a thread
+   bool (*get_lwp_regs)(struct ps_prochandle* ph, lwpid_t lwp_id, struct reg* regs);
+   // get info on thread
+   bool (*get_lwp_info)(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo);
+} ps_prochandle_ops;
+
+// the ps_prochandle
+
+struct core_data {
+   int                core_fd;   // file descriptor of core file
+   int                exec_fd;   // file descriptor of exec file
+   int                interp_fd; // file descriptor of interpreter (ld-elf.so.1)
+   // part of the class sharing workaround
+   int                classes_jsa_fd; // file descriptor of class share archive
+   uintptr_t          dynamic_addr;  // address of dynamic section of a.out
+   uintptr_t          ld_base_addr;  // base address of ld.so
+   size_t             num_maps;  // number of maps.
+   map_info*          maps;      // maps in a linked list
+   // part of the class sharing workaround
+   map_info*          class_share_maps;// class share maps in a linked list
+   map_info**         map_array; // sorted (by vaddr) array of map_info pointers
+};
+
+struct ps_prochandle {
+   ps_prochandle_ops* ops;       // vtable ptr
+   pid_t              pid;
+   int                num_libs;
+   lib_info*          libs;      // head of lib list
+   lib_info*          lib_tail;  // tail of lib list - to append at the end
+   int                num_threads;
+   thread_info*       threads;   // head of thread list
+   struct core_data*  core;      // data only used for core dumps, NULL for process
+};
+
+int pathmap_open(const char* name);
+
+void print_debug(const char* format,...);
+bool is_debug();
+
+typedef bool (*thread_info_callback)(struct ps_prochandle* ph, pthread_t pid, lwpid_t lwpid);
+
+// reads thread info using libthread_db and calls above callback for each thread
+bool read_thread_info(struct ps_prochandle* ph, thread_info_callback cb);
+
+// adds a new shared object to lib list, returns NULL on failure
+lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base);
+
+// adds a new shared object to lib list, supply open lib file descriptor as well
+lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd,
+                          uintptr_t base);
+
+// adds a new thread to threads list, returns NULL on failure
+thread_info* add_thread_info(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id);
+
+// a test for ELF signature without using libelf
+bool is_elf_file(int fd);
+
+#endif //_LIBPROC_IMPL_H_
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/mapfile	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,66 @@
+#
+
+#
+# Copyright (c) 2003, 2006, 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.
+#  
+#
+
+# Define public interface.
+
+SUNWprivate_1.1 {
+        global:
+
+		# native methods of BsdDebuggerLocal class
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_init0;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getAddressSize;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__I;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_detach0;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByName0;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_lookupByAddress0;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_readBytesFromProcess0;
+		Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0;
+	
+		# proc_service.h functions - to be used by libthread_db
+		ps_getpid;
+		ps_pglobal_lookup;
+		ps_pread;
+		ps_pwrite;
+		ps_lsetfpregs;
+		ps_lsetregs;
+		ps_lgetfpregs;
+		ps_lgetregs;
+		ps_lcontinue;
+		ps_lgetxmmregs;
+		ps_lsetxmmregs;
+		ps_lstop;
+		ps_linfo;
+
+                # used by attach test program
+                init_libproc;
+                Pgrab;
+                Pgrab_core;
+                Prelease;
+	
+	local:
+		*;
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/ps_core.c	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,1023 @@
+/*
+ * Copyright (c) 2003, 2010, 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.
+ *
+ */
+
+#include <jni.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <elf.h>
+#include <link.h>
+#include "libproc_impl.h"
+#include "salibelf.h"
+
+// This file has the libproc implementation to read core files.
+// For live processes, refer to ps_proc.c. Portions of this is adapted
+// /modelled after Solaris libproc.so (in particular Pcore.c)
+
+//----------------------------------------------------------------------
+// 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;
+   }
+}
+
+// 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;
+  }
+
+  if (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;
+  }
+}
+
+// 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);
+   }
+}
+
+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;
+   }
+
+   // 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;
+   }
+
+   // add this to map list
+   map->next  = ph->core->maps;
+   ph->core->maps   = map;
+   ph->core->num_maps++;
+
+   return map;
+}
+
+// Part of the class sharing workaround
+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 NULL;
+   }
+
+   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;
+   }
+
+   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);
+
+
+   // 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);
+}
+
+//---------------------------------------------------------------
+// Part of the class sharing workaround:
+//
+// With class sharing, pages are mapped from classes[_g].jsa file.
+// The read-only class sharing pages are mapped as MAP_SHARED,
+// PROT_READ pages. These pages are not dumped into core dump.
+// With this workaround, these pages are read from classes[_g].jsa.
+
+// FIXME: !HACK ALERT!
+// The format of sharing achive file header is needed to read shared heap
+// file mappings. For now, I am hard coding portion of FileMapHeader here.
+// Refer to filemap.hpp.
+
+// FileMapHeader describes the shared space data in the file to be
+// mapped.  This structure gets written to a file.  It is not a class,
+// so that the compilers don't add any compiler-private data to it.
+
+// Refer to CompactingPermGenGen::n_regions in compactingPermGenGen.hpp
+#define NUM_SHARED_MAPS 4
+
+// Refer to FileMapInfo::_current_version in filemap.hpp
+#define CURRENT_ARCHIVE_VERSION 1
+
+struct FileMapHeader {
+  int   _magic;              // identify file type.
+  int   _version;            // (from enum, above.)
+  size_t _alignment;         // how shared archive should be aligned
+
+  struct space_info {
+    int    _file_offset;     // sizeof(this) rounded to vm page size
+    char*  _base;            // copy-on-write base address
+    size_t _capacity;        // for validity checking
+    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.
+    char   _read_only;       // read only space?
+    char   _allow_exec;      // executable code in space?
+
+  } _space[NUM_SHARED_MAPS]; // was _space[CompactingPermGenGen::n_regions];
+
+  // Ignore the rest of the FileMapHeader. We don't need those fields here.
+};
+
+static bool read_jboolean(struct ps_prochandle* ph, uintptr_t addr, jboolean* pvalue) {
+   jboolean i;
+   if (ps_pread(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_pread(ph, (psaddr_t) addr, &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 = ' ';
+
+   while (c != '\0') {
+     if (ps_pread(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;
+}
+
+#define USE_SHARED_SPACES_SYM "UseSharedSpaces"
+// mangled name of Arguments::SharedArchivePath
+#define SHARED_ARCHIVE_PATH_SYM "_ZN9Arguments17SharedArchivePathE"
+
+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[_g].so.
+      const char *jvm_name = 0;
+      if ((jvm_name = strstr(lib->name, "/libjvm.so")) != 0 ||
+          (jvm_name = strstr(lib->name, "/libjvm_g.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;
+
+         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;
+         }
+
+         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;
+         }
+
+         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;
+         }
+
+         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;
+         }
+
+         // 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;
+         }
+
+         ph->core->classes_jsa_fd = fd;
+         // add read-only maps from classes[_g].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;
+      }
+      lib = lib->next;
+   }
+   return true;
+}
+
+
+//---------------------------------------------------------------------------
+// functions to handle map_info
+
+// Order mappings based on virtual address.  We use this function as the
+// 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);
+
+   if (lhs->vaddr == rhs->vaddr)
+      return (0);
+
+   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;
+
+   // 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;
+   }
+
+   // 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);
+
+   // 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 = %d\n", ph->core->map_array[j]->vaddr,
+                                         ph->core->map_array[j]->memsz);
+      }
+   }
+
+   return true;
+}
+
+#ifndef MIN
+#define MIN(x, y) (((x) < (y))? (x): (y))
+#endif
+
+static bool core_read_data(struct ps_prochandle* ph, uintptr_t addr, char *buf, size_t size) {
+   ssize_t resid = size;
+   int page_size=sysconf(_SC_PAGE_SIZE);
+   while (resid != 0) {
+      map_info *mp = core_lookup(ph, addr);
+      uintptr_t mapoff;
+      ssize_t len, rem;
+      off_t off;
+      int fd;
+
+      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)
+         break;
+
+      resid -= len;
+      addr += len;
+      buf = (char *)buf + len;
+
+      // mappings always start at page boundary. But, may end in fractional
+      // page. fill zeros for possible fractional page at the end of a mapping.
+      rem = mp->memsz % page_size;
+      if (rem > 0) {
+         rem = page_size - rem;
+         len = MIN(resid, rem);
+         resid -= len;
+         addr += len;
+         // we are not assuming 'buf' to be zero initialized.
+         memset(buf, 0, len);
+         buf += len;
+      }
+   }
+
+   if (resid) {
+      print_debug("core read failed for %d byte(s) @ 0x%lx (%d more bytes)\n",
+              size, addr, resid);
+      return false;
+   } else {
+      return true;
+   }
+}
+
+// null implementation for write
+static bool core_write_data(struct ps_prochandle* ph,
+                             uintptr_t addr, const char *buf , size_t size) {
+   return false;
+}
+
+static bool core_get_lwp_regs(struct ps_prochandle* ph, lwpid_t lwp_id,
+                          struct reg* regs) {
+   // for core we have cached the lwp regs from NOTE section
+   thread_info* thr = ph->threads;
+   while (thr) {
+     if (thr->lwp_id == lwp_id) {
+       memcpy(regs, &thr->regs, sizeof(struct reg));
+       return true;
+     }
+     thr = thr->next;
+   }
+   return false;
+}
+
+static bool core_get_lwp_info(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo) {
+   print_debug("core_get_lwp_info not implemented\n");
+   return false;
+}
+
+static ps_prochandle_ops core_ops = {
+   .release=  core_release,
+   .p_pread=  core_read_data,
+   .p_pwrite= core_write_data,
+   .get_lwp_regs= core_get_lwp_regs,
+   .get_lwp_info= core_get_lwp_info
+};
+
+// read regs and create thread from NT_PRSTATUS entries from core file
+static bool core_handle_prstatus(struct ps_prochandle* ph, const char* buf, size_t nbytes) {
+   // we have to read prstatus_t from buf
+   // assert(nbytes == sizeof(prstaus_t), "size mismatch on prstatus_t");
+   prstatus_t* prstat = (prstatus_t*) buf;
+   thread_info* newthr;
+   print_debug("got integer regset for lwp %d\n", prstat->pr_pid);
+   // we set pthread_t to -1 for core dump
+   if((newthr = add_thread_info(ph, (pthread_t) -1,  prstat->pr_pid)) == NULL)
+      return false;
+
+   // copy regs
+   memcpy(&newthr->regs, &prstat->pr_reg, sizeof(struct reg));
+
+   if (is_debug()) {
+      print_debug("integer regset\n");
+#ifdef i386
+      // print the regset
+      print_debug("\teax = 0x%x\n", newthr->regs.r_eax);
+      print_debug("\tebx = 0x%x\n", newthr->regs.r_ebx);
+      print_debug("\tecx = 0x%x\n", newthr->regs.r_ecx);
+      print_debug("\tedx = 0x%x\n", newthr->regs.r_edx);
+      print_debug("\tesp = 0x%x\n", newthr->regs.r_esp);
+      print_debug("\tebp = 0x%x\n", newthr->regs.r_ebp);
+      print_debug("\tesi = 0x%x\n", newthr->regs.r_esi);
+      print_debug("\tedi = 0x%x\n", newthr->regs.r_edi);
+      print_debug("\teip = 0x%x\n", newthr->regs.r_eip);
+#endif
+
+#if defined(amd64) || defined(x86_64)
+      // print the regset
+      print_debug("\tr15 = 0x%lx\n", newthr->regs.r_r15);
+      print_debug("\tr14 = 0x%lx\n", newthr->regs.r_r14);
+      print_debug("\tr13 = 0x%lx\n", newthr->regs.r_r13);
+      print_debug("\tr12 = 0x%lx\n", newthr->regs.r_r12);
+      print_debug("\trbp = 0x%lx\n", newthr->regs.r_rbp);
+      print_debug("\trbx = 0x%lx\n", newthr->regs.r_rbx);
+      print_debug("\tr11 = 0x%lx\n", newthr->regs.r_r11);
+      print_debug("\tr10 = 0x%lx\n", newthr->regs.r_r10);
+      print_debug("\tr9 = 0x%lx\n", newthr->regs.r_r9);
+      print_debug("\tr8 = 0x%lx\n", newthr->regs.r_r8);
+      print_debug("\trax = 0x%lx\n", newthr->regs.r_rax);
+      print_debug("\trcx = 0x%lx\n", newthr->regs.r_rcx);
+      print_debug("\trdx = 0x%lx\n", newthr->regs.r_rdx);
+      print_debug("\trsi = 0x%lx\n", newthr->regs.r_rsi);
+      print_debug("\trdi = 0x%lx\n", newthr->regs.r_rdi);
+      //print_debug("\torig_rax = 0x%lx\n", newthr->regs.orig_rax);
+      print_debug("\trip = 0x%lx\n", newthr->regs.r_rip);
+      print_debug("\tcs = 0x%lx\n", newthr->regs.r_cs);
+      //print_debug("\teflags = 0x%lx\n", newthr->regs.eflags);
+      print_debug("\trsp = 0x%lx\n", newthr->regs.r_rsp);
+      print_debug("\tss = 0x%lx\n", newthr->regs.r_ss);
+      //print_debug("\tfs_base = 0x%lx\n", newthr->regs.fs_base);
+      //print_debug("\tgs_base = 0x%lx\n", newthr->regs.gs_base);
+      //print_debug("\tds = 0x%lx\n", newthr->regs.ds);
+      //print_debug("\tes = 0x%lx\n", newthr->regs.es);
+      //print_debug("\tfs = 0x%lx\n", newthr->regs.fs);
+      //print_debug("\tgs = 0x%lx\n", newthr->regs.gs);
+#endif
+   }
+
+   return true;
+}
+
+#define ROUNDUP(x, y)  ((((x)+((y)-1))/(y))*(y))
+
+// read NT_PRSTATUS entries from core NOTE segment
+static bool core_handle_note(struct ps_prochandle* ph, ELF_PHDR* note_phdr) {
+   char* buf = NULL;
+   char* p = NULL;
+   size_t size = note_phdr->p_filesz;
+
+   // we are interested in just prstatus entries. we will ignore the rest.
+   // Advance the seek pointer to the start of the PT_NOTE data
+   if (lseek(ph->core->core_fd, note_phdr->p_offset, SEEK_SET) == (off_t)-1) {
+      print_debug("failed to lseek to PT_NOTE data\n");
+      return false;
+   }
+
+   // Now process the PT_NOTE structures.  Each one is preceded by
+   // an Elf{32/64}_Nhdr structure describing its type and size.
+   if ( (buf = (char*) malloc(size)) == NULL) {
+      print_debug("can't allocate memory for reading core notes\n");
+      goto err;
+   }
+
+   // read notes into buffer
+   if (read(ph->core->core_fd, buf, size) != size) {
+      print_debug("failed to read notes, core file must have been truncated\n");
+      goto err;
+   }
+
+   p = buf;
+   while (p < buf + size) {
+      ELF_NHDR* notep = (ELF_NHDR*) p;
+      char* descdata  = p + sizeof(ELF_NHDR) + ROUNDUP(notep->n_namesz, 4);
+      print_debug("Note header with n_type = %d and n_descsz = %u\n",
+                                   notep->n_type, notep->n_descsz);
+
+      if (notep->n_type == NT_PRSTATUS) {
+         if (core_handle_prstatus(ph, descdata, notep->n_descsz) != true)
+            return false;
+      }
+      p = descdata + ROUNDUP(notep->n_descsz, 4);
+   }
+
+   free(buf);
+   return true;
+
+err:
+   if (buf) free(buf);
+   return false;
+}
+
+// read all segments from core file
+static bool read_core_segments(struct ps_prochandle* ph, ELF_EHDR* core_ehdr) {
+   int i = 0;
+   ELF_PHDR* phbuf = NULL;
+   ELF_PHDR* core_php = NULL;
+
+   if ((phbuf =  read_program_header_table(ph->core->core_fd, core_ehdr)) == NULL)
+      return false;
+
+   /*
+    * Now iterate through the program headers in the core file.
+    * We're interested in two types of Phdrs: PT_NOTE (which
+    * 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:
+    *
+    *     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
+    *     PT_NOTE has data in new /proc format.
+    *
+    *     In Solaris, there is only one pstatus (process status). pstatus contains
+    *     integer register set among other stuff. For each LWP, we have one lwpstatus
+    *     entry that has integer regset for that LWP.
+    *
+    *     Linux threads are actually 'clone'd processes. To support core analysis
+    *     of "multithreaded" process, Linux creates more than one pstatus (called
+    *     "prstatus") entry in PT_NOTE. Each prstatus entry has integer regset for one
+    *     "thread". Please refer to Linux kernel src file 'fs/binfmt_elf.c', in particular
+    *     function "elf_core_dump".
+    */
+
+    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;
+            break;
+
+         case PT_LOAD: {
+            if (core_php->p_filesz != 0) {
+               if (add_map_info(ph, ph->core->core_fd, core_php->p_offset,
+                  core_php->p_vaddr, core_php->p_filesz) == NULL) goto err;
+            }
+            break;
+         }
+      }
+
+      core_php++;
+   }
+
+   free(phbuf);
+   return true;
+err:
+   free(phbuf);
+   return false;
+}
+
+// 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;
+
+   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)) {
+         if (add_map_info(ph, lib_fd, lib_php->p_offset, lib_php->p_vaddr + lib_base, lib_php->p_filesz) == NULL)
+            goto err;
+      }
+      lib_php++;
+   }
+
+   free(phbuf);
+   return true;
+err:
+   free(phbuf);
+   return false;
+}
+
+// process segments from interpreter (ld-elf.so.1)
+static bool read_interp_segments(struct ps_prochandle* ph) {
+   ELF_EHDR interp_ehdr;
+
+   if (read_elf_header(ph->core->interp_fd, &interp_ehdr) != true) {
+       print_debug("interpreter is not a valid ELF file\n");
+       return false;
+   }
+
+   if (read_lib_segments(ph, ph->core->interp_fd, &interp_ehdr, ph->core->ld_base_addr) != true) {
+       print_debug("can't read segments of interpreter\n");
+       return false;
+   }
+
+   return true;
+}
+
+// process segments of a a.out
+static bool read_exec_segments(struct ps_prochandle* ph, ELF_EHDR* exec_ehdr) {
+   int i = 0;
+   ELF_PHDR* phbuf = NULL;
+   ELF_PHDR* exec_php = NULL;
+
+   if ((phbuf = read_program_header_table(ph->core->exec_fd, exec_ehdr)) == NULL)
+      return false;
+
+   for (exec_php = phbuf, i = 0; i < exec_ehdr->e_phnum; i++) {
+      switch (exec_php->p_type) {
+
+         // add mappings for PT_LOAD segments
+         case PT_LOAD: {
+            // add only non-writable segments of non-zero filesz
+            if (!(exec_php->p_flags & PF_W) && exec_php->p_filesz != 0) {
+               if (add_map_info(ph, ph->core->exec_fd, exec_php->p_offset, exec_php->p_vaddr, exec_php->p_filesz) == NULL) goto err;
+            }
+            break;
+         }
+
+         // read the interpreter and it's segments
+         case PT_INTERP: {
+            char interp_name[BUF_SIZE];
+
+            pread(ph->core->exec_fd, interp_name, MIN(exec_php->p_filesz, BUF_SIZE), exec_php->p_offset);
+            print_debug("ELF interpreter %s\n", interp_name);
+            // read interpreter segments as well
+            if ((ph->core->interp_fd = pathmap_open(interp_name)) < 0) {
+               print_debug("can't open runtime loader\n");
+               goto err;
+            }
+            break;
+         }
+
+         // from PT_DYNAMIC we want to read address of first link_map addr
+         case PT_DYNAMIC: {
+            ph->core->dynamic_addr = exec_php->p_vaddr;
+            print_debug("address of _DYNAMIC is 0x%lx\n", ph->core->dynamic_addr);
+            break;
+         }
+
+      } // switch
+      exec_php++;
+   } // for
+
+   free(phbuf);
+   return true;
+err:
+   free(phbuf);
+   return false;
+}
+
+
+#define FIRST_LINK_MAP_OFFSET offsetof(struct r_debug,  r_map)
+#define LD_BASE_OFFSET        offsetof(struct r_debug,  r_ldbase)
+#define LINK_MAP_ADDR_OFFSET  offsetof(struct link_map, l_addr)
+#define LINK_MAP_NAME_OFFSET  offsetof(struct link_map, l_name)
+#define LINK_MAP_NEXT_OFFSET  offsetof(struct link_map, l_next)
+
+// 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_pread(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_pread(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;
+   }
+
+   // read ld_base address from struct r_debug
+   // XXX: 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;
+*/
+   ph->core->ld_base_addr = 0;
+
+   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)
+      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);
+
+   link_map_addr = first_link_map_addr;
+   while (link_map_addr != 0) {
+      // read library base address of the .so. Note that even though <sys/link.h> calls
+      // link_map->l_addr as "base address",  this is * not * really base virtual
+      // address of the shared object. This is actually the difference b/w the virtual
+      // address mentioned in shared object and the actual virtual base where runtime
+      // linker loaded it. We use "base diff" in read_lib_segments call below.
+
+      if (ps_pread(ph, (psaddr_t) link_map_addr + LINK_MAP_ADDR_OFFSET,
+                   &lib_base_diff, sizeof(uintptr_t)) != PS_OK) {
+         print_debug("can't read shared object base address diff\n");
+         return false;
+      }
+
+      // read address of the name
+      if (ps_pread(ph, (psaddr_t) link_map_addr + LINK_MAP_NAME_OFFSET,
+                    &lib_name_addr, sizeof(uintptr_t)) != PS_OK) {
+         print_debug("can't read address of shared object name\n");
+         return false;
+      }
+
+      // read name of the shared object
+      if (read_string(ph, (uintptr_t) lib_name_addr, lib_name, sizeof(lib_name)) != true) {
+         print_debug("can't read shared object name\n");
+         return false;
+      }
+
+      if (lib_name[0] != '\0') {
+         // ignore empty lib names
+         lib_fd = pathmap_open(lib_name);
+
+         if (lib_fd < 0) {
+            print_debug("can't open shared object %s\n", lib_name);
+            // continue with other libraries...
+         } else {
+            if (read_elf_header(lib_fd, &elf_ehdr)) {
+               lib_base = lib_base_diff + find_base_address(lib_fd, &elf_ehdr);
+               print_debug("reading library %s @ 0x%lx [ 0x%lx ]\n",
+                           lib_name, lib_base, lib_base_diff);
+               // while adding library mappings we need to use "base difference".
+               if (! read_lib_segments(ph, lib_fd, &elf_ehdr, lib_base_diff)) {
+                  print_debug("can't read shared object's segments\n");
+                  close(lib_fd);
+                  return false;
+               }
+               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)
+                  return false;
+            } else {
+               print_debug("can't read ELF header for shared object %s\n", lib_name);
+               close(lib_fd);
+               // continue with other libraries...
+            }
+         }
+      }
+
+      // 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) {
+         print_debug("can't read next link in link_map\n");
+         return false;
+      }
+   }
+
+   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;
+
+   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;
+   }
+
+   // 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;
+   }
+
+   // 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 (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 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;
+
+   // 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;
+
+   // 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;
+
+   return ph;
+
+err:
+   Prelease(ph);
+   return NULL;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/ps_proc.c	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,444 @@
+/*
+ * Copyright (c) 2003, 2010, 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.
+ *
+ */
+
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/ptrace.h>
+#include <sys/param.h>
+#include <sys/user.h>
+#include <elf.h>
+#include <sys/elf_common.h>
+#include <sys/link_elf.h>
+#include <libutil.h>
+#include "libproc_impl.h"
+#include "elfmacros.h"
+
+// This file has the libproc implementation specific to live process
+// For core files, refer to ps_core.c
+
+static inline uintptr_t align(uintptr_t ptr, size_t size) {
+  return (ptr & ~(size - 1));
+}
+
+// ---------------------------------------------
+// ptrace functions
+// ---------------------------------------------
+
+// read "size" bytes of data from "addr" within the target process.
+// unlike the standard ptrace() function, process_read_data() can handle
+// unaligned address - alignment check, if required, should be done
+// before calling process_read_data.
+
+static bool process_read_data(struct ps_prochandle* ph, uintptr_t addr, char *buf, size_t size) {
+  int rslt;
+  size_t i, words;
+  uintptr_t end_addr = addr + size;
+  uintptr_t aligned_addr = align(addr, sizeof(int));
+
+  if (aligned_addr != addr) {
+    char *ptr = (char *)&rslt;
+    errno = 0;
+    rslt = ptrace(PT_READ_D, ph->pid, (caddr_t) aligned_addr, 0);
+    if (errno) {
+      print_debug("ptrace(PT_READ_D, ..) failed for %d bytes @ %lx\n", size, addr);
+      return false;
+    }
+    for (; aligned_addr != addr; aligned_addr++, ptr++);
+    for (; ((intptr_t)aligned_addr % sizeof(int)) && aligned_addr < end_addr;
+        aligned_addr++)
+       *(buf++) = *(ptr++);
+  }
+
+  words = (end_addr - aligned_addr) / sizeof(int);
+
+  // assert((intptr_t)aligned_addr % sizeof(int) == 0);
+  for (i = 0; i < words; i++) {
+    errno = 0;
+    rslt = ptrace(PT_READ_D, ph->pid, (caddr_t) aligned_addr, 0);
+    if (errno) {
+      print_debug("ptrace(PT_READ_D, ..) failed for %d bytes @ %lx\n", size, addr);
+      return false;
+    }
+    *(int *)buf = rslt;
+    buf += sizeof(int);
+    aligned_addr += sizeof(int);
+  }
+
+  if (aligned_addr != end_addr) {
+    char *ptr = (char *)&rslt;
+    errno = 0;
+    rslt = ptrace(PT_READ_D, ph->pid, (caddr_t) aligned_addr, 0);
+    if (errno) {
+      print_debug("ptrace(PT_READ_D, ..) failed for %d bytes @ %lx\n", size, addr);
+      return false;
+    }
+    for (; aligned_addr != end_addr; aligned_addr++)
+       *(buf++) = *(ptr++);
+  }
+  return true;
+}
+
+// null implementation for write
+static bool process_write_data(struct ps_prochandle* ph,
+                             uintptr_t addr, const char *buf , size_t size) {
+  return false;
+}
+
+// "user" should be a pointer to a reg
+static bool process_get_lwp_regs(struct ps_prochandle* ph, pid_t pid, struct reg *user) {
+  // we have already attached to all thread 'pid's, just use ptrace call
+  // to get regset now. Note that we don't cache regset upfront for processes.
+ if (ptrace(PT_GETREGS, pid, (caddr_t) user, 0) < 0) {
+   print_debug("ptrace(PTRACE_GETREGS, ...) failed for lwp %d\n", pid);
+   return false;
+ }
+ return true;
+}
+
+// fill in ptrace_lwpinfo for lid
+static bool process_get_lwp_info(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo) {
+  errno = 0;
+  ptrace(PT_LWPINFO, lwp_id, linfo, sizeof(struct ptrace_lwpinfo));
+
+  return (errno == 0)? true: false;
+}
+
+// attach to a process/thread specified by "pid"
+static bool ptrace_attach(pid_t pid) {
+  if (ptrace(PT_ATTACH, pid, NULL, 0) < 0) {
+    print_debug("ptrace(PTRACE_ATTACH, ..) failed for %d\n", pid);
+    return false;
+  } else {
+    int ret;
+    int status;
+    do {
+      // Wait for debuggee to stop.
+      ret = waitpid(pid, &status, 0);
+      if (ret >= 0) {
+        if (WIFSTOPPED(status)) {
+          // Debuggee stopped.
+          return true;
+        } else {
+          print_debug("waitpid(): Child process exited/terminated (status = 0x%x)\n", status);
+          return false;
+        }
+      } else {
+        switch (errno) {
+          case EINTR:
+            continue;
+            break;
+          case ECHILD:
+            print_debug("waitpid() failed. Child process pid (%d) does not exist \n", pid);
+            break;
+          case EINVAL:
+            print_debug("waitpid() failed. Invalid options argument.\n");
+            break;
+          default:
+            print_debug("waitpid() failed. Unexpected error %d\n",errno);
+        }
+        return false;
+      }
+    } while(true);
+  }
+}
+
+// -------------------------------------------------------
+// functions for obtaining library information
+// -------------------------------------------------------
+
+// callback for read_thread_info
+static bool add_new_thread(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id) {
+  return add_thread_info(ph, pthread_id, lwp_id) != NULL;
+}
+
+#if defined(__FreeBSD__) && __FreeBSD_version < 701000
+/*
+ * TEXT_START_ADDR from binutils/ld/emulparams/<arch_spec>.sh
+ * Not the most robust but good enough.
+ */
+
+#if defined(amd64) || defined(x86_64)
+#define TEXT_START_ADDR 0x400000
+#elif defined(i386)
+#define TEXT_START_ADDR 0x8048000
+#else
+#error TEXT_START_ADDR not defined
+#endif
+
+#define BUF_SIZE (PATH_MAX + NAME_MAX + 1)
+
+uintptr_t linkmap_addr(struct ps_prochandle *ph) {
+  uintptr_t ehdr_addr, phdr_addr, dyn_addr, dmap_addr, lmap_addr;
+  ELF_EHDR ehdr;
+  ELF_PHDR *phdrs, *phdr;
+  ELF_DYN *dyns, *dyn;
+  struct r_debug dmap;
+  unsigned long hdrs_size;
+  unsigned int i;
+
+  /* read ELF_EHDR at TEXT_START_ADDR and validate */
+
+  ehdr_addr = (uintptr_t)TEXT_START_ADDR;
+
+  if (process_read_data(ph, ehdr_addr, (char *)&ehdr, sizeof(ehdr)) != true) {
+    print_debug("process_read_data failed for ehdr_addr %p\n", ehdr_addr);
+    return (0);
+  }
+
+  if (!IS_ELF(ehdr) ||
+        ehdr.e_ident[EI_CLASS] != ELF_TARG_CLASS ||
+        ehdr.e_ident[EI_DATA] != ELF_TARG_DATA ||
+        ehdr.e_ident[EI_VERSION] != EV_CURRENT ||
+        ehdr.e_phentsize != sizeof(ELF_PHDR) ||
+        ehdr.e_version != ELF_TARG_VER ||
+        ehdr.e_machine != ELF_TARG_MACH) {
+    print_debug("not an ELF_EHDR at %p\n", ehdr_addr);
+    return (0);
+  }
+
+  /* allocate space for all ELF_PHDR's and read */
+
+  phdr_addr = ehdr_addr + ehdr.e_phoff;
+  hdrs_size = ehdr.e_phnum * sizeof(ELF_PHDR);
+
+  if ((phdrs = malloc(hdrs_size)) == NULL)
+    return (0);
+
+  if (process_read_data(ph, phdr_addr, (char *)phdrs, hdrs_size) != true) {
+    print_debug("process_read_data failed for phdr_addr %p\n", phdr_addr);
+    return (0);
+  }
+
+  /* find PT_DYNAMIC section */
+
+  for (i = 0, phdr = phdrs; i < ehdr.e_phnum; i++, phdr++) {
+    if (phdr->p_type == PT_DYNAMIC)
+      break;
+  }
+
+  if (i >= ehdr.e_phnum) {
+    print_debug("PT_DYNAMIC section not found!\n");
+    free(phdrs);
+    return (0);
+  }
+
+  /* allocate space and read in ELF_DYN headers */
+
+  dyn_addr = phdr->p_vaddr;
+  hdrs_size = phdr->p_memsz;
+  free(phdrs);
+
+  if ((dyns = malloc(hdrs_size)) == NULL)
+    return (0);
+
+  if (process_read_data(ph, dyn_addr, (char *)dyns, hdrs_size) != true) {
+    print_debug("process_read_data failed for dyn_addr %p\n", dyn_addr);
+    free(dyns);
+    return (0);
+  }
+
+  /* find DT_DEBUG */
+
+  dyn = dyns;
+  while (dyn->d_tag != DT_DEBUG && dyn->d_tag != DT_NULL) {
+    dyn++;
+  }
+
+  if (dyn->d_tag != DT_DEBUG) {
+    print_debug("failed to find DT_DEBUG\n");
+    free(dyns);
+    return (0);
+  }
+
+  /* read struct r_debug into dmap */
+
+  dmap_addr = (uintptr_t)dyn->d_un.d_ptr;
+  free(dyns);
+
+  if (process_read_data(ph, dmap_addr, (char *)&dmap, sizeof(dmap)) != true) {
+    print_debug("process_read_data failed for dmap_addr %p\n", dmap_addr);
+    return (0);
+  }
+
+  lmap_addr = (uintptr_t)dmap.r_map;
+
+  return (lmap_addr);
+}
+#endif // __FreeBSD__ && __FreeBSD_version < 701000
+
+static bool read_lib_info(struct ps_prochandle* ph) {
+#if defined(__FreeBSD__) && __FreeBSD_version >= 701000
+  struct kinfo_vmentry *freep, *kve;
+  int i, cnt;
+
+  freep = kinfo_getvmmap(ph->pid, &cnt);
+  if (freep == NULL) {
+      print_debug("can't get vm map for pid\n", ph->pid);
+      return false;
+  }
+
+  for (i = 0; i < cnt; i++) {
+    kve = &freep[i];
+    if ((kve->kve_flags & KVME_FLAG_COW) &&
+        kve->kve_path != NULL &&
+        strlen(kve->kve_path) > 0) {
+
+      if (find_lib(ph, kve->kve_path) == false) {
+        lib_info* lib;
+        if ((lib = add_lib_info(ph, kve->kve_path,
+                                (uintptr_t) kve->kve_start)) == NULL)
+          continue; // ignore, add_lib_info prints error
+
+        // we don't need to keep the library open, symtab is already
+        // built. Only for core dump we need to keep the fd open.
+        close(lib->fd);
+        lib->fd = -1;
+      }
+    }
+  }
+
+  free(freep);
+
+  return true;
+#else
+  char *l_name;
+  struct link_map *lmap;
+  uintptr_t lmap_addr;
+
+  if ((l_name = malloc(BUF_SIZE)) == NULL)
+    return false;
+
+  if ((lmap = malloc(sizeof(*lmap))) == NULL) {
+    free(l_name);
+    return false;
+  }
+
+  lmap_addr = linkmap_addr(ph);
+
+  if (lmap_addr == 0) {
+    free(l_name);
+    free(lmap);
+    return false;
+  }
+
+  do {
+    if (process_read_data(ph, lmap_addr, (char *)lmap, sizeof(*lmap)) != true) {
+      print_debug("process_read_data failed for lmap_addr %p\n", lmap_addr);
+      free (l_name);
+      free (lmap);
+      return false;
+    }
+
+    if (process_read_data(ph, (uintptr_t)lmap->l_name, l_name,
+        BUF_SIZE) != true) {
+      print_debug("process_read_data failed for lmap->l_name %p\n",
+          lmap->l_name);
+      free (l_name);
+      free (lmap);
+      return false;
+    }
+
+    if (find_lib(ph, l_name) == false) {
+      lib_info* lib;
+      if ((lib = add_lib_info(ph, l_name,
+                              (uintptr_t) lmap->l_addr)) == NULL)
+        continue; // ignore, add_lib_info prints error
+
+      // we don't need to keep the library open, symtab is already
+      // built. Only for core dump we need to keep the fd open.
+      close(lib->fd);
+      lib->fd = -1;
+    }
+    lmap_addr = (uintptr_t)lmap->l_next;
+  } while (lmap->l_next != NULL);
+
+  free (l_name);
+  free (lmap);
+
+  return true;
+#endif
+}
+
+// detach a given pid
+static bool ptrace_detach(pid_t pid) {
+  if (pid && ptrace(PT_DETACH, pid, (caddr_t)1, 0) < 0) {
+    print_debug("ptrace(PTRACE_DETACH, ..) failed for %d\n", pid);
+    return false;
+  } else {
+    return true;
+  }
+}
+
+static void process_cleanup(struct ps_prochandle* ph) {
+  ptrace_detach(ph->pid);
+}
+
+static ps_prochandle_ops process_ops = {
+  .release=  process_cleanup,
+  .p_pread=  process_read_data,
+  .p_pwrite= process_write_data,
+  .get_lwp_regs= process_get_lwp_regs,
+  .get_lwp_info= process_get_lwp_info
+};
+
+// 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");
+     return NULL;
+  }
+
+  if (ptrace_attach(pid) != true) {
+     free(ph);
+     return NULL;
+  }
+
+  // initialize ps_prochandle
+  ph->pid = pid;
+
+  // initialize vtable
+  ph->ops = &process_ops;
+
+  // read library info and symbol tables, must do this before attaching threads,
+  // as the symbols in the pthread library will be used to figure out
+  // the list of threads within the same process.
+  if (read_lib_info(ph) != true) {
+     ptrace_detach(pid);
+     free(ph);
+     return NULL;
+  }
+
+  // read thread info
+  read_thread_info(ph, add_new_thread);
+
+  return ph;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/salibelf.c	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2003, 2006, 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.
+ *
+ */
+
+#include "salibelf.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+extern void print_debug(const char*,...);
+
+// ELF file parsing helpers. Note that we do *not* use libelf here.
+int read_elf_header(int fd, ELF_EHDR* ehdr) {
+   if (pread(fd, ehdr, sizeof (ELF_EHDR), 0) != sizeof (ELF_EHDR) ||
+            memcmp(&ehdr->e_ident[EI_MAG0], ELFMAG, SELFMAG) != 0 ||
+            ehdr->e_version != EV_CURRENT) {
+        return 0;
+   }
+   return 1;
+}
+
+bool is_elf_file(int fd) {
+   ELF_EHDR ehdr;
+   return read_elf_header(fd, &ehdr);
+}
+
+// read program header table of an ELF file
+ELF_PHDR* read_program_header_table(int fd, ELF_EHDR* hdr) {
+   ELF_PHDR* phbuf = 0;
+   // allocate memory for program header table
+   size_t nbytes = hdr->e_phnum * hdr->e_phentsize;
+
+   if ((phbuf = (ELF_PHDR*) malloc(nbytes)) == NULL) {
+      print_debug("can't allocate memory for reading program header table\n");
+      return NULL;
+   }
+
+   if (pread(fd, phbuf, nbytes, hdr->e_phoff) != nbytes) {
+      print_debug("ELF file is truncated! can't read program header table\n");
+      free(phbuf);
+      return NULL;
+   }
+
+   return phbuf;
+}
+
+// read section header table of an ELF file
+ELF_SHDR* read_section_header_table(int fd, ELF_EHDR* hdr) {
+   ELF_SHDR* shbuf = 0;
+   // allocate memory for section header table
+   size_t nbytes = hdr->e_shnum * hdr->e_shentsize;
+
+   if ((shbuf = (ELF_SHDR*) malloc(nbytes)) == NULL) {
+      print_debug("can't allocate memory for reading section header table\n");
+      return NULL;
+   }
+
+   if (pread(fd, shbuf, nbytes, hdr->e_shoff) != nbytes) {
+      print_debug("ELF file is truncated! can't read section header table\n");
+      free(shbuf);
+      return NULL;
+   }
+
+   return shbuf;
+}
+
+// read a particular section's data
+void* read_section_data(int fd, ELF_EHDR* ehdr, ELF_SHDR* shdr) {
+  void *buf = NULL;
+  if (shdr->sh_type == SHT_NOBITS || shdr->sh_size == 0) {
+     return buf;
+  }
+  if ((buf = calloc(shdr->sh_size, 1)) == NULL) {
+     print_debug("can't allocate memory for reading section data\n");
+     return NULL;
+  }
+  if (pread(fd, buf, shdr->sh_size, shdr->sh_offset) != shdr->sh_size) {
+     free(buf);
+     print_debug("section data read failed\n");
+     return NULL;
+  }
+  return buf;
+}
+
+uintptr_t find_base_address(int fd, ELF_EHDR* ehdr) {
+  uintptr_t baseaddr = (uintptr_t)-1;
+  int cnt;
+  ELF_PHDR *phbuf, *phdr;
+
+  // read program header table
+  if ((phbuf = read_program_header_table(fd, ehdr)) == NULL) {
+    goto quit;
+  }
+
+  // the base address of a shared object is the lowest vaddr of
+  // its loadable segments (PT_LOAD)
+  for (phdr = phbuf, cnt = 0; cnt < ehdr->e_phnum; cnt++, phdr++) {
+    if (phdr->p_type == PT_LOAD && phdr->p_vaddr < baseaddr) {
+      baseaddr = phdr->p_vaddr;
+    }
+  }
+
+quit:
+  if (phbuf) free(phbuf);
+  return baseaddr;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/salibelf.h	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2003, 2005, 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.
+ *
+ */
+
+#ifndef _SALIBELF_H_
+#define _SALIBELF_H_
+
+#include <elf.h>
+#include "elfmacros.h"
+#include "libproc_impl.h"
+
+// read ELF file header.
+int read_elf_header(int fd, ELF_EHDR* ehdr);
+
+// is given file descriptor corresponds to an ELF file?
+bool is_elf_file(int fd);
+
+// read program header table of an ELF file. caller has to
+// free the result pointer after use. NULL on failure.
+ELF_PHDR* read_program_header_table(int fd, ELF_EHDR* hdr);
+
+// read section header table of an ELF file. caller has to
+// free the result pointer after use. NULL on failure.
+ELF_SHDR* read_section_header_table(int fd, ELF_EHDR* hdr);
+
+// read a particular section's data. caller has to free the
+// result pointer after use. NULL on failure.
+void* read_section_data(int fd, ELF_EHDR* ehdr, ELF_SHDR* shdr);
+
+// find the base address at which the library wants to load itself
+uintptr_t find_base_address(int fd, ELF_EHDR* ehdr);
+#endif /* _SALIBELF_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/symtab.c	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,249 @@
+/*
+ * Copyright (c) 2003, 2010, 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.
+ *
+ */
+
+#include <unistd.h>
+#include <search.h>
+#include <stdlib.h>
+#include <string.h>
+#include <db.h>
+#include <fcntl.h>
+#include "symtab.h"
+#include "salibelf.h"
+
+
+// ----------------------------------------------------
+// functions for symbol lookups
+// ----------------------------------------------------
+
+struct elf_section {
+  ELF_SHDR   *c_shdr;
+  void       *c_data;
+};
+
+struct elf_symbol {
+  char *name;
+  uintptr_t offset;
+  uintptr_t size;
+};
+
+typedef struct symtab {
+  char *strs;
+  size_t num_symbols;
+  struct elf_symbol *symbols;
+  DB* hash_table;
+} symtab_t;
+
+// read symbol table from given fd.
+struct symtab* build_symtab(int fd) {
+  ELF_EHDR ehdr;
+  struct symtab* symtab = NULL;
+
+  // Reading of elf header
+  struct elf_section *scn_cache = NULL;
+  int cnt = 0;
+  ELF_SHDR* shbuf = NULL;
+  ELF_SHDR* cursct = NULL;
+  ELF_PHDR* phbuf = NULL;
+  int symtab_found = 0;
+  int dynsym_found = 0;
+  uint32_t symsection = SHT_SYMTAB;
+
+  uintptr_t baseaddr = (uintptr_t)-1;
+
+  lseek(fd, (off_t)0L, SEEK_SET);
+  if (! read_elf_header(fd, &ehdr)) {
+    // not an elf
+    return NULL;
+  }
+
+  // read ELF header
+  if ((shbuf = read_section_header_table(fd, &ehdr)) == NULL) {
+    goto quit;
+  }
+
+  baseaddr = find_base_address(fd, &ehdr);
+
+  scn_cache = calloc(ehdr.e_shnum, sizeof(*scn_cache));
+  if (scn_cache == NULL) {
+    goto quit;
+  }
+
+  for (cursct = shbuf, cnt = 0; cnt < ehdr.e_shnum; cnt++) {
+    scn_cache[cnt].c_shdr = cursct;
+    if (cursct->sh_type == SHT_SYMTAB ||
+        cursct->sh_type == SHT_STRTAB ||
+        cursct->sh_type == SHT_DYNSYM) {
+      if ( (scn_cache[cnt].c_data = read_section_data(fd, &ehdr, cursct)) == NULL) {
+         goto quit;
+      }
+    }
+
+    if (cursct->sh_type == SHT_SYMTAB)
+       symtab_found++;
+
+    if (cursct->sh_type == SHT_DYNSYM)
+       dynsym_found++;
+
+    cursct++;
+  }
+
+  if (!symtab_found && dynsym_found)
+     symsection = SHT_DYNSYM;
+
+  for (cnt = 1; cnt < ehdr.e_shnum; cnt++) {
+    ELF_SHDR *shdr = scn_cache[cnt].c_shdr;
+
+    if (shdr->sh_type == symsection) {
+      ELF_SYM  *syms;
+      int j, n;
+      size_t size;
+
+      // FIXME: there could be multiple data buffers associated with the
+      // same ELF section. Here we can handle only one buffer. See man page
+      // for elf_getdata on Solaris.
+
+      // guarantee(symtab == NULL, "multiple symtab");
+      symtab = calloc(1, sizeof(*symtab));
+      if (symtab == NULL) {
+         goto quit;
+      }
+      // the symbol table
+      syms = (ELF_SYM *)scn_cache[cnt].c_data;
+
+      // number of symbols
+      n = shdr->sh_size / shdr->sh_entsize;
+
+      // create hash table, we use berkeley db to
+      // manipulate the hash table.
+      symtab->hash_table = dbopen(NULL, O_CREAT | O_RDWR, 0600, DB_HASH, NULL);
+      // guarantee(symtab->hash_table, "unexpected failure: dbopen");
+      if (symtab->hash_table == NULL)
+        goto bad;
+
+      // shdr->sh_link points to the section that contains the actual strings
+      // for symbol names. the st_name field in ELF_SYM is just the
+      // string table index. we make a copy of the string table so the
+      // strings will not be destroyed by elf_end.
+      size = scn_cache[shdr->sh_link].c_shdr->sh_size;
+      symtab->strs = malloc(size);
+      if (symtab->strs == NULL)
+        goto bad;
+      memcpy(symtab->strs, scn_cache[shdr->sh_link].c_data, size);
+
+      // allocate memory for storing symbol offset and size;
+      symtab->num_symbols = n;
+      symtab->symbols = calloc(n , sizeof(*symtab->symbols));
+      if (symtab->symbols == NULL)
+        goto bad;
+
+      // copy symbols info our symtab and enter them info the hash table
+      for (j = 0; j < n; j++, syms++) {
+        DBT key, value;
+        char *sym_name = symtab->strs + syms->st_name;
+
+        // skip non-object and non-function symbols
+        int st_type = ELF_ST_TYPE(syms->st_info);
+        if ( st_type != STT_FUNC && st_type != STT_OBJECT)
+           continue;
+        // skip empty strings and undefined symbols
+        if (*sym_name == '\0' || syms->st_shndx == SHN_UNDEF) continue;
+
+        symtab->symbols[j].name   = sym_name;
+        symtab->symbols[j].offset = syms->st_value - baseaddr;
+        symtab->symbols[j].size   = syms->st_size;
+
+        key.data = sym_name;
+        key.size = strlen(sym_name) + 1;
+        value.data = &(symtab->symbols[j]);
+        value.size = sizeof(void *);
+        (*symtab->hash_table->put)(symtab->hash_table, &key, &value, 0);
+      }
+    }
+  }
+  goto quit;
+
+bad:
+  destroy_symtab(symtab);
+  symtab = NULL;
+
+quit:
+  if (shbuf) free(shbuf);
+  if (phbuf) free(phbuf);
+  if (scn_cache) {
+    for (cnt = 0; cnt < ehdr.e_shnum; cnt++) {
+      if (scn_cache[cnt].c_data != NULL) {
+        free(scn_cache[cnt].c_data);
+      }
+    }
+    free(scn_cache);
+  }
+  return symtab;
+}
+
+void destroy_symtab(struct symtab* symtab) {
+  if (!symtab) return;
+  if (symtab->strs) free(symtab->strs);
+  if (symtab->symbols) free(symtab->symbols);
+  if (symtab->hash_table) {
+    (*symtab->hash_table->close)(symtab->hash_table);
+  }
+  free(symtab);
+}
+
+uintptr_t search_symbol(struct symtab* symtab, uintptr_t base,
+                      const char *sym_name, int *sym_size) {
+  DBT key, value;
+  int ret;
+
+  // library does not have symbol table
+  if (!symtab || !symtab->hash_table)
+     return 0;
+
+  key.data = (char*)(uintptr_t)sym_name;
+  key.size = strlen(sym_name) + 1;
+  ret = (*symtab->hash_table->get)(symtab->hash_table, &key, &value, 0);
+  if (ret == 0) {
+    struct elf_symbol *sym = value.data;
+    uintptr_t rslt = (uintptr_t) ((char*)base + sym->offset);
+    if (sym_size) *sym_size = sym->size;
+    return rslt;
+  }
+
+  return 0;
+}
+
+const char* nearest_symbol(struct symtab* symtab, uintptr_t offset,
+                           uintptr_t* poffset) {
+  int n = 0;
+  if (!symtab) return NULL;
+  for (; n < symtab->num_symbols; n++) {
+    struct elf_symbol* sym = &(symtab->symbols[n]);
+    if (sym->name != NULL &&
+      offset >= sym->offset && offset < sym->offset + sym->size) {
+      if (poffset) *poffset = (offset - sym->offset);
+      return sym->name;
+    }
+  }
+  return NULL;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/symtab.h	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2003, 2010, 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.
+ *
+ */
+
+#ifndef _SYMTAB_H_
+#define _SYMTAB_H_
+
+#include <stdint.h>
+
+// interface to manage ELF symbol tables
+
+struct symtab;
+
+// build symbol table for a given ELF file descriptor
+struct symtab* build_symtab(int fd);
+
+// destroy the symbol table
+void destroy_symtab(struct symtab* symtab);
+
+// search for symbol in the given symbol table. Adds offset
+// to the base uintptr_t supplied. Returns NULL if not found.
+uintptr_t search_symbol(struct symtab* symtab, uintptr_t base,
+                      const char *sym_name, int *sym_size);
+
+// look for nearest symbol for a given offset (not address - base
+// subtraction done by caller
+const char* nearest_symbol(struct symtab* symtab, uintptr_t offset,
+                      uintptr_t* poffset);
+
+#endif /*_SYMTAB_H_*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/os/bsd/test.c	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2003, 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.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "libproc.h"
+
+int main(int argc, char** argv) {
+   struct ps_prochandle* ph;
+
+   init_libproc(true);
+   switch (argc) {
+      case 2: {
+         // process
+         ph = Pgrab(atoi(argv[1]));
+         break;
+      }
+
+      case 3: {
+        // core
+        ph = Pgrab_core(argv[1], argv[2]);
+        break;
+      }
+
+      default: {
+        fprintf(stderr, "usage %s <pid> or %s <exec file> <core file>\n", argv[0], argv[0]);
+        return 1;
+      }
+   }
+
+   if (ph) {
+      Prelease(ph);
+      return 0;
+   } else {
+      printf("can't connect to debuggee\n");
+      return 1;
+   }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/BsdVtblAccess.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2002, 2003, 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;
+
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.types.*;
+import sun.jvm.hotspot.types.basic.*;
+
+public class BsdVtblAccess extends BasicVtblAccess {
+  private String vt;
+
+  public BsdVtblAccess(SymbolLookup symbolLookup,
+                         String[] dllNames) {
+    super(symbolLookup, dllNames);
+
+    if (symbolLookup.lookup("libjvm.so", "__vt_10JavaThread") != null ||
+        symbolLookup.lookup("libjvm_g.so", "__vt_10JavaThread") != null) {
+       // old C++ ABI
+       vt = "__vt_";
+    } else {
+       // new C++ ABI
+       vt = "_ZTV";
+    }
+  }
+
+  protected String vtblSymbolForType(Type type) {
+    return vt + type.getName().length() + type;
+  }
+}
--- a/agent/src/share/classes/sun/jvm/hotspot/HotSpotAgent.java	Wed Oct 26 12:43:05 2011 -0700
+++ b/agent/src/share/classes/sun/jvm/hotspot/HotSpotAgent.java	Thu Oct 27 12:21:43 2011 -0700
@@ -28,6 +28,7 @@
 import java.net.*;
 import java.rmi.*;
 import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.bsd.*;
 import sun.jvm.hotspot.debugger.proc.*;
 import sun.jvm.hotspot.debugger.remote.*;
 import sun.jvm.hotspot.debugger.windbg.*;
@@ -335,6 +336,8 @@
                 setupDebuggerWin32();
             } else if (os.equals("linux")) {
                 setupDebuggerLinux();
+            } else if (os.equals("bsd")) {
+                setupDebuggerBsd();
             } else {
                 // Add support for more operating systems here
                 throw new DebuggerException("Operating system " + os + " not yet supported");
@@ -390,6 +393,10 @@
                 db = new HotSpotTypeDataBase(machDesc,
                 new LinuxVtblAccess(debugger, jvmLibNames),
                 debugger, jvmLibNames);
+            } else if (os.equals("bsd")) {
+                db = new HotSpotTypeDataBase(machDesc,
+                new BsdVtblAccess(debugger, jvmLibNames),
+                debugger, jvmLibNames);
             } else {
                 throw new DebuggerException("OS \"" + os + "\" not yet supported (no VtblAccess yet)");
             }
@@ -477,6 +484,8 @@
             setupJVMLibNamesWin32();
         } else if (os.equals("linux")) {
             setupJVMLibNamesLinux();
+        } else if (os.equals("bsd")) {
+            setupJVMLibNamesBsd();
         } else {
             throw new RuntimeException("Unknown OS type");
         }
@@ -554,6 +563,31 @@
         jvmLibNames = new String[] { "libjvm.so", "libjvm_g.so" };
     }
 
+    //
+    // BSD
+    //
+
+    private void setupDebuggerBsd() {
+        setupJVMLibNamesBsd();
+
+        if (cpu.equals("x86")) {
+            machDesc = new MachineDescriptionIntelX86();
+        } else if (cpu.equals("amd64")) {
+            machDesc = new MachineDescriptionAMD64();
+        } else {
+            throw new DebuggerException("BSD only supported on x86/amd64");
+        }
+
+        BsdDebuggerLocal dbg = new BsdDebuggerLocal(machDesc, !isServer);
+        debugger = dbg;
+
+        attachDebugger();
+    }
+
+    private void setupJVMLibNamesBsd() {
+        jvmLibNames = new String[] { "libjvm.so", "libjvm_g.so" };
+    }
+
     /** Convenience routine which should be called by per-platform
       debugger setup. Should not be called when startupMode is
       REMOTE_MODE. */
--- a/agent/src/share/classes/sun/jvm/hotspot/bugspot/BugSpotAgent.java	Wed Oct 26 12:43:05 2011 -0700
+++ b/agent/src/share/classes/sun/jvm/hotspot/bugspot/BugSpotAgent.java	Thu Oct 27 12:21:43 2011 -0700
@@ -29,6 +29,7 @@
 import java.rmi.*;
 import sun.jvm.hotspot.*;
 import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.bsd.*;
 import sun.jvm.hotspot.debugger.proc.*;
 import sun.jvm.hotspot.debugger.cdbg.*;
 import sun.jvm.hotspot.debugger.windbg.*;
@@ -514,6 +515,8 @@
                 setupDebuggerWin32();
             } else if (os.equals("linux")) {
                 setupDebuggerLinux();
+            } else if (os.equals("bsd")) {
+                setupDebuggerBsd();
             } else {
                 // Add support for more operating systems here
                 throw new DebuggerException("Operating system " + os + " not yet supported");
@@ -565,6 +568,9 @@
             } else if (os.equals("linux")) {
                 db = new HotSpotTypeDataBase(machDesc, new LinuxVtblAccess(debugger, jvmLibNames),
                 debugger, jvmLibNames);
+            } else if (os.equals("bsd")) {
+                db = new HotSpotTypeDataBase(machDesc, new BsdVtblAccess(debugger, jvmLibNames),
+                debugger, jvmLibNames);
             } else {
                 throw new DebuggerException("OS \"" + os + "\" not yet supported (no VtblAccess implemented yet)");
             }
@@ -666,6 +672,8 @@
             setupJVMLibNamesWin32();
         } else if (os.equals("linux")) {
             setupJVMLibNamesLinux();
+        } else if (os.equals("bsd")) {
+            setupJVMLibNamesBsd();
         } else {
             throw new RuntimeException("Unknown OS type");
         }
@@ -745,6 +753,34 @@
         setupJVMLibNamesSolaris();
     }
 
+    //
+    // BSD
+    //
+
+    private void setupDebuggerBsd() {
+        setupJVMLibNamesBsd();
+
+        if (cpu.equals("x86")) {
+            machDesc = new MachineDescriptionIntelX86();
+        } else if (cpu.equals("amd64")) {
+            machDesc = new MachineDescriptionAMD64();
+        } else {
+            throw new DebuggerException("Bsd only supported on x86/amd64");
+        }
+
+        // Note we do not use a cache for the local debugger in server
+        // mode; it will be taken care of on the client side (once remote
+        // debugging is implemented).
+
+        debugger = new BsdDebuggerLocal(machDesc, !isServer);
+        attachDebugger();
+    }
+
+    private void setupJVMLibNamesBsd() {
+        // same as solaris
+        setupJVMLibNamesSolaris();
+    }
+
     /** Convenience routine which should be called by per-platform
       debugger setup. Should not be called when startupMode is
       REMOTE_MODE. */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdAddress.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,399 @@
+/*
+ * Copyright (c) 2002, 2008, 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.debugger.bsd;
+
+import sun.jvm.hotspot.debugger.*;
+
+class BsdAddress implements Address {
+    protected BsdDebugger debugger;
+    protected long addr;
+
+    BsdAddress(BsdDebugger debugger, long addr) {
+        this.debugger = debugger;
+        this.addr = addr;
+    }
+
+    //
+    // Basic Java routines
+    //
+
+    public boolean equals(Object arg) {
+        if (arg == null) {
+            return false;
+        }
+
+        if (!(arg instanceof BsdAddress)) {
+            return false;
+        }
+
+        return (addr == ((BsdAddress) arg).addr);
+    }
+
+    public int hashCode() {
+        // FIXME: suggestions on a better hash code?
+        return (int) addr;
+    }
+
+    public String toString() {
+        return debugger.addressValueToString(addr);
+    }
+
+    //
+    // C/C++-related routines
+    //
+
+    public long getCIntegerAt(long offset, long numBytes, boolean isUnsigned)
+            throws UnalignedAddressException, UnmappedAddressException {
+        return debugger.readCInteger(addr + offset, numBytes, isUnsigned);
+    }
+
+    public Address getAddressAt(long offset)
+            throws UnalignedAddressException, UnmappedAddressException {
+        return debugger.readAddress(addr + offset);
+    }
+
+    public Address getCompOopAddressAt(long offset)
+            throws UnalignedAddressException, UnmappedAddressException {
+        return debugger.readCompOopAddress(addr + offset);
+    }
+
+    //
+    // Java-related routines
+    //
+
+  public boolean getJBooleanAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJBoolean(addr + offset);
+  }
+
+  public byte getJByteAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJByte(addr + offset);
+  }
+
+  public char getJCharAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJChar(addr + offset);
+  }
+
+  public double getJDoubleAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJDouble(addr + offset);
+  }
+
+  public float getJFloatAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJFloat(addr + offset);
+  }
+
+  public int getJIntAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJInt(addr + offset);
+  }
+
+  public long getJLongAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJLong(addr + offset);
+  }
+
+  public short getJShortAt(long offset) throws UnalignedAddressException, UnmappedAddressException {
+    return debugger.readJShort(addr + offset);
+  }
+
+  public OopHandle getOopHandleAt(long offset)
+    throws UnalignedAddressException, UnmappedAddressException, NotInHeapException {
+    return debugger.readOopHandle(addr + offset);
+  }
+
+  public OopHandle getCompOopHandleAt(long offset)
+    throws UnalignedAddressException, UnmappedAddressException, NotInHeapException {
+    return debugger.readCompOopHandle(addr + offset);
+  }
+
+  // Mutators -- not implemented for now (FIXME)
+  public void setCIntegerAt(long offset, long numBytes, long value) {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void setAddressAt(long offset, Address value) {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJBooleanAt      (long offset, boolean value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJByteAt         (long offset, byte value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJCharAt         (long offset, char value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJDoubleAt       (long offset, double value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJFloatAt        (long offset, float value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJIntAt          (long offset, int value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJLongAt         (long offset, long value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setJShortAt        (long offset, short value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+  public void       setOopHandleAt     (long offset, OopHandle value)
+    throws UnmappedAddressException, UnalignedAddressException {
+    throw new DebuggerException("Unimplemented");
+  }
+
+  //
+  // Arithmetic operations -- necessary evil.
+  //
+
+  public Address    addOffsetTo       (long offset) throws UnsupportedOperationException {
+    long value = addr + offset;
+    if (value == 0) {
+      return null;
+    }
+    return new BsdAddress(debugger, value);
+  }
+
+  public OopHandle  addOffsetToAsOopHandle(long offset) throws UnsupportedOperationException {
+    long value = addr + offset;
+    if (value == 0) {
+      return null;
+    }
+    return new BsdOopHandle(debugger, value);
+  }
+
+  /** (FIXME: any signed/unsigned issues? Should this work for
+      OopHandles?) */
+  public long       minus(Address arg) {
+    if (arg == null) {
+      return addr;
+    }
+    return addr - ((BsdAddress) arg).addr;
+  }
+
+  // Two's complement representation.
+  // All negative numbers are larger than positive numbers.
+  // Numbers with the same sign can be compared normally.
+  // Test harness is below in main().
+
+  public boolean    lessThan          (Address a) {
+    if (a == null) {
+      return false;
+    }
+    BsdAddress arg = (BsdAddress) a;
+    if ((addr >= 0) && (arg.addr < 0)) {
+      return true;
+    }
+    if ((addr < 0) && (arg.addr >= 0)) {
+      return false;
+    }
+    return (addr < arg.addr);
+  }
+
+  public boolean    lessThanOrEqual   (Address a) {
+    if (a == null) {
+      return false;
+    }
+    BsdAddress arg = (BsdAddress) a;
+    if ((addr >= 0) && (arg.addr < 0)) {
+      return true;
+    }
+    if ((addr < 0) && (arg.addr >= 0)) {
+      return false;
+    }
+    return (addr <= arg.addr);
+  }
+
+  public boolean    greaterThan       (Address a) {
+    if (a == null) {
+      return true;
+    }
+    BsdAddress arg = (BsdAddress) a;
+    if ((addr >= 0) && (arg.addr < 0)) {
+      return false;
+    }
+    if ((addr < 0) && (arg.addr >= 0)) {
+      return true;
+    }
+    return (addr > arg.addr);
+  }
+
+  public boolean    greaterThanOrEqual(Address a) {
+    if (a == null) {
+      return true;
+    }
+    BsdAddress arg = (BsdAddress) a;
+    if ((addr >= 0) && (arg.addr < 0)) {
+      return false;
+    }
+    if ((addr < 0) && (arg.addr >= 0)) {
+      return true;
+    }
+    return (addr >= arg.addr);
+  }
+
+  public Address    andWithMask(long mask) throws UnsupportedOperationException {
+    long value = addr & mask;
+    if (value == 0) {
+      return null;
+    }
+    return new BsdAddress(debugger, value);
+  }
+
+  public Address    orWithMask(long mask) throws UnsupportedOperationException {
+    long value = addr | mask;
+    if (value == 0) {
+      return null;
+    }
+    return new BsdAddress(debugger, value);
+  }
+
+  public Address    xorWithMask(long mask) throws UnsupportedOperationException {
+    long value = addr ^ mask;
+    if (value == 0) {
+      return null;
+    }
+    return new BsdAddress(debugger, value);
+  }
+
+
+  //--------------------------------------------------------------------------------
+  // Internals only below this point
+  //
+
+  long getValue() {
+    return addr;
+  }
+
+
+  private static void check(boolean arg, String failMessage) {
+    if (!arg) {
+      System.err.println(failMessage + ": FAILED");
+      System.exit(1);
+    }
+  }
+
+  // Test harness
+  public static void main(String[] args) {
+    // p/n indicates whether the interior address is really positive
+    // or negative. In unsigned terms, p1 < p2 < n1 < n2.
+
+    BsdAddress p1 = new BsdAddress(null, 0x7FFFFFFFFFFFFFF0L);
+    BsdAddress p2 = (BsdAddress) p1.addOffsetTo(10);
+    BsdAddress n1 = (BsdAddress) p2.addOffsetTo(10);
+    BsdAddress n2 = (BsdAddress) n1.addOffsetTo(10);
+
+    // lessThan positive tests
+    check(p1.lessThan(p2), "lessThan 1");
+    check(p1.lessThan(n1), "lessThan 2");
+    check(p1.lessThan(n2), "lessThan 3");
+    check(p2.lessThan(n1), "lessThan 4");
+    check(p2.lessThan(n2), "lessThan 5");
+    check(n1.lessThan(n2), "lessThan 6");
+
+    // lessThan negative tests
+    check(!p1.lessThan(p1), "lessThan 7");
+    check(!p2.lessThan(p2), "lessThan 8");
+    check(!n1.lessThan(n1), "lessThan 9");
+    check(!n2.lessThan(n2), "lessThan 10");
+
+    check(!p2.lessThan(p1), "lessThan 11");
+    check(!n1.lessThan(p1), "lessThan 12");
+    check(!n2.lessThan(p1), "lessThan 13");
+    check(!n1.lessThan(p2), "lessThan 14");
+    check(!n2.lessThan(p2), "lessThan 15");
+    check(!n2.lessThan(n1), "lessThan 16");
+
+    // lessThanOrEqual positive tests
+    check(p1.lessThanOrEqual(p1), "lessThanOrEqual 1");
+    check(p2.lessThanOrEqual(p2), "lessThanOrEqual 2");
+    check(n1.lessThanOrEqual(n1), "lessThanOrEqual 3");
+    check(n2.lessThanOrEqual(n2), "lessThanOrEqual 4");
+
+    check(p1.lessThanOrEqual(p2), "lessThanOrEqual 5");
+    check(p1.lessThanOrEqual(n1), "lessThanOrEqual 6");
+    check(p1.lessThanOrEqual(n2), "lessThanOrEqual 7");
+    check(p2.lessThanOrEqual(n1), "lessThanOrEqual 8");
+    check(p2.lessThanOrEqual(n2), "lessThanOrEqual 9");
+    check(n1.lessThanOrEqual(n2), "lessThanOrEqual 10");
+
+    // lessThanOrEqual negative tests
+    check(!p2.lessThanOrEqual(p1), "lessThanOrEqual 11");
+    check(!n1.lessThanOrEqual(p1), "lessThanOrEqual 12");
+    check(!n2.lessThanOrEqual(p1), "lessThanOrEqual 13");
+    check(!n1.lessThanOrEqual(p2), "lessThanOrEqual 14");
+    check(!n2.lessThanOrEqual(p2), "lessThanOrEqual 15");
+    check(!n2.lessThanOrEqual(n1), "lessThanOrEqual 16");
+
+    // greaterThan positive tests
+    check(n2.greaterThan(p1), "greaterThan 1");
+    check(n2.greaterThan(p2), "greaterThan 2");
+    check(n2.greaterThan(n1), "greaterThan 3");
+    check(n1.greaterThan(p1), "greaterThan 4");
+    check(n1.greaterThan(p2), "greaterThan 5");
+    check(p2.greaterThan(p1), "greaterThan 6");
+
+    // greaterThan negative tests
+    check(!p1.greaterThan(p1), "greaterThan 7");
+    check(!p2.greaterThan(p2), "greaterThan 8");
+    check(!n1.greaterThan(n1), "greaterThan 9");
+    check(!n2.greaterThan(n2), "greaterThan 10");
+
+    check(!p1.greaterThan(n2), "greaterThan 11");
+    check(!p2.greaterThan(n2), "greaterThan 12");
+    check(!n1.greaterThan(n2), "greaterThan 13");
+    check(!p1.greaterThan(n1), "greaterThan 14");
+    check(!p2.greaterThan(n1), "greaterThan 15");
+    check(!p1.greaterThan(p2), "greaterThan 16");
+
+    // greaterThanOrEqual positive tests
+    check(p1.greaterThanOrEqual(p1), "greaterThanOrEqual 1");
+    check(p2.greaterThanOrEqual(p2), "greaterThanOrEqual 2");
+    check(n1.greaterThanOrEqual(n1), "greaterThanOrEqual 3");
+    check(n2.greaterThanOrEqual(n2), "greaterThanOrEqual 4");
+
+    check(n2.greaterThanOrEqual(p1), "greaterThanOrEqual 5");
+    check(n2.greaterThanOrEqual(p2), "greaterThanOrEqual 6");
+    check(n2.greaterThanOrEqual(n1), "greaterThanOrEqual 7");
+    check(n1.greaterThanOrEqual(p1), "greaterThanOrEqual 8");
+    check(n1.greaterThanOrEqual(p2), "greaterThanOrEqual 9");
+    check(p2.greaterThanOrEqual(p1), "greaterThanOrEqual 10");
+
+    // greaterThanOrEqual negative tests
+    check(!p1.greaterThanOrEqual(n2), "greaterThanOrEqual 11");
+    check(!p2.greaterThanOrEqual(n2), "greaterThanOrEqual 12");
+    check(!n1.greaterThanOrEqual(n2), "greaterThanOrEqual 13");
+    check(!p1.greaterThanOrEqual(n1), "greaterThanOrEqual 14");
+    check(!p2.greaterThanOrEqual(n1), "greaterThanOrEqual 15");
+    check(!p1.greaterThanOrEqual(p2), "greaterThanOrEqual 16");
+
+    System.err.println("BsdAddress: all tests passed successfully.");
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdCDebugger.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2003, 2006, 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.debugger.bsd;
+
+import java.io.*;
+import java.util.*;
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.cdbg.*;
+import sun.jvm.hotspot.debugger.x86.*;
+import sun.jvm.hotspot.debugger.amd64.*;
+import sun.jvm.hotspot.debugger.bsd.x86.*;
+import sun.jvm.hotspot.debugger.bsd.amd64.*;
+import sun.jvm.hotspot.utilities.*;
+
+class BsdCDebugger implements CDebugger {
+  private BsdDebugger dbg;
+
+  BsdCDebugger(BsdDebugger dbg) {
+    this.dbg = dbg;
+  }
+
+  public List getThreadList() throws DebuggerException {
+    return dbg.getThreadList();
+  }
+
+  public List/*<LoadObject>*/ getLoadObjectList() throws DebuggerException {
+    return dbg.getLoadObjectList();
+  }
+
+  public LoadObject loadObjectContainingPC(Address pc) throws DebuggerException {
+    if (pc == null) {
+      return null;
+    }
+    List objs = getLoadObjectList();
+    Object[] arr = objs.toArray();
+    // load objects are sorted by base address, do binary search
+    int mid  = -1;
+    int low  = 0;
+    int high = arr.length - 1;
+
+    while (low <= high) {
+       mid = (low + high) >> 1;
+       LoadObject midVal = (LoadObject) arr[mid];
+       long cmp = pc.minus(midVal.getBase());
+       if (cmp < 0) {
+          high = mid - 1;
+       } else if (cmp > 0) {
+          long size = midVal.getSize();
+          if (cmp >= size) {
+             low = mid + 1;
+          } else {
+             return (LoadObject) arr[mid];
+          }
+       } else { // match found
+          return (LoadObject) arr[mid];
+       }
+    }
+    // no match found.
+    return null;
+  }
+
+  public CFrame topFrameForThread(ThreadProxy thread) throws DebuggerException {
+    String cpu = dbg.getCPU();
+    if (cpu.equals("x86")) {
+       X86ThreadContext context = (X86ThreadContext) thread.getContext();
+       Address ebp = context.getRegisterAsAddress(X86ThreadContext.EBP);
+       if (ebp == null) return null;
+       Address pc  = context.getRegisterAsAddress(X86ThreadContext.EIP);
+       if (pc == null) return null;
+       return new BsdX86CFrame(dbg, ebp, pc);
+    } else if (cpu.equals("amd64")) {
+       AMD64ThreadContext context = (AMD64ThreadContext) thread.getContext();
+       Address rbp = context.getRegisterAsAddress(AMD64ThreadContext.RBP);
+       if (rbp == null) return null;
+       Address pc  = context.getRegisterAsAddress(AMD64ThreadContext.RIP);
+       if (pc == null) return null;
+       return new BsdAMD64CFrame(dbg, rbp, pc);
+    } else {
+       throw new DebuggerException(cpu + " is not yet supported");
+    }
+  }
+
+  public String getNameOfFile(String fileName) {
+    return new File(fileName).getName();
+  }
+
+  public ProcessControl getProcessControl() throws DebuggerException {
+    // FIXME: after stabs parser
+    return null;
+  }
+
+  public boolean canDemangle() {
+    return false;
+  }
+
+  public String demangle(String sym) {
+    throw new UnsupportedOperationException();
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebugger.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2002, 2008, 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.debugger.bsd;
+
+import java.util.List;
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.cdbg.*;
+
+/** An extension of the JVMDebugger interface with a few additions to
+    support 32-bit vs. 64-bit debugging as well as features required
+    by the architecture-specific subpackages. */
+
+public interface BsdDebugger extends JVMDebugger {
+  public String       addressValueToString(long address) throws DebuggerException;
+  public boolean      readJBoolean(long address) throws DebuggerException;
+  public byte         readJByte(long address) throws DebuggerException;
+  public char         readJChar(long address) throws DebuggerException;
+  public double       readJDouble(long address) throws DebuggerException;
+  public float        readJFloat(long address) throws DebuggerException;
+  public int          readJInt(long address) throws DebuggerException;
+  public long         readJLong(long address) throws DebuggerException;
+  public short        readJShort(long address) throws DebuggerException;
+  public long         readCInteger(long address, long numBytes, boolean isUnsigned)
+    throws DebuggerException;
+  public BsdAddress readAddress(long address) throws DebuggerException;
+  public BsdAddress readCompOopAddress(long address) throws DebuggerException;
+  public BsdOopHandle readOopHandle(long address) throws DebuggerException;
+  public BsdOopHandle readCompOopHandle(long address) throws DebuggerException;
+  public long[]       getThreadIntegerRegisterSet(int lwp_id) throws DebuggerException;
+  public long         getAddressValue(Address addr) throws DebuggerException;
+  public Address      newAddress(long value) throws DebuggerException;
+
+  // For BsdCDebugger
+  public List         getThreadList();
+  public List         getLoadObjectList();
+  public ClosestSymbol lookup(long address);
+
+  // NOTE: this interface implicitly contains the following methods:
+  // From the Debugger interface via JVMDebugger
+  //   public void attach(int processID) throws DebuggerException;
+  //   public void attach(String executableName, String coreFileName) throws DebuggerException;
+  //   public boolean detach();
+  //   public Address parseAddress(String addressString) throws NumberFormatException;
+  //   public String getOS();
+  //   public String getCPU();
+  // From the SymbolLookup interface via Debugger and JVMDebugger
+  //   public Address lookup(String objectName, String symbol);
+  //   public OopHandle lookupOop(String objectName, String symbol);
+  // From the JVMDebugger interface
+  //   public void configureJavaPrimitiveTypeSizes(long jbooleanSize,
+  //                                               long jbyteSize,
+  //                                               long jcharSize,
+  //                                               long jdoubleSize,
+  //                                               long jfloatSize,
+  //                                               long jintSize,
+  //                                               long jlongSize,
+  //                                               long jshortSize);
+  // From the ThreadAccess interface via Debugger and JVMDebugger
+  //   public ThreadProxy getThreadForIdentifierAddress(Address addr);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdDebuggerLocal.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,597 @@
+/*
+ * Copyright (c) 2002, 2008, 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.debugger.bsd;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.x86.*;
+import sun.jvm.hotspot.debugger.cdbg.*;
+import sun.jvm.hotspot.utilities.*;
+import java.lang.reflect.*;
+
+/** <P> An implementation of the JVMDebugger interface. The basic debug
+    facilities are implemented through ptrace interface in the JNI code
+    (libsaproc.so). Library maps and symbol table management are done in
+    JNI. </P>
+
+    <P> <B>NOTE</B> that since we have the notion of fetching "Java
+    primitive types" from the remote process (which might have
+    different sizes than we expect) we have a bootstrapping
+    problem. We need to know the sizes of these types before we can
+    fetch them. The current implementation solves this problem by
+    requiring that it be configured with these type sizes before they
+    can be fetched. The readJ(Type) routines here will throw a
+    RuntimeException if they are called before the debugger is
+    configured with the Java primitive type sizes. </P> */
+
+public class BsdDebuggerLocal extends DebuggerBase implements BsdDebugger {
+    private boolean useGCC32ABI;
+    private boolean attached;
+    private long    p_ps_prochandle; // native debugger handle
+    private long    symbolicator; // macosx symbolicator handle
+    private long    task; // macosx task handle
+    private boolean isCore;
+
+    // CDebugger support
+    private BsdCDebugger cdbg;
+
+    // threadList and loadObjectList are filled by attach0 method
+    private List threadList;
+    private List loadObjectList;
+
+    // called by native method lookupByAddress0
+    private ClosestSymbol createClosestSymbol(String name, long offset) {
+       return new ClosestSymbol(name, offset);
+    }
+
+    // called by native method attach0
+    private LoadObject createLoadObject(String fileName, long textsize,
+                                        long base) {
+       File f = new File(fileName);
+       Address baseAddr = newAddress(base);
+       return new SharedObject(this, fileName, f.length(), baseAddr);
+    }
+
+    // native methods
+
+    private native static void init0()
+                                throws DebuggerException;
+    private native void attach0(int pid)
+                                throws DebuggerException;
+    private native void attach0(String execName, String coreName)
+                                throws DebuggerException;
+    private native void detach0()
+                                throws DebuggerException;
+    private native long lookupByName0(String objectName, String symbol)
+                                throws DebuggerException;
+    private native ClosestSymbol lookupByAddress0(long address)
+                                throws DebuggerException;
+    private native long[] getThreadIntegerRegisterSet0(int lwp_id)
+                                throws DebuggerException;
+    private native byte[] readBytesFromProcess0(long address, long numBytes)
+                                throws DebuggerException;
+    public native static int  getAddressSize() ;
+
+    // Note on Bsd threads are really processes. When target process is
+    // attached by a serviceability agent thread, only that thread can do
+    // ptrace operations on the target. This is because from kernel's point
+    // view, other threads are just separate processes and they are not
+    // attached to the target. When they attempt to make ptrace calls,
+    // an ESRCH error will be returned as kernel believes target is not
+    // being traced by the caller.
+    // To work around the problem, we use a worker thread here to handle
+    // all JNI functions that are making ptrace calls.
+
+    interface WorkerThreadTask {
+       public void doit(BsdDebuggerLocal debugger) throws DebuggerException;
+    }
+
+    class BsdDebuggerLocalWorkerThread extends Thread {
+       BsdDebuggerLocal debugger;
+       WorkerThreadTask task;
+       DebuggerException lastException;
+
+       public BsdDebuggerLocalWorkerThread(BsdDebuggerLocal debugger) {
+         this.debugger = debugger;
+         setDaemon(true);
+       }
+
+       public void run() {
+          synchronized (workerThread) {
+             for (;;) {
+                if (task != null) {
+                   lastException = null;
+                   try {
+                      task.doit(debugger);
+                   } catch (DebuggerException exp) {
+                      lastException = exp;
+                   }
+                   task = null;
+                   workerThread.notifyAll();
+                }
+
+                try {
+                   workerThread.wait();
+                } catch (InterruptedException x) {}
+             }
+          }
+       }
+
+       public WorkerThreadTask execute(WorkerThreadTask task) throws DebuggerException {
+          synchronized (workerThread) {
+             this.task = task;
+             workerThread.notifyAll();
+             while (this.task != null) {
+                try {
+                   workerThread.wait();
+                } catch (InterruptedException x) {}
+             }
+             if (lastException != null) {
+                throw new DebuggerException(lastException);
+             } else {
+                return task;
+             }
+          }
+       }
+    }
+
+    private BsdDebuggerLocalWorkerThread workerThread = null;
+
+    //----------------------------------------------------------------------
+    // Implementation of Debugger interface
+    //
+
+    /** <P> machDesc may not be null. </P>
+
+    <P> useCache should be set to true if debugging is being done
+    locally, and to false if the debugger is being created for the
+    purpose of supporting remote debugging. </P> */
+    public BsdDebuggerLocal(MachineDescription machDesc,
+                              boolean useCache) throws DebuggerException {
+        this.machDesc = machDesc;
+        utils = new DebuggerUtilities(machDesc.getAddressSize(),
+                                      machDesc.isBigEndian()) {
+           public void checkAlignment(long address, long alignment) {
+             // Need to override default checkAlignment because we need to
+             // relax alignment constraints on Bsd/x86
+             if ( (address % alignment != 0)
+                &&(alignment != 8 || address % 4 != 0)) {
+                throw new UnalignedAddressException(
+                        "Trying to read at address: "
+                      + addressValueToString(address)
+                      + " with alignment: " + alignment,
+                        address);
+             }
+           }
+        };
+
+        if (useCache) {
+            // FIXME: re-test necessity of cache on Bsd, where data
+            // fetching is faster
+            // Cache portion of the remote process's address space.
+            // Fetching data over the socket connection to dbx is slow.
+            // Might be faster if we were using a binary protocol to talk to
+            // dbx, but would have to test. For now, this cache works best
+            // if it covers the entire heap of the remote process. FIXME: at
+            // least should make this tunable from the outside, i.e., via
+            // the UI. This is a cache of 4096 4K pages, or 16 MB. The page
+            // size must be adjusted to be the hardware's page size.
+            // (FIXME: should pick this up from the debugger.)
+            if (getCPU().equals("ia64")) {
+              initCache(16384, parseCacheNumPagesProperty(1024));
+            } else {
+              initCache(4096, parseCacheNumPagesProperty(4096));
+            }
+        }
+
+        workerThread = new BsdDebuggerLocalWorkerThread(this);
+        workerThread.start();
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public boolean hasProcessList() throws DebuggerException {
+        return false;
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public List getProcessList() throws DebuggerException {
+        throw new DebuggerException("getProcessList not implemented yet");
+    }
+
+    private void checkAttached() throws DebuggerException {
+        if (attached) {
+            if (isCore) {
+                throw new DebuggerException("attached to a core dump already");
+            } else {
+                throw new DebuggerException("attached to a process already");
+            }
+        }
+    }
+
+    private void requireAttach() {
+        if (! attached) {
+            throw new RuntimeException("not attached to a process or a core!");
+        }
+    }
+
+    /* called from attach methods */
+    private void findABIVersion() throws DebuggerException {
+        if (lookupByName0("libjvm.so", "__vt_10JavaThread") != 0 ||
+            lookupByName0("libjvm_g.so", "__vt_10JavaThread") != 0) {
+            // old C++ ABI
+            useGCC32ABI = false;
+        } else {
+            // new C++ ABI
+            useGCC32ABI = true;
+        }
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public synchronized void attach(int processID) throws DebuggerException {
+        checkAttached();
+        threadList = new ArrayList();
+        loadObjectList = new ArrayList();
+        class AttachTask implements WorkerThreadTask {
+           int pid;
+           public void doit(BsdDebuggerLocal debugger) {
+              debugger.attach0(pid);
+              debugger.attached = true;
+              debugger.isCore = false;
+              findABIVersion();
+           }
+        }
+
+        AttachTask task = new AttachTask();
+        task.pid = processID;
+        workerThread.execute(task);
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public synchronized void attach(String execName, String coreName) {
+        checkAttached();
+        threadList = new ArrayList();
+        loadObjectList = new ArrayList();
+        attach0(execName, coreName);
+        attached = true;
+        isCore = true;
+        findABIVersion();
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public synchronized boolean detach() {
+        if (!attached) {
+            return false;
+        }
+
+        threadList = null;
+        loadObjectList = null;
+
+        if (isCore) {
+            detach0();
+            attached = false;
+            return true;
+        } else {
+            class DetachTask implements WorkerThreadTask {
+                boolean result = false;
+
+                public void doit(BsdDebuggerLocal debugger) {
+                    debugger.detach0();
+                    debugger.attached = false;
+                    result = true;
+                }
+            }
+
+            DetachTask task = new DetachTask();
+            workerThread.execute(task);
+            return task.result;
+        }
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public Address parseAddress(String addressString)
+            throws NumberFormatException {
+        long addr = utils.scanAddress(addressString);
+        if (addr == 0) {
+            return null;
+        }
+        return new BsdAddress(this, addr);
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public String getOS() {
+        return PlatformInfo.getOS();
+    }
+
+    /** From the Debugger interface via JVMDebugger */
+    public String getCPU() {
+        return PlatformInfo.getCPU();
+    }
+
+    public boolean hasConsole() throws DebuggerException {
+        return false;
+    }
+
+    public String consoleExecuteCommand(String cmd) throws DebuggerException {
+        throw new DebuggerException("No debugger console available on Bsd");
+    }
+
+    public String getConsolePrompt() throws DebuggerException {
+        return null;
+    }
+
+    /* called from lookup */
+    private long handleGCC32ABI(long addr, String symbol) throws DebuggerException {
+        if (useGCC32ABI && symbol.startsWith("_ZTV")) {
+            return addr + (2 * machDesc.getAddressSize());
+        } else {
+            return addr;
+        }
+    }
+
+    /** From the SymbolLookup interface via Debugger and JVMDebugger */
+    public synchronized Address lookup(String objectName, String symbol) {
+        requireAttach();
+        if (!attached) {
+            return null;
+        }
+
+        if (isCore) {
+            long addr = lookupByName0(objectName, symbol);
+            return (addr == 0)? null : new BsdAddress(this, handleGCC32ABI(addr, symbol));
+        } else {
+            class LookupByNameTask implements WorkerThreadTask {
+                String objectName, symbol;
+                Address result;
+
+                public void doit(BsdDebuggerLocal debugger) {
+                    long addr = debugger.lookupByName0(objectName, symbol);
+                    result = (addr == 0 ? null : new BsdAddress(debugger, handleGCC32ABI(addr, symbol)));
+                }
+            }
+
+            LookupByNameTask task = new LookupByNameTask();
+            task.objectName = objectName;
+            task.symbol = symbol;
+            workerThread.execute(task);
+            return task.result;
+        }
+    }
+
+    /** From the SymbolLookup interface via Debugger and JVMDebugger */
+    public synchronized OopHandle lookupOop(String objectName, String symbol) {
+        Address addr = lookup(objectName, symbol);
+        if (addr == null) {
+            return null;
+        }
+        return addr.addOffsetToAsOopHandle(0);
+    }
+
+    /** From the Debugger interface */
+    public MachineDescription getMachineDescription() {
+        return machDesc;
+    }
+
+    //----------------------------------------------------------------------
+    // Implementation of ThreadAccess interface
+    //
+
+    /** From the ThreadAccess interface via Debugger and JVMDebugger */
+    public ThreadProxy getThreadForIdentifierAddress(Address addr) {
+        return new BsdThread(this, addr);
+    }
+
+    /** From the ThreadAccess interface via Debugger and JVMDebugger */
+    public ThreadProxy getThreadForThreadId(long id) {
+        return new BsdThread(this, id);
+    }
+
+    //----------------------------------------------------------------------
+    // Internal routines (for implementation of BsdAddress).
+    // These must not be called until the MachineDescription has been set up.
+    //
+
+    /** From the BsdDebugger interface */
+    public String addressValueToString(long address) {
+        return utils.addressValueToString(address);
+    }
+
+    /** From the BsdDebugger interface */
+    public BsdAddress readAddress(long address)
+            throws UnmappedAddressException, UnalignedAddressException {
+        long value = readAddressValue(address);
+        return (value == 0 ? null : new BsdAddress(this, value));
+    }
+    public BsdAddress readCompOopAddress(long address)
+            throws UnmappedAddressException, UnalignedAddressException {
+        long value = readCompOopAddressValue(address);
+        return (value == 0 ? null : new BsdAddress(this, value));
+    }
+
+    /** From the BsdDebugger interface */
+    public BsdOopHandle readOopHandle(long address)
+            throws UnmappedAddressException, UnalignedAddressException,
+                NotInHeapException {
+        long value = readAddressValue(address);
+        return (value == 0 ? null : new BsdOopHandle(this, value));
+    }
+    public BsdOopHandle readCompOopHandle(long address)
+            throws UnmappedAddressException, UnalignedAddressException,
+                NotInHeapException {
+        long value = readCompOopAddressValue(address);
+        return (value == 0 ? null : new BsdOopHandle(this, value));
+    }
+
+    //----------------------------------------------------------------------
+    // Thread context access
+    //
+
+    public synchronized long[] getThreadIntegerRegisterSet(int lwp_id)
+                                            throws DebuggerException {
+        requireAttach();
+        if (isCore) {
+            return getThreadIntegerRegisterSet0(lwp_id);
+        } else {
+            class GetThreadIntegerRegisterSetTask implements WorkerThreadTask {
+                int lwp_id;
+                long[] result;
+                public void doit(BsdDebuggerLocal debugger) {
+                    result = debugger.getThreadIntegerRegisterSet0(lwp_id);
+                }
+            }
+
+            GetThreadIntegerRegisterSetTask task = new GetThreadIntegerRegisterSetTask();
+            task.lwp_id = lwp_id;
+            workerThread.execute(task);
+            return task.result;
+        }
+    }
+
+    /** Need to override this to relax alignment checks on x86. */
+    public long readCInteger(long address, long numBytes, boolean isUnsigned)
+        throws UnmappedAddressException, UnalignedAddressException {
+        // Only slightly relaxed semantics -- this is a hack, but is
+        // necessary on x86 where it seems the compiler is
+        // putting some global 64-bit data on 32-bit boundaries
+        if (numBytes == 8) {
+            utils.checkAlignment(address, 4);
+        } else {
+            utils.checkAlignment(address, numBytes);
+        }
+        byte[] data = readBytes(address, numBytes);
+        return utils.dataToCInteger(data, isUnsigned);
+    }
+
+    // Overridden from DebuggerBase because we need to relax alignment
+    // constraints on x86
+    public long readJLong(long address)
+        throws UnmappedAddressException, UnalignedAddressException {
+        utils.checkAlignment(address, jintSize);
+        byte[] data = readBytes(address, jlongSize);
+        return utils.dataToJLong(data, jlongSize);
+    }
+
+    //----------------------------------------------------------------------
+    // Address access. Can not be package private, but should only be
+    // accessed by the architecture-specific subpackages.
+
+    /** From the BsdDebugger interface */
+    public long getAddressValue(Address addr) {
+      if (addr == null) return 0;
+      return ((BsdAddress) addr).getValue();
+    }
+
+    /** From the BsdDebugger interface */
+    public Address newAddress(long value) {
+      if (value == 0) return null;
+      return new BsdAddress(this, value);
+    }
+
+    /** From the BsdCDebugger interface */
+    public List/*<ThreadProxy>*/ getThreadList() {
+      requireAttach();
+      return threadList;
+    }
+
+    /** From the BsdCDebugger interface */
+    public List/*<LoadObject>*/ getLoadObjectList() {
+      requireAttach();
+      return loadObjectList;
+    }
+
+    /** From the BsdCDebugger interface */
+    public synchronized ClosestSymbol lookup(long addr) {
+       requireAttach();
+       if (isCore) {
+          return lookupByAddress0(addr);
+       } else {
+          class LookupByAddressTask implements WorkerThreadTask {
+             long addr;
+             ClosestSymbol result;
+
+             public void doit(BsdDebuggerLocal debugger) {
+                 result = debugger.lookupByAddress0(addr);
+             }
+          }
+
+          LookupByAddressTask task = new LookupByAddressTask();
+          task.addr = addr;
+          workerThread.execute(task);
+          return task.result;
+       }
+    }
+
+    public CDebugger getCDebugger() {
+      if (cdbg == null) {
+         String cpu = getCPU();
+         if (cpu.equals("ia64") ) {
+            // IA-64 is not supported because of stack-walking issues
+            return null;
+         }
+         cdbg = new BsdCDebugger(this);
+      }
+      return cdbg;
+    }
+
+    /** This reads bytes from the remote process. */
+    public synchronized ReadResult readBytesFromProcess(long address,
+            long numBytes) throws UnmappedAddressException, DebuggerException {
+        requireAttach();
+        if (isCore) {
+            byte[] res = readBytesFromProcess0(address, numBytes);
+            return (res != null)? new ReadResult(res) : new ReadResult(address);
+        } else {
+            class ReadBytesFromProcessTask implements WorkerThreadTask {
+                long address, numBytes;
+                ReadResult result;
+                public void doit(BsdDebuggerLocal debugger) {
+                    byte[] res = debugger.readBytesFromProcess0(address, numBytes);
+                    if (res != null)
+                        result = new ReadResult(res);
+                    else
+                        result = new ReadResult(address);
+                }
+            }
+
+            ReadBytesFromProcessTask task = new ReadBytesFromProcessTask();
+            task.address = address;
+            task.numBytes = numBytes;
+            workerThread.execute(task);
+            return task.result;
+        }
+    }
+
+    public void writeBytesToProcess(long address, long numBytes, byte[] data)
+        throws UnmappedAddressException, DebuggerException {
+        // FIXME
+        throw new DebuggerException("Unimplemented");
+    }
+
+    static {
+        System.loadLibrary("saproc");
+        init0();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdOopHandle.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2002, 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.debugger.bsd;
+
+import sun.jvm.hotspot.debugger.*;
+
+class BsdOopHandle extends BsdAddress implements OopHandle {
+  BsdOopHandle(BsdDebugger debugger, long addr) {
+    super(debugger, addr);
+  }
+
+  public boolean equals(Object arg) {
+    if (arg == null) {
+      return false;
+    }
+
+    if (!(arg instanceof BsdOopHandle)) {
+      return false;
+    }
+
+    return (addr == ((BsdAddress) arg).addr);
+  }
+
+  public Address    addOffsetTo       (long offset) throws UnsupportedOperationException {
+    throw new UnsupportedOperationException("addOffsetTo not applicable to OopHandles (interior object pointers not allowed)");
+  }
+
+  public Address    andWithMask(long mask) throws UnsupportedOperationException {
+    throw new UnsupportedOperationException("andWithMask not applicable to OopHandles (i.e., anything but C addresses)");
+  }
+
+  public Address    orWithMask(long mask) throws UnsupportedOperationException {
+    throw new UnsupportedOperationException("orWithMask not applicable to OopHandles (i.e., anything but C addresses)");
+  }
+
+  public Address    xorWithMask(long mask) throws UnsupportedOperationException {
+    throw new UnsupportedOperationException("xorWithMask not applicable to OopHandles (i.e., anything but C addresses)");
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThread.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2002, 2003, 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.debugger.bsd;
+
+import sun.jvm.hotspot.debugger.*;
+
+class BsdThread implements ThreadProxy {
+    private BsdDebugger debugger;
+    private int           lwp_id;
+
+    /** The address argument must be the address of the _thread_id in the
+        OSThread. It's value is result ::gettid() call. */
+    BsdThread(BsdDebugger debugger, Address addr) {
+        this.debugger = debugger;
+        // FIXME: size of data fetched here should be configurable.
+        // However, making it so would produce a dependency on the "types"
+        // package from the debugger package, which is not desired.
+        this.lwp_id = (int) addr.getCIntegerAt(0, 4, true);
+    }
+
+    BsdThread(BsdDebugger debugger, long id) {
+        this.debugger = debugger;
+        this.lwp_id = (int) id;
+    }
+
+    public boolean equals(Object obj) {
+        if ((obj == null) || !(obj instanceof BsdThread)) {
+            return false;
+        }
+
+        return (((BsdThread) obj).lwp_id == lwp_id);
+    }
+
+    public int hashCode() {
+        return lwp_id;
+    }
+
+    public String toString() {
+        return Integer.toString(lwp_id);
+    }
+
+    public ThreadContext getContext() throws IllegalThreadStateException {
+        long[] data = debugger.getThreadIntegerRegisterSet(lwp_id);
+        ThreadContext context = BsdThreadContextFactory.createThreadContext(debugger);
+        for (int i = 0; i < data.length; i++) {
+            context.setRegister(i, data[i]);
+        }
+        return context;
+    }
+
+    public boolean canSetContext() throws DebuggerException {
+        return false;
+    }
+
+    public void setContext(ThreadContext context)
+      throws IllegalThreadStateException, DebuggerException {
+        throw new DebuggerException("Unimplemented");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThreadContextFactory.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2002, 2006, 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.debugger.bsd;
+
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.bsd.amd64.*;
+import sun.jvm.hotspot.debugger.bsd.x86.*;
+
+class BsdThreadContextFactory {
+   static ThreadContext createThreadContext(BsdDebugger dbg) {
+      String cpu = dbg.getCPU();
+      if (cpu.equals("x86")) {
+         return new BsdX86ThreadContext(dbg);
+      } else if (cpu.equals("amd64")) {
+         return new BsdAMD64ThreadContext(dbg);
+      } else {
+         throw new RuntimeException("cpu " + cpu + " is not yet supported");
+      }
+   }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/SharedObject.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2003, 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.debugger.bsd;
+
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.cdbg.*;
+import sun.jvm.hotspot.debugger.posix.*;
+
+/** A Object can represent either a .so or an a.out file. */
+
+class SharedObject extends DSO {
+  SharedObject(BsdDebugger dbg, String filename, long size, Address relocation) {
+    super(filename, size, relocation);
+    this.dbg     = dbg;
+  }
+
+  protected Address newAddress(long address) {
+    return dbg.newAddress(address);
+  }
+
+  protected long getAddressValue(Address addr) {
+    return dbg.getAddressValue(addr);
+  }
+
+  private BsdDebugger   dbg;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/amd64/BsdAMD64CFrame.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2003, 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.debugger.bsd.amd64;
+
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.bsd.*;
+import sun.jvm.hotspot.debugger.cdbg.*;
+import sun.jvm.hotspot.debugger.cdbg.basic.*;
+
+final public class BsdAMD64CFrame extends BasicCFrame {
+   public BsdAMD64CFrame(BsdDebugger dbg, Address rbp, Address rip) {
+      super(dbg.getCDebugger());
+      this.rbp = rbp;
+      this.rip = rip;
+      this.dbg = dbg;
+   }
+
+   // override base class impl to avoid ELF parsing
+   public ClosestSymbol closestSymbolToPC() {
+      // try native lookup in debugger.
+      return dbg.lookup(dbg.getAddressValue(pc()));
+   }
+
+   public Address pc() {
+      return rip;
+   }
+
+   public Address localVariableBase() {
+      return rbp;
+   }
+
+   public CFrame sender() {
+      if (rbp == null) {
+        return null;
+      }
+
+      Address nextRBP = rbp.getAddressAt( 0 * ADDRESS_SIZE);
+      if (nextRBP == null) {
+        return null;
+      }
+      Address nextPC  = rbp.getAddressAt( 1 * ADDRESS_SIZE);
+      if (nextPC == null) {
+        return null;
+      }
+      return new BsdAMD64CFrame(dbg, nextRBP, nextPC);
+   }
+
+   // package/class internals only
+   private static final int ADDRESS_SIZE = 8;
+   private Address rip;
+   private Address rbp;
+   private BsdDebugger dbg;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/amd64/BsdAMD64ThreadContext.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2003, 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.debugger.bsd.amd64;
+
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.amd64.*;
+import sun.jvm.hotspot.debugger.bsd.*;
+
+public class BsdAMD64ThreadContext extends AMD64ThreadContext {
+  private BsdDebugger debugger;
+
+  public BsdAMD64ThreadContext(BsdDebugger debugger) {
+    super();
+    this.debugger = debugger;
+  }
+
+  public void setRegisterAsAddress(int index, Address value) {
+    setRegister(index, debugger.getAddressValue(value));
+  }
+
+  public Address getRegisterAsAddress(int index) {
+    return debugger.newAddress(getRegister(index));
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/x86/BsdX86CFrame.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2003, 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.debugger.bsd.x86;
+
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.bsd.*;
+import sun.jvm.hotspot.debugger.cdbg.*;
+import sun.jvm.hotspot.debugger.cdbg.basic.*;
+
+final public class BsdX86CFrame extends BasicCFrame {
+   // package/class internals only
+   public BsdX86CFrame(BsdDebugger dbg, Address ebp, Address pc) {
+      super(dbg.getCDebugger());
+      this.ebp = ebp;
+      this.pc = pc;
+      this.dbg = dbg;
+   }
+
+   // override base class impl to avoid ELF parsing
+   public ClosestSymbol closestSymbolToPC() {
+      // try native lookup in debugger.
+      return dbg.lookup(dbg.getAddressValue(pc()));
+   }
+
+   public Address pc() {
+      return pc;
+   }
+
+   public Address localVariableBase() {
+      return ebp;
+   }
+
+   public CFrame sender() {
+      if (ebp == null) {
+        return null;
+      }
+
+      Address nextEBP = ebp.getAddressAt( 0 * ADDRESS_SIZE);
+      if (nextEBP == null) {
+        return null;
+      }
+      Address nextPC  = ebp.getAddressAt( 1 * ADDRESS_SIZE);
+      if (nextPC == null) {
+        return null;
+      }
+      return new BsdX86CFrame(dbg, nextEBP, nextPC);
+   }
+
+   private static final int ADDRESS_SIZE = 4;
+   private Address pc;
+   private Address ebp;
+   private BsdDebugger dbg;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/x86/BsdX86ThreadContext.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2003, 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.debugger.bsd.x86;
+
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.x86.*;
+import sun.jvm.hotspot.debugger.bsd.*;
+
+public class BsdX86ThreadContext extends X86ThreadContext {
+  private BsdDebugger debugger;
+
+  public BsdX86ThreadContext(BsdDebugger debugger) {
+    super();
+    this.debugger = debugger;
+  }
+
+  public void setRegisterAsAddress(int index, Address value) {
+    setRegister(index, debugger.getAddressValue(value));
+  }
+
+  public Address getRegisterAsAddress(int index) {
+    return debugger.newAddress(getRegister(index));
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/gc_implementation/g1/G1CollectedHeap.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2011, 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.gc_interface.CollectedHeapName;
+import sun.jvm.hotspot.memory.MemRegion;
+import sun.jvm.hotspot.memory.SharedHeap;
+import sun.jvm.hotspot.memory.SpaceClosure;
+import sun.jvm.hotspot.runtime.VM;
+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 G1CollectedHeap.
+
+public class G1CollectedHeap extends SharedHeap {
+    // HeapRegionSeq _seq;
+    static private long hrsFieldOffset;
+    // MemRegion _g1_committed;
+    static private long g1CommittedFieldOffset;
+    // size_t _summary_bytes_used;
+    static private CIntegerField summaryBytesUsedField;
+    // G1MonitoringSupport* _g1mm
+    static private AddressField g1mmField;
+
+    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("G1CollectedHeap");
+
+        hrsFieldOffset = type.getField("_hrs").getOffset();
+        g1CommittedFieldOffset = type.getField("_g1_committed").getOffset();
+        summaryBytesUsedField = type.getCIntegerField("_summary_bytes_used");
+        g1mmField = type.getAddressField("_g1mm");
+    }
+
+    public long capacity() {
+        Address g1CommittedAddr = addr.addOffsetTo(g1CommittedFieldOffset);
+        MemRegion g1_committed = new MemRegion(g1CommittedAddr);
+        return g1_committed.byteSize();
+    }
+
+    public long used() {
+        return summaryBytesUsedField.getValue(addr);
+    }
+
+    public long n_regions() {
+        return hrs().length();
+    }
+
+    private HeapRegionSeq hrs() {
+        Address hrsAddr = addr.addOffsetTo(hrsFieldOffset);
+        return (HeapRegionSeq) VMObjectFactory.newObject(HeapRegionSeq.class,
+                                                         hrsAddr);
+    }
+
+    public G1MonitoringSupport g1mm() {
+        Address g1mmAddr = g1mmField.getValue(addr);
+        return (G1MonitoringSupport) VMObjectFactory.newObject(G1MonitoringSupport.class, g1mmAddr);
+    }
+
+    private Iterator<HeapRegion> heapRegionIterator() {
+        return hrs().heapRegionIterator();
+    }
+
+    public void heapRegionIterate(SpaceClosure scl) {
+        Iterator<HeapRegion> iter = heapRegionIterator();
+        while (iter.hasNext()) {
+            HeapRegion hr = iter.next();
+            scl.doSpace(hr);
+        }
+    }
+
+    public CollectedHeapName kind() {
+        return CollectedHeapName.G1_COLLECTED_HEAP;
+    }
+
+    public G1CollectedHeap(Address addr) {
+        super(addr);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/gc_implementation/g1/G1MonitoringSupport.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2011, 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.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.types.CIntegerField;
+import sun.jvm.hotspot.types.Type;
+import sun.jvm.hotspot.types.TypeDataBase;
+
+// Mirror class for G1MonitoringSupport.
+
+public class G1MonitoringSupport extends VMObject {
+    // size_t _eden_committed;
+    static private CIntegerField edenCommittedField;
+    // size_t _eden_used;
+    static private CIntegerField edenUsedField;
+    // size_t _survivor_committed;
+    static private CIntegerField survivorCommittedField;
+    // size_t _survivor_used;
+    static private CIntegerField survivorUsedField;
+    // size_t _old_committed;
+    static private CIntegerField oldCommittedField;
+    // size_t _old_used;
+    static private CIntegerField oldUsedField;
+
+    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("G1MonitoringSupport");
+
+        edenCommittedField = type.getCIntegerField("_eden_committed");
+        edenUsedField = type.getCIntegerField("_eden_used");
+        survivorCommittedField = type.getCIntegerField("_survivor_committed");
+        survivorUsedField = type.getCIntegerField("_survivor_used");
+        oldCommittedField = type.getCIntegerField("_old_committed");
+        oldUsedField = type.getCIntegerField("_old_used");
+    }
+
+    public long edenCommitted() {
+        return edenCommittedField.getValue(addr);
+    }
+
+    public long edenUsed() {
+        return edenUsedField.getValue(addr);
+    }
+
+    public long survivorCommitted() {
+        return survivorCommittedField.getValue(addr);
+    }
+
+    public long survivorUsed() {
+        return survivorUsedField.getValue(addr);
+    }
+
+    public long oldCommitted() {
+        return oldCommittedField.getValue(addr);
+    }
+
+    public long oldUsed() {
+        return oldUsedField.getValue(addr);
+    }
+
+    public G1MonitoringSupport(Address addr) {
+        super(addr);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/gc_implementation/g1/HeapRegion.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2011, 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.Observable;
+import java.util.Observer;
+
+import sun.jvm.hotspot.debugger.Address;
+import sun.jvm.hotspot.memory.ContiguousSpace;
+import sun.jvm.hotspot.runtime.VM;
+import sun.jvm.hotspot.types.CIntegerField;
+import sun.jvm.hotspot.types.Type;
+import sun.jvm.hotspot.types.TypeDataBase;
+
+// Mirror class for HeapRegion. Currently we don't actually include
+// any of its fields but only iterate over it (which we get "for free"
+// as HeapRegion ultimately inherits from ContiguousSpace).
+
+public class HeapRegion extends ContiguousSpace {
+    // static int GrainBytes;
+    static private CIntegerField grainBytesField;
+
+    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("HeapRegion");
+
+        grainBytesField = type.getCIntegerField("GrainBytes");
+    }
+
+    static public long grainBytes() {
+        return grainBytesField.getValue();
+    }
+
+    public HeapRegion(Address addr) {
+        super(addr);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/gc_implementation/g1/HeapRegionSeq.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2011, 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 HeapRegionSeq. It's essentially an index -> HeapRegion map.
+
+public class HeapRegionSeq extends VMObject {
+    // HeapRegion** _regions;
+    static private AddressField regionsField;
+    // size_t _length;
+    static private CIntegerField lengthField;
+
+    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("HeapRegionSeq");
+
+        regionsField = type.getAddressField("_regions");
+        lengthField = type.getCIntegerField("_length");
+    }
+
+    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);
+    }
+
+    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();
+        }
+    }
+
+    public Iterator<HeapRegion> heapRegionIterator() {
+        return new HeapRegionIterator(addr);
+    }
+
+    public HeapRegionSeq(Address addr) {
+        super(addr);
+    }
+}
--- a/agent/src/share/classes/sun/jvm/hotspot/gc_interface/CollectedHeapName.java	Wed Oct 26 12:43:05 2011 -0700
+++ b/agent/src/share/classes/sun/jvm/hotspot/gc_interface/CollectedHeapName.java	Thu Oct 27 12:21:43 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, 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
@@ -34,6 +34,7 @@
   public static final CollectedHeapName ABSTRACT = new CollectedHeapName("abstract");
   public static final CollectedHeapName SHARED_HEAP = new CollectedHeapName("SharedHeap");
   public static final CollectedHeapName GEN_COLLECTED_HEAP = new CollectedHeapName("GenCollectedHeap");
+  public static final CollectedHeapName G1_COLLECTED_HEAP = new CollectedHeapName("G1CollectedHeap");
   public static final CollectedHeapName PARALLEL_SCAVENGE_HEAP = new CollectedHeapName("ParallelScavengeHeap");
 
   public String toString() {
--- a/agent/src/share/classes/sun/jvm/hotspot/memory/Universe.java	Wed Oct 26 12:43:05 2011 -0700
+++ b/agent/src/share/classes/sun/jvm/hotspot/memory/Universe.java	Thu Oct 27 12:21:43 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, 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
@@ -28,6 +28,7 @@
 import java.util.*;
 import sun.jvm.hotspot.debugger.*;
 import sun.jvm.hotspot.gc_interface.*;
+import sun.jvm.hotspot.gc_implementation.g1.G1CollectedHeap;
 import sun.jvm.hotspot.gc_implementation.parallelScavenge.*;
 import sun.jvm.hotspot.oops.*;
 import sun.jvm.hotspot.types.*;
@@ -72,6 +73,7 @@
     heapConstructor = new VirtualConstructor(db);
     heapConstructor.addMapping("GenCollectedHeap", GenCollectedHeap.class);
     heapConstructor.addMapping("ParallelScavengeHeap", ParallelScavengeHeap.class);
+    heapConstructor.addMapping("G1CollectedHeap", G1CollectedHeap.class);
 
     mainThreadGroupField   = type.getOopField("_main_thread_group");
     systemThreadGroupField = type.getOopField("_system_thread_group");
--- a/agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java	Wed Oct 26 12:43:05 2011 -0700
+++ b/agent/src/share/classes/sun/jvm/hotspot/oops/InstanceKlass.java	Thu Oct 27 12:21:43 2011 -0700
@@ -44,14 +44,14 @@
   }
 
   // field offset constants
-  public static int ACCESS_FLAGS_OFFSET;
-  public static int NAME_INDEX_OFFSET;
-  public static int SIGNATURE_INDEX_OFFSET;
-  public static int INITVAL_INDEX_OFFSET;
-  public static int LOW_OFFSET;
-  public static int HIGH_OFFSET;
-  public static int GENERIC_SIGNATURE_INDEX_OFFSET;
-  public static int FIELD_SLOTS;
+  private static int ACCESS_FLAGS_OFFSET;
+  private static int NAME_INDEX_OFFSET;
+  private static int SIGNATURE_INDEX_OFFSET;
+  private static int INITVAL_INDEX_OFFSET;
+  private static int LOW_OFFSET;
+  private static int HIGH_OFFSET;
+  private static int GENERIC_SIGNATURE_INDEX_OFFSET;
+  private static int FIELD_SLOTS;
   public static int IMPLEMENTORS_LIMIT;
 
   // ClassState constants
@@ -122,6 +122,13 @@
 
   InstanceKlass(OopHandle handle, ObjectHeap heap) {
     super(handle, heap);
+    if (getJavaFieldsCount() != getAllFieldsCount()) {
+      // Exercise the injected field logic
+      for (int i = getJavaFieldsCount(); i < getAllFieldsCount(); i++) {
+        getFieldName(i);
+        getFieldSignature(i);
+      }
+    }
   }
 
   private static OopField  arrayKlasses;
@@ -253,24 +260,51 @@
     return getFields().getShortAt(index * FIELD_SLOTS + ACCESS_FLAGS_OFFSET);
   }
 
+  public short getFieldNameIndex(int index) {
+    if (index >= getJavaFieldsCount()) throw new IndexOutOfBoundsException("not a Java field;");
+    return getFields().getShortAt(index * FIELD_SLOTS + NAME_INDEX_OFFSET);
+  }
+
   public Symbol getFieldName(int index) {
     int nameIndex = getFields().getShortAt(index * FIELD_SLOTS + NAME_INDEX_OFFSET);
-    return getConstants().getSymbolAt(nameIndex);
+    if (index < getJavaFieldsCount()) {
+      return getConstants().getSymbolAt(nameIndex);
+    } else {
+      return vmSymbols.symbolAt(nameIndex);
+    }
+  }
+
+  public short getFieldSignatureIndex(int index) {
+    if (index >= getJavaFieldsCount()) throw new IndexOutOfBoundsException("not a Java field;");
+    return getFields().getShortAt(index * FIELD_SLOTS + SIGNATURE_INDEX_OFFSET);
   }
 
   public Symbol getFieldSignature(int index) {
     int signatureIndex = getFields().getShortAt(index * FIELD_SLOTS + SIGNATURE_INDEX_OFFSET);
-    return getConstants().getSymbolAt(signatureIndex);
+    if (index < getJavaFieldsCount()) {
+      return getConstants().getSymbolAt(signatureIndex);
+    } else {
+      return vmSymbols.symbolAt(signatureIndex);
+    }
+  }
+
+  public short getFieldGenericSignatureIndex(int index) {
+    return getFields().getShortAt(index * FIELD_SLOTS + GENERIC_SIGNATURE_INDEX_OFFSET);
   }
 
   public Symbol getFieldGenericSignature(int index) {
-    short genericSignatureIndex = getFields().getShortAt(index * FIELD_SLOTS + GENERIC_SIGNATURE_INDEX_OFFSET);
+    short genericSignatureIndex = getFieldGenericSignatureIndex(index);
     if (genericSignatureIndex != 0)  {
       return getConstants().getSymbolAt(genericSignatureIndex);
     }
     return null;
   }
 
+  public short getFieldInitialValueIndex(int index) {
+    if (index >= getJavaFieldsCount()) throw new IndexOutOfBoundsException("not a Java field;");
+    return getFields().getShortAt(index * FIELD_SLOTS + INITVAL_INDEX_OFFSET);
+  }
+
   public int getFieldOffset(int index) {
     TypeArray fields = getFields();
     return VM.getVM().buildIntFromShorts(fields.getShortAt(index * FIELD_SLOTS + LOW_OFFSET),
@@ -288,7 +322,7 @@
   public Klass     getImplementor(int i)    { return (Klass)        implementors[i].getValue(this); }
   public TypeArray getFields()              { return (TypeArray)    fields.getValue(this); }
   public int       getJavaFieldsCount()     { return                (int) javaFieldsCount.getValue(this); }
-  public int       getAllFieldsCount()      { return                (int)getFields().getLength(); }
+  public int       getAllFieldsCount()      { return                (int)getFields().getLength() / FIELD_SLOTS; }
   public ConstantPool getConstants()        { return (ConstantPool) constants.getValue(this); }
   public Oop       getClassLoader()         { return                classLoader.getValue(this); }
   public Oop       getProtectionDomain()    { return                protectionDomain.getValue(this); }
@@ -511,7 +545,6 @@
   }
 
   void iterateStaticFieldsInternal(OopVisitor visitor) {
-    TypeArray fields = getFields();
     int length = getJavaFieldsCount();
     for (int index = 0; index < length; index++) {
       short accessFlags    = getFieldAccessFlags(index);
@@ -541,8 +574,6 @@
     if (getSuper() != null) {
       ((InstanceKlass) getSuper()).iterateNonStaticFields(visitor, obj);
     }
-    TypeArray fields = getFields();
-
     int length = getJavaFieldsCount();
     for (int index = 0; index < length; index++) {
       short accessFlags    = getFieldAccessFlags(index);
@@ -556,9 +587,7 @@
 
   /** Field access by name. */
   public Field findLocalField(Symbol name, Symbol sig) {
-    TypeArray fields = getFields();
-    int length = (int) fields.getLength();
-    ConstantPool cp = getConstants();
+    int length = getJavaFieldsCount();
     for (int i = 0; i < length; i++) {
       Symbol f_name = getFieldName(i);
       Symbol f_sig  = getFieldSignature(i);
@@ -648,8 +677,6 @@
     public List getImmediateFields() {
         // A list of Fields for each field declared in this class/interface,
         // not including inherited fields.
-        TypeArray fields = getFields();
-
         int length = getJavaFieldsCount();
         List immediateFields = new ArrayList(length);
         for (int index = 0; index < length; index++) {
@@ -839,7 +866,6 @@
 
   // Creates new field from index in fields TypeArray
   private Field newField(int index) {
-    TypeArray fields = getFields();
     FieldType type = new FieldType(getFieldSignature(index));
     if (type.isOop()) {
      if (VM.getVM().isCompressedOopsEnabled()) {
--- a/agent/src/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java	Wed Oct 26 12:43:05 2011 -0700
+++ b/agent/src/share/classes/sun/jvm/hotspot/oops/ObjectHeap.java	Thu Oct 27 12:21:43 2011 -0700
@@ -33,6 +33,7 @@
 
 import sun.jvm.hotspot.debugger.*;
 import sun.jvm.hotspot.gc_interface.*;
+import sun.jvm.hotspot.gc_implementation.g1.*;
 import sun.jvm.hotspot.gc_implementation.parallelScavenge.*;
 import sun.jvm.hotspot.memory.*;
 import sun.jvm.hotspot.runtime.*;
@@ -514,9 +515,16 @@
 
   private void addPermGenLiveRegions(List output, CollectedHeap heap) {
     LiveRegionsCollector lrc = new LiveRegionsCollector(output);
-    if (heap instanceof GenCollectedHeap) {
-       GenCollectedHeap genHeap = (GenCollectedHeap) heap;
-       Generation gen = genHeap.permGen();
+    if (heap instanceof SharedHeap) {
+       if (Assert.ASSERTS_ENABLED) {
+          Assert.that(heap instanceof GenCollectedHeap ||
+                      heap instanceof G1CollectedHeap,
+                      "Expecting GenCollectedHeap or G1CollectedHeap, " +
+                      "but got " + heap.getClass().getName());
+       }
+       // Handles both GenCollectedHeap and G1CollectedHeap
+       SharedHeap sharedHeap = (SharedHeap) heap;
+       Generation gen = sharedHeap.permGen();
        gen.spaceIterate(lrc, true);
     } else if (heap instanceof ParallelScavengeHeap) {
        ParallelScavengeHeap psh = (ParallelScavengeHeap) heap;
@@ -524,8 +532,9 @@
        addLiveRegions(permGen.objectSpace().getLiveRegions(), output);
     } else {
        if (Assert.ASSERTS_ENABLED) {
-          Assert.that(false, "Expecting GenCollectedHeap or ParallelScavengeHeap, but got " +
-                             heap.getClass().getName());
+          Assert.that(false,
+                      "Expecting SharedHeap or ParallelScavengeHeap, " +
+                      "but got " + heap.getClass().getName());
        }
     }
   }
@@ -588,10 +597,14 @@
        addLiveRegions(youngGen.fromSpace().getLiveRegions(), liveRegions);
        PSOldGen oldGen = psh.oldGen();
        addLiveRegions(oldGen.objectSpace().getLiveRegions(), liveRegions);
+    } else if (heap instanceof G1CollectedHeap) {
+        G1CollectedHeap g1h = (G1CollectedHeap) heap;
+        g1h.heapRegionIterate(lrc);
     } else {
        if (Assert.ASSERTS_ENABLED) {
-          Assert.that(false, "Expecting GenCollectedHeap or ParallelScavengeHeap, but got " +
-                              heap.getClass().getName());
+          Assert.that(false, "Expecting GenCollectedHeap, G1CollectedHeap, " +
+                      "or ParallelScavengeHeap, but got " +
+                      heap.getClass().getName());
        }
     }
 
--- a/agent/src/share/classes/sun/jvm/hotspot/runtime/Threads.java	Wed Oct 26 12:43:05 2011 -0700
+++ b/agent/src/share/classes/sun/jvm/hotspot/runtime/Threads.java	Thu Oct 27 12:21:43 2011 -0700
@@ -37,6 +37,8 @@
 import sun.jvm.hotspot.runtime.linux_ia64.LinuxIA64JavaThreadPDAccess;
 import sun.jvm.hotspot.runtime.linux_amd64.LinuxAMD64JavaThreadPDAccess;
 import sun.jvm.hotspot.runtime.linux_sparc.LinuxSPARCJavaThreadPDAccess;
+import sun.jvm.hotspot.runtime.bsd_x86.BsdX86JavaThreadPDAccess;
+import sun.jvm.hotspot.runtime.bsd_amd64.BsdAMD64JavaThreadPDAccess;
 import sun.jvm.hotspot.utilities.*;
 
 public class Threads {
@@ -90,7 +92,12 @@
             } else if (cpu.equals("sparc")) {
                 access = new LinuxSPARCJavaThreadPDAccess();
             }
-
+        } else if (os.equals("bsd")) {
+            if (cpu.equals("x86")) {
+                access = new BsdX86JavaThreadPDAccess();
+            } else if (cpu.equals("amd64")) {
+                access = new BsdAMD64JavaThreadPDAccess();
+            }
         }
 
         if (access == null) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd/BsdSignals.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2003, 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.runtime.bsd;
+
+public class BsdSignals {
+  private static String[] signalNames = {
+    "",           /* No signal 0 */
+    "SIGHUP",     /* hangup */
+    "SIGINT",     /* interrupt */
+    "SIGQUIT",    /* quit */
+    "SIGILL",     /* illegal instr. (not reset when caught) */
+    "SIGTRAP",    /* trace trap (not reset when caught) */
+    "SIGABRT",    /* abort() */
+    "SIGEMT",     /* EMT instruction */
+    "SIGFPE",     /* floating point exception */
+    "SIGKILL",    /* kill (cannot be caught or ignored) */
+    "SIGBUS",     /* bus error */
+    "SIGSEGV",    /* segmentation violation */
+    "SIGSYS",     /* non-existent system call invoked */
+    "SIGPIPE",    /* write on a pipe with no one to read it */
+    "SIGALRM",    /* alarm clock */
+    "SIGTERM",    /* software termination signal from kill */
+    "SIGURG",     /* urgent condition on IO channel */
+    "SIGSTOP",    /* sendable stop signal not from tty */
+    "SIGTSTP",    /* stop signal from tty */
+    "SIGCONT",    /* continue a stopped process */
+    "SIGCHLD",    /* to parent on child stop or exit */
+    "SIGTTIN",    /* to readers pgrp upon background tty read */
+    "SIGTTOU",    /* like TTIN if (tp->t_local&LTOSTOP) */
+    "SIGIO",      /* input/output possible signal */
+    "SIGXCPU",    /* exceeded CPU time limit */
+    "SIGXFSZ",    /* exceeded file size limit */
+    "SIGVTALRM",  /* virtual time alarm */
+    "SIGPROF",    /* profiling time alarm */
+    "SIGWINCH",   /* window size changes */
+    "SIGINFO",    /* information request */
+    "SIGUSR1",    /* user defined signal 1 */
+    "SIGUSR2"     /* user defined signal 2 */
+  };
+
+  public static String getSignalName(int sigNum) {
+    if ((sigNum <= 0) || (sigNum >= signalNames.length)) {
+      // Probably best to fail in a non-destructive way
+      return "<Error: Illegal signal number " + sigNum + ">";
+    }
+    return signalNames[sigNum];
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_amd64/BsdAMD64JavaThreadPDAccess.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2003, 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.runtime.bsd_amd64;
+
+import java.io.*;
+import java.util.*;
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.amd64.*;
+import sun.jvm.hotspot.runtime.*;
+import sun.jvm.hotspot.runtime.amd64.*;
+import sun.jvm.hotspot.runtime.x86.*;
+import sun.jvm.hotspot.types.*;
+import sun.jvm.hotspot.utilities.*;
+
+public class BsdAMD64JavaThreadPDAccess implements JavaThreadPDAccess {
+  private static AddressField  lastJavaFPField;
+  private static AddressField  osThreadField;
+
+  // Field from OSThread
+  private static CIntegerField osThreadThreadIDField;
+
+  // This is currently unneeded but is being kept in case we change
+  // the currentFrameGuess algorithm
+  private static final long GUESS_SCAN_RANGE = 128 * 1024;
+
+  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("JavaThread");
+    osThreadField           = type.getAddressField("_osthread");
+
+    Type anchorType = db.lookupType("JavaFrameAnchor");
+    lastJavaFPField         = anchorType.getAddressField("_last_Java_fp");
+
+    Type osThreadType = db.lookupType("OSThread");
+    osThreadThreadIDField   = osThreadType.getCIntegerField("_thread_id");
+  }
+
+  public    Address getLastJavaFP(Address addr) {
+    return lastJavaFPField.getValue(addr.addOffsetTo(sun.jvm.hotspot.runtime.JavaThread.getAnchorField().getOffset()));
+  }
+
+  public    Address getLastJavaPC(Address addr) {
+    return null;
+  }
+
+  public    Address getBaseOfStackPointer(Address addr) {
+    return null;
+  }
+
+  public    Frame getLastFramePD(JavaThread thread, Address addr) {
+    Address fp = thread.getLastJavaFP();
+    if (fp == null) {
+      return null; // no information
+    }
+    return new X86Frame(thread.getLastJavaSP(), fp);
+  }
+
+  public    RegisterMap newRegisterMap(JavaThread thread, boolean updateMap) {
+    return new X86RegisterMap(thread, updateMap);
+  }
+
+  public    Frame getCurrentFrameGuess(JavaThread thread, Address addr) {
+    ThreadProxy t = getThreadProxy(addr);
+    AMD64ThreadContext context = (AMD64ThreadContext) t.getContext();
+    AMD64CurrentFrameGuess guesser = new AMD64CurrentFrameGuess(context, thread);
+    if (!guesser.run(GUESS_SCAN_RANGE)) {
+      return null;
+    }
+    if (guesser.getPC() == null) {
+      return new X86Frame(guesser.getSP(), guesser.getFP());
+    } else {
+      return new X86Frame(guesser.getSP(), guesser.getFP(), guesser.getPC());
+    }
+  }
+
+  public    void printThreadIDOn(Address addr, PrintStream tty) {
+    tty.print(getThreadProxy(addr));
+  }
+
+  public    void printInfoOn(Address threadAddr, PrintStream tty) {
+    tty.print("Thread id: ");
+    printThreadIDOn(threadAddr, tty);
+//    tty.println("\nPostJavaState: " + getPostJavaState(threadAddr));
+  }
+
+  public    Address getLastSP(Address addr) {
+    ThreadProxy t = getThreadProxy(addr);
+    AMD64ThreadContext context = (AMD64ThreadContext) t.getContext();
+    return context.getRegisterAsAddress(AMD64ThreadContext.RSP);
+  }
+
+  public    ThreadProxy getThreadProxy(Address addr) {
+    // Addr is the address of the JavaThread.
+    // Fetch the OSThread (for now and for simplicity, not making a
+    // separate "OSThread" class in this package)
+    Address osThreadAddr = osThreadField.getValue(addr);
+    // Get the address of the _thread_id from the OSThread
+    Address threadIdAddr = osThreadAddr.addOffsetTo(osThreadThreadIDField.getOffset());
+
+    JVMDebugger debugger = VM.getVM().getDebugger();
+    return debugger.getThreadForIdentifierAddress(threadIdAddr);
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_x86/BsdSignals.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2002, 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.runtime.bsd_x86;
+
+public class BsdSignals {
+  private static String[] signalNames = {
+    "",           /* No signal 0 */
+    "SIGHUP",     /* hangup */
+    "SIGINT",     /* interrupt */
+    "SIGQUIT",    /* quit */
+    "SIGILL",     /* illegal instr. (not reset when caught) */
+    "SIGTRAP",    /* trace trap (not reset when caught) */
+    "SIGABRT",    /* abort() */
+    "SIGEMT",     /* EMT instruction */
+    "SIGFPE",     /* floating point exception */
+    "SIGKILL",    /* kill (cannot be caught or ignored) */
+    "SIGBUS",     /* bus error */
+    "SIGSEGV",    /* segmentation violation */
+    "SIGSYS",     /* non-existent system call invoked */
+    "SIGPIPE",    /* write on a pipe with no one to read it */
+    "SIGALRM",    /* alarm clock */
+    "SIGTERM",    /* software termination signal from kill */
+    "SIGURG",     /* urgent condition on IO channel */
+    "SIGSTOP",    /* sendable stop signal not from tty */
+    "SIGTSTP",    /* stop signal from tty */
+    "SIGCONT",    /* continue a stopped process */
+    "SIGCHLD",    /* to parent on child stop or exit */
+    "SIGTTIN",    /* to readers pgrp upon background tty read */
+    "SIGTTOU",    /* like TTIN if (tp->t_local&LTOSTOP) */
+    "SIGIO",      /* input/output possible signal */
+    "SIGXCPU",    /* exceeded CPU time limit */
+    "SIGXFSZ",    /* exceeded file size limit */
+    "SIGVTALRM",  /* virtual time alarm */
+    "SIGPROF",    /* profiling time alarm */
+    "SIGWINCH",   /* window size changes */
+    "SIGINFO",    /* information request */
+    "SIGUSR1",    /* user defined signal 1 */
+    "SIGUSR2"     /* user defined signal 2 */
+  };
+
+  public static String getSignalName(int sigNum) {
+    if ((sigNum <= 0) || (sigNum >= signalNames.length)) {
+      // Probably best to fail in a non-destructive way
+      return "<Error: Illegal signal number " + sigNum + ">";
+    }
+    return signalNames[sigNum];
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_x86/BsdX86JavaThreadPDAccess.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2002, 2003, 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.runtime.bsd_x86;
+
+import java.io.*;
+import java.util.*;
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.debugger.x86.*;
+import sun.jvm.hotspot.runtime.*;
+import sun.jvm.hotspot.runtime.x86.*;
+import sun.jvm.hotspot.types.*;
+import sun.jvm.hotspot.utilities.*;
+
+public class BsdX86JavaThreadPDAccess implements JavaThreadPDAccess {
+  private static AddressField  lastJavaFPField;
+  private static AddressField  osThreadField;
+
+  // Field from OSThread
+  private static CIntegerField osThreadThreadIDField;
+
+  // This is currently unneeded but is being kept in case we change
+  // the currentFrameGuess algorithm
+  private static final long GUESS_SCAN_RANGE = 128 * 1024;
+
+  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("JavaThread");
+    osThreadField           = type.getAddressField("_osthread");
+
+    Type anchorType = db.lookupType("JavaFrameAnchor");
+    lastJavaFPField         = anchorType.getAddressField("_last_Java_fp");
+
+    Type osThreadType = db.lookupType("OSThread");
+    osThreadThreadIDField   = osThreadType.getCIntegerField("_thread_id");
+  }
+
+  public    Address getLastJavaFP(Address addr) {
+    return lastJavaFPField.getValue(addr.addOffsetTo(sun.jvm.hotspot.runtime.JavaThread.getAnchorField().getOffset()));
+  }
+
+  public    Address getLastJavaPC(Address addr) {
+    return null;
+  }
+
+  public    Address getBaseOfStackPointer(Address addr) {
+    return null;
+  }
+
+  public    Frame getLastFramePD(JavaThread thread, Address addr) {
+    Address fp = thread.getLastJavaFP();
+    if (fp == null) {
+      return null; // no information
+    }
+    return new X86Frame(thread.getLastJavaSP(), fp);
+  }
+
+  public    RegisterMap newRegisterMap(JavaThread thread, boolean updateMap) {
+    return new X86RegisterMap(thread, updateMap);
+  }
+
+  public    Frame getCurrentFrameGuess(JavaThread thread, Address addr) {
+    ThreadProxy t = getThreadProxy(addr);
+    X86ThreadContext context = (X86ThreadContext) t.getContext();
+    X86CurrentFrameGuess guesser = new X86CurrentFrameGuess(context, thread);
+    if (!guesser.run(GUESS_SCAN_RANGE)) {
+      return null;
+    }
+    if (guesser.getPC() == null) {
+      return new X86Frame(guesser.getSP(), guesser.getFP());
+    } else {
+      return new X86Frame(guesser.getSP(), guesser.getFP(), guesser.getPC());
+    }
+  }
+
+  public    void printThreadIDOn(Address addr, PrintStream tty) {
+    tty.print(getThreadProxy(addr));
+  }
+
+  public    void printInfoOn(Address threadAddr, PrintStream tty) {
+    tty.print("Thread id: ");
+    printThreadIDOn(threadAddr, tty);
+//    tty.println("\nPostJavaState: " + getPostJavaState(threadAddr));
+  }
+
+  public    Address getLastSP(Address addr) {
+    ThreadProxy t = getThreadProxy(addr);
+    X86ThreadContext context = (X86ThreadContext) t.getContext();
+    return context.getRegisterAsAddress(X86ThreadContext.ESP);
+  }
+
+  public    ThreadProxy getThreadProxy(Address addr) {
+    // Addr is the address of the JavaThread.
+    // Fetch the OSThread (for now and for simplicity, not making a
+    // separate "OSThread" class in this package)
+    Address osThreadAddr = osThreadField.getValue(addr);
+    // Get the address of the _thread_id from the OSThread
+    Address threadIdAddr = osThreadAddr.addOffsetTo(osThreadThreadIDField.getOffset());
+
+    JVMDebugger debugger = VM.getVM().getDebugger();
+    return debugger.getThreadForIdentifierAddress(threadIdAddr);
+  }
+}
--- a/agent/src/share/classes/sun/jvm/hotspot/runtime/sparc/SPARCFrame.java	Wed Oct 26 12:43:05 2011 -0700
+++ b/agent/src/share/classes/sun/jvm/hotspot/runtime/sparc/SPARCFrame.java	Thu Oct 27 12:21:43 2011 -0700
@@ -956,7 +956,7 @@
     map.makeIntegerRegsUnsaved();
     map.shiftWindow(sp, youngerSP);
     boolean thisFrameAdjustedStack = true;  // I5_savedSP is live in this RF
-    return new SPARCFrame(sp, youngerSP, thisFrameAdjustedStack);
+    return new SPARCFrame(biasSP(sp), biasSP(youngerSP), thisFrameAdjustedStack);
   }
 
   private Frame senderForEntryFrame(RegisterMap regMap) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/agent/src/share/classes/sun/jvm/hotspot/runtime/vmSymbols.java	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2011, 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.runtime;
+
+import java.io.*;
+import java.util.*;
+import sun.jvm.hotspot.debugger.*;
+import sun.jvm.hotspot.memory.*;
+import sun.jvm.hotspot.oops.*;
+import sun.jvm.hotspot.runtime.*;
+import sun.jvm.hotspot.types.*;
+import sun.jvm.hotspot.utilities.*;
+
+
+public class vmSymbols {
+  static {
+    VM.registerVMInitializedObserver(new Observer() {
+        public void update(Observable o, Object data) {
+          initialize(VM.getVM().getTypeDataBase());
+        }
+      });
+  }
+
+  private static Address symbolsAddress;
+  private static int FIRST_SID;
+  private static int SID_LIMIT;
+
+  private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
+    Type type            = db.lookupType("vmSymbols");
+    symbolsAddress       = type.getAddressField("_symbols[0]").getStaticFieldAddress();
+    FIRST_SID            = db.lookupIntConstant("vmSymbols::FIRST_SID");
+    SID_LIMIT            = db.lookupIntConstant("vmSymbols::SID_LIMIT");
+  }
+
+  public static Symbol symbolAt(int id) {
+    if (id < FIRST_SID || id >= SID_LIMIT) throw new IndexOutOfBoundsException("bad SID " + id);
+    return Symbol.create(symbolsAddress.getAddressAt(id * VM.getVM().getAddressSize()));
+  }
+}
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java	Wed Oct 26 12:43:05 2011 -0700
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java	Thu Oct 27 12:21:43 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2011, 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
@@ -26,11 +26,11 @@
 
 import java.util.*;
 import sun.jvm.hotspot.gc_interface.*;
+import sun.jvm.hotspot.gc_implementation.g1.*;
 import sun.jvm.hotspot.gc_implementation.parallelScavenge.*;
 import sun.jvm.hotspot.gc_implementation.shared.*;
 import sun.jvm.hotspot.memory.*;
 import sun.jvm.hotspot.runtime.*;
-import sun.jvm.hotspot.tools.*;
 
 public class HeapSummary extends Tool {
 
@@ -70,32 +70,45 @@
       System.out.println();
       System.out.println("Heap Usage:");
 
-      if (heap instanceof GenCollectedHeap) {
-         GenCollectedHeap genHeap = (GenCollectedHeap) heap;
-         for (int n = 0; n < genHeap.nGens(); n++) {
-            Generation gen = genHeap.getGen(n);
-            if (gen instanceof sun.jvm.hotspot.memory.DefNewGeneration) {
-               System.out.println("New Generation (Eden + 1 Survivor Space):");
-               printGen(gen);
+      if (heap instanceof SharedHeap) {
+         SharedHeap sharedHeap = (SharedHeap) heap;
+         if (sharedHeap instanceof GenCollectedHeap) {
+            GenCollectedHeap genHeap = (GenCollectedHeap) sharedHeap;
+            for (int n = 0; n < genHeap.nGens(); n++) {
+               Generation gen = genHeap.getGen(n);
+               if (gen instanceof sun.jvm.hotspot.memory.DefNewGeneration) {
+                  System.out.println("New Generation (Eden + 1 Survivor Space):");
+                  printGen(gen);
 
-               ContiguousSpace eden = ((DefNewGeneration)gen).eden();
-               System.out.println("Eden Space:");
-               printSpace(eden);
+                  ContiguousSpace eden = ((DefNewGeneration)gen).eden();
+                  System.out.println("Eden Space:");
+                  printSpace(eden);
 
-               ContiguousSpace from = ((DefNewGeneration)gen).from();
-               System.out.println("From Space:");
-               printSpace(from);
+                  ContiguousSpace from = ((DefNewGeneration)gen).from();
+                  System.out.println("From Space:");
+                  printSpace(from);
 
-               ContiguousSpace to = ((DefNewGeneration)gen).to();
-               System.out.println("To Space:");
-               printSpace(to);
-            } else {
-               System.out.println(gen.name() + ":");
-               printGen(gen);
+                  ContiguousSpace to = ((DefNewGeneration)gen).to();
+                  System.out.println("To Space:");
+                  printSpace(to);
+               } else {
+                  System.out.println(gen.name() + ":");
+                  printGen(gen);
+               }
             }
+         } else if (sharedHeap instanceof G1CollectedHeap) {
+             G1CollectedHeap g1h = (G1CollectedHeap) sharedHeap;
+             G1MonitoringSupport g1mm = g1h.g1mm();
+             System.out.println("G1 Young Generation");
+             printG1Space("Eden Space:", g1mm.edenUsed(), g1mm.edenCommitted());
+             printG1Space("From Space:", g1mm.survivorUsed(), g1mm.survivorCommitted());
+             printG1Space("To Space:", 0, 0);
+             printG1Space("G1 Old Generation", g1mm.oldUsed(), g1mm.oldCommitted());
+         } else {
+             throw new RuntimeException("unknown SharedHeap type : " + heap.getClass());
          }
-         // Perm generation
-         Generation permGen = genHeap.permGen();
+         // Perm generation shared by the above
+         Generation permGen = sharedHeap.permGen();
          System.out.println("Perm Generation:");
          printGen(permGen);
       } else if (heap instanceof ParallelScavengeHeap) {
@@ -119,7 +132,7 @@
          printValMB("free     = ", permFree);
          System.out.println(alignment + (double)permGen.used() * 100.0 / permGen.capacity() + "% used");
       } else {
-         throw new RuntimeException("unknown heap type : " + heap.getClass());
+         throw new RuntimeException("unknown CollectedHeap type : " + heap.getClass());
       }
    }
 
@@ -151,6 +164,14 @@
           return;
        }
 
+       l = getFlagValue("UseG1GC", flagMap);
+       if (l == 1L) {
+           System.out.print("Garbage-First (G1) GC ");
+           l = getFlagValue("ParallelGCThreads", flagMap);
+           System.out.println("with " + l + " thread(s)");
+           return;
+       }
+
        System.out.println("Mark Sweep Compact GC");
    }
 
@@ -191,6 +212,16 @@
       System.out.println(alignment +  (double)space.used() * 100.0 / space.capacity() + "% used");
    }
 
+   private void printG1Space(String spaceName, long used, long capacity) {
+      long free = capacity - used;
+      System.out.println(spaceName);
+      printValMB("capacity = ", capacity);
+      printValMB("used     = ", used);
+      printValMB("free     = ", free);
+      double occPerc = (capacity > 0) ? (double) used * 100.0 / capacity : 0.0;
+      System.out.println(alignment + occPerc + "% used");
+   }
+
    private static final double FACTOR = 1024*1024;
    private void printValMB(String title, long value) {
       if (value < 0) {
--- a/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassWriter.java	Wed Oct 26 12:43:05 2011 -0700
+++ b/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassWriter.java	Thu Oct 27 12:21:43 2011 -0700
@@ -379,23 +379,21 @@
     }
 
     protected void writeFields() throws IOException {
-        TypeArray fields = klass.getFields();
         final int length = klass.getJavaFieldsCount();
 
         // write number of fields
-        dos.writeShort((short) (length / InstanceKlass.FIELD_SLOTS) );
+        dos.writeShort((short) length);
 
-        if (DEBUG) debugMessage("number of fields = "
-                                + length/InstanceKlass.FIELD_SLOTS);
+        if (DEBUG) debugMessage("number of fields = " + length);
 
-        for (int index = 0; index < length; index += InstanceKlass.FIELD_SLOTS) {
-            short accessFlags    = fields.getShortAt(index + InstanceKlass.ACCESS_FLAGS_OFFSET);
+        for (int index = 0; index < length; index++) {
+            short accessFlags    = klass.getFieldAccessFlags(index);
             dos.writeShort(accessFlags & (short) JVM_RECOGNIZED_FIELD_MODIFIERS);
 
-            short nameIndex    = fields.getShortAt(index + InstanceKlass.NAME_INDEX_OFFSET);
+            short nameIndex    = klass.getFieldNameIndex(index);
             dos.writeShort(nameIndex);
 
-            short signatureIndex = fields.getShortAt(index + InstanceKlass.SIGNATURE_INDEX_OFFSET);
+            short signatureIndex = klass.getFieldSignatureIndex(index);
             dos.writeShort(signatureIndex);
             if (DEBUG) debugMessage("\tfield name = " + nameIndex + ", signature = " + signatureIndex);
 
@@ -404,11 +402,11 @@
             if (hasSyn)
                 fieldAttributeCount++;
 
-            short initvalIndex = fields.getShortAt(index + InstanceKlass.INITVAL_INDEX_OFFSET);
+            short initvalIndex = klass.getFieldInitialValueIndex(index);
             if (initvalIndex != 0)
                 fieldAttributeCount++;
 
-            short genSigIndex = fields.getShortAt(index + InstanceKlass.GENERIC_SIGNATURE_INDEX_OFFSET);
+            short genSigIndex = klass.getFieldGenericSignatureIndex(index);
             if (genSigIndex != 0)
                 fieldAttributeCount++;
 
--- a/agent/src/share/classes/sun/jvm/hotspot/utilities/PlatformInfo.java	Wed Oct 26 12:43:05 2011 -0700
+++ b/agent/src/share/classes/sun/jvm/hotspot/utilities/PlatformInfo.java	Thu Oct 27 12:21:43 2011 -0700
@@ -37,6 +37,14 @@
       return "solaris";
     } else if (os.equals("Linux")) {
       return "linux";
+    } else if (os.equals("FreeBSD")) {
+      return "bsd";
+    } else if (os.equals("NetBSD")) {
+      return "bsd";
+    } else if (os.equals("OpenBSD")) {
+      return "bsd";
+    } else if (os.equals("Darwin") || os.startsWith("Mac OS X")) {
+      return "bsd";
     } else if (os.startsWith("Windows")) {
       return "win32";
     } else {
--- a/make/Makefile	Wed Oct 26 12:43:05 2011 -0700
+++ b/make/Makefile	Thu Oct 27 12:21:43 2011 -0700
@@ -323,28 +323,42 @@
 ifneq ($(OSNAME),windows)
   ifeq ($(ZERO_BUILD), true)
     ifeq ($(SHARK_BUILD), true)
-$(EXPORT_JRE_LIB_ARCH_DIR)/%.so: $(SHARK_DIR)/%.so
+$(EXPORT_JRE_LIB_ARCH_DIR)/%.$(LIBRARY_SUFFIX): $(SHARK_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
-$(EXPORT_SERVER_DIR)/%.so:       $(SHARK_DIR)/%.so
+$(EXPORT_SERVER_DIR)/%.$(LIBRARY_SUFFIX):       $(SHARK_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
     else
-$(EXPORT_JRE_LIB_ARCH_DIR)/%.so: $(ZERO_DIR)/%.so
+$(EXPORT_JRE_LIB_ARCH_DIR)/%.$(LIBRARY_SUFFIX): $(ZERO_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
-$(EXPORT_SERVER_DIR)/%.so:       $(ZERO_DIR)/%.so
+$(EXPORT_SERVER_DIR)/%.$(LIBRARY_SUFFIX):       $(ZERO_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
     endif
   else
-$(EXPORT_JRE_LIB_ARCH_DIR)/%.so: $(C1_DIR)/%.so
+$(EXPORT_JRE_LIB_ARCH_DIR)/%.$(LIBRARY_SUFFIX): $(C1_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
-$(EXPORT_JRE_LIB_ARCH_DIR)/%.so: $(C2_DIR)/%.so
+$(EXPORT_JRE_LIB_ARCH_DIR)/%.$(LIBRARY_SUFFIX): $(C2_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
-$(EXPORT_CLIENT_DIR)/%.so:       $(C1_DIR)/%.so
+$(EXPORT_CLIENT_DIR)/%.$(LIBRARY_SUFFIX):       $(C1_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
-$(EXPORT_CLIENT_DIR)/64/%.so:    $(C1_DIR)/%.so
+$(EXPORT_CLIENT_DIR)/64/%.$(LIBRARY_SUFFIX):    $(C1_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
-$(EXPORT_SERVER_DIR)/%.so:       $(C2_DIR)/%.so
+$(EXPORT_SERVER_DIR)/%.$(LIBRARY_SUFFIX):       $(C2_DIR)/%.$(LIBRARY_SUFFIX)
 	$(install-file)
-$(EXPORT_SERVER_DIR)/64/%.so:    $(C2_DIR)/%.so
+$(EXPORT_SERVER_DIR)/64/%.$(LIBRARY_SUFFIX):    $(C2_DIR)/%.$(LIBRARY_SUFFIX)
+	$(install-file)
+
+# Debug info for shared library
+$(EXPORT_JRE_LIB_ARCH_DIR)/%.debuginfo: $(C1_DIR)/%.debuginfo
+	$(install-file)
+$(EXPORT_JRE_LIB_ARCH_DIR)/%.debuginfo: $(C2_DIR)/%.debuginfo
+	$(install-file)
+$(EXPORT_CLIENT_DIR)/%.debuginfo:       $(C1_DIR)/%.debuginfo
+	$(install-file)
+$(EXPORT_CLIENT_DIR)/64/%.debuginfo:    $(C1_DIR)/%.debuginfo
+	$(install-file)
+$(EXPORT_SERVER_DIR)/%.debuginfo:       $(C2_DIR)/%.debuginfo
+	$(install-file)
+$(EXPORT_SERVER_DIR)/64/%.debuginfo:    $(C2_DIR)/%.debuginfo
 	$(install-file)
   endif
 endif
@@ -457,6 +471,36 @@
 	   ($(CD) $(JDK_IMAGE_DIR)/debug && $(TAR) -xf -) ; \
 	fi
 
+# macosx universal builds
+
+ifeq ($(MACOSX_UNIVERSAL), true)
+$(UNIVERSAL_LIPO_LIST):
+	lipo -create -output $@ $(EXPORT_JRE_LIB_DIR)/{i386,amd64}/$(subst $(EXPORT_JRE_LIB_DIR)/,,$@)
+
+$(UNIVERSAL_COPY_LIST):
+	$(CP) $(EXPORT_JRE_LIB_DIR)/i386/$(subst $(EXPORT_JRE_LIB_DIR)/,,$@) $@
+
+universalize: $(UNIVERSAL_LIPO_LIST) $(UNIVERSAL_COPY_LIST)
+endif
+
+universal_product:
+	$(QUIETLY) $(MAKE) ARCH_DATA_MODEL=32 MACOSX_UNIVERSAL=true all_product
+	$(QUIETLY) $(MAKE) ARCH_DATA_MODEL=64 MACOSX_UNIVERSAL=true all_product
+	$(MKDIR) -p $(EXPORT_JRE_LIB_DIR)/{client,server}
+	$(QUIETLY) $(MAKE) MACOSX_UNIVERSAL=true universalize
+
+universal_fastdebug:
+	$(QUIETLY) $(MAKE) ARCH_DATA_MODEL=32 MACOSX_UNIVERSAL=true all_fastdebug
+	$(QUIETLY) $(MAKE) ARCH_DATA_MODEL=64 MACOSX_UNIVERSAL=true all_fastdebug
+	$(MKDIR) -p $(EXPORT_JRE_LIB_DIR)/{client,server}
+	$(QUIETLY) $(MAKE) MACOSX_UNIVERSAL=true universalize
+
+universal_debug:
+	$(QUIETLY) $(MAKE) ARCH_DATA_MODEL=32 MACOSX_UNIVERSAL=true all_debug
+	$(QUIETLY) $(MAKE) ARCH_DATA_MODEL=64 MACOSX_UNIVERSAL=true all_debug
+	$(MKDIR) -p $(EXPORT_JRE_LIB_DIR)/{client,server}
+	$(QUIETLY) $(MAKE) MACOSX_UNIVERSAL=true universalize
+
 #
 # Check target
 #
@@ -585,5 +629,6 @@
 	export_product export_fastdebug export_debug export_optimized \
 	export_jdk_product export_jdk_fastdebug export_jdk_debug \
 	create_jdk copy_jdk update_jdk test_jdk \
-	copy_product_jdk copy_fastdebug_jdk copy_debug_jdk
+	copy_product_jdk copy_fastdebug_jdk copy_debug_jdk universalize \
+	universal_product
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/bsd/Makefile	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,371 @@
+#
+# Copyright (c) 1999, 2011, 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.
+#
+#
+
+# This makefile creates a build tree and lights off a build.
+# You can go back into the build tree and perform rebuilds or
+# incremental builds as desired. Be sure to reestablish
+# environment variable settings for LD_LIBRARY_PATH and JAVA_HOME.
+
+# The make process now relies on java and javac. These can be
+# specified either implicitly on the PATH, by setting the
+# (JDK-inherited) ALT_BOOTDIR environment variable to full path to a
+# JDK in which bin/java and bin/javac are present and working (e.g.,
+# /usr/local/java/jdk1.3/solaris), or via the (JDK-inherited)
+# default BOOTDIR path value. Note that one of ALT_BOOTDIR
+# or BOOTDIR has to be set. We do *not* search javac, javah, rmic etc.
+# from the PATH.
+#
+# One can set ALT_BOOTDIR or BOOTDIR to point to a jdk that runs on
+# an architecture that differs from the target architecture, as long
+# as the bootstrap jdk runs under the same flavor of OS as the target
+# (i.e., if the target is linux, point to a jdk that runs on a linux
+# box).  In order to use such a bootstrap jdk, set the make variable
+# REMOTE to the desired remote command mechanism, e.g.,
+#
+#    make REMOTE="rsh -l me myotherlinuxbox"
+
+# Along with VM, Serviceability Agent (SA) is built for SA/JDI binding.
+# JDI binding on SA produces two binaries:
+#  1. sa-jdi.jar       - This is build before building libjvm[_g].so
+#                        Please refer to ./makefiles/sa.make
+#  2. libsa[_g].so     - Native library for SA - This is built after
+#                        libjsig[_g].so (signal interposition library)
+#                        Please refer to ./makefiles/vm.make
+# If $(GAMMADIR)/agent dir is not present, SA components are not built.
+
+ifeq ($(GAMMADIR),)
+include ../../make/defs.make
+else
+include $(GAMMADIR)/make/defs.make
+endif
+include $(GAMMADIR)/make/$(OSNAME)/makefiles/rules.make
+
+ifndef CC_INTERP
+  ifndef FORCE_TIERED
+    FORCE_TIERED=1
+  endif
+endif
+
+ifdef LP64
+  ifeq ("$(filter $(LP64_ARCH),$(BUILDARCH))","")
+    _JUNK_ := $(shell echo >&2 \
+       $(OSNAME) $(ARCH) "*** ERROR: this platform does not support 64-bit compilers!")
+	@exit 1
+  endif
+endif
+
+# we need to set up LP64 correctly to satisfy sanity checks in adlc
+ifneq ("$(filter $(LP64_ARCH),$(BUILDARCH))","")
+  MFLAGS += " LP64=1 "
+endif
+
+# pass USE_SUNCC further, through MFLAGS
+ifdef USE_SUNCC
+  MFLAGS += " USE_SUNCC=1 "
+endif
+
+# The following renders pathnames in generated Makefiles valid on
+# machines other than the machine containing the build tree.
+#
+# For example, let's say my build tree lives on /files12 on
+# exact.east.sun.com.  This logic will cause GAMMADIR to begin with
+# /net/exact/files12/...
+#
+# We only do this on SunOS variants, for a couple of reasons:
+#  * It is extremely rare that source trees exist on other systems
+#  * It has been claimed that the Linux automounter is flakey, so
+#    changing GAMMADIR in a way that exercises the automounter could
+#    prove to be a source of unreliability in the build process.
+# Obviously, this Makefile is only relevant on SunOS boxes to begin
+# with, but the SunOS conditionalization will make it easier to
+# combine Makefiles in the future (assuming we ever do that).
+
+ifeq ($(OSNAME),solaris)
+
+  #   prepend current directory to relative pathnames.
+  NEW_GAMMADIR :=                                    \
+    $(shell echo $(GAMMADIR) |                       \
+      sed -e "s=^\([^/].*\)=$(shell pwd)/\1="        \
+     )
+  unexport NEW_GAMMADIR
+
+  # If NEW_GAMMADIR doesn't already start with "/net/":
+  ifeq ($(strip $(filter /net/%,$(NEW_GAMMADIR))),)
+    #   prepend /net/$(HOST)
+    #   remove /net/$(HOST) if name already began with /home/
+    #   remove /net/$(HOST) if name already began with /java/
+    #   remove /net/$(HOST) if name already began with /lab/
+    NEW_GAMMADIR :=                                     \
+         $(shell echo $(NEW_GAMMADIR) |                 \
+                 sed -e "s=^\(.*\)=/net/$(HOST)\1="     \
+                     -e "s=^/net/$(HOST)/home/=/home/=" \
+                     -e "s=^/net/$(HOST)/java/=/java/=" \
+                     -e "s=^/net/$(HOST)/lab/=/lab/="   \
+          )
+    # Don't use the new value for GAMMADIR unless a file with the new
+    # name actually exists.
+    ifneq ($(wildcard $(NEW_GAMMADIR)),)
+      GAMMADIR := $(NEW_GAMMADIR)
+    endif
+  endif
+
+endif
+
+# BUILDARCH is set to "zero" for Zero builds.  VARIANTARCH
+# is used to give the build directories meaningful names.
+VARIANTARCH = $(subst i386,i486,$(ZERO_LIBARCH))
+
+# There is a (semi-) regular correspondence between make targets and actions:
+#
+#       Target          Tree Type       Build Dir
+#
+#       debug           compiler2       <os>_<arch>_compiler2/debug
+#       fastdebug       compiler2       <os>_<arch>_compiler2/fastdebug
+#       jvmg            compiler2       <os>_<arch>_compiler2/jvmg
+#       optimized       compiler2       <os>_<arch>_compiler2/optimized
+#       profiled        compiler2       <os>_<arch>_compiler2/profiled
+#       product         compiler2       <os>_<arch>_compiler2/product
+#
+#       debug1          compiler1       <os>_<arch>_compiler1/debug
+#       fastdebug1      compiler1       <os>_<arch>_compiler1/fastdebug
+#       jvmg1           compiler1       <os>_<arch>_compiler1/jvmg
+#       optimized1      compiler1       <os>_<arch>_compiler1/optimized
+#       profiled1       compiler1       <os>_<arch>_compiler1/profiled
+#       product1        compiler1       <os>_<arch>_compiler1/product
+#
+#       debugcore       core            <os>_<arch>_core/debug
+#       fastdebugcore   core            <os>_<arch>_core/fastdebug
+#       jvmgcore        core            <os>_<arch>_core/jvmg
+#       optimizedcore   core            <os>_<arch>_core/optimized
+#       profiledcore    core            <os>_<arch>_core/profiled
+#       productcore     core            <os>_<arch>_core/product
+#
+#       debugzero       zero            <os>_<arch>_zero/debug
+#       fastdebugzero   zero            <os>_<arch>_zero/fastdebug
+#       jvmgzero        zero            <os>_<arch>_zero/jvmg
+#       optimizedzero   zero            <os>_<arch>_zero/optimized
+#       profiledzero    zero            <os>_<arch>_zero/profiled
+#       productzero     zero            <os>_<arch>_zero/product
+#
+#       debugshark      shark           <os>_<arch>_shark/debug
+#       fastdebugshark  shark           <os>_<arch>_shark/fastdebug
+#       jvmgshark       shark           <os>_<arch>_shark/jvmg
+#       optimizedshark  shark           <os>_<arch>_shark/optimized
+#       profiledshark   shark           <os>_<arch>_shark/profiled
+#       productshark    shark           <os>_<arch>_shark/product
+#
+# What you get with each target:
+#
+# debug*     - "thin" libjvm_g - debug info linked into the gamma_g launcher
+# fastdebug* - optimized compile, but with asserts enabled
+# jvmg*      - "fat" libjvm_g - debug info linked into libjvm_g.so
+# optimized* - optimized compile, no asserts
+# profiled*  - gprof
+# product*   - the shippable thing:  optimized compile, no asserts, -DPRODUCT
+
+# This target list needs to be coordinated with the usage message
+# in the build.sh script:
+TARGETS           = debug jvmg fastdebug optimized profiled product
+
+ifeq ($(ZERO_BUILD), true)
+  SUBDIR_DOCS     = $(OSNAME)_$(VARIANTARCH)_docs
+else
+  SUBDIR_DOCS     = $(OSNAME)_$(BUILDARCH)_docs
+endif
+SUBDIRS_C1        = $(addprefix $(OSNAME)_$(BUILDARCH)_compiler1/,$(TARGETS))
+SUBDIRS_C2        = $(addprefix $(OSNAME)_$(BUILDARCH)_compiler2/,$(TARGETS))
+SUBDIRS_TIERED    = $(addprefix $(OSNAME)_$(BUILDARCH)_tiered/,$(TARGETS))
+SUBDIRS_CORE      = $(addprefix $(OSNAME)_$(BUILDARCH)_core/,$(TARGETS))
+SUBDIRS_ZERO      = $(addprefix $(OSNAME)_$(VARIANTARCH)_zero/,$(TARGETS))
+SUBDIRS_SHARK     = $(addprefix $(OSNAME)_$(VARIANTARCH)_shark/,$(TARGETS))
+
+TARGETS_C2        = $(TARGETS)
+TARGETS_C1        = $(addsuffix 1,$(TARGETS))
+TARGETS_TIERED    = $(addsuffix tiered,$(TARGETS))
+TARGETS_CORE      = $(addsuffix core,$(TARGETS))
+TARGETS_ZERO      = $(addsuffix zero,$(TARGETS))
+TARGETS_SHARK     = $(addsuffix shark,$(TARGETS))
+
+BUILDTREE_MAKE    = $(GAMMADIR)/make/$(OSNAME)/makefiles/buildtree.make
+BUILDTREE_VARS    = GAMMADIR=$(GAMMADIR) OS_FAMILY=$(OSNAME) SRCARCH=$(SRCARCH) BUILDARCH=$(BUILDARCH) LIBARCH=$(LIBARCH)
+BUILDTREE_VARS   += HOTSPOT_RELEASE_VERSION=$(HOTSPOT_RELEASE_VERSION) HOTSPOT_BUILD_VERSION=$(HOTSPOT_BUILD_VERSION) JRE_RELEASE_VERSION=$(JRE_RELEASE_VERSION)
+
+BUILDTREE         = $(MAKE) -f $(BUILDTREE_MAKE) $(BUILDTREE_VARS)
+
+#-------------------------------------------------------------------------------
+
+# Could make everything by default, but that would take a while.
+all:
+	@echo "Try '$(MAKE) <target> ...'  where <target> is one or more of"
+	@echo "  $(TARGETS_C2)"
+	@echo "  $(TARGETS_C1)"
+	@echo "  $(TARGETS_CORE)"
+	@echo "  $(TARGETS_ZERO)"
+	@echo "  $(TARGETS_SHARK)"
+
+checks: check_os_version check_j2se_version
+
+# We do not want people accidentally building on old systems (e.g. Linux 2.2.x,
+# Solaris 2.5.1, 2.6).
+# Disable this check by setting DISABLE_HOTSPOT_OS_VERSION_CHECK=ok.
+
+#SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 2.7%
+DISABLE_HOTSPOT_OS_VERSION_CHECK = ok
+OS_VERSION := $(shell uname -r)
+EMPTY_IF_NOT_SUPPORTED = $(filter $(SUPPORTED_OS_VERSION),$(OS_VERSION))
+
+check_os_version:
+ifeq ($(DISABLE_HOTSPOT_OS_VERSION_CHECK)$(EMPTY_IF_NOT_SUPPORTED),)
+	$(QUIETLY) >&2 echo "*** This OS is not supported:" `uname -a`; exit 1;
+endif
+
+# jvmti.make requires XSLT (J2SE 1.4.x or newer):
+XSLT_CHECK	= $(REMOTE) $(RUN.JAVAP) javax.xml.transform.TransformerFactory
+# If not found then fail fast.
+check_j2se_version:
+	$(QUIETLY) $(XSLT_CHECK) > /dev/null 2>&1; \
+	if [ $$? -ne 0 ]; then \
+	  $(REMOTE) $(RUN.JAVA) -version; \
+	  echo "*** An XSLT processor (J2SE 1.4.x or newer) is required" \
+	  "to bootstrap this build" 1>&2; \
+	  exit 1; \
+	fi
+
+$(SUBDIRS_TIERED): $(BUILDTREE_MAKE)
+	$(QUIETLY) $(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/Makefile checks
+	$(BUILDTREE) VARIANT=tiered
+
+$(SUBDIRS_C2): $(BUILDTREE_MAKE)
+ifeq ($(FORCE_TIERED),1)
+	$(QUIETLY) $(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/Makefile checks
+		$(BUILDTREE) VARIANT=tiered FORCE_TIERED=1
+else
+	$(QUIETLY) $(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/Makefile checks
+		$(BUILDTREE) VARIANT=compiler2
+endif
+
+$(SUBDIRS_C1): $(BUILDTREE_MAKE)
+	$(QUIETLY) $(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/Makefile checks
+	$(BUILDTREE) VARIANT=compiler1
+
+$(SUBDIRS_CORE): $(BUILDTREE_MAKE)
+	$(QUIETLY) $(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/Makefile checks
+	$(BUILDTREE) VARIANT=core
+
+$(SUBDIRS_ZERO): $(BUILDTREE_MAKE) platform_zero
+	$(QUIETLY) $(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/Makefile checks
+	$(BUILDTREE) VARIANT=zero VARIANTARCH=$(VARIANTARCH)
+
+$(SUBDIRS_SHARK): $(BUILDTREE_MAKE) platform_zero
+	$(QUIETLY) $(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/Makefile checks
+	$(BUILDTREE) VARIANT=shark VARIANTARCH=$(VARIANTARCH)
+
+platform_zero: $(GAMMADIR)/make/$(OSNAME)/platform_zero.in
+	$(SED) 's/@ZERO_ARCHDEF@/$(ZERO_ARCHDEF)/g;s/@ZERO_LIBARCH@/$(ZERO_LIBARCH)/g;' < $< > $@
+
+# Define INSTALL=y at command line to automatically copy JVM into JAVA_HOME
+
+$(TARGETS_C2):  $(SUBDIRS_C2)
+	cd $(OSNAME)_$(BUILDARCH)_compiler2/$@ && $(MAKE) $(MFLAGS)
+	cd $(OSNAME)_$(BUILDARCH)_compiler2/$@ && ./test_gamma
+ifdef INSTALL
+	cd $(OSNAME)_$(BUILDARCH)_compiler2/$@ && $(MAKE) $(MFLAGS) install
+endif
+
+$(TARGETS_TIERED):  $(SUBDIRS_TIERED)
+	cd $(OSNAME)_$(BUILDARCH)_tiered/$(patsubst %tiered,%,$@) && $(MAKE) $(MFLAGS)
+	cd $(OSNAME)_$(BUILDARCH)_tiered/$(patsubst %tiered,%,$@) && ./test_gamma
+ifdef INSTALL
+	cd $(OSNAME)_$(BUILDARCH)_tiered/$(patsubst %tiered,%,$@) && $(MAKE) $(MFLAGS) install
+endif
+
+$(TARGETS_C1):  $(SUBDIRS_C1)
+	cd $(OSNAME)_$(BUILDARCH)_compiler1/$(patsubst %1,%,$@) && $(MAKE) $(MFLAGS)
+	cd $(OSNAME)_$(BUILDARCH)_compiler1/$(patsubst %1,%,$@) && ./test_gamma
+ifdef INSTALL
+	cd $(OSNAME)_$(BUILDARCH)_compiler1/$(patsubst %1,%,$@) && $(MAKE) $(MFLAGS) install
+endif
+
+$(TARGETS_CORE):  $(SUBDIRS_CORE)
+	cd $(OSNAME)_$(BUILDARCH)_core/$(patsubst %core,%,$@) && $(MAKE) $(MFLAGS)
+	cd $(OSNAME)_$(BUILDARCH)_core/$(patsubst %core,%,$@) && ./test_gamma
+ifdef INSTALL
+	cd $(OSNAME)_$(BUILDARCH)_core/$(patsubst %core,%,$@) && $(MAKE) $(MFLAGS) install
+endif
+
+$(TARGETS_ZERO):  $(SUBDIRS_ZERO)
+	cd $(OSNAME)_$(VARIANTARCH)_zero/$(patsubst %zero,%,$@) && $(MAKE) $(MFLAGS)
+	cd $(OSNAME)_$(VARIANTARCH)_zero/$(patsubst %zero,%,$@) && ./test_gamma
+ifdef INSTALL
+	cd $(OSNAME)_$(VARIANTARCH)_zero/$(patsubst %zero,%,$@) && $(MAKE) $(MFLAGS) install
+endif
+
+$(TARGETS_SHARK):  $(SUBDIRS_SHARK)
+	cd $(OSNAME)_$(VARIANTARCH)_shark/$(patsubst %shark,%,$@) && $(MAKE) $(MFLAGS)
+	cd $(OSNAME)_$(VARIANTARCH)_shark/$(patsubst %shark,%,$@) && ./test_gamma
+ifdef INSTALL
+	cd $(OSNAME)_$(VARIANTARCH)_shark/$(patsubst %shark,%,$@) && $(MAKE) $(MFLAGS) install
+endif
+
+# Just build the tree, and nothing else:
+tree:      $(SUBDIRS_C2)
+tree1:     $(SUBDIRS_C1)
+treecore:  $(SUBDIRS_CORE)
+treezero:  $(SUBDIRS_ZERO)
+treeshark: $(SUBDIRS_SHARK)
+
+# Doc target.  This is the same for all build options.
+#     Hence create a docs directory beside ...$(ARCH)_[...]
+docs: checks
+	$(QUIETLY) mkdir -p $(SUBDIR_DOCS)
+	$(MAKE) -f $(GAMMADIR)/make/$(OSNAME)/makefiles/jvmti.make $(MFLAGS) $(BUILDTREE_VARS) JvmtiOutDir=$(SUBDIR_DOCS) jvmtidocs
+
+# Synonyms for win32-like targets.
+compiler2:  jvmg product
+
+compiler1:  jvmg1 product1
+
+core: jvmgcore productcore
+
+zero: jvmgzero productzero
+
+shark: jvmgshark productshark
+
+clean_docs:
+	rm -rf $(SUBDIR_DOCS)
+
+clean_compiler1 clean_compiler2 clean_core clean_zero clean_shark:
+	rm -rf $(OSNAME)_$(BUILDARCH)_$(subst clean_,,$@)
+
+clean:  clean_compiler2 clean_compiler1 clean_core clean_zero clean_shark clean_docs
+
+include $(GAMMADIR)/make/cscope.make
+
+#-------------------------------------------------------------------------------
+
+.PHONY: $(TARGETS_C2) $(TARGETS_C1) $(TARGETS_CORE) $(TARGETS_ZERO) $(TARGETS_SHARK)
+.PHONY: tree tree1 treecore treezero treeshark
+.PHONY: all compiler1 compiler2 core zero shark
+.PHONY: clean clean_compiler1 clean_compiler2 clean_core clean_zero clean_shark docs clean_docs
+.PHONY: checks check_os_version check_j2se_version
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/bsd/README	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,26 @@
+Copyright (c) 2007, 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.
+
+________________________________________________________________________
+
+Please refer to the comments in the Makefile in this directory
+for instructions how to build the Solaris versions.
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/bsd/adlc_updater	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,20 @@
+#! /bin/sh
+#
+# This file is used by adlc.make to selectively update generated
+# adlc files. Because source and target diretories are relative
+# paths, this file is copied to the target build directory before
+# use.
+#
+# adlc-updater <file> <source-dir> <target-dir>
+#
+fix_lines() {
+  # repair bare #line directives in $1 to refer to $2
+  awk < $1 > $1+ '
+    /^#line 999999$/ {print "#line " (NR+1) " \"" F2 "\""; next}
+    {print}
+  ' F2=$2
+  mv $1+ $1
+}
+fix_lines $2/$1 $3/$1
+[ -f $3/$1 ] && cmp -s $2/$1 $3/$1 || \
+( [ -f $3/$1 ] && echo Updating $3/$1 ; touch $2/made-change ; mv $2/$1 $3/$1 )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/bsd/build.sh	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,95 @@
+#! /bin/sh
+#
+# Copyright (c) 1999, 2008, 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.
+#  
+#
+
+# Make sure the variable JAVA_HOME is set before running this script.
+
+set -u
+
+
+if [ $# != 2 ]; then 
+    echo "Usage : $0 Build_Options Location"
+    echo "Build Options : debug or optimized or basicdebug or basic or clean"
+    echo "Location : specify any workspace which has gamma sources"
+    exit 1
+fi
+
+# Just in case:
+case ${JAVA_HOME} in
+/*) true;;
+?*) JAVA_HOME=`( cd $JAVA_HOME; pwd )`;;
+esac
+
+case `uname -m` in
+  i386|i486|i586|i686)
+    mach=i386
+    ;;
+  *)
+    echo "Unsupported machine: " `uname -m`
+    exit 1
+    ;;
+esac
+
+if [ "${JAVA_HOME}" = ""  -o  ! -d "${JAVA_HOME}" -o ! -d ${JAVA_HOME}/jre/lib/${mach} ]; then
+    echo "JAVA_HOME needs to be set to a valid JDK path"
+    echo "ksh : export JAVA_HOME=/net/tetrasparc/export/gobi/JDK1.2_fcs_V/bsd"
+    echo "csh : setenv JAVA_HOME /net/tetrasparc/export/gobi/JDK1.2_fcs_V/bsd"
+    exit 1
+fi
+
+
+LD_LIBRARY_PATH=${JAVA_HOME}/jre/lib/`uname -p`:\
+${JAVA_HOME}/jre/lib/`uname -p`/native_threads:${LD_LIBRARY_PATH-.}
+
+# This is necessary as long as we are using the old launcher
+# with the new distribution format:
+CLASSPATH=${JAVA_HOME}/jre/lib/rt.jar:${CLASSPATH-.}
+
+
+for gm in gmake gnumake
+do
+  if [ "${GNUMAKE-}" != "" ]; then break; fi
+  ($gm --version >/dev/null) 2>/dev/null && GNUMAKE=$gm
+done
+: ${GNUMAKE:?'Cannot locate the gnumake program.  Stop.'}
+
+
+echo "### ENVIRONMENT SETTINGS:"
+export JAVA_HOME		; echo "JAVA_HOME=$JAVA_HOME"
+export LD_LIBRARY_PATH		; echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
+export CLASSPATH		; echo "CLASSPATH=$CLASSPATH"
+export GNUMAKE			; echo "GNUMAKE=$GNUMAKE"
+echo "###"
+
+Build_Options=$1
+Location=$2
+
+case ${Location} in
+/*) true;;
+?*) Location=`(cd ${Location}; pwd)`;;
+esac
+
+echo \
+${GNUMAKE} -f ${Location}/make/bsd/Makefile $Build_Options GAMMADIR=${Location}
+${GNUMAKE} -f ${Location}/make/bsd/Makefile $Build_Options GAMMADIR=${Location}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/bsd/makefiles/adjust-mflags.sh	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,87 @@
+#! /bin/sh
+#
+# Copyright (c) 1999, 2008, 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.
+#  
+#
+
+# This script is used only from top.make.
+# The macro $(MFLAGS-adjusted) calls this script to
+# adjust the "-j" arguments to take into account
+# the HOTSPOT_BUILD_JOBS variable.  The default
+# handling of the "-j" argument by gnumake does
+# not meet our needs, so we must adjust it ourselves.
+
+# This argument adjustment applies to two recursive
+# calls to "$(MAKE) $(MFLAGS-adjusted)" in top.make.
+# One invokes adlc.make, and the other invokes vm.make.
+# The adjustment propagates the desired concurrency
+# level down to the sub-make (of the adlc or vm).
+# The default behavior of gnumake is to run all
+# sub-makes without concurrency ("-j1").
+
+# Also, we use a make variable rather than an explicit
+# "-j<N>" argument to control this setting, so that
+# the concurrency setting (which must be tuned separately
+# for each MP system) can be set via an environment variable.
+# The recommended setting is 1.5x to 2x the number of available
+# CPUs on the MP system, which is large enough to keep the CPUs
+# busy (even though some jobs may be I/O bound) but not too large,
+# we may presume, to overflow the system's swap space.
+
+set -eu
+
+default_build_jobs=4
+
+case $# in
+[12])	true;;
+*)	>&2 echo "Usage: $0 ${MFLAGS} ${HOTSPOT_BUILD_JOBS}"; exit 2;;
+esac
+
+MFLAGS=$1
+HOTSPOT_BUILD_JOBS=${2-}
+
+# Normalize any -jN argument to the form " -j${HBJ}"
+MFLAGS=`
+	echo "$MFLAGS" \
+	| sed '
+		s/^-/ -/
+		s/ -\([^ 	][^ 	]*\)j/ -\1 -j/
+		s/ -j[0-9][0-9]*/ -j/
+		s/ -j\([^ 	]\)/ -j -\1/
+		s/ -j/ -j'${HOTSPOT_BUILD_JOBS:-${default_build_jobs}}'/
+	' `
+
+case ${HOTSPOT_BUILD_JOBS} in \
+
+'') case ${MFLAGS} in
+    *\ -j*)
+	>&2 echo "# Note: -jN is ineffective for setting parallelism in this makefile." 
+	>&2 echo "# please set HOTSPOT_BUILD_JOBS=${default_build_jobs} in the command line or environment."
+    esac;;
+
+?*) case ${MFLAGS} in
+     *\ -j*) true;;
+     *)      MFLAGS="-j${HOTSPOT_BUILD_JOBS} ${MFLAGS}";;
+    esac;;
+esac
+
+echo "${MFLAGS}"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/bsd/makefiles/adlc.make	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,228 @@
+#
+# Copyright (c) 1999, 2011, 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.
+#  
+#
+
+# This makefile (adlc.make) is included from the adlc.make in the
+# build directories.
+# It knows how to compile, link, and run the adlc.
+
+include $(GAMMADIR)/make/$(Platform_os_family)/makefiles/rules.make
+
+# #########################################################################
+
+# OUTDIR must be the same as AD_Dir = $(GENERATED)/adfiles in top.make:
+GENERATED = ../generated
+OUTDIR  = $(GENERATED)/adfiles
+
+ARCH = $(Platform_arch)
+OS = $(Platform_os_family)
+
+SOURCE.AD = $(OUTDIR)/$(OS)_$(Platform_arch_model).ad 
+
+SOURCES.AD = \
+  $(call altsrc-replace,$(HS_COMMON_SRC)/cpu/$(ARCH)/vm/$(Platform_arch_model).ad) \
+  $(call altsrc-replace,$(HS_COMMON_SRC)/os_cpu/$(OS)_$(ARCH)/vm/$(OS)_$(Platform_arch_model).ad)
+
+EXEC	= $(OUTDIR)/adlc
+
+# set VPATH so make knows where to look for source files
+Src_Dirs_V += $(GAMMADIR)/src/share/vm/adlc
+VPATH += $(Src_Dirs_V:%=%:)
+
+# set INCLUDES for C preprocessor
+Src_Dirs_I += $(GAMMADIR)/src/share/vm/adlc $(GENERATED)
+INCLUDES += $(Src_Dirs_I:%=-I%)
+
+# set flags for adlc compilation
+CPPFLAGS = $(SYSDEFS) $(INCLUDES)
+
+# Force assertions on.
+CPPFLAGS += -DASSERT
+
+# CFLAGS_WARN holds compiler options to suppress/enable warnings.
+# Compiler warnings are treated as errors
+ifneq ($(COMPILER_WARNINGS_FATAL),false)
+  CFLAGS_WARN = -Werror
+endif
+CFLAGS += $(CFLAGS_WARN)
+
+OBJECTNAMES = \
+	adlparse.o \
+	archDesc.o \
+	arena.o \
+	dfa.o \
+	dict2.o \
+	filebuff.o \
+	forms.o \
+	formsopt.o \
+	formssel.o \
+	main.o \
+	adlc-opcodes.o \
+	output_c.o \
+	output_h.o \
+
+OBJECTS = $(OBJECTNAMES:%=$(OUTDIR)/%)
+
+GENERATEDNAMES = \
+        ad_$(Platform_arch_model).cpp \
+        ad_$(Platform_arch_model).hpp \
+        ad_$(Platform_arch_model)_clone.cpp \
+        ad_$(Platform_arch_model)_expand.cpp \
+        ad_$(Platform_arch_model)_format.cpp \
+        ad_$(Platform_arch_model)_gen.cpp \
+        ad_$(Platform_arch_model)_misc.cpp \
+        ad_$(Platform_arch_model)_peephole.cpp \
+        ad_$(Platform_arch_model)_pipeline.cpp \
+        adGlobals_$(Platform_arch_model).hpp \
+        dfa_$(Platform_arch_model).cpp \
+
+GENERATEDFILES = $(GENERATEDNAMES:%=$(OUTDIR)/%)
+
+# #########################################################################
+
+all: $(EXEC)
+
+$(EXEC) : $(OBJECTS)
+	@echo Making adlc
+	$(QUIETLY) $(HOST.LINK_NOPROF.CC) -o $(EXEC) $(OBJECTS)
+
+# Random dependencies:
+$(OBJECTS): opcodes.hpp classes.hpp adlc.hpp adlcVMDeps.hpp adlparse.hpp archDesc.hpp arena.hpp dict2.hpp filebuff.hpp forms.hpp formsopt.hpp formssel.hpp
+
+# The source files refer to ostream.h, which sparcworks calls iostream.h
+$(OBJECTS): ostream.h
+
+ostream.h :
+	@echo >$@ '#include <iostream.h>'
+
+dump:
+	: OUTDIR=$(OUTDIR)
+	: OBJECTS=$(OBJECTS)
+	: products = $(GENERATEDFILES)
+
+all: $(GENERATEDFILES)
+
+$(GENERATEDFILES): refresh_adfiles
+
+# Get a unique temporary directory name, so multiple makes can run in parallel.
+# Note that product files are updated via "mv", which is atomic.
+TEMPDIR := $(OUTDIR)/mktmp$(shell echo $$$$)
+
+# Debuggable by default
+CFLAGS += -g
+
+# Pass -D flags into ADLC.
+ADLCFLAGS += $(SYSDEFS)
+
+# Note "+="; it is a hook so flags.make can add more flags, like -g or -DFOO.
+ADLCFLAGS += -q -T
+
+# Normally, debugging is done directly on the ad_<arch>*.cpp files.
+# But -g will put #line directives in those files pointing back to <arch>.ad.
+# Some builds of gcc 3.2 have a bug that gets tickled by the extra #line directives
+# so skip it for 3.2 and ealier.
+ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
+ADLCFLAGS += -g
+endif
+
+ifdef LP64
+ADLCFLAGS += -D_LP64
+else
+ADLCFLAGS += -U_LP64
+endif
+
+#
+# adlc_updater is a simple sh script, under sccs control. It is
+# used to selectively update generated adlc files. This should
+# provide a nice compilation speed improvement.
+#
+ADLC_UPDATER_DIRECTORY = $(GAMMADIR)/make/$(OS)
+ADLC_UPDATER = adlc_updater
+$(ADLC_UPDATER): $(ADLC_UPDATER_DIRECTORY)/$(ADLC_UPDATER)
+	$(QUIETLY) cp $< $@; chmod +x $@
+
+# This action refreshes all generated adlc files simultaneously.
+# The way it works is this:
+# 1) create a scratch directory to work in.
+# 2) if the current working directory does not have $(ADLC_UPDATER), copy it.
+# 3) run the compiled adlc executable. This will create new adlc files in the scratch directory.
+# 4) call $(ADLC_UPDATER) on each generated adlc file. It will selectively update changed or missing files.
+# 5) If we actually updated any files, echo a notice.
+#
+refresh_adfiles: $(EXEC) $(SOURCE.AD) $(ADLC_UPDATER)
+	@rm -rf $(TEMPDIR); mkdir $(TEMPDIR)
+	$(QUIETLY) $(EXEC) $(ADLCFLAGS) $(SOURCE.AD) \
+ -c$(TEMPDIR)/ad_$(Platform_arch_model).cpp -h$(TEMPDIR)/ad_$(Platform_arch_model).hpp -a$(TEMPDIR)/dfa_$(Platform_arch_model).cpp -v$(TEMPDIR)/adGlobals_$(Platform_arch_model).hpp \
+	    || { rm -rf $(TEMPDIR); exit 1; }
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model).cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model).hpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model)_clone.cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model)_expand.cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model)_format.cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model)_gen.cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model)_misc.cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model)_peephole.cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) ad_$(Platform_arch_model)_pipeline.cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) adGlobals_$(Platform_arch_model).hpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) ./$(ADLC_UPDATER) dfa_$(Platform_arch_model).cpp $(TEMPDIR) $(OUTDIR)
+	$(QUIETLY) [ -f $(TEMPDIR)/made-change ] \
+		|| echo "Rescanned $(SOURCE.AD) but encountered no changes."
+	$(QUIETLY) rm -rf $(TEMPDIR)
+
+
+# #########################################################################
+
+$(SOURCE.AD): $(SOURCES.AD)
+	$(QUIETLY) $(PROCESS_AD_FILES) $(SOURCES.AD) > $(SOURCE.AD)
+
+#PROCESS_AD_FILES = cat
+# Pass through #line directives, in case user enables -g option above:
+PROCESS_AD_FILES = awk '{ \
+    if (CUR_FN != FILENAME) { CUR_FN=FILENAME; NR_BASE=NR-1; need_lineno=1 } \
+    if (need_lineno && $$0 !~ /\/\//) \
+      { print "\n\n\#line " (NR-NR_BASE) " \"" FILENAME "\""; need_lineno=0 }; \
+    print }'
+
+$(OUTDIR)/%.o: %.cpp
+	@echo Compiling $<
+	$(QUIETLY) $(REMOVE_TARGET)
+	$(QUIETLY) $(HOST.COMPILE.CC) -o $@ $< $(COMPILE_DONE)
+
+# Some object files are given a prefix, to disambiguate
+# them from objects of the same name built for the VM.
+$(OUTDIR)/adlc-%.o: %.cpp
+	@echo Compiling $<
+	$(QUIETLY) $(REMOVE_TARGET)
+	$(QUIETLY) $(HOST.COMPILE.CC) -o $@ $< $(COMPILE_DONE)
+
+# #########################################################################
+
+clean	:
+	rm $(OBJECTS)
+
+cleanall :
+	rm $(OBJECTS) $(EXEC)
+
+# #########################################################################
+
+.PHONY: all dump refresh_adfiles clean cleanall
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/bsd/makefiles/amd64.make	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,39 @@
+#
+# Copyright (c) 2003, 2010, 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.
+#  
+#
+
+# The copied fdlibm routines in sharedRuntimeTrig.o must not be optimized
+OPT_CFLAGS/sharedRuntimeTrig.o = $(OPT_CFLAGS/NOOPT)
+# The copied fdlibm routines in sharedRuntimeTrans.o must not be optimized
+OPT_CFLAGS/sharedRuntimeTrans.o = $(OPT_CFLAGS/NOOPT)
+# Must also specify if CPU is little endian
+CFLAGS += -DVM_LITTLE_ENDIAN
+
+CFLAGS += -D_LP64=1
+
+# The serviceability agent relies on frame pointer (%rbp) to walk thread stack
+ifndef USE_SUNCC
+  CFLAGS += -fno-omit-frame-pointer
+endif
+
+OPT_CFLAGS/compactingPermGenGen.o = -O1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/bsd/makefiles/arm.make	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,29 @@
+#
+# Copyright (c) 2008, 2011, 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.
+#  
+#
+
+Obj_Files += bsd_arm.o
+
+LIBS += $(EXT_LIBS_PATH)/sflt_glibc.a 
+
+CFLAGS += -DVM_LITTLE_ENDIAN
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/bsd/makefiles/build_vm_def.sh	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+# If we're cross compiling use that path for nm
+if [ "$CROSS_COMPILE_ARCH" != "" ]; then 
+NM=$ALT_COMPILER_PATH/nm
+else
+NM=nm
+fi
+
+$NM --defined-only $* | awk '
+   { if ($3 ~ /^_ZTV/ || $3 ~ /^gHotSpotVM/) print "\t" $3 ";" }
+   '
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/bsd/makefiles/buildtree.make	Thu Oct 27 12:21:43 2011 -0700
@@ -0,0 +1,430 @@
+#
+# Copyright (c) 2005, 2011, 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.
+#  
+#
+
+# Usage:
+#
+# $(MAKE) -f buildtree.make SRCARCH=srcarch BUILDARCH=buildarch LIBARCH=libarch
+#         GAMMADIR=dir OS_FAMILY=os VARIANT=variant
+#
+# The macros ARCH, GAMMADIR, OS_FAMILY and VARIANT must be defined in the
+# environment or on the command-line:
+#
+# ARCH		- sparc, i486, ... HotSpot cpu and os_cpu source directory
+# BUILDARCH     - build directory
+# LIBARCH       - the corresponding directory in JDK/JRE
+# GAMMADIR	- top of workspace
+# OS_FAMILY	- operating system
+# VARIANT	- core, compiler1, compiler2, or tiered
+# HOTSPOT_RELEASE_VERSION - <major>.<minor>-b<nn> (11.0-b07)
+# HOTSPOT_BUILD_VERSION   - internal, internal-$(USER_RELEASE_SUFFIX) or empty
+# JRE_RELEASE_VERSION     - <major>.<minor>.<micro> (1.7.0)
+#
+# Builds the directory trees with makefiles plus some convenience files in
+# each directory:
+#
+# Makefile	- for "make foo"
+# flags.make	- with macro settings
+# vm.make	- to support making "$(MAKE) -v vm.make" in makefiles
+# adlc.make	- 
+# jvmti.make	- generate JVMTI bindings from the spec (JSR-163)
+# sa.make	- generate SA jar file and natives
+# env.[ck]sh	- environment settings
+# test_gamma	- script to run the Queens program
+# 
+# The makefiles are split this way so that "make foo" will run faster by not
+# having to read the dependency files for the vm.
+
+include $(GAMMADIR)/make/scm.make
+include $(GAMMADIR)/make/altsrc.make
+
+
+# 'gmake MAKE_VERBOSE=y' or 'gmake QUIETLY=' gives all the gory details.
+QUIETLY$(MAKE_VERBOSE)	= @
+
+# For now, until the compiler is less wobbly:
+TESTFLAGS	= -Xbatch -showversion
+
+ifeq ($(ZERO_BUILD), true)
+  PLATFORM_FILE = $(shell dirname $(shell dirname $(shell pwd)))/platform_zero
+else
+  ifdef USE_SUNCC
+    PLATFORM_FILE = $(GAMMADIR)/make/$(OS_FAMILY)/platform_$(BUILDARCH).suncc
+  else
+    PLATFORM_FILE = $(GAMMADIR)/make/$(OS_FAMILY)/platform_$(BUILDARCH)
+  endif
+endif
+
+# Allow overriding of the arch part of the directory but default
+# to BUILDARCH if nothing is specified
+ifeq ($(VARIANTARCH),)
+  VARIANTARCH=$(BUILDARCH)
+endif
+
+ifdef FORCE_TIERED
+ifeq		($(VARIANT),tiered)
+PLATFORM_DIR	= $(OS_FAMILY)_$(VARIANTARCH)_compiler2
+else
+PLATFORM_DIR	= $(OS_FAMILY)_$(VARIANTARCH)_$(VARIANT)
+endif
+else
+PLATFORM_DIR    = $(OS_FAMILY)_$(VARIANTARCH)_$(VARIANT)
+endif
+
+#
+# We do two levels of exclusion in the shared directory.
+# TOPLEVEL excludes are pruned, they are not recursively searched,
+# but lower level directories can be named without fear of collision.
+# ALWAYS excludes are excluded at any level in the directory tree.
+#
+
+ALWAYS_EXCLUDE_DIRS     = $(SCM_DIRS)
+
+ifeq		($(VARIANT),tiered)
+TOPLEVEL_EXCLUDE_DIRS	= $(ALWAYS_EXCLUDE_DIRS) -o -name adlc -o -name agent
+else
+ifeq		($(VARIANT),compiler2)
+TOPLEVEL_EXCLUDE_DIRS	= $(ALWAYS_EXCLUDE_DIRS) -o -name adlc -o -name c1 -o -name agent
+else
+# compiler1 and core use the same exclude list
+TOPLEVEL_EXCLUDE_DIRS	= $(ALWAYS_EXCLUDE_DIRS) -o -name adlc -o -name opto -o -name libadt -o -name agent
+endif
+endif
+
+# Get things from the platform file.
+COMPILER	= $(shell sed -n 's/^compiler[ 	]*=[ 	]*//p' $(PLATFORM_FILE))
+
+# dtracefiles is used on BSD versions that implement Dtrace (like MacOS X)
+SIMPLE_DIRS	= \
+	$(PLATFORM_DIR)/generated/dependencies \
+	$(PLATFORM_DIR)/generated/adfiles \
+	$(PLATFORM_DIR)/generated/jvmtifiles \
+	$(PLATFORM_DIR)/generated/dtracefiles
+
+TARGETS      = debug fastdebug jvmg optimized product profiled
+SUBMAKE_DIRS = $(addprefix $(PLATFORM_DIR)/,$(TARGETS))
+
+# For dependencies and recursive makes.
+BUILDTREE_MAKE	= $(GAMMADIR)/make/$(OS_FAMILY)/makefiles/buildtree.make
+
+# dtrace.make is used on BSD versions that implement Dtrace (like MacOS X)
+BUILDTREE_TARGETS = Makefile flags.make flags_vm.make vm.make adlc.make \
+	jvmti.make sa.make dtrace.make \
+        env.sh env.csh jdkpath.sh .dbxrc test_gamma
+
+BUILDTREE_VARS	= GAMMADIR=$(GAMMADIR) OS_FAMILY=$(OS_FAMILY) \
+	SRCARCH=$(SRCARCH) BUILDARCH=$(BUILDARCH) LIBARCH=$(LIBARCH) VARIANT=$(VARIANT)
+
+# Define variables to be set in flags.make.
+# Default values are set in make/defs.make.
+ifeq ($(HOTSPOT_BUILD_VERSION),)
+  HS_BUILD_VER=$(HOTSPOT_RELEASE_VERSION)
+else
+  HS_BUILD_VER=$(HOTSPOT_RELEASE_VERSION)-$(HOTSPOT_BUILD_VERSION)
+endif
+# Set BUILD_USER from system-dependent hints:  $LOGNAME, $(whoami)
+ifndef HOTSPOT_BUILD_USER
+  HOTSPOT_BUILD_USER := $(shell echo $$LOGNAME)
+endif
+ifndef HOTSPOT_BUILD_USER
+  HOTSPOT_BUILD_USER := $(shell whoami)
+endif
+# Define HOTSPOT_VM_DISTRO based on settings in make/openjdk_distro
+# or make/hotspot_distro.
+ifndef HOTSPOT_VM_DISTRO
+  ifeq ($(call if-has-altsrc,$(HS_COMMON_SRC)/,true,false),true)
+    include $(GAMMADIR)/make/hotspot_distro
+  else
+    include $(GAMMADIR)/make/openjdk_distro
+  endif
+endif
+
+# MACOSX FIXME: we should be able to run test_gamma (see MACOSX_PORT-214)
+ifdef ALWAYS_PASS_TEST_GAMMA
+  TEST_GAMMA_STATUS= echo 'exit 0';
+else
+  TEST_GAMMA_STATUS=
+endif
+
+BUILDTREE_VARS += HOTSPOT_RELEASE_VERSION=$(HS_BUILD_VER) HOTSPOT_BUILD_VERSION=  JRE_RELEASE_VERSION=$(JRE_RELEASE_VERSION)
+
+BUILDTREE	= \
+	$(MAKE) -f $(BUILDTREE_MAKE) $(BUILDTREE_TARGETS) $(BUILDTREE_VARS)
+
+BUILDTREE_COMMENT	= echo "\# Generated by $(BUILDTREE_MAKE)"
+
+all:  $(SUBMAKE_DIRS)
+
+# Run make in each subdirectory recursively.
+$(SUBMAKE_DIRS): $(SIMPLE_DIRS) FORCE
+	$(QUIETLY) [ -d $@ ] || { mkdir -p $@; }
+	$(QUIETLY) cd $@ && $(BUILDTREE) TARGET=$(@F)
+	$(QUIETLY) touch $@
+
+$(SIMPLE_DIRS):
+	$(QUIETLY) mkdir -p $@
+
+# Convenience macro which takes a source relative path, applies $(1) to the
+# absolute path, and then replaces $(GAMMADIR) in the result with a 
+# literal "$(GAMMADIR)/" suitable for inclusion in a Makefile.  
+gamma-path=$(subst $(GAMMADIR),\$$(GAMMADIR),$(call $(1),$(HS_COMMON_SRC)/$(2)))
+
+flags.make: $(BUILDTREE_MAKE) ../shared_dirs.lst
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	echo "Platform_file = $(PLATFORM_FILE)" | sed 's|$(GAMMADIR)|$$(GAMMADIR)|'; \
+	sed -n '/=/s/^ */Platform_/p' < $(PLATFORM_FILE); \
+	echo; \
+	echo "GAMMADIR = $(GAMMADIR)"; \
+	echo "SYSDEFS = \$$(Platform_sysdefs)"; \
+	echo "SRCARCH = $(SRCARCH)"; \
+	echo "BUILDARCH = $(BUILDARCH)"; \
+	echo "LIBARCH = $(LIBARCH)"; \
+	echo "TARGET = $(TARGET)"; \
+	echo "HS_BUILD_VER = $(HS_BUILD_VER)"; \
+	echo "JRE_RELEASE_VER = $(JRE_RELEASE_VERSION)"; \
+	echo "SA_BUILD_VERSION = $(HS_BUILD_VER)"; \
+	echo "HOTSPOT_BUILD_USER = $(HOTSPOT_BUILD_USER)"; \
+	echo "HOTSPOT_VM_DISTRO = $(HOTSPOT_VM_DISTRO)"; \
+	echo; \
+	echo "# Used for platform dispatching"; \
+	echo "TARGET_DEFINES  = -DTARGET_OS_FAMILY_\$$(Platform_os_family)"; \
+	echo "TARGET_DEFINES += -DTARGET_ARCH_\$$(Platform_arch)"; \
+	echo "TARGET_DEFINES += -DTARGET_ARCH_MODEL_\$$(Platform_arch_model)"; \
+	echo "TARGET_DEFINES += -DTARGET_OS_ARCH_\$$(Platform_os_arch)"; \
+	echo "TARGET_DEFINES += -DTARGET_OS_ARCH_MODEL_\$$(Platform_os_arch_model)"; \
+	echo "TARGET_DEFINES += -DTARGET_COMPILER_\$$(Platform_compiler)"; \
+	echo "CFLAGS += \$$(TARGET_DEFINES)"; \
+	echo; \
+	echo "Src_Dirs_V = \\"; \
+	sed 's/$$/ \\/;s|$(GAMMADIR)|$$(GAMMADIR)|' ../shared_dirs.lst; \
+	echo "$(call gamma-path,altsrc,cpu/$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,cpu/$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,altsrc,os_cpu/$(OS_FAMILY)_$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,os_cpu/$(OS_FAMILY)_$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,altsrc,os/$(OS_FAMILY)/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,os/$(OS_FAMILY)/vm) \\"; \
+	echo "$(call gamma-path,altsrc,os/posix/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,os/posix/vm)"; \
+	echo; \
+	echo "Src_Dirs_I = \\"; \
+	echo "$(call gamma-path,altsrc,share/vm/prims) \\"; \
+	echo "$(call gamma-path,commonsrc,share/vm/prims) \\"; \
+	echo "$(call gamma-path,altsrc,share/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,share/vm) \\"; \
+	echo "$(call gamma-path,altsrc,cpu/$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,cpu/$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,altsrc,os_cpu/$(OS_FAMILY)_$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,os_cpu/$(OS_FAMILY)_$(SRCARCH)/vm) \\"; \
+	echo "$(call gamma-path,altsrc,os/$(OS_FAMILY)/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,os/$(OS_FAMILY)/vm) \\"; \
+	echo "$(call gamma-path,altsrc,os/posix/vm) \\"; \
+	echo "$(call gamma-path,commonsrc,os/posix/vm)"; \
+	[ -n "$(CFLAGS_BROWSE)" ] && \
+	    echo && echo "CFLAGS_BROWSE = $(CFLAGS_BROWSE)"; \
+	[ -n "$(HOTSPOT_EXTRA_SYSDEFS)" ] && \
+	    echo && \
+	    echo "HOTSPOT_EXTRA_SYSDEFS\$$(HOTSPOT_EXTRA_SYSDEFS) = $(HOTSPOT_EXTRA_SYSDEFS)" && \
+	    echo "SYSDEFS += \$$(HOTSPOT_EXTRA_SYSDEFS)"; \
+	echo; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(VARIANT).make"; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(COMPILER).make"; \
+	) > $@
+
+flags_vm.make: $(BUILDTREE_MAKE) ../shared_dirs.lst
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	[ "$(TARGET)" = profiled ] && \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/optimized.make"; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(TARGET).make"; \
+	) > $@
+
+../shared_dirs.lst:  $(BUILDTREE_MAKE) $(GAMMADIR)/src/share/vm
+	@echo Creating directory list $@
+	$(QUIETLY) if [ -d $(HS_ALT_SRC)/share/vm ]; then \
+          find $(HS_ALT_SRC)/share/vm/* -prune \
+	  -type d \! \( $(TOPLEVEL_EXCLUDE_DIRS) \) -exec find {} \
+          \( $(ALWAYS_EXCLUDE_DIRS) \) -prune -o -type d -print \; > $@; \
+        fi;
+	$(QUIETLY) find $(HS_COMMON_SRC)/share/vm/* -prune \
+	-type d \! \( $(TOPLEVEL_EXCLUDE_DIRS) \) -exec find {} \
+        \( $(ALWAYS_EXCLUDE_DIRS) \) -prune -o -type d -print \; >> $@
+
+Makefile: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	echo include flags.make; \
+	echo; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/top.make"; \
+	) > $@
+
+vm.make: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	echo include flags.make; \
+	echo include flags_vm.make; \
+	echo; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(@F)"; \
+	) > $@
+
+adlc.make: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	echo include flags.make; \
+	echo; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(@F)"; \
+	) > $@
+
+jvmti.make: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	echo include flags.make; \
+	echo; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(@F)"; \
+	) > $@
+
+sa.make: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	echo include flags.make; \
+	echo; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(@F)"; \
+	) > $@
+
+dtrace.make: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo; \
+	echo include flags.make; \
+	echo; \
+	echo "include \$$(GAMMADIR)/make/$(OS_FAMILY)/makefiles/$(@F)"; \
+	) > $@
+
+env.sh: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	[ -n "$$JAVA_HOME" ] && { echo ": \$${JAVA_HOME:=$${JAVA_HOME}}"; }; \
+	{ \
+	echo "LD_LIBRARY_PATH=.:$${LD_LIBRARY_PATH:+$$LD_LIBRARY_PATH:}\$${JAVA_HOME}/jre/lib/${LIBARCH}/native_threads:\$${JAVA_HOME}/jre/lib/${LIBARCH}:${GCC_LIB}"; \
+	echo "DYLD_LIBRARY_PATH=.:$${DYLD_LIBRARY_PATH:+$$DYLD_LIBRARY_PATH:}\$${JAVA_HOME}/jre/lib/${LIBARCH}/native_threads:\$${JAVA_HOME}/jre/lib/${LIBARCH}:${GCC_LIB}"; \
+	echo "CLASSPATH=$${CLASSPATH:+$$CLASSPATH:}.:\$${JAVA_HOME}/jre/lib/rt.jar:\$${JAVA_HOME}/jre/lib/i18n.jar"; \
+	} | sed s:$${JAVA_HOME:--------}:\$${JAVA_HOME}:g; \
+	echo "HOTSPOT_BUILD_USER=\"$${LOGNAME:-$$USER} in `basename $(GAMMADIR)`\""; \
+	echo "export JAVA_HOME LD_LIBRARY_PATH DYLD_LIBRARY_PATH CLASSPATH HOTSPOT_BUILD_USER"; \
+	) > $@
+
+env.csh: env.sh
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	[ -n "$$JAVA_HOME" ] && \
+	{ echo "if (! \$$?JAVA_HOME) setenv JAVA_HOME \"$$JAVA_HOME\""; }; \
+	sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=/setenv \1 /p' $?; \
+	) > $@
+
+jdkpath.sh: $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	$(BUILDTREE_COMMENT); \
+	echo "JDK=${JAVA_HOME}"; \
+	) > $@	   
+
+.dbxrc:  $(BUILDTREE_MAKE)
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	echo "echo '# Loading $(PLATFORM_DIR)/$(TARGET)/.dbxrc'"; \
+	echo "if [ -f \"\$${HOTSPOT_DBXWARE}\" ]"; \
+	echo "then"; \
+	echo "	source \"\$${HOTSPOT_DBXWARE}\""; \
+	echo "elif [ -f \"\$$HOME/.dbxrc\" ]"; \
+	echo "then"; \
+	echo "	source \"\$$HOME/.dbxrc\""; \
+	echo "fi"; \
+	) > $@
+
+# Skip the test for product builds (which only work when installed in a JDK), to
+# avoid exiting with an error and causing make to halt.
+NO_TEST_MSG	= \
+	echo "$@:  skipping the test--this build must be tested in a JDK."
+
+NO_JAVA_HOME_MSG	= \
+	echo "JAVA_HOME must be set to run this test."
+
+DATA_MODE = $(DATA_MODE/$(BUILDARCH))
+JAVA_FLAG = $(JAVA_FLAG/$(DATA_MODE))
+
+DATA_MODE/i486    = 32
+DATA_MODE/sparc   = 32
+DATA_MODE/sparcv9 = 64
+DATA_MODE/amd64   = 64
+DATA_MODE/ia64    = 64
+DATA_MODE/zero    = $(ARCH_DATA_MODEL)
+
+JAVA_FLAG/32 = -d32
+JAVA_FLAG/64 = -d64
+
+WRONG_DATA_MODE_MSG = \
+	echo "JAVA_HOME must point to $(DATA_MODE)bit JDK."
+
+CROSS_COMPILING_MSG = \
+	echo "Cross compiling for ARCH $(CROSS_COMPILE_ARCH), skipping gamma run."
+
+test_gamma:  $(BUILDTREE_MAKE) $(GAMMADIR)/make/test/Queens.java
+	@echo Creating $@ ...
+	$(QUIETLY) ( \
+	echo '#!/bin/sh'; \
+	$(BUILDTREE_COMMENT); \
+	echo '. ./env.sh'; \
+	echo "if [ \"$(CROSS_COMPILE_ARCH)\" != \"\" ]; then { $(CROSS_COMPILING_MSG); exit 0; }; fi"; \
+	echo "if [ -z \$$JAVA_HOME ]; then { $(NO_JAVA_HOME_MSG); exit 0; }; fi"; \</