Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DROOLS-7528] Avoid casting to unnecessary interfaces (Fix the secondary super cache problem in Drools) #5451

Merged
merged 4 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ private static int updateRiaAndTerminalMemory( LeftTupleSource lt,
}

} else if (NodeTypeEnums.isTerminalNode(sink)) {
pmem = (PathMemory) reteEvaluator.getNodeMemory((MemoryFactory) sink);
pmem = reteEvaluator.getNodeMemory((AbstractTerminalNode) sink);
}

if (pmem != null && smem.getPos() < pmem.getSegmentMemories().length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.drools.core.common.ReteEvaluator;
import org.drools.core.common.TupleSets;
import org.drools.core.common.TupleSetsImpl;
import org.drools.core.reteoo.AbstractTerminalNode;
import org.drools.core.reteoo.AccumulateNode;
import org.drools.core.reteoo.AccumulateNode.AccumulateMemory;
import org.drools.core.reteoo.AsyncReceiveNode;
Expand Down Expand Up @@ -327,7 +328,7 @@ public void innerEval(PathMemory pmem,
boolean terminalNode = true;
switch (node.getType()) {
case NodeTypeEnums.RuleTerminalNode:
pRtNode.doNode(( TerminalNode ) node, activationsManager, srcTuples, executor);
pRtNode.doNode((AbstractTerminalNode) node, activationsManager, srcTuples, executor);
break;
case NodeTypeEnums.QueryTerminalNode:
pQtNode.doNode((QueryTerminalNode) node, activationsManager, srcTuples, stack);
Expand Down
14 changes: 13 additions & 1 deletion drools-core/src/main/java/org/drools/core/reteoo/LeftTuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,20 @@ public int getIndex() {
}

@Override
// It's better to always cast to a concrete or abstract class to avoid
// secondary super cache problem. See https://issues.redhat.com/browse/DROOLS-7521
public LeftTupleSink getTupleSink() {
return (LeftTupleSink)getSink();
lucamolteni marked this conversation as resolved.
Show resolved Hide resolved
Object sink = getSink();
if (sink instanceof AccumulateNode) {
return (AccumulateNode) sink;
} else if (sink instanceof RuleTerminalNode) {
return (RuleTerminalNode) sink;
} else if (sink instanceof RightInputAdapterNode) {
return (RightInputAdapterNode) sink;
} else if (sink instanceof ExistsNode) {
return (ExistsNode) sink;
}
return (LeftTupleSink)sink;
}

/* Had to add the set method because sink adapters must override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public RuleAgendaItem getOrCreateRuleAgendaItem(ActivationsManager activationsMa
}

private TerminalNode ensureAgendaItemCreated(ActivationsManager activationsManager) {
TerminalNode rtn = (TerminalNode) getPathEndNode();
AbstractTerminalNode rtn = (AbstractTerminalNode) getPathEndNode();
if (agendaItem == null) {
int salience = rtn.getRule().getSalience().isDynamic() ? 0 : rtn.getRule().getSalience().getValue();
agendaItem = activationsManager.createRuleAgendaItem(salience, this, rtn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,15 @@ public RightTupleImpl(InternalFactHandle handle,
handle.addLastRightTuple( this );
}

// It's better to always cast to a concrete or abstract class to avoid
// secondary super cache problem. See https://issues.redhat.com/browse/DROOLS-7521
public RightTupleSink getTupleSink() {
return (RightTupleSink) getSink();
Object sink = getSink();
if(sink instanceof BetaNode) {
return (BetaNode)sink;
} else {
return (RightTupleSink) sink;
}
}

public void reAdd() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void setActivationNode(final ActivationNode activationNode) {
}

public TerminalNode getTerminalNode() {
return (TerminalNode) getTupleSink();
return (AbstractTerminalNode) getTupleSink();
}

public List<FactHandle> getFactHandles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,19 @@ public BaseNode getMatchingNode(BaseNode candidate) {
public LeftTupleSink[] getSinks() {
return sinkArray;
}


// See LeftTuple.getTupleSink() or https://issues.redhat.com/browse/DROOLS-7521
public LeftTupleSinkNode getFirstLeftTupleSink() {
return ( LeftTupleSinkNode ) sink;
lucamolteni marked this conversation as resolved.
Show resolved Hide resolved
if (sink instanceof AccumulateNode) {
return (AccumulateNode) sink;
} else if (sink instanceof RuleTerminalNode) {
return (RuleTerminalNode) sink;
} else if (sink instanceof RightInputAdapterNode) {
return (RightInputAdapterNode) sink;
} else if (sink instanceof ExistsNode) {
return (ExistsNode) sink;
}
return (LeftTupleSinkNode) sink;
}

public LeftTupleSinkNode getLastLeftTupleSink() {
Expand Down
Loading