"In-depth understanding of the Java Virtual Machine," a book jdk version used is 1.6. 4.2.2 Examples of the book is not the same performance and is described in the book under jdk1.8, in this record.
Because jdk1.8 the Hotspot virtual machine has been removed permanently generations, string constants moved to the heap memory. Added Metaspace (dimensional space), the method in the area to move Metaspace. Metaspace uses local memory, memory size is limited by the physical machine.
jstat command is used to monitor virtual machines running various status information line tool. It can display a virtual machine in the process of class loading, memory, garbage collection, JIT compiler and other operating data.
An example of the exemplary write
1, a new controller
@RestController
@RequestMapping("/jvm/jstat")
public class B_Jstat {
Logger logger = LoggerFactory.getLogger(B_Jstat.class);
static List<OOMObject2> list = new ArrayList<>();
static class OOMObject2{
public byte[] placeholder = new byte[1024 * 1024]; //1M byte数组
}
public static void fillOutOfMemory(int num) throws InterruptedException{
list = new ArrayList<>();
for (int i = 0; i < num ; i++){
TimeUnit.MILLISECONDS.sleep(100);
list.add(new OOMObject2());
}
}
//属性list填充1000个OOMObject2实例,模拟堆内存溢出
@GetMapping("/obj")
public String outOfMemory(HttpServletRequest request) throws Exception{
fillOutOfMemory(1000);
return "完成";
}
}
2, start the service, the maximum and minimum heap memory is set to 512m. nohup java -jar -Xms512m -Xmx512m spring-boot-lean.jar &
3, the root directory into the java / jdkXXX / bin directory, using a virtual machine monitor jstat operating state, shown in Figure 1
4, sends a request HTTP: // XXX: 8080 / JVM / jstat-/ obj , monitoring data is changed.
jstat -gc 6602 5000 100 command to explain:
-Gc role is to monitor Java heap conditions, including the Eden area, two survivor areas, such as the capacity of the old year, used space, GC total time and other information.
6602 is the process ID of spring-boot-lean.jar this service
5000 represents five seconds once the process of inquiry
100 indicates a total of 100 queries
Figure 1 parameter to explain
S0C survivor区0总容量,单位KB
S1C survivor区1总容量,单位KB
S0U survivor区0使用量,单位KB
S1U survivor区1使用量,单位KB
EC Eden区总容量,单位KB
EU Eden区使用量,单位KB
OC 老年代总容量,单位KB
OU 老年代使用量,单位KB
MC Metaspace总容量,单位KB
MU Metaspace使用量,单位KB
CCSC Metaspace中Klass Metaspace总容量,单位KB
CCSU Metaspace中Klass Metaspace使用量,单位KB
YGC Minor GC 次数
YGCT Minor GC 消耗总时间,单位S
FGC FullGC 次数
FGCT FullGC 消耗总时间,单位S
GCT GC总消耗时间,单位S
B_Jstat the list is strong references, causing all new OOMObject2 () can not be recycled garbage collection mechanism. 1 can be seen from FIG.
1, the amount of old age gradually rises OU.
2, OU reached the maximum, the virtual machine can not copy objects to the OU, so the EU can not reduce (the last few rows, the EU can not be reduced).
3, can also be seen from the figure survivor region may also be borrowed from a portion of the capacity of Eden region.