sunflow icon indicating copy to clipboard operation
sunflow copied to clipboard

Data races in Geometry.java

Open alx01011 opened this issue 1 year ago • 1 comments

I have created a tool that detect data races in java.

The tool has detected the following races in Geometry.java:

  1. Race between read and write of field builtAccel:
  #0 org.sunflow.core.Geometry.intersect() Geometry.java:93
  #1 org.sunflow.core.Instance.intersect() Instance.java:135
  #2 org.sunflow.core.InstanceList.intersectPrimitive() InstanceList.java:30
  #3 org.sunflow.core.accel.BoundingIntervalHierarchy.intersect() BoundingIntervalHierarchy.java:559
  #4 org.sunflow.core.Scene.trace() Scene.java:199
  #5 org.sunflow.core.LightServer$1.run() LightServer.java:231
  #6 java.lang.Thread.run() Thread.java:844

 Previous write of size 8 at 0x7f2a7ef10038 by thread T16:
  #0 org.sunflow.core.Geometry.build() Geometry.java:119
  #1 org.sunflow.core.Geometry.intersect() Geometry.java:-1
  #2 org.sunflow.core.Instance.intersect() Instance.java:135
  #3 org.sunflow.core.InstanceList.intersectPrimitive() InstanceList.java:30
  #4 org.sunflow.core.accel.BoundingIntervalHierarchy.intersect() BoundingIntervalHierarchy.java:559
  #5 org.sunflow.core.Scene.trace() Scene.java:199
  #6 org.sunflow.core.LightServer$1.run() LightServer.java:231
  #7 java.lang.Thread.run() Thread.java:844```
  1. Race between read and write of field accel:
  Read of size 8 at 0x7f2a7ef10038 by thread T24:
  #0 org.sunflow.core.Geometry.intersect() Geometry.java:93
  #1 org.sunflow.core.Instance.intersect() Instance.java:135
  #2 org.sunflow.core.InstanceList.intersectPrimitive() InstanceList.java:30
  #3 org.sunflow.core.accel.BoundingIntervalHierarchy.intersect() BoundingIntervalHierarchy.java:559
  #4 org.sunflow.core.Scene.trace() Scene.java:199
  #5 org.sunflow.core.LightServer$1.run() LightServer.java:231
  #6 java.lang.Thread.run() Thread.java:844

 Previous write of size 8 at 0x7f2a7ef10038 by thread T16:
  #0 org.sunflow.core.Geometry.build() Geometry.java:119
  #1 org.sunflow.core.Geometry.intersect() Geometry.java:-1
  #2 org.sunflow.core.Instance.intersect() Instance.java:135
  #3 org.sunflow.core.InstanceList.intersectPrimitive() InstanceList.java:30
  #4 org.sunflow.core.accel.BoundingIntervalHierarchy.intersect() BoundingIntervalHierarchy.java:559
  #5 org.sunflow.core.Scene.trace() Scene.java:199
  #6 org.sunflow.core.LightServer$1.run() LightServer.java:231
  #7 java.lang.Thread.run() Thread.java:844

Those have been detected by running the DaCapo Benchmark Suite 23.11-Chopin.

alx01011 avatar Oct 12 '24 23:10 alx01011

I second this. I've been working on a Java Multi-Version Execution and Record Replay tool called JMVX ( public git, paper ) and observed races here too during testing. Additionally I think there is a chance to race on the builtTess field.

builtAccel and builtTess act as flags in part of a double check lock. The race on those fields can be eliminated by making the fields volatile. I imagine the same is true of the accel field, if the problem doesn't go away from fixing builtAccel. My testing was also done with the DaCapo Benchmark suite (version 23.11). Based on the code in master the issue should still be present.

dms061 avatar Nov 26 '24 03:11 dms061