java related learning notes

jvm

java -XX:+PrintFlagsFinal and java -XX:+PrintFlagsInitial
Output result = indicates default attribute: = indicates modified data

Strong weak virtual quotation

The weak reference WeakReference will trigger the GC and get() == null
When a GC is triggered by a soft reference, the get() value is not necessarily null. When the memory is insufficient, the data inside the soft reference will be cleared. It is suitable for use as a memory cache

JVM GC

Test code

public static void main(String[] args)throws Exception {
    String str = "kkkk";
    while (true){
        str += str + new Random().nextInt(888888888) + new Random().nextInt(777777777);
        str.intern();
    }
}

jvm startup parameters

-Xmx10m -XX:+PrintCommandLineFlags -XX:+PrintGCDetails

-20: + printcommandlineflags activate output command
-20: + printgcdetails output GC log details

Serial Collector

-XX:UseSerialGC DefNew,Tenured

New generation uses DefNew, old age belt uses Tenured

ParNew new parallel collector

-XX:+UseParNewGC ParNew,Tenured
The new generation uses the multi-threaded collector ParNew, while the old generation still uses the single threaded collector Tenured

The warning of jvm will be removed later, which is not recommended

ParallelGC parallel collector

-20: + useparallelgc new generation PSYoungGen, old generation ParOldGen
The new generation and the old generation use parallel collectors
The legendary throughput first collector, the default collector of jdk1.8
Serial collector, parallelization in new generation and old generation

➜  ~ ./opt/common/jdk1.8.0_201/bin/java -XX:+PrintCommandLineFlags -version
-XX:InitialHeapSize=113587520 -XX:MaxHeapSize=1817400320 -XX:+PrintCommandLineFlags -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC 
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

It can be seen that the parallel GC parallel collector is used by default, and the jvm compilation mode is mixed by default,
The initial heap size is about 108MB, and the maximum heap size is about 1.7G. Because the local memory is 8G, the size is about 25% plus the operating system memory

CMS collector

-XX:+UseConcMarkSweepGC

-Xmx10m
-XX:+PrintCommandLineFlags
-XX:+PrintGCDetails
-XX:+UseConcMarkSweepGC

As can be seen from the following output, ParNew is used by the default Cenozoic generation
New generation ParNew, old age CMS, and serialOld standby (when triggering CMS recovery failure, serialOld performs FullGC)
According to the GC log below, there are many GCs in the new generation, but in the old generation

  • CMS initial mark mark of CMS GCRoot object triggers STW(Stop the World)
  • CMS concurrent mark / CMS concurrent preclean queries the living object according to the GCRoot object without triggering STW
  • CMS final mark corrects part of objects marked with changed part after user thread execution, triggering STW
  • CMS concurrent sweep start does not trigger STW
  • A full GC of serialOld was triggered due to a CMS recycle failure

Positioning idea of CPU utilization over high

  • top command positioning process resource consumption
  • Jps-l or PS EF query detailed process details
  • ps -mp process number - o THREAD,tid,time query thread CPU usage
  • Convert thread ID to hexadecimal (lowercase)
  • jstack process ID |grep thread ID -A60 track the first 60 lines of thread
s -mp 25226 -o THREAD,tid,time 
USER     %CPU PRI SCNT WCHAN  USER SYSTEM   TID     TIME
cmm       100   -    - -         -      -     - 00:08:03
cmm       0.0  19    - futex_    -      - 25226 00:00:00
cmm      98.6  19    - -         -      - 25227 00:07:52
cmm       0.1  19    - futex_    -      - 25230 00:00:00
cmm       0.1  19    - futex_    -      - 25231 00:00:00
cmm       0.1  19    - futex_    -      - 25232 00:00:00
cmm       0.1  19    - futex_    -      - 25233 00:00:00
cmm       0.1  19    - futex_    -      - 25234 00:00:00
cmm       0.1  19    - futex_    -      - 25235 00:00:00
cmm       0.1  19    - futex_    -      - 25236 00:00:00
cmm       0.1  19    - futex_    -      - 25237 00:00:00
cmm       0.7  19    - futex_    -      - 25247 00:00:03
cmm       0.0  19    - futex_    -      - 25248 00:00:00
cmm       0.0  19    - futex_    -      - 25250 00:00:00
cmm       0.0  19    - futex_    -      - 25259 00:00:00
cmm       0.0  19    - wait_w    -      - 25260 00:00:00
cmm       0.0  19    - futex_    -      - 25261 00:00:00
cmm       0.0  19    - futex_    -      - 25262 00:00:00
cmm       0.0  19    - futex_    -      - 25263 00:00:00
cmm       0.0  19    - futex_    -      - 25264 00:00:00
cmm       0.0  19    - futex_    -      - 25265 00:00:00
cmm       0.0  19    - futex_    -      - 25266 00:00:00
cmm       0.0  19    - skb_wa    -      - 25270 00:00:00
➜  ~ jstack 25226 | grep 628b -A60
"main" #1 prio=5 os_prio=0 tid=0x00007f2674010800 nid=0x628b runnable [0x00007f267c3e5000]
   java.lang.Thread.State: RUNNABLE
	at my.base.Taiger.main(Taiger.java:15)

"VM Thread" os_prio=0 tid=0x00007f26741ce000 nid=0x629f runnable 

"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00007f2674026800 nid=0x628e runnable 

"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00007f2674028000 nid=0x628f runnable 

"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00007f267402a000 nid=0x6290 runnable 

"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x00007f267402b800 nid=0x6291 runnable 

"GC task thread#4 (ParallelGC)" os_prio=0 tid=0x00007f267402d800 nid=0x6292 runnable 

"GC task thread#5 (ParallelGC)" os_prio=0 tid=0x00007f267402f000 nid=0x6293 runnable 

"GC task thread#6 (ParallelGC)" os_prio=0 tid=0x00007f2674031000 nid=0x6294 runnable 

"GC task thread#7 (ParallelGC)" os_prio=0 tid=0x00007f2674032800 nid=0x6295 runnable 

"VM Periodic Task Thread" os_prio=0 tid=0x00007f267462d000 nid=0x62b2 waiting on condition 

JNI global references: 12

Operating system locality principle

When a piece of data needs to be loaded from the disk, the operating system will not only take out the target data, but also take out a part of the data adjacent to the target data and load it into the memory. Because it is thought that when this part of data is used, the data adjacent to it will be accessed approximately, so it will be loaded into the memory together. The unit of each load is that the page size is 4KB

The unit of page in innoDB is 16KB

26 original articles published, praised 27, visited 50000+
Private letter follow

Tags: Java jvm Attribute

Posted on Sun, 09 Feb 2020 23:11:15 -0500 by giovo