- Docs »
- Java »
- Java 8 Compiler & Runtime
-
Java 8 Compiler & Runtime
Compiler
- Type of compiler:
javac
- default compiler come with JDK
javax.tools.JavaCompiler
- Maven 3 + JDK 1.6 or above 1
- 3rd party compiler (i.e. ECJ 2)
- Additional work did by compiler
- Optimisation
- String concat converted StringBuffer 3
- constant value is copied to refering class
- Important option in
javac
4
- classpath (
-cp
, -classpath
)
- debugging info (
-g
, -g:none
, -g:{keywords}
- source version (
-source 1.6
)
- target version (
-target 1.7
)
- Extra:
- use
javap
to view class file Java version (javap -verbose MyClass
)
-
- show the different of javac vs Eclipse JDT compiler via slf4j
Java Runtime aka JVM
- HotSpot VM, with JIT compiler
- compile and execute vs intepret bytecode
- Important options 5
- Server vs Client VM 6
- For Java SE 6, the definition of a server-class machine is one with at least 2 CPUs and at least 2GB of physical memory g
- Client: optimise on startup time and memory footprint
- Server: optimize on operating speed
-XX:CompileThreshold
(default=10,000)
- Tips: write shorter method that widely shared
- Heap size
- PermGen size
- GC options
- possible to set custom properties via
-Dxxx
- trick used in unified.sh
- spring.profile
- Memory Model
- Eden, Young
- Survivor 1 & 2 -
- Old
- PermGen
- GC
- Minor vs Major GC vs Full GC 8
- do not trigger System.gc()
- GC options
- Type
- Serial GC
-XX:+UseSerialGC
- Parallel GC
-XX:+UseParallelGC
,
- Parallel COmpact GC
-XX:+UseParallelOldGC
- CMS GC
-XX:+UseConcMarkSweepGC
- G1 GC
-XX:+UseG1GC
- officially introduce in JDK 1.7
- enable logging
-XX:+PrintGC
, -XX:+PrintGCDetails
, -Xloggc:gc.log
-XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps
- possible to enable without restart via
jinfo
- OutOfMemoryError:
java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Permgen space
- Extra: Off-heap & Unsafe
Further Reading:
Last update: 2022-03-11 07:20:05