Modify

Opened 8 years ago

Closed 8 years ago

#12272 closed defect (fixed)

[Patch] Fix access to the AbstractPrimitive#keys

Reported by: michael2402 Owned by: team
Priority: normal Milestone: 16.01
Component: Core Version:
Keywords: Cc:

Description

The keys array is synchronized using RCU.

This patch enforced this pattern. I also rewrote the comment to make people google about RCU instead of explaining everything from scratch.

We need to declare the keys array volatile, see http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.1.4

We can skip the array duplication on key changes if we rewrite the keys reference after the change or if we use an AtomicReferenceArray.

Attachments (1)

patch-fix-keys-synchronisation.patch (14.2 KB ) - added by michael2402 8 years ago.

Download all attachments as: .zip

Change History (5)

in reply to:  description ; comment:1 by simon04, 8 years ago

Replying to michael2402:

I also rewrote the comment to make people google about RCU instead of explaining everything from scratch.

A link to a page explaining RCU would be nice in the Javadoc. :)

We need to declare the keys array volatile, see http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.1.4

How is performance affected by the added volatile keyword, e.g., when reading a huge OSM file?

Checkstyle enforces line lenghts ⩽145 (source:trunk/tools/checkstyle/josm_checks.xml), would you please adapt your patch also in this respect.

in reply to:  1 comment:2 by michael2402, 8 years ago

Replying to simon04:

Replying to michael2402:

I also rewrote the comment to make people google about RCU instead of explaining everything from scratch.

A link to a page explaining RCU would be nice in the Javadoc. :)

Good Idea. I'll search one.

We need to declare the keys array volatile, see http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.1.4

How is performance affected by the added volatile keyword, e.g., when reading a huge OSM file?

Performance should not differ much - volatile simply enforces the memory to be really written once. So for the cases where the compiler behaved like it was intended by the old code there should not be any difference. It simply prevents the compiler from doing some optimisations that would break our synchronisation (e.g. move the newKeys[keyIndex] = key after the keys = newKeys line)

by michael2402, 8 years ago

comment:3 by simon04, 8 years ago

Milestone: 16.01

Concerning performance: I verified this by measuring the time to read a country extract using OsmReader – no notable difference.

And I'll fix (the|my) implementation of OsmPrimitive#hasSameInterestingTags ;)

comment:4 by simon04, 8 years ago

Resolution: fixed
Status: newclosed

In 9267/josm:

fix #12272 - Fix access to the AbstractPrimitive#keys (patch by michael2402)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.