Commit 34ed6ce3 authored by Lubomir Bulej's avatar Lubomir Bulej

NetReferenceHelper: make the class package private.

NetReferenceHelper: make the method names conform to normal Java style.
ShadowClass, ShadowObject, ShadowClassTable, ShadowObjectTable: updated to reflect the changes.
parent 586fad4e
package ch.usi.dag.dislreserver.shadow;
public class NetReferenceHelper {
// ************* special bit mask handling methods **********
// NOTE names of the methods are unusual for reason
// you can find almost identical methods in agent
// should be in sync with net_reference functions on the client
// format of net reference looks like this
// HIGHEST (1 bit spec, 23 bits class id, 40 bits object id)
// bit field not used because there is no guarantee of alignment
final class NetReferenceHelper {
/**
* 40-bit object (instance) identifier starting at bit 0.
*/
private static final short OBJECT_ID_POS = 0;
private static final long OBJECT_ID_MASK = (1L << 40) - 1;
/**
* 22-bit class identifier starting at bit 40.
*/
private static final short CLASS_ID_POS = 40;
private static final long CLASS_ID_MASK = (1L << 22) - 1;
private static final short SPEC_POS = 63;
/**
* 1-bit class instance flag at bit 62.
*/
private static final short CBIT_POS = 62;
private static final long CBIT_MASK = (1L << 1) - 1;
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;
/**
* 1-bit special flag at bit 63.
*/
private static final short SPEC_POS = 63;
private static final long SPEC_MASK = (1L << 1) - 1;
// 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;
//
// mask it
return bits_shifted & bit_mask;
static long getObjectId (final long netReference) {
return __bits (netReference, OBJECT_ID_POS, OBJECT_ID_MASK);
}
public static long get_object_id (long net_ref) {
return get_bits (net_ref, OBJECT_ID_MASK, OBJECT_ID_POS);
static int getClassId (final long netReference) {
return (int) __bits (netReference, CLASS_ID_POS, CLASS_ID_MASK);
}
public static int get_class_id (long net_ref) {
return (int) get_bits (net_ref, CLASS_ID_MASK, CLASS_ID_POS);
static boolean isClassInstance (final long netReference) {
return __bits (netReference, CBIT_POS, CBIT_MASK) != 0;
}
public static short get_spec (long net_ref) {
return (short) get_bits (net_ref, SPEC_MASK, SPEC_POS);
static boolean isSpecial (final long netReference) {
return __bits (netReference, SPEC_POS, SPEC_MASK) != 0;
}
//
public static boolean isClassInstance (long net_ref) {
return get_bits (net_ref, CBIT_MASK, CBIT_POS) != 0;
/**
* Returns bits from the given {@code long} value shifted to the right
* by a given amount and masked using the given mask.
*/
private static long __bits (
final long value, final short shift, final long mask
) {
return (value >> shift) & mask;
}
}
......@@ -22,7 +22,7 @@ public abstract class ShadowClass extends ShadowObject {
// No need to expose the interface to user
// getId() should be sufficient
protected final int getClassId () {
return NetReferenceHelper.get_class_id (getNetRef ());
return NetReferenceHelper.getClassId (getNetRef ());
}
......
......@@ -98,7 +98,7 @@ public class ShadowClassTable {
klass = new PrimitiveShadowClass (net_ref, loader, t);
}
final int classID = NetReferenceHelper.get_class_id (net_ref);
final int classID = NetReferenceHelper.getClassId (net_ref);
final ShadowClass exist = shadowClasses.putIfAbsent (classID, klass);
if (exist == null) {
......@@ -133,7 +133,7 @@ public class ShadowClassTable {
public static void freeShadowObject (final ShadowObject obj) {
if (NetReferenceHelper.isClassInstance (obj.getNetRef ())) {
final int classID = NetReferenceHelper.get_class_id (obj.getNetRef ());
final int classID = NetReferenceHelper.getClassId (obj.getNetRef ());
shadowClasses.remove (classID);
} else if (classLoaderMap.keySet ().contains (obj)) {
......
......@@ -31,7 +31,7 @@ public class ShadowObject implements Formattable {
public final long getId () {
return NetReferenceHelper.get_object_id (__netReference);
return NetReferenceHelper.getObjectId (__netReference);
}
......
......@@ -87,7 +87,7 @@ public class ShadowObjectTable {
public static ShadowObject get (final long net_ref) {
final long objID = NetReferenceHelper.get_object_id (net_ref);
final long objID = NetReferenceHelper.getObjectId (net_ref);
if (objID == 0) {
// reserved ID for null
return null;
......@@ -103,7 +103,7 @@ public class ShadowObjectTable {
} else {
// Only common shadow object will be generated here
final ShadowClass klass = ShadowClassTable.get (NetReferenceHelper.get_class_id (net_ref));
final ShadowClass klass = ShadowClassTable.get (NetReferenceHelper.getClassId (net_ref));
ShadowObject tmp = null;
if ("java.lang.String".equals (klass.getName ())) {
......@@ -153,7 +153,7 @@ public class ShadowObjectTable {
public static void registerShadowThread (
final long netReference, final String name, final boolean isDaemon
) {
final int shadowClassId = NetReferenceHelper.get_class_id (netReference);
final int shadowClassId = NetReferenceHelper.getClassId (netReference);
final ShadowClass shadowClass = ShadowClassTable.get (shadowClassId);
final ShadowThread shadowThread = new ShadowThread (
netReference, shadowClass, name, isDaemon
......@@ -166,7 +166,7 @@ public class ShadowObjectTable {
public static void registerShadowString (
final long netReference, final String value
) {
final int shadowClassId = NetReferenceHelper.get_class_id (netReference);
final int shadowClassId = NetReferenceHelper.getClassId (netReference);
final ShadowClass shadowClass = ShadowClassTable.get (shadowClassId);
final ShadowString shadowString = new ShadowString (
netReference, shadowClass, value
......
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