Commit ed524974 authored by Lubomir Bulej's avatar Lubomir Bulej

- Merged the new DiSL agent code. Code generations options are not yet used.

- Removed the old DiSL agent code as well as the old Java agent.
- Copied old shared DiSL agent headers to Shadow VM agent.
- Added JDK includes for JNI and JVMTI to avoid looking for them.
- Unified the naming of source directories.
- Updated the test infrastructure to the new build system layout.
- Examples can be now run even from the source distribution.
parent 307e662d
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="output/build/disl" path="src"/>
<classpathentry kind="src" output="output/build/shvm" path="src-re-server"/>
<classpathentry kind="src" output="output/build/disl" path="src-disl"/>
<classpathentry kind="src" output="output/build/shvm" path="src-shvm"/>
<classpathentry kind="src" output="output/build/util" path="src-util"/>
<classpathentry kind="src" output="output/build/test" path="src-test"/>
<classpathentry kind="src" output="output/build/shvm-dispatch" path="src-re-disp"/>
<classpathentry kind="src" output="output/build/disl-agent" path="src-agent-java"/>
<classpathentry kind="src" output="output/build/shvm-dispatch" path="src-shvm-dispatch"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="output/eclipse-dynamicbypass.jar"/>
<classpathentry kind="lib" path="output/lib/disl-bypass.jar"/>
<classpathentry kind="lib" path="lib/asm-debug-all-4.1.jar"/>
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="lib/junit-4.11.jar"/>
......
......@@ -472,7 +472,7 @@ def run_client(args, parser):
cagent = args.disl_home+"/lib/libdislagent"+lib_suffix()
eagent = args.disl_home+"/lib/libdislreagent"+lib_suffix()
jagent = args.disl_home+"/lib/disl-agent.jar"
bypass = args.disl_home+"/lib/disl-bypass.jar"
dispatch = args.disl_home+"/lib/dislre-dispatch.jar"
c_cmd = ["java"]
......@@ -482,12 +482,10 @@ def run_client(args, parser):
if args.cse == True:
c_cmd+= ["-agentpath:"+eagent]
c_cmd+= ["-javaagent:"+jagent]
if args.cse == True:
c_cmd+= ["-Xbootclasspath/a:"+jagent+":"+args.instrumentation+":"+dispatch]
c_cmd+= ["-Xbootclasspath/a:"+bypass+":"+args.instrumentation+":"+dispatch]
else:
c_cmd+= ["-Xbootclasspath/a:"+jagent+":"+args.instrumentation]
c_cmd+= ["-Xbootclasspath/a:"+bypass+":"+args.instrumentation]
c_cmd+= args.c_app
......
......@@ -14,14 +14,12 @@ ant-contrib.path=${lib.dir}/${ant-contrib.lib}
src.bin=bin
src.disl=src
src.disl.bypass=src-dynbypass
src.disl.bypass.dynamic=src-dynbypass-act
src.disl.agent=src-agent-c
src.disl.agent.java=src-agent-java
src.shvm=src-re-server
src.shvm.dispatch=src-re-disp
src.shvm.agent=src-re-agent
src.disl=src-disl
src.disl.bypass=src-disl-bypass
src.disl.agent=src-disl-agent
src.shvm=src-shvm
src.shvm.agent=src-shvm-agent
src.shvm.dispatch=src-shvm-dispatch
src.test=src-test
src.util=src-util
src.doc=doc
......@@ -30,29 +28,52 @@ src.doc.intro=${src.doc}/intro
src.examples=examples
# Based output directory
out.dir=output
build=${out.dir}/build
build.util=${build}/util
build.disl=${build}/disl
# Directories for building artifacts
build.dir=${out.dir}/build
build.util=${build.dir}/util
build.disl=${build.dir}/disl
build.disl.thread=${build.disl}-thread
build.disl.bypass=${build.disl}-bypass
build.disl.agent.java=${build.disl}-agent
build.shvm=${build}/shvm
build.shvm=${build.dir}/shvm
build.shvm.dispatch=${build.shvm}-dispatch
build.test=${build}/test
build.test.jars=${build.test}-jars
build.doc=${build}/doc
build.doc.intro=${build.doc}-intro
dist=${out.dir}/dist
dist.bin=${dist}/bin
dist.lib=${dist}/lib
dist.doc=${dist}/doc
dist.doc.jdoc=${dist.doc}/javadoc
build.test=${build.dir}/test
build.doc.intro=${build.dir}/intro
# Directories for output artifacts
out.lib=${out.dir}/lib
out.src=${out.dir}/src
out.test=${out.dir}/test
out.doc.jdoc=${out.dir}/jdoc
# Output library artifact names
disl.lib=disl-server.jar
disl.bypass.lib=disl-bypass.jar
disl.agent.lib.base=dislagent
shvm.lib=dislre-server.jar
shvm.dispatch.lib=dislre-dispatch.jar
shvm.agent.lib.base=dislreagent
eclipse.agent.lib=eclipse-agent.jar
# Directories in distribution archives
dist.bin=bin
dist.lib=lib
dist.doc=doc
dist.doc.intro=${dist.doc}/intro
dist.examples=${dist}/examples
dist.doc.jdoc=${dist.doc}/javadoc
dist.examples=examples
dist.src=
# Directory for release archives
release=${out.dir}/release
release.bin.zip=${release}/disl-${disl.version}-bin.zip
release.bin.tar=${release}/disl-${disl.version}-bin.tar.bz2
......
This diff is collapsed.
disl.version=unspec
disl.version=devel
disl.prefix=disl-${disl.version}
......@@ -3,9 +3,9 @@
================================================================================
These examples demonstrate fthe basic features of DiSL. In addition, they
provide guidelines on how to package the instrumentation classes and how to run
the instrumented application using a simple launcher script that takes care of
starting the necessary Java virtual machines.
provide basic guidelines on how to package the instrumentation classes and how
to run the instrumented application using a simple launcher script that takes
care of starting the necessary Java virtual machines.
--------------------------------------------------------------------------------
......@@ -107,20 +107,19 @@ more details try running this example directly using "disl.py" and supplying
= HOW TO RUN THE EXAMPLES
================================================================================
If you have downloaded a binary DiSL distribution, enter the "examples"
directory. If you are using a source DiSL distribution, first compile DiSL by
running "ant" in the top-level directory (see README), then enter the
"output/dist/examples" directory.
If you are using a source DiSL distribution, first compile DiSL by running
"ant" in the top-level directory (see README). You can skip this step if you
are using a binary distribution of DiSL.
Choose an example you want to run, for example "smoke", and enter the
corresponding directory. To run the example, just execute "ant run".
In the "examples" directory, choose an example you want to run, e.g., "smoke",
enter the corresponding directory, and execute "ant run".
This command builds and packages the application and the instrumentation
classes and then, using the laucher script, starts the DiSL instrumentation
server and later on the application VM.
The output of the application and the applied instrumentation should be visible
on the console.
The output of the application as well as that of the applied instrumentation
should be visible on the console.
When compiled, the example can be also run using the "disl.py" launcher script
found in the "bin" directory, which allows specifying more options. To learn
......
<!--
This build file is intended to be included
from a build.xml file in each example directory.
-->
<project name="example">
<!--
This build file is intended to be included
from a build.xml file in each example directory.
-->
<property name="build.sysclasspath" value="ignore" />
<dirname property="examples.basedir" file="${ant.file.example}" />
<property file="${examples.basedir}/build-override.properties" />
<property file="${examples.basedir}/build.properties" />
<path id="inst.classpath">
<pathelement location="${examples.basedir}/${asm.path}" />
<pathelement location="${examples.basedir}/${disl.server.path}" />
<pathelement location="${examples.basedir}/${shvm.server.path}" />
<pathelement location="${examples.basedir}/${shvm.dispatch.path}" />
<pathelement location="${asm.path}" />
<pathelement location="${disl.server.path}" />
<pathelement location="${shvm.server.path}" />
<pathelement location="${shvm.dispatch.path}" />
</path>
<target name="init">
<mkdir dir="${build}" />
</target>
<target name="compile-app" depends="init">
<target name="build-app" description="Compiles and packages the application.">
<mkdir dir="${build.app}" />
<javac srcdir="${src.app}" destdir="${build.app}" debug="true" includeAntRuntime="false" />
</target>
<target name="package-app" depends="compile-app" description="Creates application package.">
<jar basedir="${build.app}" destfile="${build}/${app.jar.name}">
<jar destfile="${app.path}" basedir="${build.app}">
<manifest>
<attribute name="Main-Class" value="Main" />
</manifest>
</jar>
</target>
<target name="compile-inst" depends="init">
<target name="build-inst" description="Compiles and packages the instrumentation.">
<mkdir dir="${build.inst}" />
<javac srcdir="${src.inst}" destdir="${build.inst}" debug="true" includeAntRuntime="false">
<classpath refid="inst.classpath" />
</javac>
</target>
<target name="package-inst" depends="compile-inst" description="Creates instrumentation package.">
<jar basedir="${build.inst}" destfile="${build}/${inst.jar.name}" excludes="MANIFEST.MF" manifest="${src.inst}/MANIFEST.MF" />
<jar destfile="${inst.path}" basedir="${build.inst}" excludes="MANIFEST.MF" manifest="${src.inst}/MANIFEST.MF" />
</target>
<target name="build" depends="package-app,package-inst" />
<target name="build" depends="build-app,build-inst" />
<target name="run" depends="build">
<exec executable="${examples.basedir}/${bin.path}/disl.py">
<exec executable="${disl.launcher.path}">
<arg value="-d" />
<arg value="${disl.home}" />
<arg value="-cse" />
<!-- <arg value="-c_out=client.out" /> -->
<!-- <arg value="-e_out=evaluation.out" /> -->
<arg value="--" />
<arg value="${build}/${inst.jar.name}" />
<arg value="${inst.path}" />
<arg value="-jar" />
<arg value="${build}/${app.jar.name}" />
</exec>
<arg value="${app.path}" />
</exec>
</target>
<target name="clean">
<delete dir="${build}" />
<delete dir="${build.dir}" />
</target>
</project>
disl.home=${examples.basedir}/../output
bin.path=${examples.basedir}/../bin
disl.home=..
disl.home=${examples.basedir}/..
lib.path=${disl.home}/lib
bin.path=${disl.home}/bin
disl.launcher.path=${bin.path}/disl.py
disl.server.path=${lib.path}/disl-server.jar
shvm.server.path=${lib.path}/dislre-server.jar
shvm.dispatch.path=${lib.path}/dislre-dispatch.jar
asm.version=4.1
asm.path=${lib.path}/asm-debug-all-${asm.version}.jar
asm.path=${lib.path}/asm-debug-all-4.1.jar
src.app=src-app
src.inst=src-inst
build=build
build.app=${build}/app
build.inst=${build}/inst
build.dir=build
build.app=${build.dir}/app
build.inst=${build.dir}/inst
app.jar.name=example-app.jar
inst.jar.name=example-inst.jar
app.path=${build.dir}/example-app.jar
inst.path=${build.dir}/example-inst.jar
# if there is JAVA_HOME var file then include it
ifneq (, $(wildcard javahome/var))
include javahome/var
endif
# Source lists
LIBNAME=dislagent
SOURCES=dislagent.c
# Object files needed to create library
OBJECTS=$(SOURCES:%.c=%.o)
# Library name and options needed to build it
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
LIBRARY=lib$(LIBNAME).so
JNI_OS=linux
else ifeq ($(UNAME), Darwin)
LIBRARY=lib$(LIBNAME).jnilib
JNI_OS=darwin
else
$(error error: unsupported operating system: $(UNAME))
endif
# Building a shared library
LINK_SHARED=$(LINK.c) -shared -o $@
# GNU Compiler options needed to build it
COMMON_FLAGS=-fPIC
# Options that help find errors
COMMON_FLAGS+= -W -Wall -Wextra -O3 -Wno-unused-parameter
CFLAGS += $(COMMON_FLAGS)
CFLAGS += -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(JNI_OS)
# add debugging output
ifeq ($(DEBUG), TRUE)
CFLAGS += -DDEBUG
endif
all: $(LIBRARY)
# Build native library
$(LIBRARY): $(OBJECTS)
$(LINK_SHARED) $(OBJECTS) $(LIBRARIES)
# Cleanup the built bits
clean:
rm -f $(LIBRARY) $(OBJECTS)
debug:
$(MAKE) DEBUG=TRUE
This diff is collapsed.
package ch.usi.dag.dislagent;
import java.lang.instrument.Instrumentation;
import ch.usi.dag.disl.dynamicbypass.Bootstrap;
public class DiSLAgent {
private static volatile Instrumentation myInstrumentation;
public static void premain(String agentArguments,
Instrumentation instrumentation) {
myInstrumentation = instrumentation;
if (!Boolean.getBoolean("dislserver.noBootstrap")) {
Bootstrap.completed(instrumentation);
}
}
public static Instrumentation getInstrumentation() {
return myInstrumentation;
}
}
# Import local variable definitions
-include Makefile.local
INCLUDE_DIR ?= ../src-jdk-include
ifeq ($(OS),Windows_NT)
ifeq (,$(findstring /cygdrive/,$(PATH)))
$(error Building on the Windows platform is only supported under Cygwin)
endif
HOST_ENV := Cygwin
else
HOST_ENV := $(shell uname -s)
HOST_CPU := $(shell uname -m)
endif
TARGET_ENV ?= $(HOST_ENV)
TARGET_CPU ?= $(HOST_CPU)
ifneq ($(HOST_ENV),$(TARGET_ENV))
ifneq ($(TARGET_ENV),MinGW)
$(error Cross-compiling is only supported for TARGET_ENV=MinGW)
else
$(warning The MinGW port for the Windows platform is experimental!)
endif
endif
ifneq (,$(filter MinGW Cygwin,$(TARGET_ENV)))
LIB_PREFIX :=
LIB_SUFFIX := .dll
JDK_TARGET := windows
ifeq (MinGW,$(TARGET_ENV))
CC := $(TARGET_CPU)-w64-mingw32-gcc
CFLAGS += -DMINGW -mthreads
CFLAGS_LD += -Wl,--kill-at
LIBS += -lws2_32
endif
else ifeq (Darwin,$(TARGET_ENV))
LIB_PREFIX := lib
LIB_SUFFIX := .jnilib
JDK_TARGET := macosx
else ifeq (Linux,$(TARGET_ENV))
LIB_PREFIX := lib
LIB_SUFFIX := .so
JDK_TARGET := linux
else
$(error Target environment $(TARGET_ENV) is not supported)
endif
# Source and object files needed to create the library
SOURCES = bytecode.c common.c jvmtiutil.c connection.c \
connpool.c msgchannel.c network.c dislagent.c
HEADERS = $(wildcard *.h) codeflags.h
OBJECTS = $(SOURCES:%.c=%.o)
LIBRARY = $(LIB_PREFIX)dislagent$(LIB_SUFFIX)
# Base options depending on the build
ifeq (,$(DEBUG))
CFLAGS += -O3 -DNDEBUG -fomit-frame-pointer
else
CFLAGS += -g3 -DDEBUG
endif
# Tell the linker to create a shared library.
CFLAGS_LD += -shared
#
# For non-MinGW targets, use position independent code
# and dynamically link to the pthread library. When
# building the library as a whole, tell GCC to build
# a shared library as well.
#
ifneq (MinGW,$(TARGET_ENV))
CFLAGS += -fPIC
LIBS += -lpthread
endif
# JNI and JVMTI includes
CFLAGS += -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/$(JDK_TARGET)
# Source code options
CFLAGS += -std=gnu99 -W -Wall -Wextra -Wno-unused-parameter
# Fix-up quirks before first target
-include Makefile.quirks
all: $(LIBRARY)
# Build native library
ifneq (,$(WHOLE))
CFLAGS += -DWHOLE -fwhole-program -flto
$(LIBRARY): $(HEADERS) $(SOURCES)
$(CC) $(CFLAGS) $(TARGET_ARCH) $(CFLAGS_LD) $(SOURCES) $(LIBS) $(OUTPUT_OPTION)
else
$(LIBRARY): $(HEADERS) $(OBJECTS)
$(CC) $(CFLAGS) $(TARGET_ARCH) $(CFLAGS_LD) $(OBJECTS) $(LIBS) $(OUTPUT_OPTION)
endif
# Generated files
include Makefile.bypass
$(BYPASS_FILES):
ant -f ../build.xml compile-disl-bypass
bytecode.c: $(BYPASS_FILES) Makefile.bypass bin2cdef
./bin2cdef \
$(foreach BPC,$(BYPASS_FILES),$(BPC) $(subst /$(BYPASS_PKG_PATH)/,_,$(subst $(BYPASS_DIR)/,,$(BPC:.class=)))) \
> $@
codeflags.h:
ant -f ../build.xml prepare-disl-agent-codeflags
# Cleanup targets
clean:
-rm -f $(OBJECTS)
cleanall: clean
-rm -f $(LIBRARY)
pristine: cleanall
-rm -f Makefile.build
-rm -f codeflags.h bytecode.c
# Convenience targets
debug:
$(MAKE) DEBUG=1
whole:
$(MAKE) WHOLE=1
# Generated using the "prepare-disl-agent-makefile" Ant target.
BYPASS_DIR = ../output/build/disl-bypass
BYPASS_PKG_PATH = ch/usi/dag/disl/dynamicbypass
BYPASS_FILES += ../output/build/disl-bypass/always/ch/usi/dag/disl/dynamicbypass/BypassCheck.class
BYPASS_FILES += ../output/build/disl-bypass/dynamic/ch/usi/dag/disl/dynamicbypass/BypassCheck.class
BYPASS_FILES += ../output/build/disl-bypass/never/ch/usi/dag/disl/dynamicbypass/BypassCheck.class
#
# This file is intended to contain variable assignments specific to this
# environment, without having to modify the main Makefile.
#
#!/bin/bash
cat <<- EOT
/**
* DO NOT EDIT!
*
* This file was generated using the bin2cdef script.
*/
#include <jvmti.h>
EOT
while [ $# -gt 1 ]; do
FILE=$1; shift
NAME=$1; shift
cat << EOT
jvmtiClassDefinition ${NAME}_classdef = {
.class_byte_count = $(stat --format '%s' ${FILE}),
.class_bytes = (unsigned char *)
$(hexdump -e '"\t\t" "Q" 16/1 "xxx%02x" "Q" "\n"' ${FILE} |sed 's/xxx //g; y/Q/"/; s/xxx/\\x/g'),
};
EOT
done
/**
* DO NOT EDIT!
*
* This file was generated using the bin2cdef script.
*/
#include <jvmti.h>
jvmtiClassDefinition always_BypassCheck_classdef = {
.class_byte_count = 388,
.class_bytes = (unsigned char *)
"\xca\xfe\xba\xbe\x00\x00\x00\x33\x00\x12\x0a\x00\x03\x00\x0f\x07"
"\x00\x10\x07\x00\x11\x01\x00\x06\x3c\x69\x6e\x69\x74\x3e\x01\x00"
"\x03\x28\x29\x56\x01\x00\x04\x43\x6f\x64\x65\x01\x00\x0f\x4c\x69"
"\x6e\x65\x4e\x75\x6d\x62\x65\x72\x54\x61\x62\x6c\x65\x01\x00\x12"
"\x4c\x6f\x63\x61\x6c\x56\x61\x72\x69\x61\x62\x6c\x65\x54\x61\x62"
"\x6c\x65\x01\x00\x04\x74\x68\x69\x73\x01\x00\x2b\x4c\x63\x68\x2f"
"\x75\x73\x69\x2f\x64\x61\x67\x2f\x64\x69\x73\x6c\x2f\x64\x79\x6e"
"\x61\x6d\x69\x63\x62\x79\x70\x61\x73\x73\x2f\x42\x79\x70\x61\x73"
"\x73\x43\x68\x65\x63\x6b\x3b\x01\x00\x15\x65\x78\x65\x63\x75\x74"
"\x65\x55\x6e\x69\x6e\x73\x74\x72\x75\x6d\x65\x6e\x74\x65\x64\x01"
"\x00\x03\x28\x29\x5a\x01\x00\x0a\x53\x6f\x75\x72\x63\x65\x46\x69"
"\x6c\x65\x01\x00\x10\x42\x79\x70\x61\x73\x73\x43\x68\x65\x63\x6b"
"\x2e\x6a\x61\x76\x61\x0c\x00\x04\x00\x05\x01\x00\x29\x63\x68\x2f"
"\x75\x73\x69\x2f\x64\x61\x67\x2f\x64\x69\x73\x6c\x2f\x64\x79\x6e"
"\x61\x6d\x69\x63\x62\x79\x70\x61\x73\x73\x2f\x42\x79\x70\x61\x73"
"\x73\x43\x68\x65\x63\x6b\x01\x00\x10\x6a\x61\x76\x61\x2f\x6c\x61"
"\x6e\x67\x2f\x4f\x62\x6a\x65\x63\x74\x00\x31\x00\x02\x00\x03\x00"
"\x00\x00\x00\x00\x02\x00\x01\x00\x04\x00\x05\x00\x01\x00\x06\x00"
"\x00\x00\x2f\x00\x01\x00\x01\x00\x00\x00\x05\x2a\xb7\x00\x01\xb1"
"\x00\x00\x00\x02\x00\x07\x00\x00\x00\x06\x00\x01\x00\x00\x00\x0c"
"\x00\x08\x00\x00\x00\x0c\x00\x01\x00\x00\x00\x05\x00\x09\x00\x0a"
"\x00\x00\x00\x09\x00\x0b\x00\x0c\x00\x01\x00\x06\x00\x00\x00\x1a"
"\x00\x01\x00\x00\x00\x00\x00\x02\x04\xac\x00\x00\x00\x01\x00\x07"
"\x00\x00\x00\x06\x00\x01\x00\x00\x00\x0f\x00\x01\x00\x0d\x00\x00"
"\x00\x02\x00\x0e",
};
jvmtiClassDefinition dynamic_BypassCheck_classdef = {
.class_byte_count = 460,
.class_bytes = (unsigned char *)
"\xca\xfe\xba\xbe\x00\x00\x00\x33\x00\x17\x0a\x00\x04\x00\x10\x0a"
"\x00\x11\x00\x12\x07\x00\x13\x07\x00\x14\x01\x00\x06\x3c\x69\x6e"
"\x69\x74\x3e\x01\x00\x03\x28\x29\x56\x01\x00\x04\x43\x6f\x64\x65"
"\x01\x00\x0f\x4c\x69\x6e\x65\x4e\x75\x6d\x62\x65\x72\x54\x61\x62"
"\x6c\x65\x01\x00\x12\x4c\x6f\x63\x61\x6c\x56\x61\x72\x69\x61\x62"
"\x6c\x65\x54\x61\x62\x6c\x65\x01\x00\x04\x74\x68\x69\x73\x01\x00"
"\x2b\x4c\x63\x68\x2f\x75\x73\x69\x2f\x64\x61\x67\x2f\x64\x69\x73"
"\x6c\x2f\x64\x79\x6e\x61\x6d\x69\x63\x62\x79\x70\x61\x73\x73\x2f"
"\x42\x79\x70\x61\x73\x73\x43\x68\x65\x63\x6b\x3b\x01\x00\x15\x65"
"\x78\x65\x63\x75\x74\x65\x55\x6e\x69\x6e\x73\x74\x72\x75\x6d\x65"
"\x6e\x74\x65\x64\x01\x00\x03\x28\x29\x5a\x01\x00\x0a\x53\x6f\x75"
"\x72\x63\x65\x46\x69\x6c\x65\x01\x00\x10\x42\x79\x70\x61\x73\x73"