You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hotswap.patch 1.1MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756
  1. diff -r f5603a6e5042 .hgignore
  2. --- a/.hgignore Wed Nov 17 22:42:08 2010 -0800
  3. +++ b/.hgignore Fri Dec 17 13:23:04 2010 +0100
  4. @@ -1,7 +1,27 @@
  5. -^build/
  6. -^dist/
  7. -/nbproject/private/
  8. -^src/share/tools/hsdis/build/
  9. -^src/share/tools/IdealGraphVisualizer/[a-zA-Z0-9]*/build/
  10. -^src/share/tools/IdealGraphVisualizer/build/
  11. -^src/share/tools/IdealGraphVisualizer/dist/
  12. +^build/
  13. +^work/
  14. +^work64/
  15. +^java/
  16. +^java64/
  17. +^dist/
  18. +^make/
  19. +build/
  20. +/nbproject/private/
  21. +^src/share/tools/hsdis/build/
  22. +private/
  23. +dist/
  24. +.toc$
  25. +.ps$
  26. +.dvi$
  27. +.aux$
  28. +.swp$
  29. +.dll$
  30. +.dylib$
  31. +.so$
  32. +.bak$
  33. +.orig$
  34. +~$
  35. +hotspot.log$
  36. +^src/share/tools/IdealGraphVisualizer/[a-zA-Z0-9]*/build/
  37. +^src/share/tools/IdealGraphVisualizer/build/
  38. +^src/share/tools/IdealGraphVisualizer/dist/
  39. diff -r f5603a6e5042 .hgtags
  40. --- a/.hgtags Wed Nov 17 22:42:08 2010 -0800
  41. +++ b/.hgtags Fri Dec 17 13:23:04 2010 +0100
  42. @@ -131,3 +131,7 @@
  43. 806d0c037e6bbb88dac0699673f4ba55ee8c02da jdk7-b117
  44. 698b7b727e12de44139d8cca6ab9a494ead13253 jdk7-b118
  45. 3ef7426b4deac5dcfd4afb35cabe9ab3d666df91 hs20-b02
  46. +946201493cab53f518c55272b6f27517a0ba4e0e build 0.1-b01
  47. +4425fe0d7f0ec7f8583ae687f7eb1b4a3e94ea09 build 0.1-b02
  48. +0c5e4a085baa8aaa9aed55b20810de4bdc2d6548 build 0.2-b01
  49. +34520cf6c532e28f529340f66f71855aadf83d95 build 0.2-b02
  50. diff -r f5603a6e5042 build.cmd
  51. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  52. +++ b/build.cmd Fri Dec 17 13:23:04 2010 +0100
  53. @@ -0,0 +1,12 @@
  54. +set HotSpotMksHome=C:\Cygwin\bin
  55. +set path=%JAVA_HOME%;C:\Cygwin\bin
  56. +call "%VS_VCVARS%\vsvars32.bat"
  57. +
  58. +set OrigPath=%cd%
  59. +cd make\windows
  60. +
  61. +call build.bat product compiler1 %OrigPath% %JAVA_HOME%
  62. +call build.bat fastdebug compiler1 %OrigPath% %JAVA_HOME%
  63. +
  64. +cd %OrigPath%
  65. +pause
  66. diff -r f5603a6e5042 create.cmd
  67. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  68. +++ b/create.cmd Fri Dec 17 13:23:04 2010 +0100
  69. @@ -0,0 +1,12 @@
  70. +set HotSpotMksHome=C:\Cygwin\bin
  71. +set path=%JAVA_HOME%\bin;C:\Cygwin\bin
  72. +call "%VS_VCVARS%\vsvars32.bat"
  73. +
  74. +set OrigPath=%cd%
  75. +cd make\windows
  76. +
  77. +mkdir %OrigPath%\work
  78. +call create.bat %OrigPath% %OrigPath%\work %OrigPath%\java
  79. +
  80. +cd %OrigPath%
  81. +pause
  82. diff -r f5603a6e5042 create64.cmd
  83. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  84. +++ b/create64.cmd Fri Dec 17 13:23:04 2010 +0100
  85. @@ -0,0 +1,14 @@
  86. +set HotSpotMksHome=C:\cygwin\bin
  87. +set JAVA_HOME=%cd%\java64
  88. +set ORIG_PATH=%PATH%
  89. +set path=%JAVA_HOME%\bin;%path%;C:\cygwin\bin
  90. +
  91. +set OrigPath=%cd%
  92. +cd make\windows
  93. +
  94. +mkdir %OrigPath%\work64
  95. +call create.bat %OrigPath% %OrigPath%\work64 %OrigPath%\java64
  96. +
  97. +set PATH=%ORIG_PATH%
  98. +cd %OrigPath%
  99. +pause
  100. diff -r f5603a6e5042 create_installers.cmd
  101. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  102. +++ b/create_installers.cmd Fri Dec 17 13:23:04 2010 +0100
  103. @@ -0,0 +1,11 @@
  104. +copy hotswapinstaller\Installer\dist\Installer.jar dcevm-mac.jar
  105. +jar uvf dcevm-mac.jar -C hotswapbinaries\mac\ .
  106. +jar uvf dcevm-mac.jar -C hotswapinstaller\Installer\dist data\dcevm.jar
  107. +
  108. +copy hotswapinstaller\Installer\dist\Installer.jar dcevm-win.jar
  109. +jar uvf dcevm-win.jar -C hotswapbinaries\win\ .
  110. +jar uvf dcevm-win.jar -C hotswapinstaller\Installer\dist data\dcevm.jar
  111. +
  112. +copy hotswapinstaller\Installer\dist\Installer.jar dcevm-linux.jar
  113. +jar uvf dcevm-linux.jar -C hotswapbinaries\linux\ .
  114. +jar uvf dcevm-linux.jar -C hotswapinstaller\Installer\dist data\dcevm.jar
  115. \ No newline at end of file
  116. diff -r f5603a6e5042 create_installers.sh
  117. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  118. +++ b/create_installers.sh Fri Dec 17 13:23:04 2010 +0100
  119. @@ -0,0 +1,11 @@
  120. +cp hotswapinstaller/Installer/dist/Installer.jar dcevm-mac.jar
  121. +jar uvf dcevm-mac.jar -C hotswapbinaries/mac/ .
  122. +jar uvf dcevm-mac.jar -C hotswapinstaller/Installer/dist data/dcevm.jar
  123. +
  124. +cp hotswapinstaller/Installer/dist/Installer.jar dcevm-win.jar
  125. +jar uvf dcevm-win.jar -C hotswapbinaries/win/ .
  126. +jar uvf dcevm-win.jar -C hotswapinstaller/Installer/dist data/dcevm.jar
  127. +
  128. +cp hotswapinstaller/Installer/dist/Installer.jar dcevm-linux.jar
  129. +jar uvf dcevm-linux.jar -C hotswapbinaries/linux/ .
  130. +jar uvf dcevm-linux.jar -C hotswapinstaller/Installer/dist data/dcevm.jar
  131. diff -r f5603a6e5042 create_patch_vm_only.cmd
  132. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  133. +++ b/create_patch_vm_only.cmd Fri Dec 17 13:23:04 2010 +0100
  134. @@ -0,0 +1,1 @@
  135. +hg diff -r 2039 -X hotswapdoc -X hotswaptest -X hotswapinstaller -X create_patch.cmd -X create_patch_vm_only.cmd >hotswapping_patch_vm_only
  136. \ No newline at end of file
  137. diff -r f5603a6e5042 hotswapbinaries/README
  138. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  139. +++ b/hotswapbinaries/README Fri Dec 17 13:23:04 2010 +0100
  140. @@ -0,0 +1,18 @@
  141. +The binary files are not stored in the mercurial repository, because they would bloat the repository size. The expected files in this subdirectory are:
  142. +
  143. +==========================================
  144. +Windows
  145. +win/data/64/bin/server/jvm.dll
  146. +win/data/bin/client/jvm.dll
  147. +win/data/bin/server/jvm.dll
  148. +
  149. +==========================================
  150. +Mac
  151. +mac/data/lib/i386/client/libjvm.dylib
  152. +mac/data/lib/i386/server/libjvm.dylib
  153. +
  154. +==========================================
  155. +Linux
  156. +linux/data/64/lib/amd64/server/libjvm.so
  157. +linux/data/lib/i386/client/libjvm.so
  158. +linux/data/lib/i386/server/libjvm.so
  159. diff -r f5603a6e5042 hotswapinstaller/Installer/build.xml
  160. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  161. +++ b/hotswapinstaller/Installer/build.xml Fri Dec 17 13:23:04 2010 +0100
  162. @@ -0,0 +1,96 @@
  163. +<?xml version="1.0" encoding="UTF-8"?>
  164. +<!-- You may freely edit this file. See commented blocks below for -->
  165. +<!-- some examples of how to customize the build. -->
  166. +<!-- (If you delete it and reopen the project it will be recreated.) -->
  167. +<!-- By default, only the Clean and Build commands use this build script. -->
  168. +<!-- Commands such as Run, Debug, and Test only use this build script if -->
  169. +<!-- the Compile on Save feature is turned off for the project. -->
  170. +<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
  171. +<!-- in the project's Project Properties dialog box.-->
  172. +<project name="Installer" default="default" basedir=".">
  173. + <description>Builds, tests, and runs the project Installer.</description>
  174. + <import file="nbproject/build-impl.xml"/>
  175. + <target name="-post-compile">
  176. + <property name="hotswapvm.dir" value="${build.classes.dir}/../../../.."/>
  177. + <!--
  178. + <copy file="${hotswapvm.dir}/hotswapbinaries/win/data/bin/client/jvm.dll" tofile="${build.classes.dir}/data/bin/client/jvm.dll"/>
  179. + <copy file="${hotswapvm.dir}/hotswapbinaries/win/data/bin/server/jvm.dll" tofile="${build.classes.dir}/data/bin/server/jvm.dll"/>
  180. + <copy file="${hotswapvm.dir}/hotswapbinaries/win/data/64/bin/server/jvm.dll" tofile="${build.classes.dir}/data/64/bin/server/jvm.dll"/>
  181. + <copy file="${hotswapvm.dir}/hotswapbinaries/mac/data/lib/i386/client/libjvm.dylib" tofile="${build.classes.dir}/data/lib/i386/client/libjvm.dylib"/>
  182. + <copy file="${hotswapvm.dir}/hotswapbinaries/mac/data/lib/i386/server/libjvm.dylib" tofile="${build.classes.dir}/data/lib/i386/server/libjvm.dylib"/>
  183. +-->
  184. +
  185. +
  186. + <jar destfile="dist/data/dcevm.jar">
  187. + <manifest>
  188. + <attribute name="Premain-Class" value="at.ssw.mixin.MixinAgent"/>
  189. + <attribute name="Can-Retransform-Classes" value="true"/>
  190. + </manifest>
  191. + <zipfileset src="${hotswapvm.dir}/hotswaptest/HotSwapTool/dist/HotSwapTool.jar" />
  192. + <zipfileset src="${hotswapvm.dir}/../Mixin/Mixin/dist/Mixin.jar" />
  193. + <zipfileset src="${hotswapvm.dir}/../Mixin/Mixin/dist/lib/asm-all-3.3.jar" />
  194. + </jar>
  195. +
  196. + </target>
  197. + <!--
  198. +
  199. + There exist several targets which are by default empty and which can be
  200. + used for execution of your tasks. These targets are usually executed
  201. + before and after some main targets. They are:
  202. +
  203. + -pre-init: called before initialization of project properties
  204. + -post-init: called after initialization of project properties
  205. + -pre-compile: called before javac compilation
  206. + -post-compile: called after javac compilation
  207. + -pre-compile-single: called before javac compilation of single file
  208. + -post-compile-single: called after javac compilation of single file
  209. + -pre-compile-test: called before javac compilation of JUnit tests
  210. + -post-compile-test: called after javac compilation of JUnit tests
  211. + -pre-compile-test-single: called before javac compilation of single JUnit test
  212. + -post-compile-test-single: called after javac compilation of single JUunit test
  213. + -pre-jar: called before JAR building
  214. + -post-jar: called after JAR building
  215. + -post-clean: called after cleaning build products
  216. +
  217. + (Targets beginning with '-' are not intended to be called on their own.)
  218. +
  219. + Example of inserting an obfuscator after compilation could look like this:
  220. +
  221. + <target name="-post-compile">
  222. + <obfuscate>
  223. + <fileset dir="${build.classes.dir}"/>
  224. + </obfuscate>
  225. + </target>
  226. +
  227. + For list of available properties check the imported
  228. + nbproject/build-impl.xml file.
  229. +
  230. +
  231. + Another way to customize the build is by overriding existing main targets.
  232. + The targets of interest are:
  233. +
  234. + -init-macrodef-javac: defines macro for javac compilation
  235. + -init-macrodef-junit: defines macro for junit execution
  236. + -init-macrodef-debug: defines macro for class debugging
  237. + -init-macrodef-java: defines macro for class execution
  238. + -do-jar-with-manifest: JAR building (if you are using a manifest)
  239. + -do-jar-without-manifest: JAR building (if you are not using a manifest)
  240. + run: execution of project
  241. + -javadoc-build: Javadoc generation
  242. + test-report: JUnit report generation
  243. +
  244. + An example of overriding the target for project execution could look like this:
  245. +
  246. + <target name="run" depends="Installer-impl.jar">
  247. + <exec dir="bin" executable="launcher.exe">
  248. + <arg file="${dist.jar}"/>
  249. + </exec>
  250. + </target>
  251. +
  252. + Notice that the overridden target depends on the jar target and not only on
  253. + the compile target as the regular run target does. Again, for a list of available
  254. + properties which you can use, check the target you are overriding in the
  255. + nbproject/build-impl.xml file.
  256. +
  257. + -->
  258. +</project>
  259. diff -r f5603a6e5042 hotswapinstaller/Installer/manifest.mf
  260. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  261. +++ b/hotswapinstaller/Installer/manifest.mf Fri Dec 17 13:23:04 2010 +0100
  262. @@ -0,0 +1,3 @@
  263. +Manifest-Version: 1.0
  264. +X-COMMENT: Main-Class will be added automatically by build
  265. +
  266. diff -r f5603a6e5042 hotswapinstaller/Installer/nbproject/build-impl.xml
  267. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  268. +++ b/hotswapinstaller/Installer/nbproject/build-impl.xml Fri Dec 17 13:23:04 2010 +0100
  269. @@ -0,0 +1,883 @@
  270. +<?xml version="1.0" encoding="UTF-8"?>
  271. +<!--
  272. +*** GENERATED FROM project.xml - DO NOT EDIT ***
  273. +*** EDIT ../build.xml INSTEAD ***
  274. +
  275. +For the purpose of easier reading the script
  276. +is divided into following sections:
  277. +
  278. + - initialization
  279. + - compilation
  280. + - jar
  281. + - execution
  282. + - debugging
  283. + - javadoc
  284. + - junit compilation
  285. + - junit execution
  286. + - junit debugging
  287. + - applet
  288. + - cleanup
  289. +
  290. + -->
  291. +<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="Installer-impl">
  292. + <fail message="Please build using Ant 1.7.1 or higher.">
  293. + <condition>
  294. + <not>
  295. + <antversion atleast="1.7.1"/>
  296. + </not>
  297. + </condition>
  298. + </fail>
  299. + <target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>
  300. + <!--
  301. + ======================
  302. + INITIALIZATION SECTION
  303. + ======================
  304. + -->
  305. + <target name="-pre-init">
  306. + <!-- Empty placeholder for easier customization. -->
  307. + <!-- You can override this target in the ../build.xml file. -->
  308. + </target>
  309. + <target depends="-pre-init" name="-init-private">
  310. + <property file="nbproject/private/config.properties"/>
  311. + <property file="nbproject/private/configs/${config}.properties"/>
  312. + <property file="nbproject/private/private.properties"/>
  313. + </target>
  314. + <target depends="-pre-init,-init-private" name="-init-user">
  315. + <property file="${user.properties.file}"/>
  316. + <!-- The two properties below are usually overridden -->
  317. + <!-- by the active platform. Just a fallback. -->
  318. + <property name="default.javac.source" value="1.4"/>
  319. + <property name="default.javac.target" value="1.4"/>
  320. + </target>
  321. + <target depends="-pre-init,-init-private,-init-user" name="-init-project">
  322. + <property file="nbproject/configs/${config}.properties"/>
  323. + <property file="nbproject/project.properties"/>
  324. + </target>
  325. + <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
  326. + <available file="${manifest.file}" property="manifest.available"/>
  327. + <available file="${application.splash}" property="splashscreen.available"/>
  328. + <condition property="main.class.available">
  329. + <and>
  330. + <isset property="main.class"/>
  331. + <not>
  332. + <equals arg1="${main.class}" arg2="" trim="true"/>
  333. + </not>
  334. + </and>
  335. + </condition>
  336. + <condition property="manifest.available+main.class">
  337. + <and>
  338. + <isset property="manifest.available"/>
  339. + <isset property="main.class.available"/>
  340. + </and>
  341. + </condition>
  342. + <condition property="do.mkdist">
  343. + <and>
  344. + <isset property="libs.CopyLibs.classpath"/>
  345. + <not>
  346. + <istrue value="${mkdist.disabled}"/>
  347. + </not>
  348. + </and>
  349. + </condition>
  350. + <condition property="manifest.available+main.class+mkdist.available">
  351. + <and>
  352. + <istrue value="${manifest.available+main.class}"/>
  353. + <isset property="do.mkdist"/>
  354. + </and>
  355. + </condition>
  356. + <condition property="manifest.available+main.class+mkdist.available+splashscreen.available">
  357. + <and>
  358. + <istrue value="${manifest.available+main.class+mkdist.available}"/>
  359. + <istrue value="${splashscreen.available}"/>
  360. + </and>
  361. + </condition>
  362. + <condition property="do.archive">
  363. + <not>
  364. + <istrue value="${jar.archive.disabled}"/>
  365. + </not>
  366. + </condition>
  367. + <condition property="do.archive+manifest.available">
  368. + <and>
  369. + <isset property="manifest.available"/>
  370. + <istrue value="${do.archive}"/>
  371. + </and>
  372. + </condition>
  373. + <condition property="do.archive+manifest.available+main.class">
  374. + <and>
  375. + <istrue value="${manifest.available+main.class}"/>
  376. + <istrue value="${do.archive}"/>
  377. + </and>
  378. + </condition>
  379. + <condition property="do.archive+manifest.available+main.class+mkdist.available">
  380. + <and>
  381. + <istrue value="${manifest.available+main.class+mkdist.available}"/>
  382. + <istrue value="${do.archive}"/>
  383. + </and>
  384. + </condition>
  385. + <condition property="do.archive+manifest.available+main.class+mkdist.available+splashscreen.available">
  386. + <and>
  387. + <istrue value="${manifest.available+main.class+mkdist.available+splashscreen.available}"/>
  388. + <istrue value="${do.archive}"/>
  389. + </and>
  390. + </condition>
  391. + <condition property="have.tests">
  392. + <or>
  393. + <available file="${test.src.dir}"/>
  394. + </or>
  395. + </condition>
  396. + <condition property="have.sources">
  397. + <or>
  398. + <available file="${src.dir}"/>
  399. + </or>
  400. + </condition>
  401. + <condition property="netbeans.home+have.tests">
  402. + <and>
  403. + <isset property="netbeans.home"/>
  404. + <isset property="have.tests"/>
  405. + </and>
  406. + </condition>
  407. + <condition property="no.javadoc.preview">
  408. + <and>
  409. + <isset property="javadoc.preview"/>
  410. + <isfalse value="${javadoc.preview}"/>
  411. + </and>
  412. + </condition>
  413. + <property name="run.jvmargs" value=""/>
  414. + <property name="javac.compilerargs" value=""/>
  415. + <property name="work.dir" value="${basedir}"/>
  416. + <condition property="no.deps">
  417. + <and>
  418. + <istrue value="${no.dependencies}"/>
  419. + </and>
  420. + </condition>
  421. + <property name="javac.debug" value="true"/>
  422. + <property name="javadoc.preview" value="true"/>
  423. + <property name="application.args" value=""/>
  424. + <property name="source.encoding" value="${file.encoding}"/>
  425. + <property name="runtime.encoding" value="${source.encoding}"/>
  426. + <condition property="javadoc.encoding.used" value="${javadoc.encoding}">
  427. + <and>
  428. + <isset property="javadoc.encoding"/>
  429. + <not>
  430. + <equals arg1="${javadoc.encoding}" arg2=""/>
  431. + </not>
  432. + </and>
  433. + </condition>
  434. + <property name="javadoc.encoding.used" value="${source.encoding}"/>
  435. + <property name="includes" value="**"/>
  436. + <property name="excludes" value=""/>
  437. + <property name="do.depend" value="false"/>
  438. + <condition property="do.depend.true">
  439. + <istrue value="${do.depend}"/>
  440. + </condition>
  441. + <path id="endorsed.classpath.path" path="${endorsed.classpath}"/>
  442. + <condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'">
  443. + <length length="0" string="${endorsed.classpath}" when="greater"/>
  444. + </condition>
  445. + <property name="javac.fork" value="false"/>
  446. + <property name="jar.index" value="false"/>
  447. + <available file="${meta.inf.dir}/persistence.xml" property="has.persistence.xml"/>
  448. + </target>
  449. + <target name="-post-init">
  450. + <!-- Empty placeholder for easier customization. -->
  451. + <!-- You can override this target in the ../build.xml file. -->
  452. + </target>
  453. + <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
  454. + <fail unless="src.dir">Must set src.dir</fail>
  455. + <fail unless="test.src.dir">Must set test.src.dir</fail>
  456. + <fail unless="build.dir">Must set build.dir</fail>
  457. + <fail unless="dist.dir">Must set dist.dir</fail>
  458. + <fail unless="build.classes.dir">Must set build.classes.dir</fail>
  459. + <fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
  460. + <fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail>
  461. + <fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
  462. + <fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
  463. + <fail unless="dist.jar">Must set dist.jar</fail>
  464. + </target>
  465. + <target name="-init-macrodef-property">
  466. + <macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1">
  467. + <attribute name="name"/>
  468. + <attribute name="value"/>
  469. + <sequential>
  470. + <property name="@{name}" value="${@{value}}"/>
  471. + </sequential>
  472. + </macrodef>
  473. + </target>
  474. + <target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-macrodef-javac-with-processors">
  475. + <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
  476. + <attribute default="${src.dir}" name="srcdir"/>
  477. + <attribute default="${build.classes.dir}" name="destdir"/>
  478. + <attribute default="${javac.classpath}" name="classpath"/>
  479. + <attribute default="${javac.processorpath}" name="processorpath"/>
  480. + <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/>
  481. + <attribute default="${includes}" name="includes"/>
  482. + <attribute default="${excludes}" name="excludes"/>
  483. + <attribute default="${javac.debug}" name="debug"/>
  484. + <attribute default="${empty.dir}" name="sourcepath"/>
  485. + <attribute default="${empty.dir}" name="gensrcdir"/>
  486. + <element name="customize" optional="true"/>
  487. + <sequential>
  488. + <property location="${build.dir}/empty" name="empty.dir"/>
  489. + <mkdir dir="${empty.dir}"/>
  490. + <mkdir dir="@{apgeneratedsrcdir}"/>
  491. + <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
  492. + <src>
  493. + <dirset dir="@{gensrcdir}" erroronmissingdir="false">
  494. + <include name="*"/>
  495. + </dirset>
  496. + </src>
  497. + <classpath>
  498. + <path path="@{classpath}"/>
  499. + </classpath>
  500. + <compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
  501. + <compilerarg line="${javac.compilerargs}"/>
  502. + <compilerarg value="-processorpath"/>
  503. + <compilerarg path="@{processorpath}:${empty.dir}"/>
  504. + <compilerarg line="${ap.processors.internal}"/>
  505. + <compilerarg line="${annotation.processing.processor.options}"/>
  506. + <compilerarg value="-s"/>
  507. + <compilerarg path="@{apgeneratedsrcdir}"/>
  508. + <compilerarg line="${ap.proc.none.internal}"/>
  509. + <customize/>
  510. + </javac>
  511. + </sequential>
  512. + </macrodef>
  513. + </target>
  514. + <target depends="-init-ap-cmdline-properties" name="-init-macrodef-javac-without-processors" unless="ap.supported.internal">
  515. + <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
  516. + <attribute default="${src.dir}" name="srcdir"/>
  517. + <attribute default="${build.classes.dir}" name="destdir"/>
  518. + <attribute default="${javac.classpath}" name="classpath"/>
  519. + <attribute default="${javac.processorpath}" name="processorpath"/>
  520. + <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/>
  521. + <attribute default="${includes}" name="includes"/>
  522. + <attribute default="${excludes}" name="excludes"/>
  523. + <attribute default="${javac.debug}" name="debug"/>
  524. + <attribute default="${empty.dir}" name="sourcepath"/>
  525. + <attribute default="${empty.dir}" name="gensrcdir"/>
  526. + <element name="customize" optional="true"/>
  527. + <sequential>
  528. + <property location="${build.dir}/empty" name="empty.dir"/>
  529. + <mkdir dir="${empty.dir}"/>
  530. + <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
  531. + <src>
  532. + <dirset dir="@{gensrcdir}" erroronmissingdir="false">
  533. + <include name="*"/>
  534. + </dirset>
  535. + </src>
  536. + <classpath>
  537. + <path path="@{classpath}"/>
  538. + </classpath>
  539. + <compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
  540. + <compilerarg line="${javac.compilerargs}"/>
  541. + <customize/>
  542. + </javac>
  543. + </sequential>
  544. + </macrodef>
  545. + </target>
  546. + <target depends="-init-macrodef-javac-with-processors,-init-macrodef-javac-without-processors" name="-init-macrodef-javac">
  547. + <macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
  548. + <attribute default="${src.dir}" name="srcdir"/>
  549. + <attribute default="${build.classes.dir}" name="destdir"/>
  550. + <attribute default="${javac.classpath}" name="classpath"/>
  551. + <sequential>
  552. + <depend cache="${build.dir}/depcache" destdir="@{destdir}" excludes="${excludes}" includes="${includes}" srcdir="@{srcdir}">
  553. + <classpath>
  554. + <path path="@{classpath}"/>
  555. + </classpath>
  556. + </depend>
  557. + </sequential>
  558. + </macrodef>
  559. + <macrodef name="force-recompile" uri="http://www.netbeans.org/ns/j2se-project/3">
  560. + <attribute default="${build.classes.dir}" name="destdir"/>
  561. + <sequential>
  562. + <fail unless="javac.includes">Must set javac.includes</fail>
  563. + <pathconvert pathsep="," property="javac.includes.binary">
  564. + <path>
  565. + <filelist dir="@{destdir}" files="${javac.includes}"/>
  566. + </path>
  567. + <globmapper from="*.java" to="*.class"/>
  568. + </pathconvert>
  569. + <delete>
  570. + <files includes="${javac.includes.binary}"/>
  571. + </delete>
  572. + </sequential>
  573. + </macrodef>
  574. + </target>
  575. + <target name="-init-macrodef-junit">
  576. + <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
  577. + <attribute default="${includes}" name="includes"/>
  578. + <attribute default="${excludes}" name="excludes"/>
  579. + <attribute default="**" name="testincludes"/>
  580. + <sequential>
  581. + <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" showoutput="true" tempdir="${build.dir}">
  582. + <batchtest todir="${build.test.results.dir}">
  583. + <fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
  584. + <filename name="@{testincludes}"/>
  585. + </fileset>
  586. + </batchtest>
  587. + <classpath>
  588. + <path path="${run.test.classpath}"/>
  589. + </classpath>
  590. + <syspropertyset>
  591. + <propertyref prefix="test-sys-prop."/>
  592. + <mapper from="test-sys-prop.*" to="*" type="glob"/>
  593. + </syspropertyset>
  594. + <formatter type="brief" usefile="false"/>
  595. + <formatter type="xml"/>
  596. + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
  597. + <jvmarg line="${run.jvmargs}"/>
  598. + </junit>
  599. + </sequential>
  600. + </macrodef>
  601. + </target>
  602. + <target depends="-init-debug-args" name="-init-macrodef-nbjpda">
  603. + <macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
  604. + <attribute default="${main.class}" name="name"/>
  605. + <attribute default="${debug.classpath}" name="classpath"/>
  606. + <attribute default="" name="stopclassname"/>
  607. + <sequential>
  608. + <nbjpdastart addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}" transport="${debug-transport}">
  609. + <classpath>
  610. + <path path="@{classpath}"/>
  611. + </classpath>
  612. + </nbjpdastart>
  613. + </sequential>
  614. + </macrodef>
  615. + <macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1">
  616. + <attribute default="${build.classes.dir}" name="dir"/>
  617. + <sequential>
  618. + <nbjpdareload>
  619. + <fileset dir="@{dir}" includes="${fix.classes}">
  620. + <include name="${fix.includes}*.class"/>
  621. + </fileset>
  622. + </nbjpdareload>
  623. + </sequential>
  624. + </macrodef>
  625. + </target>
  626. + <target name="-init-debug-args">
  627. + <property name="version-output" value="java version &quot;${ant.java.version}"/>
  628. + <condition property="have-jdk-older-than-1.4">
  629. + <or>
  630. + <contains string="${version-output}" substring="java version &quot;1.0"/>
  631. + <contains string="${version-output}" substring="java version &quot;1.1"/>
  632. + <contains string="${version-output}" substring="java version &quot;1.2"/>
  633. + <contains string="${version-output}" substring="java version &quot;1.3"/>
  634. + </or>
  635. + </condition>
  636. + <condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
  637. + <istrue value="${have-jdk-older-than-1.4}"/>
  638. + </condition>
  639. + <condition else="dt_socket" property="debug-transport-by-os" value="dt_shmem">
  640. + <os family="windows"/>
  641. + </condition>
  642. + <condition else="${debug-transport-by-os}" property="debug-transport" value="${debug.transport}">
  643. + <isset property="debug.transport"/>
  644. + </condition>
  645. + </target>
  646. + <target depends="-init-debug-args" name="-init-macrodef-debug">
  647. + <macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3">
  648. + <attribute default="${main.class}" name="classname"/>
  649. + <attribute default="${debug.classpath}" name="classpath"/>
  650. + <element name="customize" optional="true"/>
  651. + <sequential>
  652. + <java classname="@{classname}" dir="${work.dir}" fork="true">
  653. + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
  654. + <jvmarg line="${debug-args-line}"/>
  655. + <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
  656. + <jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
  657. + <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
  658. + <jvmarg line="${run.jvmargs}"/>
  659. + <classpath>
  660. + <path path="@{classpath}"/>
  661. + </classpath>
  662. + <syspropertyset>
  663. + <propertyref prefix="run-sys-prop."/>
  664. + <mapper from="run-sys-prop.*" to="*" type="glob"/>
  665. + </syspropertyset>
  666. + <customize/>
  667. + </java>
  668. + </sequential>
  669. + </macrodef>
  670. + </target>
  671. + <target name="-init-macrodef-java">
  672. + <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
  673. + <attribute default="${main.class}" name="classname"/>
  674. + <attribute default="${run.classpath}" name="classpath"/>
  675. + <element name="customize" optional="true"/>
  676. + <sequential>
  677. + <java classname="@{classname}" dir="${work.dir}" fork="true">
  678. + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
  679. + <jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
  680. + <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
  681. + <jvmarg line="${run.jvmargs}"/>
  682. + <classpath>
  683. + <path path="@{classpath}"/>
  684. + </classpath>
  685. + <syspropertyset>
  686. + <propertyref prefix="run-sys-prop."/>
  687. + <mapper from="run-sys-prop.*" to="*" type="glob"/>
  688. + </syspropertyset>
  689. + <customize/>
  690. + </java>
  691. + </sequential>
  692. + </macrodef>
  693. + </target>
  694. + <target name="-init-macrodef-copylibs">
  695. + <macrodef name="copylibs" uri="http://www.netbeans.org/ns/j2se-project/3">
  696. + <element name="customize" optional="true"/>
  697. + <sequential>
  698. + <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
  699. + <pathconvert property="run.classpath.without.build.classes.dir">
  700. + <path path="${run.classpath}"/>
  701. + <map from="${build.classes.dir.resolved}" to=""/>
  702. + </pathconvert>
  703. + <pathconvert pathsep=" " property="jar.classpath">
  704. + <path path="${run.classpath.without.build.classes.dir}"/>
  705. + <chainedmapper>
  706. + <flattenmapper/>
  707. + <globmapper from="*" to="lib/*"/>
  708. + </chainedmapper>
  709. + </pathconvert>
  710. + <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
  711. + <copylibs compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}" manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
  712. + <fileset dir="${build.classes.dir}"/>
  713. + <manifest>
  714. + <attribute name="Class-Path" value="${jar.classpath}"/>
  715. + <customize/>
  716. + </manifest>
  717. + </copylibs>
  718. + </sequential>
  719. + </macrodef>
  720. + </target>
  721. + <target name="-init-presetdef-jar">
  722. + <presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
  723. + <jar compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}">
  724. + <j2seproject1:fileset dir="${build.classes.dir}"/>
  725. + </jar>
  726. + </presetdef>
  727. + </target>
  728. + <target name="-init-ap-cmdline-properties">
  729. + <property name="annotation.processing.enabled" value="true"/>
  730. + <property name="annotation.processing.processors.list" value=""/>
  731. + <property name="annotation.processing.processor.options" value=""/>
  732. + <property name="annotation.processing.run.all.processors" value="true"/>
  733. + <property name="javac.processorpath" value="${javac.classpath}"/>
  734. + <property name="javac.test.processorpath" value="${javac.test.classpath}"/>
  735. + <condition property="ap.supported.internal" value="true">
  736. + <not>
  737. + <matches pattern="1\.[0-5](\..*)?" string="${javac.source}"/>
  738. + </not>
  739. + </condition>
  740. + </target>
  741. + <target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-ap-cmdline-supported">
  742. + <condition else="" property="ap.processors.internal" value="-processor ${annotation.processing.processors.list}">
  743. + <isfalse value="${annotation.processing.run.all.processors}"/>
  744. + </condition>
  745. + <condition else="" property="ap.proc.none.internal" value="-proc:none">
  746. + <isfalse value="${annotation.processing.enabled}"/>
  747. + </condition>
  748. + </target>
  749. + <target depends="-init-ap-cmdline-properties,-init-ap-cmdline-supported" name="-init-ap-cmdline">
  750. + <property name="ap.cmd.line.internal" value=""/>
  751. + </target>
  752. + <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar,-init-ap-cmdline" name="init"/>
  753. + <!--
  754. + ===================
  755. + COMPILATION SECTION
  756. + ===================
  757. + -->
  758. + <target name="-deps-jar-init" unless="built-jar.properties">
  759. + <property location="${build.dir}/built-jar.properties" name="built-jar.properties"/>
  760. + <delete file="${built-jar.properties}" quiet="true"/>
  761. + </target>
  762. + <target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
  763. + <echo level="warn" message="Cycle detected: Installer was already built"/>
  764. + </target>
  765. + <target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
  766. + <mkdir dir="${build.dir}"/>
  767. + <touch file="${built-jar.properties}" verbose="false"/>
  768. + <property file="${built-jar.properties}" prefix="already.built.jar."/>
  769. + <antcall target="-warn-already-built-jar"/>
  770. + <propertyfile file="${built-jar.properties}">
  771. + <entry key="${basedir}" value=""/>
  772. + </propertyfile>
  773. + </target>
  774. + <target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/>
  775. + <target depends="init" name="-check-automatic-build">
  776. + <available file="${build.classes.dir}/.netbeans_automatic_build" property="netbeans.automatic.build"/>
  777. + </target>
  778. + <target depends="init" if="netbeans.automatic.build" name="-clean-after-automatic-build">
  779. + <antcall target="clean"/>
  780. + </target>
  781. + <target depends="init,deps-jar" name="-pre-pre-compile">
  782. + <mkdir dir="${build.classes.dir}"/>
  783. + </target>
  784. + <target name="-pre-compile">
  785. + <!-- Empty placeholder for easier customization. -->
  786. + <!-- You can override this target in the ../build.xml file. -->
  787. + </target>
  788. + <target if="do.depend.true" name="-compile-depend">
  789. + <pathconvert property="build.generated.subdirs">
  790. + <dirset dir="${build.generated.sources.dir}" erroronmissingdir="false">
  791. + <include name="*"/>
  792. + </dirset>
  793. + </pathconvert>
  794. + <j2seproject3:depend srcdir="${src.dir}:${build.generated.subdirs}"/>
  795. + </target>
  796. + <target depends="init,deps-jar,-pre-pre-compile,-pre-compile, -copy-persistence-xml,-compile-depend" if="have.sources" name="-do-compile">
  797. + <j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/>
  798. + <copy todir="${build.classes.dir}">
  799. + <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
  800. + </copy>
  801. + </target>
  802. + <target if="has.persistence.xml" name="-copy-persistence-xml">
  803. + <mkdir dir="${build.classes.dir}/META-INF"/>
  804. + <copy todir="${build.classes.dir}/META-INF">
  805. + <fileset dir="${meta.inf.dir}" includes="persistence.xml"/>
  806. + </copy>
  807. + </target>
  808. + <target name="-post-compile">
  809. + <!-- Empty placeholder for easier customization. -->
  810. + <!-- You can override this target in the ../build.xml file. -->
  811. + </target>
  812. + <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project." name="compile"/>
  813. + <target name="-pre-compile-single">
  814. + <!-- Empty placeholder for easier customization. -->
  815. + <!-- You can override this target in the ../build.xml file. -->
  816. + </target>
  817. + <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
  818. + <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
  819. + <j2seproject3:force-recompile/>
  820. + <j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}" sourcepath="${src.dir}"/>
  821. + </target>
  822. + <target name="-post-compile-single">
  823. + <!-- Empty placeholder for easier customization. -->
  824. + <!-- You can override this target in the ../build.xml file. -->
  825. + </target>
  826. + <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/>
  827. + <!--
  828. + ====================
  829. + JAR BUILDING SECTION
  830. + ====================
  831. + -->
  832. + <target depends="init" name="-pre-pre-jar">
  833. + <dirname file="${dist.jar}" property="dist.jar.dir"/>
  834. + <mkdir dir="${dist.jar.dir}"/>
  835. + </target>
  836. + <target name="-pre-jar">
  837. + <!-- Empty placeholder for easier customization. -->
  838. + <!-- You can override this target in the ../build.xml file. -->
  839. + </target>
  840. + <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive" name="-do-jar-without-manifest" unless="manifest.available">
  841. + <j2seproject1:jar/>
  842. + </target>
  843. + <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available" name="-do-jar-with-manifest" unless="manifest.available+main.class">
  844. + <j2seproject1:jar manifest="${manifest.file}"/>
  845. + </target>
  846. + <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available+main.class" name="-do-jar-with-mainclass" unless="manifest.available+main.class+mkdist.available">
  847. + <j2seproject1:jar manifest="${manifest.file}">
  848. + <j2seproject1:manifest>
  849. + <j2seproject1:attribute name="Main-Class" value="${main.class}"/>
  850. + </j2seproject1:manifest>
  851. + </j2seproject1:jar>
  852. + <echo>To run this application from the command line without Ant, try:</echo>
  853. + <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
  854. + <property location="${dist.jar}" name="dist.jar.resolved"/>
  855. + <pathconvert property="run.classpath.with.dist.jar">
  856. + <path path="${run.classpath}"/>
  857. + <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
  858. + </pathconvert>
  859. + <echo>java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
  860. + </target>
  861. + <target depends="init,compile,-pre-pre-jar,-pre-jar,-init-macrodef-copylibs" if="do.archive+manifest.available+main.class+mkdist.available+splashscreen.available" name="-do-jar-with-libraries-and-splashscreen">
  862. + <basename file="${application.splash}" property="splashscreen.basename"/>
  863. + <mkdir dir="${build.classes.dir}/META-INF"/>
  864. + <copy failonerror="false" file="${application.splash}" todir="${build.classes.dir}/META-INF"/>
  865. + <j2seproject3:copylibs>
  866. + <customize>
  867. + <attribute name="Main-Class" value="${main.class}"/>
  868. + <attribute name="SplashScreen-Image" value="META-INF/${splashscreen.basename}"/>
  869. + </customize>
  870. + </j2seproject3:copylibs>
  871. + <echo>To run this application from the command line without Ant, try:</echo>
  872. + <property location="${dist.jar}" name="dist.jar.resolved"/>
  873. + <echo>java -jar "${dist.jar.resolved}"</echo>
  874. + </target>
  875. + <target depends="init,compile,-pre-pre-jar,-pre-jar,-init-macrodef-copylibs" if="do.archive+manifest.available+main.class+mkdist.available" name="-do-jar-with-libraries" unless="splashscreen.available">
  876. + <j2seproject3:copylibs>
  877. + <customize>
  878. + <attribute name="Main-Class" value="${main.class}"/>
  879. + </customize>
  880. + </j2seproject3:copylibs>
  881. + <echo>To run this application from the command line without Ant, try:</echo>
  882. + <property location="${dist.jar}" name="dist.jar.resolved"/>
  883. + <echo>java -jar "${dist.jar.resolved}"</echo>
  884. + </target>
  885. + <target name="-post-jar">
  886. + <!-- Empty placeholder for easier customization. -->
  887. + <!-- You can override this target in the ../build.xml file. -->
  888. + </target>
  889. + <target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries-and-splashscreen,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/>
  890. + <!--
  891. + =================
  892. + EXECUTION SECTION
  893. + =================
  894. + -->
  895. + <target depends="init,compile" description="Run a main class." name="run">
  896. + <j2seproject1:java>
  897. + <customize>
  898. + <arg line="${application.args}"/>
  899. + </customize>
  900. + </j2seproject1:java>
  901. + </target>
  902. + <target name="-do-not-recompile">
  903. + <property name="javac.includes.binary" value=""/>
  904. + </target>
  905. + <target depends="init,compile-single" name="run-single">
  906. + <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
  907. + <j2seproject1:java classname="${run.class}"/>
  908. + </target>
  909. + <target depends="init,compile-test-single" name="run-test-with-main">
  910. + <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
  911. + <j2seproject1:java classname="${run.class}" classpath="${run.test.classpath}"/>
  912. + </target>
  913. + <!--
  914. + =================
  915. + DEBUGGING SECTION
  916. + =================
  917. + -->
  918. + <target depends="init" if="netbeans.home" name="-debug-start-debugger">
  919. + <j2seproject1:nbjpdastart name="${debug.class}"/>
  920. + </target>
  921. + <target depends="init" if="netbeans.home" name="-debug-start-debugger-main-test">
  922. + <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${debug.class}"/>
  923. + </target>
  924. + <target depends="init,compile" name="-debug-start-debuggee">
  925. + <j2seproject3:debug>
  926. + <customize>
  927. + <arg line="${application.args}"/>
  928. + </customize>
  929. + </j2seproject3:debug>
  930. + </target>
  931. + <target depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE." if="netbeans.home" name="debug"/>
  932. + <target depends="init" if="netbeans.home" name="-debug-start-debugger-stepinto">
  933. + <j2seproject1:nbjpdastart stopclassname="${main.class}"/>
  934. + </target>
  935. + <target depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee" if="netbeans.home" name="debug-stepinto"/>
  936. + <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-single">
  937. + <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
  938. + <j2seproject3:debug classname="${debug.class}"/>
  939. + </target>
  940. + <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single"/>
  941. + <target depends="init,compile-test-single" if="netbeans.home" name="-debug-start-debuggee-main-test">
  942. + <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
  943. + <j2seproject3:debug classname="${debug.class}" classpath="${debug.test.classpath}"/>
  944. + </target>
  945. + <target depends="init,compile-test-single,-debug-start-debugger-main-test,-debug-start-debuggee-main-test" if="netbeans.home" name="debug-test-with-main"/>
  946. + <target depends="init" name="-pre-debug-fix">
  947. + <fail unless="fix.includes">Must set fix.includes</fail>
  948. + <property name="javac.includes" value="${fix.includes}.java"/>
  949. + </target>
  950. + <target depends="init,-pre-debug-fix,compile-single" if="netbeans.home" name="-do-debug-fix">
  951. + <j2seproject1:nbjpdareload/>
  952. + </target>
  953. + <target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/>
  954. + <!--
  955. + ===============
  956. + JAVADOC SECTION
  957. + ===============
  958. + -->
  959. + <target depends="init" if="have.sources" name="-javadoc-build">
  960. + <mkdir dir="${dist.javadoc.dir}"/>
  961. + <javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
  962. + <classpath>
  963. + <path path="${javac.classpath}"/>
  964. + </classpath>
  965. + <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
  966. + <filename name="**/*.java"/>
  967. + </fileset>
  968. + <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
  969. + <include name="**/*.java"/>
  970. + </fileset>
  971. + </javadoc>
  972. + </target>
  973. + <target depends="init,-javadoc-build" if="netbeans.home" name="-javadoc-browse" unless="no.javadoc.preview">
  974. + <nbbrowse file="${dist.javadoc.dir}/index.html"/>
  975. + </target>
  976. + <target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/>
  977. + <!--
  978. + =========================
  979. + JUNIT COMPILATION SECTION
  980. + =========================
  981. + -->
  982. + <target depends="init,compile" if="have.tests" name="-pre-pre-compile-test">
  983. + <mkdir dir="${build.test.classes.dir}"/>
  984. + </target>
  985. + <target name="-pre-compile-test">
  986. + <!-- Empty placeholder for easier customization. -->
  987. + <!-- You can override this target in the ../build.xml file. -->
  988. + </target>
  989. + <target if="do.depend.true" name="-compile-test-depend">
  990. + <j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/>
  991. + </target>
  992. + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test">
  993. + <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" processorpath="${javac.test.processorpath}" srcdir="${test.src.dir}"/>
  994. + <copy todir="${build.test.classes.dir}">
  995. + <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
  996. + </copy>
  997. + </target>
  998. + <target name="-post-compile-test">
  999. + <!-- Empty placeholder for easier customization. -->
  1000. + <!-- You can override this target in the ../build.xml file. -->
  1001. + </target>
  1002. + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test" name="compile-test"/>
  1003. + <target name="-pre-compile-test-single">
  1004. + <!-- Empty placeholder for easier customization. -->
  1005. + <!-- You can override this target in the ../build.xml file. -->
  1006. + </target>
  1007. + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single">
  1008. + <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
  1009. + <j2seproject3:force-recompile destdir="${build.test.classes.dir}"/>
  1010. + <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" processorpath="${javac.test.processorpath}" sourcepath="${test.src.dir}" srcdir="${test.src.dir}"/>
  1011. + <copy todir="${build.test.classes.dir}">
  1012. + <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
  1013. + </copy>
  1014. + </target>
  1015. + <target name="-post-compile-test-single">
  1016. + <!-- Empty placeholder for easier customization. -->
  1017. + <!-- You can override this target in the ../build.xml file. -->
  1018. + </target>
  1019. + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/>
  1020. + <!--
  1021. + =======================
  1022. + JUNIT EXECUTION SECTION
  1023. + =======================
  1024. + -->
  1025. + <target depends="init" if="have.tests" name="-pre-test-run">
  1026. + <mkdir dir="${build.test.results.dir}"/>
  1027. + </target>
  1028. + <target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run">
  1029. + <j2seproject3:junit testincludes="**/*Test.java"/>
  1030. + </target>
  1031. + <target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run">
  1032. + <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
  1033. + </target>
  1034. + <target depends="init" if="have.tests" name="test-report"/>
  1035. + <target depends="init" if="netbeans.home+have.tests" name="-test-browse"/>
  1036. + <target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests." name="test"/>
  1037. + <target depends="init" if="have.tests" name="-pre-test-run-single">
  1038. + <mkdir dir="${build.test.results.dir}"/>
  1039. + </target>
  1040. + <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single">
  1041. + <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
  1042. + <j2seproject3:junit excludes="" includes="${test.includes}"/>
  1043. + </target>
  1044. + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single">
  1045. + <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
  1046. + </target>
  1047. + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/>
  1048. + <!--
  1049. + =======================
  1050. + JUNIT DEBUGGING SECTION
  1051. + =======================
  1052. + -->
  1053. + <target depends="init,compile-test" if="have.tests" name="-debug-start-debuggee-test">
  1054. + <fail unless="test.class">Must select one file in the IDE or set test.class</fail>
  1055. + <property location="${build.test.results.dir}/TEST-${test.class}.xml" name="test.report.file"/>
  1056. + <delete file="${test.report.file}"/>
  1057. + <mkdir dir="${build.test.results.dir}"/>
  1058. + <j2seproject3:debug classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" classpath="${ant.home}/lib/ant.jar:${ant.home}/lib/ant-junit.jar:${debug.test.classpath}">
  1059. + <customize>
  1060. + <syspropertyset>
  1061. + <propertyref prefix="test-sys-prop."/>
  1062. + <mapper from="test-sys-prop.*" to="*" type="glob"/>
  1063. + </syspropertyset>
  1064. + <arg value="${test.class}"/>
  1065. + <arg value="showoutput=true"/>
  1066. + <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter"/>
  1067. + <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,${test.report.file}"/>
  1068. + </customize>
  1069. + </j2seproject3:debug>
  1070. + </target>
  1071. + <target depends="init,compile-test" if="netbeans.home+have.tests" name="-debug-start-debugger-test">
  1072. + <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${test.class}"/>
  1073. + </target>
  1074. + <target depends="init,compile-test-single,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/>
  1075. + <target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test">
  1076. + <j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
  1077. + </target>
  1078. + <target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/>
  1079. + <!--
  1080. + =========================
  1081. + APPLET EXECUTION SECTION
  1082. + =========================
  1083. + -->
  1084. + <target depends="init,compile-single" name="run-applet">
  1085. + <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
  1086. + <j2seproject1:java classname="sun.applet.AppletViewer">
  1087. + <customize>
  1088. + <arg value="${applet.url}"/>
  1089. + </customize>
  1090. + </j2seproject1:java>
  1091. + </target>
  1092. + <!--
  1093. + =========================
  1094. + APPLET DEBUGGING SECTION
  1095. + =========================
  1096. + -->
  1097. + <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-applet">
  1098. + <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
  1099. + <j2seproject3:debug classname="sun.applet.AppletViewer">
  1100. + <customize>
  1101. + <arg value="${applet.url}"/>
  1102. + </customize>
  1103. + </j2seproject3:debug>
  1104. + </target>
  1105. + <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet" if="netbeans.home" name="debug-applet"/>
  1106. + <!--
  1107. + ===============
  1108. + CLEANUP SECTION
  1109. + ===============
  1110. + -->
  1111. + <target name="-deps-clean-init" unless="built-clean.properties">
  1112. + <property location="${build.dir}/built-clean.properties" name="built-clean.properties"/>
  1113. + <delete file="${built-clean.properties}" quiet="true"/>
  1114. + </target>
  1115. + <target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
  1116. + <echo level="warn" message="Cycle detected: Installer was already built"/>
  1117. + </target>
  1118. + <target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
  1119. + <mkdir dir="${build.dir}"/>
  1120. + <touch file="${built-clean.properties}" verbose="false"/>
  1121. + <property file="${built-clean.properties}" prefix="already.built.clean."/>
  1122. + <antcall target="-warn-already-built-clean"/>
  1123. + <propertyfile file="${built-clean.properties}">
  1124. + <entry key="${basedir}" value=""/>
  1125. + </propertyfile>
  1126. + </target>
  1127. + <target depends="init" name="-do-clean">
  1128. + <delete dir="${build.dir}"/>
  1129. + <delete dir="${dist.dir}" followsymlinks="false" includeemptydirs="true"/>
  1130. + </target>
  1131. + <target name="-post-clean">
  1132. + <!-- Empty placeholder for easier customization. -->
  1133. + <!-- You can override this target in the ../build.xml file. -->
  1134. + </target>
  1135. + <target depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products." name="clean"/>
  1136. + <target name="-check-call-dep">
  1137. + <property file="${call.built.properties}" prefix="already.built."/>
  1138. + <condition property="should.call.dep">
  1139. + <not>
  1140. + <isset property="already.built.${call.subproject}"/>
  1141. + </not>
  1142. + </condition>
  1143. + </target>
  1144. + <target depends="-check-call-dep" if="should.call.dep" name="-maybe-call-dep">
  1145. + <ant antfile="${call.script}" inheritall="false" target="${call.target}">
  1146. + <propertyset>
  1147. + <propertyref prefix="transfer."/>
  1148. + <mapper from="transfer.*" to="*" type="glob"/>
  1149. + </propertyset>
  1150. + </ant>
  1151. + </target>
  1152. +</project>
  1153. diff -r f5603a6e5042 hotswapinstaller/Installer/nbproject/project.properties
  1154. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  1155. +++ b/hotswapinstaller/Installer/nbproject/project.properties Fri Dec 17 13:23:04 2010 +0100
  1156. @@ -0,0 +1,63 @@
  1157. +build.classes.dir=${build.dir}/classes
  1158. +build.classes.excludes=**/*.java,**/*.form
  1159. +# This directory is removed when the project is cleaned:
  1160. +build.dir=build
  1161. +build.generated.dir=${build.dir}/generated
  1162. +build.generated.sources.dir=${build.dir}/generated-sources
  1163. +# Only compile against the classpath explicitly listed here:
  1164. +build.sysclasspath=ignore
  1165. +build.test.classes.dir=${build.dir}/test/classes
  1166. +build.test.results.dir=${build.dir}/test/results
  1167. +# Uncomment to specify the preferred debugger connection transport:
  1168. +#debug.transport=dt_socket
  1169. +debug.classpath=\
  1170. + ${run.classpath}
  1171. +debug.test.classpath=\
  1172. + ${run.test.classpath}
  1173. +# This directory is removed when the project is cleaned:
  1174. +dist.dir=dist
  1175. +dist.jar=${dist.dir}/Installer.jar
  1176. +dist.javadoc.dir=${dist.dir}/javadoc
  1177. +excludes=
  1178. +includes=**
  1179. +jar.compress=false
  1180. +javac.classpath=
  1181. +# Space-separated list of extra javac options
  1182. +javac.compilerargs=
  1183. +javac.deprecation=false
  1184. +javac.source=1.5
  1185. +javac.target=1.5
  1186. +javac.test.classpath=\
  1187. + ${javac.classpath}:\
  1188. + ${build.classes.dir}:\
  1189. + ${libs.junit.classpath}:\
  1190. + ${libs.junit_4.classpath}
  1191. +javadoc.additionalparam=
  1192. +javadoc.author=false
  1193. +javadoc.encoding=${source.encoding}
  1194. +javadoc.noindex=false
  1195. +javadoc.nonavbar=false
  1196. +javadoc.notree=false
  1197. +javadoc.private=false
  1198. +javadoc.splitindex=true
  1199. +javadoc.use=true
  1200. +javadoc.version=false
  1201. +javadoc.windowtitle=
  1202. +jaxbwiz.endorsed.dirs="${netbeans.home}/../ide12/modules/ext/jaxb/api"
  1203. +main.class=at.ssw.hotswap.installer.Main
  1204. +manifest.file=manifest.mf
  1205. +meta.inf.dir=${src.dir}/META-INF
  1206. +platform.active=default_platform
  1207. +run.classpath=\
  1208. + ${javac.classpath}:\
  1209. + ${build.classes.dir}
  1210. +# Space-separated list of JVM arguments used when running the project
  1211. +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
  1212. +# or test-sys-prop.name=value to set system properties for unit tests):
  1213. +run.jvmargs=
  1214. +run.test.classpath=\
  1215. + ${javac.test.classpath}:\
  1216. + ${build.test.classes.dir}
  1217. +source.encoding=UTF-8
  1218. +src.dir=src
  1219. +test.src.dir=test
  1220. diff -r f5603a6e5042 hotswapinstaller/Installer/nbproject/project.xml
  1221. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  1222. +++ b/hotswapinstaller/Installer/nbproject/project.xml Fri Dec 17 13:23:04 2010 +0100
  1223. @@ -0,0 +1,15 @@
  1224. +<?xml version="1.0" encoding="UTF-8"?>
  1225. +<project xmlns="http://www.netbeans.org/ns/project/1">
  1226. + <type>org.netbeans.modules.java.j2seproject</type>
  1227. + <configuration>
  1228. + <data xmlns="http://www.netbeans.org/ns/j2se-project/3">
  1229. + <name>Installer</name>
  1230. + <source-roots>
  1231. + <root id="src.dir"/>
  1232. + </source-roots>
  1233. + <test-roots>
  1234. + <root id="test.src.dir"/>
  1235. + </test-roots>
  1236. + </data>
  1237. + </configuration>
  1238. +</project>
  1239. diff -r f5603a6e5042 hotswapinstaller/Installer/src/at/ssw/hotswap/installer/Installation.java
  1240. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  1241. +++ b/hotswapinstaller/Installer/src/at/ssw/hotswap/installer/Installation.java Fri Dec 17 13:23:04 2010 +0100
  1242. @@ -0,0 +1,137 @@
  1243. +/*
  1244. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  1245. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  1246. + *
  1247. + * This code is free software; you can redistribute it and/or modify it
  1248. + * under the terms of the GNU General Public License version 2 only, as
  1249. + * published by the Free Software Foundation.
  1250. + *
  1251. + * This code is distributed in the hope that it will be useful, but WITHOUT
  1252. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1253. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1254. + * version 2 for more details (a copy is included in the LICENSE file that
  1255. + * accompanied this code).
  1256. + *
  1257. + * You should have received a copy of the GNU General Public License version
  1258. + * 2 along with this work; if not, write to the Free Software Foundation,
  1259. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  1260. + *
  1261. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  1262. + * or visit www.oracle.com if you need additional information or have any
  1263. + * questions.
  1264. + *
  1265. + */
  1266. +package at.ssw.hotswap.installer;
  1267. +
  1268. +import java.io.File;
  1269. +import java.io.IOException;
  1270. +import java.util.Observable;
  1271. +
  1272. +/**
  1273. + * @author Kerstin Breiteneder
  1274. + * @author Christoph Wimberger
  1275. + */
  1276. +public class Installation extends Observable {
  1277. +
  1278. + private final File file;
  1279. + private final boolean isJDK;
  1280. + private final Installer installer;
  1281. + private boolean installed;
  1282. + private String version;
  1283. + private String dceVersion;
  1284. + private boolean is64Bit;
  1285. +
  1286. + public Installation(File f, Installer i) throws InstallerException {
  1287. + installer = i;
  1288. + try {
  1289. + file = f.getCanonicalFile();
  1290. + } catch (IOException ex) {
  1291. + throw new InstallerException(f.getAbsolutePath() + " is no JRE or JDK-directory.");
  1292. + }
  1293. + isJDK = installer.isJDK(file);
  1294. + if (!isJDK && !installer.isJRE(file)) {
  1295. + throw new InstallerException(f.getAbsolutePath() + " is no JRE or JDK-directory.");
  1296. + }
  1297. +
  1298. + version = installer.getJavaVersion(file);
  1299. + update();
  1300. + }
  1301. +
  1302. + final public void update() throws InstallerException {
  1303. + installed = installer.isDCEInstalled(file);
  1304. + if (installed) {
  1305. + dceVersion = installer.getDCEVersion(file);
  1306. + }
  1307. + is64Bit = installer.is64Bit(file);
  1308. + }
  1309. +
  1310. + public File getPath() {
  1311. + return file;
  1312. + }
  1313. +
  1314. + public String getVersion() {
  1315. + return version;
  1316. + }
  1317. +
  1318. + public String getDCEVersion() {
  1319. + return dceVersion;
  1320. + }
  1321. +
  1322. + public boolean isJDK() {
  1323. + return isJDK;
  1324. + }
  1325. +
  1326. + public boolean is64Bit() {
  1327. + return is64Bit;
  1328. + }
  1329. +
  1330. + public void installDCE() throws InstallerException {
  1331. + try {
  1332. + installer.install(file, is64Bit);
  1333. + } catch (InstallerException ex) {
  1334. + throw new InstallerException("Could not install DCE to " + file.getAbsolutePath() + ".", ex);
  1335. + }
  1336. + installed = true;
  1337. + update();
  1338. + setChanged();
  1339. + notifyObservers();
  1340. + }
  1341. +
  1342. + public void uninstallDCE() throws InstallerException {
  1343. + try {
  1344. + installer.uninstall(file, is64Bit);
  1345. + } catch (InstallerException ex) {
  1346. + throw new InstallerException("Could not uninstall DCE to " + file.getAbsolutePath() + ".", ex);
  1347. + }
  1348. + installed = false;
  1349. + update();
  1350. + setChanged();
  1351. + notifyObservers();
  1352. + }
  1353. +
  1354. + public boolean isDCEInstalled() {
  1355. + return installed;
  1356. + }
  1357. +
  1358. + @Override
  1359. + public boolean equals(Object obj) {
  1360. + if (obj == null) {
  1361. + return false;
  1362. + }
  1363. + if (getClass() != obj.getClass()) {
  1364. + return false;
  1365. + }
  1366. + final Installation other = (Installation) obj;
  1367. + if (this.file != other.file && (this.file == null || !this.file.equals(other.file))) {
  1368. + return false;
  1369. + }
  1370. + return true;
  1371. + }
  1372. +
  1373. + @Override
  1374. + public int hashCode() {
  1375. + int hash = 5;
  1376. + hash = 97 * hash + (this.file != null ? this.file.hashCode() : 0);
  1377. + return hash;
  1378. + }
  1379. +}
  1380. diff -r f5603a6e5042 hotswapinstaller/Installer/src/at/ssw/hotswap/installer/Installer.java
  1381. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  1382. +++ b/hotswapinstaller/Installer/src/at/ssw/hotswap/installer/Installer.java Fri Dec 17 13:23:04 2010 +0100
  1383. @@ -0,0 +1,359 @@
  1384. +/*
  1385. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  1386. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  1387. + *
  1388. + * This code is free software; you can redistribute it and/or modify it
  1389. + * under the terms of the GNU General Public License version 2 only, as
  1390. + * published by the Free Software Foundation.
  1391. + *
  1392. + * This code is distributed in the hope that it will be useful, but WITHOUT
  1393. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1394. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1395. + * version 2 for more details (a copy is included in the LICENSE file that
  1396. + * accompanied this code).
  1397. + *
  1398. + * You should have received a copy of the GNU General Public License version
  1399. + * 2 along with this work; if not, write to the Free Software Foundation,
  1400. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  1401. + *
  1402. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  1403. + * or visit www.oracle.com if you need additional information or have any
  1404. + * questions.
  1405. + *
  1406. + */
  1407. +package at.ssw.hotswap.installer;
  1408. +
  1409. +import java.io.BufferedReader;
  1410. +import java.io.File;
  1411. +import java.io.FileOutputStream;
  1412. +import java.io.IOException;
  1413. +import java.io.InputStream;
  1414. +import java.io.InputStreamReader;
  1415. +import java.util.ArrayList;
  1416. +import java.util.Arrays;
  1417. +import java.util.List;
  1418. +import java.util.logging.Level;
  1419. +import java.util.logging.Logger;
  1420. +import java.util.regex.Matcher;
  1421. +import java.util.regex.Pattern;
  1422. +
  1423. +/**
  1424. + * @author Kerstin Breiteneder
  1425. + * @author Christoph Wimberger
  1426. + */
  1427. +public abstract class Installer {
  1428. +
  1429. + public String getJREDirectory() {
  1430. + return "jre";
  1431. + }
  1432. +
  1433. + public String getBackupLibraryName() {
  1434. + return getLibraryName() + ".backup";
  1435. + }
  1436. +
  1437. + public String getTemporaryLibraryName() {
  1438. + return getLibraryName() + ".temp";
  1439. + }
  1440. +
  1441. + public abstract String getClientDirectory();
  1442. +
  1443. + public abstract String getServerDirectory(boolean is64bit);
  1444. +
  1445. + public abstract String getLibraryName();
  1446. +
  1447. + public abstract String getJavaExecutable();
  1448. +
  1449. + public abstract List<Installation> listAllInstallations();
  1450. +
  1451. + public static Installer create() throws InstallerException {
  1452. +
  1453. + String os = System.getProperty("os.name").toLowerCase();
  1454. +
  1455. + if (os.contains("windows")) {
  1456. + return new WindowsInstaller();
  1457. + } else if (os.contains("mac") || os.contains("darwin")) {
  1458. + return new MacInstaller();
  1459. + } else if (os.contains("unix") || os.contains("linux")) {
  1460. + return new LinuxInstaller();
  1461. + }
  1462. + throw new InstallerException("Unknown OS is unsupported.");
  1463. + }
  1464. +
  1465. + final protected void extractFile(String jarpath, String dest) throws InstallerException {
  1466. + boolean fileCreated = false;
  1467. + FileOutputStream output = null;
  1468. + InputStream in = Main.class.getClassLoader().getResourceAsStream(jarpath);
  1469. + if (in == null) {
  1470. + throw new InstallerException("Could not find " + jarpath + " in jar-file.");
  1471. + }
  1472. +
  1473. + boolean failure = false;
  1474. + try {
  1475. + output = new FileOutputStream(dest);
  1476. + fileCreated = true;
  1477. + int len = 0;
  1478. + byte[] cur = new byte[102400];
  1479. + while ((len = in.read(cur)) != -1) {
  1480. + output.write(cur, 0, len);
  1481. + }
  1482. + } catch (Exception ex) {
  1483. + failure = true;
  1484. + throw new InstallerException("Could not extract file " + dest + ".", ex);
  1485. + } finally {
  1486. + if (output != null) {
  1487. + try {
  1488. + output.close();
  1489. + } catch (Exception e) {
  1490. + }
  1491. + }
  1492. + if (failure && fileCreated) {
  1493. + deleteFile(dest);
  1494. + }
  1495. + }
  1496. + }
  1497. +
  1498. + public void install(File dir, boolean bit64) throws InstallerException {
  1499. + if (isJDK(dir)) {
  1500. + dir = new File(dir, getJREDirectory());
  1501. + }
  1502. +
  1503. + String dcevm_jar = new File(dir, "lib" + File.separator + "ext" + File.separator + "dcevm.jar").getPath();
  1504. + extractFile("data/dcevm.jar", dcevm_jar);
  1505. +
  1506. + if (new File(dir, getServerDirectory(bit64)).exists()) {
  1507. + installClientServer(dir, getServerDirectory(bit64), bit64);
  1508. + }
  1509. +
  1510. + if (new File(dir, getClientDirectory()).exists() && !bit64) {
  1511. + try {
  1512. + installClientServer(dir, getClientDirectory(), false);
  1513. + } catch (InstallerException e) {
  1514. + uninstallClientServer(dir, getServerDirectory(bit64));
  1515. + throw e;
  1516. + }
  1517. + }
  1518. + }
  1519. +
  1520. + public void uninstall(File dir, boolean bit64) throws InstallerException {
  1521. + if (isJDK(dir)) {
  1522. + dir = new File(dir, getJREDirectory());
  1523. + }
  1524. +
  1525. + if (new File(dir, getServerDirectory(bit64)).exists()) {
  1526. + uninstallClientServer(dir, getServerDirectory(bit64));
  1527. + }
  1528. +
  1529. + if (new File(dir, getClientDirectory()).exists() && !bit64) {
  1530. + try {
  1531. + uninstallClientServer(dir, getClientDirectory());
  1532. + } catch (InstallerException e) {
  1533. + if (new File(dir, getServerDirectory(bit64)).exists()) {
  1534. + installClientServer(dir, getServerDirectory(bit64), bit64);
  1535. + }
  1536. + throw e;
  1537. + }
  1538. + }
  1539. +
  1540. + String dcevm_jar = new File(dir, "lib" + File.separator + "ext" + File.separator + "dcevm.jar").getPath();
  1541. + try {
  1542. + deleteFile(dcevm_jar);
  1543. + } catch (InstallerException e) {
  1544. + install(dir, bit64);
  1545. + throw e;
  1546. + }
  1547. + }
  1548. +
  1549. + private void installClientServer(File jreDir, String directory, boolean bit64) throws InstallerException {
  1550. + String jarpath = "data/" + (bit64 ? "64/" : "") + directory.replace(File.separatorChar, '/') + "/" + getLibraryName();
  1551. + File clientOrServerDir = new File(jreDir, directory);
  1552. + String jvm_dll = new File(clientOrServerDir, getLibraryName()).getPath();
  1553. + String jvm_dll_backup = new File(clientOrServerDir, getBackupLibraryName()).getPath();
  1554. +
  1555. + renameFile(jvm_dll, jvm_dll_backup);
  1556. +
  1557. + try {
  1558. + extractFile(jarpath, jvm_dll);
  1559. + } catch (InstallerException e) {
  1560. + renameFile(jvm_dll_backup, jvm_dll);
  1561. + throw e;
  1562. + }
  1563. + }
  1564. +
  1565. + private void uninstallClientServer(File jreDir, String directory) throws InstallerException {
  1566. + File clientOrServerDir = new File(jreDir, directory);
  1567. + String jvm_dll = new File(clientOrServerDir, getLibraryName()).getPath();
  1568. + String jvm_dll_backup = new File(clientOrServerDir, getBackupLibraryName()).getPath();
  1569. + String jvm_dll_backup_temp = createTempFilename(clientOrServerDir, getBackupLibraryName() + "_", ".temp");
  1570. +
  1571. + renameFile(jvm_dll_backup, jvm_dll_backup_temp);
  1572. +
  1573. + try {
  1574. + deleteFile(jvm_dll);
  1575. + } catch (InstallerException e) {
  1576. + renameFile(jvm_dll_backup_temp, jvm_dll_backup);
  1577. + throw e;
  1578. + }
  1579. +
  1580. + try {
  1581. + renameFile(jvm_dll_backup_temp, jvm_dll);
  1582. + } catch (InstallerException e) {
  1583. + throw new InstallerException("Warning: JVM directory is in an inconistent state.", e);
  1584. + }
  1585. + }
  1586. +
  1587. + private String createTempFilename(File dir, String prefix, String suffix){
  1588. + String filename;
  1589. + int i=0;
  1590. +
  1591. + do
  1592. + {
  1593. + i++;
  1594. + filename = prefix + i + suffix;
  1595. + } while(new File(dir, filename).exists() && i<1000);
  1596. +
  1597. + return new File(dir, filename).getPath();
  1598. + }
  1599. +
  1600. + private void deleteFile(String file) throws InstallerException {
  1601. + File f = new File(file);
  1602. +
  1603. + boolean succ = false;
  1604. + try {
  1605. + succ = f.delete();
  1606. + } catch (Exception e) {
  1607. + throw new InstallerException("Could not delete " + file + ".", e);
  1608. + }
  1609. +
  1610. + if (!succ) {
  1611. + throw new InstallerException("Could not delete " + file + ".");
  1612. + }
  1613. + }
  1614. +
  1615. + private void renameFile(String from, String to) throws InstallerException {
  1616. + File ffr = new File(from);
  1617. + File fto = new File(to);
  1618. + if(!fto.isAbsolute()) fto = new File(ffr, to);
  1619. +
  1620. + if (!ffr.exists()) {
  1621. + throw new InstallerException("The file " + from + " does not exist.");
  1622. + }
  1623. +
  1624. + boolean succ = false;
  1625. + try {
  1626. + succ = ffr.renameTo(fto);
  1627. + } catch (Exception e) {
  1628. + throw new InstallerException("Could not rename " + from + " to " + to + ".", e);
  1629. + }
  1630. +
  1631. + if (!succ) {
  1632. + throw new InstallerException("Could not rename " + from + " to " + to + ".");
  1633. + }
  1634. + }
  1635. +
  1636. + public boolean isJRE(File directory) {
  1637. + if (directory.isDirectory() && directory.getName().startsWith("jre")) {
  1638. +
  1639. + String[] files = {getJavaExecutable()};
  1640. + for (int i = 0; i < files.length; i++) {
  1641. + if (!new File(directory, files[i]).exists()) {
  1642. + return false;
  1643. + }
  1644. + }
  1645. +
  1646. + if (new File(directory, getClientDirectory()).exists()) {
  1647. + if (!new File(directory, getClientDirectory() + File.separator + getLibraryName()).exists()) {
  1648. + return new File(directory, getClientDirectory() + File.separator + getBackupLibraryName()).exists();
  1649. + }
  1650. + }
  1651. +
  1652. + if (new File(directory, getServerDirectory(true)).exists()) {
  1653. + if (!new File(directory, getServerDirectory(true) + File.separator + getLibraryName()).exists()) {
  1654. + return new File(directory, getServerDirectory(true) + File.separator + getBackupLibraryName()).exists();
  1655. + }
  1656. + }
  1657. + return true;
  1658. + }
  1659. + return false;
  1660. + }
  1661. +
  1662. + public boolean isJDK(File directory) {
  1663. + if (directory.isDirectory()) {
  1664. + File jreDir = new File(directory, getJREDirectory());
  1665. + return isJRE(jreDir);
  1666. + }
  1667. + return false;
  1668. + }
  1669. +
  1670. + final public String executeJava(File jreDir, String... params) throws InstallerException {
  1671. + File command = new File(jreDir, getJavaExecutable());
  1672. + try {
  1673. + StringBuilder result = new StringBuilder();
  1674. + String line;
  1675. + ArrayList<String> pp = new ArrayList<String>();
  1676. + pp.add(command.getAbsolutePath());
  1677. + pp.addAll(Arrays.asList(params));
  1678. + Process p = Runtime.getRuntime().exec(pp.toArray(new String[0]));
  1679. + BufferedReader input =
  1680. + new BufferedReader(new InputStreamReader(p.getErrorStream()));
  1681. + while ((line = input.readLine()) != null) {
  1682. + result.append(line);
  1683. + result.append('\n');
  1684. + }
  1685. + input.close();
  1686. + return result.toString();
  1687. + } catch (Exception err) {
  1688. + throw new InstallerException("Could not execute " + command + ".", err);
  1689. + }
  1690. + }
  1691. +
  1692. + public boolean isDCEInstalled(File dir) throws InstallerException {
  1693. + File jreDir;
  1694. + if (isJDK(dir)) {
  1695. + jreDir = new File(dir, "jre");
  1696. + } else {
  1697. + jreDir = dir;
  1698. + }
  1699. + File jvmDCEClientFile = new File(jreDir, getClientDirectory() + File.separator + getBackupLibraryName());
  1700. + String serverDir = getServerDirectory(false);
  1701. + if (!new File(jreDir, serverDir).exists()) {
  1702. + serverDir = getServerDirectory(true);
  1703. + }
  1704. + File jvmDCEServerFile = new File(jreDir, serverDir + File.separator + getBackupLibraryName());
  1705. +
  1706. + if (new File(jreDir, getClientDirectory()).exists() && new File(jreDir, serverDir).exists()) {
  1707. + if (jvmDCEServerFile.exists() != jvmDCEClientFile.exists()) {
  1708. + throw new InstallerException(jreDir.getAbsolutePath() + " has invalid state.");
  1709. + }
  1710. + }
  1711. + return jvmDCEClientFile.exists() || jvmDCEServerFile.exists();
  1712. + }
  1713. +
  1714. + final public String getVersionString(File jreDir) throws InstallerException {
  1715. + return executeJava(jreDir, "-version");
  1716. + }
  1717. +
  1718. + final public boolean is64Bit(File jreDir) throws InstallerException {
  1719. + return getVersionString(jreDir).contains("64-Bit");
  1720. + }
  1721. +
  1722. + final public String getJavaVersion(File jreDir) throws InstallerException {
  1723. + return getVersionHelper(jreDir, ".*java version.*\"(.*)\".*", true);
  1724. + }
  1725. +
  1726. + final public String getDCEVersion(File jreDir) throws InstallerException {
  1727. + return getVersionHelper(jreDir, ".*Dynamic Code Evolution.*build ([^,]+),.*", false);
  1728. + }
  1729. +
  1730. + private String getVersionHelper(File jreDir, String regex, boolean javaVersion) throws InstallerException {
  1731. + String version = getVersionString(jreDir);
  1732. + version = version.replaceAll("\n", "");
  1733. + Matcher matcher = Pattern.compile(regex).matcher(version);
  1734. +
  1735. + if (!matcher.matches()) {
  1736. + throw new InstallerException("Could not get " + (javaVersion ? "java" : "dce") + "version of " + jreDir.getAbsolutePath() + ".");
  1737. + }
  1738. +
  1739. + version = matcher.replaceFirst("$1");
  1740. + return version;
  1741. + }
  1742. +}
  1743. diff -r f5603a6e5042 hotswapinstaller/Installer/src/at/ssw/hotswap/installer/InstallerException.java
  1744. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  1745. +++ b/hotswapinstaller/Installer/src/at/ssw/hotswap/installer/InstallerException.java Fri Dec 17 13:23:04 2010 +0100
  1746. @@ -0,0 +1,39 @@
  1747. +/*
  1748. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  1749. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  1750. + *
  1751. + * This code is free software; you can redistribute it and/or modify it
  1752. + * under the terms of the GNU General Public License version 2 only, as
  1753. + * published by the Free Software Foundation.
  1754. + *
  1755. + * This code is distributed in the hope that it will be useful, but WITHOUT
  1756. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1757. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1758. + * version 2 for more details (a copy is included in the LICENSE file that
  1759. + * accompanied this code).
  1760. + *
  1761. + * You should have received a copy of the GNU General Public License version
  1762. + * 2 along with this work; if not, write to the Free Software Foundation,
  1763. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  1764. + *
  1765. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  1766. + * or visit www.oracle.com if you need additional information or have any
  1767. + * questions.
  1768. + *
  1769. + */
  1770. +package at.ssw.hotswap.installer;
  1771. +
  1772. +/**
  1773. + * @author Kerstin Breiteneder
  1774. + * @author Christoph Wimberger
  1775. + */
  1776. +public class InstallerException extends Exception {
  1777. +
  1778. + InstallerException(String e) {
  1779. + super(e);
  1780. + }
  1781. +
  1782. + InstallerException(String e, Throwable t) {
  1783. + super(e, t);
  1784. + }
  1785. +}
  1786. diff -r f5603a6e5042 hotswapinstaller/Installer/src/at/ssw/hotswap/installer/LinuxInstaller.java
  1787. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  1788. +++ b/hotswapinstaller/Installer/src/at/ssw/hotswap/installer/LinuxInstaller.java Fri Dec 17 13:23:04 2010 +0100
  1789. @@ -0,0 +1,78 @@
  1790. +/*
  1791. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  1792. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  1793. + *
  1794. + * This code is free software; you can redistribute it and/or modify it
  1795. + * under the terms of the GNU General Public License version 2 only, as
  1796. + * published by the Free Software Foundation.
  1797. + *
  1798. + * This code is distributed in the hope that it will be useful, but WITHOUT
  1799. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1800. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1801. + * version 2 for more details (a copy is included in the LICENSE file that
  1802. + * accompanied this code).
  1803. + *
  1804. + * You should have received a copy of the GNU General Public License version
  1805. + * 2 along with this work; if not, write to the Free Software Foundation,
  1806. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  1807. + *
  1808. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  1809. + * or visit www.oracle.com if you need additional information or have any
  1810. + * questions.
  1811. + *
  1812. + */
  1813. +package at.ssw.hotswap.installer;
  1814. +
  1815. +import java.io.File;
  1816. +import java.io.IOException;
  1817. +import java.util.ArrayList;
  1818. +import java.util.List;
  1819. +
  1820. +/**
  1821. + * @author Kerstin Breiteneder
  1822. + * @author Christoph Wimberger
  1823. + */
  1824. +public class LinuxInstaller extends Installer {
  1825. +
  1826. + public String getClientDirectory() {
  1827. + return "lib/i386/client";
  1828. + }
  1829. +
  1830. + public String getServerDirectory(boolean is64Bit) {
  1831. + if (is64Bit) {
  1832. + return "lib/amd64/server";
  1833. + } else {
  1834. + return "lib/i386/server";
  1835. + }
  1836. + }
  1837. +
  1838. + public String getLibraryName() {
  1839. + return "libjvm.so";
  1840. + }
  1841. +
  1842. + public String getJavaExecutable() {
  1843. + return "bin/java";
  1844. + }
  1845. +
  1846. + @Override
  1847. + public List<Installation> listAllInstallations() {
  1848. + File dir = new File("/usr/java");
  1849. +
  1850. + List<Installation> dirs = new ArrayList<Installation>();
  1851. +
  1852. + if (dir.exists()) {
  1853. + for (File f : dir.listFiles()) {
  1854. + try {
  1855. + Installation i = new Installation(f.getCanonicalFile(), this);
  1856. + if (!dirs.contains(i)) {
  1857. + dirs.add(i);
  1858. + }
  1859. + } catch (IOException ex) {
  1860. + } catch (InstallerException ex) {
  1861. + }
  1862. + }
  1863. + }
  1864. +
  1865. + return dirs;
  1866. + }
  1867. +}
  1868. diff -r f5603a6e5042 hotswapinstaller/Installer/src/at/ssw/hotswap/installer/MacInstaller.java
  1869. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  1870. +++ b/hotswapinstaller/Installer/src/at/ssw/hotswap/installer/MacInstaller.java Fri Dec 17 13:23:04 2010 +0100
  1871. @@ -0,0 +1,66 @@
  1872. +/*
  1873. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  1874. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  1875. + *
  1876. + * This code is free software; you can redistribute it and/or modify it
  1877. + * under the terms of the GNU General Public License version 2 only, as
  1878. + * published by the Free Software Foundation.
  1879. + *
  1880. + * This code is distributed in the hope that it will be useful, but WITHOUT
  1881. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1882. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1883. + * version 2 for more details (a copy is included in the LICENSE file that
  1884. + * accompanied this code).
  1885. + *
  1886. + * You should have received a copy of the GNU General Public License version
  1887. + * 2 along with this work; if not, write to the Free Software Foundation,
  1888. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  1889. + *
  1890. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  1891. + * or visit www.oracle.com if you need additional information or have any
  1892. + * questions.
  1893. + *
  1894. + */
  1895. +package at.ssw.hotswap.installer;
  1896. +
  1897. +import java.io.File;
  1898. +import java.util.ArrayList;
  1899. +import java.util.List;
  1900. +
  1901. +/**
  1902. + * @author Kerstin Breiteneder
  1903. + * @author Christoph Wimberger
  1904. + */
  1905. +public class MacInstaller extends Installer {
  1906. +
  1907. + @Override
  1908. + public void install(File dir, boolean bit64) throws InstallerException {
  1909. + if(bit64) throw new InstallerException("64 Bit Soylatte is not supported in this installer version.");
  1910. + super.install(dir, bit64);
  1911. + }
  1912. +
  1913. + public String getClientDirectory() {
  1914. + return "lib/i386/client";
  1915. + }
  1916. +
  1917. + public String getServerDirectory(boolean is64Bit) {
  1918. + if (is64Bit) {
  1919. + return "lib/amd64/server";
  1920. + } else {
  1921. + return "lib/i386/server";
  1922. + }
  1923. + }
  1924. +
  1925. + public String getLibraryName() {
  1926. + return "libjvm.dylib";
  1927. + }
  1928. +
  1929. + public String getJavaExecutable() {
  1930. + return "bin/java";
  1931. + }
  1932. +
  1933. + @Override
  1934. + public List<Installation> listAllInstallations() {
  1935. + return new ArrayList<Installation>();
  1936. + }
  1937. +}
  1938. diff -r f5603a6e5042 hotswapinstaller/Installer/src/at/ssw/hotswap/installer/Main.java
  1939. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  1940. +++ b/hotswapinstaller/Installer/src/at/ssw/hotswap/installer/Main.java Fri Dec 17 13:23:04 2010 +0100
  1941. @@ -0,0 +1,57 @@
  1942. +/*
  1943. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  1944. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  1945. + *
  1946. + * This code is free software; you can redistribute it and/or modify it
  1947. + * under the terms of the GNU General Public License version 2 only, as
  1948. + * published by the Free Software Foundation.
  1949. + *
  1950. + * This code is distributed in the hope that it will be useful, but WITHOUT
  1951. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1952. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  1953. + * version 2 for more details (a copy is included in the LICENSE file that
  1954. + * accompanied this code).
  1955. + *
  1956. + * You should have received a copy of the GNU General Public License version
  1957. + * 2 along with this work; if not, write to the Free Software Foundation,
  1958. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  1959. + *
  1960. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  1961. + * or visit www.oracle.com if you need additional information or have any
  1962. + * questions.
  1963. + *
  1964. + */
  1965. +package at.ssw.hotswap.installer;
  1966. +
  1967. +import javax.swing.JOptionPane;
  1968. +import javax.swing.UIManager;
  1969. +import javax.swing.UnsupportedLookAndFeelException;
  1970. +
  1971. +/**
  1972. + * @author Kerstin Breiteneder
  1973. + * @author Christoph Wimberger
  1974. + * @author Thomas Wuerthinger
  1975. + */
  1976. +public class Main {
  1977. +
  1978. + public static void main(String[] args) {
  1979. + try {
  1980. + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  1981. + } catch (UnsupportedLookAndFeelException e) {
  1982. + } catch (ClassNotFoundException e) {
  1983. + } catch (InstantiationException e) {
  1984. + } catch (IllegalAccessException e) {
  1985. + }
  1986. +
  1987. + MainWindow w;
  1988. + try {
  1989. + Installer i = Installer.create();
  1990. + w = new MainWindow(i);
  1991. + w.setLocationRelativeTo(null);
  1992. + w.setVisible(true);
  1993. + } catch (InstallerException ex) {
  1994. + JOptionPane.showMessageDialog(null, ex.getMessage(), ex.getMessage(), JOptionPane.ERROR_MESSAGE);
  1995. + }
  1996. +
  1997. + }
  1998. +}
  1999. diff -r f5603a6e5042 hotswapinstaller/Installer/src/at/ssw/hotswap/installer/MainWindow.java
  2000. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  2001. +++ b/hotswapinstaller/Installer/src/at/ssw/hotswap/installer/MainWindow.java Fri Dec 17 13:23:04 2010 +0100
  2002. @@ -0,0 +1,430 @@
  2003. +/*
  2004. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  2005. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  2006. + *
  2007. + * This code is free software; you can redistribute it and/or modify it
  2008. + * under the terms of the GNU General Public License version 2 only, as
  2009. + * published by the Free Software Foundation.
  2010. + *
  2011. + * This code is distributed in the hope that it will be useful, but WITHOUT
  2012. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  2013. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  2014. + * version 2 for more details (a copy is included in the LICENSE file that
  2015. + * accompanied this code).
  2016. + *
  2017. + * You should have received a copy of the GNU General Public License version
  2018. + * 2 along with this work; if not, write to the Free Software Foundation,
  2019. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  2020. + *
  2021. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  2022. + * or visit www.oracle.com if you need additional information or have any
  2023. + * questions.
  2024. + *
  2025. + */
  2026. +package at.ssw.hotswap.installer;
  2027. +
  2028. +import java.awt.BorderLayout;
  2029. +import java.awt.Color;
  2030. +import java.awt.Component;
  2031. +import java.awt.Dimension;
  2032. +import java.awt.FlowLayout;
  2033. +import java.awt.event.ActionEvent;
  2034. +import java.awt.image.BufferedImage;
  2035. +import java.io.File;
  2036. +import java.io.IOException;
  2037. +import java.util.ArrayList;
  2038. +import java.util.Observable;
  2039. +import java.util.Observer;
  2040. +import java.util.prefs.Preferences;
  2041. +import javax.imageio.ImageIO;
  2042. +import javax.swing.AbstractAction;
  2043. +import javax.swing.BorderFactory;
  2044. +import javax.swing.ImageIcon;
  2045. +import javax.swing.JButton;
  2046. +import javax.swing.JComponent;
  2047. +import javax.swing.JFileChooser;
  2048. +import javax.swing.JFrame;
  2049. +import javax.swing.JLabel;
  2050. +import javax.swing.JOptionPane;
  2051. +import javax.swing.JPanel;
  2052. +import javax.swing.JScrollPane;
  2053. +import javax.swing.JTable;
  2054. +import javax.swing.JTextArea;
  2055. +import javax.swing.ListSelectionModel;
  2056. +import javax.swing.event.ListSelectionEvent;
  2057. +import javax.swing.event.ListSelectionListener;
  2058. +import javax.swing.table.AbstractTableModel;
  2059. +import javax.swing.table.DefaultTableCellRenderer;
  2060. +
  2061. +/**
  2062. + * @author Kerstin Breiteneder
  2063. + * @author Christoph Wimberger
  2064. + */
  2065. +public class MainWindow extends JFrame {
  2066. +
  2067. + private final InstallationsTableModel installations;
  2068. + private final Installer installer;
  2069. + private JTable table;
  2070. +
  2071. + public MainWindow(Installer inst) {
  2072. + super("Dynamic Code Evolution VM Installer");
  2073. + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  2074. +
  2075. + installer = inst;
  2076. + installations = new InstallationsTableModel();
  2077. + for (Installation i : installer.listAllInstallations()) {
  2078. + installations.add(i);
  2079. + }
  2080. + add(getBanner(), BorderLayout.NORTH);
  2081. + add(getCenterPanel(), BorderLayout.CENTER);
  2082. + add(getBottomPanel(), BorderLayout.SOUTH);
  2083. +
  2084. + if (table.getRowCount() > 0) {
  2085. + table.setRowSelectionInterval(0, 0);
  2086. + }
  2087. +
  2088. + pack();
  2089. + setMinimumSize(getSize());
  2090. + }
  2091. +
  2092. + static void showInstallerException(InstallerException ex, Component parent) {
  2093. + Throwable e = ex;
  2094. + String error = e.getMessage();
  2095. + e = e.getCause();
  2096. +
  2097. + while (e != null) {
  2098. + error += "\n" + e.getMessage();
  2099. + e = e.getCause();
  2100. + }
  2101. +
  2102. + ex.printStackTrace();
  2103. +
  2104. + error += "\nPlease ensure that no other Java applications are running and you have sufficient permissions.";
  2105. + JOptionPane.showMessageDialog(parent, error, ex.getMessage(), JOptionPane.ERROR_MESSAGE);
  2106. + }
  2107. +
  2108. + private JComponent getBanner() {
  2109. + try {
  2110. + BufferedImage img = ImageIO.read(getClass().getResource("splash.png"));
  2111. + JLabel title = new JLabel(new ImageIcon(img));
  2112. + title.setPreferredSize(new Dimension(img.getWidth() + 10, img.getHeight()));
  2113. + title.setOpaque(true);
  2114. + title.setBackground(new Color(238, 238, 255));
  2115. + return title;
  2116. + } catch (IOException ex) {
  2117. + }
  2118. + return new JLabel();
  2119. + }
  2120. +
  2121. + private JComponent getCenterPanel() {
  2122. + JPanel center = new JPanel(new BorderLayout());
  2123. + center.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
  2124. + center.setBackground(Color.WHITE);
  2125. + JTextArea license = new javax.swing.JTextArea();
  2126. + license.setLineWrap(true);
  2127. + license.setWrapStyleWord(true);
  2128. + license.setEditable(false);
  2129. + license.setFont(license.getFont().deriveFont(11.0f));
  2130. + StringBuilder licenseText = new StringBuilder();
  2131. + licenseText.append("This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 only, as published by the Free Software Foundation.\n\nThis code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more details (a copy is included in the LICENSE file that accompanied this code).\n\nYou should have received a copy of the GNU General Public License version 2 along with this work; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.");
  2132. + licenseText.append("\n\n\nASM LICENSE TEXT:\nCopyright (c) 2000-2005 INRIA, France Telecom\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\n3. Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.");
  2133. + license.setText(licenseText.toString());
  2134. + JScrollPane licenses = new JScrollPane(license, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  2135. + licenses.setPreferredSize(new Dimension(150, 150));
  2136. + center.add(licenses, BorderLayout.NORTH);
  2137. + center.add(getChooserPanel(), BorderLayout.CENTER);
  2138. + return center;
  2139. + }
  2140. +
  2141. + private JComponent getChooserPanel() {
  2142. + JPanel p = new JPanel(new BorderLayout());
  2143. + p.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
  2144. + p.setOpaque(false);
  2145. +
  2146. + JLabel l = new JLabel("Please choose installation directory:");
  2147. + l.setVerticalAlignment(JLabel.NORTH);
  2148. + l.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
  2149. + p.add(l, BorderLayout.WEST);
  2150. +
  2151. + table = new JTable(installations);
  2152. + table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  2153. + table.setColumnSelectionAllowed(false);
  2154. + table.setDefaultRenderer(Object.class, new InstallationTableCellRenderer());
  2155. + table.getColumnModel().getColumn(0).setHeaderValue("Directory");
  2156. + table.getColumnModel().getColumn(0).setPreferredWidth(300);
  2157. + table.getColumnModel().getColumn(1).setHeaderValue("Java Version");
  2158. + table.getColumnModel().getColumn(2).setHeaderValue("Type");
  2159. + table.getColumnModel().getColumn(3).setHeaderValue("DCE");
  2160. + JScrollPane lists = new JScrollPane(table);
  2161. + lists.setPreferredSize(new Dimension(200, 200));
  2162. + p.add(lists, BorderLayout.CENTER);
  2163. +
  2164. + return p;
  2165. + }
  2166. +
  2167. + private JComponent getBottomPanel() {
  2168. +
  2169. + JPanel left = new JPanel(new FlowLayout());
  2170. + left.add(new JButton(new AddDirectoryAction(this, installations, installer)));
  2171. +
  2172. + JPanel right = new JPanel(new FlowLayout());
  2173. + right.add(new JButton(new TestAction(table, installer)));
  2174. + right.add(new JButton(new InstallUninstallAction(false, table)));
  2175. + right.add(new JButton(new InstallUninstallAction(true, table)));
  2176. +
  2177. + JPanel bottom = new JPanel(new BorderLayout());
  2178. + bottom.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  2179. + bottom.add(left, BorderLayout.WEST);
  2180. + bottom.add(right, BorderLayout.EAST);
  2181. +
  2182. + return bottom;
  2183. + }
  2184. +}
  2185. +
  2186. +class AddDirectoryAction extends AbstractAction {
  2187. +
  2188. + private final Component parent;
  2189. + private final InstallationsTableModel installations;
  2190. + private final Installer installer;
  2191. +
  2192. + public AddDirectoryAction(Component parent, InstallationsTableModel inst, Installer installer) {
  2193. + super("Add installation directory...");
  2194. + this.parent = parent;
  2195. + installations = inst;
  2196. + this.installer = installer;
  2197. + }
  2198. +
  2199. + public void actionPerformed(ActionEvent e) {
  2200. + JFileChooser fc = new JFileChooser();
  2201. + fc.setDialogTitle("Select a Java installation directory...");
  2202. + fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  2203. + fc.setAcceptAllFileFilterUsed(false);
  2204. + Preferences p = Preferences.userNodeForPackage(Installer.class);
  2205. + final String prefID = "defaultDirectory";
  2206. + fc.setCurrentDirectory(new File(p.get(prefID, ".")));
  2207. +
  2208. + if (fc.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
  2209. +
  2210. + File dir = fc.getSelectedFile();
  2211. + p.put(prefID, dir.getParent());
  2212. + try {
  2213. + installations.add(new Installation(dir, installer));
  2214. + } catch (InstallerException ex) {
  2215. + MainWindow.showInstallerException(ex, parent);
  2216. + }
  2217. + }
  2218. + }
  2219. +}
  2220. +
  2221. +class InstallUninstallAction extends AbstractAction implements ListSelectionListener, Observer {
  2222. +
  2223. + private final JTable table;
  2224. + private final boolean install;
  2225. + private Installation installation;
  2226. +
  2227. + public InstallUninstallAction(boolean install, JTable t) {
  2228. + super(install ? "Install" : "Uninstall");
  2229. + this.install = install;
  2230. + setEnabled(false);
  2231. + table = t;
  2232. + t.getSelectionModel().addListSelectionListener(this);
  2233. + }
  2234. +
  2235. + private Installation getSelectedInstallation() {
  2236. + InstallationsTableModel itm = (InstallationsTableModel) table.getModel();
  2237. + int sel = table.getSelectedRow();
  2238. + if (sel < 0) {
  2239. + return null;
  2240. + } else {
  2241. + return itm.getInstallationAt(sel);
  2242. + }
  2243. + }
  2244. +
  2245. + public void actionPerformed(ActionEvent e) {
  2246. + try {
  2247. + if (install) {
  2248. + getSelectedInstallation().installDCE();
  2249. + } else {
  2250. + getSelectedInstallation().uninstallDCE();
  2251. + }
  2252. + } catch (InstallerException ex) {
  2253. + MainWindow.showInstallerException(ex, table);
  2254. + }
  2255. + }
  2256. +
  2257. + private void setCurrentInstallation(Installation i) {
  2258. + if (installation != null) {
  2259. + installation.deleteObserver(this);
  2260. + }
  2261. + installation = i;
  2262. + if (installation != null) {
  2263. + installation.addObserver(this);
  2264. + }
  2265. + update();
  2266. + }
  2267. +
  2268. + public void valueChanged(ListSelectionEvent e) {
  2269. + Installation i = getSelectedInstallation();
  2270. + setCurrentInstallation(i);
  2271. + }
  2272. +
  2273. + private void update() {
  2274. + if (install) {
  2275. + setEnabled(installation != null && !installation.isDCEInstalled());
  2276. + } else {
  2277. + setEnabled(installation != null && installation.isDCEInstalled());
  2278. + }
  2279. + }
  2280. +
  2281. + public void update(Observable o, Object arg) {
  2282. + update();
  2283. + }
  2284. +}
  2285. +
  2286. +class TestAction extends AbstractAction implements ListSelectionListener, Observer {
  2287. +
  2288. + private final JTable table;
  2289. + private Installation installation;
  2290. + private final Installer installer;
  2291. +
  2292. + public TestAction(JTable t, Installer i) {
  2293. + super("Test Installation");
  2294. + setEnabled(false);
  2295. + table = t;
  2296. + installer = i;
  2297. + t.getSelectionModel().addListSelectionListener(this);
  2298. + }
  2299. +
  2300. + private Installation getSelectedInstallation() {
  2301. + InstallationsTableModel itm = (InstallationsTableModel) table.getModel();
  2302. + int sel = table.getSelectedRow();
  2303. + if (sel < 0) {
  2304. + return null;
  2305. + } else {
  2306. + return itm.getInstallationAt(sel);
  2307. + }
  2308. + }
  2309. +
  2310. + public void actionPerformed(ActionEvent e) {
  2311. + File p = installation.getPath();
  2312. + if(installation.isJDK()) p = new File(p, "jre");
  2313. +
  2314. + String result = "";
  2315. + try {
  2316. + String agentparam = "-javaagent:" + p.getAbsolutePath() + "/lib/ext/dcevm.jar";
  2317. + result = installer.executeJava(p, agentparam, "at.ssw.mixin.fasttest.FastTest");
  2318. + } catch (InstallerException ex) {
  2319. + MainWindow.showInstallerException(ex, table);
  2320. + }
  2321. +
  2322. + if(result.length()>0) {
  2323. + String msg = "Tests failed:\n" + result;
  2324. + JOptionPane.showMessageDialog(table.getTopLevelAncestor(), msg, "Error", JOptionPane.ERROR_MESSAGE);
  2325. + } else {
  2326. + JOptionPane.showMessageDialog(table.getTopLevelAncestor(), "All tests succeeded.", "Information", JOptionPane.INFORMATION_MESSAGE);
  2327. + }
  2328. + }
  2329. +
  2330. + private void setCurrentInstallation(Installation i) {
  2331. + if (installation != null) {
  2332. + installation.deleteObserver(this);
  2333. + }
  2334. + installation = i;
  2335. + if (installation != null) {
  2336. + installation.addObserver(this);
  2337. + }
  2338. + update();
  2339. + }
  2340. +
  2341. + public void valueChanged(ListSelectionEvent e) {
  2342. + Installation i = getSelectedInstallation();
  2343. + setCurrentInstallation(i);
  2344. + }
  2345. +
  2346. + private void update() {
  2347. + setEnabled(installation != null && installation.isDCEInstalled());
  2348. + }
  2349. +
  2350. + public void update(Observable o, Object arg) {
  2351. + update();
  2352. + }
  2353. +}
  2354. +
  2355. +class InstallationsTableModel extends AbstractTableModel implements Observer {
  2356. +
  2357. + private final ArrayList<Installation> installations;
  2358. +
  2359. + public InstallationsTableModel() {
  2360. + installations = new ArrayList<Installation>();
  2361. + }
  2362. +
  2363. + public int getRowCount() {
  2364. + return installations.size();
  2365. + }
  2366. +
  2367. + public int getColumnCount() {
  2368. + return 4;
  2369. + }
  2370. +
  2371. + public Object getValueAt(int rowIndex, int columnIndex) {
  2372. + return installations.get(rowIndex);
  2373. + }
  2374. +
  2375. + public Installation getInstallationAt(int row) {
  2376. + return installations.get(row);
  2377. + }
  2378. +
  2379. + public void add(Installation i) {
  2380. + installations.add(i);
  2381. + i.addObserver(this);
  2382. + fireTableDataChanged();
  2383. + }
  2384. +
  2385. + public void update(Observable o, Object arg) {
  2386. + int row = installations.indexOf(o);
  2387. + fireTableRowsUpdated(row, row);
  2388. + }
  2389. +}
  2390. +
  2391. +class InstallationTableCellRenderer extends DefaultTableCellRenderer {
  2392. +
  2393. + @Override
  2394. + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
  2395. + Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
  2396. +
  2397. + if (c instanceof JLabel && value instanceof Installation) {
  2398. + JLabel l = (JLabel) c;
  2399. + Installation i = (Installation) value;
  2400. +
  2401. + switch (column) {
  2402. + case 0:
  2403. + l.setText(i.getPath().getAbsolutePath());
  2404. + break;
  2405. + case 1:
  2406. + l.setText(i.getVersion());
  2407. + break;
  2408. + case 2:
  2409. + l.setText(i.isJDK() ? "JDK" : "JRE");
  2410. + if (i.is64Bit()) {
  2411. + l.setText(l.getText() + " (64 Bit)");
  2412. + }
  2413. + break;
  2414. + case 3:
  2415. + if (i.isDCEInstalled()) {
  2416. + l.setText("Yes (" + i.getDCEVersion() + ")");
  2417. + } else {
  2418. + l.setText("No");
  2419. + }
  2420. + break;
  2421. + }
  2422. + }
  2423. +
  2424. + return c;
  2425. + }
  2426. +
  2427. + @Override
  2428. + public void setText(String text) {
  2429. + super.setText(text);
  2430. + setToolTipText(text);
  2431. + }
  2432. +}
  2433. diff -r f5603a6e5042 hotswapinstaller/Installer/src/at/ssw/hotswap/installer/WindowsInstaller.java
  2434. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  2435. +++ b/hotswapinstaller/Installer/src/at/ssw/hotswap/installer/WindowsInstaller.java Fri Dec 17 13:23:04 2010 +0100
  2436. @@ -0,0 +1,88 @@
  2437. +/*
  2438. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  2439. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  2440. + *
  2441. + * This code is free software; you can redistribute it and/or modify it
  2442. + * under the terms of the GNU General Public License version 2 only, as
  2443. + * published by the Free Software Foundation.
  2444. + *
  2445. + * This code is distributed in the hope that it will be useful, but WITHOUT
  2446. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  2447. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  2448. + * version 2 for more details (a copy is included in the LICENSE file that
  2449. + * accompanied this code).
  2450. + *
  2451. + * You should have received a copy of the GNU General Public License version
  2452. + * 2 along with this work; if not, write to the Free Software Foundation,
  2453. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  2454. + *
  2455. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  2456. + * or visit www.oracle.com if you need additional information or have any
  2457. + * questions.
  2458. + *
  2459. + */
  2460. +package at.ssw.hotswap.installer;
  2461. +
  2462. +import java.io.File;
  2463. +import java.util.ArrayList;
  2464. +import java.util.List;
  2465. +
  2466. +/**
  2467. + * @author Kerstin Breiteneder
  2468. + * @author Christoph Wimberger
  2469. + */
  2470. +public class WindowsInstaller extends Installer {
  2471. +
  2472. + public String getClientDirectory() {
  2473. + return "bin\\client";
  2474. + }
  2475. +
  2476. + public String getServerDirectory(boolean is64bit) {
  2477. + return "bin\\server";
  2478. + }
  2479. +
  2480. + public String getJavaExecutable() {
  2481. + return "bin\\java.exe";
  2482. + }
  2483. +
  2484. + public String getLibraryName() {
  2485. + return "jvm.dll";
  2486. + }
  2487. +
  2488. + public List<Installation> listAllInstallations() {
  2489. + List<Installation> installations = new ArrayList<Installation>();
  2490. + String[] searchForJavaString = new String[]{
  2491. + System.getenv("JAVA_HOME") + "\\..",
  2492. + System.getenv("PROGRAMW6432") + "\\JAVA",
  2493. + System.getenv("PROGRAMFILES") + "\\JAVA",
  2494. + System.getenv("SYSTEMDRIVE") + "\\JAVA"};
  2495. +
  2496. + for (String fileString : searchForJavaString) {
  2497. + File javaDir = new File(fileString);
  2498. +
  2499. + if (javaDir.exists() && javaDir.isDirectory()) {
  2500. + for (File f : javaDir.listFiles()) {
  2501. + if (f.getName().startsWith("jdk") || f.getName().startsWith("jre")) {
  2502. + try {
  2503. + Installation i = new Installation(f, this);
  2504. + if (!installations.contains(i)) {
  2505. + installations.add(i);
  2506. + }
  2507. + } catch (InstallerException ex) {
  2508. + }
  2509. + }
  2510. + }
  2511. + }
  2512. + }
  2513. + return installations;
  2514. + }
  2515. +
  2516. + @Override
  2517. + public boolean isJDK(File directory) {
  2518. + if (directory.isDirectory() && directory.getName().startsWith("jdk")) {
  2519. + File jreDir = new File(directory, "jre");
  2520. + return isJRE(jreDir);
  2521. + }
  2522. + return false;
  2523. + }
  2524. +}
  2525. diff -r f5603a6e5042 hotswapinstaller/Installer/src/at/ssw/hotswap/installer/splash.png
  2526. Binary file hotswapinstaller/Installer/src/at/ssw/hotswap/installer/splash.png has changed
  2527. diff -r f5603a6e5042 hotswaptest/HotSwapTests/build.xml
  2528. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  2529. +++ b/hotswaptest/HotSwapTests/build.xml Fri Dec 17 13:23:04 2010 +0100
  2530. @@ -0,0 +1,74 @@
  2531. +<?xml version="1.0" encoding="UTF-8"?>
  2532. +<!-- You may freely edit this file. See commented blocks below for -->
  2533. +<!-- some examples of how to customize the build. -->
  2534. +<!-- (If you delete it and reopen the project it will be recreated.) -->
  2535. +<!-- By default, only the Clean and Build commands use this build script. -->
  2536. +<!-- Commands such as Run, Debug, and Test only use this build script if -->
  2537. +<!-- the Compile on Save feature is turned off for the project. -->
  2538. +<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
  2539. +<!-- in the project's Project Properties dialog box.-->
  2540. +<project name="HotSwapTests" default="default" basedir=".">
  2541. + <description>Builds, tests, and runs the project HotSwapTests.</description>
  2542. + <import file="nbproject/build-impl.xml"/>
  2543. + <!--
  2544. +
  2545. + There exist several targets which are by default empty and which can be
  2546. + used for execution of your tasks. These targets are usually executed
  2547. + before and after some main targets. They are:
  2548. +
  2549. + -pre-init: called before initialization of project properties
  2550. + -post-init: called after initialization of project properties
  2551. + -pre-compile: called before javac compilation
  2552. + -post-compile: called after javac compilation
  2553. + -pre-compile-single: called before javac compilation of single file
  2554. + -post-compile-single: called after javac compilation of single file
  2555. + -pre-compile-test: called before javac compilation of JUnit tests
  2556. + -post-compile-test: called after javac compilation of JUnit tests
  2557. + -pre-compile-test-single: called before javac compilation of single JUnit test
  2558. + -post-compile-test-single: called after javac compilation of single JUunit test
  2559. + -pre-jar: called before JAR building
  2560. + -post-jar: called after JAR building
  2561. + -post-clean: called after cleaning build products
  2562. +
  2563. + (Targets beginning with '-' are not intended to be called on their own.)
  2564. +
  2565. + Example of inserting an obfuscator after compilation could look like this:
  2566. +
  2567. + <target name="-post-compile">
  2568. + <obfuscate>
  2569. + <fileset dir="${build.classes.dir}"/>
  2570. + </obfuscate>
  2571. + </target>
  2572. +
  2573. + For list of available properties check the imported
  2574. + nbproject/build-impl.xml file.
  2575. +
  2576. +
  2577. + Another way to customize the build is by overriding existing main targets.
  2578. + The targets of interest are:
  2579. +
  2580. + -init-macrodef-javac: defines macro for javac compilation
  2581. + -init-macrodef-junit: defines macro for junit execution
  2582. + -init-macrodef-debug: defines macro for class debugging
  2583. + -init-macrodef-java: defines macro for class execution
  2584. + -do-jar-with-manifest: JAR building (if you are using a manifest)
  2585. + -do-jar-without-manifest: JAR building (if you are not using a manifest)
  2586. + run: execution of project
  2587. + -javadoc-build: Javadoc generation
  2588. + test-report: JUnit report generation
  2589. +
  2590. + An example of overriding the target for project execution could look like this:
  2591. +
  2592. + <target name="run" depends="HotSwapTests-impl.jar">
  2593. + <exec dir="bin" executable="launcher.exe">
  2594. + <arg file="${dist.jar}"/>
  2595. + </exec>
  2596. + </target>
  2597. +
  2598. + Notice that the overridden target depends on the jar target and not only on
  2599. + the compile target as the regular run target does. Again, for a list of available
  2600. + properties which you can use, check the target you are overriding in the
  2601. + nbproject/build-impl.xml file.
  2602. +
  2603. + -->
  2604. +</project>
  2605. diff -r f5603a6e5042 hotswaptest/HotSwapTests/manifest.mf
  2606. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  2607. +++ b/hotswaptest/HotSwapTests/manifest.mf Fri Dec 17 13:23:04 2010 +0100
  2608. @@ -0,0 +1,3 @@
  2609. +Manifest-Version: 1.0
  2610. +X-COMMENT: Main-Class will be added automatically by build
  2611. +
  2612. diff -r f5603a6e5042 hotswaptest/HotSwapTests/nbproject/build-impl.xml
  2613. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  2614. +++ b/hotswaptest/HotSwapTests/nbproject/build-impl.xml Fri Dec 17 13:23:04 2010 +0100
  2615. @@ -0,0 +1,1056 @@
  2616. +<?xml version="1.0" encoding="UTF-8"?>
  2617. +<!--
  2618. +*** GENERATED FROM project.xml - DO NOT EDIT ***
  2619. +*** EDIT ../build.xml INSTEAD ***
  2620. +
  2621. +For the purpose of easier reading the script
  2622. +is divided into following sections:
  2623. +
  2624. + - initialization
  2625. + - compilation
  2626. + - jar
  2627. + - execution
  2628. + - debugging
  2629. + - javadoc
  2630. + - junit compilation
  2631. + - junit execution
  2632. + - junit debugging
  2633. + - applet
  2634. + - cleanup
  2635. +
  2636. + -->
  2637. +<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="HotSwapTests-impl">
  2638. + <fail message="Please build using Ant 1.7.1 or higher.">
  2639. + <condition>
  2640. + <not>
  2641. + <antversion atleast="1.7.1"/>
  2642. + </not>
  2643. + </condition>
  2644. + </fail>
  2645. + <target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>
  2646. + <!--
  2647. + ======================
  2648. + INITIALIZATION SECTION
  2649. + ======================
  2650. + -->
  2651. + <target name="-pre-init">
  2652. + <!-- Empty placeholder for easier customization. -->
  2653. + <!-- You can override this target in the ../build.xml file. -->
  2654. + </target>
  2655. + <target depends="-pre-init" name="-init-private">
  2656. + <property file="nbproject/private/config.properties"/>
  2657. + <property file="nbproject/private/configs/${config}.properties"/>
  2658. + <property file="nbproject/private/private.properties"/>
  2659. + </target>
  2660. + <target depends="-pre-init,-init-private" name="-init-user">
  2661. + <property file="${user.properties.file}"/>
  2662. + <!-- The two properties below are usually overridden -->
  2663. + <!-- by the active platform. Just a fallback. -->
  2664. + <property name="default.javac.source" value="1.4"/>
  2665. + <property name="default.javac.target" value="1.4"/>
  2666. + </target>
  2667. + <target depends="-pre-init,-init-private,-init-user" name="-init-project">
  2668. + <property file="nbproject/configs/${config}.properties"/>
  2669. + <property file="nbproject/project.properties"/>
  2670. + </target>
  2671. + <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
  2672. + <j2seproject1:property name="platform.home" value="platforms.${platform.active}.home"/>
  2673. + <j2seproject1:property name="platform.bootcp" value="platforms.${platform.active}.bootclasspath"/>
  2674. + <j2seproject1:property name="platform.compiler" value="platforms.${platform.active}.compile"/>
  2675. + <j2seproject1:property name="platform.javac.tmp" value="platforms.${platform.active}.javac"/>
  2676. + <condition property="platform.javac" value="${platform.home}/bin/javac">
  2677. + <equals arg1="${platform.javac.tmp}" arg2="$${platforms.${platform.active}.javac}"/>
  2678. + </condition>
  2679. + <property name="platform.javac" value="${platform.javac.tmp}"/>
  2680. + <j2seproject1:property name="platform.java.tmp" value="platforms.${platform.active}.java"/>
  2681. + <condition property="platform.java" value="${platform.home}/bin/java">
  2682. + <equals arg1="${platform.java.tmp}" arg2="$${platforms.${platform.active}.java}"/>
  2683. + </condition>
  2684. + <property name="platform.java" value="${platform.java.tmp}"/>
  2685. + <j2seproject1:property name="platform.javadoc.tmp" value="platforms.${platform.active}.javadoc"/>
  2686. + <condition property="platform.javadoc" value="${platform.home}/bin/javadoc">
  2687. + <equals arg1="${platform.javadoc.tmp}" arg2="$${platforms.${platform.active}.javadoc}"/>
  2688. + </condition>
  2689. + <property name="platform.javadoc" value="${platform.javadoc.tmp}"/>
  2690. + <condition property="platform.invalid" value="true">
  2691. + <or>
  2692. + <contains string="${platform.javac}" substring="$${platforms."/>
  2693. + <contains string="${platform.java}" substring="$${platforms."/>
  2694. + <contains string="${platform.javadoc}" substring="$${platforms."/>
  2695. + </or>
  2696. + </condition>
  2697. + <fail unless="platform.home">Must set platform.home</fail>
  2698. + <fail unless="platform.bootcp">Must set platform.bootcp</fail>
  2699. + <fail unless="platform.java">Must set platform.java</fail>
  2700. + <fail unless="platform.javac">Must set platform.javac</fail>
  2701. + <fail if="platform.invalid">
  2702. + The J2SE Platform is not correctly set up.
  2703. + Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files.
  2704. + Either open the project in the IDE and setup the Platform with the same name or add it manually.
  2705. + For example like this:
  2706. + ant -Duser.properties.file=&lt;path_to_property_file&gt; jar (where you put the property "platforms.${platform.active}.home" in a .properties file)
  2707. + or ant -Dplatforms.${platform.active}.home=&lt;path_to_JDK_home&gt; jar (where no properties file is used)
  2708. + </fail>
  2709. + <available file="${manifest.file}" property="manifest.available"/>
  2710. + <condition property="splashscreen.available">
  2711. + <and>
  2712. + <not>
  2713. + <equals arg1="${application.splash}" arg2="" trim="true"/>
  2714. + </not>
  2715. + <available file="${application.splash}"/>
  2716. + </and>
  2717. + </condition>
  2718. + <condition property="main.class.available">
  2719. + <and>
  2720. + <isset property="main.class"/>
  2721. + <not>
  2722. + <equals arg1="${main.class}" arg2="" trim="true"/>
  2723. + </not>
  2724. + </and>
  2725. + </condition>
  2726. + <condition property="manifest.available+main.class">
  2727. + <and>
  2728. + <isset property="manifest.available"/>
  2729. + <isset property="main.class.available"/>
  2730. + </and>
  2731. + </condition>
  2732. + <condition property="do.mkdist">
  2733. + <and>
  2734. + <isset property="libs.CopyLibs.classpath"/>
  2735. + <not>
  2736. + <istrue value="${mkdist.disabled}"/>
  2737. + </not>
  2738. + </and>
  2739. + </condition>
  2740. + <condition property="manifest.available+main.class+mkdist.available">
  2741. + <and>
  2742. + <istrue value="${manifest.available+main.class}"/>
  2743. + <isset property="do.mkdist"/>
  2744. + </and>
  2745. + </condition>
  2746. + <condition property="manifest.available+main.class+mkdist.available+splashscreen.available">
  2747. + <and>
  2748. + <istrue value="${manifest.available+main.class+mkdist.available}"/>
  2749. + <istrue value="${splashscreen.available}"/>
  2750. + </and>
  2751. + </condition>
  2752. + <condition property="do.archive">
  2753. + <not>
  2754. + <istrue value="${jar.archive.disabled}"/>
  2755. + </not>
  2756. + </condition>
  2757. + <condition property="do.archive+manifest.available">
  2758. + <and>
  2759. + <isset property="manifest.available"/>
  2760. + <istrue value="${do.archive}"/>
  2761. + </and>
  2762. + </condition>
  2763. + <condition property="do.archive+manifest.available+main.class">
  2764. + <and>
  2765. + <istrue value="${manifest.available+main.class}"/>
  2766. + <istrue value="${do.archive}"/>
  2767. + </and>
  2768. + </condition>
  2769. + <condition property="do.archive+manifest.available+main.class+mkdist.available">
  2770. + <and>
  2771. + <istrue value="${manifest.available+main.class+mkdist.available}"/>
  2772. + <istrue value="${do.archive}"/>
  2773. + </and>
  2774. + </condition>
  2775. + <condition property="do.archive+manifest.available+main.class+mkdist.available+splashscreen.available">
  2776. + <and>
  2777. + <istrue value="${manifest.available+main.class+mkdist.available+splashscreen.available}"/>
  2778. + <istrue value="${do.archive}"/>
  2779. + </and>
  2780. + </condition>
  2781. + <condition property="have.tests">
  2782. + <or/>
  2783. + </condition>
  2784. + <condition property="have.sources">
  2785. + <or>
  2786. + <available file="${src.dir}"/>
  2787. + </or>
  2788. + </condition>
  2789. + <condition property="netbeans.home+have.tests">
  2790. + <and>
  2791. + <isset property="netbeans.home"/>
  2792. + <isset property="have.tests"/>
  2793. + </and>
  2794. + </condition>
  2795. + <condition property="no.javadoc.preview">
  2796. + <and>
  2797. + <isset property="javadoc.preview"/>
  2798. + <isfalse value="${javadoc.preview}"/>
  2799. + </and>
  2800. + </condition>
  2801. + <property name="run.jvmargs" value=""/>
  2802. + <property name="javac.compilerargs" value=""/>
  2803. + <property name="work.dir" value="${basedir}"/>
  2804. + <condition property="no.deps">
  2805. + <and>
  2806. + <istrue value="${no.dependencies}"/>
  2807. + </and>
  2808. + </condition>
  2809. + <property name="javac.debug" value="true"/>
  2810. + <property name="javadoc.preview" value="true"/>
  2811. + <property name="application.args" value=""/>
  2812. + <property name="source.encoding" value="${file.encoding}"/>
  2813. + <property name="runtime.encoding" value="${source.encoding}"/>
  2814. + <condition property="javadoc.encoding.used" value="${javadoc.encoding}">
  2815. + <and>
  2816. + <isset property="javadoc.encoding"/>
  2817. + <not>
  2818. + <equals arg1="${javadoc.encoding}" arg2=""/>
  2819. + </not>
  2820. + </and>
  2821. + </condition>
  2822. + <property name="javadoc.encoding.used" value="${source.encoding}"/>
  2823. + <property name="includes" value="**"/>
  2824. + <property name="excludes" value=""/>
  2825. + <property name="do.depend" value="false"/>
  2826. + <condition property="do.depend.true">
  2827. + <istrue value="${do.depend}"/>
  2828. + </condition>
  2829. + <path id="endorsed.classpath.path" path="${endorsed.classpath}"/>
  2830. + <condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'">
  2831. + <length length="0" string="${endorsed.classpath}" when="greater"/>
  2832. + </condition>
  2833. + <property name="jar.index" value="false"/>
  2834. + <available file="${meta.inf.dir}/persistence.xml" property="has.persistence.xml"/>
  2835. + </target>
  2836. + <target name="-post-init">
  2837. + <!-- Empty placeholder for easier customization. -->
  2838. + <!-- You can override this target in the ../build.xml file. -->
  2839. + </target>
  2840. + <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
  2841. + <fail unless="src.dir">Must set src.dir</fail>
  2842. + <fail unless="build.dir">Must set build.dir</fail>
  2843. + <fail unless="dist.dir">Must set dist.dir</fail>
  2844. + <fail unless="build.classes.dir">Must set build.classes.dir</fail>
  2845. + <fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
  2846. + <fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail>
  2847. + <fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
  2848. + <fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
  2849. + <fail unless="dist.jar">Must set dist.jar</fail>
  2850. + </target>
  2851. + <target name="-init-macrodef-property">
  2852. + <macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1">
  2853. + <attribute name="name"/>
  2854. + <attribute name="value"/>
  2855. + <sequential>
  2856. + <property name="@{name}" value="${@{value}}"/>
  2857. + </sequential>
  2858. + </macrodef>
  2859. + </target>
  2860. + <target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-macrodef-javac-with-processors">
  2861. + <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
  2862. + <attribute default="${src.dir}" name="srcdir"/>
  2863. + <attribute default="${build.classes.dir}" name="destdir"/>
  2864. + <attribute default="${javac.classpath}" name="classpath"/>
  2865. + <attribute default="${javac.processorpath}" name="processorpath"/>
  2866. + <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/>
  2867. + <attribute default="${includes}" name="includes"/>
  2868. + <attribute default="${excludes}" name="excludes"/>
  2869. + <attribute default="${javac.debug}" name="debug"/>
  2870. + <attribute default="${empty.dir}" name="sourcepath"/>
  2871. + <attribute default="${empty.dir}" name="gensrcdir"/>
  2872. + <element name="customize" optional="true"/>
  2873. + <sequential>
  2874. + <property location="${build.dir}/empty" name="empty.dir"/>
  2875. + <mkdir dir="${empty.dir}"/>
  2876. + <mkdir dir="@{apgeneratedsrcdir}"/>
  2877. + <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
  2878. + <src>
  2879. + <dirset dir="@{gensrcdir}" erroronmissingdir="false">
  2880. + <include name="*"/>
  2881. + </dirset>
  2882. + </src>
  2883. + <classpath>
  2884. + <path path="@{classpath}"/>
  2885. + </classpath>
  2886. + <compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
  2887. + <compilerarg line="${javac.compilerargs}"/>
  2888. + <compilerarg value="-processorpath"/>
  2889. + <compilerarg path="@{processorpath}:${empty.dir}"/>
  2890. + <compilerarg line="${ap.processors.internal}"/>
  2891. + <compilerarg line="${annotation.processing.processor.options}"/>
  2892. + <compilerarg value="-s"/>
  2893. + <compilerarg path="@{apgeneratedsrcdir}"/>
  2894. + <compilerarg line="${ap.proc.none.internal}"/>
  2895. + <customize/>
  2896. + </javac>
  2897. + </sequential>
  2898. + </macrodef>
  2899. + </target>
  2900. + <target depends="-init-ap-cmdline-properties" name="-init-macrodef-javac-without-processors" unless="ap.supported.internal">
  2901. + <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
  2902. + <attribute default="${src.dir}" name="srcdir"/>
  2903. + <attribute default="${build.classes.dir}" name="destdir"/>
  2904. + <attribute default="${javac.classpath}" name="classpath"/>
  2905. + <attribute default="${javac.processorpath}" name="processorpath"/>
  2906. + <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/>
  2907. + <attribute default="${includes}" name="includes"/>
  2908. + <attribute default="${excludes}" name="excludes"/>
  2909. + <attribute default="${javac.debug}" name="debug"/>
  2910. + <attribute default="${empty.dir}" name="sourcepath"/>
  2911. + <attribute default="${empty.dir}" name="gensrcdir"/>
  2912. + <element name="customize" optional="true"/>
  2913. + <sequential>
  2914. + <property location="${build.dir}/empty" name="empty.dir"/>
  2915. + <mkdir dir="${empty.dir}"/>
  2916. + <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
  2917. + <src>
  2918. + <dirset dir="@{gensrcdir}" erroronmissingdir="false">
  2919. + <include name="*"/>
  2920. + </dirset>
  2921. + </src>
  2922. + <classpath>
  2923. + <path path="@{classpath}"/>
  2924. + </classpath>
  2925. + <compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
  2926. + <compilerarg line="${javac.compilerargs}"/>
  2927. + <customize/>
  2928. + </javac>
  2929. + </sequential>
  2930. + </macrodef>
  2931. + </target>
  2932. + <target depends="-init-macrodef-javac-with-processors,-init-macrodef-javac-without-processors" name="-init-macrodef-javac">
  2933. + <macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
  2934. + <attribute default="${src.dir}" name="srcdir"/>
  2935. + <attribute default="${build.classes.dir}" name="destdir"/>
  2936. + <attribute default="${javac.classpath}" name="classpath"/>
  2937. + <sequential>
  2938. + <depend cache="${build.dir}/depcache" destdir="@{destdir}" excludes="${excludes}" includes="${includes}" srcdir="@{srcdir}">
  2939. + <classpath>
  2940. + <path path="@{classpath}"/>
  2941. + </classpath>
  2942. + </depend>
  2943. + </sequential>
  2944. + </macrodef>
  2945. + <macrodef name="force-recompile" uri="http://www.netbeans.org/ns/j2se-project/3">
  2946. + <attribute default="${build.classes.dir}" name="destdir"/>
  2947. + <sequential>
  2948. + <fail unless="javac.includes">Must set javac.includes</fail>
  2949. + <pathconvert pathsep="${line.separator}" property="javac.includes.binary">
  2950. + <path>
  2951. + <filelist dir="@{destdir}" files="${javac.includes}"/>
  2952. + </path>
  2953. + <globmapper from="*.java" to="*.class"/>
  2954. + </pathconvert>
  2955. + <tempfile deleteonexit="true" property="javac.includesfile.binary"/>
  2956. + <echo file="${javac.includesfile.binary}" message="${javac.includes.binary}"/>
  2957. + <delete>
  2958. + <files includesfile="${javac.includesfile.binary}"/>
  2959. + </delete>
  2960. + <delete file="${javac.includesfile.binary}"/>
  2961. + </sequential>
  2962. + </macrodef>
  2963. + </target>
  2964. + <target name="-init-macrodef-junit">
  2965. + <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
  2966. + <attribute default="${includes}" name="includes"/>
  2967. + <attribute default="${excludes}" name="excludes"/>
  2968. + <attribute default="**" name="testincludes"/>
  2969. + <sequential>
  2970. + <property name="junit.forkmode" value="perTest"/>
  2971. + <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
  2972. + <batchtest todir="${build.test.results.dir}"/>
  2973. + <classpath>
  2974. + <path path="${run.test.classpath}"/>
  2975. + </classpath>
  2976. + <syspropertyset>
  2977. + <propertyref prefix="test-sys-prop."/>
  2978. + <mapper from="test-sys-prop.*" to="*" type="glob"/>
  2979. + </syspropertyset>
  2980. + <formatter type="brief" usefile="false"/>
  2981. + <formatter type="xml"/>
  2982. + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
  2983. + <jvmarg line="${run.jvmargs}"/>
  2984. + </junit>
  2985. + </sequential>
  2986. + </macrodef>
  2987. + </target>
  2988. + <target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile, -profile-init-check" name="profile-init"/>
  2989. + <target name="-profile-pre-init">
  2990. + <!-- Empty placeholder for easier customization. -->
  2991. + <!-- You can override this target in the ../build.xml file. -->
  2992. + </target>
  2993. + <target name="-profile-post-init">
  2994. + <!-- Empty placeholder for easier customization. -->
  2995. + <!-- You can override this target in the ../build.xml file. -->
  2996. + </target>
  2997. + <target name="-profile-init-macrodef-profile">
  2998. + <macrodef name="resolve">
  2999. + <attribute name="name"/>
  3000. + <attribute name="value"/>
  3001. + <sequential>
  3002. + <property name="@{name}" value="${env.@{value}}"/>
  3003. + </sequential>
  3004. + </macrodef>
  3005. + <macrodef name="profile">
  3006. + <attribute default="${main.class}" name="classname"/>
  3007. + <element name="customize" optional="true"/>
  3008. + <sequential>
  3009. + <property environment="env"/>
  3010. + <resolve name="profiler.current.path" value="${profiler.info.pathvar}"/>
  3011. + <java classname="@{classname}" dir="${profiler.info.dir}" fork="true" jvm="${profiler.info.jvm}">
  3012. + <jvmarg value="${profiler.info.jvmargs.agent}"/>
  3013. + <jvmarg line="${profiler.info.jvmargs}"/>
  3014. + <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/>
  3015. + <arg line="${application.args}"/>
  3016. + <classpath>
  3017. + <path path="${run.classpath}"/>
  3018. + </classpath>
  3019. + <syspropertyset>
  3020. + <propertyref prefix="run-sys-prop."/>
  3021. + <mapper from="run-sys-prop.*" to="*" type="glob"/>
  3022. + </syspropertyset>
  3023. + <customize/>
  3024. + </java>
  3025. + </sequential>
  3026. + </macrodef>
  3027. + </target>
  3028. + <target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile" name="-profile-init-check">
  3029. + <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail>
  3030. + <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
  3031. + </target>
  3032. + <target depends="-init-debug-args" name="-init-macrodef-nbjpda">
  3033. + <macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
  3034. + <attribute default="${main.class}" name="name"/>
  3035. + <attribute default="${debug.classpath}" name="classpath"/>
  3036. + <attribute default="" name="stopclassname"/>
  3037. + <sequential>
  3038. + <nbjpdastart addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}" transport="${debug-transport}">
  3039. + <classpath>
  3040. + <path path="@{classpath}"/>
  3041. + </classpath>
  3042. + <bootclasspath>
  3043. + <path path="${platform.bootcp}"/>
  3044. + </bootclasspath>
  3045. + </nbjpdastart>
  3046. + </sequential>
  3047. + </macrodef>
  3048. + <macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1">
  3049. + <attribute default="${build.classes.dir}" name="dir"/>
  3050. + <sequential>
  3051. + <nbjpdareload>
  3052. + <fileset dir="@{dir}" includes="${fix.classes}">
  3053. + <include name="${fix.includes}*.class"/>
  3054. + </fileset>
  3055. + </nbjpdareload>
  3056. + </sequential>
  3057. + </macrodef>
  3058. + </target>
  3059. + <target name="-init-debug-args">
  3060. + <exec executable="${platform.java}" outputproperty="version-output">
  3061. + <arg value="-version"/>
  3062. + </exec>
  3063. + <condition property="have-jdk-older-than-1.4">
  3064. + <or>
  3065. + <contains string="${version-output}" substring="java version &quot;1.0"/>
  3066. + <contains string="${version-output}" substring="java version &quot;1.1"/>
  3067. + <contains string="${version-output}" substring="java version &quot;1.2"/>
  3068. + <contains string="${version-output}" substring="java version &quot;1.3"/>
  3069. + </or>
  3070. + </condition>
  3071. + <condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
  3072. + <istrue value="${have-jdk-older-than-1.4}"/>
  3073. + </condition>
  3074. + <condition else="dt_socket" property="debug-transport-by-os" value="dt_shmem">
  3075. + <os family="windows"/>
  3076. + </condition>
  3077. + <condition else="${debug-transport-by-os}" property="debug-transport" value="${debug.transport}">
  3078. + <isset property="debug.transport"/>
  3079. + </condition>
  3080. + </target>
  3081. + <target depends="-init-debug-args" name="-init-macrodef-debug">
  3082. + <macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3">
  3083. + <attribute default="${main.class}" name="classname"/>
  3084. + <attribute default="${debug.classpath}" name="classpath"/>
  3085. + <element name="customize" optional="true"/>
  3086. + <sequential>
  3087. + <java classname="@{classname}" dir="${work.dir}" fork="true" jvm="${platform.java}">
  3088. + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
  3089. + <jvmarg line="${debug-args-line}"/>
  3090. + <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
  3091. + <jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
  3092. + <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
  3093. + <jvmarg line="${run.jvmargs}"/>
  3094. + <classpath>
  3095. + <path path="@{classpath}"/>
  3096. + </classpath>
  3097. + <syspropertyset>
  3098. + <propertyref prefix="run-sys-prop."/>
  3099. + <mapper from="run-sys-prop.*" to="*" type="glob"/>
  3100. + </syspropertyset>
  3101. + <customize/>
  3102. + </java>
  3103. + </sequential>
  3104. + </macrodef>
  3105. + </target>
  3106. + <target name="-init-macrodef-java">
  3107. + <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
  3108. + <attribute default="${main.class}" name="classname"/>
  3109. + <attribute default="${run.classpath}" name="classpath"/>
  3110. + <element name="customize" optional="true"/>
  3111. + <sequential>
  3112. + <java classname="@{classname}" dir="${work.dir}" fork="true" jvm="${platform.java}">
  3113. + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
  3114. + <jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
  3115. + <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
  3116. + <jvmarg line="${run.jvmargs}"/>
  3117. + <classpath>
  3118. + <path path="@{classpath}"/>
  3119. + </classpath>
  3120. + <syspropertyset>
  3121. + <propertyref prefix="run-sys-prop."/>
  3122. + <mapper from="run-sys-prop.*" to="*" type="glob"/>
  3123. + </syspropertyset>
  3124. + <customize/>
  3125. + </java>
  3126. + </sequential>
  3127. + </macrodef>
  3128. + </target>
  3129. + <target name="-init-macrodef-copylibs">
  3130. + <macrodef name="copylibs" uri="http://www.netbeans.org/ns/j2se-project/3">
  3131. + <element name="customize" optional="true"/>
  3132. + <sequential>
  3133. + <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
  3134. + <pathconvert property="run.classpath.without.build.classes.dir">
  3135. + <path path="${run.classpath}"/>
  3136. + <map from="${build.classes.dir.resolved}" to=""/>
  3137. + </pathconvert>
  3138. + <pathconvert pathsep=" " property="jar.classpath">
  3139. + <path path="${run.classpath.without.build.classes.dir}"/>
  3140. + <chainedmapper>
  3141. + <flattenmapper/>
  3142. + <globmapper from="*" to="lib/*"/>
  3143. + </chainedmapper>
  3144. + </pathconvert>
  3145. + <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
  3146. + <copylibs compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}" manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
  3147. + <fileset dir="${build.classes.dir}"/>
  3148. + <manifest>
  3149. + <attribute name="Class-Path" value="${jar.classpath}"/>
  3150. + <customize/>
  3151. + </manifest>
  3152. + </copylibs>
  3153. + </sequential>
  3154. + </macrodef>
  3155. + </target>
  3156. + <target name="-init-presetdef-jar">
  3157. + <presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
  3158. + <jar compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}">
  3159. + <j2seproject1:fileset dir="${build.classes.dir}"/>
  3160. + </jar>
  3161. + </presetdef>
  3162. + </target>
  3163. + <target name="-init-ap-cmdline-properties">
  3164. + <property name="annotation.processing.enabled" value="true"/>
  3165. + <property name="annotation.processing.processors.list" value=""/>
  3166. + <property name="annotation.processing.processor.options" value=""/>
  3167. + <property name="annotation.processing.run.all.processors" value="true"/>
  3168. + <property name="javac.processorpath" value="${javac.classpath}"/>
  3169. + <property name="javac.test.processorpath" value="${javac.test.classpath}"/>
  3170. + <condition property="ap.supported.internal" value="true">
  3171. + <not>
  3172. + <matches pattern="1\.[0-5](\..*)?" string="${javac.source}"/>
  3173. + </not>
  3174. + </condition>
  3175. + </target>
  3176. + <target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-ap-cmdline-supported">
  3177. + <condition else="" property="ap.processors.internal" value="-processor ${annotation.processing.processors.list}">
  3178. + <isfalse value="${annotation.processing.run.all.processors}"/>
  3179. + </condition>
  3180. + <condition else="" property="ap.proc.none.internal" value="-proc:none">
  3181. + <isfalse value="${annotation.processing.enabled}"/>
  3182. + </condition>
  3183. + </target>
  3184. + <target depends="-init-ap-cmdline-properties,-init-ap-cmdline-supported" name="-init-ap-cmdline">
  3185. + <property name="ap.cmd.line.internal" value=""/>
  3186. + </target>
  3187. + <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar,-init-ap-cmdline" name="init"/>
  3188. + <!--
  3189. + ===================
  3190. + COMPILATION SECTION
  3191. + ===================
  3192. + -->
  3193. + <target name="-deps-jar-init" unless="built-jar.properties">
  3194. + <property location="${build.dir}/built-jar.properties" name="built-jar.properties"/>
  3195. + <delete file="${built-jar.properties}" quiet="true"/>
  3196. + </target>
  3197. + <target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
  3198. + <echo level="warn" message="Cycle detected: HotSwapTests was already built"/>
  3199. + </target>
  3200. + <target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
  3201. + <mkdir dir="${build.dir}"/>
  3202. + <touch file="${built-jar.properties}" verbose="false"/>
  3203. + <property file="${built-jar.properties}" prefix="already.built.jar."/>
  3204. + <antcall target="-warn-already-built-jar"/>
  3205. + <propertyfile file="${built-jar.properties}">
  3206. + <entry key="${basedir}" value=""/>
  3207. + </propertyfile>
  3208. + <antcall target="-maybe-call-dep">
  3209. + <param name="call.built.properties" value="${built-jar.properties}"/>
  3210. + <param location="${project.HotSwapTool}" name="call.subproject"/>
  3211. + <param location="${project.HotSwapTool}/build.xml" name="call.script"/>
  3212. + <param name="call.target" value="jar"/>
  3213. + <param name="transfer.built-jar.properties" value="${built-jar.properties}"/>
  3214. + </antcall>
  3215. + </target>
  3216. + <target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/>
  3217. + <target depends="init" name="-check-automatic-build">
  3218. + <available file="${build.classes.dir}/.netbeans_automatic_build" property="netbeans.automatic.build"/>
  3219. + </target>
  3220. + <target depends="init" if="netbeans.automatic.build" name="-clean-after-automatic-build">
  3221. + <antcall target="clean"/>
  3222. + </target>
  3223. + <target depends="init,deps-jar" name="-pre-pre-compile">
  3224. + <mkdir dir="${build.classes.dir}"/>
  3225. + </target>
  3226. + <target name="-pre-compile">
  3227. + <!-- Empty placeholder for easier customization. -->
  3228. + <!-- You can override this target in the ../build.xml file. -->
  3229. + </target>
  3230. + <target if="do.depend.true" name="-compile-depend">
  3231. + <pathconvert property="build.generated.subdirs">
  3232. + <dirset dir="${build.generated.sources.dir}" erroronmissingdir="false">
  3233. + <include name="*"/>
  3234. + </dirset>
  3235. + </pathconvert>
  3236. + <j2seproject3:depend srcdir="${src.dir}:${build.generated.subdirs}"/>
  3237. + </target>
  3238. + <target depends="init,deps-jar,-pre-pre-compile,-pre-compile, -copy-persistence-xml,-compile-depend" if="have.sources" name="-do-compile">
  3239. + <j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/>
  3240. + <copy todir="${build.classes.dir}">
  3241. + <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
  3242. + </copy>
  3243. + </target>
  3244. + <target if="has.persistence.xml" name="-copy-persistence-xml">
  3245. + <mkdir dir="${build.classes.dir}/META-INF"/>
  3246. + <copy todir="${build.classes.dir}/META-INF">
  3247. + <fileset dir="${meta.inf.dir}" includes="persistence.xml"/>
  3248. + </copy>
  3249. + </target>
  3250. + <target name="-post-compile">
  3251. + <!-- Empty placeholder for easier customization. -->
  3252. + <!-- You can override this target in the ../build.xml file. -->
  3253. + </target>
  3254. + <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project." name="compile"/>
  3255. + <target name="-pre-compile-single">
  3256. + <!-- Empty placeholder for easier customization. -->
  3257. + <!-- You can override this target in the ../build.xml file. -->
  3258. + </target>
  3259. + <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
  3260. + <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
  3261. + <j2seproject3:force-recompile/>
  3262. + <j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}" sourcepath="${src.dir}"/>
  3263. + </target>
  3264. + <target name="-post-compile-single">
  3265. + <!-- Empty placeholder for easier customization. -->
  3266. + <!-- You can override this target in the ../build.xml file. -->
  3267. + </target>
  3268. + <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/>
  3269. + <!--
  3270. + ====================
  3271. + JAR BUILDING SECTION
  3272. + ====================
  3273. + -->
  3274. + <target depends="init" name="-pre-pre-jar">
  3275. + <dirname file="${dist.jar}" property="dist.jar.dir"/>
  3276. + <mkdir dir="${dist.jar.dir}"/>
  3277. + </target>
  3278. + <target name="-pre-jar">
  3279. + <!-- Empty placeholder for easier customization. -->
  3280. + <!-- You can override this target in the ../build.xml file. -->
  3281. + </target>
  3282. + <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive" name="-do-jar-without-manifest" unless="manifest.available">
  3283. + <j2seproject1:jar/>
  3284. + </target>
  3285. + <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available" name="-do-jar-with-manifest" unless="manifest.available+main.class">
  3286. + <j2seproject1:jar manifest="${manifest.file}"/>
  3287. + </target>
  3288. + <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available+main.class" name="-do-jar-with-mainclass" unless="manifest.available+main.class+mkdist.available">
  3289. + <j2seproject1:jar manifest="${manifest.file}">
  3290. + <j2seproject1:manifest>
  3291. + <j2seproject1:attribute name="Main-Class" value="${main.class}"/>
  3292. + </j2seproject1:manifest>
  3293. + </j2seproject1:jar>
  3294. + <echo>To run this application from the command line without Ant, try:</echo>
  3295. + <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
  3296. + <property location="${dist.jar}" name="dist.jar.resolved"/>
  3297. + <pathconvert property="run.classpath.with.dist.jar">
  3298. + <path path="${run.classpath}"/>
  3299. + <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
  3300. + </pathconvert>
  3301. + <echo>${platform.java} -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
  3302. + </target>
  3303. + <target depends="init,compile,-pre-pre-jar,-pre-jar,-init-macrodef-copylibs" if="do.archive+manifest.available+main.class+mkdist.available+splashscreen.available" name="-do-jar-with-libraries-and-splashscreen">
  3304. + <basename file="${application.splash}" property="splashscreen.basename"/>
  3305. + <mkdir dir="${build.classes.dir}/META-INF"/>
  3306. + <copy failonerror="false" file="${application.splash}" todir="${build.classes.dir}/META-INF"/>
  3307. + <j2seproject3:copylibs>
  3308. + <customize>
  3309. + <attribute name="Main-Class" value="${main.class}"/>
  3310. + <attribute name="SplashScreen-Image" value="META-INF/${splashscreen.basename}"/>
  3311. + </customize>
  3312. + </j2seproject3:copylibs>
  3313. + <echo>To run this application from the command line without Ant, try:</echo>
  3314. + <property location="${dist.jar}" name="dist.jar.resolved"/>
  3315. + <echo>${platform.java} -jar "${dist.jar.resolved}"</echo>
  3316. + </target>
  3317. + <target depends="init,compile,-pre-pre-jar,-pre-jar,-init-macrodef-copylibs" if="do.archive+manifest.available+main.class+mkdist.available" name="-do-jar-with-libraries" unless="splashscreen.available">
  3318. + <j2seproject3:copylibs>
  3319. + <customize>
  3320. + <attribute name="Main-Class" value="${main.class}"/>
  3321. + </customize>
  3322. + </j2seproject3:copylibs>
  3323. + <echo>To run this application from the command line without Ant, try:</echo>
  3324. + <property location="${dist.jar}" name="dist.jar.resolved"/>
  3325. + <echo>${platform.java} -jar "${dist.jar.resolved}"</echo>
  3326. + </target>
  3327. + <target name="-post-jar">
  3328. + <!-- Empty placeholder for easier customization. -->
  3329. + <!-- You can override this target in the ../build.xml file. -->
  3330. + </target>
  3331. + <target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries-and-splashscreen,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/>
  3332. + <!--
  3333. + =================
  3334. + EXECUTION SECTION
  3335. + =================
  3336. + -->
  3337. + <target depends="init,compile" description="Run a main class." name="run">
  3338. + <j2seproject1:java>
  3339. + <customize>
  3340. + <arg line="${application.args}"/>
  3341. + </customize>
  3342. + </j2seproject1:java>
  3343. + </target>
  3344. + <target name="-do-not-recompile">
  3345. + <property name="javac.includes.binary" value=""/>
  3346. + </target>
  3347. + <target depends="init,compile-single" name="run-single">
  3348. + <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
  3349. + <j2seproject1:java classname="${run.class}"/>
  3350. + </target>
  3351. + <target depends="init,compile-test-single" name="run-test-with-main">
  3352. + <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
  3353. + <j2seproject1:java classname="${run.class}" classpath="${run.test.classpath}"/>
  3354. + </target>
  3355. + <!--
  3356. + =================
  3357. + DEBUGGING SECTION
  3358. + =================
  3359. + -->
  3360. + <target depends="init" if="netbeans.home" name="-debug-start-debugger">
  3361. + <j2seproject1:nbjpdastart name="${debug.class}"/>
  3362. + </target>
  3363. + <target depends="init" if="netbeans.home" name="-debug-start-debugger-main-test">
  3364. + <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${debug.class}"/>
  3365. + </target>
  3366. + <target depends="init,compile" name="-debug-start-debuggee">
  3367. + <j2seproject3:debug>
  3368. + <customize>
  3369. + <arg line="${application.args}"/>
  3370. + </customize>
  3371. + </j2seproject3:debug>
  3372. + </target>
  3373. + <target depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE." if="netbeans.home" name="debug"/>
  3374. + <target depends="init" if="netbeans.home" name="-debug-start-debugger-stepinto">
  3375. + <j2seproject1:nbjpdastart stopclassname="${main.class}"/>
  3376. + </target>
  3377. + <target depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee" if="netbeans.home" name="debug-stepinto"/>
  3378. + <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-single">
  3379. + <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
  3380. + <j2seproject3:debug classname="${debug.class}"/>
  3381. + </target>
  3382. + <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single"/>
  3383. + <target depends="init,compile-test-single" if="netbeans.home" name="-debug-start-debuggee-main-test">
  3384. + <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
  3385. + <j2seproject3:debug classname="${debug.class}" classpath="${debug.test.classpath}"/>
  3386. + </target>
  3387. + <target depends="init,compile-test-single,-debug-start-debugger-main-test,-debug-start-debuggee-main-test" if="netbeans.home" name="debug-test-with-main"/>
  3388. + <target depends="init" name="-pre-debug-fix">
  3389. + <fail unless="fix.includes">Must set fix.includes</fail>
  3390. + <property name="javac.includes" value="${fix.includes}.java"/>
  3391. + </target>
  3392. + <target depends="init,-pre-debug-fix,compile-single" if="netbeans.home" name="-do-debug-fix">
  3393. + <j2seproject1:nbjpdareload/>
  3394. + </target>
  3395. + <target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/>
  3396. + <!--
  3397. + =================
  3398. + PROFILING SECTION
  3399. + =================
  3400. + -->
  3401. + <target depends="profile-init,compile" description="Profile a project in the IDE." if="netbeans.home" name="profile">
  3402. + <nbprofiledirect>
  3403. + <classpath>
  3404. + <path path="${run.classpath}"/>
  3405. + </classpath>
  3406. + </nbprofiledirect>
  3407. + <profile/>
  3408. + </target>
  3409. + <target depends="profile-init,compile-single" description="Profile a selected class in the IDE." if="netbeans.home" name="profile-single">
  3410. + <fail unless="profile.class">Must select one file in the IDE or set profile.class</fail>
  3411. + <nbprofiledirect>
  3412. + <classpath>
  3413. + <path path="${run.classpath}"/>
  3414. + </classpath>
  3415. + </nbprofiledirect>
  3416. + <profile classname="${profile.class}"/>
  3417. + </target>
  3418. + <!--
  3419. + =========================
  3420. + APPLET PROFILING SECTION
  3421. + =========================
  3422. + -->
  3423. + <target depends="profile-init,compile-single" if="netbeans.home" name="profile-applet">
  3424. + <nbprofiledirect>
  3425. + <classpath>
  3426. + <path path="${run.classpath}"/>
  3427. + </classpath>
  3428. + </nbprofiledirect>
  3429. + <profile classname="sun.applet.AppletViewer">
  3430. + <customize>
  3431. + <arg value="${applet.url}"/>
  3432. + </customize>
  3433. + </profile>
  3434. + </target>
  3435. + <!--
  3436. + =========================
  3437. + TESTS PROFILING SECTION
  3438. + =========================
  3439. + -->
  3440. + <target depends="profile-init,compile-test-single" if="netbeans.home" name="profile-test-single">
  3441. + <nbprofiledirect>
  3442. + <classpath>
  3443. + <path path="${run.test.classpath}"/>
  3444. + </classpath>
  3445. + </nbprofiledirect>
  3446. + <junit dir="${profiler.info.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" jvm="${profiler.info.jvm}" showoutput="true">
  3447. + <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/>
  3448. + <jvmarg value="${profiler.info.jvmargs.agent}"/>
  3449. + <jvmarg line="${profiler.info.jvmargs}"/>
  3450. + <test name="${profile.class}"/>
  3451. + <classpath>
  3452. + <path path="${run.test.classpath}"/>
  3453. + </classpath>
  3454. + <syspropertyset>
  3455. + <propertyref prefix="test-sys-prop."/>
  3456. + <mapper from="test-sys-prop.*" to="*" type="glob"/>
  3457. + </syspropertyset>
  3458. + <formatter type="brief" usefile="false"/>
  3459. + <formatter type="xml"/>
  3460. + </junit>
  3461. + </target>
  3462. + <!--
  3463. + ===============
  3464. + JAVADOC SECTION
  3465. + ===============
  3466. + -->
  3467. + <target depends="init" if="have.sources" name="-javadoc-build">
  3468. + <mkdir dir="${dist.javadoc.dir}"/>
  3469. + <javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" executable="${platform.javadoc}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
  3470. + <classpath>
  3471. + <path path="${javac.classpath}"/>
  3472. + </classpath>
  3473. + <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
  3474. + <filename name="**/*.java"/>
  3475. + </fileset>
  3476. + <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
  3477. + <include name="**/*.java"/>
  3478. + </fileset>
  3479. + </javadoc>
  3480. + <copy todir="${dist.javadoc.dir}">
  3481. + <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
  3482. + <filename name="**/doc-files/**"/>
  3483. + </fileset>
  3484. + <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
  3485. + <include name="**/doc-files/**"/>
  3486. + </fileset>
  3487. + </copy>
  3488. + </target>
  3489. + <target depends="init,-javadoc-build" if="netbeans.home" name="-javadoc-browse" unless="no.javadoc.preview">
  3490. + <nbbrowse file="${dist.javadoc.dir}/index.html"/>
  3491. + </target>
  3492. + <target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/>
  3493. + <!--
  3494. + =========================
  3495. + JUNIT COMPILATION SECTION
  3496. + =========================
  3497. + -->
  3498. + <target depends="init,compile" if="have.tests" name="-pre-pre-compile-test">
  3499. + <mkdir dir="${build.test.classes.dir}"/>
  3500. + </target>
  3501. + <target name="-pre-compile-test">
  3502. + <!-- Empty placeholder for easier customization. -->
  3503. + <!-- You can override this target in the ../build.xml file. -->
  3504. + </target>
  3505. + <target if="do.depend.true" name="-compile-test-depend">
  3506. + <j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir=""/>
  3507. + </target>
  3508. + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test">
  3509. + <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" processorpath="${javac.test.processorpath}" srcdir=""/>
  3510. + <copy todir="${build.test.classes.dir}"/>
  3511. + </target>
  3512. + <target name="-post-compile-test">
  3513. + <!-- Empty placeholder for easier customization. -->
  3514. + <!-- You can override this target in the ../build.xml file. -->
  3515. + </target>
  3516. + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test" name="compile-test"/>
  3517. + <target name="-pre-compile-test-single">
  3518. + <!-- Empty placeholder for easier customization. -->
  3519. + <!-- You can override this target in the ../build.xml file. -->
  3520. + </target>
  3521. + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single">
  3522. + <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
  3523. + <j2seproject3:force-recompile destdir="${build.test.classes.dir}"/>
  3524. + <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" processorpath="${javac.test.processorpath}" sourcepath="" srcdir=""/>
  3525. + <copy todir="${build.test.classes.dir}"/>
  3526. + </target>
  3527. + <target name="-post-compile-test-single">
  3528. + <!-- Empty placeholder for easier customization. -->
  3529. + <!-- You can override this target in the ../build.xml file. -->
  3530. + </target>
  3531. + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/>
  3532. + <!--
  3533. + =======================
  3534. + JUNIT EXECUTION SECTION
  3535. + =======================
  3536. + -->
  3537. + <target depends="init" if="have.tests" name="-pre-test-run">
  3538. + <mkdir dir="${build.test.results.dir}"/>
  3539. + </target>
  3540. + <target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run">
  3541. + <j2seproject3:junit testincludes="**/*Test.java"/>
  3542. + </target>
  3543. + <target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run">
  3544. + <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
  3545. + </target>
  3546. + <target depends="init" if="have.tests" name="test-report"/>
  3547. + <target depends="init" if="netbeans.home+have.tests" name="-test-browse"/>
  3548. + <target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests." name="test"/>
  3549. + <target depends="init" if="have.tests" name="-pre-test-run-single">
  3550. + <mkdir dir="${build.test.results.dir}"/>
  3551. + </target>
  3552. + <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single">
  3553. + <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
  3554. + <j2seproject3:junit excludes="" includes="${test.includes}"/>
  3555. + </target>
  3556. + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single">
  3557. + <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
  3558. + </target>
  3559. + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/>
  3560. + <!--
  3561. + =======================
  3562. + JUNIT DEBUGGING SECTION
  3563. + =======================
  3564. + -->
  3565. + <target depends="init,compile-test" if="have.tests" name="-debug-start-debuggee-test">
  3566. + <fail unless="test.class">Must select one file in the IDE or set test.class</fail>
  3567. + <property location="${build.test.results.dir}/TEST-${test.class}.xml" name="test.report.file"/>
  3568. + <delete file="${test.report.file}"/>
  3569. + <mkdir dir="${build.test.results.dir}"/>
  3570. + <j2seproject3:debug classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" classpath="${ant.home}/lib/ant.jar:${ant.home}/lib/ant-junit.jar:${debug.test.classpath}">
  3571. + <customize>
  3572. + <syspropertyset>
  3573. + <propertyref prefix="test-sys-prop."/>
  3574. + <mapper from="test-sys-prop.*" to="*" type="glob"/>
  3575. + </syspropertyset>
  3576. + <arg value="${test.class}"/>
  3577. + <arg value="showoutput=true"/>
  3578. + <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter"/>
  3579. + <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,${test.report.file}"/>
  3580. + </customize>
  3581. + </j2seproject3:debug>
  3582. + </target>
  3583. + <target depends="init,compile-test" if="netbeans.home+have.tests" name="-debug-start-debugger-test">
  3584. + <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${test.class}"/>
  3585. + </target>
  3586. + <target depends="init,compile-test-single,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/>
  3587. + <target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test">
  3588. + <j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
  3589. + </target>
  3590. + <target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/>
  3591. + <!--
  3592. + =========================
  3593. + APPLET EXECUTION SECTION
  3594. + =========================
  3595. + -->
  3596. + <target depends="init,compile-single" name="run-applet">
  3597. + <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
  3598. + <j2seproject1:java classname="sun.applet.AppletViewer">
  3599. + <customize>
  3600. + <arg value="${applet.url}"/>
  3601. + </customize>
  3602. + </j2seproject1:java>
  3603. + </target>
  3604. + <!--
  3605. + =========================
  3606. + APPLET DEBUGGING SECTION
  3607. + =========================
  3608. + -->
  3609. + <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-applet">
  3610. + <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
  3611. + <j2seproject3:debug classname="sun.applet.AppletViewer">
  3612. + <customize>
  3613. + <arg value="${applet.url}"/>
  3614. + </customize>
  3615. + </j2seproject3:debug>
  3616. + </target>
  3617. + <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet" if="netbeans.home" name="debug-applet"/>
  3618. + <!--
  3619. + ===============
  3620. + CLEANUP SECTION
  3621. + ===============
  3622. + -->
  3623. + <target name="-deps-clean-init" unless="built-clean.properties">
  3624. + <property location="${build.dir}/built-clean.properties" name="built-clean.properties"/>
  3625. + <delete file="${built-clean.properties}" quiet="true"/>
  3626. + </target>
  3627. + <target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
  3628. + <echo level="warn" message="Cycle detected: HotSwapTests was already built"/>
  3629. + </target>
  3630. + <target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
  3631. + <mkdir dir="${build.dir}"/>
  3632. + <touch file="${built-clean.properties}" verbose="false"/>
  3633. + <property file="${built-clean.properties}" prefix="already.built.clean."/>
  3634. + <antcall target="-warn-already-built-clean"/>
  3635. + <propertyfile file="${built-clean.properties}">
  3636. + <entry key="${basedir}" value=""/>
  3637. + </propertyfile>
  3638. + <antcall target="-maybe-call-dep">
  3639. + <param name="call.built.properties" value="${built-clean.properties}"/>
  3640. + <param location="${project.HotSwapTool}" name="call.subproject"/>
  3641. + <param location="${project.HotSwapTool}/build.xml" name="call.script"/>
  3642. + <param name="call.target" value="clean"/>
  3643. + <param name="transfer.built-clean.properties" value="${built-clean.properties}"/>
  3644. + </antcall>
  3645. + </target>
  3646. + <target depends="init" name="-do-clean">
  3647. + <delete dir="${build.dir}"/>
  3648. + <delete dir="${dist.dir}" followsymlinks="false" includeemptydirs="true"/>
  3649. + </target>
  3650. + <target name="-post-clean">
  3651. + <!-- Empty placeholder for easier customization. -->
  3652. + <!-- You can override this target in the ../build.xml file. -->
  3653. + </target>
  3654. + <target depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products." name="clean"/>
  3655. + <target name="-check-call-dep">
  3656. + <property file="${call.built.properties}" prefix="already.built."/>
  3657. + <condition property="should.call.dep">
  3658. + <not>
  3659. + <isset property="already.built.${call.subproject}"/>
  3660. + </not>
  3661. + </condition>
  3662. + </target>
  3663. + <target depends="-check-call-dep" if="should.call.dep" name="-maybe-call-dep">
  3664. + <ant antfile="${call.script}" inheritall="false" target="${call.target}">
  3665. + <propertyset>
  3666. + <propertyref prefix="transfer."/>
  3667. + <mapper from="transfer.*" to="*" type="glob"/>
  3668. + </propertyset>
  3669. + </ant>
  3670. + </target>
  3671. +</project>
  3672. diff -r f5603a6e5042 hotswaptest/HotSwapTests/nbproject/configs/Run_All_Tests.properties
  3673. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  3674. +++ b/hotswaptest/HotSwapTests/nbproject/configs/Run_All_Tests.properties Fri Dec 17 13:23:04 2010 +0100
  3675. @@ -0,0 +1,2 @@
  3676. +$label=Run All Tests
  3677. +run.jvmargs=\ -Xdebug -XX:TraceRedefineClasses=4 -Xrunjdwp:transport=dt_socket,server=y,address=4000,suspend=n
  3678. diff -r f5603a6e5042 hotswaptest/HotSwapTests/nbproject/configs/Run_Natives_Tests.properties
  3679. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  3680. +++ b/hotswaptest/HotSwapTests/nbproject/configs/Run_Natives_Tests.properties Fri Dec 17 13:23:04 2010 +0100
  3681. @@ -0,0 +1,2 @@
  3682. +$label=Run Natives Tests
  3683. +run.jvmargs=\ -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=4000,suspend=n
  3684. diff -r f5603a6e5042 hotswaptest/HotSwapTests/nbproject/genfiles.properties
  3685. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  3686. +++ b/hotswaptest/HotSwapTests/nbproject/genfiles.properties Fri Dec 17 13:23:04 2010 +0100
  3687. @@ -0,0 +1,8 @@
  3688. +nbbuild.xml.data.CRC32=c8ab650e
  3689. +nbbuild.xml.script.CRC32=2ea92a55
  3690. +nbbuild.xml.stylesheet.CRC32=958a1d3e@1.26.2.45
  3691. +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
  3692. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
  3693. +nbproject/build-impl.xml.data.CRC32=c46425e2
  3694. +nbproject/build-impl.xml.script.CRC32=2aba14d0
  3695. +nbproject/build-impl.xml.stylesheet.CRC32=fce8b508@1.40.0.45
  3696. diff -r f5603a6e5042 hotswaptest/HotSwapTests/nbproject/project.properties
  3697. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  3698. +++ b/hotswaptest/HotSwapTests/nbproject/project.properties Fri Dec 17 13:23:04 2010 +0100
  3699. @@ -0,0 +1,76 @@
  3700. +application.title=HotSwapTests
  3701. +application.vendor=Thomas
  3702. +build.classes.dir=${build.dir}/classes
  3703. +build.classes.excludes=**/*.java,**/*.form
  3704. +# This directory is removed when the project is cleaned:
  3705. +build.dir=build
  3706. +build.generated.dir=${build.dir}/generated
  3707. +build.generated.sources.dir=${build.dir}/generated-sources
  3708. +# Only compile against the classpath explicitly listed here:
  3709. +build.sysclasspath=ignore
  3710. +build.test.classes.dir=${build.dir}/test/classes
  3711. +build.test.results.dir=${build.dir}/test/results
  3712. +buildfile=build.xml
  3713. +# Uncomment to specify the preferred debugger connection transport:
  3714. +#debug.transport=dt_socket
  3715. +debug.classpath=\
  3716. + ${run.classpath}
  3717. +debug.test.classpath=\
  3718. + ${run.test.classpath}
  3719. +# This directory is removed when the project is cleaned:
  3720. +dist.dir=dist
  3721. +dist.jar=${dist.dir}/HotSwapTests.jar
  3722. +dist.javadoc.dir=${dist.dir}/javadoc
  3723. +endorsed.classpath=
  3724. +excludes=
  3725. +file.reference.asm-all-3.2.jar=../lib/asm-all-3.2.jar
  3726. +file.reference.HotSwapTests-src=src
  3727. +file.reference.tools.jar=../lib/tools.jar
  3728. +includes=**
  3729. +jar.compress=false
  3730. +javac.classpath=\
  3731. + ${libs.junit_4.classpath}:\
  3732. + ${reference.HotSwapTool.jar}:\
  3733. + ${file.reference.asm-all-3.2.jar}:\
  3734. + ${file.reference.tools.jar}
  3735. +# Space-separated list of extra javac options
  3736. +javac.compilerargs=
  3737. +javac.deprecation=false
  3738. +javac.source=1.6
  3739. +javac.target=1.6
  3740. +javac.test.classpath=\
  3741. + ${javac.classpath}:\
  3742. + ${build.classes.dir}:\
  3743. + ${libs.junit.classpath}:\
  3744. + ${libs.junit_4.classpath}
  3745. +javadoc.additionalparam=
  3746. +javadoc.author=false
  3747. +javadoc.encoding=${source.encoding}
  3748. +javadoc.noindex=false
  3749. +javadoc.nonavbar=false
  3750. +javadoc.notree=false
  3751. +javadoc.private=false
  3752. +javadoc.splitindex=true
  3753. +javadoc.use=true
  3754. +javadoc.version=false
  3755. +javadoc.windowtitle=
  3756. +jaxbwiz.endorsed.dirs="${netbeans.home}/../ide12/modules/ext/jaxb/api"
  3757. +jnlp.codebase.type=local
  3758. +jnlp.descriptor=application
  3759. +jnlp.enabled=false
  3760. +jnlp.offline-allowed=false
  3761. +jnlp.signed=false
  3762. +main.class=at.ssw.hotswap.test.Main
  3763. +manifest.file=manifest.mf
  3764. +meta.inf.dir=${src.dir}/META-INF
  3765. +platform.active=JDK_1.7_HotSwap
  3766. +project.HotSwapTool=../HotSwapTool
  3767. +reference.HotSwapTool.jar=${project.HotSwapTool}/dist/HotSwapTool.jar
  3768. +run.classpath=\
  3769. + ${javac.classpath}:\
  3770. + ${build.classes.dir}
  3771. +run.test.classpath=\
  3772. + ${javac.test.classpath}:\
  3773. + ${build.test.classes.dir}
  3774. +source.encoding=UTF-8
  3775. +src.dir=${file.reference.HotSwapTests-src}
  3776. diff -r f5603a6e5042 hotswaptest/HotSwapTests/nbproject/project.xml
  3777. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  3778. +++ b/hotswaptest/HotSwapTests/nbproject/project.xml Fri Dec 17 13:23:04 2010 +0100
  3779. @@ -0,0 +1,25 @@
  3780. +<?xml version="1.0" encoding="UTF-8"?>
  3781. +<project xmlns="http://www.netbeans.org/ns/project/1">
  3782. + <type>org.netbeans.modules.java.j2seproject</type>
  3783. + <configuration>
  3784. + <data xmlns="http://www.netbeans.org/ns/j2se-project/3">
  3785. + <name>HotSwapTests</name>
  3786. + <minimum-ant-version>1.6.5</minimum-ant-version>
  3787. + <explicit-platform explicit-source-supported="true"/>
  3788. + <source-roots>
  3789. + <root id="src.dir"/>
  3790. + </source-roots>
  3791. + <test-roots/>
  3792. + </data>
  3793. + <references xmlns="http://www.netbeans.org/ns/ant-project-references/1">
  3794. + <reference>
  3795. + <foreign-project>HotSwapTool</foreign-project>
  3796. + <artifact-type>jar</artifact-type>
  3797. + <script>build.xml</script>
  3798. + <target>jar</target>
  3799. + <clean-target>clean</clean-target>
  3800. + <id>jar</id>
  3801. + </reference>
  3802. + </references>
  3803. + </configuration>
  3804. +</project>
  3805. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/CompleteTestSuite.java
  3806. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  3807. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/CompleteTestSuite.java Fri Dec 17 13:23:04 2010 +0100
  3808. @@ -0,0 +1,56 @@
  3809. +/*
  3810. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  3811. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  3812. + *
  3813. + * This code is free software; you can redistribute it and/or modify it
  3814. + * under the terms of the GNU General Public License version 2 only, as
  3815. + * published by the Free Software Foundation.
  3816. + *
  3817. + * This code is distributed in the hope that it will be useful, but WITHOUT
  3818. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  3819. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  3820. + * version 2 for more details (a copy is included in the LICENSE file that
  3821. + * accompanied this code).
  3822. + *
  3823. + * You should have received a copy of the GNU General Public License version
  3824. + * 2 along with this work; if not, write to the Free Software Foundation,
  3825. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  3826. + *
  3827. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  3828. + * or visit www.oracle.com if you need additional information or have any
  3829. + * questions.
  3830. + *
  3831. + */
  3832. +
  3833. +package at.ssw.hotswap.test;
  3834. +
  3835. +import at.ssw.hotswap.test.accesstests.AccessTestSuite;
  3836. +import org.junit.runner.RunWith;
  3837. +import org.junit.runners.Suite;
  3838. +
  3839. +import at.ssw.hotswap.test.body.BodyTestSuite;
  3840. +import at.ssw.hotswap.test.eval.EvalTestSuite;
  3841. +import at.ssw.hotswap.test.fields.FieldsTestSuite;
  3842. +import at.ssw.hotswap.test.methods.MethodsTestSuite;
  3843. +import at.ssw.hotswap.test.natives.NativesTestSuite;
  3844. +import at.ssw.hotswap.test.transformer.TransformerTestSuite;
  3845. +import at.ssw.hotswap.test.structural.StructuralTestSuite;
  3846. +
  3847. +/**
  3848. + * Summarizes all available test suites.
  3849. + *
  3850. + * @author Thomas Wuerthinger
  3851. + */
  3852. +@RunWith(Suite.class)
  3853. +@Suite.SuiteClasses({
  3854. + BodyTestSuite.class,
  3855. + EvalTestSuite.class,
  3856. + MethodsTestSuite.class,
  3857. + FieldsTestSuite.class,
  3858. + StructuralTestSuite.class,
  3859. + TransformerTestSuite.class,
  3860. + NativesTestSuite.class,
  3861. + AccessTestSuite.class
  3862. +})
  3863. +public class CompleteTestSuite {
  3864. +}
  3865. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/Main.java
  3866. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  3867. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/Main.java Fri Dec 17 13:23:04 2010 +0100
  3868. @@ -0,0 +1,156 @@
  3869. +/*
  3870. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  3871. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  3872. + *
  3873. + * This code is free software; you can redistribute it and/or modify it
  3874. + * under the terms of the GNU General Public License version 2 only, as
  3875. + * published by the Free Software Foundation.
  3876. + *
  3877. + * This code is distributed in the hope that it will be useful, but WITHOUT
  3878. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  3879. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  3880. + * version 2 for more details (a copy is included in the LICENSE file that
  3881. + * accompanied this code).
  3882. + *
  3883. + * You should have received a copy of the GNU General Public License version
  3884. + * 2 along with this work; if not, write to the Free Software Foundation,
  3885. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  3886. + *
  3887. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  3888. + * or visit www.oracle.com if you need additional information or have any
  3889. + * questions.
  3890. + *
  3891. + */
  3892. +
  3893. +package at.ssw.hotswap.test;
  3894. +
  3895. +import at.ssw.hotswap.HotSwapTool;
  3896. +import java.io.File;
  3897. +import java.util.HashSet;
  3898. +import java.util.Set;
  3899. +import org.junit.runner.Description;
  3900. +import org.junit.runner.JUnitCore;
  3901. +import org.junit.runner.Request;
  3902. +import org.junit.runner.manipulation.Filter;
  3903. +import org.junit.runner.notification.Failure;
  3904. +import org.junit.runner.notification.RunListener;
  3905. +
  3906. +/**
  3907. + * Main class for running class redefinition tests. Make sure that the execution directory is set such that this class file
  3908. + * can be reached via "at/ssw/hotswap/test/Main.class".
  3909. + *
  3910. + * There are different levels of redefinition:
  3911. + * Swap method bodies < add/remove methods < add/remove fields < add/remove super type
  3912. + *
  3913. + * Make sure that the application is started with a Java debug agent on port 4000. If you specify an argument, only tests
  3914. + * containing the specified string are executed.
  3915. + *
  3916. + * Example usage:
  3917. + * <pre>java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=4000,suspend=n at.ssw.hotswap.test.Main SimpleTest</pre>
  3918. + *
  3919. + * @author Thomas Wuerthinger
  3920. + *
  3921. + * Usage:
  3922. + * If a first parameter is given, then only tests with a name containing this parameter are executed.
  3923. + *
  3924. + * Default values of system properties that can be overwritten:
  3925. + * -Dhotswap.trace=0
  3926. + *
  3927. + */
  3928. +public class Main {
  3929. +
  3930. + private static int failedCount;
  3931. + private static int finishedCount;
  3932. + private static String failureString = "";
  3933. +
  3934. + public static void main(final String[] args) {
  3935. +
  3936. + boolean runNativeTests = true;
  3937. + String nativeLibraryName = new File("../../../HotSwapTestsNatives/dist/" + System.mapLibraryName("libHotSwapTestsNatives")).getAbsolutePath();
  3938. + try {
  3939. + System.out.println("Load native library: ");
  3940. + System.load(nativeLibraryName);
  3941. + } catch(UnsatisfiedLinkError e) {
  3942. + System.out.println("WARNING: Could not load native library from path " + nativeLibraryName);
  3943. + System.out.println("Disabling native tests");
  3944. + runNativeTests = false;
  3945. + }
  3946. +
  3947. + System.out.println("Running JUnit tests: ");
  3948. +
  3949. + JUnitCore core = new JUnitCore();
  3950. + core.addListener(runListener);
  3951. + Request request = Request.classes(CompleteTestSuite.class);
  3952. + HotSwapTool.setTraceLevel(Integer.parseInt(System.getProperty("hotswap.trace", "0")));
  3953. +
  3954. + // Filter the request?
  3955. + if (args.length > 0) {
  3956. +
  3957. + System.out.println("Only run tests containing \"" + args[0] + "\"");
  3958. +
  3959. + request = request.filterWith(new Filter() {
  3960. +
  3961. + @Override
  3962. + public String describe() {
  3963. + return "Filter";
  3964. + }
  3965. +
  3966. + private Set<Description> childrenToRun = new HashSet<Description>();
  3967. +
  3968. + @Override
  3969. + public boolean shouldRun(Description d) {
  3970. + System.out.println(d.getDisplayName());
  3971. +
  3972. + if (d.getDisplayName().contains(args[0]) || childrenToRun.contains(d)) {
  3973. + childrenToRun.addAll(d.getChildren());
  3974. + return true;
  3975. + }
  3976. +
  3977. + // explicitly check if any children want to run
  3978. + for (Description each : d.getChildren()) {
  3979. + if (shouldRun(each)) {
  3980. + return true;
  3981. + }
  3982. + }
  3983. +
  3984. + return false;
  3985. + }
  3986. + });
  3987. + }
  3988. +
  3989. + long startTime = System.currentTimeMillis();
  3990. + core.run(request);
  3991. + long time = System.currentTimeMillis() - startTime;
  3992. +
  3993. + System.out.println("" + (finishedCount - failedCount) + " of " + finishedCount + " tests are OK!");
  3994. + System.out.println("Time: " + ((double) time) / 1000);
  3995. + if (failedCount == 0) {
  3996. + System.out.println("ALL OK");
  3997. + } else {
  3998. + System.out.println(failedCount + " FAILURES: " + failureString);
  3999. + }
  4000. + }
  4001. +
  4002. + private static RunListener runListener = new RunListener() {
  4003. +
  4004. + @Override
  4005. + public void testStarted(Description description) throws Exception {
  4006. + System.out.println("============================================================");
  4007. + System.out.println("Test started: " + description.getDisplayName());
  4008. + }
  4009. +
  4010. + @Override
  4011. + public void testFailure(Failure failure) throws Exception {
  4012. + System.out.println("Test failure: " + failure.getMessage());
  4013. + failure.getException().printStackTrace();
  4014. + failedCount++;
  4015. + failureString += failure.getDescription().getDisplayName() + " ";
  4016. + }
  4017. +
  4018. + @Override
  4019. + public void testFinished(Description description) throws Exception {
  4020. + System.out.println("Test finished: " + description.getDisplayName());
  4021. + finishedCount++;
  4022. + }
  4023. + };
  4024. +}
  4025. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/TestUtil.java
  4026. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  4027. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/TestUtil.java Fri Dec 17 13:23:04 2010 +0100
  4028. @@ -0,0 +1,51 @@
  4029. +/*
  4030. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  4031. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4032. + *
  4033. + * This code is free software; you can redistribute it and/or modify it
  4034. + * under the terms of the GNU General Public License version 2 only, as
  4035. + * published by the Free Software Foundation.
  4036. + *
  4037. + * This code is distributed in the hope that it will be useful, but WITHOUT
  4038. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4039. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4040. + * version 2 for more details (a copy is included in the LICENSE file that
  4041. + * accompanied this code).
  4042. + *
  4043. + * You should have received a copy of the GNU General Public License version
  4044. + * 2 along with this work; if not, write to the Free Software Foundation,
  4045. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4046. + *
  4047. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4048. + * or visit www.oracle.com if you need additional information or have any
  4049. + * questions.
  4050. + *
  4051. + */
  4052. +
  4053. +package at.ssw.hotswap.test;
  4054. +
  4055. +import junit.framework.Assert;
  4056. +
  4057. +/**
  4058. + *
  4059. + * Utility methods for unit testing.
  4060. + *
  4061. + * @author Thomas Wuerthinger
  4062. + */
  4063. +public class TestUtil {
  4064. +
  4065. + public static int assertException(Class exceptionClass, Runnable run) {
  4066. +
  4067. + try {
  4068. + run.run();
  4069. + } catch(Throwable t) {
  4070. + if (t.getClass().equals(exceptionClass)) {
  4071. + return t.getStackTrace()[0].getLineNumber();
  4072. + }
  4073. + Assert.assertTrue("An exception of type " + t.getClass().getSimpleName() + " instead of " + exceptionClass.getSimpleName() + " has been thrown!", false);
  4074. + }
  4075. +
  4076. + Assert.assertTrue("No exception has been thrown!", false);
  4077. + return -1;
  4078. + }
  4079. +}
  4080. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/ClassAccess.java
  4081. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  4082. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/ClassAccess.java Fri Dec 17 13:23:04 2010 +0100
  4083. @@ -0,0 +1,39 @@
  4084. +/*
  4085. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  4086. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4087. + *
  4088. + * This code is free software; you can redistribute it and/or modify it
  4089. + * under the terms of the GNU General Public License version 2 only, as
  4090. + * published by the Free Software Foundation.
  4091. + *
  4092. + * This code is distributed in the hope that it will be useful, but WITHOUT
  4093. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4094. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4095. + * version 2 for more details (a copy is included in the LICENSE file that
  4096. + * accompanied this code).
  4097. + *
  4098. + * You should have received a copy of the GNU General Public License version
  4099. + * 2 along with this work; if not, write to the Free Software Foundation,
  4100. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4101. + *
  4102. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4103. + * or visit www.oracle.com if you need additional information or have any
  4104. + * questions.
  4105. + *
  4106. + */
  4107. +package at.ssw.hotswap.test.access;
  4108. +
  4109. +import java.util.List;
  4110. +
  4111. +/**
  4112. + * @author Kerstin Breiteneder
  4113. + * @author Christoph Wimberger
  4114. + */
  4115. +public interface ClassAccess {
  4116. +
  4117. + public String getName();
  4118. +
  4119. + public MethodAccess findMethod(String method);
  4120. +
  4121. + public List<MethodAccess> getMethods();
  4122. +}
  4123. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/MethodAccess.java
  4124. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  4125. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/MethodAccess.java Fri Dec 17 13:23:04 2010 +0100
  4126. @@ -0,0 +1,43 @@
  4127. +/*
  4128. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  4129. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4130. + *
  4131. + * This code is free software; you can redistribute it and/or modify it
  4132. + * under the terms of the GNU General Public License version 2 only, as
  4133. + * published by the Free Software Foundation.
  4134. + *
  4135. + * This code is distributed in the hope that it will be useful, but WITHOUT
  4136. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4137. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4138. + * version 2 for more details (a copy is included in the LICENSE file that
  4139. + * accompanied this code).
  4140. + *
  4141. + * You should have received a copy of the GNU General Public License version
  4142. + * 2 along with this work; if not, write to the Free Software Foundation,
  4143. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4144. + *
  4145. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4146. + * or visit www.oracle.com if you need additional information or have any
  4147. + * questions.
  4148. + *
  4149. + */
  4150. +package at.ssw.hotswap.test.access;
  4151. +
  4152. +import java.util.List;
  4153. +
  4154. +/**
  4155. + * @author Kerstin Breiteneder
  4156. + * @author Christoph Wimberger
  4157. + */
  4158. +public interface MethodAccess {
  4159. +
  4160. + public String getName();
  4161. +
  4162. + public String getSignature();
  4163. +
  4164. + public boolean canCheckObsoletness();
  4165. +
  4166. + public boolean isObsolete();
  4167. +
  4168. + public Object invoke(Object[] o, Object instance);
  4169. +}
  4170. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/StackFrameAccess.java
  4171. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  4172. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/StackFrameAccess.java Fri Dec 17 13:23:04 2010 +0100
  4173. @@ -0,0 +1,35 @@
  4174. +/*
  4175. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  4176. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4177. + *
  4178. + * This code is free software; you can redistribute it and/or modify it
  4179. + * under the terms of the GNU General Public License version 2 only, as
  4180. + * published by the Free Software Foundation.
  4181. + *
  4182. + * This code is distributed in the hope that it will be useful, but WITHOUT
  4183. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4184. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4185. + * version 2 for more details (a copy is included in the LICENSE file that
  4186. + * accompanied this code).
  4187. + *
  4188. + * You should have received a copy of the GNU General Public License version
  4189. + * 2 along with this work; if not, write to the Free Software Foundation,
  4190. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4191. + *
  4192. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4193. + * or visit www.oracle.com if you need additional information or have any
  4194. + * questions.
  4195. + *
  4196. + */
  4197. +package at.ssw.hotswap.test.access;
  4198. +
  4199. +/**
  4200. + * @author Kerstin Breiteneder
  4201. + * @author Christoph Wimberger
  4202. + */
  4203. +public interface StackFrameAccess {
  4204. +
  4205. + public MethodAccess getMethod() throws ClassNotFoundException;
  4206. +
  4207. + public ClassAccess getClazz();
  4208. +}
  4209. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/VMAccess.java
  4210. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  4211. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/VMAccess.java Fri Dec 17 13:23:04 2010 +0100
  4212. @@ -0,0 +1,41 @@
  4213. +/*
  4214. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  4215. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4216. + *
  4217. + * This code is free software; you can redistribute it and/or modify it
  4218. + * under the terms of the GNU General Public License version 2 only, as
  4219. + * published by the Free Software Foundation.
  4220. + *
  4221. + * This code is distributed in the hope that it will be useful, but WITHOUT
  4222. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4223. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4224. + * version 2 for more details (a copy is included in the LICENSE file that
  4225. + * accompanied this code).
  4226. + *
  4227. + * You should have received a copy of the GNU General Public License version
  4228. + * 2 along with this work; if not, write to the Free Software Foundation,
  4229. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4230. + *
  4231. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4232. + * or visit www.oracle.com if you need additional information or have any
  4233. + * questions.
  4234. + *
  4235. + */
  4236. +package at.ssw.hotswap.test.access;
  4237. +
  4238. +import java.util.List;
  4239. +
  4240. +/**
  4241. + * @author Kerstin Breiteneder
  4242. + * @author Christoph Wimberger
  4243. + */
  4244. +public interface VMAccess {
  4245. +
  4246. + public boolean canGetFrames();
  4247. +
  4248. + public List<StackFrameAccess> getFrames(final String threadName);
  4249. +
  4250. + public List<String> getThreadNames();
  4251. +
  4252. + public ClassAccess findClass(String clazz);
  4253. +}
  4254. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jdi/JDIClassAccess.java
  4255. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  4256. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jdi/JDIClassAccess.java Fri Dec 17 13:23:04 2010 +0100
  4257. @@ -0,0 +1,78 @@
  4258. +/*
  4259. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  4260. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4261. + *
  4262. + * This code is free software; you can redistribute it and/or modify it
  4263. + * under the terms of the GNU General Public License version 2 only, as
  4264. + * published by the Free Software Foundation.
  4265. + *
  4266. + * This code is distributed in the hope that it will be useful, but WITHOUT
  4267. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4268. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4269. + * version 2 for more details (a copy is included in the LICENSE file that
  4270. + * accompanied this code).
  4271. + *
  4272. + * You should have received a copy of the GNU General Public License version
  4273. + * 2 along with this work; if not, write to the Free Software Foundation,
  4274. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4275. + *
  4276. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4277. + * or visit www.oracle.com if you need additional information or have any
  4278. + * questions.
  4279. + *
  4280. + */
  4281. +package at.ssw.hotswap.test.access.jdi;
  4282. +
  4283. +import at.ssw.hotswap.test.access.ClassAccess;
  4284. +import at.ssw.hotswap.test.access.MethodAccess;
  4285. +import com.sun.jdi.Method;
  4286. +import com.sun.jdi.ReferenceType;
  4287. +import java.util.ArrayList;
  4288. +import java.util.List;
  4289. +
  4290. +/**
  4291. + * @author Kerstin Breiteneder
  4292. + * @author Christoph Wimberger
  4293. + */
  4294. +public class JDIClassAccess implements ClassAccess {
  4295. +
  4296. + private ReferenceType clazz;
  4297. +
  4298. + public JDIClassAccess(ReferenceType clazz) {
  4299. + this.clazz = clazz;
  4300. + }
  4301. +
  4302. + @Override
  4303. + public String getName() {
  4304. + return clazz.name();
  4305. + }
  4306. +
  4307. + @Override
  4308. + public MethodAccess findMethod(String method) {
  4309. + List<Method> methods = clazz.methodsByName(method);
  4310. + List<Method> newMethods = new ArrayList<Method>();
  4311. + for (Method m : methods) {
  4312. + if (!m.isObsolete()) {
  4313. + newMethods.add(m);
  4314. + }
  4315. + }
  4316. + if (newMethods.size() > 1) {
  4317. + throw new RuntimeException("ambiguous methods: " + newMethods.get(0) + ", " + newMethods.get(1));
  4318. + }
  4319. + if (newMethods.isEmpty()) {
  4320. + return null;
  4321. + }
  4322. + return new JDIMethodAccess(newMethods.get(0), clazz);
  4323. + }
  4324. +
  4325. + @Override
  4326. + public List<MethodAccess> getMethods() {
  4327. + List<MethodAccess> methodAccesses = new ArrayList<MethodAccess>();
  4328. + for (Method m : clazz.methods()) {
  4329. + if (!m.name().equals("<init>")) {
  4330. + methodAccesses.add(new JDIMethodAccess(m, clazz));
  4331. + }
  4332. + }
  4333. + return methodAccesses;
  4334. + }
  4335. +}
  4336. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jdi/JDIMethodAccess.java
  4337. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  4338. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jdi/JDIMethodAccess.java Fri Dec 17 13:23:04 2010 +0100
  4339. @@ -0,0 +1,133 @@
  4340. +/*
  4341. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  4342. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4343. + *
  4344. + * This code is free software; you can redistribute it and/or modify it
  4345. + * under the terms of the GNU General Public License version 2 only, as
  4346. + * published by the Free Software Foundation.
  4347. + *
  4348. + * This code is distributed in the hope that it will be useful, but WITHOUT
  4349. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4350. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4351. + * version 2 for more details (a copy is included in the LICENSE file that
  4352. + * accompanied this code).
  4353. + *
  4354. + * You should have received a copy of the GNU General Public License version
  4355. + * 2 along with this work; if not, write to the Free Software Foundation,
  4356. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4357. + *
  4358. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4359. + * or visit www.oracle.com if you need additional information or have any
  4360. + * questions.
  4361. + *
  4362. + */
  4363. +package at.ssw.hotswap.test.access.jdi;
  4364. +
  4365. +import at.ssw.hotswap.JDIProxy;
  4366. +import at.ssw.hotswap.test.access.MethodAccess;
  4367. +import com.sun.jdi.ClassNotLoadedException;
  4368. +import com.sun.jdi.ClassType;
  4369. +import com.sun.jdi.IncompatibleThreadStateException;
  4370. +import com.sun.jdi.InvalidTypeException;
  4371. +import com.sun.jdi.InvocationException;
  4372. +import com.sun.jdi.Method;
  4373. +import com.sun.jdi.ReferenceType;
  4374. +import com.sun.jdi.ThreadReference;
  4375. +import com.sun.jdi.Type;
  4376. +import java.lang.reflect.Modifier;
  4377. +import java.util.ArrayList;
  4378. +import java.util.logging.Level;
  4379. +import java.util.logging.Logger;
  4380. +
  4381. +/**
  4382. + * @author Kerstin Breiteneder
  4383. + * @author Christoph Wimberger
  4384. + */
  4385. +public class JDIMethodAccess implements MethodAccess {
  4386. +
  4387. + private Method method;
  4388. +
  4389. + public JDIMethodAccess(Method m, ReferenceType clazz) {
  4390. + method = m;
  4391. + }
  4392. +
  4393. + @Override
  4394. + public String toString() {
  4395. + return method.toString();
  4396. + }
  4397. +
  4398. + @Override
  4399. + public String getName() {
  4400. + return method.name();
  4401. + }
  4402. +
  4403. + @Override
  4404. + public String getSignature() {
  4405. + String methodString = Modifier.toString(method.modifiers()) + " " + method.returnTypeName() + " " + method.name() + "(";
  4406. + boolean paramFound = false;
  4407. + try {
  4408. + for (Type type : method.argumentTypes()) {
  4409. + if (paramFound) {
  4410. + methodString += ", ";
  4411. + }
  4412. + paramFound = true;
  4413. + methodString += type.name();
  4414. + }
  4415. + } catch (ClassNotLoadedException ex) {
  4416. + throw new RuntimeException(ex);
  4417. + }
  4418. + return methodString + ")";
  4419. + }
  4420. +
  4421. + @Override
  4422. + public boolean canCheckObsoletness() {
  4423. + return true;
  4424. + }
  4425. +
  4426. + @Override
  4427. + public boolean isObsolete() {
  4428. + return method.isObsolete();
  4429. + }
  4430. +
  4431. + @Override
  4432. + public Object invoke(Object[] o, Object instance) {
  4433. + Thread tempthread = new Thread("invokeThread") {
  4434. +
  4435. + @Override
  4436. + public void run() {
  4437. + try {
  4438. + sleep(2000);
  4439. + } catch (InterruptedException ex) {
  4440. + Logger.getLogger(JDIMethodAccess.class.getName()).log(Level.SEVERE, null, ex);
  4441. + }
  4442. + }
  4443. + };
  4444. + tempthread.start();
  4445. +
  4446. + // get Main-Thread
  4447. + final JDIProxy jdi = JDIProxy.getJDI();
  4448. + ThreadReference reference = null;
  4449. + for (ThreadReference t : jdi.getVM().allThreads()) {
  4450. + if (t.name().equals("invokeThread")) {
  4451. + reference = t;
  4452. + break;
  4453. + }
  4454. + }
  4455. + // reference.suspend();
  4456. +
  4457. + Object obj = null;
  4458. + try {
  4459. + obj = ((ClassType) method.declaringType()).invokeMethod(reference, method, new ArrayList(), ClassType.INVOKE_SINGLE_THREADED);
  4460. + } catch (InvalidTypeException ex) {
  4461. + Logger.getLogger(JDIMethodAccess.class.getName()).log(Level.SEVERE, null, ex);
  4462. + } catch (ClassNotLoadedException ex) {
  4463. + Logger.getLogger(JDIMethodAccess.class.getName()).log(Level.SEVERE, null, ex);
  4464. + } catch (IncompatibleThreadStateException ex) {
  4465. + Logger.getLogger(JDIMethodAccess.class.getName()).log(Level.SEVERE, null, ex);
  4466. + } catch (InvocationException ex) {
  4467. + Logger.getLogger(JDIMethodAccess.class.getName()).log(Level.SEVERE, null, ex);
  4468. + }
  4469. + // reference.resume();
  4470. + return obj;
  4471. + }
  4472. +}
  4473. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jdi/JDIStackFrameAccess.java
  4474. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  4475. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jdi/JDIStackFrameAccess.java Fri Dec 17 13:23:04 2010 +0100
  4476. @@ -0,0 +1,69 @@
  4477. +/*
  4478. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  4479. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4480. + *
  4481. + * This code is free software; you can redistribute it and/or modify it
  4482. + * under the terms of the GNU General Public License version 2 only, as
  4483. + * published by the Free Software Foundation.
  4484. + *
  4485. + * This code is distributed in the hope that it will be useful, but WITHOUT
  4486. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4487. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4488. + * version 2 for more details (a copy is included in the LICENSE file that
  4489. + * accompanied this code).
  4490. + *
  4491. + * You should have received a copy of the GNU General Public License version
  4492. + * 2 along with this work; if not, write to the Free Software Foundation,
  4493. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4494. + *
  4495. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4496. + * or visit www.oracle.com if you need additional information or have any
  4497. + * questions.
  4498. + *
  4499. + */
  4500. +package at.ssw.hotswap.test.access.jdi;
  4501. +
  4502. +import at.ssw.hotswap.test.access.ClassAccess;
  4503. +import at.ssw.hotswap.test.access.MethodAccess;
  4504. +import at.ssw.hotswap.test.access.StackFrameAccess;
  4505. +import com.sun.jdi.Method;
  4506. +import com.sun.jdi.ReferenceType;
  4507. +import com.sun.jdi.StackFrame;
  4508. +
  4509. +/**
  4510. + * @author Kerstin Breiteneder
  4511. + * @author Christoph Wimberger
  4512. + */
  4513. +public class JDIStackFrameAccess implements StackFrameAccess {
  4514. +
  4515. + private ReferenceType clazz;
  4516. + private Method method;
  4517. + private MethodAccess methodAccess;
  4518. + private ClassAccess classAccess;
  4519. +
  4520. + JDIStackFrameAccess(StackFrame s) {
  4521. + method = s.location().method();
  4522. + clazz = s.location().method().declaringType();
  4523. + }
  4524. +
  4525. + @Override
  4526. + public MethodAccess getMethod() {
  4527. + if (methodAccess == null) {
  4528. + methodAccess = new JDIMethodAccess(method, clazz);
  4529. + }
  4530. + return methodAccess;
  4531. + }
  4532. +
  4533. + @Override
  4534. + public ClassAccess getClazz() {
  4535. + if (classAccess == null) {
  4536. + classAccess = new JDIClassAccess(clazz);
  4537. + }
  4538. + return classAccess;
  4539. + }
  4540. +
  4541. + @Override
  4542. + public String toString() {
  4543. + return method.toString();
  4544. + }
  4545. +}
  4546. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jdi/JDIVMAccess.java
  4547. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  4548. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jdi/JDIVMAccess.java Fri Dec 17 13:23:04 2010 +0100
  4549. @@ -0,0 +1,121 @@
  4550. +/*
  4551. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  4552. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4553. + *
  4554. + * This code is free software; you can redistribute it and/or modify it
  4555. + * under the terms of the GNU General Public License version 2 only, as
  4556. + * published by the Free Software Foundation.
  4557. + *
  4558. + * This code is distributed in the hope that it will be useful, but WITHOUT
  4559. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4560. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4561. + * version 2 for more details (a copy is included in the LICENSE file that
  4562. + * accompanied this code).
  4563. + *
  4564. + * You should have received a copy of the GNU General Public License version
  4565. + * 2 along with this work; if not, write to the Free Software Foundation,
  4566. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4567. + *
  4568. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4569. + * or visit www.oracle.com if you need additional information or have any
  4570. + * questions.
  4571. + *
  4572. + */
  4573. +package at.ssw.hotswap.test.access.jdi;
  4574. +
  4575. +import at.ssw.hotswap.JDIProxy;
  4576. +import at.ssw.hotswap.test.access.ClassAccess;
  4577. +import at.ssw.hotswap.test.access.StackFrameAccess;
  4578. +import at.ssw.hotswap.test.access.VMAccess;
  4579. +import com.sun.jdi.IncompatibleThreadStateException;
  4580. +import com.sun.jdi.ReferenceType;
  4581. +import com.sun.jdi.StackFrame;
  4582. +import com.sun.jdi.ThreadReference;
  4583. +import java.util.ArrayList;
  4584. +import java.util.List;
  4585. +import java.util.logging.Level;
  4586. +import java.util.logging.Logger;
  4587. +
  4588. +/**
  4589. + * @author Kerstin Breiteneder
  4590. + * @author Christoph Wimberger
  4591. + */
  4592. +public class JDIVMAccess implements VMAccess {
  4593. +
  4594. + private List<ThreadReference> getThreads() {
  4595. + final JDIProxy jdi = JDIProxy.getJDI();
  4596. + return jdi.getVM().allThreads();
  4597. + }
  4598. +
  4599. + @Override
  4600. + public boolean canGetFrames() {
  4601. + return true;
  4602. + }
  4603. +
  4604. + @Override
  4605. + public List<StackFrameAccess> getFrames(final String threadName) {
  4606. + final JDIProxy jdi = JDIProxy.getJDI();
  4607. + final Exception[] exception = new Exception[1];
  4608. + final Object[] object = new Object[1];
  4609. + object[0] = null;
  4610. + exception[0] = null;
  4611. +
  4612. + Runnable r = new Runnable() {
  4613. +
  4614. + public void run() {
  4615. + List<StackFrameAccess> stackAccesses = new ArrayList<StackFrameAccess>();
  4616. + for (ThreadReference t : getThreads()) {
  4617. + if (t.name().equals(threadName)) {
  4618. + try {
  4619. + for (StackFrame stack : t.frames()) {
  4620. + StackFrameAccess stackAccess = new JDIStackFrameAccess(stack);
  4621. + stackAccesses.add(stackAccess);
  4622. + }
  4623. + } catch (IncompatibleThreadStateException ex) {
  4624. + exception[0] = ex;
  4625. + }
  4626. + object[0] = stackAccesses;
  4627. + return;
  4628. + }
  4629. + }
  4630. + }
  4631. + };
  4632. +
  4633. + jdi.executeSuspended(r);
  4634. +
  4635. + if (exception[0] != null) {
  4636. + throw new RuntimeException(exception[0]);
  4637. + }
  4638. + return (List<StackFrameAccess>) object[0];
  4639. + }
  4640. +
  4641. + @Override
  4642. + public List<String> getThreadNames() {
  4643. + List<String> threadNames = new ArrayList<String>();
  4644. +
  4645. + for (ThreadReference t : getThreads()) {
  4646. + threadNames.add(t.name());
  4647. + }
  4648. + return threadNames;
  4649. + }
  4650. +
  4651. + @Override
  4652. + public ClassAccess findClass(String clazz) {
  4653. + final JDIProxy jdi = JDIProxy.getJDI();
  4654. + ReferenceType found = null;
  4655. + // ensures, that all classes are retrieved
  4656. + jdi.refreshAllClasses();
  4657. + for (ReferenceType referenceType : jdi.getVM().allClasses()) {
  4658. + if (referenceType.name().equals(clazz)) {
  4659. + if (found != null) {
  4660. + throw new RuntimeException("ambiguous class name");
  4661. + }
  4662. + found = referenceType;
  4663. + }
  4664. + }
  4665. + if (found == null) {
  4666. + return null;
  4667. + }
  4668. + return new JDIClassAccess(found);
  4669. + }
  4670. +}
  4671. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jni/JNIClassAccess.java
  4672. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  4673. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jni/JNIClassAccess.java Fri Dec 17 13:23:04 2010 +0100
  4674. @@ -0,0 +1,73 @@
  4675. +/*
  4676. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  4677. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4678. + *
  4679. + * This code is free software; you can redistribute it and/or modify it
  4680. + * under the terms of the GNU General Public License version 2 only, as
  4681. + * published by the Free Software Foundation.
  4682. + *
  4683. + * This code is distributed in the hope that it will be useful, but WITHOUT
  4684. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4685. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4686. + * version 2 for more details (a copy is included in the LICENSE file that
  4687. + * accompanied this code).
  4688. + *
  4689. + * You should have received a copy of the GNU General Public License version
  4690. + * 2 along with this work; if not, write to the Free Software Foundation,
  4691. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4692. + *
  4693. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4694. + * or visit www.oracle.com if you need additional information or have any
  4695. + * questions.
  4696. + *
  4697. + */
  4698. +package at.ssw.hotswap.test.access.jni;
  4699. +
  4700. +import at.ssw.hotswap.test.access.ClassAccess;
  4701. +import at.ssw.hotswap.test.access.MethodAccess;
  4702. +import java.lang.reflect.Method;
  4703. +import java.util.ArrayList;
  4704. +import java.util.List;
  4705. +
  4706. +/**
  4707. + * @author Kerstin Breiteneder
  4708. + * @author Christoph Wimberger
  4709. + */
  4710. +public class JNIClassAccess implements ClassAccess {
  4711. +
  4712. + Class clazz;
  4713. +
  4714. + public JNIClassAccess(Class clazz) {
  4715. + this.clazz = clazz;
  4716. + }
  4717. +
  4718. + @Override
  4719. + public String getName() {
  4720. + return clazz.getName();
  4721. + }
  4722. +
  4723. + public static native Method findMethodNative(Class clazz, String methodName);
  4724. +
  4725. + @Override
  4726. + public MethodAccess findMethod(String methodName) {
  4727. + Method m;
  4728. + try {
  4729. + m = findMethodNative(clazz, methodName);
  4730. + } catch (NoSuchMethodError ex) {
  4731. + return null;
  4732. + }
  4733. + return new JNIMethodAccess(m);
  4734. + }
  4735. +
  4736. + public static native Method[] getMethodsNative(Class clazz);
  4737. +
  4738. + @Override
  4739. + public List<MethodAccess> getMethods() {
  4740. + Method[] array = getMethodsNative(clazz);
  4741. + List<MethodAccess> mAccesses = new ArrayList<MethodAccess>();
  4742. + for (int i = 0; i < array.length; i++) {
  4743. + mAccesses.add(new JNIMethodAccess(array[i]));
  4744. + }
  4745. + return mAccesses;
  4746. + }
  4747. +}
  4748. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jni/JNIMethodAccess.java
  4749. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  4750. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jni/JNIMethodAccess.java Fri Dec 17 13:23:04 2010 +0100
  4751. @@ -0,0 +1,82 @@
  4752. +/*
  4753. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  4754. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4755. + *
  4756. + * This code is free software; you can redistribute it and/or modify it
  4757. + * under the terms of the GNU General Public License version 2 only, as
  4758. + * published by the Free Software Foundation.
  4759. + *
  4760. + * This code is distributed in the hope that it will be useful, but WITHOUT
  4761. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4762. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4763. + * version 2 for more details (a copy is included in the LICENSE file that
  4764. + * accompanied this code).
  4765. + *
  4766. + * You should have received a copy of the GNU General Public License version
  4767. + * 2 along with this work; if not, write to the Free Software Foundation,
  4768. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4769. + *
  4770. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4771. + * or visit www.oracle.com if you need additional information or have any
  4772. + * questions.
  4773. + *
  4774. + */
  4775. +package at.ssw.hotswap.test.access.jni;
  4776. +
  4777. +import at.ssw.hotswap.test.access.MethodAccess;
  4778. +import java.lang.reflect.Method;
  4779. +import java.lang.reflect.Modifier;
  4780. +import org.objectweb.asm.Type;
  4781. +
  4782. +/**
  4783. + * @author Kerstin Breiteneder
  4784. + * @author Christoph Wimberger
  4785. + */
  4786. +public class JNIMethodAccess implements MethodAccess {
  4787. +
  4788. + Method method;
  4789. +
  4790. + public JNIMethodAccess(Method m) {
  4791. + method = m;
  4792. + }
  4793. +
  4794. + @Override
  4795. + public String getName() {
  4796. + return method.getName();
  4797. + }
  4798. +
  4799. + @Override
  4800. + public String getSignature() {
  4801. + String methodString = Modifier.toString(method.getModifiers()) + " " + method.getReturnType().getName() + " " + method.getName() + "(";
  4802. + boolean paramFound = false;
  4803. + for (Class c : method.getParameterTypes()) {
  4804. + if (paramFound) {
  4805. + methodString += ", ";
  4806. + }
  4807. + paramFound = true;
  4808. + methodString += c.getName();
  4809. + }
  4810. + return methodString + ")";
  4811. + }
  4812. +
  4813. + @Override
  4814. + public boolean canCheckObsoletness() {
  4815. + throw new UnsupportedOperationException("Not supported yet.");
  4816. + }
  4817. +
  4818. + @Override
  4819. + public boolean isObsolete() {
  4820. + throw new UnsupportedOperationException("Not supported yet.");
  4821. + }
  4822. +
  4823. + public static native Object invokeMethodNative(Class clazz, Object obj, String methodName, String retValue, boolean staticValue, String descriptor, Object[] params);
  4824. +
  4825. + @Override
  4826. + public Object invoke(Object[] o, Object instance) {
  4827. + boolean staticValue = java.lang.reflect.Modifier.isStatic(method.getModifiers());
  4828. + String retValue = method.getReturnType().getName();
  4829. + String descriptor = new org.objectweb.asm.commons.Method(method.getName(), Type.getReturnType(method), Type.getArgumentTypes(method)).getDescriptor();
  4830. +
  4831. + return invokeMethodNative(method.getDeclaringClass(), instance, method.getName(), retValue, staticValue, descriptor, o);
  4832. + }
  4833. +}
  4834. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jni/JNIStackFrameAccess.java
  4835. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  4836. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jni/JNIStackFrameAccess.java Fri Dec 17 13:23:04 2010 +0100
  4837. @@ -0,0 +1,45 @@
  4838. +/*
  4839. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  4840. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4841. + *
  4842. + * This code is free software; you can redistribute it and/or modify it
  4843. + * under the terms of the GNU General Public License version 2 only, as
  4844. + * published by the Free Software Foundation.
  4845. + *
  4846. + * This code is distributed in the hope that it will be useful, but WITHOUT
  4847. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4848. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4849. + * version 2 for more details (a copy is included in the LICENSE file that
  4850. + * accompanied this code).
  4851. + *
  4852. + * You should have received a copy of the GNU General Public License version
  4853. + * 2 along with this work; if not, write to the Free Software Foundation,
  4854. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4855. + *
  4856. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4857. + * or visit www.oracle.com if you need additional information or have any
  4858. + * questions.
  4859. + *
  4860. + */
  4861. +package at.ssw.hotswap.test.access.jni;
  4862. +
  4863. +import at.ssw.hotswap.test.access.ClassAccess;
  4864. +import at.ssw.hotswap.test.access.MethodAccess;
  4865. +import at.ssw.hotswap.test.access.StackFrameAccess;
  4866. +
  4867. +/**
  4868. + * @author Kerstin Breiteneder
  4869. + * @author Christoph Wimberger
  4870. + */
  4871. +public class JNIStackFrameAccess implements StackFrameAccess {
  4872. +
  4873. + @Override
  4874. + public MethodAccess getMethod() throws ClassNotFoundException {
  4875. + throw new UnsupportedOperationException("Not supported yet.");
  4876. + }
  4877. +
  4878. + @Override
  4879. + public ClassAccess getClazz() {
  4880. + throw new UnsupportedOperationException("Not supported yet.");
  4881. + }
  4882. +}
  4883. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jni/JNIVMAccess.java
  4884. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  4885. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/jni/JNIVMAccess.java Fri Dec 17 13:23:04 2010 +0100
  4886. @@ -0,0 +1,65 @@
  4887. +/*
  4888. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  4889. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4890. + *
  4891. + * This code is free software; you can redistribute it and/or modify it
  4892. + * under the terms of the GNU General Public License version 2 only, as
  4893. + * published by the Free Software Foundation.
  4894. + *
  4895. + * This code is distributed in the hope that it will be useful, but WITHOUT
  4896. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4897. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4898. + * version 2 for more details (a copy is included in the LICENSE file that
  4899. + * accompanied this code).
  4900. + *
  4901. + * You should have received a copy of the GNU General Public License version
  4902. + * 2 along with this work; if not, write to the Free Software Foundation,
  4903. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4904. + *
  4905. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4906. + * or visit www.oracle.com if you need additional information or have any
  4907. + * questions.
  4908. + *
  4909. + */
  4910. +package at.ssw.hotswap.test.access.jni;
  4911. +
  4912. +import at.ssw.hotswap.test.access.ClassAccess;
  4913. +import at.ssw.hotswap.test.access.StackFrameAccess;
  4914. +import at.ssw.hotswap.test.access.VMAccess;
  4915. +import java.io.File;
  4916. +import java.util.List;
  4917. +
  4918. +/**
  4919. + * @author Kerstin Breiteneder
  4920. + * @author Christoph Wimberger
  4921. + */
  4922. +public class JNIVMAccess implements VMAccess {
  4923. +
  4924. + @Override
  4925. + public boolean canGetFrames() {
  4926. + return false;
  4927. + }
  4928. +
  4929. + @Override
  4930. + public List<StackFrameAccess> getFrames(String threadName) {
  4931. + throw new UnsupportedOperationException("Not supported yet.");
  4932. + }
  4933. +
  4934. + @Override
  4935. + public List<String> getThreadNames() {
  4936. + throw new UnsupportedOperationException("Not supported yet.");
  4937. + }
  4938. +
  4939. + public static native Class findClassNative(String clazz) throws ClassNotFoundException, NoClassDefFoundError;
  4940. +
  4941. + @Override
  4942. + public ClassAccess findClass(String clazz) {
  4943. + try {
  4944. + return new JNIClassAccess(findClassNative(clazz.replace('.', '/')));
  4945. + } catch (ClassNotFoundException ex) {
  4946. + return null;
  4947. + } catch (NoClassDefFoundError ex) {
  4948. + return null;
  4949. + }
  4950. + }
  4951. +}
  4952. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/reflection/ReflectionClassAccess.java
  4953. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  4954. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/reflection/ReflectionClassAccess.java Fri Dec 17 13:23:04 2010 +0100
  4955. @@ -0,0 +1,70 @@
  4956. +/*
  4957. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  4958. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4959. + *
  4960. + * This code is free software; you can redistribute it and/or modify it
  4961. + * under the terms of the GNU General Public License version 2 only, as
  4962. + * published by the Free Software Foundation.
  4963. + *
  4964. + * This code is distributed in the hope that it will be useful, but WITHOUT
  4965. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4966. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4967. + * version 2 for more details (a copy is included in the LICENSE file that
  4968. + * accompanied this code).
  4969. + *
  4970. + * You should have received a copy of the GNU General Public License version
  4971. + * 2 along with this work; if not, write to the Free Software Foundation,
  4972. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4973. + *
  4974. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4975. + * or visit www.oracle.com if you need additional information or have any
  4976. + * questions.
  4977. + *
  4978. + */
  4979. +package at.ssw.hotswap.test.access.reflection;
  4980. +
  4981. +import at.ssw.hotswap.test.access.ClassAccess;
  4982. +import at.ssw.hotswap.test.access.MethodAccess;
  4983. +import java.lang.reflect.Method;
  4984. +import java.util.ArrayList;
  4985. +import java.util.List;
  4986. +
  4987. +/**
  4988. + * @author Kerstin Breiteneder
  4989. + * @author Christoph Wimberger
  4990. + */
  4991. +public class ReflectionClassAccess implements ClassAccess {
  4992. +
  4993. + private Class clazz;
  4994. +
  4995. + public ReflectionClassAccess() {
  4996. + }
  4997. + public ReflectionClassAccess(String name) throws ClassNotFoundException {
  4998. + clazz = Class.forName(name);
  4999. + }
  5000. +
  5001. + @Override
  5002. + public String getName() {
  5003. + return clazz.getName();
  5004. + }
  5005. +
  5006. + @Override
  5007. + public MethodAccess findMethod(String method) {
  5008. + try {
  5009. + return new ReflectionMethodAccess(method, clazz.getName());
  5010. + } catch (ClassNotFoundException ex) {
  5011. + return null;
  5012. + } catch (NoSuchMethodError ex) {
  5013. + return null;
  5014. + }
  5015. + }
  5016. +
  5017. + @Override
  5018. + public List<MethodAccess> getMethods() {
  5019. + List<MethodAccess> methodAccesses = new ArrayList<MethodAccess>();
  5020. + for (Method m : clazz.getDeclaredMethods()) {
  5021. + methodAccesses.add(new ReflectionMethodAccess(m, clazz));
  5022. + }
  5023. + return methodAccesses;
  5024. + }
  5025. +}
  5026. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/reflection/ReflectionMethodAccess.java
  5027. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  5028. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/reflection/ReflectionMethodAccess.java Fri Dec 17 13:23:04 2010 +0100
  5029. @@ -0,0 +1,107 @@
  5030. +/*
  5031. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  5032. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5033. + *
  5034. + * This code is free software; you can redistribute it and/or modify it
  5035. + * under the terms of the GNU General Public License version 2 only, as
  5036. + * published by the Free Software Foundation.
  5037. + *
  5038. + * This code is distributed in the hope that it will be useful, but WITHOUT
  5039. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  5040. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  5041. + * version 2 for more details (a copy is included in the LICENSE file that
  5042. + * accompanied this code).
  5043. + *
  5044. + * You should have received a copy of the GNU General Public License version
  5045. + * 2 along with this work; if not, write to the Free Software Foundation,
  5046. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  5047. + *
  5048. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  5049. + * or visit www.oracle.com if you need additional information or have any
  5050. + * questions.
  5051. + *
  5052. + */
  5053. +package at.ssw.hotswap.test.access.reflection;
  5054. +
  5055. +import at.ssw.hotswap.test.access.MethodAccess;
  5056. +import java.lang.reflect.InvocationTargetException;
  5057. +import java.lang.reflect.Method;
  5058. +import java.lang.reflect.Modifier;
  5059. +
  5060. +/**
  5061. + * @author Kerstin Breiteneder
  5062. + * @author Christoph Wimberger
  5063. + */
  5064. +public class ReflectionMethodAccess implements MethodAccess {
  5065. +
  5066. + private Method method;
  5067. +
  5068. + public ReflectionMethodAccess(String methodName, String className) throws ClassNotFoundException, NoSuchMethodError {
  5069. +
  5070. + Class clazz = Class.forName(className);
  5071. +
  5072. + Method found = null;
  5073. + for (Method m : clazz.getDeclaredMethods()) {
  5074. + if (m.getName().equals(methodName)) {
  5075. + if (found != null) {
  5076. + throw new RuntimeException("ambiguous method name");
  5077. + }
  5078. + found = m;
  5079. + }
  5080. + }
  5081. + if (found == null) {
  5082. + throw new NoSuchMethodError(methodName);
  5083. + }
  5084. + this.method = found;
  5085. + }
  5086. +
  5087. + public ReflectionMethodAccess(Method m, Class clazz) {
  5088. + this.method = m;
  5089. + }
  5090. +
  5091. + @Override
  5092. + public String getSignature() {
  5093. + String methodString = Modifier.toString(method.getModifiers()) + " " + method.getReturnType().getName() + " " + method.getName() + "(";
  5094. + boolean paramFound = false;
  5095. + for (Class c : method.getParameterTypes()) {
  5096. + if (paramFound) {
  5097. + methodString += ", ";
  5098. + }
  5099. + paramFound = true;
  5100. + methodString += c.getName();
  5101. + }
  5102. + return methodString + ")";
  5103. + }
  5104. +
  5105. + @Override
  5106. + public String getName() {
  5107. + return method.getName();
  5108. + }
  5109. +
  5110. + @Override
  5111. + public boolean canCheckObsoletness() {
  5112. + return false;
  5113. + }
  5114. +
  5115. + @Override
  5116. + public boolean isObsolete() {
  5117. + throw new UnsupportedOperationException("Not supported yet.");
  5118. + }
  5119. +
  5120. + @Override
  5121. + public Object invoke(Object[] o, Object instance) {
  5122. + try {
  5123. + boolean acc = method.isAccessible();
  5124. + method.setAccessible(true);
  5125. + Object obj = method.invoke(instance, o);
  5126. + method.setAccessible(acc);
  5127. + return obj;
  5128. + } catch (IllegalAccessException ex) {
  5129. + throw new RuntimeException(ex);
  5130. + } catch (IllegalArgumentException ex) {
  5131. + throw new RuntimeException(ex);
  5132. + } catch (InvocationTargetException ex) {
  5133. + throw new RuntimeException(ex);
  5134. + }
  5135. + }
  5136. +}
  5137. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/reflection/ReflectionStackFrameAccess.java
  5138. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  5139. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/reflection/ReflectionStackFrameAccess.java Fri Dec 17 13:23:04 2010 +0100
  5140. @@ -0,0 +1,70 @@
  5141. +/*
  5142. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  5143. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5144. + *
  5145. + * This code is free software; you can redistribute it and/or modify it
  5146. + * under the terms of the GNU General Public License version 2 only, as
  5147. + * published by the Free Software Foundation.
  5148. + *
  5149. + * This code is distributed in the hope that it will be useful, but WITHOUT
  5150. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  5151. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  5152. + * version 2 for more details (a copy is included in the LICENSE file that
  5153. + * accompanied this code).
  5154. + *
  5155. + * You should have received a copy of the GNU General Public License version
  5156. + * 2 along with this work; if not, write to the Free Software Foundation,
  5157. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  5158. + *
  5159. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  5160. + * or visit www.oracle.com if you need additional information or have any
  5161. + * questions.
  5162. + *
  5163. + */
  5164. +package at.ssw.hotswap.test.access.reflection;
  5165. +
  5166. +import at.ssw.hotswap.test.access.ClassAccess;
  5167. +import at.ssw.hotswap.test.access.MethodAccess;
  5168. +import at.ssw.hotswap.test.access.StackFrameAccess;
  5169. +
  5170. +/**
  5171. + * @author Kerstin Breiteneder
  5172. + * @author Christoph Wimberger
  5173. + */
  5174. +public class ReflectionStackFrameAccess implements StackFrameAccess {
  5175. +
  5176. + private String methodName;
  5177. + private String className;
  5178. + private MethodAccess methodAccess;
  5179. + private ClassAccess classAccess;
  5180. +
  5181. + ReflectionStackFrameAccess(StackTraceElement element) {
  5182. + methodName = element.getMethodName();
  5183. + className = element.getClassName();
  5184. + }
  5185. +
  5186. + @Override
  5187. + public MethodAccess getMethod() throws ClassNotFoundException {
  5188. + if (methodAccess == null) {
  5189. + methodAccess = new ReflectionMethodAccess(methodName, className);
  5190. + }
  5191. + return methodAccess;
  5192. + }
  5193. +
  5194. + @Override
  5195. + public ClassAccess getClazz() {
  5196. + if (classAccess == null) {
  5197. + try {
  5198. + classAccess = new ReflectionClassAccess(className);
  5199. + } catch (ClassNotFoundException ex) {
  5200. + return null;
  5201. + }
  5202. + }
  5203. + return classAccess;
  5204. + }
  5205. +
  5206. + @Override
  5207. + public String toString() {
  5208. + return methodName;
  5209. + }
  5210. +}
  5211. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/reflection/ReflectionVMAccess.java
  5212. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  5213. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/access/reflection/ReflectionVMAccess.java Fri Dec 17 13:23:04 2010 +0100
  5214. @@ -0,0 +1,101 @@
  5215. +/*
  5216. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  5217. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5218. + *
  5219. + * This code is free software; you can redistribute it and/or modify it
  5220. + * under the terms of the GNU General Public License version 2 only, as
  5221. + * published by the Free Software Foundation.
  5222. + *
  5223. + * This code is distributed in the hope that it will be useful, but WITHOUT
  5224. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  5225. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  5226. + * version 2 for more details (a copy is included in the LICENSE file that
  5227. + * accompanied this code).
  5228. + *
  5229. + * You should have received a copy of the GNU General Public License version
  5230. + * 2 along with this work; if not, write to the Free Software Foundation,
  5231. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  5232. + *
  5233. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  5234. + * or visit www.oracle.com if you need additional information or have any
  5235. + * questions.
  5236. + *
  5237. + */
  5238. +package at.ssw.hotswap.test.access.reflection;
  5239. +
  5240. +import at.ssw.hotswap.test.access.ClassAccess;
  5241. +import at.ssw.hotswap.test.access.VMAccess;
  5242. +import at.ssw.hotswap.test.access.StackFrameAccess;
  5243. +import java.util.ArrayList;
  5244. +import java.util.List;
  5245. +
  5246. +/**
  5247. + * @author Kerstin Breiteneder
  5248. + * @author Christoph Wimberger
  5249. + */
  5250. +public class ReflectionVMAccess implements VMAccess {
  5251. +
  5252. + private List<Thread> getThreads() {
  5253. + ThreadGroup root = Thread.currentThread().getThreadGroup();
  5254. + while (root.getParent() != null) {
  5255. + root = root.getParent();
  5256. + }
  5257. +
  5258. + Thread[] threads;
  5259. + int cnt;
  5260. + int estsize = root.activeCount();
  5261. +
  5262. + do {
  5263. + estsize *= 2;
  5264. + threads = new Thread[estsize];
  5265. +
  5266. + cnt = root.enumerate(threads, true);
  5267. + } while (cnt == estsize);
  5268. +
  5269. + List<Thread> ret = new ArrayList<Thread>();
  5270. + for (int i = 0; i < cnt; i++) {
  5271. + ret.add(threads[i]);
  5272. + }
  5273. + return ret;
  5274. + }
  5275. +
  5276. + @Override
  5277. + public List<String> getThreadNames() {
  5278. + List<String> threadNames = new ArrayList<String>();
  5279. + List<Thread> threads = getThreads();
  5280. + for (Thread t : threads) {
  5281. + threadNames.add(t.getName());
  5282. + }
  5283. + return threadNames;
  5284. + }
  5285. +
  5286. + @Override
  5287. + public boolean canGetFrames() {
  5288. + return true;
  5289. + }
  5290. +
  5291. + @Override
  5292. + public List<StackFrameAccess> getFrames(String threadName) {
  5293. +
  5294. + List<Thread> threads = getThreads();
  5295. + List<StackFrameAccess> stackAccesses = new ArrayList<StackFrameAccess>();
  5296. + for (Thread t : threads) {
  5297. + if (t.getName().equals(threadName)) {
  5298. + for (StackTraceElement stackElement : t.getStackTrace()) {
  5299. + StackFrameAccess stackAccess = new ReflectionStackFrameAccess(stackElement);
  5300. + stackAccesses.add(stackAccess);
  5301. + }
  5302. + }
  5303. + }
  5304. + return stackAccesses;
  5305. + }
  5306. +
  5307. + @Override
  5308. + public ClassAccess findClass(String clazz) {
  5309. + try {
  5310. + return new ReflectionClassAccess(clazz);
  5311. + } catch (ClassNotFoundException ex) {
  5312. + return null;
  5313. + }
  5314. + }
  5315. +}
  5316. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/accesstests/AccessTest.java
  5317. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  5318. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/accesstests/AccessTest.java Fri Dec 17 13:23:04 2010 +0100
  5319. @@ -0,0 +1,325 @@
  5320. +/*
  5321. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  5322. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5323. + *
  5324. + * This code is free software; you can redistribute it and/or modify it
  5325. + * under the terms of the GNU General Public License version 2 only, as
  5326. + * published by the Free Software Foundation.
  5327. + *
  5328. + * This code is distributed in the hope that it will be useful, but WITHOUT
  5329. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  5330. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  5331. + * version 2 for more details (a copy is included in the LICENSE file that
  5332. + * accompanied this code).
  5333. + *
  5334. + * You should have received a copy of the GNU General Public License version
  5335. + * 2 along with this work; if not, write to the Free Software Foundation,
  5336. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  5337. + *
  5338. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  5339. + * or visit www.oracle.com if you need additional information or have any
  5340. + * questions.
  5341. + *
  5342. + */
  5343. +package at.ssw.hotswap.test.accesstests;
  5344. +
  5345. +import static org.junit.Assert.*;
  5346. +import org.junit.Before;
  5347. +import org.junit.Test;
  5348. +import at.ssw.hotswap.HotSwapTool;
  5349. +import at.ssw.hotswap.test.access.ClassAccess;
  5350. +import at.ssw.hotswap.test.access.MethodAccess;
  5351. +import at.ssw.hotswap.test.access.StackFrameAccess;
  5352. +import at.ssw.hotswap.test.access.VMAccess;
  5353. +import at.ssw.hotswap.test.access.jdi.JDIVMAccess;
  5354. +import at.ssw.hotswap.test.access.jni.JNIVMAccess;
  5355. +import at.ssw.hotswap.test.access.reflection.ReflectionVMAccess;
  5356. +import java.util.Arrays;
  5357. +import java.util.Collection;
  5358. +import java.util.Comparator;
  5359. +import java.util.List;
  5360. +import org.junit.runner.RunWith;
  5361. +import org.junit.runners.Parameterized;
  5362. +import org.junit.runners.Parameterized.Parameters;
  5363. +
  5364. +/**
  5365. + * @author Kerstin Breiteneder
  5366. + * @author Christoph Wimberger
  5367. + */
  5368. +@RunWith(Parameterized.class)
  5369. +public class AccessTest {
  5370. +
  5371. + private static VMAccess vma;
  5372. +
  5373. + public AccessTest(VMAccess vma) {
  5374. + this.vma = vma;
  5375. + }
  5376. +
  5377. + // Version 0
  5378. + public static class A {
  5379. +
  5380. + //needed for StackTraceTest
  5381. + public static String stackTraceHelper() {
  5382. + return getParentMethodSignature();
  5383. + }
  5384. +
  5385. + //needed for FindMethodTest
  5386. + public static String method_Version0() {
  5387. + return "Version0";
  5388. + }
  5389. +
  5390. + //needed for SignatureTest
  5391. + public static String signatureHelper(String y, int x) {
  5392. + return "Version0";
  5393. + }
  5394. +
  5395. + //needed for invokeMethodIntTest()
  5396. + private int testIntRetValue() {
  5397. + return 2;
  5398. + }
  5399. +
  5400. + //needed for invokeMethodObjectTest
  5401. + private Object testObjectRetValue() {
  5402. + return new Integer(2);
  5403. + }
  5404. +
  5405. + //needed for invokeMethodVoidTest
  5406. + private static void testVoidRetValue() {
  5407. + System.out.println("Version 0");
  5408. + }
  5409. +
  5410. + //needed for invokeMethodParameterTest()
  5411. + private static int testMethodParameter(Integer x) {
  5412. + return x;
  5413. + }
  5414. + }
  5415. +
  5416. + // Version 1
  5417. + public static class A___1 {
  5418. +
  5419. + //needed for StackTraceTest
  5420. + protected static String stackTraceHelper() {
  5421. + return getParentMethodSignature();
  5422. + }
  5423. +
  5424. + //needed for FindMethodTest, SignatureTest
  5425. + public static String method_Version1() {
  5426. + return "Version1";
  5427. + }
  5428. +
  5429. + //needed for SignatureTest
  5430. + private static String signatureHelper(int y, int x) {
  5431. + return "Version1";
  5432. + }
  5433. +
  5434. + //needed for invokeMethodIntTest
  5435. + private int testIntRetValue() {
  5436. + return 3;
  5437. + }
  5438. +
  5439. + //needed for invokeMethodObjectTest
  5440. + private Object testObjectRetValue() {
  5441. + return new Integer(3);
  5442. + }
  5443. +
  5444. + //needed for invokeMethodVoidTest
  5445. + private static void testVoidRetValue() {
  5446. + System.out.println("Version 1");
  5447. + }
  5448. +
  5449. + //needed for invokeMethodParameterTest()
  5450. + private static int testMethodParameter(Integer x) {
  5451. + return x + 1;
  5452. + }
  5453. + }
  5454. +
  5455. + //needed for StackTraceTest
  5456. + private static String getParentMethodSignature() {
  5457. +
  5458. + try {
  5459. + int i = 0;
  5460. + for (StackFrameAccess stack : vma.getFrames("main")) {
  5461. + if (stack.getMethod().getName().equals("access$000")) {
  5462. + break;
  5463. + } else {
  5464. + i++;
  5465. + }
  5466. + }
  5467. + return vma.getFrames("main").get(++i).getMethod().getSignature();
  5468. + } catch (ClassNotFoundException ex) {
  5469. + return null;
  5470. + }
  5471. + }
  5472. +
  5473. + @Parameters
  5474. + public static Collection accessValues() {
  5475. + return Arrays.asList(new Object[][]{{new JDIVMAccess()}, {new JNIVMAccess()}, {new ReflectionVMAccess()}});
  5476. + //return Arrays.asList(new Object[][]{{new JDIVMAccess()}});
  5477. + }
  5478. +
  5479. + @Before
  5480. + public void setUp() throws Exception {
  5481. + HotSwapTool.toVersion(AccessTest.class, 0);
  5482. + }
  5483. +
  5484. + @Test
  5485. + public void FindClassTest() {
  5486. +
  5487. +
  5488. + ClassAccess classAccess = vma.findClass("at.ssw.hotswap.test.accesstests.AccessTest$XYZ");
  5489. + assertNull(classAccess);
  5490. +
  5491. + classAccess = vma.findClass("at.ssw.hotswap.test.accesstests.AccessTest$A");
  5492. + assertNotNull(classAccess);
  5493. +
  5494. + HotSwapTool.toVersion(AccessTest.class, 1);
  5495. +
  5496. + classAccess = vma.findClass("at.ssw.hotswap.test.accesstests.AccessTest$A");
  5497. + assertNotNull(classAccess);
  5498. + }
  5499. +
  5500. + @Test
  5501. + public void FindMethodTest() {
  5502. +
  5503. + ClassAccess classAccess = vma.findClass("at.ssw.hotswap.test.accesstests.AccessTest$A");
  5504. + assertNotNull(classAccess);
  5505. +
  5506. + assertNotNull(classAccess.findMethod("method_Version0"));
  5507. + assertNull(classAccess.findMethod("method_Version1"));
  5508. +
  5509. + HotSwapTool.toVersion(AccessTest.class, 1);
  5510. +
  5511. + assertNull(classAccess.findMethod("method_Version0"));
  5512. + assertNotNull(classAccess.findMethod("method_Version1"));
  5513. + }
  5514. +
  5515. + @Test
  5516. + public void StackTraceTest() {
  5517. + if (vma.canGetFrames()) {
  5518. + assertEquals("public static java.lang.String stackTraceHelper()", A.stackTraceHelper());
  5519. +
  5520. + HotSwapTool.toVersion(AccessTest.class, 1);
  5521. +
  5522. + assertEquals("protected static java.lang.String stackTraceHelper()", A.stackTraceHelper());
  5523. + }
  5524. + }
  5525. +
  5526. + @Test
  5527. + public void SignatureTest() {
  5528. + MethodAccess mAccess = vma.findClass("at.ssw.hotswap.test.accesstests.AccessTest$A").findMethod("signatureHelper");
  5529. + assertEquals("public static java.lang.String signatureHelper(java.lang.String, int)", mAccess.getSignature());
  5530. +
  5531. + HotSwapTool.toVersion(AccessTest.class, 1);
  5532. +
  5533. + mAccess = vma.findClass("at.ssw.hotswap.test.accesstests.AccessTest$A").findMethod("signatureHelper");
  5534. + assertEquals("private static java.lang.String signatureHelper(int, int)", mAccess.getSignature());
  5535. + }
  5536. +
  5537. + @Test
  5538. + public void invokeMethodIntTest() {
  5539. + if (vma.getClass().getName().equals("at.ssw.hotswap.test.access.jdi.JDIVMAccess")) {
  5540. + return;
  5541. + }
  5542. +
  5543. + ClassAccess classAccess = vma.findClass("at.ssw.hotswap.test.accesstests.AccessTest$A");
  5544. + assertEquals(2, classAccess.findMethod("testIntRetValue").invoke(new Object[0], new A()));
  5545. +
  5546. + HotSwapTool.toVersion(AccessTest.class, 1);
  5547. +
  5548. + assertEquals(3, classAccess.findMethod("testIntRetValue").invoke(new Object[0], new A()));
  5549. + }
  5550. +
  5551. + @Test
  5552. + public void invokeMethodObjectTest() {
  5553. + if (vma.getClass().getName().equals("at.ssw.hotswap.test.access.jdi.JDIVMAccess")) {
  5554. + return;
  5555. + }
  5556. +
  5557. + ClassAccess classAccess = vma.findClass("at.ssw.hotswap.test.accesstests.AccessTest$A");
  5558. + assertEquals(2, classAccess.findMethod("testObjectRetValue").invoke(new Object[0], new A()));
  5559. +
  5560. + HotSwapTool.toVersion(AccessTest.class, 1);
  5561. +
  5562. + assertEquals(3, classAccess.findMethod("testObjectRetValue").invoke(new Object[0], new A()));
  5563. + }
  5564. +
  5565. + @Test
  5566. + public void invokeMethodVoidTest() {
  5567. + if (vma.getClass().getName().equals("at.ssw.hotswap.test.access.jdi.JDIVMAccess")) {
  5568. + return;
  5569. + }
  5570. +
  5571. + ClassAccess classAccess = vma.findClass("at.ssw.hotswap.test.accesstests.AccessTest$A");
  5572. + assertNull(classAccess.findMethod("testVoidRetValue").invoke(new Object[0], new A()));
  5573. +
  5574. + HotSwapTool.toVersion(AccessTest.class, 1);
  5575. +
  5576. + assertNull(classAccess.findMethod("testVoidRetValue").invoke(new Object[0], new A()));
  5577. + }
  5578. +
  5579. + @Test
  5580. + public void invokeMethodParameterTest() {
  5581. + if (vma.getClass().getName().equals("at.ssw.hotswap.test.access.jdi.JDIVMAccess")) {
  5582. + return;
  5583. + }
  5584. +
  5585. + ClassAccess classAccess = vma.findClass("at.ssw.hotswap.test.accesstests.AccessTest$A");
  5586. + assertEquals(6, classAccess.findMethod("testMethodParameter").invoke(new Object[]{6}, new A()));
  5587. +
  5588. + HotSwapTool.toVersion(AccessTest.class, 1);
  5589. +
  5590. + assertEquals(7, classAccess.findMethod("testMethodParameter").invoke(new Object[]{6}, new A()));
  5591. +
  5592. + }
  5593. +
  5594. + @Test
  5595. + public void getMethodsTest() {
  5596. +
  5597. + ClassAccess cAccess = vma.findClass("at.ssw.hotswap.test.accesstests.AccessTest$A");
  5598. + List<MethodAccess> list = cAccess.getMethods();
  5599. +
  5600. + assertEquals(7, list.size());
  5601. +
  5602. + Object[] mAccesses = list.toArray();
  5603. +
  5604. + Arrays.sort(mAccesses, new Comparator() {
  5605. +
  5606. + @Override
  5607. + public int compare(Object o1, Object o2) {
  5608. + return ((MethodAccess) o1).getName().compareTo(((MethodAccess) o2).getName());
  5609. + }
  5610. + });
  5611. +
  5612. + assertEquals("method_Version0", ((MethodAccess) mAccesses[0]).getName());
  5613. + assertEquals("signatureHelper", ((MethodAccess) mAccesses[1]).getName());
  5614. + assertEquals("stackTraceHelper", ((MethodAccess) mAccesses[2]).getName());
  5615. + assertEquals("testIntRetValue", ((MethodAccess) mAccesses[3]).getName());
  5616. + assertEquals("testMethodParameter", ((MethodAccess) mAccesses[4]).getName());
  5617. + assertEquals("testObjectRetValue", ((MethodAccess) mAccesses[5]).getName());
  5618. + assertEquals("testVoidRetValue", ((MethodAccess) mAccesses[6]).getName());
  5619. +
  5620. + HotSwapTool.toVersion(AccessTest.class, 1);
  5621. +
  5622. + list = cAccess.getMethods();
  5623. +
  5624. + assertEquals(7, list.size());
  5625. +
  5626. + mAccesses = list.toArray();
  5627. + Arrays.sort(mAccesses, new Comparator() {
  5628. +
  5629. + @Override
  5630. + public int compare(Object o1, Object o2) {
  5631. + return ((MethodAccess) o1).getName().compareTo(((MethodAccess) o2).getName());
  5632. + }
  5633. + });
  5634. +
  5635. + assertEquals("method_Version1", ((MethodAccess) mAccesses[0]).getName());
  5636. + assertEquals("signatureHelper", ((MethodAccess) mAccesses[1]).getName());
  5637. + assertEquals("stackTraceHelper", ((MethodAccess) mAccesses[2]).getName());
  5638. + assertEquals("testIntRetValue", ((MethodAccess) mAccesses[3]).getName());
  5639. + assertEquals("testMethodParameter", ((MethodAccess) mAccesses[4]).getName());
  5640. + assertEquals("testObjectRetValue", ((MethodAccess) mAccesses[5]).getName());
  5641. + assertEquals("testVoidRetValue", ((MethodAccess) mAccesses[6]).getName());
  5642. +
  5643. + }
  5644. +}
  5645. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/accesstests/AccessTestSuite.java
  5646. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  5647. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/accesstests/AccessTestSuite.java Fri Dec 17 13:23:04 2010 +0100
  5648. @@ -0,0 +1,38 @@
  5649. +/*
  5650. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  5651. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5652. + *
  5653. + * This code is free software; you can redistribute it and/or modify it
  5654. + * under the terms of the GNU General Public License version 2 only, as
  5655. + * published by the Free Software Foundation.
  5656. + *
  5657. + * This code is distributed in the hope that it will be useful, but WITHOUT
  5658. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  5659. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  5660. + * version 2 for more details (a copy is included in the LICENSE file that
  5661. + * accompanied this code).
  5662. + *
  5663. + * You should have received a copy of the GNU General Public License version
  5664. + * 2 along with this work; if not, write to the Free Software Foundation,
  5665. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  5666. + *
  5667. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  5668. + * or visit www.oracle.com if you need additional information or have any
  5669. + * questions.
  5670. + *
  5671. + */
  5672. +package at.ssw.hotswap.test.accesstests;
  5673. +
  5674. +import org.junit.runner.RunWith;
  5675. +import org.junit.runners.Suite;
  5676. +
  5677. +/**
  5678. + * @author Kerstin Breiteneder
  5679. + * @author Christoph Wimberger
  5680. + */
  5681. +@RunWith(Suite.class)
  5682. +@Suite.SuiteClasses({
  5683. + AccessTest.class
  5684. +})
  5685. +public class AccessTestSuite {
  5686. +}
  5687. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/BodyTestSuite.java
  5688. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  5689. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/BodyTestSuite.java Fri Dec 17 13:23:04 2010 +0100
  5690. @@ -0,0 +1,54 @@
  5691. +/*
  5692. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  5693. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5694. + *
  5695. + * This code is free software; you can redistribute it and/or modify it
  5696. + * under the terms of the GNU General Public License version 2 only, as
  5697. + * published by the Free Software Foundation.
  5698. + *
  5699. + * This code is distributed in the hope that it will be useful, but WITHOUT
  5700. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  5701. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  5702. + * version 2 for more details (a copy is included in the LICENSE file that
  5703. + * accompanied this code).
  5704. + *
  5705. + * You should have received a copy of the GNU General Public License version
  5706. + * 2 along with this work; if not, write to the Free Software Foundation,
  5707. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  5708. + *
  5709. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  5710. + * or visit www.oracle.com if you need additional information or have any
  5711. + * questions.
  5712. + *
  5713. + */
  5714. +
  5715. +package at.ssw.hotswap.test.body;
  5716. +
  5717. +import org.junit.runner.RunWith;
  5718. +import org.junit.runners.Suite;
  5719. +
  5720. +/**
  5721. + *
  5722. + * Class redefinition tests that swap only method bodies and change nothing else. This test cases should also
  5723. + * run with the current version of HotSpot.
  5724. + *
  5725. + * @author Thomas Wuerthinger
  5726. + *
  5727. + */
  5728. +@RunWith(Suite.class)
  5729. +@Suite.SuiteClasses(
  5730. +{
  5731. + StaticTest.class,
  5732. + SimpleStaticTest.class,
  5733. + MultipleThreadsTest.class,
  5734. + OldActivationTest.class,
  5735. + RefactorActiveMethodTest.class,
  5736. + StressTest.class,
  5737. + FacTest.class,
  5738. + FibTest.class,
  5739. + RedefinePrivateMethodTest.class,
  5740. + ClassRenamingTestCase.class,
  5741. + EMCPTest.class
  5742. +})
  5743. +public class BodyTestSuite {
  5744. +}
  5745. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/ClassRenamingTestCase.java
  5746. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  5747. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/ClassRenamingTestCase.java Fri Dec 17 13:23:04 2010 +0100
  5748. @@ -0,0 +1,69 @@
  5749. +/*
  5750. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  5751. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5752. + *
  5753. + * This code is free software; you can redistribute it and/or modify it
  5754. + * under the terms of the GNU General Public License version 2 only, as
  5755. + * published by the Free Software Foundation.
  5756. + *
  5757. + * This code is distributed in the hope that it will be useful, but WITHOUT
  5758. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  5759. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  5760. + * version 2 for more details (a copy is included in the LICENSE file that
  5761. + * accompanied this code).
  5762. + *
  5763. + * You should have received a copy of the GNU General Public License version
  5764. + * 2 along with this work; if not, write to the Free Software Foundation,
  5765. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  5766. + *
  5767. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  5768. + * or visit www.oracle.com if you need additional information or have any
  5769. + * questions.
  5770. + *
  5771. + */
  5772. +package at.ssw.hotswap.test.body;
  5773. +
  5774. +import at.ssw.hotswap.ClassRedefinitionPolicy;
  5775. +import at.ssw.hotswap.HotSwapTool;
  5776. +import static org.junit.Assert.*;
  5777. +import org.junit.Test;
  5778. +
  5779. +/**
  5780. + *
  5781. + * @author Kerstin Breiteneder
  5782. + * @author Christoph Wimberger
  5783. + *
  5784. + */
  5785. +public class ClassRenamingTestCase {
  5786. +
  5787. + public static class B {
  5788. +
  5789. + public int a() {
  5790. + return 1;
  5791. + }
  5792. + }
  5793. +
  5794. + @ClassRedefinitionPolicy(alias = B.class)
  5795. + public static class A___1 {
  5796. +
  5797. + public int a() {
  5798. + return 2;
  5799. + }
  5800. + }
  5801. +
  5802. + @Test
  5803. + public void testRenaming() {
  5804. + HotSwapTool.toVersion(ClassRenamingTestCase.class, 0);
  5805. +
  5806. + B b = new B();
  5807. + assertEquals(1, b.a());
  5808. +
  5809. + HotSwapTool.toVersion(ClassRenamingTestCase.class, 1);
  5810. +
  5811. + assertEquals(2, b.a());
  5812. +
  5813. + HotSwapTool.toVersion(ClassRenamingTestCase.class, 0);
  5814. +
  5815. + assertEquals(1, b.a());
  5816. + }
  5817. +}
  5818. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/EMCPTest.java
  5819. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  5820. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/EMCPTest.java Fri Dec 17 13:23:04 2010 +0100
  5821. @@ -0,0 +1,219 @@
  5822. +/*
  5823. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  5824. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5825. + *
  5826. + * This code is free software; you can redistribute it and/or modify it
  5827. + * under the terms of the GNU General Public License version 2 only, as
  5828. + * published by the Free Software Foundation.
  5829. + *
  5830. + * This code is distributed in the hope that it will be useful, but WITHOUT
  5831. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  5832. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  5833. + * version 2 for more details (a copy is included in the LICENSE file that
  5834. + * accompanied this code).
  5835. + *
  5836. + * You should have received a copy of the GNU General Public License version
  5837. + * 2 along with this work; if not, write to the Free Software Foundation,
  5838. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  5839. + *
  5840. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  5841. + * or visit www.oracle.com if you need additional information or have any
  5842. + * questions.
  5843. + *
  5844. + */
  5845. +package at.ssw.hotswap.test.body;
  5846. +
  5847. +import at.ssw.hotswap.HotSwapTool;
  5848. +import at.ssw.hotswap.test.TestUtil;
  5849. +import java.io.PrintStream;
  5850. +import static org.junit.Assert.*;
  5851. +import org.junit.Test;
  5852. +
  5853. +/**
  5854. + *
  5855. + * EMCP (Equivalent modulo Constant Pool) tests.
  5856. + *
  5857. + * @author Thomas Wuerthinger
  5858. + *
  5859. + */
  5860. +public class EMCPTest {
  5861. +
  5862. + public static class A {
  5863. +
  5864. + public static int EMCPReturn() {
  5865. + change();
  5866. + PrintStream s = System.out;
  5867. + return 1;
  5868. + }
  5869. + }
  5870. +
  5871. + public static class B {
  5872. +
  5873. + public static int b() {
  5874. + change();
  5875. + throw new RuntimeException();
  5876. + }
  5877. + }
  5878. +
  5879. + public static class C {
  5880. +
  5881. + public static int c() {
  5882. + changeAndThrow();
  5883. + return 0;
  5884. + }
  5885. + }
  5886. +
  5887. + public static class D {
  5888. +
  5889. + private static int value = 1;
  5890. +
  5891. + public static int EMCPReturn() {
  5892. + change3();
  5893. + return value;
  5894. + }
  5895. + }
  5896. +
  5897. + public static class A___1 {
  5898. +
  5899. + public static int EMCPReturn() {
  5900. + change();
  5901. + PrintStream s = System.out;
  5902. + return 1;
  5903. + }
  5904. + }
  5905. +
  5906. + public static class B___1 {
  5907. +
  5908. + public static int b() {
  5909. + change();
  5910. + throw new RuntimeException();
  5911. + }
  5912. + }
  5913. +
  5914. + public static class C___1 {
  5915. +
  5916. + public static int c() {
  5917. + changeAndThrow();
  5918. + return 0;
  5919. + }
  5920. + }
  5921. +
  5922. + public static class D___1 {
  5923. + private static int value = 1;
  5924. +
  5925. + public static int EMCPReturn() {
  5926. + change3();
  5927. + return value;
  5928. + }
  5929. + }
  5930. +
  5931. + public static class D___2 {
  5932. + private static int value = 1;
  5933. +
  5934. + public static int EMCPReturn() {
  5935. + change3();
  5936. + return value;
  5937. + }
  5938. + }
  5939. +
  5940. + public static class D___3 {
  5941. + private static int value = 1;
  5942. +
  5943. + public static int EMCPReturn() {
  5944. + change3();
  5945. + return value;
  5946. + }
  5947. + }
  5948. +
  5949. + public static void change() {
  5950. +
  5951. + HotSwapTool.toVersion(EMCPTest.class, 1);
  5952. + }
  5953. +
  5954. + public static void change3() {
  5955. +
  5956. + HotSwapTool.toVersion(EMCPTest.class, 1);
  5957. + HotSwapTool.toVersion(EMCPTest.class, 2);
  5958. + HotSwapTool.toVersion(EMCPTest.class, 3);
  5959. + }
  5960. +
  5961. + public static void changeAndThrow() {
  5962. +
  5963. + HotSwapTool.toVersion(EMCPTest.class, 1);
  5964. +
  5965. + throw new RuntimeException();
  5966. + }
  5967. +
  5968. +
  5969. + @Test
  5970. + public void testEMCPReturn() {
  5971. + HotSwapTool.toVersion(EMCPTest.class, 0);
  5972. +
  5973. + assertEquals(1, A.EMCPReturn());
  5974. +
  5975. + HotSwapTool.toVersion(EMCPTest.class, 0);
  5976. +
  5977. + assertEquals(1, A.EMCPReturn());
  5978. +
  5979. + HotSwapTool.toVersion(EMCPTest.class, 0);
  5980. + }
  5981. +
  5982. + @Test
  5983. + public void testEMCPMultiChangeReturn() {
  5984. + HotSwapTool.toVersion(EMCPTest.class, 0);
  5985. +
  5986. + assertEquals(1, D.EMCPReturn());
  5987. +
  5988. + HotSwapTool.toVersion(EMCPTest.class, 0);
  5989. +
  5990. + assertEquals(1, D.EMCPReturn());
  5991. +
  5992. + HotSwapTool.toVersion(EMCPTest.class, 0);
  5993. + }
  5994. +
  5995. + @Test
  5996. + public void testEMCPException() {
  5997. + HotSwapTool.toVersion(EMCPTest.class, 0);
  5998. +
  5999. + TestUtil.assertException(RuntimeException.class, new Runnable(){
  6000. + @Override
  6001. + public void run() {
  6002. + B.b();
  6003. + }
  6004. + });
  6005. +
  6006. + HotSwapTool.toVersion(EMCPTest.class, 0);
  6007. +
  6008. + TestUtil.assertException(RuntimeException.class, new Runnable(){
  6009. + @Override
  6010. + public void run() {
  6011. + B.b();
  6012. + }
  6013. + });
  6014. +
  6015. + HotSwapTool.toVersion(EMCPTest.class, 0);
  6016. + }
  6017. +
  6018. + @Test
  6019. + public void testEMCPExceptionInCallee() {
  6020. + HotSwapTool.toVersion(EMCPTest.class, 0);
  6021. +
  6022. + TestUtil.assertException(RuntimeException.class, new Runnable(){
  6023. + @Override
  6024. + public void run() {
  6025. + C.c();
  6026. + }
  6027. + });
  6028. +
  6029. + HotSwapTool.toVersion(EMCPTest.class, 0);
  6030. +
  6031. + TestUtil.assertException(RuntimeException.class, new Runnable(){
  6032. + @Override
  6033. + public void run() {
  6034. + C.c();
  6035. + }
  6036. + });
  6037. +
  6038. + HotSwapTool.toVersion(EMCPTest.class, 0);
  6039. + }
  6040. +}
  6041. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/FacTest.java
  6042. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  6043. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/FacTest.java Fri Dec 17 13:23:04 2010 +0100
  6044. @@ -0,0 +1,104 @@
  6045. +/*
  6046. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  6047. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  6048. + *
  6049. + * This code is free software; you can redistribute it and/or modify it
  6050. + * under the terms of the GNU General Public License version 2 only, as
  6051. + * published by the Free Software Foundation.
  6052. + *
  6053. + * This code is distributed in the hope that it will be useful, but WITHOUT
  6054. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  6055. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  6056. + * version 2 for more details (a copy is included in the LICENSE file that
  6057. + * accompanied this code).
  6058. + *
  6059. + * You should have received a copy of the GNU General Public License version
  6060. + * 2 along with this work; if not, write to the Free Software Foundation,
  6061. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  6062. + *
  6063. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  6064. + * or visit www.oracle.com if you need additional information or have any
  6065. + * questions.
  6066. + *
  6067. + */
  6068. +
  6069. +package at.ssw.hotswap.test.body;
  6070. +
  6071. +import static org.junit.Assert.*;
  6072. +
  6073. +import org.junit.Before;
  6074. +
  6075. +import org.junit.Test;
  6076. +
  6077. +import at.ssw.hotswap.HotSwapTool;
  6078. +
  6079. +/**
  6080. + * Recursive implementation of the factorial function using class redefinition.
  6081. + *
  6082. + * @author Thomas Wuerthinger
  6083. + */
  6084. +public class FacTest {
  6085. +
  6086. + public static abstract class Base {
  6087. +
  6088. + protected int calc() {
  6089. + return calc(HotSwapTool.getCurrentVersion(FacTest.class));
  6090. + }
  6091. +
  6092. + public int calcAt(int version) {
  6093. + HotSwapTool.toVersion(FacTest.class, version);
  6094. + int result = calc();
  6095. + HotSwapTool.toVersion(FacTest.class, 0);
  6096. + return result;
  6097. + }
  6098. +
  6099. + protected int calc(int version) {
  6100. + return calc();
  6101. + }
  6102. + }
  6103. +
  6104. + public static class Factorial extends Base {
  6105. +
  6106. + @Override
  6107. + protected int calc(int n) {
  6108. + return n * calcAt(n - 1);
  6109. + }
  6110. + }
  6111. +
  6112. + public static class Factorial___1 extends Base {
  6113. +
  6114. + @Override
  6115. + protected int calc() {
  6116. + return 1;
  6117. + }
  6118. + }
  6119. +
  6120. + @Before
  6121. + public void setUp() throws Exception {
  6122. + HotSwapTool.toVersion(FacTest.class, 0);
  6123. + }
  6124. +
  6125. + @Test
  6126. + public void testFac() {
  6127. +
  6128. + assert HotSwapTool.getCurrentVersion(FacTest.class) == 0;
  6129. + Factorial f = new Factorial();
  6130. +
  6131. + assertEquals(1, f.calcAt(1));
  6132. +
  6133. + assert HotSwapTool.getCurrentVersion(FacTest.class) == 0;
  6134. + assertEquals(2, f.calcAt(2));
  6135. +
  6136. + assert HotSwapTool.getCurrentVersion(FacTest.class) == 0;
  6137. + assertEquals(6, f.calcAt(3));
  6138. +
  6139. + assert HotSwapTool.getCurrentVersion(FacTest.class) == 0;
  6140. + assertEquals(24, f.calcAt(4));
  6141. +
  6142. + assert HotSwapTool.getCurrentVersion(FacTest.class) == 0;
  6143. + assertEquals(120, f.calcAt(5));
  6144. +
  6145. + assert HotSwapTool.getCurrentVersion(FacTest.class) == 0;
  6146. + assertEquals(479001600, f.calcAt(12));
  6147. + }
  6148. +}
  6149. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/FibTest.java
  6150. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  6151. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/FibTest.java Fri Dec 17 13:23:04 2010 +0100
  6152. @@ -0,0 +1,111 @@
  6153. +/*
  6154. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  6155. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  6156. + *
  6157. + * This code is free software; you can redistribute it and/or modify it
  6158. + * under the terms of the GNU General Public License version 2 only, as
  6159. + * published by the Free Software Foundation.
  6160. + *
  6161. + * This code is distributed in the hope that it will be useful, but WITHOUT
  6162. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  6163. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  6164. + * version 2 for more details (a copy is included in the LICENSE file that
  6165. + * accompanied this code).
  6166. + *
  6167. + * You should have received a copy of the GNU General Public License version
  6168. + * 2 along with this work; if not, write to the Free Software Foundation,
  6169. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  6170. + *
  6171. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  6172. + * or visit www.oracle.com if you need additional information or have any
  6173. + * questions.
  6174. + *
  6175. + */
  6176. +
  6177. +package at.ssw.hotswap.test.body;
  6178. +
  6179. +import static org.junit.Assert.*;
  6180. +
  6181. +import org.junit.Before;
  6182. +
  6183. +import org.junit.Test;
  6184. +
  6185. +import at.ssw.hotswap.HotSwapTool;
  6186. +
  6187. +/**
  6188. + * Recursive implementation of the fibonacci function using class redefinition.
  6189. + *
  6190. + * @author Thomas Wuerthinger
  6191. + */
  6192. +public class FibTest {
  6193. +
  6194. + public static abstract class Base {
  6195. +
  6196. + protected int calc() {
  6197. + return calc(HotSwapTool.getCurrentVersion(FibTest.class));
  6198. + }
  6199. +
  6200. + public int calcAt(int version) {
  6201. + HotSwapTool.toVersion(FibTest.class, version);
  6202. + int result = calc();
  6203. + HotSwapTool.toVersion(FibTest.class, 0);
  6204. + return result;
  6205. + }
  6206. +
  6207. + protected int calc(int version) {
  6208. + return calc();
  6209. + }
  6210. + }
  6211. +
  6212. + public static class Fib extends Base {
  6213. +
  6214. + @Override
  6215. + protected int calc(int n) {
  6216. + return calcAt(n - 1) + calcAt(n - 2);
  6217. + }
  6218. + }
  6219. +
  6220. + public static class Fib___1 extends Base {
  6221. +
  6222. + @Override
  6223. + protected int calc() {
  6224. + return 1;
  6225. + }
  6226. + }
  6227. +
  6228. + public static class Fib___2 extends Base {
  6229. +
  6230. + @Override
  6231. + protected int calc() {
  6232. + return 2;
  6233. + }
  6234. + }
  6235. +
  6236. + @Before
  6237. + public void setUp() throws Exception {
  6238. + HotSwapTool.toVersion(FibTest.class, 0);
  6239. + }
  6240. +
  6241. + @Test
  6242. + public void testFib() {
  6243. +
  6244. + // 0 1 2 3 4 5
  6245. + // 1 1 2 3 5 8
  6246. + assert HotSwapTool.getCurrentVersion(FibTest.class) == 0;
  6247. + Fib f = new Fib();
  6248. +
  6249. + assertEquals(1, f.calcAt(1));
  6250. +
  6251. + assert HotSwapTool.getCurrentVersion(FibTest.class) == 0;
  6252. + assertEquals(2, f.calcAt(2));
  6253. +
  6254. + assert HotSwapTool.getCurrentVersion(FibTest.class) == 0;
  6255. + assertEquals(3, f.calcAt(3));
  6256. +
  6257. + assert HotSwapTool.getCurrentVersion(FibTest.class) == 0;
  6258. + assertEquals(5, f.calcAt(4));
  6259. +
  6260. + assert HotSwapTool.getCurrentVersion(FibTest.class) == 0;
  6261. + assertEquals(8, f.calcAt(5));
  6262. + }
  6263. +}
  6264. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/MultipleThreadsTest.java
  6265. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  6266. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/MultipleThreadsTest.java Fri Dec 17 13:23:04 2010 +0100
  6267. @@ -0,0 +1,207 @@
  6268. +/*
  6269. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  6270. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  6271. + *
  6272. + * This code is free software; you can redistribute it and/or modify it
  6273. + * under the terms of the GNU General Public License version 2 only, as
  6274. + * published by the Free Software Foundation.
  6275. + *
  6276. + * This code is distributed in the hope that it will be useful, but WITHOUT
  6277. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  6278. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  6279. + * version 2 for more details (a copy is included in the LICENSE file that
  6280. + * accompanied this code).
  6281. + *
  6282. + * You should have received a copy of the GNU General Public License version
  6283. + * 2 along with this work; if not, write to the Free Software Foundation,
  6284. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  6285. + *
  6286. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  6287. + * or visit www.oracle.com if you need additional information or have any
  6288. + * questions.
  6289. + *
  6290. + */
  6291. +
  6292. +package at.ssw.hotswap.test.body;
  6293. +
  6294. +import static org.junit.Assert.*;
  6295. +
  6296. +import org.junit.Before;
  6297. +import org.junit.Test;
  6298. +
  6299. +import at.ssw.hotswap.HotSwapTool;
  6300. +import at.ssw.hotswap.test.methods.OverrideMethodTest;
  6301. +
  6302. +/**
  6303. + * Class for testing redefining methods of classes that extend the Thread class. In the test setup the run method
  6304. + * calls the doit method in a loop until this methods returns false.
  6305. + *
  6306. + * @author Thomas Wuerthinger
  6307. + */
  6308. +public class MultipleThreadsTest {
  6309. +
  6310. + public static final int COUNT = 10;
  6311. +
  6312. + // Version 0
  6313. + public static class A extends Thread {
  6314. +
  6315. + private int value;
  6316. + private int value2;
  6317. + private boolean flag = false;
  6318. +
  6319. + @Override
  6320. + public void run() {
  6321. + while (doit()) {
  6322. + flag = false;
  6323. + }
  6324. + }
  6325. +
  6326. + public boolean doit() {
  6327. + if (flag) {
  6328. + throw new RuntimeException("Must not reach here");
  6329. + }
  6330. + flag = true;
  6331. + try {
  6332. + Thread.sleep(1);
  6333. + } catch (InterruptedException e) {
  6334. + }
  6335. +
  6336. + value++;
  6337. + return true;
  6338. + }
  6339. +
  6340. + public int getValue() {
  6341. + return value;
  6342. + }
  6343. +
  6344. + public int getValue2() {
  6345. + return value2;
  6346. + }
  6347. + }
  6348. +
  6349. + // Version 1
  6350. + public static class A___1 extends Thread {
  6351. +
  6352. + private int value;
  6353. + private int value2;
  6354. + private boolean flag = false;
  6355. +
  6356. + @Override
  6357. + public void run() {
  6358. + while (doit()) {
  6359. + flag = false;
  6360. + }
  6361. + }
  6362. +
  6363. + public boolean doit() {
  6364. + if (flag) {
  6365. + throw new RuntimeException("Must not reach here");
  6366. + }
  6367. + flag = true;
  6368. + try {
  6369. + Thread.sleep(1);
  6370. + } catch (InterruptedException e) {
  6371. + }
  6372. +
  6373. + value2++;
  6374. + return true;
  6375. + }
  6376. +
  6377. + public int getValue() {
  6378. + return value;
  6379. + }
  6380. +
  6381. + public int getValue2() {
  6382. + return value2;
  6383. + }
  6384. + }
  6385. +
  6386. + // Version 2
  6387. + public static class A___2 extends Thread {
  6388. +
  6389. + private int value;
  6390. + private int value2;
  6391. + private boolean flag = false;
  6392. +
  6393. + @Override
  6394. + public void run() {
  6395. + while (doit()) {
  6396. + flag = false;
  6397. + }
  6398. + }
  6399. +
  6400. + public boolean doit() {
  6401. + return false;
  6402. + }
  6403. +
  6404. + public int getValue() {
  6405. + return value;
  6406. + }
  6407. +
  6408. + public int getValue2() {
  6409. + return value2;
  6410. + }
  6411. + }
  6412. +
  6413. + @Before
  6414. + public void setUp() throws Exception {
  6415. + HotSwapTool.toVersion(MultipleThreadsTest.class, 0);
  6416. + }
  6417. +
  6418. + @Test
  6419. + public void testOneThread() {
  6420. + test(1);
  6421. + }
  6422. +
  6423. + @Test
  6424. + public void testThreads() {
  6425. + test(COUNT);
  6426. + }
  6427. +
  6428. + private void test(int count) {
  6429. +
  6430. + assert HotSwapTool.getCurrentVersion(MultipleThreadsTest.class) == 0;
  6431. +
  6432. + A[] arr = new A[count];
  6433. + for (int i = 0; i < count; i++) {
  6434. + arr[i] = new A();
  6435. + arr[i].start();
  6436. + }
  6437. +
  6438. + try {
  6439. + Thread.sleep(500);
  6440. + } catch (InterruptedException e) {
  6441. + }
  6442. +
  6443. + for (int i = 0; i < count; i++) {
  6444. + //assertTrue(arr[i].getValue() > 0);
  6445. + }
  6446. +
  6447. + HotSwapTool.toVersion(MultipleThreadsTest.class, 1);
  6448. +
  6449. + try {
  6450. + Thread.sleep(500);
  6451. + } catch (InterruptedException e) {
  6452. + }
  6453. +
  6454. + for (int i = 0; i < count; i++) {
  6455. + assertTrue(arr[i].getValue2() > 0);
  6456. + }
  6457. +
  6458. + HotSwapTool.toVersion(MultipleThreadsTest.class, 2);
  6459. +
  6460. + try {
  6461. + Thread.sleep(500);
  6462. + } catch (InterruptedException e) {
  6463. + }
  6464. +
  6465. +
  6466. + for (int i = 0; i < count; i++) {
  6467. + assertFalse(arr[i].isAlive());
  6468. + }
  6469. +
  6470. + HotSwapTool.toVersion(OverrideMethodTest.class, 0);
  6471. +
  6472. +
  6473. + }
  6474. +}
  6475. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/OldActivationTest.java
  6476. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  6477. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/OldActivationTest.java Fri Dec 17 13:23:04 2010 +0100
  6478. @@ -0,0 +1,158 @@
  6479. +/*
  6480. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  6481. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  6482. + *
  6483. + * This code is free software; you can redistribute it and/or modify it
  6484. + * under the terms of the GNU General Public License version 2 only, as
  6485. + * published by the Free Software Foundation.
  6486. + *
  6487. + * This code is distributed in the hope that it will be useful, but WITHOUT
  6488. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  6489. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  6490. + * version 2 for more details (a copy is included in the LICENSE file that
  6491. + * accompanied this code).
  6492. + *
  6493. + * You should have received a copy of the GNU General Public License version
  6494. + * 2 along with this work; if not, write to the Free Software Foundation,
  6495. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  6496. + *
  6497. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  6498. + * or visit www.oracle.com if you need additional information or have any
  6499. + * questions.
  6500. + *
  6501. + */
  6502. +
  6503. +package at.ssw.hotswap.test.body;
  6504. +
  6505. +import static org.junit.Assert.*;
  6506. +
  6507. +import org.junit.Before;
  6508. +import org.junit.Test;
  6509. +
  6510. +import at.ssw.hotswap.HotSwapTool;
  6511. +
  6512. +/**
  6513. + * Stress test for the number of old activations on the stack. In the test setup 10 different versions of the method A.value will be on the stack.
  6514. + *
  6515. + * @author Thomas Wuerthinger
  6516. + */
  6517. +public class OldActivationTest {
  6518. +
  6519. + // Version 0
  6520. + public static class A {
  6521. +
  6522. + public int value() {
  6523. + HotSwapTool.toVersion(OldActivationTest.class, 1);
  6524. + return 1 + this.value();
  6525. + }
  6526. + }
  6527. +
  6528. + // Version 1
  6529. + public static class A___1 {
  6530. +
  6531. + public int value() {
  6532. + HotSwapTool.toVersion(OldActivationTest.class, 2);
  6533. + return 2 + this.value();
  6534. + }
  6535. + }
  6536. +
  6537. + // Version 2
  6538. + public static class A___2 {
  6539. +
  6540. + public int value() {
  6541. + HotSwapTool.toVersion(OldActivationTest.class, 3);
  6542. + return 3 + this.value();
  6543. + }
  6544. + }
  6545. +
  6546. + // Version 3
  6547. + public static class A___3 {
  6548. +
  6549. + public int value() {
  6550. + HotSwapTool.toVersion(OldActivationTest.class, 4);
  6551. + return 4 + this.value();
  6552. + }
  6553. + }
  6554. +
  6555. + // Version 4
  6556. + public static class A___4 {
  6557. +
  6558. + public int value() {
  6559. + HotSwapTool.toVersion(OldActivationTest.class, 5);
  6560. + return 5 + this.value();
  6561. + }
  6562. + }
  6563. +
  6564. + // Version 5
  6565. + public static class A___5 {
  6566. +
  6567. + public int value() {
  6568. + HotSwapTool.toVersion(OldActivationTest.class, 6);
  6569. + return 6 + this.value();
  6570. + }
  6571. + }
  6572. +
  6573. + // Version 6
  6574. + public static class A___6 {
  6575. +
  6576. + public int value() {
  6577. + HotSwapTool.toVersion(OldActivationTest.class, 7);
  6578. + return 7 + this.value();
  6579. + }
  6580. + }
  6581. +
  6582. + // Version 7
  6583. + public static class A___7 {
  6584. +
  6585. + public int value() {
  6586. + HotSwapTool.toVersion(OldActivationTest.class, 8);
  6587. + return 8 + this.value();
  6588. + }
  6589. + }
  6590. +
  6591. + // Version 8
  6592. + public static class A___8 {
  6593. +
  6594. + public int value() {
  6595. + HotSwapTool.toVersion(OldActivationTest.class, 9);
  6596. + return 9 + this.value();
  6597. + }
  6598. + }
  6599. +
  6600. + // Version 9
  6601. + public static class A___9 {
  6602. +
  6603. + public int value() {
  6604. + HotSwapTool.toVersion(OldActivationTest.class, 0);
  6605. + return 10;
  6606. + }
  6607. + }
  6608. +
  6609. + @Before
  6610. + public void setUp() throws Exception {
  6611. + HotSwapTool.toVersion(OldActivationTest.class, 0);
  6612. + }
  6613. +
  6614. + @Test
  6615. + public void testOldActivationTest() {
  6616. +
  6617. + assert HotSwapTool.getCurrentVersion(OldActivationTest.class) == 0;
  6618. +
  6619. + A a = new A();
  6620. +
  6621. + assertEquals(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, a.value());
  6622. + assert HotSwapTool.getCurrentVersion(OldActivationTest.class) == 0;
  6623. +
  6624. + HotSwapTool.toVersion(OldActivationTest.class, 1);
  6625. + assertEquals(2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, a.value());
  6626. + assert HotSwapTool.getCurrentVersion(OldActivationTest.class) == 0;
  6627. +
  6628. + HotSwapTool.toVersion(OldActivationTest.class, 8);
  6629. + assertEquals(9 + 10, a.value());
  6630. + assert HotSwapTool.getCurrentVersion(OldActivationTest.class) == 0;
  6631. +
  6632. + HotSwapTool.toVersion(OldActivationTest.class, 4);
  6633. + assertEquals(5 + 6 + 7 + 8 + 9 + 10, a.value());
  6634. + assert HotSwapTool.getCurrentVersion(OldActivationTest.class) == 0;
  6635. + }
  6636. +}
  6637. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/RedefinePrivateMethodTest.java
  6638. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  6639. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/RedefinePrivateMethodTest.java Fri Dec 17 13:23:04 2010 +0100
  6640. @@ -0,0 +1,96 @@
  6641. +/*
  6642. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  6643. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  6644. + *
  6645. + * This code is free software; you can redistribute it and/or modify it
  6646. + * under the terms of the GNU General Public License version 2 only, as
  6647. + * published by the Free Software Foundation.
  6648. + *
  6649. + * This code is distributed in the hope that it will be useful, but WITHOUT
  6650. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  6651. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  6652. + * version 2 for more details (a copy is included in the LICENSE file that
  6653. + * accompanied this code).
  6654. + *
  6655. + * You should have received a copy of the GNU General Public License version
  6656. + * 2 along with this work; if not, write to the Free Software Foundation,
  6657. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  6658. + *
  6659. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  6660. + * or visit www.oracle.com if you need additional information or have any
  6661. + * questions.
  6662. + *
  6663. + */
  6664. +
  6665. +package at.ssw.hotswap.test.body;
  6666. +
  6667. +import static org.junit.Assert.*;
  6668. +
  6669. +import org.junit.Before;
  6670. +import org.junit.Test;
  6671. +
  6672. +import at.ssw.hotswap.HotSwapTool;
  6673. +
  6674. +/**
  6675. + * Tests redefinition of a class such that old code still accesses a redefined private method.
  6676. + *
  6677. + * @author Thomas Wuerthinger
  6678. + */
  6679. +public class RedefinePrivateMethodTest {
  6680. +
  6681. + // Version 0
  6682. + public static class A {
  6683. +
  6684. + public int foo() {
  6685. + int result = bar();
  6686. + HotSwapTool.toVersion(RedefinePrivateMethodTest.class, 1);
  6687. + result += bar();
  6688. + return result;
  6689. + }
  6690. +
  6691. + private int bar() {
  6692. + return 1;
  6693. + }
  6694. + }
  6695. +
  6696. + // Version 1
  6697. + public static class A___1 {
  6698. +
  6699. + public int foo() {
  6700. + return -1;
  6701. + }
  6702. +
  6703. + private int bar() {
  6704. + return 2;
  6705. + }
  6706. + }
  6707. +
  6708. + @Before
  6709. + public void setUp() throws Exception {
  6710. + HotSwapTool.toVersion(RedefinePrivateMethodTest.class, 0);
  6711. + }
  6712. +
  6713. + @Test
  6714. + public void testRedefinePrivateMethod() {
  6715. +
  6716. + assert HotSwapTool.getCurrentVersion(RedefinePrivateMethodTest.class) == 0;
  6717. +
  6718. + A a = new A();
  6719. +
  6720. + assertEquals(3, a.foo());
  6721. +
  6722. + assert HotSwapTool.getCurrentVersion(RedefinePrivateMethodTest.class) == 1;
  6723. +
  6724. + assertEquals(-1, a.foo());
  6725. +
  6726. + HotSwapTool.toVersion(RedefinePrivateMethodTest.class, 0);
  6727. +
  6728. + assertEquals(3, a.foo());
  6729. +
  6730. + assert HotSwapTool.getCurrentVersion(RedefinePrivateMethodTest.class) == 1;
  6731. +
  6732. + assertEquals(-1, a.foo());
  6733. +
  6734. + HotSwapTool.toVersion(RedefinePrivateMethodTest.class, 0);
  6735. + }
  6736. +}
  6737. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/RefactorActiveMethodTest.java
  6738. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  6739. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/RefactorActiveMethodTest.java Fri Dec 17 13:23:04 2010 +0100
  6740. @@ -0,0 +1,96 @@
  6741. +/*
  6742. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  6743. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  6744. + *
  6745. + * This code is free software; you can redistribute it and/or modify it
  6746. + * under the terms of the GNU General Public License version 2 only, as
  6747. + * published by the Free Software Foundation.
  6748. + *
  6749. + * This code is distributed in the hope that it will be useful, but WITHOUT
  6750. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  6751. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  6752. + * version 2 for more details (a copy is included in the LICENSE file that
  6753. + * accompanied this code).
  6754. + *
  6755. + * You should have received a copy of the GNU General Public License version
  6756. + * 2 along with this work; if not, write to the Free Software Foundation,
  6757. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  6758. + *
  6759. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  6760. + * or visit www.oracle.com if you need additional information or have any
  6761. + * questions.
  6762. + *
  6763. + */
  6764. +
  6765. +package at.ssw.hotswap.test.body;
  6766. +
  6767. +import static org.junit.Assert.*;
  6768. +
  6769. +import org.junit.Before;
  6770. +import org.junit.Test;
  6771. +
  6772. +import at.ssw.hotswap.HotSwapTool;
  6773. +
  6774. +/**
  6775. + * @author Thomas Wuerthinger
  6776. + */
  6777. +public class RefactorActiveMethodTest {
  6778. +
  6779. + // Version 0
  6780. + public static class A {
  6781. +
  6782. + public int value() {
  6783. + HotSwapTool.toVersion(RefactorActiveMethodTest.class, 1);
  6784. + return 5;
  6785. + }
  6786. +
  6787. + public int secondValue() {
  6788. + return 1;
  6789. + }
  6790. + }
  6791. +
  6792. + // Version 1
  6793. + public static class A___1 {
  6794. +
  6795. + public int value() {
  6796. + return secondValue() * 2;
  6797. + }
  6798. +
  6799. + public int secondValue() {
  6800. + return 2;
  6801. + }
  6802. + }
  6803. +
  6804. + @Before
  6805. + public void setUp() throws Exception {
  6806. + HotSwapTool.toVersion(RefactorActiveMethodTest.class, 0);
  6807. + }
  6808. +
  6809. + @Test
  6810. + public void testActiveMethodReplacement() {
  6811. +
  6812. + assert HotSwapTool.getCurrentVersion(RefactorActiveMethodTest.class) == 0;
  6813. +
  6814. + A a = new A();
  6815. +
  6816. + assertEquals(5, a.value());
  6817. +
  6818. + assert HotSwapTool.getCurrentVersion(RefactorActiveMethodTest.class) == 1;
  6819. +
  6820. + assertEquals(2, a.secondValue());
  6821. + assertEquals(4, a.value());
  6822. + assertEquals(2, a.secondValue());
  6823. +
  6824. + assert HotSwapTool.getCurrentVersion(RefactorActiveMethodTest.class) == 1;
  6825. +
  6826. + HotSwapTool.toVersion(RefactorActiveMethodTest.class, 0);
  6827. +
  6828. + assertEquals(1, a.secondValue());
  6829. + assertEquals(5, a.value());
  6830. + assertEquals(4, a.value());
  6831. +
  6832. + HotSwapTool.toVersion(RefactorActiveMethodTest.class, 0);
  6833. +
  6834. + assertEquals(1, a.secondValue());
  6835. + }
  6836. +}
  6837. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/SimpleStaticTest.java
  6838. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  6839. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/SimpleStaticTest.java Fri Dec 17 13:23:04 2010 +0100
  6840. @@ -0,0 +1,125 @@
  6841. +/*
  6842. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  6843. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  6844. + *
  6845. + * This code is free software; you can redistribute it and/or modify it
  6846. + * under the terms of the GNU General Public License version 2 only, as
  6847. + * published by the Free Software Foundation.
  6848. + *
  6849. + * This code is distributed in the hope that it will be useful, but WITHOUT
  6850. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  6851. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  6852. + * version 2 for more details (a copy is included in the LICENSE file that
  6853. + * accompanied this code).
  6854. + *
  6855. + * You should have received a copy of the GNU General Public License version
  6856. + * 2 along with this work; if not, write to the Free Software Foundation,
  6857. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  6858. + *
  6859. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  6860. + * or visit www.oracle.com if you need additional information or have any
  6861. + * questions.
  6862. + *
  6863. + */
  6864. +
  6865. +package at.ssw.hotswap.test.body;
  6866. +
  6867. +import static org.junit.Assert.*;
  6868. +
  6869. +import org.junit.Before;
  6870. +import org.junit.Test;
  6871. +
  6872. +import at.ssw.hotswap.HotSwapTool;
  6873. +import at.ssw.hotswap.test.TestUtil;
  6874. +
  6875. +/**
  6876. + * @author Thomas Wuerthinger
  6877. + */
  6878. +public class SimpleStaticTest {
  6879. +
  6880. + @Before
  6881. + public void setUp() throws Exception {
  6882. + HotSwapTool.toVersion(SimpleStaticTest.class, 0);
  6883. +
  6884. + // E and Helper must be loaded and initialized
  6885. + E e = new E();
  6886. + Helper h = new Helper();
  6887. + }
  6888. +
  6889. + // Version 0
  6890. +
  6891. + public static class Helper {
  6892. + public static int getIntegerField() {
  6893. + return E.integerField;
  6894. + }
  6895. +
  6896. + public static void setIntegerField(int x) {
  6897. + E.integerField = x;
  6898. + }
  6899. +
  6900. + public static int getFinalIntegerField() {
  6901. + return E.finalIntegerField;
  6902. + }
  6903. + }
  6904. +
  6905. + public static class E {
  6906. + public static int integerField = 10;
  6907. +
  6908. + // javac will generate "ConstantValue" attribute for this field!
  6909. + public static final int finalIntegerField = 7;
  6910. + }
  6911. +
  6912. + public static class E___1 {
  6913. + }
  6914. +
  6915. + // Version 1
  6916. + public static class E___2 {
  6917. + public static int integerField = 10;
  6918. +
  6919. + // javac will generate "ConstantValue" attribute for this field!
  6920. + public static final int finalIntegerField = 7;
  6921. + }
  6922. +
  6923. + @Test
  6924. + public void testSimpleNewStaticField() {
  6925. +
  6926. + assert HotSwapTool.getCurrentVersion(SimpleStaticTest.class) == 0;
  6927. +
  6928. + HotSwapTool.toVersion(SimpleStaticTest.class, 1);
  6929. +
  6930. + TestUtil.assertException(NoSuchFieldError.class, new Runnable(){
  6931. + @Override
  6932. + public void run() {
  6933. + Helper.getIntegerField();
  6934. + }
  6935. + });
  6936. +
  6937. + HotSwapTool.toVersion(SimpleStaticTest.class, 2);
  6938. +
  6939. + assertEquals(0, Helper.getIntegerField());
  6940. + assertEquals(7, Helper.getFinalIntegerField());
  6941. + Helper.setIntegerField(1000);
  6942. + assertEquals(1000, Helper.getIntegerField());
  6943. +
  6944. + HotSwapTool.toVersion(SimpleStaticTest.class, 1);
  6945. +
  6946. + TestUtil.assertException(NoSuchFieldError.class, new Runnable(){
  6947. + @Override
  6948. + public void run() {
  6949. + Helper.getIntegerField();
  6950. + }
  6951. + });
  6952. +
  6953. + HotSwapTool.toVersion(SimpleStaticTest.class, 2);
  6954. +
  6955. + assertEquals(0, Helper.getIntegerField());
  6956. + assertEquals(7, Helper.getFinalIntegerField());
  6957. + Helper.setIntegerField(1000);
  6958. + assertEquals(1000, Helper.getIntegerField());
  6959. +
  6960. + HotSwapTool.toVersion(SimpleStaticTest.class, 0);
  6961. +
  6962. + assertEquals(7, Helper.getFinalIntegerField());
  6963. + assertEquals(1000, Helper.getIntegerField());
  6964. + }
  6965. +}
  6966. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/StaticTest.java
  6967. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  6968. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/StaticTest.java Fri Dec 17 13:23:04 2010 +0100
  6969. @@ -0,0 +1,269 @@
  6970. +/*
  6971. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  6972. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  6973. + *
  6974. + * This code is free software; you can redistribute it and/or modify it
  6975. + * under the terms of the GNU General Public License version 2 only, as
  6976. + * published by the Free Software Foundation.
  6977. + *
  6978. + * This code is distributed in the hope that it will be useful, but WITHOUT
  6979. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  6980. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  6981. + * version 2 for more details (a copy is included in the LICENSE file that
  6982. + * accompanied this code).
  6983. + *
  6984. + * You should have received a copy of the GNU General Public License version
  6985. + * 2 along with this work; if not, write to the Free Software Foundation,
  6986. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  6987. + *
  6988. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  6989. + * or visit www.oracle.com if you need additional information or have any
  6990. + * questions.
  6991. + *
  6992. + */
  6993. +
  6994. +package at.ssw.hotswap.test.body;
  6995. +
  6996. +import static org.junit.Assert.*;
  6997. +
  6998. +import org.junit.Before;
  6999. +import org.junit.Test;
  7000. +
  7001. +import at.ssw.hotswap.HotSwapTool;
  7002. +import java.util.ArrayList;
  7003. +import java.util.List;
  7004. +
  7005. +/**
  7006. + * @author Thomas Wuerthinger
  7007. + */
  7008. +public class StaticTest {
  7009. +
  7010. + @Before
  7011. + public void setUp() throws Exception {
  7012. + HotSwapTool.toVersion(StaticTest.class, 0);
  7013. + }
  7014. +
  7015. + // Version 0
  7016. +
  7017. +
  7018. + public static class Helper {
  7019. + public static int getAdditionalField() {
  7020. + return -1;
  7021. + }
  7022. +
  7023. + public static void setAdditionalField(int x) {
  7024. +
  7025. + }
  7026. + }
  7027. +
  7028. + public static class A {
  7029. +
  7030. + public static int value() {
  7031. + return 1;
  7032. + }
  7033. + }
  7034. +
  7035. + public static class B {
  7036. +
  7037. + public static int value() {
  7038. + return 2;
  7039. + }
  7040. + }
  7041. +
  7042. + public static class C {
  7043. + static {
  7044. + System.out.println("Static initializer of C");
  7045. + }
  7046. +
  7047. + public static int value = 5;
  7048. + }
  7049. +
  7050. + public static class D {
  7051. + public static List objectField = new ArrayList();
  7052. + public static int[] arrayField = new int[10];
  7053. + public static int integerField = 5;
  7054. + public static char characterField = 6;
  7055. + public static short shortField = 7;
  7056. + public static double doubleField = 1.0;
  7057. + public static float floatField = 2.0f;
  7058. + public static long longField = 8;
  7059. + public static boolean booleanField = true;
  7060. + }
  7061. +
  7062. + // Version 1
  7063. + public static class A___1 {
  7064. +
  7065. + public static int value() {
  7066. + return B.value() * 2;
  7067. + }
  7068. + }
  7069. +
  7070. + // Version 2
  7071. + public static class B___2 {
  7072. +
  7073. + public static int value() {
  7074. + return 3;
  7075. + }
  7076. + }
  7077. +
  7078. + // Version 3
  7079. + public static class A___3 {
  7080. +
  7081. + public static int value() {
  7082. + return 5;
  7083. + }
  7084. + }
  7085. +
  7086. + public static class B___3 {
  7087. +
  7088. + public static int value() {
  7089. + return A.value() * 2;
  7090. + }
  7091. + }
  7092. +
  7093. + // Version 4
  7094. + public static class C___4 {
  7095. +
  7096. + static {
  7097. + System.out.println("Static initializer of C-4");
  7098. + }
  7099. +
  7100. + public static int value = 6;
  7101. + }
  7102. +
  7103. + public static class Helper___5 {
  7104. + public static int getAdditionalField() {
  7105. + return D___5.additionalField;
  7106. + }
  7107. +
  7108. + public static void setAdditionalField(int x) {
  7109. + D___5.additionalField = x;
  7110. + }
  7111. + }
  7112. +
  7113. + public static class D___5 {
  7114. + public static int additionalField;
  7115. +
  7116. + public static List objectField;
  7117. + public static long longField;
  7118. + public static short shortField = 10;
  7119. + public static float floatField;
  7120. + public static int[] arrayField;
  7121. + public static int integerField;
  7122. + public static char characterField;
  7123. + public static double doubleField;
  7124. + public static boolean booleanField;
  7125. + }
  7126. +
  7127. + @Test
  7128. + public void testBase() {
  7129. +
  7130. + assert HotSwapTool.getCurrentVersion(StaticTest.class) == 0;
  7131. +
  7132. +
  7133. + assertEquals(1, A.value());
  7134. + assertEquals(2, B.value());
  7135. +
  7136. + HotSwapTool.toVersion(StaticTest.class, 1);
  7137. +
  7138. + assertEquals(4, A.value());
  7139. + assertEquals(2, B.value());
  7140. +
  7141. + HotSwapTool.toVersion(StaticTest.class, 2);
  7142. +
  7143. + assertEquals(6, A.value());
  7144. + assertEquals(3, B.value());
  7145. +
  7146. + HotSwapTool.toVersion(StaticTest.class, 3);
  7147. +
  7148. + assertEquals(5, A.value());
  7149. + assertEquals(10, B.value());
  7150. +
  7151. + HotSwapTool.toVersion(StaticTest.class, 0);
  7152. +
  7153. + assertEquals(1, A.value());
  7154. + assertEquals(2, B.value());
  7155. + }
  7156. +
  7157. + @Test
  7158. + public void testStaticField() {
  7159. +
  7160. + assert HotSwapTool.getCurrentVersion(StaticTest.class) == 0;
  7161. + assertEquals(5, C.value);
  7162. +
  7163. + HotSwapTool.toVersion(StaticTest.class, 4);
  7164. + assertEquals(5, C.value);
  7165. +
  7166. + HotSwapTool.toVersion(StaticTest.class, 0);
  7167. + assertEquals(5, C.value);
  7168. + }
  7169. +
  7170. +
  7171. + @Test
  7172. + public void testManyStaticFields() {
  7173. +
  7174. + assert HotSwapTool.getCurrentVersion(StaticTest.class) == 0;
  7175. + assertTrue(D.objectField != null);
  7176. + assertTrue(D.arrayField != null);
  7177. + assertEquals(5, D.integerField);
  7178. + assertEquals(6, D.characterField);
  7179. + assertEquals(7, D.shortField);
  7180. + assertEquals(1.0, D.doubleField, 0.0);
  7181. + assertEquals(2.0f, D.floatField, 0.0);
  7182. + assertEquals(8, D.longField);
  7183. + assertEquals(true, D.booleanField);
  7184. +
  7185. + HotSwapTool.toVersion(StaticTest.class, 5);
  7186. + assertTrue(D.objectField != null);
  7187. + assertTrue(D.arrayField != null);
  7188. + assertEquals(5, D.integerField);
  7189. + assertEquals(6, D.characterField);
  7190. + assertEquals(7, D.shortField);
  7191. + assertEquals(1.0, D.doubleField, 0.0);
  7192. + assertEquals(2.0f, D.floatField, 0.0);
  7193. + assertEquals(8, D.longField);
  7194. + assertEquals(true, D.booleanField);
  7195. +
  7196. + assertEquals(0, Helper.getAdditionalField());
  7197. + Helper.setAdditionalField(1000);
  7198. + assertEquals(1000, Helper.getAdditionalField());
  7199. +
  7200. +
  7201. + HotSwapTool.toVersion(StaticTest.class, 0);
  7202. +
  7203. + assertTrue(D.objectField != null);
  7204. + assertTrue(D.arrayField != null);
  7205. + assertEquals(5, D.integerField);
  7206. + assertEquals(6, D.characterField);
  7207. + assertEquals(7, D.shortField);
  7208. + assertEquals(1.0, D.doubleField, 0.0);
  7209. + assertEquals(2.0f, D.floatField, 0.0);
  7210. + assertEquals(8, D.longField);
  7211. + assertEquals(true, D.booleanField);
  7212. +
  7213. + HotSwapTool.toVersion(StaticTest.class, 5);
  7214. + assertTrue(D.objectField != null);
  7215. + assertTrue(D.arrayField != null);
  7216. + assertEquals(5, D.integerField);
  7217. + assertEquals(6, D.characterField);
  7218. + assertEquals(7, D.shortField);
  7219. + assertEquals(1.0, D.doubleField, 0.0);
  7220. + assertEquals(2.0f, D.floatField, 0.0);
  7221. + assertEquals(8, D.longField);
  7222. + assertEquals(true, D.booleanField);
  7223. +
  7224. + assertEquals(0, Helper.getAdditionalField());
  7225. +
  7226. + HotSwapTool.toVersion(StaticTest.class, 0);
  7227. + assertTrue(D.objectField != null);
  7228. + assertTrue(D.arrayField != null);
  7229. + assertEquals(5, D.integerField);
  7230. + assertEquals(6, D.characterField);
  7231. + assertEquals(7, D.shortField);
  7232. + assertEquals(1.0, D.doubleField, 0.0);
  7233. + assertEquals(2.0f, D.floatField, 0.0);
  7234. + assertEquals(8, D.longField);
  7235. + assertEquals(true, D.booleanField);
  7236. +
  7237. + }
  7238. +}
  7239. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/StressTest.java
  7240. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  7241. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/body/StressTest.java Fri Dec 17 13:23:04 2010 +0100
  7242. @@ -0,0 +1,82 @@
  7243. +/*
  7244. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  7245. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  7246. + *
  7247. + * This code is free software; you can redistribute it and/or modify it
  7248. + * under the terms of the GNU General Public License version 2 only, as
  7249. + * published by the Free Software Foundation.
  7250. + *
  7251. + * This code is distributed in the hope that it will be useful, but WITHOUT
  7252. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  7253. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  7254. + * version 2 for more details (a copy is included in the LICENSE file that
  7255. + * accompanied this code).
  7256. + *
  7257. + * You should have received a copy of the GNU General Public License version
  7258. + * 2 along with this work; if not, write to the Free Software Foundation,
  7259. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  7260. + *
  7261. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  7262. + * or visit www.oracle.com if you need additional information or have any
  7263. + * questions.
  7264. + *
  7265. + */
  7266. +
  7267. +package at.ssw.hotswap.test.body;
  7268. +
  7269. +import static org.junit.Assert.*;
  7270. +
  7271. +import org.junit.Before;
  7272. +import org.junit.Test;
  7273. +
  7274. +import at.ssw.hotswap.HotSwapTool;
  7275. +
  7276. +/**
  7277. + * @author Thomas Wuerthinger
  7278. + */
  7279. +public class StressTest {
  7280. +
  7281. + public final static int COUNT = 10;
  7282. +
  7283. + // Version 0
  7284. + public static class A {
  7285. +
  7286. + public int value() {
  7287. + return 1;
  7288. + }
  7289. + }
  7290. +
  7291. + // Version 1
  7292. + public static class A___1 {
  7293. +
  7294. + public int value() {
  7295. + return 2;
  7296. + }
  7297. + }
  7298. +
  7299. + @Before
  7300. + public void setUp() throws Exception {
  7301. + HotSwapTool.toVersion(StressTest.class, 0);
  7302. + }
  7303. +
  7304. + @Test
  7305. + public void testStressSwap() {
  7306. +
  7307. + assert HotSwapTool.getCurrentVersion(StressTest.class) == 0;
  7308. +
  7309. + A a = new A();
  7310. +
  7311. + for (int i = 0; i < COUNT; i++) {
  7312. +
  7313. + assertEquals(1, a.value());
  7314. +
  7315. + HotSwapTool.toVersion(StressTest.class, 1);
  7316. +
  7317. + assertEquals(2, a.value());
  7318. +
  7319. + HotSwapTool.toVersion(StressTest.class, 0);
  7320. + }
  7321. +
  7322. + assertEquals(1, a.value());
  7323. + }
  7324. +}
  7325. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/eval/AddingInterfaceTest.java
  7326. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  7327. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/eval/AddingInterfaceTest.java Fri Dec 17 13:23:04 2010 +0100
  7328. @@ -0,0 +1,119 @@
  7329. +/*
  7330. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  7331. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  7332. + *
  7333. + * This code is free software; you can redistribute it and/or modify it
  7334. + * under the terms of the GNU General Public License version 2 only, as
  7335. + * published by the Free Software Foundation.
  7336. + *
  7337. + * This code is distributed in the hope that it will be useful, but WITHOUT
  7338. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  7339. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  7340. + * version 2 for more details (a copy is included in the LICENSE file that
  7341. + * accompanied this code).
  7342. + *
  7343. + * You should have received a copy of the GNU General Public License version
  7344. + * 2 along with this work; if not, write to the Free Software Foundation,
  7345. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  7346. + *
  7347. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  7348. + * or visit www.oracle.com if you need additional information or have any
  7349. + * questions.
  7350. + *
  7351. + */
  7352. +
  7353. +package at.ssw.hotswap.test.eval;
  7354. +
  7355. +import at.ssw.hotswap.HotSwapTool;
  7356. +import java.util.ArrayList;
  7357. +import java.util.List;
  7358. +import org.junit.Before;
  7359. +import org.junit.Test;
  7360. +
  7361. +/**
  7362. + * Adds an implemented interface to a class and tests whether an instance of this class can then really be treated as an instance of the interface.
  7363. + * Additionally, performs performance measurements of a call to this interface compared to a proxy object.
  7364. + *
  7365. + * @author Thomas Wuerthinger
  7366. + */
  7367. +public class AddingInterfaceTest {
  7368. +
  7369. + @Before
  7370. + public void setUp() throws Exception {
  7371. + HotSwapTool.toVersion(AddingInterfaceTest.class, 0);
  7372. + assert HotSwapTool.getCurrentVersion(AddingInterfaceTest.class) == 0;
  7373. + }
  7374. +
  7375. + public static class A {
  7376. +
  7377. + public int getValue() {
  7378. + return 1;
  7379. + }
  7380. + }
  7381. +
  7382. + public static interface I {
  7383. +
  7384. + public int getValue();
  7385. + }
  7386. +
  7387. + public static class A___1 implements I {
  7388. +
  7389. + public int getValue() {
  7390. + return 1;
  7391. + }
  7392. + }
  7393. +
  7394. + public static class Proxy implements I {
  7395. +
  7396. + private A a;
  7397. +
  7398. + public Proxy(A a) {
  7399. + this.a = a;
  7400. + }
  7401. +
  7402. + public int getValue() {
  7403. + return a.getValue();
  7404. + }
  7405. + }
  7406. +
  7407. + @Test
  7408. + public void testAddInterface() {
  7409. +
  7410. + A a = new A();
  7411. + Proxy p = new Proxy(a);
  7412. +
  7413. + final int N = 100000;
  7414. + final int Z = 1;
  7415. +
  7416. +
  7417. +
  7418. + HotSwapTool.toVersion(AddingInterfaceTest.class, 1);
  7419. + I i = (I) a;
  7420. +
  7421. + long startTime = System.currentTimeMillis();
  7422. + for (int j = 0; j < Z; j++) {
  7423. + calculateSum(N, i);
  7424. + }
  7425. + long time = System.currentTimeMillis() - startTime;
  7426. + System.out.println(time);
  7427. +
  7428. + // Must set to null, otherwise local variable i would violate type safety
  7429. + i = null;
  7430. + HotSwapTool.toVersion(AddingInterfaceTest.class, 0);
  7431. +
  7432. + startTime = System.currentTimeMillis();
  7433. + for (int j = 0; j < Z; j++) {
  7434. + calculateSum(N, p);
  7435. + }
  7436. + time = System.currentTimeMillis() - startTime;
  7437. + System.out.println(time);
  7438. + }
  7439. +
  7440. + public int calculateSum(int n, I i) {
  7441. + int sum = 0;
  7442. + for (int j = 0; j < n; j++) {
  7443. + sum += i.getValue();
  7444. + }
  7445. + return sum;
  7446. + }
  7447. +}
  7448. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/eval/EvalTestSuite.java
  7449. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  7450. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/eval/EvalTestSuite.java Fri Dec 17 13:23:04 2010 +0100
  7451. @@ -0,0 +1,43 @@
  7452. +/*
  7453. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  7454. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  7455. + *
  7456. + * This code is free software; you can redistribute it and/or modify it
  7457. + * under the terms of the GNU General Public License version 2 only, as
  7458. + * published by the Free Software Foundation.
  7459. + *
  7460. + * This code is distributed in the hope that it will be useful, but WITHOUT
  7461. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  7462. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  7463. + * version 2 for more details (a copy is included in the LICENSE file that
  7464. + * accompanied this code).
  7465. + *
  7466. + * You should have received a copy of the GNU General Public License version
  7467. + * 2 along with this work; if not, write to the Free Software Foundation,
  7468. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  7469. + *
  7470. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  7471. + * or visit www.oracle.com if you need additional information or have any
  7472. + * questions.
  7473. + *
  7474. + */
  7475. +
  7476. +package at.ssw.hotswap.test.eval;
  7477. +
  7478. +import org.junit.runner.RunWith;
  7479. +import org.junit.runners.Suite;
  7480. +
  7481. +/**
  7482. + *
  7483. + * Tests used for evaluation purposes (especially performance measurements).
  7484. + *
  7485. + * @author Thomas Wuerthinger
  7486. + *
  7487. + */
  7488. +@RunWith(Suite.class)
  7489. +@Suite.SuiteClasses({
  7490. + FractionTest.class,
  7491. + AddingInterfaceTest.class
  7492. +})
  7493. +public class EvalTestSuite {
  7494. +}
  7495. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/eval/FractionTest.java
  7496. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  7497. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/eval/FractionTest.java Fri Dec 17 13:23:04 2010 +0100
  7498. @@ -0,0 +1,232 @@
  7499. +/*
  7500. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  7501. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  7502. + *
  7503. + * This code is free software; you can redistribute it and/or modify it
  7504. + * under the terms of the GNU General Public License version 2 only, as
  7505. + * published by the Free Software Foundation.
  7506. + *
  7507. + * This code is distributed in the hope that it will be useful, but WITHOUT
  7508. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  7509. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  7510. + * version 2 for more details (a copy is included in the LICENSE file that
  7511. + * accompanied this code).
  7512. + *
  7513. + * You should have received a copy of the GNU General Public License version
  7514. + * 2 along with this work; if not, write to the Free Software Foundation,
  7515. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  7516. + *
  7517. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  7518. + * or visit www.oracle.com if you need additional information or have any
  7519. + * questions.
  7520. + *
  7521. + */
  7522. +
  7523. +package at.ssw.hotswap.test.eval;
  7524. +
  7525. +import java.lang.Runnable;
  7526. +import java.util.ArrayList;
  7527. +import java.util.List;
  7528. +import org.junit.Before;
  7529. +import org.junit.Test;
  7530. +
  7531. +import at.ssw.hotswap.HotSwapTool;
  7532. +
  7533. +/**
  7534. + * @author Thomas Wuerthinger
  7535. + */
  7536. +public class FractionTest {
  7537. +
  7538. + @Before
  7539. + public void setUp() throws Exception {
  7540. + HotSwapTool.toVersion(FractionTest.class, 0);
  7541. + assert HotSwapTool.getCurrentVersion(FractionTest.class) == 0;
  7542. + }
  7543. +
  7544. + // Version 0
  7545. + public static class NoChange {
  7546. +
  7547. + int i1;
  7548. + int i2;
  7549. + int i3;
  7550. + Object o1;
  7551. + Object o2;
  7552. + Object o3;
  7553. + }
  7554. +
  7555. + public static class Change {
  7556. +
  7557. + int i1;
  7558. + int i2;
  7559. + int i3;
  7560. + Object o1;
  7561. + Object o2;
  7562. + Object o3;
  7563. + }
  7564. +
  7565. + // Version 1
  7566. + public static class Change___1 {
  7567. +
  7568. + int i1;
  7569. + int i2;
  7570. + int i3;
  7571. + Object o1;
  7572. + Object o2;
  7573. + Object o3;
  7574. + Object o4;
  7575. + }
  7576. +
  7577. + // Version 2
  7578. + public static class Change___2 {
  7579. +
  7580. + int i1;
  7581. + int i2;
  7582. + int i3;
  7583. + Object o1;
  7584. + }
  7585. +
  7586. + // Version 3
  7587. + public static class Change___3 {
  7588. +
  7589. + int i3;
  7590. + int i1;
  7591. + int i2;
  7592. + Object o3;
  7593. + Object o1;
  7594. + Object o2;
  7595. + }
  7596. +
  7597. + // Version 3
  7598. + public static class Change___4 {
  7599. +
  7600. + int i1;
  7601. + int i2;
  7602. + int i3;
  7603. + Object o1;
  7604. + Object o2;
  7605. + Object o3;
  7606. + }
  7607. + private static List<Long> measurements = new ArrayList<Long>();
  7608. + private final int BASE = 10;
  7609. + private Object[] objects;
  7610. +
  7611. + private void clear() {
  7612. + objects = null;
  7613. + System.gc();
  7614. + System.gc();
  7615. + HotSwapTool.toVersion(FractionTest.class, 0);
  7616. + System.gc();
  7617. + System.gc();
  7618. +
  7619. + }
  7620. +
  7621. + private void init(int count, int percent) {
  7622. + objects = new Object[count];
  7623. + int changed = 0;
  7624. + int unchanged = 0;
  7625. + for (int k = 0; k < count; k++) {
  7626. + if ((count / BASE) * percent <= k/* && k >= 200000*/) {
  7627. + objects[k] = new NoChange();
  7628. + unchanged++;
  7629. + } else {
  7630. + objects[k] = new Change();
  7631. + changed++;
  7632. + }
  7633. + }
  7634. +
  7635. + System.gc();
  7636. +
  7637. + System.out.println(changed + " changed objects allocated");
  7638. + }
  7639. +
  7640. + @Test
  7641. + public void testBase() {
  7642. +
  7643. + assert HotSwapTool.getCurrentVersion(FractionTest.class) == 0;
  7644. +
  7645. + final int N = 1;
  7646. + final int INC = 4;
  7647. +
  7648. + int[] benchmarking = new int[]{40000};
  7649. + int base = BASE;
  7650. + int start = 0;
  7651. +
  7652. + MicroBenchmark[] benchmarks = new MicroBenchmark[]{new GCMicroBenchmark(), new IncreaseMicroBenchmark(), new DecreaseMicroBenchmark(), new ReorderMicroBenchmark(), new NoRealChangeMicroBenchmark()};
  7653. +
  7654. + clear();
  7655. + for (int k = 0; k < N; k++) {
  7656. + for (MicroBenchmark m : benchmarks) {
  7657. + for (int i : benchmarking) {
  7658. + System.out.println(m.getClass().getName() + " with " + i + " objects");
  7659. + for (int j = start; j <= base; j += INC) {
  7660. + System.out.println(j);
  7661. + m.init(i);
  7662. + init(i, j);
  7663. + m.doit(i, measurements);
  7664. + clear();
  7665. + }
  7666. + }
  7667. + }
  7668. + }
  7669. +
  7670. + System.out.println("Results:");
  7671. + for (long l : measurements) {
  7672. + System.out.println(l);
  7673. + }
  7674. + measurements.clear();
  7675. + }
  7676. +}
  7677. +
  7678. +abstract class MicroBenchmark {
  7679. +
  7680. + public void init(int count) {
  7681. + }
  7682. +
  7683. + public abstract void doit(int count, List<Long> measurements);
  7684. +}
  7685. +
  7686. +class GCMicroBenchmark extends MicroBenchmark {
  7687. +
  7688. + public void doit(int count, List<Long> measurements) {
  7689. + long startTime = System.currentTimeMillis();
  7690. + System.gc();
  7691. + long curTime = System.currentTimeMillis() - startTime;
  7692. + measurements.add(curTime);
  7693. + }
  7694. +}
  7695. +
  7696. +class IncreaseMicroBenchmark extends MicroBenchmark {
  7697. +
  7698. + public void doit(int count, List<Long> measurements) {
  7699. + HotSwapTool.resetTimings();
  7700. + HotSwapTool.toVersion(FractionTest.class, 1);
  7701. + measurements.add(HotSwapTool.getTotalTime());
  7702. + }
  7703. +}
  7704. +
  7705. +class DecreaseMicroBenchmark extends MicroBenchmark {
  7706. +
  7707. + public void doit(int count, List<Long> measurements) {
  7708. + HotSwapTool.resetTimings();
  7709. + HotSwapTool.toVersion(FractionTest.class, 2);
  7710. + measurements.add(HotSwapTool.getTotalTime());
  7711. + }
  7712. +}
  7713. +
  7714. +class ReorderMicroBenchmark extends MicroBenchmark {
  7715. +
  7716. + public void doit(int count, List<Long> measurements) {
  7717. + HotSwapTool.resetTimings();
  7718. + HotSwapTool.toVersion(FractionTest.class, 3);
  7719. + measurements.add(HotSwapTool.getTotalTime());
  7720. + }
  7721. +}
  7722. +
  7723. +class NoRealChangeMicroBenchmark extends MicroBenchmark {
  7724. +
  7725. + public void doit(int count, List<Long> measurements) {
  7726. + HotSwapTool.resetTimings();
  7727. + HotSwapTool.toVersion(FractionTest.class, 4);
  7728. + measurements.add(HotSwapTool.getTotalTime());
  7729. + }
  7730. +}
  7731. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/AccessDeletedFieldTest.java
  7732. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  7733. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/AccessDeletedFieldTest.java Fri Dec 17 13:23:04 2010 +0100
  7734. @@ -0,0 +1,193 @@
  7735. +/*
  7736. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  7737. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  7738. + *
  7739. + * This code is free software; you can redistribute it and/or modify it
  7740. + * under the terms of the GNU General Public License version 2 only, as
  7741. + * published by the Free Software Foundation.
  7742. + *
  7743. + * This code is distributed in the hope that it will be useful, but WITHOUT
  7744. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  7745. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  7746. + * version 2 for more details (a copy is included in the LICENSE file that
  7747. + * accompanied this code).
  7748. + *
  7749. + * You should have received a copy of the GNU General Public License version
  7750. + * 2 along with this work; if not, write to the Free Software Foundation,
  7751. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  7752. + *
  7753. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  7754. + * or visit www.oracle.com if you need additional information or have any
  7755. + * questions.
  7756. + *
  7757. + */
  7758. +package at.ssw.hotswap.test.fields;
  7759. +
  7760. +import static org.junit.Assert.assertEquals;
  7761. +
  7762. +import org.junit.Before;
  7763. +import org.junit.Test;
  7764. +
  7765. +import at.ssw.hotswap.HotSwapTool;
  7766. +import at.ssw.hotswap.test.TestUtil;
  7767. +
  7768. +/**
  7769. + * Tests for accessing a deleted field. In the first scenario, the field is deleted from the class.
  7770. + * In the second scenario, it is deleted because of a changed subtype relationship.
  7771. + *
  7772. + * @author Thomas Wuerthinger
  7773. + */
  7774. +public class AccessDeletedFieldTest {
  7775. +
  7776. + @Before
  7777. + public void setUp() throws Exception {
  7778. + HotSwapTool.toVersion(AccessDeletedFieldTest.class, 0);
  7779. + }
  7780. +
  7781. + // Version 0
  7782. + public static class A {
  7783. +
  7784. + public int x;
  7785. +
  7786. + int getFieldInOldCode() {
  7787. +
  7788. + HotSwapTool.toVersion(AccessDeletedFieldTest.class, 1);
  7789. +
  7790. + // This field does no longer exist
  7791. + return x;
  7792. + }
  7793. + }
  7794. +
  7795. + public static class B extends A {
  7796. + }
  7797. +
  7798. + // Version 1
  7799. + public static class A___1 {
  7800. + }
  7801. +
  7802. + // Version 2
  7803. + public static class B___2 {
  7804. + }
  7805. +
  7806. + // Method to enforce cast (otherwise bytecodes become invalid in version 2)
  7807. + public static A convertBtoA(Object b) {
  7808. + return (A) b;
  7809. + }
  7810. +
  7811. + @Test
  7812. + public void testOldCodeAccessesDeletedField() {
  7813. +
  7814. + assert HotSwapTool.getCurrentVersion(AccessDeletedFieldTest.class) == 0;
  7815. +
  7816. + final A a = new A();
  7817. + a.x = 1;
  7818. +
  7819. + TestUtil.assertException(NoSuchFieldError.class, new Runnable() {
  7820. + @Override
  7821. + public void run() {
  7822. + assertEquals(0, a.getFieldInOldCode());
  7823. + }
  7824. + });
  7825. +
  7826. + assert HotSwapTool.getCurrentVersion(AccessDeletedFieldTest.class) == 1;
  7827. + HotSwapTool.toVersion(AccessDeletedFieldTest.class, 0);
  7828. + assertEquals(0, a.x);
  7829. + }
  7830. +
  7831. + @Test
  7832. + public void testAccessDeletedField() {
  7833. +
  7834. + assert HotSwapTool.getCurrentVersion(AccessDeletedFieldTest.class) == 0;
  7835. +
  7836. + final A a = new A();
  7837. + a.x = 1;
  7838. +
  7839. + assertEquals(1, a.x);
  7840. +
  7841. + HotSwapTool.toVersion(AccessDeletedFieldTest.class, 1);
  7842. +
  7843. + TestUtil.assertException(NoSuchFieldError.class, new Runnable() {
  7844. + @Override
  7845. + public void run() {
  7846. + System.out.println(a.x);
  7847. + }
  7848. + });
  7849. +
  7850. + HotSwapTool.toVersion(AccessDeletedFieldTest.class, 0);
  7851. + assertEquals(0, a.x);
  7852. + }
  7853. +
  7854. + @Test
  7855. + public void testAccessDeleteBaseClassFieldNormal() {
  7856. +
  7857. + HotSwapTool.toVersion(AccessDeletedFieldTest.class, 0);
  7858. + assert HotSwapTool.getCurrentVersion(AccessDeletedFieldTest.class) == 0;
  7859. + final B b = new B();
  7860. + b.x = 1;
  7861. + final A a = new A();
  7862. + a.x = 2;
  7863. +
  7864. + assertEquals(1, b.x);
  7865. + assertEquals(2, a.x);
  7866. +
  7867. + HotSwapTool.toVersion(AccessDeletedFieldTest.class, 2);
  7868. +
  7869. + TestUtil.assertException(NoSuchFieldError.class, new Runnable() {
  7870. +
  7871. + @Override
  7872. + public void run() {
  7873. + System.out.println(b.x);
  7874. + }
  7875. + });
  7876. +
  7877. + assertEquals(2, a.x);
  7878. +
  7879. + HotSwapTool.toVersion(AccessDeletedFieldTest.class, 0);
  7880. + assertEquals(0, b.x);
  7881. + }
  7882. +
  7883. + @Test
  7884. + public void testAccessDeleteBaseClassFieldInvalid() {
  7885. +
  7886. + HotSwapTool.toVersion(AccessDeletedFieldTest.class, 0);
  7887. + assert HotSwapTool.getCurrentVersion(AccessDeletedFieldTest.class) == 0;
  7888. + final B b = new B();
  7889. + final A a1 = new A();
  7890. + a1.x = 1;
  7891. + b.x = 1;
  7892. +
  7893. + HotSwapTool.toVersion(AccessDeletedFieldTest.class, 2);
  7894. +
  7895. + TestUtil.assertException(NoSuchFieldError.class, new Runnable() {
  7896. +
  7897. + @Override
  7898. + public void run() {
  7899. + System.out.println(b.x);
  7900. + }
  7901. + });
  7902. +
  7903. + assertEquals(1, a1.x);
  7904. +
  7905. + HotSwapTool.toVersion(AccessDeletedFieldTest.class, 0);
  7906. + assertEquals(0, b.x);
  7907. + assertEquals(1, a1.x);
  7908. +
  7909. + A a = convertBtoA(b);
  7910. +
  7911. + assertEquals(0, b.x);
  7912. +
  7913. + // Must fail, because now an instance of B is in a local variable of type A!
  7914. + TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {
  7915. +
  7916. + @Override
  7917. + public void run() {
  7918. + HotSwapTool.toVersion(AccessDeletedFieldTest.class, 2);
  7919. + }
  7920. + });
  7921. +
  7922. + assertEquals(0, a.x);
  7923. +
  7924. + // Still at version 0
  7925. + assert HotSwapTool.getCurrentVersion(AccessDeletedFieldTest.class) == 0;
  7926. + }
  7927. +}
  7928. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/AccessDeletedStaticFieldTest.java
  7929. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  7930. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/AccessDeletedStaticFieldTest.java Fri Dec 17 13:23:04 2010 +0100
  7931. @@ -0,0 +1,123 @@
  7932. +/*
  7933. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  7934. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  7935. + *
  7936. + * This code is free software; you can redistribute it and/or modify it
  7937. + * under the terms of the GNU General Public License version 2 only, as
  7938. + * published by the Free Software Foundation.
  7939. + *
  7940. + * This code is distributed in the hope that it will be useful, but WITHOUT
  7941. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  7942. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  7943. + * version 2 for more details (a copy is included in the LICENSE file that
  7944. + * accompanied this code).
  7945. + *
  7946. + * You should have received a copy of the GNU General Public License version
  7947. + * 2 along with this work; if not, write to the Free Software Foundation,
  7948. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  7949. + *
  7950. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  7951. + * or visit www.oracle.com if you need additional information or have any
  7952. + * questions.
  7953. + *
  7954. + */
  7955. +package at.ssw.hotswap.test.fields;
  7956. +
  7957. +import static org.junit.Assert.assertEquals;
  7958. +
  7959. +import org.junit.Before;
  7960. +import org.junit.Test;
  7961. +
  7962. +import at.ssw.hotswap.HotSwapTool;
  7963. +import at.ssw.hotswap.test.TestUtil;
  7964. +
  7965. +/**
  7966. + * Tests for accessing a deleted static field.
  7967. + *
  7968. + * @author Thomas Wuerthinger
  7969. + */
  7970. +public class AccessDeletedStaticFieldTest {
  7971. +
  7972. + @Before
  7973. + public void setUp() throws Exception {
  7974. + HotSwapTool.toVersion(AccessDeletedStaticFieldTest.class, 0);
  7975. + }
  7976. +
  7977. + // Version 0
  7978. + public static class A {
  7979. +
  7980. + public static int x;
  7981. +
  7982. + static int getFieldInOldCode() {
  7983. +
  7984. + HotSwapTool.toVersion(AccessDeletedStaticFieldTest.class, 1);
  7985. +
  7986. + newMethodFromOldCode();
  7987. +
  7988. + // This field does no longer exist
  7989. + return x;
  7990. + }
  7991. +
  7992. + static int getFieldEMCPMethod() {
  7993. + HotSwapTool.toVersion(AccessDeletedStaticFieldTest.class, 2);
  7994. + return A.x;
  7995. + }
  7996. + }
  7997. +
  7998. + // Version 1
  7999. + public static class A___1 {
  8000. + }
  8001. +
  8002. + // Version 2
  8003. +
  8004. + public static class A___2 {
  8005. +
  8006. + // EMCP to method in version 0
  8007. + static int getFieldEMCPMethod() {
  8008. + HotSwapTool.toVersion(AccessDeletedStaticFieldTest.class, 2);
  8009. + return A.x;
  8010. + }
  8011. + }
  8012. +
  8013. + private static void newMethodFromOldCode() {
  8014. + TestUtil.assertException(NoSuchFieldError.class, new Runnable() {
  8015. + @Override
  8016. + public void run() {
  8017. + System.out.println(A.x);
  8018. + }
  8019. + });
  8020. + }
  8021. +
  8022. + @Test
  8023. + public void testAccessDeletedStaticField() {
  8024. +
  8025. + assert HotSwapTool.getCurrentVersion(AccessDeletedStaticFieldTest.class) == 0;
  8026. +
  8027. + A.x = 1;
  8028. + assertEquals(1, A.getFieldInOldCode());
  8029. +
  8030. + assert HotSwapTool.getCurrentVersion(AccessDeletedStaticFieldTest.class) == 1;
  8031. + HotSwapTool.toVersion(AccessDeletedStaticFieldTest.class, 0);
  8032. + assertEquals(0, A.x);
  8033. +
  8034. + assert HotSwapTool.getCurrentVersion(AccessDeletedStaticFieldTest.class) == 0;
  8035. + }
  8036. +
  8037. +
  8038. + @Test
  8039. + public void testAccessDeletedStaticFieldFromEMCPMethod() {
  8040. +
  8041. + assert HotSwapTool.getCurrentVersion(AccessDeletedStaticFieldTest.class) == 0;
  8042. + TestUtil.assertException(NoSuchFieldError.class, new Runnable() {
  8043. + @Override
  8044. + public void run() {
  8045. + System.out.println(A.getFieldEMCPMethod());
  8046. + }
  8047. + });
  8048. +
  8049. + HotSwapTool.toVersion(AccessDeletedStaticFieldTest.class, 0);
  8050. + assertEquals(0, A.x);
  8051. +
  8052. + assert HotSwapTool.getCurrentVersion(AccessDeletedStaticFieldTest.class) == 0;
  8053. + }
  8054. +}
  8055. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/ComplexFieldTest.java
  8056. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  8057. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/ComplexFieldTest.java Fri Dec 17 13:23:04 2010 +0100
  8058. @@ -0,0 +1,103 @@
  8059. +/*
  8060. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  8061. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  8062. + *
  8063. + * This code is free software; you can redistribute it and/or modify it
  8064. + * under the terms of the GNU General Public License version 2 only, as
  8065. + * published by the Free Software Foundation.
  8066. + *
  8067. + * This code is distributed in the hope that it will be useful, but WITHOUT
  8068. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8069. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  8070. + * version 2 for more details (a copy is included in the LICENSE file that
  8071. + * accompanied this code).
  8072. + *
  8073. + * You should have received a copy of the GNU General Public License version
  8074. + * 2 along with this work; if not, write to the Free Software Foundation,
  8075. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  8076. + *
  8077. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  8078. + * or visit www.oracle.com if you need additional information or have any
  8079. + * questions.
  8080. + *
  8081. + */
  8082. +
  8083. +package at.ssw.hotswap.test.fields;
  8084. +
  8085. +import static org.junit.Assert.*;
  8086. +
  8087. +import org.junit.Before;
  8088. +import org.junit.Test;
  8089. +
  8090. +import at.ssw.hotswap.HotSwapTool;
  8091. +
  8092. +/**
  8093. + * Complex field test.
  8094. + *
  8095. + * @author Thomas Wuerthinger
  8096. + */
  8097. +public class ComplexFieldTest {
  8098. +
  8099. + // Version 0
  8100. + public static class A {
  8101. + public byte byteFld = 10;
  8102. + public short shortFld = 20;
  8103. + public int intFld = 30;
  8104. + public long longFld = 40L;
  8105. + public float floatFld = 50.2F;
  8106. + public double doubleFld = 60.3D;
  8107. + public char charFld = 'b';
  8108. + public boolean booleanFld = true;
  8109. + public String stringFld = "OLD";
  8110. + }
  8111. +
  8112. + // Version 1
  8113. + public static class A___1 {
  8114. + public byte byteFld = 11;
  8115. + public short shortFld = 22;
  8116. + public int intFld = 33;
  8117. + public long longFld = 44L;
  8118. + public float floatFld = 55.5F;
  8119. + public double doubleFld = 66.6D;
  8120. + public char charFld = 'c';
  8121. + public boolean booleanFld = false;
  8122. + public String stringFld = "NEW";
  8123. +
  8124. + // completely new instance fields are below
  8125. + public int intComplNewFld = 333;
  8126. + public long longComplNewFld = 444L;
  8127. + public String stringComplNewFld = "completely new String field";
  8128. + }
  8129. +
  8130. + @Before
  8131. + public void setUp() throws Exception {
  8132. + HotSwapTool.toVersion(ComplexFieldTest.class, 0);
  8133. + }
  8134. +
  8135. + /**
  8136. + * Checks that the given object is unmodified (i.e. the values of the fields are correct)
  8137. + * @param a the object to be checked
  8138. + */
  8139. + private void assertObjectOK(A a) {
  8140. + assertEquals(10, a.byteFld);
  8141. + assertEquals(20, a.shortFld);
  8142. + assertEquals(30, a.intFld);
  8143. + assertEquals(40L, a.longFld);
  8144. + assertEquals(50.2F, a.floatFld, 0.01);
  8145. + assertEquals(60.3D, a.doubleFld, 0.01);
  8146. + assertEquals('b', a.charFld);
  8147. + assertEquals(true, a.booleanFld);
  8148. + assertEquals("OLD", a.stringFld);
  8149. + }
  8150. +
  8151. + @Test
  8152. + public void testComplexFieldChange() {
  8153. + assert HotSwapTool.getCurrentVersion(ComplexFieldTest.class) == 0;
  8154. + A a = new A();
  8155. + assertObjectOK(a);
  8156. + HotSwapTool.toVersion(ComplexFieldTest.class, 1);
  8157. + assertObjectOK(a);
  8158. + HotSwapTool.toVersion(ComplexFieldTest.class, 0);
  8159. + assertObjectOK(a);
  8160. + }
  8161. +}
  8162. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/FieldChangedOrderTest.java
  8163. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  8164. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/FieldChangedOrderTest.java Fri Dec 17 13:23:04 2010 +0100
  8165. @@ -0,0 +1,183 @@
  8166. +/*
  8167. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  8168. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  8169. + *
  8170. + * This code is free software; you can redistribute it and/or modify it
  8171. + * under the terms of the GNU General Public License version 2 only, as
  8172. + * published by the Free Software Foundation.
  8173. + *
  8174. + * This code is distributed in the hope that it will be useful, but WITHOUT
  8175. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8176. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  8177. + * version 2 for more details (a copy is included in the LICENSE file that
  8178. + * accompanied this code).
  8179. + *
  8180. + * You should have received a copy of the GNU General Public License version
  8181. + * 2 along with this work; if not, write to the Free Software Foundation,
  8182. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  8183. + *
  8184. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  8185. + * or visit www.oracle.com if you need additional information or have any
  8186. + * questions.
  8187. + *
  8188. + */
  8189. +
  8190. +package at.ssw.hotswap.test.fields;
  8191. +
  8192. +import static org.junit.Assert.*;
  8193. +
  8194. +import org.junit.Before;
  8195. +import org.junit.Test;
  8196. +
  8197. +import at.ssw.hotswap.HotSwapTool;
  8198. +
  8199. +/**
  8200. + * Test that changes the order of two int fields.
  8201. + *
  8202. + * @author Thomas Wuerthinger
  8203. + */
  8204. +public class FieldChangedOrderTest {
  8205. +
  8206. + // Version 0
  8207. + public static class A {
  8208. +
  8209. + public int value1;
  8210. + public int value2;
  8211. +
  8212. + public A() {
  8213. + value1 = 1;
  8214. + value2 = 2;
  8215. + }
  8216. +
  8217. + public int getValue1() {
  8218. + return value1;
  8219. + }
  8220. +
  8221. + public int getValue2() {
  8222. + return value2;
  8223. + }
  8224. + }
  8225. +
  8226. + public static class B {
  8227. +
  8228. + public static int getStaticValue1(A a) {
  8229. + return a.value1;
  8230. + }
  8231. +
  8232. + public static int getStaticValue2(A a) {
  8233. + return a.value2;
  8234. + }
  8235. + }
  8236. +
  8237. + // Version 1
  8238. + public static class A___1 {
  8239. +
  8240. + public int value2;
  8241. + public int value1;
  8242. +
  8243. + public int getValue1() {
  8244. + return value1;
  8245. + }
  8246. +
  8247. + public int getValue2() {
  8248. + return value2;
  8249. + }
  8250. + }
  8251. +
  8252. + public static class B___1 {
  8253. +
  8254. + public static int getStaticValue1(A a) {
  8255. + return a.value1;
  8256. + }
  8257. +
  8258. + public static int getStaticValue2(A a) {
  8259. + return a.value2;
  8260. + }
  8261. + }
  8262. +
  8263. + // Version 2
  8264. + public static class A___2 {
  8265. +
  8266. + public int tmp1;
  8267. + public int value2;
  8268. + public int tmp2;
  8269. + public int value1;
  8270. + public int tmp3;
  8271. +
  8272. + public int getValue1() {
  8273. + return value1;
  8274. + }
  8275. +
  8276. + public int getValue2() {
  8277. + return value2;
  8278. + }
  8279. + }
  8280. +
  8281. + // Version 3
  8282. + public static class A___3 {
  8283. +
  8284. + public int tmp1;
  8285. + public int value2;
  8286. +
  8287. + public int getValue1() {
  8288. + return tmp1;
  8289. + }
  8290. +
  8291. + public int getValue2() {
  8292. + return value2;
  8293. + }
  8294. + }
  8295. +
  8296. + @Before
  8297. + public void setUp() throws Exception {
  8298. + HotSwapTool.toVersion(FieldChangedOrderTest.class, 0);
  8299. + }
  8300. +
  8301. + @Test
  8302. + public void testRenameField() {
  8303. + assert HotSwapTool.getCurrentVersion(FieldChangedOrderTest.class) == 0;
  8304. + A a = new A();
  8305. + assertObjectOK(a);
  8306. + HotSwapTool.toVersion(FieldChangedOrderTest.class, 3);
  8307. + assertEquals(0, a.getValue1());
  8308. + assertEquals(2, a.getValue2());
  8309. + HotSwapTool.toVersion(FieldChangedOrderTest.class, 0);
  8310. + assertEquals(0, a.getValue1());
  8311. + assertEquals(2, a.getValue2());
  8312. + }
  8313. +
  8314. + @Test
  8315. + public void testSimpleOrderChange() {
  8316. + assert HotSwapTool.getCurrentVersion(FieldChangedOrderTest.class) == 0;
  8317. + A a = new A();
  8318. + assertObjectOK(a);
  8319. + HotSwapTool.toVersion(FieldChangedOrderTest.class, 1);
  8320. + assertObjectOK(a);
  8321. + HotSwapTool.toVersion(FieldChangedOrderTest.class, 0);
  8322. + assertObjectOK(a);
  8323. + }
  8324. +
  8325. + /**
  8326. + * Checks that the given object is unmodified (i.e. the values of the fields are correct)
  8327. + * @param a the object to be checked
  8328. + */
  8329. + private void assertObjectOK(A a) {
  8330. + assertEquals(1, a.getValue1());
  8331. + assertEquals(2, a.getValue2());
  8332. + assertEquals(1, B.getStaticValue1(a));
  8333. + assertEquals(2, B.getStaticValue2(a));
  8334. + assertEquals(1, a.value1);
  8335. + assertEquals(2, a.value2);
  8336. + }
  8337. +
  8338. + @Test
  8339. + public void testSimpleOrderChangeWithNewTempFields() {
  8340. + assert HotSwapTool.getCurrentVersion(FieldChangedOrderTest.class) == 0;
  8341. + A a = new A();
  8342. + assertObjectOK(a);
  8343. + HotSwapTool.toVersion(FieldChangedOrderTest.class, 2);
  8344. + assertObjectOK(a);
  8345. + HotSwapTool.toVersion(FieldChangedOrderTest.class, 0);
  8346. + assertObjectOK(a);
  8347. + }
  8348. +}
  8349. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/FieldModificationTest.java
  8350. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  8351. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/FieldModificationTest.java Fri Dec 17 13:23:04 2010 +0100
  8352. @@ -0,0 +1,278 @@
  8353. +/*
  8354. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  8355. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  8356. + *
  8357. + * This code is free software; you can redistribute it and/or modify it
  8358. + * under the terms of the GNU General Public License version 2 only, as
  8359. + * published by the Free Software Foundation.
  8360. + *
  8361. + * This code is distributed in the hope that it will be useful, but WITHOUT
  8362. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8363. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  8364. + * version 2 for more details (a copy is included in the LICENSE file that
  8365. + * accompanied this code).
  8366. + *
  8367. + * You should have received a copy of the GNU General Public License version
  8368. + * 2 along with this work; if not, write to the Free Software Foundation,
  8369. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  8370. + *
  8371. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  8372. + * or visit www.oracle.com if you need additional information or have any
  8373. + * questions.
  8374. + *
  8375. + */
  8376. +
  8377. +package at.ssw.hotswap.test.fields;
  8378. +
  8379. +import static org.junit.Assert.*;
  8380. +
  8381. +import org.junit.Before;
  8382. +import org.junit.Test;
  8383. +
  8384. +import at.ssw.hotswap.HotSwapTool;
  8385. +
  8386. +/**
  8387. + * @author Thomas Wuerthinger
  8388. + */
  8389. +public class FieldModificationTest {
  8390. +
  8391. + // Version 0
  8392. + public static class A {
  8393. +
  8394. + public int val0;
  8395. + public int val1;
  8396. + public int val2;
  8397. + public int val3;
  8398. + public int val4;
  8399. + public int val5;
  8400. + public int val6;
  8401. + public int val7;
  8402. +
  8403. + public void increaseAllByOne() {
  8404. + val0++;
  8405. + val1++;
  8406. + val2++;
  8407. + val3++;
  8408. + val4++;
  8409. + val5++;
  8410. + val6++;
  8411. + val7++;
  8412. + }
  8413. +
  8414. + public int sum() {
  8415. + return val0 + val1 + val2 + val3 + val4 + val5 + val6 + val7;
  8416. + }
  8417. + }
  8418. +
  8419. + // Version 1
  8420. + public static class A___1 {
  8421. +
  8422. + public int val0;
  8423. +
  8424. + public void increaseAllByOne() {
  8425. + val0++;
  8426. + }
  8427. +
  8428. + public int sum() {
  8429. + return val0;
  8430. + }
  8431. + }
  8432. +
  8433. + // Version 2
  8434. + public static class A___2 {
  8435. +
  8436. + public int val0;
  8437. + public int val1;
  8438. + public int val2;
  8439. + public int val3;
  8440. + public int val4;
  8441. + public int val5;
  8442. + public int val6;
  8443. + public int val7;
  8444. + public int val8;
  8445. + public int val9;
  8446. + public int val10;
  8447. + public int val11;
  8448. + public int val12;
  8449. + public int val13;
  8450. + public int val14;
  8451. + public int val15;
  8452. +
  8453. + public int sum() {
  8454. + return val0 + val1 + val2 + val3 + val4 + val5 + val6 + val7 + val8 + val9 + val10 + val11 + val12 + val13 + val14 + val15;
  8455. + }
  8456. +
  8457. + public void increaseAllByOne() {
  8458. + val0++;
  8459. + val1++;
  8460. + val2++;
  8461. + val3++;
  8462. + val4++;
  8463. + val5++;
  8464. + val6++;
  8465. + val7++;
  8466. + val8++;
  8467. + val9++;
  8468. + val10++;
  8469. + val11++;
  8470. + val12++;
  8471. + val13++;
  8472. + val14++;
  8473. + val15++;
  8474. + }
  8475. + }
  8476. +
  8477. + // Version 3
  8478. + public static class A___3 {
  8479. +
  8480. + public int val6;
  8481. + public int val0;
  8482. + public int val7;
  8483. + public int val1;
  8484. + public int val2;
  8485. + public int val5;
  8486. + public int val3;
  8487. + public int val4;
  8488. + }
  8489. +
  8490. + @Before
  8491. + public void setUp() throws Exception {
  8492. + HotSwapTool.toVersion(FieldModificationTest.class, 0);
  8493. + }
  8494. +
  8495. + @Test
  8496. + public void testReorder() {
  8497. +
  8498. + A a = new A();
  8499. +
  8500. + a.val0 = 0;
  8501. + a.val1 = 1;
  8502. + a.val2 = 2;
  8503. + a.val3 = 3;
  8504. + a.val4 = 4;
  8505. + a.val5 = 5;
  8506. + a.val6 = 6;
  8507. + a.val7 = 7;
  8508. + }
  8509. +
  8510. + @Test
  8511. + public void testIncreaseFirst() {
  8512. +
  8513. + A a = new A();
  8514. +
  8515. + a.val0 = 0;
  8516. + a.val1 = 1;
  8517. + a.val2 = 2;
  8518. + a.val3 = 3;
  8519. + a.val4 = 4;
  8520. + a.val5 = 5;
  8521. + a.val6 = 6;
  8522. + a.val7 = 7;
  8523. +
  8524. + assertEquals(0, a.val0);
  8525. + assertEquals(1, a.val1);
  8526. + assertEquals(2, a.val2);
  8527. + assertEquals(3, a.val3);
  8528. + assertEquals(4, a.val4);
  8529. + assertEquals(5, a.val5);
  8530. + assertEquals(6, a.val6);
  8531. + assertEquals(7, a.val7);
  8532. + assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7, a.sum());
  8533. +
  8534. + HotSwapTool.toVersion(FieldModificationTest.class, 2);
  8535. +
  8536. + assertEquals(0, a.val0);
  8537. + assertEquals(1, a.val1);
  8538. + assertEquals(2, a.val2);
  8539. + assertEquals(3, a.val3);
  8540. + assertEquals(4, a.val4);
  8541. + assertEquals(5, a.val5);
  8542. + assertEquals(6, a.val6);
  8543. + assertEquals(7, a.val7);
  8544. + assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7, a.sum());
  8545. +
  8546. + a.increaseAllByOne();
  8547. + assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 16, a.sum());
  8548. +
  8549. + HotSwapTool.toVersion(FieldModificationTest.class, 0);
  8550. +
  8551. + assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8, a.sum());
  8552. + assertEquals(1, a.val0);
  8553. + assertEquals(2, a.val1);
  8554. + assertEquals(3, a.val2);
  8555. + assertEquals(4, a.val3);
  8556. + assertEquals(5, a.val4);
  8557. + assertEquals(6, a.val5);
  8558. + assertEquals(7, a.val6);
  8559. + assertEquals(8, a.val7);
  8560. +
  8561. + HotSwapTool.toVersion(FieldModificationTest.class, 2);
  8562. +
  8563. + assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8, a.sum());
  8564. + assertEquals(1, a.val0);
  8565. + assertEquals(2, a.val1);
  8566. + assertEquals(3, a.val2);
  8567. + assertEquals(4, a.val3);
  8568. + assertEquals(5, a.val4);
  8569. + assertEquals(6, a.val5);
  8570. + assertEquals(7, a.val6);
  8571. + assertEquals(8, a.val7);
  8572. +
  8573. + a.increaseAllByOne();
  8574. +
  8575. + assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 16, a.sum());
  8576. + assertEquals(2, a.val0);
  8577. + assertEquals(3, a.val1);
  8578. + assertEquals(4, a.val2);
  8579. + assertEquals(5, a.val3);
  8580. + assertEquals(6, a.val4);
  8581. + assertEquals(7, a.val5);
  8582. + assertEquals(8, a.val6);
  8583. + assertEquals(9, a.val7);
  8584. + HotSwapTool.toVersion(FieldModificationTest.class, 0);
  8585. +
  8586. + assertEquals(0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 16, a.sum());
  8587. + assertEquals(2, a.val0);
  8588. + assertEquals(3, a.val1);
  8589. + assertEquals(4, a.val2);
  8590. + assertEquals(5, a.val3);
  8591. + assertEquals(6, a.val4);
  8592. + assertEquals(7, a.val5);
  8593. + assertEquals(8, a.val6);
  8594. + assertEquals(9, a.val7);
  8595. + }
  8596. +
  8597. + @Test
  8598. + public void testAddRemoveField() {
  8599. +
  8600. + assert HotSwapTool.getCurrentVersion(FieldModificationTest.class) == 0;
  8601. +
  8602. + A a = new A();
  8603. +
  8604. + assertEquals(0, a.val0);
  8605. + assertEquals(0, a.val1);
  8606. +
  8607. + HotSwapTool.toVersion(FieldModificationTest.class, 1);
  8608. +
  8609. + a.val0 = 1234;
  8610. +
  8611. + HotSwapTool.toVersion(FieldModificationTest.class, 0);
  8612. +
  8613. + assertEquals(1234, a.val0);
  8614. + assertEquals(0, a.val1);
  8615. +
  8616. + a.val1 = 1234;
  8617. +
  8618. + assertEquals(1234, a.val0);
  8619. + assertEquals(1234, a.val1);
  8620. +
  8621. + HotSwapTool.toVersion(FieldModificationTest.class, 1);
  8622. +
  8623. + assertEquals(1234, a.val0);
  8624. +
  8625. + HotSwapTool.toVersion(FieldModificationTest.class, 0);
  8626. +
  8627. + assertEquals(1234, a.val0);
  8628. + assertEquals(0, a.val1);
  8629. + }
  8630. +}
  8631. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/FieldsTestSuite.java
  8632. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  8633. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/FieldsTestSuite.java Fri Dec 17 13:23:04 2010 +0100
  8634. @@ -0,0 +1,50 @@
  8635. +/*
  8636. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  8637. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  8638. + *
  8639. + * This code is free software; you can redistribute it and/or modify it
  8640. + * under the terms of the GNU General Public License version 2 only, as
  8641. + * published by the Free Software Foundation.
  8642. + *
  8643. + * This code is distributed in the hope that it will be useful, but WITHOUT
  8644. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8645. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  8646. + * version 2 for more details (a copy is included in the LICENSE file that
  8647. + * accompanied this code).
  8648. + *
  8649. + * You should have received a copy of the GNU General Public License version
  8650. + * 2 along with this work; if not, write to the Free Software Foundation,
  8651. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  8652. + *
  8653. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  8654. + * or visit www.oracle.com if you need additional information or have any
  8655. + * questions.
  8656. + *
  8657. + */
  8658. +
  8659. +package at.ssw.hotswap.test.fields;
  8660. +
  8661. +import org.junit.runner.RunWith;
  8662. +import org.junit.runners.Suite;
  8663. +
  8664. +/**
  8665. + * Class redefinition tests that may change the methods and fields of class, but do not change the superklass or the implemented
  8666. + * interface.
  8667. + *
  8668. + * @author Thomas Wuerthinger
  8669. + *
  8670. + */
  8671. +@RunWith(Suite.class)
  8672. +@Suite.SuiteClasses({
  8673. + AccessDeletedFieldTest.class,
  8674. + FieldChangedOrderTest.class,
  8675. + FieldModificationTest.class,
  8676. + ObjectStressTest.class,
  8677. + YieldTest.class,
  8678. + ComplexFieldTest.class,
  8679. + StringFieldTest.class,
  8680. + RedefinePrivateFieldTest.class,
  8681. + AccessDeletedStaticFieldTest.class
  8682. +})
  8683. +public class FieldsTestSuite {
  8684. +}
  8685. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/ObjectStressTest.java
  8686. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  8687. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/ObjectStressTest.java Fri Dec 17 13:23:04 2010 +0100
  8688. @@ -0,0 +1,122 @@
  8689. +/*
  8690. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  8691. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  8692. + *
  8693. + * This code is free software; you can redistribute it and/or modify it
  8694. + * under the terms of the GNU General Public License version 2 only, as
  8695. + * published by the Free Software Foundation.
  8696. + *
  8697. + * This code is distributed in the hope that it will be useful, but WITHOUT
  8698. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8699. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  8700. + * version 2 for more details (a copy is included in the LICENSE file that
  8701. + * accompanied this code).
  8702. + *
  8703. + * You should have received a copy of the GNU General Public License version
  8704. + * 2 along with this work; if not, write to the Free Software Foundation,
  8705. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  8706. + *
  8707. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  8708. + * or visit www.oracle.com if you need additional information or have any
  8709. + * questions.
  8710. + *
  8711. + */
  8712. +
  8713. +package at.ssw.hotswap.test.fields;
  8714. +
  8715. +import static org.junit.Assert.assertEquals;
  8716. +
  8717. +import org.junit.Before;
  8718. +import org.junit.Test;
  8719. +
  8720. +import at.ssw.hotswap.HotSwapTool;
  8721. +
  8722. +/**
  8723. + * @author Thomas Wuerthinger
  8724. + */
  8725. +public class ObjectStressTest {
  8726. +
  8727. + private final int COUNT = 10000;
  8728. +
  8729. + @Before
  8730. + public void setUp() throws Exception {
  8731. + HotSwapTool.toVersion(ObjectStressTest.class, 0);
  8732. + }
  8733. +
  8734. + // Version 0
  8735. + public static class A {
  8736. +
  8737. + public A thisPointer;
  8738. + public int i1;
  8739. + public int i2;
  8740. + public int i3;
  8741. + public int i4;
  8742. + public int i5;
  8743. + public int i6;
  8744. + public int i7;
  8745. + public int i8;
  8746. + public int i9;
  8747. + public int i10;
  8748. +
  8749. + public int sum() {
  8750. + return i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10;
  8751. + }
  8752. + }
  8753. +
  8754. + // Version 1
  8755. + public static class A___1 {
  8756. +
  8757. + public int i1;
  8758. + public int i2;
  8759. + public int i8;
  8760. + public int i3;
  8761. + public int i4;
  8762. + public int i10;
  8763. + public int i5;
  8764. + public int i6;
  8765. + public int i7;
  8766. + public int i9;
  8767. + public A thisPointer;
  8768. +
  8769. + public int sum() {
  8770. + return i1 * i2 * i3 * i4 * i5 * i6 * i7 * i8 * i9 * i10;
  8771. + }
  8772. + }
  8773. +
  8774. + @Test
  8775. + public void testLotsOfObjects() {
  8776. +
  8777. + assert HotSwapTool.getCurrentVersion(ObjectStressTest.class) == 0;
  8778. +
  8779. + A[] arr = new A[COUNT];
  8780. + for (int i = 0; i < arr.length; i++) {
  8781. + arr[i] = new A();
  8782. + arr[i].thisPointer = arr[i];
  8783. + arr[i].i1 = 1;
  8784. + arr[i].i2 = 2;
  8785. + arr[i].i3 = 3;
  8786. + arr[i].i4 = 4;
  8787. + arr[i].i5 = 5;
  8788. + arr[i].i6 = 6;
  8789. + arr[i].i7 = 7;
  8790. + arr[i].i8 = 8;
  8791. + arr[i].i9 = 9;
  8792. + arr[i].i10 = 10;
  8793. + }
  8794. +
  8795. +
  8796. + HotSwapTool.toVersion(ObjectStressTest.class, 1);
  8797. +
  8798. + for (int i = 0; i < arr.length; i++) {
  8799. + assertEquals(1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10, arr[i].sum());
  8800. + assertEquals(arr[i].thisPointer, arr[i]);
  8801. + }
  8802. +
  8803. + HotSwapTool.toVersion(ObjectStressTest.class, 0);
  8804. +
  8805. + for (int i = 0; i < arr.length; i++) {
  8806. + assertEquals(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, arr[i].sum());
  8807. + assertEquals(arr[i].thisPointer, arr[i]);
  8808. + }
  8809. + }
  8810. +}
  8811. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/RedefinePrivateFieldTest.java
  8812. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  8813. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/RedefinePrivateFieldTest.java Fri Dec 17 13:23:04 2010 +0100
  8814. @@ -0,0 +1,97 @@
  8815. +/*
  8816. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  8817. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  8818. + *
  8819. + * This code is free software; you can redistribute it and/or modify it
  8820. + * under the terms of the GNU General Public License version 2 only, as
  8821. + * published by the Free Software Foundation.
  8822. + *
  8823. + * This code is distributed in the hope that it will be useful, but WITHOUT
  8824. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8825. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  8826. + * version 2 for more details (a copy is included in the LICENSE file that
  8827. + * accompanied this code).
  8828. + *
  8829. + * You should have received a copy of the GNU General Public License version
  8830. + * 2 along with this work; if not, write to the Free Software Foundation,
  8831. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  8832. + *
  8833. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  8834. + * or visit www.oracle.com if you need additional information or have any
  8835. + * questions.
  8836. + *
  8837. + */
  8838. +
  8839. +package at.ssw.hotswap.test.fields;
  8840. +
  8841. +import static org.junit.Assert.*;
  8842. +
  8843. +import org.junit.Before;
  8844. +import org.junit.Test;
  8845. +
  8846. +import at.ssw.hotswap.HotSwapTool;
  8847. +
  8848. +/**
  8849. + * Tests redefinition of a class such that old code still accesses a redefined private field.
  8850. + *
  8851. + * @author Thomas Wuerthinger
  8852. + */
  8853. +public class RedefinePrivateFieldTest {
  8854. +
  8855. + // Version 0
  8856. + public static class A {
  8857. +
  8858. + private int f1;
  8859. +
  8860. + public A() {
  8861. + f1 = 5;
  8862. + }
  8863. +
  8864. + public int foo() {
  8865. + int result = f1;
  8866. + HotSwapTool.toVersion(RedefinePrivateFieldTest.class, 1);
  8867. + result += f1;
  8868. + return result;
  8869. + }
  8870. + }
  8871. +
  8872. + // Version 1
  8873. + public static class A___1 {
  8874. +
  8875. + int f0;
  8876. + int f1;
  8877. +
  8878. + public int foo() {
  8879. + return -1;
  8880. + }
  8881. + }
  8882. +
  8883. + @Before
  8884. + public void setUp() throws Exception {
  8885. + HotSwapTool.toVersion(RedefinePrivateFieldTest.class, 0);
  8886. + }
  8887. +
  8888. + @Test
  8889. + public void testRedefinePrivateField() {
  8890. +
  8891. + assert HotSwapTool.getCurrentVersion(RedefinePrivateFieldTest.class) == 0;
  8892. +
  8893. + A a = new A();
  8894. +
  8895. + assertEquals(10, a.foo());
  8896. +
  8897. + assert HotSwapTool.getCurrentVersion(RedefinePrivateFieldTest.class) == 1;
  8898. +
  8899. + assertEquals(-1, a.foo());
  8900. +
  8901. + HotSwapTool.toVersion(RedefinePrivateFieldTest.class, 0);
  8902. +
  8903. + assertEquals(10, a.foo());
  8904. +
  8905. + assert HotSwapTool.getCurrentVersion(RedefinePrivateFieldTest.class) == 1;
  8906. +
  8907. + assertEquals(-1, a.foo());
  8908. +
  8909. + HotSwapTool.toVersion(RedefinePrivateFieldTest.class, 0);
  8910. + }
  8911. +}
  8912. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/StringFieldTest.java
  8913. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  8914. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/StringFieldTest.java Fri Dec 17 13:23:04 2010 +0100
  8915. @@ -0,0 +1,77 @@
  8916. +/*
  8917. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  8918. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  8919. + *
  8920. + * This code is free software; you can redistribute it and/or modify it
  8921. + * under the terms of the GNU General Public License version 2 only, as
  8922. + * published by the Free Software Foundation.
  8923. + *
  8924. + * This code is distributed in the hope that it will be useful, but WITHOUT
  8925. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8926. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  8927. + * version 2 for more details (a copy is included in the LICENSE file that
  8928. + * accompanied this code).
  8929. + *
  8930. + * You should have received a copy of the GNU General Public License version
  8931. + * 2 along with this work; if not, write to the Free Software Foundation,
  8932. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  8933. + *
  8934. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  8935. + * or visit www.oracle.com if you need additional information or have any
  8936. + * questions.
  8937. + *
  8938. + */
  8939. +
  8940. +package at.ssw.hotswap.test.fields;
  8941. +
  8942. +import static org.junit.Assert.*;
  8943. +
  8944. +import org.junit.Before;
  8945. +import org.junit.Test;
  8946. +
  8947. +import at.ssw.hotswap.HotSwapTool;
  8948. +
  8949. +/**
  8950. + * Complex field test.
  8951. + *
  8952. + * @author Thomas Wuerthinger
  8953. + */
  8954. +public class StringFieldTest {
  8955. +
  8956. + // Version 0
  8957. + public static class A {
  8958. + public String stringFld = "OLD";
  8959. + }
  8960. +
  8961. + // Version 1
  8962. + public static class A___1 {
  8963. + public String stringFld = "NEW";
  8964. + public int intComplNewFld = 333;
  8965. + public long longComplNewFld = 444L;
  8966. + public String stringComplNewFld = "completely new String field";
  8967. + }
  8968. +
  8969. + @Before
  8970. + public void setUp() throws Exception {
  8971. + HotSwapTool.toVersion(StringFieldTest.class, 0);
  8972. + }
  8973. +
  8974. + /**
  8975. + * Checks that the given object is unmodified (i.e. the values of the fields are correct)
  8976. + * @param a the object to be checked
  8977. + */
  8978. + private void assertObjectOK(A a) {
  8979. + assertEquals("OLD", a.stringFld);
  8980. + }
  8981. +
  8982. + @Test
  8983. + public void testComplexFieldChange() {
  8984. + assert HotSwapTool.getCurrentVersion(StringFieldTest.class) == 0;
  8985. + A a = new A();
  8986. + assertObjectOK(a);
  8987. + HotSwapTool.toVersion(StringFieldTest.class, 1);
  8988. + assertObjectOK(a);
  8989. + HotSwapTool.toVersion(StringFieldTest.class, 0);
  8990. + assertObjectOK(a);
  8991. + }
  8992. +}
  8993. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/YieldTest.java
  8994. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  8995. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/fields/YieldTest.java Fri Dec 17 13:23:04 2010 +0100
  8996. @@ -0,0 +1,120 @@
  8997. +/*
  8998. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  8999. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  9000. + *
  9001. + * This code is free software; you can redistribute it and/or modify it
  9002. + * under the terms of the GNU General Public License version 2 only, as
  9003. + * published by the Free Software Foundation.
  9004. + *
  9005. + * This code is distributed in the hope that it will be useful, but WITHOUT
  9006. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9007. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  9008. + * version 2 for more details (a copy is included in the LICENSE file that
  9009. + * accompanied this code).
  9010. + *
  9011. + * You should have received a copy of the GNU General Public License version
  9012. + * 2 along with this work; if not, write to the Free Software Foundation,
  9013. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  9014. + *
  9015. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  9016. + * or visit www.oracle.com if you need additional information or have any
  9017. + * questions.
  9018. + *
  9019. + */
  9020. +
  9021. +package at.ssw.hotswap.test.fields;
  9022. +
  9023. +import static org.junit.Assert.*;
  9024. +
  9025. +import org.junit.Before;
  9026. +
  9027. +import java.util.Arrays;
  9028. +import java.util.List;
  9029. +import java.util.ArrayList;
  9030. +import org.junit.Test;
  9031. +
  9032. +import at.ssw.hotswap.HotSwapTool;
  9033. +
  9034. +/**
  9035. + * Test case that produces a list of integer values recursively.
  9036. + * The recursive function does not contain a conditional statement.
  9037. + * The recursion is stopped by swapping the recursive method with a different non-recursive implementation.
  9038. + *
  9039. + * @author Thomas Wuerthinger
  9040. + */
  9041. +public class YieldTest {
  9042. +
  9043. + // Version 0
  9044. + public static class Base {
  9045. +
  9046. + protected List<Integer> arr = new ArrayList<Integer>();
  9047. +
  9048. + public void reset() {
  9049. + HotSwapTool.toVersion(YieldTest.class, 0);
  9050. + }
  9051. +
  9052. + public void next() {
  9053. + HotSwapTool.toVersion(YieldTest.class, HotSwapTool.getCurrentVersion(YieldTest.class) + 1);
  9054. + }
  9055. + }
  9056. +
  9057. + public static abstract class A extends Base {
  9058. +
  9059. + public List<Integer> gen() {
  9060. + arr.add(produce());
  9061. + next();
  9062. + return gen();
  9063. + }
  9064. +
  9065. + public abstract int produce();
  9066. + }
  9067. +
  9068. + public static class B extends A {
  9069. +
  9070. + public int produce() {
  9071. + return 1;
  9072. + }
  9073. + }
  9074. +
  9075. + public static class B___10 extends A {
  9076. +
  9077. + public int produce() {
  9078. + return 2;
  9079. + }
  9080. + }
  9081. +
  9082. + public static class B___20 extends A {
  9083. +
  9084. + private int x;
  9085. +
  9086. + public int produce() {
  9087. + return ++x;
  9088. + }
  9089. + }
  9090. +
  9091. + public static class A___30 extends Base {
  9092. +
  9093. + public List<Integer> gen() {
  9094. + reset();
  9095. + return arr;
  9096. + }
  9097. + }
  9098. +
  9099. + @Before
  9100. + public void setUp() throws Exception {
  9101. + HotSwapTool.toVersion(YieldTest.class, 0);
  9102. + }
  9103. +
  9104. + @Test
  9105. + public void testYield() {
  9106. +
  9107. + assert HotSwapTool.getCurrentVersion(YieldTest.class) == 0;
  9108. +
  9109. + B b = new B();
  9110. + assertEquals(Arrays.asList(
  9111. + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  9112. + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  9113. + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), b.gen());
  9114. + assert HotSwapTool.getCurrentVersion(YieldTest.class) == 0;
  9115. + }
  9116. +}
  9117. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/AddMethodTest.java
  9118. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  9119. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/AddMethodTest.java Fri Dec 17 13:23:04 2010 +0100
  9120. @@ -0,0 +1,168 @@
  9121. +/*
  9122. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  9123. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  9124. + *
  9125. + * This code is free software; you can redistribute it and/or modify it
  9126. + * under the terms of the GNU General Public License version 2 only, as
  9127. + * published by the Free Software Foundation.
  9128. + *
  9129. + * This code is distributed in the hope that it will be useful, but WITHOUT
  9130. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9131. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  9132. + * version 2 for more details (a copy is included in the LICENSE file that
  9133. + * accompanied this code).
  9134. + *
  9135. + * You should have received a copy of the GNU General Public License version
  9136. + * 2 along with this work; if not, write to the Free Software Foundation,
  9137. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  9138. + *
  9139. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  9140. + * or visit www.oracle.com if you need additional information or have any
  9141. + * questions.
  9142. + *
  9143. + */
  9144. +package at.ssw.hotswap.test.methods;
  9145. +
  9146. +import static org.junit.Assert.*;
  9147. +
  9148. +import org.junit.Before;
  9149. +import org.junit.Test;
  9150. +
  9151. +import at.ssw.hotswap.HotSwapTool;
  9152. +import at.ssw.hotswap.test.TestUtil;
  9153. +
  9154. +/**
  9155. + * Tests for adding / removing methods in a single class.
  9156. + *
  9157. + * @author Thomas Wuerthinger
  9158. + */
  9159. +public class AddMethodTest {
  9160. +
  9161. + // Version 0
  9162. + public static class A {
  9163. + public int value(int newVersion) {
  9164. + return newVersion;
  9165. + }
  9166. + }
  9167. +
  9168. + // Version 1
  9169. + public static class A___1 {
  9170. +
  9171. + public int value(int newVersion) {
  9172. +
  9173. + int x = 1;
  9174. + try {
  9175. + x = 2;
  9176. + } catch (NumberFormatException e) {
  9177. + x = 3;
  9178. + } catch (Exception e) {
  9179. + x = 4;
  9180. + } finally {
  9181. + x = x * 2;
  9182. + }
  9183. + HotSwapTool.toVersion(AddMethodTest.class, newVersion);
  9184. + throw new IllegalArgumentException();
  9185. + }
  9186. + }
  9187. +
  9188. + // Version 2
  9189. + public static class A___2 {
  9190. +
  9191. + public int value2() {
  9192. + return 2;
  9193. + }
  9194. +
  9195. + public int value(int newVersion) {
  9196. +
  9197. + int x = 1;
  9198. + try {
  9199. + x = 2;
  9200. + } catch (NumberFormatException e) {
  9201. + x = 3;
  9202. + } catch (Exception e) {
  9203. + x = 4;
  9204. + } finally {
  9205. + x = x * 2;
  9206. + }
  9207. + HotSwapTool.toVersion(AddMethodTest.class, newVersion);
  9208. + throw new IllegalArgumentException();
  9209. + }
  9210. +
  9211. + public int value3() {
  9212. + return 3;
  9213. + }
  9214. +
  9215. + public int value4() {
  9216. + return 4;
  9217. + }
  9218. +
  9219. + public int value5() {
  9220. + return 5;
  9221. + }
  9222. + }
  9223. +
  9224. + @Before
  9225. + public void setUp() throws Exception {
  9226. + HotSwapTool.toVersion(AddMethodTest.class, 0);
  9227. + }
  9228. +
  9229. + @Test
  9230. + public void testAddMethodToKlassWithEMCPExceptionMethod() {
  9231. +
  9232. + assert HotSwapTool.getCurrentVersion(AddMethodTest.class) == 0;
  9233. +
  9234. + final A a = new A();
  9235. +
  9236. + assertEquals(1, a.value(1));
  9237. +
  9238. + HotSwapTool.toVersion(AddMethodTest.class, 1);
  9239. +
  9240. + int firstLineNumber = TestUtil.assertException(IllegalArgumentException.class, new Runnable() {
  9241. + @Override
  9242. + public void run() {
  9243. + assertEquals(4, a.value(1));
  9244. + }
  9245. + });
  9246. +
  9247. + int secondLineNumber = TestUtil.assertException(IllegalArgumentException.class, new Runnable() {
  9248. + @Override
  9249. + public void run() {
  9250. + assertEquals(4, a.value(2));
  9251. + }
  9252. + });
  9253. +
  9254. + System.out.println("Exception line numbers: " + firstLineNumber + " and " + secondLineNumber);
  9255. +
  9256. + assertTrue("Must have different line numbers (A.value is an EMCP method and therefore execution has to be transferred)", firstLineNumber != secondLineNumber);
  9257. +
  9258. + assert HotSwapTool.getCurrentVersion(AddMethodTest.class) == 2;
  9259. +
  9260. + int newFirstLineNumber = TestUtil.assertException(IllegalArgumentException.class, new Runnable() {
  9261. + @Override
  9262. + public void run() {
  9263. + assertEquals(4, a.value(2));
  9264. + }
  9265. + });
  9266. +
  9267. + assertEquals(secondLineNumber, newFirstLineNumber);
  9268. +
  9269. + int newSecondLineNumber = TestUtil.assertException(IllegalArgumentException.class, new Runnable() {
  9270. + @Override
  9271. + public void run() {
  9272. + assertEquals(4, a.value(1));
  9273. + }
  9274. + });
  9275. +
  9276. + assertEquals(newSecondLineNumber, firstLineNumber);
  9277. +
  9278. + assertTrue("Must have different line numbers (A.value is an EMCP method and therefore execution has to be transferred)", firstLineNumber != secondLineNumber);
  9279. +
  9280. + HotSwapTool.toVersion(AddMethodTest.class, 0);
  9281. +
  9282. + assertEquals(1, a.value(1));
  9283. +
  9284. + assert HotSwapTool.getCurrentVersion(AddMethodTest.class) == 0;
  9285. +
  9286. +
  9287. + }
  9288. +}
  9289. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/CallDeletedInterfaceMethodTest.java
  9290. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  9291. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/CallDeletedInterfaceMethodTest.java Fri Dec 17 13:23:04 2010 +0100
  9292. @@ -0,0 +1,95 @@
  9293. +/*
  9294. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  9295. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  9296. + *
  9297. + * This code is free software; you can redistribute it and/or modify it
  9298. + * under the terms of the GNU General Public License version 2 only, as
  9299. + * published by the Free Software Foundation.
  9300. + *
  9301. + * This code is distributed in the hope that it will be useful, but WITHOUT
  9302. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9303. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  9304. + * version 2 for more details (a copy is included in the LICENSE file that
  9305. + * accompanied this code).
  9306. + *
  9307. + * You should have received a copy of the GNU General Public License version
  9308. + * 2 along with this work; if not, write to the Free Software Foundation,
  9309. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  9310. + *
  9311. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  9312. + * or visit www.oracle.com if you need additional information or have any
  9313. + * questions.
  9314. + *
  9315. + */
  9316. +
  9317. +package at.ssw.hotswap.test.methods;
  9318. +
  9319. +import static org.junit.Assert.assertEquals;
  9320. +import junit.framework.Assert;
  9321. +
  9322. +import org.junit.Before;
  9323. +import org.junit.Test;
  9324. +
  9325. +import at.ssw.hotswap.HotSwapTool;
  9326. +
  9327. +/**
  9328. + * Test case that calls an interface method that was deleted through class redefinition.
  9329. + *
  9330. + * @author Thomas Wuerthinger
  9331. + */
  9332. +public class CallDeletedInterfaceMethodTest {
  9333. +
  9334. + @Before
  9335. + public void setUp() throws Exception {
  9336. + HotSwapTool.toVersion(CallDeletedInterfaceMethodTest.class, 0);
  9337. + }
  9338. +
  9339. + // Version 0
  9340. + public static interface I {
  9341. + public int foo();
  9342. + }
  9343. +
  9344. + public static class A implements I {
  9345. + @Override
  9346. + public int foo() {
  9347. + return 1;
  9348. + }
  9349. + }
  9350. +
  9351. + public static class Helper {
  9352. + public static int process(I i) {
  9353. + HotSwapTool.toVersion(CallDeletedInterfaceMethodTest.class, 1);
  9354. + return i.foo();
  9355. + }
  9356. + }
  9357. +
  9358. + // Version 1
  9359. + public static interface I___1 {
  9360. +
  9361. + }
  9362. +
  9363. + public static class Helper___1 {
  9364. + public static int process(I i) {
  9365. + return 2;
  9366. + }
  9367. + }
  9368. +
  9369. + @Test
  9370. + public void testOldCodeCallsDeletedInterfaceMethod() {
  9371. +
  9372. + assert HotSwapTool.getCurrentVersion(CallDeletedInterfaceMethodTest.class) == 0;
  9373. + A a = new A();
  9374. +
  9375. + assertEquals(1, Helper.process(a));
  9376. + assert HotSwapTool.getCurrentVersion(CallDeletedInterfaceMethodTest.class) == 1;
  9377. + assertEquals(2, Helper.process(a));
  9378. +
  9379. + HotSwapTool.toVersion(CallDeletedInterfaceMethodTest.class, 0);
  9380. +
  9381. + assertEquals(1, Helper.process(a));
  9382. + assert HotSwapTool.getCurrentVersion(CallDeletedInterfaceMethodTest.class) == 1;
  9383. + assertEquals(2, Helper.process(a));
  9384. +
  9385. + HotSwapTool.toVersion(CallDeletedInterfaceMethodTest.class, 0);
  9386. + }
  9387. +}
  9388. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/CallDeletedMethodTest.java
  9389. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  9390. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/CallDeletedMethodTest.java Fri Dec 17 13:23:04 2010 +0100
  9391. @@ -0,0 +1,114 @@
  9392. +/*
  9393. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  9394. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  9395. + *
  9396. + * This code is free software; you can redistribute it and/or modify it
  9397. + * under the terms of the GNU General Public License version 2 only, as
  9398. + * published by the Free Software Foundation.
  9399. + *
  9400. + * This code is distributed in the hope that it will be useful, but WITHOUT
  9401. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9402. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  9403. + * version 2 for more details (a copy is included in the LICENSE file that
  9404. + * accompanied this code).
  9405. + *
  9406. + * You should have received a copy of the GNU General Public License version
  9407. + * 2 along with this work; if not, write to the Free Software Foundation,
  9408. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  9409. + *
  9410. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  9411. + * or visit www.oracle.com if you need additional information or have any
  9412. + * questions.
  9413. + *
  9414. + */
  9415. +
  9416. +package at.ssw.hotswap.test.methods;
  9417. +
  9418. +import at.ssw.hotswap.MethodRedefinitionPolicy;
  9419. +import static org.junit.Assert.assertEquals;
  9420. +import junit.framework.Assert;
  9421. +
  9422. +import org.junit.Before;
  9423. +import org.junit.Test;
  9424. +
  9425. +import at.ssw.hotswap.HotSwapTool;
  9426. +import at.ssw.hotswap.RedefinitionPolicy;
  9427. +
  9428. +/**
  9429. + * Test case that calls a virtual method that was deleted through class redefinition.
  9430. + *
  9431. + * @author Thomas Wuerthinger
  9432. + */
  9433. +public class CallDeletedMethodTest {
  9434. +
  9435. + @Before
  9436. + public void setUp() throws Exception {
  9437. + HotSwapTool.toVersion(CallDeletedMethodTest.class, 0);
  9438. + }
  9439. +
  9440. + // Version 0
  9441. + public static class A {
  9442. +
  9443. + public int value() {
  9444. + return 5;
  9445. + }
  9446. +
  9447. + public int oldMethod() {
  9448. + HotSwapTool.toVersion(CallDeletedMethodTest.class, 1);
  9449. + return deletedMethod();
  9450. + }
  9451. +
  9452. + public int deletedMethod() {
  9453. + return 1;
  9454. + }
  9455. + }
  9456. +
  9457. + // Version 1
  9458. + @MethodRedefinitionPolicy(RedefinitionPolicy.AccessDeletedMembers)
  9459. + public static class A___1 {
  9460. +
  9461. + public int oldMethod() {
  9462. + return 2;
  9463. + }
  9464. + }
  9465. +
  9466. + @Test
  9467. + public void testOldCodeCallsDeletedMethod() {
  9468. +
  9469. + assert HotSwapTool.getCurrentVersion(CallDeletedMethodTest.class) == 0;
  9470. + A a = new A();
  9471. +
  9472. + assertEquals(1, a.oldMethod());
  9473. + assert HotSwapTool.getCurrentVersion(CallDeletedMethodTest.class) == 1;
  9474. + assertEquals(2, a.oldMethod());
  9475. +
  9476. + HotSwapTool.toVersion(CallDeletedMethodTest.class, 0);
  9477. +
  9478. + assertEquals(1, a.oldMethod());
  9479. + assert HotSwapTool.getCurrentVersion(CallDeletedMethodTest.class) == 1;
  9480. + assertEquals(2, a.oldMethod());
  9481. +
  9482. + HotSwapTool.toVersion(CallDeletedMethodTest.class, 0);
  9483. + }
  9484. +
  9485. + @Test
  9486. + public void testNewCodeCallsDeletedMethod() {
  9487. +
  9488. + assert HotSwapTool.getCurrentVersion(CallDeletedMethodTest.class) == 0;
  9489. +
  9490. + A a = new A();
  9491. + assertEquals(5, a.value());
  9492. +
  9493. + HotSwapTool.toVersion(CallDeletedMethodTest.class, 1);
  9494. +
  9495. + try {
  9496. + a.value();
  9497. + Assert.fail("NoSuchMethodError exception must be thrown!");
  9498. + } catch (NoSuchMethodError e) {
  9499. + // Expected exception
  9500. + }
  9501. +
  9502. + HotSwapTool.toVersion(CallDeletedMethodTest.class, 0);
  9503. + assertEquals(5, a.value());
  9504. + }
  9505. +}
  9506. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/DeleteActiveMethodTest.java
  9507. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  9508. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/DeleteActiveMethodTest.java Fri Dec 17 13:23:04 2010 +0100
  9509. @@ -0,0 +1,166 @@
  9510. +/*
  9511. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  9512. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  9513. + *
  9514. + * This code is free software; you can redistribute it and/or modify it
  9515. + * under the terms of the GNU General Public License version 2 only, as
  9516. + * published by the Free Software Foundation.
  9517. + *
  9518. + * This code is distributed in the hope that it will be useful, but WITHOUT
  9519. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9520. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  9521. + * version 2 for more details (a copy is included in the LICENSE file that
  9522. + * accompanied this code).
  9523. + *
  9524. + * You should have received a copy of the GNU General Public License version
  9525. + * 2 along with this work; if not, write to the Free Software Foundation,
  9526. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  9527. + *
  9528. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  9529. + * or visit www.oracle.com if you need additional information or have any
  9530. + * questions.
  9531. + *
  9532. + */
  9533. +
  9534. +package at.ssw.hotswap.test.methods;
  9535. +
  9536. +import at.ssw.hotswap.MethodRedefinitionPolicy;
  9537. +import static org.junit.Assert.assertEquals;
  9538. +import junit.framework.Assert;
  9539. +
  9540. +import org.junit.Before;
  9541. +import org.junit.Test;
  9542. +
  9543. +import at.ssw.hotswap.HotSwapTool;
  9544. +import at.ssw.hotswap.RedefinitionPolicy;
  9545. +import at.ssw.hotswap.test.TestUtil;
  9546. +
  9547. +/**
  9548. + * Test cases that delete a method that is currently active on the stack.
  9549. + *
  9550. + * @author Thomas Wuerthinger
  9551. + */
  9552. +public class DeleteActiveMethodTest {
  9553. +
  9554. + @Before
  9555. + public void setUp() throws Exception {
  9556. + HotSwapTool.toVersion(DeleteActiveMethodTest.class, 0);
  9557. + }
  9558. +
  9559. + // Version 0
  9560. + public static class A {
  9561. +
  9562. + boolean firstCall;
  9563. +
  9564. + public int value() {
  9565. + firstCall = true;
  9566. + return helperValue();
  9567. + }
  9568. +
  9569. + public int helperValue() {
  9570. +
  9571. + if (!firstCall) {
  9572. + return -1;
  9573. + }
  9574. + firstCall = false;
  9575. +
  9576. + Thread t = new Thread(new Runnable() {
  9577. +
  9578. + @Override
  9579. + public void run() {
  9580. + HotSwapTool.toVersion(DeleteActiveMethodTest.class, 1);
  9581. + }
  9582. + });
  9583. + t.start();
  9584. +
  9585. + try {
  9586. + while (t.isAlive()) {
  9587. + try {
  9588. + this.helperValue();
  9589. + Thread.sleep(10);
  9590. + } catch (InterruptedException e) {
  9591. + }
  9592. + }
  9593. + Assert.fail("Exception expected!");
  9594. + } catch (NoSuchMethodError e) {
  9595. + }
  9596. +
  9597. + try {
  9598. + t.join();
  9599. + } catch (InterruptedException e) {
  9600. + }
  9601. +
  9602. + return 1;
  9603. + }
  9604. + }
  9605. +
  9606. + public static class B {
  9607. +
  9608. + public int fac(int x) {
  9609. + if (x == 0) {
  9610. + HotSwapTool.toVersion(DeleteActiveMethodTest.class, 1);
  9611. + }
  9612. +
  9613. + return x * fac(x - 1);
  9614. + }
  9615. + }
  9616. +
  9617. + // Version 1
  9618. + @MethodRedefinitionPolicy(RedefinitionPolicy.DynamicCheck)
  9619. + public static class A___1 {
  9620. +
  9621. + boolean firstCall;
  9622. +
  9623. + public int value() {
  9624. + HotSwapTool.toVersion(DeleteActiveMethodTest.class, 0);
  9625. + return 2;
  9626. + }
  9627. + }
  9628. +
  9629. + @MethodRedefinitionPolicy(RedefinitionPolicy.DynamicCheck)
  9630. + public static class B___1 {
  9631. + }
  9632. +
  9633. + @Test
  9634. + public void testDeleteActiveMethodSimple() {
  9635. + assert HotSwapTool.getCurrentVersion(DeleteActiveMethodTest.class) == 0;
  9636. +
  9637. + final B b = new B();
  9638. + TestUtil.assertException(NoSuchMethodError.class, new Runnable() {
  9639. + @Override
  9640. + public void run() {
  9641. + b.fac(5);
  9642. + }
  9643. + });
  9644. +
  9645. + assert HotSwapTool.getCurrentVersion(DeleteActiveMethodTest.class) == 1;
  9646. +
  9647. + HotSwapTool.toVersion(DeleteActiveMethodTest.class, 0);
  9648. + assert HotSwapTool.getCurrentVersion(DeleteActiveMethodTest.class) == 0;
  9649. + }
  9650. +
  9651. + @Test
  9652. + public void testDeleteActiveMethod() {
  9653. + assert HotSwapTool.getCurrentVersion(DeleteActiveMethodTest.class) == 0;
  9654. +
  9655. + A a = new A();
  9656. +
  9657. + assertEquals(1, a.value());
  9658. + assert HotSwapTool.getCurrentVersion(DeleteActiveMethodTest.class) == 1;
  9659. +
  9660. + assertEquals(2, a.value());
  9661. + assert HotSwapTool.getCurrentVersion(DeleteActiveMethodTest.class) == 0;
  9662. +
  9663. + assertEquals(1, a.value());
  9664. + assert HotSwapTool.getCurrentVersion(DeleteActiveMethodTest.class) == 1;
  9665. +
  9666. + assertEquals(2, a.value());
  9667. + assert HotSwapTool.getCurrentVersion(DeleteActiveMethodTest.class) == 0;
  9668. +
  9669. + assertEquals(1, a.value());
  9670. + assert HotSwapTool.getCurrentVersion(DeleteActiveMethodTest.class) == 1;
  9671. +
  9672. + assertEquals(2, a.value());
  9673. + assert HotSwapTool.getCurrentVersion(DeleteActiveMethodTest.class) == 0;
  9674. + }
  9675. +}
  9676. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/MethodsTestSuite.java
  9677. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  9678. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/MethodsTestSuite.java Fri Dec 17 13:23:04 2010 +0100
  9679. @@ -0,0 +1,49 @@
  9680. +/*
  9681. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  9682. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  9683. + *
  9684. + * This code is free software; you can redistribute it and/or modify it
  9685. + * under the terms of the GNU General Public License version 2 only, as
  9686. + * published by the Free Software Foundation.
  9687. + *
  9688. + * This code is distributed in the hope that it will be useful, but WITHOUT
  9689. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9690. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  9691. + * version 2 for more details (a copy is included in the LICENSE file that
  9692. + * accompanied this code).
  9693. + *
  9694. + * You should have received a copy of the GNU General Public License version
  9695. + * 2 along with this work; if not, write to the Free Software Foundation,
  9696. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  9697. + *
  9698. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  9699. + * or visit www.oracle.com if you need additional information or have any
  9700. + * questions.
  9701. + *
  9702. + */
  9703. +
  9704. +package at.ssw.hotswap.test.methods;
  9705. +
  9706. +import org.junit.runner.RunWith;
  9707. +import org.junit.runners.Suite;
  9708. +
  9709. +/**
  9710. + * Class redefinition tests that perform adding/removing/changing the methods of a class.
  9711. + *
  9712. + * @author Thomas Wuerthinger
  9713. + *
  9714. + */
  9715. +@RunWith(Suite.class)
  9716. +@Suite.SuiteClasses({
  9717. + AddMethodTest.class,
  9718. + CallDeletedMethodTest.class,
  9719. + DeleteActiveMethodTest.class,
  9720. + ReflectionTest.class,
  9721. + OverrideMethodTest.class,
  9722. + SingleClassTest.class,
  9723. + SingleClassReflectionTest.class,
  9724. + OldCodeNonOSRTest.class,
  9725. + CallDeletedInterfaceMethodTest.class
  9726. +})
  9727. +public class MethodsTestSuite {
  9728. +}
  9729. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/OldCodeNonOSRTest.java
  9730. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  9731. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/OldCodeNonOSRTest.java Fri Dec 17 13:23:04 2010 +0100
  9732. @@ -0,0 +1,123 @@
  9733. +/*
  9734. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  9735. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  9736. + *
  9737. + * This code is free software; you can redistribute it and/or modify it
  9738. + * under the terms of the GNU General Public License version 2 only, as
  9739. + * published by the Free Software Foundation.
  9740. + *
  9741. + * This code is distributed in the hope that it will be useful, but WITHOUT
  9742. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9743. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  9744. + * version 2 for more details (a copy is included in the LICENSE file that
  9745. + * accompanied this code).
  9746. + *
  9747. + * You should have received a copy of the GNU General Public License version
  9748. + * 2 along with this work; if not, write to the Free Software Foundation,
  9749. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  9750. + *
  9751. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  9752. + * or visit www.oracle.com if you need additional information or have any
  9753. + * questions.
  9754. + *
  9755. + */
  9756. +
  9757. +package at.ssw.hotswap.test.methods;
  9758. +
  9759. +import static org.junit.Assert.assertEquals;
  9760. +
  9761. +import org.junit.Before;
  9762. +import org.junit.Test;
  9763. +
  9764. +import at.ssw.hotswap.HotSwapTool;
  9765. +
  9766. +/**
  9767. + * Test case that makes sure that old code does not get on-stack-replaced.
  9768. + *
  9769. + * @author Thomas Wuerthinger
  9770. + */
  9771. +public class OldCodeNonOSRTest {
  9772. +
  9773. + // Chose high enough to make sure method could get OSR (usually the OSR flag in the VM is set to about 15000)
  9774. + private static final int N = 100000;
  9775. +
  9776. + @Before
  9777. + public void setUp() throws Exception {
  9778. + HotSwapTool.toVersion(OldCodeNonOSRTest.class, 0);
  9779. + }
  9780. +
  9781. + // Version 0
  9782. + public static class A {
  9783. +
  9784. + public int value() {
  9785. + return 5;
  9786. + }
  9787. +
  9788. + public int oldMethod() {
  9789. + HotSwapTool.toVersion(OldCodeNonOSRTest.class, 1);
  9790. + int sum = 0;
  9791. + for (int i=0; i<N; i++) {
  9792. + sum += i;
  9793. + }
  9794. + return (sum & deletedMethod()) | 1;
  9795. + }
  9796. +
  9797. + public int oldMethod2() {
  9798. + int sum = 0;
  9799. + for (int i=0; i<N; i++) {
  9800. + sum += i;
  9801. + }
  9802. + HotSwapTool.toVersion(OldCodeNonOSRTest.class, 1);
  9803. + return (sum & deletedMethod()) | 1;
  9804. + }
  9805. +
  9806. + public int oldMethod3() {
  9807. + int sum = 0;
  9808. + for (int i=0; i<N; i++) {
  9809. + sum += i;
  9810. + }
  9811. + HotSwapTool.toVersion(OldCodeNonOSRTest.class, 1);
  9812. + for (int i=0; i<N; i++) {
  9813. + sum += i;
  9814. + }
  9815. + return (sum & deletedMethod()) | 1;
  9816. + }
  9817. +
  9818. + public int deletedMethod() {
  9819. + return 1;
  9820. + }
  9821. + }
  9822. +
  9823. + // Version 1
  9824. + public static class A___1 {
  9825. +
  9826. + public int oldMethod() {
  9827. + return 2;
  9828. + }
  9829. + }
  9830. +
  9831. + @Test
  9832. + public void testOldCodeNonOSR() {
  9833. +
  9834. + assert HotSwapTool.getCurrentVersion(OldCodeNonOSRTest.class) == 0;
  9835. + A a = new A();
  9836. +
  9837. + assertEquals(1, a.oldMethod());
  9838. + assert HotSwapTool.getCurrentVersion(OldCodeNonOSRTest.class) == 1;
  9839. + assertEquals(2, a.oldMethod());
  9840. +
  9841. + HotSwapTool.toVersion(OldCodeNonOSRTest.class, 0);
  9842. +
  9843. + assertEquals(1, a.oldMethod2());
  9844. + assert HotSwapTool.getCurrentVersion(OldCodeNonOSRTest.class) == 1;
  9845. + assertEquals(2, a.oldMethod());
  9846. +
  9847. + HotSwapTool.toVersion(OldCodeNonOSRTest.class, 0);
  9848. +
  9849. + assertEquals(1, a.oldMethod3());
  9850. + assert HotSwapTool.getCurrentVersion(OldCodeNonOSRTest.class) == 1;
  9851. + assertEquals(2, a.oldMethod());
  9852. +
  9853. + HotSwapTool.toVersion(OldCodeNonOSRTest.class, 0);
  9854. + }
  9855. +}
  9856. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/OverrideMethodTest.java
  9857. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  9858. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/OverrideMethodTest.java Fri Dec 17 13:23:04 2010 +0100
  9859. @@ -0,0 +1,247 @@
  9860. +/*
  9861. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  9862. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  9863. + *
  9864. + * This code is free software; you can redistribute it and/or modify it
  9865. + * under the terms of the GNU General Public License version 2 only, as
  9866. + * published by the Free Software Foundation.
  9867. + *
  9868. + * This code is distributed in the hope that it will be useful, but WITHOUT
  9869. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9870. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  9871. + * version 2 for more details (a copy is included in the LICENSE file that
  9872. + * accompanied this code).
  9873. + *
  9874. + * You should have received a copy of the GNU General Public License version
  9875. + * 2 along with this work; if not, write to the Free Software Foundation,
  9876. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  9877. + *
  9878. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  9879. + * or visit www.oracle.com if you need additional information or have any
  9880. + * questions.
  9881. + *
  9882. + */
  9883. +
  9884. +package at.ssw.hotswap.test.methods;
  9885. +
  9886. +import static org.junit.Assert.assertEquals;
  9887. +
  9888. +import org.junit.Before;
  9889. +import org.junit.Test;
  9890. +
  9891. +import at.ssw.hotswap.HotSwapTool;
  9892. +
  9893. +/**
  9894. + * Tests for the class relationship A<B<C with adding / removing methods.
  9895. + *
  9896. + * @author Thomas Wuerthinger
  9897. + */
  9898. +public class OverrideMethodTest {
  9899. +
  9900. + @Before
  9901. + public void setUp() throws Exception {
  9902. + HotSwapTool.toVersion(OverrideMethodTest.class, 0);
  9903. + }
  9904. +
  9905. + // Version 0
  9906. + public static class A {
  9907. +
  9908. + public int value() {
  9909. + return 5;
  9910. + }
  9911. + }
  9912. +
  9913. + public static class B extends A {
  9914. +
  9915. + public int doubled() {
  9916. + return value() * 2;
  9917. + }
  9918. + }
  9919. +
  9920. + public static class C extends B {
  9921. + }
  9922. +
  9923. + // Version 1
  9924. + public static class A___1 {
  9925. +
  9926. + public int value() {
  9927. + return 10;
  9928. + }
  9929. + }
  9930. +
  9931. + // Version 2
  9932. + public static class B___2 extends A {
  9933. +
  9934. + public int doubled() {
  9935. + return value() * 3;
  9936. + }
  9937. + }
  9938. +
  9939. + // Version 3
  9940. + public static class C___3 extends B {
  9941. +
  9942. + @Override
  9943. + public int value() {
  9944. + return 1;
  9945. + }
  9946. + }
  9947. +
  9948. + // Verison 4
  9949. + public static class A___4 {
  9950. +
  9951. + public int value() {
  9952. + return baseValue();
  9953. + }
  9954. +
  9955. + public int baseValue() {
  9956. + return 20;
  9957. + }
  9958. + }
  9959. +
  9960. + public static class B___4 extends A {
  9961. +
  9962. + public int doubled() {
  9963. + return value() * 2;
  9964. + }
  9965. + }
  9966. +
  9967. + public static class C___4 extends B {
  9968. + }
  9969. +
  9970. + // Verison 5
  9971. + public static class A___5 {
  9972. +
  9973. + public int value() {
  9974. + return baseValue();
  9975. + }
  9976. +
  9977. + public int baseValue() {
  9978. + return 20;
  9979. + }
  9980. + }
  9981. +
  9982. + @Test
  9983. + public void testSimple() {
  9984. +
  9985. + assert HotSwapTool.getCurrentVersion(OverrideMethodTest.class) == 0;
  9986. +
  9987. + A a = new A();
  9988. + B b = new B();
  9989. + C c = new C();
  9990. +
  9991. + assertEquals(5, a.value());
  9992. + assertEquals(5, b.value());
  9993. + assertEquals(10, b.doubled());
  9994. + assertEquals(5, c.value());
  9995. + assertEquals(10, c.doubled());
  9996. +
  9997. + HotSwapTool.toVersion(OverrideMethodTest.class, 1);
  9998. + assertEquals(10, a.value());
  9999. + assertEquals(10, b.value());
  10000. + assertEquals(20, b.doubled());
  10001. + assertEquals(10, c.value());
  10002. + assertEquals(20, c.doubled());
  10003. +
  10004. + HotSwapTool.toVersion(OverrideMethodTest.class, 2);
  10005. + assertEquals(10, a.value());
  10006. + assertEquals(10, b.value());
  10007. + assertEquals(30, b.doubled());
  10008. + assertEquals(10, c.value());
  10009. + assertEquals(30, c.doubled());
  10010. +
  10011. + HotSwapTool.toVersion(OverrideMethodTest.class, 0);
  10012. + assertEquals(5, a.value());
  10013. + assertEquals(5, b.value());
  10014. + assertEquals(10, b.doubled());
  10015. + assertEquals(5, c.value());
  10016. + assertEquals(10, c.doubled());
  10017. + }
  10018. +
  10019. + @Test
  10020. + public void testMethodAdd() {
  10021. +
  10022. + assert HotSwapTool.getCurrentVersion(OverrideMethodTest.class) == 0;
  10023. + A a = new A();
  10024. + B b = new B();
  10025. + C c = new C();
  10026. +
  10027. + assertEquals(5, a.value());
  10028. + assertEquals(5, b.value());
  10029. + assertEquals(10, b.doubled());
  10030. + assertEquals(5, c.value());
  10031. + assertEquals(10, c.doubled());
  10032. +
  10033. + HotSwapTool.toVersion(OverrideMethodTest.class, 4);
  10034. + assertEquals(20, a.value());
  10035. + assertEquals(40, b.doubled());
  10036. + assertEquals(20, b.value());
  10037. + assertEquals(20, c.value());
  10038. + assertEquals(40, c.doubled());
  10039. +
  10040. + HotSwapTool.toVersion(OverrideMethodTest.class, 0);
  10041. + assertEquals(5, a.value());
  10042. + assertEquals(5, b.value());
  10043. + assertEquals(10, b.doubled());
  10044. + assertEquals(5, c.value());
  10045. + assertEquals(10, c.doubled());
  10046. + }
  10047. +
  10048. + @Test
  10049. + public void testOverride() {
  10050. +
  10051. + assert HotSwapTool.getCurrentVersion(OverrideMethodTest.class) == 0;
  10052. +
  10053. + A a = new A();
  10054. + B b = new B();
  10055. + C c = new C();
  10056. +
  10057. + assertEquals(5, a.value());
  10058. + assertEquals(5, b.value());
  10059. + assertEquals(10, b.doubled());
  10060. + assertEquals(5, c.value());
  10061. + assertEquals(10, c.doubled());
  10062. +
  10063. + HotSwapTool.toVersion(OverrideMethodTest.class, 3);
  10064. + assertEquals(5, a.value());
  10065. + assertEquals(5, b.value());
  10066. + assertEquals(10, b.doubled());
  10067. + assertEquals(1, c.value());
  10068. + assertEquals(2, c.doubled());
  10069. +
  10070. + HotSwapTool.toVersion(OverrideMethodTest.class, 0);
  10071. + assertEquals(5, a.value());
  10072. + assertEquals(5, b.value());
  10073. + assertEquals(10, b.doubled());
  10074. + assertEquals(5, c.value());
  10075. + assertEquals(10, c.doubled());
  10076. + }
  10077. +
  10078. + @Test
  10079. + public void testMethodAddAdvanced() {
  10080. +
  10081. + assert HotSwapTool.getCurrentVersion(OverrideMethodTest.class) == 0;
  10082. + A a = new A();
  10083. + B b = new B();
  10084. + C c = new C();
  10085. +
  10086. + assertEquals(5, a.value());
  10087. + assertEquals(5, b.value());
  10088. + assertEquals(10, b.doubled());
  10089. + assertEquals(5, c.value());
  10090. + assertEquals(10, c.doubled());
  10091. +
  10092. + HotSwapTool.toVersion(OverrideMethodTest.class, 5);
  10093. + assertEquals(20, a.value());
  10094. + assertEquals(20, b.value());
  10095. + assertEquals(40, b.doubled());
  10096. + assertEquals(20, c.value());
  10097. + assertEquals(40, c.doubled());
  10098. +
  10099. + HotSwapTool.toVersion(OverrideMethodTest.class, 0);
  10100. + assertEquals(5, a.value());
  10101. + assertEquals(5, b.value());
  10102. + assertEquals(10, b.doubled());
  10103. + assertEquals(5, c.value());
  10104. + assertEquals(10, c.doubled());
  10105. + }
  10106. +}
  10107. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/ReflectionTest.java
  10108. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  10109. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/ReflectionTest.java Fri Dec 17 13:23:04 2010 +0100
  10110. @@ -0,0 +1,215 @@
  10111. +/*
  10112. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10113. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10114. + *
  10115. + * This code is free software; you can redistribute it and/or modify it
  10116. + * under the terms of the GNU General Public License version 2 only, as
  10117. + * published by the Free Software Foundation.
  10118. + *
  10119. + * This code is distributed in the hope that it will be useful, but WITHOUT
  10120. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10121. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10122. + * version 2 for more details (a copy is included in the LICENSE file that
  10123. + * accompanied this code).
  10124. + *
  10125. + * You should have received a copy of the GNU General Public License version
  10126. + * 2 along with this work; if not, write to the Free Software Foundation,
  10127. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10128. + *
  10129. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10130. + * or visit www.oracle.com if you need additional information or have any
  10131. + * questions.
  10132. + *
  10133. + */
  10134. +
  10135. +package at.ssw.hotswap.test.methods;
  10136. +
  10137. +import static org.junit.Assert.assertEquals;
  10138. +
  10139. +import java.lang.reflect.Method;
  10140. +
  10141. +import junit.framework.Assert;
  10142. +
  10143. +import org.junit.Before;
  10144. +import org.junit.Test;
  10145. +
  10146. +import at.ssw.hotswap.HotSwapTool;
  10147. +import java.lang.ref.SoftReference;
  10148. +
  10149. +/**
  10150. + * Testing correct reflection functionality after class redefinition.
  10151. + *
  10152. + * @author Thomas Wuerthinger
  10153. + */
  10154. +public class ReflectionTest {
  10155. +
  10156. + @Before
  10157. + public void setUp() throws Exception {
  10158. + HotSwapTool.toVersion(ReflectionTest.class, 0);
  10159. + }
  10160. +
  10161. + // Version 0
  10162. + public static class A {
  10163. +
  10164. + public int value() {
  10165. + return 1;
  10166. + }
  10167. + }
  10168. +
  10169. + public static class B extends A {
  10170. +
  10171. + @Override
  10172. + public int value() {
  10173. + return 2;
  10174. + }
  10175. + }
  10176. +
  10177. + public static class C extends B {
  10178. +
  10179. + @Override
  10180. + public int value() {
  10181. + return 3;
  10182. + }
  10183. + }
  10184. +
  10185. + // Version 1
  10186. + public static class A___1 {
  10187. +
  10188. + public int value() {
  10189. + return 1;
  10190. + }
  10191. +
  10192. + public int value2() {
  10193. + return 2;
  10194. + }
  10195. + }
  10196. +
  10197. + // Version 2
  10198. + public static class C___2 extends A {
  10199. +
  10200. + @Override
  10201. + public int value() {
  10202. + return super.value();
  10203. + }
  10204. + }
  10205. +
  10206. + @Test
  10207. + public void testMethodReflection() {
  10208. +
  10209. + assert HotSwapTool.getCurrentVersion(ReflectionTest.class) == 0;
  10210. +
  10211. + A a = new A();
  10212. + B b = new B();
  10213. + C c = new C();
  10214. +
  10215. + assertEquals(1, a.value());
  10216. + assertEquals(2, b.value());
  10217. + assertEquals(3, c.value());
  10218. +
  10219. + assertContainsMethod(A.class, "value");
  10220. + assertDoesNotContainMethod(A.class, "value2");
  10221. +
  10222. + HotSwapTool.toVersion(ReflectionTest.class, 1);
  10223. +
  10224. + assertEquals(1, a.value());
  10225. + assertEquals(2, b.value());
  10226. + assertEquals(3, c.value());
  10227. +
  10228. + assertContainsMethod(A.class, "value");
  10229. + assertContainsMethod(A.class, "value2");
  10230. +
  10231. + HotSwapTool.toVersion(ReflectionTest.class, 0);
  10232. +
  10233. + assertEquals(1, a.value());
  10234. + assertEquals(2, b.value());
  10235. + assertEquals(3, c.value());
  10236. +
  10237. + assertContainsMethod(A.class, "value");
  10238. + assertDoesNotContainMethod(A.class, "value2");
  10239. + }
  10240. +
  10241. + private void assertContainsMethod(Class<?> c, String methodName) {
  10242. + boolean found = false;
  10243. + for (Method m : c.getDeclaredMethods()) {
  10244. + if (m.getName().equals(methodName)) {
  10245. + found = true;
  10246. + break;
  10247. + }
  10248. + }
  10249. +
  10250. + Assert.assertTrue(found);
  10251. + }
  10252. +
  10253. + private void assertDoesNotContainMethod(Class<?> c, String methodName) {
  10254. + boolean found = false;
  10255. + for (Method m : c.getDeclaredMethods()) {
  10256. + if (m.getName().equals(methodName)) {
  10257. + found = true;
  10258. + break;
  10259. + }
  10260. + }
  10261. +
  10262. + Assert.assertFalse(found);
  10263. + }
  10264. +
  10265. + private void assertIsSuper(Class<?> s, Class<?> c) {
  10266. + assertEquals(s, c.getSuperclass());
  10267. + }
  10268. +
  10269. + private void assertIsNotSuper(Class<?> s, Class<?> c) {
  10270. + Assert.assertFalse(s.equals(c.getSuperclass()));
  10271. + }
  10272. +
  10273. + @Test
  10274. + public void testClassReflection() {
  10275. +
  10276. + assert HotSwapTool.getCurrentVersion(ReflectionTest.class) == 0;
  10277. +
  10278. + A a = new A();
  10279. + B b = new B();
  10280. + C c = new C();
  10281. +
  10282. + assertIsSuper(A.class, B.class);
  10283. + assertIsSuper(B.class, C.class);
  10284. + assertIsNotSuper(A.class, C.class);
  10285. +
  10286. + assertEquals(1, a.value());
  10287. + assertEquals(2, b.value());
  10288. + assertEquals(3, c.value());
  10289. +
  10290. + HotSwapTool.toVersion(ReflectionTest.class, 2);
  10291. +
  10292. + assertIsSuper(A.class, B.class);
  10293. + assertIsNotSuper(B.class, C.class);
  10294. + assertIsSuper(A.class, C.class);
  10295. +
  10296. + assertEquals(1, a.value());
  10297. + assertEquals(2, b.value());
  10298. + assertEquals(1, c.value());
  10299. +
  10300. + HotSwapTool.toVersion(ReflectionTest.class, 0);
  10301. +
  10302. + assertIsSuper(A.class, B.class);
  10303. + assertIsNotSuper(A.class, C.class);
  10304. + assertIsSuper(B.class, C.class);
  10305. +
  10306. + assertEquals(1, a.value());
  10307. + assertEquals(2, b.value());
  10308. + assertEquals(3, c.value());
  10309. + }
  10310. +
  10311. + @Test
  10312. + public void testWeakReferenceOnClass() {
  10313. + A a = new A();
  10314. + Class strongRef = a.getClass();
  10315. + SoftReference<Class> softRef = new SoftReference<Class>(a.getClass());
  10316. +
  10317. +
  10318. + assertEquals(1, a.value());
  10319. + HotSwapTool.toVersion(ReflectionTest.class, 1);
  10320. + assertEquals(1, a.value());
  10321. + Assert.assertTrue(strongRef == softRef.get());
  10322. +
  10323. + HotSwapTool.toVersion(ReflectionTest.class, 0);
  10324. + }
  10325. +}
  10326. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/SingleClassReflectionTest.java
  10327. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  10328. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/SingleClassReflectionTest.java Fri Dec 17 13:23:04 2010 +0100
  10329. @@ -0,0 +1,88 @@
  10330. +/*
  10331. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10332. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10333. + *
  10334. + * This code is free software; you can redistribute it and/or modify it
  10335. + * under the terms of the GNU General Public License version 2 only, as
  10336. + * published by the Free Software Foundation.
  10337. + *
  10338. + * This code is distributed in the hope that it will be useful, but WITHOUT
  10339. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10340. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10341. + * version 2 for more details (a copy is included in the LICENSE file that
  10342. + * accompanied this code).
  10343. + *
  10344. + * You should have received a copy of the GNU General Public License version
  10345. + * 2 along with this work; if not, write to the Free Software Foundation,
  10346. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10347. + *
  10348. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10349. + * or visit www.oracle.com if you need additional information or have any
  10350. + * questions.
  10351. + *
  10352. + */
  10353. +
  10354. +package at.ssw.hotswap.test.methods;
  10355. +
  10356. +import static org.junit.Assert.assertEquals;
  10357. +
  10358. +import org.junit.Before;
  10359. +import org.junit.Test;
  10360. +
  10361. +import at.ssw.hotswap.HotSwapTool;
  10362. +
  10363. +/**
  10364. + * Testing correct behaviour of the class object after class redefinition (with respect to the identity hash code and synchronization).
  10365. + *
  10366. + * @author Thomas Wuerthinger
  10367. + */
  10368. +public class SingleClassReflectionTest {
  10369. +
  10370. + @Before
  10371. + public void setUp() throws Exception {
  10372. + HotSwapTool.toVersion(SingleClassReflectionTest.class, 0);
  10373. + }
  10374. +
  10375. + // Version 0
  10376. + public static class A {
  10377. +
  10378. + public static synchronized void staticSynchronized() {
  10379. + HotSwapTool.toVersion(SingleClassReflectionTest.class, 1);
  10380. + }
  10381. + }
  10382. +
  10383. +
  10384. + // Version 1
  10385. + public static class A___1 {
  10386. + public static synchronized void staticSynchronized() {
  10387. + }
  10388. + }
  10389. +
  10390. +
  10391. + @Test
  10392. + public void testHashcode() {
  10393. +
  10394. + assert HotSwapTool.getCurrentVersion(SingleClassReflectionTest.class) == 0;
  10395. +
  10396. + A a = new A();
  10397. +
  10398. + int hashcode = a.getClass().hashCode();
  10399. +
  10400. + HotSwapTool.toVersion(SingleClassReflectionTest.class, 1);
  10401. +
  10402. + assertEquals(hashcode, a.getClass().hashCode());
  10403. +
  10404. + HotSwapTool.toVersion(SingleClassReflectionTest.class, 0);
  10405. + }
  10406. +
  10407. + @Test
  10408. + public void testStaticSynchronized() {
  10409. +
  10410. + A.staticSynchronized();
  10411. +
  10412. + assertEquals(1, HotSwapTool.getCurrentVersion(SingleClassReflectionTest.class));
  10413. +
  10414. + HotSwapTool.toVersion(SingleClassReflectionTest.class, 0);
  10415. + }
  10416. +
  10417. +}
  10418. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/SingleClassTest.java
  10419. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  10420. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/methods/SingleClassTest.java Fri Dec 17 13:23:04 2010 +0100
  10421. @@ -0,0 +1,123 @@
  10422. +/*
  10423. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10424. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10425. + *
  10426. + * This code is free software; you can redistribute it and/or modify it
  10427. + * under the terms of the GNU General Public License version 2 only, as
  10428. + * published by the Free Software Foundation.
  10429. + *
  10430. + * This code is distributed in the hope that it will be useful, but WITHOUT
  10431. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10432. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10433. + * version 2 for more details (a copy is included in the LICENSE file that
  10434. + * accompanied this code).
  10435. + *
  10436. + * You should have received a copy of the GNU General Public License version
  10437. + * 2 along with this work; if not, write to the Free Software Foundation,
  10438. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10439. + *
  10440. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10441. + * or visit www.oracle.com if you need additional information or have any
  10442. + * questions.
  10443. + *
  10444. + */
  10445. +
  10446. +package at.ssw.hotswap.test.methods;
  10447. +
  10448. +import static org.junit.Assert.*;
  10449. +
  10450. +import org.junit.Before;
  10451. +import org.junit.Test;
  10452. +
  10453. +import at.ssw.hotswap.HotSwapTool;
  10454. +
  10455. +/**
  10456. + * Tests for adding / removing methods in a single class.
  10457. + *
  10458. + * @author Thomas Wuerthinger
  10459. + */
  10460. +public class SingleClassTest {
  10461. +
  10462. + // Version 0
  10463. + public static class A {
  10464. +
  10465. + public int value() {
  10466. + return 5;
  10467. + }
  10468. + }
  10469. +
  10470. + // Version 3
  10471. + public static class A___3 {
  10472. +
  10473. + public int value() {
  10474. + return 5;
  10475. + }
  10476. + }
  10477. +
  10478. + // Version 1
  10479. + public static class A___1 {
  10480. +
  10481. + public int value() {
  10482. + return 6;
  10483. + }
  10484. +
  10485. + public int testValue() {
  10486. + return 1;
  10487. +
  10488. + }
  10489. + }
  10490. +
  10491. + // Version 2
  10492. + public static class A___2 {
  10493. +
  10494. + public int value() {
  10495. + return baseValue() * 2;
  10496. + }
  10497. +
  10498. + public int baseValue() {
  10499. + return 10;
  10500. + }
  10501. + }
  10502. +
  10503. + @Before
  10504. + public void setUp() throws Exception {
  10505. + HotSwapTool.toVersion(SingleClassTest.class, 0);
  10506. + }
  10507. +
  10508. + @Test
  10509. + public void testSimpleReplacement() {
  10510. +
  10511. + assert HotSwapTool.getCurrentVersion(SingleClassTest.class) == 0;
  10512. +
  10513. + A a = new A();
  10514. +
  10515. + assertEquals(5, a.value());
  10516. +
  10517. + HotSwapTool.toVersion(SingleClassTest.class, 1);
  10518. +
  10519. + assertEquals(6, a.value());
  10520. +
  10521. + HotSwapTool.toVersion(SingleClassTest.class, 3);
  10522. +
  10523. + assertEquals(5, a.value());
  10524. +
  10525. + HotSwapTool.toVersion(SingleClassTest.class, 0);
  10526. +
  10527. + assertEquals(5, a.value());
  10528. + }
  10529. +
  10530. + @Test
  10531. + public void testAddMethod() {
  10532. +
  10533. + assert HotSwapTool.getCurrentVersion(SingleClassTest.class) == 0;
  10534. +
  10535. + A a = new A();
  10536. + assertEquals(a.value(), 5);
  10537. +
  10538. + HotSwapTool.toVersion(SingleClassTest.class, 2);
  10539. + assertEquals(a.value(), 20);
  10540. +
  10541. + HotSwapTool.toVersion(SingleClassTest.class, 0);
  10542. + assertEquals(a.value(), 5);
  10543. + }
  10544. +}
  10545. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/natives/NativesTestSuite.java
  10546. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  10547. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/natives/NativesTestSuite.java Fri Dec 17 13:23:04 2010 +0100
  10548. @@ -0,0 +1,41 @@
  10549. +/*
  10550. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10551. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10552. + *
  10553. + * This code is free software; you can redistribute it and/or modify it
  10554. + * under the terms of the GNU General Public License version 2 only, as
  10555. + * published by the Free Software Foundation.
  10556. + *
  10557. + * This code is distributed in the hope that it will be useful, but WITHOUT
  10558. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10559. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10560. + * version 2 for more details (a copy is included in the LICENSE file that
  10561. + * accompanied this code).
  10562. + *
  10563. + * You should have received a copy of the GNU General Public License version
  10564. + * 2 along with this work; if not, write to the Free Software Foundation,
  10565. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10566. + *
  10567. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10568. + * or visit www.oracle.com if you need additional information or have any
  10569. + * questions.
  10570. + *
  10571. + */
  10572. +
  10573. +package at.ssw.hotswap.test.natives;
  10574. +
  10575. +import org.junit.runner.RunWith;
  10576. +import org.junit.runners.Suite;
  10577. +
  10578. +/**
  10579. + * Class redefinition tests that include native code.
  10580. + *
  10581. + * @author Thomas Wuerthinger
  10582. + *
  10583. + */
  10584. +@RunWith(Suite.class)
  10585. +@Suite.SuiteClasses({
  10586. + SimpleNativeTest.class
  10587. +})
  10588. +public class NativesTestSuite {
  10589. +}
  10590. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/natives/SimpleNativeTest.java
  10591. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  10592. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/natives/SimpleNativeTest.java Fri Dec 17 13:23:04 2010 +0100
  10593. @@ -0,0 +1,86 @@
  10594. +/*
  10595. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10596. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10597. + *
  10598. + * This code is free software; you can redistribute it and/or modify it
  10599. + * under the terms of the GNU General Public License version 2 only, as
  10600. + * published by the Free Software Foundation.
  10601. + *
  10602. + * This code is distributed in the hope that it will be useful, but WITHOUT
  10603. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10604. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10605. + * version 2 for more details (a copy is included in the LICENSE file that
  10606. + * accompanied this code).
  10607. + *
  10608. + * You should have received a copy of the GNU General Public License version
  10609. + * 2 along with this work; if not, write to the Free Software Foundation,
  10610. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10611. + *
  10612. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10613. + * or visit www.oracle.com if you need additional information or have any
  10614. + * questions.
  10615. + *
  10616. + */
  10617. +
  10618. +package at.ssw.hotswap.test.natives;
  10619. +
  10620. +import static org.junit.Assert.assertEquals;
  10621. +
  10622. +import org.junit.Before;
  10623. +import org.junit.Test;
  10624. +
  10625. +import at.ssw.hotswap.HotSwapTool;
  10626. +
  10627. +/**
  10628. + * Testing correct resolving of a native method after class redefinition.
  10629. + *
  10630. + * @author Thomas Wuerthinger
  10631. + */
  10632. +public class SimpleNativeTest {
  10633. +
  10634. + @Before
  10635. + public void setUp() throws Exception {
  10636. + HotSwapTool.toVersion(SimpleNativeTest.class, 0);
  10637. + }
  10638. +
  10639. + // Version 0
  10640. + public static class A {
  10641. +
  10642. + public static int get() {
  10643. + return value();
  10644. + }
  10645. +
  10646. + public static native int value();
  10647. + }
  10648. +
  10649. + // Version 1
  10650. + public static class A___1 {
  10651. +
  10652. + public static int get() {
  10653. + return value() + value2();
  10654. + }
  10655. +
  10656. + public static native int value();
  10657. +
  10658. + public static native int value2();
  10659. + }
  10660. +
  10661. + @Test
  10662. + public void testSimpleNativeCalls() {
  10663. +
  10664. + assert HotSwapTool.getCurrentVersion(SimpleNativeTest.class) == 0;
  10665. +
  10666. +
  10667. + assertEquals(1, A.get());
  10668. +
  10669. + HotSwapTool.toVersion(SimpleNativeTest.class, 1);
  10670. +
  10671. + assertEquals(3, A.get());
  10672. +
  10673. + HotSwapTool.toVersion(SimpleNativeTest.class, 0);
  10674. +
  10675. + assertEquals(1, A.get());
  10676. +
  10677. + }
  10678. +
  10679. +}
  10680. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/GeometryScenario.java
  10681. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  10682. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/GeometryScenario.java Fri Dec 17 13:23:04 2010 +0100
  10683. @@ -0,0 +1,243 @@
  10684. +/*
  10685. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10686. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10687. + *
  10688. + * This code is free software; you can redistribute it and/or modify it
  10689. + * under the terms of the GNU General Public License version 2 only, as
  10690. + * published by the Free Software Foundation.
  10691. + *
  10692. + * This code is distributed in the hope that it will be useful, but WITHOUT
  10693. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10694. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10695. + * version 2 for more details (a copy is included in the LICENSE file that
  10696. + * accompanied this code).
  10697. + *
  10698. + * You should have received a copy of the GNU General Public License version
  10699. + * 2 along with this work; if not, write to the Free Software Foundation,
  10700. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10701. + *
  10702. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10703. + * or visit www.oracle.com if you need additional information or have any
  10704. + * questions.
  10705. + *
  10706. + */
  10707. +
  10708. +package at.ssw.hotswap.test.structural;
  10709. +
  10710. +import static org.junit.Assert.assertEquals;
  10711. +
  10712. +import org.junit.Before;
  10713. +import org.junit.Test;
  10714. +
  10715. +import at.ssw.hotswap.HotSwapTool;
  10716. +
  10717. +/**
  10718. + * A small geometry example application including a Point and a Rectangle class.
  10719. + *
  10720. + * @author Thomas Wuerthinger
  10721. + */
  10722. +public class GeometryScenario {
  10723. +
  10724. + @Before
  10725. + public void setUp() throws Exception {
  10726. + HotSwapTool.toVersion(GeometryScenario.class, 0);
  10727. + }
  10728. +
  10729. + // Version 0
  10730. + public static class Point {
  10731. +
  10732. + private int x;
  10733. + private int y;
  10734. +
  10735. + public Point(int x, int y) {
  10736. + this.x = x;
  10737. + this.y = y;
  10738. + }
  10739. +
  10740. + public boolean isBottomRightOf(Point p) {
  10741. + return p.x >= x && p.y >= y;
  10742. + }
  10743. +
  10744. + public boolean isTopLeftOf(Point p) {
  10745. + return p.x <= x && p.y <= y;
  10746. + }
  10747. +
  10748. + public int getX() {
  10749. + return x;
  10750. + }
  10751. +
  10752. + public int getY() {
  10753. + return y;
  10754. + }
  10755. + }
  10756. +
  10757. + public static interface IFigure {
  10758. +
  10759. + public boolean isHitAt(Point p);
  10760. + }
  10761. +
  10762. + public static class Rectangle {
  10763. +
  10764. + private Point topLeft;
  10765. + private Point bottomRight;
  10766. +
  10767. + public Rectangle(Point p1, Point p2) {
  10768. + topLeft = p1;
  10769. + bottomRight = p2;
  10770. + }
  10771. +
  10772. + public boolean isHitAt(Point p) {
  10773. + return p.isBottomRightOf(topLeft) && !p.isTopLeftOf(bottomRight);
  10774. + }
  10775. +
  10776. + public Point getTopLeft() {
  10777. + return topLeft;
  10778. + }
  10779. +
  10780. + public Point getBottomRight() {
  10781. + return bottomRight;
  10782. + }
  10783. +
  10784. + public static Rectangle create(Point p) {
  10785. + return (Rectangle) (Object) (new Rectangle___1(p));
  10786. + }
  10787. + }
  10788. +
  10789. + // Version 1
  10790. + public static class Rectangle___1 implements IFigure {
  10791. +
  10792. + private Point topLeft;
  10793. + private Point center;
  10794. + private Point bottomRight;
  10795. +
  10796. + public Point getCenter() {
  10797. + return center;
  10798. + }
  10799. +
  10800. + public Rectangle___1(Point p) {
  10801. + topLeft = p;
  10802. + bottomRight = p;
  10803. + }
  10804. +
  10805. + public boolean isHitAt(Point p) {
  10806. + return p.isBottomRightOf(topLeft) && !p.isTopLeftOf(bottomRight);
  10807. + }
  10808. +
  10809. + public Point getTopLeft() {
  10810. + return topLeft;
  10811. + }
  10812. +
  10813. + public Point getBottomRight() {
  10814. + return bottomRight;
  10815. + }
  10816. +
  10817. + public static Rectangle create(Point p) {
  10818. + return (Rectangle) (Object) (new Rectangle___1(p));
  10819. + }
  10820. + }
  10821. +
  10822. + public static class Point___1 {
  10823. +
  10824. + private char x1;
  10825. + private int y;
  10826. + private char x2;
  10827. +
  10828. + public boolean isBottomRightOf(Point p) {
  10829. + return p.x >= x1 && p.y >= y;
  10830. + }
  10831. +
  10832. + public boolean isTopLeftOf(Point p) {
  10833. + return p.x <= x1 && p.y <= y;
  10834. + }
  10835. +
  10836. + public int getY() {
  10837. + return y;
  10838. + }
  10839. +
  10840. + public int getX() {
  10841. + return x1;
  10842. + }
  10843. +
  10844. + public char getX2() {
  10845. + return x2;
  10846. + }
  10847. + }
  10848. +
  10849. + @Test
  10850. + public void testContructorChange() {
  10851. +
  10852. + assert HotSwapTool.getCurrentVersion(GeometryScenario.class) == 0;
  10853. +
  10854. + Point p1 = new Point(1, 2);
  10855. + Point p2 = new Point(3, 4);
  10856. + Rectangle r1 = new Rectangle(p1, p2);
  10857. +
  10858. + assertEquals(1, p1.getX());
  10859. + assertEquals(2, p1.getY());
  10860. + assertEquals(3, p2.getX());
  10861. + assertEquals(4, p2.getY());
  10862. + assertEquals(p1, r1.getTopLeft());
  10863. + assertEquals(p2, r1.getBottomRight());
  10864. +
  10865. + HotSwapTool.toVersion(GeometryScenario.class, 1);
  10866. +
  10867. + r1 = Rectangle.create(p1);
  10868. + assertEquals(0, p1.getX());
  10869. + assertEquals(2, p1.getY());
  10870. + assertEquals(0, p2.getX());
  10871. + assertEquals(4, p2.getY());
  10872. + assertEquals(p1, r1.getTopLeft());
  10873. + assertEquals(p1, r1.getBottomRight());
  10874. +
  10875. + HotSwapTool.toVersion(GeometryScenario.class, 0);
  10876. +
  10877. + assertEquals(0, p1.getX());
  10878. + assertEquals(2, p1.getY());
  10879. + assertEquals(0, p2.getX());
  10880. + assertEquals(4, p2.getY());
  10881. + assertEquals(p1, r1.getTopLeft());
  10882. + assertEquals(p1, r1.getBottomRight());
  10883. + }
  10884. +
  10885. + @Test
  10886. + public void testSingleGeometry() {
  10887. +
  10888. + assert HotSwapTool.getCurrentVersion(GeometryScenario.class) == 0;
  10889. +
  10890. + Point p1 = new Point(1, 2);
  10891. + Point p2 = new Point(3, 4);
  10892. + Rectangle r1 = new Rectangle(p1, p2);
  10893. +
  10894. + assertEquals(1, p1.getX());
  10895. + assertEquals(2, p1.getY());
  10896. + assertEquals(3, p2.getX());
  10897. + assertEquals(4, p2.getY());
  10898. + assertEquals(p1, r1.getTopLeft());
  10899. + assertEquals(p2, r1.getBottomRight());
  10900. +
  10901. + HotSwapTool.toVersion(GeometryScenario.class, 1);
  10902. +
  10903. + System.out.println("after redef");
  10904. + assertEquals(0, p1.getX());
  10905. + System.out.println("1");
  10906. + assertEquals(2, p1.getY());
  10907. + System.out.println("2");
  10908. + assertEquals(0, p2.getX());
  10909. + System.out.println("3");
  10910. + assertEquals(4, p2.getY());
  10911. + System.out.println("4");
  10912. + assertEquals(p1, r1.getTopLeft());
  10913. + System.out.println("5");
  10914. + assertEquals(p2, r1.getBottomRight());
  10915. + System.out.println("6");
  10916. +
  10917. + HotSwapTool.toVersion(GeometryScenario.class, 0);
  10918. +
  10919. + assertEquals(0, p1.getX());
  10920. + assertEquals(2, p1.getY());
  10921. + assertEquals(0, p2.getX());
  10922. + assertEquals(4, p2.getY());
  10923. + assertEquals(p1, r1.getTopLeft());
  10924. + assertEquals(p2, r1.getBottomRight());
  10925. + }
  10926. +}
  10927. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/HierarchySwapTest.java
  10928. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  10929. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/HierarchySwapTest.java Fri Dec 17 13:23:04 2010 +0100
  10930. @@ -0,0 +1,395 @@
  10931. +/*
  10932. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  10933. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10934. + *
  10935. + * This code is free software; you can redistribute it and/or modify it
  10936. + * under the terms of the GNU General Public License version 2 only, as
  10937. + * published by the Free Software Foundation.
  10938. + *
  10939. + * This code is distributed in the hope that it will be useful, but WITHOUT
  10940. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10941. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10942. + * version 2 for more details (a copy is included in the LICENSE file that
  10943. + * accompanied this code).
  10944. + *
  10945. + * You should have received a copy of the GNU General Public License version
  10946. + * 2 along with this work; if not, write to the Free Software Foundation,
  10947. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  10948. + *
  10949. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  10950. + * or visit www.oracle.com if you need additional information or have any
  10951. + * questions.
  10952. + *
  10953. + */
  10954. +
  10955. +package at.ssw.hotswap.test.structural;
  10956. +
  10957. +import static org.junit.Assert.*;
  10958. +
  10959. +import org.junit.Before;
  10960. +import org.junit.Test;
  10961. +
  10962. +import at.ssw.hotswap.HotSwapTool;
  10963. +
  10964. +/**
  10965. + * Smallest test case for a hierarchy swap. A<B is changed to B<A.
  10966. + *
  10967. + * @author Thomas Wuerthinger
  10968. + */
  10969. +public class HierarchySwapTest {
  10970. +
  10971. + // Version 0
  10972. + public static class A {
  10973. +
  10974. + public int value() {
  10975. + return 1;
  10976. + }
  10977. + }
  10978. +
  10979. + public static class B extends A {
  10980. +
  10981. + @Override
  10982. + public int value() {
  10983. + return super.value() * 2;
  10984. + }
  10985. + }
  10986. +
  10987. + public static class C {
  10988. +
  10989. + public boolean doInstanceCheckA(Object o) {
  10990. + return o instanceof A;
  10991. + }
  10992. +
  10993. + public boolean doInstanceCheckB(Object o) {
  10994. + return o instanceof B;
  10995. + }
  10996. + }
  10997. +
  10998. + public static class Base {
  10999. +
  11000. + public String className() {
  11001. + return "Base";
  11002. + }
  11003. + }
  11004. +
  11005. + public static class D extends Base {
  11006. +
  11007. + @Override
  11008. + public String className() {
  11009. + return "D";
  11010. + }
  11011. +
  11012. + public String superClassName() {
  11013. + return super.className();
  11014. + }
  11015. + }
  11016. +
  11017. + public static class E extends Base {
  11018. +
  11019. + @Override
  11020. + public String className() {
  11021. + return "E";
  11022. + }
  11023. +
  11024. + public String superClassName() {
  11025. + return super.className();
  11026. + }
  11027. + }
  11028. +
  11029. + public static class F extends Base {
  11030. +
  11031. + @Override
  11032. + public String className() {
  11033. + return "F";
  11034. + }
  11035. +
  11036. + public String superClassName() {
  11037. + return super.className();
  11038. + }
  11039. + }
  11040. +
  11041. + // Version 1
  11042. + public static class A___1 extends B___1 {
  11043. +
  11044. + @Override
  11045. + public int value() {
  11046. + return super.value() * 2;
  11047. + }
  11048. + }
  11049. +
  11050. + public static class B___1 {
  11051. +
  11052. + public int value() {
  11053. + return 4;
  11054. + }
  11055. + }
  11056. +
  11057. + public static class C___1 {
  11058. +
  11059. + public boolean doInstanceCheckA(Object o) {
  11060. + return o instanceof A;
  11061. + }
  11062. +
  11063. + public boolean doInstanceCheckB(Object o) {
  11064. + return o instanceof B;
  11065. + }
  11066. + }
  11067. +
  11068. + // Version 2
  11069. + public static class D___2 extends Base {
  11070. +
  11071. + @Override
  11072. + public String className() {
  11073. + return "D";
  11074. + }
  11075. +
  11076. + public String superClassName() {
  11077. + return super.className();
  11078. + }
  11079. + }
  11080. +
  11081. + public static class E___2 extends D {
  11082. +
  11083. + @Override
  11084. + public String className() {
  11085. + return "E";
  11086. + }
  11087. +
  11088. + @Override
  11089. + public String superClassName() {
  11090. + return super.className();
  11091. + }
  11092. + }
  11093. +
  11094. + public static class F___2 extends E {
  11095. +
  11096. + @Override
  11097. + public String className() {
  11098. + return "F";
  11099. + }
  11100. +
  11101. + @Override
  11102. + public String superClassName() {
  11103. + return super.className();
  11104. + }
  11105. + }
  11106. +
  11107. + // Version 3
  11108. + public static class D___3 extends E {
  11109. +
  11110. + @Override
  11111. + public String className() {
  11112. + return "D";
  11113. + }
  11114. +
  11115. + @Override
  11116. + public String superClassName() {
  11117. + return super.className();
  11118. + }
  11119. + }
  11120. +
  11121. + public static class E___3 extends F {
  11122. +
  11123. + @Override
  11124. + public String className() {
  11125. + return "E";
  11126. + }
  11127. +
  11128. + @Override
  11129. + public String superClassName() {
  11130. + return super.className();
  11131. + }
  11132. + }
  11133. +
  11134. + public static class F___3 extends Base {
  11135. +
  11136. + @Override
  11137. + public String className() {
  11138. + return "F";
  11139. + }
  11140. +
  11141. + public String superClassName() {
  11142. + return super.className();
  11143. + }
  11144. + }
  11145. +
  11146. + // Version 4
  11147. + public static class D___4 extends E {
  11148. +
  11149. + @Override
  11150. + public String className() {
  11151. + return "D";
  11152. + }
  11153. +
  11154. + @Override
  11155. + public String superClassName() {
  11156. + return super.className();
  11157. + }
  11158. + }
  11159. +
  11160. + public static class E___4 extends Base {
  11161. +
  11162. + @Override
  11163. + public String className() {
  11164. + return "E";
  11165. + }
  11166. +
  11167. + public String superClassName() {
  11168. + return super.className();
  11169. + }
  11170. + }
  11171. +
  11172. + public static class F___4 extends E {
  11173. +
  11174. + @Override
  11175. + public String className() {
  11176. + return "F";
  11177. + }
  11178. +
  11179. + @Override
  11180. + public String superClassName() {
  11181. + return super.className();
  11182. + }
  11183. + }
  11184. +
  11185. + @Before
  11186. + public void setUp() throws Exception {
  11187. + HotSwapTool.toVersion(HierarchySwapTest.class, 0);
  11188. + }
  11189. +
  11190. + @Test
  11191. + public void testHierarchySwap() {
  11192. +
  11193. + assert HotSwapTool.getCurrentVersion(HierarchySwapTest.class) == 0;
  11194. +
  11195. + A a = new A();
  11196. + B b = new B();
  11197. +
  11198. + assertEquals(1, a.value());
  11199. + assertEquals(2, b.value());
  11200. + assertTrue(b.getClass().getSuperclass().equals(A.class));
  11201. + assertFalse(a.getClass().getSuperclass().equals(B.class));
  11202. +
  11203. + HotSwapTool.toVersion(HierarchySwapTest.class, 1);
  11204. +
  11205. + assertEquals(8, a.value());
  11206. + assertEquals(4, b.value());
  11207. + assertFalse(b.getClass().getSuperclass().equals(A.class));
  11208. + assertTrue(a.getClass().getSuperclass().equals(B.class));
  11209. +
  11210. + HotSwapTool.toVersion(HierarchySwapTest.class, 0);
  11211. +
  11212. + assertEquals(1, a.value());
  11213. + assertEquals(2, b.value());
  11214. + assertTrue(b.getClass().getSuperclass().equals(A.class));
  11215. + assertFalse(a.getClass().getSuperclass().equals(B.class));
  11216. + }
  11217. +
  11218. + @Test
  11219. + public void testHierarchySwapWithInstanceOfTest() {
  11220. +
  11221. + assert HotSwapTool.getCurrentVersion(HierarchySwapTest.class) == 0;
  11222. +
  11223. + A a = new A();
  11224. + B b = new B();
  11225. + C c = new C();
  11226. +
  11227. + assertEquals(1, a.value());
  11228. + assertEquals(2, b.value());
  11229. + assertTrue(c.doInstanceCheckA(b));
  11230. + assertFalse(c.doInstanceCheckB(a));
  11231. +
  11232. + HotSwapTool.toVersion(HierarchySwapTest.class, 1);
  11233. +
  11234. + assertEquals(8, a.value());
  11235. + assertEquals(4, b.value());
  11236. + assertFalse(c.doInstanceCheckA(b));
  11237. + assertTrue(c.doInstanceCheckB(a));
  11238. +
  11239. + HotSwapTool.toVersion(HierarchySwapTest.class, 0);
  11240. +
  11241. + assertEquals(1, a.value());
  11242. + assertEquals(2, b.value());
  11243. + assertTrue(c.doInstanceCheckA(b));
  11244. + assertFalse(c.doInstanceCheckB(a));
  11245. + }
  11246. +
  11247. + @Test
  11248. + public void testHierarchySwapWithInstanceOf() {
  11249. +
  11250. + assert HotSwapTool.getCurrentVersion(HierarchySwapTest.class) == 0;
  11251. +
  11252. + A a = new A();
  11253. + B b = new B();
  11254. +
  11255. + assertEquals(1, a.value());
  11256. + assertEquals(2, b.value());
  11257. + assertTrue(b instanceof A);
  11258. + assertFalse(a instanceof B);
  11259. +
  11260. + HotSwapTool.toVersion(HierarchySwapTest.class, 1);
  11261. +
  11262. + assertEquals(8, a.value());
  11263. + assertEquals(4, b.value());
  11264. + assertFalse(b instanceof A);
  11265. + assertTrue(a instanceof B);
  11266. +
  11267. + HotSwapTool.toVersion(HierarchySwapTest.class, 0);
  11268. +
  11269. + assertEquals(1, a.value());
  11270. + assertEquals(2, b.value());
  11271. + assertTrue(b instanceof A);
  11272. + assertFalse(a instanceof B);
  11273. + }
  11274. +
  11275. + @Test
  11276. + public void testTripleSwap() {
  11277. +
  11278. +
  11279. + assert HotSwapTool.getCurrentVersion(HierarchySwapTest.class) == 0;
  11280. +
  11281. + D d = new D();
  11282. + E e = new E();
  11283. + F f = new F();
  11284. +
  11285. + assertEquals(d.superClassName(), "Base");
  11286. + assertEquals(e.superClassName(), "Base");
  11287. + assertEquals(f.superClassName(), "Base");
  11288. +
  11289. + HotSwapTool.toVersion(HierarchySwapTest.class, 2);
  11290. +
  11291. + assertEquals(d.superClassName(), "Base");
  11292. + assertEquals(e.superClassName(), "D");
  11293. + assertEquals(f.superClassName(), "E");
  11294. +
  11295. + HotSwapTool.toVersion(HierarchySwapTest.class, 3);
  11296. +
  11297. + assertEquals(d.superClassName(), "E");
  11298. + assertEquals(e.superClassName(), "F");
  11299. + assertEquals(f.superClassName(), "Base");
  11300. +
  11301. + HotSwapTool.toVersion(HierarchySwapTest.class, 4);
  11302. +
  11303. + assertEquals(d.superClassName(), "E");
  11304. + assertEquals(e.superClassName(), "Base");
  11305. + assertEquals(f.superClassName(), "E");
  11306. +
  11307. + HotSwapTool.toVersion(HierarchySwapTest.class, 3);
  11308. +
  11309. + assertEquals(d.superClassName(), "E");
  11310. + assertEquals(e.superClassName(), "F");
  11311. + assertEquals(f.superClassName(), "Base");
  11312. +
  11313. + HotSwapTool.toVersion(HierarchySwapTest.class, 2);
  11314. +
  11315. + assertEquals(d.superClassName(), "Base");
  11316. + assertEquals(e.superClassName(), "D");
  11317. + assertEquals(f.superClassName(), "E");
  11318. +
  11319. + HotSwapTool.toVersion(HierarchySwapTest.class, 0);
  11320. +
  11321. + assertEquals(d.superClassName(), "Base");
  11322. + assertEquals(e.superClassName(), "Base");
  11323. + assertEquals(f.superClassName(), "Base");
  11324. + }
  11325. +}
  11326. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/InterfaceTest.java
  11327. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  11328. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/InterfaceTest.java Fri Dec 17 13:23:04 2010 +0100
  11329. @@ -0,0 +1,152 @@
  11330. +/*
  11331. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  11332. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  11333. + *
  11334. + * This code is free software; you can redistribute it and/or modify it
  11335. + * under the terms of the GNU General Public License version 2 only, as
  11336. + * published by the Free Software Foundation.
  11337. + *
  11338. + * This code is distributed in the hope that it will be useful, but WITHOUT
  11339. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11340. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11341. + * version 2 for more details (a copy is included in the LICENSE file that
  11342. + * accompanied this code).
  11343. + *
  11344. + * You should have received a copy of the GNU General Public License version
  11345. + * 2 along with this work; if not, write to the Free Software Foundation,
  11346. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  11347. + *
  11348. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  11349. + * or visit www.oracle.com if you need additional information or have any
  11350. + * questions.
  11351. + *
  11352. + */
  11353. +
  11354. +package at.ssw.hotswap.test.structural;
  11355. +
  11356. +import static org.junit.Assert.assertEquals;
  11357. +import static org.junit.Assert.assertFalse;
  11358. +import static org.junit.Assert.assertTrue;
  11359. +import static org.junit.Assert.fail;
  11360. +
  11361. +import org.junit.After;
  11362. +import org.junit.AfterClass;
  11363. +import org.junit.Before;
  11364. +import org.junit.BeforeClass;
  11365. +import org.junit.Test;
  11366. +
  11367. +import at.ssw.hotswap.HotSwapTool;
  11368. +import at.ssw.hotswap.test.methods.OverrideMethodTest;
  11369. +
  11370. +/**
  11371. + * Tests for adding an interface to a class and for changing the methods of an interface.
  11372. + *
  11373. + * @author Thomas Wuerthinger
  11374. + */
  11375. +public class InterfaceTest {
  11376. +
  11377. + @BeforeClass
  11378. + public static void setUpBeforeClass() throws Exception {
  11379. + }
  11380. +
  11381. + @AfterClass
  11382. + public static void tearDownAfterClass() throws Exception {
  11383. + }
  11384. +
  11385. + @Before
  11386. + public void setUp() throws Exception {
  11387. + HotSwapTool.toVersion(InterfaceTest.class, 0);
  11388. + }
  11389. +
  11390. + @After
  11391. + public void tearDown() throws Exception {
  11392. + }
  11393. +
  11394. + public static interface A {
  11395. +
  11396. + int giveMeFive();
  11397. + }
  11398. +
  11399. + public static class AImpl {
  11400. +
  11401. + public int giveMeFive() {
  11402. + return 5;
  11403. + }
  11404. + }
  11405. +
  11406. + public static class BImpl implements A {
  11407. +
  11408. + @Override
  11409. + public int giveMeFive() {
  11410. + return 5;
  11411. + }
  11412. +
  11413. + public int giveMeTen() {
  11414. + return 10;
  11415. + }
  11416. + }
  11417. +
  11418. + public static class AImpl___1 implements A {
  11419. +
  11420. + @Override
  11421. + public int giveMeFive() {
  11422. + return 5;
  11423. + }
  11424. + }
  11425. +
  11426. + public static interface A___2 {
  11427. +
  11428. + int giveMeTen();
  11429. + }
  11430. +
  11431. + public static class Helper {
  11432. +
  11433. + public int giveMeTenA2(A a) {
  11434. + return 3;
  11435. + }
  11436. + }
  11437. +
  11438. + public static class Helper___2 {
  11439. +
  11440. + public int giveMeTenA2(A a) {
  11441. + return ((A___2) a).giveMeTen();
  11442. + }
  11443. + }
  11444. +
  11445. + @Test
  11446. + public void testAddInterface() {
  11447. +
  11448. + assert HotSwapTool.getCurrentVersion(OverrideMethodTest.class) == 0;
  11449. +
  11450. + AImpl a = new AImpl();
  11451. + assertFalse(a instanceof A);
  11452. + try {
  11453. + int val = (((A) a).giveMeFive());
  11454. + fail();
  11455. + } catch (ClassCastException e) {
  11456. + }
  11457. +
  11458. + HotSwapTool.toVersion(InterfaceTest.class, 1);
  11459. + assertTrue(a instanceof A);
  11460. + assertEquals(5, ((A) a).giveMeFive());
  11461. +
  11462. + HotSwapTool.toVersion(InterfaceTest.class, 0);
  11463. + assertFalse(a instanceof A);
  11464. + }
  11465. +
  11466. + @Test
  11467. + public void testModifyInterface() {
  11468. +
  11469. + assert HotSwapTool.getCurrentVersion(OverrideMethodTest.class) == 0;
  11470. +
  11471. + BImpl b = new BImpl();
  11472. + assertTrue(b instanceof A);
  11473. +
  11474. + HotSwapTool.toVersion(InterfaceTest.class, 2);
  11475. +
  11476. + assertEquals(10, new Helper().giveMeTenA2(b));
  11477. +
  11478. + HotSwapTool.toVersion(InterfaceTest.class, 0);
  11479. + assertEquals(5, ((A) b).giveMeFive());
  11480. + }
  11481. +}
  11482. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/LargeHierarchyTest.java
  11483. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  11484. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/LargeHierarchyTest.java Fri Dec 17 13:23:04 2010 +0100
  11485. @@ -0,0 +1,293 @@
  11486. +/*
  11487. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  11488. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  11489. + *
  11490. + * This code is free software; you can redistribute it and/or modify it
  11491. + * under the terms of the GNU General Public License version 2 only, as
  11492. + * published by the Free Software Foundation.
  11493. + *
  11494. + * This code is distributed in the hope that it will be useful, but WITHOUT
  11495. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11496. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11497. + * version 2 for more details (a copy is included in the LICENSE file that
  11498. + * accompanied this code).
  11499. + *
  11500. + * You should have received a copy of the GNU General Public License version
  11501. + * 2 along with this work; if not, write to the Free Software Foundation,
  11502. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  11503. + *
  11504. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  11505. + * or visit www.oracle.com if you need additional information or have any
  11506. + * questions.
  11507. + *
  11508. + */
  11509. +
  11510. +package at.ssw.hotswap.test.structural;
  11511. +
  11512. +import static org.junit.Assert.*;
  11513. +
  11514. +import org.junit.Before;
  11515. +import org.junit.Test;
  11516. +
  11517. +import at.ssw.hotswap.HotSwapTool;
  11518. +
  11519. +/**
  11520. + * Tests that modify a large class hierarchy with the classes A, B, C, D, E, and F.
  11521. + *
  11522. + * @author Thomas Wuerthinger
  11523. + */
  11524. +public class LargeHierarchyTest {
  11525. +
  11526. + private A a = new A();
  11527. + private B b = new B();
  11528. + private C c = new C();
  11529. + private D d = new D();
  11530. + private E e = new E();
  11531. + private F f = new F();
  11532. +
  11533. + @Before
  11534. + public void setUp() throws Exception {
  11535. + HotSwapTool.toVersion(LargeHierarchyTest.class, 0);
  11536. + }
  11537. +
  11538. + // Version 0
  11539. + public static class A {
  11540. +
  11541. + public int value() {
  11542. + return 1;
  11543. + }
  11544. + }
  11545. +
  11546. + public static class B extends A {
  11547. +
  11548. + @Override
  11549. + public int value() {
  11550. + return super.value() * 2;
  11551. + }
  11552. + }
  11553. +
  11554. + public static class C extends B {
  11555. +
  11556. + @Override
  11557. + public int value() {
  11558. + return super.value() * 2;
  11559. + }
  11560. + }
  11561. +
  11562. + public static class D extends C {
  11563. +
  11564. + @Override
  11565. + public int value() {
  11566. + return super.value() * 2;
  11567. + }
  11568. + }
  11569. +
  11570. + public static class E extends D {
  11571. +
  11572. + @Override
  11573. + public int value() {
  11574. + return super.value() * 2;
  11575. + }
  11576. + }
  11577. +
  11578. + public static class F extends E {
  11579. +
  11580. + @Override
  11581. + public int value() {
  11582. + return super.value() * 2;
  11583. + }
  11584. + }
  11585. +
  11586. + // Version 1
  11587. + public static class A___1 {
  11588. +
  11589. + public int value() {
  11590. + return 2;
  11591. + }
  11592. + }
  11593. +
  11594. + // Version 2
  11595. + // D - E - F
  11596. + // /
  11597. + // A - B - C
  11598. + public static class D___2 extends A {
  11599. +
  11600. + @Override
  11601. + public int value() {
  11602. + return super.value() * 2;
  11603. + }
  11604. + }
  11605. +
  11606. + // Version 3
  11607. + // D
  11608. + // /
  11609. + // A - B - C - E - F
  11610. + public static class D___3 extends A {
  11611. +
  11612. + @Override
  11613. + public int value() {
  11614. + return super.value() * 2;
  11615. + }
  11616. + }
  11617. +
  11618. + public static class E___3 extends A {
  11619. +
  11620. + @Override
  11621. + public int value() {
  11622. + return super.value() * 2;
  11623. + }
  11624. + }
  11625. +
  11626. + // Version 4
  11627. + // Completely flat
  11628. + public static class C___4 extends A {
  11629. +
  11630. + @Override
  11631. + public int value() {
  11632. + return super.value() * 2;
  11633. + }
  11634. + }
  11635. +
  11636. + public static class D___4 extends A {
  11637. +
  11638. + @Override
  11639. + public int value() {
  11640. + return super.value() * 2;
  11641. + }
  11642. + }
  11643. +
  11644. + public static class E___4 extends A {
  11645. +
  11646. + @Override
  11647. + public int value() {
  11648. + return super.value() * 2;
  11649. + }
  11650. + }
  11651. +
  11652. + public static class F___4 extends A {
  11653. +
  11654. + @Override
  11655. + public int value() {
  11656. + return super.value() * 2;
  11657. + }
  11658. + }
  11659. +
  11660. + // Version 5
  11661. + public static class F___5 extends E {
  11662. +
  11663. + @Override
  11664. + public int value() {
  11665. + return 0;
  11666. + }
  11667. + }
  11668. +
  11669. + @Test
  11670. + public void testChangeBaseClass() {
  11671. +
  11672. + assert HotSwapTool.getCurrentVersion(LargeHierarchyTest.class) == 0;
  11673. +
  11674. + assertEquals(1, a.value());
  11675. + assertEquals(2, b.value());
  11676. + assertEquals(4, c.value());
  11677. + assertEquals(8, d.value());
  11678. + assertEquals(16, e.value());
  11679. + assertEquals(32, f.value());
  11680. +
  11681. + HotSwapTool.toVersion(LargeHierarchyTest.class, 1);
  11682. +
  11683. + assertEquals(2, a.value());
  11684. + assertEquals(4, b.value());
  11685. + assertEquals(8, c.value());
  11686. + assertEquals(16, d.value());
  11687. + assertEquals(32, e.value());
  11688. + assertEquals(64, f.value());
  11689. +
  11690. + HotSwapTool.toVersion(LargeHierarchyTest.class, 0);
  11691. +
  11692. + assertEquals(1, a.value());
  11693. + assertEquals(2, b.value());
  11694. + assertEquals(4, c.value());
  11695. + assertEquals(8, d.value());
  11696. + assertEquals(16, e.value());
  11697. + assertEquals(32, f.value());
  11698. + }
  11699. +
  11700. + @Test
  11701. + public void testChangeSubClass() {
  11702. + assert HotSwapTool.getCurrentVersion(LargeHierarchyTest.class) == 0;
  11703. +
  11704. + assertEquals(1, a.value());
  11705. + assertEquals(2, b.value());
  11706. + assertEquals(4, c.value());
  11707. + assertEquals(8, d.value());
  11708. + assertEquals(16, e.value());
  11709. + assertEquals(32, f.value());
  11710. +
  11711. + HotSwapTool.toVersion(LargeHierarchyTest.class, 5);
  11712. +
  11713. + assertEquals(1, a.value());
  11714. + assertEquals(2, b.value());
  11715. + assertEquals(4, c.value());
  11716. + assertEquals(8, d.value());
  11717. + assertEquals(16, e.value());
  11718. + assertEquals(0, f.value());
  11719. +
  11720. + HotSwapTool.toVersion(LargeHierarchyTest.class, 0);
  11721. +
  11722. + assertEquals(1, a.value());
  11723. + assertEquals(2, b.value());
  11724. + assertEquals(4, c.value());
  11725. + assertEquals(8, d.value());
  11726. + assertEquals(16, e.value());
  11727. + assertEquals(32, f.value());
  11728. + }
  11729. +
  11730. + @Test
  11731. + public void testChangeHierarchy() {
  11732. +
  11733. + assert HotSwapTool.getCurrentVersion(LargeHierarchyTest.class) == 0;
  11734. +
  11735. + assertEquals(1, a.value());
  11736. + assertEquals(2, b.value());
  11737. + assertEquals(4, c.value());
  11738. + assertEquals(8, d.value());
  11739. + assertEquals(16, e.value());
  11740. + assertEquals(32, f.value());
  11741. +
  11742. + HotSwapTool.toVersion(LargeHierarchyTest.class, 2);
  11743. +
  11744. + assertEquals(1, a.value());
  11745. + assertEquals(2, b.value());
  11746. + assertEquals(4, c.value());
  11747. + assertEquals(2, d.value());
  11748. + assertEquals(4, e.value());
  11749. + assertEquals(8, f.value());
  11750. +
  11751. + HotSwapTool.toVersion(LargeHierarchyTest.class, 3);
  11752. +
  11753. + assertEquals(1, a.value());
  11754. + assertEquals(2, b.value());
  11755. + assertEquals(4, c.value());
  11756. + assertEquals(2, d.value());
  11757. + assertEquals(2, e.value());
  11758. + assertEquals(4, f.value());
  11759. +
  11760. + HotSwapTool.toVersion(LargeHierarchyTest.class, 4);
  11761. +
  11762. + assertEquals(1, a.value());
  11763. + assertEquals(2, b.value());
  11764. + assertEquals(2, c.value());
  11765. + assertEquals(2, d.value());
  11766. + assertEquals(2, e.value());
  11767. + assertEquals(2, f.value());
  11768. +
  11769. + HotSwapTool.toVersion(LargeHierarchyTest.class, 0);
  11770. +
  11771. + assertEquals(1, a.value());
  11772. + assertEquals(2, b.value());
  11773. + assertEquals(4, c.value());
  11774. + assertEquals(8, d.value());
  11775. + assertEquals(16, e.value());
  11776. + assertEquals(32, f.value());
  11777. + }
  11778. +}
  11779. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/RedefineClassClassTest.java
  11780. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  11781. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/RedefineClassClassTest.java Fri Dec 17 13:23:04 2010 +0100
  11782. @@ -0,0 +1,69 @@
  11783. +/*
  11784. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  11785. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  11786. + *
  11787. + * This code is free software; you can redistribute it and/or modify it
  11788. + * under the terms of the GNU General Public License version 2 only, as
  11789. + * published by the Free Software Foundation.
  11790. + *
  11791. + * This code is distributed in the hope that it will be useful, but WITHOUT
  11792. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11793. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11794. + * version 2 for more details (a copy is included in the LICENSE file that
  11795. + * accompanied this code).
  11796. + *
  11797. + * You should have received a copy of the GNU General Public License version
  11798. + * 2 along with this work; if not, write to the Free Software Foundation,
  11799. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  11800. + *
  11801. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  11802. + * or visit www.oracle.com if you need additional information or have any
  11803. + * questions.
  11804. + *
  11805. + */
  11806. +package at.ssw.hotswap.test.structural;
  11807. +
  11808. +import at.ssw.hotswap.ClassRedefinitionPolicy;
  11809. +
  11810. +
  11811. +import at.ssw.hotswap.HotSwapTool;
  11812. +import org.junit.Before;
  11813. +import org.junit.Test;
  11814. +
  11815. +/**
  11816. + * Smallest test case for redefining the interface java/lang/reflect/Type (causes java/lang/Class being redefined)
  11817. + *
  11818. + * @author Thomas Wuerthinger
  11819. + */
  11820. +public class RedefineClassClassTest {
  11821. +
  11822. + // Version 0
  11823. + public interface Type {
  11824. + }
  11825. +
  11826. + // Version 1
  11827. + @ClassRedefinitionPolicy(alias = java.lang.reflect.Type.class)
  11828. + public interface Type___1 {
  11829. + }
  11830. +
  11831. + @Before
  11832. + public void setUp() throws Exception {
  11833. + HotSwapTool.toVersion(RedefineClassClassTest.class, 0);
  11834. + }
  11835. +
  11836. + @Test
  11837. + public void testRedefineClass() {
  11838. +
  11839. + assert HotSwapTool.getCurrentVersion(RedefineClassClassTest.class) == 0;
  11840. +
  11841. + HotSwapTool.toVersion(RedefineClassClassTest.class, 1);
  11842. +
  11843. + HotSwapTool.toVersion(RedefineClassClassTest.class, 0);
  11844. +
  11845. + HotSwapTool.toVersion(RedefineClassClassTest.class, 1);
  11846. +
  11847. + HotSwapTool.toVersion(RedefineClassClassTest.class, 0);
  11848. +
  11849. +
  11850. + }
  11851. +}
  11852. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/RedefineObjectClassTest.java
  11853. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  11854. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/RedefineObjectClassTest.java Fri Dec 17 13:23:04 2010 +0100
  11855. @@ -0,0 +1,142 @@
  11856. +/*
  11857. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  11858. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  11859. + *
  11860. + * This code is free software; you can redistribute it and/or modify it
  11861. + * under the terms of the GNU General Public License version 2 only, as
  11862. + * published by the Free Software Foundation.
  11863. + *
  11864. + * This code is distributed in the hope that it will be useful, but WITHOUT
  11865. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11866. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11867. + * version 2 for more details (a copy is included in the LICENSE file that
  11868. + * accompanied this code).
  11869. + *
  11870. + * You should have received a copy of the GNU General Public License version
  11871. + * 2 along with this work; if not, write to the Free Software Foundation,
  11872. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  11873. + *
  11874. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  11875. + * or visit www.oracle.com if you need additional information or have any
  11876. + * questions.
  11877. + *
  11878. + */
  11879. +package at.ssw.hotswap.test.structural;
  11880. +
  11881. +import at.ssw.hotswap.ClassRedefinitionPolicy;
  11882. +import static org.junit.Assert.*;
  11883. +
  11884. +import org.junit.Before;
  11885. +import org.junit.Test;
  11886. +
  11887. +import at.ssw.hotswap.HotSwapTool;
  11888. +
  11889. +/**
  11890. + * Smallest test case for redefining java/lang/Object, without changing the number of virtual methods.
  11891. + *
  11892. + * @author Thomas Wuerthinger
  11893. + */
  11894. +public class RedefineObjectClassTest {
  11895. +
  11896. + // Version 0
  11897. + public static class Helper {
  11898. + public static String access(Object o) {
  11899. + return "";
  11900. + }
  11901. + }
  11902. +
  11903. + // Version 1
  11904. +
  11905. + public static class Helper___1 {
  11906. + public static String access(Object o) {
  11907. + return ((A___1)o).myTestFunction___();
  11908. + }
  11909. + }
  11910. +
  11911. + @ClassRedefinitionPolicy(alias=java.lang.Object.class)
  11912. + public static class A___1 {
  11913. +
  11914. + public final native Class<? extends Object> getClass___();
  11915. +
  11916. + public native int hashCode();
  11917. +
  11918. + public boolean equals(Object obj) {
  11919. + return (this == obj);
  11920. + }
  11921. +
  11922. + public static int x;
  11923. + public static int x1;
  11924. + public static int x2;
  11925. + public static int x3;
  11926. + public static int x4;
  11927. + public static int x5;
  11928. +
  11929. + protected native Object clone() throws CloneNotSupportedException;
  11930. +
  11931. + public String toString() {
  11932. + System.out.println("x=" + (x++));
  11933. + return getClass().getName() + "@" + Integer.toHexString(hashCode());// myTestFunction___();
  11934. + }
  11935. +
  11936. + public final String myTestFunction___() {
  11937. + return "test";
  11938. + }
  11939. +
  11940. + public final native void notify___();
  11941. +
  11942. + public final native void notifyAll___();
  11943. +
  11944. + public final native void wait___(long timeout) throws InterruptedException;
  11945. +
  11946. + public final void wait___(long timeout, int nanos) throws InterruptedException {
  11947. +
  11948. +
  11949. + if (timeout < 0) {
  11950. + throw new IllegalArgumentException("timeout value is negative");
  11951. + }
  11952. +
  11953. + if (nanos < 0 || nanos > 999999) {
  11954. + throw new IllegalArgumentException(
  11955. + "nanosecond timeout value out of range");
  11956. + }
  11957. +
  11958. + if (nanos >= 500000 || (nanos != 0 && timeout == 0)) {
  11959. + timeout++;
  11960. + }
  11961. +
  11962. + wait(timeout);
  11963. + }
  11964. +
  11965. + public final void wait___() throws InterruptedException {
  11966. + wait(0);
  11967. + }
  11968. +
  11969. + protected void finalize() throws Throwable {
  11970. + }
  11971. + }
  11972. +
  11973. + @Before
  11974. + public void setUp() throws Exception {
  11975. + HotSwapTool.toVersion(RedefineObjectClassTest.class, 0);
  11976. + }
  11977. +
  11978. + @Test
  11979. + public void testRedefineObject() {
  11980. +
  11981. + assert HotSwapTool.getCurrentVersion(RedefineObjectClassTest.class) == 0;
  11982. +
  11983. + Object o = new Object();
  11984. + HotSwapTool.toVersion(RedefineObjectClassTest.class, 1);
  11985. +
  11986. + System.out.println(this.toString());
  11987. + System.out.println(o.toString());
  11988. + System.out.println(this.toString());
  11989. +
  11990. +
  11991. + //assertEquals("test", o.toString());
  11992. + assertEquals("test", Helper.access(o));
  11993. + HotSwapTool.toVersion(RedefineObjectClassTest.class, 0);
  11994. + HotSwapTool.toVersion(RedefineObjectClassTest.class, 1);
  11995. + HotSwapTool.toVersion(RedefineObjectClassTest.class, 0);
  11996. + }
  11997. +}
  11998. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/StructuralTestSuite.java
  11999. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  12000. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/StructuralTestSuite.java Fri Dec 17 13:23:04 2010 +0100
  12001. @@ -0,0 +1,52 @@
  12002. +/*
  12003. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  12004. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  12005. + *
  12006. + * This code is free software; you can redistribute it and/or modify it
  12007. + * under the terms of the GNU General Public License version 2 only, as
  12008. + * published by the Free Software Foundation.
  12009. + *
  12010. + * This code is distributed in the hope that it will be useful, but WITHOUT
  12011. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12012. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12013. + * version 2 for more details (a copy is included in the LICENSE file that
  12014. + * accompanied this code).
  12015. + *
  12016. + * You should have received a copy of the GNU General Public License version
  12017. + * 2 along with this work; if not, write to the Free Software Foundation,
  12018. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  12019. + *
  12020. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  12021. + * or visit www.oracle.com if you need additional information or have any
  12022. + * questions.
  12023. + *
  12024. + */
  12025. +
  12026. +package at.ssw.hotswap.test.structural;
  12027. +
  12028. +import org.junit.runner.RunWith;
  12029. +import org.junit.runners.Suite;
  12030. +
  12031. +/**
  12032. + * Class redefinition tests that do arbitrary structural changes.
  12033. + *
  12034. + * TODO: Add a test where redefinition triggers classloading (e.g. because a super type is not yet loaded).
  12035. + *
  12036. + * @author Thomas Wuerthinger
  12037. + */
  12038. +@RunWith(Suite.class)
  12039. +@Suite.SuiteClasses({
  12040. + RedefineClassClassTest.class,
  12041. + RedefineObjectClassTest.class,
  12042. + GeometryScenario.class,
  12043. + HierarchySwapTest.class,
  12044. + InterfaceTest.class,
  12045. + LargeHierarchyTest.class,
  12046. + ThisTypeChange.class,
  12047. + TypeNarrowingHeapTest.class,
  12048. + TypeNarrowingMethodTest.class,
  12049. + TypeNarrowingMethodTest2.class,
  12050. + TypeNarrowingMethodTest3.class
  12051. +})
  12052. +public class StructuralTestSuite {
  12053. +}
  12054. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/ThisTypeChange.java
  12055. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  12056. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/ThisTypeChange.java Fri Dec 17 13:23:04 2010 +0100
  12057. @@ -0,0 +1,123 @@
  12058. +/*
  12059. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  12060. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  12061. + *
  12062. + * This code is free software; you can redistribute it and/or modify it
  12063. + * under the terms of the GNU General Public License version 2 only, as
  12064. + * published by the Free Software Foundation.
  12065. + *
  12066. + * This code is distributed in the hope that it will be useful, but WITHOUT
  12067. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12068. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12069. + * version 2 for more details (a copy is included in the LICENSE file that
  12070. + * accompanied this code).
  12071. + *
  12072. + * You should have received a copy of the GNU General Public License version
  12073. + * 2 along with this work; if not, write to the Free Software Foundation,
  12074. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  12075. + *
  12076. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  12077. + * or visit www.oracle.com if you need additional information or have any
  12078. + * questions.
  12079. + *
  12080. + */
  12081. +
  12082. +package at.ssw.hotswap.test.structural;
  12083. +
  12084. +import org.junit.Before;
  12085. +import org.junit.Test;
  12086. +
  12087. +import at.ssw.hotswap.HotSwapTool;
  12088. +import at.ssw.hotswap.test.TestUtil;
  12089. +
  12090. +/**
  12091. + * Tests that change the type of the object references by the Java this pointer.
  12092. + *
  12093. + * @author Thomas Wuerthinger
  12094. + */
  12095. +public class ThisTypeChange {
  12096. +
  12097. + @Before
  12098. + public void setUp() throws Exception {
  12099. + HotSwapTool.toVersion(ThisTypeChange.class, 0);
  12100. + }
  12101. +
  12102. + // Version 0
  12103. + public static class A {
  12104. +
  12105. + public int valueOK() {
  12106. + return 1;
  12107. + }
  12108. +
  12109. + public int value() {
  12110. + HotSwapTool.toVersion(ThisTypeChange.class, 1);
  12111. + return 1;
  12112. + }
  12113. + }
  12114. +
  12115. + public static class B extends A {
  12116. +
  12117. + @Override
  12118. + public int value() {
  12119. + return super.value();
  12120. + }
  12121. +
  12122. +
  12123. + @Override
  12124. + public int valueOK() {
  12125. + HotSwapTool.toVersion(ThisTypeChange.class, 1);
  12126. + return super.valueOK();
  12127. + }
  12128. + }
  12129. +
  12130. + // Version 1
  12131. + public static class A___1 {
  12132. +
  12133. + public int valueOK() {
  12134. + return 2;
  12135. + }
  12136. + }
  12137. +
  12138. + // Version 1
  12139. + public static class B___1 {
  12140. + }
  12141. +
  12142. + // Method to enforce cast (otherwise bytecodes become invalid in version 2)
  12143. + public static A convertBtoA(Object b) {
  12144. + return (A)b;
  12145. + }
  12146. +
  12147. + @Test
  12148. + public void testThisTypeChange() {
  12149. +
  12150. + assert HotSwapTool.getCurrentVersion(ThisTypeChange.class) == 0;
  12151. +
  12152. + final B b = new B();
  12153. + TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {
  12154. + @Override
  12155. + public void run() {
  12156. + b.value();
  12157. + }
  12158. + });
  12159. +
  12160. + assert HotSwapTool.getCurrentVersion(ThisTypeChange.class) == 0;
  12161. +
  12162. + TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {
  12163. + @Override
  12164. + public void run() {
  12165. + b.valueOK();
  12166. + }
  12167. + });
  12168. +
  12169. + assert HotSwapTool.getCurrentVersion(ThisTypeChange.class) == 0;
  12170. +
  12171. + TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {
  12172. + @Override
  12173. + public void run() {
  12174. + b.valueOK();
  12175. + }
  12176. + });
  12177. +
  12178. + assert HotSwapTool.getCurrentVersion(ThisTypeChange.class) == 0;
  12179. + }
  12180. +}
  12181. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/TypeNarrowingHeapTest.java
  12182. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  12183. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/TypeNarrowingHeapTest.java Fri Dec 17 13:23:04 2010 +0100
  12184. @@ -0,0 +1,180 @@
  12185. +/*
  12186. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  12187. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  12188. + *
  12189. + * This code is free software; you can redistribute it and/or modify it
  12190. + * under the terms of the GNU General Public License version 2 only, as
  12191. + * published by the Free Software Foundation.
  12192. + *
  12193. + * This code is distributed in the hope that it will be useful, but WITHOUT
  12194. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12195. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12196. + * version 2 for more details (a copy is included in the LICENSE file that
  12197. + * accompanied this code).
  12198. + *
  12199. + * You should have received a copy of the GNU General Public License version
  12200. + * 2 along with this work; if not, write to the Free Software Foundation,
  12201. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  12202. + *
  12203. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  12204. + * or visit www.oracle.com if you need additional information or have any
  12205. + * questions.
  12206. + *
  12207. + */
  12208. +
  12209. +package at.ssw.hotswap.test.structural;
  12210. +
  12211. +import static org.junit.Assert.*;
  12212. +
  12213. +import org.junit.Before;
  12214. +import org.junit.Test;
  12215. +
  12216. +import at.ssw.hotswap.HotSwapTool;
  12217. +import at.ssw.hotswap.test.TestUtil;
  12218. +
  12219. +/**
  12220. + * Test case for type narrowing.
  12221. + *
  12222. + * @author Thomas Wuerthinger
  12223. + */
  12224. +public class TypeNarrowingHeapTest {
  12225. +
  12226. + // Version 0
  12227. + public static class A {
  12228. +
  12229. + int x = 1;
  12230. + int y = 2;
  12231. + int z = 3;
  12232. +
  12233. + public int value() {
  12234. + return x;
  12235. + }
  12236. + }
  12237. +
  12238. + public static class C {
  12239. + private A a;
  12240. +
  12241. + public C(A a) {
  12242. + this.a = a;
  12243. + }
  12244. + }
  12245. +
  12246. + public static class B extends A {
  12247. +
  12248. + }
  12249. +
  12250. +
  12251. + // Version 1
  12252. + public static class B___1 {
  12253. + }
  12254. +
  12255. +
  12256. + @Before
  12257. + public void setUp() throws Exception {
  12258. + HotSwapTool.toVersion(TypeNarrowingHeapTest.class, 0);
  12259. + A a = new A();
  12260. + B b = new B();
  12261. + }
  12262. +
  12263. + @Test
  12264. + public void testSimpleTypeNarrowing() {
  12265. +
  12266. + assert HotSwapTool.getCurrentVersion(TypeNarrowingHeapTest.class) == 0;
  12267. +
  12268. + A a = convertBtoA(new B());
  12269. +
  12270. + assertEquals(1, a.value());
  12271. +
  12272. + // Cannot do conversion if A object is on the stack!
  12273. + a = null;
  12274. +
  12275. + HotSwapTool.toVersion(TypeNarrowingHeapTest.class, 1);
  12276. +
  12277. + TestUtil.assertException(NoSuchMethodError.class, new Runnable() {
  12278. + @Override
  12279. + public void run() {
  12280. + B b = new B();
  12281. + b.value();
  12282. + }
  12283. + });
  12284. +
  12285. + HotSwapTool.toVersion(TypeNarrowingHeapTest.class, 0);
  12286. + assert HotSwapTool.getCurrentVersion(TypeNarrowingHeapTest.class) == 0;
  12287. + }
  12288. +
  12289. + @Test
  12290. + public void testTypeNarrowingWithField() {
  12291. + C c = new C(new A());
  12292. +
  12293. + HotSwapTool.toVersion(TypeNarrowingHeapTest.class, 1);
  12294. +
  12295. + HotSwapTool.toVersion(TypeNarrowingHeapTest.class, 0);
  12296. +
  12297. + c = new C(convertBtoA(new B()));
  12298. +
  12299. + TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {
  12300. + @Override
  12301. + public void run() {
  12302. + HotSwapTool.toVersion(TypeNarrowingHeapTest.class, 1);
  12303. + }
  12304. + });
  12305. +
  12306. + assert HotSwapTool.getCurrentVersion(TypeNarrowingHeapTest.class) == 0;
  12307. +
  12308. + c.a = null;
  12309. +
  12310. + HotSwapTool.toVersion(TypeNarrowingHeapTest.class, 1);
  12311. +
  12312. + HotSwapTool.toVersion(TypeNarrowingHeapTest.class, 0);
  12313. + }
  12314. +
  12315. + // Method to enforce cast (otherwise bytecodes become invalid in version 2)
  12316. + public static A convertBtoA(Object b) {
  12317. + return (A)b;
  12318. + }
  12319. +
  12320. + @Test
  12321. + public void testTypeNarrowingWithArray() {
  12322. + final B b = new B();
  12323. + final A[] arr = new A[3];
  12324. + arr[0] = new A();
  12325. +
  12326. + assert b instanceof A;
  12327. +
  12328. + HotSwapTool.toVersion(TypeNarrowingHeapTest.class, 1);
  12329. +
  12330. + assert !(b instanceof A);
  12331. +
  12332. + TestUtil.assertException(ArrayStoreException.class, new Runnable() {
  12333. + @Override
  12334. + public void run() {
  12335. + arr[1] = b;
  12336. + }
  12337. + });
  12338. +
  12339. + HotSwapTool.toVersion(TypeNarrowingHeapTest.class, 0);
  12340. +
  12341. + arr[1] = new B();
  12342. +
  12343. + TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {
  12344. + @Override
  12345. + public void run() {
  12346. + HotSwapTool.toVersion(TypeNarrowingHeapTest.class, 1);
  12347. + }
  12348. + });
  12349. +
  12350. + assert HotSwapTool.getCurrentVersion(TypeNarrowingHeapTest.class) == 0;
  12351. +
  12352. + assert b instanceof A;
  12353. +
  12354. + arr[1] = new A();
  12355. +
  12356. + HotSwapTool.toVersion(TypeNarrowingHeapTest.class, 1);
  12357. +
  12358. + assert !(b instanceof A);
  12359. +
  12360. + HotSwapTool.toVersion(TypeNarrowingHeapTest.class, 0);
  12361. +
  12362. + assert b instanceof A;
  12363. + }
  12364. +}
  12365. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/TypeNarrowingMethodTest.java
  12366. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  12367. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/TypeNarrowingMethodTest.java Fri Dec 17 13:23:04 2010 +0100
  12368. @@ -0,0 +1,112 @@
  12369. +/*
  12370. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  12371. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  12372. + *
  12373. + * This code is free software; you can redistribute it and/or modify it
  12374. + * under the terms of the GNU General Public License version 2 only, as
  12375. + * published by the Free Software Foundation.
  12376. + *
  12377. + * This code is distributed in the hope that it will be useful, but WITHOUT
  12378. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12379. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12380. + * version 2 for more details (a copy is included in the LICENSE file that
  12381. + * accompanied this code).
  12382. + *
  12383. + * You should have received a copy of the GNU General Public License version
  12384. + * 2 along with this work; if not, write to the Free Software Foundation,
  12385. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  12386. + *
  12387. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  12388. + * or visit www.oracle.com if you need additional information or have any
  12389. + * questions.
  12390. + *
  12391. + */
  12392. +
  12393. +package at.ssw.hotswap.test.structural;
  12394. +
  12395. +import static org.junit.Assert.*;
  12396. +
  12397. +import org.junit.Before;
  12398. +import org.junit.Test;
  12399. +
  12400. +import at.ssw.hotswap.HotSwapTool;
  12401. +import at.ssw.hotswap.test.TestUtil;
  12402. +
  12403. +/**
  12404. + * Test case for type narrowing where a non-active method fails verification because of the new hierarchy.
  12405. + *
  12406. + * @author Thomas Wuerthinger
  12407. + */
  12408. +public class TypeNarrowingMethodTest {
  12409. +
  12410. + // Version 0
  12411. + public static class A {
  12412. +
  12413. + int x = 1;
  12414. + int y = 2;
  12415. + int z = 3;
  12416. +
  12417. + public int value() {
  12418. + return x;
  12419. + }
  12420. +
  12421. + public static int badMethod(B b) {
  12422. + A a = b;
  12423. + return a.y;
  12424. + }
  12425. + }
  12426. +
  12427. + public static class B extends A {
  12428. +
  12429. + }
  12430. +
  12431. +
  12432. + // Version 1
  12433. + public static class B___1 {
  12434. + }
  12435. +
  12436. + // Version 2
  12437. + public static class A___2 {
  12438. +
  12439. + int x = 1;
  12440. + int y = 2;
  12441. + int z = 3;
  12442. +
  12443. + public int value() {
  12444. + return x;
  12445. + }
  12446. +
  12447. + public static int badMethod(B b) {
  12448. + return 5;
  12449. + }
  12450. + }
  12451. +
  12452. + public static class B___2 {
  12453. + }
  12454. +
  12455. +
  12456. + @Before
  12457. + public void setUp() throws Exception {
  12458. + HotSwapTool.toVersion(TypeNarrowingMethodTest.class, 0);
  12459. + A a = new A();
  12460. + B b = new B();
  12461. + }
  12462. +
  12463. +
  12464. + @Test
  12465. + public void testTypeNarrowingWithViolatingMethod() {
  12466. +
  12467. + TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {
  12468. + @Override
  12469. + public void run() {
  12470. + HotSwapTool.toVersion(TypeNarrowingMethodTest.class, 1);
  12471. + }
  12472. + });
  12473. +
  12474. + assert HotSwapTool.getCurrentVersion(TypeNarrowingMethodTest.class) == 0;
  12475. +
  12476. + HotSwapTool.toVersion(TypeNarrowingMethodTest.class, 2);
  12477. +
  12478. + HotSwapTool.toVersion(TypeNarrowingMethodTest.class, 0);
  12479. + }
  12480. +}
  12481. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/TypeNarrowingMethodTest2.java
  12482. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  12483. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/TypeNarrowingMethodTest2.java Fri Dec 17 13:23:04 2010 +0100
  12484. @@ -0,0 +1,117 @@
  12485. +/*
  12486. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  12487. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  12488. + *
  12489. + * This code is free software; you can redistribute it and/or modify it
  12490. + * under the terms of the GNU General Public License version 2 only, as
  12491. + * published by the Free Software Foundation.
  12492. + *
  12493. + * This code is distributed in the hope that it will be useful, but WITHOUT
  12494. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12495. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12496. + * version 2 for more details (a copy is included in the LICENSE file that
  12497. + * accompanied this code).
  12498. + *
  12499. + * You should have received a copy of the GNU General Public License version
  12500. + * 2 along with this work; if not, write to the Free Software Foundation,
  12501. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  12502. + *
  12503. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  12504. + * or visit www.oracle.com if you need additional information or have any
  12505. + * questions.
  12506. + *
  12507. + */
  12508. +
  12509. +package at.ssw.hotswap.test.structural;
  12510. +
  12511. +import static org.junit.Assert.*;
  12512. +
  12513. +import org.junit.Before;
  12514. +import org.junit.Test;
  12515. +
  12516. +import at.ssw.hotswap.HotSwapTool;
  12517. +import at.ssw.hotswap.test.TestUtil;
  12518. +
  12519. +/**
  12520. + * Test case for type narrowing where a non-active method fails verification because of the new hierarchy.
  12521. + *
  12522. + * @author Thomas Wuerthinger
  12523. + */
  12524. +public class TypeNarrowingMethodTest2 {
  12525. +
  12526. + // Version 0
  12527. + public static class A {
  12528. +
  12529. + int x = 1;
  12530. + int y = 2;
  12531. + int z = 3;
  12532. +
  12533. + public int value() {
  12534. + return x;
  12535. + }
  12536. +
  12537. + public static int badMethod() {
  12538. + A a = indirectionMethod();
  12539. + return a.y;
  12540. + }
  12541. + }
  12542. +
  12543. + public static class B extends A {
  12544. +
  12545. + }
  12546. +
  12547. +
  12548. + // Version 1
  12549. + public static class B___1 {
  12550. + }
  12551. +
  12552. + // Version 2
  12553. + public static class A___2 {
  12554. +
  12555. + int x = 1;
  12556. + int y = 2;
  12557. + int z = 3;
  12558. +
  12559. + public int value() {
  12560. + return x;
  12561. + }
  12562. +
  12563. + public static int badMethod(B b) {
  12564. + return 5;
  12565. + }
  12566. + }
  12567. +
  12568. + public static class B___2 {
  12569. + }
  12570. +
  12571. +
  12572. + @Before
  12573. + public void setUp() throws Exception {
  12574. + HotSwapTool.toVersion(TypeNarrowingMethodTest2.class, 0);
  12575. + A a = new A();
  12576. + B b = new B();
  12577. + }
  12578. +
  12579. + public static B indirectionMethod() {
  12580. + return new B();
  12581. + }
  12582. +
  12583. + @Test
  12584. + public void testTypeNarrowingWithViolatingMethod() {
  12585. + final A a = new A();
  12586. +
  12587. + TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {
  12588. + @Override
  12589. + public void run() {
  12590. + HotSwapTool.toVersion(TypeNarrowingMethodTest2.class, 1);
  12591. + System.out.println(a.badMethod());
  12592. + }
  12593. + });
  12594. +
  12595. + assert HotSwapTool.getCurrentVersion(TypeNarrowingMethodTest2.class) == 0;
  12596. +
  12597. + HotSwapTool.toVersion(TypeNarrowingMethodTest2.class, 2);
  12598. +
  12599. + HotSwapTool.toVersion(TypeNarrowingMethodTest2.class, 0);
  12600. + }
  12601. +}
  12602. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/TypeNarrowingMethodTest3.java
  12603. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  12604. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/structural/TypeNarrowingMethodTest3.java Fri Dec 17 13:23:04 2010 +0100
  12605. @@ -0,0 +1,114 @@
  12606. +/*
  12607. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  12608. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  12609. + *
  12610. + * This code is free software; you can redistribute it and/or modify it
  12611. + * under the terms of the GNU General Public License version 2 only, as
  12612. + * published by the Free Software Foundation.
  12613. + *
  12614. + * This code is distributed in the hope that it will be useful, but WITHOUT
  12615. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12616. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12617. + * version 2 for more details (a copy is included in the LICENSE file that
  12618. + * accompanied this code).
  12619. + *
  12620. + * You should have received a copy of the GNU General Public License version
  12621. + * 2 along with this work; if not, write to the Free Software Foundation,
  12622. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  12623. + *
  12624. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  12625. + * or visit www.oracle.com if you need additional information or have any
  12626. + * questions.
  12627. + *
  12628. + */
  12629. +
  12630. +package at.ssw.hotswap.test.structural;
  12631. +
  12632. +import org.junit.Before;
  12633. +import org.junit.Test;
  12634. +
  12635. +import at.ssw.hotswap.HotSwapTool;
  12636. +import at.ssw.hotswap.test.TestUtil;
  12637. +
  12638. +/**
  12639. + * Test case for type narrowing where a non-active method fails verification because of the new hierarchy.
  12640. + *
  12641. + * @author Thomas Wuerthinger
  12642. + */
  12643. +public class TypeNarrowingMethodTest3 {
  12644. +
  12645. + // Version 0
  12646. + public static class A {
  12647. +
  12648. + int x = 1;
  12649. + int y = 2;
  12650. + int z = 3;
  12651. +
  12652. + public int value() {
  12653. + return x;
  12654. + }
  12655. +
  12656. + public static int badMethod() {
  12657. + A a = indirectionMethod()[0];
  12658. + return a.y;
  12659. + }
  12660. + }
  12661. +
  12662. + public static class B extends A {
  12663. +
  12664. + }
  12665. +
  12666. + // Version 1
  12667. + public static class B___1 {
  12668. + }
  12669. +
  12670. + // Version 2
  12671. + public static class A___2 {
  12672. +
  12673. + int x = 1;
  12674. + int y = 2;
  12675. + int z = 3;
  12676. +
  12677. + public int value() {
  12678. + return x;
  12679. + }
  12680. +
  12681. + public static int badMethod(B b) {
  12682. + return 5;
  12683. + }
  12684. + }
  12685. +
  12686. + public static class B___2 {
  12687. + }
  12688. +
  12689. +
  12690. + @Before
  12691. + public void setUp() throws Exception {
  12692. + HotSwapTool.toVersion(TypeNarrowingMethodTest3.class, 0);
  12693. + A a = new A();
  12694. + B b = new B();
  12695. + }
  12696. +
  12697. + public static B[] indirectionMethod() {
  12698. + return new B[]{ new B() };
  12699. + }
  12700. +
  12701. + @Test
  12702. + public void testTypeNarrowingWithViolatingMethod() {
  12703. + final A a = new A();
  12704. +
  12705. + TestUtil.assertException(UnsupportedOperationException.class, new Runnable() {
  12706. + @Override
  12707. + public void run() {
  12708. + HotSwapTool.toVersion(TypeNarrowingMethodTest3.class, 1);
  12709. + System.out.println(a.badMethod());
  12710. + }
  12711. + });
  12712. +
  12713. + assert HotSwapTool.getCurrentVersion(TypeNarrowingMethodTest3.class) == 0;
  12714. +
  12715. + HotSwapTool.toVersion(TypeNarrowingMethodTest3.class, 2);
  12716. +
  12717. + HotSwapTool.toVersion(TypeNarrowingMethodTest3.class, 0);
  12718. + }
  12719. +}
  12720. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/transformer/BaseClassTransformerTest.java
  12721. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  12722. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/transformer/BaseClassTransformerTest.java Fri Dec 17 13:23:04 2010 +0100
  12723. @@ -0,0 +1,100 @@
  12724. +/*
  12725. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  12726. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  12727. + *
  12728. + * This code is free software; you can redistribute it and/or modify it
  12729. + * under the terms of the GNU General Public License version 2 only, as
  12730. + * published by the Free Software Foundation.
  12731. + *
  12732. + * This code is distributed in the hope that it will be useful, but WITHOUT
  12733. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12734. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12735. + * version 2 for more details (a copy is included in the LICENSE file that
  12736. + * accompanied this code).
  12737. + *
  12738. + * You should have received a copy of the GNU General Public License version
  12739. + * 2 along with this work; if not, write to the Free Software Foundation,
  12740. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  12741. + *
  12742. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  12743. + * or visit www.oracle.com if you need additional information or have any
  12744. + * questions.
  12745. + *
  12746. + */
  12747. +
  12748. +package at.ssw.hotswap.test.transformer;
  12749. +
  12750. +import static org.junit.Assert.*;
  12751. +
  12752. +import org.junit.Before;
  12753. +import org.junit.Test;
  12754. +
  12755. +import at.ssw.hotswap.HotSwapTool;
  12756. +
  12757. +class BaseClass {
  12758. + public void $transformer() {
  12759. + transformerExecuted();
  12760. + }
  12761. +
  12762. + public void transformerExecuted() {
  12763. +
  12764. + }
  12765. +}
  12766. +
  12767. +/**
  12768. + * Tests for executing the transformer of a base class.
  12769. + *
  12770. + * @author Thomas Wuerthinger
  12771. + */
  12772. +public class BaseClassTransformerTest {
  12773. +
  12774. + // Version 0
  12775. + public static class A {
  12776. +
  12777. + public int x = 2;
  12778. + }
  12779. +
  12780. + // Version 3
  12781. + public static class A___1 extends BaseClass {
  12782. +
  12783. + public int x;
  12784. +
  12785. + @Override
  12786. + public void transformerExecuted() {
  12787. + System.out.println("Transformer of A executing...");
  12788. + x = x * 2;
  12789. + }
  12790. + }
  12791. +
  12792. +
  12793. + @Before
  12794. + public void setUp() throws Exception {
  12795. + HotSwapTool.toVersion(BaseClassTransformerTest.class, 0);
  12796. + }
  12797. +
  12798. + @Test
  12799. + public void testSimpleTransformer() {
  12800. +
  12801. + assert HotSwapTool.getCurrentVersion(BaseClassTransformerTest.class) == 0;
  12802. +
  12803. + A a = new A();
  12804. +
  12805. + assertEquals(2, a.x);
  12806. +
  12807. + HotSwapTool.toVersion(BaseClassTransformerTest.class, 1);
  12808. +
  12809. + assertEquals(4, a.x);
  12810. +
  12811. + HotSwapTool.toVersion(BaseClassTransformerTest.class, 0);
  12812. +
  12813. + assertEquals(4, a.x);
  12814. +
  12815. + HotSwapTool.toVersion(BaseClassTransformerTest.class, 1);
  12816. +
  12817. + assertEquals(8, a.x);
  12818. +
  12819. + HotSwapTool.toVersion(BaseClassTransformerTest.class, 0);
  12820. +
  12821. + assertEquals(8, a.x);
  12822. + }
  12823. +}
  12824. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/transformer/SimpleTransformerTest.java
  12825. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  12826. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/transformer/SimpleTransformerTest.java Fri Dec 17 13:23:04 2010 +0100
  12827. @@ -0,0 +1,89 @@
  12828. +/*
  12829. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  12830. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  12831. + *
  12832. + * This code is free software; you can redistribute it and/or modify it
  12833. + * under the terms of the GNU General Public License version 2 only, as
  12834. + * published by the Free Software Foundation.
  12835. + *
  12836. + * This code is distributed in the hope that it will be useful, but WITHOUT
  12837. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12838. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12839. + * version 2 for more details (a copy is included in the LICENSE file that
  12840. + * accompanied this code).
  12841. + *
  12842. + * You should have received a copy of the GNU General Public License version
  12843. + * 2 along with this work; if not, write to the Free Software Foundation,
  12844. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  12845. + *
  12846. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  12847. + * or visit www.oracle.com if you need additional information or have any
  12848. + * questions.
  12849. + *
  12850. + */
  12851. +
  12852. +package at.ssw.hotswap.test.transformer;
  12853. +
  12854. +import static org.junit.Assert.*;
  12855. +
  12856. +import org.junit.Before;
  12857. +import org.junit.Test;
  12858. +
  12859. +import at.ssw.hotswap.HotSwapTool;
  12860. +
  12861. +/**
  12862. + * Tests for executing the transformer of a class.
  12863. + *
  12864. + * @author Thomas Wuerthinger
  12865. + */
  12866. +public class SimpleTransformerTest {
  12867. +
  12868. + // Version 0
  12869. + public static class A {
  12870. +
  12871. + public int x = 2;
  12872. + }
  12873. +
  12874. + // Version 3
  12875. + public static class A___1 {
  12876. +
  12877. + public int x;
  12878. +
  12879. + public void $transformer() {
  12880. + System.out.println("Transformer of A executing...");
  12881. + x = x * 2;
  12882. + }
  12883. + }
  12884. +
  12885. +
  12886. + @Before
  12887. + public void setUp() throws Exception {
  12888. + HotSwapTool.toVersion(SimpleTransformerTest.class, 0);
  12889. + }
  12890. +
  12891. + @Test
  12892. + public void testSimpleTransformer() {
  12893. +
  12894. + assert HotSwapTool.getCurrentVersion(SimpleTransformerTest.class) == 0;
  12895. +
  12896. + A a = new A();
  12897. +
  12898. + assertEquals(2, a.x);
  12899. +
  12900. + HotSwapTool.toVersion(SimpleTransformerTest.class, 1);
  12901. +
  12902. + assertEquals(4, a.x);
  12903. +
  12904. + HotSwapTool.toVersion(SimpleTransformerTest.class, 0);
  12905. +
  12906. + assertEquals(4, a.x);
  12907. +
  12908. + HotSwapTool.toVersion(SimpleTransformerTest.class, 1);
  12909. +
  12910. + assertEquals(8, a.x);
  12911. +
  12912. + HotSwapTool.toVersion(SimpleTransformerTest.class, 0);
  12913. +
  12914. + assertEquals(8, a.x);
  12915. + }
  12916. +}
  12917. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/transformer/StaticConstructorTransformerTest.java
  12918. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  12919. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/transformer/StaticConstructorTransformerTest.java Fri Dec 17 13:23:04 2010 +0100
  12920. @@ -0,0 +1,86 @@
  12921. +/*
  12922. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  12923. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  12924. + *
  12925. + * This code is free software; you can redistribute it and/or modify it
  12926. + * under the terms of the GNU General Public License version 2 only, as
  12927. + * published by the Free Software Foundation.
  12928. + *
  12929. + * This code is distributed in the hope that it will be useful, but WITHOUT
  12930. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12931. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12932. + * version 2 for more details (a copy is included in the LICENSE file that
  12933. + * accompanied this code).
  12934. + *
  12935. + * You should have received a copy of the GNU General Public License version
  12936. + * 2 along with this work; if not, write to the Free Software Foundation,
  12937. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  12938. + *
  12939. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  12940. + * or visit www.oracle.com if you need additional information or have any
  12941. + * questions.
  12942. + *
  12943. + */
  12944. +package at.ssw.hotswap.test.transformer;
  12945. +
  12946. +import at.ssw.hotswap.HotSwapTool;
  12947. +import org.junit.Before;
  12948. +import org.junit.Test;
  12949. +
  12950. +/**
  12951. + * @author Kerstin Breiteneder
  12952. + * @author Christoph Wimberger
  12953. + */
  12954. +public class StaticConstructorTransformerTest {
  12955. +
  12956. + //Version 0
  12957. + public static class Static_TestClass {
  12958. +
  12959. + // remove static --> no fatal error occurs
  12960. + public static int x = 0;
  12961. + //public int x = 0;
  12962. +
  12963. + static {
  12964. + System.out.println("Start Static_TestClass Version 0");
  12965. +
  12966. + try {
  12967. + Thread.sleep(1000);
  12968. + } catch (InterruptedException ex) {
  12969. + }
  12970. + System.out.println("End Static_TestClass Version 0");
  12971. + }
  12972. + }
  12973. +
  12974. + //Version 1
  12975. + public static class Static_TestClass___1 {
  12976. +
  12977. + public int version = 1;
  12978. +
  12979. + static {
  12980. + System.out.println("Static_TestClass Version 1");
  12981. + }
  12982. +
  12983. + public void $transformer() {
  12984. + System.out.println(":::::::::transformerExecuted:::::::::::");
  12985. + }
  12986. + }
  12987. +
  12988. + @Before
  12989. + public void setUp() throws Exception {
  12990. + HotSwapTool.toVersion(StaticConstructorTransformerTest.class, 0);
  12991. + }
  12992. +
  12993. + @Test
  12994. + public void testStaticConstructorTransformerTest() {
  12995. +
  12996. + assert HotSwapTool.getCurrentVersion(StaticConstructorTransformerTest.class) == 0;
  12997. + try {
  12998. + Class.forName("at.ssw.hotswap.test.transformer.StaticConstructorTransformerTest$Static_TestClass");
  12999. + } catch (ClassNotFoundException ex) {
  13000. + ex.printStackTrace();
  13001. + }
  13002. + Static_TestClass clazz = new Static_TestClass();
  13003. +
  13004. + HotSwapTool.toVersion(StaticConstructorTransformerTest.class, 1);
  13005. + }
  13006. +}
  13007. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/transformer/StaticTransformerTest.java
  13008. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  13009. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/transformer/StaticTransformerTest.java Fri Dec 17 13:23:04 2010 +0100
  13010. @@ -0,0 +1,87 @@
  13011. +/*
  13012. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  13013. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  13014. + *
  13015. + * This code is free software; you can redistribute it and/or modify it
  13016. + * under the terms of the GNU General Public License version 2 only, as
  13017. + * published by the Free Software Foundation.
  13018. + *
  13019. + * This code is distributed in the hope that it will be useful, but WITHOUT
  13020. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13021. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13022. + * version 2 for more details (a copy is included in the LICENSE file that
  13023. + * accompanied this code).
  13024. + *
  13025. + * You should have received a copy of the GNU General Public License version
  13026. + * 2 along with this work; if not, write to the Free Software Foundation,
  13027. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  13028. + *
  13029. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  13030. + * or visit www.oracle.com if you need additional information or have any
  13031. + * questions.
  13032. + *
  13033. + */
  13034. +
  13035. +package at.ssw.hotswap.test.transformer;
  13036. +
  13037. +import static org.junit.Assert.*;
  13038. +
  13039. +import org.junit.Before;
  13040. +import org.junit.Test;
  13041. +
  13042. +import at.ssw.hotswap.HotSwapTool;
  13043. +
  13044. +/**
  13045. + * Tests for executing the transformer of a class.
  13046. + *
  13047. + * @author Thomas Wuerthinger
  13048. + */
  13049. +public class StaticTransformerTest {
  13050. +
  13051. + // Version 0
  13052. + public static class A {
  13053. +
  13054. + public static int x = 2;
  13055. + }
  13056. +
  13057. + // Version 3
  13058. + public static class A___1 {
  13059. +
  13060. + public static int x;
  13061. +
  13062. + public static void $staticTransformer() {
  13063. + System.out.println("Static transformer of A executing...");
  13064. + x = x * 2;
  13065. + }
  13066. + }
  13067. +
  13068. +
  13069. + @Before
  13070. + public void setUp() throws Exception {
  13071. + HotSwapTool.toVersion(StaticTransformerTest.class, 0);
  13072. + }
  13073. +
  13074. + @Test
  13075. + public void testStaticTransformer() {
  13076. +
  13077. + assert HotSwapTool.getCurrentVersion(StaticTransformerTest.class) == 0;
  13078. +
  13079. + assertEquals(2, A.x);
  13080. +
  13081. + HotSwapTool.toVersion(StaticTransformerTest.class, 1);
  13082. +
  13083. + assertEquals(4, A.x);
  13084. +
  13085. + HotSwapTool.toVersion(StaticTransformerTest.class, 0);
  13086. +
  13087. + assertEquals(4, A.x);
  13088. +
  13089. + HotSwapTool.toVersion(StaticTransformerTest.class, 1);
  13090. +
  13091. + assertEquals(8, A.x);
  13092. +
  13093. + HotSwapTool.toVersion(StaticTransformerTest.class, 0);
  13094. +
  13095. + assertEquals(8, A.x);
  13096. + }
  13097. +}
  13098. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/transformer/TransformerTestSuite.java
  13099. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  13100. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/transformer/TransformerTestSuite.java Fri Dec 17 13:23:04 2010 +0100
  13101. @@ -0,0 +1,44 @@
  13102. +/*
  13103. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  13104. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  13105. + *
  13106. + * This code is free software; you can redistribute it and/or modify it
  13107. + * under the terms of the GNU General Public License version 2 only, as
  13108. + * published by the Free Software Foundation.
  13109. + *
  13110. + * This code is distributed in the hope that it will be useful, but WITHOUT
  13111. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13112. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13113. + * version 2 for more details (a copy is included in the LICENSE file that
  13114. + * accompanied this code).
  13115. + *
  13116. + * You should have received a copy of the GNU General Public License version
  13117. + * 2 along with this work; if not, write to the Free Software Foundation,
  13118. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  13119. + *
  13120. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  13121. + * or visit www.oracle.com if you need additional information or have any
  13122. + * questions.
  13123. + *
  13124. + */
  13125. +
  13126. +package at.ssw.hotswap.test.transformer;
  13127. +
  13128. +import org.junit.runner.RunWith;
  13129. +import org.junit.runners.Suite;
  13130. +
  13131. +/**
  13132. + * Class redefinition tests that test the correct execution of transformer methods
  13133. + *
  13134. + * @author Thomas Wuerthinger
  13135. + *
  13136. + */
  13137. +@RunWith(Suite.class)
  13138. +@Suite.SuiteClasses({
  13139. + SimpleTransformerTest.class,
  13140. + BaseClassTransformerTest.class,
  13141. + StaticTransformerTest.class,
  13142. + StaticConstructorTransformerTest.class
  13143. +})
  13144. +public class TransformerTestSuite {
  13145. +}
  13146. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/util/CallingMethodGetter.java
  13147. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  13148. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/util/CallingMethodGetter.java Fri Dec 17 13:23:04 2010 +0100
  13149. @@ -0,0 +1,33 @@
  13150. +/*
  13151. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  13152. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  13153. + *
  13154. + * This code is free software; you can redistribute it and/or modify it
  13155. + * under the terms of the GNU General Public License version 2 only, as
  13156. + * published by the Free Software Foundation.
  13157. + *
  13158. + * This code is distributed in the hope that it will be useful, but WITHOUT
  13159. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13160. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13161. + * version 2 for more details (a copy is included in the LICENSE file that
  13162. + * accompanied this code).
  13163. + *
  13164. + * You should have received a copy of the GNU General Public License version
  13165. + * 2 along with this work; if not, write to the Free Software Foundation,
  13166. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  13167. + *
  13168. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  13169. + * or visit www.oracle.com if you need additional information or have any
  13170. + * questions.
  13171. + *
  13172. + */
  13173. +package at.ssw.hotswap.test.util;
  13174. +
  13175. +/**
  13176. + * @author Kerstin Breiteneder
  13177. + * @author Christoph Wimberger
  13178. + */
  13179. +public interface CallingMethodGetter {
  13180. +
  13181. + public String getCallingMethod();
  13182. +}
  13183. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/util/CallingMethodGetterFactory.java
  13184. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  13185. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/util/CallingMethodGetterFactory.java Fri Dec 17 13:23:04 2010 +0100
  13186. @@ -0,0 +1,47 @@
  13187. +/*
  13188. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  13189. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  13190. + *
  13191. + * This code is free software; you can redistribute it and/or modify it
  13192. + * under the terms of the GNU General Public License version 2 only, as
  13193. + * published by the Free Software Foundation.
  13194. + *
  13195. + * This code is distributed in the hope that it will be useful, but WITHOUT
  13196. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13197. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13198. + * version 2 for more details (a copy is included in the LICENSE file that
  13199. + * accompanied this code).
  13200. + *
  13201. + * You should have received a copy of the GNU General Public License version
  13202. + * 2 along with this work; if not, write to the Free Software Foundation,
  13203. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  13204. + *
  13205. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  13206. + * or visit www.oracle.com if you need additional information or have any
  13207. + * questions.
  13208. + *
  13209. + */
  13210. +package at.ssw.hotswap.test.util;
  13211. +
  13212. +/**
  13213. + * @author Kerstin Breiteneder
  13214. + * @author Christoph Wimberger
  13215. + */
  13216. +public class CallingMethodGetterFactory {
  13217. +
  13218. + public enum CallingMethodType {
  13219. +
  13220. + REFLECTION,
  13221. + JDI
  13222. + }
  13223. +
  13224. + public static CallingMethodGetter create(CallingMethodType type) {
  13225. + if (type == CallingMethodType.REFLECTION) {
  13226. + return new ReflectionCallingMethodGetter();
  13227. + }
  13228. + if (type == CallingMethodType.JDI) {
  13229. + return new JDICallingMethodGetter();
  13230. + }
  13231. + return null;
  13232. + }
  13233. +}
  13234. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/util/JDICallingMethodGetter.java
  13235. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  13236. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/util/JDICallingMethodGetter.java Fri Dec 17 13:23:04 2010 +0100
  13237. @@ -0,0 +1,101 @@
  13238. +/*
  13239. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  13240. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  13241. + *
  13242. + * This code is free software; you can redistribute it and/or modify it
  13243. + * under the terms of the GNU General Public License version 2 only, as
  13244. + * published by the Free Software Foundation.
  13245. + *
  13246. + * This code is distributed in the hope that it will be useful, but WITHOUT
  13247. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13248. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13249. + * version 2 for more details (a copy is included in the LICENSE file that
  13250. + * accompanied this code).
  13251. + *
  13252. + * You should have received a copy of the GNU General Public License version
  13253. + * 2 along with this work; if not, write to the Free Software Foundation,
  13254. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  13255. + *
  13256. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  13257. + * or visit www.oracle.com if you need additional information or have any
  13258. + * questions.
  13259. + *
  13260. + */
  13261. +package at.ssw.hotswap.test.util;
  13262. +
  13263. +import at.ssw.hotswap.JDIProxy;
  13264. +import com.sun.jdi.ClassNotLoadedException;
  13265. +import com.sun.jdi.IncompatibleThreadStateException;
  13266. +import com.sun.jdi.Method;
  13267. +import com.sun.jdi.StackFrame;
  13268. +import com.sun.jdi.ThreadReference;
  13269. +import com.sun.jdi.Type;
  13270. +import java.lang.reflect.Modifier;
  13271. +import java.util.List;
  13272. +
  13273. +/**
  13274. + * @author Kerstin Breiteneder
  13275. + * @author Christoph Wimberger
  13276. + */
  13277. +public class JDICallingMethodGetter implements CallingMethodGetter {
  13278. +
  13279. + @Override
  13280. + public String getCallingMethod() {
  13281. +
  13282. + final StringBuffer methodBuffer = new StringBuffer();
  13283. + final JDIProxy jdi = JDIProxy.getJDI();
  13284. + final Exception[] exception = new Exception[1];
  13285. + exception[0] = null;
  13286. +
  13287. + Runnable r = new Runnable() {
  13288. +
  13289. + public void run() {
  13290. +
  13291. + final List<ThreadReference> threads = jdi.getVM().allThreads();
  13292. + for (ThreadReference t : threads) {
  13293. + if (t.name().equals("main")) {
  13294. + StackFrame stackFrame = null;
  13295. + boolean found = false;
  13296. + try {
  13297. + for (StackFrame s : t.frames()) {
  13298. + if (found) {
  13299. + stackFrame = s;
  13300. + break;
  13301. + }
  13302. + if (s.toString().contains("JDICallingMethodGetter")) {
  13303. + found = true;
  13304. + }
  13305. + }
  13306. + } catch (IncompatibleThreadStateException ex) {
  13307. + exception[0] = ex;
  13308. + }
  13309. +
  13310. + Method method = stackFrame.location().method();
  13311. + String methodString = Modifier.toString(method.modifiers()) + " " + method.name() + "(";
  13312. + boolean paramFound = false;
  13313. + try {
  13314. + for (Type type : method.argumentTypes()) {
  13315. + if (paramFound) {
  13316. + methodString += ", ";
  13317. + }
  13318. + paramFound = true;
  13319. + methodString += type.name();
  13320. + }
  13321. + } catch (ClassNotLoadedException ex) {
  13322. + exception[0] = ex;
  13323. + }
  13324. + methodString += ")";
  13325. + methodBuffer.append(methodString);
  13326. + }
  13327. + }
  13328. + }
  13329. + };
  13330. +
  13331. + jdi.executeSuspended(r);
  13332. + if (exception[0] != null) {
  13333. + throw new RuntimeException(exception[0]);
  13334. + }
  13335. +
  13336. + return methodBuffer.toString();
  13337. + }
  13338. +}
  13339. diff -r f5603a6e5042 hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/util/ReflectionCallingMethodGetter.java
  13340. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  13341. +++ b/hotswaptest/HotSwapTests/src/at/ssw/hotswap/test/util/ReflectionCallingMethodGetter.java Fri Dec 17 13:23:04 2010 +0100
  13342. @@ -0,0 +1,69 @@
  13343. +/*
  13344. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  13345. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  13346. + *
  13347. + * This code is free software; you can redistribute it and/or modify it
  13348. + * under the terms of the GNU General Public License version 2 only, as
  13349. + * published by the Free Software Foundation.
  13350. + *
  13351. + * This code is distributed in the hope that it will be useful, but WITHOUT
  13352. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13353. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13354. + * version 2 for more details (a copy is included in the LICENSE file that
  13355. + * accompanied this code).
  13356. + *
  13357. + * You should have received a copy of the GNU General Public License version
  13358. + * 2 along with this work; if not, write to the Free Software Foundation,
  13359. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  13360. + *
  13361. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  13362. + * or visit www.oracle.com if you need additional information or have any
  13363. + * questions.
  13364. + *
  13365. + */
  13366. +package at.ssw.hotswap.test.util;
  13367. +
  13368. +import java.lang.reflect.Method;
  13369. +import java.lang.reflect.Modifier;
  13370. +
  13371. +/**
  13372. + * @author Kerstin Breiteneder
  13373. + * @author Christoph Wimberger
  13374. + */
  13375. +public class ReflectionCallingMethodGetter implements CallingMethodGetter {
  13376. +
  13377. + @Override
  13378. + public String getCallingMethod() {
  13379. + StackTraceElement stack = Thread.currentThread().getStackTrace()[2];
  13380. + Class clazz = null;
  13381. +
  13382. + try {
  13383. + clazz = Class.forName(stack.getClassName());
  13384. + } catch (ClassNotFoundException ex) {
  13385. + throw new RuntimeException(ex);
  13386. + }
  13387. +
  13388. + Method found = null;
  13389. + for (Method method : clazz.getDeclaredMethods()) {
  13390. + if (method.getName().equals(stack.getMethodName())) {
  13391. + if (found != null) {
  13392. + throw new RuntimeException("ambiguous method name");
  13393. + }
  13394. + found = method;
  13395. + }
  13396. + }
  13397. +
  13398. + String methodString = Modifier.toString(found.getModifiers()) + " " + found.getName() + "(";
  13399. + boolean paramFound = false;
  13400. + for (Class c : found.getParameterTypes()) {
  13401. + if (paramFound) {
  13402. + methodString += ", ";
  13403. + }
  13404. + paramFound = true;
  13405. + methodString += c.getName();
  13406. + }
  13407. + methodString += ")";
  13408. +
  13409. + return methodString;
  13410. + }
  13411. +}
  13412. diff -r f5603a6e5042 hotswaptest/HotSwapTestsNatives/.dep.inc
  13413. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  13414. +++ b/hotswaptest/HotSwapTestsNatives/.dep.inc Fri Dec 17 13:23:04 2010 +0100
  13415. @@ -0,0 +1,5 @@
  13416. +# This code depends on make tool being used
  13417. +DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES}))
  13418. +ifneq (${DEPFILES},)
  13419. +include ${DEPFILES}
  13420. +endif
  13421. diff -r f5603a6e5042 hotswaptest/HotSwapTestsNatives/Makefile
  13422. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  13423. +++ b/hotswaptest/HotSwapTestsNatives/Makefile Fri Dec 17 13:23:04 2010 +0100
  13424. @@ -0,0 +1,109 @@
  13425. +#
  13426. +# There exist several targets which are by default empty and which can be
  13427. +# used for execution of your targets. These targets are usually executed
  13428. +# before and after some main targets. They are:
  13429. +#
  13430. +# .build-pre: called before 'build' target
  13431. +# .build-post: called after 'build' target
  13432. +# .clean-pre: called before 'clean' target
  13433. +# .clean-post: called after 'clean' target
  13434. +# .clobber-pre: called before 'clobber' target
  13435. +# .clobber-post: called after 'clobber' target
  13436. +# .all-pre: called before 'all' target
  13437. +# .all-post: called after 'all' target
  13438. +# .help-pre: called before 'help' target
  13439. +# .help-post: called after 'help' target
  13440. +#
  13441. +# Targets beginning with '.' are not intended to be called on their own.
  13442. +#
  13443. +# Main targets can be executed directly, and they are:
  13444. +#
  13445. +# build build a specific configuration
  13446. +# clean remove built files from a configuration
  13447. +# clobber remove all built files
  13448. +# all build all configurations
  13449. +# help print help mesage
  13450. +#
  13451. +# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and
  13452. +# .help-impl are implemented in nbproject/makefile-impl.mk.
  13453. +#
  13454. +# Available make variables:
  13455. +#
  13456. +# CND_BASEDIR base directory for relative paths
  13457. +# CND_DISTDIR default top distribution directory (build artifacts)
  13458. +# CND_BUILDDIR default top build directory (object files, ...)
  13459. +# CONF name of current configuration
  13460. +# CND_PLATFORM_${CONF} platform name (current configuration)
  13461. +# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration)
  13462. +# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration)
  13463. +# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration)
  13464. +# CND_PACKAGE_DIR_${CONF} directory of package (current configuration)
  13465. +# CND_PACKAGE_NAME_${CONF} name of package (current configuration)
  13466. +# CND_PACKAGE_PATH_${CONF} path to package (current configuration)
  13467. +#
  13468. +# NOCDDL
  13469. +
  13470. +
  13471. +# Environment
  13472. +MKDIR=mkdir
  13473. +CP=cp
  13474. +CCADMIN=CCadmin
  13475. +RANLIB=ranlib
  13476. +
  13477. +
  13478. +# build
  13479. +build: .build-post
  13480. +
  13481. +.build-pre:
  13482. +# Add your pre 'build' code here...
  13483. +
  13484. +.build-post: .build-impl
  13485. +# Add your post 'build' code here...
  13486. +
  13487. +
  13488. +# clean
  13489. +clean: .clean-post
  13490. +
  13491. +.clean-pre:
  13492. +# Add your pre 'clean' code here...
  13493. +
  13494. +.clean-post: .clean-impl
  13495. +# Add your post 'clean' code here...
  13496. +
  13497. +
  13498. +# clobber
  13499. +clobber: .clobber-post
  13500. +
  13501. +.clobber-pre:
  13502. +# Add your pre 'clobber' code here...
  13503. +
  13504. +.clobber-post: .clobber-impl
  13505. +# Add your post 'clobber' code here...
  13506. +
  13507. +
  13508. +# all
  13509. +all: .all-post
  13510. +
  13511. +.all-pre:
  13512. +# Add your pre 'all' code here...
  13513. +
  13514. +.all-post: .all-impl
  13515. +# Add your post 'all' code here...
  13516. +
  13517. +
  13518. +# help
  13519. +help: .help-post
  13520. +
  13521. +.help-pre:
  13522. +# Add your pre 'help' code here...
  13523. +
  13524. +.help-post: .help-impl
  13525. +# Add your post 'help' code here...
  13526. +
  13527. +
  13528. +
  13529. +# include project implementation makefile
  13530. +include nbproject/Makefile-impl.mk
  13531. +
  13532. +# include project make variables
  13533. +include nbproject/Makefile-variables.mk
  13534. diff -r f5603a6e5042 hotswaptest/HotSwapTestsNatives/natives.c
  13535. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  13536. +++ b/hotswaptest/HotSwapTestsNatives/natives.c Fri Dec 17 13:23:04 2010 +0100
  13537. @@ -0,0 +1,174 @@
  13538. +/*
  13539. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  13540. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  13541. + *
  13542. + * This code is free software; you can redistribute it and/or modify it
  13543. + * under the terms of the GNU General Public License version 2 only, as
  13544. + * published by the Free Software Foundation.
  13545. + *
  13546. + * This code is distributed in the hope that it will be useful, but WITHOUT
  13547. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13548. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13549. + * version 2 for more details (a copy is included in the LICENSE file that
  13550. + * accompanied this code).
  13551. + *
  13552. + * You should have received a copy of the GNU General Public License version
  13553. + * 2 along with this work; if not, write to the Free Software Foundation,
  13554. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  13555. + *
  13556. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  13557. + * or visit www.oracle.com if you need additional information or have any
  13558. + * questions.
  13559. + *
  13560. + */
  13561. +
  13562. +#include <stdio.h>
  13563. +#include <jni.h>
  13564. +#include <string.h>
  13565. +#include <stdlib.h>
  13566. +#include "natives.h"
  13567. +
  13568. +JNIEXPORT jint JNICALL Java_at_ssw_hotswap_test_natives_SimpleNativeTest_00024A_value(JNIEnv *env, jclass c) {
  13569. + return 1;
  13570. +}
  13571. +
  13572. +JNIEXPORT jint JNICALL Java_at_ssw_hotswap_test_natives_SimpleNativeTest_00024A_value2(JNIEnv *env, jclass c) {
  13573. + return 2;
  13574. +}
  13575. +
  13576. +JNIEXPORT jclass JNICALL Java_at_ssw_hotswap_test_access_jni_JNIVMAccess_findClassNative(JNIEnv *env, jclass c, jstring s) {
  13577. + const char* name = (*env)->GetStringUTFChars(env, s, 0);
  13578. + jclass clazz = (*env)->FindClass(env, name);
  13579. + (*env)->ReleaseStringUTFChars(env, s, name);
  13580. + return clazz;
  13581. +}
  13582. +
  13583. +JNIEXPORT jobject JNICALL Java_at_ssw_hotswap_test_access_jni_JNIClassAccess_findMethodNative(JNIEnv *env, jclass c, jclass cls, jstring methodName) {
  13584. + const char *methodstr = (*env)->GetStringUTFChars(env, methodName, 0);
  13585. +
  13586. + jclass jCls = (*env)->GetObjectClass(env, cls);
  13587. +
  13588. + // Get Method ID of getMethods()
  13589. + jmethodID midGetFields = (*env)->GetMethodID(env, jCls, "getDeclaredMethods", "()[Ljava/lang/reflect/Method;");
  13590. + (*env)->ExceptionDescribe(env);
  13591. + jobjectArray jobjArray = (jobjectArray) (*env)->CallObjectMethod(env, cls, midGetFields);
  13592. +
  13593. + jsize len = (*env)->GetArrayLength(env, jobjArray);
  13594. + jsize i = 0;
  13595. +
  13596. + for (i = 0; i < len; i++) {
  13597. + jobject _strMethod = (*env)->GetObjectArrayElement(env, jobjArray, i);
  13598. + jclass _methodClazz = (*env)->GetObjectClass(env, _strMethod);
  13599. + jmethodID mid = (*env)->GetMethodID(env, _methodClazz, "getName", "()Ljava/lang/String;");
  13600. + jstring _name = (jstring) (*env)->CallObjectMethod(env, _strMethod, mid);
  13601. +
  13602. + const char *str = (*env)->GetStringUTFChars(env, _name, 0);
  13603. +
  13604. + if (strcmp(str, methodstr) == 0) {
  13605. + (*env)->ReleaseStringUTFChars(env, methodName, methodstr);
  13606. + (*env)->ReleaseStringUTFChars(env, _name, str);
  13607. + return _strMethod;
  13608. + }
  13609. + (*env)->ReleaseStringUTFChars(env, _name, str);
  13610. + }
  13611. +
  13612. + jclass exc = (*env)->FindClass(env, "java/lang/NoSuchMethodError");
  13613. + (*env)->ThrowNew(env, exc, methodstr);
  13614. + (*env)->ReleaseStringUTFChars(env, methodName, methodstr);
  13615. +
  13616. +}
  13617. +
  13618. +JNIEXPORT jobjectArray JNICALL Java_at_ssw_hotswap_test_access_jni_JNIClassAccess_getMethodsNative(JNIEnv *env, jclass c, jclass cls) {
  13619. + jobjectArray array;
  13620. +
  13621. + jclass jCls = (*env)->GetObjectClass(env, cls);
  13622. +
  13623. + // Get Method ID of getMethods()
  13624. + jmethodID midGetFields = (*env)->GetMethodID(env, jCls, "getDeclaredMethods", "()[Ljava/lang/reflect/Method;");
  13625. + (*env)->ExceptionDescribe(env);
  13626. + jobjectArray jobjArray = (jobjectArray) (*env)->CallObjectMethod(env, cls, midGetFields);
  13627. +
  13628. + jsize len = (*env)->GetArrayLength(env, jobjArray);
  13629. + jsize i = 0;
  13630. +
  13631. + array = (*env)->NewObjectArray(env, len, (*env)->FindClass(env, "java/lang/reflect/Method"), 0);
  13632. +
  13633. + for (i = 0; i < len; i++) {
  13634. + jobject _strMethod = (*env)->GetObjectArrayElement(env, jobjArray, i);
  13635. + (*env)->SetObjectArrayElement(env, array, i, _strMethod);
  13636. + }
  13637. +
  13638. + return array;
  13639. +}
  13640. +
  13641. +jobject callVoidMethod(JNIEnv *env, jobject obj, jboolean staticValue, jmethodID methodID, jvalue *params) {
  13642. + if (staticValue) {
  13643. + (*env)->CallStaticVoidMethodA(env, obj, methodID, params);
  13644. + } else {
  13645. + (*env)->CallVoidMethodA(env, obj, methodID, params);
  13646. + }
  13647. + return (*env)->NewGlobalRef(env, NULL);
  13648. +}
  13649. +
  13650. +jobject callIntMethod(JNIEnv *env, jobject obj, jboolean staticValue, jmethodID methodID, jvalue *params) {
  13651. + jint intValue;
  13652. + if (staticValue) {
  13653. + intValue = (*env)->CallStaticIntMethodA(env, obj, methodID, params);
  13654. + } else {
  13655. + intValue = (*env)->CallIntMethodA(env, obj, methodID, params);
  13656. + }
  13657. + jclass clazz = (*env)->FindClass(env, "Ljava/lang/Integer;");
  13658. + jmethodID methodIDInteger = (*env)->GetMethodID(env, clazz, "<init>", "(I)V");
  13659. + return (*env)->NewObject(env, clazz, methodIDInteger, intValue);
  13660. +}
  13661. +
  13662. +jobject callObjectMethod(JNIEnv *env, jobject obj, jboolean staticValue, jmethodID methodID, jvalue *params) {
  13663. + if (staticValue) {
  13664. + return (*env)->CallStaticObjectMethodA(env, obj, methodID, params);
  13665. + } else {
  13666. + return (*env)->CallObjectMethodA(env, obj, methodID, params);
  13667. + }
  13668. +}
  13669. +
  13670. +JNIEXPORT jobject JNICALL Java_at_ssw_hotswap_test_access_jni_JNIMethodAccess_invokeMethodNative(JNIEnv *env, jclass c, jclass cls, jobject obj, jstring methodName, jstring retValue, jboolean staticValue, jstring descriptor, jobjectArray params) {
  13671. + const char *methodstr = (*env)->GetStringUTFChars(env, methodName, 0);
  13672. + const char *descriptorstr = (*env)->GetStringUTFChars(env, descriptor, 0);
  13673. + const char *retValuestr = (*env)->GetStringUTFChars(env, retValue, 0);
  13674. +
  13675. + jmethodID methodID;
  13676. + if (staticValue) {
  13677. + methodID = (*env)->GetStaticMethodID(env, cls, methodstr, descriptorstr);
  13678. + } else {
  13679. + methodID = (*env)->GetMethodID(env, cls, methodstr, descriptorstr);
  13680. + }
  13681. +
  13682. + jsize len = (*env)->GetArrayLength(env, params);
  13683. + jvalue *m = (jvalue*) malloc(sizeof (jvalue) * len);
  13684. +
  13685. + jvalue *mm = m;
  13686. + int i = 0;
  13687. + for (i; i < len; i++) {
  13688. + *mm = (jvalue)(*env)->GetObjectArrayElement(env, params, i);
  13689. + mm += 1;
  13690. + }
  13691. +
  13692. + jobject object = (*env)->NewGlobalRef(env, NULL);
  13693. +
  13694. + if (strcmp(retValuestr, "void") == 0) {
  13695. + object = callVoidMethod(env, obj, staticValue, methodID, m);
  13696. + } else if (strcmp(retValuestr, "int") == 0) {
  13697. + object = callIntMethod(env, obj, staticValue, methodID, m);
  13698. + } else if (strcmp(retValuestr, "java.lang.Object") == 0) {
  13699. + object = callObjectMethod(env, obj, staticValue, methodID, m);
  13700. + } else {
  13701. + jclass exc = (*env)->FindClass(env, "java.lang.NotImplementedException");
  13702. + (*env)->ThrowNew(env, exc, "required retValue: bool/int/object");
  13703. + }
  13704. +
  13705. + (*env)->ReleaseStringUTFChars(env, methodName, methodstr);
  13706. + (*env)->ReleaseStringUTFChars(env, descriptor, descriptorstr);
  13707. + (*env)->ReleaseStringUTFChars(env, retValue, retValuestr);
  13708. +
  13709. + return object;
  13710. +}
  13711. +
  13712. diff -r f5603a6e5042 hotswaptest/HotSwapTestsNatives/natives.h
  13713. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  13714. +++ b/hotswaptest/HotSwapTestsNatives/natives.h Fri Dec 17 13:23:04 2010 +0100
  13715. @@ -0,0 +1,72 @@
  13716. +/*
  13717. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  13718. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  13719. + *
  13720. + * This code is free software; you can redistribute it and/or modify it
  13721. + * under the terms of the GNU General Public License version 2 only, as
  13722. + * published by the Free Software Foundation.
  13723. + *
  13724. + * This code is distributed in the hope that it will be useful, but WITHOUT
  13725. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13726. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13727. + * version 2 for more details (a copy is included in the LICENSE file that
  13728. + * accompanied this code).
  13729. + *
  13730. + * You should have received a copy of the GNU General Public License version
  13731. + * 2 along with this work; if not, write to the Free Software Foundation,
  13732. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  13733. + *
  13734. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  13735. + * or visit www.oracle.com if you need additional information or have any
  13736. + * questions.
  13737. + *
  13738. + */
  13739. +
  13740. +#include <jni.h>
  13741. +
  13742. +#ifndef NATIVES
  13743. +#define NATIVES
  13744. +
  13745. +/*
  13746. + * Class: at_ssw_hotswap_test_natives_SimpleNativeTest_A
  13747. + * Method: value
  13748. + * Signature: ()I
  13749. + */
  13750. +JNIEXPORT jint JNICALL Java_at_ssw_hotswap_test_natives_SimpleNativeTest_00024A_value(JNIEnv *, jclass);
  13751. +
  13752. +/*
  13753. + * Class: at_ssw_hotswap_test_natives_SimpleNativeTest_A
  13754. + * Method: value2
  13755. + * Signature: ()I
  13756. + */
  13757. +JNIEXPORT jint JNICALL Java_at_ssw_hotswap_test_natives_SimpleNativeTest_00024A_value2(JNIEnv *, jclass);
  13758. +
  13759. +/*
  13760. + * Class: at_ssw_hotswap_test_access_jni_JNIVMAccess
  13761. + * Method: findClass
  13762. + * Signature: (String)Class
  13763. + */
  13764. +JNIEXPORT jclass JNICALL Java_at_ssw_hotswap_test_access_jni_JNIVMAccess_findClassNative(JNIEnv *, jclass, jstring);
  13765. +
  13766. +/*
  13767. + * Class: at_ssw_hotswap_test_access_jni_JNIClassAccess
  13768. + * Method: findMethod
  13769. + * Signature: (Class, String)Object
  13770. + */
  13771. +JNIEXPORT jobject JNICALL Java_at_ssw_hotswap_test_access_jni_JNIClassAccess_findMethodNative(JNIEnv *, jclass, jclass, jstring);
  13772. +
  13773. +/*
  13774. + * Class: at_ssw_hotswap_test_access_jni_JNIClassAccess
  13775. + * Method: getMethods
  13776. + * Signature: (Class)Object[]
  13777. + */
  13778. +JNIEXPORT jobjectArray JNICALL Java_at_ssw_hotswap_test_access_jni_JNIClassAccess_getMethodsNative(JNIEnv *, jclass, jclass);
  13779. +
  13780. +/*
  13781. + * Class: at_ssw_hotswap_test_access_jni_JNIMethodAccess
  13782. + * Method: invokeMethod
  13783. + * Signature: (Class, String, Object)Value
  13784. + */
  13785. +JNIEXPORT jobject JNICALL Java_at_ssw_hotswap_test_access_jni_JNIMethodAccess_invokeMethod(JNIEnv *, jclass, jclass, jobject, jstring, jstring, jboolean, jstring);
  13786. +
  13787. +#endif
  13788. diff -r f5603a6e5042 hotswaptest/HotSwapTestsNatives/nbproject/Makefile-Debug.mk
  13789. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  13790. +++ b/hotswaptest/HotSwapTestsNatives/nbproject/Makefile-Debug.mk Fri Dec 17 13:23:04 2010 +0100
  13791. @@ -0,0 +1,79 @@
  13792. +#
  13793. +# Generated Makefile - do not edit!
  13794. +#
  13795. +# Edit the Makefile in the project folder instead (../Makefile). Each target
  13796. +# has a -pre and a -post target defined where you can add customized code.
  13797. +#
  13798. +# This makefile implements configuration specific macros and targets.
  13799. +
  13800. +
  13801. +# Environment
  13802. +MKDIR=mkdir
  13803. +CP=cp
  13804. +CCADMIN=CCadmin
  13805. +RANLIB=ranlib
  13806. +CC=gcc.exe
  13807. +CCC=g++.exe
  13808. +CXX=g++.exe
  13809. +FC=
  13810. +AS=as.exe
  13811. +
  13812. +# Macros
  13813. +CND_PLATFORM=MinGW-Windows
  13814. +CND_CONF=Debug
  13815. +CND_DISTDIR=dist
  13816. +
  13817. +# Include project Makefile
  13818. +include Makefile
  13819. +
  13820. +# Object Directory
  13821. +OBJECTDIR=build/${CND_CONF}/${CND_PLATFORM}
  13822. +
  13823. +# Object Files
  13824. +OBJECTFILES= \
  13825. + ${OBJECTDIR}/natives.o
  13826. +
  13827. +# C Compiler Flags
  13828. +CFLAGS=
  13829. +
  13830. +# CC Compiler Flags
  13831. +CCFLAGS=
  13832. +CXXFLAGS=
  13833. +
  13834. +# Fortran Compiler Flags
  13835. +FFLAGS=
  13836. +
  13837. +# Assembler Flags
  13838. +ASFLAGS=
  13839. +
  13840. +# Link Libraries and Options
  13841. +LDLIBSOPTIONS=
  13842. +
  13843. +# Build Targets
  13844. +.build-conf: ${BUILD_SUBPROJECTS}
  13845. + ${MAKE} -f nbproject/Makefile-Debug.mk dist/libHotSwapTestsNatives.dll
  13846. +
  13847. +dist/libHotSwapTestsNatives.dll: ${OBJECTFILES}
  13848. + ${MKDIR} -p dist
  13849. + ${LINK.c} -Wl,--add-stdcall-alias -shared -o ${CND_DISTDIR}/libHotSwapTestsNatives.dll ${OBJECTFILES} ${LDLIBSOPTIONS}
  13850. +
  13851. +${OBJECTDIR}/natives.o: nbproject/Makefile-${CND_CONF}.mk natives.c
  13852. + ${MKDIR} -p ${OBJECTDIR}
  13853. + ${RM} $@.d
  13854. + $(COMPILE.c) -g -MMD -MP -MF $@.d -o ${OBJECTDIR}/natives.o natives.c
  13855. +
  13856. +# Subprojects
  13857. +.build-subprojects:
  13858. +
  13859. +# Clean Targets
  13860. +.clean-conf: ${CLEAN_SUBPROJECTS}
  13861. + ${RM} -r build/Debug
  13862. + ${RM} dist/libHotSwapTestsNatives.dll
  13863. +
  13864. +# Subprojects
  13865. +.clean-subprojects:
  13866. +
  13867. +# Enable dependency checking
  13868. +.dep.inc: .depcheck-impl
  13869. +
  13870. +include .dep.inc
  13871. diff -r f5603a6e5042 hotswaptest/HotSwapTestsNatives/nbproject/Makefile-Release.mk
  13872. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  13873. +++ b/hotswaptest/HotSwapTestsNatives/nbproject/Makefile-Release.mk Fri Dec 17 13:23:04 2010 +0100
  13874. @@ -0,0 +1,79 @@
  13875. +#
  13876. +# Generated Makefile - do not edit!
  13877. +#
  13878. +# Edit the Makefile in the project folder instead (../Makefile). Each target
  13879. +# has a -pre and a -post target defined where you can add customized code.
  13880. +#
  13881. +# This makefile implements configuration specific macros and targets.
  13882. +
  13883. +
  13884. +# Environment
  13885. +MKDIR=mkdir
  13886. +CP=cp
  13887. +CCADMIN=CCadmin
  13888. +RANLIB=ranlib
  13889. +CC=gcc.exe
  13890. +CCC=g++.exe
  13891. +CXX=g++.exe
  13892. +FC=
  13893. +AS=as.exe
  13894. +
  13895. +# Macros
  13896. +CND_PLATFORM=MinGW-Windows
  13897. +CND_CONF=Release
  13898. +CND_DISTDIR=dist
  13899. +
  13900. +# Include project Makefile
  13901. +include Makefile
  13902. +
  13903. +# Object Directory
  13904. +OBJECTDIR=build/${CND_CONF}/${CND_PLATFORM}
  13905. +
  13906. +# Object Files
  13907. +OBJECTFILES= \
  13908. + ${OBJECTDIR}/natives.o
  13909. +
  13910. +# C Compiler Flags
  13911. +CFLAGS=
  13912. +
  13913. +# CC Compiler Flags
  13914. +CCFLAGS=
  13915. +CXXFLAGS=
  13916. +
  13917. +# Fortran Compiler Flags
  13918. +FFLAGS=
  13919. +
  13920. +# Assembler Flags
  13921. +ASFLAGS=
  13922. +
  13923. +# Link Libraries and Options
  13924. +LDLIBSOPTIONS=
  13925. +
  13926. +# Build Targets
  13927. +.build-conf: ${BUILD_SUBPROJECTS}
  13928. + ${MAKE} -f nbproject/Makefile-Release.mk dist/libHotSwapTestsNatives.dll
  13929. +
  13930. +dist/libHotSwapTestsNatives.dll: ${OBJECTFILES}
  13931. + ${MKDIR} -p dist
  13932. + ${LINK.c} -Wl,--add-stdcall-alias -shared -o ${CND_DISTDIR}/libHotSwapTestsNatives.dll -s ${OBJECTFILES} ${LDLIBSOPTIONS}
  13933. +
  13934. +${OBJECTDIR}/natives.o: nbproject/Makefile-${CND_CONF}.mk natives.c
  13935. + ${MKDIR} -p ${OBJECTDIR}
  13936. + ${RM} $@.d
  13937. + $(COMPILE.c) -O2 -MMD -MP -MF $@.d -o ${OBJECTDIR}/natives.o natives.c
  13938. +
  13939. +# Subprojects
  13940. +.build-subprojects:
  13941. +
  13942. +# Clean Targets
  13943. +.clean-conf: ${CLEAN_SUBPROJECTS}
  13944. + ${RM} -r build/Release
  13945. + ${RM} dist/libHotSwapTestsNatives.dll
  13946. +
  13947. +# Subprojects
  13948. +.clean-subprojects:
  13949. +
  13950. +# Enable dependency checking
  13951. +.dep.inc: .depcheck-impl
  13952. +
  13953. +include .dep.inc
  13954. diff -r f5603a6e5042 hotswaptest/HotSwapTestsNatives/nbproject/Makefile-impl.mk
  13955. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  13956. +++ b/hotswaptest/HotSwapTestsNatives/nbproject/Makefile-impl.mk Fri Dec 17 13:23:04 2010 +0100
  13957. @@ -0,0 +1,123 @@
  13958. +#
  13959. +# Generated Makefile - do not edit!
  13960. +#
  13961. +# Edit the Makefile in the project folder instead (../Makefile). Each target
  13962. +# has a pre- and a post- target defined where you can add customization code.
  13963. +#
  13964. +# This makefile implements macros and targets common to all configurations.
  13965. +#
  13966. +# NOCDDL
  13967. +
  13968. +
  13969. +# Building and Cleaning subprojects are done by default, but can be controlled with the SUB
  13970. +# macro. If SUB=no, subprojects will not be built or cleaned. The following macro
  13971. +# statements set BUILD_SUB-CONF and CLEAN_SUB-CONF to .build-reqprojects-conf
  13972. +# and .clean-reqprojects-conf unless SUB has the value 'no'
  13973. +SUB_no=NO
  13974. +SUBPROJECTS=${SUB_${SUB}}
  13975. +BUILD_SUBPROJECTS_=.build-subprojects
  13976. +BUILD_SUBPROJECTS_NO=
  13977. +BUILD_SUBPROJECTS=${BUILD_SUBPROJECTS_${SUBPROJECTS}}
  13978. +CLEAN_SUBPROJECTS_=.clean-subprojects
  13979. +CLEAN_SUBPROJECTS_NO=
  13980. +CLEAN_SUBPROJECTS=${CLEAN_SUBPROJECTS_${SUBPROJECTS}}
  13981. +
  13982. +
  13983. +# Project Name
  13984. +PROJECTNAME=HotSwapTestsNatives
  13985. +
  13986. +# Active Configuration
  13987. +DEFAULTCONF=Debug
  13988. +CONF=${DEFAULTCONF}
  13989. +
  13990. +# All Configurations
  13991. +ALLCONFS=Debug Release
  13992. +
  13993. +
  13994. +# build
  13995. +.build-impl: .build-pre .validate-impl .depcheck-impl
  13996. + @#echo "=> Running $@... Configuration=$(CONF)"
  13997. + ${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf
  13998. +
  13999. +
  14000. +# clean
  14001. +.clean-impl: .clean-pre .validate-impl .depcheck-impl
  14002. + @#echo "=> Running $@... Configuration=$(CONF)"
  14003. + ${MAKE} -f nbproject/Makefile-${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf
  14004. +
  14005. +
  14006. +# clobber
  14007. +.clobber-impl: .clobber-pre .depcheck-impl
  14008. + @#echo "=> Running $@..."
  14009. + for CONF in ${ALLCONFS}; \
  14010. + do \
  14011. + ${MAKE} -f nbproject/Makefile-$${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .clean-conf; \
  14012. + done
  14013. +
  14014. +# all
  14015. +.all-impl: .all-pre .depcheck-impl
  14016. + @#echo "=> Running $@..."
  14017. + for CONF in ${ALLCONFS}; \
  14018. + do \
  14019. + ${MAKE} -f nbproject/Makefile-$${CONF}.mk SUBPROJECTS=${SUBPROJECTS} .build-conf; \
  14020. + done
  14021. +
  14022. +# dependency checking support
  14023. +.depcheck-impl:
  14024. + @echo "# This code depends on make tool being used" >.dep.inc
  14025. + @if [ -n "${MAKE_VERSION}" ]; then \
  14026. + echo "DEPFILES=\$$(wildcard \$$(addsuffix .d, \$${OBJECTFILES}))" >>.dep.inc; \
  14027. + echo "ifneq (\$${DEPFILES},)" >>.dep.inc; \
  14028. + echo "include \$${DEPFILES}" >>.dep.inc; \
  14029. + echo "endif" >>.dep.inc; \
  14030. + else \
  14031. + echo ".KEEP_STATE:" >>.dep.inc; \
  14032. + echo ".KEEP_STATE_FILE:.make.state.\$${CONF}" >>.dep.inc; \
  14033. + fi
  14034. +
  14035. +# configuration validation
  14036. +.validate-impl:
  14037. + @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \
  14038. + then \
  14039. + echo ""; \
  14040. + echo "Error: can not find the makefile for configuration '${CONF}' in project ${PROJECTNAME}"; \
  14041. + echo "See 'make help' for details."; \
  14042. + echo "Current directory: " `pwd`; \
  14043. + echo ""; \
  14044. + fi
  14045. + @if [ ! -f nbproject/Makefile-${CONF}.mk ]; \
  14046. + then \
  14047. + exit 1; \
  14048. + fi
  14049. +
  14050. +
  14051. +# help
  14052. +.help-impl: .help-pre
  14053. + @echo "This makefile supports the following configurations:"
  14054. + @echo " ${ALLCONFS}"
  14055. + @echo ""
  14056. + @echo "and the following targets:"
  14057. + @echo " build (default target)"
  14058. + @echo " clean"
  14059. + @echo " clobber"
  14060. + @echo " all"
  14061. + @echo " help"
  14062. + @echo ""
  14063. + @echo "Makefile Usage:"
  14064. + @echo " make [CONF=<CONFIGURATION>] [SUB=no] build"
  14065. + @echo " make [CONF=<CONFIGURATION>] [SUB=no] clean"
  14066. + @echo " make [SUB=no] clobber"
  14067. + @echo " make [SUB=no] all"
  14068. + @echo " make help"
  14069. + @echo ""
  14070. + @echo "Target 'build' will build a specific configuration and, unless 'SUB=no',"
  14071. + @echo " also build subprojects."
  14072. + @echo "Target 'clean' will clean a specific configuration and, unless 'SUB=no',"
  14073. + @echo " also clean subprojects."
  14074. + @echo "Target 'clobber' will remove all built files from all configurations and,"
  14075. + @echo " unless 'SUB=no', also from subprojects."
  14076. + @echo "Target 'all' will will build all configurations and, unless 'SUB=no',"
  14077. + @echo " also build subprojects."
  14078. + @echo "Target 'help' prints this message."
  14079. + @echo ""
  14080. +
  14081. diff -r f5603a6e5042 hotswaptest/HotSwapTestsNatives/nbproject/Makefile-variables.mk
  14082. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  14083. +++ b/hotswaptest/HotSwapTestsNatives/nbproject/Makefile-variables.mk Fri Dec 17 13:23:04 2010 +0100
  14084. @@ -0,0 +1,24 @@
  14085. +#
  14086. +# Generated - do not edit!
  14087. +#
  14088. +# NOCDDL
  14089. +#
  14090. +CND_BASEDIR=`pwd`
  14091. +CND_BUILDDIR=build
  14092. +CND_DISTDIR=dist
  14093. +# Debug configuration
  14094. +CND_PLATFORM_Debug=MinGW-Windows
  14095. +CND_ARTIFACT_DIR_Debug=dist
  14096. +CND_ARTIFACT_NAME_Debug=libHotSwapTestsNatives.dll
  14097. +CND_ARTIFACT_PATH_Debug=dist/libHotSwapTestsNatives.dll
  14098. +CND_PACKAGE_DIR_Debug=dist/Debug/MinGW-Windows/package
  14099. +CND_PACKAGE_NAME_Debug=libHotSwapTestsNatives.dll.tar
  14100. +CND_PACKAGE_PATH_Debug=dist/Debug/MinGW-Windows/package/libHotSwapTestsNatives.dll.tar
  14101. +# Release configuration
  14102. +CND_PLATFORM_Release=MinGW-Windows
  14103. +CND_ARTIFACT_DIR_Release=dist
  14104. +CND_ARTIFACT_NAME_Release=libHotSwapTestsNatives.dll
  14105. +CND_ARTIFACT_PATH_Release=dist/libHotSwapTestsNatives.dll
  14106. +CND_PACKAGE_DIR_Release=dist/Release/MinGW-Windows/package
  14107. +CND_PACKAGE_NAME_Release=libHotSwapTestsNatives.dll.tar
  14108. +CND_PACKAGE_PATH_Release=dist/Release/MinGW-Windows/package/libHotSwapTestsNatives.dll.tar
  14109. diff -r f5603a6e5042 hotswaptest/HotSwapTestsNatives/nbproject/Package-Debug.bash
  14110. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  14111. +++ b/hotswaptest/HotSwapTestsNatives/nbproject/Package-Debug.bash Fri Dec 17 13:23:04 2010 +0100
  14112. @@ -0,0 +1,74 @@
  14113. +#!/bin/bash -x
  14114. +
  14115. +#
  14116. +# Generated - do not edit!
  14117. +#
  14118. +
  14119. +# Macros
  14120. +TOP=`pwd`
  14121. +CND_PLATFORM=MinGW-Windows
  14122. +CND_CONF=Debug
  14123. +CND_DISTDIR=dist
  14124. +TMPDIR=build/${CND_CONF}/${CND_PLATFORM}/tmp-packaging
  14125. +TMPDIRNAME=tmp-packaging
  14126. +OUTPUT_PATH=${CND_DISTDIR}/libHotSwapTestsNatives.dll
  14127. +OUTPUT_BASENAME=libHotSwapTestsNatives.dll
  14128. +PACKAGE_TOP_DIR=libHotSwapTestsNatives.dll/
  14129. +
  14130. +# Functions
  14131. +function checkReturnCode
  14132. +{
  14133. + rc=$?
  14134. + if [ $rc != 0 ]
  14135. + then
  14136. + exit $rc
  14137. + fi
  14138. +}
  14139. +function makeDirectory
  14140. +# $1 directory path
  14141. +# $2 permission (optional)
  14142. +{
  14143. + mkdir -p "$1"
  14144. + checkReturnCode
  14145. + if [ "$2" != "" ]
  14146. + then
  14147. + chmod $2 "$1"
  14148. + checkReturnCode
  14149. + fi
  14150. +}
  14151. +function copyFileToTmpDir
  14152. +# $1 from-file path
  14153. +# $2 to-file path
  14154. +# $3 permission
  14155. +{
  14156. + cp "$1" "$2"
  14157. + checkReturnCode
  14158. + if [ "$3" != "" ]
  14159. + then
  14160. + chmod $3 "$2"
  14161. + checkReturnCode
  14162. + fi
  14163. +}
  14164. +
  14165. +# Setup
  14166. +cd "${TOP}"
  14167. +mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package
  14168. +rm -rf ${TMPDIR}
  14169. +mkdir -p ${TMPDIR}
  14170. +
  14171. +# Copy files and create directories and links
  14172. +cd "${TOP}"
  14173. +makeDirectory ${TMPDIR}/libHotSwapTestsNatives.dll/lib
  14174. +copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}lib/${OUTPUT_BASENAME}" 0644
  14175. +
  14176. +
  14177. +# Generate tar file
  14178. +cd "${TOP}"
  14179. +rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/libHotSwapTestsNatives.dll.tar
  14180. +cd ${TMPDIR}
  14181. +tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/libHotSwapTestsNatives.dll.tar *
  14182. +checkReturnCode
  14183. +
  14184. +# Cleanup
  14185. +cd "${TOP}"
  14186. +rm -rf ${TMPDIR}
  14187. diff -r f5603a6e5042 hotswaptest/HotSwapTestsNatives/nbproject/Package-Release.bash
  14188. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  14189. +++ b/hotswaptest/HotSwapTestsNatives/nbproject/Package-Release.bash Fri Dec 17 13:23:04 2010 +0100
  14190. @@ -0,0 +1,74 @@
  14191. +#!/bin/bash -x
  14192. +
  14193. +#
  14194. +# Generated - do not edit!
  14195. +#
  14196. +
  14197. +# Macros
  14198. +TOP=`pwd`
  14199. +CND_PLATFORM=MinGW-Windows
  14200. +CND_CONF=Release
  14201. +CND_DISTDIR=dist
  14202. +TMPDIR=build/${CND_CONF}/${CND_PLATFORM}/tmp-packaging
  14203. +TMPDIRNAME=tmp-packaging
  14204. +OUTPUT_PATH=${CND_DISTDIR}/libHotSwapTestsNatives.dll
  14205. +OUTPUT_BASENAME=libHotSwapTestsNatives.dll
  14206. +PACKAGE_TOP_DIR=libHotSwapTestsNatives.dll/
  14207. +
  14208. +# Functions
  14209. +function checkReturnCode
  14210. +{
  14211. + rc=$?
  14212. + if [ $rc != 0 ]
  14213. + then
  14214. + exit $rc
  14215. + fi
  14216. +}
  14217. +function makeDirectory
  14218. +# $1 directory path
  14219. +# $2 permission (optional)
  14220. +{
  14221. + mkdir -p "$1"
  14222. + checkReturnCode
  14223. + if [ "$2" != "" ]
  14224. + then
  14225. + chmod $2 "$1"
  14226. + checkReturnCode
  14227. + fi
  14228. +}
  14229. +function copyFileToTmpDir
  14230. +# $1 from-file path
  14231. +# $2 to-file path
  14232. +# $3 permission
  14233. +{
  14234. + cp "$1" "$2"
  14235. + checkReturnCode
  14236. + if [ "$3" != "" ]
  14237. + then
  14238. + chmod $3 "$2"
  14239. + checkReturnCode
  14240. + fi
  14241. +}
  14242. +
  14243. +# Setup
  14244. +cd "${TOP}"
  14245. +mkdir -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package
  14246. +rm -rf ${TMPDIR}
  14247. +mkdir -p ${TMPDIR}
  14248. +
  14249. +# Copy files and create directories and links
  14250. +cd "${TOP}"
  14251. +makeDirectory ${TMPDIR}/libHotSwapTestsNatives.dll/lib
  14252. +copyFileToTmpDir "${OUTPUT_PATH}" "${TMPDIR}/${PACKAGE_TOP_DIR}lib/${OUTPUT_BASENAME}" 0644
  14253. +
  14254. +
  14255. +# Generate tar file
  14256. +cd "${TOP}"
  14257. +rm -f ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/libHotSwapTestsNatives.dll.tar
  14258. +cd ${TMPDIR}
  14259. +tar -vcf ../../../../${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/package/libHotSwapTestsNatives.dll.tar *
  14260. +checkReturnCode
  14261. +
  14262. +# Cleanup
  14263. +cd "${TOP}"
  14264. +rm -rf ${TMPDIR}
  14265. diff -r f5603a6e5042 hotswaptest/HotSwapTestsNatives/nbproject/configurations.xml
  14266. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  14267. +++ b/hotswaptest/HotSwapTestsNatives/nbproject/configurations.xml Fri Dec 17 13:23:04 2010 +0100
  14268. @@ -0,0 +1,67 @@
  14269. +<?xml version="1.0" encoding="UTF-8"?>
  14270. +<configurationDescriptor version="62">
  14271. + <logicalFolder name="root" displayName="root" projectFiles="true">
  14272. + <logicalFolder name="HeaderFiles"
  14273. + displayName="Header Files"
  14274. + projectFiles="true">
  14275. + <itemPath>natives.h</itemPath>
  14276. + </logicalFolder>
  14277. + <logicalFolder name="ResourceFiles"
  14278. + displayName="Resource Files"
  14279. + projectFiles="true">
  14280. + </logicalFolder>
  14281. + <logicalFolder name="SourceFiles"
  14282. + displayName="Source Files"
  14283. + projectFiles="true">
  14284. + <itemPath>natives.c</itemPath>
  14285. + </logicalFolder>
  14286. + <logicalFolder name="ExternalFiles"
  14287. + displayName="Important Files"
  14288. + projectFiles="false">
  14289. + <itemPath>Makefile</itemPath>
  14290. + </logicalFolder>
  14291. + </logicalFolder>
  14292. + <projectmakefile>Makefile</projectmakefile>
  14293. + <confs>
  14294. + <conf name="Debug" type="2">
  14295. + <toolsSet>
  14296. + <developmentServer>localhost</developmentServer>
  14297. + <compilerSet>MinGW|MinGW</compilerSet>
  14298. + <platform>3</platform>
  14299. + </toolsSet>
  14300. + <compileType>
  14301. + <linkerTool>
  14302. + <output>${CND_DISTDIR}/libHotSwapTestsNatives.dll</output>
  14303. + <linkerLibItems>
  14304. + </linkerLibItems>
  14305. + <commandLine>-Wl,--add-stdcall-alias</commandLine>
  14306. + </linkerTool>
  14307. + </compileType>
  14308. + </conf>
  14309. + <conf name="Release" type="2">
  14310. + <toolsSet>
  14311. + <developmentServer>localhost</developmentServer>
  14312. + <compilerSet>MinGW|MinGW</compilerSet>
  14313. + <platform>3</platform>
  14314. + </toolsSet>
  14315. + <compileType>
  14316. + <cTool>
  14317. + <developmentMode>5</developmentMode>
  14318. + </cTool>
  14319. + <ccTool>
  14320. + <developmentMode>5</developmentMode>
  14321. + </ccTool>
  14322. + <fortranCompilerTool>
  14323. + <developmentMode>5</developmentMode>
  14324. + </fortranCompilerTool>
  14325. + <linkerTool>
  14326. + <output>${CND_DISTDIR}/libHotSwapTestsNatives.dll</output>
  14327. + <stripSymbols>true</stripSymbols>
  14328. + <linkerLibItems>
  14329. + </linkerLibItems>
  14330. + <commandLine>-Wl,--add-stdcall-alias</commandLine>
  14331. + </linkerTool>
  14332. + </compileType>
  14333. + </conf>
  14334. + </confs>
  14335. +</configurationDescriptor>
  14336. diff -r f5603a6e5042 hotswaptest/HotSwapTestsNatives/nbproject/project.xml
  14337. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  14338. +++ b/hotswaptest/HotSwapTestsNatives/nbproject/project.xml Fri Dec 17 13:23:04 2010 +0100
  14339. @@ -0,0 +1,15 @@
  14340. +<?xml version="1.0" encoding="UTF-8"?>
  14341. +<project xmlns="http://www.netbeans.org/ns/project/1">
  14342. + <type>org.netbeans.modules.cnd.makeproject</type>
  14343. + <configuration>
  14344. + <data xmlns="http://www.netbeans.org/ns/make-project/1">
  14345. + <name>HotSwapTestsNatives</name>
  14346. + <make-project-type>0</make-project-type>
  14347. + <c-extensions>c</c-extensions>
  14348. + <cpp-extensions/>
  14349. + <header-extensions>h</header-extensions>
  14350. + <sourceEncoding>UTF-8</sourceEncoding>
  14351. + <make-dep-projects/>
  14352. + </data>
  14353. + </configuration>
  14354. +</project>
  14355. diff -r f5603a6e5042 hotswaptest/HotSwapTool/build.xml
  14356. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  14357. +++ b/hotswaptest/HotSwapTool/build.xml Fri Dec 17 13:23:04 2010 +0100
  14358. @@ -0,0 +1,74 @@
  14359. +<?xml version="1.0" encoding="UTF-8"?>
  14360. +<!-- You may freely edit this file. See commented blocks below for -->
  14361. +<!-- some examples of how to customize the build. -->
  14362. +<!-- (If you delete it and reopen the project it will be recreated.) -->
  14363. +<!-- By default, only the Clean and Build commands use this build script. -->
  14364. +<!-- Commands such as Run, Debug, and Test only use this build script if -->
  14365. +<!-- the Compile on Save feature is turned off for the project. -->
  14366. +<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
  14367. +<!-- in the project's Project Properties dialog box.-->
  14368. +<project name="HotSwapTool" default="default" basedir=".">
  14369. + <description>Builds, tests, and runs the project HotSwapTool.</description>
  14370. + <import file="nbproject/build-impl.xml"/>
  14371. + <!--
  14372. +
  14373. + There exist several targets which are by default empty and which can be
  14374. + used for execution of your tasks. These targets are usually executed
  14375. + before and after some main targets. They are:
  14376. +
  14377. + -pre-init: called before initialization of project properties
  14378. + -post-init: called after initialization of project properties
  14379. + -pre-compile: called before javac compilation
  14380. + -post-compile: called after javac compilation
  14381. + -pre-compile-single: called before javac compilation of single file
  14382. + -post-compile-single: called after javac compilation of single file
  14383. + -pre-compile-test: called before javac compilation of JUnit tests
  14384. + -post-compile-test: called after javac compilation of JUnit tests
  14385. + -pre-compile-test-single: called before javac compilation of single JUnit test
  14386. + -post-compile-test-single: called after javac compilation of single JUunit test
  14387. + -pre-jar: called before JAR building
  14388. + -post-jar: called after JAR building
  14389. + -post-clean: called after cleaning build products
  14390. +
  14391. + (Targets beginning with '-' are not intended to be called on their own.)
  14392. +
  14393. + Example of inserting an obfuscator after compilation could look like this:
  14394. +
  14395. + <target name="-post-compile">
  14396. + <obfuscate>
  14397. + <fileset dir="${build.classes.dir}"/>
  14398. + </obfuscate>
  14399. + </target>
  14400. +
  14401. + For list of available properties check the imported
  14402. + nbproject/build-impl.xml file.
  14403. +
  14404. +
  14405. + Another way to customize the build is by overriding existing main targets.
  14406. + The targets of interest are:
  14407. +
  14408. + -init-macrodef-javac: defines macro for javac compilation
  14409. + -init-macrodef-junit: defines macro for junit execution
  14410. + -init-macrodef-debug: defines macro for class debugging
  14411. + -init-macrodef-java: defines macro for class execution
  14412. + -do-jar-with-manifest: JAR building (if you are using a manifest)
  14413. + -do-jar-without-manifest: JAR building (if you are not using a manifest)
  14414. + run: execution of project
  14415. + -javadoc-build: Javadoc generation
  14416. + test-report: JUnit report generation
  14417. +
  14418. + An example of overriding the target for project execution could look like this:
  14419. +
  14420. + <target name="run" depends="HotSwapTool-impl.jar">
  14421. + <exec dir="bin" executable="launcher.exe">
  14422. + <arg file="${dist.jar}"/>
  14423. + </exec>
  14424. + </target>
  14425. +
  14426. + Notice that the overridden target depends on the jar target and not only on
  14427. + the compile target as the regular run target does. Again, for a list of available
  14428. + properties which you can use, check the target you are overriding in the
  14429. + nbproject/build-impl.xml file.
  14430. +
  14431. + -->
  14432. +</project>
  14433. diff -r f5603a6e5042 hotswaptest/HotSwapTool/manifest.mf
  14434. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  14435. +++ b/hotswaptest/HotSwapTool/manifest.mf Fri Dec 17 13:23:04 2010 +0100
  14436. @@ -0,0 +1,3 @@
  14437. +Manifest-Version: 1.0
  14438. +X-COMMENT: Main-Class will be added automatically by build
  14439. +
  14440. diff -r f5603a6e5042 hotswaptest/HotSwapTool/nbproject/build-impl.xml
  14441. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  14442. +++ b/hotswaptest/HotSwapTool/nbproject/build-impl.xml Fri Dec 17 13:23:04 2010 +0100
  14443. @@ -0,0 +1,880 @@
  14444. +<?xml version="1.0" encoding="UTF-8"?>
  14445. +<!--
  14446. +*** GENERATED FROM project.xml - DO NOT EDIT ***
  14447. +*** EDIT ../build.xml INSTEAD ***
  14448. +
  14449. +For the purpose of easier reading the script
  14450. +is divided into following sections:
  14451. +
  14452. + - initialization
  14453. + - compilation
  14454. + - jar
  14455. + - execution
  14456. + - debugging
  14457. + - javadoc
  14458. + - junit compilation
  14459. + - junit execution
  14460. + - junit debugging
  14461. + - applet
  14462. + - cleanup
  14463. +
  14464. + -->
  14465. +<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="HotSwapTool-impl">
  14466. + <fail message="Please build using Ant 1.7.1 or higher.">
  14467. + <condition>
  14468. + <not>
  14469. + <antversion atleast="1.7.1"/>
  14470. + </not>
  14471. + </condition>
  14472. + </fail>
  14473. + <target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>
  14474. + <!--
  14475. + ======================
  14476. + INITIALIZATION SECTION
  14477. + ======================
  14478. + -->
  14479. + <target name="-pre-init">
  14480. + <!-- Empty placeholder for easier customization. -->
  14481. + <!-- You can override this target in the ../build.xml file. -->
  14482. + </target>
  14483. + <target depends="-pre-init" name="-init-private">
  14484. + <property file="nbproject/private/config.properties"/>
  14485. + <property file="nbproject/private/configs/${config}.properties"/>
  14486. + <property file="nbproject/private/private.properties"/>
  14487. + </target>
  14488. + <target depends="-pre-init,-init-private" name="-init-user">
  14489. + <property file="${user.properties.file}"/>
  14490. + <!-- The two properties below are usually overridden -->
  14491. + <!-- by the active platform. Just a fallback. -->
  14492. + <property name="default.javac.source" value="1.4"/>
  14493. + <property name="default.javac.target" value="1.4"/>
  14494. + </target>
  14495. + <target depends="-pre-init,-init-private,-init-user" name="-init-project">
  14496. + <property file="nbproject/configs/${config}.properties"/>
  14497. + <property file="nbproject/project.properties"/>
  14498. + </target>
  14499. + <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
  14500. + <available file="${manifest.file}" property="manifest.available"/>
  14501. + <available file="${application.splash}" property="splashscreen.available"/>
  14502. + <condition property="main.class.available">
  14503. + <and>
  14504. + <isset property="main.class"/>
  14505. + <not>
  14506. + <equals arg1="${main.class}" arg2="" trim="true"/>
  14507. + </not>
  14508. + </and>
  14509. + </condition>
  14510. + <condition property="manifest.available+main.class">
  14511. + <and>
  14512. + <isset property="manifest.available"/>
  14513. + <isset property="main.class.available"/>
  14514. + </and>
  14515. + </condition>
  14516. + <condition property="do.mkdist">
  14517. + <and>
  14518. + <isset property="libs.CopyLibs.classpath"/>
  14519. + <not>
  14520. + <istrue value="${mkdist.disabled}"/>
  14521. + </not>
  14522. + </and>
  14523. + </condition>
  14524. + <condition property="manifest.available+main.class+mkdist.available">
  14525. + <and>
  14526. + <istrue value="${manifest.available+main.class}"/>
  14527. + <isset property="do.mkdist"/>
  14528. + </and>
  14529. + </condition>
  14530. + <condition property="manifest.available+main.class+mkdist.available+splashscreen.available">
  14531. + <and>
  14532. + <istrue value="${manifest.available+main.class+mkdist.available}"/>
  14533. + <istrue value="${splashscreen.available}"/>
  14534. + </and>
  14535. + </condition>
  14536. + <condition property="do.archive">
  14537. + <not>
  14538. + <istrue value="${jar.archive.disabled}"/>
  14539. + </not>
  14540. + </condition>
  14541. + <condition property="do.archive+manifest.available">
  14542. + <and>
  14543. + <isset property="manifest.available"/>
  14544. + <istrue value="${do.archive}"/>
  14545. + </and>
  14546. + </condition>
  14547. + <condition property="do.archive+manifest.available+main.class">
  14548. + <and>
  14549. + <istrue value="${manifest.available+main.class}"/>
  14550. + <istrue value="${do.archive}"/>
  14551. + </and>
  14552. + </condition>
  14553. + <condition property="do.archive+manifest.available+main.class+mkdist.available">
  14554. + <and>
  14555. + <istrue value="${manifest.available+main.class+mkdist.available}"/>
  14556. + <istrue value="${do.archive}"/>
  14557. + </and>
  14558. + </condition>
  14559. + <condition property="do.archive+manifest.available+main.class+mkdist.available+splashscreen.available">
  14560. + <and>
  14561. + <istrue value="${manifest.available+main.class+mkdist.available+splashscreen.available}"/>
  14562. + <istrue value="${do.archive}"/>
  14563. + </and>
  14564. + </condition>
  14565. + <condition property="have.tests">
  14566. + <or/>
  14567. + </condition>
  14568. + <condition property="have.sources">
  14569. + <or>
  14570. + <available file="${src.dir}"/>
  14571. + </or>
  14572. + </condition>
  14573. + <condition property="netbeans.home+have.tests">
  14574. + <and>
  14575. + <isset property="netbeans.home"/>
  14576. + <isset property="have.tests"/>
  14577. + </and>
  14578. + </condition>
  14579. + <condition property="no.javadoc.preview">
  14580. + <and>
  14581. + <isset property="javadoc.preview"/>
  14582. + <isfalse value="${javadoc.preview}"/>
  14583. + </and>
  14584. + </condition>
  14585. + <property name="run.jvmargs" value=""/>
  14586. + <property name="javac.compilerargs" value=""/>
  14587. + <property name="work.dir" value="${basedir}"/>
  14588. + <condition property="no.deps">
  14589. + <and>
  14590. + <istrue value="${no.dependencies}"/>
  14591. + </and>
  14592. + </condition>
  14593. + <property name="javac.debug" value="true"/>
  14594. + <property name="javadoc.preview" value="true"/>
  14595. + <property name="application.args" value=""/>
  14596. + <property name="source.encoding" value="${file.encoding}"/>
  14597. + <property name="runtime.encoding" value="${source.encoding}"/>
  14598. + <condition property="javadoc.encoding.used" value="${javadoc.encoding}">
  14599. + <and>
  14600. + <isset property="javadoc.encoding"/>
  14601. + <not>
  14602. + <equals arg1="${javadoc.encoding}" arg2=""/>
  14603. + </not>
  14604. + </and>
  14605. + </condition>
  14606. + <property name="javadoc.encoding.used" value="${source.encoding}"/>
  14607. + <property name="includes" value="**"/>
  14608. + <property name="excludes" value=""/>
  14609. + <property name="do.depend" value="false"/>
  14610. + <condition property="do.depend.true">
  14611. + <istrue value="${do.depend}"/>
  14612. + </condition>
  14613. + <path id="endorsed.classpath.path" path="${endorsed.classpath}"/>
  14614. + <condition else="" property="endorsed.classpath.cmd.line.arg" value="-Xbootclasspath/p:'${toString:endorsed.classpath.path}'">
  14615. + <length length="0" string="${endorsed.classpath}" when="greater"/>
  14616. + </condition>
  14617. + <property name="javac.fork" value="false"/>
  14618. + <property name="jar.index" value="false"/>
  14619. + <available file="${meta.inf.dir}/persistence.xml" property="has.persistence.xml"/>
  14620. + </target>
  14621. + <target name="-post-init">
  14622. + <!-- Empty placeholder for easier customization. -->
  14623. + <!-- You can override this target in the ../build.xml file. -->
  14624. + </target>
  14625. + <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
  14626. + <fail unless="src.dir">Must set src.dir</fail>
  14627. + <fail unless="build.dir">Must set build.dir</fail>
  14628. + <fail unless="dist.dir">Must set dist.dir</fail>
  14629. + <fail unless="build.classes.dir">Must set build.classes.dir</fail>
  14630. + <fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
  14631. + <fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail>
  14632. + <fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
  14633. + <fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
  14634. + <fail unless="dist.jar">Must set dist.jar</fail>
  14635. + </target>
  14636. + <target name="-init-macrodef-property">
  14637. + <macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1">
  14638. + <attribute name="name"/>
  14639. + <attribute name="value"/>
  14640. + <sequential>
  14641. + <property name="@{name}" value="${@{value}}"/>
  14642. + </sequential>
  14643. + </macrodef>
  14644. + </target>
  14645. + <target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-macrodef-javac-with-processors">
  14646. + <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
  14647. + <attribute default="${src.dir}" name="srcdir"/>
  14648. + <attribute default="${build.classes.dir}" name="destdir"/>
  14649. + <attribute default="${javac.classpath}" name="classpath"/>
  14650. + <attribute default="${javac.processorpath}" name="processorpath"/>
  14651. + <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/>
  14652. + <attribute default="${includes}" name="includes"/>
  14653. + <attribute default="${excludes}" name="excludes"/>
  14654. + <attribute default="${javac.debug}" name="debug"/>
  14655. + <attribute default="${empty.dir}" name="sourcepath"/>
  14656. + <attribute default="${empty.dir}" name="gensrcdir"/>
  14657. + <element name="customize" optional="true"/>
  14658. + <sequential>
  14659. + <property location="${build.dir}/empty" name="empty.dir"/>
  14660. + <mkdir dir="${empty.dir}"/>
  14661. + <mkdir dir="@{apgeneratedsrcdir}"/>
  14662. + <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
  14663. + <src>
  14664. + <dirset dir="@{gensrcdir}" erroronmissingdir="false">
  14665. + <include name="*"/>
  14666. + </dirset>
  14667. + </src>
  14668. + <classpath>
  14669. + <path path="@{classpath}"/>
  14670. + </classpath>
  14671. + <compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
  14672. + <compilerarg line="${javac.compilerargs}"/>
  14673. + <compilerarg value="-processorpath"/>
  14674. + <compilerarg path="@{processorpath}:${empty.dir}"/>
  14675. + <compilerarg line="${ap.processors.internal}"/>
  14676. + <compilerarg line="${annotation.processing.processor.options}"/>
  14677. + <compilerarg value="-s"/>
  14678. + <compilerarg path="@{apgeneratedsrcdir}"/>
  14679. + <compilerarg line="${ap.proc.none.internal}"/>
  14680. + <customize/>
  14681. + </javac>
  14682. + </sequential>
  14683. + </macrodef>
  14684. + </target>
  14685. + <target depends="-init-ap-cmdline-properties" name="-init-macrodef-javac-without-processors" unless="ap.supported.internal">
  14686. + <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
  14687. + <attribute default="${src.dir}" name="srcdir"/>
  14688. + <attribute default="${build.classes.dir}" name="destdir"/>
  14689. + <attribute default="${javac.classpath}" name="classpath"/>
  14690. + <attribute default="${javac.processorpath}" name="processorpath"/>
  14691. + <attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/>
  14692. + <attribute default="${includes}" name="includes"/>
  14693. + <attribute default="${excludes}" name="excludes"/>
  14694. + <attribute default="${javac.debug}" name="debug"/>
  14695. + <attribute default="${empty.dir}" name="sourcepath"/>
  14696. + <attribute default="${empty.dir}" name="gensrcdir"/>
  14697. + <element name="customize" optional="true"/>
  14698. + <sequential>
  14699. + <property location="${build.dir}/empty" name="empty.dir"/>
  14700. + <mkdir dir="${empty.dir}"/>
  14701. + <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
  14702. + <src>
  14703. + <dirset dir="@{gensrcdir}" erroronmissingdir="false">
  14704. + <include name="*"/>
  14705. + </dirset>
  14706. + </src>
  14707. + <classpath>
  14708. + <path path="@{classpath}"/>
  14709. + </classpath>
  14710. + <compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
  14711. + <compilerarg line="${javac.compilerargs}"/>
  14712. + <customize/>
  14713. + </javac>
  14714. + </sequential>
  14715. + </macrodef>
  14716. + </target>
  14717. + <target depends="-init-macrodef-javac-with-processors,-init-macrodef-javac-without-processors" name="-init-macrodef-javac">
  14718. + <macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
  14719. + <attribute default="${src.dir}" name="srcdir"/>
  14720. + <attribute default="${build.classes.dir}" name="destdir"/>
  14721. + <attribute default="${javac.classpath}" name="classpath"/>
  14722. + <sequential>
  14723. + <depend cache="${build.dir}/depcache" destdir="@{destdir}" excludes="${excludes}" includes="${includes}" srcdir="@{srcdir}">
  14724. + <classpath>
  14725. + <path path="@{classpath}"/>
  14726. + </classpath>
  14727. + </depend>
  14728. + </sequential>
  14729. + </macrodef>
  14730. + <macrodef name="force-recompile" uri="http://www.netbeans.org/ns/j2se-project/3">
  14731. + <attribute default="${build.classes.dir}" name="destdir"/>
  14732. + <sequential>
  14733. + <fail unless="javac.includes">Must set javac.includes</fail>
  14734. + <pathconvert pathsep="," property="javac.includes.binary">
  14735. + <path>
  14736. + <filelist dir="@{destdir}" files="${javac.includes}"/>
  14737. + </path>
  14738. + <globmapper from="*.java" to="*.class"/>
  14739. + </pathconvert>
  14740. + <delete>
  14741. + <files includes="${javac.includes.binary}"/>
  14742. + </delete>
  14743. + </sequential>
  14744. + </macrodef>
  14745. + </target>
  14746. + <target name="-init-macrodef-junit">
  14747. + <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
  14748. + <attribute default="${includes}" name="includes"/>
  14749. + <attribute default="${excludes}" name="excludes"/>
  14750. + <attribute default="**" name="testincludes"/>
  14751. + <sequential>
  14752. + <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" showoutput="true" tempdir="${build.dir}">
  14753. + <batchtest todir="${build.test.results.dir}"/>
  14754. + <classpath>
  14755. + <path path="${run.test.classpath}"/>
  14756. + </classpath>
  14757. + <syspropertyset>
  14758. + <propertyref prefix="test-sys-prop."/>
  14759. + <mapper from="test-sys-prop.*" to="*" type="glob"/>
  14760. + </syspropertyset>
  14761. + <formatter type="brief" usefile="false"/>
  14762. + <formatter type="xml"/>
  14763. + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
  14764. + <jvmarg line="${run.jvmargs}"/>
  14765. + </junit>
  14766. + </sequential>
  14767. + </macrodef>
  14768. + </target>
  14769. + <target depends="-init-debug-args" name="-init-macrodef-nbjpda">
  14770. + <macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
  14771. + <attribute default="${main.class}" name="name"/>
  14772. + <attribute default="${debug.classpath}" name="classpath"/>
  14773. + <attribute default="" name="stopclassname"/>
  14774. + <sequential>
  14775. + <nbjpdastart addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}" transport="${debug-transport}">
  14776. + <classpath>
  14777. + <path path="@{classpath}"/>
  14778. + </classpath>
  14779. + </nbjpdastart>
  14780. + </sequential>
  14781. + </macrodef>
  14782. + <macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1">
  14783. + <attribute default="${build.classes.dir}" name="dir"/>
  14784. + <sequential>
  14785. + <nbjpdareload>
  14786. + <fileset dir="@{dir}" includes="${fix.classes}">
  14787. + <include name="${fix.includes}*.class"/>
  14788. + </fileset>
  14789. + </nbjpdareload>
  14790. + </sequential>
  14791. + </macrodef>
  14792. + </target>
  14793. + <target name="-init-debug-args">
  14794. + <property name="version-output" value="java version &quot;${ant.java.version}"/>
  14795. + <condition property="have-jdk-older-than-1.4">
  14796. + <or>
  14797. + <contains string="${version-output}" substring="java version &quot;1.0"/>
  14798. + <contains string="${version-output}" substring="java version &quot;1.1"/>
  14799. + <contains string="${version-output}" substring="java version &quot;1.2"/>
  14800. + <contains string="${version-output}" substring="java version &quot;1.3"/>
  14801. + </or>
  14802. + </condition>
  14803. + <condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
  14804. + <istrue value="${have-jdk-older-than-1.4}"/>
  14805. + </condition>
  14806. + <condition else="dt_socket" property="debug-transport-by-os" value="dt_shmem">
  14807. + <os family="windows"/>
  14808. + </condition>
  14809. + <condition else="${debug-transport-by-os}" property="debug-transport" value="${debug.transport}">
  14810. + <isset property="debug.transport"/>
  14811. + </condition>
  14812. + </target>
  14813. + <target depends="-init-debug-args" name="-init-macrodef-debug">
  14814. + <macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3">
  14815. + <attribute default="${main.class}" name="classname"/>
  14816. + <attribute default="${debug.classpath}" name="classpath"/>
  14817. + <element name="customize" optional="true"/>
  14818. + <sequential>
  14819. + <java classname="@{classname}" dir="${work.dir}" fork="true">
  14820. + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
  14821. + <jvmarg line="${debug-args-line}"/>
  14822. + <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
  14823. + <jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
  14824. + <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
  14825. + <jvmarg line="${run.jvmargs}"/>
  14826. + <classpath>
  14827. + <path path="@{classpath}"/>
  14828. + </classpath>
  14829. + <syspropertyset>
  14830. + <propertyref prefix="run-sys-prop."/>
  14831. + <mapper from="run-sys-prop.*" to="*" type="glob"/>
  14832. + </syspropertyset>
  14833. + <customize/>
  14834. + </java>
  14835. + </sequential>
  14836. + </macrodef>
  14837. + </target>
  14838. + <target name="-init-macrodef-java">
  14839. + <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
  14840. + <attribute default="${main.class}" name="classname"/>
  14841. + <attribute default="${run.classpath}" name="classpath"/>
  14842. + <element name="customize" optional="true"/>
  14843. + <sequential>
  14844. + <java classname="@{classname}" dir="${work.dir}" fork="true">
  14845. + <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
  14846. + <jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
  14847. + <redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
  14848. + <jvmarg line="${run.jvmargs}"/>
  14849. + <classpath>
  14850. + <path path="@{classpath}"/>
  14851. + </classpath>
  14852. + <syspropertyset>
  14853. + <propertyref prefix="run-sys-prop."/>
  14854. + <mapper from="run-sys-prop.*" to="*" type="glob"/>
  14855. + </syspropertyset>
  14856. + <customize/>
  14857. + </java>
  14858. + </sequential>
  14859. + </macrodef>
  14860. + </target>
  14861. + <target name="-init-macrodef-copylibs">
  14862. + <macrodef name="copylibs" uri="http://www.netbeans.org/ns/j2se-project/3">
  14863. + <element name="customize" optional="true"/>
  14864. + <sequential>
  14865. + <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
  14866. + <pathconvert property="run.classpath.without.build.classes.dir">
  14867. + <path path="${run.classpath}"/>
  14868. + <map from="${build.classes.dir.resolved}" to=""/>
  14869. + </pathconvert>
  14870. + <pathconvert pathsep=" " property="jar.classpath">
  14871. + <path path="${run.classpath.without.build.classes.dir}"/>
  14872. + <chainedmapper>
  14873. + <flattenmapper/>
  14874. + <globmapper from="*" to="lib/*"/>
  14875. + </chainedmapper>
  14876. + </pathconvert>
  14877. + <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
  14878. + <copylibs compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}" manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
  14879. + <fileset dir="${build.classes.dir}"/>
  14880. + <manifest>
  14881. + <attribute name="Class-Path" value="${jar.classpath}"/>
  14882. + <customize/>
  14883. + </manifest>
  14884. + </copylibs>
  14885. + </sequential>
  14886. + </macrodef>
  14887. + </target>
  14888. + <target name="-init-presetdef-jar">
  14889. + <presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
  14890. + <jar compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}">
  14891. + <j2seproject1:fileset dir="${build.classes.dir}"/>
  14892. + </jar>
  14893. + </presetdef>
  14894. + </target>
  14895. + <target name="-init-ap-cmdline-properties">
  14896. + <property name="annotation.processing.enabled" value="true"/>
  14897. + <property name="annotation.processing.processors.list" value=""/>
  14898. + <property name="annotation.processing.processor.options" value=""/>
  14899. + <property name="annotation.processing.run.all.processors" value="true"/>
  14900. + <property name="javac.processorpath" value="${javac.classpath}"/>
  14901. + <property name="javac.test.processorpath" value="${javac.test.classpath}"/>
  14902. + <condition property="ap.supported.internal" value="true">
  14903. + <not>
  14904. + <matches pattern="1\.[0-5](\..*)?" string="${javac.source}"/>
  14905. + </not>
  14906. + </condition>
  14907. + </target>
  14908. + <target depends="-init-ap-cmdline-properties" if="ap.supported.internal" name="-init-ap-cmdline-supported">
  14909. + <condition else="" property="ap.processors.internal" value="-processor ${annotation.processing.processors.list}">
  14910. + <isfalse value="${annotation.processing.run.all.processors}"/>
  14911. + </condition>
  14912. + <condition else="" property="ap.proc.none.internal" value="-proc:none">
  14913. + <isfalse value="${annotation.processing.enabled}"/>
  14914. + </condition>
  14915. + </target>
  14916. + <target depends="-init-ap-cmdline-properties,-init-ap-cmdline-supported" name="-init-ap-cmdline">
  14917. + <property name="ap.cmd.line.internal" value=""/>
  14918. + </target>
  14919. + <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar,-init-ap-cmdline" name="init"/>
  14920. + <!--
  14921. + ===================
  14922. + COMPILATION SECTION
  14923. + ===================
  14924. + -->
  14925. + <target name="-deps-jar-init" unless="built-jar.properties">
  14926. + <property location="${build.dir}/built-jar.properties" name="built-jar.properties"/>
  14927. + <delete file="${built-jar.properties}" quiet="true"/>
  14928. + </target>
  14929. + <target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
  14930. + <echo level="warn" message="Cycle detected: HotSwapTool was already built"/>
  14931. + </target>
  14932. + <target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
  14933. + <mkdir dir="${build.dir}"/>
  14934. + <touch file="${built-jar.properties}" verbose="false"/>
  14935. + <property file="${built-jar.properties}" prefix="already.built.jar."/>
  14936. + <antcall target="-warn-already-built-jar"/>
  14937. + <propertyfile file="${built-jar.properties}">
  14938. + <entry key="${basedir}" value=""/>
  14939. + </propertyfile>
  14940. + </target>
  14941. + <target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/>
  14942. + <target depends="init" name="-check-automatic-build">
  14943. + <available file="${build.classes.dir}/.netbeans_automatic_build" property="netbeans.automatic.build"/>
  14944. + </target>
  14945. + <target depends="init" if="netbeans.automatic.build" name="-clean-after-automatic-build">
  14946. + <antcall target="clean"/>
  14947. + </target>
  14948. + <target depends="init,deps-jar" name="-pre-pre-compile">
  14949. + <mkdir dir="${build.classes.dir}"/>
  14950. + </target>
  14951. + <target name="-pre-compile">
  14952. + <!-- Empty placeholder for easier customization. -->
  14953. + <!-- You can override this target in the ../build.xml file. -->
  14954. + </target>
  14955. + <target if="do.depend.true" name="-compile-depend">
  14956. + <pathconvert property="build.generated.subdirs">
  14957. + <dirset dir="${build.generated.sources.dir}" erroronmissingdir="false">
  14958. + <include name="*"/>
  14959. + </dirset>
  14960. + </pathconvert>
  14961. + <j2seproject3:depend srcdir="${src.dir}:${build.generated.subdirs}"/>
  14962. + </target>
  14963. + <target depends="init,deps-jar,-pre-pre-compile,-pre-compile, -copy-persistence-xml,-compile-depend" if="have.sources" name="-do-compile">
  14964. + <j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/>
  14965. + <copy todir="${build.classes.dir}">
  14966. + <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
  14967. + </copy>
  14968. + </target>
  14969. + <target if="has.persistence.xml" name="-copy-persistence-xml">
  14970. + <mkdir dir="${build.classes.dir}/META-INF"/>
  14971. + <copy todir="${build.classes.dir}/META-INF">
  14972. + <fileset dir="${meta.inf.dir}" includes="persistence.xml"/>
  14973. + </copy>
  14974. + </target>
  14975. + <target name="-post-compile">
  14976. + <!-- Empty placeholder for easier customization. -->
  14977. + <!-- You can override this target in the ../build.xml file. -->
  14978. + </target>
  14979. + <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project." name="compile"/>
  14980. + <target name="-pre-compile-single">
  14981. + <!-- Empty placeholder for easier customization. -->
  14982. + <!-- You can override this target in the ../build.xml file. -->
  14983. + </target>
  14984. + <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
  14985. + <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
  14986. + <j2seproject3:force-recompile/>
  14987. + <j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}" sourcepath="${src.dir}"/>
  14988. + </target>
  14989. + <target name="-post-compile-single">
  14990. + <!-- Empty placeholder for easier customization. -->
  14991. + <!-- You can override this target in the ../build.xml file. -->
  14992. + </target>
  14993. + <target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/>
  14994. + <!--
  14995. + ====================
  14996. + JAR BUILDING SECTION
  14997. + ====================
  14998. + -->
  14999. + <target depends="init" name="-pre-pre-jar">
  15000. + <dirname file="${dist.jar}" property="dist.jar.dir"/>
  15001. + <mkdir dir="${dist.jar.dir}"/>
  15002. + </target>
  15003. + <target name="-pre-jar">
  15004. + <!-- Empty placeholder for easier customization. -->
  15005. + <!-- You can override this target in the ../build.xml file. -->
  15006. + </target>
  15007. + <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive" name="-do-jar-without-manifest" unless="manifest.available">
  15008. + <j2seproject1:jar/>
  15009. + </target>
  15010. + <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available" name="-do-jar-with-manifest" unless="manifest.available+main.class">
  15011. + <j2seproject1:jar manifest="${manifest.file}"/>
  15012. + </target>
  15013. + <target depends="init,compile,-pre-pre-jar,-pre-jar" if="do.archive+manifest.available+main.class" name="-do-jar-with-mainclass" unless="manifest.available+main.class+mkdist.available">
  15014. + <j2seproject1:jar manifest="${manifest.file}">
  15015. + <j2seproject1:manifest>
  15016. + <j2seproject1:attribute name="Main-Class" value="${main.class}"/>
  15017. + </j2seproject1:manifest>
  15018. + </j2seproject1:jar>
  15019. + <echo>To run this application from the command line without Ant, try:</echo>
  15020. + <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
  15021. + <property location="${dist.jar}" name="dist.jar.resolved"/>
  15022. + <pathconvert property="run.classpath.with.dist.jar">
  15023. + <path path="${run.classpath}"/>
  15024. + <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
  15025. + </pathconvert>
  15026. + <echo>java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
  15027. + </target>
  15028. + <target depends="init,compile,-pre-pre-jar,-pre-jar,-init-macrodef-copylibs" if="do.archive+manifest.available+main.class+mkdist.available+splashscreen.available" name="-do-jar-with-libraries-and-splashscreen">
  15029. + <basename file="${application.splash}" property="splashscreen.basename"/>
  15030. + <mkdir dir="${build.classes.dir}/META-INF"/>
  15031. + <copy failonerror="false" file="${application.splash}" todir="${build.classes.dir}/META-INF"/>
  15032. + <j2seproject3:copylibs>
  15033. + <customize>
  15034. + <attribute name="Main-Class" value="${main.class}"/>
  15035. + <attribute name="SplashScreen-Image" value="META-INF/${splashscreen.basename}"/>
  15036. + </customize>
  15037. + </j2seproject3:copylibs>
  15038. + <echo>To run this application from the command line without Ant, try:</echo>
  15039. + <property location="${dist.jar}" name="dist.jar.resolved"/>
  15040. + <echo>java -jar "${dist.jar.resolved}"</echo>
  15041. + </target>
  15042. + <target depends="init,compile,-pre-pre-jar,-pre-jar,-init-macrodef-copylibs" if="do.archive+manifest.available+main.class+mkdist.available" name="-do-jar-with-libraries" unless="splashscreen.available">
  15043. + <j2seproject3:copylibs>
  15044. + <customize>
  15045. + <attribute name="Main-Class" value="${main.class}"/>
  15046. + </customize>
  15047. + </j2seproject3:copylibs>
  15048. + <echo>To run this application from the command line without Ant, try:</echo>
  15049. + <property location="${dist.jar}" name="dist.jar.resolved"/>
  15050. + <echo>java -jar "${dist.jar.resolved}"</echo>
  15051. + </target>
  15052. + <target name="-post-jar">
  15053. + <!-- Empty placeholder for easier customization. -->
  15054. + <!-- You can override this target in the ../build.xml file. -->
  15055. + </target>
  15056. + <target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries-and-splashscreen,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/>
  15057. + <!--
  15058. + =================
  15059. + EXECUTION SECTION
  15060. + =================
  15061. + -->
  15062. + <target depends="init,compile" description="Run a main class." name="run">
  15063. + <j2seproject1:java>
  15064. + <customize>
  15065. + <arg line="${application.args}"/>
  15066. + </customize>
  15067. + </j2seproject1:java>
  15068. + </target>
  15069. + <target name="-do-not-recompile">
  15070. + <property name="javac.includes.binary" value=""/>
  15071. + </target>
  15072. + <target depends="init,compile-single" name="run-single">
  15073. + <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
  15074. + <j2seproject1:java classname="${run.class}"/>
  15075. + </target>
  15076. + <target depends="init,compile-test-single" name="run-test-with-main">
  15077. + <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
  15078. + <j2seproject1:java classname="${run.class}" classpath="${run.test.classpath}"/>
  15079. + </target>
  15080. + <!--
  15081. + =================
  15082. + DEBUGGING SECTION
  15083. + =================
  15084. + -->
  15085. + <target depends="init" if="netbeans.home" name="-debug-start-debugger">
  15086. + <j2seproject1:nbjpdastart name="${debug.class}"/>
  15087. + </target>
  15088. + <target depends="init" if="netbeans.home" name="-debug-start-debugger-main-test">
  15089. + <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${debug.class}"/>
  15090. + </target>
  15091. + <target depends="init,compile" name="-debug-start-debuggee">
  15092. + <j2seproject3:debug>
  15093. + <customize>
  15094. + <arg line="${application.args}"/>
  15095. + </customize>
  15096. + </j2seproject3:debug>
  15097. + </target>
  15098. + <target depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE." if="netbeans.home" name="debug"/>
  15099. + <target depends="init" if="netbeans.home" name="-debug-start-debugger-stepinto">
  15100. + <j2seproject1:nbjpdastart stopclassname="${main.class}"/>
  15101. + </target>
  15102. + <target depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee" if="netbeans.home" name="debug-stepinto"/>
  15103. + <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-single">
  15104. + <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
  15105. + <j2seproject3:debug classname="${debug.class}"/>
  15106. + </target>
  15107. + <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single"/>
  15108. + <target depends="init,compile-test-single" if="netbeans.home" name="-debug-start-debuggee-main-test">
  15109. + <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
  15110. + <j2seproject3:debug classname="${debug.class}" classpath="${debug.test.classpath}"/>
  15111. + </target>
  15112. + <target depends="init,compile-test-single,-debug-start-debugger-main-test,-debug-start-debuggee-main-test" if="netbeans.home" name="debug-test-with-main"/>
  15113. + <target depends="init" name="-pre-debug-fix">
  15114. + <fail unless="fix.includes">Must set fix.includes</fail>
  15115. + <property name="javac.includes" value="${fix.includes}.java"/>
  15116. + </target>
  15117. + <target depends="init,-pre-debug-fix,compile-single" if="netbeans.home" name="-do-debug-fix">
  15118. + <j2seproject1:nbjpdareload/>
  15119. + </target>
  15120. + <target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/>
  15121. + <!--
  15122. + ===============
  15123. + JAVADOC SECTION
  15124. + ===============
  15125. + -->
  15126. + <target depends="init" if="have.sources" name="-javadoc-build">
  15127. + <mkdir dir="${dist.javadoc.dir}"/>
  15128. + <javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
  15129. + <classpath>
  15130. + <path path="${javac.classpath}"/>
  15131. + </classpath>
  15132. + <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
  15133. + <filename name="**/*.java"/>
  15134. + </fileset>
  15135. + <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
  15136. + <include name="**/*.java"/>
  15137. + </fileset>
  15138. + </javadoc>
  15139. + <copy todir="${dist.javadoc.dir}">
  15140. + <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
  15141. + <filename name="**/doc-files/**"/>
  15142. + </fileset>
  15143. + <fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
  15144. + <include name="**/doc-files/**"/>
  15145. + </fileset>
  15146. + </copy>
  15147. + </target>
  15148. + <target depends="init,-javadoc-build" if="netbeans.home" name="-javadoc-browse" unless="no.javadoc.preview">
  15149. + <nbbrowse file="${dist.javadoc.dir}/index.html"/>
  15150. + </target>
  15151. + <target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/>
  15152. + <!--
  15153. + =========================
  15154. + JUNIT COMPILATION SECTION
  15155. + =========================
  15156. + -->
  15157. + <target depends="init,compile" if="have.tests" name="-pre-pre-compile-test">
  15158. + <mkdir dir="${build.test.classes.dir}"/>
  15159. + </target>
  15160. + <target name="-pre-compile-test">
  15161. + <!-- Empty placeholder for easier customization. -->
  15162. + <!-- You can override this target in the ../build.xml file. -->
  15163. + </target>
  15164. + <target if="do.depend.true" name="-compile-test-depend">
  15165. + <j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir=""/>
  15166. + </target>
  15167. + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test">
  15168. + <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" processorpath="${javac.test.processorpath}" srcdir=""/>
  15169. + <copy todir="${build.test.classes.dir}"/>
  15170. + </target>
  15171. + <target name="-post-compile-test">
  15172. + <!-- Empty placeholder for easier customization. -->
  15173. + <!-- You can override this target in the ../build.xml file. -->
  15174. + </target>
  15175. + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test" name="compile-test"/>
  15176. + <target name="-pre-compile-test-single">
  15177. + <!-- Empty placeholder for easier customization. -->
  15178. + <!-- You can override this target in the ../build.xml file. -->
  15179. + </target>
  15180. + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single">
  15181. + <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
  15182. + <j2seproject3:force-recompile destdir="${build.test.classes.dir}"/>
  15183. + <j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" processorpath="${javac.test.processorpath}" sourcepath="" srcdir=""/>
  15184. + <copy todir="${build.test.classes.dir}"/>
  15185. + </target>
  15186. + <target name="-post-compile-test-single">
  15187. + <!-- Empty placeholder for easier customization. -->
  15188. + <!-- You can override this target in the ../build.xml file. -->
  15189. + </target>
  15190. + <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/>
  15191. + <!--
  15192. + =======================
  15193. + JUNIT EXECUTION SECTION
  15194. + =======================
  15195. + -->
  15196. + <target depends="init" if="have.tests" name="-pre-test-run">
  15197. + <mkdir dir="${build.test.results.dir}"/>
  15198. + </target>
  15199. + <target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run">
  15200. + <j2seproject3:junit testincludes="**/*Test.java"/>
  15201. + </target>
  15202. + <target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run">
  15203. + <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
  15204. + </target>
  15205. + <target depends="init" if="have.tests" name="test-report"/>
  15206. + <target depends="init" if="netbeans.home+have.tests" name="-test-browse"/>
  15207. + <target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests." name="test"/>
  15208. + <target depends="init" if="have.tests" name="-pre-test-run-single">
  15209. + <mkdir dir="${build.test.results.dir}"/>
  15210. + </target>
  15211. + <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single">
  15212. + <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
  15213. + <j2seproject3:junit excludes="" includes="${test.includes}"/>
  15214. + </target>
  15215. + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single">
  15216. + <fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
  15217. + </target>
  15218. + <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/>
  15219. + <!--
  15220. + =======================
  15221. + JUNIT DEBUGGING SECTION
  15222. + =======================
  15223. + -->
  15224. + <target depends="init,compile-test" if="have.tests" name="-debug-start-debuggee-test">
  15225. + <fail unless="test.class">Must select one file in the IDE or set test.class</fail>
  15226. + <property location="${build.test.results.dir}/TEST-${test.class}.xml" name="test.report.file"/>
  15227. + <delete file="${test.report.file}"/>
  15228. + <mkdir dir="${build.test.results.dir}"/>
  15229. + <j2seproject3:debug classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" classpath="${ant.home}/lib/ant.jar:${ant.home}/lib/ant-junit.jar:${debug.test.classpath}">
  15230. + <customize>
  15231. + <syspropertyset>
  15232. + <propertyref prefix="test-sys-prop."/>
  15233. + <mapper from="test-sys-prop.*" to="*" type="glob"/>
  15234. + </syspropertyset>
  15235. + <arg value="${test.class}"/>
  15236. + <arg value="showoutput=true"/>
  15237. + <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter"/>
  15238. + <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,${test.report.file}"/>
  15239. + </customize>
  15240. + </j2seproject3:debug>
  15241. + </target>
  15242. + <target depends="init,compile-test" if="netbeans.home+have.tests" name="-debug-start-debugger-test">
  15243. + <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${test.class}"/>
  15244. + </target>
  15245. + <target depends="init,compile-test-single,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/>
  15246. + <target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test">
  15247. + <j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
  15248. + </target>
  15249. + <target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/>
  15250. + <!--
  15251. + =========================
  15252. + APPLET EXECUTION SECTION
  15253. + =========================
  15254. + -->
  15255. + <target depends="init,compile-single" name="run-applet">
  15256. + <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
  15257. + <j2seproject1:java classname="sun.applet.AppletViewer">
  15258. + <customize>
  15259. + <arg value="${applet.url}"/>
  15260. + </customize>
  15261. + </j2seproject1:java>
  15262. + </target>
  15263. + <!--
  15264. + =========================
  15265. + APPLET DEBUGGING SECTION
  15266. + =========================
  15267. + -->
  15268. + <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-applet">
  15269. + <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
  15270. + <j2seproject3:debug classname="sun.applet.AppletViewer">
  15271. + <customize>
  15272. + <arg value="${applet.url}"/>
  15273. + </customize>
  15274. + </j2seproject3:debug>
  15275. + </target>
  15276. + <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet" if="netbeans.home" name="debug-applet"/>
  15277. + <!--
  15278. + ===============
  15279. + CLEANUP SECTION
  15280. + ===============
  15281. + -->
  15282. + <target name="-deps-clean-init" unless="built-clean.properties">
  15283. + <property location="${build.dir}/built-clean.properties" name="built-clean.properties"/>
  15284. + <delete file="${built-clean.properties}" quiet="true"/>
  15285. + </target>
  15286. + <target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
  15287. + <echo level="warn" message="Cycle detected: HotSwapTool was already built"/>
  15288. + </target>
  15289. + <target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
  15290. + <mkdir dir="${build.dir}"/>
  15291. + <touch file="${built-clean.properties}" verbose="false"/>
  15292. + <property file="${built-clean.properties}" prefix="already.built.clean."/>
  15293. + <antcall target="-warn-already-built-clean"/>
  15294. + <propertyfile file="${built-clean.properties}">
  15295. + <entry key="${basedir}" value=""/>
  15296. + </propertyfile>
  15297. + </target>
  15298. + <target depends="init" name="-do-clean">
  15299. + <delete dir="${build.dir}"/>
  15300. + <delete dir="${dist.dir}" followsymlinks="false" includeemptydirs="true"/>
  15301. + </target>
  15302. + <target name="-post-clean">
  15303. + <!-- Empty placeholder for easier customization. -->
  15304. + <!-- You can override this target in the ../build.xml file. -->
  15305. + </target>
  15306. + <target depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products." name="clean"/>
  15307. + <target name="-check-call-dep">
  15308. + <property file="${call.built.properties}" prefix="already.built."/>
  15309. + <condition property="should.call.dep">
  15310. + <not>
  15311. + <isset property="already.built.${call.subproject}"/>
  15312. + </not>
  15313. + </condition>
  15314. + </target>
  15315. + <target depends="-check-call-dep" if="should.call.dep" name="-maybe-call-dep">
  15316. + <ant antfile="${call.script}" inheritall="false" target="${call.target}">
  15317. + <propertyset>
  15318. + <propertyref prefix="transfer."/>
  15319. + <mapper from="transfer.*" to="*" type="glob"/>
  15320. + </propertyset>
  15321. + </ant>
  15322. + </target>
  15323. +</project>
  15324. diff -r f5603a6e5042 hotswaptest/HotSwapTool/nbproject/genfiles.properties
  15325. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  15326. +++ b/hotswaptest/HotSwapTool/nbproject/genfiles.properties Fri Dec 17 13:23:04 2010 +0100
  15327. @@ -0,0 +1,8 @@
  15328. +build.xml.data.CRC32=e63f7c25
  15329. +build.xml.script.CRC32=0269d054
  15330. +build.xml.stylesheet.CRC32=28e38971@1.40.0.45
  15331. +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
  15332. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
  15333. +nbproject/build-impl.xml.data.CRC32=e63f7c25
  15334. +nbproject/build-impl.xml.script.CRC32=57906c39
  15335. +nbproject/build-impl.xml.stylesheet.CRC32=5c621a33@1.26.2.45
  15336. diff -r f5603a6e5042 hotswaptest/HotSwapTool/nbproject/project.properties
  15337. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  15338. +++ b/hotswaptest/HotSwapTool/nbproject/project.properties Fri Dec 17 13:23:04 2010 +0100
  15339. @@ -0,0 +1,70 @@
  15340. +application.title=HotSwapTool
  15341. +application.vendor=Thomas
  15342. +build.classes.dir=${build.dir}/classes
  15343. +build.classes.excludes=**/*.java,**/*.form
  15344. +# This directory is removed when the project is cleaned:
  15345. +build.dir=build
  15346. +build.generated.dir=${build.dir}/generated
  15347. +build.generated.sources.dir=${build.dir}/generated-sources
  15348. +# Only compile against the classpath explicitly listed here:
  15349. +build.sysclasspath=ignore
  15350. +build.test.classes.dir=${build.dir}/test/classes
  15351. +build.test.results.dir=${build.dir}/test/results
  15352. +# Uncomment to specify the preferred debugger connection transport:
  15353. +#debug.transport=dt_socket
  15354. +debug.classpath=\
  15355. + ${run.classpath}
  15356. +debug.test.classpath=\
  15357. + ${run.test.classpath}
  15358. +# This directory is removed when the project is cleaned:
  15359. +dist.dir=dist
  15360. +dist.jar=${dist.dir}/HotSwapTool.jar
  15361. +dist.javadoc.dir=${dist.dir}/javadoc
  15362. +endorsed.classpath=
  15363. +excludes=
  15364. +file.reference.asm-all-3.2.jar=../lib/asm-all-3.2.jar
  15365. +file.reference.HotSwapTool-src=src
  15366. +file.reference.tools.jar=../lib/tools.jar
  15367. +includes=**
  15368. +jar.compress=false
  15369. +javac.classpath=\
  15370. + ${file.reference.tools.jar}:\
  15371. + ${file.reference.asm-all-3.2.jar}
  15372. +# Space-separated list of extra javac options
  15373. +javac.compilerargs=
  15374. +javac.deprecation=false
  15375. +javac.source=1.5
  15376. +javac.target=1.5
  15377. +javac.test.classpath=\
  15378. + ${javac.classpath}:\
  15379. + ${build.classes.dir}:\
  15380. + ${libs.junit.classpath}:\
  15381. + ${libs.junit_4.classpath}
  15382. +javadoc.additionalparam=
  15383. +javadoc.author=false
  15384. +javadoc.encoding=${source.encoding}
  15385. +javadoc.noindex=false
  15386. +javadoc.nonavbar=false
  15387. +javadoc.notree=false
  15388. +javadoc.private=false
  15389. +javadoc.splitindex=true
  15390. +javadoc.use=true
  15391. +javadoc.version=false
  15392. +javadoc.windowtitle=
  15393. +jaxbwiz.endorsed.dirs="${netbeans.home}/../ide12/modules/ext/jaxb/api"
  15394. +main.class=
  15395. +manifest.file=manifest.mf
  15396. +meta.inf.dir=${src.dir}/META-INF
  15397. +platform.active=default_platform
  15398. +run.classpath=\
  15399. + ${javac.classpath}:\
  15400. + ${build.classes.dir}
  15401. +# Space-separated list of JVM arguments used when running the project
  15402. +# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
  15403. +# or test-sys-prop.name=value to set system properties for unit tests):
  15404. +run.jvmargs=
  15405. +run.test.classpath=\
  15406. + ${javac.test.classpath}:\
  15407. + ${build.test.classes.dir}
  15408. +source.encoding=UTF-8
  15409. +src.dir=${file.reference.HotSwapTool-src}
  15410. diff -r f5603a6e5042 hotswaptest/HotSwapTool/nbproject/project.xml
  15411. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  15412. +++ b/hotswaptest/HotSwapTool/nbproject/project.xml Fri Dec 17 13:23:04 2010 +0100
  15413. @@ -0,0 +1,14 @@
  15414. +<?xml version="1.0" encoding="UTF-8"?>
  15415. +<project xmlns="http://www.netbeans.org/ns/project/1">
  15416. + <type>org.netbeans.modules.java.j2seproject</type>
  15417. + <configuration>
  15418. + <data xmlns="http://www.netbeans.org/ns/j2se-project/3">
  15419. + <name>HotSwapTool</name>
  15420. + <minimum-ant-version>1.6.5</minimum-ant-version>
  15421. + <source-roots>
  15422. + <root id="src.dir"/>
  15423. + </source-roots>
  15424. + <test-roots/>
  15425. + </data>
  15426. + </configuration>
  15427. +</project>
  15428. diff -r f5603a6e5042 hotswaptest/HotSwapTool/src/at/ssw/hotswap/ClassIdentifier.java
  15429. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  15430. +++ b/hotswaptest/HotSwapTool/src/at/ssw/hotswap/ClassIdentifier.java Fri Dec 17 13:23:04 2010 +0100
  15431. @@ -0,0 +1,95 @@
  15432. +/*
  15433. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  15434. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  15435. + *
  15436. + * This code is free software; you can redistribute it and/or modify it
  15437. + * under the terms of the GNU General Public License version 2 only, as
  15438. + * published by the Free Software Foundation.
  15439. + *
  15440. + * This code is distributed in the hope that it will be useful, but WITHOUT
  15441. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15442. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15443. + * version 2 for more details (a copy is included in the LICENSE file that
  15444. + * accompanied this code).
  15445. + *
  15446. + * You should have received a copy of the GNU General Public License version
  15447. + * 2 along with this work; if not, write to the Free Software Foundation,
  15448. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  15449. + *
  15450. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  15451. + * or visit www.oracle.com if you need additional information or have any
  15452. + * questions.
  15453. + *
  15454. + */
  15455. +package at.ssw.hotswap;
  15456. +
  15457. +/**
  15458. + * @author Kerstin Breiteneder
  15459. + * @author Christoph Wimberger
  15460. + */
  15461. +public class ClassIdentifier {
  15462. +
  15463. + private String methodSignature = null;
  15464. + private String typeSignature = null;
  15465. + private String slashedTypeName = null;
  15466. + private String dottedTypeName = null;
  15467. +
  15468. + public ClassIdentifier(String name) {
  15469. + if (name != null) {
  15470. + if (name.indexOf('(') >= 0) {
  15471. + this.methodSignature = name;
  15472. + } else if (name.endsWith(";")) {
  15473. + this.typeSignature = name;
  15474. + } else if (name.indexOf('.') >= 0) {
  15475. + this.dottedTypeName = name;
  15476. + } else {
  15477. + this.slashedTypeName = name;
  15478. + }
  15479. + }
  15480. + }
  15481. +
  15482. + public String getOriginal() {
  15483. + if (this.typeSignature != null) {
  15484. + return this.typeSignature;
  15485. + }
  15486. + if (this.methodSignature != null) {
  15487. + return this.methodSignature;
  15488. + }
  15489. + if (this.dottedTypeName != null) {
  15490. + return this.dottedTypeName;
  15491. + }
  15492. + return this.slashedTypeName;
  15493. + }
  15494. +
  15495. + public String getDescriptor() {
  15496. + if (this.dottedTypeName != null) {
  15497. + return this.dottedTypeName;
  15498. + }
  15499. + if (this.typeSignature != null) {
  15500. + return this.typeSignature.substring(1, this.typeSignature.length() - 1).replace('/', '.');
  15501. + }
  15502. + if (this.methodSignature != null) {
  15503. + return this.methodSignature.substring(1).replace('/', '.');
  15504. + }
  15505. + if (this.slashedTypeName != null) {
  15506. + return this.slashedTypeName.replace('/', '.');
  15507. + }
  15508. +
  15509. + return null;
  15510. + }
  15511. +
  15512. + public void setDescriptor(String ts) {
  15513. +
  15514. + if (this.dottedTypeName != null) {
  15515. + this.dottedTypeName = ts;
  15516. + } else if (this.typeSignature != null) {
  15517. + this.typeSignature = "L" + ts.replace('.', '/') + ";";
  15518. + } else if (this.methodSignature != null) {
  15519. + this.methodSignature = "(" + ts.replace('.', '/');
  15520. + } else if (this.slashedTypeName != null) {
  15521. + this.slashedTypeName = ts.replace('.', '/');
  15522. + } else {
  15523. + assert false : "something went wrong in ClassIdentifier";
  15524. + }
  15525. + }
  15526. +}
  15527. diff -r f5603a6e5042 hotswaptest/HotSwapTool/src/at/ssw/hotswap/ClassRedefinitionPolicy.java
  15528. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  15529. +++ b/hotswaptest/HotSwapTool/src/at/ssw/hotswap/ClassRedefinitionPolicy.java Fri Dec 17 13:23:04 2010 +0100
  15530. @@ -0,0 +1,40 @@
  15531. +/*
  15532. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  15533. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  15534. + *
  15535. + * This code is free software; you can redistribute it and/or modify it
  15536. + * under the terms of the GNU General Public License version 2 only, as
  15537. + * published by the Free Software Foundation.
  15538. + *
  15539. + * This code is distributed in the hope that it will be useful, but WITHOUT
  15540. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15541. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15542. + * version 2 for more details (a copy is included in the LICENSE file that
  15543. + * accompanied this code).
  15544. + *
  15545. + * You should have received a copy of the GNU General Public License version
  15546. + * 2 along with this work; if not, write to the Free Software Foundation,
  15547. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  15548. + *
  15549. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  15550. + * or visit www.oracle.com if you need additional information or have any
  15551. + * questions.
  15552. + *
  15553. + */
  15554. +package at.ssw.hotswap;
  15555. +
  15556. +import java.lang.annotation.Retention;
  15557. +import java.lang.annotation.RetentionPolicy;
  15558. +
  15559. +/**
  15560. + * @author Kerstin Breiteneder
  15561. + */
  15562. +@Retention(value = RetentionPolicy.RUNTIME)
  15563. +public @interface ClassRedefinitionPolicy {
  15564. +
  15565. + // Default value if no alias is set.
  15566. + public final static class NoClass {
  15567. + }
  15568. +
  15569. + Class alias() default NoClass.class;
  15570. +}
  15571. diff -r f5603a6e5042 hotswaptest/HotSwapTool/src/at/ssw/hotswap/FieldRedefinitionPolicy.java
  15572. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  15573. +++ b/hotswaptest/HotSwapTool/src/at/ssw/hotswap/FieldRedefinitionPolicy.java Fri Dec 17 13:23:04 2010 +0100
  15574. @@ -0,0 +1,37 @@
  15575. +/*
  15576. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  15577. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  15578. + *
  15579. + * This code is free software; you can redistribute it and/or modify it
  15580. + * under the terms of the GNU General Public License version 2 only, as
  15581. + * published by the Free Software Foundation.
  15582. + *
  15583. + * This code is distributed in the hope that it will be useful, but WITHOUT
  15584. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15585. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15586. + * version 2 for more details (a copy is included in the LICENSE file that
  15587. + * accompanied this code).
  15588. + *
  15589. + * You should have received a copy of the GNU General Public License version
  15590. + * 2 along with this work; if not, write to the Free Software Foundation,
  15591. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  15592. + *
  15593. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  15594. + * or visit www.oracle.com if you need additional information or have any
  15595. + * questions.
  15596. + *
  15597. + */
  15598. +package at.ssw.hotswap;
  15599. +
  15600. +import java.lang.annotation.Retention;
  15601. +import java.lang.annotation.RetentionPolicy;
  15602. +
  15603. +/**
  15604. + *
  15605. + * @author Thomas Wuerthinger
  15606. + */
  15607. +@Retention(RetentionPolicy.CLASS)
  15608. +public @interface FieldRedefinitionPolicy {
  15609. +
  15610. + RedefinitionPolicy value();
  15611. +}
  15612. diff -r f5603a6e5042 hotswaptest/HotSwapTool/src/at/ssw/hotswap/HotSwapException.java
  15613. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  15614. +++ b/hotswaptest/HotSwapTool/src/at/ssw/hotswap/HotSwapException.java Fri Dec 17 13:23:04 2010 +0100
  15615. @@ -0,0 +1,48 @@
  15616. +/*
  15617. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  15618. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  15619. + *
  15620. + * This code is free software; you can redistribute it and/or modify it
  15621. + * under the terms of the GNU General Public License version 2 only, as
  15622. + * published by the Free Software Foundation.
  15623. + *
  15624. + * This code is distributed in the hope that it will be useful, but WITHOUT
  15625. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15626. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15627. + * version 2 for more details (a copy is included in the LICENSE file that
  15628. + * accompanied this code).
  15629. + *
  15630. + * You should have received a copy of the GNU General Public License version
  15631. + * 2 along with this work; if not, write to the Free Software Foundation,
  15632. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  15633. + *
  15634. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  15635. + * or visit www.oracle.com if you need additional information or have any
  15636. + * questions.
  15637. + *
  15638. + */
  15639. +
  15640. +package at.ssw.hotswap;
  15641. +
  15642. +/**
  15643. + * @author Thomas Wuerthinger
  15644. + */
  15645. +public class HotSwapException extends Exception {
  15646. + private static final long serialVersionUID = 1L;
  15647. +
  15648. + public HotSwapException() {
  15649. + super("Exception during hotswapping");
  15650. + }
  15651. +
  15652. + public HotSwapException(Throwable t) {
  15653. + super(t);
  15654. + }
  15655. +
  15656. + public HotSwapException(String s) {
  15657. + super(s);
  15658. + }
  15659. +
  15660. + public HotSwapException(String s, Throwable t) {
  15661. + super(s, t);
  15662. + }
  15663. +}
  15664. diff -r f5603a6e5042 hotswaptest/HotSwapTool/src/at/ssw/hotswap/HotSwapTool.java
  15665. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  15666. +++ b/hotswaptest/HotSwapTool/src/at/ssw/hotswap/HotSwapTool.java Fri Dec 17 13:23:04 2010 +0100
  15667. @@ -0,0 +1,542 @@
  15668. +/*
  15669. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  15670. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  15671. + *
  15672. + * This code is free software; you can redistribute it and/or modify it
  15673. + * under the terms of the GNU General Public License version 2 only, as
  15674. + * published by the Free Software Foundation.
  15675. + *
  15676. + * This code is distributed in the hope that it will be useful, but WITHOUT
  15677. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15678. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15679. + * version 2 for more details (a copy is included in the LICENSE file that
  15680. + * accompanied this code).
  15681. + *
  15682. + * You should have received a copy of the GNU General Public License version
  15683. + * 2 along with this work; if not, write to the Free Software Foundation,
  15684. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  15685. + *
  15686. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  15687. + * or visit www.oracle.com if you need additional information or have any
  15688. + * questions.
  15689. + *
  15690. + */
  15691. +package at.ssw.hotswap;
  15692. +
  15693. +import com.sun.jdi.IncompatibleThreadStateException;
  15694. +import com.sun.jdi.Location;
  15695. +import com.sun.jdi.ReferenceType;
  15696. +import com.sun.jdi.StackFrame;
  15697. +import com.sun.jdi.ThreadReference;
  15698. +import java.io.File;
  15699. +import java.io.FileInputStream;
  15700. +import java.io.FileNotFoundException;
  15701. +import java.io.IOException;
  15702. +import java.io.InputStream;
  15703. +import java.lang.annotation.Annotation;
  15704. +import java.lang.reflect.Field;
  15705. +import java.util.ArrayList;
  15706. +import java.util.HashMap;
  15707. +import java.util.HashSet;
  15708. +import java.util.Hashtable;
  15709. +import java.util.List;
  15710. +import java.util.Map;
  15711. +import java.util.Map.Entry;
  15712. +import java.util.Set;
  15713. +import org.objectweb.asm.ClassReader;
  15714. +import org.objectweb.asm.ClassWriter;
  15715. +
  15716. +/**
  15717. + *
  15718. + * @author Thomas Wuerthinger
  15719. + * @author Kerstin Breiteneder
  15720. + * @author Christoph Wimberger
  15721. + *
  15722. + */
  15723. +public class HotSwapTool {
  15724. +
  15725. + /** Prefix for the version number in the class name. The class bytes are modified that this string including
  15726. + * the following number is removed. This means that e.g. A___2 is treated as A anywhere in the source code. This is introduced
  15727. + * to make the IDE not complain about multiple defined classes.
  15728. + */
  15729. + public static final String IDENTIFIER = "___";
  15730. + /** Level at which the program prints console output. Use 0 to disable the console output. **/
  15731. + private static int TRACE_LEVEL;
  15732. + private static final String CLASS_FILE_SUFFIX = ".class";
  15733. + private static Map<Class<?>, Integer> currentVersion = new Hashtable<Class<?>, Integer>();
  15734. + private static int redefinitionCount;
  15735. + private static long totalTime;
  15736. +
  15737. + public static void setTraceLevel(int level) {
  15738. + TRACE_LEVEL = level;
  15739. + }
  15740. +
  15741. + /**
  15742. + * Utility method for dumping the current call stack. The parameter identifies the class version the caller method corresponds to.
  15743. + * @param version the manually specified class version of the caller method
  15744. + */
  15745. + public static void dumpEnter(int version) {
  15746. +
  15747. + System.out.print("Method enter version " + version + " of ");
  15748. +
  15749. + StackTraceElement[] trace = Thread.currentThread().getStackTrace();
  15750. + if (trace.length < 3) {
  15751. + return;
  15752. + }
  15753. +
  15754. + boolean first = true;
  15755. + for (int i = 2; i <= 3; i++) {
  15756. + StackTraceElement elem = trace[i];
  15757. + if (elem.getClassName().startsWith("at.ssw")) {
  15758. + String className = elem.getClassName();
  15759. + className = className.substring(className.lastIndexOf('.') + 1);
  15760. + if (first) {
  15761. + first = false;
  15762. + System.out.print(className + "." + elem.getMethodName() + ": ");
  15763. + } else {
  15764. + System.out.print(className + "." + elem.getMethodName() + "[" + elem.getLineNumber() + "] ");
  15765. + }
  15766. + }
  15767. + }
  15768. + System.out.println();
  15769. + }
  15770. +
  15771. + /**
  15772. + * Returns the current version of the inner classes of a specified outer class.
  15773. + * @param baseClass the outer class whose version is queried
  15774. + * @return the version of the inner classes of the specified outer class
  15775. + */
  15776. + public static int getCurrentVersion(Class<?> baseClass) {
  15777. + if (!currentVersion.containsKey(baseClass)) {
  15778. + currentVersion.put(baseClass, 0);
  15779. + }
  15780. + return currentVersion.get(baseClass).intValue();
  15781. + }
  15782. +
  15783. + /**
  15784. + * Performs an explit shutdown and disconnects from the VM.
  15785. + */
  15786. + public static void shutdown() {
  15787. + final JDIProxy jdi = JDIProxy.getJDI();
  15788. +
  15789. + try {
  15790. + jdi.disconnect();
  15791. + } catch (HotSwapException e) {
  15792. + throw new Error(e);
  15793. + }
  15794. + }
  15795. +
  15796. + /**
  15797. + * Redefines the Java class specified by the array of class files.
  15798. + * @param files the class files with the byte codes of the new version of the java classes
  15799. + * @throws HotSwapException if redefining the classes failed
  15800. + * @throws ClassNotFoundException if a class that is not yet loaded in the target VM should be redefined
  15801. + */
  15802. + public static void redefine(List<File> files, final Map<String,String> replacements) throws HotSwapException, ClassNotFoundException {
  15803. +
  15804. + final JDIProxy jdi = JDIProxy.getJDI();
  15805. + assert jdi.isConnected();
  15806. +
  15807. + // Be sure to be in sync with the VM.
  15808. + jdi.refreshAllClasses();
  15809. + List<ReferenceType> klasses = jdi.allClasses();
  15810. + if (TRACE_LEVEL >= 2) {
  15811. + System.out.println("Number of classes loaded before redefinition: " + klasses.size());
  15812. + }
  15813. +
  15814. + Map<String, ReferenceType> klassesMap = new HashMap<String, ReferenceType>();
  15815. + for (ReferenceType t : klasses) {
  15816. + if (!t.name().endsWith("[]")) {
  15817. + assert !klassesMap.containsKey(t.name()) : "Must not contain two classes with same name " + t.name() + "!";
  15818. + klassesMap.put(t.name(), t);
  15819. + }
  15820. + }
  15821. +
  15822. + // Print loaded types
  15823. + if (TRACE_LEVEL >= 4) {
  15824. + for (Entry<String, ReferenceType> entry : klassesMap.entrySet()) {
  15825. + System.out.println("Loaded reference type: " + entry.getValue());
  15826. + }
  15827. + }
  15828. +
  15829. + final Set<String> redefinedClasses = new HashSet<String>();
  15830. + Map<ReferenceType, byte[]> map = new HashMap<ReferenceType, byte[]>();
  15831. +
  15832. + for (File f : files) {
  15833. + try {
  15834. +
  15835. + InputStream s = new FileInputStream(f);
  15836. + ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
  15837. +
  15838. + TestCaseClassAdapter adapter = new TestCaseClassAdapter(writer, new TypeNameAdapter() {
  15839. +
  15840. + public String adapt(String typeName) {
  15841. + String newClass = getReplacementClassName(typeName, replacements);
  15842. + return newClass;
  15843. + }
  15844. + });
  15845. +
  15846. + ClassReader cr = new ClassReader(s);
  15847. + cr.accept(adapter, 0);
  15848. + s.close();
  15849. + byte[] bytes = writer.toByteArray();
  15850. +
  15851. + String className = adapter.name.replace('/', '.');
  15852. + ReferenceType t = klassesMap.get(className);
  15853. +
  15854. + assert t != null : "Class must be loaded in target VM (name=" + className + ")!";
  15855. +
  15856. + // TODO: Check if the hack to put in java/lang/Object as the name for every class is apropriate.
  15857. + // This could be used to make redefinition of not-yet-loaded classes possible.
  15858. + // Problem: Which class loaded to choose from? Currently a ReferenceType object is a combination of classname/classloader.
  15859. + map.put(t, bytes);
  15860. + redefinedClasses.add(t.name());
  15861. + } catch (FileNotFoundException e) {
  15862. + throw new HotSwapException(
  15863. + "Could not find specified class file", e);
  15864. + } catch (IOException e) {
  15865. + throw new HotSwapException(
  15866. + "IO exception while reading class file", e);
  15867. + }
  15868. + }
  15869. +
  15870. + if (TRACE_LEVEL >= 2) {
  15871. + System.out.print("Redefining the classes:");
  15872. + for (ReferenceType t : map.keySet()) {
  15873. + System.out.print(" " + t.name());
  15874. + }
  15875. + System.out.println();
  15876. + }
  15877. +
  15878. + long startTime = System.currentTimeMillis();
  15879. + jdi.getVM().redefineClasses(map);
  15880. +
  15881. + long curTime = System.currentTimeMillis() - startTime;
  15882. + totalTime += curTime;
  15883. + redefinitionCount++;
  15884. +
  15885. + }
  15886. +
  15887. + private static void getAndTouchMainStackFrames() {
  15888. + try {
  15889. + List<StackFrame> frames = HotSwapTool.getStackFramesOfMainThread();
  15890. + for (int i = 0; i < frames.size(); i++) {
  15891. + StackFrame frame = frames.get(i);
  15892. +
  15893. + // Access the parts of the stack frame one-by-one.
  15894. + Field f = null;
  15895. + try {
  15896. + f = frame.getClass().getDeclaredField("location");
  15897. + } catch (NoSuchFieldException ex) {
  15898. + throw new HotSwapException(ex);
  15899. + } catch (SecurityException ex) {
  15900. + throw new HotSwapException(ex);
  15901. + }
  15902. + f.setAccessible(true);
  15903. + Location l = null;
  15904. + try {
  15905. + l = (Location) f.get(frame);
  15906. + } catch (IllegalArgumentException ex) {
  15907. + throw new HotSwapException(ex);
  15908. + } catch (IllegalAccessException ex) {
  15909. + throw new HotSwapException(ex);
  15910. + }
  15911. + if (TRACE_LEVEL >= 3) {
  15912. + System.out.println("Frame number " + i);
  15913. +
  15914. + }
  15915. + com.sun.jdi.Method method = l.method();
  15916. + if (TRACE_LEVEL >= 3) {
  15917. + System.out.println("Method: " + method);
  15918. + }
  15919. + int lineNumber = l.lineNumber();
  15920. + if (TRACE_LEVEL >= 3) {
  15921. + System.out.println(lineNumber + " ");
  15922. + }
  15923. + if (l.lineNumber() == -1) {
  15924. + String methodString = l.method().toString();
  15925. + if (TRACE_LEVEL >= 3) {
  15926. + System.out.print(methodString);
  15927. + System.out.print("+");
  15928. + System.out.println(l.codeIndex());
  15929. + }
  15930. + } else if (TRACE_LEVEL >= 3) {
  15931. + System.out.print(l.declaringType().name());
  15932. + System.out.print(":");
  15933. + System.out.println(l.lineNumber());
  15934. + }
  15935. + }
  15936. + } catch (HotSwapException ex) {
  15937. + ex.printStackTrace();
  15938. + }
  15939. + }
  15940. +
  15941. + /**
  15942. + * Redefines all inner classes of a outer class to a specified version. Inner classes who do not have a particular
  15943. + * representation for a version remain unchanged.
  15944. + * @param outerClass the outer class whose inner classes should be redefined
  15945. + * @param versionNumber the target version number
  15946. + */
  15947. + public static void toVersion(Class<?> outerClass, int versionNumber) {
  15948. + assert versionNumber >= 0;
  15949. +
  15950. + if (TRACE_LEVEL >= 2) {
  15951. + System.out.println("Entering toVersion");
  15952. + }
  15953. +
  15954. + // Touch stack frames to make sure everything is OK.
  15955. + getAndTouchMainStackFrames();
  15956. +
  15957. + if (TRACE_LEVEL >= 1) {
  15958. + System.out.println("Changing class " + outerClass.getSimpleName() + " to version number " + versionNumber + " from version " + getCurrentVersion(outerClass));
  15959. + }
  15960. +
  15961. + if (versionNumber == getCurrentVersion(outerClass)) {
  15962. + // Nothing to do!
  15963. + return;
  15964. + }
  15965. +
  15966. + List<File> result = new ArrayList<File>();
  15967. + getClassFilesWithVersion(result, new File("."), versionNumber, outerClass);
  15968. +
  15969. + // Make sure all classes are loaded in the VM, before they are redefined
  15970. + List<Class<?>> classes = new ArrayList<Class<?>>();
  15971. + for (File curFile : result) {
  15972. + String curFileName = fileToClassName(curFile.getPath());
  15973. +
  15974. + try {
  15975. + classes.add(Class.forName(curFileName));
  15976. + if (TRACE_LEVEL >= 2) {
  15977. + System.out.println("Class added: " + classes.get(classes.size() - 1));
  15978. + }
  15979. + } catch (ClassNotFoundException e) {
  15980. + e.printStackTrace();
  15981. + assert false;
  15982. + return;
  15983. + }
  15984. + }
  15985. + Map<String,String> replacements = new HashMap<String,String>();
  15986. +
  15987. + for(Class c : classes) {
  15988. + Annotation a = c.getAnnotation(ClassRedefinitionPolicy.class);
  15989. + if(a!=null && a instanceof ClassRedefinitionPolicy) {
  15990. + Class rep = ((ClassRedefinitionPolicy)a).alias();
  15991. +
  15992. + if(rep != ClassRedefinitionPolicy.NoClass.class) {
  15993. + String oldClassName = c.getName();
  15994. + String newClassName = rep.getName();
  15995. + replacements.put(oldClassName, newClassName);
  15996. + }
  15997. + else {
  15998. + replacements.put(c.getName(), stripVersion(c.getName()));
  15999. + }
  16000. + }
  16001. + else {
  16002. + replacements.put(c.getName(), stripVersion(c.getName()));
  16003. + }
  16004. + }
  16005. +
  16006. + for (File curFile : result) {
  16007. + String curFileName = curFile.getPath();
  16008. + String curClassName = getReplacementClassName(fileToClassName(curFileName), replacements);
  16009. +
  16010. + try {
  16011. + classes.add(Class.forName(curClassName));
  16012. + if (TRACE_LEVEL >= 2) {
  16013. + System.out.println("Class added: " + classes.get(classes.size() - 1));
  16014. + }
  16015. + } catch (ClassNotFoundException e) {
  16016. + e.printStackTrace();
  16017. + assert false;
  16018. + return;
  16019. + }
  16020. + }
  16021. + try {
  16022. + redefine(result, replacements);
  16023. + } catch (ClassNotFoundException e) {
  16024. + e.printStackTrace();
  16025. + assert false;
  16026. + return;
  16027. + } catch (HotSwapException e) {
  16028. + e.printStackTrace();
  16029. + assert false;
  16030. + return;
  16031. + }
  16032. +
  16033. + // Touch stack frames again for testing purposes.
  16034. + getAndTouchMainStackFrames();
  16035. +
  16036. + if (TRACE_LEVEL >= 2) {
  16037. + for (Class<?> c : classes) {
  16038. + System.out.println("Classes were: " + c.getName());
  16039. + assert isClassLoaded(c.getName());
  16040. + }
  16041. + }
  16042. + setCurrentVersion(outerClass, versionNumber);
  16043. + if (TRACE_LEVEL >= 2) {
  16044. + System.out.println("Version successfully changed to " + versionNumber);
  16045. + }
  16046. + assert getCurrentVersion(outerClass) == versionNumber;
  16047. + }
  16048. +
  16049. + private static void getClassFilesWithVersion(List<File> files, File f, int versionNumber,
  16050. + Class<?> baseClass) {
  16051. + if (f.isFile()) {
  16052. + String name = f.getName();
  16053. + if (isInnerClass(name, baseClass)) {
  16054. + int curVersionNumber = getVersionNumber(name);
  16055. + if (curVersionNumber == versionNumber) {
  16056. + files.add(f);
  16057. + }
  16058. + }
  16059. + } else if (f.isDirectory()) {
  16060. + for (File subFile : f.listFiles()) {
  16061. + getClassFilesWithVersion(files, subFile, versionNumber, baseClass);
  16062. + }
  16063. + } else {
  16064. + assert false;
  16065. + }
  16066. + }
  16067. +
  16068. + private static String fileToClassName(String s) {
  16069. + s = s.substring(0, s.length() - ".class".length());
  16070. + s = s.replace(".", "");
  16071. + s = s.replace(File.separator, ".");
  16072. + return s.substring(1);
  16073. + }
  16074. +
  16075. + private static int getVersionNumber(String name) {
  16076. +
  16077. + if (!name.endsWith(CLASS_FILE_SUFFIX)) {
  16078. + return -1;
  16079. + }
  16080. +
  16081. + int index = name.indexOf(IDENTIFIER);
  16082. + if (index == -1) {
  16083. + return 0;
  16084. + }
  16085. +
  16086. + int result = 0;
  16087. + int curIndex = index + IDENTIFIER.length();
  16088. + while (curIndex < name.length()) {
  16089. +
  16090. + char c = name.charAt(curIndex);
  16091. + if (!Character.isDigit(c)) {
  16092. + break;
  16093. + }
  16094. + curIndex++;
  16095. + result *= 10;
  16096. + result += c - '0';
  16097. + }
  16098. +
  16099. + return result;
  16100. + }
  16101. +
  16102. + private static boolean isInnerClass(String name, Class<?> baseClass) {
  16103. + return name.contains("." + baseClass.getSimpleName() + "$") || name.startsWith(baseClass.getSimpleName() + "$");
  16104. + }
  16105. +
  16106. + private static void setCurrentVersion(Class<?> baseClass, int value) {
  16107. + currentVersion.put(baseClass, value);
  16108. + }
  16109. +
  16110. + private static String getReplacementClassName(String clazz, Map<String, String> replacements) {
  16111. + if (clazz == null) {
  16112. + return null;
  16113. + }
  16114. + ClassIdentifier classIdentifier = new ClassIdentifier(clazz);
  16115. +
  16116. +
  16117. + for(String key: replacements.keySet()){
  16118. + String newClazz = classIdentifier.getDescriptor();
  16119. + if(newClazz.startsWith(key)){
  16120. + newClazz = newClazz.substring(key.length());
  16121. + classIdentifier.setDescriptor(replacements.get(key)+newClazz);
  16122. + return classIdentifier.getOriginal();
  16123. + }
  16124. + }
  16125. + return clazz;
  16126. + }
  16127. +
  16128. + public static String decodeDescriptor(String s) {
  16129. + assert s.charAt(0) == 'L' && s.charAt(s.length() - 1) == ';' : "argument must be type descriptor LCLASSNAME;";
  16130. + String typeName = s.substring(1, s.length() - 1);
  16131. + typeName = typeName.replace('/', '.');
  16132. + return typeName;
  16133. + }
  16134. +
  16135. + private static String stripVersion(String className) {
  16136. + if (className == null) {
  16137. + return null;
  16138. + }
  16139. + int index = className.indexOf(IDENTIFIER);
  16140. + if (index != -1) {
  16141. +
  16142. + int curIndex = index + IDENTIFIER.length();
  16143. + while (curIndex < className.length()) {
  16144. + if (Character.isDigit(className.charAt(curIndex))) {
  16145. + curIndex++;
  16146. + } else {
  16147. + break;
  16148. + }
  16149. + }
  16150. +
  16151. + className = className.substring(0, index) + className.substring(curIndex);
  16152. + }
  16153. + return className;
  16154. + }
  16155. +
  16156. + public static List<StackFrame> getStackFramesOfMainThread() {
  16157. + final JDIProxy jdi = JDIProxy.getJDI();
  16158. + final List<StackFrame> resultList = new ArrayList<StackFrame>();
  16159. + Runnable r = new Runnable() {
  16160. +
  16161. + public void run() {
  16162. + final List<ThreadReference> threads = jdi.getVM().allThreads();
  16163. + for (ThreadReference t : threads) {
  16164. + if (t.name().equals("main")) {
  16165. + try {
  16166. + if (TRACE_LEVEL >= 3) {
  16167. + System.out.println("Before accessing stack frames");
  16168. + }
  16169. + resultList.addAll(t.frames());
  16170. + if (TRACE_LEVEL >= 3) {
  16171. + System.out.println("Number of stack frames: " + resultList.size());
  16172. + }
  16173. + } catch (IncompatibleThreadStateException ex) {
  16174. + throw new IllegalStateException(ex);
  16175. + }
  16176. + }
  16177. + }
  16178. + }
  16179. + };
  16180. +
  16181. + jdi.executeSuspended(r);
  16182. + return resultList;
  16183. + }
  16184. + static int cnt;
  16185. +
  16186. + private static boolean isClassLoaded(String className) {
  16187. +
  16188. + List<ReferenceType> klasses = JDIProxy.getJDI().allClasses();
  16189. + for (ReferenceType klass : klasses) {
  16190. + if (klass.name().equals(className)) {
  16191. + return true;
  16192. + }
  16193. + }
  16194. + return false;
  16195. + }
  16196. +
  16197. + public static void resetTimings() {
  16198. + redefinitionCount = 0;
  16199. + totalTime = 0;
  16200. + }
  16201. +
  16202. + public static int getRedefinitionCount() {
  16203. + return redefinitionCount;
  16204. + }
  16205. +
  16206. + public static long getTotalTime() {
  16207. + return totalTime;
  16208. + }
  16209. +}
  16210. diff -r f5603a6e5042 hotswaptest/HotSwapTool/src/at/ssw/hotswap/JDIProxy.java
  16211. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  16212. +++ b/hotswaptest/HotSwapTool/src/at/ssw/hotswap/JDIProxy.java Fri Dec 17 13:23:04 2010 +0100
  16213. @@ -0,0 +1,206 @@
  16214. +/*
  16215. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  16216. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  16217. + *
  16218. + * This code is free software; you can redistribute it and/or modify it
  16219. + * under the terms of the GNU General Public License version 2 only, as
  16220. + * published by the Free Software Foundation.
  16221. + *
  16222. + * This code is distributed in the hope that it will be useful, but WITHOUT
  16223. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16224. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16225. + * version 2 for more details (a copy is included in the LICENSE file that
  16226. + * accompanied this code).
  16227. + *
  16228. + * You should have received a copy of the GNU General Public License version
  16229. + * 2 along with this work; if not, write to the Free Software Foundation,
  16230. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  16231. + *
  16232. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  16233. + * or visit www.oracle.com if you need additional information or have any
  16234. + * questions.
  16235. + *
  16236. + */
  16237. +package at.ssw.hotswap;
  16238. +
  16239. +import java.io.IOException;
  16240. +import java.util.ArrayList;
  16241. +import java.util.List;
  16242. +import java.util.Map;
  16243. +
  16244. +
  16245. +import com.sun.jdi.Bootstrap;
  16246. +import com.sun.jdi.ReferenceType;
  16247. +import com.sun.jdi.ThreadReference;
  16248. +import com.sun.jdi.VirtualMachine;
  16249. +import com.sun.jdi.VirtualMachineManager;
  16250. +import com.sun.jdi.connect.AttachingConnector;
  16251. +import com.sun.jdi.connect.IllegalConnectorArgumentsException;
  16252. +import com.sun.jdi.connect.Connector.Argument;
  16253. +import java.lang.reflect.Field;
  16254. +import java.util.logging.Level;
  16255. +import java.util.logging.Logger;
  16256. +
  16257. +/**
  16258. + * Utility class for performing hotswapping. Two main use cases:
  16259. + * <ul>
  16260. + * <li>Redefine a set of classes using the {@link #redefine(File[]) redefine} method.</li>
  16261. + * <li>Redefine all inner classes of a specified outer class to a certain version using the
  16262. + * {@link #toVersion(Class, int) toVersion} method.
  16263. + * The magic prefix to identify version numbers in classes is specified by the {@link #IDENTIFIER IDENTIFIER} field.
  16264. + * </li>
  16265. + * </ul>
  16266. + *
  16267. + * @author Thomas Wuerthinger
  16268. + * @author Kerstin Breiteneder
  16269. + * @author Christoph Wimberger
  16270. + *
  16271. + */
  16272. +public class JDIProxy {
  16273. +
  16274. + private static final String PORT_ARGUMENT_NAME = "port";
  16275. + private static final String TRANSPORT_NAME = "dt_socket";
  16276. +
  16277. + private VirtualMachine vm;
  16278. +
  16279. + private static JDIProxy jdi;
  16280. +
  16281. + /** Port at which to connect to the agent of the VM. **/
  16282. + public static final int PORT = 4000;
  16283. +
  16284. + private JDIProxy() {
  16285. + }
  16286. +
  16287. + public static JDIProxy getJDI() {
  16288. + if (jdi == null) {
  16289. +
  16290. + jdi = new JDIProxy();
  16291. + try {
  16292. + jdi.connect(PORT);
  16293. + } catch (HotSwapException e) {
  16294. + throw new IllegalStateException(e);
  16295. + }
  16296. + }
  16297. +
  16298. + return jdi;
  16299. + }
  16300. +
  16301. + public void connect(int port) throws HotSwapException {
  16302. +
  16303. + if (isConnected()) {
  16304. + throw new HotSwapException("Already connected");
  16305. + }
  16306. + VirtualMachineManager manager = Bootstrap.virtualMachineManager();
  16307. +
  16308. + // Find appropiate connector
  16309. + List<AttachingConnector> connectors = manager.attachingConnectors();
  16310. + AttachingConnector chosenConnector = null;
  16311. + for (AttachingConnector c : connectors) {
  16312. + if (c.transport().name().equals(TRANSPORT_NAME)) {
  16313. + chosenConnector = c;
  16314. + break;
  16315. + }
  16316. + }
  16317. + if (chosenConnector == null) {
  16318. + throw new HotSwapException("Could not find socket connector");
  16319. + }
  16320. +
  16321. + // Set port argument
  16322. + AttachingConnector connector = chosenConnector;
  16323. + Map<String, Argument> defaults = connector.defaultArguments();
  16324. + Argument a = defaults.get(PORT_ARGUMENT_NAME);
  16325. + if (a == null) {
  16326. + throw new HotSwapException("Could not find port argument");
  16327. + }
  16328. + a.setValue(Integer.toString(port));
  16329. +
  16330. + // Attach
  16331. + try {
  16332. + System.out.println("Connector arguments: " + defaults);
  16333. + vm = connector.attach(defaults);
  16334. + // vm.setDebugTraceMode(VirtualMachine.TRACE_EVENTS);
  16335. + } catch (IOException e) {
  16336. + throw new HotSwapException("IO exception during attach", e);
  16337. + } catch (IllegalConnectorArgumentsException e) {
  16338. + throw new HotSwapException("Illegal connector arguments", e);
  16339. + }
  16340. +
  16341. + assert isConnected();
  16342. + }
  16343. +
  16344. + public void disconnect() throws HotSwapException {
  16345. + assert isConnected();
  16346. + vm.dispose();
  16347. + vm = null;
  16348. + assert !isConnected();
  16349. + }
  16350. +
  16351. + // Checks if the tool is currently connected
  16352. + public boolean isConnected() {
  16353. + return vm != null;
  16354. + }
  16355. +
  16356. + public VirtualMachine getVM() {
  16357. + return vm;
  16358. + }
  16359. +
  16360. + /**
  16361. + * Call this method before calling allClasses() in order to refresh the JDI state of loaded classes.
  16362. + * This is necessary because the JDI map of all loaded classes is only updated based on events received over JDWP (network connection)
  16363. + * and therefore it is not necessarily up-to-date with the real state within the VM.
  16364. + */
  16365. + public void refreshAllClasses() {
  16366. + try {
  16367. + Field f = vm.getClass().getDeclaredField("retrievedAllTypes");
  16368. + f.setAccessible(true);
  16369. + f.set(vm, false);
  16370. + } catch (IllegalArgumentException ex) {
  16371. + Logger.getLogger(HotSwapTool.class.getName()).log(Level.SEVERE, null, ex);
  16372. + } catch (IllegalAccessException ex) {
  16373. + Logger.getLogger(HotSwapTool.class.getName()).log(Level.SEVERE, null, ex);
  16374. + } catch (NoSuchFieldException ex) {
  16375. + Logger.getLogger(HotSwapTool.class.getName()).log(Level.SEVERE, null, ex);
  16376. + } catch (SecurityException ex) {
  16377. + Logger.getLogger(HotSwapTool.class.getName()).log(Level.SEVERE, null, ex);
  16378. + }
  16379. + }
  16380. +
  16381. + public void executeSuspended(final Runnable r) {
  16382. +
  16383. + assert isConnected();
  16384. +
  16385. + Thread backup = new Thread(new Runnable() {
  16386. +
  16387. + public void run() {
  16388. + List<ThreadReference> threadsToSuspend = new ArrayList<ThreadReference>();
  16389. +
  16390. + for (ThreadReference t : vm.allThreads()) {
  16391. + if (t.name().equals("main")) {
  16392. + threadsToSuspend.add(t);
  16393. + }
  16394. + }
  16395. +
  16396. + for (ThreadReference t : threadsToSuspend) {
  16397. + t.suspend();
  16398. + }
  16399. + r.run();
  16400. + for (ThreadReference t : threadsToSuspend) {
  16401. + t.resume();
  16402. + }
  16403. + }
  16404. + });
  16405. + backup.start();
  16406. + try {
  16407. + backup.join();
  16408. + } catch (InterruptedException ex) {
  16409. + ex.getStackTrace();
  16410. + }
  16411. + }
  16412. +
  16413. + List<ReferenceType> allClasses() {
  16414. + // System.out.println("enter all classes");
  16415. + List<ReferenceType> result = vm.allClasses();
  16416. + //System.out.println("exit all classes");
  16417. + return result;
  16418. + }
  16419. +}
  16420. diff -r f5603a6e5042 hotswaptest/HotSwapTool/src/at/ssw/hotswap/Main.java
  16421. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  16422. +++ b/hotswaptest/HotSwapTool/src/at/ssw/hotswap/Main.java Fri Dec 17 13:23:04 2010 +0100
  16423. @@ -0,0 +1,72 @@
  16424. +/*
  16425. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  16426. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  16427. + *
  16428. + * This code is free software; you can redistribute it and/or modify it
  16429. + * under the terms of the GNU General Public License version 2 only, as
  16430. + * published by the Free Software Foundation.
  16431. + *
  16432. + * This code is distributed in the hope that it will be useful, but WITHOUT
  16433. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16434. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16435. + * version 2 for more details (a copy is included in the LICENSE file that
  16436. + * accompanied this code).
  16437. + *
  16438. + * You should have received a copy of the GNU General Public License version
  16439. + * 2 along with this work; if not, write to the Free Software Foundation,
  16440. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  16441. + *
  16442. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  16443. + * or visit www.oracle.com if you need additional information or have any
  16444. + * questions.
  16445. + *
  16446. + */
  16447. +
  16448. +package at.ssw.hotswap;
  16449. +
  16450. +import java.io.File;
  16451. +import java.util.ArrayList;
  16452. +import java.util.HashMap;
  16453. +import java.util.List;
  16454. +
  16455. +/**
  16456. + * Small program for using class HotSwapTool from the command line.
  16457. + * Example:
  16458. + * java at.ssw.hotswap.Main File1.class File2.class
  16459. + *
  16460. + * @author Thomas Wuerthinger
  16461. + */
  16462. +public class Main {
  16463. +
  16464. + public static final int PORT = 4000;
  16465. + public static final int TOOL_PORT = 1234;
  16466. +
  16467. + public static void main(String[] args) {
  16468. + System.out.println("Starting HotSwapTool");
  16469. + if (args.length == 0) {
  16470. + System.out.println("Usage: Specify class file names you want to hotswap.");
  16471. + return;
  16472. + }
  16473. +
  16474. + try {
  16475. + System.out.println("Using port " + PORT + " to connect to target VM");
  16476. + System.out.println("Redefining classes");
  16477. +
  16478. + List<File> klasses = new ArrayList<File>();
  16479. + for(int i=0; i<args.length; i++) {
  16480. + klasses.add(new File(args[i]));
  16481. + }
  16482. +
  16483. + try {
  16484. + HotSwapTool.redefine(klasses, new HashMap<String, String>());
  16485. + } catch (ClassNotFoundException e) {
  16486. + e.printStackTrace();
  16487. + } finally {
  16488. + HotSwapTool.shutdown();
  16489. + }
  16490. +
  16491. + } catch(HotSwapException e) {
  16492. + e.printStackTrace();
  16493. + }
  16494. + }
  16495. +}
  16496. \ No newline at end of file
  16497. diff -r f5603a6e5042 hotswaptest/HotSwapTool/src/at/ssw/hotswap/MethodRedefinitionPolicy.java
  16498. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  16499. +++ b/hotswaptest/HotSwapTool/src/at/ssw/hotswap/MethodRedefinitionPolicy.java Fri Dec 17 13:23:04 2010 +0100
  16500. @@ -0,0 +1,38 @@
  16501. +/*
  16502. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  16503. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  16504. + *
  16505. + * This code is free software; you can redistribute it and/or modify it
  16506. + * under the terms of the GNU General Public License version 2 only, as
  16507. + * published by the Free Software Foundation.
  16508. + *
  16509. + * This code is distributed in the hope that it will be useful, but WITHOUT
  16510. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16511. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16512. + * version 2 for more details (a copy is included in the LICENSE file that
  16513. + * accompanied this code).
  16514. + *
  16515. + * You should have received a copy of the GNU General Public License version
  16516. + * 2 along with this work; if not, write to the Free Software Foundation,
  16517. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  16518. + *
  16519. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  16520. + * or visit www.oracle.com if you need additional information or have any
  16521. + * questions.
  16522. + *
  16523. + */
  16524. +
  16525. +package at.ssw.hotswap;
  16526. +
  16527. +import java.lang.annotation.Retention;
  16528. +import java.lang.annotation.RetentionPolicy;
  16529. +
  16530. +/**
  16531. + *
  16532. + * @author Thomas Wuerthinger
  16533. + */
  16534. +@Retention(RetentionPolicy.CLASS)
  16535. +public @interface MethodRedefinitionPolicy {
  16536. + RedefinitionPolicy value();
  16537. +
  16538. +}
  16539. diff -r f5603a6e5042 hotswaptest/HotSwapTool/src/at/ssw/hotswap/RedefinitionPolicy.java
  16540. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  16541. +++ b/hotswaptest/HotSwapTool/src/at/ssw/hotswap/RedefinitionPolicy.java Fri Dec 17 13:23:04 2010 +0100
  16542. @@ -0,0 +1,36 @@
  16543. +/*
  16544. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  16545. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  16546. + *
  16547. + * This code is free software; you can redistribute it and/or modify it
  16548. + * under the terms of the GNU General Public License version 2 only, as
  16549. + * published by the Free Software Foundation.
  16550. + *
  16551. + * This code is distributed in the hope that it will be useful, but WITHOUT
  16552. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16553. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16554. + * version 2 for more details (a copy is included in the LICENSE file that
  16555. + * accompanied this code).
  16556. + *
  16557. + * You should have received a copy of the GNU General Public License version
  16558. + * 2 along with this work; if not, write to the Free Software Foundation,
  16559. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  16560. + *
  16561. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  16562. + * or visit www.oracle.com if you need additional information or have any
  16563. + * questions.
  16564. + *
  16565. + */
  16566. +
  16567. +package at.ssw.hotswap;
  16568. +
  16569. +/**
  16570. + *
  16571. + * @author Thomas Wuerthinger
  16572. + */
  16573. +public enum RedefinitionPolicy {
  16574. + StaticCheck,
  16575. + DynamicCheck,
  16576. + AccessDeletedMembers,
  16577. + AccessOldMembers
  16578. +}
  16579. diff -r f5603a6e5042 hotswaptest/HotSwapTool/src/at/ssw/hotswap/TestCaseClassAdapter.java
  16580. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  16581. +++ b/hotswaptest/HotSwapTool/src/at/ssw/hotswap/TestCaseClassAdapter.java Fri Dec 17 13:23:04 2010 +0100
  16582. @@ -0,0 +1,239 @@
  16583. +/*
  16584. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  16585. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  16586. + *
  16587. + * This code is free software; you can redistribute it and/or modify it
  16588. + * under the terms of the GNU General Public License version 2 only, as
  16589. + * published by the Free Software Foundation.
  16590. + *
  16591. + * This code is distributed in the hope that it will be useful, but WITHOUT
  16592. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16593. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16594. + * version 2 for more details (a copy is included in the LICENSE file that
  16595. + * accompanied this code).
  16596. + *
  16597. + * You should have received a copy of the GNU General Public License version
  16598. + * 2 along with this work; if not, write to the Free Software Foundation,
  16599. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  16600. + *
  16601. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  16602. + * or visit www.oracle.com if you need additional information or have any
  16603. + * questions.
  16604. + *
  16605. + */
  16606. +package at.ssw.hotswap;
  16607. +
  16608. +import java.util.HashSet;
  16609. +import java.util.Set;
  16610. +import org.objectweb.asm.AnnotationVisitor;
  16611. +import org.objectweb.asm.Attribute;
  16612. +import org.objectweb.asm.ByteVector;
  16613. +import org.objectweb.asm.ClassAdapter;
  16614. +import org.objectweb.asm.ClassVisitor;
  16615. +import org.objectweb.asm.ClassWriter;
  16616. +import org.objectweb.asm.FieldVisitor;
  16617. +import org.objectweb.asm.Label;
  16618. +import org.objectweb.asm.MethodAdapter;
  16619. +import org.objectweb.asm.MethodVisitor;
  16620. +import org.objectweb.asm.tree.AnnotationNode;
  16621. +
  16622. +/**
  16623. + *
  16624. + * @author Thomas Wuerthinger
  16625. + */
  16626. +public class TestCaseClassAdapter extends ClassAdapter {
  16627. +
  16628. + public String name;
  16629. +
  16630. + private TypeNameAdapter adapter;
  16631. +
  16632. + private Set<InnerClassEntry> innerClassEntries = new HashSet<InnerClassEntry>();
  16633. +
  16634. + private static class InnerClassEntry {
  16635. + String name;
  16636. + String outerName;
  16637. + String innerName;
  16638. + int access;
  16639. +
  16640. + public InnerClassEntry(String name, String outerName, String innerName, int access) {
  16641. + this.name = name;
  16642. + this.outerName = outerName;
  16643. + this.innerName = innerName;
  16644. + this.access = access;
  16645. + }
  16646. +
  16647. + @Override
  16648. + public int hashCode() {
  16649. + return ((name == null) ? 0 : name.hashCode()) * 27 + ((outerName == null) ? 0 : outerName.hashCode()) * 13 + ((innerName == null) ? 0 : innerName.hashCode()) * 7 + access;
  16650. + }
  16651. +
  16652. + @Override
  16653. + public boolean equals(Object o) {
  16654. + if (o != null && o instanceof InnerClassEntry) {
  16655. + final InnerClassEntry other = (InnerClassEntry)o;
  16656. + return equals(name, other.name) && equals(outerName, other.outerName) && equals(innerName, other.innerName) && access == other.access;
  16657. + }
  16658. +
  16659. + return false;
  16660. + }
  16661. +
  16662. + private boolean equals(Object o1, Object o2) {
  16663. + if (o1 == null) return o2 == null;
  16664. + if (o2 == null) return o1 == null;
  16665. + return o1.equals(o2);
  16666. + }
  16667. + }
  16668. +
  16669. + public TestCaseClassAdapter(ClassVisitor cv, TypeNameAdapter adapter) {
  16670. + super(cv);
  16671. + this.adapter = adapter;
  16672. + }
  16673. +
  16674. + private static String[] adapt(TypeNameAdapter adapter, String[] values) {
  16675. + if (values == null) return null;
  16676. + final String[] result = new String[values.length];
  16677. + for (int i = 0; i < result.length; i++) {
  16678. + result[i] = adapter.adapt(values[i]);
  16679. + }
  16680. + return result;
  16681. + }
  16682. +
  16683. + @Override
  16684. + public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
  16685. + this.name = adapter.adapt(name);
  16686. +
  16687. + if (this.name.equals("java/lang/Object")) {
  16688. + superName = null;
  16689. + }
  16690. +
  16691. + cv.visit(version, access, this.name, adapter.adapt(signature), adapter.adapt(superName), adapt(adapter, interfaces));
  16692. + }
  16693. +
  16694. + @Override
  16695. + public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
  16696. + return cv.visitField(access, name, desc, adapter.adapt(signature), value);
  16697. + }
  16698. +
  16699. + @Override
  16700. + public void visitInnerClass(String name, String outerName, String innerName, int access) {
  16701. +
  16702. + // Inner class entries may only occur once.
  16703. + InnerClassEntry entry = new InnerClassEntry(adapter.adapt(name), adapter.adapt(outerName), adapter.adapt(innerName), access);
  16704. + if (innerClassEntries.contains(entry)) {
  16705. + return;
  16706. + }
  16707. + innerClassEntries.add(entry);
  16708. +
  16709. + cv.visitInnerClass(entry.name, entry.outerName, entry.innerName, entry.access);
  16710. + }
  16711. +
  16712. + @Override
  16713. + public void visitOuterClass(String owner, String name, String desc) {
  16714. + cv.visitOuterClass(adapter.adapt(owner), adapter.adapt(name), desc);
  16715. + }
  16716. +
  16717. + @Override
  16718. + public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
  16719. +
  16720. + if (name.endsWith("___")) {
  16721. + name = name.substring(0, name.length() - 3);
  16722. + }
  16723. +
  16724. + MethodVisitor mv = cv.visitMethod(access, name, adapter.adapt(desc), adapter.adapt(signature), adapt(adapter, exceptions));
  16725. + if (mv != null) {
  16726. + mv = new MethodAdapter(mv) {
  16727. +
  16728. + @Override
  16729. + public void visitMethodInsn(int opcode, String owner, String name, String desc) {
  16730. + if (name.equals("<init>") && TestCaseClassAdapter.this.name.equals("java/lang/Object") && owner.equals("java/lang/Object")) {
  16731. + return;
  16732. + }
  16733. +
  16734. + if (name.endsWith("___")) {
  16735. + name = name.substring(0, name.length() - 3);
  16736. + }
  16737. +
  16738. + mv.visitMethodInsn(opcode, adapter.adapt(owner), name, adapter.adapt(desc));
  16739. + }
  16740. +
  16741. + @Override
  16742. + public void visitFieldInsn(int opcode, String owner, String name, String desc) {
  16743. + super.visitFieldInsn(opcode, adapter.adapt(owner), name, adapter.adapt(desc));
  16744. + }
  16745. +
  16746. + @Override
  16747. + public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
  16748. + super.visitLocalVariable(name, adapter.adapt(desc), adapter.adapt(signature), start, end, index);
  16749. + }
  16750. +
  16751. + @Override
  16752. + public void visitTypeInsn(int opcode, String type) {
  16753. + super.visitTypeInsn(opcode, adapter.adapt(type));
  16754. + }
  16755. +
  16756. + @Override
  16757. + public void visitMultiANewArrayInsn(String desc, int dims) {
  16758. + super.visitMultiANewArrayInsn(adapter.adapt(desc), dims);
  16759. + }
  16760. +
  16761. + @Override
  16762. + public void visitTryCatchBlock(Label start, Label end, Label handler, String type) {
  16763. + super.visitTryCatchBlock(start, end, handler, adapter.adapt(type));
  16764. + }
  16765. +
  16766. + @Override
  16767. + public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
  16768. + return super.visitAnnotation(adapter.adapt(desc), visible);
  16769. + }
  16770. + };
  16771. + }
  16772. +
  16773. + return mv;
  16774. + }
  16775. +
  16776. +
  16777. + @Override
  16778. + public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
  16779. +
  16780. + return new AnnotationNode(adapter.adapt(desc)) {
  16781. +
  16782. + @Override
  16783. + public void visitEnum(String name, String enumDesc, String value) {
  16784. +
  16785. +
  16786. + class SingleByteAttribute extends Attribute {
  16787. + private byte value;
  16788. +
  16789. + public SingleByteAttribute(String name, byte value) {
  16790. + super(name);
  16791. + this.value = value;
  16792. + }
  16793. +
  16794. + @Override
  16795. + protected ByteVector write(ClassWriter writer, byte[] code, int len, int maxStack, int maxLocals) {
  16796. + return new ByteVector().putByte(value);
  16797. + }
  16798. +
  16799. + }
  16800. +
  16801. + if (HotSwapTool.decodeDescriptor(enumDesc).equals(RedefinitionPolicy.class.getName())) {
  16802. + RedefinitionPolicy valueAsEnum = RedefinitionPolicy.valueOf(value);
  16803. + if (HotSwapTool.decodeDescriptor(desc).equals(FieldRedefinitionPolicy.class.getName())) {
  16804. + cv.visitAttribute(new SingleByteAttribute(FieldRedefinitionPolicy.class.getSimpleName(), (byte) valueAsEnum.ordinal()));
  16805. + }
  16806. + if (HotSwapTool.decodeDescriptor(desc).equals(MethodRedefinitionPolicy.class.getName())) {
  16807. + cv.visitAttribute(new SingleByteAttribute(MethodRedefinitionPolicy.class.getSimpleName(), (byte) valueAsEnum.ordinal()));
  16808. + }
  16809. + }
  16810. +
  16811. + super.visitEnum(name, desc, value);
  16812. + }
  16813. +
  16814. + @Override
  16815. + public void visitEnd() {
  16816. + accept(cv.visitAnnotation(desc, visible));
  16817. + }
  16818. + };
  16819. +
  16820. + }
  16821. +}
  16822. diff -r f5603a6e5042 hotswaptest/HotSwapTool/src/at/ssw/hotswap/TypeNameAdapter.java
  16823. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  16824. +++ b/hotswaptest/HotSwapTool/src/at/ssw/hotswap/TypeNameAdapter.java Fri Dec 17 13:23:04 2010 +0100
  16825. @@ -0,0 +1,34 @@
  16826. +/*
  16827. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  16828. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  16829. + *
  16830. + * This code is free software; you can redistribute it and/or modify it
  16831. + * under the terms of the GNU General Public License version 2 only, as
  16832. + * published by the Free Software Foundation.
  16833. + *
  16834. + * This code is distributed in the hope that it will be useful, but WITHOUT
  16835. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16836. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16837. + * version 2 for more details (a copy is included in the LICENSE file that
  16838. + * accompanied this code).
  16839. + *
  16840. + * You should have received a copy of the GNU General Public License version
  16841. + * 2 along with this work; if not, write to the Free Software Foundation,
  16842. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  16843. + *
  16844. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  16845. + * or visit www.oracle.com if you need additional information or have any
  16846. + * questions.
  16847. + *
  16848. + */
  16849. +
  16850. +package at.ssw.hotswap;
  16851. +
  16852. +/**
  16853. + *
  16854. + * @author Thomas Wuerthinger
  16855. + */
  16856. +public interface TypeNameAdapter {
  16857. +
  16858. + String adapt(String typeName);
  16859. +}
  16860. diff -r f5603a6e5042 hotswaptest/HotSwapTool/src/sun/misc/ClassRedefinition.java
  16861. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  16862. +++ b/hotswaptest/HotSwapTool/src/sun/misc/ClassRedefinition.java Fri Dec 17 13:23:04 2010 +0100
  16863. @@ -0,0 +1,34 @@
  16864. +/*
  16865. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  16866. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  16867. + *
  16868. + * This code is free software; you can redistribute it and/or modify it
  16869. + * under the terms of the GNU General Public License version 2 only, as
  16870. + * published by the Free Software Foundation.
  16871. + *
  16872. + * This code is distributed in the hope that it will be useful, but WITHOUT
  16873. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16874. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16875. + * version 2 for more details (a copy is included in the LICENSE file that
  16876. + * accompanied this code).
  16877. + *
  16878. + * You should have received a copy of the GNU General Public License version
  16879. + * 2 along with this work; if not, write to the Free Software Foundation,
  16880. + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  16881. + *
  16882. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  16883. + * or visit www.oracle.com if you need additional information or have any
  16884. + * questions.
  16885. + *
  16886. + */
  16887. +
  16888. +package sun.misc;
  16889. +
  16890. +/**
  16891. + * @author Kerstin Breiteneder
  16892. + * @author Christoph Wimberger
  16893. + */
  16894. +public class ClassRedefinition {
  16895. + //TODO: change parameters to allow multiple redefinitions
  16896. + public static native int redefineClasses(Class target, byte[] newBytes);
  16897. +}
  16898. diff -r f5603a6e5042 hotswaptest/lib/asm-all-3.2.jar
  16899. Binary file hotswaptest/lib/asm-all-3.2.jar has changed
  16900. diff -r f5603a6e5042 hotswaptest/lib/tools.jar
  16901. Binary file hotswaptest/lib/tools.jar has changed
  16902. diff -r f5603a6e5042 make/windows/build_vm_def.sh
  16903. --- a/make/windows/build_vm_def.sh Wed Nov 17 22:42:08 2010 -0800
  16904. +++ b/make/windows/build_vm_def.sh Fri Dec 17 13:23:04 2010 +0100
  16905. @@ -51,6 +51,7 @@
  16906. CAT="$MKS_HOME/cat.exe"
  16907. RM="$MKS_HOME/rm.exe"
  16908. DUMPBIN="link.exe /dump"
  16909. +export VS_UNICODE_OUTPUT=
  16910. # When called from IDE the first param should contain the link version, otherwise may be nill
  16911. if [ "x$1" != "x" ]; then
  16912. diff -r f5603a6e5042 make/windows/create.bat
  16913. --- a/make/windows/create.bat Wed Nov 17 22:42:08 2010 -0800
  16914. +++ b/make/windows/create.bat Fri Dec 17 13:23:04 2010 +0100
  16915. @@ -39,6 +39,8 @@
  16916. REM Note: Running this batch file from the Windows command shell requires
  16917. REM that "grep" be accessible on the PATH. An MKS install does this.
  16918. REM
  16919. +cl 2>&1 | grep "x64" >NUL
  16920. +if %errorlevel% == 0 goto amd64
  16921. cl 2>&1 | grep "IA-64" >NUL
  16922. if %errorlevel% == 0 goto isia64
  16923. cl 2>&1 | grep "AMD64" >NUL
  16924. diff -r f5603a6e5042 src/cpu/x86/vm/interp_masm_x86_32.cpp
  16925. --- a/src/cpu/x86/vm/interp_masm_x86_32.cpp Wed Nov 17 22:42:08 2010 -0800
  16926. +++ b/src/cpu/x86/vm/interp_masm_x86_32.cpp Fri Dec 17 13:23:04 2010 +0100
  16927. @@ -1352,7 +1352,7 @@
  16928. }
  16929. // RedefineClasses() tracing support for obsolete method entry
  16930. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  16931. + IF_TRACE_RC4 {
  16932. get_thread(rcx);
  16933. get_method(rbx);
  16934. call_VM_leaf(
  16935. diff -r f5603a6e5042 src/cpu/x86/vm/interp_masm_x86_64.cpp
  16936. --- a/src/cpu/x86/vm/interp_masm_x86_64.cpp Wed Nov 17 22:42:08 2010 -0800
  16937. +++ b/src/cpu/x86/vm/interp_masm_x86_64.cpp Fri Dec 17 13:23:04 2010 +0100
  16938. @@ -1438,7 +1438,7 @@
  16939. }
  16940. // RedefineClasses() tracing support for obsolete method entry
  16941. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  16942. + IF_TRACE_RC4 {
  16943. get_method(c_rarg1);
  16944. call_VM_leaf(
  16945. CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
  16946. diff -r f5603a6e5042 src/cpu/x86/vm/sharedRuntime_x86_32.cpp
  16947. --- a/src/cpu/x86/vm/sharedRuntime_x86_32.cpp Wed Nov 17 22:42:08 2010 -0800
  16948. +++ b/src/cpu/x86/vm/sharedRuntime_x86_32.cpp Fri Dec 17 13:23:04 2010 +0100
  16949. @@ -1494,7 +1494,7 @@
  16950. }
  16951. // RedefineClasses() tracing support for obsolete method entry
  16952. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  16953. + IF_TRACE_RC4 {
  16954. __ movoop(rax, JNIHandles::make_local(method()));
  16955. __ call_VM_leaf(
  16956. CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
  16957. diff -r f5603a6e5042 src/cpu/x86/vm/sharedRuntime_x86_64.cpp
  16958. --- a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp Wed Nov 17 22:42:08 2010 -0800
  16959. +++ b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp Fri Dec 17 13:23:04 2010 +0100
  16960. @@ -1490,7 +1490,7 @@
  16961. }
  16962. // RedefineClasses() tracing support for obsolete method entry
  16963. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  16964. + IF_TRACE_RC4 {
  16965. // protect the args we've loaded
  16966. save_args(masm, total_c_args, c_arg, out_regs);
  16967. __ movoop(c_rarg1, JNIHandles::make_local(method()));
  16968. diff -r f5603a6e5042 src/cpu/x86/vm/templateTable_x86_32.cpp
  16969. --- a/src/cpu/x86/vm/templateTable_x86_32.cpp Wed Nov 17 22:42:08 2010 -0800
  16970. +++ b/src/cpu/x86/vm/templateTable_x86_32.cpp Fri Dec 17 13:23:04 2010 +0100
  16971. @@ -2110,6 +2110,22 @@
  16972. // resolve first time through
  16973. address entry;
  16974. switch (bytecode()) {
  16975. + case Bytecodes::_fast_agetfield : // fall through
  16976. + case Bytecodes::_fast_bgetfield : // fall through
  16977. + case Bytecodes::_fast_cgetfield : // fall through
  16978. + case Bytecodes::_fast_dgetfield : // fall through
  16979. + case Bytecodes::_fast_fgetfield : // fall through
  16980. + case Bytecodes::_fast_igetfield : // fall through
  16981. + case Bytecodes::_fast_lgetfield : // fall through
  16982. + case Bytecodes::_fast_sgetfield : // fall through
  16983. + case Bytecodes::_fast_aputfield : // fall through
  16984. + case Bytecodes::_fast_bputfield : // fall through
  16985. + case Bytecodes::_fast_cputfield : // fall through
  16986. + case Bytecodes::_fast_dputfield : // fall through
  16987. + case Bytecodes::_fast_fputfield : // fall through
  16988. + case Bytecodes::_fast_iputfield : // fall through
  16989. + case Bytecodes::_fast_lputfield : // fall through
  16990. + case Bytecodes::_fast_sputfield : // fall through
  16991. case Bytecodes::_getstatic : // fall through
  16992. case Bytecodes::_putstatic : // fall through
  16993. case Bytecodes::_getfield : // fall through
  16994. @@ -2204,6 +2220,7 @@
  16995. // Correct values of the cache and index registers are preserved.
  16996. void TemplateTable::jvmti_post_field_access(Register cache,
  16997. Register index,
  16998. + int byte_no,
  16999. bool is_static,
  17000. bool has_tos) {
  17001. if (JvmtiExport::can_post_field_access()) {
  17002. @@ -2230,7 +2247,11 @@
  17003. // cache: cache entry pointer
  17004. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
  17005. rax, cache);
  17006. - __ get_cache_and_index_at_bcp(cache, index, 1);
  17007. +
  17008. + // (tw) Redefinition might have occured => reresolve the cp entry.
  17009. + __ restore_bcp();
  17010. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  17011. +
  17012. __ bind(L1);
  17013. }
  17014. }
  17015. @@ -2251,7 +2272,7 @@
  17016. const Register flags = rax;
  17017. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  17018. - jvmti_post_field_access(cache, index, is_static, false);
  17019. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  17020. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  17021. if (!is_static) pop_and_check_object(obj);
  17022. @@ -2386,7 +2407,7 @@
  17023. // The registers cache and index expected to be set before call.
  17024. // The function may destroy various registers, just not the cache and index registers.
  17025. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  17026. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  17027. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  17028. @@ -2444,7 +2465,11 @@
  17029. // rcx: jvalue object on the stack
  17030. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
  17031. rbx, rax, rcx);
  17032. - __ get_cache_and_index_at_bcp(cache, index, 1);
  17033. +
  17034. + // (tw) Redefinition might have occured => reresolve the cp entry.
  17035. + __ restore_bcp();
  17036. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  17037. +
  17038. __ bind(L1);
  17039. }
  17040. }
  17041. @@ -2460,7 +2485,7 @@
  17042. const Register flags = rax;
  17043. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  17044. - jvmti_post_field_mod(cache, index, is_static);
  17045. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  17046. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  17047. // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  17048. @@ -2683,6 +2708,11 @@
  17049. // rax,: cache entry pointer
  17050. // rcx: jvalue object on the stack
  17051. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, rax, rcx);
  17052. +
  17053. + // (tw) Redefinition might have occured => reresolve the cp entry.
  17054. + __ restore_bcp();
  17055. + resolve_cache_and_index(2, noreg, rax, rcx, sizeof(u2));
  17056. +
  17057. if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx); // restore high value
  17058. __ pop(rax); // restore lower value
  17059. __ addptr(rsp, sizeof(jvalue)); // release jvalue object space
  17060. @@ -2803,6 +2833,11 @@
  17061. // rcx: cache entry pointer
  17062. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx);
  17063. __ pop_ptr(rax); // restore object pointer
  17064. +
  17065. + // (tw) Redefinition might have occured => reresolve the cp entry.
  17066. + __ restore_bcp();
  17067. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  17068. +
  17069. __ bind(L1);
  17070. }
  17071. @@ -2973,6 +3008,29 @@
  17072. __ bind(notFinal);
  17073. + Label notOld;
  17074. +
  17075. + // Check if we are calling an old method (and have to go slow path)
  17076. + __ movl(rax, flags);
  17077. + __ andl(rax, (1 << ConstantPoolCacheEntry::oldMethodBit));
  17078. + __ jcc(Assembler::zero, notOld);
  17079. +
  17080. + // Need a null check here!
  17081. + __ null_check(recv);
  17082. +
  17083. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  17084. + // (tw) TODO: Check if we can improve performance by inlining.
  17085. + // (tw) TODO: Check if this additional branch affects normal execution time.
  17086. + __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  17087. + // Method is now in rax
  17088. + __ mov(method, rax);
  17089. +
  17090. + // profile this call
  17091. + __ profile_final_call(rax);
  17092. + __ jump_from_interpreted(method, rdx);
  17093. +
  17094. + __ bind(notOld);
  17095. +
  17096. // get receiver klass
  17097. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  17098. // Keep recv in rcx for callee expects it there
  17099. @@ -3054,6 +3112,36 @@
  17100. invokevirtual_helper(rbx, rcx, rdx);
  17101. __ bind(notMethod);
  17102. +
  17103. + Label notOld;
  17104. +
  17105. + // Check if we are calling an old method (and have to go slow path)
  17106. + //__ movl(rax, rdx);
  17107. + __ andl(rdx, (1 << ConstantPoolCacheEntry::oldMethodBit));
  17108. + __ jcc(Assembler::zero, notOld);
  17109. +
  17110. + // Get receiver klass into rdx - also a null check
  17111. + __ movptr(rdx, Address(rcx, oopDesc::klass_offset_in_bytes()));
  17112. + __ verify_oop(rdx);
  17113. +
  17114. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  17115. + // (tw) TODO: Check if we can improve performance by inlining.
  17116. + // (tw) TODO: Check if this additional branch affects normal execution time.
  17117. + // (tw) TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  17118. + __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), rcx, rax, rbx);
  17119. +
  17120. + // Method is now in rax
  17121. + __ movptr(rbx, rax);
  17122. +
  17123. + // (tw) TODO: Check if resolved method could be null.
  17124. +
  17125. + // profile this call
  17126. + __ profile_virtual_call(rdx, rsi, rdi);
  17127. +
  17128. + __ jump_from_interpreted(rbx, rdx);
  17129. +
  17130. + __ bind(notOld);
  17131. +
  17132. // Get receiver klass into rdx - also a null check
  17133. __ restore_locals(); // restore rdi
  17134. __ movptr(rdx, Address(rcx, oopDesc::klass_offset_in_bytes()));
  17135. diff -r f5603a6e5042 src/cpu/x86/vm/templateTable_x86_64.cpp
  17136. --- a/src/cpu/x86/vm/templateTable_x86_64.cpp Wed Nov 17 22:42:08 2010 -0800
  17137. +++ b/src/cpu/x86/vm/templateTable_x86_64.cpp Fri Dec 17 13:23:04 2010 +0100
  17138. @@ -2113,6 +2113,22 @@
  17139. // resolve first time through
  17140. address entry;
  17141. switch (bytecode()) {
  17142. + case Bytecodes::_fast_agetfield : // fall through
  17143. + case Bytecodes::_fast_bgetfield : // fall through
  17144. + case Bytecodes::_fast_cgetfield : // fall through
  17145. + case Bytecodes::_fast_dgetfield : // fall through
  17146. + case Bytecodes::_fast_fgetfield : // fall through
  17147. + case Bytecodes::_fast_igetfield : // fall through
  17148. + case Bytecodes::_fast_lgetfield : // fall through
  17149. + case Bytecodes::_fast_sgetfield : // fall through
  17150. + case Bytecodes::_fast_aputfield : // fall through
  17151. + case Bytecodes::_fast_bputfield : // fall through
  17152. + case Bytecodes::_fast_cputfield : // fall through
  17153. + case Bytecodes::_fast_dputfield : // fall through
  17154. + case Bytecodes::_fast_fputfield : // fall through
  17155. + case Bytecodes::_fast_iputfield : // fall through
  17156. + case Bytecodes::_fast_lputfield : // fall through
  17157. + case Bytecodes::_fast_sputfield : // fall through
  17158. case Bytecodes::_getstatic:
  17159. case Bytecodes::_putstatic:
  17160. case Bytecodes::_getfield:
  17161. @@ -2219,7 +2235,7 @@
  17162. // The registers cache and index expected to be set before call.
  17163. // Correct values of the cache and index registers are preserved.
  17164. void TemplateTable::jvmti_post_field_access(Register cache, Register index,
  17165. - bool is_static, bool has_tos) {
  17166. + int byte_no, bool is_static, bool has_tos) {
  17167. // do the JVMTI work here to avoid disturbing the register state below
  17168. // We use c_rarg registers here because we want to use the register used in
  17169. // the call to the VM
  17170. @@ -2250,7 +2266,11 @@
  17171. __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  17172. InterpreterRuntime::post_field_access),
  17173. c_rarg1, c_rarg2, c_rarg3);
  17174. - __ get_cache_and_index_at_bcp(cache, index, 1);
  17175. +
  17176. + // (tw) Redefinition might have occured => reresolve the cp entry.
  17177. + __ restore_bcp();
  17178. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  17179. +
  17180. __ bind(L1);
  17181. }
  17182. }
  17183. @@ -2272,7 +2292,7 @@
  17184. const Register bc = c_rarg3; // uses same reg as obj, so don't mix them
  17185. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  17186. - jvmti_post_field_access(cache, index, is_static, false);
  17187. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  17188. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  17189. if (!is_static) {
  17190. @@ -2406,7 +2426,7 @@
  17191. // The registers cache and index expected to be set before call.
  17192. // The function may destroy various registers, just not the cache and index registers.
  17193. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  17194. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  17195. transition(vtos, vtos);
  17196. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  17197. @@ -2459,7 +2479,11 @@
  17198. CAST_FROM_FN_PTR(address,
  17199. InterpreterRuntime::post_field_modification),
  17200. c_rarg1, c_rarg2, c_rarg3);
  17201. - __ get_cache_and_index_at_bcp(cache, index, 1);
  17202. +
  17203. + // (tw) Redefinition might have occured => reresolve the cp entry.
  17204. + __ restore_bcp();
  17205. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  17206. +
  17207. __ bind(L1);
  17208. }
  17209. }
  17210. @@ -2475,7 +2499,7 @@
  17211. const Register bc = c_rarg3;
  17212. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  17213. - jvmti_post_field_mod(cache, index, is_static);
  17214. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  17215. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  17216. // [jk] not needed currently
  17217. @@ -2661,6 +2685,11 @@
  17218. CAST_FROM_FN_PTR(address,
  17219. InterpreterRuntime::post_field_modification),
  17220. rbx, c_rarg2, c_rarg3);
  17221. +
  17222. + // (tw) Redefinition might have occured => reresolve the cp entry.
  17223. + __ restore_bcp();
  17224. + resolve_cache_and_index(2, noreg, rax, rcx, sizeof(u2));
  17225. +
  17226. __ pop(rax); // restore lower value
  17227. __ addptr(rsp, sizeof(jvalue)); // release jvalue object space
  17228. __ bind(L2);
  17229. @@ -2762,6 +2791,11 @@
  17230. c_rarg1, c_rarg2);
  17231. __ mov(rax, r12); // restore object pointer
  17232. __ reinit_heapbase();
  17233. +
  17234. + // (tw) Redefinition might have occured => reresolve the cp entry.
  17235. + __ restore_bcp();
  17236. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  17237. +
  17238. __ bind(L1);
  17239. }
  17240. @@ -2977,6 +3011,29 @@
  17241. __ bind(notFinal);
  17242. + Label notOld;
  17243. +
  17244. + // Check if we are calling an old method (and have to go slow path)
  17245. + __ movl(rax, flags);
  17246. + __ andl(rax, (1 << ConstantPoolCacheEntry::oldMethodBit));
  17247. + __ jcc(Assembler::zero, notOld);
  17248. +
  17249. + // Need a null check here!
  17250. + __ null_check(recv);
  17251. +
  17252. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  17253. + // (tw) TODO: Check if we can improve performance by inlining.
  17254. + // (tw) TODO: Check if this additional branch affects normal execution time.
  17255. + __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_method), recv, index);
  17256. + // Method is now in rax
  17257. + __ mov(method, rax);
  17258. +
  17259. + // profile this call
  17260. + __ profile_final_call(rax);
  17261. + __ jump_from_interpreted(method, rdx);
  17262. +
  17263. + __ bind(notOld);
  17264. +
  17265. // get receiver klass
  17266. __ null_check(recv, oopDesc::klass_offset_in_bytes());
  17267. __ load_klass(rax, recv);
  17268. @@ -3060,6 +3117,35 @@
  17269. invokevirtual_helper(rbx, rcx, rdx);
  17270. __ bind(notMethod);
  17271. + Label notOld;
  17272. +
  17273. + // Check if we are calling an old method (and have to go slow path)
  17274. + //__ movl(rax, rdx);
  17275. + __ andl(rdx, (1 << ConstantPoolCacheEntry::oldMethodBit));
  17276. + __ jcc(Assembler::zero, notOld);
  17277. +
  17278. + // Get receiver klass into rdx - also a null check
  17279. + __ movptr(rdx, Address(rcx, oopDesc::klass_offset_in_bytes()));
  17280. + __ verify_oop(rdx);
  17281. +
  17282. + // Call out to VM to do look up based on correct vTable version (has to iterate back over the class history of the receiver class)
  17283. + // (tw) TODO: Check if we can improve performance by inlining.
  17284. + // (tw) TODO: Check if this additional branch affects normal execution time.
  17285. + // (tw) TODO: Check the exact semantic (with respect to destoying registers) of call_VM
  17286. + __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::find_correct_interface_method), rcx, rax, rbx);
  17287. +
  17288. + // Method is now in rax
  17289. + __ movptr(rbx, rax);
  17290. +
  17291. + // (tw) TODO: Check if resolved method could be null.
  17292. +
  17293. + // profile this call
  17294. + __ profile_virtual_call(rdx, rsi, rdi);
  17295. +
  17296. + __ jump_from_interpreted(rbx, rdx);
  17297. +
  17298. + __ bind(notOld);
  17299. +
  17300. // Get receiver klass into rdx - also a null check
  17301. __ restore_locals(); // restore r14
  17302. __ load_klass(rdx, rcx);
  17303. diff -r f5603a6e5042 src/share/tools/MakeDeps/BuildConfig.java
  17304. --- a/src/share/tools/MakeDeps/BuildConfig.java Wed Nov 17 22:42:08 2010 -0800
  17305. +++ b/src/share/tools/MakeDeps/BuildConfig.java Fri Dec 17 13:23:04 2010 +0100
  17306. @@ -242,7 +242,20 @@
  17307. void initDefaultDefines(Vector defines) {
  17308. Vector sysDefines = new Vector();
  17309. - sysDefines.add("WIN32");
  17310. +
  17311. + if( Util.os().equals("Win32")) {
  17312. + sysDefines.add("WIN32");
  17313. + sysDefines.add("HOTSPOT_LIB_ARCH=\\\"i386\\\"");
  17314. + } else {
  17315. + sysDefines.add("_AMD64_");
  17316. + sysDefines.add("AMD64");
  17317. + sysDefines.add("_WIN64");
  17318. + sysDefines.add("_LP64");
  17319. + if (System.getenv("MSC_VER") != null)
  17320. + sysDefines.add("MSC_VER=" + System.getenv("MSC_VER"));
  17321. + sysDefines.add("HOTSPOT_LIB_ARCH=\\\"amd64\\\"");
  17322. + }
  17323. +
  17324. sysDefines.add("_WINDOWS");
  17325. sysDefines.add("HOTSPOT_BUILD_USER="+System.getProperty("user.name"));
  17326. sysDefines.add("HOTSPOT_BUILD_TARGET=\\\""+get("Build")+"\\\"");
  17327. diff -r f5603a6e5042 src/share/tools/MakeDeps/Util.java
  17328. --- a/src/share/tools/MakeDeps/Util.java Wed Nov 17 22:42:08 2010 -0800
  17329. +++ b/src/share/tools/MakeDeps/Util.java Fri Dec 17 13:23:04 2010 +0100
  17330. @@ -84,5 +84,26 @@
  17331. }
  17332. static String sep = File.separator;
  17333. - static String os = "Win32"; //System.getProperty("os.name");
  17334. +
  17335. + private static String _os;
  17336. +
  17337. + static String os() {
  17338. + if( _os==null) {
  17339. +
  17340. + for(Map.Entry<String, String> entry: System.getenv().entrySet())
  17341. + if("PLATFORM_ARCH_MODEL".equals(entry.getKey().toUpperCase())) {
  17342. + String archModel = entry.getValue();
  17343. + if("x86_32".equals(archModel))
  17344. + _os = "Win32";
  17345. + else if("x86_64".equals(archModel))
  17346. + _os = "x64";
  17347. + else
  17348. + throw new RuntimeException("Unsupported PLATFORM_ARCH_MODEL " + archModel);
  17349. + return _os;
  17350. + }
  17351. + throw new RuntimeException("PLATFORM_ARCH_MODEL not specified");
  17352. + }
  17353. + return _os;
  17354. + }
  17355. +
  17356. }
  17357. diff -r f5603a6e5042 src/share/tools/MakeDeps/WinGammaPlatformVC6.java
  17358. --- a/src/share/tools/MakeDeps/WinGammaPlatformVC6.java Wed Nov 17 22:42:08 2010 -0800
  17359. +++ b/src/share/tools/MakeDeps/WinGammaPlatformVC6.java Fri Dec 17 13:23:04 2010 +0100
  17360. @@ -236,7 +236,7 @@
  17361. " /nologo /base:\"0x8000000\" /subsystem:windows /dll" +
  17362. " /export:JNI_GetDefaultJavaVMInitArgs /export:JNI_CreateJavaVM /export:JNI_GetCreatedJavaVMs "+
  17363. " /export:jio_snprintf /export:jio_printf /export:jio_fprintf /export:jio_vfprintf "+
  17364. - " /export:jio_vsnprintf ");
  17365. + " /export:jio_vsnprintf /export:JVM_GetVersionInfo /export:JVM_GetThreadStateNames /export:JVM_GetThreadStateValues /export:JVM_InitAgentProperties /export:JVM_FindClassFromBootLoader");
  17366. rv.add("SUBTRACT LINK32 /pdb:none /map");
  17367. return rv;
  17368. @@ -286,6 +286,6 @@
  17369. }
  17370. String makeCfgName(String flavourBuild) {
  17371. - return "vm - "+ Util.os + " " + flavourBuild;
  17372. + return "vm - "+ "Win32" + " " + flavourBuild;
  17373. }
  17374. }
  17375. diff -r f5603a6e5042 src/share/tools/MakeDeps/WinGammaPlatformVC7.java
  17376. --- a/src/share/tools/MakeDeps/WinGammaPlatformVC7.java Wed Nov 17 22:42:08 2010 -0800
  17377. +++ b/src/share/tools/MakeDeps/WinGammaPlatformVC7.java Fri Dec 17 13:23:04 2010 +0100
  17378. @@ -51,7 +51,7 @@
  17379. );
  17380. startTag("Platforms", null);
  17381. - tag("Platform", new String[] {"Name", Util.os});
  17382. + tag("Platform", new String[] {"Name", Util.os()});
  17383. endTag("Platforms");
  17384. startTag("Configurations", null);
  17385. @@ -467,7 +467,7 @@
  17386. "PreprocessorDefinitions", "NDEBUG",
  17387. "MkTypLibCompatible", "TRUE",
  17388. "SuppressStartupBanner", "TRUE",
  17389. - "TargetEnvironment", "1",
  17390. + "TargetEnvironment", Util.os().equals("Win32") ? "1" : "3",
  17391. "TypeLibraryName", cfg.get("OutputDir") + Util.sep + "vm.tlb",
  17392. "HeaderFileName", ""
  17393. }
  17394. @@ -596,7 +596,7 @@
  17395. "/export:JNI_GetCreatedJavaVMs "+
  17396. "/export:jio_snprintf /export:jio_printf "+
  17397. "/export:jio_fprintf /export:jio_vfprintf "+
  17398. - "/export:jio_vsnprintf ");
  17399. + "/export:jio_vsnprintf /export:JVM_GetVersionInfo /export:JVM_GetThreadStateNames /export:JVM_GetThreadStateValues /export:JVM_InitAgentProperties /export:JVM_FindClassFromBootLoader");
  17400. addAttr(rv, "AdditionalDependencies", "Wsock32.lib winmm.lib");
  17401. addAttr(rv, "OutputFile", outDll);
  17402. // Set /INCREMENTAL option. 1 is linkIncrementalNo
  17403. @@ -609,7 +609,7 @@
  17404. addAttr(rv, "BaseAddress", "0x8000000");
  17405. addAttr(rv, "ImportLibrary", outDir+Util.sep+"jvm.lib");
  17406. // Set /MACHINE option. 1 is machineX86
  17407. - addAttr(rv, "TargetMachine", "1");
  17408. + addAttr(rv, "TargetMachine", Util.os().equals("Win32") ? "1" : "17");
  17409. return rv;
  17410. }
  17411. @@ -687,6 +687,6 @@
  17412. }
  17413. String makeCfgName(String flavourBuild) {
  17414. - return flavourBuild + "|" + Util.os;
  17415. + return flavourBuild + "|" + Util.os();
  17416. }
  17417. }
  17418. diff -r f5603a6e5042 src/share/tools/MakeDeps/WinGammaPlatformVC8.java
  17419. --- a/src/share/tools/MakeDeps/WinGammaPlatformVC8.java Wed Nov 17 22:42:08 2010 -0800
  17420. +++ b/src/share/tools/MakeDeps/WinGammaPlatformVC8.java Fri Dec 17 13:23:04 2010 +0100
  17421. @@ -41,6 +41,9 @@
  17422. addAttr(rv, "UsePrecompiledHeader", "2");
  17423. // Set /EHsc- option. 0 is cppExceptionHandlingNo
  17424. addAttr(rv, "ExceptionHandling", "0");
  17425. + // Parallel compilation
  17426. + addAttr(rv, "AdditionalOptions", "/MP");
  17427. +
  17428. return rv;
  17429. }
  17430. diff -r f5603a6e5042 src/share/vm/c1/c1_Compilation.hpp
  17431. --- a/src/share/vm/c1/c1_Compilation.hpp Wed Nov 17 22:42:08 2010 -0800
  17432. +++ b/src/share/vm/c1/c1_Compilation.hpp Fri Dec 17 13:23:04 2010 +0100
  17433. @@ -232,8 +232,8 @@
  17434. #define BAILOUT(msg) { bailout(msg); return; }
  17435. #define BAILOUT_(msg, res) { bailout(msg); return res; }
  17436. -#define CHECK_BAILOUT() { if (bailed_out()) return; }
  17437. -#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
  17438. +#define CHECK_BAILOUT() { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return; }
  17439. +#define CHECK_BAILOUT_(res) { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return res; }
  17440. class InstructionMark: public StackObj {
  17441. diff -r f5603a6e5042 src/share/vm/c1/c1_LIRGenerator.cpp
  17442. --- a/src/share/vm/c1/c1_LIRGenerator.cpp Wed Nov 17 22:42:08 2010 -0800
  17443. +++ b/src/share/vm/c1/c1_LIRGenerator.cpp Fri Dec 17 13:23:04 2010 +0100
  17444. @@ -2498,7 +2498,7 @@
  17445. // Load CallSite object from constant pool cache.
  17446. __ oop2reg(cpcache->constant_encoding(), tmp);
  17447. - __ load(new LIR_Address(tmp, call_site_offset, T_OBJECT), tmp);
  17448. + __ load(new LIR_Address(tmp, (int)call_site_offset, T_OBJECT), tmp);
  17449. // Load target MethodHandle from CallSite object.
  17450. __ load(new LIR_Address(tmp, java_dyn_CallSite::target_offset_in_bytes(), T_OBJECT), receiver);
  17451. diff -r f5603a6e5042 src/share/vm/ci/ciEnv.cpp
  17452. --- a/src/share/vm/ci/ciEnv.cpp Wed Nov 17 22:42:08 2010 -0800
  17453. +++ b/src/share/vm/ci/ciEnv.cpp Fri Dec 17 13:23:04 2010 +0100
  17454. @@ -1075,3 +1075,11 @@
  17455. // If memory is low, we stop compiling methods.
  17456. record_method_not_compilable("out of memory");
  17457. }
  17458. +
  17459. +// (tw) Called after class redefinition to clean up possibly invalidated state.
  17460. +void ciEnv::cleanup_after_redefinition() {
  17461. +
  17462. + if (_factory != NULL) {
  17463. + _factory->cleanup_after_redefinition();
  17464. + }
  17465. +}
  17466. \ No newline at end of file
  17467. diff -r f5603a6e5042 src/share/vm/ci/ciEnv.hpp
  17468. --- a/src/share/vm/ci/ciEnv.hpp Wed Nov 17 22:42:08 2010 -0800
  17469. +++ b/src/share/vm/ci/ciEnv.hpp Fri Dec 17 13:23:04 2010 +0100
  17470. @@ -383,4 +383,6 @@
  17471. void record_failure(const char* reason);
  17472. void record_method_not_compilable(const char* reason, bool all_tiers = true);
  17473. void record_out_of_memory_failure();
  17474. +
  17475. + void cleanup_after_redefinition();
  17476. };
  17477. diff -r f5603a6e5042 src/share/vm/ci/ciObjectFactory.cpp
  17478. --- a/src/share/vm/ci/ciObjectFactory.cpp Wed Nov 17 22:42:08 2010 -0800
  17479. +++ b/src/share/vm/ci/ciObjectFactory.cpp Fri Dec 17 13:23:04 2010 +0100
  17480. @@ -255,6 +255,11 @@
  17481. // into the table. We need to recompute our index.
  17482. index = find(keyHandle(), _ci_objects);
  17483. }
  17484. +
  17485. + if (is_found_at(index, keyHandle(), _ci_objects)) {
  17486. + // (tw) Check if this is an error? Can occur when redefining classes.
  17487. + return _ci_objects->at(index);
  17488. + }
  17489. assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert");
  17490. insert(index, new_object, _ci_objects);
  17491. return new_object;
  17492. @@ -711,3 +716,50 @@
  17493. _unloaded_instances->length(),
  17494. _unloaded_klasses->length());
  17495. }
  17496. +
  17497. +// (tw) Resoring the ciObject arrays after class redefinition
  17498. +void ciObjectFactory::sort_ci_objects(GrowableArray<ciObject*>* objects) {
  17499. +
  17500. + // Resort the _ci_objects array. The order of two class pointers can be changed during class redefinition.
  17501. + oop last = NULL;
  17502. + for (int j = 0; j< objects->length(); j++) {
  17503. + oop o = objects->at(j)->get_oop();
  17504. + if (last >= o) {
  17505. + int cur_last_index = j - 1;
  17506. + oop cur_last = last;
  17507. + while (cur_last >= o) {
  17508. +
  17509. + // Swap the two objects to guarantee ordering
  17510. + ciObject *tmp = objects->at(cur_last_index);
  17511. + objects->at_put(cur_last_index, objects->at(cur_last_index + 1));
  17512. + objects->at_put(cur_last_index + 1, tmp);
  17513. +
  17514. + // Decrement index to move one step to the left
  17515. + cur_last_index--;
  17516. + if (cur_last_index < 0) {
  17517. + break;
  17518. + }
  17519. + cur_last =objects->at(cur_last_index)->get_oop();
  17520. + }
  17521. + } else {
  17522. + assert(last < o, "out of order");
  17523. + last = o;
  17524. + }
  17525. + }
  17526. +
  17527. +#ifdef ASSERT
  17528. + if (CIObjectFactoryVerify) {
  17529. + oop last = NULL;
  17530. + for (int j = 0; j< objects->length(); j++) {
  17531. + oop o = objects->at(j)->get_oop();
  17532. + assert(last < o, "out of order");
  17533. + last = o;
  17534. + }
  17535. + }
  17536. +#endif // ASSERT
  17537. +}
  17538. +
  17539. +// (tw) Called after class redefinition to clean up possibly invalidated state.
  17540. +void ciObjectFactory::cleanup_after_redefinition() {
  17541. + sort_ci_objects(_ci_objects);
  17542. +}
  17543. \ No newline at end of file
  17544. diff -r f5603a6e5042 src/share/vm/ci/ciObjectFactory.hpp
  17545. --- a/src/share/vm/ci/ciObjectFactory.hpp Wed Nov 17 22:42:08 2010 -0800
  17546. +++ b/src/share/vm/ci/ciObjectFactory.hpp Fri Dec 17 13:23:04 2010 +0100
  17547. @@ -29,6 +29,10 @@
  17548. // which ensures that for each oop, at most one ciObject is created.
  17549. // This invariant allows efficient implementation of ciObject.
  17550. class ciObjectFactory : public ResourceObj {
  17551. +
  17552. + friend class ciEnv;
  17553. + friend class CompileBroker;
  17554. +
  17555. private:
  17556. static volatile bool _initialized;
  17557. static GrowableArray<ciObject*>* _shared_ci_objects;
  17558. @@ -122,4 +126,9 @@
  17559. void print_contents();
  17560. void print();
  17561. +
  17562. +private:
  17563. +
  17564. + static void sort_ci_objects(GrowableArray<ciObject*>* objects);
  17565. + void cleanup_after_redefinition();
  17566. };
  17567. diff -r f5603a6e5042 src/share/vm/classfile/classFileParser.cpp
  17568. --- a/src/share/vm/classfile/classFileParser.cpp Wed Nov 17 22:42:08 2010 -0800
  17569. +++ b/src/share/vm/classfile/classFileParser.cpp Fri Dec 17 13:23:04 2010 +0100
  17570. @@ -833,6 +833,7 @@
  17571. Handle class_loader,
  17572. Handle protection_domain,
  17573. symbolHandle class_name,
  17574. + KlassHandle old_klass,
  17575. TRAPS) {
  17576. ClassFileStream* cfs = stream();
  17577. assert(length > 0, "only called for length>0");
  17578. @@ -851,6 +852,9 @@
  17579. interface_index, CHECK_(nullHandle));
  17580. if (cp->tag_at(interface_index).is_klass()) {
  17581. interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
  17582. + if (!old_klass.is_null() && !interf->is_newest_version()) {
  17583. + interf = KlassHandle(THREAD, interf->newest_version());
  17584. + }
  17585. } else {
  17586. symbolHandle unresolved_klass (THREAD, cp->klass_name_at(interface_index));
  17587. @@ -863,6 +867,9 @@
  17588. klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
  17589. unresolved_klass, class_loader, protection_domain,
  17590. false, CHECK_(nullHandle));
  17591. + if (!old_klass.is_null()) {
  17592. + k = k->klass_part()->newest_version();
  17593. + }
  17594. interf = KlassHandle(THREAD, k);
  17595. if (LinkWellKnownClasses) // my super type is well known to me
  17596. @@ -1706,6 +1713,8 @@
  17597. int runtime_invisible_parameter_annotations_length = 0;
  17598. u1* annotation_default = NULL;
  17599. int annotation_default_length = 0;
  17600. + u2 code_section_table_length;
  17601. + typeArrayHandle code_section_table;
  17602. // Parse code and exceptions attribute
  17603. u2 method_attributes_count = cfs->get_u2_fast();
  17604. @@ -1805,7 +1814,6 @@
  17605. // Parse and compress line number table
  17606. parse_linenumber_table(code_attribute_length, code_length,
  17607. &linenumber_table, CHECK_(nullHandle));
  17608. -
  17609. } else if (LoadLocalVariableTables &&
  17610. cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_table()) {
  17611. // Parse local variable table
  17612. @@ -1875,6 +1883,24 @@
  17613. parse_stackmap_table(code_attribute_length, CHECK_(nullHandle));
  17614. stackmap_data = typeArrayHandle(THREAD, sm);
  17615. parsed_stackmap_attribute = true;
  17616. + } else if (UseMethodForwardPoints && cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_code_sections()) {
  17617. + int length = code_attribute_length;
  17618. + int value_count = length / sizeof(u2);
  17619. + int line_count = length / 3;
  17620. + if (TraceRedefineClasses >= 3) {
  17621. + tty->print_cr("Found code section attribute when loading class with %d entries", value_count, line_count);
  17622. + }
  17623. + code_section_table_length = value_count;
  17624. + code_section_table = oopFactory::new_permanent_shortArray(value_count, CHECK_NULL);
  17625. + code_section_table->set_length(value_count);
  17626. +
  17627. + for (int i = 0; i < value_count; ++i) {
  17628. + u2 value = cfs->get_u2(CHECK_(nullHandle));
  17629. + code_section_table->short_at_put(i, value);
  17630. + if (TraceRedefineClasses >= 4) {
  17631. + tty->print_cr("Code section table at %d: %d", i, value);
  17632. + }
  17633. + }
  17634. } else {
  17635. // Skip unknown attributes
  17636. cfs->skip_u1(code_attribute_length, CHECK_(nullHandle));
  17637. @@ -1996,6 +2022,18 @@
  17638. }
  17639. #endif
  17640. + // (tw) TODO: Get a different solution for the problem of method forward
  17641. + // points and variable sized interpreter frames.
  17642. + if (UseMethodForwardPoints) {
  17643. + if (max_stack > MethodForwardPointsMaxStack) {
  17644. + fatal(err_msg("Method has too large stack (%d), increase the value of MethodForwardPointsMaxStack (%d)", max_stack, MethodForwardPointsMaxStack));
  17645. + }
  17646. + if (max_locals > MethodForwardPointsMaxLocals) {
  17647. + fatal(err_msg("Method has too many locals (%d), increase the value of MethodForwardPointsMaxLocals (%d)", max_stack, MethodForwardPointsMaxStack));
  17648. + }
  17649. + max_stack = MethodForwardPointsMaxStack;
  17650. + max_locals = MethodForwardPointsMaxLocals;
  17651. + }
  17652. // Fill in code attribute information
  17653. m->set_max_stack(max_stack);
  17654. m->set_max_locals(max_locals);
  17655. @@ -2010,6 +2048,8 @@
  17656. */
  17657. m->set_exception_table(exception_handlers());
  17658. + m->constMethod()->set_code_section_table(code_section_table());
  17659. +
  17660. // Copy byte codes
  17661. m->set_code(code_start);
  17662. @@ -2469,6 +2509,24 @@
  17663. "Invalid Deprecated classfile attribute length %u in class file %s",
  17664. attribute_length, CHECK);
  17665. }
  17666. + // (tw) Check for deleted field attribute
  17667. + } else if (tag == vmSymbols::tag_field_redefinition_policy()) {
  17668. +
  17669. + char field_redefinition_policy = cfs->get_u1_fast();
  17670. + k->set_field_redefinition_policy(field_redefinition_policy);
  17671. +
  17672. + // (tw) Check for deleted static field attribute
  17673. + } else if (tag == vmSymbols::tag_static_field_redefinition_policy()) {
  17674. +
  17675. + char static_field_redefinition_policy = cfs->get_u1_fast();
  17676. + k->set_static_field_redefinition_policy(static_field_redefinition_policy);
  17677. +
  17678. + // (tw) Check for deleted method attribute
  17679. + } else if (tag == vmSymbols::tag_method_redefinition_policy()) {
  17680. +
  17681. + char method_redefinition_policy = cfs->get_u1_fast();
  17682. + k->set_method_redefinition_policy(method_redefinition_policy);
  17683. +
  17684. } else if (_major_version >= JAVA_1_5_VERSION) {
  17685. if (tag == vmSymbols::tag_signature()) {
  17686. if (attribute_length != 2) {
  17687. @@ -2549,7 +2607,7 @@
  17688. }
  17689. -static void initialize_static_field(fieldDescriptor* fd, TRAPS) {
  17690. +void ClassFileParser::initialize_static_field(fieldDescriptor* fd, TRAPS) {
  17691. KlassHandle h_k (THREAD, fd->field_holder());
  17692. assert(h_k.not_null() && fd->is_static(), "just checking");
  17693. if (fd->has_initial_value()) {
  17694. @@ -2746,6 +2804,123 @@
  17695. (*next_nonstatic_oop_offset_ptr) += (extra * heapOopSize);
  17696. }
  17697. +// (tw) Finds the super symbols by reading the bytes of the class and returns
  17698. +// them in a growable array.
  17699. +void ClassFileParser::findSuperSymbols(symbolHandle name,
  17700. + Handle class_loader,
  17701. + Handle protection_domain,
  17702. + KlassHandle old_klass,
  17703. + GrowableArray<symbolHandle> &handles,
  17704. + TRAPS) {
  17705. +
  17706. + _cp_patches = NULL;
  17707. + // So that JVMTI can cache class file in the state before retransformable agents
  17708. + // have modified it
  17709. + unsigned char *cached_class_file_bytes = NULL;
  17710. +
  17711. + ClassFileStream* cfs = stream();
  17712. +
  17713. + _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
  17714. +
  17715. + instanceKlassHandle nullHandle;
  17716. +
  17717. + // Save the class file name for easier error message printing.
  17718. + _class_name = name.not_null()? name : vmSymbolHandles::unknown_class_name();
  17719. +
  17720. + cfs->guarantee_more(8, CHECK); // magic, major, minor
  17721. + // Magic value
  17722. + u4 magic = cfs->get_u4_fast();
  17723. + if (magic != JAVA_CLASSFILE_MAGIC) {
  17724. + // Invalid class file!
  17725. + return;
  17726. + }
  17727. +
  17728. + // Version numbers
  17729. + u2 minor_version = cfs->get_u2_fast();
  17730. + u2 major_version = cfs->get_u2_fast();
  17731. +
  17732. + // Check version numbers - we check this even with verifier off
  17733. + if (!is_supported_version(major_version, minor_version)) {
  17734. +
  17735. + // Unsupported version!
  17736. + return;
  17737. + }
  17738. +
  17739. + _major_version = major_version;
  17740. + _minor_version = minor_version;
  17741. +
  17742. +
  17743. + // Check if verification needs to be relaxed for this class file
  17744. + // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
  17745. + _relax_verify = Verifier::relax_verify_for(class_loader());
  17746. + _need_verify = false;
  17747. +
  17748. + // Constant pool
  17749. + constantPoolHandle cp = parse_constant_pool(CHECK);
  17750. + int cp_size = cp->length();
  17751. +
  17752. + cfs->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
  17753. +
  17754. + // Access flags
  17755. + AccessFlags access_flags;
  17756. + jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
  17757. +
  17758. + if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
  17759. + // Set abstract bit for old class files for backward compatibility
  17760. + flags |= JVM_ACC_ABSTRACT;
  17761. + }
  17762. + access_flags.set_flags(flags);
  17763. +
  17764. + // This class and superclass
  17765. + instanceKlassHandle super_klass;
  17766. + u2 this_class_index = cfs->get_u2_fast();
  17767. + check_property(
  17768. + valid_cp_range(this_class_index, cp_size) &&
  17769. + cp->tag_at(this_class_index).is_unresolved_klass(),
  17770. + "Invalid this class index %u in constant pool in class file %s",
  17771. + this_class_index, CHECK);
  17772. +
  17773. + symbolHandle class_name (THREAD, cp->unresolved_klass_at(this_class_index));
  17774. + assert(class_name.not_null(), "class_name can't be null");
  17775. +
  17776. + // Update _class_name which could be null previously to be class_name
  17777. + _class_name = class_name;
  17778. +
  17779. + // (tw) DO NOT release all handles when parsing is done
  17780. + {// HandleMark hm(THREAD);
  17781. +
  17782. + // Checks if name in class file matches requested name
  17783. + if (name.not_null() && class_name() != name()) {
  17784. + return;
  17785. + }
  17786. +
  17787. + u2 super_class_index = cfs->get_u2_fast();
  17788. +
  17789. + if (super_class_index != 0) {
  17790. + symbolHandle super_class (THREAD, cp->klass_name_at(super_class_index));
  17791. + handles.append(super_class);
  17792. + } else {
  17793. + // (tw) This redefinition must be for the Object class.
  17794. + }
  17795. +
  17796. + // Interfaces
  17797. + u2 itfs_len = cfs->get_u2_fast();
  17798. + objArrayHandle local_interfaces;
  17799. + if (itfs_len == 0) {
  17800. + local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  17801. + } else {
  17802. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK);
  17803. + }
  17804. +
  17805. + for (int i=0; i<local_interfaces->length(); i++) {
  17806. + oop o = local_interfaces->obj_at(i);
  17807. + symbolHandle interface_handle (THREAD, ((klassOop)o)->klass_part()->name());
  17808. + handles.append(interface_handle);
  17809. + }
  17810. + }
  17811. +}
  17812. +
  17813. +
  17814. // Force MethodHandle.vmentry to be an unmanaged pointer.
  17815. // There is no way for a classfile to express this, so we must help it.
  17816. @@ -2819,6 +2994,7 @@
  17817. instanceKlassHandle ClassFileParser::parseClassFile(symbolHandle name,
  17818. Handle class_loader,
  17819. Handle protection_domain,
  17820. + KlassHandle old_klass,
  17821. KlassHandle host_klass,
  17822. GrowableArray<Handle>* cp_patches,
  17823. symbolHandle& parsed_name,
  17824. @@ -2847,10 +3023,13 @@
  17825. unsigned char* ptr = cfs->buffer();
  17826. unsigned char* end_ptr = cfs->buffer() + cfs->length();
  17827. + bool pretend_new_universe = Thread::current()->pretend_new_universe();
  17828. + Thread::current()->set_pretend_new_universe(false);
  17829. JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
  17830. &ptr, &end_ptr,
  17831. &cached_class_file_bytes,
  17832. &cached_class_file_length);
  17833. + Thread::current()->set_pretend_new_universe(pretend_new_universe);
  17834. if (ptr != cfs->buffer()) {
  17835. // JVMTI agent has modified class file data.
  17836. @@ -3001,7 +3180,11 @@
  17837. // However, make sure it is not an array type.
  17838. bool is_array = false;
  17839. if (cp->tag_at(super_class_index).is_klass()) {
  17840. - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
  17841. + klassOop resolved_klass = cp->resolved_klass_at(super_class_index);
  17842. + if (!old_klass.is_null()) {
  17843. + resolved_klass = resolved_klass->klass_part()->newest_version();
  17844. + }
  17845. + super_klass = instanceKlassHandle(THREAD, resolved_klass);
  17846. if (_need_verify)
  17847. is_array = super_klass->oop_is_array();
  17848. } else if (_need_verify) {
  17849. @@ -3019,7 +3202,7 @@
  17850. if (itfs_len == 0) {
  17851. local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  17852. } else {
  17853. - local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
  17854. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_(nullHandle));
  17855. }
  17856. // Fields (offsets are filled in later)
  17857. @@ -3063,7 +3246,9 @@
  17858. protection_domain,
  17859. true,
  17860. CHECK_(nullHandle));
  17861. -
  17862. + if (!old_klass.is_null()) {
  17863. + k = k->klass_part()->newest_version();
  17864. + }
  17865. KlassHandle kh (THREAD, k);
  17866. super_klass = instanceKlassHandle(THREAD, kh());
  17867. if (LinkWellKnownClasses) // my super class is well known to me
  17868. @@ -3490,6 +3675,19 @@
  17869. rt = REF_NONE;
  17870. } else {
  17871. rt = super_klass->reference_type();
  17872. +
  17873. + // (tw) With class redefinition, it can also happen that special classes are loaded.
  17874. + if (name() == vmSymbols::java_lang_ref_Reference()) {
  17875. + rt = REF_OTHER;
  17876. + } else if (name() == vmSymbols::java_lang_ref_SoftReference()) {
  17877. + rt = REF_SOFT;
  17878. + } else if (name() == vmSymbols::java_lang_ref_WeakReference()) {
  17879. + rt = REF_WEAK;
  17880. + } else if (name() == vmSymbols::java_lang_ref_FinalReference()) {
  17881. + rt = REF_FINAL;
  17882. + } else if (name() == vmSymbols::java_lang_ref_PhantomReference()) {
  17883. + rt = REF_PHANTOM;
  17884. + }
  17885. }
  17886. // We can now create the basic klassOop for this klass
  17887. @@ -3591,7 +3789,7 @@
  17888. // Do final class setup
  17889. fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
  17890. - set_precomputed_flags(this_klass);
  17891. + set_precomputed_flags(this_klass, old_klass);
  17892. // reinitialize modifiers, using the InnerClasses attribute
  17893. int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  17894. @@ -3611,6 +3809,10 @@
  17895. check_illegal_static_method(this_klass, CHECK_(nullHandle));
  17896. }
  17897. + if (rt == REF_OTHER) {
  17898. + instanceRefKlass::update_nonstatic_oop_maps(ik);
  17899. + }
  17900. +
  17901. ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()),
  17902. false /* not shared class */);
  17903. @@ -3753,7 +3955,7 @@
  17904. }
  17905. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  17906. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  17907. klassOop super = k->super();
  17908. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  17909. @@ -3761,7 +3963,9 @@
  17910. if (!_has_empty_finalizer) {
  17911. if (_has_finalizer ||
  17912. (super != NULL && super->klass_part()->has_finalizer())) {
  17913. - k->set_has_finalizer();
  17914. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  17915. + k->set_has_finalizer();
  17916. + }
  17917. }
  17918. }
  17919. @@ -3777,7 +3981,7 @@
  17920. // Check if this klass supports the java.lang.Cloneable interface
  17921. if (SystemDictionary::Cloneable_klass_loaded()) {
  17922. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  17923. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
  17924. k->set_is_cloneable();
  17925. }
  17926. }
  17927. diff -r f5603a6e5042 src/share/vm/classfile/classFileParser.hpp
  17928. --- a/src/share/vm/classfile/classFileParser.hpp Wed Nov 17 22:42:08 2010 -0800
  17929. +++ b/src/share/vm/classfile/classFileParser.hpp Fri Dec 17 13:23:04 2010 +0100
  17930. @@ -65,6 +65,7 @@
  17931. Handle class_loader,
  17932. Handle protection_domain,
  17933. symbolHandle class_name,
  17934. + KlassHandle old_klass,
  17935. TRAPS);
  17936. // Field parsing
  17937. @@ -135,7 +136,7 @@
  17938. unsigned int nonstatic_oop_map_count,
  17939. int* nonstatic_oop_offsets,
  17940. unsigned int* nonstatic_oop_counts);
  17941. - void set_precomputed_flags(instanceKlassHandle k);
  17942. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  17943. objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
  17944. objArrayHandle local_ifs, TRAPS);
  17945. @@ -265,21 +266,33 @@
  17946. instanceKlassHandle parseClassFile(symbolHandle name,
  17947. Handle class_loader,
  17948. Handle protection_domain,
  17949. + KlassHandle old_klass,
  17950. symbolHandle& parsed_name,
  17951. bool verify,
  17952. TRAPS) {
  17953. KlassHandle no_host_klass;
  17954. - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  17955. + return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, parsed_name, verify, THREAD);
  17956. }
  17957. instanceKlassHandle parseClassFile(symbolHandle name,
  17958. Handle class_loader,
  17959. Handle protection_domain,
  17960. + KlassHandle old_klass,
  17961. KlassHandle host_klass,
  17962. GrowableArray<Handle>* cp_patches,
  17963. symbolHandle& parsed_name,
  17964. bool verify,
  17965. TRAPS);
  17966. + static void initialize_static_field(fieldDescriptor* fd, TRAPS);
  17967. +
  17968. + // (tw) Creates symbol handles for the super class and the interfaces
  17969. + void findSuperSymbols(symbolHandle name,
  17970. + Handle class_loader,
  17971. + Handle protection_domain,
  17972. + KlassHandle old_klass,
  17973. + GrowableArray<symbolHandle> &handles,
  17974. + TRAPS);
  17975. +
  17976. // Verifier checks
  17977. static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
  17978. static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
  17979. diff -r f5603a6e5042 src/share/vm/classfile/classLoader.cpp
  17980. --- a/src/share/vm/classfile/classLoader.cpp Wed Nov 17 22:42:08 2010 -0800
  17981. +++ b/src/share/vm/classfile/classLoader.cpp Fri Dec 17 13:23:04 2010 +0100
  17982. @@ -164,7 +164,7 @@
  17983. if (file_handle != -1) {
  17984. // read contents into resource array
  17985. u1* buffer = NEW_RESOURCE_ARRAY(u1, st.st_size);
  17986. - size_t num_read = os::read(file_handle, (char*) buffer, st.st_size);
  17987. + size_t num_read = hpi::read(file_handle, (char*) buffer, st.st_size);
  17988. // close file
  17989. hpi::close(file_handle);
  17990. // construct ClassFileStream
  17991. @@ -872,6 +872,7 @@
  17992. instanceKlassHandle result = parser.parseClassFile(h_name,
  17993. class_loader,
  17994. protection_domain,
  17995. + KlassHandle(),
  17996. parsed_name,
  17997. false,
  17998. CHECK_(h));
  17999. diff -r f5603a6e5042 src/share/vm/classfile/dictionary.cpp
  18000. --- a/src/share/vm/classfile/dictionary.cpp Wed Nov 17 22:42:08 2010 -0800
  18001. +++ b/src/share/vm/classfile/dictionary.cpp Fri Dec 17 13:23:04 2010 +0100
  18002. @@ -149,8 +149,8 @@
  18003. int live_count = 0;
  18004. // RC_TRACE macro has an embedded ResourceMark
  18005. - RC_TRACE(0x00000200, ("unload: %s: previous version length=%d",
  18006. - ik->external_name(), ik->previous_versions()->length()));
  18007. + TRACE_RC4("unload: %s: previous version length=%d",
  18008. + ik->external_name(), ik->previous_versions()->length());
  18009. for (int i = ik->previous_versions()->length() - 1; i >= 0; i--) {
  18010. // check the previous versions array for GC'ed weak refs
  18011. @@ -175,7 +175,7 @@
  18012. gc_count++;
  18013. continue;
  18014. } else {
  18015. - RC_TRACE(0x00000200, ("unload: previous version @%d is alive", i));
  18016. + TRACE_RC4("unload: previous version @%d is alive", i);
  18017. if (is_alive->do_object_b(pvcp)) {
  18018. live_count++;
  18019. } else {
  18020. @@ -185,8 +185,7 @@
  18021. GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  18022. if (method_refs != NULL) {
  18023. - RC_TRACE(0x00000200, ("unload: previous methods length=%d",
  18024. - method_refs->length()));
  18025. + TRACE_RC4("unload: previous methods length=%d", method_refs->length());
  18026. for (int j = method_refs->length() - 1; j >= 0; j--) {
  18027. jweak method_ref = method_refs->at(j);
  18028. assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  18029. @@ -203,19 +202,14 @@
  18030. JNIHandles::destroy_weak_global(method_ref);
  18031. method_refs->remove_at(j);
  18032. } else {
  18033. - // RC_TRACE macro has an embedded ResourceMark
  18034. - RC_TRACE(0x00000200,
  18035. - ("unload: %s(%s): prev method @%d in version @%d is alive",
  18036. - method->name()->as_C_string(),
  18037. - method->signature()->as_C_string(), j, i));
  18038. + TRACE_RC4("unload: %s(%s): prev method @%d in version @%d is alive", method->name()->as_C_string(),
  18039. + method->signature()->as_C_string(), j, i);
  18040. }
  18041. }
  18042. }
  18043. }
  18044. assert(ik->previous_versions()->length() == live_count, "sanity check");
  18045. - RC_TRACE(0x00000200,
  18046. - ("unload: previous version stats: live=%d, GC'ed=%d", live_count,
  18047. - gc_count));
  18048. + TRACE_RC4("unload: previous version stats: live=%d, GC'ed=%d", live_count, gc_count);
  18049. }
  18050. // Non-unloadable classes were handled in always_strong_oops_do
  18051. @@ -321,6 +315,21 @@
  18052. }
  18053. }
  18054. +
  18055. +// (tw) Just the classes from defining class loaders
  18056. +void Dictionary::classes_do(ObjectClosure *closure) {
  18057. + for (int index = 0; index < table_size(); index++) {
  18058. + for (DictionaryEntry* probe = bucket(index);
  18059. + probe != NULL;
  18060. + probe = probe->next()) {
  18061. + klassOop k = probe->klass();
  18062. + if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
  18063. + closure->do_object(k);
  18064. + }
  18065. + }
  18066. + }
  18067. +}
  18068. +
  18069. // Added for initialize_itable_for_klass to handle exceptions
  18070. // Just the classes from defining class loaders
  18071. void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
  18072. @@ -428,6 +437,33 @@
  18073. add_entry(index, entry);
  18074. }
  18075. +// (tw) Updates the klass entry to point to the new klassOop. Necessary only for class redefinition.
  18076. +bool Dictionary::update_klass(int index, unsigned int hash, symbolHandle name, Handle loader, KlassHandle k, KlassHandle old_class) {
  18077. +
  18078. + // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
  18079. + bool found = false;
  18080. + for (int index = 0; index < table_size(); index++) {
  18081. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  18082. + if (entry->klass() == old_class()) {
  18083. + entry->set_literal(k());
  18084. + found = true;
  18085. + }
  18086. + }
  18087. + }
  18088. +
  18089. + return found;
  18090. +}
  18091. +
  18092. +// (tw) Undo previous updates to the system dictionary
  18093. +void Dictionary::rollback_redefinition() {
  18094. + for (int index = 0; index < table_size(); index++) {
  18095. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  18096. + if (entry->klass()->klass_part()->is_redefining()) {
  18097. + entry->set_literal(entry->klass()->klass_part()->old_version());
  18098. + }
  18099. + }
  18100. + }
  18101. +}
  18102. // This routine does not lock the system dictionary.
  18103. //
  18104. @@ -455,12 +491,21 @@
  18105. return NULL;
  18106. }
  18107. +klassOop Dictionary::intercept_for_version(klassOop k) {
  18108. + if (k == NULL) return k;
  18109. +
  18110. + if (k->klass_part()->is_redefining() && !Thread::current()->pretend_new_universe()) {
  18111. + return k->klass_part()->old_version();
  18112. + }
  18113. +
  18114. + return k;
  18115. +}
  18116. klassOop Dictionary::find(int index, unsigned int hash, symbolHandle name,
  18117. Handle loader, Handle protection_domain, TRAPS) {
  18118. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  18119. if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
  18120. - return entry->klass();
  18121. + return intercept_for_version(entry->klass());
  18122. } else {
  18123. return NULL;
  18124. }
  18125. @@ -473,7 +518,7 @@
  18126. assert (index == index_for(name, loader), "incorrect index?");
  18127. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  18128. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  18129. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  18130. }
  18131. @@ -485,7 +530,7 @@
  18132. assert (index == index_for(name, Handle()), "incorrect index?");
  18133. DictionaryEntry* entry = get_entry(index, hash, name, Handle());
  18134. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  18135. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  18136. }
  18137. diff -r f5603a6e5042 src/share/vm/classfile/dictionary.hpp
  18138. --- a/src/share/vm/classfile/dictionary.hpp Wed Nov 17 22:42:08 2010 -0800
  18139. +++ b/src/share/vm/classfile/dictionary.hpp Fri Dec 17 13:23:04 2010 +0100
  18140. @@ -65,6 +65,10 @@
  18141. void add_klass(symbolHandle class_name, Handle class_loader,KlassHandle obj);
  18142. + bool update_klass(int index, unsigned int hash, symbolHandle name, Handle loader, KlassHandle k, KlassHandle old_class);
  18143. +
  18144. + void rollback_redefinition();
  18145. +
  18146. klassOop find_class(int index, unsigned int hash,
  18147. symbolHandle name, Handle loader);
  18148. @@ -81,6 +85,7 @@
  18149. void classes_do(void f(klassOop, TRAPS), TRAPS);
  18150. void classes_do(void f(klassOop, oop));
  18151. void classes_do(void f(klassOop, oop, TRAPS), TRAPS);
  18152. + void classes_do(ObjectClosure *closure);
  18153. void methods_do(void f(methodOop));
  18154. @@ -97,6 +102,7 @@
  18155. bool do_unloading(BoolObjectClosure* is_alive);
  18156. // Protection domains
  18157. + static klassOop intercept_for_version(klassOop k);
  18158. klassOop find(int index, unsigned int hash, symbolHandle name,
  18159. Handle loader, Handle protection_domain, TRAPS);
  18160. bool is_valid_protection_domain(int index, unsigned int hash,
  18161. diff -r f5603a6e5042 src/share/vm/classfile/javaClasses.cpp
  18162. --- a/src/share/vm/classfile/javaClasses.cpp Wed Nov 17 22:42:08 2010 -0800
  18163. +++ b/src/share/vm/classfile/javaClasses.cpp Fri Dec 17 13:23:04 2010 +0100
  18164. @@ -1537,7 +1537,7 @@
  18165. klassOop klass = SystemDictionary::reflect_Method_klass();
  18166. // This class is eagerly initialized during VM initialization, since we keep a refence
  18167. // to one of the methods
  18168. - assert(instanceKlass::cast(klass)->is_initialized(), "must be initialized");
  18169. + assert(instanceKlass::cast(klass)->is_initialized() || klass->klass_part()->old_version() != NULL, "must be initialized");
  18170. return instanceKlass::cast(klass)->allocate_instance_handle(CHECK_NH);
  18171. }
  18172. diff -r f5603a6e5042 src/share/vm/classfile/javaClasses.hpp
  18173. --- a/src/share/vm/classfile/javaClasses.hpp Wed Nov 17 22:42:08 2010 -0800
  18174. +++ b/src/share/vm/classfile/javaClasses.hpp Fri Dec 17 13:23:04 2010 +0100
  18175. @@ -124,6 +124,7 @@
  18176. class java_lang_Class : AllStatic {
  18177. friend class VMStructs;
  18178. + friend class VM_RedefineClasses;
  18179. private:
  18180. // The fake offsets are added by the class loader when java.lang.Class is loaded
  18181. diff -r f5603a6e5042 src/share/vm/classfile/loaderConstraints.cpp
  18182. --- a/src/share/vm/classfile/loaderConstraints.cpp Wed Nov 17 22:42:08 2010 -0800
  18183. +++ b/src/share/vm/classfile/loaderConstraints.cpp Fri Dec 17 13:23:04 2010 +0100
  18184. @@ -449,7 +449,7 @@
  18185. if (k != NULL) {
  18186. // We found the class in the system dictionary, so we should
  18187. // make sure that the klassOop matches what we already have.
  18188. - guarantee(k == probe->klass(), "klass should be in dictionary");
  18189. + guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
  18190. } else {
  18191. // If we don't find the class in the system dictionary, it
  18192. // has to be in the placeholders table.
  18193. diff -r f5603a6e5042 src/share/vm/classfile/loaderConstraints.hpp
  18194. --- a/src/share/vm/classfile/loaderConstraints.hpp Wed Nov 17 22:42:08 2010 -0800
  18195. +++ b/src/share/vm/classfile/loaderConstraints.hpp Fri Dec 17 13:23:04 2010 +0100
  18196. @@ -99,7 +99,7 @@
  18197. klassOop klass() { return (klassOop)literal(); }
  18198. klassOop* klass_addr() { return (klassOop*)literal_addr(); }
  18199. - void set_klass(klassOop k) { set_literal(k); }
  18200. + void set_klass(klassOop k) { set_literal(k); assert(k == NULL || !k->klass_part()->is_redefining(), "just checking"); }
  18201. LoaderConstraintEntry* next() {
  18202. return (LoaderConstraintEntry*)HashtableEntry::next();
  18203. diff -r f5603a6e5042 src/share/vm/classfile/systemDictionary.cpp
  18204. --- a/src/share/vm/classfile/systemDictionary.cpp Wed Nov 17 22:42:08 2010 -0800
  18205. +++ b/src/share/vm/classfile/systemDictionary.cpp Fri Dec 17 13:23:04 2010 +0100
  18206. @@ -119,6 +119,7 @@
  18207. // can return a null klass
  18208. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  18209. }
  18210. + assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
  18211. return klass;
  18212. }
  18213. @@ -161,7 +162,8 @@
  18214. // Forwards to resolve_instance_class_or_null
  18215. klassOop SystemDictionary::resolve_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  18216. - assert(!THREAD->is_Compiler_thread(), "Can not load classes with the Compiler thread");
  18217. + // (tw) Check if this relaxing of the condition is correct? Test case hs203t004 failing otherwise.
  18218. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL, "Can not load classes with the Compiler thread");
  18219. if (FieldType::is_array(class_name())) {
  18220. return resolve_array_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL);
  18221. } else {
  18222. @@ -976,6 +978,7 @@
  18223. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  18224. class_loader,
  18225. protection_domain,
  18226. + KlassHandle(),
  18227. host_klass,
  18228. cp_patches,
  18229. parsed_name,
  18230. @@ -1036,8 +1039,15 @@
  18231. Handle protection_domain,
  18232. ClassFileStream* st,
  18233. bool verify,
  18234. + KlassHandle old_class,
  18235. TRAPS) {
  18236. + bool redefine_classes_locked = false;
  18237. + if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
  18238. + Thread::current()->redefine_classes_mutex()->lock();
  18239. + redefine_classes_locked = true;
  18240. + }
  18241. +
  18242. // Classloaders that support parallelism, e.g. bootstrap classloader,
  18243. // or all classloaders with UnsyncloadClass do not acquire lock here
  18244. bool DoObjectLock = true;
  18245. @@ -1065,9 +1075,14 @@
  18246. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  18247. class_loader,
  18248. protection_domain,
  18249. + old_class,
  18250. parsed_name,
  18251. verify,
  18252. THREAD);
  18253. + if (!old_class.is_null() && !k.is_null()) {
  18254. + k->set_redefining(true);
  18255. + k->set_old_version(old_class());
  18256. + }
  18257. const char* pkg = "java/";
  18258. if (!HAS_PENDING_EXCEPTION &&
  18259. @@ -1103,13 +1118,18 @@
  18260. // Add class just loaded
  18261. // If a class loader supports parallel classloading handle parallel define requests
  18262. // find_or_define_instance_class may return a different instanceKlass
  18263. - if (is_parallelCapable(class_loader)) {
  18264. + // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  18265. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  18266. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  18267. } else {
  18268. - define_instance_class(k, THREAD);
  18269. + define_instance_class(k, old_class, THREAD);
  18270. }
  18271. }
  18272. + if (redefine_classes_locked) {
  18273. + Thread::current()->redefine_classes_mutex()->unlock();
  18274. + }
  18275. +
  18276. // If parsing the class file or define_instance_class failed, we
  18277. // need to remove the placeholder added on our behalf. But we
  18278. // must make sure parsed_name is valid first (it won't be if we had
  18279. @@ -1138,7 +1158,7 @@
  18280. MutexLocker mu(SystemDictionary_lock, THREAD);
  18281. oop check = find_class_or_placeholder(parsed_name, class_loader);
  18282. - assert(check == k(), "should be present in the dictionary");
  18283. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  18284. oop check2 = find_class_or_placeholder(h_name, h_loader);
  18285. assert(check == check2, "name inconsistancy in SystemDictionary");
  18286. @@ -1424,7 +1444,11 @@
  18287. }
  18288. }
  18289. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  18290. +void SystemDictionary::rollback_redefinition() {
  18291. + dictionary()->rollback_redefinition();
  18292. +}
  18293. +
  18294. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  18295. Handle class_loader_h(THREAD, k->class_loader());
  18296. @@ -1451,13 +1475,23 @@
  18297. symbolHandle name_h(THREAD, k->name());
  18298. unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
  18299. int d_index = dictionary()->hash_to_index(d_hash);
  18300. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  18301. +
  18302. + // (tw) Update version of the klassOop in the system dictionary
  18303. + // TODO: Check for thread safety!
  18304. + if (!old_class.is_null()) {
  18305. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
  18306. + assert (ok, "must have found old class and updated!");
  18307. + }
  18308. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  18309. +
  18310. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  18311. // Register class just loaded with class loader (placed in Vector)
  18312. // Note we do this before updating the dictionary, as this can
  18313. // fail with an OutOfMemoryError (if it does, we will *not* put this
  18314. // class in the dictionary and will not update the class hierarchy).
  18315. - if (k->class_loader() != NULL) {
  18316. + // (tw) Only register if not redefining a class.
  18317. + if (k->class_loader() != NULL && old_class.is_null()) {
  18318. methodHandle m(THREAD, Universe::loader_addClass_method());
  18319. JavaValue result(T_VOID);
  18320. JavaCallArguments args(class_loader_h);
  18321. @@ -1483,8 +1517,9 @@
  18322. }
  18323. k->eager_initialize(THREAD);
  18324. + // (tw) Only notify jvmti if not redefining a class.
  18325. // notify jvmti
  18326. - if (JvmtiExport::should_post_class_load()) {
  18327. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  18328. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  18329. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  18330. @@ -1558,7 +1593,7 @@
  18331. }
  18332. }
  18333. - define_instance_class(k, THREAD);
  18334. + define_instance_class(k, KlassHandle(), THREAD);
  18335. Handle linkage_exception = Handle(); // null handle
  18336. @@ -1698,6 +1733,14 @@
  18337. Universe::flush_dependents_on(k);
  18338. }
  18339. +// (tw) Remove from hierarchy - Undo add_to_hierarchy.
  18340. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  18341. + assert(k.not_null(), "just checking");
  18342. +
  18343. + k->remove_from_sibling_list();
  18344. +
  18345. + // TODO: Remove from interfaces.
  18346. +}
  18347. // ----------------------------------------------------------------------------
  18348. // GC support
  18349. @@ -1778,10 +1821,8 @@
  18350. }
  18351. -void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  18352. - f->do_oop((oop*) &wk_klass_name_limits[0]);
  18353. - f->do_oop((oop*) &wk_klass_name_limits[1]);
  18354. -
  18355. +// (tw) Iterate over all pre-loaded classes in the dictionary.
  18356. +void SystemDictionary::preloaded_classes_do(OopClosure *f) {
  18357. for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  18358. f->do_oop((oop*) &_well_known_klasses[k]);
  18359. }
  18360. @@ -1795,6 +1836,26 @@
  18361. }
  18362. }
  18363. + // TODO: Check if we need to call FilterFieldsMap
  18364. +}
  18365. +
  18366. +void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  18367. + f->do_oop((oop*) &wk_klass_name_limits[0]);
  18368. + f->do_oop((oop*) &wk_klass_name_limits[1]);
  18369. +
  18370. + for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  18371. + f->do_oop((oop*) &_well_known_klasses[k]);
  18372. + }
  18373. +
  18374. + {
  18375. + for (int i = 0; i < T_VOID+1; i++) {
  18376. + if (_box_klasses[i] != NULL) {
  18377. + assert(i >= T_BOOLEAN, "checking");
  18378. + f->do_oop((oop*) &_box_klasses[i]);
  18379. + }
  18380. + }
  18381. + }
  18382. +
  18383. // The basic type mirrors would have already been processed in
  18384. // Universe::oops_do(), via a call to shared_oops_do(), so should
  18385. // not be processed again.
  18386. @@ -1813,6 +1874,11 @@
  18387. dictionary()->classes_do(f);
  18388. }
  18389. +// (tw) Iterate over all classes in the dictionary.
  18390. +void SystemDictionary::classes_do(ObjectClosure *closure) {
  18391. + dictionary()->classes_do(closure);
  18392. +}
  18393. +
  18394. // Added for initialize_itable_for_klass
  18395. // Just the classes from defining class loaders
  18396. // Don't iterate over placeholders
  18397. @@ -1962,7 +2028,9 @@
  18398. // Preload ref klasses and set reference types
  18399. instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
  18400. - instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  18401. +
  18402. + // (tw) This is now done in parseClassFile in order to support class redefinition
  18403. + // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  18404. initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
  18405. instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
  18406. @@ -2064,7 +2132,11 @@
  18407. // also holds array classes
  18408. assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
  18409. - if ((defining == true) || (k() != check)) {
  18410. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  18411. + ResourceMark rm(Thread::current());
  18412. + tty->print_cr("(%d / %d) (%s/%s)", k->revision_number(), check->klass_part()->revision_number(), k->name()->as_C_string(), check->klass_part()->name()->as_C_string());
  18413. + k()->print();
  18414. + check->print();
  18415. linkage_error = "loader (instance of %s): attempted duplicate class "
  18416. "definition for name: \"%s\"";
  18417. } else {
  18418. @@ -2718,8 +2790,9 @@
  18419. if (probe == NULL) {
  18420. probe = SystemDictionary::find_shared_class(class_name);
  18421. }
  18422. + // (tw) Relaxed assertion to allow different class versions. Also allow redefining classes lie around (because of rollback).
  18423. guarantee(probe != NULL &&
  18424. - (!probe->is_klass() || probe == obj()),
  18425. + (!probe->is_klass() || (!((klassOop)(obj()))->klass_part()->is_redefining()) || ((klassOop)probe)->klass_part()->is_same_or_older_version((klassOop)(obj()))) || ((klassOop)(obj()))->klass_part()->is_redefining(),
  18426. "Loaded klasses should be in SystemDictionary");
  18427. }
  18428. diff -r f5603a6e5042 src/share/vm/classfile/systemDictionary.hpp
  18429. --- a/src/share/vm/classfile/systemDictionary.hpp Wed Nov 17 22:42:08 2010 -0800
  18430. +++ b/src/share/vm/classfile/systemDictionary.hpp Fri Dec 17 13:23:04 2010 +0100
  18431. @@ -260,7 +260,7 @@
  18432. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  18433. static klassOop resolve_from_stream(symbolHandle class_name, Handle class_loader,
  18434. Handle protection_domain,
  18435. - ClassFileStream* st, bool verify, TRAPS);
  18436. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  18437. // Lookup an already loaded class. If not found NULL is returned.
  18438. static klassOop find(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS);
  18439. @@ -304,6 +304,8 @@
  18440. // Iterate over all klasses in dictionary
  18441. // Just the classes from defining class loaders
  18442. static void classes_do(void f(klassOop));
  18443. + static void classes_do(ObjectClosure *closure);
  18444. + static void preloaded_classes_do(OopClosure *closure);
  18445. // Added for initialize_itable_for_klass to handle exceptions
  18446. static void classes_do(void f(klassOop, TRAPS), TRAPS);
  18447. // All classes, and their class loaders
  18448. @@ -408,6 +410,8 @@
  18449. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  18450. }
  18451. + static void rollback_redefinition();
  18452. +
  18453. public:
  18454. #define WK_KLASS_DECLARE(name, ignore_symbol, option) \
  18455. static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); }
  18456. @@ -576,7 +580,7 @@
  18457. // after waiting, but before reentering SystemDictionary_lock
  18458. // to preserve lock order semantics.
  18459. static void double_lock_wait(Handle lockObject, TRAPS);
  18460. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  18461. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  18462. static instanceKlassHandle find_or_define_instance_class(symbolHandle class_name,
  18463. Handle class_loader,
  18464. instanceKlassHandle k, TRAPS);
  18465. @@ -595,6 +599,11 @@
  18466. // Setup link to hierarchy
  18467. static void add_to_hierarchy(instanceKlassHandle k, TRAPS);
  18468. +public:
  18469. +
  18470. + // Remove link to hierarchy
  18471. + static void remove_from_hierarchy(instanceKlassHandle k);
  18472. +
  18473. private:
  18474. // We pass in the hashtable index so we can calculate it outside of
  18475. // the SystemDictionary_lock.
  18476. diff -r f5603a6e5042 src/share/vm/classfile/verifier.cpp
  18477. --- a/src/share/vm/classfile/verifier.cpp Wed Nov 17 22:42:08 2010 -0800
  18478. +++ b/src/share/vm/classfile/verifier.cpp Fri Dec 17 13:23:04 2010 +0100
  18479. @@ -70,7 +70,7 @@
  18480. return !need_verify;
  18481. }
  18482. -bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
  18483. +bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
  18484. ResourceMark rm(THREAD);
  18485. HandleMark hm;
  18486. @@ -94,17 +94,19 @@
  18487. split_verifier.verify_class(THREAD);
  18488. exception_name = split_verifier.result();
  18489. if (klass->major_version() < NOFAILOVER_MAJOR_VERSION &&
  18490. - FailOverToOldVerifier && !HAS_PENDING_EXCEPTION &&
  18491. + FailOverToOldVerifier && may_use_old_verifier && !HAS_PENDING_EXCEPTION &&
  18492. (exception_name == vmSymbols::java_lang_VerifyError() ||
  18493. exception_name == vmSymbols::java_lang_ClassFormatError())) {
  18494. if (TraceClassInitialization) {
  18495. tty->print_cr(
  18496. "Fail over class verification to old verifier for: %s", klassName);
  18497. }
  18498. + assert(may_use_old_verifier, "");
  18499. exception_name = inference_verify(
  18500. klass, message_buffer, message_buffer_len, THREAD);
  18501. }
  18502. } else {
  18503. + assert(may_use_old_verifier, "");
  18504. exception_name = inference_verify(
  18505. klass, message_buffer, message_buffer_len, THREAD);
  18506. }
  18507. @@ -119,6 +121,9 @@
  18508. }
  18509. tty->print_cr("End class verification for: %s", klassName);
  18510. }
  18511. + } else if (TraceClassInitialization) {
  18512. + // (tw) Output not verified classes
  18513. + tty->print_cr("Class %s was not verified", klassName);
  18514. }
  18515. if (HAS_PENDING_EXCEPTION) {
  18516. @@ -170,7 +175,7 @@
  18517. // NOTE: this is called too early in the bootstrapping process to be
  18518. // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
  18519. (refl_magic_klass == NULL ||
  18520. - !klass->is_subtype_of(refl_magic_klass) ||
  18521. + !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
  18522. VerifyReflectionBytecodes)
  18523. );
  18524. }
  18525. @@ -240,7 +245,7 @@
  18526. ClassVerifier::ClassVerifier(
  18527. instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS)
  18528. : _thread(THREAD), _exception_type(symbolHandle()), _message(msg),
  18529. - _message_buffer_len(msg_len), _klass(klass) {
  18530. + _message_buffer_len(msg_len), _klass(klass->newest_version()), _klass_to_verify(klass) {
  18531. _this_type = VerificationType::reference_type(klass->name());
  18532. }
  18533. @@ -253,7 +258,7 @@
  18534. _klass->external_name());
  18535. }
  18536. - objArrayHandle methods(THREAD, _klass->methods());
  18537. + objArrayHandle methods(THREAD, _klass_to_verify->methods());
  18538. int num_methods = methods->length();
  18539. for (int index = 0; index < num_methods; index++) {
  18540. @@ -2043,7 +2048,10 @@
  18541. VerificationType stack_object_type =
  18542. current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  18543. if (current_type() != stack_object_type) {
  18544. - assert(cp->cache() == NULL, "not rewritten yet");
  18545. +
  18546. + // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
  18547. + //assert(cp->cache() == NULL, "not rewritten yet");
  18548. +
  18549. symbolHandle ref_class_name = symbolHandle(THREAD,
  18550. cp->klass_name_at(cp->klass_ref_index_at(index)));
  18551. // See the comments in verify_field_instructions() for
  18552. diff -r f5603a6e5042 src/share/vm/classfile/verifier.hpp
  18553. --- a/src/share/vm/classfile/verifier.hpp Wed Nov 17 22:42:08 2010 -0800
  18554. +++ b/src/share/vm/classfile/verifier.hpp Fri Dec 17 13:23:04 2010 +0100
  18555. @@ -37,7 +37,7 @@
  18556. * Otherwise, no exception is thrown and the return indicates the
  18557. * error.
  18558. */
  18559. - static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
  18560. + static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS);
  18561. // Return false if the class is loaded by the bootstrap loader,
  18562. // or if defineClass was called requesting skipping verification
  18563. @@ -88,7 +88,10 @@
  18564. char* _message;
  18565. size_t _message_buffer_len;
  18566. +public:
  18567. void verify_method(methodHandle method, TRAPS);
  18568. +
  18569. +private:
  18570. char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
  18571. void verify_exception_handler_table(u4 code_length, char* code_data, int& min, int& max, TRAPS);
  18572. void verify_local_variable_table(u4 code_length, char* code_data, TRAPS);
  18573. @@ -157,6 +160,7 @@
  18574. bool name_in_supers(symbolOop ref_name, instanceKlassHandle current);
  18575. + instanceKlassHandle _klass_to_verify;
  18576. instanceKlassHandle _klass; // the class being verified
  18577. methodHandle _method; // current method being verified
  18578. VerificationType _this_type; // the verification type of the current class
  18579. diff -r f5603a6e5042 src/share/vm/classfile/vmSymbols.hpp
  18580. --- a/src/share/vm/classfile/vmSymbols.hpp Wed Nov 17 22:42:08 2010 -0800
  18581. +++ b/src/share/vm/classfile/vmSymbols.hpp Fri Dec 17 13:23:04 2010 +0100
  18582. @@ -127,6 +127,10 @@
  18583. template(tag_runtime_invisible_parameter_annotations,"RuntimeInvisibleParameterAnnotations") \
  18584. template(tag_annotation_default, "AnnotationDefault") \
  18585. template(tag_enclosing_method, "EnclosingMethod") \
  18586. + template(tag_static_field_redefinition_policy, "StaticFieldRedefinitionPolicy") \
  18587. + template(tag_field_redefinition_policy, "FieldRedefinitionPolicy") \
  18588. + template(tag_method_redefinition_policy, "MethodRedefinitionPolicy") \
  18589. + template(tag_code_sections, "CodeSections") \
  18590. \
  18591. /* exception klasses: at least all exceptions thrown by the VM have entries here */ \
  18592. template(java_lang_ArithmeticException, "java/lang/ArithmeticException") \
  18593. @@ -349,6 +353,9 @@
  18594. template(erasedType_name, "erasedType") \
  18595. template(genericInvoker_name, "genericInvoker") \
  18596. template(append_name, "append") \
  18597. + /* mutator in case of class redefinition */ \
  18598. + template(static_transformer_name, "$staticTransformer") \
  18599. + template(transformer_name, "$transformer") \
  18600. \
  18601. /* non-intrinsic name/signature pairs: */ \
  18602. template(register_method_name, "register") \
  18603. diff -r f5603a6e5042 src/share/vm/code/nmethod.cpp
  18604. --- a/src/share/vm/code/nmethod.cpp Wed Nov 17 22:42:08 2010 -0800
  18605. +++ b/src/share/vm/code/nmethod.cpp Fri Dec 17 13:23:04 2010 +0100
  18606. @@ -2055,15 +2055,14 @@
  18607. methodOop method = deps.method_argument(0);
  18608. for (int j = 0; j < dependee_methods->length(); j++) {
  18609. if ((methodOop) dependee_methods->obj_at(j) == method) {
  18610. - // RC_TRACE macro has an embedded ResourceMark
  18611. - RC_TRACE(0x01000000,
  18612. - ("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)",
  18613. + ResourceMark rm(Thread::current());
  18614. + TRACE_RC3("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)",
  18615. _method->method_holder()->klass_part()->external_name(),
  18616. _method->name()->as_C_string(),
  18617. _method->signature()->as_C_string(), compile_id(),
  18618. method->method_holder()->klass_part()->external_name(),
  18619. method->name()->as_C_string(),
  18620. - method->signature()->as_C_string()));
  18621. + method->signature()->as_C_string());
  18622. if (TraceDependencies || LogCompilation)
  18623. deps.log_dependency(dependee);
  18624. return true;
  18625. diff -r f5603a6e5042 src/share/vm/compiler/compileBroker.cpp
  18626. --- a/src/share/vm/compiler/compileBroker.cpp Wed Nov 17 22:42:08 2010 -0800
  18627. +++ b/src/share/vm/compiler/compileBroker.cpp Fri Dec 17 13:23:04 2010 +0100
  18628. @@ -1027,6 +1027,7 @@
  18629. }
  18630. // RedefineClasses() has replaced this method; just return
  18631. + // (tw) This is important for the new version of hotswapping: Old code will only execute properly in the interpreter!
  18632. if (method->is_old()) {
  18633. return NULL;
  18634. }
  18635. @@ -1352,6 +1353,8 @@
  18636. // Never compile a method if breakpoints are present in it
  18637. if (method()->number_of_breakpoints() == 0) {
  18638. + thread->compilation_mutex()->lock();
  18639. + thread->set_should_bailout(false);
  18640. // Compile the method.
  18641. if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
  18642. #ifdef COMPILER1
  18643. @@ -1375,6 +1378,7 @@
  18644. // After compilation is disabled, remove remaining methods from queue
  18645. method->clear_queued_for_compilation();
  18646. }
  18647. + thread->compilation_mutex()->unlock();
  18648. }
  18649. }
  18650. }
  18651. @@ -1535,7 +1539,11 @@
  18652. //assert(false, "compiler should always document failure");
  18653. // The compiler elected, without comment, not to register a result.
  18654. // Do not attempt further compilations of this method.
  18655. - ci_env.record_method_not_compilable("compile failed");
  18656. + if (((CompilerThread *)Thread::current())->should_bailout()) {
  18657. + ci_env.record_failure("compile externally aborted");
  18658. + } else {
  18659. + ci_env.record_method_not_compilable("compile failed");
  18660. + }
  18661. }
  18662. if (ci_env.failing()) {
  18663. @@ -1882,3 +1890,15 @@
  18664. st->cr();
  18665. #endif
  18666. }
  18667. +
  18668. +// (tw) Clean up compiler interface after a class redefinition step
  18669. +void CompileBroker::cleanup_after_redefinition() {
  18670. + int num_threads = _method_threads->length();
  18671. +
  18672. + ciObjectFactory::sort_ci_objects(ciObjectFactory::_shared_ci_objects);
  18673. + for (int i=0; i<num_threads; i++) {
  18674. + if (_method_threads->at(i)->env() != NULL && _method_threads->at(i)->env() != (ciEnv *)badAddress) {
  18675. + _method_threads->at(i)->env()->cleanup_after_redefinition();
  18676. + }
  18677. + }
  18678. +}
  18679. \ No newline at end of file
  18680. diff -r f5603a6e5042 src/share/vm/compiler/compileBroker.hpp
  18681. --- a/src/share/vm/compiler/compileBroker.hpp Wed Nov 17 22:42:08 2010 -0800
  18682. +++ b/src/share/vm/compiler/compileBroker.hpp Fri Dec 17 13:23:04 2010 +0100
  18683. @@ -379,4 +379,6 @@
  18684. static void print_last_compile();
  18685. static void print_compiler_threads_on(outputStream* st);
  18686. +
  18687. + static void cleanup_after_redefinition();
  18688. };
  18689. diff -r f5603a6e5042 src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  18690. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Wed Nov 17 22:42:08 2010 -0800
  18691. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Fri Dec 17 13:23:04 2010 +0100
  18692. @@ -140,6 +140,13 @@
  18693. }
  18694. }
  18695. +
  18696. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  18697. + CompactPoint* cp, HeapWord* compact_top) {
  18698. + ShouldNotReachHere();
  18699. + return NULL;
  18700. +}
  18701. +
  18702. // Like CompactibleSpace forward() but always calls cross_threshold() to
  18703. // update the block offset table. Removed initialize_threshold call because
  18704. // CFLS does not use a block offset array for contiguous spaces.
  18705. diff -r f5603a6e5042 src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  18706. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp Wed Nov 17 22:42:08 2010 -0800
  18707. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp Fri Dec 17 13:23:04 2010 +0100
  18708. @@ -140,6 +140,7 @@
  18709. // Support for compacting cms
  18710. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  18711. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  18712. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  18713. // Initialization helpers.
  18714. diff -r f5603a6e5042 src/share/vm/gc_implementation/includeDB_gc_g1
  18715. --- a/src/share/vm/gc_implementation/includeDB_gc_g1 Wed Nov 17 22:42:08 2010 -0800
  18716. +++ b/src/share/vm/gc_implementation/includeDB_gc_g1 Fri Dec 17 13:23:04 2010 +0100
  18717. @@ -330,8 +330,6 @@
  18718. ptrQueue.hpp allocation.hpp
  18719. ptrQueue.hpp sizes.hpp
  18720. -ptrQueue.inline.hpp ptrQueue.hpp
  18721. -
  18722. satbQueue.cpp allocation.inline.hpp
  18723. satbQueue.cpp mutexLocker.hpp
  18724. satbQueue.cpp satbQueue.hpp
  18725. diff -r f5603a6e5042 src/share/vm/gc_implementation/shared/markSweep.cpp
  18726. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp Wed Nov 17 22:42:08 2010 -0800
  18727. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp Fri Dec 17 13:23:04 2010 +0100
  18728. @@ -25,6 +25,8 @@
  18729. #include "incls/_precompiled.incl"
  18730. #include "incls/_markSweep.cpp.incl"
  18731. +GrowableArray<oop>* MarkSweep::_rescued_oops = NULL;
  18732. +
  18733. Stack<oop> MarkSweep::_marking_stack;
  18734. Stack<DataLayout*> MarkSweep::_revisit_mdo_stack;
  18735. Stack<Klass*> MarkSweep::_revisit_klass_stack;
  18736. @@ -345,3 +347,86 @@
  18737. }
  18738. #endif
  18739. +
  18740. +// (tw) Copy the rescued objects to their destination address after compaction.
  18741. +void MarkSweep::copy_rescued_objects_back() {
  18742. +
  18743. + if (_rescued_oops != NULL) {
  18744. +
  18745. + for (int i=0; i<_rescued_oops->length(); i++) {
  18746. + oop rescued_obj = _rescued_oops->at(i);
  18747. +
  18748. + int size = rescued_obj->size();
  18749. + oop new_obj = rescued_obj->forwardee();
  18750. +
  18751. + if (rescued_obj->blueprint()->new_version() != NULL) {
  18752. + MarkSweep::update_fields(rescued_obj, new_obj);
  18753. + } else {
  18754. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  18755. + }
  18756. +
  18757. + FREE_RESOURCE_ARRAY(HeapWord, rescued_obj, size);
  18758. +
  18759. + new_obj->init_mark();
  18760. + assert(new_obj->is_oop(), "must be a valid oop");
  18761. + }
  18762. + _rescued_oops->clear();
  18763. + _rescued_oops = NULL;
  18764. + }
  18765. +}
  18766. +
  18767. +// (tw) Update instances of a class whose fields changed.
  18768. +void MarkSweep::update_fields(oop q, oop new_location) {
  18769. +
  18770. + assert(q->blueprint()->new_version() != NULL, "class of old object must have new version");
  18771. +
  18772. + klassOop old_klass_oop = q->klass();
  18773. + klassOop new_klass_oop = q->blueprint()->new_version();
  18774. +
  18775. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  18776. + instanceKlass *new_klass = instanceKlass::cast(new_klass_oop);
  18777. +
  18778. + int size = q->size_given_klass(old_klass);
  18779. + int new_size = q->size_given_klass(new_klass);
  18780. +
  18781. + oop tmp_obj = q;
  18782. +
  18783. + if (new_klass_oop->klass_part()->is_copying_backwards()) {
  18784. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  18785. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  18786. + tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  18787. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  18788. + }
  18789. + }
  18790. +
  18791. + int *cur = new_klass_oop->klass_part()->update_information();
  18792. +
  18793. + tmp_obj->set_klass_no_check(new_klass_oop);
  18794. +
  18795. + if (cur == NULL) {
  18796. + assert(size == new_size, "just checking");
  18797. + Copy::conjoint_words(((HeapWord *)tmp_obj), ((HeapWord *)new_location), size);
  18798. + } else {
  18799. + int destOffset = 0;
  18800. + while (*cur != 0) {
  18801. + if (*cur > 0) {
  18802. + int size = *cur;
  18803. + cur++;
  18804. + int offset = *cur;
  18805. + Copy::conjoint_jbytes(((char *)tmp_obj) + offset, ((char *)new_location) + destOffset, size);
  18806. + destOffset += size;
  18807. + cur++;
  18808. + } else {
  18809. + assert(*cur < 0, "");
  18810. + int skip = -*cur;
  18811. + Copy::fill_to_bytes(((char*)new_location) + destOffset, skip, 0);
  18812. + destOffset += skip;
  18813. + cur++;
  18814. + }
  18815. + }
  18816. + }
  18817. +
  18818. + if (tmp_obj != q) {
  18819. + FREE_RESOURCE_ARRAY(HeapWord, tmp_obj, size);
  18820. + }
  18821. +}
  18822. diff -r f5603a6e5042 src/share/vm/gc_implementation/shared/markSweep.hpp
  18823. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp Wed Nov 17 22:42:08 2010 -0800
  18824. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp Fri Dec 17 13:23:04 2010 +0100
  18825. @@ -103,8 +103,12 @@
  18826. friend class AdjustPointerClosure;
  18827. friend class KeepAliveClosure;
  18828. friend class VM_MarkSweep;
  18829. + friend class GenMarkSweep;
  18830. friend void marksweep_init();
  18831. +public:
  18832. + static GrowableArray<oop>* _rescued_oops;
  18833. +
  18834. //
  18835. // Vars
  18836. //
  18837. @@ -190,6 +194,8 @@
  18838. template <class T> static inline void mark_and_push(T* p);
  18839. static inline void push_objarray(oop obj, size_t index);
  18840. + static void copy_rescued_objects_back();
  18841. + static void update_fields(oop q, oop new_location);
  18842. static void follow_stack(); // Empty marking stack.
  18843. static void preserve_mark(oop p, markOop mark);
  18844. diff -r f5603a6e5042 src/share/vm/includeDB_core
  18845. --- a/src/share/vm/includeDB_core Wed Nov 17 22:42:08 2010 -0800
  18846. +++ b/src/share/vm/includeDB_core Fri Dec 17 13:23:04 2010 +0100
  18847. @@ -1782,6 +1782,7 @@
  18848. genMarkSweep.cpp thread_<os_family>.inline.hpp
  18849. genMarkSweep.cpp vmSymbols.hpp
  18850. genMarkSweep.cpp vmThread.hpp
  18851. +genMarkSweep.cpp jvmtiRedefineClassesTrace.hpp
  18852. genMarkSweep.hpp markSweep.hpp
  18853. @@ -2625,6 +2626,7 @@
  18854. klassVtable.hpp handles.hpp
  18855. klassVtable.hpp oopsHierarchy.hpp
  18856. +linkResolver.cpp jvmtiRedefineClassesTrace.hpp
  18857. linkResolver.cpp bytecode.hpp
  18858. linkResolver.cpp collectedHeap.inline.hpp
  18859. linkResolver.cpp compilationPolicy.hpp
  18860. @@ -3860,6 +3862,7 @@
  18861. space.cpp systemDictionary.hpp
  18862. space.cpp universe.inline.hpp
  18863. space.cpp vmSymbols.hpp
  18864. +space.cpp jvmtiRedefineClassesTrace.hpp
  18865. space.hpp allocation.hpp
  18866. space.hpp blockOffsetTable.hpp
  18867. diff -r f5603a6e5042 src/share/vm/includeDB_jvmti
  18868. --- a/src/share/vm/includeDB_jvmti Wed Nov 17 22:42:08 2010 -0800
  18869. +++ b/src/share/vm/includeDB_jvmti Fri Dec 17 13:23:04 2010 +0100
  18870. @@ -231,7 +231,10 @@
  18871. jvmtiRedefineClasses.cpp systemDictionary.hpp
  18872. jvmtiRedefineClasses.cpp universe.inline.hpp
  18873. jvmtiRedefineClasses.cpp verifier.hpp
  18874. +jvmtiRedefineClasses.cpp jvmtiClassFileReconstituter.hpp
  18875. +jvmtiRedefineClasses.cpp compileBroker.hpp
  18876. +jvmtiRedefineClasses.hpp vmGCOperations.hpp
  18877. jvmtiRedefineClasses.hpp jvmtiEnv.hpp
  18878. jvmtiRedefineClasses.hpp jvmtiRedefineClassesTrace.hpp
  18879. jvmtiRedefineClasses.hpp objArrayKlass.hpp
  18880. diff -r f5603a6e5042 src/share/vm/interpreter/interpreterRuntime.cpp
  18881. --- a/src/share/vm/interpreter/interpreterRuntime.cpp Wed Nov 17 22:42:08 2010 -0800
  18882. +++ b/src/share/vm/interpreter/interpreterRuntime.cpp Fri Dec 17 13:23:04 2010 +0100
  18883. @@ -366,7 +366,7 @@
  18884. assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
  18885. assert(h_exception->is_oop(), "just checking");
  18886. // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
  18887. - if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  18888. + if (!(h_exception->is_a(SystemDictionary::Throwable_klass()->klass_part()->newest_version())) && !(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  18889. if (ExitVMOnVerifyError) vm_exit(-1);
  18890. ShouldNotReachHere();
  18891. }
  18892. @@ -622,6 +622,81 @@
  18893. JvmtiExport::post_raw_breakpoint(thread, method, bcp);
  18894. IRT_END
  18895. +// (tw) Correctly resolve method when running old code.
  18896. +IRT_ENTRY(void, InterpreterRuntime::forward_method(JavaThread *thread))
  18897. + {
  18898. + MonitorLockerEx ml(RedefinitionSync_lock);
  18899. + while (Threads::wait_at_instrumentation_entry()) {
  18900. + ml.wait();
  18901. + }
  18902. + }
  18903. + frame f = last_frame(thread);
  18904. + methodOop m = f.interpreter_frame_method();
  18905. + methodOop forward_method = m->forward_method();
  18906. + if (forward_method != NULL) {
  18907. + int bci = f.interpreter_frame_bci();
  18908. +
  18909. + if (TraceRedefineClasses >= 3) {
  18910. + tty->print_cr("Executing NOP in method %s at bci %d %d", m->name()->as_C_string(), bci, m->is_in_code_section(bci + 1));
  18911. + }
  18912. +
  18913. + int next_bci = bci - 1;
  18914. + // First try bci before NOP.
  18915. + if (!m->is_in_code_section(next_bci)) {
  18916. + // Try bci after NOP.
  18917. + next_bci = bci + 1;
  18918. + if (!m->is_in_code_section(next_bci)) return;
  18919. + }
  18920. +
  18921. + int new_bci = m->calculate_forward_bci(next_bci, forward_method);
  18922. + if (TraceRedefineClasses >= 2) {
  18923. + tty->print_cr("Transfering execution of %s to new method old_bci=%d new_bci=%d", forward_method->name()->as_C_string(), bci, new_bci);
  18924. + }
  18925. + RegisterMap reg_map(thread);
  18926. + vframe* vf = vframe::new_vframe(&f, &reg_map, thread);
  18927. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  18928. + iframe->set_method(forward_method, new_bci - 1);
  18929. + }
  18930. +IRT_END
  18931. +
  18932. +// (tw) Correctly resolve method when running old code.
  18933. +IRT_ENTRY(methodOop, InterpreterRuntime::find_correct_method(JavaThread *thread, oopDesc* receiverOop, int vTableIndex))
  18934. + // extract receiver from the outgoing argument list if necessary
  18935. + Handle receiver(thread, receiverOop);
  18936. +
  18937. + // TODO: Check for invokeinterface!
  18938. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  18939. +
  18940. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  18941. + klassOop klass = receiverOop->klass();
  18942. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  18943. + klass = klass->klass_part()->old_version();
  18944. + }
  18945. +
  18946. + // TODO: Check for correctness if different vtable indices in different versions?
  18947. +
  18948. + return ((instanceKlass *)klass->klass_part())->method_at_vtable(vTableIndex);
  18949. +IRT_END
  18950. +
  18951. +// Correctly resolve interface method when running old code.
  18952. +IRT_ENTRY(methodOop, InterpreterRuntime::find_correct_interface_method(JavaThread *thread, oopDesc* receiverOop, oopDesc* interface_klass, int vTableIndex))
  18953. +
  18954. + // extract receiver from the outgoing argument list if necessary
  18955. + Handle receiver(thread, receiverOop);
  18956. +
  18957. + // TODO: Check for invokeinterface!
  18958. + Bytecodes::Code bytecode = Bytecodes::_invokevirtual;
  18959. +
  18960. + int method_holder_revision_number = method(thread)->method_holder()->klass_part()->revision_number();
  18961. + klassOop klass = receiverOop->klass();
  18962. + while (klass->klass_part()->revision_number() > method_holder_revision_number) {
  18963. + klass = klass->klass_part()->old_version();
  18964. + }
  18965. +
  18966. + methodOop result = ((instanceKlass *)klass->klass_part())->method_at_itable((klassOop)interface_klass, vTableIndex, THREAD);
  18967. + return result;
  18968. +IRT_END
  18969. +
  18970. IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode))
  18971. // extract receiver from the outgoing argument list if necessary
  18972. Handle receiver(thread, NULL);
  18973. @@ -650,6 +725,10 @@
  18974. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  18975. int retry_count = 0;
  18976. while (info.resolved_method()->is_old()) {
  18977. + // (tw) If we are executing an old method, this is OK!
  18978. + if (method(thread)->is_old()) {
  18979. + break;
  18980. + }
  18981. // It is very unlikely that method is redefined more than 100 times
  18982. // in the middle of resolve. If it is looping here more than 100 times
  18983. // means then there could be a bug here.
  18984. diff -r f5603a6e5042 src/share/vm/interpreter/interpreterRuntime.hpp
  18985. --- a/src/share/vm/interpreter/interpreterRuntime.hpp Wed Nov 17 22:42:08 2010 -0800
  18986. +++ b/src/share/vm/interpreter/interpreterRuntime.hpp Fri Dec 17 13:23:04 2010 +0100
  18987. @@ -115,6 +115,9 @@
  18988. static void post_method_entry(JavaThread *thread);
  18989. static void post_method_exit (JavaThread *thread);
  18990. static int interpreter_contains(address pc);
  18991. + static void forward_method(JavaThread *thread);
  18992. + static methodOop find_correct_method(JavaThread *thread, oopDesc* receiver, int vTableIndex);
  18993. + static methodOop find_correct_interface_method(JavaThread *thread, oopDesc* receiver, oopDesc* interface_klass, int vTableIndex);
  18994. // Native signature handlers
  18995. static void prepare_native_call(JavaThread* thread, methodOopDesc* method);
  18996. diff -r f5603a6e5042 src/share/vm/interpreter/linkResolver.cpp
  18997. --- a/src/share/vm/interpreter/linkResolver.cpp Wed Nov 17 22:42:08 2010 -0800
  18998. +++ b/src/share/vm/interpreter/linkResolver.cpp Fri Dec 17 13:23:04 2010 +0100
  18999. @@ -114,8 +114,8 @@
  19000. // Klass resolution
  19001. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  19002. - if (!Reflection::verify_class_access(ref_klass->as_klassOop(),
  19003. - sel_klass->as_klassOop(),
  19004. + if (!Reflection::verify_class_access(ref_klass->as_klassOop()->klass_part()->newest_version(),
  19005. + sel_klass->as_klassOop()->klass_part()->newest_version(),
  19006. true)) {
  19007. ResourceMark rm(THREAD);
  19008. Exceptions::fthrow(
  19009. @@ -227,7 +227,7 @@
  19010. // We'll check for the method name first, as that's most likely
  19011. // to be false (so we'll short-circuit out of these tests).
  19012. if (sel_method->name() == vmSymbols::clone_name() &&
  19013. - sel_klass() == SystemDictionary::Object_klass() &&
  19014. + sel_klass()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version() &&
  19015. resolved_klass->oop_is_array()) {
  19016. // We need to change "protected" to "public".
  19017. assert(flags.is_protected(), "clone not protected?");
  19018. @@ -293,6 +293,146 @@
  19019. }
  19020. +void LinkResolver::lookup_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  19021. + symbolHandle method_name, symbolHandle method_signature, bool is_interface, KlassHandle current_klass, TRAPS) {
  19022. +
  19023. + // Interface method lookup?
  19024. + if (is_interface) {
  19025. +
  19026. + // lookup method in this interface or its super, java.lang.Object
  19027. + lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  19028. +
  19029. + if (resolved_method.is_null()) {
  19030. + // lookup method in all the super-interfaces
  19031. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  19032. + }
  19033. +
  19034. + // Other methods
  19035. + } else {
  19036. +
  19037. + // 2. lookup method in resolved klass and its super klasses
  19038. + lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  19039. +
  19040. + if (resolved_method.is_null()) { // not found in the class hierarchy
  19041. + // 3. lookup method in all the interfaces implemented by the resolved klass
  19042. + lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  19043. +
  19044. + if (resolved_method.is_null()) {
  19045. + // JSR 292: see if this is an implicitly generated method MethodHandle.invoke(*...)
  19046. + lookup_implicit_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, CHECK);
  19047. + }
  19048. + }
  19049. + }
  19050. +}
  19051. +
  19052. +void LinkResolver::lookup_correct_field(fieldDescriptor &fd, KlassHandle &sel_klass, KlassHandle resolved_klass, KlassHandle current_klass, symbolOop field_name, symbolOop field_sig, bool is_static) {
  19053. +
  19054. + // First attempt unversioned
  19055. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  19056. +
  19057. +
  19058. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  19059. +
  19060. + // Look for the policy defined in the new version of the class (_not_ in the newest, but only in the newer relative to current klass).
  19061. + int redefinition_policy = current_klass->new_version()->klass_part()->field_redefinition_policy();
  19062. + if (is_static) {
  19063. + redefinition_policy = current_klass->new_version()->klass_part()->static_field_redefinition_policy();
  19064. + }
  19065. +
  19066. + assert(redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  19067. +
  19068. + if (redefinition_policy != Klass::DynamicCheck) {
  19069. +
  19070. + if (redefinition_policy == Klass::AccessOldMembers) {
  19071. + // Forget looked up fields
  19072. + sel_klass = KlassHandle(Thread::current(), (oop)NULL);
  19073. + }
  19074. +
  19075. + assert(redefinition_policy == Klass::AccessOldMembers || redefinition_policy == Klass::AccessDeletedMembers, "");
  19076. +
  19077. + if (sel_klass.is_null() || fd.is_static() != is_static /* access old static field field is changed from static to non-static */) {
  19078. +
  19079. + // Select correct version for resolved klass.
  19080. + find_correct_resolved_klass(resolved_klass, current_klass);
  19081. +
  19082. + sel_klass = KlassHandle(Thread::current(), instanceKlass::cast(resolved_klass())->find_field(field_name, field_sig, &fd));
  19083. +
  19084. + if (sel_klass.is_null()) {
  19085. + TRACE_RC2("Trying to resolve field (%s) in old universe failed => exception is the correct behaviour", field_name->as_C_string());
  19086. + } else {
  19087. + assert(sel_klass->new_version() != NULL, "must be old class!");
  19088. + TRACE_RC2("Resolved a field in the old universe (%s)!", field_name->as_C_string());
  19089. + }
  19090. + }
  19091. + }
  19092. + }
  19093. +}
  19094. +
  19095. +void LinkResolver::lookup_correct_method(methodHandle& resolved_method, KlassHandle resolved_klass, KlassHandle current_klass,
  19096. + symbolHandle method_name, symbolHandle method_signature, bool is_interface, TRAPS) {
  19097. +
  19098. + // First attempt unversioned
  19099. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  19100. +
  19101. + // (tw) Are we in an old method that wants to see a different view on the world?
  19102. + if (!current_klass.is_null() && !current_klass->is_newest_version()) {
  19103. +
  19104. + // Look for the policy defined in the new version of the class (_not_ in the newest, but only in the newer relative to current klass).
  19105. + int method_redefinition_policy = current_klass->new_version()->klass_part()->method_redefinition_policy();
  19106. + assert(method_redefinition_policy != Klass::StaticCheck, "if the policy is static check, then we can never reach here");
  19107. +
  19108. + if (method_redefinition_policy != Klass::DynamicCheck) {
  19109. +
  19110. + // We do not throw the exception
  19111. + if (method_redefinition_policy == Klass::AccessOldMembers) {
  19112. + // Forget any new member lookup
  19113. + resolved_method = methodHandle(THREAD, NULL);
  19114. + }
  19115. +
  19116. + assert(method_redefinition_policy == Klass::AccessOldMembers || method_redefinition_policy == Klass::AccessDeletedMembers, "");
  19117. +
  19118. + if (resolved_method.is_null()) {
  19119. +
  19120. + // Select correct version for resolved klass.
  19121. + find_correct_resolved_klass(resolved_klass, current_klass);
  19122. +
  19123. + // Now do the lookup in a second attempt with a different resolved klass.
  19124. + lookup_method(resolved_method, resolved_klass, method_name, method_signature, is_interface, current_klass, CHECK);
  19125. +
  19126. + IF_TRACE_RC2 {
  19127. + ResourceMark rm(THREAD);
  19128. + if (resolved_method.is_null()) {
  19129. + TRACE_RC2("Trying to resolve method (%s) in old universe failed => exception is the correct behaviour", method_name->as_C_string());
  19130. + } else {
  19131. + assert(resolved_method->is_old(), "must be old method!");
  19132. + TRACE_RC2("Resolved a method in the old universe (%s)!", resolved_method->name()->as_C_string());
  19133. + }
  19134. + }
  19135. + }
  19136. + }
  19137. + }
  19138. +
  19139. + if (resolved_method.is_null()) {
  19140. + // no method found
  19141. + ResourceMark rm(THREAD);
  19142. + THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  19143. + methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  19144. + method_name(),
  19145. + method_signature()));
  19146. + }
  19147. +}
  19148. +
  19149. +void LinkResolver::find_correct_resolved_klass(KlassHandle &resolved_klass, KlassHandle &current_klass) {
  19150. + int current_klass_revision = current_klass->revision_number();
  19151. + int resolved_klass_revision = resolved_klass->revision_number();
  19152. + TRACE_RC2("The two different revision numbers for interfaces: current=%d / resolved_callee=%d", current_klass_revision, resolved_klass_revision);
  19153. +
  19154. + while (resolved_klass->revision_number() > current_klass_revision) {
  19155. + assert(resolved_klass->old_version(), "must have old version");
  19156. + resolved_klass = KlassHandle(Thread::current(), resolved_klass->old_version());
  19157. + }
  19158. +}
  19159. +
  19160. void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle resolved_klass,
  19161. symbolHandle method_name, symbolHandle method_signature,
  19162. KlassHandle current_klass, bool check_access, TRAPS) {
  19163. @@ -304,27 +444,8 @@
  19164. THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
  19165. }
  19166. - // 2. lookup method in resolved klass and its super klasses
  19167. - lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  19168. -
  19169. - if (resolved_method.is_null()) { // not found in the class hierarchy
  19170. - // 3. lookup method in all the interfaces implemented by the resolved klass
  19171. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  19172. -
  19173. - if (resolved_method.is_null()) {
  19174. - // JSR 292: see if this is an implicitly generated method MethodHandle.invoke(*...)
  19175. - lookup_implicit_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, CHECK);
  19176. - }
  19177. -
  19178. - if (resolved_method.is_null()) {
  19179. - // 4. method lookup failed
  19180. - ResourceMark rm(THREAD);
  19181. - THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  19182. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  19183. - method_name(),
  19184. - method_signature()));
  19185. - }
  19186. - }
  19187. + // 2. and 3. and 4. lookup method in resolved klass and its super klasses
  19188. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, false, CHECK);
  19189. // 5. check if method is concrete
  19190. if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) {
  19191. @@ -391,20 +512,7 @@
  19192. }
  19193. // lookup method in this interface or its super, java.lang.Object
  19194. - lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  19195. -
  19196. - if (resolved_method.is_null()) {
  19197. - // lookup method in all the super-interfaces
  19198. - lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK);
  19199. - if (resolved_method.is_null()) {
  19200. - // no method found
  19201. - ResourceMark rm(THREAD);
  19202. - THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(),
  19203. - methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),
  19204. - method_name(),
  19205. - method_signature()));
  19206. - }
  19207. - }
  19208. + lookup_correct_method(resolved_method, resolved_klass, current_klass, method_name, method_signature, true, CHECK);
  19209. if (check_access) {
  19210. HandleMark hm(THREAD);
  19211. @@ -492,9 +600,14 @@
  19212. THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
  19213. }
  19214. + KlassHandle ref_klass(THREAD, pool->pool_holder()->klass_part());
  19215. +
  19216. // Resolve instance field
  19217. fieldDescriptor fd; // find_field initializes fd if found
  19218. - KlassHandle sel_klass(THREAD, instanceKlass::cast(resolved_klass())->find_field(field, sig, &fd));
  19219. +
  19220. + KlassHandle sel_klass;
  19221. + lookup_correct_field(fd, sel_klass, resolved_klass, ref_klass, field, sig, is_static);
  19222. +
  19223. // check if field exists; i.e., if a klass containing the field def has been selected
  19224. if (sel_klass.is_null()){
  19225. ResourceMark rm(THREAD);
  19226. @@ -502,7 +615,6 @@
  19227. }
  19228. // check access
  19229. - KlassHandle ref_klass(THREAD, pool->pool_holder());
  19230. check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK);
  19231. // check for errors
  19232. @@ -513,7 +625,7 @@
  19233. }
  19234. // Final fields can only be accessed from its own class.
  19235. - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
  19236. + if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()->klass_part()->active_version() && sel_klass() != pool->pool_holder()) {
  19237. THROW(vmSymbols::java_lang_IllegalAccessError());
  19238. }
  19239. @@ -715,7 +827,7 @@
  19240. bool check_access, bool check_null_and_abstract, TRAPS) {
  19241. methodHandle resolved_method;
  19242. linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
  19243. - runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
  19244. + runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, current_klass, check_null_and_abstract, CHECK);
  19245. }
  19246. // throws linktime exceptions
  19247. @@ -744,6 +856,7 @@
  19248. KlassHandle resolved_klass,
  19249. Handle recv,
  19250. KlassHandle recv_klass,
  19251. + KlassHandle current_klass,
  19252. bool check_null_and_abstract,
  19253. TRAPS) {
  19254. @@ -792,7 +905,39 @@
  19255. // recv_klass might be an arrayKlassOop but all vtables start at
  19256. // the same place. The cast is to avoid virtual call and assertion.
  19257. instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part();
  19258. +
  19259. + // (tw) The type of the virtual method call and the type of the receiver do not need to
  19260. + // have anything in common, as the receiver type could've been hotswapped.
  19261. + // Does not always work (method could be resolved with correct dynamic type and later
  19262. + // be called at the same place with a wrong dynamic type).
  19263. + // (tw) TODO: Need to handle the static type vs dynamic type issue more generally.
  19264. +
  19265. + // The vTable must be based on the view of the world of the resolved method
  19266. + klassOop method_holder = resolved_method->method_holder();
  19267. +
  19268. + if (method_holder->klass_part()->new_version() != NULL) {
  19269. + // We are executing in old code
  19270. + TRACE_RC2("Calling a method in old code");
  19271. + while (method_holder->klass_part()->revision_number() < inst->revision_number()) {
  19272. + inst = (instanceKlass *)(inst->old_version()->klass_part());
  19273. + }
  19274. + }
  19275. +
  19276. + if (inst->is_subtype_of(method_holder)) {
  19277. selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  19278. + } else {
  19279. +
  19280. + tty->print_cr("Failure:");
  19281. + inst->as_klassOop()->print();
  19282. + inst->super()->print();
  19283. + juint off = inst->super_check_offset();
  19284. + klassOop sup = *(klassOop*)( (address)inst->as_klassOop() + off );
  19285. + sup->print();
  19286. + method_holder->print();
  19287. +
  19288. + bool b = inst->is_subtype_of(method_holder);
  19289. + THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(), "(tw) A virtual method was called, but the type of the receiver is not related with the type of the class of the called method!");
  19290. + }
  19291. }
  19292. }
  19293. diff -r f5603a6e5042 src/share/vm/interpreter/linkResolver.hpp
  19294. --- a/src/share/vm/interpreter/linkResolver.hpp Wed Nov 17 22:42:08 2010 -0800
  19295. +++ b/src/share/vm/interpreter/linkResolver.hpp Fri Dec 17 13:23:04 2010 +0100
  19296. @@ -100,7 +100,11 @@
  19297. // It does all necessary link-time checks & throws exceptions if necessary.
  19298. class LinkResolver: AllStatic {
  19299. - private:
  19300. +private:
  19301. + static void lookup_method (methodHandle& result, KlassHandle resolved_klass, symbolHandle name, symbolHandle signature, bool is_interface, KlassHandle current_klass, TRAPS);
  19302. + static void lookup_correct_field (fieldDescriptor &fd, KlassHandle &sel_klass, KlassHandle resolved_klass, KlassHandle current_klass, symbolOop field_name, symbolOop field_sig, bool is_static);
  19303. + static void lookup_correct_method (methodHandle& result, KlassHandle resolved_klass, KlassHandle current_klass, symbolHandle name, symbolHandle signature, bool is_interface, TRAPS);
  19304. + static void find_correct_resolved_klass (KlassHandle &resolved_klass, KlassHandle &current_klass);
  19305. static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS);
  19306. static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS);
  19307. static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS);
  19308. @@ -123,7 +127,7 @@
  19309. static void linktime_resolve_interface_method (methodHandle& resolved_method, KlassHandle resolved_klass, symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS);
  19310. static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
  19311. - static void runtime_resolve_virtual_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS);
  19312. + static void runtime_resolve_virtual_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, Handle recv, KlassHandle recv_klass, KlassHandle current_klass, bool check_null_and_abstract, TRAPS);
  19313. static void runtime_resolve_interface_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS);
  19314. static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
  19315. diff -r f5603a6e5042 src/share/vm/interpreter/oopMapCache.cpp
  19316. --- a/src/share/vm/interpreter/oopMapCache.cpp Wed Nov 17 22:42:08 2010 -0800
  19317. +++ b/src/share/vm/interpreter/oopMapCache.cpp Fri Dec 17 13:23:04 2010 +0100
  19318. @@ -530,9 +530,9 @@
  19319. if (!_array[i].is_empty() && _array[i].method()->is_old()) {
  19320. // Cache entry is occupied by an old redefined method and we don't want
  19321. // to pin it down so flush the entry.
  19322. - RC_TRACE(0x08000000, ("flush: %s(%s): cached entry @%d",
  19323. + TRACE_RC3("flush: %s(%s): cached entry @%d",
  19324. _array[i].method()->name()->as_C_string(),
  19325. - _array[i].method()->signature()->as_C_string(), i));
  19326. + _array[i].method()->signature()->as_C_string(), i);
  19327. _array[i].flush();
  19328. }
  19329. diff -r f5603a6e5042 src/share/vm/interpreter/templateTable.hpp
  19330. --- a/src/share/vm/interpreter/templateTable.hpp Wed Nov 17 22:42:08 2010 -0800
  19331. +++ b/src/share/vm/interpreter/templateTable.hpp Fri Dec 17 13:23:04 2010 +0100
  19332. @@ -303,8 +303,8 @@
  19333. static void shouldnotreachhere();
  19334. // jvmti support
  19335. - static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos);
  19336. - static void jvmti_post_field_mod(Register cache, Register index, bool is_static);
  19337. + static void jvmti_post_field_access(Register cache, Register index, int byte_no, bool is_static, bool has_tos);
  19338. + static void jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static);
  19339. static void jvmti_post_fast_field_mod();
  19340. // debugging of TemplateGenerator
  19341. diff -r f5603a6e5042 src/share/vm/memory/genMarkSweep.cpp
  19342. --- a/src/share/vm/memory/genMarkSweep.cpp Wed Nov 17 22:42:08 2010 -0800
  19343. +++ b/src/share/vm/memory/genMarkSweep.cpp Fri Dec 17 13:23:04 2010 +0100
  19344. @@ -372,6 +372,7 @@
  19345. // in the same order in phase2, phase3 and phase4. We don't quite do that
  19346. // here (perm_gen first rather than last), so we tell the validate code
  19347. // to use a higher index (saved from phase2) when verifying perm_gen.
  19348. + assert(_rescued_oops == NULL, "must be empty before processing");
  19349. GenCollectedHeap* gch = GenCollectedHeap::heap();
  19350. Generation* pg = gch->perm_gen();
  19351. @@ -385,10 +386,14 @@
  19352. VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
  19353. + MarkSweep::copy_rescued_objects_back();
  19354. +
  19355. GenCompactClosure blk;
  19356. gch->generation_iterate(&blk, true);
  19357. VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
  19358. + MarkSweep::copy_rescued_objects_back();
  19359. +
  19360. pg->post_compact(); // Shared spaces verification.
  19361. }
  19362. diff -r f5603a6e5042 src/share/vm/memory/permGen.cpp
  19363. --- a/src/share/vm/memory/permGen.cpp Wed Nov 17 22:42:08 2010 -0800
  19364. +++ b/src/share/vm/memory/permGen.cpp Fri Dec 17 13:23:04 2010 +0100
  19365. @@ -44,7 +44,12 @@
  19366. for (;;) {
  19367. {
  19368. - MutexLocker ml(Heap_lock);
  19369. + // (tw) Only lock when not at a safepoint (necessary to use the split verifier from the VmThread)
  19370. + Monitor *lock = Heap_lock;
  19371. + if (SafepointSynchronize::is_at_safepoint()) {
  19372. + lock = NULL;
  19373. + }
  19374. + MutexLockerEx ml(lock);
  19375. if ((obj = gen->allocate(size, false)) != NULL) {
  19376. return obj;
  19377. }
  19378. diff -r f5603a6e5042 src/share/vm/memory/space.cpp
  19379. --- a/src/share/vm/memory/space.cpp Wed Nov 17 22:42:08 2010 -0800
  19380. +++ b/src/share/vm/memory/space.cpp Fri Dec 17 13:23:04 2010 +0100
  19381. @@ -359,6 +359,31 @@
  19382. _compaction_top = bottom();
  19383. }
  19384. +// (tw) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  19385. +HeapWord* CompactibleSpace::forward_compact_top(size_t size,
  19386. +CompactPoint* cp, HeapWord* compact_top) {
  19387. + // First check if we should switch compaction space
  19388. + assert(this == cp->space, "'this' should be current compaction space.");
  19389. + size_t compaction_max_size = pointer_delta(end(), compact_top);
  19390. + while (size > compaction_max_size) {
  19391. + // switch to next compaction space
  19392. + cp->space->set_compaction_top(compact_top);
  19393. + cp->space = cp->space->next_compaction_space();
  19394. + if (cp->space == NULL) {
  19395. + cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen);
  19396. + assert(cp->gen != NULL, "compaction must succeed");
  19397. + cp->space = cp->gen->first_compaction_space();
  19398. + assert(cp->space != NULL, "generation must have a first compaction space");
  19399. + }
  19400. + compact_top = cp->space->bottom();
  19401. + cp->space->set_compaction_top(compact_top);
  19402. + cp->threshold = cp->space->initialize_threshold();
  19403. + compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  19404. + }
  19405. +
  19406. + return compact_top;
  19407. +}
  19408. +
  19409. HeapWord* CompactibleSpace::forward(oop q, size_t size,
  19410. CompactPoint* cp, HeapWord* compact_top) {
  19411. // q is alive
  19412. @@ -382,7 +407,7 @@
  19413. }
  19414. // store the forwarding pointer into the mark word
  19415. - if ((HeapWord*)q != compact_top) {
  19416. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  19417. q->forward_to(oop(compact_top));
  19418. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  19419. } else {
  19420. @@ -430,7 +455,204 @@
  19421. // Faster object search.
  19422. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  19423. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  19424. + if (!Universe::is_redefining_gc_run()) {
  19425. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  19426. + return;
  19427. + }
  19428. +
  19429. + /* Compute the new addresses for the live objects and store it in the mark
  19430. + * Used by universe::mark_sweep_phase2()
  19431. + */
  19432. + HeapWord* compact_top; /* This is where we are currently compacting to. */
  19433. +
  19434. + /* We're sure to be here before any objects are compacted into this
  19435. + * space, so this is a good time to initialize this:
  19436. + */
  19437. + set_compaction_top(bottom());
  19438. +
  19439. + if (cp->space == NULL) {
  19440. + assert(cp->gen != NULL, "need a generation");
  19441. + assert(cp->threshold == NULL, "just checking");
  19442. + assert(cp->gen->first_compaction_space() == this, "just checking");
  19443. + cp->space = cp->gen->first_compaction_space();
  19444. + compact_top = cp->space->bottom();
  19445. + cp->space->set_compaction_top(compact_top);
  19446. + cp->threshold = cp->space->initialize_threshold();
  19447. + } else {
  19448. + compact_top = cp->space->compaction_top();
  19449. + }
  19450. +
  19451. + /* We allow some amount of garbage towards the bottom of the space, so
  19452. + * we don't start compacting before there is a significant gain to be made.
  19453. + * Occasionally, we want to ensure a full compaction, which is determined
  19454. + * by the MarkSweepAlwaysCompactCount parameter.
  19455. + */
  19456. + int invocations = SharedHeap::heap()->perm_gen()->stat_record()->invocations;
  19457. + bool skip_dead = ((invocations % MarkSweepAlwaysCompactCount) != 0);
  19458. +
  19459. + size_t allowed_deadspace = 0;
  19460. + if (skip_dead) {
  19461. + int ratio = (int)allowed_dead_ratio();
  19462. + allowed_deadspace = (capacity() * ratio / 100) / HeapWordSize;
  19463. + }
  19464. +
  19465. + HeapWord* q = bottom();
  19466. + HeapWord* t = end();
  19467. +
  19468. + HeapWord* end_of_live= q; /* One byte beyond the last byte of the last
  19469. + live object. */
  19470. + HeapWord* first_dead = end();/* The first dead object. */
  19471. + LiveRange* liveRange = NULL; /* The current live range, recorded in the
  19472. + first header of preceding free area. */
  19473. + _first_dead = first_dead;
  19474. +
  19475. + const intx interval = PrefetchScanIntervalInBytes;
  19476. +
  19477. + while (q < t) {
  19478. + assert(!block_is_obj(q) ||
  19479. + oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() ||
  19480. + oop(q)->mark()->has_bias_pattern(),
  19481. + "these are the only valid states during a mark sweep");
  19482. + if (block_is_obj(q) && oop(q)->is_gc_marked()) {
  19483. + /* prefetch beyond q */
  19484. + Prefetch::write(q, interval);
  19485. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  19486. + size_t size = block_size(q);
  19487. +
  19488. + size_t forward_size = size;
  19489. +
  19490. + //////////////////////////////////////////////////////////////////////////
  19491. + // Compute the forward sizes and leave out objects whose position could
  19492. + // possibly overlap other objects.
  19493. +
  19494. + // (tw) There is a new version of the class of q => different size
  19495. + if (oop(q)->blueprint()->new_version() != NULL && oop(q)->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  19496. +
  19497. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  19498. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  19499. + forward_size = new_size;
  19500. + }
  19501. +
  19502. + compact_top = cp->space->forward_compact_top(forward_size, cp, compact_top);
  19503. +
  19504. + bool rescueing = false;
  19505. + if (rescueing = must_rescue(oop(q), oop(compact_top))) {
  19506. + if (MarkSweep::_rescued_oops == NULL) {
  19507. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  19508. + }
  19509. + TRACE_RC5("rescue obj %d klass=%s", MarkSweep::_rescued_oops->length(), oop(q)->klass()->klass_part()->name()->as_C_string());
  19510. + MarkSweep::_rescued_oops->append(oop(q));
  19511. + } else {
  19512. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  19513. + }
  19514. +
  19515. + if ((size != forward_size || rescueing) && q < first_dead) {
  19516. + // (tw) This object moves => first_dead must be set to here!
  19517. + first_dead = q;
  19518. + }
  19519. + //////////////////////////////////////////////////////////////////////////
  19520. +
  19521. + end_of_live = q + size; //forward_size;
  19522. + q += size;
  19523. + } else {
  19524. + /* run over all the contiguous dead objects */
  19525. + HeapWord* end = q;
  19526. + do {
  19527. + /* prefetch beyond end */
  19528. + Prefetch::write(end, interval);
  19529. + end += block_size(end);
  19530. + } while (end < t && (!block_is_obj(end) || !oop(end)->is_gc_marked()));
  19531. +
  19532. + /* see if we might want to pretend this object is alive so that
  19533. + * we don't have to compact quite as often.
  19534. + */
  19535. + if (allowed_deadspace > 0 && q == compact_top) {
  19536. + size_t sz = pointer_delta(end, q);
  19537. + if (insert_deadspace(allowed_deadspace, q, sz)) {
  19538. + compact_top = cp->space->forward(oop(q), sz, cp, compact_top);
  19539. + q = end;
  19540. + end_of_live = end;
  19541. + continue;
  19542. + }
  19543. + }
  19544. +
  19545. + /* otherwise, it really is a free region. */
  19546. +
  19547. + /* for the previous LiveRange, record the end of the live objects. */
  19548. + if (liveRange) {
  19549. + liveRange->set_end(q);
  19550. + }
  19551. +
  19552. + /* record the current LiveRange object.
  19553. + * liveRange->start() is overlaid on the mark word.
  19554. + */
  19555. + liveRange = (LiveRange*)q;
  19556. + liveRange->set_start(end);
  19557. + liveRange->set_end(end);
  19558. +
  19559. + /* see if this is the first dead region. */
  19560. + if (q < first_dead) {
  19561. + first_dead = q;
  19562. + }
  19563. +
  19564. + /* move on to the next object */
  19565. + q = end;
  19566. + }
  19567. + }
  19568. +
  19569. + //////////////////////////////////////////////////////////////////////////
  19570. + // Compute the forwarding addresses for the objects that need to be
  19571. + // rescued.
  19572. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  19573. + if (MarkSweep::_rescued_oops != NULL) {
  19574. + TRACE_RC2("Calculating new forward sizes for %d objects!", MarkSweep::_rescued_oops->length());
  19575. +
  19576. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  19577. + oop q = MarkSweep::_rescued_oops->at(i);
  19578. +
  19579. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  19580. + size_t size = block_size((HeapWord*)q);
  19581. +
  19582. + size_t forward_size = size;
  19583. +
  19584. + // (tw) There is a new version of the class of q => different size
  19585. + if (oop(q)->blueprint()->new_version() != NULL) {
  19586. +
  19587. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  19588. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  19589. + forward_size = new_size;
  19590. + }
  19591. +
  19592. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  19593. + assert(compact_top <= t, "must not write over end of space!");
  19594. + }
  19595. + MarkSweep::_rescued_oops->clear();
  19596. + MarkSweep::_rescued_oops = NULL;
  19597. + }
  19598. + //////////////////////////////////////////////////////////////////////////
  19599. +
  19600. + assert(q == t, "just checking");
  19601. + if (liveRange != NULL) {
  19602. + liveRange->set_end(q);
  19603. + }
  19604. + _end_of_live = end_of_live;
  19605. + if (end_of_live < first_dead) {
  19606. + first_dead = end_of_live;
  19607. + }
  19608. + _first_dead = first_dead;
  19609. +
  19610. + if (_first_dead > top()) {
  19611. + _first_dead = top();
  19612. + }
  19613. +
  19614. + if (_end_of_live > top()) {
  19615. + _end_of_live = top();
  19616. + }
  19617. + assert(_first_dead <= top(), "Must be smaller equal");
  19618. + assert(_end_of_live <= top(), "Must be smaller equal");
  19619. +
  19620. + /* save the compaction_top of the compaction space. */
  19621. + cp->space->set_compaction_top(compact_top);
  19622. }
  19623. void Space::adjust_pointers() {
  19624. @@ -471,17 +693,322 @@
  19625. assert(q == t, "just checking");
  19626. }
  19627. +
  19628. +#ifdef ASSERT
  19629. +
  19630. +int CompactibleSpace::space_index(oop obj) {
  19631. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  19632. +
  19633. + if (heap->is_in_permanent(obj)) {
  19634. + return -1;
  19635. + }
  19636. +
  19637. + int index = 0;
  19638. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  19639. + Generation* gen = heap->get_gen(i);
  19640. + CompactibleSpace* space = gen->first_compaction_space();
  19641. + while (space != NULL) {
  19642. + if (space->is_in_reserved(obj)) {
  19643. + return index;
  19644. + }
  19645. + space = space->next_compaction_space();
  19646. + index++;
  19647. + }
  19648. + }
  19649. +
  19650. + tty->print_cr("could not compute space_index for %08xh", obj);
  19651. + index = 0;
  19652. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  19653. + Generation* gen = heap->get_gen(i);
  19654. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  19655. +
  19656. + CompactibleSpace* space = gen->first_compaction_space();
  19657. + while (space != NULL) {
  19658. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  19659. + space = space->next_compaction_space();
  19660. + index++;
  19661. + }
  19662. + }
  19663. +
  19664. + ShouldNotReachHere();
  19665. + return 0;
  19666. +}
  19667. +#endif
  19668. +
  19669. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  19670. +
  19671. + assert(is_in_reserved(old_obj), "old_obj must be in this space");
  19672. +
  19673. + if (old_obj->is_perm()) {
  19674. + // This object is in perm gen; check for invariant obj->klass() <= obj
  19675. + if (oop(old_obj)->blueprint()->new_version() != NULL) {
  19676. + return true;
  19677. + }
  19678. + }
  19679. +
  19680. + int size = old_obj->size();
  19681. + int original_size = size;
  19682. + if (oop(old_obj)->blueprint()->is_redefining()) {
  19683. + assert(oop(old_obj)->blueprint()->old_version() != NULL, "must not be null");
  19684. + original_size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->old_version()->klass_part());
  19685. + } else if (oop(old_obj)->blueprint()->new_version() != NULL) {
  19686. + size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->new_version()->klass_part());
  19687. + }
  19688. +
  19689. + bool normalComparison = (old_obj + original_size < new_obj + size);
  19690. +
  19691. + if (is_in_reserved(new_obj)) {
  19692. + // Old and new address are in same space, so just compare the address.
  19693. + // Must rescue if object moves towards the top of the space.
  19694. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  19695. + return normalComparison;
  19696. +
  19697. + } else {
  19698. +
  19699. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  19700. +
  19701. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  19702. + if (tenured_gen->is_in_reserved(new_obj)) {
  19703. + // Must never rescue when moving from the new into the old generation.
  19704. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  19705. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  19706. + return false;
  19707. +
  19708. + } else if (tenured_gen->is_in_reserved(old_obj)) {
  19709. + // Must always rescue when moving from the old into the new generation.
  19710. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  19711. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  19712. + return true;
  19713. +
  19714. + } else {
  19715. + // In the new generation, eden is located before the from space, so a
  19716. + // simple pointer comparison is sufficient.
  19717. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  19718. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  19719. + assert((normalComparison) == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  19720. + return normalComparison;
  19721. + }
  19722. + }
  19723. +}
  19724. +
  19725. +oop CompactibleSpace::rescue(oop old_obj) {
  19726. + assert(must_rescue(old_obj, old_obj->forwardee()), "do not call otherwise");
  19727. +
  19728. + int size = old_obj->size();
  19729. + oop rescued_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  19730. + Copy::aligned_disjoint_words((HeapWord*)old_obj, (HeapWord*)rescued_obj, size);
  19731. +
  19732. + if (MarkSweep::_rescued_oops == NULL) {
  19733. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  19734. + }
  19735. +
  19736. + MarkSweep::_rescued_oops->append(rescued_obj);
  19737. + return rescued_obj;
  19738. +}
  19739. +
  19740. void CompactibleSpace::adjust_pointers() {
  19741. // Check first is there is any work to do.
  19742. if (used() == 0) {
  19743. return; // Nothing to do.
  19744. }
  19745. + /* adjust all the interior pointers to point at the new locations of objects
  19746. + * Used by MarkSweep::mark_sweep_phase3() */
  19747. - SCAN_AND_ADJUST_POINTERS(adjust_obj_size);
  19748. + HeapWord* q = bottom();
  19749. + HeapWord* t = _end_of_live; /* Established by "prepare_for_compaction". */
  19750. +
  19751. + assert(_first_dead <= _end_of_live, "Stands to reason, no?");
  19752. +
  19753. + debug_only(HeapWord* prev_q = NULL);
  19754. + debug_only(HeapWord* prev_prev_q = NULL);
  19755. + debug_only(HeapWord* prev_prev_prev_q = NULL);
  19756. + if (q < t && _first_dead > q &&
  19757. + !oop(q)->is_gc_marked()) {
  19758. + /* we have a chunk of the space which hasn't moved and we've
  19759. + * reinitialized the mark word during the previous pass, so we can't
  19760. + * use is_gc_marked for the traversal. */
  19761. + HeapWord* end = _first_dead;
  19762. +
  19763. + while (q < end) {
  19764. + /* I originally tried to conjoin "block_start(q) == q" to the
  19765. + * assertion below, but that doesn't work, because you can't
  19766. + * accurately traverse previous objects to get to the current one
  19767. + * after their pointers (including pointers into permGen) have been
  19768. + * updated, until the actual compaction is done. dld, 4/00 */
  19769. + assert(block_is_obj(q),
  19770. + "should be at block boundaries, and should be looking at objs");
  19771. +
  19772. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  19773. +
  19774. + /* point all the oops to the new location */
  19775. + size_t size = oop(q)->adjust_pointers();
  19776. + size = adjust_obj_size(size);
  19777. +
  19778. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  19779. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  19780. +
  19781. + debug_only(prev_prev_prev_q = prev_prev_q);
  19782. + debug_only(prev_prev_q = prev_q);
  19783. + debug_only(prev_q = q);
  19784. + q += size;
  19785. + }
  19786. +
  19787. + // (tw) first_dead can be live object!
  19788. + q = _first_dead;
  19789. +
  19790. +// if (_first_dead == t) {
  19791. +// q = t;
  19792. +// } else {
  19793. +// /* $$$ This is funky. Using this to read the previously written
  19794. +// * LiveRange. See also use below. */
  19795. +// q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer();
  19796. +// }
  19797. + }
  19798. +
  19799. + const intx interval = PrefetchScanIntervalInBytes;
  19800. +
  19801. + debug_only(prev_q = NULL);
  19802. + debug_only(prev_prev_q = NULL);
  19803. + debug_only(prev_prev_prev_q = NULL);
  19804. + while (q < t) {
  19805. + /* prefetch beyond q */
  19806. + Prefetch::write(q, interval);
  19807. + if (oop(q)->is_gc_marked()) {
  19808. + /* q is alive */
  19809. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  19810. + /* point all the oops to the new location */
  19811. + size_t size = oop(q)->adjust_pointers();
  19812. + size = adjust_obj_size(size);
  19813. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  19814. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  19815. + debug_only(prev_prev_prev_q = prev_prev_q);
  19816. + debug_only(prev_prev_q = prev_q);
  19817. + debug_only(prev_q = q);
  19818. + q += size;
  19819. + } else {
  19820. + /* q is not a live object, so its mark should point at the next
  19821. + * live object */
  19822. + debug_only(prev_prev_prev_q = prev_prev_q);
  19823. + debug_only(prev_prev_q = prev_q);
  19824. + debug_only(prev_q = q);
  19825. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  19826. + assert(q > prev_q, "we should be moving forward through memory");
  19827. + }
  19828. + }
  19829. +
  19830. + assert(q == t, "just checking");
  19831. }
  19832. void CompactibleSpace::compact() {
  19833. - SCAN_AND_COMPACT(obj_size);
  19834. +
  19835. + if(!Universe::is_redefining_gc_run()) {
  19836. + SCAN_AND_COMPACT(obj_size);
  19837. + return;
  19838. + }
  19839. +
  19840. + /* Copy all live objects to their new location
  19841. + * Used by MarkSweep::mark_sweep_phase4() */
  19842. +
  19843. + HeapWord* q = bottom();
  19844. + HeapWord* const t = _end_of_live;
  19845. + debug_only(HeapWord* prev_q = NULL);
  19846. + debug_only(HeapWord* prev_prev_q = NULL);
  19847. + debug_only(HeapWord* prev_compaction_top = NULL);
  19848. + debug_only(int old_size = 0);
  19849. +
  19850. + if (q < t && _first_dead > q &&
  19851. + !oop(q)->is_gc_marked()) {
  19852. + /* we have a chunk of the space which hasn't moved and we've reinitialized
  19853. + * the mark word during the previous pass, so we can't use is_gc_marked for
  19854. + * the traversal. */
  19855. + HeapWord* const end = _first_dead;
  19856. +
  19857. +#ifdef ASSERT
  19858. + while (q < end) {
  19859. + size_t size = oop(q)->size();
  19860. + assert(!oop(q)->is_gc_marked(),
  19861. + "should be unmarked (special dense prefix handling)");
  19862. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, q));
  19863. + debug_only(prev_prev_q = prev_q);
  19864. + debug_only(prev_q = q);
  19865. + q += size;
  19866. + }
  19867. +#endif
  19868. + // (tw) first_dead can be live object!
  19869. + q = _first_dead;
  19870. +
  19871. + //if (_first_dead == t) {
  19872. + // q = t;
  19873. + //} else {
  19874. + ///* $$$ Funky */
  19875. + //q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer();
  19876. + //}
  19877. + }
  19878. +
  19879. + const intx scan_interval = PrefetchScanIntervalInBytes;
  19880. + const intx copy_interval = PrefetchCopyIntervalInBytes;
  19881. + while (q < t) {
  19882. + if (!oop(q)->is_gc_marked()) {
  19883. + /* mark is pointer to next marked oop */
  19884. + debug_only(prev_prev_q = prev_q);
  19885. + debug_only(prev_q = q);
  19886. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  19887. + assert(q > prev_q, "we should be moving forward through memory");
  19888. + } else {
  19889. + /* prefetch beyond q */
  19890. + Prefetch::read(q, scan_interval);
  19891. +
  19892. + /* size and destination */
  19893. + size_t size = obj_size(q);
  19894. + HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee();
  19895. +
  19896. + size_t original_size = size;
  19897. +
  19898. + if (must_rescue(oop(q), oop(q)->forwardee())) {
  19899. + oop dest_obj = rescue(oop(q));
  19900. + debug_only(Copy::fill_to_words(q, original_size, 0));
  19901. + } else {
  19902. +
  19903. + /* prefetch beyond compaction_top */
  19904. + Prefetch::write(compaction_top, copy_interval);
  19905. +
  19906. + /* copy object and reinit its mark */
  19907. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size,
  19908. + compaction_top));
  19909. + assert(q != compaction_top || oop(q)->blueprint()->new_version() != NULL, "everything in this pass should be moving");
  19910. +
  19911. + if (oop(q)->blueprint()->new_version() != NULL) {
  19912. + MarkSweep::update_fields(oop(q), oop(compaction_top));
  19913. + } else {
  19914. + Copy::aligned_conjoint_words(q, compaction_top, size);
  19915. + }
  19916. + oop(compaction_top)->init_mark();
  19917. + assert(oop(compaction_top)->klass() != NULL, "should have a class");
  19918. + }
  19919. +
  19920. + debug_only(prev_compaction_top = compaction_top);
  19921. + debug_only(prev_prev_q = prev_q);
  19922. + debug_only(prev_q = q);
  19923. + debug_only(old_size = (int)size);
  19924. + q += original_size;
  19925. + }
  19926. + }
  19927. +
  19928. + /* Reset space after compaction is complete */
  19929. + reset_after_compaction();
  19930. + /* We do this clear, below, since it has overloaded meanings for some */
  19931. + /* space subtypes. For example, OffsetTableContigSpace's that were */
  19932. + /* compacted into will have had their offset table thresholds updated */
  19933. + /* continuously, but those that weren't need to have their thresholds */
  19934. + /* re-initialized. Also mangles unused area for debugging. */
  19935. + if (is_empty()) {
  19936. + clear(SpaceDecorator::Mangle);
  19937. + } else {
  19938. + if (ZapUnusedHeapArea) mangle_unused_area();
  19939. + }
  19940. +
  19941. +
  19942. + //SCAN_AND_COMPACT(obj_size);
  19943. }
  19944. void Space::print_short() const { print_short_on(tty); }
  19945. diff -r f5603a6e5042 src/share/vm/memory/space.hpp
  19946. --- a/src/share/vm/memory/space.hpp Wed Nov 17 22:42:08 2010 -0800
  19947. +++ b/src/share/vm/memory/space.hpp Fri Dec 17 13:23:04 2010 +0100
  19948. @@ -419,6 +419,9 @@
  19949. // indicates when the next such action should be taken.
  19950. virtual void prepare_for_compaction(CompactPoint* cp);
  19951. // MarkSweep support phase3
  19952. + DEBUG_ONLY(int space_index(oop obj));
  19953. + bool must_rescue(oop old_obj, oop new_obj);
  19954. + oop rescue(oop old_obj);
  19955. virtual void adjust_pointers();
  19956. // MarkSweep support phase4
  19957. virtual void compact();
  19958. @@ -449,6 +452,10 @@
  19959. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  19960. HeapWord* compact_top);
  19961. + // (tw)
  19962. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp,
  19963. + HeapWord* compact_top);
  19964. +
  19965. // Return a size with adjusments as required of the space.
  19966. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  19967. diff -r f5603a6e5042 src/share/vm/memory/universe.cpp
  19968. --- a/src/share/vm/memory/universe.cpp Wed Nov 17 22:42:08 2010 -0800
  19969. +++ b/src/share/vm/memory/universe.cpp Fri Dec 17 13:23:04 2010 +0100
  19970. @@ -25,6 +25,8 @@
  19971. # include "incls/_precompiled.incl"
  19972. # include "incls/_universe.cpp.incl"
  19973. +bool Universe::_is_redefining_gc_run = false;
  19974. +
  19975. // Known objects
  19976. klassOop Universe::_boolArrayKlassObj = NULL;
  19977. klassOop Universe::_byteArrayKlassObj = NULL;
  19978. @@ -131,6 +133,43 @@
  19979. f(systemObjArrayKlassObj());
  19980. }
  19981. +// (tw) This method should iterate all pointers that are not within heap objects.
  19982. +void Universe::root_oops_do(OopClosure *oopClosure) {
  19983. +
  19984. + class AlwaysTrueClosure: public BoolObjectClosure {
  19985. + public:
  19986. + void do_object(oop p) { ShouldNotReachHere(); }
  19987. + bool do_object_b(oop p) { return true; }
  19988. + };
  19989. + AlwaysTrueClosure always_true;
  19990. +
  19991. + Universe::oops_do(oopClosure);
  19992. + ReferenceProcessor::oops_do(oopClosure);
  19993. + JNIHandles::oops_do(oopClosure); // Global (strong) JNI handles
  19994. + Threads::oops_do(oopClosure, NULL);
  19995. + ObjectSynchronizer::oops_do(oopClosure);
  19996. + FlatProfiler::oops_do(oopClosure);
  19997. + JvmtiExport::oops_do(oopClosure);
  19998. + // SO_AllClasses
  19999. + SystemDictionary::oops_do(oopClosure);
  20000. + vmSymbols::oops_do(oopClosure);
  20001. +
  20002. + // Now adjust pointers in remaining weak roots. (All of which should
  20003. + // have been cleared if they pointed to non-surviving objects.)
  20004. + // Global (weak) JNI handles
  20005. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  20006. +
  20007. + CodeCache::oops_do(oopClosure);
  20008. + SymbolTable::oops_do(oopClosure);
  20009. + StringTable::oops_do(oopClosure);
  20010. +
  20011. + // (tw) TODO: Check if this is correct?
  20012. + //CodeCache::scavenge_root_nmethods_oops_do(oopClosure);
  20013. + //Management::oops_do(oopClosure);
  20014. + //ref_processor()->weak_oops_do(&oopClosure);
  20015. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure);
  20016. +}
  20017. +
  20018. void Universe::oops_do(OopClosure* f, bool do_all) {
  20019. f->do_oop((oop*) &_int_mirror);
  20020. @@ -1424,10 +1463,9 @@
  20021. }
  20022. // RC_TRACE macro has an embedded ResourceMark
  20023. - RC_TRACE(0x00000100,
  20024. - ("add: %s(%s): adding prev version ref for cached method @%d",
  20025. + TRACE_RC2("add: %s(%s): adding prev version ref for cached method @%d",
  20026. method->name()->as_C_string(), method->signature()->as_C_string(),
  20027. - _prev_methods->length()));
  20028. + _prev_methods->length());
  20029. methodHandle method_h(method);
  20030. jweak method_ref = JNIHandles::make_weak_global(method_h);
  20031. @@ -1454,9 +1492,8 @@
  20032. JNIHandles::destroy_weak_global(method_ref);
  20033. _prev_methods->remove_at(i);
  20034. } else {
  20035. - // RC_TRACE macro has an embedded ResourceMark
  20036. - RC_TRACE(0x00000400, ("add: %s(%s): previous cached method @%d is alive",
  20037. - m->name()->as_C_string(), m->signature()->as_C_string(), i));
  20038. + TRACE_RC2("add: %s(%s): previous cached method @%d is alive",
  20039. + m->name()->as_C_string(), m->signature()->as_C_string(), i);
  20040. }
  20041. }
  20042. } // end add_previous_version()
  20043. diff -r f5603a6e5042 src/share/vm/memory/universe.hpp
  20044. --- a/src/share/vm/memory/universe.hpp Wed Nov 17 22:42:08 2010 -0800
  20045. +++ b/src/share/vm/memory/universe.hpp Fri Dec 17 13:23:04 2010 +0100
  20046. @@ -113,6 +113,8 @@
  20047. friend class SystemDictionary;
  20048. friend class VMStructs;
  20049. friend class CompactingPermGenGen;
  20050. + friend class Space;
  20051. + friend class ContiguousSpace;
  20052. friend class VM_PopulateDumpSharedSpace;
  20053. friend jint universe_init();
  20054. @@ -246,7 +248,18 @@
  20055. static void compute_verify_oop_data();
  20056. + static bool _is_redefining_gc_run;
  20057. +
  20058. public:
  20059. +
  20060. + static bool is_redefining_gc_run() {
  20061. + return _is_redefining_gc_run;
  20062. + }
  20063. +
  20064. + static void set_redefining_gc_run(bool b) {
  20065. + _is_redefining_gc_run = b;
  20066. + }
  20067. +
  20068. // Known classes in the VM
  20069. static klassOop boolArrayKlassObj() { return _boolArrayKlassObj; }
  20070. static klassOop byteArrayKlassObj() { return _byteArrayKlassObj; }
  20071. @@ -388,6 +401,8 @@
  20072. // Iteration
  20073. + static void root_oops_do(OopClosure *f);
  20074. +
  20075. // Apply "f" to the addresses of all the direct heap pointers maintained
  20076. // as static fields of "Universe".
  20077. static void oops_do(OopClosure* f, bool do_all = false);
  20078. @@ -404,6 +419,7 @@
  20079. // Debugging
  20080. static bool verify_in_progress() { return _verify_in_progress; }
  20081. + static void set_verify_in_progress(bool b) { _verify_in_progress = b; }
  20082. static void verify(bool allow_dirty = true, bool silent = false, bool option = true);
  20083. static int verify_count() { return _verify_count; }
  20084. static void print();
  20085. diff -r f5603a6e5042 src/share/vm/oops/arrayKlass.cpp
  20086. --- a/src/share/vm/oops/arrayKlass.cpp Wed Nov 17 22:42:08 2010 -0800
  20087. +++ b/src/share/vm/oops/arrayKlass.cpp Fri Dec 17 13:23:04 2010 +0100
  20088. @@ -117,9 +117,9 @@
  20089. bool arrayKlass::compute_is_subtype_of(klassOop k) {
  20090. // An array is a subtype of Serializable, Clonable, and Object
  20091. - return k == SystemDictionary::Object_klass()
  20092. - || k == SystemDictionary::Cloneable_klass()
  20093. - || k == SystemDictionary::Serializable_klass();
  20094. + return k->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version()
  20095. + || k->klass_part()->newest_version() == SystemDictionary::Cloneable_klass()->klass_part()->newest_version()
  20096. + || k->klass_part()->newest_version() == SystemDictionary::Serializable_klass()->klass_part()->newest_version();
  20097. }
  20098. diff -r f5603a6e5042 src/share/vm/oops/constMethodKlass.cpp
  20099. --- a/src/share/vm/oops/constMethodKlass.cpp Wed Nov 17 22:42:08 2010 -0800
  20100. +++ b/src/share/vm/oops/constMethodKlass.cpp Fri Dec 17 13:23:04 2010 +0100
  20101. @@ -93,6 +93,7 @@
  20102. MarkSweep::mark_and_push(cm->adr_method());
  20103. MarkSweep::mark_and_push(cm->adr_stackmap_data());
  20104. MarkSweep::mark_and_push(cm->adr_exception_table());
  20105. + MarkSweep::mark_and_push(cm->adr_code_section_table());
  20106. // Performance tweak: We skip iterating over the klass pointer since we
  20107. // know that Universe::constMethodKlassObj never moves.
  20108. }
  20109. @@ -105,6 +106,7 @@
  20110. PSParallelCompact::mark_and_push(cm, cm_oop->adr_method());
  20111. PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data());
  20112. PSParallelCompact::mark_and_push(cm, cm_oop->adr_exception_table());
  20113. + PSParallelCompact::mark_and_push(cm, cm_oop->adr_code_section_table());
  20114. // Performance tweak: We skip iterating over the klass pointer since we
  20115. // know that Universe::constMethodKlassObj never moves.
  20116. }
  20117. @@ -116,6 +118,7 @@
  20118. blk->do_oop(cm->adr_method());
  20119. blk->do_oop(cm->adr_stackmap_data());
  20120. blk->do_oop(cm->adr_exception_table());
  20121. + blk->do_oop(cm->adr_code_section_table());
  20122. // Get size before changing pointers.
  20123. // Don't call size() or oop_size() since that is a virtual call.
  20124. int size = cm->object_size();
  20125. @@ -133,6 +136,8 @@
  20126. if (mr.contains(adr)) blk->do_oop(adr);
  20127. adr = cm->adr_exception_table();
  20128. if (mr.contains(adr)) blk->do_oop(adr);
  20129. + adr = cm->adr_code_section_table();
  20130. + if (mr.contains(adr)) blk->do_oop(adr);
  20131. // Get size before changing pointers.
  20132. // Don't call size() or oop_size() since that is a virtual call.
  20133. int size = cm->object_size();
  20134. @@ -148,6 +153,7 @@
  20135. MarkSweep::adjust_pointer(cm->adr_method());
  20136. MarkSweep::adjust_pointer(cm->adr_stackmap_data());
  20137. MarkSweep::adjust_pointer(cm->adr_exception_table());
  20138. + MarkSweep::adjust_pointer(cm->adr_code_section_table());
  20139. // Get size before changing pointers.
  20140. // Don't call size() or oop_size() since that is a virtual call.
  20141. int size = cm->object_size();
  20142. @@ -167,6 +173,7 @@
  20143. #if 0
  20144. PSParallelCompact::adjust_pointer(cm_oop->adr_method());
  20145. PSParallelCompact::adjust_pointer(cm_oop->adr_exception_table());
  20146. + PSParallelCompact::adjust_pointer(cm_oop->adr_code_section_table());
  20147. PSParallelCompact::adjust_pointer(cm_oop->adr_stackmap_data());
  20148. #endif
  20149. oop* const beg_oop = cm_oop->oop_block_beg();
  20150. diff -r f5603a6e5042 src/share/vm/oops/constMethodOop.hpp
  20151. --- a/src/share/vm/oops/constMethodOop.hpp Wed Nov 17 22:42:08 2010 -0800
  20152. +++ b/src/share/vm/oops/constMethodOop.hpp Fri Dec 17 13:23:04 2010 +0100
  20153. @@ -108,7 +108,7 @@
  20154. public:
  20155. oop* oop_block_beg() const { return adr_method(); }
  20156. - oop* oop_block_end() const { return adr_exception_table() + 1; }
  20157. + oop* oop_block_end() const { return adr_code_section_table() + 1; }
  20158. private:
  20159. //
  20160. @@ -126,6 +126,10 @@
  20161. // table is pointing to Universe::the_empty_int_array
  20162. typeArrayOop _exception_table;
  20163. +
  20164. + // (tw) Table mapping code sections for method forward points.
  20165. + typeArrayOop _code_section_table;
  20166. +
  20167. //
  20168. // End of the oop block.
  20169. //
  20170. @@ -178,6 +182,28 @@
  20171. void set_exception_table(typeArrayOop e) { oop_store_without_check((oop*) &_exception_table, (oop) e); }
  20172. bool has_exception_handler() const { return exception_table() != NULL && exception_table()->length() > 0; }
  20173. + // code section table
  20174. + typeArrayOop code_section_table() const { return _code_section_table; }
  20175. + void set_code_section_table(typeArrayOop e) { oop_store_without_check((oop*) &_code_section_table, (oop) e); }
  20176. + bool has_code_section_table() const { return code_section_table() != NULL && code_section_table()->length() > 0; }
  20177. + static const int ValuesPerCodeSectionEntry = 3;
  20178. + int code_section_entries() const {
  20179. + if (!has_code_section_table()) return 0;
  20180. + return _code_section_table->length() / ValuesPerCodeSectionEntry;
  20181. + }
  20182. +
  20183. + int code_section_new_index_at(int index) const {
  20184. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry);
  20185. + }
  20186. +
  20187. + int code_section_original_index_at(int index) const {
  20188. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 1);
  20189. + }
  20190. +
  20191. + int code_section_length_at(int index) const {
  20192. + return _code_section_table->short_at(index * ValuesPerCodeSectionEntry + 2);
  20193. + }
  20194. +
  20195. void init_fingerprint() {
  20196. const uint64_t initval = CONST64(0x8000000000000000);
  20197. _fingerprint = initval;
  20198. @@ -279,6 +305,7 @@
  20199. oop* adr_method() const { return (oop*)&_method; }
  20200. oop* adr_stackmap_data() const { return (oop*)&_stackmap_data; }
  20201. oop* adr_exception_table() const { return (oop*)&_exception_table; }
  20202. + oop* adr_code_section_table() const { return (oop*)&_code_section_table; }
  20203. bool is_conc_safe() { return _is_conc_safe; }
  20204. void set_is_conc_safe(bool v) { _is_conc_safe = v; }
  20205. diff -r f5603a6e5042 src/share/vm/oops/cpCacheOop.cpp
  20206. --- a/src/share/vm/oops/cpCacheOop.cpp Wed Nov 17 22:42:08 2010 -0800
  20207. +++ b/src/share/vm/oops/cpCacheOop.cpp Fri Dec 17 13:23:04 2010 +0100
  20208. @@ -28,9 +28,15 @@
  20209. // Implememtation of ConstantPoolCacheEntry
  20210. +void ConstantPoolCacheEntry::copy_from(ConstantPoolCacheEntry *other) {
  20211. + _flags = other->_flags; // flags
  20212. +}
  20213. +
  20214. void ConstantPoolCacheEntry::initialize_entry(int index) {
  20215. assert(0 < index && index < 0x10000, "sanity check");
  20216. _indices = index;
  20217. + _f1 = NULL;
  20218. + _f2 = 0;
  20219. assert(constant_pool_index() == index, "");
  20220. }
  20221. @@ -42,7 +48,7 @@
  20222. int ConstantPoolCacheEntry::as_flags(TosState state, bool is_final,
  20223. bool is_vfinal, bool is_volatile,
  20224. - bool is_method_interface, bool is_method) {
  20225. + bool is_method_interface, bool is_method, bool is_old_method) {
  20226. int f = state;
  20227. assert( state < number_of_states, "Invalid state in as_flags");
  20228. @@ -57,7 +63,9 @@
  20229. if (is_method_interface) f |= 1;
  20230. f <<= 1;
  20231. if (is_method) f |= 1;
  20232. - f <<= ConstantPoolCacheEntry::hotSwapBit;
  20233. + f <<= 1;
  20234. + if (is_old_method) f |= 1;
  20235. + f <<= ConstantPoolCacheEntry::oldMethodBit;
  20236. // Preserve existing flag bit values
  20237. #ifdef ASSERT
  20238. int old_state = ((_flags >> tosBits) & 0x0F);
  20239. @@ -133,7 +141,7 @@
  20240. const int field_index = orig_field_index / instanceKlass::next_offset;
  20241. assert(field_index <= field_index_mask,
  20242. "field index does not fit in low flag bits");
  20243. - set_flags(as_flags(field_type, is_final, false, is_volatile, false, false) |
  20244. + set_flags(as_flags(field_type, is_final, false, is_volatile, false, false, false) |
  20245. (field_index & field_index_mask));
  20246. set_bytecode_1(get_code);
  20247. set_bytecode_2(put_code);
  20248. @@ -149,7 +157,8 @@
  20249. int vtable_index) {
  20250. assert(!is_secondary_entry(), "");
  20251. assert(method->interpreter_entry() != NULL, "should have been set at this point");
  20252. - assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  20253. + // (tw) No longer valid assert
  20254. + //assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  20255. bool change_to_virtual = (invoke_code == Bytecodes::_invokeinterface);
  20256. int byte_no = -1;
  20257. @@ -163,6 +172,9 @@
  20258. } else {
  20259. assert(vtable_index >= 0, "valid index");
  20260. set_f2(vtable_index);
  20261. +
  20262. + // (tw) save method holder in f1 for virtual calls
  20263. + set_f1(method());
  20264. }
  20265. byte_no = 2;
  20266. break;
  20267. @@ -208,7 +220,7 @@
  20268. needs_vfinal_flag,
  20269. false,
  20270. change_to_virtual,
  20271. - true)|
  20272. + true, method->is_old())|
  20273. method()->size_of_parameters());
  20274. // Note: byte_no also appears in TemplateTable::resolve.
  20275. @@ -248,7 +260,7 @@
  20276. assert(instanceKlass::cast(interf)->is_interface(), "must be an interface");
  20277. set_f1(interf);
  20278. set_f2(index);
  20279. - set_flags(as_flags(as_TosState(method->result_type()), method->is_final_method(), false, false, false, true) | method()->size_of_parameters());
  20280. + set_flags(as_flags(as_TosState(method->result_type()), method->is_final_method(), false, false, false, true, method->is_old()) | method()->size_of_parameters());
  20281. set_bytecode_1(Bytecodes::_invokeinterface);
  20282. }
  20283. @@ -279,7 +291,7 @@
  20284. }
  20285. bool is_final = true;
  20286. assert(signature_invoker->is_final_method(), "is_final");
  20287. - set_flags(as_flags(as_TosState(signature_invoker->result_type()), is_final, false, false, false, true) | param_size);
  20288. + set_flags(as_flags(as_TosState(signature_invoker->result_type()), is_final, false, false, false, true, false) | param_size);
  20289. // do not do set_bytecode on a secondary CP cache entry
  20290. //set_bytecode_1(Bytecodes::_invokedynamic);
  20291. }
  20292. @@ -376,26 +388,13 @@
  20293. // If this constantPoolCacheEntry refers to old_method then update it
  20294. // to refer to new_method.
  20295. bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  20296. - methodOop new_method, bool * trace_name_printed) {
  20297. + methodOop new_method) {
  20298. if (is_vfinal()) {
  20299. +
  20300. // virtual and final so f2() contains method ptr instead of vtable index
  20301. - if (f2() == (intptr_t)old_method) {
  20302. - // match old_method so need an update
  20303. - _f2 = (intptr_t)new_method;
  20304. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  20305. - if (!(*trace_name_printed)) {
  20306. - // RC_TRACE_MESG macro has an embedded ResourceMark
  20307. - RC_TRACE_MESG(("adjust: name=%s",
  20308. - Klass::cast(old_method->method_holder())->external_name()));
  20309. - *trace_name_printed = true;
  20310. - }
  20311. - // RC_TRACE macro has an embedded ResourceMark
  20312. - RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
  20313. - new_method->name()->as_C_string(),
  20314. - new_method->signature()->as_C_string()));
  20315. - }
  20316. -
  20317. + if((methodOop)f2() != NULL && ((methodOop)f2())->method_holder()->klass_part()->new_version()) {
  20318. + initialize_entry(constant_pool_index());
  20319. return true;
  20320. }
  20321. @@ -403,65 +402,28 @@
  20322. return false;
  20323. }
  20324. - if ((oop)_f1 == NULL) {
  20325. - // NULL f1() means this is a virtual entry so bail out
  20326. - // We are assuming that the vtable index does not need change.
  20327. + // (tw) check how to update interface methods!
  20328. + if (bytecode_1() == Bytecodes::_invokevirtual || bytecode_2() == Bytecodes::_invokevirtual) {
  20329. +
  20330. + if(((methodOop)f1())->method_holder()->klass_part()->new_version()) {
  20331. + initialize_entry(constant_pool_index());
  20332. + return true;
  20333. + }
  20334. +
  20335. return false;
  20336. }
  20337. if ((oop)_f1 == old_method) {
  20338. _f1 = new_method;
  20339. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  20340. - if (!(*trace_name_printed)) {
  20341. - // RC_TRACE_MESG macro has an embedded ResourceMark
  20342. - RC_TRACE_MESG(("adjust: name=%s",
  20343. - Klass::cast(old_method->method_holder())->external_name()));
  20344. - *trace_name_printed = true;
  20345. - }
  20346. - // RC_TRACE macro has an embedded ResourceMark
  20347. - RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
  20348. - new_method->name()->as_C_string(),
  20349. - new_method->signature()->as_C_string()));
  20350. - }
  20351. -
  20352. + return true;
  20353. + } else if(_f1 != NULL && (bytecode_1() != Bytecodes::_invokeinterface && ((methodOop)f1())->method_holder()->klass_part()->new_version())) {
  20354. + initialize_entry(constant_pool_index());
  20355. return true;
  20356. }
  20357. return false;
  20358. }
  20359. -bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
  20360. - if (!is_method_entry()) {
  20361. - // not a method entry so not interesting by default
  20362. - return false;
  20363. - }
  20364. -
  20365. - methodOop m = NULL;
  20366. - if (is_vfinal()) {
  20367. - // virtual and final so _f2 contains method ptr instead of vtable index
  20368. - m = (methodOop)_f2;
  20369. - } else if ((oop)_f1 == NULL) {
  20370. - // NULL _f1 means this is a virtual entry so also not interesting
  20371. - return false;
  20372. - } else {
  20373. - if (!((oop)_f1)->is_method()) {
  20374. - // _f1 can also contain a klassOop for an interface
  20375. - return false;
  20376. - }
  20377. - m = (methodOop)_f1;
  20378. - }
  20379. -
  20380. - assert(m != NULL && m->is_method(), "sanity check");
  20381. - if (m == NULL || !m->is_method() || m->method_holder() != k) {
  20382. - // robustness for above sanity checks or method is not in
  20383. - // the interesting class
  20384. - return false;
  20385. - }
  20386. -
  20387. - // the method is in the interesting class so the entry is interesting
  20388. - return true;
  20389. -}
  20390. -
  20391. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  20392. // print separator
  20393. if (index == 0) tty->print_cr(" -------------");
  20394. @@ -502,38 +464,18 @@
  20395. // RedefineClasses() API support:
  20396. // If any entry of this constantPoolCache points to any of
  20397. // old_methods, replace it with the corresponding new_method.
  20398. -void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  20399. - int methods_length, bool * trace_name_printed) {
  20400. -
  20401. - if (methods_length == 0) {
  20402. - // nothing to do if there are no methods
  20403. - return;
  20404. - }
  20405. -
  20406. - // get shorthand for the interesting class
  20407. - klassOop old_holder = old_methods[0]->method_holder();
  20408. +void constantPoolCacheOopDesc::adjust_entries(methodOop* old_methods, methodOop* new_methods,
  20409. + int methods_length) {
  20410. for (int i = 0; i < length(); i++) {
  20411. - if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
  20412. - // skip uninteresting methods
  20413. - continue;
  20414. - }
  20415. + if (entry_at(i)->is_field_entry()) {
  20416. - // The constantPoolCache contains entries for several different
  20417. - // things, but we only care about methods. In fact, we only care
  20418. - // about methods in the same class as the one that contains the
  20419. - // old_methods. At this point, we have an interesting entry.
  20420. -
  20421. - for (int j = 0; j < methods_length; j++) {
  20422. - methodOop old_method = old_methods[j];
  20423. - methodOop new_method = new_methods[j];
  20424. -
  20425. - if (entry_at(i)->adjust_method_entry(old_method, new_method,
  20426. - trace_name_printed)) {
  20427. - // current old_method matched this entry and we updated it so
  20428. - // break out and get to the next interesting entry if there one
  20429. - break;
  20430. - }
  20431. + // (tw) TODO: Update only field offsets and modify only constant pool entries that
  20432. + // point to changed fields
  20433. + entry_at(i)->initialize_entry(entry_at(i)->constant_pool_index());
  20434. +
  20435. + } else if(entry_at(i)->is_method_entry()) {
  20436. + entry_at(i)->adjust_method_entry(NULL, NULL);
  20437. }
  20438. }
  20439. }
  20440. diff -r f5603a6e5042 src/share/vm/oops/cpCacheOop.hpp
  20441. --- a/src/share/vm/oops/cpCacheOop.hpp Wed Nov 17 22:42:08 2010 -0800
  20442. +++ b/src/share/vm/oops/cpCacheOop.hpp Fri Dec 17 13:23:04 2010 +0100
  20443. @@ -127,19 +127,24 @@
  20444. void set_bytecode_2(Bytecodes::Code code);
  20445. void set_f1(oop f1) {
  20446. oop existing_f1 = _f1; // read once
  20447. - assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  20448. + // (tw) need to relax assertion for redefinition
  20449. + // assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  20450. oop_store(&_f1, f1);
  20451. }
  20452. void set_f1_if_null_atomic(oop f1);
  20453. - void set_f2(intx f2) { assert(_f2 == 0 || _f2 == f2, "illegal field change"); _f2 = f2; }
  20454. + void set_f2(intx f2) {
  20455. + // (tw) need to relax assertion for redefinition
  20456. + // assert(_f2 == 0 || _f2 == f2, "illegal field change");
  20457. + _f2 = f2; }
  20458. int as_flags(TosState state, bool is_final, bool is_vfinal, bool is_volatile,
  20459. - bool is_method_interface, bool is_method);
  20460. + bool is_method_interface, bool is_method, bool is_old_method);
  20461. void set_flags(intx flags) { _flags = flags; }
  20462. public:
  20463. // specific bit values in flag field
  20464. // Note: the interpreter knows this layout!
  20465. enum FlagBitValues {
  20466. + oldMethodBit = 22,
  20467. hotSwapBit = 23,
  20468. methodInterface = 24,
  20469. volatileField = 25,
  20470. @@ -159,6 +164,8 @@
  20471. void initialize_entry(int original_index); // initialize primary entry
  20472. void initialize_secondary_entry(int main_index); // initialize secondary entry
  20473. + void copy_from(ConstantPoolCacheEntry *other);
  20474. +
  20475. void set_field( // sets entry to resolved field state
  20476. Bytecodes::Code get_code, // the bytecode used for reading the field
  20477. Bytecodes::Code put_code, // the bytecode used for writing the field
  20478. @@ -287,9 +294,7 @@
  20479. // trace_name_printed is set to true if the current call has
  20480. // printed the klass name so that other routines in the adjust_*
  20481. // group don't print the klass name.
  20482. - bool adjust_method_entry(methodOop old_method, methodOop new_method,
  20483. - bool * trace_name_printed);
  20484. - bool is_interesting_method_entry(klassOop k);
  20485. + bool adjust_method_entry(methodOop old_method, methodOop new_method);
  20486. bool is_field_entry() const { return (_flags & (1 << hotSwapBit)) == 0; }
  20487. bool is_method_entry() const { return (_flags & (1 << hotSwapBit)) != 0; }
  20488. @@ -397,12 +402,7 @@
  20489. return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
  20490. }
  20491. - // RedefineClasses() API support:
  20492. - // If any entry of this constantPoolCache points to any of
  20493. - // old_methods, replace it with the corresponding new_method.
  20494. - // trace_name_printed is set to true if the current call has
  20495. - // printed the klass name so that other routines in the adjust_*
  20496. - // group don't print the klass name.
  20497. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  20498. - int methods_length, bool * trace_name_printed);
  20499. + // (tw) Update method and field references
  20500. + void adjust_entries(methodOop* old_methods, methodOop* new_methods,
  20501. + int methods_length);
  20502. };
  20503. diff -r f5603a6e5042 src/share/vm/oops/instanceKlass.cpp
  20504. --- a/src/share/vm/oops/instanceKlass.cpp Wed Nov 17 22:42:08 2010 -0800
  20505. +++ b/src/share/vm/oops/instanceKlass.cpp Fri Dec 17 13:23:04 2010 +0100
  20506. @@ -157,12 +157,116 @@
  20507. }
  20508. +void instanceKlass::initialize_redefined_class() {
  20509. +
  20510. + TRACE_RC3("initializing redefined class %s", name()->as_C_string());
  20511. +
  20512. + assert(!is_initialized(), "");
  20513. + assert(this->old_version() != NULL, "");
  20514. + assert(is_linked(), "must be linked before");
  20515. +
  20516. +
  20517. + instanceKlassHandle this_oop(Thread::current(), this->as_klassOop());
  20518. + class UpdateStaticFieldClosure : public FieldClosure {
  20519. +
  20520. + private:
  20521. + instanceKlassHandle this_oop;
  20522. +
  20523. + public:
  20524. + UpdateStaticFieldClosure(instanceKlassHandle this_oop) {
  20525. + this->this_oop = this_oop;
  20526. + }
  20527. +
  20528. + virtual void do_field(fieldDescriptor* fd) {
  20529. + fieldDescriptor result;
  20530. + bool found = ((instanceKlass *)(this_oop->old_version()->klass_part()))->find_local_field(fd->name(), fd->signature(), &result);
  20531. +
  20532. + if (found && result.is_static()) {
  20533. + int old_offset = result.offset();
  20534. + assert(result.field_type() == fd->field_type(), "");
  20535. +
  20536. + oop new_location = this_oop();
  20537. + oop old_location = this_oop->old_version();
  20538. + int offset = fd->offset();
  20539. + TRACE_RC3("Copying static field value for field %s old_offset=%d new_offset=%d", fd->name()->as_C_string(), old_offset, offset);
  20540. +
  20541. + oop cur_oop;
  20542. +
  20543. + switch(result.field_type()) {
  20544. +
  20545. + // Found static field with same name and type in the old klass => copy value from old to new klass
  20546. +
  20547. + case T_BOOLEAN:
  20548. + new_location->bool_field_put(offset, old_location->bool_field(old_offset));
  20549. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  20550. + break;
  20551. +
  20552. + case T_CHAR:
  20553. + new_location->char_field_put(offset, old_location->char_field(old_offset));
  20554. + DEBUG_ONLY(old_location->char_field_put(old_offset, 0));
  20555. + break;
  20556. +
  20557. + case T_FLOAT:
  20558. + new_location->float_field_put(offset, old_location->float_field(old_offset));
  20559. + DEBUG_ONLY(old_location->float_field_put(old_offset, 0));
  20560. + break;
  20561. +
  20562. + case T_DOUBLE:
  20563. + new_location->double_field_put(offset, old_location->double_field(old_offset));
  20564. + DEBUG_ONLY(old_location->double_field_put(old_offset, 0));
  20565. + break;
  20566. +
  20567. + case T_BYTE:
  20568. + new_location->byte_field_put(offset, old_location->byte_field(old_offset));
  20569. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  20570. + break;
  20571. +
  20572. + case T_SHORT:
  20573. + new_location->short_field_put(offset, old_location->short_field(old_offset));
  20574. + DEBUG_ONLY(old_location->short_field_put(old_offset, 0));
  20575. + break;
  20576. +
  20577. + case T_INT:
  20578. + new_location->int_field_put(offset, old_location->int_field(old_offset));
  20579. + DEBUG_ONLY(old_location->int_field_put(old_offset, 0));
  20580. + break;
  20581. +
  20582. + case T_LONG:
  20583. + new_location->long_field_put(offset, old_location->long_field(old_offset));
  20584. + DEBUG_ONLY(old_location->long_field_put(old_offset, 0));
  20585. + break;
  20586. +
  20587. + case T_OBJECT:
  20588. + case T_ARRAY:
  20589. + cur_oop = old_location->obj_field(old_offset);
  20590. + new_location->obj_field_raw_put(offset, cur_oop);
  20591. + old_location->obj_field_raw_put(old_offset, NULL);
  20592. + break;
  20593. +
  20594. + default:
  20595. + ShouldNotReachHere();
  20596. + }
  20597. + } else {
  20598. +
  20599. + TRACE_RC2("New static field %s has_initial_value=%d", fd->name()->as_C_string(), (int)(fd->has_initial_value()));
  20600. + // field not found
  20601. + // (tw) TODO: Probably this call is not necessary here!
  20602. + ClassFileParser::initialize_static_field(fd, Thread::current());
  20603. + }
  20604. + }
  20605. + };
  20606. +
  20607. + UpdateStaticFieldClosure cl(this_oop);
  20608. + this->do_local_static_fields(&cl);
  20609. +}
  20610. +
  20611. +
  20612. bool instanceKlass::verify_code(
  20613. instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) {
  20614. // 1) Verify the bytecodes
  20615. Verifier::Mode mode =
  20616. throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
  20617. - return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false);
  20618. + return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), true, CHECK_false);
  20619. }
  20620. @@ -269,7 +373,13 @@
  20621. jt->get_thread_stat()->perf_recursion_counts_addr(),
  20622. jt->get_thread_stat()->perf_timers_addr(),
  20623. PerfClassTraceTime::CLASS_VERIFY);
  20624. - bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  20625. + if (this_oop->is_redefining()) {
  20626. + Thread::current()->set_pretend_new_universe(true);
  20627. + }
  20628. + bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  20629. + if (this_oop->is_redefining()) {
  20630. + Thread::current()->set_pretend_new_universe(false);
  20631. + }
  20632. if (!verify_ok) {
  20633. return false;
  20634. }
  20635. @@ -304,7 +414,8 @@
  20636. }
  20637. #endif
  20638. this_oop->set_init_state(linked);
  20639. - if (JvmtiExport::should_post_class_prepare()) {
  20640. + // (tw) Must check for old version in order to prevent infinite loops.
  20641. + if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
  20642. Thread *thread = THREAD;
  20643. assert(thread->is_Java_thread(), "thread->is_Java_thread()");
  20644. JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
  20645. @@ -571,6 +682,18 @@
  20646. return false;
  20647. }
  20648. +bool instanceKlass::implements_interface_any_version(klassOop k) const {
  20649. + k = k->klass_part()->newest_version();
  20650. + if (this->newest_version() == k) return true;
  20651. + assert(Klass::cast(k)->is_interface(), "should be an interface class");
  20652. + for (int i = 0; i < transitive_interfaces()->length(); i++) {
  20653. + if (((klassOop)transitive_interfaces()->obj_at(i))->klass_part()->newest_version() == k) {
  20654. + return true;
  20655. + }
  20656. + }
  20657. + return false;
  20658. +}
  20659. +
  20660. objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) {
  20661. if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
  20662. if (length > arrayOopDesc::max_array_length(T_OBJECT)) {
  20663. @@ -691,7 +814,25 @@
  20664. }
  20665. void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) {
  20666. +
  20667. + ResourceMark rm(THREAD);
  20668. methodHandle h_method(THREAD, this_oop->class_initializer());
  20669. +
  20670. + if (this_oop->revision_number() != -1){
  20671. + methodOop m = NULL;
  20672. + if (AllowAdvancedClassRedefinition) {
  20673. + m = this_oop->find_method(vmSymbols::static_transformer_name(), vmSymbols::void_method_signature());
  20674. + }
  20675. + methodHandle method(m);
  20676. + if (method() != NULL && method()->is_static()) {
  20677. + TRACE_RC2("Calling static transformer instead of static initializer");
  20678. + h_method = method;
  20679. + } else if (!((instanceKlass*)this_oop->old_version()->klass_part())->is_not_initialized()) {
  20680. + // Only execute the static initializer, if it was not yet executed for the old version of the class.
  20681. + return;
  20682. + }
  20683. + }
  20684. +
  20685. assert(!this_oop->is_initialized(), "we cannot initialize twice");
  20686. if (TraceClassInitialization) {
  20687. tty->print("%d Initializing ", call_class_initializer_impl_counter++);
  20688. @@ -843,6 +984,153 @@
  20689. }
  20690. }
  20691. +void instanceKlass::store_update_information(GrowableArray<int> &values) {
  20692. + int *arr = NEW_C_HEAP_ARRAY(int, values.length());
  20693. + for (int i=0; i<values.length(); i++) {
  20694. + arr[i] = values.at(i);
  20695. + }
  20696. + set_update_information(arr);
  20697. +}
  20698. +
  20699. +void instanceKlass::clear_update_information() {
  20700. + FREE_C_HEAP_ARRAY(int, update_information());
  20701. + set_update_information(NULL);
  20702. +}
  20703. +
  20704. +typedef Pair<int, klassOop> typeInfoPair;
  20705. +
  20706. +void instanceKlass::store_type_check_information(GrowableArray< Pair<int, klassOop> > &values) {
  20707. + Pair<int, klassOop> *arr = NEW_C_HEAP_ARRAY(typeInfoPair, values.length());
  20708. + for (int i=0; i<values.length(); i++) {
  20709. + arr[i] = values.at(i);
  20710. + }
  20711. + set_type_check_information(arr);
  20712. +}
  20713. +
  20714. +void instanceKlass::clear_type_check_information() {
  20715. + FREE_C_HEAP_ARRAY(typeInfoPair, type_check_information());
  20716. + set_type_check_information(NULL);
  20717. +}
  20718. +
  20719. +void instanceKlass::do_fields_evolution(FieldEvolutionClosure* cl) {
  20720. +
  20721. + assert (old_version() != NULL, "must have old version!");
  20722. +
  20723. + klassOop old_klass_oop = old_version();
  20724. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  20725. + instanceKlass *new_klass = this;
  20726. +
  20727. + fieldDescriptor fd;
  20728. + fieldDescriptor old_fd;
  20729. +
  20730. + instanceKlass *cur_new_klass = new_klass;
  20731. + klassOop cur_new_klass_oop = this->as_klassOop();
  20732. +
  20733. + if (_fields_not_changed) {
  20734. +
  20735. + class MyFieldClosure : public FieldClosure {
  20736. +
  20737. + FieldEvolutionClosure *_cl;
  20738. + public:
  20739. + MyFieldClosure(FieldEvolutionClosure *cl) {_cl = cl; }
  20740. + virtual void do_field(fieldDescriptor* fd) {
  20741. + _cl->do_changed_field(fd, fd);
  20742. + }
  20743. + };
  20744. +
  20745. + MyFieldClosure mfc(cl);
  20746. + do_nonstatic_fields(&mfc);
  20747. + } else {
  20748. +
  20749. + _fields_not_changed = true;
  20750. +
  20751. +
  20752. + GrowableArray<fieldDescriptor> fds;
  20753. +
  20754. +
  20755. + while (true) {
  20756. +
  20757. + for (int i=0; i<cur_new_klass->fields()->length(); i+=instanceKlass::next_offset) {
  20758. +
  20759. + fd.initialize(cur_new_klass_oop, i);
  20760. +
  20761. + if (fd.is_static()) {
  20762. + continue;
  20763. + }
  20764. +
  20765. + fds.append(fd);
  20766. + }
  20767. +
  20768. + if (cur_new_klass->super() != NULL) {
  20769. + cur_new_klass_oop = cur_new_klass->super();
  20770. + cur_new_klass = instanceKlass::cast(cur_new_klass_oop);
  20771. + } else {
  20772. + break;
  20773. + }
  20774. + }
  20775. +
  20776. + GrowableArray<fieldDescriptor> sortedFds;
  20777. +
  20778. + while (fds.length() > 0) {
  20779. +
  20780. + int minOffset = 0x7fffffff;
  20781. + int minIndex = -1;
  20782. + for (int i=0; i<fds.length(); i++) {
  20783. + int curOffset = fds.adr_at(i)->offset();
  20784. + if (curOffset < minOffset) {
  20785. + minOffset = curOffset;
  20786. + minIndex = i;
  20787. + }
  20788. + }
  20789. +
  20790. + sortedFds.append(fds.at(minIndex));
  20791. + fds.remove_at(minIndex);
  20792. + }
  20793. +
  20794. +
  20795. + for (int i=0; i<sortedFds.length(); i++) {
  20796. +
  20797. + fieldDescriptor &fd = *sortedFds.adr_at(i);
  20798. +
  20799. + char found = 0;
  20800. + instanceKlass *cur_old_klass = old_klass;
  20801. + klassOop cur_old_klass_oop = old_klass_oop;
  20802. + while (true) {
  20803. + for (int j=0; j<cur_old_klass->fields()->length(); j+=instanceKlass::next_offset) {
  20804. +
  20805. + old_fd.initialize(cur_old_klass_oop, j);
  20806. +
  20807. + if (old_fd.is_static()) {
  20808. + continue;
  20809. + }
  20810. +
  20811. + if (old_fd.name() == fd.name() && old_fd.signature() == fd.signature()) {
  20812. + found = 1;
  20813. + break;
  20814. + }
  20815. + }
  20816. +
  20817. + if (!found && cur_old_klass->super()) {
  20818. + cur_old_klass_oop = cur_old_klass->super();
  20819. + cur_old_klass = instanceKlass::cast(cur_old_klass_oop);
  20820. + } else {
  20821. + break;
  20822. + }
  20823. + }
  20824. +
  20825. + if (found) {
  20826. + if (old_fd.offset() != fd.offset()) {
  20827. + _fields_not_changed = false;
  20828. + }
  20829. + cl->do_changed_field(&old_fd, &fd);
  20830. + } else {
  20831. + _fields_not_changed = false;
  20832. + cl->do_new_field(&fd);
  20833. + }
  20834. + }
  20835. + }
  20836. +}
  20837. +
  20838. void instanceKlass::do_local_static_fields(FieldClosure* cl) {
  20839. fieldDescriptor fd;
  20840. int length = fields()->length();
  20841. @@ -1229,6 +1517,20 @@
  20842. return id;
  20843. }
  20844. +bool instanceKlass::update_jmethod_id(methodOop method, jmethodID newMethodID) {
  20845. + size_t idnum = (size_t)method->method_idnum();
  20846. + jmethodID* jmeths = methods_jmethod_ids_acquire();
  20847. + size_t length; // length assigned as debugging crumb
  20848. + jmethodID id = NULL;
  20849. + if (jmeths != NULL && // If there is a cache
  20850. + (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
  20851. + jmeths[idnum+1] = newMethodID; // Set the id (may be NULL)
  20852. + return true;
  20853. + }
  20854. +
  20855. + return false;
  20856. +}
  20857. +
  20858. // Cache an itable index
  20859. void instanceKlass::set_cached_itable_index(size_t idnum, int index) {
  20860. @@ -1419,6 +1721,13 @@
  20861. last = b;
  20862. b = b->next();
  20863. }
  20864. +
  20865. + // (tw) Hack as dependencies get wrong version of klassOop
  20866. + if(this->old_version() != NULL) {
  20867. + ((instanceKlass *)this->old_version()->klass_part())->remove_dependent_nmethod(nm);
  20868. + return;
  20869. + }
  20870. +
  20871. #ifdef ASSERT
  20872. tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
  20873. nm->print();
  20874. @@ -2351,6 +2660,9 @@
  20875. klassOop mirrored_klass = java_lang_Class::as_klassOop(obj);
  20876. st->print(BULLET"fake entry for mirror: ");
  20877. mirrored_klass->print_value_on(st);
  20878. + if (mirrored_klass != NULL) {
  20879. + st->print_cr("revision: %d (oldest=%d, newest=%d)", mirrored_klass->klass_part()->revision_number(), mirrored_klass->klass_part()->oldest_version()->klass_part()->revision_number(), mirrored_klass->klass_part()->newest_version()->klass_part()->revision_number());
  20880. + }
  20881. st->cr();
  20882. st->print(BULLET"fake entry resolved_constructor: ");
  20883. methodOop ctor = java_lang_Class::resolved_constructor(obj);
  20884. @@ -2552,9 +2864,8 @@
  20885. GrowableArray<PreviousVersionNode *>(2, true);
  20886. }
  20887. - // RC_TRACE macro has an embedded ResourceMark
  20888. - RC_TRACE(0x00000100, ("adding previous version ref for %s @%d, EMCP_cnt=%d",
  20889. - ikh->external_name(), _previous_versions->length(), emcp_method_count));
  20890. + TRACE_RC3("adding previous version ref for %s @%d, EMCP_cnt=%d",
  20891. + ikh->external_name(), _previous_versions->length(), emcp_method_count);
  20892. constantPoolHandle cp_h(ikh->constants());
  20893. jobject cp_ref;
  20894. if (cp_h->is_shared()) {
  20895. @@ -2570,8 +2881,7 @@
  20896. if (emcp_method_count == 0) {
  20897. // non-shared ConstantPool gets a weak reference
  20898. pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), NULL);
  20899. - RC_TRACE(0x00000400,
  20900. - ("add: all methods are obsolete; flushing any EMCP weak refs"));
  20901. + TRACE_RC3("add: all methods are obsolete; flushing any EMCP weak refs");
  20902. } else {
  20903. int local_count = 0;
  20904. GrowableArray<jweak>* method_refs = new (ResourceObj::C_HEAP)
  20905. @@ -2600,8 +2910,7 @@
  20906. // caller is the VMThread and we are at a safepoint, this is a good
  20907. // time to clear out unused weak references.
  20908. - RC_TRACE(0x00000400, ("add: previous version length=%d",
  20909. - _previous_versions->length()));
  20910. + TRACE_RC3("add: previous version length=%d", _previous_versions->length());
  20911. // skip the last entry since we just added it
  20912. for (int i = _previous_versions->length() - 2; i >= 0; i--) {
  20913. @@ -2626,13 +2935,12 @@
  20914. // do anything special with the index.
  20915. continue;
  20916. } else {
  20917. - RC_TRACE(0x00000400, ("add: previous version @%d is alive", i));
  20918. + TRACE_RC3("add: previous version @%d is alive", i);
  20919. }
  20920. GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  20921. if (method_refs != NULL) {
  20922. - RC_TRACE(0x00000400, ("add: previous methods length=%d",
  20923. - method_refs->length()));
  20924. + TRACE_RC3("add: previous methods length=%d", method_refs->length());
  20925. for (int j = method_refs->length() - 1; j >= 0; j--) {
  20926. jweak method_ref = method_refs->at(j);
  20927. assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  20928. @@ -2651,11 +2959,8 @@
  20929. JNIHandles::destroy_weak_global(method_ref);
  20930. method_refs->remove_at(j);
  20931. } else {
  20932. - // RC_TRACE macro has an embedded ResourceMark
  20933. - RC_TRACE(0x00000400,
  20934. - ("add: %s(%s): previous method @%d in version @%d is alive",
  20935. - method->name()->as_C_string(), method->signature()->as_C_string(),
  20936. - j, i));
  20937. + TRACE_RC3("add: %s(%s): previous method @%d in version @%d is alive",
  20938. + method->name()->as_C_string(), method->signature()->as_C_string(), j, i);
  20939. }
  20940. }
  20941. }
  20942. @@ -2738,9 +3043,8 @@
  20943. // The current RedefineClasses() call has made all EMCP
  20944. // versions of this method obsolete so mark it as obsolete
  20945. // and remove the weak ref.
  20946. - RC_TRACE(0x00000400,
  20947. - ("add: %s(%s): flush obsolete method @%d in version @%d",
  20948. - m_name->as_C_string(), m_signature->as_C_string(), k, j));
  20949. + TRACE_RC3("add: %s(%s): flush obsolete method @%d in version @%d",
  20950. + m_name->as_C_string(), m_signature->as_C_string(), k, j);
  20951. method->set_is_obsolete();
  20952. JNIHandles::destroy_weak_global(method_ref);
  20953. diff -r f5603a6e5042 src/share/vm/oops/instanceKlass.hpp
  20954. --- a/src/share/vm/oops/instanceKlass.hpp Wed Nov 17 22:42:08 2010 -0800
  20955. +++ b/src/share/vm/oops/instanceKlass.hpp Fri Dec 17 13:23:04 2010 +0100
  20956. @@ -86,6 +86,22 @@
  20957. virtual void do_field(fieldDescriptor* fd) = 0;
  20958. };
  20959. +// (tw) Iterates over the fields of the old and new class
  20960. +class FieldEvolutionClosure : public StackObj {
  20961. +public:
  20962. + virtual void do_new_field(fieldDescriptor* fd) = 0;
  20963. + virtual void do_old_field(fieldDescriptor* fd) = 0;
  20964. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd) = 0;
  20965. +};
  20966. +
  20967. +// (tw) Iterates over the methods of the old and new class
  20968. +class MethodEvolutionClosure : public StackObj {
  20969. +public:
  20970. + virtual void do_new_method(methodOop oop) = 0;
  20971. + virtual void do_old_method(methodOop oop) = 0;
  20972. + virtual void do_changed_method(methodOop oldOop, methodOop newOop) = 0;
  20973. +};
  20974. +
  20975. #ifndef PRODUCT
  20976. // Print fields.
  20977. // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
  20978. @@ -244,6 +260,11 @@
  20979. JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map; // JVMTI: used during heap iteration
  20980. volatile u2 _idnum_allocated_count; // JNI/JVMTI: increments with the addition of methods, old ids don't change
  20981. + // (tw) Field that allows for a short-path when calculating updated fields for the second time and
  20982. + // no fields changed. Testing performance impact with this, can be removed later when the update
  20983. + // information is cached.
  20984. + bool _fields_not_changed;
  20985. +
  20986. // embedded Java vtable follows here
  20987. // embedded Java itables follows here
  20988. // embedded static fields follows here
  20989. @@ -374,6 +395,7 @@
  20990. // initialization (virtuals from Klass)
  20991. bool should_be_initialized() const; // means that initialize should be called
  20992. void initialize(TRAPS);
  20993. + void initialize_redefined_class();
  20994. void link_class(TRAPS);
  20995. bool link_class_or_fail(TRAPS); // returns false on failure
  20996. void unlink_class();
  20997. @@ -519,6 +541,7 @@
  20998. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  20999. size_t *length_p, jmethodID* id_p);
  21000. jmethodID jmethod_id_or_null(methodOop method);
  21001. + bool update_jmethod_id(methodOop method, jmethodID newMethodID);
  21002. // cached itable index support
  21003. void set_cached_itable_index(size_t idnum, int index);
  21004. @@ -600,6 +623,7 @@
  21005. // subclass/subinterface checks
  21006. bool implements_interface(klassOop k) const;
  21007. + bool implements_interface_any_version(klassOop k) const;
  21008. // Access to implementors of an interface. We only store the count
  21009. // of implementors, and in case, there are only a few
  21010. @@ -629,6 +653,12 @@
  21011. void do_local_static_fields(FieldClosure* cl);
  21012. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  21013. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  21014. + void do_fields_evolution(FieldEvolutionClosure *cl);
  21015. + void store_update_information(GrowableArray<int> &values);
  21016. + void clear_update_information();
  21017. + void store_type_check_information(GrowableArray< Pair<int, klassOop> > &values);
  21018. + void clear_type_check_information();
  21019. +
  21020. void methods_do(void f(methodOop method));
  21021. void array_klasses_do(void f(klassOop k));
  21022. diff -r f5603a6e5042 src/share/vm/oops/instanceKlassKlass.cpp
  21023. --- a/src/share/vm/oops/instanceKlassKlass.cpp Wed Nov 17 22:42:08 2010 -0800
  21024. +++ b/src/share/vm/oops/instanceKlassKlass.cpp Fri Dec 17 13:23:04 2010 +0100
  21025. @@ -487,6 +487,28 @@
  21026. instanceKlass* ik = instanceKlass::cast(klassOop(obj));
  21027. klassKlass::oop_print_on(obj, st);
  21028. + // (tw) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  21029. +
  21030. + st->print(BULLET"revision: %d", ik->revision_number());
  21031. +
  21032. + if (ik->new_version() != NULL) {
  21033. + st->print(" (newer=%d)", ik->new_version()->klass_part()->revision_number());
  21034. + }
  21035. +
  21036. + if (ik->newest_version() != ik->new_version() && ik->newest_version() != obj) {
  21037. + st->print(" (newest=%d)", ik->newest_version()->klass_part()->revision_number());
  21038. + }
  21039. +
  21040. + if (ik->old_version() != NULL) {
  21041. + st->print(" (old=%d)", ik->old_version()->klass_part()->revision_number());
  21042. + }
  21043. +
  21044. + if (ik->oldest_version() != ik->old_version() && ik->oldest_version() != obj) {
  21045. + st->print(" (oldest=%d)", ik->oldest_version()->klass_part()->revision_number());
  21046. + }
  21047. +
  21048. + st->cr();
  21049. +
  21050. st->print(BULLET"instance size: %d", ik->size_helper()); st->cr();
  21051. st->print(BULLET"klass size: %d", ik->object_size()); st->cr();
  21052. st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr();
  21053. @@ -685,7 +707,7 @@
  21054. }
  21055. guarantee(sib->as_klassOop()->is_klass(), "should be klass");
  21056. guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
  21057. - guarantee(sib->super() == super, "siblings should have same superklass");
  21058. + guarantee(sib->super() == super || super->klass_part()->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  21059. sib = sib->next_sibling();
  21060. }
  21061. diff -r f5603a6e5042 src/share/vm/oops/instanceRefKlass.cpp
  21062. --- a/src/share/vm/oops/instanceRefKlass.cpp Wed Nov 17 22:42:08 2010 -0800
  21063. +++ b/src/share/vm/oops/instanceRefKlass.cpp Fri Dec 17 13:23:04 2010 +0100
  21064. @@ -363,10 +363,13 @@
  21065. instanceKlass* ik = instanceKlass::cast(k);
  21066. // Check that we have the right class
  21067. - debug_only(static bool first_time = true);
  21068. - assert(k == SystemDictionary::Reference_klass() && first_time,
  21069. - "Invalid update of maps");
  21070. - debug_only(first_time = false);
  21071. +
  21072. + // (tw) Asserts no longer valid for class redefinition
  21073. + // debug_only(static bool first_time = true);
  21074. +
  21075. + //assert(k == SystemDictionary::Reference_klass() && first_time,
  21076. + // "Invalid update of maps");
  21077. + //debug_only(first_time = false);
  21078. assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  21079. OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  21080. diff -r f5603a6e5042 src/share/vm/oops/klass.cpp
  21081. --- a/src/share/vm/oops/klass.cpp Wed Nov 17 22:42:08 2010 -0800
  21082. +++ b/src/share/vm/oops/klass.cpp Fri Dec 17 13:23:04 2010 +0100
  21083. @@ -40,6 +40,26 @@
  21084. return false;
  21085. }
  21086. +void Klass::update_supers_to_newest_version() {
  21087. +
  21088. + if (super() != NULL) set_super(super()->klass_part()->newest_version());
  21089. +
  21090. + for (uint i=0; i<primary_super_limit(); i++) {
  21091. + klassOop cur = _primary_supers[i];
  21092. + if (cur != NULL) {
  21093. + _primary_supers[i] = cur->klass_part()->newest_version();
  21094. + }
  21095. + }
  21096. +
  21097. + // Scan the array-of-objects
  21098. + int cnt = secondary_supers()->length();
  21099. + for (int i = 0; i < cnt; i++) {
  21100. + klassOop cur = (klassOop)secondary_supers()->obj_at(i);
  21101. + if (cur != NULL) {
  21102. + secondary_supers()->obj_at_put(i, cur->klass_part()->newest_version());
  21103. + }
  21104. + }
  21105. +}
  21106. bool Klass::search_secondary_supers(klassOop k) const {
  21107. // Put some extra logic here out-of-line, before the search proper.
  21108. // This cuts down the size of the inline method.
  21109. @@ -145,6 +165,16 @@
  21110. kl->set_alloc_count(0);
  21111. kl->set_alloc_size(0);
  21112. + kl->set_redefinition_flags(Klass::NoRedefinition);
  21113. + kl->set_redefining(false);
  21114. + kl->set_new_version(NULL);
  21115. + kl->set_old_version(NULL);
  21116. + kl->set_redefinition_index(-1);
  21117. + kl->set_revision_number(-1);
  21118. + kl->set_field_redefinition_policy(DynamicCheck);
  21119. + kl->set_static_field_redefinition_policy(AccessDeletedMembers);
  21120. + kl->set_method_redefinition_policy(AccessDeletedMembers);
  21121. +
  21122. kl->set_prototype_header(markOopDesc::prototype());
  21123. kl->set_biased_lock_revocation_count(0);
  21124. kl->set_last_biased_lock_bulk_revocation_time(0);
  21125. @@ -217,7 +247,7 @@
  21126. set_super(NULL);
  21127. oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
  21128. assert(super_depth() == 0, "Object must already be initialized properly");
  21129. - } else if (k != super() || k == SystemDictionary::Object_klass()) {
  21130. + } else if (k != super() || k->klass_part()->super() == NULL) {
  21131. assert(super() == NULL || super() == SystemDictionary::Object_klass(),
  21132. "initialize this only once to a non-trivial value");
  21133. set_super(k);
  21134. diff -r f5603a6e5042 src/share/vm/oops/klass.hpp
  21135. --- a/src/share/vm/oops/klass.hpp Wed Nov 17 22:42:08 2010 -0800
  21136. +++ b/src/share/vm/oops/klass.hpp Fri Dec 17 13:23:04 2010 +0100
  21137. @@ -150,6 +150,7 @@
  21138. void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
  21139. };
  21140. +template<class L, class R> class Pair;
  21141. class Klass : public Klass_vtbl {
  21142. friend class VMStructs;
  21143. @@ -198,6 +199,39 @@
  21144. oop* oop_block_beg() const { return adr_secondary_super_cache(); }
  21145. oop* oop_block_end() const { return adr_next_sibling() + 1; }
  21146. + // (tw) Different class redefinition flags of code evolution.
  21147. + enum RedefinitionFlags {
  21148. +
  21149. + // This class is not redefined at all!
  21150. + NoRedefinition,
  21151. +
  21152. + // There are changes to the class meta data.
  21153. + ModifyClass = 1,
  21154. +
  21155. + // The size of the class meta data changes.
  21156. + ModifyClassSize = ModifyClass << 1,
  21157. +
  21158. + // There are change to the instance format.
  21159. + ModifyInstances = ModifyClassSize << 1,
  21160. +
  21161. + // The size of instances changes.
  21162. + ModifyInstanceSize = ModifyInstances << 1,
  21163. +
  21164. + // A super type of this class is removed.
  21165. + RemoveSuperType = ModifyInstanceSize << 1,
  21166. +
  21167. + // This class (or one of its super classes) has an instance transformer method.
  21168. + HasInstanceTransformer = RemoveSuperType << 1,
  21169. + };
  21170. +
  21171. + // (tw) Different policies dealing with deleted fields / methods in old code.
  21172. + enum RedefinitionPolicy {
  21173. + StaticCheck,
  21174. + DynamicCheck,
  21175. + AccessDeletedMembers,
  21176. + AccessOldMembers
  21177. + };
  21178. +
  21179. protected:
  21180. //
  21181. // The oop block. All oop fields must be declared here and only oop fields
  21182. @@ -217,6 +251,10 @@
  21183. oop _java_mirror;
  21184. // Superclass
  21185. klassOop _super;
  21186. + // Old class
  21187. + klassOop _old_version;
  21188. + // New class
  21189. + klassOop _new_version;
  21190. // Class name. Instance classes: java/lang/String, etc. Array classes: [I,
  21191. // [Ljava/lang/String;, etc. Set to zero for all other kinds of classes.
  21192. symbolOop _name;
  21193. @@ -232,6 +270,19 @@
  21194. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  21195. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  21196. + // (tw) Non-oop fields for enhanced class redefinition
  21197. + jint _revision_number; // The revision number for redefined classes
  21198. + jint _redefinition_index; // Index of this class when performing the redefinition
  21199. + bool _subtype_changed;
  21200. + int _redefinition_flags; // Level of class redefinition
  21201. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  21202. + int * _update_information; // Update information
  21203. + Pair<int, klassOop> * _type_check_information; // Offsets of object fields that need a type check
  21204. + char _method_redefinition_policy;
  21205. + char _field_redefinition_policy;
  21206. + char _static_field_redefinition_policy;
  21207. + bool _is_redefining;
  21208. +
  21209. #ifndef PRODUCT
  21210. int _verify_count; // to avoid redundant verifies
  21211. #endif
  21212. @@ -279,6 +330,99 @@
  21213. klassOop secondary_super_cache() const { return _secondary_super_cache; }
  21214. void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
  21215. + // BEGIN class redefinition utilities
  21216. +
  21217. + // double links between new and old version of a class
  21218. + klassOop old_version() const { return _old_version; }
  21219. + void set_old_version(klassOop klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  21220. + klassOop new_version() const { return _new_version; }
  21221. + void set_new_version(klassOop klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  21222. +
  21223. + // A subtype of this class is no longer a subtype
  21224. + bool has_subtype_changed() const { return _subtype_changed; }
  21225. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->klass_part()->is_newest_version(), "must be newest or second newest version");
  21226. + _subtype_changed = b; }
  21227. + // state of being redefined
  21228. + int redefinition_index() const { return _redefinition_index; }
  21229. + void set_redefinition_index(int index) { _redefinition_index = index; }
  21230. + void set_redefining(bool b) { _is_redefining = b; }
  21231. + bool is_redefining() const { return _is_redefining; }
  21232. + int redefinition_flags() const { return _redefinition_flags; }
  21233. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  21234. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  21235. + bool is_copying_backwards() const { return _is_copying_backwards; }
  21236. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  21237. +
  21238. + // update information
  21239. + int *update_information() const { return _update_information; }
  21240. + void set_update_information(int *info) { _update_information = info; }
  21241. + Pair<int, klassOop> *type_check_information() const { return _type_check_information; }
  21242. + void set_type_check_information(Pair<int, klassOop> *info) { _type_check_information = info; }
  21243. +
  21244. + bool is_same_or_older_version(klassOop klass) const {
  21245. + if (Klass::cast(klass) == this) { return true; }
  21246. + else if (_old_version == NULL) { return false; }
  21247. + else { return _old_version->klass_part()->is_same_or_older_version(klass); }
  21248. + }
  21249. +
  21250. + // Revision number for redefined classes, -1 for originally loaded classes
  21251. + jint revision_number() const {
  21252. + return _revision_number;
  21253. + }
  21254. +
  21255. + bool was_redefined() const {
  21256. + return _revision_number != -1;
  21257. + }
  21258. +
  21259. + void set_revision_number(jint number) {
  21260. + _revision_number = number;
  21261. + }
  21262. +
  21263. + char method_redefinition_policy() {
  21264. + return _method_redefinition_policy;
  21265. + }
  21266. +
  21267. + void set_method_redefinition_policy(char v) {
  21268. + _method_redefinition_policy = v;
  21269. + }
  21270. +
  21271. + char field_redefinition_policy() {
  21272. + return _field_redefinition_policy;
  21273. + }
  21274. +
  21275. + void set_field_redefinition_policy(char v) {
  21276. + _field_redefinition_policy = v;
  21277. + }
  21278. +
  21279. + char static_field_redefinition_policy() {
  21280. + return _static_field_redefinition_policy;
  21281. + }
  21282. +
  21283. + void set_static_field_redefinition_policy(char v) {
  21284. + _static_field_redefinition_policy = v;
  21285. + }
  21286. +
  21287. + klassOop oldest_version() const {
  21288. + if (_old_version == NULL) { return this->as_klassOop(); }
  21289. + else { return _old_version->klass_part()->oldest_version(); };
  21290. + }
  21291. +
  21292. + klassOop newest_version() const {
  21293. + if (_new_version == NULL) { return this->as_klassOop(); }
  21294. + else { return _new_version->klass_part()->newest_version(); };
  21295. + }
  21296. +
  21297. + klassOop active_version() const {
  21298. + if (_new_version == NULL || _new_version->klass_part()->is_redefining()) { return this->as_klassOop(); assert(!this->is_redefining(), "just checking"); }
  21299. + else { return _new_version->klass_part()->active_version(); };
  21300. + }
  21301. +
  21302. + bool is_newest_version() const {
  21303. + return _new_version == NULL;
  21304. + }
  21305. +
  21306. + // END class redefinition utilities
  21307. +
  21308. objArrayOop secondary_supers() const { return _secondary_supers; }
  21309. void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
  21310. @@ -339,6 +483,8 @@
  21311. void set_next_sibling(klassOop s);
  21312. oop* adr_super() const { return (oop*)&_super; }
  21313. + oop* adr_old_version() const { return (oop*)&_old_version; }
  21314. + oop* adr_new_version() const { return (oop*)&_new_version; }
  21315. oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
  21316. oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
  21317. oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
  21318. @@ -469,6 +615,7 @@
  21319. return search_secondary_supers(k);
  21320. }
  21321. }
  21322. + void update_supers_to_newest_version();
  21323. bool search_secondary_supers(klassOop k) const;
  21324. // Find LCA in class hierarchy
  21325. diff -r f5603a6e5042 src/share/vm/oops/klassKlass.cpp
  21326. --- a/src/share/vm/oops/klassKlass.cpp Wed Nov 17 22:42:08 2010 -0800
  21327. +++ b/src/share/vm/oops/klassKlass.cpp Fri Dec 17 13:23:04 2010 +0100
  21328. @@ -45,6 +45,8 @@
  21329. Klass* k = Klass::cast(klassOop(obj));
  21330. // If we are alive it is valid to keep our superclass and subtype caches alive
  21331. MarkSweep::mark_and_push(k->adr_super());
  21332. + MarkSweep::mark_and_push(k->adr_old_version());
  21333. + MarkSweep::mark_and_push(k->adr_new_version());
  21334. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  21335. MarkSweep::mark_and_push(k->adr_primary_supers()+i);
  21336. MarkSweep::mark_and_push(k->adr_secondary_super_cache());
  21337. @@ -65,6 +67,8 @@
  21338. Klass* k = Klass::cast(klassOop(obj));
  21339. // If we are alive it is valid to keep our superclass and subtype caches alive
  21340. PSParallelCompact::mark_and_push(cm, k->adr_super());
  21341. + PSParallelCompact::mark_and_push(cm, k->adr_old_version());
  21342. + PSParallelCompact::mark_and_push(cm, k->adr_new_version());
  21343. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  21344. PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
  21345. PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
  21346. @@ -85,6 +89,8 @@
  21347. int size = oop_size(obj);
  21348. Klass* k = Klass::cast(klassOop(obj));
  21349. blk->do_oop(k->adr_super());
  21350. + blk->do_oop(k->adr_old_version());
  21351. + blk->do_oop(k->adr_new_version());
  21352. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  21353. blk->do_oop(k->adr_primary_supers()+i);
  21354. blk->do_oop(k->adr_secondary_super_cache());
  21355. @@ -114,6 +120,10 @@
  21356. oop* adr;
  21357. adr = k->adr_super();
  21358. if (mr.contains(adr)) blk->do_oop(adr);
  21359. + adr = k->adr_old_version();
  21360. + if (mr.contains(adr)) blk->do_oop(adr);
  21361. + adr = k->adr_new_version();
  21362. + if (mr.contains(adr)) blk->do_oop(adr);
  21363. for (juint i = 0; i < Klass::primary_super_limit(); i++) {
  21364. adr = k->adr_primary_supers()+i;
  21365. if (mr.contains(adr)) blk->do_oop(adr);
  21366. @@ -149,6 +159,8 @@
  21367. Klass* k = Klass::cast(klassOop(obj));
  21368. MarkSweep::adjust_pointer(k->adr_super());
  21369. + MarkSweep::adjust_pointer(k->adr_new_version());
  21370. + MarkSweep::adjust_pointer(k->adr_old_version());
  21371. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  21372. MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
  21373. MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
  21374. diff -r f5603a6e5042 src/share/vm/oops/klassVtable.cpp
  21375. --- a/src/share/vm/oops/klassVtable.cpp Wed Nov 17 22:42:08 2010 -0800
  21376. +++ b/src/share/vm/oops/klassVtable.cpp Fri Dec 17 13:23:04 2010 +0100
  21377. @@ -82,7 +82,8 @@
  21378. vtable_length = Universe::base_vtable_size();
  21379. }
  21380. - if (super == NULL && !Universe::is_bootstrapping() &&
  21381. + // (tw) TODO: Check if we can relax the condition on a fixed base vtable size
  21382. + /*if (super == NULL && !Universe::is_bootstrapping() &&
  21383. vtable_length != Universe::base_vtable_size()) {
  21384. // Someone is attempting to redefine java.lang.Object incorrectly. The
  21385. // only way this should happen is from
  21386. @@ -92,9 +93,9 @@
  21387. vtable_length = Universe::base_vtable_size();
  21388. }
  21389. assert(super != NULL || vtable_length == Universe::base_vtable_size(),
  21390. - "bad vtable size for class Object");
  21391. + "bad vtable size for class Object");*/
  21392. assert(vtable_length % vtableEntry::size() == 0, "bad vtable length");
  21393. - assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  21394. + //assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  21395. }
  21396. int klassVtable::index_of(methodOop m, int len) const {
  21397. @@ -611,17 +612,13 @@
  21398. if (unchecked_method_at(index) == old_method) {
  21399. put_method_at(new_method, index);
  21400. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  21401. + IF_TRACE_RC4 {
  21402. if (!(*trace_name_printed)) {
  21403. - // RC_TRACE_MESG macro has an embedded ResourceMark
  21404. - RC_TRACE_MESG(("adjust: name=%s",
  21405. - Klass::cast(old_method->method_holder())->external_name()));
  21406. + TRACE_RC4("adjust: name=%s", Klass::cast(old_method->method_holder())->external_name());
  21407. *trace_name_printed = true;
  21408. }
  21409. - // RC_TRACE macro has an embedded ResourceMark
  21410. - RC_TRACE(0x00100000, ("vtable method update: %s(%s)",
  21411. - new_method->name()->as_C_string(),
  21412. - new_method->signature()->as_C_string()));
  21413. + TRACE_RC4("vtable method update: %s(%s)", new_method->name()->as_C_string(),
  21414. + new_method->signature()->as_C_string());
  21415. }
  21416. }
  21417. }
  21418. @@ -994,17 +991,13 @@
  21419. if (ime->method() == old_method) {
  21420. ime->initialize(new_method);
  21421. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  21422. + IF_TRACE_RC4 {
  21423. if (!(*trace_name_printed)) {
  21424. - // RC_TRACE_MESG macro has an embedded ResourceMark
  21425. - RC_TRACE_MESG(("adjust: name=%s",
  21426. - Klass::cast(old_method->method_holder())->external_name()));
  21427. + TRACE_RC4("adjust: name=%s", Klass::cast(old_method->method_holder())->external_name());
  21428. *trace_name_printed = true;
  21429. }
  21430. - // RC_TRACE macro has an embedded ResourceMark
  21431. - RC_TRACE(0x00200000, ("itable method update: %s(%s)",
  21432. - new_method->name()->as_C_string(),
  21433. - new_method->signature()->as_C_string()));
  21434. + TRACE_RC4("itable method update: %s(%s)", new_method->name()->as_C_string(),
  21435. + new_method->signature()->as_C_string());
  21436. }
  21437. break;
  21438. }
  21439. @@ -1198,6 +1191,7 @@
  21440. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  21441. vtableEntry* vte = &vt->table()[index];
  21442. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  21443. if (vte->method()->name() != table()[index].method()->name() ||
  21444. vte->method()->signature() != table()[index].method()->signature()) {
  21445. fatal("mismatched name/signature of vtable entries");
  21446. @@ -1217,6 +1211,8 @@
  21447. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  21448. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  21449. + // (tw) TODO: Check: Does not hold?
  21450. + if (method() != NULL) {
  21451. assert(method() != NULL, "must have set method");
  21452. method()->verify();
  21453. // we sub_type, because it could be a miranda method
  21454. @@ -1224,7 +1220,13 @@
  21455. #ifndef PRODUCT
  21456. print();
  21457. #endif
  21458. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  21459. + klassOop first_klass = vt->klass()();
  21460. + klassOop second_klass = method()->method_holder();
  21461. + // (tw) the following fatal does not work for old versions of classes
  21462. + if (first_klass->klass_part()->is_newest_version()) {
  21463. + //fatal1("vtableEntry %#lx: method is from subclass", this);
  21464. + }
  21465. + }
  21466. }
  21467. }
  21468. @@ -1232,7 +1234,7 @@
  21469. void vtableEntry::print() {
  21470. ResourceMark rm;
  21471. - tty->print("vtableEntry %s: ", method()->name()->as_C_string());
  21472. + tty->print("vtableEntry %s: ", (method() == NULL) ? "null" : method()->name()->as_C_string());
  21473. if (Verbose) {
  21474. tty->print("m %#lx ", (address)method());
  21475. }
  21476. @@ -1304,7 +1306,7 @@
  21477. for (int i = 0; i < length(); i++) {
  21478. methodOop m = unchecked_method_at(i);
  21479. if (m != NULL) {
  21480. - if (m->is_old()) {
  21481. + if (m->is_old() || !m->method_holder()->klass_part()->is_newest_version()) {
  21482. return false;
  21483. }
  21484. }
  21485. diff -r f5603a6e5042 src/share/vm/oops/methodKlass.cpp
  21486. --- a/src/share/vm/oops/methodKlass.cpp Wed Nov 17 22:42:08 2010 -0800
  21487. +++ b/src/share/vm/oops/methodKlass.cpp Fri Dec 17 13:23:04 2010 +0100
  21488. @@ -78,6 +78,10 @@
  21489. m->set_adapter_entry(NULL);
  21490. m->clear_code(); // from_c/from_i get set to c2i/i2i
  21491. + m->set_forward_method(NULL);
  21492. + m->set_new_version(NULL);
  21493. + m->set_old_version(NULL);
  21494. +
  21495. if (access_flags.is_native()) {
  21496. m->clear_native_function();
  21497. m->set_signature_handler(NULL);
  21498. @@ -106,6 +110,9 @@
  21499. // Performance tweak: We skip iterating over the klass pointer since we
  21500. // know that Universe::methodKlassObj never moves.
  21501. MarkSweep::mark_and_push(m->adr_constMethod());
  21502. + MarkSweep::mark_and_push(m->adr_forward_method());
  21503. + MarkSweep::mark_and_push(m->adr_new_version());
  21504. + MarkSweep::mark_and_push(m->adr_old_version());
  21505. MarkSweep::mark_and_push(m->adr_constants());
  21506. if (m->method_data() != NULL) {
  21507. MarkSweep::mark_and_push(m->adr_method_data());
  21508. @@ -120,6 +127,9 @@
  21509. // Performance tweak: We skip iterating over the klass pointer since we
  21510. // know that Universe::methodKlassObj never moves.
  21511. PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
  21512. + PSParallelCompact::mark_and_push(cm, m->adr_forward_method());
  21513. + PSParallelCompact::mark_and_push(cm, m->adr_new_version());
  21514. + PSParallelCompact::mark_and_push(cm, m->adr_old_version());
  21515. PSParallelCompact::mark_and_push(cm, m->adr_constants());
  21516. #ifdef COMPILER2
  21517. if (m->method_data() != NULL) {
  21518. @@ -138,6 +148,9 @@
  21519. // Performance tweak: We skip iterating over the klass pointer since we
  21520. // know that Universe::methodKlassObj never moves
  21521. blk->do_oop(m->adr_constMethod());
  21522. + blk->do_oop(m->adr_forward_method());
  21523. + blk->do_oop(m->adr_new_version());
  21524. + blk->do_oop(m->adr_old_version());
  21525. blk->do_oop(m->adr_constants());
  21526. if (m->method_data() != NULL) {
  21527. blk->do_oop(m->adr_method_data());
  21528. @@ -157,6 +170,12 @@
  21529. oop* adr;
  21530. adr = m->adr_constMethod();
  21531. if (mr.contains(adr)) blk->do_oop(adr);
  21532. + adr = m->adr_new_version();
  21533. + if (mr.contains(adr)) blk->do_oop(adr);
  21534. + adr = m->adr_forward_method();
  21535. + if (mr.contains(adr)) blk->do_oop(adr);
  21536. + adr = m->adr_old_version();
  21537. + if (mr.contains(adr)) blk->do_oop(adr);
  21538. adr = m->adr_constants();
  21539. if (mr.contains(adr)) blk->do_oop(adr);
  21540. if (m->method_data() != NULL) {
  21541. @@ -176,6 +195,9 @@
  21542. // Performance tweak: We skip iterating over the klass pointer since we
  21543. // know that Universe::methodKlassObj never moves.
  21544. MarkSweep::adjust_pointer(m->adr_constMethod());
  21545. + MarkSweep::adjust_pointer(m->adr_forward_method());
  21546. + MarkSweep::adjust_pointer(m->adr_new_version());
  21547. + MarkSweep::adjust_pointer(m->adr_old_version());
  21548. MarkSweep::adjust_pointer(m->adr_constants());
  21549. if (m->method_data() != NULL) {
  21550. MarkSweep::adjust_pointer(m->adr_method_data());
  21551. @@ -192,6 +214,8 @@
  21552. assert(obj->is_method(), "should be method");
  21553. methodOop m = methodOop(obj);
  21554. PSParallelCompact::adjust_pointer(m->adr_constMethod());
  21555. + PSParallelCompact::adjust_pointer(m->adr_new_version());
  21556. + PSParallelCompact::adjust_pointer(m->adr_old_version());
  21557. PSParallelCompact::adjust_pointer(m->adr_constants());
  21558. #ifdef COMPILER2
  21559. if (m->method_data() != NULL) {
  21560. @@ -210,6 +234,12 @@
  21561. p = m->adr_constMethod();
  21562. PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
  21563. + p = m->adr_forward_method();
  21564. + PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
  21565. + p = m->adr_new_version();
  21566. + PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
  21567. + p = m->adr_old_version();
  21568. + PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
  21569. p = m->adr_constants();
  21570. PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
  21571. @@ -234,7 +264,18 @@
  21572. methodOop m = methodOop(obj);
  21573. // get the effect of PrintOopAddress, always, for methods:
  21574. st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
  21575. - st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
  21576. + st->print (" - method holder: "); m->method_holder()->print_value_on(st);
  21577. +
  21578. + if (m->method_holder()->klass_part()->new_version() != NULL) {
  21579. + st->print(" (old)");
  21580. + }
  21581. + st->cr();
  21582. +
  21583. + st->print_cr(" - is obsolete: %d", (int)(m->is_obsolete()));
  21584. + st->print_cr(" - is old: %d", (int)(m->is_old()));
  21585. + st->print_cr(" - new version: %d", (int)(m->new_version()));
  21586. + st->print_cr(" - old version: %d", (int)(m->old_version()));
  21587. + st->print_cr(" - holder revision: %d", m->method_holder()->klass_part()->revision_number());
  21588. st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
  21589. m->constants()->print_value_on(st); st->cr();
  21590. st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
  21591. diff -r f5603a6e5042 src/share/vm/oops/methodOop.cpp
  21592. --- a/src/share/vm/oops/methodOop.cpp Wed Nov 17 22:42:08 2010 -0800
  21593. +++ b/src/share/vm/oops/methodOop.cpp Fri Dec 17 13:23:04 2010 +0100
  21594. @@ -305,6 +305,70 @@
  21595. }
  21596. +bool methodOopDesc::is_in_code_section(int bci) {
  21597. + // There is no table => every bci is in the code section table.
  21598. + if (!constMethod()->has_code_section_table()) return true;
  21599. +
  21600. + constMethodOop m = constMethod();
  21601. + for (int i = 0; i < m->code_section_entries(); ++i) {
  21602. + u2 new_index = m->code_section_new_index_at(i);
  21603. + u2 length = m->code_section_length_at(i);
  21604. + if (bci >= new_index && bci < new_index + length) {
  21605. + // We are in a specified code section.
  21606. + return true;
  21607. + }
  21608. + }
  21609. +
  21610. + return false;
  21611. +}
  21612. +
  21613. +int methodOopDesc::calculate_forward_bci(int bci, methodOop new_method) {
  21614. + int original_bci = -1;
  21615. + if (constMethod()->has_code_section_table()) {
  21616. + assert(is_in_code_section(bci), "can only forward in section");
  21617. + // First calculate back to original bci.
  21618. + constMethodOop m = constMethod();
  21619. + for (int i = 0; i < m->code_section_entries(); ++i) {
  21620. + u2 new_index = m->code_section_new_index_at(i);
  21621. + u2 original_index = m->code_section_original_index_at(i);
  21622. + u2 length = m->code_section_length_at(i);
  21623. + if (bci >= new_index && bci < new_index + length) {
  21624. + // We are in a specified code section.
  21625. + original_bci = bci - new_index + original_index;
  21626. + break;
  21627. + }
  21628. + }
  21629. + assert (original_bci != -1, "must have been in code section");
  21630. + } else {
  21631. + // No code sections specified => we are in an original method.
  21632. + original_bci = bci;
  21633. + }
  21634. +
  21635. + // We know the original bci => match to new method.
  21636. + int new_bci = -1;
  21637. + if (new_method->constMethod()->has_code_section_table()) {
  21638. + // Map to new bci.
  21639. + constMethodOop m = new_method->constMethod();
  21640. + for (int i = 0; i < m->code_section_entries(); ++i) {
  21641. + u2 new_index = m->code_section_new_index_at(i);
  21642. + u2 original_index = m->code_section_original_index_at(i);
  21643. + u2 length = m->code_section_length_at(i);
  21644. + if (original_bci >= original_index && original_bci < original_index + length) {
  21645. + new_bci = original_bci - original_index + new_index;
  21646. + break;
  21647. + }
  21648. + }
  21649. + assert (new_bci != -1, "must have found new code section");
  21650. +
  21651. + } else {
  21652. + // We are in an original method.
  21653. + new_bci = original_bci;
  21654. + }
  21655. +
  21656. + return new_bci;
  21657. +}
  21658. +
  21659. +
  21660. int methodOopDesc::extra_stack_words() {
  21661. // not an inline function, to avoid a header dependency on Interpreter
  21662. return extra_stack_entries() * Interpreter::stackElementSize;
  21663. @@ -986,6 +1050,9 @@
  21664. // Reset correct method/const method, method size, and parameter info
  21665. newcm->set_method(newm());
  21666. newm->set_constMethod(newcm);
  21667. + newm->set_forward_method(newm->forward_method());
  21668. + newm->set_new_version(newm->new_version());
  21669. + newm->set_old_version(newm->old_version());
  21670. assert(newcm->method() == newm(), "check");
  21671. newm->constMethod()->set_code_size(new_code_length);
  21672. newm->constMethod()->set_constMethod_size(new_const_method_size);
  21673. diff -r f5603a6e5042 src/share/vm/oops/methodOop.hpp
  21674. --- a/src/share/vm/oops/methodOop.hpp Wed Nov 17 22:42:08 2010 -0800
  21675. +++ b/src/share/vm/oops/methodOop.hpp Fri Dec 17 13:23:04 2010 +0100
  21676. @@ -96,6 +96,11 @@
  21677. AccessFlags _access_flags; // Access flags
  21678. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  21679. // note: can have vtables with >2**16 elements (because of inheritance)
  21680. + // (tw) Newer version of method available?
  21681. + methodOop _forward_method;
  21682. + methodOop _new_version;
  21683. + methodOop _old_version;
  21684. +
  21685. #ifdef CC_INTERP
  21686. int _result_index; // C++ interpreter needs for converting results to/from stack
  21687. #endif
  21688. @@ -150,6 +155,32 @@
  21689. int name_index() const { return constMethod()->name_index(); }
  21690. void set_name_index(int index) { constMethod()->set_name_index(index); }
  21691. + methodOop forward_method() const {return _forward_method; }
  21692. + void set_forward_method(methodOop m) { _forward_method = m; }
  21693. + bool has_forward_method() const { return forward_method() != NULL; }
  21694. + methodOop new_version() const {return _new_version; }
  21695. + void set_new_version(methodOop m) { _new_version = m; }
  21696. + methodOop newest_version() { if(_new_version == NULL) return this; else return new_version()->newest_version(); }
  21697. +
  21698. + methodOop old_version() const {return _old_version; };
  21699. + void set_old_version(methodOop m) {
  21700. + if (m == NULL) {
  21701. + _old_version = NULL;
  21702. + return;
  21703. + }
  21704. +
  21705. + assert(_old_version == NULL, "may only be set once");
  21706. + assert(this->code_size() == m->code_size(), "must have same code length");
  21707. + _old_version = m;
  21708. + }
  21709. +
  21710. + methodOop oldest_version() const {
  21711. + if(_old_version == NULL) return (methodOop)this;
  21712. + else {
  21713. + return old_version()->oldest_version();
  21714. + }
  21715. + }
  21716. +
  21717. // signature
  21718. symbolOop signature() const { return _constants->symbol_at(signature_index()); }
  21719. int signature_index() const { return constMethod()->signature_index(); }
  21720. @@ -614,6 +645,10 @@
  21721. // Inline cache support
  21722. void cleanup_inline_caches();
  21723. + // (tw) Method forwarding support.
  21724. + bool is_in_code_section(int bci);
  21725. + int calculate_forward_bci(int bci, methodOop new_method);
  21726. +
  21727. // Find if klass for method is loaded
  21728. bool is_klass_loaded_by_klass_index(int klass_index) const;
  21729. bool is_klass_loaded(int refinfo_index, bool must_be_resolved = false) const;
  21730. @@ -669,6 +704,9 @@
  21731. // Garbage collection support
  21732. oop* adr_constMethod() const { return (oop*)&_constMethod; }
  21733. + oop* adr_forward_method() const { return (oop*)&_forward_method; }
  21734. + oop* adr_new_version() const { return (oop*)&_new_version; }
  21735. + oop* adr_old_version() const { return (oop*)&_old_version; }
  21736. oop* adr_constants() const { return (oop*)&_constants; }
  21737. oop* adr_method_data() const { return (oop*)&_method_data; }
  21738. };
  21739. diff -r f5603a6e5042 src/share/vm/oops/oop.hpp
  21740. --- a/src/share/vm/oops/oop.hpp Wed Nov 17 22:42:08 2010 -0800
  21741. +++ b/src/share/vm/oops/oop.hpp Fri Dec 17 13:23:04 2010 +0100
  21742. @@ -81,6 +81,7 @@
  21743. narrowOop* compressed_klass_addr();
  21744. void set_klass(klassOop k);
  21745. + void set_klass_no_check(klassOop k);
  21746. // For klass field compression
  21747. int klass_gap() const;
  21748. @@ -121,6 +122,7 @@
  21749. bool is_objArray() const;
  21750. bool is_symbol() const;
  21751. bool is_klass() const;
  21752. + bool is_instanceKlass() const;
  21753. bool is_thread() const;
  21754. bool is_method() const;
  21755. bool is_constMethod() const;
  21756. diff -r f5603a6e5042 src/share/vm/oops/oop.inline.hpp
  21757. --- a/src/share/vm/oops/oop.inline.hpp Wed Nov 17 22:42:08 2010 -0800
  21758. +++ b/src/share/vm/oops/oop.inline.hpp Fri Dec 17 13:23:04 2010 +0100
  21759. @@ -78,6 +78,14 @@
  21760. }
  21761. }
  21762. +inline void oopDesc::set_klass_no_check(klassOop k) {
  21763. + if (UseCompressedOops) {
  21764. + oop_store_without_check(compressed_klass_addr(), (oop)k);
  21765. + } else {
  21766. + oop_store_without_check(klass_addr(), (oop) k);
  21767. + }
  21768. +}
  21769. +
  21770. inline int oopDesc::klass_gap() const {
  21771. return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  21772. }
  21773. @@ -111,6 +119,7 @@
  21774. inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
  21775. inline bool oopDesc::is_symbol() const { return blueprint()->oop_is_symbol(); }
  21776. inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
  21777. +inline bool oopDesc::is_instanceKlass() const { return blueprint()->oop_is_instanceKlass(); }
  21778. inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
  21779. inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
  21780. inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
  21781. diff -r f5603a6e5042 src/share/vm/prims/jni.cpp
  21782. --- a/src/share/vm/prims/jni.cpp Wed Nov 17 22:42:08 2010 -0800
  21783. +++ b/src/share/vm/prims/jni.cpp Fri Dec 17 13:23:04 2010 +0100
  21784. @@ -299,7 +299,7 @@
  21785. }
  21786. }
  21787. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  21788. - Handle(), &st, true,
  21789. + Handle(), &st, true, KlassHandle(),
  21790. CHECK_NULL);
  21791. if (TraceClassResolution && k != NULL) {
  21792. diff -r f5603a6e5042 src/share/vm/prims/jvm.cpp
  21793. --- a/src/share/vm/prims/jvm.cpp Wed Nov 17 22:42:08 2010 -0800
  21794. +++ b/src/share/vm/prims/jvm.cpp Fri Dec 17 13:23:04 2010 +0100
  21795. @@ -811,7 +811,7 @@
  21796. Handle protection_domain (THREAD, JNIHandles::resolve(pd));
  21797. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  21798. protection_domain, &st,
  21799. - verify != 0,
  21800. + verify != 0, KlassHandle(),
  21801. CHECK_NULL);
  21802. if (TraceClassResolution && k != NULL) {
  21803. diff -r f5603a6e5042 src/share/vm/prims/jvmtiClassFileReconstituter.cpp
  21804. --- a/src/share/vm/prims/jvmtiClassFileReconstituter.cpp Wed Nov 17 22:42:08 2010 -0800
  21805. +++ b/src/share/vm/prims/jvmtiClassFileReconstituter.cpp Fri Dec 17 13:23:04 2010 +0100
  21806. @@ -120,6 +120,7 @@
  21807. constMethodHandle const_method(thread(), method->constMethod());
  21808. u2 line_num_cnt = 0;
  21809. int stackmap_len = 0;
  21810. + int local_variable_table_length = 0;
  21811. // compute number and length of attributes -- FIXME: for now no LVT
  21812. int attr_count = 0;
  21813. @@ -154,6 +155,25 @@
  21814. attr_size += 2 + 4 + stackmap_len;
  21815. }
  21816. }
  21817. + if (method->has_localvariable_table()) {
  21818. + local_variable_table_length = method->localvariable_table_length();
  21819. + ++attr_count;
  21820. + if (local_variable_table_length != 0) {
  21821. + // Compute the size of the local variable table attribute (VM stores raw):
  21822. + // LocalVariableTable_attribute {
  21823. + // u2 attribute_name_index;
  21824. + // u4 attribute_length;
  21825. + // u2 local_variable_table_length;
  21826. + // {
  21827. + // u2 start_pc;
  21828. + // u2 length;
  21829. + // u2 name_index;
  21830. + // u2 descriptor_index;
  21831. + // u2 index;
  21832. + // }
  21833. + attr_size += 2 + 4 + 2 + local_variable_table_length * (2 + 2 + 2 + 2 + 2);
  21834. + }
  21835. + }
  21836. typeArrayHandle exception_table(thread(), const_method->exception_table());
  21837. int exception_table_length = exception_table->length();
  21838. @@ -188,6 +208,10 @@
  21839. write_stackmap_table_attribute(method, stackmap_len);
  21840. }
  21841. + if (local_variable_table_length != 0) {
  21842. + write_local_variable_table_attribute(method, local_variable_table_length);
  21843. + }
  21844. +
  21845. // FIXME: write LVT attribute
  21846. }
  21847. @@ -355,6 +379,36 @@
  21848. }
  21849. }
  21850. +// Write LineNumberTable attribute
  21851. +// JVMSpec| LocalVariableTable_attribute {
  21852. +// JVMSpec| u2 attribute_name_index;
  21853. +// JVMSpec| u4 attribute_length;
  21854. +// JVMSpec| u2 local_variable_table_length;
  21855. +// JVMSpec| { u2 start_pc;
  21856. +// JVMSpec| u2 length;
  21857. +// JVMSpec| u2 name_index;
  21858. +// JVMSpec| u2 descriptor_index;
  21859. +// JVMSpec| u2 index;
  21860. +// JVMSpec| } local_variable_table[local_variable_table_length];
  21861. +// JVMSpec| }
  21862. +void JvmtiClassFileReconstituter::write_local_variable_table_attribute(methodHandle method, u2 num_entries) {
  21863. + write_attribute_name_index("LocalVariableTable");
  21864. + write_u4(2 + num_entries * (2 + 2 + 2 + 2 + 2));
  21865. + write_u2(num_entries);
  21866. +
  21867. + assert(method->localvariable_table_length() == num_entries, "just checking");
  21868. +
  21869. + LocalVariableTableElement *elem = method->localvariable_table_start();
  21870. + for (int j=0; j<method->localvariable_table_length(); j++) {
  21871. + write_u2(elem->start_bci);
  21872. + write_u2(elem->length);
  21873. + write_u2(elem->name_cp_index);
  21874. + write_u2(elem->descriptor_cp_index);
  21875. + write_u2(elem->slot);
  21876. + elem++;
  21877. + }
  21878. +}
  21879. +
  21880. // Write stack map table attribute
  21881. // JSR-202| StackMapTable_attribute {
  21882. // JSR-202| u2 attribute_name_index;
  21883. diff -r f5603a6e5042 src/share/vm/prims/jvmtiClassFileReconstituter.hpp
  21884. --- a/src/share/vm/prims/jvmtiClassFileReconstituter.hpp Wed Nov 17 22:42:08 2010 -0800
  21885. +++ b/src/share/vm/prims/jvmtiClassFileReconstituter.hpp Fri Dec 17 13:23:04 2010 +0100
  21886. @@ -114,6 +114,7 @@
  21887. void write_source_debug_extension_attribute();
  21888. u2 line_number_table_entries(methodHandle method);
  21889. void write_line_number_table_attribute(methodHandle method, u2 num_entries);
  21890. + void write_local_variable_table_attribute(methodHandle method, u2 num_entries);
  21891. void write_stackmap_table_attribute(methodHandle method, int stackmap_table_len);
  21892. u2 inner_classes_attribute_length();
  21893. void write_inner_classes_attribute(int length);
  21894. diff -r f5603a6e5042 src/share/vm/prims/jvmtiEnv.cpp
  21895. --- a/src/share/vm/prims/jvmtiEnv.cpp Wed Nov 17 22:42:08 2010 -0800
  21896. +++ b/src/share/vm/prims/jvmtiEnv.cpp Fri Dec 17 13:23:04 2010 +0100
  21897. @@ -240,7 +240,10 @@
  21898. class_definitions[index].klass = jcls;
  21899. }
  21900. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  21901. - VMThread::execute(&op);
  21902. + {
  21903. + MutexLocker sd_mutex(RedefineClasses_lock);
  21904. + VMThread::execute(&op);
  21905. + }
  21906. return (op.check_error());
  21907. } /* end RetransformClasses */
  21908. @@ -249,9 +252,12 @@
  21909. // class_definitions - pre-checked for NULL
  21910. jvmtiError
  21911. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  21912. -//TODO: add locking
  21913. +
  21914. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  21915. - VMThread::execute(&op);
  21916. + {
  21917. + MutexLocker sd_mutex(RedefineClasses_lock);
  21918. + VMThread::execute(&op);
  21919. + }
  21920. return (op.check_error());
  21921. } /* end RedefineClasses */
  21922. diff -r f5603a6e5042 src/share/vm/prims/jvmtiExport.cpp
  21923. --- a/src/share/vm/prims/jvmtiExport.cpp Wed Nov 17 22:42:08 2010 -0800
  21924. +++ b/src/share/vm/prims/jvmtiExport.cpp Fri Dec 17 13:23:04 2010 +0100
  21925. @@ -756,7 +756,7 @@
  21926. void JvmtiExport::post_pending_compiled_method_unload_events() {
  21927. JavaThread* self = JavaThread::current();
  21928. - assert(!self->owns_locks(), "can't hold locks");
  21929. + assert(!self->owns_locks_but_redefine_classes_lock(), "can't hold locks");
  21930. // Indicates if this is the first activiation of this function.
  21931. // In theory the profiler's callback could call back into VM and provoke
  21932. @@ -2392,7 +2392,7 @@
  21933. // iterate over any code blob descriptors collected and post a
  21934. // DYNAMIC_CODE_GENERATED event to the profiler.
  21935. JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
  21936. - assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
  21937. + assert(!JavaThread::current()->owns_locks_but_redefine_classes_lock(), "all locks must be released to post deferred events");
  21938. // iterate over any code blob descriptors that we collected
  21939. if (_code_blobs != NULL) {
  21940. for (int i=0; i<_code_blobs->length(); i++) {
  21941. diff -r f5603a6e5042 src/share/vm/prims/jvmtiImpl.cpp
  21942. --- a/src/share/vm/prims/jvmtiImpl.cpp Wed Nov 17 22:42:08 2010 -0800
  21943. +++ b/src/share/vm/prims/jvmtiImpl.cpp Fri Dec 17 13:23:04 2010 +0100
  21944. @@ -254,6 +254,8 @@
  21945. void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
  21946. ((methodOopDesc*)_method->*meth_act)(_bci);
  21947. + // (tw) TODO: Check how we can implement this differently here!
  21948. +
  21949. // add/remove breakpoint to/from versions of the method that
  21950. // are EMCP. Directly or transitively obsolete methods are
  21951. // not saved in the PreviousVersionInfo.
  21952. @@ -293,10 +295,10 @@
  21953. for (int i = methods->length() - 1; i >= 0; i--) {
  21954. methodHandle method = methods->at(i);
  21955. if (method->name() == m_name && method->signature() == m_signature) {
  21956. - RC_TRACE(0x00000800, ("%sing breakpoint in %s(%s)",
  21957. + TRACE_RC3("%sing breakpoint in %s(%s)",
  21958. meth_act == &methodOopDesc::set_breakpoint ? "sett" : "clear",
  21959. method->name()->as_C_string(),
  21960. - method->signature()->as_C_string()));
  21961. + method->signature()->as_C_string());
  21962. assert(!method->is_obsolete(), "only EMCP methods here");
  21963. ((methodOopDesc*)method()->*meth_act)(_bci);
  21964. diff -r f5603a6e5042 src/share/vm/prims/jvmtiRedefineClasses.cpp
  21965. --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp Wed Nov 17 22:42:08 2010 -0800
  21966. +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp Fri Dec 17 13:23:04 2010 +0100
  21967. @@ -1,26 +1,26 @@
  21968. /*
  21969. - * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
  21970. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  21971. - *
  21972. - * This code is free software; you can redistribute it and/or modify it
  21973. - * under the terms of the GNU General Public License version 2 only, as
  21974. - * published by the Free Software Foundation.
  21975. - *
  21976. - * This code is distributed in the hope that it will be useful, but WITHOUT
  21977. - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  21978. - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  21979. - * version 2 for more details (a copy is included in the LICENSE file that
  21980. - * accompanied this code).
  21981. - *
  21982. - * You should have received a copy of the GNU General Public License version
  21983. - * 2 along with this work; if not, write to the Free Software Foundation,
  21984. - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21985. - *
  21986. - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21987. - * or visit www.oracle.com if you need additional information or have any
  21988. - * questions.
  21989. - *
  21990. - */
  21991. +* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  21992. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  21993. +*
  21994. +* This code is free software; you can redistribute it and/or modify it
  21995. +* under the terms of the GNU General Public License version 2 only, as
  21996. +* published by the Free Software Foundation.
  21997. +*
  21998. +* This code is distributed in the hope that it will be useful, but WITHOUT
  21999. +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  22000. +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  22001. +* version 2 for more details (a copy is included in the LICENSE file that
  22002. +* accompanied this code).
  22003. +*
  22004. +* You should have received a copy of the GNU General Public License version
  22005. +* 2 along with this work; if not, write to the Free Software Foundation,
  22006. +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  22007. +*
  22008. +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22009. +* or visit www.oracle.com if you need additional information or have any
  22010. +* questions.
  22011. +*
  22012. +*/
  22013. # include "incls/_precompiled.incl"
  22014. # include "incls/_jvmtiRedefineClasses.cpp.incl"
  22015. @@ -28,479 +28,601 @@
  22016. objArrayOop VM_RedefineClasses::_old_methods = NULL;
  22017. objArrayOop VM_RedefineClasses::_new_methods = NULL;
  22018. -methodOop* VM_RedefineClasses::_matching_old_methods = NULL;
  22019. -methodOop* VM_RedefineClasses::_matching_new_methods = NULL;
  22020. -methodOop* VM_RedefineClasses::_deleted_methods = NULL;
  22021. -methodOop* VM_RedefineClasses::_added_methods = NULL;
  22022. +int* VM_RedefineClasses::_matching_old_methods = NULL;
  22023. +int* VM_RedefineClasses::_matching_new_methods = NULL;
  22024. +int* VM_RedefineClasses::_deleted_methods = NULL;
  22025. +int* VM_RedefineClasses::_added_methods = NULL;
  22026. int VM_RedefineClasses::_matching_methods_length = 0;
  22027. int VM_RedefineClasses::_deleted_methods_length = 0;
  22028. int VM_RedefineClasses::_added_methods_length = 0;
  22029. klassOop VM_RedefineClasses::_the_class_oop = NULL;
  22030. -
  22031. -VM_RedefineClasses::VM_RedefineClasses(jint class_count,
  22032. - const jvmtiClassDefinition *class_defs,
  22033. - JvmtiClassLoadKind class_load_kind) {
  22034. +// Holds the revision number of the current class redefinition
  22035. +int VM_RedefineClasses::_revision_number = -1;
  22036. +
  22037. +VM_RedefineClasses::VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  22038. + : VM_GC_Operation(Universe::heap()->total_full_collections()) {
  22039. + RC_TIMER_START(_timer_total);
  22040. _class_count = class_count;
  22041. _class_defs = class_defs;
  22042. _class_load_kind = class_load_kind;
  22043. - _res = JVMTI_ERROR_NONE;
  22044. + _updated_oops = NULL;
  22045. + _result = JVMTI_ERROR_NONE;
  22046. }
  22047. +VM_RedefineClasses::~VM_RedefineClasses() {
  22048. + {
  22049. + MonitorLockerEx ml(RedefinitionSync_lock);
  22050. + Threads::set_wait_at_instrumentation_entry(false);
  22051. + ml.notify_all();
  22052. + }
  22053. +
  22054. + unlock_threads();
  22055. + RC_TIMER_STOP(_timer_total);
  22056. +
  22057. + if (TimeRedefineClasses) {
  22058. + tty->print_cr("Timing Prologue: %d", _timer_prologue.milliseconds());
  22059. + tty->print_cr("Timing Class Loading: %d", _timer_class_loading.milliseconds());
  22060. + tty->print_cr("Timing Waiting for Lock: %d", _timer_wait_for_locks.milliseconds());
  22061. + tty->print_cr("Timing Class Linking: %d", _timer_class_linking.milliseconds());
  22062. + tty->print_cr("Timing Check Type: %d", _timer_check_type.milliseconds());
  22063. + tty->print_cr("Timing Prepare Redefinition: %d", _timer_prepare_redefinition.milliseconds());
  22064. + tty->print_cr("Timing Redefinition GC: %d", _timer_redefinition.milliseconds());
  22065. + tty->print_cr("Timing Epilogue: %d", _timer_vm_op_epilogue.milliseconds());
  22066. + tty->print_cr("------------------------------------------------------------------");
  22067. + tty->print_cr("Total Time: %d", _timer_total.milliseconds());
  22068. + }
  22069. +}
  22070. +
  22071. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  22072. +jvmtiError VM_RedefineClasses::find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses) {
  22073. +
  22074. + // Create array with all classes for which the redefine command was given
  22075. + GrowableArray<instanceKlassHandle> klasses_to_redefine;
  22076. + for (int i=0; i<_class_count; i++) {
  22077. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  22078. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_klassOop(mirror));
  22079. + klasses_to_redefine.append(klass_handle);
  22080. + assert(klass_handle->new_version() == NULL, "Must be new class");
  22081. + }
  22082. +
  22083. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  22084. + GrowableArray<instanceKlassHandle> affected_classes;
  22085. + FindAffectedKlassesClosure closure(&klasses_to_redefine, &affected_classes);
  22086. +
  22087. + // Trace affected classes
  22088. + TRACE_RC1("Klasses affected: %d", affected_classes.length());
  22089. + IF_TRACE_RC2 {
  22090. + for (int i=0; i<affected_classes.length(); i++) {
  22091. + TRACE_RC2(affected_classes.at(i)->name()->as_C_string());
  22092. + }
  22093. + }
  22094. +
  22095. + // Add the array of affected classes and the array of redefined classes to get a list of all classes that need a redefinition
  22096. + all_affected_klasses->appendAll(&klasses_to_redefine);
  22097. + all_affected_klasses->appendAll(&affected_classes);
  22098. +
  22099. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  22100. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, &affected_classes, all_affected_klasses, Thread::current());
  22101. + IF_TRACE_RC2 {
  22102. + TRACE_RC2("Redefine order: ");
  22103. + for (int i=0; i<all_affected_klasses->length(); i++) {
  22104. + TRACE_RC2("%s", all_affected_klasses->at(i)->name()->as_C_string());
  22105. + }
  22106. + }
  22107. +
  22108. + return result;
  22109. +}
  22110. +
  22111. +// Searches for the class bytes of the given class and returns them as a byte array.
  22112. +jvmtiError VM_RedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  22113. +
  22114. + *not_changed = false;
  22115. +
  22116. + // Search for the index in the redefinition array that corresponds to the current class
  22117. + int j;
  22118. + for (j=0; j<_class_count; j++) {
  22119. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  22120. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  22121. + if (the_class_oop == the_class()) {
  22122. + break;
  22123. + }
  22124. + }
  22125. +
  22126. + if (j == _class_count) {
  22127. +
  22128. + *not_changed = true;
  22129. +
  22130. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  22131. + // so the user did not specify a different bytecode for that class.
  22132. +
  22133. + if (the_class->get_cached_class_file_bytes() == NULL) {
  22134. + // not cached, we need to reconstitute the class file from VM representation
  22135. + constantPoolHandle constants(Thread::current(), the_class->constants());
  22136. + ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  22137. +
  22138. + JvmtiClassFileReconstituter reconstituter(the_class);
  22139. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  22140. + return reconstituter.get_error();
  22141. + }
  22142. +
  22143. + *class_byte_count = (jint)reconstituter.class_file_size();
  22144. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  22145. +
  22146. + } else {
  22147. +
  22148. + // it is cached, get it from the cache
  22149. + *class_byte_count = the_class->get_cached_class_file_len();
  22150. + *class_bytes = the_class->get_cached_class_file_bytes();
  22151. + }
  22152. +
  22153. + } else {
  22154. +
  22155. + // Redefine with bytecodes at index j
  22156. + *class_bytes = _class_defs[j].class_bytes;
  22157. + *class_byte_count = _class_defs[j].class_byte_count;
  22158. + }
  22159. +
  22160. + return JVMTI_ERROR_NONE;
  22161. +}
  22162. +
  22163. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  22164. bool VM_RedefineClasses::doit_prologue() {
  22165. - if (_class_count == 0) {
  22166. - _res = JVMTI_ERROR_NONE;
  22167. +
  22168. + _revision_number++;
  22169. + TRACE_RC1("Redefinition with revision number %d started!", _revision_number);
  22170. +
  22171. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  22172. + RC_TIMER_START(_timer_prologue);
  22173. +
  22174. + if (!check_arguments()) {
  22175. + RC_TIMER_STOP(_timer_prologue);
  22176. return false;
  22177. }
  22178. - if (_class_defs == NULL) {
  22179. - _res = JVMTI_ERROR_NULL_POINTER;
  22180. +
  22181. + // We first load new class versions in the prologue, because somewhere down the
  22182. + // call chain it is required that the current thread is a Java thread.
  22183. + _new_classes = new (ResourceObj::C_HEAP) GrowableArray<instanceKlassHandle>(5, true);
  22184. + _result = load_new_class_versions(Thread::current());
  22185. +
  22186. + TRACE_RC1("Loaded new class versions!");
  22187. + if (_result != JVMTI_ERROR_NONE) {
  22188. + TRACE_RC1("error occured: %d!", _result);
  22189. + delete _new_classes;
  22190. + _new_classes = NULL;
  22191. + RC_TIMER_STOP(_timer_prologue);
  22192. return false;
  22193. }
  22194. +
  22195. + TRACE_RC2("nearly finished");
  22196. + VM_GC_Operation::doit_prologue();
  22197. + RC_TIMER_STOP(_timer_prologue);
  22198. + TRACE_RC2("doit_prologue finished!");
  22199. + return true;
  22200. +}
  22201. +
  22202. +// Checks basic properties of the arguments of the redefinition command.
  22203. +bool VM_RedefineClasses::check_arguments() {
  22204. +
  22205. + if (_class_count == 0) RC_ABORT(JVMTI_ERROR_NONE);
  22206. + if (_class_defs == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  22207. for (int i = 0; i < _class_count; i++) {
  22208. - if (_class_defs[i].klass == NULL) {
  22209. - _res = JVMTI_ERROR_INVALID_CLASS;
  22210. - return false;
  22211. + if (_class_defs[i].klass == NULL) RC_ABORT(JVMTI_ERROR_INVALID_CLASS);
  22212. + if (_class_defs[i].class_byte_count == 0) RC_ABORT(JVMTI_ERROR_INVALID_CLASS_FORMAT);
  22213. + if (_class_defs[i].class_bytes == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  22214. + }
  22215. +
  22216. + return true;
  22217. +}
  22218. +
  22219. +jvmtiError VM_RedefineClasses::check_exception() const {
  22220. + Thread* THREAD = Thread::current();
  22221. + if (HAS_PENDING_EXCEPTION) {
  22222. +
  22223. + symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  22224. + TRACE_RC1("parse_stream exception: '%s'", ex_name->as_C_string());
  22225. + if (TraceRedefineClasses >= 1) {
  22226. + java_lang_Throwable::print(PENDING_EXCEPTION, tty);
  22227. + tty->print_cr("");
  22228. }
  22229. - if (_class_defs[i].class_byte_count == 0) {
  22230. - _res = JVMTI_ERROR_INVALID_CLASS_FORMAT;
  22231. - return false;
  22232. - }
  22233. - if (_class_defs[i].class_bytes == NULL) {
  22234. - _res = JVMTI_ERROR_NULL_POINTER;
  22235. - return false;
  22236. + CLEAR_PENDING_EXCEPTION;
  22237. +
  22238. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  22239. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  22240. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  22241. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  22242. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  22243. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  22244. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  22245. + // The message will be "XXX (wrong name: YYY)"
  22246. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  22247. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  22248. + return JVMTI_ERROR_OUT_OF_MEMORY;
  22249. + } else {
  22250. + // Just in case more exceptions can be thrown..
  22251. + return JVMTI_ERROR_FAILS_VERIFICATION;
  22252. }
  22253. }
  22254. - // Start timer after all the sanity checks; not quite accurate, but
  22255. - // better than adding a bunch of stop() calls.
  22256. - RC_TIMER_START(_timer_vm_op_prologue);
  22257. -
  22258. - // We first load new class versions in the prologue, because somewhere down the
  22259. - // call chain it is required that the current thread is a Java thread.
  22260. - _res = load_new_class_versions(Thread::current());
  22261. - if (_res != JVMTI_ERROR_NONE) {
  22262. - // Free os::malloc allocated memory in load_new_class_version.
  22263. - os::free(_scratch_classes);
  22264. - RC_TIMER_STOP(_timer_vm_op_prologue);
  22265. - return false;
  22266. + return JVMTI_ERROR_NONE;
  22267. +}
  22268. +
  22269. +// Loads all new class versions and stores the instanceKlass handles in an array.
  22270. +jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  22271. +
  22272. + ResourceMark rm(THREAD);
  22273. +
  22274. + TRACE_RC1("===================================================================");
  22275. + TRACE_RC1("load new class versions (%d)", _class_count);
  22276. +
  22277. + // Retrieve an array of all classes that need to be redefined
  22278. + GrowableArray<instanceKlassHandle> all_affected_klasses;
  22279. + jvmtiError err = find_sorted_affected_classes(&all_affected_klasses);
  22280. + if (err != JVMTI_ERROR_NONE) {
  22281. + TRACE_RC1("Error finding sorted affected classes: %d", (int)err);
  22282. + return err;
  22283. }
  22284. - RC_TIMER_STOP(_timer_vm_op_prologue);
  22285. - return true;
  22286. -}
  22287. -
  22288. -void VM_RedefineClasses::doit() {
  22289. - Thread *thread = Thread::current();
  22290. -
  22291. - if (UseSharedSpaces) {
  22292. - // Sharing is enabled so we remap the shared readonly space to
  22293. - // shared readwrite, private just in case we need to redefine
  22294. - // a shared class. We do the remap during the doit() phase of
  22295. - // the safepoint to be safer.
  22296. - if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  22297. - RC_TRACE_WITH_THREAD(0x00000001, thread,
  22298. - ("failed to remap shared readonly space to readwrite, private"));
  22299. - _res = JVMTI_ERROR_INTERNAL;
  22300. - return;
  22301. +
  22302. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  22303. +
  22304. + _max_redefinition_flags = Klass::NoRedefinition;
  22305. + jvmtiError result = JVMTI_ERROR_NONE;
  22306. +
  22307. + for (int i=0; i<all_affected_klasses.length(); i++) {
  22308. + TRACE_RC2("Processing affected class %d of %d", i+1, all_affected_klasses.length());
  22309. +
  22310. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  22311. + TRACE_RC2("name=%s", the_class->name()->as_C_string());
  22312. +
  22313. + the_class->link_class(THREAD);
  22314. + result = check_exception();
  22315. + if (result != JVMTI_ERROR_NONE) break;
  22316. +
  22317. + // Find new class bytes
  22318. + const unsigned char* class_bytes;
  22319. + jint class_byte_count;
  22320. + jvmtiError error;
  22321. + jboolean not_changed;
  22322. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  22323. + TRACE_RC1("Error finding class bytes: %d", (int)error);
  22324. + result = error;
  22325. + break;
  22326. + }
  22327. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  22328. +
  22329. +
  22330. + // Set redefined class handle in JvmtiThreadState class.
  22331. + // This redefined class is sent to agent event handler for class file
  22332. + // load hook event.
  22333. + state->set_class_being_redefined(&the_class, _class_load_kind);
  22334. +
  22335. + TRACE_RC2("Before resolving from stream");
  22336. +
  22337. + RC_TIMER_STOP(_timer_prologue);
  22338. + RC_TIMER_START(_timer_class_loading);
  22339. +
  22340. +
  22341. + // Parse the stream.
  22342. + Handle the_class_loader(THREAD, the_class->class_loader());
  22343. + Handle protection_domain(THREAD, the_class->protection_domain());
  22344. + symbolHandle the_class_sym = symbolHandle(THREAD, the_class->name());
  22345. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_RedefineClasses__");
  22346. + instanceKlassHandle new_class(THREAD, SystemDictionary::resolve_from_stream(the_class_sym,
  22347. + the_class_loader,
  22348. + protection_domain,
  22349. + &st,
  22350. + true,
  22351. + the_class,
  22352. + THREAD));
  22353. +
  22354. + not_changed = false;
  22355. +
  22356. + RC_TIMER_STOP(_timer_class_loading);
  22357. + RC_TIMER_START(_timer_prologue);
  22358. +
  22359. + TRACE_RC2("After resolving class from stream!");
  22360. + // Clear class_being_redefined just to be sure.
  22361. + state->clear_class_being_redefined();
  22362. +
  22363. + result = check_exception();
  22364. + if (result != JVMTI_ERROR_NONE) break;
  22365. +
  22366. +#ifdef ASSERT
  22367. +
  22368. + assert(new_class() != NULL, "Class could not be loaded!");
  22369. + assert(new_class() != the_class(), "must be different");
  22370. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  22371. +
  22372. +
  22373. + objArrayOop k_interfaces = new_class->local_interfaces();
  22374. + for (int j=0; j<k_interfaces->length(); j++) {
  22375. + assert(((klassOop)k_interfaces->obj_at(j))->klass_part()->is_newest_version(), "just checking");
  22376. + }
  22377. +
  22378. + if (!THREAD->is_Compiler_thread()) {
  22379. +
  22380. + TRACE_RC2("name=%s loader=%d protection_domain=%d", the_class->name()->as_C_string(), (int)(the_class->class_loader()), (int)(the_class->protection_domain()));
  22381. + // If we are on the compiler thread, we must not try to resolve a class.
  22382. + klassOop systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  22383. +
  22384. + if (systemLookup != NULL) {
  22385. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  22386. +
  22387. +
  22388. + Klass *subklass = new_class()->klass_part()->subklass();
  22389. + while (subklass != NULL) {
  22390. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  22391. + subklass = subklass->next_sibling();
  22392. + }
  22393. + } else {
  22394. + // This can happen for reflection generated classes.. ?
  22395. + CLEAR_PENDING_EXCEPTION;
  22396. + }
  22397. + }
  22398. +
  22399. +#endif
  22400. +
  22401. + IF_TRACE_RC1 {
  22402. + if (new_class->layout_helper() != the_class->layout_helper()) {
  22403. + TRACE_RC1("Instance size change for class %s: new=%d old=%d", new_class->name()->as_C_string(), new_class->layout_helper(), the_class->layout_helper());
  22404. + }
  22405. + }
  22406. +
  22407. + // Set the new version of the class
  22408. + new_class->set_revision_number(_revision_number);
  22409. + new_class->set_redefinition_index(i);
  22410. + the_class->set_new_version(new_class());
  22411. + _new_classes->append(new_class);
  22412. +
  22413. + assert(new_class->new_version() == NULL, "");
  22414. +
  22415. + int redefinition_flags = Klass::NoRedefinition;
  22416. +
  22417. + if (not_changed) {
  22418. + redefinition_flags = Klass::NoRedefinition;
  22419. + } else if (AllowAdvancedClassRedefinition) {
  22420. + redefinition_flags = calculate_redefinition_flags(new_class);
  22421. + } else {
  22422. + jvmtiError allowed = check_redefinition_allowed(new_class);
  22423. + if (allowed != JVMTI_ERROR_NONE) {
  22424. + TRACE_RC1("Error redefinition not allowed!");
  22425. + result = allowed;
  22426. + break;
  22427. + }
  22428. + redefinition_flags = Klass::ModifyClass;
  22429. + }
  22430. +
  22431. + if (new_class->super() != NULL) {
  22432. + redefinition_flags = redefinition_flags | new_class->super()->klass_part()->redefinition_flags();
  22433. + }
  22434. +
  22435. + for (int j=0; j<new_class->local_interfaces()->length(); j++) {
  22436. + redefinition_flags = redefinition_flags | ((klassOop)new_class->local_interfaces()->obj_at(j))->klass_part()->redefinition_flags();
  22437. + }
  22438. +
  22439. + new_class->set_redefinition_flags(redefinition_flags);
  22440. +
  22441. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  22442. +
  22443. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  22444. + // TODO: Check if watch access flags of static fields are updated correctly.
  22445. + calculate_instance_update_information(_new_classes->at(i)());
  22446. + } else {
  22447. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->klass_part()->layout_helper() >> 1, "must be equal");
  22448. + assert(new_class->fields()->length() == ((instanceKlass*)new_class->old_version()->klass_part())->fields()->length(), "must be equal");
  22449. +
  22450. + fieldDescriptor fd_new;
  22451. + fieldDescriptor fd_old;
  22452. + for (int i=0; i<new_class->fields()->length(); i+=instanceKlass::next_offset) {
  22453. + fd_new.initialize(new_class(), i);
  22454. + fd_old.initialize(new_class->old_version(), i);
  22455. + transfer_special_access_flags(&fd_old, &fd_new);
  22456. + }
  22457. + }
  22458. +
  22459. + IF_TRACE_RC3 {
  22460. + if (new_class->super() != NULL) {
  22461. + TRACE_RC3("Super class is %s", new_class->super()->klass_part()->name()->as_C_string());
  22462. + }
  22463. + }
  22464. +
  22465. +#ifdef ASSERT
  22466. + assert(new_class->super() == NULL || new_class->super()->klass_part()->new_version() == NULL, "Super klass must be newest version!");
  22467. +
  22468. + the_class->vtable()->verify(tty);
  22469. + new_class->vtable()->verify(tty);
  22470. +#endif
  22471. +
  22472. + TRACE_RC2("Verification done!");
  22473. +
  22474. + if (i == all_affected_klasses.length() - 1) {
  22475. +
  22476. + // This was the last class processed => check if additional classes have been loaded in the meantime
  22477. +
  22478. + RC_TIMER_STOP(_timer_prologue);
  22479. + lock_threads();
  22480. + RC_TIMER_START(_timer_prologue);
  22481. +
  22482. + for (int j=0; j<all_affected_klasses.length(); j++) {
  22483. +
  22484. + klassOop initial_klass = all_affected_klasses.at(j)();
  22485. + Klass *initial_subklass = initial_klass->klass_part()->subklass();
  22486. + Klass *cur_klass = initial_subklass;
  22487. + while(cur_klass != NULL) {
  22488. +
  22489. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version()) {
  22490. + instanceKlassHandle handle(THREAD, cur_klass->as_klassOop());
  22491. + if (!all_affected_klasses.contains(handle)) {
  22492. +
  22493. + int k = i + 1;
  22494. + for (; k<all_affected_klasses.length(); k++) {
  22495. + if (all_affected_klasses.at(k)->is_subtype_of(cur_klass->as_klassOop())) {
  22496. + break;
  22497. + }
  22498. + }
  22499. + all_affected_klasses.insert_before(k, handle);
  22500. + TRACE_RC2("Adding newly loaded class to affected classes: %s", cur_klass->name()->as_C_string());
  22501. + }
  22502. + }
  22503. +
  22504. + cur_klass = cur_klass->next_sibling();
  22505. + }
  22506. + }
  22507. +
  22508. + int new_count = all_affected_klasses.length() - 1 - i;
  22509. + if (new_count != 0) {
  22510. +
  22511. + unlock_threads();
  22512. + TRACE_RC1("Found new number of affected classes: %d", new_count);
  22513. + }
  22514. }
  22515. }
  22516. - for (int i = 0; i < _class_count; i++) {
  22517. - redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  22518. + if (result != JVMTI_ERROR_NONE) {
  22519. + rollback();
  22520. + return result;
  22521. }
  22522. - // Disable any dependent concurrent compilations
  22523. - SystemDictionary::notice_modification();
  22524. -
  22525. - // Set flag indicating that some invariants are no longer true.
  22526. - // See jvmtiExport.hpp for detailed explanation.
  22527. - JvmtiExport::set_has_redefined_a_class();
  22528. +
  22529. + RC_TIMER_STOP(_timer_prologue);
  22530. + RC_TIMER_START(_timer_class_linking);
  22531. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  22532. + for (int i=0; i<all_affected_klasses.length(); i++) {
  22533. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  22534. + instanceKlassHandle new_class(the_class->new_version());
  22535. +
  22536. + TRACE_RC2("Linking class %d/%d %s", i, all_affected_klasses.length(), the_class->name()->as_C_string());
  22537. + new_class->link_class(THREAD);
  22538. +
  22539. + result = check_exception();
  22540. + if (result != JVMTI_ERROR_NONE) break;
  22541. + }
  22542. + RC_TIMER_STOP(_timer_class_linking);
  22543. + RC_TIMER_START(_timer_prologue);
  22544. +
  22545. + if (result != JVMTI_ERROR_NONE) {
  22546. + rollback();
  22547. + return result;
  22548. + }
  22549. +
  22550. + TRACE_RC2("All classes loaded!");
  22551. #ifdef ASSERT
  22552. - SystemDictionary::classes_do(check_class, thread);
  22553. + for (int i=0; i<all_affected_klasses.length(); i++) {
  22554. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  22555. + assert(the_class->new_version() != NULL, "Must have been redefined");
  22556. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  22557. + assert(new_version->new_version() == NULL, "Must be newest version");
  22558. +
  22559. + if (!(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL)) {
  22560. + new_version()->print();
  22561. + new_version->super()->print();
  22562. + }
  22563. + assert(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL, "Super class must be newest version");
  22564. + }
  22565. +
  22566. + SystemDictionary::classes_do(check_class, THREAD);
  22567. +
  22568. #endif
  22569. +
  22570. + TRACE_RC1("Finished verification!");
  22571. + return JVMTI_ERROR_NONE;
  22572. }
  22573. -void VM_RedefineClasses::doit_epilogue() {
  22574. - // Free os::malloc allocated memory.
  22575. - // The memory allocated in redefine will be free'ed in next VM operation.
  22576. - os::free(_scratch_classes);
  22577. -
  22578. - if (RC_TRACE_ENABLED(0x00000004)) {
  22579. - // Used to have separate timers for "doit" and "all", but the timer
  22580. - // overhead skewed the measurements.
  22581. - jlong doit_time = _timer_rsc_phase1.milliseconds() +
  22582. - _timer_rsc_phase2.milliseconds();
  22583. - jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
  22584. -
  22585. - RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
  22586. - " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
  22587. - _timer_vm_op_prologue.milliseconds(), doit_time));
  22588. - RC_TRACE(0x00000004,
  22589. - ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
  22590. - _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
  22591. +void VM_RedefineClasses::lock_threads() {
  22592. +
  22593. + RC_TIMER_START(_timer_wait_for_locks);
  22594. +
  22595. +
  22596. + JavaThread *javaThread = Threads::first();
  22597. + while (javaThread != NULL) {
  22598. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  22599. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  22600. + compilerThread->set_should_bailout(true);
  22601. + }
  22602. + javaThread = javaThread->next();
  22603. }
  22604. +
  22605. + int cnt = 0;
  22606. + javaThread = Threads::first();
  22607. + while (javaThread != NULL) {
  22608. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  22609. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  22610. + compilerThread->compilation_mutex()->lock();
  22611. + cnt++;
  22612. + }
  22613. + javaThread = javaThread->next();
  22614. + }
  22615. +
  22616. + TRACE_RC2("Locked %d compiler threads", cnt);
  22617. +
  22618. + cnt = 0;
  22619. + javaThread = Threads::first();
  22620. + while (javaThread != NULL) {
  22621. + if (javaThread != Thread::current()) {
  22622. + javaThread->redefine_classes_mutex()->lock();
  22623. + }
  22624. + javaThread = javaThread->next();
  22625. + }
  22626. +
  22627. +
  22628. + TRACE_RC2("Locked %d threads", cnt);
  22629. +
  22630. + RC_TIMER_STOP(_timer_wait_for_locks);
  22631. }
  22632. -bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  22633. - // classes for primitives cannot be redefined
  22634. - if (java_lang_Class::is_primitive(klass_mirror)) {
  22635. - return false;
  22636. +void VM_RedefineClasses::unlock_threads() {
  22637. +
  22638. + int cnt = 0;
  22639. + JavaThread *javaThread = Threads::first();
  22640. + Thread *thread = Thread::current();
  22641. + while (javaThread != NULL) {
  22642. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  22643. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  22644. + if (compilerThread->compilation_mutex()->owned_by_self()) {
  22645. + compilerThread->compilation_mutex()->unlock();
  22646. + cnt++;
  22647. + }
  22648. + }
  22649. + javaThread = javaThread->next();
  22650. }
  22651. - klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  22652. - // classes for arrays cannot be redefined
  22653. - if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  22654. - return false;
  22655. +
  22656. + TRACE_RC2("Unlocked %d compiler threads", cnt);
  22657. +
  22658. + cnt = 0;
  22659. + javaThread = Threads::first();
  22660. + while (javaThread != NULL) {
  22661. + if (javaThread != Thread::current()) {
  22662. + if (javaThread->redefine_classes_mutex()->owned_by_self()) {
  22663. + javaThread->redefine_classes_mutex()->unlock();
  22664. + }
  22665. + }
  22666. + javaThread = javaThread->next();
  22667. }
  22668. - return true;
  22669. +
  22670. + TRACE_RC2("Unlocked %d threads", cnt);
  22671. }
  22672. -// Append the current entry at scratch_i in scratch_cp to *merge_cp_p
  22673. -// where the end of *merge_cp_p is specified by *merge_cp_length_p. For
  22674. -// direct CP entries, there is just the current entry to append. For
  22675. -// indirect and double-indirect CP entries, there are zero or more
  22676. -// referenced CP entries along with the current entry to append.
  22677. -// Indirect and double-indirect CP entries are handled by recursive
  22678. -// calls to append_entry() as needed. The referenced CP entries are
  22679. -// always appended to *merge_cp_p before the referee CP entry. These
  22680. -// referenced CP entries may already exist in *merge_cp_p in which case
  22681. -// there is nothing extra to append and only the current entry is
  22682. -// appended.
  22683. -void VM_RedefineClasses::append_entry(constantPoolHandle scratch_cp,
  22684. - int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p,
  22685. - TRAPS) {
  22686. -
  22687. - // append is different depending on entry tag type
  22688. - switch (scratch_cp->tag_at(scratch_i).value()) {
  22689. -
  22690. - // The old verifier is implemented outside the VM. It loads classes,
  22691. - // but does not resolve constant pool entries directly so we never
  22692. - // see Class entries here with the old verifier. Similarly the old
  22693. - // verifier does not like Class entries in the input constant pool.
  22694. - // The split-verifier is implemented in the VM so it can optionally
  22695. - // and directly resolve constant pool entries to load classes. The
  22696. - // split-verifier can accept either Class entries or UnresolvedClass
  22697. - // entries in the input constant pool. We revert the appended copy
  22698. - // back to UnresolvedClass so that either verifier will be happy
  22699. - // with the constant pool entry.
  22700. - case JVM_CONSTANT_Class:
  22701. - {
  22702. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  22703. - (*merge_cp_p)->unresolved_klass_at_put(*merge_cp_length_p,
  22704. - scratch_cp->klass_name_at(scratch_i));
  22705. -
  22706. - if (scratch_i != *merge_cp_length_p) {
  22707. - // The new entry in *merge_cp_p is at a different index than
  22708. - // the new entry in scratch_cp so we need to map the index values.
  22709. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  22710. - }
  22711. - (*merge_cp_length_p)++;
  22712. - } break;
  22713. -
  22714. - // these are direct CP entries so they can be directly appended,
  22715. - // but double and long take two constant pool entries
  22716. - case JVM_CONSTANT_Double: // fall through
  22717. - case JVM_CONSTANT_Long:
  22718. - {
  22719. - scratch_cp->copy_entry_to(scratch_i, *merge_cp_p, *merge_cp_length_p,
  22720. - THREAD);
  22721. -
  22722. - if (scratch_i != *merge_cp_length_p) {
  22723. - // The new entry in *merge_cp_p is at a different index than
  22724. - // the new entry in scratch_cp so we need to map the index values.
  22725. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  22726. - }
  22727. - (*merge_cp_length_p) += 2;
  22728. - } break;
  22729. -
  22730. - // these are direct CP entries so they can be directly appended
  22731. - case JVM_CONSTANT_Float: // fall through
  22732. - case JVM_CONSTANT_Integer: // fall through
  22733. - case JVM_CONSTANT_Utf8: // fall through
  22734. -
  22735. - // This was an indirect CP entry, but it has been changed into
  22736. - // an interned string so this entry can be directly appended.
  22737. - case JVM_CONSTANT_String: // fall through
  22738. -
  22739. - // These were indirect CP entries, but they have been changed into
  22740. - // symbolOops so these entries can be directly appended.
  22741. - case JVM_CONSTANT_UnresolvedClass: // fall through
  22742. - case JVM_CONSTANT_UnresolvedString:
  22743. - {
  22744. - scratch_cp->copy_entry_to(scratch_i, *merge_cp_p, *merge_cp_length_p,
  22745. - THREAD);
  22746. -
  22747. - if (scratch_i != *merge_cp_length_p) {
  22748. - // The new entry in *merge_cp_p is at a different index than
  22749. - // the new entry in scratch_cp so we need to map the index values.
  22750. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  22751. - }
  22752. - (*merge_cp_length_p)++;
  22753. - } break;
  22754. -
  22755. - // this is an indirect CP entry so it needs special handling
  22756. - case JVM_CONSTANT_NameAndType:
  22757. - {
  22758. - int name_ref_i = scratch_cp->name_ref_index_at(scratch_i);
  22759. - int new_name_ref_i = 0;
  22760. - bool match = (name_ref_i < *merge_cp_length_p) &&
  22761. - scratch_cp->compare_entry_to(name_ref_i, *merge_cp_p, name_ref_i,
  22762. - THREAD);
  22763. - if (!match) {
  22764. - // forward reference in *merge_cp_p or not a direct match
  22765. -
  22766. - int found_i = scratch_cp->find_matching_entry(name_ref_i, *merge_cp_p,
  22767. - THREAD);
  22768. - if (found_i != 0) {
  22769. - guarantee(found_i != name_ref_i,
  22770. - "compare_entry_to() and find_matching_entry() do not agree");
  22771. -
  22772. - // Found a matching entry somewhere else in *merge_cp_p so
  22773. - // just need a mapping entry.
  22774. - new_name_ref_i = found_i;
  22775. - map_index(scratch_cp, name_ref_i, found_i);
  22776. - } else {
  22777. - // no match found so we have to append this entry to *merge_cp_p
  22778. - append_entry(scratch_cp, name_ref_i, merge_cp_p, merge_cp_length_p,
  22779. - THREAD);
  22780. - // The above call to append_entry() can only append one entry
  22781. - // so the post call query of *merge_cp_length_p is only for
  22782. - // the sake of consistency.
  22783. - new_name_ref_i = *merge_cp_length_p - 1;
  22784. - }
  22785. - }
  22786. -
  22787. - int signature_ref_i = scratch_cp->signature_ref_index_at(scratch_i);
  22788. - int new_signature_ref_i = 0;
  22789. - match = (signature_ref_i < *merge_cp_length_p) &&
  22790. - scratch_cp->compare_entry_to(signature_ref_i, *merge_cp_p,
  22791. - signature_ref_i, THREAD);
  22792. - if (!match) {
  22793. - // forward reference in *merge_cp_p or not a direct match
  22794. -
  22795. - int found_i = scratch_cp->find_matching_entry(signature_ref_i,
  22796. - *merge_cp_p, THREAD);
  22797. - if (found_i != 0) {
  22798. - guarantee(found_i != signature_ref_i,
  22799. - "compare_entry_to() and find_matching_entry() do not agree");
  22800. -
  22801. - // Found a matching entry somewhere else in *merge_cp_p so
  22802. - // just need a mapping entry.
  22803. - new_signature_ref_i = found_i;
  22804. - map_index(scratch_cp, signature_ref_i, found_i);
  22805. - } else {
  22806. - // no match found so we have to append this entry to *merge_cp_p
  22807. - append_entry(scratch_cp, signature_ref_i, merge_cp_p,
  22808. - merge_cp_length_p, THREAD);
  22809. - // The above call to append_entry() can only append one entry
  22810. - // so the post call query of *merge_cp_length_p is only for
  22811. - // the sake of consistency.
  22812. - new_signature_ref_i = *merge_cp_length_p - 1;
  22813. - }
  22814. - }
  22815. -
  22816. - // If the referenced entries already exist in *merge_cp_p, then
  22817. - // both new_name_ref_i and new_signature_ref_i will both be 0.
  22818. - // In that case, all we are appending is the current entry.
  22819. - if (new_name_ref_i == 0) {
  22820. - new_name_ref_i = name_ref_i;
  22821. - } else {
  22822. - RC_TRACE(0x00080000,
  22823. - ("NameAndType entry@%d name_ref_index change: %d to %d",
  22824. - *merge_cp_length_p, name_ref_i, new_name_ref_i));
  22825. - }
  22826. - if (new_signature_ref_i == 0) {
  22827. - new_signature_ref_i = signature_ref_i;
  22828. - } else {
  22829. - RC_TRACE(0x00080000,
  22830. - ("NameAndType entry@%d signature_ref_index change: %d to %d",
  22831. - *merge_cp_length_p, signature_ref_i, new_signature_ref_i));
  22832. - }
  22833. -
  22834. - (*merge_cp_p)->name_and_type_at_put(*merge_cp_length_p,
  22835. - new_name_ref_i, new_signature_ref_i);
  22836. - if (scratch_i != *merge_cp_length_p) {
  22837. - // The new entry in *merge_cp_p is at a different index than
  22838. - // the new entry in scratch_cp so we need to map the index values.
  22839. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  22840. - }
  22841. - (*merge_cp_length_p)++;
  22842. - } break;
  22843. -
  22844. - // this is a double-indirect CP entry so it needs special handling
  22845. - case JVM_CONSTANT_Fieldref: // fall through
  22846. - case JVM_CONSTANT_InterfaceMethodref: // fall through
  22847. - case JVM_CONSTANT_Methodref:
  22848. - {
  22849. - int klass_ref_i = scratch_cp->uncached_klass_ref_index_at(scratch_i);
  22850. - int new_klass_ref_i = 0;
  22851. - bool match = (klass_ref_i < *merge_cp_length_p) &&
  22852. - scratch_cp->compare_entry_to(klass_ref_i, *merge_cp_p, klass_ref_i,
  22853. - THREAD);
  22854. - if (!match) {
  22855. - // forward reference in *merge_cp_p or not a direct match
  22856. -
  22857. - int found_i = scratch_cp->find_matching_entry(klass_ref_i, *merge_cp_p,
  22858. - THREAD);
  22859. - if (found_i != 0) {
  22860. - guarantee(found_i != klass_ref_i,
  22861. - "compare_entry_to() and find_matching_entry() do not agree");
  22862. -
  22863. - // Found a matching entry somewhere else in *merge_cp_p so
  22864. - // just need a mapping entry.
  22865. - new_klass_ref_i = found_i;
  22866. - map_index(scratch_cp, klass_ref_i, found_i);
  22867. - } else {
  22868. - // no match found so we have to append this entry to *merge_cp_p
  22869. - append_entry(scratch_cp, klass_ref_i, merge_cp_p, merge_cp_length_p,
  22870. - THREAD);
  22871. - // The above call to append_entry() can only append one entry
  22872. - // so the post call query of *merge_cp_length_p is only for
  22873. - // the sake of consistency. Without the optimization where we
  22874. - // use JVM_CONSTANT_UnresolvedClass, then up to two entries
  22875. - // could be appended.
  22876. - new_klass_ref_i = *merge_cp_length_p - 1;
  22877. - }
  22878. - }
  22879. -
  22880. - int name_and_type_ref_i =
  22881. - scratch_cp->uncached_name_and_type_ref_index_at(scratch_i);
  22882. - int new_name_and_type_ref_i = 0;
  22883. - match = (name_and_type_ref_i < *merge_cp_length_p) &&
  22884. - scratch_cp->compare_entry_to(name_and_type_ref_i, *merge_cp_p,
  22885. - name_and_type_ref_i, THREAD);
  22886. - if (!match) {
  22887. - // forward reference in *merge_cp_p or not a direct match
  22888. -
  22889. - int found_i = scratch_cp->find_matching_entry(name_and_type_ref_i,
  22890. - *merge_cp_p, THREAD);
  22891. - if (found_i != 0) {
  22892. - guarantee(found_i != name_and_type_ref_i,
  22893. - "compare_entry_to() and find_matching_entry() do not agree");
  22894. -
  22895. - // Found a matching entry somewhere else in *merge_cp_p so
  22896. - // just need a mapping entry.
  22897. - new_name_and_type_ref_i = found_i;
  22898. - map_index(scratch_cp, name_and_type_ref_i, found_i);
  22899. - } else {
  22900. - // no match found so we have to append this entry to *merge_cp_p
  22901. - append_entry(scratch_cp, name_and_type_ref_i, merge_cp_p,
  22902. - merge_cp_length_p, THREAD);
  22903. - // The above call to append_entry() can append more than
  22904. - // one entry so the post call query of *merge_cp_length_p
  22905. - // is required in order to get the right index for the
  22906. - // JVM_CONSTANT_NameAndType entry.
  22907. - new_name_and_type_ref_i = *merge_cp_length_p - 1;
  22908. - }
  22909. - }
  22910. -
  22911. - // If the referenced entries already exist in *merge_cp_p, then
  22912. - // both new_klass_ref_i and new_name_and_type_ref_i will both be
  22913. - // 0. In that case, all we are appending is the current entry.
  22914. - if (new_klass_ref_i == 0) {
  22915. - new_klass_ref_i = klass_ref_i;
  22916. - }
  22917. - if (new_name_and_type_ref_i == 0) {
  22918. - new_name_and_type_ref_i = name_and_type_ref_i;
  22919. - }
  22920. -
  22921. - const char *entry_name;
  22922. - switch (scratch_cp->tag_at(scratch_i).value()) {
  22923. - case JVM_CONSTANT_Fieldref:
  22924. - entry_name = "Fieldref";
  22925. - (*merge_cp_p)->field_at_put(*merge_cp_length_p, new_klass_ref_i,
  22926. - new_name_and_type_ref_i);
  22927. - break;
  22928. - case JVM_CONSTANT_InterfaceMethodref:
  22929. - entry_name = "IFMethodref";
  22930. - (*merge_cp_p)->interface_method_at_put(*merge_cp_length_p,
  22931. - new_klass_ref_i, new_name_and_type_ref_i);
  22932. - break;
  22933. - case JVM_CONSTANT_Methodref:
  22934. - entry_name = "Methodref";
  22935. - (*merge_cp_p)->method_at_put(*merge_cp_length_p, new_klass_ref_i,
  22936. - new_name_and_type_ref_i);
  22937. - break;
  22938. - default:
  22939. - guarantee(false, "bad switch");
  22940. - break;
  22941. - }
  22942. -
  22943. - if (klass_ref_i != new_klass_ref_i) {
  22944. - RC_TRACE(0x00080000, ("%s entry@%d class_index changed: %d to %d",
  22945. - entry_name, *merge_cp_length_p, klass_ref_i, new_klass_ref_i));
  22946. - }
  22947. - if (name_and_type_ref_i != new_name_and_type_ref_i) {
  22948. - RC_TRACE(0x00080000,
  22949. - ("%s entry@%d name_and_type_index changed: %d to %d",
  22950. - entry_name, *merge_cp_length_p, name_and_type_ref_i,
  22951. - new_name_and_type_ref_i));
  22952. - }
  22953. -
  22954. - if (scratch_i != *merge_cp_length_p) {
  22955. - // The new entry in *merge_cp_p is at a different index than
  22956. - // the new entry in scratch_cp so we need to map the index values.
  22957. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  22958. - }
  22959. - (*merge_cp_length_p)++;
  22960. - } break;
  22961. -
  22962. - // At this stage, Class or UnresolvedClass could be here, but not
  22963. - // ClassIndex
  22964. - case JVM_CONSTANT_ClassIndex: // fall through
  22965. -
  22966. - // Invalid is used as the tag for the second constant pool entry
  22967. - // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
  22968. - // not be seen by itself.
  22969. - case JVM_CONSTANT_Invalid: // fall through
  22970. -
  22971. - // At this stage, String or UnresolvedString could be here, but not
  22972. - // StringIndex
  22973. - case JVM_CONSTANT_StringIndex: // fall through
  22974. -
  22975. - // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
  22976. - // here
  22977. - case JVM_CONSTANT_UnresolvedClassInError: // fall through
  22978. -
  22979. - default:
  22980. - {
  22981. - // leave a breadcrumb
  22982. - jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
  22983. - ShouldNotReachHere();
  22984. - } break;
  22985. - } // end switch tag value
  22986. -} // end append_entry()
  22987. -
  22988. -
  22989. -void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  22990. - typeArrayOop save;
  22991. -
  22992. - save = scratch_class->get_method_annotations_of(i);
  22993. - scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
  22994. - scratch_class->set_method_annotations_of(j, save);
  22995. -
  22996. - save = scratch_class->get_method_parameter_annotations_of(i);
  22997. - scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
  22998. - scratch_class->set_method_parameter_annotations_of(j, save);
  22999. -
  23000. - save = scratch_class->get_method_default_annotations_of(i);
  23001. - scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
  23002. - scratch_class->set_method_default_annotations_of(j, save);
  23003. -}
  23004. -
  23005. -
  23006. -jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  23007. - instanceKlassHandle the_class,
  23008. - instanceKlassHandle scratch_class) {
  23009. +jvmtiError VM_RedefineClasses::check_redefinition_allowed(instanceKlassHandle scratch_class) {
  23010. +
  23011. +
  23012. +
  23013. + // Compatibility mode => check for unsupported modification
  23014. +
  23015. +
  23016. + assert(scratch_class->old_version() != NULL, "must have old version");
  23017. + instanceKlassHandle the_class(scratch_class->old_version());
  23018. +
  23019. int i;
  23020. // Check superclasses, or rather their names, since superclasses themselves can be
  23021. // requested to replace.
  23022. // Check for NULL superclass first since this might be java.lang.Object
  23023. if (the_class->super() != scratch_class->super() &&
  23024. - (the_class->super() == NULL || scratch_class->super() == NULL ||
  23025. - Klass::cast(the_class->super())->name() !=
  23026. - Klass::cast(scratch_class->super())->name())) {
  23027. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  23028. + (the_class->super() == NULL || scratch_class->super() == NULL ||
  23029. + Klass::cast(the_class->super())->name() !=
  23030. + Klass::cast(scratch_class->super())->name())) {
  23031. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  23032. }
  23033. // Check if the number, names and order of directly implemented interfaces are the same.
  23034. @@ -518,8 +640,8 @@
  23035. }
  23036. for (i = 0; i < n_intfs; i++) {
  23037. if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
  23038. - Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  23039. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  23040. + Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  23041. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  23042. }
  23043. }
  23044. @@ -554,10 +676,10 @@
  23045. }
  23046. // offset
  23047. if (k_old_fields->short_at(i + instanceKlass::low_offset) !=
  23048. - k_new_fields->short_at(i + instanceKlass::low_offset) ||
  23049. - k_old_fields->short_at(i + instanceKlass::high_offset) !=
  23050. - k_new_fields->short_at(i + instanceKlass::high_offset)) {
  23051. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED;
  23052. + k_new_fields->short_at(i + instanceKlass::low_offset) ||
  23053. + k_old_fields->short_at(i + instanceKlass::high_offset) !=
  23054. + k_new_fields->short_at(i + instanceKlass::high_offset)) {
  23055. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED;
  23056. }
  23057. // name and signature
  23058. jshort name_index = k_old_fields->short_at(i + instanceKlass::name_index_offset);
  23059. @@ -573,6 +695,7 @@
  23060. }
  23061. }
  23062. +
  23063. // Do a parallel walk through the old and new methods. Detect
  23064. // cases where they match (exist in both), have been added in
  23065. // the new methods, or have been deleted (exist only in the
  23066. @@ -674,12 +797,8 @@
  23067. idnum_owner->set_method_idnum(new_num);
  23068. }
  23069. k_new_method->set_method_idnum(old_num);
  23070. - swap_all_method_annotations(old_num, new_num, scratch_class);
  23071. }
  23072. }
  23073. - RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  23074. - k_new_method->name_and_sig_as_C_string(), ni,
  23075. - k_old_method->name_and_sig_as_C_string(), oi));
  23076. // advance to next pair of methods
  23077. ++oi;
  23078. ++ni;
  23079. @@ -688,11 +807,11 @@
  23080. // method added, see if it is OK
  23081. new_flags = (jushort) k_new_method->access_flags().get_flags();
  23082. if ((new_flags & JVM_ACC_PRIVATE) == 0
  23083. - // hack: private should be treated as final, but alas
  23084. - || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  23085. - ) {
  23086. - // new methods must be private
  23087. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  23088. + // hack: private should be treated as final, but alas
  23089. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  23090. + ) {
  23091. + // new methods must be private
  23092. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  23093. }
  23094. {
  23095. u2 num = the_class->next_method_idnum();
  23096. @@ -707,24 +826,19 @@
  23097. idnum_owner->set_method_idnum(new_num);
  23098. }
  23099. k_new_method->set_method_idnum(num);
  23100. - swap_all_method_annotations(new_num, num, scratch_class);
  23101. }
  23102. - RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  23103. - k_new_method->name_and_sig_as_C_string(), ni));
  23104. ++ni; // advance to next new method
  23105. break;
  23106. case deleted:
  23107. // method deleted, see if it is OK
  23108. old_flags = (jushort) k_old_method->access_flags().get_flags();
  23109. if ((old_flags & JVM_ACC_PRIVATE) == 0
  23110. - // hack: private should be treated as final, but alas
  23111. - || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  23112. - ) {
  23113. - // deleted methods must be private
  23114. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  23115. + // hack: private should be treated as final, but alas
  23116. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  23117. + ) {
  23118. + // deleted methods must be private
  23119. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  23120. }
  23121. - RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  23122. - k_old_method->name_and_sig_as_C_string(), oi));
  23123. ++oi; // advance to next old method
  23124. break;
  23125. default:
  23126. @@ -735,2081 +849,2158 @@
  23127. return JVMTI_ERROR_NONE;
  23128. }
  23129. -
  23130. -// Find new constant pool index value for old constant pool index value
  23131. -// by seaching the index map. Returns zero (0) if there is no mapped
  23132. -// value for the old constant pool index.
  23133. -int VM_RedefineClasses::find_new_index(int old_index) {
  23134. - if (_index_map_count == 0) {
  23135. - // map is empty so nothing can be found
  23136. - return 0;
  23137. +int VM_RedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  23138. +
  23139. + int result = Klass::NoRedefinition;
  23140. +
  23141. +
  23142. +
  23143. + TRACE_RC2("Comparing different class versions of class %s", new_class->name()->as_C_string());
  23144. +
  23145. + assert(new_class->old_version() != NULL, "must have old version");
  23146. + instanceKlassHandle the_class(new_class->old_version());
  23147. +
  23148. + // Check whether class is in the error init state.
  23149. + if (the_class->is_in_error_state()) {
  23150. + // TBD #5057930: special error code is needed in 1.6
  23151. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  23152. }
  23153. - if (old_index < 1 || old_index >= _index_map_p->length()) {
  23154. - // The old_index is out of range so it is not mapped. This should
  23155. - // not happen in regular constant pool merging use, but it can
  23156. - // happen if a corrupt annotation is processed.
  23157. - return 0;
  23158. + int i;
  23159. +
  23160. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  23161. + // Check superclasses
  23162. + assert(new_class->super() == NULL || new_class->super()->klass_part()->is_newest_version(), "");
  23163. + if (the_class->super() != new_class->super()) {
  23164. + // Super class changed
  23165. +
  23166. + klassOop cur_klass = the_class->super();
  23167. + while (cur_klass != NULL) {
  23168. + if (!new_class->is_subclass_of(cur_klass->klass_part()->newest_version())) {
  23169. + TRACE_RC2("Removed super class %s", cur_klass->klass_part()->name()->as_C_string());
  23170. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  23171. +
  23172. + if (!cur_klass->klass_part()->has_subtype_changed()) {
  23173. + TRACE_RC2("Subtype changed of class %s", cur_klass->klass_part()->name()->as_C_string());
  23174. + cur_klass->klass_part()->set_subtype_changed(true);
  23175. + }
  23176. + }
  23177. +
  23178. + cur_klass = cur_klass->klass_part()->super();
  23179. + }
  23180. +
  23181. + cur_klass = new_class->super();
  23182. + while (cur_klass != NULL) {
  23183. + if (!the_class->is_subclass_of(cur_klass->klass_part()->old_version())) {
  23184. + TRACE_RC2("Added super class %s", cur_klass->klass_part()->name()->as_C_string());
  23185. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  23186. + }
  23187. + cur_klass = cur_klass->klass_part()->super();
  23188. + }
  23189. }
  23190. - int value = _index_map_p->at(old_index);
  23191. - if (value == -1) {
  23192. - // the old_index is not mapped
  23193. - return 0;
  23194. - }
  23195. -
  23196. - return value;
  23197. -} // end find_new_index()
  23198. -
  23199. -
  23200. -// Returns true if the current mismatch is due to a resolved/unresolved
  23201. -// class pair. Otherwise, returns false.
  23202. -bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1,
  23203. - int index1, constantPoolHandle cp2, int index2) {
  23204. -
  23205. - jbyte t1 = cp1->tag_at(index1).value();
  23206. - if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {
  23207. - return false; // wrong entry type; not our special case
  23208. - }
  23209. -
  23210. - jbyte t2 = cp2->tag_at(index2).value();
  23211. - if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {
  23212. - return false; // wrong entry type; not our special case
  23213. - }
  23214. -
  23215. - if (t1 == t2) {
  23216. - return false; // not a mismatch; not our special case
  23217. - }
  23218. -
  23219. - char *s1 = cp1->klass_name_at(index1)->as_C_string();
  23220. - char *s2 = cp2->klass_name_at(index2)->as_C_string();
  23221. - if (strcmp(s1, s2) != 0) {
  23222. - return false; // strings don't match; not our special case
  23223. - }
  23224. -
  23225. - return true; // made it through the gauntlet; this is our special case
  23226. -} // end is_unresolved_class_mismatch()
  23227. -
  23228. -
  23229. -// Returns true if the current mismatch is due to a resolved/unresolved
  23230. -// string pair. Otherwise, returns false.
  23231. -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
  23232. - int index1, constantPoolHandle cp2, int index2) {
  23233. -
  23234. - jbyte t1 = cp1->tag_at(index1).value();
  23235. - if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
  23236. - return false; // wrong entry type; not our special case
  23237. - }
  23238. -
  23239. - jbyte t2 = cp2->tag_at(index2).value();
  23240. - if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
  23241. - return false; // wrong entry type; not our special case
  23242. - }
  23243. -
  23244. - if (t1 == t2) {
  23245. - return false; // not a mismatch; not our special case
  23246. - }
  23247. -
  23248. - char *s1 = cp1->string_at_noresolve(index1);
  23249. - char *s2 = cp2->string_at_noresolve(index2);
  23250. - if (strcmp(s1, s2) != 0) {
  23251. - return false; // strings don't match; not our special case
  23252. - }
  23253. -
  23254. - return true; // made it through the gauntlet; this is our special case
  23255. -} // end is_unresolved_string_mismatch()
  23256. -
  23257. -
  23258. -jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  23259. - // For consistency allocate memory using os::malloc wrapper.
  23260. - _scratch_classes = (instanceKlassHandle *)
  23261. - os::malloc(sizeof(instanceKlassHandle) * _class_count);
  23262. - if (_scratch_classes == NULL) {
  23263. - return JVMTI_ERROR_OUT_OF_MEMORY;
  23264. - }
  23265. -
  23266. - ResourceMark rm(THREAD);
  23267. -
  23268. - JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  23269. - // state can only be NULL if the current thread is exiting which
  23270. - // should not happen since we're trying to do a RedefineClasses
  23271. - guarantee(state != NULL, "exiting thread calling load_new_class_versions");
  23272. - for (int i = 0; i < _class_count; i++) {
  23273. - oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  23274. - // classes for primitives cannot be redefined
  23275. - if (!is_modifiable_class(mirror)) {
  23276. - return JVMTI_ERROR_UNMODIFIABLE_CLASS;
  23277. - }
  23278. - klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  23279. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  23280. - symbolHandle the_class_sym = symbolHandle(THREAD, the_class->name());
  23281. -
  23282. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  23283. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  23284. - ("loading name=%s (avail_mem=" UINT64_FORMAT "K)",
  23285. - the_class->external_name(), os::available_memory() >> 10));
  23286. -
  23287. - ClassFileStream st((u1*) _class_defs[i].class_bytes,
  23288. - _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  23289. -
  23290. - // Parse the stream.
  23291. - Handle the_class_loader(THREAD, the_class->class_loader());
  23292. - Handle protection_domain(THREAD, the_class->protection_domain());
  23293. - // Set redefined class handle in JvmtiThreadState class.
  23294. - // This redefined class is sent to agent event handler for class file
  23295. - // load hook event.
  23296. - state->set_class_being_redefined(&the_class, _class_load_kind);
  23297. -
  23298. - klassOop k = SystemDictionary::parse_stream(the_class_sym,
  23299. - the_class_loader,
  23300. - protection_domain,
  23301. - &st,
  23302. - THREAD);
  23303. - // Clear class_being_redefined just to be sure.
  23304. - state->clear_class_being_redefined();
  23305. -
  23306. - // TODO: if this is retransform, and nothing changed we can skip it
  23307. -
  23308. - instanceKlassHandle scratch_class (THREAD, k);
  23309. -
  23310. - if (HAS_PENDING_EXCEPTION) {
  23311. - symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  23312. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  23313. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
  23314. - ex_name->as_C_string()));
  23315. - CLEAR_PENDING_EXCEPTION;
  23316. -
  23317. - if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  23318. - return JVMTI_ERROR_UNSUPPORTED_VERSION;
  23319. - } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  23320. - return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  23321. - } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  23322. - return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  23323. - } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  23324. - // The message will be "XXX (wrong name: YYY)"
  23325. - return JVMTI_ERROR_NAMES_DONT_MATCH;
  23326. - } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  23327. - return JVMTI_ERROR_OUT_OF_MEMORY;
  23328. - } else { // Just in case more exceptions can be thrown..
  23329. - return JVMTI_ERROR_FAILS_VERIFICATION;
  23330. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  23331. + // Check interfaces
  23332. +
  23333. + // Interfaces removed?
  23334. + objArrayOop old_interfaces = the_class->transitive_interfaces();
  23335. + for (i = 0; i<old_interfaces->length(); i++) {
  23336. + instanceKlassHandle old_interface((klassOop)old_interfaces->obj_at(i));
  23337. + if (!new_class->implements_interface_any_version(old_interface())) {
  23338. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  23339. + TRACE_RC2("Removed interface %s", old_interface->name()->as_C_string());
  23340. +
  23341. + if (!old_interface->has_subtype_changed()) {
  23342. + TRACE_RC2("Subtype changed of interface %s", old_interface->name()->as_C_string());
  23343. + old_interface->set_subtype_changed(true);
  23344. }
  23345. }
  23346. -
  23347. - // Ensure class is linked before redefine
  23348. - if (!the_class->is_linked()) {
  23349. - the_class->link_class(THREAD);
  23350. - if (HAS_PENDING_EXCEPTION) {
  23351. - symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  23352. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  23353. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
  23354. - ex_name->as_C_string()));
  23355. - CLEAR_PENDING_EXCEPTION;
  23356. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  23357. - return JVMTI_ERROR_OUT_OF_MEMORY;
  23358. + }
  23359. +
  23360. + // Interfaces added?
  23361. + objArrayOop new_interfaces = new_class->transitive_interfaces();
  23362. + for (i = 0; i<new_interfaces->length(); i++) {
  23363. + if (!the_class->implements_interface_any_version((klassOop)new_interfaces->obj_at(i))) {
  23364. + result = result | Klass::ModifyClass;
  23365. + TRACE_RC2("Added interface %s", ((klassOop)new_interfaces->obj_at(i))->klass_part()->name()->as_C_string());
  23366. + }
  23367. + }
  23368. +
  23369. +
  23370. + // Check whether class modifiers are the same.
  23371. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  23372. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  23373. + if (old_flags != new_flags) {
  23374. + // TODO (tw): Can this have any effects?
  23375. + }
  23376. +
  23377. + // Check if the number, names, types and order of fields declared in these classes
  23378. + // are the same.
  23379. + typeArrayOop k_old_fields = the_class->fields();
  23380. + typeArrayOop k_new_fields = new_class->fields();
  23381. + int n_fields = k_old_fields->length();
  23382. + if (n_fields != k_new_fields->length()) {
  23383. + result = result | Klass::ModifyInstances;
  23384. + } else {
  23385. + for (i = 0; i < n_fields; i += instanceKlass::next_offset) {
  23386. + // access
  23387. + old_flags = k_old_fields->ushort_at(i + instanceKlass::access_flags_offset);
  23388. + new_flags = k_new_fields->ushort_at(i + instanceKlass::access_flags_offset);
  23389. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  23390. + // (tw) Can this have any effects?
  23391. + }
  23392. + // offset
  23393. + if (k_old_fields->short_at(i + instanceKlass::low_offset) !=
  23394. + k_new_fields->short_at(i + instanceKlass::low_offset) ||
  23395. + k_old_fields->short_at(i + instanceKlass::high_offset) !=
  23396. + k_new_fields->short_at(i + instanceKlass::high_offset)) {
  23397. + result = result | Klass::ModifyInstances;
  23398. + }
  23399. + // name and signature
  23400. + jshort name_index = k_old_fields->short_at(i + instanceKlass::name_index_offset);
  23401. + jshort sig_index = k_old_fields->short_at(i +instanceKlass::signature_index_offset);
  23402. + symbolOop name_sym1 = the_class->constants()->symbol_at(name_index);
  23403. + symbolOop sig_sym1 = the_class->constants()->symbol_at(sig_index);
  23404. + name_index = k_new_fields->short_at(i + instanceKlass::name_index_offset);
  23405. + sig_index = k_new_fields->short_at(i + instanceKlass::signature_index_offset);
  23406. + symbolOop name_sym2 = new_class->constants()->symbol_at(name_index);
  23407. + symbolOop sig_sym2 = new_class->constants()->symbol_at(sig_index);
  23408. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  23409. + result = result | Klass::ModifyInstances;
  23410. + }
  23411. + }
  23412. + }
  23413. +
  23414. + // Do a parallel walk through the old and new methods. Detect
  23415. + // cases where they match (exist in both), have been added in
  23416. + // the new methods, or have been deleted (exist only in the
  23417. + // old methods). The class file parser places methods in order
  23418. + // by method name, but does not order overloaded methods by
  23419. + // signature. In order to determine what fate befell the methods,
  23420. + // this code places the overloaded new methods that have matching
  23421. + // old methods in the same order as the old methods and places
  23422. + // new overloaded methods at the end of overloaded methods of
  23423. + // that name. The code for this order normalization is adapted
  23424. + // from the algorithm used in instanceKlass::find_method().
  23425. + // Since we are swapping out of order entries as we find them,
  23426. + // we only have to search forward through the overloaded methods.
  23427. + // Methods which are added and have the same name as an existing
  23428. + // method (but different signature) will be put at the end of
  23429. + // the methods with that name, and the name mismatch code will
  23430. + // handle them.
  23431. + objArrayHandle k_old_methods(the_class->methods());
  23432. + objArrayHandle k_new_methods(new_class->methods());
  23433. + int n_old_methods = k_old_methods->length();
  23434. + int n_new_methods = k_new_methods->length();
  23435. +
  23436. + int ni = 0;
  23437. + int oi = 0;
  23438. + while (true) {
  23439. + methodOop k_old_method;
  23440. + methodOop k_new_method;
  23441. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  23442. +
  23443. + if (oi >= n_old_methods) {
  23444. + if (ni >= n_new_methods) {
  23445. + break; // we've looked at everything, done
  23446. + }
  23447. + // New method at the end
  23448. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  23449. + method_was = added;
  23450. + } else if (ni >= n_new_methods) {
  23451. + // Old method, at the end, is deleted
  23452. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  23453. + method_was = deleted;
  23454. + } else {
  23455. + // There are more methods in both the old and new lists
  23456. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  23457. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  23458. + if (k_old_method->name() != k_new_method->name()) {
  23459. + // Methods are sorted by method name, so a mismatch means added
  23460. + // or deleted
  23461. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  23462. + method_was = added;
  23463. } else {
  23464. - return JVMTI_ERROR_INTERNAL;
  23465. + method_was = deleted;
  23466. + }
  23467. + } else if (k_old_method->signature() == k_new_method->signature()) {
  23468. + // Both the name and signature match
  23469. + method_was = matched;
  23470. + } else {
  23471. + // The name matches, but the signature doesn't, which means we have to
  23472. + // search forward through the new overloaded methods.
  23473. + int nj; // outside the loop for post-loop check
  23474. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  23475. + methodOop m = (methodOop)k_new_methods->obj_at(nj);
  23476. + if (k_old_method->name() != m->name()) {
  23477. + // reached another method name so no more overloaded methods
  23478. + method_was = deleted;
  23479. + break;
  23480. + }
  23481. + if (k_old_method->signature() == m->signature()) {
  23482. + // found a match so swap the methods
  23483. + k_new_methods->obj_at_put(ni, m);
  23484. + k_new_methods->obj_at_put(nj, k_new_method);
  23485. + k_new_method = m;
  23486. + method_was = matched;
  23487. + break;
  23488. + }
  23489. + }
  23490. +
  23491. + if (nj >= n_new_methods) {
  23492. + // reached the end without a match; so method was deleted
  23493. + method_was = deleted;
  23494. }
  23495. }
  23496. }
  23497. - // Do the validity checks in compare_and_normalize_class_versions()
  23498. - // before verifying the byte codes. By doing these checks first, we
  23499. - // limit the number of functions that require redirection from
  23500. - // the_class to scratch_class. In particular, we don't have to
  23501. - // modify JNI GetSuperclass() and thus won't change its performance.
  23502. - jvmtiError res = compare_and_normalize_class_versions(the_class,
  23503. - scratch_class);
  23504. - if (res != JVMTI_ERROR_NONE) {
  23505. - return res;
  23506. + switch (method_was) {
  23507. + case matched:
  23508. + // methods match, be sure modifiers do too
  23509. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  23510. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  23511. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  23512. + // (tw) Can this have any effects? Probably yes on vtables?
  23513. + result = result | Klass::ModifyClass;
  23514. }
  23515. -
  23516. - // verify what the caller passed us
  23517. {
  23518. - // The bug 6214132 caused the verification to fail.
  23519. - // Information about the_class and scratch_class is temporarily
  23520. - // recorded into jvmtiThreadState. This data is used to redirect
  23521. - // the_class to scratch_class in the JVM_* functions called by the
  23522. - // verifier. Please, refer to jvmtiThreadState.hpp for the detailed
  23523. - // description.
  23524. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  23525. - Verifier::verify(
  23526. - scratch_class, Verifier::ThrowException, true, THREAD);
  23527. - }
  23528. -
  23529. - if (HAS_PENDING_EXCEPTION) {
  23530. - symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  23531. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  23532. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  23533. - ("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
  23534. - CLEAR_PENDING_EXCEPTION;
  23535. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  23536. - return JVMTI_ERROR_OUT_OF_MEMORY;
  23537. - } else {
  23538. - // tell the caller the bytecodes are bad
  23539. - return JVMTI_ERROR_FAILS_VERIFICATION;
  23540. + u2 new_num = k_new_method->method_idnum();
  23541. + u2 old_num = k_old_method->method_idnum();
  23542. + if (new_num != old_num) {
  23543. + methodOop idnum_owner = new_class->method_with_idnum(old_num);
  23544. + if (idnum_owner != NULL) {
  23545. + // There is already a method assigned this idnum -- switch them
  23546. + idnum_owner->set_method_idnum(new_num);
  23547. + }
  23548. + k_new_method->set_method_idnum(old_num);
  23549. + TRACE_RC2("swapping idnum of new and old method %d / %d!", new_num, old_num);
  23550. + // swap_all_method_annotations(old_num, new_num, new_class);
  23551. }
  23552. }
  23553. -
  23554. - res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
  23555. - if (res != JVMTI_ERROR_NONE) {
  23556. - return res;
  23557. + TRACE_RC3("Method matched: new: %s [%d] == old: %s [%d]",
  23558. + k_new_method->name_and_sig_as_C_string(), ni,
  23559. + k_old_method->name_and_sig_as_C_string(), oi);
  23560. + // advance to next pair of methods
  23561. + ++oi;
  23562. + ++ni;
  23563. + break;
  23564. + case added:
  23565. + // method added, see if it is OK
  23566. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  23567. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  23568. + // hack: private should be treated as final, but alas
  23569. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  23570. + ) {
  23571. + // new methods must be private
  23572. + result = result | Klass::ModifyClass;
  23573. }
  23574. -
  23575. - if (VerifyMergedCPBytecodes) {
  23576. - // verify what we have done during constant pool merging
  23577. - {
  23578. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  23579. - Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
  23580. + {
  23581. + u2 num = the_class->next_method_idnum();
  23582. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  23583. + // cannot add any more methods
  23584. + result = result | Klass::ModifyClass;
  23585. }
  23586. -
  23587. - if (HAS_PENDING_EXCEPTION) {
  23588. - symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  23589. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  23590. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  23591. - ("verify_byte_codes post merge-CP exception: '%s'",
  23592. - ex_name->as_C_string()));
  23593. - CLEAR_PENDING_EXCEPTION;
  23594. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  23595. - return JVMTI_ERROR_OUT_OF_MEMORY;
  23596. - } else {
  23597. - // tell the caller that constant pool merging screwed up
  23598. - return JVMTI_ERROR_INTERNAL;
  23599. + u2 new_num = k_new_method->method_idnum();
  23600. + methodOop idnum_owner = new_class->method_with_idnum(num);
  23601. + if (idnum_owner != NULL) {
  23602. + // There is already a method assigned this idnum -- switch them
  23603. + idnum_owner->set_method_idnum(new_num);
  23604. + }
  23605. + k_new_method->set_method_idnum(num);
  23606. + //swap_all_method_annotations(new_num, num, new_class);
  23607. + }
  23608. + TRACE_RC1("Method added: new: %s [%d]",
  23609. + k_new_method->name_and_sig_as_C_string(), ni);
  23610. + ++ni; // advance to next new method
  23611. + break;
  23612. + case deleted:
  23613. + // method deleted, see if it is OK
  23614. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  23615. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  23616. + // hack: private should be treated as final, but alas
  23617. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  23618. + ) {
  23619. + // deleted methods must be private
  23620. + result = result | Klass::ModifyClass;
  23621. + }
  23622. + TRACE_RC1("Method deleted: old: %s [%d]",
  23623. + k_old_method->name_and_sig_as_C_string(), oi);
  23624. + ++oi; // advance to next old method
  23625. + break;
  23626. + default:
  23627. + ShouldNotReachHere();
  23628. + }
  23629. + }
  23630. +
  23631. + if (new_class()->size() != new_class->old_version()->size()) {
  23632. + result |= Klass::ModifyClassSize;
  23633. + }
  23634. +
  23635. + if (new_class->size_helper() != ((instanceKlass*)(new_class->old_version()->klass_part()))->size_helper()) {
  23636. + result |= Klass::ModifyInstanceSize;
  23637. + }
  23638. +
  23639. + methodHandle instanceTransformerMethod(new_class->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature()));
  23640. + if (!instanceTransformerMethod.is_null() && !instanceTransformerMethod->is_static()) {
  23641. + result |= Klass::HasInstanceTransformer;
  23642. + }
  23643. +
  23644. + // (tw) Check method bodies to be able to return NoChange?
  23645. + return result;
  23646. +}
  23647. +
  23648. +void VM_RedefineClasses::calculate_instance_update_information(klassOop new_version) {
  23649. +
  23650. + class UpdateFieldsEvolutionClosure : public FieldEvolutionClosure {
  23651. +
  23652. + private:
  23653. +
  23654. + GrowableArray<int> info;
  23655. + int curPosition;
  23656. + bool copy_backwards;
  23657. +
  23658. + public:
  23659. +
  23660. + bool does_copy_backwards() {
  23661. + return copy_backwards;
  23662. + }
  23663. +
  23664. + UpdateFieldsEvolutionClosure(klassOop klass) {
  23665. +
  23666. + int base_offset = instanceOopDesc::base_offset_in_bytes();
  23667. +
  23668. + if (klass->klass_part()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version()) {
  23669. + base_offset += java_lang_Class::number_of_fake_oop_fields*size_of_type(T_OBJECT);
  23670. + }
  23671. +
  23672. + info.append(base_offset);
  23673. + info.append(0);
  23674. + curPosition = base_offset;
  23675. + copy_backwards = false;
  23676. + }
  23677. +
  23678. + GrowableArray<int> &finish() {
  23679. + info.append(0);
  23680. + return info;
  23681. + }
  23682. +
  23683. + virtual void do_new_field(fieldDescriptor* fd){
  23684. + int size = size_of_type(fd->field_type());
  23685. + fill(size);
  23686. + }
  23687. +
  23688. + private:
  23689. +
  23690. + void fill(int size) {
  23691. + if (info.length() > 0 && info.at(info.length() - 1) < 0) {
  23692. + (*info.adr_at(info.length() - 1)) -= size;
  23693. + } else {
  23694. + info.append(-size);
  23695. + }
  23696. +
  23697. + curPosition += size;
  23698. + }
  23699. +
  23700. + int size_of_type(BasicType type) {
  23701. + int size = 0;
  23702. + switch(type) {
  23703. + case T_BOOLEAN:
  23704. + size = sizeof(jboolean);
  23705. + break;
  23706. +
  23707. + case T_CHAR:
  23708. + size = (sizeof(jchar));
  23709. + break;
  23710. +
  23711. + case T_FLOAT:
  23712. + size = (sizeof(jfloat));
  23713. + break;
  23714. +
  23715. + case T_DOUBLE:
  23716. + size = (sizeof(jdouble));
  23717. + break;
  23718. +
  23719. + case T_BYTE:
  23720. + size = (sizeof(jbyte));
  23721. + break;
  23722. +
  23723. + case T_SHORT:
  23724. + size = (sizeof(jshort));
  23725. + break;
  23726. +
  23727. + case T_INT:
  23728. + size = (sizeof(jint));
  23729. + break;
  23730. +
  23731. + case T_LONG:
  23732. + size = (sizeof(jlong));
  23733. + break;
  23734. +
  23735. + case T_OBJECT:
  23736. + case T_ARRAY:
  23737. + if (UseCompressedOops) {
  23738. + size = sizeof(narrowOop);
  23739. + } else {
  23740. + size = (sizeof(oop));
  23741. + }
  23742. + break;
  23743. +
  23744. + default:
  23745. + ShouldNotReachHere();
  23746. + }
  23747. +
  23748. + assert(size > 0, "");
  23749. + return size;
  23750. +
  23751. + }
  23752. +
  23753. + public:
  23754. +
  23755. + virtual void do_old_field(fieldDescriptor* fd){}
  23756. +
  23757. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd){
  23758. +
  23759. + int alignment = new_fd->offset() - curPosition;
  23760. + if (alignment > 0) {
  23761. + // This field was aligned, so we need to make sure that we fill the gap
  23762. + fill(alignment);
  23763. + }
  23764. +
  23765. + assert(old_fd->field_type() == new_fd->field_type(), "");
  23766. + assert(curPosition == new_fd->offset(), "must be correct offset!");
  23767. +
  23768. + int offset = old_fd->offset();
  23769. + int size = size_of_type(old_fd->field_type());
  23770. +
  23771. + int prevEnd = -1;
  23772. + if (info.length() > 0 && info.at(info.length() - 1) > 0) {
  23773. + prevEnd = info.at(info.length() - 2) + info.at(info.length() - 1);
  23774. + }
  23775. +
  23776. + if (prevEnd == offset) {
  23777. + info.at_put(info.length() - 2, info.at(info.length() - 2) + size);
  23778. + } else {
  23779. + info.append(size);
  23780. + info.append(offset);
  23781. + }
  23782. +
  23783. + if (old_fd->offset() < new_fd->offset()) {
  23784. + copy_backwards = true;
  23785. + }
  23786. +
  23787. + transfer_special_access_flags(old_fd, new_fd);
  23788. +
  23789. + curPosition += size;
  23790. + }
  23791. + };
  23792. +
  23793. + UpdateFieldsEvolutionClosure cl(new_version);
  23794. + ((instanceKlass*)new_version->klass_part())->do_fields_evolution(&cl);
  23795. +
  23796. + GrowableArray<int> result = cl.finish();
  23797. + ((instanceKlass*)new_version->klass_part())->store_update_information(result);
  23798. + ((instanceKlass*)new_version->klass_part())->set_copying_backwards(cl.does_copy_backwards());
  23799. +
  23800. + IF_TRACE_RC2 {
  23801. + TRACE_RC2("Instance update information for %s:", new_version->klass_part()->name()->as_C_string());
  23802. + if (cl.does_copy_backwards()) {
  23803. + TRACE_RC2("\tDoes copy backwards!");
  23804. + }
  23805. + for (int i=0; i<result.length(); i++) {
  23806. + int curNum = result.at(i);
  23807. + if (curNum < 0) {
  23808. + TRACE_RC2("\t%d CLEAN", curNum);
  23809. + } else if (curNum > 0) {
  23810. + TRACE_RC2("\t%d COPY from %d", curNum, result.at(i + 1));
  23811. + i++;
  23812. + } else {
  23813. + TRACE_RC2("\tEND");
  23814. + }
  23815. + }
  23816. + }
  23817. +}
  23818. +
  23819. +symbolOop VM_RedefineClasses::signature_to_class_name(symbolOop signature) {
  23820. + assert(FieldType::is_obj(signature), "");
  23821. + return oopFactory::new_symbol_handle(signature->as_C_string() + 1, signature->utf8_length() - 2, Thread::current())();
  23822. +}
  23823. +
  23824. +void VM_RedefineClasses::calculate_type_check_information() {
  23825. + class MarkAffectedClassesClosure : public ObjectClosure {
  23826. +
  23827. + virtual void do_object(oop obj) {
  23828. + klassOop klass = (klassOop)obj;
  23829. +
  23830. + if (klass->klass_part()->is_redefining()) {
  23831. + klass = klass->klass_part()->old_version();
  23832. + }
  23833. +
  23834. + // We found an instance klass!
  23835. + instanceKlass *cur_instance_klass = instanceKlass::cast(klass);
  23836. + GrowableArray< Pair<int, klassOop> > type_check_information;
  23837. +
  23838. + class MyFieldClosure : public FieldClosure {
  23839. +
  23840. + public:
  23841. +
  23842. + GrowableArray< Pair<int, klassOop> > *_arr;
  23843. +
  23844. + MyFieldClosure(GrowableArray< Pair<int, klassOop> > *arr) {
  23845. + _arr = arr;
  23846. + }
  23847. +
  23848. + virtual void do_field(fieldDescriptor* fd) {
  23849. + if (fd->field_type() == T_OBJECT) {
  23850. + symbolOop signature = fd->signature();
  23851. + if (FieldType::is_obj(signature)) {
  23852. + symbolHandle name = signature_to_class_name(signature);
  23853. + klassOop field_klass;
  23854. + if (is_field_dangerous(name, fd, field_klass)) {
  23855. + TRACE_RC2("Found dangerous field %s in klass %s of type %s", fd->name()->as_C_string(), fd->field_holder()->klass_part()->name()->as_C_string(), name->as_C_string());
  23856. + _arr->append(Pair<int, klassOop>(fd->offset(), field_klass->klass_part()->newest_version()));
  23857. + }
  23858. + }
  23859. +
  23860. + // Array fields can never be a problem!
  23861. + }
  23862. + }
  23863. +
  23864. + bool is_field_dangerous(symbolHandle klass_name, fieldDescriptor *fd, klassOop &field_klass) {
  23865. + field_klass = SystemDictionary::find(klass_name, fd->field_holder()->klass_part()->class_loader(), fd->field_holder()->klass_part()->protection_domain(), Thread::current());
  23866. + if(field_klass != NULL) {
  23867. + if (field_klass->klass_part()->is_redefining()) {
  23868. + field_klass = field_klass->klass_part()->old_version();
  23869. + }
  23870. + if (field_klass->klass_part()->has_subtype_changed()) {
  23871. + return true;
  23872. + }
  23873. + }
  23874. + return false;
  23875. + }
  23876. + };
  23877. +
  23878. + MyFieldClosure fieldClosure(&type_check_information);
  23879. + cur_instance_klass->do_nonstatic_fields(&fieldClosure);
  23880. +
  23881. + if (type_check_information.length() > 0) {
  23882. + type_check_information.append(Pair<int, klassOop>(-1, NULL));
  23883. + cur_instance_klass->store_type_check_information(type_check_information);
  23884. + }
  23885. + }
  23886. + };
  23887. +
  23888. + MarkAffectedClassesClosure markAffectedClassesClosure;
  23889. + SystemDictionary::classes_do(&markAffectedClassesClosure);
  23890. +}
  23891. +
  23892. +bool VM_RedefineClasses::check_field_value_types() {
  23893. +
  23894. + Thread *THREAD = Thread::current();
  23895. + class CheckFieldTypesClosure : public ObjectClosure {
  23896. +
  23897. + private:
  23898. +
  23899. + bool _result;
  23900. +
  23901. + public:
  23902. +
  23903. + CheckFieldTypesClosure() {
  23904. + _result = true;
  23905. + }
  23906. +
  23907. + bool result() { return _result; }
  23908. +
  23909. + virtual void do_object(oop obj) {
  23910. +
  23911. + if (!_result) {
  23912. + return;
  23913. + }
  23914. +
  23915. + if (obj->is_objArray()) {
  23916. +
  23917. + objArrayOop array = objArrayOop(obj);
  23918. +
  23919. + klassOop element_klass = objArrayKlass::cast(array->klass())->element_klass();
  23920. +
  23921. + if (element_klass->klass_part()->has_subtype_changed()) {
  23922. + int length = array->length();
  23923. + for (int i=0; i<length; i++) {
  23924. + oop element = array->obj_at(i);
  23925. + if (element != NULL && element->blueprint()->newest_version()->klass_part()->is_redefining()) {
  23926. + // Check subtype relationship to static type of array
  23927. + if (!element->blueprint()->newest_version()->klass_part()->is_subtype_of(element_klass->klass_part()->newest_version())) {
  23928. + TRACE_RC1("Array value is INVALID - abort redefinition (static_type=%s, index=%d, dynamic_type=%s)", element_klass->klass_part()->name()->as_C_string(), i, element->blueprint()->name()->as_C_string());
  23929. + _result = false;
  23930. + break;
  23931. + }
  23932. + }
  23933. + }
  23934. + }
  23935. +
  23936. + } else {
  23937. + Pair<int, klassOop> *cur = obj->klass()->klass_part()->type_check_information();
  23938. + if (cur != NULL) {
  23939. + // Type check information exists for this oop
  23940. + while ((*cur).left() != -1) {
  23941. + check_field(obj, (*cur).left(), (*cur).right());
  23942. + cur++;
  23943. + }
  23944. }
  23945. }
  23946. }
  23947. - Rewriter::rewrite(scratch_class, THREAD);
  23948. - if (HAS_PENDING_EXCEPTION) {
  23949. - symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  23950. - CLEAR_PENDING_EXCEPTION;
  23951. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  23952. - return JVMTI_ERROR_OUT_OF_MEMORY;
  23953. - } else {
  23954. - return JVMTI_ERROR_INTERNAL;
  23955. - }
  23956. - }
  23957. -
  23958. - _scratch_classes[i] = scratch_class;
  23959. -
  23960. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  23961. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  23962. - ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
  23963. - the_class->external_name(), os::available_memory() >> 10));
  23964. - }
  23965. -
  23966. - return JVMTI_ERROR_NONE;
  23967. -}
  23968. -
  23969. -
  23970. -// Map old_index to new_index as needed. scratch_cp is only needed
  23971. -// for RC_TRACE() calls.
  23972. -void VM_RedefineClasses::map_index(constantPoolHandle scratch_cp,
  23973. - int old_index, int new_index) {
  23974. - if (find_new_index(old_index) != 0) {
  23975. - // old_index is already mapped
  23976. - return;
  23977. - }
  23978. -
  23979. - if (old_index == new_index) {
  23980. - // no mapping is needed
  23981. - return;
  23982. - }
  23983. -
  23984. - _index_map_p->at_put(old_index, new_index);
  23985. - _index_map_count++;
  23986. -
  23987. - RC_TRACE(0x00040000, ("mapped tag %d at index %d to %d",
  23988. - scratch_cp->tag_at(old_index).value(), old_index, new_index));
  23989. -} // end map_index()
  23990. -
  23991. -
  23992. -// Merge old_cp and scratch_cp and return the results of the merge via
  23993. -// merge_cp_p. The number of entries in *merge_cp_p is returned via
  23994. -// merge_cp_length_p. The entries in old_cp occupy the same locations
  23995. -// in *merge_cp_p. Also creates a map of indices from entries in
  23996. -// scratch_cp to the corresponding entry in *merge_cp_p. Index map
  23997. -// entries are only created for entries in scratch_cp that occupy a
  23998. -// different location in *merged_cp_p.
  23999. -bool VM_RedefineClasses::merge_constant_pools(constantPoolHandle old_cp,
  24000. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  24001. - int *merge_cp_length_p, TRAPS) {
  24002. -
  24003. - if (merge_cp_p == NULL) {
  24004. - assert(false, "caller must provide scatch constantPool");
  24005. - return false; // robustness
  24006. - }
  24007. - if (merge_cp_length_p == NULL) {
  24008. - assert(false, "caller must provide scatch CP length");
  24009. - return false; // robustness
  24010. - }
  24011. - // Worst case we need old_cp->length() + scratch_cp()->length(),
  24012. - // but the caller might be smart so make sure we have at least
  24013. - // the minimum.
  24014. - if ((*merge_cp_p)->length() < old_cp->length()) {
  24015. - assert(false, "merge area too small");
  24016. - return false; // robustness
  24017. - }
  24018. -
  24019. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  24020. - ("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(),
  24021. - scratch_cp->length()));
  24022. -
  24023. - {
  24024. - // Pass 0:
  24025. - // The old_cp is copied to *merge_cp_p; this means that any code
  24026. - // using old_cp does not have to change. This work looks like a
  24027. - // perfect fit for constantPoolOop::copy_cp_to(), but we need to
  24028. - // handle one special case:
  24029. - // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
  24030. - // This will make verification happy.
  24031. -
  24032. - int old_i; // index into old_cp
  24033. -
  24034. - // index zero (0) is not used in constantPools
  24035. - for (old_i = 1; old_i < old_cp->length(); old_i++) {
  24036. - // leave debugging crumb
  24037. - jbyte old_tag = old_cp->tag_at(old_i).value();
  24038. - switch (old_tag) {
  24039. - case JVM_CONSTANT_Class:
  24040. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  24041. - (*merge_cp_p)->unresolved_klass_at_put(old_i,
  24042. - old_cp->klass_name_at(old_i));
  24043. - break;
  24044. -
  24045. - case JVM_CONSTANT_Double:
  24046. - case JVM_CONSTANT_Long:
  24047. - // just copy the entry to *merge_cp_p, but double and long take
  24048. - // two constant pool entries
  24049. - old_cp->copy_entry_to(old_i, *merge_cp_p, old_i, CHECK_0);
  24050. - old_i++;
  24051. - break;
  24052. -
  24053. - default:
  24054. - // just copy the entry to *merge_cp_p
  24055. - old_cp->copy_entry_to(old_i, *merge_cp_p, old_i, CHECK_0);
  24056. - break;
  24057. - }
  24058. - } // end for each old_cp entry
  24059. -
  24060. - // We don't need to sanity check that *merge_cp_length_p is within
  24061. - // *merge_cp_p bounds since we have the minimum on-entry check above.
  24062. - (*merge_cp_length_p) = old_i;
  24063. - }
  24064. -
  24065. - // merge_cp_len should be the same as old_cp->length() at this point
  24066. - // so this trace message is really a "warm-and-breathing" message.
  24067. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  24068. - ("after pass 0: merge_cp_len=%d", *merge_cp_length_p));
  24069. -
  24070. - int scratch_i; // index into scratch_cp
  24071. - {
  24072. - // Pass 1a:
  24073. - // Compare scratch_cp entries to the old_cp entries that we have
  24074. - // already copied to *merge_cp_p. In this pass, we are eliminating
  24075. - // exact duplicates (matching entry at same index) so we only
  24076. - // compare entries in the common indice range.
  24077. - int increment = 1;
  24078. - int pass1a_length = MIN2(old_cp->length(), scratch_cp->length());
  24079. - for (scratch_i = 1; scratch_i < pass1a_length; scratch_i += increment) {
  24080. - switch (scratch_cp->tag_at(scratch_i).value()) {
  24081. - case JVM_CONSTANT_Double:
  24082. - case JVM_CONSTANT_Long:
  24083. - // double and long take two constant pool entries
  24084. - increment = 2;
  24085. - break;
  24086. -
  24087. - default:
  24088. - increment = 1;
  24089. - break;
  24090. - }
  24091. -
  24092. - bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p,
  24093. - scratch_i, CHECK_0);
  24094. - if (match) {
  24095. - // found a match at the same index so nothing more to do
  24096. - continue;
  24097. - } else if (is_unresolved_class_mismatch(scratch_cp, scratch_i,
  24098. - *merge_cp_p, scratch_i)) {
  24099. - // The mismatch in compare_entry_to() above is because of a
  24100. - // resolved versus unresolved class entry at the same index
  24101. - // with the same string value. Since Pass 0 reverted any
  24102. - // class entries to unresolved class entries in *merge_cp_p,
  24103. - // we go with the unresolved class entry.
  24104. - continue;
  24105. - } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
  24106. - *merge_cp_p, scratch_i)) {
  24107. - // The mismatch in compare_entry_to() above is because of a
  24108. - // resolved versus unresolved string entry at the same index
  24109. - // with the same string value. We can live with whichever
  24110. - // happens to be at scratch_i in *merge_cp_p.
  24111. - continue;
  24112. - }
  24113. -
  24114. - int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
  24115. - CHECK_0);
  24116. - if (found_i != 0) {
  24117. - guarantee(found_i != scratch_i,
  24118. - "compare_entry_to() and find_matching_entry() do not agree");
  24119. -
  24120. - // Found a matching entry somewhere else in *merge_cp_p so
  24121. - // just need a mapping entry.
  24122. - map_index(scratch_cp, scratch_i, found_i);
  24123. - continue;
  24124. - }
  24125. -
  24126. - // The find_matching_entry() call above could fail to find a match
  24127. - // due to a resolved versus unresolved class or string entry situation
  24128. - // like we solved above with the is_unresolved_*_mismatch() calls.
  24129. - // However, we would have to call is_unresolved_*_mismatch() over
  24130. - // all of *merge_cp_p (potentially) and that doesn't seem to be
  24131. - // worth the time.
  24132. -
  24133. - // No match found so we have to append this entry and any unique
  24134. - // referenced entries to *merge_cp_p.
  24135. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  24136. - CHECK_0);
  24137. - }
  24138. - }
  24139. -
  24140. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  24141. - ("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  24142. - *merge_cp_length_p, scratch_i, _index_map_count));
  24143. -
  24144. - if (scratch_i < scratch_cp->length()) {
  24145. - // Pass 1b:
  24146. - // old_cp is smaller than scratch_cp so there are entries in
  24147. - // scratch_cp that we have not yet processed. We take care of
  24148. - // those now.
  24149. - int increment = 1;
  24150. - for (; scratch_i < scratch_cp->length(); scratch_i += increment) {
  24151. - switch (scratch_cp->tag_at(scratch_i).value()) {
  24152. - case JVM_CONSTANT_Double:
  24153. - case JVM_CONSTANT_Long:
  24154. - // double and long take two constant pool entries
  24155. - increment = 2;
  24156. - break;
  24157. -
  24158. - default:
  24159. - increment = 1;
  24160. - break;
  24161. - }
  24162. -
  24163. - int found_i =
  24164. - scratch_cp->find_matching_entry(scratch_i, *merge_cp_p, CHECK_0);
  24165. - if (found_i != 0) {
  24166. - // Found a matching entry somewhere else in *merge_cp_p so
  24167. - // just need a mapping entry.
  24168. - map_index(scratch_cp, scratch_i, found_i);
  24169. - continue;
  24170. - }
  24171. -
  24172. - // No match found so we have to append this entry and any unique
  24173. - // referenced entries to *merge_cp_p.
  24174. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  24175. - CHECK_0);
  24176. - }
  24177. -
  24178. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  24179. - ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  24180. - *merge_cp_length_p, scratch_i, _index_map_count));
  24181. - }
  24182. -
  24183. - return true;
  24184. -} // end merge_constant_pools()
  24185. -
  24186. -
  24187. -// Merge constant pools between the_class and scratch_class and
  24188. -// potentially rewrite bytecodes in scratch_class to use the merged
  24189. -// constant pool.
  24190. -jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
  24191. - instanceKlassHandle the_class, instanceKlassHandle scratch_class,
  24192. - TRAPS) {
  24193. - // worst case merged constant pool length is old and new combined
  24194. - int merge_cp_length = the_class->constants()->length()
  24195. - + scratch_class->constants()->length();
  24196. -
  24197. - constantPoolHandle old_cp(THREAD, the_class->constants());
  24198. - constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  24199. -
  24200. - // Constant pools are not easily reused so we allocate a new one
  24201. - // each time.
  24202. - // merge_cp is created unsafe for concurrent GC processing. It
  24203. - // should be marked safe before discarding it because, even if
  24204. - // garbage. If it crosses a card boundary, it may be scanned
  24205. - // in order to find the start of the first complete object on the card.
  24206. - constantPoolHandle merge_cp(THREAD,
  24207. - oopFactory::new_constantPool(merge_cp_length,
  24208. - methodOopDesc::IsUnsafeConc,
  24209. - THREAD));
  24210. - int orig_length = old_cp->orig_length();
  24211. - if (orig_length == 0) {
  24212. - // This old_cp is an actual original constant pool. We save
  24213. - // the original length in the merged constant pool so that
  24214. - // merge_constant_pools() can be more efficient. If a constant
  24215. - // pool has a non-zero orig_length() value, then that constant
  24216. - // pool was created by a merge operation in RedefineClasses.
  24217. - merge_cp->set_orig_length(old_cp->length());
  24218. - } else {
  24219. - // This old_cp is a merged constant pool from a previous
  24220. - // RedefineClasses() calls so just copy the orig_length()
  24221. - // value.
  24222. - merge_cp->set_orig_length(old_cp->orig_length());
  24223. - }
  24224. -
  24225. - ResourceMark rm(THREAD);
  24226. - _index_map_count = 0;
  24227. - _index_map_p = new intArray(scratch_cp->length(), -1);
  24228. -
  24229. - bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
  24230. - &merge_cp_length, THREAD);
  24231. - if (!result) {
  24232. - // The merge can fail due to memory allocation failure or due
  24233. - // to robustness checks.
  24234. - return JVMTI_ERROR_INTERNAL;
  24235. - }
  24236. -
  24237. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  24238. - ("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count));
  24239. -
  24240. - if (_index_map_count == 0) {
  24241. - // there is nothing to map between the new and merged constant pools
  24242. -
  24243. - if (old_cp->length() == scratch_cp->length()) {
  24244. - // The old and new constant pools are the same length and the
  24245. - // index map is empty. This means that the three constant pools
  24246. - // are equivalent (but not the same). Unfortunately, the new
  24247. - // constant pool has not gone through link resolution nor have
  24248. - // the new class bytecodes gone through constant pool cache
  24249. - // rewriting so we can't use the old constant pool with the new
  24250. - // class.
  24251. -
  24252. - merge_cp()->set_is_conc_safe(true);
  24253. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  24254. - } else if (old_cp->length() < scratch_cp->length()) {
  24255. - // The old constant pool has fewer entries than the new constant
  24256. - // pool and the index map is empty. This means the new constant
  24257. - // pool is a superset of the old constant pool. However, the old
  24258. - // class bytecodes have already gone through constant pool cache
  24259. - // rewriting so we can't use the new constant pool with the old
  24260. - // class.
  24261. -
  24262. - merge_cp()->set_is_conc_safe(true);
  24263. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  24264. - } else {
  24265. - // The old constant pool has more entries than the new constant
  24266. - // pool and the index map is empty. This means that both the old
  24267. - // and merged constant pools are supersets of the new constant
  24268. - // pool.
  24269. -
  24270. - // Replace the new constant pool with a shrunken copy of the
  24271. - // merged constant pool; the previous new constant pool will
  24272. - // get GCed.
  24273. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  24274. - THREAD);
  24275. - // drop local ref to the merged constant pool
  24276. - merge_cp()->set_is_conc_safe(true);
  24277. - merge_cp = constantPoolHandle();
  24278. - }
  24279. - } else {
  24280. - if (RC_TRACE_ENABLED(0x00040000)) {
  24281. - // don't want to loop unless we are tracing
  24282. - int count = 0;
  24283. - for (int i = 1; i < _index_map_p->length(); i++) {
  24284. - int value = _index_map_p->at(i);
  24285. -
  24286. - if (value != -1) {
  24287. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  24288. - ("index_map[%d]: old=%d new=%d", count, i, value));
  24289. - count++;
  24290. + void check_field(oop obj, int offset, klassOop static_type) {
  24291. + oop field_value = obj->obj_field(offset);
  24292. + if (field_value != NULL) {
  24293. + // Field is not null
  24294. + if (field_value->klass()->klass_part()->newest_version()->klass_part()->is_subtype_of(static_type)) {
  24295. + // We are OK
  24296. + TRACE_RC3("Field value is OK (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)", obj->klass()->klass_part()->name()->as_C_string(), static_type->klass_part()->name()->as_C_string(), offset, field_value->klass()->klass_part()->name()->as_C_string());
  24297. + } else {
  24298. + // Failure!
  24299. + TRACE_RC1("Field value is INVALID - abort redefinition (klass=%s, static_type=%s, offset=%d, dynamic_type=%s)", obj->klass()->klass_part()->name()->as_C_string(), static_type->klass_part()->name()->as_C_string(), offset, field_value->klass()->klass_part()->name()->as_C_string());
  24300. + _result = false;
  24301. }
  24302. }
  24303. }
  24304. -
  24305. - // We have entries mapped between the new and merged constant pools
  24306. - // so we have to rewrite some constant pool references.
  24307. - if (!rewrite_cp_refs(scratch_class, THREAD)) {
  24308. - return JVMTI_ERROR_INTERNAL;
  24309. + };
  24310. +
  24311. + CheckFieldTypesClosure myObjectClosure;
  24312. +
  24313. + // make sure that heap is parsable (fills TLABs with filler objects)
  24314. + Universe::heap()->ensure_parsability(false); // no need to retire TLABs
  24315. +
  24316. + // do the iteration
  24317. + // If this operation encounters a bad object when using CMS,
  24318. + // consider using safe_object_iterate() which avoids perm gen
  24319. + // objects that may contain bad references.
  24320. + Universe::heap()->object_iterate(&myObjectClosure);
  24321. +
  24322. + // when sharing is enabled we must iterate over the shared spaces
  24323. + if (UseSharedSpaces) {
  24324. + GenCollectedHeap* gch = GenCollectedHeap::heap();
  24325. + CompactingPermGenGen* gen = (CompactingPermGenGen*)gch->perm_gen();
  24326. + gen->ro_space()->object_iterate(&myObjectClosure);
  24327. + gen->rw_space()->object_iterate(&myObjectClosure);
  24328. + }
  24329. +
  24330. + return myObjectClosure.result();
  24331. +}
  24332. +
  24333. +void VM_RedefineClasses::clear_type_check_information() {
  24334. + class ClearTypeCheckInformationClosure : public ObjectClosure {
  24335. + virtual void do_object(oop obj) {
  24336. + klassOop klass = (klassOop)obj;
  24337. +
  24338. + if (klass->klass_part()->is_redefining()) {
  24339. + klass = klass->klass_part()->old_version();
  24340. + }
  24341. +
  24342. + // We found an instance klass!
  24343. + instanceKlass *cur_instance_klass = instanceKlass::cast(klass);
  24344. + cur_instance_klass->clear_type_check_information();
  24345. }
  24346. -
  24347. - // Replace the new constant pool with a shrunken copy of the
  24348. - // merged constant pool so now the rewritten bytecodes have
  24349. - // valid references; the previous new constant pool will get
  24350. - // GCed.
  24351. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  24352. - THREAD);
  24353. - merge_cp()->set_is_conc_safe(true);
  24354. + };
  24355. +
  24356. + ClearTypeCheckInformationClosure clearTypeCheckInformationClosure;
  24357. + SystemDictionary::classes_do(&clearTypeCheckInformationClosure);
  24358. +}
  24359. +
  24360. +void VM_RedefineClasses::update_active_methods() {
  24361. +
  24362. + TRACE_RC2("Updating active methods");
  24363. + JavaThread *java_thread = Threads::first();
  24364. + while (java_thread != NULL) {
  24365. +
  24366. + int stack_depth = 0;
  24367. + if (java_thread->has_last_Java_frame()) {
  24368. +
  24369. + TRACE_RC4("checking stack of Java thread %s", java_thread->name());
  24370. +
  24371. + // vframes are resource allocated
  24372. + Thread* current_thread = Thread::current();
  24373. + ResourceMark rm(current_thread);
  24374. + HandleMark hm(current_thread);
  24375. +
  24376. + RegisterMap reg_map(java_thread);
  24377. + frame f = java_thread->last_frame();
  24378. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  24379. + frame* last_entry_frame = NULL;
  24380. +
  24381. + while (vf != NULL) {
  24382. + if (vf->is_java_frame()) {
  24383. + // java frame (interpreted, compiled, ...)
  24384. + javaVFrame *jvf = javaVFrame::cast(vf);
  24385. +
  24386. + if (!(jvf->method()->is_native())) {
  24387. + int bci = jvf->bci();
  24388. + TRACE_RC4("found method: %s / bci=%d", jvf->method()->name()->as_C_string(), bci);
  24389. + ResourceMark rm(Thread::current());
  24390. + HandleMark hm;
  24391. + instanceKlassHandle klass(jvf->method()->method_holder());
  24392. +
  24393. + if (jvf->method()->new_version() != NULL && jvf->is_interpreted_frame()) {
  24394. +
  24395. +
  24396. + TRACE_RC2("Found method that should just be updated to the newest version %s", jvf->method()->name_and_sig_as_C_string());
  24397. +
  24398. + IF_TRACE_RC5 {
  24399. + int code_size = jvf->method()->code_size();
  24400. + char *code_base_old = (char*)jvf->method()->code_base();
  24401. + char *code_base_new = (char*)jvf->method()->new_version()->code_base();
  24402. + for (int i=0; i<code_size; i++) {
  24403. + tty->print_cr("old=%d new=%d", *code_base_old++, *code_base_new++);
  24404. + }
  24405. + jvf->method()->print_codes_on(tty);
  24406. + jvf->method()->new_version()->print_codes_on(tty);
  24407. + }
  24408. +
  24409. + assert(jvf->is_interpreted_frame(), "Every frame must be interpreted!");
  24410. + interpretedVFrame *iframe = (interpretedVFrame *)jvf;
  24411. +
  24412. +
  24413. + IF_TRACE_RC5 {
  24414. + constantPoolCacheOop cp_old = jvf->method()->constants()->cache();
  24415. + tty->print_cr("old cp");
  24416. + for (int i=0; i<cp_old->length(); i++) {
  24417. + cp_old->entry_at(i)->print(tty, i);
  24418. + }
  24419. + constantPoolCacheOop cp_new = jvf->method()->new_version()->constants()->cache();
  24420. + tty->print_cr("new cp");
  24421. + for (int i=0; i<cp_new->length(); i++) {
  24422. + cp_new->entry_at(i)->print(tty, i);
  24423. + }
  24424. + }
  24425. +
  24426. + iframe->set_method(jvf->method()->new_version(), bci);
  24427. + TRACE_RC2("Updated method to newer version");
  24428. + assert(jvf->method()->new_version() == NULL, "must be latest version");
  24429. +
  24430. + }
  24431. + }
  24432. + }
  24433. + vf = vf->sender();
  24434. + }
  24435. + }
  24436. +
  24437. + // Advance to next thread
  24438. + java_thread = java_thread->next();
  24439. }
  24440. - assert(old_cp()->is_conc_safe(), "Just checking");
  24441. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  24442. -
  24443. - return JVMTI_ERROR_NONE;
  24444. -} // end merge_cp_and_rewrite()
  24445. -
  24446. -
  24447. -// Rewrite constant pool references in klass scratch_class.
  24448. -bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
  24449. - TRAPS) {
  24450. -
  24451. - // rewrite constant pool references in the methods:
  24452. - if (!rewrite_cp_refs_in_methods(scratch_class, THREAD)) {
  24453. - // propagate failure back to caller
  24454. +}
  24455. +
  24456. +void VM_RedefineClasses::method_forwarding() {
  24457. +
  24458. + int forwarding_count = 0;
  24459. + JavaThread *java_thread = Threads::first();
  24460. + while (java_thread != NULL) {
  24461. +
  24462. + int stack_depth = 0;
  24463. + if (java_thread->has_last_Java_frame()) {
  24464. +
  24465. + TRACE_RC4("checking stack of Java thread %s", java_thread->name());
  24466. +
  24467. + // vframes are resource allocated
  24468. + Thread* current_thread = Thread::current();
  24469. + ResourceMark rm(current_thread);
  24470. + HandleMark hm(current_thread);
  24471. +
  24472. + RegisterMap reg_map(java_thread);
  24473. + frame f = java_thread->last_frame();
  24474. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  24475. + frame* last_entry_frame = NULL;
  24476. +
  24477. + while (vf != NULL) {
  24478. + if (vf->is_java_frame()) {
  24479. + // java frame (interpreted, compiled, ...)
  24480. + javaVFrame *jvf = javaVFrame::cast(vf);
  24481. +
  24482. + if (!(jvf->method()->is_native())) {
  24483. + TRACE_RC3("found method: %s", jvf->method()->name()->as_C_string());
  24484. + ResourceMark rm(Thread::current());
  24485. + HandleMark hm;
  24486. + instanceKlassHandle klass(jvf->method()->method_holder());
  24487. + methodOop m = jvf->method();
  24488. + int bci = jvf->bci();
  24489. + TRACE_RC3("klass redef %d", klass->is_redefining());
  24490. +
  24491. + if (klass->new_version() != NULL && m->new_version() == NULL) {
  24492. + TRACE_RC3("found potential forwarding method: %s", m->name()->as_C_string());
  24493. +
  24494. + klassOop new_klass = klass->newest_version();
  24495. + methodOop new_method = new_klass->klass_part()->lookup_method(m->name(), m->signature());
  24496. + TRACE_RC2("%d %d", new_method, new_method->constMethod()->has_code_section_table());
  24497. +
  24498. + if (new_method != NULL && new_method->constMethod()->has_code_section_table()) {
  24499. + TRACE_RC3("found code section table for method: %s", new_method->name()->as_C_string());
  24500. + m->set_forward_method(new_method);
  24501. + if (new_method->max_locals() != m->max_locals()) {
  24502. + tty->print_cr("new_m max locals: %d old_m max locals: %d", new_method->max_locals(), m->max_locals());
  24503. + }
  24504. + assert(new_method->max_locals() == m->max_locals(), "number of locals must match");
  24505. + assert(new_method->max_stack() == m->max_stack(), "number of stack values must match");
  24506. + if (jvf->is_interpreted_frame()) {
  24507. + if (m->is_in_code_section(bci)) {
  24508. + // We must transfer now and cannot delay until next NOP.
  24509. + int new_bci = m->calculate_forward_bci(bci, new_method);
  24510. + interpretedVFrame* iframe = interpretedVFrame::cast(jvf);
  24511. + TRACE_RC2("Transfering execution of %s to new method old_bci=%d new_bci=%d", new_method->name()->as_C_string(), bci, new_bci);
  24512. + iframe->set_method(new_method, new_bci);
  24513. + } else {
  24514. + TRACE_RC2("Delaying method forwarding of %s because %d is not in a code section", new_method->name()->as_C_string(), bci);
  24515. + }
  24516. + } else {
  24517. + TRACE_RC2("Delaying method forwarding of %s because method is compiled", new_method->name()->as_C_string());
  24518. + }
  24519. + }
  24520. + }
  24521. + }
  24522. + }
  24523. + vf = vf->sender();
  24524. + }
  24525. + }
  24526. +
  24527. + // Advance to next thread
  24528. + java_thread = java_thread->next();
  24529. + }
  24530. +
  24531. + TRACE_RC1("Method forwarding applied to %d methods", forwarding_count);
  24532. +}
  24533. +
  24534. +bool VM_RedefineClasses::check_method_stacks() {
  24535. +
  24536. + JavaThread *java_thread = Threads::first();
  24537. + while (java_thread != NULL) {
  24538. +
  24539. + int stack_depth = 0;
  24540. + if (java_thread->has_last_Java_frame()) {
  24541. +
  24542. + TRACE_RC4("checking stack of Java thread %s", java_thread->name());
  24543. +
  24544. + // vframes are resource allocated
  24545. + Thread* current_thread = Thread::current();
  24546. + ResourceMark rm(current_thread);
  24547. + HandleMark hm(current_thread);
  24548. +
  24549. + RegisterMap reg_map(java_thread);
  24550. + frame f = java_thread->last_frame();
  24551. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  24552. + frame* last_entry_frame = NULL;
  24553. +
  24554. + while (vf != NULL) {
  24555. + if (vf->is_java_frame()) {
  24556. + // java frame (interpreted, compiled, ...)
  24557. + javaVFrame *jvf = javaVFrame::cast(vf);
  24558. +
  24559. + if (!(jvf->method()->is_native())) {
  24560. + TRACE_RC4("found method: %s", jvf->method()->name()->as_C_string());
  24561. + ResourceMark rm(Thread::current());
  24562. + HandleMark hm;
  24563. + instanceKlassHandle klass(jvf->method()->method_holder());
  24564. +
  24565. + StackValueCollection *locals = jvf->locals();
  24566. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  24567. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  24568. +
  24569. + for (int i=0; i<locals->size(); i++) {
  24570. + StackValue *stack_value = locals->at(i);
  24571. + if (stack_value->type() == T_OBJECT) {
  24572. + Handle obj = stack_value->get_obj();
  24573. + if (!obj.is_null() && obj->klass()->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType)) {
  24574. +
  24575. + // OK, so this is a possible failure => check local variable table, if it could be OK.
  24576. + bool result = false;
  24577. + methodOop method = jvf->method();
  24578. + if (method->has_localvariable_table()) {
  24579. + LocalVariableTableElement *elem = jvf->method()->localvariable_table_start();
  24580. + for (int j=0; j<method->localvariable_table_length(); j++) {
  24581. +
  24582. + if (elem->slot == i) {
  24583. +
  24584. + // Matching index found
  24585. +
  24586. + if (elem->start_bci <= jvf->bci() && elem->start_bci + elem->length > jvf->bci()) {
  24587. +
  24588. + // Also in range!!
  24589. + symbolOop signature = jvf->method()->constants()->symbol_at(elem->descriptor_cp_index);
  24590. + symbolOop klass_name = signature_to_class_name(signature);
  24591. +
  24592. + klassOop local_klass = SystemDictionary::find(klass_name, jvf->method()->method_holder()->klass_part()->class_loader(), jvf->method()->method_holder()->klass_part()->protection_domain(), Thread::current())->klass_part()->newest_version();
  24593. + klassOop cur = obj->klass()->klass_part()->newest_version();
  24594. +
  24595. + // Field is not null
  24596. + if (cur->klass_part()->newest_version()->klass_part()->is_subtype_of(local_klass)) {
  24597. + // We are OK
  24598. + TRACE_RC3("Local variable value is OK (local_klass=%s, cur_klass=%s)", local_klass->klass_part()->name()->as_C_string(), cur->klass_part()->name()->as_C_string());
  24599. + result = true;
  24600. + } else {
  24601. + // Failure!
  24602. + TRACE_RC1("Local variable value is INVALID - abort redefinition (local_klass=%s, cur_klass=%s)", local_klass->klass_part()->name()->as_C_string(), cur->klass_part()->name()->as_C_string());
  24603. + return false;
  24604. + }
  24605. + }
  24606. + }
  24607. +
  24608. + elem++;
  24609. + }
  24610. + } else {
  24611. + TRACE_RC2("Method %s does not have a local variable table => abort", method->name_and_sig_as_C_string());
  24612. + }
  24613. +
  24614. + if (!result) {
  24615. + return false;
  24616. + }
  24617. +
  24618. + TRACE_RC3("Verifying class %s", jvf->method()->method_holder()->klass_part()->name()->as_C_string());
  24619. +
  24620. + symbolHandle exception_name;
  24621. + const size_t message_buffer_len = klass->name()->utf8_length() + 1024;
  24622. + char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len);
  24623. +
  24624. + if (TraceRedefineClasses >= 4) {
  24625. + ClassVerifier::_verify_verbose = true;
  24626. + }
  24627. +
  24628. + Thread::current()->set_pretend_new_universe(true);
  24629. + ClassVerifier split_verifier(klass, message_buffer, message_buffer_len, Thread::current());
  24630. + split_verifier.verify_method(jvf->method(), Thread::current());
  24631. + exception_name = split_verifier.result();
  24632. + Thread::current()->set_pretend_new_universe(false);
  24633. +
  24634. + if (TraceRedefineClasses >= 4) {
  24635. + ClassVerifier::_verify_verbose = false;
  24636. + }
  24637. +
  24638. + if (!exception_name.is_null()) {
  24639. +
  24640. + TRACE_RC1("Verification of class %s failed", jvf->method()->method_holder()->klass_part()->name()->as_C_string());
  24641. + TRACE_RC1("Exception: %s", exception_name->as_C_string());
  24642. + TRACE_RC1("Message: %s", message_buffer);
  24643. + Thread::current()->clear_pending_exception();
  24644. + return false;
  24645. + }
  24646. +
  24647. + }
  24648. + }
  24649. + }
  24650. + }
  24651. + }
  24652. + vf = vf->sender();
  24653. + }
  24654. + }
  24655. +
  24656. + // Advance to next thread
  24657. + java_thread = java_thread->next();
  24658. + }
  24659. +
  24660. + return true;
  24661. +}
  24662. +
  24663. +bool VM_RedefineClasses::check_method(methodOop method) {
  24664. +
  24665. +
  24666. + return true;
  24667. +}
  24668. +
  24669. +// Warning: destroys redefinition level values of klasses.
  24670. +bool VM_RedefineClasses::check_loaded_methods() {
  24671. +
  24672. + class CheckLoadedMethodsClosure : public ObjectClosure {
  24673. +
  24674. + private:
  24675. +
  24676. + bool _result;
  24677. + GrowableArray<klassOop> *_dangerous_klasses;
  24678. +
  24679. + public:
  24680. + CheckLoadedMethodsClosure(GrowableArray<klassOop> *dangerous_klasses) {
  24681. + _result = true;
  24682. + _dangerous_klasses = dangerous_klasses;
  24683. + }
  24684. +
  24685. + bool result() {
  24686. + return _result;
  24687. + }
  24688. +
  24689. + bool is_class_dangerous(klassOop k) {
  24690. + return k->klass_part()->newest_version()->klass_part()->check_redefinition_flag(Klass::RemoveSuperType);
  24691. + }
  24692. +
  24693. + bool can_be_affected(instanceKlass *klass) {
  24694. +
  24695. + constantPoolOop cp = klass->constants();
  24696. +
  24697. + Thread *THREAD = Thread::current();
  24698. + klassOop k;
  24699. + symbolOop symbol;
  24700. +
  24701. + for (int i=1; i<cp->length(); i++) {
  24702. + jbyte tag = cp->tag_at(i).value();
  24703. + switch(tag) {
  24704. + case JVM_CONSTANT_Long:
  24705. + case JVM_CONSTANT_Double:
  24706. + i++;
  24707. + break;
  24708. +
  24709. + case JVM_CONSTANT_Utf8:
  24710. + case JVM_CONSTANT_Unicode:
  24711. + case JVM_CONSTANT_Integer:
  24712. + case JVM_CONSTANT_Float:
  24713. + case JVM_CONSTANT_String:
  24714. + case JVM_CONSTANT_Fieldref:
  24715. + case JVM_CONSTANT_Methodref:
  24716. + case JVM_CONSTANT_InterfaceMethodref:
  24717. + case JVM_CONSTANT_ClassIndex:
  24718. + case JVM_CONSTANT_UnresolvedString:
  24719. + case JVM_CONSTANT_StringIndex:
  24720. + case JVM_CONSTANT_UnresolvedClassInError:
  24721. + case JVM_CONSTANT_Object:
  24722. + // do nothing
  24723. + break;
  24724. +
  24725. + case JVM_CONSTANT_Class:
  24726. + k = cp->klass_at(i, CHECK_(true));
  24727. + if (is_class_dangerous(k)) {
  24728. + TRACE_RC2("Class %s is potentially affected, because at cp[%d] references class %s", klass->name()->as_C_string(), i, k->klass_part()->name()->as_C_string());
  24729. + return true;
  24730. + }
  24731. + break;
  24732. +
  24733. + case JVM_CONSTANT_NameAndType:
  24734. + symbol = cp->symbol_at(cp->signature_ref_index_at(i));
  24735. + if (symbol->byte_at(0) == '(') {
  24736. + // This must be a method
  24737. + SignatureStream signatureStream(symbol);
  24738. + while (true) {
  24739. +
  24740. + if (signatureStream.is_array()) {
  24741. + symbolOop cur_signature = signatureStream.as_symbol(Thread::current());
  24742. + if (is_type_signature_dangerous(cur_signature)) {
  24743. + return true;
  24744. + }
  24745. + } else if (signatureStream.is_object()) {
  24746. + if (is_symbol_dangerous(signatureStream.as_symbol(Thread::current()))) {
  24747. + return true;
  24748. + }
  24749. + }
  24750. +
  24751. + if (signatureStream.at_return_type()) {
  24752. + break;
  24753. + }
  24754. +
  24755. + signatureStream.next();
  24756. + }
  24757. +
  24758. + } else if (is_type_signature_dangerous(symbol)) {
  24759. + return true;
  24760. + }
  24761. + break;
  24762. +
  24763. + case JVM_CONSTANT_UnresolvedClass:
  24764. + symbol = cp->unresolved_klass_at(i);
  24765. + if (is_symbol_dangerous(symbol)) {
  24766. + return true;
  24767. + }
  24768. + break;
  24769. +
  24770. + default:
  24771. + ShouldNotReachHere();
  24772. + }
  24773. + }
  24774. +
  24775. + return false;
  24776. + }
  24777. +
  24778. + bool is_type_signature_dangerous(symbolOop signature) {
  24779. + // This must be a field type
  24780. + if (FieldType::is_obj(signature)) {
  24781. + symbolOop name = signature_to_class_name(signature);
  24782. + if (is_symbol_dangerous(name)) {
  24783. + return true;
  24784. + }
  24785. + } else if (FieldType::is_array(signature)) {
  24786. + jint dimension;
  24787. + symbolOop object_key;
  24788. + FieldType::get_array_info(signature, &dimension, &object_key, Thread::current());
  24789. + if (is_symbol_dangerous(object_key)) {
  24790. + return true;
  24791. + }
  24792. + }
  24793. + return false;
  24794. + }
  24795. +
  24796. + bool is_symbol_dangerous(symbolOop symbol) {
  24797. + for (int i=0; i<_dangerous_klasses->length(); i++) {
  24798. + if(_dangerous_klasses->at(i)->klass_part()->name() == symbol) {
  24799. + TRACE_RC2("Found constant pool index %d references class %s", i, symbol->as_C_string());
  24800. + return true;
  24801. + }
  24802. + }
  24803. + return false;
  24804. + }
  24805. +
  24806. + virtual void do_object(oop obj) {
  24807. +
  24808. + if (!_result) return;
  24809. +
  24810. + klassOop klassObj = (klassOop)obj;
  24811. + Thread *THREAD = Thread::current();
  24812. +
  24813. + // We found an instance klass!
  24814. + instanceKlass *klass = instanceKlass::cast(klassObj);
  24815. + instanceKlassHandle handle(klassObj);
  24816. +
  24817. + TRACE_RC4("Check if verification is necessary for class %s major_version=%d", handle->name()->as_C_string(), handle->major_version());
  24818. +
  24819. + if (!can_be_affected(klass)) {
  24820. + TRACE_RC4("Skipping verification of class %s major_version=%d", handle->name()->as_C_string(), handle->major_version());
  24821. + return;
  24822. + }
  24823. +
  24824. + if (handle->major_version() < Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION) {
  24825. + TRACE_RC1("Failing because cannot verify class %s major_version=%d", handle->name()->as_C_string(), handle->major_version());
  24826. + _result = false;
  24827. + return;
  24828. + }
  24829. +
  24830. + TRACE_RC3("Verifying class %s", handle->name()->as_C_string());
  24831. +
  24832. + if (!Verifier::verify(handle, Verifier::NoException, true, false, Thread::current())) {
  24833. +
  24834. + TRACE_RC1("Verification of class %s failed", handle->name()->as_C_string());
  24835. + //symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  24836. + //TRACE_RC2("exception when verifying class: '%s'", ex_name->as_C_string());
  24837. + //PENDING_EXCEPTION->print();
  24838. + CLEAR_PENDING_EXCEPTION;
  24839. + _result = false;
  24840. + }
  24841. +
  24842. + /*int method_count = klass->methods()->length();
  24843. + for (int i=0; i<method_count; i++) {
  24844. + methodOop cur_method = (methodOop)klass->methods()->obj_at(i);
  24845. + if (!check_method(cur_method)) {
  24846. + TRACE_RC1("Failed to verify consistency of method %s of klass %s", cur_method->name()->as_C_string(), klass->name()->as_C_string());
  24847. + }
  24848. + }*/
  24849. + }
  24850. + };
  24851. +
  24852. + // TODO: Check bytecodes in case of interface => class or class => interface etc..
  24853. +
  24854. + GrowableArray<klassOop> dangerous_klasses;
  24855. + for (int i=0; i<_new_classes->length(); i++) {
  24856. + instanceKlassHandle handle = _new_classes->at(i);
  24857. + if (handle->check_redefinition_flag(Klass::RemoveSuperType)) {
  24858. + dangerous_klasses.append(handle());
  24859. + }
  24860. + }
  24861. +
  24862. + CheckLoadedMethodsClosure checkLoadedMethodsClosure(&dangerous_klasses);
  24863. + Thread::current()->set_pretend_new_universe(true);
  24864. + SystemDictionary::classes_do(&checkLoadedMethodsClosure);
  24865. + Thread::current()->set_pretend_new_universe(false);
  24866. +
  24867. +
  24868. + return checkLoadedMethodsClosure.result();
  24869. +}
  24870. +
  24871. +bool VM_RedefineClasses::check_type_consistency() {
  24872. +
  24873. + Universe::set_verify_in_progress(true);
  24874. +
  24875. + calculate_type_check_information();
  24876. + bool result = check_field_value_types();
  24877. + clear_type_check_information();
  24878. + if (!result) {
  24879. + TRACE_RC1("Aborting redefinition because of wrong field or array element value!");
  24880. + Universe::set_verify_in_progress(false);
  24881. return false;
  24882. }
  24883. - // rewrite constant pool references in the class_annotations:
  24884. - if (!rewrite_cp_refs_in_class_annotations(scratch_class, THREAD)) {
  24885. - // propagate failure back to caller
  24886. + result = check_method_stacks();
  24887. + if (!result) {
  24888. + TRACE_RC1("Aborting redefinition because of wrong value on the stack");
  24889. + Universe::set_verify_in_progress(false);
  24890. return false;
  24891. }
  24892. - // rewrite constant pool references in the fields_annotations:
  24893. - if (!rewrite_cp_refs_in_fields_annotations(scratch_class, THREAD)) {
  24894. - // propagate failure back to caller
  24895. + result = check_loaded_methods();
  24896. + if (!result) {
  24897. + TRACE_RC1("Aborting redefinition because of wrong loaded method");
  24898. + Universe::set_verify_in_progress(false);
  24899. return false;
  24900. }
  24901. - // rewrite constant pool references in the methods_annotations:
  24902. - if (!rewrite_cp_refs_in_methods_annotations(scratch_class, THREAD)) {
  24903. - // propagate failure back to caller
  24904. + TRACE_RC1("Verification passed => hierarchy change is valid!");
  24905. + Universe::set_verify_in_progress(false);
  24906. + return true;
  24907. +}
  24908. +
  24909. +void VM_RedefineClasses::rollback() {
  24910. + TRACE_RC1("Rolling back redefinition!");
  24911. + SystemDictionary::rollback_redefinition();
  24912. +
  24913. + TRACE_RC1("After rolling back system dictionary!");
  24914. + for (int i=0; i<_new_classes->length(); i++) {
  24915. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  24916. + }
  24917. +
  24918. + for (int i=0; i<_new_classes->length(); i++) {
  24919. + instanceKlassHandle new_class = _new_classes->at(i);
  24920. + new_class->set_redefining(false);
  24921. + new_class->old_version()->klass_part()->set_new_version(NULL);
  24922. + new_class->set_old_version(NULL);
  24923. + }
  24924. +
  24925. +}
  24926. +
  24927. +template <class T> void VM_RedefineClasses::do_oop_work(T* p) {
  24928. + T heap_oop = oopDesc::load_heap_oop(p);
  24929. + if (!oopDesc::is_null(heap_oop)) {
  24930. + oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  24931. + if (obj->is_instanceKlass()) {
  24932. + klassOop klass = (klassOop)obj;
  24933. + if (klass->klass_part()->new_version() != NULL && klass->klass_part()->new_version()->klass_part()->is_redefining()) {
  24934. + obj = klass->klass_part()->new_version();
  24935. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  24936. + }
  24937. + } else if (obj->blueprint()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version()) {
  24938. +
  24939. + klassOop klass_oop = java_lang_Class::as_klassOop(obj);
  24940. + if (klass_oop != NULL) {
  24941. + if (klass_oop->klass_part()->new_version() != NULL && klass_oop->klass_part()->new_version()->klass_part()->is_redefining()) {
  24942. + obj = klass_oop->klass_part()->new_version()->klass_part()->java_mirror();
  24943. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  24944. + } else if (klass_oop->klass_part()->is_redefining()) {
  24945. + obj = klass_oop->klass_part()->java_mirror();
  24946. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  24947. + }
  24948. + }
  24949. + }
  24950. + }
  24951. +}
  24952. +
  24953. +void VM_RedefineClasses::swap_marks(oop first, oop second) {
  24954. + markOop first_mark = first->mark();
  24955. + markOop second_mark = second->mark();
  24956. + first->set_mark(second_mark);
  24957. + second->set_mark(first_mark);
  24958. +}
  24959. +
  24960. +void VM_RedefineClasses::doit() {
  24961. + Thread *thread = Thread::current();
  24962. +
  24963. + TRACE_RC1("Entering doit!");
  24964. +
  24965. +
  24966. + if ((_max_redefinition_flags & Klass::RemoveSuperType) != 0) {
  24967. +
  24968. + RC_TIMER_START(_timer_check_type);
  24969. +
  24970. + if (!check_type_consistency()) {
  24971. + // (tw) TODO: Rollback the class redefinition
  24972. + rollback();
  24973. + TRACE_RC1("Detected type inconsistency!");
  24974. + _result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  24975. + RC_TIMER_STOP(_timer_check_type);
  24976. + return;
  24977. + }
  24978. +
  24979. + RC_TIMER_STOP(_timer_check_type);
  24980. +
  24981. + } else {
  24982. + TRACE_RC1("No type narrowing => skipping check for type inconsistency");
  24983. + }
  24984. +
  24985. + if (UseMethodForwardPoints) {
  24986. + TRACE_RC1("Check stack for forwarding methods to new version");
  24987. + method_forwarding();
  24988. + }
  24989. +
  24990. + if (UseSharedSpaces) {
  24991. + // Sharing is enabled so we remap the shared readonly space to
  24992. + // shared readwrite, private just in case we need to redefine
  24993. + // a shared class. We do the remap during the doit() phase of
  24994. + // the safepoint to be safer.
  24995. + if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  24996. + TRACE_RC1("failed to remap shared readonly space to readwrite, private");
  24997. + _result = JVMTI_ERROR_INTERNAL;
  24998. + return;
  24999. + }
  25000. + }
  25001. +
  25002. + RC_TIMER_START(_timer_prepare_redefinition);
  25003. + for (int i = 0; i < _new_classes->length(); i++) {
  25004. + redefine_single_class(_new_classes->at(i), thread);
  25005. + }
  25006. +
  25007. + // Deoptimize all compiled code that depends on this class
  25008. + flush_dependent_code(instanceKlassHandle(Thread::current(), (klassOop)NULL), Thread::current());
  25009. +
  25010. + // Adjust constantpool caches and vtables for all classes
  25011. + // that reference methods of the evolved class.
  25012. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  25013. +
  25014. + RC_TIMER_STOP(_timer_prepare_redefinition);
  25015. + RC_TIMER_START(_timer_redefinition);
  25016. +
  25017. + class ChangePointersOopClosure : public OopClosure {
  25018. + virtual void do_oop(oop* o) {
  25019. + do_oop_work(o);
  25020. + }
  25021. +
  25022. + virtual void do_oop(narrowOop* o) {
  25023. + do_oop_work(o);
  25024. + }
  25025. + };
  25026. +
  25027. + class ChangePointersObjectClosure : public ObjectClosure {
  25028. +
  25029. + private:
  25030. +
  25031. + OopClosure *_closure;
  25032. + bool _needs_instance_update;
  25033. + GrowableArray<oop> *_updated_oops;
  25034. +
  25035. + public:
  25036. + ChangePointersObjectClosure(OopClosure *closure) : _closure(closure), _needs_instance_update(false), _updated_oops(NULL) {}
  25037. +
  25038. + bool needs_instance_update() {
  25039. + return _needs_instance_update;
  25040. + }
  25041. +
  25042. + GrowableArray<oop> *updated_oops() { return _updated_oops; }
  25043. +
  25044. + virtual void do_object(oop obj) {
  25045. + if (!obj->is_instanceKlass()) {
  25046. + obj->oop_iterate(_closure);
  25047. +
  25048. + if (obj->blueprint()->is_redefining()) {
  25049. +
  25050. + if (obj->blueprint()->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  25051. + if (_updated_oops == NULL) {
  25052. + _updated_oops = new (ResourceObj::C_HEAP) GrowableArray<oop>(100, true);
  25053. + }
  25054. + _updated_oops->append(obj);
  25055. + }
  25056. +
  25057. + if(obj->blueprint()->update_information() != NULL || obj->is_perm()) {
  25058. +
  25059. + assert(obj->blueprint()->old_version() != NULL, "must have old version");
  25060. + obj->set_klass_no_check(obj->blueprint()->old_version());
  25061. +
  25062. + if (obj->size() != obj->size_given_klass(obj->blueprint()->new_version()->klass_part()) || obj->is_perm()) {
  25063. + // We need an instance update => set back to old klass
  25064. + _needs_instance_update = true;
  25065. +
  25066. + } else {
  25067. + MarkSweep::update_fields(obj, obj);
  25068. + assert(obj->blueprint()->is_redefining(), "update fields resets the klass");
  25069. + }
  25070. + }
  25071. + }
  25072. +
  25073. + } else {
  25074. + instanceKlass *klass = instanceKlass::cast((klassOop)obj);
  25075. + if (klass->is_redefining()) {
  25076. + // Initialize the new class! Special static initialization that does not execute the
  25077. + // static constructor but copies static field values from the old class if name
  25078. + // and signature of a static field match.
  25079. + klass->initialize_redefined_class();
  25080. + }
  25081. + klass->iterate_static_fields(_closure);
  25082. + }
  25083. + }
  25084. + };
  25085. +
  25086. + ChangePointersOopClosure oopClosure;
  25087. + ChangePointersObjectClosure objectClosure(&oopClosure);
  25088. +
  25089. + {
  25090. + SharedHeap::heap()->gc_prologue(true);
  25091. + Universe::root_oops_do(&oopClosure);
  25092. + Universe::heap()->object_iterate(&objectClosure);
  25093. + SharedHeap::heap()->gc_epilogue(false);
  25094. + }
  25095. +
  25096. + // Swap marks to have same hashcodes
  25097. + for (int i=0; i<_new_classes->length(); i++) {
  25098. + swap_marks(_new_classes->at(i)(), _new_classes->at(i)->old_version());
  25099. + swap_marks(_new_classes->at(i)->java_mirror(), _new_classes->at(i)->old_version()->klass_part()->java_mirror());
  25100. + ((instanceKlass*)_new_classes->at(i)->old_version()->klass_part())->constants()->set_pool_holder(_new_classes->at(i)->old_version());
  25101. + }
  25102. +
  25103. + _updated_oops = objectClosure.updated_oops();
  25104. +
  25105. + if (objectClosure.needs_instance_update()){
  25106. +
  25107. + // Do a full garbage collection to update the instance sizes accordingly
  25108. + TRACE_RC1("Before performing full GC!");
  25109. + Universe::set_redefining_gc_run(true);
  25110. + JvmtiGCFullMarker jgcm;
  25111. + notify_gc_begin(true);
  25112. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  25113. + notify_gc_end();
  25114. + Universe::set_redefining_gc_run(false);
  25115. + TRACE_RC1("GC done!");
  25116. + }
  25117. +
  25118. +
  25119. + IF_TRACE_RC1 {
  25120. + if (_updated_oops != NULL) {
  25121. + TRACE_RC1("%d object(s) updated!", _updated_oops->length());
  25122. + } else {
  25123. + TRACE_RC1("No objects updated!");
  25124. + }
  25125. + }
  25126. +
  25127. + // Unmark klassOops as "redefining"
  25128. + for (int i=0; i<_new_classes->length(); i++) {
  25129. + klassOop cur = _new_classes->at(i)();
  25130. + _new_classes->at(i)->set_redefining(false);
  25131. + _new_classes->at(i)->clear_update_information();
  25132. + _new_classes->at(i)->update_supers_to_newest_version();
  25133. +
  25134. + if (((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses() != NULL) {
  25135. + update_array_classes_to_newest_version(((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses());
  25136. +
  25137. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  25138. + ((instanceKlass*)cur->klass_part())->set_array_klasses(((instanceKlass*)cur->klass_part()->old_version()->klass_part())->array_klasses());
  25139. +
  25140. + oop new_mirror = _new_classes->at(i)->java_mirror();
  25141. + oop old_mirror = _new_classes->at(i)->old_version()->klass_part()->java_mirror();
  25142. + java_lang_Class::set_array_klass(new_mirror, java_lang_Class::array_klass(old_mirror));
  25143. + }
  25144. + }
  25145. +
  25146. + for (int i=T_BOOLEAN; i<=T_LONG; i++) {
  25147. + update_array_classes_to_newest_version(Universe::typeArrayKlassObj((BasicType)i));
  25148. + }
  25149. +
  25150. + // Disable any dependent concurrent compilations
  25151. + SystemDictionary::notice_modification();
  25152. +
  25153. + // Set flag indicating that some invariants are no longer true.
  25154. + // See jvmtiExport.hpp for detailed explanation.
  25155. + JvmtiExport::set_has_redefined_a_class();
  25156. +
  25157. + // Clean up caches in the compiler interface and compiler threads
  25158. + CompileBroker::cleanup_after_redefinition();
  25159. +
  25160. +#ifdef ASSERT
  25161. +
  25162. + // Universe::verify();
  25163. + // JNIHandles::verify();
  25164. +
  25165. + SystemDictionary::classes_do(check_class, thread);
  25166. +#endif
  25167. +
  25168. + update_active_methods();
  25169. + RC_TIMER_STOP(_timer_redefinition);
  25170. +
  25171. +}
  25172. +
  25173. +void VM_RedefineClasses::update_array_classes_to_newest_version(klassOop smallest_dimension) {
  25174. +
  25175. + arrayKlass *curArrayKlass = arrayKlass::cast(smallest_dimension);
  25176. + assert(curArrayKlass->lower_dimension() == NULL, "argument must be smallest dimension");
  25177. +
  25178. +
  25179. + while (curArrayKlass != NULL) {
  25180. + klassOop higher_dimension = curArrayKlass->higher_dimension();
  25181. + klassOop lower_dimension = curArrayKlass->lower_dimension();
  25182. + curArrayKlass->update_supers_to_newest_version();
  25183. +
  25184. + curArrayKlass = NULL;
  25185. + if (higher_dimension != NULL) {
  25186. + curArrayKlass = arrayKlass::cast(higher_dimension);
  25187. + }
  25188. + }
  25189. +
  25190. +}
  25191. +
  25192. +void VM_RedefineClasses::doit_epilogue() {
  25193. +
  25194. + RC_TIMER_START(_timer_vm_op_epilogue);
  25195. +
  25196. + unlock_threads();
  25197. +
  25198. + ResourceMark mark;
  25199. +
  25200. + VM_GC_Operation::doit_epilogue();
  25201. + TRACE_RC1("GC Operation epilogue finished! ");
  25202. +
  25203. + GrowableArray<methodHandle> instanceTransformerMethods;
  25204. +
  25205. + // Call static transformers
  25206. + for (int i=0; i<_new_classes->length(); i++) {
  25207. +
  25208. + instanceKlassHandle klass = _new_classes->at(i);
  25209. +
  25210. + // Find instance transformer method
  25211. +
  25212. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  25213. +
  25214. + TRACE_RC5("Call instance transformer of %s instance", klass->name()->as_C_string());
  25215. + klassOop cur_klass = klass();
  25216. + while (cur_klass != NULL) {
  25217. + methodOop method = ((instanceKlass*)cur_klass->klass_part())->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature());
  25218. + if (method != NULL) {
  25219. + methodHandle instanceTransformerMethod(method);
  25220. + instanceTransformerMethods.append(instanceTransformerMethod);
  25221. + break;
  25222. + } else {
  25223. + cur_klass = cur_klass->klass_part()->super();
  25224. + }
  25225. + }
  25226. + assert(cur_klass != NULL, "must have instance transformer method");
  25227. + } else {
  25228. + instanceTransformerMethods.append(methodHandle(Thread::current(), NULL));
  25229. + }
  25230. + }
  25231. +
  25232. +
  25233. + // Call instance transformers
  25234. + if (_updated_oops != NULL) {
  25235. +
  25236. + for (int i=0; i<_updated_oops->length(); i++) {
  25237. + assert(_updated_oops->at(i) != NULL, "must not be null!");
  25238. + Handle cur(_updated_oops->at(i));
  25239. + instanceKlassHandle klass(cur->klass());
  25240. +
  25241. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  25242. +
  25243. + methodHandle method = instanceTransformerMethods.at(klass->redefinition_index());
  25244. +
  25245. + TRACE_RC5("executing transformer method");
  25246. +
  25247. + Thread *__the_thread__ = Thread::current();
  25248. + JavaValue result(T_VOID);
  25249. + JavaCallArguments args(cur);
  25250. + JavaCalls::call(&result,
  25251. + method,
  25252. + &args,
  25253. + THREAD);
  25254. +
  25255. + // TODO: What to do with an exception here?
  25256. + if (HAS_PENDING_EXCEPTION) {
  25257. + symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  25258. + TRACE_RC2("exception when executing transformer: '%s'", ex_name->as_C_string());
  25259. + CLEAR_PENDING_EXCEPTION;
  25260. + }
  25261. + }
  25262. + }
  25263. +
  25264. + delete _updated_oops;
  25265. + _updated_oops = NULL;
  25266. + }
  25267. +
  25268. + // Free the array of scratch classes
  25269. + delete _new_classes;
  25270. + _new_classes = NULL;
  25271. + TRACE_RC1("Redefinition finished!");
  25272. +
  25273. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  25274. +}
  25275. +
  25276. +bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  25277. + // classes for primitives cannot be redefined
  25278. + if (java_lang_Class::is_primitive(klass_mirror)) {
  25279. return false;
  25280. }
  25281. -
  25282. - // rewrite constant pool references in the methods_parameter_annotations:
  25283. - if (!rewrite_cp_refs_in_methods_parameter_annotations(scratch_class,
  25284. - THREAD)) {
  25285. - // propagate failure back to caller
  25286. + klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  25287. + // classes for arrays cannot be redefined
  25288. + if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  25289. return false;
  25290. }
  25291. -
  25292. - // rewrite constant pool references in the methods_default_annotations:
  25293. - if (!rewrite_cp_refs_in_methods_default_annotations(scratch_class,
  25294. - THREAD)) {
  25295. - // propagate failure back to caller
  25296. - return false;
  25297. - }
  25298. -
  25299. - return true;
  25300. -} // end rewrite_cp_refs()
  25301. -
  25302. -
  25303. -// Rewrite constant pool references in the methods.
  25304. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
  25305. - instanceKlassHandle scratch_class, TRAPS) {
  25306. -
  25307. - objArrayHandle methods(THREAD, scratch_class->methods());
  25308. -
  25309. - if (methods.is_null() || methods->length() == 0) {
  25310. - // no methods so nothing to do
  25311. - return true;
  25312. - }
  25313. -
  25314. - // rewrite constant pool references in the methods:
  25315. - for (int i = methods->length() - 1; i >= 0; i--) {
  25316. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  25317. - methodHandle new_method;
  25318. - rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
  25319. - if (!new_method.is_null()) {
  25320. - // the method has been replaced so save the new method version
  25321. - methods->obj_at_put(i, new_method());
  25322. - }
  25323. - }
  25324. -
  25325. return true;
  25326. }
  25327. -
  25328. -// Rewrite constant pool references in the specific method. This code
  25329. -// was adapted from Rewriter::rewrite_method().
  25330. -void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
  25331. - methodHandle *new_method_p, TRAPS) {
  25332. -
  25333. - *new_method_p = methodHandle(); // default is no new method
  25334. -
  25335. - // We cache a pointer to the bytecodes here in code_base. If GC
  25336. - // moves the methodOop, then the bytecodes will also move which
  25337. - // will likely cause a crash. We create a No_Safepoint_Verifier
  25338. - // object to detect whether we pass a possible safepoint in this
  25339. - // code block.
  25340. - No_Safepoint_Verifier nsv;
  25341. -
  25342. - // Bytecodes and their length
  25343. - address code_base = method->code_base();
  25344. - int code_length = method->code_size();
  25345. -
  25346. - int bc_length;
  25347. - for (int bci = 0; bci < code_length; bci += bc_length) {
  25348. - address bcp = code_base + bci;
  25349. - Bytecodes::Code c = (Bytecodes::Code)(*bcp);
  25350. -
  25351. - bc_length = Bytecodes::length_for(c);
  25352. - if (bc_length == 0) {
  25353. - // More complicated bytecodes report a length of zero so
  25354. - // we have to try again a slightly different way.
  25355. - bc_length = Bytecodes::length_at(bcp);
  25356. - }
  25357. -
  25358. - assert(bc_length != 0, "impossible bytecode length");
  25359. -
  25360. - switch (c) {
  25361. - case Bytecodes::_ldc:
  25362. - {
  25363. - int cp_index = *(bcp + 1);
  25364. - int new_index = find_new_index(cp_index);
  25365. -
  25366. - if (StressLdcRewrite && new_index == 0) {
  25367. - // If we are stressing ldc -> ldc_w rewriting, then we
  25368. - // always need a new_index value.
  25369. - new_index = cp_index;
  25370. - }
  25371. - if (new_index != 0) {
  25372. - // the original index is mapped so we have more work to do
  25373. - if (!StressLdcRewrite && new_index <= max_jubyte) {
  25374. - // The new value can still use ldc instead of ldc_w
  25375. - // unless we are trying to stress ldc -> ldc_w rewriting
  25376. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  25377. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  25378. - bcp, cp_index, new_index));
  25379. - *(bcp + 1) = new_index;
  25380. - } else {
  25381. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  25382. - ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
  25383. - Bytecodes::name(c), bcp, cp_index, new_index));
  25384. - // the new value needs ldc_w instead of ldc
  25385. - u_char inst_buffer[4]; // max instruction size is 4 bytes
  25386. - bcp = (address)inst_buffer;
  25387. - // construct new instruction sequence
  25388. - *bcp = Bytecodes::_ldc_w;
  25389. - bcp++;
  25390. - // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
  25391. - // See comment below for difference between put_Java_u2()
  25392. - // and put_native_u2().
  25393. - Bytes::put_Java_u2(bcp, new_index);
  25394. -
  25395. - Relocator rc(method, NULL /* no RelocatorListener needed */);
  25396. - methodHandle m;
  25397. - {
  25398. - Pause_No_Safepoint_Verifier pnsv(&nsv);
  25399. -
  25400. - // ldc is 2 bytes and ldc_w is 3 bytes
  25401. - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD);
  25402. - if (m.is_null() || HAS_PENDING_EXCEPTION) {
  25403. - guarantee(false, "insert_space_at() failed");
  25404. - }
  25405. - }
  25406. -
  25407. - // return the new method so that the caller can update
  25408. - // the containing class
  25409. - *new_method_p = method = m;
  25410. - // switch our bytecode processing loop from the old method
  25411. - // to the new method
  25412. - code_base = method->code_base();
  25413. - code_length = method->code_size();
  25414. - bcp = code_base + bci;
  25415. - c = (Bytecodes::Code)(*bcp);
  25416. - bc_length = Bytecodes::length_for(c);
  25417. - assert(bc_length != 0, "sanity check");
  25418. - } // end we need ldc_w instead of ldc
  25419. - } // end if there is a mapped index
  25420. - } break;
  25421. -
  25422. - // these bytecodes have a two-byte constant pool index
  25423. - case Bytecodes::_anewarray : // fall through
  25424. - case Bytecodes::_checkcast : // fall through
  25425. - case Bytecodes::_getfield : // fall through
  25426. - case Bytecodes::_getstatic : // fall through
  25427. - case Bytecodes::_instanceof : // fall through
  25428. - case Bytecodes::_invokeinterface: // fall through
  25429. - case Bytecodes::_invokespecial : // fall through
  25430. - case Bytecodes::_invokestatic : // fall through
  25431. - case Bytecodes::_invokevirtual : // fall through
  25432. - case Bytecodes::_ldc_w : // fall through
  25433. - case Bytecodes::_ldc2_w : // fall through
  25434. - case Bytecodes::_multianewarray : // fall through
  25435. - case Bytecodes::_new : // fall through
  25436. - case Bytecodes::_putfield : // fall through
  25437. - case Bytecodes::_putstatic :
  25438. - {
  25439. - address p = bcp + 1;
  25440. - int cp_index = Bytes::get_Java_u2(p);
  25441. - int new_index = find_new_index(cp_index);
  25442. - if (new_index != 0) {
  25443. - // the original index is mapped so update w/ new value
  25444. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  25445. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  25446. - bcp, cp_index, new_index));
  25447. - // Rewriter::rewrite_method() uses put_native_u2() in this
  25448. - // situation because it is reusing the constant pool index
  25449. - // location for a native index into the constantPoolCache.
  25450. - // Since we are updating the constant pool index prior to
  25451. - // verification and constantPoolCache initialization, we
  25452. - // need to keep the new index in Java byte order.
  25453. - Bytes::put_Java_u2(p, new_index);
  25454. - }
  25455. - } break;
  25456. - }
  25457. - } // end for each bytecode
  25458. -} // end rewrite_cp_refs_in_method()
  25459. -
  25460. -
  25461. -// Rewrite constant pool references in the class_annotations field.
  25462. -bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
  25463. - instanceKlassHandle scratch_class, TRAPS) {
  25464. -
  25465. - typeArrayHandle class_annotations(THREAD,
  25466. - scratch_class->class_annotations());
  25467. - if (class_annotations.is_null() || class_annotations->length() == 0) {
  25468. - // no class_annotations so nothing to do
  25469. - return true;
  25470. +#ifdef ASSERT
  25471. +
  25472. +void VM_RedefineClasses::verify_classes(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  25473. + klassOop k_oop = k_oop_latest;
  25474. + while (k_oop != NULL) {
  25475. +
  25476. + instanceKlassHandle k_handle(THREAD, k_oop);
  25477. + Verifier::verify(k_handle, Verifier::ThrowException, true, true, THREAD);
  25478. + k_oop = k_oop->klass_part()->old_version();
  25479. }
  25480. -
  25481. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25482. - ("class_annotations length=%d", class_annotations->length()));
  25483. -
  25484. - int byte_i = 0; // byte index into class_annotations
  25485. - return rewrite_cp_refs_in_annotations_typeArray(class_annotations, byte_i,
  25486. - THREAD);
  25487. }
  25488. -
  25489. -// Rewrite constant pool references in an annotations typeArray. This
  25490. -// "structure" is adapted from the RuntimeVisibleAnnotations_attribute
  25491. -// that is described in section 4.8.15 of the 2nd-edition of the VM spec:
  25492. -//
  25493. -// annotations_typeArray {
  25494. -// u2 num_annotations;
  25495. -// annotation annotations[num_annotations];
  25496. -// }
  25497. -//
  25498. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
  25499. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  25500. -
  25501. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  25502. - // not enough room for num_annotations field
  25503. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25504. - ("length() is too small for num_annotations field"));
  25505. - return false;
  25506. - }
  25507. -
  25508. - u2 num_annotations = Bytes::get_Java_u2((address)
  25509. - annotations_typeArray->byte_at_addr(byte_i_ref));
  25510. - byte_i_ref += 2;
  25511. -
  25512. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25513. - ("num_annotations=%d", num_annotations));
  25514. -
  25515. - int calc_num_annotations = 0;
  25516. - for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
  25517. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  25518. - byte_i_ref, THREAD)) {
  25519. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25520. - ("bad annotation_struct at %d", calc_num_annotations));
  25521. - // propagate failure back to caller
  25522. - return false;
  25523. - }
  25524. - }
  25525. - assert(num_annotations == calc_num_annotations, "sanity check");
  25526. -
  25527. - return true;
  25528. -} // end rewrite_cp_refs_in_annotations_typeArray()
  25529. -
  25530. -
  25531. -// Rewrite constant pool references in the annotation struct portion of
  25532. -// an annotations_typeArray. This "structure" is from section 4.8.15 of
  25533. -// the 2nd-edition of the VM spec:
  25534. -//
  25535. -// struct annotation {
  25536. -// u2 type_index;
  25537. -// u2 num_element_value_pairs;
  25538. -// {
  25539. -// u2 element_name_index;
  25540. -// element_value value;
  25541. -// } element_value_pairs[num_element_value_pairs];
  25542. -// }
  25543. -//
  25544. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
  25545. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  25546. - if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
  25547. - // not enough room for smallest annotation_struct
  25548. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25549. - ("length() is too small for annotation_struct"));
  25550. - return false;
  25551. - }
  25552. -
  25553. - u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray,
  25554. - byte_i_ref, "mapped old type_index=%d", THREAD);
  25555. -
  25556. - u2 num_element_value_pairs = Bytes::get_Java_u2((address)
  25557. - annotations_typeArray->byte_at_addr(
  25558. - byte_i_ref));
  25559. - byte_i_ref += 2;
  25560. -
  25561. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25562. - ("type_index=%d num_element_value_pairs=%d", type_index,
  25563. - num_element_value_pairs));
  25564. -
  25565. - int calc_num_element_value_pairs = 0;
  25566. - for (; calc_num_element_value_pairs < num_element_value_pairs;
  25567. - calc_num_element_value_pairs++) {
  25568. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  25569. - // not enough room for another element_name_index, let alone
  25570. - // the rest of another component
  25571. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25572. - ("length() is too small for element_name_index"));
  25573. - return false;
  25574. - }
  25575. -
  25576. - u2 element_name_index = rewrite_cp_ref_in_annotation_data(
  25577. - annotations_typeArray, byte_i_ref,
  25578. - "mapped old element_name_index=%d", THREAD);
  25579. -
  25580. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25581. - ("element_name_index=%d", element_name_index));
  25582. -
  25583. - if (!rewrite_cp_refs_in_element_value(annotations_typeArray,
  25584. - byte_i_ref, THREAD)) {
  25585. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25586. - ("bad element_value at %d", calc_num_element_value_pairs));
  25587. - // propagate failure back to caller
  25588. - return false;
  25589. - }
  25590. - } // end for each component
  25591. - assert(num_element_value_pairs == calc_num_element_value_pairs,
  25592. - "sanity check");
  25593. -
  25594. - return true;
  25595. -} // end rewrite_cp_refs_in_annotation_struct()
  25596. -
  25597. -
  25598. -// Rewrite a constant pool reference at the current position in
  25599. -// annotations_typeArray if needed. Returns the original constant
  25600. -// pool reference if a rewrite was not needed or the new constant
  25601. -// pool reference if a rewrite was needed.
  25602. -u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
  25603. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  25604. - const char * trace_mesg, TRAPS) {
  25605. -
  25606. - address cp_index_addr = (address)
  25607. - annotations_typeArray->byte_at_addr(byte_i_ref);
  25608. - u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
  25609. - u2 new_cp_index = find_new_index(old_cp_index);
  25610. - if (new_cp_index != 0) {
  25611. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index));
  25612. - Bytes::put_Java_u2(cp_index_addr, new_cp_index);
  25613. - old_cp_index = new_cp_index;
  25614. - }
  25615. - byte_i_ref += 2;
  25616. - return old_cp_index;
  25617. -}
  25618. -
  25619. -
  25620. -// Rewrite constant pool references in the element_value portion of an
  25621. -// annotations_typeArray. This "structure" is from section 4.8.15.1 of
  25622. -// the 2nd-edition of the VM spec:
  25623. -//
  25624. -// struct element_value {
  25625. -// u1 tag;
  25626. -// union {
  25627. -// u2 const_value_index;
  25628. -// {
  25629. -// u2 type_name_index;
  25630. -// u2 const_name_index;
  25631. -// } enum_const_value;
  25632. -// u2 class_info_index;
  25633. -// annotation annotation_value;
  25634. -// struct {
  25635. -// u2 num_values;
  25636. -// element_value values[num_values];
  25637. -// } array_value;
  25638. -// } value;
  25639. -// }
  25640. -//
  25641. -bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
  25642. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  25643. -
  25644. - if ((byte_i_ref + 1) > annotations_typeArray->length()) {
  25645. - // not enough room for a tag let alone the rest of an element_value
  25646. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25647. - ("length() is too small for a tag"));
  25648. - return false;
  25649. - }
  25650. -
  25651. - u1 tag = annotations_typeArray->byte_at(byte_i_ref);
  25652. - byte_i_ref++;
  25653. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
  25654. -
  25655. - switch (tag) {
  25656. - // These BaseType tag values are from Table 4.2 in VM spec:
  25657. - case 'B': // byte
  25658. - case 'C': // char
  25659. - case 'D': // double
  25660. - case 'F': // float
  25661. - case 'I': // int
  25662. - case 'J': // long
  25663. - case 'S': // short
  25664. - case 'Z': // boolean
  25665. -
  25666. - // The remaining tag values are from Table 4.8 in the 2nd-edition of
  25667. - // the VM spec:
  25668. - case 's':
  25669. - {
  25670. - // For the above tag values (including the BaseType values),
  25671. - // value.const_value_index is right union field.
  25672. -
  25673. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  25674. - // not enough room for a const_value_index
  25675. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25676. - ("length() is too small for a const_value_index"));
  25677. - return false;
  25678. - }
  25679. -
  25680. - u2 const_value_index = rewrite_cp_ref_in_annotation_data(
  25681. - annotations_typeArray, byte_i_ref,
  25682. - "mapped old const_value_index=%d", THREAD);
  25683. -
  25684. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25685. - ("const_value_index=%d", const_value_index));
  25686. - } break;
  25687. -
  25688. - case 'e':
  25689. - {
  25690. - // for the above tag value, value.enum_const_value is right union field
  25691. -
  25692. - if ((byte_i_ref + 4) > annotations_typeArray->length()) {
  25693. - // not enough room for a enum_const_value
  25694. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25695. - ("length() is too small for a enum_const_value"));
  25696. - return false;
  25697. - }
  25698. -
  25699. - u2 type_name_index = rewrite_cp_ref_in_annotation_data(
  25700. - annotations_typeArray, byte_i_ref,
  25701. - "mapped old type_name_index=%d", THREAD);
  25702. -
  25703. - u2 const_name_index = rewrite_cp_ref_in_annotation_data(
  25704. - annotations_typeArray, byte_i_ref,
  25705. - "mapped old const_name_index=%d", THREAD);
  25706. -
  25707. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25708. - ("type_name_index=%d const_name_index=%d", type_name_index,
  25709. - const_name_index));
  25710. - } break;
  25711. -
  25712. - case 'c':
  25713. - {
  25714. - // for the above tag value, value.class_info_index is right union field
  25715. -
  25716. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  25717. - // not enough room for a class_info_index
  25718. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25719. - ("length() is too small for a class_info_index"));
  25720. - return false;
  25721. - }
  25722. -
  25723. - u2 class_info_index = rewrite_cp_ref_in_annotation_data(
  25724. - annotations_typeArray, byte_i_ref,
  25725. - "mapped old class_info_index=%d", THREAD);
  25726. -
  25727. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25728. - ("class_info_index=%d", class_info_index));
  25729. - } break;
  25730. -
  25731. - case '@':
  25732. - // For the above tag value, value.attr_value is the right union
  25733. - // field. This is a nested annotation.
  25734. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  25735. - byte_i_ref, THREAD)) {
  25736. - // propagate failure back to caller
  25737. - return false;
  25738. - }
  25739. - break;
  25740. -
  25741. - case '[':
  25742. - {
  25743. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  25744. - // not enough room for a num_values field
  25745. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25746. - ("length() is too small for a num_values field"));
  25747. - return false;
  25748. - }
  25749. -
  25750. - // For the above tag value, value.array_value is the right union
  25751. - // field. This is an array of nested element_value.
  25752. - u2 num_values = Bytes::get_Java_u2((address)
  25753. - annotations_typeArray->byte_at_addr(byte_i_ref));
  25754. - byte_i_ref += 2;
  25755. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
  25756. -
  25757. - int calc_num_values = 0;
  25758. - for (; calc_num_values < num_values; calc_num_values++) {
  25759. - if (!rewrite_cp_refs_in_element_value(
  25760. - annotations_typeArray, byte_i_ref, THREAD)) {
  25761. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25762. - ("bad nested element_value at %d", calc_num_values));
  25763. - // propagate failure back to caller
  25764. - return false;
  25765. - }
  25766. - }
  25767. - assert(num_values == calc_num_values, "sanity check");
  25768. - } break;
  25769. -
  25770. - default:
  25771. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("bad tag=0x%x", tag));
  25772. - return false;
  25773. - } // end decode tag field
  25774. -
  25775. - return true;
  25776. -} // end rewrite_cp_refs_in_element_value()
  25777. -
  25778. -
  25779. -// Rewrite constant pool references in a fields_annotations field.
  25780. -bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
  25781. - instanceKlassHandle scratch_class, TRAPS) {
  25782. -
  25783. - objArrayHandle fields_annotations(THREAD,
  25784. - scratch_class->fields_annotations());
  25785. -
  25786. - if (fields_annotations.is_null() || fields_annotations->length() == 0) {
  25787. - // no fields_annotations so nothing to do
  25788. - return true;
  25789. - }
  25790. -
  25791. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25792. - ("fields_annotations length=%d", fields_annotations->length()));
  25793. -
  25794. - for (int i = 0; i < fields_annotations->length(); i++) {
  25795. - typeArrayHandle field_annotations(THREAD,
  25796. - (typeArrayOop)fields_annotations->obj_at(i));
  25797. - if (field_annotations.is_null() || field_annotations->length() == 0) {
  25798. - // this field does not have any annotations so skip it
  25799. - continue;
  25800. - }
  25801. -
  25802. - int byte_i = 0; // byte index into field_annotations
  25803. - if (!rewrite_cp_refs_in_annotations_typeArray(field_annotations, byte_i,
  25804. - THREAD)) {
  25805. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25806. - ("bad field_annotations at %d", i));
  25807. - // propagate failure back to caller
  25808. - return false;
  25809. - }
  25810. - }
  25811. -
  25812. - return true;
  25813. -} // end rewrite_cp_refs_in_fields_annotations()
  25814. -
  25815. -
  25816. -// Rewrite constant pool references in a methods_annotations field.
  25817. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
  25818. - instanceKlassHandle scratch_class, TRAPS) {
  25819. -
  25820. - objArrayHandle methods_annotations(THREAD,
  25821. - scratch_class->methods_annotations());
  25822. -
  25823. - if (methods_annotations.is_null() || methods_annotations->length() == 0) {
  25824. - // no methods_annotations so nothing to do
  25825. - return true;
  25826. - }
  25827. -
  25828. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25829. - ("methods_annotations length=%d", methods_annotations->length()));
  25830. -
  25831. - for (int i = 0; i < methods_annotations->length(); i++) {
  25832. - typeArrayHandle method_annotations(THREAD,
  25833. - (typeArrayOop)methods_annotations->obj_at(i));
  25834. - if (method_annotations.is_null() || method_annotations->length() == 0) {
  25835. - // this method does not have any annotations so skip it
  25836. - continue;
  25837. - }
  25838. -
  25839. - int byte_i = 0; // byte index into method_annotations
  25840. - if (!rewrite_cp_refs_in_annotations_typeArray(method_annotations, byte_i,
  25841. - THREAD)) {
  25842. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25843. - ("bad method_annotations at %d", i));
  25844. - // propagate failure back to caller
  25845. - return false;
  25846. - }
  25847. - }
  25848. -
  25849. - return true;
  25850. -} // end rewrite_cp_refs_in_methods_annotations()
  25851. -
  25852. -
  25853. -// Rewrite constant pool references in a methods_parameter_annotations
  25854. -// field. This "structure" is adapted from the
  25855. -// RuntimeVisibleParameterAnnotations_attribute described in section
  25856. -// 4.8.17 of the 2nd-edition of the VM spec:
  25857. -//
  25858. -// methods_parameter_annotations_typeArray {
  25859. -// u1 num_parameters;
  25860. -// {
  25861. -// u2 num_annotations;
  25862. -// annotation annotations[num_annotations];
  25863. -// } parameter_annotations[num_parameters];
  25864. -// }
  25865. -//
  25866. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
  25867. - instanceKlassHandle scratch_class, TRAPS) {
  25868. -
  25869. - objArrayHandle methods_parameter_annotations(THREAD,
  25870. - scratch_class->methods_parameter_annotations());
  25871. -
  25872. - if (methods_parameter_annotations.is_null()
  25873. - || methods_parameter_annotations->length() == 0) {
  25874. - // no methods_parameter_annotations so nothing to do
  25875. - return true;
  25876. - }
  25877. -
  25878. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25879. - ("methods_parameter_annotations length=%d",
  25880. - methods_parameter_annotations->length()));
  25881. -
  25882. - for (int i = 0; i < methods_parameter_annotations->length(); i++) {
  25883. - typeArrayHandle method_parameter_annotations(THREAD,
  25884. - (typeArrayOop)methods_parameter_annotations->obj_at(i));
  25885. - if (method_parameter_annotations.is_null()
  25886. - || method_parameter_annotations->length() == 0) {
  25887. - // this method does not have any parameter annotations so skip it
  25888. - continue;
  25889. - }
  25890. -
  25891. - if (method_parameter_annotations->length() < 1) {
  25892. - // not enough room for a num_parameters field
  25893. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25894. - ("length() is too small for a num_parameters field at %d", i));
  25895. - return false;
  25896. - }
  25897. -
  25898. - int byte_i = 0; // byte index into method_parameter_annotations
  25899. -
  25900. - u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
  25901. - byte_i++;
  25902. -
  25903. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25904. - ("num_parameters=%d", num_parameters));
  25905. -
  25906. - int calc_num_parameters = 0;
  25907. - for (; calc_num_parameters < num_parameters; calc_num_parameters++) {
  25908. - if (!rewrite_cp_refs_in_annotations_typeArray(
  25909. - method_parameter_annotations, byte_i, THREAD)) {
  25910. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25911. - ("bad method_parameter_annotations at %d", calc_num_parameters));
  25912. - // propagate failure back to caller
  25913. - return false;
  25914. - }
  25915. - }
  25916. - assert(num_parameters == calc_num_parameters, "sanity check");
  25917. - }
  25918. -
  25919. - return true;
  25920. -} // end rewrite_cp_refs_in_methods_parameter_annotations()
  25921. -
  25922. -
  25923. -// Rewrite constant pool references in a methods_default_annotations
  25924. -// field. This "structure" is adapted from the AnnotationDefault_attribute
  25925. -// that is described in section 4.8.19 of the 2nd-edition of the VM spec:
  25926. -//
  25927. -// methods_default_annotations_typeArray {
  25928. -// element_value default_value;
  25929. -// }
  25930. -//
  25931. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
  25932. - instanceKlassHandle scratch_class, TRAPS) {
  25933. -
  25934. - objArrayHandle methods_default_annotations(THREAD,
  25935. - scratch_class->methods_default_annotations());
  25936. -
  25937. - if (methods_default_annotations.is_null()
  25938. - || methods_default_annotations->length() == 0) {
  25939. - // no methods_default_annotations so nothing to do
  25940. - return true;
  25941. - }
  25942. -
  25943. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25944. - ("methods_default_annotations length=%d",
  25945. - methods_default_annotations->length()));
  25946. -
  25947. - for (int i = 0; i < methods_default_annotations->length(); i++) {
  25948. - typeArrayHandle method_default_annotations(THREAD,
  25949. - (typeArrayOop)methods_default_annotations->obj_at(i));
  25950. - if (method_default_annotations.is_null()
  25951. - || method_default_annotations->length() == 0) {
  25952. - // this method does not have any default annotations so skip it
  25953. - continue;
  25954. - }
  25955. -
  25956. - int byte_i = 0; // byte index into method_default_annotations
  25957. -
  25958. - if (!rewrite_cp_refs_in_element_value(
  25959. - method_default_annotations, byte_i, THREAD)) {
  25960. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  25961. - ("bad default element_value at %d", i));
  25962. - // propagate failure back to caller
  25963. - return false;
  25964. - }
  25965. - }
  25966. -
  25967. - return true;
  25968. -} // end rewrite_cp_refs_in_methods_default_annotations()
  25969. -
  25970. -
  25971. -// Rewrite constant pool references in the method's stackmap table.
  25972. -// These "structures" are adapted from the StackMapTable_attribute that
  25973. -// is described in section 4.8.4 of the 6.0 version of the VM spec
  25974. -// (dated 2005.10.26):
  25975. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  25976. -//
  25977. -// stack_map {
  25978. -// u2 number_of_entries;
  25979. -// stack_map_frame entries[number_of_entries];
  25980. -// }
  25981. -//
  25982. -void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table(
  25983. - methodHandle method, TRAPS) {
  25984. -
  25985. - if (!method->has_stackmap_table()) {
  25986. - return;
  25987. - }
  25988. -
  25989. - typeArrayOop stackmap_data = method->stackmap_data();
  25990. - address stackmap_p = (address)stackmap_data->byte_at_addr(0);
  25991. - address stackmap_end = stackmap_p + stackmap_data->length();
  25992. -
  25993. - assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
  25994. - u2 number_of_entries = Bytes::get_Java_u2(stackmap_p);
  25995. - stackmap_p += 2;
  25996. -
  25997. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  25998. - ("number_of_entries=%u", number_of_entries));
  25999. -
  26000. - // walk through each stack_map_frame
  26001. - u2 calc_number_of_entries = 0;
  26002. - for (; calc_number_of_entries < number_of_entries; calc_number_of_entries++) {
  26003. - // The stack_map_frame structure is a u1 frame_type followed by
  26004. - // 0 or more bytes of data:
  26005. - //
  26006. - // union stack_map_frame {
  26007. - // same_frame;
  26008. - // same_locals_1_stack_item_frame;
  26009. - // same_locals_1_stack_item_frame_extended;
  26010. - // chop_frame;
  26011. - // same_frame_extended;
  26012. - // append_frame;
  26013. - // full_frame;
  26014. - // }
  26015. -
  26016. - assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type");
  26017. - // The Linux compiler does not like frame_type to be u1 or u2. It
  26018. - // issues the following warning for the first if-statement below:
  26019. - //
  26020. - // "warning: comparison is always true due to limited range of data type"
  26021. - //
  26022. - u4 frame_type = *stackmap_p;
  26023. - stackmap_p++;
  26024. -
  26025. - // same_frame {
  26026. - // u1 frame_type = SAME; /* 0-63 */
  26027. - // }
  26028. - if (frame_type >= 0 && frame_type <= 63) {
  26029. - // nothing more to do for same_frame
  26030. - }
  26031. -
  26032. - // same_locals_1_stack_item_frame {
  26033. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
  26034. - // verification_type_info stack[1];
  26035. - // }
  26036. - else if (frame_type >= 64 && frame_type <= 127) {
  26037. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  26038. - calc_number_of_entries, frame_type, THREAD);
  26039. - }
  26040. -
  26041. - // reserved for future use
  26042. - else if (frame_type >= 128 && frame_type <= 246) {
  26043. - // nothing more to do for reserved frame_types
  26044. - }
  26045. -
  26046. - // same_locals_1_stack_item_frame_extended {
  26047. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
  26048. - // u2 offset_delta;
  26049. - // verification_type_info stack[1];
  26050. - // }
  26051. - else if (frame_type == 247) {
  26052. - stackmap_p += 2;
  26053. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  26054. - calc_number_of_entries, frame_type, THREAD);
  26055. - }
  26056. -
  26057. - // chop_frame {
  26058. - // u1 frame_type = CHOP; /* 248-250 */
  26059. - // u2 offset_delta;
  26060. - // }
  26061. - else if (frame_type >= 248 && frame_type <= 250) {
  26062. - stackmap_p += 2;
  26063. - }
  26064. -
  26065. - // same_frame_extended {
  26066. - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251*/
  26067. - // u2 offset_delta;
  26068. - // }
  26069. - else if (frame_type == 251) {
  26070. - stackmap_p += 2;
  26071. - }
  26072. -
  26073. - // append_frame {
  26074. - // u1 frame_type = APPEND; /* 252-254 */
  26075. - // u2 offset_delta;
  26076. - // verification_type_info locals[frame_type - 251];
  26077. - // }
  26078. - else if (frame_type >= 252 && frame_type <= 254) {
  26079. - assert(stackmap_p + 2 <= stackmap_end,
  26080. - "no room for offset_delta");
  26081. - stackmap_p += 2;
  26082. - u1 len = frame_type - 251;
  26083. - for (u1 i = 0; i < len; i++) {
  26084. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  26085. - calc_number_of_entries, frame_type, THREAD);
  26086. - }
  26087. - }
  26088. -
  26089. - // full_frame {
  26090. - // u1 frame_type = FULL_FRAME; /* 255 */
  26091. - // u2 offset_delta;
  26092. - // u2 number_of_locals;
  26093. - // verification_type_info locals[number_of_locals];
  26094. - // u2 number_of_stack_items;
  26095. - // verification_type_info stack[number_of_stack_items];
  26096. - // }
  26097. - else if (frame_type == 255) {
  26098. - assert(stackmap_p + 2 + 2 <= stackmap_end,
  26099. - "no room for smallest full_frame");
  26100. - stackmap_p += 2;
  26101. -
  26102. - u2 number_of_locals = Bytes::get_Java_u2(stackmap_p);
  26103. - stackmap_p += 2;
  26104. -
  26105. - for (u2 locals_i = 0; locals_i < number_of_locals; locals_i++) {
  26106. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  26107. - calc_number_of_entries, frame_type, THREAD);
  26108. - }
  26109. -
  26110. - // Use the largest size for the number_of_stack_items, but only get
  26111. - // the right number of bytes.
  26112. - u2 number_of_stack_items = Bytes::get_Java_u2(stackmap_p);
  26113. - stackmap_p += 2;
  26114. -
  26115. - for (u2 stack_i = 0; stack_i < number_of_stack_items; stack_i++) {
  26116. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  26117. - calc_number_of_entries, frame_type, THREAD);
  26118. - }
  26119. - }
  26120. - } // end while there is a stack_map_frame
  26121. - assert(number_of_entries == calc_number_of_entries, "sanity check");
  26122. -} // end rewrite_cp_refs_in_stack_map_table()
  26123. -
  26124. -
  26125. -// Rewrite constant pool references in the verification type info
  26126. -// portion of the method's stackmap table. These "structures" are
  26127. -// adapted from the StackMapTable_attribute that is described in
  26128. -// section 4.8.4 of the 6.0 version of the VM spec (dated 2005.10.26):
  26129. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  26130. -//
  26131. -// The verification_type_info structure is a u1 tag followed by 0 or
  26132. -// more bytes of data:
  26133. -//
  26134. -// union verification_type_info {
  26135. -// Top_variable_info;
  26136. -// Integer_variable_info;
  26137. -// Float_variable_info;
  26138. -// Long_variable_info;
  26139. -// Double_variable_info;
  26140. -// Null_variable_info;
  26141. -// UninitializedThis_variable_info;
  26142. -// Object_variable_info;
  26143. -// Uninitialized_variable_info;
  26144. -// }
  26145. -//
  26146. -void VM_RedefineClasses::rewrite_cp_refs_in_verification_type_info(
  26147. - address& stackmap_p_ref, address stackmap_end, u2 frame_i,
  26148. - u1 frame_type, TRAPS) {
  26149. -
  26150. - assert(stackmap_p_ref + 1 <= stackmap_end, "no room for tag");
  26151. - u1 tag = *stackmap_p_ref;
  26152. - stackmap_p_ref++;
  26153. -
  26154. - switch (tag) {
  26155. - // Top_variable_info {
  26156. - // u1 tag = ITEM_Top; /* 0 */
  26157. - // }
  26158. - // verificationType.hpp has zero as ITEM_Bogus instead of ITEM_Top
  26159. - case 0: // fall through
  26160. -
  26161. - // Integer_variable_info {
  26162. - // u1 tag = ITEM_Integer; /* 1 */
  26163. - // }
  26164. - case ITEM_Integer: // fall through
  26165. -
  26166. - // Float_variable_info {
  26167. - // u1 tag = ITEM_Float; /* 2 */
  26168. - // }
  26169. - case ITEM_Float: // fall through
  26170. -
  26171. - // Double_variable_info {
  26172. - // u1 tag = ITEM_Double; /* 3 */
  26173. - // }
  26174. - case ITEM_Double: // fall through
  26175. -
  26176. - // Long_variable_info {
  26177. - // u1 tag = ITEM_Long; /* 4 */
  26178. - // }
  26179. - case ITEM_Long: // fall through
  26180. -
  26181. - // Null_variable_info {
  26182. - // u1 tag = ITEM_Null; /* 5 */
  26183. - // }
  26184. - case ITEM_Null: // fall through
  26185. -
  26186. - // UninitializedThis_variable_info {
  26187. - // u1 tag = ITEM_UninitializedThis; /* 6 */
  26188. - // }
  26189. - case ITEM_UninitializedThis:
  26190. - // nothing more to do for the above tag types
  26191. - break;
  26192. -
  26193. - // Object_variable_info {
  26194. - // u1 tag = ITEM_Object; /* 7 */
  26195. - // u2 cpool_index;
  26196. - // }
  26197. - case ITEM_Object:
  26198. - {
  26199. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for cpool_index");
  26200. - u2 cpool_index = Bytes::get_Java_u2(stackmap_p_ref);
  26201. - u2 new_cp_index = find_new_index(cpool_index);
  26202. - if (new_cp_index != 0) {
  26203. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  26204. - ("mapped old cpool_index=%d", cpool_index));
  26205. - Bytes::put_Java_u2(stackmap_p_ref, new_cp_index);
  26206. - cpool_index = new_cp_index;
  26207. - }
  26208. - stackmap_p_ref += 2;
  26209. -
  26210. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  26211. - ("frame_i=%u, frame_type=%u, cpool_index=%d", frame_i,
  26212. - frame_type, cpool_index));
  26213. - } break;
  26214. -
  26215. - // Uninitialized_variable_info {
  26216. - // u1 tag = ITEM_Uninitialized; /* 8 */
  26217. - // u2 offset;
  26218. - // }
  26219. - case ITEM_Uninitialized:
  26220. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for offset");
  26221. - stackmap_p_ref += 2;
  26222. - break;
  26223. -
  26224. - default:
  26225. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  26226. - ("frame_i=%u, frame_type=%u, bad tag=0x%x", frame_i, frame_type, tag));
  26227. - ShouldNotReachHere();
  26228. - break;
  26229. - } // end switch (tag)
  26230. -} // end rewrite_cp_refs_in_verification_type_info()
  26231. -
  26232. -
  26233. -// Change the constant pool associated with klass scratch_class to
  26234. -// scratch_cp. If shrink is true, then scratch_cp_length elements
  26235. -// are copied from scratch_cp to a smaller constant pool and the
  26236. -// smaller constant pool is associated with scratch_class.
  26237. -void VM_RedefineClasses::set_new_constant_pool(
  26238. - instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
  26239. - int scratch_cp_length, bool shrink, TRAPS) {
  26240. - assert(!shrink || scratch_cp->length() >= scratch_cp_length, "sanity check");
  26241. -
  26242. - if (shrink) {
  26243. - // scratch_cp is a merged constant pool and has enough space for a
  26244. - // worst case merge situation. We want to associate the minimum
  26245. - // sized constant pool with the klass to save space.
  26246. - constantPoolHandle smaller_cp(THREAD,
  26247. - oopFactory::new_constantPool(scratch_cp_length,
  26248. - methodOopDesc::IsUnsafeConc,
  26249. - THREAD));
  26250. - // preserve orig_length() value in the smaller copy
  26251. - int orig_length = scratch_cp->orig_length();
  26252. - assert(orig_length != 0, "sanity check");
  26253. - smaller_cp->set_orig_length(orig_length);
  26254. - scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  26255. - scratch_cp = smaller_cp;
  26256. - smaller_cp()->set_is_conc_safe(true);
  26257. - }
  26258. -
  26259. - // attach new constant pool to klass
  26260. - scratch_cp->set_pool_holder(scratch_class());
  26261. -
  26262. - // attach klass to new constant pool
  26263. - scratch_class->set_constants(scratch_cp());
  26264. -
  26265. - int i; // for portability
  26266. -
  26267. - // update each field in klass to use new constant pool indices as needed
  26268. - typeArrayHandle fields(THREAD, scratch_class->fields());
  26269. - int n_fields = fields->length();
  26270. - for (i = 0; i < n_fields; i += instanceKlass::next_offset) {
  26271. - jshort cur_index = fields->short_at(i + instanceKlass::name_index_offset);
  26272. - jshort new_index = find_new_index(cur_index);
  26273. - if (new_index != 0) {
  26274. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  26275. - ("field-name_index change: %d to %d", cur_index, new_index));
  26276. - fields->short_at_put(i + instanceKlass::name_index_offset, new_index);
  26277. - }
  26278. - cur_index = fields->short_at(i + instanceKlass::signature_index_offset);
  26279. - new_index = find_new_index(cur_index);
  26280. - if (new_index != 0) {
  26281. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  26282. - ("field-signature_index change: %d to %d", cur_index, new_index));
  26283. - fields->short_at_put(i + instanceKlass::signature_index_offset,
  26284. - new_index);
  26285. - }
  26286. - cur_index = fields->short_at(i + instanceKlass::initval_index_offset);
  26287. - new_index = find_new_index(cur_index);
  26288. - if (new_index != 0) {
  26289. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  26290. - ("field-initval_index change: %d to %d", cur_index, new_index));
  26291. - fields->short_at_put(i + instanceKlass::initval_index_offset, new_index);
  26292. - }
  26293. - cur_index = fields->short_at(i + instanceKlass::generic_signature_offset);
  26294. - new_index = find_new_index(cur_index);
  26295. - if (new_index != 0) {
  26296. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  26297. - ("field-generic_signature change: %d to %d", cur_index, new_index));
  26298. - fields->short_at_put(i + instanceKlass::generic_signature_offset,
  26299. - new_index);
  26300. - }
  26301. - } // end for each field
  26302. -
  26303. - // Update constant pool indices in the inner classes info to use
  26304. - // new constant indices as needed. The inner classes info is a
  26305. - // quadruple:
  26306. - // (inner_class_info, outer_class_info, inner_name, inner_access_flags)
  26307. - typeArrayOop inner_class_list = scratch_class->inner_classes();
  26308. - int icl_length = (inner_class_list == NULL) ? 0 : inner_class_list->length();
  26309. - if (icl_length > 0) {
  26310. - typeArrayHandle inner_class_list_h(THREAD, inner_class_list);
  26311. - for (int i = 0; i < icl_length;
  26312. - i += instanceKlass::inner_class_next_offset) {
  26313. - int cur_index = inner_class_list_h->ushort_at(i
  26314. - + instanceKlass::inner_class_inner_class_info_offset);
  26315. - if (cur_index == 0) {
  26316. - continue; // JVM spec. allows null inner class refs so skip it
  26317. - }
  26318. - int new_index = find_new_index(cur_index);
  26319. - if (new_index != 0) {
  26320. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  26321. - ("inner_class_info change: %d to %d", cur_index, new_index));
  26322. - inner_class_list_h->ushort_at_put(i
  26323. - + instanceKlass::inner_class_inner_class_info_offset, new_index);
  26324. - }
  26325. - cur_index = inner_class_list_h->ushort_at(i
  26326. - + instanceKlass::inner_class_outer_class_info_offset);
  26327. - new_index = find_new_index(cur_index);
  26328. - if (new_index != 0) {
  26329. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  26330. - ("outer_class_info change: %d to %d", cur_index, new_index));
  26331. - inner_class_list_h->ushort_at_put(i
  26332. - + instanceKlass::inner_class_outer_class_info_offset, new_index);
  26333. - }
  26334. - cur_index = inner_class_list_h->ushort_at(i
  26335. - + instanceKlass::inner_class_inner_name_offset);
  26336. - new_index = find_new_index(cur_index);
  26337. - if (new_index != 0) {
  26338. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  26339. - ("inner_name change: %d to %d", cur_index, new_index));
  26340. - inner_class_list_h->ushort_at_put(i
  26341. - + instanceKlass::inner_class_inner_name_offset, new_index);
  26342. - }
  26343. - } // end for each inner class
  26344. - } // end if we have inner classes
  26345. -
  26346. - // Attach each method in klass to the new constant pool and update
  26347. - // to use new constant pool indices as needed:
  26348. - objArrayHandle methods(THREAD, scratch_class->methods());
  26349. - for (i = methods->length() - 1; i >= 0; i--) {
  26350. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  26351. - method->set_constants(scratch_cp());
  26352. -
  26353. - int new_index = find_new_index(method->name_index());
  26354. - if (new_index != 0) {
  26355. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  26356. - ("method-name_index change: %d to %d", method->name_index(),
  26357. - new_index));
  26358. - method->set_name_index(new_index);
  26359. - }
  26360. - new_index = find_new_index(method->signature_index());
  26361. - if (new_index != 0) {
  26362. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  26363. - ("method-signature_index change: %d to %d",
  26364. - method->signature_index(), new_index));
  26365. - method->set_signature_index(new_index);
  26366. - }
  26367. - new_index = find_new_index(method->generic_signature_index());
  26368. - if (new_index != 0) {
  26369. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  26370. - ("method-generic_signature_index change: %d to %d",
  26371. - method->generic_signature_index(), new_index));
  26372. - method->set_generic_signature_index(new_index);
  26373. - }
  26374. -
  26375. - // Update constant pool indices in the method's checked exception
  26376. - // table to use new constant indices as needed.
  26377. - int cext_length = method->checked_exceptions_length();
  26378. - if (cext_length > 0) {
  26379. - CheckedExceptionElement * cext_table =
  26380. - method->checked_exceptions_start();
  26381. - for (int j = 0; j < cext_length; j++) {
  26382. - int cur_index = cext_table[j].class_cp_index;
  26383. - int new_index = find_new_index(cur_index);
  26384. - if (new_index != 0) {
  26385. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  26386. - ("cext-class_cp_index change: %d to %d", cur_index, new_index));
  26387. - cext_table[j].class_cp_index = (u2)new_index;
  26388. - }
  26389. - } // end for each checked exception table entry
  26390. - } // end if there are checked exception table entries
  26391. -
  26392. - // Update each catch type index in the method's exception table
  26393. - // to use new constant pool indices as needed. The exception table
  26394. - // holds quadruple entries of the form:
  26395. - // (beg_bci, end_bci, handler_bci, klass_index)
  26396. - const int beg_bci_offset = 0;
  26397. - const int end_bci_offset = 1;
  26398. - const int handler_bci_offset = 2;
  26399. - const int klass_index_offset = 3;
  26400. - const int entry_size = 4;
  26401. -
  26402. - typeArrayHandle ex_table (THREAD, method->exception_table());
  26403. - int ext_length = ex_table->length();
  26404. - assert(ext_length % entry_size == 0, "exception table format has changed");
  26405. -
  26406. - for (int j = 0; j < ext_length; j += entry_size) {
  26407. - int cur_index = ex_table->int_at(j + klass_index_offset);
  26408. - int new_index = find_new_index(cur_index);
  26409. - if (new_index != 0) {
  26410. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  26411. - ("ext-klass_index change: %d to %d", cur_index, new_index));
  26412. - ex_table->int_at_put(j + klass_index_offset, new_index);
  26413. - }
  26414. - } // end for each exception table entry
  26415. -
  26416. - // Update constant pool indices in the method's local variable
  26417. - // table to use new constant indices as needed. The local variable
  26418. - // table hold sextuple entries of the form:
  26419. - // (start_pc, length, name_index, descriptor_index, signature_index, slot)
  26420. - int lvt_length = method->localvariable_table_length();
  26421. - if (lvt_length > 0) {
  26422. - LocalVariableTableElement * lv_table =
  26423. - method->localvariable_table_start();
  26424. - for (int j = 0; j < lvt_length; j++) {
  26425. - int cur_index = lv_table[j].name_cp_index;
  26426. - int new_index = find_new_index(cur_index);
  26427. - if (new_index != 0) {
  26428. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  26429. - ("lvt-name_cp_index change: %d to %d", cur_index, new_index));
  26430. - lv_table[j].name_cp_index = (u2)new_index;
  26431. - }
  26432. - cur_index = lv_table[j].descriptor_cp_index;
  26433. - new_index = find_new_index(cur_index);
  26434. - if (new_index != 0) {
  26435. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  26436. - ("lvt-descriptor_cp_index change: %d to %d", cur_index,
  26437. - new_index));
  26438. - lv_table[j].descriptor_cp_index = (u2)new_index;
  26439. - }
  26440. - cur_index = lv_table[j].signature_cp_index;
  26441. - new_index = find_new_index(cur_index);
  26442. - if (new_index != 0) {
  26443. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  26444. - ("lvt-signature_cp_index change: %d to %d", cur_index, new_index));
  26445. - lv_table[j].signature_cp_index = (u2)new_index;
  26446. - }
  26447. - } // end for each local variable table entry
  26448. - } // end if there are local variable table entries
  26449. -
  26450. - rewrite_cp_refs_in_stack_map_table(method, THREAD);
  26451. - } // end for each method
  26452. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  26453. -} // end set_new_constant_pool()
  26454. -
  26455. -
  26456. -// Unevolving classes may point to methods of the_class directly
  26457. +#endif
  26458. +
  26459. +
  26460. +// Unevolving classes may point to old methods directly
  26461. // from their constant pool caches, itables, and/or vtables. We
  26462. // use the SystemDictionary::classes_do() facility and this helper
  26463. -// to fix up these pointers.
  26464. +// to fix up these pointers. Additional field offsets and vtable indices
  26465. +// in the constant pool cache entries are fixed.
  26466. //
  26467. // Note: We currently don't support updating the vtable in
  26468. // arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  26469. -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  26470. - oop initiating_loader, TRAPS) {
  26471. +void VM_RedefineClasses::adjust_cpool_cache(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  26472. + klassOop k_oop = k_oop_latest;
  26473. + while (k_oop != NULL) {
  26474. + //tty->print_cr("name=%s", k_oop->klass_part()->name()->as_C_string());
  26475. +/*
  26476. + methodOop *matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  26477. + methodOop *matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  26478. +
  26479. + for (int i=0; i<_matching_methods_length; i++) {
  26480. + matching_old_methods[i] = (methodOop)_old_methods->obj_at(_matching_old_methods[i]);
  26481. + matching_new_methods[i] = (methodOop)_new_methods->obj_at(_matching_new_methods[i]);
  26482. + }*/
  26483. +
  26484. + Klass *k = k_oop->klass_part();
  26485. + if (k->oop_is_instance()) {
  26486. + HandleMark hm(THREAD);
  26487. + instanceKlass *ik = (instanceKlass *) k;
  26488. +
  26489. + constantPoolHandle other_cp;
  26490. + constantPoolCacheOop cp_cache;
  26491. +
  26492. + other_cp = constantPoolHandle(ik->constants());
  26493. +
  26494. + for (int i=0; i<other_cp->length(); i++) {
  26495. + if (other_cp->tag_at(i).is_klass()) {
  26496. + klassOop klass = other_cp->klass_at(i, THREAD);
  26497. + if (klass->klass_part()->new_version() != NULL) {
  26498. +
  26499. + // (tw) TODO: check why/if this is necessary
  26500. + other_cp->klass_at_put(i, klass->klass_part()->new_version());
  26501. + }
  26502. + klass = other_cp->klass_at(i, THREAD);
  26503. + assert(klass->klass_part()->new_version() == NULL, "Must be new klass!");
  26504. + }
  26505. + }
  26506. +
  26507. + cp_cache = other_cp->cache();
  26508. +
  26509. + if (cp_cache != NULL) {
  26510. + cp_cache->adjust_entries(NULL,
  26511. + NULL,
  26512. + 0);
  26513. + }
  26514. + }
  26515. + k_oop = k_oop->klass_part()->old_version();
  26516. + }
  26517. +}
  26518. +
  26519. +void VM_RedefineClasses::update_jmethod_ids() {
  26520. + for (int j = 0; j < _matching_methods_length; ++j) {
  26521. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  26522. + TRACE_RC3("matching method %s", old_method->name_and_sig_as_C_string());
  26523. +
  26524. + jmethodID jmid = old_method->find_jmethod_id_or_null();
  26525. + if (old_method->new_version() != NULL && jmid == NULL) {
  26526. + // (tw) Have to create jmethodID in this case
  26527. + jmid = old_method->jmethod_id();
  26528. + }
  26529. +
  26530. + if (jmid != NULL) {
  26531. + // There is a jmethodID, change it to point to the new method
  26532. + methodHandle new_method_h((methodOop)_new_methods->obj_at(_matching_new_methods[j]));
  26533. + if (old_method->new_version() == NULL) {
  26534. + methodHandle old_method_h((methodOop)_old_methods->obj_at(_matching_old_methods[j]));
  26535. + jmethodID new_jmethod_id = JNIHandles::make_jmethod_id(old_method_h);
  26536. + bool result = instanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  26537. + //TRACE_RC3("Changed jmethodID for old method assigned to %d / result=%d", new_jmethod_id, result);
  26538. + //TRACE_RC3("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  26539. + } else {
  26540. + jmethodID mid = new_method_h->jmethod_id();
  26541. + bool result = instanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  26542. + //TRACE_RC3("Changed jmethodID for new method assigned to %d / result=%d", jmid, result);
  26543. +
  26544. + }
  26545. + JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  26546. + //TRACE_RC3("changing method associated with jmethod id %d to %s", (int)jmid, new_method_h->name()->as_C_string());
  26547. + assert(JNIHandles::resolve_jmethod_id(jmid) == (methodOop)_new_methods->obj_at(_matching_new_methods[j]), "should be replaced");
  26548. + jmethodID mid = ((methodOop)_new_methods->obj_at(_matching_new_methods[j]))->jmethod_id();
  26549. + assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  26550. +
  26551. + //TRACE_RC3("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  26552. + }
  26553. + }
  26554. +}
  26555. +
  26556. +
  26557. +// Deoptimize all compiled code that depends on this class.
  26558. +//
  26559. +// If the can_redefine_classes capability is obtained in the onload
  26560. +// phase then the compiler has recorded all dependencies from startup.
  26561. +// In that case we need only deoptimize and throw away all compiled code
  26562. +// that depends on the class.
  26563. +//
  26564. +// If can_redefine_classes is obtained sometime after the onload
  26565. +// phase then the dependency information may be incomplete. In that case
  26566. +// the first call to RedefineClasses causes all compiled code to be
  26567. +// thrown away. As can_redefine_classes has been obtained then
  26568. +// all future compilations will record dependencies so second and
  26569. +// subsequent calls to RedefineClasses need only throw away code
  26570. +// that depends on the class.
  26571. +//
  26572. +void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  26573. + assert_locked_or_safepoint(Compile_lock);
  26574. +
  26575. + // All dependencies have been recorded from startup or this is a second or
  26576. + // subsequent use of RedefineClasses
  26577. +
  26578. + // For now deopt all
  26579. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  26580. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  26581. + Universe::flush_evol_dependents_on(k_h);
  26582. + } else {
  26583. + CodeCache::mark_all_nmethods_for_deoptimization();
  26584. +
  26585. + ResourceMark rm(THREAD);
  26586. + DeoptimizationMarker dm;
  26587. +
  26588. + // Deoptimize all activations depending on marked nmethods
  26589. + Deoptimization::deoptimize_dependents();
  26590. +
  26591. + // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  26592. + CodeCache::make_marked_nmethods_not_entrant();
  26593. +
  26594. + // From now on we know that the dependency information is complete
  26595. + JvmtiExport::set_all_dependencies_are_recorded(true);
  26596. + }
  26597. +}
  26598. +
  26599. +void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  26600. + methodOop old_method;
  26601. + methodOop new_method;
  26602. +
  26603. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  26604. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  26605. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  26606. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  26607. +
  26608. + _matching_methods_length = 0;
  26609. + _deleted_methods_length = 0;
  26610. + _added_methods_length = 0;
  26611. +
  26612. + int nj = 0;
  26613. + int oj = 0;
  26614. + while (true) {
  26615. + if (oj >= _old_methods->length()) {
  26616. + if (nj >= _new_methods->length()) {
  26617. + break; // we've looked at everything, done
  26618. + }
  26619. + // New method at the end
  26620. + new_method = (methodOop) _new_methods->obj_at(nj);
  26621. + _added_methods[_added_methods_length++] = nj;
  26622. + ++nj;
  26623. + } else if (nj >= _new_methods->length()) {
  26624. + // Old method, at the end, is deleted
  26625. + old_method = (methodOop) _old_methods->obj_at(oj);
  26626. + _deleted_methods[_deleted_methods_length++] = oj;
  26627. + ++oj;
  26628. + } else {
  26629. + old_method = (methodOop) _old_methods->obj_at(oj);
  26630. + new_method = (methodOop) _new_methods->obj_at(nj);
  26631. + if (old_method->name() == new_method->name()) {
  26632. + if (old_method->signature() == new_method->signature()) {
  26633. + _matching_old_methods[_matching_methods_length ] = oj;//old_method;
  26634. + _matching_new_methods[_matching_methods_length++] = nj;//new_method;
  26635. + ++nj;
  26636. + ++oj;
  26637. + } else {
  26638. + // added overloaded have already been moved to the end,
  26639. + // so this is a deleted overloaded method
  26640. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  26641. + ++oj;
  26642. + }
  26643. + } else { // names don't match
  26644. + if (old_method->name()->fast_compare(new_method->name()) > 0) {
  26645. + // new method
  26646. + _added_methods[_added_methods_length++] = nj;//new_method;
  26647. + ++nj;
  26648. + } else {
  26649. + // deleted method
  26650. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  26651. + ++oj;
  26652. + }
  26653. + }
  26654. + }
  26655. + }
  26656. + assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  26657. + assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  26658. + TRACE_RC3("Matching methods = %d / deleted methods = %d / added methods = %d", _matching_methods_length, _deleted_methods_length, _added_methods_length);
  26659. +}
  26660. +
  26661. +
  26662. +
  26663. +// Install the redefinition of a class:
  26664. +// - house keeping (flushing breakpoints and caches, deoptimizing
  26665. +// dependent compiled code)
  26666. +// - adjusting constant pool caches and vtables in other classes
  26667. +void VM_RedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  26668. +
  26669. + ResourceMark rm(THREAD);
  26670. +
  26671. + assert(the_new_class->old_version() != NULL, "Must not be null");
  26672. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  26673. +
  26674. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  26675. +
  26676. +#ifndef JVMTI_KERNEL
  26677. + // Remove all breakpoints in methods of this class
  26678. + JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  26679. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  26680. +#endif // !JVMTI_KERNEL
  26681. +
  26682. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  26683. + // We are redefining java.lang.reflect.Method. Method.invoke() is
  26684. + // cached and users of the cache care about each active version of
  26685. + // the method so we have to track this previous version.
  26686. + // Do this before methods get switched
  26687. + Universe::reflect_invoke_cache()->add_previous_version(
  26688. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  26689. + }
  26690. +
  26691. + _old_methods = the_old_class->methods();
  26692. + _new_methods = the_new_class->methods();
  26693. + _the_class_oop = the_old_class();
  26694. + compute_added_deleted_matching_methods();
  26695. +
  26696. + // track which methods are EMCP for add_previous_version() call below
  26697. +
  26698. + // (tw) TODO: Check if we need the concept of EMCP?
  26699. + BitMap emcp_methods(_old_methods->length());
  26700. + int emcp_method_count = 0;
  26701. + emcp_methods.clear(); // clears 0..(length() - 1)
  26702. +
  26703. + // We need to mark methods as old!!
  26704. + check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  26705. + update_jmethod_ids();
  26706. +
  26707. + // keep track of previous versions of this class
  26708. + the_new_class->add_previous_version(the_old_class, &emcp_methods,
  26709. + emcp_method_count);
  26710. +
  26711. + // TODO:
  26712. + transfer_old_native_function_registrations(the_old_class);
  26713. +
  26714. +
  26715. +
  26716. +#ifdef ASSERT
  26717. +
  26718. +// klassOop systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  26719. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  26720. +
  26721. + //JNIHandles::verify();
  26722. +
  26723. +// klassOop systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  26724. +
  26725. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  26726. + assert(the_new_class->old_version() != NULL, "Must not be null");
  26727. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  26728. +
  26729. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  26730. + assert(((methodOop)the_new_class->methods()->obj_at(i))->method_holder() == the_new_class(), "method holder must match!");
  26731. + }
  26732. +
  26733. + _old_methods->verify();
  26734. + _new_methods->verify();
  26735. +
  26736. + the_new_class->vtable()->verify(tty);
  26737. + the_old_class->vtable()->verify(tty);
  26738. +
  26739. +#endif
  26740. +
  26741. + // increment the classRedefinedCount field in the_class and in any
  26742. + // direct and indirect subclasses of the_class
  26743. + increment_class_counter((instanceKlass *)the_old_class()->klass_part(), THREAD);
  26744. +
  26745. +}
  26746. +
  26747. +
  26748. +void VM_RedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  26749. + TRACE_RC3("Checking matching methods for EMCP");
  26750. + *emcp_method_count_p = 0;
  26751. + int obsolete_count = 0;
  26752. + int old_index = 0;
  26753. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  26754. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  26755. + methodOop new_method = (methodOop)_new_methods->obj_at(_matching_new_methods[j]);
  26756. + methodOop old_array_method;
  26757. +
  26758. + // Maintain an old_index into the _old_methods array by skipping
  26759. + // deleted methods
  26760. + while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  26761. + != old_method) {
  26762. + ++old_index;
  26763. + }
  26764. +
  26765. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  26766. + // The EMCP definition from JSR-163 requires the bytecodes to be
  26767. + // the same with the exception of constant pool indices which may
  26768. + // differ. However, the constants referred to by those indices
  26769. + // must be the same.
  26770. + //
  26771. + // We use methods_EMCP() for comparison since constant pool
  26772. + // merging can remove duplicate constant pool entries that were
  26773. + // present in the old method and removed from the rewritten new
  26774. + // method. A faster binary comparison function would consider the
  26775. + // old and new methods to be different when they are actually
  26776. + // EMCP.
  26777. +
  26778. + // track which methods are EMCP for add_previous_version() call
  26779. + emcp_methods->set_bit(old_index);
  26780. + (*emcp_method_count_p)++;
  26781. +
  26782. + // An EMCP method is _not_ obsolete. An obsolete method has a
  26783. + // different jmethodID than the current method. An EMCP method
  26784. + // has the same jmethodID as the current method. Having the
  26785. + // same jmethodID for all EMCP versions of a method allows for
  26786. + // a consistent view of the EMCP methods regardless of which
  26787. + // EMCP method you happen to have in hand. For example, a
  26788. + // breakpoint set in one EMCP method will work for all EMCP
  26789. + // versions of the method including the current one.
  26790. +
  26791. + old_method->set_new_version(new_method);
  26792. + new_method->set_old_version(old_method);
  26793. +
  26794. + TRACE_RC3("Found EMCP method %s", old_method->name_and_sig_as_C_string());
  26795. +
  26796. + // Transfer breakpoints
  26797. + instanceKlass *ik = instanceKlass::cast(old_method->method_holder());
  26798. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  26799. + TRACE_RC2("Checking breakpoint");
  26800. + TRACE_RC2("%d / %d", bp->match(old_method), bp->match(new_method));
  26801. + if (bp->match(old_method)) {
  26802. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  26803. + TRACE_RC2("Found a breakpoint in an old EMCP method");
  26804. + new_method->set_breakpoint(bp->bci());
  26805. + }
  26806. + }
  26807. +
  26808. +
  26809. +
  26810. + } else {
  26811. + // mark obsolete methods as such
  26812. + old_method->set_is_obsolete();
  26813. + obsolete_count++;
  26814. +
  26815. + // With tracing we try not to "yack" too much. The position of
  26816. + // this trace assumes there are fewer obsolete methods than
  26817. + // EMCP methods.
  26818. + TRACE_RC3("mark %s(%s) as obsolete",
  26819. + old_method->name()->as_C_string(),
  26820. + old_method->signature()->as_C_string());
  26821. + }
  26822. + old_method->set_is_old();
  26823. + }
  26824. + for (int i = 0; i < _deleted_methods_length; ++i) {
  26825. + methodOop old_method = (methodOop)_old_methods->obj_at(_deleted_methods[i]);
  26826. +
  26827. + //assert(old_method->vtable_index() < 0,
  26828. + // "cannot delete methods with vtable entries");;
  26829. +
  26830. + // Mark all deleted methods as old and obsolete
  26831. + old_method->set_is_old();
  26832. + old_method->set_is_obsolete();
  26833. + ++obsolete_count;
  26834. + // With tracing we try not to "yack" too much. The position of
  26835. + // this trace assumes there are fewer obsolete methods than
  26836. + // EMCP methods.
  26837. + TRACE_RC3("mark deleted %s(%s) as obsolete",
  26838. + old_method->name()->as_C_string(),
  26839. + old_method->signature()->as_C_string());
  26840. + }
  26841. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  26842. + TRACE_RC3("EMCP_cnt=%d, obsolete_cnt=%d !", *emcp_method_count_p, obsolete_count);
  26843. +}
  26844. +
  26845. +// Increment the classRedefinedCount field in the specific instanceKlass
  26846. +// and in all direct and indirect subclasses.
  26847. +void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  26848. + oop class_mirror = ik->java_mirror();
  26849. + klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  26850. + int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  26851. + java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  26852. + TRACE_RC3("updated count for class=%s to %d", ik->external_name(), new_count);
  26853. +}
  26854. +
  26855. +#ifndef PRODUCT
  26856. +void VM_RedefineClasses::check_class(klassOop k_oop, TRAPS) {
  26857. Klass *k = k_oop->klass_part();
  26858. if (k->oop_is_instance()) {
  26859. HandleMark hm(THREAD);
  26860. instanceKlass *ik = (instanceKlass *) k;
  26861. -
  26862. - // HotSpot specific optimization! HotSpot does not currently
  26863. - // support delegation from the bootstrap class loader to a
  26864. - // user-defined class loader. This means that if the bootstrap
  26865. - // class loader is the initiating class loader, then it will also
  26866. - // be the defining class loader. This also means that classes
  26867. - // loaded by the bootstrap class loader cannot refer to classes
  26868. - // loaded by a user-defined class loader. Note: a user-defined
  26869. - // class loader can delegate to the bootstrap class loader.
  26870. - //
  26871. - // If the current class being redefined has a user-defined class
  26872. - // loader as its defining class loader, then we can skip all
  26873. - // classes loaded by the bootstrap class loader.
  26874. - bool is_user_defined =
  26875. - instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  26876. - if (is_user_defined && ik->class_loader() == NULL) {
  26877. - return;
  26878. - }
  26879. -
  26880. - // This is a very busy routine. We don't want too much tracing
  26881. - // printed out.
  26882. - bool trace_name_printed = false;
  26883. -
  26884. - // Very noisy: only enable this call if you are trying to determine
  26885. - // that a specific class gets found by this routine.
  26886. - // RC_TRACE macro has an embedded ResourceMark
  26887. - // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  26888. - // ("adjust check: name=%s", ik->external_name()));
  26889. - // trace_name_printed = true;
  26890. -
  26891. - // Fix the vtable embedded in the_class and subclasses of the_class,
  26892. - // if one exists. We discard scratch_class and we don't keep an
  26893. - // instanceKlass around to hold obsolete methods so we don't have
  26894. - // any other instanceKlass embedded vtables to update. The vtable
  26895. - // holds the methodOops for virtual (but not final) methods.
  26896. - if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  26897. - // ik->vtable() creates a wrapper object; rm cleans it up
  26898. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  26899. +
  26900. + if (ik->vtable_length() > 0) {
  26901. ResourceMark rm(THREAD);
  26902. - ik->vtable()->adjust_method_entries(_matching_old_methods,
  26903. - _matching_new_methods,
  26904. - _matching_methods_length,
  26905. - &trace_name_printed);
  26906. - }
  26907. -
  26908. - // If the current class has an itable and we are either redefining an
  26909. - // interface or if the current class is a subclass of the_class, then
  26910. - // we potentially have to fix the itable. If we are redefining an
  26911. - // interface, then we have to call adjust_method_entries() for
  26912. - // every instanceKlass that has an itable since there isn't a
  26913. - // subclass relationship between an interface and an instanceKlass.
  26914. - if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  26915. - || ik->is_subclass_of(_the_class_oop))) {
  26916. - // ik->itable() creates a wrapper object; rm cleans it up
  26917. - ResourceMark rm(THREAD);
  26918. - ik->itable()->adjust_method_entries(_matching_old_methods,
  26919. - _matching_new_methods,
  26920. - _matching_methods_length,
  26921. - &trace_name_printed);
  26922. - }
  26923. -
  26924. - // The constant pools in other classes (other_cp) can refer to
  26925. - // methods in the_class. We have to update method information in
  26926. - // other_cp's cache. If other_cp has a previous version, then we
  26927. - // have to repeat the process for each previous version. The
  26928. - // constant pool cache holds the methodOops for non-virtual
  26929. - // methods and for virtual, final methods.
  26930. - //
  26931. - // Special case: if the current class is the_class, then new_cp
  26932. - // has already been attached to the_class and old_cp has already
  26933. - // been added as a previous version. The new_cp doesn't have any
  26934. - // cached references to old methods so it doesn't need to be
  26935. - // updated. We can simply start with the previous version(s) in
  26936. - // that case.
  26937. - constantPoolHandle other_cp;
  26938. - constantPoolCacheOop cp_cache;
  26939. -
  26940. - if (k_oop != _the_class_oop) {
  26941. - // this klass' constant pool cache may need adjustment
  26942. - other_cp = constantPoolHandle(ik->constants());
  26943. - cp_cache = other_cp->cache();
  26944. - if (cp_cache != NULL) {
  26945. - cp_cache->adjust_method_entries(_matching_old_methods,
  26946. - _matching_new_methods,
  26947. - _matching_methods_length,
  26948. - &trace_name_printed);
  26949. + if (!ik->vtable()->check_no_old_entries()) {
  26950. + TRACE_RC1("size of class: %d\n", k_oop->size());
  26951. + TRACE_RC1("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  26952. + assert(false, "OLD method found");
  26953. }
  26954. - }
  26955. - {
  26956. - ResourceMark rm(THREAD);
  26957. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  26958. - // contain a GrowableArray of handles. We have to clean up the
  26959. - // GrowableArray _after_ the PreviousVersionWalker destructor
  26960. - // has destroyed the handles.
  26961. - {
  26962. - // the previous versions' constant pool caches may need adjustment
  26963. - PreviousVersionWalker pvw(ik);
  26964. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  26965. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  26966. - other_cp = pv_info->prev_constant_pool_handle();
  26967. - cp_cache = other_cp->cache();
  26968. - if (cp_cache != NULL) {
  26969. - cp_cache->adjust_method_entries(_matching_old_methods,
  26970. - _matching_new_methods,
  26971. - _matching_methods_length,
  26972. - &trace_name_printed);
  26973. - }
  26974. - }
  26975. - } // pvw is cleaned up
  26976. - } // rm is cleaned up
  26977. - }
  26978. -}
  26979. -
  26980. -void VM_RedefineClasses::update_jmethod_ids() {
  26981. - for (int j = 0; j < _matching_methods_length; ++j) {
  26982. - methodOop old_method = _matching_old_methods[j];
  26983. - jmethodID jmid = old_method->find_jmethod_id_or_null();
  26984. - if (jmid != NULL) {
  26985. - // There is a jmethodID, change it to point to the new method
  26986. - methodHandle new_method_h(_matching_new_methods[j]);
  26987. - JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  26988. - assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  26989. - "should be replaced");
  26990. +
  26991. + ik->vtable()->verify(tty, true);
  26992. }
  26993. }
  26994. }
  26995. -void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  26996. - BitMap *emcp_methods, int * emcp_method_count_p) {
  26997. - *emcp_method_count_p = 0;
  26998. - int obsolete_count = 0;
  26999. - int old_index = 0;
  27000. - for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  27001. - methodOop old_method = _matching_old_methods[j];
  27002. - methodOop new_method = _matching_new_methods[j];
  27003. - methodOop old_array_method;
  27004. -
  27005. - // Maintain an old_index into the _old_methods array by skipping
  27006. - // deleted methods
  27007. - while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  27008. - != old_method) {
  27009. - ++old_index;
  27010. +#endif
  27011. +
  27012. +VM_RedefineClasses::FindAffectedKlassesClosure::FindAffectedKlassesClosure( GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result )
  27013. +{
  27014. + assert(original_klasses != NULL && result != NULL, "");
  27015. + this->_original_klasses = original_klasses;
  27016. + this->_result = result;
  27017. + SystemDictionary::classes_do(this);
  27018. +}
  27019. +
  27020. +void VM_RedefineClasses::FindAffectedKlassesClosure::do_object( oop obj )
  27021. +{
  27022. + klassOop klass = (klassOop)obj;
  27023. + assert(!_result->contains(klass), "must not occur more than once!");
  27024. + assert(klass->klass_part()->new_version() == NULL, "Only last version is valid entry in system dictionary");
  27025. +
  27026. + for(int i=0; i<_original_klasses->length(); i++) {
  27027. + instanceKlassHandle cur = _original_klasses->at(i);
  27028. + if (cur() != klass && klass->klass_part()->is_subtype_of(cur()) && !_original_klasses->contains(klass)) {
  27029. + TRACE_RC3("Found affected class: %s", klass->klass_part()->name()->as_C_string());
  27030. + _result->append(klass);
  27031. + break;
  27032. }
  27033. -
  27034. - if (MethodComparator::methods_EMCP(old_method, new_method)) {
  27035. - // The EMCP definition from JSR-163 requires the bytecodes to be
  27036. - // the same with the exception of constant pool indices which may
  27037. - // differ. However, the constants referred to by those indices
  27038. - // must be the same.
  27039. - //
  27040. - // We use methods_EMCP() for comparison since constant pool
  27041. - // merging can remove duplicate constant pool entries that were
  27042. - // present in the old method and removed from the rewritten new
  27043. - // method. A faster binary comparison function would consider the
  27044. - // old and new methods to be different when they are actually
  27045. - // EMCP.
  27046. - //
  27047. - // The old and new methods are EMCP and you would think that we
  27048. - // could get rid of one of them here and now and save some space.
  27049. - // However, the concept of EMCP only considers the bytecodes and
  27050. - // the constant pool entries in the comparison. Other things,
  27051. - // e.g., the line number table (LNT) or the local variable table
  27052. - // (LVT) don't count in the comparison. So the new (and EMCP)
  27053. - // method can have a new LNT that we need so we can't just
  27054. - // overwrite the new method with the old method.
  27055. - //
  27056. - // When this routine is called, we have already attached the new
  27057. - // methods to the_class so the old methods are effectively
  27058. - // overwritten. However, if an old method is still executing,
  27059. - // then the old method cannot be collected until sometime after
  27060. - // the old method call has returned. So the overwriting of old
  27061. - // methods by new methods will save us space except for those
  27062. - // (hopefully few) old methods that are still executing.
  27063. - //
  27064. - // A method refers to a constMethodOop and this presents another
  27065. - // possible avenue to space savings. The constMethodOop in the
  27066. - // new method contains possibly new attributes (LNT, LVT, etc).
  27067. - // At first glance, it seems possible to save space by replacing
  27068. - // the constMethodOop in the old method with the constMethodOop
  27069. - // from the new method. The old and new methods would share the
  27070. - // same constMethodOop and we would save the space occupied by
  27071. - // the old constMethodOop. However, the constMethodOop contains
  27072. - // a back reference to the containing method. Sharing the
  27073. - // constMethodOop between two methods could lead to confusion in
  27074. - // the code that uses the back reference. This would lead to
  27075. - // brittle code that could be broken in non-obvious ways now or
  27076. - // in the future.
  27077. - //
  27078. - // Another possibility is to copy the constMethodOop from the new
  27079. - // method to the old method and then overwrite the new method with
  27080. - // the old method. Since the constMethodOop contains the bytecodes
  27081. - // for the method embedded in the oop, this option would change
  27082. - // the bytecodes out from under any threads executing the old
  27083. - // method and make the thread's bcp invalid. Since EMCP requires
  27084. - // that the bytecodes be the same modulo constant pool indices, it
  27085. - // is straight forward to compute the correct new bcp in the new
  27086. - // constMethodOop from the old bcp in the old constMethodOop. The
  27087. - // time consuming part would be searching all the frames in all
  27088. - // of the threads to find all of the calls to the old method.
  27089. - //
  27090. - // It looks like we will have to live with the limited savings
  27091. - // that we get from effectively overwriting the old methods
  27092. - // when the new methods are attached to the_class.
  27093. -
  27094. - // track which methods are EMCP for add_previous_version() call
  27095. - emcp_methods->set_bit(old_index);
  27096. - (*emcp_method_count_p)++;
  27097. -
  27098. - // An EMCP method is _not_ obsolete. An obsolete method has a
  27099. - // different jmethodID than the current method. An EMCP method
  27100. - // has the same jmethodID as the current method. Having the
  27101. - // same jmethodID for all EMCP versions of a method allows for
  27102. - // a consistent view of the EMCP methods regardless of which
  27103. - // EMCP method you happen to have in hand. For example, a
  27104. - // breakpoint set in one EMCP method will work for all EMCP
  27105. - // versions of the method including the current one.
  27106. - } else {
  27107. - // mark obsolete methods as such
  27108. - old_method->set_is_obsolete();
  27109. - obsolete_count++;
  27110. -
  27111. - // obsolete methods need a unique idnum
  27112. - u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  27113. - if (num != constMethodOopDesc::UNSET_IDNUM) {
  27114. -// u2 old_num = old_method->method_idnum();
  27115. - old_method->set_method_idnum(num);
  27116. -// TO DO: attach obsolete annotations to obsolete method's new idnum
  27117. + }
  27118. +}
  27119. +
  27120. +jvmtiError VM_RedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS)
  27121. +{
  27122. + GrowableArray< Pair<klassOop, klassOop> > *links = new GrowableArray< Pair<klassOop, klassOop> >();
  27123. +
  27124. + for (int i=0; i<class_count; i++) {
  27125. +
  27126. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  27127. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  27128. + instanceKlassHandle the_class(THREAD, the_class_oop);
  27129. + Handle the_class_loader(THREAD, the_class->class_loader());
  27130. + Handle protection_domain(THREAD, the_class->protection_domain());
  27131. +
  27132. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  27133. + class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  27134. + ClassFileParser cfp(&st);
  27135. +
  27136. + GrowableArray<symbolHandle> symbolArr;
  27137. + TRACE_RC2("Before find super symbols of class %s", the_class->name()->as_C_string());
  27138. + cfp.findSuperSymbols(the_class->name(), the_class_loader, protection_domain, the_class, symbolArr, THREAD);
  27139. +
  27140. + for (int j=0; j<symbolArr.length(); j++) {
  27141. + symbolHandle sym = symbolArr.at(j);
  27142. +
  27143. + TRACE_RC3("Before adding link to super class %s", sym->as_C_string());
  27144. +
  27145. + for (int k=0; k<arr->length(); k++) {
  27146. + klassOop curOop = arr->at(k)();
  27147. + // (tw) TODO: Check if we get aliasing problems with different class loaders?
  27148. + if (curOop->klass_part()->name() == sym() /*&& curOop->klass_part()->class_loader() == the_class_loader()*/) {
  27149. + TRACE_RC2("Found class to link");
  27150. + links->append(Pair<klassOop, klassOop>(curOop, the_class()));
  27151. + break;
  27152. + }
  27153. }
  27154. - // With tracing we try not to "yack" too much. The position of
  27155. - // this trace assumes there are fewer obsolete methods than
  27156. - // EMCP methods.
  27157. - RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  27158. - old_method->name()->as_C_string(),
  27159. - old_method->signature()->as_C_string()));
  27160. }
  27161. - old_method->set_is_old();
  27162. }
  27163. - for (int i = 0; i < _deleted_methods_length; ++i) {
  27164. - methodOop old_method = _deleted_methods[i];
  27165. -
  27166. - assert(old_method->vtable_index() < 0,
  27167. - "cannot delete methods with vtable entries");;
  27168. -
  27169. - // Mark all deleted methods as old and obsolete
  27170. - old_method->set_is_old();
  27171. - old_method->set_is_obsolete();
  27172. - ++obsolete_count;
  27173. - // With tracing we try not to "yack" too much. The position of
  27174. - // this trace assumes there are fewer obsolete methods than
  27175. - // EMCP methods.
  27176. - RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  27177. - old_method->name()->as_C_string(),
  27178. - old_method->signature()->as_C_string()));
  27179. +
  27180. +
  27181. + TRACE_RC1("Identified links between classes! ");
  27182. +
  27183. + for (int i=0; i<affected->length(); i++) {
  27184. +
  27185. + instanceKlassHandle klass = affected->at(i);
  27186. +
  27187. + klassOop superKlass = klass->super();
  27188. + if (affected->contains(superKlass)) {
  27189. + links->append(Pair<klassOop, klassOop>(superKlass, klass()));
  27190. + }
  27191. +
  27192. + objArrayOop superInterfaces = klass->local_interfaces();
  27193. + for (int j=0; j<superInterfaces->length(); j++) {
  27194. + klassOop interfaceKlass = (klassOop)superInterfaces->obj_at(j);
  27195. + if (arr->contains(interfaceKlass)) {
  27196. + links->append(Pair<klassOop, klassOop>(interfaceKlass, klass()));
  27197. + }
  27198. + }
  27199. }
  27200. - assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  27201. - "sanity check");
  27202. - RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  27203. - obsolete_count));
  27204. +
  27205. + IF_TRACE_RC2 {
  27206. + TRACE_RC2("Identified links: ");
  27207. + for (int i=0; i<links->length(); i++) {
  27208. + TRACE_RC2("%s to %s", links->at(i).left()->klass_part()->name()->as_C_string(),
  27209. + links->at(i).right()->klass_part()->name()->as_C_string());
  27210. + }
  27211. + }
  27212. +
  27213. + for (int i=0; i<arr->length(); i++) {
  27214. +
  27215. + int j;
  27216. + for (j=i; j<arr->length(); j++) {
  27217. +
  27218. + int k;
  27219. + for (k=0; k<links->length(); k++) {
  27220. +
  27221. + klassOop k1 = links->adr_at(k)->right();
  27222. + klassOop k2 = arr->at(j)();
  27223. + if (k1 == k2) {
  27224. + break;
  27225. + }
  27226. + }
  27227. +
  27228. + if (k == links->length()) {
  27229. + break;
  27230. + }
  27231. + }
  27232. +
  27233. + if (j == arr->length()) {
  27234. + // circle detected
  27235. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  27236. + }
  27237. +
  27238. + for (int k=0; k<links->length(); k++) {
  27239. + if (links->adr_at(k)->left() == arr->at(j)()) {
  27240. + links->at_put(k, links->at(links->length() - 1));
  27241. + links->remove_at(links->length() - 1);
  27242. + k--;
  27243. + }
  27244. + }
  27245. +
  27246. + instanceKlassHandle tmp = arr->at(j);
  27247. + arr->at_put(j, arr->at(i));
  27248. + arr->at_put(i, tmp);
  27249. + }
  27250. +
  27251. + return JVMTI_ERROR_NONE;
  27252. }
  27253. +void VM_RedefineClasses::oops_do(OopClosure *closure) {
  27254. +
  27255. + if (_updated_oops != NULL) {
  27256. + for (int i=0; i<_updated_oops->length(); i++) {
  27257. + closure->do_oop(_updated_oops->adr_at(i));
  27258. + }
  27259. + }
  27260. +}
  27261. +
  27262. +void VM_RedefineClasses::transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to) {
  27263. + to->set_is_field_modification_watched(from->is_field_modification_watched());
  27264. + to->set_is_field_access_watched(from->is_field_access_watched());
  27265. + if (from->is_field_modification_watched() || from->is_field_access_watched()) {
  27266. + TRACE_RC2("Transfered watch for field %s", from->name()->as_C_string());
  27267. + }
  27268. + update_klass_field_access_flag(to);
  27269. +}
  27270. +
  27271. +void VM_RedefineClasses::update_klass_field_access_flag(fieldDescriptor *fd) {
  27272. + instanceKlass* ik = instanceKlass::cast(fd->field_holder());
  27273. + typeArrayOop fields = ik->fields();
  27274. + fields->ushort_at_put(fd->index(), (jushort)fd->access_flags().as_short());
  27275. +}
  27276. +
  27277. +
  27278. // This internal class transfers the native function registration from old methods
  27279. // to new methods. It is designed to handle both the simple case of unchanged
  27280. // native methods and the complex cases of native method prefixes being added and/or
  27281. @@ -2831,7 +3022,7 @@
  27282. // Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  27283. //
  27284. class TransferNativeFunctionRegistration {
  27285. - private:
  27286. +private:
  27287. instanceKlassHandle the_class;
  27288. int prefix_count;
  27289. char** prefixes;
  27290. @@ -2844,42 +3035,42 @@
  27291. // (2) with the prefix.
  27292. // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  27293. methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  27294. - symbolOop signature) {
  27295. - symbolOop name_symbol = SymbolTable::probe(name_str, (int)name_len);
  27296. - if (name_symbol != NULL) {
  27297. - methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  27298. - if (method != NULL) {
  27299. - // Even if prefixed, intermediate methods must exist.
  27300. - if (method->is_native()) {
  27301. - // Wahoo, we found a (possibly prefixed) version of the method, return it.
  27302. - return method;
  27303. - }
  27304. - if (depth < prefix_count) {
  27305. - // Try applying further prefixes (other than this one).
  27306. - method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  27307. - if (method != NULL) {
  27308. - return method; // found
  27309. + symbolOop signature) {
  27310. + symbolOop name_symbol = SymbolTable::probe(name_str, (int)name_len);
  27311. + if (name_symbol != NULL) {
  27312. + methodOop method = Klass::cast(the_class()->klass_part()->new_version())->lookup_method(name_symbol, signature);
  27313. + if (method != NULL) {
  27314. + // Even if prefixed, intermediate methods must exist.
  27315. + if (method->is_native()) {
  27316. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  27317. + return method;
  27318. }
  27319. -
  27320. - // Try adding this prefix to the method name and see if it matches
  27321. - // another method name.
  27322. - char* prefix = prefixes[depth];
  27323. - size_t prefix_len = strlen(prefix);
  27324. - size_t trial_len = name_len + prefix_len;
  27325. - char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  27326. - strcpy(trial_name_str, prefix);
  27327. - strcat(trial_name_str, name_str);
  27328. - method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  27329. - signature);
  27330. - if (method != NULL) {
  27331. - // If found along this branch, it was prefixed, mark as such
  27332. - method->set_is_prefixed_native();
  27333. - return method; // found
  27334. + if (depth < prefix_count) {
  27335. + // Try applying further prefixes (other than this one).
  27336. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  27337. + if (method != NULL) {
  27338. + return method; // found
  27339. + }
  27340. +
  27341. + // Try adding this prefix to the method name and see if it matches
  27342. + // another method name.
  27343. + char* prefix = prefixes[depth];
  27344. + size_t prefix_len = strlen(prefix);
  27345. + size_t trial_len = name_len + prefix_len;
  27346. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  27347. + strcpy(trial_name_str, prefix);
  27348. + strcat(trial_name_str, name_str);
  27349. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  27350. + signature);
  27351. + if (method != NULL) {
  27352. + // If found along this branch, it was prefixed, mark as such
  27353. + method->set_is_prefixed_native();
  27354. + return method; // found
  27355. + }
  27356. }
  27357. }
  27358. }
  27359. - }
  27360. - return NULL; // This whole branch bore nothing
  27361. + return NULL; // This whole branch bore nothing
  27362. }
  27363. // Return the method name with old prefixes stripped away.
  27364. @@ -2904,10 +3095,10 @@
  27365. ResourceMark rm;
  27366. char* name_str = method_name_without_prefixes(method);
  27367. return search_prefix_name_space(0, name_str, strlen(name_str),
  27368. - method->signature());
  27369. + method->signature());
  27370. }
  27371. - public:
  27372. +public:
  27373. // Construct a native method transfer processor for this class.
  27374. TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  27375. @@ -2918,9 +3109,9 @@
  27376. }
  27377. // Attempt to transfer any of the old or deleted methods that are native
  27378. - void transfer_registrations(methodOop* old_methods, int methods_length) {
  27379. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  27380. for (int j = 0; j < methods_length; j++) {
  27381. - methodOop old_method = old_methods[j];
  27382. + methodOop old_method = (methodOop)old_klass->methods()->obj_at(old_methods[j]);
  27383. if (old_method->is_native() && old_method->has_native_function()) {
  27384. methodOop new_method = strip_and_search_for_new_native(old_method);
  27385. @@ -2929,7 +3120,9 @@
  27386. // Redefine does not send events (except CFLH), certainly not this
  27387. // behind the scenes re-registration.
  27388. new_method->set_native_function(old_method->native_function(),
  27389. - !methodOopDesc::native_bind_event_is_interesting);
  27390. + !methodOopDesc::native_bind_event_is_interesting);
  27391. +
  27392. + TRACE_RC3("Transfering native function for method %s", old_method->name()->as_C_string());
  27393. }
  27394. }
  27395. }
  27396. @@ -2937,481 +3130,8 @@
  27397. };
  27398. // Don't lose the association between a native method and its JNI function.
  27399. -void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
  27400. - TransferNativeFunctionRegistration transfer(the_class);
  27401. - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
  27402. - transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
  27403. +void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  27404. + TransferNativeFunctionRegistration transfer(old_klass);
  27405. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  27406. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  27407. }
  27408. -
  27409. -// Deoptimize all compiled code that depends on this class.
  27410. -//
  27411. -// If the can_redefine_classes capability is obtained in the onload
  27412. -// phase then the compiler has recorded all dependencies from startup.
  27413. -// In that case we need only deoptimize and throw away all compiled code
  27414. -// that depends on the class.
  27415. -//
  27416. -// If can_redefine_classes is obtained sometime after the onload
  27417. -// phase then the dependency information may be incomplete. In that case
  27418. -// the first call to RedefineClasses causes all compiled code to be
  27419. -// thrown away. As can_redefine_classes has been obtained then
  27420. -// all future compilations will record dependencies so second and
  27421. -// subsequent calls to RedefineClasses need only throw away code
  27422. -// that depends on the class.
  27423. -//
  27424. -void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  27425. - assert_locked_or_safepoint(Compile_lock);
  27426. -
  27427. - // All dependencies have been recorded from startup or this is a second or
  27428. - // subsequent use of RedefineClasses
  27429. - if (JvmtiExport::all_dependencies_are_recorded()) {
  27430. - Universe::flush_evol_dependents_on(k_h);
  27431. - } else {
  27432. - CodeCache::mark_all_nmethods_for_deoptimization();
  27433. -
  27434. - ResourceMark rm(THREAD);
  27435. - DeoptimizationMarker dm;
  27436. -
  27437. - // Deoptimize all activations depending on marked nmethods
  27438. - Deoptimization::deoptimize_dependents();
  27439. -
  27440. - // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  27441. - CodeCache::make_marked_nmethods_not_entrant();
  27442. -
  27443. - // From now on we know that the dependency information is complete
  27444. - JvmtiExport::set_all_dependencies_are_recorded(true);
  27445. - }
  27446. -}
  27447. -
  27448. -void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  27449. - methodOop old_method;
  27450. - methodOop new_method;
  27451. -
  27452. - _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  27453. - _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  27454. - _added_methods = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  27455. - _deleted_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  27456. -
  27457. - _matching_methods_length = 0;
  27458. - _deleted_methods_length = 0;
  27459. - _added_methods_length = 0;
  27460. -
  27461. - int nj = 0;
  27462. - int oj = 0;
  27463. - while (true) {
  27464. - if (oj >= _old_methods->length()) {
  27465. - if (nj >= _new_methods->length()) {
  27466. - break; // we've looked at everything, done
  27467. - }
  27468. - // New method at the end
  27469. - new_method = (methodOop) _new_methods->obj_at(nj);
  27470. - _added_methods[_added_methods_length++] = new_method;
  27471. - ++nj;
  27472. - } else if (nj >= _new_methods->length()) {
  27473. - // Old method, at the end, is deleted
  27474. - old_method = (methodOop) _old_methods->obj_at(oj);
  27475. - _deleted_methods[_deleted_methods_length++] = old_method;
  27476. - ++oj;
  27477. - } else {
  27478. - old_method = (methodOop) _old_methods->obj_at(oj);
  27479. - new_method = (methodOop) _new_methods->obj_at(nj);
  27480. - if (old_method->name() == new_method->name()) {
  27481. - if (old_method->signature() == new_method->signature()) {
  27482. - _matching_old_methods[_matching_methods_length ] = old_method;
  27483. - _matching_new_methods[_matching_methods_length++] = new_method;
  27484. - ++nj;
  27485. - ++oj;
  27486. - } else {
  27487. - // added overloaded have already been moved to the end,
  27488. - // so this is a deleted overloaded method
  27489. - _deleted_methods[_deleted_methods_length++] = old_method;
  27490. - ++oj;
  27491. - }
  27492. - } else { // names don't match
  27493. - if (old_method->name()->fast_compare(new_method->name()) > 0) {
  27494. - // new method
  27495. - _added_methods[_added_methods_length++] = new_method;
  27496. - ++nj;
  27497. - } else {
  27498. - // deleted method
  27499. - _deleted_methods[_deleted_methods_length++] = old_method;
  27500. - ++oj;
  27501. - }
  27502. - }
  27503. - }
  27504. - }
  27505. - assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  27506. - assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  27507. -}
  27508. -
  27509. -
  27510. -
  27511. -// Install the redefinition of a class:
  27512. -// - house keeping (flushing breakpoints and caches, deoptimizing
  27513. -// dependent compiled code)
  27514. -// - replacing parts in the_class with parts from scratch_class
  27515. -// - adding a weak reference to track the obsolete but interesting
  27516. -// parts of the_class
  27517. -// - adjusting constant pool caches and vtables in other classes
  27518. -// that refer to methods in the_class. These adjustments use the
  27519. -// SystemDictionary::classes_do() facility which only allows
  27520. -// a helper method to be specified. The interesting parameters
  27521. -// that we would like to pass to the helper method are saved in
  27522. -// static global fields in the VM operation.
  27523. -void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  27524. - instanceKlassHandle scratch_class, TRAPS) {
  27525. -
  27526. - RC_TIMER_START(_timer_rsc_phase1);
  27527. -
  27528. - oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  27529. - klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  27530. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  27531. -
  27532. -#ifndef JVMTI_KERNEL
  27533. - // Remove all breakpoints in methods of this class
  27534. - JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  27535. - jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop);
  27536. -#endif // !JVMTI_KERNEL
  27537. -
  27538. - if (the_class_oop == Universe::reflect_invoke_cache()->klass()) {
  27539. - // We are redefining java.lang.reflect.Method. Method.invoke() is
  27540. - // cached and users of the cache care about each active version of
  27541. - // the method so we have to track this previous version.
  27542. - // Do this before methods get switched
  27543. - Universe::reflect_invoke_cache()->add_previous_version(
  27544. - the_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  27545. - }
  27546. -
  27547. - // Deoptimize all compiled code that depends on this class
  27548. - flush_dependent_code(the_class, THREAD);
  27549. -
  27550. - _old_methods = the_class->methods();
  27551. - _new_methods = scratch_class->methods();
  27552. - _the_class_oop = the_class_oop;
  27553. - compute_added_deleted_matching_methods();
  27554. - update_jmethod_ids();
  27555. -
  27556. - // Attach new constant pool to the original klass. The original
  27557. - // klass still refers to the old constant pool (for now).
  27558. - scratch_class->constants()->set_pool_holder(the_class());
  27559. -
  27560. -#if 0
  27561. - // In theory, with constant pool merging in place we should be able
  27562. - // to save space by using the new, merged constant pool in place of
  27563. - // the old constant pool(s). By "pool(s)" I mean the constant pool in
  27564. - // the klass version we are replacing now and any constant pool(s) in
  27565. - // previous versions of klass. Nice theory, doesn't work in practice.
  27566. - // When this code is enabled, even simple programs throw NullPointer
  27567. - // exceptions. I'm guessing that this is caused by some constant pool
  27568. - // cache difference between the new, merged constant pool and the
  27569. - // constant pool that was just being used by the klass. I'm keeping
  27570. - // this code around to archive the idea, but the code has to remain
  27571. - // disabled for now.
  27572. -
  27573. - // Attach each old method to the new constant pool. This can be
  27574. - // done here since we are past the bytecode verification and
  27575. - // constant pool optimization phases.
  27576. - for (int i = _old_methods->length() - 1; i >= 0; i--) {
  27577. - methodOop method = (methodOop)_old_methods->obj_at(i);
  27578. - method->set_constants(scratch_class->constants());
  27579. - }
  27580. -
  27581. - {
  27582. - // walk all previous versions of the klass
  27583. - instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  27584. - PreviousVersionWalker pvw(ik);
  27585. - instanceKlassHandle ikh;
  27586. - do {
  27587. - ikh = pvw.next_previous_version();
  27588. - if (!ikh.is_null()) {
  27589. - ik = ikh();
  27590. -
  27591. - // attach previous version of klass to the new constant pool
  27592. - ik->set_constants(scratch_class->constants());
  27593. -
  27594. - // Attach each method in the previous version of klass to the
  27595. - // new constant pool
  27596. - objArrayOop prev_methods = ik->methods();
  27597. - for (int i = prev_methods->length() - 1; i >= 0; i--) {
  27598. - methodOop method = (methodOop)prev_methods->obj_at(i);
  27599. - method->set_constants(scratch_class->constants());
  27600. - }
  27601. - }
  27602. - } while (!ikh.is_null());
  27603. - }
  27604. -#endif
  27605. -
  27606. - // Replace methods and constantpool
  27607. - the_class->set_methods(_new_methods);
  27608. - scratch_class->set_methods(_old_methods); // To prevent potential GCing of the old methods,
  27609. - // and to be able to undo operation easily.
  27610. -
  27611. - constantPoolOop old_constants = the_class->constants();
  27612. - the_class->set_constants(scratch_class->constants());
  27613. - scratch_class->set_constants(old_constants); // See the previous comment.
  27614. -#if 0
  27615. - // We are swapping the guts of "the new class" with the guts of "the
  27616. - // class". Since the old constant pool has just been attached to "the
  27617. - // new class", it seems logical to set the pool holder in the old
  27618. - // constant pool also. However, doing this will change the observable
  27619. - // class hierarchy for any old methods that are still executing. A
  27620. - // method can query the identity of its "holder" and this query uses
  27621. - // the method's constant pool link to find the holder. The change in
  27622. - // holding class from "the class" to "the new class" can confuse
  27623. - // things.
  27624. - //
  27625. - // Setting the old constant pool's holder will also cause
  27626. - // verification done during vtable initialization below to fail.
  27627. - // During vtable initialization, the vtable's class is verified to be
  27628. - // a subtype of the method's holder. The vtable's class is "the
  27629. - // class" and the method's holder is gotten from the constant pool
  27630. - // link in the method itself. For "the class"'s directly implemented
  27631. - // methods, the method holder is "the class" itself (as gotten from
  27632. - // the new constant pool). The check works fine in this case. The
  27633. - // check also works fine for methods inherited from super classes.
  27634. - //
  27635. - // Miranda methods are a little more complicated. A miranda method is
  27636. - // provided by an interface when the class implementing the interface
  27637. - // does not provide its own method. These interfaces are implemented
  27638. - // internally as an instanceKlass. These special instanceKlasses
  27639. - // share the constant pool of the class that "implements" the
  27640. - // interface. By sharing the constant pool, the method holder of a
  27641. - // miranda method is the class that "implements" the interface. In a
  27642. - // non-redefine situation, the subtype check works fine. However, if
  27643. - // the old constant pool's pool holder is modified, then the check
  27644. - // fails because there is no class hierarchy relationship between the
  27645. - // vtable's class and "the new class".
  27646. -
  27647. - old_constants->set_pool_holder(scratch_class());
  27648. -#endif
  27649. -
  27650. - // track which methods are EMCP for add_previous_version() call below
  27651. - BitMap emcp_methods(_old_methods->length());
  27652. - int emcp_method_count = 0;
  27653. - emcp_methods.clear(); // clears 0..(length() - 1)
  27654. - check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  27655. - transfer_old_native_function_registrations(the_class);
  27656. -
  27657. - // The class file bytes from before any retransformable agents mucked
  27658. - // with them was cached on the scratch class, move to the_class.
  27659. - // Note: we still want to do this if nothing needed caching since it
  27660. - // should get cleared in the_class too.
  27661. - the_class->set_cached_class_file(scratch_class->get_cached_class_file_bytes(),
  27662. - scratch_class->get_cached_class_file_len());
  27663. -
  27664. - // Replace inner_classes
  27665. - typeArrayOop old_inner_classes = the_class->inner_classes();
  27666. - the_class->set_inner_classes(scratch_class->inner_classes());
  27667. - scratch_class->set_inner_classes(old_inner_classes);
  27668. -
  27669. - // Initialize the vtable and interface table after
  27670. - // methods have been rewritten
  27671. - {
  27672. - ResourceMark rm(THREAD);
  27673. - // no exception should happen here since we explicitly
  27674. - // do not check loader constraints.
  27675. - // compare_and_normalize_class_versions has already checked:
  27676. - // - classloaders unchanged, signatures unchanged
  27677. - // - all instanceKlasses for redefined classes reused & contents updated
  27678. - the_class->vtable()->initialize_vtable(false, THREAD);
  27679. - the_class->itable()->initialize_itable(false, THREAD);
  27680. - assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
  27681. - }
  27682. -
  27683. - // Leave arrays of jmethodIDs and itable index cache unchanged
  27684. -
  27685. - // Copy the "source file name" attribute from new class version
  27686. - the_class->set_source_file_name(scratch_class->source_file_name());
  27687. -
  27688. - // Copy the "source debug extension" attribute from new class version
  27689. - the_class->set_source_debug_extension(
  27690. - scratch_class->source_debug_extension());
  27691. -
  27692. - // Use of javac -g could be different in the old and the new
  27693. - if (scratch_class->access_flags().has_localvariable_table() !=
  27694. - the_class->access_flags().has_localvariable_table()) {
  27695. -
  27696. - AccessFlags flags = the_class->access_flags();
  27697. - if (scratch_class->access_flags().has_localvariable_table()) {
  27698. - flags.set_has_localvariable_table();
  27699. - } else {
  27700. - flags.clear_has_localvariable_table();
  27701. - }
  27702. - the_class->set_access_flags(flags);
  27703. - }
  27704. -
  27705. - // Replace class annotation fields values
  27706. - typeArrayOop old_class_annotations = the_class->class_annotations();
  27707. - the_class->set_class_annotations(scratch_class->class_annotations());
  27708. - scratch_class->set_class_annotations(old_class_annotations);
  27709. -
  27710. - // Replace fields annotation fields values
  27711. - objArrayOop old_fields_annotations = the_class->fields_annotations();
  27712. - the_class->set_fields_annotations(scratch_class->fields_annotations());
  27713. - scratch_class->set_fields_annotations(old_fields_annotations);
  27714. -
  27715. - // Replace methods annotation fields values
  27716. - objArrayOop old_methods_annotations = the_class->methods_annotations();
  27717. - the_class->set_methods_annotations(scratch_class->methods_annotations());
  27718. - scratch_class->set_methods_annotations(old_methods_annotations);
  27719. -
  27720. - // Replace methods parameter annotation fields values
  27721. - objArrayOop old_methods_parameter_annotations =
  27722. - the_class->methods_parameter_annotations();
  27723. - the_class->set_methods_parameter_annotations(
  27724. - scratch_class->methods_parameter_annotations());
  27725. - scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  27726. -
  27727. - // Replace methods default annotation fields values
  27728. - objArrayOop old_methods_default_annotations =
  27729. - the_class->methods_default_annotations();
  27730. - the_class->set_methods_default_annotations(
  27731. - scratch_class->methods_default_annotations());
  27732. - scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  27733. -
  27734. - // Replace minor version number of class file
  27735. - u2 old_minor_version = the_class->minor_version();
  27736. - the_class->set_minor_version(scratch_class->minor_version());
  27737. - scratch_class->set_minor_version(old_minor_version);
  27738. -
  27739. - // Replace major version number of class file
  27740. - u2 old_major_version = the_class->major_version();
  27741. - the_class->set_major_version(scratch_class->major_version());
  27742. - scratch_class->set_major_version(old_major_version);
  27743. -
  27744. - // Replace CP indexes for class and name+type of enclosing method
  27745. - u2 old_class_idx = the_class->enclosing_method_class_index();
  27746. - u2 old_method_idx = the_class->enclosing_method_method_index();
  27747. - the_class->set_enclosing_method_indices(
  27748. - scratch_class->enclosing_method_class_index(),
  27749. - scratch_class->enclosing_method_method_index());
  27750. - scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  27751. -
  27752. - // keep track of previous versions of this class
  27753. - the_class->add_previous_version(scratch_class, &emcp_methods,
  27754. - emcp_method_count);
  27755. -
  27756. - RC_TIMER_STOP(_timer_rsc_phase1);
  27757. - RC_TIMER_START(_timer_rsc_phase2);
  27758. -
  27759. - // Adjust constantpool caches and vtables for all classes
  27760. - // that reference methods of the evolved class.
  27761. - SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  27762. -
  27763. - if (the_class->oop_map_cache() != NULL) {
  27764. - // Flush references to any obsolete methods from the oop map cache
  27765. - // so that obsolete methods are not pinned.
  27766. - the_class->oop_map_cache()->flush_obsolete_entries();
  27767. - }
  27768. -
  27769. - // increment the classRedefinedCount field in the_class and in any
  27770. - // direct and indirect subclasses of the_class
  27771. - increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  27772. -
  27773. - // RC_TRACE macro has an embedded ResourceMark
  27774. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  27775. - ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
  27776. - the_class->external_name(),
  27777. - java_lang_Class::classRedefinedCount(the_class_mirror),
  27778. - os::available_memory() >> 10));
  27779. -
  27780. - RC_TIMER_STOP(_timer_rsc_phase2);
  27781. -} // end redefine_single_class()
  27782. -
  27783. -
  27784. -// Increment the classRedefinedCount field in the specific instanceKlass
  27785. -// and in all direct and indirect subclasses.
  27786. -void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  27787. - oop class_mirror = ik->java_mirror();
  27788. - klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  27789. - int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  27790. - java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  27791. -
  27792. - if (class_oop != _the_class_oop) {
  27793. - // _the_class_oop count is printed at end of redefine_single_class()
  27794. - RC_TRACE_WITH_THREAD(0x00000008, THREAD,
  27795. - ("updated count in subclass=%s to %d", ik->external_name(), new_count));
  27796. - }
  27797. -
  27798. - for (Klass *subk = ik->subklass(); subk != NULL;
  27799. - subk = subk->next_sibling()) {
  27800. - klassOop sub = subk->as_klassOop();
  27801. - instanceKlass *subik = (instanceKlass *)sub->klass_part();
  27802. -
  27803. - // recursively do subclasses of the current subclass
  27804. - increment_class_counter(subik, THREAD);
  27805. - }
  27806. -}
  27807. -
  27808. -#ifndef PRODUCT
  27809. -void VM_RedefineClasses::check_class(klassOop k_oop,
  27810. - oop initiating_loader, TRAPS) {
  27811. - Klass *k = k_oop->klass_part();
  27812. - if (k->oop_is_instance()) {
  27813. - HandleMark hm(THREAD);
  27814. - instanceKlass *ik = (instanceKlass *) k;
  27815. -
  27816. - if (ik->vtable_length() > 0) {
  27817. - ResourceMark rm(THREAD);
  27818. - if (!ik->vtable()->check_no_old_entries()) {
  27819. - tty->print_cr("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  27820. - ik->vtable()->dump_vtable();
  27821. - dump_methods();
  27822. - assert(false, "OLD method found");
  27823. - }
  27824. - }
  27825. - }
  27826. -}
  27827. -
  27828. -void VM_RedefineClasses::dump_methods() {
  27829. - int j;
  27830. - tty->print_cr("_old_methods --");
  27831. - for (j = 0; j < _old_methods->length(); ++j) {
  27832. - methodOop m = (methodOop) _old_methods->obj_at(j);
  27833. - tty->print("%4d (%5d) ", j, m->vtable_index());
  27834. - m->access_flags().print_on(tty);
  27835. - tty->print(" -- ");
  27836. - m->print_name(tty);
  27837. - tty->cr();
  27838. - }
  27839. - tty->print_cr("_new_methods --");
  27840. - for (j = 0; j < _new_methods->length(); ++j) {
  27841. - methodOop m = (methodOop) _new_methods->obj_at(j);
  27842. - tty->print("%4d (%5d) ", j, m->vtable_index());
  27843. - m->access_flags().print_on(tty);
  27844. - tty->print(" -- ");
  27845. - m->print_name(tty);
  27846. - tty->cr();
  27847. - }
  27848. - tty->print_cr("_matching_(old/new)_methods --");
  27849. - for (j = 0; j < _matching_methods_length; ++j) {
  27850. - methodOop m = _matching_old_methods[j];
  27851. - tty->print("%4d (%5d) ", j, m->vtable_index());
  27852. - m->access_flags().print_on(tty);
  27853. - tty->print(" -- ");
  27854. - m->print_name(tty);
  27855. - tty->cr();
  27856. - m = _matching_new_methods[j];
  27857. - tty->print(" (%5d) ", m->vtable_index());
  27858. - m->access_flags().print_on(tty);
  27859. - tty->cr();
  27860. - }
  27861. - tty->print_cr("_deleted_methods --");
  27862. - for (j = 0; j < _deleted_methods_length; ++j) {
  27863. - methodOop m = _deleted_methods[j];
  27864. - tty->print("%4d (%5d) ", j, m->vtable_index());
  27865. - m->access_flags().print_on(tty);
  27866. - tty->print(" -- ");
  27867. - m->print_name(tty);
  27868. - tty->cr();
  27869. - }
  27870. - tty->print_cr("_added_methods --");
  27871. - for (j = 0; j < _added_methods_length; ++j) {
  27872. - methodOop m = _added_methods[j];
  27873. - tty->print("%4d (%5d) ", j, m->vtable_index());
  27874. - m->access_flags().print_on(tty);
  27875. - tty->print(" -- ");
  27876. - m->print_name(tty);
  27877. - tty->cr();
  27878. - }
  27879. -}
  27880. -#endif
  27881. diff -r f5603a6e5042 src/share/vm/prims/jvmtiRedefineClasses.hpp
  27882. --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp Wed Nov 17 22:42:08 2010 -0800
  27883. +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp Fri Dec 17 13:23:04 2010 +0100
  27884. @@ -1,351 +1,50 @@
  27885. /*
  27886. - * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
  27887. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  27888. - *
  27889. - * This code is free software; you can redistribute it and/or modify it
  27890. - * under the terms of the GNU General Public License version 2 only, as
  27891. - * published by the Free Software Foundation.
  27892. - *
  27893. - * This code is distributed in the hope that it will be useful, but WITHOUT
  27894. - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  27895. - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  27896. - * version 2 for more details (a copy is included in the LICENSE file that
  27897. - * accompanied this code).
  27898. - *
  27899. - * You should have received a copy of the GNU General Public License version
  27900. - * 2 along with this work; if not, write to the Free Software Foundation,
  27901. - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  27902. - *
  27903. - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  27904. - * or visit www.oracle.com if you need additional information or have any
  27905. - * questions.
  27906. - *
  27907. - */
  27908. +* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  27909. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  27910. +*
  27911. +* This code is free software; you can redistribute it and/or modify it
  27912. +* under the terms of the GNU General Public License version 2 only, as
  27913. +* published by the Free Software Foundation.
  27914. +*
  27915. +* This code is distributed in the hope that it will be useful, but WITHOUT
  27916. +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  27917. +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  27918. +* version 2 for more details (a copy is included in the LICENSE file that
  27919. +* accompanied this code).
  27920. +*
  27921. +* You should have received a copy of the GNU General Public License version
  27922. +* 2 along with this work; if not, write to the Free Software Foundation,
  27923. +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  27924. +*
  27925. +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  27926. +* or visit www.oracle.com if you need additional information or have any
  27927. +* questions.
  27928. +*
  27929. +*/
  27930. -// Introduction:
  27931. -//
  27932. -// The RedefineClasses() API is used to change the definition of one or
  27933. -// more classes. While the API supports redefining more than one class
  27934. -// in a single call, in general, the API is discussed in the context of
  27935. -// changing the definition of a single current class to a single new
  27936. -// class. For clarity, the current class is will always be called
  27937. -// "the_class" and the new class will always be called "scratch_class".
  27938. -//
  27939. -// The name "the_class" is used because there is only one structure
  27940. -// that represents a specific class; redefinition does not replace the
  27941. -// structure, but instead replaces parts of the structure. The name
  27942. -// "scratch_class" is used because the structure that represents the
  27943. -// new definition of a specific class is simply used to carry around
  27944. -// the parts of the new definition until they are used to replace the
  27945. -// appropriate parts in the_class. Once redefinition of a class is
  27946. -// complete, scratch_class is thrown away.
  27947. -//
  27948. -//
  27949. -// Implementation Overview:
  27950. -//
  27951. -// The RedefineClasses() API is mostly a wrapper around the VM op that
  27952. -// does the real work. The work is split in varying degrees between
  27953. -// doit_prologue(), doit() and doit_epilogue().
  27954. -//
  27955. -// 1) doit_prologue() is called by the JavaThread on the way to a
  27956. -// safepoint. It does parameter verification and loads scratch_class
  27957. -// which involves:
  27958. -// - parsing the incoming class definition using the_class' class
  27959. -// loader and security context
  27960. -// - linking scratch_class
  27961. -// - merging constant pools and rewriting bytecodes as needed
  27962. -// for the merged constant pool
  27963. -// - verifying the bytecodes in scratch_class
  27964. -// - setting up the constant pool cache and rewriting bytecodes
  27965. -// as needed to use the cache
  27966. -// - finally, scratch_class is compared to the_class to verify
  27967. -// that it is a valid replacement class
  27968. -// - if everything is good, then scratch_class is saved in an
  27969. -// instance field in the VM operation for the doit() call
  27970. -//
  27971. -// Note: A JavaThread must do the above work.
  27972. -//
  27973. -// 2) doit() is called by the VMThread during a safepoint. It installs
  27974. -// the new class definition(s) which involves:
  27975. -// - retrieving the scratch_class from the instance field in the
  27976. -// VM operation
  27977. -// - house keeping (flushing breakpoints and caches, deoptimizing
  27978. -// dependent compiled code)
  27979. -// - replacing parts in the_class with parts from scratch_class
  27980. -// - adding weak reference(s) to track the obsolete but interesting
  27981. -// parts of the_class
  27982. -// - adjusting constant pool caches and vtables in other classes
  27983. -// that refer to methods in the_class. These adjustments use the
  27984. -// SystemDictionary::classes_do() facility which only allows
  27985. -// a helper method to be specified. The interesting parameters
  27986. -// that we would like to pass to the helper method are saved in
  27987. -// static global fields in the VM operation.
  27988. -// - telling the SystemDictionary to notice our changes
  27989. -//
  27990. -// Note: the above work must be done by the VMThread to be safe.
  27991. -//
  27992. -// 3) doit_epilogue() is called by the JavaThread after the VM op
  27993. -// is finished and the safepoint is done. It simply cleans up
  27994. -// memory allocated in doit_prologue() and used in doit().
  27995. -//
  27996. -//
  27997. -// Constant Pool Details:
  27998. -//
  27999. -// When the_class is redefined, we cannot just replace the constant
  28000. -// pool in the_class with the constant pool from scratch_class because
  28001. -// that could confuse obsolete methods that may still be running.
  28002. -// Instead, the constant pool from the_class, old_cp, is merged with
  28003. -// the constant pool from scratch_class, scratch_cp. The resulting
  28004. -// constant pool, merge_cp, replaces old_cp in the_class.
  28005. -//
  28006. -// The key part of any merging algorithm is the entry comparison
  28007. -// function so we have to know the types of entries in a constant pool
  28008. -// in order to merge two of them together. Constant pools can contain
  28009. -// up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
  28010. -// is not presently used so we only have to worry about the other 11
  28011. -// entry types. For the purposes of constant pool merging, it is
  28012. -// helpful to know that the 11 entry types fall into 3 different
  28013. -// subtypes: "direct", "indirect" and "double-indirect".
  28014. -//
  28015. -// Direct CP entries contain data and do not contain references to
  28016. -// other CP entries. The following are direct CP entries:
  28017. -// JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
  28018. -//
  28019. -// Indirect CP entries contain 1 or 2 references to a direct CP entry
  28020. -// and no other data. The following are indirect CP entries:
  28021. -// JVM_CONSTANT_{Class,NameAndType,String}
  28022. -//
  28023. -// Double-indirect CP entries contain two references to indirect CP
  28024. -// entries and no other data. The following are double-indirect CP
  28025. -// entries:
  28026. -// JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
  28027. -//
  28028. -// When comparing entries between two constant pools, the entry types
  28029. -// are compared first and if they match, then further comparisons are
  28030. -// made depending on the entry subtype. Comparing direct CP entries is
  28031. -// simply a matter of comparing the data associated with each entry.
  28032. -// Comparing both indirect and double-indirect CP entries requires
  28033. -// recursion.
  28034. -//
  28035. -// Fortunately, the recursive combinations are limited because indirect
  28036. -// CP entries can only refer to direct CP entries and double-indirect
  28037. -// CP entries can only refer to indirect CP entries. The following is
  28038. -// an example illustration of the deepest set of indirections needed to
  28039. -// access the data associated with a JVM_CONSTANT_Fieldref entry:
  28040. -//
  28041. -// JVM_CONSTANT_Fieldref {
  28042. -// class_index => JVM_CONSTANT_Class {
  28043. -// name_index => JVM_CONSTANT_Utf8 {
  28044. -// <data-1>
  28045. -// }
  28046. -// }
  28047. -// name_and_type_index => JVM_CONSTANT_NameAndType {
  28048. -// name_index => JVM_CONSTANT_Utf8 {
  28049. -// <data-2>
  28050. -// }
  28051. -// descriptor_index => JVM_CONSTANT_Utf8 {
  28052. -// <data-3>
  28053. -// }
  28054. -// }
  28055. -// }
  28056. -//
  28057. -// The above illustration is not a data structure definition for any
  28058. -// computer language. The curly braces ('{' and '}') are meant to
  28059. -// delimit the context of the "fields" in the CP entry types shown.
  28060. -// Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
  28061. -// "=>", e.g., the class_index is used to indirectly reference a
  28062. -// JVM_CONSTANT_Class entry where the name_index is used to indirectly
  28063. -// reference a JVM_CONSTANT_Utf8 entry which contains the interesting
  28064. -// <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
  28065. -// have to do a total of 5 indirections just to get to the CP entries
  28066. -// that contain the interesting pieces of data and then we have to
  28067. -// fetch the three pieces of data. This means we have to do a total of
  28068. -// (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
  28069. -// entries.
  28070. -//
  28071. -// Here is the indirection, data and dereference count for each entry
  28072. -// type:
  28073. -//
  28074. -// JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
  28075. -// JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
  28076. -// JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
  28077. -// JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
  28078. -// JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
  28079. -// JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
  28080. -// JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
  28081. -// JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
  28082. -// JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
  28083. -// JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
  28084. -// JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
  28085. -//
  28086. -// So different subtypes of CP entries require different amounts of
  28087. -// work for a proper comparison.
  28088. -//
  28089. -// Now that we've talked about the different entry types and how to
  28090. -// compare them we need to get back to merging. This is not a merge in
  28091. -// the "sort -u" sense or even in the "sort" sense. When we merge two
  28092. -// constant pools, we copy all the entries from old_cp to merge_cp,
  28093. -// preserving entry order. Next we append all the unique entries from
  28094. -// scratch_cp to merge_cp and we track the index changes from the
  28095. -// location in scratch_cp to the possibly new location in merge_cp.
  28096. -// When we are done, any obsolete code that is still running that
  28097. -// uses old_cp should not be able to observe any difference if it
  28098. -// were to use merge_cp. As for the new code in scratch_class, it is
  28099. -// modified to use the appropriate index values in merge_cp before it
  28100. -// is used to replace the code in the_class.
  28101. -//
  28102. -// There is one small complication in copying the entries from old_cp
  28103. -// to merge_cp. Two of the CP entry types are special in that they are
  28104. -// lazily resolved. Before explaining the copying complication, we need
  28105. -// to digress into CP entry resolution.
  28106. -//
  28107. -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
  28108. -// the class file, but are not stored in memory as such until they are
  28109. -// resolved. The entries are not resolved unless they are used because
  28110. -// resolution is expensive. During class file parsing the entries are
  28111. -// initially stored in memory as JVM_CONSTANT_ClassIndex and
  28112. -// JVM_CONSTANT_StringIndex entries. These special CP entry types
  28113. -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
  28114. -// have been parsed, but the index values in the entries have not been
  28115. -// validated. After the entire constant pool has been parsed, the index
  28116. -// values can be validated and then the entries are converted into
  28117. -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
  28118. -// entries. During this conversion process, the UTF8 values that are
  28119. -// indirectly referenced by the JVM_CONSTANT_ClassIndex and
  28120. -// JVM_CONSTANT_StringIndex entries are changed into symbolOops and the
  28121. -// entries are modified to refer to the symbolOops. This optimization
  28122. -// eliminates one level of indirection for those two CP entry types and
  28123. -// gets the entries ready for verification. During class file parsing
  28124. -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
  28125. -// resolved into JVM_CONSTANT_String entries. Verification expects to
  28126. -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
  28127. -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
  28128. -// entries.
  28129. -//
  28130. -// Now we can get back to the copying complication. When we copy
  28131. -// entries from old_cp to merge_cp, we have to revert any
  28132. -// JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
  28133. -// or verification will fail.
  28134. -//
  28135. -// It is important to explicitly state that the merging algorithm
  28136. -// effectively unresolves JVM_CONSTANT_Class entries that were in the
  28137. -// old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
  28138. -// entries in the merge_cp. This is done both to make verification
  28139. -// happy and to avoid adding more brittleness between RedefineClasses
  28140. -// and the constant pool cache. By allowing the constant pool cache
  28141. -// implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
  28142. -// into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
  28143. -// about those algorithms in RedefineClasses.
  28144. -//
  28145. -// Appending unique entries from scratch_cp to merge_cp is straight
  28146. -// forward for direct CP entries and most indirect CP entries. For the
  28147. -// indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
  28148. -// indirect CP entry types, the presence of more than one piece of
  28149. -// interesting data makes appending the entries more complicated.
  28150. -//
  28151. -// For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
  28152. -// the entry is simply copied from scratch_cp to the end of merge_cp.
  28153. -// If the index in scratch_cp is different than the destination index
  28154. -// in merge_cp, then the change in index value is tracked.
  28155. -//
  28156. -// Note: the above discussion for the direct CP entries also applies
  28157. -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
  28158. -//
  28159. -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
  28160. -// one data element at the end of the recursion, we know that we have
  28161. -// either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
  28162. -// unique then it is appended to merge_cp before the current entry.
  28163. -// If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
  28164. -// is updated to refer to the duplicate entry in merge_cp before it is
  28165. -// appended to merge_cp. Again, any changes in index values are tracked
  28166. -// as needed.
  28167. -//
  28168. -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
  28169. -// types is theoretical. Since those entry types have already been
  28170. -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
  28171. -// they are handled as direct CP entries.
  28172. -//
  28173. -// For the JVM_CONSTANT_NameAndType entry type, since there are two
  28174. -// data elements at the end of the recursions, we know that we have
  28175. -// between one and three unique entries. Any unique JVM_CONSTANT_Utf8
  28176. -// entries are appended to merge_cp before the current entry. For any
  28177. -// JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
  28178. -// updated to refer to the duplicate entry in merge_cp before it is
  28179. -// appended to merge_cp. Again, any changes in index values are tracked
  28180. -// as needed.
  28181. -//
  28182. -// For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
  28183. -// types, since there are two indirect CP entries and three data
  28184. -// elements at the end of the recursions, we know that we have between
  28185. -// one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
  28186. -// above for an example of all six entries. The uniqueness algorithm
  28187. -// for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
  28188. -// covered above. Any unique entries are appended to merge_cp before
  28189. -// the current entry. For any entries that are not unique, the current
  28190. -// entry is updated to refer to the duplicate entry in merge_cp before
  28191. -// it is appended to merge_cp. Again, any changes in index values are
  28192. -// tracked as needed.
  28193. -//
  28194. -//
  28195. -// Other Details:
  28196. -//
  28197. -// Details for other parts of RedefineClasses need to be written.
  28198. -// This is a placeholder section.
  28199. -//
  28200. -//
  28201. -// Open Issues (in no particular order):
  28202. -//
  28203. -// - How do we serialize the RedefineClasses() API without deadlocking?
  28204. -//
  28205. -// - SystemDictionary::parse_stream() was called with a NULL protection
  28206. -// domain since the initial version. This has been changed to pass
  28207. -// the_class->protection_domain(). This change has been tested with
  28208. -// all NSK tests and nothing broke, but what will adding it now break
  28209. -// in ways that we don't test?
  28210. -//
  28211. -// - GenerateOopMap::rewrite_load_or_store() has a comment in its
  28212. -// (indirect) use of the Relocator class that the max instruction
  28213. -// size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
  28214. -// 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
  28215. -// what it does to the bytecodes. More investigation is needed.
  28216. -//
  28217. -// - java.lang.Object methods can be called on arrays. This is
  28218. -// implemented via the arrayKlassOop vtable which we don't
  28219. -// update. For example, if we redefine java.lang.Object.toString(),
  28220. -// then the new version of the method will not be called for array
  28221. -// objects.
  28222. -//
  28223. -// - How do we know if redefine_single_class() and the guts of
  28224. -// instanceKlass are out of sync? I don't think this can be
  28225. -// automated, but we should probably order the work in
  28226. -// redefine_single_class() to match the order of field
  28227. -// definitions in instanceKlass. We also need to add some
  28228. -// comments about keeping things in sync.
  28229. -//
  28230. -// - set_new_constant_pool() is huge and we should consider refactoring
  28231. -// it into smaller chunks of work.
  28232. -//
  28233. -// - The exception table update code in set_new_constant_pool() defines
  28234. -// const values that are also defined in a local context elsewhere.
  28235. -// The same literal values are also used in elsewhere. We need to
  28236. -// coordinate a cleanup of these constants with Runtime.
  28237. -//
  28238. +// New version that allows arbitrary changes to already loaded classes.
  28239. +// Modifications done by: Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
  28240. -class VM_RedefineClasses: public VM_Operation {
  28241. +#define RC_ABORT(error) { _result = error; return false; }
  28242. +
  28243. +class VM_RedefineClasses: public VM_GC_Operation {
  28244. private:
  28245. +
  28246. // These static fields are needed by SystemDictionary::classes_do()
  28247. // facility and the adjust_cpool_cache_and_vtable() helper:
  28248. static objArrayOop _old_methods;
  28249. static objArrayOop _new_methods;
  28250. - static methodOop* _matching_old_methods;
  28251. - static methodOop* _matching_new_methods;
  28252. - static methodOop* _deleted_methods;
  28253. - static methodOop* _added_methods;
  28254. + static int* _matching_old_methods;
  28255. + static int* _matching_new_methods;
  28256. + static int* _deleted_methods;
  28257. + static int* _added_methods;
  28258. static int _matching_methods_length;
  28259. static int _deleted_methods_length;
  28260. static int _added_methods_length;
  28261. static klassOop _the_class_oop;
  28262. + static int _revision_number;
  28263. +
  28264. // The instance fields are used to pass information from
  28265. // doit_prologue() to doit() and doit_epilogue().
  28266. jint _class_count;
  28267. @@ -359,36 +58,29 @@
  28268. // _index_map_p contains any entries.
  28269. int _index_map_count;
  28270. intArray * _index_map_p;
  28271. - // ptr to _class_count scratch_classes
  28272. - instanceKlassHandle * _scratch_classes;
  28273. - jvmtiError _res;
  28274. + GrowableArray<instanceKlassHandle>* _new_classes;
  28275. + GrowableArray<oop>* _updated_oops;
  28276. + jvmtiError _result;
  28277. + int _max_redefinition_flags;
  28278. // Performance measurement support. These timers do not cover all
  28279. // the work done for JVM/TI RedefineClasses() but they do cover
  28280. // the heavy lifting.
  28281. - elapsedTimer _timer_rsc_phase1;
  28282. - elapsedTimer _timer_rsc_phase2;
  28283. - elapsedTimer _timer_vm_op_prologue;
  28284. + elapsedTimer _timer_total;
  28285. + elapsedTimer _timer_prologue;
  28286. + elapsedTimer _timer_class_linking;
  28287. + elapsedTimer _timer_class_loading;
  28288. + elapsedTimer _timer_check_type;
  28289. + elapsedTimer _timer_prepare_redefinition;
  28290. + elapsedTimer _timer_wait_for_locks;
  28291. + elapsedTimer _timer_redefinition;
  28292. + elapsedTimer _timer_vm_op_epilogue;
  28293. - // These routines are roughly in call order unless otherwise noted.
  28294. -
  28295. - // Load the caller's new class definition(s) into _scratch_classes.
  28296. - // Constant pool merging work is done here as needed. Also calls
  28297. - // compare_and_normalize_class_versions() to verify the class
  28298. - // definition(s).
  28299. + jvmtiError check_redefinition_allowed(instanceKlassHandle new_class);
  28300. + jvmtiError find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses);
  28301. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  28302. jvmtiError load_new_class_versions(TRAPS);
  28303. - // Verify that the caller provided class definition(s) that meet
  28304. - // the restrictions of RedefineClasses. Normalize the order of
  28305. - // overloaded methods as needed.
  28306. - jvmtiError compare_and_normalize_class_versions(
  28307. - instanceKlassHandle the_class, instanceKlassHandle scratch_class);
  28308. -
  28309. - // Swap annotations[i] with annotations[j]
  28310. - // Used by compare_and_normalize_class_versions() when normalizing
  28311. - // overloaded methods or changing idnum as when adding or deleting methods.
  28312. - void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  28313. -
  28314. // Figure out which new methods match old methods in name and signature,
  28315. // which methods have been added, and which are no longer present
  28316. void compute_added_deleted_matching_methods();
  28317. @@ -396,94 +88,94 @@
  28318. // Change jmethodIDs to point to the new methods
  28319. void update_jmethod_ids();
  28320. - // In addition to marking methods as obsolete, this routine
  28321. - // records which methods are EMCP (Equivalent Module Constant
  28322. - // Pool) in the emcp_methods BitMap and returns the number of
  28323. - // EMCP methods via emcp_method_count_p. This information is
  28324. - // used when information about the previous version of the_class
  28325. - // is squirreled away.
  28326. - void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
  28327. - int * emcp_method_count_p);
  28328. - void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  28329. + class FindAffectedKlassesClosure : public ObjectClosure {
  28330. - // Unevolving classes may point to methods of the_class directly
  28331. - // from their constant pool caches, itables, and/or vtables. We
  28332. - // use the SystemDictionary::classes_do() facility and this helper
  28333. - // to fix up these pointers.
  28334. - static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
  28335. + private:
  28336. + GrowableArray<instanceKlassHandle> *_original_klasses;
  28337. + GrowableArray<instanceKlassHandle> *_result;
  28338. +
  28339. + public:
  28340. + FindAffectedKlassesClosure(GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result);
  28341. +
  28342. + virtual void do_object(oop obj);
  28343. + };
  28344. +
  28345. +
  28346. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS);
  28347. // Install the redefinition of a class
  28348. - void redefine_single_class(jclass the_jclass,
  28349. - instanceKlassHandle scratch_class, TRAPS);
  28350. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  28351. // Increment the classRedefinedCount field in the specific instanceKlass
  28352. // and in all direct and indirect subclasses.
  28353. void increment_class_counter(instanceKlass *ik, TRAPS);
  28354. - // Support for constant pool merging (these routines are in alpha
  28355. - // order):
  28356. - void append_entry(constantPoolHandle scratch_cp, int scratch_i,
  28357. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  28358. - int find_new_index(int old_index);
  28359. - bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
  28360. - constantPoolHandle cp2, int index2);
  28361. - bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
  28362. - constantPoolHandle cp2, int index2);
  28363. - void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
  28364. - bool merge_constant_pools(constantPoolHandle old_cp,
  28365. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  28366. - int *merge_cp_length_p, TRAPS);
  28367. - jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
  28368. - instanceKlassHandle scratch_class, TRAPS);
  28369. - u2 rewrite_cp_ref_in_annotation_data(
  28370. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  28371. - const char * trace_mesg, TRAPS);
  28372. - bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
  28373. - bool rewrite_cp_refs_in_annotation_struct(
  28374. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  28375. - bool rewrite_cp_refs_in_annotations_typeArray(
  28376. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
  28377. - bool rewrite_cp_refs_in_class_annotations(
  28378. - instanceKlassHandle scratch_class, TRAPS);
  28379. - bool rewrite_cp_refs_in_element_value(
  28380. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  28381. - bool rewrite_cp_refs_in_fields_annotations(
  28382. - instanceKlassHandle scratch_class, TRAPS);
  28383. - void rewrite_cp_refs_in_method(methodHandle method,
  28384. - methodHandle * new_method_p, TRAPS);
  28385. - bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
  28386. - bool rewrite_cp_refs_in_methods_annotations(
  28387. - instanceKlassHandle scratch_class, TRAPS);
  28388. - bool rewrite_cp_refs_in_methods_default_annotations(
  28389. - instanceKlassHandle scratch_class, TRAPS);
  28390. - bool rewrite_cp_refs_in_methods_parameter_annotations(
  28391. - instanceKlassHandle scratch_class, TRAPS);
  28392. - void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
  28393. - void rewrite_cp_refs_in_verification_type_info(
  28394. - address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
  28395. - u1 frame_size, TRAPS);
  28396. - void set_new_constant_pool(instanceKlassHandle scratch_class,
  28397. - constantPoolHandle scratch_cp, int scratch_cp_length, bool shrink, TRAPS);
  28398. void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  28399. - static void check_class(klassOop k_oop, oop initiating_loader, TRAPS) PRODUCT_RETURN;
  28400. + static void check_class(klassOop k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  28401. - static void dump_methods() PRODUCT_RETURN;
  28402. + static void adjust_cpool_cache(klassOop k_oop, oop initiating_loader, TRAPS);
  28403. +
  28404. +#ifdef ASSERT
  28405. + static void verify_classes(klassOop k_oop, oop initiating_loader, TRAPS);
  28406. +#endif
  28407. +
  28408. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  28409. + void calculate_instance_update_information(klassOop new_version);
  28410. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  28411. public:
  28412. - VM_RedefineClasses(jint class_count,
  28413. - const jvmtiClassDefinition *class_defs,
  28414. - JvmtiClassLoadKind class_load_kind);
  28415. - VMOp_Type type() const { return VMOp_RedefineClasses; }
  28416. + VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  28417. + virtual ~VM_RedefineClasses();
  28418. +
  28419. + bool check_arguments();
  28420. bool doit_prologue();
  28421. void doit();
  28422. void doit_epilogue();
  28423. + void rollback();
  28424. - bool allow_nested_vm_operations() const { return true; }
  28425. - jvmtiError check_error() { return _res; }
  28426. + jvmtiError check_exception() const;
  28427. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  28428. + bool skip_operation() const { return false; }
  28429. + bool allow_nested_vm_operations() const { return true; }
  28430. + jvmtiError check_error() { return _result; }
  28431. +
  28432. + void update_active_methods();
  28433. +
  28434. + // Checks for type consistency after hierarchy change
  28435. + bool check_type_consistency();
  28436. + void calculate_type_check_information();
  28437. + bool check_field_value_types();
  28438. + void clear_type_check_information();
  28439. + bool check_method_stacks();
  28440. + bool check_loaded_methods();
  28441. + bool check_method(methodOop method);
  28442. + static symbolOop signature_to_class_name(symbolOop signature);
  28443. +
  28444. + void method_forwarding();
  28445. +
  28446. + void update_array_classes_to_newest_version(klassOop smallest_dimension);
  28447. // Modifiable test must be shared between IsModifiableClass query
  28448. // and redefine implementation
  28449. static bool is_modifiable_class(oop klass_mirror);
  28450. -};
  28451. +
  28452. + // Method used during garbage collection, the VM operation must iterate over all oops.
  28453. + void oops_do(OopClosure* f);
  28454. +
  28455. + // Utility methods for transfering field access flags
  28456. +
  28457. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  28458. + static void update_klass_field_access_flag(fieldDescriptor *fd);
  28459. +
  28460. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  28461. +
  28462. + void lock_threads();
  28463. + void unlock_threads();
  28464. +
  28465. + template <class T> static void do_oop_work(T* p);
  28466. +
  28467. + static void swap_marks(oop first, oop second);
  28468. +
  28469. +};
  28470. \ No newline at end of file
  28471. diff -r f5603a6e5042 src/share/vm/prims/jvmtiRedefineClassesTrace.hpp
  28472. --- a/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp Wed Nov 17 22:42:08 2010 -0800
  28473. +++ b/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp Fri Dec 17 13:23:04 2010 +0100
  28474. @@ -22,102 +22,26 @@
  28475. *
  28476. */
  28477. -// RedefineClasses tracing support via the TraceRedefineClasses
  28478. -// option. A bit is assigned to each group of trace messages.
  28479. -// Groups of messages are individually selectable. We have to use
  28480. -// decimal values on the command line since the command option
  28481. -// parsing logic doesn't like non-decimal numerics. The HEX values
  28482. -// are used in the actual RC_TRACE() calls for sanity. To achieve
  28483. -// the old cumulative behavior, pick the level after the one in
  28484. -// which you are interested and subtract one, e.g., 33554431 will
  28485. -// print every tracing message.
  28486. -//
  28487. -// 0x00000000 | 0 - default; no tracing messages
  28488. -// 0x00000001 | 1 - name each target class before loading, after
  28489. -// loading and after redefinition is completed
  28490. -// 0x00000002 | 2 - print info if parsing, linking or
  28491. -// verification throws an exception
  28492. -// 0x00000004 | 4 - print timer info for the VM operation
  28493. -// 0x00000008 | 8 - print subclass counter updates
  28494. -// 0x00000010 | 16 - unused
  28495. -// 0x00000020 | 32 - unused
  28496. -// 0x00000040 | 64 - unused
  28497. -// 0x00000080 | 128 - unused
  28498. -// 0x00000100 | 256 - previous class weak reference addition
  28499. -// 0x00000200 | 512 - previous class weak reference mgmt during
  28500. -// class unloading checks (GC)
  28501. -// 0x00000400 | 1024 - previous class weak reference mgmt during
  28502. -// add previous ops (GC)
  28503. -// 0x00000800 | 2048 - previous class breakpoint mgmt
  28504. -// 0x00001000 | 4096 - detect calls to obsolete methods
  28505. -// 0x00002000 | 8192 - fail a guarantee() in addition to detection
  28506. -// 0x00004000 | 16384 - unused
  28507. -// 0x00008000 | 32768 - old/new method matching/add/delete
  28508. -// 0x00010000 | 65536 - impl details: CP size info
  28509. -// 0x00020000 | 131072 - impl details: CP merge pass info
  28510. -// 0x00040000 | 262144 - impl details: CP index maps
  28511. -// 0x00080000 | 524288 - impl details: modified CP index values
  28512. -// 0x00100000 | 1048576 - impl details: vtable updates
  28513. -// 0x00200000 | 2097152 - impl details: itable updates
  28514. -// 0x00400000 | 4194304 - impl details: constant pool cache updates
  28515. -// 0x00800000 | 8388608 - impl details: methodComparator info
  28516. -// 0x01000000 | 16777216 - impl details: nmethod evolution info
  28517. -// 0x02000000 | 33554432 - impl details: annotation updates
  28518. -// 0x04000000 | 67108864 - impl details: StackMapTable updates
  28519. -// 0x08000000 | 134217728 - impl details: OopMapCache updates
  28520. -// 0x10000000 | 268435456 - unused
  28521. -// 0x20000000 | 536870912 - unused
  28522. -// 0x40000000 | 1073741824 - unused
  28523. -// 0x80000000 | 2147483648 - unused
  28524. -//
  28525. -// Note: The ResourceMark is to cleanup resource allocated args.
  28526. -// The "while (0)" is so we can use semi-colon at end of RC_TRACE().
  28527. -#define RC_TRACE(level, args) \
  28528. - if ((TraceRedefineClasses & level) != 0) { \
  28529. - ResourceMark rm; \
  28530. - tty->print("RedefineClasses-0x%x: ", level); \
  28531. - tty->print_cr args; \
  28532. - } while (0)
  28533. +#define IF_TRACE_RC1 if (TraceRedefineClasses >= 1)
  28534. +#define IF_TRACE_RC2 if (TraceRedefineClasses >= 2)
  28535. +#define IF_TRACE_RC3 if (TraceRedefineClasses >= 3)
  28536. +#define IF_TRACE_RC4 if (TraceRedefineClasses >= 4)
  28537. +#define IF_TRACE_RC5 if (TraceRedefineClasses >= 5)
  28538. -#define RC_TRACE_WITH_THREAD(level, thread, args) \
  28539. - if ((TraceRedefineClasses & level) != 0) { \
  28540. - ResourceMark rm(thread); \
  28541. - tty->print("RedefineClasses-0x%x: ", level); \
  28542. - tty->print_cr args; \
  28543. - } while (0)
  28544. -
  28545. -#define RC_TRACE_MESG(args) \
  28546. - { \
  28547. - ResourceMark rm; \
  28548. - tty->print("RedefineClasses: "); \
  28549. - tty->print_cr args; \
  28550. - } while (0)
  28551. -
  28552. -// Macro for checking if TraceRedefineClasses has a specific bit
  28553. -// enabled. Returns true if the bit specified by level is set.
  28554. -#define RC_TRACE_ENABLED(level) ((TraceRedefineClasses & level) != 0)
  28555. -
  28556. -// Macro for checking if TraceRedefineClasses has one or more bits
  28557. -// set in a range of bit values. Returns true if one or more bits
  28558. -// is set in the range from low..high inclusive. Assumes that low
  28559. -// and high are single bit values.
  28560. -//
  28561. -// ((high << 1) - 1)
  28562. -// Yields a mask that removes bits greater than the high bit value.
  28563. -// This algorithm doesn't work with highest bit.
  28564. -// ~(low - 1)
  28565. -// Yields a mask that removes bits lower than the low bit value.
  28566. -#define RC_TRACE_IN_RANGE(low, high) \
  28567. -(((TraceRedefineClasses & ((high << 1) - 1)) & ~(low - 1)) != 0)
  28568. +#define TRACE_RC1 if (TraceRedefineClasses >= 1) tty->print("TraceRedefineClasses-1: "); if (TraceRedefineClasses >= 1) tty->print_cr
  28569. +#define TRACE_RC2 if (TraceRedefineClasses >= 2) tty->print(" TraceRedefineClasses-2: "); if (TraceRedefineClasses >= 2) tty->print_cr
  28570. +#define TRACE_RC3 if (TraceRedefineClasses >= 3) tty->print(" TraceRedefineClasses-3: "); if (TraceRedefineClasses >= 3) tty->print_cr
  28571. +#define TRACE_RC4 if (TraceRedefineClasses >= 4) tty->print(" TraceRedefineClasses-4: "); if (TraceRedefineClasses >= 4) tty->print_cr
  28572. +#define TRACE_RC5 if (TraceRedefineClasses >= 5) tty->print(" TraceRedefineClasses-5: "); if (TraceRedefineClasses >= 5) tty->print_cr
  28573. // Timer support macros. Only do timer operations if timer tracing
  28574. // is enabled. The "while (0)" is so we can use semi-colon at end of
  28575. // the macro.
  28576. #define RC_TIMER_START(t) \
  28577. - if (RC_TRACE_ENABLED(0x00000004)) { \
  28578. + if (TimeRedefineClasses) { \
  28579. t.start(); \
  28580. } while (0)
  28581. #define RC_TIMER_STOP(t) \
  28582. - if (RC_TRACE_ENABLED(0x00000004)) { \
  28583. + if (TimeRedefineClasses) { \
  28584. t.stop(); \
  28585. } while (0)
  28586. diff -r f5603a6e5042 src/share/vm/prims/methodComparator.cpp
  28587. --- a/src/share/vm/prims/methodComparator.cpp Wed Nov 17 22:42:08 2010 -0800
  28588. +++ b/src/share/vm/prims/methodComparator.cpp Fri Dec 17 13:23:04 2010 +0100
  28589. @@ -37,10 +37,9 @@
  28590. if (old_method->code_size() != new_method->code_size())
  28591. return false;
  28592. if (check_stack_and_locals_size(old_method, new_method) != 0) {
  28593. - // RC_TRACE macro has an embedded ResourceMark
  28594. - RC_TRACE(0x00800000, ("Methods %s non-comparable with diagnosis %d",
  28595. + TRACE_RC4("Methods %s non-comparable with diagnosis %d",
  28596. old_method->name()->as_C_string(),
  28597. - check_stack_and_locals_size(old_method, new_method)));
  28598. + check_stack_and_locals_size(old_method, new_method));
  28599. return false;
  28600. }
  28601. @@ -60,6 +59,37 @@
  28602. if (! args_same(c_old, c_new))
  28603. return false;
  28604. }
  28605. +
  28606. + // (tw) Added exception table comparison to EMCP comparison
  28607. +
  28608. + typeArrayOop ex_old = old_method->constMethod()->exception_table();
  28609. + typeArrayOop ex_new = new_method->constMethod()->exception_table();
  28610. +
  28611. + if (ex_old == NULL && ex_new != NULL) return false;
  28612. + if (ex_old != NULL && ex_new == NULL) return false;
  28613. +
  28614. + if (ex_old != NULL && ex_new != NULL && ex_old->length() == ex_new->length()) {
  28615. + // Per entry:
  28616. + /* start */
  28617. + /* limit */
  28618. + /* goto pc */
  28619. + /* cp index */
  28620. + for (int i=0; i<ex_old->length(); i++) {
  28621. + int old_val = ex_old->int_at(i);
  28622. + int new_val = ex_new->int_at(i);
  28623. + if ((i + 1) % 4 == 0) {
  28624. + if (old_val == 0 || new_val == 0) {
  28625. + if (old_val != new_val) return false;
  28626. + } else if ((_old_cp->klass_at_noresolve(old_val) != _new_cp->klass_at_noresolve(new_val)))
  28627. + return false;
  28628. + } else {
  28629. + if (old_val != new_val) {
  28630. + return false;
  28631. + }
  28632. + }
  28633. + }
  28634. + }
  28635. +
  28636. return true;
  28637. }
  28638. @@ -109,10 +139,9 @@
  28639. // Now we can test all forward jumps
  28640. for (int i = 0; i < fwd_jmps.length() / 2; i++) {
  28641. if (! bci_map.old_and_new_locations_same(fwd_jmps.at(i*2), fwd_jmps.at(i*2+1))) {
  28642. - RC_TRACE(0x00800000,
  28643. - ("Fwd jump miss: old dest = %d, calc new dest = %d, act new dest = %d",
  28644. + TRACE_RC4("Fwd jump miss: old dest = %d, calc new dest = %d, act new dest = %d",
  28645. fwd_jmps.at(i*2), bci_map.new_bci_for_old(fwd_jmps.at(i*2)),
  28646. - fwd_jmps.at(i*2+1)));
  28647. + fwd_jmps.at(i*2+1));
  28648. return false;
  28649. }
  28650. }
  28651. diff -r f5603a6e5042 src/share/vm/prims/nativeLookup.cpp
  28652. --- a/src/share/vm/prims/nativeLookup.cpp Wed Nov 17 22:42:08 2010 -0800
  28653. +++ b/src/share/vm/prims/nativeLookup.cpp Fri Dec 17 13:23:04 2010 +0100
  28654. @@ -1,4 +1,4 @@
  28655. -/*
  28656. +*
  28657. * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
  28658. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  28659. *
  28660. @@ -24,7 +24,7 @@
  28661. # include "incls/_precompiled.incl"
  28662. # include "incls/_nativeLookup.cpp.incl"
  28663. -
  28664. +# include "incls/_jvmtiEnv.cpp.incl"
  28665. static void mangle_name_on(outputStream* st, symbolOop name, int begin, int end) {
  28666. char* bytes = (char*)name->bytes() + begin;
  28667. @@ -82,6 +82,39 @@
  28668. void JNICALL JVM_RegisterPerfMethods(JNIEnv *env, jclass perfclass);
  28669. }
  28670. +// Helper function to call redefineClasses from Java Code
  28671. +JVM_ENTRY(int, JVM_RedefineClassesHelper(JNIEnv *env, jclass cb, jclass target, jbyteArray bytes))
  28672. + ResourceMark rm(THREAD);
  28673. +
  28674. + JavaThread* current_thread = JavaThread::current();
  28675. + jbyte* bytecodes = NULL;
  28676. + const int class_count = 1;
  28677. + jvmtiClassDefinition* class_definitions = NEW_RESOURCE_ARRAY(jvmtiClassDefinition, class_count);
  28678. +
  28679. + {
  28680. + ThreadToNativeFromVM ttnfv(thread);
  28681. + bytecodes = env->GetByteArrayElements(bytes, false);
  28682. + class_definitions[0].klass = target;
  28683. + class_definitions[0].class_byte_count = env->GetArrayLength(bytes);
  28684. + class_definitions[0].class_bytes = (unsigned char*)bytecodes;
  28685. + }
  28686. +
  28687. + VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  28688. + VMThread::execute(&op);
  28689. + int result = op.check_error();
  28690. +
  28691. + {
  28692. + ThreadToNativeFromVM ttnfv(thread);
  28693. + if (env->ExceptionOccurred()) {
  28694. + return -1;
  28695. + }
  28696. + env->ReleaseByteArrayElements(bytes, bytecodes, 0);
  28697. + }
  28698. +
  28699. + return result;
  28700. +JVM_END
  28701. +
  28702. +
  28703. static address lookup_special_native(char* jni_name) {
  28704. // NB: To ignore the jni prefix and jni postfix strstr is used matching.
  28705. if (!JDK_Version::is_gte_jdk14x_version()) {
  28706. @@ -135,6 +168,9 @@
  28707. return entry;
  28708. }
  28709. }
  28710. + if(strstr(jni_name, "Java_at_ssw_hotswap_ClassRedefinition_redefineClasses") != NULL) {
  28711. + return CAST_FROM_FN_PTR(address, JVM_RedefineClassesHelper);
  28712. + }
  28713. // Otherwise call static method findNative in ClassLoader
  28714. KlassHandle klass (THREAD, SystemDictionary::ClassLoader_klass());
  28715. diff -r f5603a6e5042 src/share/vm/runtime/arguments.cpp
  28716. --- a/src/share/vm/runtime/arguments.cpp Wed Nov 17 22:42:08 2010 -0800
  28717. +++ b/src/share/vm/runtime/arguments.cpp Fri Dec 17 13:23:04 2010 +0100
  28718. @@ -25,7 +25,7 @@
  28719. #include "incls/_precompiled.incl"
  28720. #include "incls/_arguments.cpp.incl"
  28721. -#define DEFAULT_VENDOR_URL_BUG "http://java.sun.com/webapps/bugreport/crash.jsp"
  28722. +#define DEFAULT_VENDOR_URL_BUG "http://ssw.jku.at/dcevm/bugreport/"
  28723. #define DEFAULT_JAVA_LAUNCHER "generic"
  28724. char** Arguments::_jvm_flags_array = NULL;
  28725. @@ -1704,6 +1704,15 @@
  28726. status = false;
  28727. }
  28728. + // (tw) Must use serial GC
  28729. + if (!UseSerialGC && i >= 1) {
  28730. + jio_fprintf(defaultStream::error_stream(),
  28731. + "Must use the serial GC in the Dynamic Code Evolution VM\n");
  28732. + status = false;
  28733. + } else {
  28734. + UseSerialGC = true;
  28735. + }
  28736. +
  28737. return status;
  28738. }
  28739. diff -r f5603a6e5042 src/share/vm/runtime/deoptimization.cpp
  28740. --- a/src/share/vm/runtime/deoptimization.cpp Wed Nov 17 22:42:08 2010 -0800
  28741. +++ b/src/share/vm/runtime/deoptimization.cpp Fri Dec 17 13:23:04 2010 +0100
  28742. @@ -513,6 +513,38 @@
  28743. // Cleanup thread deopt data
  28744. cleanup_deopt_info(thread, array);
  28745. + // (tw) Redefinition support: Check if we need to transfer method execution points to new versions
  28746. + {
  28747. + ResourceMark res_mark;
  28748. +
  28749. + // Verify that the just-unpacked frames match the interpreter's
  28750. + // notions of expression stack and locals
  28751. + vframeArray* cur_array = thread->vframe_array_last();
  28752. + RegisterMap rm(thread, false);
  28753. + rm.set_include_argument_oops(false);
  28754. + for (int i = 0; i < cur_array->frames(); i++) {
  28755. + vframeArrayElement* el = cur_array->element(i);
  28756. + frame* frame = el->iframe();
  28757. + guarantee(frame->is_interpreted_frame(), "Wrong frame type");
  28758. + RegisterMap reg_map(thread);
  28759. + vframe* vf = vframe::new_vframe(frame, &reg_map, thread);
  28760. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  28761. + methodOop method = iframe->method();
  28762. + int bci = iframe->bci();
  28763. + method = method->newest_version();
  28764. + iframe->set_method(method, bci);
  28765. +
  28766. + methodOop forward_method = method->forward_method();
  28767. + if (forward_method != NULL && method->is_in_code_section(bci)) {
  28768. + int new_bci = method->calculate_forward_bci(bci, forward_method);
  28769. + if (TraceRedefineClasses >= 2) {
  28770. + tty->print_cr("Transfering execution of %s to new method old_bci=%d new_bci=%d", forward_method->name()->as_C_string(), bci, new_bci);
  28771. + }
  28772. + iframe->set_method(forward_method, new_bci);
  28773. + }
  28774. + }
  28775. + }
  28776. +
  28777. #ifndef PRODUCT
  28778. if (VerifyStack) {
  28779. ResourceMark res_mark;
  28780. diff -r f5603a6e5042 src/share/vm/runtime/frame.cpp
  28781. --- a/src/share/vm/runtime/frame.cpp Wed Nov 17 22:42:08 2010 -0800
  28782. +++ b/src/share/vm/runtime/frame.cpp Fri Dec 17 13:23:04 2010 +0100
  28783. @@ -357,6 +357,12 @@
  28784. *interpreter_frame_method_addr() = method;
  28785. }
  28786. +// (tw) Sets constant pool cache oop
  28787. +void frame::interpreter_frame_set_cache(constantPoolCacheOop cp) {
  28788. + assert(is_interpreted_frame(), "interpreted frame expected");
  28789. + *interpreter_frame_cache_addr() = cp;
  28790. +}
  28791. +
  28792. void frame::interpreter_frame_set_bcx(intptr_t bcx) {
  28793. assert(is_interpreted_frame(), "Not an interpreted frame");
  28794. if (ProfileInterpreter) {
  28795. @@ -372,19 +378,27 @@
  28796. // The bcx was just converted from bci to bcp.
  28797. // Convert the mdx in parallel.
  28798. methodDataOop mdo = interpreter_frame_method()->method_data();
  28799. - assert(mdo != NULL, "");
  28800. - int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  28801. - address mdp = mdo->di_to_dp(mdi);
  28802. - interpreter_frame_set_mdx((intptr_t)mdp);
  28803. + if (mdo == NULL) {
  28804. + interpreter_frame_set_mdx(0);
  28805. + } else {
  28806. + assert(mdo != NULL, "");
  28807. + int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  28808. + address mdp = mdo->di_to_dp(mdi);
  28809. + interpreter_frame_set_mdx((intptr_t)mdp);
  28810. + }
  28811. }
  28812. } else {
  28813. if (is_now_bci) {
  28814. // The bcx was just converted from bcp to bci.
  28815. // Convert the mdx in parallel.
  28816. methodDataOop mdo = interpreter_frame_method()->method_data();
  28817. - assert(mdo != NULL, "");
  28818. - int mdi = mdo->dp_to_di((address)mdx);
  28819. - interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  28820. + if (mdo == NULL) {
  28821. + interpreter_frame_set_mdx(0);
  28822. + } else {
  28823. + assert(mdo != NULL, "");
  28824. + int mdi = mdo->dp_to_di((address)mdx);
  28825. + interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  28826. + }
  28827. }
  28828. }
  28829. }
  28830. diff -r f5603a6e5042 src/share/vm/runtime/frame.hpp
  28831. --- a/src/share/vm/runtime/frame.hpp Wed Nov 17 22:42:08 2010 -0800
  28832. +++ b/src/share/vm/runtime/frame.hpp Fri Dec 17 13:23:04 2010 +0100
  28833. @@ -295,6 +295,7 @@
  28834. // Method & constant pool cache
  28835. methodOop interpreter_frame_method() const;
  28836. void interpreter_frame_set_method(methodOop method);
  28837. + void interpreter_frame_set_cache(constantPoolCacheOop method);
  28838. methodOop* interpreter_frame_method_addr() const;
  28839. constantPoolCacheOop* interpreter_frame_cache_addr() const;
  28840. #ifdef PPC
  28841. diff -r f5603a6e5042 src/share/vm/runtime/globals.hpp
  28842. --- a/src/share/vm/runtime/globals.hpp Wed Nov 17 22:42:08 2010 -0800
  28843. +++ b/src/share/vm/runtime/globals.hpp Fri Dec 17 13:23:04 2010 +0100
  28844. @@ -1127,9 +1127,23 @@
  28845. product(bool, StressLdcRewrite, false, \
  28846. "Force ldc -> ldc_w rewrite during RedefineClasses") \
  28847. \
  28848. + product(bool, UseMethodForwardPoints, false, \
  28849. + "Use method forward points") \
  28850. + \
  28851. + product(intx, MethodForwardPointsMaxLocals, 300, \
  28852. + "Maximum number of locals in forwarding method") \
  28853. + \
  28854. + product(intx, MethodForwardPointsMaxStack, 300, \
  28855. + "Maximum number of stack slots in forwarding method") \
  28856. + \
  28857. product(intx, TraceRedefineClasses, 0, \
  28858. "Trace level for JVMTI RedefineClasses") \
  28859. \
  28860. + product(bool, TimeRedefineClasses, false, \
  28861. + "Measure timing for JVMTI RedefineClasses") \
  28862. + \
  28863. + product(bool, AllowAdvancedClassRedefinition, true, \
  28864. + "Allow advanced class redefinition beyond swapping method bodies")\
  28865. develop(bool, StressMethodComparator, false, \
  28866. "run the MethodComparator on all loaded methods") \
  28867. \
  28868. diff -r f5603a6e5042 src/share/vm/runtime/interfaceSupport.hpp
  28869. --- a/src/share/vm/runtime/interfaceSupport.hpp Wed Nov 17 22:42:08 2010 -0800
  28870. +++ b/src/share/vm/runtime/interfaceSupport.hpp Fri Dec 17 13:23:04 2010 +0100
  28871. @@ -257,7 +257,7 @@
  28872. ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
  28873. // We are leaving the VM at this point and going directly to native code.
  28874. // Block, if we are in the middle of a safepoint synchronization.
  28875. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  28876. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  28877. thread->frame_anchor()->make_walkable(thread);
  28878. trans_and_fence(_thread_in_vm, _thread_in_native);
  28879. // Check for pending. async. exceptions or suspends.
  28880. diff -r f5603a6e5042 src/share/vm/runtime/javaCalls.cpp
  28881. --- a/src/share/vm/runtime/javaCalls.cpp Wed Nov 17 22:42:08 2010 -0800
  28882. +++ b/src/share/vm/runtime/javaCalls.cpp Fri Dec 17 13:23:04 2010 +0100
  28883. @@ -33,7 +33,7 @@
  28884. bool clear_pending_exception = true;
  28885. guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
  28886. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  28887. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  28888. guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
  28889. _result = result;
  28890. diff -r f5603a6e5042 src/share/vm/runtime/jniHandles.cpp
  28891. --- a/src/share/vm/runtime/jniHandles.cpp Wed Nov 17 22:42:08 2010 -0800
  28892. +++ b/src/share/vm/runtime/jniHandles.cpp Fri Dec 17 13:23:04 2010 +0100
  28893. @@ -96,6 +96,10 @@
  28894. }
  28895. jmethodID JNIHandles::make_jmethod_id(methodHandle mh) {
  28896. + if (mh->newest_version() != mh()) {
  28897. + methodHandle mh_new(Thread::current(), mh()->newest_version());
  28898. + return (jmethodID) make_weak_global(mh_new);
  28899. + }
  28900. return (jmethodID) make_weak_global(mh);
  28901. }
  28902. diff -r f5603a6e5042 src/share/vm/runtime/mutex.cpp
  28903. --- a/src/share/vm/runtime/mutex.cpp Wed Nov 17 22:42:08 2010 -0800
  28904. +++ b/src/share/vm/runtime/mutex.cpp Fri Dec 17 13:23:04 2010 +0100
  28905. @@ -1195,7 +1195,7 @@
  28906. // in increasing rank order (modulo any native ranks)
  28907. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  28908. if (tmp->next() != NULL) {
  28909. - assert(tmp->rank() == Mutex::native ||
  28910. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  28911. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  28912. }
  28913. }
  28914. @@ -1215,7 +1215,7 @@
  28915. // in increasing rank order (modulo any native ranks)
  28916. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  28917. if (tmp->next() != NULL) {
  28918. - assert(tmp->rank() == Mutex::native ||
  28919. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  28920. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  28921. }
  28922. }
  28923. @@ -1282,6 +1282,7 @@
  28924. // already hold Terminator_lock - may happen because of periodic safepoints
  28925. if (this->rank() != Mutex::native &&
  28926. this->rank() != Mutex::suspend_resume &&
  28927. + this->rank() != Mutex::redefine_classes &&
  28928. locks != NULL && locks->rank() <= this->rank() &&
  28929. !SafepointSynchronize::is_at_safepoint() &&
  28930. this != Interrupt_lock && this != ProfileVM_lock &&
  28931. diff -r f5603a6e5042 src/share/vm/runtime/mutex.hpp
  28932. --- a/src/share/vm/runtime/mutex.hpp Wed Nov 17 22:42:08 2010 -0800
  28933. +++ b/src/share/vm/runtime/mutex.hpp Fri Dec 17 13:23:04 2010 +0100
  28934. @@ -102,7 +102,8 @@
  28935. barrier = safepoint + 1,
  28936. nonleaf = barrier + 1,
  28937. max_nonleaf = nonleaf + 900,
  28938. - native = max_nonleaf + 1
  28939. + native = max_nonleaf + 1,
  28940. + redefine_classes = native + 1
  28941. };
  28942. // The WaitSet and EntryList linked lists are composed of ParkEvents.
  28943. diff -r f5603a6e5042 src/share/vm/runtime/mutexLocker.cpp
  28944. --- a/src/share/vm/runtime/mutexLocker.cpp Wed Nov 17 22:42:08 2010 -0800
  28945. +++ b/src/share/vm/runtime/mutexLocker.cpp Fri Dec 17 13:23:04 2010 +0100
  28946. @@ -34,6 +34,7 @@
  28947. // Consider using GCC's __read_mostly.
  28948. Mutex* Patching_lock = NULL;
  28949. +Mutex* RedefineClasses_lock = NULL;
  28950. Monitor* SystemDictionary_lock = NULL;
  28951. Mutex* PackageTable_lock = NULL;
  28952. Mutex* CompiledIC_lock = NULL;
  28953. @@ -77,6 +78,7 @@
  28954. Mutex* DirtyCardQ_FL_lock = NULL;
  28955. Monitor* DirtyCardQ_CBL_mon = NULL;
  28956. Mutex* Shared_DirtyCardQ_lock = NULL;
  28957. +Monitor* RedefinitionSync_lock = NULL;
  28958. Mutex* ParGCRareEvent_lock = NULL;
  28959. Mutex* EvacFailureStack_lock = NULL;
  28960. Mutex* DerivedPointerTableGC_lock = NULL;
  28961. @@ -180,6 +182,7 @@
  28962. def(HotCardCache_lock , Mutex , special , true );
  28963. def(EvacFailureStack_lock , Mutex , nonleaf , true );
  28964. }
  28965. + def(RedefinitionSync_lock , Monitor , leaf , false );
  28966. def(ParGCRareEvent_lock , Mutex , leaf , true );
  28967. def(DerivedPointerTableGC_lock , Mutex, leaf, true );
  28968. def(CodeCache_lock , Mutex , special, true );
  28969. @@ -253,6 +256,7 @@
  28970. def(Debug2_lock , Mutex , nonleaf+4, true );
  28971. def(Debug3_lock , Mutex , nonleaf+4, true );
  28972. def(ProfileVM_lock , Monitor, nonleaf+4, false); // used for profiling of the VMThread
  28973. + def(RedefineClasses_lock , Mutex, nonleaf+7, false ); // for ensuring that class redefinition is not done in parallel
  28974. def(CompileThread_lock , Monitor, nonleaf+5, false );
  28975. }
  28976. diff -r f5603a6e5042 src/share/vm/runtime/mutexLocker.hpp
  28977. --- a/src/share/vm/runtime/mutexLocker.hpp Wed Nov 17 22:42:08 2010 -0800
  28978. +++ b/src/share/vm/runtime/mutexLocker.hpp Fri Dec 17 13:23:04 2010 +0100
  28979. @@ -25,6 +25,8 @@
  28980. // Mutexes used in the VM.
  28981. extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
  28982. +extern Monitor* RedefinitionSync_lock; // a lock on synchronized class redefinition
  28983. +extern Mutex* RedefineClasses_lock; // a lock on class redefinition
  28984. extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
  28985. extern Mutex* PackageTable_lock; // a lock on the class loader package table
  28986. extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
  28987. diff -r f5603a6e5042 src/share/vm/runtime/reflection.cpp
  28988. --- a/src/share/vm/runtime/reflection.cpp Wed Nov 17 22:42:08 2010 -0800
  28989. +++ b/src/share/vm/runtime/reflection.cpp Fri Dec 17 13:23:04 2010 +0100
  28990. @@ -449,7 +449,8 @@
  28991. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  28992. if ( JDK_Version::is_gte_jdk14x_version()
  28993. && UseNewReflection
  28994. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  28995. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  28996. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  28997. return true;
  28998. }
  28999. @@ -505,6 +506,12 @@
  29000. AccessFlags access,
  29001. bool classloader_only,
  29002. bool protected_restriction) {
  29003. +
  29004. + // (tw) Decide accessibility based on active version
  29005. + if (current_class != NULL) {
  29006. + current_class = current_class->klass_part()->active_version();
  29007. + }
  29008. +
  29009. // Verify that current_class can access a field of field_class, where that
  29010. // field's access bits are "access". We assume that we've already verified
  29011. // that current_class can access field_class.
  29012. @@ -546,7 +553,8 @@
  29013. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  29014. if ( JDK_Version::is_gte_jdk14x_version()
  29015. && UseNewReflection
  29016. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  29017. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  29018. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  29019. return true;
  29020. }
  29021. diff -r f5603a6e5042 src/share/vm/runtime/sharedRuntime.cpp
  29022. --- a/src/share/vm/runtime/sharedRuntime.cpp Wed Nov 17 22:42:08 2010 -0800
  29023. +++ b/src/share/vm/runtime/sharedRuntime.cpp Fri Dec 17 13:23:04 2010 +0100
  29024. @@ -511,21 +511,13 @@
  29025. //
  29026. JRT_LEAF(int, SharedRuntime::rc_trace_method_entry(
  29027. JavaThread* thread, methodOopDesc* method))
  29028. - assert(RC_TRACE_IN_RANGE(0x00001000, 0x00002000), "wrong call");
  29029. + assert(TraceRedefineClasses >= 4, "wrong call");
  29030. if (method->is_obsolete()) {
  29031. // We are calling an obsolete method, but this is not necessarily
  29032. // an error. Our method could have been redefined just after we
  29033. // fetched the methodOop from the constant pool.
  29034. -
  29035. - // RC_TRACE macro has an embedded ResourceMark
  29036. - RC_TRACE_WITH_THREAD(0x00001000, thread,
  29037. - ("calling obsolete method '%s'",
  29038. - method->name_and_sig_as_C_string()));
  29039. - if (RC_TRACE_ENABLED(0x00002000)) {
  29040. - // this option is provided to debug calls to obsolete methods
  29041. - guarantee(false, "faulting at call to an obsolete method.");
  29042. - }
  29043. + TRACE_RC4("calling obsolete method '%s'", method->name_and_sig_as_C_string());
  29044. }
  29045. return 0;
  29046. JRT_END
  29047. @@ -986,7 +978,20 @@
  29048. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  29049. int retry_count = 0;
  29050. while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
  29051. - callee_method->method_holder() != SystemDictionary::Object_klass()) {
  29052. + callee_method->method_holder()->klass_part()->newest_version() != SystemDictionary::Object_klass()->klass_part()->newest_version()) {
  29053. +
  29054. + // (tw) If we are executing an old method, this is OK!
  29055. + {
  29056. + ResourceMark rm(thread);
  29057. + RegisterMap cbl_map(thread, false);
  29058. + frame caller_frame = thread->last_frame().sender(&cbl_map);
  29059. +
  29060. + CodeBlob* caller_cb = caller_frame.cb();
  29061. + guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
  29062. + nmethod* caller_nm = caller_cb->as_nmethod_or_null();
  29063. + if (caller_nm->method()->is_old()) break;
  29064. + }
  29065. +
  29066. // If has a pending exception then there is no need to re-try to
  29067. // resolve this method.
  29068. // If the method has been redefined, we need to try again.
  29069. diff -r f5603a6e5042 src/share/vm/runtime/thread.cpp
  29070. --- a/src/share/vm/runtime/thread.cpp Wed Nov 17 22:42:08 2010 -0800
  29071. +++ b/src/share/vm/runtime/thread.cpp Fri Dec 17 13:23:04 2010 +0100
  29072. @@ -109,6 +109,8 @@
  29073. _lgrp_id = -1;
  29074. _osthread = NULL;
  29075. + _redefine_classes_mutex = new Mutex(Mutex::redefine_classes, "redefine classes lock", false);
  29076. +
  29077. // allocated data structures
  29078. set_resource_area(new ResourceArea());
  29079. set_handle_area(new HandleArea(NULL));
  29080. @@ -141,6 +143,7 @@
  29081. omFreeProvision = 32 ;
  29082. omInUseList = NULL ;
  29083. omInUseCount = 0 ;
  29084. + _pretend_new_universe = false;
  29085. _SR_lock = new Monitor(Mutex::suspend_resume, "SR_lock", true);
  29086. _suspend_flags = 0;
  29087. @@ -747,6 +750,15 @@
  29088. return false;
  29089. }
  29090. +bool Thread::owns_locks_but_redefine_classes_lock() const {
  29091. + for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  29092. + if (cur != RedefineClasses_lock && cur->rank() != Mutex::redefine_classes) {
  29093. + return true;
  29094. + }
  29095. + }
  29096. + return false;
  29097. +}
  29098. +
  29099. #endif
  29100. @@ -1397,7 +1409,7 @@
  29101. ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  29102. assert(JavaThread::current() == this, "sanity check");
  29103. - assert(!Thread::current()->owns_locks(), "sanity check");
  29104. + assert(!Thread::current()->owns_locks_but_redefine_classes_lock(), "sanity check");
  29105. DTRACE_THREAD_PROBE(start, this);
  29106. @@ -2842,13 +2854,14 @@
  29107. // Create a CompilerThread
  29108. CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  29109. -: JavaThread(&compiler_thread_entry) {
  29110. +: JavaThread(&compiler_thread_entry), _should_bailout(false) {
  29111. _env = NULL;
  29112. _log = NULL;
  29113. _task = NULL;
  29114. _queue = queue;
  29115. _counters = counters;
  29116. _buffer_blob = NULL;
  29117. + _compilation_mutex = new Mutex(Mutex::redefine_classes, "compilationMutex", false);
  29118. #ifndef PRODUCT
  29119. _ideal_graph_printer = NULL;
  29120. @@ -2869,6 +2882,7 @@
  29121. int Threads::_number_of_non_daemon_threads = 0;
  29122. int Threads::_return_code = 0;
  29123. size_t JavaThread::_stack_size_at_create = 0;
  29124. +bool Threads::_wait_at_instrumentation_entry = false;
  29125. // All JavaThreads
  29126. #define ALL_JAVA_THREADS(X) for (JavaThread* X = _thread_list; X; X = X->next())
  29127. diff -r f5603a6e5042 src/share/vm/runtime/thread.hpp
  29128. --- a/src/share/vm/runtime/thread.hpp Wed Nov 17 22:42:08 2010 -0800
  29129. +++ b/src/share/vm/runtime/thread.hpp Fri Dec 17 13:23:04 2010 +0100
  29130. @@ -162,11 +162,14 @@
  29131. void enter_signal_handler() { _num_nested_signal++; }
  29132. void leave_signal_handler() { _num_nested_signal--; }
  29133. bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  29134. + Mutex* redefine_classes_mutex() { return _redefine_classes_mutex; }
  29135. private:
  29136. // Debug tracing
  29137. static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
  29138. + Mutex* _redefine_classes_mutex;
  29139. +
  29140. // Active_handles points to a block of handles
  29141. JNIHandleBlock* _active_handles;
  29142. @@ -438,10 +441,15 @@
  29143. uintptr_t _self_raw_id; // used by get_thread (mutable)
  29144. int _lgrp_id;
  29145. +
  29146. + bool _pretend_new_universe;
  29147. +
  29148. public:
  29149. // Stack overflow support
  29150. address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
  29151. + void set_pretend_new_universe(bool b) { if (_pretend_new_universe != b) { if (TraceRedefineClasses >= 5) tty->print_cr("Changing pretend universe to %d", (int)b); _pretend_new_universe = b; } }
  29152. + bool pretend_new_universe() { return _pretend_new_universe; }
  29153. void set_stack_base(address base) { _stack_base = base; }
  29154. size_t stack_size() const { return _stack_size; }
  29155. void set_stack_size(size_t size) { _stack_size = size; }
  29156. @@ -476,6 +484,7 @@
  29157. void print_owned_locks() const { print_owned_locks_on(tty); }
  29158. Monitor * owned_locks() const { return _owned_locks; }
  29159. bool owns_locks() const { return owned_locks() != NULL; }
  29160. + bool owns_locks_but_redefine_classes_lock() const;
  29161. bool owns_locks_but_compiled_lock() const;
  29162. // Deadlock detection
  29163. @@ -1611,6 +1620,8 @@
  29164. CompileTask* _task;
  29165. CompileQueue* _queue;
  29166. BufferBlob* _buffer_blob;
  29167. + bool _should_bailout;
  29168. + Mutex* _compilation_mutex;
  29169. public:
  29170. @@ -1618,12 +1629,16 @@
  29171. CompilerThread(CompileQueue* queue, CompilerCounters* counters);
  29172. + bool should_bailout() const { return _should_bailout; }
  29173. + void set_should_bailout(bool b) { _should_bailout = false; }
  29174. +
  29175. bool is_Compiler_thread() const { return true; }
  29176. // Hide this compiler thread from external view.
  29177. bool is_hidden_from_external_view() const { return true; }
  29178. CompileQueue* queue() { return _queue; }
  29179. CompilerCounters* counters() { return _counters; }
  29180. + Mutex *compilation_mutex() { return _compilation_mutex; }
  29181. // Get/set the thread's compilation environment.
  29182. ciEnv* env() { return _env; }
  29183. @@ -1667,6 +1682,7 @@
  29184. static int _number_of_threads;
  29185. static int _number_of_non_daemon_threads;
  29186. static int _return_code;
  29187. + static bool _wait_at_instrumentation_entry;
  29188. public:
  29189. // Thread management
  29190. @@ -1678,6 +1694,9 @@
  29191. static JavaThread* first() { return _thread_list; }
  29192. static void threads_do(ThreadClosure* tc);
  29193. + static bool wait_at_instrumentation_entry() { return _wait_at_instrumentation_entry; }
  29194. + static void set_wait_at_instrumentation_entry(bool b) { _wait_at_instrumentation_entry = b; }
  29195. +
  29196. // Initializes the vm and creates the vm thread
  29197. static jint create_vm(JavaVMInitArgs* args, bool* canTryAgain);
  29198. static void convert_vm_init_libraries_to_agents();
  29199. diff -r f5603a6e5042 src/share/vm/runtime/vframe.cpp
  29200. --- a/src/share/vm/runtime/vframe.cpp Wed Nov 17 22:42:08 2010 -0800
  29201. +++ b/src/share/vm/runtime/vframe.cpp Fri Dec 17 13:23:04 2010 +0100
  29202. @@ -232,6 +232,46 @@
  29203. return fr().interpreter_frame_method();
  29204. }
  29205. +// (tw) Sets interpreter frame method.
  29206. +void interpretedVFrame::set_method(methodOop new_method, int new_bci) {
  29207. + methodOop old_method = fr().interpreter_frame_method();
  29208. + int old_stack_size = fr().interpreter_frame_expression_stack_size();
  29209. + if (old_method == new_method) return;
  29210. + u_char *old_bcp = bcp();
  29211. + int old_bci = bci();
  29212. + fr().interpreter_frame_set_method(new_method);
  29213. + fr().interpreter_frame_set_cache(new_method->constants()->cache());
  29214. + u_char *new_bcp = new_method->code_base() + new_bci;
  29215. + assert(new_method->bcp_from(new_bci) == new_bcp, "");
  29216. +
  29217. + set_bcp(new_bcp);
  29218. +
  29219. + Bytecodes::Code code = Bytecodes::java_code_at(old_bcp);
  29220. + assert(Bytecodes::java_code_at(new_bcp) == code, "must have same bytecode at this position");
  29221. +
  29222. + switch (code) {
  29223. + case Bytecodes::_invokevirtual :
  29224. + case Bytecodes::_invokespecial :
  29225. + case Bytecodes::_invokestatic :
  29226. + case Bytecodes::_invokeinterface: {
  29227. + int old_index = Bytes::get_native_u2(old_bcp+1);
  29228. + int new_index = Bytes::get_native_u2(new_bcp+1);
  29229. + new_method->constants()->cache()->entry_at(new_index)->copy_from(old_method->constants()->cache()->entry_at(old_index));
  29230. + break;
  29231. + }
  29232. +
  29233. + case Bytecodes::_invokedynamic: {
  29234. + int old_index = Bytes::get_native_u4(old_bcp+1);
  29235. + int new_index = Bytes::get_native_u4(new_bcp+1);
  29236. + new_method->constants()->cache()->secondary_entry_at(new_index)->copy_from(old_method->constants()->cache()->secondary_entry_at(old_index));
  29237. + break;
  29238. + }
  29239. + }
  29240. +
  29241. + int new_stack_size = fr().interpreter_frame_expression_stack_size();
  29242. + assert(new_method->validate_bci_from_bcx((intptr_t)new_bcp) == new_bci, "");
  29243. +}
  29244. +
  29245. StackValueCollection* interpretedVFrame::locals() const {
  29246. int length = method()->max_locals();
  29247. diff -r f5603a6e5042 src/share/vm/runtime/vframe.hpp
  29248. --- a/src/share/vm/runtime/vframe.hpp Wed Nov 17 22:42:08 2010 -0800
  29249. +++ b/src/share/vm/runtime/vframe.hpp Fri Dec 17 13:23:04 2010 +0100
  29250. @@ -150,6 +150,7 @@
  29251. StackValueCollection* locals() const;
  29252. StackValueCollection* expressions() const;
  29253. GrowableArray<MonitorInfo*>* monitors() const;
  29254. + void set_method(methodOop method, int new_bci);
  29255. void set_locals(StackValueCollection* values) const;
  29256. diff -r f5603a6e5042 src/share/vm/runtime/vmThread.cpp
  29257. --- a/src/share/vm/runtime/vmThread.cpp Wed Nov 17 22:42:08 2010 -0800
  29258. +++ b/src/share/vm/runtime/vmThread.cpp Fri Dec 17 13:23:04 2010 +0100
  29259. @@ -624,6 +624,9 @@
  29260. void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
  29261. Thread::oops_do(f, cf);
  29262. _vm_queue->oops_do(f);
  29263. + if (_cur_vm_operation != NULL) {
  29264. + _cur_vm_operation->oops_do(f);
  29265. + }
  29266. }
  29267. //------------------------------------------------------------------------------------------------------------------
  29268. diff -r f5603a6e5042 src/share/vm/runtime/vm_version.cpp
  29269. --- a/src/share/vm/runtime/vm_version.cpp Wed Nov 17 22:42:08 2010 -0800
  29270. +++ b/src/share/vm/runtime/vm_version.cpp Fri Dec 17 13:23:04 2010 +0100
  29271. @@ -40,10 +40,11 @@
  29272. #error HOTSPOT_BUILD_TARGET must be defined
  29273. #endif
  29274. +// (tw) added DCE VM build number
  29275. #ifdef PRODUCT
  29276. - #define VM_RELEASE HOTSPOT_RELEASE_VERSION
  29277. + #define VM_RELEASE "0.2-b02-internal, " HOTSPOT_RELEASE_VERSION
  29278. #else
  29279. - #define VM_RELEASE HOTSPOT_RELEASE_VERSION "-" HOTSPOT_BUILD_TARGET
  29280. + #define VM_RELEASE "0.2-b02-internal-debug, " HOTSPOT_RELEASE_VERSION "-" HOTSPOT_BUILD_TARGET
  29281. #endif
  29282. // HOTSPOT_RELEASE_VERSION must follow the release version naming convention
  29283. @@ -110,6 +111,12 @@
  29284. #ifndef HOTSPOT_VM_DISTRO
  29285. #error HOTSPOT_VM_DISTRO must be defined
  29286. #endif
  29287. +
  29288. +// (tw) Set VM name to DCE
  29289. +#undef HOTSPOT_VM_DISTRO
  29290. +#define HOTSPOT_VM_DISTRO "Dynamic Code Evolution"
  29291. +#define VM_RELEASE_HOTSP
  29292. +
  29293. #define VMNAME HOTSPOT_VM_DISTRO " " VMLP VMTYPE " VM"
  29294. const char* Abstract_VM_Version::vm_name() {
  29295. diff -r f5603a6e5042 src/share/vm/utilities/exceptions.cpp
  29296. --- a/src/share/vm/utilities/exceptions.cpp Wed Nov 17 22:42:08 2010 -0800
  29297. +++ b/src/share/vm/utilities/exceptions.cpp Fri Dec 17 13:23:04 2010 +0100
  29298. @@ -239,6 +239,8 @@
  29299. assert(thread->is_Java_thread(), "can only be called by a Java thread");
  29300. assert(!thread->has_pending_exception(), "already has exception");
  29301. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  29302. + Thread::current()->set_pretend_new_universe(false);
  29303. Handle h_exception;
  29304. // Resolve exception klass
  29305. @@ -286,6 +288,8 @@
  29306. h_exception = Handle(thread, thread->pending_exception());
  29307. thread->clear_pending_exception();
  29308. }
  29309. +
  29310. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  29311. return h_exception;
  29312. }
  29313. diff -r f5603a6e5042 src/share/vm/utilities/growableArray.hpp
  29314. --- a/src/share/vm/utilities/growableArray.hpp Wed Nov 17 22:42:08 2010 -0800
  29315. +++ b/src/share/vm/utilities/growableArray.hpp Fri Dec 17 13:23:04 2010 +0100
  29316. @@ -124,6 +124,33 @@
  29317. assert(on_stack(), "fast ResourceObj path only");
  29318. return (void*)resource_allocate_bytes(thread, elementSize * _max);
  29319. }
  29320. +
  29321. +};
  29322. +
  29323. +template<class E, class F> class Pair : public StackObj
  29324. +{
  29325. +private:
  29326. + E _left;
  29327. + F _right;
  29328. +
  29329. +public:
  29330. +
  29331. + Pair() {
  29332. +
  29333. + }
  29334. +
  29335. + Pair(E left, F right) {
  29336. + this->_left = left;
  29337. + this->_right = right;
  29338. + }
  29339. +
  29340. + E left() {
  29341. + return _left;
  29342. + }
  29343. +
  29344. + F right() {
  29345. + return _right;
  29346. + }
  29347. };
  29348. template<class E> class GrowableArray : public GenericGrowableArray {