提交 fdd5e33d 编写于 作者: D dholmes

Merge

......@@ -6,3 +6,4 @@
^src/share/tools/IdealGraphVisualizer/build/
^src/share/tools/IdealGraphVisualizer/dist/
^.hgtip
.DS_Store
/*
* 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);
}
......@@ -32,7 +32,6 @@ SOURCES = salibelf.c \
libproc_impl.c \
ps_proc.c \
ps_core.c \
hsearch_r.c \
BsdDebuggerLocal.c
INCLUDES = -I${JAVA_HOME}/include -I${JAVA_HOME}/include/$(shell uname -s | tr "[:upper:]" "[:lower:]")
......
......@@ -116,7 +116,7 @@ struct symtab* build_symtab(int fd) {
if (shdr->sh_type == symsection) {
ELF_SYM *syms;
int j, n, rslt;
int j, n;
size_t size;
// FIXME: there could be multiple data buffers associated with the
......@@ -138,6 +138,8 @@ struct symtab* build_symtab(int fd) {
// 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
......@@ -145,11 +147,15 @@ struct symtab* build_symtab(int fd) {
// 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++) {
......@@ -175,6 +181,11 @@ struct symtab* build_symtab(int fd) {
}
}
}
goto quit;
bad:
destroy_symtab(symtab);
symtab = NULL;
quit:
if (shbuf) free(shbuf);
......@@ -195,7 +206,7 @@ void destroy_symtab(struct symtab* symtab) {
if (symtab->strs) free(symtab->strs);
if (symtab->symbols) free(symtab->symbols);
if (symtab->hash_table) {
symtab->hash_table->close(symtab->hash_table);
(*symtab->hash_table->close)(symtab->hash_table);
}
free(symtab);
}
......@@ -219,7 +230,6 @@ uintptr_t search_symbol(struct symtab* symtab, uintptr_t base,
return rslt;
}
quit:
return 0;
}
......@@ -228,12 +238,12 @@ const char* nearest_symbol(struct symtab* symtab, uintptr_t offset,
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;
}
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;
}
......@@ -52,6 +52,8 @@ 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
......
......@@ -43,7 +43,7 @@ public class PlatformInfo {
return "bsd";
} else if (os.equals("OpenBSD")) {
return "bsd";
} else if (os.equals("Darwin")) {
} else if (os.equals("Darwin") || os.startsWith("Mac OS X")) {
return "bsd";
} else if (os.startsWith("Windows")) {
return "win32";
......
......@@ -471,6 +471,36 @@ copy_debug_jdk:
($(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
#
......@@ -599,5 +629,6 @@ include $(GAMMADIR)/make/jprt.gmk
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
......@@ -61,7 +61,9 @@ CPPFLAGS += -DASSERT
# CFLAGS_WARN holds compiler options to suppress/enable warnings.
# Compiler warnings are treated as errors
CFLAGS_WARN = -Werror
ifneq ($(COMPILER_WARNINGS_FATAL),false)
CFLAGS_WARN = -Werror
endif
CFLAGS += $(CFLAGS_WARN)
OBJECTNAMES = \
......
......@@ -114,10 +114,12 @@ 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/jvmtifiles \
$(PLATFORM_DIR)/generated/dtracefiles
TARGETS = debug fastdebug jvmg optimized product profiled
SUBMAKE_DIRS = $(addprefix $(PLATFORM_DIR)/,$(TARGETS))
......@@ -125,7 +127,9 @@ SUBMAKE_DIRS = $(addprefix $(PLATFORM_DIR)/,$(TARGETS))
# For dependencies and recursive makes.
BUILDTREE_MAKE = $(GAMMADIR)/make/$(OS_FAMILY)/makefiles/buildtree.make
BUILDTREE_TARGETS = Makefile flags.make flags_vm.make vm.make adlc.make jvmti.make sa.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) \
......@@ -155,6 +159,13 @@ ifndef HOTSPOT_VM_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 = \
......@@ -314,6 +325,16 @@ sa.make: $(BUILDTREE_MAKE)
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) ( \
......@@ -390,7 +411,6 @@ test_gamma: $(BUILDTREE_MAKE) $(GAMMADIR)/make/test/Queens.java
echo '#!/bin/sh'; \
$(BUILDTREE_COMMENT); \
echo '. ./env.sh'; \
echo "exit 0;"; \
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"; \
echo "if ! \$${JAVA_HOME}/bin/java $(JAVA_FLAG) -fullversion 2>&1 > /dev/null"; \
......@@ -401,6 +421,7 @@ test_gamma: $(BUILDTREE_MAKE) $(GAMMADIR)/make/test/Queens.java
echo "\$${JAVA_HOME}/bin/javac -d . $(GAMMADIR)/make/test/Queens.java"; \
echo '[ -f gamma_g ] && { gamma=gamma_g; }'; \
echo './$${gamma:-gamma} $(TESTFLAGS) Queens < /dev/null'; \
$(TEST_GAMMA_STATUS) \
) > $@
$(QUIETLY) chmod +x $@
......
......@@ -162,9 +162,19 @@ ADD_SA_BINARIES/x86 = $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.$(LIBRARY_SUFFIX) \
$(EXPORT_LIB_DIR)/sa-jdi.jar
ADD_SA_BINARIES/sparc = $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.$(LIBRARY_SUFFIX) \
$(EXPORT_LIB_DIR)/sa-jdi.jar
ADD_SA_BINARIES/universal = $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.$(LIBRARY_SUFFIX) \
$(EXPORT_LIB_DIR)/sa-jdi.jar
ADD_SA_BINARIES/ppc =
ADD_SA_BINARIES/ia64 =
ADD_SA_BINARIES/arm =
ADD_SA_BINARIES/zero =
EXPORT_LIST += $(ADD_SA_BINARIES/$(HS_ARCH))
UNIVERSAL_LIPO_LIST += $(EXPORT_JRE_LIB_DIR)/libjsig.$(LIBRARY_SUFFIX)
UNIVERSAL_LIPO_LIST += $(EXPORT_JRE_LIB_DIR)/libsaproc.$(LIBRARY_SUFFIX)
UNIVERSAL_LIPO_LIST += $(EXPORT_JRE_LIB_DIR)/server/libjvm.$(LIBRARY_SUFFIX)
UNIVERSAL_COPY_LIST += $(EXPORT_JRE_LIB_DIR)/server/Xusage.txt
UNIVERSAL_COPY_LIST += $(EXPORT_JRE_LIB_DIR)/client/Xusage.txt
UNIVERSAL_COPY_LIST += $(EXPORT_JRE_LIB_DIR)/client/libjvm.$(LIBRARY_SUFFIX)
#
# Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2005, 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
......@@ -22,6 +22,282 @@
#
#
# Bsd does not build jvm_db
LIBJVM_DB =
# Rules to build jvm_db/dtrace, used by vm.make
# We build libjvm_dtrace/libjvm_db/dtrace for COMPILER1 and COMPILER2
# but not for CORE or KERNEL configurations.
ifneq ("${TYPE}", "CORE")
ifneq ("${TYPE}", "KERNEL")
ifeq ($(OS_VENDOR), Darwin)
# we build dtrace for macosx using USDT2 probes
DtraceOutDir = $(GENERATED)/dtracefiles
# Bsd does not build libjvm_db, does not compile on macosx
# disabled in build: rule in vm.make
JVM_DB = libjvm_db
#LIBJVM_DB = libjvm_db.dylib
LIBJVM_DB = libjvm$(G_SUFFIX)_db.dylib
JVM_DTRACE = jvm_dtrace
#LIBJVM_DTRACE = libjvm_dtrace.dylib
LIBJVM_DTRACE = libjvm$(G_SUFFIX)_dtrace.dylib
JVMOFFS = JvmOffsets
JVMOFFS.o = $(JVMOFFS).o
GENOFFS = generate$(JVMOFFS)
DTRACE_SRCDIR = $(GAMMADIR)/src/os/$(Platform_os_family)/dtrace
DTRACE = dtrace
DTRACE.o = $(DTRACE).o
# to remove '-g' option which causes link problems
# also '-z nodefs' is used as workaround
GENOFFS_CFLAGS = $(shell echo $(CFLAGS) | sed -e 's/ -g / /g' -e 's/ -g0 / /g';)
ifdef LP64
DTRACE_OPTS = -D_LP64
endif
# making libjvm_db
# Use mapfile with libjvm_db.so
LIBJVM_DB_MAPFILE = # no mapfile for usdt2 # $(MAKEFILES_DIR)/mapfile-vers-jvm_db
#LFLAGS_JVM_DB += $(MAPFLAG:FILENAME=$(LIBJVM_DB_MAPFILE))
# Use mapfile with libjvm_dtrace.so
LIBJVM_DTRACE_MAPFILE = # no mapfile for usdt2 # $(MAKEFILES_DIR)/mapfile-vers-jvm_dtrace
#LFLAGS_JVM_DTRACE += $(MAPFLAG:FILENAME=$(LIBJVM_DTRACE_MAPFILE))
LFLAGS_JVM_DB += $(PICFLAG) # -D_REENTRANT
LFLAGS_JVM_DTRACE += $(PICFLAG) # -D_REENTRANT
ISA = $(subst i386,i486,$(BUILDARCH))
# Making 64/libjvm_db.so: 64-bit version of libjvm_db.so which handles 32-bit libjvm.so
ifneq ("${ISA}","${BUILDARCH}")
XLIBJVM_DB = 64/$(LIBJVM_DB)
XLIBJVM_DB_G = 64/$(LIBJVM_DB_G)
XLIBJVM_DTRACE = 64/$(LIBJVM_DTRACE)
XLIBJVM_DTRACE_G = 64/$(LIBJVM_DTRACE_G)
XARCH = $(subst sparcv9,v9,$(shell echo $(ISA)))
$(XLIBJVM_DB): $(DTRACE_SRCDIR)/$(JVM_DB).c $(JVMOFFS).h $(LIBJVM_DB_MAPFILE)
@echo Making $@
$(QUIETLY) mkdir -p 64/ ; \
$(CC) $(SYMFLAG) -xarch=$(XARCH) -D$(TYPE) -I. -I$(GENERATED) \
$(SHARED_FLAG) $(LFLAGS_JVM_DB) -o $@ $(DTRACE_SRCDIR)/$(JVM_DB).c #-lc
# [ -f $(XLIBJVM_DB_G) ] || { ln -s $(LIBJVM_DB) $(XLIBJVM_DB_G); }
$(XLIBJVM_DTRACE): $(DTRACE_SRCDIR)/$(JVM_DTRACE).c $(DTRACE_SRCDIR)/$(JVM_DTRACE).h $(LIBJVM_DTRACE_MAPFILE)
@echo Making $@
$(QUIETLY) mkdir -p 64/ ; \
$(CC) $(SYMFLAG) -xarch=$(XARCH) -D$(TYPE) -I. \
$(SHARED_FLAG) $(LFLAGS_JVM_DTRACE) -o $@ $(DTRACE_SRCDIR)/$(JVM_DTRACE).c #-lc -lthread -ldoor
# [ -f $(XLIBJVM_DTRACE_G) ] || { ln -s $(LIBJVM_DTRACE) $(XLIBJVM_DTRACE_G); }
endif # ifneq ("${ISA}","${BUILDARCH}")
LFLAGS_GENOFFS += -L.
lib$(GENOFFS).dylib: $(DTRACE_SRCDIR)/$(GENOFFS).cpp $(DTRACE_SRCDIR)/$(GENOFFS).h \
$(LIBJVM.o)
$(QUIETLY) $(CCC) $(CPPFLAGS) $(GENOFFS_CFLAGS) $(SHARED_FLAG) $(PICFLAG) \
$(LFLAGS_GENOFFS) -o $@ $(DTRACE_SRCDIR)/$(GENOFFS).cpp -ljvm
$(GENOFFS): $(DTRACE_SRCDIR)/$(GENOFFS)Main.c lib$(GENOFFS).dylib
$(QUIETLY) $(LINK.CC) -o $@ $(DTRACE_SRCDIR)/$(GENOFFS)Main.c \
./lib$(GENOFFS).dylib
# $@.tmp is created first to avoid an empty $(JVMOFFS).h if an error occurs.
$(JVMOFFS).h: $(GENOFFS)
$(QUIETLY) DYLD_LIBRARY_PATH=. ./$(GENOFFS) -header > $@.tmp; touch $@; \
if [ `diff $@.tmp $@ > /dev/null 2>&1; echo $$?` -ne 0 ] ; \
then rm -f $@; mv $@.tmp $@; \
else rm -f $@.tmp; \
fi
$(JVMOFFS)Index.h: $(GENOFFS)
$(QUIETLY) DYLD_LIBRARY_PATH=. ./$(GENOFFS) -index > $@.tmp; touch $@; \
if [ `diff $@.tmp $@ > /dev/null 2>&1; echo $$?` -ne 0 ] ; \
then rm -f $@; mv $@.tmp $@; \
else rm -f $@.tmp; \
fi
$(JVMOFFS).cpp: $(GENOFFS) $(JVMOFFS).h $(JVMOFFS)Index.h
$(QUIETLY) DYLD_LIBRARY_PATH=. ./$(GENOFFS) -table > $@.tmp; touch $@; \
if [ `diff $@.tmp $@ > /dev/null 2>&1; echo $$?` -ne 0 ] ; \
then rm -f $@; mv $@.tmp $@; \
else rm -f $@.tmp; \
fi
$(JVMOFFS.o): $(JVMOFFS).h $(JVMOFFS).cpp
$(QUIETLY) $(CCC) -c -I. -o $@ $(ARCHFLAG) -D$(TYPE) $(JVMOFFS).cpp
$(LIBJVM_DB): $(DTRACE_SRCDIR)/$(JVM_DB).c $(JVMOFFS.o) $(XLIBJVM_DB) $(LIBJVM_DB_MAPFILE)
@echo Making $@
$(QUIETLY) $(CC) $(SYMFLAG) $(ARCHFLAG) -D$(TYPE) -I. -I$(GENERATED) \
$(SHARED_FLAG) $(LFLAGS_JVM_DB) -o $@ $(DTRACE_SRCDIR)/$(JVM_DB).c -Wall # -lc
# [ -f $(LIBJVM_DB_G) ] || { ln -s $@ $(LIBJVM_DB_G); }
$(LIBJVM_DTRACE): $(DTRACE_SRCDIR)/$(JVM_DTRACE).c $(XLIBJVM_DTRACE) $(DTRACE_SRCDIR)/$(JVM_DTRACE).h $(LIBJVM_DTRACE_MAPFILE)
@echo Making $@
$(QUIETLY) $(CC) $(SYMFLAG) $(ARCHFLAG) -D$(TYPE) -I. \
$(SHARED_FLAG) $(LFLAGS_JVM_DTRACE) -o $@ $(DTRACE_SRCDIR)/$(JVM_DTRACE).c #-lc -lthread -ldoor
# [ -f $(LIBJVM_DTRACE_G) ] || { ln -s $@ $(LIBJVM_DTRACE_G); }
#$(DTRACE).d: $(DTRACE_SRCDIR)/hotspot.d $(DTRACE_SRCDIR)/hotspot_jni.d \
# $(DTRACE_SRCDIR)/hs_private.d $(DTRACE_SRCDIR)/jhelper.d
# $(QUIETLY) cat $^ > $@
$(DtraceOutDir):
mkdir $(DtraceOutDir)
$(DtraceOutDir)/hotspot.h: $(DTRACE_SRCDIR)/hotspot.d | $(DtraceOutDir)
$(QUIETLY) $(DTRACE_PROG) $(DTRACE_OPTS) -C -I. -h -o $@ -s $(DTRACE_SRCDIR)/hotspot.d
$(DtraceOutDir)/hotspot_jni.h: $(DTRACE_SRCDIR)/hotspot_jni.d | $(DtraceOutDir)
$(QUIETLY) $(DTRACE_PROG) $(DTRACE_OPTS) -C -I. -h -o $@ -s $(DTRACE_SRCDIR)/hotspot_jni.d
$(DtraceOutDir)/hs_private.h: $(DTRACE_SRCDIR)/hs_private.d | $(DtraceOutDir)
$(QUIETLY) $(DTRACE_PROG) $(DTRACE_OPTS) -C -I. -h -o $@ -s $(DTRACE_SRCDIR)/hs_private.d
$(DtraceOutDir)/jhelper.h: $(DTRACE_SRCDIR)/jhelper.d $(JVMOFFS).o | $(DtraceOutDir)
$(QUIETLY) $(DTRACE_PROG) $(DTRACE_OPTS) -C -I. -h -o $@ -s $(DTRACE_SRCDIR)/jhelper.d
# jhelper currently disabled
dtrace_gen_headers: $(DtraceOutDir)/hotspot.h $(DtraceOutDir)/hotspot_jni.h $(DtraceOutDir)/hs_private.h
DTraced_Files = ciEnv.o \
classLoadingService.o \
compileBroker.o \
hashtable.o \
instanceKlass.o \
java.o \
jni.o \
jvm.o \
memoryManager.o \
nmethod.o \
objectMonitor.o \
runtimeService.o \
sharedRuntime.o \
synchronizer.o \
thread.o \
unsafe.o \
vmThread.o \
vmCMSOperations.o \
vmPSOperations.o \
vmGCOperations.o \
# Dtrace is available, so we build $(DTRACE.o)
#$(DTRACE.o): $(DTRACE).d $(JVMOFFS).h $(JVMOFFS)Index.h $(DTraced_Files)
# @echo Compiling $(DTRACE).d
# $(QUIETLY) $(DTRACE_PROG) $(DTRACE_OPTS) -C -I. -G -xlazyload -o $@ -s $(DTRACE).d \
# $(DTraced_Files) ||\
# STATUS=$$?;\
# if [ x"$$STATUS" = x"1" -a \
# x`uname -r` = x"5.10" -a \
# x`uname -p` = x"sparc" ]; then\
# echo "*****************************************************************";\
# echo "* If you are building server compiler, and the error message is ";\
# echo "* \"incorrect ELF machine type...\", you have run into solaris bug ";\
# echo "* 6213962, \"dtrace -G doesn't work on sparcv8+ object files\".";\
# echo "* Either patch/upgrade your system (>= S10u1_15), or set the ";\
# echo "* environment variable HOTSPOT_DISABLE_DTRACE_PROBES to disable ";\
# echo "* dtrace probes for this build.";\
# echo "*****************************************************************";\
# fi;\
# exit $$STATUS
# Since some DTraced_Files are in LIBJVM.o and they are touched by this
# command, and libgenerateJvmOffsets.so depends on LIBJVM.o, 'make' will
# think it needs to rebuild libgenerateJvmOffsets.so and thus JvmOffsets*
# files, but it doesn't, so we touch the necessary files to prevent later
# recompilation. Note: we only touch the necessary files if they already
# exist in order to close a race where an empty file can be created
# before the real build rule is executed.
# But, we can't touch the *.h files: This rule depends
# on them, and that would cause an infinite cycle of rebuilding.
# Neither the *.h or *.ccp files need to be touched, since they have
# rules which do not update them when the generator file has not
# changed their contents.
# $(QUIETLY) if [ -f lib$(GENOFFS).so ]; then touch lib$(GENOFFS).so; fi
# $(QUIETLY) if [ -f $(GENOFFS) ]; then touch $(GENOFFS); fi
# $(QUIETLY) if [ -f $(JVMOFFS.o) ]; then touch $(JVMOFFS.o); fi
.PHONY: dtraceCheck
#SYSTEM_DTRACE_H = /usr/include/dtrace.h
SYSTEM_DTRACE_PROG = /usr/sbin/dtrace
#PATCH_DTRACE_PROG = /opt/SUNWdtrd/sbin/dtrace
systemDtraceFound := $(wildcard ${SYSTEM_DTRACE_PROG})
#patchDtraceFound := $(wildcard ${PATCH_DTRACE_PROG})
#systemDtraceHdrFound := $(wildcard $(SYSTEM_DTRACE_H))
#ifneq ("$(systemDtraceHdrFound)", "")
#CFLAGS += -DHAVE_DTRACE_H
#endif
#ifneq ("$(patchDtraceFound)", "")
#DTRACE_PROG=$(PATCH_DTRACE_PROG)
#DTRACE_INCL=-I/opt/SUNWdtrd/include
#else
ifneq ("$(systemDtraceFound)", "")
DTRACE_PROG=$(SYSTEM_DTRACE_PROG)
else
endif # ifneq ("$(systemDtraceFound)", "")
#endif # ifneq ("$(patchDtraceFound)", "")
ifneq ("${DTRACE_PROG}", "")
ifeq ("${HOTSPOT_DISABLE_DTRACE_PROBES}", "")
DTRACE_OBJS = $(DTRACE.o) #$(JVMOFFS.o)
CFLAGS += -DDTRACE_ENABLED #$(DTRACE_INCL)
#clangCFLAGS += -DDTRACE_ENABLED -fno-optimize-sibling-calls
#MAPFILE_DTRACE_OPT = $(MAPFILE_DTRACE)
dtraceCheck:
dtrace_stuff: dtrace_gen_headers
$(QUIETLY) echo "dtrace headers generated"
else # manually disabled
dtraceCheck:
$(QUIETLY) echo "**NOTICE** Dtrace support disabled via environment variable"
dtrace_stuff:
endif # ifeq ("${HOTSPOT_DISABLE_DTRACE_PROBES}", "")
else # No dtrace program found
dtraceCheck:
$(QUIETLY) echo "**NOTICE** Dtrace support disabled: not supported by system"
dtrace_stuff:
endif # ifneq ("${dtraceFound}", "")
endif # ifeq ($(OS_VENDOR), Darwin)
else # KERNEL build
dtraceCheck:
$(QUIETLY) echo "**NOTICE** Dtrace support disabled for KERNEL builds"
endif # ifneq ("${TYPE}", "KERNEL")
else # CORE build
dtraceCheck:
$(QUIETLY) echo "**NOTICE** Dtrace support disabled for CORE builds"
endif # ifneq ("${TYPE}", "CORE")
......@@ -30,17 +30,49 @@ OS_VENDOR = $(shell uname -s)
# When cross-compiling the ALT_COMPILER_PATH points
# to the cross-compilation toolset
ifdef CROSS_COMPILE_ARCH
CXX = $(ALT_COMPILER_PATH)/g++
CPP = $(ALT_COMPILER_PATH)/g++
CC = $(ALT_COMPILER_PATH)/gcc
HOSTCPP = g++
HOSTCC = gcc
else
CXX ?= g++
CPP = $(CXX)
CC ?= gcc
HOSTCPP = $(CPP)
HOSTCC = $(CPP)
CPP = $(ALT_COMPILER_PATH)/g++
CC = $(ALT_COMPILER_PATH)/gcc
HOSTCPP = g++
HOSTCC = gcc
else ifneq ($(OS_VENDOR), Darwin)
CXX = g++
CPP = $(CXX)
CC = gcc
HOSTCPP = $(CPP)
HOSTCC = $(CC)
endif
# i486 hotspot requires -mstackrealign on Darwin.
# llvm-gcc supports this in Xcode 3.2.6 and 4.0.
# gcc-4.0 supports this on earlier versions.
# Prefer llvm-gcc where available.
ifeq ($(OS_VENDOR), Darwin)
ifeq ($(origin CXX), default)
CXX = llvm-g++
endif
ifeq ($(origin CC), default)
CC = llvm-gcc
endif
CPP = $(CXX)
ifeq ($(ARCH), i486)
LLVM_SUPPORTS_STACKREALIGN := $(shell \
[ "0"`llvm-gcc -v 2>&1 | grep LLVM | sed -E "s/.*LLVM build ([0-9]+).*/\1/"` -gt "2333" ] \
&& echo true || echo false)
ifeq ($(LLVM_SUPPORTS_STACKREALIGN), true)
CXX32 ?= llvm-g++
CC32 ?= llvm-gcc
else
CXX32 ?= g++-4.0
CC32 ?= gcc-4.0
endif
CPP = $(CXX32)
CC = $(CC32)
endif
HOSTCPP = $(CPP)
HOSTCC = $(CC)
endif
AS = $(CC) -c -x assembler-with-cpp
......@@ -130,7 +162,9 @@ else
endif
# Compiler warnings are treated as errors
WARNINGS_ARE_ERRORS = -Werror
ifneq ($(COMPILER_WARNINGS_FATAL),false)
WARNINGS_ARE_ERRORS = -Werror
endif
# Except for a few acceptable ones
# Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit
......@@ -152,7 +186,13 @@ endif
# The flags to use for an Optimized g++ build
OPT_CFLAGS += -O3
ifeq ($(OS_VENDOR), Darwin)
# use -Os by default, unless -O3 can be proved to be worth the cost, as per policy
# <http://wikis.sun.com/display/OpenJDK/Mac+OS+X+Port+Compilers>
OPT_CFLAGS += -Os
else
OPT_CFLAGS += -O3
endif
# Hotspot uses very unstrict aliasing turn this optimization off
OPT_CFLAGS += -fno-strict-aliasing
......@@ -212,7 +252,7 @@ ifeq ($(OS_VENDOR), Darwin)
SONAMEFLAG =
# Build shared library
SHARED_FLAG = -dynamiclib $(VM_PICFLAG)
SHARED_FLAG = -Wl,-install_name,@rpath/$(@F) -dynamiclib -compatibility_version 1.0.0 -current_version 1.0.0 $(VM_PICFLAG)
# Keep symbols even they are not used
#AOUT_FLAGS += -Xlinker -export-dynamic
......
......@@ -38,18 +38,16 @@ TOPDIR = $(shell echo `pwd`)
GENERATED = $(TOPDIR)/../generated
# tools.jar is needed by the JDI - SA binding
SA_CLASSPATH = $(BOOT_JAVA_HOME)/lib/tools.jar
ifeq ($(SA_APPLE_BOOT_JAVA),true)
SA_CLASSPATH = $(BOOT_JAVA_HOME)/bundle/Classes/classes.jar
else
SA_CLASSPATH = $(BOOT_JAVA_HOME)/lib/tools.jar
endif
# TODO: if it's a modules image, check if SA module is installed.
MODULELIB_PATH= $(BOOT_JAVA_HOME)/lib/modules
# gnumake 3.78.1 does not accept the *s that
# are in AGENT_FILES1 and AGENT_FILES2, so use the shell to expand them
AGENT_FILES1 := $(shell /bin/test -d $(AGENT_DIR) && /bin/ls $(AGENT_FILES1))
AGENT_FILES2 := $(shell /bin/test -d $(AGENT_DIR) && /bin/ls $(AGENT_FILES2))
AGENT_FILES1_LIST := $(GENERATED)/agent1.classes.list
AGENT_FILES2_LIST := $(GENERATED)/agent2.classes.list
AGENT_FILES_LIST := $(GENERATED)/agent.classes.list
SA_CLASSDIR = $(GENERATED)/saclasses
......@@ -68,7 +66,7 @@ all:
$(MAKE) -f sa.make $(GENERATED)/sa-jdi.jar; \
fi
$(GENERATED)/sa-jdi.jar: $(AGENT_FILES1) $(AGENT_FILES2)
$(GENERATED)/sa-jdi.jar: $(AGENT_FILES)
$(QUIETLY) echo "Making $@"
$(QUIETLY) if [ "$(BOOT_JAVA_HOME)" = "" ]; then \
echo "ALT_BOOTDIR, BOOTDIR or JAVA_HOME needs to be defined to build SA"; \
......@@ -82,7 +80,6 @@ $(GENERATED)/sa-jdi.jar: $(AGENT_FILES1) $(AGENT_FILES2)
$(QUIETLY) if [ ! -d $(SA_CLASSDIR) ] ; then \
mkdir -p $(SA_CLASSDIR); \
fi
# Note: When indented, make tries to execute the '$(shell' comment.
# In some environments, cmd processors have limited line length.
# To prevent the javac invocation in the next block from using
......@@ -93,13 +90,12 @@ $(GENERATED)/sa-jdi.jar: $(AGENT_FILES1) $(AGENT_FILES2)
# the initialization of the lists is also done in the same phase
# using '$(shell rm ...' instead of using the more traditional
# 'rm ...' rule.
$(shell rm -rf $(AGENT_FILES1_LIST) $(AGENT_FILES2_LIST))
$(foreach file,$(AGENT_FILES1),$(shell echo $(file) >> $(AGENT_FILES1_LIST)))
$(foreach file,$(AGENT_FILES2),$(shell echo $(file) >> $(AGENT_FILES2_LIST)))
$(QUIETLY) $(REMOTE) $(COMPILE.JAVAC) -classpath $(SA_CLASSPATH) -sourcepath $(AGENT_SRC_DIR) -d $(SA_CLASSDIR) @$(AGENT_FILES1_LIST)
$(QUIETLY) $(REMOTE) $(COMPILE.JAVAC) -classpath $(SA_CLASSPATH) -sourcepath $(AGENT_SRC_DIR) -d $(SA_CLASSDIR) @$(AGENT_FILES2_LIST)
$(shell rm -rf $(AGENT_FILES_LIST))
# gnumake 3.78.1 does not accept the *'s that
# are in AGENT_FILES, so use the shell to expand them.
# Be extra carefull to not produce too long command lines in the shell!
$(foreach file,$(AGENT_FILES),$(shell ls -1 $(file) >> $(AGENT_FILES_LIST)))
$(QUIETLY) $(REMOTE) $(COMPILE.JAVAC) -classpath $(SA_CLASSPATH) -sourcepath $(AGENT_SRC_DIR) -d $(SA_CLASSDIR) @$(AGENT_FILES_LIST)
$(QUIETLY) $(REMOTE) $(COMPILE.RMIC) -classpath $(SA_CLASSDIR) -d $(SA_CLASSDIR) sun.jvm.hotspot.debugger.remote.RemoteDebuggerServer
$(QUIETLY) echo "$(SA_BUILD_VERSION_PROP)" > $(SA_PROPERTIES)
$(QUIETLY) rm -f $(SA_CLASSDIR)/sun/jvm/hotspot/utilities/soql/sa.js
......@@ -118,4 +114,4 @@ $(GENERATED)/sa-jdi.jar: $(AGENT_FILES1) $(AGENT_FILES2)
clean:
rm -rf $(SA_CLASSDIR)
rm -rf $(GENERATED)/sa-jdi.jar
rm -rf $(AGENT_FILES1_LIST) $(AGENT_FILES2_LIST)
rm -rf $(AGENT_FILES_LIST)
......@@ -40,20 +40,29 @@ AGENT_DIR = $(GAMMADIR)/agent
SASRCDIR = $(AGENT_DIR)/src/os/$(Platform_os_family)
# disable building saproc until hsearch_r license issues are resolved
#ifeq ($(OS_VENDOR), FreeBSD)
#SASRCFILES = $(SASRCDIR)/salibelf.c \
# $(SASRCDIR)/symtab.c \
# $(SASRCDIR)/libproc_impl.c \
# $(SASRCDIR)/ps_proc.c \
# $(SASRCDIR)/ps_core.c \
# $(SASRCDIR)/hsearch_r.c \
# $(SASRCDIR)/BsdDebuggerLocal.c
#SALIBS = -lutil -lthread_db
#else
SASRCFILES = $(SASRCDIR)/StubDebuggerLocal.c
SALIBS =
#endif
NON_STUB_SASRCFILES = $(SASRCDIR)/salibelf.c \
$(SASRCDIR)/symtab.c \
$(SASRCDIR)/libproc_impl.c \
$(SASRCDIR)/ps_proc.c \
$(SASRCDIR)/ps_core.c \
$(SASRCDIR)/BsdDebuggerLocal.c
ifeq ($(OS_VENDOR), FreeBSD)
SASRCFILES = $(NON_STUB_SASRCFILES)
SALIBS = -lutil -lthread_db
SAARCH = $(ARCHFLAG)
else
ifeq ($(OS_VENDOR), Darwin)
SASRCFILES = $(SASRCDIR)/MacosxDebuggerLocal.m
SALIBS = -g -framework Foundation -F/System/Library/Frameworks/JavaVM.framework/Frameworks -framework JavaNativeFoundation -framework Security -framework CoreFoundation
#objc compiler blows up on -march=i586, perhaps it should not be included in the macosx intel 32-bit C++ compiles?
SAARCH = $(subst -march=i586,,$(ARCHFLAG))
else
SASRCFILES = $(SASRCDIR)/StubDebuggerLocal.c
SALIBS =
SAARCH = $(ARCHFLAG)
endif
endif
SAMAPFILE = $(SASRCDIR)/mapfile
......@@ -79,6 +88,15 @@ SA_LFLAGS = $(MAPFLAG:FILENAME=$(SAMAPFILE))
endif
SA_LFLAGS += $(LDFLAGS_HASH_STYLE)
ifeq ($(OS_VENDOR), Darwin)
BOOT_JAVA_INCLUDES = -I$(BOOT_JAVA_HOME)/include \
-I$(BOOT_JAVA_HOME)/include/$(shell uname -s | tr "[:upper:]" "[:lower:]") \
-I/System/Library/Frameworks/JavaVM.framework/Headers
else
BOOT_JAVA_INCLUDES = -I$(BOOT_JAVA_HOME)/include \
-I$(BOOT_JAVA_HOME)/include/$(shell uname -s | tr "[:upper:]" "[:lower:]")
endif
$(LIBSAPROC): $(SASRCFILES) $(SAMAPFILE)
$(QUIETLY) if [ "$(BOOT_JAVA_HOME)" = "" ]; then \
echo "ALT_BOOTDIR, BOOTDIR or JAVA_HOME needs to be defined to build SA"; \
......@@ -86,11 +104,10 @@ $(LIBSAPROC): $(SASRCFILES) $(SAMAPFILE)
fi
@echo Making SA debugger back-end...
$(QUIETLY) $(CC) -D$(BUILDARCH) -D_GNU_SOURCE \
$(SYMFLAG) $(ARCHFLAG) $(SHARED_FLAG) $(PICFLAG) \
$(SYMFLAG) $(SAARCH) $(SHARED_FLAG) $(PICFLAG) \
-I$(SASRCDIR) \
-I$(GENERATED) \
-I$(BOOT_JAVA_HOME)/include \
-I$(BOOT_JAVA_HOME)/include/$(shell uname -s | tr "[:upper:]" "[:lower:]") \
$(BOOT_JAVA_INCLUDES) \
$(SASRCFILES) \
$(SA_LFLAGS) \
$(SA_DEBUG_CFLAGS) \
......
......@@ -82,7 +82,7 @@ default: vm_build_preliminaries the_vm
@echo All done.
# This is an explicit dependency for the sake of parallel makes.
vm_build_preliminaries: checks $(Cached_plat) $(AD_Files_If_Required) jvmti_stuff sa_stuff
vm_build_preliminaries: checks $(Cached_plat) $(AD_Files_If_Required) jvmti_stuff sa_stuff dtrace_stuff
@# We need a null action here, so implicit rules don't get consulted.
$(Cached_plat): $(Plat_File)
......@@ -96,6 +96,15 @@ ad_stuff: $(Cached_plat) $(adjust-mflags)
jvmti_stuff: $(Cached_plat) $(adjust-mflags)
@$(MAKE) -f jvmti.make $(MFLAGS-adjusted)
ifeq ($(OS_VENDOR), Darwin)
# generate dtrace header files
dtrace_stuff: $(Cached_plat) $(adjust-mflags)
@$(MAKE) -f dtrace.make dtrace_stuff $(MFLAGS-adjusted) GENERATED=$(GENERATED)
else
dtrace_stuff:
@# We need a null action here, so implicit rules don't get consulted.
endif
# generate SA jar files and native header
sa_stuff:
@$(MAKE) -f sa.make $(MFLAGS-adjusted)
......
......@@ -108,6 +108,7 @@ LFLAGS += $(EXTRA_CFLAGS)
# Don't set excutable bit on stack segment
# the same could be done by separate execstack command
# Darwin is non-executable-stack by default
ifneq ($(OS_VENDOR), Darwin)
LFLAGS += -Xlinker -z -Xlinker noexecstack
endif
......@@ -322,7 +323,16 @@ include $(MAKEFILES_DIR)/saproc.make
#----------------------------------------------------------------------
ifeq ($(OS_VENDOR), Darwin)
$(LIBJVM).dSYM: $(LIBJVM)
dsymutil $(LIBJVM)
# no launcher or libjvm_db for macosx
build: $(LIBJVM) $(LIBJSIG) $(BUILDLIBSAPROC) dtraceCheck $(LIBJVM).dSYM
echo "Doing vm.make build:"
else
build: $(LIBJVM) $(LAUNCHER) $(LIBJSIG) $(LIBJVM_DB) $(BUILDLIBSAPROC)
endif
install: install_jvm install_jsig install_saproc
......
......@@ -281,6 +281,13 @@ EXPORT_JRE_BIN_DIR = $(EXPORT_JRE_DIR)/bin
EXPORT_JRE_LIB_DIR = $(EXPORT_JRE_DIR)/lib
EXPORT_JRE_LIB_ARCH_DIR = $(EXPORT_JRE_LIB_DIR)/$(LIBARCH)
# non-universal macosx builds need to appear universal
ifeq ($(OS_VENDOR), Darwin)
ifneq ($(MACOSX_UNIVERSAL), true)
EXPORT_JRE_LIB_ARCH_DIR = $(EXPORT_JRE_LIB_DIR)
endif
endif
# Common export list of files
EXPORT_LIST += $(EXPORT_INCLUDE_DIR)/jvmti.h
EXPORT_LIST += $(EXPORT_INCLUDE_DIR)/jvmticmlr.h
......
Copyright (c) %YEARS%, Oracle and/or its affiliates. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of Oracle nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
......@@ -38,10 +38,14 @@
#define JNICALL
typedef int jint;
#ifdef _LP64
#if defined(_LP64) && !defined(__APPLE__)
typedef long jlong;
#else
/*
* On _LP64 __APPLE__ "long" and "long long" are both 64 bits,
* but we use the "long long" typedef to avoid complaints from
* the __APPLE__ compiler about fprintf formats.
*/
typedef long long jlong;
#endif
......
/*
* 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
* 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 is to provide sanity check in jhelper.d which compares SCCS
* versions of generateJvmOffsets.cpp used to create and extract
* contents of __JvmOffsets[] table.
* The __JvmOffsets[] table is located in generated JvmOffsets.cpp.
*
* GENOFFS_SCCS_VER 34
*/
#include "generateJvmOffsets.h"
/* A workaround for private and protected fields */
#define private public
#define protected public
// not on macosx #include <proc_service.h>
#include "code/codeBlob.hpp"
#include "code/nmethod.hpp"
#include "code/pcDesc.hpp"
#include "gc_interface/collectedHeap.hpp"
#include "memory/heap.hpp"
#include "memory/memRegion.hpp"
#include "memory/universe.hpp"
#include "oops/constMethodOop.hpp"
#include "oops/klass.hpp"
#include "oops/methodOop.hpp"
#include "oops/oop.hpp"
#include "oops/symbol.hpp"
#include "runtime/virtualspace.hpp"
#include "runtime/vmStructs.hpp"
#include "utilities/accessFlags.hpp"
#include "utilities/globalDefinitions.hpp"
// These are defined somewhere for Solaris
#define PR_MODEL_ILP32 1
#define PR_MODEL_LP64 2
#ifdef COMPILER1
#if defined(DEBUG) || defined(FASTDEBUG)
/*
* To avoid the most part of potential link errors
* we link this program with -z nodefs .
*
* But for 'debug1' and 'fastdebug1' we still have to provide
* a particular workaround for the following symbols bellow.
* It will be good to find out a generic way in the future.
*/
#pragma weak tty
#pragma weak CMSExpAvgFactor
#if defined(i386) || defined(__i386) || defined(__amd64)
#pragma weak noreg
#endif /* i386 */
LIR_Opr LIR_OprFact::illegalOpr = (LIR_Opr) 0;
address StubRoutines::_call_stub_return_address = NULL;
StubQueue* AbstractInterpreter::_code = NULL;
#endif /* defined(DEBUG) || defined(FASTDEBUG) */
#endif /* COMPILER1 */
#define GEN_OFFS(Type,Name) \
switch(gen_variant) { \
case GEN_OFFSET: \
printf("#define OFFSET_%-33s %ld\n", \
#Type #Name, offset_of(Type, Name)); \
break; \
case GEN_INDEX: \
printf("#define IDX_OFFSET_%-33s %d\n", \
#Type #Name, index++); \
break; \
case GEN_TABLE: \
printf("\tOFFSET_%s,\n", #Type #Name); \
break; \
}
#define GEN_SIZE(Type) \
switch(gen_variant) { \
case GEN_OFFSET: \
printf("#define SIZE_%-35s %ld\n", \
#Type, sizeof(Type)); \
break; \
case GEN_INDEX: \
printf("#define IDX_SIZE_%-35s %d\n", \
#Type, index++); \
break; \
case GEN_TABLE: \
printf("\tSIZE_%s,\n", #Type); \
break; \
}
#define GEN_VALUE(String,Value) \
switch(gen_variant) { \
case GEN_OFFSET: \
printf("#define %-40s %d\n", #String, Value); \
break; \
case GEN_INDEX: \
printf("#define IDX_%-40s %d\n", #String, index++); \
break; \
case GEN_TABLE: \
printf("\t" #String ",\n"); \
break; \
}
void gen_prologue(GEN_variant gen_variant) {
const char *suffix;
switch(gen_variant) {
case GEN_OFFSET: suffix = ".h"; break;
case GEN_INDEX: suffix = "Index.h"; break;
case GEN_TABLE: suffix = ".cpp"; break;
}
printf("/*\n");
printf(" * JvmOffsets%s !!!DO NOT EDIT!!! \n", suffix);
printf(" * The generateJvmOffsets program generates this file!\n");
printf(" */\n\n");
switch(gen_variant) {
case GEN_OFFSET:
case GEN_INDEX:
break;
case GEN_TABLE:
printf("#include \"JvmOffsets.h\"\n");
printf("\n");
printf("int __JvmOffsets[] = {\n");
break;
}
}
void gen_epilogue(GEN_variant gen_variant) {
if (gen_variant != GEN_TABLE) {
return;
}
printf("};\n\n");
return;
}
int generateJvmOffsets(GEN_variant gen_variant) {
int index = 0; /* It is used to generate JvmOffsetsIndex.h */
int pointer_size = sizeof(void *);
int data_model = (pointer_size == 4) ? PR_MODEL_ILP32 : PR_MODEL_LP64;
gen_prologue(gen_variant);
GEN_VALUE(DATA_MODEL, data_model);
GEN_VALUE(POINTER_SIZE, pointer_size);
#if defined(TIERED)
GEN_VALUE(COMPILER, 3);
#elif COMPILER1
GEN_VALUE(COMPILER, 1);
#elif COMPILER2
GEN_VALUE(COMPILER, 2);
#else
GEN_VALUE(COMPILER, 0);
#endif // COMPILER1 && COMPILER2
printf("\n");
GEN_OFFS(CollectedHeap, _reserved);
GEN_OFFS(MemRegion, _start);
GEN_OFFS(MemRegion, _word_size);
GEN_SIZE(HeapWord);
printf("\n");
GEN_OFFS(VMStructEntry, typeName);
GEN_OFFS(VMStructEntry, fieldName);
GEN_OFFS(VMStructEntry, address);
GEN_SIZE(VMStructEntry);
printf("\n");
GEN_VALUE(MAX_METHOD_CODE_SIZE, max_method_code_size);
#if defined(sparc) || defined(__sparc)
GEN_VALUE(OFFSET_interpreter_frame_method, 2 * pointer_size); /* L2 in saved window */
GEN_VALUE(OFFSET_interpreter_frame_sender_sp, 13 * pointer_size); /* I5 in saved window */
// Fake value for consistency. It is not going to be used.
GEN_VALUE(OFFSET_interpreter_frame_bcx_offset, 0xFFFF);
#elif defined(i386) || defined(__i386) || defined(__amd64)
GEN_VALUE(OFFSET_interpreter_frame_sender_sp, -1 * pointer_size);
GEN_VALUE(OFFSET_interpreter_frame_method, -3 * pointer_size);
GEN_VALUE(OFFSET_interpreter_frame_bcx_offset, -7 * pointer_size);
#endif
GEN_OFFS(Klass, _name);
GEN_OFFS(constantPoolOopDesc, _pool_holder);
printf("\n");
GEN_VALUE(OFFSET_HeapBlockHeader_used, (int) offset_of(HeapBlock::Header, _used));
GEN_OFFS(oopDesc, _metadata);
printf("\n");
GEN_VALUE(AccessFlags_NATIVE, JVM_ACC_NATIVE);
GEN_VALUE(constMethodOopDesc_has_linenumber_table, constMethodOopDesc::_has_linenumber_table);
GEN_OFFS(AccessFlags, _flags);
GEN_OFFS(Symbol, _length);
GEN_OFFS(Symbol, _body);
printf("\n");
GEN_OFFS(methodOopDesc, _constMethod);
GEN_OFFS(methodOopDesc, _constants);
GEN_OFFS(methodOopDesc, _access_flags);
printf("\n");
GEN_OFFS(constMethodOopDesc, _flags);
GEN_OFFS(constMethodOopDesc, _code_size);
GEN_OFFS(constMethodOopDesc, _name_index);
GEN_OFFS(constMethodOopDesc, _signature_index);
printf("\n");
GEN_OFFS(CodeHeap, _memory);
GEN_OFFS(CodeHeap, _segmap);
GEN_OFFS(CodeHeap, _log2_segment_size);
printf("\n");
GEN_OFFS(VirtualSpace, _low_boundary);
GEN_OFFS(VirtualSpace, _high_boundary);
GEN_OFFS(VirtualSpace, _low);
GEN_OFFS(VirtualSpace, _high);
printf("\n");
GEN_OFFS(CodeBlob, _name);
GEN_OFFS(CodeBlob, _header_size);
GEN_OFFS(CodeBlob, _content_offset);
GEN_OFFS(CodeBlob, _code_offset);
GEN_OFFS(CodeBlob, _data_offset);
GEN_OFFS(CodeBlob, _frame_size);
printf("\n");
GEN_OFFS(nmethod, _method);
GEN_OFFS(nmethod, _oops_offset);
GEN_OFFS(nmethod, _scopes_data_offset);
GEN_OFFS(nmethod, _scopes_pcs_offset);
GEN_OFFS(nmethod, _handler_table_offset);
GEN_OFFS(nmethod, _deoptimize_offset);
GEN_OFFS(nmethod, _orig_pc_offset);
GEN_OFFS(PcDesc, _pc_offset);
GEN_OFFS(PcDesc, _scope_decode_offset);
printf("\n");
GEN_OFFS(NarrowOopStruct, _base);
GEN_OFFS(NarrowOopStruct, _shift);
printf("\n");
GEN_VALUE(SIZE_HeapBlockHeader, (int) sizeof(HeapBlock::Header));
GEN_SIZE(oopDesc);
GEN_SIZE(constantPoolOopDesc);
printf("\n");
GEN_SIZE(PcDesc);
GEN_SIZE(methodOopDesc);
GEN_SIZE(constMethodOopDesc);
GEN_SIZE(nmethod);
GEN_SIZE(CodeBlob);
GEN_SIZE(BufferBlob);
GEN_SIZE(SingletonBlob);
GEN_SIZE(RuntimeStub);
GEN_SIZE(SafepointBlob);
gen_epilogue(gen_variant);
printf("\n");
fflush(stdout);
return 0;
}
/*
* 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 OS_SOLARIS_DTRACE_GENERATEJVMOFFSETS_H
#define OS_SOLARIS_DTRACE_GENERATEJVMOFFSETS_H
#include <stdio.h>
#include <strings.h>
typedef enum GEN_variant {
GEN_OFFSET = 0,
GEN_INDEX = 1,
GEN_TABLE = 2
} GEN_variant;
extern "C" {
int generateJvmOffsets(GEN_variant gen_var);
void gen_prologue(GEN_variant gen_var);
void gen_epilogue(GEN_variant gen_var);
}
#endif // OS_SOLARIS_DTRACE_GENERATEJVMOFFSETS_H
/*
* 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 "generateJvmOffsets.h"
const char *HELP =
"HELP: generateJvmOffsets {-header | -index | -table} \n";
int main(int argc, const char *argv[]) {
GEN_variant gen_var;
if (argc != 2) {
printf("%s", HELP);
return 1;
}
if (0 == strcmp(argv[1], "-header")) {
gen_var = GEN_OFFSET;
}
else if (0 == strcmp(argv[1], "-index")) {
gen_var = GEN_INDEX;
}
else if (0 == strcmp(argv[1], "-table")) {
gen_var = GEN_TABLE;
}
else {
printf("%s", HELP);
return 1;
}
return generateJvmOffsets(gen_var);
}
/*
* Copyright (c) 2005, 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.
*
*/
provider hotspot {
probe class__loaded(char*, uintptr_t, void*, uintptr_t);
probe class__unloaded(char*, uintptr_t, void*, uintptr_t);
probe class__initialization__required(char*, uintptr_t, void*, intptr_t);
probe class__initialization__recursive(char*, uintptr_t, void*, intptr_t,int);
probe class__initialization__concurrent(char*, uintptr_t, void*, intptr_t,int);
probe class__initialization__erroneous(char*, uintptr_t, void*, intptr_t, int);
probe class__initialization__super__failed(char*, uintptr_t, void*, intptr_t,int);
probe class__initialization__clinit(char*, uintptr_t, void*, intptr_t,int);
probe class__initialization__error(char*, uintptr_t, void*, intptr_t,int);
probe class__initialization__end(char*, uintptr_t, void*, intptr_t,int);
probe vm__init__begin();
probe vm__init__end();
probe vm__shutdown();
probe vmops__request(char*, uintptr_t, int);
probe vmops__begin(char*, uintptr_t, int);
probe vmops__end(char*, uintptr_t, int);
probe gc__begin(uintptr_t);
probe gc__end();
probe mem__pool__gc__begin(
char*, uintptr_t, char*, uintptr_t,
uintptr_t, uintptr_t, uintptr_t, uintptr_t);
probe mem__pool__gc__end(
char*, uintptr_t, char*, uintptr_t,
uintptr_t, uintptr_t, uintptr_t, uintptr_t);
probe thread__probe__start(char*, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
probe thread__probe__stop(char*, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
probe thread__sleep__begin(long long);
probe thread__sleep__end(int);
probe thread__yield();
probe thread__park__begin(uintptr_t, int, long long);
probe thread__park__end(uintptr_t);
probe thread__unpark(uintptr_t);
probe method__compile__begin(
const char*, uintptr_t, const char*, uintptr_t, const char*, uintptr_t, const char*, uintptr_t);
probe method__compile__end(
char*, uintptr_t, char*, uintptr_t, char*, uintptr_t,
char*, uintptr_t, uintptr_t);
probe compiled__method__load(
char*, uintptr_t, char*, uintptr_t, char*, uintptr_t, void*, uintptr_t);
probe compiled__method__unload(
char*, uintptr_t, char*, uintptr_t, char*, uintptr_t);
probe monitor__contended__enter(uintptr_t, uintptr_t, char*, uintptr_t);
probe monitor__contended__entered(uintptr_t, uintptr_t, char*, uintptr_t);
probe monitor__contended__exit(uintptr_t, uintptr_t, char*, uintptr_t);
probe monitor__wait(uintptr_t, uintptr_t, char*, uintptr_t, uintptr_t);
probe monitor__probe__waited(uintptr_t, uintptr_t, char*, uintptr_t);
probe monitor__notify(uintptr_t, uintptr_t, char*, uintptr_t);
probe monitor__notifyAll(uintptr_t, uintptr_t, char*, uintptr_t);
probe object__alloc(int, char*, uintptr_t, uintptr_t);
probe method__entry(
int, char*, int, char*, int, char*, int);
probe method__return(
int, char*, int, char*, int, char*, int);
};
#pragma D attributes Evolving/Evolving/Common provider hotspot provider
#pragma D attributes Private/Private/Unknown provider hotspot module
#pragma D attributes Private/Private/Unknown provider hotspot function
#pragma D attributes Evolving/Evolving/Common provider hotspot name
#pragma D attributes Evolving/Evolving/Common provider hotspot args
此差异已折叠。
/*
* Copyright (c) 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.
*
*/
provider hs_private {
probe hashtable__new_entry(void*, uint32_t, uintptr_t, void*);
probe safepoint__begin();
probe safepoint__end();
probe cms__initmark__begin();
probe cms__initmark__end();
probe cms__remark__begin();
probe cms__remark__end();
};
#pragma D attributes Private/Private/Common provider hs_private provider
#pragma D attributes Private/Private/Unknown provider hs_private module
#pragma D attributes Private/Private/Unknown provider hs_private function
#pragma D attributes Private/Private/Common provider hs_private name
#pragma D attributes Private/Private/Common provider hs_private args
/*
* 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
* 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 file is auto-generated */
#include "JvmOffsetsIndex.h"
#define DEBUG
#ifdef DEBUG
#define MARK_LINE this->line = __LINE__
#else
#define MARK_LINE
#endif
#ifdef _LP64
#define STACK_BIAS 0x7ff
#define pointer uint64_t
#else
#define STACK_BIAS 0
#define pointer uint32_t
#endif
extern pointer __JvmOffsets;
extern pointer __1cJCodeCacheF_heap_;
extern pointer __1cIUniverseP_methodKlassObj_;
extern pointer __1cIUniverseO_collectedHeap_;
extern pointer __1cIUniverseL_narrow_oop_;
#ifdef _LP64
extern pointer UseCompressedOops;
#endif
extern pointer __1cHnmethodG__vtbl_;
extern pointer __1cKBufferBlobG__vtbl_;
#define copyin_ptr(ADDR) *(pointer*) copyin((pointer) (ADDR), sizeof(pointer))
#define copyin_uchar(ADDR) *(uchar_t*) copyin((pointer) (ADDR), sizeof(uchar_t))
#define copyin_uint16(ADDR) *(uint16_t*) copyin((pointer) (ADDR), sizeof(uint16_t))
#define copyin_uint32(ADDR) *(uint32_t*) copyin((pointer) (ADDR), sizeof(uint32_t))
#define copyin_int32(ADDR) *(int32_t*) copyin((pointer) (ADDR), sizeof(int32_t))
#define copyin_uint8(ADDR) *(uint8_t*) copyin((pointer) (ADDR), sizeof(uint8_t))
#define SAME(x) x
#define copyin_offset(JVM_CONST) JVM_CONST = \
copyin_int32(JvmOffsetsPtr + SAME(IDX_)JVM_CONST * sizeof(int32_t))
int init_done;
dtrace:helper:ustack:
{
MARK_LINE;
this->done = 0;
/*
* TBD:
* Here we initialize init_done, otherwise jhelper does not work.
* Therefore, copyin_offset() statements work multiple times now.
* There is a hope we could avoid it in the future, and so,
* this initialization can be removed.
*/
init_done = 0;
this->error = (char *) NULL;
this->result = (char *) NULL;
this->methodOop = 0;
this->codecache = 0;
this->klass = (pointer) NULL;
this->vtbl = (pointer) NULL;
this->suffix = '\0';
}
dtrace:helper:ustack:
{
MARK_LINE;
/* Initialization of JvmOffsets constants */
JvmOffsetsPtr = (pointer) &``__JvmOffsets;
}
dtrace:helper:ustack:
/!init_done && !this->done/
{
MARK_LINE;
init_done = 1;
copyin_offset(COMPILER);
copyin_offset(OFFSET_CollectedHeap_reserved);
copyin_offset(OFFSET_MemRegion_start);
copyin_offset(OFFSET_MemRegion_word_size);
copyin_offset(SIZE_HeapWord);
copyin_offset(OFFSET_interpreter_frame_method);
copyin_offset(OFFSET_Klass_name);
copyin_offset(OFFSET_constantPoolOopDesc_pool_holder);
copyin_offset(OFFSET_HeapBlockHeader_used);
copyin_offset(OFFSET_oopDesc_metadata);
copyin_offset(OFFSET_Symbol_length);
copyin_offset(OFFSET_Symbol_body);
copyin_offset(OFFSET_methodOopDesc_constMethod);
copyin_offset(OFFSET_methodOopDesc_constants);
copyin_offset(OFFSET_constMethodOopDesc_name_index);
copyin_offset(OFFSET_constMethodOopDesc_signature_index);
copyin_offset(OFFSET_CodeHeap_memory);
copyin_offset(OFFSET_CodeHeap_segmap);
copyin_offset(OFFSET_CodeHeap_log2_segment_size);
copyin_offset(OFFSET_VirtualSpace_low);
copyin_offset(OFFSET_VirtualSpace_high);
copyin_offset(OFFSET_CodeBlob_name);
copyin_offset(OFFSET_nmethod_method);
copyin_offset(SIZE_HeapBlockHeader);
copyin_offset(SIZE_oopDesc);
copyin_offset(SIZE_constantPoolOopDesc);
copyin_offset(OFFSET_NarrowOopStruct_base);
copyin_offset(OFFSET_NarrowOopStruct_shift);
/*
* The PC to translate is in arg0.
*/
this->pc = arg0;
/*
* The methodOopPtr is in %l2 on SPARC. This can be found at
* offset 8 from the frame pointer on 32-bit processes.
*/
#if defined(__sparc)
this->methodOopPtr = copyin_ptr(arg1 + 2 * sizeof(pointer) + STACK_BIAS);
#elif defined(__i386) || defined(__amd64)
this->methodOopPtr = copyin_ptr(arg1 + OFFSET_interpreter_frame_method);
#else
#error "Don't know architecture"
#endif
this->Universe_methodKlassOop = copyin_ptr(&``__1cIUniverseP_methodKlassObj_);
this->CodeCache_heap_address = copyin_ptr(&``__1cJCodeCacheF_heap_);
/* Reading volatile values */
#ifdef _LP64
this->Use_Compressed_Oops = copyin_uint8(&``UseCompressedOops);
#else
this->Use_Compressed_Oops = 0;
#endif
this->Universe_narrow_oop_base = copyin_ptr(&``__1cIUniverseL_narrow_oop_ +
OFFSET_NarrowOopStruct_base);
this->Universe_narrow_oop_shift = copyin_int32(&``__1cIUniverseL_narrow_oop_ +
OFFSET_NarrowOopStruct_shift);
this->CodeCache_low = copyin_ptr(this->CodeCache_heap_address +
OFFSET_CodeHeap_memory + OFFSET_VirtualSpace_low);
this->CodeCache_high = copyin_ptr(this->CodeCache_heap_address +
OFFSET_CodeHeap_memory + OFFSET_VirtualSpace_high);
this->CodeCache_segmap_low = copyin_ptr(this->CodeCache_heap_address +
OFFSET_CodeHeap_segmap + OFFSET_VirtualSpace_low);
this->CodeCache_segmap_high = copyin_ptr(this->CodeCache_heap_address +
OFFSET_CodeHeap_segmap + OFFSET_VirtualSpace_high);
this->CodeHeap_log2_segment_size = copyin_uint32(
this->CodeCache_heap_address + OFFSET_CodeHeap_log2_segment_size);
/*
* Get Java heap bounds
*/
this->Universe_collectedHeap = copyin_ptr(&``__1cIUniverseO_collectedHeap_);
this->heap_start = copyin_ptr(this->Universe_collectedHeap +
OFFSET_CollectedHeap_reserved +
OFFSET_MemRegion_start);
this->heap_size = SIZE_HeapWord *
copyin_ptr(this->Universe_collectedHeap +
OFFSET_CollectedHeap_reserved +
OFFSET_MemRegion_word_size
);
this->heap_end = this->heap_start + this->heap_size;
}
dtrace:helper:ustack:
/!this->done &&
this->CodeCache_low <= this->pc && this->pc < this->CodeCache_high/
{
MARK_LINE;
this->codecache = 1;
/*
* Find start.
*/
this->segment = (this->pc - this->CodeCache_low) >>
this->CodeHeap_log2_segment_size;
this->block = this->CodeCache_segmap_low;
this->tag = copyin_uchar(this->block + this->segment);
"second";
}
dtrace:helper:ustack:
/!this->done && this->codecache && this->tag > 0/
{
MARK_LINE;
this->tag = copyin_uchar(this->block + this->segment);
this->segment = this->segment - this->tag;
}
dtrace:helper:ustack:
/!this->done && this->codecache && this->tag > 0/
{
MARK_LINE;
this->tag = copyin_uchar(this->block + this->segment);
this->segment = this->segment - this->tag;
}
dtrace:helper:ustack:
/!this->done && this->codecache && this->tag > 0/
{
MARK_LINE;
this->tag = copyin_uchar(this->block + this->segment);
this->segment = this->segment - this->tag;
}
dtrace:helper:ustack:
/!this->done && this->codecache && this->tag > 0/
{
MARK_LINE;
this->tag = copyin_uchar(this->block + this->segment);
this->segment = this->segment - this->tag;
}
dtrace:helper:ustack:
/!this->done && this->codecache && this->tag > 0/
{
MARK_LINE;
this->tag = copyin_uchar(this->block + this->segment);
this->segment = this->segment - this->tag;
}
dtrace:helper:ustack:
/!this->done && this->codecache && this->tag > 0/
{
MARK_LINE;
this->error = "<couldn't find start>";
this->done = 1;
}
dtrace:helper:ustack:
/!this->done && this->codecache/
{
MARK_LINE;
this->block = this->CodeCache_low +
(this->segment << this->CodeHeap_log2_segment_size);
this->used = copyin_uint32(this->block + OFFSET_HeapBlockHeader_used);
}
dtrace:helper:ustack:
/!this->done && this->codecache && !this->used/
{
MARK_LINE;
this->error = "<block not in use>";
this->done = 1;
}
dtrace:helper:ustack:
/!this->done && this->codecache/
{
MARK_LINE;
this->start = this->block + SIZE_HeapBlockHeader;
this->vtbl = copyin_ptr(this->start);
this->nmethod_vtbl = (pointer) &``__1cHnmethodG__vtbl_;
this->BufferBlob_vtbl = (pointer) &``__1cKBufferBlobG__vtbl_;
}
dtrace:helper:ustack:
/!this->done && this->vtbl == this->nmethod_vtbl/
{
MARK_LINE;
this->methodOopPtr = copyin_ptr(this->start + OFFSET_nmethod_method);
this->suffix = '*';
this->methodOop = 1;
}
dtrace:helper:ustack:
/!this->done && this->vtbl == this->BufferBlob_vtbl/
{
MARK_LINE;
this->name = copyin_ptr(this->start + OFFSET_CodeBlob_name);
}
dtrace:helper:ustack:
/!this->done && this->vtbl == this->BufferBlob_vtbl &&
this->Use_Compressed_Oops == 0 &&
this->methodOopPtr > this->heap_start && this->methodOopPtr < this->heap_end/
{
MARK_LINE;
this->klass = copyin_ptr(this->methodOopPtr + OFFSET_oopDesc_metadata);
this->methodOop = this->klass == this->Universe_methodKlassOop;
this->done = !this->methodOop;
}
dtrace:helper:ustack:
/!this->done && this->vtbl == this->BufferBlob_vtbl &&
this->Use_Compressed_Oops != 0 &&
this->methodOopPtr > this->heap_start && this->methodOopPtr < this->heap_end/
{
MARK_LINE;
/*
* Read compressed pointer and decode heap oop, same as oop.inline.hpp
*/
this->cklass = copyin_uint32(this->methodOopPtr + OFFSET_oopDesc_metadata);
this->klass = (uint64_t)((uintptr_t)this->Universe_narrow_oop_base +
((uintptr_t)this->cklass << this->Universe_narrow_oop_shift));
this->methodOop = this->klass == this->Universe_methodKlassOop;
this->done = !this->methodOop;
}
dtrace:helper:ustack:
/!this->done && !this->methodOop/
{
MARK_LINE;
this->name = copyin_ptr(this->start + OFFSET_CodeBlob_name);
this->result = this->name != 0 ? copyinstr(this->name) : "<CodeBlob>";
this->done = 1;
}
dtrace:helper:ustack:
/!this->done && this->methodOop/
{
MARK_LINE;
this->constMethod = copyin_ptr(this->methodOopPtr +
OFFSET_methodOopDesc_constMethod);
this->nameIndex = copyin_uint16(this->constMethod +
OFFSET_constMethodOopDesc_name_index);
this->signatureIndex = copyin_uint16(this->constMethod +
OFFSET_constMethodOopDesc_signature_index);
this->constantPool = copyin_ptr(this->methodOopPtr +
OFFSET_methodOopDesc_constants);
this->nameSymbol = copyin_ptr(this->constantPool +
this->nameIndex * sizeof (pointer) + SIZE_constantPoolOopDesc);
this->nameSymbolLength = copyin_uint16(this->nameSymbol +
OFFSET_Symbol_length);
this->signatureSymbol = copyin_ptr(this->constantPool +
this->signatureIndex * sizeof (pointer) + SIZE_constantPoolOopDesc);
this->signatureSymbolLength = copyin_uint16(this->signatureSymbol +
OFFSET_Symbol_length);
this->klassPtr = copyin_ptr(this->constantPool +
OFFSET_constantPoolOopDesc_pool_holder);
this->klassSymbol = copyin_ptr(this->klassPtr +
OFFSET_Klass_name + SIZE_oopDesc);
this->klassSymbolLength = copyin_uint16(this->klassSymbol +
OFFSET_Symbol_length);
/*
* Enough for three strings, plus the '.', plus the trailing '\0'.
*/
this->result = (char *) alloca(this->klassSymbolLength +
this->nameSymbolLength +
this->signatureSymbolLength + 2 + 1);
copyinto(this->klassSymbol + OFFSET_Symbol_body,
this->klassSymbolLength, this->result);
/*
* Add the '.' between the class and the name.
*/
this->result[this->klassSymbolLength] = '.';
copyinto(this->nameSymbol + OFFSET_Symbol_body,
this->nameSymbolLength,
this->result + this->klassSymbolLength + 1);
copyinto(this->signatureSymbol + OFFSET_Symbol_body,
this->signatureSymbolLength,
this->result + this->klassSymbolLength +
this->nameSymbolLength + 1);
/*
* Now we need to add a trailing '\0' and possibly a tag character.
*/
this->result[this->klassSymbolLength + 1 +
this->nameSymbolLength +
this->signatureSymbolLength] = this->suffix;
this->result[this->klassSymbolLength + 2 +
this->nameSymbolLength +
this->signatureSymbolLength] = '\0';
this->done = 1;
}
dtrace:helper:ustack:
/this->done && this->error == (char *) NULL/
{
this->result;
}
dtrace:helper:ustack:
/this->done && this->error != (char *) NULL/
{
this->error;
}
dtrace:helper:ustack:
/!this->done && this->codecache/
{
this->done = 1;
"error";
}
dtrace:helper:ustack:
/!this->done/
{
NULL;
}
/*
* Copyright (c) 2006, 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 <door.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <poll.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <thread.h>
#include <unistd.h>
#include "jvm_dtrace.h"
// NOTE: These constants are used in JVM code as well.
// KEEP JVM CODE IN SYNC if you are going to change these...
#define DTRACE_ALLOC_PROBES 0x1
#define DTRACE_METHOD_PROBES 0x2
#define DTRACE_MONITOR_PROBES 0x4
#define DTRACE_ALL_PROBES -1
// generic error messages
#define JVM_ERR_OUT_OF_MEMORY "out of memory (native heap)"
#define JVM_ERR_INVALID_PARAM "invalid input parameter(s)"
#define JVM_ERR_NULL_PARAM "input paramater is NULL"
// error messages for attach
#define JVM_ERR_CANT_OPEN_DOOR "cannot open door file"
#define JVM_ERR_CANT_CREATE_ATTACH_FILE "cannot create attach file"
#define JVM_ERR_DOOR_FILE_PERMISSION "door file is not secure"
#define JVM_ERR_CANT_SIGNAL "cannot send SIGQUIT to target"
// error messages for enable probe
#define JVM_ERR_DOOR_CMD_SEND "door command send failed"
#define JVM_ERR_DOOR_CANT_READ_STATUS "cannot read door command status"
#define JVM_ERR_DOOR_CMD_STATUS "door command error status"
// error message for detach
#define JVM_ERR_CANT_CLOSE_DOOR "cannot close door file"
#define RESTARTABLE(_cmd, _result) do { \
do { \
_result = _cmd; \
} while((_result == -1) && (errno == EINTR)); \
} while(0)
struct _jvm_t {
pid_t pid;
int door_fd;
};
static int libjvm_dtrace_debug;
static void print_debug(const char* fmt,...) {
if (libjvm_dtrace_debug) {
va_list alist;
va_start(alist, fmt);
fputs("libjvm_dtrace DEBUG: ", stderr);
vfprintf(stderr, fmt, alist);
va_end(alist);
}
}
/* Key for thread local error message */
static thread_key_t jvm_error_key;
/* init function for this library */
static void init_jvm_dtrace() {
/* check for env. var for debug mode */
libjvm_dtrace_debug = getenv("LIBJVM_DTRACE_DEBUG") != NULL;
/* create key for thread local error message */
if (thr_keycreate(&jvm_error_key, NULL) != 0) {
print_debug("can't create thread_key_t for jvm error key\n");
// exit(1); ?
}
}
#pragma init(init_jvm_dtrace)
/* set thread local error message */
static void set_jvm_error(const char* msg) {
thr_setspecific(jvm_error_key, (void*)msg);
}
/* clear thread local error message */
static void clear_jvm_error() {
thr_setspecific(jvm_error_key, NULL);
}
/* file handling functions that can handle interrupt */
static int file_open(const char* path, int flag) {
int ret;
RESTARTABLE(open(path, flag), ret);
return ret;
}
static int file_close(int fd) {
int ret;
RESTARTABLE(close(fd), ret);
return ret;
}
static int file_read(int fd, char* buf, int len) {
int ret;
RESTARTABLE(read(fd, buf, len), ret);
return ret;
}
/* send SIGQUIT signal to given process */
static int send_sigquit(pid_t pid) {
int ret;
RESTARTABLE(kill(pid, SIGQUIT), ret);
return ret;
}
/* called to check permissions on attach file */
static int check_permission(const char* path) {
struct stat64 sb;
uid_t uid, gid;
int res;
/*
* Check that the path is owned by the effective uid/gid of this
* process. Also check that group/other access is not allowed.
*/
uid = geteuid();
gid = getegid();
res = stat64(path, &sb);
if (res != 0) {
print_debug("stat failed for %s\n", path);
return -1;
}
if ((sb.st_uid != uid) || (sb.st_gid != gid) ||
((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0)) {
print_debug("well-known file %s is not secure\n", path);
return -1;
}
return 0;
}
#define ATTACH_FILE_PATTERN "/tmp/.attach_pid%d"
/* fill-in the name of attach file name in given buffer */
static void fill_attach_file_name(char* path, int len, pid_t pid) {
memset(path, 0, len);
sprintf(path, ATTACH_FILE_PATTERN, pid);
}
#define DOOR_FILE_PATTERN "/tmp/.java_pid%d"
/* open door file for the given JVM */
static int open_door(pid_t pid) {
char path[PATH_MAX + 1];
int fd;
sprintf(path, DOOR_FILE_PATTERN, pid);
fd = file_open(path, O_RDONLY);
if (fd < 0) {
set_jvm_error(JVM_ERR_CANT_OPEN_DOOR);
print_debug("cannot open door file %s\n", path);
return -1;
}
print_debug("opened door file %s\n", path);
if (check_permission(path) != 0) {
set_jvm_error(JVM_ERR_DOOR_FILE_PERMISSION);
print_debug("check permission failed for %s\n", path);
file_close(fd);
fd = -1;
}
return fd;
}
/* create attach file for given process */
static int create_attach_file(pid_t pid) {
char path[PATH_MAX + 1];
int fd;
fill_attach_file_name(path, sizeof(path), pid);
fd = file_open(path, O_CREAT | O_RDWR);
if (fd < 0) {
set_jvm_error(JVM_ERR_CANT_CREATE_ATTACH_FILE);
print_debug("cannot create file %s\n", path);
} else {
print_debug("created attach file %s\n", path);
}
return fd;
}
/* delete attach file for given process */
static void delete_attach_file(pid_t pid) {
char path[PATH_MAX + 1];
fill_attach_file_name(path, sizeof(path), pid);
int res = unlink(path);
if (res) {
print_debug("cannot delete attach file %s\n", path);
} else {
print_debug("deleted attach file %s\n", path);
}
}
/* attach to given JVM */
jvm_t* jvm_attach(pid_t pid) {
jvm_t* jvm;
int door_fd, attach_fd, i;
jvm = (jvm_t*) calloc(1, sizeof(jvm_t));
if (jvm == NULL) {
set_jvm_error(JVM_ERR_OUT_OF_MEMORY);
print_debug("calloc failed in %s at %d\n", __FILE__, __LINE__);
return NULL;
}
jvm->pid = pid;
attach_fd = -1;
door_fd = open_door(pid);
if (door_fd < 0) {
print_debug("trying to create attach file\n");
if ((attach_fd = create_attach_file(pid)) < 0) {
goto quit;
}
/* send QUIT signal to the target so that it will
* check for the attach file.
*/
if (send_sigquit(pid) != 0) {
set_jvm_error(JVM_ERR_CANT_SIGNAL);
print_debug("sending SIGQUIT failed\n");
goto quit;
}
/* give the target VM time to start the attach mechanism */
do {
int res;
RESTARTABLE(poll(0, 0, 200), res);
door_fd = open_door(pid);
i++;
} while (i <= 50 && door_fd == -1);
if (door_fd < 0) {
print_debug("Unable to open door to process %d\n", pid);
goto quit;
}
}
quit:
if (attach_fd >= 0) {
file_close(attach_fd);
delete_attach_file(jvm->pid);
}
if (door_fd >= 0) {
jvm->door_fd = door_fd;
clear_jvm_error();
} else {
free(jvm);
jvm = NULL;
}
return jvm;
}
/* return the last thread local error message */
const char* jvm_get_last_error() {
const char* res = NULL;
thr_getspecific(jvm_error_key, (void**)&res);
return res;
}
/* detach the givenb JVM */
int jvm_detach(jvm_t* jvm) {
if (jvm) {
int res;
if (jvm->door_fd != -1) {
if (file_close(jvm->door_fd) != 0) {
set_jvm_error(JVM_ERR_CANT_CLOSE_DOOR);
res = -1;
} else {
clear_jvm_error();
res = 0;
}
}
free(jvm);
return res;
} else {
set_jvm_error(JVM_ERR_NULL_PARAM);
print_debug("jvm_t* is NULL\n");
return -1;
}
}
/*
* A simple table to translate some known errors into reasonable
* error messages
*/
static struct {
int err;
const char* msg;
} const error_messages[] = {
{ 100, "Bad request" },
{ 101, "Protocol mismatch" },
{ 102, "Resource failure" },
{ 103, "Internal error" },
{ 104, "Permission denied" },
};
/*
* Lookup the given error code and return the appropriate
* message. If not found return NULL.
*/
static const char* translate_error(int err) {
int table_size = sizeof(error_messages) / sizeof(error_messages[0]);
int i;
for (i=0; i<table_size; i++) {
if (err == error_messages[i].err) {
return error_messages[i].msg;
}
}
return NULL;
}
/*
* Current protocol version
*/
static const char* PROTOCOL_VERSION = "1";
#define RES_BUF_SIZE 128
/*
* Enqueue attach-on-demand command to the given JVM
*/
static
int enqueue_command(jvm_t* jvm, const char* cstr, int arg_count, const char** args) {
size_t size;
door_arg_t door_args;
char res_buffer[RES_BUF_SIZE];
int rc, i;
char* buf = NULL;
int result = -1;
/*
* First we get the command string and create the start of the
* argument string to send to the target VM:
* <ver>\0<cmd>\0
*/
if (cstr == NULL) {
print_debug("command name is NULL\n");
goto quit;
}
size = strlen(PROTOCOL_VERSION) + strlen(cstr) + 2;
buf = (char*)malloc(size);
if (buf != NULL) {
char* pos = buf;
strcpy(buf, PROTOCOL_VERSION);
pos += strlen(PROTOCOL_VERSION)+1;
strcpy(pos, cstr);
} else {
set_jvm_error(JVM_ERR_OUT_OF_MEMORY);
print_debug("malloc failed at %d in %s\n", __LINE__, __FILE__);
goto quit;
}
/*
* Next we iterate over the arguments and extend the buffer
* to include them.
*/
for (i=0; i<arg_count; i++) {
cstr = args[i];
if (cstr != NULL) {
size_t len = strlen(cstr);
char* newbuf = (char*)realloc(buf, size+len+1);
if (newbuf == NULL) {
set_jvm_error(JVM_ERR_OUT_OF_MEMORY);
print_debug("realloc failed in %s at %d\n", __FILE__, __LINE__);
goto quit;
}
buf = newbuf;
strcpy(buf+size, cstr);
size += len+1;
}
}
/*
* The arguments to the door function are in 'buf' so we now
* do the door call
*/
door_args.data_ptr = buf;
door_args.data_size = size;
door_args.desc_ptr = NULL;
door_args.desc_num = 0;
door_args.rbuf = (char*)&res_buffer;
door_args.rsize = sizeof(res_buffer);
RESTARTABLE(door_call(jvm->door_fd, &door_args), rc);
/*
* door_call failed
*/
if (rc == -1) {
print_debug("door_call failed\n");
} else {
/*
* door_call succeeded but the call didn't return the the expected jint.
*/
if (door_args.data_size < sizeof(int)) {
print_debug("Enqueue error - reason unknown as result is truncated!");
} else {
int* res = (int*)(door_args.data_ptr);
if (*res != 0) {
const char* msg = translate_error(*res);
if (msg == NULL) {
print_debug("Unable to enqueue command to target VM: %d\n", *res);
} else {
print_debug("Unable to enqueue command to target VM: %s\n", msg);
}
} else {
/*
* The door call should return a file descriptor to one end of
* a socket pair
*/
if ((door_args.desc_ptr != NULL) &&
(door_args.desc_num == 1) &&
(door_args.desc_ptr->d_attributes & DOOR_DESCRIPTOR)) {
result = door_args.desc_ptr->d_data.d_desc.d_descriptor;
} else {
print_debug("Reply from enqueue missing descriptor!\n");
}
}
}
}
quit:
if (buf) free(buf);
return result;
}
/* read status code for a door command */
static int read_status(int fd) {
char ch, buf[16];
int index = 0;
while (1) {
if (file_read(fd, &ch, sizeof(ch)) != sizeof(ch)) {
set_jvm_error(JVM_ERR_DOOR_CANT_READ_STATUS);
print_debug("door cmd status: read status failed\n");
return -1;
}
buf[index++] = ch;
if (ch == '\n') {
buf[index - 1] = '\0';
return atoi(buf);
}
if (index == sizeof(buf)) {
set_jvm_error(JVM_ERR_DOOR_CANT_READ_STATUS);
print_debug("door cmd status: read status overflow\n");
return -1;
}
}
}
static const char* ENABLE_DPROBES_CMD = "enabledprobes";
/* enable one or more DTrace probes for a given JVM */
int jvm_enable_dtprobes(jvm_t* jvm, int num_probe_types, const char** probe_types) {
int fd, status = 0;
char ch;
const char* args[1];
char buf[16];
int probe_type = 0, index;
int count = 0;
if (jvm == NULL) {
set_jvm_error(JVM_ERR_NULL_PARAM);
print_debug("jvm_t* is NULL\n");
return -1;
}
if (num_probe_types == 0 || probe_types == NULL ||
probe_types[0] == NULL) {
set_jvm_error(JVM_ERR_INVALID_PARAM);
print_debug("invalid probe type argument(s)\n");
return -1;
}
for (index = 0; index < num_probe_types; index++) {
const char* p = probe_types[index];
if (strcmp(p, JVM_DTPROBE_OBJECT_ALLOC) == 0) {
probe_type |= DTRACE_ALLOC_PROBES;
count++;
} else if (strcmp(p, JVM_DTPROBE_METHOD_ENTRY) == 0 ||
strcmp(p, JVM_DTPROBE_METHOD_RETURN) == 0) {
probe_type |= DTRACE_METHOD_PROBES;
count++;
} else if (strcmp(p, JVM_DTPROBE_MONITOR_ENTER) == 0 ||
strcmp(p, JVM_DTPROBE_MONITOR_ENTERED) == 0 ||
strcmp(p, JVM_DTPROBE_MONITOR_EXIT) == 0 ||
strcmp(p, JVM_DTPROBE_MONITOR_WAIT) == 0 ||
strcmp(p, JVM_DTPROBE_MONITOR_WAITED) == 0 ||
strcmp(p, JVM_DTPROBE_MONITOR_NOTIFY) == 0 ||
strcmp(p, JVM_DTPROBE_MONITOR_NOTIFYALL) == 0) {
probe_type |= DTRACE_MONITOR_PROBES;
count++;
} else if (strcmp(p, JVM_DTPROBE_ALL) == 0) {
probe_type |= DTRACE_ALL_PROBES;
count++;
}
}
if (count == 0) {
return count;
}
sprintf(buf, "%d", probe_type);
args[0] = buf;
fd = enqueue_command(jvm, ENABLE_DPROBES_CMD, 1, args);
if (fd < 0) {
set_jvm_error(JVM_ERR_DOOR_CMD_SEND);
return -1;
}
status = read_status(fd);
// non-zero status is error
if (status) {
set_jvm_error(JVM_ERR_DOOR_CMD_STATUS);
print_debug("%s command failed (status: %d) in target JVM\n",
ENABLE_DPROBES_CMD, status);
file_close(fd);
return -1;
}
// read from stream until EOF
while (file_read(fd, &ch, sizeof(ch)) == sizeof(ch)) {
if (libjvm_dtrace_debug) {
printf("%c", ch);
}
}
file_close(fd);
clear_jvm_error();
return count;
}
/*
* Copyright (c) 2006, 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 _JVM_DTRACE_H_
#define _JVM_DTRACE_H_
/*
* Interface to dynamically turn on probes in Hotspot JVM. Currently,
* this interface can be used to dynamically enable certain DTrace
* probe points that are costly to have "always on".
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
struct _jvm_t;
typedef struct _jvm_t jvm_t;
/* Attach to the given JVM process. Returns NULL on failure.
jvm_get_last_error() returns last error message. */
jvm_t* jvm_attach(pid_t pid);
/* Returns the last error message from this library or NULL if none. */
const char* jvm_get_last_error();
/* few well-known probe type constants for 'probe_types' param below */
#define JVM_DTPROBE_METHOD_ENTRY "method-entry"
#define JVM_DTPROBE_METHOD_RETURN "method-return"
#define JVM_DTPROBE_MONITOR_ENTER "monitor-contended-enter"
#define JVM_DTPROBE_MONITOR_ENTERED "monitor-contended-entered"
#define JVM_DTPROBE_MONITOR_EXIT "monitor-contended-exit"
#define JVM_DTPROBE_MONITOR_WAIT "monitor-wait"
#define JVM_DTPROBE_MONITOR_WAITED "monitor-waited"
#define JVM_DTPROBE_MONITOR_NOTIFY "monitor-notify"
#define JVM_DTPROBE_MONITOR_NOTIFYALL "monitor-notifyall"
#define JVM_DTPROBE_OBJECT_ALLOC "object-alloc"
#define JVM_DTPROBE_ALL "*"
/* Enable the specified DTrace probes of given probe types on
* the specified JVM. Returns >= 0 on success, -1 on failure.
* On success, this returns number of probe_types enabled.
* On failure, jvm_get_last_error() returns the last error message.
*/
int jvm_enable_dtprobes(jvm_t* jvm, int num_probe_types, const char** probe_types);
/* Note: There is no jvm_disable_dtprobes function. Probes are automatically
* disabled when there are no more clients requiring those probes.
*/
/* Detach the given JVM. Returns 0 on success, -1 on failure.
* jvm_get_last_error() returns the last error message.
*/
int jvm_detach(jvm_t* jvm);
#ifdef __cplusplus
}
#endif
#endif /* _JVM_DTRACE_H_ */
此差异已折叠。
此差异已折叠。
......@@ -33,6 +33,13 @@
#include "runtime/signature.hpp"
#include "utilities/globalDefinitions.hpp"
/*
* JSDT java dtrace probes have never been implemented in macosx. It is unknown if the solaris implementation
* is close or if significant implementation work is necessary. The future of the solaris implementation also
* appears to be unclear since compiling code with JSDT probes produces the following warning:
* "warning: ProviderFactory is internal proprietary API and may be removed in a future release"
*/
int DTraceJSDT::pd_activate(
void* baseAddress, jstring module,
jint providers_count, JVM_DTraceProvider* providers) {
......
......@@ -41,6 +41,21 @@
* This file is currently collecting system-specific dregs for the
* JNI conversion, which should be sorted out later.
*/
#ifdef __NetBSD__
/*
* Since we are compiling with c++, we need the following to make c macros
* visible.
*/
# if !defined(__STDC_LIMIT_MACROS)
# define __STDC_LIMIT_MACROS 1
# endif
# if !defined(__STDC_CONSTANT_MACROS)
# define __STDC_CONSTANT_MACROS 1
# endif
# if !defined(__STDC_FORMAT_MACROS)
# define __STDC_FORMAT_MACROS 1
# endif
#endif
#include <dirent.h> /* For DIR */
#include <sys/param.h> /* For MAXPATHLEN */
......
此差异已折叠。
......@@ -4357,6 +4357,11 @@ int os::active_processor_count() {
return online_cpus;
}
void os::set_native_thread_name(const char *name) {
// Not yet implemented.
return;
}
bool os::distribute_processes(uint length, uint* distribution) {
// Not yet implemented.
return false;
......
......@@ -669,6 +669,11 @@ static bool assign_distribution(processorid_t* id_array,
return true;
}
void os::set_native_thread_name(const char *name) {
// Not yet implemented.
return;
}
bool os::distribute_processes(uint length, uint* distribution) {
bool result = false;
// Find the processor id's of all the available CPUs.
......
......@@ -710,6 +710,11 @@ int os::active_processor_count() {
}
}
void os::set_native_thread_name(const char *name) {
// Not yet implemented.
return;
}
bool os::distribute_processes(uint length, uint* distribution) {
// Not yet implemented.
return false;
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册