英文文献 科技类 原文及翻译 电子 电气 自动化 通信74Word文件下载.docx
《英文文献 科技类 原文及翻译 电子 电气 自动化 通信74Word文件下载.docx》由会员分享,可在线阅读,更多相关《英文文献 科技类 原文及翻译 电子 电气 自动化 通信74Word文件下载.docx(33页珍藏版)》请在冰豆网上搜索。
![英文文献 科技类 原文及翻译 电子 电气 自动化 通信74Word文件下载.docx](https://file1.bdocx.com/fileroot1/2022-10/11/66f78ded-4e7f-4987-9847-b992f58a52a8/66f78ded-4e7f-4987-9847-b992f58a52a81.gif)
you,thesoftwaredeveloper,tocreatesoftwareagentsthatcanmonitorandcontrolyourJava
programminglanguageapplications.JVMTIisnewintheJava2SoftwareDevelopmentKit
(SDK),StandardEdition,version1.5.0.ItreplacestheJavaVirtualMachineProfilingInterface
(JVMPI),whichhadbeenincludedasanexperimentalfeatureoftheJava2SDKsinceversion
1.1.JVMTIisdescribedinJSR-163.
ThisarticleillustrateshowtouseJVMTItocreateadebuggingandprofilingtoolforJavaapplications.Suchatool,alsocalledanagent,usesthefunctionalityexposedbytheinterface
toregisterfornotificationofeventsastheyoccurintheapplication,andtoqueryandcontrol
theapplication.JVMTIdocumentationisavailablehere.AJVMTIagentcanbeusefulfordebuggingandtuninganapplication.Itcanillustrateaspectsoftheapplication,suchas
memoryallocation,CPUutilization,andlockcontention.
EventhoughJVMPIisexperimental,itisbeingusedbymanyJavatechnologydevelopers,andin
severalcommercially-availableJavaapplicationprofilers.PleasenotethatdevelopersarestronglyencouragedtouseJVMTIinsteadofJVMPI.JVMPIwillbediscontinuedintheverynearfuture.
JVMTIimprovesuponthefunctionalityandperformanceofJVMPIinmanyways.Forexample:
JVMTIreliesonacallbackforeachevent.ThisismoreefficientthantheJVMPIdesignofusing
eventstructures,whichneededtobemarshalledandunmarshalled.
JVMTIcontainsfourtimesasmanyfunctionsasJVMPI(includingmanymorefunctionsto
obtaininformationaboutvariables,fields,methods,andclasses).ForacompleteindexoftheJVMTI
functions,seetheFunctionIndexpage.
JVMTIprovidesnotificationformoretypesofeventsthandoesJVMPI,includingexception
events,fieldaccessandmodificationevents,andbreakpointandsingle-stepevents.
SomeoftheJVMPIeventsthatwereneverfullyutilized,suchasarenanewanddelete,orthat
canbebetterobtainedthroughbytecodeinstrumentation,ortheJVMTIfunctionsthemselves,(such
asheapdumpandobjectallocation)havebeendropped.Adescriptionoftheeventsisavailableat
theEventIndexpage.
JVMTIiscapability-based,whereasJVMPIwas"
allornothing"
withcorrespondingperformanceimpact.
JVMPIheapfunctionalitydidnotscale.
JVMPIhadnoerrorreturninformation.
JVMPIwasdeeplyinvasiveonVMimplementationswithresultingmaintenanceissuesand
performanceimpacts.
JVMPIisexperimentalandwillbediscontinuedverysoon.
Intheremainderofthisarticle,wepresentasimpleagentthatusesJVMTIfunctionstoextract
informationfromaJavaapplication.Theagentmustbewritteninnativecode.Thesample
agentshownhereiswrittenintheCprogramminglanguage.Youcandownloadthecompletesampleagentcodehere.Thefollowingparagraphsdescribehowanagentisinitialized,and
howtheagentusesJVMTIfunctionstoextractinformationaboutaJavaapplication,aswellas
howtocompileandruntheagent.Thesamplecodeandcompilationstepsarespecificto
UNIXenvironments,butcanbemodifiedforusewithWindows.TheagentdescribedherecanbeusedtoanalyzethethreadsandtodetermineJVMmemoryusageinanyJavaapplication.
AsimpleprogramwrittenintheJavaprogramminglanguage,calledSimpleThread.java,isincludedandcanbedownloadedhere.WeuseThreadSample.javatodemonstratetheexpectedoutputfromtheagent.
ThefunctionalityofJVMTIismuchmoreextensivethanwecandetailhere,butthecode
inthisarticleshouldprovideastartingplacefordevelopingprofilingtoolstomeetyourown
specificneeds.
AgentInitialization
Thissectiondescribesthecodethatisusedtoinitializetheagent.Tobeginwith,theagentmustincludethejvmti.hfilewiththestatement:
#include<
jvmti.h>
.
Inaddition,theagentmustcontainafunctioncalledAgent_OnLoad,whichisinvokedwhenthelibraryisloaded.TheAgent_OnLoadfunctionisusedtosetupfunctionalitythatis
1requiredpriortoinitializingtheJavavirtualmachine(JVM).TheAgent_OnLoadsignaturelookslikethis:
JNIEXPORTjintJNICALLAgent_OnLoad(JavaVM*jvm,char*options,void
*reserved){
...
/*WereturnJNI_OKtosignifysuccess*/
returnJNI_OK;
}
Inoursamplecode,wemustenableseveralcapabilitiesfortheJVMTIfunctionsand
eventsthatwewillbeusing.Itisgenerallydesired,andinsomecasesrequired,toaddthesecapabilitiesintheAgent_OnLoadfunction.Thecapabilitiesnecessaryforeachfunctionor
eventaredescribedintheJavaVirtualMachineToolInterfacepages.Forexample,tousetheInterruptT