JVM architecture

Class file load – Verify – Prepare – Parse – Initialize – Use – unload one stack per thread, one stack frame per method

How to identify garbage

  • Reference counting
    • There are problems with circular references
  • Forward to
    • Count reachable objects from the roots object

Garbage collection algorithm

  • Tag cleanup (disadvantages: memory fragmentation, no contiguous memory)

  • Copying (disadvantage: waste memory commonly used in the new generation)

  • Mark compression (a bit slower than copying is commonly used in old times [tenured])

  • new

    • Few viable objects
    • Using copying takes up less memory space and is also more efficient
  • old

    • Less waste
    • Mark-compact is commonly used

Look at the last oneGarbage Collector

  • Serial Collector
    • XX:+UseSerialGC
    • Single thread
  • Parallel Collector
    • There is a lot of parallelism, but the JVM pauses every time garbage is collected
    • CMS Collector
    • Do this with concurrent partitions and short pause times
  • G1
    • Not only the pause is short, the colleague concurrency is large. It’s just a balance point
    • Someone suggested that Java9 use this

The JVM parameter

  • – Standard parameter, which should be supported by all JVMS
  • -x is non-standard, and each JVM implementation is different
  • -XX Indicates an unstable parameter that may be cancelled in the next version

Allocation of Java objects

No open escape analysis is allocated on the stack firstCopy the code
  • On the stack

    • Thread private small object
    • No escape (-xx :+DoEscapeAnalysis enable Escape analysis is enabled by default)
    • Support for scalar substitution
    • Don’t need to adjust
  • TLAB (Thread Locla Allacation Buffer)

    It is also Eden on the heap, so that a portion of the data can be unlocked

    • Occupy Eden, default 1%
    • Multi-threaded users can apply for space without competing for Eden, which improves efficiency
    • Small objects
    • Don’t need to adjust
  • The old s

    • The big object
  • eden

  • Heap: – XX: XX: HeapDumpOnOutOfMemoryError – HeapDumpPath = TMP/JVM dump – XX: PrintGCDetails Xms10M – Xmx10M augmenting the biggest directly, avoid midway through analysis and calculation of recycling

  • Stack +Xss128k large thread recursive calls can be very deep and the number of concurrent small threads can be particularly large

The last

Like can pay attention to my public number ‘Java small melon brother sharing platform “thank you!