One of the best known advantages of Java technology is that, unlike other languages such as C programmers, Java programmers do not have to be responsible for daunting memory allocations and releases. The Java runtime can manage these tasks for you. Each instantiated object automatically allocates memory in the heap, and the garbage collector periodically reclaims the memory occupied by objects that are no longer in use. But you're not completely out of it. You still need to monitor the memory usage of your program, because the Java process's memory includes more than just the objects that are allocated in the heap. It also includes the program's bytecode (the JVM interprets execution instructions at run time), JIT code (code that has been compiled for the target processor), any native code, and some metadata (exception table, row number table, and so on) used by the JVM. More complicated, some types of memory, such as native libraries, can be shared between processes, so determining the memory footprint of a Java application can be a daunting task.
There are plenty of tools for monitoring memory usage in Windows, but unfortunately no one can provide all the information you need. To make things worse, these various tools do not even have a common vocabulary. But this article will help you by introducing some of the most useful tools available for free, and providing tips on how to use them.
Windows Memory: A whirlwind trip
Before you understand the tools that are discussed in this article, you need to have a basic understanding of how Windows is managed. Windows uses a paging request virtual memory system, and now we're going to analyze the system.
Virtual address space
The concept of virtual memory was proposed in the 50 's, and was proposed as a solution to the complex problem of the process of not loading the actual memory at once. In virtual memory systems, programs can access a larger set of addresses that exceed available physical memory, and the dedicated memory management program maps These logical addresses to the actual addresses and uses temporary storage on the disk to save the excess.
In modern virtual memory implementations used by Windows, virtual storage is organized into units of the same size, called pages. Each operating system process consumes its own virtual address space, a set of virtual memory pages that can be read and written. There are three states of each page:
Freedom: No process has yet used this part of the address space. If you attempt to access this part of the space, both read and write will cause some run-time failure. This action will cause a Windows dialog box to pop up, prompting an access violation. (Java programs do not cause this error, and only programs written in a language that supports pointers can cause this problem.) )
Reserved: This part of the address space is reserved for future use, but cannot be accessed until it is delivered. Many Java heaps are in a reserved state at first.
Commit: The memory that the program can access is fully supported, which means that the page frame has been allocated in the paging file. The submitted page is loaded into main memory only the first time it is referenced, so it becomes a request paging.
Figure 1 illustrates how a virtual page in the process address space maps to a physical page frame in memory.
Figure 1. Mapping of virtual pages to physical page frames in the process address space