6580131: 3/4 CompiledMethodLoad events don't produce the expected extra notifications to describe inlining

Add support for additional implementation specific info to the JVM/TI CompiledMethodLoad event via the compile_info parameter.

Reviewed-by: never, ohair, tbell, tdeneau
This commit is contained in:
Vasanth Venkatachalam 2010-01-20 12:09:31 -07:00 committed by Daniel D. Daugherty
parent 57afe92dd1
commit 688eab1157
16 changed files with 696 additions and 21 deletions

View File

@ -1,5 +1,5 @@
#
# Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved.
# Copyright 2005-2010 Sun Microsystems, Inc. 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
@ -1093,6 +1093,7 @@ endif
# Check for existence of misc Hotspot imported files
######################################################
HOTSPOT_INCLUDE_FILE_LIST = jvmti.h
HOTSPOT_INCLUDE_FILE_LIST += jvmticmlr.h
#HOTSPOT_INCLUDE_FILE_LIST += jni.h jni_md.h
#HOTSPOT_INCLUDE_FILE_LIST += jvm.h jvm_md.h
#HOTSPOT_INCLUDE_FILE_LIST += jmm.h

View File

@ -1,5 +1,5 @@
#
# Copyright 1995-2005 Sun Microsystems, Inc. All Rights Reserved.
# Copyright 1995-2010 Sun Microsystems, Inc. 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,7 +34,8 @@ include $(BUILDDIR)/common/Defs.gmk
FILES_h = $(INCLUDEDIR)/jni.h \
$(PLATFORM_INCLUDE)/jni_md.h \
$(INCLUDEDIR)/jvmti.h \
$(INCLUDEDIR)/jvmti.h \
$(INCLUDEDIR)/jvmticmlr.h \
$(INCLUDEDIR)/classfile_constants.h
$(INCLUDEDIR)/%.h: $(SHARE_SRC)/javavm/export/%.h

View File

@ -1,5 +1,5 @@
#
# Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved.
# Copyright 2004-2010 Sun Microsystems, Inc. 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,12 +34,13 @@ include $(BUILDDIR)/common/Defs.gmk
# Can be built in any order, the JRE version of hprof and java_crw_demo are
# really built in make/java.
# The hprof target here just deliveres the sources and README files.
# The hprof target here just delivers the sources and README files.
# The java_crw_demo and agent_util files are copied into each demo that
# uses them.
SUBDIRS = \
versionCheck \
gctest \
compiledMethodLoad \
gctest \
heapViewer \
heapTracker \
minst \

View File

@ -1,5 +1,5 @@
#
# Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
# Copyright 2004-2010 Sun Microsystems, Inc. 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
@ -27,8 +27,8 @@ Instructions on adding a jvmti demo agent.
Basically you want to mimic the jvmti demo agent "mtrace".
* Create and populate a source directory at src/demo/jvmti
(Try and re-use code in agent_util area like src/demo/jvmti/mtrace)
* Create and populate a source directory at src/share/demo/jvmti
(Try and re-use code in agent_util area like src/share/demo/jvmti/mtrace)
(This should include a small README.txt document on what this demo is)
* Make sure the appropriate "demo" copyright notice is added to all the
@ -44,7 +44,7 @@ Basically you want to mimic the jvmti demo agent "mtrace".
* Create test directory at test/demo/jvmti, create at least one test
(Use test/demo/jvmti/mtrace as a template)
* Don't forget to SCCS in all the new files
* Don't forget to check in all the new files
* Build and create images (cd make && gnumake && gnumake images)
(Do this on Solaris, Linux, and at least one Windows platform)
@ -54,5 +54,5 @@ Basically you want to mimic the jvmti demo agent "mtrace".
* Run the tests: cd test/demo/jvmti && runregress .
(Do this on Solaris, Linux, and at least one Windows platform)
Contact: jk-svc-group@sun.com for more information or help.
Contact: serviceability-dev@openjdk.java.net for more information or help.

View File

@ -0,0 +1,41 @@
#
# Copyright 2010 Sun Microsystems, Inc. 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. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun in the LICENSE file that accompanied this code.
#
# 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
BUILDDIR = ../../..
PRODUCT = demo/jvmti
DEMONAME = compiledMethodLoad
include $(BUILDDIR)/common/Defs.gmk
DEMO_ROOT = $(SHARE_SRC)/demo/jvmti/$(DEMONAME)
DEMO_TOPFILES = ./README.txt
DEMO_DESTDIR = $(DEMODIR)/jvmti/$(DEMONAME)
DEMO_OBJECTS = agent_util.$(OBJECT_SUFFIX)
#
# Demo jar building rules.
#
include $(BUILDDIR)/common/Demo.gmk

View File

@ -0,0 +1,42 @@
#
# Copyright 2010 Sun Microsystems, Inc. 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 Sun Microsystems 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.
#
compiledMethodLoad
This agent library traces CompiledMethodLoad events along
with the HotSpot specific compile_info parameter.
You can use this agent library as follows:
java -agentlib:compiledMethodLoad ...
See ${JAVA_HOME}/demo/jvmti/index.html for help running and building agents.

View File

@ -0,0 +1,268 @@
/*
* Copyright 2010 Sun Microsystems, Inc. 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 Sun Microsystems 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "jni.h"
#include "jvmti.h"
#include "jvmticmlr.h"
#include "agent_util.h"
/* Global static data */
static char OUTPUT_FILE[] = "compiledMethodLoad.txt";
static FILE *fp;
static jvmtiEnv *jvmti;
static jrawMonitorID lock;
/* print a jvmtiCompiledMethodLoadDummyRecord */
void
print_dummy_record(jvmtiCompiledMethodLoadDummyRecord* record,
jvmtiEnv* jvmti, FILE* fp) {
if (record != NULL) {
fprintf(fp, "Dummy record detected containing message: %s\n",
(char *)record->message);
}
}
/* print the specified stack frames */
void
print_stack_frames(PCStackInfo* record, jvmtiEnv *jvmti, FILE* fp) {
if (record != NULL && record->methods != NULL) {
int i;
for (i = 0; i < record->numstackframes; i++) {
jvmtiError err;
char* method_name = NULL;
char* class_name = NULL;
char* method_signature = NULL;
char* class_signature = NULL;
char* generic_ptr_method = NULL;
char* generic_ptr_class = NULL;
jmethodID id;
jclass declaringclassptr;
id = record->methods[i];
err = (*jvmti)->GetMethodDeclaringClass(jvmti, id,
&declaringclassptr);
check_jvmti_error(jvmti, err, "get method declaring class");
err = (*jvmti)->GetClassSignature(jvmti, declaringclassptr,
&class_signature, &generic_ptr_class);
check_jvmti_error(jvmti, err, "get class signature");
err = (*jvmti)->GetMethodName(jvmti, id, &method_name,
&method_signature, &generic_ptr_method);
check_jvmti_error(jvmti, err, "get method name");
fprintf(fp, "%s::%s %s %s @%d\n", class_signature, method_name,
method_signature,
generic_ptr_method == NULL ? "" : generic_ptr_method,
record->bcis[i]);
if (method_name != NULL) {
err = (*jvmti)->Deallocate(jvmti, (unsigned char*)method_name);
check_jvmti_error(jvmti, err, "deallocate method_name");
}
if (method_signature != NULL) {
err = (*jvmti)->Deallocate(jvmti,
(unsigned char*)method_signature);
check_jvmti_error(jvmti, err, "deallocate method_signature");
}
if (generic_ptr_method != NULL) {
err = (*jvmti)->Deallocate(jvmti,
(unsigned char*)generic_ptr_method);
check_jvmti_error(jvmti, err, "deallocate generic_ptr_method");
}
if (class_name != NULL) {
err = (*jvmti)->Deallocate(jvmti, (unsigned char*)class_name);
check_jvmti_error(jvmti, err, "deallocate class_name");
}
if (class_signature != NULL) {
err = (*jvmti)->Deallocate(jvmti,
(unsigned char*)class_signature);
check_jvmti_error(jvmti, err, "deallocate class_signature");
}
if (generic_ptr_class != NULL) {
err = (*jvmti)->Deallocate(jvmti,
(unsigned char*)generic_ptr_class);
check_jvmti_error(jvmti, err, "deallocate generic_ptr_class");
}
}
}
}
/* print a jvmtiCompiledMethodLoadInlineRecord */
void
print_inline_info_record(jvmtiCompiledMethodLoadInlineRecord* record,
jvmtiEnv *jvmti, FILE* fp) {
if (record != NULL && record->pcinfo != NULL) {
int numpcs = record->numpcs;
int i;
for (i = 0; i < numpcs; i++) {
PCStackInfo pcrecord = (record->pcinfo[i]);
fprintf(fp, "PcDescriptor(pc=0x%lx):\n", (jint)(pcrecord.pc));
print_stack_frames(&pcrecord, jvmti, fp);
}
}
}
/* decode kind of CompiledMethodLoadRecord and print */
void
print_records(jvmtiCompiledMethodLoadRecordHeader* list, jvmtiEnv *jvmti,
FILE* fp)
{
jvmtiCompiledMethodLoadRecordHeader* curr = list;
fprintf(fp, "\nPrinting PC Descriptors\n\n");
while (curr != NULL) {
switch (curr->kind) {
case JVMTI_CMLR_DUMMY:
print_dummy_record((jvmtiCompiledMethodLoadDummyRecord *)curr,
jvmti, fp);
break;
case JVMTI_CMLR_INLINE_INFO:
print_inline_info_record(
(jvmtiCompiledMethodLoadInlineRecord *)curr, jvmti, fp);
break;
default:
fprintf(fp, "Warning: unrecognized record: kind=%d\n", curr->kind);
break;
}
curr = (jvmtiCompiledMethodLoadRecordHeader *)curr->next;
}
}
/* Callback for JVMTI_EVENT_COMPILED_METHOD_LOAD */
void JNICALL
compiled_method_load(jvmtiEnv *jvmti, jmethodID method, jint code_size,
const void* code_addr, jint map_length, const jvmtiAddrLocationMap* map,
const void* compile_info)
{
jvmtiError err;
char* name = NULL;
char* signature = NULL;
char* generic_ptr = NULL;
jvmtiCompiledMethodLoadRecordHeader* pcs;
err = (*jvmti)->RawMonitorEnter(jvmti, lock);
check_jvmti_error(jvmti, err, "raw monitor enter");
err = (*jvmti)->GetMethodName(jvmti, method, &name, &signature,
&generic_ptr);
check_jvmti_error(jvmti, err, "get method name");
fprintf(fp, "\nCompiled method load event\n");
fprintf(fp, "Method name %s %s %s\n\n", name, signature,
generic_ptr == NULL ? "" : generic_ptr);
pcs = (jvmtiCompiledMethodLoadRecordHeader *)compile_info;
if (pcs != NULL) {
print_records(pcs, jvmti, fp);
}
if (name != NULL) {
err = (*jvmti)->Deallocate(jvmti, (unsigned char*)name);
check_jvmti_error(jvmti, err, "deallocate name");
}
if (signature != NULL) {
err = (*jvmti)->Deallocate(jvmti, (unsigned char*)signature);
check_jvmti_error(jvmti, err, "deallocate signature");
}
if (generic_ptr != NULL) {
err = (*jvmti)->Deallocate(jvmti, (unsigned char*)generic_ptr);
check_jvmti_error(jvmti, err, "deallocate generic_ptr");
}
err = (*jvmti)->RawMonitorExit(jvmti, lock);
check_jvmti_error(jvmti, err, "raw monitor exit");
}
/* Agent_OnLoad() is called first, we prepare for a COMPILED_METHOD_LOAD
* event here.
*/
JNIEXPORT jint JNICALL
Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
{
jint rc;
jvmtiError err;
jvmtiCapabilities capabilities;
jvmtiEventCallbacks callbacks;
fp = fopen(OUTPUT_FILE, "w");
if (fp == NULL) {
fatal_error("ERROR: %s: Unable to create output file\n", OUTPUT_FILE);
return -1;
}
/* Get JVMTI environment */
rc = (*vm)->GetEnv(vm, (void **)&jvmti, JVMTI_VERSION);
if (rc != JNI_OK) {
fatal_error(
"ERROR: Unable to create jvmtiEnv, GetEnv failed, error=%d\n", rc);
return -1;
}
/* add JVMTI capabilities */
memset(&capabilities,0, sizeof(capabilities));
capabilities.can_generate_compiled_method_load_events = 1;
err = (*jvmti)->AddCapabilities(jvmti, &capabilities);
check_jvmti_error(jvmti, err, "add capabilities");
/* set JVMTI callbacks for events */
memset(&callbacks, 0, sizeof(callbacks));
callbacks.CompiledMethodLoad = &compiled_method_load;
err = (*jvmti)->SetEventCallbacks(jvmti, &callbacks, sizeof(callbacks));
check_jvmti_error(jvmti, err, "set event callbacks");
/* enable JVMTI events */
err = (*jvmti)->SetEventNotificationMode(jvmti, JVMTI_ENABLE,
JVMTI_EVENT_COMPILED_METHOD_LOAD, NULL);
check_jvmti_error(jvmti, err, "set event notify");
/* create coordination monitor */
err = (*jvmti)->CreateRawMonitor(jvmti, "agent lock", &lock);
check_jvmti_error(jvmti, err, "create raw monitor");
return 0;
}
/* Agent_OnUnload() is called last */
JNIEXPORT void JNICALL
Agent_OnUnload(JavaVM *vm)
{
}

View File

@ -0,0 +1,148 @@
#
# Copyright 2010 Sun Microsystems, Inc. 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 Sun Microsystems 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.
#
########################################################################
#
# Sample GNU Makefile for building JVMTI Demo compiledMethodLoad
#
# Example uses:
# gnumake JDK=<java_home> OSNAME=solaris [OPT=true] [LIBARCH=sparc]
# gnumake JDK=<java_home> OSNAME=solaris [OPT=true] [LIBARCH=sparcv9]
# gnumake JDK=<java_home> OSNAME=linux [OPT=true]
# gnumake JDK=<java_home> OSNAME=win32 [OPT=true]
#
########################################################################
# Source lists
LIBNAME=compiledMethodLoad
SOURCES=compiledMethodLoad.c ../agent_util/agent_util.c
# Solaris Sun C Compiler Version 5.5
ifeq ($(OSNAME), solaris)
# Sun Solaris Compiler options needed
COMMON_FLAGS=-mt -KPIC
# Options that help find errors
COMMON_FLAGS+= -Xa -v -xstrconst -xc99=%none
# Check LIBARCH for any special compiler options
LIBARCH=$(shell uname -p)
ifeq ($(LIBARCH), sparc)
COMMON_FLAGS+=-xarch=v8 -xregs=no%appl
endif
ifeq ($(LIBARCH), sparcv9)
COMMON_FLAGS+=-xarch=v9 -xregs=no%appl
endif
ifeq ($(OPT), true)
CFLAGS=-xO2 $(COMMON_FLAGS)
else
CFLAGS=-g $(COMMON_FLAGS)
endif
# Object files needed to create library
OBJECTS=$(SOURCES:%.c=%.o)
# Library name and options needed to build it
LIBRARY=lib$(LIBNAME).so
LDFLAGS=-z defs -ztext
# Libraries we are dependent on
LIBRARIES= -lc
# Building a shared library
LINK_SHARED=$(LINK.c) -G -o $@
endif
# Linux GNU C Compiler
ifeq ($(OSNAME), linux)
# GNU Compiler options needed to build it
COMMON_FLAGS=-fno-strict-aliasing -fPIC -fno-omit-frame-pointer
# Options that help find errors
COMMON_FLAGS+= -W -Wall -Wno-unused -Wno-parentheses
ifeq ($(OPT), true)
CFLAGS=-O2 $(COMMON_FLAGS)
else
CFLAGS=-g $(COMMON_FLAGS)
endif
# Object files needed to create library
OBJECTS=$(SOURCES:%.c=%.o)
# Library name and options needed to build it
LIBRARY=lib$(LIBNAME).so
LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc -mimpure-text
# Libraries we are dependent on
LIBRARIES=-lc
# Building a shared library
LINK_SHARED=$(LINK.c) -shared -o $@
endif
# Windows Microsoft C/C++ Optimizing Compiler Version 12
ifeq ($(OSNAME), win32)
CC=cl
# Compiler options needed to build it
COMMON_FLAGS=-Gy -DWIN32
# Options that help find errors
COMMON_FLAGS+=-W0 -WX
ifeq ($(OPT), true)
CFLAGS= -Ox -Op -Zi $(COMMON_FLAGS)
else
CFLAGS= -Od -Zi $(COMMON_FLAGS)
endif
# Object files needed to create library
OBJECTS=$(SOURCES:%.c=%.obj)
# Library name and options needed to build it
LIBRARY=$(LIBNAME).dll
LDFLAGS=
# Libraries we are dependent on
LIBRARIES=
# Building a shared library
LINK_SHARED=link -dll -out:$@
endif
# Common -I options
CFLAGS += -I.
CFLAGS += -I../agent_util
CFLAGS += -I$(JDK)/include -I$(JDK)/include/$(OSNAME)
# Default rule
all: $(LIBRARY)
# Build native library
$(LIBRARY): $(OBJECTS)
$(LINK_SHARED) $(OBJECTS) $(LIBRARIES)
# Cleanup the built bits
clean:
rm -f $(LIBRARY) $(OBJECTS)
# Simple tester
test: all
LD_LIBRARY_PATH=`pwd` $(JDK)/bin/java -agentlib:$(LIBNAME) -version
# Compilation rule only needed on Windows
ifeq ($(OSNAME), win32)
%.obj: %.c
$(COMPILE.c) $<
endif

View File

@ -99,6 +99,13 @@ version string supplied in the jvmti.h file, with the version
number supplied by the VM at runtime.
</li>
<li>
<A HREF="compiledMethodLoad">compiledMethodLoad</A>
<br>
This is a small agent that traces CompiledMethodLoad events along
with the HotSpot specific compile_info parameter.
</li>
<li>
<A HREF="mtrace">mtrace</A>
<br>

View File

@ -0,0 +1,115 @@
/*
* Copyright 2010 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* This header file defines the data structures sent by the VM
* through the JVMTI CompiledMethodLoad callback function via the
* "void * compile_info" parameter. The memory pointed to by the
* compile_info parameter may not be referenced after returning from
* the CompiledMethodLoad callback. These are VM implementation
* specific data structures that may evolve in future releases. A
* JVMTI agent should interpret a non-NULL compile_info as a pointer
* to a region of memory containing a list of records. In a typical
* usage scenario, a JVMTI agent would cast each record to a
* jvmtiCompiledMethodLoadRecordHeader, a struct that represents
* arbitrary information. This struct contains a kind field to indicate
* the kind of information being passed, and a pointer to the next
* record. If the kind field indicates inlining information, then the
* agent would cast the record to a jvmtiCompiledMethodLoadInlineRecord.
* This record contains an array of PCStackInfo structs, which indicate
* for every pc address what are the methods on the invocation stack.
* The "methods" and "bcis" fields in each PCStackInfo struct specify a
* 1-1 mapping between these inlined methods and their bytecode indices.
* This can be used to derive the proper source lines of the inlined
* methods.
*/
#ifndef _JVMTI_CMLR_H_
#define _JVMTI_CMLR_H_
enum {
JVMTI_CMLR_MAJOR_VERSION_1 = 0x00000001,
JVMTI_CMLR_MINOR_VERSION_0 = 0x00000000,
JVMTI_CMLR_MAJOR_VERSION = 0x00000001,
JVMTI_CMLR_MINOR_VERSION = 0x00000000
/*
* This comment is for the "JDK import from HotSpot" sanity check:
* version: 1.0.0
*/
};
typedef enum {
JVMTI_CMLR_DUMMY = 1,
JVMTI_CMLR_INLINE_INFO = 2
} jvmtiCMLRKind;
/*
* Record that represents arbitrary information passed through JVMTI
* CompiledMethodLoadEvent void pointer.
*/
typedef struct _jvmtiCompiledMethodLoadRecordHeader {
jvmtiCMLRKind kind; /* id for the kind of info passed in the record */
jint majorinfoversion; /* major and minor info version values. Init'ed */
jint minorinfoversion; /* to current version value in jvmtiExport.cpp. */
struct _jvmtiCompiledMethodLoadRecordHeader* next;
} jvmtiCompiledMethodLoadRecordHeader;
/*
* Record that gives information about the methods on the compile-time
* stack at a specific pc address of a compiled method. Each element in
* the methods array maps to same element in the bcis array.
*/
typedef struct _PCStackInfo {
void* pc; /* the pc address for this compiled method */
jint numstackframes; /* number of methods on the stack */
jmethodID* methods; /* array of numstackframes method ids */
jint* bcis; /* array of numstackframes bytecode indices */
} PCStackInfo;
/*
* Record that contains inlining information for each pc address of
* an nmethod.
*/
typedef struct _jvmtiCompiledMethodLoadInlineRecord {
jvmtiCompiledMethodLoadRecordHeader header; /* common header for casting */
jint numpcs; /* number of pc descriptors in this nmethod */
PCStackInfo* pcinfo; /* array of numpcs pc descriptors */
} jvmtiCompiledMethodLoadInlineRecord;
/*
* Dummy record used to test that we can pass records with different
* information through the void pointer provided that they can be cast
* to a jvmtiCompiledMethodLoadRecordHeader.
*/
typedef struct _jvmtiCompiledMethodLoadDummyRecord {
jvmtiCompiledMethodLoadRecordHeader header; /* common header for casting */
char message[50];
} jvmtiCompiledMethodLoadDummyRecord;
#endif

View File

@ -0,0 +1,51 @@
/*
* Copyright 2010 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/* @test
* @bug 6580131
* @summary Test jvmti demo compiledMethodLoad
*
* @compile ../DemoRun.java ../Hello.java
* @build CompiledMethodLoadTest
* @run main CompiledMethodLoadTest Hello
*/
public class CompiledMethodLoadTest {
public static void main(String args[]) throws Exception {
DemoRun demo;
/* Run demo that uses JVMTI compiledMethodLoad agent (no options) */
demo = new DemoRun("compiledMethodLoad", "" /* options to compiledMethodLoad */ );
demo.runit(args[0]);
/* Make sure patterns in output look ok */
if (demo.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in output");
}
/* Must be a pass. */
System.out.println("Test passed - cleanly terminated");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2004-2010 Sun Microsystems, Inc. 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
@ -43,7 +43,7 @@ public class HeapTrackerTest {
/* Make sure patterns in output look ok */
if (demo.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in oputput");
throw new RuntimeException("Test failed - ERROR seen in output");
}
/* Must be a pass. */

View File

@ -1,5 +1,5 @@
/*
* Copyright 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2004-2010 Sun Microsystems, Inc. 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
@ -44,7 +44,7 @@ public class CpuTimesDefineClassTest {
/* Make sure patterns in output look ok */
if (hprof.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in oputput");
throw new RuntimeException("Test failed - ERROR seen in output");
}
/* Must be a pass. */

View File

@ -1,5 +1,5 @@
/*
* Copyright 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2004-2010 Sun Microsystems, Inc. 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
@ -42,7 +42,7 @@ public class CpuTimesTest {
/* Make sure patterns in output look ok */
if (hprof.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in oputput");
throw new RuntimeException("Test failed - ERROR seen in output");
}
/* Must be a pass. */

View File

@ -1,5 +1,5 @@
/*
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2006-2010 Sun Microsystems, Inc. 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
@ -43,7 +43,7 @@ public class MinstTest {
/* Make sure patterns in output look ok */
if (demo.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in oputput");
throw new RuntimeException("Test failed - ERROR seen in output");
}
/* Must be a pass. */

View File

@ -1,5 +1,5 @@
/*
* Copyright 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2004-2010 Sun Microsystems, Inc. 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
@ -43,7 +43,7 @@ public class TraceJFrame {
/* Make sure patterns in output look ok */
if (demo.output_contains("ERROR")) {
throw new RuntimeException("Test failed - ERROR seen in oputput");
throw new RuntimeException("Test failed - ERROR seen in output");
}
/* Must be a pass. */