Profile Image

What is JVM startup parameter: -XX:AllocatePrefetchInstr?

What is JVM startup parameter: -XX:AllocatePrefetchInstr? 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-allocateprefetchinstr

  • x-allocateprefetchinstr

  • JVM startup parameter

Please Sign In or to post your comment or answer

Profile Image

Pavel Khodakovsky


 The parameter AllocatePrefetchInstr sets to select instruction to prefetch ahead of the allocation.

-XX:AllocatePrefetchInstr=value, where value it’s between the range of 0 and 3.




Starting from JDK 6.




This will instruct JVM to set the prefetch instruction to 3:






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.


JVM introduced since JDK 6 “AllocatePrefetchInstr”, its main purpose is to set the instruction to prefetch before of the allocation pointer.


Default Value:


By default, the value is 0.




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, AllocatePrefetchDistance, AllocatePrefetchLines, AllocatePrefetchStepSize, AllocatePrefetchStyle


Related Posts:



Got something else on mind? Post Your Question

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

  • xx-allocateprefetchinstr

  • x-allocateprefetchinstr

  • JVM startup parameter