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.

hotswaplight.patch 468KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364
  1. diff -r f5603a6e5042 .hgignore
  2. --- a/.hgignore Wed Nov 17 22:42:08 2010 -0800
  3. +++ b/.hgignore Fri Dec 17 13:24:08 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:24:08 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:24:08 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:24:08 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:24:08 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:24:08 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:24:08 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 hotswapbinaries/README
  132. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  133. +++ b/hotswapbinaries/README Fri Dec 17 13:24:08 2010 +0100
  134. @@ -0,0 +1,18 @@
  135. +The binary files are not stored in the mercurial repository, because they would bloat the repository size. The expected files in this subdirectory are:
  136. +
  137. +==========================================
  138. +Windows
  139. +win/data/64/bin/server/jvm.dll
  140. +win/data/bin/client/jvm.dll
  141. +win/data/bin/server/jvm.dll
  142. +
  143. +==========================================
  144. +Mac
  145. +mac/data/lib/i386/client/libjvm.dylib
  146. +mac/data/lib/i386/server/libjvm.dylib
  147. +
  148. +==========================================
  149. +Linux
  150. +linux/data/64/lib/amd64/server/libjvm.so
  151. +linux/data/lib/i386/client/libjvm.so
  152. +linux/data/lib/i386/server/libjvm.so
  153. diff -r f5603a6e5042 make/windows/build_vm_def.sh
  154. --- a/make/windows/build_vm_def.sh Wed Nov 17 22:42:08 2010 -0800
  155. +++ b/make/windows/build_vm_def.sh Fri Dec 17 13:24:08 2010 +0100
  156. @@ -51,6 +51,7 @@
  157. CAT="$MKS_HOME/cat.exe"
  158. RM="$MKS_HOME/rm.exe"
  159. DUMPBIN="link.exe /dump"
  160. +export VS_UNICODE_OUTPUT=
  161. # When called from IDE the first param should contain the link version, otherwise may be nill
  162. if [ "x$1" != "x" ]; then
  163. diff -r f5603a6e5042 make/windows/create.bat
  164. --- a/make/windows/create.bat Wed Nov 17 22:42:08 2010 -0800
  165. +++ b/make/windows/create.bat Fri Dec 17 13:24:08 2010 +0100
  166. @@ -39,6 +39,8 @@
  167. REM Note: Running this batch file from the Windows command shell requires
  168. REM that "grep" be accessible on the PATH. An MKS install does this.
  169. REM
  170. +cl 2>&1 | grep "x64" >NUL
  171. +if %errorlevel% == 0 goto amd64
  172. cl 2>&1 | grep "IA-64" >NUL
  173. if %errorlevel% == 0 goto isia64
  174. cl 2>&1 | grep "AMD64" >NUL
  175. diff -r f5603a6e5042 src/cpu/x86/vm/interp_masm_x86_32.cpp
  176. --- a/src/cpu/x86/vm/interp_masm_x86_32.cpp Wed Nov 17 22:42:08 2010 -0800
  177. +++ b/src/cpu/x86/vm/interp_masm_x86_32.cpp Fri Dec 17 13:24:08 2010 +0100
  178. @@ -1352,7 +1352,7 @@
  179. }
  180. // RedefineClasses() tracing support for obsolete method entry
  181. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  182. + IF_TRACE_RC4 {
  183. get_thread(rcx);
  184. get_method(rbx);
  185. call_VM_leaf(
  186. diff -r f5603a6e5042 src/cpu/x86/vm/interp_masm_x86_64.cpp
  187. --- a/src/cpu/x86/vm/interp_masm_x86_64.cpp Wed Nov 17 22:42:08 2010 -0800
  188. +++ b/src/cpu/x86/vm/interp_masm_x86_64.cpp Fri Dec 17 13:24:08 2010 +0100
  189. @@ -1438,7 +1438,7 @@
  190. }
  191. // RedefineClasses() tracing support for obsolete method entry
  192. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  193. + IF_TRACE_RC4 {
  194. get_method(c_rarg1);
  195. call_VM_leaf(
  196. CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
  197. diff -r f5603a6e5042 src/cpu/x86/vm/sharedRuntime_x86_32.cpp
  198. --- a/src/cpu/x86/vm/sharedRuntime_x86_32.cpp Wed Nov 17 22:42:08 2010 -0800
  199. +++ b/src/cpu/x86/vm/sharedRuntime_x86_32.cpp Fri Dec 17 13:24:08 2010 +0100
  200. @@ -1494,7 +1494,7 @@
  201. }
  202. // RedefineClasses() tracing support for obsolete method entry
  203. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  204. + IF_TRACE_RC4 {
  205. __ movoop(rax, JNIHandles::make_local(method()));
  206. __ call_VM_leaf(
  207. CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
  208. diff -r f5603a6e5042 src/cpu/x86/vm/sharedRuntime_x86_64.cpp
  209. --- a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp Wed Nov 17 22:42:08 2010 -0800
  210. +++ b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp Fri Dec 17 13:24:08 2010 +0100
  211. @@ -1490,7 +1490,7 @@
  212. }
  213. // RedefineClasses() tracing support for obsolete method entry
  214. - if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
  215. + IF_TRACE_RC4 {
  216. // protect the args we've loaded
  217. save_args(masm, total_c_args, c_arg, out_regs);
  218. __ movoop(c_rarg1, JNIHandles::make_local(method()));
  219. diff -r f5603a6e5042 src/cpu/x86/vm/templateTable_x86_32.cpp
  220. --- a/src/cpu/x86/vm/templateTable_x86_32.cpp Wed Nov 17 22:42:08 2010 -0800
  221. +++ b/src/cpu/x86/vm/templateTable_x86_32.cpp Fri Dec 17 13:24:08 2010 +0100
  222. @@ -2110,6 +2110,22 @@
  223. // resolve first time through
  224. address entry;
  225. switch (bytecode()) {
  226. + case Bytecodes::_fast_agetfield : // fall through
  227. + case Bytecodes::_fast_bgetfield : // fall through
  228. + case Bytecodes::_fast_cgetfield : // fall through
  229. + case Bytecodes::_fast_dgetfield : // fall through
  230. + case Bytecodes::_fast_fgetfield : // fall through
  231. + case Bytecodes::_fast_igetfield : // fall through
  232. + case Bytecodes::_fast_lgetfield : // fall through
  233. + case Bytecodes::_fast_sgetfield : // fall through
  234. + case Bytecodes::_fast_aputfield : // fall through
  235. + case Bytecodes::_fast_bputfield : // fall through
  236. + case Bytecodes::_fast_cputfield : // fall through
  237. + case Bytecodes::_fast_dputfield : // fall through
  238. + case Bytecodes::_fast_fputfield : // fall through
  239. + case Bytecodes::_fast_iputfield : // fall through
  240. + case Bytecodes::_fast_lputfield : // fall through
  241. + case Bytecodes::_fast_sputfield : // fall through
  242. case Bytecodes::_getstatic : // fall through
  243. case Bytecodes::_putstatic : // fall through
  244. case Bytecodes::_getfield : // fall through
  245. @@ -2204,6 +2220,7 @@
  246. // Correct values of the cache and index registers are preserved.
  247. void TemplateTable::jvmti_post_field_access(Register cache,
  248. Register index,
  249. + int byte_no,
  250. bool is_static,
  251. bool has_tos) {
  252. if (JvmtiExport::can_post_field_access()) {
  253. @@ -2230,7 +2247,11 @@
  254. // cache: cache entry pointer
  255. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
  256. rax, cache);
  257. - __ get_cache_and_index_at_bcp(cache, index, 1);
  258. +
  259. + // (tw) Redefinition might have occured => reresolve the cp entry.
  260. + __ restore_bcp();
  261. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  262. +
  263. __ bind(L1);
  264. }
  265. }
  266. @@ -2251,7 +2272,7 @@
  267. const Register flags = rax;
  268. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  269. - jvmti_post_field_access(cache, index, is_static, false);
  270. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  271. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  272. if (!is_static) pop_and_check_object(obj);
  273. @@ -2386,7 +2407,7 @@
  274. // The registers cache and index expected to be set before call.
  275. // The function may destroy various registers, just not the cache and index registers.
  276. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  277. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  278. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  279. @@ -2444,7 +2465,11 @@
  280. // rcx: jvalue object on the stack
  281. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
  282. rbx, rax, rcx);
  283. - __ get_cache_and_index_at_bcp(cache, index, 1);
  284. +
  285. + // (tw) Redefinition might have occured => reresolve the cp entry.
  286. + __ restore_bcp();
  287. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  288. +
  289. __ bind(L1);
  290. }
  291. }
  292. @@ -2460,7 +2485,7 @@
  293. const Register flags = rax;
  294. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  295. - jvmti_post_field_mod(cache, index, is_static);
  296. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  297. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  298. // Doug Lea believes this is not needed with current Sparcs (TSO) and Intel (PSO).
  299. @@ -2683,6 +2708,11 @@
  300. // rax,: cache entry pointer
  301. // rcx: jvalue object on the stack
  302. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), rbx, rax, rcx);
  303. +
  304. + // (tw) Redefinition might have occured => reresolve the cp entry.
  305. + __ restore_bcp();
  306. + resolve_cache_and_index(2, noreg, rax, rcx, sizeof(u2));
  307. +
  308. if (bytecode() == Bytecodes::_fast_lputfield) __ pop(rdx); // restore high value
  309. __ pop(rax); // restore lower value
  310. __ addptr(rsp, sizeof(jvalue)); // release jvalue object space
  311. @@ -2803,6 +2833,11 @@
  312. // rcx: cache entry pointer
  313. __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access), rax, rcx);
  314. __ pop_ptr(rax); // restore object pointer
  315. +
  316. + // (tw) Redefinition might have occured => reresolve the cp entry.
  317. + __ restore_bcp();
  318. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  319. +
  320. __ bind(L1);
  321. }
  322. diff -r f5603a6e5042 src/cpu/x86/vm/templateTable_x86_64.cpp
  323. --- a/src/cpu/x86/vm/templateTable_x86_64.cpp Wed Nov 17 22:42:08 2010 -0800
  324. +++ b/src/cpu/x86/vm/templateTable_x86_64.cpp Fri Dec 17 13:24:08 2010 +0100
  325. @@ -2113,6 +2113,22 @@
  326. // resolve first time through
  327. address entry;
  328. switch (bytecode()) {
  329. + case Bytecodes::_fast_agetfield : // fall through
  330. + case Bytecodes::_fast_bgetfield : // fall through
  331. + case Bytecodes::_fast_cgetfield : // fall through
  332. + case Bytecodes::_fast_dgetfield : // fall through
  333. + case Bytecodes::_fast_fgetfield : // fall through
  334. + case Bytecodes::_fast_igetfield : // fall through
  335. + case Bytecodes::_fast_lgetfield : // fall through
  336. + case Bytecodes::_fast_sgetfield : // fall through
  337. + case Bytecodes::_fast_aputfield : // fall through
  338. + case Bytecodes::_fast_bputfield : // fall through
  339. + case Bytecodes::_fast_cputfield : // fall through
  340. + case Bytecodes::_fast_dputfield : // fall through
  341. + case Bytecodes::_fast_fputfield : // fall through
  342. + case Bytecodes::_fast_iputfield : // fall through
  343. + case Bytecodes::_fast_lputfield : // fall through
  344. + case Bytecodes::_fast_sputfield : // fall through
  345. case Bytecodes::_getstatic:
  346. case Bytecodes::_putstatic:
  347. case Bytecodes::_getfield:
  348. @@ -2219,7 +2235,7 @@
  349. // The registers cache and index expected to be set before call.
  350. // Correct values of the cache and index registers are preserved.
  351. void TemplateTable::jvmti_post_field_access(Register cache, Register index,
  352. - bool is_static, bool has_tos) {
  353. + int byte_no, bool is_static, bool has_tos) {
  354. // do the JVMTI work here to avoid disturbing the register state below
  355. // We use c_rarg registers here because we want to use the register used in
  356. // the call to the VM
  357. @@ -2250,7 +2266,11 @@
  358. __ call_VM(noreg, CAST_FROM_FN_PTR(address,
  359. InterpreterRuntime::post_field_access),
  360. c_rarg1, c_rarg2, c_rarg3);
  361. - __ get_cache_and_index_at_bcp(cache, index, 1);
  362. +
  363. + // (tw) Redefinition might have occured => reresolve the cp entry.
  364. + __ restore_bcp();
  365. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  366. +
  367. __ bind(L1);
  368. }
  369. }
  370. @@ -2272,7 +2292,7 @@
  371. const Register bc = c_rarg3; // uses same reg as obj, so don't mix them
  372. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  373. - jvmti_post_field_access(cache, index, is_static, false);
  374. + jvmti_post_field_access(cache, index, byte_no, is_static, false);
  375. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  376. if (!is_static) {
  377. @@ -2406,7 +2426,7 @@
  378. // The registers cache and index expected to be set before call.
  379. // The function may destroy various registers, just not the cache and index registers.
  380. -void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
  381. +void TemplateTable::jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static) {
  382. transition(vtos, vtos);
  383. ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
  384. @@ -2459,7 +2479,11 @@
  385. CAST_FROM_FN_PTR(address,
  386. InterpreterRuntime::post_field_modification),
  387. c_rarg1, c_rarg2, c_rarg3);
  388. - __ get_cache_and_index_at_bcp(cache, index, 1);
  389. +
  390. + // (tw) Redefinition might have occured => reresolve the cp entry.
  391. + __ restore_bcp();
  392. + resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  393. +
  394. __ bind(L1);
  395. }
  396. }
  397. @@ -2475,7 +2499,7 @@
  398. const Register bc = c_rarg3;
  399. resolve_cache_and_index(byte_no, noreg, cache, index, sizeof(u2));
  400. - jvmti_post_field_mod(cache, index, is_static);
  401. + jvmti_post_field_mod(cache, index, byte_no, is_static);
  402. load_field_cp_cache_entry(obj, cache, index, off, flags, is_static);
  403. // [jk] not needed currently
  404. @@ -2661,6 +2685,11 @@
  405. CAST_FROM_FN_PTR(address,
  406. InterpreterRuntime::post_field_modification),
  407. rbx, c_rarg2, c_rarg3);
  408. +
  409. + // (tw) Redefinition might have occured => reresolve the cp entry.
  410. + __ restore_bcp();
  411. + resolve_cache_and_index(2, noreg, rax, rcx, sizeof(u2));
  412. +
  413. __ pop(rax); // restore lower value
  414. __ addptr(rsp, sizeof(jvalue)); // release jvalue object space
  415. __ bind(L2);
  416. @@ -2762,6 +2791,11 @@
  417. c_rarg1, c_rarg2);
  418. __ mov(rax, r12); // restore object pointer
  419. __ reinit_heapbase();
  420. +
  421. + // (tw) Redefinition might have occured => reresolve the cp entry.
  422. + __ restore_bcp();
  423. + resolve_cache_and_index(1, noreg, rax, rcx, sizeof(u2));
  424. +
  425. __ bind(L1);
  426. }
  427. diff -r f5603a6e5042 src/share/tools/MakeDeps/BuildConfig.java
  428. --- a/src/share/tools/MakeDeps/BuildConfig.java Wed Nov 17 22:42:08 2010 -0800
  429. +++ b/src/share/tools/MakeDeps/BuildConfig.java Fri Dec 17 13:24:08 2010 +0100
  430. @@ -242,7 +242,20 @@
  431. void initDefaultDefines(Vector defines) {
  432. Vector sysDefines = new Vector();
  433. - sysDefines.add("WIN32");
  434. +
  435. + if( Util.os().equals("Win32")) {
  436. + sysDefines.add("WIN32");
  437. + sysDefines.add("HOTSPOT_LIB_ARCH=\\\"i386\\\"");
  438. + } else {
  439. + sysDefines.add("_AMD64_");
  440. + sysDefines.add("AMD64");
  441. + sysDefines.add("_WIN64");
  442. + sysDefines.add("_LP64");
  443. + if (System.getenv("MSC_VER") != null)
  444. + sysDefines.add("MSC_VER=" + System.getenv("MSC_VER"));
  445. + sysDefines.add("HOTSPOT_LIB_ARCH=\\\"amd64\\\"");
  446. + }
  447. +
  448. sysDefines.add("_WINDOWS");
  449. sysDefines.add("HOTSPOT_BUILD_USER="+System.getProperty("user.name"));
  450. sysDefines.add("HOTSPOT_BUILD_TARGET=\\\""+get("Build")+"\\\"");
  451. diff -r f5603a6e5042 src/share/tools/MakeDeps/Util.java
  452. --- a/src/share/tools/MakeDeps/Util.java Wed Nov 17 22:42:08 2010 -0800
  453. +++ b/src/share/tools/MakeDeps/Util.java Fri Dec 17 13:24:08 2010 +0100
  454. @@ -84,5 +84,26 @@
  455. }
  456. static String sep = File.separator;
  457. - static String os = "Win32"; //System.getProperty("os.name");
  458. +
  459. + private static String _os;
  460. +
  461. + static String os() {
  462. + if( _os==null) {
  463. +
  464. + for(Map.Entry<String, String> entry: System.getenv().entrySet())
  465. + if("PLATFORM_ARCH_MODEL".equals(entry.getKey().toUpperCase())) {
  466. + String archModel = entry.getValue();
  467. + if("x86_32".equals(archModel))
  468. + _os = "Win32";
  469. + else if("x86_64".equals(archModel))
  470. + _os = "x64";
  471. + else
  472. + throw new RuntimeException("Unsupported PLATFORM_ARCH_MODEL " + archModel);
  473. + return _os;
  474. + }
  475. + throw new RuntimeException("PLATFORM_ARCH_MODEL not specified");
  476. + }
  477. + return _os;
  478. + }
  479. +
  480. }
  481. diff -r f5603a6e5042 src/share/tools/MakeDeps/WinGammaPlatformVC6.java
  482. --- a/src/share/tools/MakeDeps/WinGammaPlatformVC6.java Wed Nov 17 22:42:08 2010 -0800
  483. +++ b/src/share/tools/MakeDeps/WinGammaPlatformVC6.java Fri Dec 17 13:24:08 2010 +0100
  484. @@ -236,7 +236,7 @@
  485. " /nologo /base:\"0x8000000\" /subsystem:windows /dll" +
  486. " /export:JNI_GetDefaultJavaVMInitArgs /export:JNI_CreateJavaVM /export:JNI_GetCreatedJavaVMs "+
  487. " /export:jio_snprintf /export:jio_printf /export:jio_fprintf /export:jio_vfprintf "+
  488. - " /export:jio_vsnprintf ");
  489. + " /export:jio_vsnprintf /export:JVM_GetVersionInfo /export:JVM_GetThreadStateNames /export:JVM_GetThreadStateValues /export:JVM_InitAgentProperties /export:JVM_FindClassFromBootLoader");
  490. rv.add("SUBTRACT LINK32 /pdb:none /map");
  491. return rv;
  492. @@ -286,6 +286,6 @@
  493. }
  494. String makeCfgName(String flavourBuild) {
  495. - return "vm - "+ Util.os + " " + flavourBuild;
  496. + return "vm - "+ "Win32" + " " + flavourBuild;
  497. }
  498. }
  499. diff -r f5603a6e5042 src/share/tools/MakeDeps/WinGammaPlatformVC7.java
  500. --- a/src/share/tools/MakeDeps/WinGammaPlatformVC7.java Wed Nov 17 22:42:08 2010 -0800
  501. +++ b/src/share/tools/MakeDeps/WinGammaPlatformVC7.java Fri Dec 17 13:24:08 2010 +0100
  502. @@ -51,7 +51,7 @@
  503. );
  504. startTag("Platforms", null);
  505. - tag("Platform", new String[] {"Name", Util.os});
  506. + tag("Platform", new String[] {"Name", Util.os()});
  507. endTag("Platforms");
  508. startTag("Configurations", null);
  509. @@ -467,7 +467,7 @@
  510. "PreprocessorDefinitions", "NDEBUG",
  511. "MkTypLibCompatible", "TRUE",
  512. "SuppressStartupBanner", "TRUE",
  513. - "TargetEnvironment", "1",
  514. + "TargetEnvironment", Util.os().equals("Win32") ? "1" : "3",
  515. "TypeLibraryName", cfg.get("OutputDir") + Util.sep + "vm.tlb",
  516. "HeaderFileName", ""
  517. }
  518. @@ -596,7 +596,7 @@
  519. "/export:JNI_GetCreatedJavaVMs "+
  520. "/export:jio_snprintf /export:jio_printf "+
  521. "/export:jio_fprintf /export:jio_vfprintf "+
  522. - "/export:jio_vsnprintf ");
  523. + "/export:jio_vsnprintf /export:JVM_GetVersionInfo /export:JVM_GetThreadStateNames /export:JVM_GetThreadStateValues /export:JVM_InitAgentProperties /export:JVM_FindClassFromBootLoader");
  524. addAttr(rv, "AdditionalDependencies", "Wsock32.lib winmm.lib");
  525. addAttr(rv, "OutputFile", outDll);
  526. // Set /INCREMENTAL option. 1 is linkIncrementalNo
  527. @@ -609,7 +609,7 @@
  528. addAttr(rv, "BaseAddress", "0x8000000");
  529. addAttr(rv, "ImportLibrary", outDir+Util.sep+"jvm.lib");
  530. // Set /MACHINE option. 1 is machineX86
  531. - addAttr(rv, "TargetMachine", "1");
  532. + addAttr(rv, "TargetMachine", Util.os().equals("Win32") ? "1" : "17");
  533. return rv;
  534. }
  535. @@ -687,6 +687,6 @@
  536. }
  537. String makeCfgName(String flavourBuild) {
  538. - return flavourBuild + "|" + Util.os;
  539. + return flavourBuild + "|" + Util.os();
  540. }
  541. }
  542. diff -r f5603a6e5042 src/share/tools/MakeDeps/WinGammaPlatformVC8.java
  543. --- a/src/share/tools/MakeDeps/WinGammaPlatformVC8.java Wed Nov 17 22:42:08 2010 -0800
  544. +++ b/src/share/tools/MakeDeps/WinGammaPlatformVC8.java Fri Dec 17 13:24:08 2010 +0100
  545. @@ -41,6 +41,9 @@
  546. addAttr(rv, "UsePrecompiledHeader", "2");
  547. // Set /EHsc- option. 0 is cppExceptionHandlingNo
  548. addAttr(rv, "ExceptionHandling", "0");
  549. + // Parallel compilation
  550. + addAttr(rv, "AdditionalOptions", "/MP");
  551. +
  552. return rv;
  553. }
  554. diff -r f5603a6e5042 src/share/vm/c1/c1_Compilation.hpp
  555. --- a/src/share/vm/c1/c1_Compilation.hpp Wed Nov 17 22:42:08 2010 -0800
  556. +++ b/src/share/vm/c1/c1_Compilation.hpp Fri Dec 17 13:24:08 2010 +0100
  557. @@ -232,8 +232,8 @@
  558. #define BAILOUT(msg) { bailout(msg); return; }
  559. #define BAILOUT_(msg, res) { bailout(msg); return res; }
  560. -#define CHECK_BAILOUT() { if (bailed_out()) return; }
  561. -#define CHECK_BAILOUT_(res) { if (bailed_out()) return res; }
  562. +#define CHECK_BAILOUT() { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return; }
  563. +#define CHECK_BAILOUT_(res) { if (((CompilerThread *)Thread::current())->should_bailout()) bailout("Aborted externally"); if (bailed_out()) return res; }
  564. class InstructionMark: public StackObj {
  565. diff -r f5603a6e5042 src/share/vm/c1/c1_LIRGenerator.cpp
  566. --- a/src/share/vm/c1/c1_LIRGenerator.cpp Wed Nov 17 22:42:08 2010 -0800
  567. +++ b/src/share/vm/c1/c1_LIRGenerator.cpp Fri Dec 17 13:24:08 2010 +0100
  568. @@ -2498,7 +2498,7 @@
  569. // Load CallSite object from constant pool cache.
  570. __ oop2reg(cpcache->constant_encoding(), tmp);
  571. - __ load(new LIR_Address(tmp, call_site_offset, T_OBJECT), tmp);
  572. + __ load(new LIR_Address(tmp, (int)call_site_offset, T_OBJECT), tmp);
  573. // Load target MethodHandle from CallSite object.
  574. __ load(new LIR_Address(tmp, java_dyn_CallSite::target_offset_in_bytes(), T_OBJECT), receiver);
  575. diff -r f5603a6e5042 src/share/vm/ci/ciEnv.cpp
  576. --- a/src/share/vm/ci/ciEnv.cpp Wed Nov 17 22:42:08 2010 -0800
  577. +++ b/src/share/vm/ci/ciEnv.cpp Fri Dec 17 13:24:08 2010 +0100
  578. @@ -1075,3 +1075,11 @@
  579. // If memory is low, we stop compiling methods.
  580. record_method_not_compilable("out of memory");
  581. }
  582. +
  583. +// (tw) Called after class redefinition to clean up possibly invalidated state.
  584. +void ciEnv::cleanup_after_redefinition() {
  585. +
  586. + if (_factory != NULL) {
  587. + _factory->cleanup_after_redefinition();
  588. + }
  589. +}
  590. \ No newline at end of file
  591. diff -r f5603a6e5042 src/share/vm/ci/ciEnv.hpp
  592. --- a/src/share/vm/ci/ciEnv.hpp Wed Nov 17 22:42:08 2010 -0800
  593. +++ b/src/share/vm/ci/ciEnv.hpp Fri Dec 17 13:24:08 2010 +0100
  594. @@ -383,4 +383,6 @@
  595. void record_failure(const char* reason);
  596. void record_method_not_compilable(const char* reason, bool all_tiers = true);
  597. void record_out_of_memory_failure();
  598. +
  599. + void cleanup_after_redefinition();
  600. };
  601. diff -r f5603a6e5042 src/share/vm/ci/ciObjectFactory.cpp
  602. --- a/src/share/vm/ci/ciObjectFactory.cpp Wed Nov 17 22:42:08 2010 -0800
  603. +++ b/src/share/vm/ci/ciObjectFactory.cpp Fri Dec 17 13:24:08 2010 +0100
  604. @@ -255,6 +255,11 @@
  605. // into the table. We need to recompute our index.
  606. index = find(keyHandle(), _ci_objects);
  607. }
  608. +
  609. + if (is_found_at(index, keyHandle(), _ci_objects)) {
  610. + // (tw) Check if this is an error? Can occur when redefining classes.
  611. + return _ci_objects->at(index);
  612. + }
  613. assert(!is_found_at(index, keyHandle(), _ci_objects), "no double insert");
  614. insert(index, new_object, _ci_objects);
  615. return new_object;
  616. @@ -711,3 +716,50 @@
  617. _unloaded_instances->length(),
  618. _unloaded_klasses->length());
  619. }
  620. +
  621. +// (tw) Resoring the ciObject arrays after class redefinition
  622. +void ciObjectFactory::sort_ci_objects(GrowableArray<ciObject*>* objects) {
  623. +
  624. + // Resort the _ci_objects array. The order of two class pointers can be changed during class redefinition.
  625. + oop last = NULL;
  626. + for (int j = 0; j< objects->length(); j++) {
  627. + oop o = objects->at(j)->get_oop();
  628. + if (last >= o) {
  629. + int cur_last_index = j - 1;
  630. + oop cur_last = last;
  631. + while (cur_last >= o) {
  632. +
  633. + // Swap the two objects to guarantee ordering
  634. + ciObject *tmp = objects->at(cur_last_index);
  635. + objects->at_put(cur_last_index, objects->at(cur_last_index + 1));
  636. + objects->at_put(cur_last_index + 1, tmp);
  637. +
  638. + // Decrement index to move one step to the left
  639. + cur_last_index--;
  640. + if (cur_last_index < 0) {
  641. + break;
  642. + }
  643. + cur_last =objects->at(cur_last_index)->get_oop();
  644. + }
  645. + } else {
  646. + assert(last < o, "out of order");
  647. + last = o;
  648. + }
  649. + }
  650. +
  651. +#ifdef ASSERT
  652. + if (CIObjectFactoryVerify) {
  653. + oop last = NULL;
  654. + for (int j = 0; j< objects->length(); j++) {
  655. + oop o = objects->at(j)->get_oop();
  656. + assert(last < o, "out of order");
  657. + last = o;
  658. + }
  659. + }
  660. +#endif // ASSERT
  661. +}
  662. +
  663. +// (tw) Called after class redefinition to clean up possibly invalidated state.
  664. +void ciObjectFactory::cleanup_after_redefinition() {
  665. + sort_ci_objects(_ci_objects);
  666. +}
  667. \ No newline at end of file
  668. diff -r f5603a6e5042 src/share/vm/ci/ciObjectFactory.hpp
  669. --- a/src/share/vm/ci/ciObjectFactory.hpp Wed Nov 17 22:42:08 2010 -0800
  670. +++ b/src/share/vm/ci/ciObjectFactory.hpp Fri Dec 17 13:24:08 2010 +0100
  671. @@ -29,6 +29,10 @@
  672. // which ensures that for each oop, at most one ciObject is created.
  673. // This invariant allows efficient implementation of ciObject.
  674. class ciObjectFactory : public ResourceObj {
  675. +
  676. + friend class ciEnv;
  677. + friend class CompileBroker;
  678. +
  679. private:
  680. static volatile bool _initialized;
  681. static GrowableArray<ciObject*>* _shared_ci_objects;
  682. @@ -122,4 +126,9 @@
  683. void print_contents();
  684. void print();
  685. +
  686. +private:
  687. +
  688. + static void sort_ci_objects(GrowableArray<ciObject*>* objects);
  689. + void cleanup_after_redefinition();
  690. };
  691. diff -r f5603a6e5042 src/share/vm/classfile/classFileParser.cpp
  692. --- a/src/share/vm/classfile/classFileParser.cpp Wed Nov 17 22:42:08 2010 -0800
  693. +++ b/src/share/vm/classfile/classFileParser.cpp Fri Dec 17 13:24:08 2010 +0100
  694. @@ -833,6 +833,7 @@
  695. Handle class_loader,
  696. Handle protection_domain,
  697. symbolHandle class_name,
  698. + KlassHandle old_klass,
  699. TRAPS) {
  700. ClassFileStream* cfs = stream();
  701. assert(length > 0, "only called for length>0");
  702. @@ -851,6 +852,9 @@
  703. interface_index, CHECK_(nullHandle));
  704. if (cp->tag_at(interface_index).is_klass()) {
  705. interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
  706. + if (!old_klass.is_null() && !interf->is_newest_version()) {
  707. + interf = KlassHandle(THREAD, interf->newest_version());
  708. + }
  709. } else {
  710. symbolHandle unresolved_klass (THREAD, cp->klass_name_at(interface_index));
  711. @@ -863,6 +867,9 @@
  712. klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
  713. unresolved_klass, class_loader, protection_domain,
  714. false, CHECK_(nullHandle));
  715. + if (!old_klass.is_null()) {
  716. + k = k->klass_part()->newest_version();
  717. + }
  718. interf = KlassHandle(THREAD, k);
  719. if (LinkWellKnownClasses) // my super type is well known to me
  720. @@ -1805,7 +1812,6 @@
  721. // Parse and compress line number table
  722. parse_linenumber_table(code_attribute_length, code_length,
  723. &linenumber_table, CHECK_(nullHandle));
  724. -
  725. } else if (LoadLocalVariableTables &&
  726. cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_table()) {
  727. // Parse local variable table
  728. @@ -2549,7 +2555,7 @@
  729. }
  730. -static void initialize_static_field(fieldDescriptor* fd, TRAPS) {
  731. +void ClassFileParser::initialize_static_field(fieldDescriptor* fd, TRAPS) {
  732. KlassHandle h_k (THREAD, fd->field_holder());
  733. assert(h_k.not_null() && fd->is_static(), "just checking");
  734. if (fd->has_initial_value()) {
  735. @@ -2746,6 +2752,123 @@
  736. (*next_nonstatic_oop_offset_ptr) += (extra * heapOopSize);
  737. }
  738. +// (tw) Finds the super symbols by reading the bytes of the class and returns
  739. +// them in a growable array.
  740. +void ClassFileParser::findSuperSymbols(symbolHandle name,
  741. + Handle class_loader,
  742. + Handle protection_domain,
  743. + KlassHandle old_klass,
  744. + GrowableArray<symbolHandle> &handles,
  745. + TRAPS) {
  746. +
  747. + _cp_patches = NULL;
  748. + // So that JVMTI can cache class file in the state before retransformable agents
  749. + // have modified it
  750. + unsigned char *cached_class_file_bytes = NULL;
  751. +
  752. + ClassFileStream* cfs = stream();
  753. +
  754. + _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
  755. +
  756. + instanceKlassHandle nullHandle;
  757. +
  758. + // Save the class file name for easier error message printing.
  759. + _class_name = name.not_null()? name : vmSymbolHandles::unknown_class_name();
  760. +
  761. + cfs->guarantee_more(8, CHECK); // magic, major, minor
  762. + // Magic value
  763. + u4 magic = cfs->get_u4_fast();
  764. + if (magic != JAVA_CLASSFILE_MAGIC) {
  765. + // Invalid class file!
  766. + return;
  767. + }
  768. +
  769. + // Version numbers
  770. + u2 minor_version = cfs->get_u2_fast();
  771. + u2 major_version = cfs->get_u2_fast();
  772. +
  773. + // Check version numbers - we check this even with verifier off
  774. + if (!is_supported_version(major_version, minor_version)) {
  775. +
  776. + // Unsupported version!
  777. + return;
  778. + }
  779. +
  780. + _major_version = major_version;
  781. + _minor_version = minor_version;
  782. +
  783. +
  784. + // Check if verification needs to be relaxed for this class file
  785. + // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
  786. + _relax_verify = Verifier::relax_verify_for(class_loader());
  787. + _need_verify = false;
  788. +
  789. + // Constant pool
  790. + constantPoolHandle cp = parse_constant_pool(CHECK);
  791. + int cp_size = cp->length();
  792. +
  793. + cfs->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len
  794. +
  795. + // Access flags
  796. + AccessFlags access_flags;
  797. + jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
  798. +
  799. + if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
  800. + // Set abstract bit for old class files for backward compatibility
  801. + flags |= JVM_ACC_ABSTRACT;
  802. + }
  803. + access_flags.set_flags(flags);
  804. +
  805. + // This class and superclass
  806. + instanceKlassHandle super_klass;
  807. + u2 this_class_index = cfs->get_u2_fast();
  808. + check_property(
  809. + valid_cp_range(this_class_index, cp_size) &&
  810. + cp->tag_at(this_class_index).is_unresolved_klass(),
  811. + "Invalid this class index %u in constant pool in class file %s",
  812. + this_class_index, CHECK);
  813. +
  814. + symbolHandle class_name (THREAD, cp->unresolved_klass_at(this_class_index));
  815. + assert(class_name.not_null(), "class_name can't be null");
  816. +
  817. + // Update _class_name which could be null previously to be class_name
  818. + _class_name = class_name;
  819. +
  820. + // (tw) DO NOT release all handles when parsing is done
  821. + {// HandleMark hm(THREAD);
  822. +
  823. + // Checks if name in class file matches requested name
  824. + if (name.not_null() && class_name() != name()) {
  825. + return;
  826. + }
  827. +
  828. + u2 super_class_index = cfs->get_u2_fast();
  829. +
  830. + if (super_class_index != 0) {
  831. + symbolHandle super_class (THREAD, cp->klass_name_at(super_class_index));
  832. + handles.append(super_class);
  833. + } else {
  834. + // (tw) This redefinition must be for the Object class.
  835. + }
  836. +
  837. + // Interfaces
  838. + u2 itfs_len = cfs->get_u2_fast();
  839. + objArrayHandle local_interfaces;
  840. + if (itfs_len == 0) {
  841. + local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  842. + } else {
  843. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK);
  844. + }
  845. +
  846. + for (int i=0; i<local_interfaces->length(); i++) {
  847. + oop o = local_interfaces->obj_at(i);
  848. + symbolHandle interface_handle (THREAD, ((klassOop)o)->klass_part()->name());
  849. + handles.append(interface_handle);
  850. + }
  851. + }
  852. +}
  853. +
  854. +
  855. // Force MethodHandle.vmentry to be an unmanaged pointer.
  856. // There is no way for a classfile to express this, so we must help it.
  857. @@ -2819,6 +2942,7 @@
  858. instanceKlassHandle ClassFileParser::parseClassFile(symbolHandle name,
  859. Handle class_loader,
  860. Handle protection_domain,
  861. + KlassHandle old_klass,
  862. KlassHandle host_klass,
  863. GrowableArray<Handle>* cp_patches,
  864. symbolHandle& parsed_name,
  865. @@ -2847,10 +2971,13 @@
  866. unsigned char* ptr = cfs->buffer();
  867. unsigned char* end_ptr = cfs->buffer() + cfs->length();
  868. + bool pretend_new_universe = Thread::current()->pretend_new_universe();
  869. + Thread::current()->set_pretend_new_universe(false);
  870. JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
  871. &ptr, &end_ptr,
  872. &cached_class_file_bytes,
  873. &cached_class_file_length);
  874. + Thread::current()->set_pretend_new_universe(pretend_new_universe);
  875. if (ptr != cfs->buffer()) {
  876. // JVMTI agent has modified class file data.
  877. @@ -3001,7 +3128,11 @@
  878. // However, make sure it is not an array type.
  879. bool is_array = false;
  880. if (cp->tag_at(super_class_index).is_klass()) {
  881. - super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index));
  882. + klassOop resolved_klass = cp->resolved_klass_at(super_class_index);
  883. + if (!old_klass.is_null()) {
  884. + resolved_klass = resolved_klass->klass_part()->newest_version();
  885. + }
  886. + super_klass = instanceKlassHandle(THREAD, resolved_klass);
  887. if (_need_verify)
  888. is_array = super_klass->oop_is_array();
  889. } else if (_need_verify) {
  890. @@ -3019,7 +3150,7 @@
  891. if (itfs_len == 0) {
  892. local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
  893. } else {
  894. - local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, CHECK_(nullHandle));
  895. + local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, _class_name, old_klass, CHECK_(nullHandle));
  896. }
  897. // Fields (offsets are filled in later)
  898. @@ -3063,7 +3194,9 @@
  899. protection_domain,
  900. true,
  901. CHECK_(nullHandle));
  902. -
  903. + if (!old_klass.is_null()) {
  904. + k = k->klass_part()->newest_version();
  905. + }
  906. KlassHandle kh (THREAD, k);
  907. super_klass = instanceKlassHandle(THREAD, kh());
  908. if (LinkWellKnownClasses) // my super class is well known to me
  909. @@ -3490,6 +3623,19 @@
  910. rt = REF_NONE;
  911. } else {
  912. rt = super_klass->reference_type();
  913. +
  914. + // (tw) With class redefinition, it can also happen that special classes are loaded.
  915. + if (name() == vmSymbols::java_lang_ref_Reference()) {
  916. + rt = REF_OTHER;
  917. + } else if (name() == vmSymbols::java_lang_ref_SoftReference()) {
  918. + rt = REF_SOFT;
  919. + } else if (name() == vmSymbols::java_lang_ref_WeakReference()) {
  920. + rt = REF_WEAK;
  921. + } else if (name() == vmSymbols::java_lang_ref_FinalReference()) {
  922. + rt = REF_FINAL;
  923. + } else if (name() == vmSymbols::java_lang_ref_PhantomReference()) {
  924. + rt = REF_PHANTOM;
  925. + }
  926. }
  927. // We can now create the basic klassOop for this klass
  928. @@ -3591,7 +3737,7 @@
  929. // Do final class setup
  930. fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts);
  931. - set_precomputed_flags(this_klass);
  932. + set_precomputed_flags(this_klass, old_klass);
  933. // reinitialize modifiers, using the InnerClasses attribute
  934. int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
  935. @@ -3611,6 +3757,10 @@
  936. check_illegal_static_method(this_klass, CHECK_(nullHandle));
  937. }
  938. + if (rt == REF_OTHER) {
  939. + instanceRefKlass::update_nonstatic_oop_maps(ik);
  940. + }
  941. +
  942. ClassLoadingService::notify_class_loaded(instanceKlass::cast(this_klass()),
  943. false /* not shared class */);
  944. @@ -3753,7 +3903,7 @@
  945. }
  946. -void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) {
  947. +void ClassFileParser::set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass) {
  948. klassOop super = k->super();
  949. // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
  950. @@ -3761,7 +3911,9 @@
  951. if (!_has_empty_finalizer) {
  952. if (_has_finalizer ||
  953. (super != NULL && super->klass_part()->has_finalizer())) {
  954. - k->set_has_finalizer();
  955. + if (old_klass.is_null() || old_klass->has_finalizer()) {
  956. + k->set_has_finalizer();
  957. + }
  958. }
  959. }
  960. @@ -3777,7 +3929,7 @@
  961. // Check if this klass supports the java.lang.Cloneable interface
  962. if (SystemDictionary::Cloneable_klass_loaded()) {
  963. - if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) {
  964. + if (k->is_subtype_of(SystemDictionary::Cloneable_klass()) || k->is_subtype_of(SystemDictionary::Cloneable_klass()->klass_part()->newest_version())) {
  965. k->set_is_cloneable();
  966. }
  967. }
  968. diff -r f5603a6e5042 src/share/vm/classfile/classFileParser.hpp
  969. --- a/src/share/vm/classfile/classFileParser.hpp Wed Nov 17 22:42:08 2010 -0800
  970. +++ b/src/share/vm/classfile/classFileParser.hpp Fri Dec 17 13:24:08 2010 +0100
  971. @@ -65,6 +65,7 @@
  972. Handle class_loader,
  973. Handle protection_domain,
  974. symbolHandle class_name,
  975. + KlassHandle old_klass,
  976. TRAPS);
  977. // Field parsing
  978. @@ -135,7 +136,7 @@
  979. unsigned int nonstatic_oop_map_count,
  980. int* nonstatic_oop_offsets,
  981. unsigned int* nonstatic_oop_counts);
  982. - void set_precomputed_flags(instanceKlassHandle k);
  983. + void set_precomputed_flags(instanceKlassHandle k, KlassHandle old_klass);
  984. objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
  985. objArrayHandle local_ifs, TRAPS);
  986. @@ -265,21 +266,33 @@
  987. instanceKlassHandle parseClassFile(symbolHandle name,
  988. Handle class_loader,
  989. Handle protection_domain,
  990. + KlassHandle old_klass,
  991. symbolHandle& parsed_name,
  992. bool verify,
  993. TRAPS) {
  994. KlassHandle no_host_klass;
  995. - return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
  996. + return parseClassFile(name, class_loader, protection_domain, old_klass, no_host_klass, NULL, parsed_name, verify, THREAD);
  997. }
  998. instanceKlassHandle parseClassFile(symbolHandle name,
  999. Handle class_loader,
  1000. Handle protection_domain,
  1001. + KlassHandle old_klass,
  1002. KlassHandle host_klass,
  1003. GrowableArray<Handle>* cp_patches,
  1004. symbolHandle& parsed_name,
  1005. bool verify,
  1006. TRAPS);
  1007. + static void initialize_static_field(fieldDescriptor* fd, TRAPS);
  1008. +
  1009. + // (tw) Creates symbol handles for the super class and the interfaces
  1010. + void findSuperSymbols(symbolHandle name,
  1011. + Handle class_loader,
  1012. + Handle protection_domain,
  1013. + KlassHandle old_klass,
  1014. + GrowableArray<symbolHandle> &handles,
  1015. + TRAPS);
  1016. +
  1017. // Verifier checks
  1018. static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
  1019. static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
  1020. diff -r f5603a6e5042 src/share/vm/classfile/classLoader.cpp
  1021. --- a/src/share/vm/classfile/classLoader.cpp Wed Nov 17 22:42:08 2010 -0800
  1022. +++ b/src/share/vm/classfile/classLoader.cpp Fri Dec 17 13:24:08 2010 +0100
  1023. @@ -164,7 +164,7 @@
  1024. if (file_handle != -1) {
  1025. // read contents into resource array
  1026. u1* buffer = NEW_RESOURCE_ARRAY(u1, st.st_size);
  1027. - size_t num_read = os::read(file_handle, (char*) buffer, st.st_size);
  1028. + size_t num_read = hpi::read(file_handle, (char*) buffer, st.st_size);
  1029. // close file
  1030. hpi::close(file_handle);
  1031. // construct ClassFileStream
  1032. @@ -872,6 +872,7 @@
  1033. instanceKlassHandle result = parser.parseClassFile(h_name,
  1034. class_loader,
  1035. protection_domain,
  1036. + KlassHandle(),
  1037. parsed_name,
  1038. false,
  1039. CHECK_(h));
  1040. diff -r f5603a6e5042 src/share/vm/classfile/dictionary.cpp
  1041. --- a/src/share/vm/classfile/dictionary.cpp Wed Nov 17 22:42:08 2010 -0800
  1042. +++ b/src/share/vm/classfile/dictionary.cpp Fri Dec 17 13:24:08 2010 +0100
  1043. @@ -149,8 +149,8 @@
  1044. int live_count = 0;
  1045. // RC_TRACE macro has an embedded ResourceMark
  1046. - RC_TRACE(0x00000200, ("unload: %s: previous version length=%d",
  1047. - ik->external_name(), ik->previous_versions()->length()));
  1048. + TRACE_RC4("unload: %s: previous version length=%d",
  1049. + ik->external_name(), ik->previous_versions()->length());
  1050. for (int i = ik->previous_versions()->length() - 1; i >= 0; i--) {
  1051. // check the previous versions array for GC'ed weak refs
  1052. @@ -175,7 +175,7 @@
  1053. gc_count++;
  1054. continue;
  1055. } else {
  1056. - RC_TRACE(0x00000200, ("unload: previous version @%d is alive", i));
  1057. + TRACE_RC4("unload: previous version @%d is alive", i);
  1058. if (is_alive->do_object_b(pvcp)) {
  1059. live_count++;
  1060. } else {
  1061. @@ -185,8 +185,7 @@
  1062. GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  1063. if (method_refs != NULL) {
  1064. - RC_TRACE(0x00000200, ("unload: previous methods length=%d",
  1065. - method_refs->length()));
  1066. + TRACE_RC4("unload: previous methods length=%d", method_refs->length());
  1067. for (int j = method_refs->length() - 1; j >= 0; j--) {
  1068. jweak method_ref = method_refs->at(j);
  1069. assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  1070. @@ -203,19 +202,14 @@
  1071. JNIHandles::destroy_weak_global(method_ref);
  1072. method_refs->remove_at(j);
  1073. } else {
  1074. - // RC_TRACE macro has an embedded ResourceMark
  1075. - RC_TRACE(0x00000200,
  1076. - ("unload: %s(%s): prev method @%d in version @%d is alive",
  1077. - method->name()->as_C_string(),
  1078. - method->signature()->as_C_string(), j, i));
  1079. + TRACE_RC4("unload: %s(%s): prev method @%d in version @%d is alive", method->name()->as_C_string(),
  1080. + method->signature()->as_C_string(), j, i);
  1081. }
  1082. }
  1083. }
  1084. }
  1085. assert(ik->previous_versions()->length() == live_count, "sanity check");
  1086. - RC_TRACE(0x00000200,
  1087. - ("unload: previous version stats: live=%d, GC'ed=%d", live_count,
  1088. - gc_count));
  1089. + TRACE_RC4("unload: previous version stats: live=%d, GC'ed=%d", live_count, gc_count);
  1090. }
  1091. // Non-unloadable classes were handled in always_strong_oops_do
  1092. @@ -321,6 +315,21 @@
  1093. }
  1094. }
  1095. +
  1096. +// (tw) Just the classes from defining class loaders
  1097. +void Dictionary::classes_do(ObjectClosure *closure) {
  1098. + for (int index = 0; index < table_size(); index++) {
  1099. + for (DictionaryEntry* probe = bucket(index);
  1100. + probe != NULL;
  1101. + probe = probe->next()) {
  1102. + klassOop k = probe->klass();
  1103. + if (probe->loader() == instanceKlass::cast(k)->class_loader()) {
  1104. + closure->do_object(k);
  1105. + }
  1106. + }
  1107. + }
  1108. +}
  1109. +
  1110. // Added for initialize_itable_for_klass to handle exceptions
  1111. // Just the classes from defining class loaders
  1112. void Dictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
  1113. @@ -428,6 +437,33 @@
  1114. add_entry(index, entry);
  1115. }
  1116. +// (tw) Updates the klass entry to point to the new klassOop. Necessary only for class redefinition.
  1117. +bool Dictionary::update_klass(int index, unsigned int hash, symbolHandle name, Handle loader, KlassHandle k, KlassHandle old_class) {
  1118. +
  1119. + // There are several entries for the same class in the dictionary: One extra entry for each parent classloader of the classloader of the class.
  1120. + bool found = false;
  1121. + for (int index = 0; index < table_size(); index++) {
  1122. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  1123. + if (entry->klass() == old_class()) {
  1124. + entry->set_literal(k());
  1125. + found = true;
  1126. + }
  1127. + }
  1128. + }
  1129. +
  1130. + return found;
  1131. +}
  1132. +
  1133. +// (tw) Undo previous updates to the system dictionary
  1134. +void Dictionary::rollback_redefinition() {
  1135. + for (int index = 0; index < table_size(); index++) {
  1136. + for (DictionaryEntry* entry = bucket(index); entry != NULL; entry = entry->next()) {
  1137. + if (entry->klass()->klass_part()->is_redefining()) {
  1138. + entry->set_literal(entry->klass()->klass_part()->old_version());
  1139. + }
  1140. + }
  1141. + }
  1142. +}
  1143. // This routine does not lock the system dictionary.
  1144. //
  1145. @@ -455,12 +491,21 @@
  1146. return NULL;
  1147. }
  1148. +klassOop Dictionary::intercept_for_version(klassOop k) {
  1149. + if (k == NULL) return k;
  1150. +
  1151. + if (k->klass_part()->is_redefining() && !Thread::current()->pretend_new_universe()) {
  1152. + return k->klass_part()->old_version();
  1153. + }
  1154. +
  1155. + return k;
  1156. +}
  1157. klassOop Dictionary::find(int index, unsigned int hash, symbolHandle name,
  1158. Handle loader, Handle protection_domain, TRAPS) {
  1159. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  1160. if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) {
  1161. - return entry->klass();
  1162. + return intercept_for_version(entry->klass());
  1163. } else {
  1164. return NULL;
  1165. }
  1166. @@ -473,7 +518,7 @@
  1167. assert (index == index_for(name, loader), "incorrect index?");
  1168. DictionaryEntry* entry = get_entry(index, hash, name, loader);
  1169. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  1170. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  1171. }
  1172. @@ -485,7 +530,7 @@
  1173. assert (index == index_for(name, Handle()), "incorrect index?");
  1174. DictionaryEntry* entry = get_entry(index, hash, name, Handle());
  1175. - return (entry != NULL) ? entry->klass() : (klassOop)NULL;
  1176. + return intercept_for_version((entry != NULL) ? entry->klass() : (klassOop)NULL);
  1177. }
  1178. diff -r f5603a6e5042 src/share/vm/classfile/dictionary.hpp
  1179. --- a/src/share/vm/classfile/dictionary.hpp Wed Nov 17 22:42:08 2010 -0800
  1180. +++ b/src/share/vm/classfile/dictionary.hpp Fri Dec 17 13:24:08 2010 +0100
  1181. @@ -65,6 +65,10 @@
  1182. void add_klass(symbolHandle class_name, Handle class_loader,KlassHandle obj);
  1183. + bool update_klass(int index, unsigned int hash, symbolHandle name, Handle loader, KlassHandle k, KlassHandle old_class);
  1184. +
  1185. + void rollback_redefinition();
  1186. +
  1187. klassOop find_class(int index, unsigned int hash,
  1188. symbolHandle name, Handle loader);
  1189. @@ -81,6 +85,7 @@
  1190. void classes_do(void f(klassOop, TRAPS), TRAPS);
  1191. void classes_do(void f(klassOop, oop));
  1192. void classes_do(void f(klassOop, oop, TRAPS), TRAPS);
  1193. + void classes_do(ObjectClosure *closure);
  1194. void methods_do(void f(methodOop));
  1195. @@ -97,6 +102,7 @@
  1196. bool do_unloading(BoolObjectClosure* is_alive);
  1197. // Protection domains
  1198. + static klassOop intercept_for_version(klassOop k);
  1199. klassOop find(int index, unsigned int hash, symbolHandle name,
  1200. Handle loader, Handle protection_domain, TRAPS);
  1201. bool is_valid_protection_domain(int index, unsigned int hash,
  1202. diff -r f5603a6e5042 src/share/vm/classfile/javaClasses.cpp
  1203. --- a/src/share/vm/classfile/javaClasses.cpp Wed Nov 17 22:42:08 2010 -0800
  1204. +++ b/src/share/vm/classfile/javaClasses.cpp Fri Dec 17 13:24:08 2010 +0100
  1205. @@ -1537,7 +1537,7 @@
  1206. klassOop klass = SystemDictionary::reflect_Method_klass();
  1207. // This class is eagerly initialized during VM initialization, since we keep a refence
  1208. // to one of the methods
  1209. - assert(instanceKlass::cast(klass)->is_initialized(), "must be initialized");
  1210. + assert(instanceKlass::cast(klass)->is_initialized() || klass->klass_part()->old_version() != NULL, "must be initialized");
  1211. return instanceKlass::cast(klass)->allocate_instance_handle(CHECK_NH);
  1212. }
  1213. diff -r f5603a6e5042 src/share/vm/classfile/javaClasses.hpp
  1214. --- a/src/share/vm/classfile/javaClasses.hpp Wed Nov 17 22:42:08 2010 -0800
  1215. +++ b/src/share/vm/classfile/javaClasses.hpp Fri Dec 17 13:24:08 2010 +0100
  1216. @@ -124,6 +124,7 @@
  1217. class java_lang_Class : AllStatic {
  1218. friend class VMStructs;
  1219. + friend class VM_RedefineClasses;
  1220. private:
  1221. // The fake offsets are added by the class loader when java.lang.Class is loaded
  1222. diff -r f5603a6e5042 src/share/vm/classfile/loaderConstraints.cpp
  1223. --- a/src/share/vm/classfile/loaderConstraints.cpp Wed Nov 17 22:42:08 2010 -0800
  1224. +++ b/src/share/vm/classfile/loaderConstraints.cpp Fri Dec 17 13:24:08 2010 +0100
  1225. @@ -449,7 +449,7 @@
  1226. if (k != NULL) {
  1227. // We found the class in the system dictionary, so we should
  1228. // make sure that the klassOop matches what we already have.
  1229. - guarantee(k == probe->klass(), "klass should be in dictionary");
  1230. + guarantee(k == probe->klass()->klass_part()->newest_version(), "klass should be in dictionary");
  1231. } else {
  1232. // If we don't find the class in the system dictionary, it
  1233. // has to be in the placeholders table.
  1234. diff -r f5603a6e5042 src/share/vm/classfile/loaderConstraints.hpp
  1235. --- a/src/share/vm/classfile/loaderConstraints.hpp Wed Nov 17 22:42:08 2010 -0800
  1236. +++ b/src/share/vm/classfile/loaderConstraints.hpp Fri Dec 17 13:24:08 2010 +0100
  1237. @@ -99,7 +99,7 @@
  1238. klassOop klass() { return (klassOop)literal(); }
  1239. klassOop* klass_addr() { return (klassOop*)literal_addr(); }
  1240. - void set_klass(klassOop k) { set_literal(k); }
  1241. + void set_klass(klassOop k) { set_literal(k); assert(k == NULL || !k->klass_part()->is_redefining(), "just checking"); }
  1242. LoaderConstraintEntry* next() {
  1243. return (LoaderConstraintEntry*)HashtableEntry::next();
  1244. diff -r f5603a6e5042 src/share/vm/classfile/systemDictionary.cpp
  1245. --- a/src/share/vm/classfile/systemDictionary.cpp Wed Nov 17 22:42:08 2010 -0800
  1246. +++ b/src/share/vm/classfile/systemDictionary.cpp Fri Dec 17 13:24:08 2010 +0100
  1247. @@ -119,6 +119,7 @@
  1248. // can return a null klass
  1249. klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
  1250. }
  1251. + assert(klass == NULL || klass->klass_part()->is_newest_version() || klass->klass_part()->newest_version()->klass_part()->is_redefining(), "must be");
  1252. return klass;
  1253. }
  1254. @@ -161,7 +162,8 @@
  1255. // Forwards to resolve_instance_class_or_null
  1256. klassOop SystemDictionary::resolve_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS) {
  1257. - assert(!THREAD->is_Compiler_thread(), "Can not load classes with the Compiler thread");
  1258. + // (tw) Check if this relaxing of the condition is correct? Test case hs203t004 failing otherwise.
  1259. + assert(!THREAD->is_Compiler_thread() || JvmtiThreadState::state_for(JavaThread::current())->get_class_being_redefined() != NULL, "Can not load classes with the Compiler thread");
  1260. if (FieldType::is_array(class_name())) {
  1261. return resolve_array_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL);
  1262. } else {
  1263. @@ -976,6 +978,7 @@
  1264. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1265. class_loader,
  1266. protection_domain,
  1267. + KlassHandle(),
  1268. host_klass,
  1269. cp_patches,
  1270. parsed_name,
  1271. @@ -1036,8 +1039,15 @@
  1272. Handle protection_domain,
  1273. ClassFileStream* st,
  1274. bool verify,
  1275. + KlassHandle old_class,
  1276. TRAPS) {
  1277. + bool redefine_classes_locked = false;
  1278. + if (!Thread::current()->redefine_classes_mutex()->owned_by_self()) {
  1279. + Thread::current()->redefine_classes_mutex()->lock();
  1280. + redefine_classes_locked = true;
  1281. + }
  1282. +
  1283. // Classloaders that support parallelism, e.g. bootstrap classloader,
  1284. // or all classloaders with UnsyncloadClass do not acquire lock here
  1285. bool DoObjectLock = true;
  1286. @@ -1065,9 +1075,14 @@
  1287. instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
  1288. class_loader,
  1289. protection_domain,
  1290. + old_class,
  1291. parsed_name,
  1292. verify,
  1293. THREAD);
  1294. + if (!old_class.is_null() && !k.is_null()) {
  1295. + k->set_redefining(true);
  1296. + k->set_old_version(old_class());
  1297. + }
  1298. const char* pkg = "java/";
  1299. if (!HAS_PENDING_EXCEPTION &&
  1300. @@ -1103,13 +1118,18 @@
  1301. // Add class just loaded
  1302. // If a class loader supports parallel classloading handle parallel define requests
  1303. // find_or_define_instance_class may return a different instanceKlass
  1304. - if (is_parallelCapable(class_loader)) {
  1305. + // (tw) TODO: for class redefinition the parallel version does not work, check if this is a problem?
  1306. + if (is_parallelCapable(class_loader) && old_class.is_null()) {
  1307. k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
  1308. } else {
  1309. - define_instance_class(k, THREAD);
  1310. + define_instance_class(k, old_class, THREAD);
  1311. }
  1312. }
  1313. + if (redefine_classes_locked) {
  1314. + Thread::current()->redefine_classes_mutex()->unlock();
  1315. + }
  1316. +
  1317. // If parsing the class file or define_instance_class failed, we
  1318. // need to remove the placeholder added on our behalf. But we
  1319. // must make sure parsed_name is valid first (it won't be if we had
  1320. @@ -1138,7 +1158,7 @@
  1321. MutexLocker mu(SystemDictionary_lock, THREAD);
  1322. oop check = find_class_or_placeholder(parsed_name, class_loader);
  1323. - assert(check == k(), "should be present in the dictionary");
  1324. + assert((check == k() && !k->is_redefining()) || (k->is_redefining() && check == k->old_version()), "should be present in the dictionary");
  1325. oop check2 = find_class_or_placeholder(h_name, h_loader);
  1326. assert(check == check2, "name inconsistancy in SystemDictionary");
  1327. @@ -1424,7 +1444,11 @@
  1328. }
  1329. }
  1330. -void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
  1331. +void SystemDictionary::rollback_redefinition() {
  1332. + dictionary()->rollback_redefinition();
  1333. +}
  1334. +
  1335. +void SystemDictionary::define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS) {
  1336. Handle class_loader_h(THREAD, k->class_loader());
  1337. @@ -1451,13 +1475,23 @@
  1338. symbolHandle name_h(THREAD, k->name());
  1339. unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
  1340. int d_index = dictionary()->hash_to_index(d_hash);
  1341. - check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
  1342. +
  1343. + // (tw) Update version of the klassOop in the system dictionary
  1344. + // TODO: Check for thread safety!
  1345. + if (!old_class.is_null()) {
  1346. + bool ok = dictionary()->update_klass(d_index, d_hash, name_h, class_loader_h, k, old_class);
  1347. + assert (ok, "must have found old class and updated!");
  1348. + }
  1349. + check_constraints(d_index, d_hash, k, class_loader_h, old_class.is_null(), CHECK);
  1350. +
  1351. + if(!old_class.is_null() && TraceRedefineClasses >= 3){ tty->print_cr("Class has been updated!"); }
  1352. // Register class just loaded with class loader (placed in Vector)
  1353. // Note we do this before updating the dictionary, as this can
  1354. // fail with an OutOfMemoryError (if it does, we will *not* put this
  1355. // class in the dictionary and will not update the class hierarchy).
  1356. - if (k->class_loader() != NULL) {
  1357. + // (tw) Only register if not redefining a class.
  1358. + if (k->class_loader() != NULL && old_class.is_null()) {
  1359. methodHandle m(THREAD, Universe::loader_addClass_method());
  1360. JavaValue result(T_VOID);
  1361. JavaCallArguments args(class_loader_h);
  1362. @@ -1483,8 +1517,9 @@
  1363. }
  1364. k->eager_initialize(THREAD);
  1365. + // (tw) Only notify jvmti if not redefining a class.
  1366. // notify jvmti
  1367. - if (JvmtiExport::should_post_class_load()) {
  1368. + if (JvmtiExport::should_post_class_load() && old_class.is_null()) {
  1369. assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
  1370. JvmtiExport::post_class_load((JavaThread *) THREAD, k());
  1371. @@ -1558,7 +1593,7 @@
  1372. }
  1373. }
  1374. - define_instance_class(k, THREAD);
  1375. + define_instance_class(k, KlassHandle(), THREAD);
  1376. Handle linkage_exception = Handle(); // null handle
  1377. @@ -1698,6 +1733,14 @@
  1378. Universe::flush_dependents_on(k);
  1379. }
  1380. +// (tw) Remove from hierarchy - Undo add_to_hierarchy.
  1381. +void SystemDictionary::remove_from_hierarchy(instanceKlassHandle k) {
  1382. + assert(k.not_null(), "just checking");
  1383. +
  1384. + k->remove_from_sibling_list();
  1385. +
  1386. + // TODO: Remove from interfaces.
  1387. +}
  1388. // ----------------------------------------------------------------------------
  1389. // GC support
  1390. @@ -1778,10 +1821,8 @@
  1391. }
  1392. -void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  1393. - f->do_oop((oop*) &wk_klass_name_limits[0]);
  1394. - f->do_oop((oop*) &wk_klass_name_limits[1]);
  1395. -
  1396. +// (tw) Iterate over all pre-loaded classes in the dictionary.
  1397. +void SystemDictionary::preloaded_classes_do(OopClosure *f) {
  1398. for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1399. f->do_oop((oop*) &_well_known_klasses[k]);
  1400. }
  1401. @@ -1795,6 +1836,26 @@
  1402. }
  1403. }
  1404. + // TODO: Check if we need to call FilterFieldsMap
  1405. +}
  1406. +
  1407. +void SystemDictionary::preloaded_oops_do(OopClosure* f) {
  1408. + f->do_oop((oop*) &wk_klass_name_limits[0]);
  1409. + f->do_oop((oop*) &wk_klass_name_limits[1]);
  1410. +
  1411. + for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
  1412. + f->do_oop((oop*) &_well_known_klasses[k]);
  1413. + }
  1414. +
  1415. + {
  1416. + for (int i = 0; i < T_VOID+1; i++) {
  1417. + if (_box_klasses[i] != NULL) {
  1418. + assert(i >= T_BOOLEAN, "checking");
  1419. + f->do_oop((oop*) &_box_klasses[i]);
  1420. + }
  1421. + }
  1422. + }
  1423. +
  1424. // The basic type mirrors would have already been processed in
  1425. // Universe::oops_do(), via a call to shared_oops_do(), so should
  1426. // not be processed again.
  1427. @@ -1813,6 +1874,11 @@
  1428. dictionary()->classes_do(f);
  1429. }
  1430. +// (tw) Iterate over all classes in the dictionary.
  1431. +void SystemDictionary::classes_do(ObjectClosure *closure) {
  1432. + dictionary()->classes_do(closure);
  1433. +}
  1434. +
  1435. // Added for initialize_itable_for_klass
  1436. // Just the classes from defining class loaders
  1437. // Don't iterate over placeholders
  1438. @@ -1962,7 +2028,9 @@
  1439. // Preload ref klasses and set reference types
  1440. instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
  1441. - instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1442. +
  1443. + // (tw) This is now done in parseClassFile in order to support class redefinition
  1444. + // instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
  1445. initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
  1446. instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
  1447. @@ -2064,7 +2132,11 @@
  1448. // also holds array classes
  1449. assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
  1450. - if ((defining == true) || (k() != check)) {
  1451. + if ((defining == true) && ((k() != check) && k->old_version() != check)) {
  1452. + ResourceMark rm(Thread::current());
  1453. + 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());
  1454. + k()->print();
  1455. + check->print();
  1456. linkage_error = "loader (instance of %s): attempted duplicate class "
  1457. "definition for name: \"%s\"";
  1458. } else {
  1459. @@ -2718,8 +2790,9 @@
  1460. if (probe == NULL) {
  1461. probe = SystemDictionary::find_shared_class(class_name);
  1462. }
  1463. + // (tw) Relaxed assertion to allow different class versions. Also allow redefining classes lie around (because of rollback).
  1464. guarantee(probe != NULL &&
  1465. - (!probe->is_klass() || probe == obj()),
  1466. + (!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(),
  1467. "Loaded klasses should be in SystemDictionary");
  1468. }
  1469. diff -r f5603a6e5042 src/share/vm/classfile/systemDictionary.hpp
  1470. --- a/src/share/vm/classfile/systemDictionary.hpp Wed Nov 17 22:42:08 2010 -0800
  1471. +++ b/src/share/vm/classfile/systemDictionary.hpp Fri Dec 17 13:24:08 2010 +0100
  1472. @@ -260,7 +260,7 @@
  1473. // Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
  1474. static klassOop resolve_from_stream(symbolHandle class_name, Handle class_loader,
  1475. Handle protection_domain,
  1476. - ClassFileStream* st, bool verify, TRAPS);
  1477. + ClassFileStream* st, bool verify, KlassHandle old_class, TRAPS);
  1478. // Lookup an already loaded class. If not found NULL is returned.
  1479. static klassOop find(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS);
  1480. @@ -304,6 +304,8 @@
  1481. // Iterate over all klasses in dictionary
  1482. // Just the classes from defining class loaders
  1483. static void classes_do(void f(klassOop));
  1484. + static void classes_do(ObjectClosure *closure);
  1485. + static void preloaded_classes_do(OopClosure *closure);
  1486. // Added for initialize_itable_for_klass to handle exceptions
  1487. static void classes_do(void f(klassOop, TRAPS), TRAPS);
  1488. // All classes, and their class loaders
  1489. @@ -408,6 +410,8 @@
  1490. initialize_wk_klasses_until((WKID) limit, start_id, THREAD);
  1491. }
  1492. + static void rollback_redefinition();
  1493. +
  1494. public:
  1495. #define WK_KLASS_DECLARE(name, ignore_symbol, option) \
  1496. static klassOop name() { return check_klass_##option(_well_known_klasses[WK_KLASS_ENUM_NAME(name)]); }
  1497. @@ -576,7 +580,7 @@
  1498. // after waiting, but before reentering SystemDictionary_lock
  1499. // to preserve lock order semantics.
  1500. static void double_lock_wait(Handle lockObject, TRAPS);
  1501. - static void define_instance_class(instanceKlassHandle k, TRAPS);
  1502. + static void define_instance_class(instanceKlassHandle k, KlassHandle old_class, TRAPS);
  1503. static instanceKlassHandle find_or_define_instance_class(symbolHandle class_name,
  1504. Handle class_loader,
  1505. instanceKlassHandle k, TRAPS);
  1506. @@ -595,6 +599,11 @@
  1507. // Setup link to hierarchy
  1508. static void add_to_hierarchy(instanceKlassHandle k, TRAPS);
  1509. +public:
  1510. +
  1511. + // Remove link to hierarchy
  1512. + static void remove_from_hierarchy(instanceKlassHandle k);
  1513. +
  1514. private:
  1515. // We pass in the hashtable index so we can calculate it outside of
  1516. // the SystemDictionary_lock.
  1517. diff -r f5603a6e5042 src/share/vm/classfile/verifier.cpp
  1518. --- a/src/share/vm/classfile/verifier.cpp Wed Nov 17 22:42:08 2010 -0800
  1519. +++ b/src/share/vm/classfile/verifier.cpp Fri Dec 17 13:24:08 2010 +0100
  1520. @@ -70,7 +70,7 @@
  1521. return !need_verify;
  1522. }
  1523. -bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) {
  1524. +bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS) {
  1525. ResourceMark rm(THREAD);
  1526. HandleMark hm;
  1527. @@ -94,17 +94,19 @@
  1528. split_verifier.verify_class(THREAD);
  1529. exception_name = split_verifier.result();
  1530. if (klass->major_version() < NOFAILOVER_MAJOR_VERSION &&
  1531. - FailOverToOldVerifier && !HAS_PENDING_EXCEPTION &&
  1532. + FailOverToOldVerifier && may_use_old_verifier && !HAS_PENDING_EXCEPTION &&
  1533. (exception_name == vmSymbols::java_lang_VerifyError() ||
  1534. exception_name == vmSymbols::java_lang_ClassFormatError())) {
  1535. if (TraceClassInitialization) {
  1536. tty->print_cr(
  1537. "Fail over class verification to old verifier for: %s", klassName);
  1538. }
  1539. + assert(may_use_old_verifier, "");
  1540. exception_name = inference_verify(
  1541. klass, message_buffer, message_buffer_len, THREAD);
  1542. }
  1543. } else {
  1544. + assert(may_use_old_verifier, "");
  1545. exception_name = inference_verify(
  1546. klass, message_buffer, message_buffer_len, THREAD);
  1547. }
  1548. @@ -119,6 +121,9 @@
  1549. }
  1550. tty->print_cr("End class verification for: %s", klassName);
  1551. }
  1552. + } else if (TraceClassInitialization) {
  1553. + // (tw) Output not verified classes
  1554. + tty->print_cr("Class %s was not verified", klassName);
  1555. }
  1556. if (HAS_PENDING_EXCEPTION) {
  1557. @@ -170,7 +175,7 @@
  1558. // NOTE: this is called too early in the bootstrapping process to be
  1559. // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection.
  1560. (refl_magic_klass == NULL ||
  1561. - !klass->is_subtype_of(refl_magic_klass) ||
  1562. + !(klass->is_subtype_of(refl_magic_klass) || klass->is_subtype_of(refl_magic_klass->klass_part()->newest_version())) ||
  1563. VerifyReflectionBytecodes)
  1564. );
  1565. }
  1566. @@ -240,7 +245,7 @@
  1567. ClassVerifier::ClassVerifier(
  1568. instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS)
  1569. : _thread(THREAD), _exception_type(symbolHandle()), _message(msg),
  1570. - _message_buffer_len(msg_len), _klass(klass) {
  1571. + _message_buffer_len(msg_len), _klass(klass->newest_version()), _klass_to_verify(klass) {
  1572. _this_type = VerificationType::reference_type(klass->name());
  1573. }
  1574. @@ -253,7 +258,7 @@
  1575. _klass->external_name());
  1576. }
  1577. - objArrayHandle methods(THREAD, _klass->methods());
  1578. + objArrayHandle methods(THREAD, _klass_to_verify->methods());
  1579. int num_methods = methods->length();
  1580. for (int index = 0; index < num_methods; index++) {
  1581. @@ -2043,7 +2048,10 @@
  1582. VerificationType stack_object_type =
  1583. current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
  1584. if (current_type() != stack_object_type) {
  1585. - assert(cp->cache() == NULL, "not rewritten yet");
  1586. +
  1587. + // (tw) TODO: Check if relaxing the following assertion is correct. For class redefinition we might call the verifier twice.
  1588. + //assert(cp->cache() == NULL, "not rewritten yet");
  1589. +
  1590. symbolHandle ref_class_name = symbolHandle(THREAD,
  1591. cp->klass_name_at(cp->klass_ref_index_at(index)));
  1592. // See the comments in verify_field_instructions() for
  1593. diff -r f5603a6e5042 src/share/vm/classfile/verifier.hpp
  1594. --- a/src/share/vm/classfile/verifier.hpp Wed Nov 17 22:42:08 2010 -0800
  1595. +++ b/src/share/vm/classfile/verifier.hpp Fri Dec 17 13:24:08 2010 +0100
  1596. @@ -37,7 +37,7 @@
  1597. * Otherwise, no exception is thrown and the return indicates the
  1598. * error.
  1599. */
  1600. - static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
  1601. + static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, bool may_use_old_verifier, TRAPS);
  1602. // Return false if the class is loaded by the bootstrap loader,
  1603. // or if defineClass was called requesting skipping verification
  1604. @@ -88,7 +88,10 @@
  1605. char* _message;
  1606. size_t _message_buffer_len;
  1607. +public:
  1608. void verify_method(methodHandle method, TRAPS);
  1609. +
  1610. +private:
  1611. char* generate_code_data(methodHandle m, u4 code_length, TRAPS);
  1612. void verify_exception_handler_table(u4 code_length, char* code_data, int& min, int& max, TRAPS);
  1613. void verify_local_variable_table(u4 code_length, char* code_data, TRAPS);
  1614. @@ -157,6 +160,7 @@
  1615. bool name_in_supers(symbolOop ref_name, instanceKlassHandle current);
  1616. + instanceKlassHandle _klass_to_verify;
  1617. instanceKlassHandle _klass; // the class being verified
  1618. methodHandle _method; // current method being verified
  1619. VerificationType _this_type; // the verification type of the current class
  1620. diff -r f5603a6e5042 src/share/vm/classfile/vmSymbols.hpp
  1621. --- a/src/share/vm/classfile/vmSymbols.hpp Wed Nov 17 22:42:08 2010 -0800
  1622. +++ b/src/share/vm/classfile/vmSymbols.hpp Fri Dec 17 13:24:08 2010 +0100
  1623. @@ -349,6 +349,9 @@
  1624. template(erasedType_name, "erasedType") \
  1625. template(genericInvoker_name, "genericInvoker") \
  1626. template(append_name, "append") \
  1627. + /* mutator in case of class redefinition */ \
  1628. + template(static_transformer_name, "$staticTransformer") \
  1629. + template(transformer_name, "$transformer") \
  1630. \
  1631. /* non-intrinsic name/signature pairs: */ \
  1632. template(register_method_name, "register") \
  1633. diff -r f5603a6e5042 src/share/vm/code/nmethod.cpp
  1634. --- a/src/share/vm/code/nmethod.cpp Wed Nov 17 22:42:08 2010 -0800
  1635. +++ b/src/share/vm/code/nmethod.cpp Fri Dec 17 13:24:08 2010 +0100
  1636. @@ -2055,15 +2055,14 @@
  1637. methodOop method = deps.method_argument(0);
  1638. for (int j = 0; j < dependee_methods->length(); j++) {
  1639. if ((methodOop) dependee_methods->obj_at(j) == method) {
  1640. - // RC_TRACE macro has an embedded ResourceMark
  1641. - RC_TRACE(0x01000000,
  1642. - ("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)",
  1643. + ResourceMark rm(Thread::current());
  1644. + TRACE_RC3("Found evol dependency of nmethod %s.%s(%s) compile_id=%d on method %s.%s(%s)",
  1645. _method->method_holder()->klass_part()->external_name(),
  1646. _method->name()->as_C_string(),
  1647. _method->signature()->as_C_string(), compile_id(),
  1648. method->method_holder()->klass_part()->external_name(),
  1649. method->name()->as_C_string(),
  1650. - method->signature()->as_C_string()));
  1651. + method->signature()->as_C_string());
  1652. if (TraceDependencies || LogCompilation)
  1653. deps.log_dependency(dependee);
  1654. return true;
  1655. diff -r f5603a6e5042 src/share/vm/compiler/compileBroker.cpp
  1656. --- a/src/share/vm/compiler/compileBroker.cpp Wed Nov 17 22:42:08 2010 -0800
  1657. +++ b/src/share/vm/compiler/compileBroker.cpp Fri Dec 17 13:24:08 2010 +0100
  1658. @@ -1027,6 +1027,7 @@
  1659. }
  1660. // RedefineClasses() has replaced this method; just return
  1661. + // (tw) This is important for the new version of hotswapping: Old code will only execute properly in the interpreter!
  1662. if (method->is_old()) {
  1663. return NULL;
  1664. }
  1665. @@ -1352,6 +1353,8 @@
  1666. // Never compile a method if breakpoints are present in it
  1667. if (method()->number_of_breakpoints() == 0) {
  1668. + thread->compilation_mutex()->lock();
  1669. + thread->set_should_bailout(false);
  1670. // Compile the method.
  1671. if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
  1672. #ifdef COMPILER1
  1673. @@ -1375,6 +1378,7 @@
  1674. // After compilation is disabled, remove remaining methods from queue
  1675. method->clear_queued_for_compilation();
  1676. }
  1677. + thread->compilation_mutex()->unlock();
  1678. }
  1679. }
  1680. }
  1681. @@ -1535,7 +1539,11 @@
  1682. //assert(false, "compiler should always document failure");
  1683. // The compiler elected, without comment, not to register a result.
  1684. // Do not attempt further compilations of this method.
  1685. - ci_env.record_method_not_compilable("compile failed");
  1686. + if (((CompilerThread *)Thread::current())->should_bailout()) {
  1687. + ci_env.record_failure("compile externally aborted");
  1688. + } else {
  1689. + ci_env.record_method_not_compilable("compile failed");
  1690. + }
  1691. }
  1692. if (ci_env.failing()) {
  1693. @@ -1882,3 +1890,15 @@
  1694. st->cr();
  1695. #endif
  1696. }
  1697. +
  1698. +// (tw) Clean up compiler interface after a class redefinition step
  1699. +void CompileBroker::cleanup_after_redefinition() {
  1700. + int num_threads = _method_threads->length();
  1701. +
  1702. + ciObjectFactory::sort_ci_objects(ciObjectFactory::_shared_ci_objects);
  1703. + for (int i=0; i<num_threads; i++) {
  1704. + if (_method_threads->at(i)->env() != NULL && _method_threads->at(i)->env() != (ciEnv *)badAddress) {
  1705. + _method_threads->at(i)->env()->cleanup_after_redefinition();
  1706. + }
  1707. + }
  1708. +}
  1709. \ No newline at end of file
  1710. diff -r f5603a6e5042 src/share/vm/compiler/compileBroker.hpp
  1711. --- a/src/share/vm/compiler/compileBroker.hpp Wed Nov 17 22:42:08 2010 -0800
  1712. +++ b/src/share/vm/compiler/compileBroker.hpp Fri Dec 17 13:24:08 2010 +0100
  1713. @@ -379,4 +379,6 @@
  1714. static void print_last_compile();
  1715. static void print_compiler_threads_on(outputStream* st);
  1716. +
  1717. + static void cleanup_after_redefinition();
  1718. };
  1719. diff -r f5603a6e5042 src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp
  1720. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Wed Nov 17 22:42:08 2010 -0800
  1721. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.cpp Fri Dec 17 13:24:08 2010 +0100
  1722. @@ -140,6 +140,13 @@
  1723. }
  1724. }
  1725. +
  1726. +HeapWord* CompactibleFreeListSpace::forward_compact_top(size_t size,
  1727. + CompactPoint* cp, HeapWord* compact_top) {
  1728. + ShouldNotReachHere();
  1729. + return NULL;
  1730. +}
  1731. +
  1732. // Like CompactibleSpace forward() but always calls cross_threshold() to
  1733. // update the block offset table. Removed initialize_threshold call because
  1734. // CFLS does not use a block offset array for contiguous spaces.
  1735. diff -r f5603a6e5042 src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp
  1736. --- a/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp Wed Nov 17 22:42:08 2010 -0800
  1737. +++ b/src/share/vm/gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp Fri Dec 17 13:24:08 2010 +0100
  1738. @@ -140,6 +140,7 @@
  1739. // Support for compacting cms
  1740. HeapWord* cross_threshold(HeapWord* start, HeapWord* end);
  1741. + HeapWord* forward_compact_top(size_t size, CompactPoint* cp, HeapWord* compact_top);
  1742. HeapWord* forward(oop q, size_t size, CompactPoint* cp, HeapWord* compact_top);
  1743. // Initialization helpers.
  1744. diff -r f5603a6e5042 src/share/vm/gc_implementation/includeDB_gc_g1
  1745. --- a/src/share/vm/gc_implementation/includeDB_gc_g1 Wed Nov 17 22:42:08 2010 -0800
  1746. +++ b/src/share/vm/gc_implementation/includeDB_gc_g1 Fri Dec 17 13:24:08 2010 +0100
  1747. @@ -330,8 +330,6 @@
  1748. ptrQueue.hpp allocation.hpp
  1749. ptrQueue.hpp sizes.hpp
  1750. -ptrQueue.inline.hpp ptrQueue.hpp
  1751. -
  1752. satbQueue.cpp allocation.inline.hpp
  1753. satbQueue.cpp mutexLocker.hpp
  1754. satbQueue.cpp satbQueue.hpp
  1755. diff -r f5603a6e5042 src/share/vm/gc_implementation/shared/markSweep.cpp
  1756. --- a/src/share/vm/gc_implementation/shared/markSweep.cpp Wed Nov 17 22:42:08 2010 -0800
  1757. +++ b/src/share/vm/gc_implementation/shared/markSweep.cpp Fri Dec 17 13:24:08 2010 +0100
  1758. @@ -25,6 +25,8 @@
  1759. #include "incls/_precompiled.incl"
  1760. #include "incls/_markSweep.cpp.incl"
  1761. +GrowableArray<oop>* MarkSweep::_rescued_oops = NULL;
  1762. +
  1763. Stack<oop> MarkSweep::_marking_stack;
  1764. Stack<DataLayout*> MarkSweep::_revisit_mdo_stack;
  1765. Stack<Klass*> MarkSweep::_revisit_klass_stack;
  1766. @@ -345,3 +347,86 @@
  1767. }
  1768. #endif
  1769. +
  1770. +// (tw) Copy the rescued objects to their destination address after compaction.
  1771. +void MarkSweep::copy_rescued_objects_back() {
  1772. +
  1773. + if (_rescued_oops != NULL) {
  1774. +
  1775. + for (int i=0; i<_rescued_oops->length(); i++) {
  1776. + oop rescued_obj = _rescued_oops->at(i);
  1777. +
  1778. + int size = rescued_obj->size();
  1779. + oop new_obj = rescued_obj->forwardee();
  1780. +
  1781. + if (rescued_obj->blueprint()->new_version() != NULL) {
  1782. + MarkSweep::update_fields(rescued_obj, new_obj);
  1783. + } else {
  1784. + Copy::aligned_disjoint_words((HeapWord*)rescued_obj, (HeapWord*)new_obj, size);
  1785. + }
  1786. +
  1787. + FREE_RESOURCE_ARRAY(HeapWord, rescued_obj, size);
  1788. +
  1789. + new_obj->init_mark();
  1790. + assert(new_obj->is_oop(), "must be a valid oop");
  1791. + }
  1792. + _rescued_oops->clear();
  1793. + _rescued_oops = NULL;
  1794. + }
  1795. +}
  1796. +
  1797. +// (tw) Update instances of a class whose fields changed.
  1798. +void MarkSweep::update_fields(oop q, oop new_location) {
  1799. +
  1800. + assert(q->blueprint()->new_version() != NULL, "class of old object must have new version");
  1801. +
  1802. + klassOop old_klass_oop = q->klass();
  1803. + klassOop new_klass_oop = q->blueprint()->new_version();
  1804. +
  1805. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  1806. + instanceKlass *new_klass = instanceKlass::cast(new_klass_oop);
  1807. +
  1808. + int size = q->size_given_klass(old_klass);
  1809. + int new_size = q->size_given_klass(new_klass);
  1810. +
  1811. + oop tmp_obj = q;
  1812. +
  1813. + if (new_klass_oop->klass_part()->is_copying_backwards()) {
  1814. + if (((HeapWord *)q >= (HeapWord *)new_location && (HeapWord *)q < (HeapWord *)new_location + new_size) ||
  1815. + ((HeapWord *)new_location >= (HeapWord *)q && (HeapWord *)new_location < (HeapWord *)q + size)) {
  1816. + tmp_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  1817. + Copy::aligned_disjoint_words((HeapWord*)q, (HeapWord*)tmp_obj, size);
  1818. + }
  1819. + }
  1820. +
  1821. + int *cur = new_klass_oop->klass_part()->update_information();
  1822. +
  1823. + tmp_obj->set_klass_no_check(new_klass_oop);
  1824. +
  1825. + if (cur == NULL) {
  1826. + assert(size == new_size, "just checking");
  1827. + Copy::conjoint_words(((HeapWord *)tmp_obj), ((HeapWord *)new_location), size);
  1828. + } else {
  1829. + int destOffset = 0;
  1830. + while (*cur != 0) {
  1831. + if (*cur > 0) {
  1832. + int size = *cur;
  1833. + cur++;
  1834. + int offset = *cur;
  1835. + Copy::conjoint_jbytes(((char *)tmp_obj) + offset, ((char *)new_location) + destOffset, size);
  1836. + destOffset += size;
  1837. + cur++;
  1838. + } else {
  1839. + assert(*cur < 0, "");
  1840. + int skip = -*cur;
  1841. + Copy::fill_to_bytes(((char*)new_location) + destOffset, skip, 0);
  1842. + destOffset += skip;
  1843. + cur++;
  1844. + }
  1845. + }
  1846. + }
  1847. +
  1848. + if (tmp_obj != q) {
  1849. + FREE_RESOURCE_ARRAY(HeapWord, tmp_obj, size);
  1850. + }
  1851. +}
  1852. diff -r f5603a6e5042 src/share/vm/gc_implementation/shared/markSweep.hpp
  1853. --- a/src/share/vm/gc_implementation/shared/markSweep.hpp Wed Nov 17 22:42:08 2010 -0800
  1854. +++ b/src/share/vm/gc_implementation/shared/markSweep.hpp Fri Dec 17 13:24:08 2010 +0100
  1855. @@ -103,8 +103,12 @@
  1856. friend class AdjustPointerClosure;
  1857. friend class KeepAliveClosure;
  1858. friend class VM_MarkSweep;
  1859. + friend class GenMarkSweep;
  1860. friend void marksweep_init();
  1861. +public:
  1862. + static GrowableArray<oop>* _rescued_oops;
  1863. +
  1864. //
  1865. // Vars
  1866. //
  1867. @@ -190,6 +194,8 @@
  1868. template <class T> static inline void mark_and_push(T* p);
  1869. static inline void push_objarray(oop obj, size_t index);
  1870. + static void copy_rescued_objects_back();
  1871. + static void update_fields(oop q, oop new_location);
  1872. static void follow_stack(); // Empty marking stack.
  1873. static void preserve_mark(oop p, markOop mark);
  1874. diff -r f5603a6e5042 src/share/vm/includeDB_core
  1875. --- a/src/share/vm/includeDB_core Wed Nov 17 22:42:08 2010 -0800
  1876. +++ b/src/share/vm/includeDB_core Fri Dec 17 13:24:08 2010 +0100
  1877. @@ -1782,6 +1782,7 @@
  1878. genMarkSweep.cpp thread_<os_family>.inline.hpp
  1879. genMarkSweep.cpp vmSymbols.hpp
  1880. genMarkSweep.cpp vmThread.hpp
  1881. +genMarkSweep.cpp jvmtiRedefineClassesTrace.hpp
  1882. genMarkSweep.hpp markSweep.hpp
  1883. @@ -2625,6 +2626,7 @@
  1884. klassVtable.hpp handles.hpp
  1885. klassVtable.hpp oopsHierarchy.hpp
  1886. +linkResolver.cpp jvmtiRedefineClassesTrace.hpp
  1887. linkResolver.cpp bytecode.hpp
  1888. linkResolver.cpp collectedHeap.inline.hpp
  1889. linkResolver.cpp compilationPolicy.hpp
  1890. @@ -3860,6 +3862,7 @@
  1891. space.cpp systemDictionary.hpp
  1892. space.cpp universe.inline.hpp
  1893. space.cpp vmSymbols.hpp
  1894. +space.cpp jvmtiRedefineClassesTrace.hpp
  1895. space.hpp allocation.hpp
  1896. space.hpp blockOffsetTable.hpp
  1897. diff -r f5603a6e5042 src/share/vm/includeDB_jvmti
  1898. --- a/src/share/vm/includeDB_jvmti Wed Nov 17 22:42:08 2010 -0800
  1899. +++ b/src/share/vm/includeDB_jvmti Fri Dec 17 13:24:08 2010 +0100
  1900. @@ -231,7 +231,10 @@
  1901. jvmtiRedefineClasses.cpp systemDictionary.hpp
  1902. jvmtiRedefineClasses.cpp universe.inline.hpp
  1903. jvmtiRedefineClasses.cpp verifier.hpp
  1904. +jvmtiRedefineClasses.cpp jvmtiClassFileReconstituter.hpp
  1905. +jvmtiRedefineClasses.cpp compileBroker.hpp
  1906. +jvmtiRedefineClasses.hpp vmGCOperations.hpp
  1907. jvmtiRedefineClasses.hpp jvmtiEnv.hpp
  1908. jvmtiRedefineClasses.hpp jvmtiRedefineClassesTrace.hpp
  1909. jvmtiRedefineClasses.hpp objArrayKlass.hpp
  1910. diff -r f5603a6e5042 src/share/vm/interpreter/interpreterRuntime.cpp
  1911. --- a/src/share/vm/interpreter/interpreterRuntime.cpp Wed Nov 17 22:42:08 2010 -0800
  1912. +++ b/src/share/vm/interpreter/interpreterRuntime.cpp Fri Dec 17 13:24:08 2010 +0100
  1913. @@ -366,7 +366,7 @@
  1914. assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
  1915. assert(h_exception->is_oop(), "just checking");
  1916. // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
  1917. - if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1918. + if (!(h_exception->is_a(SystemDictionary::Throwable_klass()->klass_part()->newest_version())) && !(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
  1919. if (ExitVMOnVerifyError) vm_exit(-1);
  1920. ShouldNotReachHere();
  1921. }
  1922. diff -r f5603a6e5042 src/share/vm/interpreter/linkResolver.cpp
  1923. --- a/src/share/vm/interpreter/linkResolver.cpp Wed Nov 17 22:42:08 2010 -0800
  1924. +++ b/src/share/vm/interpreter/linkResolver.cpp Fri Dec 17 13:24:08 2010 +0100
  1925. @@ -114,8 +114,8 @@
  1926. // Klass resolution
  1927. void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) {
  1928. - if (!Reflection::verify_class_access(ref_klass->as_klassOop(),
  1929. - sel_klass->as_klassOop(),
  1930. + if (!Reflection::verify_class_access(ref_klass->as_klassOop()->klass_part()->newest_version(),
  1931. + sel_klass->as_klassOop()->klass_part()->newest_version(),
  1932. true)) {
  1933. ResourceMark rm(THREAD);
  1934. Exceptions::fthrow(
  1935. @@ -227,7 +227,7 @@
  1936. // We'll check for the method name first, as that's most likely
  1937. // to be false (so we'll short-circuit out of these tests).
  1938. if (sel_method->name() == vmSymbols::clone_name() &&
  1939. - sel_klass() == SystemDictionary::Object_klass() &&
  1940. + sel_klass()->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version() &&
  1941. resolved_klass->oop_is_array()) {
  1942. // We need to change "protected" to "public".
  1943. assert(flags.is_protected(), "clone not protected?");
  1944. @@ -513,7 +513,7 @@
  1945. }
  1946. // Final fields can only be accessed from its own class.
  1947. - if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) {
  1948. + if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()->klass_part()->active_version() && sel_klass() != pool->pool_holder()) {
  1949. THROW(vmSymbols::java_lang_IllegalAccessError());
  1950. }
  1951. @@ -715,7 +715,7 @@
  1952. bool check_access, bool check_null_and_abstract, TRAPS) {
  1953. methodHandle resolved_method;
  1954. linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK);
  1955. - runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK);
  1956. + runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, current_klass, check_null_and_abstract, CHECK);
  1957. }
  1958. // throws linktime exceptions
  1959. @@ -744,6 +744,7 @@
  1960. KlassHandle resolved_klass,
  1961. Handle recv,
  1962. KlassHandle recv_klass,
  1963. + KlassHandle current_klass,
  1964. bool check_null_and_abstract,
  1965. TRAPS) {
  1966. @@ -792,7 +793,31 @@
  1967. // recv_klass might be an arrayKlassOop but all vtables start at
  1968. // the same place. The cast is to avoid virtual call and assertion.
  1969. instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part();
  1970. +
  1971. + // (tw) The type of the virtual method call and the type of the receiver do not need to
  1972. + // have anything in common, as the receiver type could've been hotswapped.
  1973. + // Does not always work (method could be resolved with correct dynamic type and later
  1974. + // be called at the same place with a wrong dynamic type).
  1975. + // (tw) TODO: Need to handle the static type vs dynamic type issue more generally.
  1976. +
  1977. + // The vTable must be based on the view of the world of the resolved method
  1978. + klassOop method_holder = resolved_method->method_holder();
  1979. +
  1980. + if (inst->is_subtype_of(method_holder)) {
  1981. selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index));
  1982. + } else {
  1983. +
  1984. + tty->print_cr("Failure:");
  1985. + inst->as_klassOop()->print();
  1986. + inst->super()->print();
  1987. + juint off = inst->super_check_offset();
  1988. + klassOop sup = *(klassOop*)( (address)inst->as_klassOop() + off );
  1989. + sup->print();
  1990. + method_holder->print();
  1991. +
  1992. + bool b = inst->is_subtype_of(method_holder);
  1993. + 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!");
  1994. + }
  1995. }
  1996. }
  1997. diff -r f5603a6e5042 src/share/vm/interpreter/linkResolver.hpp
  1998. --- a/src/share/vm/interpreter/linkResolver.hpp Wed Nov 17 22:42:08 2010 -0800
  1999. +++ b/src/share/vm/interpreter/linkResolver.hpp Fri Dec 17 13:24:08 2010 +0100
  2000. @@ -100,7 +100,11 @@
  2001. // It does all necessary link-time checks & throws exceptions if necessary.
  2002. class LinkResolver: AllStatic {
  2003. - private:
  2004. +private:
  2005. + static void lookup_method (methodHandle& result, KlassHandle resolved_klass, symbolHandle name, symbolHandle signature, bool is_interface, KlassHandle current_klass, TRAPS);
  2006. + 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);
  2007. + static void lookup_correct_method (methodHandle& result, KlassHandle resolved_klass, KlassHandle current_klass, symbolHandle name, symbolHandle signature, bool is_interface, TRAPS);
  2008. + static void find_correct_resolved_klass (KlassHandle &resolved_klass, KlassHandle &current_klass);
  2009. static void lookup_method_in_klasses (methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS);
  2010. static void lookup_instance_method_in_klasses (methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS);
  2011. static void lookup_method_in_interfaces (methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS);
  2012. @@ -123,7 +127,7 @@
  2013. 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);
  2014. static void runtime_resolve_special_method (CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, KlassHandle current_klass, bool check_access, TRAPS);
  2015. - 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);
  2016. + 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);
  2017. 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);
  2018. static void check_field_accessability (KlassHandle ref_klass, KlassHandle resolved_klass, KlassHandle sel_klass, fieldDescriptor& fd, TRAPS);
  2019. diff -r f5603a6e5042 src/share/vm/interpreter/oopMapCache.cpp
  2020. --- a/src/share/vm/interpreter/oopMapCache.cpp Wed Nov 17 22:42:08 2010 -0800
  2021. +++ b/src/share/vm/interpreter/oopMapCache.cpp Fri Dec 17 13:24:08 2010 +0100
  2022. @@ -530,9 +530,9 @@
  2023. if (!_array[i].is_empty() && _array[i].method()->is_old()) {
  2024. // Cache entry is occupied by an old redefined method and we don't want
  2025. // to pin it down so flush the entry.
  2026. - RC_TRACE(0x08000000, ("flush: %s(%s): cached entry @%d",
  2027. + TRACE_RC3("flush: %s(%s): cached entry @%d",
  2028. _array[i].method()->name()->as_C_string(),
  2029. - _array[i].method()->signature()->as_C_string(), i));
  2030. + _array[i].method()->signature()->as_C_string(), i);
  2031. _array[i].flush();
  2032. }
  2033. diff -r f5603a6e5042 src/share/vm/interpreter/templateTable.hpp
  2034. --- a/src/share/vm/interpreter/templateTable.hpp Wed Nov 17 22:42:08 2010 -0800
  2035. +++ b/src/share/vm/interpreter/templateTable.hpp Fri Dec 17 13:24:08 2010 +0100
  2036. @@ -303,8 +303,8 @@
  2037. static void shouldnotreachhere();
  2038. // jvmti support
  2039. - static void jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos);
  2040. - static void jvmti_post_field_mod(Register cache, Register index, bool is_static);
  2041. + static void jvmti_post_field_access(Register cache, Register index, int byte_no, bool is_static, bool has_tos);
  2042. + static void jvmti_post_field_mod(Register cache, Register index, int byte_no, bool is_static);
  2043. static void jvmti_post_fast_field_mod();
  2044. // debugging of TemplateGenerator
  2045. diff -r f5603a6e5042 src/share/vm/memory/genMarkSweep.cpp
  2046. --- a/src/share/vm/memory/genMarkSweep.cpp Wed Nov 17 22:42:08 2010 -0800
  2047. +++ b/src/share/vm/memory/genMarkSweep.cpp Fri Dec 17 13:24:08 2010 +0100
  2048. @@ -372,6 +372,7 @@
  2049. // in the same order in phase2, phase3 and phase4. We don't quite do that
  2050. // here (perm_gen first rather than last), so we tell the validate code
  2051. // to use a higher index (saved from phase2) when verifying perm_gen.
  2052. + assert(_rescued_oops == NULL, "must be empty before processing");
  2053. GenCollectedHeap* gch = GenCollectedHeap::heap();
  2054. Generation* pg = gch->perm_gen();
  2055. @@ -385,10 +386,14 @@
  2056. VALIDATE_MARK_SWEEP_ONLY(reset_live_oop_tracking(false));
  2057. + MarkSweep::copy_rescued_objects_back();
  2058. +
  2059. GenCompactClosure blk;
  2060. gch->generation_iterate(&blk, true);
  2061. VALIDATE_MARK_SWEEP_ONLY(compaction_complete());
  2062. + MarkSweep::copy_rescued_objects_back();
  2063. +
  2064. pg->post_compact(); // Shared spaces verification.
  2065. }
  2066. diff -r f5603a6e5042 src/share/vm/memory/permGen.cpp
  2067. --- a/src/share/vm/memory/permGen.cpp Wed Nov 17 22:42:08 2010 -0800
  2068. +++ b/src/share/vm/memory/permGen.cpp Fri Dec 17 13:24:08 2010 +0100
  2069. @@ -44,7 +44,12 @@
  2070. for (;;) {
  2071. {
  2072. - MutexLocker ml(Heap_lock);
  2073. + // (tw) Only lock when not at a safepoint (necessary to use the split verifier from the VmThread)
  2074. + Monitor *lock = Heap_lock;
  2075. + if (SafepointSynchronize::is_at_safepoint()) {
  2076. + lock = NULL;
  2077. + }
  2078. + MutexLockerEx ml(lock);
  2079. if ((obj = gen->allocate(size, false)) != NULL) {
  2080. return obj;
  2081. }
  2082. diff -r f5603a6e5042 src/share/vm/memory/space.cpp
  2083. --- a/src/share/vm/memory/space.cpp Wed Nov 17 22:42:08 2010 -0800
  2084. +++ b/src/share/vm/memory/space.cpp Fri Dec 17 13:24:08 2010 +0100
  2085. @@ -359,6 +359,31 @@
  2086. _compaction_top = bottom();
  2087. }
  2088. +// (tw) Calculates the compact_top that will be used for placing the next object with the giving size on the heap.
  2089. +HeapWord* CompactibleSpace::forward_compact_top(size_t size,
  2090. +CompactPoint* cp, HeapWord* compact_top) {
  2091. + // First check if we should switch compaction space
  2092. + assert(this == cp->space, "'this' should be current compaction space.");
  2093. + size_t compaction_max_size = pointer_delta(end(), compact_top);
  2094. + while (size > compaction_max_size) {
  2095. + // switch to next compaction space
  2096. + cp->space->set_compaction_top(compact_top);
  2097. + cp->space = cp->space->next_compaction_space();
  2098. + if (cp->space == NULL) {
  2099. + cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen);
  2100. + assert(cp->gen != NULL, "compaction must succeed");
  2101. + cp->space = cp->gen->first_compaction_space();
  2102. + assert(cp->space != NULL, "generation must have a first compaction space");
  2103. + }
  2104. + compact_top = cp->space->bottom();
  2105. + cp->space->set_compaction_top(compact_top);
  2106. + cp->threshold = cp->space->initialize_threshold();
  2107. + compaction_max_size = pointer_delta(cp->space->end(), compact_top);
  2108. + }
  2109. +
  2110. + return compact_top;
  2111. +}
  2112. +
  2113. HeapWord* CompactibleSpace::forward(oop q, size_t size,
  2114. CompactPoint* cp, HeapWord* compact_top) {
  2115. // q is alive
  2116. @@ -382,7 +407,7 @@
  2117. }
  2118. // store the forwarding pointer into the mark word
  2119. - if ((HeapWord*)q != compact_top) {
  2120. + if ((HeapWord*)q != compact_top || (size_t)q->size() != size) {
  2121. q->forward_to(oop(compact_top));
  2122. assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
  2123. } else {
  2124. @@ -430,7 +455,204 @@
  2125. // Faster object search.
  2126. void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
  2127. - SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2128. + if (!Universe::is_redefining_gc_run()) {
  2129. + SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size);
  2130. + return;
  2131. + }
  2132. +
  2133. + /* Compute the new addresses for the live objects and store it in the mark
  2134. + * Used by universe::mark_sweep_phase2()
  2135. + */
  2136. + HeapWord* compact_top; /* This is where we are currently compacting to. */
  2137. +
  2138. + /* We're sure to be here before any objects are compacted into this
  2139. + * space, so this is a good time to initialize this:
  2140. + */
  2141. + set_compaction_top(bottom());
  2142. +
  2143. + if (cp->space == NULL) {
  2144. + assert(cp->gen != NULL, "need a generation");
  2145. + assert(cp->threshold == NULL, "just checking");
  2146. + assert(cp->gen->first_compaction_space() == this, "just checking");
  2147. + cp->space = cp->gen->first_compaction_space();
  2148. + compact_top = cp->space->bottom();
  2149. + cp->space->set_compaction_top(compact_top);
  2150. + cp->threshold = cp->space->initialize_threshold();
  2151. + } else {
  2152. + compact_top = cp->space->compaction_top();
  2153. + }
  2154. +
  2155. + /* We allow some amount of garbage towards the bottom of the space, so
  2156. + * we don't start compacting before there is a significant gain to be made.
  2157. + * Occasionally, we want to ensure a full compaction, which is determined
  2158. + * by the MarkSweepAlwaysCompactCount parameter.
  2159. + */
  2160. + int invocations = SharedHeap::heap()->perm_gen()->stat_record()->invocations;
  2161. + bool skip_dead = ((invocations % MarkSweepAlwaysCompactCount) != 0);
  2162. +
  2163. + size_t allowed_deadspace = 0;
  2164. + if (skip_dead) {
  2165. + int ratio = (int)allowed_dead_ratio();
  2166. + allowed_deadspace = (capacity() * ratio / 100) / HeapWordSize;
  2167. + }
  2168. +
  2169. + HeapWord* q = bottom();
  2170. + HeapWord* t = end();
  2171. +
  2172. + HeapWord* end_of_live= q; /* One byte beyond the last byte of the last
  2173. + live object. */
  2174. + HeapWord* first_dead = end();/* The first dead object. */
  2175. + LiveRange* liveRange = NULL; /* The current live range, recorded in the
  2176. + first header of preceding free area. */
  2177. + _first_dead = first_dead;
  2178. +
  2179. + const intx interval = PrefetchScanIntervalInBytes;
  2180. +
  2181. + while (q < t) {
  2182. + assert(!block_is_obj(q) ||
  2183. + oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() ||
  2184. + oop(q)->mark()->has_bias_pattern(),
  2185. + "these are the only valid states during a mark sweep");
  2186. + if (block_is_obj(q) && oop(q)->is_gc_marked()) {
  2187. + /* prefetch beyond q */
  2188. + Prefetch::write(q, interval);
  2189. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2190. + size_t size = block_size(q);
  2191. +
  2192. + size_t forward_size = size;
  2193. +
  2194. + //////////////////////////////////////////////////////////////////////////
  2195. + // Compute the forward sizes and leave out objects whose position could
  2196. + // possibly overlap other objects.
  2197. +
  2198. + // (tw) There is a new version of the class of q => different size
  2199. + if (oop(q)->blueprint()->new_version() != NULL && oop(q)->blueprint()->new_version()->klass_part()->update_information() != NULL) {
  2200. +
  2201. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2202. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2203. + forward_size = new_size;
  2204. + }
  2205. +
  2206. + compact_top = cp->space->forward_compact_top(forward_size, cp, compact_top);
  2207. +
  2208. + bool rescueing = false;
  2209. + if (rescueing = must_rescue(oop(q), oop(compact_top))) {
  2210. + if (MarkSweep::_rescued_oops == NULL) {
  2211. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2212. + }
  2213. + TRACE_RC5("rescue obj %d klass=%s", MarkSweep::_rescued_oops->length(), oop(q)->klass()->klass_part()->name()->as_C_string());
  2214. + MarkSweep::_rescued_oops->append(oop(q));
  2215. + } else {
  2216. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2217. + }
  2218. +
  2219. + if ((size != forward_size || rescueing) && q < first_dead) {
  2220. + // (tw) This object moves => first_dead must be set to here!
  2221. + first_dead = q;
  2222. + }
  2223. + //////////////////////////////////////////////////////////////////////////
  2224. +
  2225. + end_of_live = q + size; //forward_size;
  2226. + q += size;
  2227. + } else {
  2228. + /* run over all the contiguous dead objects */
  2229. + HeapWord* end = q;
  2230. + do {
  2231. + /* prefetch beyond end */
  2232. + Prefetch::write(end, interval);
  2233. + end += block_size(end);
  2234. + } while (end < t && (!block_is_obj(end) || !oop(end)->is_gc_marked()));
  2235. +
  2236. + /* see if we might want to pretend this object is alive so that
  2237. + * we don't have to compact quite as often.
  2238. + */
  2239. + if (allowed_deadspace > 0 && q == compact_top) {
  2240. + size_t sz = pointer_delta(end, q);
  2241. + if (insert_deadspace(allowed_deadspace, q, sz)) {
  2242. + compact_top = cp->space->forward(oop(q), sz, cp, compact_top);
  2243. + q = end;
  2244. + end_of_live = end;
  2245. + continue;
  2246. + }
  2247. + }
  2248. +
  2249. + /* otherwise, it really is a free region. */
  2250. +
  2251. + /* for the previous LiveRange, record the end of the live objects. */
  2252. + if (liveRange) {
  2253. + liveRange->set_end(q);
  2254. + }
  2255. +
  2256. + /* record the current LiveRange object.
  2257. + * liveRange->start() is overlaid on the mark word.
  2258. + */
  2259. + liveRange = (LiveRange*)q;
  2260. + liveRange->set_start(end);
  2261. + liveRange->set_end(end);
  2262. +
  2263. + /* see if this is the first dead region. */
  2264. + if (q < first_dead) {
  2265. + first_dead = q;
  2266. + }
  2267. +
  2268. + /* move on to the next object */
  2269. + q = end;
  2270. + }
  2271. + }
  2272. +
  2273. + //////////////////////////////////////////////////////////////////////////
  2274. + // Compute the forwarding addresses for the objects that need to be
  2275. + // rescued.
  2276. + // TODO: empty the _rescued_oops after ALL spaces are compacted!
  2277. + if (MarkSweep::_rescued_oops != NULL) {
  2278. + TRACE_RC2("Calculating new forward sizes for %d objects!", MarkSweep::_rescued_oops->length());
  2279. +
  2280. + for (int i=0; i<MarkSweep::_rescued_oops->length(); i++) {
  2281. + oop q = MarkSweep::_rescued_oops->at(i);
  2282. +
  2283. + /* size_t size = oop(q)->size(); changing this for cms for perm gen */
  2284. + size_t size = block_size((HeapWord*)q);
  2285. +
  2286. + size_t forward_size = size;
  2287. +
  2288. + // (tw) There is a new version of the class of q => different size
  2289. + if (oop(q)->blueprint()->new_version() != NULL) {
  2290. +
  2291. + size_t new_size = oop(q)->size_given_klass(oop(q)->blueprint()->new_version()->klass_part());
  2292. + assert(size != new_size || oop(q)->is_perm(), "instances without changed size have to be updated prior to GC run");
  2293. + forward_size = new_size;
  2294. + }
  2295. +
  2296. + compact_top = cp->space->forward(oop(q), forward_size, cp, compact_top);
  2297. + assert(compact_top <= t, "must not write over end of space!");
  2298. + }
  2299. + MarkSweep::_rescued_oops->clear();
  2300. + MarkSweep::_rescued_oops = NULL;
  2301. + }
  2302. + //////////////////////////////////////////////////////////////////////////
  2303. +
  2304. + assert(q == t, "just checking");
  2305. + if (liveRange != NULL) {
  2306. + liveRange->set_end(q);
  2307. + }
  2308. + _end_of_live = end_of_live;
  2309. + if (end_of_live < first_dead) {
  2310. + first_dead = end_of_live;
  2311. + }
  2312. + _first_dead = first_dead;
  2313. +
  2314. + if (_first_dead > top()) {
  2315. + _first_dead = top();
  2316. + }
  2317. +
  2318. + if (_end_of_live > top()) {
  2319. + _end_of_live = top();
  2320. + }
  2321. + assert(_first_dead <= top(), "Must be smaller equal");
  2322. + assert(_end_of_live <= top(), "Must be smaller equal");
  2323. +
  2324. + /* save the compaction_top of the compaction space. */
  2325. + cp->space->set_compaction_top(compact_top);
  2326. }
  2327. void Space::adjust_pointers() {
  2328. @@ -471,17 +693,322 @@
  2329. assert(q == t, "just checking");
  2330. }
  2331. +
  2332. +#ifdef ASSERT
  2333. +
  2334. +int CompactibleSpace::space_index(oop obj) {
  2335. + GenCollectedHeap* heap = GenCollectedHeap::heap();
  2336. +
  2337. + if (heap->is_in_permanent(obj)) {
  2338. + return -1;
  2339. + }
  2340. +
  2341. + int index = 0;
  2342. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2343. + Generation* gen = heap->get_gen(i);
  2344. + CompactibleSpace* space = gen->first_compaction_space();
  2345. + while (space != NULL) {
  2346. + if (space->is_in_reserved(obj)) {
  2347. + return index;
  2348. + }
  2349. + space = space->next_compaction_space();
  2350. + index++;
  2351. + }
  2352. + }
  2353. +
  2354. + tty->print_cr("could not compute space_index for %08xh", obj);
  2355. + index = 0;
  2356. + for (int i = heap->n_gens() - 1; i >= 0; i--) {
  2357. + Generation* gen = heap->get_gen(i);
  2358. + tty->print_cr(" generation %s: %08xh - %08xh", gen->name(), gen->reserved().start(), gen->reserved().end());
  2359. +
  2360. + CompactibleSpace* space = gen->first_compaction_space();
  2361. + while (space != NULL) {
  2362. + tty->print_cr(" %2d space %08xh - %08xh", index, space->bottom(), space->end());
  2363. + space = space->next_compaction_space();
  2364. + index++;
  2365. + }
  2366. + }
  2367. +
  2368. + ShouldNotReachHere();
  2369. + return 0;
  2370. +}
  2371. +#endif
  2372. +
  2373. +bool CompactibleSpace::must_rescue(oop old_obj, oop new_obj) {
  2374. +
  2375. + assert(is_in_reserved(old_obj), "old_obj must be in this space");
  2376. +
  2377. + if (old_obj->is_perm()) {
  2378. + // This object is in perm gen; check for invariant obj->klass() <= obj
  2379. + if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2380. + return true;
  2381. + }
  2382. + }
  2383. +
  2384. + int size = old_obj->size();
  2385. + int original_size = size;
  2386. + if (oop(old_obj)->blueprint()->is_redefining()) {
  2387. + assert(oop(old_obj)->blueprint()->old_version() != NULL, "must not be null");
  2388. + original_size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->old_version()->klass_part());
  2389. + } else if (oop(old_obj)->blueprint()->new_version() != NULL) {
  2390. + size = oop(old_obj)->size_given_klass(oop(old_obj)->blueprint()->new_version()->klass_part());
  2391. + }
  2392. +
  2393. + bool normalComparison = (old_obj + original_size < new_obj + size);
  2394. +
  2395. + if (is_in_reserved(new_obj)) {
  2396. + // Old and new address are in same space, so just compare the address.
  2397. + // Must rescue if object moves towards the top of the space.
  2398. + assert(space_index(old_obj) == space_index(new_obj), "old_obj and new_obj must be in same space");
  2399. + return normalComparison;
  2400. +
  2401. + } else {
  2402. +
  2403. + assert(space_index(old_obj) != space_index(new_obj), "old_obj and new_obj must be in different spaces");
  2404. +
  2405. + Generation* tenured_gen = GenCollectedHeap::heap()->get_gen(1);
  2406. + if (tenured_gen->is_in_reserved(new_obj)) {
  2407. + // Must never rescue when moving from the new into the old generation.
  2408. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2409. + assert(space_index(old_obj) > space_index(new_obj), "must be");
  2410. + return false;
  2411. +
  2412. + } else if (tenured_gen->is_in_reserved(old_obj)) {
  2413. + // Must always rescue when moving from the old into the new generation.
  2414. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2415. + assert(space_index(old_obj) < space_index(new_obj), "must be");
  2416. + return true;
  2417. +
  2418. + } else {
  2419. + // In the new generation, eden is located before the from space, so a
  2420. + // simple pointer comparison is sufficient.
  2421. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(old_obj), "old_obj must be in DefNewGeneration");
  2422. + assert(GenCollectedHeap::heap()->get_gen(0)->is_in_reserved(new_obj), "new_obj must be in DefNewGeneration");
  2423. + assert((normalComparison) == (space_index(old_obj) < space_index(new_obj)), "slow and fast computation must yield same result");
  2424. + return normalComparison;
  2425. + }
  2426. + }
  2427. +}
  2428. +
  2429. +oop CompactibleSpace::rescue(oop old_obj) {
  2430. + assert(must_rescue(old_obj, old_obj->forwardee()), "do not call otherwise");
  2431. +
  2432. + int size = old_obj->size();
  2433. + oop rescued_obj = (oop)resource_allocate_bytes(size * HeapWordSize);
  2434. + Copy::aligned_disjoint_words((HeapWord*)old_obj, (HeapWord*)rescued_obj, size);
  2435. +
  2436. + if (MarkSweep::_rescued_oops == NULL) {
  2437. + MarkSweep::_rescued_oops = new GrowableArray<oop>(128);
  2438. + }
  2439. +
  2440. + MarkSweep::_rescued_oops->append(rescued_obj);
  2441. + return rescued_obj;
  2442. +}
  2443. +
  2444. void CompactibleSpace::adjust_pointers() {
  2445. // Check first is there is any work to do.
  2446. if (used() == 0) {
  2447. return; // Nothing to do.
  2448. }
  2449. + /* adjust all the interior pointers to point at the new locations of objects
  2450. + * Used by MarkSweep::mark_sweep_phase3() */
  2451. - SCAN_AND_ADJUST_POINTERS(adjust_obj_size);
  2452. + HeapWord* q = bottom();
  2453. + HeapWord* t = _end_of_live; /* Established by "prepare_for_compaction". */
  2454. +
  2455. + assert(_first_dead <= _end_of_live, "Stands to reason, no?");
  2456. +
  2457. + debug_only(HeapWord* prev_q = NULL);
  2458. + debug_only(HeapWord* prev_prev_q = NULL);
  2459. + debug_only(HeapWord* prev_prev_prev_q = NULL);
  2460. + if (q < t && _first_dead > q &&
  2461. + !oop(q)->is_gc_marked()) {
  2462. + /* we have a chunk of the space which hasn't moved and we've
  2463. + * reinitialized the mark word during the previous pass, so we can't
  2464. + * use is_gc_marked for the traversal. */
  2465. + HeapWord* end = _first_dead;
  2466. +
  2467. + while (q < end) {
  2468. + /* I originally tried to conjoin "block_start(q) == q" to the
  2469. + * assertion below, but that doesn't work, because you can't
  2470. + * accurately traverse previous objects to get to the current one
  2471. + * after their pointers (including pointers into permGen) have been
  2472. + * updated, until the actual compaction is done. dld, 4/00 */
  2473. + assert(block_is_obj(q),
  2474. + "should be at block boundaries, and should be looking at objs");
  2475. +
  2476. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2477. +
  2478. + /* point all the oops to the new location */
  2479. + size_t size = oop(q)->adjust_pointers();
  2480. + size = adjust_obj_size(size);
  2481. +
  2482. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2483. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2484. +
  2485. + debug_only(prev_prev_prev_q = prev_prev_q);
  2486. + debug_only(prev_prev_q = prev_q);
  2487. + debug_only(prev_q = q);
  2488. + q += size;
  2489. + }
  2490. +
  2491. + // (tw) first_dead can be live object!
  2492. + q = _first_dead;
  2493. +
  2494. +// if (_first_dead == t) {
  2495. +// q = t;
  2496. +// } else {
  2497. +// /* $$$ This is funky. Using this to read the previously written
  2498. +// * LiveRange. See also use below. */
  2499. +// q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer();
  2500. +// }
  2501. + }
  2502. +
  2503. + const intx interval = PrefetchScanIntervalInBytes;
  2504. +
  2505. + debug_only(prev_q = NULL);
  2506. + debug_only(prev_prev_q = NULL);
  2507. + debug_only(prev_prev_prev_q = NULL);
  2508. + while (q < t) {
  2509. + /* prefetch beyond q */
  2510. + Prefetch::write(q, interval);
  2511. + if (oop(q)->is_gc_marked()) {
  2512. + /* q is alive */
  2513. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q)));
  2514. + /* point all the oops to the new location */
  2515. + size_t size = oop(q)->adjust_pointers();
  2516. + size = adjust_obj_size(size);
  2517. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers());
  2518. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size));
  2519. + debug_only(prev_prev_prev_q = prev_prev_q);
  2520. + debug_only(prev_prev_q = prev_q);
  2521. + debug_only(prev_q = q);
  2522. + q += size;
  2523. + } else {
  2524. + /* q is not a live object, so its mark should point at the next
  2525. + * live object */
  2526. + debug_only(prev_prev_prev_q = prev_prev_q);
  2527. + debug_only(prev_prev_q = prev_q);
  2528. + debug_only(prev_q = q);
  2529. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2530. + assert(q > prev_q, "we should be moving forward through memory");
  2531. + }
  2532. + }
  2533. +
  2534. + assert(q == t, "just checking");
  2535. }
  2536. void CompactibleSpace::compact() {
  2537. - SCAN_AND_COMPACT(obj_size);
  2538. +
  2539. + if(!Universe::is_redefining_gc_run()) {
  2540. + SCAN_AND_COMPACT(obj_size);
  2541. + return;
  2542. + }
  2543. +
  2544. + /* Copy all live objects to their new location
  2545. + * Used by MarkSweep::mark_sweep_phase4() */
  2546. +
  2547. + HeapWord* q = bottom();
  2548. + HeapWord* const t = _end_of_live;
  2549. + debug_only(HeapWord* prev_q = NULL);
  2550. + debug_only(HeapWord* prev_prev_q = NULL);
  2551. + debug_only(HeapWord* prev_compaction_top = NULL);
  2552. + debug_only(int old_size = 0);
  2553. +
  2554. + if (q < t && _first_dead > q &&
  2555. + !oop(q)->is_gc_marked()) {
  2556. + /* we have a chunk of the space which hasn't moved and we've reinitialized
  2557. + * the mark word during the previous pass, so we can't use is_gc_marked for
  2558. + * the traversal. */
  2559. + HeapWord* const end = _first_dead;
  2560. +
  2561. +#ifdef ASSERT
  2562. + while (q < end) {
  2563. + size_t size = oop(q)->size();
  2564. + assert(!oop(q)->is_gc_marked(),
  2565. + "should be unmarked (special dense prefix handling)");
  2566. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, q));
  2567. + debug_only(prev_prev_q = prev_q);
  2568. + debug_only(prev_q = q);
  2569. + q += size;
  2570. + }
  2571. +#endif
  2572. + // (tw) first_dead can be live object!
  2573. + q = _first_dead;
  2574. +
  2575. + //if (_first_dead == t) {
  2576. + // q = t;
  2577. + //} else {
  2578. + ///* $$$ Funky */
  2579. + //q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer();
  2580. + //}
  2581. + }
  2582. +
  2583. + const intx scan_interval = PrefetchScanIntervalInBytes;
  2584. + const intx copy_interval = PrefetchCopyIntervalInBytes;
  2585. + while (q < t) {
  2586. + if (!oop(q)->is_gc_marked()) {
  2587. + /* mark is pointer to next marked oop */
  2588. + debug_only(prev_prev_q = prev_q);
  2589. + debug_only(prev_q = q);
  2590. + q = (HeapWord*) oop(q)->mark()->decode_pointer();
  2591. + assert(q > prev_q, "we should be moving forward through memory");
  2592. + } else {
  2593. + /* prefetch beyond q */
  2594. + Prefetch::read(q, scan_interval);
  2595. +
  2596. + /* size and destination */
  2597. + size_t size = obj_size(q);
  2598. + HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee();
  2599. +
  2600. + size_t original_size = size;
  2601. +
  2602. + if (must_rescue(oop(q), oop(q)->forwardee())) {
  2603. + oop dest_obj = rescue(oop(q));
  2604. + debug_only(Copy::fill_to_words(q, original_size, 0));
  2605. + } else {
  2606. +
  2607. + /* prefetch beyond compaction_top */
  2608. + Prefetch::write(compaction_top, copy_interval);
  2609. +
  2610. + /* copy object and reinit its mark */
  2611. + VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size,
  2612. + compaction_top));
  2613. + assert(q != compaction_top || oop(q)->blueprint()->new_version() != NULL, "everything in this pass should be moving");
  2614. +
  2615. + if (oop(q)->blueprint()->new_version() != NULL) {
  2616. + MarkSweep::update_fields(oop(q), oop(compaction_top));
  2617. + } else {
  2618. + Copy::aligned_conjoint_words(q, compaction_top, size);
  2619. + }
  2620. + oop(compaction_top)->init_mark();
  2621. + assert(oop(compaction_top)->klass() != NULL, "should have a class");
  2622. + }
  2623. +
  2624. + debug_only(prev_compaction_top = compaction_top);
  2625. + debug_only(prev_prev_q = prev_q);
  2626. + debug_only(prev_q = q);
  2627. + debug_only(old_size = (int)size);
  2628. + q += original_size;
  2629. + }
  2630. + }
  2631. +
  2632. + /* Reset space after compaction is complete */
  2633. + reset_after_compaction();
  2634. + /* We do this clear, below, since it has overloaded meanings for some */
  2635. + /* space subtypes. For example, OffsetTableContigSpace's that were */
  2636. + /* compacted into will have had their offset table thresholds updated */
  2637. + /* continuously, but those that weren't need to have their thresholds */
  2638. + /* re-initialized. Also mangles unused area for debugging. */
  2639. + if (is_empty()) {
  2640. + clear(SpaceDecorator::Mangle);
  2641. + } else {
  2642. + if (ZapUnusedHeapArea) mangle_unused_area();
  2643. + }
  2644. +
  2645. +
  2646. + //SCAN_AND_COMPACT(obj_size);
  2647. }
  2648. void Space::print_short() const { print_short_on(tty); }
  2649. diff -r f5603a6e5042 src/share/vm/memory/space.hpp
  2650. --- a/src/share/vm/memory/space.hpp Wed Nov 17 22:42:08 2010 -0800
  2651. +++ b/src/share/vm/memory/space.hpp Fri Dec 17 13:24:08 2010 +0100
  2652. @@ -419,6 +419,9 @@
  2653. // indicates when the next such action should be taken.
  2654. virtual void prepare_for_compaction(CompactPoint* cp);
  2655. // MarkSweep support phase3
  2656. + DEBUG_ONLY(int space_index(oop obj));
  2657. + bool must_rescue(oop old_obj, oop new_obj);
  2658. + oop rescue(oop old_obj);
  2659. virtual void adjust_pointers();
  2660. // MarkSweep support phase4
  2661. virtual void compact();
  2662. @@ -449,6 +452,10 @@
  2663. virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp,
  2664. HeapWord* compact_top);
  2665. + // (tw)
  2666. + virtual HeapWord* forward_compact_top(size_t size, CompactPoint* cp,
  2667. + HeapWord* compact_top);
  2668. +
  2669. // Return a size with adjusments as required of the space.
  2670. virtual size_t adjust_object_size_v(size_t size) const { return size; }
  2671. diff -r f5603a6e5042 src/share/vm/memory/universe.cpp
  2672. --- a/src/share/vm/memory/universe.cpp Wed Nov 17 22:42:08 2010 -0800
  2673. +++ b/src/share/vm/memory/universe.cpp Fri Dec 17 13:24:08 2010 +0100
  2674. @@ -25,6 +25,8 @@
  2675. # include "incls/_precompiled.incl"
  2676. # include "incls/_universe.cpp.incl"
  2677. +bool Universe::_is_redefining_gc_run = false;
  2678. +
  2679. // Known objects
  2680. klassOop Universe::_boolArrayKlassObj = NULL;
  2681. klassOop Universe::_byteArrayKlassObj = NULL;
  2682. @@ -131,6 +133,43 @@
  2683. f(systemObjArrayKlassObj());
  2684. }
  2685. +// (tw) This method should iterate all pointers that are not within heap objects.
  2686. +void Universe::root_oops_do(OopClosure *oopClosure) {
  2687. +
  2688. + class AlwaysTrueClosure: public BoolObjectClosure {
  2689. + public:
  2690. + void do_object(oop p) { ShouldNotReachHere(); }
  2691. + bool do_object_b(oop p) { return true; }
  2692. + };
  2693. + AlwaysTrueClosure always_true;
  2694. +
  2695. + Universe::oops_do(oopClosure);
  2696. + ReferenceProcessor::oops_do(oopClosure);
  2697. + JNIHandles::oops_do(oopClosure); // Global (strong) JNI handles
  2698. + Threads::oops_do(oopClosure, NULL);
  2699. + ObjectSynchronizer::oops_do(oopClosure);
  2700. + FlatProfiler::oops_do(oopClosure);
  2701. + JvmtiExport::oops_do(oopClosure);
  2702. + // SO_AllClasses
  2703. + SystemDictionary::oops_do(oopClosure);
  2704. + vmSymbols::oops_do(oopClosure);
  2705. +
  2706. + // Now adjust pointers in remaining weak roots. (All of which should
  2707. + // have been cleared if they pointed to non-surviving objects.)
  2708. + // Global (weak) JNI handles
  2709. + JNIHandles::weak_oops_do(&always_true, oopClosure);
  2710. +
  2711. + CodeCache::oops_do(oopClosure);
  2712. + SymbolTable::oops_do(oopClosure);
  2713. + StringTable::oops_do(oopClosure);
  2714. +
  2715. + // (tw) TODO: Check if this is correct?
  2716. + //CodeCache::scavenge_root_nmethods_oops_do(oopClosure);
  2717. + //Management::oops_do(oopClosure);
  2718. + //ref_processor()->weak_oops_do(&oopClosure);
  2719. + //PSScavenge::reference_processor()->weak_oops_do(&oopClosure);
  2720. +}
  2721. +
  2722. void Universe::oops_do(OopClosure* f, bool do_all) {
  2723. f->do_oop((oop*) &_int_mirror);
  2724. @@ -1424,10 +1463,9 @@
  2725. }
  2726. // RC_TRACE macro has an embedded ResourceMark
  2727. - RC_TRACE(0x00000100,
  2728. - ("add: %s(%s): adding prev version ref for cached method @%d",
  2729. + TRACE_RC2("add: %s(%s): adding prev version ref for cached method @%d",
  2730. method->name()->as_C_string(), method->signature()->as_C_string(),
  2731. - _prev_methods->length()));
  2732. + _prev_methods->length());
  2733. methodHandle method_h(method);
  2734. jweak method_ref = JNIHandles::make_weak_global(method_h);
  2735. @@ -1454,9 +1492,8 @@
  2736. JNIHandles::destroy_weak_global(method_ref);
  2737. _prev_methods->remove_at(i);
  2738. } else {
  2739. - // RC_TRACE macro has an embedded ResourceMark
  2740. - RC_TRACE(0x00000400, ("add: %s(%s): previous cached method @%d is alive",
  2741. - m->name()->as_C_string(), m->signature()->as_C_string(), i));
  2742. + TRACE_RC2("add: %s(%s): previous cached method @%d is alive",
  2743. + m->name()->as_C_string(), m->signature()->as_C_string(), i);
  2744. }
  2745. }
  2746. } // end add_previous_version()
  2747. diff -r f5603a6e5042 src/share/vm/memory/universe.hpp
  2748. --- a/src/share/vm/memory/universe.hpp Wed Nov 17 22:42:08 2010 -0800
  2749. +++ b/src/share/vm/memory/universe.hpp Fri Dec 17 13:24:08 2010 +0100
  2750. @@ -113,6 +113,8 @@
  2751. friend class SystemDictionary;
  2752. friend class VMStructs;
  2753. friend class CompactingPermGenGen;
  2754. + friend class Space;
  2755. + friend class ContiguousSpace;
  2756. friend class VM_PopulateDumpSharedSpace;
  2757. friend jint universe_init();
  2758. @@ -246,7 +248,18 @@
  2759. static void compute_verify_oop_data();
  2760. + static bool _is_redefining_gc_run;
  2761. +
  2762. public:
  2763. +
  2764. + static bool is_redefining_gc_run() {
  2765. + return _is_redefining_gc_run;
  2766. + }
  2767. +
  2768. + static void set_redefining_gc_run(bool b) {
  2769. + _is_redefining_gc_run = b;
  2770. + }
  2771. +
  2772. // Known classes in the VM
  2773. static klassOop boolArrayKlassObj() { return _boolArrayKlassObj; }
  2774. static klassOop byteArrayKlassObj() { return _byteArrayKlassObj; }
  2775. @@ -388,6 +401,8 @@
  2776. // Iteration
  2777. + static void root_oops_do(OopClosure *f);
  2778. +
  2779. // Apply "f" to the addresses of all the direct heap pointers maintained
  2780. // as static fields of "Universe".
  2781. static void oops_do(OopClosure* f, bool do_all = false);
  2782. @@ -404,6 +419,7 @@
  2783. // Debugging
  2784. static bool verify_in_progress() { return _verify_in_progress; }
  2785. + static void set_verify_in_progress(bool b) { _verify_in_progress = b; }
  2786. static void verify(bool allow_dirty = true, bool silent = false, bool option = true);
  2787. static int verify_count() { return _verify_count; }
  2788. static void print();
  2789. diff -r f5603a6e5042 src/share/vm/oops/arrayKlass.cpp
  2790. --- a/src/share/vm/oops/arrayKlass.cpp Wed Nov 17 22:42:08 2010 -0800
  2791. +++ b/src/share/vm/oops/arrayKlass.cpp Fri Dec 17 13:24:08 2010 +0100
  2792. @@ -117,9 +117,9 @@
  2793. bool arrayKlass::compute_is_subtype_of(klassOop k) {
  2794. // An array is a subtype of Serializable, Clonable, and Object
  2795. - return k == SystemDictionary::Object_klass()
  2796. - || k == SystemDictionary::Cloneable_klass()
  2797. - || k == SystemDictionary::Serializable_klass();
  2798. + return k->klass_part()->newest_version() == SystemDictionary::Object_klass()->klass_part()->newest_version()
  2799. + || k->klass_part()->newest_version() == SystemDictionary::Cloneable_klass()->klass_part()->newest_version()
  2800. + || k->klass_part()->newest_version() == SystemDictionary::Serializable_klass()->klass_part()->newest_version();
  2801. }
  2802. diff -r f5603a6e5042 src/share/vm/oops/cpCacheOop.cpp
  2803. --- a/src/share/vm/oops/cpCacheOop.cpp Wed Nov 17 22:42:08 2010 -0800
  2804. +++ b/src/share/vm/oops/cpCacheOop.cpp Fri Dec 17 13:24:08 2010 +0100
  2805. @@ -28,9 +28,15 @@
  2806. // Implememtation of ConstantPoolCacheEntry
  2807. +void ConstantPoolCacheEntry::copy_from(ConstantPoolCacheEntry *other) {
  2808. + _flags = other->_flags; // flags
  2809. +}
  2810. +
  2811. void ConstantPoolCacheEntry::initialize_entry(int index) {
  2812. assert(0 < index && index < 0x10000, "sanity check");
  2813. _indices = index;
  2814. + _f1 = NULL;
  2815. + _f2 = 0;
  2816. assert(constant_pool_index() == index, "");
  2817. }
  2818. @@ -149,7 +155,8 @@
  2819. int vtable_index) {
  2820. assert(!is_secondary_entry(), "");
  2821. assert(method->interpreter_entry() != NULL, "should have been set at this point");
  2822. - assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2823. + // (tw) No longer valid assert
  2824. + //assert(!method->is_obsolete(), "attempt to write obsolete method to cpCache");
  2825. bool change_to_virtual = (invoke_code == Bytecodes::_invokeinterface);
  2826. int byte_no = -1;
  2827. @@ -163,6 +170,9 @@
  2828. } else {
  2829. assert(vtable_index >= 0, "valid index");
  2830. set_f2(vtable_index);
  2831. +
  2832. + // (tw) save method holder in f1 for virtual calls
  2833. + set_f1(method());
  2834. }
  2835. byte_no = 2;
  2836. break;
  2837. @@ -376,26 +386,13 @@
  2838. // If this constantPoolCacheEntry refers to old_method then update it
  2839. // to refer to new_method.
  2840. bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
  2841. - methodOop new_method, bool * trace_name_printed) {
  2842. + methodOop new_method) {
  2843. if (is_vfinal()) {
  2844. +
  2845. // virtual and final so f2() contains method ptr instead of vtable index
  2846. - if (f2() == (intptr_t)old_method) {
  2847. - // match old_method so need an update
  2848. - _f2 = (intptr_t)new_method;
  2849. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  2850. - if (!(*trace_name_printed)) {
  2851. - // RC_TRACE_MESG macro has an embedded ResourceMark
  2852. - RC_TRACE_MESG(("adjust: name=%s",
  2853. - Klass::cast(old_method->method_holder())->external_name()));
  2854. - *trace_name_printed = true;
  2855. - }
  2856. - // RC_TRACE macro has an embedded ResourceMark
  2857. - RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
  2858. - new_method->name()->as_C_string(),
  2859. - new_method->signature()->as_C_string()));
  2860. - }
  2861. -
  2862. + if((methodOop)f2() != NULL && ((methodOop)f2())->method_holder()->klass_part()->new_version()) {
  2863. + initialize_entry(constant_pool_index());
  2864. return true;
  2865. }
  2866. @@ -403,65 +400,28 @@
  2867. return false;
  2868. }
  2869. - if ((oop)_f1 == NULL) {
  2870. - // NULL f1() means this is a virtual entry so bail out
  2871. - // We are assuming that the vtable index does not need change.
  2872. + // (tw) check how to update interface methods!
  2873. + if (bytecode_1() == Bytecodes::_invokevirtual || bytecode_2() == Bytecodes::_invokevirtual) {
  2874. +
  2875. + if(((methodOop)f1())->method_holder()->klass_part()->new_version()) {
  2876. + initialize_entry(constant_pool_index());
  2877. + return true;
  2878. + }
  2879. +
  2880. return false;
  2881. }
  2882. if ((oop)_f1 == old_method) {
  2883. _f1 = new_method;
  2884. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  2885. - if (!(*trace_name_printed)) {
  2886. - // RC_TRACE_MESG macro has an embedded ResourceMark
  2887. - RC_TRACE_MESG(("adjust: name=%s",
  2888. - Klass::cast(old_method->method_holder())->external_name()));
  2889. - *trace_name_printed = true;
  2890. - }
  2891. - // RC_TRACE macro has an embedded ResourceMark
  2892. - RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
  2893. - new_method->name()->as_C_string(),
  2894. - new_method->signature()->as_C_string()));
  2895. - }
  2896. -
  2897. + return true;
  2898. + } else if(_f1 != NULL && (bytecode_1() != Bytecodes::_invokeinterface && ((methodOop)f1())->method_holder()->klass_part()->new_version())) {
  2899. + initialize_entry(constant_pool_index());
  2900. return true;
  2901. }
  2902. return false;
  2903. }
  2904. -bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
  2905. - if (!is_method_entry()) {
  2906. - // not a method entry so not interesting by default
  2907. - return false;
  2908. - }
  2909. -
  2910. - methodOop m = NULL;
  2911. - if (is_vfinal()) {
  2912. - // virtual and final so _f2 contains method ptr instead of vtable index
  2913. - m = (methodOop)_f2;
  2914. - } else if ((oop)_f1 == NULL) {
  2915. - // NULL _f1 means this is a virtual entry so also not interesting
  2916. - return false;
  2917. - } else {
  2918. - if (!((oop)_f1)->is_method()) {
  2919. - // _f1 can also contain a klassOop for an interface
  2920. - return false;
  2921. - }
  2922. - m = (methodOop)_f1;
  2923. - }
  2924. -
  2925. - assert(m != NULL && m->is_method(), "sanity check");
  2926. - if (m == NULL || !m->is_method() || m->method_holder() != k) {
  2927. - // robustness for above sanity checks or method is not in
  2928. - // the interesting class
  2929. - return false;
  2930. - }
  2931. -
  2932. - // the method is in the interesting class so the entry is interesting
  2933. - return true;
  2934. -}
  2935. -
  2936. void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
  2937. // print separator
  2938. if (index == 0) tty->print_cr(" -------------");
  2939. @@ -502,38 +462,18 @@
  2940. // RedefineClasses() API support:
  2941. // If any entry of this constantPoolCache points to any of
  2942. // old_methods, replace it with the corresponding new_method.
  2943. -void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  2944. - int methods_length, bool * trace_name_printed) {
  2945. -
  2946. - if (methods_length == 0) {
  2947. - // nothing to do if there are no methods
  2948. - return;
  2949. - }
  2950. -
  2951. - // get shorthand for the interesting class
  2952. - klassOop old_holder = old_methods[0]->method_holder();
  2953. +void constantPoolCacheOopDesc::adjust_entries(methodOop* old_methods, methodOop* new_methods,
  2954. + int methods_length) {
  2955. for (int i = 0; i < length(); i++) {
  2956. - if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
  2957. - // skip uninteresting methods
  2958. - continue;
  2959. - }
  2960. + if (entry_at(i)->is_field_entry()) {
  2961. - // The constantPoolCache contains entries for several different
  2962. - // things, but we only care about methods. In fact, we only care
  2963. - // about methods in the same class as the one that contains the
  2964. - // old_methods. At this point, we have an interesting entry.
  2965. -
  2966. - for (int j = 0; j < methods_length; j++) {
  2967. - methodOop old_method = old_methods[j];
  2968. - methodOop new_method = new_methods[j];
  2969. -
  2970. - if (entry_at(i)->adjust_method_entry(old_method, new_method,
  2971. - trace_name_printed)) {
  2972. - // current old_method matched this entry and we updated it so
  2973. - // break out and get to the next interesting entry if there one
  2974. - break;
  2975. - }
  2976. + // (tw) TODO: Update only field offsets and modify only constant pool entries that
  2977. + // point to changed fields
  2978. + entry_at(i)->initialize_entry(entry_at(i)->constant_pool_index());
  2979. +
  2980. + } else if(entry_at(i)->is_method_entry()) {
  2981. + entry_at(i)->adjust_method_entry(NULL, NULL);
  2982. }
  2983. }
  2984. }
  2985. diff -r f5603a6e5042 src/share/vm/oops/cpCacheOop.hpp
  2986. --- a/src/share/vm/oops/cpCacheOop.hpp Wed Nov 17 22:42:08 2010 -0800
  2987. +++ b/src/share/vm/oops/cpCacheOop.hpp Fri Dec 17 13:24:08 2010 +0100
  2988. @@ -127,11 +127,15 @@
  2989. void set_bytecode_2(Bytecodes::Code code);
  2990. void set_f1(oop f1) {
  2991. oop existing_f1 = _f1; // read once
  2992. - assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  2993. + // (tw) need to relax assertion for redefinition
  2994. + // assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
  2995. oop_store(&_f1, f1);
  2996. }
  2997. void set_f1_if_null_atomic(oop f1);
  2998. - void set_f2(intx f2) { assert(_f2 == 0 || _f2 == f2, "illegal field change"); _f2 = f2; }
  2999. + void set_f2(intx f2) {
  3000. + // (tw) need to relax assertion for redefinition
  3001. + // assert(_f2 == 0 || _f2 == f2, "illegal field change");
  3002. + _f2 = f2; }
  3003. int as_flags(TosState state, bool is_final, bool is_vfinal, bool is_volatile,
  3004. bool is_method_interface, bool is_method);
  3005. void set_flags(intx flags) { _flags = flags; }
  3006. @@ -159,6 +163,8 @@
  3007. void initialize_entry(int original_index); // initialize primary entry
  3008. void initialize_secondary_entry(int main_index); // initialize secondary entry
  3009. + void copy_from(ConstantPoolCacheEntry *other);
  3010. +
  3011. void set_field( // sets entry to resolved field state
  3012. Bytecodes::Code get_code, // the bytecode used for reading the field
  3013. Bytecodes::Code put_code, // the bytecode used for writing the field
  3014. @@ -287,9 +293,7 @@
  3015. // trace_name_printed is set to true if the current call has
  3016. // printed the klass name so that other routines in the adjust_*
  3017. // group don't print the klass name.
  3018. - bool adjust_method_entry(methodOop old_method, methodOop new_method,
  3019. - bool * trace_name_printed);
  3020. - bool is_interesting_method_entry(klassOop k);
  3021. + bool adjust_method_entry(methodOop old_method, methodOop new_method);
  3022. bool is_field_entry() const { return (_flags & (1 << hotSwapBit)) == 0; }
  3023. bool is_method_entry() const { return (_flags & (1 << hotSwapBit)) != 0; }
  3024. @@ -397,12 +401,7 @@
  3025. return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
  3026. }
  3027. - // RedefineClasses() API support:
  3028. - // If any entry of this constantPoolCache points to any of
  3029. - // old_methods, replace it with the corresponding new_method.
  3030. - // trace_name_printed is set to true if the current call has
  3031. - // printed the klass name so that other routines in the adjust_*
  3032. - // group don't print the klass name.
  3033. - void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
  3034. - int methods_length, bool * trace_name_printed);
  3035. + // (tw) Update method and field references
  3036. + void adjust_entries(methodOop* old_methods, methodOop* new_methods,
  3037. + int methods_length);
  3038. };
  3039. diff -r f5603a6e5042 src/share/vm/oops/instanceKlass.cpp
  3040. --- a/src/share/vm/oops/instanceKlass.cpp Wed Nov 17 22:42:08 2010 -0800
  3041. +++ b/src/share/vm/oops/instanceKlass.cpp Fri Dec 17 13:24:08 2010 +0100
  3042. @@ -157,12 +157,116 @@
  3043. }
  3044. +void instanceKlass::initialize_redefined_class() {
  3045. +
  3046. + TRACE_RC3("initializing redefined class %s", name()->as_C_string());
  3047. +
  3048. + assert(!is_initialized(), "");
  3049. + assert(this->old_version() != NULL, "");
  3050. + assert(is_linked(), "must be linked before");
  3051. +
  3052. +
  3053. + instanceKlassHandle this_oop(Thread::current(), this->as_klassOop());
  3054. + class UpdateStaticFieldClosure : public FieldClosure {
  3055. +
  3056. + private:
  3057. + instanceKlassHandle this_oop;
  3058. +
  3059. + public:
  3060. + UpdateStaticFieldClosure(instanceKlassHandle this_oop) {
  3061. + this->this_oop = this_oop;
  3062. + }
  3063. +
  3064. + virtual void do_field(fieldDescriptor* fd) {
  3065. + fieldDescriptor result;
  3066. + bool found = ((instanceKlass *)(this_oop->old_version()->klass_part()))->find_local_field(fd->name(), fd->signature(), &result);
  3067. +
  3068. + if (found && result.is_static()) {
  3069. + int old_offset = result.offset();
  3070. + assert(result.field_type() == fd->field_type(), "");
  3071. +
  3072. + oop new_location = this_oop();
  3073. + oop old_location = this_oop->old_version();
  3074. + int offset = fd->offset();
  3075. + TRACE_RC3("Copying static field value for field %s old_offset=%d new_offset=%d", fd->name()->as_C_string(), old_offset, offset);
  3076. +
  3077. + oop cur_oop;
  3078. +
  3079. + switch(result.field_type()) {
  3080. +
  3081. + // Found static field with same name and type in the old klass => copy value from old to new klass
  3082. +
  3083. + case T_BOOLEAN:
  3084. + new_location->bool_field_put(offset, old_location->bool_field(old_offset));
  3085. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3086. + break;
  3087. +
  3088. + case T_CHAR:
  3089. + new_location->char_field_put(offset, old_location->char_field(old_offset));
  3090. + DEBUG_ONLY(old_location->char_field_put(old_offset, 0));
  3091. + break;
  3092. +
  3093. + case T_FLOAT:
  3094. + new_location->float_field_put(offset, old_location->float_field(old_offset));
  3095. + DEBUG_ONLY(old_location->float_field_put(old_offset, 0));
  3096. + break;
  3097. +
  3098. + case T_DOUBLE:
  3099. + new_location->double_field_put(offset, old_location->double_field(old_offset));
  3100. + DEBUG_ONLY(old_location->double_field_put(old_offset, 0));
  3101. + break;
  3102. +
  3103. + case T_BYTE:
  3104. + new_location->byte_field_put(offset, old_location->byte_field(old_offset));
  3105. + DEBUG_ONLY(old_location->byte_field_put(old_offset, 0));
  3106. + break;
  3107. +
  3108. + case T_SHORT:
  3109. + new_location->short_field_put(offset, old_location->short_field(old_offset));
  3110. + DEBUG_ONLY(old_location->short_field_put(old_offset, 0));
  3111. + break;
  3112. +
  3113. + case T_INT:
  3114. + new_location->int_field_put(offset, old_location->int_field(old_offset));
  3115. + DEBUG_ONLY(old_location->int_field_put(old_offset, 0));
  3116. + break;
  3117. +
  3118. + case T_LONG:
  3119. + new_location->long_field_put(offset, old_location->long_field(old_offset));
  3120. + DEBUG_ONLY(old_location->long_field_put(old_offset, 0));
  3121. + break;
  3122. +
  3123. + case T_OBJECT:
  3124. + case T_ARRAY:
  3125. + cur_oop = old_location->obj_field(old_offset);
  3126. + new_location->obj_field_raw_put(offset, cur_oop);
  3127. + old_location->obj_field_raw_put(old_offset, NULL);
  3128. + break;
  3129. +
  3130. + default:
  3131. + ShouldNotReachHere();
  3132. + }
  3133. + } else {
  3134. +
  3135. + TRACE_RC2("New static field %s has_initial_value=%d", fd->name()->as_C_string(), (int)(fd->has_initial_value()));
  3136. + // field not found
  3137. + // (tw) TODO: Probably this call is not necessary here!
  3138. + ClassFileParser::initialize_static_field(fd, Thread::current());
  3139. + }
  3140. + }
  3141. + };
  3142. +
  3143. + UpdateStaticFieldClosure cl(this_oop);
  3144. + this->do_local_static_fields(&cl);
  3145. +}
  3146. +
  3147. +
  3148. bool instanceKlass::verify_code(
  3149. instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) {
  3150. // 1) Verify the bytecodes
  3151. Verifier::Mode mode =
  3152. throw_verifyerror ? Verifier::ThrowException : Verifier::NoException;
  3153. - return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false);
  3154. + return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), true, CHECK_false);
  3155. }
  3156. @@ -269,7 +373,13 @@
  3157. jt->get_thread_stat()->perf_recursion_counts_addr(),
  3158. jt->get_thread_stat()->perf_timers_addr(),
  3159. PerfClassTraceTime::CLASS_VERIFY);
  3160. - bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3161. + if (this_oop->is_redefining()) {
  3162. + Thread::current()->set_pretend_new_universe(true);
  3163. + }
  3164. + bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD);
  3165. + if (this_oop->is_redefining()) {
  3166. + Thread::current()->set_pretend_new_universe(false);
  3167. + }
  3168. if (!verify_ok) {
  3169. return false;
  3170. }
  3171. @@ -304,7 +414,8 @@
  3172. }
  3173. #endif
  3174. this_oop->set_init_state(linked);
  3175. - if (JvmtiExport::should_post_class_prepare()) {
  3176. + // (tw) Must check for old version in order to prevent infinite loops.
  3177. + if (JvmtiExport::should_post_class_prepare() && this_oop->old_version() == NULL /* JVMTI deadlock otherwise */) {
  3178. Thread *thread = THREAD;
  3179. assert(thread->is_Java_thread(), "thread->is_Java_thread()");
  3180. JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop());
  3181. @@ -571,6 +682,18 @@
  3182. return false;
  3183. }
  3184. +bool instanceKlass::implements_interface_any_version(klassOop k) const {
  3185. + k = k->klass_part()->newest_version();
  3186. + if (this->newest_version() == k) return true;
  3187. + assert(Klass::cast(k)->is_interface(), "should be an interface class");
  3188. + for (int i = 0; i < transitive_interfaces()->length(); i++) {
  3189. + if (((klassOop)transitive_interfaces()->obj_at(i))->klass_part()->newest_version() == k) {
  3190. + return true;
  3191. + }
  3192. + }
  3193. + return false;
  3194. +}
  3195. +
  3196. objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) {
  3197. if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException());
  3198. if (length > arrayOopDesc::max_array_length(T_OBJECT)) {
  3199. @@ -691,7 +814,25 @@
  3200. }
  3201. void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) {
  3202. +
  3203. + ResourceMark rm(THREAD);
  3204. methodHandle h_method(THREAD, this_oop->class_initializer());
  3205. +
  3206. + if (this_oop->revision_number() != -1){
  3207. + methodOop m = NULL;
  3208. + if (AllowAdvancedClassRedefinition) {
  3209. + m = this_oop->find_method(vmSymbols::static_transformer_name(), vmSymbols::void_method_signature());
  3210. + }
  3211. + methodHandle method(m);
  3212. + if (method() != NULL && method()->is_static()) {
  3213. + TRACE_RC2("Calling static transformer instead of static initializer");
  3214. + h_method = method;
  3215. + } else if (!((instanceKlass*)this_oop->old_version()->klass_part())->is_not_initialized()) {
  3216. + // Only execute the static initializer, if it was not yet executed for the old version of the class.
  3217. + return;
  3218. + }
  3219. + }
  3220. +
  3221. assert(!this_oop->is_initialized(), "we cannot initialize twice");
  3222. if (TraceClassInitialization) {
  3223. tty->print("%d Initializing ", call_class_initializer_impl_counter++);
  3224. @@ -843,6 +984,138 @@
  3225. }
  3226. }
  3227. +void instanceKlass::store_update_information(GrowableArray<int> &values) {
  3228. + int *arr = NEW_C_HEAP_ARRAY(int, values.length());
  3229. + for (int i=0; i<values.length(); i++) {
  3230. + arr[i] = values.at(i);
  3231. + }
  3232. + set_update_information(arr);
  3233. +}
  3234. +
  3235. +void instanceKlass::clear_update_information() {
  3236. + FREE_C_HEAP_ARRAY(int, update_information());
  3237. + set_update_information(NULL);
  3238. +}
  3239. +
  3240. +void instanceKlass::do_fields_evolution(FieldEvolutionClosure* cl) {
  3241. +
  3242. + assert (old_version() != NULL, "must have old version!");
  3243. +
  3244. + klassOop old_klass_oop = old_version();
  3245. + instanceKlass *old_klass = instanceKlass::cast(old_klass_oop);
  3246. + instanceKlass *new_klass = this;
  3247. +
  3248. + fieldDescriptor fd;
  3249. + fieldDescriptor old_fd;
  3250. +
  3251. + instanceKlass *cur_new_klass = new_klass;
  3252. + klassOop cur_new_klass_oop = this->as_klassOop();
  3253. +
  3254. + if (_fields_not_changed) {
  3255. +
  3256. + class MyFieldClosure : public FieldClosure {
  3257. +
  3258. + FieldEvolutionClosure *_cl;
  3259. + public:
  3260. + MyFieldClosure(FieldEvolutionClosure *cl) {_cl = cl; }
  3261. + virtual void do_field(fieldDescriptor* fd) {
  3262. + _cl->do_changed_field(fd, fd);
  3263. + }
  3264. + };
  3265. +
  3266. + MyFieldClosure mfc(cl);
  3267. + do_nonstatic_fields(&mfc);
  3268. + } else {
  3269. +
  3270. + _fields_not_changed = true;
  3271. +
  3272. +
  3273. + GrowableArray<fieldDescriptor> fds;
  3274. +
  3275. +
  3276. + while (true) {
  3277. +
  3278. + for (int i=0; i<cur_new_klass->fields()->length(); i+=instanceKlass::next_offset) {
  3279. +
  3280. + fd.initialize(cur_new_klass_oop, i);
  3281. +
  3282. + if (fd.is_static()) {
  3283. + continue;
  3284. + }
  3285. +
  3286. + fds.append(fd);
  3287. + }
  3288. +
  3289. + if (cur_new_klass->super() != NULL) {
  3290. + cur_new_klass_oop = cur_new_klass->super();
  3291. + cur_new_klass = instanceKlass::cast(cur_new_klass_oop);
  3292. + } else {
  3293. + break;
  3294. + }
  3295. + }
  3296. +
  3297. + GrowableArray<fieldDescriptor> sortedFds;
  3298. +
  3299. + while (fds.length() > 0) {
  3300. +
  3301. + int minOffset = 0x7fffffff;
  3302. + int minIndex = -1;
  3303. + for (int i=0; i<fds.length(); i++) {
  3304. + int curOffset = fds.adr_at(i)->offset();
  3305. + if (curOffset < minOffset) {
  3306. + minOffset = curOffset;
  3307. + minIndex = i;
  3308. + }
  3309. + }
  3310. +
  3311. + sortedFds.append(fds.at(minIndex));
  3312. + fds.remove_at(minIndex);
  3313. + }
  3314. +
  3315. +
  3316. + for (int i=0; i<sortedFds.length(); i++) {
  3317. +
  3318. + fieldDescriptor &fd = *sortedFds.adr_at(i);
  3319. +
  3320. + char found = 0;
  3321. + instanceKlass *cur_old_klass = old_klass;
  3322. + klassOop cur_old_klass_oop = old_klass_oop;
  3323. + while (true) {
  3324. + for (int j=0; j<cur_old_klass->fields()->length(); j+=instanceKlass::next_offset) {
  3325. +
  3326. + old_fd.initialize(cur_old_klass_oop, j);
  3327. +
  3328. + if (old_fd.is_static()) {
  3329. + continue;
  3330. + }
  3331. +
  3332. + if (old_fd.name() == fd.name() && old_fd.signature() == fd.signature()) {
  3333. + found = 1;
  3334. + break;
  3335. + }
  3336. + }
  3337. +
  3338. + if (!found && cur_old_klass->super()) {
  3339. + cur_old_klass_oop = cur_old_klass->super();
  3340. + cur_old_klass = instanceKlass::cast(cur_old_klass_oop);
  3341. + } else {
  3342. + break;
  3343. + }
  3344. + }
  3345. +
  3346. + if (found) {
  3347. + if (old_fd.offset() != fd.offset()) {
  3348. + _fields_not_changed = false;
  3349. + }
  3350. + cl->do_changed_field(&old_fd, &fd);
  3351. + } else {
  3352. + _fields_not_changed = false;
  3353. + cl->do_new_field(&fd);
  3354. + }
  3355. + }
  3356. + }
  3357. +}
  3358. +
  3359. void instanceKlass::do_local_static_fields(FieldClosure* cl) {
  3360. fieldDescriptor fd;
  3361. int length = fields()->length();
  3362. @@ -1229,6 +1502,20 @@
  3363. return id;
  3364. }
  3365. +bool instanceKlass::update_jmethod_id(methodOop method, jmethodID newMethodID) {
  3366. + size_t idnum = (size_t)method->method_idnum();
  3367. + jmethodID* jmeths = methods_jmethod_ids_acquire();
  3368. + size_t length; // length assigned as debugging crumb
  3369. + jmethodID id = NULL;
  3370. + if (jmeths != NULL && // If there is a cache
  3371. + (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
  3372. + jmeths[idnum+1] = newMethodID; // Set the id (may be NULL)
  3373. + return true;
  3374. + }
  3375. +
  3376. + return false;
  3377. +}
  3378. +
  3379. // Cache an itable index
  3380. void instanceKlass::set_cached_itable_index(size_t idnum, int index) {
  3381. @@ -1419,6 +1706,13 @@
  3382. last = b;
  3383. b = b->next();
  3384. }
  3385. +
  3386. + // (tw) Hack as dependencies get wrong version of klassOop
  3387. + if(this->old_version() != NULL) {
  3388. + ((instanceKlass *)this->old_version()->klass_part())->remove_dependent_nmethod(nm);
  3389. + return;
  3390. + }
  3391. +
  3392. #ifdef ASSERT
  3393. tty->print_cr("### %s can't find dependent nmethod:", this->external_name());
  3394. nm->print();
  3395. @@ -2552,9 +2846,8 @@
  3396. GrowableArray<PreviousVersionNode *>(2, true);
  3397. }
  3398. - // RC_TRACE macro has an embedded ResourceMark
  3399. - RC_TRACE(0x00000100, ("adding previous version ref for %s @%d, EMCP_cnt=%d",
  3400. - ikh->external_name(), _previous_versions->length(), emcp_method_count));
  3401. + TRACE_RC3("adding previous version ref for %s @%d, EMCP_cnt=%d",
  3402. + ikh->external_name(), _previous_versions->length(), emcp_method_count);
  3403. constantPoolHandle cp_h(ikh->constants());
  3404. jobject cp_ref;
  3405. if (cp_h->is_shared()) {
  3406. @@ -2570,8 +2863,7 @@
  3407. if (emcp_method_count == 0) {
  3408. // non-shared ConstantPool gets a weak reference
  3409. pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), NULL);
  3410. - RC_TRACE(0x00000400,
  3411. - ("add: all methods are obsolete; flushing any EMCP weak refs"));
  3412. + TRACE_RC3("add: all methods are obsolete; flushing any EMCP weak refs");
  3413. } else {
  3414. int local_count = 0;
  3415. GrowableArray<jweak>* method_refs = new (ResourceObj::C_HEAP)
  3416. @@ -2600,8 +2892,7 @@
  3417. // caller is the VMThread and we are at a safepoint, this is a good
  3418. // time to clear out unused weak references.
  3419. - RC_TRACE(0x00000400, ("add: previous version length=%d",
  3420. - _previous_versions->length()));
  3421. + TRACE_RC3("add: previous version length=%d", _previous_versions->length());
  3422. // skip the last entry since we just added it
  3423. for (int i = _previous_versions->length() - 2; i >= 0; i--) {
  3424. @@ -2626,13 +2917,12 @@
  3425. // do anything special with the index.
  3426. continue;
  3427. } else {
  3428. - RC_TRACE(0x00000400, ("add: previous version @%d is alive", i));
  3429. + TRACE_RC3("add: previous version @%d is alive", i);
  3430. }
  3431. GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods();
  3432. if (method_refs != NULL) {
  3433. - RC_TRACE(0x00000400, ("add: previous methods length=%d",
  3434. - method_refs->length()));
  3435. + TRACE_RC3("add: previous methods length=%d", method_refs->length());
  3436. for (int j = method_refs->length() - 1; j >= 0; j--) {
  3437. jweak method_ref = method_refs->at(j);
  3438. assert(method_ref != NULL, "weak method ref was unexpectedly cleared");
  3439. @@ -2651,11 +2941,8 @@
  3440. JNIHandles::destroy_weak_global(method_ref);
  3441. method_refs->remove_at(j);
  3442. } else {
  3443. - // RC_TRACE macro has an embedded ResourceMark
  3444. - RC_TRACE(0x00000400,
  3445. - ("add: %s(%s): previous method @%d in version @%d is alive",
  3446. - method->name()->as_C_string(), method->signature()->as_C_string(),
  3447. - j, i));
  3448. + TRACE_RC3("add: %s(%s): previous method @%d in version @%d is alive",
  3449. + method->name()->as_C_string(), method->signature()->as_C_string(), j, i);
  3450. }
  3451. }
  3452. }
  3453. @@ -2738,9 +3025,8 @@
  3454. // The current RedefineClasses() call has made all EMCP
  3455. // versions of this method obsolete so mark it as obsolete
  3456. // and remove the weak ref.
  3457. - RC_TRACE(0x00000400,
  3458. - ("add: %s(%s): flush obsolete method @%d in version @%d",
  3459. - m_name->as_C_string(), m_signature->as_C_string(), k, j));
  3460. + TRACE_RC3("add: %s(%s): flush obsolete method @%d in version @%d",
  3461. + m_name->as_C_string(), m_signature->as_C_string(), k, j);
  3462. method->set_is_obsolete();
  3463. JNIHandles::destroy_weak_global(method_ref);
  3464. diff -r f5603a6e5042 src/share/vm/oops/instanceKlass.hpp
  3465. --- a/src/share/vm/oops/instanceKlass.hpp Wed Nov 17 22:42:08 2010 -0800
  3466. +++ b/src/share/vm/oops/instanceKlass.hpp Fri Dec 17 13:24:08 2010 +0100
  3467. @@ -86,6 +86,14 @@
  3468. virtual void do_field(fieldDescriptor* fd) = 0;
  3469. };
  3470. +// (tw) Iterates over the fields of the old and new class
  3471. +class FieldEvolutionClosure : public StackObj {
  3472. +public:
  3473. + virtual void do_new_field(fieldDescriptor* fd) = 0;
  3474. + virtual void do_old_field(fieldDescriptor* fd) = 0;
  3475. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd) = 0;
  3476. +};
  3477. +
  3478. #ifndef PRODUCT
  3479. // Print fields.
  3480. // If "obj" argument to constructor is NULL, prints static fields, otherwise prints non-static fields.
  3481. @@ -244,6 +252,11 @@
  3482. JvmtiCachedClassFieldMap* _jvmti_cached_class_field_map; // JVMTI: used during heap iteration
  3483. volatile u2 _idnum_allocated_count; // JNI/JVMTI: increments with the addition of methods, old ids don't change
  3484. + // (tw) Field that allows for a short-path when calculating updated fields for the second time and
  3485. + // no fields changed. Testing performance impact with this, can be removed later when the update
  3486. + // information is cached.
  3487. + bool _fields_not_changed;
  3488. +
  3489. // embedded Java vtable follows here
  3490. // embedded Java itables follows here
  3491. // embedded static fields follows here
  3492. @@ -374,6 +387,7 @@
  3493. // initialization (virtuals from Klass)
  3494. bool should_be_initialized() const; // means that initialize should be called
  3495. void initialize(TRAPS);
  3496. + void initialize_redefined_class();
  3497. void link_class(TRAPS);
  3498. bool link_class_or_fail(TRAPS); // returns false on failure
  3499. void unlink_class();
  3500. @@ -519,6 +533,7 @@
  3501. static void get_jmethod_id_length_value(jmethodID* cache, size_t idnum,
  3502. size_t *length_p, jmethodID* id_p);
  3503. jmethodID jmethod_id_or_null(methodOop method);
  3504. + bool update_jmethod_id(methodOop method, jmethodID newMethodID);
  3505. // cached itable index support
  3506. void set_cached_itable_index(size_t idnum, int index);
  3507. @@ -600,6 +615,7 @@
  3508. // subclass/subinterface checks
  3509. bool implements_interface(klassOop k) const;
  3510. + bool implements_interface_any_version(klassOop k) const;
  3511. // Access to implementors of an interface. We only store the count
  3512. // of implementors, and in case, there are only a few
  3513. @@ -629,6 +645,10 @@
  3514. void do_local_static_fields(FieldClosure* cl);
  3515. void do_nonstatic_fields(FieldClosure* cl); // including inherited fields
  3516. void do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS);
  3517. + void do_fields_evolution(FieldEvolutionClosure *cl);
  3518. + void store_update_information(GrowableArray<int> &values);
  3519. + void clear_update_information();
  3520. +
  3521. void methods_do(void f(methodOop method));
  3522. void array_klasses_do(void f(klassOop k));
  3523. diff -r f5603a6e5042 src/share/vm/oops/instanceKlassKlass.cpp
  3524. --- a/src/share/vm/oops/instanceKlassKlass.cpp Wed Nov 17 22:42:08 2010 -0800
  3525. +++ b/src/share/vm/oops/instanceKlassKlass.cpp Fri Dec 17 13:24:08 2010 +0100
  3526. @@ -487,6 +487,28 @@
  3527. instanceKlass* ik = instanceKlass::cast(klassOop(obj));
  3528. klassKlass::oop_print_on(obj, st);
  3529. + // (tw) Output revision number and revision numbers of older / newer and oldest / newest version of this class.
  3530. +
  3531. + st->print(BULLET"revision: %d", ik->revision_number());
  3532. +
  3533. + if (ik->new_version() != NULL) {
  3534. + st->print(" (newer=%d)", ik->new_version()->klass_part()->revision_number());
  3535. + }
  3536. +
  3537. + if (ik->newest_version() != ik->new_version() && ik->newest_version() != obj) {
  3538. + st->print(" (newest=%d)", ik->newest_version()->klass_part()->revision_number());
  3539. + }
  3540. +
  3541. + if (ik->old_version() != NULL) {
  3542. + st->print(" (old=%d)", ik->old_version()->klass_part()->revision_number());
  3543. + }
  3544. +
  3545. + if (ik->oldest_version() != ik->old_version() && ik->oldest_version() != obj) {
  3546. + st->print(" (oldest=%d)", ik->oldest_version()->klass_part()->revision_number());
  3547. + }
  3548. +
  3549. + st->cr();
  3550. +
  3551. st->print(BULLET"instance size: %d", ik->size_helper()); st->cr();
  3552. st->print(BULLET"klass size: %d", ik->object_size()); st->cr();
  3553. st->print(BULLET"access: "); ik->access_flags().print_on(st); st->cr();
  3554. @@ -685,7 +707,7 @@
  3555. }
  3556. guarantee(sib->as_klassOop()->is_klass(), "should be klass");
  3557. guarantee(sib->as_klassOop()->is_perm(), "should be in permspace");
  3558. - guarantee(sib->super() == super, "siblings should have same superklass");
  3559. + guarantee(sib->super() == super || super->klass_part()->newest_version() == SystemDictionary::Object_klass(), "siblings should have same superklass");
  3560. sib = sib->next_sibling();
  3561. }
  3562. diff -r f5603a6e5042 src/share/vm/oops/instanceRefKlass.cpp
  3563. --- a/src/share/vm/oops/instanceRefKlass.cpp Wed Nov 17 22:42:08 2010 -0800
  3564. +++ b/src/share/vm/oops/instanceRefKlass.cpp Fri Dec 17 13:24:08 2010 +0100
  3565. @@ -363,10 +363,13 @@
  3566. instanceKlass* ik = instanceKlass::cast(k);
  3567. // Check that we have the right class
  3568. - debug_only(static bool first_time = true);
  3569. - assert(k == SystemDictionary::Reference_klass() && first_time,
  3570. - "Invalid update of maps");
  3571. - debug_only(first_time = false);
  3572. +
  3573. + // (tw) Asserts no longer valid for class redefinition
  3574. + // debug_only(static bool first_time = true);
  3575. +
  3576. + //assert(k == SystemDictionary::Reference_klass() && first_time,
  3577. + // "Invalid update of maps");
  3578. + //debug_only(first_time = false);
  3579. assert(ik->nonstatic_oop_map_count() == 1, "just checking");
  3580. OopMapBlock* map = ik->start_of_nonstatic_oop_maps();
  3581. diff -r f5603a6e5042 src/share/vm/oops/klass.cpp
  3582. --- a/src/share/vm/oops/klass.cpp Wed Nov 17 22:42:08 2010 -0800
  3583. +++ b/src/share/vm/oops/klass.cpp Fri Dec 17 13:24:08 2010 +0100
  3584. @@ -40,6 +40,26 @@
  3585. return false;
  3586. }
  3587. +void Klass::update_supers_to_newest_version() {
  3588. +
  3589. + if (super() != NULL) set_super(super()->klass_part()->newest_version());
  3590. +
  3591. + for (uint i=0; i<primary_super_limit(); i++) {
  3592. + klassOop cur = _primary_supers[i];
  3593. + if (cur != NULL) {
  3594. + _primary_supers[i] = cur->klass_part()->newest_version();
  3595. + }
  3596. + }
  3597. +
  3598. + // Scan the array-of-objects
  3599. + int cnt = secondary_supers()->length();
  3600. + for (int i = 0; i < cnt; i++) {
  3601. + klassOop cur = (klassOop)secondary_supers()->obj_at(i);
  3602. + if (cur != NULL) {
  3603. + secondary_supers()->obj_at_put(i, cur->klass_part()->newest_version());
  3604. + }
  3605. + }
  3606. +}
  3607. bool Klass::search_secondary_supers(klassOop k) const {
  3608. // Put some extra logic here out-of-line, before the search proper.
  3609. // This cuts down the size of the inline method.
  3610. @@ -145,6 +165,13 @@
  3611. kl->set_alloc_count(0);
  3612. kl->set_alloc_size(0);
  3613. + kl->set_redefinition_flags(Klass::NoRedefinition);
  3614. + kl->set_redefining(false);
  3615. + kl->set_new_version(NULL);
  3616. + kl->set_old_version(NULL);
  3617. + kl->set_redefinition_index(-1);
  3618. + kl->set_revision_number(-1);
  3619. +
  3620. kl->set_prototype_header(markOopDesc::prototype());
  3621. kl->set_biased_lock_revocation_count(0);
  3622. kl->set_last_biased_lock_bulk_revocation_time(0);
  3623. @@ -217,7 +244,7 @@
  3624. set_super(NULL);
  3625. oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
  3626. assert(super_depth() == 0, "Object must already be initialized properly");
  3627. - } else if (k != super() || k == SystemDictionary::Object_klass()) {
  3628. + } else if (k != super() || k->klass_part()->super() == NULL) {
  3629. assert(super() == NULL || super() == SystemDictionary::Object_klass(),
  3630. "initialize this only once to a non-trivial value");
  3631. set_super(k);
  3632. diff -r f5603a6e5042 src/share/vm/oops/klass.hpp
  3633. --- a/src/share/vm/oops/klass.hpp Wed Nov 17 22:42:08 2010 -0800
  3634. +++ b/src/share/vm/oops/klass.hpp Fri Dec 17 13:24:08 2010 +0100
  3635. @@ -150,6 +150,7 @@
  3636. void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
  3637. };
  3638. +template<class L, class R> class Pair;
  3639. class Klass : public Klass_vtbl {
  3640. friend class VMStructs;
  3641. @@ -198,6 +199,31 @@
  3642. oop* oop_block_beg() const { return adr_secondary_super_cache(); }
  3643. oop* oop_block_end() const { return adr_next_sibling() + 1; }
  3644. + // (tw) Different class redefinition flags of code evolution.
  3645. + enum RedefinitionFlags {
  3646. +
  3647. + // This class is not redefined at all!
  3648. + NoRedefinition,
  3649. +
  3650. + // There are changes to the class meta data.
  3651. + ModifyClass = 1,
  3652. +
  3653. + // The size of the class meta data changes.
  3654. + ModifyClassSize = ModifyClass << 1,
  3655. +
  3656. + // There are change to the instance format.
  3657. + ModifyInstances = ModifyClassSize << 1,
  3658. +
  3659. + // The size of instances changes.
  3660. + ModifyInstanceSize = ModifyInstances << 1,
  3661. +
  3662. + // A super type of this class is removed.
  3663. + RemoveSuperType = ModifyInstanceSize << 1,
  3664. +
  3665. + // This class (or one of its super classes) has an instance transformer method.
  3666. + HasInstanceTransformer = RemoveSuperType << 1,
  3667. + };
  3668. +
  3669. protected:
  3670. //
  3671. // The oop block. All oop fields must be declared here and only oop fields
  3672. @@ -217,6 +243,10 @@
  3673. oop _java_mirror;
  3674. // Superclass
  3675. klassOop _super;
  3676. + // Old class
  3677. + klassOop _old_version;
  3678. + // New class
  3679. + klassOop _new_version;
  3680. // Class name. Instance classes: java/lang/String, etc. Array classes: [I,
  3681. // [Ljava/lang/String;, etc. Set to zero for all other kinds of classes.
  3682. symbolOop _name;
  3683. @@ -232,6 +262,16 @@
  3684. jint _modifier_flags; // Processed access flags, for use by Class.getModifiers.
  3685. AccessFlags _access_flags; // Access flags. The class/interface distinction is stored here.
  3686. + // (tw) Non-oop fields for enhanced class redefinition
  3687. + jint _revision_number; // The revision number for redefined classes
  3688. + jint _redefinition_index; // Index of this class when performing the redefinition
  3689. + bool _subtype_changed;
  3690. + int _redefinition_flags; // Level of class redefinition
  3691. + bool _is_copying_backwards; // Does the class need to copy fields backwards? => possibly overwrite itself?
  3692. + int * _update_information; // Update information
  3693. + Pair<int, klassOop> * _type_check_information; // Offsets of object fields that need a type check
  3694. + bool _is_redefining;
  3695. +
  3696. #ifndef PRODUCT
  3697. int _verify_count; // to avoid redundant verifies
  3698. #endif
  3699. @@ -279,6 +319,75 @@
  3700. klassOop secondary_super_cache() const { return _secondary_super_cache; }
  3701. void set_secondary_super_cache(klassOop k) { oop_store_without_check((oop*) &_secondary_super_cache, (oop) k); }
  3702. + // BEGIN class redefinition utilities
  3703. +
  3704. + // double links between new and old version of a class
  3705. + klassOop old_version() const { return _old_version; }
  3706. + void set_old_version(klassOop klass) { assert(_old_version == NULL || klass == NULL, "Can only be set once!"); _old_version = klass; }
  3707. + klassOop new_version() const { return _new_version; }
  3708. + void set_new_version(klassOop klass) { assert(_new_version == NULL || klass == NULL, "Can only be set once!"); _new_version = klass; }
  3709. +
  3710. + // A subtype of this class is no longer a subtype
  3711. + bool has_subtype_changed() const { return _subtype_changed; }
  3712. + void set_subtype_changed(bool b) { assert(is_newest_version() || new_version()->klass_part()->is_newest_version(), "must be newest or second newest version");
  3713. + _subtype_changed = b; }
  3714. + // state of being redefined
  3715. + int redefinition_index() const { return _redefinition_index; }
  3716. + void set_redefinition_index(int index) { _redefinition_index = index; }
  3717. + void set_redefining(bool b) { _is_redefining = b; }
  3718. + bool is_redefining() const { return _is_redefining; }
  3719. + int redefinition_flags() const { return _redefinition_flags; }
  3720. + bool check_redefinition_flag(int flags) const { return (_redefinition_flags & flags) != 0; }
  3721. + void set_redefinition_flags(int flags) { _redefinition_flags = flags; }
  3722. + bool is_copying_backwards() const { return _is_copying_backwards; }
  3723. + void set_copying_backwards(bool b) { _is_copying_backwards = b; }
  3724. +
  3725. + // update information
  3726. + int *update_information() const { return _update_information; }
  3727. + void set_update_information(int *info) { _update_information = info; }
  3728. + Pair<int, klassOop> *type_check_information() const { return _type_check_information; }
  3729. + void set_type_check_information(Pair<int, klassOop> *info) { _type_check_information = info; }
  3730. +
  3731. + bool is_same_or_older_version(klassOop klass) const {
  3732. + if (Klass::cast(klass) == this) { return true; }
  3733. + else if (_old_version == NULL) { return false; }
  3734. + else { return _old_version->klass_part()->is_same_or_older_version(klass); }
  3735. + }
  3736. +
  3737. + // Revision number for redefined classes, -1 for originally loaded classes
  3738. + jint revision_number() const {
  3739. + return _revision_number;
  3740. + }
  3741. +
  3742. + bool was_redefined() const {
  3743. + return _revision_number != -1;
  3744. + }
  3745. +
  3746. + void set_revision_number(jint number) {
  3747. + _revision_number = number;
  3748. + }
  3749. +
  3750. + klassOop oldest_version() const {
  3751. + if (_old_version == NULL) { return this->as_klassOop(); }
  3752. + else { return _old_version->klass_part()->oldest_version(); };
  3753. + }
  3754. +
  3755. + klassOop newest_version() const {
  3756. + if (_new_version == NULL) { return this->as_klassOop(); }
  3757. + else { return _new_version->klass_part()->newest_version(); };
  3758. + }
  3759. +
  3760. + klassOop active_version() const {
  3761. + if (_new_version == NULL || _new_version->klass_part()->is_redefining()) { return this->as_klassOop(); assert(!this->is_redefining(), "just checking"); }
  3762. + else { return _new_version->klass_part()->active_version(); };
  3763. + }
  3764. +
  3765. + bool is_newest_version() const {
  3766. + return _new_version == NULL;
  3767. + }
  3768. +
  3769. + // END class redefinition utilities
  3770. +
  3771. objArrayOop secondary_supers() const { return _secondary_supers; }
  3772. void set_secondary_supers(objArrayOop k) { oop_store_without_check((oop*) &_secondary_supers, (oop) k); }
  3773. @@ -339,6 +448,8 @@
  3774. void set_next_sibling(klassOop s);
  3775. oop* adr_super() const { return (oop*)&_super; }
  3776. + oop* adr_old_version() const { return (oop*)&_old_version; }
  3777. + oop* adr_new_version() const { return (oop*)&_new_version; }
  3778. oop* adr_primary_supers() const { return (oop*)&_primary_supers[0]; }
  3779. oop* adr_secondary_super_cache() const { return (oop*)&_secondary_super_cache; }
  3780. oop* adr_secondary_supers()const { return (oop*)&_secondary_supers; }
  3781. @@ -469,6 +580,7 @@
  3782. return search_secondary_supers(k);
  3783. }
  3784. }
  3785. + void update_supers_to_newest_version();
  3786. bool search_secondary_supers(klassOop k) const;
  3787. // Find LCA in class hierarchy
  3788. diff -r f5603a6e5042 src/share/vm/oops/klassKlass.cpp
  3789. --- a/src/share/vm/oops/klassKlass.cpp Wed Nov 17 22:42:08 2010 -0800
  3790. +++ b/src/share/vm/oops/klassKlass.cpp Fri Dec 17 13:24:08 2010 +0100
  3791. @@ -45,6 +45,8 @@
  3792. Klass* k = Klass::cast(klassOop(obj));
  3793. // If we are alive it is valid to keep our superclass and subtype caches alive
  3794. MarkSweep::mark_and_push(k->adr_super());
  3795. + MarkSweep::mark_and_push(k->adr_old_version());
  3796. + MarkSweep::mark_and_push(k->adr_new_version());
  3797. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3798. MarkSweep::mark_and_push(k->adr_primary_supers()+i);
  3799. MarkSweep::mark_and_push(k->adr_secondary_super_cache());
  3800. @@ -65,6 +67,8 @@
  3801. Klass* k = Klass::cast(klassOop(obj));
  3802. // If we are alive it is valid to keep our superclass and subtype caches alive
  3803. PSParallelCompact::mark_and_push(cm, k->adr_super());
  3804. + PSParallelCompact::mark_and_push(cm, k->adr_old_version());
  3805. + PSParallelCompact::mark_and_push(cm, k->adr_new_version());
  3806. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3807. PSParallelCompact::mark_and_push(cm, k->adr_primary_supers()+i);
  3808. PSParallelCompact::mark_and_push(cm, k->adr_secondary_super_cache());
  3809. @@ -85,6 +89,8 @@
  3810. int size = oop_size(obj);
  3811. Klass* k = Klass::cast(klassOop(obj));
  3812. blk->do_oop(k->adr_super());
  3813. + blk->do_oop(k->adr_old_version());
  3814. + blk->do_oop(k->adr_new_version());
  3815. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3816. blk->do_oop(k->adr_primary_supers()+i);
  3817. blk->do_oop(k->adr_secondary_super_cache());
  3818. @@ -114,6 +120,10 @@
  3819. oop* adr;
  3820. adr = k->adr_super();
  3821. if (mr.contains(adr)) blk->do_oop(adr);
  3822. + adr = k->adr_old_version();
  3823. + if (mr.contains(adr)) blk->do_oop(adr);
  3824. + adr = k->adr_new_version();
  3825. + if (mr.contains(adr)) blk->do_oop(adr);
  3826. for (juint i = 0; i < Klass::primary_super_limit(); i++) {
  3827. adr = k->adr_primary_supers()+i;
  3828. if (mr.contains(adr)) blk->do_oop(adr);
  3829. @@ -149,6 +159,8 @@
  3830. Klass* k = Klass::cast(klassOop(obj));
  3831. MarkSweep::adjust_pointer(k->adr_super());
  3832. + MarkSweep::adjust_pointer(k->adr_new_version());
  3833. + MarkSweep::adjust_pointer(k->adr_old_version());
  3834. for (juint i = 0; i < Klass::primary_super_limit(); i++)
  3835. MarkSweep::adjust_pointer(k->adr_primary_supers()+i);
  3836. MarkSweep::adjust_pointer(k->adr_secondary_super_cache());
  3837. diff -r f5603a6e5042 src/share/vm/oops/klassVtable.cpp
  3838. --- a/src/share/vm/oops/klassVtable.cpp Wed Nov 17 22:42:08 2010 -0800
  3839. +++ b/src/share/vm/oops/klassVtable.cpp Fri Dec 17 13:24:08 2010 +0100
  3840. @@ -82,7 +82,8 @@
  3841. vtable_length = Universe::base_vtable_size();
  3842. }
  3843. - if (super == NULL && !Universe::is_bootstrapping() &&
  3844. + // (tw) TODO: Check if we can relax the condition on a fixed base vtable size
  3845. + /*if (super == NULL && !Universe::is_bootstrapping() &&
  3846. vtable_length != Universe::base_vtable_size()) {
  3847. // Someone is attempting to redefine java.lang.Object incorrectly. The
  3848. // only way this should happen is from
  3849. @@ -92,9 +93,9 @@
  3850. vtable_length = Universe::base_vtable_size();
  3851. }
  3852. assert(super != NULL || vtable_length == Universe::base_vtable_size(),
  3853. - "bad vtable size for class Object");
  3854. + "bad vtable size for class Object");*/
  3855. assert(vtable_length % vtableEntry::size() == 0, "bad vtable length");
  3856. - assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  3857. + //assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
  3858. }
  3859. int klassVtable::index_of(methodOop m, int len) const {
  3860. @@ -611,17 +612,13 @@
  3861. if (unchecked_method_at(index) == old_method) {
  3862. put_method_at(new_method, index);
  3863. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3864. + IF_TRACE_RC4 {
  3865. if (!(*trace_name_printed)) {
  3866. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3867. - RC_TRACE_MESG(("adjust: name=%s",
  3868. - Klass::cast(old_method->method_holder())->external_name()));
  3869. + TRACE_RC4("adjust: name=%s", Klass::cast(old_method->method_holder())->external_name());
  3870. *trace_name_printed = true;
  3871. }
  3872. - // RC_TRACE macro has an embedded ResourceMark
  3873. - RC_TRACE(0x00100000, ("vtable method update: %s(%s)",
  3874. - new_method->name()->as_C_string(),
  3875. - new_method->signature()->as_C_string()));
  3876. + TRACE_RC4("vtable method update: %s(%s)", new_method->name()->as_C_string(),
  3877. + new_method->signature()->as_C_string());
  3878. }
  3879. }
  3880. }
  3881. @@ -994,17 +991,13 @@
  3882. if (ime->method() == old_method) {
  3883. ime->initialize(new_method);
  3884. - if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  3885. + IF_TRACE_RC4 {
  3886. if (!(*trace_name_printed)) {
  3887. - // RC_TRACE_MESG macro has an embedded ResourceMark
  3888. - RC_TRACE_MESG(("adjust: name=%s",
  3889. - Klass::cast(old_method->method_holder())->external_name()));
  3890. + TRACE_RC4("adjust: name=%s", Klass::cast(old_method->method_holder())->external_name());
  3891. *trace_name_printed = true;
  3892. }
  3893. - // RC_TRACE macro has an embedded ResourceMark
  3894. - RC_TRACE(0x00200000, ("itable method update: %s(%s)",
  3895. - new_method->name()->as_C_string(),
  3896. - new_method->signature()->as_C_string()));
  3897. + TRACE_RC4("itable method update: %s(%s)", new_method->name()->as_C_string(),
  3898. + new_method->signature()->as_C_string());
  3899. }
  3900. break;
  3901. }
  3902. @@ -1198,6 +1191,7 @@
  3903. void klassVtable::verify_against(outputStream* st, klassVtable* vt, int index) {
  3904. vtableEntry* vte = &vt->table()[index];
  3905. + if (vte->method() == NULL || table()[index].method() == NULL) return;
  3906. if (vte->method()->name() != table()[index].method()->name() ||
  3907. vte->method()->signature() != table()[index].method()->signature()) {
  3908. fatal("mismatched name/signature of vtable entries");
  3909. @@ -1217,6 +1211,8 @@
  3910. void vtableEntry::verify(klassVtable* vt, outputStream* st) {
  3911. NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true));
  3912. + // (tw) TODO: Check: Does not hold?
  3913. + if (method() != NULL) {
  3914. assert(method() != NULL, "must have set method");
  3915. method()->verify();
  3916. // we sub_type, because it could be a miranda method
  3917. @@ -1224,7 +1220,13 @@
  3918. #ifndef PRODUCT
  3919. print();
  3920. #endif
  3921. - fatal(err_msg("vtableEntry " PTR_FORMAT ": method is from subclass", this));
  3922. + klassOop first_klass = vt->klass()();
  3923. + klassOop second_klass = method()->method_holder();
  3924. + // (tw) the following fatal does not work for old versions of classes
  3925. + if (first_klass->klass_part()->is_newest_version()) {
  3926. + //fatal1("vtableEntry %#lx: method is from subclass", this);
  3927. + }
  3928. + }
  3929. }
  3930. }
  3931. @@ -1232,7 +1234,7 @@
  3932. void vtableEntry::print() {
  3933. ResourceMark rm;
  3934. - tty->print("vtableEntry %s: ", method()->name()->as_C_string());
  3935. + tty->print("vtableEntry %s: ", (method() == NULL) ? "null" : method()->name()->as_C_string());
  3936. if (Verbose) {
  3937. tty->print("m %#lx ", (address)method());
  3938. }
  3939. @@ -1304,7 +1306,7 @@
  3940. for (int i = 0; i < length(); i++) {
  3941. methodOop m = unchecked_method_at(i);
  3942. if (m != NULL) {
  3943. - if (m->is_old()) {
  3944. + if (m->is_old() || !m->method_holder()->klass_part()->is_newest_version()) {
  3945. return false;
  3946. }
  3947. }
  3948. diff -r f5603a6e5042 src/share/vm/oops/methodKlass.cpp
  3949. --- a/src/share/vm/oops/methodKlass.cpp Wed Nov 17 22:42:08 2010 -0800
  3950. +++ b/src/share/vm/oops/methodKlass.cpp Fri Dec 17 13:24:08 2010 +0100
  3951. @@ -78,6 +78,10 @@
  3952. m->set_adapter_entry(NULL);
  3953. m->clear_code(); // from_c/from_i get set to c2i/i2i
  3954. + m->set_forward_method(NULL);
  3955. + m->set_new_version(NULL);
  3956. + m->set_old_version(NULL);
  3957. +
  3958. if (access_flags.is_native()) {
  3959. m->clear_native_function();
  3960. m->set_signature_handler(NULL);
  3961. @@ -106,6 +110,9 @@
  3962. // Performance tweak: We skip iterating over the klass pointer since we
  3963. // know that Universe::methodKlassObj never moves.
  3964. MarkSweep::mark_and_push(m->adr_constMethod());
  3965. + MarkSweep::mark_and_push(m->adr_forward_method());
  3966. + MarkSweep::mark_and_push(m->adr_new_version());
  3967. + MarkSweep::mark_and_push(m->adr_old_version());
  3968. MarkSweep::mark_and_push(m->adr_constants());
  3969. if (m->method_data() != NULL) {
  3970. MarkSweep::mark_and_push(m->adr_method_data());
  3971. @@ -120,6 +127,9 @@
  3972. // Performance tweak: We skip iterating over the klass pointer since we
  3973. // know that Universe::methodKlassObj never moves.
  3974. PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
  3975. + PSParallelCompact::mark_and_push(cm, m->adr_forward_method());
  3976. + PSParallelCompact::mark_and_push(cm, m->adr_new_version());
  3977. + PSParallelCompact::mark_and_push(cm, m->adr_old_version());
  3978. PSParallelCompact::mark_and_push(cm, m->adr_constants());
  3979. #ifdef COMPILER2
  3980. if (m->method_data() != NULL) {
  3981. @@ -138,6 +148,9 @@
  3982. // Performance tweak: We skip iterating over the klass pointer since we
  3983. // know that Universe::methodKlassObj never moves
  3984. blk->do_oop(m->adr_constMethod());
  3985. + blk->do_oop(m->adr_forward_method());
  3986. + blk->do_oop(m->adr_new_version());
  3987. + blk->do_oop(m->adr_old_version());
  3988. blk->do_oop(m->adr_constants());
  3989. if (m->method_data() != NULL) {
  3990. blk->do_oop(m->adr_method_data());
  3991. @@ -157,6 +170,12 @@
  3992. oop* adr;
  3993. adr = m->adr_constMethod();
  3994. if (mr.contains(adr)) blk->do_oop(adr);
  3995. + adr = m->adr_new_version();
  3996. + if (mr.contains(adr)) blk->do_oop(adr);
  3997. + adr = m->adr_forward_method();
  3998. + if (mr.contains(adr)) blk->do_oop(adr);
  3999. + adr = m->adr_old_version();
  4000. + if (mr.contains(adr)) blk->do_oop(adr);
  4001. adr = m->adr_constants();
  4002. if (mr.contains(adr)) blk->do_oop(adr);
  4003. if (m->method_data() != NULL) {
  4004. @@ -176,6 +195,9 @@
  4005. // Performance tweak: We skip iterating over the klass pointer since we
  4006. // know that Universe::methodKlassObj never moves.
  4007. MarkSweep::adjust_pointer(m->adr_constMethod());
  4008. + MarkSweep::adjust_pointer(m->adr_forward_method());
  4009. + MarkSweep::adjust_pointer(m->adr_new_version());
  4010. + MarkSweep::adjust_pointer(m->adr_old_version());
  4011. MarkSweep::adjust_pointer(m->adr_constants());
  4012. if (m->method_data() != NULL) {
  4013. MarkSweep::adjust_pointer(m->adr_method_data());
  4014. @@ -192,6 +214,8 @@
  4015. assert(obj->is_method(), "should be method");
  4016. methodOop m = methodOop(obj);
  4017. PSParallelCompact::adjust_pointer(m->adr_constMethod());
  4018. + PSParallelCompact::adjust_pointer(m->adr_new_version());
  4019. + PSParallelCompact::adjust_pointer(m->adr_old_version());
  4020. PSParallelCompact::adjust_pointer(m->adr_constants());
  4021. #ifdef COMPILER2
  4022. if (m->method_data() != NULL) {
  4023. @@ -210,6 +234,12 @@
  4024. p = m->adr_constMethod();
  4025. PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
  4026. + p = m->adr_forward_method();
  4027. + PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
  4028. + p = m->adr_new_version();
  4029. + PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
  4030. + p = m->adr_old_version();
  4031. + PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
  4032. p = m->adr_constants();
  4033. PSParallelCompact::adjust_pointer(p, beg_addr, end_addr);
  4034. @@ -234,7 +264,18 @@
  4035. methodOop m = methodOop(obj);
  4036. // get the effect of PrintOopAddress, always, for methods:
  4037. st->print_cr(" - this oop: "INTPTR_FORMAT, (intptr_t)m);
  4038. - st->print (" - method holder: "); m->method_holder()->print_value_on(st); st->cr();
  4039. + st->print (" - method holder: "); m->method_holder()->print_value_on(st);
  4040. +
  4041. + if (m->method_holder()->klass_part()->new_version() != NULL) {
  4042. + st->print(" (old)");
  4043. + }
  4044. + st->cr();
  4045. +
  4046. + st->print_cr(" - is obsolete: %d", (int)(m->is_obsolete()));
  4047. + st->print_cr(" - is old: %d", (int)(m->is_old()));
  4048. + st->print_cr(" - new version: %d", (int)(m->new_version()));
  4049. + st->print_cr(" - old version: %d", (int)(m->old_version()));
  4050. + st->print_cr(" - holder revision: %d", m->method_holder()->klass_part()->revision_number());
  4051. st->print (" - constants: "INTPTR_FORMAT" ", (address)m->constants());
  4052. m->constants()->print_value_on(st); st->cr();
  4053. st->print (" - access: 0x%x ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
  4054. diff -r f5603a6e5042 src/share/vm/oops/methodOop.cpp
  4055. --- a/src/share/vm/oops/methodOop.cpp Wed Nov 17 22:42:08 2010 -0800
  4056. +++ b/src/share/vm/oops/methodOop.cpp Fri Dec 17 13:24:08 2010 +0100
  4057. @@ -986,6 +986,9 @@
  4058. // Reset correct method/const method, method size, and parameter info
  4059. newcm->set_method(newm());
  4060. newm->set_constMethod(newcm);
  4061. + newm->set_forward_method(newm->forward_method());
  4062. + newm->set_new_version(newm->new_version());
  4063. + newm->set_old_version(newm->old_version());
  4064. assert(newcm->method() == newm(), "check");
  4065. newm->constMethod()->set_code_size(new_code_length);
  4066. newm->constMethod()->set_constMethod_size(new_const_method_size);
  4067. diff -r f5603a6e5042 src/share/vm/oops/methodOop.hpp
  4068. --- a/src/share/vm/oops/methodOop.hpp Wed Nov 17 22:42:08 2010 -0800
  4069. +++ b/src/share/vm/oops/methodOop.hpp Fri Dec 17 13:24:08 2010 +0100
  4070. @@ -96,6 +96,11 @@
  4071. AccessFlags _access_flags; // Access flags
  4072. int _vtable_index; // vtable index of this method (see VtableIndexFlag)
  4073. // note: can have vtables with >2**16 elements (because of inheritance)
  4074. + // (tw) Newer version of method available?
  4075. + methodOop _forward_method;
  4076. + methodOop _new_version;
  4077. + methodOop _old_version;
  4078. +
  4079. #ifdef CC_INTERP
  4080. int _result_index; // C++ interpreter needs for converting results to/from stack
  4081. #endif
  4082. @@ -150,6 +155,32 @@
  4083. int name_index() const { return constMethod()->name_index(); }
  4084. void set_name_index(int index) { constMethod()->set_name_index(index); }
  4085. + methodOop forward_method() const {return _forward_method; }
  4086. + void set_forward_method(methodOop m) { _forward_method = m; }
  4087. + bool has_forward_method() const { return forward_method() != NULL; }
  4088. + methodOop new_version() const {return _new_version; }
  4089. + void set_new_version(methodOop m) { _new_version = m; }
  4090. + methodOop newest_version() { if(_new_version == NULL) return this; else return new_version()->newest_version(); }
  4091. +
  4092. + methodOop old_version() const {return _old_version; };
  4093. + void set_old_version(methodOop m) {
  4094. + if (m == NULL) {
  4095. + _old_version = NULL;
  4096. + return;
  4097. + }
  4098. +
  4099. + assert(_old_version == NULL, "may only be set once");
  4100. + assert(this->code_size() == m->code_size(), "must have same code length");
  4101. + _old_version = m;
  4102. + }
  4103. +
  4104. + methodOop oldest_version() const {
  4105. + if(_old_version == NULL) return (methodOop)this;
  4106. + else {
  4107. + return old_version()->oldest_version();
  4108. + }
  4109. + }
  4110. +
  4111. // signature
  4112. symbolOop signature() const { return _constants->symbol_at(signature_index()); }
  4113. int signature_index() const { return constMethod()->signature_index(); }
  4114. @@ -669,6 +700,9 @@
  4115. // Garbage collection support
  4116. oop* adr_constMethod() const { return (oop*)&_constMethod; }
  4117. + oop* adr_forward_method() const { return (oop*)&_forward_method; }
  4118. + oop* adr_new_version() const { return (oop*)&_new_version; }
  4119. + oop* adr_old_version() const { return (oop*)&_old_version; }
  4120. oop* adr_constants() const { return (oop*)&_constants; }
  4121. oop* adr_method_data() const { return (oop*)&_method_data; }
  4122. };
  4123. diff -r f5603a6e5042 src/share/vm/oops/oop.hpp
  4124. --- a/src/share/vm/oops/oop.hpp Wed Nov 17 22:42:08 2010 -0800
  4125. +++ b/src/share/vm/oops/oop.hpp Fri Dec 17 13:24:08 2010 +0100
  4126. @@ -81,6 +81,7 @@
  4127. narrowOop* compressed_klass_addr();
  4128. void set_klass(klassOop k);
  4129. + void set_klass_no_check(klassOop k);
  4130. // For klass field compression
  4131. int klass_gap() const;
  4132. @@ -121,6 +122,7 @@
  4133. bool is_objArray() const;
  4134. bool is_symbol() const;
  4135. bool is_klass() const;
  4136. + bool is_instanceKlass() const;
  4137. bool is_thread() const;
  4138. bool is_method() const;
  4139. bool is_constMethod() const;
  4140. diff -r f5603a6e5042 src/share/vm/oops/oop.inline.hpp
  4141. --- a/src/share/vm/oops/oop.inline.hpp Wed Nov 17 22:42:08 2010 -0800
  4142. +++ b/src/share/vm/oops/oop.inline.hpp Fri Dec 17 13:24:08 2010 +0100
  4143. @@ -78,6 +78,14 @@
  4144. }
  4145. }
  4146. +inline void oopDesc::set_klass_no_check(klassOop k) {
  4147. + if (UseCompressedOops) {
  4148. + oop_store_without_check(compressed_klass_addr(), (oop)k);
  4149. + } else {
  4150. + oop_store_without_check(klass_addr(), (oop) k);
  4151. + }
  4152. +}
  4153. +
  4154. inline int oopDesc::klass_gap() const {
  4155. return *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes());
  4156. }
  4157. @@ -111,6 +119,7 @@
  4158. inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
  4159. inline bool oopDesc::is_symbol() const { return blueprint()->oop_is_symbol(); }
  4160. inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
  4161. +inline bool oopDesc::is_instanceKlass() const { return blueprint()->oop_is_instanceKlass(); }
  4162. inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
  4163. inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
  4164. inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
  4165. diff -r f5603a6e5042 src/share/vm/prims/jni.cpp
  4166. --- a/src/share/vm/prims/jni.cpp Wed Nov 17 22:42:08 2010 -0800
  4167. +++ b/src/share/vm/prims/jni.cpp Fri Dec 17 13:24:08 2010 +0100
  4168. @@ -299,7 +299,7 @@
  4169. }
  4170. }
  4171. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4172. - Handle(), &st, true,
  4173. + Handle(), &st, true, KlassHandle(),
  4174. CHECK_NULL);
  4175. if (TraceClassResolution && k != NULL) {
  4176. diff -r f5603a6e5042 src/share/vm/prims/jvm.cpp
  4177. --- a/src/share/vm/prims/jvm.cpp Wed Nov 17 22:42:08 2010 -0800
  4178. +++ b/src/share/vm/prims/jvm.cpp Fri Dec 17 13:24:08 2010 +0100
  4179. @@ -811,7 +811,7 @@
  4180. Handle protection_domain (THREAD, JNIHandles::resolve(pd));
  4181. klassOop k = SystemDictionary::resolve_from_stream(class_name, class_loader,
  4182. protection_domain, &st,
  4183. - verify != 0,
  4184. + verify != 0, KlassHandle(),
  4185. CHECK_NULL);
  4186. if (TraceClassResolution && k != NULL) {
  4187. diff -r f5603a6e5042 src/share/vm/prims/jvmtiClassFileReconstituter.cpp
  4188. --- a/src/share/vm/prims/jvmtiClassFileReconstituter.cpp Wed Nov 17 22:42:08 2010 -0800
  4189. +++ b/src/share/vm/prims/jvmtiClassFileReconstituter.cpp Fri Dec 17 13:24:08 2010 +0100
  4190. @@ -120,6 +120,7 @@
  4191. constMethodHandle const_method(thread(), method->constMethod());
  4192. u2 line_num_cnt = 0;
  4193. int stackmap_len = 0;
  4194. + int local_variable_table_length = 0;
  4195. // compute number and length of attributes -- FIXME: for now no LVT
  4196. int attr_count = 0;
  4197. @@ -154,6 +155,25 @@
  4198. attr_size += 2 + 4 + stackmap_len;
  4199. }
  4200. }
  4201. + if (method->has_localvariable_table()) {
  4202. + local_variable_table_length = method->localvariable_table_length();
  4203. + ++attr_count;
  4204. + if (local_variable_table_length != 0) {
  4205. + // Compute the size of the local variable table attribute (VM stores raw):
  4206. + // LocalVariableTable_attribute {
  4207. + // u2 attribute_name_index;
  4208. + // u4 attribute_length;
  4209. + // u2 local_variable_table_length;
  4210. + // {
  4211. + // u2 start_pc;
  4212. + // u2 length;
  4213. + // u2 name_index;
  4214. + // u2 descriptor_index;
  4215. + // u2 index;
  4216. + // }
  4217. + attr_size += 2 + 4 + 2 + local_variable_table_length * (2 + 2 + 2 + 2 + 2);
  4218. + }
  4219. + }
  4220. typeArrayHandle exception_table(thread(), const_method->exception_table());
  4221. int exception_table_length = exception_table->length();
  4222. @@ -188,6 +208,10 @@
  4223. write_stackmap_table_attribute(method, stackmap_len);
  4224. }
  4225. + if (local_variable_table_length != 0) {
  4226. + write_local_variable_table_attribute(method, local_variable_table_length);
  4227. + }
  4228. +
  4229. // FIXME: write LVT attribute
  4230. }
  4231. @@ -355,6 +379,36 @@
  4232. }
  4233. }
  4234. +// Write LineNumberTable attribute
  4235. +// JVMSpec| LocalVariableTable_attribute {
  4236. +// JVMSpec| u2 attribute_name_index;
  4237. +// JVMSpec| u4 attribute_length;
  4238. +// JVMSpec| u2 local_variable_table_length;
  4239. +// JVMSpec| { u2 start_pc;
  4240. +// JVMSpec| u2 length;
  4241. +// JVMSpec| u2 name_index;
  4242. +// JVMSpec| u2 descriptor_index;
  4243. +// JVMSpec| u2 index;
  4244. +// JVMSpec| } local_variable_table[local_variable_table_length];
  4245. +// JVMSpec| }
  4246. +void JvmtiClassFileReconstituter::write_local_variable_table_attribute(methodHandle method, u2 num_entries) {
  4247. + write_attribute_name_index("LocalVariableTable");
  4248. + write_u4(2 + num_entries * (2 + 2 + 2 + 2 + 2));
  4249. + write_u2(num_entries);
  4250. +
  4251. + assert(method->localvariable_table_length() == num_entries, "just checking");
  4252. +
  4253. + LocalVariableTableElement *elem = method->localvariable_table_start();
  4254. + for (int j=0; j<method->localvariable_table_length(); j++) {
  4255. + write_u2(elem->start_bci);
  4256. + write_u2(elem->length);
  4257. + write_u2(elem->name_cp_index);
  4258. + write_u2(elem->descriptor_cp_index);
  4259. + write_u2(elem->slot);
  4260. + elem++;
  4261. + }
  4262. +}
  4263. +
  4264. // Write stack map table attribute
  4265. // JSR-202| StackMapTable_attribute {
  4266. // JSR-202| u2 attribute_name_index;
  4267. diff -r f5603a6e5042 src/share/vm/prims/jvmtiClassFileReconstituter.hpp
  4268. --- a/src/share/vm/prims/jvmtiClassFileReconstituter.hpp Wed Nov 17 22:42:08 2010 -0800
  4269. +++ b/src/share/vm/prims/jvmtiClassFileReconstituter.hpp Fri Dec 17 13:24:08 2010 +0100
  4270. @@ -114,6 +114,7 @@
  4271. void write_source_debug_extension_attribute();
  4272. u2 line_number_table_entries(methodHandle method);
  4273. void write_line_number_table_attribute(methodHandle method, u2 num_entries);
  4274. + void write_local_variable_table_attribute(methodHandle method, u2 num_entries);
  4275. void write_stackmap_table_attribute(methodHandle method, int stackmap_table_len);
  4276. u2 inner_classes_attribute_length();
  4277. void write_inner_classes_attribute(int length);
  4278. diff -r f5603a6e5042 src/share/vm/prims/jvmtiEnv.cpp
  4279. --- a/src/share/vm/prims/jvmtiEnv.cpp Wed Nov 17 22:42:08 2010 -0800
  4280. +++ b/src/share/vm/prims/jvmtiEnv.cpp Fri Dec 17 13:24:08 2010 +0100
  4281. @@ -240,7 +240,10 @@
  4282. class_definitions[index].klass = jcls;
  4283. }
  4284. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  4285. - VMThread::execute(&op);
  4286. + {
  4287. + MutexLocker sd_mutex(RedefineClasses_lock);
  4288. + VMThread::execute(&op);
  4289. + }
  4290. return (op.check_error());
  4291. } /* end RetransformClasses */
  4292. @@ -249,9 +252,12 @@
  4293. // class_definitions - pre-checked for NULL
  4294. jvmtiError
  4295. JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
  4296. -//TODO: add locking
  4297. +
  4298. VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
  4299. - VMThread::execute(&op);
  4300. + {
  4301. + MutexLocker sd_mutex(RedefineClasses_lock);
  4302. + VMThread::execute(&op);
  4303. + }
  4304. return (op.check_error());
  4305. } /* end RedefineClasses */
  4306. diff -r f5603a6e5042 src/share/vm/prims/jvmtiExport.cpp
  4307. --- a/src/share/vm/prims/jvmtiExport.cpp Wed Nov 17 22:42:08 2010 -0800
  4308. +++ b/src/share/vm/prims/jvmtiExport.cpp Fri Dec 17 13:24:08 2010 +0100
  4309. @@ -756,7 +756,7 @@
  4310. void JvmtiExport::post_pending_compiled_method_unload_events() {
  4311. JavaThread* self = JavaThread::current();
  4312. - assert(!self->owns_locks(), "can't hold locks");
  4313. + assert(!self->owns_locks_but_redefine_classes_lock(), "can't hold locks");
  4314. // Indicates if this is the first activiation of this function.
  4315. // In theory the profiler's callback could call back into VM and provoke
  4316. @@ -2392,7 +2392,7 @@
  4317. // iterate over any code blob descriptors collected and post a
  4318. // DYNAMIC_CODE_GENERATED event to the profiler.
  4319. JvmtiDynamicCodeEventCollector::~JvmtiDynamicCodeEventCollector() {
  4320. - assert(!JavaThread::current()->owns_locks(), "all locks must be released to post deferred events");
  4321. + assert(!JavaThread::current()->owns_locks_but_redefine_classes_lock(), "all locks must be released to post deferred events");
  4322. // iterate over any code blob descriptors that we collected
  4323. if (_code_blobs != NULL) {
  4324. for (int i=0; i<_code_blobs->length(); i++) {
  4325. diff -r f5603a6e5042 src/share/vm/prims/jvmtiImpl.cpp
  4326. --- a/src/share/vm/prims/jvmtiImpl.cpp Wed Nov 17 22:42:08 2010 -0800
  4327. +++ b/src/share/vm/prims/jvmtiImpl.cpp Fri Dec 17 13:24:08 2010 +0100
  4328. @@ -254,6 +254,8 @@
  4329. void JvmtiBreakpoint::each_method_version_do(method_action meth_act) {
  4330. ((methodOopDesc*)_method->*meth_act)(_bci);
  4331. + // (tw) TODO: Check how we can implement this differently here!
  4332. +
  4333. // add/remove breakpoint to/from versions of the method that
  4334. // are EMCP. Directly or transitively obsolete methods are
  4335. // not saved in the PreviousVersionInfo.
  4336. @@ -293,10 +295,10 @@
  4337. for (int i = methods->length() - 1; i >= 0; i--) {
  4338. methodHandle method = methods->at(i);
  4339. if (method->name() == m_name && method->signature() == m_signature) {
  4340. - RC_TRACE(0x00000800, ("%sing breakpoint in %s(%s)",
  4341. + TRACE_RC3("%sing breakpoint in %s(%s)",
  4342. meth_act == &methodOopDesc::set_breakpoint ? "sett" : "clear",
  4343. method->name()->as_C_string(),
  4344. - method->signature()->as_C_string()));
  4345. + method->signature()->as_C_string());
  4346. assert(!method->is_obsolete(), "only EMCP methods here");
  4347. ((methodOopDesc*)method()->*meth_act)(_bci);
  4348. diff -r f5603a6e5042 src/share/vm/prims/jvmtiRedefineClasses.cpp
  4349. --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp Wed Nov 17 22:42:08 2010 -0800
  4350. +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp Fri Dec 17 13:24:08 2010 +0100
  4351. @@ -1,26 +1,26 @@
  4352. /*
  4353. - * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
  4354. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4355. - *
  4356. - * This code is free software; you can redistribute it and/or modify it
  4357. - * under the terms of the GNU General Public License version 2 only, as
  4358. - * published by the Free Software Foundation.
  4359. - *
  4360. - * This code is distributed in the hope that it will be useful, but WITHOUT
  4361. - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4362. - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4363. - * version 2 for more details (a copy is included in the LICENSE file that
  4364. - * accompanied this code).
  4365. - *
  4366. - * You should have received a copy of the GNU General Public License version
  4367. - * 2 along with this work; if not, write to the Free Software Foundation,
  4368. - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4369. - *
  4370. - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4371. - * or visit www.oracle.com if you need additional information or have any
  4372. - * questions.
  4373. - *
  4374. - */
  4375. +* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  4376. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4377. +*
  4378. +* This code is free software; you can redistribute it and/or modify it
  4379. +* under the terms of the GNU General Public License version 2 only, as
  4380. +* published by the Free Software Foundation.
  4381. +*
  4382. +* This code is distributed in the hope that it will be useful, but WITHOUT
  4383. +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4384. +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  4385. +* version 2 for more details (a copy is included in the LICENSE file that
  4386. +* accompanied this code).
  4387. +*
  4388. +* You should have received a copy of the GNU General Public License version
  4389. +* 2 along with this work; if not, write to the Free Software Foundation,
  4390. +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  4391. +*
  4392. +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  4393. +* or visit www.oracle.com if you need additional information or have any
  4394. +* questions.
  4395. +*
  4396. +*/
  4397. # include "incls/_precompiled.incl"
  4398. # include "incls/_jvmtiRedefineClasses.cpp.incl"
  4399. @@ -28,479 +28,600 @@
  4400. objArrayOop VM_RedefineClasses::_old_methods = NULL;
  4401. objArrayOop VM_RedefineClasses::_new_methods = NULL;
  4402. -methodOop* VM_RedefineClasses::_matching_old_methods = NULL;
  4403. -methodOop* VM_RedefineClasses::_matching_new_methods = NULL;
  4404. -methodOop* VM_RedefineClasses::_deleted_methods = NULL;
  4405. -methodOop* VM_RedefineClasses::_added_methods = NULL;
  4406. +int* VM_RedefineClasses::_matching_old_methods = NULL;
  4407. +int* VM_RedefineClasses::_matching_new_methods = NULL;
  4408. +int* VM_RedefineClasses::_deleted_methods = NULL;
  4409. +int* VM_RedefineClasses::_added_methods = NULL;
  4410. int VM_RedefineClasses::_matching_methods_length = 0;
  4411. int VM_RedefineClasses::_deleted_methods_length = 0;
  4412. int VM_RedefineClasses::_added_methods_length = 0;
  4413. klassOop VM_RedefineClasses::_the_class_oop = NULL;
  4414. -
  4415. -VM_RedefineClasses::VM_RedefineClasses(jint class_count,
  4416. - const jvmtiClassDefinition *class_defs,
  4417. - JvmtiClassLoadKind class_load_kind) {
  4418. +// Holds the revision number of the current class redefinition
  4419. +int VM_RedefineClasses::_revision_number = -1;
  4420. +
  4421. +VM_RedefineClasses::VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind)
  4422. + : VM_GC_Operation(Universe::heap()->total_full_collections()) {
  4423. + RC_TIMER_START(_timer_total);
  4424. _class_count = class_count;
  4425. _class_defs = class_defs;
  4426. _class_load_kind = class_load_kind;
  4427. - _res = JVMTI_ERROR_NONE;
  4428. + _updated_oops = NULL;
  4429. + _result = JVMTI_ERROR_NONE;
  4430. }
  4431. +VM_RedefineClasses::~VM_RedefineClasses() {
  4432. + unlock_threads();
  4433. + RC_TIMER_STOP(_timer_total);
  4434. +
  4435. + if (TimeRedefineClasses) {
  4436. + tty->print_cr("Timing Prologue: %d", _timer_prologue.milliseconds());
  4437. + tty->print_cr("Timing Class Loading: %d", _timer_class_loading.milliseconds());
  4438. + tty->print_cr("Timing Waiting for Lock: %d", _timer_wait_for_locks.milliseconds());
  4439. + tty->print_cr("Timing Class Linking: %d", _timer_class_linking.milliseconds());
  4440. + tty->print_cr("Timing Check Type: %d", _timer_check_type.milliseconds());
  4441. + tty->print_cr("Timing Prepare Redefinition: %d", _timer_prepare_redefinition.milliseconds());
  4442. + tty->print_cr("Timing Redefinition GC: %d", _timer_redefinition.milliseconds());
  4443. + tty->print_cr("Timing Epilogue: %d", _timer_vm_op_epilogue.milliseconds());
  4444. + tty->print_cr("------------------------------------------------------------------");
  4445. + tty->print_cr("Total Time: %d", _timer_total.milliseconds());
  4446. + }
  4447. +}
  4448. +
  4449. +// Searches for all affected classes and performs a sorting such that a supertype is always before a subtype.
  4450. +jvmtiError VM_RedefineClasses::find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses) {
  4451. +
  4452. + // Create array with all classes for which the redefine command was given
  4453. + GrowableArray<instanceKlassHandle> klasses_to_redefine;
  4454. + for (int i=0; i<_class_count; i++) {
  4455. + oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  4456. + instanceKlassHandle klass_handle(Thread::current(), java_lang_Class::as_klassOop(mirror));
  4457. + klasses_to_redefine.append(klass_handle);
  4458. + assert(klass_handle->new_version() == NULL, "Must be new class");
  4459. + }
  4460. +
  4461. + // Find classes not directly redefined, but affected by a redefinition (because one of its supertypes is redefined)
  4462. + GrowableArray<instanceKlassHandle> affected_classes;
  4463. + FindAffectedKlassesClosure closure(&klasses_to_redefine, &affected_classes);
  4464. +
  4465. + // Trace affected classes
  4466. + TRACE_RC1("Klasses affected: %d", affected_classes.length());
  4467. + IF_TRACE_RC2 {
  4468. + for (int i=0; i<affected_classes.length(); i++) {
  4469. + TRACE_RC2(affected_classes.at(i)->name()->as_C_string());
  4470. + }
  4471. + }
  4472. +
  4473. + // Add the array of affected classes and the array of redefined classes to get a list of all classes that need a redefinition
  4474. + all_affected_klasses->appendAll(&klasses_to_redefine);
  4475. + all_affected_klasses->appendAll(&affected_classes);
  4476. +
  4477. + // Sort the affected klasses such that a supertype is always on a smaller array index than its subtype.
  4478. + jvmtiError result = do_topological_class_sorting(_class_defs, _class_count, &affected_classes, all_affected_klasses, Thread::current());
  4479. + IF_TRACE_RC2 {
  4480. + TRACE_RC2("Redefine order: ");
  4481. + for (int i=0; i<all_affected_klasses->length(); i++) {
  4482. + TRACE_RC2("%s", all_affected_klasses->at(i)->name()->as_C_string());
  4483. + }
  4484. + }
  4485. +
  4486. + return result;
  4487. +}
  4488. +
  4489. +// Searches for the class bytes of the given class and returns them as a byte array.
  4490. +jvmtiError VM_RedefineClasses::find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed) {
  4491. +
  4492. + *not_changed = false;
  4493. +
  4494. + // Search for the index in the redefinition array that corresponds to the current class
  4495. + int j;
  4496. + for (j=0; j<_class_count; j++) {
  4497. + oop mirror = JNIHandles::resolve_non_null(_class_defs[j].klass);
  4498. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  4499. + if (the_class_oop == the_class()) {
  4500. + break;
  4501. + }
  4502. + }
  4503. +
  4504. + if (j == _class_count) {
  4505. +
  4506. + *not_changed = true;
  4507. +
  4508. + // Redefine with same bytecodes. This is a class that is only indirectly affected by redefinition,
  4509. + // so the user did not specify a different bytecode for that class.
  4510. +
  4511. + if (the_class->get_cached_class_file_bytes() == NULL) {
  4512. + // not cached, we need to reconstitute the class file from VM representation
  4513. + constantPoolHandle constants(Thread::current(), the_class->constants());
  4514. + ObjectLocker ol(constants, Thread::current()); // lock constant pool while we query it
  4515. +
  4516. + JvmtiClassFileReconstituter reconstituter(the_class);
  4517. + if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
  4518. + return reconstituter.get_error();
  4519. + }
  4520. +
  4521. + *class_byte_count = (jint)reconstituter.class_file_size();
  4522. + *class_bytes = (unsigned char*)reconstituter.class_file_bytes();
  4523. +
  4524. + } else {
  4525. +
  4526. + // it is cached, get it from the cache
  4527. + *class_byte_count = the_class->get_cached_class_file_len();
  4528. + *class_bytes = the_class->get_cached_class_file_bytes();
  4529. + }
  4530. +
  4531. + } else {
  4532. +
  4533. + // Redefine with bytecodes at index j
  4534. + *class_bytes = _class_defs[j].class_bytes;
  4535. + *class_byte_count = _class_defs[j].class_byte_count;
  4536. + }
  4537. +
  4538. + return JVMTI_ERROR_NONE;
  4539. +}
  4540. +
  4541. +// Prologue of the VM operation, called on the Java thread in parallel to normal program execution
  4542. bool VM_RedefineClasses::doit_prologue() {
  4543. - if (_class_count == 0) {
  4544. - _res = JVMTI_ERROR_NONE;
  4545. +
  4546. + _revision_number++;
  4547. + TRACE_RC1("Redefinition with revision number %d started!", _revision_number);
  4548. +
  4549. + assert(Thread::current()->is_Java_thread(), "must be Java thread");
  4550. + RC_TIMER_START(_timer_prologue);
  4551. +
  4552. + if (!check_arguments()) {
  4553. + RC_TIMER_STOP(_timer_prologue);
  4554. return false;
  4555. }
  4556. - if (_class_defs == NULL) {
  4557. - _res = JVMTI_ERROR_NULL_POINTER;
  4558. +
  4559. + // We first load new class versions in the prologue, because somewhere down the
  4560. + // call chain it is required that the current thread is a Java thread.
  4561. + _new_classes = new (ResourceObj::C_HEAP) GrowableArray<instanceKlassHandle>(5, true);
  4562. + _result = load_new_class_versions(Thread::current());
  4563. +
  4564. + TRACE_RC1("Loaded new class versions!");
  4565. + if (_result != JVMTI_ERROR_NONE) {
  4566. + TRACE_RC1("error occured: %d!", _result);
  4567. + delete _new_classes;
  4568. + _new_classes = NULL;
  4569. + RC_TIMER_STOP(_timer_prologue);
  4570. return false;
  4571. }
  4572. +
  4573. + TRACE_RC2("nearly finished");
  4574. + VM_GC_Operation::doit_prologue();
  4575. + RC_TIMER_STOP(_timer_prologue);
  4576. + TRACE_RC2("doit_prologue finished!");
  4577. + return true;
  4578. +}
  4579. +
  4580. +// Checks basic properties of the arguments of the redefinition command.
  4581. +bool VM_RedefineClasses::check_arguments() {
  4582. +
  4583. + if (_class_count == 0) RC_ABORT(JVMTI_ERROR_NONE);
  4584. + if (_class_defs == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4585. for (int i = 0; i < _class_count; i++) {
  4586. - if (_class_defs[i].klass == NULL) {
  4587. - _res = JVMTI_ERROR_INVALID_CLASS;
  4588. - return false;
  4589. + if (_class_defs[i].klass == NULL) RC_ABORT(JVMTI_ERROR_INVALID_CLASS);
  4590. + if (_class_defs[i].class_byte_count == 0) RC_ABORT(JVMTI_ERROR_INVALID_CLASS_FORMAT);
  4591. + if (_class_defs[i].class_bytes == NULL) RC_ABORT(JVMTI_ERROR_NULL_POINTER);
  4592. + }
  4593. +
  4594. + return true;
  4595. +}
  4596. +
  4597. +jvmtiError VM_RedefineClasses::check_exception() const {
  4598. + Thread* THREAD = Thread::current();
  4599. + if (HAS_PENDING_EXCEPTION) {
  4600. +
  4601. + symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  4602. + TRACE_RC1("parse_stream exception: '%s'", ex_name->as_C_string());
  4603. + if (TraceRedefineClasses >= 1) {
  4604. + java_lang_Throwable::print(PENDING_EXCEPTION, tty);
  4605. + tty->print_cr("");
  4606. }
  4607. - if (_class_defs[i].class_byte_count == 0) {
  4608. - _res = JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4609. - return false;
  4610. - }
  4611. - if (_class_defs[i].class_bytes == NULL) {
  4612. - _res = JVMTI_ERROR_NULL_POINTER;
  4613. - return false;
  4614. + CLEAR_PENDING_EXCEPTION;
  4615. +
  4616. + if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  4617. + return JVMTI_ERROR_UNSUPPORTED_VERSION;
  4618. + } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  4619. + return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  4620. + } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  4621. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  4622. + } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  4623. + // The message will be "XXX (wrong name: YYY)"
  4624. + return JVMTI_ERROR_NAMES_DONT_MATCH;
  4625. + } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  4626. + return JVMTI_ERROR_OUT_OF_MEMORY;
  4627. + } else {
  4628. + // Just in case more exceptions can be thrown..
  4629. + return JVMTI_ERROR_FAILS_VERIFICATION;
  4630. }
  4631. }
  4632. - // Start timer after all the sanity checks; not quite accurate, but
  4633. - // better than adding a bunch of stop() calls.
  4634. - RC_TIMER_START(_timer_vm_op_prologue);
  4635. -
  4636. - // We first load new class versions in the prologue, because somewhere down the
  4637. - // call chain it is required that the current thread is a Java thread.
  4638. - _res = load_new_class_versions(Thread::current());
  4639. - if (_res != JVMTI_ERROR_NONE) {
  4640. - // Free os::malloc allocated memory in load_new_class_version.
  4641. - os::free(_scratch_classes);
  4642. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4643. - return false;
  4644. + return JVMTI_ERROR_NONE;
  4645. +}
  4646. +
  4647. +// Loads all new class versions and stores the instanceKlass handles in an array.
  4648. +jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  4649. +
  4650. + ResourceMark rm(THREAD);
  4651. +
  4652. + TRACE_RC1("===================================================================");
  4653. + TRACE_RC1("load new class versions (%d)", _class_count);
  4654. +
  4655. + // Retrieve an array of all classes that need to be redefined
  4656. + GrowableArray<instanceKlassHandle> all_affected_klasses;
  4657. + jvmtiError err = find_sorted_affected_classes(&all_affected_klasses);
  4658. + if (err != JVMTI_ERROR_NONE) {
  4659. + TRACE_RC1("Error finding sorted affected classes: %d", (int)err);
  4660. + return err;
  4661. }
  4662. - RC_TIMER_STOP(_timer_vm_op_prologue);
  4663. - return true;
  4664. -}
  4665. -
  4666. -void VM_RedefineClasses::doit() {
  4667. - Thread *thread = Thread::current();
  4668. -
  4669. - if (UseSharedSpaces) {
  4670. - // Sharing is enabled so we remap the shared readonly space to
  4671. - // shared readwrite, private just in case we need to redefine
  4672. - // a shared class. We do the remap during the doit() phase of
  4673. - // the safepoint to be safer.
  4674. - if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  4675. - RC_TRACE_WITH_THREAD(0x00000001, thread,
  4676. - ("failed to remap shared readonly space to readwrite, private"));
  4677. - _res = JVMTI_ERROR_INTERNAL;
  4678. - return;
  4679. +
  4680. + JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  4681. +
  4682. + _max_redefinition_flags = Klass::NoRedefinition;
  4683. + jvmtiError result = JVMTI_ERROR_NONE;
  4684. +
  4685. + for (int i=0; i<all_affected_klasses.length(); i++) {
  4686. + TRACE_RC2("Processing affected class %d of %d", i+1, all_affected_klasses.length());
  4687. +
  4688. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  4689. + TRACE_RC2("name=%s", the_class->name()->as_C_string());
  4690. +
  4691. + the_class->link_class(THREAD);
  4692. + result = check_exception();
  4693. + if (result != JVMTI_ERROR_NONE) break;
  4694. +
  4695. + // Find new class bytes
  4696. + const unsigned char* class_bytes;
  4697. + jint class_byte_count;
  4698. + jvmtiError error;
  4699. + jboolean not_changed;
  4700. + if ((error = find_class_bytes(the_class, &class_bytes, &class_byte_count, &not_changed)) != JVMTI_ERROR_NONE) {
  4701. + TRACE_RC1("Error finding class bytes: %d", (int)error);
  4702. + result = error;
  4703. + break;
  4704. + }
  4705. + assert(class_bytes != NULL && class_byte_count != 0, "Class bytes defined at this point!");
  4706. +
  4707. +
  4708. + // Set redefined class handle in JvmtiThreadState class.
  4709. + // This redefined class is sent to agent event handler for class file
  4710. + // load hook event.
  4711. + state->set_class_being_redefined(&the_class, _class_load_kind);
  4712. +
  4713. + TRACE_RC2("Before resolving from stream");
  4714. +
  4715. + RC_TIMER_STOP(_timer_prologue);
  4716. + RC_TIMER_START(_timer_class_loading);
  4717. +
  4718. +
  4719. + // Parse the stream.
  4720. + Handle the_class_loader(THREAD, the_class->class_loader());
  4721. + Handle protection_domain(THREAD, the_class->protection_domain());
  4722. + symbolHandle the_class_sym = symbolHandle(THREAD, the_class->name());
  4723. + ClassFileStream st((u1*) class_bytes, class_byte_count, (char *)"__VM_RedefineClasses__");
  4724. + instanceKlassHandle new_class(THREAD, SystemDictionary::resolve_from_stream(the_class_sym,
  4725. + the_class_loader,
  4726. + protection_domain,
  4727. + &st,
  4728. + true,
  4729. + the_class,
  4730. + THREAD));
  4731. +
  4732. + not_changed = false;
  4733. +
  4734. + RC_TIMER_STOP(_timer_class_loading);
  4735. + RC_TIMER_START(_timer_prologue);
  4736. +
  4737. + TRACE_RC2("After resolving class from stream!");
  4738. + // Clear class_being_redefined just to be sure.
  4739. + state->clear_class_being_redefined();
  4740. +
  4741. + result = check_exception();
  4742. + if (result != JVMTI_ERROR_NONE) break;
  4743. +
  4744. +#ifdef ASSERT
  4745. +
  4746. + assert(new_class() != NULL, "Class could not be loaded!");
  4747. + assert(new_class() != the_class(), "must be different");
  4748. + assert(new_class->new_version() == NULL && new_class->old_version() != NULL, "");
  4749. +
  4750. +
  4751. + objArrayOop k_interfaces = new_class->local_interfaces();
  4752. + for (int j=0; j<k_interfaces->length(); j++) {
  4753. + assert(((klassOop)k_interfaces->obj_at(j))->klass_part()->is_newest_version(), "just checking");
  4754. + }
  4755. +
  4756. + if (!THREAD->is_Compiler_thread()) {
  4757. +
  4758. + 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()));
  4759. + // If we are on the compiler thread, we must not try to resolve a class.
  4760. + klassOop systemLookup = SystemDictionary::resolve_or_null(the_class->name(), the_class->class_loader(), the_class->protection_domain(), THREAD);
  4761. +
  4762. + if (systemLookup != NULL) {
  4763. + assert(systemLookup == new_class->old_version(), "Old class must be in system dictionary!");
  4764. +
  4765. +
  4766. + Klass *subklass = new_class()->klass_part()->subklass();
  4767. + while (subklass != NULL) {
  4768. + assert(subklass->new_version() == NULL, "Most recent version of class!");
  4769. + subklass = subklass->next_sibling();
  4770. + }
  4771. + } else {
  4772. + // This can happen for reflection generated classes.. ?
  4773. + CLEAR_PENDING_EXCEPTION;
  4774. + }
  4775. + }
  4776. +
  4777. +#endif
  4778. +
  4779. + IF_TRACE_RC1 {
  4780. + if (new_class->layout_helper() != the_class->layout_helper()) {
  4781. + 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());
  4782. + }
  4783. + }
  4784. +
  4785. + // Set the new version of the class
  4786. + new_class->set_revision_number(_revision_number);
  4787. + new_class->set_redefinition_index(i);
  4788. + the_class->set_new_version(new_class());
  4789. + _new_classes->append(new_class);
  4790. +
  4791. + assert(new_class->new_version() == NULL, "");
  4792. +
  4793. + int redefinition_flags = Klass::NoRedefinition;
  4794. +
  4795. + if (not_changed) {
  4796. + redefinition_flags = Klass::NoRedefinition;
  4797. + } else if (AllowAdvancedClassRedefinition) {
  4798. + redefinition_flags = calculate_redefinition_flags(new_class);
  4799. + if (redefinition_flags >= Klass::RemoveSuperType) {
  4800. + TRACE_RC1("Remove super type is not allowed");
  4801. + result = JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  4802. + break;
  4803. + }
  4804. + } else {
  4805. + jvmtiError allowed = check_redefinition_allowed(new_class);
  4806. + if (allowed != JVMTI_ERROR_NONE) {
  4807. + TRACE_RC1("Error redefinition not allowed!");
  4808. + result = allowed;
  4809. + break;
  4810. + }
  4811. + redefinition_flags = Klass::ModifyClass;
  4812. + }
  4813. +
  4814. + if (new_class->super() != NULL) {
  4815. + redefinition_flags = redefinition_flags | new_class->super()->klass_part()->redefinition_flags();
  4816. + }
  4817. +
  4818. + for (int j=0; j<new_class->local_interfaces()->length(); j++) {
  4819. + redefinition_flags = redefinition_flags | ((klassOop)new_class->local_interfaces()->obj_at(j))->klass_part()->redefinition_flags();
  4820. + }
  4821. +
  4822. + new_class->set_redefinition_flags(redefinition_flags);
  4823. +
  4824. + _max_redefinition_flags = _max_redefinition_flags | redefinition_flags;
  4825. +
  4826. + if ((redefinition_flags & Klass::ModifyInstances) != 0) {
  4827. + // TODO: Check if watch access flags of static fields are updated correctly.
  4828. + calculate_instance_update_information(_new_classes->at(i)());
  4829. + } else {
  4830. + assert(new_class->layout_helper() >> 1 == new_class->old_version()->klass_part()->layout_helper() >> 1, "must be equal");
  4831. + assert(new_class->fields()->length() == ((instanceKlass*)new_class->old_version()->klass_part())->fields()->length(), "must be equal");
  4832. +
  4833. + fieldDescriptor fd_new;
  4834. + fieldDescriptor fd_old;
  4835. + for (int i=0; i<new_class->fields()->length(); i+=instanceKlass::next_offset) {
  4836. + fd_new.initialize(new_class(), i);
  4837. + fd_old.initialize(new_class->old_version(), i);
  4838. + transfer_special_access_flags(&fd_old, &fd_new);
  4839. + }
  4840. + }
  4841. +
  4842. + IF_TRACE_RC3 {
  4843. + if (new_class->super() != NULL) {
  4844. + TRACE_RC3("Super class is %s", new_class->super()->klass_part()->name()->as_C_string());
  4845. + }
  4846. + }
  4847. +
  4848. +#ifdef ASSERT
  4849. + assert(new_class->super() == NULL || new_class->super()->klass_part()->new_version() == NULL, "Super klass must be newest version!");
  4850. +
  4851. + the_class->vtable()->verify(tty);
  4852. + new_class->vtable()->verify(tty);
  4853. +#endif
  4854. +
  4855. + TRACE_RC2("Verification done!");
  4856. +
  4857. + if (i == all_affected_klasses.length() - 1) {
  4858. +
  4859. + // This was the last class processed => check if additional classes have been loaded in the meantime
  4860. +
  4861. + RC_TIMER_STOP(_timer_prologue);
  4862. + lock_threads();
  4863. + RC_TIMER_START(_timer_prologue);
  4864. +
  4865. + for (int j=0; j<all_affected_klasses.length(); j++) {
  4866. +
  4867. + klassOop initial_klass = all_affected_klasses.at(j)();
  4868. + Klass *initial_subklass = initial_klass->klass_part()->subklass();
  4869. + Klass *cur_klass = initial_subklass;
  4870. + while(cur_klass != NULL) {
  4871. +
  4872. + if(cur_klass->oop_is_instance() && cur_klass->is_newest_version()) {
  4873. + instanceKlassHandle handle(THREAD, cur_klass->as_klassOop());
  4874. + if (!all_affected_klasses.contains(handle)) {
  4875. +
  4876. + int k = i + 1;
  4877. + for (; k<all_affected_klasses.length(); k++) {
  4878. + if (all_affected_klasses.at(k)->is_subtype_of(cur_klass->as_klassOop())) {
  4879. + break;
  4880. + }
  4881. + }
  4882. + all_affected_klasses.insert_before(k, handle);
  4883. + TRACE_RC2("Adding newly loaded class to affected classes: %s", cur_klass->name()->as_C_string());
  4884. + }
  4885. + }
  4886. +
  4887. + cur_klass = cur_klass->next_sibling();
  4888. + }
  4889. + }
  4890. +
  4891. + int new_count = all_affected_klasses.length() - 1 - i;
  4892. + if (new_count != 0) {
  4893. +
  4894. + unlock_threads();
  4895. + TRACE_RC1("Found new number of affected classes: %d", new_count);
  4896. + }
  4897. }
  4898. }
  4899. - for (int i = 0; i < _class_count; i++) {
  4900. - redefine_single_class(_class_defs[i].klass, _scratch_classes[i], thread);
  4901. + if (result != JVMTI_ERROR_NONE) {
  4902. + rollback();
  4903. + return result;
  4904. }
  4905. - // Disable any dependent concurrent compilations
  4906. - SystemDictionary::notice_modification();
  4907. -
  4908. - // Set flag indicating that some invariants are no longer true.
  4909. - // See jvmtiExport.hpp for detailed explanation.
  4910. - JvmtiExport::set_has_redefined_a_class();
  4911. +
  4912. + RC_TIMER_STOP(_timer_prologue);
  4913. + RC_TIMER_START(_timer_class_linking);
  4914. + // Link and verify new classes _after_ all classes have been updated in the system dictionary!
  4915. + for (int i=0; i<all_affected_klasses.length(); i++) {
  4916. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  4917. + instanceKlassHandle new_class(the_class->new_version());
  4918. +
  4919. + TRACE_RC2("Linking class %d/%d %s", i, all_affected_klasses.length(), the_class->name()->as_C_string());
  4920. + new_class->link_class(THREAD);
  4921. +
  4922. + result = check_exception();
  4923. + if (result != JVMTI_ERROR_NONE) break;
  4924. + }
  4925. + RC_TIMER_STOP(_timer_class_linking);
  4926. + RC_TIMER_START(_timer_prologue);
  4927. +
  4928. + if (result != JVMTI_ERROR_NONE) {
  4929. + rollback();
  4930. + return result;
  4931. + }
  4932. +
  4933. + TRACE_RC2("All classes loaded!");
  4934. #ifdef ASSERT
  4935. - SystemDictionary::classes_do(check_class, thread);
  4936. + for (int i=0; i<all_affected_klasses.length(); i++) {
  4937. + instanceKlassHandle the_class = all_affected_klasses.at(i);
  4938. + assert(the_class->new_version() != NULL, "Must have been redefined");
  4939. + instanceKlassHandle new_version = instanceKlassHandle(THREAD, the_class->new_version());
  4940. + assert(new_version->new_version() == NULL, "Must be newest version");
  4941. +
  4942. + if (!(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL)) {
  4943. + new_version()->print();
  4944. + new_version->super()->print();
  4945. + }
  4946. + assert(new_version->super() == NULL || new_version->super()->klass_part()->new_version() == NULL, "Super class must be newest version");
  4947. + }
  4948. +
  4949. + SystemDictionary::classes_do(check_class, THREAD);
  4950. +
  4951. #endif
  4952. +
  4953. + TRACE_RC1("Finished verification!");
  4954. + return JVMTI_ERROR_NONE;
  4955. }
  4956. -void VM_RedefineClasses::doit_epilogue() {
  4957. - // Free os::malloc allocated memory.
  4958. - // The memory allocated in redefine will be free'ed in next VM operation.
  4959. - os::free(_scratch_classes);
  4960. -
  4961. - if (RC_TRACE_ENABLED(0x00000004)) {
  4962. - // Used to have separate timers for "doit" and "all", but the timer
  4963. - // overhead skewed the measurements.
  4964. - jlong doit_time = _timer_rsc_phase1.milliseconds() +
  4965. - _timer_rsc_phase2.milliseconds();
  4966. - jlong all_time = _timer_vm_op_prologue.milliseconds() + doit_time;
  4967. -
  4968. - RC_TRACE(0x00000004, ("vm_op: all=" UINT64_FORMAT
  4969. - " prologue=" UINT64_FORMAT " doit=" UINT64_FORMAT, all_time,
  4970. - _timer_vm_op_prologue.milliseconds(), doit_time));
  4971. - RC_TRACE(0x00000004,
  4972. - ("redefine_single_class: phase1=" UINT64_FORMAT " phase2=" UINT64_FORMAT,
  4973. - _timer_rsc_phase1.milliseconds(), _timer_rsc_phase2.milliseconds()));
  4974. +void VM_RedefineClasses::lock_threads() {
  4975. +
  4976. + RC_TIMER_START(_timer_wait_for_locks);
  4977. +
  4978. +
  4979. + JavaThread *javaThread = Threads::first();
  4980. + while (javaThread != NULL) {
  4981. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  4982. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  4983. + compilerThread->set_should_bailout(true);
  4984. + }
  4985. + javaThread = javaThread->next();
  4986. }
  4987. +
  4988. + int cnt = 0;
  4989. + javaThread = Threads::first();
  4990. + while (javaThread != NULL) {
  4991. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  4992. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  4993. + compilerThread->compilation_mutex()->lock();
  4994. + cnt++;
  4995. + }
  4996. + javaThread = javaThread->next();
  4997. + }
  4998. +
  4999. + TRACE_RC2("Locked %d compiler threads", cnt);
  5000. +
  5001. + cnt = 0;
  5002. + javaThread = Threads::first();
  5003. + while (javaThread != NULL) {
  5004. + if (javaThread != Thread::current()) {
  5005. + javaThread->redefine_classes_mutex()->lock();
  5006. + }
  5007. + javaThread = javaThread->next();
  5008. + }
  5009. +
  5010. +
  5011. + TRACE_RC2("Locked %d threads", cnt);
  5012. +
  5013. + RC_TIMER_STOP(_timer_wait_for_locks);
  5014. }
  5015. -bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  5016. - // classes for primitives cannot be redefined
  5017. - if (java_lang_Class::is_primitive(klass_mirror)) {
  5018. - return false;
  5019. +void VM_RedefineClasses::unlock_threads() {
  5020. +
  5021. + int cnt = 0;
  5022. + JavaThread *javaThread = Threads::first();
  5023. + Thread *thread = Thread::current();
  5024. + while (javaThread != NULL) {
  5025. + if (javaThread->is_Compiler_thread() && javaThread != Thread::current()) {
  5026. + CompilerThread *compilerThread = (CompilerThread *)javaThread;
  5027. + if (compilerThread->compilation_mutex()->owned_by_self()) {
  5028. + compilerThread->compilation_mutex()->unlock();
  5029. + cnt++;
  5030. + }
  5031. + }
  5032. + javaThread = javaThread->next();
  5033. }
  5034. - klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  5035. - // classes for arrays cannot be redefined
  5036. - if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  5037. - return false;
  5038. +
  5039. + TRACE_RC2("Unlocked %d compiler threads", cnt);
  5040. +
  5041. + cnt = 0;
  5042. + javaThread = Threads::first();
  5043. + while (javaThread != NULL) {
  5044. + if (javaThread != Thread::current()) {
  5045. + if (javaThread->redefine_classes_mutex()->owned_by_self()) {
  5046. + javaThread->redefine_classes_mutex()->unlock();
  5047. + }
  5048. + }
  5049. + javaThread = javaThread->next();
  5050. }
  5051. - return true;
  5052. +
  5053. + TRACE_RC2("Unlocked %d threads", cnt);
  5054. }
  5055. -// Append the current entry at scratch_i in scratch_cp to *merge_cp_p
  5056. -// where the end of *merge_cp_p is specified by *merge_cp_length_p. For
  5057. -// direct CP entries, there is just the current entry to append. For
  5058. -// indirect and double-indirect CP entries, there are zero or more
  5059. -// referenced CP entries along with the current entry to append.
  5060. -// Indirect and double-indirect CP entries are handled by recursive
  5061. -// calls to append_entry() as needed. The referenced CP entries are
  5062. -// always appended to *merge_cp_p before the referee CP entry. These
  5063. -// referenced CP entries may already exist in *merge_cp_p in which case
  5064. -// there is nothing extra to append and only the current entry is
  5065. -// appended.
  5066. -void VM_RedefineClasses::append_entry(constantPoolHandle scratch_cp,
  5067. - int scratch_i, constantPoolHandle *merge_cp_p, int *merge_cp_length_p,
  5068. - TRAPS) {
  5069. -
  5070. - // append is different depending on entry tag type
  5071. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5072. -
  5073. - // The old verifier is implemented outside the VM. It loads classes,
  5074. - // but does not resolve constant pool entries directly so we never
  5075. - // see Class entries here with the old verifier. Similarly the old
  5076. - // verifier does not like Class entries in the input constant pool.
  5077. - // The split-verifier is implemented in the VM so it can optionally
  5078. - // and directly resolve constant pool entries to load classes. The
  5079. - // split-verifier can accept either Class entries or UnresolvedClass
  5080. - // entries in the input constant pool. We revert the appended copy
  5081. - // back to UnresolvedClass so that either verifier will be happy
  5082. - // with the constant pool entry.
  5083. - case JVM_CONSTANT_Class:
  5084. - {
  5085. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  5086. - (*merge_cp_p)->unresolved_klass_at_put(*merge_cp_length_p,
  5087. - scratch_cp->klass_name_at(scratch_i));
  5088. -
  5089. - if (scratch_i != *merge_cp_length_p) {
  5090. - // The new entry in *merge_cp_p is at a different index than
  5091. - // the new entry in scratch_cp so we need to map the index values.
  5092. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5093. - }
  5094. - (*merge_cp_length_p)++;
  5095. - } break;
  5096. -
  5097. - // these are direct CP entries so they can be directly appended,
  5098. - // but double and long take two constant pool entries
  5099. - case JVM_CONSTANT_Double: // fall through
  5100. - case JVM_CONSTANT_Long:
  5101. - {
  5102. - scratch_cp->copy_entry_to(scratch_i, *merge_cp_p, *merge_cp_length_p,
  5103. - THREAD);
  5104. -
  5105. - if (scratch_i != *merge_cp_length_p) {
  5106. - // The new entry in *merge_cp_p is at a different index than
  5107. - // the new entry in scratch_cp so we need to map the index values.
  5108. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5109. - }
  5110. - (*merge_cp_length_p) += 2;
  5111. - } break;
  5112. -
  5113. - // these are direct CP entries so they can be directly appended
  5114. - case JVM_CONSTANT_Float: // fall through
  5115. - case JVM_CONSTANT_Integer: // fall through
  5116. - case JVM_CONSTANT_Utf8: // fall through
  5117. -
  5118. - // This was an indirect CP entry, but it has been changed into
  5119. - // an interned string so this entry can be directly appended.
  5120. - case JVM_CONSTANT_String: // fall through
  5121. -
  5122. - // These were indirect CP entries, but they have been changed into
  5123. - // symbolOops so these entries can be directly appended.
  5124. - case JVM_CONSTANT_UnresolvedClass: // fall through
  5125. - case JVM_CONSTANT_UnresolvedString:
  5126. - {
  5127. - scratch_cp->copy_entry_to(scratch_i, *merge_cp_p, *merge_cp_length_p,
  5128. - THREAD);
  5129. -
  5130. - if (scratch_i != *merge_cp_length_p) {
  5131. - // The new entry in *merge_cp_p is at a different index than
  5132. - // the new entry in scratch_cp so we need to map the index values.
  5133. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5134. - }
  5135. - (*merge_cp_length_p)++;
  5136. - } break;
  5137. -
  5138. - // this is an indirect CP entry so it needs special handling
  5139. - case JVM_CONSTANT_NameAndType:
  5140. - {
  5141. - int name_ref_i = scratch_cp->name_ref_index_at(scratch_i);
  5142. - int new_name_ref_i = 0;
  5143. - bool match = (name_ref_i < *merge_cp_length_p) &&
  5144. - scratch_cp->compare_entry_to(name_ref_i, *merge_cp_p, name_ref_i,
  5145. - THREAD);
  5146. - if (!match) {
  5147. - // forward reference in *merge_cp_p or not a direct match
  5148. -
  5149. - int found_i = scratch_cp->find_matching_entry(name_ref_i, *merge_cp_p,
  5150. - THREAD);
  5151. - if (found_i != 0) {
  5152. - guarantee(found_i != name_ref_i,
  5153. - "compare_entry_to() and find_matching_entry() do not agree");
  5154. -
  5155. - // Found a matching entry somewhere else in *merge_cp_p so
  5156. - // just need a mapping entry.
  5157. - new_name_ref_i = found_i;
  5158. - map_index(scratch_cp, name_ref_i, found_i);
  5159. - } else {
  5160. - // no match found so we have to append this entry to *merge_cp_p
  5161. - append_entry(scratch_cp, name_ref_i, merge_cp_p, merge_cp_length_p,
  5162. - THREAD);
  5163. - // The above call to append_entry() can only append one entry
  5164. - // so the post call query of *merge_cp_length_p is only for
  5165. - // the sake of consistency.
  5166. - new_name_ref_i = *merge_cp_length_p - 1;
  5167. - }
  5168. - }
  5169. -
  5170. - int signature_ref_i = scratch_cp->signature_ref_index_at(scratch_i);
  5171. - int new_signature_ref_i = 0;
  5172. - match = (signature_ref_i < *merge_cp_length_p) &&
  5173. - scratch_cp->compare_entry_to(signature_ref_i, *merge_cp_p,
  5174. - signature_ref_i, THREAD);
  5175. - if (!match) {
  5176. - // forward reference in *merge_cp_p or not a direct match
  5177. -
  5178. - int found_i = scratch_cp->find_matching_entry(signature_ref_i,
  5179. - *merge_cp_p, THREAD);
  5180. - if (found_i != 0) {
  5181. - guarantee(found_i != signature_ref_i,
  5182. - "compare_entry_to() and find_matching_entry() do not agree");
  5183. -
  5184. - // Found a matching entry somewhere else in *merge_cp_p so
  5185. - // just need a mapping entry.
  5186. - new_signature_ref_i = found_i;
  5187. - map_index(scratch_cp, signature_ref_i, found_i);
  5188. - } else {
  5189. - // no match found so we have to append this entry to *merge_cp_p
  5190. - append_entry(scratch_cp, signature_ref_i, merge_cp_p,
  5191. - merge_cp_length_p, THREAD);
  5192. - // The above call to append_entry() can only append one entry
  5193. - // so the post call query of *merge_cp_length_p is only for
  5194. - // the sake of consistency.
  5195. - new_signature_ref_i = *merge_cp_length_p - 1;
  5196. - }
  5197. - }
  5198. -
  5199. - // If the referenced entries already exist in *merge_cp_p, then
  5200. - // both new_name_ref_i and new_signature_ref_i will both be 0.
  5201. - // In that case, all we are appending is the current entry.
  5202. - if (new_name_ref_i == 0) {
  5203. - new_name_ref_i = name_ref_i;
  5204. - } else {
  5205. - RC_TRACE(0x00080000,
  5206. - ("NameAndType entry@%d name_ref_index change: %d to %d",
  5207. - *merge_cp_length_p, name_ref_i, new_name_ref_i));
  5208. - }
  5209. - if (new_signature_ref_i == 0) {
  5210. - new_signature_ref_i = signature_ref_i;
  5211. - } else {
  5212. - RC_TRACE(0x00080000,
  5213. - ("NameAndType entry@%d signature_ref_index change: %d to %d",
  5214. - *merge_cp_length_p, signature_ref_i, new_signature_ref_i));
  5215. - }
  5216. -
  5217. - (*merge_cp_p)->name_and_type_at_put(*merge_cp_length_p,
  5218. - new_name_ref_i, new_signature_ref_i);
  5219. - if (scratch_i != *merge_cp_length_p) {
  5220. - // The new entry in *merge_cp_p is at a different index than
  5221. - // the new entry in scratch_cp so we need to map the index values.
  5222. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5223. - }
  5224. - (*merge_cp_length_p)++;
  5225. - } break;
  5226. -
  5227. - // this is a double-indirect CP entry so it needs special handling
  5228. - case JVM_CONSTANT_Fieldref: // fall through
  5229. - case JVM_CONSTANT_InterfaceMethodref: // fall through
  5230. - case JVM_CONSTANT_Methodref:
  5231. - {
  5232. - int klass_ref_i = scratch_cp->uncached_klass_ref_index_at(scratch_i);
  5233. - int new_klass_ref_i = 0;
  5234. - bool match = (klass_ref_i < *merge_cp_length_p) &&
  5235. - scratch_cp->compare_entry_to(klass_ref_i, *merge_cp_p, klass_ref_i,
  5236. - THREAD);
  5237. - if (!match) {
  5238. - // forward reference in *merge_cp_p or not a direct match
  5239. -
  5240. - int found_i = scratch_cp->find_matching_entry(klass_ref_i, *merge_cp_p,
  5241. - THREAD);
  5242. - if (found_i != 0) {
  5243. - guarantee(found_i != klass_ref_i,
  5244. - "compare_entry_to() and find_matching_entry() do not agree");
  5245. -
  5246. - // Found a matching entry somewhere else in *merge_cp_p so
  5247. - // just need a mapping entry.
  5248. - new_klass_ref_i = found_i;
  5249. - map_index(scratch_cp, klass_ref_i, found_i);
  5250. - } else {
  5251. - // no match found so we have to append this entry to *merge_cp_p
  5252. - append_entry(scratch_cp, klass_ref_i, merge_cp_p, merge_cp_length_p,
  5253. - THREAD);
  5254. - // The above call to append_entry() can only append one entry
  5255. - // so the post call query of *merge_cp_length_p is only for
  5256. - // the sake of consistency. Without the optimization where we
  5257. - // use JVM_CONSTANT_UnresolvedClass, then up to two entries
  5258. - // could be appended.
  5259. - new_klass_ref_i = *merge_cp_length_p - 1;
  5260. - }
  5261. - }
  5262. -
  5263. - int name_and_type_ref_i =
  5264. - scratch_cp->uncached_name_and_type_ref_index_at(scratch_i);
  5265. - int new_name_and_type_ref_i = 0;
  5266. - match = (name_and_type_ref_i < *merge_cp_length_p) &&
  5267. - scratch_cp->compare_entry_to(name_and_type_ref_i, *merge_cp_p,
  5268. - name_and_type_ref_i, THREAD);
  5269. - if (!match) {
  5270. - // forward reference in *merge_cp_p or not a direct match
  5271. -
  5272. - int found_i = scratch_cp->find_matching_entry(name_and_type_ref_i,
  5273. - *merge_cp_p, THREAD);
  5274. - if (found_i != 0) {
  5275. - guarantee(found_i != name_and_type_ref_i,
  5276. - "compare_entry_to() and find_matching_entry() do not agree");
  5277. -
  5278. - // Found a matching entry somewhere else in *merge_cp_p so
  5279. - // just need a mapping entry.
  5280. - new_name_and_type_ref_i = found_i;
  5281. - map_index(scratch_cp, name_and_type_ref_i, found_i);
  5282. - } else {
  5283. - // no match found so we have to append this entry to *merge_cp_p
  5284. - append_entry(scratch_cp, name_and_type_ref_i, merge_cp_p,
  5285. - merge_cp_length_p, THREAD);
  5286. - // The above call to append_entry() can append more than
  5287. - // one entry so the post call query of *merge_cp_length_p
  5288. - // is required in order to get the right index for the
  5289. - // JVM_CONSTANT_NameAndType entry.
  5290. - new_name_and_type_ref_i = *merge_cp_length_p - 1;
  5291. - }
  5292. - }
  5293. -
  5294. - // If the referenced entries already exist in *merge_cp_p, then
  5295. - // both new_klass_ref_i and new_name_and_type_ref_i will both be
  5296. - // 0. In that case, all we are appending is the current entry.
  5297. - if (new_klass_ref_i == 0) {
  5298. - new_klass_ref_i = klass_ref_i;
  5299. - }
  5300. - if (new_name_and_type_ref_i == 0) {
  5301. - new_name_and_type_ref_i = name_and_type_ref_i;
  5302. - }
  5303. -
  5304. - const char *entry_name;
  5305. - switch (scratch_cp->tag_at(scratch_i).value()) {
  5306. - case JVM_CONSTANT_Fieldref:
  5307. - entry_name = "Fieldref";
  5308. - (*merge_cp_p)->field_at_put(*merge_cp_length_p, new_klass_ref_i,
  5309. - new_name_and_type_ref_i);
  5310. - break;
  5311. - case JVM_CONSTANT_InterfaceMethodref:
  5312. - entry_name = "IFMethodref";
  5313. - (*merge_cp_p)->interface_method_at_put(*merge_cp_length_p,
  5314. - new_klass_ref_i, new_name_and_type_ref_i);
  5315. - break;
  5316. - case JVM_CONSTANT_Methodref:
  5317. - entry_name = "Methodref";
  5318. - (*merge_cp_p)->method_at_put(*merge_cp_length_p, new_klass_ref_i,
  5319. - new_name_and_type_ref_i);
  5320. - break;
  5321. - default:
  5322. - guarantee(false, "bad switch");
  5323. - break;
  5324. - }
  5325. -
  5326. - if (klass_ref_i != new_klass_ref_i) {
  5327. - RC_TRACE(0x00080000, ("%s entry@%d class_index changed: %d to %d",
  5328. - entry_name, *merge_cp_length_p, klass_ref_i, new_klass_ref_i));
  5329. - }
  5330. - if (name_and_type_ref_i != new_name_and_type_ref_i) {
  5331. - RC_TRACE(0x00080000,
  5332. - ("%s entry@%d name_and_type_index changed: %d to %d",
  5333. - entry_name, *merge_cp_length_p, name_and_type_ref_i,
  5334. - new_name_and_type_ref_i));
  5335. - }
  5336. -
  5337. - if (scratch_i != *merge_cp_length_p) {
  5338. - // The new entry in *merge_cp_p is at a different index than
  5339. - // the new entry in scratch_cp so we need to map the index values.
  5340. - map_index(scratch_cp, scratch_i, *merge_cp_length_p);
  5341. - }
  5342. - (*merge_cp_length_p)++;
  5343. - } break;
  5344. -
  5345. - // At this stage, Class or UnresolvedClass could be here, but not
  5346. - // ClassIndex
  5347. - case JVM_CONSTANT_ClassIndex: // fall through
  5348. -
  5349. - // Invalid is used as the tag for the second constant pool entry
  5350. - // occupied by JVM_CONSTANT_Double or JVM_CONSTANT_Long. It should
  5351. - // not be seen by itself.
  5352. - case JVM_CONSTANT_Invalid: // fall through
  5353. -
  5354. - // At this stage, String or UnresolvedString could be here, but not
  5355. - // StringIndex
  5356. - case JVM_CONSTANT_StringIndex: // fall through
  5357. -
  5358. - // At this stage JVM_CONSTANT_UnresolvedClassInError should not be
  5359. - // here
  5360. - case JVM_CONSTANT_UnresolvedClassInError: // fall through
  5361. -
  5362. - default:
  5363. - {
  5364. - // leave a breadcrumb
  5365. - jbyte bad_value = scratch_cp->tag_at(scratch_i).value();
  5366. - ShouldNotReachHere();
  5367. - } break;
  5368. - } // end switch tag value
  5369. -} // end append_entry()
  5370. -
  5371. -
  5372. -void VM_RedefineClasses::swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class) {
  5373. - typeArrayOop save;
  5374. -
  5375. - save = scratch_class->get_method_annotations_of(i);
  5376. - scratch_class->set_method_annotations_of(i, scratch_class->get_method_annotations_of(j));
  5377. - scratch_class->set_method_annotations_of(j, save);
  5378. -
  5379. - save = scratch_class->get_method_parameter_annotations_of(i);
  5380. - scratch_class->set_method_parameter_annotations_of(i, scratch_class->get_method_parameter_annotations_of(j));
  5381. - scratch_class->set_method_parameter_annotations_of(j, save);
  5382. -
  5383. - save = scratch_class->get_method_default_annotations_of(i);
  5384. - scratch_class->set_method_default_annotations_of(i, scratch_class->get_method_default_annotations_of(j));
  5385. - scratch_class->set_method_default_annotations_of(j, save);
  5386. -}
  5387. -
  5388. -
  5389. -jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions(
  5390. - instanceKlassHandle the_class,
  5391. - instanceKlassHandle scratch_class) {
  5392. +jvmtiError VM_RedefineClasses::check_redefinition_allowed(instanceKlassHandle scratch_class) {
  5393. +
  5394. +
  5395. +
  5396. + // Compatibility mode => check for unsupported modification
  5397. +
  5398. +
  5399. + assert(scratch_class->old_version() != NULL, "must have old version");
  5400. + instanceKlassHandle the_class(scratch_class->old_version());
  5401. +
  5402. int i;
  5403. // Check superclasses, or rather their names, since superclasses themselves can be
  5404. // requested to replace.
  5405. // Check for NULL superclass first since this might be java.lang.Object
  5406. if (the_class->super() != scratch_class->super() &&
  5407. - (the_class->super() == NULL || scratch_class->super() == NULL ||
  5408. - Klass::cast(the_class->super())->name() !=
  5409. - Klass::cast(scratch_class->super())->name())) {
  5410. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5411. + (the_class->super() == NULL || scratch_class->super() == NULL ||
  5412. + Klass::cast(the_class->super())->name() !=
  5413. + Klass::cast(scratch_class->super())->name())) {
  5414. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5415. }
  5416. // Check if the number, names and order of directly implemented interfaces are the same.
  5417. @@ -518,8 +639,8 @@
  5418. }
  5419. for (i = 0; i < n_intfs; i++) {
  5420. if (Klass::cast((klassOop) k_interfaces->obj_at(i))->name() !=
  5421. - Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5422. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5423. + Klass::cast((klassOop) k_new_interfaces->obj_at(i))->name()) {
  5424. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED;
  5425. }
  5426. }
  5427. @@ -554,10 +675,10 @@
  5428. }
  5429. // offset
  5430. if (k_old_fields->short_at(i + instanceKlass::low_offset) !=
  5431. - k_new_fields->short_at(i + instanceKlass::low_offset) ||
  5432. - k_old_fields->short_at(i + instanceKlass::high_offset) !=
  5433. - k_new_fields->short_at(i + instanceKlass::high_offset)) {
  5434. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED;
  5435. + k_new_fields->short_at(i + instanceKlass::low_offset) ||
  5436. + k_old_fields->short_at(i + instanceKlass::high_offset) !=
  5437. + k_new_fields->short_at(i + instanceKlass::high_offset)) {
  5438. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED;
  5439. }
  5440. // name and signature
  5441. jshort name_index = k_old_fields->short_at(i + instanceKlass::name_index_offset);
  5442. @@ -573,6 +694,7 @@
  5443. }
  5444. }
  5445. +
  5446. // Do a parallel walk through the old and new methods. Detect
  5447. // cases where they match (exist in both), have been added in
  5448. // the new methods, or have been deleted (exist only in the
  5449. @@ -674,12 +796,8 @@
  5450. idnum_owner->set_method_idnum(new_num);
  5451. }
  5452. k_new_method->set_method_idnum(old_num);
  5453. - swap_all_method_annotations(old_num, new_num, scratch_class);
  5454. }
  5455. }
  5456. - RC_TRACE(0x00008000, ("Method matched: new: %s [%d] == old: %s [%d]",
  5457. - k_new_method->name_and_sig_as_C_string(), ni,
  5458. - k_old_method->name_and_sig_as_C_string(), oi));
  5459. // advance to next pair of methods
  5460. ++oi;
  5461. ++ni;
  5462. @@ -688,11 +806,11 @@
  5463. // method added, see if it is OK
  5464. new_flags = (jushort) k_new_method->access_flags().get_flags();
  5465. if ((new_flags & JVM_ACC_PRIVATE) == 0
  5466. - // hack: private should be treated as final, but alas
  5467. - || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5468. - ) {
  5469. - // new methods must be private
  5470. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5471. + // hack: private should be treated as final, but alas
  5472. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5473. + ) {
  5474. + // new methods must be private
  5475. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED;
  5476. }
  5477. {
  5478. u2 num = the_class->next_method_idnum();
  5479. @@ -707,24 +825,19 @@
  5480. idnum_owner->set_method_idnum(new_num);
  5481. }
  5482. k_new_method->set_method_idnum(num);
  5483. - swap_all_method_annotations(new_num, num, scratch_class);
  5484. }
  5485. - RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  5486. - k_new_method->name_and_sig_as_C_string(), ni));
  5487. ++ni; // advance to next new method
  5488. break;
  5489. case deleted:
  5490. // method deleted, see if it is OK
  5491. old_flags = (jushort) k_old_method->access_flags().get_flags();
  5492. if ((old_flags & JVM_ACC_PRIVATE) == 0
  5493. - // hack: private should be treated as final, but alas
  5494. - || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5495. - ) {
  5496. - // deleted methods must be private
  5497. - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5498. + // hack: private should be treated as final, but alas
  5499. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5500. + ) {
  5501. + // deleted methods must be private
  5502. + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED;
  5503. }
  5504. - RC_TRACE(0x00008000, ("Method deleted: old: %s [%d]",
  5505. - k_old_method->name_and_sig_as_C_string(), oi));
  5506. ++oi; // advance to next old method
  5507. break;
  5508. default:
  5509. @@ -735,2081 +848,1502 @@
  5510. return JVMTI_ERROR_NONE;
  5511. }
  5512. -
  5513. -// Find new constant pool index value for old constant pool index value
  5514. -// by seaching the index map. Returns zero (0) if there is no mapped
  5515. -// value for the old constant pool index.
  5516. -int VM_RedefineClasses::find_new_index(int old_index) {
  5517. - if (_index_map_count == 0) {
  5518. - // map is empty so nothing can be found
  5519. - return 0;
  5520. +int VM_RedefineClasses::calculate_redefinition_flags(instanceKlassHandle new_class) {
  5521. +
  5522. + int result = Klass::NoRedefinition;
  5523. +
  5524. +
  5525. +
  5526. + TRACE_RC2("Comparing different class versions of class %s", new_class->name()->as_C_string());
  5527. +
  5528. + assert(new_class->old_version() != NULL, "must have old version");
  5529. + instanceKlassHandle the_class(new_class->old_version());
  5530. +
  5531. + // Check whether class is in the error init state.
  5532. + if (the_class->is_in_error_state()) {
  5533. + // TBD #5057930: special error code is needed in 1.6
  5534. + //result = Klass::union_redefinition_level(result, Klass::Invalid);
  5535. }
  5536. - if (old_index < 1 || old_index >= _index_map_p->length()) {
  5537. - // The old_index is out of range so it is not mapped. This should
  5538. - // not happen in regular constant pool merging use, but it can
  5539. - // happen if a corrupt annotation is processed.
  5540. - return 0;
  5541. + int i;
  5542. +
  5543. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5544. + // Check superclasses
  5545. + assert(new_class->super() == NULL || new_class->super()->klass_part()->is_newest_version(), "");
  5546. + if (the_class->super() != new_class->super()) {
  5547. + // Super class changed
  5548. +
  5549. + klassOop cur_klass = the_class->super();
  5550. + while (cur_klass != NULL) {
  5551. + if (!new_class->is_subclass_of(cur_klass->klass_part()->newest_version())) {
  5552. + TRACE_RC2("Removed super class %s", cur_klass->klass_part()->name()->as_C_string());
  5553. + result = result | Klass::RemoveSuperType | Klass::ModifyInstances | Klass::ModifyClass;
  5554. +
  5555. + if (!cur_klass->klass_part()->has_subtype_changed()) {
  5556. + TRACE_RC2("Subtype changed of class %s", cur_klass->klass_part()->name()->as_C_string());
  5557. + cur_klass->klass_part()->set_subtype_changed(true);
  5558. + }
  5559. + }
  5560. +
  5561. + cur_klass = cur_klass->klass_part()->super();
  5562. + }
  5563. +
  5564. + cur_klass = new_class->super();
  5565. + while (cur_klass != NULL) {
  5566. + if (!the_class->is_subclass_of(cur_klass->klass_part()->old_version())) {
  5567. + TRACE_RC2("Added super class %s", cur_klass->klass_part()->name()->as_C_string());
  5568. + result = result | Klass::ModifyClass | Klass::ModifyInstances;
  5569. + }
  5570. + cur_klass = cur_klass->klass_part()->super();
  5571. + }
  5572. }
  5573. - int value = _index_map_p->at(old_index);
  5574. - if (value == -1) {
  5575. - // the old_index is not mapped
  5576. - return 0;
  5577. - }
  5578. -
  5579. - return value;
  5580. -} // end find_new_index()
  5581. -
  5582. -
  5583. -// Returns true if the current mismatch is due to a resolved/unresolved
  5584. -// class pair. Otherwise, returns false.
  5585. -bool VM_RedefineClasses::is_unresolved_class_mismatch(constantPoolHandle cp1,
  5586. - int index1, constantPoolHandle cp2, int index2) {
  5587. -
  5588. - jbyte t1 = cp1->tag_at(index1).value();
  5589. - if (t1 != JVM_CONSTANT_Class && t1 != JVM_CONSTANT_UnresolvedClass) {
  5590. - return false; // wrong entry type; not our special case
  5591. - }
  5592. -
  5593. - jbyte t2 = cp2->tag_at(index2).value();
  5594. - if (t2 != JVM_CONSTANT_Class && t2 != JVM_CONSTANT_UnresolvedClass) {
  5595. - return false; // wrong entry type; not our special case
  5596. - }
  5597. -
  5598. - if (t1 == t2) {
  5599. - return false; // not a mismatch; not our special case
  5600. - }
  5601. -
  5602. - char *s1 = cp1->klass_name_at(index1)->as_C_string();
  5603. - char *s2 = cp2->klass_name_at(index2)->as_C_string();
  5604. - if (strcmp(s1, s2) != 0) {
  5605. - return false; // strings don't match; not our special case
  5606. - }
  5607. -
  5608. - return true; // made it through the gauntlet; this is our special case
  5609. -} // end is_unresolved_class_mismatch()
  5610. -
  5611. -
  5612. -// Returns true if the current mismatch is due to a resolved/unresolved
  5613. -// string pair. Otherwise, returns false.
  5614. -bool VM_RedefineClasses::is_unresolved_string_mismatch(constantPoolHandle cp1,
  5615. - int index1, constantPoolHandle cp2, int index2) {
  5616. -
  5617. - jbyte t1 = cp1->tag_at(index1).value();
  5618. - if (t1 != JVM_CONSTANT_String && t1 != JVM_CONSTANT_UnresolvedString) {
  5619. - return false; // wrong entry type; not our special case
  5620. - }
  5621. -
  5622. - jbyte t2 = cp2->tag_at(index2).value();
  5623. - if (t2 != JVM_CONSTANT_String && t2 != JVM_CONSTANT_UnresolvedString) {
  5624. - return false; // wrong entry type; not our special case
  5625. - }
  5626. -
  5627. - if (t1 == t2) {
  5628. - return false; // not a mismatch; not our special case
  5629. - }
  5630. -
  5631. - char *s1 = cp1->string_at_noresolve(index1);
  5632. - char *s2 = cp2->string_at_noresolve(index2);
  5633. - if (strcmp(s1, s2) != 0) {
  5634. - return false; // strings don't match; not our special case
  5635. - }
  5636. -
  5637. - return true; // made it through the gauntlet; this is our special case
  5638. -} // end is_unresolved_string_mismatch()
  5639. -
  5640. -
  5641. -jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) {
  5642. - // For consistency allocate memory using os::malloc wrapper.
  5643. - _scratch_classes = (instanceKlassHandle *)
  5644. - os::malloc(sizeof(instanceKlassHandle) * _class_count);
  5645. - if (_scratch_classes == NULL) {
  5646. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5647. - }
  5648. -
  5649. - ResourceMark rm(THREAD);
  5650. -
  5651. - JvmtiThreadState *state = JvmtiThreadState::state_for(JavaThread::current());
  5652. - // state can only be NULL if the current thread is exiting which
  5653. - // should not happen since we're trying to do a RedefineClasses
  5654. - guarantee(state != NULL, "exiting thread calling load_new_class_versions");
  5655. - for (int i = 0; i < _class_count; i++) {
  5656. - oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass);
  5657. - // classes for primitives cannot be redefined
  5658. - if (!is_modifiable_class(mirror)) {
  5659. - return JVMTI_ERROR_UNMODIFIABLE_CLASS;
  5660. - }
  5661. - klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  5662. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  5663. - symbolHandle the_class_sym = symbolHandle(THREAD, the_class->name());
  5664. -
  5665. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5666. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  5667. - ("loading name=%s (avail_mem=" UINT64_FORMAT "K)",
  5668. - the_class->external_name(), os::available_memory() >> 10));
  5669. -
  5670. - ClassFileStream st((u1*) _class_defs[i].class_bytes,
  5671. - _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  5672. -
  5673. - // Parse the stream.
  5674. - Handle the_class_loader(THREAD, the_class->class_loader());
  5675. - Handle protection_domain(THREAD, the_class->protection_domain());
  5676. - // Set redefined class handle in JvmtiThreadState class.
  5677. - // This redefined class is sent to agent event handler for class file
  5678. - // load hook event.
  5679. - state->set_class_being_redefined(&the_class, _class_load_kind);
  5680. -
  5681. - klassOop k = SystemDictionary::parse_stream(the_class_sym,
  5682. - the_class_loader,
  5683. - protection_domain,
  5684. - &st,
  5685. - THREAD);
  5686. - // Clear class_being_redefined just to be sure.
  5687. - state->clear_class_being_redefined();
  5688. -
  5689. - // TODO: if this is retransform, and nothing changed we can skip it
  5690. -
  5691. - instanceKlassHandle scratch_class (THREAD, k);
  5692. -
  5693. - if (HAS_PENDING_EXCEPTION) {
  5694. - symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5695. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5696. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("parse_stream exception: '%s'",
  5697. - ex_name->as_C_string()));
  5698. - CLEAR_PENDING_EXCEPTION;
  5699. -
  5700. - if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) {
  5701. - return JVMTI_ERROR_UNSUPPORTED_VERSION;
  5702. - } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) {
  5703. - return JVMTI_ERROR_INVALID_CLASS_FORMAT;
  5704. - } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) {
  5705. - return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  5706. - } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) {
  5707. - // The message will be "XXX (wrong name: YYY)"
  5708. - return JVMTI_ERROR_NAMES_DONT_MATCH;
  5709. - } else if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5710. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5711. - } else { // Just in case more exceptions can be thrown..
  5712. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5713. + //////////////////////////////////////////////////////////////////////////////////////////////////////////
  5714. + // Check interfaces
  5715. +
  5716. + // Interfaces removed?
  5717. + objArrayOop old_interfaces = the_class->transitive_interfaces();
  5718. + for (i = 0; i<old_interfaces->length(); i++) {
  5719. + instanceKlassHandle old_interface((klassOop)old_interfaces->obj_at(i));
  5720. + if (!new_class->implements_interface_any_version(old_interface())) {
  5721. + result = result | Klass::RemoveSuperType | Klass::ModifyClass;
  5722. + TRACE_RC2("Removed interface %s", old_interface->name()->as_C_string());
  5723. +
  5724. + if (!old_interface->has_subtype_changed()) {
  5725. + TRACE_RC2("Subtype changed of interface %s", old_interface->name()->as_C_string());
  5726. + old_interface->set_subtype_changed(true);
  5727. }
  5728. }
  5729. -
  5730. - // Ensure class is linked before redefine
  5731. - if (!the_class->is_linked()) {
  5732. - the_class->link_class(THREAD);
  5733. - if (HAS_PENDING_EXCEPTION) {
  5734. - symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5735. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5736. - RC_TRACE_WITH_THREAD(0x00000002, THREAD, ("link_class exception: '%s'",
  5737. - ex_name->as_C_string()));
  5738. - CLEAR_PENDING_EXCEPTION;
  5739. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5740. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5741. + }
  5742. +
  5743. + // Interfaces added?
  5744. + objArrayOop new_interfaces = new_class->transitive_interfaces();
  5745. + for (i = 0; i<new_interfaces->length(); i++) {
  5746. + if (!the_class->implements_interface_any_version((klassOop)new_interfaces->obj_at(i))) {
  5747. + result = result | Klass::ModifyClass;
  5748. + TRACE_RC2("Added interface %s", ((klassOop)new_interfaces->obj_at(i))->klass_part()->name()->as_C_string());
  5749. + }
  5750. + }
  5751. +
  5752. +
  5753. + // Check whether class modifiers are the same.
  5754. + jushort old_flags = (jushort) the_class->access_flags().get_flags();
  5755. + jushort new_flags = (jushort) new_class->access_flags().get_flags();
  5756. + if (old_flags != new_flags) {
  5757. + // TODO (tw): Can this have any effects?
  5758. + }
  5759. +
  5760. + // Check if the number, names, types and order of fields declared in these classes
  5761. + // are the same.
  5762. + typeArrayOop k_old_fields = the_class->fields();
  5763. + typeArrayOop k_new_fields = new_class->fields();
  5764. + int n_fields = k_old_fields->length();
  5765. + if (n_fields != k_new_fields->length()) {
  5766. + result = result | Klass::ModifyInstances;
  5767. + } else {
  5768. + for (i = 0; i < n_fields; i += instanceKlass::next_offset) {
  5769. + // access
  5770. + old_flags = k_old_fields->ushort_at(i + instanceKlass::access_flags_offset);
  5771. + new_flags = k_new_fields->ushort_at(i + instanceKlass::access_flags_offset);
  5772. + if ((old_flags ^ new_flags) & JVM_RECOGNIZED_FIELD_MODIFIERS) {
  5773. + // (tw) Can this have any effects?
  5774. + }
  5775. + // offset
  5776. + if (k_old_fields->short_at(i + instanceKlass::low_offset) !=
  5777. + k_new_fields->short_at(i + instanceKlass::low_offset) ||
  5778. + k_old_fields->short_at(i + instanceKlass::high_offset) !=
  5779. + k_new_fields->short_at(i + instanceKlass::high_offset)) {
  5780. + result = result | Klass::ModifyInstances;
  5781. + }
  5782. + // name and signature
  5783. + jshort name_index = k_old_fields->short_at(i + instanceKlass::name_index_offset);
  5784. + jshort sig_index = k_old_fields->short_at(i +instanceKlass::signature_index_offset);
  5785. + symbolOop name_sym1 = the_class->constants()->symbol_at(name_index);
  5786. + symbolOop sig_sym1 = the_class->constants()->symbol_at(sig_index);
  5787. + name_index = k_new_fields->short_at(i + instanceKlass::name_index_offset);
  5788. + sig_index = k_new_fields->short_at(i + instanceKlass::signature_index_offset);
  5789. + symbolOop name_sym2 = new_class->constants()->symbol_at(name_index);
  5790. + symbolOop sig_sym2 = new_class->constants()->symbol_at(sig_index);
  5791. + if (name_sym1 != name_sym2 || sig_sym1 != sig_sym2) {
  5792. + result = result | Klass::ModifyInstances;
  5793. + }
  5794. + }
  5795. + }
  5796. +
  5797. + // Do a parallel walk through the old and new methods. Detect
  5798. + // cases where they match (exist in both), have been added in
  5799. + // the new methods, or have been deleted (exist only in the
  5800. + // old methods). The class file parser places methods in order
  5801. + // by method name, but does not order overloaded methods by
  5802. + // signature. In order to determine what fate befell the methods,
  5803. + // this code places the overloaded new methods that have matching
  5804. + // old methods in the same order as the old methods and places
  5805. + // new overloaded methods at the end of overloaded methods of
  5806. + // that name. The code for this order normalization is adapted
  5807. + // from the algorithm used in instanceKlass::find_method().
  5808. + // Since we are swapping out of order entries as we find them,
  5809. + // we only have to search forward through the overloaded methods.
  5810. + // Methods which are added and have the same name as an existing
  5811. + // method (but different signature) will be put at the end of
  5812. + // the methods with that name, and the name mismatch code will
  5813. + // handle them.
  5814. + objArrayHandle k_old_methods(the_class->methods());
  5815. + objArrayHandle k_new_methods(new_class->methods());
  5816. + int n_old_methods = k_old_methods->length();
  5817. + int n_new_methods = k_new_methods->length();
  5818. +
  5819. + int ni = 0;
  5820. + int oi = 0;
  5821. + while (true) {
  5822. + methodOop k_old_method;
  5823. + methodOop k_new_method;
  5824. + enum { matched, added, deleted, undetermined } method_was = undetermined;
  5825. +
  5826. + if (oi >= n_old_methods) {
  5827. + if (ni >= n_new_methods) {
  5828. + break; // we've looked at everything, done
  5829. + }
  5830. + // New method at the end
  5831. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  5832. + method_was = added;
  5833. + } else if (ni >= n_new_methods) {
  5834. + // Old method, at the end, is deleted
  5835. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  5836. + method_was = deleted;
  5837. + } else {
  5838. + // There are more methods in both the old and new lists
  5839. + k_old_method = (methodOop) k_old_methods->obj_at(oi);
  5840. + k_new_method = (methodOop) k_new_methods->obj_at(ni);
  5841. + if (k_old_method->name() != k_new_method->name()) {
  5842. + // Methods are sorted by method name, so a mismatch means added
  5843. + // or deleted
  5844. + if (k_old_method->name()->fast_compare(k_new_method->name()) > 0) {
  5845. + method_was = added;
  5846. } else {
  5847. - return JVMTI_ERROR_INTERNAL;
  5848. + method_was = deleted;
  5849. + }
  5850. + } else if (k_old_method->signature() == k_new_method->signature()) {
  5851. + // Both the name and signature match
  5852. + method_was = matched;
  5853. + } else {
  5854. + // The name matches, but the signature doesn't, which means we have to
  5855. + // search forward through the new overloaded methods.
  5856. + int nj; // outside the loop for post-loop check
  5857. + for (nj = ni + 1; nj < n_new_methods; nj++) {
  5858. + methodOop m = (methodOop)k_new_methods->obj_at(nj);
  5859. + if (k_old_method->name() != m->name()) {
  5860. + // reached another method name so no more overloaded methods
  5861. + method_was = deleted;
  5862. + break;
  5863. + }
  5864. + if (k_old_method->signature() == m->signature()) {
  5865. + // found a match so swap the methods
  5866. + k_new_methods->obj_at_put(ni, m);
  5867. + k_new_methods->obj_at_put(nj, k_new_method);
  5868. + k_new_method = m;
  5869. + method_was = matched;
  5870. + break;
  5871. + }
  5872. + }
  5873. +
  5874. + if (nj >= n_new_methods) {
  5875. + // reached the end without a match; so method was deleted
  5876. + method_was = deleted;
  5877. }
  5878. }
  5879. }
  5880. - // Do the validity checks in compare_and_normalize_class_versions()
  5881. - // before verifying the byte codes. By doing these checks first, we
  5882. - // limit the number of functions that require redirection from
  5883. - // the_class to scratch_class. In particular, we don't have to
  5884. - // modify JNI GetSuperclass() and thus won't change its performance.
  5885. - jvmtiError res = compare_and_normalize_class_versions(the_class,
  5886. - scratch_class);
  5887. - if (res != JVMTI_ERROR_NONE) {
  5888. - return res;
  5889. + switch (method_was) {
  5890. + case matched:
  5891. + // methods match, be sure modifiers do too
  5892. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  5893. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  5894. + if ((old_flags ^ new_flags) & ~(JVM_ACC_NATIVE)) {
  5895. + // (tw) Can this have any effects? Probably yes on vtables?
  5896. + result = result | Klass::ModifyClass;
  5897. }
  5898. -
  5899. - // verify what the caller passed us
  5900. {
  5901. - // The bug 6214132 caused the verification to fail.
  5902. - // Information about the_class and scratch_class is temporarily
  5903. - // recorded into jvmtiThreadState. This data is used to redirect
  5904. - // the_class to scratch_class in the JVM_* functions called by the
  5905. - // verifier. Please, refer to jvmtiThreadState.hpp for the detailed
  5906. - // description.
  5907. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  5908. - Verifier::verify(
  5909. - scratch_class, Verifier::ThrowException, true, THREAD);
  5910. - }
  5911. -
  5912. - if (HAS_PENDING_EXCEPTION) {
  5913. - symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5914. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5915. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  5916. - ("verify_byte_codes exception: '%s'", ex_name->as_C_string()));
  5917. - CLEAR_PENDING_EXCEPTION;
  5918. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5919. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5920. - } else {
  5921. - // tell the caller the bytecodes are bad
  5922. - return JVMTI_ERROR_FAILS_VERIFICATION;
  5923. + u2 new_num = k_new_method->method_idnum();
  5924. + u2 old_num = k_old_method->method_idnum();
  5925. + if (new_num != old_num) {
  5926. + methodOop idnum_owner = new_class->method_with_idnum(old_num);
  5927. + if (idnum_owner != NULL) {
  5928. + // There is already a method assigned this idnum -- switch them
  5929. + idnum_owner->set_method_idnum(new_num);
  5930. + }
  5931. + k_new_method->set_method_idnum(old_num);
  5932. + TRACE_RC2("swapping idnum of new and old method %d / %d!", new_num, old_num);
  5933. + // swap_all_method_annotations(old_num, new_num, new_class);
  5934. }
  5935. }
  5936. -
  5937. - res = merge_cp_and_rewrite(the_class, scratch_class, THREAD);
  5938. - if (res != JVMTI_ERROR_NONE) {
  5939. - return res;
  5940. + TRACE_RC3("Method matched: new: %s [%d] == old: %s [%d]",
  5941. + k_new_method->name_and_sig_as_C_string(), ni,
  5942. + k_old_method->name_and_sig_as_C_string(), oi);
  5943. + // advance to next pair of methods
  5944. + ++oi;
  5945. + ++ni;
  5946. + break;
  5947. + case added:
  5948. + // method added, see if it is OK
  5949. + new_flags = (jushort) k_new_method->access_flags().get_flags();
  5950. + if ((new_flags & JVM_ACC_PRIVATE) == 0
  5951. + // hack: private should be treated as final, but alas
  5952. + || (new_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  5953. + ) {
  5954. + // new methods must be private
  5955. + result = result | Klass::ModifyClass;
  5956. }
  5957. -
  5958. - if (VerifyMergedCPBytecodes) {
  5959. - // verify what we have done during constant pool merging
  5960. - {
  5961. - RedefineVerifyMark rvm(&the_class, &scratch_class, state);
  5962. - Verifier::verify(scratch_class, Verifier::ThrowException, true, THREAD);
  5963. + {
  5964. + u2 num = the_class->next_method_idnum();
  5965. + if (num == constMethodOopDesc::UNSET_IDNUM) {
  5966. + // cannot add any more methods
  5967. + result = result | Klass::ModifyClass;
  5968. }
  5969. -
  5970. - if (HAS_PENDING_EXCEPTION) {
  5971. - symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  5972. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  5973. - RC_TRACE_WITH_THREAD(0x00000002, THREAD,
  5974. - ("verify_byte_codes post merge-CP exception: '%s'",
  5975. - ex_name->as_C_string()));
  5976. - CLEAR_PENDING_EXCEPTION;
  5977. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  5978. - return JVMTI_ERROR_OUT_OF_MEMORY;
  5979. - } else {
  5980. - // tell the caller that constant pool merging screwed up
  5981. - return JVMTI_ERROR_INTERNAL;
  5982. + u2 new_num = k_new_method->method_idnum();
  5983. + methodOop idnum_owner = new_class->method_with_idnum(num);
  5984. + if (idnum_owner != NULL) {
  5985. + // There is already a method assigned this idnum -- switch them
  5986. + idnum_owner->set_method_idnum(new_num);
  5987. + }
  5988. + k_new_method->set_method_idnum(num);
  5989. + //swap_all_method_annotations(new_num, num, new_class);
  5990. + }
  5991. + TRACE_RC1("Method added: new: %s [%d]",
  5992. + k_new_method->name_and_sig_as_C_string(), ni);
  5993. + ++ni; // advance to next new method
  5994. + break;
  5995. + case deleted:
  5996. + // method deleted, see if it is OK
  5997. + old_flags = (jushort) k_old_method->access_flags().get_flags();
  5998. + if ((old_flags & JVM_ACC_PRIVATE) == 0
  5999. + // hack: private should be treated as final, but alas
  6000. + || (old_flags & (JVM_ACC_FINAL|JVM_ACC_STATIC)) == 0
  6001. + ) {
  6002. + // deleted methods must be private
  6003. + result = result | Klass::ModifyClass;
  6004. + }
  6005. + TRACE_RC1("Method deleted: old: %s [%d]",
  6006. + k_old_method->name_and_sig_as_C_string(), oi);
  6007. + ++oi; // advance to next old method
  6008. + break;
  6009. + default:
  6010. + ShouldNotReachHere();
  6011. + }
  6012. + }
  6013. +
  6014. + if (new_class()->size() != new_class->old_version()->size()) {
  6015. + result |= Klass::ModifyClassSize;
  6016. + }
  6017. +
  6018. + if (new_class->size_helper() != ((instanceKlass*)(new_class->old_version()->klass_part()))->size_helper()) {
  6019. + result |= Klass::ModifyInstanceSize;
  6020. + }
  6021. +
  6022. + methodHandle instanceTransformerMethod(new_class->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature()));
  6023. + if (!instanceTransformerMethod.is_null() && !instanceTransformerMethod->is_static()) {
  6024. + result |= Klass::HasInstanceTransformer;
  6025. + }
  6026. +
  6027. + // (tw) Check method bodies to be able to return NoChange?
  6028. + return result;
  6029. +}
  6030. +
  6031. +void VM_RedefineClasses::calculate_instance_update_information(klassOop new_version) {
  6032. +
  6033. + class UpdateFieldsEvolutionClosure : public FieldEvolutionClosure {
  6034. +
  6035. + private:
  6036. +
  6037. + GrowableArray<int> info;
  6038. + int curPosition;
  6039. + bool copy_backwards;
  6040. +
  6041. + public:
  6042. +
  6043. + bool does_copy_backwards() {
  6044. + return copy_backwards;
  6045. + }
  6046. +
  6047. + UpdateFieldsEvolutionClosure(klassOop klass) {
  6048. +
  6049. + int base_offset = instanceOopDesc::base_offset_in_bytes();
  6050. +
  6051. + if (klass->klass_part()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version()) {
  6052. + base_offset += java_lang_Class::number_of_fake_oop_fields*size_of_type(T_OBJECT);
  6053. + }
  6054. +
  6055. + info.append(base_offset);
  6056. + info.append(0);
  6057. + curPosition = base_offset;
  6058. + copy_backwards = false;
  6059. + }
  6060. +
  6061. + GrowableArray<int> &finish() {
  6062. + info.append(0);
  6063. + return info;
  6064. + }
  6065. +
  6066. + virtual void do_new_field(fieldDescriptor* fd){
  6067. + int size = size_of_type(fd->field_type());
  6068. + fill(size);
  6069. + }
  6070. +
  6071. + private:
  6072. +
  6073. + void fill(int size) {
  6074. + if (info.length() > 0 && info.at(info.length() - 1) < 0) {
  6075. + (*info.adr_at(info.length() - 1)) -= size;
  6076. + } else {
  6077. + info.append(-size);
  6078. + }
  6079. +
  6080. + curPosition += size;
  6081. + }
  6082. +
  6083. + int size_of_type(BasicType type) {
  6084. + int size = 0;
  6085. + switch(type) {
  6086. + case T_BOOLEAN:
  6087. + size = sizeof(jboolean);
  6088. + break;
  6089. +
  6090. + case T_CHAR:
  6091. + size = (sizeof(jchar));
  6092. + break;
  6093. +
  6094. + case T_FLOAT:
  6095. + size = (sizeof(jfloat));
  6096. + break;
  6097. +
  6098. + case T_DOUBLE:
  6099. + size = (sizeof(jdouble));
  6100. + break;
  6101. +
  6102. + case T_BYTE:
  6103. + size = (sizeof(jbyte));
  6104. + break;
  6105. +
  6106. + case T_SHORT:
  6107. + size = (sizeof(jshort));
  6108. + break;
  6109. +
  6110. + case T_INT:
  6111. + size = (sizeof(jint));
  6112. + break;
  6113. +
  6114. + case T_LONG:
  6115. + size = (sizeof(jlong));
  6116. + break;
  6117. +
  6118. + case T_OBJECT:
  6119. + case T_ARRAY:
  6120. + if (UseCompressedOops) {
  6121. + size = sizeof(narrowOop);
  6122. + } else {
  6123. + size = (sizeof(oop));
  6124. + }
  6125. + break;
  6126. +
  6127. + default:
  6128. + ShouldNotReachHere();
  6129. + }
  6130. +
  6131. + assert(size > 0, "");
  6132. + return size;
  6133. +
  6134. + }
  6135. +
  6136. + public:
  6137. +
  6138. + virtual void do_old_field(fieldDescriptor* fd){}
  6139. +
  6140. + virtual void do_changed_field(fieldDescriptor* old_fd, fieldDescriptor *new_fd){
  6141. +
  6142. + int alignment = new_fd->offset() - curPosition;
  6143. + if (alignment > 0) {
  6144. + // This field was aligned, so we need to make sure that we fill the gap
  6145. + fill(alignment);
  6146. + }
  6147. +
  6148. + assert(old_fd->field_type() == new_fd->field_type(), "");
  6149. + assert(curPosition == new_fd->offset(), "must be correct offset!");
  6150. +
  6151. + int offset = old_fd->offset();
  6152. + int size = size_of_type(old_fd->field_type());
  6153. +
  6154. + int prevEnd = -1;
  6155. + if (info.length() > 0 && info.at(info.length() - 1) > 0) {
  6156. + prevEnd = info.at(info.length() - 2) + info.at(info.length() - 1);
  6157. + }
  6158. +
  6159. + if (prevEnd == offset) {
  6160. + info.at_put(info.length() - 2, info.at(info.length() - 2) + size);
  6161. + } else {
  6162. + info.append(size);
  6163. + info.append(offset);
  6164. + }
  6165. +
  6166. + if (old_fd->offset() < new_fd->offset()) {
  6167. + copy_backwards = true;
  6168. + }
  6169. +
  6170. + transfer_special_access_flags(old_fd, new_fd);
  6171. +
  6172. + curPosition += size;
  6173. + }
  6174. + };
  6175. +
  6176. + UpdateFieldsEvolutionClosure cl(new_version);
  6177. + ((instanceKlass*)new_version->klass_part())->do_fields_evolution(&cl);
  6178. +
  6179. + GrowableArray<int> result = cl.finish();
  6180. + ((instanceKlass*)new_version->klass_part())->store_update_information(result);
  6181. + ((instanceKlass*)new_version->klass_part())->set_copying_backwards(cl.does_copy_backwards());
  6182. +
  6183. + IF_TRACE_RC2 {
  6184. + TRACE_RC2("Instance update information for %s:", new_version->klass_part()->name()->as_C_string());
  6185. + if (cl.does_copy_backwards()) {
  6186. + TRACE_RC2("\tDoes copy backwards!");
  6187. + }
  6188. + for (int i=0; i<result.length(); i++) {
  6189. + int curNum = result.at(i);
  6190. + if (curNum < 0) {
  6191. + TRACE_RC2("\t%d CLEAN", curNum);
  6192. + } else if (curNum > 0) {
  6193. + TRACE_RC2("\t%d COPY from %d", curNum, result.at(i + 1));
  6194. + i++;
  6195. + } else {
  6196. + TRACE_RC2("\tEND");
  6197. + }
  6198. + }
  6199. + }
  6200. +}
  6201. +
  6202. +void VM_RedefineClasses::update_active_methods() {
  6203. +
  6204. + TRACE_RC2("Updating active methods");
  6205. + JavaThread *java_thread = Threads::first();
  6206. + while (java_thread != NULL) {
  6207. +
  6208. + int stack_depth = 0;
  6209. + if (java_thread->has_last_Java_frame()) {
  6210. +
  6211. + TRACE_RC4("checking stack of Java thread %s", java_thread->name());
  6212. +
  6213. + // vframes are resource allocated
  6214. + Thread* current_thread = Thread::current();
  6215. + ResourceMark rm(current_thread);
  6216. + HandleMark hm(current_thread);
  6217. +
  6218. + RegisterMap reg_map(java_thread);
  6219. + frame f = java_thread->last_frame();
  6220. + vframe* vf = vframe::new_vframe(&f, &reg_map, java_thread);
  6221. + frame* last_entry_frame = NULL;
  6222. +
  6223. + while (vf != NULL) {
  6224. + if (vf->is_java_frame()) {
  6225. + // java frame (interpreted, compiled, ...)
  6226. + javaVFrame *jvf = javaVFrame::cast(vf);
  6227. +
  6228. + if (!(jvf->method()->is_native())) {
  6229. + int bci = jvf->bci();
  6230. + TRACE_RC4("found method: %s / bci=%d", jvf->method()->name()->as_C_string(), bci);
  6231. + ResourceMark rm(Thread::current());
  6232. + HandleMark hm;
  6233. + instanceKlassHandle klass(jvf->method()->method_holder());
  6234. +
  6235. + if (jvf->method()->new_version() != NULL && jvf->is_interpreted_frame()) {
  6236. +
  6237. +
  6238. + TRACE_RC2("Found method that should just be updated to the newest version %s", jvf->method()->name_and_sig_as_C_string());
  6239. +
  6240. + IF_TRACE_RC5 {
  6241. + int code_size = jvf->method()->code_size();
  6242. + char *code_base_old = (char*)jvf->method()->code_base();
  6243. + char *code_base_new = (char*)jvf->method()->new_version()->code_base();
  6244. + for (int i=0; i<code_size; i++) {
  6245. + tty->print_cr("old=%d new=%d", *code_base_old++, *code_base_new++);
  6246. + }
  6247. + jvf->method()->print_codes_on(tty);
  6248. + jvf->method()->new_version()->print_codes_on(tty);
  6249. + }
  6250. +
  6251. + assert(jvf->is_interpreted_frame(), "Every frame must be interpreted!");
  6252. + interpretedVFrame *iframe = (interpretedVFrame *)jvf;
  6253. +
  6254. +
  6255. + IF_TRACE_RC5 {
  6256. + constantPoolCacheOop cp_old = jvf->method()->constants()->cache();
  6257. + tty->print_cr("old cp");
  6258. + for (int i=0; i<cp_old->length(); i++) {
  6259. + cp_old->entry_at(i)->print(tty, i);
  6260. + }
  6261. + constantPoolCacheOop cp_new = jvf->method()->new_version()->constants()->cache();
  6262. + tty->print_cr("new cp");
  6263. + for (int i=0; i<cp_new->length(); i++) {
  6264. + cp_new->entry_at(i)->print(tty, i);
  6265. + }
  6266. + }
  6267. +
  6268. + iframe->set_method(jvf->method()->new_version(), bci);
  6269. + TRACE_RC2("Updated method to newer version");
  6270. + assert(jvf->method()->new_version() == NULL, "must be latest version");
  6271. +
  6272. + }
  6273. + }
  6274. + }
  6275. + vf = vf->sender();
  6276. + }
  6277. + }
  6278. +
  6279. + // Advance to next thread
  6280. + java_thread = java_thread->next();
  6281. + }
  6282. +}
  6283. +
  6284. +void VM_RedefineClasses::rollback() {
  6285. + TRACE_RC1("Rolling back redefinition!");
  6286. + SystemDictionary::rollback_redefinition();
  6287. +
  6288. + TRACE_RC1("After rolling back system dictionary!");
  6289. + for (int i=0; i<_new_classes->length(); i++) {
  6290. + SystemDictionary::remove_from_hierarchy(_new_classes->at(i));
  6291. + }
  6292. +
  6293. + for (int i=0; i<_new_classes->length(); i++) {
  6294. + instanceKlassHandle new_class = _new_classes->at(i);
  6295. + new_class->set_redefining(false);
  6296. + new_class->old_version()->klass_part()->set_new_version(NULL);
  6297. + new_class->set_old_version(NULL);
  6298. + }
  6299. +
  6300. +}
  6301. +
  6302. +template <class T> void VM_RedefineClasses::do_oop_work(T* p) {
  6303. + T heap_oop = oopDesc::load_heap_oop(p);
  6304. + if (!oopDesc::is_null(heap_oop)) {
  6305. + oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
  6306. + if (obj->is_instanceKlass()) {
  6307. + klassOop klass = (klassOop)obj;
  6308. + if (klass->klass_part()->new_version() != NULL && klass->klass_part()->new_version()->klass_part()->is_redefining()) {
  6309. + obj = klass->klass_part()->new_version();
  6310. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  6311. + }
  6312. + } else if (obj->blueprint()->newest_version() == SystemDictionary::Class_klass()->klass_part()->newest_version()) {
  6313. +
  6314. + klassOop klass_oop = java_lang_Class::as_klassOop(obj);
  6315. + if (klass_oop != NULL) {
  6316. + if (klass_oop->klass_part()->new_version() != NULL && klass_oop->klass_part()->new_version()->klass_part()->is_redefining()) {
  6317. + obj = klass_oop->klass_part()->new_version()->klass_part()->java_mirror();
  6318. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  6319. + } else if (klass_oop->klass_part()->is_redefining()) {
  6320. + obj = klass_oop->klass_part()->java_mirror();
  6321. + oopDesc::encode_store_heap_oop_not_null(p, obj);
  6322. }
  6323. }
  6324. }
  6325. -
  6326. - Rewriter::rewrite(scratch_class, THREAD);
  6327. - if (HAS_PENDING_EXCEPTION) {
  6328. - symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6329. - CLEAR_PENDING_EXCEPTION;
  6330. - if (ex_name == vmSymbols::java_lang_OutOfMemoryError()) {
  6331. - return JVMTI_ERROR_OUT_OF_MEMORY;
  6332. - } else {
  6333. - return JVMTI_ERROR_INTERNAL;
  6334. - }
  6335. - }
  6336. -
  6337. - _scratch_classes[i] = scratch_class;
  6338. -
  6339. - // RC_TRACE_WITH_THREAD macro has an embedded ResourceMark
  6340. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  6341. - ("loaded name=%s (avail_mem=" UINT64_FORMAT "K)",
  6342. - the_class->external_name(), os::available_memory() >> 10));
  6343. }
  6344. -
  6345. - return JVMTI_ERROR_NONE;
  6346. }
  6347. -
  6348. -// Map old_index to new_index as needed. scratch_cp is only needed
  6349. -// for RC_TRACE() calls.
  6350. -void VM_RedefineClasses::map_index(constantPoolHandle scratch_cp,
  6351. - int old_index, int new_index) {
  6352. - if (find_new_index(old_index) != 0) {
  6353. - // old_index is already mapped
  6354. - return;
  6355. - }
  6356. -
  6357. - if (old_index == new_index) {
  6358. - // no mapping is needed
  6359. - return;
  6360. - }
  6361. -
  6362. - _index_map_p->at_put(old_index, new_index);
  6363. - _index_map_count++;
  6364. -
  6365. - RC_TRACE(0x00040000, ("mapped tag %d at index %d to %d",
  6366. - scratch_cp->tag_at(old_index).value(), old_index, new_index));
  6367. -} // end map_index()
  6368. -
  6369. -
  6370. -// Merge old_cp and scratch_cp and return the results of the merge via
  6371. -// merge_cp_p. The number of entries in *merge_cp_p is returned via
  6372. -// merge_cp_length_p. The entries in old_cp occupy the same locations
  6373. -// in *merge_cp_p. Also creates a map of indices from entries in
  6374. -// scratch_cp to the corresponding entry in *merge_cp_p. Index map
  6375. -// entries are only created for entries in scratch_cp that occupy a
  6376. -// different location in *merged_cp_p.
  6377. -bool VM_RedefineClasses::merge_constant_pools(constantPoolHandle old_cp,
  6378. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  6379. - int *merge_cp_length_p, TRAPS) {
  6380. -
  6381. - if (merge_cp_p == NULL) {
  6382. - assert(false, "caller must provide scatch constantPool");
  6383. - return false; // robustness
  6384. - }
  6385. - if (merge_cp_length_p == NULL) {
  6386. - assert(false, "caller must provide scatch CP length");
  6387. - return false; // robustness
  6388. - }
  6389. - // Worst case we need old_cp->length() + scratch_cp()->length(),
  6390. - // but the caller might be smart so make sure we have at least
  6391. - // the minimum.
  6392. - if ((*merge_cp_p)->length() < old_cp->length()) {
  6393. - assert(false, "merge area too small");
  6394. - return false; // robustness
  6395. - }
  6396. -
  6397. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6398. - ("old_cp_len=%d, scratch_cp_len=%d", old_cp->length(),
  6399. - scratch_cp->length()));
  6400. -
  6401. - {
  6402. - // Pass 0:
  6403. - // The old_cp is copied to *merge_cp_p; this means that any code
  6404. - // using old_cp does not have to change. This work looks like a
  6405. - // perfect fit for constantPoolOop::copy_cp_to(), but we need to
  6406. - // handle one special case:
  6407. - // - revert JVM_CONSTANT_Class to JVM_CONSTANT_UnresolvedClass
  6408. - // This will make verification happy.
  6409. -
  6410. - int old_i; // index into old_cp
  6411. -
  6412. - // index zero (0) is not used in constantPools
  6413. - for (old_i = 1; old_i < old_cp->length(); old_i++) {
  6414. - // leave debugging crumb
  6415. - jbyte old_tag = old_cp->tag_at(old_i).value();
  6416. - switch (old_tag) {
  6417. - case JVM_CONSTANT_Class:
  6418. - // revert the copy to JVM_CONSTANT_UnresolvedClass
  6419. - (*merge_cp_p)->unresolved_klass_at_put(old_i,
  6420. - old_cp->klass_name_at(old_i));
  6421. - break;
  6422. -
  6423. - case JVM_CONSTANT_Double:
  6424. - case JVM_CONSTANT_Long:
  6425. - // just copy the entry to *merge_cp_p, but double and long take
  6426. - // two constant pool entries
  6427. - old_cp->copy_entry_to(old_i, *merge_cp_p, old_i, CHECK_0);
  6428. - old_i++;
  6429. - break;
  6430. -
  6431. - default:
  6432. - // just copy the entry to *merge_cp_p
  6433. - old_cp->copy_entry_to(old_i, *merge_cp_p, old_i, CHECK_0);
  6434. - break;
  6435. - }
  6436. - } // end for each old_cp entry
  6437. -
  6438. - // We don't need to sanity check that *merge_cp_length_p is within
  6439. - // *merge_cp_p bounds since we have the minimum on-entry check above.
  6440. - (*merge_cp_length_p) = old_i;
  6441. - }
  6442. -
  6443. - // merge_cp_len should be the same as old_cp->length() at this point
  6444. - // so this trace message is really a "warm-and-breathing" message.
  6445. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6446. - ("after pass 0: merge_cp_len=%d", *merge_cp_length_p));
  6447. -
  6448. - int scratch_i; // index into scratch_cp
  6449. - {
  6450. - // Pass 1a:
  6451. - // Compare scratch_cp entries to the old_cp entries that we have
  6452. - // already copied to *merge_cp_p. In this pass, we are eliminating
  6453. - // exact duplicates (matching entry at same index) so we only
  6454. - // compare entries in the common indice range.
  6455. - int increment = 1;
  6456. - int pass1a_length = MIN2(old_cp->length(), scratch_cp->length());
  6457. - for (scratch_i = 1; scratch_i < pass1a_length; scratch_i += increment) {
  6458. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6459. - case JVM_CONSTANT_Double:
  6460. - case JVM_CONSTANT_Long:
  6461. - // double and long take two constant pool entries
  6462. - increment = 2;
  6463. - break;
  6464. -
  6465. - default:
  6466. - increment = 1;
  6467. - break;
  6468. - }
  6469. -
  6470. - bool match = scratch_cp->compare_entry_to(scratch_i, *merge_cp_p,
  6471. - scratch_i, CHECK_0);
  6472. - if (match) {
  6473. - // found a match at the same index so nothing more to do
  6474. - continue;
  6475. - } else if (is_unresolved_class_mismatch(scratch_cp, scratch_i,
  6476. - *merge_cp_p, scratch_i)) {
  6477. - // The mismatch in compare_entry_to() above is because of a
  6478. - // resolved versus unresolved class entry at the same index
  6479. - // with the same string value. Since Pass 0 reverted any
  6480. - // class entries to unresolved class entries in *merge_cp_p,
  6481. - // we go with the unresolved class entry.
  6482. - continue;
  6483. - } else if (is_unresolved_string_mismatch(scratch_cp, scratch_i,
  6484. - *merge_cp_p, scratch_i)) {
  6485. - // The mismatch in compare_entry_to() above is because of a
  6486. - // resolved versus unresolved string entry at the same index
  6487. - // with the same string value. We can live with whichever
  6488. - // happens to be at scratch_i in *merge_cp_p.
  6489. - continue;
  6490. - }
  6491. -
  6492. - int found_i = scratch_cp->find_matching_entry(scratch_i, *merge_cp_p,
  6493. - CHECK_0);
  6494. - if (found_i != 0) {
  6495. - guarantee(found_i != scratch_i,
  6496. - "compare_entry_to() and find_matching_entry() do not agree");
  6497. -
  6498. - // Found a matching entry somewhere else in *merge_cp_p so
  6499. - // just need a mapping entry.
  6500. - map_index(scratch_cp, scratch_i, found_i);
  6501. - continue;
  6502. - }
  6503. -
  6504. - // The find_matching_entry() call above could fail to find a match
  6505. - // due to a resolved versus unresolved class or string entry situation
  6506. - // like we solved above with the is_unresolved_*_mismatch() calls.
  6507. - // However, we would have to call is_unresolved_*_mismatch() over
  6508. - // all of *merge_cp_p (potentially) and that doesn't seem to be
  6509. - // worth the time.
  6510. -
  6511. - // No match found so we have to append this entry and any unique
  6512. - // referenced entries to *merge_cp_p.
  6513. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6514. - CHECK_0);
  6515. +void VM_RedefineClasses::swap_marks(oop first, oop second) {
  6516. + markOop first_mark = first->mark();
  6517. + markOop second_mark = second->mark();
  6518. + first->set_mark(second_mark);
  6519. + second->set_mark(first_mark);
  6520. +}
  6521. +
  6522. +void VM_RedefineClasses::doit() {
  6523. + Thread *thread = Thread::current();
  6524. +
  6525. + TRACE_RC1("Entering doit!");
  6526. +
  6527. + assert((_max_redefinition_flags & Klass::RemoveSuperType) == 0, "removing super types not allowed");
  6528. +
  6529. + if (UseSharedSpaces) {
  6530. + // Sharing is enabled so we remap the shared readonly space to
  6531. + // shared readwrite, private just in case we need to redefine
  6532. + // a shared class. We do the remap during the doit() phase of
  6533. + // the safepoint to be safer.
  6534. + if (!CompactingPermGenGen::remap_shared_readonly_as_readwrite()) {
  6535. + TRACE_RC1("failed to remap shared readonly space to readwrite, private");
  6536. + _result = JVMTI_ERROR_INTERNAL;
  6537. + return;
  6538. }
  6539. }
  6540. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6541. - ("after pass 1a: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6542. - *merge_cp_length_p, scratch_i, _index_map_count));
  6543. -
  6544. - if (scratch_i < scratch_cp->length()) {
  6545. - // Pass 1b:
  6546. - // old_cp is smaller than scratch_cp so there are entries in
  6547. - // scratch_cp that we have not yet processed. We take care of
  6548. - // those now.
  6549. - int increment = 1;
  6550. - for (; scratch_i < scratch_cp->length(); scratch_i += increment) {
  6551. - switch (scratch_cp->tag_at(scratch_i).value()) {
  6552. - case JVM_CONSTANT_Double:
  6553. - case JVM_CONSTANT_Long:
  6554. - // double and long take two constant pool entries
  6555. - increment = 2;
  6556. - break;
  6557. -
  6558. - default:
  6559. - increment = 1;
  6560. - break;
  6561. + RC_TIMER_START(_timer_prepare_redefinition);
  6562. + for (int i = 0; i < _new_classes->length(); i++) {
  6563. + redefine_single_class(_new_classes->at(i), thread);
  6564. + }
  6565. +
  6566. + // Deoptimize all compiled code that depends on this class
  6567. + flush_dependent_code(instanceKlassHandle(Thread::current(), (klassOop)NULL), Thread::current());
  6568. +
  6569. + // Adjust constantpool caches and vtables for all classes
  6570. + // that reference methods of the evolved class.
  6571. + SystemDictionary::classes_do(adjust_cpool_cache, Thread::current());
  6572. +
  6573. + RC_TIMER_STOP(_timer_prepare_redefinition);
  6574. + RC_TIMER_START(_timer_redefinition);
  6575. +
  6576. + class ChangePointersOopClosure : public OopClosure {
  6577. + virtual void do_oop(oop* o) {
  6578. + do_oop_work(o);
  6579. }
  6580. - int found_i =
  6581. - scratch_cp->find_matching_entry(scratch_i, *merge_cp_p, CHECK_0);
  6582. - if (found_i != 0) {
  6583. - // Found a matching entry somewhere else in *merge_cp_p so
  6584. - // just need a mapping entry.
  6585. - map_index(scratch_cp, scratch_i, found_i);
  6586. - continue;
  6587. + virtual void do_oop(narrowOop* o) {
  6588. + do_oop_work(o);
  6589. }
  6590. -
  6591. - // No match found so we have to append this entry and any unique
  6592. - // referenced entries to *merge_cp_p.
  6593. - append_entry(scratch_cp, scratch_i, merge_cp_p, merge_cp_length_p,
  6594. - CHECK_0);
  6595. + };
  6596. +
  6597. + class ChangePointersObjectClosure : public ObjectClosure {
  6598. +
  6599. + private:
  6600. +
  6601. + OopClosure *_closure;
  6602. + bool _needs_instance_update;
  6603. + GrowableArray<oop> *_updated_oops;
  6604. +
  6605. + public:
  6606. + ChangePointersObjectClosure(OopClosure *closure) : _closure(closure), _needs_instance_update(false), _updated_oops(NULL) {}
  6607. +
  6608. + bool needs_instance_update() {
  6609. + return _needs_instance_update;
  6610. + }
  6611. +
  6612. + GrowableArray<oop> *updated_oops() { return _updated_oops; }
  6613. +
  6614. + virtual void do_object(oop obj) {
  6615. + if (!obj->is_instanceKlass()) {
  6616. + obj->oop_iterate(_closure);
  6617. +
  6618. + if (obj->blueprint()->is_redefining()) {
  6619. +
  6620. + if (obj->blueprint()->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  6621. + if (_updated_oops == NULL) {
  6622. + _updated_oops = new (ResourceObj::C_HEAP) GrowableArray<oop>(100, true);
  6623. + }
  6624. + _updated_oops->append(obj);
  6625. + }
  6626. +
  6627. + if(obj->blueprint()->update_information() != NULL || obj->is_perm()) {
  6628. +
  6629. + assert(obj->blueprint()->old_version() != NULL, "must have old version");
  6630. + obj->set_klass_no_check(obj->blueprint()->old_version());
  6631. +
  6632. + if (obj->size() != obj->size_given_klass(obj->blueprint()->new_version()->klass_part()) || obj->is_perm()) {
  6633. + // We need an instance update => set back to old klass
  6634. + _needs_instance_update = true;
  6635. +
  6636. + } else {
  6637. + MarkSweep::update_fields(obj, obj);
  6638. + assert(obj->blueprint()->is_redefining(), "update fields resets the klass");
  6639. + }
  6640. + }
  6641. + }
  6642. +
  6643. + } else {
  6644. + instanceKlass *klass = instanceKlass::cast((klassOop)obj);
  6645. + if (klass->is_redefining()) {
  6646. + // Initialize the new class! Special static initialization that does not execute the
  6647. + // static constructor but copies static field values from the old class if name
  6648. + // and signature of a static field match.
  6649. + klass->initialize_redefined_class();
  6650. + }
  6651. + klass->iterate_static_fields(_closure);
  6652. + }
  6653. + }
  6654. + };
  6655. +
  6656. + ChangePointersOopClosure oopClosure;
  6657. + ChangePointersObjectClosure objectClosure(&oopClosure);
  6658. +
  6659. + {
  6660. + SharedHeap::heap()->gc_prologue(true);
  6661. + Universe::root_oops_do(&oopClosure);
  6662. + Universe::heap()->object_iterate(&objectClosure);
  6663. + SharedHeap::heap()->gc_epilogue(false);
  6664. }
  6665. - RC_TRACE_WITH_THREAD(0x00020000, THREAD,
  6666. - ("after pass 1b: merge_cp_len=%d, scratch_i=%d, index_map_len=%d",
  6667. - *merge_cp_length_p, scratch_i, _index_map_count));
  6668. + // Swap marks to have same hashcodes
  6669. + for (int i=0; i<_new_classes->length(); i++) {
  6670. + swap_marks(_new_classes->at(i)(), _new_classes->at(i)->old_version());
  6671. + swap_marks(_new_classes->at(i)->java_mirror(), _new_classes->at(i)->old_version()->klass_part()->java_mirror());
  6672. + ((instanceKlass*)_new_classes->at(i)->old_version()->klass_part())->constants()->set_pool_holder(_new_classes->at(i)->old_version());
  6673. + }
  6674. +
  6675. + _updated_oops = objectClosure.updated_oops();
  6676. +
  6677. + if (objectClosure.needs_instance_update()){
  6678. +
  6679. + // Do a full garbage collection to update the instance sizes accordingly
  6680. + TRACE_RC1("Before performing full GC!");
  6681. + Universe::set_redefining_gc_run(true);
  6682. + JvmtiGCFullMarker jgcm;
  6683. + notify_gc_begin(true);
  6684. + Universe::heap()->collect_as_vm_thread(GCCause::_heap_inspection);
  6685. + notify_gc_end();
  6686. + Universe::set_redefining_gc_run(false);
  6687. + TRACE_RC1("GC done!");
  6688. }
  6689. - return true;
  6690. -} // end merge_constant_pools()
  6691. -
  6692. -
  6693. -// Merge constant pools between the_class and scratch_class and
  6694. -// potentially rewrite bytecodes in scratch_class to use the merged
  6695. -// constant pool.
  6696. -jvmtiError VM_RedefineClasses::merge_cp_and_rewrite(
  6697. - instanceKlassHandle the_class, instanceKlassHandle scratch_class,
  6698. - TRAPS) {
  6699. - // worst case merged constant pool length is old and new combined
  6700. - int merge_cp_length = the_class->constants()->length()
  6701. - + scratch_class->constants()->length();
  6702. -
  6703. - constantPoolHandle old_cp(THREAD, the_class->constants());
  6704. - constantPoolHandle scratch_cp(THREAD, scratch_class->constants());
  6705. -
  6706. - // Constant pools are not easily reused so we allocate a new one
  6707. - // each time.
  6708. - // merge_cp is created unsafe for concurrent GC processing. It
  6709. - // should be marked safe before discarding it because, even if
  6710. - // garbage. If it crosses a card boundary, it may be scanned
  6711. - // in order to find the start of the first complete object on the card.
  6712. - constantPoolHandle merge_cp(THREAD,
  6713. - oopFactory::new_constantPool(merge_cp_length,
  6714. - methodOopDesc::IsUnsafeConc,
  6715. - THREAD));
  6716. - int orig_length = old_cp->orig_length();
  6717. - if (orig_length == 0) {
  6718. - // This old_cp is an actual original constant pool. We save
  6719. - // the original length in the merged constant pool so that
  6720. - // merge_constant_pools() can be more efficient. If a constant
  6721. - // pool has a non-zero orig_length() value, then that constant
  6722. - // pool was created by a merge operation in RedefineClasses.
  6723. - merge_cp->set_orig_length(old_cp->length());
  6724. - } else {
  6725. - // This old_cp is a merged constant pool from a previous
  6726. - // RedefineClasses() calls so just copy the orig_length()
  6727. - // value.
  6728. - merge_cp->set_orig_length(old_cp->orig_length());
  6729. +
  6730. + IF_TRACE_RC1 {
  6731. + if (_updated_oops != NULL) {
  6732. + TRACE_RC1("%d object(s) updated!", _updated_oops->length());
  6733. + } else {
  6734. + TRACE_RC1("No objects updated!");
  6735. + }
  6736. }
  6737. - ResourceMark rm(THREAD);
  6738. - _index_map_count = 0;
  6739. - _index_map_p = new intArray(scratch_cp->length(), -1);
  6740. -
  6741. - bool result = merge_constant_pools(old_cp, scratch_cp, &merge_cp,
  6742. - &merge_cp_length, THREAD);
  6743. - if (!result) {
  6744. - // The merge can fail due to memory allocation failure or due
  6745. - // to robustness checks.
  6746. - return JVMTI_ERROR_INTERNAL;
  6747. + // Unmark klassOops as "redefining"
  6748. + for (int i=0; i<_new_classes->length(); i++) {
  6749. + klassOop cur = _new_classes->at(i)();
  6750. + _new_classes->at(i)->set_redefining(false);
  6751. + _new_classes->at(i)->clear_update_information();
  6752. + _new_classes->at(i)->update_supers_to_newest_version();
  6753. +
  6754. + if (((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses() != NULL) {
  6755. + update_array_classes_to_newest_version(((instanceKlass *)cur->klass_part()->old_version()->klass_part())->array_klasses());
  6756. +
  6757. + // Transfer the array classes, otherwise we might get cast exceptions when casting array types.
  6758. + ((instanceKlass*)cur->klass_part())->set_array_klasses(((instanceKlass*)cur->klass_part()->old_version()->klass_part())->array_klasses());
  6759. +
  6760. + oop new_mirror = _new_classes->at(i)->java_mirror();
  6761. + oop old_mirror = _new_classes->at(i)->old_version()->klass_part()->java_mirror();
  6762. + java_lang_Class::set_array_klass(new_mirror, java_lang_Class::array_klass(old_mirror));
  6763. + }
  6764. }
  6765. - RC_TRACE_WITH_THREAD(0x00010000, THREAD,
  6766. - ("merge_cp_len=%d, index_map_len=%d", merge_cp_length, _index_map_count));
  6767. -
  6768. - if (_index_map_count == 0) {
  6769. - // there is nothing to map between the new and merged constant pools
  6770. -
  6771. - if (old_cp->length() == scratch_cp->length()) {
  6772. - // The old and new constant pools are the same length and the
  6773. - // index map is empty. This means that the three constant pools
  6774. - // are equivalent (but not the same). Unfortunately, the new
  6775. - // constant pool has not gone through link resolution nor have
  6776. - // the new class bytecodes gone through constant pool cache
  6777. - // rewriting so we can't use the old constant pool with the new
  6778. - // class.
  6779. -
  6780. - merge_cp()->set_is_conc_safe(true);
  6781. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6782. - } else if (old_cp->length() < scratch_cp->length()) {
  6783. - // The old constant pool has fewer entries than the new constant
  6784. - // pool and the index map is empty. This means the new constant
  6785. - // pool is a superset of the old constant pool. However, the old
  6786. - // class bytecodes have already gone through constant pool cache
  6787. - // rewriting so we can't use the new constant pool with the old
  6788. - // class.
  6789. -
  6790. - merge_cp()->set_is_conc_safe(true);
  6791. - merge_cp = constantPoolHandle(); // toss the merged constant pool
  6792. + for (int i=T_BOOLEAN; i<=T_LONG; i++) {
  6793. + update_array_classes_to_newest_version(Universe::typeArrayKlassObj((BasicType)i));
  6794. + }
  6795. +
  6796. + // Disable any dependent concurrent compilations
  6797. + SystemDictionary::notice_modification();
  6798. +
  6799. + // Set flag indicating that some invariants are no longer true.
  6800. + // See jvmtiExport.hpp for detailed explanation.
  6801. + JvmtiExport::set_has_redefined_a_class();
  6802. +
  6803. + // Clean up caches in the compiler interface and compiler threads
  6804. + CompileBroker::cleanup_after_redefinition();
  6805. +
  6806. +#ifdef ASSERT
  6807. +
  6808. + // Universe::verify();
  6809. + // JNIHandles::verify();
  6810. +
  6811. + SystemDictionary::classes_do(check_class, thread);
  6812. +#endif
  6813. +
  6814. + update_active_methods();
  6815. + RC_TIMER_STOP(_timer_redefinition);
  6816. +
  6817. +}
  6818. +
  6819. +void VM_RedefineClasses::update_array_classes_to_newest_version(klassOop smallest_dimension) {
  6820. +
  6821. + arrayKlass *curArrayKlass = arrayKlass::cast(smallest_dimension);
  6822. + assert(curArrayKlass->lower_dimension() == NULL, "argument must be smallest dimension");
  6823. +
  6824. +
  6825. + while (curArrayKlass != NULL) {
  6826. + klassOop higher_dimension = curArrayKlass->higher_dimension();
  6827. + klassOop lower_dimension = curArrayKlass->lower_dimension();
  6828. + curArrayKlass->update_supers_to_newest_version();
  6829. +
  6830. + curArrayKlass = NULL;
  6831. + if (higher_dimension != NULL) {
  6832. + curArrayKlass = arrayKlass::cast(higher_dimension);
  6833. + }
  6834. + }
  6835. +
  6836. +}
  6837. +
  6838. +void VM_RedefineClasses::doit_epilogue() {
  6839. +
  6840. + RC_TIMER_START(_timer_vm_op_epilogue);
  6841. +
  6842. + unlock_threads();
  6843. +
  6844. + ResourceMark mark;
  6845. +
  6846. + VM_GC_Operation::doit_epilogue();
  6847. + TRACE_RC1("GC Operation epilogue finished! ");
  6848. +
  6849. + GrowableArray<methodHandle> instanceTransformerMethods;
  6850. +
  6851. + // Call static transformers
  6852. + for (int i=0; i<_new_classes->length(); i++) {
  6853. +
  6854. + instanceKlassHandle klass = _new_classes->at(i);
  6855. +
  6856. + // Find instance transformer method
  6857. +
  6858. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  6859. +
  6860. + TRACE_RC5("Call instance transformer of %s instance", klass->name()->as_C_string());
  6861. + klassOop cur_klass = klass();
  6862. + while (cur_klass != NULL) {
  6863. + methodOop method = ((instanceKlass*)cur_klass->klass_part())->find_method(vmSymbols::transformer_name(), vmSymbols::void_method_signature());
  6864. + if (method != NULL) {
  6865. + methodHandle instanceTransformerMethod(method);
  6866. + instanceTransformerMethods.append(instanceTransformerMethod);
  6867. + break;
  6868. + } else {
  6869. + cur_klass = cur_klass->klass_part()->super();
  6870. + }
  6871. + }
  6872. + assert(cur_klass != NULL, "must have instance transformer method");
  6873. } else {
  6874. - // The old constant pool has more entries than the new constant
  6875. - // pool and the index map is empty. This means that both the old
  6876. - // and merged constant pools are supersets of the new constant
  6877. - // pool.
  6878. -
  6879. - // Replace the new constant pool with a shrunken copy of the
  6880. - // merged constant pool; the previous new constant pool will
  6881. - // get GCed.
  6882. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  6883. - THREAD);
  6884. - // drop local ref to the merged constant pool
  6885. - merge_cp()->set_is_conc_safe(true);
  6886. - merge_cp = constantPoolHandle();
  6887. + instanceTransformerMethods.append(methodHandle(Thread::current(), NULL));
  6888. }
  6889. - } else {
  6890. - if (RC_TRACE_ENABLED(0x00040000)) {
  6891. - // don't want to loop unless we are tracing
  6892. - int count = 0;
  6893. - for (int i = 1; i < _index_map_p->length(); i++) {
  6894. - int value = _index_map_p->at(i);
  6895. -
  6896. - if (value != -1) {
  6897. - RC_TRACE_WITH_THREAD(0x00040000, THREAD,
  6898. - ("index_map[%d]: old=%d new=%d", count, i, value));
  6899. - count++;
  6900. + }
  6901. +
  6902. +
  6903. + // Call instance transformers
  6904. + if (_updated_oops != NULL) {
  6905. +
  6906. + for (int i=0; i<_updated_oops->length(); i++) {
  6907. + assert(_updated_oops->at(i) != NULL, "must not be null!");
  6908. + Handle cur(_updated_oops->at(i));
  6909. + instanceKlassHandle klass(cur->klass());
  6910. +
  6911. + if (klass->check_redefinition_flag(Klass::HasInstanceTransformer)) {
  6912. +
  6913. + methodHandle method = instanceTransformerMethods.at(klass->redefinition_index());
  6914. +
  6915. + TRACE_RC5("executing transformer method");
  6916. +
  6917. + Thread *__the_thread__ = Thread::current();
  6918. + JavaValue result(T_VOID);
  6919. + JavaCallArguments args(cur);
  6920. + JavaCalls::call(&result,
  6921. + method,
  6922. + &args,
  6923. + THREAD);
  6924. +
  6925. + // TODO: What to do with an exception here?
  6926. + if (HAS_PENDING_EXCEPTION) {
  6927. + symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name();
  6928. + TRACE_RC2("exception when executing transformer: '%s'", ex_name->as_C_string());
  6929. + CLEAR_PENDING_EXCEPTION;
  6930. }
  6931. }
  6932. }
  6933. - // We have entries mapped between the new and merged constant pools
  6934. - // so we have to rewrite some constant pool references.
  6935. - if (!rewrite_cp_refs(scratch_class, THREAD)) {
  6936. - return JVMTI_ERROR_INTERNAL;
  6937. - }
  6938. -
  6939. - // Replace the new constant pool with a shrunken copy of the
  6940. - // merged constant pool so now the rewritten bytecodes have
  6941. - // valid references; the previous new constant pool will get
  6942. - // GCed.
  6943. - set_new_constant_pool(scratch_class, merge_cp, merge_cp_length, true,
  6944. - THREAD);
  6945. - merge_cp()->set_is_conc_safe(true);
  6946. + delete _updated_oops;
  6947. + _updated_oops = NULL;
  6948. }
  6949. - assert(old_cp()->is_conc_safe(), "Just checking");
  6950. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  6951. -
  6952. - return JVMTI_ERROR_NONE;
  6953. -} // end merge_cp_and_rewrite()
  6954. -
  6955. -
  6956. -// Rewrite constant pool references in klass scratch_class.
  6957. -bool VM_RedefineClasses::rewrite_cp_refs(instanceKlassHandle scratch_class,
  6958. - TRAPS) {
  6959. -
  6960. - // rewrite constant pool references in the methods:
  6961. - if (!rewrite_cp_refs_in_methods(scratch_class, THREAD)) {
  6962. - // propagate failure back to caller
  6963. +
  6964. + // Free the array of scratch classes
  6965. + delete _new_classes;
  6966. + _new_classes = NULL;
  6967. + TRACE_RC1("Redefinition finished!");
  6968. +
  6969. + RC_TIMER_STOP(_timer_vm_op_epilogue);
  6970. +}
  6971. +
  6972. +bool VM_RedefineClasses::is_modifiable_class(oop klass_mirror) {
  6973. + // classes for primitives cannot be redefined
  6974. + if (java_lang_Class::is_primitive(klass_mirror)) {
  6975. return false;
  6976. }
  6977. -
  6978. - // rewrite constant pool references in the class_annotations:
  6979. - if (!rewrite_cp_refs_in_class_annotations(scratch_class, THREAD)) {
  6980. - // propagate failure back to caller
  6981. + klassOop the_class_oop = java_lang_Class::as_klassOop(klass_mirror);
  6982. + // classes for arrays cannot be redefined
  6983. + if (the_class_oop == NULL || !Klass::cast(the_class_oop)->oop_is_instance()) {
  6984. return false;
  6985. }
  6986. -
  6987. - // rewrite constant pool references in the fields_annotations:
  6988. - if (!rewrite_cp_refs_in_fields_annotations(scratch_class, THREAD)) {
  6989. - // propagate failure back to caller
  6990. - return false;
  6991. - }
  6992. -
  6993. - // rewrite constant pool references in the methods_annotations:
  6994. - if (!rewrite_cp_refs_in_methods_annotations(scratch_class, THREAD)) {
  6995. - // propagate failure back to caller
  6996. - return false;
  6997. - }
  6998. -
  6999. - // rewrite constant pool references in the methods_parameter_annotations:
  7000. - if (!rewrite_cp_refs_in_methods_parameter_annotations(scratch_class,
  7001. - THREAD)) {
  7002. - // propagate failure back to caller
  7003. - return false;
  7004. - }
  7005. -
  7006. - // rewrite constant pool references in the methods_default_annotations:
  7007. - if (!rewrite_cp_refs_in_methods_default_annotations(scratch_class,
  7008. - THREAD)) {
  7009. - // propagate failure back to caller
  7010. - return false;
  7011. - }
  7012. -
  7013. - return true;
  7014. -} // end rewrite_cp_refs()
  7015. -
  7016. -
  7017. -// Rewrite constant pool references in the methods.
  7018. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods(
  7019. - instanceKlassHandle scratch_class, TRAPS) {
  7020. -
  7021. - objArrayHandle methods(THREAD, scratch_class->methods());
  7022. -
  7023. - if (methods.is_null() || methods->length() == 0) {
  7024. - // no methods so nothing to do
  7025. - return true;
  7026. - }
  7027. -
  7028. - // rewrite constant pool references in the methods:
  7029. - for (int i = methods->length() - 1; i >= 0; i--) {
  7030. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  7031. - methodHandle new_method;
  7032. - rewrite_cp_refs_in_method(method, &new_method, CHECK_false);
  7033. - if (!new_method.is_null()) {
  7034. - // the method has been replaced so save the new method version
  7035. - methods->obj_at_put(i, new_method());
  7036. - }
  7037. - }
  7038. -
  7039. return true;
  7040. }
  7041. -
  7042. -// Rewrite constant pool references in the specific method. This code
  7043. -// was adapted from Rewriter::rewrite_method().
  7044. -void VM_RedefineClasses::rewrite_cp_refs_in_method(methodHandle method,
  7045. - methodHandle *new_method_p, TRAPS) {
  7046. -
  7047. - *new_method_p = methodHandle(); // default is no new method
  7048. -
  7049. - // We cache a pointer to the bytecodes here in code_base. If GC
  7050. - // moves the methodOop, then the bytecodes will also move which
  7051. - // will likely cause a crash. We create a No_Safepoint_Verifier
  7052. - // object to detect whether we pass a possible safepoint in this
  7053. - // code block.
  7054. - No_Safepoint_Verifier nsv;
  7055. -
  7056. - // Bytecodes and their length
  7057. - address code_base = method->code_base();
  7058. - int code_length = method->code_size();
  7059. -
  7060. - int bc_length;
  7061. - for (int bci = 0; bci < code_length; bci += bc_length) {
  7062. - address bcp = code_base + bci;
  7063. - Bytecodes::Code c = (Bytecodes::Code)(*bcp);
  7064. -
  7065. - bc_length = Bytecodes::length_for(c);
  7066. - if (bc_length == 0) {
  7067. - // More complicated bytecodes report a length of zero so
  7068. - // we have to try again a slightly different way.
  7069. - bc_length = Bytecodes::length_at(bcp);
  7070. - }
  7071. -
  7072. - assert(bc_length != 0, "impossible bytecode length");
  7073. -
  7074. - switch (c) {
  7075. - case Bytecodes::_ldc:
  7076. - {
  7077. - int cp_index = *(bcp + 1);
  7078. - int new_index = find_new_index(cp_index);
  7079. -
  7080. - if (StressLdcRewrite && new_index == 0) {
  7081. - // If we are stressing ldc -> ldc_w rewriting, then we
  7082. - // always need a new_index value.
  7083. - new_index = cp_index;
  7084. - }
  7085. - if (new_index != 0) {
  7086. - // the original index is mapped so we have more work to do
  7087. - if (!StressLdcRewrite && new_index <= max_jubyte) {
  7088. - // The new value can still use ldc instead of ldc_w
  7089. - // unless we are trying to stress ldc -> ldc_w rewriting
  7090. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7091. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  7092. - bcp, cp_index, new_index));
  7093. - *(bcp + 1) = new_index;
  7094. - } else {
  7095. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7096. - ("%s->ldc_w@" INTPTR_FORMAT " old=%d, new=%d",
  7097. - Bytecodes::name(c), bcp, cp_index, new_index));
  7098. - // the new value needs ldc_w instead of ldc
  7099. - u_char inst_buffer[4]; // max instruction size is 4 bytes
  7100. - bcp = (address)inst_buffer;
  7101. - // construct new instruction sequence
  7102. - *bcp = Bytecodes::_ldc_w;
  7103. - bcp++;
  7104. - // Rewriter::rewrite_method() does not rewrite ldc -> ldc_w.
  7105. - // See comment below for difference between put_Java_u2()
  7106. - // and put_native_u2().
  7107. - Bytes::put_Java_u2(bcp, new_index);
  7108. -
  7109. - Relocator rc(method, NULL /* no RelocatorListener needed */);
  7110. - methodHandle m;
  7111. - {
  7112. - Pause_No_Safepoint_Verifier pnsv(&nsv);
  7113. -
  7114. - // ldc is 2 bytes and ldc_w is 3 bytes
  7115. - m = rc.insert_space_at(bci, 3, inst_buffer, THREAD);
  7116. - if (m.is_null() || HAS_PENDING_EXCEPTION) {
  7117. - guarantee(false, "insert_space_at() failed");
  7118. - }
  7119. - }
  7120. -
  7121. - // return the new method so that the caller can update
  7122. - // the containing class
  7123. - *new_method_p = method = m;
  7124. - // switch our bytecode processing loop from the old method
  7125. - // to the new method
  7126. - code_base = method->code_base();
  7127. - code_length = method->code_size();
  7128. - bcp = code_base + bci;
  7129. - c = (Bytecodes::Code)(*bcp);
  7130. - bc_length = Bytecodes::length_for(c);
  7131. - assert(bc_length != 0, "sanity check");
  7132. - } // end we need ldc_w instead of ldc
  7133. - } // end if there is a mapped index
  7134. - } break;
  7135. -
  7136. - // these bytecodes have a two-byte constant pool index
  7137. - case Bytecodes::_anewarray : // fall through
  7138. - case Bytecodes::_checkcast : // fall through
  7139. - case Bytecodes::_getfield : // fall through
  7140. - case Bytecodes::_getstatic : // fall through
  7141. - case Bytecodes::_instanceof : // fall through
  7142. - case Bytecodes::_invokeinterface: // fall through
  7143. - case Bytecodes::_invokespecial : // fall through
  7144. - case Bytecodes::_invokestatic : // fall through
  7145. - case Bytecodes::_invokevirtual : // fall through
  7146. - case Bytecodes::_ldc_w : // fall through
  7147. - case Bytecodes::_ldc2_w : // fall through
  7148. - case Bytecodes::_multianewarray : // fall through
  7149. - case Bytecodes::_new : // fall through
  7150. - case Bytecodes::_putfield : // fall through
  7151. - case Bytecodes::_putstatic :
  7152. - {
  7153. - address p = bcp + 1;
  7154. - int cp_index = Bytes::get_Java_u2(p);
  7155. - int new_index = find_new_index(cp_index);
  7156. - if (new_index != 0) {
  7157. - // the original index is mapped so update w/ new value
  7158. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7159. - ("%s@" INTPTR_FORMAT " old=%d, new=%d", Bytecodes::name(c),
  7160. - bcp, cp_index, new_index));
  7161. - // Rewriter::rewrite_method() uses put_native_u2() in this
  7162. - // situation because it is reusing the constant pool index
  7163. - // location for a native index into the constantPoolCache.
  7164. - // Since we are updating the constant pool index prior to
  7165. - // verification and constantPoolCache initialization, we
  7166. - // need to keep the new index in Java byte order.
  7167. - Bytes::put_Java_u2(p, new_index);
  7168. - }
  7169. - } break;
  7170. - }
  7171. - } // end for each bytecode
  7172. -} // end rewrite_cp_refs_in_method()
  7173. -
  7174. -
  7175. -// Rewrite constant pool references in the class_annotations field.
  7176. -bool VM_RedefineClasses::rewrite_cp_refs_in_class_annotations(
  7177. - instanceKlassHandle scratch_class, TRAPS) {
  7178. -
  7179. - typeArrayHandle class_annotations(THREAD,
  7180. - scratch_class->class_annotations());
  7181. - if (class_annotations.is_null() || class_annotations->length() == 0) {
  7182. - // no class_annotations so nothing to do
  7183. - return true;
  7184. +#ifdef ASSERT
  7185. +
  7186. +void VM_RedefineClasses::verify_classes(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  7187. + klassOop k_oop = k_oop_latest;
  7188. + while (k_oop != NULL) {
  7189. +
  7190. + instanceKlassHandle k_handle(THREAD, k_oop);
  7191. + Verifier::verify(k_handle, Verifier::ThrowException, true, true, THREAD);
  7192. + k_oop = k_oop->klass_part()->old_version();
  7193. }
  7194. -
  7195. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7196. - ("class_annotations length=%d", class_annotations->length()));
  7197. -
  7198. - int byte_i = 0; // byte index into class_annotations
  7199. - return rewrite_cp_refs_in_annotations_typeArray(class_annotations, byte_i,
  7200. - THREAD);
  7201. }
  7202. -
  7203. -// Rewrite constant pool references in an annotations typeArray. This
  7204. -// "structure" is adapted from the RuntimeVisibleAnnotations_attribute
  7205. -// that is described in section 4.8.15 of the 2nd-edition of the VM spec:
  7206. -//
  7207. -// annotations_typeArray {
  7208. -// u2 num_annotations;
  7209. -// annotation annotations[num_annotations];
  7210. -// }
  7211. -//
  7212. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotations_typeArray(
  7213. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7214. -
  7215. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7216. - // not enough room for num_annotations field
  7217. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7218. - ("length() is too small for num_annotations field"));
  7219. - return false;
  7220. - }
  7221. -
  7222. - u2 num_annotations = Bytes::get_Java_u2((address)
  7223. - annotations_typeArray->byte_at_addr(byte_i_ref));
  7224. - byte_i_ref += 2;
  7225. -
  7226. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7227. - ("num_annotations=%d", num_annotations));
  7228. -
  7229. - int calc_num_annotations = 0;
  7230. - for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
  7231. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  7232. - byte_i_ref, THREAD)) {
  7233. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7234. - ("bad annotation_struct at %d", calc_num_annotations));
  7235. - // propagate failure back to caller
  7236. - return false;
  7237. - }
  7238. - }
  7239. - assert(num_annotations == calc_num_annotations, "sanity check");
  7240. -
  7241. - return true;
  7242. -} // end rewrite_cp_refs_in_annotations_typeArray()
  7243. -
  7244. -
  7245. -// Rewrite constant pool references in the annotation struct portion of
  7246. -// an annotations_typeArray. This "structure" is from section 4.8.15 of
  7247. -// the 2nd-edition of the VM spec:
  7248. -//
  7249. -// struct annotation {
  7250. -// u2 type_index;
  7251. -// u2 num_element_value_pairs;
  7252. -// {
  7253. -// u2 element_name_index;
  7254. -// element_value value;
  7255. -// } element_value_pairs[num_element_value_pairs];
  7256. -// }
  7257. -//
  7258. -bool VM_RedefineClasses::rewrite_cp_refs_in_annotation_struct(
  7259. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7260. - if ((byte_i_ref + 2 + 2) > annotations_typeArray->length()) {
  7261. - // not enough room for smallest annotation_struct
  7262. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7263. - ("length() is too small for annotation_struct"));
  7264. - return false;
  7265. - }
  7266. -
  7267. - u2 type_index = rewrite_cp_ref_in_annotation_data(annotations_typeArray,
  7268. - byte_i_ref, "mapped old type_index=%d", THREAD);
  7269. -
  7270. - u2 num_element_value_pairs = Bytes::get_Java_u2((address)
  7271. - annotations_typeArray->byte_at_addr(
  7272. - byte_i_ref));
  7273. - byte_i_ref += 2;
  7274. -
  7275. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7276. - ("type_index=%d num_element_value_pairs=%d", type_index,
  7277. - num_element_value_pairs));
  7278. -
  7279. - int calc_num_element_value_pairs = 0;
  7280. - for (; calc_num_element_value_pairs < num_element_value_pairs;
  7281. - calc_num_element_value_pairs++) {
  7282. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7283. - // not enough room for another element_name_index, let alone
  7284. - // the rest of another component
  7285. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7286. - ("length() is too small for element_name_index"));
  7287. - return false;
  7288. - }
  7289. -
  7290. - u2 element_name_index = rewrite_cp_ref_in_annotation_data(
  7291. - annotations_typeArray, byte_i_ref,
  7292. - "mapped old element_name_index=%d", THREAD);
  7293. -
  7294. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7295. - ("element_name_index=%d", element_name_index));
  7296. -
  7297. - if (!rewrite_cp_refs_in_element_value(annotations_typeArray,
  7298. - byte_i_ref, THREAD)) {
  7299. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7300. - ("bad element_value at %d", calc_num_element_value_pairs));
  7301. - // propagate failure back to caller
  7302. - return false;
  7303. - }
  7304. - } // end for each component
  7305. - assert(num_element_value_pairs == calc_num_element_value_pairs,
  7306. - "sanity check");
  7307. -
  7308. - return true;
  7309. -} // end rewrite_cp_refs_in_annotation_struct()
  7310. -
  7311. -
  7312. -// Rewrite a constant pool reference at the current position in
  7313. -// annotations_typeArray if needed. Returns the original constant
  7314. -// pool reference if a rewrite was not needed or the new constant
  7315. -// pool reference if a rewrite was needed.
  7316. -u2 VM_RedefineClasses::rewrite_cp_ref_in_annotation_data(
  7317. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  7318. - const char * trace_mesg, TRAPS) {
  7319. -
  7320. - address cp_index_addr = (address)
  7321. - annotations_typeArray->byte_at_addr(byte_i_ref);
  7322. - u2 old_cp_index = Bytes::get_Java_u2(cp_index_addr);
  7323. - u2 new_cp_index = find_new_index(old_cp_index);
  7324. - if (new_cp_index != 0) {
  7325. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, (trace_mesg, old_cp_index));
  7326. - Bytes::put_Java_u2(cp_index_addr, new_cp_index);
  7327. - old_cp_index = new_cp_index;
  7328. - }
  7329. - byte_i_ref += 2;
  7330. - return old_cp_index;
  7331. -}
  7332. -
  7333. -
  7334. -// Rewrite constant pool references in the element_value portion of an
  7335. -// annotations_typeArray. This "structure" is from section 4.8.15.1 of
  7336. -// the 2nd-edition of the VM spec:
  7337. -//
  7338. -// struct element_value {
  7339. -// u1 tag;
  7340. -// union {
  7341. -// u2 const_value_index;
  7342. -// {
  7343. -// u2 type_name_index;
  7344. -// u2 const_name_index;
  7345. -// } enum_const_value;
  7346. -// u2 class_info_index;
  7347. -// annotation annotation_value;
  7348. -// struct {
  7349. -// u2 num_values;
  7350. -// element_value values[num_values];
  7351. -// } array_value;
  7352. -// } value;
  7353. -// }
  7354. -//
  7355. -bool VM_RedefineClasses::rewrite_cp_refs_in_element_value(
  7356. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS) {
  7357. -
  7358. - if ((byte_i_ref + 1) > annotations_typeArray->length()) {
  7359. - // not enough room for a tag let alone the rest of an element_value
  7360. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7361. - ("length() is too small for a tag"));
  7362. - return false;
  7363. - }
  7364. -
  7365. - u1 tag = annotations_typeArray->byte_at(byte_i_ref);
  7366. - byte_i_ref++;
  7367. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("tag='%c'", tag));
  7368. -
  7369. - switch (tag) {
  7370. - // These BaseType tag values are from Table 4.2 in VM spec:
  7371. - case 'B': // byte
  7372. - case 'C': // char
  7373. - case 'D': // double
  7374. - case 'F': // float
  7375. - case 'I': // int
  7376. - case 'J': // long
  7377. - case 'S': // short
  7378. - case 'Z': // boolean
  7379. -
  7380. - // The remaining tag values are from Table 4.8 in the 2nd-edition of
  7381. - // the VM spec:
  7382. - case 's':
  7383. - {
  7384. - // For the above tag values (including the BaseType values),
  7385. - // value.const_value_index is right union field.
  7386. -
  7387. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7388. - // not enough room for a const_value_index
  7389. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7390. - ("length() is too small for a const_value_index"));
  7391. - return false;
  7392. - }
  7393. -
  7394. - u2 const_value_index = rewrite_cp_ref_in_annotation_data(
  7395. - annotations_typeArray, byte_i_ref,
  7396. - "mapped old const_value_index=%d", THREAD);
  7397. -
  7398. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7399. - ("const_value_index=%d", const_value_index));
  7400. - } break;
  7401. -
  7402. - case 'e':
  7403. - {
  7404. - // for the above tag value, value.enum_const_value is right union field
  7405. -
  7406. - if ((byte_i_ref + 4) > annotations_typeArray->length()) {
  7407. - // not enough room for a enum_const_value
  7408. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7409. - ("length() is too small for a enum_const_value"));
  7410. - return false;
  7411. - }
  7412. -
  7413. - u2 type_name_index = rewrite_cp_ref_in_annotation_data(
  7414. - annotations_typeArray, byte_i_ref,
  7415. - "mapped old type_name_index=%d", THREAD);
  7416. -
  7417. - u2 const_name_index = rewrite_cp_ref_in_annotation_data(
  7418. - annotations_typeArray, byte_i_ref,
  7419. - "mapped old const_name_index=%d", THREAD);
  7420. -
  7421. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7422. - ("type_name_index=%d const_name_index=%d", type_name_index,
  7423. - const_name_index));
  7424. - } break;
  7425. -
  7426. - case 'c':
  7427. - {
  7428. - // for the above tag value, value.class_info_index is right union field
  7429. -
  7430. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7431. - // not enough room for a class_info_index
  7432. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7433. - ("length() is too small for a class_info_index"));
  7434. - return false;
  7435. - }
  7436. -
  7437. - u2 class_info_index = rewrite_cp_ref_in_annotation_data(
  7438. - annotations_typeArray, byte_i_ref,
  7439. - "mapped old class_info_index=%d", THREAD);
  7440. -
  7441. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7442. - ("class_info_index=%d", class_info_index));
  7443. - } break;
  7444. -
  7445. - case '@':
  7446. - // For the above tag value, value.attr_value is the right union
  7447. - // field. This is a nested annotation.
  7448. - if (!rewrite_cp_refs_in_annotation_struct(annotations_typeArray,
  7449. - byte_i_ref, THREAD)) {
  7450. - // propagate failure back to caller
  7451. - return false;
  7452. - }
  7453. - break;
  7454. -
  7455. - case '[':
  7456. - {
  7457. - if ((byte_i_ref + 2) > annotations_typeArray->length()) {
  7458. - // not enough room for a num_values field
  7459. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7460. - ("length() is too small for a num_values field"));
  7461. - return false;
  7462. - }
  7463. -
  7464. - // For the above tag value, value.array_value is the right union
  7465. - // field. This is an array of nested element_value.
  7466. - u2 num_values = Bytes::get_Java_u2((address)
  7467. - annotations_typeArray->byte_at_addr(byte_i_ref));
  7468. - byte_i_ref += 2;
  7469. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("num_values=%d", num_values));
  7470. -
  7471. - int calc_num_values = 0;
  7472. - for (; calc_num_values < num_values; calc_num_values++) {
  7473. - if (!rewrite_cp_refs_in_element_value(
  7474. - annotations_typeArray, byte_i_ref, THREAD)) {
  7475. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7476. - ("bad nested element_value at %d", calc_num_values));
  7477. - // propagate failure back to caller
  7478. - return false;
  7479. - }
  7480. - }
  7481. - assert(num_values == calc_num_values, "sanity check");
  7482. - } break;
  7483. -
  7484. - default:
  7485. - RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("bad tag=0x%x", tag));
  7486. - return false;
  7487. - } // end decode tag field
  7488. -
  7489. - return true;
  7490. -} // end rewrite_cp_refs_in_element_value()
  7491. -
  7492. -
  7493. -// Rewrite constant pool references in a fields_annotations field.
  7494. -bool VM_RedefineClasses::rewrite_cp_refs_in_fields_annotations(
  7495. - instanceKlassHandle scratch_class, TRAPS) {
  7496. -
  7497. - objArrayHandle fields_annotations(THREAD,
  7498. - scratch_class->fields_annotations());
  7499. -
  7500. - if (fields_annotations.is_null() || fields_annotations->length() == 0) {
  7501. - // no fields_annotations so nothing to do
  7502. - return true;
  7503. - }
  7504. -
  7505. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7506. - ("fields_annotations length=%d", fields_annotations->length()));
  7507. -
  7508. - for (int i = 0; i < fields_annotations->length(); i++) {
  7509. - typeArrayHandle field_annotations(THREAD,
  7510. - (typeArrayOop)fields_annotations->obj_at(i));
  7511. - if (field_annotations.is_null() || field_annotations->length() == 0) {
  7512. - // this field does not have any annotations so skip it
  7513. - continue;
  7514. - }
  7515. -
  7516. - int byte_i = 0; // byte index into field_annotations
  7517. - if (!rewrite_cp_refs_in_annotations_typeArray(field_annotations, byte_i,
  7518. - THREAD)) {
  7519. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7520. - ("bad field_annotations at %d", i));
  7521. - // propagate failure back to caller
  7522. - return false;
  7523. - }
  7524. - }
  7525. -
  7526. - return true;
  7527. -} // end rewrite_cp_refs_in_fields_annotations()
  7528. -
  7529. -
  7530. -// Rewrite constant pool references in a methods_annotations field.
  7531. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_annotations(
  7532. - instanceKlassHandle scratch_class, TRAPS) {
  7533. -
  7534. - objArrayHandle methods_annotations(THREAD,
  7535. - scratch_class->methods_annotations());
  7536. -
  7537. - if (methods_annotations.is_null() || methods_annotations->length() == 0) {
  7538. - // no methods_annotations so nothing to do
  7539. - return true;
  7540. - }
  7541. -
  7542. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7543. - ("methods_annotations length=%d", methods_annotations->length()));
  7544. -
  7545. - for (int i = 0; i < methods_annotations->length(); i++) {
  7546. - typeArrayHandle method_annotations(THREAD,
  7547. - (typeArrayOop)methods_annotations->obj_at(i));
  7548. - if (method_annotations.is_null() || method_annotations->length() == 0) {
  7549. - // this method does not have any annotations so skip it
  7550. - continue;
  7551. - }
  7552. -
  7553. - int byte_i = 0; // byte index into method_annotations
  7554. - if (!rewrite_cp_refs_in_annotations_typeArray(method_annotations, byte_i,
  7555. - THREAD)) {
  7556. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7557. - ("bad method_annotations at %d", i));
  7558. - // propagate failure back to caller
  7559. - return false;
  7560. - }
  7561. - }
  7562. -
  7563. - return true;
  7564. -} // end rewrite_cp_refs_in_methods_annotations()
  7565. -
  7566. -
  7567. -// Rewrite constant pool references in a methods_parameter_annotations
  7568. -// field. This "structure" is adapted from the
  7569. -// RuntimeVisibleParameterAnnotations_attribute described in section
  7570. -// 4.8.17 of the 2nd-edition of the VM spec:
  7571. -//
  7572. -// methods_parameter_annotations_typeArray {
  7573. -// u1 num_parameters;
  7574. -// {
  7575. -// u2 num_annotations;
  7576. -// annotation annotations[num_annotations];
  7577. -// } parameter_annotations[num_parameters];
  7578. -// }
  7579. -//
  7580. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_parameter_annotations(
  7581. - instanceKlassHandle scratch_class, TRAPS) {
  7582. -
  7583. - objArrayHandle methods_parameter_annotations(THREAD,
  7584. - scratch_class->methods_parameter_annotations());
  7585. -
  7586. - if (methods_parameter_annotations.is_null()
  7587. - || methods_parameter_annotations->length() == 0) {
  7588. - // no methods_parameter_annotations so nothing to do
  7589. - return true;
  7590. - }
  7591. -
  7592. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7593. - ("methods_parameter_annotations length=%d",
  7594. - methods_parameter_annotations->length()));
  7595. -
  7596. - for (int i = 0; i < methods_parameter_annotations->length(); i++) {
  7597. - typeArrayHandle method_parameter_annotations(THREAD,
  7598. - (typeArrayOop)methods_parameter_annotations->obj_at(i));
  7599. - if (method_parameter_annotations.is_null()
  7600. - || method_parameter_annotations->length() == 0) {
  7601. - // this method does not have any parameter annotations so skip it
  7602. - continue;
  7603. - }
  7604. -
  7605. - if (method_parameter_annotations->length() < 1) {
  7606. - // not enough room for a num_parameters field
  7607. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7608. - ("length() is too small for a num_parameters field at %d", i));
  7609. - return false;
  7610. - }
  7611. -
  7612. - int byte_i = 0; // byte index into method_parameter_annotations
  7613. -
  7614. - u1 num_parameters = method_parameter_annotations->byte_at(byte_i);
  7615. - byte_i++;
  7616. -
  7617. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7618. - ("num_parameters=%d", num_parameters));
  7619. -
  7620. - int calc_num_parameters = 0;
  7621. - for (; calc_num_parameters < num_parameters; calc_num_parameters++) {
  7622. - if (!rewrite_cp_refs_in_annotations_typeArray(
  7623. - method_parameter_annotations, byte_i, THREAD)) {
  7624. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7625. - ("bad method_parameter_annotations at %d", calc_num_parameters));
  7626. - // propagate failure back to caller
  7627. - return false;
  7628. - }
  7629. - }
  7630. - assert(num_parameters == calc_num_parameters, "sanity check");
  7631. - }
  7632. -
  7633. - return true;
  7634. -} // end rewrite_cp_refs_in_methods_parameter_annotations()
  7635. -
  7636. -
  7637. -// Rewrite constant pool references in a methods_default_annotations
  7638. -// field. This "structure" is adapted from the AnnotationDefault_attribute
  7639. -// that is described in section 4.8.19 of the 2nd-edition of the VM spec:
  7640. -//
  7641. -// methods_default_annotations_typeArray {
  7642. -// element_value default_value;
  7643. -// }
  7644. -//
  7645. -bool VM_RedefineClasses::rewrite_cp_refs_in_methods_default_annotations(
  7646. - instanceKlassHandle scratch_class, TRAPS) {
  7647. -
  7648. - objArrayHandle methods_default_annotations(THREAD,
  7649. - scratch_class->methods_default_annotations());
  7650. -
  7651. - if (methods_default_annotations.is_null()
  7652. - || methods_default_annotations->length() == 0) {
  7653. - // no methods_default_annotations so nothing to do
  7654. - return true;
  7655. - }
  7656. -
  7657. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7658. - ("methods_default_annotations length=%d",
  7659. - methods_default_annotations->length()));
  7660. -
  7661. - for (int i = 0; i < methods_default_annotations->length(); i++) {
  7662. - typeArrayHandle method_default_annotations(THREAD,
  7663. - (typeArrayOop)methods_default_annotations->obj_at(i));
  7664. - if (method_default_annotations.is_null()
  7665. - || method_default_annotations->length() == 0) {
  7666. - // this method does not have any default annotations so skip it
  7667. - continue;
  7668. - }
  7669. -
  7670. - int byte_i = 0; // byte index into method_default_annotations
  7671. -
  7672. - if (!rewrite_cp_refs_in_element_value(
  7673. - method_default_annotations, byte_i, THREAD)) {
  7674. - RC_TRACE_WITH_THREAD(0x02000000, THREAD,
  7675. - ("bad default element_value at %d", i));
  7676. - // propagate failure back to caller
  7677. - return false;
  7678. - }
  7679. - }
  7680. -
  7681. - return true;
  7682. -} // end rewrite_cp_refs_in_methods_default_annotations()
  7683. -
  7684. -
  7685. -// Rewrite constant pool references in the method's stackmap table.
  7686. -// These "structures" are adapted from the StackMapTable_attribute that
  7687. -// is described in section 4.8.4 of the 6.0 version of the VM spec
  7688. -// (dated 2005.10.26):
  7689. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  7690. -//
  7691. -// stack_map {
  7692. -// u2 number_of_entries;
  7693. -// stack_map_frame entries[number_of_entries];
  7694. -// }
  7695. -//
  7696. -void VM_RedefineClasses::rewrite_cp_refs_in_stack_map_table(
  7697. - methodHandle method, TRAPS) {
  7698. -
  7699. - if (!method->has_stackmap_table()) {
  7700. - return;
  7701. - }
  7702. -
  7703. - typeArrayOop stackmap_data = method->stackmap_data();
  7704. - address stackmap_p = (address)stackmap_data->byte_at_addr(0);
  7705. - address stackmap_end = stackmap_p + stackmap_data->length();
  7706. -
  7707. - assert(stackmap_p + 2 <= stackmap_end, "no room for number_of_entries");
  7708. - u2 number_of_entries = Bytes::get_Java_u2(stackmap_p);
  7709. - stackmap_p += 2;
  7710. -
  7711. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  7712. - ("number_of_entries=%u", number_of_entries));
  7713. -
  7714. - // walk through each stack_map_frame
  7715. - u2 calc_number_of_entries = 0;
  7716. - for (; calc_number_of_entries < number_of_entries; calc_number_of_entries++) {
  7717. - // The stack_map_frame structure is a u1 frame_type followed by
  7718. - // 0 or more bytes of data:
  7719. - //
  7720. - // union stack_map_frame {
  7721. - // same_frame;
  7722. - // same_locals_1_stack_item_frame;
  7723. - // same_locals_1_stack_item_frame_extended;
  7724. - // chop_frame;
  7725. - // same_frame_extended;
  7726. - // append_frame;
  7727. - // full_frame;
  7728. - // }
  7729. -
  7730. - assert(stackmap_p + 1 <= stackmap_end, "no room for frame_type");
  7731. - // The Linux compiler does not like frame_type to be u1 or u2. It
  7732. - // issues the following warning for the first if-statement below:
  7733. - //
  7734. - // "warning: comparison is always true due to limited range of data type"
  7735. - //
  7736. - u4 frame_type = *stackmap_p;
  7737. - stackmap_p++;
  7738. -
  7739. - // same_frame {
  7740. - // u1 frame_type = SAME; /* 0-63 */
  7741. - // }
  7742. - if (frame_type >= 0 && frame_type <= 63) {
  7743. - // nothing more to do for same_frame
  7744. - }
  7745. -
  7746. - // same_locals_1_stack_item_frame {
  7747. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM; /* 64-127 */
  7748. - // verification_type_info stack[1];
  7749. - // }
  7750. - else if (frame_type >= 64 && frame_type <= 127) {
  7751. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  7752. - calc_number_of_entries, frame_type, THREAD);
  7753. - }
  7754. -
  7755. - // reserved for future use
  7756. - else if (frame_type >= 128 && frame_type <= 246) {
  7757. - // nothing more to do for reserved frame_types
  7758. - }
  7759. -
  7760. - // same_locals_1_stack_item_frame_extended {
  7761. - // u1 frame_type = SAME_LOCALS_1_STACK_ITEM_EXTENDED; /* 247 */
  7762. - // u2 offset_delta;
  7763. - // verification_type_info stack[1];
  7764. - // }
  7765. - else if (frame_type == 247) {
  7766. - stackmap_p += 2;
  7767. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  7768. - calc_number_of_entries, frame_type, THREAD);
  7769. - }
  7770. -
  7771. - // chop_frame {
  7772. - // u1 frame_type = CHOP; /* 248-250 */
  7773. - // u2 offset_delta;
  7774. - // }
  7775. - else if (frame_type >= 248 && frame_type <= 250) {
  7776. - stackmap_p += 2;
  7777. - }
  7778. -
  7779. - // same_frame_extended {
  7780. - // u1 frame_type = SAME_FRAME_EXTENDED; /* 251*/
  7781. - // u2 offset_delta;
  7782. - // }
  7783. - else if (frame_type == 251) {
  7784. - stackmap_p += 2;
  7785. - }
  7786. -
  7787. - // append_frame {
  7788. - // u1 frame_type = APPEND; /* 252-254 */
  7789. - // u2 offset_delta;
  7790. - // verification_type_info locals[frame_type - 251];
  7791. - // }
  7792. - else if (frame_type >= 252 && frame_type <= 254) {
  7793. - assert(stackmap_p + 2 <= stackmap_end,
  7794. - "no room for offset_delta");
  7795. - stackmap_p += 2;
  7796. - u1 len = frame_type - 251;
  7797. - for (u1 i = 0; i < len; i++) {
  7798. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  7799. - calc_number_of_entries, frame_type, THREAD);
  7800. - }
  7801. - }
  7802. -
  7803. - // full_frame {
  7804. - // u1 frame_type = FULL_FRAME; /* 255 */
  7805. - // u2 offset_delta;
  7806. - // u2 number_of_locals;
  7807. - // verification_type_info locals[number_of_locals];
  7808. - // u2 number_of_stack_items;
  7809. - // verification_type_info stack[number_of_stack_items];
  7810. - // }
  7811. - else if (frame_type == 255) {
  7812. - assert(stackmap_p + 2 + 2 <= stackmap_end,
  7813. - "no room for smallest full_frame");
  7814. - stackmap_p += 2;
  7815. -
  7816. - u2 number_of_locals = Bytes::get_Java_u2(stackmap_p);
  7817. - stackmap_p += 2;
  7818. -
  7819. - for (u2 locals_i = 0; locals_i < number_of_locals; locals_i++) {
  7820. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  7821. - calc_number_of_entries, frame_type, THREAD);
  7822. - }
  7823. -
  7824. - // Use the largest size for the number_of_stack_items, but only get
  7825. - // the right number of bytes.
  7826. - u2 number_of_stack_items = Bytes::get_Java_u2(stackmap_p);
  7827. - stackmap_p += 2;
  7828. -
  7829. - for (u2 stack_i = 0; stack_i < number_of_stack_items; stack_i++) {
  7830. - rewrite_cp_refs_in_verification_type_info(stackmap_p, stackmap_end,
  7831. - calc_number_of_entries, frame_type, THREAD);
  7832. - }
  7833. - }
  7834. - } // end while there is a stack_map_frame
  7835. - assert(number_of_entries == calc_number_of_entries, "sanity check");
  7836. -} // end rewrite_cp_refs_in_stack_map_table()
  7837. -
  7838. -
  7839. -// Rewrite constant pool references in the verification type info
  7840. -// portion of the method's stackmap table. These "structures" are
  7841. -// adapted from the StackMapTable_attribute that is described in
  7842. -// section 4.8.4 of the 6.0 version of the VM spec (dated 2005.10.26):
  7843. -// file:///net/quincunx.sfbay/export/gbracha/ClassFile-Java6.pdf
  7844. -//
  7845. -// The verification_type_info structure is a u1 tag followed by 0 or
  7846. -// more bytes of data:
  7847. -//
  7848. -// union verification_type_info {
  7849. -// Top_variable_info;
  7850. -// Integer_variable_info;
  7851. -// Float_variable_info;
  7852. -// Long_variable_info;
  7853. -// Double_variable_info;
  7854. -// Null_variable_info;
  7855. -// UninitializedThis_variable_info;
  7856. -// Object_variable_info;
  7857. -// Uninitialized_variable_info;
  7858. -// }
  7859. -//
  7860. -void VM_RedefineClasses::rewrite_cp_refs_in_verification_type_info(
  7861. - address& stackmap_p_ref, address stackmap_end, u2 frame_i,
  7862. - u1 frame_type, TRAPS) {
  7863. -
  7864. - assert(stackmap_p_ref + 1 <= stackmap_end, "no room for tag");
  7865. - u1 tag = *stackmap_p_ref;
  7866. - stackmap_p_ref++;
  7867. -
  7868. - switch (tag) {
  7869. - // Top_variable_info {
  7870. - // u1 tag = ITEM_Top; /* 0 */
  7871. - // }
  7872. - // verificationType.hpp has zero as ITEM_Bogus instead of ITEM_Top
  7873. - case 0: // fall through
  7874. -
  7875. - // Integer_variable_info {
  7876. - // u1 tag = ITEM_Integer; /* 1 */
  7877. - // }
  7878. - case ITEM_Integer: // fall through
  7879. -
  7880. - // Float_variable_info {
  7881. - // u1 tag = ITEM_Float; /* 2 */
  7882. - // }
  7883. - case ITEM_Float: // fall through
  7884. -
  7885. - // Double_variable_info {
  7886. - // u1 tag = ITEM_Double; /* 3 */
  7887. - // }
  7888. - case ITEM_Double: // fall through
  7889. -
  7890. - // Long_variable_info {
  7891. - // u1 tag = ITEM_Long; /* 4 */
  7892. - // }
  7893. - case ITEM_Long: // fall through
  7894. -
  7895. - // Null_variable_info {
  7896. - // u1 tag = ITEM_Null; /* 5 */
  7897. - // }
  7898. - case ITEM_Null: // fall through
  7899. -
  7900. - // UninitializedThis_variable_info {
  7901. - // u1 tag = ITEM_UninitializedThis; /* 6 */
  7902. - // }
  7903. - case ITEM_UninitializedThis:
  7904. - // nothing more to do for the above tag types
  7905. - break;
  7906. -
  7907. - // Object_variable_info {
  7908. - // u1 tag = ITEM_Object; /* 7 */
  7909. - // u2 cpool_index;
  7910. - // }
  7911. - case ITEM_Object:
  7912. - {
  7913. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for cpool_index");
  7914. - u2 cpool_index = Bytes::get_Java_u2(stackmap_p_ref);
  7915. - u2 new_cp_index = find_new_index(cpool_index);
  7916. - if (new_cp_index != 0) {
  7917. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  7918. - ("mapped old cpool_index=%d", cpool_index));
  7919. - Bytes::put_Java_u2(stackmap_p_ref, new_cp_index);
  7920. - cpool_index = new_cp_index;
  7921. - }
  7922. - stackmap_p_ref += 2;
  7923. -
  7924. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  7925. - ("frame_i=%u, frame_type=%u, cpool_index=%d", frame_i,
  7926. - frame_type, cpool_index));
  7927. - } break;
  7928. -
  7929. - // Uninitialized_variable_info {
  7930. - // u1 tag = ITEM_Uninitialized; /* 8 */
  7931. - // u2 offset;
  7932. - // }
  7933. - case ITEM_Uninitialized:
  7934. - assert(stackmap_p_ref + 2 <= stackmap_end, "no room for offset");
  7935. - stackmap_p_ref += 2;
  7936. - break;
  7937. -
  7938. - default:
  7939. - RC_TRACE_WITH_THREAD(0x04000000, THREAD,
  7940. - ("frame_i=%u, frame_type=%u, bad tag=0x%x", frame_i, frame_type, tag));
  7941. - ShouldNotReachHere();
  7942. - break;
  7943. - } // end switch (tag)
  7944. -} // end rewrite_cp_refs_in_verification_type_info()
  7945. -
  7946. -
  7947. -// Change the constant pool associated with klass scratch_class to
  7948. -// scratch_cp. If shrink is true, then scratch_cp_length elements
  7949. -// are copied from scratch_cp to a smaller constant pool and the
  7950. -// smaller constant pool is associated with scratch_class.
  7951. -void VM_RedefineClasses::set_new_constant_pool(
  7952. - instanceKlassHandle scratch_class, constantPoolHandle scratch_cp,
  7953. - int scratch_cp_length, bool shrink, TRAPS) {
  7954. - assert(!shrink || scratch_cp->length() >= scratch_cp_length, "sanity check");
  7955. -
  7956. - if (shrink) {
  7957. - // scratch_cp is a merged constant pool and has enough space for a
  7958. - // worst case merge situation. We want to associate the minimum
  7959. - // sized constant pool with the klass to save space.
  7960. - constantPoolHandle smaller_cp(THREAD,
  7961. - oopFactory::new_constantPool(scratch_cp_length,
  7962. - methodOopDesc::IsUnsafeConc,
  7963. - THREAD));
  7964. - // preserve orig_length() value in the smaller copy
  7965. - int orig_length = scratch_cp->orig_length();
  7966. - assert(orig_length != 0, "sanity check");
  7967. - smaller_cp->set_orig_length(orig_length);
  7968. - scratch_cp->copy_cp_to(1, scratch_cp_length - 1, smaller_cp, 1, THREAD);
  7969. - scratch_cp = smaller_cp;
  7970. - smaller_cp()->set_is_conc_safe(true);
  7971. - }
  7972. -
  7973. - // attach new constant pool to klass
  7974. - scratch_cp->set_pool_holder(scratch_class());
  7975. -
  7976. - // attach klass to new constant pool
  7977. - scratch_class->set_constants(scratch_cp());
  7978. -
  7979. - int i; // for portability
  7980. -
  7981. - // update each field in klass to use new constant pool indices as needed
  7982. - typeArrayHandle fields(THREAD, scratch_class->fields());
  7983. - int n_fields = fields->length();
  7984. - for (i = 0; i < n_fields; i += instanceKlass::next_offset) {
  7985. - jshort cur_index = fields->short_at(i + instanceKlass::name_index_offset);
  7986. - jshort new_index = find_new_index(cur_index);
  7987. - if (new_index != 0) {
  7988. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7989. - ("field-name_index change: %d to %d", cur_index, new_index));
  7990. - fields->short_at_put(i + instanceKlass::name_index_offset, new_index);
  7991. - }
  7992. - cur_index = fields->short_at(i + instanceKlass::signature_index_offset);
  7993. - new_index = find_new_index(cur_index);
  7994. - if (new_index != 0) {
  7995. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  7996. - ("field-signature_index change: %d to %d", cur_index, new_index));
  7997. - fields->short_at_put(i + instanceKlass::signature_index_offset,
  7998. - new_index);
  7999. - }
  8000. - cur_index = fields->short_at(i + instanceKlass::initval_index_offset);
  8001. - new_index = find_new_index(cur_index);
  8002. - if (new_index != 0) {
  8003. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8004. - ("field-initval_index change: %d to %d", cur_index, new_index));
  8005. - fields->short_at_put(i + instanceKlass::initval_index_offset, new_index);
  8006. - }
  8007. - cur_index = fields->short_at(i + instanceKlass::generic_signature_offset);
  8008. - new_index = find_new_index(cur_index);
  8009. - if (new_index != 0) {
  8010. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8011. - ("field-generic_signature change: %d to %d", cur_index, new_index));
  8012. - fields->short_at_put(i + instanceKlass::generic_signature_offset,
  8013. - new_index);
  8014. - }
  8015. - } // end for each field
  8016. -
  8017. - // Update constant pool indices in the inner classes info to use
  8018. - // new constant indices as needed. The inner classes info is a
  8019. - // quadruple:
  8020. - // (inner_class_info, outer_class_info, inner_name, inner_access_flags)
  8021. - typeArrayOop inner_class_list = scratch_class->inner_classes();
  8022. - int icl_length = (inner_class_list == NULL) ? 0 : inner_class_list->length();
  8023. - if (icl_length > 0) {
  8024. - typeArrayHandle inner_class_list_h(THREAD, inner_class_list);
  8025. - for (int i = 0; i < icl_length;
  8026. - i += instanceKlass::inner_class_next_offset) {
  8027. - int cur_index = inner_class_list_h->ushort_at(i
  8028. - + instanceKlass::inner_class_inner_class_info_offset);
  8029. - if (cur_index == 0) {
  8030. - continue; // JVM spec. allows null inner class refs so skip it
  8031. - }
  8032. - int new_index = find_new_index(cur_index);
  8033. - if (new_index != 0) {
  8034. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8035. - ("inner_class_info change: %d to %d", cur_index, new_index));
  8036. - inner_class_list_h->ushort_at_put(i
  8037. - + instanceKlass::inner_class_inner_class_info_offset, new_index);
  8038. - }
  8039. - cur_index = inner_class_list_h->ushort_at(i
  8040. - + instanceKlass::inner_class_outer_class_info_offset);
  8041. - new_index = find_new_index(cur_index);
  8042. - if (new_index != 0) {
  8043. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8044. - ("outer_class_info change: %d to %d", cur_index, new_index));
  8045. - inner_class_list_h->ushort_at_put(i
  8046. - + instanceKlass::inner_class_outer_class_info_offset, new_index);
  8047. - }
  8048. - cur_index = inner_class_list_h->ushort_at(i
  8049. - + instanceKlass::inner_class_inner_name_offset);
  8050. - new_index = find_new_index(cur_index);
  8051. - if (new_index != 0) {
  8052. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8053. - ("inner_name change: %d to %d", cur_index, new_index));
  8054. - inner_class_list_h->ushort_at_put(i
  8055. - + instanceKlass::inner_class_inner_name_offset, new_index);
  8056. - }
  8057. - } // end for each inner class
  8058. - } // end if we have inner classes
  8059. -
  8060. - // Attach each method in klass to the new constant pool and update
  8061. - // to use new constant pool indices as needed:
  8062. - objArrayHandle methods(THREAD, scratch_class->methods());
  8063. - for (i = methods->length() - 1; i >= 0; i--) {
  8064. - methodHandle method(THREAD, (methodOop)methods->obj_at(i));
  8065. - method->set_constants(scratch_cp());
  8066. -
  8067. - int new_index = find_new_index(method->name_index());
  8068. - if (new_index != 0) {
  8069. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8070. - ("method-name_index change: %d to %d", method->name_index(),
  8071. - new_index));
  8072. - method->set_name_index(new_index);
  8073. - }
  8074. - new_index = find_new_index(method->signature_index());
  8075. - if (new_index != 0) {
  8076. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8077. - ("method-signature_index change: %d to %d",
  8078. - method->signature_index(), new_index));
  8079. - method->set_signature_index(new_index);
  8080. - }
  8081. - new_index = find_new_index(method->generic_signature_index());
  8082. - if (new_index != 0) {
  8083. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8084. - ("method-generic_signature_index change: %d to %d",
  8085. - method->generic_signature_index(), new_index));
  8086. - method->set_generic_signature_index(new_index);
  8087. - }
  8088. -
  8089. - // Update constant pool indices in the method's checked exception
  8090. - // table to use new constant indices as needed.
  8091. - int cext_length = method->checked_exceptions_length();
  8092. - if (cext_length > 0) {
  8093. - CheckedExceptionElement * cext_table =
  8094. - method->checked_exceptions_start();
  8095. - for (int j = 0; j < cext_length; j++) {
  8096. - int cur_index = cext_table[j].class_cp_index;
  8097. - int new_index = find_new_index(cur_index);
  8098. - if (new_index != 0) {
  8099. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8100. - ("cext-class_cp_index change: %d to %d", cur_index, new_index));
  8101. - cext_table[j].class_cp_index = (u2)new_index;
  8102. - }
  8103. - } // end for each checked exception table entry
  8104. - } // end if there are checked exception table entries
  8105. -
  8106. - // Update each catch type index in the method's exception table
  8107. - // to use new constant pool indices as needed. The exception table
  8108. - // holds quadruple entries of the form:
  8109. - // (beg_bci, end_bci, handler_bci, klass_index)
  8110. - const int beg_bci_offset = 0;
  8111. - const int end_bci_offset = 1;
  8112. - const int handler_bci_offset = 2;
  8113. - const int klass_index_offset = 3;
  8114. - const int entry_size = 4;
  8115. -
  8116. - typeArrayHandle ex_table (THREAD, method->exception_table());
  8117. - int ext_length = ex_table->length();
  8118. - assert(ext_length % entry_size == 0, "exception table format has changed");
  8119. -
  8120. - for (int j = 0; j < ext_length; j += entry_size) {
  8121. - int cur_index = ex_table->int_at(j + klass_index_offset);
  8122. - int new_index = find_new_index(cur_index);
  8123. - if (new_index != 0) {
  8124. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8125. - ("ext-klass_index change: %d to %d", cur_index, new_index));
  8126. - ex_table->int_at_put(j + klass_index_offset, new_index);
  8127. - }
  8128. - } // end for each exception table entry
  8129. -
  8130. - // Update constant pool indices in the method's local variable
  8131. - // table to use new constant indices as needed. The local variable
  8132. - // table hold sextuple entries of the form:
  8133. - // (start_pc, length, name_index, descriptor_index, signature_index, slot)
  8134. - int lvt_length = method->localvariable_table_length();
  8135. - if (lvt_length > 0) {
  8136. - LocalVariableTableElement * lv_table =
  8137. - method->localvariable_table_start();
  8138. - for (int j = 0; j < lvt_length; j++) {
  8139. - int cur_index = lv_table[j].name_cp_index;
  8140. - int new_index = find_new_index(cur_index);
  8141. - if (new_index != 0) {
  8142. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8143. - ("lvt-name_cp_index change: %d to %d", cur_index, new_index));
  8144. - lv_table[j].name_cp_index = (u2)new_index;
  8145. - }
  8146. - cur_index = lv_table[j].descriptor_cp_index;
  8147. - new_index = find_new_index(cur_index);
  8148. - if (new_index != 0) {
  8149. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8150. - ("lvt-descriptor_cp_index change: %d to %d", cur_index,
  8151. - new_index));
  8152. - lv_table[j].descriptor_cp_index = (u2)new_index;
  8153. - }
  8154. - cur_index = lv_table[j].signature_cp_index;
  8155. - new_index = find_new_index(cur_index);
  8156. - if (new_index != 0) {
  8157. - RC_TRACE_WITH_THREAD(0x00080000, THREAD,
  8158. - ("lvt-signature_cp_index change: %d to %d", cur_index, new_index));
  8159. - lv_table[j].signature_cp_index = (u2)new_index;
  8160. - }
  8161. - } // end for each local variable table entry
  8162. - } // end if there are local variable table entries
  8163. -
  8164. - rewrite_cp_refs_in_stack_map_table(method, THREAD);
  8165. - } // end for each method
  8166. - assert(scratch_cp()->is_conc_safe(), "Just checking");
  8167. -} // end set_new_constant_pool()
  8168. -
  8169. -
  8170. -// Unevolving classes may point to methods of the_class directly
  8171. +#endif
  8172. +
  8173. +
  8174. +// Unevolving classes may point to old methods directly
  8175. // from their constant pool caches, itables, and/or vtables. We
  8176. // use the SystemDictionary::classes_do() facility and this helper
  8177. -// to fix up these pointers.
  8178. +// to fix up these pointers. Additional field offsets and vtable indices
  8179. +// in the constant pool cache entries are fixed.
  8180. //
  8181. // Note: We currently don't support updating the vtable in
  8182. // arrayKlassOops. See Open Issues in jvmtiRedefineClasses.hpp.
  8183. -void VM_RedefineClasses::adjust_cpool_cache_and_vtable(klassOop k_oop,
  8184. - oop initiating_loader, TRAPS) {
  8185. +void VM_RedefineClasses::adjust_cpool_cache(klassOop k_oop_latest, oop initiating_loader, TRAPS) {
  8186. + klassOop k_oop = k_oop_latest;
  8187. + while (k_oop != NULL) {
  8188. + //tty->print_cr("name=%s", k_oop->klass_part()->name()->as_C_string());
  8189. +/*
  8190. + methodOop *matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  8191. + methodOop *matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  8192. +
  8193. + for (int i=0; i<_matching_methods_length; i++) {
  8194. + matching_old_methods[i] = (methodOop)_old_methods->obj_at(_matching_old_methods[i]);
  8195. + matching_new_methods[i] = (methodOop)_new_methods->obj_at(_matching_new_methods[i]);
  8196. + }*/
  8197. +
  8198. + Klass *k = k_oop->klass_part();
  8199. + if (k->oop_is_instance()) {
  8200. + HandleMark hm(THREAD);
  8201. + instanceKlass *ik = (instanceKlass *) k;
  8202. +
  8203. + constantPoolHandle other_cp;
  8204. + constantPoolCacheOop cp_cache;
  8205. +
  8206. + other_cp = constantPoolHandle(ik->constants());
  8207. +
  8208. + for (int i=0; i<other_cp->length(); i++) {
  8209. + if (other_cp->tag_at(i).is_klass()) {
  8210. + klassOop klass = other_cp->klass_at(i, THREAD);
  8211. + if (klass->klass_part()->new_version() != NULL) {
  8212. +
  8213. + // (tw) TODO: check why/if this is necessary
  8214. + other_cp->klass_at_put(i, klass->klass_part()->new_version());
  8215. + }
  8216. + klass = other_cp->klass_at(i, THREAD);
  8217. + assert(klass->klass_part()->new_version() == NULL, "Must be new klass!");
  8218. + }
  8219. + }
  8220. +
  8221. + cp_cache = other_cp->cache();
  8222. +
  8223. + if (cp_cache != NULL) {
  8224. + cp_cache->adjust_entries(NULL,
  8225. + NULL,
  8226. + 0);
  8227. + }
  8228. + }
  8229. + k_oop = k_oop->klass_part()->old_version();
  8230. + }
  8231. +}
  8232. +
  8233. +void VM_RedefineClasses::update_jmethod_ids() {
  8234. + for (int j = 0; j < _matching_methods_length; ++j) {
  8235. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  8236. + TRACE_RC3("matching method %s", old_method->name_and_sig_as_C_string());
  8237. +
  8238. + jmethodID jmid = old_method->find_jmethod_id_or_null();
  8239. + if (old_method->new_version() != NULL && jmid == NULL) {
  8240. + // (tw) Have to create jmethodID in this case
  8241. + jmid = old_method->jmethod_id();
  8242. + }
  8243. +
  8244. + if (jmid != NULL) {
  8245. + // There is a jmethodID, change it to point to the new method
  8246. + methodHandle new_method_h((methodOop)_new_methods->obj_at(_matching_new_methods[j]));
  8247. + if (old_method->new_version() == NULL) {
  8248. + methodHandle old_method_h((methodOop)_old_methods->obj_at(_matching_old_methods[j]));
  8249. + jmethodID new_jmethod_id = JNIHandles::make_jmethod_id(old_method_h);
  8250. + bool result = instanceKlass::cast(old_method_h->method_holder())->update_jmethod_id(old_method_h(), new_jmethod_id);
  8251. + //TRACE_RC3("Changed jmethodID for old method assigned to %d / result=%d", new_jmethod_id, result);
  8252. + //TRACE_RC3("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  8253. + } else {
  8254. + jmethodID mid = new_method_h->jmethod_id();
  8255. + bool result = instanceKlass::cast(new_method_h->method_holder())->update_jmethod_id(new_method_h(), jmid);
  8256. + //TRACE_RC3("Changed jmethodID for new method assigned to %d / result=%d", jmid, result);
  8257. +
  8258. + }
  8259. + JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  8260. + //TRACE_RC3("changing method associated with jmethod id %d to %s", (int)jmid, new_method_h->name()->as_C_string());
  8261. + assert(JNIHandles::resolve_jmethod_id(jmid) == (methodOop)_new_methods->obj_at(_matching_new_methods[j]), "should be replaced");
  8262. + jmethodID mid = ((methodOop)_new_methods->obj_at(_matching_new_methods[j]))->jmethod_id();
  8263. + assert(JNIHandles::resolve_non_null((jobject)mid) == new_method_h(), "must match!");
  8264. +
  8265. + //TRACE_RC3("jmethodID new method: %d jmethodID old method: %d", new_method_h->jmethod_id(), old_method->jmethod_id());
  8266. + }
  8267. + }
  8268. +}
  8269. +
  8270. +
  8271. +// Deoptimize all compiled code that depends on this class.
  8272. +//
  8273. +// If the can_redefine_classes capability is obtained in the onload
  8274. +// phase then the compiler has recorded all dependencies from startup.
  8275. +// In that case we need only deoptimize and throw away all compiled code
  8276. +// that depends on the class.
  8277. +//
  8278. +// If can_redefine_classes is obtained sometime after the onload
  8279. +// phase then the dependency information may be incomplete. In that case
  8280. +// the first call to RedefineClasses causes all compiled code to be
  8281. +// thrown away. As can_redefine_classes has been obtained then
  8282. +// all future compilations will record dependencies so second and
  8283. +// subsequent calls to RedefineClasses need only throw away code
  8284. +// that depends on the class.
  8285. +//
  8286. +void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  8287. + assert_locked_or_safepoint(Compile_lock);
  8288. +
  8289. + // All dependencies have been recorded from startup or this is a second or
  8290. + // subsequent use of RedefineClasses
  8291. +
  8292. + // For now deopt all
  8293. + // (tw) TODO: Improve the dependency system such that we can safely deopt only a subset of the methods
  8294. + if (0 && JvmtiExport::all_dependencies_are_recorded()) {
  8295. + Universe::flush_evol_dependents_on(k_h);
  8296. + } else {
  8297. + CodeCache::mark_all_nmethods_for_deoptimization();
  8298. +
  8299. + ResourceMark rm(THREAD);
  8300. + DeoptimizationMarker dm;
  8301. +
  8302. + // Deoptimize all activations depending on marked nmethods
  8303. + Deoptimization::deoptimize_dependents();
  8304. +
  8305. + // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  8306. + CodeCache::make_marked_nmethods_not_entrant();
  8307. +
  8308. + // From now on we know that the dependency information is complete
  8309. + JvmtiExport::set_all_dependencies_are_recorded(true);
  8310. + }
  8311. +}
  8312. +
  8313. +void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  8314. + methodOop old_method;
  8315. + methodOop new_method;
  8316. +
  8317. + _matching_old_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  8318. + _matching_new_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  8319. + _added_methods = NEW_RESOURCE_ARRAY(int, _new_methods->length());
  8320. + _deleted_methods = NEW_RESOURCE_ARRAY(int, _old_methods->length());
  8321. +
  8322. + _matching_methods_length = 0;
  8323. + _deleted_methods_length = 0;
  8324. + _added_methods_length = 0;
  8325. +
  8326. + int nj = 0;
  8327. + int oj = 0;
  8328. + while (true) {
  8329. + if (oj >= _old_methods->length()) {
  8330. + if (nj >= _new_methods->length()) {
  8331. + break; // we've looked at everything, done
  8332. + }
  8333. + // New method at the end
  8334. + new_method = (methodOop) _new_methods->obj_at(nj);
  8335. + _added_methods[_added_methods_length++] = nj;
  8336. + ++nj;
  8337. + } else if (nj >= _new_methods->length()) {
  8338. + // Old method, at the end, is deleted
  8339. + old_method = (methodOop) _old_methods->obj_at(oj);
  8340. + _deleted_methods[_deleted_methods_length++] = oj;
  8341. + ++oj;
  8342. + } else {
  8343. + old_method = (methodOop) _old_methods->obj_at(oj);
  8344. + new_method = (methodOop) _new_methods->obj_at(nj);
  8345. + if (old_method->name() == new_method->name()) {
  8346. + if (old_method->signature() == new_method->signature()) {
  8347. + _matching_old_methods[_matching_methods_length ] = oj;//old_method;
  8348. + _matching_new_methods[_matching_methods_length++] = nj;//new_method;
  8349. + ++nj;
  8350. + ++oj;
  8351. + } else {
  8352. + // added overloaded have already been moved to the end,
  8353. + // so this is a deleted overloaded method
  8354. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  8355. + ++oj;
  8356. + }
  8357. + } else { // names don't match
  8358. + if (old_method->name()->fast_compare(new_method->name()) > 0) {
  8359. + // new method
  8360. + _added_methods[_added_methods_length++] = nj;//new_method;
  8361. + ++nj;
  8362. + } else {
  8363. + // deleted method
  8364. + _deleted_methods[_deleted_methods_length++] = oj;//old_method;
  8365. + ++oj;
  8366. + }
  8367. + }
  8368. + }
  8369. + }
  8370. + assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  8371. + assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  8372. + TRACE_RC3("Matching methods = %d / deleted methods = %d / added methods = %d", _matching_methods_length, _deleted_methods_length, _added_methods_length);
  8373. +}
  8374. +
  8375. +
  8376. +
  8377. +// Install the redefinition of a class:
  8378. +// - house keeping (flushing breakpoints and caches, deoptimizing
  8379. +// dependent compiled code)
  8380. +// - adjusting constant pool caches and vtables in other classes
  8381. +void VM_RedefineClasses::redefine_single_class(instanceKlassHandle the_new_class, TRAPS) {
  8382. +
  8383. + ResourceMark rm(THREAD);
  8384. +
  8385. + assert(the_new_class->old_version() != NULL, "Must not be null");
  8386. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  8387. +
  8388. + instanceKlassHandle the_old_class = instanceKlassHandle(THREAD, the_new_class->old_version());
  8389. +
  8390. +#ifndef JVMTI_KERNEL
  8391. + // Remove all breakpoints in methods of this class
  8392. + JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  8393. + jvmti_breakpoints.clearall_in_class_at_safepoint(the_old_class());
  8394. +#endif // !JVMTI_KERNEL
  8395. +
  8396. + if (the_old_class() == Universe::reflect_invoke_cache()->klass()) {
  8397. + // We are redefining java.lang.reflect.Method. Method.invoke() is
  8398. + // cached and users of the cache care about each active version of
  8399. + // the method so we have to track this previous version.
  8400. + // Do this before methods get switched
  8401. + Universe::reflect_invoke_cache()->add_previous_version(
  8402. + the_old_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  8403. + }
  8404. +
  8405. + _old_methods = the_old_class->methods();
  8406. + _new_methods = the_new_class->methods();
  8407. + _the_class_oop = the_old_class();
  8408. + compute_added_deleted_matching_methods();
  8409. +
  8410. + // track which methods are EMCP for add_previous_version() call below
  8411. +
  8412. + // (tw) TODO: Check if we need the concept of EMCP?
  8413. + BitMap emcp_methods(_old_methods->length());
  8414. + int emcp_method_count = 0;
  8415. + emcp_methods.clear(); // clears 0..(length() - 1)
  8416. +
  8417. + // We need to mark methods as old!!
  8418. + check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  8419. + update_jmethod_ids();
  8420. +
  8421. + // keep track of previous versions of this class
  8422. + the_new_class->add_previous_version(the_old_class, &emcp_methods,
  8423. + emcp_method_count);
  8424. +
  8425. + // TODO:
  8426. + transfer_old_native_function_registrations(the_old_class);
  8427. +
  8428. +
  8429. +
  8430. +#ifdef ASSERT
  8431. +
  8432. +// klassOop systemLookup1 = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  8433. +// assert(systemLookup1 == the_new_class(), "New class must be in system dictionary!");
  8434. +
  8435. + //JNIHandles::verify();
  8436. +
  8437. +// klassOop systemLookup = SystemDictionary::resolve_or_null(the_old_class->name(), the_old_class->class_loader(), the_old_class->protection_domain(), THREAD);
  8438. +
  8439. +// assert(systemLookup == the_new_class(), "New class must be in system dictionary!");
  8440. + assert(the_new_class->old_version() != NULL, "Must not be null");
  8441. + assert(the_new_class->old_version()->klass_part()->new_version() == the_new_class(), "Must equal");
  8442. +
  8443. + for (int i=0; i<the_new_class->methods()->length(); i++) {
  8444. + assert(((methodOop)the_new_class->methods()->obj_at(i))->method_holder() == the_new_class(), "method holder must match!");
  8445. + }
  8446. +
  8447. + _old_methods->verify();
  8448. + _new_methods->verify();
  8449. +
  8450. + the_new_class->vtable()->verify(tty);
  8451. + the_old_class->vtable()->verify(tty);
  8452. +
  8453. +#endif
  8454. +
  8455. + // increment the classRedefinedCount field in the_class and in any
  8456. + // direct and indirect subclasses of the_class
  8457. + increment_class_counter((instanceKlass *)the_old_class()->klass_part(), THREAD);
  8458. +
  8459. +}
  8460. +
  8461. +
  8462. +void VM_RedefineClasses::check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p) {
  8463. + TRACE_RC3("Checking matching methods for EMCP");
  8464. + *emcp_method_count_p = 0;
  8465. + int obsolete_count = 0;
  8466. + int old_index = 0;
  8467. + for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  8468. + methodOop old_method = (methodOop)_old_methods->obj_at(_matching_old_methods[j]);
  8469. + methodOop new_method = (methodOop)_new_methods->obj_at(_matching_new_methods[j]);
  8470. + methodOop old_array_method;
  8471. +
  8472. + // Maintain an old_index into the _old_methods array by skipping
  8473. + // deleted methods
  8474. + while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  8475. + != old_method) {
  8476. + ++old_index;
  8477. + }
  8478. +
  8479. + if (MethodComparator::methods_EMCP(old_method, new_method)) {
  8480. + // The EMCP definition from JSR-163 requires the bytecodes to be
  8481. + // the same with the exception of constant pool indices which may
  8482. + // differ. However, the constants referred to by those indices
  8483. + // must be the same.
  8484. + //
  8485. + // We use methods_EMCP() for comparison since constant pool
  8486. + // merging can remove duplicate constant pool entries that were
  8487. + // present in the old method and removed from the rewritten new
  8488. + // method. A faster binary comparison function would consider the
  8489. + // old and new methods to be different when they are actually
  8490. + // EMCP.
  8491. +
  8492. + // track which methods are EMCP for add_previous_version() call
  8493. + emcp_methods->set_bit(old_index);
  8494. + (*emcp_method_count_p)++;
  8495. +
  8496. + // An EMCP method is _not_ obsolete. An obsolete method has a
  8497. + // different jmethodID than the current method. An EMCP method
  8498. + // has the same jmethodID as the current method. Having the
  8499. + // same jmethodID for all EMCP versions of a method allows for
  8500. + // a consistent view of the EMCP methods regardless of which
  8501. + // EMCP method you happen to have in hand. For example, a
  8502. + // breakpoint set in one EMCP method will work for all EMCP
  8503. + // versions of the method including the current one.
  8504. +
  8505. + old_method->set_new_version(new_method);
  8506. + new_method->set_old_version(old_method);
  8507. +
  8508. + TRACE_RC3("Found EMCP method %s", old_method->name_and_sig_as_C_string());
  8509. +
  8510. + // Transfer breakpoints
  8511. + instanceKlass *ik = instanceKlass::cast(old_method->method_holder());
  8512. + for (BreakpointInfo* bp = ik->breakpoints(); bp != NULL; bp = bp->next()) {
  8513. + TRACE_RC2("Checking breakpoint");
  8514. + TRACE_RC2("%d / %d", bp->match(old_method), bp->match(new_method));
  8515. + if (bp->match(old_method)) {
  8516. + assert(bp->match(new_method), "if old method is method, then new method must match too");
  8517. + TRACE_RC2("Found a breakpoint in an old EMCP method");
  8518. + new_method->set_breakpoint(bp->bci());
  8519. + }
  8520. + }
  8521. +
  8522. +
  8523. +
  8524. + } else {
  8525. + // mark obsolete methods as such
  8526. + old_method->set_is_obsolete();
  8527. + obsolete_count++;
  8528. +
  8529. + // With tracing we try not to "yack" too much. The position of
  8530. + // this trace assumes there are fewer obsolete methods than
  8531. + // EMCP methods.
  8532. + TRACE_RC3("mark %s(%s) as obsolete",
  8533. + old_method->name()->as_C_string(),
  8534. + old_method->signature()->as_C_string());
  8535. + }
  8536. + old_method->set_is_old();
  8537. + }
  8538. + for (int i = 0; i < _deleted_methods_length; ++i) {
  8539. + methodOop old_method = (methodOop)_old_methods->obj_at(_deleted_methods[i]);
  8540. +
  8541. + //assert(old_method->vtable_index() < 0,
  8542. + // "cannot delete methods with vtable entries");;
  8543. +
  8544. + // Mark all deleted methods as old and obsolete
  8545. + old_method->set_is_old();
  8546. + old_method->set_is_obsolete();
  8547. + ++obsolete_count;
  8548. + // With tracing we try not to "yack" too much. The position of
  8549. + // this trace assumes there are fewer obsolete methods than
  8550. + // EMCP methods.
  8551. + TRACE_RC3("mark deleted %s(%s) as obsolete",
  8552. + old_method->name()->as_C_string(),
  8553. + old_method->signature()->as_C_string());
  8554. + }
  8555. + //assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(), "sanity check");
  8556. + TRACE_RC3("EMCP_cnt=%d, obsolete_cnt=%d !", *emcp_method_count_p, obsolete_count);
  8557. +}
  8558. +
  8559. +// Increment the classRedefinedCount field in the specific instanceKlass
  8560. +// and in all direct and indirect subclasses.
  8561. +void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  8562. + oop class_mirror = ik->java_mirror();
  8563. + klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  8564. + int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  8565. + java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  8566. + TRACE_RC3("updated count for class=%s to %d", ik->external_name(), new_count);
  8567. +}
  8568. +
  8569. +#ifndef PRODUCT
  8570. +void VM_RedefineClasses::check_class(klassOop k_oop, TRAPS) {
  8571. Klass *k = k_oop->klass_part();
  8572. if (k->oop_is_instance()) {
  8573. HandleMark hm(THREAD);
  8574. instanceKlass *ik = (instanceKlass *) k;
  8575. -
  8576. - // HotSpot specific optimization! HotSpot does not currently
  8577. - // support delegation from the bootstrap class loader to a
  8578. - // user-defined class loader. This means that if the bootstrap
  8579. - // class loader is the initiating class loader, then it will also
  8580. - // be the defining class loader. This also means that classes
  8581. - // loaded by the bootstrap class loader cannot refer to classes
  8582. - // loaded by a user-defined class loader. Note: a user-defined
  8583. - // class loader can delegate to the bootstrap class loader.
  8584. - //
  8585. - // If the current class being redefined has a user-defined class
  8586. - // loader as its defining class loader, then we can skip all
  8587. - // classes loaded by the bootstrap class loader.
  8588. - bool is_user_defined =
  8589. - instanceKlass::cast(_the_class_oop)->class_loader() != NULL;
  8590. - if (is_user_defined && ik->class_loader() == NULL) {
  8591. - return;
  8592. - }
  8593. -
  8594. - // This is a very busy routine. We don't want too much tracing
  8595. - // printed out.
  8596. - bool trace_name_printed = false;
  8597. -
  8598. - // Very noisy: only enable this call if you are trying to determine
  8599. - // that a specific class gets found by this routine.
  8600. - // RC_TRACE macro has an embedded ResourceMark
  8601. - // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  8602. - // ("adjust check: name=%s", ik->external_name()));
  8603. - // trace_name_printed = true;
  8604. -
  8605. - // Fix the vtable embedded in the_class and subclasses of the_class,
  8606. - // if one exists. We discard scratch_class and we don't keep an
  8607. - // instanceKlass around to hold obsolete methods so we don't have
  8608. - // any other instanceKlass embedded vtables to update. The vtable
  8609. - // holds the methodOops for virtual (but not final) methods.
  8610. - if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
  8611. - // ik->vtable() creates a wrapper object; rm cleans it up
  8612. + assert(ik->is_newest_version(), "must be latest version in system dictionary");
  8613. +
  8614. + if (ik->vtable_length() > 0) {
  8615. ResourceMark rm(THREAD);
  8616. - ik->vtable()->adjust_method_entries(_matching_old_methods,
  8617. - _matching_new_methods,
  8618. - _matching_methods_length,
  8619. - &trace_name_printed);
  8620. - }
  8621. -
  8622. - // If the current class has an itable and we are either redefining an
  8623. - // interface or if the current class is a subclass of the_class, then
  8624. - // we potentially have to fix the itable. If we are redefining an
  8625. - // interface, then we have to call adjust_method_entries() for
  8626. - // every instanceKlass that has an itable since there isn't a
  8627. - // subclass relationship between an interface and an instanceKlass.
  8628. - if (ik->itable_length() > 0 && (Klass::cast(_the_class_oop)->is_interface()
  8629. - || ik->is_subclass_of(_the_class_oop))) {
  8630. - // ik->itable() creates a wrapper object; rm cleans it up
  8631. - ResourceMark rm(THREAD);
  8632. - ik->itable()->adjust_method_entries(_matching_old_methods,
  8633. - _matching_new_methods,
  8634. - _matching_methods_length,
  8635. - &trace_name_printed);
  8636. - }
  8637. -
  8638. - // The constant pools in other classes (other_cp) can refer to
  8639. - // methods in the_class. We have to update method information in
  8640. - // other_cp's cache. If other_cp has a previous version, then we
  8641. - // have to repeat the process for each previous version. The
  8642. - // constant pool cache holds the methodOops for non-virtual
  8643. - // methods and for virtual, final methods.
  8644. - //
  8645. - // Special case: if the current class is the_class, then new_cp
  8646. - // has already been attached to the_class and old_cp has already
  8647. - // been added as a previous version. The new_cp doesn't have any
  8648. - // cached references to old methods so it doesn't need to be
  8649. - // updated. We can simply start with the previous version(s) in
  8650. - // that case.
  8651. - constantPoolHandle other_cp;
  8652. - constantPoolCacheOop cp_cache;
  8653. -
  8654. - if (k_oop != _the_class_oop) {
  8655. - // this klass' constant pool cache may need adjustment
  8656. - other_cp = constantPoolHandle(ik->constants());
  8657. - cp_cache = other_cp->cache();
  8658. - if (cp_cache != NULL) {
  8659. - cp_cache->adjust_method_entries(_matching_old_methods,
  8660. - _matching_new_methods,
  8661. - _matching_methods_length,
  8662. - &trace_name_printed);
  8663. + if (!ik->vtable()->check_no_old_entries()) {
  8664. + TRACE_RC1("size of class: %d\n", k_oop->size());
  8665. + TRACE_RC1("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  8666. + assert(false, "OLD method found");
  8667. }
  8668. - }
  8669. - {
  8670. - ResourceMark rm(THREAD);
  8671. - // PreviousVersionInfo objects returned via PreviousVersionWalker
  8672. - // contain a GrowableArray of handles. We have to clean up the
  8673. - // GrowableArray _after_ the PreviousVersionWalker destructor
  8674. - // has destroyed the handles.
  8675. - {
  8676. - // the previous versions' constant pool caches may need adjustment
  8677. - PreviousVersionWalker pvw(ik);
  8678. - for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
  8679. - pv_info != NULL; pv_info = pvw.next_previous_version()) {
  8680. - other_cp = pv_info->prev_constant_pool_handle();
  8681. - cp_cache = other_cp->cache();
  8682. - if (cp_cache != NULL) {
  8683. - cp_cache->adjust_method_entries(_matching_old_methods,
  8684. - _matching_new_methods,
  8685. - _matching_methods_length,
  8686. - &trace_name_printed);
  8687. - }
  8688. - }
  8689. - } // pvw is cleaned up
  8690. - } // rm is cleaned up
  8691. - }
  8692. -}
  8693. -
  8694. -void VM_RedefineClasses::update_jmethod_ids() {
  8695. - for (int j = 0; j < _matching_methods_length; ++j) {
  8696. - methodOop old_method = _matching_old_methods[j];
  8697. - jmethodID jmid = old_method->find_jmethod_id_or_null();
  8698. - if (jmid != NULL) {
  8699. - // There is a jmethodID, change it to point to the new method
  8700. - methodHandle new_method_h(_matching_new_methods[j]);
  8701. - JNIHandles::change_method_associated_with_jmethod_id(jmid, new_method_h);
  8702. - assert(JNIHandles::resolve_jmethod_id(jmid) == _matching_new_methods[j],
  8703. - "should be replaced");
  8704. +
  8705. + ik->vtable()->verify(tty, true);
  8706. }
  8707. }
  8708. }
  8709. -void VM_RedefineClasses::check_methods_and_mark_as_obsolete(
  8710. - BitMap *emcp_methods, int * emcp_method_count_p) {
  8711. - *emcp_method_count_p = 0;
  8712. - int obsolete_count = 0;
  8713. - int old_index = 0;
  8714. - for (int j = 0; j < _matching_methods_length; ++j, ++old_index) {
  8715. - methodOop old_method = _matching_old_methods[j];
  8716. - methodOop new_method = _matching_new_methods[j];
  8717. - methodOop old_array_method;
  8718. -
  8719. - // Maintain an old_index into the _old_methods array by skipping
  8720. - // deleted methods
  8721. - while ((old_array_method = (methodOop) _old_methods->obj_at(old_index))
  8722. - != old_method) {
  8723. - ++old_index;
  8724. +#endif
  8725. +
  8726. +VM_RedefineClasses::FindAffectedKlassesClosure::FindAffectedKlassesClosure( GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result )
  8727. +{
  8728. + assert(original_klasses != NULL && result != NULL, "");
  8729. + this->_original_klasses = original_klasses;
  8730. + this->_result = result;
  8731. + SystemDictionary::classes_do(this);
  8732. +}
  8733. +
  8734. +void VM_RedefineClasses::FindAffectedKlassesClosure::do_object( oop obj )
  8735. +{
  8736. + klassOop klass = (klassOop)obj;
  8737. + assert(!_result->contains(klass), "must not occur more than once!");
  8738. + assert(klass->klass_part()->new_version() == NULL, "Only last version is valid entry in system dictionary");
  8739. +
  8740. + for(int i=0; i<_original_klasses->length(); i++) {
  8741. + instanceKlassHandle cur = _original_klasses->at(i);
  8742. + if (cur() != klass && klass->klass_part()->is_subtype_of(cur()) && !_original_klasses->contains(klass)) {
  8743. + TRACE_RC3("Found affected class: %s", klass->klass_part()->name()->as_C_string());
  8744. + _result->append(klass);
  8745. + break;
  8746. }
  8747. -
  8748. - if (MethodComparator::methods_EMCP(old_method, new_method)) {
  8749. - // The EMCP definition from JSR-163 requires the bytecodes to be
  8750. - // the same with the exception of constant pool indices which may
  8751. - // differ. However, the constants referred to by those indices
  8752. - // must be the same.
  8753. - //
  8754. - // We use methods_EMCP() for comparison since constant pool
  8755. - // merging can remove duplicate constant pool entries that were
  8756. - // present in the old method and removed from the rewritten new
  8757. - // method. A faster binary comparison function would consider the
  8758. - // old and new methods to be different when they are actually
  8759. - // EMCP.
  8760. - //
  8761. - // The old and new methods are EMCP and you would think that we
  8762. - // could get rid of one of them here and now and save some space.
  8763. - // However, the concept of EMCP only considers the bytecodes and
  8764. - // the constant pool entries in the comparison. Other things,
  8765. - // e.g., the line number table (LNT) or the local variable table
  8766. - // (LVT) don't count in the comparison. So the new (and EMCP)
  8767. - // method can have a new LNT that we need so we can't just
  8768. - // overwrite the new method with the old method.
  8769. - //
  8770. - // When this routine is called, we have already attached the new
  8771. - // methods to the_class so the old methods are effectively
  8772. - // overwritten. However, if an old method is still executing,
  8773. - // then the old method cannot be collected until sometime after
  8774. - // the old method call has returned. So the overwriting of old
  8775. - // methods by new methods will save us space except for those
  8776. - // (hopefully few) old methods that are still executing.
  8777. - //
  8778. - // A method refers to a constMethodOop and this presents another
  8779. - // possible avenue to space savings. The constMethodOop in the
  8780. - // new method contains possibly new attributes (LNT, LVT, etc).
  8781. - // At first glance, it seems possible to save space by replacing
  8782. - // the constMethodOop in the old method with the constMethodOop
  8783. - // from the new method. The old and new methods would share the
  8784. - // same constMethodOop and we would save the space occupied by
  8785. - // the old constMethodOop. However, the constMethodOop contains
  8786. - // a back reference to the containing method. Sharing the
  8787. - // constMethodOop between two methods could lead to confusion in
  8788. - // the code that uses the back reference. This would lead to
  8789. - // brittle code that could be broken in non-obvious ways now or
  8790. - // in the future.
  8791. - //
  8792. - // Another possibility is to copy the constMethodOop from the new
  8793. - // method to the old method and then overwrite the new method with
  8794. - // the old method. Since the constMethodOop contains the bytecodes
  8795. - // for the method embedded in the oop, this option would change
  8796. - // the bytecodes out from under any threads executing the old
  8797. - // method and make the thread's bcp invalid. Since EMCP requires
  8798. - // that the bytecodes be the same modulo constant pool indices, it
  8799. - // is straight forward to compute the correct new bcp in the new
  8800. - // constMethodOop from the old bcp in the old constMethodOop. The
  8801. - // time consuming part would be searching all the frames in all
  8802. - // of the threads to find all of the calls to the old method.
  8803. - //
  8804. - // It looks like we will have to live with the limited savings
  8805. - // that we get from effectively overwriting the old methods
  8806. - // when the new methods are attached to the_class.
  8807. -
  8808. - // track which methods are EMCP for add_previous_version() call
  8809. - emcp_methods->set_bit(old_index);
  8810. - (*emcp_method_count_p)++;
  8811. -
  8812. - // An EMCP method is _not_ obsolete. An obsolete method has a
  8813. - // different jmethodID than the current method. An EMCP method
  8814. - // has the same jmethodID as the current method. Having the
  8815. - // same jmethodID for all EMCP versions of a method allows for
  8816. - // a consistent view of the EMCP methods regardless of which
  8817. - // EMCP method you happen to have in hand. For example, a
  8818. - // breakpoint set in one EMCP method will work for all EMCP
  8819. - // versions of the method including the current one.
  8820. - } else {
  8821. - // mark obsolete methods as such
  8822. - old_method->set_is_obsolete();
  8823. - obsolete_count++;
  8824. -
  8825. - // obsolete methods need a unique idnum
  8826. - u2 num = instanceKlass::cast(_the_class_oop)->next_method_idnum();
  8827. - if (num != constMethodOopDesc::UNSET_IDNUM) {
  8828. -// u2 old_num = old_method->method_idnum();
  8829. - old_method->set_method_idnum(num);
  8830. -// TO DO: attach obsolete annotations to obsolete method's new idnum
  8831. + }
  8832. +}
  8833. +
  8834. +jvmtiError VM_RedefineClasses::do_topological_class_sorting( const jvmtiClassDefinition *class_defs, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS)
  8835. +{
  8836. + GrowableArray< Pair<klassOop, klassOop> > *links = new GrowableArray< Pair<klassOop, klassOop> >();
  8837. +
  8838. + for (int i=0; i<class_count; i++) {
  8839. +
  8840. + oop mirror = JNIHandles::resolve_non_null(class_defs[i].klass);
  8841. + klassOop the_class_oop = java_lang_Class::as_klassOop(mirror);
  8842. + instanceKlassHandle the_class(THREAD, the_class_oop);
  8843. + Handle the_class_loader(THREAD, the_class->class_loader());
  8844. + Handle protection_domain(THREAD, the_class->protection_domain());
  8845. +
  8846. + ClassFileStream st((u1*) class_defs[i].class_bytes,
  8847. + class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__");
  8848. + ClassFileParser cfp(&st);
  8849. +
  8850. + GrowableArray<symbolHandle> symbolArr;
  8851. + TRACE_RC2("Before find super symbols of class %s", the_class->name()->as_C_string());
  8852. + cfp.findSuperSymbols(the_class->name(), the_class_loader, protection_domain, the_class, symbolArr, THREAD);
  8853. +
  8854. + for (int j=0; j<symbolArr.length(); j++) {
  8855. + symbolHandle sym = symbolArr.at(j);
  8856. +
  8857. + TRACE_RC3("Before adding link to super class %s", sym->as_C_string());
  8858. +
  8859. + for (int k=0; k<arr->length(); k++) {
  8860. + klassOop curOop = arr->at(k)();
  8861. + // (tw) TODO: Check if we get aliasing problems with different class loaders?
  8862. + if (curOop->klass_part()->name() == sym() /*&& curOop->klass_part()->class_loader() == the_class_loader()*/) {
  8863. + TRACE_RC2("Found class to link");
  8864. + links->append(Pair<klassOop, klassOop>(curOop, the_class()));
  8865. + break;
  8866. + }
  8867. }
  8868. - // With tracing we try not to "yack" too much. The position of
  8869. - // this trace assumes there are fewer obsolete methods than
  8870. - // EMCP methods.
  8871. - RC_TRACE(0x00000100, ("mark %s(%s) as obsolete",
  8872. - old_method->name()->as_C_string(),
  8873. - old_method->signature()->as_C_string()));
  8874. }
  8875. - old_method->set_is_old();
  8876. }
  8877. - for (int i = 0; i < _deleted_methods_length; ++i) {
  8878. - methodOop old_method = _deleted_methods[i];
  8879. -
  8880. - assert(old_method->vtable_index() < 0,
  8881. - "cannot delete methods with vtable entries");;
  8882. -
  8883. - // Mark all deleted methods as old and obsolete
  8884. - old_method->set_is_old();
  8885. - old_method->set_is_obsolete();
  8886. - ++obsolete_count;
  8887. - // With tracing we try not to "yack" too much. The position of
  8888. - // this trace assumes there are fewer obsolete methods than
  8889. - // EMCP methods.
  8890. - RC_TRACE(0x00000100, ("mark deleted %s(%s) as obsolete",
  8891. - old_method->name()->as_C_string(),
  8892. - old_method->signature()->as_C_string()));
  8893. +
  8894. +
  8895. + TRACE_RC1("Identified links between classes! ");
  8896. +
  8897. + for (int i=0; i<affected->length(); i++) {
  8898. +
  8899. + instanceKlassHandle klass = affected->at(i);
  8900. +
  8901. + klassOop superKlass = klass->super();
  8902. + if (affected->contains(superKlass)) {
  8903. + links->append(Pair<klassOop, klassOop>(superKlass, klass()));
  8904. + }
  8905. +
  8906. + objArrayOop superInterfaces = klass->local_interfaces();
  8907. + for (int j=0; j<superInterfaces->length(); j++) {
  8908. + klassOop interfaceKlass = (klassOop)superInterfaces->obj_at(j);
  8909. + if (arr->contains(interfaceKlass)) {
  8910. + links->append(Pair<klassOop, klassOop>(interfaceKlass, klass()));
  8911. + }
  8912. + }
  8913. }
  8914. - assert((*emcp_method_count_p + obsolete_count) == _old_methods->length(),
  8915. - "sanity check");
  8916. - RC_TRACE(0x00000100, ("EMCP_cnt=%d, obsolete_cnt=%d", *emcp_method_count_p,
  8917. - obsolete_count));
  8918. +
  8919. + IF_TRACE_RC2 {
  8920. + TRACE_RC2("Identified links: ");
  8921. + for (int i=0; i<links->length(); i++) {
  8922. + TRACE_RC2("%s to %s", links->at(i).left()->klass_part()->name()->as_C_string(),
  8923. + links->at(i).right()->klass_part()->name()->as_C_string());
  8924. + }
  8925. + }
  8926. +
  8927. + for (int i=0; i<arr->length(); i++) {
  8928. +
  8929. + int j;
  8930. + for (j=i; j<arr->length(); j++) {
  8931. +
  8932. + int k;
  8933. + for (k=0; k<links->length(); k++) {
  8934. +
  8935. + klassOop k1 = links->adr_at(k)->right();
  8936. + klassOop k2 = arr->at(j)();
  8937. + if (k1 == k2) {
  8938. + break;
  8939. + }
  8940. + }
  8941. +
  8942. + if (k == links->length()) {
  8943. + break;
  8944. + }
  8945. + }
  8946. +
  8947. + if (j == arr->length()) {
  8948. + // circle detected
  8949. + return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION;
  8950. + }
  8951. +
  8952. + for (int k=0; k<links->length(); k++) {
  8953. + if (links->adr_at(k)->left() == arr->at(j)()) {
  8954. + links->at_put(k, links->at(links->length() - 1));
  8955. + links->remove_at(links->length() - 1);
  8956. + k--;
  8957. + }
  8958. + }
  8959. +
  8960. + instanceKlassHandle tmp = arr->at(j);
  8961. + arr->at_put(j, arr->at(i));
  8962. + arr->at_put(i, tmp);
  8963. + }
  8964. +
  8965. + return JVMTI_ERROR_NONE;
  8966. }
  8967. +void VM_RedefineClasses::oops_do(OopClosure *closure) {
  8968. +
  8969. + if (_updated_oops != NULL) {
  8970. + for (int i=0; i<_updated_oops->length(); i++) {
  8971. + closure->do_oop(_updated_oops->adr_at(i));
  8972. + }
  8973. + }
  8974. +}
  8975. +
  8976. +void VM_RedefineClasses::transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to) {
  8977. + to->set_is_field_modification_watched(from->is_field_modification_watched());
  8978. + to->set_is_field_access_watched(from->is_field_access_watched());
  8979. + if (from->is_field_modification_watched() || from->is_field_access_watched()) {
  8980. + TRACE_RC2("Transfered watch for field %s", from->name()->as_C_string());
  8981. + }
  8982. + update_klass_field_access_flag(to);
  8983. +}
  8984. +
  8985. +void VM_RedefineClasses::update_klass_field_access_flag(fieldDescriptor *fd) {
  8986. + instanceKlass* ik = instanceKlass::cast(fd->field_holder());
  8987. + typeArrayOop fields = ik->fields();
  8988. + fields->ushort_at_put(fd->index(), (jushort)fd->access_flags().as_short());
  8989. +}
  8990. +
  8991. +
  8992. // This internal class transfers the native function registration from old methods
  8993. // to new methods. It is designed to handle both the simple case of unchanged
  8994. // native methods and the complex cases of native method prefixes being added and/or
  8995. @@ -2831,7 +2365,7 @@
  8996. // Same, caused by prefix removal only 3_2_1_m -> 3_2_m
  8997. //
  8998. class TransferNativeFunctionRegistration {
  8999. - private:
  9000. +private:
  9001. instanceKlassHandle the_class;
  9002. int prefix_count;
  9003. char** prefixes;
  9004. @@ -2844,42 +2378,42 @@
  9005. // (2) with the prefix.
  9006. // where 'prefix' is the prefix at that 'depth' (first prefix, second prefix,...)
  9007. methodOop search_prefix_name_space(int depth, char* name_str, size_t name_len,
  9008. - symbolOop signature) {
  9009. - symbolOop name_symbol = SymbolTable::probe(name_str, (int)name_len);
  9010. - if (name_symbol != NULL) {
  9011. - methodOop method = Klass::cast(the_class())->lookup_method(name_symbol, signature);
  9012. - if (method != NULL) {
  9013. - // Even if prefixed, intermediate methods must exist.
  9014. - if (method->is_native()) {
  9015. - // Wahoo, we found a (possibly prefixed) version of the method, return it.
  9016. - return method;
  9017. - }
  9018. - if (depth < prefix_count) {
  9019. - // Try applying further prefixes (other than this one).
  9020. - method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  9021. - if (method != NULL) {
  9022. - return method; // found
  9023. + symbolOop signature) {
  9024. + symbolOop name_symbol = SymbolTable::probe(name_str, (int)name_len);
  9025. + if (name_symbol != NULL) {
  9026. + methodOop method = Klass::cast(the_class()->klass_part()->new_version())->lookup_method(name_symbol, signature);
  9027. + if (method != NULL) {
  9028. + // Even if prefixed, intermediate methods must exist.
  9029. + if (method->is_native()) {
  9030. + // Wahoo, we found a (possibly prefixed) version of the method, return it.
  9031. + return method;
  9032. }
  9033. -
  9034. - // Try adding this prefix to the method name and see if it matches
  9035. - // another method name.
  9036. - char* prefix = prefixes[depth];
  9037. - size_t prefix_len = strlen(prefix);
  9038. - size_t trial_len = name_len + prefix_len;
  9039. - char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  9040. - strcpy(trial_name_str, prefix);
  9041. - strcat(trial_name_str, name_str);
  9042. - method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  9043. - signature);
  9044. - if (method != NULL) {
  9045. - // If found along this branch, it was prefixed, mark as such
  9046. - method->set_is_prefixed_native();
  9047. - return method; // found
  9048. + if (depth < prefix_count) {
  9049. + // Try applying further prefixes (other than this one).
  9050. + method = search_prefix_name_space(depth+1, name_str, name_len, signature);
  9051. + if (method != NULL) {
  9052. + return method; // found
  9053. + }
  9054. +
  9055. + // Try adding this prefix to the method name and see if it matches
  9056. + // another method name.
  9057. + char* prefix = prefixes[depth];
  9058. + size_t prefix_len = strlen(prefix);
  9059. + size_t trial_len = name_len + prefix_len;
  9060. + char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
  9061. + strcpy(trial_name_str, prefix);
  9062. + strcat(trial_name_str, name_str);
  9063. + method = search_prefix_name_space(depth+1, trial_name_str, trial_len,
  9064. + signature);
  9065. + if (method != NULL) {
  9066. + // If found along this branch, it was prefixed, mark as such
  9067. + method->set_is_prefixed_native();
  9068. + return method; // found
  9069. + }
  9070. }
  9071. }
  9072. }
  9073. - }
  9074. - return NULL; // This whole branch bore nothing
  9075. + return NULL; // This whole branch bore nothing
  9076. }
  9077. // Return the method name with old prefixes stripped away.
  9078. @@ -2904,10 +2438,10 @@
  9079. ResourceMark rm;
  9080. char* name_str = method_name_without_prefixes(method);
  9081. return search_prefix_name_space(0, name_str, strlen(name_str),
  9082. - method->signature());
  9083. + method->signature());
  9084. }
  9085. - public:
  9086. +public:
  9087. // Construct a native method transfer processor for this class.
  9088. TransferNativeFunctionRegistration(instanceKlassHandle _the_class) {
  9089. @@ -2918,9 +2452,9 @@
  9090. }
  9091. // Attempt to transfer any of the old or deleted methods that are native
  9092. - void transfer_registrations(methodOop* old_methods, int methods_length) {
  9093. + void transfer_registrations(instanceKlassHandle old_klass, int* old_methods, int methods_length) {
  9094. for (int j = 0; j < methods_length; j++) {
  9095. - methodOop old_method = old_methods[j];
  9096. + methodOop old_method = (methodOop)old_klass->methods()->obj_at(old_methods[j]);
  9097. if (old_method->is_native() && old_method->has_native_function()) {
  9098. methodOop new_method = strip_and_search_for_new_native(old_method);
  9099. @@ -2929,7 +2463,9 @@
  9100. // Redefine does not send events (except CFLH), certainly not this
  9101. // behind the scenes re-registration.
  9102. new_method->set_native_function(old_method->native_function(),
  9103. - !methodOopDesc::native_bind_event_is_interesting);
  9104. + !methodOopDesc::native_bind_event_is_interesting);
  9105. +
  9106. + TRACE_RC3("Transfering native function for method %s", old_method->name()->as_C_string());
  9107. }
  9108. }
  9109. }
  9110. @@ -2937,481 +2473,8 @@
  9111. };
  9112. // Don't lose the association between a native method and its JNI function.
  9113. -void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle the_class) {
  9114. - TransferNativeFunctionRegistration transfer(the_class);
  9115. - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length);
  9116. - transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
  9117. +void VM_RedefineClasses::transfer_old_native_function_registrations(instanceKlassHandle old_klass) {
  9118. + TransferNativeFunctionRegistration transfer(old_klass);
  9119. + transfer.transfer_registrations(old_klass, _deleted_methods, _deleted_methods_length);
  9120. + transfer.transfer_registrations(old_klass, _matching_old_methods, _matching_methods_length);
  9121. }
  9122. -
  9123. -// Deoptimize all compiled code that depends on this class.
  9124. -//
  9125. -// If the can_redefine_classes capability is obtained in the onload
  9126. -// phase then the compiler has recorded all dependencies from startup.
  9127. -// In that case we need only deoptimize and throw away all compiled code
  9128. -// that depends on the class.
  9129. -//
  9130. -// If can_redefine_classes is obtained sometime after the onload
  9131. -// phase then the dependency information may be incomplete. In that case
  9132. -// the first call to RedefineClasses causes all compiled code to be
  9133. -// thrown away. As can_redefine_classes has been obtained then
  9134. -// all future compilations will record dependencies so second and
  9135. -// subsequent calls to RedefineClasses need only throw away code
  9136. -// that depends on the class.
  9137. -//
  9138. -void VM_RedefineClasses::flush_dependent_code(instanceKlassHandle k_h, TRAPS) {
  9139. - assert_locked_or_safepoint(Compile_lock);
  9140. -
  9141. - // All dependencies have been recorded from startup or this is a second or
  9142. - // subsequent use of RedefineClasses
  9143. - if (JvmtiExport::all_dependencies_are_recorded()) {
  9144. - Universe::flush_evol_dependents_on(k_h);
  9145. - } else {
  9146. - CodeCache::mark_all_nmethods_for_deoptimization();
  9147. -
  9148. - ResourceMark rm(THREAD);
  9149. - DeoptimizationMarker dm;
  9150. -
  9151. - // Deoptimize all activations depending on marked nmethods
  9152. - Deoptimization::deoptimize_dependents();
  9153. -
  9154. - // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
  9155. - CodeCache::make_marked_nmethods_not_entrant();
  9156. -
  9157. - // From now on we know that the dependency information is complete
  9158. - JvmtiExport::set_all_dependencies_are_recorded(true);
  9159. - }
  9160. -}
  9161. -
  9162. -void VM_RedefineClasses::compute_added_deleted_matching_methods() {
  9163. - methodOop old_method;
  9164. - methodOop new_method;
  9165. -
  9166. - _matching_old_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9167. - _matching_new_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9168. - _added_methods = NEW_RESOURCE_ARRAY(methodOop, _new_methods->length());
  9169. - _deleted_methods = NEW_RESOURCE_ARRAY(methodOop, _old_methods->length());
  9170. -
  9171. - _matching_methods_length = 0;
  9172. - _deleted_methods_length = 0;
  9173. - _added_methods_length = 0;
  9174. -
  9175. - int nj = 0;
  9176. - int oj = 0;
  9177. - while (true) {
  9178. - if (oj >= _old_methods->length()) {
  9179. - if (nj >= _new_methods->length()) {
  9180. - break; // we've looked at everything, done
  9181. - }
  9182. - // New method at the end
  9183. - new_method = (methodOop) _new_methods->obj_at(nj);
  9184. - _added_methods[_added_methods_length++] = new_method;
  9185. - ++nj;
  9186. - } else if (nj >= _new_methods->length()) {
  9187. - // Old method, at the end, is deleted
  9188. - old_method = (methodOop) _old_methods->obj_at(oj);
  9189. - _deleted_methods[_deleted_methods_length++] = old_method;
  9190. - ++oj;
  9191. - } else {
  9192. - old_method = (methodOop) _old_methods->obj_at(oj);
  9193. - new_method = (methodOop) _new_methods->obj_at(nj);
  9194. - if (old_method->name() == new_method->name()) {
  9195. - if (old_method->signature() == new_method->signature()) {
  9196. - _matching_old_methods[_matching_methods_length ] = old_method;
  9197. - _matching_new_methods[_matching_methods_length++] = new_method;
  9198. - ++nj;
  9199. - ++oj;
  9200. - } else {
  9201. - // added overloaded have already been moved to the end,
  9202. - // so this is a deleted overloaded method
  9203. - _deleted_methods[_deleted_methods_length++] = old_method;
  9204. - ++oj;
  9205. - }
  9206. - } else { // names don't match
  9207. - if (old_method->name()->fast_compare(new_method->name()) > 0) {
  9208. - // new method
  9209. - _added_methods[_added_methods_length++] = new_method;
  9210. - ++nj;
  9211. - } else {
  9212. - // deleted method
  9213. - _deleted_methods[_deleted_methods_length++] = old_method;
  9214. - ++oj;
  9215. - }
  9216. - }
  9217. - }
  9218. - }
  9219. - assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity");
  9220. - assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity");
  9221. -}
  9222. -
  9223. -
  9224. -
  9225. -// Install the redefinition of a class:
  9226. -// - house keeping (flushing breakpoints and caches, deoptimizing
  9227. -// dependent compiled code)
  9228. -// - replacing parts in the_class with parts from scratch_class
  9229. -// - adding a weak reference to track the obsolete but interesting
  9230. -// parts of the_class
  9231. -// - adjusting constant pool caches and vtables in other classes
  9232. -// that refer to methods in the_class. These adjustments use the
  9233. -// SystemDictionary::classes_do() facility which only allows
  9234. -// a helper method to be specified. The interesting parameters
  9235. -// that we would like to pass to the helper method are saved in
  9236. -// static global fields in the VM operation.
  9237. -void VM_RedefineClasses::redefine_single_class(jclass the_jclass,
  9238. - instanceKlassHandle scratch_class, TRAPS) {
  9239. -
  9240. - RC_TIMER_START(_timer_rsc_phase1);
  9241. -
  9242. - oop the_class_mirror = JNIHandles::resolve_non_null(the_jclass);
  9243. - klassOop the_class_oop = java_lang_Class::as_klassOop(the_class_mirror);
  9244. - instanceKlassHandle the_class = instanceKlassHandle(THREAD, the_class_oop);
  9245. -
  9246. -#ifndef JVMTI_KERNEL
  9247. - // Remove all breakpoints in methods of this class
  9248. - JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
  9249. - jvmti_breakpoints.clearall_in_class_at_safepoint(the_class_oop);
  9250. -#endif // !JVMTI_KERNEL
  9251. -
  9252. - if (the_class_oop == Universe::reflect_invoke_cache()->klass()) {
  9253. - // We are redefining java.lang.reflect.Method. Method.invoke() is
  9254. - // cached and users of the cache care about each active version of
  9255. - // the method so we have to track this previous version.
  9256. - // Do this before methods get switched
  9257. - Universe::reflect_invoke_cache()->add_previous_version(
  9258. - the_class->method_with_idnum(Universe::reflect_invoke_cache()->method_idnum()));
  9259. - }
  9260. -
  9261. - // Deoptimize all compiled code that depends on this class
  9262. - flush_dependent_code(the_class, THREAD);
  9263. -
  9264. - _old_methods = the_class->methods();
  9265. - _new_methods = scratch_class->methods();
  9266. - _the_class_oop = the_class_oop;
  9267. - compute_added_deleted_matching_methods();
  9268. - update_jmethod_ids();
  9269. -
  9270. - // Attach new constant pool to the original klass. The original
  9271. - // klass still refers to the old constant pool (for now).
  9272. - scratch_class->constants()->set_pool_holder(the_class());
  9273. -
  9274. -#if 0
  9275. - // In theory, with constant pool merging in place we should be able
  9276. - // to save space by using the new, merged constant pool in place of
  9277. - // the old constant pool(s). By "pool(s)" I mean the constant pool in
  9278. - // the klass version we are replacing now and any constant pool(s) in
  9279. - // previous versions of klass. Nice theory, doesn't work in practice.
  9280. - // When this code is enabled, even simple programs throw NullPointer
  9281. - // exceptions. I'm guessing that this is caused by some constant pool
  9282. - // cache difference between the new, merged constant pool and the
  9283. - // constant pool that was just being used by the klass. I'm keeping
  9284. - // this code around to archive the idea, but the code has to remain
  9285. - // disabled for now.
  9286. -
  9287. - // Attach each old method to the new constant pool. This can be
  9288. - // done here since we are past the bytecode verification and
  9289. - // constant pool optimization phases.
  9290. - for (int i = _old_methods->length() - 1; i >= 0; i--) {
  9291. - methodOop method = (methodOop)_old_methods->obj_at(i);
  9292. - method->set_constants(scratch_class->constants());
  9293. - }
  9294. -
  9295. - {
  9296. - // walk all previous versions of the klass
  9297. - instanceKlass *ik = (instanceKlass *)the_class()->klass_part();
  9298. - PreviousVersionWalker pvw(ik);
  9299. - instanceKlassHandle ikh;
  9300. - do {
  9301. - ikh = pvw.next_previous_version();
  9302. - if (!ikh.is_null()) {
  9303. - ik = ikh();
  9304. -
  9305. - // attach previous version of klass to the new constant pool
  9306. - ik->set_constants(scratch_class->constants());
  9307. -
  9308. - // Attach each method in the previous version of klass to the
  9309. - // new constant pool
  9310. - objArrayOop prev_methods = ik->methods();
  9311. - for (int i = prev_methods->length() - 1; i >= 0; i--) {
  9312. - methodOop method = (methodOop)prev_methods->obj_at(i);
  9313. - method->set_constants(scratch_class->constants());
  9314. - }
  9315. - }
  9316. - } while (!ikh.is_null());
  9317. - }
  9318. -#endif
  9319. -
  9320. - // Replace methods and constantpool
  9321. - the_class->set_methods(_new_methods);
  9322. - scratch_class->set_methods(_old_methods); // To prevent potential GCing of the old methods,
  9323. - // and to be able to undo operation easily.
  9324. -
  9325. - constantPoolOop old_constants = the_class->constants();
  9326. - the_class->set_constants(scratch_class->constants());
  9327. - scratch_class->set_constants(old_constants); // See the previous comment.
  9328. -#if 0
  9329. - // We are swapping the guts of "the new class" with the guts of "the
  9330. - // class". Since the old constant pool has just been attached to "the
  9331. - // new class", it seems logical to set the pool holder in the old
  9332. - // constant pool also. However, doing this will change the observable
  9333. - // class hierarchy for any old methods that are still executing. A
  9334. - // method can query the identity of its "holder" and this query uses
  9335. - // the method's constant pool link to find the holder. The change in
  9336. - // holding class from "the class" to "the new class" can confuse
  9337. - // things.
  9338. - //
  9339. - // Setting the old constant pool's holder will also cause
  9340. - // verification done during vtable initialization below to fail.
  9341. - // During vtable initialization, the vtable's class is verified to be
  9342. - // a subtype of the method's holder. The vtable's class is "the
  9343. - // class" and the method's holder is gotten from the constant pool
  9344. - // link in the method itself. For "the class"'s directly implemented
  9345. - // methods, the method holder is "the class" itself (as gotten from
  9346. - // the new constant pool). The check works fine in this case. The
  9347. - // check also works fine for methods inherited from super classes.
  9348. - //
  9349. - // Miranda methods are a little more complicated. A miranda method is
  9350. - // provided by an interface when the class implementing the interface
  9351. - // does not provide its own method. These interfaces are implemented
  9352. - // internally as an instanceKlass. These special instanceKlasses
  9353. - // share the constant pool of the class that "implements" the
  9354. - // interface. By sharing the constant pool, the method holder of a
  9355. - // miranda method is the class that "implements" the interface. In a
  9356. - // non-redefine situation, the subtype check works fine. However, if
  9357. - // the old constant pool's pool holder is modified, then the check
  9358. - // fails because there is no class hierarchy relationship between the
  9359. - // vtable's class and "the new class".
  9360. -
  9361. - old_constants->set_pool_holder(scratch_class());
  9362. -#endif
  9363. -
  9364. - // track which methods are EMCP for add_previous_version() call below
  9365. - BitMap emcp_methods(_old_methods->length());
  9366. - int emcp_method_count = 0;
  9367. - emcp_methods.clear(); // clears 0..(length() - 1)
  9368. - check_methods_and_mark_as_obsolete(&emcp_methods, &emcp_method_count);
  9369. - transfer_old_native_function_registrations(the_class);
  9370. -
  9371. - // The class file bytes from before any retransformable agents mucked
  9372. - // with them was cached on the scratch class, move to the_class.
  9373. - // Note: we still want to do this if nothing needed caching since it
  9374. - // should get cleared in the_class too.
  9375. - the_class->set_cached_class_file(scratch_class->get_cached_class_file_bytes(),
  9376. - scratch_class->get_cached_class_file_len());
  9377. -
  9378. - // Replace inner_classes
  9379. - typeArrayOop old_inner_classes = the_class->inner_classes();
  9380. - the_class->set_inner_classes(scratch_class->inner_classes());
  9381. - scratch_class->set_inner_classes(old_inner_classes);
  9382. -
  9383. - // Initialize the vtable and interface table after
  9384. - // methods have been rewritten
  9385. - {
  9386. - ResourceMark rm(THREAD);
  9387. - // no exception should happen here since we explicitly
  9388. - // do not check loader constraints.
  9389. - // compare_and_normalize_class_versions has already checked:
  9390. - // - classloaders unchanged, signatures unchanged
  9391. - // - all instanceKlasses for redefined classes reused & contents updated
  9392. - the_class->vtable()->initialize_vtable(false, THREAD);
  9393. - the_class->itable()->initialize_itable(false, THREAD);
  9394. - assert(!HAS_PENDING_EXCEPTION || (THREAD->pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())), "redefine exception");
  9395. - }
  9396. -
  9397. - // Leave arrays of jmethodIDs and itable index cache unchanged
  9398. -
  9399. - // Copy the "source file name" attribute from new class version
  9400. - the_class->set_source_file_name(scratch_class->source_file_name());
  9401. -
  9402. - // Copy the "source debug extension" attribute from new class version
  9403. - the_class->set_source_debug_extension(
  9404. - scratch_class->source_debug_extension());
  9405. -
  9406. - // Use of javac -g could be different in the old and the new
  9407. - if (scratch_class->access_flags().has_localvariable_table() !=
  9408. - the_class->access_flags().has_localvariable_table()) {
  9409. -
  9410. - AccessFlags flags = the_class->access_flags();
  9411. - if (scratch_class->access_flags().has_localvariable_table()) {
  9412. - flags.set_has_localvariable_table();
  9413. - } else {
  9414. - flags.clear_has_localvariable_table();
  9415. - }
  9416. - the_class->set_access_flags(flags);
  9417. - }
  9418. -
  9419. - // Replace class annotation fields values
  9420. - typeArrayOop old_class_annotations = the_class->class_annotations();
  9421. - the_class->set_class_annotations(scratch_class->class_annotations());
  9422. - scratch_class->set_class_annotations(old_class_annotations);
  9423. -
  9424. - // Replace fields annotation fields values
  9425. - objArrayOop old_fields_annotations = the_class->fields_annotations();
  9426. - the_class->set_fields_annotations(scratch_class->fields_annotations());
  9427. - scratch_class->set_fields_annotations(old_fields_annotations);
  9428. -
  9429. - // Replace methods annotation fields values
  9430. - objArrayOop old_methods_annotations = the_class->methods_annotations();
  9431. - the_class->set_methods_annotations(scratch_class->methods_annotations());
  9432. - scratch_class->set_methods_annotations(old_methods_annotations);
  9433. -
  9434. - // Replace methods parameter annotation fields values
  9435. - objArrayOop old_methods_parameter_annotations =
  9436. - the_class->methods_parameter_annotations();
  9437. - the_class->set_methods_parameter_annotations(
  9438. - scratch_class->methods_parameter_annotations());
  9439. - scratch_class->set_methods_parameter_annotations(old_methods_parameter_annotations);
  9440. -
  9441. - // Replace methods default annotation fields values
  9442. - objArrayOop old_methods_default_annotations =
  9443. - the_class->methods_default_annotations();
  9444. - the_class->set_methods_default_annotations(
  9445. - scratch_class->methods_default_annotations());
  9446. - scratch_class->set_methods_default_annotations(old_methods_default_annotations);
  9447. -
  9448. - // Replace minor version number of class file
  9449. - u2 old_minor_version = the_class->minor_version();
  9450. - the_class->set_minor_version(scratch_class->minor_version());
  9451. - scratch_class->set_minor_version(old_minor_version);
  9452. -
  9453. - // Replace major version number of class file
  9454. - u2 old_major_version = the_class->major_version();
  9455. - the_class->set_major_version(scratch_class->major_version());
  9456. - scratch_class->set_major_version(old_major_version);
  9457. -
  9458. - // Replace CP indexes for class and name+type of enclosing method
  9459. - u2 old_class_idx = the_class->enclosing_method_class_index();
  9460. - u2 old_method_idx = the_class->enclosing_method_method_index();
  9461. - the_class->set_enclosing_method_indices(
  9462. - scratch_class->enclosing_method_class_index(),
  9463. - scratch_class->enclosing_method_method_index());
  9464. - scratch_class->set_enclosing_method_indices(old_class_idx, old_method_idx);
  9465. -
  9466. - // keep track of previous versions of this class
  9467. - the_class->add_previous_version(scratch_class, &emcp_methods,
  9468. - emcp_method_count);
  9469. -
  9470. - RC_TIMER_STOP(_timer_rsc_phase1);
  9471. - RC_TIMER_START(_timer_rsc_phase2);
  9472. -
  9473. - // Adjust constantpool caches and vtables for all classes
  9474. - // that reference methods of the evolved class.
  9475. - SystemDictionary::classes_do(adjust_cpool_cache_and_vtable, THREAD);
  9476. -
  9477. - if (the_class->oop_map_cache() != NULL) {
  9478. - // Flush references to any obsolete methods from the oop map cache
  9479. - // so that obsolete methods are not pinned.
  9480. - the_class->oop_map_cache()->flush_obsolete_entries();
  9481. - }
  9482. -
  9483. - // increment the classRedefinedCount field in the_class and in any
  9484. - // direct and indirect subclasses of the_class
  9485. - increment_class_counter((instanceKlass *)the_class()->klass_part(), THREAD);
  9486. -
  9487. - // RC_TRACE macro has an embedded ResourceMark
  9488. - RC_TRACE_WITH_THREAD(0x00000001, THREAD,
  9489. - ("redefined name=%s, count=%d (avail_mem=" UINT64_FORMAT "K)",
  9490. - the_class->external_name(),
  9491. - java_lang_Class::classRedefinedCount(the_class_mirror),
  9492. - os::available_memory() >> 10));
  9493. -
  9494. - RC_TIMER_STOP(_timer_rsc_phase2);
  9495. -} // end redefine_single_class()
  9496. -
  9497. -
  9498. -// Increment the classRedefinedCount field in the specific instanceKlass
  9499. -// and in all direct and indirect subclasses.
  9500. -void VM_RedefineClasses::increment_class_counter(instanceKlass *ik, TRAPS) {
  9501. - oop class_mirror = ik->java_mirror();
  9502. - klassOop class_oop = java_lang_Class::as_klassOop(class_mirror);
  9503. - int new_count = java_lang_Class::classRedefinedCount(class_mirror) + 1;
  9504. - java_lang_Class::set_classRedefinedCount(class_mirror, new_count);
  9505. -
  9506. - if (class_oop != _the_class_oop) {
  9507. - // _the_class_oop count is printed at end of redefine_single_class()
  9508. - RC_TRACE_WITH_THREAD(0x00000008, THREAD,
  9509. - ("updated count in subclass=%s to %d", ik->external_name(), new_count));
  9510. - }
  9511. -
  9512. - for (Klass *subk = ik->subklass(); subk != NULL;
  9513. - subk = subk->next_sibling()) {
  9514. - klassOop sub = subk->as_klassOop();
  9515. - instanceKlass *subik = (instanceKlass *)sub->klass_part();
  9516. -
  9517. - // recursively do subclasses of the current subclass
  9518. - increment_class_counter(subik, THREAD);
  9519. - }
  9520. -}
  9521. -
  9522. -#ifndef PRODUCT
  9523. -void VM_RedefineClasses::check_class(klassOop k_oop,
  9524. - oop initiating_loader, TRAPS) {
  9525. - Klass *k = k_oop->klass_part();
  9526. - if (k->oop_is_instance()) {
  9527. - HandleMark hm(THREAD);
  9528. - instanceKlass *ik = (instanceKlass *) k;
  9529. -
  9530. - if (ik->vtable_length() > 0) {
  9531. - ResourceMark rm(THREAD);
  9532. - if (!ik->vtable()->check_no_old_entries()) {
  9533. - tty->print_cr("klassVtable::check_no_old_entries failure -- OLD method found -- class: %s", ik->signature_name());
  9534. - ik->vtable()->dump_vtable();
  9535. - dump_methods();
  9536. - assert(false, "OLD method found");
  9537. - }
  9538. - }
  9539. - }
  9540. -}
  9541. -
  9542. -void VM_RedefineClasses::dump_methods() {
  9543. - int j;
  9544. - tty->print_cr("_old_methods --");
  9545. - for (j = 0; j < _old_methods->length(); ++j) {
  9546. - methodOop m = (methodOop) _old_methods->obj_at(j);
  9547. - tty->print("%4d (%5d) ", j, m->vtable_index());
  9548. - m->access_flags().print_on(tty);
  9549. - tty->print(" -- ");
  9550. - m->print_name(tty);
  9551. - tty->cr();
  9552. - }
  9553. - tty->print_cr("_new_methods --");
  9554. - for (j = 0; j < _new_methods->length(); ++j) {
  9555. - methodOop m = (methodOop) _new_methods->obj_at(j);
  9556. - tty->print("%4d (%5d) ", j, m->vtable_index());
  9557. - m->access_flags().print_on(tty);
  9558. - tty->print(" -- ");
  9559. - m->print_name(tty);
  9560. - tty->cr();
  9561. - }
  9562. - tty->print_cr("_matching_(old/new)_methods --");
  9563. - for (j = 0; j < _matching_methods_length; ++j) {
  9564. - methodOop m = _matching_old_methods[j];
  9565. - tty->print("%4d (%5d) ", j, m->vtable_index());
  9566. - m->access_flags().print_on(tty);
  9567. - tty->print(" -- ");
  9568. - m->print_name(tty);
  9569. - tty->cr();
  9570. - m = _matching_new_methods[j];
  9571. - tty->print(" (%5d) ", m->vtable_index());
  9572. - m->access_flags().print_on(tty);
  9573. - tty->cr();
  9574. - }
  9575. - tty->print_cr("_deleted_methods --");
  9576. - for (j = 0; j < _deleted_methods_length; ++j) {
  9577. - methodOop m = _deleted_methods[j];
  9578. - tty->print("%4d (%5d) ", j, m->vtable_index());
  9579. - m->access_flags().print_on(tty);
  9580. - tty->print(" -- ");
  9581. - m->print_name(tty);
  9582. - tty->cr();
  9583. - }
  9584. - tty->print_cr("_added_methods --");
  9585. - for (j = 0; j < _added_methods_length; ++j) {
  9586. - methodOop m = _added_methods[j];
  9587. - tty->print("%4d (%5d) ", j, m->vtable_index());
  9588. - m->access_flags().print_on(tty);
  9589. - tty->print(" -- ");
  9590. - m->print_name(tty);
  9591. - tty->cr();
  9592. - }
  9593. -}
  9594. -#endif
  9595. diff -r f5603a6e5042 src/share/vm/prims/jvmtiRedefineClasses.hpp
  9596. --- a/src/share/vm/prims/jvmtiRedefineClasses.hpp Wed Nov 17 22:42:08 2010 -0800
  9597. +++ b/src/share/vm/prims/jvmtiRedefineClasses.hpp Fri Dec 17 13:24:08 2010 +0100
  9598. @@ -1,351 +1,50 @@
  9599. /*
  9600. - * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
  9601. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  9602. - *
  9603. - * This code is free software; you can redistribute it and/or modify it
  9604. - * under the terms of the GNU General Public License version 2 only, as
  9605. - * published by the Free Software Foundation.
  9606. - *
  9607. - * This code is distributed in the hope that it will be useful, but WITHOUT
  9608. - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9609. - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  9610. - * version 2 for more details (a copy is included in the LICENSE file that
  9611. - * accompanied this code).
  9612. - *
  9613. - * You should have received a copy of the GNU General Public License version
  9614. - * 2 along with this work; if not, write to the Free Software Foundation,
  9615. - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  9616. - *
  9617. - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  9618. - * or visit www.oracle.com if you need additional information or have any
  9619. - * questions.
  9620. - *
  9621. - */
  9622. +* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  9623. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  9624. +*
  9625. +* This code is free software; you can redistribute it and/or modify it
  9626. +* under the terms of the GNU General Public License version 2 only, as
  9627. +* published by the Free Software Foundation.
  9628. +*
  9629. +* This code is distributed in the hope that it will be useful, but WITHOUT
  9630. +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9631. +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  9632. +* version 2 for more details (a copy is included in the LICENSE file that
  9633. +* accompanied this code).
  9634. +*
  9635. +* You should have received a copy of the GNU General Public License version
  9636. +* 2 along with this work; if not, write to the Free Software Foundation,
  9637. +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  9638. +*
  9639. +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  9640. +* or visit www.oracle.com if you need additional information or have any
  9641. +* questions.
  9642. +*
  9643. +*/
  9644. -// Introduction:
  9645. -//
  9646. -// The RedefineClasses() API is used to change the definition of one or
  9647. -// more classes. While the API supports redefining more than one class
  9648. -// in a single call, in general, the API is discussed in the context of
  9649. -// changing the definition of a single current class to a single new
  9650. -// class. For clarity, the current class is will always be called
  9651. -// "the_class" and the new class will always be called "scratch_class".
  9652. -//
  9653. -// The name "the_class" is used because there is only one structure
  9654. -// that represents a specific class; redefinition does not replace the
  9655. -// structure, but instead replaces parts of the structure. The name
  9656. -// "scratch_class" is used because the structure that represents the
  9657. -// new definition of a specific class is simply used to carry around
  9658. -// the parts of the new definition until they are used to replace the
  9659. -// appropriate parts in the_class. Once redefinition of a class is
  9660. -// complete, scratch_class is thrown away.
  9661. -//
  9662. -//
  9663. -// Implementation Overview:
  9664. -//
  9665. -// The RedefineClasses() API is mostly a wrapper around the VM op that
  9666. -// does the real work. The work is split in varying degrees between
  9667. -// doit_prologue(), doit() and doit_epilogue().
  9668. -//
  9669. -// 1) doit_prologue() is called by the JavaThread on the way to a
  9670. -// safepoint. It does parameter verification and loads scratch_class
  9671. -// which involves:
  9672. -// - parsing the incoming class definition using the_class' class
  9673. -// loader and security context
  9674. -// - linking scratch_class
  9675. -// - merging constant pools and rewriting bytecodes as needed
  9676. -// for the merged constant pool
  9677. -// - verifying the bytecodes in scratch_class
  9678. -// - setting up the constant pool cache and rewriting bytecodes
  9679. -// as needed to use the cache
  9680. -// - finally, scratch_class is compared to the_class to verify
  9681. -// that it is a valid replacement class
  9682. -// - if everything is good, then scratch_class is saved in an
  9683. -// instance field in the VM operation for the doit() call
  9684. -//
  9685. -// Note: A JavaThread must do the above work.
  9686. -//
  9687. -// 2) doit() is called by the VMThread during a safepoint. It installs
  9688. -// the new class definition(s) which involves:
  9689. -// - retrieving the scratch_class from the instance field in the
  9690. -// VM operation
  9691. -// - house keeping (flushing breakpoints and caches, deoptimizing
  9692. -// dependent compiled code)
  9693. -// - replacing parts in the_class with parts from scratch_class
  9694. -// - adding weak reference(s) to track the obsolete but interesting
  9695. -// parts of the_class
  9696. -// - adjusting constant pool caches and vtables in other classes
  9697. -// that refer to methods in the_class. These adjustments use the
  9698. -// SystemDictionary::classes_do() facility which only allows
  9699. -// a helper method to be specified. The interesting parameters
  9700. -// that we would like to pass to the helper method are saved in
  9701. -// static global fields in the VM operation.
  9702. -// - telling the SystemDictionary to notice our changes
  9703. -//
  9704. -// Note: the above work must be done by the VMThread to be safe.
  9705. -//
  9706. -// 3) doit_epilogue() is called by the JavaThread after the VM op
  9707. -// is finished and the safepoint is done. It simply cleans up
  9708. -// memory allocated in doit_prologue() and used in doit().
  9709. -//
  9710. -//
  9711. -// Constant Pool Details:
  9712. -//
  9713. -// When the_class is redefined, we cannot just replace the constant
  9714. -// pool in the_class with the constant pool from scratch_class because
  9715. -// that could confuse obsolete methods that may still be running.
  9716. -// Instead, the constant pool from the_class, old_cp, is merged with
  9717. -// the constant pool from scratch_class, scratch_cp. The resulting
  9718. -// constant pool, merge_cp, replaces old_cp in the_class.
  9719. -//
  9720. -// The key part of any merging algorithm is the entry comparison
  9721. -// function so we have to know the types of entries in a constant pool
  9722. -// in order to merge two of them together. Constant pools can contain
  9723. -// up to 12 different kinds of entries; the JVM_CONSTANT_Unicode entry
  9724. -// is not presently used so we only have to worry about the other 11
  9725. -// entry types. For the purposes of constant pool merging, it is
  9726. -// helpful to know that the 11 entry types fall into 3 different
  9727. -// subtypes: "direct", "indirect" and "double-indirect".
  9728. -//
  9729. -// Direct CP entries contain data and do not contain references to
  9730. -// other CP entries. The following are direct CP entries:
  9731. -// JVM_CONSTANT_{Double,Float,Integer,Long,Utf8}
  9732. -//
  9733. -// Indirect CP entries contain 1 or 2 references to a direct CP entry
  9734. -// and no other data. The following are indirect CP entries:
  9735. -// JVM_CONSTANT_{Class,NameAndType,String}
  9736. -//
  9737. -// Double-indirect CP entries contain two references to indirect CP
  9738. -// entries and no other data. The following are double-indirect CP
  9739. -// entries:
  9740. -// JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref}
  9741. -//
  9742. -// When comparing entries between two constant pools, the entry types
  9743. -// are compared first and if they match, then further comparisons are
  9744. -// made depending on the entry subtype. Comparing direct CP entries is
  9745. -// simply a matter of comparing the data associated with each entry.
  9746. -// Comparing both indirect and double-indirect CP entries requires
  9747. -// recursion.
  9748. -//
  9749. -// Fortunately, the recursive combinations are limited because indirect
  9750. -// CP entries can only refer to direct CP entries and double-indirect
  9751. -// CP entries can only refer to indirect CP entries. The following is
  9752. -// an example illustration of the deepest set of indirections needed to
  9753. -// access the data associated with a JVM_CONSTANT_Fieldref entry:
  9754. -//
  9755. -// JVM_CONSTANT_Fieldref {
  9756. -// class_index => JVM_CONSTANT_Class {
  9757. -// name_index => JVM_CONSTANT_Utf8 {
  9758. -// <data-1>
  9759. -// }
  9760. -// }
  9761. -// name_and_type_index => JVM_CONSTANT_NameAndType {
  9762. -// name_index => JVM_CONSTANT_Utf8 {
  9763. -// <data-2>
  9764. -// }
  9765. -// descriptor_index => JVM_CONSTANT_Utf8 {
  9766. -// <data-3>
  9767. -// }
  9768. -// }
  9769. -// }
  9770. -//
  9771. -// The above illustration is not a data structure definition for any
  9772. -// computer language. The curly braces ('{' and '}') are meant to
  9773. -// delimit the context of the "fields" in the CP entry types shown.
  9774. -// Each indirection from the JVM_CONSTANT_Fieldref entry is shown via
  9775. -// "=>", e.g., the class_index is used to indirectly reference a
  9776. -// JVM_CONSTANT_Class entry where the name_index is used to indirectly
  9777. -// reference a JVM_CONSTANT_Utf8 entry which contains the interesting
  9778. -// <data-1>. In order to understand a JVM_CONSTANT_Fieldref entry, we
  9779. -// have to do a total of 5 indirections just to get to the CP entries
  9780. -// that contain the interesting pieces of data and then we have to
  9781. -// fetch the three pieces of data. This means we have to do a total of
  9782. -// (5 + 3) * 2 == 16 dereferences to compare two JVM_CONSTANT_Fieldref
  9783. -// entries.
  9784. -//
  9785. -// Here is the indirection, data and dereference count for each entry
  9786. -// type:
  9787. -//
  9788. -// JVM_CONSTANT_Class 1 indir, 1 data, 2 derefs
  9789. -// JVM_CONSTANT_Double 0 indir, 1 data, 1 deref
  9790. -// JVM_CONSTANT_Fieldref 2 indir, 3 data, 8 derefs
  9791. -// JVM_CONSTANT_Float 0 indir, 1 data, 1 deref
  9792. -// JVM_CONSTANT_Integer 0 indir, 1 data, 1 deref
  9793. -// JVM_CONSTANT_InterfaceMethodref 2 indir, 3 data, 8 derefs
  9794. -// JVM_CONSTANT_Long 0 indir, 1 data, 1 deref
  9795. -// JVM_CONSTANT_Methodref 2 indir, 3 data, 8 derefs
  9796. -// JVM_CONSTANT_NameAndType 1 indir, 2 data, 4 derefs
  9797. -// JVM_CONSTANT_String 1 indir, 1 data, 2 derefs
  9798. -// JVM_CONSTANT_Utf8 0 indir, 1 data, 1 deref
  9799. -//
  9800. -// So different subtypes of CP entries require different amounts of
  9801. -// work for a proper comparison.
  9802. -//
  9803. -// Now that we've talked about the different entry types and how to
  9804. -// compare them we need to get back to merging. This is not a merge in
  9805. -// the "sort -u" sense or even in the "sort" sense. When we merge two
  9806. -// constant pools, we copy all the entries from old_cp to merge_cp,
  9807. -// preserving entry order. Next we append all the unique entries from
  9808. -// scratch_cp to merge_cp and we track the index changes from the
  9809. -// location in scratch_cp to the possibly new location in merge_cp.
  9810. -// When we are done, any obsolete code that is still running that
  9811. -// uses old_cp should not be able to observe any difference if it
  9812. -// were to use merge_cp. As for the new code in scratch_class, it is
  9813. -// modified to use the appropriate index values in merge_cp before it
  9814. -// is used to replace the code in the_class.
  9815. -//
  9816. -// There is one small complication in copying the entries from old_cp
  9817. -// to merge_cp. Two of the CP entry types are special in that they are
  9818. -// lazily resolved. Before explaining the copying complication, we need
  9819. -// to digress into CP entry resolution.
  9820. -//
  9821. -// JVM_CONSTANT_Class and JVM_CONSTANT_String entries are present in
  9822. -// the class file, but are not stored in memory as such until they are
  9823. -// resolved. The entries are not resolved unless they are used because
  9824. -// resolution is expensive. During class file parsing the entries are
  9825. -// initially stored in memory as JVM_CONSTANT_ClassIndex and
  9826. -// JVM_CONSTANT_StringIndex entries. These special CP entry types
  9827. -// indicate that the JVM_CONSTANT_Class and JVM_CONSTANT_String entries
  9828. -// have been parsed, but the index values in the entries have not been
  9829. -// validated. After the entire constant pool has been parsed, the index
  9830. -// values can be validated and then the entries are converted into
  9831. -// JVM_CONSTANT_UnresolvedClass and JVM_CONSTANT_UnresolvedString
  9832. -// entries. During this conversion process, the UTF8 values that are
  9833. -// indirectly referenced by the JVM_CONSTANT_ClassIndex and
  9834. -// JVM_CONSTANT_StringIndex entries are changed into symbolOops and the
  9835. -// entries are modified to refer to the symbolOops. This optimization
  9836. -// eliminates one level of indirection for those two CP entry types and
  9837. -// gets the entries ready for verification. During class file parsing
  9838. -// it is also possible for JVM_CONSTANT_UnresolvedString entries to be
  9839. -// resolved into JVM_CONSTANT_String entries. Verification expects to
  9840. -// find JVM_CONSTANT_UnresolvedClass and either JVM_CONSTANT_String or
  9841. -// JVM_CONSTANT_UnresolvedString entries and not JVM_CONSTANT_Class
  9842. -// entries.
  9843. -//
  9844. -// Now we can get back to the copying complication. When we copy
  9845. -// entries from old_cp to merge_cp, we have to revert any
  9846. -// JVM_CONSTANT_Class entries to JVM_CONSTANT_UnresolvedClass entries
  9847. -// or verification will fail.
  9848. -//
  9849. -// It is important to explicitly state that the merging algorithm
  9850. -// effectively unresolves JVM_CONSTANT_Class entries that were in the
  9851. -// old_cp when they are changed into JVM_CONSTANT_UnresolvedClass
  9852. -// entries in the merge_cp. This is done both to make verification
  9853. -// happy and to avoid adding more brittleness between RedefineClasses
  9854. -// and the constant pool cache. By allowing the constant pool cache
  9855. -// implementation to (re)resolve JVM_CONSTANT_UnresolvedClass entries
  9856. -// into JVM_CONSTANT_Class entries, we avoid having to embed knowledge
  9857. -// about those algorithms in RedefineClasses.
  9858. -//
  9859. -// Appending unique entries from scratch_cp to merge_cp is straight
  9860. -// forward for direct CP entries and most indirect CP entries. For the
  9861. -// indirect CP entry type JVM_CONSTANT_NameAndType and for the double-
  9862. -// indirect CP entry types, the presence of more than one piece of
  9863. -// interesting data makes appending the entries more complicated.
  9864. -//
  9865. -// For the JVM_CONSTANT_{Double,Float,Integer,Long,Utf8} entry types,
  9866. -// the entry is simply copied from scratch_cp to the end of merge_cp.
  9867. -// If the index in scratch_cp is different than the destination index
  9868. -// in merge_cp, then the change in index value is tracked.
  9869. -//
  9870. -// Note: the above discussion for the direct CP entries also applies
  9871. -// to the JVM_CONSTANT_Unresolved{Class,String} entry types.
  9872. -//
  9873. -// For the JVM_CONSTANT_{Class,String} entry types, since there is only
  9874. -// one data element at the end of the recursion, we know that we have
  9875. -// either one or two unique entries. If the JVM_CONSTANT_Utf8 entry is
  9876. -// unique then it is appended to merge_cp before the current entry.
  9877. -// If the JVM_CONSTANT_Utf8 entry is not unique, then the current entry
  9878. -// is updated to refer to the duplicate entry in merge_cp before it is
  9879. -// appended to merge_cp. Again, any changes in index values are tracked
  9880. -// as needed.
  9881. -//
  9882. -// Note: the above discussion for JVM_CONSTANT_{Class,String} entry
  9883. -// types is theoretical. Since those entry types have already been
  9884. -// optimized into JVM_CONSTANT_Unresolved{Class,String} entry types,
  9885. -// they are handled as direct CP entries.
  9886. -//
  9887. -// For the JVM_CONSTANT_NameAndType entry type, since there are two
  9888. -// data elements at the end of the recursions, we know that we have
  9889. -// between one and three unique entries. Any unique JVM_CONSTANT_Utf8
  9890. -// entries are appended to merge_cp before the current entry. For any
  9891. -// JVM_CONSTANT_Utf8 entries that are not unique, the current entry is
  9892. -// updated to refer to the duplicate entry in merge_cp before it is
  9893. -// appended to merge_cp. Again, any changes in index values are tracked
  9894. -// as needed.
  9895. -//
  9896. -// For the JVM_CONSTANT_{Fieldref,InterfaceMethodref,Methodref} entry
  9897. -// types, since there are two indirect CP entries and three data
  9898. -// elements at the end of the recursions, we know that we have between
  9899. -// one and six unique entries. See the JVM_CONSTANT_Fieldref diagram
  9900. -// above for an example of all six entries. The uniqueness algorithm
  9901. -// for the JVM_CONSTANT_Class and JVM_CONSTANT_NameAndType entries is
  9902. -// covered above. Any unique entries are appended to merge_cp before
  9903. -// the current entry. For any entries that are not unique, the current
  9904. -// entry is updated to refer to the duplicate entry in merge_cp before
  9905. -// it is appended to merge_cp. Again, any changes in index values are
  9906. -// tracked as needed.
  9907. -//
  9908. -//
  9909. -// Other Details:
  9910. -//
  9911. -// Details for other parts of RedefineClasses need to be written.
  9912. -// This is a placeholder section.
  9913. -//
  9914. -//
  9915. -// Open Issues (in no particular order):
  9916. -//
  9917. -// - How do we serialize the RedefineClasses() API without deadlocking?
  9918. -//
  9919. -// - SystemDictionary::parse_stream() was called with a NULL protection
  9920. -// domain since the initial version. This has been changed to pass
  9921. -// the_class->protection_domain(). This change has been tested with
  9922. -// all NSK tests and nothing broke, but what will adding it now break
  9923. -// in ways that we don't test?
  9924. -//
  9925. -// - GenerateOopMap::rewrite_load_or_store() has a comment in its
  9926. -// (indirect) use of the Relocator class that the max instruction
  9927. -// size is 4 bytes. goto_w and jsr_w are 5 bytes and wide/iinc is
  9928. -// 6 bytes. Perhaps Relocator only needs a 4 byte buffer to do
  9929. -// what it does to the bytecodes. More investigation is needed.
  9930. -//
  9931. -// - java.lang.Object methods can be called on arrays. This is
  9932. -// implemented via the arrayKlassOop vtable which we don't
  9933. -// update. For example, if we redefine java.lang.Object.toString(),
  9934. -// then the new version of the method will not be called for array
  9935. -// objects.
  9936. -//
  9937. -// - How do we know if redefine_single_class() and the guts of
  9938. -// instanceKlass are out of sync? I don't think this can be
  9939. -// automated, but we should probably order the work in
  9940. -// redefine_single_class() to match the order of field
  9941. -// definitions in instanceKlass. We also need to add some
  9942. -// comments about keeping things in sync.
  9943. -//
  9944. -// - set_new_constant_pool() is huge and we should consider refactoring
  9945. -// it into smaller chunks of work.
  9946. -//
  9947. -// - The exception table update code in set_new_constant_pool() defines
  9948. -// const values that are also defined in a local context elsewhere.
  9949. -// The same literal values are also used in elsewhere. We need to
  9950. -// coordinate a cleanup of these constants with Runtime.
  9951. -//
  9952. +// New version that allows arbitrary changes to already loaded classes.
  9953. +// Modifications done by: Thomas Wuerthinger <thomas.wuerthinger@gmail.com>
  9954. -class VM_RedefineClasses: public VM_Operation {
  9955. +#define RC_ABORT(error) { _result = error; return false; }
  9956. +
  9957. +class VM_RedefineClasses: public VM_GC_Operation {
  9958. private:
  9959. +
  9960. // These static fields are needed by SystemDictionary::classes_do()
  9961. // facility and the adjust_cpool_cache_and_vtable() helper:
  9962. static objArrayOop _old_methods;
  9963. static objArrayOop _new_methods;
  9964. - static methodOop* _matching_old_methods;
  9965. - static methodOop* _matching_new_methods;
  9966. - static methodOop* _deleted_methods;
  9967. - static methodOop* _added_methods;
  9968. + static int* _matching_old_methods;
  9969. + static int* _matching_new_methods;
  9970. + static int* _deleted_methods;
  9971. + static int* _added_methods;
  9972. static int _matching_methods_length;
  9973. static int _deleted_methods_length;
  9974. static int _added_methods_length;
  9975. static klassOop _the_class_oop;
  9976. + static int _revision_number;
  9977. +
  9978. // The instance fields are used to pass information from
  9979. // doit_prologue() to doit() and doit_epilogue().
  9980. jint _class_count;
  9981. @@ -359,36 +58,29 @@
  9982. // _index_map_p contains any entries.
  9983. int _index_map_count;
  9984. intArray * _index_map_p;
  9985. - // ptr to _class_count scratch_classes
  9986. - instanceKlassHandle * _scratch_classes;
  9987. - jvmtiError _res;
  9988. + GrowableArray<instanceKlassHandle>* _new_classes;
  9989. + GrowableArray<oop>* _updated_oops;
  9990. + jvmtiError _result;
  9991. + int _max_redefinition_flags;
  9992. // Performance measurement support. These timers do not cover all
  9993. // the work done for JVM/TI RedefineClasses() but they do cover
  9994. // the heavy lifting.
  9995. - elapsedTimer _timer_rsc_phase1;
  9996. - elapsedTimer _timer_rsc_phase2;
  9997. - elapsedTimer _timer_vm_op_prologue;
  9998. + elapsedTimer _timer_total;
  9999. + elapsedTimer _timer_prologue;
  10000. + elapsedTimer _timer_class_linking;
  10001. + elapsedTimer _timer_class_loading;
  10002. + elapsedTimer _timer_check_type;
  10003. + elapsedTimer _timer_prepare_redefinition;
  10004. + elapsedTimer _timer_wait_for_locks;
  10005. + elapsedTimer _timer_redefinition;
  10006. + elapsedTimer _timer_vm_op_epilogue;
  10007. - // These routines are roughly in call order unless otherwise noted.
  10008. -
  10009. - // Load the caller's new class definition(s) into _scratch_classes.
  10010. - // Constant pool merging work is done here as needed. Also calls
  10011. - // compare_and_normalize_class_versions() to verify the class
  10012. - // definition(s).
  10013. + jvmtiError check_redefinition_allowed(instanceKlassHandle new_class);
  10014. + jvmtiError find_sorted_affected_classes(GrowableArray<instanceKlassHandle> *all_affected_klasses);
  10015. + jvmtiError find_class_bytes(instanceKlassHandle the_class, const unsigned char **class_bytes, jint *class_byte_count, jboolean *not_changed);
  10016. jvmtiError load_new_class_versions(TRAPS);
  10017. - // Verify that the caller provided class definition(s) that meet
  10018. - // the restrictions of RedefineClasses. Normalize the order of
  10019. - // overloaded methods as needed.
  10020. - jvmtiError compare_and_normalize_class_versions(
  10021. - instanceKlassHandle the_class, instanceKlassHandle scratch_class);
  10022. -
  10023. - // Swap annotations[i] with annotations[j]
  10024. - // Used by compare_and_normalize_class_versions() when normalizing
  10025. - // overloaded methods or changing idnum as when adding or deleting methods.
  10026. - void swap_all_method_annotations(int i, int j, instanceKlassHandle scratch_class);
  10027. -
  10028. // Figure out which new methods match old methods in name and signature,
  10029. // which methods have been added, and which are no longer present
  10030. void compute_added_deleted_matching_methods();
  10031. @@ -396,94 +88,82 @@
  10032. // Change jmethodIDs to point to the new methods
  10033. void update_jmethod_ids();
  10034. - // In addition to marking methods as obsolete, this routine
  10035. - // records which methods are EMCP (Equivalent Module Constant
  10036. - // Pool) in the emcp_methods BitMap and returns the number of
  10037. - // EMCP methods via emcp_method_count_p. This information is
  10038. - // used when information about the previous version of the_class
  10039. - // is squirreled away.
  10040. - void check_methods_and_mark_as_obsolete(BitMap *emcp_methods,
  10041. - int * emcp_method_count_p);
  10042. - void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  10043. + class FindAffectedKlassesClosure : public ObjectClosure {
  10044. - // Unevolving classes may point to methods of the_class directly
  10045. - // from their constant pool caches, itables, and/or vtables. We
  10046. - // use the SystemDictionary::classes_do() facility and this helper
  10047. - // to fix up these pointers.
  10048. - static void adjust_cpool_cache_and_vtable(klassOop k_oop, oop loader, TRAPS);
  10049. + private:
  10050. + GrowableArray<instanceKlassHandle> *_original_klasses;
  10051. + GrowableArray<instanceKlassHandle> *_result;
  10052. +
  10053. + public:
  10054. + FindAffectedKlassesClosure(GrowableArray<instanceKlassHandle> *original_klasses, GrowableArray<instanceKlassHandle> *result);
  10055. +
  10056. + virtual void do_object(oop obj);
  10057. + };
  10058. +
  10059. +
  10060. + static jvmtiError do_topological_class_sorting(const jvmtiClassDefinition *class_definitions, int class_count, GrowableArray<instanceKlassHandle> *affected, GrowableArray<instanceKlassHandle> *arr, TRAPS);
  10061. // Install the redefinition of a class
  10062. - void redefine_single_class(jclass the_jclass,
  10063. - instanceKlassHandle scratch_class, TRAPS);
  10064. + void redefine_single_class(instanceKlassHandle the_new_class, TRAPS);
  10065. // Increment the classRedefinedCount field in the specific instanceKlass
  10066. // and in all direct and indirect subclasses.
  10067. void increment_class_counter(instanceKlass *ik, TRAPS);
  10068. - // Support for constant pool merging (these routines are in alpha
  10069. - // order):
  10070. - void append_entry(constantPoolHandle scratch_cp, int scratch_i,
  10071. - constantPoolHandle *merge_cp_p, int *merge_cp_length_p, TRAPS);
  10072. - int find_new_index(int old_index);
  10073. - bool is_unresolved_class_mismatch(constantPoolHandle cp1, int index1,
  10074. - constantPoolHandle cp2, int index2);
  10075. - bool is_unresolved_string_mismatch(constantPoolHandle cp1, int index1,
  10076. - constantPoolHandle cp2, int index2);
  10077. - void map_index(constantPoolHandle scratch_cp, int old_index, int new_index);
  10078. - bool merge_constant_pools(constantPoolHandle old_cp,
  10079. - constantPoolHandle scratch_cp, constantPoolHandle *merge_cp_p,
  10080. - int *merge_cp_length_p, TRAPS);
  10081. - jvmtiError merge_cp_and_rewrite(instanceKlassHandle the_class,
  10082. - instanceKlassHandle scratch_class, TRAPS);
  10083. - u2 rewrite_cp_ref_in_annotation_data(
  10084. - typeArrayHandle annotations_typeArray, int &byte_i_ref,
  10085. - const char * trace_mesg, TRAPS);
  10086. - bool rewrite_cp_refs(instanceKlassHandle scratch_class, TRAPS);
  10087. - bool rewrite_cp_refs_in_annotation_struct(
  10088. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  10089. - bool rewrite_cp_refs_in_annotations_typeArray(
  10090. - typeArrayHandle annotations_typeArray, int &byte_i_ref, TRAPS);
  10091. - bool rewrite_cp_refs_in_class_annotations(
  10092. - instanceKlassHandle scratch_class, TRAPS);
  10093. - bool rewrite_cp_refs_in_element_value(
  10094. - typeArrayHandle class_annotations, int &byte_i_ref, TRAPS);
  10095. - bool rewrite_cp_refs_in_fields_annotations(
  10096. - instanceKlassHandle scratch_class, TRAPS);
  10097. - void rewrite_cp_refs_in_method(methodHandle method,
  10098. - methodHandle * new_method_p, TRAPS);
  10099. - bool rewrite_cp_refs_in_methods(instanceKlassHandle scratch_class, TRAPS);
  10100. - bool rewrite_cp_refs_in_methods_annotations(
  10101. - instanceKlassHandle scratch_class, TRAPS);
  10102. - bool rewrite_cp_refs_in_methods_default_annotations(
  10103. - instanceKlassHandle scratch_class, TRAPS);
  10104. - bool rewrite_cp_refs_in_methods_parameter_annotations(
  10105. - instanceKlassHandle scratch_class, TRAPS);
  10106. - void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
  10107. - void rewrite_cp_refs_in_verification_type_info(
  10108. - address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
  10109. - u1 frame_size, TRAPS);
  10110. - void set_new_constant_pool(instanceKlassHandle scratch_class,
  10111. - constantPoolHandle scratch_cp, int scratch_cp_length, bool shrink, TRAPS);
  10112. void flush_dependent_code(instanceKlassHandle k_h, TRAPS);
  10113. - static void check_class(klassOop k_oop, oop initiating_loader, TRAPS) PRODUCT_RETURN;
  10114. + static void check_class(klassOop k_oop,/* oop initiating_loader,*/ TRAPS) PRODUCT_RETURN;
  10115. - static void dump_methods() PRODUCT_RETURN;
  10116. + static void adjust_cpool_cache(klassOop k_oop, oop initiating_loader, TRAPS);
  10117. +
  10118. +#ifdef ASSERT
  10119. + static void verify_classes(klassOop k_oop, oop initiating_loader, TRAPS);
  10120. +#endif
  10121. +
  10122. + int calculate_redefinition_flags(instanceKlassHandle new_version);
  10123. + void calculate_instance_update_information(klassOop new_version);
  10124. + void check_methods_and_mark_as_obsolete(BitMap *emcp_methods, int * emcp_method_count_p);
  10125. public:
  10126. - VM_RedefineClasses(jint class_count,
  10127. - const jvmtiClassDefinition *class_defs,
  10128. - JvmtiClassLoadKind class_load_kind);
  10129. - VMOp_Type type() const { return VMOp_RedefineClasses; }
  10130. + VM_RedefineClasses(jint class_count, const jvmtiClassDefinition *class_defs, JvmtiClassLoadKind class_load_kind);
  10131. + virtual ~VM_RedefineClasses();
  10132. +
  10133. + bool check_arguments();
  10134. bool doit_prologue();
  10135. void doit();
  10136. void doit_epilogue();
  10137. + void rollback();
  10138. - bool allow_nested_vm_operations() const { return true; }
  10139. - jvmtiError check_error() { return _res; }
  10140. + jvmtiError check_exception() const;
  10141. + VMOp_Type type() const { return VMOp_RedefineClasses; }
  10142. + bool skip_operation() const { return false; }
  10143. + bool allow_nested_vm_operations() const { return true; }
  10144. + jvmtiError check_error() { return _result; }
  10145. +
  10146. + void update_active_methods();
  10147. +
  10148. + void update_array_classes_to_newest_version(klassOop smallest_dimension);
  10149. // Modifiable test must be shared between IsModifiableClass query
  10150. // and redefine implementation
  10151. static bool is_modifiable_class(oop klass_mirror);
  10152. -};
  10153. +
  10154. + // Method used during garbage collection, the VM operation must iterate over all oops.
  10155. + void oops_do(OopClosure* f);
  10156. +
  10157. + // Utility methods for transfering field access flags
  10158. +
  10159. + static void transfer_special_access_flags(fieldDescriptor *from, fieldDescriptor *to);
  10160. + static void update_klass_field_access_flag(fieldDescriptor *fd);
  10161. +
  10162. + void transfer_old_native_function_registrations(instanceKlassHandle the_class);
  10163. +
  10164. + void lock_threads();
  10165. + void unlock_threads();
  10166. +
  10167. + template <class T> static void do_oop_work(T* p);
  10168. +
  10169. + static void swap_marks(oop first, oop second);
  10170. +
  10171. +};
  10172. \ No newline at end of file
  10173. diff -r f5603a6e5042 src/share/vm/prims/jvmtiRedefineClassesTrace.hpp
  10174. --- a/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp Wed Nov 17 22:42:08 2010 -0800
  10175. +++ b/src/share/vm/prims/jvmtiRedefineClassesTrace.hpp Fri Dec 17 13:24:08 2010 +0100
  10176. @@ -22,102 +22,26 @@
  10177. *
  10178. */
  10179. -// RedefineClasses tracing support via the TraceRedefineClasses
  10180. -// option. A bit is assigned to each group of trace messages.
  10181. -// Groups of messages are individually selectable. We have to use
  10182. -// decimal values on the command line since the command option
  10183. -// parsing logic doesn't like non-decimal numerics. The HEX values
  10184. -// are used in the actual RC_TRACE() calls for sanity. To achieve
  10185. -// the old cumulative behavior, pick the level after the one in
  10186. -// which you are interested and subtract one, e.g., 33554431 will
  10187. -// print every tracing message.
  10188. -//
  10189. -// 0x00000000 | 0 - default; no tracing messages
  10190. -// 0x00000001 | 1 - name each target class before loading, after
  10191. -// loading and after redefinition is completed
  10192. -// 0x00000002 | 2 - print info if parsing, linking or
  10193. -// verification throws an exception
  10194. -// 0x00000004 | 4 - print timer info for the VM operation
  10195. -// 0x00000008 | 8 - print subclass counter updates
  10196. -// 0x00000010 | 16 - unused
  10197. -// 0x00000020 | 32 - unused
  10198. -// 0x00000040 | 64 - unused
  10199. -// 0x00000080 | 128 - unused
  10200. -// 0x00000100 | 256 - previous class weak reference addition
  10201. -// 0x00000200 | 512 - previous class weak reference mgmt during
  10202. -// class unloading checks (GC)
  10203. -// 0x00000400 | 1024 - previous class weak reference mgmt during
  10204. -// add previous ops (GC)
  10205. -// 0x00000800 | 2048 - previous class breakpoint mgmt
  10206. -// 0x00001000 | 4096 - detect calls to obsolete methods
  10207. -// 0x00002000 | 8192 - fail a guarantee() in addition to detection
  10208. -// 0x00004000 | 16384 - unused
  10209. -// 0x00008000 | 32768 - old/new method matching/add/delete
  10210. -// 0x00010000 | 65536 - impl details: CP size info
  10211. -// 0x00020000 | 131072 - impl details: CP merge pass info
  10212. -// 0x00040000 | 262144 - impl details: CP index maps
  10213. -// 0x00080000 | 524288 - impl details: modified CP index values
  10214. -// 0x00100000 | 1048576 - impl details: vtable updates
  10215. -// 0x00200000 | 2097152 - impl details: itable updates
  10216. -// 0x00400000 | 4194304 - impl details: constant pool cache updates
  10217. -// 0x00800000 | 8388608 - impl details: methodComparator info
  10218. -// 0x01000000 | 16777216 - impl details: nmethod evolution info
  10219. -// 0x02000000 | 33554432 - impl details: annotation updates
  10220. -// 0x04000000 | 67108864 - impl details: StackMapTable updates
  10221. -// 0x08000000 | 134217728 - impl details: OopMapCache updates
  10222. -// 0x10000000 | 268435456 - unused
  10223. -// 0x20000000 | 536870912 - unused
  10224. -// 0x40000000 | 1073741824 - unused
  10225. -// 0x80000000 | 2147483648 - unused
  10226. -//
  10227. -// Note: The ResourceMark is to cleanup resource allocated args.
  10228. -// The "while (0)" is so we can use semi-colon at end of RC_TRACE().
  10229. -#define RC_TRACE(level, args) \
  10230. - if ((TraceRedefineClasses & level) != 0) { \
  10231. - ResourceMark rm; \
  10232. - tty->print("RedefineClasses-0x%x: ", level); \
  10233. - tty->print_cr args; \
  10234. - } while (0)
  10235. +#define IF_TRACE_RC1 if (TraceRedefineClasses >= 1)
  10236. +#define IF_TRACE_RC2 if (TraceRedefineClasses >= 2)
  10237. +#define IF_TRACE_RC3 if (TraceRedefineClasses >= 3)
  10238. +#define IF_TRACE_RC4 if (TraceRedefineClasses >= 4)
  10239. +#define IF_TRACE_RC5 if (TraceRedefineClasses >= 5)
  10240. -#define RC_TRACE_WITH_THREAD(level, thread, args) \
  10241. - if ((TraceRedefineClasses & level) != 0) { \
  10242. - ResourceMark rm(thread); \
  10243. - tty->print("RedefineClasses-0x%x: ", level); \
  10244. - tty->print_cr args; \
  10245. - } while (0)
  10246. -
  10247. -#define RC_TRACE_MESG(args) \
  10248. - { \
  10249. - ResourceMark rm; \
  10250. - tty->print("RedefineClasses: "); \
  10251. - tty->print_cr args; \
  10252. - } while (0)
  10253. -
  10254. -// Macro for checking if TraceRedefineClasses has a specific bit
  10255. -// enabled. Returns true if the bit specified by level is set.
  10256. -#define RC_TRACE_ENABLED(level) ((TraceRedefineClasses & level) != 0)
  10257. -
  10258. -// Macro for checking if TraceRedefineClasses has one or more bits
  10259. -// set in a range of bit values. Returns true if one or more bits
  10260. -// is set in the range from low..high inclusive. Assumes that low
  10261. -// and high are single bit values.
  10262. -//
  10263. -// ((high << 1) - 1)
  10264. -// Yields a mask that removes bits greater than the high bit value.
  10265. -// This algorithm doesn't work with highest bit.
  10266. -// ~(low - 1)
  10267. -// Yields a mask that removes bits lower than the low bit value.
  10268. -#define RC_TRACE_IN_RANGE(low, high) \
  10269. -(((TraceRedefineClasses & ((high << 1) - 1)) & ~(low - 1)) != 0)
  10270. +#define TRACE_RC1 if (TraceRedefineClasses >= 1) tty->print("TraceRedefineClasses-1: "); if (TraceRedefineClasses >= 1) tty->print_cr
  10271. +#define TRACE_RC2 if (TraceRedefineClasses >= 2) tty->print(" TraceRedefineClasses-2: "); if (TraceRedefineClasses >= 2) tty->print_cr
  10272. +#define TRACE_RC3 if (TraceRedefineClasses >= 3) tty->print(" TraceRedefineClasses-3: "); if (TraceRedefineClasses >= 3) tty->print_cr
  10273. +#define TRACE_RC4 if (TraceRedefineClasses >= 4) tty->print(" TraceRedefineClasses-4: "); if (TraceRedefineClasses >= 4) tty->print_cr
  10274. +#define TRACE_RC5 if (TraceRedefineClasses >= 5) tty->print(" TraceRedefineClasses-5: "); if (TraceRedefineClasses >= 5) tty->print_cr
  10275. // Timer support macros. Only do timer operations if timer tracing
  10276. // is enabled. The "while (0)" is so we can use semi-colon at end of
  10277. // the macro.
  10278. #define RC_TIMER_START(t) \
  10279. - if (RC_TRACE_ENABLED(0x00000004)) { \
  10280. + if (TimeRedefineClasses) { \
  10281. t.start(); \
  10282. } while (0)
  10283. #define RC_TIMER_STOP(t) \
  10284. - if (RC_TRACE_ENABLED(0x00000004)) { \
  10285. + if (TimeRedefineClasses) { \
  10286. t.stop(); \
  10287. } while (0)
  10288. diff -r f5603a6e5042 src/share/vm/prims/methodComparator.cpp
  10289. --- a/src/share/vm/prims/methodComparator.cpp Wed Nov 17 22:42:08 2010 -0800
  10290. +++ b/src/share/vm/prims/methodComparator.cpp Fri Dec 17 13:24:08 2010 +0100
  10291. @@ -37,10 +37,9 @@
  10292. if (old_method->code_size() != new_method->code_size())
  10293. return false;
  10294. if (check_stack_and_locals_size(old_method, new_method) != 0) {
  10295. - // RC_TRACE macro has an embedded ResourceMark
  10296. - RC_TRACE(0x00800000, ("Methods %s non-comparable with diagnosis %d",
  10297. + TRACE_RC4("Methods %s non-comparable with diagnosis %d",
  10298. old_method->name()->as_C_string(),
  10299. - check_stack_and_locals_size(old_method, new_method)));
  10300. + check_stack_and_locals_size(old_method, new_method));
  10301. return false;
  10302. }
  10303. @@ -60,6 +59,37 @@
  10304. if (! args_same(c_old, c_new))
  10305. return false;
  10306. }
  10307. +
  10308. + // (tw) Added exception table comparison to EMCP comparison
  10309. +
  10310. + typeArrayOop ex_old = old_method->constMethod()->exception_table();
  10311. + typeArrayOop ex_new = new_method->constMethod()->exception_table();
  10312. +
  10313. + if (ex_old == NULL && ex_new != NULL) return false;
  10314. + if (ex_old != NULL && ex_new == NULL) return false;
  10315. +
  10316. + if (ex_old != NULL && ex_new != NULL && ex_old->length() == ex_new->length()) {
  10317. + // Per entry:
  10318. + /* start */
  10319. + /* limit */
  10320. + /* goto pc */
  10321. + /* cp index */
  10322. + for (int i=0; i<ex_old->length(); i++) {
  10323. + int old_val = ex_old->int_at(i);
  10324. + int new_val = ex_new->int_at(i);
  10325. + if ((i + 1) % 4 == 0) {
  10326. + if (old_val == 0 || new_val == 0) {
  10327. + if (old_val != new_val) return false;
  10328. + } else if ((_old_cp->klass_at_noresolve(old_val) != _new_cp->klass_at_noresolve(new_val)))
  10329. + return false;
  10330. + } else {
  10331. + if (old_val != new_val) {
  10332. + return false;
  10333. + }
  10334. + }
  10335. + }
  10336. + }
  10337. +
  10338. return true;
  10339. }
  10340. @@ -109,10 +139,9 @@
  10341. // Now we can test all forward jumps
  10342. for (int i = 0; i < fwd_jmps.length() / 2; i++) {
  10343. if (! bci_map.old_and_new_locations_same(fwd_jmps.at(i*2), fwd_jmps.at(i*2+1))) {
  10344. - RC_TRACE(0x00800000,
  10345. - ("Fwd jump miss: old dest = %d, calc new dest = %d, act new dest = %d",
  10346. + TRACE_RC4("Fwd jump miss: old dest = %d, calc new dest = %d, act new dest = %d",
  10347. fwd_jmps.at(i*2), bci_map.new_bci_for_old(fwd_jmps.at(i*2)),
  10348. - fwd_jmps.at(i*2+1)));
  10349. + fwd_jmps.at(i*2+1));
  10350. return false;
  10351. }
  10352. }
  10353. diff -r f5603a6e5042 src/share/vm/prims/nativeLookup.cpp
  10354. --- a/src/share/vm/prims/nativeLookup.cpp Wed Nov 17 22:42:08 2010 -0800
  10355. +++ b/src/share/vm/prims/nativeLookup.cpp Fri Dec 17 13:24:08 2010 +0100
  10356. @@ -1,4 +1,4 @@
  10357. -/*
  10358. +*
  10359. * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
  10360. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10361. *
  10362. @@ -24,7 +24,7 @@
  10363. # include "incls/_precompiled.incl"
  10364. # include "incls/_nativeLookup.cpp.incl"
  10365. -
  10366. +# include "incls/_jvmtiEnv.cpp.incl"
  10367. static void mangle_name_on(outputStream* st, symbolOop name, int begin, int end) {
  10368. char* bytes = (char*)name->bytes() + begin;
  10369. @@ -82,6 +82,39 @@
  10370. void JNICALL JVM_RegisterPerfMethods(JNIEnv *env, jclass perfclass);
  10371. }
  10372. +// Helper function to call redefineClasses from Java Code
  10373. +JVM_ENTRY(int, JVM_RedefineClassesHelper(JNIEnv *env, jclass cb, jclass target, jbyteArray bytes))
  10374. + ResourceMark rm(THREAD);
  10375. +
  10376. + JavaThread* current_thread = JavaThread::current();
  10377. + jbyte* bytecodes = NULL;
  10378. + const int class_count = 1;
  10379. + jvmtiClassDefinition* class_definitions = NEW_RESOURCE_ARRAY(jvmtiClassDefinition, class_count);
  10380. +
  10381. + {
  10382. + ThreadToNativeFromVM ttnfv(thread);
  10383. + bytecodes = env->GetByteArrayElements(bytes, false);
  10384. + class_definitions[0].klass = target;
  10385. + class_definitions[0].class_byte_count = env->GetArrayLength(bytes);
  10386. + class_definitions[0].class_bytes = (unsigned char*)bytecodes;
  10387. + }
  10388. +
  10389. + VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
  10390. + VMThread::execute(&op);
  10391. + int result = op.check_error();
  10392. +
  10393. + {
  10394. + ThreadToNativeFromVM ttnfv(thread);
  10395. + if (env->ExceptionOccurred()) {
  10396. + return -1;
  10397. + }
  10398. + env->ReleaseByteArrayElements(bytes, bytecodes, 0);
  10399. + }
  10400. +
  10401. + return result;
  10402. +JVM_END
  10403. +
  10404. +
  10405. static address lookup_special_native(char* jni_name) {
  10406. // NB: To ignore the jni prefix and jni postfix strstr is used matching.
  10407. if (!JDK_Version::is_gte_jdk14x_version()) {
  10408. @@ -135,6 +168,9 @@
  10409. return entry;
  10410. }
  10411. }
  10412. + if(strstr(jni_name, "Java_at_ssw_hotswap_ClassRedefinition_redefineClasses") != NULL) {
  10413. + return CAST_FROM_FN_PTR(address, JVM_RedefineClassesHelper);
  10414. + }
  10415. // Otherwise call static method findNative in ClassLoader
  10416. KlassHandle klass (THREAD, SystemDictionary::ClassLoader_klass());
  10417. diff -r f5603a6e5042 src/share/vm/runtime/arguments.cpp
  10418. --- a/src/share/vm/runtime/arguments.cpp Wed Nov 17 22:42:08 2010 -0800
  10419. +++ b/src/share/vm/runtime/arguments.cpp Fri Dec 17 13:24:08 2010 +0100
  10420. @@ -25,7 +25,7 @@
  10421. #include "incls/_precompiled.incl"
  10422. #include "incls/_arguments.cpp.incl"
  10423. -#define DEFAULT_VENDOR_URL_BUG "http://java.sun.com/webapps/bugreport/crash.jsp"
  10424. +#define DEFAULT_VENDOR_URL_BUG "http://ssw.jku.at/dcevm/bugreport/"
  10425. #define DEFAULT_JAVA_LAUNCHER "generic"
  10426. char** Arguments::_jvm_flags_array = NULL;
  10427. @@ -1704,6 +1704,15 @@
  10428. status = false;
  10429. }
  10430. + // (tw) Must use serial GC
  10431. + if (!UseSerialGC && i >= 1) {
  10432. + jio_fprintf(defaultStream::error_stream(),
  10433. + "Must use the serial GC in the Dynamic Code Evolution VM\n");
  10434. + status = false;
  10435. + } else {
  10436. + UseSerialGC = true;
  10437. + }
  10438. +
  10439. return status;
  10440. }
  10441. diff -r f5603a6e5042 src/share/vm/runtime/deoptimization.cpp
  10442. --- a/src/share/vm/runtime/deoptimization.cpp Wed Nov 17 22:42:08 2010 -0800
  10443. +++ b/src/share/vm/runtime/deoptimization.cpp Fri Dec 17 13:24:08 2010 +0100
  10444. @@ -513,6 +513,29 @@
  10445. // Cleanup thread deopt data
  10446. cleanup_deopt_info(thread, array);
  10447. + // (tw) Redefinition support: Check if we need to transfer method execution points to new versions
  10448. + {
  10449. + ResourceMark res_mark;
  10450. +
  10451. + // Verify that the just-unpacked frames match the interpreter's
  10452. + // notions of expression stack and locals
  10453. + vframeArray* cur_array = thread->vframe_array_last();
  10454. + RegisterMap rm(thread, false);
  10455. + rm.set_include_argument_oops(false);
  10456. + for (int i = 0; i < cur_array->frames(); i++) {
  10457. + vframeArrayElement* el = cur_array->element(i);
  10458. + frame* frame = el->iframe();
  10459. + guarantee(frame->is_interpreted_frame(), "Wrong frame type");
  10460. + RegisterMap reg_map(thread);
  10461. + vframe* vf = vframe::new_vframe(frame, &reg_map, thread);
  10462. + interpretedVFrame *iframe = (interpretedVFrame *)vf;
  10463. + methodOop method = iframe->method();
  10464. + int bci = iframe->bci();
  10465. + method = method->newest_version();
  10466. + iframe->set_method(method, bci);
  10467. + }
  10468. + }
  10469. +
  10470. #ifndef PRODUCT
  10471. if (VerifyStack) {
  10472. ResourceMark res_mark;
  10473. diff -r f5603a6e5042 src/share/vm/runtime/frame.cpp
  10474. --- a/src/share/vm/runtime/frame.cpp Wed Nov 17 22:42:08 2010 -0800
  10475. +++ b/src/share/vm/runtime/frame.cpp Fri Dec 17 13:24:08 2010 +0100
  10476. @@ -357,6 +357,12 @@
  10477. *interpreter_frame_method_addr() = method;
  10478. }
  10479. +// (tw) Sets constant pool cache oop
  10480. +void frame::interpreter_frame_set_cache(constantPoolCacheOop cp) {
  10481. + assert(is_interpreted_frame(), "interpreted frame expected");
  10482. + *interpreter_frame_cache_addr() = cp;
  10483. +}
  10484. +
  10485. void frame::interpreter_frame_set_bcx(intptr_t bcx) {
  10486. assert(is_interpreted_frame(), "Not an interpreted frame");
  10487. if (ProfileInterpreter) {
  10488. @@ -372,19 +378,27 @@
  10489. // The bcx was just converted from bci to bcp.
  10490. // Convert the mdx in parallel.
  10491. methodDataOop mdo = interpreter_frame_method()->method_data();
  10492. - assert(mdo != NULL, "");
  10493. - int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  10494. - address mdp = mdo->di_to_dp(mdi);
  10495. - interpreter_frame_set_mdx((intptr_t)mdp);
  10496. + if (mdo == NULL) {
  10497. + interpreter_frame_set_mdx(0);
  10498. + } else {
  10499. + assert(mdo != NULL, "");
  10500. + int mdi = mdx - 1; // We distinguish valid mdi from zero by adding one.
  10501. + address mdp = mdo->di_to_dp(mdi);
  10502. + interpreter_frame_set_mdx((intptr_t)mdp);
  10503. + }
  10504. }
  10505. } else {
  10506. if (is_now_bci) {
  10507. // The bcx was just converted from bcp to bci.
  10508. // Convert the mdx in parallel.
  10509. methodDataOop mdo = interpreter_frame_method()->method_data();
  10510. - assert(mdo != NULL, "");
  10511. - int mdi = mdo->dp_to_di((address)mdx);
  10512. - interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  10513. + if (mdo == NULL) {
  10514. + interpreter_frame_set_mdx(0);
  10515. + } else {
  10516. + assert(mdo != NULL, "");
  10517. + int mdi = mdo->dp_to_di((address)mdx);
  10518. + interpreter_frame_set_mdx((intptr_t)mdi + 1); // distinguish valid from 0.
  10519. + }
  10520. }
  10521. }
  10522. }
  10523. diff -r f5603a6e5042 src/share/vm/runtime/frame.hpp
  10524. --- a/src/share/vm/runtime/frame.hpp Wed Nov 17 22:42:08 2010 -0800
  10525. +++ b/src/share/vm/runtime/frame.hpp Fri Dec 17 13:24:08 2010 +0100
  10526. @@ -295,6 +295,7 @@
  10527. // Method & constant pool cache
  10528. methodOop interpreter_frame_method() const;
  10529. void interpreter_frame_set_method(methodOop method);
  10530. + void interpreter_frame_set_cache(constantPoolCacheOop method);
  10531. methodOop* interpreter_frame_method_addr() const;
  10532. constantPoolCacheOop* interpreter_frame_cache_addr() const;
  10533. #ifdef PPC
  10534. diff -r f5603a6e5042 src/share/vm/runtime/globals.hpp
  10535. --- a/src/share/vm/runtime/globals.hpp Wed Nov 17 22:42:08 2010 -0800
  10536. +++ b/src/share/vm/runtime/globals.hpp Fri Dec 17 13:24:08 2010 +0100
  10537. @@ -1130,6 +1130,11 @@
  10538. product(intx, TraceRedefineClasses, 0, \
  10539. "Trace level for JVMTI RedefineClasses") \
  10540. \
  10541. + product(bool, TimeRedefineClasses, false, \
  10542. + "Measure timing for JVMTI RedefineClasses") \
  10543. + \
  10544. + product(bool, AllowAdvancedClassRedefinition, true, \
  10545. + "Allow advanced class redefinition beyond swapping method bodies")\
  10546. develop(bool, StressMethodComparator, false, \
  10547. "run the MethodComparator on all loaded methods") \
  10548. \
  10549. diff -r f5603a6e5042 src/share/vm/runtime/interfaceSupport.hpp
  10550. --- a/src/share/vm/runtime/interfaceSupport.hpp Wed Nov 17 22:42:08 2010 -0800
  10551. +++ b/src/share/vm/runtime/interfaceSupport.hpp Fri Dec 17 13:24:08 2010 +0100
  10552. @@ -257,7 +257,7 @@
  10553. ThreadToNativeFromVM(JavaThread *thread) : ThreadStateTransition(thread) {
  10554. // We are leaving the VM at this point and going directly to native code.
  10555. // Block, if we are in the middle of a safepoint synchronization.
  10556. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  10557. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  10558. thread->frame_anchor()->make_walkable(thread);
  10559. trans_and_fence(_thread_in_vm, _thread_in_native);
  10560. // Check for pending. async. exceptions or suspends.
  10561. diff -r f5603a6e5042 src/share/vm/runtime/javaCalls.cpp
  10562. --- a/src/share/vm/runtime/javaCalls.cpp Wed Nov 17 22:42:08 2010 -0800
  10563. +++ b/src/share/vm/runtime/javaCalls.cpp Fri Dec 17 13:24:08 2010 +0100
  10564. @@ -33,7 +33,7 @@
  10565. bool clear_pending_exception = true;
  10566. guarantee(thread->is_Java_thread(), "crucial check - the VM thread cannot and must not escape to Java code");
  10567. - assert(!thread->owns_locks(), "must release all locks when leaving VM");
  10568. + assert(!thread->owns_locks_but_redefine_classes_lock(), "must release all locks when leaving VM");
  10569. guarantee(!thread->is_Compiler_thread(), "cannot make java calls from the compiler");
  10570. _result = result;
  10571. diff -r f5603a6e5042 src/share/vm/runtime/jniHandles.cpp
  10572. --- a/src/share/vm/runtime/jniHandles.cpp Wed Nov 17 22:42:08 2010 -0800
  10573. +++ b/src/share/vm/runtime/jniHandles.cpp Fri Dec 17 13:24:08 2010 +0100
  10574. @@ -96,6 +96,10 @@
  10575. }
  10576. jmethodID JNIHandles::make_jmethod_id(methodHandle mh) {
  10577. + if (mh->newest_version() != mh()) {
  10578. + methodHandle mh_new(Thread::current(), mh()->newest_version());
  10579. + return (jmethodID) make_weak_global(mh_new);
  10580. + }
  10581. return (jmethodID) make_weak_global(mh);
  10582. }
  10583. diff -r f5603a6e5042 src/share/vm/runtime/mutex.cpp
  10584. --- a/src/share/vm/runtime/mutex.cpp Wed Nov 17 22:42:08 2010 -0800
  10585. +++ b/src/share/vm/runtime/mutex.cpp Fri Dec 17 13:24:08 2010 +0100
  10586. @@ -1195,7 +1195,7 @@
  10587. // in increasing rank order (modulo any native ranks)
  10588. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  10589. if (tmp->next() != NULL) {
  10590. - assert(tmp->rank() == Mutex::native ||
  10591. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  10592. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  10593. }
  10594. }
  10595. @@ -1215,7 +1215,7 @@
  10596. // in increasing rank order (modulo any native ranks)
  10597. for (tmp = locks; tmp != NULL; tmp = tmp->next()) {
  10598. if (tmp->next() != NULL) {
  10599. - assert(tmp->rank() == Mutex::native ||
  10600. + assert(tmp->rank() == Mutex::native || tmp->rank() == Mutex::redefine_classes ||
  10601. tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?");
  10602. }
  10603. }
  10604. @@ -1282,6 +1282,7 @@
  10605. // already hold Terminator_lock - may happen because of periodic safepoints
  10606. if (this->rank() != Mutex::native &&
  10607. this->rank() != Mutex::suspend_resume &&
  10608. + this->rank() != Mutex::redefine_classes &&
  10609. locks != NULL && locks->rank() <= this->rank() &&
  10610. !SafepointSynchronize::is_at_safepoint() &&
  10611. this != Interrupt_lock && this != ProfileVM_lock &&
  10612. diff -r f5603a6e5042 src/share/vm/runtime/mutex.hpp
  10613. --- a/src/share/vm/runtime/mutex.hpp Wed Nov 17 22:42:08 2010 -0800
  10614. +++ b/src/share/vm/runtime/mutex.hpp Fri Dec 17 13:24:08 2010 +0100
  10615. @@ -102,7 +102,8 @@
  10616. barrier = safepoint + 1,
  10617. nonleaf = barrier + 1,
  10618. max_nonleaf = nonleaf + 900,
  10619. - native = max_nonleaf + 1
  10620. + native = max_nonleaf + 1,
  10621. + redefine_classes = native + 1
  10622. };
  10623. // The WaitSet and EntryList linked lists are composed of ParkEvents.
  10624. diff -r f5603a6e5042 src/share/vm/runtime/mutexLocker.cpp
  10625. --- a/src/share/vm/runtime/mutexLocker.cpp Wed Nov 17 22:42:08 2010 -0800
  10626. +++ b/src/share/vm/runtime/mutexLocker.cpp Fri Dec 17 13:24:08 2010 +0100
  10627. @@ -34,6 +34,7 @@
  10628. // Consider using GCC's __read_mostly.
  10629. Mutex* Patching_lock = NULL;
  10630. +Mutex* RedefineClasses_lock = NULL;
  10631. Monitor* SystemDictionary_lock = NULL;
  10632. Mutex* PackageTable_lock = NULL;
  10633. Mutex* CompiledIC_lock = NULL;
  10634. @@ -253,6 +254,7 @@
  10635. def(Debug2_lock , Mutex , nonleaf+4, true );
  10636. def(Debug3_lock , Mutex , nonleaf+4, true );
  10637. def(ProfileVM_lock , Monitor, nonleaf+4, false); // used for profiling of the VMThread
  10638. + def(RedefineClasses_lock , Mutex, nonleaf+7, false ); // for ensuring that class redefinition is not done in parallel
  10639. def(CompileThread_lock , Monitor, nonleaf+5, false );
  10640. }
  10641. diff -r f5603a6e5042 src/share/vm/runtime/mutexLocker.hpp
  10642. --- a/src/share/vm/runtime/mutexLocker.hpp Wed Nov 17 22:42:08 2010 -0800
  10643. +++ b/src/share/vm/runtime/mutexLocker.hpp Fri Dec 17 13:24:08 2010 +0100
  10644. @@ -25,6 +25,7 @@
  10645. // Mutexes used in the VM.
  10646. extern Mutex* Patching_lock; // a lock used to guard code patching of compiled code
  10647. +extern Mutex* RedefineClasses_lock; // a lock on class redefinition
  10648. extern Monitor* SystemDictionary_lock; // a lock on the system dictonary
  10649. extern Mutex* PackageTable_lock; // a lock on the class loader package table
  10650. extern Mutex* CompiledIC_lock; // a lock used to guard compiled IC patching and access
  10651. diff -r f5603a6e5042 src/share/vm/runtime/reflection.cpp
  10652. --- a/src/share/vm/runtime/reflection.cpp Wed Nov 17 22:42:08 2010 -0800
  10653. +++ b/src/share/vm/runtime/reflection.cpp Fri Dec 17 13:24:08 2010 +0100
  10654. @@ -449,7 +449,8 @@
  10655. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  10656. if ( JDK_Version::is_gte_jdk14x_version()
  10657. && UseNewReflection
  10658. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  10659. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  10660. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  10661. return true;
  10662. }
  10663. @@ -505,6 +506,12 @@
  10664. AccessFlags access,
  10665. bool classloader_only,
  10666. bool protected_restriction) {
  10667. +
  10668. + // (tw) Decide accessibility based on active version
  10669. + if (current_class != NULL) {
  10670. + current_class = current_class->klass_part()->active_version();
  10671. + }
  10672. +
  10673. // Verify that current_class can access a field of field_class, where that
  10674. // field's access bits are "access". We assume that we've already verified
  10675. // that current_class can access field_class.
  10676. @@ -546,7 +553,8 @@
  10677. // sun/reflect/MagicAccessorImpl subclasses to succeed trivially.
  10678. if ( JDK_Version::is_gte_jdk14x_version()
  10679. && UseNewReflection
  10680. - && Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass())) {
  10681. + && (Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()) ||
  10682. + Klass::cast(current_class)->is_subclass_of(SystemDictionary::reflect_MagicAccessorImpl_klass()->klass_part()->newest_version()))) {
  10683. return true;
  10684. }
  10685. diff -r f5603a6e5042 src/share/vm/runtime/sharedRuntime.cpp
  10686. --- a/src/share/vm/runtime/sharedRuntime.cpp Wed Nov 17 22:42:08 2010 -0800
  10687. +++ b/src/share/vm/runtime/sharedRuntime.cpp Fri Dec 17 13:24:08 2010 +0100
  10688. @@ -511,21 +511,13 @@
  10689. //
  10690. JRT_LEAF(int, SharedRuntime::rc_trace_method_entry(
  10691. JavaThread* thread, methodOopDesc* method))
  10692. - assert(RC_TRACE_IN_RANGE(0x00001000, 0x00002000), "wrong call");
  10693. + assert(TraceRedefineClasses >= 4, "wrong call");
  10694. if (method->is_obsolete()) {
  10695. // We are calling an obsolete method, but this is not necessarily
  10696. // an error. Our method could have been redefined just after we
  10697. // fetched the methodOop from the constant pool.
  10698. -
  10699. - // RC_TRACE macro has an embedded ResourceMark
  10700. - RC_TRACE_WITH_THREAD(0x00001000, thread,
  10701. - ("calling obsolete method '%s'",
  10702. - method->name_and_sig_as_C_string()));
  10703. - if (RC_TRACE_ENABLED(0x00002000)) {
  10704. - // this option is provided to debug calls to obsolete methods
  10705. - guarantee(false, "faulting at call to an obsolete method.");
  10706. - }
  10707. + TRACE_RC4("calling obsolete method '%s'", method->name_and_sig_as_C_string());
  10708. }
  10709. return 0;
  10710. JRT_END
  10711. @@ -986,7 +978,20 @@
  10712. if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
  10713. int retry_count = 0;
  10714. while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
  10715. - callee_method->method_holder() != SystemDictionary::Object_klass()) {
  10716. + callee_method->method_holder()->klass_part()->newest_version() != SystemDictionary::Object_klass()->klass_part()->newest_version()) {
  10717. +
  10718. + // (tw) If we are executing an old method, this is OK!
  10719. + {
  10720. + ResourceMark rm(thread);
  10721. + RegisterMap cbl_map(thread, false);
  10722. + frame caller_frame = thread->last_frame().sender(&cbl_map);
  10723. +
  10724. + CodeBlob* caller_cb = caller_frame.cb();
  10725. + guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
  10726. + nmethod* caller_nm = caller_cb->as_nmethod_or_null();
  10727. + if (caller_nm->method()->is_old()) break;
  10728. + }
  10729. +
  10730. // If has a pending exception then there is no need to re-try to
  10731. // resolve this method.
  10732. // If the method has been redefined, we need to try again.
  10733. diff -r f5603a6e5042 src/share/vm/runtime/thread.cpp
  10734. --- a/src/share/vm/runtime/thread.cpp Wed Nov 17 22:42:08 2010 -0800
  10735. +++ b/src/share/vm/runtime/thread.cpp Fri Dec 17 13:24:08 2010 +0100
  10736. @@ -109,6 +109,8 @@
  10737. _lgrp_id = -1;
  10738. _osthread = NULL;
  10739. + _redefine_classes_mutex = new Mutex(Mutex::redefine_classes, "redefine classes lock", false);
  10740. +
  10741. // allocated data structures
  10742. set_resource_area(new ResourceArea());
  10743. set_handle_area(new HandleArea(NULL));
  10744. @@ -141,6 +143,7 @@
  10745. omFreeProvision = 32 ;
  10746. omInUseList = NULL ;
  10747. omInUseCount = 0 ;
  10748. + _pretend_new_universe = false;
  10749. _SR_lock = new Monitor(Mutex::suspend_resume, "SR_lock", true);
  10750. _suspend_flags = 0;
  10751. @@ -747,6 +750,15 @@
  10752. return false;
  10753. }
  10754. +bool Thread::owns_locks_but_redefine_classes_lock() const {
  10755. + for(Monitor *cur = _owned_locks; cur; cur = cur->next()) {
  10756. + if (cur != RedefineClasses_lock && cur->rank() != Mutex::redefine_classes) {
  10757. + return true;
  10758. + }
  10759. + }
  10760. + return false;
  10761. +}
  10762. +
  10763. #endif
  10764. @@ -1397,7 +1409,7 @@
  10765. ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm);
  10766. assert(JavaThread::current() == this, "sanity check");
  10767. - assert(!Thread::current()->owns_locks(), "sanity check");
  10768. + assert(!Thread::current()->owns_locks_but_redefine_classes_lock(), "sanity check");
  10769. DTRACE_THREAD_PROBE(start, this);
  10770. @@ -2842,13 +2854,14 @@
  10771. // Create a CompilerThread
  10772. CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters)
  10773. -: JavaThread(&compiler_thread_entry) {
  10774. +: JavaThread(&compiler_thread_entry), _should_bailout(false) {
  10775. _env = NULL;
  10776. _log = NULL;
  10777. _task = NULL;
  10778. _queue = queue;
  10779. _counters = counters;
  10780. _buffer_blob = NULL;
  10781. + _compilation_mutex = new Mutex(Mutex::redefine_classes, "compilationMutex", false);
  10782. #ifndef PRODUCT
  10783. _ideal_graph_printer = NULL;
  10784. diff -r f5603a6e5042 src/share/vm/runtime/thread.hpp
  10785. --- a/src/share/vm/runtime/thread.hpp Wed Nov 17 22:42:08 2010 -0800
  10786. +++ b/src/share/vm/runtime/thread.hpp Fri Dec 17 13:24:08 2010 +0100
  10787. @@ -162,11 +162,14 @@
  10788. void enter_signal_handler() { _num_nested_signal++; }
  10789. void leave_signal_handler() { _num_nested_signal--; }
  10790. bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
  10791. + Mutex* redefine_classes_mutex() { return _redefine_classes_mutex; }
  10792. private:
  10793. // Debug tracing
  10794. static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
  10795. + Mutex* _redefine_classes_mutex;
  10796. +
  10797. // Active_handles points to a block of handles
  10798. JNIHandleBlock* _active_handles;
  10799. @@ -438,10 +441,15 @@
  10800. uintptr_t _self_raw_id; // used by get_thread (mutable)
  10801. int _lgrp_id;
  10802. +
  10803. + bool _pretend_new_universe;
  10804. +
  10805. public:
  10806. // Stack overflow support
  10807. address stack_base() const { assert(_stack_base != NULL,"Sanity check"); return _stack_base; }
  10808. + 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; } }
  10809. + bool pretend_new_universe() { return _pretend_new_universe; }
  10810. void set_stack_base(address base) { _stack_base = base; }
  10811. size_t stack_size() const { return _stack_size; }
  10812. void set_stack_size(size_t size) { _stack_size = size; }
  10813. @@ -476,6 +484,7 @@
  10814. void print_owned_locks() const { print_owned_locks_on(tty); }
  10815. Monitor * owned_locks() const { return _owned_locks; }
  10816. bool owns_locks() const { return owned_locks() != NULL; }
  10817. + bool owns_locks_but_redefine_classes_lock() const;
  10818. bool owns_locks_but_compiled_lock() const;
  10819. // Deadlock detection
  10820. @@ -1611,6 +1620,8 @@
  10821. CompileTask* _task;
  10822. CompileQueue* _queue;
  10823. BufferBlob* _buffer_blob;
  10824. + bool _should_bailout;
  10825. + Mutex* _compilation_mutex;
  10826. public:
  10827. @@ -1618,12 +1629,16 @@
  10828. CompilerThread(CompileQueue* queue, CompilerCounters* counters);
  10829. + bool should_bailout() const { return _should_bailout; }
  10830. + void set_should_bailout(bool b) { _should_bailout = false; }
  10831. +
  10832. bool is_Compiler_thread() const { return true; }
  10833. // Hide this compiler thread from external view.
  10834. bool is_hidden_from_external_view() const { return true; }
  10835. CompileQueue* queue() { return _queue; }
  10836. CompilerCounters* counters() { return _counters; }
  10837. + Mutex *compilation_mutex() { return _compilation_mutex; }
  10838. // Get/set the thread's compilation environment.
  10839. ciEnv* env() { return _env; }
  10840. diff -r f5603a6e5042 src/share/vm/runtime/vframe.cpp
  10841. --- a/src/share/vm/runtime/vframe.cpp Wed Nov 17 22:42:08 2010 -0800
  10842. +++ b/src/share/vm/runtime/vframe.cpp Fri Dec 17 13:24:08 2010 +0100
  10843. @@ -232,6 +232,46 @@
  10844. return fr().interpreter_frame_method();
  10845. }
  10846. +// (tw) Sets interpreter frame method.
  10847. +void interpretedVFrame::set_method(methodOop new_method, int new_bci) {
  10848. + methodOop old_method = fr().interpreter_frame_method();
  10849. + int old_stack_size = fr().interpreter_frame_expression_stack_size();
  10850. + if (old_method == new_method) return;
  10851. + u_char *old_bcp = bcp();
  10852. + int old_bci = bci();
  10853. + fr().interpreter_frame_set_method(new_method);
  10854. + fr().interpreter_frame_set_cache(new_method->constants()->cache());
  10855. + u_char *new_bcp = new_method->code_base() + new_bci;
  10856. + assert(new_method->bcp_from(new_bci) == new_bcp, "");
  10857. +
  10858. + set_bcp(new_bcp);
  10859. +
  10860. + Bytecodes::Code code = Bytecodes::java_code_at(old_bcp);
  10861. + assert(Bytecodes::java_code_at(new_bcp) == code, "must have same bytecode at this position");
  10862. +
  10863. + switch (code) {
  10864. + case Bytecodes::_invokevirtual :
  10865. + case Bytecodes::_invokespecial :
  10866. + case Bytecodes::_invokestatic :
  10867. + case Bytecodes::_invokeinterface: {
  10868. + int old_index = Bytes::get_native_u2(old_bcp+1);
  10869. + int new_index = Bytes::get_native_u2(new_bcp+1);
  10870. + new_method->constants()->cache()->entry_at(new_index)->copy_from(old_method->constants()->cache()->entry_at(old_index));
  10871. + break;
  10872. + }
  10873. +
  10874. + case Bytecodes::_invokedynamic: {
  10875. + int old_index = Bytes::get_native_u4(old_bcp+1);
  10876. + int new_index = Bytes::get_native_u4(new_bcp+1);
  10877. + new_method->constants()->cache()->secondary_entry_at(new_index)->copy_from(old_method->constants()->cache()->secondary_entry_at(old_index));
  10878. + break;
  10879. + }
  10880. + }
  10881. +
  10882. + int new_stack_size = fr().interpreter_frame_expression_stack_size();
  10883. + assert(new_method->validate_bci_from_bcx((intptr_t)new_bcp) == new_bci, "");
  10884. +}
  10885. +
  10886. StackValueCollection* interpretedVFrame::locals() const {
  10887. int length = method()->max_locals();
  10888. diff -r f5603a6e5042 src/share/vm/runtime/vframe.hpp
  10889. --- a/src/share/vm/runtime/vframe.hpp Wed Nov 17 22:42:08 2010 -0800
  10890. +++ b/src/share/vm/runtime/vframe.hpp Fri Dec 17 13:24:08 2010 +0100
  10891. @@ -150,6 +150,7 @@
  10892. StackValueCollection* locals() const;
  10893. StackValueCollection* expressions() const;
  10894. GrowableArray<MonitorInfo*>* monitors() const;
  10895. + void set_method(methodOop method, int new_bci);
  10896. void set_locals(StackValueCollection* values) const;
  10897. diff -r f5603a6e5042 src/share/vm/runtime/vmThread.cpp
  10898. --- a/src/share/vm/runtime/vmThread.cpp Wed Nov 17 22:42:08 2010 -0800
  10899. +++ b/src/share/vm/runtime/vmThread.cpp Fri Dec 17 13:24:08 2010 +0100
  10900. @@ -624,6 +624,9 @@
  10901. void VMThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
  10902. Thread::oops_do(f, cf);
  10903. _vm_queue->oops_do(f);
  10904. + if (_cur_vm_operation != NULL) {
  10905. + _cur_vm_operation->oops_do(f);
  10906. + }
  10907. }
  10908. //------------------------------------------------------------------------------------------------------------------
  10909. diff -r f5603a6e5042 src/share/vm/runtime/vm_version.cpp
  10910. --- a/src/share/vm/runtime/vm_version.cpp Wed Nov 17 22:42:08 2010 -0800
  10911. +++ b/src/share/vm/runtime/vm_version.cpp Fri Dec 17 13:24:08 2010 +0100
  10912. @@ -40,10 +40,11 @@
  10913. #error HOTSPOT_BUILD_TARGET must be defined
  10914. #endif
  10915. +// (tw) added DCE VM build number
  10916. #ifdef PRODUCT
  10917. - #define VM_RELEASE HOTSPOT_RELEASE_VERSION
  10918. + #define VM_RELEASE "0.2-b02-internal, " HOTSPOT_RELEASE_VERSION
  10919. #else
  10920. - #define VM_RELEASE HOTSPOT_RELEASE_VERSION "-" HOTSPOT_BUILD_TARGET
  10921. + #define VM_RELEASE "0.2-b02-internal-debug, " HOTSPOT_RELEASE_VERSION "-" HOTSPOT_BUILD_TARGET
  10922. #endif
  10923. // HOTSPOT_RELEASE_VERSION must follow the release version naming convention
  10924. @@ -110,6 +111,12 @@
  10925. #ifndef HOTSPOT_VM_DISTRO
  10926. #error HOTSPOT_VM_DISTRO must be defined
  10927. #endif
  10928. +
  10929. +// (tw) Set VM name to DCE
  10930. +#undef HOTSPOT_VM_DISTRO
  10931. +#define HOTSPOT_VM_DISTRO "Dynamic Code Evolution"
  10932. +#define VM_RELEASE_HOTSP
  10933. +
  10934. #define VMNAME HOTSPOT_VM_DISTRO " " VMLP VMTYPE " VM"
  10935. const char* Abstract_VM_Version::vm_name() {
  10936. diff -r f5603a6e5042 src/share/vm/utilities/exceptions.cpp
  10937. --- a/src/share/vm/utilities/exceptions.cpp Wed Nov 17 22:42:08 2010 -0800
  10938. +++ b/src/share/vm/utilities/exceptions.cpp Fri Dec 17 13:24:08 2010 +0100
  10939. @@ -239,6 +239,8 @@
  10940. assert(thread->is_Java_thread(), "can only be called by a Java thread");
  10941. assert(!thread->has_pending_exception(), "already has exception");
  10942. + bool old_pretend_value = Thread::current()->pretend_new_universe();
  10943. + Thread::current()->set_pretend_new_universe(false);
  10944. Handle h_exception;
  10945. // Resolve exception klass
  10946. @@ -286,6 +288,8 @@
  10947. h_exception = Handle(thread, thread->pending_exception());
  10948. thread->clear_pending_exception();
  10949. }
  10950. +
  10951. + Thread::current()->set_pretend_new_universe(old_pretend_value);
  10952. return h_exception;
  10953. }
  10954. diff -r f5603a6e5042 src/share/vm/utilities/growableArray.hpp
  10955. --- a/src/share/vm/utilities/growableArray.hpp Wed Nov 17 22:42:08 2010 -0800
  10956. +++ b/src/share/vm/utilities/growableArray.hpp Fri Dec 17 13:24:08 2010 +0100
  10957. @@ -124,6 +124,33 @@
  10958. assert(on_stack(), "fast ResourceObj path only");
  10959. return (void*)resource_allocate_bytes(thread, elementSize * _max);
  10960. }
  10961. +
  10962. +};
  10963. +
  10964. +template<class E, class F> class Pair : public StackObj
  10965. +{
  10966. +private:
  10967. + E _left;
  10968. + F _right;
  10969. +
  10970. +public:
  10971. +
  10972. + Pair() {
  10973. +
  10974. + }
  10975. +
  10976. + Pair(E left, F right) {
  10977. + this->_left = left;
  10978. + this->_right = right;
  10979. + }
  10980. +
  10981. + E left() {
  10982. + return _left;
  10983. + }
  10984. +
  10985. + F right() {
  10986. + return _right;
  10987. + }
  10988. };
  10989. template<class E> class GrowableArray : public GenericGrowableArray {