Profile Image

What is JVM startup parameter: -XX:AllocatePrefetchStyle?

What is JVM startup parameter: -XX:AllocatePrefetchStyle? Have you used this JVM arguement before? What are the pros & cons of using this Java argument? Can you share your perspective/experience in using this JVM argument?

  • jvmargument

  • xx-allocateprefetchstyle

  • x-allocateprefetchstyle

  • JVM startup parameter

Please Sign In or to post your comment or answer

Profile Image

Pavel Khodakovsky


 This flag sets the code style for prefetch instructions. Its syntax is the following:

-XX:AllocatePrefetchStyle=value, where value is between 0 and 3




Starting from JDK 6.




This will instruct JVM to use code style 3 (will be discussed in the description):






Before talking about the flag, we need to understand these topics, Java Heap, Allocations, Prefetching, and Thread Local Allocation Buffers (TLABs).


The Java heap is a memory area managed by the garbage collector, so it is also called the "GC heap" in some sources. Before the appearance of the G1 collector, all garbage collectors inside the HotSpot virtual machine were designed based on "classical generation", so the Java heap is divided into "Young generation", "Old or Tenured Generation" and "Permanent Generation.


The Java heap which is shared by all threads can be split up into multiple Thread Local Allocation Buffer (TLAB) to improve the object allocation’s efficiency. Their main purpose is to store instances of objects and subdividing the Java heap is just to reclaim or allocate memory faster.


Usually, objects are allocated on the heap, because the heap is shared by threads, so many threads may apply for space allocation at the same time. If a there is a lock, it will reduce the allocation efficiency. Fortunately, JVM introduced Thread Local Allocation Buffers (TLABs) which is a thread-specific memory allocation area. When using the argument “-XX:UseTLAB”, each thread is initialized with a separate size of memory so that each thread has it’s own space. If you need to allocate memory, you can use it yourself in this way, there is no competition, which can greatly improve the allocation efficiency.


 JVM automatically manages the Heap memory which is very important for the performance of an application. When a program tries to allocate more memory on the Heap than that is freely available (depending on the “Xmx” config) we encounter “OutOfMemoryError”.


JVM manages the heap memory by garbage collection. In simple terms, it frees the memory used by orphan objects, i.e, objects that are no longer referenced from the Stack directly or indirectly (via a reference in another object) to make space for new object creation.


Let us take a close look at this code snippet:


class Student {


    private String firstName;


    private String lastName;


    private Integer score;


    public Student(String firstName, String lastName, Integer score) {


        this.firstName = firstName;


        this.lastName = lastName;


        this.score = score;




    public void setScore(Integer score) {


        this.score = score;






public class Exam {


    private final static int EXAM_BONUS = 5;


    private static Integer calculateExamBonus(Integer score) {


        int finalScore = score + 5;


        return finalScore > 100 ? score : finalScore;




    public static void main(String[] args) {


        Integer score = 90;


        Student student = new Student("John", "Doe", score);








When we initiate a new Student instance, it will create the instance in the heap of the program and the three fields in the constructor will also create an instance of each type in the heap memory as you can see below in the image. But the static fields are not stored in the heap memory but the thread stack.

As we discussed before, the JVM is responsible for the memory management. Therefore, it has control over the instructions and its parameters. JVM can know if a given instruction is accessing to an object, what properties the object have such as type, size and addresses and the position in the memory of the object. Given all these information, the JVM can get a pattern of accessing to the object. This access pattern might be used to predict the next pages of the application consequently prefetch them.


The flag “AllocatePrefetchStyle” was introduced since JDK 6. It allows the JVM to set a generated code style for prefetching instructions. The possible values are between 0 and 3.


  • 0: It will not generate any prefetch instructions
  • 1: It will execute a prefetch instruction after each allocation.
  • 2: It will use TLAB pointer to know when the prefetch instructions are executed.
  • 3: It will use BIS instruction for allocation prefetch on Sparc since it avoids fetching cache line from memory.


Default Value:


The default value is 1.




This flag only supported by Java HotSpot Server VM.




JVM throws an error if the value is outside the range 0 to 3.


Arguments related:


AllocateInstancePrefetchLines, AllocatePrefetchStepSize, AllocatePrefetchDistance, AllocatePrefetchLines, AllocatePrefetchInstr


Related Posts







Got something else on mind? Post Your Question

Not the answer you're looking for? Browse other questions tagged
  • jvmargument

  • xx-allocateprefetchstyle

  • x-allocateprefetchstyle

  • JVM startup parameter