计算机科学与技术专业毕业论文外文文献翻译Java垃圾收集器的工作方式.docx

上传人:b****6 文档编号:13645869 上传时间:2023-06-16 格式:DOCX 页数:9 大小:23.04KB
下载 相关 举报
计算机科学与技术专业毕业论文外文文献翻译Java垃圾收集器的工作方式.docx_第1页
第1页 / 共9页
计算机科学与技术专业毕业论文外文文献翻译Java垃圾收集器的工作方式.docx_第2页
第2页 / 共9页
计算机科学与技术专业毕业论文外文文献翻译Java垃圾收集器的工作方式.docx_第3页
第3页 / 共9页
计算机科学与技术专业毕业论文外文文献翻译Java垃圾收集器的工作方式.docx_第4页
第4页 / 共9页
计算机科学与技术专业毕业论文外文文献翻译Java垃圾收集器的工作方式.docx_第5页
第5页 / 共9页
计算机科学与技术专业毕业论文外文文献翻译Java垃圾收集器的工作方式.docx_第6页
第6页 / 共9页
计算机科学与技术专业毕业论文外文文献翻译Java垃圾收集器的工作方式.docx_第7页
第7页 / 共9页
计算机科学与技术专业毕业论文外文文献翻译Java垃圾收集器的工作方式.docx_第8页
第8页 / 共9页
计算机科学与技术专业毕业论文外文文献翻译Java垃圾收集器的工作方式.docx_第9页
第9页 / 共9页
亲,该文档总共9页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

计算机科学与技术专业毕业论文外文文献翻译Java垃圾收集器的工作方式.docx

《计算机科学与技术专业毕业论文外文文献翻译Java垃圾收集器的工作方式.docx》由会员分享,可在线阅读,更多相关《计算机科学与技术专业毕业论文外文文献翻译Java垃圾收集器的工作方式.docx(9页珍藏版)》请在冰点文库上搜索。

计算机科学与技术专业毕业论文外文文献翻译Java垃圾收集器的工作方式.docx

计算机科学与技术专业毕业论文外文文献翻译Java垃圾收集器的工作方式

计算机科学与技术专业毕业论文外文文献翻译:

Java垃圾收集器的工作方式

计算机科学与技术专业毕业论文外文文献翻译:

Java

垃圾收集器的工作方式

毕业设计论文

外文文献翻译

专业计算机科学与技术

学生姓名

班级

学号

指导教师

信息工程学院

英文原文

HowagarbagecollectorworksofJavaLanguage

Ifyoucomefromaprogramminglanguagewhereallocatingobjectsontheheapisexpensive,youmaynaturallyassumethatJava’sschemeofallocatingeverythingexceptprimitivesontheheapisalsoexpensive.However,itturnsoutthatthegarbagecollectorcanhaveasignificantimpactonincreasingthespeedofobjectcreation.Thismightsoundabitoddatfirst?

thatstoragereleaseaffectsstorageallocation?

butit’sthewaysomeJVMswork,anditmeansthatallocatingstorageforheapobjectsinJavacanbenearlyasfastascreatingstorageonthestack

inotherlanguages.

Forexample,youcanthinkoftheC++heapasayardwhereeachstakesoutitsownpieceofturfobject.Thisrealestatecanbecomeabandonedsometimelaterandmustbereused.InsomeJVMs,theJavaheapisquitedifferent;it’smorelikeaconveyorbeltthatmovesforwardeverytime

youallocateanewobject.Thismeansthatobjectstorageallocationisremarkablyrapid.The“heappointer”issimplymovedforwardintovirginterritory,soit’seffectivelythesameasC++’sstackallocation.Ofcourse,there’salittleextraoverheadforbookkeeping,butit’snothinglikesearchingforstorage.

Youmightobservethattheheapisn’tinfactaconveyorbelt,andifyoutreatitthatway,you’llstartpagingmemory?

movingitonandoffdisk,sothatyoucanappeartohavemorememorythanyouactuallydo.Pagingsignificantlyimpactsperformance.Eventually,afteryoucreateenoughobjects,you’llrunoutofmemory.Thetrickisthatthegarbagecollectorstepsin,andwhileitcollectsthegarbageitcompactsalltheobjectsintheheapsothatyou’veeffectivelymovedthe“heappointer”closertothebeginningoftheconveyorbeltandfartherawayfromapagefault.Thegarbagecollectorrearrangesthingsandmakesitpossibleforthehigh-speed,infinite-free-heapmodeltobeusedwhileallocatingstorageTounderstandgarbagecollectioninJava,it’shelpfullearnhowgarbage-collectionschemesworkinothersystems.A

simplebutslowgarbage-collectiontechniqueiscalledreferencecounting.Thismeansthateachobjectcontainsareferencecounter,andeverytimeareferenceisattachedtothatobject,thereferencecountisincreased.Everytimeareferencegoesoutofscopeorissettonull,thereferencecountisdecreased.Thus,managingreferencecountsisasmallbutconstantoverheadthathappensthroughoutthelifetimeofyourprogram.Thegarbagecollectormovesthroughtheentirelistofobjects,andwhenitfindsonewithareferencecountofzeroitreleasesthatstoragehowever,referencecountingschemesoftenreleaseanobjectassoonasthecountgoestozero.Theonedrawbackisthatifobjectscircularlyrefertoeachothertheycanhavenonzeroreferencecountswhilestillbeinggarbage.Locatingsuchself-referentialgroupsrequiressignificantextraworkforthegarbagecollector.Referencecountingiscommonlyusedtoexplainonekindofgarbagecollection,butitdoesn’tseemtobeusedinanyJVMimplementationsInfasterschemes,garbagecollectionisnotbasedonreferencecounting.Instead,itisbasedontheideathatanynon-deadobjectmustultimatelybetraceablebacktoareferencethatliveseitheronthestackorinstaticstorage.Thechainmightgothroughseverallayersofobjects.Thus,ifyoustartinthestackandinthestaticstorageareaandwalkthroughallthereferences,you’llfindalltheliveobjects.Foreachreferencethatyoufind,youmusttraceintotheobjectthatitpointstoandthenfollowallthereferencesin

thatobject,tracingintotheobjectstheypointto,etc.,untilyou’ve

movedthroughtheentireWebthatoriginatedwiththereferenceonthestackorinstaticstorage.Eachobjectthatyoumovethroughmuststillbealive.Notethatthereisnoproblemwithdetachedself-referentialgroups?

thesearesimplynotfound,andarethereforeautomaticallygarbageIntheapproachdescribedhere,theJVMusesanadaptivegarbage-collectionscheme,andwhatitdoeswiththeliveobjectsthatitlocatesdependsonthevariantcurrentlybeingused.Oneofthesevariantsisstop-and-copy.Thismeansthat?

forreasonsthatwillbecomeapparent?

theprogramisfirststoppedthisisnotabackgroundcollectionscheme.Then,eachliveobjectiscopiedfromoneheaptoanother,leavingbehindallthegarbage.Inaddition,astheobjectsarecopiedintothenewheap,theyarepackedend-to-end,thuscompactingthenewheapandallowingnewstoragetosimplybereeledofftheendaspreviouslydescribed.

Ofcourse,whenanobjectismovedfromoneplacetoanother,allreferencesthatpointattheobjectmustbechanged.Thereferencethatgoesfromtheheaporthestaticstorageareatotheobjectcanbechangedrightaway,buttherecanbeotherreferencespointingtothisobjectInitialization&Cleanupthatwillbeencounteredlaterduringthe“walk.”Thesearefixedupastheyarefoundyoucouldimagineatablethatmapsoldaddressestonewones.

Therearetwoissuesthatmaketheseso-called“copycollectors”

inefficient.Thefirstistheideathatyouhavetwoheapsandyousloshallthememorybackandforthbetweenthesetwoseparateheaps,maintainingtwiceasmuchmemoryasyouactuallyneed.SomeJVMsdealwiththisbyallocatingtheheapinchunksasneededandsimplycopyingfromonechunktoanother.

Thesecondissueisthecopyingprocessitself.Onceyourprogrambecomesstable,itmightbegeneratinglittleornogarbage.Despitethat,acopycollectorwillstillcopyallthememoryfromoneplacetoanother,whichiswasteful.Topreventthis,someJVMsdetectthatnonewgarbageisbeinggeneratedandswitchtoadifferentschemethisisthe“adaptive”part.Thisotherschemeiscalledmark-and-sweep,andit’s

whatearlierversionsofSun’sJVMusedallthetime.Forgeneraluse,mark-and-sweepisfairlyslow,butwhenyouknowyou’regeneratinglittleornogarbage,it’sfast.Mark-and-sweepfollowsthesamelogicof

startingfromthestackandstaticstorage,andtracingthroughallthereferencestofindliveobjectsHowever,eachtimeitfindsaliveobject,thatobjectismarkedbysettingaflaginit,buttheobjectisn’tcollectedyet.Onlywhenthemarkingprocessisfinisheddoesthesweepoccur.Duringthesweep,thedeadobjectsarereleased.However,nocopyinghappens,soifthecollectorchoosestocompactafragmentedheap,itdoessobyshufflingobjectsaround.“Stop-and-copy”referstothe

ideathatthistypeofgarbagecollectionisnotdoneinthebackground;Instead,theprogramisstoppedwhilethegarbagecollectionoccurs.IntheSunliteratureyou’llfindmanyreferencestogarbagecollectionasalow-prioritybackgroundprocess,butitturnsoutthatthegarbagecollectionwasnotimplementedthatwayinearlierversionsoftheSunJVM.Instead,theSungarbagecollectorstoppedtheprogramwhenmemorygotlow.Mark-and-sweepalsorequiresthattheprogrambestopped.

Aspreviouslymentioned,intheJVMdescribedherememoryisallocatedinbigblocks.Ifyouallocatealargeobject,itgetsitsownblock.Strictstop-and-copyrequirescopyingeveryliveobjectfromthesourceheaptoanewheapbeforeyoucanfreetheoldone,whichtranslatestolotsofmemory.Withblocks,thegarbagecollectioncantypicallycopyobjectstodeadblocksasitcollects.Eachblockhasagenerationcounttokeeptrackofwhetherit’salive.Inthenormalcase,onlytheblockscreatedsincethelastgarbagecollectionarecompacted;allotherblocksgettheirgenerationcountbumpediftheyhavebeenreferencedfromsomewhere.Thishandlesthenormalcaseoflotsofshort-livedtemporaryobjects.Periodically,afullsweepismade?

largeobjectsarestillnotcopiedtheyjustgettheirgenerationcountbumped,andblockscontainingsmallobjectsarecopiedandcompacted.

TheJVMmonitorstheefficiencyofgarbagecollectionandifitbecomesawasteoftimebecauseallobjectsarelong-lived,thenit

switchestomark-andsweep.Similarly,theJVMkeepstrackofhowsuccessfulmark-and-sweepis,andiftheheapstartstobecomefragmented,itswitchesbacktostop-and-copy.Thisiswherethe“adaptive”part

comesin,soyouendupwithamouthful:

“Adaptivegenerationalstop-and-copymark-andsweep.”

ThereareanumberofadditionalspeedupspossibleinaJVM.Anespeciallyimportantoneinvolvestheoperationoftheloaderandwhatiscalledajust-in-timeJITcompiler.AJITcompilerpartiallyorfullyconvertsaprogramintonativemachinecodesothatitdoesn’tneedtobeinterpretedbytheJVMandthusrunsmuchfaster.Whenaclassmustbeloadedtypically,thefirsttimeyouwanttocreateanobjectofthatclass,the.classfileislocated,andthebytecodesforthatclassarebroughtintomemory.Atthispoint,oneapproachistosimplyJITcompileallthecode,butthishastwodrawbacks:

Ittakesalittlemoretime,which,compoundedthroughoutthelifeoftheprogram,canaddup;anditincreasesthesizeoftheexecutablebytecodesaresignificantlymorecompactthanexpandedJITcode,andthismightcausepaging,whichdefinitelyslowsdownaprogram.Analternativeapproachislazyevaluation,whichmeansthatthecodeisnotJITcompileduntilnecessary.Thus,codethatnevergetsexecutedmightneverbeJITcompiled.TheJavaHotspottechnologiesinrecentJDKstakeasimilarapproachbyincreasinglyoptimizingapieceofcodeeachtimeitisexecuted,sothe

morethecodeisexecuted,thefasteritgets.

中文译文Java垃圾收集器的工作方式

如果你学下过一种因为在堆里分配对象所以开销过大的编程语言,很自然你可能会假定

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2