diff --git a/jdk/make/common/shared/Sanity.gmk b/jdk/make/common/shared/Sanity.gmk index c19df0eb6ef..7499f6bb189 100644 --- a/jdk/make/common/shared/Sanity.gmk +++ b/jdk/make/common/shared/Sanity.gmk @@ -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 diff --git a/jdk/make/java/jvm/Makefile b/jdk/make/java/jvm/Makefile index ee992a1630b..8bc1c800e4e 100644 --- a/jdk/make/java/jvm/Makefile +++ b/jdk/make/java/jvm/Makefile @@ -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 diff --git a/jdk/make/mkdemo/jvmti/Makefile b/jdk/make/mkdemo/jvmti/Makefile index 749068b909d..c966170fceb 100644 --- a/jdk/make/mkdemo/jvmti/Makefile +++ b/jdk/make/mkdemo/jvmti/Makefile @@ -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 \ diff --git a/jdk/make/mkdemo/jvmti/README.txt b/jdk/make/mkdemo/jvmti/README.txt index cc02bb4c6f1..0078d534ab7 100644 --- a/jdk/make/mkdemo/jvmti/README.txt +++ b/jdk/make/mkdemo/jvmti/README.txt @@ -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. diff --git a/jdk/make/mkdemo/jvmti/compiledMethodLoad/Makefile b/jdk/make/mkdemo/jvmti/compiledMethodLoad/Makefile new file mode 100644 index 00000000000..aea96e4d068 --- /dev/null +++ b/jdk/make/mkdemo/jvmti/compiledMethodLoad/Makefile @@ -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 + diff --git a/jdk/src/share/demo/jvmti/compiledMethodLoad/README.txt b/jdk/src/share/demo/jvmti/compiledMethodLoad/README.txt new file mode 100644 index 00000000000..f34fa1fc108 --- /dev/null +++ b/jdk/src/share/demo/jvmti/compiledMethodLoad/README.txt @@ -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. + diff --git a/jdk/src/share/demo/jvmti/compiledMethodLoad/compiledMethodLoad.c b/jdk/src/share/demo/jvmti/compiledMethodLoad/compiledMethodLoad.c new file mode 100644 index 00000000000..9eec1b45e28 --- /dev/null +++ b/jdk/src/share/demo/jvmti/compiledMethodLoad/compiledMethodLoad.c @@ -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 +#include +#include + +#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) +{ +} diff --git a/jdk/src/share/demo/jvmti/compiledMethodLoad/sample.makefile.txt b/jdk/src/share/demo/jvmti/compiledMethodLoad/sample.makefile.txt new file mode 100644 index 00000000000..a759dc71751 --- /dev/null +++ b/jdk/src/share/demo/jvmti/compiledMethodLoad/sample.makefile.txt @@ -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= OSNAME=solaris [OPT=true] [LIBARCH=sparc] +# gnumake JDK= OSNAME=solaris [OPT=true] [LIBARCH=sparcv9] +# gnumake JDK= OSNAME=linux [OPT=true] +# gnumake JDK= 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 + diff --git a/jdk/src/share/demo/jvmti/index.html b/jdk/src/share/demo/jvmti/index.html index 87da6cc1171..b3efe373d45 100644 --- a/jdk/src/share/demo/jvmti/index.html +++ b/jdk/src/share/demo/jvmti/index.html @@ -99,6 +99,13 @@ version string supplied in the jvmti.h file, with the version number supplied by the VM at runtime. +
  • +compiledMethodLoad +
    +This is a small agent that traces CompiledMethodLoad events along +with the HotSpot specific compile_info parameter. +
  • +
  • mtrace
    diff --git a/jdk/src/share/javavm/export/jvmticmlr.h b/jdk/src/share/javavm/export/jvmticmlr.h new file mode 100644 index 00000000000..d2713954f6f --- /dev/null +++ b/jdk/src/share/javavm/export/jvmticmlr.h @@ -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 diff --git a/jdk/test/demo/jvmti/compiledMethodLoad/CompiledMethodLoadTest.java b/jdk/test/demo/jvmti/compiledMethodLoad/CompiledMethodLoadTest.java new file mode 100644 index 00000000000..de0d1b962a8 --- /dev/null +++ b/jdk/test/demo/jvmti/compiledMethodLoad/CompiledMethodLoadTest.java @@ -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"); + } +} diff --git a/jdk/test/demo/jvmti/heapTracker/HeapTrackerTest.java b/jdk/test/demo/jvmti/heapTracker/HeapTrackerTest.java index 20e05de4f4a..9f0b70a4ab0 100644 --- a/jdk/test/demo/jvmti/heapTracker/HeapTrackerTest.java +++ b/jdk/test/demo/jvmti/heapTracker/HeapTrackerTest.java @@ -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. */ diff --git a/jdk/test/demo/jvmti/hprof/CpuTimesDefineClassTest.java b/jdk/test/demo/jvmti/hprof/CpuTimesDefineClassTest.java index 63cfcb3e5c4..922aafc19ee 100644 --- a/jdk/test/demo/jvmti/hprof/CpuTimesDefineClassTest.java +++ b/jdk/test/demo/jvmti/hprof/CpuTimesDefineClassTest.java @@ -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. */ diff --git a/jdk/test/demo/jvmti/hprof/CpuTimesTest.java b/jdk/test/demo/jvmti/hprof/CpuTimesTest.java index a99d384494b..3e378d414f8 100644 --- a/jdk/test/demo/jvmti/hprof/CpuTimesTest.java +++ b/jdk/test/demo/jvmti/hprof/CpuTimesTest.java @@ -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. */ diff --git a/jdk/test/demo/jvmti/minst/MinstTest.java b/jdk/test/demo/jvmti/minst/MinstTest.java index 70c64344a64..fbc9adfce5b 100644 --- a/jdk/test/demo/jvmti/minst/MinstTest.java +++ b/jdk/test/demo/jvmti/minst/MinstTest.java @@ -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. */ diff --git a/jdk/test/demo/jvmti/mtrace/TraceJFrame.java b/jdk/test/demo/jvmti/mtrace/TraceJFrame.java index 34def2770c2..d80c578c4a9 100644 --- a/jdk/test/demo/jvmti/mtrace/TraceJFrame.java +++ b/jdk/test/demo/jvmti/mtrace/TraceJFrame.java @@ -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. */