[jboss-jira] [JBoss JIRA] (DROOLS-9) Exception in User-defined Java method when rules are optimized by the JIT compiler

Andreas Bentele (JIRA) jira-events at lists.jboss.org
Wed Jan 23 08:06:47 EST 2013


    [ https://issues.jboss.org/browse/DROOLS-9?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12749876#comment-12749876 ] 

Andreas Bentele commented on DROOLS-9:
--------------------------------------

I respect your decision, but I want to note that this decision has some implications for rule developers.

* the first point: the Exceptions thrown in my case are because of inconsistencies within the input data. There is no integrity problem, because after such an exception the engine isn't used again
* the second point: I cannot comprehend this. Why must mvel execute all the Java methods to optimize execution?
* the third point: ok. But in a production system such exceptions should never be logged, because they are not relevant (for administrators, service employees ...).

Because of your decision we have to redesign our methods to do no assertions (such as "throw IllegalArgumentException") in the case when they are called within the jitting thread. I have an idea to extend Drools to set a ThreadLocal variable in the jitting Thread to be able to distinguish. To implement this I will implement my own ExecutorProvider instance and register it:
{code}
ServiceRegistryImpl.getInstance().addDefault(ExecutorProvider.class, MyExecutorProviderImpl.class.getName());
{code}
                
> Exception in User-defined Java method when rules are optimized by the JIT compiler 
> -----------------------------------------------------------------------------------
>
>                 Key: DROOLS-9
>                 URL: https://issues.jboss.org/browse/DROOLS-9
>             Project: Drools
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>            Reporter: Andreas Bentele
>            Assignee: Mario Fusco
>         Attachments: DroolsJITTestCase.zip
>
>
> I watched this issue after upgrading from Drools 5.3.1 to Drools 5.5.0.Final.
> I didn't find any trivial example, so I reproduced the error with a non-trivial test case derived from a real-live rule, and attached the test case to this issue. The output is listed in the field "Steps to reproduce":
> What does the application:
> - it calls the rule "DroolsJITTest-Rule" 20 times - 20 is the threshold for jitting. In the output, you can see the line "Service.getAllTimers" 20 times.
> - after that output, a exception during jitting is thrown, because com.sample.Service.getTimePerStroke(Service.java:42) throwed an exception
> - this service is called in the LHS of the rule
> But:
> # in the rule, the following expression evaluates always to false, because service.getLongValue returns always 0
> {code}
> $service.getLongValue(service.workplaceIdForMachineId($machineId, $actionTimestamp), "RC.WORKPLACE_LEADING_OPERATION_ID") > 0
> {code}
> # from this and rule semantics it follows that the next expression should never be evaluated, but the JIT compiler evaluates it:
> {code}
> service.getTimePerStroke($service.getLongValue(service.workplaceIdForMachineId($machineId, $actionTimestamp), "RC.WORKPLACE_LEADING_OPERATION_ID")) > 15
> {code}
> # as we have seen in the bullet no. 1, the parameter of service.getTimePerStroke is 0. In com.sample.Service, Line 41 the parameter value is asserted to be not 0, so an RuntimeException is thrown (Line 42).
> Code of the rule:
> {code}
> rule "DroolsJITTest-Rule"
> when
> 	$service : Service() 
> 	p: PulseEvent(
> 		$actionTimestamp : actionTimestamp,
> 		$eventTimestamp : eventTimestamp
> 	)
>     t: TimerToken(
> 		$machineId : id,
> 		$timestampUTC : timestampUTC,
> 		$service.getLongValue(service.workplaceIdForMachineId($machineId, $actionTimestamp), "RC.WORKPLACE_LEADING_OPERATION_ID") > 0,
> 		service.getTimePerStroke($service.getLongValue(service.workplaceIdForMachineId($machineId, $actionTimestamp), "RC.WORKPLACE_LEADING_OPERATION_ID")) > 15
> 	) from $service.getAllTimers("RC.MACHINE_STROKE_TIMER")
> then
>     System.out.println( "Rule executed" );
>     update(p);
> end
> {code}
> I think, it's a failure that the JIT compiler evaluates the line 
> {code}
> service.getTimePerStroke($service.getLongValue(service.workplaceIdForMachineId($machineId, $actionTimestamp), "RC.WORKPLACE_LEADING_OPERATION_ID")) > 15
> {code}
> because the previous condition expression evaluates to false. Or do you think this behavior works as designed?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the jboss-jira mailing list