學(xué)習(xí)筆記 JVM Log技術(shù)簡(jiǎn)介
本文向大家簡(jiǎn)單介紹一下JVM Log的概念,初始化和釋放,JVM Log各個(gè)class的實(shí)現(xiàn)除了很自然地運(yùn)用了繼承,同時(shí)運(yùn)用重載new/deleteoperator這個(gè)C++特有的技巧,也 有效地封裝了JVM Log的創(chuàng)建和釋放功能。
JVM Log簡(jiǎn)介
JVM在調(diào)試版本下,會(huì)輸出hotspot.JVM Log。通過(guò)參數(shù)-XJVM Loggc:FileName,來(lái)設(shè)置GC的JVM Log。
JVM Log的實(shí)現(xiàn)主要在
- \hotspot\src\share\vm\utilities\ostream.hpp
- \hotspot\src\share\vm\utilities\ostream.cpp
- \hotspot\src\share\vm\utilities\xmlstream.hpp
- \hotspot\src\share\vm\utilities\xmlstream.cpp
- \hotspot\src\share\vm\utilities\defaultStream.hpp
主要的class是:outputStream、fileStream、xmlTextStream、defaultStream
繼承關(guān)系是:
ResourceObj
|
|-- outputStream
|
|--- fileStream
|
|--- xmlTextStream
|
|--- defaultStream
defaultStream::instance是其他模塊調(diào)用的主要接口。
JVM Log的初始化
ostream_init()初始化defaultStream::instance
ostream_init_JVM Log()初始化JVM的DebugJVM Log和GC的JVM Log,
其中其核心代碼是:defaultStream::instance->has_JVM Log_file();它轉(zhuǎn)而調(diào)用voiddefaultStream::init_JVM Log();這是真正干活的代碼了。
defaultStream::init_JVM Log的代碼寫(xiě)的很清晰,其中只有一個(gè)C++的語(yǔ)法點(diǎn)需要注意:重載newoperator。
ostream.cppline346
fileStream*file=new(ResourceObj::C_HEAP)fileStream(try_name);
這是因?yàn)閛utputStream的父類(lèi)是ResourceObj,ResourceObj重載了new和deleteoperator。關(guān)于C++語(yǔ)法就不多說(shuō)了,太多的好書(shū)論及了這個(gè)問(wèn)題。
JVM Log的最終釋放
Threads::destroy_vm()
|
|--> exit_globals()
|
|--> ostream_exit()
|
|--> 用delete operator釋放掉各個(gè)JVM Log
總結(jié)
JVM Log各個(gè)class的實(shí)現(xiàn)除了很自然地運(yùn)用了繼承,同時(shí)運(yùn)用重載new/deleteoperator這個(gè)C++特有的技巧,也 有效地封裝了JVM Log的創(chuàng)建和釋放功能。
【編輯推薦】