private StatementMap substatements = StatementMap.empty();
private @Nullable D declaredInstance;
private boolean implicitDeclared;
+ private boolean fullyDefined;
// Copy constructor
AbstractResumedStatement(final AbstractResumedStatement<A, D, E> original) {
this.rawArgument = original.rawArgument;
this.substatements = original.substatements;
this.declaredInstance = original.declaredInstance;
+ this.fullyDefined = original.fullyDefined;
}
AbstractResumedStatement(final StatementDefinitionContext<A, D, E> def, final StatementSourceReference ref,
@Override
public final boolean isFullyDefined() {
- return fullyDefined();
+ return fullyDefined;
+ }
+
+ final void setFullyDefined() {
+ fullyDefined = true;
}
@Override
private final QNameModule targetModule;
private final A argument;
+ // Indicates whether or not this statement's substatement file was modified, i.e. it is not quite the same as the
+ // prototype's file.
+ private boolean modified;
+
/**
* Effective substatements, lazily materialized. This field can have four states:
* <ul>
this.prototype = original.prototype;
this.originalCtx = original.originalCtx;
this.argument = original.argument;
+ this.modified = original.modified;
// Substatements are initialized here
this.substatements = ImmutableList.of();
}
// the substatement list, as this operation turned out to not affect them.
final E effective = createInferredEffective(factory);
// Since we have forced instantiation to deal with this case, we also need to reset the 'modified' flag
- setUnmodified();
+ modified = false;
if (sameSubstatements(original.effectiveSubstatements(), effective)) {
LOG.debug("Reusing unchanged substatements of: {}", prototype);
}
private @NonNull E internAlongCopyAxis(final StatementFactory<A, D, E> factory, final @NonNull E stmt) {
- if (!isModified()) {
+ if (!modified) {
final EffectiveStatementState state = factory.extractEffectiveState(stmt);
if (state != null) {
return prototype.unmodifiedEffectiveSource().attachEffectiveCopy(state, stmt);
@Override
ReactorStmtCtx<A, D, E> unmodifiedEffectiveSource() {
- return isModified() ? this : prototype.unmodifiedEffectiveSource();
+ return modified ? this : prototype.unmodifiedEffectiveSource();
}
@Override
final var ret = beforeAddEffectiveStatementUnsafe(ImmutableList.of(), buffer.size());
ret.addAll(buffer);
substatements = ret;
- setModified();
+ modified = true;
prototype.decRef();
return ret;
// resizing operation.
materializedSchemaTree = new HashMap<>(4);
substatements = materializedSchemaTree;
- setModified();
+ modified = true;
} else {
verify(substatements instanceof HashMap, "Unexpected substatements %s", substatements);
materializedSchemaTree = castMaterialized(substatements);
// hence improve memory layout.
private byte flags;
- // Flag for use by AbstractResumedStatement, ReplicaStatementContext and InferredStatementContext. Each of them
- // uses it to indicated a different condition. This is hiding in the alignment shadow created by
- // 'isSupportedToBuildEffective'.
- // FIXME: move this out once we have JDK15+
- private boolean boolFlag;
-
ReactorStmtCtx() {
// Empty on purpose
}
ReactorStmtCtx(final ReactorStmtCtx<A, D, E> original) {
isSupportedToBuildEffective = original.isSupportedToBuildEffective;
- boolFlag = original.boolFlag;
flags = original.flags;
}
// Used by ReplicaStatementContext only
ReactorStmtCtx(final ReactorStmtCtx<A, D, E> original, final Void dummy) {
- boolFlag = isSupportedToBuildEffective = original.isSupportedToBuildEffective;
+ isSupportedToBuildEffective = original.isSupportedToBuildEffective;
flags = original.flags;
}
return false;
}
- // These two exist only due to memory optimization, should live in AbstractResumedStatement.
- final boolean fullyDefined() {
- return boolFlag;
- }
-
- final void setFullyDefined() {
- boolFlag = true;
- }
-
- // This exists only due to memory optimization, should live in ReplicaStatementContext. In this context the flag
- // indicates the need to drop source's reference count when we are being swept.
- final boolean haveSourceReference() {
- return boolFlag;
- }
-
- // These three exist due to memory optimization, should live in InferredStatementContext. In this context the flag
- // indicates whether or not this statement's substatement file was modified, i.e. it is not quite the same as the
- // prototype's file.
- final boolean isModified() {
- return boolFlag;
- }
-
- final void setModified() {
- boolFlag = true;
- }
-
- final void setUnmodified() {
- boolFlag = false;
- }
-
// These two exist only for StatementContextBase. Since we are squeezed for size, with only a single bit available
// in flags, we default to 'false' and only set the flag to true when we are absolutely sure -- and all other cases
// err on the side of caution by taking the time to evaluate each substatement separately.
extends ReactorStmtCtx<A, D, E> {
private final StatementContextBase<?, ?, ?> parent;
private final ReactorStmtCtx<A, D, E> source;
+ // We need to drop source's reference count when we are being swept.
+ private final boolean haveSourceRef;
ReplicaStatementContext(final StatementContextBase<?, ?, ?> parent, final ReactorStmtCtx<A, D, E> source) {
super(source, null);
this.source = requireNonNull(source);
if (source.isSupportedToBuildEffective()) {
source.incRef();
+ haveSourceRef = true;
+ } else {
+ haveSourceRef = false;
}
}
@Override
int sweepSubstatements() {
- if (haveSourceReference()) {
+ if (haveSourceRef) {
source.decRef();
}
return 0;