Skip to content

Obey the Contented annotation of Java 8 #29

@Neiko2002

Description

@Neiko2002

If we support volatile fields and programmers want to avoid False Sharing between cores, they should be able to add the sun.misc.Contented annotation to the get/set methods.

public interface Foo {
    @Contented
    @Volatile
    public int getNumber();

    @Contented
    @Volatile
    public int getValue();
}

The underlying data of those methods should be seperated from each other by at least one cache line size (2x would be better). The line size can be gathered from the system:

  • Win: wmic cpu list full
  • OSX: sysctl machdep.cpu.cache.linesize
  • Linux: getconf LEVEL1_DCACHE_LINESIZE

Read up
https://blog.logentries.com/2016/03/a-point-of-contention-cache-coherence-on-the-jvm/
https://shipilev.net/talks/jvmls-July2013-contended.pdf
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/sun/misc/Contended.java

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions