Commit 22d5a20d authored by Yudi Zheng's avatar Yudi Zheng

Remove ASM java/lang/Class representation in the remote VM.

Add equals method for ShadowObject, ShadowString and ShadowThread.
Add hashcode method for ShadowObject
Small fix like wrap the error output with if(debug) and several TODOs reverted.
parent 561c2969
......@@ -23,9 +23,10 @@ public class ClassInfoHandler implements RequestHandler {
String classGenericStr = is.readUTF();
ShadowObject classLoader = ShadowObjectTable.get(is.readLong());
ShadowClass superClass = (ShadowClass) ShadowObjectTable.get(is.readLong());
ShadowClass superClass = (ShadowClass) ShadowObjectTable.get(is
.readLong());
ShadowClassTable.newInstance(net_ref, superClass, classLoader,
classSignature, classGenericStr);
classSignature, classGenericStr, debug);
} catch (IOException e) {
throw new DiSLREServerException(e);
}
......
......@@ -24,7 +24,7 @@ public class NewClassHandler implements RequestHandler {
byte[] classCode = new byte[classCodeLength];
is.readFully(classCode);
ShadowClassTable.load(classLoader, className, classCode);
ShadowClassTable.load(classLoader, className, classCode, debug);
} catch (IOException e) {
throw new DiSLREServerException(e);
}
......
......@@ -23,6 +23,7 @@ public class ObjectFreeHandler implements RequestHandler {
Set<RemoteAnalysis> raSet = AnalysisResolver.getAllAnalyses();
// TODO ! free events should be sent to analysis that sees the shadow object
for (RemoteAnalysis ra : raSet) {
ra.objectFree(obj);
}
......
......@@ -20,7 +20,7 @@ public class StringInfoHandler implements RequestHandler {
String str = is.readUTF();
ShadowString sString = new ShadowString(net_ref, str);
ShadowObjectTable.register(sString);
ShadowObjectTable.register(sString, debug);
} catch (IOException e) {
throw new DiSLREServerException(e);
}
......
......@@ -21,7 +21,7 @@ public class ThreadInfoHandler implements RequestHandler {
boolean isDaemon = is.readBoolean();
ShadowThread sThread = new ShadowThread(net_ref, name, isDaemon);
ShadowObjectTable.register(sThread);
ShadowObjectTable.register(sThread, debug);
} catch (IOException e) {
throw new DiSLREServerException(e);
}
......
package ch.usi.dag.dislreserver.shadow;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Type;
import ch.usi.dag.dislreserver.exception.DiSLREServerFatalException;
......@@ -21,17 +18,7 @@ public class ShadowClassTable {
static {
BOOTSTRAP_CLASSLOADER = new ShadowObject(0, null);
try {
ClassReader cr = new ClassReader("java.lang.Class");
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS
| ClassWriter.COMPUTE_FRAMES);
cr.accept(cw, ClassReader.SKIP_DEBUG | ClassReader.EXPAND_FRAMES);
JAVA_LANG_CLASS = new ShadowCommonClass(0, "Ljava/lang/Class;",
BOOTSTRAP_CLASSLOADER, null, cw.toByteArray());
} catch (IOException e) {
JAVA_LANG_CLASS = null;
}
JAVA_LANG_CLASS = null;
classLoaderMap = new ConcurrentHashMap<ShadowObject, ConcurrentHashMap<String, byte[]>>();
shadowClasses = new ConcurrentHashMap<Integer, ShadowClass>();
......@@ -41,7 +28,7 @@ public class ShadowClassTable {
}
public static void load(ShadowObject loader, String className,
byte[] classCode) {
byte[] classCode, boolean debug) {
ConcurrentHashMap<String, byte[]> classNameMap;
......@@ -62,12 +49,16 @@ public class ShadowClassTable {
}
if (classNameMap.putIfAbsent(className.replace('/', '.'), classCode) != null) {
System.err.println("Reloading/Redefining class " + className);
if (debug) {
System.out.println("DiSL-RE: Reloading/Redefining class "
+ className);
}
}
}
public static ShadowClass newInstance(long net_ref, ShadowClass superClass,
ShadowObject loader, String classSignature, String classGenericStr) {
ShadowObject loader, String classSignature, String classGenericStr,
boolean debug) {
if (!NetReferenceHelper.isClassInstance(net_ref)) {
throw new DiSLREServerFatalException("Unknown class instance");
......@@ -77,6 +68,7 @@ public class ShadowClassTable {
Type t = Type.getType(classSignature);
if (t.getSort() == Type.ARRAY) {
// TODO unknown array component type
klass = new ShadowArrayClass(net_ref, loader, superClass, null, t);
} else if (t.getSort() == Type.OBJECT) {
......@@ -111,11 +103,16 @@ public class ShadowClassTable {
ShadowClass exist = shadowClasses.putIfAbsent(classID, klass);
if (exist == null) {
ShadowObjectTable.register(klass);
ShadowObjectTable.register(klass, debug);
} else if (!exist.equals(klass)) {
throw new DiSLREServerFatalException("Duplicated class ID");
}
if (JAVA_LANG_CLASS == null
&& "Ljava/lang/Class;".equals(classSignature)) {
JAVA_LANG_CLASS = klass;
}
return klass;
}
......
......@@ -33,16 +33,19 @@ public class ShadowObject implements Formattable {
return shadowId;
}
public ShadowClass getShadowClass () {
if (shadowClass != null) {
return shadowClass;
} else {
return ShadowClassTable.JAVA_LANG_CLASS;
}
}
public ShadowClass getShadowClass() {
if (shadowClass != null) {
return shadowClass;
} else {
if (equals(ShadowClassTable.BOOTSTRAP_CLASSLOADER)) {
throw new NullPointerException();
}
return ShadowClassTable.JAVA_LANG_CLASS;
}
}
public synchronized Object getState () {
return shadowState;
......@@ -68,6 +71,24 @@ public class ShadowObject implements Formattable {
return retVal;
}
// only object id considered
// TODO consider also the class ID
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (shadowId ^ (shadowId >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof ShadowObject) {
return shadowId == ((ShadowObject) obj).shadowId;
}
return false;
}
//
......
......@@ -14,7 +14,7 @@ public class ShadowObjectTable {
shadowObjects = new ConcurrentHashMap<Long, ShadowObject>();
}
public static void register(ShadowObject obj) {
public static void register(ShadowObject obj, boolean debug) {
if (obj == null) {
throw new DiSLREServerFatalException(
......@@ -26,7 +26,9 @@ public class ShadowObjectTable {
if (exist != null) {
if (exist.equals(obj)) {
System.err.println("Re-register a shadow object.");
if (debug) {
System.out.println("Re-register a shadow object.");
}
} else {
throw new DiSLREServerFatalException("Duplicated net reference");
}
......
......@@ -14,4 +14,15 @@ public class ShadowString extends ShadowObject {
return value;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof ShadowString) {
return value.equals(((ShadowString) obj).value)
&& super.equals(obj);
}
return false;
}
}
......@@ -20,4 +20,16 @@ public class ShadowThread extends ShadowObject {
return isDaemon;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof ShadowThread) {
ShadowThread t = (ShadowThread) obj;
return name.equals(t.name) && (isDaemon == t.isDaemon)
&& super.equals(obj);
}
return false;
}
}
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