Skip to content

Commit

Permalink
* Fixed missing case for putOrderedObject
Browse files Browse the repository at this point in the history
  • Loading branch information
katherine-hough committed Nov 29, 2023
1 parent 0a4a422 commit 3919742
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package edu.columbia.cs.psl.phosphor.runtime.mask;

public enum SpecialAccessPolicy {
VOLATILE {
@Override
public void putObject(UnsafeAdapter unsafe, Object o, long offset, Object x) {
unsafe.putObjectVolatile(o, offset, x);
}

@Override
public Object getObject(UnsafeAdapter unsafe, Object o, long offset) {
return unsafe.getObjectVolatile(o, offset);
}
},
ORDERED {
@Override
public void putObject(UnsafeAdapter unsafe, Object o, long offset, Object x) {
unsafe.putOrderedObject(o, offset, x);
}

@Override
public Object getObject(UnsafeAdapter unsafe, Object o, long offset) {
throw new UnsupportedOperationException();
}
},
NONE {
@Override
public void putObject(UnsafeAdapter unsafe, Object o, long offset, Object x) {
unsafe.putObject(o, offset, x);
}

@Override
public Object getObject(UnsafeAdapter unsafe, Object o, long offset) {
return unsafe.getObject(o, offset);
}
};

public abstract void putObject(UnsafeAdapter unsafe, Object o, long offset, Object x);

public abstract Object getObject(UnsafeAdapter unsafe, Object o, long offset);
}
Original file line number Diff line number Diff line change
Expand Up @@ -367,19 +367,6 @@ private static void putTagPrimitive(Object o, long offset, Taint<?> valTaint, Sp
}
}

private static void putObject(Object o, long offset, Object x, SpecialAccessPolicy policy) {
switch (policy) {
case NONE:
ADAPTER.putObject(o, offset, x);
return;
case VOLATILE:
ADAPTER.putObjectVolatile(o, offset, x);
return;
default:
throw new IllegalArgumentException();
}
}

private static Object getObjectPolicy(Object o, long offset, PhosphorStackFrame frame, SpecialAccessPolicy policy) {
if (o instanceof TaggedReferenceArray) {
// Push the taint from the `offset` argument to the `idx` argument for get
Expand All @@ -393,14 +380,7 @@ private static Object getObjectPolicy(Object o, long offset, PhosphorStackFrame
offset = pair.wrappedFieldOffset;
}
getTag(ADAPTER, o, offset, frame, policy);
switch (policy) {
case NONE:
return ADAPTER.getObject(o, offset);
case VOLATILE:
return ADAPTER.getObjectVolatile(o, offset);
default:
throw new IllegalArgumentException();
}
return policy.getObject(ADAPTER, o, offset);
}
}

Expand All @@ -417,16 +397,19 @@ private static void putObject(
}
if (pair != null) {
if (pair.tagFieldOffset != UnsafeProxy.INVALID_FIELD_OFFSET) {
putObject(o, pair.tagFieldOffset, frame.getArgTaint(3), policy);
Object x1 = frame.getArgTaint(3);
policy.putObject(ADAPTER, o, pair.tagFieldOffset, x1);
}
if (pair.wrappedFieldOffset != UnsafeProxy.INVALID_FIELD_OFFSET) {
putObject(o, pair.wrappedFieldOffset, x, policy);
putObject(o, offset, MultiDArrayUtils.unbox1DOrNull(x), policy);
policy.putObject(ADAPTER, o, pair.wrappedFieldOffset, x);
Object x1 = MultiDArrayUtils.unbox1DOrNull(x);
policy.putObject(ADAPTER, o, offset, x1);
} else {
putObject(o, offset, x, policy);
policy.putObject(ADAPTER, o, offset, x);
}
} else {
putObject(o, offset, MultiDArrayUtils.unbox1DOrNull(x), policy);
Object x1 = MultiDArrayUtils.unbox1DOrNull(x);
policy.putObject(ADAPTER, o, offset, x1);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,4 @@ public static int getArrayIndex(UnsafeAdapter unsafe, TaggedArray array, long of
return (int) ((offset - baseOffset) / scale);
}

public enum SpecialAccessPolicy {
VOLATILE,
ORDERED,
NONE
}
}

0 comments on commit 3919742

Please sign in to comment.