Skip to content

Commit

Permalink
Be smarter about memory barrier usage
Browse files Browse the repository at this point in the history
We were being very fine-grained in our use of memory barriers. Some
operations may want to be more choosy about how they use memory
barriers, so we expose functionality to facilitate that.
  • Loading branch information
iamsrp-deshaw committed Nov 5, 2024
1 parent f8454e8 commit be911f2
Show file tree
Hide file tree
Showing 116 changed files with 2,559 additions and 1,650 deletions.
36 changes: 19 additions & 17 deletions java/src/main/java/com/deshaw/hypercube/AbstractHypercube.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,25 @@ public boolean isSingleton()
return (size == 1);
}

/**
* {@inheritDoc}
*/
@Override
public void preRead()
{
final boolean dummy = myBarrier;
if (dummy && !dummy) throw new IllegalStateException();
}

/**
* {@inheritDoc}
*/
@Override
public void postWrite()
{
myBarrier = !myBarrier;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -885,23 +904,6 @@ protected void fromOffset(long offset, final long[] indices)
}
}

/**
* Call before a read to ensure that the memory barrier is flushed.
*/
protected void preRead()
{
final boolean dummy = myBarrier;
if (dummy && !dummy) throw new IllegalStateException();
}

/**
* Call after a write to ensure that the memory barrier is set up.
*/
protected void postWrite()
{
myBarrier = !myBarrier;
}

/**
* The {@link #toString()} helper method. This is designed to create
* something which looks like the {@code numpy} printed version of an array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public Hypercube<T> roll(final Dimension.Roll<?>... rolls)
* {@inheritDoc}
*/
@Override
public T getObjectAt(final long index)
public T weakGetObjectAt(final long index)
throws IndexOutOfBoundsException
{
// Give it back from the parent
Expand All @@ -312,7 +312,7 @@ public T getObjectAt(final long index)
* {@inheritDoc}
*/
@Override
public void setObjectAt(final long index, final T obj)
public void weakSetObjectAt(final long index, final T obj)
throws IndexOutOfBoundsException
{
// Set it in the parent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Boolean1dWrappingHypercube(final boolean[] array)
* the result of {@code false}.
*/
@Override
public boolean get(final long... indices)
public boolean weakGet(final long... indices)
throws IndexOutOfBoundsException
{
if (indices == null) {
Expand Down Expand Up @@ -83,7 +83,7 @@ public boolean get(final long... indices)
* will be silently ignored.
*/
@Override
public void set(final boolean value, final long... indices)
public void weakSet(final boolean value, final long... indices)
throws IndexOutOfBoundsException
{
if (indices == null) {
Expand Down Expand Up @@ -115,7 +115,7 @@ public void set(final boolean value, final long... indices)
* the result of {@code false}.
*/
@Override
public boolean getAt(long index)
public boolean weakGetAt(long index)
throws IndexOutOfBoundsException
{
if (index < 0 || index >= size) {{
Expand All @@ -139,7 +139,7 @@ public boolean getAt(long index)
* will be silently ignored.
*/
@Override
public void setAt(long index, final boolean value)
public void weakSetAt(long index, final boolean value)
throws IndexOutOfBoundsException
{
if (index < 0 || index >= size) {{
Expand All @@ -160,20 +160,20 @@ public void setAt(long index, final boolean value)
* {@inheritDoc}
*/
@Override
public Boolean getObjectAt(final long index)
public Boolean weakGetObjectAt(final long index)
throws IndexOutOfBoundsException
{
return Boolean.valueOf(getAt(index));
return Boolean.valueOf(weakGetAt(index));
}

/**
* {@inheritDoc}
*/
@Override
public void setObjectAt(final long index, final Boolean value)
public void weakSetObjectAt(final long index, final Boolean value)
throws IndexOutOfBoundsException
{
setAt(index, (value == null) ? false : value.booleanValue());
weakSetAt(index, (value == null) ? false : value.booleanValue());
}

/**
Expand All @@ -190,4 +190,4 @@ protected Map<String,Boolean> createFlags()
}
}

// [[[end]]] (checksum: 5abbe4da14634c64655b31c9c07b7b60)
// [[[end]]] (checksum: 6d965717f14b66658e607425d4624e6c)
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Boolean2dWrappingHypercube(final boolean[][] array)
* the result of {@code false}.
*/
@Override
public boolean get(final long... indices)
public boolean weakGet(final long... indices)
throws IndexOutOfBoundsException
{
if (indices == null) {
Expand Down Expand Up @@ -97,7 +97,7 @@ public boolean get(final long... indices)
* will be silently ignored.
*/
@Override
public void set(final boolean value, final long... indices)
public void weakSet(final boolean value, final long... indices)
throws IndexOutOfBoundsException
{
if (indices == null) {
Expand Down Expand Up @@ -140,7 +140,7 @@ public void set(final boolean value, final long... indices)
* the result of {@code false}.
*/
@Override
public boolean getAt(long index)
public boolean weakGetAt(long index)
throws IndexOutOfBoundsException
{
if (index < 0 || index >= size) {{
Expand Down Expand Up @@ -170,7 +170,7 @@ public boolean getAt(long index)
* will be silently ignored.
*/
@Override
public void setAt(long index, final boolean value)
public void weakSetAt(long index, final boolean value)
throws IndexOutOfBoundsException
{
if (index < 0 || index >= size) {{
Expand All @@ -197,20 +197,20 @@ public void setAt(long index, final boolean value)
* {@inheritDoc}
*/
@Override
public Boolean getObjectAt(final long index)
public Boolean weakGetObjectAt(final long index)
throws IndexOutOfBoundsException
{
return Boolean.valueOf(getAt(index));
return Boolean.valueOf(weakGetAt(index));
}

/**
* {@inheritDoc}
*/
@Override
public void setObjectAt(final long index, final Boolean value)
public void weakSetObjectAt(final long index, final Boolean value)
throws IndexOutOfBoundsException
{
setAt(index, (value == null) ? false : value.booleanValue());
weakSetAt(index, (value == null) ? false : value.booleanValue());
}

/**
Expand All @@ -227,4 +227,4 @@ protected Map<String,Boolean> createFlags()
}
}

// [[[end]]] (checksum: c5523934cb14314ab3c7b5120c240d1f)
// [[[end]]] (checksum: 44b8b3157f27d8dd72afe6aafa230aff)
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Boolean3dWrappingHypercube(final boolean[][][] array)
* the result of {@code false}.
*/
@Override
public boolean get(final long... indices)
public boolean weakGet(final long... indices)
throws IndexOutOfBoundsException
{
if (indices == null) {
Expand Down Expand Up @@ -111,7 +111,7 @@ public boolean get(final long... indices)
* will be silently ignored.
*/
@Override
public void set(final boolean value, final long... indices)
public void weakSet(final boolean value, final long... indices)
throws IndexOutOfBoundsException
{
if (indices == null) {
Expand Down Expand Up @@ -165,7 +165,7 @@ public void set(final boolean value, final long... indices)
* the result of {@code false}.
*/
@Override
public boolean getAt(long index)
public boolean weakGetAt(long index)
throws IndexOutOfBoundsException
{
if (index < 0 || index >= size) {{
Expand Down Expand Up @@ -201,7 +201,7 @@ public boolean getAt(long index)
* will be silently ignored.
*/
@Override
public void setAt(long index, final boolean value)
public void weakSetAt(long index, final boolean value)
throws IndexOutOfBoundsException
{
if (index < 0 || index >= size) {{
Expand Down Expand Up @@ -234,20 +234,20 @@ public void setAt(long index, final boolean value)
* {@inheritDoc}
*/
@Override
public Boolean getObjectAt(final long index)
public Boolean weakGetObjectAt(final long index)
throws IndexOutOfBoundsException
{
return Boolean.valueOf(getAt(index));
return Boolean.valueOf(weakGetAt(index));
}

/**
* {@inheritDoc}
*/
@Override
public void setObjectAt(final long index, final Boolean value)
public void weakSetObjectAt(final long index, final Boolean value)
throws IndexOutOfBoundsException
{
setAt(index, (value == null) ? false : value.booleanValue());
weakSetAt(index, (value == null) ? false : value.booleanValue());
}

/**
Expand All @@ -264,4 +264,4 @@ protected Map<String,Boolean> createFlags()
}
}

// [[[end]]] (checksum: b290df49d7096ee12705e48e067b4722)
// [[[end]]] (checksum: e8d7e7de9de3195089585da37cedb91a)
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Boolean4dWrappingHypercube(final boolean[][][][] array)
* the result of {@code false}.
*/
@Override
public boolean get(final long... indices)
public boolean weakGet(final long... indices)
throws IndexOutOfBoundsException
{
if (indices == null) {
Expand Down Expand Up @@ -125,7 +125,7 @@ public boolean get(final long... indices)
* will be silently ignored.
*/
@Override
public void set(final boolean value, final long... indices)
public void weakSet(final boolean value, final long... indices)
throws IndexOutOfBoundsException
{
if (indices == null) {
Expand Down Expand Up @@ -190,7 +190,7 @@ public void set(final boolean value, final long... indices)
* the result of {@code false}.
*/
@Override
public boolean getAt(long index)
public boolean weakGetAt(long index)
throws IndexOutOfBoundsException
{
if (index < 0 || index >= size) {{
Expand Down Expand Up @@ -232,7 +232,7 @@ public boolean getAt(long index)
* will be silently ignored.
*/
@Override
public void setAt(long index, final boolean value)
public void weakSetAt(long index, final boolean value)
throws IndexOutOfBoundsException
{
if (index < 0 || index >= size) {{
Expand Down Expand Up @@ -271,20 +271,20 @@ public void setAt(long index, final boolean value)
* {@inheritDoc}
*/
@Override
public Boolean getObjectAt(final long index)
public Boolean weakGetObjectAt(final long index)
throws IndexOutOfBoundsException
{
return Boolean.valueOf(getAt(index));
return Boolean.valueOf(weakGetAt(index));
}

/**
* {@inheritDoc}
*/
@Override
public void setObjectAt(final long index, final Boolean value)
public void weakSetObjectAt(final long index, final Boolean value)
throws IndexOutOfBoundsException
{
setAt(index, (value == null) ? false : value.booleanValue());
weakSetAt(index, (value == null) ? false : value.booleanValue());
}

/**
Expand All @@ -301,4 +301,4 @@ protected Map<String,Boolean> createFlags()
}
}

// [[[end]]] (checksum: 049693f08167c79a23ef923e013cb799)
// [[[end]]] (checksum: 42a81e5e200aa82e368c4b19227c3b5f)
Loading

0 comments on commit be911f2

Please sign in to comment.