Stm’s for object oriented languages like Java, c#, Scala etc can either be:
- field granular: meaning that each field of an object is managed individually
- object granular: meaning that all fields of an object are managed indivisible
Both approaches have some pro’s and con’s. The advantage of field granularity, is that independent fields of transactional object won’t cause conflicts. If you have a double linkedlist for example, you want the head and tail of the list to be accessed no matter what happens on the other side. This reduces the number of conflicts you get, so improves concurrency.
But having field granularity is not without its problems:
- more expensive transactions: because each field needs to be tracked individually
- more expensive loading; with a field granularity, each fields needs to be loaded individually.
- more expensive conflict detection; since each fields needs to be checked individually
- more expensive commit: each field needs to be locked/updated individually
This means that transactions require more cpu and memory. Another problem is that a transaction that uses field granularity takes longer and this means that it could suffer from more conflicts (causing reduced concurrency) and causing more conflicts (since they acquire locks longer). And last but not least, a field granular transaction puts a lot more pressure on your memory bus since more ‘synchronization’ actions are needed.
In Multiverse (when instrumentation is used), object granularity is the default. And to make field granularity possible, just place a @FieldGranular annotation on top of your field.