Commit bc2aba42 authored by Lubomir Bulej's avatar Lubomir Bulej

Another batch of white-space-only/formatting changes to ease subsequent changes.

parent a9a2b980
......@@ -76,5 +76,5 @@ public class MethodInfo {
public boolean isPublic () {
return (modifiers & Opcodes.ACC_PUBLIC) != 0;
}
}
......@@ -13,20 +13,25 @@ public class NetReferenceHelper {
// bit field not used because there is no guarantee of alignment
private static final short OBJECT_ID_POS = 0;
private static final short CLASS_ID_POS = 40;
private static final short SPEC_POS = 63;
private static final short CBIT_POS = 62;
private static final long OBJECT_ID_MASK = 0xFFFFFFFFFFL;
private static final long CLASS_ID_MASK = 0x3FFFFFL;
private static final long SPEC_MASK = 0x1L;
private static final long CBIT_MASK = 0x1L;
// get bits from "from" with pattern "bit_mask" lowest bit starting on
// position
// "low_start" (from 0)
private static long get_bits(long from, long bit_mask, short low_start) {
// get bits from "from" with pattern "bit_mask"
// lowest bit starting at position "low_start" (from 0)
private static long get_bits (long from, long bit_mask, short low_start) {
// shift it
long bits_shifted = from >> low_start;
......@@ -34,24 +39,24 @@ public class NetReferenceHelper {
return bits_shifted & bit_mask;
}
public static long get_object_id(long net_ref) {
return get_bits(net_ref, OBJECT_ID_MASK, OBJECT_ID_POS);
public static long get_object_id (long net_ref) {
return get_bits (net_ref, OBJECT_ID_MASK, OBJECT_ID_POS);
}
public static int get_class_id(long net_ref) {
return (int) get_bits(net_ref, CLASS_ID_MASK, CLASS_ID_POS);
public static int get_class_id (long net_ref) {
return (int) get_bits (net_ref, CLASS_ID_MASK, CLASS_ID_POS);
}
public static short get_spec(long net_ref) {
return (short) get_bits(net_ref, SPEC_MASK, SPEC_POS);
public static short get_spec (long net_ref) {
return (short) get_bits (net_ref, SPEC_MASK, SPEC_POS);
}
public static boolean isClassInstance(long net_ref) {
return get_bits(net_ref, CBIT_MASK, CBIT_POS) != 0;
public static boolean isClassInstance (long net_ref) {
return get_bits (net_ref, CBIT_MASK, CBIT_POS) != 0;
}
}
......@@ -6,12 +6,16 @@ import org.objectweb.asm.Type;
import ch.usi.dag.dislreserver.DiSLREServerFatalException;
public class ShadowArrayClass extends ShadowClass {
private final Type type;
private final ShadowClass superClass;
private final ShadowClass arrayComponentClass;
//
ShadowArrayClass (
......@@ -28,140 +32,170 @@ public class ShadowArrayClass extends ShadowClass {
@Override
public boolean isArray() {
public boolean isArray () {
return true;
}
public int getArrayDimensions() {
return type.getDimensions();
public int getArrayDimensions () {
return type.getDimensions ();
}
@Override
public ShadowClass getComponentType() {
public ShadowClass getComponentType () {
// return arrayComponentClass;
throw new DiSLREServerFatalException(
"ShadowArrayClass.getComponentType not implemented");
throw new DiSLREServerFatalException ("ShadowArrayClass.getComponentType not implemented");
}
@Override
public boolean isInstance(ShadowObject obj) {
return equals(obj.getShadowClass());
public boolean isInstance (ShadowObject obj) {
return equals (obj.getShadowClass ());
}
@Override
public boolean isAssignableFrom(ShadowClass klass) {
return equals(klass)
|| ((klass instanceof ShadowArrayClass) && arrayComponentClass
.isAssignableFrom(klass.getComponentType()));
public boolean isAssignableFrom (ShadowClass klass) {
return
equals (klass)
||
(
(klass instanceof ShadowArrayClass)
&&
arrayComponentClass.isAssignableFrom (klass.getComponentType ())
);
}
@Override
public boolean isInterface() {
public boolean isInterface () {
return false;
}
@Override
public boolean isPrimitive() {
public boolean isPrimitive () {
return false;
}
@Override
public boolean isAnnotation() {
public boolean isAnnotation () {
return false;
}
@Override
public boolean isSynthetic() {
public boolean isSynthetic () {
return false;
}
@Override
public boolean isEnum() {
public boolean isEnum () {
return false;
}
@Override
public String getName() {
return type.getDescriptor().replace('/', '.');
public String getName () {
return type.getDescriptor ().replace ('/', '.');
}
@Override
public String getCanonicalName() {
return type.getClassName();
public String getCanonicalName () {
return type.getClassName ();
}
@Override
public String[] getInterfaces() {
return new String[] { "java.lang.Cloneable", "java.io.Serializable" };
public String [] getInterfaces () {
return new String [] { "java.lang.Cloneable", "java.io.Serializable" };
}
@Override
public String getPackage() {
public String getPackage () {
return null;
}
@Override
public ShadowClass getSuperclass() {
public ShadowClass getSuperclass () {
return superClass;
}
@Override
public FieldInfo[] getFields() {
return new FieldInfo[0];
public FieldInfo [] getFields () {
return new FieldInfo [0];
}
@Override
public FieldInfo getField(String fieldName) throws NoSuchFieldException {
throw new NoSuchFieldException(type.getClassName() + "." + fieldName);
public FieldInfo getField (String fieldName) throws NoSuchFieldException {
throw new NoSuchFieldException (type.getClassName () + "." + fieldName);
}
@Override
public MethodInfo[] getMethods() {
return getSuperclass().getMethods();
public MethodInfo [] getMethods () {
return getSuperclass ().getMethods ();
}
@Override
public MethodInfo getMethod(String methodName, String[] argumentNames)
throws NoSuchMethodException {
public MethodInfo getMethod (String methodName, String [] argumentNames)
throws NoSuchMethodException {
for (MethodInfo methodInfo : superClass.getMethods()) {
if (methodName.equals(methodInfo.getName())
&& Arrays.equals(argumentNames,
methodInfo.getParameterTypes())) {
for (MethodInfo methodInfo : superClass.getMethods ()) {
if (methodName.equals (methodInfo.getName ())
&& Arrays.equals (argumentNames, methodInfo.getParameterTypes ())
) {
return methodInfo;
}
}
throw new NoSuchMethodException(type.getClassName() + "." + methodName
+ argumentNamesToString(argumentNames));
throw new NoSuchMethodException (
type.getClassName () + "." + methodName + argumentNamesToString (argumentNames)
);
}
@Override
public String[] getDeclaredClasses() {
return new String[0];
public String [] getDeclaredClasses () {
return new String [0];
}
@Override
public FieldInfo[] getDeclaredFields() {
return new FieldInfo[0];
public FieldInfo [] getDeclaredFields () {
return new FieldInfo [0];
}
@Override
public FieldInfo getDeclaredField(String fieldName)
throws NoSuchFieldException {
throw new NoSuchFieldException(type.getClassName() + "." + fieldName);
public FieldInfo getDeclaredField (String fieldName)
throws NoSuchFieldException {
throw new NoSuchFieldException (type.getClassName () + "." + fieldName);
}
@Override
public MethodInfo[] getDeclaredMethods() {
return new MethodInfo[0];
public MethodInfo [] getDeclaredMethods () {
return new MethodInfo [0];
}
@Override
public MethodInfo getDeclaredMethod(String methodName,
String[] argumentNames) throws NoSuchMethodException {
throw new NoSuchMethodException(type.getClassName() + "." + methodName
+ argumentNamesToString(argumentNames));
public MethodInfo getDeclaredMethod (String methodName,
String [] argumentNames)
throws NoSuchMethodException {
throw new NoSuchMethodException (
type.getClassName () + "." + methodName + argumentNamesToString (argumentNames)
);
}
}
......@@ -2,69 +2,92 @@ package ch.usi.dag.dislreserver.shadow;
import java.util.Formatter;
public abstract class ShadowClass extends ShadowObject {
private final int classId;
private final int classId;
private final ShadowObject classLoader;
//
protected ShadowClass(
final long netReference, final ShadowObject classLoader) {
super(netReference, null);
protected ShadowClass (
final long netReference, final ShadowObject classLoader
) {
super (netReference, null);
this.classId = NetReferenceHelper.get_class_id(netReference);
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() {
protected final int getClassId () {
return classId;
}
public final ShadowObject getShadowClassLoader() {
public final ShadowObject getShadowClassLoader () {
return classLoader;
}
public abstract boolean isArray();
public abstract ShadowClass getComponentType();
public abstract boolean isArray ();
public abstract ShadowClass getComponentType ();
public abstract boolean isInstance (ShadowObject obj);
public abstract boolean isAssignableFrom (ShadowClass klass);
public abstract boolean isInterface ();
public abstract boolean isPrimitive ();
public abstract boolean isAnnotation ();
public abstract boolean isSynthetic ();
public abstract boolean isInstance(ShadowObject obj);
public abstract boolean isAssignableFrom(ShadowClass klass);
public abstract boolean isEnum ();
public abstract boolean isInterface();
public abstract boolean isPrimitive();
public abstract String getName ();
public abstract boolean isAnnotation();
public abstract boolean isSynthetic();
public abstract String getCanonicalName ();
public abstract boolean isEnum();
public abstract String getName();
public abstract String [] getInterfaces ();
public abstract String getCanonicalName();
public abstract String[] getInterfaces();
public abstract String getPackage ();
public abstract String getPackage();
public abstract ShadowClass getSuperclass();
public abstract ShadowClass getSuperclass ();
//
@Override
public boolean equals (final Object object) {
if (object instanceof ShadowClass) {
final ShadowClass that = (ShadowClass) object;
if (this.getName ().equals (that.getName ())) {
return this.getShadowClassLoader ().equals (that.getShadowClassLoader ());
return this.getShadowClassLoader ().equals (
that.getShadowClassLoader ()
);
}
}
......@@ -73,85 +96,100 @@ public abstract class ShadowClass extends ShadowObject {
@Override
public int hashCode() {
public int hashCode () {
//
// TODO LB: Check ShadowClass.hashCode() -- it's needed.
//
return super.hashCode ();
}
//
public abstract FieldInfo[] getFields();
public abstract FieldInfo getField(String fieldName)
throws NoSuchFieldException;
public abstract FieldInfo [] getFields ();
public abstract FieldInfo getField (String fieldName)
throws NoSuchFieldException;
public abstract MethodInfo [] getMethods ();
public abstract MethodInfo getMethod (
String methodName, String [] argumentNames
) throws NoSuchMethodException;
public abstract MethodInfo[] getMethods();
public abstract String [] getDeclaredClasses ();
public abstract MethodInfo getMethod(String methodName,
String[] argumentNames) throws NoSuchMethodException;
public abstract String[] getDeclaredClasses();
public abstract FieldInfo [] getDeclaredFields ();
public abstract FieldInfo[] getDeclaredFields();
public abstract FieldInfo getDeclaredField(String fieldName)
throws NoSuchFieldException;
public abstract FieldInfo getDeclaredField (String fieldName)
throws NoSuchFieldException;
public abstract MethodInfo[] getDeclaredMethods();
public abstract MethodInfo getDeclaredMethod(String methodName,
String[] argumentNames) throws NoSuchMethodException;
public abstract MethodInfo [] getDeclaredMethods ();
public MethodInfo getMethod(String methodName, ShadowClass[] arguments)
throws NoSuchMethodException {
return getMethod(methodName, classesToStrings(arguments));
public abstract MethodInfo getDeclaredMethod (
String methodName, String [] argumentNames
) throws NoSuchMethodException;
public MethodInfo getMethod (
String methodName, ShadowClass [] arguments
) throws NoSuchMethodException {
return getMethod (methodName, classesToStrings (arguments));
}
public MethodInfo getDeclaredMethod(String methodName,
ShadowClass[] arguments) throws NoSuchMethodException {
return getDeclaredMethod(methodName, classesToStrings(arguments));
public MethodInfo getDeclaredMethod (
String methodName, ShadowClass [] arguments
) throws NoSuchMethodException {
return getDeclaredMethod (methodName, classesToStrings (arguments));
}
protected static String[] classesToStrings(ShadowClass[] arguments) {
protected static String [] classesToStrings (ShadowClass [] arguments) {
if (arguments == null) {
return new String[0];
return new String [0];
}
int size = arguments.length;
String[] argumentNames = new String[size];
String [] argumentNames = new String [size];
for (int i = 0; i < size; i++) {
argumentNames[i] = arguments[i].getName();
argumentNames [i] = arguments [i].getName ();
}
return argumentNames;
}
protected static String argumentNamesToString(String[] argumentNames) {
StringBuilder buf = new StringBuilder();
buf.append("(");
if (argumentNames != null) {
protected static String argumentNamesToString (String [] argumentNames) {
StringBuilder buf = new StringBuilder ();
buf.append ("(");
if (argumentNames != null) {
for (int i = 0; i < argumentNames.length; i++) {
if (i > 0) {
buf.append(", ");
buf.append (", ");
}
buf.append(argumentNames[i]);
buf.append (argumentNames [i]);
}
}
buf.append(")");
return buf.toString();
buf.append (")");
return buf.toString ();
}
//
@Override
public void formatTo (
final Formatter formatter,
......@@ -160,5 +198,5 @@ public abstract class ShadowClass extends ShadowObject {
// FIXME LB: ShadowClass instances do not have a ShadowClass (of Class)
formatter.format ("java.lang.Class@%d <%s>", getId (), getName ());
}
}
......@@ -6,6 +6,7 @@ import org.objectweb.asm.Type;
import ch.usi.dag.dislreserver.DiSLREServerFatalException;
public class ShadowClassTable {
private static final int INITIAL_TABLE_SIZE = 10000;
......@@ -14,133 +15,129 @@ public class ShadowClassTable {
static ShadowClass JAVA_LANG_CLASS;
private static ConcurrentHashMap<ShadowObject, ConcurrentHashMap<String, byte[]>> classLoaderMap;
private static ConcurrentHashMap<Integer, ShadowClass> shadowClasses;
private static ConcurrentHashMap <ShadowObject, ConcurrentHashMap <String, byte []>> classLoaderMap;
static {
private static ConcurrentHashMap <Integer, ShadowClass> shadowClasses;
BOOTSTRAP_CLASSLOADER = new ShadowObject(0, null);
static {
BOOTSTRAP_CLASSLOADER = new ShadowObject (0, null);
JAVA_LANG_CLASS = null;
classLoaderMap = new ConcurrentHashMap<ShadowObject, ConcurrentHashMap<String, byte[]>>(INITIAL_TABLE_SIZE);
shadowClasses = new ConcurrentHashMap<Integer, ShadowClass>(INITIAL_TABLE_SIZE);
classLoaderMap = new ConcurrentHashMap <ShadowObject, ConcurrentHashMap <String, byte []>> (INITIAL_TABLE_SIZE);
shadowClasses = new ConcurrentHashMap <Integer, ShadowClass> (INITIAL_TABLE_SIZE);
classLoaderMap.put(BOOTSTRAP_CLASSLOADER,
new ConcurrentHashMap<String, byte[]>());
classLoaderMap.put (BOOTSTRAP_CLASSLOADER, new ConcurrentHashMap <String, byte []> ());
}
public static void load(ShadowObject loader, String className,
byte[] classCode, boolean debug) {
ConcurrentHashMap<String, byte[]> classNameMap;
public static void load (
ShadowObject loader, String className, byte [] classCode, boolean debug
) {
ConcurrentHashMap <String, byte []> classNameMap;
if (loader == null) {
// bootstrap loader
loader = BOOTSTRAP_CLASSLOADER;
}
classNameMap = classLoaderMap.get(loader);
classNameMap = classLoaderMap.get (loader);
if (classNameMap == null) {
ConcurrentHashMap<String, byte[]> tmp = new ConcurrentHashMap<String, byte[]>();
if ((classNameMap = classLoaderMap.putIfAbsent(loader, tmp)) == null) {
ConcurrentHashMap <String, byte []> tmp = new ConcurrentHashMap <String, byte []> ();
if ((classNameMap = classLoaderMap.putIfAbsent (loader, tmp)) == null) {
classNameMap = tmp;
}
}
if (classNameMap.putIfAbsent(className.replace('/', '.'), classCode) != null) {
if (classNameMap.putIfAbsent (className.replace ('/', '.'), classCode) != null) {
if (debug) {
System.out.println("DiSL-RE: Reloading/Redefining class "
+ className);
System.out.println ("DiSL-RE: Reloading/Redefining class "+ className);
}
}
}
public static ShadowClass newInstance(long net_ref, ShadowClass superClass,
ShadowObject loader, String classSignature, String classGenericStr,
boolean debug) {
if (!NetReferenceHelper.isClassInstance(net_ref)) {
throw new DiSLREServerFatalException("Unknown class instance");
public static ShadowClass newInstance (
long net_ref, ShadowClass superClass, ShadowObject loader,
String classSignature, String classGenericStr, boolean debug
) {
if (!NetReferenceHelper.isClassInstance (net_ref)) {
throw new DiSLREServerFatalException ("Unknown class instance");
}
ShadowClass klass = null;
Type t = Type.getType(classSignature);
Type t = Type.getType (classSignature);
if (t.getSort() == Type.ARRAY) {
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) {
klass = new ShadowArrayClass (net_ref, loader, superClass, null, t);
ConcurrentHashMap<String, byte[]> classNameMap;
} else if (t.getSort () == Type.OBJECT) {
ConcurrentHashMap <String, byte []> classNameMap;
if (loader == null) {
// bootstrap loader
loader = BOOTSTRAP_CLASSLOADER;
}
classNameMap = classLoaderMap.get(loader);
classNameMap = classLoaderMap.get (loader);
if (classNameMap == null) {
throw new DiSLREServerFatalException("Unknown class loader");
throw new DiSLREServerFatalException ("Unknown class loader");
}
byte[] classCode = classNameMap.get(t.getClassName());
byte [] classCode = classNameMap.get (t.getClassName ());
if (classCode == null) {
throw new DiSLREServerFatalException("Class "
+ t.getClassName() + " has not been loaded");
throw new DiSLREServerFatalException (
"Class "+ t.getClassName () + " has not been loaded"
);
}
klass = new ShadowCommonClass(net_ref, classSignature, loader,
superClass, classCode);
} else {
klass = new ShadowCommonClass (
net_ref, classSignature, loader, superClass, classCode