Commit 6bb54a32 authored by František Haas's avatar František Haas

fixed example bugs

fixed some details reported by findbugs and pmd 
added libs licenses
improved marker javadoc
removed scripts from build.xml, added ant-contrib
parent 27fd4f3b
================================================================================
= DiSL
================================================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
......@@ -201,34 +204,8 @@
limitations under the License.
For the library lib/asm-debug-all-4.0.jar
================================================================================
= LIBRARIES
================================================================================
Licenses for libraries used in the project are in the lib directory.
Copyright (c) 2000-2011 INRIA, France Telecom
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. 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.
3. Neither the name of the copyright holders 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.
......@@ -30,10 +30,8 @@ Firstly, building of suite test apps and instrumentations is handled by a
scripted target that lists all directories in a "ch.usi.dag.disl.test2.suite"
package and one by one "app" and "instr" package are jared.
If not scripted, evil ant-contrib would be required.
Secondly, when running the instances of client and server using Process API
never forget to clear environemnt variables as inherited classpath could cause
never forget to clear environment variables as inherited classpath could cause
serious troubles.
If a suite instr test contains a manifest file it's used and if none is present
......
......@@ -6,6 +6,10 @@ junit.core.path=lib/${junit.core.lib}
junit.hamcrest.lib=hamcrest-core-1.3.jar
junit.hamcrest.path=lib/${junit.hamcrest.lib}
ant-contrib.lib=ant-contrib-0.6.jar
ant-contrib.resource=net/sf/antcontrib/antlib.xml
ant-contrib.path=lib/${ant-contrib.lib}
src.disl=src
src.dynbypass=src-dynbypass
src.dynbypass.act=src-dynbypass-act
......
This diff is collapsed.
================================================================================
= DiSL SETUP EXAMPLE
================================================================================
These simple examples illustrates a basic instrumentation setup. It shows, how
the instrumentation should be packaged and contains a scripts that should ease
running DiSL together with your program.
......@@ -109,7 +108,6 @@ enables more detailed settings. To learn more about this run "./disl.py -h"
================================================================================
= NOTE
================================================================================
If you want to use "disl.py" to run your application, don't forget to set
"DISL_HOME" variable correctly or it can be specified to "disl.py" at command
line or inside the script as a default value.
......@@ -118,12 +116,9 @@ line or inside the script as a default value.
================================================================================
= NOTE
================================================================================
If you want to include use some library in your instrumentation you should
insert it directly to the instrumentation jar using jarjar.
http://code.google.com/p/jarjar/
Other option is to provide library's classpath to the "disl.py" utility.
<project name="disl-example" default="clean" basedir=".">
<project name="disl-example" default="run" basedir=".">
<target name="clean">
<ant antfile="dynamic/build.xml" target="clean" useNativeBasedir="true" />
<ant antfile="guard/build.xml" target="clean" useNativeBasedir="true" />
......@@ -7,4 +7,13 @@
<ant antfile="smoke/build.xml" target="clean" useNativeBasedir="true" />
<ant antfile="static/build.xml" target="clean" useNativeBasedir="true" />
</target>
<target name="run">
<ant antfile="dynamic/build.xml" target="run" useNativeBasedir="true" />
<ant antfile="guard/build.xml" target="run" useNativeBasedir="true" />
<ant antfile="marker/build.xml" target="run" useNativeBasedir="true" />
<ant antfile="scope/build.xml" target="run" useNativeBasedir="true" />
<ant antfile="smoke/build.xml" target="run" useNativeBasedir="true" />
<ant antfile="static/build.xml" target="run" useNativeBasedir="true" />
</target>
</project>
import ch.usi.dag.disl.annotation.After;
import ch.usi.dag.disl.annotation.AfterReturning;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.marker.MethodInvocationMarker;
public class DiSLClass {
......
import java.util.LinkedList;
import java.util.List;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import ch.usi.dag.disl.marker.AbstractMarker;
import ch.usi.dag.disl.marker.AbstractDWRMarker;
/**
* Sets the region on every method invocation instruction.
*
*/
public class MethodInvocationMarker extends AbstractDWRMarker {
public List<MarkedRegion> markWithDefaultWeavingReg(MethodNode method) {
List<MarkedRegion> regions = new LinkedList<MarkedRegion>();
// traverse all instructions
InsnList instructions = method.instructions;
for (AbstractInsnNode instruction : instructions.toArray()) {
// check for method invocation instructions
if (instruction instanceof MethodInsnNode) {
// add region containing one instruction (method invocation)
regions.add(new MarkedRegion(instruction, instruction));
}
}
return regions;
}
}
import ch.usi.dag.disl.annotation.After;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.marker.BodyMarker;
import ch.usi.dag.disl.staticcontext.DumbLoopContext;
import ch.usi.dag.disl.staticcontext.MethodStaticContext;
public class DiSLClass {
......@@ -19,4 +18,4 @@ public class DiSLClass {
System.out.printf("disl: %s had no loop\n", msc.thisMethodName());
}
}
}
\ No newline at end of file
}
import ch.usi.dag.disl.annotation.GuardMethod;
import ch.usi.dag.disl.staticcontext.DumbLoopContext;
public class DumbLoopGuard {
......
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 Ant-Contrib project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. 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.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Ant-Contrib project (http://sourceforge.net/projects/ant-contrib)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The name Ant-Contrib must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact
* ant-contrib-developers@lists.sourceforge.net.
*
* 5. Products derived from this software may not be called "Ant-Contrib"
* nor may "Ant-Contrib" appear in their names without prior written
* permission of the Ant-Contrib project.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 ANT-CONTRIB PROJECT OR ITS
* 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.
* ====================================================================
*/
Copyright (c) 2000-2011 INRIA, France Telecom
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. 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.
3. Neither the name of the copyright holders 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.
BSD License
Copyright (c) 2000-2006, www.hamcrest.org
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 Hamcrest 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.
This diff is collapsed.
......@@ -2,143 +2,147 @@ package ch.usi.dag.dislreserver.shadow;
public abstract class ShadowClass extends ShadowObject {
private final int classId;
private final ShadowObject classLoader;
private final int classId;
private final ShadowObject classLoader;
//
protected ShadowClass (
final long netReference, final ShadowObject classLoader
) {
super (netReference, null);
//
this.classId = NetReferenceHelper.get_class_id (netReference);
protected ShadowClass(
final long netReference, final ShadowObject classLoader) {
super(netReference, null);
this.classId = NetReferenceHelper.get_class_id(netReference);
this.classLoader = classLoader;
}
//
//
// No need to expose the interface to user
// getId() should be sufficient
protected final int getClassId() {
return classId;
}
// No need to expose the interface to user
// getId() should be sufficient
protected final int getClassId() {
return classId;
}
public final ShadowObject getShadowClassLoader() {
return classLoader;
}
public final ShadowObject getShadowClassLoader() {
return classLoader;
}
public abstract boolean isArray();
public abstract boolean isArray();
public abstract ShadowClass getComponentType();
public abstract ShadowClass getComponentType();
public abstract boolean isInstance(ShadowObject obj);
public abstract boolean isInstance(ShadowObject obj);
public abstract boolean isAssignableFrom(ShadowClass klass);
public abstract boolean isAssignableFrom(ShadowClass klass);
public abstract boolean isInterface();
public abstract boolean isInterface();
public abstract boolean isPrimitive();
public abstract boolean isPrimitive();
public abstract boolean isAnnotation();
public abstract boolean isAnnotation();
public abstract boolean isSynthetic();
public abstract boolean isSynthetic();
public abstract boolean isEnum();
public abstract boolean isEnum();
public abstract String getName();
public abstract String getName();
public abstract String getCanonicalName();
public abstract String getCanonicalName();
public abstract String[] getInterfaces();
public abstract String[] getInterfaces();
public abstract String getPackage();
public abstract String getPackage();
public abstract ShadowClass getSuperclass();
public abstract ShadowClass getSuperclass();
@Override
public boolean equals(Object obj) {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof ShadowClass)) {
return false;
}
if (!(obj instanceof ShadowClass)) {
return false;
}
ShadowClass sClass = (ShadowClass) obj;
ShadowClass sClass = (ShadowClass) obj;
if (getName().equals(sClass.getName())
&& getShadowClassLoader().equals(sClass.getShadowClassLoader())) {
return true;
}
if (getName().equals(sClass.getName())
&& getShadowClassLoader().equals(sClass.getShadowClassLoader())) {
return true;
}
return false;
}
public abstract FieldInfo[] getFields();
return false;
}
public abstract FieldInfo getField(String fieldName)
throws NoSuchFieldException;
@Override
public int hashCode() {
throw new UnsupportedOperationException("overriden equals, not overriden hashCode");
}
public abstract MethodInfo[] getMethods();
public abstract FieldInfo[] getFields();
public abstract MethodInfo getMethod(String methodName,
String[] argumentNames) throws NoSuchMethodException;
public abstract FieldInfo getField(String fieldName)
throws NoSuchFieldException;
public abstract String[] getDeclaredClasses();
public abstract MethodInfo[] getMethods();
public abstract FieldInfo[] getDeclaredFields();
public abstract MethodInfo getMethod(String methodName,
String[] argumentNames) throws NoSuchMethodException;
public abstract FieldInfo getDeclaredField(String fieldName)
throws NoSuchFieldException;
public abstract String[] getDeclaredClasses();
public abstract MethodInfo[] getDeclaredMethods();
public abstract FieldInfo[] getDeclaredFields();
public abstract MethodInfo getDeclaredMethod(String methodName,
String[] argumentNames) throws NoSuchMethodException;
public abstract FieldInfo getDeclaredField(String fieldName)
throws NoSuchFieldException;
public MethodInfo getMethod(String methodName, ShadowClass[] arguments)
throws NoSuchMethodException {
return getMethod(methodName, classesToStrings(arguments));
}
public abstract MethodInfo[] getDeclaredMethods();
public MethodInfo getDeclaredMethod(String methodName,
ShadowClass[] arguments) throws NoSuchMethodException {
return getDeclaredMethod(methodName, classesToStrings(arguments));
}
public abstract MethodInfo getDeclaredMethod(String methodName,
String[] argumentNames) throws NoSuchMethodException;
protected static String[] classesToStrings(ShadowClass[] arguments) {
public MethodInfo getMethod(String methodName, ShadowClass[] arguments)
throws NoSuchMethodException {
return getMethod(methodName, classesToStrings(arguments));
}
if (arguments == null) {
return new String[0];
}
public MethodInfo getDeclaredMethod(String methodName,
ShadowClass[] arguments) throws NoSuchMethodException {
return getDeclaredMethod(methodName, classesToStrings(arguments));
}
protected static String[] classesToStrings(ShadowClass[] arguments) {
int size = arguments.length;
String[] argumentNames = new String[size];
if (arguments == null) {
return new String[0];
}
for (int i = 0; i < size; i++) {
argumentNames[i] = arguments[i].getName();
}
int size = arguments.length;
String[] argumentNames = new String[size];
return argumentNames;
}
for (int i = 0; i < size; i++) {
argumentNames[i] = arguments[i].getName();
}
protected static String argumentNamesToString(String[] argumentNames) {
StringBuilder buf = new StringBuilder();
buf.append("(");
return argumentNames;
}
if (argumentNames != null) {
protected static String argumentNamesToString(String[] argumentNames) {
StringBuilder buf = new StringBuilder();
buf.append("(");
for (int i = 0; i < argumentNames.length; i++) {
if (argumentNames != null) {
if (i > 0) {
buf.append(", ");
}
for (int i = 0; i < argumentNames.length; i++) {
buf.append(argumentNames[i]);
}
}
if (i > 0) {
buf.append(", ");
}
buf.append(")");
return buf.toString();
}
buf.append(argumentNames[i]);
}
}
buf.append(")");
return buf.toString();
}
}
\ No newline at end of file
}
......@@ -4,37 +4,42 @@ package ch.usi.dag.dislreserver.shadow;
// over network - throw a runtime exception ??
public class ShadowString extends ShadowObject {
private String value;
private String value;
public ShadowString(long net_ref, String value, ShadowClass klass) {
super(net_ref, klass);
this.value = value;
}
public ShadowString(long net_ref, String value, ShadowClass klass) {
super(net_ref, klass);
this.value = value;
}
// TODO warn user that it will return null when the ShadowString is not yet sent.
@Override
public String toString() {
return value;
}
// TODO warn user that it will return null when the ShadowString is not yet
// sent.
@Override
public String toString() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public boolean equals(Object obj) {
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {
if (super.equals(obj)) {
if (obj instanceof ShadowString) {
if (obj instanceof ShadowString) {
if (value != null && value.equals(((ShadowString) obj).value)) {
return true;
}
}
}
if (value != null && value.equals(((ShadowString) obj).value)) {
return true;
}
}
}
return false;
}
return false;
}
@Override
public int hashCode() {
throw new UnsupportedOperationException("overriden equals, not overriden hashCode");
}
}
......@@ -4,52 +4,58 @@ package ch.usi.dag.dislreserver.shadow;
// over network - throw a runtime exception ??
public class ShadowThread extends ShadowObject {
private String name;
private boolean isDaemon;
private String name;
private boolean isDaemon;
public ShadowThread(long net_ref, String name, boolean isDaemon,
ShadowClass klass) {
super(net_ref, klass);
public ShadowThread(long net_ref, String name, boolean isDaemon,
ShadowClass klass) {
super(net_ref, klass);
this.name = name;
this.isDaemon = isDaemon;
}
this.name = name;
this.isDaemon = isDaemon;
}
// TODO warn user that it will return null when the ShadowThread is not yet sent.
public String getName() {
return name;
}
// TODO warn user that it will return null when the ShadowThread is not yet
// sent.
public String getName() {
return name;
}
// TODO warn user that it will return false when the ShadowThread is not yet sent.
public boolean isDaemon() {
return isDaemon;
}
// TODO warn user that it will return false when the ShadowThread is not yet
// sent.
public boolean isDaemon() {
return isDaemon;
}
public void setName(String name) {
this.name = name;
}
public void setName(String name) {
this.name = name;
}
public void setDaemon(boolean isDaemon) {
this.isDaemon = isDaemon;
}
public void setDaemon(boolean isDaemon) {
this.isDaemon = isDaemon;
}
@Override
public boolean equals(Object obj) {
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {
if (super.equals(obj)) {
if (obj instanceof ShadowThread) {
if (obj instanceof ShadowThread) {
ShadowThread t = (ShadowThread) obj;
ShadowThread t = (ShadowThread) obj;
if (name != null && name.equals(t.name)
&& (isDaemon == t.isDaemon)) {
return true;
}
}
}
if (name != null && name.equals(t.name)
&& (isDaemon == t.isDaemon)) {
return true;
}
}
}
return false;
}
return false;
}
@Override
public int hashCode() {
throw new UnsupportedOperationException("overriden equals, not overriden hashCode");
}
}