Disable JIT in Drools 6.2 with Java 8

2019-05-29 09:18发布

We are working with Drools version 6.2.0.Final for parsing some of our rules. But sometimes when we have a lot of runs, Drools invokes the JIT compiler which is causing failures. We have this covered in our Junit tests and we are getting the following error

java.lang.NoSuchMethodError: org.mvel2.compiler.BlankLiteral.<init>(Ljava/lang/String;)V
at ConditionEvaluatoref4dc802b6174038b0307f5e6196e229.evaluate(Unknown Source)
at org.drools.core.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:248)
at org.drools.core.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:204)
at org.drools.core.reteoo.AlphaNode.assertObject(AlphaNode.java:141)
at org.drools.core.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:494)
at org.drools.core.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:384)
at org.drools.core.reteoo.ObjectTypeNode.propagateAssert(ObjectTypeNode.java:298)
at org.drools.core.phreak.PropagationEntry$Insert.execute(PropagationEntry.java:93)
at org.drools.core.phreak.SynchronizedPropagationList.flush(SynchronizedPropagationList.java:96)
at org.drools.core.phreak.SynchronizedPropagationList.flush(SynchronizedPropagationList.java:69)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.flushPropagations(StatefulKnowledgeSessionImpl.java:1993)
at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1289)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1294)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1281)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1260)
at org.drools.core.impl.StatelessKnowledgeSessionImpl.execute(StatelessKnowledgeSessionImpl.java:306)

We got this error in Java 7 as well but escaped this by using the option

KieBaseConfiguration kbConfig = KieServices.Factory.get().newKieBaseConfiguration();
kbConfig.setOption(PermGenThresholdOption.get(0));

Setting this option disabled JIT and our code was working fine. But since Java 8 has removed the PermGen option altogether, I am not able to figure out an option to achieve the same thing. This is causing the rules to fail when a lot of runs are executed.

I have tried a lot options to disable it but could not make it work.

- OptimizerFactory.setDefaultOptimizer(OptimizerFactory.SAFE_REFLECTIVE);
- System.setProperty("-Ddrools.dialect.java.compiler", "JANINO");
- System.setProperty("-Djava.compiler", "NONE");
- System.setProperty("-Dmvel2.disable.jit", "true");
- kbConfig.setOption(RuleEngineOption.PHREAK);

Some help will be really helpful.

2条回答
Melony?
2楼-- · 2019-05-29 09:46

Well after doing a lot of debugging we found that one of our rule was causing the problem. But the rule was valid and we could not discard it.

Finally I found a way to disable the JIT compiler which solved our problem and the error was gone. This is a different solution from what was mentioned by Esteban Aliverti. The one mentioned below worked for our case and would work for most of the cases.

I used the following way to disable the JIT compiler:

KieBaseConfiguration kbConfig = KieServices.Factory.get().newKieBaseConfiguration();
kbConfig.setOption(ConstraintJittingThresholdOption.get(-1));

The actual explanation is as follows:

0 -> force immediate synchronous jitting (it's adviced to use this only for testing purposes).
-1 (or any other negative number) -> disable jitting
Default value is 20.

So once we set the ConstraintJittingThresholdOption as -1, it disables the JIT compiler.

查看更多
The star\"
3楼-- · 2019-05-29 09:56

The way I found in Drools 6.4 (maybe it also works in 6.2) to disable the JIT compilation of MVEL expressions is to set its threshold to 0. The JIT threshold basically tells Drools how many times an expression has to be evaluated before it gets JIT compiled. A threshold of 0 means 'never JIT compile the expressions'.

The way I found to do this was by using the org.kie.internal.conf.ConstraintJittingThresholdOption KieBaseConfiguration in my KieBases:

KieHelper helper = new KieHelper();
helper.addResource(ResourceFactory.newClassPathResource("rules/jit/jit-sample.drl"));

KieSession ksession = helper.build(ConstraintJittingThresholdOption.get(0)).newKieSession();

I couldn't find a way to do it from the kmodule.xml file though.

I didn't try to use -Ddrools.jittingThreshold=0 either, but I think it should also work.

NOTE: The problem with disabling the JIT compilation of the expressions in Drools is that it affects the entire KieBase. I would suggest you to investigate a little bit further what the exception you are getting is all about.


Edit:

Satyam Roy is right. The propper value to use for ConstraintJittingThresholdOption or -Ddrools.jittingThreshold in order to completely disable the JIT compilation is a negative number and not 0.

Hope it helps,

查看更多
登录 后发表回答