日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Hotspot hotswap, who and who are best freinds

發(fā)布時間:2023/12/9 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Hotspot hotswap, who and who are best freinds 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Hotspot&hotswap,whoandwhoarebestfreinds(點(diǎn)擊這里查看ppt)

java動態(tài)替換的ppt。

hotspot&hotswapwhoandwhoarebestfriends
xuanxi@taobao.com

whyweneedhotswap?
主管:你在偷懶?
匯編開發(fā)人員:我在編譯。
C++開發(fā)人員:我在編譯打包部署。
java開發(fā)人員:我在打包部署。
Jsp開發(fā)人員:我在部署。
Python開發(fā)人員:………
Ruby開發(fā)人員:………

whyweneedhotswap?
線上緊急修改。(方法體的修改、增加和減少方法,字段,類,接口,更改類繼承拓?fù)浣Y(jié)構(gòu))

JVM1.2以后支持了hotswap功能

JVMTMToolInterface

typedefstruct { jclassklass; jintclass_byte_count; const unsigned char* class_bytes; } jvmtiClassDefinition; jvmtiError RedefineClasses(jvmtiEnv* env, jintclass_count, const jvmtiClassDefinition* class_definitions)

JVM1.2以后支持了hotswap功能

JavaTMVirtualMachineDebugInterfaceReference

typedefstruct { jclassclazz; /* Class to be redefined */ jintclass_byte_count; /* number of bytes defining class (below) */ jbyte *class_bytes; /* bytes defining class */ /* (in Class File Format of JVM spec) */ } JVMDI_class_definition;jvmdiError RedefineClasses(jintclassCount, JVMDI_class_definition *classDefs)

Javadev除打包部署外還干嘛?
用IDE(eclipse)調(diào)試

Soundsgood,what’stheproblem?
Unfortunately,thisredefinitionislimitedonlytochangingmethodbodies—itcannoteitheraddmethodsorfieldsorotherwisechangeanythingelse,exceptforthemethodbodies.

So,Herewego!
Discardingclassloaders
java.lang.instrument
HackingchangesintotheJVMitselffeelsafragileapproach

Discardingclassloaders

Discardingclassloaderscanhelp,but
Notparticularlygranular
Instancestateislost
Canrunintomemoryproblems
Demo(discarding.classloaders.hotswap)byken.wug@gmail.com

java.lang.instrument
aJRubyobjectisnotmuchmorethanaMapfrommethodnamestotheirimplementationsandfromfieldnamestotheirvalues.
byte[]transform(ClassLoaderloader,
StringclassName,
Class<?>classBeingRedefined,
ProtectionDomainprotectionDomain,
byte[]classfileBuffer)
throwsIllegalClassFormatException

java.lang.instrument
java.lang.instrument.ClassFileTransformer.Thisclasscandotwothings:
replacemethodbodiesofexistingclasses(butnothingelse,itisessentiallythesameashotswap).
modifyclassesbeforetheygetloadedintothejavavirtualmachine
classClass1
{protectedstaticintfield;
}

java.lang.instrument

classClass1{protectedstaticintfield;publicstaticObject__REDEFINED_STATIC_METHOD_(intmethodNo,Object[]parameters){if(methodNo==0){returnfield;}if(methodNo==1){Integerp0=(Integer)parameters[0];intunboxedP0=p0.intValue();field=unboxedP0;returnnull;}returnnull;}}

java.lang.instrument
publicclassProxy1{publicvoidsetField(intparam){Object[]params=newObject[1];params[0]=newInteger(param);Class1.__REDEFINED_STATIC_METHOD_(1,params);}}

Soundswell,but…
Perfomance.subjecttoindirection&Pemmemory
JavaSDKclasses.Thenativecode
Compatibility.A.class.getMethods()

fakereplace
GoogleCodeproject
Usualstructurechangessupported
Methods,fields,constructors
Annotations
Reflectioninstrumentation
Integratessupportdirectlyforsomeframeworks

Fakereplacedemo

Jrebel(notfree)
onemasterclass+severalanonymous
Solveproblem
directionandlightweight
AvoidsinstrumentingtheJava
TweakstheresultsoftheReflectionAPI,sothatwecancorrectlyincludetheadded/removedmembersintheseresults

JrebelDemo

Soundsperfect

國家隊(duì)(nationteam)
Hotswap.patch

hotspotandhotswap
Arbitrarychangespossible(includingchangestosubtyperelationships)
Noperformancepenaltybeforeorafterthechange
Nointroducedindirections
Continuedexecutionofoldactivemethods
Onlysimple,comprehensiblestrategiesforfieldmatchingormethodtransitions
ChangepossibleatanypointwhentheVMissuspended
Gracefulhandlingofaccessestodeletedfieldsorcallsofdeletedmethods

HotswapStatus

TransformerMethods

class A { int x; intdoubleX; static void $staticTransformer() //class transformer { System.out.println(“Class A has a new version”); } void $transformer() { doubleX = 2 * x; } //instance’s }

Hotswap.patchdemo

  • Hotswap.patchAlgorithm

    LoadingtheNewClasses

  • UpdatingtheDataStructuresandPointers

  • LoadingtheNewClasses
    step1:Findallaffectedclasses.
    (VM_RedefineClasses::FindAffectedKlassesClosure)
    RedefiningDandB
    Findallaffectedclasses

  • LoadingtheNewClasses
    step2:Sorttheclassestopologically.
    (VM_RedefineClasses::TopologicalClassSorting)
    Topologicalorder.

  • UpdatingtheDataStructuresandPointers
    step1:Flushdependentcode.
    Currentlyallcompiledmethodsaredeoptimized
    (Classes::flush_dependent_code)

  • UpdatingtheDataStructuresandPointers
    step2:Updateconstantpoolcacheentries.
    (VM_RedefineClasses::adjust_cpool_cache)

  • UpdatingtheDataStructuresandPointers
    step3:Swappointers.
    利用gc的特性,gc復(fù)制一個對象的后會調(diào)整指向該對象的pointer
    (MarkSweep::adjust_pointer)

  • UpdatingtheDataStructuresandPointers
    step4:Updateinstancefields.
    allnewfieldsareinitializedtozero.(新建)
    instanceKlass::do_fields_evolution(標(biāo)記)
    MarkSweep::update_fields(拷貝)

  • Fantastic,but…

  • Hotswap@taobao.com

    HSF_JETTYplugin自動集成hotswap.patch。

    • 你也可以自己打patch。

  • Questiontime

  • Partytime謝謝!xuanxi@taobao.com

轉(zhuǎn)載于:https://blog.51cto.com/aliapp/1327693

總結(jié)

以上是生活随笔為你收集整理的Hotspot hotswap, who and who are best freinds的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。