From 3919742f449634d2028dfdf424ac182322302ca4 Mon Sep 17 00:00:00 2001 From: katherine-hough <32645020+katherine-hough@users.noreply.github.com> Date: Wed, 29 Nov 2023 09:37:19 -0500 Subject: [PATCH] * Fixed missing case for putOrderedObject --- .../runtime/mask/SpecialAccessPolicy.java | 41 +++++++++++++++++++ .../runtime/mask/SunUnsafeMasker.java | 35 ++++------------ .../runtime/mask/UnsafeMaskerHelper.java | 5 --- 3 files changed, 50 insertions(+), 31 deletions(-) create mode 100644 Phosphor/src/main/java/edu/columbia/cs/psl/phosphor/runtime/mask/SpecialAccessPolicy.java diff --git a/Phosphor/src/main/java/edu/columbia/cs/psl/phosphor/runtime/mask/SpecialAccessPolicy.java b/Phosphor/src/main/java/edu/columbia/cs/psl/phosphor/runtime/mask/SpecialAccessPolicy.java new file mode 100644 index 000000000..ef1107a28 --- /dev/null +++ b/Phosphor/src/main/java/edu/columbia/cs/psl/phosphor/runtime/mask/SpecialAccessPolicy.java @@ -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); +} diff --git a/Phosphor/src/main/java/edu/columbia/cs/psl/phosphor/runtime/mask/SunUnsafeMasker.java b/Phosphor/src/main/java/edu/columbia/cs/psl/phosphor/runtime/mask/SunUnsafeMasker.java index bd2ef47f0..f7fbbc9e9 100644 --- a/Phosphor/src/main/java/edu/columbia/cs/psl/phosphor/runtime/mask/SunUnsafeMasker.java +++ b/Phosphor/src/main/java/edu/columbia/cs/psl/phosphor/runtime/mask/SunUnsafeMasker.java @@ -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 @@ -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); } } @@ -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); } } } diff --git a/Phosphor/src/main/java/edu/columbia/cs/psl/phosphor/runtime/mask/UnsafeMaskerHelper.java b/Phosphor/src/main/java/edu/columbia/cs/psl/phosphor/runtime/mask/UnsafeMaskerHelper.java index 5449a4574..465fc4a82 100644 --- a/Phosphor/src/main/java/edu/columbia/cs/psl/phosphor/runtime/mask/UnsafeMaskerHelper.java +++ b/Phosphor/src/main/java/edu/columbia/cs/psl/phosphor/runtime/mask/UnsafeMaskerHelper.java @@ -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 - } }