Commit 3de8e852 authored by Lubomir Bulej's avatar Lubomir Bulej

Added comments and made cosmetic changes to various classes.

parent bebc878f
......@@ -98,6 +98,7 @@ final class ArrayShadowClass extends ShadowClass {
@Override
public ShadowClass getSuperclass () {
// Array types (should) have Object as the super class.
return __superClass;
}
......@@ -110,6 +111,7 @@ final class ArrayShadowClass extends ShadowClass {
@Override
public String [] getInterfaceDescriptors () {
// Array types implement Cloneable and Serializable interfaces.
return new String [] {
Type.getType (Cloneable.class).getDescriptor (),
Type.getType (Serializable.class).getDescriptor ()
......
......@@ -21,7 +21,7 @@ final class NetReferenceHelper {
private static final long CBIT_MASK = (1L << 1) - 1;
/**
* 1-bit special flag at bit 63.
* 1-bit special flag at bit 63 (used internally in the agent).
*/
private static final short SPEC_POS = 63;
private static final long SPEC_MASK = (1L << 1) - 1;
......
......@@ -9,8 +9,7 @@ import org.objectweb.asm.Type;
final class PrimitiveShadowClass extends ShadowClass {
PrimitiveShadowClass (
final long netReference, final Type type,
final ShadowObject classLoader
final long netReference, final Type type, final ShadowObject classLoader
) {
super (netReference, type, classLoader);
}
......@@ -62,18 +61,21 @@ final class PrimitiveShadowClass extends ShadowClass {
*/
@Override
public ShadowClass getSuperclass () {
// Primitive types have no superclass.
return null;
}
@Override
public ShadowClass [] getInterfaces () {
// Primitive types implement no interfaces.
return new ShadowClass [0];
}
@Override
public String [] getInterfaceDescriptors () {
// Primitive types implement no interfaces.
return new String [0];
}
......
......@@ -98,6 +98,13 @@ public abstract class ShadowClass extends ShadowObject {
// Should return null for primitive types or for classes
// loaded by the bootstrap class loader.
//
// TODO LB: Consider exposing a reference for the bootstrap class loader.
//
// This would diverge from the behavior of Java reflection API, but it
// would potentially allow an analysis to attach state to a shadow
// object representing the bootstrap class loader. Not sure if it is
// necessary though.
//
return __classLoader;
}
......@@ -164,10 +171,16 @@ public abstract class ShadowClass extends ShadowObject {
//
public abstract boolean isInstance (ShadowObject obj);
public abstract boolean isInstance (ShadowObject object);
public abstract boolean isAssignableFrom (ShadowClass klass);
/**
* @throws NullPointerException
* if the specified {@link ShadowClass} parameter is {@code null}
*
* @see Class#isAssignableFrom(Class)
*/
public abstract boolean isAssignableFrom (ShadowClass other);
//
......
......@@ -21,6 +21,14 @@ public final class ShadowClassTable {
//
/**
* Represents a bootstrap class loader. In the observed VM, the bootstrap
* class loader loads classes for which the call to
* {@link Class#getClassLoader()} returns {@code null}. Because here we need
* to be able to associate classes with the bootstrap class loader, we need
* a special object to use as a key into a map that returns a map of class
* names to class code.
*/
static final ShadowObject BOOTSTRAP_CLASSLOADER;
static final AtomicReference <ShadowClass> JAVA_LANG_CLASS;
......@@ -131,8 +139,8 @@ public final class ShadowClassTable {
final ShadowClass superClass, ShadowObject classLoader
) {
//
// Assumes that the sort of primitive types is lexicographically
// before the sort of arrays and subsequently objects.
// Assumes that the sorts of primitive types in ASM Type precede the
// sort of array, which itself precedes the sort of object.
//
if (type.getSort () < Type.ARRAY) {
// Primitive type should return null as classloader.
......
......@@ -46,6 +46,11 @@ public class ShadowObject implements Formattable {
return __shadowClass;
} else {
//
// FIXME LB: Consider not exposing the BOOTSTRAP_CLASSLOADER reference to the user.
//
// Then there should be no need for this hackery.
//
if (this.equals (ShadowClassTable.BOOTSTRAP_CLASSLOADER)) {
throw new NullPointerException ();
}
......@@ -166,7 +171,7 @@ public class ShadowObject implements Formattable {
* the {@link ShadowObject} instance to update from.
*/
protected void _updateFrom (final ShadowObject object) {
// do nothing
// By default do nothing.
}
//
......
......@@ -22,7 +22,7 @@ public final class ShadowObjectTable {
//
public static void register (final ShadowObject object) {
static void register (final ShadowObject object) {
if (object == null) {
__log.warn ("attempting to register a null shadow object");
return;
......@@ -62,9 +62,9 @@ public final class ShadowObjectTable {
return null;
}
final ShadowObject retVal = shadowObjects.get (objectId);
if (retVal != null) {
return retVal;
final ShadowObject existing = shadowObjects.get (objectId);
if (existing != null) {
return existing;
}
//
......@@ -116,14 +116,12 @@ public final class ShadowObjectTable {
}
public static void freeShadowObject (final ShadowObject obj) {
shadowObjects.remove (obj.getId ());
ShadowClassTable.freeShadowObject (obj);
public static void freeShadowObject (final ShadowObject object) {
shadowObjects.remove (object.getId ());
ShadowClassTable.freeShadowObject (object);
}
// TODO: find a more elegant way to allow users to traverse the shadow
// object table
//TODO: find a more elegant way to allow users to traverse the shadow object table
public static Iterator <Entry <Long, ShadowObject>> getIterator () {
return shadowObjects.entrySet ().iterator ();
}
......
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