Skip to content

Commit

Permalink
[Java] Support turning on access checks independently of bounds checks.
Browse files Browse the repository at this point in the history
Introduces the system property:

```
sbe.enable.access.order.checks
```
  • Loading branch information
ZachBray committed Jun 21, 2023
1 parent d3f9abc commit aaa73c1
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,12 @@ private static CharSequence generateFieldOrderStates(final FieldOrderModel field
{
final StringBuilder sb = new StringBuilder();

sb.append(" private static final boolean DEBUG_MODE = ")
sb.append(" private static final boolean ENABLE_BOUNDS_CHECKS = ")
.append("!Boolean.getBoolean(\"agrona.disable.bounds.checks\");\n\n");
sb.append(" private static final boolean ENABLE_ACCESS_ORDER_CHECKS = ")
.append("Boolean.parseBoolean(System.getProperty(\n")
.append(" \"sbe.enable.access.order.checks\",\n")
.append(" Boolean.toString(ENABLE_BOUNDS_CHECKS)));\n\n");

sb.append(" /**\n");
sb.append(" * The states in which a encoder/decoder/codec can live.\n");
Expand Down Expand Up @@ -329,7 +333,7 @@ private static CharSequence generateFieldOrderStateTransitions(

final StringBuilder sb = new StringBuilder();

sb.append(indent).append("if (DEBUG_MODE)\n")
sb.append(indent).append("if (ENABLE_ACCESS_ORDER_CHECKS)\n")
.append(indent).append("{\n");

generateFieldOrderStateTransitions(
Expand All @@ -352,7 +356,7 @@ private static CharSequence generateFieldOrderStateTransitions(
{
final StringBuilder sb = new StringBuilder();

sb.append(indent).append("if (DEBUG_MODE)\n")
sb.append(indent).append("if (ENABLE_ACCESS_ORDER_CHECKS)\n")
.append(indent).append("{\n")
.append(indent).append(" final int remaining = ").append(remainingExpression).append(";\n")
.append(indent).append(" if (remaining == 0)\n")
Expand Down Expand Up @@ -432,7 +436,7 @@ private static CharSequence generateFieldOrderStateTransitionsForNextGroupElemen
{
final StringBuilder sb = new StringBuilder();

sb.append(indent).append("if (DEBUG_MODE)\n")
sb.append(indent).append("if (ENABLE_ACCESS_ORDER_CHECKS)\n")
.append(indent).append("{\n")
.append(indent).append(" final int remaining = ").append(remainingExpression).append(";\n")
.append(indent).append(" if (remaining > 1)\n")
Expand Down Expand Up @@ -468,7 +472,7 @@ private static CharSequence generateFieldOrderStateTransitionForDecoderWrap(
final String actingVersion)
{
final StringBuilder sb = new StringBuilder();
sb.append(indent).append("if (DEBUG_MODE)\n")
sb.append(indent).append("if (ENABLE_ACCESS_ORDER_CHECKS)\n")
.append(indent).append("{\n")
.append(indent).append(" switch(" + actingVersion + ")")
.append(indent).append(" {\n");
Expand Down Expand Up @@ -3093,7 +3097,7 @@ private CharSequence generateDecoderFlyweightCode(
" sbeSkip();\n" +
" final int decodedLength = encodedLength();\n" +
" limit(currentLimit);\n\n" +
" if (DEBUG_MODE)\n" +
" if (ENABLE_ACCESS_ORDER_CHECKS)\n" +
" {\n" +
" codecState(currentCodecState);\n" +
" }\n\n" +
Expand Down Expand Up @@ -3221,7 +3225,7 @@ private CharSequence generateEncoderFlyweightCode(
" this.initialOffset = offset;\n" +
" this.offset = offset;\n" +
" limit(offset + BLOCK_LENGTH);\n\n" +
" if (DEBUG_MODE)\n" +
" if (ENABLE_ACCESS_ORDER_CHECKS)\n" +
" {\n" +
" codecState(" + qualifiedStateCase(fieldOrderModel.latestVersionWrappedState()) + ");\n" +
" }\n\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
@SuppressWarnings("all")
public final class FrameCodecDecoder
{
private static final boolean DEBUG_MODE = !Boolean.getBoolean("agrona.disable.bounds.checks");
private static final boolean ENABLE_BOUNDS_CHECKS = !Boolean.getBoolean("agrona.disable.bounds.checks");

private static final boolean ENABLE_ACCESS_ORDER_CHECKS = Boolean.parseBoolean(System.getProperty(
"sbe.enable.access.order.checks",
Boolean.toString(ENABLE_BOUNDS_CHECKS)));

/**
* The states in which a encoder/decoder/codec can live.
Expand Down Expand Up @@ -123,7 +127,7 @@ public FrameCodecDecoder wrap(
this.actingVersion = actingVersion;
limit(offset + actingBlockLength);

if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch(actingVersion) {
case 0:
Expand Down Expand Up @@ -171,7 +175,7 @@ public int sbeDecodedLength()
final int decodedLength = encodedLength();
limit(currentLimit);

if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
codecState(currentCodecState);
}
Expand Down Expand Up @@ -241,7 +245,7 @@ public static int irIdMaxValue()

public int irId()
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
if (codecState() == CodecState.NOT_WRAPPED)
{
Expand Down Expand Up @@ -300,7 +304,7 @@ public static int irVersionMaxValue()

public int irVersion()
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
if (codecState() == CodecState.NOT_WRAPPED)
{
Expand Down Expand Up @@ -359,7 +363,7 @@ public static int schemaVersionMaxValue()

public int schemaVersion()
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
if (codecState() == CodecState.NOT_WRAPPED)
{
Expand Down Expand Up @@ -403,7 +407,7 @@ public static int packageNameHeaderLength()

public int packageNameLength()
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand All @@ -421,7 +425,7 @@ public int packageNameLength()

public int skipPackageName()
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand All @@ -444,7 +448,7 @@ public int skipPackageName()

public int getPackageName(final MutableDirectBuffer dst, final int dstOffset, final int length)
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand All @@ -468,7 +472,7 @@ public int getPackageName(final MutableDirectBuffer dst, final int dstOffset, fi

public int getPackageName(final byte[] dst, final int dstOffset, final int length)
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand All @@ -492,7 +496,7 @@ public int getPackageName(final byte[] dst, final int dstOffset, final int lengt

public void wrapPackageName(final DirectBuffer wrapBuffer)
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand All @@ -513,7 +517,7 @@ public void wrapPackageName(final DirectBuffer wrapBuffer)

public String packageName()
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand Down Expand Up @@ -573,7 +577,7 @@ public static int namespaceNameHeaderLength()

public int namespaceNameLength()
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand All @@ -591,7 +595,7 @@ public int namespaceNameLength()

public int skipNamespaceName()
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand All @@ -614,7 +618,7 @@ public int skipNamespaceName()

public int getNamespaceName(final MutableDirectBuffer dst, final int dstOffset, final int length)
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand All @@ -638,7 +642,7 @@ public int getNamespaceName(final MutableDirectBuffer dst, final int dstOffset,

public int getNamespaceName(final byte[] dst, final int dstOffset, final int length)
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand All @@ -662,7 +666,7 @@ public int getNamespaceName(final byte[] dst, final int dstOffset, final int len

public void wrapNamespaceName(final DirectBuffer wrapBuffer)
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand All @@ -683,7 +687,7 @@ public void wrapNamespaceName(final DirectBuffer wrapBuffer)

public String namespaceName()
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand Down Expand Up @@ -743,7 +747,7 @@ public static int semanticVersionHeaderLength()

public int semanticVersionLength()
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand All @@ -761,7 +765,7 @@ public int semanticVersionLength()

public int skipSemanticVersion()
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand All @@ -784,7 +788,7 @@ public int skipSemanticVersion()

public int getSemanticVersion(final MutableDirectBuffer dst, final int dstOffset, final int length)
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand All @@ -808,7 +812,7 @@ public int getSemanticVersion(final MutableDirectBuffer dst, final int dstOffset

public int getSemanticVersion(final byte[] dst, final int dstOffset, final int length)
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand All @@ -832,7 +836,7 @@ public int getSemanticVersion(final byte[] dst, final int dstOffset, final int l

public void wrapSemanticVersion(final DirectBuffer wrapBuffer)
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand All @@ -853,7 +857,7 @@ public void wrapSemanticVersion(final DirectBuffer wrapBuffer)

public String semanticVersion()
{
if (DEBUG_MODE)
if (ENABLE_ACCESS_ORDER_CHECKS)
{
switch (codecState())
{
Expand Down
Loading

0 comments on commit aaa73c1

Please sign in to comment.