Avoid Cache Misses in Java

For the time being, I will switch my state of mind to developing cache-friendly applications.
In C ++ im, using the distribution of the stack where I can, and I hold the data for the same purpose in the same array (Data Driven Programming) etc .... But it is also Java-developer, and the question arises:
I I heard that Java is a "skipped cache generator".
All that is on the heap, and scattered throughout the RAM after allocation or garbage collector. I think the same problem with C #.
Would it make sense to write Java in Data Driven?
Is there a way to optimize Java code, or are we stuck with automatic Java optimization and skipping cache?

+4
source share
4 answers

In C ++ im, using the stack distribution where I can, I also keep the data for the same purpose in a single array (Data Driven Programming), etc.

In Java, it will automatically push short live objects onto the stack using Escape Analysis. I would not worry about this if you do not see in the profiler that this is a problem. Even then, it may happen that the profiler does not allow escape analysis to work, and this is not a problem in a real program.

I heard that Java is a "skipped cache generator".

Java has much more links than C ++ or C # code that was written to use structures or objects embedded within objects. What difference does it depend on how sensitive your application is to micro-settings.

, , . , #.

Java ( #) . , . ,

class A { }

class B {
    A a = new A();
}

B, A , . Java Eden, . . , 99.9% A B, , . " " Java . .. , .

GC?

JVM OpenJDK/Oracle . .. A B .

Java Data Driven?

, < 1% . , , , .

Java, Java ?

Unsafe . (Chronicle Software) , , , , , 99% . .

. , , -. .

, GC. , , , , , . - , , , . " ", .

+5

Java, . , , , . , FORTRAN . , , ...

#, , . struct , #, List<T> T .

+3

- , , . , Java-.

... , , " " ( ): flyweight pattern.

, , , , , OO .

, . , , .

+2

, , sun.misc.Unsafe, .

Java . :

  • ( , sun.misc.Contended)

, " ", .

ArrayList LinkedList, HashMap TreeMap, .

, , ( ).

, . , , .

, ( JMH) .

0

All Articles