Commit 9fbd5ab1 authored by Lukáš Marek's avatar Lukáš Marek

Fixed reflective info

Analysis handler now supports ClassInfo as analysis method parameter + test
parent 48c4b510
......@@ -18,7 +18,7 @@ export RE_SERVER_FILE
if [ -e ${SERVER_FILE} ]
then
kill -KILL `cat ${SERVER_FILE}`
rm .server.pid
rm ${SERVER_FILE}
fi
# kill running server
......@@ -54,6 +54,6 @@ sleep 1
# kill server
kill -KILL `cat ${SERVER_FILE}` 2> /dev/null
rm .server.pid
rm ${SERVER_FILE}
kill -KILL `cat ${RE_SERVER_FILE}` 2> /dev/null
rm ${RE_SERVER_FILE}
......@@ -10,6 +10,8 @@ import java.util.List;
import ch.usi.dag.dislreserver.exception.DiSLREServerException;
import ch.usi.dag.dislreserver.msg.analyze.AnalysisResolver.AnalysisMethodHolder;
import ch.usi.dag.dislreserver.netreference.NetReference;
import ch.usi.dag.dislreserver.reflectiveinfo.ClassInfo;
import ch.usi.dag.dislreserver.reflectiveinfo.ClassInfoResolver;
import ch.usi.dag.dislreserver.reflectiveinfo.InvalidClass;
import ch.usi.dag.dislreserver.reqdispatch.RequestHandler;
import ch.usi.dag.dislreserver.stringcache.StringCache;
......@@ -150,6 +152,11 @@ public class AnalysisHandler implements RequestHandler {
return new NetReference(is.readLong());
}
// return ClassInfo object
if(argClass.equals(ClassInfo.class)) {
return ClassInfoResolver.getClass(is.readInt());
}
// return "invalid" class object
if(argClass.equals(Class.class)) {
return InvalidClass.class;
......
......@@ -20,8 +20,6 @@ import ch.usi.dag.dislreserver.netreference.NetReference;
*/
public class CommonClassInfo extends AbstractClassInfo {
// TODO ! is this implementation of methods really working ??
private ClassNode classNode;
CommonClassInfo(int classId, String classSignature, String classGenericStr,
......@@ -66,85 +64,79 @@ public class CommonClassInfo extends AbstractClassInfo {
access = classNode.access;
name = classNode.name.replace('/', '.');
methods = new ArrayList<MethodInfo>(classNode.methods.size());
public_methods = new LinkedList<MethodInfo>();
List<MethodInfo> methodsLst = new ArrayList<MethodInfo>(classNode.methods.size());
List<MethodInfo> publicMethodsLst = new LinkedList<MethodInfo>();
for (MethodNode methodNode : classNode.methods) {
MethodInfo methodInfo = new CommonMethodInfo(methodNode);
methods.add(methodInfo);
methodsLst.add(methodInfo);
if (methodInfo.isPublic()) {
public_methods.add(methodInfo);
publicMethodsLst.add(methodInfo);
}
}
fields = new ArrayList<FieldInfo>(classNode.fields.size());
public_fields = new LinkedList<FieldInfo>();
List<FieldInfo> fieldsLst = new ArrayList<FieldInfo>(classNode.fields.size());
List<FieldInfo> publicFieldsLst = new LinkedList<FieldInfo>();
for (FieldNode fieldNode : classNode.fields) {
FieldInfo fieldInfo = new CommonFieldInfo(fieldNode);
fields.add(fieldInfo);
fieldsLst.add(fieldInfo);
if (fieldInfo.isPublic()) {
public_fields.add(fieldInfo);
publicFieldsLst.add(fieldInfo);
}
}
if (getSuperclass() != null) {
for (MethodInfo methodInfo : getSuperclass().getMethods()) {
public_methods.add(methodInfo);
publicMethodsLst.add(methodInfo);
}
for (FieldInfo fieldInfo : getSuperclass().getFields()) {
public_fields.add(fieldInfo);
publicFieldsLst.add(fieldInfo);
}
}
interfaces = new ArrayList<String>(classNode.interfaces);
innerclasses = new ArrayList<String>(classNode.innerClasses.size());
List<String> innerClassesLst = new ArrayList<String>(classNode.innerClasses.size());
for (InnerClassNode innerClassNode : classNode.innerClasses) {
innerclasses.add(innerClassNode.name);
innerClassesLst.add(innerClassNode.name);
}
// to have "checked" array :(
methods = methodsLst.toArray(new MethodInfo[0]);
publicMethods = publicMethodsLst.toArray(new MethodInfo[0]);
fields = fieldsLst.toArray(new FieldInfo[0]);
publicFields = publicFieldsLst.toArray(new FieldInfo[0]);
interfaces = classNode.interfaces.toArray(new String[0]);
innerClasses = innerClassesLst.toArray(new String[0]);
}
private int access;
private String name;
private List<MethodInfo> methods;
private List<MethodInfo> public_methods;
private List<FieldInfo> fields;
private List<FieldInfo> public_fields;
private List<String> interfaces;
private List<String> innerclasses;
private MethodInfo[] methods;
private MethodInfo[] publicMethods;
private FieldInfo[] fields;
private FieldInfo[] publicFields;
private String[] interfaces;
private String[] innerClasses;
// All these methods should return the value of fields initialized by
// generateClassInfo(byte[])
// NOTE: returned arrays should be copies (obtained using
// Arrays.copyOf(...))
public boolean isInstance(NetReference nr) {
// ClassInfo current = ClassInfoResolver.getClass(nr.getClassId());
//
// while (current != null) {
//
// if (this == current) {
// return true;
// }
//
// current = current.getSuperclass();
// }
// TODO isInstance
// TODO Auto-generated method stub
throw new DiSLREServerFatalException("Not implemented");
}
public boolean isAssignableFrom(ClassInfo ci) {
// TODO isAssignableFrom
// TODO Auto-generated method stub
throw new DiSLREServerFatalException("Not implemented");
}
......@@ -173,18 +165,17 @@ public class CommonClassInfo extends AbstractClassInfo {
}
public String getCanonicalName() {
// TODO getCanonicalName
// TODO Auto-generated method stub
throw new DiSLREServerFatalException("Not implemented");
}
public String[] getInterfaces() {
// to have "checked" array :(
return interfaces.toArray(new String[0]);
return Arrays.copyOf(interfaces, interfaces.length);
}
public String getPackage() {
int i = name.lastIndexOf('.');
if (i != -1) {
......@@ -196,8 +187,7 @@ public class CommonClassInfo extends AbstractClassInfo {
public FieldInfo[] getFields() {
// to have "checked" array :(
return public_fields.toArray(new FieldInfo[0]);
return Arrays.copyOf(publicFields, publicFields.length);
}
public FieldInfo getField(String fieldName) throws NoSuchFieldException {
......@@ -217,8 +207,7 @@ public class CommonClassInfo extends AbstractClassInfo {
public MethodInfo[] getMethods() {
// to have "checked" array :(
return public_methods.toArray(new MethodInfo[0]);
return Arrays.copyOf(publicMethods, publicMethods.length);
}
public MethodInfo getMethod(String methodName, ClassInfo[] argumentCIs)
......@@ -247,11 +236,13 @@ public class CommonClassInfo extends AbstractClassInfo {
}
public String[] getDeclaredClasses() {
return (String[]) innerclasses.toArray();
return Arrays.copyOf(innerClasses, innerClasses.length);
}
public FieldInfo[] getDeclaredFields() {
return (FieldInfo[]) fields.toArray();
return Arrays.copyOf(fields, fields.length);
}
public FieldInfo getDeclaredField(String fieldName)
......@@ -267,7 +258,8 @@ public class CommonClassInfo extends AbstractClassInfo {
}
public MethodInfo[] getDeclaredMethods() {
return (MethodInfo[]) methods.toArray();
return Arrays.copyOf(methods, methods.length);
}
public MethodInfo getDeclaredMethod(String methodName,
......@@ -292,21 +284,25 @@ public class CommonClassInfo extends AbstractClassInfo {
private static String[] classesToStrings(ClassInfo[] argumentCIs) {
if (argumentCIs == null) {
return new String[0];
}
int size = argumentCIs.length;
String[] argumentNames = new String[size];
for (int i = 0; i < size; i++) {
argumentNames[i] = argumentCIs[i].getName();
}
throw new DiSLREServerFatalException("Not implemented");
return argumentNames;
// TODO it should return the same as methodInfo.getParameterTypes()
// if (argumentCIs == null) {
// return new String[0];
// }
//
// int size = argumentCIs.length;
// String[] argumentNames = new String[size];
//
// for (int i = 0; i < size; i++) {
// argumentNames[i] = argumentCIs[i].getName();
// }
//
// return argumentNames;
}
private static String argumentNamesToString(String[] argumentNames) {
StringBuilder buf = new StringBuilder();
buf.append("(");
......
......@@ -3,10 +3,10 @@ package ch.usi.dag.dislreserver.reflectiveinfo;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.FieldNode;
import ch.usi.dag.dislreserver.exception.DiSLREServerFatalException;
public class CommonFieldInfo implements FieldInfo {
// TODO ! is this implementation of methods really working ??
private FieldNode fieldNode;
private int modifiers;
private String name;
......@@ -29,7 +29,8 @@ public class CommonFieldInfo implements FieldInfo {
}
public int getModifiers() {
return modifiers;
// TODO Auto-generated method stub
throw new DiSLREServerFatalException("Not implemented");
}
public String getType() {
......
......@@ -6,10 +6,10 @@ import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.MethodNode;
import ch.usi.dag.dislreserver.exception.DiSLREServerFatalException;
public class CommonMethodInfo implements MethodInfo {
// TODO ! is this implementation of methods really working ??
private MethodNode methodNode;
private int modifiers;
private String name;
......@@ -22,8 +22,7 @@ public class CommonMethodInfo implements MethodInfo {
this.methodNode = methodNode;
name = methodNode.name;
modifiers = methodNode.access;
returnType = methodNode.desc
.substring(methodNode.desc.indexOf(')') + 1);
returnType = Type.getReturnType(methodNode.desc).getDescriptor();
Type[] parameters = Type.getArgumentTypes(methodNode.desc);
int size = parameters.length;
......@@ -47,7 +46,8 @@ public class CommonMethodInfo implements MethodInfo {
}
public int getModifiers() {
return modifiers;
// TODO Auto-generated method stub
throw new DiSLREServerFatalException("Not implemented");
}
public String getReturnType() {
......
......@@ -86,15 +86,15 @@ public class CodeExecuted extends RemoteAnalysis {
System.out.println("gen: " + ci.getGenericStr());
}
public static void testingAdvanced2(Object o1, Object o2, Object o3,
public static void testingAdvanced2(Object o1, NetReference o2, Object o3,
Object o4, Class<?> class1, int cid1, Class<?> class2, int cid2,
Class<?> class3, int cid3, Class<?> class4, int cid4) {
Class<?> class3, int cid3, ClassInfo class4) {
System.out.println("* o1 class *");
printClassInfo(((NetReference)o1).getClassInfo());
System.out.println("* o2 class *");
printClassInfo(((NetReference)o2).getClassInfo());
printClassInfo(o2.getClassInfo());
System.out.println("* o3 class *");
printClassInfo(((NetReference)o3).getClassInfo());
......@@ -112,7 +112,7 @@ public class CodeExecuted extends RemoteAnalysis {
printClassInfo(ClassInfoResolver.getClass(cid3));
System.out.println("* class 4 *");
printClassInfo(ClassInfoResolver.getClass(cid4));
printClassInfo(class4);
}
public void atExit() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment